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

rust-lld: error: undefined symbol: __gxx_personality_v0 #135257

Open
hasenbanck opened this issue Jan 8, 2025 · 3 comments
Open

rust-lld: error: undefined symbol: __gxx_personality_v0 #135257

hasenbanck opened this issue Jan 8, 2025 · 3 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries A-linkers Area: linkers... you gotta love linkers C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. requires-nightly This issue requires a nightly compiler in some way. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@hasenbanck
Copy link

We encountered a bug, where the experimental rust-lld currently activated under nightly linux / x86-64, can't links certain executables in release mode with the "intel_tex_2" crate. Switching to the old linker solves the problem.

I created a small repository which includes a minimal example.

https://github.com/hasenbanck/rust_lld_bug

It will crash when compiled via:

cargo run --release

Normaly it should compile fine, but we instead get the following error:

error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH=".....*A LOT OF PATHS*...."
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: rust-lld: error: undefined symbol: __gxx_personality_v0
          >>> referenced by ispc_texcomp_astc.cpp
          >>>               ispc_texcomp_astc.o:(DW.ref.__gxx_personality_v0) in archive /mnt/c/Development/rust_lld_bug/target/release/deps/libintel_tex_2-2caaaa92d5e41391.rlib
          collect2: error: ld returned 1 exit status

error: could not compile `rust_lld_bug` (bin "rust_lld_bug") due to 1 previous error

We used the nightly toolchain 2025-01-07, but older nightly versions are also affected.
We reproduces this error under WSL Ubuntu 24.04 and Fedora 41 running on bare metal.

The old linker works fine:

RUSTFLAGS="-Z linker-features=-lld" cargo run --release
@hasenbanck hasenbanck added the C-bug Category: This is a bug. label Jan 8, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 8, 2025
@bjorn3
Copy link
Member

bjorn3 commented Jan 9, 2025

__gxx_personality_v0 is the C++ personality function which is defined by the C++ standard library. I can't find where intel_tex_2 tells the linker to link against the C++ standard library. Can you check if in part of the linker invocation that you omitted there is a -lc++ or -lstdc++ or something like argument that?

@hasenbanck
Copy link
Author

  Downloaded num_cpus v1.16.0
  Downloaded ispc_rt v2.0.1
  Downloaded libc v0.2.169
  Downloaded intel_tex_2 v0.4.0
  Downloaded 4 crates (9.7 MB) in 0.74s (largest was `intel_tex_2` at 8.9 MB)
   Compiling libc v0.2.169
   Compiling num_cpus v1.16.0
   Compiling ispc_rt v2.0.1
   Compiling intel_tex_2 v0.4.0
   Compiling rust_lld_bug v0.1.0 (/home/a_user/Development/rust_lld_bug)
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/a_user/.rustup/toolchains/nightly-2025-01-07-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/a_user/.rustup/toolchains/nightly-2025-01-07-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/self-contained:/home/a_user/.cargo/bin:/home/a_user/.local/bin:/home/a_user/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin" VSLANG="1033" "cc" "-m64" "/tmp/rustckQ50hQ/symbols.o" "<2 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "/home/a_user/Development/rust_lld_bug/target/release/deps/{libintel_tex_2-2caaaa92d5e41391.rlib,libispc_rt-c1f667297e82208b.rlib,libnum_cpus-b5fa6fd5af20baf4.rlib,liblibc-49da99225b5d9d58.rlib}" "/home/a_user/.rustup/toolchains/nightly-2025-01-07-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-d6f1d924b2f4233e.rlib,libpanic_unwind-00eb06e39850f679.rlib,libobject-d0382f11baa011b6.rlib,libmemchr-b7e2e2c1a7e4643d.rlib,libaddr2line-30ced7f1999cfa29.rlib,libgimli-3ee7e14c58e31ebd.rlib,librustc_demangle-a4f649bba77ffcc5.rlib,libstd_detect-c89a3ce7ad7c3dbd.rlib,libhashbrown-e1ce1d3d110c6707.rlib,librustc_std_workspace_alloc-e0604fecbf0f39dc.rlib,libminiz_oxide-0a9c6172f04822cc.rlib,libadler2-14a33f7117abcee7.rlib,libunwind-24c16adbe5e57356.rlib,libcfg_if-d2688d4a5c8e415b.rlib,liblibc-8ff7ba6d97853f27.rlib,liballoc-5c001d095eb077ec.rlib,librustc_std_workspace_core-395a38b8e0851c9b.rlib,libcore-d453bab70303062c.rlib,libcompiler_builtins-dd545221bb4f4734.rlib}" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-B/home/a_user/.rustup/toolchains/nightly-2025-01-07-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld" "-fuse-ld=lld" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/a_user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/intel_tex_2-0.4.0/src/ispc" "-L" "/home/a_user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/intel_tex_2-0.4.0/src/ispc" "-L" "/home/a_user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/intel_tex_2-0.4.0/src/ispc" "-L" "/home/a_user/.rustup/toolchains/nightly-2025-01-07-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/a_user/Development/rust_lld_bug/target/release/deps/rust_lld_bug-8ac7a768a1ddcd3d" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: rust-lld: error: undefined symbol: __gxx_personality_v0
          >>> referenced by ispc_texcomp_astc.cpp
          >>>               ispc_texcomp_astc.o:(DW.ref.__gxx_personality_v0) in archive /home/a_user/Development/rust_lld_bug/target/release/deps/libintel_tex_2-2caaaa92d5e41391.rlib
          collect2: error: ld returned 1 exit status


error: could not compile `rust_lld_bug` (bin "rust_lld_bug") due to 1 previous error

Here is the full error output from a fresh Fedora 41 installaction. I can't see any -lc++ or -lstdc++

Just want to add that the default linker on stable for linux, macos and windows link this project fine.

I'm not deep into the topic of linking, but I think what happens here is, that code is stripped out by the other linker, which is never actually used by intel-tex-rs-2 (see the comment in the build script).

rust-lld is then trying to link the code that needs the C++ standard library, where as the other linker don't do that, since they stripped that code out already.

The question is now, what the expected behavior in this case is, especially in light of the different behavior on stable (of course intel-tex-rs-2 could remove that code, since it's not implemented anyhow).

@bjorn3
Copy link
Member

bjorn3 commented Jan 9, 2025

I think it is expected that you may get an error about unresolved symbols if those are referenced by a function even if that function ends up getting discarded in the end. We don't guarantee that we enable --gc-sections to discard unused functions and even have an option to disable this using -Clink-dead-code=yes.

@lolbinarycat lolbinarycat added requires-nightly This issue requires a nightly compiler in some way. regression-untriaged Untriaged performance or correctness regression. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue A-linkers Area: linkers... you gotta love linkers T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 10, 2025
@bjorn3 bjorn3 added the A-linkage Area: linking into static, shared libraries and binaries label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries A-linkers Area: linkers... you gotta love linkers C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. requires-nightly This issue requires a nightly compiler in some way. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants