diff options
27 files changed, 132 insertions, 134 deletions
diff --git a/lld/include/lld/Core/Pass.h b/lld/include/lld/Core/Pass.h index 15ab94a2cd7..2e49cd1b8ee 100644 --- a/lld/include/lld/Core/Pass.h +++ b/lld/include/lld/Core/Pass.h @@ -34,7 +34,7 @@ public: virtual ~Pass() { } /// Do the actual work of the Pass. - virtual std::error_code perform(std::unique_ptr<SimpleFile> &mergedFile) = 0; + virtual std::error_code perform(SimpleFile &mergedFile) = 0; protected: // Only subclassess can be instantiated. diff --git a/lld/include/lld/Core/PassManager.h b/lld/include/lld/Core/PassManager.h index cea74c3804b..62aa119f8f7 100644 --- a/lld/include/lld/Core/PassManager.h +++ b/lld/include/lld/Core/PassManager.h @@ -31,7 +31,7 @@ public: _passes.push_back(std::move(pass)); } - std::error_code runOnFile(std::unique_ptr<SimpleFile> &file) { + std::error_code runOnFile(SimpleFile &file) { for (std::unique_ptr<Pass> &pass : _passes) if (std::error_code EC = pass->perform(file)) return EC; diff --git a/lld/lib/Driver/Driver.cpp b/lld/lib/Driver/Driver.cpp index 968b2cc42ef..7ceecd92ee3 100644 --- a/lld/lib/Driver/Driver.cpp +++ b/lld/lib/Driver/Driver.cpp @@ -117,7 +117,7 @@ bool Driver::link(LinkingContext &ctx, raw_ostream &diagnostics) { ScopedTask passTask(getDefaultDomain(), "Passes"); PassManager pm; ctx.addPasses(pm); - if (std::error_code ec = pm.runOnFile(merged)) { + if (std::error_code ec = pm.runOnFile(*merged)) { diagnostics << "Failed to write file '" << ctx.outputPath() << "': " << ec.message() << "\n"; return false; diff --git a/lld/lib/ReaderWriter/CoreLinkingContext.cpp b/lld/lib/ReaderWriter/CoreLinkingContext.cpp index 103fed80458..2f4752bf877 100644 --- a/lld/lib/ReaderWriter/CoreLinkingContext.cpp +++ b/lld/lib/ReaderWriter/CoreLinkingContext.cpp @@ -22,8 +22,8 @@ namespace { class OrderPass : public Pass { public: /// Sorts atoms by position - std::error_code perform(std::unique_ptr<SimpleFile> &file) override { - SimpleFile::DefinedAtomRange defined = file->definedAtoms(); + std::error_code perform(SimpleFile &file) override { + SimpleFile::DefinedAtomRange defined = file.definedAtoms(); std::sort(defined.begin(), defined.end(), DefinedAtom::compareByPosition); return std::error_code(); } @@ -40,10 +40,8 @@ bool CoreLinkingContext::validateImpl(raw_ostream &) { void CoreLinkingContext::addPasses(PassManager &pm) { for (StringRef name : _passNames) { - if (name.equals("order")) - pm.add(std::unique_ptr<Pass>(new OrderPass())); - else - llvm_unreachable("bad pass name"); + assert(name == "order" && "bad pass name"); + pm.add(std::unique_ptr<Pass>(new OrderPass())); } } diff --git a/lld/lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.cpp b/lld/lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.cpp index 787d11c1303..bf8d6c4e0b8 100644 --- a/lld/lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.cpp +++ b/lld/lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.cpp @@ -256,32 +256,32 @@ public: /// /// After all references are handled, the atoms created during that are all /// added to mf. - std::error_code perform(std::unique_ptr<SimpleFile> &mf) override { + std::error_code perform(SimpleFile &mf) override { ScopedTask task(getDefaultDomain(), "AArch64 GOT/PLT Pass"); DEBUG_WITH_TYPE( "AArch64", llvm::dbgs() << "Undefined Atoms" << "\n"; for (const auto &atom - : mf->undefined()) { + : mf.undefined()) { llvm::dbgs() << " Name of Atom: " << atom->name().str() << "\n"; } llvm::dbgs() << "Shared Library Atoms" << "\n"; for (const auto &atom - : mf->sharedLibrary()) { + : mf.sharedLibrary()) { llvm::dbgs() << " Name of Atom: " << atom->name().str() << "\n"; } llvm::dbgs() << "Absolute Atoms" << "\n"; for (const auto &atom - : mf->absolute()) { + : mf.absolute()) { llvm::dbgs() << " Name of Atom: " << atom->name().str() << "\n"; } // Process all references. llvm::dbgs() << "Defined Atoms" << "\n"); - for (const auto &atom : mf->defined()) { + for (const auto &atom : mf.defined()) { for (const auto &ref : *atom) { handleReference(*atom, *ref); } @@ -291,29 +291,29 @@ public: uint64_t ordinal = 0; if (_plt0) { _plt0->setOrdinal(ordinal++); - mf->addAtom(*_plt0); + mf.addAtom(*_plt0); } for (auto &plt : _pltVector) { plt->setOrdinal(ordinal++); - mf->addAtom(*plt); + mf.addAtom(*plt); } if (_null) { _null->setOrdinal(ordinal++); - mf->addAtom(*_null); + mf.addAtom(*_null); } if (_plt0) { _got0->setOrdinal(ordinal++); _got1->setOrdinal(ordinal++); - mf->addAtom(*_got0); - mf->addAtom(*_got1); + mf.addAtom(*_got0); + mf.addAtom(*_got1); } for (auto &got : _gotVector) { got->setOrdinal(ordinal++); - mf->addAtom(*got); + mf.addAtom(*got); } for (auto obj : _objectVector) { obj->setOrdinal(ordinal++); - mf->addAtom(*obj); + mf.addAtom(*obj); } return std::error_code(); diff --git a/lld/lib/ReaderWriter/ELF/ARM/ARMRelocationPass.cpp b/lld/lib/ReaderWriter/ELF/ARM/ARMRelocationPass.cpp index 4ba02d809f9..fc2ae75cd7a 100644 --- a/lld/lib/ReaderWriter/ELF/ARM/ARMRelocationPass.cpp +++ b/lld/lib/ReaderWriter/ELF/ARM/ARMRelocationPass.cpp @@ -673,35 +673,35 @@ public: /// /// After all references are handled, the atoms created during that are all /// added to mf. - std::error_code perform(std::unique_ptr<SimpleFile> &mf) override { + std::error_code perform(SimpleFile &mf) override { ScopedTask task(getDefaultDomain(), "ARM GOT/PLT Pass"); DEBUG_WITH_TYPE( "ARM", llvm::dbgs() << "Undefined Atoms" << "\n"; for (const auto &atom - : mf->undefined()) { + : mf.undefined()) { llvm::dbgs() << " Name of Atom: " << atom->name().str() << "\n"; } llvm::dbgs() << "Shared Library Atoms" << "\n"; for (const auto &atom - : mf->sharedLibrary()) { + : mf.sharedLibrary()) { llvm::dbgs() << " Name of Atom: " << atom->name().str() << "\n"; } llvm::dbgs() << "Absolute Atoms" << "\n"; for (const auto &atom - : mf->absolute()) { + : mf.absolute()) { llvm::dbgs() << " Name of Atom: " << atom->name().str() << "\n"; } llvm::dbgs() << "Defined Atoms" << "\n"; for (const auto &atom - : mf->defined()) { + : mf.defined()) { llvm::dbgs() << " Name of Atom: " << atom->name().str() << "\n"; }); // Process all references. - for (const auto &atom : mf->defined()) { + for (const auto &atom : mf.defined()) { for (const auto &ref : *atom) { handleReference(*atom, *ref); } @@ -711,53 +711,53 @@ public: uint64_t ordinal = 0; if (_plt0) { _plt0->setOrdinal(ordinal++); - mf->addAtom(*_plt0); + mf.addAtom(*_plt0); _plt0_d->setOrdinal(ordinal++); - mf->addAtom(*_plt0_d); + mf.addAtom(*_plt0_d); } for (auto &pltKV : _pltAtoms) { auto &plt = pltKV.second; if (auto *v = plt._veneer) { v->setOrdinal(ordinal++); - mf->addAtom(*v); + mf.addAtom(*v); } auto *p = plt._plt; p->setOrdinal(ordinal++); - mf->addAtom(*p); + mf.addAtom(*p); } if (_null) { _null->setOrdinal(ordinal++); - mf->addAtom(*_null); + mf.addAtom(*_null); } if (_plt0) { _got0->setOrdinal(ordinal++); - mf->addAtom(*_got0); + mf.addAtom(*_got0); _got1->setOrdinal(ordinal++); - mf->addAtom(*_got1); + mf.addAtom(*_got1); } for (auto &gotKV : _gotAtoms) { auto &got = gotKV.second; got->setOrdinal(ordinal++); - mf->addAtom(*got); + mf.addAtom(*got); } for (auto &gotKV : _gotpltAtoms) { auto &got = gotKV.second; got->setOrdinal(ordinal++); - mf->addAtom(*got); + mf.addAtom(*got); } for (auto &objectKV : _objectAtoms) { auto &obj = objectKV.second; obj->setOrdinal(ordinal++); - mf->addAtom(*obj); + mf.addAtom(*obj); } for (auto &veneerKV : _veneerAtoms) { auto &veneer = veneerKV.second; auto *m = veneer._mapping; m->setOrdinal(ordinal++); - mf->addAtom(*m); + mf.addAtom(*m); auto *v = veneer._veneer; v->setOrdinal(ordinal++); - mf->addAtom(*v); + mf.addAtom(*v); } return std::error_code(); diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp index f835eb6683d..6c0360c310f 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp @@ -169,9 +169,9 @@ public: /// /// After all references are handled, the atoms created during that are all /// added to mf. - std::error_code perform(std::unique_ptr<SimpleFile> &mf) override { + std::error_code perform(SimpleFile &mf) override { // Process all references. - for (const auto &atom : mf->defined()) + for (const auto &atom : mf.defined()) for (const auto &ref : *atom) handleReference(*atom, *ref); @@ -179,23 +179,23 @@ public: uint64_t ordinal = 0; if (_plt0) { _plt0->setOrdinal(ordinal++); - mf->addAtom(*_plt0); + mf.addAtom(*_plt0); } for (auto &plt : _pltVector) { plt->setOrdinal(ordinal++); - mf->addAtom(*plt); + mf.addAtom(*plt); } if (_null) { _null->setOrdinal(ordinal++); - mf->addAtom(*_null); + mf.addAtom(*_null); } if (_got0) { _got0->setOrdinal(ordinal++); - mf->addAtom(*_got0); + mf.addAtom(*_got0); } for (auto &got : _gotVector) { got->setOrdinal(ordinal++); - mf->addAtom(*got); + mf.addAtom(*got); } return std::error_code(); diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsCtorsOrderPass.cpp b/lld/lib/ReaderWriter/ELF/Mips/MipsCtorsOrderPass.cpp index 276d87dc193..a7062813df4 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsCtorsOrderPass.cpp +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsCtorsOrderPass.cpp @@ -49,8 +49,8 @@ static int32_t getSectionPriority(StringRef path, StringRef sectionName) { return priority; } -std::error_code MipsCtorsOrderPass::perform(std::unique_ptr<SimpleFile> &f) { - auto definedAtoms = f->definedAtoms(); +std::error_code MipsCtorsOrderPass::perform(SimpleFile &f) { + auto definedAtoms = f.definedAtoms(); auto last = std::stable_partition(definedAtoms.begin(), definedAtoms.end(), [](const DefinedAtom *atom) { diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsCtorsOrderPass.h b/lld/lib/ReaderWriter/ELF/Mips/MipsCtorsOrderPass.h index 65c9d9b90d5..5b12b7de0fa 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsCtorsOrderPass.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsCtorsOrderPass.h @@ -17,7 +17,7 @@ namespace elf { /// \brief This pass sorts atoms in .{ctors,dtors}.<priority> sections. class MipsCtorsOrderPass : public Pass { public: - std::error_code perform(std::unique_ptr<SimpleFile> &mergedFile) override; + std::error_code perform(SimpleFile &mergedFile) override; }; } } diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp b/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp index f4f0a8acd93..493b41abee1 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp @@ -302,7 +302,7 @@ template <typename ELFT> class RelocationPass : public Pass { public: RelocationPass(MipsLinkingContext &ctx); - std::error_code perform(std::unique_ptr<SimpleFile> &mf) override; + std::error_code perform(SimpleFile &mf) override; private: /// \brief Reference to the linking context. @@ -428,14 +428,14 @@ RelocationPass<ELFT>::RelocationPass(MipsLinkingContext &ctx) } template <typename ELFT> -std::error_code RelocationPass<ELFT>::perform(std::unique_ptr<SimpleFile> &mf) { - for (const auto &atom : mf->defined()) +std::error_code RelocationPass<ELFT>::perform(SimpleFile &mf) { + for (const auto &atom : mf.defined()) for (const auto &ref : *atom) collectReferenceInfo(*cast<MipsELFDefinedAtom<ELFT>>(atom), const_cast<Reference &>(*ref)); // Process all references. - for (const auto &atom : mf->defined()) + for (const auto &atom : mf.defined()) for (const auto &ref : *atom) handleReference(*cast<MipsELFDefinedAtom<ELFT>>(atom), const_cast<Reference &>(*ref)); @@ -457,22 +457,22 @@ std::error_code RelocationPass<ELFT>::perform(std::unique_ptr<SimpleFile> &mf) { !_tlsGotVector.empty()) { SimpleDefinedAtom *ga = new (_file._alloc) MipsGlobalOffsetTableAtom(_file); ga->setOrdinal(ordinal++); - mf->addAtom(*ga); + mf.addAtom(*ga); } for (auto &got : _localGotVector) { got->setOrdinal(ordinal++); - mf->addAtom(*got); + mf.addAtom(*got); } for (auto &got : _globalGotVector) { got->setOrdinal(ordinal++); - mf->addAtom(*got); + mf.addAtom(*got); } for (auto &got : _tlsGotVector) { got->setOrdinal(ordinal++); - mf->addAtom(*got); + mf.addAtom(*got); } // Create and emit PLT0 entry. @@ -484,19 +484,19 @@ std::error_code RelocationPass<ELFT>::perform(std::unique_ptr<SimpleFile> &mf) { if (plt0Atom) { plt0Atom->setOrdinal(ordinal++); - mf->addAtom(*plt0Atom); + mf.addAtom(*plt0Atom); } // Emit regular PLT entries firts. for (auto &plt : _pltRegVector) { plt->setOrdinal(ordinal++); - mf->addAtom(*plt); + mf.addAtom(*plt); } // microMIPS PLT entries come after regular ones. for (auto &plt : _pltMicroVector) { plt->setOrdinal(ordinal++); - mf->addAtom(*plt); + mf.addAtom(*plt); } // Assign PLT0 to GOTPLT entries. @@ -506,17 +506,17 @@ std::error_code RelocationPass<ELFT>::perform(std::unique_ptr<SimpleFile> &mf) { for (auto &gotplt : _gotpltVector) { gotplt->setOrdinal(ordinal++); - mf->addAtom(*gotplt); + mf.addAtom(*gotplt); } for (auto obj : _objectVector) { obj->setOrdinal(ordinal++); - mf->addAtom(*obj); + mf.addAtom(*obj); } for (auto la25 : _la25Vector) { la25->setOrdinal(ordinal++); - mf->addAtom(*la25); + mf.addAtom(*la25); } return std::error_code(); diff --git a/lld/lib/ReaderWriter/ELF/OrderPass.h b/lld/lib/ReaderWriter/ELF/OrderPass.h index 4b4e2b16af5..11f88056c8c 100644 --- a/lld/lib/ReaderWriter/ELF/OrderPass.h +++ b/lld/lib/ReaderWriter/ELF/OrderPass.h @@ -19,8 +19,8 @@ namespace elf { /// \brief This pass sorts atoms by file and atom ordinals. class OrderPass : public Pass { public: - std::error_code perform(std::unique_ptr<SimpleFile> &file) override { - parallel_sort(file->definedAtoms().begin(), file->definedAtoms().end(), + std::error_code perform(SimpleFile &file) override { + parallel_sort(file.definedAtoms().begin(), file.definedAtoms().end(), DefinedAtom::compareByPosition); return std::error_code(); } diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp b/lld/lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp index 10b6d4c15f1..a2f10dc08a4 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp @@ -254,10 +254,10 @@ public: /// /// After all references are handled, the atoms created during that are all /// added to mf. - std::error_code perform(std::unique_ptr<SimpleFile> &mf) override { + std::error_code perform(SimpleFile &mf) override { ScopedTask task(getDefaultDomain(), "X86-64 GOT/PLT Pass"); // Process all references. - for (const auto &atom : mf->defined()) + for (const auto &atom : mf.defined()) for (const auto &ref : *atom) handleReference(*atom, *ref); @@ -265,33 +265,33 @@ public: uint64_t ordinal = 0; if (_plt0) { _plt0->setOrdinal(ordinal++); - mf->addAtom(*_plt0); + mf.addAtom(*_plt0); } for (auto &plt : _pltVector) { plt->setOrdinal(ordinal++); - mf->addAtom(*plt); + mf.addAtom(*plt); } if (_null) { _null->setOrdinal(ordinal++); - mf->addAtom(*_null); + mf.addAtom(*_null); } if (_plt0) { _got0->setOrdinal(ordinal++); _got1->setOrdinal(ordinal++); - mf->addAtom(*_got0); - mf->addAtom(*_got1); + mf.addAtom(*_got0); + mf.addAtom(*_got1); } for (auto &got : _gotVector) { got->setOrdinal(ordinal++); - mf->addAtom(*got); + mf.addAtom(*got); } for (auto &got : _tlsGotVector) { got->setOrdinal(ordinal++); - mf->addAtom(*got); + mf.addAtom(*got); } for (auto obj : _objectVector) { obj->setOrdinal(ordinal++); - mf->addAtom(*obj); + mf.addAtom(*obj); } return std::error_code(); } diff --git a/lld/lib/ReaderWriter/MachO/CompactUnwindPass.cpp b/lld/lib/ReaderWriter/MachO/CompactUnwindPass.cpp index 97925f3d1fe..c194318f8c9 100644 --- a/lld/lib/ReaderWriter/MachO/CompactUnwindPass.cpp +++ b/lld/lib/ReaderWriter/MachO/CompactUnwindPass.cpp @@ -277,7 +277,7 @@ public: _isBig(MachOLinkingContext::isBigEndian(_ctx.arch())) {} private: - std::error_code perform(std::unique_ptr<SimpleFile> &mergedFile) override { + std::error_code perform(SimpleFile &mergedFile) override { DEBUG(llvm::dbgs() << "MachO Compact Unwind pass\n"); std::map<const Atom *, CompactUnwindEntry> unwindLocs; @@ -342,10 +342,10 @@ private: UnwindInfoAtom *unwind = new (_file.allocator()) UnwindInfoAtom(_archHandler, _file, _isBig, personalities, commonEncodings, pages, numLSDAs); - mergedFile->addAtom(*unwind); + mergedFile.addAtom(*unwind); // Finally, remove all __compact_unwind atoms now that we've processed them. - mergedFile->removeDefinedAtomsIf([](const DefinedAtom *atom) { + mergedFile.removeDefinedAtomsIf([](const DefinedAtom *atom) { return atom->contentType() == DefinedAtom::typeCompactUnwindInfo; }); @@ -353,12 +353,12 @@ private: } void collectCompactUnwindEntries( - std::unique_ptr<SimpleFile> &mergedFile, + const SimpleFile &mergedFile, std::map<const Atom *, CompactUnwindEntry> &unwindLocs, std::vector<const Atom *> &personalities, uint32_t &numLSDAs) { DEBUG(llvm::dbgs() << " Collecting __compact_unwind entries\n"); - for (const DefinedAtom *atom : mergedFile->defined()) { + for (const DefinedAtom *atom : mergedFile.defined()) { if (atom->contentType() != DefinedAtom::typeCompactUnwindInfo) continue; @@ -424,9 +424,9 @@ private: } void - collectDwarfFrameEntries(std::unique_ptr<SimpleFile> &mergedFile, + collectDwarfFrameEntries(const SimpleFile &mergedFile, std::map<const Atom *, const Atom *> &dwarfFrames) { - for (const DefinedAtom *ehFrameAtom : mergedFile->defined()) { + for (const DefinedAtom *ehFrameAtom : mergedFile.defined()) { if (ehFrameAtom->contentType() != DefinedAtom::typeCFI) continue; if (ArchHandler::isDwarfCIE(_isBig, ehFrameAtom)) @@ -444,7 +444,7 @@ private: /// + A synthesised reference to __eh_frame if there's no __compact_unwind /// or too many personality functions to be accommodated. std::vector<CompactUnwindEntry> createUnwindInfoEntries( - const std::unique_ptr<SimpleFile> &mergedFile, + const SimpleFile &mergedFile, const std::map<const Atom *, CompactUnwindEntry> &unwindLocs, const std::vector<const Atom *> &personalities, const std::map<const Atom *, const Atom *> &dwarfFrames) { @@ -454,7 +454,7 @@ private: // The final order in the __unwind_info section must be derived from the // order of typeCode atoms, since that's how they'll be put into the object // file eventually (yuck!). - for (const DefinedAtom *atom : mergedFile->defined()) { + for (const DefinedAtom *atom : mergedFile.defined()) { if (atom->contentType() != DefinedAtom::typeCode) continue; diff --git a/lld/lib/ReaderWriter/MachO/GOTPass.cpp b/lld/lib/ReaderWriter/MachO/GOTPass.cpp index 28e1c8abc28..ab8c4403231 100644 --- a/lld/lib/ReaderWriter/MachO/GOTPass.cpp +++ b/lld/lib/ReaderWriter/MachO/GOTPass.cpp @@ -96,9 +96,9 @@ public: _file("<mach-o GOT Pass>") {} private: - std::error_code perform(std::unique_ptr<SimpleFile> &mergedFile) override { + std::error_code perform(SimpleFile &mergedFile) override { // Scan all references in all atoms. - for (const DefinedAtom *atom : mergedFile->defined()) { + for (const DefinedAtom *atom : mergedFile.defined()) { for (const Reference *ref : *atom) { // Look at instructions accessing the GOT. bool canBypassGOT; @@ -130,7 +130,7 @@ private: return (left->slotName().compare(right->slotName()) < 0); }); for (const GOTEntryAtom *slot : entries) - mergedFile->addAtom(*slot); + mergedFile.addAtom(*slot); return std::error_code(); } diff --git a/lld/lib/ReaderWriter/MachO/LayoutPass.cpp b/lld/lib/ReaderWriter/MachO/LayoutPass.cpp index c523470c191..071a0dc3d9a 100644 --- a/lld/lib/ReaderWriter/MachO/LayoutPass.cpp +++ b/lld/lib/ReaderWriter/MachO/LayoutPass.cpp @@ -437,10 +437,10 @@ void LayoutPass::undecorate(SimpleFile::DefinedAtomRange &atomRange, } /// Perform the actual pass -std::error_code LayoutPass::perform(std::unique_ptr<SimpleFile> &mergedFile) { +std::error_code LayoutPass::perform(SimpleFile &mergedFile) { // sort the atoms ScopedTask task(getDefaultDomain(), "LayoutPass"); - SimpleFile::DefinedAtomRange atomRange = mergedFile->definedAtoms(); + SimpleFile::DefinedAtomRange atomRange = mergedFile.definedAtoms(); // Build follow on tables buildFollowOnTable(atomRange); diff --git a/lld/lib/ReaderWriter/MachO/LayoutPass.h b/lld/lib/ReaderWriter/MachO/LayoutPass.h index be061d91c42..f7da420f82a 100644 --- a/lld/lib/ReaderWriter/MachO/LayoutPass.h +++ b/lld/lib/ReaderWriter/MachO/LayoutPass.h @@ -46,7 +46,7 @@ public: LayoutPass(const Registry ®istry, SortOverride sorter); /// Sorts atoms in mergedFile by content type then by command line order. - std::error_code perform(std::unique_ptr<SimpleFile> &mergedFile) override; + std::error_code perform(SimpleFile &mergedFile) override; virtual ~LayoutPass() {} diff --git a/lld/lib/ReaderWriter/MachO/ShimPass.cpp b/lld/lib/ReaderWriter/MachO/ShimPass.cpp index 24e1937de92..df29e37c183 100644 --- a/lld/lib/ReaderWriter/MachO/ShimPass.cpp +++ b/lld/lib/ReaderWriter/MachO/ShimPass.cpp @@ -44,9 +44,9 @@ public: : _ctx(context), _archHandler(_ctx.archHandler()), _stubInfo(_archHandler.stubInfo()), _file("<mach-o shim pass>") {} - std::error_code perform(std::unique_ptr<SimpleFile> &mergedFile) override { + std::error_code perform(SimpleFile &mergedFile) override { // Scan all references in all atoms. - for (const DefinedAtom *atom : mergedFile->defined()) { + for (const DefinedAtom *atom : mergedFile.defined()) { for (const Reference *ref : *atom) { // Look at non-call branches. if (!_archHandler.isNonCallBranch(*ref)) @@ -77,9 +77,8 @@ public: }); // Add all shims to master file. - for (const DefinedAtom *shim : shims) { - mergedFile->addAtom(*shim); - } + for (const DefinedAtom *shim : shims) + mergedFile.addAtom(*shim); return std::error_code(); } diff --git a/lld/lib/ReaderWriter/MachO/StubsPass.cpp b/lld/lib/ReaderWriter/MachO/StubsPass.cpp index 25fccfd3114..8eee9e6febe 100644 --- a/lld/lib/ReaderWriter/MachO/StubsPass.cpp +++ b/lld/lib/ReaderWriter/MachO/StubsPass.cpp @@ -209,13 +209,13 @@ public: : _ctx(context), _archHandler(_ctx.archHandler()), _stubInfo(_archHandler.stubInfo()), _file("<mach-o Stubs pass>") {} - std::error_code perform(std::unique_ptr<SimpleFile> &mergedFile) override { + std::error_code perform(SimpleFile &mergedFile) override { // Skip this pass if output format uses text relocations instead of stubs. if (!this->noTextRelocs()) return std::error_code(); // Scan all references in all atoms. - for (const DefinedAtom *atom : mergedFile->defined()) { + for (const DefinedAtom *atom : mergedFile.defined()) { for (const Reference *ref : *atom) { // Look at call-sites. if (!this->isCallSite(*ref)) @@ -258,17 +258,18 @@ public: addOptReference( helperCommonAtom, _stubInfo.stubHelperCommonReferenceToBinder, _stubInfo.optStubHelperCommonReferenceToBinder, helperBinderNLPAtom); - mergedFile->addAtom(*helperCommonAtom); - mergedFile->addAtom(*helperBinderNLPAtom); - mergedFile->addAtom(*helperCacheNLPAtom); + mergedFile.addAtom(*helperCommonAtom); + mergedFile.addAtom(*helperBinderNLPAtom); + mergedFile.addAtom(*helperCacheNLPAtom); // Add reference to dyld_stub_binder in libSystem.dylib auto I = std::find_if( - mergedFile->sharedLibrary().begin(), mergedFile->sharedLibrary().end(), + mergedFile.sharedLibrary().begin(), mergedFile.sharedLibrary().end(), [&](const SharedLibraryAtom *atom) { return atom->name().equals(_stubInfo.binderSymbolName); }); - assert(I != mergedFile->sharedLibrary().end() && "dyld_stub_binder not found"); + assert(I != mergedFile.sharedLibrary().end() && + "dyld_stub_binder not found"); addReference(helperBinderNLPAtom, _stubInfo.nonLazyPointerReferenceToBinder, *I); // Sort targets by name, so stubs and lazy pointers are consistent @@ -300,9 +301,9 @@ public: addReference(helper, _stubInfo.stubHelperReferenceToHelperCommon, helperCommonAtom); - mergedFile->addAtom(*stub); - mergedFile->addAtom(*lp); - mergedFile->addAtom(*helper); + mergedFile.addAtom(*stub); + mergedFile.addAtom(*lp); + mergedFile.addAtom(*helper); // Update each reference to use stub. for (const Reference *ref : _targetToUses[target]) { diff --git a/lld/lib/ReaderWriter/PECOFF/EdataPass.cpp b/lld/lib/ReaderWriter/PECOFF/EdataPass.cpp index c42d6ecf185..723f79a3621 100644 --- a/lld/lib/ReaderWriter/PECOFF/EdataPass.cpp +++ b/lld/lib/ReaderWriter/PECOFF/EdataPass.cpp @@ -78,10 +78,10 @@ static void assignOrdinals(PECOFFLinkingContext &ctx) { desc.ordinal = nextOrdinal++; } -static bool getExportedAtoms(PECOFFLinkingContext &ctx, SimpleFile *file, +static bool getExportedAtoms(PECOFFLinkingContext &ctx, const SimpleFile &file, std::vector<TableEntry> &ret) { std::map<StringRef, const DefinedAtom *> definedAtoms; - for (const DefinedAtom *atom : file->defined()) + for (const DefinedAtom *atom : file.defined()) definedAtoms[atom->name()] = atom; for (PECOFFLinkingContext::ExportDesc &desc : ctx.getDllExports()) { @@ -175,12 +175,12 @@ EdataPass::createOrdinalTable(const std::vector<TableEntry> &entries, return ret; } -std::error_code EdataPass::perform(std::unique_ptr<SimpleFile> &file) { +std::error_code EdataPass::perform(SimpleFile &file) { dedupExports(_ctx); assignOrdinals(_ctx); std::vector<TableEntry> entries; - if (!getExportedAtoms(_ctx, file.get(), entries)) + if (!getExportedAtoms(_ctx, file, entries)) return std::error_code(); if (entries.empty()) return std::error_code(); @@ -195,30 +195,30 @@ std::error_code EdataPass::perform(std::unique_ptr<SimpleFile> &file) { EdataAtom *table = createExportDirectoryTable(namedEntries, ordinalBase, maxOrdinal); - file->addAtom(*table); + file.addAtom(*table); COFFStringAtom *dllName = new (_alloc) COFFStringAtom(_file, _stringOrdinal++, ".edata", llvm::sys::path::filename(_ctx.outputPath())); - file->addAtom(*dllName); + file.addAtom(*dllName); addDir32NBReloc(table, dllName, _ctx.getMachineType(), offsetof(export_directory_table_entry, NameRVA)); EdataAtom *addressTable = createAddressTable(entries, ordinalBase, maxOrdinal); - file->addAtom(*addressTable); + file.addAtom(*addressTable); addDir32NBReloc( table, addressTable, _ctx.getMachineType(), offsetof(export_directory_table_entry, ExportAddressTableRVA)); EdataAtom *namePointerTable = - createNamePointerTable(_ctx, namedEntries, file.get()); - file->addAtom(*namePointerTable); + createNamePointerTable(_ctx, namedEntries, &file); + file.addAtom(*namePointerTable); addDir32NBReloc(table, namePointerTable, _ctx.getMachineType(), offsetof(export_directory_table_entry, NamePointerRVA)); EdataAtom *ordinalTable = createOrdinalTable(namedEntries, ordinalBase); - file->addAtom(*ordinalTable); + file.addAtom(*ordinalTable); addDir32NBReloc(table, ordinalTable, _ctx.getMachineType(), offsetof(export_directory_table_entry, OrdinalTableRVA)); diff --git a/lld/lib/ReaderWriter/PECOFF/EdataPass.h b/lld/lib/ReaderWriter/PECOFF/EdataPass.h index 94ba705ff71..f88022ee723 100644 --- a/lld/lib/ReaderWriter/PECOFF/EdataPass.h +++ b/lld/lib/ReaderWriter/PECOFF/EdataPass.h @@ -66,7 +66,7 @@ public: EdataPass(PECOFFLinkingContext &ctx) : _ctx(ctx), _file(ctx), _is64(ctx.is64Bit()), _stringOrdinal(1024) {} - std::error_code perform(std::unique_ptr<SimpleFile> &file) override; + std::error_code perform(SimpleFile &file) override; private: edata::EdataAtom * diff --git a/lld/lib/ReaderWriter/PECOFF/IdataPass.cpp b/lld/lib/ReaderWriter/PECOFF/IdataPass.cpp index 37b0030422c..aa1410a3640 100644 --- a/lld/lib/ReaderWriter/PECOFF/IdataPass.cpp +++ b/lld/lib/ReaderWriter/PECOFF/IdataPass.cpp @@ -287,13 +287,13 @@ DelayLoaderAtom::createContent(MachineTypes machine) const { } // namespace idata -std::error_code IdataPass::perform(std::unique_ptr<SimpleFile> &file) { - if (file->sharedLibrary().empty()) +std::error_code IdataPass::perform(SimpleFile &file) { + if (file.sharedLibrary().empty()) return std::error_code(); - idata::IdataContext context(*file, _dummyFile, _ctx); + idata::IdataContext context(file, _dummyFile, _ctx); std::map<StringRef, std::vector<COFFSharedLibraryAtom *>> sharedAtoms = - groupByLoadName(*file); + groupByLoadName(file); bool hasImports = false; bool hasDelayImports = false; @@ -321,7 +321,7 @@ std::error_code IdataPass::perform(std::unique_ptr<SimpleFile> &file) { if (hasDelayImports) new (_alloc) idata::DelayNullImportDirectoryAtom(context); - replaceSharedLibraryAtoms(*file); + replaceSharedLibraryAtoms(&file); return std::error_code(); } @@ -342,8 +342,8 @@ IdataPass::groupByLoadName(SimpleFile &file) { } /// Transforms a reference to a COFFSharedLibraryAtom to a real reference. -void IdataPass::replaceSharedLibraryAtoms(SimpleFile &file) { - for (const DefinedAtom *atom : file.defined()) { +void IdataPass::replaceSharedLibraryAtoms(SimpleFile *file) { + for (const DefinedAtom *atom : file->defined()) { for (const Reference *ref : *atom) { const Atom *target = ref->target(); auto *sharedAtom = dyn_cast<SharedLibraryAtom>(target); diff --git a/lld/lib/ReaderWriter/PECOFF/IdataPass.h b/lld/lib/ReaderWriter/PECOFF/IdataPass.h index ccc59bcb576..4bde49b27c6 100644 --- a/lld/lib/ReaderWriter/PECOFF/IdataPass.h +++ b/lld/lib/ReaderWriter/PECOFF/IdataPass.h @@ -195,13 +195,13 @@ class IdataPass : public lld::Pass { public: IdataPass(const PECOFFLinkingContext &ctx) : _dummyFile(ctx), _ctx(ctx) {} - std::error_code perform(std::unique_ptr<SimpleFile> &file) override; + std::error_code perform(SimpleFile &file) override; private: std::map<StringRef, std::vector<COFFSharedLibraryAtom *>> groupByLoadName(SimpleFile &file); - void replaceSharedLibraryAtoms(SimpleFile &file); + void replaceSharedLibraryAtoms(SimpleFile *file); // A dummy file with which all the atoms created in the pass will be // associated. Atoms need to be associated to an input file even if it's not diff --git a/lld/lib/ReaderWriter/PECOFF/InferSubsystemPass.h b/lld/lib/ReaderWriter/PECOFF/InferSubsystemPass.h index 33bea44f255..052b35fd451 100644 --- a/lld/lib/ReaderWriter/PECOFF/InferSubsystemPass.h +++ b/lld/lib/ReaderWriter/PECOFF/InferSubsystemPass.h @@ -22,7 +22,7 @@ class InferSubsystemPass : public lld::Pass { public: InferSubsystemPass(PECOFFLinkingContext &ctx) : _ctx(ctx) {} - std::error_code perform(std::unique_ptr<SimpleFile> &file) override { + std::error_code perform(SimpleFile &file) override { if (_ctx.getSubsystem() != WindowsSubsystem::IMAGE_SUBSYSTEM_UNKNOWN) return std::error_code(); @@ -41,7 +41,7 @@ public: const std::string main = _ctx.decorateSymbol("mainCRTStartup"); const std::string mainAt = _ctx.decorateSymbol("mainCRTStartup@"); - for (const DefinedAtom *atom : file->definedAtoms()) { + for (const DefinedAtom *atom : file.definedAtoms()) { if (atom->name() == wWinMain || atom->name().startswith(wWinMainAt) || atom->name() == winMain || atom->name().startswith(winMainAt)) { _ctx.setSubsystem(WindowsSubsystem::IMAGE_SUBSYSTEM_WINDOWS_GUI); diff --git a/lld/lib/ReaderWriter/PECOFF/LoadConfigPass.cpp b/lld/lib/ReaderWriter/PECOFF/LoadConfigPass.cpp index bebe26bf825..a67416d82ae 100644 --- a/lld/lib/ReaderWriter/PECOFF/LoadConfigPass.cpp +++ b/lld/lib/ReaderWriter/PECOFF/LoadConfigPass.cpp @@ -49,14 +49,14 @@ LoadConfigAtom::LoadConfigAtom(VirtualFile &file, const DefinedAtom *sxdata, } // namespace loadcfg -std::error_code LoadConfigPass::perform(std::unique_ptr<SimpleFile> &file) { +std::error_code LoadConfigPass::perform(SimpleFile &file) { if (_ctx.noSEH()) return std::error_code(); // Find the first atom in .sxdata section. const DefinedAtom *sxdata = nullptr; int sectionSize = 0; - for (const DefinedAtom *atom : file->defined()) { + for (const DefinedAtom *atom : file.defined()) { if (atom->customSectionName() == ".sxdata") { if (!sxdata) sxdata = atom; @@ -68,7 +68,7 @@ std::error_code LoadConfigPass::perform(std::unique_ptr<SimpleFile> &file) { auto *loadcfg = new (_alloc) loadcfg::LoadConfigAtom(_file, sxdata, sectionSize / sizeof(uint32_t)); - file->addAtom(*loadcfg); + file.addAtom(*loadcfg); return std::error_code(); } diff --git a/lld/lib/ReaderWriter/PECOFF/LoadConfigPass.h b/lld/lib/ReaderWriter/PECOFF/LoadConfigPass.h index a3c704a7ea3..d66a02bb9a9 100644 --- a/lld/lib/ReaderWriter/PECOFF/LoadConfigPass.h +++ b/lld/lib/ReaderWriter/PECOFF/LoadConfigPass.h @@ -49,7 +49,7 @@ class LoadConfigPass : public lld::Pass { public: LoadConfigPass(PECOFFLinkingContext &ctx) : _ctx(ctx), _file(ctx) {} - std::error_code perform(std::unique_ptr<SimpleFile> &file) override; + std::error_code perform(SimpleFile &file) override; private: PECOFFLinkingContext &_ctx; diff --git a/lld/lib/ReaderWriter/PECOFF/OrderPass.h b/lld/lib/ReaderWriter/PECOFF/OrderPass.h index 44177283f2a..3adac443a09 100644 --- a/lld/lib/ReaderWriter/PECOFF/OrderPass.h +++ b/lld/lib/ReaderWriter/PECOFF/OrderPass.h @@ -55,8 +55,8 @@ static bool compare(const DefinedAtom *lhs, const DefinedAtom *rhs) { class OrderPass : public lld::Pass { public: - std::error_code perform(std::unique_ptr<SimpleFile> &file) override { - SimpleFile::DefinedAtomRange defined = file->definedAtoms(); + std::error_code perform(SimpleFile &file) override { + SimpleFile::DefinedAtomRange defined = file.definedAtoms(); parallel_sort(defined.begin(), defined.end(), compare); return std::error_code(); } diff --git a/lld/lib/ReaderWriter/PECOFF/PDBPass.h b/lld/lib/ReaderWriter/PECOFF/PDBPass.h index 79a6066fb1c..5dd867df8bc 100644 --- a/lld/lib/ReaderWriter/PECOFF/PDBPass.h +++ b/lld/lib/ReaderWriter/PECOFF/PDBPass.h @@ -21,7 +21,7 @@ class PDBPass : public lld::Pass { public: PDBPass(PECOFFLinkingContext &ctx) : _ctx(ctx) {} - std::error_code perform(std::unique_ptr<SimpleFile> &file) override { + std::error_code perform(SimpleFile &) override { if (_ctx.getDebug()) touch(_ctx.getPDBFilePath()); return std::error_code(); |