From 1f917f69ff07f09b6dbb670971f57f8efe718b84 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Thu, 14 Jul 2022 20:50:02 +0200 Subject: Vendor import of llvm-project main llvmorg-15-init-16436-g18a6ab5b8d1f. --- lld/ELF/OutputSections.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'lld/ELF/OutputSections.cpp') diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index bc940c7e6546..cbde8ac800d3 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -419,7 +419,8 @@ template void OutputSection::writeTo(uint8_t *buf) { } // Write leading padding. - SmallVector sections = getInputSections(*this); + SmallVector storage; + ArrayRef sections = getInputSections(*this, storage); std::array filler = getFiller(); bool nonZeroFiller = read32(filler.data()) != 0; if (nonZeroFiller) @@ -592,12 +593,24 @@ InputSection *elf::getFirstInputSection(const OutputSection *os) { return nullptr; } -SmallVector elf::getInputSections(const OutputSection &os) { - SmallVector ret; - for (SectionCommand *cmd : os.commands) - if (auto *isd = dyn_cast(cmd)) - ret.insert(ret.end(), isd->sections.begin(), isd->sections.end()); - return ret; +ArrayRef +elf::getInputSections(const OutputSection &os, + SmallVector &storage) { + ArrayRef ret; + storage.clear(); + for (SectionCommand *cmd : os.commands) { + auto *isd = dyn_cast(cmd); + if (!isd) + continue; + if (ret.empty()) { + ret = isd->sections; + } else { + if (storage.empty()) + storage.assign(ret.begin(), ret.end()); + storage.insert(storage.end(), isd->sections.begin(), isd->sections.end()); + } + } + return storage.empty() ? ret : makeArrayRef(storage); } // Sorts input sections by section name suffixes, so that .foo.N comes @@ -622,7 +635,8 @@ std::array OutputSection::getFiller() { void OutputSection::checkDynRelAddends(const uint8_t *bufStart) { assert(config->writeAddends && config->checkDynamicRelocs); assert(type == SHT_REL || type == SHT_RELA); - SmallVector sections = getInputSections(*this); + SmallVector storage; + ArrayRef sections = getInputSections(*this, storage); parallelFor(0, sections.size(), [&](size_t i) { // When linking with -r or --emit-relocs we might also call this function // for input .rel[a]. sections which we simply pass through to the -- cgit v1.3