Skip to content

Commit

Permalink
rustc_codegen_ssa: fix get_rpath_relative_to_output panic when lib on…
Browse files Browse the repository at this point in the history
…ly contains file name
  • Loading branch information
name1e5s committed Jun 1, 2024
1 parent 05965ae commit 153de76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ fn get_rpath_relative_to_output(config: &RPathConfig<'_>, lib: &Path) -> OsStrin
// Strip filenames
let lib = lib.parent().unwrap();
let output = config.out_filename.parent().unwrap();

// If output is empty, just assume it locates in current path
let output = if output == Path::new("") { Path::new(".") } else { output };

let lib = try_canonicalize(lib).unwrap();
let output = try_canonicalize(output).unwrap();
let relative = path_relative_from(&lib, &output)
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/rpath/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ fn test_rpath_relative() {
};
let res = get_rpath_relative_to_output(config, Path::new("lib/libstd.so"));
assert_eq!(res, "@loader_path/../lib");
// Should not panic when lib only contains filename.
// Issue 119571
let _ = get_rpath_relative_to_output(config, Path::new("libstd.so"));
} else {
let config = &mut RPathConfig {
libs: &[],
Expand All @@ -54,6 +57,9 @@ fn test_rpath_relative() {
};
let res = get_rpath_relative_to_output(config, Path::new("lib/libstd.so"));
assert_eq!(res, "$ORIGIN/../lib");
// Should not panic when lib only contains filename.
// Issue 119571
let _ = get_rpath_relative_to_output(config, Path::new("libstd.so"));
}
}

Expand Down

0 comments on commit 153de76

Please sign in to comment.