[lld] 6188fd4 - [ELF] Rename OutputSection::sectionCommands to commands. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 25 16:47:13 PST 2021
Author: Fangrui Song
Date: 2021-11-25T16:47:07-08:00
New Revision: 6188fd495744ffea76f481a960df9beacb8ce91b
URL: https://github.com/llvm/llvm-project/commit/6188fd495744ffea76f481a960df9beacb8ce91b
DIFF: https://github.com/llvm/llvm-project/commit/6188fd495744ffea76f481a960df9beacb8ce91b.diff
LOG: [ELF] Rename OutputSection::sectionCommands to commands. NFC
This partially reverts r315409: the description applies to LinkerScript, but not
to OutputSection.
The name "sectionCommands" is used in both LinkerScript::sectionCommands and
OutputSection::sectionCommands, which may lead to confusion.
"commands" in OutputSection has no ambiguity because there are no other types
of commands.
Added:
Modified:
lld/ELF/AArch64ErrataFix.cpp
lld/ELF/ARMErrataFix.cpp
lld/ELF/ICF.cpp
lld/ELF/LinkerScript.cpp
lld/ELF/MapFile.cpp
lld/ELF/OutputSections.cpp
lld/ELF/OutputSections.h
lld/ELF/Relocations.cpp
lld/ELF/ScriptParser.cpp
lld/ELF/SyntheticSections.cpp
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/AArch64ErrataFix.cpp b/lld/ELF/AArch64ErrataFix.cpp
index b9fd4cdbad69..331a5786fc34 100644
--- a/lld/ELF/AArch64ErrataFix.cpp
+++ b/lld/ELF/AArch64ErrataFix.cpp
@@ -630,7 +630,7 @@ bool AArch64Err843419Patcher::createFixes() {
for (OutputSection *os : outputSections) {
if (!(os->flags & SHF_ALLOC) || !(os->flags & SHF_EXECINSTR))
continue;
- for (BaseCommand *bc : os->sectionCommands)
+ for (BaseCommand *bc : os->commands)
if (auto *isd = dyn_cast<InputSectionDescription>(bc)) {
std::vector<Patch843419Section *> patches =
patchInputSectionDescription(*isd);
diff --git a/lld/ELF/ARMErrataFix.cpp b/lld/ELF/ARMErrataFix.cpp
index 77623780ffa5..bf41f65b95dd 100644
--- a/lld/ELF/ARMErrataFix.cpp
+++ b/lld/ELF/ARMErrataFix.cpp
@@ -525,7 +525,7 @@ bool ARMErr657417Patcher::createFixes() {
for (OutputSection *os : outputSections) {
if (!(os->flags & SHF_ALLOC) || !(os->flags & SHF_EXECINSTR))
continue;
- for (BaseCommand *bc : os->sectionCommands)
+ for (BaseCommand *bc : os->commands)
if (auto *isd = dyn_cast<InputSectionDescription>(bc)) {
std::vector<Patch657417Section *> patches =
patchInputSectionDescription(*isd);
diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp
index c13969806916..b35e46b4fc63 100644
--- a/lld/ELF/ICF.cpp
+++ b/lld/ELF/ICF.cpp
@@ -554,7 +554,7 @@ template <class ELFT> void ICF<ELFT>::run() {
// ICF may fold some input sections assigned to output sections. Remove them.
for (BaseCommand *base : script->sectionCommands)
if (auto *sec = dyn_cast<OutputSection>(base))
- for (BaseCommand *sub_base : sec->sectionCommands)
+ for (BaseCommand *sub_base : sec->commands)
if (auto *isd = dyn_cast<InputSectionDescription>(sub_base))
llvm::erase_if(isd->sections,
[](InputSection *isec) { return !isec->isLive(); });
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 5e09e5dde39d..d9346c891006 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -285,7 +285,7 @@ getSymbolAssignmentValues(const std::vector<BaseCommand *> §ionCommands) {
std::make_pair(cmd->sym->section, cmd->sym->value));
continue;
}
- for (BaseCommand *sub_base : cast<OutputSection>(base)->sectionCommands)
+ for (BaseCommand *sub_base : cast<OutputSection>(base)->commands)
if (auto *cmd = dyn_cast<SymbolAssignment>(sub_base))
if (cmd->sym)
ret.try_emplace(cmd->sym,
@@ -360,7 +360,7 @@ void LinkerScript::declareSymbols() {
auto *sec = cast<OutputSection>(base);
if (sec->constraint != ConstraintKind::NoConstraint)
continue;
- for (BaseCommand *base2 : sec->sectionCommands)
+ for (BaseCommand *base2 : sec->commands)
if (auto *cmd = dyn_cast<SymbolAssignment>(base2))
declareSymbol(cmd);
}
@@ -588,7 +588,7 @@ void LinkerScript::discardSynthetic(OutputSection &outCmd) {
continue;
std::vector<InputSectionBase *> secs(part.armExidx->exidxSections.begin(),
part.armExidx->exidxSections.end());
- for (BaseCommand *base : outCmd.sectionCommands)
+ for (BaseCommand *base : outCmd.commands)
if (auto *cmd = dyn_cast<InputSectionDescription>(base)) {
std::vector<InputSectionBase *> matches =
computeInputSections(cmd, secs);
@@ -602,7 +602,7 @@ std::vector<InputSectionBase *>
LinkerScript::createInputSectionList(OutputSection &outCmd) {
std::vector<InputSectionBase *> ret;
- for (BaseCommand *base : outCmd.sectionCommands) {
+ for (BaseCommand *base : outCmd.commands) {
if (auto *cmd = dyn_cast<InputSectionDescription>(base)) {
cmd->sectionBases = computeInputSections(cmd, inputSections);
for (InputSectionBase *s : cmd->sectionBases)
@@ -624,7 +624,7 @@ void LinkerScript::processSectionCommands() {
for (InputSectionBase *s : v)
discard(s);
discardSynthetic(*osec);
- osec->sectionCommands.clear();
+ osec->commands.clear();
return false;
}
@@ -638,7 +638,7 @@ void LinkerScript::processSectionCommands() {
if (!matchConstraints(v, osec->constraint)) {
for (InputSectionBase *s : v)
s->parent = nullptr;
- osec->sectionCommands.clear();
+ osec->commands.clear();
return false;
}
@@ -703,7 +703,7 @@ void LinkerScript::processSymbolAssignments() {
if (auto *cmd = dyn_cast<SymbolAssignment>(base))
addSymbol(cmd);
else
- for (BaseCommand *sub_base : cast<OutputSection>(base)->sectionCommands)
+ for (BaseCommand *sub_base : cast<OutputSection>(base)->commands)
if (auto *cmd = dyn_cast<SymbolAssignment>(sub_base))
addSymbol(cmd);
}
@@ -813,8 +813,7 @@ addInputSec(StringMap<TinyPtrVector<OutputSection *>> &map,
// end up being linked to the same output section. The casts are fine
// because everything in the map was created by the orphan placement code.
auto *firstIsec = cast<InputSectionBase>(
- cast<InputSectionDescription>(sec->sectionCommands[0])
- ->sectionBases[0]);
+ cast<InputSectionDescription>(sec->commands[0])->sectionBases[0]);
OutputSection *firstIsecOut =
firstIsec->flags & SHF_LINK_ORDER
? firstIsec->getLinkOrderDep()->getOutputSection()
@@ -1059,7 +1058,7 @@ void LinkerScript::assignOffsets(OutputSection *sec) {
// We visited SectionsCommands from processSectionCommands to
// layout sections. Now, we visit SectionsCommands again to fix
// section offsets.
- for (BaseCommand *base : sec->sectionCommands) {
+ for (BaseCommand *base : sec->commands) {
// This handles the assignments to symbol or to the dot.
if (auto *cmd = dyn_cast<SymbolAssignment>(base)) {
cmd->addr = dot;
@@ -1110,7 +1109,7 @@ static bool isDiscardable(const OutputSection &sec) {
if (sec.usedInExpression)
return false;
- for (BaseCommand *base : sec.sectionCommands) {
+ for (BaseCommand *base : sec.commands) {
if (auto cmd = dyn_cast<SymbolAssignment>(base))
// Don't create empty output sections just for unreferenced PROVIDE
// symbols.
diff --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp
index c4690ae5aefd..9ae8d7b303fa 100644
--- a/lld/ELF/MapFile.cpp
+++ b/lld/ELF/MapFile.cpp
@@ -179,7 +179,7 @@ void elf::writeMapFile() {
os << osec->name << '\n';
// Dump symbols for each input section.
- for (BaseCommand *base : osec->sectionCommands) {
+ for (BaseCommand *base : osec->commands) {
if (auto *isd = dyn_cast<InputSectionDescription>(base)) {
for (InputSection *isec : isd->sections) {
if (auto *ehSec = dyn_cast<EhFrameSection>(isec)) {
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index cc4f0688701a..8890427cd185 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -100,10 +100,9 @@ static bool canMergeToProgbits(unsigned type) {
void OutputSection::recordSection(InputSectionBase *isec) {
partition = isec->partition;
isec->parent = this;
- if (sectionCommands.empty() ||
- !isa<InputSectionDescription>(sectionCommands.back()))
- sectionCommands.push_back(make<InputSectionDescription>(""));
- auto *isd = cast<InputSectionDescription>(sectionCommands.back());
+ if (commands.empty() || !isa<InputSectionDescription>(commands.back()))
+ commands.push_back(make<InputSectionDescription>(""));
+ auto *isd = cast<InputSectionDescription>(commands.back());
isd->sectionBases.push_back(isec);
}
@@ -166,7 +165,7 @@ void OutputSection::commitSection(InputSection *isec) {
// to compute an output offset for each piece of each input section.
void OutputSection::finalizeInputSections() {
std::vector<MergeSyntheticSection *> mergeSections;
- for (BaseCommand *base : sectionCommands) {
+ for (BaseCommand *base : commands) {
auto *cmd = dyn_cast<InputSectionDescription>(base);
if (!cmd)
continue;
@@ -243,7 +242,7 @@ bool OutputSection::classof(const BaseCommand *c) {
void OutputSection::sort(llvm::function_ref<int(InputSectionBase *s)> order) {
assert(isLive());
- for (BaseCommand *b : sectionCommands)
+ for (BaseCommand *b : commands)
if (auto *isd = dyn_cast<InputSectionDescription>(b))
sortByOrder(isd->sections, order);
}
@@ -367,7 +366,7 @@ template <class ELFT> 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 : sectionCommands)
+ for (BaseCommand *base : commands)
if (auto *data = dyn_cast<ByteCommand>(base))
writeInt(buf + data->offset, data->expression().getValue(), data->size);
}
@@ -485,8 +484,8 @@ static bool compCtors(const InputSection *a, const InputSection *b) {
// Unfortunately, the rules are
diff erent from the one for .{init,fini}_array.
// Read the comment above.
void OutputSection::sortCtorsDtors() {
- assert(sectionCommands.size() == 1);
- auto *isd = cast<InputSectionDescription>(sectionCommands[0]);
+ assert(commands.size() == 1);
+ auto *isd = cast<InputSectionDescription>(commands[0]);
llvm::stable_sort(isd->sections, compCtors);
}
@@ -505,7 +504,7 @@ int elf::getPriority(StringRef s) {
}
InputSection *elf::getFirstInputSection(const OutputSection *os) {
- for (BaseCommand *base : os->sectionCommands)
+ for (BaseCommand *base : os->commands)
if (auto *isd = dyn_cast<InputSectionDescription>(base))
if (!isd->sections.empty())
return isd->sections[0];
@@ -514,7 +513,7 @@ InputSection *elf::getFirstInputSection(const OutputSection *os) {
std::vector<InputSection *> elf::getInputSections(const OutputSection *os) {
std::vector<InputSection *> ret;
- for (BaseCommand *base : os->sectionCommands)
+ for (BaseCommand *base : os->commands)
if (auto *isd = dyn_cast<InputSectionDescription>(base))
ret.insert(ret.end(), isd->sections.begin(), isd->sections.end());
return ret;
diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h
index a0f806614387..fe9fd4ed3785 100644
--- a/lld/ELF/OutputSections.h
+++ b/lld/ELF/OutputSections.h
@@ -82,7 +82,7 @@ class OutputSection final : public BaseCommand, public SectionBase {
Expr alignExpr;
Expr lmaExpr;
Expr subalignExpr;
- std::vector<BaseCommand *> sectionCommands;
+ std::vector<BaseCommand *> commands;
std::vector<StringRef> phdrs;
llvm::Optional<std::array<uint8_t, 4>> filler;
ConstraintKind constraint = ConstraintKind::NoConstraint;
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 9c22ce7d6013..023a04f00450 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -366,10 +366,10 @@ template <class ELFT> static void addCopyRelSymbol(SharedSymbol &ss) {
// At this point, sectionBases has been migrated to sections. Append sec to
// sections.
- if (osec->sectionCommands.empty() ||
- !isa<InputSectionDescription>(osec->sectionCommands.back()))
- osec->sectionCommands.push_back(make<InputSectionDescription>(""));
- auto *isd = cast<InputSectionDescription>(osec->sectionCommands.back());
+ if (osec->commands.empty() ||
+ !isa<InputSectionDescription>(osec->commands.back()))
+ osec->commands.push_back(make<InputSectionDescription>(""));
+ auto *isd = cast<InputSectionDescription>(osec->commands.back());
isd->sections.push_back(sec);
osec->commitSection(sec);
@@ -1640,7 +1640,7 @@ static void forEachInputSectionDescription(
for (OutputSection *os : outputSections) {
if (!(os->flags & SHF_ALLOC) || !(os->flags & SHF_EXECINSTR))
continue;
- for (BaseCommand *bc : os->sectionCommands)
+ for (BaseCommand *bc : os->commands)
if (auto *isd = dyn_cast<InputSectionDescription>(bc))
fn(os, isd);
}
@@ -1817,7 +1817,7 @@ ThunkSection *ThunkCreator::getISThunkSec(InputSection *isec) {
// Find InputSectionRange within Target Output Section (TOS) that the
// InputSection (IS) that we need to precede is in.
OutputSection *tos = isec->getParent();
- for (BaseCommand *bc : tos->sectionCommands) {
+ for (BaseCommand *bc : tos->commands) {
auto *isd = dyn_cast<InputSectionDescription>(bc);
if (!isd || isd->sections.empty())
continue;
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index cc18a59da236..d91caed8c626 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -849,7 +849,7 @@ OutputSection *ScriptParser::readOverlaySectionDescription() {
uint64_t withoutFlags = 0;
if (consume("INPUT_SECTION_FLAGS"))
std::tie(withFlags, withoutFlags) = readInputSectionFlags();
- cmd->sectionCommands.push_back(
+ cmd->commands.push_back(
readInputSectionRules(next(), withFlags, withoutFlags));
}
return cmd;
@@ -885,9 +885,9 @@ OutputSection *ScriptParser::readOutputSectionDescription(StringRef outSec) {
if (tok == ";") {
// Empty commands are allowed. Do nothing here.
} else if (SymbolAssignment *assign = readAssignment(tok)) {
- cmd->sectionCommands.push_back(assign);
+ cmd->commands.push_back(assign);
} else if (ByteCommand *data = readByteCommand(tok)) {
- cmd->sectionCommands.push_back(data);
+ cmd->commands.push_back(data);
} else if (tok == "CONSTRUCTORS") {
// CONSTRUCTORS is a keyword to make the linker recognize C++ ctors/dtors
// by name. This is for very old file formats such as ECOFF/XCOFF.
@@ -904,7 +904,7 @@ OutputSection *ScriptParser::readOutputSectionDescription(StringRef outSec) {
} else if (tok == "INCLUDE") {
readInclude();
} else if (peek() == "(") {
- cmd->sectionCommands.push_back(readInputSectionDescription(tok));
+ cmd->commands.push_back(readInputSectionDescription(tok));
} else {
// We have a file name and no input sections description. It is not a
// commonly used syntax, but still acceptable. In that case, all sections
@@ -914,7 +914,7 @@ OutputSection *ScriptParser::readOutputSectionDescription(StringRef outSec) {
// case above.
auto *isd = make<InputSectionDescription>(tok);
isd->sectionPatterns.push_back({{}, StringMatcher("*")});
- cmd->sectionCommands.push_back(isd);
+ cmd->commands.push_back(isd);
}
}
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 3936f0f0d74f..0413e3105e96 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -900,7 +900,7 @@ void MipsGotSection::build() {
got.pagesMap) {
const OutputSection *os = p.first;
uint64_t secSize = 0;
- for (BaseCommand *cmd : os->sectionCommands) {
+ for (BaseCommand *cmd : os->commands) {
if (auto *isd = dyn_cast<InputSectionDescription>(cmd))
for (InputSection *isec : isd->sections) {
uint64_t off = alignTo(secSize, isec->alignment);
@@ -3604,7 +3604,7 @@ PPC32Got2Section::PPC32Got2Section()
bool PPC32Got2Section::isNeeded() const {
// See the comment below. This is not needed if there is no other
// InputSection.
- for (BaseCommand *base : getParent()->sectionCommands)
+ for (BaseCommand *base : getParent()->commands)
if (auto *isd = dyn_cast<InputSectionDescription>(base))
for (InputSection *isec : isd->sections)
if (isec != this)
@@ -3618,7 +3618,7 @@ void PPC32Got2Section::finalizeContents() {
// PPC32PltCallStub::writeTo(). The purpose of this empty synthetic section is
// to collect input sections named ".got2".
uint32_t offset = 0;
- for (BaseCommand *base : getParent()->sectionCommands)
+ for (BaseCommand *base : getParent()->commands)
if (auto *isd = dyn_cast<InputSectionDescription>(base)) {
for (InputSection *isec : isd->sections) {
if (isec == this)
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index da7fd788d1bd..59a751946844 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -729,12 +729,12 @@ template <class ELFT> void Writer<ELFT>::addSectionSymbols() {
auto *sec = dyn_cast<OutputSection>(base);
if (!sec)
continue;
- auto i = llvm::find_if(sec->sectionCommands, [](BaseCommand *base) {
+ auto i = llvm::find_if(sec->commands, [](BaseCommand *base) {
if (auto *isd = dyn_cast<InputSectionDescription>(base))
return !isd->sections.empty();
return false;
});
- if (i == sec->sectionCommands.end())
+ if (i == sec->commands.end())
continue;
InputSectionBase *isec = cast<InputSectionDescription>(*i)->sections[0];
@@ -1420,7 +1420,7 @@ static void sortSection(OutputSection *sec,
// digit radix sort. The sections may be sorted stably again by a more
// significant key.
if (!order.empty())
- for (BaseCommand *b : sec->sectionCommands)
+ for (BaseCommand *b : sec->commands)
if (auto *isd = dyn_cast<InputSectionDescription>(b))
sortISDBySectionOrder(isd, order);
@@ -1437,8 +1437,8 @@ static void sortSection(OutputSection *sec,
// addressable range of [.got, .got + 0xFFFC] for GOT-relative relocations.
// To reduce the risk of relocation overflow, .toc contents are sorted so
// that sections having smaller relocation offsets are at beginning of .toc
- assert(sec->sectionCommands.size() == 1);
- auto *isd = cast<InputSectionDescription>(sec->sectionCommands[0]);
+ assert(sec->commands.size() == 1);
+ auto *isd = cast<InputSectionDescription>(sec->commands[0]);
llvm::stable_sort(isd->sections,
[](const InputSection *a, const InputSection *b) -> bool {
return a->file->ppc64SmallCodeModelTocRelocs &&
@@ -1608,7 +1608,7 @@ template <class ELFT> void Writer<ELFT>::resolveShfLinkOrder() {
// Sorting is performed separately.
std::vector<InputSection **> scriptSections;
std::vector<InputSection *> sections;
- for (BaseCommand *base : sec->sectionCommands) {
+ for (BaseCommand *base : sec->commands) {
auto *isd = dyn_cast<InputSectionDescription>(base);
if (!isd)
continue;
@@ -1842,7 +1842,7 @@ static void removeUnusedSyntheticSections() {
// If we reach here, then ss is an unused synthetic section and we want
// to remove it from the corresponding input section description, and
// orphanSections.
- for (BaseCommand *b : os->sectionCommands)
+ for (BaseCommand *b : os->commands)
if (auto *isd = dyn_cast<InputSectionDescription>(b))
isdSet.insert(isd);
More information about the llvm-commits
mailing list