[llvm] r345433 - Revert "[PassManager/Sanitizer] Enable usage of ported AddressSanitizer passes with -fsanitize=address"
Leonard Chan via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 26 15:51:51 PDT 2018
Author: leonardchan
Date: Fri Oct 26 15:51:51 2018
New Revision: 345433
URL: http://llvm.org/viewvc/llvm-project?rev=345433&view=rev
Log:
Revert "[PassManager/Sanitizer] Enable usage of ported AddressSanitizer passes with -fsanitize=address"
This reverts commit 8d6af840396f2da2e4ed6aab669214ae25443204 and commit
b78d19c287b6e4a9abc9fb0545de9a3106d38d3d which causes slower build times
by initializing the AddressSanitizer on every function run.
The corresponding revisions are https://reviews.llvm.org/D52814 and
https://reviews.llvm.org/D52739.
Removed:
llvm/trunk/include/llvm/Transforms/Instrumentation/AddressSanitizerPass.h
Modified:
llvm/trunk/include/llvm/InitializePasses.h
llvm/trunk/lib/Passes/PassBuilder.cpp
llvm/trunk/lib/Passes/PassRegistry.def
llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp
llvm/trunk/test/Instrumentation/AddressSanitizer/basic.ll
Modified: llvm/trunk/include/llvm/InitializePasses.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=345433&r1=345432&r2=345433&view=diff
==============================================================================
--- llvm/trunk/include/llvm/InitializePasses.h (original)
+++ llvm/trunk/include/llvm/InitializePasses.h Fri Oct 26 15:51:51 2018
@@ -65,8 +65,8 @@ void initializeAAEvalLegacyPassPass(Pass
void initializeAAResultsWrapperPassPass(PassRegistry&);
void initializeADCELegacyPassPass(PassRegistry&);
void initializeAddDiscriminatorsLegacyPassPass(PassRegistry&);
-void initializeAddressSanitizerModuleLegacyPassPass(PassRegistry &);
-void initializeAddressSanitizerLegacyPassPass(PassRegistry &);
+void initializeAddressSanitizerModulePass(PassRegistry&);
+void initializeAddressSanitizerPass(PassRegistry&);
void initializeAggressiveInstCombinerLegacyPassPass(PassRegistry&);
void initializeAliasSetPrinterPass(PassRegistry&);
void initializeAlignmentFromAssumptionsPass(PassRegistry&);
Removed: llvm/trunk/include/llvm/Transforms/Instrumentation/AddressSanitizerPass.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Instrumentation/AddressSanitizerPass.h?rev=345432&view=auto
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Instrumentation/AddressSanitizerPass.h (original)
+++ llvm/trunk/include/llvm/Transforms/Instrumentation/AddressSanitizerPass.h (removed)
@@ -1,41 +0,0 @@
-//===--------- Definition of the AddressSanitizer class ---------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file declares the AddressSanitizer class which is a port of the legacy
-// AddressSanitizer pass to use the new PassManager infrastructure.
-//
-//===----------------------------------------------------------------------===//
-#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZERPASS_H
-#define LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZERPASS_H
-
-#include "llvm/IR/Function.h"
-#include "llvm/IR/Module.h"
-#include "llvm/IR/PassManager.h"
-
-namespace llvm {
-
-/// Public interface to the address sanitizer pass for instrumenting code to
-/// check for various memory bugs.
-class AddressSanitizerPass : public PassInfoMixin<AddressSanitizerPass> {
-public:
- explicit AddressSanitizerPass(bool CompileKernel = false,
- bool Recover = false,
- bool UseAfterScope = false);
- PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
- PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
-
-private:
- bool CompileKernel;
- bool Recover;
- bool UseAfterScope;
-};
-
-} // namespace llvm
-
-#endif
Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=345433&r1=345432&r2=345433&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
+++ llvm/trunk/lib/Passes/PassBuilder.cpp Fri Oct 26 15:51:51 2018
@@ -62,6 +62,7 @@
#include "llvm/Support/Regex.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h"
+#include "llvm/Transforms/Instrumentation/CGProfile.h"
#include "llvm/Transforms/IPO/AlwaysInliner.h"
#include "llvm/Transforms/IPO/ArgumentPromotion.h"
#include "llvm/Transforms/IPO/CalledValuePropagation.h"
@@ -87,9 +88,7 @@
#include "llvm/Transforms/IPO/SyntheticCountsPropagation.h"
#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
#include "llvm/Transforms/InstCombine/InstCombine.h"
-#include "llvm/Transforms/Instrumentation/AddressSanitizerPass.h"
#include "llvm/Transforms/Instrumentation/BoundsChecking.h"
-#include "llvm/Transforms/Instrumentation/CGProfile.h"
#include "llvm/Transforms/Instrumentation/ControlHeightReduction.h"
#include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
Modified: llvm/trunk/lib/Passes/PassRegistry.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassRegistry.def?rev=345433&r1=345432&r2=345433&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassRegistry.def (original)
+++ llvm/trunk/lib/Passes/PassRegistry.def Fri Oct 26 15:51:51 2018
@@ -40,7 +40,6 @@ MODULE_ALIAS_ANALYSIS("globals-aa", Glob
#define MODULE_PASS(NAME, CREATE_PASS)
#endif
MODULE_PASS("always-inline", AlwaysInlinerPass())
-MODULE_PASS("asan", AddressSanitizerPass(false, false, true))
MODULE_PASS("called-value-propagation", CalledValuePropagationPass())
MODULE_PASS("cg-profile", CGProfilePass())
MODULE_PASS("constmerge", ConstantMergePass())
@@ -148,7 +147,6 @@ FUNCTION_PASS("adce", ADCEPass())
FUNCTION_PASS("add-discriminators", AddDiscriminatorsPass())
FUNCTION_PASS("aggressive-instcombine", AggressiveInstCombinePass())
FUNCTION_PASS("alignment-from-assumptions", AlignmentFromAssumptionsPass())
-FUNCTION_PASS("asan", AddressSanitizerPass(false, false, false))
FUNCTION_PASS("bdce", BDCEPass())
FUNCTION_PASS("bounds-checking", BoundsCheckingPass())
FUNCTION_PASS("break-crit-edges", BreakCriticalEdgesPass())
Modified: llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?rev=345433&r1=345432&r2=345433&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp Fri Oct 26 15:51:51 2018
@@ -25,6 +25,7 @@
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
+#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/BinaryFormat/MachO.h"
#include "llvm/IR/Argument.h"
@@ -69,10 +70,8 @@
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Instrumentation.h"
-#include "llvm/Transforms/Instrumentation/AddressSanitizerPass.h"
#include "llvm/Transforms/Utils/ASanStackFrameLayout.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
-#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"
#include "llvm/Transforms/Utils/PromoteMemToReg.h"
#include <algorithm>
@@ -598,22 +597,26 @@ static size_t RedzoneSizeForScale(int Ma
namespace {
/// AddressSanitizer: instrument the code in module to find memory bugs.
-struct AddressSanitizer {
- explicit AddressSanitizer(Module &M, DominatorTree *DT,
- bool CompileKernel = false, bool Recover = false,
+struct AddressSanitizer : public FunctionPass {
+ // Pass identification, replacement for typeid
+ static char ID;
+
+ explicit AddressSanitizer(bool CompileKernel = false, bool Recover = false,
bool UseAfterScope = false)
- : UseAfterScope(UseAfterScope || ClUseAfterScope), DT(DT) {
+ : FunctionPass(ID), UseAfterScope(UseAfterScope || ClUseAfterScope) {
this->Recover = ClRecover.getNumOccurrences() > 0 ? ClRecover : Recover;
this->CompileKernel = ClEnableKasan.getNumOccurrences() > 0 ?
ClEnableKasan : CompileKernel;
+ initializeAddressSanitizerPass(*PassRegistry::getPassRegistry());
+ }
+
+ StringRef getPassName() const override {
+ return "AddressSanitizerFunctionPass";
+ }
- // Initialize the private fields. No one has accessed them before.
- GlobalsMD.init(M);
- C = &(M.getContext());
- LongSize = M.getDataLayout().getPointerSizeInBits();
- IntptrTy = Type::getIntNTy(*C, LongSize);
- TargetTriple = Triple(M.getTargetTriple());
- Mapping = getShadowMapping(TargetTriple, LongSize, CompileKernel);
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.addRequired<DominatorTreeWrapperPass>();
+ AU.addRequired<TargetLibraryInfoWrapperPass>();
}
uint64_t getAllocaSizeInBytes(const AllocaInst &AI) const {
@@ -658,12 +661,12 @@ struct AddressSanitizer {
Value *SizeArgument, uint32_t Exp);
void instrumentMemIntrinsic(MemIntrinsic *MI);
Value *memToShadow(Value *Shadow, IRBuilder<> &IRB);
+ bool runOnFunction(Function &F) override;
bool maybeInsertAsanInitAtFunctionEntry(Function &F);
void maybeInsertDynamicShadowAtFunctionEntry(Function &F);
void markEscapedLocalAllocas(Function &F);
-
- /// Return true if the function changed.
- bool instrument(Function &F, const TargetLibraryInfo *TLI);
+ bool doInitialization(Module &M) override;
+ bool doFinalization(Module &M) override;
DominatorTree &getDominatorTree() const { return *DT; }
@@ -721,12 +724,16 @@ private:
DenseMap<const AllocaInst *, bool> ProcessedAllocas;
};
-class AddressSanitizerModule {
+class AddressSanitizerModule : public ModulePass {
public:
+ // Pass identification, replacement for typeid
+ static char ID;
+
explicit AddressSanitizerModule(bool CompileKernel = false,
bool Recover = false,
bool UseGlobalsGC = true)
- : UseGlobalsGC(UseGlobalsGC && ClUseGlobalsGC),
+ : ModulePass(ID),
+ UseGlobalsGC(UseGlobalsGC && ClUseGlobalsGC),
// Not a typo: ClWithComdat is almost completely pointless without
// ClUseGlobalsGC (because then it only works on modules without
// globals, which are rare); it is a prerequisite for ClUseGlobalsGC;
@@ -735,12 +742,14 @@ public:
// ClWithComdat and ClUseGlobalsGC unless the frontend says it's ok to
// do globals-gc.
UseCtorComdat(UseGlobalsGC && ClWithComdat) {
- this->Recover = ClRecover.getNumOccurrences() > 0 ? ClRecover : Recover;
- this->CompileKernel =
- ClEnableKasan.getNumOccurrences() > 0 ? ClEnableKasan : CompileKernel;
- }
+ this->Recover = ClRecover.getNumOccurrences() > 0 ?
+ ClRecover : Recover;
+ this->CompileKernel = ClEnableKasan.getNumOccurrences() > 0 ?
+ ClEnableKasan : CompileKernel;
+ }
- bool instrument(Module &M);
+ bool runOnModule(Module &M) override;
+ StringRef getPassName() const override { return "AddressSanitizerModule"; }
private:
void initializeCallbacks(Module &M);
@@ -1048,102 +1057,18 @@ struct FunctionStackPoisoner : public In
Instruction *ThenTerm, Value *ValueIfFalse);
};
-class AddressSanitizerLegacyPass : public FunctionPass {
-public:
- static char ID;
-
- explicit AddressSanitizerLegacyPass(bool CompileKernel = false,
- bool Recover = false,
- bool UseAfterScope = false)
- : FunctionPass(ID), CompileKernel(CompileKernel), Recover(Recover),
- UseAfterScope(UseAfterScope) {
- initializeAddressSanitizerLegacyPassPass(*PassRegistry::getPassRegistry());
- }
-
- StringRef getPassName() const override {
- return "AddressSanitizerFunctionPass";
- }
-
- void getAnalysisUsage(AnalysisUsage &AU) const override {
- AU.addRequired<DominatorTreeWrapperPass>();
- AU.addRequired<TargetLibraryInfoWrapperPass>();
- }
-
- bool runOnFunction(Function &F) override {
- DominatorTree *DTree =
- &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
- const TargetLibraryInfo *TLI =
- &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
- AddressSanitizer Sanitizer(*F.getParent(), DTree, CompileKernel, Recover,
- UseAfterScope);
- return Sanitizer.instrument(F, TLI);
- }
-
-private:
- bool CompileKernel;
- bool Recover;
- bool UseAfterScope;
-};
-
-class AddressSanitizerModuleLegacyPass : public ModulePass {
-public:
- static char ID;
-
- explicit AddressSanitizerModuleLegacyPass(bool CompileKernel = false,
- bool Recover = false,
- bool UseAfterScope = true)
- : ModulePass(ID), CompileKernel(CompileKernel), Recover(Recover),
- UseAfterScope(UseAfterScope) {}
-
- StringRef getPassName() const override { return "AddressSanitizerModule"; }
-
- bool runOnModule(Module &M) override {
- AddressSanitizerModule Sanitizer(CompileKernel, Recover, UseAfterScope);
- return Sanitizer.instrument(M);
- }
-
-private:
- bool CompileKernel;
- bool Recover;
- bool UseAfterScope;
-};
-
} // end anonymous namespace
-AddressSanitizerPass::AddressSanitizerPass(bool CompileKernel, bool Recover,
- bool UseAfterScope)
- : CompileKernel(CompileKernel), Recover(Recover),
- UseAfterScope(UseAfterScope) {}
-
-PreservedAnalyses AddressSanitizerPass::run(Function &F,
- AnalysisManager<Function> &AM) {
- DominatorTree *DT = &AM.getResult<DominatorTreeAnalysis>(F);
- const TargetLibraryInfo *TLI = &AM.getResult<TargetLibraryAnalysis>(F);
- AddressSanitizer Sanitizer(*F.getParent(), DT, CompileKernel, Recover,
- UseAfterScope);
- if (Sanitizer.instrument(F, TLI))
- return PreservedAnalyses::none();
- return PreservedAnalyses::all();
-}
-
-PreservedAnalyses AddressSanitizerPass::run(Module &M,
- AnalysisManager<Module> &AM) {
- AddressSanitizerModule Sanitizer(CompileKernel, Recover, UseAfterScope);
- if (Sanitizer.instrument(M))
- return PreservedAnalyses::none();
- return PreservedAnalyses::all();
-}
-
-char AddressSanitizerLegacyPass::ID = 0;
+char AddressSanitizer::ID = 0;
INITIALIZE_PASS_BEGIN(
- AddressSanitizerLegacyPass, "asan",
+ AddressSanitizer, "asan",
"AddressSanitizer: detects use-after-free and out-of-bounds bugs.", false,
false)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
INITIALIZE_PASS_END(
- AddressSanitizerLegacyPass, "asan",
+ AddressSanitizer, "asan",
"AddressSanitizer: detects use-after-free and out-of-bounds bugs.", false,
false)
@@ -1151,13 +1076,13 @@ FunctionPass *llvm::createAddressSanitiz
bool Recover,
bool UseAfterScope) {
assert(!CompileKernel || Recover);
- return new AddressSanitizerLegacyPass(CompileKernel, Recover, UseAfterScope);
+ return new AddressSanitizer(CompileKernel, Recover, UseAfterScope);
}
-char AddressSanitizerModuleLegacyPass::ID = 0;
+char AddressSanitizerModule::ID = 0;
INITIALIZE_PASS(
- AddressSanitizerModuleLegacyPass, "asan-module",
+ AddressSanitizerModule, "asan-module",
"AddressSanitizer: detects use-after-free and out-of-bounds bugs."
"ModulePass",
false, false)
@@ -1166,8 +1091,7 @@ ModulePass *llvm::createAddressSanitizer
bool Recover,
bool UseGlobalsGC) {
assert(!CompileKernel || Recover);
- return new AddressSanitizerModuleLegacyPass(CompileKernel, Recover,
- UseGlobalsGC);
+ return new AddressSanitizerModule(CompileKernel, Recover, UseGlobalsGC);
}
static size_t TypeSizeToSizeIndex(uint32_t TypeSize) {
@@ -2331,7 +2255,7 @@ int AddressSanitizerModule::GetAsanVersi
return Version;
}
-bool AddressSanitizerModule::instrument(Module &M) {
+bool AddressSanitizerModule::runOnModule(Module &M) {
C = &(M.getContext());
int LongSize = M.getDataLayout().getPointerSizeInBits();
IntptrTy = Type::getIntNTy(*C, LongSize);
@@ -2450,6 +2374,25 @@ void AddressSanitizer::initializeCallbac
ArrayType::get(IRB.getInt8Ty(), 0));
}
+// virtual
+bool AddressSanitizer::doInitialization(Module &M) {
+ // Initialize the private fields. No one has accessed them before.
+ GlobalsMD.init(M);
+
+ C = &(M.getContext());
+ LongSize = M.getDataLayout().getPointerSizeInBits();
+ IntptrTy = Type::getIntNTy(*C, LongSize);
+ TargetTriple = Triple(M.getTargetTriple());
+
+ Mapping = getShadowMapping(TargetTriple, LongSize, CompileKernel);
+ return true;
+}
+
+bool AddressSanitizer::doFinalization(Module &M) {
+ GlobalsMD.reset();
+ return false;
+}
+
bool AddressSanitizer::maybeInsertAsanInitAtFunctionEntry(Function &F) {
// For each NSObject descendant having a +load method, this method is invoked
// by the ObjC runtime before any of the static constructors is called.
@@ -2523,7 +2466,7 @@ void AddressSanitizer::markEscapedLocalA
}
}
-bool AddressSanitizer::instrument(Function &F, const TargetLibraryInfo *TLI) {
+bool AddressSanitizer::runOnFunction(Function &F) {
if (F.getLinkage() == GlobalValue::AvailableExternallyLinkage) return false;
if (!ClDebugFunc.empty() && ClDebugFunc == F.getName()) return false;
if (F.getName().startswith("__asan_")) return false;
@@ -2542,6 +2485,7 @@ bool AddressSanitizer::instrument(Functi
LLVM_DEBUG(dbgs() << "ASAN instrumenting:\n" << F << "\n");
initializeCallbacks(*F.getParent());
+ DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
FunctionStateRAII CleanupObj(this);
@@ -2562,6 +2506,8 @@ bool AddressSanitizer::instrument(Functi
bool IsWrite;
unsigned Alignment;
uint64_t TypeSize;
+ const TargetLibraryInfo *TLI =
+ &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
// Fill the set of memory operations to instrument.
for (auto &BB : F) {
Modified: llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp?rev=345433&r1=345432&r2=345433&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp Fri Oct 26 15:51:51 2018
@@ -88,8 +88,8 @@ Comdat *llvm::GetOrCreateFunctionComdat(
/// initializeInstrumentation - Initialize all passes in the TransformUtils
/// library.
void llvm::initializeInstrumentation(PassRegistry &Registry) {
- initializeAddressSanitizerLegacyPassPass(Registry);
- initializeAddressSanitizerModuleLegacyPassPass(Registry);
+ initializeAddressSanitizerPass(Registry);
+ initializeAddressSanitizerModulePass(Registry);
initializeBoundsCheckingLegacyPassPass(Registry);
initializeControlHeightReductionLegacyPassPass(Registry);
initializeGCOVProfilerLegacyPassPass(Registry);
Modified: llvm/trunk/test/Instrumentation/AddressSanitizer/basic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/AddressSanitizer/basic.ll?rev=345433&r1=345432&r2=345433&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/AddressSanitizer/basic.ll (original)
+++ llvm/trunk/test/Instrumentation/AddressSanitizer/basic.ll Fri Oct 26 15:51:51 2018
@@ -1,9 +1,7 @@
; Test basic address sanitizer instrumentation.
;
; RUN: opt < %s -asan -asan-module -S | FileCheck --check-prefixes=CHECK,CHECK-S3 %s
-; RUN: opt < %s -passes='function(asan),module(asan)' -S | FileCheck --check-prefixes=CHECK,CHECK-S3 %s
; RUN: opt < %s -asan -asan-module -asan-mapping-scale=5 -S | FileCheck --check-prefixes=CHECK,CHECK-S5 %s
-; RUN: opt < %s -passes='function(asan),module(asan)' -asan-mapping-scale=5 -S | FileCheck --check-prefixes=CHECK,CHECK-S5 %s
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-unknown-linux-gnu"
More information about the llvm-commits
mailing list