[lld] r263712 - [ELF][MIPS] Support R_MIPS_TLS_DTPREL_HI16/LO16 and R_MIPS_TLS_TPREL_HI16/LO16 relocations

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 17 05:36:08 PDT 2016


Author: atanasyan
Date: Thu Mar 17 07:36:08 2016
New Revision: 263712

URL: http://llvm.org/viewvc/llvm-project?rev=263712&view=rev
Log:
[ELF][MIPS] Support R_MIPS_TLS_DTPREL_HI16/LO16 and R_MIPS_TLS_TPREL_HI16/LO16 relocations

That is initial and the most trivial patch to support TLS for MIPS targets.

Added:
    lld/trunk/test/ELF/mips-tls-hilo.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=263712&r1=263711&r2=263712&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Thu Mar 17 07:36:08 2016
@@ -1677,6 +1677,10 @@ void MipsTargetInfo<ELFT>::relocateOne(u
                                        uint32_t Type, uint64_t P, uint64_t S,
                                        uint64_t ZA, uint8_t *PairedLoc) const {
   const endianness E = ELFT::TargetEndianness;
+  // Thread pointer and DRP offsets from the start of TLS data area.
+  // https://www.linux-mips.org/wiki/NPTL
+  const uint32_t TPOffset = 0x7000;
+  const uint32_t DTPOffset = 0x8000;
   switch (Type) {
   case R_MIPS_32:
     add32<E>(Loc, S);
@@ -1747,6 +1751,18 @@ void MipsTargetInfo<ELFT>::relocateOne(u
   case R_MIPS_PCLO16:
     writeMipsLo16<E>(Loc, S + readSignedLo16<E>(Loc) - P);
     break;
+  case R_MIPS_TLS_DTPREL_HI16:
+    writeMipsHi16<E>(Loc, S - DTPOffset + readSignedLo16<E>(Loc));
+    break;
+  case R_MIPS_TLS_DTPREL_LO16:
+    writeMipsLo16<E>(Loc, S - DTPOffset + readSignedLo16<E>(Loc));
+    break;
+  case R_MIPS_TLS_TPREL_HI16:
+    writeMipsHi16<E>(Loc, S - TPOffset + readSignedLo16<E>(Loc));
+    break;
+  case R_MIPS_TLS_TPREL_LO16:
+    writeMipsLo16<E>(Loc, S - TPOffset + readSignedLo16<E>(Loc));
+    break;
   default:
     fatal("unrecognized reloc " + Twine(Type));
   }
@@ -1767,6 +1783,10 @@ bool MipsTargetInfo<ELFT>::isRelRelative
   case R_MIPS_64:
   case R_MIPS_HI16:
   case R_MIPS_LO16:
+  case R_MIPS_TLS_DTPREL_HI16:
+  case R_MIPS_TLS_DTPREL_LO16:
+  case R_MIPS_TLS_TPREL_HI16:
+  case R_MIPS_TLS_TPREL_LO16:
     return false;
   }
 }

Added: lld/trunk/test/ELF/mips-tls-hilo.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-tls-hilo.s?rev=263712&view=auto
==============================================================================
--- lld/trunk/test/ELF/mips-tls-hilo.s (added)
+++ lld/trunk/test/ELF/mips-tls-hilo.s Thu Mar 17 07:36:08 2016
@@ -0,0 +1,39 @@
+# Check MIPS R_MIPS_TLS_DTPREL_HI16/LO16 and R_MIPS_TLS_TPREL_HI16/LO16
+# relocations handling.
+
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o
+# RUN: ld.lld %t.o -o %t.exe
+# RUN: llvm-objdump -d -t %t.exe | FileCheck -check-prefix=DIS %s
+# RUN: llvm-readobj -r -mips-plt-got %t.exe | FileCheck %s
+
+# REQUIRES: mips
+
+# DIS:      __start:
+# DIS-NEXT:    20000:   24 62 00 00   addiu   $2, $3, 0
+#                       %hi(loc0 - .tdata - 0x8000) --^
+# DIS-NEXT:    20004:   24 62 80 00   addiu   $2, $3, -32768
+#                       %lo(loc0 - .tdata - 0x8000) --^
+# DIS-NEXT:    20008:   24 62 00 00   addiu   $2, $3, 0
+#                       %hi(loc0 - .tdata - 0x7000) --^
+# DIS-NEXT:    2000c:   24 62 90 00   addiu   $2, $3, -28672
+#                       %lo(loc0 - .tdata - 0x7000) --^
+
+# DIS: 00030000 l       .tdata          00000000 .tdata
+# DIS: 00030000 l       .tdata          00000000 loc0
+
+# CHECK:      Relocations [
+# CHECK-NEXT: ]
+# CHECK-NOT:  Primary GOT
+
+  .text
+  .globl  __start
+  .type __start, at function
+__start:
+  addiu $2, $3, %dtprel_hi(loc0)  # R_MIPS_TLS_DTPREL_HI16
+  addiu $2, $3, %dtprel_lo(loc0)  # R_MIPS_TLS_DTPREL_LO16
+  addiu $2, $3, %tprel_hi(loc0)   # R_MIPS_TLS_TPREL_HI16
+  addiu $2, $3, %tprel_lo(loc0)   # R_MIPS_TLS_TPREL_LO16
+
+ .section .tdata,"awT",%progbits
+loc0:
+ .word 0




More information about the llvm-commits mailing list