aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
diff options
context:
space:
mode:
authorIsmail Pazarbasi <ismail.pazarbasi@gmail.com>2015-05-07 21:41:23 +0000
committerIsmail Pazarbasi <ismail.pazarbasi@gmail.com>2015-05-07 21:41:23 +0000
commit2d4ae9f0d5ab5b2c79c20f19b02854272f55754d (patch)
treeeff646ab46f39cdeee7bf80b42e15986a965bf79 /llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
parent09c3709e7565905f4d0594fc2c9aa1f0a6b6c828 (diff)
downloadllvm-2d4ae9f0d5ab5b2c79c20f19b02854272f55754d.zip
llvm-2d4ae9f0d5ab5b2c79c20f19b02854272f55754d.tar.gz
llvm-2d4ae9f0d5ab5b2c79c20f19b02854272f55754d.tar.bz2
TSan: Use `createSanitizerCtor` to create ctor, and call `__tsan_init`
Reviewers: kcc, dvyukov Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D8779 llvm-svn: 236778
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp')
-rw-r--r--llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
index aa8ee5a..b23dacc 100644
--- a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
@@ -72,6 +72,9 @@ STATISTIC(NumOmittedReadsFromConstantGlobals,
STATISTIC(NumOmittedReadsFromVtable, "Number of vtable reads");
STATISTIC(NumOmittedNonCaptured, "Number of accesses ignored due to capturing");
+static const char *const kTsanModuleCtorName = "tsan.module_ctor";
+static const char *const kTsanInitName = "__tsan_init";
+
namespace {
/// ThreadSanitizer: instrument the code in module to find races.
@@ -113,6 +116,7 @@ struct ThreadSanitizer : public FunctionPass {
Function *TsanVptrUpdate;
Function *TsanVptrLoad;
Function *MemmoveFn, *MemcpyFn, *MemsetFn;
+ Function *TsanCtorFunction;
};
} // namespace
@@ -225,13 +229,12 @@ void ThreadSanitizer::initializeCallbacks(Module &M) {
bool ThreadSanitizer::doInitialization(Module &M) {
const DataLayout &DL = M.getDataLayout();
+ IntptrTy = DL.getIntPtrType(M.getContext());
+ std::tie(TsanCtorFunction, std::ignore) = createSanitizerCtorAndInitFunctions(
+ M, kTsanModuleCtorName, kTsanInitName, /*InitArgTypes=*/{},
+ /*InitArgs=*/{});
- // Always insert a call to __tsan_init into the module's CTORs.
- IRBuilder<> IRB(M.getContext());
- IntptrTy = IRB.getIntPtrTy(DL);
- Value *TsanInit = M.getOrInsertFunction("__tsan_init",
- IRB.getVoidTy(), nullptr);
- appendToGlobalCtors(M, cast<Function>(TsanInit), 0);
+ appendToGlobalCtors(M, TsanCtorFunction, 0);
return true;
}
@@ -329,6 +332,10 @@ static bool isAtomic(Instruction *I) {
}
bool ThreadSanitizer::runOnFunction(Function &F) {
+ // This is required to prevent instrumenting call to __tsan_init from within
+ // the module constructor.
+ if (&F == TsanCtorFunction)
+ return false;
initializeCallbacks(*F.getParent());
SmallVector<Instruction*, 8> RetVec;
SmallVector<Instruction*, 8> AllLoadsAndStores;