Skip to content

Commit

Permalink
Rollup merge of #133462 - mustartt:aix-improve-bootstrap-loading, r=j…
Browse files Browse the repository at this point in the history
…ieyouxu

Use ReadCache for archive reading in bootstrap

Address expensive archive reading in bootstrap. This fixes #133268

Enable the `std` feature of `object` to use `ReadCache` instead of reading the entire archive file into memory to check for headers. This takes minimal extra time to compile compared to introducing other expensive dependencies to `bootstrap`.

r? jieyouxu
  • Loading branch information
GuillaumeGomez authored Nov 26, 2024
2 parents 64c0eff + 9f1cfec commit 7e3422f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ fn attempt_load_dylib(path: &Path) -> Result<libloading::Library, libloading::Er
// the expected format is lib<name>.a(libname.so) for the actual
// dynamic library
let library_name = path.file_stem().expect("expect a library name");
let mut archive_member = OsString::from("a(");
let mut archive_member = std::ffi::OsString::from("a(");
archive_member.push(library_name);
archive_member.push(".so)");
let new_path = path.with_extension(archive_member);
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fd-lock = "4.0"
home = "0.5"
ignore = "0.4"
libc = "0.2"
object = { version = "0.36.3", default-features = false, features = ["archive", "coff", "read_core", "unaligned"] }
object = { version = "0.36.3", default-features = false, features = ["archive", "coff", "read_core", "std", "unaligned"] }
opener = "0.5"
semver = "1.0"
serde = "1.0"
Expand Down
14 changes: 7 additions & 7 deletions src/bootstrap/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ pub fn is_dylib(path: &Path) -> bool {
}

fn is_aix_shared_archive(path: &Path) -> bool {
// FIXME(#133268): reading the entire file as &[u8] into memory seems excessive
// look into either mmap it or use the ReadCache
let data = match fs::read(path) {
Ok(data) => data,
let file = match fs::File::open(path) {
Ok(file) => file,
Err(_) => return false,
};
let file = match ArchiveFile::parse(&*data) {
Ok(file) => file,
let reader = object::ReadCache::new(file);
let archive = match ArchiveFile::parse(&reader) {
Ok(result) => result,
Err(_) => return false,
};

file.members()
archive
.members()
.filter_map(Result::ok)
.any(|entry| String::from_utf8_lossy(entry.name()).contains(".so"))
}
Expand Down

0 comments on commit 7e3422f

Please sign in to comment.