Skip to content

Commit 1def498

Browse files
committed
Auto merge of #126692 - DianQK:nixos-patchelf, r=Nilstrieb
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.
2 parents 7033f9b + 80e43c1 commit 1def498

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

src/bootstrap/bootstrap.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,9 @@ def download_toolchain(self):
617617
self.fix_bin_or_dylib("{}/bin/rustdoc".format(bin_root))
618618
self.fix_bin_or_dylib("{}/libexec/rust-analyzer-proc-macro-srv".format(bin_root))
619619
lib_dir = "{}/lib".format(bin_root)
620+
rustlib_bin_dir = "{}/rustlib/{}/bin".format(lib_dir, self.build)
621+
self.fix_bin_or_dylib("{}/rust-lld".format(rustlib_bin_dir))
622+
self.fix_bin_or_dylib("{}/gcc-ld/ld.lld".format(rustlib_bin_dir))
620623
for lib in os.listdir(lib_dir):
621624
# .so is not necessarily the suffix, there can be version numbers afterwards.
622625
if ".so" in lib:
@@ -731,12 +734,9 @@ def fix_bin_or_dylib(self, fname):
731734

732735
patchelf = "{}/bin/patchelf".format(nix_deps_dir)
733736
rpath_entries = [
734-
# Relative default, all binary and dynamic libraries we ship
735-
# appear to have this (even when `../lib` is redundant).
736-
"$ORIGIN/../lib",
737737
os.path.join(os.path.realpath(nix_deps_dir), "lib")
738738
]
739-
patchelf_args = ["--set-rpath", ":".join(rpath_entries)]
739+
patchelf_args = ["--add-rpath", ":".join(rpath_entries)]
740740
if ".so" not in fname:
741741
# Finally, set the correct .interp for binaries
742742
with open("{}/nix-support/dynamic-linker".format(nix_deps_dir)) as dynamic_linker:

src/bootstrap/src/core/download.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,10 @@ impl Config {
173173
}
174174

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

0 commit comments

Comments
 (0)