diff options
author | Martin Nowack <m.nowack@imperial.ac.uk> | 2018-09-06 11:29:06 +0100 |
---|---|---|
committer | Cristian Cadar <c.cadar@imperial.ac.uk> | 2018-09-10 15:24:17 +0100 |
commit | 83fcf1504597b2ee77276d287e70bd0ae8d201ec (patch) | |
tree | e6f7dd692a00037641f6bc189839e08bc245c689 /lib | |
parent | 3d373d8b5c101e0798ea8a5e8015aa03537d02d8 (diff) | |
download | klee-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')
-rw-r--r-- | lib/Module/KModule.cpp | 8 |
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 |