diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp index 626ba192b9e0..34eb98185eb1 100644 --- a/lld/ELF/LTO.cpp +++ b/lld/ELF/LTO.cpp @@ -130,7 +130,7 @@ void BitcodeCompiler::add(BitcodeFile &F) { std::vector Resols(Syms.size()); DenseSet ScriptSymbols; - for (BaseCommand *Base : Script->Commands) + for (BaseCommand *Base : Script->SectionCommands) if (auto *Cmd = dyn_cast(Base)) ScriptSymbols.insert(Cmd->Name); diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 29a11e392e07..d7123d948811 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -341,7 +341,7 @@ std::vector LinkerScript::createInputSectionList(OutputSection &OutCmd) { std::vector Ret; - for (BaseCommand *Base : OutCmd.Commands) { + for (BaseCommand *Base : OutCmd.SectionCommands) { auto *Cmd = dyn_cast(Base); if (!Cmd) continue; @@ -374,14 +374,14 @@ void LinkerScript::processCommands(OutputSectionFactory &Factory) { CurAddressState = State.get(); CurAddressState->OutSec = Aether; - for (size_t I = 0; I < Commands.size(); ++I) { + for (size_t I = 0; I < SectionCommands.size(); ++I) { // Handle symbol assignments outside of any output section. - if (auto *Cmd = dyn_cast(Commands[I])) { + if (auto *Cmd = dyn_cast(SectionCommands[I])) { addSymbol(Cmd); continue; } - if (auto *Sec = dyn_cast(Commands[I])) { + if (auto *Sec = dyn_cast(SectionCommands[I])) { std::vector V = createInputSectionList(*Sec); // The output section name `/DISCARD/' is special. @@ -396,19 +396,19 @@ void LinkerScript::processCommands(OutputSectionFactory &Factory) { // sections satisfy a given constraint. If not, a directive is handled // as if it wasn't present from the beginning. // - // Because we'll iterate over Commands many more times, the easiest + // Because we'll iterate over SectionCommands many more times, the easiest // way to "make it as if it wasn't present" is to just remove it. if (!matchConstraints(V, Sec->Constraint)) { for (InputSectionBase *S : V) S->Assigned = false; - Commands.erase(Commands.begin() + I); + SectionCommands.erase(SectionCommands.begin() + I); --I; continue; } // A directive may contain symbol definitions like this: // ".foo : { ...; bar = .; }". Handle them. - for (BaseCommand *Base : Sec->Commands) + for (BaseCommand *Base : Sec->SectionCommands) if (auto *OutCmd = dyn_cast(Base)) addSymbol(OutCmd); @@ -447,7 +447,8 @@ void LinkerScript::fabricateDefaultCommands() { auto Expr = [=] { return std::min(StartAddr, Target->getImageBase() + elf::getHeaderSize()); }; - Commands.insert(Commands.begin(), make(".", Expr, "")); + SectionCommands.insert(SectionCommands.begin(), + make(".", Expr, "")); } static OutputSection *findByName(ArrayRef Vec, @@ -461,7 +462,7 @@ static OutputSection *findByName(ArrayRef Vec, // Add sections that didn't match any sections command. void LinkerScript::addOrphanSections(OutputSectionFactory &Factory) { - unsigned End = Commands.size(); + unsigned End = SectionCommands.size(); for (InputSectionBase *S : InputSections) { if (!S->Live || S->Parent) @@ -471,13 +472,13 @@ void LinkerScript::addOrphanSections(OutputSectionFactory &Factory) { log(toString(S) + " is being placed in '" + Name + "'"); if (OutputSection *Sec = - findByName(makeArrayRef(Commands).slice(0, End), Name)) { + findByName(makeArrayRef(SectionCommands).slice(0, End), Name)) { Sec->addSection(cast(S)); continue; } if (OutputSection *OS = Factory.addInputSec(S, Name)) - Script->Commands.push_back(OS); + SectionCommands.push_back(OS); assert(S->getOutputSection()->SectionIndex == INT_MAX); } } @@ -636,7 +637,7 @@ void LinkerScript::assignOffsets(OutputSection *Sec) { if (CurAddressState->OutSec->Flags & SHF_COMPRESSED) return; - for (BaseCommand *C : Sec->Commands) + for (BaseCommand *C : Sec->SectionCommands) process(*C); } @@ -647,7 +648,7 @@ void LinkerScript::removeEmptyCommands() { // clutter the output. // We instead remove trivially empty sections. The bfd linker seems even // more aggressive at removing them. - llvm::erase_if(Commands, [&](BaseCommand *Base) { + llvm::erase_if(SectionCommands, [&](BaseCommand *Base) { if (auto *Sec = dyn_cast(Base)) return !Sec->Live; return false; @@ -655,7 +656,7 @@ void LinkerScript::removeEmptyCommands() { } static bool isAllSectionDescription(const OutputSection &Cmd) { - for (BaseCommand *Base : Cmd.Commands) + for (BaseCommand *Base : Cmd.SectionCommands) if (!isa(*Base)) return false; return true; @@ -668,7 +669,7 @@ void LinkerScript::adjustSectionsBeforeSorting() { // consequeces and gives us a section to put the symbol in. uint64_t Flags = SHF_ALLOC; - for (BaseCommand *Cmd : Commands) { + for (BaseCommand *Cmd : SectionCommands) { auto *Sec = dyn_cast(Cmd); if (!Sec) continue; @@ -687,7 +688,7 @@ void LinkerScript::adjustSectionsBeforeSorting() { void LinkerScript::adjustSectionsAfterSorting() { // Try and find an appropriate memory region to assign offsets in. - for (BaseCommand *Base : Commands) { + for (BaseCommand *Base : SectionCommands) { if (auto *Sec = dyn_cast(Base)) { if (!Sec->Live) continue; @@ -714,7 +715,7 @@ void LinkerScript::adjustSectionsAfterSorting() { // Walk the commands and propagate the program headers to commands that don't // explicitly specify them. - for (BaseCommand *Base : Commands) { + for (BaseCommand *Base : SectionCommands) { auto *Sec = dyn_cast(Base); if (!Sec) continue; @@ -801,7 +802,7 @@ void LinkerScript::assignAddresses() { ErrorOnMissingSection = true; switchTo(Aether); - for (BaseCommand *Base : Commands) { + for (BaseCommand *Base : SectionCommands) { if (auto *Cmd = dyn_cast(Base)) { assignSymbol(Cmd, false); continue; diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index 5cf86653ade2..065042e942ec 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -246,7 +246,7 @@ public: void processCommands(OutputSectionFactory &Factory); // SECTIONS command list. - std::vector Commands; + std::vector SectionCommands; // PHDRS command list. std::vector PhdrsCommands; diff --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp index d744a82f2c75..968dc611b814 100644 --- a/lld/ELF/MapFile.cpp +++ b/lld/ELF/MapFile.cpp @@ -133,7 +133,7 @@ template void elf::writeMapFile() { OS << OSec->Name << '\n'; // Dump symbols for each input section. - for (BaseCommand *Base : OSec->Commands) { + for (BaseCommand *Base : OSec->SectionCommands) { auto *ISD = dyn_cast(Base); if (!ISD) continue; diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 9013adfccc13..6f0c0f290ce3 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -139,9 +139,10 @@ void OutputSection::addSection(InputSection *IS) { if (!IS->Assigned) { IS->Assigned = true; - if (Commands.empty() || !isa(Commands.back())) - Commands.push_back(make("")); - auto *ISD = cast(Commands.back()); + if (SectionCommands.empty() || + !isa(SectionCommands.back())) + SectionCommands.push_back(make("")); + auto *ISD = cast(SectionCommands.back()); ISD->Sections.push_back(IS); } } @@ -311,8 +312,9 @@ bool OutputSection::classof(const BaseCommand *C) { } void OutputSection::sort(std::function Order) { - assert(Commands.size() == 1); - sortByOrder(cast(Commands[0])->Sections, Order); + assert(SectionCommands.size() == 1); + sortByOrder(cast(SectionCommands[0])->Sections, + Order); } // Fill [Buf, Buf + Size) with Filler. @@ -382,7 +384,7 @@ template void OutputSection::writeTo(uint8_t *Buf) { // Write leading padding. std::vector Sections; - for (BaseCommand *Cmd : Commands) + for (BaseCommand *Cmd : SectionCommands) if (auto *ISD = dyn_cast(Cmd)) for (InputSection *IS : ISD->Sections) if (IS->Live) @@ -409,7 +411,7 @@ template void OutputSection::writeTo(uint8_t *Buf) { // Linker scripts may have BYTE()-family commands with which you // can write arbitrary bytes to the output. Process them if any. - for (BaseCommand *Base : Commands) + for (BaseCommand *Base : SectionCommands) if (auto *Data = dyn_cast(Base)) writeInt(Buf + Data->Offset, Data->Expression().getValue(), Data->Size); } @@ -449,7 +451,7 @@ template void OutputSection::finalize() { // but sort must consider them all at once. std::vector ScriptSections; std::vector Sections; - for (BaseCommand *Base : Commands) { + for (BaseCommand *Base : SectionCommands) { if (auto *ISD = dyn_cast(Base)) { for (InputSection *&IS : ISD->Sections) { ScriptSections.push_back(&IS); @@ -546,8 +548,8 @@ static bool compCtors(const InputSection *A, const InputSection *B) { // Unfortunately, the rules are different from the one for .{init,fini}_array. // Read the comment above. void OutputSection::sortCtorsDtors() { - assert(Commands.size() == 1); - auto *ISD = cast(Commands[0]); + assert(SectionCommands.size() == 1); + auto *ISD = cast(SectionCommands[0]); std::stable_sort(ISD->Sections.begin(), ISD->Sections.end(), compCtors); } diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index 665fffe3b6db..f4889f7b94f0 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -88,7 +88,7 @@ public: Expr AlignExpr; Expr LMAExpr; Expr SubalignExpr; - std::vector Commands; + std::vector SectionCommands; std::vector Phdrs; llvm::Optional Filler; ConstraintKind Constraint = ConstraintKind::NoConstraint; diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 86d5d5e37f47..0215a0bfd96d 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -1024,7 +1024,7 @@ void ThunkCreator::mergeThunks() { } static uint32_t findEndOfFirstNonExec(OutputSection &Cmd) { - for (BaseCommand *Base : Cmd.Commands) + for (BaseCommand *Base : Cmd.SectionCommands) if (auto *ISD = dyn_cast(Base)) for (auto *IS : ISD->Sections) if ((IS->Flags & SHF_EXECINSTR) == 0) @@ -1052,7 +1052,7 @@ ThunkSection *ThunkCreator::getISThunkSec(InputSection *IS) { // InputSection (IS) that we need to precede is in. OutputSection *TOS = IS->getParent(); std::vector *Range = nullptr; - for (BaseCommand *BC : TOS->Commands) + for (BaseCommand *BC : TOS->SectionCommands) if (auto *ISD = dyn_cast(BC)) { InputSection *first = ISD->Sections.front(); InputSection *last = ISD->Sections.back(); @@ -1100,7 +1100,7 @@ void ThunkCreator::forEachExecInputSection( for (OutputSection *OS : OutputSections) { if (!(OS->Flags & SHF_ALLOC) || !(OS->Flags & SHF_EXECINSTR)) continue; - for (BaseCommand *BC : OS->Commands) + for (BaseCommand *BC : OS->SectionCommands) if (auto *ISD = dyn_cast(BC)) { CurTS = nullptr; for (InputSection *IS : ISD->Sections) diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp index 1c2e9d318a67..d30538e416c6 100644 --- a/lld/ELF/ScriptParser.cpp +++ b/lld/ELF/ScriptParser.cpp @@ -234,7 +234,7 @@ void ScriptParser::readLinkerScript() { continue; if (Tok == "ASSERT") { - Script->Commands.push_back(readAssert()); + Script->SectionCommands.push_back(readAssert()); } else if (Tok == "ENTRY") { readEntry(); } else if (Tok == "EXTERN") { @@ -262,7 +262,7 @@ void ScriptParser::readLinkerScript() { } else if (Tok == "VERSION") { readVersion(); } else if (SymbolAssignment *Cmd = readProvideOrAssignment(Tok)) { - Script->Commands.push_back(Cmd); + Script->SectionCommands.push_back(Cmd); } else { setError("unknown directive: " + Tok); } @@ -451,7 +451,7 @@ void ScriptParser::readSections() { else Cmd = readOutputSectionDescription(Tok); } - Script->Commands.push_back(Cmd); + Script->SectionCommands.push_back(Cmd); } } @@ -669,11 +669,11 @@ OutputSection *ScriptParser::readOutputSectionDescription(StringRef OutSec) { if (Tok == ";") { // Empty commands are allowed. Do nothing here. } else if (SymbolAssignment *Assign = readProvideOrAssignment(Tok)) { - Cmd->Commands.push_back(Assign); + Cmd->SectionCommands.push_back(Assign); } else if (BytesDataCommand *Data = readBytesDataCommand(Tok)) { - Cmd->Commands.push_back(Data); + Cmd->SectionCommands.push_back(Data); } else if (Tok == "ASSERT") { - Cmd->Commands.push_back(readAssert()); + Cmd->SectionCommands.push_back(readAssert()); expect(";"); } else if (Tok == "CONSTRUCTORS") { // CONSTRUCTORS is a keyword to make the linker recognize C++ ctors/dtors @@ -684,7 +684,7 @@ OutputSection *ScriptParser::readOutputSectionDescription(StringRef OutSec) { } else if (Tok == "SORT") { readSort(); } else if (peek() == "(") { - Cmd->Commands.push_back(readInputSectionDescription(Tok)); + Cmd->SectionCommands.push_back(readInputSectionDescription(Tok)); } else { setError("unknown command " + Tok); } diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 44ee6e1c2095..1548749cde64 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -2378,10 +2378,11 @@ void ARMExidxSentinelSection::writeTo(uint8_t *Buf) { // sentinel. By construction the Sentinel is in the last // InputSectionDescription as the InputSection that precedes it. OutputSection *C = getParent(); - auto ISD = std::find_if(C->Commands.rbegin(), C->Commands.rend(), - [](const BaseCommand *Base) { - return isa(Base); - }); + auto ISD = + std::find_if(C->SectionCommands.rbegin(), C->SectionCommands.rend(), + [](const BaseCommand *Base) { + return isa(Base); + }); auto L = cast(*ISD); InputSection *Highest = L->Sections[L->Sections.size() - 2]; InputSection *LS = Highest->getLinkOrderDep(); diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 283d06499ac0..99a7029331fd 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -466,16 +466,16 @@ template void Writer::copyLocalSymbols() { template void Writer::addSectionSymbols() { // Create one STT_SECTION symbol for each output section we might // have a relocation with. - for (BaseCommand *Base : Script->Commands) { + for (BaseCommand *Base : Script->SectionCommands) { auto *Sec = dyn_cast(Base); if (!Sec) continue; - auto I = llvm::find_if(Sec->Commands, [](BaseCommand *Base) { + auto I = llvm::find_if(Sec->SectionCommands, [](BaseCommand *Base) { if (auto *ISD = dyn_cast(Base)) return !ISD->Sections.empty(); return false; }); - if (I == Sec->Commands.end()) + if (I == Sec->SectionCommands.end()) continue; InputSection *IS = cast(*I)->Sections[0]; if (isa(IS) || IS->Type == SHT_REL || @@ -849,7 +849,7 @@ static void sortBySymbolsOrder() { // Sort sections by priority. DenseMap SectionOrder = buildSectionOrder(); - for (BaseCommand *Base : Script->Commands) + for (BaseCommand *Base : Script->SectionCommands) if (auto *Sec = dyn_cast(Base)) Sec->sort([&](InputSectionBase *S) { return SectionOrder.lookup(S); }); } @@ -876,7 +876,8 @@ template void Writer::createSections() { Factory.addInputSec(IS, getOutputSectionName(IS->Name))) Vec.push_back(Sec); - Script->Commands.insert(Script->Commands.begin(), Vec.begin(), Vec.end()); + Script->SectionCommands.insert(Script->SectionCommands.begin(), Vec.begin(), + Vec.end()); Script->fabricateDefaultCommands(); sortBySymbolsOrder(); @@ -1051,15 +1052,15 @@ template void Writer::sortSections() { if (Config->Relocatable) return; - for (BaseCommand *Base : Script->Commands) + for (BaseCommand *Base : Script->SectionCommands) if (auto *Sec = dyn_cast(Base)) Sec->SortRank = getSectionRank(Sec); if (!Script->HasSectionsCommand) { // We know that all the OutputSections are contiguous in // this case. - auto E = Script->Commands.end(); - auto I = Script->Commands.begin(); + auto E = Script->SectionCommands.end(); + auto I = Script->SectionCommands.begin(); auto IsSection = [](BaseCommand *Base) { return isa(Base); }; I = std::find_if(I, E, IsSection); E = std::find_if(llvm::make_reverse_iterator(E), @@ -1108,8 +1109,8 @@ template void Writer::sortSections() { // after another commands. For the details, look at shouldSkip // function. - auto I = Script->Commands.begin(); - auto E = Script->Commands.end(); + auto I = Script->SectionCommands.begin(); + auto E = Script->SectionCommands.end(); auto NonScriptI = std::find_if(I, E, [](BaseCommand *Base) { if (auto *Sec = dyn_cast(Base)) return Sec->Live && Sec->SectionIndex == INT_MAX; @@ -1178,8 +1179,9 @@ static void removeUnusedSyntheticSections() { if (!SS->empty() || !OS) continue; - std::vector::iterator Empty = OS->Commands.end(); - for (auto I = OS->Commands.begin(), E = OS->Commands.end(); I != E; ++I) { + std::vector::iterator Empty = OS->SectionCommands.end(); + for (auto I = OS->SectionCommands.begin(), E = OS->SectionCommands.end(); + I != E; ++I) { BaseCommand *B = *I; if (auto *ISD = dyn_cast(B)) { llvm::erase_if(ISD->Sections, @@ -1188,12 +1190,12 @@ static void removeUnusedSyntheticSections() { Empty = I; } } - if (Empty != OS->Commands.end()) - OS->Commands.erase(Empty); + if (Empty != OS->SectionCommands.end()) + OS->SectionCommands.erase(Empty); // If there are no other sections in the output section, remove it from the // output. - if (OS->Commands.empty()) + if (OS->SectionCommands.empty()) OS->Live = false; } } @@ -1240,7 +1242,7 @@ template void Writer::finalizeSections() { // addresses of each section by section name. Add such symbols. if (!Config->Relocatable) { addStartEndSymbols(); - for (BaseCommand *Base : Script->Commands) + for (BaseCommand *Base : Script->SectionCommands) if (auto *Sec = dyn_cast(Base)) addStartStopSymbols(Sec); } @@ -1304,7 +1306,7 @@ template void Writer::finalizeSections() { // Now that we have the final list, create a list of all the // OutputSections for convenience. - for (BaseCommand *Base : Script->Commands) + for (BaseCommand *Base : Script->SectionCommands) if (auto *Sec = dyn_cast(Base)) OutputSections.push_back(Sec); @@ -1440,7 +1442,7 @@ void Writer::addStartStopSymbols(OutputSection *Sec) { } template OutputSection *Writer::findSection(StringRef Name) { - for (BaseCommand *Base : Script->Commands) + for (BaseCommand *Base : Script->SectionCommands) if (auto *Sec = dyn_cast(Base)) if (Sec->Name == Name) return Sec;