From 83fcf1504597b2ee77276d287e70bd0ae8d201ec Mon Sep 17 00:00:00 2001 From: Martin Nowack Date: Thu, 6 Sep 2018 11:29:06 +0100 Subject: Fix generation of global constructors and destructors Validate if the user-selected entry function exists. Do not assume it is `main`. --- lib/Module/KModule.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/Module') diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp index 74d91a8f..07f3572e 100644 --- a/lib/Module/KModule.cpp +++ b/lib/Module/KModule.cpp @@ -142,14 +142,16 @@ static Function *getStubFunctionForCtorList(Module *m, return fn; } -static void injectStaticConstructorsAndDestructors(Module *m) { +static void +injectStaticConstructorsAndDestructors(Module *m, + llvm::StringRef entryFunction) { GlobalVariable *ctors = m->getNamedGlobal("llvm.global_ctors"); GlobalVariable *dtors = m->getNamedGlobal("llvm.global_dtors"); if (!ctors && !dtors) return; - Function *mainFn = m->getFunction("main"); + Function *mainFn = m->getFunction(entryFunction); if (!mainFn) klee_error("Could not find main() function."); @@ -239,7 +241,7 @@ void KModule::optimiseAndPrepare( // Needs to happen after linking (since ctors/dtors can be modified) // and optimization (since global optimization can rewrite lists). - injectStaticConstructorsAndDestructors(module.get()); + injectStaticConstructorsAndDestructors(module.get(), opts.EntryPoint); // Finally, run the passes that maintain invariants we expect during // interpretation. We run the intrinsic cleaner just in case we -- cgit 1.4.1