Skip to content

Commit

Permalink
Don't fail klee on alias with uclibc
Browse files Browse the repository at this point in the history
  • Loading branch information
ladisgin authored and misonijnik committed Apr 12, 2023
1 parent 32532cc commit 1b0c2fe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/Module/ModuleUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ klee::linkModules(std::vector<std::unique_ptr<llvm::Module>> &modules,
for (auto &module : modules) {
if (!module || !containsUsedSymbols(module.get()))
continue;

if (!linkTwoModules(composite.get(), std::move(module), errorMsg)) {
// Linking failed
errorMsg = "Linking module containing '__attribute__((used))'"
Expand Down
10 changes: 8 additions & 2 deletions lib/Runner/run_klee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,9 @@ preparePOSIX(std::vector<std::unique_ptr<llvm::Module>> &loadedModules,
break;
}

if (!mainFn)
if (!mainFn) {
klee_error("Entry function '%s' not found in module.", EntryPoint.c_str());
}
mainFn->setName("__klee_posix_wrapped_main");

// Add a definition of the entry function if needed. This is the case if we
Expand Down Expand Up @@ -1091,7 +1092,12 @@ createLibCWrapper(std::vector<std::unique_ptr<llvm::Module>> &modules,
// argv), since it does not explicitly take an envp argument.
auto &ctx = modules[0]->getContext();
Function *userMainFn = modules[0]->getFunction(intendedFunction);
assert(userMainFn && "unable to get user main");

if (!userMainFn) {
klee_error("Entry function '%s' not found in module.",
intendedFunction.str().c_str());
}

// Rename entry point using a prefix
userMainFn->setName("__user_" + intendedFunction);

Expand Down
9 changes: 9 additions & 0 deletions test/Runtime/Uclibc/FunctionNotFound.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %clang %s -emit-llvm %O0opt -c -o %t1.bc
// RUN: rm -rf %t.klee-out
// RUN: not %klee --entry-point=main --output-dir=%t.klee-out --libc=uclibc --exit-on-error %t1.bc 2>&1 | FileCheck %s

int foo(int argc, char *argv[]) {
return 0;
}

// CHECK: KLEE: ERROR: Entry function 'main' not found in module.

0 comments on commit 1b0c2fe

Please sign in to comment.