Skip to content

Commit ec99673

Browse files
committed
rustc: Remove absolute rpaths
Concerns have been raised about using absolute rpaths in #11746, and this is the first step towards not relying on rpaths at all. The only current use case for an absolute rpath is when a non-installed rust builds an executable that then moves from is built location. The relative rpath back to libstd and absolute rpath to the installation directory still remain (CFG_PREFIX). Closes #11746 Rebasing of #12754
1 parent 85299e3 commit ec99673

File tree

2 files changed

+1
-33
lines changed

2 files changed

+1
-33
lines changed

mk/main.mk

-4
Original file line numberDiff line numberDiff line change
@@ -358,17 +358,13 @@ CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
358358
endif
359359
endif
360360

361-
ifdef CFG_DISABLE_RPATH
362361
ifeq ($$(OSTYPE_$(3)),apple-darwin)
363362
RPATH_VAR$(1)_T_$(2)_H_$(3) := \
364363
DYLD_LIBRARY_PATH="$$$$DYLD_LIBRARY_PATH:$$(CURDIR)/$$(HLIB$(1)_H_$(3))"
365364
else
366365
RPATH_VAR$(1)_T_$(2)_H_$(3) := \
367366
LD_LIBRARY_PATH="$$$$LD_LIBRARY_PATH:$$(CURDIR)/$$(HLIB$(1)_H_$(3))"
368367
endif
369-
else
370-
RPATH_VAR$(1)_T_$(2)_H_$(3) :=
371-
endif
372368

373369
STAGE$(1)_T_$(2)_H_$(3) := \
374370
$$(Q)$$(RPATH_VAR$(1)_T_$(2)_H_$(3)) \

src/librustc/back/rpath.rs

+1-29
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ fn get_rpaths(os: abi::Os,
8787
// crates they depend on.
8888
let rel_rpaths = get_rpaths_relative_to_output(os, output, libs);
8989

90-
// Make backup absolute paths to the libraries. Binaries can
91-
// be moved as long as the crates they link against don't move.
92-
let abs_rpaths = get_absolute_rpaths(libs);
93-
9490
// And a final backup rpath to the global library location.
9591
let fallback_rpaths = vec!(get_install_prefix_rpath(sysroot, target_triple));
9692

@@ -102,11 +98,9 @@ fn get_rpaths(os: abi::Os,
10298
}
10399

104100
log_rpaths("relative", rel_rpaths.as_slice());
105-
log_rpaths("absolute", abs_rpaths.as_slice());
106101
log_rpaths("fallback", fallback_rpaths.as_slice());
107102

108103
let mut rpaths = rel_rpaths;
109-
rpaths.push_all(abs_rpaths.as_slice());
110104
rpaths.push_all(fallback_rpaths.as_slice());
111105

112106
// Remove duplicates
@@ -146,17 +140,6 @@ pub fn get_rpath_relative_to_output(os: abi::Os,
146140
prefix+"/"+relative.as_str().expect("non-utf8 component in path")
147141
}
148142

149-
fn get_absolute_rpaths(libs: &[Path]) -> Vec<~str> {
150-
libs.iter().map(|a| get_absolute_rpath(a)).collect()
151-
}
152-
153-
pub fn get_absolute_rpath(lib: &Path) -> ~str {
154-
let mut p = os::make_absolute(lib);
155-
p.pop();
156-
// FIXME (#9639): This needs to handle non-utf8 paths
157-
p.as_str().expect("non-utf8 component in rpath").to_owned()
158-
}
159-
160143
pub fn get_install_prefix_rpath(sysroot: &Path, target_triple: &str) -> ~str {
161144
let install_prefix = env!("CFG_PREFIX");
162145

@@ -183,7 +166,7 @@ pub fn minimize_rpaths(rpaths: &[~str]) -> Vec<~str> {
183166
mod test {
184167
use std::os;
185168

186-
use back::rpath::{get_absolute_rpath, get_install_prefix_rpath};
169+
use back::rpath::get_install_prefix_rpath;
187170
use back::rpath::{minimize_rpaths, rpaths_to_flags, get_rpath_relative_to_output};
188171
use syntax::abi;
189172
use metadata::filesearch;
@@ -258,15 +241,4 @@ mod test {
258241
&Path::new("lib/libstd.so"));
259242
assert_eq!(res.as_slice(), "@loader_path/../lib");
260243
}
261-
262-
#[test]
263-
fn test_get_absolute_rpath() {
264-
let res = get_absolute_rpath(&Path::new("lib/libstd.so"));
265-
let lib = os::make_absolute(&Path::new("lib"));
266-
debug!("test_get_absolute_rpath: {} vs. {}",
267-
res.to_str(), lib.display());
268-
269-
// FIXME (#9639): This needs to handle non-utf8 paths
270-
assert_eq!(res.as_slice(), lib.as_str().expect("non-utf8 component in path"));
271-
}
272244
}

0 commit comments

Comments
 (0)