Skip to content

Commit 7e3422f

Browse files
Rollup merge of rust-lang#133462 - mustartt:aix-improve-bootstrap-loading, r=jieyouxu
Use ReadCache for archive reading in bootstrap Address expensive archive reading in bootstrap. This fixes rust-lang#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
2 parents 64c0eff + 9f1cfec commit 7e3422f

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

compiler/rustc_metadata/src/creader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ fn attempt_load_dylib(path: &Path) -> Result<libloading::Library, libloading::Er
11721172
// the expected format is lib<name>.a(libname.so) for the actual
11731173
// dynamic library
11741174
let library_name = path.file_stem().expect("expect a library name");
1175-
let mut archive_member = OsString::from("a(");
1175+
let mut archive_member = std::ffi::OsString::from("a(");
11761176
archive_member.push(library_name);
11771177
archive_member.push(".so)");
11781178
let new_path = path.with_extension(archive_member);

src/bootstrap/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fd-lock = "4.0"
4747
home = "0.5"
4848
ignore = "0.4"
4949
libc = "0.2"
50-
object = { version = "0.36.3", default-features = false, features = ["archive", "coff", "read_core", "unaligned"] }
50+
object = { version = "0.36.3", default-features = false, features = ["archive", "coff", "read_core", "std", "unaligned"] }
5151
opener = "0.5"
5252
semver = "1.0"
5353
serde = "1.0"

src/bootstrap/src/utils/helpers.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ pub fn is_dylib(path: &Path) -> bool {
6161
}
6262

6363
fn is_aix_shared_archive(path: &Path) -> bool {
64-
// FIXME(#133268): reading the entire file as &[u8] into memory seems excessive
65-
// look into either mmap it or use the ReadCache
66-
let data = match fs::read(path) {
67-
Ok(data) => data,
64+
let file = match fs::File::open(path) {
65+
Ok(file) => file,
6866
Err(_) => return false,
6967
};
70-
let file = match ArchiveFile::parse(&*data) {
71-
Ok(file) => file,
68+
let reader = object::ReadCache::new(file);
69+
let archive = match ArchiveFile::parse(&reader) {
70+
Ok(result) => result,
7271
Err(_) => return false,
7372
};
7473

75-
file.members()
74+
archive
75+
.members()
7676
.filter_map(Result::ok)
7777
.any(|entry| String::from_utf8_lossy(entry.name()).contains(".so"))
7878
}

0 commit comments

Comments
 (0)