Skip to content
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

Merged
merged 1 commit into from
May 22, 2020

Conversation

alexcrichton
Copy link
Member

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.

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
Copy link
Collaborator

r? @ecstatic-morse

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 18, 2020
@alexcrichton
Copy link
Member Author

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.

@ecstatic-morse
Copy link
Contributor

I'm not qualified to review this, so reassigning to the first recommended reviewer:
r? @nnethercote

@nnethercote
Copy link
Contributor

Thanks for the detailed comment.

@bors r+

@bors
Copy link
Contributor

bors commented May 18, 2020

📌 Commit cc91041 has been approved by nnethercote

@bors
Copy link
Contributor

bors commented May 18, 2020

🌲 The tree is currently closed for pull requests below priority 1000, this pull request will be tested once the tree is reopened

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 18, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request May 22, 2020
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
@bors bors merged commit 1119421 into rust-lang:master May 22, 2020
@alexcrichton alexcrichton deleted the ignore-linker-plugin-lto branch July 23, 2020 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants