Skip to content

ThinLTO linking failure #45195

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

Closed
alexcrichton opened this issue Oct 11, 2017 · 2 comments
Closed

ThinLTO linking failure #45195

alexcrichton opened this issue Oct 11, 2017 · 2 comments
Labels
A-codegen Area: Code generation A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.

Comments

@alexcrichton
Copy link
Member

An extracted test case from https://internals.rust-lang.org/t/help-test-out-thinlto/6017/32 can be minimized down to:

#[inline]          
pub fn wut(a: u8) {
    a.to_string(); 
}                  

and can be reproduced with:

$ rustc +nightly -Z thinlto -C codegen-units=2 src/lib.rs --crate-type dylib
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/alex/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "lib.lib0-8cd878b7c8d78940dfe6697baf5b88ec.rs.rust-cgu.o" "lib.lib1-8cd878b7c8d78940dfe6697baf5b88ec.rs.rust-cgu.o" "-o" "liblib.so" "lib.crate.metadata.rust-cgu.o" "lib.crate.allocator.rust-cgu.o" "-Wl,-z,relro,-z,now" "-nodefaultlibs" "-L" "/home/alex/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,--whole-archive" "/tmp/rustc.7o4PYrZszXql/libstd-b3337a279b80aa68.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.7o4PYrZszXql/librand-90ba6ea1a4b00ac9.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.7o4PYrZszXql/liballoc_system-8b8c81c75416769d.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.7o4PYrZszXql/libpanic_unwind-835a006d40378e68.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.7o4PYrZszXql/libunwind-7683a3e743ffc736.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.7o4PYrZszXql/liblibc-1b0e0cf3656476c6.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.7o4PYrZszXql/liballoc-86482e4a0f4afc7d.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.7o4PYrZszXql/libstd_unicode-4c6e67dafb0b1a44.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.7o4PYrZszXql/libcore-3bc7dbfdcf1abd3d.rlib" "-Wl,--no-whole-archive" "/tmp/rustc.7o4PYrZszXql/libcompiler_builtins-7227b52ccb6f78fe.rlib" "-Wl,-Bdynamic" "-l" "dl" "-l" "rt" "-l" "pthread" "-l" "pthread" "-l" "gcc_s" "-l" "c" "-l" "m" "-l" "rt" "-l" "pthread" "-l" "util" "-shared"
  = note: /usr/bin/ld: error: lib.lib0-8cd878b7c8d78940dfe6697baf5b88ec.rs.rust-cgu.o: requires dynamic R_X86_64_PC32 reloc against '_ZN44_$LT$char$u20$as$u20$core..char..CharExt$GT$11encode_utf817h929e1aa83e3da410E' which may overflow at runtime; recompile with -fPIC
          lib.lib0-8cd878b7c8d78940dfe6697baf5b88ec.rs.rust-cgu.o:lib0-8cd878b7c8d78940dfe6697baf5b88ec.rs:function std_unicode::char::_$LT$impl$u20$char$GT$::encode_utf8::hd034682058f9c2b9: error: undefined reference to '_$LT$char$u20$as$u20$core..char..CharExt$GT$::encode_utf8::h929e1aa83e3da410'
          collect2: error: ld returned 1 exit status
          

error: aborting due to previous error

Oddly enough the error is slightly nondeterministic...

@alexcrichton alexcrichton added A-codegen Area: Code generation A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. labels Oct 11, 2017
@alexcrichton
Copy link
Member Author

Hm ok that's not actually a great reproduction. ThinLTO is performing as expected for that reproduction, the problem is that we just don't have dead code elimination turned on at O1 in LLVM. Going to try to re-reduce again with optimizations enabled to get closer to the original issue.

@alexcrichton
Copy link
Member Author

Er actually turns out I was testing the wrong thing! I think I've got a fix

alexcrichton added a commit to alexcrichton/rust that referenced this issue Oct 15, 2017
First the `addPreservedGUID` function forgot to take care of "alias" summaries.
I'm not 100% sure what this is but the current code now matches upstream. Next
the `computeDeadSymbols` return value wasn't actually being used, but it needed
to be used! Together these should...

Closes rust-lang#45195
bors added a commit that referenced this issue Oct 15, 2017
…lwoerister

rustc: Fix some ThinLTO internalization

First the `addPreservedGUID` function forgot to take care of "alias" summaries.
I'm not 100% sure what this is but the current code now matches upstream. Next
the `computeDeadSymbols` return value wasn't actually being used, but it needed
to be used! Together these should...

Closes #45195
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
Projects
None yet
Development

No branches or pull requests

1 participant