diff options
Diffstat (limited to 'lld/lib/ReaderWriter')
5 files changed, 38 insertions, 37 deletions
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h b/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h index 7934a6c0336..98767e961df 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h @@ -294,7 +294,7 @@ readBinary(std::unique_ptr<MemoryBuffer> &mb, const MachOLinkingContext::Arch arch); /// Takes in-memory normalized view and writes a mach-o object file. -std::error_code writeBinary(const NormalizedFile &file, StringRef path); +llvm::Error writeBinary(const NormalizedFile &file, StringRef path); size_t headerAndLoadCommandsSize(const NormalizedFile &file); @@ -322,7 +322,7 @@ normalizedToAtoms(const NormalizedFile &normalizedFile, StringRef path, bool copyRefs); /// Takes atoms and generates a normalized macho-o view. -ErrorOr<std::unique_ptr<NormalizedFile>> +llvm::Expected<std::unique_ptr<NormalizedFile>> normalizedFromAtoms(const lld::File &atomFile, const MachOLinkingContext &ctxt); diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp index f85dbba9d6e..b8c739627c4 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp @@ -133,7 +133,7 @@ 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. - std::error_code writeBinary(StringRef path); + llvm::Error writeBinary(StringRef path); private: uint32_t loadCommandsSize(uint32_t &count); @@ -1459,10 +1459,10 @@ void MachOFileLayout::writeLinkEditContent() { } } -std::error_code MachOFileLayout::writeBinary(StringRef path) { +llvm::Error MachOFileLayout::writeBinary(StringRef path) { // Check for pending error from constructor. if (_ec) - return _ec; + return llvm::errorCodeToError(_ec); // Create FileOutputBuffer with calculated size. unsigned flags = 0; if (_file.fileType != llvm::MachO::MH_OBJECT) @@ -1470,23 +1470,23 @@ std::error_code MachOFileLayout::writeBinary(StringRef path) { ErrorOr<std::unique_ptr<llvm::FileOutputBuffer>> fobOrErr = llvm::FileOutputBuffer::create(path, size(), flags); if (std::error_code ec = fobOrErr.getError()) - return ec; + return llvm::errorCodeToError(ec); std::unique_ptr<llvm::FileOutputBuffer> &fob = *fobOrErr; // Write content. _buffer = fob->getBufferStart(); writeMachHeader(); std::error_code ec = writeLoadCommands(); if (ec) - return ec; + return llvm::errorCodeToError(ec); writeSectionContent(); writeLinkEditContent(); fob->commit(); - return std::error_code(); + return llvm::Error(); } /// Takes in-memory normalized view and writes a mach-o object file. -std::error_code writeBinary(const NormalizedFile &file, StringRef path) { +llvm::Error writeBinary(const NormalizedFile &file, StringRef path) { MachOFileLayout layout(file); return layout.writeBinary(path); } diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp index 5570382fb9a..bfd133e3b16 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp @@ -120,7 +120,7 @@ public: void copySectionInfo(NormalizedFile &file); void updateSectionInfo(NormalizedFile &file); void buildAtomToAddressMap(); - std::error_code addSymbols(const lld::File &atomFile, NormalizedFile &file); + llvm::Error addSymbols(const lld::File &atomFile, NormalizedFile &file); void addIndirectSymbols(const lld::File &atomFile, NormalizedFile &file); void addRebaseAndBindingInfo(const lld::File &, NormalizedFile &file); void addExportInfo(const lld::File &, NormalizedFile &file); @@ -164,9 +164,9 @@ private: uint8_t &segmentIndex, uint64_t &segmentStartAddr); const Atom *targetOfLazyPointer(const DefinedAtom *lpAtom); const Atom *targetOfStub(const DefinedAtom *stubAtom); - std::error_code getSymbolTableRegion(const DefinedAtom* atom, - bool &inGlobalsRegion, - SymbolScope &symbolScope); + llvm::Error getSymbolTableRegion(const DefinedAtom* atom, + bool &inGlobalsRegion, + SymbolScope &symbolScope); void appendSection(SectionInfo *si, NormalizedFile &file); uint32_t sectionIndexForAtom(const Atom *atom); @@ -820,55 +820,55 @@ bool Util::AtomSorter::operator()(const AtomAndIndex &left, return (left.atom->name().compare(right.atom->name()) < 0); } -std::error_code Util::getSymbolTableRegion(const DefinedAtom* atom, - bool &inGlobalsRegion, - SymbolScope &scope) { +llvm::Error Util::getSymbolTableRegion(const DefinedAtom* atom, + bool &inGlobalsRegion, + SymbolScope &scope) { bool rMode = (_ctx.outputMachOType() == llvm::MachO::MH_OBJECT); switch (atom->scope()) { case Atom::scopeTranslationUnit: scope = 0; inGlobalsRegion = false; - return std::error_code(); + return llvm::Error(); case Atom::scopeLinkageUnit: if ((_ctx.exportMode() == MachOLinkingContext::ExportMode::whiteList) && _ctx.exportSymbolNamed(atom->name())) { - return make_dynamic_error_code(Twine("cannot export hidden symbol ") - + atom->name()); + return llvm::make_error<GenericError>( + Twine("cannot export hidden symbol ") + atom->name()); } if (rMode) { if (_ctx.keepPrivateExterns()) { // -keep_private_externs means keep in globals region as N_PEXT. scope = N_PEXT | N_EXT; inGlobalsRegion = true; - return std::error_code(); + return llvm::Error(); } } // scopeLinkageUnit symbols are no longer global once linked. scope = N_PEXT; inGlobalsRegion = false; - return std::error_code(); + return llvm::Error(); case Atom::scopeGlobal: if (_ctx.exportRestrictMode()) { if (_ctx.exportSymbolNamed(atom->name())) { scope = N_EXT; inGlobalsRegion = true; - return std::error_code(); + return llvm::Error(); } else { scope = N_PEXT; inGlobalsRegion = false; - return std::error_code(); + return llvm::Error(); } } else { scope = N_EXT; inGlobalsRegion = true; - return std::error_code(); + return llvm::Error(); } break; } } -std::error_code Util::addSymbols(const lld::File &atomFile, - NormalizedFile &file) { +llvm::Error Util::addSymbols(const lld::File &atomFile, + NormalizedFile &file) { bool rMode = (_ctx.outputMachOType() == llvm::MachO::MH_OBJECT); // Mach-O symbol table has three regions: locals, globals, undefs. @@ -964,7 +964,7 @@ std::error_code Util::addSymbols(const lld::File &atomFile, file.undefinedSymbols.push_back(sym); } - return std::error_code(); + return llvm::Error(); } const Atom *Util::targetOfLazyPointer(const DefinedAtom *lpAtom) { @@ -1350,7 +1350,7 @@ namespace mach_o { namespace normalized { /// Convert a set of Atoms into a normalized mach-o file. -ErrorOr<std::unique_ptr<NormalizedFile>> +llvm::Expected<std::unique_ptr<NormalizedFile>> normalizedFromAtoms(const lld::File &atomFile, const MachOLinkingContext &context) { // The util object buffers info until the normalized file can be made. @@ -1406,7 +1406,7 @@ normalizedFromAtoms(const lld::File &atomFile, util.updateSectionInfo(normFile); util.copySectionContent(normFile); if (auto ec = util.addSymbols(atomFile, normFile)) { - return ec; + return std::move(ec); } util.addIndirectSymbols(atomFile, normFile); util.addRebaseAndBindingInfo(atomFile, normFile); diff --git a/lld/lib/ReaderWriter/MachO/WriterMachO.cpp b/lld/lib/ReaderWriter/MachO/WriterMachO.cpp index cce0a179608..972f987f60c 100644 --- a/lld/lib/ReaderWriter/MachO/WriterMachO.cpp +++ b/lld/lib/ReaderWriter/MachO/WriterMachO.cpp @@ -28,17 +28,18 @@ class MachOWriter : public Writer { public: MachOWriter(const MachOLinkingContext &ctxt) : _ctx(ctxt) {} - std::error_code writeFile(const lld::File &file, StringRef path) override { + llvm::Error writeFile(const lld::File &file, StringRef path) override { // Construct empty normalized file from atoms. - ErrorOr<std::unique_ptr<NormalizedFile>> nFile = + llvm::Expected<std::unique_ptr<NormalizedFile>> nFile = normalized::normalizedFromAtoms(file, _ctx); - if (std::error_code ec = nFile.getError()) - return ec; + if (auto ec = nFile.takeError()) + return std::move(ec); // For testing, write out yaml form of normalized file. if (_ctx.printAtoms()) { std::unique_ptr<Writer> yamlWriter = createWriterYAML(_ctx); - yamlWriter->writeFile(file, "-"); + if (auto ec = yamlWriter->writeFile(file, "-")) + return std::move(ec); } // Write normalized file as mach-o binary. diff --git a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp index f98fa0e3a6c..a2f27f841d7 100644 --- a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp +++ b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp @@ -1280,12 +1280,12 @@ class Writer : public lld::Writer { public: Writer(const LinkingContext &context) : _ctx(context) {} - std::error_code writeFile(const lld::File &file, StringRef outPath) override { + llvm::Error writeFile(const lld::File &file, StringRef outPath) override { // Create stream to path. std::error_code ec; llvm::raw_fd_ostream out(outPath, ec, llvm::sys::fs::F_Text); if (ec) - return ec; + return llvm::errorCodeToError(ec); // Create yaml Output writer, using yaml options for context. YamlContext yamlContext; @@ -1297,7 +1297,7 @@ public: const lld::File *fileRef = &file; yout << fileRef; - return std::error_code(); + return llvm::Error(); } private: |