[lld] r255452 - [ELF][MIPS] Match paired relocation using relocation type and symbol index

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 12 22:49:08 PST 2015


Author: atanasyan
Date: Sun Dec 13 00:49:08 2015
New Revision: 255452

URL: http://llvm.org/viewvc/llvm-project?rev=255452&view=rev
Log:
[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.

Modified:
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/InputSection.h
    lld/trunk/test/ELF/mips-hilo-hi-only.s

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=255452&r1=255451&r2=255452&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Sun Dec 13 00:49:08 2015
@@ -95,7 +95,8 @@ bool InputSection<ELFT>::classof(const I
 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>::findMipsPairedRe
   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(ui
     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(ui
     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));
   }
 }
 

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=255452&r1=255451&r2=255452&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Sun Dec 13 00:49:08 2015
@@ -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);
 };
 

Modified: lld/trunk/test/ELF/mips-hilo-hi-only.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-hilo-hi-only.s?rev=255452&r1=255451&r2=255452&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-hilo-hi-only.s (original)
+++ lld/trunk/test/ELF/mips-hilo-hi-only.s Sun Dec 13 00:49:08 2015
@@ -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




More information about the llvm-commits mailing list