Skip to content

Commit cec2d14

Browse files
committed
Pass --enable-new-dtags to GNU ld
This causes the linker to emit DT_RUNPATH instead of DT_RPATH, which fixes rust-lang#30378.
1 parent 9e63cec commit cec2d14

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/librustc_back/rpath.rs

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub struct RPathConfig<'a> {
1919
pub out_filename: PathBuf,
2020
pub is_like_osx: bool,
2121
pub has_rpath: bool,
22+
pub linker_is_gnu: bool,
2223
pub get_install_prefix_lib_path: &'a mut FnMut() -> PathBuf,
2324
}
2425

@@ -36,6 +37,12 @@ pub fn get_rpath_flags(config: &mut RPathConfig) -> Vec<String> {
3637
let libs = libs.into_iter().filter_map(|(_, l)| l).collect::<Vec<_>>();
3738
let rpaths = get_rpaths(config, &libs[..]);
3839
flags.extend_from_slice(&rpaths_to_flags(&rpaths[..]));
40+
41+
// Use DT_RUNPATH instead of DT_RPATH if available
42+
if config.linker_is_gnu {
43+
flags.push("-Wl,--enable-new-dtags".to_string());
44+
}
45+
3946
flags
4047
}
4148

@@ -228,6 +235,7 @@ mod tests {
228235
used_crates: Vec::new(),
229236
has_rpath: true,
230237
is_like_osx: true,
238+
linker_is_gnu: false,
231239
out_filename: PathBuf::from("bin/rustc"),
232240
get_install_prefix_lib_path: &mut || panic!(),
233241
};
@@ -241,6 +249,7 @@ mod tests {
241249
get_install_prefix_lib_path: &mut || panic!(),
242250
has_rpath: true,
243251
is_like_osx: false,
252+
linker_is_gnu: true,
244253
};
245254
let res = get_rpath_relative_to_output(config,
246255
Path::new("lib/libstd.so"));

src/librustc_trans/back/link.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,7 @@ fn link_args(cmd: &mut Linker,
10541054
out_filename: out_filename.to_path_buf(),
10551055
has_rpath: sess.target.target.options.has_rpath,
10561056
is_like_osx: sess.target.target.options.is_like_osx,
1057+
linker_is_gnu: sess.target.target.options.linker_is_gnu,
10571058
get_install_prefix_lib_path: &mut get_install_prefix_lib_path,
10581059
};
10591060
cmd.args(&rpath::get_rpath_flags(&mut rpath_config));

0 commit comments

Comments
 (0)