diff options
Diffstat (limited to 'lld/lib/ReaderWriter/Native')
-rw-r--r-- | lld/lib/ReaderWriter/Native/NativeFileFormat.h | 10 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/Native/ReaderNative.cpp | 66 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/Native/WriterNative.cpp | 8 |
3 files changed, 52 insertions, 32 deletions
diff --git a/lld/lib/ReaderWriter/Native/NativeFileFormat.h b/lld/lib/ReaderWriter/Native/NativeFileFormat.h index ebc26ea780b..0f58e0ab8b1 100644 --- a/lld/lib/ReaderWriter/Native/NativeFileFormat.h +++ b/lld/lib/ReaderWriter/Native/NativeFileFormat.h @@ -202,8 +202,10 @@ struct NativeReferenceIvarsV1 { enum { noTarget = UINT16_MAX }; - uint16_t offsetInAtom; - int16_t kind; + uint32_t offsetInAtom; + uint16_t kindValue; + uint8_t kindNamespace; + uint8_t kindArch; uint16_t targetIndex; uint16_t addendIndex; }; @@ -218,7 +220,9 @@ struct NativeReferenceIvarsV2 { }; uint64_t offsetInAtom; int64_t addend; - int32_t kind; + uint16_t kindValue; + uint8_t kindNamespace; + uint8_t kindArch; uint32_t targetIndex; }; diff --git a/lld/lib/ReaderWriter/Native/ReaderNative.cpp b/lld/lib/ReaderWriter/Native/ReaderNative.cpp index 7f6f4616c23..d7fc44f5d16 100644 --- a/lld/lib/ReaderWriter/Native/ReaderNative.cpp +++ b/lld/lib/ReaderWriter/Native/ReaderNative.cpp @@ -214,8 +214,9 @@ private: class NativeReferenceV1 : public Reference { public: NativeReferenceV1(const File& f, const NativeReferenceIvarsV1* ivarData) - : _file(&f), _ivarData(ivarData) { - setKind(ivarData->kind); + : Reference((KindNamespace)ivarData->kindNamespace, + (KindArch)ivarData->kindArch, ivarData->kindValue), + _file(&f), _ivarData(ivarData) { } virtual uint64_t offsetInAtom() const { @@ -240,8 +241,9 @@ private: class NativeReferenceV2 : public Reference { public: NativeReferenceV2(const File& f, const NativeReferenceIvarsV2* ivarData) - : _file(&f), _ivarData(ivarData) { - setKind(ivarData->kind); + : Reference((KindNamespace)ivarData->kindNamespace, + (KindArch)ivarData->kindArch, ivarData->kindValue), + _file(&f), _ivarData(ivarData) { } virtual uint64_t offsetInAtom() const { @@ -267,8 +269,7 @@ public: /// Instantiates a File object from a native object file. Ownership /// of the MemoryBuffer is transferred to the resulting File object. - static error_code make(const LinkingContext &context, - std::unique_ptr<MemoryBuffer> mb, + static error_code make(std::unique_ptr<MemoryBuffer> mb, std::vector<std::unique_ptr<lld::File> > &result) { const uint8_t *const base = reinterpret_cast<const uint8_t *>(mb->getBufferStart()); @@ -293,7 +294,7 @@ public: << header->chunkCount << "\n"); // instantiate NativeFile object and add values to it as found - std::unique_ptr<File> file(new File(context, std::move(mb), path)); + std::unique_ptr<File> file(new File(std::move(mb), path)); // process each chunk for (uint32_t i = 0; i < header->chunkCount; ++i) { @@ -360,7 +361,7 @@ public: for (const Reference *r : *a) { llvm::dbgs() << " offset=" << llvm::format("0x%03X", r->offsetInAtom()) - << ", kind=" << r->kind() + << ", kind=" << r->kindValue() << ", target=" << r->target() << "\n"; } } @@ -397,7 +398,6 @@ public: virtual const atom_collection<AbsoluteAtom> &absolute() const { return _absoluteAtoms; } - virtual const LinkingContext &getLinkingContext() const { return _context; } private: friend NativeDefinedAtomV1; @@ -792,14 +792,12 @@ private: } // private constructor, only called by make() - File(const LinkingContext &context, std::unique_ptr<MemoryBuffer> mb, - StringRef path) + File(std::unique_ptr<MemoryBuffer> mb, StringRef path) : lld::File(path, kindObject), _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), - _context(context) { + _addendsMaxIndex(0), _contentStart(nullptr), _contentEnd(nullptr) { _header = reinterpret_cast<const NativeFileHeader *>(_buffer->getBufferStart()); } @@ -845,7 +843,7 @@ private: }; - std::unique_ptr<MemoryBuffer> _buffer; + std::unique_ptr<MemoryBuffer> _buffer; const NativeFileHeader* _header; AtomArray<DefinedAtom> _definedAtoms; AtomArray<UndefinedAtom> _undefinedAtoms; @@ -862,10 +860,9 @@ private: const char* _strings; uint32_t _stringsMaxOffset; const Reference::Addend* _addends; - uint32_t _addendsMaxIndex; - const uint8_t *_contentStart; - const uint8_t *_contentEnd; - const LinkingContext &_context; + uint32_t _addendsMaxIndex; + const uint8_t *_contentStart; + const uint8_t *_contentEnd; }; inline const lld::File &NativeDefinedAtomV1::file() const { @@ -1002,19 +999,34 @@ inline void NativeReferenceV2::setAddend(Addend a) { llvm_unreachable("setAddend() not supported"); } -class Reader : public lld::Reader { -public: - Reader(const LinkingContext &context) : lld::Reader(context) {} +} // end namespace native + +namespace { + +class NativeReader : public Reader { +public: + virtual bool canParse(file_magic magic, StringRef, + const MemoryBuffer& mb) const { + const NativeFileHeader *const header = + reinterpret_cast<const NativeFileHeader *>(mb.getBufferStart()); + return (memcmp(header->magic, NATIVE_FILE_HEADER_MAGIC, + sizeof(header->magic)) == 0); + } + virtual error_code - parseFile(std::unique_ptr<MemoryBuffer> &mb, - std::vector<std::unique_ptr<lld::File> > &result) const { - return File::make(_context, std::move(mb), result); + parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &, + std::vector<std::unique_ptr<File>> &result) const { + return lld::native::File::make(std::move(mb), result); + return error_code::success(); } }; -} // end namespace native -std::unique_ptr<Reader> createReaderNative(const LinkingContext &context) { - return std::unique_ptr<Reader>(new lld::native::Reader(context)); + } + +void Registry::addSupportNativeObjects() { + add(std::unique_ptr<Reader>(new NativeReader())); +} + } // end namespace lld diff --git a/lld/lib/ReaderWriter/Native/WriterNative.cpp b/lld/lib/ReaderWriter/Native/WriterNative.cpp index 8f93363033e..fb0e1e57bc2 100644 --- a/lld/lib/ReaderWriter/Native/WriterNative.cpp +++ b/lld/lib/ReaderWriter/Native/WriterNative.cpp @@ -155,7 +155,9 @@ private: for (const NativeReferenceIvarsV2 &v2 : _referencesV2) { NativeReferenceIvarsV1 v1; v1.offsetInAtom = v2.offsetInAtom; - v1.kind = v2.kind; + v1.kindNamespace = v2.kindNamespace; + v1.kindArch = v2.kindArch; + v1.kindValue = v2.kindValue; v1.targetIndex = (v2.targetIndex == NativeReferenceIvarsV2::noTarget) ? NativeReferenceIvarsV1::noTarget : v2.targetIndex; v1.addendIndex = this->getAddendIndex(v2.addend); @@ -431,7 +433,9 @@ private: for (const Reference *ref : atom) { NativeReferenceIvarsV2 nref; nref.offsetInAtom = ref->offsetInAtom(); - nref.kind = ref->kind(); + nref.kindNamespace = (uint8_t)ref->kindNamespace(); + nref.kindArch = (uint8_t)ref->kindArch(); + nref.kindValue = ref->kindValue(); nref.targetIndex = this->getTargetIndex(ref->target()); nref.addend = ref->addend(); _referencesV2.push_back(nref); |