[PATCH] D14950: [ELF2][MIPS] Support R_MIPS_CALL16 relocation

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 24 21:09:43 PST 2015


atanasyan updated this revision to Diff 41107.
atanasyan added a comment.

Removed checking for R_MIPS_CALL16 target symbol (local/global). Now we just calculate and apply the relocation.


Repository:
  rL LLVM

http://reviews.llvm.org/D14950

Files:
  ELF/Target.cpp
  test/ELF/mips-call16.s

Index: test/ELF/mips-call16.s
===================================================================
--- /dev/null
+++ test/ELF/mips-call16.s
@@ -0,0 +1,40 @@
+# Check R_MIPS_CALL16 relocation calculation.
+
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o
+# RUN: ld.lld %t.o -shared -o %t.exe
+# RUN: llvm-objdump -d %t.exe | FileCheck %s
+# RUN: llvm-readobj -mips-plt-got -symbols %t.exe \
+# RUN:   | FileCheck -check-prefix=GOT %s
+
+# REQUIRES: mips
+
+  .text
+  .globl  __start
+__start:
+  lw      $t0,%call16(g1)($gp)
+
+  .globl g1
+  .type  g1, at function
+g1:
+  nop
+
+# CHECK:      Disassembly of section .text:
+# CHECK-NEXT: __start:
+# CHECK-NEXT:      10000:   8f 88 80 18   lw   $8, -32744
+
+# GOT:      Name: g1
+# GOT-NEXT: Value: 0x[[ADDR:[0-9A-F]+]]
+
+# GOT:      Local entries [
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT:   Entry {
+# GOT-NEXT:     Address:
+# GOT-NEXT:     Access: -32744
+# GOT-NEXT:     Initial: 0x[[ADDR]]
+# GOT-NEXT:     Value: 0x[[ADDR]]
+# GOT-NEXT:     Type: Function
+# GOT-NEXT:     Section: .text
+# GOT-NEXT:     Name: g1
+# GOT-NEXT:   }
+# GOT-NEXT: ]
Index: ELF/Target.cpp
===================================================================
--- ELF/Target.cpp
+++ ELF/Target.cpp
@@ -113,6 +113,7 @@
 template <class ELFT> class MipsTargetInfo final : public TargetInfo {
 public:
   MipsTargetInfo();
+  unsigned getGotRefReloc(unsigned Type) const override;
   void writeGotHeaderEntries(uint8_t *Buf) const override;
   void writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const override;
   void writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,
@@ -845,6 +846,11 @@
 }
 
 template <class ELFT>
+unsigned MipsTargetInfo<ELFT>::getGotRefReloc(unsigned Type) const {
+  return Type;
+}
+
+template <class ELFT>
 void MipsTargetInfo<ELFT>::writeGotHeaderEntries(uint8_t *Buf) const {
   typedef typename llvm::object::ELFFile<ELFT>::Elf_Off Elf_Off;
   auto *P = reinterpret_cast<Elf_Off *>(Buf);
@@ -864,7 +870,7 @@
 template <class ELFT>
 bool MipsTargetInfo<ELFT>::relocNeedsGot(uint32_t Type,
                                          const SymbolBody &S) const {
-  return Type == R_MIPS_GOT16;
+  return Type == R_MIPS_GOT16 || Type == R_MIPS_CALL16;
 }
 
 template <class ELFT>
@@ -882,9 +888,10 @@
   case R_MIPS_32:
     add32<E>(Loc, SA);
     break;
+  case R_MIPS_CALL16:
   case R_MIPS_GOT16: {
     int64_t V = SA - getMipsGpAddr<ELFT>();
-    if (!isInt<16>(V))
+    if (Type == R_MIPS_GOT16 && !isInt<16>(V))
       error("Relocation R_MIPS_GOT16 out of range");
     write32<E>(Loc, (read32<E>(Loc) & 0xffff0000) | (V & 0xffff));
     break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14950.41107.patch
Type: text/x-patch
Size: 2651 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151125/cc7caaf1/attachment.bin>


More information about the llvm-commits mailing list