1
Fork 0

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``
This commit is contained in:
Matthias Krüger 2023-05-09 20:49:32 +02:00 committed by GitHub
commit efe697e133
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 1 deletions

View file

@ -750,6 +750,10 @@ changelog-seen = 2
# This option will override the same option under [build] section. # This option will override the same option under [build] section.
#profiler = build.profiler (bool) #profiler = build.profiler (bool)
# This option supports enable `rpath` in each target independently,
# and will override the same option under [rust] section. It only works on Unix platforms
#rpath = rust.rpath (bool)
# Force static or dynamic linkage of the standard library for this target. If # Force static or dynamic linkage of the standard library for this target. If
# this target is a host for rustc, this will also affect the linkage of the # this target is a host for rustc, this will also affect the linkage of the
# compiler itself. This is useful for building rustc on targets that normally # compiler itself. This is useful for building rustc on targets that normally

View file

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

View file

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

View file

@ -467,6 +467,7 @@ pub struct Target {
pub ndk: Option<PathBuf>, pub ndk: Option<PathBuf>,
pub sanitizers: Option<bool>, pub sanitizers: Option<bool>,
pub profiler: Option<bool>, pub profiler: Option<bool>,
pub rpath: Option<bool>,
pub crt_static: Option<bool>, pub crt_static: Option<bool>,
pub musl_root: Option<PathBuf>, pub musl_root: Option<PathBuf>,
pub musl_libdir: Option<PathBuf>, pub musl_libdir: Option<PathBuf>,
@ -812,6 +813,7 @@ define_config! {
android_ndk: Option<String> = "android-ndk", android_ndk: Option<String> = "android-ndk",
sanitizers: Option<bool> = "sanitizers", sanitizers: Option<bool> = "sanitizers",
profiler: Option<bool> = "profiler", profiler: Option<bool> = "profiler",
rpath: Option<bool> = "rpath",
crt_static: Option<bool> = "crt-static", crt_static: Option<bool> = "crt-static",
musl_root: Option<String> = "musl-root", musl_root: Option<String> = "musl-root",
musl_libdir: Option<String> = "musl-libdir", musl_libdir: Option<String> = "musl-libdir",
@ -1318,6 +1320,7 @@ impl Config {
target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from); target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from);
target.sanitizers = cfg.sanitizers; target.sanitizers = cfg.sanitizers;
target.profiler = cfg.profiler; target.profiler = cfg.profiler;
target.rpath = cfg.rpath;
config.target_config.insert(TargetSelection::from_user(&triple), target); config.target_config.insert(TargetSelection::from_user(&triple), target);
} }
@ -1649,6 +1652,10 @@ impl Config {
self.target_config.values().any(|t| t.profiler == Some(true)) || self.profiler self.target_config.values().any(|t| t.profiler == Some(true)) || self.profiler
} }
pub fn rpath_enabled(&self, target: TargetSelection) -> bool {
self.target_config.get(&target).map(|t| t.rpath).flatten().unwrap_or(self.rust_rpath)
}
pub fn llvm_enabled(&self) -> bool { pub fn llvm_enabled(&self) -> bool {
self.rust_codegen_backends.contains(&INTERNER.intern_str("llvm")) self.rust_codegen_backends.contains(&INTERNER.intern_str("llvm"))
} }