| Sanitizer runtimes are currently behind the `-Z` flag, which is only available |
| on nightly builds of the compiler. We would like to enable fuzzing on chrome |
| os anyway so move the sanitizer option under `-C` instead since we don't build |
| the toolchain in nightly mode. |
| |
| The changes this patch makes are: |
| - changing debugging_opts.sanitizer to cg.sanitizer. |
| - add the appropriate options to options.rs. |
| |
| diff --git a/src/librustc_codegen_llvm/attributes.rs b/src/librustc_codegen_llvm/attributes.rs |
| index a4e17a5f675..0b109d392bf 100644 |
| --- a/src/librustc_codegen_llvm/attributes.rs |
| +++ b/src/librustc_codegen_llvm/attributes.rs |
| @@ -46,7 +46,7 @@ fn inline(cx: &CodegenCx<'ll, '_>, val: &'ll Value, inline: InlineAttr) { |
| /// Apply LLVM sanitize attributes. |
| #[inline] |
| pub fn sanitize(cx: &CodegenCx<'ll, '_>, codegen_fn_flags: CodegenFnAttrFlags, llfn: &'ll Value) { |
| - if let Some(ref sanitizer) = cx.tcx.sess.opts.debugging_opts.sanitizer { |
| + if let Some(ref sanitizer) = cx.tcx.sess.opts.cg.sanitizer { |
| match *sanitizer { |
| Sanitizer::Address => { |
| if !codegen_fn_flags.contains(CodegenFnAttrFlags::NO_SANITIZE_ADDRESS) { |
| @@ -123,7 +123,7 @@ fn set_probestack(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) { |
| // Currently stack probes seem somewhat incompatible with the address |
| // sanitizer and thread sanitizer. With asan we're already protected from |
| // stack overflow anyway so we don't really need stack probes regardless. |
| - match cx.sess().opts.debugging_opts.sanitizer { |
| + match cx.sess().opts.cg.sanitizer { |
| Some(Sanitizer::Address | Sanitizer::Thread) => return, |
| _ => {} |
| } |
| diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs |
| index dcce1d45298..ef5e7d2a42a 100644 |
| --- a/src/librustc_codegen_ssa/back/link.rs |
| +++ b/src/librustc_codegen_ssa/back/link.rs |
| @@ -718,7 +718,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>( |
| } |
| |
| fn link_sanitizer_runtime(sess: &Session, crate_type: CrateType, linker: &mut dyn Linker) { |
| - let sanitizer = match &sess.opts.debugging_opts.sanitizer { |
| + let sanitizer = match &sess.opts.cg.sanitizer { |
| Some(s) => s, |
| None => return, |
| }; |
| @@ -752,7 +752,11 @@ fn link_sanitizer_runtime(sess: &Session, crate_type: CrateType, linker: &mut dy |
| linker.args(&["-Wl,-rpath", "-Xlinker", rpath]); |
| linker.link_dylib(Symbol::intern(&libname)); |
| } |
| - "x86_64-unknown-linux-gnu" | "x86_64-fuchsia" | "aarch64-fuchsia" => { |
| + "x86_64-unknown-linux-gnu" |
| + | "x86_64-fuchsia" |
| + | "aarch64-fuchsia" |
| + | "x86_64-cros-linux-gnu" |
| + | "x86_64-pc-linux-gnu" => { |
| let filename = format!("librustc{}_rt.{}.a", channel, name); |
| let path = default_tlib.join(&filename); |
| linker.link_whole_rlib(&path); |
| @@ -1509,7 +1513,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( |
| |
| // NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER |
| if sess.target.target.options.is_like_fuchsia && crate_type == CrateType::Executable { |
| - let prefix = match sess.opts.debugging_opts.sanitizer { |
| + let prefix = match sess.opts.cg.sanitizer { |
| Some(Sanitizer::Address) => "asan/", |
| _ => "", |
| }; |
| diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs |
| index 970d13b30c0..50a82461fef 100644 |
| --- a/src/librustc_codegen_ssa/back/symbol_export.rs |
| +++ b/src/librustc_codegen_ssa/back/symbol_export.rs |
| @@ -202,7 +202,7 @@ fn exported_symbols_provider_local( |
| })); |
| } |
| |
| - if let Some(Sanitizer::Memory) = tcx.sess.opts.debugging_opts.sanitizer { |
| + if let Some(Sanitizer::Memory) = tcx.sess.opts.cg.sanitizer { |
| // Similar to profiling, preserve weak msan symbol during LTO. |
| const MSAN_WEAK_SYMBOLS: [&str; 2] = ["__msan_track_origins", "__msan_keep_going"]; |
| |
| diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs |
| index cb5c95c11fa..a040013901a 100644 |
| --- a/src/librustc_codegen_ssa/back/write.rs |
| +++ b/src/librustc_codegen_ssa/back/write.rs |
| @@ -189,7 +189,7 @@ impl ModuleConfig { |
| ), |
| pgo_use: if_regular!(sess.opts.cg.profile_use.clone(), None), |
| |
| - sanitizer: if_regular!(sess.opts.debugging_opts.sanitizer.clone(), None), |
| + sanitizer: if_regular!(sess.opts.cg.sanitizer.clone(), None), |
| sanitizer_recover: if_regular!( |
| sess.opts.debugging_opts.sanitizer_recover.clone(), |
| vec![] |
| diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs |
| index 35d55c4cb9b..e167ca3da51 100644 |
| --- a/src/librustc_mir/transform/inline.rs |
| +++ b/src/librustc_mir/transform/inline.rs |
| @@ -232,7 +232,7 @@ impl Inliner<'tcx> { |
| |
| // Avoid inlining functions marked as no_sanitize if sanitizer is enabled, |
| // since instrumentation might be enabled and performed on the caller. |
| - match self.tcx.sess.opts.debugging_opts.sanitizer { |
| + match self.tcx.sess.opts.cg.sanitizer { |
| Some(Sanitizer::Address) => { |
| if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NO_SANITIZE_ADDRESS) { |
| return false; |
| diff --git a/src/librustc_session/config.rs b/src/librustc_session/config.rs |
| index 5bdd7b67723..41569753010 100644 |
| --- a/src/librustc_session/config.rs |
| +++ b/src/librustc_session/config.rs |
| @@ -726,7 +726,7 @@ pub fn default_configuration(sess: &Session) -> CrateConfig { |
| } |
| } |
| } |
| - if let Some(s) = &sess.opts.debugging_opts.sanitizer { |
| + if let Some(s) = &sess.opts.cg.sanitizer { |
| let symbol = Symbol::intern(&s.to_string()); |
| ret.insert((sym::sanitize, Some(symbol))); |
| } |
| diff --git a/src/librustc_session/options.rs b/src/librustc_session/options.rs |
| index a38e7f063d7..838fd26700f 100644 |
| --- a/src/librustc_session/options.rs |
| +++ b/src/librustc_session/options.rs |
| @@ -759,6 +759,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options, |
| "print remarks for these optimization passes (space separated, or \"all\")"), |
| rpath: bool = (false, parse_bool, [UNTRACKED], |
| "set rpath values in libs/exes (default: no)"), |
| + sanitizer: Option<Sanitizer> = (None, parse_sanitizer, [TRACKED], |
| + "use a sanitizer"), |
| save_temps: bool = (false, parse_bool, [UNTRACKED], |
| "save all temporary output files during compilation (default: no)"), |
| soft_float: bool = (false, parse_bool, [TRACKED], |
| diff --git a/src/librustc_session/session.rs b/src/librustc_session/session.rs |
| index 048033846a1..b09e6acb981 100644 |
| --- a/src/librustc_session/session.rs |
| +++ b/src/librustc_session/session.rs |
| @@ -650,7 +650,7 @@ impl Session { |
| || self.opts.output_types.contains_key(&OutputType::Bitcode); |
| |
| // Address sanitizer and memory sanitizer use alloca name when reporting an issue. |
| - let more_names = match self.opts.debugging_opts.sanitizer { |
| + let more_names = match self.opts.cg.sanitizer { |
| Some(Sanitizer::Address) => true, |
| Some(Sanitizer::Memory) => true, |
| _ => more_names, |
| @@ -1017,7 +1017,7 @@ impl Session { |
| |
| /// Checks if LLVM lifetime markers should be emitted. |
| pub fn emit_lifetime_markers(&self) -> bool { |
| - match self.opts.debugging_opts.sanitizer { |
| + match self.opts.cg.sanitizer { |
| // AddressSanitizer uses lifetimes to detect use after scope bugs. |
| // MemorySanitizer uses lifetimes to detect use of uninitialized stack variables. |
| Some(Sanitizer::Address | Sanitizer::Memory) => true, |
| @@ -1354,18 +1354,32 @@ fn validate_commandline_args_with_session_available(sess: &Session) { |
| } |
| |
| // Sanitizers can only be used on some tested platforms. |
| - if let Some(ref sanitizer) = sess.opts.debugging_opts.sanitizer { |
| + if let Some(ref sanitizer) = sess.opts.cg.sanitizer { |
| const ASAN_SUPPORTED_TARGETS: &[&str] = &[ |
| "x86_64-unknown-linux-gnu", |
| + "x86_64-cros-linux-gnu", |
| + "x86_64-pc-linux-gnu", |
| "x86_64-apple-darwin", |
| "x86_64-fuchsia", |
| "aarch64-fuchsia", |
| ]; |
| - const TSAN_SUPPORTED_TARGETS: &[&str] = |
| - &["x86_64-unknown-linux-gnu", "x86_64-apple-darwin"]; |
| - const LSAN_SUPPORTED_TARGETS: &[&str] = |
| - &["x86_64-unknown-linux-gnu", "x86_64-apple-darwin"]; |
| - const MSAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu"]; |
| + const TSAN_SUPPORTED_TARGETS: &[&str] = &[ |
| + "x86_64-unknown-linux-gnu", |
| + "x86_64-cros-linux-gnu", |
| + "x86_64-pc-linux-gnu", |
| + "x86_64-apple-darwin", |
| + ]; |
| + const LSAN_SUPPORTED_TARGETS: &[&str] = &[ |
| + "x86_64-unknown-linux-gnu", |
| + "x86_64-cros-linux-gnu", |
| + "x86_64-pc-linux-gnu", |
| + "x86_64-apple-darwin", |
| + ]; |
| + const MSAN_SUPPORTED_TARGETS: &[&str] = &[ |
| + "x86_64-unknown-linux-gnu", |
| + "x86_64-cros-linux-gnu", |
| + "x86_64-pc-linux-gnu", |
| + ]; |
| |
| let supported_targets = match *sanitizer { |
| Sanitizer::Address => ASAN_SUPPORTED_TARGETS, |
| |