rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.72k stars 12.5k forks source link

Invalid local symbol errors linking shared library with rust-lld #128938

Open spearman opened 1 month ago

spearman commented 1 month ago

I have a project generating bindings for FMOD using bindgen: https://gitlab.com/spearman/fmod-rs/-/tree/master/fmod-sys

Trying to build and link an executable with rust-lld generates the following errors:

  = note: rust-lld: error: /home/spearman/rs/local/fmod-rs/fmod-sys/lib/x86_64/libfmod.so: invalid local symbol '__bss_start' in global part of symbol table
          rust-lld: error: /home/spearman/rs/local/fmod-rs/fmod-sys/lib/x86_64/libfmod.so: invalid local symbol '_end' in global part of symbol table
          rust-lld: error: /home/spearman/rs/local/fmod-rs/fmod-sys/lib/x86_64/libfmod.so: invalid local symbol '_edata' in global part of symbol table
          collect2: error: ld returned 1 exit status

For now I am using the rustflags option -Zlinker-features=-lld to avoid using rust-lld

lqd commented 1 month ago

That looks purely like an lld issue, and is not related to rust. It's probably better to open an issue in the llvm/lld project, we couldn't fix this on our side.

It also looks very common with lld when linking to libs linked with another linker like gold -- and e.g. fixable by linking everything with lld, but seems impossible in your case.

The other workarounds mentioned in the many projects like Android hitting this issue, like setting hidden visibility, disabling gc-sections, no start gc, ignoring fatal warnings, didn't seem to work on your project.

I don't believe there's anything we can do here.

spearman commented 1 month ago

That looks purely like an lld issue, and is not related to rust. It's probably better to open an issue in the llvm/lld project, we couldn't fix this on our side.

It also looks very common with lld when linking to libs linked with another linker like gold -- and e.g. fixable by linking everything with lld, but seems impossible in your case.

The other workarounds mentioned in the many projects like Android hitting this issue, like setting hidden visibility, disabling gc-sections, no start gc, ignoring fatal warnings, didn't seem to work on your project.

I don't believe there's anything we can do here.

Could you explain a little more what you mean that there is a problem with lld? If it wasn't clear, it builds and links normally with lld (no errors), the error only occurs when linking with rust-lld.

lqd commented 1 month ago

rust-lld is lld without modifications, just renamed. Any issue with rust-lld should be in lld. We just pass -fuse-ld=lld and the paths in the sysroot, and that's it.

There are many e.g. reports online of this exact issue with lld, eg https://github.com/android/ndk/issues/927

Something weird must be going if e.g. lld without the -B path works...

lqd commented 1 month ago

Something weird must be going on indeed. For me, it doesn't work with a locally built lld but does with e.g. ubuntu's lld.

lqd commented 1 month ago

I've tried different versions of lld, and things seem to be consistent with my "the issue is in lld" theory:

Which versions did you try @spearman?