diff options
| -rw-r--r-- | lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp index 40fa4e0faf2..8f4372d5110 100644 --- a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp @@ -120,6 +120,8 @@ private: const coff_section *section, const vector<COFFDefinedFileAtom *> &atoms); + error_code getSectionContents(StringRef sectionName, + ArrayRef<uint8_t> &result); error_code getReferenceArch(Reference::KindArch &result); error_code addRelocationReferenceToAtoms(); error_code findSection(StringRef name, const coff_section *&result); @@ -275,15 +277,11 @@ FileCOFF::FileCOFF(std::unique_ptr<MemoryBuffer> mb, error_code &ec) bin.take(); // Read .drectve section if exists. - const coff_section *section = nullptr; - if ((ec = findSection(".drectve", section))) + ArrayRef<uint8_t> contents; + if ((ec = getSectionContents(".drectve", contents))) return; - if (section != nullptr) { - ArrayRef<uint8_t> contents; - if ((ec = _obj->getSectionContents(section, contents))) - return; + if (!contents.empty()) _directives = ArrayRefToString(contents); - } } error_code FileCOFF::parse(StringMap &altNames) { @@ -737,6 +735,19 @@ FileCOFF::addRelocationReference(const coff_relocation *rel, return error_code::success(); } +// Read section contents. +error_code FileCOFF::getSectionContents(StringRef sectionName, + ArrayRef<uint8_t> &result) { + const coff_section *section = nullptr; + if (error_code ec = findSection(sectionName, section)) + return ec; + if (!section) + return error_code::success(); + if (error_code ec = _obj->getSectionContents(section, result)) + return ec; + return error_code::success(); +} + /// Returns the target machine type of the current object file. error_code FileCOFF::getReferenceArch(Reference::KindArch &result) { const llvm::object::coff_file_header *header = nullptr; |

