Stream: general

Topic: LTO not linking std?

Jethro (Jan 21 2019 at 12:20, on Zulip):

When compiling a simple crate with LTO enabled, std doesn't get passed to the linker

Jethro (Jan 21 2019 at 12:20, on Zulip):

this seems weird to me?

Jethro (Jan 21 2019 at 12:20, on Zulip):
$ cargo new ltotest --bin
     Created binary (application) `ltotest` package
$ cd ltotest/
$ cargo rustc --release -- -C lto -Z print-link-args
   Compiling ltotest v0.1.0 (/tmp/ltotest)
"cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/tmp/ltotest/target/release/deps/ltotest-d6435de1c5152f8c.ltotest.ept6w7lf-cgu.0.rcgu.o" "-o" "/tmp/ltotest/target/release/deps/ltotest-d6435de1c5152f8c" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/tmp/ltotest/target/release/deps" "-L" "~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/tmp/rustcSoNfzg/libbacktrace_sys-6741d64f34191261.rlib" "-Wl,--end-group" "~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-c8174d577f7ebb97.rlib" "-Wl,-Bdynamic" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil"
    Finished release [optimized] target(s) in 1.83s
Jethro (Jan 21 2019 at 12:21, on Zulip):

this is a problem for my custom target where I expect std to always be linked explicitly (so that certain global symbols are available for linking)

Jethro (Jan 21 2019 at 13:35, on Zulip):

is this ?

Jethro (Jan 21 2019 at 13:44, on Zulip):

hmm maybe this is a difference between extern "C" and extern "Rust"

mw (Jan 25 2019 at 10:12, on Zulip):

if you do -C lto then rustc will do all the LTO work and only pass and already merged object file to the linker.

Last update: Jul 16 2020 at 13:55UTC