Rollup merge of #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 https://github.com/rust-lang/rust/pull/121392. :)
This commit is contained in:
Matthias Krüger 2024-03-05 19:53:22 +01:00 committed by GitHub
commit f5ff6d5ae5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 1 deletions

View File

@ -1132,7 +1132,13 @@ fn load_dylib(path: &Path, max_attempts: usize) -> Result<libloading::Library, S
Err(err) => {
// Only try to recover from this specific error.
if !matches!(err, libloading::Error::LoadLibraryExW { .. }) {
return Err(err.to_string());
let err = format_dlopen_err(&err);
// We include the path of the dylib in the error ourselves, so
// if it's in the error, we strip it.
if let Some(err) = err.strip_prefix(&format!(": {}", path.display())) {
return Err(err.to_string());
}
return Err(err);
}
last_error = Some(err);

View File

@ -0,0 +1,7 @@
//@ only-linux
//@ compile-flags: -Zcodegen-backend=/non-existing-one.so
// This test ensures that the error of the "not found dylib" doesn't duplicate
// the path of the dylib.
fn main() {}

View File

@ -0,0 +1,2 @@
error: couldn't load codegen backend /non-existing-one.so: cannot open shared object file: No such file or directory