Skip to content

port(MachO): emit LC_RPATH load commands - #2679

Merged
marxin merged 3 commits into
wild-linker:mainfrom
jadenfix:macho-lc-rpath
Oct 6, 2026
Merged

marxin merged 3 commits into
wild-linker:mainfrom
jadenfix:macho-lc-rpath

Conversation

@jadenfix

@jadenfix jadenfix commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Closes #2677

-rpath was parsed but ignored on Mach-O. Now each value gets its own LC_RPATH command, written directly after the LC_LOAD_DYLIB commands. Duplicates are dropped like ld64 does.

Added a Mach-O rpath test that makes sure the paths end up in the binary. Also compared otool -l output against Apple's ld and confirmed the commands match. Tested with both Apple ld and lld 23.1.2; init-offsets2 fails on my machine with or without this change.

Emit one LC_RPATH command per -rpath value instead of ignoring the
option. Repeated paths are dropped, as ld64 does.

@marxin marxin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution.

Note the option is commonly used with @ (e.g. -Wl,-rpath,@loader_path/../lib) and we should double check our save_dir.rs code can properly escape it (if needed).

Comment thread libwild/src/macho.rs Outdated
-headerpad_max_install_names now leaves MAXPATHLEN of room for each
LC_RPATH command as well as each LC_LOAD_DYLIB, so install_name_tool
can rewrite an rpath in place.
With WILD_SAVE_DIR set, `-rpath @loader_path/../lib` failed the link
because save-dir tried to read `loader_path/../lib` as a response file.
Response files have already been read by the argument parser, so only
treat an `@` argument as one if the file exists.

@marxin marxin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for your first contribution.

@marxin
marxin enabled auto-merge (squash) October 6, 2026 18:38
@marxin
marxin merged commit 2ed9a2e into wild-linker:main Oct 6, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mach-O: emit LC_RPATH load command

3 participants