Skip to content
Open
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
12 changes: 12 additions & 0 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,8 @@ pub fn build_session(

let timings = TimingSectionHandler::new(sopts.json_timings);

let sopts = enable_default_sanitizers(sopts, &target);

let sess = Session {
target,
host,
Expand Down Expand Up @@ -1143,6 +1145,16 @@ pub fn build_session(
sess
}

/// Update parsed sanitizers with the target defaults.
//
// This is the first time we have access to both the target and parsed options,
// and we need to update the sanitizer list for ABI changing sanitizers, like
// Shadow Call Stack.
fn enable_default_sanitizers(mut sopts: config::Options, target: &Target) -> config::Options {
sopts.unstable_opts.sanitizer |= target.options.default_sanitizers;
return sopts;
}

/// Validate command line arguments with a `Session`.
///
/// If it is useful to have a Session available already for validating a commandline argument, you
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_target/src/spec/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ impl Target {
supported_sanitizers.into_iter().fold(SanitizerSet::empty(), |a, b| a | b);
}

if let Some(default_sanitizers) = json.default_sanitizers {
base.default_sanitizers =
default_sanitizers.into_iter().fold(SanitizerSet::empty(), |a, b| a | b);
}

forward!(generate_arange_section);
forward!(supports_stack_protector);
forward!(small_data_threshold_support);
Expand Down Expand Up @@ -392,6 +397,7 @@ impl ToJson for Target {
target_option_val!(split_debuginfo);
target_option_val!(supported_split_debuginfo);
target_option_val!(supported_sanitizers);
target_option_val!(default_sanitizers);
target_option_val!(c_enum_min_bits);
target_option_val!(generate_arange_section);
target_option_val!(supports_stack_protector);
Expand Down Expand Up @@ -612,6 +618,7 @@ struct TargetSpecJson {
split_debuginfo: Option<SplitDebuginfo>,
supported_split_debuginfo: Option<StaticCow<[SplitDebuginfo]>>,
supported_sanitizers: Option<Vec<SanitizerSet>>,
default_sanitizers: Option<Vec<SanitizerSet>>,
generate_arange_section: Option<bool>,
supports_stack_protector: Option<bool>,
small_data_threshold_support: Option<SmallDataThresholdSupport>,
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2319,6 +2319,13 @@ pub struct TargetOptions {
/// distributed with the target, the sanitizer should still appear in this list for the target.
pub supported_sanitizers: SanitizerSet,

/// The sanitizers that are enabled by default on this target.
///
/// Note that the support here is at a codegen level. If the machine code with sanitizer
/// enabled can generated on this target, but the necessary supporting libraries are not
/// distributed with the target, the sanitizer should still appear in this list for the target.
pub default_sanitizers: SanitizerSet,

/// Minimum number of bits in #[repr(C)] enum. Defaults to the size of c_int
pub c_enum_min_bits: Option<u64>,

Expand Down Expand Up @@ -2567,6 +2574,7 @@ impl Default for TargetOptions {
// `Off` is supported by default, but targets can remove this manually, e.g. Windows.
supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]),
supported_sanitizers: SanitizerSet::empty(),
default_sanitizers: SanitizerSet::empty(),
c_enum_min_bits: None,
generate_arange_section: true,
supports_stack_protector: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub(crate) fn target() -> Target {
| SanitizerSet::CFI
| SanitizerSet::LEAK
| SanitizerSet::SHADOWCALLSTACK;
base.default_sanitizers = SanitizerSet::SHADOWCALLSTACK;
base.supports_xray = true;

base.add_pre_link_args(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub(crate) fn target() -> Target {
base.max_atomic_width = Some(64);
base.stack_probes = StackProbeType::Inline;
base.supported_sanitizers = SanitizerSet::SHADOWCALLSTACK;
base.default_sanitizers = SanitizerSet::SHADOWCALLSTACK;
base.supports_xray = true;

Target {
Expand Down
Loading