-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
null symbols cause unsoundness with extern static #139128
Comments
this is an LLVM bug: it e.g. applies the following transformation to an @GLIBC_PRIVATE = external global i64
define noundef zeroext i1 @example_foo_h402e223ff693409d() unnamed_addr {
start:
- %self.dbg.spill = alloca [8 x i8], align 8
- store ptr @GLIBC_PRIVATE, ptr %self.dbg.spill, align 8
- %_0 = icmp eq i64 ptrtoint (ptr @GLIBC_PRIVATE to i64), 0
- ret i1 %_0
+ ret i1 false
} |
|
I have filed an issue at llvm/llvm-project#133621 |
Responses to the LLVM issue say that the global must be marked with weak linkage (I assume this is ends up as a weak symbol, otherwise I’d expect a linker error). From a Rust POOV I would also argue this is “just” the fault of the |
If we wish to accept LLVM's decision on this point, instead of implementing some sus workaround, then it seems we should update the reference accordingly. cc @rust-lang/opsem |
Fully agreed. Alignment seems entirely obvious (just like the type of the |
What about for unit, and other ZSTs? Since a null pointer is valid for them, then should they be allowed to be linked to address zero / null? |
A null reference is not valid though, and no actual allocation can exist at the null address, not even allocations of size 0. So I don't think they are special here. The key point is that a static represents an allocation, not just a pointer. |
Pointers to external statics are incorrectly assumed to be non-null and well-aligned. Edition 2024 marking
extern
as unsafe does help, but there is no documentation mentioning this, and this still works in 2021 despite forbiddingunsafe_code
.https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=4d1319d8ff14e454c3e391474ef299e6
The text was updated successfully, but these errors were encountered: