Skip to content

Commit

Permalink
Rollup merge of rust-lang#91858 - semarie:runpath, r=petrochenkov
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matthiaskrgr committed Dec 17, 2021
2 parents 6e90e8b + 8ae5780 commit 9b356de
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub fn get_rpath_flags(config: &mut RPathConfig<'_>) -> Vec<String> {
fn rpaths_to_flags(rpaths: &[String]) -> Vec<String> {
let mut ret = Vec::with_capacity(rpaths.len()); // the minimum needed capacity

ret.push(String::from("-Wl,-z,origin"));
for rpath in rpaths {
if rpath.contains(',') {
ret.push("-Wl,-rpath".into());
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,7 @@ impl<'a> Builder<'a> {
rustflags.arg("-Zosx-rpath-install-name");
Some("-Wl,-rpath,@loader_path/../lib")
} else if !target.contains("windows") {
rustflags.arg("-Clink-args=-Wl,-z,origin");
Some("-Wl,-rpath,$ORIGIN/../lib")
} else {
None
Expand Down

0 comments on commit 9b356de

Please sign in to comment.