linkme icon indicating copy to clipboard operation
linkme copied to clipboard

rust-lld: error: undefined symbol: `__[start|stop]_linkm2_KNOWN_STUBS`

Open torokati44 opened this issue 1 year ago • 7 comments

This has been an issue before (https://github.com/dtolnay/linkme/pull/88), but now it has reached rustc beta: https://github.com/ruffle-rs/ruffle/actions/runs/9462151873/job/26064482962?pr=16448

  = note: rust-lld: error: undefined symbol: __start_linkm2_KNOWN_STUBS
          >>> referenced by 14g71b7tf2rrf8tb6zps16jjh
          >>>               ruffle_core-d15044b578f91d45.14g71b7tf2rrf8tb6zps16jjh.rcgu.o:(ruffle_core::stub::KNOWN_STUBS::h570647c79bce49d9) in archive /home/runner/work/ruffle/ruffle/target/ci/deps/libruffle_core-d15044b578f91d45.rlib
          >>> did you mean: __start_linkme_KNOWN_STUBS
          >>> defined in: <internal>
          >>> the encapsulation symbol needs to be retained under --gc-sections properly; consider -z nostart-stop-gc (see https://lld.llvm.org/ELF/start-stop-gc)
          
          rust-lld: error: undefined symbol: __stop_linkm2_KNOWN_STUBS
          >>> referenced by 14g71b7tf2rrf8tb6zps16jjh
          >>>               ruffle_core-d15044b578f91d45.14g71b7tf2rrf8tb6zps16jjh.rcgu.o:(ruffle_core::stub::KNOWN_STUBS::h570647c79bce49d9) in archive /home/runner/work/ruffle/ruffle/target/ci/deps/libruffle_core-d15044b578f91d45.rlib
          >>> did you mean: __stop_linkme_KNOWN_STUBS
          >>> defined in: <internal>
          collect2: error: ld returned 1 exit status

torokati44 avatar Jun 11 '24 09:06 torokati44

See also: https://github.com/dtolnay/linkme/actions/runs/9458387043/job/26053880019

torokati44 avatar Jun 11 '24 14:06 torokati44

RUSTFLAGS="-C link-args=-znostart-stop-gc" does indeed work around this. Pasting the link from the error message to make it clickable: https://lld.llvm.org/ELF/start-stop-gc

torokati44 avatar Jun 11 '24 15:06 torokati44

It seems to really be a dup of now-long-standing #49 (see that digit switch? what a coincidence!)

BTW, what was the platform in this case? (distro, libc, cc toolkit; with versions) I am wondering how to pinpoint the real culprit.

yoctozepto avatar Aug 07 '24 21:08 yoctozepto

It seems to really be a dup of now-long-standing #49 (see that digit switch? what a coincidence!)

BTW, what was the platform in this case? (distro, libc, cc toolkit; with versions) I am wondering how to pinpoint the real culprit.

I have realised the main post had a ref to GHA running Ubuntu 22.04 which has clang in version 14 https://packages.ubuntu.com/jammy/clang and obviously runs glibc

yoctozepto avatar Aug 07 '24 21:08 yoctozepto

Same issue here. link-args=-znostart-stop-gc as the error suggests works for me, as does link-dead-code.

Host triple: x86_64-unknown-linux-gnu Arch Linux w/Rustup rustc 1.85.0-nightly (a224f3807 2024-12-09) glibc 2.40 clang/lld 18.1.8

willmtemple avatar Dec 10 '24 18:12 willmtemple

Also having the same issue with macOS

InvalidJoker avatar Feb 15 '25 11:02 InvalidJoker

Rust will pass the necessary flag automatically for now: https://github.com/rust-lang/rust/pull/137685

But this should be fixed in linkme as described in the lld docs.

Noratrieb avatar Mar 03 '25 11:03 Noratrieb

The workaround indeed doesn't seem to be required anymore. Thanks!

torokati44 avatar May 22 '25 10:05 torokati44