[lld] r226963 - [MachO] Remove dependency on lldDriver

Greg Fitzgerald garious at gmail.com
Fri Jan 23 15:26:13 PST 2015


Author: garious
Date: Fri Jan 23 17:26:13 2015
New Revision: 226963

URL: http://llvm.org/viewvc/llvm-project?rev=226963&view=rev
Log:
[MachO] Remove dependency on lldDriver

Moved getMemoryBuffer from DarwnLdDriver to MachOLinkingContext.
lldMachO shared library target now builds.

Differential Review: http://reviews.llvm.org/D7155

Modified:
    lld/trunk/include/lld/Driver/Driver.h
    lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h
    lld/trunk/lib/Driver/DarwinLdDriver.cpp
    lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp

Modified: lld/trunk/include/lld/Driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/Driver.h?rev=226963&r1=226962&r2=226963&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/Driver.h (original)
+++ lld/trunk/include/lld/Driver/Driver.h Fri Jan 23 17:26:13 2015
@@ -101,11 +101,6 @@ public:
   static bool parse(int argc, const char *argv[], MachOLinkingContext &info,
                     raw_ostream &diagnostics = llvm::errs());
 
-  // Reads a file from disk to memory. Returns only a needed chunk
-  // if a fat binary.
-  static ErrorOr<std::unique_ptr<MemoryBuffer>>
-  getMemoryBuffer(MachOLinkingContext &ctx, StringRef path);
-
 private:
   DarwinLdDriver() LLVM_DELETED_FUNCTION;
 };

Modified: lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h?rev=226963&r1=226962&r2=226963&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h Fri Jan 23 17:26:13 2015
@@ -253,6 +253,10 @@ public:
   /// Used to keep track of direct and indirect dylibs.
   void registerDylib(mach_o::MachODylibFile *dylib, bool upward) const;
 
+  // Reads a file from disk to memory. Returns only a needed chunk
+  // if a fat binary.
+  ErrorOr<std::unique_ptr<MemoryBuffer>> getMemoryBuffer(StringRef path);
+
   /// Used to find indirect dylibs. Instantiates a MachODylibFile if one
   /// has not already been made for the requested dylib.  Uses -L and -F
   /// search paths to allow indirect dylibs to be overridden.

Modified: lld/trunk/lib/Driver/DarwinLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdDriver.cpp?rev=226963&r1=226962&r2=226963&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/DarwinLdDriver.cpp Fri Jan 23 17:26:13 2015
@@ -77,8 +77,7 @@ loadFile(MachOLinkingContext &ctx, Strin
   if (ctx.logInputFiles())
     diag << path << "\n";
 
-  ErrorOr<std::unique_ptr<MemoryBuffer>> mbOrErr =
-    DarwinLdDriver::getMemoryBuffer(ctx, path);
+  ErrorOr<std::unique_ptr<MemoryBuffer>> mbOrErr = ctx.getMemoryBuffer(path);
   if (std::error_code ec = mbOrErr.getError())
     return makeErrorFile(path, ec);
   std::vector<std::unique_ptr<File>> files;
@@ -264,25 +263,6 @@ static bool parseNumberBase16(StringRef
 
 namespace lld {
 
-ErrorOr<std::unique_ptr<MemoryBuffer>>
-DarwinLdDriver::getMemoryBuffer(MachOLinkingContext &ctx, StringRef path) {
-  ctx.addInputFileDependency(path);
-
-  ErrorOr<std::unique_ptr<MemoryBuffer>> mbOrErr =
-    MemoryBuffer::getFileOrSTDIN(path);
-  if (std::error_code ec = mbOrErr.getError())
-    return ec;
-  std::unique_ptr<MemoryBuffer> mb = std::move(mbOrErr.get());
-
-  // If buffer contains a fat file, find required arch in fat buffer
-  // and switch buffer to point to just that required slice.
-  uint32_t offset;
-  uint32_t size;
-  if (ctx.sliceFromFatFile(*mb, offset, size))
-    return MemoryBuffer::getFileSlice(path, size, offset);
-  return std::move(mb);
-}
-
 bool DarwinLdDriver::linkMachO(int argc, const char *argv[],
                                raw_ostream &diagnostics) {
   MachOLinkingContext ctx;

Modified: lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=226963&r1=226962&r2=226963&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp Fri Jan 23 17:26:13 2015
@@ -605,9 +605,27 @@ Writer &MachOLinkingContext::writer() co
   return *_writer;
 }
 
-MachODylibFile* MachOLinkingContext::loadIndirectDylib(StringRef path) {
+ErrorOr<std::unique_ptr<MemoryBuffer>>
+MachOLinkingContext::getMemoryBuffer(StringRef path) {
+  addInputFileDependency(path);
+
   ErrorOr<std::unique_ptr<MemoryBuffer>> mbOrErr =
-    DarwinLdDriver::getMemoryBuffer(*this, path);
+    MemoryBuffer::getFileOrSTDIN(path);
+  if (std::error_code ec = mbOrErr.getError())
+    return ec;
+  std::unique_ptr<MemoryBuffer> mb = std::move(mbOrErr.get());
+
+  // If buffer contains a fat file, find required arch in fat buffer
+  // and switch buffer to point to just that required slice.
+  uint32_t offset;
+  uint32_t size;
+  if (sliceFromFatFile(*mb, offset, size))
+    return MemoryBuffer::getFileSlice(path, size, offset);
+  return std::move(mb);
+}
+
+MachODylibFile* MachOLinkingContext::loadIndirectDylib(StringRef path) {
+  ErrorOr<std::unique_ptr<MemoryBuffer>> mbOrErr = getMemoryBuffer(path);
   if (mbOrErr.getError())
     return nullptr;
 





More information about the llvm-commits mailing list