|
33 | 33 | #include "llvm/Support/TimeProfiler.h" |
34 | 34 | #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h" |
35 | 35 | #include "llvm/Transforms/Instrumentation/MemorySanitizer.h" |
| 36 | +#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h" |
36 | 37 | #include "llvm/Transforms/Utils/CanonicalizeAliases.h" |
37 | 38 | #include "llvm/Transforms/Utils/NameAnonGlobals.h" |
38 | 39 |
|
@@ -133,6 +134,12 @@ extern "C" LLVMPassRef LLVMRustCreateThreadSanitizerPass() { |
133 | 134 | return wrap(createThreadSanitizerLegacyPassPass()); |
134 | 135 | } |
135 | 136 |
|
| 137 | +extern "C" LLVMPassRef LLVMRustCreateHWAddressSanitizerPass(bool Recover) { |
| 138 | + const bool CompileKernel = false; |
| 139 | + |
| 140 | + return wrap(createHWAddressSanitizerLegacyPassPass(CompileKernel, Recover)); |
| 141 | +} |
| 142 | + |
136 | 143 | extern "C" LLVMRustPassKind LLVMRustPassKind(LLVMPassRef RustPass) { |
137 | 144 | assert(RustPass); |
138 | 145 | Pass *Pass = unwrap(RustPass); |
@@ -722,6 +729,8 @@ struct LLVMRustSanitizerOptions { |
722 | 729 | bool SanitizeMemoryRecover; |
723 | 730 | int SanitizeMemoryTrackOrigins; |
724 | 731 | bool SanitizeThread; |
| 732 | + bool SanitizeHWAddress; |
| 733 | + bool SanitizeHWAddressRecover; |
725 | 734 | }; |
726 | 735 |
|
727 | 736 | extern "C" void |
@@ -886,6 +895,23 @@ LLVMRustOptimizeWithNewPassManager( |
886 | 895 | /*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover)); |
887 | 896 | } |
888 | 897 | ); |
| 898 | +#endif |
| 899 | + } |
| 900 | + if (SanitizerOptions->SanitizeHWAddress) { |
| 901 | +#if LLVM_VERSION_GE(11, 0) |
| 902 | + OptimizerLastEPCallbacks.push_back( |
| 903 | + [SanitizerOptions](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { |
| 904 | + MPM.addPass(HWAddressSanitizerPass( |
| 905 | + /*CompileKernel=*/false, SanitizerOptions->SanitizeHWAddressRecover)); |
| 906 | + } |
| 907 | + ); |
| 908 | +#else |
| 909 | + PipelineStartEPCallbacks.push_back( |
| 910 | + [SanitizerOptions](ModulePassManager &MPM) { |
| 911 | + MPM.addPass(HWAddressSanitizerPass( |
| 912 | + /*CompileKernel=*/false, SanitizerOptions->SanitizeHWAddressRecover)); |
| 913 | + } |
| 914 | + ); |
889 | 915 | #endif |
890 | 916 | } |
891 | 917 | } |
|
0 commit comments