From d1b7a1efd08b3407d1627edce23c506167f215eb Mon Sep 17 00:00:00 2001 From: danieljhkim Date: Fri, 9 Oct 2026 17:27:28 -0700 Subject: [PATCH] bootstrap: add an rpath to libLLVM for the distributed `rust-objcopy` `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 --- src/bootstrap/download-ci-llvm-stamp | 2 +- src/bootstrap/src/core/build_steps/llvm.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/download-ci-llvm-stamp b/src/bootstrap/download-ci-llvm-stamp index 58691539edfa3..7c2096206166d 100644 --- a/src/bootstrap/download-ci-llvm-stamp +++ b/src/bootstrap/download-ci-llvm-stamp @@ -1,4 +1,4 @@ Change this file to make users of the `download-ci-llvm` configuration download a new version of LLVM from CI, even if the LLVM submodule hasn’t changed. -Last change is for: https://github.com/rust-lang/rust/pull/163954 +Last change is for: https://github.com/rust-lang/rust/pull/164064 diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 4ac0f6ea85679..10d6e84b0cc19 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -561,6 +561,24 @@ impl CommandLineStep for Llvm { cfg.define("LLVM_LINK_LLVM_DYLIB", "ON"); // Keep the pre-LLVM23 behavior for now. cfg.define("LLVM_VERSIONED_DYLIB_NAME_ON_DARWIN", "OFF"); + + // `llvm-objcopy` is also shipped in the `rustc` component as + // "$root/lib/rustlib/$host/bin/rust-objcopy", where the default rpath of + // "$ORIGIN/../lib" does not reach the LLVM shared library distributed at "$root/lib". + // Add the same rpath entry as `Lld::run` does for `rust-lld`, so `rust-objcopy` can + // be invoked without rustup's library path overrides or the `llvm-tools` component. + // + // Be careful when changing this path, we need to ensure it's quoted or escaped: + // `$ORIGIN` would otherwise be expanded when the `LdFlags` are passed verbatim to + // cmake. + if builder.config.rpath_enabled(target) && helpers::use_host_linker(target) { + if target.contains("linux") { + ldflags.exe.push(" -Wl,-rpath,'$ORIGIN/../../../'"); + } + if target.contains("apple-darwin") { + ldflags.exe.push(" -Wl,-rpath,'@loader_path/../../../'"); + } + } } if (target.starts_with("csky")