basic instcombine support for CDS.
[oota-llvm.git] / lib / Linker / Linker.cpp
index 9606d067e0accde2335c481d6cd64d482acc2cd5..7c6cf4f3dd786c9ae17b3d6bf5604c90a0a63f6b 100644 (file)
@@ -17,7 +17,6 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/Config/config.h"
 #include "llvm/Support/system_error.h"
 using namespace llvm;
 
@@ -99,14 +98,12 @@ Linker::LoadObject(const sys::Path &FN) {
   std::string ParseErrorMessage;
   Module *Result = 0;
 
-  error_code ec;
-  std::auto_ptr<MemoryBuffer> Buffer(
-    MemoryBuffer::getFileOrSTDIN(FN.c_str(), ec));
-  if (Buffer.get())
-    Result = ParseBitcodeFile(Buffer.get(), Context, &ParseErrorMessage);
-  else
+  OwningPtr<MemoryBuffer> Buffer;
+  if (error_code ec = MemoryBuffer::getFileOrSTDIN(FN.c_str(), Buffer))
     ParseErrorMessage = "Error reading file '" + FN.str() + "'" + ": "
                       + ec.message();
+  else
+    Result = ParseBitcodeFile(Buffer.get(), Context, &ParseErrorMessage);
 
   if (Result)
     return std::auto_ptr<Module>(Result);
@@ -143,6 +140,14 @@ static inline sys::Path IsLibrary(StringRef Name,
   if (FullPath.isBitcodeFile())    // .so file containing bitcode?
     return FullPath;
 
+  // Try libX form, to make it possible to add dependency on the
+  // specific version of .so, like liblzma.so.1.0.0
+  FullPath.eraseSuffix();
+  if (FullPath.isDynamicLibrary())  // Native shared library?
+    return FullPath;
+  if (FullPath.isBitcodeFile())    // .so file containing bitcode?
+    return FullPath;
+
   // Not found .. fall through
 
   // Indicate that the library was not found in the directory.