Skip to content

Commit 069ffec

Browse files
authored
Rollup merge of #91858 - semarie:runpath, r=petrochenkov
pass -Wl,-z,origin to set DF_ORIGIN when using rpath DF_ORIGIN flag signifies that the object being loaded may make reference to the $ORIGIN substitution string. Some implementations are just ignoring [DF_ORIGIN](http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#df_flags) and do [substitution](http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#substitution) for $ORIGIN if present (whatever DF_ORIGIN presence or not) like glibc. But some others mandate the present of DF_ORIGIN for the substitution (like OpenBSD). Set the flag inconditionally if rpath is wanted. One possible fallout is if the linker rejects `-z origin` option.
2 parents 208ced6 + c3da28e commit 069ffec

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

compiler/rustc_codegen_ssa/src/back/rpath.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ pub fn get_rpath_flags(config: &mut RPathConfig<'_>) -> Vec<String> {
2323
let rpaths = get_rpaths(config);
2424
let mut flags = rpaths_to_flags(&rpaths);
2525

26-
// Use DT_RUNPATH instead of DT_RPATH if available
2726
if config.linker_is_gnu {
27+
// Use DT_RUNPATH instead of DT_RPATH if available
2828
flags.push("-Wl,--enable-new-dtags".to_owned());
29+
30+
// Set DF_ORIGIN for substitute $ORIGIN
31+
flags.push("-Wl,-z,origin".to_owned());
2932
}
3033

3134
flags

src/bootstrap/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,7 @@ impl<'a> Builder<'a> {
11761176
rustflags.arg("-Zosx-rpath-install-name");
11771177
Some("-Wl,-rpath,@loader_path/../lib")
11781178
} else if !target.contains("windows") {
1179+
rustflags.arg("-Clink-args=-Wl,-z,origin");
11791180
Some("-Wl,-rpath,$ORIGIN/../lib")
11801181
} else {
11811182
None

0 commit comments

Comments
 (0)