RISC-V: Support assembler modifier %got_pcrel_hi.
authorNelson Chu <nelson.chu@sifive.com>
Wed, 4 Mar 2020 05:08:05 +0000 (21:08 -0800)
committerJim Wilson <jimw@sifive.com>
Thu, 5 Mar 2020 01:11:37 +0000 (17:11 -0800)
gas/
* config/tc-riscv.c: Support the modifier %got_pcrel_hi.
* doc/c-riscv.texi: Add documentation.
* testsuite/gas/riscv/no-relax-reloc.d: Add test case for the new
modifier %got_pcrel_hi.
* testsuite/gas/riscv/no-relax-reloc.s: Likewise.
* testsuite/gas/riscv/relax-reloc.d: Likewise.
* testsuite/gas/riscv/relax-reloc.s: Likewise.

gas/ChangeLog
gas/config/tc-riscv.c
gas/doc/c-riscv.texi
gas/testsuite/gas/riscv/no-relax-reloc.d
gas/testsuite/gas/riscv/no-relax-reloc.s
gas/testsuite/gas/riscv/relax-reloc.d
gas/testsuite/gas/riscv/relax-reloc.s

index 179ebe789a61d4206aef773423c5c90460e17911..859f01fae7915fdf1bc21f4d504ec5ccd088f06d 100644 (file)
@@ -1,5 +1,14 @@
 2020-03-04  Nelson Chu  <nelson.chu@sifive.com>
 
+       * config/tc-riscv.c (percent_op_utype): Support the modifier
+       %got_pcrel_hi.
+       * doc/c-riscv.texi: Add documentation.
+       * testsuite/gas/riscv/no-relax-reloc.d: Add test case for the new
+       modifier %got_pcrel_hi.
+       * testsuite/gas/riscv/no-relax-reloc.s: Likewise.
+       * testsuite/gas/riscv/relax-reloc.d: Likewise.
+       * testsuite/gas/riscv/relax-reloc.s: Likewise.
+
        * doc/c-riscv.texi (relocation modifiers): Add documentation.
        (RISC-V-Formats): Update the section name from "Instruction Formats"
        to "RISC-V Instruction Formats".
index ddd4d1457f5d324b4f8f274baa3f6e99183ae9b6..168561e7b562e2a285dc2d812bf7b71a515628d2 100644 (file)
@@ -1308,6 +1308,7 @@ static const struct percent_op_match percent_op_utype[] =
 {
   {"%tprel_hi", BFD_RELOC_RISCV_TPREL_HI20},
   {"%pcrel_hi", BFD_RELOC_RISCV_PCREL_HI20},
+  {"%got_pcrel_hi", BFD_RELOC_RISCV_GOT_HI20},
   {"%tls_ie_pcrel_hi", BFD_RELOC_RISCV_TLS_GOT_HI20},
   {"%tls_gd_pcrel_hi", BFD_RELOC_RISCV_TLS_GD_HI20},
   {"%hi", BFD_RELOC_RISCV_HI20},
index 6e932dcb2443c9c68e0aaeea9b110f83cf3614a9..488cf56051fa5f73629503cb33a4866a098f1d48 100644 (file)
@@ -257,6 +257,23 @@ Or you can use the pseudo lla/lw/sw/... instruction to do this.
        lla  a0, @var{symbol}
 @end smallexample
 
+@item %got_pcrel_hi(@var{symbol})
+The high 20 bits of relative address between pc and the GOT entry of
+@var{symbol}.  This is usually used with the %pcrel_lo modifier to access
+the GOT entry.
+
+@smallexample
+@var{label}:
+       auipc      a0, %got_pcrel_hi(@var{symbol}) // R_RISCV_GOT_HI20
+       addi       a0, a0, %pcrel_lo(@var{label})  // R_RISCV_PCREL_LO12_I
+
+@var{label}:
+       auipc      a0, %got_pcrel_hi(@var{symbol}) // R_RISCV_GOT_HI20
+       load/store a0, %pcrel_lo(@var{label})(a0)  // R_RISCV_PCREL_LO12_I/S
+@end smallexample
+
+Also, the pseudo la instruction with PIC has similar behavior.
+
 @item %tprel_add(@var{symbol})
 This is used purely to associate the R_RISCV_TPREL_ADD relocation for
 TLS relaxation.  This one is only valid as the fourth operand to the normally
index 62f28e09275f97ea1d600ebb9505526a51e7dc37..c2ca1aa6e7213dcc6b82816398db1d5f87c23783 100644 (file)
@@ -9,4 +9,6 @@ RELOCATION RECORDS FOR .*
 0+4 R_RISCV_LO12_I.*
 0+8 R_RISCV_PCREL_HI20.*
 0+c R_RISCV_PCREL_LO12_I.*
-0+10 R_RISCV_CALL.*
+0+10 R_RISCV_GOT_HI20.*
+0+14 R_RISCV_PCREL_LO12_I.*
+0+18 R_RISCV_CALL.*
index 7f1a484fc2ec26fb33db60af78437433c3bea982..2aab995769c018f056a3934a2e87f36d9304a333 100644 (file)
@@ -2,7 +2,10 @@ target:
        lui     a5,%hi(target)
        lw      a5,%lo(target)(a5)
 
-        .LA0: auipc     a5,%pcrel_hi(bar)
-        lw      a0,%pcrel_lo(.LA0)(a5)
+       .LA0: auipc     a5,%pcrel_hi(symbol1)
+       lw      a0,%pcrel_lo(.LA0)(a5)
+
+       .LA1: auipc     a5,%got_pcrel_hi(symbol2)
+       lw      a0,%pcrel_lo(.LA1)(a5)
 
        call target
index f5f592ce036f5bcb8ee24b4c50e13fc2b58784f5..623218ec5d15271d002e1186c9b6a26df8d1f49e 100644 (file)
@@ -13,5 +13,8 @@ RELOCATION RECORDS FOR .*
 0+8 R_RISCV_RELAX.*
 0+c R_RISCV_PCREL_LO12_I.*
 0+c R_RISCV_RELAX.*
-0+10 R_RISCV_CALL.*
-0+10 R_RISCV_RELAX.*
+0+10 R_RISCV_GOT_HI20.*
+0+14 R_RISCV_PCREL_LO12_I.*
+0+14 R_RISCV_RELAX.*
+0+18 R_RISCV_CALL.*
+0+18 R_RISCV_RELAX.*
index 7f1a484fc2ec26fb33db60af78437433c3bea982..2aab995769c018f056a3934a2e87f36d9304a333 100644 (file)
@@ -2,7 +2,10 @@ target:
        lui     a5,%hi(target)
        lw      a5,%lo(target)(a5)
 
-        .LA0: auipc     a5,%pcrel_hi(bar)
-        lw      a0,%pcrel_lo(.LA0)(a5)
+       .LA0: auipc     a5,%pcrel_hi(symbol1)
+       lw      a0,%pcrel_lo(.LA0)(a5)
+
+       .LA1: auipc     a5,%got_pcrel_hi(symbol2)
+       lw      a0,%pcrel_lo(.LA1)(a5)
 
        call target
This page took 0.029806 seconds and 4 git commands to generate.