about summary refs log tree commit diff homepage
path: root/tools
diff options
context:
space:
mode:
authorRiccardo Schirone <sirmy15@gmail.com>2015-07-08 10:23:46 +0200
committerRiccardo Schirone <sirmy15@gmail.com>2015-08-14 13:24:45 +0000
commitaff25c9879751fc02298069ed6c93975cfdb08c9 (patch)
tree632daee8b6176a5d65e8a99e5eb3260bc96da318 /tools
parentf33130e48366422d00a8aba2d349b2288e5bd14b (diff)
downloadklee-aff25c9879751fc02298069ed6c93975cfdb08c9.tar.gz
tools/klee: pass the entry function name as argument
Diffstat (limited to 'tools')
-rw-r--r--tools/klee/main.cpp15
1 files 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
@@ -72,6 +72,11 @@ namespace {
   InputFile(cl::desc("<input bytecode>"), cl::Positional, cl::init("-"));
 
   cl::opt<std::string>
+  EntryPoint("entry-point",
+               cl::desc("Consider the function with the given name as the entrypoint"),
+               cl::init("main"));
+
+  cl::opt<std::string>
   RunInDir("run-in", cl::desc("Change to the given directory prior to executing"));
 
   cl::opt<std::string>
@@ -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;
   }