[llvm] 406dc54 - [dfsan] Refactor defining TLS variables
Jianzhou Zhao via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 18 10:04:52 PST 2021
Author: Jianzhou Zhao
Date: 2021-02-18T18:04:21Z
New Revision: 406dc549034adc4da5e6f45ef3d9aef98c177331
URL: https://github.com/llvm/llvm-project/commit/406dc549034adc4da5e6f45ef3d9aef98c177331
DIFF: https://github.com/llvm/llvm-project/commit/406dc549034adc4da5e6f45ef3d9aef98c177331.diff
LOG: [dfsan] Refactor defining TLS variables
This is a part of https://reviews.llvm.org/D95835.
Reviewed-by: morehouse
Differential Revision: https://reviews.llvm.org/D96941
Added:
Modified:
llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
index 10e510baee74..de3831870627 100644
--- a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -1098,19 +1098,23 @@ bool DataFlowSanitizer::runImpl(Module &M) {
bool Changed = false;
- Type *ArgTLSTy = ArrayType::get(Type::getInt64Ty(*Ctx), kArgTLSSize / 8);
- ArgTLS = Mod->getOrInsertGlobal("__dfsan_arg_tls", ArgTLSTy);
- if (GlobalVariable *G = dyn_cast<GlobalVariable>(ArgTLS)) {
- Changed |= G->getThreadLocalMode() != GlobalVariable::InitialExecTLSModel;
- G->setThreadLocalMode(GlobalVariable::InitialExecTLSModel);
- }
- Type *RetvalTLSTy =
- ArrayType::get(Type::getInt64Ty(*Ctx), kRetvalTLSSize / 8);
- RetvalTLS = Mod->getOrInsertGlobal("__dfsan_retval_tls", RetvalTLSTy);
- if (GlobalVariable *G = dyn_cast<GlobalVariable>(RetvalTLS)) {
- Changed |= G->getThreadLocalMode() != GlobalVariable::InitialExecTLSModel;
- G->setThreadLocalMode(GlobalVariable::InitialExecTLSModel);
- }
+ auto getOrInsertGlobal = [this, &Changed](StringRef Name,
+ Type *Ty) -> Constant * {
+ Constant *C = Mod->getOrInsertGlobal(Name, Ty);
+ if (GlobalVariable *G = dyn_cast<GlobalVariable>(C)) {
+ Changed |= G->getThreadLocalMode() != GlobalVariable::InitialExecTLSModel;
+ G->setThreadLocalMode(GlobalVariable::InitialExecTLSModel);
+ }
+ return C;
+ };
+
+ // These globals must be kept in sync with the ones in dfsan.cpp.
+ ArgTLS = getOrInsertGlobal(
+ "__dfsan_arg_tls",
+ ArrayType::get(Type::getInt64Ty(*Ctx), kArgTLSSize / 8));
+ RetvalTLS = getOrInsertGlobal(
+ "__dfsan_retval_tls",
+ ArrayType::get(Type::getInt64Ty(*Ctx), kRetvalTLSSize / 8));
ExternalShadowMask =
Mod->getOrInsertGlobal(kDFSanExternShadowPtrMask, IntptrTy);
More information about the llvm-commits
mailing list