From 2e6cd338c6d4605fa599f583bc8ca202dda6a551 Mon Sep 17 00:00:00 2001 From: Jianzhou Zhao Date: Thu, 18 Feb 2021 08:04:30 +0000 Subject: [PATCH] [dfsan] Refactor runtime functions checking This is a part of https://reviews.llvm.org/D95835. Reviewed-by: morehouse Differential Revision: https://reviews.llvm.org/D96940 --- .../Instrumentation/DataFlowSanitizer.cpp | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp index 331715765b32..10e510baee74 100644 --- a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp @@ -393,6 +393,7 @@ class DataFlowSanitizer { FunctionCallee DFSanStoreCallbackFn; FunctionCallee DFSanMemTransferCallbackFn; FunctionCallee DFSanCmpCallbackFn; + SmallPtrSet DFSanRuntimeFunctions; MDNode *ColdCallWeights; DFSanABIList ABIList; DenseMap UnwrappedFnMap; @@ -1048,6 +1049,30 @@ void DataFlowSanitizer::initializeRuntimeFunctions(Module &M) { Mod->getOrInsertFunction("__dfsan_nonzero_label", DFSanNonzeroLabelFnTy); DFSanVarargWrapperFn = Mod->getOrInsertFunction("__dfsan_vararg_wrapper", DFSanVarargWrapperFnTy); + + DFSanRuntimeFunctions.insert(DFSanUnionFn.getCallee()->stripPointerCasts()); + DFSanRuntimeFunctions.insert( + DFSanCheckedUnionFn.getCallee()->stripPointerCasts()); + DFSanRuntimeFunctions.insert( + DFSanUnionLoadFn.getCallee()->stripPointerCasts()); + DFSanRuntimeFunctions.insert( + DFSanUnionLoadFast16LabelsFn.getCallee()->stripPointerCasts()); + DFSanRuntimeFunctions.insert( + DFSanUnimplementedFn.getCallee()->stripPointerCasts()); + DFSanRuntimeFunctions.insert( + DFSanSetLabelFn.getCallee()->stripPointerCasts()); + DFSanRuntimeFunctions.insert( + DFSanNonzeroLabelFn.getCallee()->stripPointerCasts()); + DFSanRuntimeFunctions.insert( + DFSanVarargWrapperFn.getCallee()->stripPointerCasts()); + DFSanRuntimeFunctions.insert( + DFSanLoadCallbackFn.getCallee()->stripPointerCasts()); + DFSanRuntimeFunctions.insert( + DFSanStoreCallbackFn.getCallee()->stripPointerCasts()); + DFSanRuntimeFunctions.insert( + DFSanMemTransferCallbackFn.getCallee()->stripPointerCasts()); + DFSanRuntimeFunctions.insert( + DFSanCmpCallbackFn.getCallee()->stripPointerCasts()); } // Initializes event callback functions and declare them in the module @@ -1095,22 +1120,9 @@ bool DataFlowSanitizer::runImpl(Module &M) { std::vector FnsToInstrument; SmallPtrSet FnsWithNativeABI; - for (Function &i : M) { - if (!i.isIntrinsic() && - &i != DFSanUnionFn.getCallee()->stripPointerCasts() && - &i != DFSanCheckedUnionFn.getCallee()->stripPointerCasts() && - &i != DFSanUnionLoadFn.getCallee()->stripPointerCasts() && - &i != DFSanUnionLoadFast16LabelsFn.getCallee()->stripPointerCasts() && - &i != DFSanUnimplementedFn.getCallee()->stripPointerCasts() && - &i != DFSanSetLabelFn.getCallee()->stripPointerCasts() && - &i != DFSanNonzeroLabelFn.getCallee()->stripPointerCasts() && - &i != DFSanVarargWrapperFn.getCallee()->stripPointerCasts() && - &i != DFSanLoadCallbackFn.getCallee()->stripPointerCasts() && - &i != DFSanStoreCallbackFn.getCallee()->stripPointerCasts() && - &i != DFSanMemTransferCallbackFn.getCallee()->stripPointerCasts() && - &i != DFSanCmpCallbackFn.getCallee()->stripPointerCasts()) + for (Function &i : M) + if (!i.isIntrinsic() && !DFSanRuntimeFunctions.contains(&i)) FnsToInstrument.push_back(&i); - } // Give function aliases prefixes when necessary, and build wrappers where the // instrumentedness is inconsistent. -- 2.34.1