summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/Native/ReaderNative.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/lib/ReaderWriter/Native/ReaderNative.cpp')
-rw-r--r--lld/lib/ReaderWriter/Native/ReaderNative.cpp71
1 files changed, 33 insertions, 38 deletions
diff --git a/lld/lib/ReaderWriter/Native/ReaderNative.cpp b/lld/lib/ReaderWriter/Native/ReaderNative.cpp
index 3c7846b1ae3..c29fc4543f2 100644
--- a/lld/lib/ReaderWriter/Native/ReaderNative.cpp
+++ b/lld/lib/ReaderWriter/Native/ReaderNative.cpp
@@ -259,14 +259,21 @@ private:
//
class File : public lld::File {
public:
+ File(std::unique_ptr<MemoryBuffer> mb)
+ : lld::File(mb->getBufferIdentifier(), kindObject),
+ _mb(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 *>(_mb->getBufferStart());
+ }
- /// Instantiates a File object from a native object file. Ownership
- /// of the MemoryBuffer is transferred to the resulting File object.
- static std::error_code make(std::unique_ptr<MemoryBuffer> mb,
- std::vector<std::unique_ptr<lld::File>> &result) {
+ /// Parses a File object from a native object file.
+ std::error_code doParse() override {
const uint8_t *const base =
- reinterpret_cast<const uint8_t *>(mb->getBufferStart());
- StringRef path(mb->getBufferIdentifier());
+ reinterpret_cast<const uint8_t *>(_mb->getBufferStart());
+ StringRef path(_mb->getBufferIdentifier());
const NativeFileHeader *const header =
reinterpret_cast<const NativeFileHeader *>(base);
const NativeChunk *const chunks =
@@ -277,7 +284,7 @@ public:
return make_error_code(NativeReaderError::unknown_file_format);
// make sure mapped file contains all needed data
- const size_t fileSize = mb->getBufferSize();
+ const size_t fileSize = _mb->getBufferSize();
if (header->fileSize > fileSize)
return make_error_code(NativeReaderError::file_too_short);
@@ -286,9 +293,6 @@ public:
<< 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));
-
// process each chunk
for (uint32_t i = 0; i < header->chunkCount; ++i) {
std::error_code ec;
@@ -301,40 +305,40 @@ public:
// process chunk, based on signature
switch ( chunk->signature ) {
case NCS_DefinedAtomsV1:
- ec = file->processDefinedAtomsV1(base, chunk);
+ ec = processDefinedAtomsV1(base, chunk);
break;
case NCS_AttributesArrayV1:
- ec = file->processAttributesV1(base, chunk);
+ ec = processAttributesV1(base, chunk);
break;
case NCS_UndefinedAtomsV1:
- ec = file->processUndefinedAtomsV1(base, chunk);
+ ec = processUndefinedAtomsV1(base, chunk);
break;
case NCS_SharedLibraryAtomsV1:
- ec = file->processSharedLibraryAtomsV1(base, chunk);
+ ec = processSharedLibraryAtomsV1(base, chunk);
break;
case NCS_AbsoluteAtomsV1:
- ec = file->processAbsoluteAtomsV1(base, chunk);
+ ec = processAbsoluteAtomsV1(base, chunk);
break;
case NCS_AbsoluteAttributesV1:
- ec = file->processAbsoluteAttributesV1(base, chunk);
+ ec = processAbsoluteAttributesV1(base, chunk);
break;
case NCS_ReferencesArrayV1:
- ec = file->processReferencesV1(base, chunk);
+ ec = processReferencesV1(base, chunk);
break;
case NCS_ReferencesArrayV2:
- ec = file->processReferencesV2(base, chunk);
+ ec = processReferencesV2(base, chunk);
break;
case NCS_TargetsTable:
- ec = file->processTargetsTable(base, chunk);
+ ec = processTargetsTable(base, chunk);
break;
case NCS_AddendsTable:
- ec = file->processAddendsTable(base, chunk);
+ ec = processAddendsTable(base, chunk);
break;
case NCS_Content:
- ec = file->processContent(base, chunk);
+ ec = processContent(base, chunk);
break;
case NCS_Strings:
- ec = file->processStrings(base, chunk);
+ ec = processStrings(base, chunk);
break;
default:
return make_error_code(NativeReaderError::unknown_chunk_type);
@@ -347,7 +351,7 @@ public:
DEBUG_WITH_TYPE("ReaderNative", {
llvm::dbgs() << " ReaderNative DefinedAtoms:\n";
- for (const DefinedAtom *a : file->defined()) {
+ for (const DefinedAtom *a : defined()) {
llvm::dbgs() << llvm::format(" 0x%09lX", a)
<< ", name=" << a->name()
<< ", size=" << a->size() << "\n";
@@ -359,12 +363,11 @@ public:
}
}
});
- result.push_back(std::move(file));
return make_error_code(NativeReaderError::success);
}
virtual ~File() {
- // _buffer is automatically deleted because of std::unique_ptr<>
+ // _mb is automatically deleted because of std::unique_ptr<>
// All other ivar pointers are pointers into the MemoryBuffer, except
// the _definedAtoms array which was allocated to contain an array
@@ -785,17 +788,6 @@ private:
_targetsTable[index] = newAtom;
}
- // private constructor, only called by make()
- 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) {
- _header =
- reinterpret_cast<const NativeFileHeader *>(_buffer->getBufferStart());
- }
-
template <typename T>
class AtomArray : public File::atom_collection<T> {
public:
@@ -836,7 +828,7 @@ private:
uint32_t elementCount;
};
- std::unique_ptr<MemoryBuffer> _buffer;
+ std::unique_ptr<MemoryBuffer> _mb;
const NativeFileHeader* _header;
AtomArray<DefinedAtom> _definedAtoms;
AtomArray<UndefinedAtom> _undefinedAtoms;
@@ -1009,9 +1001,12 @@ public:
virtual std::error_code
parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
std::vector<std::unique_ptr<File>> &result) const override {
- return lld::native::File::make(std::move(mb), result);
+ auto *file = new lld::native::File(std::move(mb));
+ result.push_back(std::unique_ptr<File>(file));
+ return std::error_code();
}
};
+
}
void Registry::addSupportNativeObjects() {
OpenPOWER on IntegriCloud