about summary refs log tree commit diff homepage
path: root/lib/Module/ModuleUtil.cpp
diff options
context:
space:
mode:
authorMartin Nowack <martin.nowack@gmail.com>2013-08-13 12:22:36 +0200
committerMartin Nowack <martin.nowack@gmail.com>2013-08-27 23:16:18 +0200
commitb1b96a784632f71928220117624a2c07ab3ca9e6 (patch)
tree8b47a50e639521fee563d276579f60e8512f048f /lib/Module/ModuleUtil.cpp
parentc4147c2ad9ba1e74642e1a3de31be8f4446cc7f3 (diff)
downloadklee-b1b96a784632f71928220117624a2c07ab3ca9e6.tar.gz
Port to LLVM 3.3
Major changes are:
- Switching to llvm-link to build archive files
- Use GetMallocUsage instead of GetTotalMemoryUsage (be aware of bug in
  LLVM 3.3 http://llvm.org/bugs/show_bug.cgi?id=16847)
- intrinsic library functions like memcpy/mov/set use weak linkage to be
  replaced by e.g. uclibc functions
- rewrote linking with library
- enhanced MemoryLimit test case to check if mallocs were successful
Diffstat (limited to 'lib/Module/ModuleUtil.cpp')
-rw-r--r--lib/Module/ModuleUtil.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp
index 029540ae..617a91ca 100644
--- a/lib/Module/ModuleUtil.cpp
+++ b/lib/Module/ModuleUtil.cpp
@@ -10,11 +10,22 @@
 #include "klee/Internal/Support/ModuleUtil.h"
 #include "klee/Config/Version.h"
 
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
+#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/DataStream.h"
+#else
 #include "llvm/Function.h"
 #include "llvm/Instructions.h"
 #include "llvm/IntrinsicInst.h"
-#include "llvm/Linker.h"
 #include "llvm/Module.h"
+#endif
+
+#include "llvm/Linker.h"
 #if LLVM_VERSION_CODE < LLVM_VERSION(2, 8)
 #include "llvm/Assembly/AsmAnnotationWriter.h"
 #else
@@ -42,6 +53,36 @@ using namespace klee;
 
 Module *klee::linkWithLibrary(Module *module, 
                               const std::string &libraryName) {
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
+  Linker linker(module);
+  std::string errorMessage;
+
+  DataStreamer * streamer = getDataFileStreamer(libraryName, &errorMessage);
+
+  if (!streamer)
+    fprintf(stderr, "Error Loading file: %s\n", errorMessage.c_str());
+  assert(streamer);
+  
+  OwningPtr<Module> library_module;
+  library_module.reset(getStreamedBitcodeModule(libraryName, streamer, getGlobalContext(), &errorMessage));
+  if (library_module.get() != 0
+	  && library_module->MaterializeAllPermanently(&errorMessage)) {
+	  library_module.reset();
+  }
+
+  if (library_module.get() == 0) {
+	  errs() << errorMessage << " for " << libraryName << "\n";
+	  assert(library_module.get());
+  }
+  if (linker.linkInModule(library_module.get(), &errorMessage)){
+	  fprintf(stderr, "Error in Linking %s; Existing module: %s, library to be linked in %s\n", errorMessage.c_str(),
+	      module->getModuleIdentifier().c_str(), libraryName.c_str());
+	  assert(0 && "linking in library failed!");
+  }
+
+  return linker.getModule();
+
+#else
   Linker linker("klee", module, false);
 
   llvm::sys::Path libraryPath(libraryName);
@@ -52,6 +93,7 @@ Module *klee::linkWithLibrary(Module *module,
   }
     
   return linker.releaseModule();
+#endif
 }
 
 Function *klee::getDirectCallTarget(CallSite cs) {