Skip to content

Commit 5d928ff

Browse files
committed
[ELF] Remove error-prone RelocationBaseSection::classof
1 parent 861bd36 commit 5d928ff

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

lld/ELF/OutputSections.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,11 @@ void OutputSection::checkDynRelAddends(Ctx &ctx) {
882882
// for input .rel[a].<sec> sections which we simply pass through to the
883883
// output. We skip over those and only look at the synthetic relocation
884884
// sections created during linking.
885-
const auto *sec = dyn_cast<RelocationBaseSection>(sections[i]);
885+
if (!SyntheticSection::classof(sections[i]) ||
886+
!is_contained({ELF::SHT_REL, ELF::SHT_RELA, ELF::SHT_RELR},
887+
sections[i]->type))
888+
return;
889+
const auto *sec = cast<RelocationBaseSection>(sections[i]);
886890
if (!sec)
887891
return;
888892
for (const DynamicReloc &rel : sec->relocs) {

lld/ELF/SyntheticSections.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -547,13 +547,7 @@ class RelocationBaseSection : public SyntheticSection {
547547
void mergeRels();
548548
void partitionRels();
549549
void finalizeContents() override;
550-
static bool classof(const SectionBase *d) {
551-
return SyntheticSection::classof(d) &&
552-
(d->type == llvm::ELF::SHT_RELA || d->type == llvm::ELF::SHT_REL ||
553-
d->type == llvm::ELF::SHT_RELR ||
554-
(d->type == llvm::ELF::SHT_AARCH64_AUTH_RELR &&
555-
elf::ctx.arg.emachine == llvm::ELF::EM_AARCH64));
556-
}
550+
557551
int32_t dynamicTag, sizeDynamicTag;
558552
SmallVector<DynamicReloc, 0> relocs;
559553

lld/ELF/Writer.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,10 +1690,9 @@ static void removeUnusedSyntheticSections(Ctx &ctx) {
16901690
// finalizeAddressDependentContent, making .rela.dyn no longer empty.
16911691
// Conservatively keep .rela.dyn. .relr.auth.dyn can be made empty, but
16921692
// we would fail to remove it here.
1693-
if (ctx.arg.emachine == EM_AARCH64 && ctx.arg.relrPackDynRelocs)
1694-
if (auto *relSec = dyn_cast<RelocationBaseSection>(sec))
1695-
if (relSec == ctx.mainPart->relaDyn.get())
1696-
return false;
1693+
if (ctx.arg.emachine == EM_AARCH64 && ctx.arg.relrPackDynRelocs &&
1694+
sec == ctx.mainPart->relaDyn.get())
1695+
return false;
16971696
unused.insert(sec);
16981697
return true;
16991698
});

0 commit comments

Comments
 (0)