aboutsummaryrefslogtreecommitdiff
path: root/lld/ELF/OutputSections.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/ELF/OutputSections.cpp')
-rw-r--r--lld/ELF/OutputSections.cpp48
1 files changed, 23 insertions, 25 deletions
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index cc4f0688701a..a17f713b742a 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -33,7 +33,6 @@ using namespace lld;
using namespace lld::elf;
uint8_t *Out::bufferStart;
-uint8_t Out::first;
PhdrEntry *Out::tlsPhdr;
OutputSection *Out::elfHeader;
OutputSection *Out::programHeaders;
@@ -69,7 +68,7 @@ void OutputSection::writeHeaderTo(typename ELFT::Shdr *shdr) {
}
OutputSection::OutputSection(StringRef name, uint32_t type, uint64_t flags)
- : BaseCommand(OutputSectionKind),
+ : SectionCommand(OutputSectionKind),
SectionBase(Output, name, flags, /*Entsize*/ 0, /*Alignment*/ 1, type,
/*Info*/ 0, /*Link*/ 0) {}
@@ -100,10 +99,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,15 +164,15 @@ 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) {
- auto *cmd = dyn_cast<InputSectionDescription>(base);
- if (!cmd)
+ for (SectionCommand *cmd : commands) {
+ auto *isd = dyn_cast<InputSectionDescription>(cmd);
+ if (!isd)
continue;
- cmd->sections.reserve(cmd->sectionBases.size());
- for (InputSectionBase *s : cmd->sectionBases) {
+ isd->sections.reserve(isd->sectionBases.size());
+ for (InputSectionBase *s : isd->sectionBases) {
MergeInputSection *ms = dyn_cast<MergeInputSection>(s);
if (!ms) {
- cmd->sections.push_back(cast<InputSection>(s));
+ isd->sections.push_back(cast<InputSection>(s));
continue;
}
@@ -203,17 +201,17 @@ void OutputSection::finalizeInputSections() {
mergeSections.push_back(syn);
i = std::prev(mergeSections.end());
syn->entsize = ms->entsize;
- cmd->sections.push_back(syn);
+ isd->sections.push_back(syn);
}
(*i)->addSection(ms);
}
// sectionBases should not be used from this point onwards. Clear it to
// catch misuses.
- cmd->sectionBases.clear();
+ isd->sectionBases.clear();
// Some input sections may be removed from the list after ICF.
- for (InputSection *s : cmd->sections)
+ for (InputSection *s : isd->sections)
commitSection(s);
}
for (auto *ms : mergeSections)
@@ -237,13 +235,13 @@ uint64_t elf::getHeaderSize() {
return Out::elfHeader->size + Out::programHeaders->size;
}
-bool OutputSection::classof(const BaseCommand *c) {
+bool OutputSection::classof(const SectionCommand *c) {
return c->kind == OutputSectionKind;
}
void OutputSection::sort(llvm::function_ref<int(InputSectionBase *s)> order) {
assert(isLive());
- for (BaseCommand *b : sectionCommands)
+ for (SectionCommand *b : commands)
if (auto *isd = dyn_cast<InputSectionDescription>(b))
sortByOrder(isd->sections, order);
}
@@ -367,8 +365,8 @@ 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)
- if (auto *data = dyn_cast<ByteCommand>(base))
+ for (SectionCommand *cmd : commands)
+ if (auto *data = dyn_cast<ByteCommand>(cmd))
writeInt(buf + data->offset, data->expression().getValue(), data->size);
}
@@ -485,8 +483,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(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,8 +503,8 @@ int elf::getPriority(StringRef s) {
}
InputSection *elf::getFirstInputSection(const OutputSection *os) {
- for (BaseCommand *base : os->sectionCommands)
- if (auto *isd = dyn_cast<InputSectionDescription>(base))
+ for (SectionCommand *cmd : os->commands)
+ if (auto *isd = dyn_cast<InputSectionDescription>(cmd))
if (!isd->sections.empty())
return isd->sections[0];
return nullptr;
@@ -514,8 +512,8 @@ InputSection *elf::getFirstInputSection(const OutputSection *os) {
std::vector<InputSection *> elf::getInputSections(const OutputSection *os) {
std::vector<InputSection *> ret;
- for (BaseCommand *base : os->sectionCommands)
- if (auto *isd = dyn_cast<InputSectionDescription>(base))
+ for (SectionCommand *cmd : os->commands)
+ if (auto *isd = dyn_cast<InputSectionDescription>(cmd))
ret.insert(ret.end(), isd->sections.begin(), isd->sections.end());
return ret;
}