Skip to content

Commit 5e802f0

Browse files
committed
rustc_codegen_ssa: fix get_rpath_relative_to_output panic when lib only contains file name
1 parent 05965ae commit 5e802f0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

compiler/rustc_codegen_ssa/src/back/rpath.rs

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ fn get_rpath_relative_to_output(config: &RPathConfig<'_>, lib: &Path) -> OsStrin
8585
// Strip filenames
8686
let lib = lib.parent().unwrap();
8787
let output = config.out_filename.parent().unwrap();
88+
89+
// If output or lib is empty, just assume it locates in current path
90+
let lib = if lib == Path::new("") { Path::new(".") } else { lib };
91+
let output = if output == Path::new("") { Path::new(".") } else { output };
92+
8893
let lib = try_canonicalize(lib).unwrap();
8994
let output = try_canonicalize(output).unwrap();
9095
let relative = path_relative_from(&lib, &output)

compiler/rustc_codegen_ssa/src/back/rpath/tests.rs

+16
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ fn test_rpath_relative() {
5757
}
5858
}
5959

60+
#[test]
61+
fn test_rpath_relative_issue_119571() {
62+
let config = &mut RPathConfig {
63+
libs: &[],
64+
out_filename: PathBuf::from("rustc"),
65+
has_rpath: true,
66+
is_like_osx: false,
67+
linker_is_gnu: true,
68+
};
69+
// Should not panic when out_filename only contains filename.
70+
// Issue 119571
71+
let _ = get_rpath_relative_to_output(config, Path::new("lib/libstd.so"));
72+
// Should not panic when lib only contains filename.
73+
let _ = get_rpath_relative_to_output(config, Path::new("libstd.so"));
74+
}
75+
6076
#[test]
6177
fn test_xlinker() {
6278
let args = rpaths_to_flags(vec!["a/normal/path".into(), "a,comma,path".into()]);

0 commit comments

Comments
 (0)