]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
or1k: Implement relocation R_OR1K_GOT_AHI16 for gotha()
authorStafford Horne <shorne@gmail.com>
Thu, 6 May 2021 11:51:24 +0000 (20:51 +0900)
committerStafford Horne <shorne@gmail.com>
Thu, 6 May 2021 11:51:24 +0000 (20:51 +0900)
The gotha() relocation mnemonic will be outputted by OpenRISC GCC when
using the -mcmodel=large option.  This relocation is used along with
got() to generate 32-bit GOT offsets.  This increases the previous GOT
offset limit from the previous 16-bit (64K) limit.

This is needed on large binaries where the GOT grows larger than 64k.

bfd/ChangeLog:

PR 21464
* bfd-in2.h: Add BFD_RELOC_OR1K_GOT_AHI16 relocation.
* elf32-or1k.c (or1k_elf_howto_table, or1k_reloc_map): Likewise.
(or1k_final_link_relocate, or1k_elf_relocate_section,
or1k_elf_check_relocs): Likewise.
* libbfd.h (bfd_reloc_code_real_names): Likewise.
* reloc.c: Likewise.

cpu/ChangeLog:

PR 21464
* or1k.opc (or1k_imm16_relocs, parse_reloc): Define parse logic
for gotha() relocation.

include/ChangeLog:

PR 21464
* elf/or1k.h (elf_or1k_reloc_type): Define R_OR1K_GOT_AHI16 number.

opcodes/ChangeLog:

PR 21464
* or1k-asm.c: Regenerate.

gas/ChangeLog:

PR 21464
* testsuite/gas/or1k/reloc-1.s: Add test for new relocation.
* testsuite/gas/or1k/reloc-1.d: Add test result for new
relocation.

Cc: Giulio Benetti <giulio.benetti@benettiengineering.com>
fixup reloc, add tests

14 files changed:
bfd/ChangeLog
bfd/bfd-in2.h
bfd/elf32-or1k.c
bfd/libbfd.h
bfd/reloc.c
cpu/ChangeLog
cpu/or1k.opc
gas/ChangeLog
gas/testsuite/gas/or1k/reloc-1.d
gas/testsuite/gas/or1k/reloc-1.s
include/ChangeLog
include/elf/or1k.h
opcodes/ChangeLog
opcodes/or1k-asm.c

index 7a6b9a14422b40b904737232297dd090eda0bb99..c4a83dfe4f7851900da27d1c79688cb442e430b7 100644 (file)
@@ -1,3 +1,13 @@
+2021-05-06  Stafford Horne  <shorne@gmail.com>
+
+       PR 21464
+       * bfd-in2.h: Add BFD_RELOC_OR1K_GOT_AHI16 relocation.
+       * elf32-or1k.c (or1k_elf_howto_table, or1k_reloc_map): Likewise.
+       (or1k_final_link_relocate, or1k_elf_relocate_section,
+       or1k_elf_check_relocs): Likewise.
+       * libbfd.h (bfd_reloc_code_real_names): Likewise.
+       * reloc.c: Likewise.
+
 2021-05-06  Stafford Horne  <shorne@gmail.com>
 
        PR 27624
index d5780e46873c39979ccf229cb2897e0abf0459fa..7650522d6d7473b04240b3c07cf3b577f7b90eb7 100644 (file)
@@ -5032,6 +5032,7 @@ then it may be truncated to 8 bits.  */
   BFD_RELOC_OR1K_TLS_TPOFF,
   BFD_RELOC_OR1K_TLS_DTPOFF,
   BFD_RELOC_OR1K_TLS_DTPMOD,
+  BFD_RELOC_OR1K_GOT_AHI16,
 
 /* H8 elf Relocations.  */
   BFD_RELOC_H8_DIR16A8,
index cc6c51220e502de6f317363050b6e298ed227e3e..1b8938df37f9125c7b1e5487c12081a47678dab7 100644 (file)
@@ -808,6 +808,20 @@ static reloc_howto_type or1k_elf_howto_table[] =
         0,                     /* Source Mask.  */
         0x03ffffff,            /* Dest Mask.  */
         true),                 /* PC relative offset?  */
+
+  HOWTO (R_OR1K_GOT_AHI16,     /* type */
+        16,                    /* rightshift */
+        2,                     /* size (0 = byte, 1 = short, 2 = long) */
+        16,                    /* bitsize */
+        false,                 /* pc_relative */
+        0,                     /* bitpos */
+        complain_overflow_signed, /* complain_on_overflow */
+        bfd_elf_generic_reloc, /* special_function */
+        "R_OR1K_GOT_AHI16",    /* name */
+        false,                 /* partial_inplace */
+        0,                     /* src_mask */
+        0xffff,                /* dst_mask */
+        false),                /* pcrel_offset */
 };
 
 /* Map BFD reloc types to Or1k ELF reloc types.  */
@@ -871,6 +885,7 @@ static const struct or1k_reloc_map or1k_reloc_map[] =
   { BFD_RELOC_OR1K_TLS_IE_LO13,        R_OR1K_TLS_IE_LO13 },
   { BFD_RELOC_OR1K_SLO13,      R_OR1K_SLO13 },
   { BFD_RELOC_OR1K_PLTA26,     R_OR1K_PLTA26 },
+  { BFD_RELOC_OR1K_GOT_AHI16,  R_OR1K_GOT_AHI16 },
 };
 
 /* tls_type is a mask used to track how each symbol is accessed,
@@ -1111,6 +1126,7 @@ or1k_final_link_relocate (reloc_howto_type *howto, bfd *input_bfd,
   switch (howto->type)
     {
     case R_OR1K_AHI16:
+    case R_OR1K_GOT_AHI16:
     case R_OR1K_GOTOFF_AHI16:
     case R_OR1K_TLS_IE_AHI16:
     case R_OR1K_TLS_LE_AHI16:
@@ -1373,6 +1389,7 @@ or1k_elf_relocate_section (bfd *output_bfd,
            }
          break;
 
+       case R_OR1K_GOT_AHI16:
        case R_OR1K_GOT16:
        case R_OR1K_GOT_PG21:
        case R_OR1K_GOT_LO13:
@@ -1464,7 +1481,8 @@ or1k_elf_relocate_section (bfd *output_bfd,
            /* The GOT_PG21 and GOT_LO13 relocs are pc-relative,
               while the GOT16 reloc is GOT relative.  */
            relocation = got_base + off;
-           if (r_type == R_OR1K_GOT16)
+           if (r_type == R_OR1K_GOT16
+               || r_type == R_OR1K_GOT_AHI16)
              relocation -= got_sym_value;
 
          /* Addend should be zero.  */
@@ -1990,6 +2008,7 @@ or1k_elf_check_relocs (bfd *abfd,
            }
          break;
 
+       case R_OR1K_GOT_AHI16:
        case R_OR1K_GOT16:
        case R_OR1K_GOT_PG21:
        case R_OR1K_GOT_LO13:
index f3a32fa428530d8e06abda06ec7f90bab27a80a7..bbd3b0dbba65f0b7e421134915dd66de2fe63e8c 100644 (file)
@@ -2774,6 +2774,7 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
   "BFD_RELOC_OR1K_TLS_TPOFF",
   "BFD_RELOC_OR1K_TLS_DTPOFF",
   "BFD_RELOC_OR1K_TLS_DTPMOD",
+  "BFD_RELOC_OR1K_GOT_AHI16",
   "BFD_RELOC_H8_DIR16A8",
   "BFD_RELOC_H8_DIR16R8",
   "BFD_RELOC_H8_DIR24A8",
index 674b075a6b860f050b57036e9961dcc00543c8db..6d920e1df06937bdda90254be115d8af37086da0 100644 (file)
@@ -6206,6 +6206,8 @@ ENUMX
   BFD_RELOC_OR1K_GOTPC_HI16
 ENUMX
   BFD_RELOC_OR1K_GOTPC_LO16
+ENUMX
+  BFD_RELOC_OR1K_GOT_AHI16
 ENUMX
   BFD_RELOC_OR1K_GOT16
 ENUMX
index f6e50879c232a04b362f81e0ae0f789002772d9c..2739df0edd5571ea657fafc2ef0a2990f4784161 100644 (file)
@@ -1,3 +1,9 @@
+2021-05-06  Stafford Horne  <shorne@gmail.com>
+
+       PR 21464
+       * or1k.opc (or1k_imm16_relocs, parse_reloc): Define parse logic
+       for gotha() relocation.
+
 2021-03-31  Alan Modra  <amodra@gmail.com>
 
        * frv.opc: Replace bfd_boolean with bool, FALSE with false, and
index f0adcbb00a5b94ade4949d8b3594eb030e5b66ae..5d20a1f33a709931962647b12b61751ed94c324d 100644 (file)
@@ -193,7 +193,7 @@ static const bfd_reloc_code_real_type or1k_imm16_relocs[][6] = {
     BFD_RELOC_OR1K_GOT_LO13,
     BFD_RELOC_UNUSED,
     BFD_RELOC_UNUSED,
-    BFD_RELOC_UNUSED },
+    BFD_RELOC_OR1K_GOT_AHI16 },
   { BFD_RELOC_OR1K_GOTPC_LO16,
     BFD_RELOC_UNUSED,
     BFD_RELOC_UNUSED,
@@ -296,6 +296,11 @@ parse_reloc (const char **strp)
        str += 5;
        cls = RCLASS_TPOFF;
       }
+    else if (strncasecmp (str, "got", 3) == 0)
+      {
+       str += 3;
+       cls = RCLASS_GOT;
+      }
 
     if (strncasecmp (str, "hi(", 3) == 0)
       {
index fa1c100d6aca2193cb18506c2c8afe94f00cd6b6..790951ad9327fbfe81b4671a6faa1d6a05f36b96 100644 (file)
@@ -1,3 +1,10 @@
+2021-05-06  Stafford Horne  <shorne@gmail.com>
+
+       PR 21464
+       * testsuite/gas/or1k/reloc-1.s: Add test for new relocation.
+       * testsuite/gas/or1k/reloc-1.d: Add test result for new
+       relocation.
+
 2021-05-03  Christoph Muellner <cmuellner@gcc.gnu.org>
 
        PR 27764
index d1bcf5608bb5b37ef112bfca01cc5503412613be..3a001c4ed99fea4be2d35b7bd64b95a6973ae4f9 100644 (file)
@@ -68,5 +68,7 @@ OFFSET   TYPE              VALUE
 000000ec R_OR1K_LO13       x
 000000f0 R_OR1K_GOT_LO13   x
 000000f4 R_OR1K_SLO13      x
-
+000000f8 R_OR1K_GOT_AHI16  x
+000000fc R_OR1K_GOT_AHI16  x
+00000100 R_OR1K_GOT_AHI16  x
 
index e76abef653208b978fb7c6e40d795ce19c201532..562609aa869fb9622276c7e452dbc5587d111669 100644 (file)
@@ -74,3 +74,7 @@
        l.lbz   r5,po(x)(r3)
        l.lbz   r5,gotpo(x)(r3)
        l.sb    po(x)(r3),r6
+
+       l.movhi r4,gotha(x)
+       l.ori   r3,r4,gotha(x)
+       l.addi  r3,r4,gotha(x)
index aed37fd563a9e644402250f487b79ecdae2e4e28..621045e90d7b05cafe486d1c6313181ab2eb9c69 100644 (file)
@@ -1,3 +1,8 @@
+2021-05-06  Stafford Horne  <shorne@gmail.com>
+
+       PR 21464
+       * elf/or1k.h (elf_or1k_reloc_type): Define R_OR1K_GOT_AHI16 number.
+
 2021-05-06  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf.h (CTF_K_UNKNOWN): Document that it can be used for
index 7f2814810617c17ef308200149bbe72a8c1bd888..69ab90584a2e85334ad1c3dab7842c4272b13a31 100644 (file)
@@ -77,6 +77,7 @@ START_RELOC_NUMBERS (elf_or1k_reloc_type)
   RELOC_NUMBER (R_OR1K_TLS_IE_LO13,   51)
   RELOC_NUMBER (R_OR1K_SLO13,         52)
   RELOC_NUMBER (R_OR1K_PLTA26,        53)
+  RELOC_NUMBER (R_OR1K_GOT_AHI16,     54)
 END_RELOC_NUMBERS (R_OR1K_max)
 
 #define EF_OR1K_NODELAY (1UL << 0)
index 979b18cd0c1b7ea2ae081ca98b7c0f72b6dec260..bc5d44fc773ef10a981b605de6c161897f8df4b4 100644 (file)
@@ -1,3 +1,8 @@
+2021-05-06  Stafford Horne  <shorne@gmail.com>
+
+       PR 21464
+       * or1k-asm.c: Regenerate.
+
 2021-05-01  Max Filippov  <jcmvbkbc@gmail.com>
 
        * xtensa-dis.c (print_insn_xtensa): Fill in info->insn_type and
index 045ab6230b6c173da3db5dfbf206e2c982546ddb..fdccf67f9e1861260354491f14f3ce5c2a2ac7ca 100644 (file)
@@ -177,7 +177,7 @@ static const bfd_reloc_code_real_type or1k_imm16_relocs[][6] = {
     BFD_RELOC_OR1K_GOT_LO13,
     BFD_RELOC_UNUSED,
     BFD_RELOC_UNUSED,
-    BFD_RELOC_UNUSED },
+    BFD_RELOC_OR1K_GOT_AHI16 },
   { BFD_RELOC_OR1K_GOTPC_LO16,
     BFD_RELOC_UNUSED,
     BFD_RELOC_UNUSED,
@@ -280,6 +280,11 @@ parse_reloc (const char **strp)
        str += 5;
        cls = RCLASS_TPOFF;
       }
+    else if (strncasecmp (str, "got", 3) == 0)
+      {
+       str += 3;
+       cls = RCLASS_GOT;
+      }
 
     if (strncasecmp (str, "hi(", 3) == 0)
       {