[Mips] Support R_MIPS_HIGHER / R_MIPS_HIGHEST relocations handling
authorSimon Atanasyan <simon@atanasyan.com>
Mon, 22 Jun 2015 09:25:57 +0000 (09:25 +0000)
committerSimon Atanasyan <simon@atanasyan.com>
Mon, 22 Jun 2015 09:25:57 +0000 (09:25 +0000)
llvm-svn: 240259

lld/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
lld/test/elf/Mips/rel-high-01.test [new file with mode: 0644]

index e7a57e6..42fdc77 100644 (file)
@@ -100,6 +100,8 @@ static MipsRelocationParams getRelocationParams(uint32_t rType) {
   case R_MIPS_HI16:
     return {4, 0xffff, 0, false, gpDispCheck<16>};
   case R_MIPS_LO16:
+  case R_MIPS_HIGHER:
+  case R_MIPS_HIGHEST:
     return {4, 0xffff, 0, false, dummyCheck};
   case R_MIPS_16:
   case R_MIPS_PCHI16:
@@ -195,6 +197,14 @@ static int64_t getHi16(int64_t value) {
   return ((value + 0x8000) >> 16) & 0xffff;
 }
 
+static int64_t getHigher16(int64_t value) {
+  return ((value + 0x80008000ull) >> 32) & 0xffff;
+}
+
+static int64_t getHighest16(int64_t value) {
+  return ((value + 0x800080008000ull) >> 48) & 0xffff;
+}
+
 static int64_t maskLow16(int64_t value) {
   return (value + 0x8000) & ~0xffff;
 }
@@ -382,6 +392,10 @@ static ErrorOr<int64_t> calculateRelocation(Reference::KindValue kind,
   case R_MICROMIPS_GOT_HI16:
   case R_MICROMIPS_CALL_HI16:
     return getHi16(tgtAddr - gpAddr);
+  case R_MIPS_HIGHER:
+    return getHigher16(tgtAddr + addend);
+  case R_MIPS_HIGHEST:
+    return getHighest16(tgtAddr + addend);
   case R_MIPS_EH:
   case R_MIPS_GOT16:
   case R_MIPS_CALL16:
diff --git a/lld/test/elf/Mips/rel-high-01.test b/lld/test/elf/Mips/rel-high-01.test
new file mode 100644 (file)
index 0000000..f15f16a
--- /dev/null
@@ -0,0 +1,55 @@
+# Check handling R_MIPS_HIGHER / R_MIPS_HIGHEST relocations.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor gnu -target mips64el -e T0 -o %t.exe %t.o
+# RUN: llvm-nm %t.exe | FileCheck -check-prefix=SYM %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=RAW %s
+
+# SYM: 00000001200001a0 T T0
+# SYM: 00000001200001a8 T T1
+
+# RAW:      Contents of section .text:
+# RAW-NEXT:  1200001a0 02800000 00000000 01400000 00000000
+
+FileHeader:
+  Class:    ELFCLASS64
+  Data:     ELFDATA2LSB
+  Type:     ET_REL
+  Machine:  EM_MIPS
+  Flags:    [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+  - Name:          .text
+    Type:          SHT_PROGBITS
+    Flags:         [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:  16
+    Size:          16
+
+  - Name:          .rela.text
+    Type:          SHT_RELA
+    Flags:         [ SHF_INFO_LINK ]
+    Link:          .symtab
+    AddressAlign:  8
+    Info:          .text
+    Relocations:
+      - Offset:  0
+        Symbol:  T1
+        Type:    R_MIPS_HIGHER
+        Addend:  0x0000800100000000
+      - Offset:  8
+        Symbol:  T1
+        Type:    R_MIPS_HIGHEST
+        Addend:  0x4001000000000000
+
+Symbols:
+  Global:
+    - Name:     T0
+      Type:     STT_FUNC
+      Section:  .text
+      Value:    0
+      Size:     8
+    - Name:     T1
+      Type:     STT_FUNC
+      Section:  .text
+      Value:    8
+      Size:     8