Skip to content

Commit e715cdb

Browse files
committed
Allow opting-out of rpath usage
By default, the compiler and libraries are all still built with rpaths, but this can be opted out of with --disable-rpath to ./configure or --no-rpath to rustc. cc #5219
1 parent fce7922 commit e715cdb

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

Makefile.in

+20-1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ endif
124124
ifdef TRACE
125125
CFG_RUSTC_FLAGS += -Z trace
126126
endif
127+
ifdef DISABLE_RPATH
128+
# NOTE: make this CFG_RUSTC_FLAGS after stage0 snapshot
129+
RUSTFLAGS_STAGE1 += --no-rpath
130+
RUSTFLAGS_STAGE2 += --no-rpath
131+
RUSTFLAGS_STAGE3 += --no-rpath
132+
endif
127133

128134
# The executables crated during this compilation process have no need to include
129135
# static copies of libstd and libextra. We also generate dynamic versions of all
@@ -541,8 +547,21 @@ CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
541547
endif
542548
endif
543549

550+
ifdef CFG_DISABLE_RPATH
551+
ifeq ($$(OSTYPE_$(3)),apple-darwin)
552+
RPATH_VAR$(1)_T_$(2)_H_$(3) := \
553+
DYLD_LIBRARY_PATH="$$$$DYLD_LIBRARY_PATH:$$(HLIB$(1)_H_$(3))"
554+
else
555+
RPATH_VAR$(1)_T_$(2)_H_$(3) := \
556+
LD_LIBRARY_PATH="$$$$LD_LIBRARY_PATH:$$(HLIB$(1)_H_$(3))"
557+
endif
558+
else
559+
RPATH_VAR$(1)_T_$(2)_H_$(3) :=
560+
endif
561+
544562
STAGE$(1)_T_$(2)_H_$(3) := \
545-
$$(Q)$$(call CFG_RUN_TARG_$(3),$(1), \
563+
$$(Q)$$(RPATH_VAR$(1)_T_$(2)_H_$(3)) \
564+
$$(call CFG_RUN_TARG_$(3),$(1), \
546565
$$(CFG_VALGRIND_COMPILE$(1)) \
547566
$$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
548567
--cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3)) \

configure

+1
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ opt ccache 0 "invoke gcc/clang via ccache to reuse object files between builds"
382382
opt local-rust 0 "use an installed rustc rather than downloading a snapshot"
383383
opt pax-flags 0 "apply PaX flags to rustc binaries (required for GRSecurity/PaX-patched kernels)"
384384
opt inject-std-version 1 "inject the current compiler version of libstd into programs"
385+
opt rpath 1 "build rpaths into rustc itself"
385386
valopt prefix "/usr/local" "set installation prefix"
386387
valopt local-rust-root "/usr/local" "set prefix for local rust binary"
387388
valopt llvm-root "" "set LLVM root"

src/librustc/back/link.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1089,8 +1089,10 @@ fn link_args(sess: Session,
10891089
args.push(~"-dynamiclib");
10901090
args.push(~"-Wl,-dylib");
10911091
// FIXME (#9639): This needs to handle non-utf8 paths
1092-
args.push(~"-Wl,-install_name,@rpath/" +
1093-
out_filename.filename_str().unwrap());
1092+
if !sess.opts.no_rpath {
1093+
args.push(~"-Wl,-install_name,@rpath/" +
1094+
out_filename.filename_str().unwrap());
1095+
}
10941096
} else {
10951097
args.push(~"-shared")
10961098
}
@@ -1108,7 +1110,9 @@ fn link_args(sess: Session,
11081110
// FIXME (#2397): At some point we want to rpath our guesses as to
11091111
// where extern libraries might live, based on the
11101112
// addl_lib_search_paths
1111-
args.push_all(rpath::get_rpath_flags(sess, out_filename));
1113+
if !sess.opts.no_rpath {
1114+
args.push_all(rpath::get_rpath_flags(sess, out_filename));
1115+
}
11121116

11131117
// Finally add all the linker arguments provided on the command line along
11141118
// with any #[link_args] attributes found inside the crate

src/librustc/driver/driver.rs

+3
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ pub fn build_session_options(binary: ~str,
734734
let parse_only = matches.opt_present("parse-only");
735735
let no_trans = matches.opt_present("no-trans");
736736
let no_analysis = matches.opt_present("no-analysis");
737+
let no_rpath = matches.opt_present("no-rpath");
737738

738739
let lint_levels = [lint::allow, lint::warn,
739740
lint::deny, lint::forbid];
@@ -888,6 +889,7 @@ pub fn build_session_options(binary: ~str,
888889
parse_only: parse_only,
889890
no_trans: no_trans,
890891
no_analysis: no_analysis,
892+
no_rpath: no_rpath,
891893
debugging_opts: debugging_opts,
892894
android_cross_path: android_cross_path,
893895
write_dependency_info: write_dependency_info,
@@ -995,6 +997,7 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
995997
\"list\" will list all of the available passes", "NAMES"),
996998
optopt("", "llvm-args", "A list of arguments to pass to llvm, comma \
997999
separated", "ARGS"),
1000+
optflag("", "no-rpath", "Disables setting the rpath in libs/exes"),
9981001
optopt( "", "out-dir",
9991002
"Write output to compiler-chosen filename
10001003
in <dir>", "DIR"),

src/librustc/driver/session.rs

+2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ pub struct Options {
170170
parse_only: bool,
171171
no_trans: bool,
172172
no_analysis: bool,
173+
no_rpath: bool,
173174
debugging_opts: u64,
174175
android_cross_path: Option<~str>,
175176
/// Whether to write dependency files. It's (enabled, optional filename).
@@ -388,6 +389,7 @@ pub fn basic_options() -> @Options {
388389
parse_only: false,
389390
no_trans: false,
390391
no_analysis: false,
392+
no_rpath: false,
391393
debugging_opts: 0,
392394
android_cross_path: None,
393395
write_dependency_info: (false, None),

0 commit comments

Comments
 (0)