Skip to content

Commit

Permalink
Auto merge of #126692 - DianQK:nixos-patchelf, r=Nilstrieb
Browse files Browse the repository at this point in the history
patch `rust-lld` and `ld.lld` on NixOS

When `rustc` uses its self-contained lld, we also need to patch `rust-lld` and `ld.lld`.
The `rpath` for `rust-lld` is `$ORIGIN/../../../:$ORIGIN/../lib`, so I use `--add-rpath` instead of `--set-rpath`, which should be easier to maintain.

I also changed `src/bootstrap/src/core/download.rs`, even this doesn't fix any known issues.

For the `lld-wrapper.sh` of lld, refer to: rust-lang/rustc-dev-guide#1999.
  • Loading branch information
bors committed Jun 27, 2024
2 parents 7033f9b + 80e43c1 commit 1def498
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,9 @@ def download_toolchain(self):
self.fix_bin_or_dylib("{}/bin/rustdoc".format(bin_root))
self.fix_bin_or_dylib("{}/libexec/rust-analyzer-proc-macro-srv".format(bin_root))
lib_dir = "{}/lib".format(bin_root)
rustlib_bin_dir = "{}/rustlib/{}/bin".format(lib_dir, self.build)
self.fix_bin_or_dylib("{}/rust-lld".format(rustlib_bin_dir))
self.fix_bin_or_dylib("{}/gcc-ld/ld.lld".format(rustlib_bin_dir))
for lib in os.listdir(lib_dir):
# .so is not necessarily the suffix, there can be version numbers afterwards.
if ".so" in lib:
Expand Down Expand Up @@ -731,12 +734,9 @@ def fix_bin_or_dylib(self, fname):

patchelf = "{}/bin/patchelf".format(nix_deps_dir)
rpath_entries = [
# Relative default, all binary and dynamic libraries we ship
# appear to have this (even when `../lib` is redundant).
"$ORIGIN/../lib",
os.path.join(os.path.realpath(nix_deps_dir), "lib")
]
patchelf_args = ["--set-rpath", ":".join(rpath_entries)]
patchelf_args = ["--add-rpath", ":".join(rpath_entries)]
if ".so" not in fname:
# Finally, set the correct .interp for binaries
with open("{}/nix-support/dynamic-linker".format(nix_deps_dir)) as dynamic_linker:
Expand Down
13 changes: 4 additions & 9 deletions src/bootstrap/src/core/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,10 @@ impl Config {
}

let mut patchelf = Command::new(nix_deps_dir.join("bin/patchelf"));
let rpath_entries = {
// ORIGIN is a relative default, all binary and dynamic libraries we ship
// appear to have this (even when `../lib` is redundant).
// NOTE: there are only two paths here, delimited by a `:`
let mut entries = OsString::from("$ORIGIN/../lib:");
entries.push(t!(fs::canonicalize(nix_deps_dir)).join("lib"));
entries
};
patchelf.args(&[OsString::from("--set-rpath"), rpath_entries]);
patchelf.args(&[
OsString::from("--add-rpath"),
OsString::from(t!(fs::canonicalize(nix_deps_dir)).join("lib")),
]);
if !path_is_dylib(fname) {
// Finally, set the correct .interp for binaries
let dynamic_linker_path = nix_deps_dir.join("nix-support/dynamic-linker");
Expand Down

0 comments on commit 1def498

Please sign in to comment.