Repository navigation
Conversation
Mirror nixpkgs' ld-wrapper.sh so a linker reached through -fuse-ld produces the same RUNPATH on NixOS. For each -L directory under the Nix store (NIX_STORE, default /nix/store) that provides a shared library named by a linked -l flag, append it to RUNPATH after any explicit -rpath entries. The directory of a store .so passed by path is also added. Disabled by NIX_DONT_SET_RPATH=1 and overridable with --nix-rpath=auto|on|off. Closes #110. Co-Authored-By: Claude Code <[email protected]>
The test builds ELF shared objects with cc, which only works on Linux; gate it so macOS/Windows --all-targets builds compile it out. Co-Authored-By: Claude Code <[email protected]>
9 of 31 tasks
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.
Summary
Implements reld's half of #110: bake nixpkgs'
ld-wrapper.shRUNPATH rule into reld's ELF path, so a binary linked through-fuse-ld=reldon NixOS gets the sameDT_RUNPATHit would get from theldwrapper — without depending on that wrapper (which-fuse-ldbypasses).Behavior
When targeting a dynamic ELF output and a Nix store is in use (
NIX_STORE, default/nix/store):-L <dir>under the store, in command-line order, add<dir>to RUNPATH if it provideslib<name>.sofor a linked-l<name>..sogiven by path.-rpathentries keep their position first; derived entries follow (matching the wrapper'sextraAfterplacement).NIX_DONT_SET_RPATH=1, and overridable with--nix-rpath=auto|on|off(for hermetic builds).When no store paths are involved, nothing changes — output is byte-identical to today. Static (non-PIE) and relocatable outputs never emit a dynamic section, so no RUNPATH is written for them regardless.
Implementation
crates/reld-core/src/args/elf.rs:NixRpathMode { Auto, On, Off }and--nix-rpathflag.ElfArgs::add_nix_rpath_entriesreadsNIX_STORE/NIX_DONT_SET_RPATHand appends derived entries torpath_setafter explicit-rpathentries. The derivation is split intoadd_nix_rpath_entries_withso it can be exercised without touching the environment.Tests
args/elf.rscovering: store-dir derivation, non-store skip, no-lib skip,NIX_DONT_SET_RPATH,on/offmodes, direct.sopath, explicit-first ordering, dedup, and flag parsing.crates/reld/tests/nix_rpath.rs) that compile a real shared lib withcc, link it with reld under a fakeNIX_STORE, and assertDT_RUNPATHvia theobjectcrate: derivation,NIX_DONT_SET_RPATH=1disables, and non-store dir yields no RUNPATH.Verified end-to-end on this machine (NixOS):
NIX_STORE=$dir reld -shared -o out.so main.o -L $dir/lib -lfooemitsDT_RUNPATH=[$dir/lib]andlddresolveslibfoo.so.Closes #110.
🤖 Generated with Claude Code