@@ -390,22 +390,17 @@ namespace {
390
390
class OffsetGetter {
391
391
public:
392
392
OffsetGetter () = default ;
393
- explicit OffsetGetter (InputSectionBase &sec) {
394
- if (auto *eh = dyn_cast<EhInputSection>(&sec)) {
395
- cies = eh->cies ;
396
- fdes = eh->fdes ;
397
- i = cies.begin ();
398
- j = fdes.begin ();
399
- }
393
+ explicit OffsetGetter (EhInputSection &sec) {
394
+ cies = sec.cies ;
395
+ fdes = sec.fdes ;
396
+ i = cies.begin ();
397
+ j = fdes.begin ();
400
398
}
401
399
402
400
// Translates offsets in input sections to offsets in output sections.
403
401
// Given offset must increase monotonically. We assume that Piece is
404
402
// sorted by inputOff.
405
403
uint64_t get (Ctx &ctx, uint64_t off) {
406
- if (cies.empty ())
407
- return off;
408
-
409
404
while (j != fdes.end () && j->inputOff <= off)
410
405
++j;
411
406
auto it = j;
@@ -435,13 +430,12 @@ class OffsetGetter {
435
430
class RelocationScanner {
436
431
public:
437
432
RelocationScanner (Ctx &ctx) : ctx(ctx) {}
438
- template <class ELFT >
439
- void scanSection (InputSectionBase &s, bool isEH = false );
433
+ template <class ELFT > void scanSection (InputSectionBase &s);
434
+ template < class ELFT > void scanEhSection (EhInputSection &s);
440
435
441
436
private:
442
437
Ctx &ctx;
443
438
InputSectionBase *sec;
444
- OffsetGetter getter;
445
439
446
440
// End of relocations, used by Mips/PPC64.
447
441
const void *end = nullptr ;
@@ -1496,9 +1490,7 @@ void RelocationScanner::scan(typename Relocs<RelTy>::const_iterator &i) {
1496
1490
}
1497
1491
}
1498
1492
// Get an offset in an output section this relocation is applied to.
1499
- uint64_t offset = getter.get (ctx, rel.r_offset );
1500
- if (offset == uint64_t (-1 ))
1501
- return ;
1493
+ uint64_t offset = rel.r_offset ;
1502
1494
1503
1495
RelExpr expr =
1504
1496
ctx.target ->getRelExpr (type, sym, sec->content ().data () + offset);
@@ -1634,13 +1626,10 @@ void RelocationScanner::scanSectionImpl(Relocs<RelTy> rels) {
1634
1626
if (ctx.arg .emachine == EM_PPC64)
1635
1627
checkPPC64TLSRelax<RelTy>(*sec, rels);
1636
1628
1637
- // For EhInputSection, OffsetGetter expects the relocations to be sorted by
1638
- // r_offset. In rare cases (.eh_frame pieces are reordered by a linker
1639
- // script), the relocations may be unordered.
1640
1629
// On SystemZ, all sections need to be sorted by r_offset, to allow TLS
1641
1630
// relaxation to be handled correctly - see SystemZ::getTlsGdRelaxSkip.
1642
1631
SmallVector<RelTy, 0 > storage;
1643
- if (isa<EhInputSection>(sec) || ctx.arg .emachine == EM_S390)
1632
+ if (ctx.arg .emachine == EM_S390)
1644
1633
rels = sortRels (rels, storage);
1645
1634
1646
1635
if constexpr (RelTy::IsCrel) {
@@ -1665,11 +1654,9 @@ void RelocationScanner::scanSectionImpl(Relocs<RelTy> rels) {
1665
1654
});
1666
1655
}
1667
1656
1668
- template <class ELFT >
1669
- void RelocationScanner::scanSection (InputSectionBase &s, bool isEH) {
1657
+ template <class ELFT > void RelocationScanner::scanSection (InputSectionBase &s) {
1670
1658
sec = &s;
1671
- getter = OffsetGetter (s);
1672
- const RelsOrRelas<ELFT> rels = s.template relsOrRelas <ELFT>(!isEH);
1659
+ const RelsOrRelas<ELFT> rels = s.template relsOrRelas <ELFT>();
1673
1660
if (rels.areRelocsCrel ())
1674
1661
scanSectionImpl<ELFT>(rels.crels );
1675
1662
else if (rels.areRelocsRel ())
@@ -1678,6 +1665,27 @@ void RelocationScanner::scanSection(InputSectionBase &s, bool isEH) {
1678
1665
scanSectionImpl<ELFT>(rels.relas );
1679
1666
}
1680
1667
1668
+ template <class ELFT > void RelocationScanner::scanEhSection (EhInputSection &s) {
1669
+ sec = &s;
1670
+ OffsetGetter getter (s);
1671
+ auto rels = s.rels ;
1672
+ s.relocations .reserve (rels.size ());
1673
+ for (auto &r : rels) {
1674
+ // Ignore R_*_NONE and other marker relocations.
1675
+ if (r.expr == R_NONE)
1676
+ continue ;
1677
+ uint64_t offset = getter.get (ctx, r.offset );
1678
+ // Skip if the relocation offset is within a dead piece.
1679
+ if (offset == uint64_t (-1 ))
1680
+ continue ;
1681
+ Symbol *sym = r.sym ;
1682
+ if (sym->isUndefined () &&
1683
+ maybeReportUndefined (ctx, cast<Undefined>(*sym), *sec, offset))
1684
+ continue ;
1685
+ process (r.expr , r.type , offset, *sym, r.addend );
1686
+ }
1687
+ }
1688
+
1681
1689
template <class ELFT > void elf::scanRelocations (Ctx &ctx) {
1682
1690
// Scan all relocations. Each relocation goes through a series of tests to
1683
1691
// determine if it needs special treatment, such as creating GOT, PLT,
@@ -1710,7 +1718,7 @@ template <class ELFT> void elf::scanRelocations(Ctx &ctx) {
1710
1718
RelocationScanner scanner (ctx);
1711
1719
for (Partition &part : ctx.partitions ) {
1712
1720
for (EhInputSection *sec : part.ehFrame ->sections )
1713
- scanner.template scanSection <ELFT>(*sec, /* isEH= */ true );
1721
+ scanner.template scanEhSection <ELFT>(*sec);
1714
1722
if (part.armExidx && part.armExidx ->isLive ())
1715
1723
for (InputSection *sec : part.armExidx ->exidxSections )
1716
1724
if (sec->isLive ())
0 commit comments