diff options
Diffstat (limited to 'lld/lib/ReaderWriter/Native/ReaderNative.cpp')
| -rw-r--r-- | lld/lib/ReaderWriter/Native/ReaderNative.cpp | 74 |
1 files changed, 34 insertions, 40 deletions
diff --git a/lld/lib/ReaderWriter/Native/ReaderNative.cpp b/lld/lib/ReaderWriter/Native/ReaderNative.cpp index 814215fea52..36bc7fca615 100644 --- a/lld/lib/ReaderWriter/Native/ReaderNative.cpp +++ b/lld/lib/ReaderWriter/Native/ReaderNative.cpp @@ -246,11 +246,11 @@ public: /// Instantiates a File object from a native object file. Ownership /// of the MemoryBuffer is transfered to the resulting File object. - static error_code make(std::unique_ptr<llvm::MemoryBuffer> &mb, - StringRef path, - std::vector<std::unique_ptr<lld::File>> &result) { - const uint8_t* const base = - reinterpret_cast<const uint8_t*>(mb->getBufferStart()); + static error_code make( + const TargetInfo &ti, std::unique_ptr<llvm::MemoryBuffer> &mb, + StringRef path, std::vector<std::unique_ptr<lld::File> > &result) { + const uint8_t *const base = + reinterpret_cast<const uint8_t *>(mb->getBufferStart()); const NativeFileHeader* const header = reinterpret_cast<const NativeFileHeader*>(base); const NativeChunk *const chunks = @@ -264,17 +264,16 @@ public: if ( header->fileSize > fileSize ) return make_error_code(native_reader_error::file_too_short); - DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs() - << " Native File Header:" - << " fileSize=" << header->fileSize - << " chunkCount=" << header->chunkCount - << "\n"); + DEBUG_WITH_TYPE("ReaderNative", + llvm::dbgs() << " Native File Header:" << " fileSize=" + << header->fileSize << " chunkCount=" + << header->chunkCount << "\n"); // instantiate NativeFile object and add values to it as found - std::unique_ptr<File> file(new File(std::move(mb), path)); + std::unique_ptr<File> file(new File(ti, std::move(mb), path)); // process each chunk - for(uint32_t i=0; i < header->chunkCount; ++i) { + for (uint32_t i = 0; i < header->chunkCount; ++i) { error_code ec; const NativeChunk* chunk = &chunks[i]; // sanity check chunk is within file @@ -373,9 +372,10 @@ public: virtual const atom_collection<SharedLibraryAtom>& sharedLibrary() const { return _sharedLibraryAtoms; } - virtual const atom_collection<AbsoluteAtom>& absolute() const { - return _absoluteAtoms; + virtual const atom_collection<AbsoluteAtom> &absolute() const { + return _absoluteAtoms; } + virtual const TargetInfo &getTargetInfo() const { return _targetInfo; } private: friend class NativeDefinedAtomV1; @@ -728,25 +728,18 @@ private: assert(index > _targetsTableCount); _targetsTable[index] = newAtom; } - - // private constructor, only called by make() - File(std::unique_ptr<llvm::MemoryBuffer> mb, StringRef path) : - lld::File(path), - _buffer(std::move(mb)), // Reader now takes ownership of buffer - _header(nullptr), - _targetsTable(nullptr), - _targetsTableCount(0), - _strings(nullptr), - _stringsMaxOffset(0), - _addends(nullptr), - _addendsMaxIndex(0), - _contentStart(nullptr), - _contentEnd(nullptr) - { - _header = reinterpret_cast<const NativeFileHeader*> - (_buffer->getBufferStart()); + File(const TargetInfo &ti, std::unique_ptr<llvm::MemoryBuffer> mb, + StringRef path) + : lld::File(path), + _buffer(std::move(mb)), // Reader now takes ownership of buffer + _header(nullptr), _targetsTable(nullptr), _targetsTableCount(0), + _strings(nullptr), _stringsMaxOffset(0), _addends(nullptr), + _addendsMaxIndex(0), _contentStart(nullptr), _contentEnd(nullptr), + _targetInfo(ti) { + _header = + reinterpret_cast<const NativeFileHeader *>(_buffer->getBufferStart()); } template <typename T> @@ -805,13 +798,13 @@ private: const char* _strings; uint32_t _stringsMaxOffset; const Reference::Addend* _addends; - uint32_t _addendsMaxIndex; - const uint8_t* _contentStart; - const uint8_t* _contentEnd; + uint32_t _addendsMaxIndex; + const uint8_t *_contentStart; + const uint8_t *_contentEnd; + const TargetInfo &_targetInfo; }; - -inline const class lld::File& NativeDefinedAtomV1::file() const { +inline const class lld::File &NativeDefinedAtomV1::file() const { return *_file; } @@ -929,10 +922,11 @@ class Reader : public lld::Reader { public: Reader(const TargetInfo &ti) : lld::Reader(ti) {} - - virtual error_code parseFile(std::unique_ptr<MemoryBuffer> mb, - std::vector<std::unique_ptr<lld::File>> &result) { - return File::make(mb, mb->getBufferIdentifier(), result); + + virtual error_code parseFile( + std::unique_ptr<MemoryBuffer> mb, + std::vector<std::unique_ptr<lld::File> > &result) { + return File::make(_targetInfo, mb, mb->getBufferIdentifier(), result); } }; } // end namespace native |

