From b4eb64ef6a26c361f246c4441db4a29b2c3acdb1 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Fri, 23 Jan 2015 23:26:13 +0000 Subject: [PATCH] [MachO] Remove dependency on lldDriver Moved getMemoryBuffer from DarwnLdDriver to MachOLinkingContext. lldMachO shared library target now builds. Differential Review: http://reviews.llvm.org/D7155 llvm-svn: 226963 --- lld/include/lld/Driver/Driver.h | 5 ----- lld/include/lld/ReaderWriter/MachOLinkingContext.h | 4 ++++ lld/lib/Driver/DarwinLdDriver.cpp | 22 +--------------------- lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp | 22 ++++++++++++++++++++-- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/lld/include/lld/Driver/Driver.h b/lld/include/lld/Driver/Driver.h index 7571755..627eb17 100644 --- a/lld/include/lld/Driver/Driver.h +++ b/lld/include/lld/Driver/Driver.h @@ -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> - getMemoryBuffer(MachOLinkingContext &ctx, StringRef path); - private: DarwinLdDriver() LLVM_DELETED_FUNCTION; }; diff --git a/lld/include/lld/ReaderWriter/MachOLinkingContext.h b/lld/include/lld/ReaderWriter/MachOLinkingContext.h index c5093c4..bdbd91a 100644 --- a/lld/include/lld/ReaderWriter/MachOLinkingContext.h +++ b/lld/include/lld/ReaderWriter/MachOLinkingContext.h @@ -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> 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. diff --git a/lld/lib/Driver/DarwinLdDriver.cpp b/lld/lib/Driver/DarwinLdDriver.cpp index 8831fb3..2c64aee 100644 --- a/lld/lib/Driver/DarwinLdDriver.cpp +++ b/lld/lib/Driver/DarwinLdDriver.cpp @@ -77,8 +77,7 @@ loadFile(MachOLinkingContext &ctx, StringRef path, if (ctx.logInputFiles()) diag << path << "\n"; - ErrorOr> mbOrErr = - DarwinLdDriver::getMemoryBuffer(ctx, path); + ErrorOr> mbOrErr = ctx.getMemoryBuffer(path); if (std::error_code ec = mbOrErr.getError()) return makeErrorFile(path, ec); std::vector> files; @@ -264,25 +263,6 @@ static bool parseNumberBase16(StringRef numStr, uint64_t &baseAddress) { namespace lld { -ErrorOr> -DarwinLdDriver::getMemoryBuffer(MachOLinkingContext &ctx, StringRef path) { - ctx.addInputFileDependency(path); - - ErrorOr> mbOrErr = - MemoryBuffer::getFileOrSTDIN(path); - if (std::error_code ec = mbOrErr.getError()) - return ec; - std::unique_ptr 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; diff --git a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp index 9fe1610..41da4e7 100644 --- a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp +++ b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp @@ -605,9 +605,27 @@ Writer &MachOLinkingContext::writer() const { return *_writer; } -MachODylibFile* MachOLinkingContext::loadIndirectDylib(StringRef path) { +ErrorOr> +MachOLinkingContext::getMemoryBuffer(StringRef path) { + addInputFileDependency(path); + ErrorOr> mbOrErr = - DarwinLdDriver::getMemoryBuffer(*this, path); + MemoryBuffer::getFileOrSTDIN(path); + if (std::error_code ec = mbOrErr.getError()) + return ec; + std::unique_ptr 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> mbOrErr = getMemoryBuffer(path); if (mbOrErr.getError()) return nullptr; -- 2.7.4