[ELF][MIPS] Match paired relocation using relocation type and symbol index
If we have R_MIPS_HI16 relocation, the paired relocation is the next
R_MIPS_LO16 relocation with the same symbol as a target.
llvm-svn: 255452
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 4d24dd9..f449e70 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -95,7 +95,8 @@
template <class ELFT>
template <bool isRela>
uint8_t *
-InputSectionBase<ELFT>::findMipsPairedReloc(uint8_t *Buf, uint32_t Type,
+InputSectionBase<ELFT>::findMipsPairedReloc(uint8_t *Buf, uint32_t SymIndex,
+ uint32_t Type,
RelIteratorRange<isRela> Rels) {
// Some MIPS relocations use addend calculated from addend of the relocation
// itself and addend of paired relocation. ABI requires to compute such
@@ -114,6 +115,8 @@
for (const auto &RI : Rels) {
if (RI.getType(Config->Mips64EL) != Type)
continue;
+ if (RI.getSymbol(Config->Mips64EL) != SymIndex)
+ continue;
uintX_t Offset = getOffset(RI.r_offset);
if (Offset == (uintX_t)-1)
return nullptr;
@@ -162,7 +165,7 @@
if (SymIndex < SymTab->sh_info) {
uintX_t SymVA = getLocalRelTarget(*File, RI);
Target->relocateOne(BufLoc, BufEnd, Type, AddrLoc, SymVA, 0,
- findMipsPairedReloc(Buf, Type, NextRelocs));
+ findMipsPairedReloc(Buf, SymIndex, Type, NextRelocs));
continue;
}
@@ -206,7 +209,7 @@
uintX_t A = getAddend<ELFT>(RI);
uintX_t Size = getSymSize<ELFT>(Body);
Target->relocateOne(BufLoc, BufEnd, Type, AddrLoc, SymVA + A, Size + A,
- findMipsPairedReloc(Buf, Type, NextRelocs));
+ findMipsPairedReloc(Buf, SymIndex, Type, NextRelocs));
}
}