Skip to content

Commit bff0987

Browse files
author
serge-sans-paille
committed
Fix return status of DataFlowSanitizer pass
Take into account added functions, global values and attribute change. Differential Revision: https://reviews.llvm.org/D81239
1 parent 90b54fa commit bff0987

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

llvm/include/llvm/IR/Module.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ class Module {
593593
const_global_iterator global_begin() const { return GlobalList.begin(); }
594594
global_iterator global_end () { return GlobalList.end(); }
595595
const_global_iterator global_end () const { return GlobalList.end(); }
596+
size_t global_size () const { return GlobalList.size(); }
596597
bool global_empty() const { return GlobalList.empty(); }
597598

598599
iterator_range<global_iterator> globals() {

llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,16 +811,25 @@ bool DataFlowSanitizer::runOnModule(Module &M) {
811811
if (ABIList.isIn(M, "skip"))
812812
return false;
813813

814+
const unsigned InitialGlobalSize = M.global_size();
815+
const unsigned InitialModuleSize = M.size();
816+
817+
bool Changed = false;
818+
814819
if (!GetArgTLSPtr) {
815820
Type *ArgTLSTy = ArrayType::get(ShadowTy, 64);
816821
ArgTLS = Mod->getOrInsertGlobal("__dfsan_arg_tls", ArgTLSTy);
817-
if (GlobalVariable *G = dyn_cast<GlobalVariable>(ArgTLS))
822+
if (GlobalVariable *G = dyn_cast<GlobalVariable>(ArgTLS)) {
823+
Changed |= G->getThreadLocalMode() != GlobalVariable::InitialExecTLSModel;
818824
G->setThreadLocalMode(GlobalVariable::InitialExecTLSModel);
825+
}
819826
}
820827
if (!GetRetvalTLSPtr) {
821828
RetvalTLS = Mod->getOrInsertGlobal("__dfsan_retval_tls", ShadowTy);
822-
if (GlobalVariable *G = dyn_cast<GlobalVariable>(RetvalTLS))
829+
if (GlobalVariable *G = dyn_cast<GlobalVariable>(RetvalTLS)) {
830+
Changed |= G->getThreadLocalMode() != GlobalVariable::InitialExecTLSModel;
823831
G->setThreadLocalMode(GlobalVariable::InitialExecTLSModel);
832+
}
824833
}
825834

826835
ExternalShadowMask =
@@ -1044,7 +1053,8 @@ bool DataFlowSanitizer::runOnModule(Module &M) {
10441053
}
10451054
}
10461055

1047-
return false;
1056+
return Changed || !FnsToInstrument.empty() ||
1057+
M.global_size() != InitialGlobalSize || M.size() != InitialModuleSize;
10481058
}
10491059

10501060
Value *DFSanFunction::getArgTLSPtr() {

0 commit comments

Comments
 (0)