ld.lld segmentation fault
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
this appeared in a large project and I don’t know how to minimize linker bug reproductions, but this reproduces the issue (it requires nix, `nixos/nix` docker container will do):
```
git clone https://git.lix.systems/lix-project/lix
git checkout d9652f26517aa82918cc62ad40e5dddfadd08907
nix --extra-experimental-features 'nix-command flakes' develop '.#native-clangStdenvPackages'
# inside of a devshell
just setup
just build
```
crash backtrace:
```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
#0 0x000070402b73c448 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/nix/store/xhksjsyfasibpqk200g7l7rhaadcdl70-llvm-21.1.8-lib/lib/libLLVM.so.21.1+0xd40448)
#1 0x000070402b7391e7 SignalHandler(int, siginfo_t*, void*) (/nix/store/xhksjsyfasibpqk200g7l7rhaadcdl70-llvm-21.1.8-lib/lib/libLLVM.so.21.1+0xd3d1e7)
#2 0x000070402a48a790 __restore_rt (/nix/store/34dkjp1wxxh6djsvxk8nhvzp0izasds0-glibc-2.42-67/lib/libc.so.6+0x42790)
#3 0x00005b62ed19323d (anonymous namespace)::X86_64::relocateAlloc(lld::elf::InputSectionBase&, unsigned char*) const (/nix/store/bgkcq1y6q5gidmjnzj8qbqhzfmhgd065-llvm-binutils-21.1.8/bin/ld.lld+0x43323d)
#4 0x00005b62ed00ee0d void lld::elf::InputSection::writeTo>(lld::elf::Ctx&, unsigned char*) (/nix/store/bgkcq1y6q5gidmjnzj8qbqhzfmhgd065-llvm-binutils-21.1.8/bin/ld.lld+0x2aee0d)
#5 0x00005b62ed04dbc9 std::_Function_handler>(lld::elf::Ctx&, unsigned char*, llvm::parallel::TaskGroup&)::'lambda'()>::_M_invoke(std::_Any_data const&) (/nix/store/bgkcq1y6q5gidmjnzj8qbqhzfmhgd065-llvm-binutils-21.1.8/bin/ld.lld+0x2edbc9)
#6 0x000070402b67191b std::_Function_handler)::'lambda'()>::_M_invoke(std::_Any_data const&) (/nix/store/xhksjsyfasibpqk200g7l7rhaadcdl70-llvm-21.1.8-lib/lib/libLLVM.so.21.1+0xc7591b)
#7 0x000070402b671a4c std::thread::_State_impl>>::_M_run() (/nix/store/xhksjsyfasibpqk200g7l7rhaadcdl70-llvm-21.1.8-lib/lib/libLLVM.so.21.1+0xc75a4c)
#8 0x000070402a86cfa4 execute_native_thread_routine (/nix/store/n35z8vvlr7c5k1406n5bwd0f8h2hgj1j-gcc-15.2.0-lib/lib/libstdc++.so.6+0xf2fa4)
#9 0x000070402a4e5d53 start_thread (/nix/store/34dkjp1wxxh6djsvxk8nhvzp0izasds0-glibc-2.42-67/lib/libc.so.6+0x9dd53)
#10 0x000070402a56d63c __GI___clone3 (/nix/store/34dkjp1wxxh6djsvxk8nhvzp0izasds0-glibc-2.42-67/lib/libc.so.6+0x12563c)
/nix/store/wjg9d2laxplmlllgxragzqxzq3c0i5c7-llvm-binutils-wrapper-21.1.8/bin/ld.lld: line 292: 99638 Segmentation fault (core dumped) /nix/store/bgkcq1y6q5gidmjnzj8qbqhzfmhgd065-llvm-binutils-21.1.8/bin/ld.lld ${extraBefore+"${extraBefore[@]}"} ${params+"${params[@]}"} ${extraAfter+"${extraAfter[@]}"}
clang++: error: linker command failed with exit code 139 (use -v to see invocation)
```
devshell uses `ld.lld 21.1.8` by default, but I verified that it also reproduces with `ld.lld 22.1.5`
you can verify this by adding `llvmPackages = pkgs.llvmPackages_22;` in `flake.nix` after line 191 (`nix = pkgs.callPackage ./package.nix {`) before running `nix develop`. you can get an editor to do this in a docker container by running `nix-shell -p vim`.
crash backtrace for that version is the same
Contributor guide
Research direction
Reproduce the crash in the Lix checkout using the Nix devshell and `just setup` followed by `just build`. Start with the `X86_64::relocateAlloc` frame in lld's ELF linker path and compare behavior with LLVM 21.1.8 and 22.1.5. Done means the build no longer causes `ld.lld` to segfault, ideally with a minimized reproducer for the failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100