Index: lld/ELF/AArch64ErrataFix.h =================================================================== --- lld/ELF/AArch64ErrataFix.h +++ lld/ELF/AArch64ErrataFix.h @@ -19,7 +19,7 @@ class Defined; class InputSection; -struct InputSectionDescription; +struct SectionPattern; class OutputSection; class Patch843419Section; @@ -29,10 +29,9 @@ bool createFixes(); private: - std::vector - patchInputSectionDescription(InputSectionDescription &ISD); + std::vector patchSectionPattern(SectionPattern &Pat); - void insertPatches(InputSectionDescription &ISD, + void insertPatches(SectionPattern &Pat, std::vector &Patches); void init(); Index: lld/ELF/AArch64ErrataFix.cpp =================================================================== --- lld/ELF/AArch64ErrataFix.cpp +++ lld/ELF/AArch64ErrataFix.cpp @@ -479,14 +479,14 @@ } // Insert the PatchSections we have created back into the -// InputSectionDescription. As inserting patches alters the addresses of +// SectionPattern. As inserting patches alters the addresses of // InputSections that follow them, we try and place the patches after all the // executable sections, although we may need to insert them earlier if the -// InputSectionDescription is larger than the maximum branch range. +// SectionPattern is larger than the maximum branch range. void AArch64Err843419Patcher::insertPatches( - InputSectionDescription &ISD, std::vector &Patches) { + SectionPattern &Pat, std::vector &Patches) { uint64_t ISLimit; - uint64_t PrevISLimit = ISD.Sections.front()->OutSecOff; + uint64_t PrevISLimit = Pat.Sections.front()->OutSecOff; uint64_t PatchUpperBound = PrevISLimit + Target->getThunkSectionSpacing(); // Set the OutSecOff of patches to the place where we want to insert them. @@ -494,7 +494,7 @@ // every multiple of maximum branch range. auto PatchIt = Patches.begin(); auto PatchEnd = Patches.end(); - for (const InputSection *IS : ISD.Sections) { + for (const InputSection *IS : Pat.Sections) { ISLimit = IS->OutSecOff + IS->getSize(); if (ISLimit > PatchUpperBound) { while (PatchIt != PatchEnd) { @@ -513,10 +513,10 @@ // merge all patch sections. We use the OutSecOff assigned above to // determine the insertion point. This is ok as we only merge into an - // InputSectionDescription once per pass, and at the end of the pass + // SectionPattern once per pass, and at the end of the pass // assignAddresses() will recalculate all the OutSecOff values. std::vector Tmp; - Tmp.reserve(ISD.Sections.size() + Patches.size()); + Tmp.reserve(Pat.Sections.size() + Patches.size()); auto MergeCmp = [](const InputSection *A, const InputSection *B) { if (A->OutSecOff < B->OutSecOff) return true; @@ -525,9 +525,9 @@ return true; return false; }; - std::merge(ISD.Sections.begin(), ISD.Sections.end(), Patches.begin(), + std::merge(Pat.Sections.begin(), Pat.Sections.end(), Patches.begin(), Patches.end(), std::back_inserter(Tmp), MergeCmp); - ISD.Sections = std::move(Tmp); + Pat.Sections = std::move(Tmp); } // Given an erratum sequence that starts at address AdrpAddr, with an @@ -572,14 +572,13 @@ IS->Relocations.push_back(MakeRelToPatch(PatcheeOffset, PS->PatchSym)); } -// Scan all the instructions in InputSectionDescription, for each instance of +// Scan all the instructions in SectionPattern, for each instance of // the erratum sequence create a Patch843419Section. We return the list of -// Patch843419Sections that need to be applied to ISD. +// Patch843419Sections that need to be applied to Pat. std::vector -AArch64Err843419Patcher::patchInputSectionDescription( - InputSectionDescription &ISD) { +AArch64Err843419Patcher::patchSectionPattern(SectionPattern &Pat) { std::vector Patches; - for (InputSection *IS : ISD.Sections) { + for (InputSection *IS : Pat.Sections) { // LLD doesn't use the erratum sequence in SyntheticSections. if (isa(IS)) continue; @@ -613,10 +612,10 @@ return Patches; } -// For each InputSectionDescription make one pass over the executable sections +// For each SectionPattern make one pass over the executable sections // looking for the erratum sequence; creating a synthetic Patch843419Section // for each instance found. We insert these synthetic patch sections after the -// executable code in each InputSectionDescription. +// executable code in each SectionPattern. // // PreConditions: // The Output and Input Sections have had their final addresses assigned. @@ -634,11 +633,10 @@ if (!(OS->Flags & SHF_ALLOC) || !(OS->Flags & SHF_EXECINSTR)) continue; for (BaseCommand *BC : OS->SectionCommands) - if (auto *ISD = dyn_cast(BC)) { - std::vector Patches = - patchInputSectionDescription(*ISD); + if (auto *Pat = dyn_cast(BC)) { + std::vector Patches = patchSectionPattern(*Pat); if (!Patches.empty()) { - insertPatches(*ISD, Patches); + insertPatches(*Pat, Patches); AddressesChanged = true; } } Index: lld/ELF/Arch/ARM.cpp =================================================================== --- lld/ELF/Arch/ARM.cpp +++ lld/ELF/Arch/ARM.cpp @@ -37,7 +37,7 @@ void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr, int32_t Index, unsigned RelOff) const override; void addPltSymbols(InputSection &IS, uint64_t Off) const override; - void addPltHeaderSymbols(InputSection &ISD) const override; + void addPltHeaderSymbols(InputSection &Pat) const override; bool needsThunk(RelExpr Expr, RelType Type, const InputFile *File, uint64_t BranchAddr, const Symbol &S) const override; uint32_t getThunkSectionSpacing() const override; Index: lld/ELF/LinkerScript.h =================================================================== --- lld/ELF/LinkerScript.h +++ lld/ELF/LinkerScript.h @@ -32,7 +32,6 @@ class Defined; class InputSection; class InputSectionBase; -class InputSectionBase; class OutputSection; class SectionBase; class Symbol; @@ -144,8 +143,8 @@ // This struct represents one section match pattern in SECTIONS() command. // It can optionally have negative match pattern for EXCLUDED_FILE command. // Also it may be surrounded with SORT() command, so contains sorting rules. -struct SectionPattern { - SectionPattern(StringMatcher &&Pat1, StringMatcher &&Pat2) +struct Wildcard { + Wildcard(StringMatcher &&Pat1, StringMatcher &&Pat2) : ExcludedFilePat(Pat1), SectionPat(Pat2) {} StringMatcher ExcludedFilePat; @@ -154,8 +153,13 @@ SortSectionPolicy SortInner; }; -struct InputSectionDescription : BaseCommand { - InputSectionDescription(StringRef FilePattern) +// This class represents the "input section description" which is the most +// common output section command. An example is "*(.text)" which specifies .text +// sections in all input files. +// +// https://sourceware.org/binutils/docs/ld/Input-Section-Basics.html +struct SectionPattern : BaseCommand { + SectionPattern(StringRef FilePattern) : BaseCommand(InputSectionKind), FilePat(FilePattern) {} static bool classof(const BaseCommand *C) { @@ -164,9 +168,9 @@ StringMatcher FilePat; - // Input sections that matches at least one of SectionPatterns - // will be associated with this InputSectionDescription. - std::vector SectionPatterns; + // Input sections that matches at least one of Wildcards + // will be associated with this SectionPattern. + std::vector Wildcards; std::vector Sections; @@ -226,8 +230,7 @@ void expandOutputSection(uint64_t Size); void expandMemoryRegions(uint64_t Size); - std::vector - computeInputSections(const InputSectionDescription *); + std::vector computeInputSections(const SectionPattern *); std::vector createInputSectionList(OutputSection &Cmd); @@ -290,7 +293,7 @@ // List of section patterns specified with KEEP commands. They will // be kept even if they are unused and --gc-sections is specified. - std::vector KeptSections; + std::vector KeptSections; // A map from memory region name to a memory region descriptor. llvm::MapVector MemoryRegions; Index: lld/ELF/LinkerScript.cpp =================================================================== --- lld/ELF/LinkerScript.cpp +++ lld/ELF/LinkerScript.cpp @@ -298,9 +298,9 @@ if (KeptSections.empty()) return false; std::string Filename = getFilename(S->File); - for (InputSectionDescription *ID : KeptSections) + for (SectionPattern *ID : KeptSections) if (ID->FilePat.match(Filename)) - for (SectionPattern &P : ID->SectionPatterns) + for (Wildcard &P : ID->Wildcards) if (P.SectionPat.match(S->Name)) return true; return false; @@ -361,7 +361,7 @@ // 3. If one SORT command is given, and if it is SORT_NONE, don't sort. // 4. If no SORT command is given, sort according to --sort-section. static void sortInputSections(MutableArrayRef Vec, - const SectionPattern &Pat) { + const Wildcard &Pat) { if (Pat.SortOuter == SortSectionPolicy::None) return; @@ -372,13 +372,13 @@ sortSections(Vec, Pat.SortOuter); } -// Compute and remember which sections the InputSectionDescription matches. +// Compute and remember which sections the SectionPattern matches. std::vector -LinkerScript::computeInputSections(const InputSectionDescription *Cmd) { +LinkerScript::computeInputSections(const SectionPattern *Cmd) { std::vector Ret; // Collects all sections that satisfy constraints of Cmd. - for (const SectionPattern &Pat : Cmd->SectionPatterns) { + for (const Wildcard &Pat : Cmd->Wildcards) { size_t SizeBefore = Ret.size(); for (InputSectionBase *Sec : InputSections) { @@ -439,7 +439,7 @@ std::vector Ret; for (BaseCommand *Base : OutCmd.SectionCommands) { - if (auto *Cmd = dyn_cast(Base)) { + if (auto *Cmd = dyn_cast(Base)) { Cmd->Sections = computeInputSections(Cmd); Ret.insert(Ret.end(), Cmd->Sections.begin(), Cmd->Sections.end()); } @@ -818,7 +818,7 @@ // Handle a single input section description command. // It calculates and assigns the offsets for each section and also // updates the output section size. - for (InputSection *Sec : cast(Base)->Sections) + for (InputSection *Sec : cast(Base)->Sections) output(Sec); } } @@ -842,7 +842,7 @@ if (Cmd->Name != "." && !Cmd->Sym) continue; - if (!isa(*Base)) + if (!isa(*Base)) return false; } return true; Index: lld/ELF/MapFile.cpp =================================================================== --- lld/ELF/MapFile.cpp +++ lld/ELF/MapFile.cpp @@ -179,8 +179,8 @@ // Dump symbols for each input section. for (BaseCommand *Base : OSec->SectionCommands) { - if (auto *ISD = dyn_cast(Base)) { - for (InputSection *IS : ISD->Sections) { + if (auto *Pat = dyn_cast(Base)) { + for (InputSection *IS : Pat->Sections) { if (IS == In.EhFrame) { printEhFrame(OS, OSec); continue; Index: lld/ELF/OutputSections.cpp =================================================================== --- lld/ELF/OutputSections.cpp +++ lld/ELF/OutputSections.cpp @@ -129,11 +129,10 @@ if (!IS->Assigned) { IS->Assigned = true; - if (SectionCommands.empty() || - !isa(SectionCommands.back())) - SectionCommands.push_back(make("")); - auto *ISD = cast(SectionCommands.back()); - ISD->Sections.push_back(IS); + if (SectionCommands.empty() || !isa(SectionCommands.back())) + SectionCommands.push_back(make("")); + auto *Pat = cast(SectionCommands.back()); + Pat->Sections.push_back(IS); } } @@ -164,8 +163,8 @@ void OutputSection::sort(llvm::function_ref Order) { assert(Live); for (BaseCommand *B : SectionCommands) - if (auto *ISD = dyn_cast(B)) - sortByOrder(ISD->Sections, Order); + if (auto *Pat = dyn_cast(B)) + sortByOrder(Pat->Sections, Order); } // Fill [Buf, Buf + Size) with Filler. @@ -369,8 +368,8 @@ // Read the comment above. void OutputSection::sortCtorsDtors() { assert(SectionCommands.size() == 1); - auto *ISD = cast(SectionCommands[0]); - std::stable_sort(ISD->Sections.begin(), ISD->Sections.end(), compCtors); + auto *Pat = cast(SectionCommands[0]); + std::stable_sort(Pat->Sections.begin(), Pat->Sections.end(), compCtors); } // If an input string is in the form of "foo.N" where N is a number, @@ -389,8 +388,8 @@ std::vector elf::getInputSections(OutputSection *OS) { std::vector Ret; for (BaseCommand *Base : OS->SectionCommands) - if (auto *ISD = dyn_cast(Base)) - Ret.insert(Ret.end(), ISD->Sections.begin(), ISD->Sections.end()); + if (auto *Pat = dyn_cast(Base)) + Ret.insert(Ret.end(), Pat->Sections.begin(), Pat->Sections.end()); return Ret; } Index: lld/ELF/Relocations.h =================================================================== --- lld/ELF/Relocations.h +++ lld/ELF/Relocations.h @@ -150,7 +150,7 @@ class ThunkSection; class Thunk; -struct InputSectionDescription; +struct SectionPattern; class ThunkCreator { public: @@ -165,8 +165,8 @@ private: void mergeThunks(ArrayRef OutputSections); - ThunkSection *getISDThunkSec(OutputSection *OS, InputSection *IS, - InputSectionDescription *ISD, uint32_t Type, + ThunkSection *getPatThunkSec(OutputSection *OS, InputSection *IS, + SectionPattern *Pat, uint32_t Type, uint64_t Src); ThunkSection *getISThunkSec(InputSection *IS); @@ -175,7 +175,7 @@ std::pair getThunk(Symbol &Sym, RelType Type, uint64_t Src); - ThunkSection *addThunkSection(OutputSection *OS, InputSectionDescription *, + ThunkSection *addThunkSection(OutputSection *OS, SectionPattern *, uint64_t Off); bool normalizeExistingThunk(Relocation &Rel, uint64_t Src); Index: lld/ELF/Relocations.cpp =================================================================== --- lld/ELF/Relocations.cpp +++ lld/ELF/Relocations.cpp @@ -1089,16 +1089,16 @@ } // Call Fn on every executable InputSection accessed via the linker script -// InputSectionDescription::Sections. -static void forEachInputSectionDescription( +// SectionPattern::Sections. +static void forEachSectionPattern( ArrayRef OutputSections, - llvm::function_ref Fn) { + llvm::function_ref Fn) { for (OutputSection *OS : OutputSections) { if (!(OS->Flags & SHF_ALLOC) || !(OS->Flags & SHF_EXECINSTR)) continue; for (BaseCommand *BC : OS->SectionCommands) - if (auto *ISD = dyn_cast(BC)) - Fn(OS, ISD); + if (auto *Pat = dyn_cast(BC)) + Fn(OS, Pat); } } @@ -1153,11 +1153,11 @@ // - Simple to understand and implement // // In lld for the first pass, we pre-create one or more ThunkSections per -// InputSectionDescription at Target specific intervals. A ThunkSection is +// SectionPattern at Target specific intervals. A ThunkSection is // placed so that the estimated end of the ThunkSection is within range of the -// start of the InputSectionDescription or the previous ThunkSection. For +// start of the SectionPattern or the previous ThunkSection. For // example: -// InputSectionDescription +// SectionPattern // Section 0 // ... // Section N @@ -1194,22 +1194,22 @@ // offsets. // This may invalidate any output section offsets stored outside of InputSection void ThunkCreator::mergeThunks(ArrayRef OutputSections) { - forEachInputSectionDescription( - OutputSections, [&](OutputSection *OS, InputSectionDescription *ISD) { - if (ISD->ThunkSections.empty()) + forEachSectionPattern( + OutputSections, [&](OutputSection *OS, SectionPattern *Pat) { + if (Pat->ThunkSections.empty()) return; // Remove any zero sized precreated Thunks. - llvm::erase_if(ISD->ThunkSections, + llvm::erase_if(Pat->ThunkSections, [](const std::pair &TS) { return TS.first->getSize() == 0; }); - // ISD->ThunkSections contains all created ThunkSections, including + // Pat->ThunkSections contains all created ThunkSections, including // those inserted in previous passes. Extract the Thunks created this // pass and order them in ascending OutSecOff. std::vector NewThunks; - for (const std::pair TS : ISD->ThunkSections) + for (const std::pair TS : Pat->ThunkSections) if (TS.second == Pass) NewThunks.push_back(TS.first); std::stable_sort(NewThunks.begin(), NewThunks.end(), @@ -1219,23 +1219,23 @@ // Merge sorted vectors of Thunks and InputSections by OutSecOff std::vector Tmp; - Tmp.reserve(ISD->Sections.size() + NewThunks.size()); + Tmp.reserve(Pat->Sections.size() + NewThunks.size()); - std::merge(ISD->Sections.begin(), ISD->Sections.end(), + std::merge(Pat->Sections.begin(), Pat->Sections.end(), NewThunks.begin(), NewThunks.end(), std::back_inserter(Tmp), mergeCmp); - ISD->Sections = std::move(Tmp); + Pat->Sections = std::move(Tmp); }); } -// Find or create a ThunkSection within the InputSectionDescription (ISD) that -// is in range of Src. An ISD maps to a range of InputSections described by a +// Find or create a ThunkSection within the SectionPattern (Pat) that +// is in range of Src. An Pat maps to a range of InputSections described by a // linker script section pattern such as { .text .text.* }. -ThunkSection *ThunkCreator::getISDThunkSec(OutputSection *OS, InputSection *IS, - InputSectionDescription *ISD, - uint32_t Type, uint64_t Src) { - for (std::pair TP : ISD->ThunkSections) { +ThunkSection *ThunkCreator::getPatThunkSec(OutputSection *OS, InputSection *IS, + SectionPattern *Pat, uint32_t Type, + uint64_t Src) { + for (std::pair TP : Pat->ThunkSections) { ThunkSection *TS = TP.first; uint64_t TSBase = OS->Addr + TS->OutSecOff; uint64_t TSLimit = TSBase + TS->getSize(); @@ -1255,7 +1255,7 @@ fatal("InputSection too large for range extension thunk " + IS->getObjMsg(Src - (OS->Addr + IS->OutSecOff))); } - return addThunkSection(OS, ISD, ThunkSecOff); + return addThunkSection(OS, Pat, ThunkSecOff); } // Add a Thunk that needs to be placed in a ThunkSection that immediately @@ -1269,17 +1269,17 @@ // InputSection (IS) that we need to precede is in. OutputSection *TOS = IS->getParent(); for (BaseCommand *BC : TOS->SectionCommands) { - auto *ISD = dyn_cast(BC); - if (!ISD || ISD->Sections.empty()) + auto *Pat = dyn_cast(BC); + if (!Pat || Pat->Sections.empty()) continue; - InputSection *First = ISD->Sections.front(); - InputSection *Last = ISD->Sections.back(); + InputSection *First = Pat->Sections.front(); + InputSection *Last = Pat->Sections.back(); if (IS->OutSecOff < First->OutSecOff || Last->OutSecOff < IS->OutSecOff) continue; - TS = addThunkSection(TOS, ISD, IS->OutSecOff); + TS = addThunkSection(TOS, Pat, IS->OutSecOff); ThunkedSections[IS] = TS; return TS; } @@ -1295,53 +1295,52 @@ // // We follow a simple but conservative heuristic to place ThunkSections at // offsets that are multiples of a Target specific branch range. -// For an InputSectionDescription that is smaller than the range, a single +// For an SectionPattern that is smaller than the range, a single // ThunkSection at the end of the range will do. // -// For an InputSectionDescription that is more than twice the size of the range, +// For an SectionPattern that is more than twice the size of the range, // we place the last ThunkSection at range bytes from the end of the -// InputSectionDescription in order to increase the likelihood that the +// SectionPattern in order to increase the likelihood that the // distance from a thunk to its target will be sufficiently small to // allow for the creation of a short thunk. void ThunkCreator::createInitialThunkSections( ArrayRef OutputSections) { uint32_t ThunkSectionSpacing = Target->getThunkSectionSpacing(); - forEachInputSectionDescription( - OutputSections, [&](OutputSection *OS, InputSectionDescription *ISD) { - if (ISD->Sections.empty()) + forEachSectionPattern( + OutputSections, [&](OutputSection *OS, SectionPattern *Pat) { + if (Pat->Sections.empty()) return; - uint32_t ISDBegin = ISD->Sections.front()->OutSecOff; - uint32_t ISDEnd = - ISD->Sections.back()->OutSecOff + ISD->Sections.back()->getSize(); + uint32_t PatBegin = Pat->Sections.front()->OutSecOff; + uint32_t PatEnd = + Pat->Sections.back()->OutSecOff + Pat->Sections.back()->getSize(); uint32_t LastThunkLowerBound = -1; - if (ISDEnd - ISDBegin > ThunkSectionSpacing * 2) - LastThunkLowerBound = ISDEnd - ThunkSectionSpacing; + if (PatEnd - PatBegin > ThunkSectionSpacing * 2) + LastThunkLowerBound = PatEnd - ThunkSectionSpacing; uint32_t ISLimit; - uint32_t PrevISLimit = ISDBegin; - uint32_t ThunkUpperBound = ISDBegin + ThunkSectionSpacing; + uint32_t PrevISLimit = PatBegin; + uint32_t ThunkUpperBound = PatBegin + ThunkSectionSpacing; - for (const InputSection *IS : ISD->Sections) { + for (const InputSection *IS : Pat->Sections) { ISLimit = IS->OutSecOff + IS->getSize(); if (ISLimit > ThunkUpperBound) { - addThunkSection(OS, ISD, PrevISLimit); + addThunkSection(OS, Pat, PrevISLimit); ThunkUpperBound = PrevISLimit + ThunkSectionSpacing; } if (ISLimit > LastThunkLowerBound) break; PrevISLimit = ISLimit; } - addThunkSection(OS, ISD, ISLimit); + addThunkSection(OS, Pat, ISLimit); }); } ThunkSection *ThunkCreator::addThunkSection(OutputSection *OS, - InputSectionDescription *ISD, - uint64_t Off) { + SectionPattern *Pat, uint64_t Off) { auto *TS = make(OS, Off); - ISD->ThunkSections.push_back({TS, Pass}); + Pat->ThunkSections.push_back({TS, Pass}); return TS; } @@ -1385,7 +1384,7 @@ } // Process all relocations from the InputSections that have been assigned -// to InputSectionDescriptions and redirect through Thunks if needed. The +// to SectionPatterns and redirect through Thunks if needed. The // function should be called iteratively until it returns false. // // PreConditions: @@ -1421,13 +1420,13 @@ fatal("thunk creation not converged"); // Create all the Thunks and insert them into synthetic ThunkSections. The - // ThunkSections are later inserted back into InputSectionDescriptions. + // ThunkSections are later inserted back into SectionPatterns. // We separate the creation of ThunkSections from the insertion of the // ThunkSections as ThunkSections are not always inserted into the same - // InputSectionDescription as the caller. - forEachInputSectionDescription( - OutputSections, [&](OutputSection *OS, InputSectionDescription *ISD) { - for (InputSection *IS : ISD->Sections) + // SectionPattern as the caller. + forEachSectionPattern( + OutputSections, [&](OutputSection *OS, SectionPattern *Pat) { + for (InputSection *IS : Pat->Sections) for (Relocation &Rel : IS->Relocations) { uint64_t Src = IS->getVA(Rel.Offset); @@ -1451,7 +1450,7 @@ if (auto *TIS = T->getTargetInputSection()) TS = getISThunkSec(TIS); else - TS = getISDThunkSec(OS, IS, ISD, Rel.Type, Src); + TS = getPatThunkSec(OS, IS, Pat, Rel.Type, Src); TS->addThunk(T); Thunks[T->getThunkTargetSym()] = T; } @@ -1461,7 +1460,7 @@ Rel.Expr = fromPlt(Rel.Expr); } - for (auto &P : ISD->ThunkSections) + for (auto &P : Pat->ThunkSections) AddressesChanged |= P.first->assignOffsets(); }); Index: lld/ELF/ScriptParser.cpp =================================================================== --- lld/ELF/ScriptParser.cpp +++ lld/ELF/ScriptParser.cpp @@ -86,10 +86,10 @@ OutputSection *readOutputSectionDescription(StringRef OutSec); std::vector readOverlay(); std::vector readOutputSectionPhdrs(); - InputSectionDescription *readInputSectionDescription(StringRef Tok); + SectionPattern *readSectionPattern(StringRef Tok); StringMatcher readFilePatterns(); - std::vector readInputSectionsList(); - InputSectionDescription *readInputSectionRules(StringRef FilePattern); + std::vector readInputSectionsList(); + SectionPattern *readInputSectionRules(StringRef FilePattern); unsigned readPhdrType(); SortSectionPolicy readSortKind(); SymbolAssignment *readProvideHidden(bool Provide, bool Hidden); @@ -618,8 +618,8 @@ // is parsed as ".foo", ".bar" with "a.o", and ".baz" with "b.o". // The semantics of that is section .foo in any file, section .bar in // any file but a.o, and section .baz in any file but b.o. -std::vector ScriptParser::readInputSectionsList() { - std::vector Ret; +std::vector ScriptParser::readInputSectionsList() { + std::vector Ret; while (!errorCount() && peek() != ")") { StringMatcher ExcludeFilePat; if (consume("EXCLUDE_FILE")) { @@ -650,15 +650,14 @@ // | "SORT_BY_INIT_PRIORITY" | "SORT_NONE" // // is parsed by readInputSectionsList(). -InputSectionDescription * -ScriptParser::readInputSectionRules(StringRef FilePattern) { - auto *Cmd = make(FilePattern); +SectionPattern *ScriptParser::readInputSectionRules(StringRef FilePattern) { + auto *Cmd = make(FilePattern); expect("("); while (!errorCount() && !consume(")")) { SortSectionPolicy Outer = readSortKind(); SortSectionPolicy Inner = SortSectionPolicy::Default; - std::vector V; + std::vector V; if (Outer != SortSectionPolicy::Default) { expect("("); Inner = readSortKind(); @@ -674,24 +673,23 @@ V = readInputSectionsList(); } - for (SectionPattern &Pat : V) { + for (Wildcard &Pat : V) { Pat.SortInner = Inner; Pat.SortOuter = Outer; } - std::move(V.begin(), V.end(), std::back_inserter(Cmd->SectionPatterns)); + std::move(V.begin(), V.end(), std::back_inserter(Cmd->Wildcards)); } return Cmd; } -InputSectionDescription * -ScriptParser::readInputSectionDescription(StringRef Tok) { +SectionPattern *ScriptParser::readSectionPattern(StringRef Tok) { // Input section wildcard can be surrounded by KEEP. // https://sourceware.org/binutils/docs/ld/Input-Section-Keep.html#Input-Section-Keep if (Tok == "KEEP") { expect("("); StringRef FilePattern = next(); - InputSectionDescription *Cmd = readInputSectionRules(FilePattern); + SectionPattern *Cmd = readInputSectionRules(FilePattern); expect(")"); Script->KeptSections.push_back(Cmd); return Cmd; @@ -836,7 +834,7 @@ } else if (Tok == "INCLUDE") { readInclude(); } else if (peek() == "(") { - Cmd->SectionCommands.push_back(readInputSectionDescription(Tok)); + Cmd->SectionCommands.push_back(readSectionPattern(Tok)); } else { setError("unknown command " + Tok); } Index: lld/ELF/SyntheticSections.cpp =================================================================== --- lld/ELF/SyntheticSections.cpp +++ lld/ELF/SyntheticSections.cpp @@ -853,8 +853,8 @@ const OutputSection *OS = P.first; uint64_t SecSize = 0; for (BaseCommand *Cmd : OS->SectionCommands) { - if (auto *ISD = dyn_cast(Cmd)) - for (InputSection *IS : ISD->Sections) { + if (auto *Pat = dyn_cast(Cmd)) + for (InputSection *IS : Pat->Sections) { uint64_t Off = alignTo(SecSize, IS->Alignment); SecSize = Off + IS->getSize(); } Index: lld/ELF/Writer.cpp =================================================================== --- lld/ELF/Writer.cpp +++ lld/ELF/Writer.cpp @@ -603,13 +603,13 @@ if (!Sec) continue; auto I = llvm::find_if(Sec->SectionCommands, [](BaseCommand *Base) { - if (auto *ISD = dyn_cast(Base)) - return !ISD->Sections.empty(); + if (auto *Pat = dyn_cast(Base)) + return !Pat->Sections.empty(); return false; }); if (I == Sec->SectionCommands.end()) continue; - InputSection *IS = cast(*I)->Sections[0]; + InputSection *IS = cast(*I)->Sections[0]; // Relocations are not using REL[A] section symbols. if (IS->Type == SHT_REL || IS->Type == SHT_RELA) @@ -1122,15 +1122,15 @@ return SectionOrder; } -// Sorts the sections in ISD according to the provided section order. +// Sorts the sections in Pat according to the provided section order. static void -sortISDBySectionOrder(InputSectionDescription *ISD, +sortPatBySectionOrder(SectionPattern *Pat, const DenseMap &Order) { std::vector UnorderedSections; std::vector> OrderedSections; uint64_t UnorderedSize = 0; - for (InputSection *IS : ISD->Sections) { + for (InputSection *IS : Pat->Sections) { auto I = Order.find(IS); if (I == Order.end()) { UnorderedSections.push_back(IS); @@ -1181,13 +1181,13 @@ } } - ISD->Sections.clear(); + Pat->Sections.clear(); for (InputSection *IS : makeArrayRef(UnorderedSections).slice(0, InsPt)) - ISD->Sections.push_back(IS); + Pat->Sections.push_back(IS); for (std::pair P : OrderedSections) - ISD->Sections.push_back(P.first); + Pat->Sections.push_back(P.first); for (InputSection *IS : makeArrayRef(UnorderedSections).slice(InsPt)) - ISD->Sections.push_back(IS); + Pat->Sections.push_back(IS); } static void sortSection(OutputSection *Sec, @@ -1217,8 +1217,8 @@ // by --symbol-ordering-file. if (!Order.empty()) for (BaseCommand *B : Sec->SectionCommands) - if (auto *ISD = dyn_cast(B)) - sortISDBySectionOrder(ISD, Order); + if (auto *Pat = dyn_cast(B)) + sortPatBySectionOrder(Pat, Order); } // If no layout was provided by linker script, we want to apply default @@ -1408,13 +1408,13 @@ if (!(Sec->Flags & SHF_LINK_ORDER)) continue; - // Link order may be distributed across several InputSectionDescriptions + // Link order may be distributed across several SectionPatterns // but sort must consider them all at once. std::vector ScriptSections; std::vector Sections; for (BaseCommand *Base : Sec->SectionCommands) { - if (auto *ISD = dyn_cast(Base)) { - for (InputSection *&IS : ISD->Sections) { + if (auto *Pat = dyn_cast(Base)) { + for (InputSection *&IS : Pat->Sections) { ScriptSections.push_back(&IS); Sections.push_back(IS); } @@ -1457,8 +1457,8 @@ // Remove the Sections we marked as duplicate earlier. for (BaseCommand *Base : Sec->SectionCommands) - if (auto *ISD = dyn_cast(Base)) - llvm::erase_if(ISD->Sections, [](InputSection *IS) { return !IS; }); + if (auto *Pat = dyn_cast(Base)) + llvm::erase_if(Pat->Sections, [](InputSection *IS) { return !IS; }); } } @@ -1534,8 +1534,8 @@ // If we reach here, then SS is an unused synthetic section and we want to // remove it from corresponding input section description of output section. for (BaseCommand *B : OS->SectionCommands) - if (auto *ISD = dyn_cast(B)) - llvm::erase_if(ISD->Sections, + if (auto *Pat = dyn_cast(B)) + llvm::erase_if(Pat->Sections, [=](InputSection *IS) { return IS == SS; }); } }