llvm.org GIT mirror llvm / 1976555
hwasan: Initialize the pass only once. This will let us instrument globals during initialization. This required making the new PM pass a module pass, which should still provide access to analyses via the ModuleAnalysisManager. Differential Revision: https://reviews.llvm.org/D64843 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366379 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 2 months ago
4 changed file(s) with 26 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
2525 public:
2626 explicit HWAddressSanitizerPass(bool CompileKernel = false,
2727 bool Recover = false);
28 PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
28 PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
2929
3030 private:
3131 bool CompileKernel;
5454 MODULE_PASS("globalopt", GlobalOptPass())
5555 MODULE_PASS("globalsplit", GlobalSplitPass())
5656 MODULE_PASS("hotcoldsplit", HotColdSplittingPass())
57 MODULE_PASS("hwasan", HWAddressSanitizerPass(false, false))
58 MODULE_PASS("khwasan", HWAddressSanitizerPass(true, true))
5759 MODULE_PASS("inferattrs", InferFunctionAttrsPass())
5860 MODULE_PASS("insert-gcov-profiling", GCOVProfilerPass())
5961 MODULE_PASS("instrorderfile", InstrOrderFilePass())
239241 FUNCTION_PASS("transform-warning", WarnMissedTransformationsPass())
240242 FUNCTION_PASS("asan", AddressSanitizerPass(false, false, false))
241243 FUNCTION_PASS("kasan", AddressSanitizerPass(true, false, false))
242 FUNCTION_PASS("hwasan", HWAddressSanitizerPass(false, false))
243 FUNCTION_PASS("khwasan", HWAddressSanitizerPass(true, true))
244244 FUNCTION_PASS("msan", MemorySanitizerPass({}))
245245 FUNCTION_PASS("kmsan", MemorySanitizerPass({0, false, /*Kernel=*/true}))
246246 FUNCTION_PASS("tsan", ThreadSanitizerPass())
276276
277277 StringRef getPassName() const override { return "HWAddressSanitizer"; }
278278
279 bool doInitialization(Module &M) override {
280 HWASan = llvm::make_unique(M, CompileKernel, Recover);
281 return true;
282 }
283
279284 bool runOnFunction(Function &F) override {
280 HWAddressSanitizer HWASan(*F.getParent(), CompileKernel, Recover);
281 return HWASan.sanitizeFunction(F);
285 return HWASan->sanitizeFunction(F);
286 }
287
288 bool doFinalization(Module &M) override {
289 HWASan.reset();
290 return false;
282291 }
283292
284293 private:
294 std::unique_ptr HWASan;
285295 bool CompileKernel;
286296 bool Recover;
287297 };
308318 HWAddressSanitizerPass::HWAddressSanitizerPass(bool CompileKernel, bool Recover)
309319 : CompileKernel(CompileKernel), Recover(Recover) {}
310320
311 PreservedAnalyses HWAddressSanitizerPass::run(Function &F,
312 FunctionAnalysisManager &FAM) {
313 HWAddressSanitizer HWASan(*F.getParent(), CompileKernel, Recover);
314 if (HWASan.sanitizeFunction(F))
321 PreservedAnalyses HWAddressSanitizerPass::run(Module &M,
322 ModuleAnalysisManager &MAM) {
323 HWAddressSanitizer HWASan(M, CompileKernel, Recover);
324 bool Modified = false;
325 for (Function &F : M)
326 Modified |= HWASan.sanitizeFunction(F);
327 if (Modified)
315328 return PreservedAnalyses::none();
316329 return PreservedAnalyses::all();
317330 }
55 ; RUN: opt < %s -hwasan -hwasan-recover=1 -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=CHECK,RECOVER,RECOVER-ZERO-BASED-SHADOW
66
77 ; Ensure than hwasan runs with the new PM pass
8 ; RUN: opt < %s -passes='function(hwasan)' -hwasan-recover=0 -hwasan-with-ifunc=1 -hwasan-with-tls=0 -S | FileCheck %s --check-prefixes=CHECK,ABORT,ABORT-DYNAMIC-SHADOW
9 ; RUN: opt < %s -passes='function(hwasan)' -hwasan-recover=1 -hwasan-with-ifunc=1 -hwasan-with-tls=0 -S | FileCheck %s --check-prefixes=CHECK,RECOVER,RECOVER-DYNAMIC-SHADOW
10 ; RUN: opt < %s -passes='function(hwasan)' -hwasan-recover=0 -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=CHECK,ABORT,ABORT-ZERO-BASED-SHADOW
11 ; RUN: opt < %s -passes='function(hwasan)' -hwasan-recover=1 -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=CHECK,RECOVER,RECOVER-ZERO-BASED-SHADOW
8 ; RUN: opt < %s -passes=hwasan -hwasan-recover=0 -hwasan-with-ifunc=1 -hwasan-with-tls=0 -S | FileCheck %s --check-prefixes=CHECK,ABORT,ABORT-DYNAMIC-SHADOW
9 ; RUN: opt < %s -passes=hwasan -hwasan-recover=1 -hwasan-with-ifunc=1 -hwasan-with-tls=0 -S | FileCheck %s --check-prefixes=CHECK,RECOVER,RECOVER-DYNAMIC-SHADOW
10 ; RUN: opt < %s -passes=hwasan -hwasan-recover=0 -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=CHECK,ABORT,ABORT-ZERO-BASED-SHADOW
11 ; RUN: opt < %s -passes=hwasan -hwasan-recover=1 -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=CHECK,RECOVER,RECOVER-ZERO-BASED-SHADOW
1212
1313 ; CHECK: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* @hwasan.module_ctor, i8* bitcast (void ()* @hwasan.module_ctor to i8*) }]
1414