[lld] r239959 - [Mips] Support R_MIPS_16 relocation handling

Simon Atanasyan simon at atanasyan.com
Wed Jun 17 15:27:40 PDT 2015


Author: atanasyan
Date: Wed Jun 17 17:27:39 2015
New Revision: 239959

URL: http://llvm.org/viewvc/llvm-project?rev=239959&view=rev
Log:
[Mips] Support R_MIPS_16 relocation handling

Added:
    lld/trunk/test/elf/Mips/rel-16-overflow.test
    lld/trunk/test/elf/Mips/rel-16.test
Modified:
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp?rev=239959&r1=239958&r2=239959&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp Wed Jun 17 17:27:39 2015
@@ -101,6 +101,7 @@ static MipsRelocationParams getRelocatio
     return {4, 0xffff, 0, false, gpDispCheck<16>};
   case R_MIPS_LO16:
     return {4, 0xffff, 0, false, dummyCheck};
+  case R_MIPS_16:
   case R_MIPS_PCHI16:
   case R_MIPS_PCLO16:
   case R_MIPS_GOT16:
@@ -438,6 +439,8 @@ static ErrorOr<int64_t> calculateRelocat
   switch (kind) {
   case R_MIPS_NONE:
     return 0;
+  case R_MIPS_16:
+    return tgtAddr + llvm::SignExtend32<16>(addend);
   case R_MIPS_32:
   case R_MIPS_64:
     return tgtAddr + addend;

Added: lld/trunk/test/elf/Mips/rel-16-overflow.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/rel-16-overflow.test?rev=239959&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/rel-16-overflow.test (added)
+++ lld/trunk/test/elf/Mips/rel-16-overflow.test Wed Jun 17 17:27:39 2015
@@ -0,0 +1,45 @@
+# Check R_MIPS_16 relocation overflow handling.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o 2>&1 \
+# RUN:       | FileCheck %s
+
+# CHECK: Relocation out of range in file {{.*}} reference from T0+0 to T1+32767 of type 1 (R_MIPS_16)
+
+FileHeader:
+  Class:   ELFCLASS32
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_MIPS
+  Flags:   [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name:         .text
+  Type:         SHT_PROGBITS
+  Content:      "ff7f00000000000000000000"
+#                                ^ T1
+#                ^ T0 A := 0x7fff
+  AddressAlign: 16
+  Flags:        [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name:         .rel.text
+  Type:         SHT_REL
+  Info:         .text
+  AddressAlign: 4
+  Relocations:
+    - Offset: 0
+      Symbol: T1
+      Type:   R_MIPS_16
+
+Symbols:
+  Global:
+    - Name:    T0
+      Section: .text
+      Type:    STT_FUNC
+      Value:   0
+      Size:    8
+    - Name:    T1
+      Section: .text
+      Type:    STT_FUNC
+      Value:   8
+      Size:    4

Added: lld/trunk/test/elf/Mips/rel-16.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/rel-16.test?rev=239959&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/rel-16.test (added)
+++ lld/trunk/test/elf/Mips/rel-16.test Wed Jun 17 17:27:39 2015
@@ -0,0 +1,51 @@
+# Check handling of R_MIPS_16 relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor gnu -target mipsel -shared -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 00f0 f0000000 00000000 00000000
+#                  ^ V = (T1 - 8) = T0
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 000000f0 g  F .text  00000008 T0
+# CHECK: 000000f8 g  F .text  00000004 T1
+
+FileHeader:
+  Class:   ELFCLASS32
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_MIPS
+  Flags:   [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name:         .text
+  Type:         SHT_PROGBITS
+  Content:      "f8ff00000000000000000000"
+#                                ^ T1
+#                ^ T0 A := 0xfff8 = -8
+  AddressAlign: 16
+  Flags:        [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name:         .rel.text
+  Type:         SHT_REL
+  Info:         .text
+  AddressAlign: 4
+  Relocations:
+    - Offset: 0
+      Symbol: T1
+      Type:   R_MIPS_16
+
+Symbols:
+  Global:
+    - Name:    T0
+      Section: .text
+      Type:    STT_FUNC
+      Value:   0
+      Size:    8
+    - Name:    T1
+      Section: .text
+      Type:    STT_FUNC
+      Value:   8
+      Size:    4





More information about the llvm-commits mailing list