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

rustc 1.18 regression: order of linker arguments changed #42606

Closed
Riateche opened this Issue Jun 12, 2017 · 4 comments

Comments

Projects
None yet
4 participants
@Riateche
Copy link

Riateche commented Jun 12, 2017

After updating from rust stable 1.17 to 1.18 my crate couldn't compile because of the following error:

     Running `rustc --crate-name qt_core /home/ri/.cargo/registry/src/github.com-1ecc6299db9ec823/qt_core-0.2.1/src/lib.rs --emit=dep-info,link -C debuginfo=2 --test -C metadata=d4f1aa06bfccc911 -C extra-filename=-d4f1aa06bfccc911 --out-dir /data/projects/rust/rust_qt/repos/qt_ci/test_crate/target/debug/deps -L dependency=/data/projects/rust/rust_qt/repos/qt_ci/test_crate/target/debug/deps --extern cpp_utils=/data/projects/rust/rust_qt/repos/qt_ci/test_crate/target/debug/deps/libcpp_utils-5c5914e1d6cd97a2.rlib --extern libc=/data/projects/rust/rust_qt/repos/qt_ci/test_crate/target/debug/deps/liblibc-496b028781a2b35b.rlib --cap-lints warn -L native=/home/ri/bin/Qt/5.8/gcc_64/lib -L native=/data/projects/rust/rust_qt/repos/qt_ci/test_crate/target/debug/build/qt_core-5f8a991aad29b8d6/out/c_lib_install/lib -l Qt5Core`
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/ri/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/data/projects/rust/rust_qt/repos/qt_ci/test_crate/target/debug/deps/qt_core-d4f1aa06bfccc911.0.o" "-o" "/data/projects/rust/rust_qt/repos/qt_ci/test_crate/target/debug/deps/qt_core-d4f1aa06bfccc911" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/data/projects/rust/rust_qt/repos/qt_ci/test_crate/target/debug/deps" "-L" "/home/ri/bin/Qt/5.8/gcc_64/lib" "-L" "/data/projects/rust/rust_qt/repos/qt_ci/test_crate/target/debug/build/qt_core-5f8a991aad29b8d6/out/c_lib_install/lib" "-L" "/home/ri/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-l" "stdc++" "-Wl,-Bstatic" "-Wl,--whole-archive" "-l" "qt_core_c" "-Wl,--no-whole-archive" "-Wl,-Bdynamic" "-l" "Qt5Core" "-Wl,-Bstatic" "/data/projects/rust/rust_qt/repos/qt_ci/test_crate/target/debug/deps/liblibc-496b028781a2b35b.rlib" "/data/projects/rust/rust_qt/repos/qt_ci/test_crate/target/debug/deps/libcpp_utils-5c5914e1d6cd97a2.rlib" "/home/ri/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libtest-6c35a477e7bec8d3.rlib" "/home/ri/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libterm-fa872424129019f5.rlib" "/home/ri/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgetopts-a80f7c589731de53.rlib" "/home/ri/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-f4594d3e53dcb114.rlib" "/home/ri/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-a0157c0ca919c364.rlib" "/home/ri/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-488b4ab4bd53a138.rlib" "/home/ri/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-1efbcfd8938372b6.rlib" "/home/ri/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-532a3dbf317eff86.rlib" "/home/ri/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-ca07b617414dd0fa.rlib" "/home/ri/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-492d8ea7fa3384ff.rlib" "/home/ri/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-88c194c15fdb6521.rlib" "/home/ri/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_unicode-cfbd6648f7db2ee5.rlib" "/home/ri/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-687e6a964d22cbb4.rlib" "/home/ri/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-987729be881d4d32.rlib" "-Wl,-Bdynamic" "-l" "util" "-l" "dl" "-l" "rt" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "pthread" "-l" "util"
  = note: /usr/bin/ld: /data/projects/rust/rust_qt/repos/qt_ci/test_crate/target/debug/build/qt_core-5f8a991aad29b8d6/out/c_lib_install/lib/libqt_core_c.a(qt_core_c_slots.cpp.o): undefined reference to symbol '__cxa_guard_acquire@@CXXABI_1.3'
          /usr/lib/gcc/x86_64-linux-gnu/4.9/libstdc++.so: error adding symbols: DSO missing from command line
          collect2: error: ld returned 1 exit status

In rust 1.17 cargo runs the following command which looks more of less the same as in rust 1.18:

     Running `rustc --crate-name qt_core /home/ri/.cargo/registry/src/github.com-1ecc6299db9ec823/qt_core-0.2.1/src/lib.rs --emit=dep-info,link -C debuginfo=2 --test -C metadata=9a91784edbc01ee8 -C extra-filename=-9a91784edbc01ee8 --out-dir /data/projects/rust/rust_qt/repos/qt_ci_rust1.17/test_crate/target/debug/deps -L dependency=/data/projects/rust/rust_qt/repos/qt_ci_rust1.17/test_crate/target/debug/deps --extern libc=/data/projects/rust/rust_qt/repos/qt_ci_rust1.17/test_crate/target/debug/deps/liblibc-d69a024cc1f6bd5d.rlib --extern cpp_utils=/data/projects/rust/rust_qt/repos/qt_ci_rust1.17/test_crate/target/debug/deps/libcpp_utils-86b3af6690ba8815.rlib -L native=/home/ri/bin/Qt/5.8/gcc_64/lib -L native=/data/projects/rust/rust_qt/repos/qt_ci_rust1.17/test_crate/target/debug/build/qt_core-51b98eba30464ee3/out/c_lib_install/lib -l Qt5Core`

And when I run this command with -Z print-link-args I get the following linker invokation:

"cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/ri/.rustup/toolchains/1.17.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/data/projects/rust/rust_qt/repos/qt_ci_rust1.17/test_crate/target/debug/deps/qt_core-9a91784edbc01ee8.0.o" "-o" "/data/projects/rust/rust_qt/repos/qt_ci_rust1.17/test_crate/target/debug/deps/qt_core-9a91784edbc01ee8" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/data/projects/rust/rust_qt/repos/qt_ci_rust1.17/test_crate/target/debug/deps" "-L" "/home/ri/bin/Qt/5.8/gcc_64/lib" "-L" "/data/projects/rust/rust_qt/repos/qt_ci_rust1.17/test_crate/target/debug/build/qt_core-51b98eba30464ee3/out/c_lib_install/lib" "-L" "/home/ri/.rustup/toolchains/1.17.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,--whole-archive" "-l" "qt_core_c" "-Wl,--no-whole-archive" "-Wl,-Bdynamic" "-l" "stdc++" "-l" "Qt5Core" "/data/projects/rust/rust_qt/repos/qt_ci_rust1.17/test_crate/target/debug/deps/liblibc-d69a024cc1f6bd5d.rlib" "/data/projects/rust/rust_qt/repos/qt_ci_rust1.17/test_crate/target/debug/deps/libcpp_utils-86b3af6690ba8815.rlib" "/home/ri/.rustup/toolchains/1.17.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libtest-6c35a477e7bec8d3.rlib" "/home/ri/.rustup/toolchains/1.17.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libterm-fa872424129019f5.rlib" "/home/ri/.rustup/toolchains/1.17.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgetopts-a80f7c589731de53.rlib" "/home/ri/.rustup/toolchains/1.17.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-f4594d3e53dcb114.rlib" "/home/ri/.rustup/toolchains/1.17.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-a0157c0ca919c364.rlib" "/home/ri/.rustup/toolchains/1.17.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-488b4ab4bd53a138.rlib" "/home/ri/.rustup/toolchains/1.17.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-1efbcfd8938372b6.rlib" "/home/ri/.rustup/toolchains/1.17.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-532a3dbf317eff86.rlib" "/home/ri/.rustup/toolchains/1.17.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-ca07b617414dd0fa.rlib" "/home/ri/.rustup/toolchains/1.17.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-492d8ea7fa3384ff.rlib" "/home/ri/.rustup/toolchains/1.17.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-88c194c15fdb6521.rlib" "/home/ri/.rustup/toolchains/1.17.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_unicode-cfbd6648f7db2ee5.rlib" "/home/ri/.rustup/toolchains/1.17.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-687e6a964d22cbb4.rlib" "/home/ri/.rustup/toolchains/1.17.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-987729be881d4d32.rlib" "-l" "util" "-l" "dl" "-l" "rt" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "util"

If I'm not mistaken, the key difference between the two linker commands is that "-l" "stdc++" appears after "-l" "qt_core_c" with rustc 1.17 and the opposite way in rustc 1.18, so the linker refuses to add symbols from libstdc++ with rustc 1.18. But linkers are complicated so I'm not sure. MacOS and Windows builds continue to work, so it seems to be a Linux-specific issue. I fixed it on my end by replacing #[link] attribute with cargo:rustc-link-lib output, but I don't understand why it helped.

@retep998

This comment has been minimized.

Copy link
Member

retep998 commented Jun 12, 2017

Can we get a link to the crate that is failing?

@Riateche

This comment has been minimized.

Copy link
Author

Riateche commented Jun 12, 2017

It was qt_core 0.2.1.
See also Travis log.

It will probably build now because I've made the fix in qt_build_tools dependency. I think you would need to lock qt_build_tools at version 0.2.0 to reproduce it. And it requires Qt 5.8 to build.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jun 19, 2017

I believe this was caused by #40805 along with the other regressions mentioned

The bug here is indeed that in 1.17 you see ... -lqt_core_c ... -lstdc++ whereas in 1.18 you see ... -lstdc++ ... -lqt_core_c ... (the wrong order). The fix looks correct where if you want to have fine-grained control over the order of linked libraries you need to either (a) use #[link] attributes on the same extern block or (b) pass arguments via the command line as -l that are ordered (which rustc will preserve).

In 1.17 and before rustc would automatically sort staticlibs before dylibs regardless of input order. This in turn had bugs for other applications and the change was to respect order regardless of library kind.

We ended up closing a similar issue (#41416) so I'm going to close this as well as it looks like @Riateche the bug is fixed. Sorry for the trouble @Riateche! If you need any help with any other crates though please let us know!

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jun 19, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.