Skip to content

ThinLTO linking failure #45195

Closed
Closed
@alexcrichton

Description

@alexcrichton

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions