@@ -245,10 +245,13 @@ void ICF<ELFT>::segregate(size_t begin, size_t end, uint32_t eqClassBase,
245245template <class ELFT >
246246template <class RelTy >
247247bool ICF<ELFT>::isTrivialRelocation(InputSection *a, Symbol &s, RelTy reloc) {
248- OffsetGetter getter (*a);
249- uint64_t offset = getter.get (ctx, reloc.r_offset );
248+ // For our use cases, we can get by without calculating exact location within
249+ // the section, and just use fake location array. We need to ensure validity
250+ // for loc[-1] to loc[3] as various targets' getRelExpr() reference them.
251+ std::array<uint8_t , 5 > fakeLocArray;
252+ uint8_t *fakeLoc = fakeLocArray.data () + 1 ;
250253 RelExpr expr = ctx.target ->getRelExpr (reloc.getType (ctx.arg .isMips64EL ), s,
251- a-> content (). data () + offset );
254+ fakeLoc );
252255
253256 if (needsGot (expr) || needsTls (s, expr))
254257 return false ;
@@ -412,7 +415,7 @@ bool ICF<ELFT>::variableEq(InputSection *secA, Relocs<RelTy> ra,
412415 // getting merged into each other (done later in ICF). We do this as
413416 // post-ICF passes cannot handle duplicates when iterating over local
414417 // symbols. There are also assertions that prevent this.
415- if ((! da->isGlobal () || ! db->isGlobal ()) &&
418+ if ((da->isLocal () || db->isLocal ()) &&
416419 !isTrivialRelocation (secA, sa, *rai))
417420 return false ;
418421
0 commit comments