diff options
author | Fangrui Song <i@maskray.me> | 2022-10-16 10:49:48 +0300 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2022-10-16 10:49:48 +0300 |
commit | 14f996dca8a2b5b17d6917528bfd9ee71ba6192a (patch) | |
tree | e1ef1f1e24e10f92600d759147fe3e93d5d94e8f /lld | |
parent | 08901c8a980d98672d456558fac3b2bee990bf61 (diff) |
[ELF] Move inputSections/ehInputSections into Ctx. NFC
Diffstat (limited to 'lld')
-rw-r--r-- | lld/ELF/Arch/PPC64.cpp | 2 | ||||
-rw-r--r-- | lld/ELF/Config.h | 3 | ||||
-rw-r--r-- | lld/ELF/Driver.cpp | 18 | ||||
-rw-r--r-- | lld/ELF/ICF.cpp | 2 | ||||
-rw-r--r-- | lld/ELF/InputSection.cpp | 2 | ||||
-rw-r--r-- | lld/ELF/InputSection.h | 4 | ||||
-rw-r--r-- | lld/ELF/LinkerScript.cpp | 8 | ||||
-rw-r--r-- | lld/ELF/MarkLive.cpp | 10 | ||||
-rw-r--r-- | lld/ELF/SyntheticSections.cpp | 14 | ||||
-rw-r--r-- | lld/ELF/Target.cpp | 2 | ||||
-rw-r--r-- | lld/ELF/Writer.cpp | 38 |
11 files changed, 50 insertions, 53 deletions
diff --git a/lld/ELF/Arch/PPC64.cpp b/lld/ELF/Arch/PPC64.cpp index c2834f0bdee5..b33adefa5396 100644 --- a/lld/ELF/Arch/PPC64.cpp +++ b/lld/ELF/Arch/PPC64.cpp @@ -233,7 +233,7 @@ static void writeSequence(MutableArrayRef<uint32_t> buf, const char *prefix, makeArrayRef(reinterpret_cast<uint8_t *>(buf.data() + first), 4 * (buf.size() - first)), ".text"); - inputSections.push_back(sec); + ctx.inputSections.push_back(sec); for (Defined *sym : defined) { sym->section = sec; sym->value -= 4 * first; diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index c5da9b4a980d..1a69bd867fb4 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -37,6 +37,7 @@ class BitcodeFile; class ELFFileBase; class SharedFile; class InputSectionBase; +class EhInputSection; class Symbol; class BitcodeCompiler; @@ -418,6 +419,8 @@ struct Ctx { SmallVector<BinaryFile *, 0> binaryFiles; SmallVector<BitcodeFile *, 0> bitcodeFiles; SmallVector<BitcodeFile *, 0> lazyBitcodeFiles; + SmallVector<InputSectionBase *, 0> inputSections; + SmallVector<EhInputSection *, 0> ehInputSections; // Duplicate symbol candidates. SmallVector<DuplicateSymbol, 0> duplicates; // Symbols in a non-prevailing COMDAT group which should be changed to an diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 0271f31729c3..dd6a77a6da33 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -95,6 +95,8 @@ void Ctx::reset() { binaryFiles.clear(); bitcodeFiles.clear(); lazyBitcodeFiles.clear(); + inputSections.clear(); + ehInputSections.clear(); duplicates.clear(); nonPrevailingSyms.clear(); whyExtractRecords.clear(); @@ -114,8 +116,6 @@ bool elf::link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS, elf::ctx.reset(); symtab = SymbolTable(); - inputSections.clear(); - ehInputSections.clear(); outputSections.clear(); symAux.clear(); @@ -2013,7 +2013,7 @@ static void replaceCommonSymbols() { auto *bss = make<BssSection>("COMMON", s->size, s->alignment); bss->file = s->file; - inputSections.push_back(bss); + ctx.inputSections.push_back(bss); Defined(s->file, StringRef(), s->binding, s->stOther, s->type, /*value=*/0, s->size, bss) .overwrite(*s); @@ -2702,20 +2702,20 @@ void LinkerDriver::link(opt::InputArgList &args) { if (!s || s == &InputSection::discarded) continue; if (LLVM_UNLIKELY(isa<EhInputSection>(s))) - ehInputSections.push_back(cast<EhInputSection>(s)); + ctx.ehInputSections.push_back(cast<EhInputSection>(s)); else - inputSections.push_back(s); + ctx.inputSections.push_back(s); } } for (BinaryFile *f : ctx.binaryFiles) for (InputSectionBase *s : f->getSections()) - inputSections.push_back(cast<InputSection>(s)); + ctx.inputSections.push_back(cast<InputSection>(s)); } { llvm::TimeTraceScope timeScope("Strip sections"); if (ctx.hasSympart.load(std::memory_order_relaxed)) { - llvm::erase_if(inputSections, [](InputSectionBase *s) { + llvm::erase_if(ctx.inputSections, [](InputSectionBase *s) { if (s->type != SHT_LLVM_SYMPART) return false; invokeELFT(readSymbolPartitionSection, s); @@ -2725,7 +2725,7 @@ void LinkerDriver::link(opt::InputArgList &args) { // We do not want to emit debug sections if --strip-all // or --strip-debug are given. if (config->strip != StripPolicy::None) { - llvm::erase_if(inputSections, [](InputSectionBase *s) { + llvm::erase_if(ctx.inputSections, [](InputSectionBase *s) { if (isDebugSection(*s)) return true; if (auto *isec = dyn_cast<InputSection>(s)) @@ -2782,7 +2782,7 @@ void LinkerDriver::link(opt::InputArgList &args) { // This adds a .comment section containing a version string. if (!config->relocatable) - inputSections.push_back(createCommentSection()); + ctx.inputSections.push_back(createCommentSection()); // Split SHF_MERGE and .eh_frame sections into pieces in preparation for garbage collection. invokeELFT(splitSections); diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index 3e76a9baba9b..169826a3190a 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -477,7 +477,7 @@ template <class ELFT> void ICF<ELFT>::run() { [&](InputSection &s) { s.eqClass[0] = s.eqClass[1] = ++uniqueId; }); // Collect sections to merge. - for (InputSectionBase *sec : inputSections) { + for (InputSectionBase *sec : ctx.inputSections) { auto *s = dyn_cast<InputSection>(sec); if (s && s->eqClass[0] == 0) { if (isEligible(s)) diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index a599786e13fb..aa41da623e17 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -33,8 +33,6 @@ using namespace llvm::sys; using namespace lld; using namespace lld::elf; -SmallVector<InputSectionBase *, 0> elf::inputSections; -SmallVector<EhInputSection *, 0> elf::ehInputSections; DenseSet<std::pair<const Symbol *, uint64_t>> elf::ppc64noTocRelax; // Returns a string to construct an error message. diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index 0663b2763e58..6cb20818d9c4 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -423,10 +423,6 @@ inline bool isDebugSection(const InputSectionBase &sec) { sec.name.startswith(".debug"); } -// The list of all input sections. -extern SmallVector<InputSectionBase *, 0> inputSections; -extern SmallVector<EhInputSection *, 0> ehInputSections; - // The set of TOC entries (.toc + addend) for which we should not apply // toc-indirect to toc-relative relaxation. const Symbol * refers to the // STT_SECTION symbol associated to the .toc input section. diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index e19da00fbde6..7c34f02558fc 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -589,7 +589,7 @@ LinkerScript::createInputSectionList(OutputSection &outCmd) { for (SectionCommand *cmd : outCmd.commands) { if (auto *isd = dyn_cast<InputSectionDescription>(cmd)) { - isd->sectionBases = computeInputSections(isd, inputSections); + isd->sectionBases = computeInputSections(isd, ctx.inputSections); for (InputSectionBase *s : isd->sectionBases) s->parent = &outCmd; ret.insert(ret.end(), isd->sectionBases.begin(), isd->sectionBases.end()); @@ -847,10 +847,10 @@ void LinkerScript::addOrphanSections() { // to create target sections first. We do not want priority handling // for synthetic sections because them are special. size_t n = 0; - for (InputSectionBase *isec : inputSections) { + for (InputSectionBase *isec : ctx.inputSections) { // Process InputSection and MergeInputSection. if (LLVM_LIKELY(isa<InputSection>(isec))) - inputSections[n++] = isec; + ctx.inputSections[n++] = isec; // In -r links, SHF_LINK_ORDER sections are added while adding their parent // sections because we need to know the parent's output section before we @@ -869,7 +869,7 @@ void LinkerScript::addOrphanSections() { add(depSec); } // Keep just InputSection. - inputSections.resize(n); + ctx.inputSections.resize(n); // If no SECTIONS command was given, we should insert sections commands // before others, so that we can handle scripts which refers them, diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index 265424800f68..2b309f00cf8b 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -235,14 +235,14 @@ template <class ELFT> void MarkLive<ELFT>::run() { // that point to .eh_frames. Otherwise, the garbage collector would drop // all of them. We also want to preserve personality routines and LSDA // referenced by .eh_frame sections, so we scan them for that here. - for (EhInputSection *eh : ehInputSections) { + for (EhInputSection *eh : ctx.ehInputSections) { const RelsOrRelas<ELFT> rels = eh->template relsOrRelas<ELFT>(); if (rels.areRelocsRel()) scanEhFrameSection(*eh, rels.rels); else if (rels.relas.size()) scanEhFrameSection(*eh, rels.relas); } - for (InputSectionBase *sec : inputSections) { + for (InputSectionBase *sec : ctx.inputSections) { if (sec->flags & SHF_GNU_RETAIN) { enqueue(sec, 0); continue; @@ -335,7 +335,7 @@ template <class ELFT> void MarkLive<ELFT>::moveToMain() { d->section->isLive()) markSymbol(s); - for (InputSectionBase *sec : inputSections) { + for (InputSectionBase *sec : ctx.inputSections) { if (!sec->isLive() || !isValidCIdentifier(sec->name)) continue; if (symtab.find(("__start_" + sec->name).str()) || @@ -361,7 +361,7 @@ template <class ELFT> void elf::markLive() { return; } - for (InputSectionBase *sec : inputSections) + for (InputSectionBase *sec : ctx.inputSections) sec->markDead(); // Follow the graph to mark all live sections. @@ -376,7 +376,7 @@ template <class ELFT> void elf::markLive() { // Report garbage-collected sections. if (config->printGcSections) - for (InputSectionBase *sec : inputSections) + for (InputSectionBase *sec : ctx.inputSections) if (!sec->isLive()) message("removing unused section " + toString(sec)); } diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 52f8948e8b18..50478e7dcb02 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -107,7 +107,7 @@ std::unique_ptr<MipsAbiFlagsSection<ELFT>> MipsAbiFlagsSection<ELFT>::create() { Elf_Mips_ABIFlags flags = {}; bool create = false; - for (InputSectionBase *sec : inputSections) { + for (InputSectionBase *sec : ctx.inputSections) { if (sec->type != SHT_MIPS_ABIFLAGS) continue; sec->markDead(); @@ -174,7 +174,7 @@ std::unique_ptr<MipsOptionsSection<ELFT>> MipsOptionsSection<ELFT>::create() { return nullptr; SmallVector<InputSectionBase *, 0> sections; - for (InputSectionBase *sec : inputSections) + for (InputSectionBase *sec : ctx.inputSections) if (sec->type == SHT_MIPS_OPTIONS) sections.push_back(sec); @@ -231,7 +231,7 @@ std::unique_ptr<MipsReginfoSection<ELFT>> MipsReginfoSection<ELFT>::create() { return nullptr; SmallVector<InputSectionBase *, 0> sections; - for (InputSectionBase *sec : inputSections) + for (InputSectionBase *sec : ctx.inputSections) if (sec->type == SHT_MIPS_REGINFO) sections.push_back(sec); @@ -2840,7 +2840,7 @@ template <class ELFT> GdbIndexSection *GdbIndexSection::create() { // note that isec->data() may uncompress the full content, which should be // parallelized. SetVector<InputFile *> files; - for (InputSectionBase *s : inputSections) { + for (InputSectionBase *s : ctx.inputSections) { InputSection *isec = dyn_cast<InputSection>(s); if (!isec) continue; @@ -2853,7 +2853,7 @@ template <class ELFT> GdbIndexSection *GdbIndexSection::create() { files.insert(isec->file); } // Drop .rel[a].debug_gnu_pub{names,types} for --emit-relocs. - llvm::erase_if(inputSections, [](InputSectionBase *s) { + llvm::erase_if(ctx.inputSections, [](InputSectionBase *s) { if (auto *isec = dyn_cast<InputSection>(s)) if (InputSectionBase *rel = isec->getRelocatedSection()) return !rel->isLive(); @@ -3309,7 +3309,7 @@ template <class ELFT> void elf::splitSections() { void elf::combineEhSections() { llvm::TimeTraceScope timeScope("Combine EH sections"); - for (EhInputSection *sec : ehInputSections) { + for (EhInputSection *sec : ctx.ehInputSections) { EhFrameSection &eh = *sec->getPartition().ehFrame; sec->parent = &eh; eh.alignment = std::max(eh.alignment, sec->alignment); @@ -3319,7 +3319,7 @@ void elf::combineEhSections() { if (!mainPart->armExidx) return; - llvm::erase_if(inputSections, [](InputSectionBase *s) { + llvm::erase_if(ctx.inputSections, [](InputSectionBase *s) { // Ignore dead sections and the partition end marker (.part.end), // whose partition number is out of bounds. if (!s->isLive() || s->partition == 255) diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index cfc160e0892d..cb3ce6d5ddb4 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -93,7 +93,7 @@ TargetInfo *elf::getTarget() { ErrorPlace elf::getErrorPlace(const uint8_t *loc) { assert(loc != nullptr); - for (InputSectionBase *d : inputSections) { + for (InputSectionBase *d : ctx.inputSections) { auto *isec = dyn_cast<InputSection>(d); if (!isec || !isec->getParent() || (isec->type & SHT_NOBITS)) continue; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index ef80082f4048..918490b972ef 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -121,9 +121,9 @@ static void removeEmptyPTLoad(SmallVector<PhdrEntry *, 0> &phdrs) { void elf::copySectionsIntoPartitions() { SmallVector<InputSectionBase *, 0> newSections; - const size_t ehSize = ehInputSections.size(); + const size_t ehSize = ctx.ehInputSections.size(); for (unsigned part = 2; part != partitions.size() + 1; ++part) { - for (InputSectionBase *s : inputSections) { + for (InputSectionBase *s : ctx.inputSections) { if (!(s->flags & SHF_ALLOC) || !s->isLive() || s->type != SHT_NOTE) continue; auto *copy = make<InputSection>(cast<InputSection>(*s)); @@ -131,15 +131,15 @@ void elf::copySectionsIntoPartitions() { newSections.push_back(copy); } for (size_t i = 0; i != ehSize; ++i) { - assert(ehInputSections[i]->isLive()); - auto *copy = make<EhInputSection>(*ehInputSections[i]); + assert(ctx.ehInputSections[i]->isLive()); + auto *copy = make<EhInputSection>(*ctx.ehInputSections[i]); copy->partition = part; - ehInputSections.push_back(copy); + ctx.ehInputSections.push_back(copy); } } - inputSections.insert(inputSections.end(), newSections.begin(), - newSections.end()); + ctx.inputSections.insert(ctx.inputSections.end(), newSections.begin(), + newSections.end()); } static Defined *addOptionalRegular(StringRef name, SectionBase *sec, @@ -273,11 +273,11 @@ template <class ELFT> void elf::createSyntheticSections() { for (size_t i = 1; i <= partitions.size(); ++i) { InputSection *sec = createInterpSection(); sec->partition = i; - inputSections.push_back(sec); + ctx.inputSections.push_back(sec); } } - auto add = [](SyntheticSection &sec) { inputSections.push_back(&sec); }; + auto add = [](SyntheticSection &sec) { ctx.inputSections.push_back(&sec); }; in.shStrTab = std::make_unique<StringTableSection>(".shstrtab", false); @@ -321,7 +321,7 @@ template <class ELFT> void elf::createSyntheticSections() { for (Partition &part : partitions) { auto add = [&](SyntheticSection &sec) { sec.partition = part.getNumber(); - inputSections.push_back(&sec); + ctx.inputSections.push_back(&sec); }; if (!part.name.empty()) { @@ -1202,7 +1202,7 @@ static void maybeShuffle(DenseMap<const InputSectionBase *, int> &order) { if (config->shuffleSections.empty()) return; - SmallVector<InputSectionBase *, 0> matched, sections = inputSections; + SmallVector<InputSectionBase *, 0> matched, sections = ctx.inputSections; matched.reserve(sections.size()); for (const auto &patAndSeed : config->shuffleSections) { matched.clear(); @@ -1793,23 +1793,23 @@ static void removeUnusedSyntheticSections() { // All input synthetic sections that can be empty are placed after // all regular ones. Reverse iterate to find the first synthetic section // after a non-synthetic one which will be our starting point. - auto start = std::find_if(inputSections.rbegin(), inputSections.rend(), - [](InputSectionBase *s) { - return !isa<SyntheticSection>(s); - }) - .base(); + auto start = + std::find_if( + ctx.inputSections.rbegin(), ctx.inputSections.rend(), + [](InputSectionBase *s) { return !isa<SyntheticSection>(s); }) + .base(); - // Remove unused synthetic sections from inputSections; + // Remove unused synthetic sections from ctx.inputSections; DenseSet<InputSectionBase *> unused; auto end = - std::remove_if(start, inputSections.end(), [&](InputSectionBase *s) { + std::remove_if(start, ctx.inputSections.end(), [&](InputSectionBase *s) { auto *sec = cast<SyntheticSection>(s); if (sec->getParent() && sec->isNeeded()) return false; unused.insert(sec); return true; }); - inputSections.erase(end, inputSections.end()); + ctx.inputSections.erase(end, ctx.inputSections.end()); // Remove unused synthetic sections from the corresponding input section // description and orphanSections. |