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