[PATCH] D96941: [dfsan] Refactor defining TLS variables
stephan.yichao.zhao via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 18 10:00:17 PST 2021
stephan.yichao.zhao updated this revision to Diff 324686.
stephan.yichao.zhao retitled this revision from " [dfsan] Refactor defining TLS variables" to "[dfsan] Refactor defining TLS variables".
stephan.yichao.zhao added a comment.
chanegd getOrInsertGlobal to be a lambda.
We still keep Ty because it is different at callsites.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D96941/new/
https://reviews.llvm.org/D96941
Files:
llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
Index: llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -1073,19 +1073,23 @@
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96941.324686.patch
Type: text/x-patch
Size: 1885 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210218/197ba97d/attachment.bin>
More information about the llvm-commits
mailing list