Skip to content

rustc 1.18 regression: order of linker arguments changed #42606

Closed
@Riateche

Description

@Riateche

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.

Metadata

Metadata

Assignees

Labels

A-linkageArea: linking into static, shared libraries and binariesP-highHigh priorityregression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions