-
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
Accessing large static global behaves incorrectly #121868
Comments
In the playground trying to get the llvm ir or output assembly results in a crash. Maybe there is an overflow at the llvm ir level? |
Emitting asm/llvm works fine for me on CLI, I think it's just a playground issue |
@rustbot claim |
This issue is caused by a known problem in LLVM, which is the use of This was encountered by Zig at ziglang/zig#1424, and one of their folks created an updated version of Unfortunately this doesn't help because the problem call is actually to
The best fix would be to update all of these functions in LLVM (why didn't the first PR just update them all? :P), then eventually integrate them here. In the meantime, we can add correct implementations of these functions to Alternatively we can just add overflow checks to all of the callsites and disallow 2^32-length constant arrays & strings. GCC & Clang also choke on If the goal is just to have a huge static block of zeros at runtime, you can also just make |
Thanks for the info. I actually initially ran into this problem while trying to make a large mutable array, but I used the immutable example in the report because it didn't require unsafe to access (I forgot this would cause it not to go in the BSS). The following example still breaks, even though it should be possible to put the data in the BSS (I think).
|
Oh that's my mistake - I had the accesses commented out and it optimized VALS out :P. It does work for C, though. You could use that fact if this is something you really wanted. |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-critical |
Priority downgraded (Zulip discussion) as it's not a release blocker and in out there since some time. @rustbot label -I-prioritize +P-high -P-critical |
This will be fixed by #122000 |
Fix 32-bit overflows in LLVM composite constants Inspired by rust-lang#121868. Fixes unsoundness created when constructing constant arrays, strings, and structs with 2^32 or more elements on x86_64. This introduces copies of a few LLVM functions that have their signatures updated to use size_t in place of unsigned int. Alternatively we could just add overflow checks and just disallow huge composite constants. That introduces less code, but maybe a huge static block of memory is useful in embedded/no-os situations?
Fix 32-bit overflows in LLVM composite constants Inspired by rust-lang#121868. Fixes unsoundness created when constructing constant arrays, strings, and structs with 2^32 or more elements on x86_64. This introduces copies of a few LLVM functions that have their signatures updated to use size_t in place of unsigned int. Alternatively we could just add overflow checks and just disallow huge composite constants. That introduces less code, but maybe a huge static block of memory is useful in embedded/no-os situations?
Rollup merge of rust-lang#122000 - erer1243:issue-121868, r=nikic Fix 32-bit overflows in LLVM composite constants Inspired by rust-lang#121868. Fixes unsoundness created when constructing constant arrays, strings, and structs with 2^32 or more elements on x86_64. This introduces copies of a few LLVM functions that have their signatures updated to use size_t in place of unsigned int. Alternatively we could just add overflow checks and just disallow huge composite constants. That introduces less code, but maybe a huge static block of memory is useful in embedded/no-os situations?
It's Also, please don't use |
That PR landed, so should this be closed?
FWIW I don't agree with this advice. Anyway that's kind of off-topic here. :) |
@RalfJung yes I believe it should be closed |
Great, thanks to everyone who contributed to the fix. :) |
I tried this code:
I expected to see this happen: it should print 2048 zeroes, since the array is statically initialized to zero.
Instead, this happened: it prints random values of memory. In debug mode, it also exits at the first non-zero value and prints "NON-ZERO". In release mode, it never prints "NON-ZERO", but the values that it displays are in fact non-zero (I believe this is cause it is optimizing out the if statement).
It appears that the linker is not including the data for the
VALS
array in the binary, but a symbol is still included, which causes the loads to access other variables stored at the location of the symbol.Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: