Skip to content

Commit 3f8487a

Browse files
committed
Add safe compilation options
Add two options when building rust: strip and stack protector. If set `strip = true`, symbols will be stripped using `-Cstrip=symbols`. Also can set `stack-protector` and stack protectors will be used.
1 parent da1da3f commit 3f8487a

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

config.example.toml

+10
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,16 @@ change-id = 117813
600600
# desired in distributions, for example.
601601
#rpath = true
602602

603+
# Indicates whether symbols should be stripped using `-Cstrip=symbols`.
604+
#strip = false
605+
606+
# Indicates whether stack protectors should be used
607+
# via the unstable option `-Zstack-protector`.
608+
#
609+
# Valid options are : `none`(default),`basic`,`strong`, or `all`.
610+
# `strong` and `basic` options may be buggy and are not recommended, see rust-lang/rust#114903.
611+
#stack-protector = "none"
612+
603613
# Prints each test name as it is executed, to help debug issues in the test harness itself.
604614
#verbose-tests = false
605615

src/bootstrap/src/core/builder.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,12 @@ impl<'a> Builder<'a> {
16671667
}
16681668
}
16691669

1670+
cargo.env(profile_var("STRIP"), self.config.rust_strip.to_string());
1671+
1672+
if let Some(stack_protector) = &self.config.rust_stack_protector {
1673+
rustflags.arg(&format!("-Zstack-protector={stack_protector}"));
1674+
}
1675+
16701676
if let Some(host_linker) = self.linker(compiler.host) {
16711677
hostflags.arg(format!("-Clinker={}", host_linker.display()));
16721678
}

src/bootstrap/src/core/config/config.rs

+7
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ pub struct Config {
222222
pub rust_debuginfo_level_tests: DebuginfoLevel,
223223
pub rust_split_debuginfo: SplitDebuginfo,
224224
pub rust_rpath: bool,
225+
pub rust_strip: bool,
226+
pub rust_stack_protector: Option<String>,
225227
pub rustc_parallel: bool,
226228
pub rustc_default_linker: Option<String>,
227229
pub rust_optimize_tests: bool,
@@ -1001,6 +1003,8 @@ define_config! {
10011003
description: Option<String> = "description",
10021004
musl_root: Option<String> = "musl-root",
10031005
rpath: Option<bool> = "rpath",
1006+
strip: Option<bool> = "strip",
1007+
stack_protector: Option<String> = "stack-protector",
10041008
verbose_tests: Option<bool> = "verbose-tests",
10051009
optimize_tests: Option<bool> = "optimize-tests",
10061010
codegen_tests: Option<bool> = "codegen-tests",
@@ -1069,6 +1073,7 @@ impl Config {
10691073
config.docs = true;
10701074
config.docs_minification = true;
10711075
config.rust_rpath = true;
1076+
config.rust_strip = false;
10721077
config.channel = "dev".to_string();
10731078
config.codegen_tests = true;
10741079
config.rust_dist_src = true;
@@ -1422,6 +1427,8 @@ impl Config {
14221427
set(&mut config.rust_optimize_tests, rust.optimize_tests);
14231428
set(&mut config.codegen_tests, rust.codegen_tests);
14241429
set(&mut config.rust_rpath, rust.rpath);
1430+
set(&mut config.rust_strip, rust.strip);
1431+
config.rust_stack_protector = rust.stack_protector;
14251432
set(&mut config.jemalloc, rust.jemalloc);
14261433
set(&mut config.test_compare_mode, rust.test_compare_mode);
14271434
set(&mut config.backtrace, rust.backtrace);

0 commit comments

Comments
 (0)