diff options
| author | Ivan Lozano <ivanlozano@google.com> | 2021-12-03 16:11:13 -0500 |
|---|---|---|
| committer | Ivan Lozano <ivanlozano@google.com> | 2022-02-16 09:39:03 -0500 |
| commit | 568aeda9e955ca2a4c043bc2ae7f854e60f6103a (patch) | |
| tree | 9bf9fb4b071e057a6869945ceef6883aebf40050 /compiler/rustc_codegen_llvm/src/attributes.rs | |
| parent | 55697574915ca58c3fcd7b1c854c1c93e002dc85 (diff) | |
| download | rust-568aeda9e955ca2a4c043bc2ae7f854e60f6103a.tar.gz rust-568aeda9e955ca2a4c043bc2ae7f854e60f6103a.zip | |
MemTagSanitizer Support
Adds support for the LLVM MemTagSanitizer.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/attributes.rs')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/attributes.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index 2472789601e..4d054ec3d81 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -55,6 +55,19 @@ pub fn sanitize<'ll>(cx: &CodegenCx<'ll, '_>, no_sanitize: SanitizerSet, llfn: & if enabled.contains(SanitizerSet::HWADDRESS) { llvm::Attribute::SanitizeHWAddress.apply_llfn(Function, llfn); } + if enabled.contains(SanitizerSet::MEMTAG) { + // Check to make sure the mte target feature is actually enabled. + let sess = cx.tcx.sess; + let features = llvm_util::llvm_global_features(sess).join(","); + let mte_feature_enabled = features.rfind("+mte"); + let mte_feature_disabled = features.rfind("-mte"); + + if mte_feature_enabled.is_none() || (mte_feature_disabled > mte_feature_enabled) { + sess.err("`-Zsanitizer=memtag` requires `-Ctarget-feature=+mte`"); + } + + llvm::Attribute::SanitizeMemTag.apply_llfn(Function, llfn); + } } /// Tell LLVM to emit or not emit the information necessary to unwind the stack for the function. |
