Skip to content

Commit

Permalink
rustc: use -Xlinker when specifying an rpath with ',' in it
Browse files Browse the repository at this point in the history
The `-Wl` option splits its parameters on commas, so if rustc specifies
`-Wl,-rpath,<path>` when `<path>` contains commas, the path gets split up
and the linker gets a partial path and spurious extra parameters.

Gcc/clang support the more verbose `-Xlinker` option to pass options
to the linker directly, so use it for comma-containing paths.

Fixes rust issue #38795.
  • Loading branch information
jsgf committed Jan 3, 2017
1 parent 8f62c29 commit a8fa2cf
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/librustc_trans/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ pub fn get_rpath_flags(config: &mut RPathConfig) -> Vec<String> {
fn rpaths_to_flags(rpaths: &[String]) -> Vec<String> {
let mut ret = Vec::new();
for rpath in rpaths {
ret.push(format!("-Wl,-rpath,{}", &(*rpath)));
if rpath.contains(',') {
ret.push("-Wl,-rpath".into());
ret.push("-Xlinker".into());
ret.push(rpath.clone());
} else {
ret.push(format!("-Wl,-rpath,{}", &(*rpath)));
}
}
return ret;
}
Expand Down Expand Up @@ -258,4 +264,19 @@ mod tests {
assert_eq!(res, "$ORIGIN/../lib");
}
}

#[test]
fn test_xlinker() {
let args = rpaths_to_flags(&[
"a/normal/path".to_string(),
"a,comma,path".to_string()
]);

assert_eq!(args, vec![
"-Wl,-rpath,a/normal/path".to_string(),
"-Wl,-rpath".to_string(),
"-Xlinker".to_string(),
"a,comma,path".to_string()
]);
}
}

0 comments on commit a8fa2cf

Please sign in to comment.