Repository navigation
Conversation
This was referenced Sep 16, 2026
rustc passes a handful of GNU-driver flags when reld is the direct `CARGO_TARGET_*_LINKER` (as `SOLDR_LINKER=reld` makes it). reld's native ELF parser rejected them, so the build failed before reaching a real link. - `-m64` maps to x86-64 (and `-m32` is rejected with a clear message). - Expand `-Wl,<flags>` pass-through args (split on commas) so `-Wl,-z,relro,-z,now` parses as `-z relro -z now`. - `-B<prefix>`: no-op (reld is the linker, it never invokes gcc-ld). - `-nodefaultlibs`: no-op (reld adds no default libraries of its own). Progress toward `SOLDR_LINKER=reld` on native GNU targets. Co-Authored-By: Claude Code <[email protected]>
reld had no default library search paths, so as a direct linker it couldn't resolve `-lgcc_s`, `-lc`, etc. (which the gcc driver normally supplies). Add `LIBRARY_PATH` and the common multiarch/system dirs. Co-Authored-By: Claude Code <[email protected]>
reld left `dynamic_linker` unset, so dynamically-linked output had no PT_INTERP segment and segfaulted at startup (the kernel can't load the interpreter). Default to the per-architecture interpreter when `--dynamic-linker` isn't given. Co-Authored-By: Claude Code <[email protected]>
A direct linker (reld, as opposed to the gcc/clang driver) must supply the CRT startup objects itself — otherwise the output has no `_start` symbol and the entry point silently falls back to the .text start, producing a binary that segfaults at startup (PC=0x0/0x1). Locate crt1/crti/crtbegin (prefix) and crtend/crtn (suffix) via `cc -print-file-name` and inject them around the user's inputs for executables only. Co-Authored-By: Claude Code <[email protected]>
reld hardcoded /usr/lib, /lib, etc. — fine on FHS systems, but it could not find libgcc_s/libc in non-FHS environments (Nix) where those live in store paths reachable only through the gcc driver's own search dirs. Query `cc -print-search-dirs` and add its `libraries:` list. Those dirs are driver defaults, not user `-L` flags, so they must not seed the Nix RUNPATH derivation (which mirrors nixpkgs' ld-wrapper and keys off `-L` alone). Record the user-`-L` boundary in `user_lib_search_path_len` and have the derivation honor it. Co-Authored-By: Claude Code <[email protected]>
When reld is driven via `clang -fuse-ld=reld` (the consumer-acceptance path), the clang driver already injects Scrt1.o/crti.o/crtbegin.o on the command line. reld's own CRT injection then added them a second time, producing 'Duplicate symbols detected: _IO_stdin_used'. Detect whether a CRT startup object is already among the inputs and skip injection in that case — direct `-C linker=reld` invocation (rustc, no driver) still injects. Co-Authored-By: Claude Code <[email protected]>
zackees
force-pushed
the
fix/native-gnu-linker-flags
branch
from
September 16, 2026 01:53
c6cdde9 to
180f02c
Compare
Standalone fixtures (e.g. the linker-diff corpus) compile their own `_start` and link without CRT; injecting crt1.o then yields a duplicate `_start`. Scan the plain object inputs for a `_start` definition and skip injection when present, so reld matches the direct-linker behaviour of mold/wild/lld there while still supplying CRT for rustc's `-C linker=reld` path. Co-Authored-By: Claude Code <[email protected]>
Collaborator
Author
|
Closing: reld needs no changes. It already works as a pure linker via |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Progress toward making reld usable as a direct linker via
SOLDR_LINKER=reldon native GNU targets. Five gaps fixed so far:-m64maps to x86-64 (reject-m32clearly),-Wl,<flags>pass-through is expanded,-B<prefix>is a no-op,-nodefaultlibsis ignored.-L; it now honorsLIBRARY_PATHand the compiler driver's owncc -print-search-dirslibraries:list (so-lgcc_s/-lc/etc. resolve even in non-FHS environments like Nix), plus common system dirs. These driver dirs are kept out of the Nix RUNPATH derivation.PT_INTERP—dynamic_linkerwas unset, so dynamically-linked output had no interpreter and segfaulted at startup. Now defaults per architecture (/lib64/ld-linux-x86-64.so.2on x86-64).crt1.o/crti.o/crtbegin.o(prefix) andcrtend.o/crtn.o(suffix) itself, or the output has no_startand the entry point silently falls back to.text, segfaulting at startup. reld now locates them viacc -print-file-nameand injects them around the user's inputs for executables.Validation
cargo test -p reld-core— 188 passed.CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=reld cargo build -p reldnow produces a runnable binary:./target/release/reld --versionprints the version and exits 0. The output has a properPT_INTERPand_startentry point (verified viareadelf/nm), and no RUNPATH pollution from the driver dirs.Co-Authored-By: Claude Code [email protected]