@@ -334,26 +334,27 @@ bool ICF<ELFT>::equalsConstant(const InputSection *a, const InputSection *b) {
334
334
: constantEq (a, ra.relas , b, rb.relas );
335
335
}
336
336
337
- template <class RelTy >
338
- static SmallVector<Symbol *> getReloc (const InputSection *sec,
337
+ template <class ELFT , class RelTy >
338
+ static SmallVector<std::pair< Symbol *, uint64_t > > getReloc (const InputSection *sec,
339
339
Relocs<RelTy> relocs) {
340
- SmallVector<Symbol *> syms;
340
+ SmallVector<std::pair< Symbol *, uint64_t > > syms;
341
341
for (auto ri = relocs.begin (), re = relocs.end (); ri != re; ++ri) {
342
342
Symbol &sym = sec->file ->getRelocTargetSym (*ri);
343
- syms.push_back (&sym);
343
+ uint64_t addend = getAddend<ELFT>(*ri);
344
+ syms.push_back (std::make_pair (&sym, addend));
344
345
}
345
346
return syms;
346
347
}
347
348
348
349
template <class ELFT >
349
- static SmallVector<Symbol *> getRelocTargetSyms (const InputSection *sec) {
350
+ static SmallVector<std::pair< Symbol *, uint64_t >> getRelocTargets (const InputSection *sec) {
350
351
const RelsOrRelas<ELFT> rel = sec->template relsOrRelas <ELFT>();
351
352
if (rel.areRelocsCrel ())
352
- return getReloc (sec, rel.crels );
353
+ return getReloc<ELFT> (sec, rel.crels );
353
354
if (rel.areRelocsRel ())
354
- return getReloc (sec, rel.rels );
355
+ return getReloc<ELFT> (sec, rel.rels );
355
356
356
- return getReloc (sec, rel.relas );
357
+ return getReloc<ELFT> (sec, rel.relas );
357
358
}
358
359
359
360
// Compare two lists of relocations. Returns true if all pairs of
@@ -568,19 +569,19 @@ template <class ELFT> void ICF<ELFT>::run() {
568
569
if (end - begin == 1 )
569
570
return ;
570
571
print () << " selected section " << sections[begin];
571
- SmallVector<Symbol *> syms = getRelocTargetSyms <ELFT>(sections[begin]);
572
+ SmallVector<std::pair< Symbol *, uint64_t >> syms = getRelocTargets <ELFT>(sections[begin]);
572
573
for (size_t i = begin + 1 ; i < end; ++i) {
573
574
print () << " removing identical section " << sections[i];
574
575
sections[begin]->replace (sections[i]);
575
- SmallVector<Symbol *> replacedSyms =
576
- getRelocTargetSyms <ELFT>(sections[i]);
576
+ SmallVector<std::pair< Symbol *, uint64_t > > replacedSyms =
577
+ getRelocTargets <ELFT>(sections[i]);
577
578
assert (syms.size () == replacedSyms.size () &&
578
579
" Should have same number of syms!" );
579
580
for (size_t i = 0 ; i < syms.size (); i++) {
580
- if (syms[i] == replacedSyms[i] || !syms[i]->isGlobal () ||
581
- !replacedSyms[i]->isGlobal ())
581
+ if (syms[i]. first == replacedSyms[i]. first || !syms[i]. first ->isGlobal () ||
582
+ !replacedSyms[i]. first ->isGlobal () || syms[i]. second != replacedSyms[i]. second )
582
583
continue ;
583
- symbolEquivalence.unionSets (syms[i], replacedSyms[i]);
584
+ symbolEquivalence.unionSets (syms[i]. first , replacedSyms[i]. first );
584
585
}
585
586
586
587
// At this point we know sections merged are fully identical and hence
0 commit comments