mirror of
https://github.com/openharmony/third_party_rust_rust.git
synced 2026-07-18 17:34:40 -04:00
!7 add safe compile options
Merge pull request !7 from erjuan/stack-protect
This commit is contained in:
@@ -577,6 +577,13 @@ changelog-seen = 2
|
||||
# desired in distributions, for example.
|
||||
#rpath = true
|
||||
|
||||
# Indicates whether `rustc` should be stripped of symbols using `-Cstrip=symbols`.
|
||||
#strip = false
|
||||
|
||||
# Indicates whether `rustc` should be compiled with stack protectors.
|
||||
# Valid options are : `none`(default),`basic`,`strong`, or `all`.
|
||||
#stack-protector = "none"
|
||||
|
||||
# Prints each test name as it is executed, to help debug issues in the test harness itself.
|
||||
#verbose-tests = false
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ use std::process::Command;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use crate::cache::{Cache, Interned, INTERNER};
|
||||
use crate::config::{SplitDebuginfo, TargetSelection};
|
||||
use crate::config::{SplitDebuginfo, TargetSelection, StackProtector};
|
||||
use crate::doc;
|
||||
use crate::flags::{Color, Subcommand};
|
||||
use crate::install;
|
||||
@@ -1621,6 +1621,16 @@ impl<'a> Builder<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
if self.config.rust_strip {
|
||||
rustflags.arg("-Cstrip=symbols");
|
||||
}
|
||||
match self.config.rust_stack_protector {
|
||||
StackProtector::All => rustflags.arg("-Zstack-protector=all"),
|
||||
StackProtector::Strong => rustflags.arg("-Zstack-protector=strong"),
|
||||
StackProtector::Basic => rustflags.arg("-Zstack-protector=basic"),
|
||||
StackProtector::None => rustflags.arg("-Zstack-protector=none"),
|
||||
};
|
||||
|
||||
if let Some(host_linker) = self.linker(compiler.host) {
|
||||
cargo.env("RUSTC_HOST_LINKER", host_linker);
|
||||
}
|
||||
|
||||
@@ -216,6 +216,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: StackProtector,
|
||||
pub rustc_parallel: bool,
|
||||
pub rustc_default_linker: Option<String>,
|
||||
pub rust_optimize_tests: bool,
|
||||
@@ -401,6 +403,29 @@ impl SplitDebuginfo {
|
||||
}
|
||||
}
|
||||
|
||||
/// Stack protector mode for compiling rustc itself
|
||||
#[derive(Default, Clone, PartialEq, Debug)]
|
||||
pub enum StackProtector {
|
||||
#[default]
|
||||
None,
|
||||
Basic,
|
||||
Strong,
|
||||
All,
|
||||
}
|
||||
|
||||
impl std::str::FromStr for StackProtector {
|
||||
type Err = String;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"none" => Ok(StackProtector::None),
|
||||
"basic" => Ok(StackProtector::Basic),
|
||||
"strong" => Ok(StackProtector::Strong),
|
||||
"all" => Ok(StackProtector::All),
|
||||
_ => Err(format!("Invalid value for stack protector: {}", s)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// LTO mode used for compiling rustc itself.
|
||||
#[derive(Default, Clone, PartialEq, Debug)]
|
||||
pub enum RustcLto {
|
||||
@@ -947,6 +972,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",
|
||||
@@ -1015,6 +1042,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;
|
||||
@@ -1351,6 +1379,12 @@ 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
|
||||
.as_deref()
|
||||
.map(|value| StackProtector::from_str(value).unwrap())
|
||||
.unwrap_or_default();
|
||||
set(&mut config.jemalloc, rust.jemalloc);
|
||||
set(&mut config.test_compare_mode, rust.test_compare_mode);
|
||||
set(&mut config.backtrace, rust.backtrace);
|
||||
|
||||
Reference in New Issue
Block a user