Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add safe compilation options #117966

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,16 @@ change-id = 117813
# desired in distributions, for example.
#rpath = true

# Indicates whether symbols should be stripped using `-Cstrip=symbols`.
#strip = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is this necessary, if debuginfo is not enabled in the first place? Do we really need another option here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-Cstrip=symbols will strip all symbols, not only the debuginfo. The artifacts will be smaller and have fewer symbols if we use strip = true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I compare the size of binary artifacts, it will be smaller if use -Cstrip=symbols compare to not using. For example, the size of librustc_driver.so is 194.5MB without using -Cstrip=symbols, but 141.3MB when using -Cstrip=symbols.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks!


# Indicates whether stack protectors should be used
# via the unstable option `-Zstack-protector`.
#
# Valid options are : `none`(default),`basic`,`strong`, or `all`.
# `strong` and `basic` options may be buggy and are not recommended, see rust-lang/rust#114903.
#stack-protector = "none"
davidtwco marked this conversation as resolved.
Show resolved Hide resolved

# Prints each test name as it is executed, to help debug issues in the test harness itself.
#verbose-tests = false

Expand Down
6 changes: 6 additions & 0 deletions src/bootstrap/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,12 @@ impl<'a> Builder<'a> {
}
}

cargo.env(profile_var("STRIP"), self.config.rust_strip.to_string());

if let Some(stack_protector) = &self.config.rust_stack_protector {
rustflags.arg(&format!("-Zstack-protector={stack_protector}"));
}

if let Some(host_linker) = self.linker(compiler.host) {
hostflags.arg(format!("-Clinker={}", host_linker.display()));
}
Expand Down
7 changes: 7 additions & 0 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ pub struct Config {
pub rust_debuginfo_level_tests: DebuginfoLevel,
pub rust_split_debuginfo: SplitDebuginfo,
pub rust_rpath: bool,
pub rust_strip: bool,
pub rust_stack_protector: Option<String>,
pub rustc_parallel: bool,
pub rustc_default_linker: Option<String>,
pub rust_optimize_tests: bool,
Expand Down Expand Up @@ -1001,6 +1003,8 @@ define_config! {
description: Option<String> = "description",
musl_root: Option<String> = "musl-root",
rpath: Option<bool> = "rpath",
strip: Option<bool> = "strip",
stack_protector: Option<String> = "stack-protector",
verbose_tests: Option<bool> = "verbose-tests",
optimize_tests: Option<bool> = "optimize-tests",
codegen_tests: Option<bool> = "codegen-tests",
Expand Down Expand Up @@ -1069,6 +1073,7 @@ impl Config {
config.docs = true;
config.docs_minification = true;
config.rust_rpath = true;
config.rust_strip = false;
config.channel = "dev".to_string();
config.codegen_tests = true;
config.rust_dist_src = true;
Expand Down Expand Up @@ -1422,6 +1427,8 @@ impl Config {
set(&mut config.rust_optimize_tests, rust.optimize_tests);
set(&mut config.codegen_tests, rust.codegen_tests);
set(&mut config.rust_rpath, rust.rpath);
set(&mut config.rust_strip, rust.strip);
config.rust_stack_protector = rust.stack_protector;
set(&mut config.jemalloc, rust.jemalloc);
set(&mut config.test_compare_mode, rust.test_compare_mode);
set(&mut config.backtrace, rust.backtrace);
Expand Down
Loading