diff options
-rw-r--r-- | lld/ELF/InputSection.cpp | 9 | ||||
-rw-r--r-- | lld/ELF/InputSection.h | 2 | ||||
-rw-r--r-- | lld/test/ELF/mips-hilo-hi-only.s | 8 |
3 files changed, 14 insertions, 5 deletions
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 4d24dd9af78..f449e70003c 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -95,7 +95,8 @@ bool InputSection<ELFT>::classof(const InputSectionBase<ELFT> *S) { 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 @@ InputSectionBase<ELFT>::findMipsPairedReloc(uint8_t *Buf, uint32_t Type, 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 @@ void InputSectionBase<ELFT>::relocate(uint8_t *Buf, uint8_t *BufEnd, 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 @@ void InputSectionBase<ELFT>::relocate(uint8_t *Buf, uint8_t *BufEnd, 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)); } } diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index d72f9f23dd4..9924bc27de1 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -84,7 +84,7 @@ public: private: template <bool isRela> - uint8_t *findMipsPairedReloc(uint8_t *Buf, uint32_t Type, + uint8_t *findMipsPairedReloc(uint8_t *Buf, uint32_t SymIndex, uint32_t Type, RelIteratorRange<isRela> Rels); }; diff --git a/lld/test/ELF/mips-hilo-hi-only.s b/lld/test/ELF/mips-hilo-hi-only.s index e6aad8345aa..ad18a9f9161 100644 --- a/lld/test/ELF/mips-hilo-hi-only.s +++ b/lld/test/ELF/mips-hilo-hi-only.s @@ -10,6 +10,9 @@ .globl __start __start: lui $t0,%hi(__start+0x10000) + addi $t0,$t0,%lo(_label) +_label: + nop # WARN: Can't find matching R_MIPS_LO16 relocation for R_MIPS_HI16 @@ -17,6 +20,9 @@ __start: # CHECK-NEXT: __start: # CHECK-NEXT: 20000: 3c 08 00 02 lui $8, 2 # ^-- %hi(__start) w/o addend +# CHECK-NEXT 20004: 21 08 00 08 addi $8, $8, 8 +# ^-- %lo(_label) # CHECK: SYMBOL TABLE: -# CHECK: 0020000 .text 00000000 __start +# CHECK: 00020008 .text 00000000 _label +# CHECK: 00020000 .text 00000000 __start |