Skip to content

Commit efe697e

Browse files
authored
Rollup merge of #111242 - wangkirin:support_rpath_independent_config, r=albertlarsan68
support set `rpath` option for each target independently Currently the `rpath` option is a global config and it's effect on all targets. But sometimes when developers edit the rustc code and try to release rust toolchains themselves, they may not want to add `rpath` in all targets to avoid dynamically linked shared object library privilege escalation attack. This PR supports set `rpath` option for each target independently . Common developers are not aware of the existence of this configuration option and do not affect the existing development process. This configuration option takes effect only after developers explicitly sets . r? ``@albertlarsan68``
2 parents 363d158 + bb4976a commit efe697e

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

config.example.toml

+4
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,10 @@ changelog-seen = 2
750750
# This option will override the same option under [build] section.
751751
#profiler = build.profiler (bool)
752752

753+
# This option supports enable `rpath` in each target independently,
754+
# and will override the same option under [rust] section. It only works on Unix platforms
755+
#rpath = rust.rpath (bool)
756+
753757
# Force static or dynamic linkage of the standard library for this target. If
754758
# this target is a host for rustc, this will also affect the linkage of the
755759
# compiler itself. This is useful for building rustc on targets that normally

src/bootstrap/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2727
from the default rust toolchain. [#78513](https://github.com/rust-lang/rust/pull/78513)
2828
- Add options for enabling overflow checks, one for std (`overflow-checks-std`) and one for everything else (`overflow-checks`). Both default to false.
2929
- Add llvm option `enable-warnings` to have control on llvm compilation warnings. Default to false.
30+
- Add `rpath` option in `target` section to support set rpath option for each target independently. [#111242](https://github.com/rust-lang/rust/pull/111242)
3031

3132

3233
## [Version 2] - 2020-09-25

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,7 @@ impl<'a> Builder<'a> {
16231623
// argument manually via `-C link-args=-Wl,-rpath,...`. Plus isn't it
16241624
// fun to pass a flag to a tool to pass a flag to pass a flag to a tool
16251625
// to change a flag in a binary?
1626-
if self.config.rust_rpath && util::use_host_linker(target) {
1626+
if self.config.rpath_enabled(target) && util::use_host_linker(target) {
16271627
let rpath = if target.contains("apple") {
16281628
// Note that we need to take one extra step on macOS to also pass
16291629
// `-Wl,-instal_name,@rpath/...` to get things to work right. To

src/bootstrap/config.rs

+7
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ pub struct Target {
467467
pub ndk: Option<PathBuf>,
468468
pub sanitizers: Option<bool>,
469469
pub profiler: Option<bool>,
470+
pub rpath: Option<bool>,
470471
pub crt_static: Option<bool>,
471472
pub musl_root: Option<PathBuf>,
472473
pub musl_libdir: Option<PathBuf>,
@@ -812,6 +813,7 @@ define_config! {
812813
android_ndk: Option<String> = "android-ndk",
813814
sanitizers: Option<bool> = "sanitizers",
814815
profiler: Option<bool> = "profiler",
816+
rpath: Option<bool> = "rpath",
815817
crt_static: Option<bool> = "crt-static",
816818
musl_root: Option<String> = "musl-root",
817819
musl_libdir: Option<String> = "musl-libdir",
@@ -1318,6 +1320,7 @@ impl Config {
13181320
target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from);
13191321
target.sanitizers = cfg.sanitizers;
13201322
target.profiler = cfg.profiler;
1323+
target.rpath = cfg.rpath;
13211324

13221325
config.target_config.insert(TargetSelection::from_user(&triple), target);
13231326
}
@@ -1649,6 +1652,10 @@ impl Config {
16491652
self.target_config.values().any(|t| t.profiler == Some(true)) || self.profiler
16501653
}
16511654

1655+
pub fn rpath_enabled(&self, target: TargetSelection) -> bool {
1656+
self.target_config.get(&target).map(|t| t.rpath).flatten().unwrap_or(self.rust_rpath)
1657+
}
1658+
16521659
pub fn llvm_enabled(&self) -> bool {
16531660
self.rust_codegen_backends.contains(&INTERNER.intern_str("llvm"))
16541661
}

0 commit comments

Comments
 (0)