From aff25c9879751fc02298069ed6c93975cfdb08c9 Mon Sep 17 00:00:00 2001 From: Riccardo Schirone Date: Wed, 8 Jul 2015 10:23:46 +0200 Subject: tools/klee: pass the entry function name as argument --- tools/klee/main.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp index 56471e84..0a292500 100644 --- a/tools/klee/main.cpp +++ b/tools/klee/main.cpp @@ -71,6 +71,11 @@ namespace { cl::opt InputFile(cl::desc(""), cl::Positional, cl::init("-")); + cl::opt + EntryPoint("entry-point", + cl::desc("Consider the function with the given name as the entrypoint"), + cl::init("main")); + cl::opt RunInDir("run-in", cl::desc("Change to the given directory prior to executing")); @@ -647,7 +652,7 @@ static int initEnv(Module *mainModule) { oldArgv->replaceAllUsesWith(nArgv) */ - Function *mainFn = mainModule->getFunction("main"); + Function *mainFn = mainModule->getFunction(EntryPoint); if (mainFn->arg_size() < 2) { klee_error("Cannot handle ""--posix-runtime"" when main() has less than two arguments.\n"); @@ -1095,7 +1100,7 @@ static llvm::Module *linkWithUclibc(llvm::Module *mainModule, StringRef libDir) // also an implicit cooperation in that runFunctionAsMain sets up // the environment arguments to what uclibc expects (following // argv), since it does not explicitly take an envp argument. - Function *userMainFn = mainModule->getFunction("main"); + Function *userMainFn = mainModule->getFunction(EntryPoint); assert(userMainFn && "unable to get user main"); Function *uclibcMainFn = mainModule->getFunction("__uClibc_main"); assert(uclibcMainFn && "unable to get uclibc main"); @@ -1109,7 +1114,7 @@ static llvm::Module *linkWithUclibc(llvm::Module *mainModule, StringRef libDir) fArgs.push_back(ft->getParamType(2)); // argv Function *stub = Function::Create(FunctionType::get(Type::getInt32Ty(getGlobalContext()), fArgs, false), GlobalVariable::ExternalLinkage, - "main", + EntryPoint, mainModule); BasicBlock *bb = BasicBlock::Create(getGlobalContext(), "entry", stub); @@ -1300,9 +1305,9 @@ int main(int argc, char **argv, char **envp) { // Get the desired main function. klee_main initializes uClibc // locale and other data and then calls main. - Function *mainFn = mainModule->getFunction("main"); + Function *mainFn = mainModule->getFunction(EntryPoint); if (!mainFn) { - llvm::errs() << "'main' function not found in module.\n"; + llvm::errs() << "'" << EntryPoint << "' function not found in module.\n"; return -1; } -- cgit 1.4.1