Issue 52799
Summary Segfault in lld:: elf::PPC32Got2Section::finalizeContents
Labels new issue
Assignees
Reporter QuarkTheAwesome
    Hi,

I'm experimenting with Rust and ld.lld for Wii U (a powerpc target, using ELF but with extra sections for import/export tables) and ran into the following crash in ld.lld:

```
error: linking with `rust-lld` failed: signal: 11 (core dumped)
  |
  = note: "rust-lld" "-flavor" "gnu" "--gc-sections" "--emit-relocs" "-znocopyreloc" "--entry=main" "-Tcafe.ld" "/home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/wut_rust_demo-e45af48c9920e099.26rwja7l8px8ogj8.rcgu.o" "/home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/wut_rust_demo-e45af48c9920e099.26wl4pwofg5ml4cj.rcgu.o" "/home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/wut_rust_demo-e45af48c9920e099.2f0up282g2pv82ep.rcgu.o" "/home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/wut_rust_demo-e45af48c9920e099.33w0thwi02pohxp0.rcgu.o" "/home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/wut_rust_demo-e45af48c9920e099.fin5duuobv10bne.rcgu.o" "/home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/wut_rust_demo-e45af48c9920e099.6z1fip811supwzl.rcgu.o" "-L" "/home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps" "-L" "/home/ash/Code/wut-rust-demo/target/debug/deps" "-L" "/home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/build/cafeos-sys-6915539a5d0c6b76/out" "-L" "/home/ash/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/powerpc-unknown-eabi/lib" "--start-group" "-Bstatic" "/home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/libcafeos-3a893634a527b8e5.rlib" "/home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/libarrayvec-c9e52e24cea1b8fa.rlib" "/home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/libcafeos_sys-feb2346b65bf4d2e.rlib" "/home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/libcty-e513a74c8541530d.rlib" "/home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/liballoc-cbbab191eb0fa90c.rlib" "/home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/librustc_std_workspace_core-e311cd3aad6f6119.rlib" "/home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/libcore-7006cbc5b064dea1.rlib" "--end-group" "/home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/libcompiler_builtins-900730f1d1ffb84a.rlib" "-Bdynamic" "--eh-frame-hdr" "-L" "/home/ash/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/powerpc-unknown-eabi/lib" "-o" "/home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/wut_rust_demo-e45af48c9920e099"
  = note: PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
          Stack dump:
          0.    Program arguments: rust-lld -flavor gnu --gc-sections --emit-relocs -znocopyreloc --entry=main -Tcafe.ld /home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/wut_rust_demo-e45af48c9920e099.26rwja7l8px8ogj8.rcgu.o /home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/wut_rust_demo-e45af48c9920e099.26wl4pwofg5ml4cj.rcgu.o /home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/wut_rust_demo-e45af48c9920e099.2f0up282g2pv82ep.rcgu.o /home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/wut_rust_demo-e45af48c9920e099.33w0thwi02pohxp0.rcgu.o /home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/wut_rust_demo-e45af48c9920e099.fin5duuobv10bne.rcgu.o /home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/wut_rust_demo-e45af48c9920e099.6z1fip811supwzl.rcgu.o -L /home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps -L /home/ash/Code/wut-rust-demo/target/debug/deps -L /home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/build/cafeos-sys-6915539a5d0c6b76/out -L /home/ash/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/powerpc-unknown-eabi/lib --start-group -Bstatic /home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/libcafeos-3a893634a527b8e5.rlib /home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/libarrayvec-c9e52e24cea1b8fa.rlib /home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/libcafeos_sys-feb2346b65bf4d2e.rlib /home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/libcty-e513a74c8541530d.rlib /home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/liballoc-cbbab191eb0fa90c.rlib /home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/librustc_std_workspace_core-e311cd3aad6f6119.rlib /home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/libcore-7006cbc5b064dea1.rlib --end-group /home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/libcompiler_builtins-900730f1d1ffb84a.rlib -Bdynamic --eh-frame-hdr -L /home/ash/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/powerpc-unknown-eabi/lib -o /home/ash/Code/wut-rust-demo/target/powerpc-unknown-eabi/debug/deps/wut_rust_demo-e45af48c9920e099
           #0 0x00007f5ae8bab864 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/ash/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-13-rust-1.59.0-nightly.so+0x3256864)
           #1 0x00007f5ae8baba6b SignalHandler(int) Signals.cpp:0:0
           #2 0x00007f5ae5696750 __restore_rt (/lib64/libc.so.6+0x42750)
           #3 0x00000000005c9995 lld::elf::PPC32Got2Section::finalizeContents() (/home/ash/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/rust-lld+0x5c9995)
           #4 0x000000000067e128 (anonymous namespace)::Writer<llvm::object::ELFType<(llvm::support::endianness)0, false> >::finalizeSections() Writer.cpp:0:0
           #5 0x000000000064fc18 void lld::elf::writeResult<llvm::object::ELFType<(llvm::support::endianness)0, false> >() (/home/ash/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/rust-lld+0x64fc18)
           #6 0x00000000004f3e1f void lld::elf::LinkerDriver::link<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::opt::InputArgList&) (/home/ash/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/rust-lld+0x4f3e1f)
           #7 0x00000000004e71f6 lld::elf::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) (/home/ash/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/rust-lld+0x4e71f6)
           #8 0x00000000004e4a9b lld::elf::link(llvm::ArrayRef<char const*>, bool, llvm::raw_ostream&, llvm::raw_ostream&) (/home/ash/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/rust-lld+0x4e4a9b)
           #9 0x00000000004212a5 lldMain(int, char const**, llvm::raw_ostream&, llvm::raw_ostream&, bool) lld.cpp:0:0
          #10 0x0000000000420b94 main (/home/ash/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/rust-lld+0x420b94)
          #11 0x00007f5ae5681560 __libc_start_call_main (/lib64/libc.so.6+0x2d560)
          #12 0x00007f5ae568160c __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2d60c)
          #13 0x00000000004206f5 _start (/home/ash/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/rust-lld+0x4206f5)
```
You can see this issue appear with a fresh environment in CI [here](https://github.com/QuarkTheAwesome/wut-rust-demo/runs/4352947313?check_suite_focus=true), albeit without the backtrace. The stacktrace provided came from `rustc 1.59.0-nightly (91a0600a5 2021-12-18) (from rustc 1.59.0-nightly (db9d361a4 2021-11-28))`'s included LLVM tools.

The issue cropped up after I added [this linker script](https://github.com/QuarkTheAwesome/wut-rust-demo/blob/llvm/cafe.ld) to lay out the binaries correctly. This script works fine on GNU ld, but I'd rather avoid that if I can.

I can try to come up with a more minimal testcase if needed, though I'm unsure where to start with that. The source used [is available in Git](https://github.com/QuarkTheAwesome/wut-rust-demo/tree/46d60093506b7e6903447466b75008337f319a9b), and while the application itself is complex the build process should be a simple `cargo build`.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to