-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
ThinLTO and -o
compiler option can lead to duplicate object file inclusion in staticlib
#64153
Comments
Thanks a lot for the bug report, @nikhilm! And great debugging too! This does look problematic indeed. It might be easy to fix by making the compiler behave consistently when |
Nominating for prioritization. |
triage: P-high, unnominating. Assigning to @michaelwoerister with intention that they choose if they'd prefer to fix it themselves, or to mentor someone else in authoring a fix. |
nominating for discussion at T-compiler meeting, in hopes of finding someone to address this. |
I'll look into this now. |
great, I'll remove the nomination label. |
…to identify Rust generated object files.
…=alexcrichton Fix rust-lang#64153 This PR changes how the compiler detects if an object file from an upstream crate is a Rust object file or not. Instead of checking if the name starts with the crate name and ends with `.o` (which is not always the case, as described in rust-lang#64153), it now just checks if the filename ends with `.rcgu.o`. This fixes rust-lang#64153. However, ideally we'd clean up the code around filename generation some more. Then this check could be made more robust. r? @alexcrichton
…=alexcrichton Fix rust-lang#64153 This PR changes how the compiler detects if an object file from an upstream crate is a Rust object file or not. Instead of checking if the name starts with the crate name and ends with `.o` (which is not always the case, as described in rust-lang#64153), it now just checks if the filename ends with `.rcgu.o`. This fixes rust-lang#64153. However, ideally we'd clean up the code around filename generation some more. Then this check could be made more robust. r? @alexcrichton
…to identify Rust generated object files.
Just a quick note of appreciation. Thanks @nikhilm, @michaelwoerister and anyone else involved here. I hit this exact issue and was delighted to find it was already fixed in 1.40.0. |
❤️ |
I've verified this on macOS 10.14/Xcode 10.3 as well as Ubuntu 14.04/GCC 4.8
rustc -V: rustc 1.36.0-nightly (50a0def 2019-05-21) (although the code i mention is the same in master)
tl;dr object files (
.o
) prefixes are inferred from-o
, but lto object file exclusion uses crate name. External build systems which use-o
can face build failures.Setup:
-o
that causes it to have a custom output name.Sample: https://gist.github.com/nikhilm/a72d89002553ecab4511fbe77df223cc
Run
cargo build --release -vv
to get the command lines.First, just building the dependent rlib (by copying the cargo invocation, no
-o
passed)notice how the prefix is bitflags
Now, tweaking the rustc command for bitflags to add a
-o
and running ar on that file:notice how the prefix is libbitflags.
This is fine. But when compiling a staticlib comprising this rlib, there is a special case when lto is enabled.
rust/src/librustc_codegen_llvm/back/archive.rs
Line 143 in 6c18a3d
Now, if we take a look at the cargo generated staticlib, running
ar -t target/release/libhello_world.a
:However, if we tweak the rustc for the staticlib to link against the rlib generated using
-o
If this is different from the crate name, we are in trouble because the
starts_with
match fails (libbitflags does not start with bitflags).The text was updated successfully, but these errors were encountered: