-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#[repr(align(x))] is limited to 32768 #42960
Comments
#30170 appears to be only for alignment using the allocator, so not covering all the cases of I have been pointed to Line 1389 in 9b5b514
|
The limit comes from here: rust/src/librustc/ty/layout.rs Lines 287 to 289 in 686ec28
|
Thanks! So, the blame seems to show it all came from the same commit that introduced the Could that be premature optimization, or do you think there is a strong performance case for having the alignment restricted this way? |
No idea, I just traced the alignment variable through the code. I can try to change it, but I don't know much about this stuff. I'm assuming 2^31 would be more than enough? |
@Ekleog It looks like it's just trying to optimize compiler memory usage by keeping the size of the alignment info small. We should just be able to bump that to |
@sfackler I'm currently working on that. |
Yeah, 2^31 is ~2GB, I think it would be enough for all practical purposes (the only cases I know of required natural alignment for large arrays are for embedded devices, which don't have that much memory anyway -- while 2^15 is 32kB which stays under the “existing” limit) Thanks @PlasmaPower ! |
I understand the code a bit better now. It was dividing a u8 into 2 nibbles, for the abi and preferred alignments. Instead of using a u16, I'm just using 2 PR should be up shortly, currently working on tests. |
#43097 created to fix this. |
Raise alignment limit from 2^15 to 2^31 - 1 Fixes #42960
Thanks! |
In some cases, the hardware imposes natural alignment for some data (ie. data aligned to its length). For example, the ARM Memory Protection Unit.
This can happen even when handling large structs (eg.
0x10000
-sized buffers). These buffers would thus require an alignment of0x10000
. Which appears not to be possible with#[repr(align(x))]
, that appears limited to 32768.I'm currently using the following (ugly, esp. because of the absence of type-level integers) workaround to get the aligned data I need:
If I can manually do it, I don't really get why rustc wouldn't be able to do it (esp. with http://www.cs.brandeis.edu/~cs146a/rust/doc-02-21-2015/rustc/lib/llvm/fn.LLVMSetAlignment.html taking an u32 as input)?
Is there a technical issue or is this just a current implementation limitation?
As this behaviour is not specified in RFC1358, cc'ing #33626
Disclaimer: I'm not actually running this code on an ARM MPU-enabled chip, but explaining the actual use case would be too long and complex and the issue is exactly the same, so I just picked this example.
The text was updated successfully, but these errors were encountered: