Skip to content

Commit cf70a1e

Browse files
committed
[ELF] .llvm.sympart: support CREL
When both CREL and the experimental lld partitions feature are enabled, the relocation section may look like .crel.llvm_sympart.f1, and `rels.relas` is empty. While here, support relocation sections with zero entry.
1 parent 62cdc2a commit cf70a1e

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lld/ELF/Driver.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,11 +2438,18 @@ static void readSymbolPartitionSection(InputSectionBase *s) {
24382438
// Read the relocation that refers to the partition's entry point symbol.
24392439
Symbol *sym;
24402440
const RelsOrRelas<ELFT> rels = s->template relsOrRelas<ELFT>();
2441-
if (rels.areRelocsRel())
2442-
sym = &s->file->getRelocTargetSym(rels.rels[0]);
2441+
auto readEntry = [](InputFile *file, const auto &rels) -> Symbol * {
2442+
for (const auto &rel : rels)
2443+
return &file->getRelocTargetSym(rel);
2444+
return nullptr;
2445+
};
2446+
if (rels.areRelocsCrel())
2447+
sym = readEntry(s->file, rels.crels);
2448+
else if (rels.areRelocsRel())
2449+
sym = readEntry(s->file, rels.rels);
24432450
else
2444-
sym = &s->file->getRelocTargetSym(rels.relas[0]);
2445-
if (!isa<Defined>(sym) || !sym->includeInDynsym())
2451+
sym = readEntry(s->file, rels.relas);
2452+
if (!isa_and_nonnull<Defined>(sym) || !sym->includeInDynsym())
24462453
return;
24472454

24482455
StringRef partName = reinterpret_cast<const char *>(s->content().data());

lld/test/ELF/partitions.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// RUN: ld.lld %t.o -o %t --export-dynamic --gc-sections -z max-page-size=65536
44
// RUN: llvm-readelf -S -s %t | FileCheck %s
55

6-
// RUN: llvm-mc %s -o %t.o -filetype=obj --triple=aarch64
6+
// RUN: llvm-mc %s -o %t.o -filetype=obj --triple=aarch64 --crel
77
// RUN: ld.lld %t.o -o %t --export-dynamic --gc-sections
88
// RUN: llvm-readelf -S -s %t | FileCheck %s
99

0 commit comments

Comments
 (0)