Skip to content

bootstrap: add an rpath to libLLVM for the distributed rust-objcopy - #164064

Closed
danieljhkim wants to merge 1 commit into
rust-lang:mainfrom
danieljhkim:fix-rust-objcopy-rpath
Closed

danieljhkim wants to merge 1 commit into
rust-lang:mainfrom
danieljhkim:fix-rust-objcopy-rpath

Conversation

@danieljhkim

@danieljhkim danieljhkim commented Oct 10, 2026 •

Copy link
Copy Markdown

Fixes #164063.

rust-objcopy is a renamed copy of llvm-objcopy, shipped in the rustc component at lib/rustlib/$host/bin/. When LLVM is linked dynamically, the copy keeps LLVM's default rpath, $ORIGIN/../lib (@loader_path/../lib on darwin). That resolves to lib/rustlib/$host/lib/, but the rustc component ships libLLVM only in lib/. So rust-objcopy fails to load unless rustup's LD_LIBRARY_PATH/DYLD_FALLBACK_LIBRARY_PATH override is in effect or the llvm-tools component is installed. rustc runs it to strip debuginfo, and it reports a failed strip only as a warning, so release binaries silently keep their debuginfo.

#163954 fixed the same problem for rust-lld in Lld::run. rust-objcopy is built by the Llvm step instead, so that fix doesn't reach it. This PR adds the same rpath entry, $ORIGIN/../../../ on Linux and @loader_path/../../../ on darwin, to the executable linker flags of the main LLVM build, behind the same rpath_enabled/use_host_linker guards. The extra entry only adds a search path for the other LLVM tools: in llvm-tools, those still resolve through rustlib/$host/lib.

Observed on 1.98.1 outside rustup's overrides:

  • aarch64-apple-darwin: dyld aborts with Library not loaded: @rpath/libLLVM.dylib (SIGABRT). This is a regression since Link LLVM dynamically on aarch64-apple-darwin #157205.
  • x86_64-unknown-linux-gnu: libLLVM.so.22.1-rust-1.98.1-stable: cannot open shared object file. The same $ORIGIN/../lib-only runpath is present back to at least 1.89.

Testing

  • cargo check of bootstrap and rustfmt --check pass.
  • I validated the rpath value by hand on a copy of the 1.98.1 darwin toolchain layout. rust-objcopy exits with SIGABRT as shipped, and works after install_name_tool -add_rpath @loader_path/../../../ and an ad-hoc re-sign.
  • I have not run a full ./x dist locally. Like fix(bootstrap/darwin): fix rpath for distributed LLD #163954, there doesn't seem to be a dist test that covers this, so CI artifacts are the real check.

The download-ci-llvm-stamp is bumped because CI LLVM artifacts change.

cc @rami3l @sgasho

Disclosure: the diagnosis, patch and description were produced with an LLM (Claude). I reviewed them and checked the observations above on my own machines.

🤖 Generated with Claude Code

@rustbot

rustbot commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

This PR changes how LLVM is built. Consider updating src/bootstrap/download-ci-llvm-stamp.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Oct 10, 2026
@rustbot

rustbot commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @clubby789 (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: bootstrap
  • bootstrap expanded to 6 candidates
  • Random selection from Mark-Simulacrum, clubby789

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

`rust-objcopy` is a renamed copy of `llvm-objcopy` shipped in the `rustc`
component at `lib/rustlib/$host/bin`. When LLVM is linked dynamically it
only carries LLVM's default `$ORIGIN/../lib` (`@loader_path/../lib` on
darwin) rpath, which does not reach the `libLLVM` shipped in `lib/`, so it
fails to load outside rustup's library path overrides.

Mirror the rpath entry `Lld::run` already adds for `rust-lld` on the LLVM
tools themselves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@danieljhkim
danieljhkim force-pushed the fix-rust-objcopy-rpath branch from 7cab71b to d1b7a1e Compare October 10, 2026 00:32
@clubby789

Copy link
Copy Markdown
Contributor

Per our LLM policy, LLMs must not be used to create code, comments and PRs without prior agreement. You can join the LLM mentoring Zulip channel if you want to pre-arrange a reviewer for an LLM-written PR, or write the changes yourself and open a new PR.

@clubby789 clubby789 closed this Oct 10, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rust-objcopy on aarch64-apple-darwin cannot load libLLVM.dylib (rpath @loader_path/../lib); not covered by #163954

3 participants