diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-02-07 17:00:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-07 17:00:16 +0100 |
| commit | 2f1eaeea772c2800cd45d263a6927db366f5bdc5 (patch) | |
| tree | 1f9f6d8e4553a4a0cee6a539eb2767bcf9259d09 /src/librustc_codegen_llvm/attributes.rs | |
| parent | b5e21dbb5cabdaaadc47a4d8e3f59979dcad2871 (diff) | |
| parent | 80adde2e337f4e0d784da401b2db37c5d4d3468b (diff) | |
Rollup merge of #68164 - tmiasko:no-sanitize, r=nikomatsakis
Selectively disable sanitizer instrumentation Add `no_sanitize` attribute that allows to opt out from sanitizer instrumentation in an annotated function.
Diffstat (limited to 'src/librustc_codegen_llvm/attributes.rs')
| -rw-r--r-- | src/librustc_codegen_llvm/attributes.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/librustc_codegen_llvm/attributes.rs b/src/librustc_codegen_llvm/attributes.rs index e3920d99c90..a9e4fdba030 100644 --- a/src/librustc_codegen_llvm/attributes.rs +++ b/src/librustc_codegen_llvm/attributes.rs @@ -46,6 +46,31 @@ 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 { + match *sanitizer { + Sanitizer::Address => { + if !codegen_fn_flags.contains(CodegenFnAttrFlags::NO_SANITIZE_ADDRESS) { + llvm::Attribute::SanitizeAddress.apply_llfn(Function, llfn); + } + } + Sanitizer::Memory => { + if !codegen_fn_flags.contains(CodegenFnAttrFlags::NO_SANITIZE_MEMORY) { + llvm::Attribute::SanitizeMemory.apply_llfn(Function, llfn); + } + } + Sanitizer::Thread => { + if !codegen_fn_flags.contains(CodegenFnAttrFlags::NO_SANITIZE_THREAD) { + llvm::Attribute::SanitizeThread.apply_llfn(Function, llfn); + } + } + Sanitizer::Leak => {} + } + } +} + /// Tell LLVM to emit or not emit the information necessary to unwind the stack for the function. #[inline] pub fn emit_uwtable(val: &'ll Value, emit: bool) { @@ -288,6 +313,7 @@ pub fn from_fn_attrs( if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::ALLOCATOR) { Attribute::NoAlias.apply_llfn(llvm::AttributePlace::ReturnValue, llfn); } + sanitize(cx, codegen_fn_attrs.flags, llfn); unwind( llfn, |
