Patches objdump (XCC)
[akaros.git] / tools / compilers / gcc-glibc / binutils-2.21.1-riscv.patch
1 diff --git a/binutils-2.21.1/bfd/archures.c b/binutils-2.21.1/bfd/archures.c
2 index 1867154..ae47b0c 100644
3 --- a/binutils-2.21.1/bfd/archures.c
4 +++ binutils-2.21.1/bfd/archures.c
5 @@ -515,6 +515,7 @@ extern const bfd_arch_info_type bfd_pj_arch;
6  extern const bfd_arch_info_type bfd_plugin_arch;
7  extern const bfd_arch_info_type bfd_powerpc_archs[];
8  #define bfd_powerpc_arch bfd_powerpc_archs[0]
9 +extern const bfd_arch_info_type bfd_riscv_arch;
10  extern const bfd_arch_info_type bfd_rs6000_arch;
11  extern const bfd_arch_info_type bfd_rx_arch;
12  extern const bfd_arch_info_type bfd_s390_arch;
13 @@ -589,6 +590,7 @@ static const bfd_arch_info_type * const bfd_archures_list[] =
14      &bfd_or32_arch,
15      &bfd_pdp11_arch,
16      &bfd_powerpc_arch,
17 +    &bfd_riscv_arch,
18      &bfd_rs6000_arch,
19      &bfd_rx_arch,
20      &bfd_s390_arch,
21 diff --git a/binutils-2.21.1/bfd/bfd-in2.h b/binutils-2.21.1/bfd/bfd-in2.h
22 index 59b1b8f..f7b7c3a 100644
23 --- a/binutils-2.21.1/bfd/bfd-in2.h
24 +++ binutils-2.21.1/bfd/bfd-in2.h
25 @@ -1919,6 +1919,9 @@ enum bfd_architecture
26  #define bfd_mach_ppc_e500mc    5001
27  #define bfd_mach_ppc_e500mc64  5005
28  #define bfd_mach_ppc_titan     83
29 +  bfd_arch_riscv, /* RISC-V */
30 +#define bfd_mach_riscv_rocket32 132
31 +#define bfd_mach_riscv_rocket64 164
32    bfd_arch_rs6000,    /* IBM RS/6000 */
33  #define bfd_mach_rs6k          6000
34  #define bfd_mach_rs6k_rs1      6001
35 @@ -4761,6 +4764,14 @@ relative offset from _GLOBAL_OFFSET_TABLE_  */
36  value in a word.  The relocation is relative offset from  */
37    BFD_RELOC_MICROBLAZE_32_GOTOFF,
38  
39 +  /* RISC-V relocations */
40 +  BFD_RELOC_RISCV_TLS_GOT_HI16,
41 +  BFD_RELOC_RISCV_TLS_GOT_LO16,
42 +  BFD_RELOC_RISCV_TLS_GD_HI16,
43 +  BFD_RELOC_RISCV_TLS_GD_LO16,
44 +  BFD_RELOC_RISCV_TLS_LDM_HI16,
45 +  BFD_RELOC_RISCV_TLS_LDM_LO16,
46 +
47  /* This is used to tell the dynamic linker to copy the value out of
48  the dynamic object into the runtime process image.  */
49    BFD_RELOC_MICROBLAZE_COPY,
50 diff --git a/binutils-2.21.1/bfd/config.bfd b/binutils-2.21.1/bfd/config.bfd
51 index fbf77ad..5c5535e 100644
52 --- a/binutils-2.21.1/bfd/config.bfd
53 +++ binutils-2.21.1/bfd/config.bfd
54 @@ -96,6 +96,7 @@ or32*)                 targ_archs=bfd_or32_arch ;;
55  pdp11*)                 targ_archs=bfd_pdp11_arch ;;
56  pj*)            targ_archs="bfd_pj_arch bfd_i386_arch";;
57  powerpc*)       targ_archs="bfd_rs6000_arch bfd_powerpc_arch" ;;
58 +riscv*)                 targ_archs=bfd_riscv_arch ;;
59  rs6000)                 targ_archs="bfd_rs6000_arch bfd_powerpc_arch" ;;
60  s390*)          targ_archs=bfd_s390_arch ;;
61  sh*)            targ_archs=bfd_sh_arch ;;
62 @@ -1193,6 +1194,14 @@ case "${targ}" in
63      targ_selvecs="bfd_powerpcle_pei_vec bfd_powerpc_pei_vec bfd_powerpcle_pe_vec bfd_powerpc_pe_vec"
64      ;;
65  
66 +#ifdef BFD64
67 +  riscv*-*-*)
68 +    targ_defvec=bfd_elf64_littleriscv_vec
69 +    targ_selvecs="bfd_elf32_littleriscv_vec bfd_elf64_littleriscv_vec"
70 +    want64=true
71 +    ;;
72 +#endif
73 +
74    rx-*-elf)
75      targ_defvec=bfd_elf32_rx_le_vec
76      targ_selvecs="bfd_elf32_rx_be_vec bfd_elf32_rx_le_vec"
77 diff --git a/binutils-2.21.1/bfd/configure b/binutils-2.21.1/bfd/configure
78 index 4675ad2..e882968 100755
79 --- a/binutils-2.21.1/bfd/configure
80 +++ binutils-2.21.1/bfd/configure
81 @@ -15239,6 +15239,7 @@ do
82      bfd_elf32_littlemips_vec)  tb="$tb elf32-mips.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo" ;;
83      bfd_elf32_littlemips_vxworks_vec)
84                                 tb="$tb elf32-mips.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo" ;;
85 +    bfd_elf32_littleriscv_vec)         tb="$tb elf32-riscv.lo elfxx-riscv.lo elf32.lo $elf ecofflink.lo" ;;
86      bfd_elf32_m32c_vec)         tb="$tb elf32-m32c.lo elf32.lo $elf" ;;
87      bfd_elf32_m32r_vec)                tb="$tb elf32-m32r.lo elf32.lo $elf" ;;
88      bfd_elf32_m32rle_vec)       tb="$tb elf32-m32r.lo elf32.lo $elf" ;;
89 @@ -15320,6 +15321,7 @@ do
90      bfd_elf64_ia64_vms_vec)    tb="$tb elf64-ia64.lo elf64.lo vms-lib.lo vms-misc.lo $elf"; target_size=64 ;;
91      bfd_elf64_little_generic_vec) tb="$tb elf64-gen.lo elf64.lo $elf"; target_size=64 ;;
92      bfd_elf64_littlemips_vec)  tb="$tb elf64-mips.lo elf64.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo"; target_size=64 ;;
93 +    bfd_elf64_littleriscv_vec)         tb="$tb elf64-riscv.lo elf64.lo elfxx-riscv.lo elf32.lo $elf ecofflink.lo"; target_size=64 ;;
94      bfd_elf64_mmix_vec)        tb="$tb elf64-mmix.lo elf64.lo $elf" target_size=64 ;;
95      bfd_elf64_powerpc_vec)     tb="$tb elf64-ppc.lo elf64-gen.lo elf64.lo $elf"; target_size=64 ;;
96      bfd_elf64_powerpcle_vec)   tb="$tb elf64-ppc.lo elf64-gen.lo elf64.lo $elf" target_size=64 ;;
97 diff --git a/binutils-2.21.1/bfd/configure.in b/binutils-2.21.1/bfd/configure.in
98 index 9f6d7a9..617b5df 100644
99 --- a/binutils-2.21.1/bfd/configure.in
100 +++ binutils-2.21.1/bfd/configure.in
101 @@ -730,6 +730,7 @@ do
102      bfd_elf32_littlemips_vec)  tb="$tb elf32-mips.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo" ;;
103      bfd_elf32_littlemips_vxworks_vec)
104                                 tb="$tb elf32-mips.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo" ;;
105 +    bfd_elf32_littleriscv_vec)         tb="$tb elf32-riscv.lo elfxx-riscv.lo elf32.lo $elf ecofflink.lo" ;;
106      bfd_elf32_m32c_vec)         tb="$tb elf32-m32c.lo elf32.lo $elf" ;;
107      bfd_elf32_m32r_vec)                tb="$tb elf32-m32r.lo elf32.lo $elf" ;;
108      bfd_elf32_m32rle_vec)       tb="$tb elf32-m32r.lo elf32.lo $elf" ;;
109 @@ -811,6 +812,7 @@ do
110      bfd_elf64_ia64_vms_vec)    tb="$tb elf64-ia64.lo elf64.lo vms-lib.lo vms-misc.lo $elf"; target_size=64 ;;
111      bfd_elf64_little_generic_vec) tb="$tb elf64-gen.lo elf64.lo $elf"; target_size=64 ;;
112      bfd_elf64_littlemips_vec)  tb="$tb elf64-mips.lo elf64.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo"; target_size=64 ;;
113 +    bfd_elf64_littleriscv_vec)         tb="$tb elf64-riscv.lo elf64.lo elfxx-riscv.lo elf32.lo $elf ecofflink.lo"; target_size=64 ;;
114      bfd_elf64_mmix_vec)        tb="$tb elf64-mmix.lo elf64.lo $elf" target_size=64 ;;
115      bfd_elf64_powerpc_vec)     tb="$tb elf64-ppc.lo elf64-gen.lo elf64.lo $elf"; target_size=64 ;;
116      bfd_elf64_powerpcle_vec)   tb="$tb elf64-ppc.lo elf64-gen.lo elf64.lo $elf" target_size=64 ;;
117 diff --git a/binutils-2.21.1/bfd/cpu-riscv.c b/binutils-2.21.1/bfd/cpu-riscv.c
118 new file mode 100644
119 index 0000000..22edee7
120 --- /dev/null
121 +++ binutils-2.21.1/bfd/cpu-riscv.c
122 @@ -0,0 +1,78 @@
123 +/* bfd back-end for mips support
124 +   Copyright 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001,
125 +   2002, 2003, 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
126 +   Written by Steve Chamberlain of Cygnus Support.
127 +
128 +   This file is part of BFD, the Binary File Descriptor library.
129 +
130 +   This program is free software; you can redistribute it and/or modify
131 +   it under the terms of the GNU General Public License as published by
132 +   the Free Software Foundation; either version 3 of the License, or
133 +   (at your option) any later version.
134 +
135 +   This program is distributed in the hope that it will be useful,
136 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
137 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
138 +   GNU General Public License for more details.
139 +
140 +   You should have received a copy of the GNU General Public License
141 +   along with this program; if not, write to the Free Software
142 +   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
143 +   MA 02110-1301, USA.  */
144 +
145 +#include "sysdep.h"
146 +#include "bfd.h"
147 +#include "libbfd.h"
148 +
149 +static const bfd_arch_info_type *mips_compatible
150 +  (const bfd_arch_info_type *, const bfd_arch_info_type *);
151 +
152 +/* The default routine tests bits_per_word, which is wrong on mips as
153 +   mips word size doesn't correlate with reloc size.  */
154 +
155 +static const bfd_arch_info_type *
156 +mips_compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b)
157 +{
158 +  if (a->arch != b->arch)
159 +    return NULL;
160 +
161 +  /* Machine compatibility is checked in
162 +     _bfd_mips_elf_merge_private_bfd_data.  */
163 +
164 +  return a;
165 +}
166 +
167 +#define N(BITS_WORD, BITS_ADDR, NUMBER, PRINT, DEFAULT, NEXT)          \
168 +  {                                                    \
169 +    BITS_WORD, /*  bits in a word */                   \
170 +    BITS_ADDR, /* bits in an address */                        \
171 +    8, /* 8 bits in a byte */                          \
172 +    bfd_arch_riscv,                                    \
173 +    NUMBER,                                            \
174 +    "riscv",                                           \
175 +    PRINT,                                             \
176 +    3,                                                 \
177 +    DEFAULT,                                           \
178 +    mips_compatible,                                   \
179 +    bfd_default_scan,                                  \
180 +    NEXT,                                              \
181 +  }
182 +
183 +enum
184 +{
185 +  I_riscv_rocket64,
186 +  I_riscv_rocket32
187 +};
188 +
189 +#define NN(index) (&arch_info_struct[(index) + 1])
190 +
191 +static const bfd_arch_info_type arch_info_struct[] =
192 +{
193 +  N (64, 64, bfd_mach_riscv_rocket64, "riscv:rocket64", FALSE, NN(I_riscv_rocket64)),
194 +  N (32, 32, bfd_mach_riscv_rocket32, "riscv:rocket32", FALSE, 0)
195 +};
196 +
197 +/* The default architecture is riscv:rocket64. */
198 +
199 +const bfd_arch_info_type bfd_riscv_arch =
200 +N (64, 64, 0, "riscv", TRUE, &arch_info_struct[0]);
201 diff --git a/binutils-2.21.1/bfd/elf32-riscv.c b/binutils-2.21.1/bfd/elf32-riscv.c
202 new file mode 100644
203 index 0000000..ef7f248
204 --- /dev/null
205 +++ binutils-2.21.1/bfd/elf32-riscv.c
206 @@ -0,0 +1,2170 @@
207 +/* MIPS-specific support for 32-bit ELF
208 +   Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
209 +   2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
210 +
211 +   Most of the information added by Ian Lance Taylor, Cygnus Support,
212 +   <ian@cygnus.com>.
213 +   N32/64 ABI support added by Mark Mitchell, CodeSourcery, LLC.
214 +   <mark@codesourcery.com>
215 +   Traditional MIPS targets support added by Koundinya.K, Dansk Data
216 +   Elektronik & Operations Research Group. <kk@ddeorg.soft.net>
217 +
218 +   This file is part of BFD, the Binary File Descriptor library.
219 +
220 +   This program is free software; you can redistribute it and/or modify
221 +   it under the terms of the GNU General Public License as published by
222 +   the Free Software Foundation; either version 3 of the License, or
223 +   (at your option) any later version.
224 +
225 +   This program is distributed in the hope that it will be useful,
226 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
227 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
228 +   GNU General Public License for more details.
229 +
230 +   You should have received a copy of the GNU General Public License
231 +   along with this program; if not, write to the Free Software
232 +   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
233 +   MA 02110-1301, USA.  */
234 +
235 +
236 +/* This file handles MIPS ELF targets.  SGI Irix 5 uses a slightly
237 +   different MIPS ELF from other targets.  This matters when linking.
238 +   This file supports both, switching at runtime.  */
239 +
240 +#include "sysdep.h"
241 +#include "bfd.h"
242 +#include "libbfd.h"
243 +#include "bfdlink.h"
244 +#include "genlink.h"
245 +#include "elf-bfd.h"
246 +#include "elfxx-riscv.h"
247 +#include "elf/riscv.h"
248 +#include "opcode/riscv.h"
249 +
250 +/* Get the ECOFF swapping routines.  */
251 +#include "coff/sym.h"
252 +#include "coff/symconst.h"
253 +#include "coff/internal.h"
254 +#include "coff/ecoff.h"
255 +#include "coff/mips.h"
256 +#define ECOFF_SIGNED_32
257 +#include "ecoffswap.h"
258 +
259 +#include "opcode/riscv.h"
260 +
261 +static bfd_boolean mips_elf_assign_gp
262 +  (bfd *, bfd_vma *);
263 +static bfd_reloc_status_type mips_elf_final_gp
264 +  (bfd *, asymbol *, bfd_boolean, char **, bfd_vma *);
265 +static bfd_reloc_status_type mips_elf_gprel16_reloc
266 +  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
267 +static bfd_reloc_status_type mips_elf_literal_reloc
268 +  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
269 +static bfd_reloc_status_type mips_elf_gprel32_reloc
270 +  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
271 +static bfd_reloc_status_type gprel32_with_gp
272 +  (bfd *, asymbol *, arelent *, asection *, bfd_boolean, void *, bfd_vma);
273 +static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
274 +  (bfd *, bfd_reloc_code_real_type);
275 +static reloc_howto_type *mips_elf_n32_rtype_to_howto
276 +  (unsigned int, bfd_boolean);
277 +static void mips_info_to_howto_rel
278 +  (bfd *, arelent *, Elf_Internal_Rela *);
279 +static void mips_info_to_howto_rela
280 +  (bfd *, arelent *, Elf_Internal_Rela *);
281 +static bfd_boolean mips_elf_sym_is_global
282 +  (bfd *, asymbol *);
283 +static bfd_boolean mips_elf_n32_object_p
284 +  (bfd *);
285 +static bfd_boolean elf32_mips_grok_prstatus
286 +  (bfd *, Elf_Internal_Note *);
287 +static bfd_boolean elf32_mips_grok_psinfo
288 +  (bfd *, Elf_Internal_Note *);
289 +
290 +extern const bfd_target bfd_elf32_nbigmips_vec;
291 +extern const bfd_target bfd_elf32_nlittlemips_vec;
292 +
293 +/* The number of local .got entries we reserve.  */
294 +#define MIPS_RESERVED_GOTNO (2)
295 +
296 +/* In case we're on a 32-bit machine, construct a 64-bit "-1" value
297 +   from smaller values.  Start with zero, widen, *then* decrement.  */
298 +#define MINUS_ONE      (((bfd_vma)0) - 1)
299 +
300 +/* The relocation table used for SHT_REL sections.  */
301 +
302 +static reloc_howto_type elf_mips_howto_table_rel[] =
303 +{
304 +  /* No relocation.  */
305 +  HOWTO (R_RISCV_NONE,         /* type */
306 +        0,                     /* rightshift */
307 +        0,                     /* size (0 = byte, 1 = short, 2 = long) */
308 +        0,                     /* bitsize */
309 +        FALSE,                 /* pc_relative */
310 +        0,                     /* bitpos */
311 +        complain_overflow_dont, /* complain_on_overflow */
312 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
313 +        "R_RISCV_NONE",                /* name */
314 +        FALSE,                 /* partial_inplace */
315 +        0,                     /* src_mask */
316 +        0,                     /* dst_mask */
317 +        FALSE),                /* pcrel_offset */
318 +
319 +  EMPTY_HOWTO (1),
320 +
321 +  /* 32 bit relocation.  */
322 +  HOWTO (R_RISCV_32,           /* type */
323 +        0,                     /* rightshift */
324 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
325 +        32,                    /* bitsize */
326 +        FALSE,                 /* pc_relative */
327 +        0,                     /* bitpos */
328 +        complain_overflow_dont, /* complain_on_overflow */
329 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
330 +        "R_RISCV_32",          /* name */
331 +        TRUE,                  /* partial_inplace */
332 +        0xffffffff,            /* src_mask */
333 +        0xffffffff,            /* dst_mask */
334 +        FALSE),                /* pcrel_offset */
335 +
336 +  /* 32 bit symbol relative relocation.  */
337 +  HOWTO (R_RISCV_REL32,                /* type */
338 +        0,                     /* rightshift */
339 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
340 +        32,                    /* bitsize */
341 +        FALSE,                 /* pc_relative */
342 +        0,                     /* bitpos */
343 +        complain_overflow_dont, /* complain_on_overflow */
344 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
345 +        "R_RISCV_REL32",       /* name */
346 +        TRUE,                  /* partial_inplace */
347 +        0xffffffff,            /* src_mask */
348 +        0xffffffff,            /* dst_mask */
349 +        FALSE),                /* pcrel_offset */
350 +
351 +  /* 26 bit jump address.  */
352 +  HOWTO (R_RISCV_26,           /* type */
353 +        RISCV_JUMP_ALIGN_BITS,                 /* rightshift */
354 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
355 +        RISCV_JUMP_BITS,                       /* bitsize */
356 +        TRUE,                  /* pc_relative */
357 +        OP_SH_TARGET,                  /* bitpos */
358 +        complain_overflow_dont, /* complain_on_overflow */
359 +                               /* This needs complex overflow
360 +                                  detection, because the upper 36
361 +                                  bits must match the PC + 4.  */
362 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
363 +        "R_RISCV_26",          /* name */
364 +        TRUE,                  /* partial_inplace */
365 +        ((1<<RISCV_JUMP_BITS)-1) << OP_SH_TARGET,              /* src_mask */
366 +        ((1<<RISCV_JUMP_BITS)-1) << OP_SH_TARGET,              /* dst_mask */
367 +        TRUE),         /* pcrel_offset */
368 +
369 +  /* R_RISCV_HI16 and R_RISCV_LO16 are unsupported for NewABI REL.
370 +     However, the native IRIX6 tools use them, so we try our best. */
371 +
372 +  /* High 16 bits of symbol value.  */
373 +  HOWTO (R_RISCV_HI16,         /* type */
374 +        RISCV_IMM_BITS,                        /* rightshift */
375 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
376 +        RISCV_BIGIMM_BITS,                     /* bitsize */
377 +        FALSE,                 /* pc_relative */
378 +        OP_SH_BIGIMMEDIATE,                    /* bitpos */
379 +        complain_overflow_dont, /* complain_on_overflow */
380 +        _bfd_riscv_elf_hi16_reloc, /* special_function */
381 +        "R_RISCV_HI16",                /* name */
382 +        TRUE,                  /* partial_inplace */
383 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,              /* src_mask */
384 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,              /* dst_mask */
385 +        FALSE),                /* pcrel_offset */
386 +
387 +  /* Low 16 bits of symbol value.  */
388 +  HOWTO (R_RISCV_LO16,         /* type */
389 +        0,                     /* rightshift */
390 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
391 +        RISCV_IMM_BITS,                        /* bitsize */
392 +        FALSE,                 /* pc_relative */
393 +        OP_SH_IMMEDIATE,                       /* bitpos */
394 +        complain_overflow_dont, /* complain_on_overflow */
395 +        _bfd_riscv_elf_lo16_reloc, /* special_function */
396 +        "R_RISCV_LO16",                /* name */
397 +        TRUE,                  /* partial_inplace */
398 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,                /* src_mask */
399 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,                /* dst_mask */
400 +        FALSE),                /* pcrel_offset */
401 +
402 +  /* GP relative reference.  */
403 +  HOWTO (R_RISCV_GPREL16,      /* type */
404 +        0,                     /* rightshift */
405 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
406 +        RISCV_IMM_BITS,                        /* bitsize */
407 +        FALSE,                 /* pc_relative */
408 +        OP_SH_IMMEDIATE,       /* bitpos */
409 +        complain_overflow_signed, /* complain_on_overflow */
410 +        mips_elf_gprel16_reloc, /* special_function */
411 +        "R_RISCV_GPREL16",     /* name */
412 +        TRUE,                  /* partial_inplace */
413 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
414 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
415 +        FALSE),                /* pcrel_offset */
416 +
417 +  /* Reference to literal section.  */
418 +  HOWTO (R_RISCV_LITERAL,      /* type */
419 +        0,                     /* rightshift */
420 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
421 +        RISCV_IMM_BITS,                        /* bitsize */
422 +        FALSE,                 /* pc_relative */
423 +        OP_SH_IMMEDIATE,       /* bitpos */
424 +        complain_overflow_signed, /* complain_on_overflow */
425 +        mips_elf_literal_reloc, /* special_function */
426 +        "R_RISCV_LITERAL",     /* name */
427 +        TRUE,                  /* partial_inplace */
428 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
429 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
430 +        FALSE),                /* pcrel_offset */
431 +
432 +  /* Reference to global offset table.  */
433 +  HOWTO (R_RISCV_GOT16,                /* type */
434 +        0,                     /* rightshift */
435 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
436 +        RISCV_IMM_BITS,        /* bitsize */
437 +        FALSE,                 /* pc_relative */
438 +        OP_SH_IMMEDIATE,       /* bitpos */
439 +        complain_overflow_signed, /* complain_on_overflow */
440 +        _bfd_riscv_elf_got16_reloc, /* special_function */
441 +        "R_RISCV_GOT16",       /* name */
442 +        TRUE,                  /* partial_inplace */
443 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,                /* src_mask */
444 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,                /* dst_mask */
445 +        FALSE),                /* pcrel_offset */
446 +
447 +  /* 16 bit PC relative reference.  Note that the ABI document has a typo
448 +     and claims R_RISCV_PC16 to be not rightshifted, rendering it useless.
449 +     We do the right thing here.  */
450 +  HOWTO (R_RISCV_PC16,         /* type */
451 +        RISCV_BRANCH_ALIGN_BITS,                       /* rightshift */
452 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
453 +        RISCV_IMM_BITS,                        /* bitsize */
454 +        TRUE,                  /* pc_relative */
455 +        OP_SH_IMMEDIATE,       /* bitpos */
456 +        complain_overflow_signed, /* complain_on_overflow */
457 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
458 +        "R_RISCV_PC16",                /* name */
459 +        TRUE,                  /* partial_inplace */
460 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
461 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
462 +        TRUE),                 /* pcrel_offset */
463 +
464 +  /* 16 bit call through global offset table.  */
465 +  HOWTO (R_RISCV_CALL16,               /* type */
466 +        0,                     /* rightshift */
467 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
468 +        RISCV_IMM_BITS,                        /* bitsize */
469 +        FALSE,                 /* pc_relative */
470 +        OP_SH_IMMEDIATE,       /* bitpos */
471 +        complain_overflow_signed, /* complain_on_overflow */
472 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
473 +        "R_RISCV_CALL16",      /* name */
474 +        TRUE,                  /* partial_inplace */
475 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
476 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
477 +        FALSE),                /* pcrel_offset */
478 +
479 +  /* 32 bit GP relative reference.  */
480 +  HOWTO (R_RISCV_GPREL32,      /* type */
481 +        0,                     /* rightshift */
482 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
483 +        32,                    /* bitsize */
484 +        FALSE,                 /* pc_relative */
485 +        0,                     /* bitpos */
486 +        complain_overflow_dont, /* complain_on_overflow */
487 +        mips_elf_gprel32_reloc, /* special_function */
488 +        "R_RISCV_GPREL32",     /* name */
489 +        TRUE,                  /* partial_inplace */
490 +        0xffffffff,            /* src_mask */
491 +        0xffffffff,            /* dst_mask */
492 +        FALSE),                /* pcrel_offset */
493 +
494 +  EMPTY_HOWTO (13),
495 +  EMPTY_HOWTO (14),
496 +  EMPTY_HOWTO (15),
497 +  EMPTY_HOWTO (16),
498 +  EMPTY_HOWTO (17),
499 +
500 +  /* 64 bit relocation.  */
501 +  HOWTO (R_RISCV_64,           /* type */
502 +        0,                     /* rightshift */
503 +        4,                     /* size (0 = byte, 1 = short, 2 = long) */
504 +        64,                    /* bitsize */
505 +        FALSE,                 /* pc_relative */
506 +        0,                     /* bitpos */
507 +        complain_overflow_dont, /* complain_on_overflow */
508 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
509 +        "R_RISCV_64",          /* name */
510 +        TRUE,                  /* partial_inplace */
511 +        MINUS_ONE,             /* src_mask */
512 +        MINUS_ONE,             /* dst_mask */
513 +        FALSE),                /* pcrel_offset */
514 +
515 +  /* Displacement in the global offset table.  */
516 +  HOWTO (R_RISCV_GOT_DISP,     /* type */
517 +        0,                     /* rightshift */
518 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
519 +        RISCV_IMM_BITS,                        /* bitsize */
520 +        FALSE,                 /* pc_relative */
521 +        OP_SH_IMMEDIATE,                       /* bitpos */
522 +        complain_overflow_signed, /* complain_on_overflow */
523 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
524 +        "R_RISCV_GOT_DISP",    /* name */
525 +        TRUE,                  /* partial_inplace */
526 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,                /* src_mask */
527 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,                /* dst_mask */
528 +        FALSE),                /* pcrel_offset */
529 +
530 +  EMPTY_HOWTO (20),
531 +  EMPTY_HOWTO (21),
532 +
533 +  /* High 16 bits of displacement in global offset table.  */
534 +  HOWTO (R_RISCV_GOT_HI16,     /* type */
535 +        0,                     /* rightshift */
536 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
537 +        RISCV_BIGIMM_BITS,     /* bitsize */
538 +        TRUE,                  /* pc_relative */
539 +        OP_SH_BIGIMMEDIATE,    /* bitpos */
540 +        complain_overflow_dont, /* complain_on_overflow */
541 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
542 +        "R_RISCV_GOT_HI16",    /* name */
543 +        TRUE,                  /* partial_inplace */
544 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,              /* src_mask */
545 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,              /* dst_mask */
546 +        FALSE),                /* pcrel_offset */
547 +
548 +  /* Low 16 bits of displacement in global offset table.  */
549 +  HOWTO (R_RISCV_GOT_LO16,     /* type */
550 +        0,                     /* rightshift */
551 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
552 +        RISCV_IMM_BITS,                        /* bitsize */
553 +        TRUE,                  /* pc_relative */
554 +        OP_SH_IMMEDIATE,       /* bitpos */
555 +        complain_overflow_dont, /* complain_on_overflow */
556 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
557 +        "R_RISCV_GOT_LO16",    /* name */
558 +        TRUE,                  /* partial_inplace */
559 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,                /* src_mask */
560 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,                /* dst_mask */
561 +        FALSE),                /* pcrel_offset */
562 +
563 +  /* 64 bit subtraction.  */
564 +  HOWTO (R_RISCV_SUB,          /* type */
565 +        0,                     /* rightshift */
566 +        4,                     /* size (0 = byte, 1 = short, 2 = long) */
567 +        64,                    /* bitsize */
568 +        FALSE,                 /* pc_relative */
569 +        0,                     /* bitpos */
570 +        complain_overflow_dont, /* complain_on_overflow */
571 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
572 +        "R_RISCV_SUB",         /* name */
573 +        TRUE,                  /* partial_inplace */
574 +        MINUS_ONE,             /* src_mask */
575 +        MINUS_ONE,             /* dst_mask */
576 +        FALSE),                /* pcrel_offset */
577 +
578 +  /* Insert the addend as an instruction.  */
579 +  /* FIXME: Not handled correctly.  */
580 +  HOWTO (R_RISCV_INSERT_A,     /* type */
581 +        0,                     /* rightshift */
582 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
583 +        32,                    /* bitsize */
584 +        FALSE,                 /* pc_relative */
585 +        0,                     /* bitpos */
586 +        complain_overflow_dont, /* complain_on_overflow */
587 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
588 +        "R_RISCV_INSERT_A",    /* name */
589 +        TRUE,                  /* partial_inplace */
590 +        0xffffffff,            /* src_mask */
591 +        0xffffffff,            /* dst_mask */
592 +        FALSE),                /* pcrel_offset */
593 +
594 +  /* Insert the addend as an instruction, and change all relocations
595 +     to refer to the old instruction at the address.  */
596 +  /* FIXME: Not handled correctly.  */
597 +  HOWTO (R_RISCV_INSERT_B,     /* type */
598 +        0,                     /* rightshift */
599 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
600 +        32,                    /* bitsize */
601 +        FALSE,                 /* pc_relative */
602 +        0,                     /* bitpos */
603 +        complain_overflow_dont, /* complain_on_overflow */
604 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
605 +        "R_RISCV_INSERT_B",    /* name */
606 +        TRUE,                  /* partial_inplace */
607 +        0xffffffff,            /* src_mask */
608 +        0xffffffff,            /* dst_mask */
609 +        FALSE),                /* pcrel_offset */
610 +
611 +  /* Delete a 32 bit instruction.  */
612 +  /* FIXME: Not handled correctly.  */
613 +  HOWTO (R_RISCV_DELETE,               /* type */
614 +        0,                     /* rightshift */
615 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
616 +        32,                    /* bitsize */
617 +        FALSE,                 /* pc_relative */
618 +        0,                     /* bitpos */
619 +        complain_overflow_dont, /* complain_on_overflow */
620 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
621 +        "R_RISCV_DELETE",      /* name */
622 +        TRUE,                  /* partial_inplace */
623 +        0xffffffff,            /* src_mask */
624 +        0xffffffff,            /* dst_mask */
625 +        FALSE),                /* pcrel_offset */
626 +
627 +  EMPTY_HOWTO (28),
628 +  EMPTY_HOWTO (29),
629 +
630 +  /* High 16 bits of displacement in global offset table.  */
631 +  HOWTO (R_RISCV_CALL_HI16,    /* type */
632 +        0,                     /* rightshift */
633 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
634 +        RISCV_BIGIMM_BITS,                     /* bitsize */
635 +        FALSE,                 /* pc_relative */
636 +        OP_SH_BIGIMMEDIATE,    /* bitpos */
637 +        complain_overflow_dont, /* complain_on_overflow */
638 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
639 +        "R_RISCV_CALL_HI16",   /* name */
640 +        TRUE,                  /* partial_inplace */
641 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,      /* src_mask */
642 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,      /* dst_mask */
643 +        FALSE),                /* pcrel_offset */
644 +
645 +  /* Low 16 bits of displacement in global offset table.  */
646 +  HOWTO (R_RISCV_CALL_LO16,    /* type */
647 +        0,                     /* rightshift */
648 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
649 +        RISCV_IMM_BITS,                        /* bitsize */
650 +        FALSE,                 /* pc_relative */
651 +        OP_SH_IMMEDIATE,       /* bitpos */
652 +        complain_overflow_dont, /* complain_on_overflow */
653 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
654 +        "R_RISCV_CALL_LO16",   /* name */
655 +        TRUE,                  /* partial_inplace */
656 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
657 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
658 +        FALSE),                /* pcrel_offset */
659 +
660 +  /* Section displacement, used by an associated event location section.  */
661 +  HOWTO (R_RISCV_SCN_DISP,     /* type */
662 +        0,                     /* rightshift */
663 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
664 +        32,                    /* bitsize */
665 +        FALSE,                 /* pc_relative */
666 +        0,                     /* bitpos */
667 +        complain_overflow_dont, /* complain_on_overflow */
668 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
669 +        "R_RISCV_SCN_DISP",    /* name */
670 +        TRUE,                  /* partial_inplace */
671 +        0xffffffff,            /* src_mask */
672 +        0xffffffff,            /* dst_mask */
673 +        FALSE),                /* pcrel_offset */
674 +
675 +  HOWTO (R_RISCV_REL16,                /* type */
676 +        0,                     /* rightshift */
677 +        1,                     /* size (0 = byte, 1 = short, 2 = long) */
678 +        RISCV_IMM_BITS,                        /* bitsize */
679 +        FALSE,                 /* pc_relative */
680 +        OP_SH_IMMEDIATE,       /* bitpos */
681 +        complain_overflow_signed, /* complain_on_overflow */
682 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
683 +        "R_RISCV_REL16",       /* name */
684 +        TRUE,                  /* partial_inplace */
685 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
686 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
687 +        FALSE),                /* pcrel_offset */
688 +
689 +  /* These two are obsolete.  */
690 +  EMPTY_HOWTO (R_RISCV_ADD_IMMEDIATE),
691 +  EMPTY_HOWTO (R_RISCV_PJUMP),
692 +
693 +  /* Similiar to R_RISCV_REL32, but used for relocations in a GOT section.
694 +     It must be used for multigot GOT's (and only there).  */
695 +  HOWTO (R_RISCV_RELGOT,               /* type */
696 +        0,                     /* rightshift */
697 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
698 +        32,                    /* bitsize */
699 +        FALSE,                 /* pc_relative */
700 +        0,                     /* bitpos */
701 +        complain_overflow_dont, /* complain_on_overflow */
702 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
703 +        "R_RISCV_RELGOT",      /* name */
704 +        TRUE,                  /* partial_inplace */
705 +        0xffffffff,            /* src_mask */
706 +        0xffffffff,            /* dst_mask */
707 +        FALSE),                /* pcrel_offset */
708 +
709 +  EMPTY_HOWTO(37),
710 +
711 +  /* TLS relocations.  */
712 +  HOWTO (R_RISCV_TLS_DTPMOD32, /* type */
713 +        0,                     /* rightshift */
714 +        4,                     /* size (0 = byte, 1 = short, 2 = long) */
715 +        32,                    /* bitsize */
716 +        FALSE,                 /* pc_relative */
717 +        0,                     /* bitpos */
718 +        complain_overflow_dont, /* complain_on_overflow */
719 +        _bfd_riscv_elf_generic_reloc, /* special_function */
720 +        "R_RISCV_TLS_DTPMOD32",        /* name */
721 +        TRUE,                  /* partial_inplace */
722 +        MINUS_ONE,             /* src_mask */
723 +        MINUS_ONE,             /* dst_mask */
724 +        FALSE),                /* pcrel_offset */
725 +
726 +  HOWTO (R_RISCV_TLS_DTPREL32, /* type */
727 +        0,                     /* rightshift */
728 +        4,                     /* size (0 = byte, 1 = short, 2 = long) */
729 +        32,                    /* bitsize */
730 +        FALSE,                 /* pc_relative */
731 +        0,                     /* bitpos */
732 +        complain_overflow_dont, /* complain_on_overflow */
733 +        _bfd_riscv_elf_generic_reloc, /* special_function */
734 +        "R_RISCV_TLS_DTPREL32",        /* name */
735 +        TRUE,                  /* partial_inplace */
736 +        MINUS_ONE,             /* src_mask */
737 +        MINUS_ONE,             /* dst_mask */
738 +        FALSE),                /* pcrel_offset */
739 +
740 +  EMPTY_HOWTO (R_RISCV_TLS_DTPMOD64),
741 +  EMPTY_HOWTO (R_RISCV_TLS_DTPREL64),
742 +
743 +  /* TLS general dynamic variable reference.  */
744 +  HOWTO (R_RISCV_TLS_GD,               /* type */
745 +        0,                     /* rightshift */
746 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
747 +        RISCV_IMM_BITS,                        /* bitsize */
748 +        FALSE,                 /* pc_relative */
749 +        OP_SH_IMMEDIATE,       /* bitpos */
750 +        complain_overflow_signed, /* complain_on_overflow */
751 +        _bfd_riscv_elf_generic_reloc, /* special_function */
752 +        "R_RISCV_TLS_GD",      /* name */
753 +        TRUE,                  /* partial_inplace */
754 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
755 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
756 +        FALSE),                /* pcrel_offset */
757 +
758 +  /* TLS local dynamic variable reference.  */
759 +  HOWTO (R_RISCV_TLS_LDM,      /* type */
760 +        0,                     /* rightshift */
761 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
762 +        RISCV_IMM_BITS,                        /* bitsize */
763 +        FALSE,                 /* pc_relative */
764 +        OP_SH_IMMEDIATE,       /* bitpos */
765 +        complain_overflow_signed, /* complain_on_overflow */
766 +        _bfd_riscv_elf_generic_reloc, /* special_function */
767 +        "R_RISCV_TLS_LDM",     /* name */
768 +        TRUE,                  /* partial_inplace */
769 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
770 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
771 +        FALSE),                /* pcrel_offset */
772 +
773 +  /* TLS local dynamic offset.  */
774 +  HOWTO (R_RISCV_TLS_DTPREL_HI16,      /* type */
775 +        0,                     /* rightshift */
776 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
777 +        RISCV_BIGIMM_BITS,                     /* bitsize */
778 +        FALSE,                 /* pc_relative */
779 +        OP_SH_BIGIMMEDIATE,    /* bitpos */
780 +        complain_overflow_signed, /* complain_on_overflow */
781 +        _bfd_riscv_elf_generic_reloc, /* special_function */
782 +        "R_RISCV_TLS_DTPREL_HI16",     /* name */
783 +        TRUE,                  /* partial_inplace */
784 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,      /* src_mask */
785 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,      /* dst_mask */
786 +        FALSE),                /* pcrel_offset */
787 +
788 +  /* TLS local dynamic offset.  */
789 +  HOWTO (R_RISCV_TLS_DTPREL_LO16,      /* type */
790 +        0,                     /* rightshift */
791 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
792 +        RISCV_IMM_BITS,                        /* bitsize */
793 +        FALSE,                 /* pc_relative */
794 +        OP_SH_IMMEDIATE,       /* bitpos */
795 +        complain_overflow_signed, /* complain_on_overflow */
796 +        _bfd_riscv_elf_generic_reloc, /* special_function */
797 +        "R_RISCV_TLS_DTPREL_LO16",     /* name */
798 +        TRUE,                  /* partial_inplace */
799 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
800 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
801 +        FALSE),                /* pcrel_offset */
802 +
803 +  /* TLS thread pointer offset.  */
804 +  HOWTO (R_RISCV_TLS_GOTTPREL, /* type */
805 +        0,                     /* rightshift */
806 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
807 +        RISCV_IMM_BITS,                        /* bitsize */
808 +        FALSE,                 /* pc_relative */
809 +        OP_SH_IMMEDIATE,       /* bitpos */
810 +        complain_overflow_signed, /* complain_on_overflow */
811 +        _bfd_riscv_elf_generic_reloc, /* special_function */
812 +        "R_RISCV_TLS_GOTTPREL",        /* name */
813 +        TRUE,                  /* partial_inplace */
814 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
815 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
816 +        FALSE),                /* pcrel_offset */
817 +
818 +  /* TLS IE dynamic relocations.  */
819 +  HOWTO (R_RISCV_TLS_TPREL32,  /* type */
820 +        0,                     /* rightshift */
821 +        4,                     /* size (0 = byte, 1 = short, 2 = long) */
822 +        32,                    /* bitsize */
823 +        FALSE,                 /* pc_relative */
824 +        0,                     /* bitpos */
825 +        complain_overflow_dont, /* complain_on_overflow */
826 +        _bfd_riscv_elf_generic_reloc, /* special_function */
827 +        "R_RISCV_TLS_TPREL32", /* name */
828 +        TRUE,                  /* partial_inplace */
829 +        MINUS_ONE,             /* src_mask */
830 +        MINUS_ONE,             /* dst_mask */
831 +        FALSE),                /* pcrel_offset */
832 +
833 +  EMPTY_HOWTO (R_RISCV_TLS_TPREL64),
834 +
835 +  /* TLS thread pointer offset.  */
836 +  HOWTO (R_RISCV_TLS_TPREL_HI16,       /* type */
837 +        0,                     /* rightshift */
838 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
839 +        RISCV_BIGIMM_BITS,                     /* bitsize */
840 +        FALSE,                 /* pc_relative */
841 +        OP_SH_BIGIMMEDIATE,    /* bitpos */
842 +        complain_overflow_signed, /* complain_on_overflow */
843 +        _bfd_riscv_elf_generic_reloc, /* special_function */
844 +        "R_RISCV_TLS_TPREL_HI16", /* name */
845 +        TRUE,                  /* partial_inplace */
846 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,      /* src_mask */
847 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,      /* dst_mask */
848 +        FALSE),                /* pcrel_offset */
849 +
850 +  /* TLS thread pointer offset.  */
851 +  HOWTO (R_RISCV_TLS_TPREL_LO16,       /* type */
852 +        0,                     /* rightshift */
853 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
854 +        RISCV_IMM_BITS,                        /* bitsize */
855 +        FALSE,                 /* pc_relative */
856 +        OP_SH_IMMEDIATE,       /* bitpos */
857 +        complain_overflow_signed, /* complain_on_overflow */
858 +        _bfd_riscv_elf_generic_reloc, /* special_function */
859 +        "R_RISCV_TLS_TPREL_LO16", /* name */
860 +        TRUE,                  /* partial_inplace */
861 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
862 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
863 +        FALSE),                /* pcrel_offset */
864 +
865 +  /* High 16 bits of displacement in global offset table.  */
866 +  HOWTO (R_RISCV_TLS_GOT_HI16, /* type */
867 +        0,                     /* rightshift */
868 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
869 +        RISCV_BIGIMM_BITS,     /* bitsize */
870 +        TRUE,                  /* pc_relative */
871 +        OP_SH_BIGIMMEDIATE,    /* bitpos */
872 +        complain_overflow_dont, /* complain_on_overflow */
873 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
874 +        "R_RISCV_TLS_GOT_HI16",        /* name */
875 +        TRUE,                  /* partial_inplace */
876 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,              /* src_mask */
877 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,              /* dst_mask */
878 +        FALSE),                /* pcrel_offset */
879 +
880 +  /* TLS thread pointer offset.  */
881 +  HOWTO (R_RISCV_TLS_GOT_LO16, /* type */
882 +        0,                     /* rightshift */
883 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
884 +        RISCV_IMM_BITS,                        /* bitsize */
885 +        TRUE,                  /* pc_relative */
886 +        OP_SH_IMMEDIATE,       /* bitpos */
887 +        complain_overflow_dont, /* complain_on_overflow */
888 +        _bfd_riscv_elf_generic_reloc, /* special_function */
889 +        "R_RISCV_TLS_GOT_LO16",        /* name */
890 +        TRUE,                  /* partial_inplace */
891 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
892 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
893 +        FALSE),                /* pcrel_offset */
894 +
895 +  /* High 16 bits of displacement in global offset table.  */
896 +  HOWTO (R_RISCV_TLS_GD_HI16,  /* type */
897 +        0,                     /* rightshift */
898 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
899 +        RISCV_BIGIMM_BITS,     /* bitsize */
900 +        FALSE,                 /* pc_relative */
901 +        OP_SH_BIGIMMEDIATE,    /* bitpos */
902 +        complain_overflow_dont, /* complain_on_overflow */
903 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
904 +        "R_RISCV_TLS_GD_HI16", /* name */
905 +        TRUE,                  /* partial_inplace */
906 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,              /* src_mask */
907 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,              /* dst_mask */
908 +        FALSE),                /* pcrel_offset */
909 +
910 +  /* TLS thread pointer offset.  */
911 +  HOWTO (R_RISCV_TLS_GD_LO16,  /* type */
912 +        0,                     /* rightshift */
913 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
914 +        RISCV_IMM_BITS,                        /* bitsize */
915 +        FALSE,                 /* pc_relative */
916 +        OP_SH_IMMEDIATE,       /* bitpos */
917 +        complain_overflow_dont, /* complain_on_overflow */
918 +        _bfd_riscv_elf_generic_reloc, /* special_function */
919 +        "R_RISCV_TLS_GD_LO16", /* name */
920 +        TRUE,                  /* partial_inplace */
921 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
922 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
923 +        FALSE),                /* pcrel_offset */
924 +
925 +  /* High 16 bits of displacement in global offset table.  */
926 +  HOWTO (R_RISCV_TLS_LDM_HI16, /* type */
927 +        0,                     /* rightshift */
928 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
929 +        RISCV_BIGIMM_BITS,     /* bitsize */
930 +        FALSE,                 /* pc_relative */
931 +        OP_SH_BIGIMMEDIATE,    /* bitpos */
932 +        complain_overflow_dont, /* complain_on_overflow */
933 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
934 +        "R_RISCV_TLS_LDM_HI16",        /* name */
935 +        TRUE,                  /* partial_inplace */
936 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,              /* src_mask */
937 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,              /* dst_mask */
938 +        FALSE),                /* pcrel_offset */
939 +
940 +  /* TLS thread pointer offset.  */
941 +  HOWTO (R_RISCV_TLS_LDM_LO16, /* type */
942 +        0,                     /* rightshift */
943 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
944 +        RISCV_IMM_BITS,                        /* bitsize */
945 +        FALSE,                 /* pc_relative */
946 +        OP_SH_IMMEDIATE,       /* bitpos */
947 +        complain_overflow_dont, /* complain_on_overflow */
948 +        _bfd_riscv_elf_generic_reloc, /* special_function */
949 +        "R_RISCV_TLS_LDM_LO16",        /* name */
950 +        TRUE,                  /* partial_inplace */
951 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
952 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
953 +        FALSE),                /* pcrel_offset */
954 +
955 +  /* 32 bit relocation with no addend.  */
956 +  HOWTO (R_RISCV_GLOB_DAT,     /* type */
957 +        0,                     /* rightshift */
958 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
959 +        32,                    /* bitsize */
960 +        FALSE,                 /* pc_relative */
961 +        0,                     /* bitpos */
962 +        complain_overflow_dont, /* complain_on_overflow */
963 +        _bfd_riscv_elf_generic_reloc, /* special_function */
964 +        "R_RISCV_GLOB_DAT",    /* name */
965 +        FALSE,                 /* partial_inplace */
966 +        0x0,                   /* src_mask */
967 +        0xffffffff,            /* dst_mask */
968 +        FALSE),                /* pcrel_offset */
969 +};
970 +
971 +/* The relocation table used for SHT_RELA sections.  */
972 +
973 +static reloc_howto_type elf_mips_howto_table_rela[] =
974 +{
975 +  /* No relocation.  */
976 +  HOWTO (R_RISCV_NONE,         /* type */
977 +        0,                     /* rightshift */
978 +        0,                     /* size (0 = byte, 1 = short, 2 = long) */
979 +        0,                     /* bitsize */
980 +        FALSE,                 /* pc_relative */
981 +        0,                     /* bitpos */
982 +        complain_overflow_dont, /* complain_on_overflow */
983 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
984 +        "R_RISCV_NONE",                /* name */
985 +        FALSE,                 /* partial_inplace */
986 +        0,                     /* src_mask */
987 +        0,                     /* dst_mask */
988 +        FALSE),                /* pcrel_offset */
989 +
990 +  EMPTY_HOWTO (1),
991 +
992 +  /* 32 bit relocation.  */
993 +  HOWTO (R_RISCV_32,           /* type */
994 +        0,                     /* rightshift */
995 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
996 +        32,                    /* bitsize */
997 +        FALSE,                 /* pc_relative */
998 +        0,                     /* bitpos */
999 +        complain_overflow_dont, /* complain_on_overflow */
1000 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1001 +        "R_RISCV_32",          /* name */
1002 +        FALSE,                 /* partial_inplace */
1003 +        0,                     /* src_mask */
1004 +        0xffffffff,            /* dst_mask */
1005 +        FALSE),                /* pcrel_offset */
1006 +
1007 +  /* 32 bit symbol relative relocation.  */
1008 +  HOWTO (R_RISCV_REL32,                /* type */
1009 +        0,                     /* rightshift */
1010 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1011 +        32,                    /* bitsize */
1012 +        FALSE,                 /* pc_relative */
1013 +        0,                     /* bitpos */
1014 +        complain_overflow_dont, /* complain_on_overflow */
1015 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1016 +        "R_RISCV_REL32",       /* name */
1017 +        FALSE,                 /* partial_inplace */
1018 +        0,                     /* src_mask */
1019 +        0xffffffff,            /* dst_mask */
1020 +        FALSE),                /* pcrel_offset */
1021 +
1022 +  /* 26 bit jump address.  */
1023 +  HOWTO (R_RISCV_26,           /* type */
1024 +        RISCV_JUMP_ALIGN_BITS,                 /* rightshift */
1025 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1026 +        RISCV_JUMP_BITS,                       /* bitsize */
1027 +        TRUE,                  /* pc_relative */
1028 +        OP_SH_TARGET,                  /* bitpos */
1029 +        complain_overflow_dont, /* complain_on_overflow */
1030 +                               /* This needs complex overflow
1031 +                                  detection, because the upper 36
1032 +                                  bits must match the PC + 4.  */
1033 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1034 +        "R_RISCV_26",          /* name */
1035 +        FALSE,                 /* partial_inplace */
1036 +        0,                     /* src_mask */
1037 +        ((1<<RISCV_JUMP_BITS)-1) << OP_SH_TARGET,              /* dst_mask */
1038 +        TRUE),         /* pcrel_offset */
1039 +
1040 +  /* High 16 bits of symbol value.  */
1041 +  HOWTO (R_RISCV_HI16,         /* type */
1042 +        0,                     /* rightshift */
1043 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1044 +        RISCV_BIGIMM_BITS,                     /* bitsize */
1045 +        FALSE,                 /* pc_relative */
1046 +        OP_SH_BIGIMMEDIATE,    /* bitpos */
1047 +        complain_overflow_dont, /* complain_on_overflow */
1048 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1049 +        "R_RISCV_HI16",                /* name */
1050 +        FALSE,                 /* partial_inplace */
1051 +        0,                     /* src_mask */
1052 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,              /* dst_mask */
1053 +        FALSE),                /* pcrel_offset */
1054 +
1055 +  /* Low 16 bits of symbol value.  */
1056 +  HOWTO (R_RISCV_LO16,         /* type */
1057 +        0,                     /* rightshift */
1058 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1059 +        RISCV_IMM_BITS,                        /* bitsize */
1060 +        FALSE,                 /* pc_relative */
1061 +        OP_SH_IMMEDIATE,       /* bitpos */
1062 +        complain_overflow_dont, /* complain_on_overflow */
1063 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1064 +        "R_RISCV_LO16",                /* name */
1065 +        FALSE,                 /* partial_inplace */
1066 +        0,                     /* src_mask */
1067 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,                /* dst_mask */
1068 +        FALSE),                /* pcrel_offset */
1069 +
1070 +  /* GP relative reference.  */
1071 +  HOWTO (R_RISCV_GPREL16,      /* type */
1072 +        0,                     /* rightshift */
1073 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1074 +        RISCV_IMM_BITS,                        /* bitsize */
1075 +        FALSE,                 /* pc_relative */
1076 +        OP_SH_IMMEDIATE,       /* bitpos */
1077 +        complain_overflow_signed, /* complain_on_overflow */
1078 +        mips_elf_gprel16_reloc, /* special_function */
1079 +        "R_RISCV_GPREL16",     /* name */
1080 +        FALSE,                 /* partial_inplace */
1081 +        0,                     /* src_mask */
1082 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
1083 +        FALSE),                /* pcrel_offset */
1084 +
1085 +  /* Reference to literal section.  */
1086 +  HOWTO (R_RISCV_LITERAL,      /* type */
1087 +        0,                     /* rightshift */
1088 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1089 +        RISCV_IMM_BITS,                        /* bitsize */
1090 +        FALSE,                 /* pc_relative */
1091 +        OP_SH_IMMEDIATE,       /* bitpos */
1092 +        complain_overflow_signed, /* complain_on_overflow */
1093 +        mips_elf_literal_reloc, /* special_function */
1094 +        "R_RISCV_LITERAL",     /* name */
1095 +        FALSE,                 /* partial_inplace */
1096 +        0,                     /* src_mask */
1097 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
1098 +        FALSE),                /* pcrel_offset */
1099 +
1100 +  /* Reference to global offset table.  */
1101 +  HOWTO (R_RISCV_GOT16,                /* type */
1102 +        0,                     /* rightshift */
1103 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1104 +        RISCV_IMM_BITS,                        /* bitsize */
1105 +        FALSE,                 /* pc_relative */
1106 +        OP_SH_IMMEDIATE,       /* bitpos */
1107 +        complain_overflow_signed, /* complain_on_overflow */
1108 +        _bfd_riscv_elf_generic_reloc, /* special_function */
1109 +        "R_RISCV_GOT16",       /* name */
1110 +        FALSE,                 /* partial_inplace */
1111 +        0,                     /* src_mask */
1112 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
1113 +        FALSE),                /* pcrel_offset */
1114 +
1115 +  /* 16 bit PC relative reference.  Note that the ABI document has a typo
1116 +     and claims R_RISCV_PC16 to be not rightshifted, rendering it useless.
1117 +     We do the right thing here.  */
1118 +  HOWTO (R_RISCV_PC16,         /* type */
1119 +        2,                     /* rightshift */
1120 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1121 +        RISCV_IMM_BITS,                        /* bitsize */
1122 +        TRUE,                  /* pc_relative */
1123 +        OP_SH_IMMEDIATE,       /* bitpos */
1124 +        complain_overflow_signed, /* complain_on_overflow */
1125 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1126 +        "R_RISCV_PC16",                /* name */
1127 +        FALSE,                 /* partial_inplace */
1128 +        0,                     /* src_mask */
1129 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
1130 +        TRUE),                 /* pcrel_offset */
1131 +
1132 +  /* 16 bit call through global offset table.  */
1133 +  HOWTO (R_RISCV_CALL16,               /* type */
1134 +        0,                     /* rightshift */
1135 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1136 +        RISCV_IMM_BITS,                        /* bitsize */
1137 +        FALSE,                 /* pc_relative */
1138 +        OP_SH_IMMEDIATE,       /* bitpos */
1139 +        complain_overflow_signed, /* complain_on_overflow */
1140 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1141 +        "R_RISCV_CALL16",      /* name */
1142 +        FALSE,                 /* partial_inplace */
1143 +        0,                     /* src_mask */
1144 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
1145 +        FALSE),                /* pcrel_offset */
1146 +
1147 +  /* 32 bit GP relative reference.  */
1148 +  HOWTO (R_RISCV_GPREL32,      /* type */
1149 +        0,                     /* rightshift */
1150 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1151 +        32,                    /* bitsize */
1152 +        FALSE,                 /* pc_relative */
1153 +        0,                     /* bitpos */
1154 +        complain_overflow_dont, /* complain_on_overflow */
1155 +        mips_elf_gprel32_reloc, /* special_function */
1156 +        "R_RISCV_GPREL32",     /* name */
1157 +        FALSE,                 /* partial_inplace */
1158 +        0,                     /* src_mask */
1159 +        0xffffffff,            /* dst_mask */
1160 +        FALSE),                /* pcrel_offset */
1161 +
1162 +  EMPTY_HOWTO (13),
1163 +  EMPTY_HOWTO (14),
1164 +  EMPTY_HOWTO (15),
1165 +  EMPTY_HOWTO (16),
1166 +  EMPTY_HOWTO (17),
1167 +
1168 +  /* 64 bit relocation.  */
1169 +  HOWTO (R_RISCV_64,           /* type */
1170 +        0,                     /* rightshift */
1171 +        4,                     /* size (0 = byte, 1 = short, 2 = long) */
1172 +        64,                    /* bitsize */
1173 +        FALSE,                 /* pc_relative */
1174 +        0,                     /* bitpos */
1175 +        complain_overflow_dont, /* complain_on_overflow */
1176 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1177 +        "R_RISCV_64",          /* name */
1178 +        FALSE,                 /* partial_inplace */
1179 +        0,                     /* src_mask */
1180 +        MINUS_ONE,             /* dst_mask */
1181 +        FALSE),                /* pcrel_offset */
1182 +
1183 +  /* Displacement in the global offset table.  */
1184 +  HOWTO (R_RISCV_GOT_DISP,     /* type */
1185 +        0,                     /* rightshift */
1186 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1187 +        RISCV_IMM_BITS,                        /* bitsize */
1188 +        FALSE,                 /* pc_relative */
1189 +        OP_SH_IMMEDIATE,       /* bitpos */
1190 +        complain_overflow_signed, /* complain_on_overflow */
1191 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1192 +        "R_RISCV_GOT_DISP",    /* name */
1193 +        FALSE,                 /* partial_inplace */
1194 +        0,                     /* src_mask */
1195 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
1196 +        FALSE),                /* pcrel_offset */
1197 +
1198 +  EMPTY_HOWTO (20),
1199 +  EMPTY_HOWTO (21),
1200 +
1201 +  /* High 16 bits of displacement in global offset table.  */
1202 +  HOWTO (R_RISCV_GOT_HI16,     /* type */
1203 +        0,                     /* rightshift */
1204 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1205 +        RISCV_BIGIMM_BITS,                     /* bitsize */
1206 +        TRUE,                  /* pc_relative */
1207 +        OP_SH_BIGIMMEDIATE,    /* bitpos */
1208 +        complain_overflow_dont, /* complain_on_overflow */
1209 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1210 +        "R_RISCV_GOT_HI16",    /* name */
1211 +        FALSE,                 /* partial_inplace */
1212 +        0,                     /* src_mask */
1213 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,      /* dst_mask */
1214 +        FALSE),                /* pcrel_offset */
1215 +
1216 +  /* Low 16 bits of displacement in global offset table.  */
1217 +  HOWTO (R_RISCV_GOT_LO16,     /* type */
1218 +        0,                     /* rightshift */
1219 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1220 +        RISCV_IMM_BITS,                        /* bitsize */
1221 +        TRUE,                  /* pc_relative */
1222 +        OP_SH_IMMEDIATE,       /* bitpos */
1223 +        complain_overflow_dont, /* complain_on_overflow */
1224 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1225 +        "R_RISCV_GOT_LO16",    /* name */
1226 +        FALSE,                 /* partial_inplace */
1227 +        0,                     /* src_mask */
1228 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
1229 +        FALSE),                /* pcrel_offset */
1230 +
1231 +  /* 64 bit subtraction.  */
1232 +  HOWTO (R_RISCV_SUB,          /* type */
1233 +        0,                     /* rightshift */
1234 +        4,                     /* size (0 = byte, 1 = short, 2 = long) */
1235 +        64,                    /* bitsize */
1236 +        FALSE,                 /* pc_relative */
1237 +        0,                     /* bitpos */
1238 +        complain_overflow_dont, /* complain_on_overflow */
1239 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1240 +        "R_RISCV_SUB",         /* name */
1241 +        FALSE,                 /* partial_inplace */
1242 +        0,                     /* src_mask */
1243 +        MINUS_ONE,             /* dst_mask */
1244 +        FALSE),                /* pcrel_offset */
1245 +
1246 +  /* Insert the addend as an instruction.  */
1247 +  /* FIXME: Not handled correctly.  */
1248 +  HOWTO (R_RISCV_INSERT_A,     /* type */
1249 +        0,                     /* rightshift */
1250 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1251 +        32,                    /* bitsize */
1252 +        FALSE,                 /* pc_relative */
1253 +        0,                     /* bitpos */
1254 +        complain_overflow_dont, /* complain_on_overflow */
1255 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1256 +        "R_RISCV_INSERT_A",    /* name */
1257 +        FALSE,                 /* partial_inplace */
1258 +        0,                     /* src_mask */
1259 +        0xffffffff,            /* dst_mask */
1260 +        FALSE),                /* pcrel_offset */
1261 +
1262 +  /* Insert the addend as an instruction, and change all relocations
1263 +     to refer to the old instruction at the address.  */
1264 +  /* FIXME: Not handled correctly.  */
1265 +  HOWTO (R_RISCV_INSERT_B,     /* type */
1266 +        0,                     /* rightshift */
1267 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1268 +        32,                    /* bitsize */
1269 +        FALSE,                 /* pc_relative */
1270 +        0,                     /* bitpos */
1271 +        complain_overflow_dont, /* complain_on_overflow */
1272 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1273 +        "R_RISCV_INSERT_B",    /* name */
1274 +        FALSE,                 /* partial_inplace */
1275 +        0,                     /* src_mask */
1276 +        0xffffffff,            /* dst_mask */
1277 +        FALSE),                /* pcrel_offset */
1278 +
1279 +  /* Delete a 32 bit instruction.  */
1280 +  /* FIXME: Not handled correctly.  */
1281 +  HOWTO (R_RISCV_DELETE,               /* type */
1282 +        0,                     /* rightshift */
1283 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1284 +        32,                    /* bitsize */
1285 +        FALSE,                 /* pc_relative */
1286 +        0,                     /* bitpos */
1287 +        complain_overflow_dont, /* complain_on_overflow */
1288 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1289 +        "R_RISCV_DELETE",      /* name */
1290 +        FALSE,                 /* partial_inplace */
1291 +        0,                     /* src_mask */
1292 +        0xffffffff,            /* dst_mask */
1293 +        FALSE),                /* pcrel_offset */
1294 +
1295 +  EMPTY_HOWTO (28),
1296 +  EMPTY_HOWTO (29),
1297 +
1298 +  /* High 16 bits of displacement in global offset table.  */
1299 +  HOWTO (R_RISCV_CALL_HI16,    /* type */
1300 +        0,                     /* rightshift */
1301 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1302 +        RISCV_BIGIMM_BITS,                     /* bitsize */
1303 +        FALSE,                 /* pc_relative */
1304 +        OP_SH_BIGIMMEDIATE,    /* bitpos */
1305 +        complain_overflow_dont, /* complain_on_overflow */
1306 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1307 +        "R_RISCV_CALL_HI16",   /* name */
1308 +        FALSE,                 /* partial_inplace */
1309 +        0,                     /* src_mask */
1310 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,      /* dst_mask */
1311 +        FALSE),                /* pcrel_offset */
1312 +
1313 +  /* Low 16 bits of displacement in global offset table.  */
1314 +  HOWTO (R_RISCV_CALL_LO16,    /* type */
1315 +        0,                     /* rightshift */
1316 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1317 +        RISCV_IMM_BITS,                        /* bitsize */
1318 +        FALSE,                 /* pc_relative */
1319 +        OP_SH_IMMEDIATE,       /* bitpos */
1320 +        complain_overflow_dont, /* complain_on_overflow */
1321 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1322 +        "R_RISCV_CALL_LO16",   /* name */
1323 +        FALSE,                 /* partial_inplace */
1324 +        0,                     /* src_mask */
1325 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
1326 +        FALSE),                /* pcrel_offset */
1327 +
1328 +  /* Section displacement, used by an associated event location section.  */
1329 +  HOWTO (R_RISCV_SCN_DISP,     /* type */
1330 +        0,                     /* rightshift */
1331 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1332 +        32,                    /* bitsize */
1333 +        FALSE,                 /* pc_relative */
1334 +        0,                     /* bitpos */
1335 +        complain_overflow_dont, /* complain_on_overflow */
1336 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1337 +        "R_RISCV_SCN_DISP",    /* name */
1338 +        FALSE,                 /* partial_inplace */
1339 +        0,                     /* src_mask */
1340 +        0xffffffff,            /* dst_mask */
1341 +        FALSE),                /* pcrel_offset */
1342 +
1343 +  HOWTO (R_RISCV_REL16,                /* type */
1344 +        0,                     /* rightshift */
1345 +        1,                     /* size (0 = byte, 1 = short, 2 = long) */
1346 +        RISCV_IMM_BITS,                        /* bitsize */
1347 +        FALSE,                 /* pc_relative */
1348 +        OP_SH_IMMEDIATE,       /* bitpos */
1349 +        complain_overflow_signed, /* complain_on_overflow */
1350 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1351 +        "R_RISCV_REL16",       /* name */
1352 +        FALSE,                 /* partial_inplace */
1353 +        0,                     /* src_mask */
1354 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
1355 +        FALSE),                /* pcrel_offset */
1356 +
1357 +  /* These two are obsolete.  */
1358 +  EMPTY_HOWTO (R_RISCV_ADD_IMMEDIATE),
1359 +  EMPTY_HOWTO (R_RISCV_PJUMP),
1360 +
1361 +  /* Similiar to R_RISCV_REL32, but used for relocations in a GOT section.
1362 +     It must be used for multigot GOT's (and only there).  */
1363 +  HOWTO (R_RISCV_RELGOT,               /* type */
1364 +        0,                     /* rightshift */
1365 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1366 +        32,                    /* bitsize */
1367 +        FALSE,                 /* pc_relative */
1368 +        0,                     /* bitpos */
1369 +        complain_overflow_dont, /* complain_on_overflow */
1370 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1371 +        "R_RISCV_RELGOT",      /* name */
1372 +        FALSE,                 /* partial_inplace */
1373 +        0,                     /* src_mask */
1374 +        0xffffffff,            /* dst_mask */
1375 +        FALSE),                /* pcrel_offset */
1376 +
1377 +  EMPTY_HOWTO(37),
1378 +
1379 +  /* TLS relocations.  */
1380 +  HOWTO (R_RISCV_TLS_DTPMOD32, /* type */
1381 +        0,                     /* rightshift */
1382 +        4,                     /* size (0 = byte, 1 = short, 2 = long) */
1383 +        32,                    /* bitsize */
1384 +        FALSE,                 /* pc_relative */
1385 +        0,                     /* bitpos */
1386 +        complain_overflow_dont, /* complain_on_overflow */
1387 +        _bfd_riscv_elf_generic_reloc, /* special_function */
1388 +        "R_RISCV_TLS_DTPMOD32", /* name */
1389 +        FALSE,                 /* partial_inplace */
1390 +        MINUS_ONE,             /* src_mask */
1391 +        MINUS_ONE,             /* dst_mask */
1392 +        FALSE),                /* pcrel_offset */
1393 +
1394 +  HOWTO (R_RISCV_TLS_DTPREL32, /* type */
1395 +        0,                     /* rightshift */
1396 +        4,                     /* size (0 = byte, 1 = short, 2 = long) */
1397 +        32,                    /* bitsize */
1398 +        FALSE,                 /* pc_relative */
1399 +        0,                     /* bitpos */
1400 +        complain_overflow_dont, /* complain_on_overflow */
1401 +        _bfd_riscv_elf_generic_reloc, /* special_function */
1402 +        "R_RISCV_TLS_DTPREL32",        /* name */
1403 +        TRUE,                  /* partial_inplace */
1404 +        MINUS_ONE,             /* src_mask */
1405 +        MINUS_ONE,             /* dst_mask */
1406 +        FALSE),                /* pcrel_offset */
1407 +
1408 +  EMPTY_HOWTO (R_RISCV_TLS_DTPMOD64),
1409 +  EMPTY_HOWTO (R_RISCV_TLS_DTPREL64),
1410 +
1411 +  /* TLS general dynamic variable reference.  */
1412 +  HOWTO (R_RISCV_TLS_GD,       /* type */
1413 +        0,                     /* rightshift */
1414 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1415 +        RISCV_IMM_BITS,        /* bitsize */
1416 +        FALSE,                 /* pc_relative */
1417 +        OP_SH_IMMEDIATE,       /* bitpos */
1418 +        complain_overflow_signed, /* complain_on_overflow */
1419 +        _bfd_riscv_elf_generic_reloc, /* special_function */
1420 +        "R_RISCV_TLS_GD",      /* name */
1421 +        TRUE,                  /* partial_inplace */
1422 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
1423 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
1424 +        FALSE),                /* pcrel_offset */
1425 +
1426 +  /* TLS local dynamic variable reference.  */
1427 +  HOWTO (R_RISCV_TLS_LDM,      /* type */
1428 +        0,                     /* rightshift */
1429 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1430 +        RISCV_IMM_BITS,        /* bitsize */
1431 +        FALSE,                 /* pc_relative */
1432 +        OP_SH_IMMEDIATE,       /* bitpos */
1433 +        complain_overflow_signed, /* complain_on_overflow */
1434 +        _bfd_riscv_elf_generic_reloc, /* special_function */
1435 +        "R_RISCV_TLS_LDM",     /* name */
1436 +        TRUE,                  /* partial_inplace */
1437 +        0,                     /* src_mask */
1438 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
1439 +        FALSE),                /* pcrel_offset */
1440 +
1441 +  /* TLS local dynamic offset.  */
1442 +  HOWTO (R_RISCV_TLS_DTPREL_HI16,      /* type */
1443 +        0,                     /* rightshift */
1444 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1445 +        RISCV_BIGIMM_BITS,     /* bitsize */
1446 +        FALSE,                 /* pc_relative */
1447 +        OP_SH_BIGIMMEDIATE,    /* bitpos */
1448 +        complain_overflow_signed, /* complain_on_overflow */
1449 +        _bfd_riscv_elf_generic_reloc, /* special_function */
1450 +        "R_RISCV_TLS_DTPREL_HI16",     /* name */
1451 +        TRUE,                  /* partial_inplace */
1452 +        0,                     /* src_mask */
1453 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,      /* dst_mask */
1454 +        FALSE),                /* pcrel_offset */
1455 +
1456 +  /* TLS local dynamic offset.  */
1457 +  HOWTO (R_RISCV_TLS_DTPREL_LO16,      /* type */
1458 +        0,                     /* rightshift */
1459 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1460 +        RISCV_IMM_BITS,        /* bitsize */
1461 +        FALSE,                 /* pc_relative */
1462 +        OP_SH_IMMEDIATE,       /* bitpos */
1463 +        complain_overflow_signed, /* complain_on_overflow */
1464 +        _bfd_riscv_elf_generic_reloc, /* special_function */
1465 +        "R_RISCV_TLS_DTPREL_LO16",     /* name */
1466 +        TRUE,                  /* partial_inplace */
1467 +        0,                     /* src_mask */
1468 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
1469 +        FALSE),                /* pcrel_offset */
1470 +
1471 +  /* TLS thread pointer offset.  */
1472 +  HOWTO (R_RISCV_TLS_GOTTPREL, /* type */
1473 +        0,                     /* rightshift */
1474 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1475 +        RISCV_IMM_BITS,        /* bitsize */
1476 +        FALSE,                 /* pc_relative */
1477 +        OP_SH_IMMEDIATE,       /* bitpos */
1478 +        complain_overflow_signed, /* complain_on_overflow */
1479 +        _bfd_riscv_elf_generic_reloc, /* special_function */
1480 +        "R_RISCV_TLS_GOTTPREL",        /* name */
1481 +        TRUE,                  /* partial_inplace */
1482 +        0,                     /* src_mask */
1483 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
1484 +        FALSE),                /* pcrel_offset */
1485 +
1486 +  HOWTO (R_RISCV_TLS_TPREL32,  /* type */
1487 +        0,                     /* rightshift */
1488 +        4,                     /* size (0 = byte, 1 = short, 2 = long) */
1489 +        32,                    /* bitsize */
1490 +        FALSE,                 /* pc_relative */
1491 +        0,                     /* bitpos */
1492 +        complain_overflow_dont, /* complain_on_overflow */
1493 +        _bfd_riscv_elf_generic_reloc, /* special_function */
1494 +        "R_RISCV_TLS_TPREL32", /* name */
1495 +        FALSE,                 /* partial_inplace */
1496 +        MINUS_ONE,             /* src_mask */
1497 +        MINUS_ONE,             /* dst_mask */
1498 +        FALSE),                /* pcrel_offset */
1499 +
1500 +  EMPTY_HOWTO (R_RISCV_TLS_TPREL64),
1501 +
1502 +  /* TLS thread pointer offset.  */
1503 +  HOWTO (R_RISCV_TLS_TPREL_HI16,       /* type */
1504 +        0,                     /* rightshift */
1505 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1506 +        RISCV_BIGIMM_BITS,     /* bitsize */
1507 +        FALSE,                 /* pc_relative */
1508 +        OP_SH_BIGIMMEDIATE,    /* bitpos */
1509 +        complain_overflow_signed, /* complain_on_overflow */
1510 +        _bfd_riscv_elf_generic_reloc, /* special_function */
1511 +        "R_RISCV_TLS_TPREL_HI16", /* name */
1512 +        TRUE,                  /* partial_inplace */
1513 +        0,                     /* src_mask */
1514 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,      /* dst_mask */
1515 +        FALSE),                /* pcrel_offset */
1516 +
1517 +  /* TLS thread pointer offset.  */
1518 +  HOWTO (R_RISCV_TLS_TPREL_LO16,       /* type */
1519 +        0,                     /* rightshift */
1520 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1521 +        RISCV_IMM_BITS,        /* bitsize */
1522 +        FALSE,                 /* pc_relative */
1523 +        OP_SH_IMMEDIATE,       /* bitpos */
1524 +        complain_overflow_signed, /* complain_on_overflow */
1525 +        _bfd_riscv_elf_generic_reloc, /* special_function */
1526 +        "R_RISCV_TLS_TPREL_LO16", /* name */
1527 +        TRUE,                  /* partial_inplace */
1528 +        0,                     /* src_mask */
1529 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
1530 +        FALSE),                /* pcrel_offset */
1531 +
1532 +  /* High 16 bits of displacement in global offset table.  */
1533 +  HOWTO (R_RISCV_TLS_GOT_HI16, /* type */
1534 +        0,                     /* rightshift */
1535 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1536 +        RISCV_BIGIMM_BITS,                     /* bitsize */
1537 +        TRUE,                  /* pc_relative */
1538 +        OP_SH_BIGIMMEDIATE,    /* bitpos */
1539 +        complain_overflow_dont, /* complain_on_overflow */
1540 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1541 +        "R_RISCV_TLS_GOT_HI16",        /* name */
1542 +        FALSE,                 /* partial_inplace */
1543 +        0,                     /* src_mask */
1544 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,      /* dst_mask */
1545 +        FALSE),                /* pcrel_offset */
1546 +
1547 +  /* Low 16 bits of displacement in global offset table.  */
1548 +  HOWTO (R_RISCV_TLS_GOT_LO16, /* type */
1549 +        0,                     /* rightshift */
1550 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1551 +        RISCV_IMM_BITS,                        /* bitsize */
1552 +        TRUE,                  /* pc_relative */
1553 +        OP_SH_IMMEDIATE,       /* bitpos */
1554 +        complain_overflow_dont, /* complain_on_overflow */
1555 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1556 +        "R_RISCV_TLS_GOT_LO16",        /* name */
1557 +        FALSE,                 /* partial_inplace */
1558 +        0,                     /* src_mask */
1559 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
1560 +        FALSE),                /* pcrel_offset */
1561 +
1562 +  /* High 16 bits of displacement in global offset table.  */
1563 +  HOWTO (R_RISCV_TLS_GD_HI16,  /* type */
1564 +        0,                     /* rightshift */
1565 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1566 +        RISCV_BIGIMM_BITS,                     /* bitsize */
1567 +        FALSE,                 /* pc_relative */
1568 +        OP_SH_BIGIMMEDIATE,    /* bitpos */
1569 +        complain_overflow_dont, /* complain_on_overflow */
1570 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1571 +        "R_RISCV_TLS_GD_HI16", /* name */
1572 +        FALSE,                 /* partial_inplace */
1573 +        0,                     /* src_mask */
1574 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,      /* dst_mask */
1575 +        FALSE),                /* pcrel_offset */
1576 +
1577 +  /* Low 16 bits of displacement in global offset table.  */
1578 +  HOWTO (R_RISCV_TLS_GD_LO16,  /* type */
1579 +        0,                     /* rightshift */
1580 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1581 +        RISCV_IMM_BITS,                        /* bitsize */
1582 +        FALSE,                 /* pc_relative */
1583 +        OP_SH_IMMEDIATE,       /* bitpos */
1584 +        complain_overflow_dont, /* complain_on_overflow */
1585 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1586 +        "R_RISCV_TLS_GD_LO16", /* name */
1587 +        FALSE,                 /* partial_inplace */
1588 +        0,                     /* src_mask */
1589 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
1590 +        FALSE),                /* pcrel_offset */
1591 +
1592 +  /* High 16 bits of displacement in global offset table.  */
1593 +  HOWTO (R_RISCV_TLS_LDM_HI16, /* type */
1594 +        0,                     /* rightshift */
1595 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1596 +        RISCV_BIGIMM_BITS,                     /* bitsize */
1597 +        FALSE,                 /* pc_relative */
1598 +        OP_SH_BIGIMMEDIATE,    /* bitpos */
1599 +        complain_overflow_dont, /* complain_on_overflow */
1600 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1601 +        "R_RISCV_TLS_LDM_HI16",        /* name */
1602 +        FALSE,                 /* partial_inplace */
1603 +        0,                     /* src_mask */
1604 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,      /* dst_mask */
1605 +        FALSE),                /* pcrel_offset */
1606 +
1607 +  /* Low 16 bits of displacement in global offset table.  */
1608 +  HOWTO (R_RISCV_TLS_LDM_LO16, /* type */
1609 +        0,                     /* rightshift */
1610 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1611 +        RISCV_IMM_BITS,                        /* bitsize */
1612 +        FALSE,                 /* pc_relative */
1613 +        OP_SH_IMMEDIATE,       /* bitpos */
1614 +        complain_overflow_dont, /* complain_on_overflow */
1615 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
1616 +        "R_RISCV_TLS_LDM_LO16",        /* name */
1617 +        FALSE,                 /* partial_inplace */
1618 +        0,                     /* src_mask */
1619 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
1620 +        FALSE),                /* pcrel_offset */
1621 +
1622 +  /* 32 bit relocation with no addend.  */
1623 +  HOWTO (R_RISCV_GLOB_DAT,     /* type */
1624 +        0,                     /* rightshift */
1625 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1626 +        32,                    /* bitsize */
1627 +        FALSE,                 /* pc_relative */
1628 +        0,                     /* bitpos */
1629 +        complain_overflow_dont, /* complain_on_overflow */
1630 +        _bfd_riscv_elf_generic_reloc, /* special_function */
1631 +        "R_RISCV_GLOB_DAT",    /* name */
1632 +        FALSE,                 /* partial_inplace */
1633 +        0x0,                   /* src_mask */
1634 +        0xffffffff,            /* dst_mask */
1635 +        FALSE),                /* pcrel_offset */
1636 +};
1637 +
1638 +/* GNU extension to record C++ vtable hierarchy */
1639 +static reloc_howto_type elf_mips_gnu_vtinherit_howto =
1640 +  HOWTO (R_RISCV_GNU_VTINHERIT,        /* type */
1641 +        0,                     /* rightshift */
1642 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1643 +        0,                     /* bitsize */
1644 +        FALSE,                 /* pc_relative */
1645 +        0,                     /* bitpos */
1646 +        complain_overflow_dont, /* complain_on_overflow */
1647 +        NULL,                  /* special_function */
1648 +        "R_RISCV_GNU_VTINHERIT", /* name */
1649 +        FALSE,                 /* partial_inplace */
1650 +        0,                     /* src_mask */
1651 +        0,                     /* dst_mask */
1652 +        FALSE);                /* pcrel_offset */
1653 +
1654 +/* GNU extension to record C++ vtable member usage */
1655 +static reloc_howto_type elf_mips_gnu_vtentry_howto =
1656 +  HOWTO (R_RISCV_GNU_VTENTRY,  /* type */
1657 +        0,                     /* rightshift */
1658 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1659 +        0,                     /* bitsize */
1660 +        FALSE,                 /* pc_relative */
1661 +        0,                     /* bitpos */
1662 +        complain_overflow_dont, /* complain_on_overflow */
1663 +        _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1664 +        "R_RISCV_GNU_VTENTRY", /* name */
1665 +        FALSE,                 /* partial_inplace */
1666 +        0,                     /* src_mask */
1667 +        0,                     /* dst_mask */
1668 +        FALSE);                /* pcrel_offset */
1669 +\f
1670 +/* 16 bit offset for pc-relative branches.  */
1671 +static reloc_howto_type elf_mips_gnu_rel16_s2 =
1672 +  HOWTO (R_RISCV_GNU_REL16_S2, /* type */
1673 +        2,                     /* rightshift */
1674 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1675 +        16,                    /* bitsize */
1676 +        TRUE,                  /* pc_relative */
1677 +        0,                     /* bitpos */
1678 +        complain_overflow_signed, /* complain_on_overflow */
1679 +        _bfd_riscv_elf_generic_reloc, /* special_function */
1680 +        "R_RISCV_GNU_REL16_S2",        /* name */
1681 +        TRUE,                  /* partial_inplace */
1682 +        0x0000ffff,            /* src_mask */
1683 +        0x0000ffff,            /* dst_mask */
1684 +        TRUE);                 /* pcrel_offset */
1685 +
1686 +/* 16 bit offset for pc-relative branches.  */
1687 +static reloc_howto_type elf_mips_gnu_rela16_s2 =
1688 +  HOWTO (R_RISCV_GNU_REL16_S2, /* type */
1689 +        2,                     /* rightshift */
1690 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1691 +        16,                    /* bitsize */
1692 +        TRUE,                  /* pc_relative */
1693 +        0,                     /* bitpos */
1694 +        complain_overflow_signed, /* complain_on_overflow */
1695 +        _bfd_riscv_elf_generic_reloc, /* special_function */
1696 +        "R_RISCV_GNU_REL16_S2",        /* name */
1697 +        FALSE,                 /* partial_inplace */
1698 +        0,                     /* src_mask */
1699 +        0x0000ffff,            /* dst_mask */
1700 +        TRUE);                 /* pcrel_offset */
1701 +\f
1702 +/* Originally a VxWorks extension, but now used for other systems too.  */
1703 +static reloc_howto_type elf_mips_copy_howto =
1704 +  HOWTO (R_RISCV_COPY,         /* type */
1705 +        0,                     /* rightshift */
1706 +        0,                     /* this one is variable size */
1707 +        0,                     /* bitsize */
1708 +        FALSE,                 /* pc_relative */
1709 +        0,                     /* bitpos */
1710 +        complain_overflow_bitfield, /* complain_on_overflow */
1711 +        bfd_elf_generic_reloc, /* special_function */
1712 +        "R_RISCV_COPY",                /* name */
1713 +        FALSE,                 /* partial_inplace */
1714 +        0x0,                   /* src_mask */
1715 +        0x0,                   /* dst_mask */
1716 +        FALSE);                /* pcrel_offset */
1717 +
1718 +/* Originally a VxWorks extension, but now used for other systems too.  */
1719 +static reloc_howto_type elf_mips_jump_slot_howto =
1720 +  HOWTO (R_RISCV_JUMP_SLOT,    /* type */
1721 +        0,                     /* rightshift */
1722 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
1723 +        32,                    /* bitsize */
1724 +        FALSE,                 /* pc_relative */
1725 +        0,                     /* bitpos */
1726 +        complain_overflow_bitfield, /* complain_on_overflow */
1727 +        bfd_elf_generic_reloc, /* special_function */
1728 +        "R_RISCV_JUMP_SLOT",   /* name */
1729 +        FALSE,                 /* partial_inplace */
1730 +        0x0,                   /* src_mask */
1731 +        0x0,                   /* dst_mask */
1732 +        FALSE);                /* pcrel_offset */
1733 +\f
1734 +/* Set the GP value for OUTPUT_BFD.  Returns FALSE if this is a
1735 +   dangerous relocation.  */
1736 +
1737 +static bfd_boolean
1738 +mips_elf_assign_gp (bfd *output_bfd, bfd_vma *pgp)
1739 +{
1740 +  unsigned int count;
1741 +  asymbol **sym;
1742 +  unsigned int i;
1743 +
1744 +  /* If we've already figured out what GP will be, just return it.  */
1745 +  *pgp = _bfd_get_gp_value (output_bfd);
1746 +  if (*pgp)
1747 +    return TRUE;
1748 +
1749 +  count = bfd_get_symcount (output_bfd);
1750 +  sym = bfd_get_outsymbols (output_bfd);
1751 +
1752 +  /* The linker script will have created a symbol named `_gp' with the
1753 +     appropriate value.  */
1754 +  if (sym == NULL)
1755 +    i = count;
1756 +  else
1757 +    {
1758 +      for (i = 0; i < count; i++, sym++)
1759 +       {
1760 +         register const char *name;
1761 +
1762 +         name = bfd_asymbol_name (*sym);
1763 +         if (*name == '_' && strcmp (name, "_gp") == 0)
1764 +           {
1765 +             *pgp = bfd_asymbol_value (*sym);
1766 +             _bfd_set_gp_value (output_bfd, *pgp);
1767 +             break;
1768 +           }
1769 +       }
1770 +    }
1771 +
1772 +  if (i >= count)
1773 +    {
1774 +      /* Only get the error once.  */
1775 +      *pgp = 4;
1776 +      _bfd_set_gp_value (output_bfd, *pgp);
1777 +      return FALSE;
1778 +    }
1779 +
1780 +  return TRUE;
1781 +}
1782 +
1783 +/* We have to figure out the gp value, so that we can adjust the
1784 +   symbol value correctly.  We look up the symbol _gp in the output
1785 +   BFD.  If we can't find it, we're stuck.  We cache it in the ELF
1786 +   target data.  We don't need to adjust the symbol value for an
1787 +   external symbol if we are producing relocatable output.  */
1788 +
1789 +static bfd_reloc_status_type
1790 +mips_elf_final_gp (bfd *output_bfd, asymbol *symbol, bfd_boolean relocatable,
1791 +                  char **error_message, bfd_vma *pgp)
1792 +{
1793 +  if (bfd_is_und_section (symbol->section)
1794 +      && ! relocatable)
1795 +    {
1796 +      *pgp = 0;
1797 +      return bfd_reloc_undefined;
1798 +    }
1799 +
1800 +  *pgp = _bfd_get_gp_value (output_bfd);
1801 +  if (*pgp == 0
1802 +      && (! relocatable
1803 +         || (symbol->flags & BSF_SECTION_SYM) != 0))
1804 +    {
1805 +      if (relocatable)
1806 +       {
1807 +         /* Make up a value.  */
1808 +         *pgp = symbol->section->output_section->vma /*+ 0x4000*/;
1809 +         _bfd_set_gp_value (output_bfd, *pgp);
1810 +       }
1811 +      else if (!mips_elf_assign_gp (output_bfd, pgp))
1812 +       {
1813 +         *error_message =
1814 +           (char *) _("GP relative relocation when _gp not defined");
1815 +         return bfd_reloc_dangerous;
1816 +       }
1817 +    }
1818 +
1819 +  return bfd_reloc_ok;
1820 +}
1821 +
1822 +/* Do a R_RISCV_GPREL16 relocation.  This is a 16 bit value which must
1823 +   become the offset from the gp register.  */
1824 +
1825 +static bfd_reloc_status_type
1826 +mips_elf_gprel16_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
1827 +                       asymbol *symbol, void *data ATTRIBUTE_UNUSED,
1828 +                       asection *input_section, bfd *output_bfd,
1829 +                       char **error_message ATTRIBUTE_UNUSED)
1830 +{
1831 +  bfd_boolean relocatable;
1832 +  bfd_reloc_status_type ret;
1833 +  bfd_vma gp;
1834 +
1835 +  if (output_bfd != NULL)
1836 +    relocatable = TRUE;
1837 +  else
1838 +    {
1839 +      relocatable = FALSE;
1840 +      output_bfd = symbol->section->output_section->owner;
1841 +    }
1842 +
1843 +  ret = mips_elf_final_gp (output_bfd, symbol, relocatable, error_message,
1844 +                          &gp);
1845 +  if (ret != bfd_reloc_ok)
1846 +    return ret;
1847 +
1848 +  return _bfd_riscv_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1849 +                                       input_section, relocatable,
1850 +                                       data, gp);
1851 +}
1852 +
1853 +/* Do a R_RISCV_LITERAL relocation.  */
1854 +
1855 +static bfd_reloc_status_type
1856 +mips_elf_literal_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
1857 +                       void *data, asection *input_section, bfd *output_bfd,
1858 +                       char **error_message)
1859 +{
1860 +  bfd_boolean relocatable;
1861 +  bfd_reloc_status_type ret;
1862 +  bfd_vma gp;
1863 +
1864 +  /* R_RISCV_LITERAL relocations are defined for local symbols only.  */
1865 +  if (output_bfd != NULL
1866 +      && (symbol->flags & BSF_SECTION_SYM) == 0
1867 +      && (symbol->flags & BSF_LOCAL) != 0)
1868 +    {
1869 +      *error_message = (char *)
1870 +       _("literal relocation occurs for an external symbol");
1871 +      return bfd_reloc_outofrange;
1872 +    }
1873 +
1874 +  /* FIXME: The entries in the .lit8 and .lit4 sections should be merged.  */
1875 +  if (output_bfd != NULL)
1876 +    relocatable = TRUE;
1877 +  else
1878 +    {
1879 +      relocatable = FALSE;
1880 +      output_bfd = symbol->section->output_section->owner;
1881 +    }
1882 +
1883 +  ret = mips_elf_final_gp (output_bfd, symbol, relocatable, error_message,
1884 +                          &gp);
1885 +  if (ret != bfd_reloc_ok)
1886 +    return ret;
1887 +
1888 +  return _bfd_riscv_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1889 +                                       input_section, relocatable,
1890 +                                       data, gp);
1891 +}
1892 +
1893 +/* Do a R_RISCV_GPREL32 relocation.  This is a 32 bit value which must
1894 +   become the offset from the gp register.  */
1895 +
1896 +static bfd_reloc_status_type
1897 +mips_elf_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
1898 +                       void *data, asection *input_section, bfd *output_bfd,
1899 +                       char **error_message)
1900 +{
1901 +  bfd_boolean relocatable;
1902 +  bfd_reloc_status_type ret;
1903 +  bfd_vma gp;
1904 +
1905 +  /* R_RISCV_GPREL32 relocations are defined for local symbols only.  */
1906 +  if (output_bfd != NULL
1907 +      && (symbol->flags & BSF_SECTION_SYM) == 0
1908 +      && (symbol->flags & BSF_LOCAL) != 0)
1909 +    {
1910 +      *error_message = (char *)
1911 +       _("32bits gp relative relocation occurs for an external symbol");
1912 +      return bfd_reloc_outofrange;
1913 +    }
1914 +
1915 +  if (output_bfd != NULL)
1916 +    {
1917 +      relocatable = TRUE;
1918 +      gp = _bfd_get_gp_value (output_bfd);
1919 +    }
1920 +  else
1921 +    {
1922 +      relocatable = FALSE;
1923 +      output_bfd = symbol->section->output_section->owner;
1924 +
1925 +      ret = mips_elf_final_gp (output_bfd, symbol, relocatable,
1926 +                              error_message, &gp);
1927 +      if (ret != bfd_reloc_ok)
1928 +       return ret;
1929 +    }
1930 +
1931 +  return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
1932 +                         relocatable, data, gp);
1933 +}
1934 +
1935 +static bfd_reloc_status_type
1936 +gprel32_with_gp (bfd *abfd, asymbol *symbol, arelent *reloc_entry,
1937 +                asection *input_section, bfd_boolean relocatable,
1938 +                void *data, bfd_vma gp)
1939 +{
1940 +  bfd_vma relocation;
1941 +  unsigned long val;
1942 +
1943 +  if (bfd_is_com_section (symbol->section))
1944 +    relocation = 0;
1945 +  else
1946 +    relocation = symbol->value;
1947 +
1948 +  relocation += symbol->section->output_section->vma;
1949 +  relocation += symbol->section->output_offset;
1950 +
1951 +  if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
1952 +    return bfd_reloc_outofrange;
1953 +
1954 +  if (reloc_entry->howto->src_mask == 0)
1955 +    val = 0;
1956 +  else
1957 +    val = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1958 +
1959 +  /* Set val to the offset into the section or symbol.  */
1960 +  val += reloc_entry->addend;
1961 +
1962 +  /* Adjust val for the final section location and GP value.  If we
1963 +     are producing relocatable output, we don't want to do this for
1964 +     an external symbol.  */
1965 +  if (! relocatable
1966 +      || (symbol->flags & BSF_SECTION_SYM) != 0)
1967 +    val += relocation - gp;
1968 +
1969 +  bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);
1970 +
1971 +  if (relocatable)
1972 +    reloc_entry->address += input_section->output_offset;
1973 +
1974 +  return bfd_reloc_ok;
1975 +}
1976 +
1977 +/* A mapping from BFD reloc types to MIPS ELF reloc types.  */
1978 +
1979 +struct elf_reloc_map {
1980 +  bfd_reloc_code_real_type bfd_val;
1981 +  enum elf_riscv_reloc_type elf_val;
1982 +};
1983 +
1984 +static const struct elf_reloc_map mips_reloc_map[] =
1985 +{
1986 +  { BFD_RELOC_NONE, R_RISCV_NONE },
1987 +  { BFD_RELOC_32, R_RISCV_32 },
1988 +  /* There is no BFD reloc for R_RISCV_REL32.  */
1989 +  { BFD_RELOC_CTOR, R_RISCV_32 },
1990 +  { BFD_RELOC_64, R_RISCV_64 },
1991 +  { BFD_RELOC_16_PCREL_S2, R_RISCV_PC16 },
1992 +  { BFD_RELOC_HI16_S, R_RISCV_HI16 },
1993 +  { BFD_RELOC_LO16, R_RISCV_LO16 },
1994 +  { BFD_RELOC_GPREL16, R_RISCV_GPREL16 },
1995 +  { BFD_RELOC_GPREL32, R_RISCV_GPREL32 },
1996 +  { BFD_RELOC_MIPS_JMP, R_RISCV_26 },
1997 +  { BFD_RELOC_MIPS_LITERAL, R_RISCV_LITERAL },
1998 +  { BFD_RELOC_MIPS_GOT16, R_RISCV_GOT16 },
1999 +  { BFD_RELOC_MIPS_CALL16, R_RISCV_CALL16 },
2000 +  { BFD_RELOC_MIPS_GOT_DISP, R_RISCV_GOT_DISP },
2001 +  { BFD_RELOC_MIPS_GOT_HI16, R_RISCV_GOT_HI16 },
2002 +  { BFD_RELOC_MIPS_GOT_LO16, R_RISCV_GOT_LO16 },
2003 +  { BFD_RELOC_MIPS_SUB, R_RISCV_SUB },
2004 +  { BFD_RELOC_MIPS_INSERT_A, R_RISCV_INSERT_A },
2005 +  { BFD_RELOC_MIPS_INSERT_B, R_RISCV_INSERT_B },
2006 +  { BFD_RELOC_MIPS_DELETE, R_RISCV_DELETE },
2007 +  { BFD_RELOC_MIPS_CALL_HI16, R_RISCV_CALL_HI16 },
2008 +  { BFD_RELOC_MIPS_CALL_LO16, R_RISCV_CALL_LO16 },
2009 +  { BFD_RELOC_MIPS_SCN_DISP, R_RISCV_SCN_DISP },
2010 +  { BFD_RELOC_MIPS_REL16, R_RISCV_REL16 },
2011 +  { BFD_RELOC_MIPS_RELGOT, R_RISCV_RELGOT },
2012 +  { BFD_RELOC_MIPS_TLS_DTPMOD32, R_RISCV_TLS_DTPMOD32 },
2013 +  { BFD_RELOC_MIPS_TLS_DTPREL32, R_RISCV_TLS_DTPREL32 },
2014 +  { BFD_RELOC_MIPS_TLS_DTPMOD64, R_RISCV_TLS_DTPMOD64 },
2015 +  { BFD_RELOC_MIPS_TLS_DTPREL64, R_RISCV_TLS_DTPREL64 },
2016 +  { BFD_RELOC_MIPS_TLS_GD, R_RISCV_TLS_GD },
2017 +  { BFD_RELOC_MIPS_TLS_LDM, R_RISCV_TLS_LDM },
2018 +  { BFD_RELOC_MIPS_TLS_DTPREL_HI16, R_RISCV_TLS_DTPREL_HI16 },
2019 +  { BFD_RELOC_MIPS_TLS_DTPREL_LO16, R_RISCV_TLS_DTPREL_LO16 },
2020 +  { BFD_RELOC_MIPS_TLS_GOTTPREL, R_RISCV_TLS_GOTTPREL },
2021 +  { BFD_RELOC_MIPS_TLS_TPREL32, R_RISCV_TLS_TPREL32 },
2022 +  { BFD_RELOC_MIPS_TLS_TPREL64, R_RISCV_TLS_TPREL64 },
2023 +  { BFD_RELOC_MIPS_TLS_TPREL_HI16, R_RISCV_TLS_TPREL_HI16 },
2024 +  { BFD_RELOC_MIPS_TLS_TPREL_LO16, R_RISCV_TLS_TPREL_LO16 }
2025 +};
2026 +
2027 +/* Given a BFD reloc type, return a howto structure.  */
2028 +
2029 +static reloc_howto_type *
2030 +bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2031 +                                bfd_reloc_code_real_type code)
2032 +{
2033 +  unsigned int i;
2034 +  /* FIXME: We default to RELA here instead of choosing the right
2035 +     relocation variant.  */
2036 +  reloc_howto_type *howto_table = elf_mips_howto_table_rela;
2037 +
2038 +  for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map);
2039 +       i++)
2040 +    {
2041 +      if (mips_reloc_map[i].bfd_val == code)
2042 +       return &howto_table[(int) mips_reloc_map[i].elf_val];
2043 +    }
2044 +
2045 +  switch (code)
2046 +    {
2047 +    case BFD_RELOC_VTABLE_INHERIT:
2048 +      return &elf_mips_gnu_vtinherit_howto;
2049 +    case BFD_RELOC_VTABLE_ENTRY:
2050 +      return &elf_mips_gnu_vtentry_howto;
2051 +    case BFD_RELOC_MIPS_COPY:
2052 +      return &elf_mips_copy_howto;
2053 +    case BFD_RELOC_MIPS_JUMP_SLOT:
2054 +      return &elf_mips_jump_slot_howto;
2055 +    default:
2056 +      bfd_set_error (bfd_error_bad_value);
2057 +      return NULL;
2058 +    }
2059 +}
2060 +
2061 +static reloc_howto_type *
2062 +bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2063 +                                const char *r_name)
2064 +{
2065 +  unsigned int i;
2066 +
2067 +  for (i = 0;
2068 +       i < (sizeof (elf_mips_howto_table_rela)
2069 +           / sizeof (elf_mips_howto_table_rela[0]));
2070 +       i++)
2071 +    if (elf_mips_howto_table_rela[i].name != NULL
2072 +       && strcasecmp (elf_mips_howto_table_rela[i].name, r_name) == 0)
2073 +      return &elf_mips_howto_table_rela[i];
2074 +
2075 +  if (strcasecmp (elf_mips_gnu_vtinherit_howto.name, r_name) == 0)
2076 +    return &elf_mips_gnu_vtinherit_howto;
2077 +  if (strcasecmp (elf_mips_gnu_vtentry_howto.name, r_name) == 0)
2078 +    return &elf_mips_gnu_vtentry_howto;
2079 +  if (strcasecmp (elf_mips_gnu_rel16_s2.name, r_name) == 0)
2080 +    return &elf_mips_gnu_rel16_s2;
2081 +  if (strcasecmp (elf_mips_gnu_rela16_s2.name, r_name) == 0)
2082 +    return &elf_mips_gnu_rela16_s2;
2083 +  if (strcasecmp (elf_mips_copy_howto.name, r_name) == 0)
2084 +    return &elf_mips_copy_howto;
2085 +  if (strcasecmp (elf_mips_jump_slot_howto.name, r_name) == 0)
2086 +    return &elf_mips_jump_slot_howto;
2087 +
2088 +  return NULL;
2089 +}
2090 +
2091 +/* Given a MIPS Elf_Internal_Rel, fill in an arelent structure.  */
2092 +
2093 +static reloc_howto_type *
2094 +mips_elf_n32_rtype_to_howto (unsigned int r_type, bfd_boolean rela_p)
2095 +{
2096 +  switch (r_type)
2097 +    {
2098 +    case R_RISCV_GNU_VTINHERIT:
2099 +      return &elf_mips_gnu_vtinherit_howto;
2100 +    case R_RISCV_GNU_VTENTRY:
2101 +      return &elf_mips_gnu_vtentry_howto;
2102 +    case R_RISCV_GNU_REL16_S2:
2103 +      if (rela_p)
2104 +       return &elf_mips_gnu_rela16_s2;
2105 +      else
2106 +       return &elf_mips_gnu_rel16_s2;
2107 +    case R_RISCV_COPY:
2108 +      return &elf_mips_copy_howto;
2109 +    case R_RISCV_JUMP_SLOT:
2110 +      return &elf_mips_jump_slot_howto;
2111 +    default:
2112 +      BFD_ASSERT (r_type < (unsigned int) R_RISCV_max);
2113 +      if (rela_p)
2114 +       return &elf_mips_howto_table_rela[r_type];
2115 +      else
2116 +       return &elf_mips_howto_table_rel[r_type];
2117 +      break;
2118 +    }
2119 +}
2120 +
2121 +/* Given a MIPS Elf_Internal_Rel, fill in an arelent structure.  */
2122 +
2123 +static void
2124 +mips_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
2125 +{
2126 +  unsigned int r_type;
2127 +
2128 +  r_type = ELF32_R_TYPE (dst->r_info);
2129 +  cache_ptr->howto = mips_elf_n32_rtype_to_howto (r_type, FALSE);
2130 +
2131 +  /* The addend for a GPREL16 or LITERAL relocation comes from the GP
2132 +     value for the object file.  We get the addend now, rather than
2133 +     when we do the relocation, because the symbol manipulations done
2134 +     by the linker may cause us to lose track of the input BFD.  */
2135 +  if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
2136 +      && (r_type == R_RISCV_GPREL16 || r_type == (unsigned int) R_RISCV_LITERAL))
2137 +    cache_ptr->addend = elf_gp (abfd);
2138 +}
2139 +
2140 +/* Given a MIPS Elf_Internal_Rela, fill in an arelent structure.  */
2141 +
2142 +static void
2143 +mips_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
2144 +                        arelent *cache_ptr, Elf_Internal_Rela *dst)
2145 +{
2146 +  unsigned int r_type;
2147 +
2148 +  r_type = ELF32_R_TYPE (dst->r_info);
2149 +  cache_ptr->howto = mips_elf_n32_rtype_to_howto (r_type, TRUE);
2150 +  cache_ptr->addend = dst->r_addend;
2151 +}
2152 +\f
2153 +/* Determine whether a symbol is global for the purposes of splitting
2154 +   the symbol table into global symbols and local symbols.  At least
2155 +   on Irix 5, this split must be between section symbols and all other
2156 +   symbols.  On most ELF targets the split is between static symbols
2157 +   and externally visible symbols.  */
2158 +
2159 +static bfd_boolean
2160 +mips_elf_sym_is_global (bfd *abfd ATTRIBUTE_UNUSED, asymbol *sym)
2161 +{
2162 +  return ((sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE)) != 0
2163 +         || bfd_is_und_section (bfd_get_section (sym))
2164 +         || bfd_is_com_section (bfd_get_section (sym)));
2165 +}
2166 +\f
2167 +/* Set the right machine number for a MIPS ELF file.  */
2168 +
2169 +static bfd_boolean
2170 +mips_elf_n32_object_p (bfd *abfd)
2171 +{
2172 +  unsigned long mach;
2173 +
2174 +  mach = _bfd_elf_riscv_mach (elf_elfheader (abfd)->e_flags);
2175 +  bfd_default_set_arch_mach (abfd, bfd_arch_riscv, mach);
2176 +  return TRUE;
2177 +}
2178 +\f
2179 +/* Support for core dump NOTE sections.  */
2180 +static bfd_boolean
2181 +elf32_mips_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
2182 +{
2183 +  int offset;
2184 +  unsigned int size;
2185 +
2186 +  switch (note->descsz)
2187 +    {
2188 +      default:
2189 +       return FALSE;
2190 +
2191 +      case 440:                /* Linux/MIPS N32 */
2192 +       /* pr_cursig */
2193 +       elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
2194 +
2195 +       /* pr_pid */
2196 +       elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, note->descdata + 24);
2197 +
2198 +       /* pr_reg */
2199 +       offset = 72;
2200 +       size = 360;
2201 +
2202 +       break;
2203 +    }
2204 +
2205 +  /* Make a ".reg/999" section.  */
2206 +  return _bfd_elfcore_make_pseudosection (abfd, ".reg", size,
2207 +                                         note->descpos + offset);
2208 +}
2209 +
2210 +static bfd_boolean
2211 +elf32_mips_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
2212 +{
2213 +  switch (note->descsz)
2214 +    {
2215 +      default:
2216 +       return FALSE;
2217 +
2218 +      case 128:                /* Linux/MIPS elf_prpsinfo */
2219 +       elf_tdata (abfd)->core_program
2220 +        = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
2221 +       elf_tdata (abfd)->core_command
2222 +        = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
2223 +    }
2224 +
2225 +  /* Note that for some reason, a spurious space is tacked
2226 +     onto the end of the args in some (at least one anyway)
2227 +     implementations, so strip it off if it exists.  */
2228 +
2229 +  {
2230 +    char *command = elf_tdata (abfd)->core_command;
2231 +    int n = strlen (command);
2232 +
2233 +    if (0 < n && command[n - 1] == ' ')
2234 +      command[n - 1] = '\0';
2235 +  }
2236 +
2237 +  return TRUE;
2238 +}
2239 +
2240 +/* ECOFF swapping routines.  These are used when dealing with the
2241 +   .mdebug section, which is in the ECOFF debugging format.  */
2242 +static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = {
2243 +  /* Symbol table magic number.  */
2244 +  magicSym,
2245 +  /* Alignment of debugging information.  E.g., 4.  */
2246 +  4,
2247 +  /* Sizes of external symbolic information.  */
2248 +  sizeof (struct hdr_ext),
2249 +  sizeof (struct dnr_ext),
2250 +  sizeof (struct pdr_ext),
2251 +  sizeof (struct sym_ext),
2252 +  sizeof (struct opt_ext),
2253 +  sizeof (struct fdr_ext),
2254 +  sizeof (struct rfd_ext),
2255 +  sizeof (struct ext_ext),
2256 +  /* Functions to swap in external symbolic data.  */
2257 +  ecoff_swap_hdr_in,
2258 +  ecoff_swap_dnr_in,
2259 +  ecoff_swap_pdr_in,
2260 +  ecoff_swap_sym_in,
2261 +  ecoff_swap_opt_in,
2262 +  ecoff_swap_fdr_in,
2263 +  ecoff_swap_rfd_in,
2264 +  ecoff_swap_ext_in,
2265 +  _bfd_ecoff_swap_tir_in,
2266 +  _bfd_ecoff_swap_rndx_in,
2267 +  /* Functions to swap out external symbolic data.  */
2268 +  ecoff_swap_hdr_out,
2269 +  ecoff_swap_dnr_out,
2270 +  ecoff_swap_pdr_out,
2271 +  ecoff_swap_sym_out,
2272 +  ecoff_swap_opt_out,
2273 +  ecoff_swap_fdr_out,
2274 +  ecoff_swap_rfd_out,
2275 +  ecoff_swap_ext_out,
2276 +  _bfd_ecoff_swap_tir_out,
2277 +  _bfd_ecoff_swap_rndx_out,
2278 +  /* Function to read in symbolic data.  */
2279 +  _bfd_riscv_elf_read_ecoff_info
2280 +};
2281 +\f
2282 +#define ELF_ARCH                       bfd_arch_riscv
2283 +#define ELF_TARGET_ID                  MIPS_ELF_DATA
2284 +#define ELF_MACHINE_CODE               EM_RISCV
2285 +
2286 +#define elf_backend_collect            TRUE
2287 +#define elf_backend_type_change_ok     TRUE
2288 +#define elf_backend_can_gc_sections    TRUE
2289 +#define elf_info_to_howto              mips_info_to_howto_rela
2290 +#define elf_info_to_howto_rel          mips_info_to_howto_rel
2291 +#define elf_backend_sym_is_global      mips_elf_sym_is_global
2292 +#define elf_backend_object_p           mips_elf_n32_object_p
2293 +#define elf_backend_symbol_processing  _bfd_riscv_elf_symbol_processing
2294 +#define elf_backend_section_processing _bfd_riscv_elf_section_processing
2295 +#define elf_backend_section_from_shdr  _bfd_riscv_elf_section_from_shdr
2296 +#define elf_backend_fake_sections      _bfd_riscv_elf_fake_sections
2297 +#define elf_backend_section_from_bfd_section \
2298 +                                       _bfd_riscv_elf_section_from_bfd_section
2299 +#define elf_backend_add_symbol_hook    _bfd_riscv_elf_add_symbol_hook
2300 +#define elf_backend_link_output_symbol_hook \
2301 +                                       _bfd_riscv_elf_link_output_symbol_hook
2302 +#define elf_backend_create_dynamic_sections \
2303 +                                       _bfd_riscv_elf_create_dynamic_sections
2304 +#define elf_backend_check_relocs       _bfd_riscv_elf_check_relocs
2305 +#define elf_backend_merge_symbol_attribute \
2306 +                                       _bfd_riscv_elf_merge_symbol_attribute
2307 +#define elf_backend_get_target_dtag    _bfd_riscv_elf_get_target_dtag
2308 +#define elf_backend_adjust_dynamic_symbol \
2309 +                                       _bfd_riscv_elf_adjust_dynamic_symbol
2310 +#define elf_backend_always_size_sections \
2311 +                                       _bfd_riscv_elf_always_size_sections
2312 +#define elf_backend_size_dynamic_sections \
2313 +                                       _bfd_riscv_elf_size_dynamic_sections
2314 +#define elf_backend_init_index_section _bfd_elf_init_1_index_section
2315 +#define elf_backend_relocate_section   _bfd_riscv_elf_relocate_section
2316 +#define elf_backend_finish_dynamic_symbol \
2317 +                                       _bfd_riscv_elf_finish_dynamic_symbol
2318 +#define elf_backend_finish_dynamic_sections \
2319 +                                       _bfd_riscv_elf_finish_dynamic_sections
2320 +#define elf_backend_final_write_processing \
2321 +                                       _bfd_riscv_elf_final_write_processing
2322 +#define elf_backend_additional_program_headers \
2323 +                                       _bfd_riscv_elf_additional_program_headers
2324 +#define elf_backend_modify_segment_map _bfd_riscv_elf_modify_segment_map
2325 +#define elf_backend_gc_mark_hook       _bfd_riscv_elf_gc_mark_hook
2326 +#define elf_backend_gc_sweep_hook      _bfd_riscv_elf_gc_sweep_hook
2327 +#define elf_backend_copy_indirect_symbol \
2328 +                                       _bfd_riscv_elf_copy_indirect_symbol
2329 +#define elf_backend_grok_prstatus      elf32_mips_grok_prstatus
2330 +#define elf_backend_grok_psinfo                elf32_mips_grok_psinfo
2331 +#define elf_backend_ecoff_debug_swap   &mips_elf32_ecoff_debug_swap
2332 +
2333 +#define elf_backend_got_header_size    (4 * MIPS_RESERVED_GOTNO)
2334 +
2335 +/* MIPS n32 ELF can use a mixture of REL and RELA, but some Relocations
2336 +   work better/work only in RELA, so we default to this.  */
2337 +#define elf_backend_may_use_rel_p      1
2338 +#define elf_backend_may_use_rela_p     1
2339 +#define elf_backend_default_use_rela_p 1
2340 +#define elf_backend_rela_plts_and_copies_p 0
2341 +#define elf_backend_sign_extend_vma    TRUE
2342 +#define elf_backend_plt_readonly       1
2343 +#define elf_backend_plt_sym_val                _bfd_riscv_elf_plt_sym_val
2344 +
2345 +#define elf_backend_discard_info       _bfd_riscv_elf_discard_info
2346 +#define elf_backend_ignore_discarded_relocs \
2347 +                                       _bfd_riscv_elf_ignore_discarded_relocs
2348 +#define elf_backend_write_section      _bfd_riscv_elf_write_section
2349 +#define elf_backend_mips_rtype_to_howto        mips_elf_n32_rtype_to_howto
2350 +#define bfd_elf32_find_nearest_line    _bfd_riscv_elf_find_nearest_line
2351 +#define bfd_elf32_find_inliner_info    _bfd_riscv_elf_find_inliner_info
2352 +#define bfd_elf32_new_section_hook     _bfd_riscv_elf_new_section_hook
2353 +#define bfd_elf32_set_section_contents _bfd_riscv_elf_set_section_contents
2354 +#define bfd_elf32_bfd_get_relocated_section_contents \
2355 +                               _bfd_elf_riscv_get_relocated_section_contents
2356 +#define bfd_elf32_bfd_link_hash_table_create \
2357 +                                       _bfd_riscv_elf_link_hash_table_create
2358 +#define bfd_elf32_bfd_final_link       _bfd_riscv_elf_final_link
2359 +#define bfd_elf32_bfd_merge_private_bfd_data \
2360 +                                       _bfd_riscv_elf_merge_private_bfd_data
2361 +#define bfd_elf32_bfd_set_private_flags        _bfd_riscv_elf_set_private_flags
2362 +#define bfd_elf32_bfd_print_private_bfd_data \
2363 +                                       _bfd_riscv_elf_print_private_bfd_data
2364 +#define bfd_elf32_bfd_relax_section     _bfd_riscv_relax_section
2365 +
2366 +/* Support for SGI-ish mips targets using n32 ABI.  */
2367 +
2368 +#define TARGET_LITTLE_SYM               bfd_elf32_littleriscv_vec
2369 +#define TARGET_LITTLE_NAME              "elf32-littleriscv"
2370 +#define TARGET_BIG_SYM                  bfd_elf32_bigriscv_vec
2371 +#define TARGET_BIG_NAME                 "elf32-bigriscv"
2372 +
2373 +#define ELF_MAXPAGESIZE                        0x10000
2374 +#define ELF_COMMONPAGESIZE             0x1000
2375 +
2376 +#include "elf32-target.h"
2377 diff --git a/binutils-2.21.1/bfd/elf64-riscv.c b/binutils-2.21.1/bfd/elf64-riscv.c
2378 new file mode 100644
2379 index 0000000..c9c5d1a
2380 --- /dev/null
2381 +++ binutils-2.21.1/bfd/elf64-riscv.c
2382 @@ -0,0 +1,2999 @@
2383 +/* MIPS-specific support for 64-bit ELF
2384 +   Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2385 +   2006, 2007, 2008, 2009, 2010
2386 +   Free Software Foundation, Inc.
2387 +   Ian Lance Taylor, Cygnus Support
2388 +   Linker support added by Mark Mitchell, CodeSourcery, LLC.
2389 +   <mark@codesourcery.com>
2390 +
2391 +   This file is part of BFD, the Binary File Descriptor library.
2392 +
2393 +   This program is free software; you can redistribute it and/or modify
2394 +   it under the terms of the GNU General Public License as published by
2395 +   the Free Software Foundation; either version 3 of the License, or
2396 +   (at your option) any later version.
2397 +
2398 +   This program is distributed in the hope that it will be useful,
2399 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
2400 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2401 +   GNU General Public License for more details.
2402 +
2403 +   You should have received a copy of the GNU General Public License
2404 +   along with this program; if not, write to the Free Software
2405 +   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
2406 +   MA 02110-1301, USA.  */
2407 +
2408 +
2409 +/* This file supports the 64-bit MIPS ELF ABI.
2410 +
2411 +   The MIPS 64-bit ELF ABI uses an unusual reloc format.  This file
2412 +   overrides the usual ELF reloc handling, and handles reading and
2413 +   writing the relocations here.  */
2414 +
2415 +/* TODO: Many things are unsupported, even if there is some code for it
2416 + .       (which was mostly stolen from elf32-mips.c and slightly adapted).
2417 + .
2418 + .   - Relocation handling for REL relocs is wrong in many cases and
2419 + .     generally untested.
2420 + .   - Relocation handling for RELA relocs related to GOT support are
2421 + .     also likely to be wrong.
2422 + .   - Support for MIPS16 is untested.
2423 + .   - Combined relocs with RSS_* entries are unsupported.
2424 + .   - The whole GOT handling for NewABI is missing, some parts of
2425 + .     the OldABI version is still lying around and should be removed.
2426 + */
2427 +
2428 +#include "sysdep.h"
2429 +#include "bfd.h"
2430 +#include "libbfd.h"
2431 +#include "aout/ar.h"
2432 +#include "bfdlink.h"
2433 +#include "genlink.h"
2434 +#include "elf-bfd.h"
2435 +#include "elfxx-riscv.h"
2436 +#include "elf/riscv.h"
2437 +#include "opcode/riscv.h"
2438 +
2439 +/* Get the ECOFF swapping routines.  The 64-bit ABI is not supposed to
2440 +   use ECOFF.  However, we support it anyhow for an easier changeover.  */
2441 +#include "coff/sym.h"
2442 +#include "coff/symconst.h"
2443 +#include "coff/internal.h"
2444 +#include "coff/ecoff.h"
2445 +/* The 64 bit versions of the mdebug data structures are in alpha.h.  */
2446 +#include "coff/alpha.h"
2447 +#define ECOFF_SIGNED_64
2448 +#include "ecoffswap.h"
2449 +
2450 +#include "opcode/riscv.h"
2451 +
2452 +static void mips_elf64_swap_reloc_in
2453 +  (bfd *, const Elf64_Mips_External_Rel *, Elf64_Mips_Internal_Rela *);
2454 +static void mips_elf64_swap_reloca_in
2455 +  (bfd *, const Elf64_Mips_External_Rela *, Elf64_Mips_Internal_Rela *);
2456 +static void mips_elf64_swap_reloc_out
2457 +  (bfd *, const Elf64_Mips_Internal_Rela *, Elf64_Mips_External_Rel *);
2458 +static void mips_elf64_swap_reloca_out
2459 +  (bfd *, const Elf64_Mips_Internal_Rela *, Elf64_Mips_External_Rela *);
2460 +static void mips_elf64_be_swap_reloc_in
2461 +  (bfd *, const bfd_byte *, Elf_Internal_Rela *);
2462 +static void mips_elf64_be_swap_reloc_out
2463 +  (bfd *, const Elf_Internal_Rela *, bfd_byte *);
2464 +static void mips_elf64_be_swap_reloca_in
2465 +  (bfd *, const bfd_byte *, Elf_Internal_Rela *);
2466 +static void mips_elf64_be_swap_reloca_out
2467 +  (bfd *, const Elf_Internal_Rela *, bfd_byte *);
2468 +static reloc_howto_type *bfd_elf64_bfd_reloc_type_lookup
2469 +  (bfd *, bfd_reloc_code_real_type);
2470 +static reloc_howto_type *mips_elf64_rtype_to_howto
2471 +  (unsigned int, bfd_boolean);
2472 +static void mips_elf64_info_to_howto_rel
2473 +  (bfd *, arelent *, Elf_Internal_Rela *);
2474 +static void mips_elf64_info_to_howto_rela
2475 +  (bfd *, arelent *, Elf_Internal_Rela *);
2476 +static long mips_elf64_get_reloc_upper_bound
2477 +  (bfd *, asection *);
2478 +static long mips_elf64_canonicalize_reloc
2479 +  (bfd *, asection *, arelent **, asymbol **);
2480 +static long mips_elf64_get_dynamic_reloc_upper_bound
2481 +  (bfd *);
2482 +static long mips_elf64_canonicalize_dynamic_reloc
2483 +  (bfd *, arelent **, asymbol **);
2484 +static bfd_boolean mips_elf64_slurp_one_reloc_table
2485 +  (bfd *, asection *, Elf_Internal_Shdr *, bfd_size_type, arelent *,
2486 +   asymbol **, bfd_boolean);
2487 +static bfd_boolean mips_elf64_slurp_reloc_table
2488 +  (bfd *, asection *, asymbol **, bfd_boolean);
2489 +static void mips_elf64_write_relocs
2490 +  (bfd *, asection *, void *);
2491 +static void mips_elf64_write_rel
2492 +  (bfd *, asection *, Elf_Internal_Shdr *, int *, void *);
2493 +static void mips_elf64_write_rela
2494 +  (bfd *, asection *, Elf_Internal_Shdr *, int *, void *);
2495 +static bfd_reloc_status_type mips_elf64_gprel16_reloc
2496 +  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
2497 +static bfd_reloc_status_type mips_elf64_literal_reloc
2498 +  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
2499 +static bfd_reloc_status_type mips_elf64_gprel32_reloc
2500 +  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
2501 +static bfd_boolean mips_elf64_assign_gp
2502 +  (bfd *, bfd_vma *);
2503 +static bfd_reloc_status_type mips_elf64_final_gp
2504 +  (bfd *, asymbol *, bfd_boolean, char **, bfd_vma *);
2505 +static bfd_boolean mips_elf64_object_p
2506 +  (bfd *);
2507 +static bfd_boolean elf64_mips_grok_prstatus
2508 +  (bfd *, Elf_Internal_Note *);
2509 +static bfd_boolean elf64_mips_grok_psinfo
2510 +  (bfd *, Elf_Internal_Note *);
2511 +
2512 +/* In case we're on a 32-bit machine, construct a 64-bit "-1" value
2513 +   from smaller values.  Start with zero, widen, *then* decrement.  */
2514 +#define MINUS_ONE      (((bfd_vma)0) - 1)
2515 +
2516 +/* The number of local .got entries we reserve.  */
2517 +#define MIPS_RESERVED_GOTNO (2)
2518 +\f
2519 +/* The relocation table used for SHT_REL sections.  */
2520 +
2521 +static reloc_howto_type mips_elf64_howto_table_rel[] =
2522 +{
2523 +  /* No relocation.  */
2524 +  HOWTO (R_RISCV_NONE,         /* type */
2525 +        0,                     /* rightshift */
2526 +        0,                     /* size (0 = byte, 1 = short, 2 = long) */
2527 +        0,                     /* bitsize */
2528 +        FALSE,                 /* pc_relative */
2529 +        0,                     /* bitpos */
2530 +        complain_overflow_dont, /* complain_on_overflow */
2531 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
2532 +        "R_RISCV_NONE",                /* name */
2533 +        FALSE,                 /* partial_inplace */
2534 +        0,                     /* src_mask */
2535 +        0,                     /* dst_mask */
2536 +        FALSE),                /* pcrel_offset */
2537 +
2538 +  EMPTY_HOWTO (1),
2539 +
2540 +  /* 32 bit relocation.  */
2541 +  HOWTO (R_RISCV_32,           /* type */
2542 +        0,                     /* rightshift */
2543 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
2544 +        32,                    /* bitsize */
2545 +        FALSE,                 /* pc_relative */
2546 +        0,                     /* bitpos */
2547 +        complain_overflow_dont, /* complain_on_overflow */
2548 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
2549 +        "R_RISCV_32",          /* name */
2550 +        TRUE,                  /* partial_inplace */
2551 +        0xffffffff,            /* src_mask */
2552 +        0xffffffff,            /* dst_mask */
2553 +        FALSE),                /* pcrel_offset */
2554 +
2555 +  /* 32 bit symbol relative relocation.  */
2556 +  HOWTO (R_RISCV_REL32,                /* type */
2557 +        0,                     /* rightshift */
2558 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
2559 +        32,                    /* bitsize */
2560 +        FALSE,                 /* pc_relative */
2561 +        0,                     /* bitpos */
2562 +        complain_overflow_dont, /* complain_on_overflow */
2563 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
2564 +        "R_RISCV_REL32",       /* name */
2565 +        TRUE,                  /* partial_inplace */
2566 +        0xffffffff,            /* src_mask */
2567 +        0xffffffff,            /* dst_mask */
2568 +        FALSE),                /* pcrel_offset */
2569 +
2570 +  /* 26 bit jump address.  */
2571 +  HOWTO (R_RISCV_26,           /* type */
2572 +        RISCV_JUMP_ALIGN_BITS,                 /* rightshift */
2573 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
2574 +        RISCV_JUMP_BITS,                       /* bitsize */
2575 +        TRUE,                  /* pc_relative */
2576 +        OP_SH_TARGET,                  /* bitpos */
2577 +        complain_overflow_dont, /* complain_on_overflow */
2578 +                               /* This needs complex overflow
2579 +                                  detection, because the upper 36
2580 +                                  bits must match the PC + 4.  */
2581 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
2582 +        "R_RISCV_26",          /* name */
2583 +        TRUE,                  /* partial_inplace */
2584 +        ((1<<RISCV_JUMP_BITS)-1) << OP_SH_TARGET,              /* src_mask */
2585 +        ((1<<RISCV_JUMP_BITS)-1) << OP_SH_TARGET,              /* dst_mask */
2586 +        TRUE),         /* pcrel_offset */
2587 +
2588 +  /* R_RISCV_HI16 and R_RISCV_LO16 are unsupported for NewABI REL.
2589 +     However, the native IRIX6 tools use them, so we try our best. */
2590 +
2591 +  /* High 16 bits of symbol value.  */
2592 +  HOWTO (R_RISCV_HI16,         /* type */
2593 +        RISCV_IMM_BITS,                        /* rightshift */
2594 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
2595 +        RISCV_BIGIMM_BITS,                     /* bitsize */
2596 +        FALSE,                 /* pc_relative */
2597 +        OP_SH_BIGIMMEDIATE,                    /* bitpos */
2598 +        complain_overflow_dont, /* complain_on_overflow */
2599 +        _bfd_riscv_elf_hi16_reloc, /* special_function */
2600 +        "R_RISCV_HI16",                /* name */
2601 +        TRUE,                  /* partial_inplace */
2602 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,              /* src_mask */
2603 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,              /* dst_mask */
2604 +        FALSE),                /* pcrel_offset */
2605 +
2606 +  /* Low 16 bits of symbol value.  */
2607 +  HOWTO (R_RISCV_LO16,         /* type */
2608 +        0,                     /* rightshift */
2609 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
2610 +        RISCV_IMM_BITS,                        /* bitsize */
2611 +        FALSE,                 /* pc_relative */
2612 +        OP_SH_IMMEDIATE,                       /* bitpos */
2613 +        complain_overflow_dont, /* complain_on_overflow */
2614 +        _bfd_riscv_elf_lo16_reloc, /* special_function */
2615 +        "R_RISCV_LO16",                /* name */
2616 +        TRUE,                  /* partial_inplace */
2617 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,                /* src_mask */
2618 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,                /* dst_mask */
2619 +        FALSE),                /* pcrel_offset */
2620 +
2621 +  /* GP relative reference.  */
2622 +  HOWTO (R_RISCV_GPREL16,      /* type */
2623 +        0,                     /* rightshift */
2624 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
2625 +        RISCV_IMM_BITS,                        /* bitsize */
2626 +        FALSE,                 /* pc_relative */
2627 +        OP_SH_IMMEDIATE,       /* bitpos */
2628 +        complain_overflow_signed, /* complain_on_overflow */
2629 +        mips_elf64_gprel16_reloc, /* special_function */
2630 +        "R_RISCV_GPREL16",     /* name */
2631 +        TRUE,                  /* partial_inplace */
2632 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
2633 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
2634 +        FALSE),                /* pcrel_offset */
2635 +
2636 +  /* Reference to literal section.  */
2637 +  HOWTO (R_RISCV_LITERAL,      /* type */
2638 +        0,                     /* rightshift */
2639 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
2640 +        RISCV_IMM_BITS,                        /* bitsize */
2641 +        FALSE,                 /* pc_relative */
2642 +        OP_SH_IMMEDIATE,       /* bitpos */
2643 +        complain_overflow_signed, /* complain_on_overflow */
2644 +        mips_elf64_literal_reloc, /* special_function */
2645 +        "R_RISCV_LITERAL",     /* name */
2646 +        TRUE,                  /* partial_inplace */
2647 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
2648 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
2649 +        FALSE),                /* pcrel_offset */
2650 +
2651 +  /* Reference to global offset table.  */
2652 +  HOWTO (R_RISCV_GOT16,                /* type */
2653 +        0,                     /* rightshift */
2654 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
2655 +        RISCV_IMM_BITS,        /* bitsize */
2656 +        FALSE,                 /* pc_relative */
2657 +        OP_SH_IMMEDIATE,       /* bitpos */
2658 +        complain_overflow_signed, /* complain_on_overflow */
2659 +        _bfd_riscv_elf_got16_reloc, /* special_function */
2660 +        "R_RISCV_GOT16",       /* name */
2661 +        TRUE,                  /* partial_inplace */
2662 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,                /* src_mask */
2663 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,                /* dst_mask */
2664 +        FALSE),                /* pcrel_offset */
2665 +
2666 +  /* 16 bit PC relative reference.  Note that the ABI document has a typo
2667 +     and claims R_RISCV_PC16 to be not rightshifted, rendering it useless.
2668 +     We do the right thing here.  */
2669 +  HOWTO (R_RISCV_PC16,         /* type */
2670 +        RISCV_BRANCH_ALIGN_BITS,                       /* rightshift */
2671 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
2672 +        RISCV_IMM_BITS,                        /* bitsize */
2673 +        TRUE,                  /* pc_relative */
2674 +        OP_SH_IMMEDIATE,       /* bitpos */
2675 +        complain_overflow_signed, /* complain_on_overflow */
2676 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
2677 +        "R_RISCV_PC16",                /* name */
2678 +        TRUE,                  /* partial_inplace */
2679 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
2680 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
2681 +        TRUE),                 /* pcrel_offset */
2682 +
2683 +  /* 16 bit call through global offset table.  */
2684 +  HOWTO (R_RISCV_CALL16,               /* type */
2685 +        0,                     /* rightshift */
2686 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
2687 +        RISCV_IMM_BITS,                        /* bitsize */
2688 +        FALSE,                 /* pc_relative */
2689 +        OP_SH_IMMEDIATE,       /* bitpos */
2690 +        complain_overflow_signed, /* complain_on_overflow */
2691 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
2692 +        "R_RISCV_CALL16",      /* name */
2693 +        TRUE,                  /* partial_inplace */
2694 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* src_mask */
2695 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,        /* dst_mask */
2696 +        FALSE),                /* pcrel_offset */
2697 +
2698 +  /* 32 bit GP relative reference.  */
2699 +  HOWTO (R_RISCV_GPREL32,      /* type */
2700 +        0,                     /* rightshift */
2701 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
2702 +        32,                    /* bitsize */
2703 +        FALSE,                 /* pc_relative */
2704 +        0,                     /* bitpos */
2705 +        complain_overflow_dont, /* complain_on_overflow */
2706 +        mips_elf64_gprel32_reloc, /* special_function */
2707 +        "R_RISCV_GPREL32",     /* name */
2708 +        TRUE,                  /* partial_inplace */
2709 +        0xffffffff,            /* src_mask */
2710 +        0xffffffff,            /* dst_mask */
2711 +        FALSE),                /* pcrel_offset */
2712 +
2713 +  EMPTY_HOWTO (13),
2714 +  EMPTY_HOWTO (14),
2715 +  EMPTY_HOWTO (15),
2716 +  EMPTY_HOWTO (16),
2717 +  EMPTY_HOWTO (17),
2718 +
2719 +  /* 64 bit relocation.  */
2720 +  HOWTO (R_RISCV_64,           /* type */
2721 +        0,                     /* rightshift */
2722 +        4,                     /* size (0 = byte, 1 = short, 2 = long) */
2723 +        64,                    /* bitsize */
2724 +        FALSE,                 /* pc_relative */
2725 +        0,                     /* bitpos */
2726 +        complain_overflow_dont, /* complain_on_overflow */
2727 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
2728 +        "R_RISCV_64",          /* name */
2729 +        TRUE,                  /* partial_inplace */
2730 +        MINUS_ONE,             /* src_mask */
2731 +        MINUS_ONE,             /* dst_mask */
2732 +        FALSE),                /* pcrel_offset */
2733 +
2734 +  /* Displacement in the global offset table.  */
2735 +  HOWTO (R_RISCV_GOT_DISP,     /* type */
2736 +        0,                     /* rightshift */
2737 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
2738 +        RISCV_IMM_BITS,                        /* bitsize */
2739 +        FALSE,                 /* pc_relative */
2740 +        OP_SH_IMMEDIATE,                       /* bitpos */
2741 +        complain_overflow_signed, /* complain_on_overflow */
2742 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
2743 +        "R_RISCV_GOT_DISP",    /* name */
2744 +        TRUE,                  /* partial_inplace */
2745 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,                /* src_mask */
2746 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,                /* dst_mask */
2747 +        FALSE),                /* pcrel_offset */
2748 +
2749 +  EMPTY_HOWTO (20),
2750 +  EMPTY_HOWTO (21),
2751 +
2752 +  /* High 16 bits of displacement in global offset table.  */
2753 +  HOWTO (R_RISCV_GOT_HI16,     /* type */
2754 +        0,                     /* rightshift */
2755 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
2756 +        RISCV_BIGIMM_BITS,     /* bitsize */
2757 +        TRUE,                  /* pc_relative */
2758 +        OP_SH_BIGIMMEDIATE,    /* bitpos */
2759 +        complain_overflow_dont, /* complain_on_overflow */
2760 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
2761 +        "R_RISCV_GOT_HI16",    /* name */
2762 +        TRUE,                  /* partial_inplace */
2763 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,              /* src_mask */
2764 +        ((1<<RISCV_BIGIMM_BITS)-1) << OP_SH_BIGIMMEDIATE,              /* dst_mask */
2765 +        FALSE),                /* pcrel_offset */
2766 +
2767 +  /* Low 16 bits of displacement in global offset table.  */
2768 +  HOWTO (R_RISCV_GOT_LO16,     /* type */
2769 +        0,                     /* rightshift */
2770 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
2771 +        RISCV_IMM_BITS,                        /* bitsize */
2772 +        TRUE,                  /* pc_relative */
2773 +        OP_SH_IMMEDIATE,       /* bitpos */
2774 +        complain_overflow_dont, /* complain_on_overflow */
2775 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
2776 +        "R_RISCV_GOT_LO16",    /* name */
2777 +        TRUE,                  /* partial_inplace */
2778 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,                /* src_mask */
2779 +        (RISCV_IMM_REACH-1) << OP_SH_IMMEDIATE,                /* dst_mask */
2780 +        FALSE),                /* pcrel_offset */
2781 +
2782 +  /* 64 bit subtraction.  */
2783 +  HOWTO (R_RISCV_SUB,          /* type */
2784 +        0,                     /* rightshift */
2785 +        4,                     /* size (0 = byte, 1 = short, 2 = long) */
2786 +        64,                    /* bitsize */
2787 +        FALSE,                 /* pc_relative */
2788 +        0,                     /* bitpos */
2789 +        complain_overflow_dont, /* complain_on_overflow */
2790 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
2791 +        "R_RISCV_SUB",         /* name */
2792 +        TRUE,                  /* partial_inplace */
2793 +        MINUS_ONE,             /* src_mask */
2794 +        MINUS_ONE,             /* dst_mask */
2795 +        FALSE),                /* pcrel_offset */
2796 +
2797 +  /* Insert the addend as an instruction.  */
2798 +  /* FIXME: Not handled correctly.  */
2799 +  HOWTO (R_RISCV_INSERT_A,     /* type */
2800 +        0,                     /* rightshift */
2801 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
2802 +        32,                    /* bitsize */
2803 +        FALSE,                 /* pc_relative */
2804 +        0,                     /* bitpos */
2805 +        complain_overflow_dont, /* complain_on_overflow */
2806 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
2807 +        "R_RISCV_INSERT_A",    /* name */
2808 +        TRUE,                  /* partial_inplace */
2809 +        0xffffffff,            /* src_mask */
2810 +        0xffffffff,            /* dst_mask */
2811 +        FALSE),                /* pcrel_offset */
2812 +
2813 +  /* Insert the addend as an instruction, and change all relocations
2814 +     to refer to the old instruction at the address.  */
2815 +  /* FIXME: Not handled correctly.  */
2816 +  HOWTO (R_RISCV_INSERT_B,     /* type */
2817 +        0,                     /* rightshift */
2818 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
2819 +        32,                    /* bitsize */
2820 +        FALSE,                 /* pc_relative */
2821 +        0,                     /* bitpos */
2822 +        complain_overflow_dont, /* complain_on_overflow */
2823 +        _bfd_riscv_elf_generic_reloc,  /* special_function */
2824 +        "R_RISCV_INSERT_B",    /* name */
2825 +        TRUE,                  /* partial_inplace */
2826 +        0xffffffff,            /* src_mask */
2827 +        0xffffffff,            /* dst_mask */
2828 +        FALSE),                /* pcrel_offset */
2829 +
2830 +  /* Delete a 32 bit instruction.  */
2831 +  /* FIXME: Not handled correctly.  */
2832 +  HOWTO (R_RISCV_DELETE,               /* type */
2833 +        0,                     /* rightshift */
2834 +        2,                     /* size (0 = byte, 1 = short, 2 = long) */
2835 +        32,                    /* bitsize */
2836 +        FALSE,                 /* pc_relative */
2837 +        0,                     /* bitpos */
2838 +        complain_overflow_dont, /* complain_on_overflow */
2839 +        _bfd_riscv_elf_generic_reloc,  /* special_function */