[ELF] Move EhInputSection out of inputSections. NFC

inputSections temporarily contains EhInputSection objects mainly for
combineEhSections. Place EhInputSection objects into a new vector
ehInputSections instead of inputSections.
This commit is contained in:
Fangrui Song 2022-07-31 11:58:08 -07:00
parent 02b3a35892
commit c09d323599
7 changed files with 43 additions and 42 deletions

View File

@ -96,6 +96,7 @@ bool elf::link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
ctx->e.initialize(stdoutOS, stderrOS, exitEarly, disableOutput);
ctx->e.cleanupCallback = []() {
inputSections.clear();
ehInputSections.clear();
outputSections.clear();
symAux.clear();
@ -2655,10 +2656,16 @@ void LinkerDriver::link(opt::InputArgList &args) {
// Now that we have a complete list of input files.
// Beyond this point, no new files are added.
// Aggregate all input sections into one place.
for (InputFile *f : ctx->objectFiles)
for (InputSectionBase *s : f->getSections())
if (s && s != &InputSection::discarded)
for (InputFile *f : ctx->objectFiles) {
for (InputSectionBase *s : f->getSections()) {
if (!s || s == &InputSection::discarded)
continue;
if (LLVM_UNLIKELY(isa<EhInputSection>(s)))
ehInputSections.push_back(cast<EhInputSection>(s));
else
inputSections.push_back(s);
}
}
for (BinaryFile *f : ctx->binaryFiles)
for (InputSectionBase *s : f->getSections())
inputSections.push_back(cast<InputSection>(s));

View File

@ -34,6 +34,7 @@ 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.

View File

@ -424,6 +424,7 @@ inline bool isDebugSection(const InputSectionBase &sec) {
// 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

View File

@ -848,11 +848,9 @@ void LinkerScript::addOrphanSections() {
// for synthetic sections because them are special.
size_t n = 0;
for (InputSectionBase *isec : inputSections) {
// Process InputSection and MergeInputSection. Discard EhInputSection.
// Process InputSection and MergeInputSection.
if (LLVM_LIKELY(isa<InputSection>(isec)))
inputSections[n++] = isec;
else if (isa<EhInputSection>(isec))
continue;
// 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

View File

@ -244,22 +244,18 @@ template <class ELFT> void MarkLive<ELFT>::run() {
for (StringRef s : script->referencedSymbols)
markSymbol(symtab->find(s));
// Mark .eh_frame sections as live because there are usually no relocations
// 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) {
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) {
// Mark .eh_frame sections as live because there are usually no relocations
// 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.
if (auto *eh = dyn_cast<EhInputSection>(sec)) {
eh->markLive();
const RelsOrRelas<ELFT> rels = eh->template relsOrRelas<ELFT>();
if (rels.areRelocsRel())
scanEhFrameSection(*eh, rels.rels);
else if (rels.relas.size())
scanEhFrameSection(*eh, rels.relas);
continue;
}
if (sec->flags & SHF_GNU_RETAIN) {
enqueue(sec, 0);
continue;

View File

@ -3364,23 +3364,20 @@ template <class ELFT> void elf::splitSections() {
void elf::combineEhSections() {
llvm::TimeTraceScope timeScope("Combine EH sections");
for (InputSectionBase *&s : inputSections) {
for (EhInputSection *sec : ehInputSections)
sec->getPartition().ehFrame->addSection(sec);
if (!mainPart->armExidx)
return;
llvm::erase_if(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)
continue;
return false;
Partition &part = s->getPartition();
if (auto *es = dyn_cast<EhInputSection>(s)) {
part.ehFrame->addSection(es);
} else if (s->kind() == SectionBase::Regular && part.armExidx &&
part.armExidx->addSection(cast<InputSection>(s))) {
s = nullptr;
}
}
if (mainPart->armExidx)
llvm::erase_value(inputSections, nullptr);
return s->kind() == SectionBase::Regular && part.armExidx &&
part.armExidx->addSection(cast<InputSection>(s));
});
}
MipsRldMapSection::MipsRldMapSection()

View File

@ -121,20 +121,21 @@ static void removeEmptyPTLoad(SmallVector<PhdrEntry *, 0> &phdrs) {
void elf::copySectionsIntoPartitions() {
SmallVector<InputSectionBase *, 0> newSections;
const size_t ehSize = ehInputSections.size();
for (unsigned part = 2; part != partitions.size() + 1; ++part) {
for (InputSectionBase *s : inputSections) {
if (!(s->flags & SHF_ALLOC) || !s->isLive())
continue;
InputSectionBase *copy;
if (s->type == SHT_NOTE)
copy = make<InputSection>(cast<InputSection>(*s));
else if (auto *es = dyn_cast<EhInputSection>(s))
copy = make<EhInputSection>(*es);
else
if (!(s->flags & SHF_ALLOC) || !s->isLive() || s->type != SHT_NOTE)
continue;
auto *copy = make<InputSection>(cast<InputSection>(*s));
copy->partition = part;
newSections.push_back(copy);
}
for (size_t i = 0; i != ehSize; ++i) {
assert(ehInputSections[i]->isLive());
auto *copy = make<EhInputSection>(*ehInputSections[i]);
copy->partition = part;
ehInputSections.push_back(copy);
}
}
inputSections.insert(inputSections.end(), newSections.begin(),