[PATCH] D17809: [mips] Extend MipsAsmParser class to handle expressions in the %tprel / %dtprel relocations

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 2 07:39:44 PST 2016


atanasyan created this revision.
atanasyan added reviewers: dsanders, vkalintiris.
atanasyan added a subscriber: llvm-commits.
atanasyan set the repository for this revision to rL LLVM.
Herald added a subscriber: dsanders.

Now the asm parser supports %tprel_hi/lo and %dtprel_hi/lo relocations with a symbol argument only. But expressions like `sym + const` are valid also and accepted by GAS.

Repository:
  rL LLVM

http://reviews.llvm.org/D17809

Files:
  lib/Target/Mips/AsmParser/MipsAsmParser.cpp
  test/MC/Mips/tprel-hi-lo-expr.s

Index: test/MC/Mips/tprel-hi-lo-expr.s
===================================================================
--- /dev/null
+++ test/MC/Mips/tprel-hi-lo-expr.s
@@ -0,0 +1,26 @@
+# Check that llvm-mc accepts arithmetic expression as an argument
+# of the %tprel_hi, %tprel_lo relocations.
+
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s \
+# RUN:   | llvm-objdump -d -r - | FileCheck %s
+
+  .text
+foo:
+  lui     $3,%tprel_hi($loc+0x10004)
+# CHECK: 0:       3c 03 00 01     lui   $3, 1
+# CHECK:                  00000000:  R_MIPS_TLS_TPREL_HI16    $loc
+  addiu   $3,$3,%tprel_lo($loc+0x10004)
+# CHECK: 4:       24 63 00 04     addiu $3, $3, 4
+# CHECK:                  00000004:  R_MIPS_TLS_TPREL_LO16    $loc
+  lui     $3,%dtprel_hi($loc+0x10004)
+# CHECK: 8:       3c 03 00 01     lui   $3, 1
+# CHECK:                  00000008:  R_MIPS_TLS_DTPREL_HI16   $loc
+  addiu   $3,$3,%dtprel_lo($loc+0x10004)
+# CHECK: c:       24 63 00 04     addiu $3, $3, 4
+# CHECK:                  0000000c:  R_MIPS_TLS_DTPREL_LO16   $loc
+
+  .section .tdata,"awT",%progbits
+$loc:
+  .word 0
+  .space 0x10000
+  .word 0
Index: lib/Target/Mips/AsmParser/MipsAsmParser.cpp
===================================================================
--- lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -4078,10 +4078,14 @@
     int16_t Val;
     switch (getVariantKind(RelocStr)) {
     case MCSymbolRefExpr::VK_Mips_ABS_LO:
+    case MCSymbolRefExpr::VK_Mips_DTPREL_LO:
+    case MCSymbolRefExpr::VK_Mips_TPREL_LO:
       // Get the 1st 16-bits.
       Val = MCE->getValue() & 0xffff;
       break;
     case MCSymbolRefExpr::VK_Mips_ABS_HI:
+    case MCSymbolRefExpr::VK_Mips_DTPREL_HI:
+    case MCSymbolRefExpr::VK_Mips_TPREL_HI:
     case MCSymbolRefExpr::VK_Mips_GOT:
       // Get the 2nd 16-bits. Also add 1 if bit 15 is 1, to compensate for low
       // 16 bits being negative.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17809.49621.patch
Type: text/x-patch
Size: 1930 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160302/ec4b71a3/attachment.bin>


More information about the llvm-commits mailing list