Skip to content
/ rust Public
forked from rust-lang/rust

Commit a6ef0cc

Browse files
authored
Rollup merge of rust-lang#121978 - GuillaumeGomez:dylib-duplicated-path, r=bjorn3
Fix duplicated path in the "not found dylib" error While working on the gcc backend, I couldn't figure out why I had this error: ``` error: couldn't load codegen backend /checkout/compiler/rustc_codegen_gcc/target/release/librustc_codegen_gcc.so/checkout/compiler/rustc_codegen_gcc/target/release/librustc_codegen_gcc.so: cannot open shared object file: No such file or directory ``` As you can see, the path is duplicated for some reason. After investigating a bit more, I realized that `libloading::Error::LoadLibraryExW` starts with the path of the not found dylib, making it appear twice in our error afterward (because we do render it like this: `{path}{err}`, and since the `err` starts with the path...). Thanks to ``@bjorn3`` for linking me to rust-lang#121392. :)
2 parents d03f11d + 5e6e140 commit a6ef0cc

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

compiler/rustc_metadata/src/creader.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,13 @@ fn load_dylib(path: &Path, max_attempts: usize) -> Result<libloading::Library, S
11321132
Err(err) => {
11331133
// Only try to recover from this specific error.
11341134
if !matches!(err, libloading::Error::LoadLibraryExW { .. }) {
1135-
return Err(err.to_string());
1135+
let err = format_dlopen_err(&err);
1136+
// We include the path of the dylib in the error ourselves, so
1137+
// if it's in the error, we strip it.
1138+
if let Some(err) = err.strip_prefix(&format!(": {}", path.display())) {
1139+
return Err(err.to_string());
1140+
}
1141+
return Err(err);
11361142
}
11371143

11381144
last_error = Some(err);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@ only-linux
2+
//@ compile-flags: -Zcodegen-backend=/non-existing-one.so
3+
4+
// This test ensures that the error of the "not found dylib" doesn't duplicate
5+
// the path of the dylib.
6+
7+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: couldn't load codegen backend /non-existing-one.so: cannot open shared object file: No such file or directory
2+

0 commit comments

Comments
 (0)