From b39a97c8f6c02f5ce9d048849dfae4c3ee26d5ee Mon Sep 17 00:00:00 2001 From: Philip Pfaffe Date: Thu, 3 Jan 2019 13:42:44 +0000 Subject: [NewPM] Port Msan Summary: Keeping msan a function pass requires replacing the module level initialization: That means, don't define a ctor function which calls __msan_init, instead just declare the init function at the first access, and add that to the global ctors list. Changes: - Pull the actual sanitizer and the wrapper pass apart. - Add a newpm msan pass. The function pass inserts calls to runtime library functions, for which it inserts declarations as necessary. - Update tests. Caveats: - There is one test that I dropped, because it specifically tested the definition of the ctor. Reviewers: chandlerc, fedor.sergeev, leonardchan, vitalybuka Subscribers: sdardis, nemanjai, javed.absar, hiraditya, kbarton, bollu, atanasyan, jsji Differential Revision: https://reviews.llvm.org/D55647 llvm-svn: 350305 --- llvm/lib/Transforms/Utils/ModuleUtils.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'llvm/lib/Transforms/Utils/ModuleUtils.cpp') diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp index ba4b7f3..8040cc7 100644 --- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp +++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp @@ -174,6 +174,27 @@ std::pair llvm::createSanitizerCtorAndInitFunctions( return std::make_pair(Ctor, InitFunction); } +Function *llvm::getOrCreateInitFunction(Module &M, StringRef Name) { + assert(!Name.empty() && "Expected init function name"); + if (Function *F = M.getFunction(Name)) { + if (F->arg_size() != 0 || + F->getReturnType() != Type::getVoidTy(M.getContext())) { + std::string Err; + raw_string_ostream Stream(Err); + Stream << "Sanitizer interface function defined with wrong type: " << *F; + report_fatal_error(Err); + } + return F; + } + Function *F = checkSanitizerInterfaceFunction(M.getOrInsertFunction( + Name, AttributeList(), Type::getVoidTy(M.getContext()))); + F->setLinkage(Function::ExternalLinkage); + + appendToGlobalCtors(M, F, 0); + + return F; +} + void llvm::filterDeadComdatFunctions( Module &M, SmallVectorImpl &DeadComdatFunctions) { // Build a map from the comdat to the number of entries in that comdat we -- cgit v1.1