Skip to content

Commit

Permalink
Auto merge of rust-lang#122911 - Nilstrieb:live-love-patch, r=clubby789
Browse files Browse the repository at this point in the history
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 rust-lang#122906
  • Loading branch information
bors committed Mar 23, 2024
2 parents c308726 + 60b97a2 commit c3b05c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
12 changes: 9 additions & 3 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,14 @@ def download_toolchain(self):
self.fix_bin_or_dylib("{}/libexec/rust-analyzer-proc-macro-srv".format(bin_root))
lib_dir = "{}/lib".format(bin_root)
for lib in os.listdir(lib_dir):
if lib.endswith(".so"):
self.fix_bin_or_dylib(os.path.join(lib_dir, lib))
# .so is not necessarily the suffix, there can be version numbers afterwards.
if ".so" in lib:
elf_path = os.path.join(lib_dir, lib)
with open(elf_path, "rb") as f:
magic = f.read(4)
# Patchelf will skip non-ELF files, but issue a warning.
if magic == b"\x7fELF":
self.fix_bin_or_dylib(elf_path)

with output(self.rustc_stamp()) as rust_stamp:
rust_stamp.write(key)
Expand Down Expand Up @@ -725,7 +731,7 @@ def fix_bin_or_dylib(self, fname):
os.path.join(os.path.realpath(nix_deps_dir), "lib")
]
patchelf_args = ["--set-rpath", ":".join(rpath_entries)]
if not fname.endswith(".so"):
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:
patchelf_args += ["--set-interpreter", dynamic_linker.read().rstrip()]
Expand Down
15 changes: 10 additions & 5 deletions src/bootstrap/src/core/download.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
env,
ffi::{OsStr, OsString},
ffi::OsString,
fs::{self, File},
io::{BufRead, BufReader, BufWriter, ErrorKind, Write},
path::{Path, PathBuf},
Expand Down Expand Up @@ -183,7 +183,7 @@ impl Config {
entries
};
patchelf.args(&[OsString::from("--set-rpath"), rpath_entries]);
if !fname.extension().map_or(false, |ext| ext == "so") {
if !path_is_dylib(fname) {
// Finally, set the correct .interp for binaries
let dynamic_linker_path = nix_deps_dir.join("nix-support/dynamic-linker");
// FIXME: can we support utf8 here? `args` doesn't accept Vec<u8>, only OsString ...
Expand Down Expand Up @@ -440,7 +440,7 @@ impl Config {
let lib_dir = bin_root.join("lib");
for lib in t!(fs::read_dir(&lib_dir), lib_dir.display().to_string()) {
let lib = t!(lib);
if lib.path().extension() == Some(OsStr::new("so")) {
if path_is_dylib(&lib.path()) {
self.fix_bin_or_dylib(&lib.path());
}
}
Expand Down Expand Up @@ -545,7 +545,7 @@ impl Config {
let lib_dir = bin_root.join("lib");
for lib in t!(fs::read_dir(&lib_dir), lib_dir.display().to_string()) {
let lib = t!(lib);
if lib.path().extension() == Some(OsStr::new("so")) {
if path_is_dylib(&lib.path()) {
self.fix_bin_or_dylib(&lib.path());
}
}
Expand Down Expand Up @@ -697,7 +697,7 @@ download-rustc = false
let llvm_lib = llvm_root.join("lib");
for entry in t!(fs::read_dir(llvm_lib)) {
let lib = t!(entry).path();
if lib.extension().map_or(false, |ext| ext == "so") {
if path_is_dylib(&lib) {
self.fix_bin_or_dylib(&lib);
}
}
Expand Down Expand Up @@ -743,3 +743,8 @@ download-rustc = false
self.unpack(&tarball, &llvm_root, "rust-dev");
}
}

fn path_is_dylib(path: &Path) -> bool {
// The .so is not necessarily the extension, it might be libLLVM.so.18.1
path.to_str().map_or(false, |path| path.contains(".so"))
}

0 comments on commit c3b05c6

Please sign in to comment.