diff options
Diffstat (limited to 'lld/lib/ReaderWriter')
20 files changed, 282 insertions, 279 deletions
diff --git a/lld/lib/ReaderWriter/ELF/DynamicFile.h b/lld/lib/ReaderWriter/ELF/DynamicFile.h index 3c24f7dc672..fefba30b9ea 100644 --- a/lld/lib/ReaderWriter/ELF/DynamicFile.h +++ b/lld/lib/ReaderWriter/ELF/DynamicFile.h @@ -85,7 +85,7 @@ DynamicFile<ELFT>::create(std::unique_ptr<llvm::MemoryBuffer> mb, bool useShlibUndefines) { std::unique_ptr<DynamicFile> file(new DynamicFile(mb->getBufferIdentifier())); - error_code ec; + std::error_code ec; file->_objFile.reset(new llvm::object::ELFFile<ELFT>(mb.release(), ec)); if (ec) diff --git a/lld/lib/ReaderWriter/ELF/ELFFile.h b/lld/lib/ReaderWriter/ELF/ELFFile.h index 65cc8944dac..48c58d23a80 100644 --- a/lld/lib/ReaderWriter/ELF/ELFFile.h +++ b/lld/lib/ReaderWriter/ELF/ELFFile.h @@ -129,19 +129,19 @@ public: /// \brief Read input sections and populate necessary data structures /// to read them later and create atoms - virtual error_code createAtomizableSections(); + virtual std::error_code createAtomizableSections(); /// \brief Create mergeable atoms from sections that have the merge attribute /// set - virtual error_code createMergeableAtoms(); + virtual std::error_code createMergeableAtoms(); /// \brief Add the symbols that the sections contain. The symbols will be /// converted to atoms for /// Undefined symbols, absolute symbols - virtual error_code createSymbolsFromAtomizableSections(); + virtual std::error_code createSymbolsFromAtomizableSections(); /// \brief Create individual atoms - virtual error_code createAtoms(); + virtual std::error_code createAtoms(); const atom_collection<DefinedAtom> &defined() const override { return _definedAtoms; @@ -410,7 +410,7 @@ public: template <class ELFT> ErrorOr<std::unique_ptr<ELFFile<ELFT>>> ELFFile<ELFT>::create(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings) { - error_code ec; + std::error_code ec; std::unique_ptr<ELFFile<ELFT>> file( new ELFFile<ELFT>(mb->getBufferIdentifier(), atomizeStrings)); @@ -459,7 +459,8 @@ template <class ELFT> Reference::KindArch ELFFile<ELFT>::kindArch() { llvm_unreachable("unsupported e_machine value"); } -template <class ELFT> error_code ELFFile<ELFT>::createAtomizableSections() { +template <class ELFT> +std::error_code ELFFile<ELFT>::createAtomizableSections() { // Handle: SHT_REL and SHT_RELA sections: // Increment over the sections, when REL/RELA section types are found add // the contents to the RelocationReferences map. @@ -484,7 +485,7 @@ template <class ELFT> error_code ELFFile<ELFT>::createAtomizableSections() { auto sHdr = _objFile->getSection(section.sh_info); auto sectionName = _objFile->getSectionName(sHdr); - if (error_code ec = sectionName.getError()) + if (std::error_code ec = sectionName.getError()) return ec; auto rai(_objFile->begin_rela(§ion)); @@ -498,7 +499,7 @@ template <class ELFT> error_code ELFFile<ELFT>::createAtomizableSections() { auto sHdr = _objFile->getSection(section.sh_info); auto sectionName = _objFile->getSectionName(sHdr); - if (error_code ec = sectionName.getError()) + if (std::error_code ec = sectionName.getError()) return ec; auto ri(_objFile->begin_rel(§ion)); @@ -509,10 +510,10 @@ template <class ELFT> error_code ELFFile<ELFT>::createAtomizableSections() { } } _references.reserve(totalRelocs); - return error_code(); + return std::error_code(); } -template <class ELFT> error_code ELFFile<ELFT>::createMergeableAtoms() { +template <class ELFT> std::error_code ELFFile<ELFT>::createMergeableAtoms() { // Divide the section that contains mergeable strings into tokens // TODO // a) add resolver support to recognize multibyte chars @@ -520,11 +521,11 @@ template <class ELFT> error_code ELFFile<ELFT>::createMergeableAtoms() { std::vector<MergeString *> tokens; for (const Elf_Shdr *msi : _mergeStringSections) { auto sectionName = getSectionName(msi); - if (error_code ec = sectionName.getError()) + if (std::error_code ec = sectionName.getError()) return ec; auto sectionContents = getSectionContents(msi); - if (error_code ec = sectionContents.getError()) + if (std::error_code ec = sectionContents.getError()) return ec; StringRef secCont(reinterpret_cast<const char *>(sectionContents->begin()), @@ -550,11 +551,11 @@ template <class ELFT> error_code ELFFile<ELFT>::createMergeableAtoms() { _definedAtoms._atoms.push_back(*mergeAtom); _mergeAtoms.push_back(*mergeAtom); } - return error_code(); + return std::error_code(); } template <class ELFT> -error_code ELFFile<ELFT>::createSymbolsFromAtomizableSections() { +std::error_code ELFFile<ELFT>::createSymbolsFromAtomizableSections() { // Increment over all the symbols collecting atoms and symbol names for // later use. auto SymI = _objFile->begin_symbols(), SymE = _objFile->end_symbols(); @@ -567,7 +568,7 @@ error_code ELFFile<ELFT>::createSymbolsFromAtomizableSections() { const Elf_Shdr *section = _objFile->getSection(&*SymI); auto symbolName = _objFile->getSymbolName(SymI); - if (error_code ec = symbolName.getError()) + if (std::error_code ec = symbolName.getError()) return ec; if (isAbsoluteSymbol(&*SymI)) { @@ -594,10 +595,10 @@ error_code ELFFile<ELFT>::createSymbolsFromAtomizableSections() { } } - return error_code(); + return std::error_code(); } -template <class ELFT> error_code ELFFile<ELFT>::createAtoms() { +template <class ELFT> std::error_code ELFFile<ELFT>::createAtoms() { for (auto &i : _sectionSymbols) { const Elf_Shdr *section = i.first; @@ -613,11 +614,11 @@ template <class ELFT> error_code ELFFile<ELFT>::createAtoms() { Elf_Sym_Iter B) { return A->st_value < B->st_value; }); ErrorOr<StringRef> sectionName = this->getSectionName(section); - if (error_code ec = sectionName.getError()) + if (std::error_code ec = sectionName.getError()) return ec; auto sectionContents = getSectionContents(section); - if (error_code ec = sectionContents.getError()) + if (std::error_code ec = sectionContents.getError()) return ec; if (handleSectionWithNoSymbols(section, symbols)) { @@ -637,7 +638,7 @@ template <class ELFT> error_code ELFFile<ELFT>::createAtoms() { StringRef symbolName = ""; if (symbol->getType() != llvm::ELF::STT_SECTION) { auto symName = _objFile->getSymbolName(symbol); - if (error_code ec = symName.getError()) + if (std::error_code ec = symName.getError()) return ec; symbolName = *symName; } @@ -736,7 +737,7 @@ template <class ELFT> error_code ELFFile<ELFT>::createAtoms() { } updateReferences(); - return error_code(); + return std::error_code(); } template <class ELFT> diff --git a/lld/lib/ReaderWriter/ELF/ELFReader.h b/lld/lib/ReaderWriter/ELF/ELFReader.h index 932649e14bd..d288b66d1bd 100644 --- a/lld/lib/ReaderWriter/ELF/ELFReader.h +++ b/lld/lib/ReaderWriter/ELF/ELFReader.h @@ -48,7 +48,7 @@ public: return (magic == llvm::sys::fs::file_magic::elf_relocatable); } - error_code + std::error_code parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &, std::vector<std::unique_ptr<File>> &result) const override { std::size_t maxAlignment = @@ -56,10 +56,10 @@ public: auto f = createELF<ELFFileCreateELFTraits>( llvm::object::getElfArchType(&*mb), maxAlignment, std::move(mb), _atomizeStrings); - if (error_code ec = f.getError()) + if (std::error_code ec = f.getError()) return ec; result.push_back(std::move(*f)); - return error_code(); + return std::error_code(); } protected: @@ -75,7 +75,7 @@ public: return (magic == llvm::sys::fs::file_magic::elf_shared_object); } - error_code + std::error_code parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &, std::vector<std::unique_ptr<File>> &result) const override { std::size_t maxAlignment = @@ -83,10 +83,10 @@ public: auto f = createELF<DynamicFileCreateELFTraits>( llvm::object::getElfArchType(&*mb), maxAlignment, std::move(mb), _useUndefines); - if (error_code ec = f.getError()) + if (std::error_code ec = f.getError()) return ec; result.push_back(std::move(*f)); - return error_code(); + return std::error_code(); } protected: diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h index 9d1c5888f8f..0230267181a 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h @@ -68,12 +68,12 @@ public: : ELFFile<ELFT>(name, atomizeStrings) {} MipsELFFile(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings, - error_code &ec) + std::error_code &ec) : ELFFile<ELFT>(std::move(mb), atomizeStrings, ec) {} static ErrorOr<std::unique_ptr<MipsELFFile>> create(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings) { - error_code ec; + std::error_code ec; std::unique_ptr<MipsELFFile<ELFT>> file( new MipsELFFile<ELFT>(mb->getBufferIdentifier(), atomizeStrings)); @@ -142,13 +142,13 @@ private: referenceStart, referenceEnd, referenceList); } - error_code readAuxData() { + std::error_code readAuxData() { typedef llvm::object::Elf_RegInfo<ELFT> Elf_RegInfo; for (const Elf_Shdr §ion : this->_objFile->sections()) { if (!_gp0.hasValue() && section.sh_type == llvm::ELF::SHT_MIPS_REGINFO) { auto contents = this->getSectionContents(§ion); - if (error_code ec = contents.getError()) + if (std::error_code ec = contents.getError()) return ec; ArrayRef<uint8_t> raw = contents.get(); @@ -162,7 +162,7 @@ private: _dtpOff = section.sh_addr + DTP_OFFSET; } } - return error_code(); + return std::error_code(); } void createRelocationReferences(const Elf_Sym &symbol, diff --git a/lld/lib/ReaderWriter/ELF/TargetHandler.h b/lld/lib/ReaderWriter/ELF/TargetHandler.h index 8f8e1f05257..a1f6be39d83 100644 --- a/lld/lib/ReaderWriter/ELF/TargetHandler.h +++ b/lld/lib/ReaderWriter/ELF/TargetHandler.h @@ -42,9 +42,9 @@ template <class ELFT> class TargetLayout; template <class ELFT> class TargetRelocationHandler { public: - virtual error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &, - const lld::AtomLayout &, - const Reference &) const = 0; + virtual std::error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &, + const lld::AtomLayout &, + const Reference &) const = 0; virtual ~TargetRelocationHandler() {} }; diff --git a/lld/lib/ReaderWriter/ELF/Writer.h b/lld/lib/ReaderWriter/ELF/Writer.h index 8f3b1e4151f..08fd5e57d45 100644 --- a/lld/lib/ReaderWriter/ELF/Writer.h +++ b/lld/lib/ReaderWriter/ELF/Writer.h @@ -27,7 +27,7 @@ public: virtual void buildChunks(const File &file) = 0; /// \brief Writes the chunks into the output file specified by path - virtual error_code writeFile(const File &file, StringRef path) = 0; + virtual std::error_code writeFile(const File &file, StringRef path) = 0; /// \brief Get the virtual address of \p atom after layout. virtual uint64_t addressOfAtom(const Atom *atom) = 0; diff --git a/lld/lib/ReaderWriter/FileArchive.cpp b/lld/lib/ReaderWriter/FileArchive.cpp index 549d4ffcccb..8563cf3fc82 100644 --- a/lld/lib/ReaderWriter/FileArchive.cpp +++ b/lld/lib/ReaderWriter/FileArchive.cpp @@ -77,14 +77,14 @@ public: virtual bool isWholeArchive() const { return _isWholeArchive; } /// \brief parse each member - error_code + std::error_code parseAllMembers(std::vector<std::unique_ptr<File>> &result) const override { for (auto mf = _archive->child_begin(), me = _archive->child_end(); mf != me; ++mf) { - if (error_code ec = instantiateMember(mf, result)) + if (std::error_code ec = instantiateMember(mf, result)) return ec; } - return error_code(); + return std::error_code(); } const atom_collection<DefinedAtom> &defined() const override { @@ -103,7 +103,7 @@ public: return _absoluteAtoms; } - error_code buildTableOfContents() { + std::error_code buildTableOfContents() { DEBUG_WITH_TYPE("FileArchive", llvm::dbgs() << "Table of contents for archive '" << _archive->getFileName() << "':\n"); @@ -111,9 +111,9 @@ public: i != e; ++i) { StringRef name; Archive::child_iterator member; - if (error_code ec = i->getName(name)) + if (std::error_code ec = i->getName(name)) return ec; - if (error_code ec = i->getMember(member)) + if (std::error_code ec = i->getMember(member)) return ec; DEBUG_WITH_TYPE( "FileArchive", @@ -121,7 +121,7 @@ public: << "'" << name << "'\n"); _symbolMemberMap[name] = member; } - return error_code(); + return std::error_code(); } /// Returns a set of all defined symbols in the archive. @@ -133,24 +133,25 @@ public: } protected: - error_code + std::error_code instantiateMember(Archive::child_iterator member, std::vector<std::unique_ptr<File>> &result) const { std::unique_ptr<MemoryBuffer> mb; - if (error_code ec = member->getMemoryBuffer(mb, true)) + if (std::error_code ec = member->getMemoryBuffer(mb, true)) return ec; if (_logLoading) llvm::outs() << mb->getBufferIdentifier() << "\n"; _registry.parseFile(mb, result); const char *memberStart = member->getBuffer().data(); _membersInstantiated.insert(memberStart); - return error_code(); + return std::error_code(); } // Parses the given memory buffer as an object file, and returns success error // code if the given symbol is a data symbol. If the symbol is not a data // symbol or does not exist, returns a failure. - error_code isDataSymbol(std::unique_ptr<MemoryBuffer> mb, StringRef symbol) const { + std::error_code isDataSymbol(std::unique_ptr<MemoryBuffer> mb, + StringRef symbol) const { auto objOrErr(ObjectFile::createObjectFile(mb.release())); if (auto ec = objOrErr.getError()) return ec; @@ -163,7 +164,7 @@ protected: for (symbol_iterator i = ibegin; i != iend; ++i) { // Get symbol name - if (error_code ec = i->getName(symbolname)) + if (std::error_code ec = i->getName(symbolname)) return ec; if (symbolname != symbol) continue; @@ -175,11 +176,11 @@ protected: continue; // Get Symbol Type - if (error_code ec = i->getType(symtype)) + if (std::error_code ec = i->getType(symtype)) return ec; if (symtype == SymbolRef::ST_Data) - return error_code(); + return std::error_code(); } return object_error::parse_failed; } @@ -209,11 +210,11 @@ public: return (magic == llvm::sys::fs::file_magic::archive); } - error_code + std::error_code parseFile(std::unique_ptr<MemoryBuffer> &mb, const Registry ®, std::vector<std::unique_ptr<File>> &result) const override { // Make Archive object which will be owned by FileArchive object. - error_code ec; + std::error_code ec; Archive *archive = new Archive(mb.get(), ec); if (ec) return ec; @@ -229,7 +230,7 @@ public: mb.release(); result.push_back(std::move(file)); - return error_code(); + return std::error_code(); } private: diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h b/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h index c2d398485ab..71cb9f08068 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h @@ -249,8 +249,7 @@ readBinary(std::unique_ptr<MemoryBuffer> &mb, const MachOLinkingContext::Arch arch); /// Takes in-memory normalized view and writes a mach-o object file. -error_code -writeBinary(const NormalizedFile &file, StringRef path); +std::error_code writeBinary(const NormalizedFile &file, StringRef path); size_t headerAndLoadCommandsSize(const NormalizedFile &file); @@ -260,9 +259,7 @@ ErrorOr<std::unique_ptr<NormalizedFile>> readYaml(std::unique_ptr<MemoryBuffer> &mb); /// Writes a yaml encoded mach-o files given an in-memory normalized view. -error_code -writeYaml(const NormalizedFile &file, raw_ostream &out); - +std::error_code writeYaml(const NormalizedFile &file, raw_ostream &out); /// Takes in-memory normalized dylib or object and parses it into lld::File ErrorOr<std::unique_ptr<lld::File>> diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp index 6d46fb36b02..5847b3dda97 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp @@ -50,10 +50,9 @@ namespace mach_o { namespace normalized { // Utility to call a lambda expression on each load command. -static error_code -forEachLoadCommand(StringRef lcRange, unsigned lcCount, bool swap, bool is64, - std::function<bool (uint32_t cmd, uint32_t size, - const char* lc)> func) { +static std::error_code forEachLoadCommand( + StringRef lcRange, unsigned lcCount, bool swap, bool is64, + std::function<bool(uint32_t cmd, uint32_t size, const char *lc)> func) { const char* p = lcRange.begin(); for (unsigned i=0; i < lcCount; ++i) { const load_command *lc = reinterpret_cast<const load_command*>(p); @@ -68,18 +67,17 @@ forEachLoadCommand(StringRef lcRange, unsigned lcCount, bool swap, bool is64, return std::make_error_code(std::errc::executable_format_error); if (func(slc->cmd, slc->cmdsize, p)) - return error_code(); + return std::error_code(); p += slc->cmdsize; } - return error_code(); + return std::error_code(); } - -static error_code -appendRelocations(Relocations &relocs, StringRef buffer, bool swap, - bool bigEndian, uint32_t reloff, uint32_t nreloc) { +static std::error_code appendRelocations(Relocations &relocs, StringRef buffer, + bool swap, bool bigEndian, + uint32_t reloff, uint32_t nreloc) { if ((reloff + nreloc*8) > buffer.size()) return std::make_error_code(std::errc::executable_format_error); const any_relocation_info* relocsArray = @@ -88,10 +86,10 @@ appendRelocations(Relocations &relocs, StringRef buffer, bool swap, for(uint32_t i=0; i < nreloc; ++i) { relocs.push_back(unpackRelocation(relocsArray[i], swap, bigEndian)); } - return error_code(); + return std::error_code(); } -static error_code +static std::error_code appendIndirectSymbols(IndirectSymbols &isyms, StringRef buffer, bool swap, bool bigEndian, uint32_t istOffset, uint32_t istCount, uint32_t startIndex, uint32_t count) { @@ -105,7 +103,7 @@ appendIndirectSymbols(IndirectSymbols &isyms, StringRef buffer, bool swap, for(uint32_t i=0; i < count; ++i) { isyms.push_back(read32(swap, indirectSymbolArray[startIndex+i])); } - return error_code(); + return std::error_code(); } @@ -206,8 +204,9 @@ readBinary(std::unique_ptr<MemoryBuffer> &mb, // Pre-scan load commands looking for indirect symbol table. uint32_t indirectSymbolTableOffset = 0; uint32_t indirectSymbolTableCount = 0; - error_code ec = forEachLoadCommand(lcRange, lcCount, swap, is64, - [&] (uint32_t cmd, uint32_t size, const char* lc) -> bool { + std::error_code ec = forEachLoadCommand(lcRange, lcCount, swap, is64, + [&](uint32_t cmd, uint32_t size, + const char *lc) -> bool { if (cmd == LC_DYSYMTAB) { const dysymtab_command *d = reinterpret_cast<const dysymtab_command*>(lc); indirectSymbolTableOffset = read32(swap, d->indirectsymoff); @@ -412,21 +411,21 @@ public: return true; } - error_code + std::error_code parseFile(std::unique_ptr<MemoryBuffer> &mb, const Registry ®istry, - std::vector<std::unique_ptr<File> > &result) const override { + std::vector<std::unique_ptr<File>> &result) const override { // Convert binary file to normalized mach-o. auto normFile = readBinary(mb, _arch); - if (error_code ec = normFile.getError()) + if (std::error_code ec = normFile.getError()) return ec; // Convert normalized mach-o to atoms. auto file = normalizedToAtoms(**normFile, mb->getBufferIdentifier(), false); - if (error_code ec = file.getError()) + if (std::error_code ec = file.getError()) return ec; result.push_back(std::move(*file)); - return error_code(); + return std::error_code(); } private: MachOLinkingContext::Arch _arch; diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp index 8e3bd4e7cc1..69f62ef0df1 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp @@ -63,13 +63,13 @@ public: /// Writes the normalized file as a binary mach-o file to the specified /// path. This does not have a stream interface because the generated /// file may need the 'x' bit set. - error_code writeBinary(StringRef path); + std::error_code writeBinary(StringRef path); private: uint32_t loadCommandsSize(uint32_t &count); void buildFileOffsets(); void writeMachHeader(); - error_code writeLoadCommands(); + std::error_code writeLoadCommands(); void writeSectionContent(); void writeRelocations(); void writeSymbolTable(); @@ -103,9 +103,8 @@ private: }; template <typename T> - error_code writeSingleSegmentLoadCommand(uint8_t *&lc); - template <typename T> - error_code writeSegmentLoadCommands(uint8_t *&lc); + std::error_code writeSingleSegmentLoadCommand(uint8_t *&lc); + template <typename T> std::error_code writeSegmentLoadCommands(uint8_t *&lc); uint32_t pointerAlign(uint32_t value); static StringRef dyldPath(); @@ -154,7 +153,7 @@ private: typedef std::map<const Section*, SectionExtraInfo> SectionMap; const NormalizedFile &_file; - error_code _ec; + std::error_code _ec; uint8_t *_buffer; const bool _is64; const bool _swap; @@ -480,10 +479,8 @@ uint32_t MachOFileLayout::indirectSymbolElementSize(const Section §) { return sect.content.size() / sect.indirectSymbols.size(); } - - template <typename T> -error_code MachOFileLayout::writeSingleSegmentLoadCommand(uint8_t *&lc) { +std::error_code MachOFileLayout::writeSingleSegmentLoadCommand(uint8_t *&lc) { typename T::command* seg = reinterpret_cast<typename T::command*>(lc); seg->cmd = T::LC; seg->cmdsize = sizeof(typename T::command) @@ -524,12 +521,11 @@ error_code MachOFileLayout::writeSingleSegmentLoadCommand(uint8_t *&lc) { ++sout; } lc = next; - return error_code(); + return std::error_code(); } - template <typename T> -error_code MachOFileLayout::writeSegmentLoadCommands(uint8_t *&lc) { +std::error_code MachOFileLayout::writeSegmentLoadCommands(uint8_t *&lc) { uint32_t indirectSymRunningIndex = 0; for (const Segment &seg : _file.segments) { // Write segment command with trailing sections. @@ -587,12 +583,11 @@ error_code MachOFileLayout::writeSegmentLoadCommands(uint8_t *&lc) { if (_swap) swapStruct(*cmd); lc = next; - return error_code(); + return std::error_code(); } - -error_code MachOFileLayout::writeLoadCommands() { - error_code ec; +std::error_code MachOFileLayout::writeLoadCommands() { + std::error_code ec; uint8_t *lc = &_buffer[_startOfLoadCommands]; if (_file.fileType == llvm::MachO::MH_OBJECT) { // Object files have one unnamed segment which holds all sections. @@ -929,8 +924,7 @@ void MachOFileLayout::writeLinkEditContent() { } } - -error_code MachOFileLayout::writeBinary(StringRef path) { +std::error_code MachOFileLayout::writeBinary(StringRef path) { // Check for pending error from constructor. if (_ec) return _ec; @@ -939,7 +933,7 @@ error_code MachOFileLayout::writeBinary(StringRef path) { unsigned flags = 0; if (_file.fileType != llvm::MachO::MH_OBJECT) flags = llvm::FileOutputBuffer::F_executable; - error_code ec; + std::error_code ec; ec = llvm::FileOutputBuffer::create(path, size(), fob, flags); if (ec) return ec; @@ -954,14 +948,13 @@ error_code MachOFileLayout::writeBinary(StringRef path) { writeLinkEditContent(); fob->commit(); - return error_code(); + return std::error_code(); } /// Takes in-memory normalized view and writes a mach-o object file. -error_code -writeBinary(const NormalizedFile &file, StringRef path) { +std::error_code writeBinary(const NormalizedFile &file, StringRef path) { MachOFileLayout layout(file); return layout.writeBinary(path); } diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp index 69e703173be..2be8d3b2db0 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp @@ -244,10 +244,10 @@ void atomFromSymbol(DefinedAtom::ContentType atomType, const Section §ion, } } -error_code processSymboledSection(DefinedAtom::ContentType atomType, - const Section §ion, - const NormalizedFile &normalizedFile, - MachOFile &file, bool copyRefs) { +std::error_code processSymboledSection(DefinedAtom::ContentType atomType, + const Section §ion, + const NormalizedFile &normalizedFile, + MachOFile &file, bool copyRefs) { // Find section's index. uint32_t sectIndex = 1; for (auto § : normalizedFile.sections) { @@ -282,7 +282,7 @@ error_code processSymboledSection(DefinedAtom::ContentType atomType, // If section has no symbols and no content, there are no atoms. if (symbols.empty() && section.content.empty()) - return error_code(); + return std::error_code(); const uint64_t firstSymbolAddr = symbols.front()->value; if (firstSymbolAddr != section.address) { @@ -304,13 +304,13 @@ error_code processSymboledSection(DefinedAtom::ContentType atomType, lastSym->desc, atomScope(lastSym->scope), section.address + section.content.size(), copyRefs); } - return error_code(); + return std::error_code(); } -error_code processSection(DefinedAtom::ContentType atomType, - const Section §ion, - const NormalizedFile &normalizedFile, - MachOFile &file, bool copyRefs) { +std::error_code processSection(DefinedAtom::ContentType atomType, + const Section §ion, + const NormalizedFile &normalizedFile, + MachOFile &file, bool copyRefs) { const bool is64 = MachOLinkingContext::is64Bit(normalizedFile.arch); const bool swap = !MachOLinkingContext::isHostEndian(normalizedFile.arch); @@ -400,7 +400,7 @@ error_code processSection(DefinedAtom::ContentType atomType, offset += size; } } - return error_code(); + return std::error_code(); } ErrorOr<std::unique_ptr<lld::File>> @@ -410,8 +410,8 @@ normalizedObjectToAtoms(const NormalizedFile &normalizedFile, StringRef path, // Create atoms from each section. for (auto § : normalizedFile.sections) { DefinedAtom::ContentType atomType = atomTypeFromSection(sect); - if (error_code ec = processSection(atomType, sect, normalizedFile, *file, - copyRefs)) + if (std::error_code ec = + processSection(atomType, sect, normalizedFile, *file, copyRefs)) return ec; } // Create atoms from undefined symbols. diff --git a/lld/lib/ReaderWriter/MachO/WriterMachO.cpp b/lld/lib/ReaderWriter/MachO/WriterMachO.cpp index 504e8cdfad4..549229b252f 100644 --- a/lld/lib/ReaderWriter/MachO/WriterMachO.cpp +++ b/lld/lib/ReaderWriter/MachO/WriterMachO.cpp @@ -32,11 +32,11 @@ class MachOWriter : public Writer { public: MachOWriter(const MachOLinkingContext &ctxt) : _context(ctxt) { } - error_code writeFile(const lld::File &file, StringRef path) override { + std::error_code writeFile(const lld::File &file, StringRef path) override { // Construct empty normalized file from atoms. ErrorOr<std::unique_ptr<NormalizedFile>> nFile = normalized::normalizedFromAtoms(file, _context); - if (error_code ec = nFile.getError()) + if (std::error_code ec = nFile.getError()) return ec; // For testing, write out yaml form of normalized file. diff --git a/lld/lib/ReaderWriter/Native/ReaderNative.cpp b/lld/lib/ReaderWriter/Native/ReaderNative.cpp index 76be92258ae..48bf912c0ed 100644 --- a/lld/lib/ReaderWriter/Native/ReaderNative.cpp +++ b/lld/lib/ReaderWriter/Native/ReaderNative.cpp @@ -261,8 +261,8 @@ 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(std::unique_ptr<MemoryBuffer> mb, - std::vector<std::unique_ptr<lld::File>> &result) { + static std::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()); StringRef path(mb->getBufferIdentifier()); @@ -290,7 +290,7 @@ public: // process each chunk for (uint32_t i = 0; i < header->chunkCount; ++i) { - error_code ec; + std::error_code ec; const NativeChunk* chunk = &chunks[i]; // sanity check chunk is within file if ( chunk->fileOffset > fileSize ) @@ -400,8 +400,8 @@ private: friend NativeReferenceV2; // instantiate array of DefinedAtoms from v1 ivar data in file - error_code processDefinedAtomsV1(const uint8_t *base, - const NativeChunk *chunk) { + std::error_code processDefinedAtomsV1(const uint8_t *base, + const NativeChunk *chunk) { const size_t atomSize = sizeof(NativeDefinedAtomV1); size_t atomsArraySize = chunk->elementCount * atomSize; uint8_t* atomsStart = reinterpret_cast<uint8_t*> @@ -437,8 +437,8 @@ private: // set up pointers to attributes array - error_code processAttributesV1(const uint8_t *base, - const NativeChunk *chunk) { + std::error_code processAttributesV1(const uint8_t *base, + const NativeChunk *chunk) { this->_attributes = base + chunk->fileOffset; this->_attributesMaxOffset = chunk->fileSize; DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs() @@ -450,8 +450,8 @@ private: } // set up pointers to attributes array - error_code processAbsoluteAttributesV1(const uint8_t *base, - const NativeChunk *chunk) { + std::error_code processAbsoluteAttributesV1(const uint8_t *base, + const NativeChunk *chunk) { this->_absAttributes = base + chunk->fileOffset; this->_absAbsoluteMaxOffset = chunk->fileSize; DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs() @@ -463,8 +463,8 @@ private: } // instantiate array of UndefinedAtoms from v1 ivar data in file - error_code processUndefinedAtomsV1(const uint8_t *base, - const NativeChunk *chunk) { + std::error_code processUndefinedAtomsV1(const uint8_t *base, + const NativeChunk *chunk) { const size_t atomSize = sizeof(NativeUndefinedAtomV1); size_t atomsArraySize = chunk->elementCount * atomSize; uint8_t* atomsStart = reinterpret_cast<uint8_t*> @@ -499,8 +499,8 @@ private: // instantiate array of ShareLibraryAtoms from v1 ivar data in file - error_code processSharedLibraryAtomsV1(const uint8_t *base, - const NativeChunk *chunk) { + std::error_code processSharedLibraryAtomsV1(const uint8_t *base, + const NativeChunk *chunk) { const size_t atomSize = sizeof(NativeSharedLibraryAtomV1); size_t atomsArraySize = chunk->elementCount * atomSize; uint8_t* atomsStart = reinterpret_cast<uint8_t*> @@ -535,8 +535,8 @@ private: // instantiate array of AbsoluteAtoms from v1 ivar data in file - error_code processAbsoluteAtomsV1(const uint8_t *base, - const NativeChunk *chunk) { + std::error_code processAbsoluteAtomsV1(const uint8_t *base, + const NativeChunk *chunk) { const size_t atomSize = sizeof(NativeAbsoluteAtomV1); size_t atomsArraySize = chunk->elementCount * atomSize; uint8_t* atomsStart = reinterpret_cast<uint8_t*> @@ -569,9 +569,10 @@ private: return make_error_code(NativeReaderError::success); } - template<class T, class U> - error_code processReferences(const uint8_t *base, const NativeChunk *chunk, - uint8_t *&refsStart, uint8_t *&refsEnd) const { + template <class T, class U> + std::error_code + processReferences(const uint8_t *base, const NativeChunk *chunk, + uint8_t *&refsStart, uint8_t *&refsEnd) const { if (chunk->elementCount == 0) return make_error_code(NativeReaderError::success); size_t refsArraySize = chunk->elementCount * sizeof(T); @@ -592,11 +593,11 @@ private: } // instantiate array of References from v1 ivar data in file - error_code processReferencesV1(const uint8_t *base, - const NativeChunk *chunk) { + std::error_code processReferencesV1(const uint8_t *base, + const NativeChunk *chunk) { uint8_t *refsStart, *refsEnd; - if (error_code ec - = processReferences<NativeReferenceV1, NativeReferenceIvarsV1>( + if (std::error_code ec = + processReferences<NativeReferenceV1, NativeReferenceIvarsV1>( base, chunk, refsStart, refsEnd)) return ec; this->_referencesV1.arrayStart = refsStart; @@ -612,11 +613,11 @@ private: } // instantiate array of References from v2 ivar data in file - error_code processReferencesV2(const uint8_t *base, - const NativeChunk *chunk) { + std::error_code processReferencesV2(const uint8_t *base, + const NativeChunk *chunk) { uint8_t *refsStart, *refsEnd; - if (error_code ec - = processReferences<NativeReferenceV2, NativeReferenceIvarsV2>( + if (std::error_code ec = + processReferences<NativeReferenceV2, NativeReferenceIvarsV2>( base, chunk, refsStart, refsEnd)) return ec; this->_referencesV2.arrayStart = refsStart; @@ -632,8 +633,8 @@ private: } // set up pointers to target table - error_code processTargetsTable(const uint8_t *base, - const NativeChunk *chunk) { + std::error_code processTargetsTable(const uint8_t *base, + const NativeChunk *chunk) { const uint32_t* targetIndexes = reinterpret_cast<const uint32_t*> (base + chunk->fileOffset); this->_targetsTableCount = chunk->elementCount; @@ -682,8 +683,8 @@ private: // set up pointers to addend pool in file - error_code processAddendsTable(const uint8_t *base, - const NativeChunk *chunk) { + std::error_code processAddendsTable(const uint8_t *base, + const NativeChunk *chunk) { this->_addends = reinterpret_cast<const Reference::Addend*> (base + chunk->fileOffset); this->_addendsMaxIndex = chunk->elementCount; @@ -696,8 +697,8 @@ private: } // set up pointers to string pool in file - error_code processStrings(const uint8_t *base, - const NativeChunk *chunk) { + std::error_code processStrings(const uint8_t *base, + const NativeChunk *chunk) { this->_strings = reinterpret_cast<const char*>(base + chunk->fileOffset); this->_stringsMaxOffset = chunk->fileSize; DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs() @@ -708,8 +709,8 @@ private: } // set up pointers to content area in file - error_code processContent(const uint8_t *base, - const NativeChunk *chunk) { + std::error_code processContent(const uint8_t *base, + const NativeChunk *chunk) { this->_contentStart = base + chunk->fileOffset; this->_contentEnd = base + chunk->fileOffset + chunk->fileSize; DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs() @@ -1004,11 +1005,11 @@ public: sizeof(header->magic)) == 0); } - virtual error_code + 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); - return error_code(); + return std::error_code(); } }; } diff --git a/lld/lib/ReaderWriter/Native/WriterNative.cpp b/lld/lib/ReaderWriter/Native/WriterNative.cpp index fe7bf7fa131..8809074151e 100644 --- a/lld/lib/ReaderWriter/Native/WriterNative.cpp +++ b/lld/lib/ReaderWriter/Native/WriterNative.cpp @@ -32,7 +32,7 @@ class Writer : public lld::Writer { public: Writer(const LinkingContext &context) {} - error_code writeFile(const lld::File &file, StringRef outPath) override { + std::error_code writeFile(const lld::File &file, StringRef outPath) override { // reserve first byte for unnamed atoms _stringPool.push_back('\0'); // visit all atoms @@ -73,11 +73,11 @@ public: llvm::raw_fd_ostream out(outPath.data(), errorInfo, llvm::sys::fs::F_None); if (!errorInfo.empty()) - return error_code(); // FIXME + return std::error_code(); // FIXME this->write(out); - return error_code(); + return std::error_code(); } virtual ~Writer() { diff --git a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h index b5ee4f19407..931b1e4a6c6 100644 --- a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h +++ b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h @@ -76,9 +76,9 @@ public: return _absoluteAtoms; } - error_code + std::error_code parseAllMembers(std::vector<std::unique_ptr<File>> &result) const override { - return error_code(); + return std::error_code(); } private: diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp index 82ce4c102b0..83ef1f1db15 100644 --- a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp @@ -68,9 +68,9 @@ private: public: typedef const std::map<std::string, std::string> StringMap; - FileCOFF(std::unique_ptr<MemoryBuffer> mb, error_code &ec); + FileCOFF(std::unique_ptr<MemoryBuffer> mb, std::error_code &ec); - error_code parse(); + std::error_code parse(); StringRef getLinkerDirectives() const { return _directives; } bool isCompatibleWithSEH() const { return _compatibleWithSEH; } @@ -97,44 +97,48 @@ public: mutable llvm::BumpPtrAllocator _alloc; private: - error_code readSymbolTable(std::vector<const coff_symbol *> &result); + std::error_code readSymbolTable(std::vector<const coff_symbol *> &result); void createAbsoluteAtoms(const SymbolVectorT &symbols, std::vector<const AbsoluteAtom *> &result); - error_code createUndefinedAtoms(const SymbolVectorT &symbols, - std::vector<const UndefinedAtom *> &result); + std::error_code + createUndefinedAtoms(const SymbolVectorT &symbols, + std::vector<const UndefinedAtom *> &result); - error_code createDefinedSymbols(const SymbolVectorT &symbols, - std::vector<const DefinedAtom *> &result); + std::error_code + createDefinedSymbols(const SymbolVectorT &symbols, + std::vector<const DefinedAtom *> &result); - error_code cacheSectionAttributes(); - error_code maybeCreateSXDataAtoms(); + std::error_code cacheSectionAttributes(); + std::error_code maybeCreateSXDataAtoms(); - error_code + std::error_code AtomizeDefinedSymbolsInSection(const coff_section *section, std::vector<const coff_symbol *> &symbols, std::vector<COFFDefinedFileAtom *> &atoms); - error_code + std::error_code AtomizeDefinedSymbols(SectionToSymbolsT &definedSymbols, std::vector<const DefinedAtom *> &definedAtoms); - error_code findAtomAt(const coff_section *section, uint32_t targetAddress, - COFFDefinedFileAtom *&result, uint32_t &offsetInAtom); + std::error_code findAtomAt(const coff_section *section, + uint32_t targetAddress, + COFFDefinedFileAtom *&result, + uint32_t &offsetInAtom); - error_code getAtomBySymbolIndex(uint32_t index, Atom *&ret); + std::error_code getAtomBySymbolIndex(uint32_t index, Atom *&ret); - error_code + std::error_code addRelocationReference(const coff_relocation *rel, const coff_section *section, const std::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); + std::error_code getSectionContents(StringRef sectionName, + ArrayRef<uint8_t> &result); + std::error_code getReferenceArch(Reference::KindArch &result); + std::error_code addRelocationReferenceToAtoms(); + std::error_code findSection(StringRef name, const coff_section *&result); StringRef ArrayRefToString(ArrayRef<uint8_t> array); std::unique_ptr<const llvm::object::COFFObjectFile> _obj; @@ -277,7 +281,7 @@ DefinedAtom::Merge getMerge(const coff_aux_section_definition *auxsym) { } } -FileCOFF::FileCOFF(std::unique_ptr<MemoryBuffer> mb, error_code &ec) +FileCOFF::FileCOFF(std::unique_ptr<MemoryBuffer> mb, std::error_code &ec) : File(mb->getBufferIdentifier(), kindObject), _compatibleWithSEH(false), _ordinal(0) { auto binaryOrErr = llvm::object::createBinary(mb.release()); @@ -300,46 +304,48 @@ FileCOFF::FileCOFF(std::unique_ptr<MemoryBuffer> mb, error_code &ec) _directives = ArrayRefToString(directives); } -error_code FileCOFF::parse() { - if (error_code ec = getReferenceArch(_referenceArch)) +std::error_code FileCOFF::parse() { + if (std::error_code ec = getReferenceArch(_referenceArch)) return ec; // Read the symbol table and atomize them if possible. Defined atoms // cannot be atomized in one pass, so they will be not be atomized but // added to symbolToAtom. SymbolVectorT symbols; - if (error_code ec = readSymbolTable(symbols)) + if (std::error_code ec = readSymbolTable(symbols)) return ec; createAbsoluteAtoms(symbols, _absoluteAtoms._atoms); - if (error_code ec = createUndefinedAtoms(symbols, _undefinedAtoms._atoms)) + if (std::error_code ec = + createUndefinedAtoms(symbols, _undefinedAtoms._atoms)) return ec; - if (error_code ec = createDefinedSymbols(symbols, _definedAtoms._atoms)) + if (std::error_code ec = createDefinedSymbols(symbols, _definedAtoms._atoms)) return ec; - if (error_code ec = addRelocationReferenceToAtoms()) + if (std::error_code ec = addRelocationReferenceToAtoms()) return ec; - if (error_code ec = maybeCreateSXDataAtoms()) + if (std::error_code ec = maybeCreateSXDataAtoms()) return ec; - return error_code(); + return std::error_code(); } /// Iterate over the symbol table to retrieve all symbols. -error_code FileCOFF::readSymbolTable(std::vector<const coff_symbol *> &result) { +std::error_code +FileCOFF::readSymbolTable(std::vector<const coff_symbol *> &result) { const llvm::object::coff_file_header *header = nullptr; - if (error_code ec = _obj->getHeader(header)) + if (std::error_code ec = _obj->getHeader(header)) return ec; for (uint32_t i = 0, e = header->NumberOfSymbols; i != e; ++i) { // Retrieve the symbol. const coff_symbol *sym; StringRef name; - if (error_code ec = _obj->getSymbol(i, sym)) + if (std::error_code ec = _obj->getSymbol(i, sym)) return ec; if (sym->SectionNumber == llvm::COFF::IMAGE_SYM_DEBUG) goto next; result.push_back(sym); - if (error_code ec = _obj->getSymbolName(sym, name)) + if (std::error_code ec = _obj->getSymbolName(sym, name)) return ec; // Existence of the symbol @feat.00 indicates that object file is compatible @@ -359,14 +365,14 @@ error_code FileCOFF::readSymbolTable(std::vector<const coff_symbol *> &result) { // store it to _auxSymbol. if (sym->NumberOfAuxSymbols > 0) { const coff_symbol *aux = nullptr; - if (error_code ec = _obj->getAuxSymbol(i + 1, aux)) + if (std::error_code ec = _obj->getAuxSymbol(i + 1, aux)) return ec; _auxSymbol[sym] = aux; } next: i += sym->NumberOfAuxSymbols; } - return error_code(); + return std::error_code(); } /// Create atoms for the absolute symbols. @@ -390,7 +396,7 @@ void FileCOFF::createAbsoluteAtoms(const SymbolVectorT &symbols, /// it's linked normally. If not, sym1 is resolved as if it has sym2's /// name. This relationship between sym1 and sym2 is represented using /// fallback mechanism of undefined symbol. -error_code +std::error_code FileCOFF::createUndefinedAtoms(const SymbolVectorT &symbols, std::vector<const UndefinedAtom *> &result) { // Sort out undefined symbols from all symbols. @@ -409,7 +415,7 @@ FileCOFF::createUndefinedAtoms(const SymbolVectorT &symbols, const coff_aux_weak_external *aux = reinterpret_cast<const coff_aux_weak_external *>(iter->second); const coff_symbol *sym2; - if (error_code ec = _obj->getSymbol(aux->TagIndex, sym2)) + if (std::error_code ec = _obj->getSymbol(aux->TagIndex, sym2)) return ec; weakExternal[sym] = sym2; } @@ -438,20 +444,20 @@ FileCOFF::createUndefinedAtoms(const SymbolVectorT &symbols, result.push_back(atom); _symbolAtom[sym] = atom; } - return error_code(); + return std::error_code(); } /// Create atoms for the defined symbols. This pass is a bit complicated than /// the other two, because in order to create the atom for the defined symbol /// we need to know the adjacent symbols. -error_code +std::error_code FileCOFF::createDefinedSymbols(const SymbolVectorT &symbols, std::vector<const DefinedAtom *> &result) { // A defined atom can be merged if its section attribute allows its contents // to be merged. In COFF, it's not very easy to get the section attribute // for the symbol, so scan all sections in advance and cache the attributes // for later use. - if (error_code ec = cacheSectionAttributes()) + if (std::error_code ec = cacheSectionAttributes()) return ec; // Filter non-defined atoms, and group defined atoms by its section. @@ -497,7 +503,7 @@ FileCOFF::createDefinedSymbols(const SymbolVectorT &symbols, continue; const coff_section *sec; - if (error_code ec = _obj->getSection(sym->SectionNumber, sec)) + if (std::error_code ec = _obj->getSection(sym->SectionNumber, sec)) return ec; assert(sec && "SectionIndex > 0, Sec must be non-null!"); @@ -506,7 +512,7 @@ FileCOFF::createDefinedSymbols(const SymbolVectorT &symbols, // multiple COMDAT sections whose section name are the same. We don't want // to make atoms for them as they would become duplicate symbols. StringRef sectionName; - if (error_code ec = _obj->getSectionName(sec, sectionName)) + if (std::error_code ec = _obj->getSectionName(sec, sectionName)) return ec; if (_symbolName[sym] == sectionName && sym->Value == 0 && _merge[sec] != DefinedAtom::mergeNo) @@ -526,15 +532,15 @@ FileCOFF::createDefinedSymbols(const SymbolVectorT &symbols, } // Atomize the defined symbols. - if (error_code ec = AtomizeDefinedSymbols(definedSymbols, result)) + if (std::error_code ec = AtomizeDefinedSymbols(definedSymbols, result)) return ec; - return error_code(); + return std::error_code(); } // Cache the COMDAT attributes, which indicate whether the symbols in the // section can be merged or not. -error_code FileCOFF::cacheSectionAttributes() { +std::error_code FileCOFF::cacheSectionAttributes() { // The COMDAT section attribute is not an attribute of coff_section, but is // stored in the auxiliary symbol for the first symbol referring a COMDAT // section. It feels to me that it's unnecessarily complicated, but this is @@ -546,7 +552,7 @@ error_code FileCOFF::cacheSectionAttributes() { continue; const coff_section *sec; - if (error_code ec = _obj->getSection(sym->SectionNumber, sec)) + if (std::error_code ec = _obj->getSection(sym->SectionNumber, sec)) return ec; if (_merge.count(sec)) @@ -570,12 +576,12 @@ error_code FileCOFF::cacheSectionAttributes() { if (!_merge.count(sec)) _merge[sec] = DefinedAtom::mergeNo; } - return error_code(); + return std::error_code(); } /// Atomize \p symbols and append the results to \p atoms. The symbols are /// assumed to have been defined in the \p section. -error_code FileCOFF::AtomizeDefinedSymbolsInSection( +std::error_code FileCOFF::AtomizeDefinedSymbolsInSection( const coff_section *section, std::vector<const coff_symbol *> &symbols, std::vector<COFFDefinedFileAtom *> &atoms) { // Sort symbols by position. @@ -589,7 +595,7 @@ error_code FileCOFF::AtomizeDefinedSymbolsInSection( -> bool { return a->Value < b->Value; })); StringRef sectionName; - if (error_code ec = _obj->getSectionName(section, sectionName)) + if (std::error_code ec = _obj->getSectionName(section, sectionName)) return ec; // BSS section does not have contents. If this is the BSS section, create @@ -605,18 +611,18 @@ error_code FileCOFF::AtomizeDefinedSymbolsInSection( atoms.push_back(atom); _symbolAtom[sym] = atom; } - return error_code(); + return std::error_code(); } ArrayRef<uint8_t> secData; - if (error_code ec = _obj->getSectionContents(section, secData)) + if (std::error_code ec = _obj->getSectionContents(section, secData)) return ec; // A section with IMAGE_SCN_LNK_{INFO,REMOVE} attribute will never become // a part of the output image. That's what the COFF spec says. if (section->Characteristics & llvm::COFF::IMAGE_SCN_LNK_INFO || section->Characteristics & llvm::COFF::IMAGE_SCN_LNK_REMOVE) - return error_code(); + return std::error_code(); // Supporting debug info needs more work than just linking and combining // .debug sections. We don't support it yet. Let's discard .debug sections at @@ -624,7 +630,7 @@ error_code FileCOFF::AtomizeDefinedSymbolsInSection( // blobs that nobody would understand. if ((section->Characteristics & llvm::COFF::IMAGE_SCN_MEM_DISCARDABLE) && (sectionName == ".debug" || sectionName.startswith(".debug$"))) { - return error_code(); + return std::error_code(); } DefinedAtom::ContentType type = getContentType(section); @@ -639,7 +645,7 @@ error_code FileCOFF::AtomizeDefinedSymbolsInSection( perms, _merge[section], data, _ordinal++); atoms.push_back(atom); _definedAtomLocations[section][0].push_back(atom); - return error_code(); + return std::error_code(); } // Create an unnamed atom if the first atom isn't at the start of the @@ -671,10 +677,10 @@ error_code FileCOFF::AtomizeDefinedSymbolsInSection( // Finally, set alignment to the first atom so that the section contents // will be aligned as specified by the object section header. _definedAtomLocations[section][0][0]->setAlignment(getAlignment(section)); - return error_code(); + return std::error_code(); } -error_code FileCOFF::AtomizeDefinedSymbols( +std::error_code FileCOFF::AtomizeDefinedSymbols( SectionToSymbolsT &definedSymbols, std::vector<const DefinedAtom *> &definedAtoms) { // For each section, make atoms for all the symbols defined in the @@ -683,7 +689,8 @@ error_code FileCOFF::AtomizeDefinedSymbols( const coff_section *section = i.first; std::vector<const coff_symbol *> &symbols = i.second; std::vector<COFFDefinedFileAtom *> atoms; - if (error_code ec = AtomizeDefinedSymbolsInSection(section, symbols, atoms)) + if (std::error_code ec = + AtomizeDefinedSymbolsInSection(section, symbols, atoms)) return ec; // Connect atoms with layout-before/layout-after edges. @@ -694,14 +701,14 @@ error_code FileCOFF::AtomizeDefinedSymbols( definedAtoms.push_back(atom); } } - return error_code(); + return std::error_code(); } /// Find the atom that is at \p targetAddress in \p section. -error_code FileCOFF::findAtomAt(const coff_section *section, - uint32_t targetAddress, - COFFDefinedFileAtom *&result, - uint32_t &offsetInAtom) { +std::error_code FileCOFF::findAtomAt(const coff_section *section, + uint32_t targetAddress, + COFFDefinedFileAtom *&result, + uint32_t &offsetInAtom) { for (auto i : _definedAtomLocations[section]) { uint32_t atomAddress = i.first; std::vector<COFFDefinedAtom *> &atomsAtSameLocation = i.second; @@ -710,7 +717,7 @@ error_code FileCOFF::findAtomAt(const coff_section *section, targetAddress < atomAddress + atom->size()) { result = atom; offsetInAtom = targetAddress - atomAddress; - return error_code(); + return std::error_code(); } } // Relocation target is out of range @@ -719,19 +726,19 @@ error_code FileCOFF::findAtomAt(const coff_section *section, /// Find the atom for the symbol that was at the \p index in the symbol /// table. -error_code FileCOFF::getAtomBySymbolIndex(uint32_t index, Atom *&ret) { +std::error_code FileCOFF::getAtomBySymbolIndex(uint32_t index, Atom *&ret) { const coff_symbol *symbol; - if (error_code ec = _obj->getSymbol(index, symbol)) + if (std::error_code ec = _obj->getSymbol(index, symbol)) return ec; ret = _symbolAtom[symbol]; assert(ret); - return error_code(); + return std::error_code(); } /// Add relocation information to an atom based on \p rel. \p rel is an /// relocation entry for the \p section, and \p atoms are all the atoms /// defined in the \p section. -error_code FileCOFF::addRelocationReference( +std::error_code FileCOFF::addRelocationReference( const coff_relocation *rel, const coff_section *section, const std::vector<COFFDefinedFileAtom *> &atoms) { assert(atoms.size() > 0); @@ -741,54 +748,55 @@ error_code FileCOFF::addRelocationReference( uint32_t itemAddress = rel->VirtualAddress + section->VirtualAddress; Atom *targetAtom = nullptr; - if (error_code ec = getAtomBySymbolIndex(rel->SymbolTableIndex, targetAtom)) + if (std::error_code ec = + getAtomBySymbolIndex(rel->SymbolTableIndex, targetAtom)) return ec; COFFDefinedFileAtom *atom; uint32_t offsetInAtom; - if (error_code ec = findAtomAt(section, itemAddress, atom, offsetInAtom)) + if (std::error_code ec = findAtomAt(section, itemAddress, atom, offsetInAtom)) return ec; atom->addReference(std::unique_ptr<COFFReference>( new COFFReference(targetAtom, offsetInAtom, rel->Type, Reference::KindNamespace::COFF, _referenceArch))); - return error_code(); + return std::error_code(); } // Read section contents. -error_code FileCOFF::getSectionContents(StringRef sectionName, - ArrayRef<uint8_t> &result) { +std::error_code FileCOFF::getSectionContents(StringRef sectionName, + ArrayRef<uint8_t> &result) { const coff_section *section = nullptr; - if (error_code ec = findSection(sectionName, section)) + if (std::error_code ec = findSection(sectionName, section)) return ec; if (!section) - return error_code(); - if (error_code ec = _obj->getSectionContents(section, result)) + return std::error_code(); + if (std::error_code ec = _obj->getSectionContents(section, result)) return ec; - return error_code(); + return std::error_code(); } /// Returns the target machine type of the current object file. -error_code FileCOFF::getReferenceArch(Reference::KindArch &result) { +std::error_code FileCOFF::getReferenceArch(Reference::KindArch &result) { const llvm::object::coff_file_header *header = nullptr; - if (error_code ec = _obj->getHeader(header)) + if (std::error_code ec = _obj->getHeader(header)) return ec; switch (header->Machine) { case llvm::COFF::IMAGE_FILE_MACHINE_I386: result = Reference::KindArch::x86; - return error_code(); + return std::error_code(); case llvm::COFF::IMAGE_FILE_MACHINE_AMD64: result = Reference::KindArch::x86_64; - return error_code(); + return std::error_code(); case llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN: result = Reference::KindArch::all; - return error_code(); + return std::error_code(); } llvm::errs() << "Unsupported machine type: " << header->Machine << "\n"; return llvm::object::object_error::parse_failed; } /// Add relocation information to atoms. -error_code FileCOFF::addRelocationReferenceToAtoms() { +std::error_code FileCOFF::addRelocationReferenceToAtoms() { // Relocation entries are defined for each section. for (const auto &sec : _obj->sections()) { const coff_section *section = _obj->getCOFFSection(sec); @@ -806,7 +814,7 @@ error_code FileCOFF::addRelocationReferenceToAtoms() { return ec; } } - return error_code(); + return std::error_code(); } // Read .sxdata section if exists. .sxdata is a x86-only section that contains a @@ -822,12 +830,12 @@ error_code FileCOFF::addRelocationReferenceToAtoms() { // What we want to emit from the linker is a vector of SEH handler VAs, but here // we have a vector of offsets to the symbol table. So we convert the latter to // the former. -error_code FileCOFF::maybeCreateSXDataAtoms() { +std::error_code FileCOFF::maybeCreateSXDataAtoms() { ArrayRef<uint8_t> sxdata; - if (error_code ec = getSectionContents(".sxdata", sxdata)) + if (std::error_code ec = getSectionContents(".sxdata", sxdata)) return ec; if (sxdata.empty()) - return error_code(); + return std::error_code(); std::vector<uint8_t> atomContent = *new (_alloc) std::vector<uint8_t>((size_t)sxdata.size()); @@ -842,7 +850,7 @@ error_code FileCOFF::maybeCreateSXDataAtoms() { for (int i = 0; i < numSymbols; ++i) { Atom *handlerFunc; - if (error_code ec = getAtomBySymbolIndex(symbolIndex[i], handlerFunc)) + if (std::error_code ec = getAtomBySymbolIndex(symbolIndex[i], handlerFunc)) return ec; int offsetInAtom = i * sizeof(uint32_t); atom->addReference(std::unique_ptr<COFFReference>(new COFFReference( @@ -851,11 +859,12 @@ error_code FileCOFF::maybeCreateSXDataAtoms() { } _definedAtoms._atoms.push_back(atom); - return error_code(); + return std::error_code(); } /// Find a section by name. -error_code FileCOFF::findSection(StringRef name, const coff_section *&result) { +std::error_code FileCOFF::findSection(StringRef name, + const coff_section *&result) { for (const auto &sec : _obj->sections()) { const coff_section *section = _obj->getCOFFSection(sec); StringRef sectionName; @@ -863,12 +872,12 @@ error_code FileCOFF::findSection(StringRef name, const coff_section *&result) { return ec; if (sectionName == name) { result = section; - return error_code(); + return std::error_code(); } } // Section was not found, but it's not an error. This method returns // an error only when there's a read error. - return error_code(); + return std::error_code(); } // Convert ArrayRef<uint8_t> to std::string. The array contains a string which @@ -911,27 +920,27 @@ public: return (magic == llvm::sys::fs::file_magic::windows_resource); } - error_code + std::error_code parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &, std::vector<std::unique_ptr<File>> &result) const override { // Convert RC file to COFF ErrorOr<std::string> coffPath = convertResourceFileToCOFF(std::move(mb)); - if (error_code ec = coffPath.getError()) + if (std::error_code ec = coffPath.getError()) return ec; llvm::FileRemover coffFileRemover(*coffPath); // Read and parse the COFF std::unique_ptr<MemoryBuffer> newmb; - if (error_code ec = MemoryBuffer::getFile(*coffPath, newmb)) + if (std::error_code ec = MemoryBuffer::getFile(*coffPath, newmb)) return ec; - error_code ec; + std::error_code ec; std::unique_ptr<FileCOFF> file(new FileCOFF(std::move(newmb), ec)); if (ec) return ec; - if (error_code ec = file->parse()) + if (std::error_code ec = file->parse()) return ec; result.push_back(std::move(file)); - return error_code(); + return std::error_code(); } private: @@ -939,18 +948,18 @@ private: writeResToTemporaryFile(std::unique_ptr<MemoryBuffer> mb) { // Get a temporary file path for .res file. SmallString<128> tempFilePath; - if (error_code ec = + if (std::error_code ec = llvm::sys::fs::createTemporaryFile("tmp", "res", tempFilePath)) return ec; // Write the memory buffer contents to .res file, so that we can run // cvtres.exe on it. std::unique_ptr<llvm::FileOutputBuffer> buffer; - if (error_code ec = llvm::FileOutputBuffer::create( + if (std::error_code ec = llvm::FileOutputBuffer::create( tempFilePath.str(), mb->getBufferSize(), buffer)) return ec; memcpy(buffer->getBufferStart(), mb->getBufferStart(), mb->getBufferSize()); - if (error_code ec = buffer->commit()) + if (std::error_code ec = buffer->commit()) return ec; // Convert SmallString -> StringRef -> std::string. @@ -961,13 +970,13 @@ private: convertResourceFileToCOFF(std::unique_ptr<MemoryBuffer> mb) { // Write the resource file to a temporary file. ErrorOr<std::string> inFilePath = writeResToTemporaryFile(std::move(mb)); - if (error_code ec = inFilePath.getError()) + if (std::error_code ec = inFilePath.getError()) return ec; llvm::FileRemover inFileRemover(*inFilePath); // Create an output file path. SmallString<128> outFilePath; - if (error_code ec = + if (std::error_code ec = llvm::sys::fs::createTemporaryFile("tmp", "obj", outFilePath)) return ec; std::string outFileArg = ("/out:" + outFilePath).str(); @@ -1011,12 +1020,12 @@ public: return magic == llvm::sys::fs::file_magic::coff_object; } - error_code + std::error_code parseFile(std::unique_ptr<MemoryBuffer> &mb, const Registry ®istry, std::vector<std::unique_ptr<File>> &result) const override { // Parse the memory buffer as PECOFF file. const char *mbName = mb->getBufferIdentifier(); - error_code ec; + std::error_code ec; std::unique_ptr<FileCOFF> file(new FileCOFF(std::move(mb), ec)); if (ec) return ec; @@ -1024,10 +1033,10 @@ public: // Interpret .drectve section if the section has contents. StringRef directives = file->getLinkerDirectives(); if (!directives.empty()) - if (error_code ec = handleDirectiveSection(registry, directives)) + if (std::error_code ec = handleDirectiveSection(registry, directives)) return ec; - if (error_code ec = file->parse()) + if (std::error_code ec = file->parse()) return ec; // Check for /SAFESEH. @@ -1048,7 +1057,7 @@ public: createAlternateNameAtoms(*file); result.push_back(std::move(file)); - return error_code(); + return std::error_code(); } private: @@ -1058,8 +1067,8 @@ private: // // The section mainly contains /defaultlib (-l in Unix), but can contain any // options as long as they are valid. - error_code handleDirectiveSection(const Registry ®istry, - StringRef directives) const { + std::error_code handleDirectiveSection(const Registry ®istry, + StringRef directives) const { DEBUG(llvm::dbgs() << ".drectve: " << directives << "\n"); // Split the string into tokens, as the shell would do for argv. @@ -1086,7 +1095,7 @@ private: if (!errorMessage.empty()) { llvm::errs() << "lld warning: " << errorMessage << "\n"; } - return error_code(); + return std::error_code(); } AliasAtom *createAlias(FileCOFF &file, StringRef name, diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.h b/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.h index 4f9eb0b4300..33ccc6a3870 100644 --- a/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.h +++ b/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.h @@ -23,9 +23,10 @@ class File; namespace pecoff { -error_code parseCOFFImportLibrary(const LinkingContext &context, - std::unique_ptr<MemoryBuffer> &mb, - std::vector<std::unique_ptr<File> > &result); +std::error_code +parseCOFFImportLibrary(const LinkingContext &context, + std::unique_ptr<MemoryBuffer> &mb, + std::vector<std::unique_ptr<File>> &result); } } diff --git a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp index ec281ed2e9e..1ac8d38593a 100644 --- a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp @@ -832,7 +832,7 @@ public: _imageSizeOnDisk(0) {} template <class PEHeader> void build(const File &linkedFile); - error_code writeFile(const File &linkedFile, StringRef path) override; + std::error_code writeFile(const File &linkedFile, StringRef path) override; private: void applyAllRelocations(uint8_t *bufferStart); @@ -1008,7 +1008,8 @@ void PECOFFWriter::build(const File &linkedFile) { peHeader->setSizeOfHeaders(sectionTable->fileOffset() + sectionTable->size()); } -error_code PECOFFWriter::writeFile(const File &linkedFile, StringRef path) { +std::error_code PECOFFWriter::writeFile(const File &linkedFile, + StringRef path) { if (_ctx.is64Bit()) { this->build<llvm::object::pe32plus_header>(linkedFile); } else { @@ -1017,7 +1018,7 @@ error_code PECOFFWriter::writeFile(const File &linkedFile, StringRef path) { uint64_t totalSize = _chunks.back()->fileOffset() + _chunks.back()->size(); std::unique_ptr<llvm::FileOutputBuffer> buffer; - error_code ec = llvm::FileOutputBuffer::create( + std::error_code ec = llvm::FileOutputBuffer::create( path, totalSize, buffer, llvm::FileOutputBuffer::F_executable); if (ec) return ec; diff --git a/lld/lib/ReaderWriter/Reader.cpp b/lld/lib/ReaderWriter/Reader.cpp index 355f7e1ef57..f35a9e60d22 100644 --- a/lld/lib/ReaderWriter/Reader.cpp +++ b/lld/lib/ReaderWriter/Reader.cpp @@ -29,7 +29,7 @@ void Registry::add(std::unique_ptr<YamlIOTaggedDocumentHandler> handler) { _yamlHandlers.push_back(std::move(handler)); } -error_code +std::error_code Registry::parseFile(std::unique_ptr<MemoryBuffer> &mb, std::vector<std::unique_ptr<File>> &result) const { // Get file type. diff --git a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp index 3462ce27696..1663c6143f0 100644 --- a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp +++ b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp @@ -635,9 +635,9 @@ template <> struct MappingTraits<const lld::File *> { return nullptr; } - virtual error_code + virtual std::error_code parseAllMembers(std::vector<std::unique_ptr<File>> &result) const override { - return error_code(); + return std::error_code(); } StringRef _path; @@ -1246,7 +1246,7 @@ class Writer : public lld::Writer { public: Writer(const LinkingContext &context) : _context(context) {} - error_code writeFile(const lld::File &file, StringRef outPath) override { + std::error_code writeFile(const lld::File &file, StringRef outPath) override { // Create stream to path. std::string errorInfo; llvm::raw_fd_ostream out(outPath.data(), errorInfo, llvm::sys::fs::F_Text); @@ -1263,7 +1263,7 @@ public: const lld::File *fileRef = &file; yout << fileRef; - return error_code(); + return std::error_code(); } private: @@ -1307,7 +1307,7 @@ public: return (ext.equals(".objtxt") || ext.equals(".yaml")); } - error_code + std::error_code parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &, std::vector<std::unique_ptr<File>> &result) const override { // Note: we do not take ownership of the MemoryBuffer. That is |

