-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Make #[used(linker)] the default on ELF too #140872
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
base: master
Are you sure you want to change the base?
Conversation
r? @nnethercote rustbot has assigned @nnethercote. Use |
Some changes occurred in compiler/rustc_codegen_ssa Some changes occurred in compiler/rustc_codegen_ssa/src/codegen_attrs.rs |
cg_clif currently treats |
Looks ok to me, but as this is the first I've heard of these attributes, I will run it past the person who first suggested them: r? @nikic |
This generally sounds reasonable to me in the interest of having consistent behavior across platforms. Some questions:
|
symbols.o only ensures that the object file containing the symbol is pulled in from an archive. It does nothing to stop
I want to guarantee the |
It would at least remove the main reason why we introduced |
SHF_GNU_RETAIN is a lot newer than I thought. It was only introduced in 2021 with binutils 2.36. I guess that means we can't make it a hard guarantee for now. We can stop passing |
☔ The latest upstream changes (presumably #141518) made this pull request unmergeable. Please resolve the merge conflicts. |
#[used] currently is an alias for #[used(linker)] on all platforms except ELF based ones where it is an alias for #[used(compiler)]. The latter has surprising behavior and the LLVM LangRef explicitly states that it "should only be used in rare circumstances, and should not be exposed to source languages." The reason #[used] still was an alias to #[used(compiler)] on ELF is because the gold linker has issues with it. Luckily gold has been deprecated with GCC 15 and seems to be unable to bootstrap rustc anyway. As such we shouldn't really care about supporting gold.
46f6422
to
2a7a131
Compare
I did some investigation on the history of Originally, the previously existing C-equivalent of It was then discovered that this behavior broke projects, like the Linux kernel (https://gcc.gnu.org/pipermail/gcc-patches/2021-February/565337.html). The reason for that was that they already used So what does that mean for Rust? Since we always use the equivalent of I've opened #141750 to see whether it's possible to warn about the potential miscompiles with gold. |
#[used]
currently is an alias for#[used(linker)]
on all platforms except ELF based ones where it is an alias for#[used(compiler)]
. The latter has surprising behavior and the LLVM LangRef explicitly states that it "should only be used in rare circumstances, and should not be exposed to source languages." 1The reason
#[used]
still was an alias to#[used(compiler)]
on ELF is because the gold linker has issues with it. Luckily gold has been deprecated with GCC 15 2 and seems to be unable to bootstrap rustc anyway 3. As such we shouldn't really care about supporting gold.This would also allow re-enabling start-stop-gc with lld.
cc #93798
Likely fixes #85045
Footnotes
https://llvm.org/docs/LangRef.html#the-llvm-compiler-used-global-variable ↩
https://lists.gnu.org/archive/html/info-gnu/2025-02/msg00001.html ↩
https://github.com/rust-lang/rust/issues/139425 ↩