[lld] r254092 - [ELF2][MIPS] Support R_MIPS_CALL16 relocation

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 25 12:58:53 PST 2015


Author: atanasyan
Date: Wed Nov 25 14:58:52 2015
New Revision: 254092

URL: http://llvm.org/viewvc/llvm-project?rev=254092&view=rev
Log:
[ELF2][MIPS] Support R_MIPS_CALL16 relocation

R_MIPS_CALL16 relocation provides the same result as R_MIPS_GOT16
relocation but does not need to check the result on overflow.

Differential Revision: http://reviews.llvm.org/D14916

Added:
    lld/trunk/test/ELF/mips-call16.s
Modified:
    lld/trunk/ELF/Target.cpp

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=254092&r1=254091&r2=254092&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Wed Nov 25 14:58:52 2015
@@ -116,6 +116,7 @@ public:
 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,
@@ -876,6 +877,11 @@ template <class ELFT> MipsTargetInfo<ELF
 }
 
 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);
@@ -895,7 +901,7 @@ void MipsTargetInfo<ELFT>::writePltEntry
 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>
@@ -913,9 +919,10 @@ void MipsTargetInfo<ELFT>::relocateOne(u
   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;

Added: lld/trunk/test/ELF/mips-call16.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-call16.s?rev=254092&view=auto
==============================================================================
--- lld/trunk/test/ELF/mips-call16.s (added)
+++ lld/trunk/test/ELF/mips-call16.s Wed Nov 25 14:58:52 2015
@@ -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: ]




More information about the llvm-commits mailing list