diff options
author | Dan Liew <daniel.liew@imperial.ac.uk> | 2013-12-15 22:47:14 +0000 |
---|---|---|
committer | Dan Liew <daniel.liew@imperial.ac.uk> | 2013-12-21 23:22:46 +0000 |
commit | 8d541d5e7613bd42be0714c2654138bcc3c2c6d4 (patch) | |
tree | f1a5e9288ae86803be1a4a128193b8501c78f4a2 | |
parent | 492de06e578a76a8d6b8311dd7c1c1c440623072 (diff) | |
download | klee-8d541d5e7613bd42be0714c2654138bcc3c2c6d4.tar.gz |
The location of KLEE's runtime libraries (apart from klee-uclibc)
are now detected at runtime. This allows the correct location to be used when klee is invoked from the build directory or from its install location (i.e. make install)
-rw-r--r-- | Makefile.common | 3 | ||||
-rw-r--r-- | tools/klee/main.cpp | 32 |
2 files changed, 33 insertions, 2 deletions
diff --git a/Makefile.common b/Makefile.common index 3550baae..21985db1 100644 --- a/Makefile.common +++ b/Makefile.common @@ -32,7 +32,8 @@ C.Flags += -std=gnu89 LD.Flags += -L$(STP_ROOT)/lib CXX.Flags += -I$(STP_ROOT)/include -CXX.Flags += -DKLEE_DIR=\"$(PROJ_OBJ_ROOT)\" +CXX.Flags += -DKLEE_DIR=\"$(PROJ_OBJ_ROOT)\" -DKLEE_INSTALL_BIN_DIR=\"$(PROJ_bindir)\" +CXX.Flags += -DKLEE_INSTALL_LIB_DIR=\"$(PROJ_libdir)\" # For STP. CXX.Flags += -DEXT_HASH_MAP diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp index 9d5a1b1d..faf53439 100644 --- a/tools/klee/main.cpp +++ b/tools/klee/main.cpp @@ -34,6 +34,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Debug.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" @@ -257,6 +258,8 @@ public: static void getOutFiles(std::string path, std::vector<std::string> &results); + + static llvm::sys::Path getRunTimeLibraryPath(const char* argv0, void *MainExecAddr); }; KleeHandler::KleeHandler(int argc, char **argv) @@ -569,6 +572,32 @@ void KleeHandler::getOutFiles(std::string path, } } + +llvm::sys::Path KleeHandler::getRunTimeLibraryPath(const char* argv0, void* MainExecAddr) +{ + llvm::sys::Path toolRoot = llvm::sys::Path::GetMainExecutable(argv0, MainExecAddr); + toolRoot.eraseComponent(); // Strip off executable so we have a directory path + + llvm::sys::Path libDir; + + if ( strcmp(toolRoot.c_str(), KLEE_INSTALL_BIN_DIR ) == 0) + { + DEBUG_WITH_TYPE("klee_runtime", llvm::dbgs() << + "Using installed KLEE library runtime: "); + libDir = llvm::sys::Path( KLEE_INSTALL_LIB_DIR ); + } + else + { + DEBUG_WITH_TYPE("klee_runtime", llvm::dbgs() << + "Using build directory KLEE library runtime :"); + libDir = llvm::sys::Path(KLEE_DIR "/" RUNTIME_CONFIGURATION "/lib"); + } + + DEBUG_WITH_TYPE("klee_runtime", llvm::dbgs() << + libDir.c_str() << "\n"); + return libDir; +} + //===----------------------------------------------------------------------===// // main Driver function // @@ -1227,7 +1256,8 @@ int main(int argc, char **argv, char **envp) { return r; } - llvm::sys::Path LibraryDir(KLEE_DIR "/" RUNTIME_CONFIGURATION "/lib"); + llvm::sys::Path LibraryDir = KleeHandler::getRunTimeLibraryPath(argv[0], + reinterpret_cast<void*>(main)); Interpreter::ModuleOptions Opts(LibraryDir.c_str(), /*Optimize=*/OptimizeModule, /*CheckDivZero=*/CheckDivZero, |