Rollup merge of #138783 - bjorn3:cache_current_dll_path, r=lqd
Cache current_dll_path output Computing the current dll path is somewhat expensive relative to other work when compiling `fn main() {}` as `dladdr` needs to iterate over the symbol table of librustc_driver.so until it finds a match.
This commit is contained in:
commit
ab138e6aa8
1 changed files with 64 additions and 54 deletions
|
@ -60,6 +60,14 @@ pub fn make_target_bin_path(sysroot: &Path, target_triple: &str) -> PathBuf {
|
|||
|
||||
#[cfg(unix)]
|
||||
fn current_dll_path() -> Result<PathBuf, String> {
|
||||
use std::sync::OnceLock;
|
||||
|
||||
// This is somewhat expensive relative to other work when compiling `fn main() {}` as `dladdr`
|
||||
// needs to iterate over the symbol table of librustc_driver.so until it finds a match.
|
||||
// As such cache this to avoid recomputing if we try to get the sysroot in multiple places.
|
||||
static CURRENT_DLL_PATH: OnceLock<Result<PathBuf, String>> = OnceLock::new();
|
||||
CURRENT_DLL_PATH
|
||||
.get_or_init(|| {
|
||||
use std::ffi::{CStr, OsStr};
|
||||
use std::os::unix::prelude::*;
|
||||
|
||||
|
@ -115,11 +123,13 @@ fn current_dll_path() -> Result<PathBuf, String> {
|
|||
if (*current).ldinfo_next == 0 {
|
||||
break;
|
||||
}
|
||||
current =
|
||||
(current as *mut i8).offset((*current).ldinfo_next as isize) as *mut libc::ld_info;
|
||||
current = (current as *mut i8).offset((*current).ldinfo_next as isize)
|
||||
as *mut libc::ld_info;
|
||||
}
|
||||
return Err(format!("current dll's address {} is not in the load map", addr));
|
||||
}
|
||||
})
|
||||
.clone()
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue