aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/Module
diff options
context:
space:
mode:
authorMartin Nowack <m.nowack@imperial.ac.uk>2018-09-06 11:29:06 +0100
committerCristian Cadar <c.cadar@imperial.ac.uk>2018-09-10 15:24:17 +0100
commit83fcf1504597b2ee77276d287e70bd0ae8d201ec (patch)
treee6f7dd692a00037641f6bc189839e08bc245c689 /lib/Module
parent3d373d8b5c101e0798ea8a5e8015aa03537d02d8 (diff)
downloadklee-83fcf1504597b2ee77276d287e70bd0ae8d201ec.tar.gz
Fix generation of global constructors and destructors
Validate if the user-selected entry function exists. Do not assume it is `main`.
Diffstat (limited to 'lib/Module')
-rw-r--r--lib/Module/KModule.cpp8
1 files changed, 5 insertions, 3 deletions
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