You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
elf: linked binaries segfault at startup (dynamic relocations resolve to bad addresses) #117
reld's native ELF backend produces binaries that segfault at startup — the dynamic relocations resolve to a bogus address.
Evidence (after the flag / library-path / PT_INTERP fixes in #115)
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=reld cargo build -p reld now links, but every linked build-script binary crashes on launch:
Program received signal SIGSEGV (PC = 0x0000000000000001)
The output is a DYN (PIE) with 453 R_X86_64_RELATIVE, 45 R_X86_64_GLOB_DAT, and 1 R_X86_64_64 dynamic relocations, plus a correct PT_INTERP (/lib64/ld-linux-x86-64.so.2). The PC landing at 0x1 means a GOT/PLT slot (or a R_X86_64_RELATIVE addend) resolves to an invalid address — the dynamic-relocation computation is wrong.
Fix
Trace reld's dynamic-relocation emission/resolution for R_X86_64_RELATIVE/R_X86_64_GLOB_DAT (and the GOT/PLT layout) so each slot resolves to load_base + addend (or the correct symbol address) rather than 0x1. A minimal repro is any -C relocation-model=pic Rust build linked with reld.
__dso_handle emitted as a dynamic relocation for an undefined symbol.readelf -rW shows a lone R_X86_64_64 targeting __dso_handle, which is UND WEAK (dynsym Position reld as a wild successor; add test, stress, and benchmark infrastructure #1). Rust actually provides it via the local _rust_extern_with_linkage_…___dso_handle symbol (a LOCAL OBJECT at the same address). reld emits a dynamic relocation against the undefined__dso_handle instead of resolving it to that local definition — so at runtime the slot resolves to 0 (weak undef) rather than the real __dso_handle address.
Startup crash is a jump to 0x1 (not 0): a GOT/PLT/function-pointer slot resolves to 0x1. Relocations present: 453 R_X86_64_RELATIVE, 45 R_X86_64_GLOB_DAT, 1 R_X86_64_64. No R_X86_64_JUMP_SLOT (expected for -z now/PIE). The 0x1 strongly suggests an unrelocated or mis-resolved GOT slot.
Repro: CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=reld cargo build -p reld (any Rust build with reld as the direct linker).
Root cause found — it's not a relocation bug, it's missing CRT startup objects.
rustc passes -B<sysroot>/…/bin/gcc-ld and the object files, but notcrt1.o////. The gcc driver normally injects those; a direct linker (reld) must supply them itself.
So reld's output has no _start symbol, and elf_entry_address falls back to the .text section start (0x12ad0 = __rust_alloc) instead of _start.
The program then starts executing __rust_alloc → jmp __rdl_alloc with garbage registers, which is the observed startup crash (PC eventually lands at 0x1).
_start is confirmed absent from reld's output (readelf -sW) but present in cc-linked binaries (nm target/release/reld | grep _start → T _start), and absent from the std rlib (it comes from crt1.o).
Fix: link the CRT startup objects for executables — locate crt1.o (or Scrt1.o for PIE) + crti.o/// (via the -B prefix / gcc -print-file-name / system CRT dirs) and add them to the link so _start is defined.
Re-diagnosed and resolved differently than filed. The 'segfault at startup' was not bad dynamic relocations — it was a missing _start: a direct -C linker=reld invocation has no CRT startup objects, so the entry point fell back to .text and the binary jumped to address 0/1.
Resolution: reld is a pure linker and is not meant to inject the CRT itself (its correctness oracle in crates/reld/tests/acceptance.rs compares against lld/mold/wild, which also don't inject CRT). The fix is to drive reld through the clang driver (clang --ld-path=reld), which injects CRT + -dynamic-linker. This is done on the soldr side in soldr#3261.
Activity
zackees commentedon Sep 16, 2026
Deeper findings from live debugging:
__dso_handleemitted as a dynamic relocation for an undefined symbol.readelf -rWshows a loneR_X86_64_64targeting__dso_handle, which isUND WEAK(dynsym Position reld as a wild successor; add test, stress, and benchmark infrastructure #1). Rust actually provides it via the local_rust_extern_with_linkage_…___dso_handlesymbol (aLOCAL OBJECTat the same address). reld emits a dynamic relocation against the undefined__dso_handleinstead of resolving it to that local definition — so at runtime the slot resolves to 0 (weak undef) rather than the real__dso_handleaddress.Startup crash is a jump to
0x1(not 0): a GOT/PLT/function-pointer slot resolves to0x1. Relocations present: 453R_X86_64_RELATIVE, 45R_X86_64_GLOB_DAT, 1R_X86_64_64. NoR_X86_64_JUMP_SLOT(expected for-z now/PIE). The0x1strongly suggests an unrelocated or mis-resolved GOT slot.Repro:
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=reld cargo build -p reld(any Rust build with reld as the direct linker).zackees commentedon Sep 16, 2026
Root cause found — it's not a relocation bug, it's missing CRT startup objects.
-B<sysroot>/…/bin/gcc-ldand the object files, but notcrt1.o////. The gcc driver normally injects those; a direct linker (reld) must supply them itself._startsymbol, andelf_entry_addressfalls back to the.textsection start (0x12ad0 =__rust_alloc) instead of_start.__rust_alloc→jmp __rdl_allocwith garbage registers, which is the observed startup crash (PC eventually lands at 0x1)._startis confirmed absent from reld's output (readelf -sW) but present in cc-linked binaries (nm target/release/reld | grep _start→T _start), and absent from the std rlib (it comes fromcrt1.o).Fix: link the CRT startup objects for executables — locate
crt1.o(orScrt1.ofor PIE) +crti.o/// (via the-Bprefix /gcc -print-file-name/ system CRT dirs) and add them to the link so_startis defined.zackees commentedon Sep 16, 2026
Re-diagnosed and resolved differently than filed. The 'segfault at startup' was not bad dynamic relocations — it was a missing
_start: a direct-C linker=reldinvocation has no CRT startup objects, so the entry point fell back to.textand the binary jumped to address 0/1.Resolution: reld is a pure linker and is not meant to inject the CRT itself (its correctness oracle in
crates/reld/tests/acceptance.rscompares against lld/mold/wild, which also don't inject CRT). The fix is to drive reld through the clang driver (clang --ld-path=reld), which injects CRT +-dynamic-linker. This is done on the soldr side in soldr#3261.