Skip to content

Commit c3b05c6

Browse files
committed
Auto merge of #122911 - Nilstrieb:live-love-patch, r=clubby789
Fix nix patching for LLVM 18 LLVM 18 now ships `libLLVM*.so.*`, so `.so` is not the sole extension anymore, which breaks the dylib detection. Oops! Adjust it to only search for `.so` somewhere. fixes #122906
2 parents c308726 + 60b97a2 commit c3b05c6

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/bootstrap/bootstrap.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,14 @@ def download_toolchain(self):
612612
self.fix_bin_or_dylib("{}/libexec/rust-analyzer-proc-macro-srv".format(bin_root))
613613
lib_dir = "{}/lib".format(bin_root)
614614
for lib in os.listdir(lib_dir):
615-
if lib.endswith(".so"):
616-
self.fix_bin_or_dylib(os.path.join(lib_dir, lib))
615+
# .so is not necessarily the suffix, there can be version numbers afterwards.
616+
if ".so" in lib:
617+
elf_path = os.path.join(lib_dir, lib)
618+
with open(elf_path, "rb") as f:
619+
magic = f.read(4)
620+
# Patchelf will skip non-ELF files, but issue a warning.
621+
if magic == b"\x7fELF":
622+
self.fix_bin_or_dylib(elf_path)
617623

618624
with output(self.rustc_stamp()) as rust_stamp:
619625
rust_stamp.write(key)
@@ -725,7 +731,7 @@ def fix_bin_or_dylib(self, fname):
725731
os.path.join(os.path.realpath(nix_deps_dir), "lib")
726732
]
727733
patchelf_args = ["--set-rpath", ":".join(rpath_entries)]
728-
if not fname.endswith(".so"):
734+
if ".so" not in fname:
729735
# Finally, set the correct .interp for binaries
730736
with open("{}/nix-support/dynamic-linker".format(nix_deps_dir)) as dynamic_linker:
731737
patchelf_args += ["--set-interpreter", dynamic_linker.read().rstrip()]

src/bootstrap/src/core/download.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
env,
3-
ffi::{OsStr, OsString},
3+
ffi::OsString,
44
fs::{self, File},
55
io::{BufRead, BufReader, BufWriter, ErrorKind, Write},
66
path::{Path, PathBuf},
@@ -183,7 +183,7 @@ impl Config {
183183
entries
184184
};
185185
patchelf.args(&[OsString::from("--set-rpath"), rpath_entries]);
186-
if !fname.extension().map_or(false, |ext| ext == "so") {
186+
if !path_is_dylib(fname) {
187187
// Finally, set the correct .interp for binaries
188188
let dynamic_linker_path = nix_deps_dir.join("nix-support/dynamic-linker");
189189
// FIXME: can we support utf8 here? `args` doesn't accept Vec<u8>, only OsString ...
@@ -440,7 +440,7 @@ impl Config {
440440
let lib_dir = bin_root.join("lib");
441441
for lib in t!(fs::read_dir(&lib_dir), lib_dir.display().to_string()) {
442442
let lib = t!(lib);
443-
if lib.path().extension() == Some(OsStr::new("so")) {
443+
if path_is_dylib(&lib.path()) {
444444
self.fix_bin_or_dylib(&lib.path());
445445
}
446446
}
@@ -545,7 +545,7 @@ impl Config {
545545
let lib_dir = bin_root.join("lib");
546546
for lib in t!(fs::read_dir(&lib_dir), lib_dir.display().to_string()) {
547547
let lib = t!(lib);
548-
if lib.path().extension() == Some(OsStr::new("so")) {
548+
if path_is_dylib(&lib.path()) {
549549
self.fix_bin_or_dylib(&lib.path());
550550
}
551551
}
@@ -697,7 +697,7 @@ download-rustc = false
697697
let llvm_lib = llvm_root.join("lib");
698698
for entry in t!(fs::read_dir(llvm_lib)) {
699699
let lib = t!(entry).path();
700-
if lib.extension().map_or(false, |ext| ext == "so") {
700+
if path_is_dylib(&lib) {
701701
self.fix_bin_or_dylib(&lib);
702702
}
703703
}
@@ -743,3 +743,8 @@ download-rustc = false
743743
self.unpack(&tarball, &llvm_root, "rust-dev");
744744
}
745745
}
746+
747+
fn path_is_dylib(path: &Path) -> bool {
748+
// The .so is not necessarily the extension, it might be libLLVM.so.18.1
749+
path.to_str().map_or(false, |path| path.contains(".so"))
750+
}

0 commit comments

Comments
 (0)