-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Always generated object code for #![no_builtins]
#72325
Conversation
This commit updates the code generation for `#![no_builtins]` to always produce object files instead of conditionally respecting `-Clinker-plugin-lto` and sometimes producing bitcode. This is intended to address rust-lang/cargo#8239. The issue at hand here is that Cargo has tried to get "smarter" about codegen in whole crate graph scenarios. When LTO is enabled it attempts to avoid codegen on as many crates as possible, opting to pass `-Clinker-plugin-lto` where it can to only generate bitcode. When this is combined with `-Zbuild-std`, however, it means that `compiler-builtins` only generates LLVM bitcode instead of object files. Rustc's own LTO passes then explicitly skip `compiler-builtins` (because it wouldn't work anyway) which means that LLVM bitcode gets sent to the linker, which chokes most of the time. The fix in this PR is to not actually respect `-Clinker-plugin-lto` for `#![no_builtins]` crates. These crates, even if slurped up by the linker rather than rustc, will not work with LTO. They define symbols which are only referenced as part of codegen, so LTO's aggressive internalization would trivially remove the symbols only to have the linker realize later that the symbol is undefined. Since pure-bitcode never makes sense for these libraries, the `-Clinker-plugin-lto` flag is silently ignored.
(rust_highfive has picked a reviewer for you, use r? to override) |
Unfortunately I don't really know of a great way to test this, but I've tested it via rust-lang/cargo#8239 to verify it works as intended. |
I'm not qualified to review this, so reassigning to the first recommended reviewer: |
Thanks for the detailed comment. @bors r+ |
📌 Commit cc91041 has been approved by |
🌲 The tree is currently closed for pull requests below priority 1000, this pull request will be tested once the tree is reopened |
Rollup of 4 pull requests Successful merges: - rust-lang#71610 (InvalidUndefBytes: Track size of undef region used) - rust-lang#72161 (Replace fcntl-based file lock with flock) - rust-lang#72306 (Break tokens before checking if they are 'probably equal') - rust-lang#72325 (Always generated object code for `#![no_builtins]`) Failed merges: r? @ghost
This commit updates the code generation for
#![no_builtins]
to alwaysproduce object files instead of conditionally respecting
-Clinker-plugin-lto
and sometimes producing bitcode. This is intendedto address rust-lang/cargo#8239.
The issue at hand here is that Cargo has tried to get "smarter" about
codegen in whole crate graph scenarios. When LTO is enabled it attempts
to avoid codegen on as many crates as possible, opting to pass
-Clinker-plugin-lto
where it can to only generate bitcode. When thisis combined with
-Zbuild-std
, however, it means thatcompiler-builtins
only generates LLVM bitcode instead of object files.Rustc's own LTO passes then explicitly skip
compiler-builtins
(becauseit wouldn't work anyway) which means that LLVM bitcode gets sent to the
linker, which chokes most of the time.
The fix in this PR is to not actually respect
-Clinker-plugin-lto
for#![no_builtins]
crates. These crates, even if slurped up by the linkerrather than rustc, will not work with LTO. They define symbols which are
only referenced as part of codegen, so LTO's aggressive internalization
would trivially remove the symbols only to have the linker realize later
that the symbol is undefined. Since pure-bitcode never makes sense for
these libraries, the
-Clinker-plugin-lto
flag is silently ignored.