Skip to content

Commit a821fee

Browse files
committed
[ELF] scanRelocations: support .crel.eh_frame
Follow-up to llvm#98115. For EhInputSection, RelocationScanner::scan calls sortRels, which doesn't support the CREL iterator. We should set supportsCrel to false to ensure that the initial_location fields in .eh_frame FDEs are relocated.
1 parent 88a8594 commit a821fee

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lld/ELF/Relocations.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,8 @@ class OffsetGetter {
459459
// InputSectionBase.
460460
class RelocationScanner {
461461
public:
462-
template <class ELFT> void scanSection(InputSectionBase &s);
462+
template <class ELFT>
463+
void scanSection(InputSectionBase &s, bool isEH = false);
463464

464465
private:
465466
InputSectionBase *sec;
@@ -1617,10 +1618,11 @@ void RelocationScanner::scan(Relocs<RelTy> rels) {
16171618
});
16181619
}
16191620

1620-
template <class ELFT> void RelocationScanner::scanSection(InputSectionBase &s) {
1621+
template <class ELFT>
1622+
void RelocationScanner::scanSection(InputSectionBase &s, bool isEH) {
16211623
sec = &s;
16221624
getter = OffsetGetter(s);
1623-
const RelsOrRelas<ELFT> rels = s.template relsOrRelas<ELFT>();
1625+
const RelsOrRelas<ELFT> rels = s.template relsOrRelas<ELFT>(!isEH);
16241626
if (rels.areRelocsCrel())
16251627
scan<ELFT>(rels.crels);
16261628
else if (rels.areRelocsRel())
@@ -1658,7 +1660,7 @@ template <class ELFT> void elf::scanRelocations() {
16581660
RelocationScanner scanner;
16591661
for (Partition &part : partitions) {
16601662
for (EhInputSection *sec : part.ehFrame->sections)
1661-
scanner.template scanSection<ELFT>(*sec);
1663+
scanner.template scanSection<ELFT>(*sec, /*isEH=*/true);
16621664
if (part.armExidx && part.armExidx->isLive())
16631665
for (InputSection *sec : part.armExidx->exidxSections)
16641666
if (sec->isLive())

lld/test/ELF/crel.s

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# RUN: ld.lld -pie a.o b.o -o out
66
# RUN: llvm-objdump -d out | FileCheck %s
77
# RUN: llvm-readelf -Srs out | FileCheck %s --check-prefix=RELOC
8+
# RUN: llvm-dwarfdump --eh-frame out | FileCheck %s --check-prefix=UNWIND
89

910
# CHECK: <_start>:
1011
# CHECK-NEXT: callq {{.*}} <foo>
@@ -18,6 +19,13 @@
1819

1920
# RELOC: {{0*}}[[#DATA+8]] 0000000000000008 R_X86_64_RELATIVE [[#%x,DATA+0x8000000000000000]]
2021

22+
# RELOC: 00000000000012f4 0 NOTYPE GLOBAL DEFAULT [[#]] _start
23+
# RELOC-NEXT: 00000000000012fe 0 NOTYPE GLOBAL DEFAULT [[#]] foo
24+
25+
## initial_location fields in FDEs are correctly relocated.
26+
# UNWIND: 00000018 00000010 0000001c FDE cie=00000000 pc=000012f4...000012fe
27+
# UNWIND: 0000002c 00000010 00000030 FDE cie=00000000 pc=000012fe...0000130c
28+
2129
# RUN: ld.lld -pie --emit-relocs a.o b.o -o out1
2230
# RUN: llvm-objdump -dr out1 | FileCheck %s --check-prefix=CHECKE
2331
# RUN: llvm-readelf -Sr out1 | FileCheck %s --check-prefix=RELOCE

0 commit comments

Comments
 (0)