Skip to content

Commit

Permalink
[ASAN] Add doFinalization to reset state
Browse files Browse the repository at this point in the history
Summary: If the same pass manager is used for multiple modules ASAN
complains about GlobalsMD being initialized twice. Fix this by
resetting GlobalsMD in a new doFinalization method to allow this
use case.

Reviewers: kcc

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D14962

llvm-svn: 254851
  • Loading branch information
Keno committed Dec 5, 2015
1 parent 44375e4 commit e03fae4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ class GlobalsMetadata {

GlobalsMetadata() : inited_(false) {}

void reset() {
inited_ = false;
Entries.clear();
}

void init(Module &M) {
assert(!inited_);
inited_ = true;
Expand Down Expand Up @@ -450,6 +455,7 @@ struct AddressSanitizer : public FunctionPass {
bool maybeInsertAsanInitAtFunctionEntry(Function &F);
void markEscapedLocalAllocas(Function &F);
bool doInitialization(Module &M) override;
bool doFinalization(Module &M) override;
static char ID; // Pass identification, replacement for typeid

DominatorTree &getDominatorTree() const { return *DT; }
Expand Down Expand Up @@ -1521,6 +1527,11 @@ bool AddressSanitizer::doInitialization(Module &M) {
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.
Expand Down
8 changes: 8 additions & 0 deletions llvm/test/Instrumentation/AddressSanitizer/twice.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; Check that the address sanitizer pass can be reused
; RUN: opt < %s -S -run-twice -asan

define void @foo(i64* %b) nounwind uwtable sanitize_address {
entry:
store i64 0, i64* %b, align 1
ret void
}

0 comments on commit e03fae4

Please sign in to comment.