[lld] c729736 - [ELF] Combine EhInputSection removal and MergeInputSection removal. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 29 00:40:01 PDT 2022
Author: Fangrui Song
Date: 2022-07-29T00:39:57-07:00
New Revision: c72973608d034e7222957b1cb2f712ddbca8c253
URL: https://github.com/llvm/llvm-project/commit/c72973608d034e7222957b1cb2f712ddbca8c253
DIFF: https://github.com/llvm/llvm-project/commit/c72973608d034e7222957b1cb2f712ddbca8c253.diff
LOG: [ELF] Combine EhInputSection removal and MergeInputSection removal. NFC
Added:
Modified:
lld/ELF/ICF.cpp
lld/ELF/LinkerScript.cpp
lld/ELF/Target.cpp
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp
index 64fb6cb5cd97..9322c7500675 100644
--- a/lld/ELF/ICF.cpp
+++ b/lld/ELF/ICF.cpp
@@ -478,8 +478,8 @@ template <class ELFT> void ICF<ELFT>::run() {
// Collect sections to merge.
for (InputSectionBase *sec : inputSections) {
- auto *s = cast<InputSection>(sec);
- if (s->eqClass[0] == 0) {
+ auto *s = dyn_cast<InputSection>(sec);
+ if (s && s->eqClass[0] == 0) {
if (isEligible(s))
sections.push_back(s);
else
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 6028652b2b20..7e41b622beb5 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -848,8 +848,11 @@ void LinkerScript::addOrphanSections() {
// for synthetic sections because them are special.
size_t n = 0;
for (InputSectionBase *isec : inputSections) {
- if (!isa<MergeInputSection>(isec))
+ // Process InputSection and MergeInputSection. Discard EhInputSection.
+ 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
@@ -867,6 +870,7 @@ void LinkerScript::addOrphanSections() {
if (depSec->flags & SHF_LINK_ORDER)
add(depSec);
}
+ // Keep just InputSection.
inputSections.resize(n);
// If no SECTIONS command was given, we should insert sections commands
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp
index 7bc5121eabe4..cfc160e0892d 100644
--- a/lld/ELF/Target.cpp
+++ b/lld/ELF/Target.cpp
@@ -94,8 +94,8 @@ TargetInfo *elf::getTarget() {
ErrorPlace elf::getErrorPlace(const uint8_t *loc) {
assert(loc != nullptr);
for (InputSectionBase *d : inputSections) {
- auto *isec = cast<InputSection>(d);
- if (!isec->getParent() || (isec->type & SHT_NOBITS))
+ auto *isec = dyn_cast<InputSection>(d);
+ if (!isec || !isec->getParent() || (isec->type & SHT_NOBITS))
continue;
const uint8_t *isecLoc =
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index c14cad34450d..814eac07b24a 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -152,14 +152,14 @@ void elf::combineEhSections() {
Partition &part = s->getPartition();
if (auto *es = dyn_cast<EhInputSection>(s)) {
part.ehFrame->addSection(es);
- s = nullptr;
} else if (s->kind() == SectionBase::Regular && part.armExidx &&
part.armExidx->addSection(cast<InputSection>(s))) {
s = nullptr;
}
}
- llvm::erase_value(inputSections, nullptr);
+ if (mainPart->armExidx)
+ llvm::erase_value(inputSections, nullptr);
}
static Defined *addOptionalRegular(StringRef name, SectionBase *sec,
More information about the llvm-commits
mailing list