]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - bfd/elf64-mips.c
Update copyright years
[thirdparty/binutils-gdb.git] / bfd / elf64-mips.c
1 /* MIPS-specific support for 64-bit ELF
2 Copyright (C) 1996-2014 Free Software Foundation, Inc.
3 Ian Lance Taylor, Cygnus Support
4 Linker support added by Mark Mitchell, CodeSourcery, LLC.
5 <mark@codesourcery.com>
6
7 This file is part of BFD, the Binary File Descriptor library.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
23
24
25 /* This file supports the 64-bit MIPS ELF ABI.
26
27 The MIPS 64-bit ELF ABI uses an unusual reloc format. This file
28 overrides the usual ELF reloc handling, and handles reading and
29 writing the relocations here. */
30
31 /* TODO: Many things are unsupported, even if there is some code for it
32 . (which was mostly stolen from elf32-mips.c and slightly adapted).
33 .
34 . - Relocation handling for REL relocs is wrong in many cases and
35 . generally untested.
36 . - Relocation handling for RELA relocs related to GOT support are
37 . also likely to be wrong.
38 . - Support for MIPS16 is untested.
39 . - Combined relocs with RSS_* entries are unsupported.
40 . - The whole GOT handling for NewABI is missing, some parts of
41 . the OldABI version is still lying around and should be removed.
42 */
43
44 #include "sysdep.h"
45 #include "bfd.h"
46 #include "libbfd.h"
47 #include "aout/ar.h"
48 #include "bfdlink.h"
49 #include "genlink.h"
50 #include "elf-bfd.h"
51 #include "elfxx-mips.h"
52 #include "elf/mips.h"
53
54 /* Get the ECOFF swapping routines. The 64-bit ABI is not supposed to
55 use ECOFF. However, we support it anyhow for an easier changeover. */
56 #include "coff/sym.h"
57 #include "coff/symconst.h"
58 #include "coff/internal.h"
59 #include "coff/ecoff.h"
60 /* The 64 bit versions of the mdebug data structures are in alpha.h. */
61 #include "coff/alpha.h"
62 #define ECOFF_SIGNED_64
63 #include "ecoffswap.h"
64
65 static void mips_elf64_swap_reloc_in
66 (bfd *, const Elf64_Mips_External_Rel *, Elf64_Mips_Internal_Rela *);
67 static void mips_elf64_swap_reloca_in
68 (bfd *, const Elf64_Mips_External_Rela *, Elf64_Mips_Internal_Rela *);
69 static void mips_elf64_swap_reloc_out
70 (bfd *, const Elf64_Mips_Internal_Rela *, Elf64_Mips_External_Rel *);
71 static void mips_elf64_swap_reloca_out
72 (bfd *, const Elf64_Mips_Internal_Rela *, Elf64_Mips_External_Rela *);
73 static void mips_elf64_be_swap_reloc_in
74 (bfd *, const bfd_byte *, Elf_Internal_Rela *);
75 static void mips_elf64_be_swap_reloc_out
76 (bfd *, const Elf_Internal_Rela *, bfd_byte *);
77 static void mips_elf64_be_swap_reloca_in
78 (bfd *, const bfd_byte *, Elf_Internal_Rela *);
79 static void mips_elf64_be_swap_reloca_out
80 (bfd *, const Elf_Internal_Rela *, bfd_byte *);
81 static reloc_howto_type *bfd_elf64_bfd_reloc_type_lookup
82 (bfd *, bfd_reloc_code_real_type);
83 static reloc_howto_type *mips_elf64_rtype_to_howto
84 (unsigned int, bfd_boolean);
85 static void mips_elf64_info_to_howto_rel
86 (bfd *, arelent *, Elf_Internal_Rela *);
87 static void mips_elf64_info_to_howto_rela
88 (bfd *, arelent *, Elf_Internal_Rela *);
89 static long mips_elf64_get_reloc_upper_bound
90 (bfd *, asection *);
91 static long mips_elf64_canonicalize_reloc
92 (bfd *, asection *, arelent **, asymbol **);
93 static long mips_elf64_get_dynamic_reloc_upper_bound
94 (bfd *);
95 static long mips_elf64_canonicalize_dynamic_reloc
96 (bfd *, arelent **, asymbol **);
97 static bfd_boolean mips_elf64_slurp_one_reloc_table
98 (bfd *, asection *, Elf_Internal_Shdr *, bfd_size_type, arelent *,
99 asymbol **, bfd_boolean);
100 static bfd_boolean mips_elf64_slurp_reloc_table
101 (bfd *, asection *, asymbol **, bfd_boolean);
102 static void mips_elf64_write_relocs
103 (bfd *, asection *, void *);
104 static void mips_elf64_write_rel
105 (bfd *, asection *, Elf_Internal_Shdr *, int *, void *);
106 static void mips_elf64_write_rela
107 (bfd *, asection *, Elf_Internal_Shdr *, int *, void *);
108 static bfd_reloc_status_type mips_elf64_gprel16_reloc
109 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
110 static bfd_reloc_status_type mips_elf64_literal_reloc
111 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
112 static bfd_reloc_status_type mips_elf64_gprel32_reloc
113 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
114 static bfd_reloc_status_type mips_elf64_shift6_reloc
115 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
116 static bfd_reloc_status_type mips16_gprel_reloc
117 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
118 static bfd_boolean mips_elf64_assign_gp
119 (bfd *, bfd_vma *);
120 static bfd_reloc_status_type mips_elf64_final_gp
121 (bfd *, asymbol *, bfd_boolean, char **, bfd_vma *);
122 static bfd_boolean mips_elf64_object_p
123 (bfd *);
124 static irix_compat_t elf64_mips_irix_compat
125 (bfd *);
126 static bfd_boolean elf64_mips_grok_prstatus
127 (bfd *, Elf_Internal_Note *);
128 static bfd_boolean elf64_mips_grok_psinfo
129 (bfd *, Elf_Internal_Note *);
130
131 extern const bfd_target bfd_elf64_bigmips_vec;
132 extern const bfd_target bfd_elf64_littlemips_vec;
133
134 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
135 from smaller values. Start with zero, widen, *then* decrement. */
136 #define MINUS_ONE (((bfd_vma)0) - 1)
137
138 /* The number of local .got entries we reserve. */
139 #define MIPS_RESERVED_GOTNO (2)
140 \f
141 /* The relocation table used for SHT_REL sections. */
142
143 static reloc_howto_type mips_elf64_howto_table_rel[] =
144 {
145 /* No relocation. */
146 HOWTO (R_MIPS_NONE, /* type */
147 0, /* rightshift */
148 0, /* size (0 = byte, 1 = short, 2 = long) */
149 0, /* bitsize */
150 FALSE, /* pc_relative */
151 0, /* bitpos */
152 complain_overflow_dont, /* complain_on_overflow */
153 _bfd_mips_elf_generic_reloc, /* special_function */
154 "R_MIPS_NONE", /* name */
155 FALSE, /* partial_inplace */
156 0, /* src_mask */
157 0, /* dst_mask */
158 FALSE), /* pcrel_offset */
159
160 /* 16 bit relocation. */
161 HOWTO (R_MIPS_16, /* type */
162 0, /* rightshift */
163 2, /* size (0 = byte, 1 = short, 2 = long) */
164 16, /* bitsize */
165 FALSE, /* pc_relative */
166 0, /* bitpos */
167 complain_overflow_signed, /* complain_on_overflow */
168 _bfd_mips_elf_generic_reloc, /* special_function */
169 "R_MIPS_16", /* name */
170 TRUE, /* partial_inplace */
171 0x0000ffff, /* src_mask */
172 0x0000ffff, /* dst_mask */
173 FALSE), /* pcrel_offset */
174
175 /* 32 bit relocation. */
176 HOWTO (R_MIPS_32, /* type */
177 0, /* rightshift */
178 2, /* size (0 = byte, 1 = short, 2 = long) */
179 32, /* bitsize */
180 FALSE, /* pc_relative */
181 0, /* bitpos */
182 complain_overflow_dont, /* complain_on_overflow */
183 _bfd_mips_elf_generic_reloc, /* special_function */
184 "R_MIPS_32", /* name */
185 TRUE, /* partial_inplace */
186 0xffffffff, /* src_mask */
187 0xffffffff, /* dst_mask */
188 FALSE), /* pcrel_offset */
189
190 /* 32 bit symbol relative relocation. */
191 HOWTO (R_MIPS_REL32, /* type */
192 0, /* rightshift */
193 2, /* size (0 = byte, 1 = short, 2 = long) */
194 32, /* bitsize */
195 FALSE, /* pc_relative */
196 0, /* bitpos */
197 complain_overflow_dont, /* complain_on_overflow */
198 _bfd_mips_elf_generic_reloc, /* special_function */
199 "R_MIPS_REL32", /* name */
200 TRUE, /* partial_inplace */
201 0xffffffff, /* src_mask */
202 0xffffffff, /* dst_mask */
203 FALSE), /* pcrel_offset */
204
205 /* 26 bit jump address. */
206 HOWTO (R_MIPS_26, /* type */
207 2, /* rightshift */
208 2, /* size (0 = byte, 1 = short, 2 = long) */
209 26, /* bitsize */
210 FALSE, /* pc_relative */
211 0, /* bitpos */
212 complain_overflow_dont, /* complain_on_overflow */
213 /* This needs complex overflow
214 detection, because the upper 36
215 bits must match the PC + 4. */
216 _bfd_mips_elf_generic_reloc, /* special_function */
217 "R_MIPS_26", /* name */
218 TRUE, /* partial_inplace */
219 0x03ffffff, /* src_mask */
220 0x03ffffff, /* dst_mask */
221 FALSE), /* pcrel_offset */
222
223 /* R_MIPS_HI16 and R_MIPS_LO16 are unsupported for NewABI REL.
224 However, the native IRIX6 tools use them, so we try our best. */
225
226 /* High 16 bits of symbol value. */
227 HOWTO (R_MIPS_HI16, /* type */
228 16, /* rightshift */
229 2, /* size (0 = byte, 1 = short, 2 = long) */
230 16, /* bitsize */
231 FALSE, /* pc_relative */
232 0, /* bitpos */
233 complain_overflow_dont, /* complain_on_overflow */
234 _bfd_mips_elf_hi16_reloc, /* special_function */
235 "R_MIPS_HI16", /* name */
236 TRUE, /* partial_inplace */
237 0x0000ffff, /* src_mask */
238 0x0000ffff, /* dst_mask */
239 FALSE), /* pcrel_offset */
240
241 /* Low 16 bits of symbol value. */
242 HOWTO (R_MIPS_LO16, /* type */
243 0, /* rightshift */
244 2, /* size (0 = byte, 1 = short, 2 = long) */
245 16, /* bitsize */
246 FALSE, /* pc_relative */
247 0, /* bitpos */
248 complain_overflow_dont, /* complain_on_overflow */
249 _bfd_mips_elf_lo16_reloc, /* special_function */
250 "R_MIPS_LO16", /* name */
251 TRUE, /* partial_inplace */
252 0x0000ffff, /* src_mask */
253 0x0000ffff, /* dst_mask */
254 FALSE), /* pcrel_offset */
255
256 /* GP relative reference. */
257 HOWTO (R_MIPS_GPREL16, /* type */
258 0, /* rightshift */
259 2, /* size (0 = byte, 1 = short, 2 = long) */
260 16, /* bitsize */
261 FALSE, /* pc_relative */
262 0, /* bitpos */
263 complain_overflow_signed, /* complain_on_overflow */
264 mips_elf64_gprel16_reloc, /* special_function */
265 "R_MIPS_GPREL16", /* name */
266 TRUE, /* partial_inplace */
267 0x0000ffff, /* src_mask */
268 0x0000ffff, /* dst_mask */
269 FALSE), /* pcrel_offset */
270
271 /* Reference to literal section. */
272 HOWTO (R_MIPS_LITERAL, /* type */
273 0, /* rightshift */
274 2, /* size (0 = byte, 1 = short, 2 = long) */
275 16, /* bitsize */
276 FALSE, /* pc_relative */
277 0, /* bitpos */
278 complain_overflow_signed, /* complain_on_overflow */
279 mips_elf64_literal_reloc, /* special_function */
280 "R_MIPS_LITERAL", /* name */
281 TRUE, /* partial_inplace */
282 0x0000ffff, /* src_mask */
283 0x0000ffff, /* dst_mask */
284 FALSE), /* pcrel_offset */
285
286 /* Reference to global offset table. */
287 HOWTO (R_MIPS_GOT16, /* type */
288 0, /* rightshift */
289 2, /* size (0 = byte, 1 = short, 2 = long) */
290 16, /* bitsize */
291 FALSE, /* pc_relative */
292 0, /* bitpos */
293 complain_overflow_signed, /* complain_on_overflow */
294 _bfd_mips_elf_got16_reloc, /* special_function */
295 "R_MIPS_GOT16", /* name */
296 TRUE, /* partial_inplace */
297 0x0000ffff, /* src_mask */
298 0x0000ffff, /* dst_mask */
299 FALSE), /* pcrel_offset */
300
301 /* 16 bit PC relative reference. Note that the ABI document has a typo
302 and claims R_MIPS_PC16 to be not rightshifted, rendering it useless.
303 We do the right thing here. */
304 HOWTO (R_MIPS_PC16, /* type */
305 2, /* rightshift */
306 2, /* size (0 = byte, 1 = short, 2 = long) */
307 16, /* bitsize */
308 TRUE, /* pc_relative */
309 0, /* bitpos */
310 complain_overflow_signed, /* complain_on_overflow */
311 _bfd_mips_elf_generic_reloc, /* special_function */
312 "R_MIPS_PC16", /* name */
313 TRUE, /* partial_inplace */
314 0x0000ffff, /* src_mask */
315 0x0000ffff, /* dst_mask */
316 TRUE), /* pcrel_offset */
317
318 /* 16 bit call through global offset table. */
319 HOWTO (R_MIPS_CALL16, /* type */
320 0, /* rightshift */
321 2, /* size (0 = byte, 1 = short, 2 = long) */
322 16, /* bitsize */
323 FALSE, /* pc_relative */
324 0, /* bitpos */
325 complain_overflow_signed, /* complain_on_overflow */
326 _bfd_mips_elf_generic_reloc, /* special_function */
327 "R_MIPS_CALL16", /* name */
328 TRUE, /* partial_inplace */
329 0x0000ffff, /* src_mask */
330 0x0000ffff, /* dst_mask */
331 FALSE), /* pcrel_offset */
332
333 /* 32 bit GP relative reference. */
334 HOWTO (R_MIPS_GPREL32, /* type */
335 0, /* rightshift */
336 2, /* size (0 = byte, 1 = short, 2 = long) */
337 32, /* bitsize */
338 FALSE, /* pc_relative */
339 0, /* bitpos */
340 complain_overflow_dont, /* complain_on_overflow */
341 mips_elf64_gprel32_reloc, /* special_function */
342 "R_MIPS_GPREL32", /* name */
343 TRUE, /* partial_inplace */
344 0xffffffff, /* src_mask */
345 0xffffffff, /* dst_mask */
346 FALSE), /* pcrel_offset */
347
348 EMPTY_HOWTO (13),
349 EMPTY_HOWTO (14),
350 EMPTY_HOWTO (15),
351
352 /* A 5 bit shift field. */
353 HOWTO (R_MIPS_SHIFT5, /* type */
354 0, /* rightshift */
355 2, /* size (0 = byte, 1 = short, 2 = long) */
356 5, /* bitsize */
357 FALSE, /* pc_relative */
358 6, /* bitpos */
359 complain_overflow_bitfield, /* complain_on_overflow */
360 _bfd_mips_elf_generic_reloc, /* special_function */
361 "R_MIPS_SHIFT5", /* name */
362 TRUE, /* partial_inplace */
363 0x000007c0, /* src_mask */
364 0x000007c0, /* dst_mask */
365 FALSE), /* pcrel_offset */
366
367 /* A 6 bit shift field. */
368 HOWTO (R_MIPS_SHIFT6, /* type */
369 0, /* rightshift */
370 2, /* size (0 = byte, 1 = short, 2 = long) */
371 6, /* bitsize */
372 FALSE, /* pc_relative */
373 6, /* bitpos */
374 complain_overflow_bitfield, /* complain_on_overflow */
375 mips_elf64_shift6_reloc, /* special_function */
376 "R_MIPS_SHIFT6", /* name */
377 TRUE, /* partial_inplace */
378 0x000007c4, /* src_mask */
379 0x000007c4, /* dst_mask */
380 FALSE), /* pcrel_offset */
381
382 /* 64 bit relocation. */
383 HOWTO (R_MIPS_64, /* type */
384 0, /* rightshift */
385 4, /* size (0 = byte, 1 = short, 2 = long) */
386 64, /* bitsize */
387 FALSE, /* pc_relative */
388 0, /* bitpos */
389 complain_overflow_dont, /* complain_on_overflow */
390 _bfd_mips_elf_generic_reloc, /* special_function */
391 "R_MIPS_64", /* name */
392 TRUE, /* partial_inplace */
393 MINUS_ONE, /* src_mask */
394 MINUS_ONE, /* dst_mask */
395 FALSE), /* pcrel_offset */
396
397 /* Displacement in the global offset table. */
398 HOWTO (R_MIPS_GOT_DISP, /* type */
399 0, /* rightshift */
400 2, /* size (0 = byte, 1 = short, 2 = long) */
401 16, /* bitsize */
402 FALSE, /* pc_relative */
403 0, /* bitpos */
404 complain_overflow_signed, /* complain_on_overflow */
405 _bfd_mips_elf_generic_reloc, /* special_function */
406 "R_MIPS_GOT_DISP", /* name */
407 TRUE, /* partial_inplace */
408 0x0000ffff, /* src_mask */
409 0x0000ffff, /* dst_mask */
410 FALSE), /* pcrel_offset */
411
412 /* Displacement to page pointer in the global offset table. */
413 HOWTO (R_MIPS_GOT_PAGE, /* type */
414 0, /* rightshift */
415 2, /* size (0 = byte, 1 = short, 2 = long) */
416 16, /* bitsize */
417 FALSE, /* pc_relative */
418 0, /* bitpos */
419 complain_overflow_signed, /* complain_on_overflow */
420 _bfd_mips_elf_generic_reloc, /* special_function */
421 "R_MIPS_GOT_PAGE", /* name */
422 TRUE, /* partial_inplace */
423 0x0000ffff, /* src_mask */
424 0x0000ffff, /* dst_mask */
425 FALSE), /* pcrel_offset */
426
427 /* Offset from page pointer in the global offset table. */
428 HOWTO (R_MIPS_GOT_OFST, /* type */
429 0, /* rightshift */
430 2, /* size (0 = byte, 1 = short, 2 = long) */
431 16, /* bitsize */
432 FALSE, /* pc_relative */
433 0, /* bitpos */
434 complain_overflow_signed, /* complain_on_overflow */
435 _bfd_mips_elf_generic_reloc, /* special_function */
436 "R_MIPS_GOT_OFST", /* name */
437 TRUE, /* partial_inplace */
438 0x0000ffff, /* src_mask */
439 0x0000ffff, /* dst_mask */
440 FALSE), /* pcrel_offset */
441
442 /* High 16 bits of displacement in global offset table. */
443 HOWTO (R_MIPS_GOT_HI16, /* type */
444 0, /* rightshift */
445 2, /* size (0 = byte, 1 = short, 2 = long) */
446 16, /* bitsize */
447 FALSE, /* pc_relative */
448 0, /* bitpos */
449 complain_overflow_dont, /* complain_on_overflow */
450 _bfd_mips_elf_generic_reloc, /* special_function */
451 "R_MIPS_GOT_HI16", /* name */
452 TRUE, /* partial_inplace */
453 0x0000ffff, /* src_mask */
454 0x0000ffff, /* dst_mask */
455 FALSE), /* pcrel_offset */
456
457 /* Low 16 bits of displacement in global offset table. */
458 HOWTO (R_MIPS_GOT_LO16, /* type */
459 0, /* rightshift */
460 2, /* size (0 = byte, 1 = short, 2 = long) */
461 16, /* bitsize */
462 FALSE, /* pc_relative */
463 0, /* bitpos */
464 complain_overflow_dont, /* complain_on_overflow */
465 _bfd_mips_elf_generic_reloc, /* special_function */
466 "R_MIPS_GOT_LO16", /* name */
467 TRUE, /* partial_inplace */
468 0x0000ffff, /* src_mask */
469 0x0000ffff, /* dst_mask */
470 FALSE), /* pcrel_offset */
471
472 /* 64 bit subtraction. */
473 HOWTO (R_MIPS_SUB, /* type */
474 0, /* rightshift */
475 4, /* size (0 = byte, 1 = short, 2 = long) */
476 64, /* bitsize */
477 FALSE, /* pc_relative */
478 0, /* bitpos */
479 complain_overflow_dont, /* complain_on_overflow */
480 _bfd_mips_elf_generic_reloc, /* special_function */
481 "R_MIPS_SUB", /* name */
482 TRUE, /* partial_inplace */
483 MINUS_ONE, /* src_mask */
484 MINUS_ONE, /* dst_mask */
485 FALSE), /* pcrel_offset */
486
487 /* Insert the addend as an instruction. */
488 /* FIXME: Not handled correctly. */
489 HOWTO (R_MIPS_INSERT_A, /* type */
490 0, /* rightshift */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
492 32, /* bitsize */
493 FALSE, /* pc_relative */
494 0, /* bitpos */
495 complain_overflow_dont, /* complain_on_overflow */
496 _bfd_mips_elf_generic_reloc, /* special_function */
497 "R_MIPS_INSERT_A", /* name */
498 TRUE, /* partial_inplace */
499 0xffffffff, /* src_mask */
500 0xffffffff, /* dst_mask */
501 FALSE), /* pcrel_offset */
502
503 /* Insert the addend as an instruction, and change all relocations
504 to refer to the old instruction at the address. */
505 /* FIXME: Not handled correctly. */
506 HOWTO (R_MIPS_INSERT_B, /* type */
507 0, /* rightshift */
508 2, /* size (0 = byte, 1 = short, 2 = long) */
509 32, /* bitsize */
510 FALSE, /* pc_relative */
511 0, /* bitpos */
512 complain_overflow_dont, /* complain_on_overflow */
513 _bfd_mips_elf_generic_reloc, /* special_function */
514 "R_MIPS_INSERT_B", /* name */
515 TRUE, /* partial_inplace */
516 0xffffffff, /* src_mask */
517 0xffffffff, /* dst_mask */
518 FALSE), /* pcrel_offset */
519
520 /* Delete a 32 bit instruction. */
521 /* FIXME: Not handled correctly. */
522 HOWTO (R_MIPS_DELETE, /* type */
523 0, /* rightshift */
524 2, /* size (0 = byte, 1 = short, 2 = long) */
525 32, /* bitsize */
526 FALSE, /* pc_relative */
527 0, /* bitpos */
528 complain_overflow_dont, /* complain_on_overflow */
529 _bfd_mips_elf_generic_reloc, /* special_function */
530 "R_MIPS_DELETE", /* name */
531 TRUE, /* partial_inplace */
532 0xffffffff, /* src_mask */
533 0xffffffff, /* dst_mask */
534 FALSE), /* pcrel_offset */
535
536 /* The MIPS ELF64 ABI Draft wants us to support these for REL relocations.
537 We don't, because
538 a) It means building the addend from a R_MIPS_HIGHEST/R_MIPS_HIGHER/
539 R_MIPS_HI16/R_MIPS_LO16 sequence with varying ordering, using
540 fallable heuristics.
541 b) No other NewABI toolchain actually emits such relocations. */
542 EMPTY_HOWTO (R_MIPS_HIGHER),
543 EMPTY_HOWTO (R_MIPS_HIGHEST),
544
545 /* High 16 bits of displacement in global offset table. */
546 HOWTO (R_MIPS_CALL_HI16, /* type */
547 0, /* rightshift */
548 2, /* size (0 = byte, 1 = short, 2 = long) */
549 16, /* bitsize */
550 FALSE, /* pc_relative */
551 0, /* bitpos */
552 complain_overflow_dont, /* complain_on_overflow */
553 _bfd_mips_elf_generic_reloc, /* special_function */
554 "R_MIPS_CALL_HI16", /* name */
555 TRUE, /* partial_inplace */
556 0x0000ffff, /* src_mask */
557 0x0000ffff, /* dst_mask */
558 FALSE), /* pcrel_offset */
559
560 /* Low 16 bits of displacement in global offset table. */
561 HOWTO (R_MIPS_CALL_LO16, /* type */
562 0, /* rightshift */
563 2, /* size (0 = byte, 1 = short, 2 = long) */
564 16, /* bitsize */
565 FALSE, /* pc_relative */
566 0, /* bitpos */
567 complain_overflow_dont, /* complain_on_overflow */
568 _bfd_mips_elf_generic_reloc, /* special_function */
569 "R_MIPS_CALL_LO16", /* name */
570 TRUE, /* partial_inplace */
571 0x0000ffff, /* src_mask */
572 0x0000ffff, /* dst_mask */
573 FALSE), /* pcrel_offset */
574
575 /* Section displacement, used by an associated event location section. */
576 HOWTO (R_MIPS_SCN_DISP, /* type */
577 0, /* rightshift */
578 2, /* size (0 = byte, 1 = short, 2 = long) */
579 32, /* bitsize */
580 FALSE, /* pc_relative */
581 0, /* bitpos */
582 complain_overflow_dont, /* complain_on_overflow */
583 _bfd_mips_elf_generic_reloc, /* special_function */
584 "R_MIPS_SCN_DISP", /* name */
585 TRUE, /* partial_inplace */
586 0xffffffff, /* src_mask */
587 0xffffffff, /* dst_mask */
588 FALSE), /* pcrel_offset */
589
590 HOWTO (R_MIPS_REL16, /* type */
591 0, /* rightshift */
592 1, /* size (0 = byte, 1 = short, 2 = long) */
593 16, /* bitsize */
594 FALSE, /* pc_relative */
595 0, /* bitpos */
596 complain_overflow_signed, /* complain_on_overflow */
597 _bfd_mips_elf_generic_reloc, /* special_function */
598 "R_MIPS_REL16", /* name */
599 TRUE, /* partial_inplace */
600 0xffff, /* src_mask */
601 0xffff, /* dst_mask */
602 FALSE), /* pcrel_offset */
603
604 /* These two are obsolete. */
605 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
606 EMPTY_HOWTO (R_MIPS_PJUMP),
607
608 /* Similiar to R_MIPS_REL32, but used for relocations in a GOT section.
609 It must be used for multigot GOT's (and only there). */
610 HOWTO (R_MIPS_RELGOT, /* type */
611 0, /* rightshift */
612 2, /* size (0 = byte, 1 = short, 2 = long) */
613 32, /* bitsize */
614 FALSE, /* pc_relative */
615 0, /* bitpos */
616 complain_overflow_dont, /* complain_on_overflow */
617 _bfd_mips_elf_generic_reloc, /* special_function */
618 "R_MIPS_RELGOT", /* name */
619 TRUE, /* partial_inplace */
620 0xffffffff, /* src_mask */
621 0xffffffff, /* dst_mask */
622 FALSE), /* pcrel_offset */
623
624 /* Protected jump conversion. This is an optimization hint. No
625 relocation is required for correctness. */
626 HOWTO (R_MIPS_JALR, /* type */
627 0, /* rightshift */
628 2, /* size (0 = byte, 1 = short, 2 = long) */
629 32, /* bitsize */
630 FALSE, /* pc_relative */
631 0, /* bitpos */
632 complain_overflow_dont, /* complain_on_overflow */
633 _bfd_mips_elf_generic_reloc, /* special_function */
634 "R_MIPS_JALR", /* name */
635 FALSE, /* partial_inplace */
636 0, /* src_mask */
637 0x00000000, /* dst_mask */
638 FALSE), /* pcrel_offset */
639
640 /* TLS relocations. */
641 EMPTY_HOWTO (R_MIPS_TLS_DTPMOD32),
642 EMPTY_HOWTO (R_MIPS_TLS_DTPREL32),
643
644 HOWTO (R_MIPS_TLS_DTPMOD64, /* type */
645 0, /* rightshift */
646 4, /* size (0 = byte, 1 = short, 2 = long) */
647 64, /* bitsize */
648 FALSE, /* pc_relative */
649 0, /* bitpos */
650 complain_overflow_dont, /* complain_on_overflow */
651 _bfd_mips_elf_generic_reloc, /* special_function */
652 "R_MIPS_TLS_DTPMOD64", /* name */
653 TRUE, /* partial_inplace */
654 MINUS_ONE, /* src_mask */
655 MINUS_ONE, /* dst_mask */
656 FALSE), /* pcrel_offset */
657
658 HOWTO (R_MIPS_TLS_DTPREL64, /* type */
659 0, /* rightshift */
660 4, /* size (0 = byte, 1 = short, 2 = long) */
661 64, /* bitsize */
662 FALSE, /* pc_relative */
663 0, /* bitpos */
664 complain_overflow_dont, /* complain_on_overflow */
665 _bfd_mips_elf_generic_reloc, /* special_function */
666 "R_MIPS_TLS_DTPREL64", /* name */
667 TRUE, /* partial_inplace */
668 MINUS_ONE, /* src_mask */
669 MINUS_ONE, /* dst_mask */
670 FALSE), /* pcrel_offset */
671
672 /* TLS general dynamic variable reference. */
673 HOWTO (R_MIPS_TLS_GD, /* type */
674 0, /* rightshift */
675 2, /* size (0 = byte, 1 = short, 2 = long) */
676 16, /* bitsize */
677 FALSE, /* pc_relative */
678 0, /* bitpos */
679 complain_overflow_signed, /* complain_on_overflow */
680 _bfd_mips_elf_generic_reloc, /* special_function */
681 "R_MIPS_TLS_GD", /* name */
682 TRUE, /* partial_inplace */
683 0x0000ffff, /* src_mask */
684 0x0000ffff, /* dst_mask */
685 FALSE), /* pcrel_offset */
686
687 /* TLS local dynamic variable reference. */
688 HOWTO (R_MIPS_TLS_LDM, /* type */
689 0, /* rightshift */
690 2, /* size (0 = byte, 1 = short, 2 = long) */
691 16, /* bitsize */
692 FALSE, /* pc_relative */
693 0, /* bitpos */
694 complain_overflow_signed, /* complain_on_overflow */
695 _bfd_mips_elf_generic_reloc, /* special_function */
696 "R_MIPS_TLS_LDM", /* name */
697 TRUE, /* partial_inplace */
698 0x0000ffff, /* src_mask */
699 0x0000ffff, /* dst_mask */
700 FALSE), /* pcrel_offset */
701
702 /* TLS local dynamic offset. */
703 HOWTO (R_MIPS_TLS_DTPREL_HI16, /* type */
704 0, /* rightshift */
705 2, /* size (0 = byte, 1 = short, 2 = long) */
706 16, /* bitsize */
707 FALSE, /* pc_relative */
708 0, /* bitpos */
709 complain_overflow_signed, /* complain_on_overflow */
710 _bfd_mips_elf_generic_reloc, /* special_function */
711 "R_MIPS_TLS_DTPREL_HI16", /* name */
712 TRUE, /* partial_inplace */
713 0x0000ffff, /* src_mask */
714 0x0000ffff, /* dst_mask */
715 FALSE), /* pcrel_offset */
716
717 /* TLS local dynamic offset. */
718 HOWTO (R_MIPS_TLS_DTPREL_LO16, /* type */
719 0, /* rightshift */
720 2, /* size (0 = byte, 1 = short, 2 = long) */
721 16, /* bitsize */
722 FALSE, /* pc_relative */
723 0, /* bitpos */
724 complain_overflow_signed, /* complain_on_overflow */
725 _bfd_mips_elf_generic_reloc, /* special_function */
726 "R_MIPS_TLS_DTPREL_LO16", /* name */
727 TRUE, /* partial_inplace */
728 0x0000ffff, /* src_mask */
729 0x0000ffff, /* dst_mask */
730 FALSE), /* pcrel_offset */
731
732 /* TLS thread pointer offset. */
733 HOWTO (R_MIPS_TLS_GOTTPREL, /* type */
734 0, /* rightshift */
735 2, /* size (0 = byte, 1 = short, 2 = long) */
736 16, /* bitsize */
737 FALSE, /* pc_relative */
738 0, /* bitpos */
739 complain_overflow_signed, /* complain_on_overflow */
740 _bfd_mips_elf_generic_reloc, /* special_function */
741 "R_MIPS_TLS_GOTTPREL", /* name */
742 TRUE, /* partial_inplace */
743 0x0000ffff, /* src_mask */
744 0x0000ffff, /* dst_mask */
745 FALSE), /* pcrel_offset */
746
747 /* TLS IE dynamic relocations. */
748 EMPTY_HOWTO (R_MIPS_TLS_TPREL32),
749
750 HOWTO (R_MIPS_TLS_TPREL64, /* type */
751 0, /* rightshift */
752 4, /* size (0 = byte, 1 = short, 2 = long) */
753 64, /* bitsize */
754 FALSE, /* pc_relative */
755 0, /* bitpos */
756 complain_overflow_dont, /* complain_on_overflow */
757 _bfd_mips_elf_generic_reloc, /* special_function */
758 "R_MIPS_TLS_TPREL64", /* name */
759 TRUE, /* partial_inplace */
760 MINUS_ONE, /* src_mask */
761 MINUS_ONE, /* dst_mask */
762 FALSE), /* pcrel_offset */
763
764 /* TLS thread pointer offset. */
765 HOWTO (R_MIPS_TLS_TPREL_HI16, /* type */
766 0, /* rightshift */
767 2, /* size (0 = byte, 1 = short, 2 = long) */
768 16, /* bitsize */
769 FALSE, /* pc_relative */
770 0, /* bitpos */
771 complain_overflow_signed, /* complain_on_overflow */
772 _bfd_mips_elf_generic_reloc, /* special_function */
773 "R_MIPS_TLS_TPREL_HI16", /* name */
774 TRUE, /* partial_inplace */
775 0x0000ffff, /* src_mask */
776 0x0000ffff, /* dst_mask */
777 FALSE), /* pcrel_offset */
778
779 /* TLS thread pointer offset. */
780 HOWTO (R_MIPS_TLS_TPREL_LO16, /* type */
781 0, /* rightshift */
782 2, /* size (0 = byte, 1 = short, 2 = long) */
783 16, /* bitsize */
784 FALSE, /* pc_relative */
785 0, /* bitpos */
786 complain_overflow_signed, /* complain_on_overflow */
787 _bfd_mips_elf_generic_reloc, /* special_function */
788 "R_MIPS_TLS_TPREL_LO16", /* name */
789 TRUE, /* partial_inplace */
790 0x0000ffff, /* src_mask */
791 0x0000ffff, /* dst_mask */
792 FALSE), /* pcrel_offset */
793
794 /* 32 bit relocation with no addend. */
795 HOWTO (R_MIPS_GLOB_DAT, /* type */
796 0, /* rightshift */
797 2, /* size (0 = byte, 1 = short, 2 = long) */
798 32, /* bitsize */
799 FALSE, /* pc_relative */
800 0, /* bitpos */
801 complain_overflow_dont, /* complain_on_overflow */
802 _bfd_mips_elf_generic_reloc, /* special_function */
803 "R_MIPS_GLOB_DAT", /* name */
804 FALSE, /* partial_inplace */
805 0x0, /* src_mask */
806 0xffffffff, /* dst_mask */
807 FALSE), /* pcrel_offset */
808 };
809
810 /* The relocation table used for SHT_RELA sections. */
811
812 static reloc_howto_type mips_elf64_howto_table_rela[] =
813 {
814 /* No relocation. */
815 HOWTO (R_MIPS_NONE, /* type */
816 0, /* rightshift */
817 0, /* size (0 = byte, 1 = short, 2 = long) */
818 0, /* bitsize */
819 FALSE, /* pc_relative */
820 0, /* bitpos */
821 complain_overflow_dont, /* complain_on_overflow */
822 _bfd_mips_elf_generic_reloc, /* special_function */
823 "R_MIPS_NONE", /* name */
824 FALSE, /* partial_inplace */
825 0, /* src_mask */
826 0, /* dst_mask */
827 FALSE), /* pcrel_offset */
828
829 /* 16 bit relocation. */
830 HOWTO (R_MIPS_16, /* type */
831 0, /* rightshift */
832 2, /* size (0 = byte, 1 = short, 2 = long) */
833 16, /* bitsize */
834 FALSE, /* pc_relative */
835 0, /* bitpos */
836 complain_overflow_signed, /* complain_on_overflow */
837 _bfd_mips_elf_generic_reloc, /* special_function */
838 "R_MIPS_16", /* name */
839 FALSE, /* partial_inplace */
840 0, /* src_mask */
841 0x0000ffff, /* dst_mask */
842 FALSE), /* pcrel_offset */
843
844 /* 32 bit relocation. */
845 HOWTO (R_MIPS_32, /* type */
846 0, /* rightshift */
847 2, /* size (0 = byte, 1 = short, 2 = long) */
848 32, /* bitsize */
849 FALSE, /* pc_relative */
850 0, /* bitpos */
851 complain_overflow_dont, /* complain_on_overflow */
852 _bfd_mips_elf_generic_reloc, /* special_function */
853 "R_MIPS_32", /* name */
854 FALSE, /* partial_inplace */
855 0, /* src_mask */
856 0xffffffff, /* dst_mask */
857 FALSE), /* pcrel_offset */
858
859 /* 32 bit symbol relative relocation. */
860 HOWTO (R_MIPS_REL32, /* type */
861 0, /* rightshift */
862 2, /* size (0 = byte, 1 = short, 2 = long) */
863 32, /* bitsize */
864 FALSE, /* pc_relative */
865 0, /* bitpos */
866 complain_overflow_dont, /* complain_on_overflow */
867 _bfd_mips_elf_generic_reloc, /* special_function */
868 "R_MIPS_REL32", /* name */
869 FALSE, /* partial_inplace */
870 0, /* src_mask */
871 0xffffffff, /* dst_mask */
872 FALSE), /* pcrel_offset */
873
874 /* 26 bit jump address. */
875 HOWTO (R_MIPS_26, /* type */
876 2, /* rightshift */
877 2, /* size (0 = byte, 1 = short, 2 = long) */
878 26, /* bitsize */
879 FALSE, /* pc_relative */
880 0, /* bitpos */
881 complain_overflow_dont, /* complain_on_overflow */
882 /* This needs complex overflow
883 detection, because the upper 36
884 bits must match the PC + 4. */
885 _bfd_mips_elf_generic_reloc, /* special_function */
886 "R_MIPS_26", /* name */
887 FALSE, /* partial_inplace */
888 0, /* src_mask */
889 0x03ffffff, /* dst_mask */
890 FALSE), /* pcrel_offset */
891
892 /* High 16 bits of symbol value. */
893 HOWTO (R_MIPS_HI16, /* type */
894 0, /* rightshift */
895 2, /* size (0 = byte, 1 = short, 2 = long) */
896 16, /* bitsize */
897 FALSE, /* pc_relative */
898 0, /* bitpos */
899 complain_overflow_dont, /* complain_on_overflow */
900 _bfd_mips_elf_generic_reloc, /* special_function */
901 "R_MIPS_HI16", /* name */
902 FALSE, /* partial_inplace */
903 0, /* src_mask */
904 0x0000ffff, /* dst_mask */
905 FALSE), /* pcrel_offset */
906
907 /* Low 16 bits of symbol value. */
908 HOWTO (R_MIPS_LO16, /* type */
909 0, /* rightshift */
910 2, /* size (0 = byte, 1 = short, 2 = long) */
911 16, /* bitsize */
912 FALSE, /* pc_relative */
913 0, /* bitpos */
914 complain_overflow_dont, /* complain_on_overflow */
915 _bfd_mips_elf_generic_reloc, /* special_function */
916 "R_MIPS_LO16", /* name */
917 FALSE, /* partial_inplace */
918 0, /* src_mask */
919 0x0000ffff, /* dst_mask */
920 FALSE), /* pcrel_offset */
921
922 /* GP relative reference. */
923 HOWTO (R_MIPS_GPREL16, /* type */
924 0, /* rightshift */
925 2, /* size (0 = byte, 1 = short, 2 = long) */
926 16, /* bitsize */
927 FALSE, /* pc_relative */
928 0, /* bitpos */
929 complain_overflow_signed, /* complain_on_overflow */
930 mips_elf64_gprel16_reloc, /* special_function */
931 "R_MIPS_GPREL16", /* name */
932 FALSE, /* partial_inplace */
933 0, /* src_mask */
934 0x0000ffff, /* dst_mask */
935 FALSE), /* pcrel_offset */
936
937 /* Reference to literal section. */
938 HOWTO (R_MIPS_LITERAL, /* type */
939 0, /* rightshift */
940 2, /* size (0 = byte, 1 = short, 2 = long) */
941 16, /* bitsize */
942 FALSE, /* pc_relative */
943 0, /* bitpos */
944 complain_overflow_signed, /* complain_on_overflow */
945 mips_elf64_literal_reloc, /* special_function */
946 "R_MIPS_LITERAL", /* name */
947 FALSE, /* partial_inplace */
948 0, /* src_mask */
949 0x0000ffff, /* dst_mask */
950 FALSE), /* pcrel_offset */
951
952 /* Reference to global offset table. */
953 HOWTO (R_MIPS_GOT16, /* type */
954 0, /* rightshift */
955 2, /* size (0 = byte, 1 = short, 2 = long) */
956 16, /* bitsize */
957 FALSE, /* pc_relative */
958 0, /* bitpos */
959 complain_overflow_signed, /* complain_on_overflow */
960 _bfd_mips_elf_generic_reloc, /* special_function */
961 "R_MIPS_GOT16", /* name */
962 FALSE, /* partial_inplace */
963 0, /* src_mask */
964 0x0000ffff, /* dst_mask */
965 FALSE), /* pcrel_offset */
966
967 /* 16 bit PC relative reference. Note that the ABI document has a typo
968 and claims R_MIPS_PC16 to be not rightshifted, rendering it useless.
969 We do the right thing here. */
970 HOWTO (R_MIPS_PC16, /* type */
971 2, /* rightshift */
972 2, /* size (0 = byte, 1 = short, 2 = long) */
973 16, /* bitsize */
974 TRUE, /* pc_relative */
975 0, /* bitpos */
976 complain_overflow_signed, /* complain_on_overflow */
977 _bfd_mips_elf_generic_reloc, /* special_function */
978 "R_MIPS_PC16", /* name */
979 FALSE, /* partial_inplace */
980 0, /* src_mask */
981 0x0000ffff, /* dst_mask */
982 TRUE), /* pcrel_offset */
983
984 /* 16 bit call through global offset table. */
985 HOWTO (R_MIPS_CALL16, /* type */
986 0, /* rightshift */
987 2, /* size (0 = byte, 1 = short, 2 = long) */
988 16, /* bitsize */
989 FALSE, /* pc_relative */
990 0, /* bitpos */
991 complain_overflow_signed, /* complain_on_overflow */
992 _bfd_mips_elf_generic_reloc, /* special_function */
993 "R_MIPS_CALL16", /* name */
994 FALSE, /* partial_inplace */
995 0, /* src_mask */
996 0x0000ffff, /* dst_mask */
997 FALSE), /* pcrel_offset */
998
999 /* 32 bit GP relative reference. */
1000 HOWTO (R_MIPS_GPREL32, /* type */
1001 0, /* rightshift */
1002 2, /* size (0 = byte, 1 = short, 2 = long) */
1003 32, /* bitsize */
1004 FALSE, /* pc_relative */
1005 0, /* bitpos */
1006 complain_overflow_dont, /* complain_on_overflow */
1007 mips_elf64_gprel32_reloc, /* special_function */
1008 "R_MIPS_GPREL32", /* name */
1009 FALSE, /* partial_inplace */
1010 0, /* src_mask */
1011 0xffffffff, /* dst_mask */
1012 FALSE), /* pcrel_offset */
1013
1014 EMPTY_HOWTO (13),
1015 EMPTY_HOWTO (14),
1016 EMPTY_HOWTO (15),
1017
1018 /* A 5 bit shift field. */
1019 HOWTO (R_MIPS_SHIFT5, /* type */
1020 0, /* rightshift */
1021 2, /* size (0 = byte, 1 = short, 2 = long) */
1022 5, /* bitsize */
1023 FALSE, /* pc_relative */
1024 6, /* bitpos */
1025 complain_overflow_bitfield, /* complain_on_overflow */
1026 _bfd_mips_elf_generic_reloc, /* special_function */
1027 "R_MIPS_SHIFT5", /* name */
1028 FALSE, /* partial_inplace */
1029 0, /* src_mask */
1030 0x000007c0, /* dst_mask */
1031 FALSE), /* pcrel_offset */
1032
1033 /* A 6 bit shift field. */
1034 HOWTO (R_MIPS_SHIFT6, /* type */
1035 0, /* rightshift */
1036 2, /* size (0 = byte, 1 = short, 2 = long) */
1037 6, /* bitsize */
1038 FALSE, /* pc_relative */
1039 6, /* bitpos */
1040 complain_overflow_bitfield, /* complain_on_overflow */
1041 mips_elf64_shift6_reloc, /* special_function */
1042 "R_MIPS_SHIFT6", /* name */
1043 FALSE, /* partial_inplace */
1044 0, /* src_mask */
1045 0x000007c4, /* dst_mask */
1046 FALSE), /* pcrel_offset */
1047
1048 /* 64 bit relocation. */
1049 HOWTO (R_MIPS_64, /* type */
1050 0, /* rightshift */
1051 4, /* size (0 = byte, 1 = short, 2 = long) */
1052 64, /* bitsize */
1053 FALSE, /* pc_relative */
1054 0, /* bitpos */
1055 complain_overflow_dont, /* complain_on_overflow */
1056 _bfd_mips_elf_generic_reloc, /* special_function */
1057 "R_MIPS_64", /* name */
1058 FALSE, /* partial_inplace */
1059 0, /* src_mask */
1060 MINUS_ONE, /* dst_mask */
1061 FALSE), /* pcrel_offset */
1062
1063 /* Displacement in the global offset table. */
1064 HOWTO (R_MIPS_GOT_DISP, /* type */
1065 0, /* rightshift */
1066 2, /* size (0 = byte, 1 = short, 2 = long) */
1067 16, /* bitsize */
1068 FALSE, /* pc_relative */
1069 0, /* bitpos */
1070 complain_overflow_signed, /* complain_on_overflow */
1071 _bfd_mips_elf_generic_reloc, /* special_function */
1072 "R_MIPS_GOT_DISP", /* name */
1073 FALSE, /* partial_inplace */
1074 0, /* src_mask */
1075 0x0000ffff, /* dst_mask */
1076 FALSE), /* pcrel_offset */
1077
1078 /* Displacement to page pointer in the global offset table. */
1079 HOWTO (R_MIPS_GOT_PAGE, /* type */
1080 0, /* rightshift */
1081 2, /* size (0 = byte, 1 = short, 2 = long) */
1082 16, /* bitsize */
1083 FALSE, /* pc_relative */
1084 0, /* bitpos */
1085 complain_overflow_signed, /* complain_on_overflow */
1086 _bfd_mips_elf_generic_reloc, /* special_function */
1087 "R_MIPS_GOT_PAGE", /* name */
1088 FALSE, /* partial_inplace */
1089 0, /* src_mask */
1090 0x0000ffff, /* dst_mask */
1091 FALSE), /* pcrel_offset */
1092
1093 /* Offset from page pointer in the global offset table. */
1094 HOWTO (R_MIPS_GOT_OFST, /* type */
1095 0, /* rightshift */
1096 2, /* size (0 = byte, 1 = short, 2 = long) */
1097 16, /* bitsize */
1098 FALSE, /* pc_relative */
1099 0, /* bitpos */
1100 complain_overflow_signed, /* complain_on_overflow */
1101 _bfd_mips_elf_generic_reloc, /* special_function */
1102 "R_MIPS_GOT_OFST", /* name */
1103 FALSE, /* partial_inplace */
1104 0, /* src_mask */
1105 0x0000ffff, /* dst_mask */
1106 FALSE), /* pcrel_offset */
1107
1108 /* High 16 bits of displacement in global offset table. */
1109 HOWTO (R_MIPS_GOT_HI16, /* type */
1110 0, /* rightshift */
1111 2, /* size (0 = byte, 1 = short, 2 = long) */
1112 16, /* bitsize */
1113 FALSE, /* pc_relative */
1114 0, /* bitpos */
1115 complain_overflow_dont, /* complain_on_overflow */
1116 _bfd_mips_elf_generic_reloc, /* special_function */
1117 "R_MIPS_GOT_HI16", /* name */
1118 FALSE, /* partial_inplace */
1119 0, /* src_mask */
1120 0x0000ffff, /* dst_mask */
1121 FALSE), /* pcrel_offset */
1122
1123 /* Low 16 bits of displacement in global offset table. */
1124 HOWTO (R_MIPS_GOT_LO16, /* type */
1125 0, /* rightshift */
1126 2, /* size (0 = byte, 1 = short, 2 = long) */
1127 16, /* bitsize */
1128 FALSE, /* pc_relative */
1129 0, /* bitpos */
1130 complain_overflow_dont, /* complain_on_overflow */
1131 _bfd_mips_elf_generic_reloc, /* special_function */
1132 "R_MIPS_GOT_LO16", /* name */
1133 FALSE, /* partial_inplace */
1134 0, /* src_mask */
1135 0x0000ffff, /* dst_mask */
1136 FALSE), /* pcrel_offset */
1137
1138 /* 64 bit subtraction. */
1139 HOWTO (R_MIPS_SUB, /* type */
1140 0, /* rightshift */
1141 4, /* size (0 = byte, 1 = short, 2 = long) */
1142 64, /* bitsize */
1143 FALSE, /* pc_relative */
1144 0, /* bitpos */
1145 complain_overflow_dont, /* complain_on_overflow */
1146 _bfd_mips_elf_generic_reloc, /* special_function */
1147 "R_MIPS_SUB", /* name */
1148 FALSE, /* partial_inplace */
1149 0, /* src_mask */
1150 MINUS_ONE, /* dst_mask */
1151 FALSE), /* pcrel_offset */
1152
1153 /* Insert the addend as an instruction. */
1154 /* FIXME: Not handled correctly. */
1155 HOWTO (R_MIPS_INSERT_A, /* type */
1156 0, /* rightshift */
1157 2, /* size (0 = byte, 1 = short, 2 = long) */
1158 32, /* bitsize */
1159 FALSE, /* pc_relative */
1160 0, /* bitpos */
1161 complain_overflow_dont, /* complain_on_overflow */
1162 _bfd_mips_elf_generic_reloc, /* special_function */
1163 "R_MIPS_INSERT_A", /* name */
1164 FALSE, /* partial_inplace */
1165 0, /* src_mask */
1166 0xffffffff, /* dst_mask */
1167 FALSE), /* pcrel_offset */
1168
1169 /* Insert the addend as an instruction, and change all relocations
1170 to refer to the old instruction at the address. */
1171 /* FIXME: Not handled correctly. */
1172 HOWTO (R_MIPS_INSERT_B, /* type */
1173 0, /* rightshift */
1174 2, /* size (0 = byte, 1 = short, 2 = long) */
1175 32, /* bitsize */
1176 FALSE, /* pc_relative */
1177 0, /* bitpos */
1178 complain_overflow_dont, /* complain_on_overflow */
1179 _bfd_mips_elf_generic_reloc, /* special_function */
1180 "R_MIPS_INSERT_B", /* name */
1181 FALSE, /* partial_inplace */
1182 0, /* src_mask */
1183 0xffffffff, /* dst_mask */
1184 FALSE), /* pcrel_offset */
1185
1186 /* Delete a 32 bit instruction. */
1187 /* FIXME: Not handled correctly. */
1188 HOWTO (R_MIPS_DELETE, /* type */
1189 0, /* rightshift */
1190 2, /* size (0 = byte, 1 = short, 2 = long) */
1191 32, /* bitsize */
1192 FALSE, /* pc_relative */
1193 0, /* bitpos */
1194 complain_overflow_dont, /* complain_on_overflow */
1195 _bfd_mips_elf_generic_reloc, /* special_function */
1196 "R_MIPS_DELETE", /* name */
1197 FALSE, /* partial_inplace */
1198 0, /* src_mask */
1199 0xffffffff, /* dst_mask */
1200 FALSE), /* pcrel_offset */
1201
1202 /* Get the higher value of a 64 bit addend. */
1203 HOWTO (R_MIPS_HIGHER, /* type */
1204 0, /* rightshift */
1205 2, /* size (0 = byte, 1 = short, 2 = long) */
1206 16, /* bitsize */
1207 FALSE, /* pc_relative */
1208 0, /* bitpos */
1209 complain_overflow_dont, /* complain_on_overflow */
1210 _bfd_mips_elf_generic_reloc, /* special_function */
1211 "R_MIPS_HIGHER", /* name */
1212 FALSE, /* partial_inplace */
1213 0, /* src_mask */
1214 0x0000ffff, /* dst_mask */
1215 FALSE), /* pcrel_offset */
1216
1217 /* Get the highest value of a 64 bit addend. */
1218 HOWTO (R_MIPS_HIGHEST, /* type */
1219 0, /* rightshift */
1220 2, /* size (0 = byte, 1 = short, 2 = long) */
1221 16, /* bitsize */
1222 FALSE, /* pc_relative */
1223 0, /* bitpos */
1224 complain_overflow_dont, /* complain_on_overflow */
1225 _bfd_mips_elf_generic_reloc, /* special_function */
1226 "R_MIPS_HIGHEST", /* name */
1227 FALSE, /* partial_inplace */
1228 0, /* src_mask */
1229 0x0000ffff, /* dst_mask */
1230 FALSE), /* pcrel_offset */
1231
1232 /* High 16 bits of displacement in global offset table. */
1233 HOWTO (R_MIPS_CALL_HI16, /* type */
1234 0, /* rightshift */
1235 2, /* size (0 = byte, 1 = short, 2 = long) */
1236 16, /* bitsize */
1237 FALSE, /* pc_relative */
1238 0, /* bitpos */
1239 complain_overflow_dont, /* complain_on_overflow */
1240 _bfd_mips_elf_generic_reloc, /* special_function */
1241 "R_MIPS_CALL_HI16", /* name */
1242 FALSE, /* partial_inplace */
1243 0, /* src_mask */
1244 0x0000ffff, /* dst_mask */
1245 FALSE), /* pcrel_offset */
1246
1247 /* Low 16 bits of displacement in global offset table. */
1248 HOWTO (R_MIPS_CALL_LO16, /* type */
1249 0, /* rightshift */
1250 2, /* size (0 = byte, 1 = short, 2 = long) */
1251 16, /* bitsize */
1252 FALSE, /* pc_relative */
1253 0, /* bitpos */
1254 complain_overflow_dont, /* complain_on_overflow */
1255 _bfd_mips_elf_generic_reloc, /* special_function */
1256 "R_MIPS_CALL_LO16", /* name */
1257 FALSE, /* partial_inplace */
1258 0, /* src_mask */
1259 0x0000ffff, /* dst_mask */
1260 FALSE), /* pcrel_offset */
1261
1262 /* Section displacement, used by an associated event location section. */
1263 HOWTO (R_MIPS_SCN_DISP, /* type */
1264 0, /* rightshift */
1265 2, /* size (0 = byte, 1 = short, 2 = long) */
1266 32, /* bitsize */
1267 FALSE, /* pc_relative */
1268 0, /* bitpos */
1269 complain_overflow_dont, /* complain_on_overflow */
1270 _bfd_mips_elf_generic_reloc, /* special_function */
1271 "R_MIPS_SCN_DISP", /* name */
1272 FALSE, /* partial_inplace */
1273 0, /* src_mask */
1274 0xffffffff, /* dst_mask */
1275 FALSE), /* pcrel_offset */
1276
1277 HOWTO (R_MIPS_REL16, /* type */
1278 0, /* rightshift */
1279 1, /* size (0 = byte, 1 = short, 2 = long) */
1280 16, /* bitsize */
1281 FALSE, /* pc_relative */
1282 0, /* bitpos */
1283 complain_overflow_signed, /* complain_on_overflow */
1284 _bfd_mips_elf_generic_reloc, /* special_function */
1285 "R_MIPS_REL16", /* name */
1286 FALSE, /* partial_inplace */
1287 0, /* src_mask */
1288 0xffff, /* dst_mask */
1289 FALSE), /* pcrel_offset */
1290
1291 /* These two are obsolete. */
1292 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
1293 EMPTY_HOWTO (R_MIPS_PJUMP),
1294
1295 /* Similiar to R_MIPS_REL32, but used for relocations in a GOT section.
1296 It must be used for multigot GOT's (and only there). */
1297 HOWTO (R_MIPS_RELGOT, /* type */
1298 0, /* rightshift */
1299 2, /* size (0 = byte, 1 = short, 2 = long) */
1300 32, /* bitsize */
1301 FALSE, /* pc_relative */
1302 0, /* bitpos */
1303 complain_overflow_dont, /* complain_on_overflow */
1304 _bfd_mips_elf_generic_reloc, /* special_function */
1305 "R_MIPS_RELGOT", /* name */
1306 FALSE, /* partial_inplace */
1307 0, /* src_mask */
1308 0xffffffff, /* dst_mask */
1309 FALSE), /* pcrel_offset */
1310
1311 /* Protected jump conversion. This is an optimization hint. No
1312 relocation is required for correctness. */
1313 HOWTO (R_MIPS_JALR, /* type */
1314 0, /* rightshift */
1315 2, /* size (0 = byte, 1 = short, 2 = long) */
1316 32, /* bitsize */
1317 FALSE, /* pc_relative */
1318 0, /* bitpos */
1319 complain_overflow_dont, /* complain_on_overflow */
1320 _bfd_mips_elf_generic_reloc, /* special_function */
1321 "R_MIPS_JALR", /* name */
1322 FALSE, /* partial_inplace */
1323 0, /* src_mask */
1324 0x00000000, /* dst_mask */
1325 FALSE), /* pcrel_offset */
1326
1327 /* TLS relocations. */
1328 EMPTY_HOWTO (R_MIPS_TLS_DTPMOD32),
1329 EMPTY_HOWTO (R_MIPS_TLS_DTPREL32),
1330
1331 HOWTO (R_MIPS_TLS_DTPMOD64, /* type */
1332 0, /* rightshift */
1333 4, /* size (0 = byte, 1 = short, 2 = long) */
1334 64, /* bitsize */
1335 FALSE, /* pc_relative */
1336 0, /* bitpos */
1337 complain_overflow_dont, /* complain_on_overflow */
1338 _bfd_mips_elf_generic_reloc, /* special_function */
1339 "R_MIPS_TLS_DTPMOD64", /* name */
1340 FALSE, /* partial_inplace */
1341 0, /* src_mask */
1342 MINUS_ONE, /* dst_mask */
1343 FALSE), /* pcrel_offset */
1344
1345 HOWTO (R_MIPS_TLS_DTPREL64, /* type */
1346 0, /* rightshift */
1347 4, /* size (0 = byte, 1 = short, 2 = long) */
1348 64, /* bitsize */
1349 FALSE, /* pc_relative */
1350 0, /* bitpos */
1351 complain_overflow_dont, /* complain_on_overflow */
1352 _bfd_mips_elf_generic_reloc, /* special_function */
1353 "R_MIPS_TLS_DTPREL64", /* name */
1354 FALSE, /* partial_inplace */
1355 0, /* src_mask */
1356 MINUS_ONE, /* dst_mask */
1357 FALSE), /* pcrel_offset */
1358
1359 /* TLS general dynamic variable reference. */
1360 HOWTO (R_MIPS_TLS_GD, /* type */
1361 0, /* rightshift */
1362 2, /* size (0 = byte, 1 = short, 2 = long) */
1363 16, /* bitsize */
1364 FALSE, /* pc_relative */
1365 0, /* bitpos */
1366 complain_overflow_signed, /* complain_on_overflow */
1367 _bfd_mips_elf_generic_reloc, /* special_function */
1368 "R_MIPS_TLS_GD", /* name */
1369 FALSE, /* partial_inplace */
1370 0, /* src_mask */
1371 0x0000ffff, /* dst_mask */
1372 FALSE), /* pcrel_offset */
1373
1374 /* TLS local dynamic variable reference. */
1375 HOWTO (R_MIPS_TLS_LDM, /* type */
1376 0, /* rightshift */
1377 2, /* size (0 = byte, 1 = short, 2 = long) */
1378 16, /* bitsize */
1379 FALSE, /* pc_relative */
1380 0, /* bitpos */
1381 complain_overflow_signed, /* complain_on_overflow */
1382 _bfd_mips_elf_generic_reloc, /* special_function */
1383 "R_MIPS_TLS_LDM", /* name */
1384 FALSE, /* partial_inplace */
1385 0, /* src_mask */
1386 0x0000ffff, /* dst_mask */
1387 FALSE), /* pcrel_offset */
1388
1389 /* TLS local dynamic offset. */
1390 HOWTO (R_MIPS_TLS_DTPREL_HI16, /* type */
1391 0, /* rightshift */
1392 2, /* size (0 = byte, 1 = short, 2 = long) */
1393 16, /* bitsize */
1394 FALSE, /* pc_relative */
1395 0, /* bitpos */
1396 complain_overflow_signed, /* complain_on_overflow */
1397 _bfd_mips_elf_generic_reloc, /* special_function */
1398 "R_MIPS_TLS_DTPREL_HI16", /* name */
1399 FALSE, /* partial_inplace */
1400 0, /* src_mask */
1401 0x0000ffff, /* dst_mask */
1402 FALSE), /* pcrel_offset */
1403
1404 /* TLS local dynamic offset. */
1405 HOWTO (R_MIPS_TLS_DTPREL_LO16, /* type */
1406 0, /* rightshift */
1407 2, /* size (0 = byte, 1 = short, 2 = long) */
1408 16, /* bitsize */
1409 FALSE, /* pc_relative */
1410 0, /* bitpos */
1411 complain_overflow_signed, /* complain_on_overflow */
1412 _bfd_mips_elf_generic_reloc, /* special_function */
1413 "R_MIPS_TLS_DTPREL_LO16", /* name */
1414 FALSE, /* partial_inplace */
1415 0, /* src_mask */
1416 0x0000ffff, /* dst_mask */
1417 FALSE), /* pcrel_offset */
1418
1419 /* TLS thread pointer offset. */
1420 HOWTO (R_MIPS_TLS_GOTTPREL, /* type */
1421 0, /* rightshift */
1422 2, /* size (0 = byte, 1 = short, 2 = long) */
1423 16, /* bitsize */
1424 FALSE, /* pc_relative */
1425 0, /* bitpos */
1426 complain_overflow_signed, /* complain_on_overflow */
1427 _bfd_mips_elf_generic_reloc, /* special_function */
1428 "R_MIPS_TLS_GOTTPREL", /* name */
1429 FALSE, /* partial_inplace */
1430 0, /* src_mask */
1431 0x0000ffff, /* dst_mask */
1432 FALSE), /* pcrel_offset */
1433
1434 /* TLS IE dynamic relocations. */
1435 EMPTY_HOWTO (R_MIPS_TLS_TPREL32),
1436
1437 HOWTO (R_MIPS_TLS_TPREL64, /* type */
1438 0, /* rightshift */
1439 4, /* size (0 = byte, 1 = short, 2 = long) */
1440 64, /* bitsize */
1441 FALSE, /* pc_relative */
1442 0, /* bitpos */
1443 complain_overflow_dont, /* complain_on_overflow */
1444 _bfd_mips_elf_generic_reloc, /* special_function */
1445 "R_MIPS_TLS_TPREL64", /* name */
1446 FALSE, /* partial_inplace */
1447 0, /* src_mask */
1448 MINUS_ONE, /* dst_mask */
1449 FALSE), /* pcrel_offset */
1450
1451 /* TLS thread pointer offset. */
1452 HOWTO (R_MIPS_TLS_TPREL_HI16, /* type */
1453 0, /* rightshift */
1454 2, /* size (0 = byte, 1 = short, 2 = long) */
1455 16, /* bitsize */
1456 FALSE, /* pc_relative */
1457 0, /* bitpos */
1458 complain_overflow_signed, /* complain_on_overflow */
1459 _bfd_mips_elf_generic_reloc, /* special_function */
1460 "R_MIPS_TLS_TPREL_HI16", /* name */
1461 FALSE, /* partial_inplace */
1462 0, /* src_mask */
1463 0x0000ffff, /* dst_mask */
1464 FALSE), /* pcrel_offset */
1465
1466 /* TLS thread pointer offset. */
1467 HOWTO (R_MIPS_TLS_TPREL_LO16, /* type */
1468 0, /* rightshift */
1469 2, /* size (0 = byte, 1 = short, 2 = long) */
1470 16, /* bitsize */
1471 FALSE, /* pc_relative */
1472 0, /* bitpos */
1473 complain_overflow_signed, /* complain_on_overflow */
1474 _bfd_mips_elf_generic_reloc, /* special_function */
1475 "R_MIPS_TLS_TPREL_LO16", /* name */
1476 FALSE, /* partial_inplace */
1477 0, /* src_mask */
1478 0x0000ffff, /* dst_mask */
1479 FALSE), /* pcrel_offset */
1480
1481 /* 32 bit relocation with no addend. */
1482 HOWTO (R_MIPS_GLOB_DAT, /* type */
1483 0, /* rightshift */
1484 2, /* size (0 = byte, 1 = short, 2 = long) */
1485 32, /* bitsize */
1486 FALSE, /* pc_relative */
1487 0, /* bitpos */
1488 complain_overflow_dont, /* complain_on_overflow */
1489 _bfd_mips_elf_generic_reloc, /* special_function */
1490 "R_MIPS_GLOB_DAT", /* name */
1491 FALSE, /* partial_inplace */
1492 0x0, /* src_mask */
1493 0xffffffff, /* dst_mask */
1494 FALSE), /* pcrel_offset */
1495 };
1496
1497 static reloc_howto_type mips16_elf64_howto_table_rel[] =
1498 {
1499 /* The reloc used for the mips16 jump instruction. */
1500 HOWTO (R_MIPS16_26, /* type */
1501 2, /* rightshift */
1502 2, /* size (0 = byte, 1 = short, 2 = long) */
1503 26, /* bitsize */
1504 FALSE, /* pc_relative */
1505 0, /* bitpos */
1506 complain_overflow_dont, /* complain_on_overflow */
1507 /* This needs complex overflow
1508 detection, because the upper four
1509 bits must match the PC. */
1510 _bfd_mips_elf_generic_reloc, /* special_function */
1511 "R_MIPS16_26", /* name */
1512 TRUE, /* partial_inplace */
1513 0x3ffffff, /* src_mask */
1514 0x3ffffff, /* dst_mask */
1515 FALSE), /* pcrel_offset */
1516
1517 /* The reloc used for the mips16 gprel instruction. */
1518 HOWTO (R_MIPS16_GPREL, /* type */
1519 0, /* rightshift */
1520 2, /* size (0 = byte, 1 = short, 2 = long) */
1521 16, /* bitsize */
1522 FALSE, /* pc_relative */
1523 0, /* bitpos */
1524 complain_overflow_signed, /* complain_on_overflow */
1525 mips16_gprel_reloc, /* special_function */
1526 "R_MIPS16_GPREL", /* name */
1527 TRUE, /* partial_inplace */
1528 0x0000ffff, /* src_mask */
1529 0x0000ffff, /* dst_mask */
1530 FALSE), /* pcrel_offset */
1531
1532 /* A MIPS16 reference to the global offset table. */
1533 HOWTO (R_MIPS16_GOT16, /* type */
1534 0, /* rightshift */
1535 2, /* size (0 = byte, 1 = short, 2 = long) */
1536 16, /* bitsize */
1537 FALSE, /* pc_relative */
1538 0, /* bitpos */
1539 complain_overflow_dont, /* complain_on_overflow */
1540 _bfd_mips_elf_got16_reloc, /* special_function */
1541 "R_MIPS16_GOT16", /* name */
1542 TRUE, /* partial_inplace */
1543 0x0000ffff, /* src_mask */
1544 0x0000ffff, /* dst_mask */
1545 FALSE), /* pcrel_offset */
1546
1547 /* A MIPS16 call through the global offset table. */
1548 HOWTO (R_MIPS16_CALL16, /* type */
1549 0, /* rightshift */
1550 2, /* size (0 = byte, 1 = short, 2 = long) */
1551 16, /* bitsize */
1552 FALSE, /* pc_relative */
1553 0, /* bitpos */
1554 complain_overflow_dont, /* complain_on_overflow */
1555 _bfd_mips_elf_generic_reloc, /* special_function */
1556 "R_MIPS16_CALL16", /* name */
1557 TRUE, /* partial_inplace */
1558 0x0000ffff, /* src_mask */
1559 0x0000ffff, /* dst_mask */
1560 FALSE), /* pcrel_offset */
1561
1562 /* MIPS16 high 16 bits of symbol value. */
1563 HOWTO (R_MIPS16_HI16, /* type */
1564 16, /* rightshift */
1565 2, /* size (0 = byte, 1 = short, 2 = long) */
1566 16, /* bitsize */
1567 FALSE, /* pc_relative */
1568 0, /* bitpos */
1569 complain_overflow_dont, /* complain_on_overflow */
1570 _bfd_mips_elf_hi16_reloc, /* special_function */
1571 "R_MIPS16_HI16", /* name */
1572 TRUE, /* partial_inplace */
1573 0x0000ffff, /* src_mask */
1574 0x0000ffff, /* dst_mask */
1575 FALSE), /* pcrel_offset */
1576
1577 /* MIPS16 low 16 bits of symbol value. */
1578 HOWTO (R_MIPS16_LO16, /* type */
1579 0, /* rightshift */
1580 2, /* size (0 = byte, 1 = short, 2 = long) */
1581 16, /* bitsize */
1582 FALSE, /* pc_relative */
1583 0, /* bitpos */
1584 complain_overflow_dont, /* complain_on_overflow */
1585 _bfd_mips_elf_lo16_reloc, /* special_function */
1586 "R_MIPS16_LO16", /* name */
1587 TRUE, /* partial_inplace */
1588 0x0000ffff, /* src_mask */
1589 0x0000ffff, /* dst_mask */
1590 FALSE), /* pcrel_offset */
1591
1592 /* MIPS16 TLS general dynamic variable reference. */
1593 HOWTO (R_MIPS16_TLS_GD, /* type */
1594 0, /* rightshift */
1595 2, /* size (0 = byte, 1 = short, 2 = long) */
1596 16, /* bitsize */
1597 FALSE, /* pc_relative */
1598 0, /* bitpos */
1599 complain_overflow_signed, /* complain_on_overflow */
1600 _bfd_mips_elf_generic_reloc, /* special_function */
1601 "R_MIPS16_TLS_GD", /* name */
1602 TRUE, /* partial_inplace */
1603 0x0000ffff, /* src_mask */
1604 0x0000ffff, /* dst_mask */
1605 FALSE), /* pcrel_offset */
1606
1607 /* MIPS16 TLS local dynamic variable reference. */
1608 HOWTO (R_MIPS16_TLS_LDM, /* type */
1609 0, /* rightshift */
1610 2, /* size (0 = byte, 1 = short, 2 = long) */
1611 16, /* bitsize */
1612 FALSE, /* pc_relative */
1613 0, /* bitpos */
1614 complain_overflow_signed, /* complain_on_overflow */
1615 _bfd_mips_elf_generic_reloc, /* special_function */
1616 "R_MIPS16_TLS_LDM", /* name */
1617 TRUE, /* partial_inplace */
1618 0x0000ffff, /* src_mask */
1619 0x0000ffff, /* dst_mask */
1620 FALSE), /* pcrel_offset */
1621
1622 /* MIPS16 TLS local dynamic offset. */
1623 HOWTO (R_MIPS16_TLS_DTPREL_HI16, /* type */
1624 0, /* rightshift */
1625 2, /* size (0 = byte, 1 = short, 2 = long) */
1626 16, /* bitsize */
1627 FALSE, /* pc_relative */
1628 0, /* bitpos */
1629 complain_overflow_signed, /* complain_on_overflow */
1630 _bfd_mips_elf_generic_reloc, /* special_function */
1631 "R_MIPS16_TLS_DTPREL_HI16", /* name */
1632 TRUE, /* partial_inplace */
1633 0x0000ffff, /* src_mask */
1634 0x0000ffff, /* dst_mask */
1635 FALSE), /* pcrel_offset */
1636
1637 /* MIPS16 TLS local dynamic offset. */
1638 HOWTO (R_MIPS16_TLS_DTPREL_LO16, /* type */
1639 0, /* rightshift */
1640 2, /* size (0 = byte, 1 = short, 2 = long) */
1641 16, /* bitsize */
1642 FALSE, /* pc_relative */
1643 0, /* bitpos */
1644 complain_overflow_signed, /* complain_on_overflow */
1645 _bfd_mips_elf_generic_reloc, /* special_function */
1646 "R_MIPS16_TLS_DTPREL_LO16", /* name */
1647 TRUE, /* partial_inplace */
1648 0x0000ffff, /* src_mask */
1649 0x0000ffff, /* dst_mask */
1650 FALSE), /* pcrel_offset */
1651
1652 /* MIPS16 TLS thread pointer offset. */
1653 HOWTO (R_MIPS16_TLS_GOTTPREL, /* type */
1654 0, /* rightshift */
1655 2, /* size (0 = byte, 1 = short, 2 = long) */
1656 16, /* bitsize */
1657 FALSE, /* pc_relative */
1658 0, /* bitpos */
1659 complain_overflow_signed, /* complain_on_overflow */
1660 _bfd_mips_elf_generic_reloc, /* special_function */
1661 "R_MIPS16_TLS_GOTTPREL", /* name */
1662 TRUE, /* partial_inplace */
1663 0x0000ffff, /* src_mask */
1664 0x0000ffff, /* dst_mask */
1665 FALSE), /* pcrel_offset */
1666
1667 /* MIPS16 TLS thread pointer offset. */
1668 HOWTO (R_MIPS16_TLS_TPREL_HI16, /* type */
1669 0, /* rightshift */
1670 2, /* size (0 = byte, 1 = short, 2 = long) */
1671 16, /* bitsize */
1672 FALSE, /* pc_relative */
1673 0, /* bitpos */
1674 complain_overflow_signed, /* complain_on_overflow */
1675 _bfd_mips_elf_generic_reloc, /* special_function */
1676 "R_MIPS16_TLS_TPREL_HI16", /* name */
1677 TRUE, /* partial_inplace */
1678 0x0000ffff, /* src_mask */
1679 0x0000ffff, /* dst_mask */
1680 FALSE), /* pcrel_offset */
1681
1682 /* MIPS16 TLS thread pointer offset. */
1683 HOWTO (R_MIPS16_TLS_TPREL_LO16, /* type */
1684 0, /* rightshift */
1685 2, /* size (0 = byte, 1 = short, 2 = long) */
1686 16, /* bitsize */
1687 FALSE, /* pc_relative */
1688 0, /* bitpos */
1689 complain_overflow_signed, /* complain_on_overflow */
1690 _bfd_mips_elf_generic_reloc, /* special_function */
1691 "R_MIPS16_TLS_TPREL_LO16", /* name */
1692 TRUE, /* partial_inplace */
1693 0x0000ffff, /* src_mask */
1694 0x0000ffff, /* dst_mask */
1695 FALSE), /* pcrel_offset */
1696 };
1697
1698 static reloc_howto_type mips16_elf64_howto_table_rela[] =
1699 {
1700 /* The reloc used for the mips16 jump instruction. */
1701 HOWTO (R_MIPS16_26, /* type */
1702 2, /* rightshift */
1703 2, /* size (0 = byte, 1 = short, 2 = long) */
1704 26, /* bitsize */
1705 FALSE, /* pc_relative */
1706 0, /* bitpos */
1707 complain_overflow_dont, /* complain_on_overflow */
1708 /* This needs complex overflow
1709 detection, because the upper four
1710 bits must match the PC. */
1711 _bfd_mips_elf_generic_reloc, /* special_function */
1712 "R_MIPS16_26", /* name */
1713 FALSE, /* partial_inplace */
1714 0, /* src_mask */
1715 0x3ffffff, /* dst_mask */
1716 FALSE), /* pcrel_offset */
1717
1718 /* The reloc used for the mips16 gprel instruction. */
1719 HOWTO (R_MIPS16_GPREL, /* type */
1720 0, /* rightshift */
1721 2, /* size (0 = byte, 1 = short, 2 = long) */
1722 16, /* bitsize */
1723 FALSE, /* pc_relative */
1724 0, /* bitpos */
1725 complain_overflow_signed, /* complain_on_overflow */
1726 mips16_gprel_reloc, /* special_function */
1727 "R_MIPS16_GPREL", /* name */
1728 FALSE, /* partial_inplace */
1729 0, /* src_mask */
1730 0x0000ffff, /* dst_mask */
1731 FALSE), /* pcrel_offset */
1732
1733 /* A MIPS16 reference to the global offset table. */
1734 HOWTO (R_MIPS16_GOT16, /* type */
1735 0, /* rightshift */
1736 2, /* size (0 = byte, 1 = short, 2 = long) */
1737 16, /* bitsize */
1738 FALSE, /* pc_relative */
1739 0, /* bitpos */
1740 complain_overflow_dont, /* complain_on_overflow */
1741 _bfd_mips_elf_got16_reloc, /* special_function */
1742 "R_MIPS16_GOT16", /* name */
1743 FALSE, /* partial_inplace */
1744 0, /* src_mask */
1745 0x0000ffff, /* dst_mask */
1746 FALSE), /* pcrel_offset */
1747
1748 /* A MIPS16 call through the global offset table. */
1749 HOWTO (R_MIPS16_CALL16, /* type */
1750 0, /* rightshift */
1751 2, /* size (0 = byte, 1 = short, 2 = long) */
1752 16, /* bitsize */
1753 FALSE, /* pc_relative */
1754 0, /* bitpos */
1755 complain_overflow_dont, /* complain_on_overflow */
1756 _bfd_mips_elf_generic_reloc, /* special_function */
1757 "R_MIPS16_CALL16", /* name */
1758 FALSE, /* partial_inplace */
1759 0, /* src_mask */
1760 0x0000ffff, /* dst_mask */
1761 FALSE), /* pcrel_offset */
1762
1763 /* MIPS16 high 16 bits of symbol value. */
1764 HOWTO (R_MIPS16_HI16, /* type */
1765 16, /* rightshift */
1766 2, /* size (0 = byte, 1 = short, 2 = long) */
1767 16, /* bitsize */
1768 FALSE, /* pc_relative */
1769 0, /* bitpos */
1770 complain_overflow_dont, /* complain_on_overflow */
1771 _bfd_mips_elf_hi16_reloc, /* special_function */
1772 "R_MIPS16_HI16", /* name */
1773 FALSE, /* partial_inplace */
1774 0, /* src_mask */
1775 0x0000ffff, /* dst_mask */
1776 FALSE), /* pcrel_offset */
1777
1778 /* MIPS16 low 16 bits of symbol value. */
1779 HOWTO (R_MIPS16_LO16, /* type */
1780 0, /* rightshift */
1781 2, /* size (0 = byte, 1 = short, 2 = long) */
1782 16, /* bitsize */
1783 FALSE, /* pc_relative */
1784 0, /* bitpos */
1785 complain_overflow_dont, /* complain_on_overflow */
1786 _bfd_mips_elf_lo16_reloc, /* special_function */
1787 "R_MIPS16_LO16", /* name */
1788 FALSE, /* partial_inplace */
1789 0, /* src_mask */
1790 0x0000ffff, /* dst_mask */
1791 FALSE), /* pcrel_offset */
1792
1793 /* MIPS16 TLS general dynamic variable reference. */
1794 HOWTO (R_MIPS16_TLS_GD, /* type */
1795 0, /* rightshift */
1796 2, /* size (0 = byte, 1 = short, 2 = long) */
1797 16, /* bitsize */
1798 FALSE, /* pc_relative */
1799 0, /* bitpos */
1800 complain_overflow_signed, /* complain_on_overflow */
1801 _bfd_mips_elf_generic_reloc, /* special_function */
1802 "R_MIPS16_TLS_GD", /* name */
1803 FALSE, /* partial_inplace */
1804 0, /* src_mask */
1805 0x0000ffff, /* dst_mask */
1806 FALSE), /* pcrel_offset */
1807
1808 /* MIPS16 TLS local dynamic variable reference. */
1809 HOWTO (R_MIPS16_TLS_LDM, /* type */
1810 0, /* rightshift */
1811 2, /* size (0 = byte, 1 = short, 2 = long) */
1812 16, /* bitsize */
1813 FALSE, /* pc_relative */
1814 0, /* bitpos */
1815 complain_overflow_signed, /* complain_on_overflow */
1816 _bfd_mips_elf_generic_reloc, /* special_function */
1817 "R_MIPS16_TLS_LDM", /* name */
1818 FALSE, /* partial_inplace */
1819 0, /* src_mask */
1820 0x0000ffff, /* dst_mask */
1821 FALSE), /* pcrel_offset */
1822
1823 /* MIPS16 TLS local dynamic offset. */
1824 HOWTO (R_MIPS16_TLS_DTPREL_HI16, /* type */
1825 0, /* rightshift */
1826 2, /* size (0 = byte, 1 = short, 2 = long) */
1827 16, /* bitsize */
1828 FALSE, /* pc_relative */
1829 0, /* bitpos */
1830 complain_overflow_signed, /* complain_on_overflow */
1831 _bfd_mips_elf_generic_reloc, /* special_function */
1832 "R_MIPS16_TLS_DTPREL_HI16", /* name */
1833 FALSE, /* partial_inplace */
1834 0, /* src_mask */
1835 0x0000ffff, /* dst_mask */
1836 FALSE), /* pcrel_offset */
1837
1838 /* MIPS16 TLS local dynamic offset. */
1839 HOWTO (R_MIPS16_TLS_DTPREL_LO16, /* type */
1840 0, /* rightshift */
1841 2, /* size (0 = byte, 1 = short, 2 = long) */
1842 16, /* bitsize */
1843 FALSE, /* pc_relative */
1844 0, /* bitpos */
1845 complain_overflow_signed, /* complain_on_overflow */
1846 _bfd_mips_elf_generic_reloc, /* special_function */
1847 "R_MIPS16_TLS_DTPREL_LO16", /* name */
1848 FALSE, /* partial_inplace */
1849 0, /* src_mask */
1850 0x0000ffff, /* dst_mask */
1851 FALSE), /* pcrel_offset */
1852
1853 /* MIPS16 TLS thread pointer offset. */
1854 HOWTO (R_MIPS16_TLS_GOTTPREL, /* type */
1855 0, /* rightshift */
1856 2, /* size (0 = byte, 1 = short, 2 = long) */
1857 16, /* bitsize */
1858 FALSE, /* pc_relative */
1859 0, /* bitpos */
1860 complain_overflow_signed, /* complain_on_overflow */
1861 _bfd_mips_elf_generic_reloc, /* special_function */
1862 "R_MIPS16_TLS_GOTTPREL", /* name */
1863 FALSE, /* partial_inplace */
1864 0, /* src_mask */
1865 0x0000ffff, /* dst_mask */
1866 FALSE), /* pcrel_offset */
1867
1868 /* MIPS16 TLS thread pointer offset. */
1869 HOWTO (R_MIPS16_TLS_TPREL_HI16, /* type */
1870 0, /* rightshift */
1871 2, /* size (0 = byte, 1 = short, 2 = long) */
1872 16, /* bitsize */
1873 FALSE, /* pc_relative */
1874 0, /* bitpos */
1875 complain_overflow_signed, /* complain_on_overflow */
1876 _bfd_mips_elf_generic_reloc, /* special_function */
1877 "R_MIPS16_TLS_TPREL_HI16", /* name */
1878 FALSE, /* partial_inplace */
1879 0, /* src_mask */
1880 0x0000ffff, /* dst_mask */
1881 FALSE), /* pcrel_offset */
1882
1883 /* MIPS16 TLS thread pointer offset. */
1884 HOWTO (R_MIPS16_TLS_TPREL_LO16, /* type */
1885 0, /* rightshift */
1886 2, /* size (0 = byte, 1 = short, 2 = long) */
1887 16, /* bitsize */
1888 FALSE, /* pc_relative */
1889 0, /* bitpos */
1890 complain_overflow_signed, /* complain_on_overflow */
1891 _bfd_mips_elf_generic_reloc, /* special_function */
1892 "R_MIPS16_TLS_TPREL_LO16", /* name */
1893 FALSE, /* partial_inplace */
1894 0, /* src_mask */
1895 0x0000ffff, /* dst_mask */
1896 FALSE), /* pcrel_offset */
1897 };
1898
1899 static reloc_howto_type micromips_elf64_howto_table_rel[] =
1900 {
1901 EMPTY_HOWTO (130),
1902 EMPTY_HOWTO (131),
1903 EMPTY_HOWTO (132),
1904
1905 /* 26 bit jump address. */
1906 HOWTO (R_MICROMIPS_26_S1, /* type */
1907 1, /* rightshift */
1908 2, /* size (0 = byte, 1 = short, 2 = long) */
1909 26, /* bitsize */
1910 FALSE, /* pc_relative */
1911 0, /* bitpos */
1912 complain_overflow_dont, /* complain_on_overflow */
1913 /* This needs complex overflow
1914 detection, because the upper four
1915 bits must match the PC. */
1916 _bfd_mips_elf_generic_reloc, /* special_function */
1917 "R_MICROMIPS_26_S1", /* name */
1918 TRUE, /* partial_inplace */
1919 0x3ffffff, /* src_mask */
1920 0x3ffffff, /* dst_mask */
1921 FALSE), /* pcrel_offset */
1922
1923 /* High 16 bits of symbol value. */
1924 HOWTO (R_MICROMIPS_HI16, /* type */
1925 16, /* rightshift */
1926 2, /* size (0 = byte, 1 = short, 2 = long) */
1927 16, /* bitsize */
1928 FALSE, /* pc_relative */
1929 0, /* bitpos */
1930 complain_overflow_dont, /* complain_on_overflow */
1931 _bfd_mips_elf_hi16_reloc, /* special_function */
1932 "R_MICROMIPS_HI16", /* name */
1933 TRUE, /* partial_inplace */
1934 0x0000ffff, /* src_mask */
1935 0x0000ffff, /* dst_mask */
1936 FALSE), /* pcrel_offset */
1937
1938 /* Low 16 bits of symbol value. */
1939 HOWTO (R_MICROMIPS_LO16, /* type */
1940 0, /* rightshift */
1941 2, /* size (0 = byte, 1 = short, 2 = long) */
1942 16, /* bitsize */
1943 FALSE, /* pc_relative */
1944 0, /* bitpos */
1945 complain_overflow_dont, /* complain_on_overflow */
1946 _bfd_mips_elf_lo16_reloc, /* special_function */
1947 "R_MICROMIPS_LO16", /* name */
1948 TRUE, /* partial_inplace */
1949 0x0000ffff, /* src_mask */
1950 0x0000ffff, /* dst_mask */
1951 FALSE), /* pcrel_offset */
1952
1953 /* GP relative reference. */
1954 HOWTO (R_MICROMIPS_GPREL16, /* type */
1955 0, /* rightshift */
1956 2, /* size (0 = byte, 1 = short, 2 = long) */
1957 16, /* bitsize */
1958 FALSE, /* pc_relative */
1959 0, /* bitpos */
1960 complain_overflow_signed, /* complain_on_overflow */
1961 _bfd_mips_elf32_gprel16_reloc, /* special_function */
1962 "R_MICROMIPS_GPREL16", /* name */
1963 TRUE, /* partial_inplace */
1964 0x0000ffff, /* src_mask */
1965 0x0000ffff, /* dst_mask */
1966 FALSE), /* pcrel_offset */
1967
1968 /* Reference to literal section. */
1969 HOWTO (R_MICROMIPS_LITERAL, /* type */
1970 0, /* rightshift */
1971 2, /* size (0 = byte, 1 = short, 2 = long) */
1972 16, /* bitsize */
1973 FALSE, /* pc_relative */
1974 0, /* bitpos */
1975 complain_overflow_signed, /* complain_on_overflow */
1976 _bfd_mips_elf32_gprel16_reloc, /* special_function */
1977 "R_MICROMIPS_LITERAL", /* name */
1978 TRUE, /* partial_inplace */
1979 0x0000ffff, /* src_mask */
1980 0x0000ffff, /* dst_mask */
1981 FALSE), /* pcrel_offset */
1982
1983 /* Reference to global offset table. */
1984 HOWTO (R_MICROMIPS_GOT16, /* type */
1985 0, /* rightshift */
1986 2, /* size (0 = byte, 1 = short, 2 = long) */
1987 16, /* bitsize */
1988 FALSE, /* pc_relative */
1989 0, /* bitpos */
1990 complain_overflow_signed, /* complain_on_overflow */
1991 _bfd_mips_elf_got16_reloc, /* special_function */
1992 "R_MICROMIPS_GOT16", /* name */
1993 TRUE, /* partial_inplace */
1994 0x0000ffff, /* src_mask */
1995 0x0000ffff, /* dst_mask */
1996 FALSE), /* pcrel_offset */
1997
1998 /* This is for microMIPS branches. */
1999 HOWTO (R_MICROMIPS_PC7_S1, /* type */
2000 1, /* rightshift */
2001 1, /* size (0 = byte, 1 = short, 2 = long) */
2002 7, /* bitsize */
2003 TRUE, /* pc_relative */
2004 0, /* bitpos */
2005 complain_overflow_signed, /* complain_on_overflow */
2006 _bfd_mips_elf_generic_reloc, /* special_function */
2007 "R_MICROMIPS_PC7_S1", /* name */
2008 TRUE, /* partial_inplace */
2009 0x0000007f, /* src_mask */
2010 0x0000007f, /* dst_mask */
2011 TRUE), /* pcrel_offset */
2012
2013 HOWTO (R_MICROMIPS_PC10_S1, /* type */
2014 1, /* rightshift */
2015 1, /* size (0 = byte, 1 = short, 2 = long) */
2016 10, /* bitsize */
2017 TRUE, /* pc_relative */
2018 0, /* bitpos */
2019 complain_overflow_signed, /* complain_on_overflow */
2020 _bfd_mips_elf_generic_reloc, /* special_function */
2021 "R_MICROMIPS_PC10_S1", /* name */
2022 TRUE, /* partial_inplace */
2023 0x000003ff, /* src_mask */
2024 0x000003ff, /* dst_mask */
2025 TRUE), /* pcrel_offset */
2026
2027 HOWTO (R_MICROMIPS_PC16_S1, /* type */
2028 1, /* rightshift */
2029 2, /* size (0 = byte, 1 = short, 2 = long) */
2030 16, /* bitsize */
2031 TRUE, /* pc_relative */
2032 0, /* bitpos */
2033 complain_overflow_signed, /* complain_on_overflow */
2034 _bfd_mips_elf_generic_reloc, /* special_function */
2035 "R_MICROMIPS_PC16_S1", /* name */
2036 TRUE, /* partial_inplace */
2037 0x0000ffff, /* src_mask */
2038 0x0000ffff, /* dst_mask */
2039 TRUE), /* pcrel_offset */
2040
2041 /* 16 bit call through global offset table. */
2042 HOWTO (R_MICROMIPS_CALL16, /* type */
2043 0, /* rightshift */
2044 2, /* size (0 = byte, 1 = short, 2 = long) */
2045 16, /* bitsize */
2046 FALSE, /* pc_relative */
2047 0, /* bitpos */
2048 complain_overflow_signed, /* complain_on_overflow */
2049 _bfd_mips_elf_generic_reloc, /* special_function */
2050 "R_MICROMIPS_CALL16", /* name */
2051 TRUE, /* partial_inplace */
2052 0x0000ffff, /* src_mask */
2053 0x0000ffff, /* dst_mask */
2054 FALSE), /* pcrel_offset */
2055
2056 EMPTY_HOWTO (143),
2057 EMPTY_HOWTO (144),
2058
2059 /* Displacement in the global offset table. */
2060 HOWTO (R_MICROMIPS_GOT_DISP, /* type */
2061 0, /* rightshift */
2062 2, /* size (0 = byte, 1 = short, 2 = long) */
2063 16, /* bitsize */
2064 FALSE, /* pc_relative */
2065 0, /* bitpos */
2066 complain_overflow_signed, /* complain_on_overflow */
2067 _bfd_mips_elf_generic_reloc, /* special_function */
2068 "R_MICROMIPS_GOT_DISP",/* name */
2069 TRUE, /* partial_inplace */
2070 0x0000ffff, /* src_mask */
2071 0x0000ffff, /* dst_mask */
2072 FALSE), /* pcrel_offset */
2073
2074 /* Displacement to page pointer in the global offset table. */
2075 HOWTO (R_MICROMIPS_GOT_PAGE, /* type */
2076 0, /* rightshift */
2077 2, /* size (0 = byte, 1 = short, 2 = long) */
2078 16, /* bitsize */
2079 FALSE, /* pc_relative */
2080 0, /* bitpos */
2081 complain_overflow_signed, /* complain_on_overflow */
2082 _bfd_mips_elf_generic_reloc, /* special_function */
2083 "R_MICROMIPS_GOT_PAGE",/* name */
2084 TRUE, /* partial_inplace */
2085 0x0000ffff, /* src_mask */
2086 0x0000ffff, /* dst_mask */
2087 FALSE), /* pcrel_offset */
2088
2089 /* Offset from page pointer in the global offset table. */
2090 HOWTO (R_MICROMIPS_GOT_OFST, /* type */
2091 0, /* rightshift */
2092 2, /* size (0 = byte, 1 = short, 2 = long) */
2093 16, /* bitsize */
2094 FALSE, /* pc_relative */
2095 0, /* bitpos */
2096 complain_overflow_signed, /* complain_on_overflow */
2097 _bfd_mips_elf_generic_reloc, /* special_function */
2098 "R_MICROMIPS_GOT_OFST",/* name */
2099 TRUE, /* partial_inplace */
2100 0x0000ffff, /* src_mask */
2101 0x0000ffff, /* dst_mask */
2102 FALSE), /* pcrel_offset */
2103
2104 /* High 16 bits of displacement in global offset table. */
2105 HOWTO (R_MICROMIPS_GOT_HI16, /* type */
2106 0, /* rightshift */
2107 2, /* size (0 = byte, 1 = short, 2 = long) */
2108 16, /* bitsize */
2109 FALSE, /* pc_relative */
2110 0, /* bitpos */
2111 complain_overflow_dont, /* complain_on_overflow */
2112 _bfd_mips_elf_generic_reloc, /* special_function */
2113 "R_MICROMIPS_GOT_HI16",/* name */
2114 TRUE, /* partial_inplace */
2115 0x0000ffff, /* src_mask */
2116 0x0000ffff, /* dst_mask */
2117 FALSE), /* pcrel_offset */
2118
2119 /* Low 16 bits of displacement in global offset table. */
2120 HOWTO (R_MICROMIPS_GOT_LO16, /* type */
2121 0, /* rightshift */
2122 2, /* size (0 = byte, 1 = short, 2 = long) */
2123 16, /* bitsize */
2124 FALSE, /* pc_relative */
2125 0, /* bitpos */
2126 complain_overflow_dont, /* complain_on_overflow */
2127 _bfd_mips_elf_generic_reloc, /* special_function */
2128 "R_MICROMIPS_GOT_LO16",/* name */
2129 TRUE, /* partial_inplace */
2130 0x0000ffff, /* src_mask */
2131 0x0000ffff, /* dst_mask */
2132 FALSE), /* pcrel_offset */
2133
2134 /* 64 bit subtraction. Used in the N32 ABI. */
2135 HOWTO (R_MICROMIPS_SUB, /* type */
2136 0, /* rightshift */
2137 4, /* size (0 = byte, 1 = short, 2 = long) */
2138 64, /* bitsize */
2139 FALSE, /* pc_relative */
2140 0, /* bitpos */
2141 complain_overflow_dont, /* complain_on_overflow */
2142 _bfd_mips_elf_generic_reloc, /* special_function */
2143 "R_MICROMIPS_SUB", /* name */
2144 TRUE, /* partial_inplace */
2145 MINUS_ONE, /* src_mask */
2146 MINUS_ONE, /* dst_mask */
2147 FALSE), /* pcrel_offset */
2148
2149 /* We don't support these for REL relocations, because it means building
2150 the addend from a R_MICROMIPS_HIGHEST/R_MICROMIPS_HIGHER/
2151 R_MICROMIPS_HI16/R_MICROMIPS_LO16 sequence with varying ordering,
2152 using fallable heuristics. */
2153 EMPTY_HOWTO (R_MICROMIPS_HIGHER),
2154 EMPTY_HOWTO (R_MICROMIPS_HIGHEST),
2155
2156 /* High 16 bits of displacement in global offset table. */
2157 HOWTO (R_MICROMIPS_CALL_HI16, /* type */
2158 0, /* rightshift */
2159 2, /* size (0 = byte, 1 = short, 2 = long) */
2160 16, /* bitsize */
2161 FALSE, /* pc_relative */
2162 0, /* bitpos */
2163 complain_overflow_dont, /* complain_on_overflow */
2164 _bfd_mips_elf_generic_reloc, /* special_function */
2165 "R_MICROMIPS_CALL_HI16",/* name */
2166 TRUE, /* partial_inplace */
2167 0x0000ffff, /* src_mask */
2168 0x0000ffff, /* dst_mask */
2169 FALSE), /* pcrel_offset */
2170
2171 /* Low 16 bits of displacement in global offset table. */
2172 HOWTO (R_MICROMIPS_CALL_LO16, /* type */
2173 0, /* rightshift */
2174 2, /* size (0 = byte, 1 = short, 2 = long) */
2175 16, /* bitsize */
2176 FALSE, /* pc_relative */
2177 0, /* bitpos */
2178 complain_overflow_dont, /* complain_on_overflow */
2179 _bfd_mips_elf_generic_reloc, /* special_function */
2180 "R_MICROMIPS_CALL_LO16",/* name */
2181 TRUE, /* partial_inplace */
2182 0x0000ffff, /* src_mask */
2183 0x0000ffff, /* dst_mask */
2184 FALSE), /* pcrel_offset */
2185
2186 /* Section displacement. */
2187 HOWTO (R_MICROMIPS_SCN_DISP, /* type */
2188 0, /* rightshift */
2189 2, /* size (0 = byte, 1 = short, 2 = long) */
2190 32, /* bitsize */
2191 FALSE, /* pc_relative */
2192 0, /* bitpos */
2193 complain_overflow_dont, /* complain_on_overflow */
2194 _bfd_mips_elf_generic_reloc, /* special_function */
2195 "R_MICROMIPS_SCN_DISP", /* name */
2196 TRUE, /* partial_inplace */
2197 0xffffffff, /* src_mask */
2198 0xffffffff, /* dst_mask */
2199 FALSE), /* pcrel_offset */
2200
2201 /* Protected jump conversion. This is an optimization hint. No
2202 relocation is required for correctness. */
2203 HOWTO (R_MICROMIPS_JALR, /* type */
2204 0, /* rightshift */
2205 2, /* size (0 = byte, 1 = short, 2 = long) */
2206 32, /* bitsize */
2207 FALSE, /* pc_relative */
2208 0, /* bitpos */
2209 complain_overflow_dont, /* complain_on_overflow */
2210 _bfd_mips_elf_generic_reloc, /* special_function */
2211 "R_MICROMIPS_JALR", /* name */
2212 FALSE, /* partial_inplace */
2213 0, /* src_mask */
2214 0x00000000, /* dst_mask */
2215 FALSE), /* pcrel_offset */
2216 };
2217
2218 static reloc_howto_type micromips_elf64_howto_table_rela[] =
2219 {
2220 EMPTY_HOWTO (130),
2221 EMPTY_HOWTO (131),
2222 EMPTY_HOWTO (132),
2223
2224 /* 26 bit jump address. */
2225 HOWTO (R_MICROMIPS_26_S1, /* type */
2226 1, /* rightshift */
2227 2, /* size (0 = byte, 1 = short, 2 = long) */
2228 26, /* bitsize */
2229 FALSE, /* pc_relative */
2230 0, /* bitpos */
2231 complain_overflow_dont, /* complain_on_overflow */
2232 /* This needs complex overflow
2233 detection, because the upper four
2234 bits must match the PC. */
2235 _bfd_mips_elf_generic_reloc, /* special_function */
2236 "R_MICROMIPS_26_S1", /* name */
2237 FALSE, /* partial_inplace */
2238 0, /* src_mask */
2239 0x3ffffff, /* dst_mask */
2240 FALSE), /* pcrel_offset */
2241
2242 /* High 16 bits of symbol value. */
2243 HOWTO (R_MICROMIPS_HI16, /* type */
2244 16, /* rightshift */
2245 2, /* size (0 = byte, 1 = short, 2 = long) */
2246 16, /* bitsize */
2247 FALSE, /* pc_relative */
2248 0, /* bitpos */
2249 complain_overflow_dont, /* complain_on_overflow */
2250 _bfd_mips_elf_hi16_reloc, /* special_function */
2251 "R_MICROMIPS_HI16", /* name */
2252 FALSE, /* partial_inplace */
2253 0, /* src_mask */
2254 0x0000ffff, /* dst_mask */
2255 FALSE), /* pcrel_offset */
2256
2257 /* Low 16 bits of symbol value. */
2258 HOWTO (R_MICROMIPS_LO16, /* type */
2259 0, /* rightshift */
2260 2, /* size (0 = byte, 1 = short, 2 = long) */
2261 16, /* bitsize */
2262 FALSE, /* pc_relative */
2263 0, /* bitpos */
2264 complain_overflow_dont, /* complain_on_overflow */
2265 _bfd_mips_elf_lo16_reloc, /* special_function */
2266 "R_MICROMIPS_LO16", /* name */
2267 FALSE, /* partial_inplace */
2268 0, /* src_mask */
2269 0x0000ffff, /* dst_mask */
2270 FALSE), /* pcrel_offset */
2271
2272 /* GP relative reference. */
2273 HOWTO (R_MICROMIPS_GPREL16, /* type */
2274 0, /* rightshift */
2275 2, /* size (0 = byte, 1 = short, 2 = long) */
2276 16, /* bitsize */
2277 FALSE, /* pc_relative */
2278 0, /* bitpos */
2279 complain_overflow_signed, /* complain_on_overflow */
2280 _bfd_mips_elf32_gprel16_reloc, /* special_function */
2281 "R_MICROMIPS_GPREL16", /* name */
2282 FALSE, /* partial_inplace */
2283 0, /* src_mask */
2284 0x0000ffff, /* dst_mask */
2285 FALSE), /* pcrel_offset */
2286
2287 /* Reference to literal section. */
2288 HOWTO (R_MICROMIPS_LITERAL, /* type */
2289 0, /* rightshift */
2290 2, /* size (0 = byte, 1 = short, 2 = long) */
2291 16, /* bitsize */
2292 FALSE, /* pc_relative */
2293 0, /* bitpos */
2294 complain_overflow_signed, /* complain_on_overflow */
2295 _bfd_mips_elf32_gprel16_reloc, /* special_function */
2296 "R_MICROMIPS_LITERAL", /* name */
2297 FALSE, /* partial_inplace */
2298 0, /* src_mask */
2299 0x0000ffff, /* dst_mask */
2300 FALSE), /* pcrel_offset */
2301
2302 /* Reference to global offset table. */
2303 HOWTO (R_MICROMIPS_GOT16, /* type */
2304 0, /* rightshift */
2305 2, /* size (0 = byte, 1 = short, 2 = long) */
2306 16, /* bitsize */
2307 FALSE, /* pc_relative */
2308 0, /* bitpos */
2309 complain_overflow_signed, /* complain_on_overflow */
2310 _bfd_mips_elf_got16_reloc, /* special_function */
2311 "R_MICROMIPS_GOT16", /* name */
2312 FALSE, /* partial_inplace */
2313 0, /* src_mask */
2314 0x0000ffff, /* dst_mask */
2315 FALSE), /* pcrel_offset */
2316
2317 /* This is for microMIPS branches. */
2318 HOWTO (R_MICROMIPS_PC7_S1, /* type */
2319 1, /* rightshift */
2320 1, /* size (0 = byte, 1 = short, 2 = long) */
2321 7, /* bitsize */
2322 TRUE, /* pc_relative */
2323 0, /* bitpos */
2324 complain_overflow_signed, /* complain_on_overflow */
2325 _bfd_mips_elf_generic_reloc, /* special_function */
2326 "R_MICROMIPS_PC7_S1", /* name */
2327 FALSE, /* partial_inplace */
2328 0, /* src_mask */
2329 0x0000007f, /* dst_mask */
2330 TRUE), /* pcrel_offset */
2331
2332 HOWTO (R_MICROMIPS_PC10_S1, /* type */
2333 1, /* rightshift */
2334 1, /* size (0 = byte, 1 = short, 2 = long) */
2335 10, /* bitsize */
2336 TRUE, /* pc_relative */
2337 0, /* bitpos */
2338 complain_overflow_signed, /* complain_on_overflow */
2339 _bfd_mips_elf_generic_reloc, /* special_function */
2340 "R_MICROMIPS_PC10_S1", /* name */
2341 FALSE, /* partial_inplace */
2342 0, /* src_mask */
2343 0x000003ff, /* dst_mask */
2344 TRUE), /* pcrel_offset */
2345
2346 HOWTO (R_MICROMIPS_PC16_S1, /* type */
2347 1, /* rightshift */
2348 2, /* size (0 = byte, 1 = short, 2 = long) */
2349 16, /* bitsize */
2350 TRUE, /* pc_relative */
2351 0, /* bitpos */
2352 complain_overflow_signed, /* complain_on_overflow */
2353 _bfd_mips_elf_generic_reloc, /* special_function */
2354 "R_MICROMIPS_PC16_S1", /* name */
2355 FALSE, /* partial_inplace */
2356 0, /* src_mask */
2357 0x0000ffff, /* dst_mask */
2358 TRUE), /* pcrel_offset */
2359
2360 /* 16 bit call through global offset table. */
2361 HOWTO (R_MICROMIPS_CALL16, /* type */
2362 0, /* rightshift */
2363 2, /* size (0 = byte, 1 = short, 2 = long) */
2364 16, /* bitsize */
2365 FALSE, /* pc_relative */
2366 0, /* bitpos */
2367 complain_overflow_signed, /* complain_on_overflow */
2368 _bfd_mips_elf_generic_reloc, /* special_function */
2369 "R_MICROMIPS_CALL16", /* name */
2370 FALSE, /* partial_inplace */
2371 0, /* src_mask */
2372 0x0000ffff, /* dst_mask */
2373 FALSE), /* pcrel_offset */
2374
2375 EMPTY_HOWTO (143),
2376 EMPTY_HOWTO (144),
2377
2378 /* Displacement in the global offset table. */
2379 HOWTO (R_MICROMIPS_GOT_DISP, /* type */
2380 0, /* rightshift */
2381 2, /* size (0 = byte, 1 = short, 2 = long) */
2382 16, /* bitsize */
2383 FALSE, /* pc_relative */
2384 0, /* bitpos */
2385 complain_overflow_signed, /* complain_on_overflow */
2386 _bfd_mips_elf_generic_reloc, /* special_function */
2387 "R_MICROMIPS_GOT_DISP",/* name */
2388 FALSE, /* partial_inplace */
2389 0, /* src_mask */
2390 0x0000ffff, /* dst_mask */
2391 FALSE), /* pcrel_offset */
2392
2393 /* Displacement to page pointer in the global offset table. */
2394 HOWTO (R_MICROMIPS_GOT_PAGE, /* type */
2395 0, /* rightshift */
2396 2, /* size (0 = byte, 1 = short, 2 = long) */
2397 16, /* bitsize */
2398 FALSE, /* pc_relative */
2399 0, /* bitpos */
2400 complain_overflow_signed, /* complain_on_overflow */
2401 _bfd_mips_elf_generic_reloc, /* special_function */
2402 "R_MICROMIPS_GOT_PAGE",/* name */
2403 FALSE, /* partial_inplace */
2404 0, /* src_mask */
2405 0x0000ffff, /* dst_mask */
2406 FALSE), /* pcrel_offset */
2407
2408 /* Offset from page pointer in the global offset table. */
2409 HOWTO (R_MICROMIPS_GOT_OFST, /* type */
2410 0, /* rightshift */
2411 2, /* size (0 = byte, 1 = short, 2 = long) */
2412 16, /* bitsize */
2413 FALSE, /* pc_relative */
2414 0, /* bitpos */
2415 complain_overflow_signed, /* complain_on_overflow */
2416 _bfd_mips_elf_generic_reloc, /* special_function */
2417 "R_MICROMIPS_GOT_OFST",/* name */
2418 FALSE, /* partial_inplace */
2419 0, /* src_mask */
2420 0x0000ffff, /* dst_mask */
2421 FALSE), /* pcrel_offset */
2422
2423 /* High 16 bits of displacement in global offset table. */
2424 HOWTO (R_MICROMIPS_GOT_HI16, /* type */
2425 0, /* rightshift */
2426 2, /* size (0 = byte, 1 = short, 2 = long) */
2427 16, /* bitsize */
2428 FALSE, /* pc_relative */
2429 0, /* bitpos */
2430 complain_overflow_dont, /* complain_on_overflow */
2431 _bfd_mips_elf_generic_reloc, /* special_function */
2432 "R_MICROMIPS_GOT_HI16",/* name */
2433 FALSE, /* partial_inplace */
2434 0, /* src_mask */
2435 0x0000ffff, /* dst_mask */
2436 FALSE), /* pcrel_offset */
2437
2438 /* Low 16 bits of displacement in global offset table. */
2439 HOWTO (R_MICROMIPS_GOT_LO16, /* type */
2440 0, /* rightshift */
2441 2, /* size (0 = byte, 1 = short, 2 = long) */
2442 16, /* bitsize */
2443 FALSE, /* pc_relative */
2444 0, /* bitpos */
2445 complain_overflow_dont, /* complain_on_overflow */
2446 _bfd_mips_elf_generic_reloc, /* special_function */
2447 "R_MICROMIPS_GOT_LO16",/* name */
2448 FALSE, /* partial_inplace */
2449 0, /* src_mask */
2450 0x0000ffff, /* dst_mask */
2451 FALSE), /* pcrel_offset */
2452
2453 /* 64 bit subtraction. Used in the N32 ABI. */
2454 HOWTO (R_MICROMIPS_SUB, /* type */
2455 0, /* rightshift */
2456 4, /* size (0 = byte, 1 = short, 2 = long) */
2457 64, /* bitsize */
2458 FALSE, /* pc_relative */
2459 0, /* bitpos */
2460 complain_overflow_dont, /* complain_on_overflow */
2461 _bfd_mips_elf_generic_reloc, /* special_function */
2462 "R_MICROMIPS_SUB", /* name */
2463 FALSE, /* partial_inplace */
2464 0, /* src_mask */
2465 MINUS_ONE, /* dst_mask */
2466 FALSE), /* pcrel_offset */
2467
2468 /* Get the higher value of a 64 bit addend. */
2469 HOWTO (R_MICROMIPS_HIGHER, /* type */
2470 0, /* rightshift */
2471 2, /* size (0 = byte, 1 = short, 2 = long) */
2472 16, /* bitsize */
2473 FALSE, /* pc_relative */
2474 0, /* bitpos */
2475 complain_overflow_dont, /* complain_on_overflow */
2476 _bfd_mips_elf_generic_reloc, /* special_function */
2477 "R_MICROMIPS_HIGHER", /* name */
2478 FALSE, /* partial_inplace */
2479 0, /* src_mask */
2480 0x0000ffff, /* dst_mask */
2481 FALSE), /* pcrel_offset */
2482
2483 /* Get the highest value of a 64 bit addend. */
2484 HOWTO (R_MICROMIPS_HIGHEST, /* type */
2485 0, /* rightshift */
2486 2, /* size (0 = byte, 1 = short, 2 = long) */
2487 16, /* bitsize */
2488 FALSE, /* pc_relative */
2489 0, /* bitpos */
2490 complain_overflow_dont, /* complain_on_overflow */
2491 _bfd_mips_elf_generic_reloc, /* special_function */
2492 "R_MICROMIPS_HIGHEST", /* name */
2493 FALSE, /* partial_inplace */
2494 0, /* src_mask */
2495 0x0000ffff, /* dst_mask */
2496 FALSE), /* pcrel_offset */
2497
2498 /* High 16 bits of displacement in global offset table. */
2499 HOWTO (R_MICROMIPS_CALL_HI16, /* type */
2500 0, /* rightshift */
2501 2, /* size (0 = byte, 1 = short, 2 = long) */
2502 16, /* bitsize */
2503 FALSE, /* pc_relative */
2504 0, /* bitpos */
2505 complain_overflow_dont, /* complain_on_overflow */
2506 _bfd_mips_elf_generic_reloc, /* special_function */
2507 "R_MICROMIPS_CALL_HI16",/* name */
2508 FALSE, /* partial_inplace */
2509 0, /* src_mask */
2510 0x0000ffff, /* dst_mask */
2511 FALSE), /* pcrel_offset */
2512
2513 /* Low 16 bits of displacement in global offset table. */
2514 HOWTO (R_MICROMIPS_CALL_LO16, /* type */
2515 0, /* rightshift */
2516 2, /* size (0 = byte, 1 = short, 2 = long) */
2517 16, /* bitsize */
2518 FALSE, /* pc_relative */
2519 0, /* bitpos */
2520 complain_overflow_dont, /* complain_on_overflow */
2521 _bfd_mips_elf_generic_reloc, /* special_function */
2522 "R_MICROMIPS_CALL_LO16",/* name */
2523 FALSE, /* partial_inplace */
2524 0, /* src_mask */
2525 0x0000ffff, /* dst_mask */
2526 FALSE), /* pcrel_offset */
2527
2528 /* Section displacement. */
2529 HOWTO (R_MICROMIPS_SCN_DISP, /* type */
2530 0, /* rightshift */
2531 2, /* size (0 = byte, 1 = short, 2 = long) */
2532 32, /* bitsize */
2533 FALSE, /* pc_relative */
2534 0, /* bitpos */
2535 complain_overflow_dont, /* complain_on_overflow */
2536 _bfd_mips_elf_generic_reloc, /* special_function */
2537 "R_MICROMIPS_SCN_DISP", /* name */
2538 FALSE, /* partial_inplace */
2539 0, /* src_mask */
2540 0xffffffff, /* dst_mask */
2541 FALSE), /* pcrel_offset */
2542
2543 /* Protected jump conversion. This is an optimization hint. No
2544 relocation is required for correctness. */
2545 HOWTO (R_MICROMIPS_JALR, /* 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_mips_elf_generic_reloc, /* special_function */
2553 "R_MICROMIPS_JALR", /* name */
2554 FALSE, /* partial_inplace */
2555 0, /* src_mask */
2556 0x00000000, /* dst_mask */
2557 FALSE), /* pcrel_offset */
2558 };
2559
2560 /* GNU extension to record C++ vtable hierarchy */
2561 static reloc_howto_type elf_mips_gnu_vtinherit_howto =
2562 HOWTO (R_MIPS_GNU_VTINHERIT, /* type */
2563 0, /* rightshift */
2564 2, /* size (0 = byte, 1 = short, 2 = long) */
2565 0, /* bitsize */
2566 FALSE, /* pc_relative */
2567 0, /* bitpos */
2568 complain_overflow_dont, /* complain_on_overflow */
2569 NULL, /* special_function */
2570 "R_MIPS_GNU_VTINHERIT", /* name */
2571 FALSE, /* partial_inplace */
2572 0, /* src_mask */
2573 0, /* dst_mask */
2574 FALSE); /* pcrel_offset */
2575
2576 /* GNU extension to record C++ vtable member usage */
2577 static reloc_howto_type elf_mips_gnu_vtentry_howto =
2578 HOWTO (R_MIPS_GNU_VTENTRY, /* type */
2579 0, /* rightshift */
2580 2, /* size (0 = byte, 1 = short, 2 = long) */
2581 0, /* bitsize */
2582 FALSE, /* pc_relative */
2583 0, /* bitpos */
2584 complain_overflow_dont, /* complain_on_overflow */
2585 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
2586 "R_MIPS_GNU_VTENTRY", /* name */
2587 FALSE, /* partial_inplace */
2588 0, /* src_mask */
2589 0, /* dst_mask */
2590 FALSE); /* pcrel_offset */
2591 \f
2592 /* 16 bit offset for pc-relative branches. */
2593 static reloc_howto_type elf_mips_gnu_rel16_s2 =
2594 HOWTO (R_MIPS_GNU_REL16_S2, /* type */
2595 2, /* rightshift */
2596 2, /* size (0 = byte, 1 = short, 2 = long) */
2597 16, /* bitsize */
2598 TRUE, /* pc_relative */
2599 0, /* bitpos */
2600 complain_overflow_signed, /* complain_on_overflow */
2601 _bfd_mips_elf_generic_reloc, /* special_function */
2602 "R_MIPS_GNU_REL16_S2", /* name */
2603 TRUE, /* partial_inplace */
2604 0x0000ffff, /* src_mask */
2605 0x0000ffff, /* dst_mask */
2606 TRUE); /* pcrel_offset */
2607
2608 /* 16 bit offset for pc-relative branches. */
2609 static reloc_howto_type elf_mips_gnu_rela16_s2 =
2610 HOWTO (R_MIPS_GNU_REL16_S2, /* type */
2611 2, /* rightshift */
2612 2, /* size (0 = byte, 1 = short, 2 = long) */
2613 16, /* bitsize */
2614 TRUE, /* pc_relative */
2615 0, /* bitpos */
2616 complain_overflow_signed, /* complain_on_overflow */
2617 _bfd_mips_elf_generic_reloc, /* special_function */
2618 "R_MIPS_GNU_REL16_S2", /* name */
2619 FALSE, /* partial_inplace */
2620 0, /* src_mask */
2621 0x0000ffff, /* dst_mask */
2622 TRUE); /* pcrel_offset */
2623
2624 /* 32 bit pc-relative. Used for compact EH tables. */
2625 static reloc_howto_type elf_mips_gnu_pcrel32 =
2626 HOWTO (R_MIPS_PC32, /* type */
2627 0, /* rightshift */
2628 2, /* size (0 = byte, 1 = short, 2 = long) */
2629 32, /* bitsize */
2630 TRUE, /* pc_relative */
2631 0, /* bitpos */
2632 complain_overflow_signed, /* complain_on_overflow */
2633 _bfd_mips_elf_generic_reloc, /* special_function */
2634 "R_MIPS_PC32", /* name */
2635 TRUE, /* partial_inplace */
2636 0xffffffff, /* src_mask */
2637 0xffffffff, /* dst_mask */
2638 TRUE); /* pcrel_offset */
2639
2640 \f
2641 /* Originally a VxWorks extension, but now used for other systems too. */
2642 static reloc_howto_type elf_mips_copy_howto =
2643 HOWTO (R_MIPS_COPY, /* type */
2644 0, /* rightshift */
2645 0, /* this one is variable size */
2646 0, /* bitsize */
2647 FALSE, /* pc_relative */
2648 0, /* bitpos */
2649 complain_overflow_bitfield, /* complain_on_overflow */
2650 _bfd_mips_elf_generic_reloc, /* special_function */
2651 "R_MIPS_COPY", /* name */
2652 FALSE, /* partial_inplace */
2653 0x0, /* src_mask */
2654 0x0, /* dst_mask */
2655 FALSE); /* pcrel_offset */
2656
2657 /* Originally a VxWorks extension, but now used for other systems too. */
2658 static reloc_howto_type elf_mips_jump_slot_howto =
2659 HOWTO (R_MIPS_JUMP_SLOT, /* type */
2660 0, /* rightshift */
2661 4, /* size (0 = byte, 1 = short, 2 = long) */
2662 64, /* bitsize */
2663 FALSE, /* pc_relative */
2664 0, /* bitpos */
2665 complain_overflow_bitfield, /* complain_on_overflow */
2666 _bfd_mips_elf_generic_reloc, /* special_function */
2667 "R_MIPS_JUMP_SLOT", /* name */
2668 FALSE, /* partial_inplace */
2669 0x0, /* src_mask */
2670 0x0, /* dst_mask */
2671 FALSE); /* pcrel_offset */
2672
2673 /* Used in EH tables. */
2674 static reloc_howto_type elf_mips_eh_howto =
2675 HOWTO (R_MIPS_EH, /* type */
2676 0, /* rightshift */
2677 2, /* size (0 = byte, 1 = short, 2 = long) */
2678 32, /* bitsize */
2679 FALSE, /* pc_relative */
2680 0, /* bitpos */
2681 complain_overflow_signed, /* complain_on_overflow */
2682 _bfd_mips_elf_generic_reloc, /* special_function */
2683 "R_MIPS_EH", /* name */
2684 TRUE, /* partial_inplace */
2685 0xffffffff, /* src_mask */
2686 0xffffffff, /* dst_mask */
2687 FALSE); /* pcrel_offset */
2688
2689 \f
2690 /* Swap in a MIPS 64-bit Rel reloc. */
2691
2692 static void
2693 mips_elf64_swap_reloc_in (bfd *abfd, const Elf64_Mips_External_Rel *src,
2694 Elf64_Mips_Internal_Rela *dst)
2695 {
2696 dst->r_offset = H_GET_64 (abfd, src->r_offset);
2697 dst->r_sym = H_GET_32 (abfd, src->r_sym);
2698 dst->r_ssym = H_GET_8 (abfd, src->r_ssym);
2699 dst->r_type3 = H_GET_8 (abfd, src->r_type3);
2700 dst->r_type2 = H_GET_8 (abfd, src->r_type2);
2701 dst->r_type = H_GET_8 (abfd, src->r_type);
2702 dst->r_addend = 0;
2703 }
2704
2705 /* Swap in a MIPS 64-bit Rela reloc. */
2706
2707 static void
2708 mips_elf64_swap_reloca_in (bfd *abfd, const Elf64_Mips_External_Rela *src,
2709 Elf64_Mips_Internal_Rela *dst)
2710 {
2711 dst->r_offset = H_GET_64 (abfd, src->r_offset);
2712 dst->r_sym = H_GET_32 (abfd, src->r_sym);
2713 dst->r_ssym = H_GET_8 (abfd, src->r_ssym);
2714 dst->r_type3 = H_GET_8 (abfd, src->r_type3);
2715 dst->r_type2 = H_GET_8 (abfd, src->r_type2);
2716 dst->r_type = H_GET_8 (abfd, src->r_type);
2717 dst->r_addend = H_GET_S64 (abfd, src->r_addend);
2718 }
2719
2720 /* Swap out a MIPS 64-bit Rel reloc. */
2721
2722 static void
2723 mips_elf64_swap_reloc_out (bfd *abfd, const Elf64_Mips_Internal_Rela *src,
2724 Elf64_Mips_External_Rel *dst)
2725 {
2726 H_PUT_64 (abfd, src->r_offset, dst->r_offset);
2727 H_PUT_32 (abfd, src->r_sym, dst->r_sym);
2728 H_PUT_8 (abfd, src->r_ssym, dst->r_ssym);
2729 H_PUT_8 (abfd, src->r_type3, dst->r_type3);
2730 H_PUT_8 (abfd, src->r_type2, dst->r_type2);
2731 H_PUT_8 (abfd, src->r_type, dst->r_type);
2732 }
2733
2734 /* Swap out a MIPS 64-bit Rela reloc. */
2735
2736 static void
2737 mips_elf64_swap_reloca_out (bfd *abfd, const Elf64_Mips_Internal_Rela *src,
2738 Elf64_Mips_External_Rela *dst)
2739 {
2740 H_PUT_64 (abfd, src->r_offset, dst->r_offset);
2741 H_PUT_32 (abfd, src->r_sym, dst->r_sym);
2742 H_PUT_8 (abfd, src->r_ssym, dst->r_ssym);
2743 H_PUT_8 (abfd, src->r_type3, dst->r_type3);
2744 H_PUT_8 (abfd, src->r_type2, dst->r_type2);
2745 H_PUT_8 (abfd, src->r_type, dst->r_type);
2746 H_PUT_S64 (abfd, src->r_addend, dst->r_addend);
2747 }
2748
2749 /* Swap in a MIPS 64-bit Rel reloc. */
2750
2751 static void
2752 mips_elf64_be_swap_reloc_in (bfd *abfd, const bfd_byte *src,
2753 Elf_Internal_Rela *dst)
2754 {
2755 Elf64_Mips_Internal_Rela mirel;
2756
2757 mips_elf64_swap_reloc_in (abfd,
2758 (const Elf64_Mips_External_Rel *) src,
2759 &mirel);
2760
2761 dst[0].r_offset = mirel.r_offset;
2762 dst[0].r_info = ELF64_R_INFO (mirel.r_sym, mirel.r_type);
2763 dst[0].r_addend = 0;
2764 dst[1].r_offset = mirel.r_offset;
2765 dst[1].r_info = ELF64_R_INFO (mirel.r_ssym, mirel.r_type2);
2766 dst[1].r_addend = 0;
2767 dst[2].r_offset = mirel.r_offset;
2768 dst[2].r_info = ELF64_R_INFO (STN_UNDEF, mirel.r_type3);
2769 dst[2].r_addend = 0;
2770 }
2771
2772 /* Swap in a MIPS 64-bit Rela reloc. */
2773
2774 static void
2775 mips_elf64_be_swap_reloca_in (bfd *abfd, const bfd_byte *src,
2776 Elf_Internal_Rela *dst)
2777 {
2778 Elf64_Mips_Internal_Rela mirela;
2779
2780 mips_elf64_swap_reloca_in (abfd,
2781 (const Elf64_Mips_External_Rela *) src,
2782 &mirela);
2783
2784 dst[0].r_offset = mirela.r_offset;
2785 dst[0].r_info = ELF64_R_INFO (mirela.r_sym, mirela.r_type);
2786 dst[0].r_addend = mirela.r_addend;
2787 dst[1].r_offset = mirela.r_offset;
2788 dst[1].r_info = ELF64_R_INFO (mirela.r_ssym, mirela.r_type2);
2789 dst[1].r_addend = 0;
2790 dst[2].r_offset = mirela.r_offset;
2791 dst[2].r_info = ELF64_R_INFO (STN_UNDEF, mirela.r_type3);
2792 dst[2].r_addend = 0;
2793 }
2794
2795 /* Swap out a MIPS 64-bit Rel reloc. */
2796
2797 static void
2798 mips_elf64_be_swap_reloc_out (bfd *abfd, const Elf_Internal_Rela *src,
2799 bfd_byte *dst)
2800 {
2801 Elf64_Mips_Internal_Rela mirel;
2802
2803 mirel.r_offset = src[0].r_offset;
2804 BFD_ASSERT(src[0].r_offset == src[1].r_offset);
2805 BFD_ASSERT(src[0].r_offset == src[2].r_offset);
2806
2807 mirel.r_type = ELF64_MIPS_R_TYPE (src[0].r_info);
2808 mirel.r_sym = ELF64_R_SYM (src[0].r_info);
2809 mirel.r_type2 = ELF64_MIPS_R_TYPE (src[1].r_info);
2810 mirel.r_ssym = ELF64_MIPS_R_SSYM (src[1].r_info);
2811 mirel.r_type3 = ELF64_MIPS_R_TYPE (src[2].r_info);
2812
2813 mips_elf64_swap_reloc_out (abfd, &mirel,
2814 (Elf64_Mips_External_Rel *) dst);
2815 }
2816
2817 /* Swap out a MIPS 64-bit Rela reloc. */
2818
2819 static void
2820 mips_elf64_be_swap_reloca_out (bfd *abfd, const Elf_Internal_Rela *src,
2821 bfd_byte *dst)
2822 {
2823 Elf64_Mips_Internal_Rela mirela;
2824
2825 mirela.r_offset = src[0].r_offset;
2826 BFD_ASSERT(src[0].r_offset == src[1].r_offset);
2827 BFD_ASSERT(src[0].r_offset == src[2].r_offset);
2828
2829 mirela.r_type = ELF64_MIPS_R_TYPE (src[0].r_info);
2830 mirela.r_sym = ELF64_R_SYM (src[0].r_info);
2831 mirela.r_addend = src[0].r_addend;
2832 BFD_ASSERT(src[1].r_addend == 0);
2833 BFD_ASSERT(src[2].r_addend == 0);
2834
2835 mirela.r_type2 = ELF64_MIPS_R_TYPE (src[1].r_info);
2836 mirela.r_ssym = ELF64_MIPS_R_SSYM (src[1].r_info);
2837 mirela.r_type3 = ELF64_MIPS_R_TYPE (src[2].r_info);
2838
2839 mips_elf64_swap_reloca_out (abfd, &mirela,
2840 (Elf64_Mips_External_Rela *) dst);
2841 }
2842 \f
2843 /* Set the GP value for OUTPUT_BFD. Returns FALSE if this is a
2844 dangerous relocation. */
2845
2846 static bfd_boolean
2847 mips_elf64_assign_gp (bfd *output_bfd, bfd_vma *pgp)
2848 {
2849 unsigned int count;
2850 asymbol **sym;
2851 unsigned int i;
2852
2853 /* If we've already figured out what GP will be, just return it. */
2854 *pgp = _bfd_get_gp_value (output_bfd);
2855 if (*pgp)
2856 return TRUE;
2857
2858 count = bfd_get_symcount (output_bfd);
2859 sym = bfd_get_outsymbols (output_bfd);
2860
2861 /* The linker script will have created a symbol named `_gp' with the
2862 appropriate value. */
2863 if (sym == NULL)
2864 i = count;
2865 else
2866 {
2867 for (i = 0; i < count; i++, sym++)
2868 {
2869 register const char *name;
2870
2871 name = bfd_asymbol_name (*sym);
2872 if (*name == '_' && strcmp (name, "_gp") == 0)
2873 {
2874 *pgp = bfd_asymbol_value (*sym);
2875 _bfd_set_gp_value (output_bfd, *pgp);
2876 break;
2877 }
2878 }
2879 }
2880
2881 if (i >= count)
2882 {
2883 /* Only get the error once. */
2884 *pgp = 4;
2885 _bfd_set_gp_value (output_bfd, *pgp);
2886 return FALSE;
2887 }
2888
2889 return TRUE;
2890 }
2891
2892 /* We have to figure out the gp value, so that we can adjust the
2893 symbol value correctly. We look up the symbol _gp in the output
2894 BFD. If we can't find it, we're stuck. We cache it in the ELF
2895 target data. We don't need to adjust the symbol value for an
2896 external symbol if we are producing relocatable output. */
2897
2898 static bfd_reloc_status_type
2899 mips_elf64_final_gp (bfd *output_bfd, asymbol *symbol, bfd_boolean relocatable,
2900 char **error_message, bfd_vma *pgp)
2901 {
2902 if (bfd_is_und_section (symbol->section)
2903 && ! relocatable)
2904 {
2905 *pgp = 0;
2906 return bfd_reloc_undefined;
2907 }
2908
2909 *pgp = _bfd_get_gp_value (output_bfd);
2910 if (*pgp == 0
2911 && (! relocatable
2912 || (symbol->flags & BSF_SECTION_SYM) != 0))
2913 {
2914 if (relocatable)
2915 {
2916 /* Make up a value. */
2917 *pgp = symbol->section->output_section->vma /*+ 0x4000*/;
2918 _bfd_set_gp_value (output_bfd, *pgp);
2919 }
2920 else if (!mips_elf64_assign_gp (output_bfd, pgp))
2921 {
2922 *error_message =
2923 (char *) _("GP relative relocation when _gp not defined");
2924 return bfd_reloc_dangerous;
2925 }
2926 }
2927
2928 return bfd_reloc_ok;
2929 }
2930
2931 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
2932 become the offset from the gp register. */
2933
2934 static bfd_reloc_status_type
2935 mips_elf64_gprel16_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2936 void *data, asection *input_section, bfd *output_bfd,
2937 char **error_message)
2938 {
2939 bfd_boolean relocatable;
2940 bfd_reloc_status_type ret;
2941 bfd_vma gp;
2942
2943 /* If we're relocating, and this is an external symbol, we don't want
2944 to change anything. */
2945 if (output_bfd != NULL
2946 && (symbol->flags & BSF_SECTION_SYM) == 0
2947 && (symbol->flags & BSF_LOCAL) != 0)
2948 {
2949 reloc_entry->address += input_section->output_offset;
2950 return bfd_reloc_ok;
2951 }
2952
2953 if (output_bfd != NULL)
2954 relocatable = TRUE;
2955 else
2956 {
2957 relocatable = FALSE;
2958 output_bfd = symbol->section->output_section->owner;
2959 }
2960
2961 ret = mips_elf64_final_gp (output_bfd, symbol, relocatable, error_message,
2962 &gp);
2963 if (ret != bfd_reloc_ok)
2964 return ret;
2965
2966 return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
2967 input_section, relocatable,
2968 data, gp);
2969 }
2970
2971 /* Do a R_MIPS_LITERAL relocation. */
2972
2973 static bfd_reloc_status_type
2974 mips_elf64_literal_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2975 void *data, asection *input_section, bfd *output_bfd,
2976 char **error_message)
2977 {
2978 bfd_boolean relocatable;
2979 bfd_reloc_status_type ret;
2980 bfd_vma gp;
2981
2982 /* R_MIPS_LITERAL relocations are defined for local symbols only. */
2983 if (output_bfd != NULL
2984 && (symbol->flags & BSF_SECTION_SYM) == 0
2985 && (symbol->flags & BSF_LOCAL) != 0)
2986 {
2987 *error_message = (char *)
2988 _("literal relocation occurs for an external symbol");
2989 return bfd_reloc_outofrange;
2990 }
2991
2992 /* FIXME: The entries in the .lit8 and .lit4 sections should be merged. */
2993 if (output_bfd != NULL)
2994 relocatable = TRUE;
2995 else
2996 {
2997 relocatable = FALSE;
2998 output_bfd = symbol->section->output_section->owner;
2999 }
3000
3001 ret = mips_elf64_final_gp (output_bfd, symbol, relocatable, error_message,
3002 &gp);
3003 if (ret != bfd_reloc_ok)
3004 return ret;
3005
3006 return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
3007 input_section, relocatable,
3008 data, gp);
3009 }
3010
3011 /* Do a R_MIPS_GPREL32 relocation. This is a 32 bit value which must
3012 become the offset from the gp register. */
3013
3014 static bfd_reloc_status_type
3015 mips_elf64_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
3016 void *data, asection *input_section, bfd *output_bfd,
3017 char **error_message)
3018 {
3019 bfd_boolean relocatable;
3020 bfd_reloc_status_type ret;
3021 bfd_vma gp;
3022 bfd_vma relocation;
3023 bfd_vma val;
3024
3025 /* R_MIPS_GPREL32 relocations are defined for local symbols only. */
3026 if (output_bfd != NULL
3027 && (symbol->flags & BSF_SECTION_SYM) == 0
3028 && (symbol->flags & BSF_LOCAL) != 0)
3029 {
3030 *error_message = (char *)
3031 _("32bits gp relative relocation occurs for an external symbol");
3032 return bfd_reloc_outofrange;
3033 }
3034
3035 if (output_bfd != NULL)
3036 relocatable = TRUE;
3037 else
3038 {
3039 relocatable = FALSE;
3040 output_bfd = symbol->section->output_section->owner;
3041 }
3042
3043 ret = mips_elf64_final_gp (output_bfd, symbol, relocatable,
3044 error_message, &gp);
3045 if (ret != bfd_reloc_ok)
3046 return ret;
3047
3048 if (bfd_is_com_section (symbol->section))
3049 relocation = 0;
3050 else
3051 relocation = symbol->value;
3052
3053 relocation += symbol->section->output_section->vma;
3054 relocation += symbol->section->output_offset;
3055
3056 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
3057 return bfd_reloc_outofrange;
3058
3059 /* Set val to the offset into the section or symbol. */
3060 val = reloc_entry->addend;
3061
3062 if (reloc_entry->howto->partial_inplace)
3063 val += bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
3064
3065 /* Adjust val for the final section location and GP value. If we
3066 are producing relocatable output, we don't want to do this for
3067 an external symbol. */
3068 if (! relocatable
3069 || (symbol->flags & BSF_SECTION_SYM) != 0)
3070 val += relocation - gp;
3071
3072 if (reloc_entry->howto->partial_inplace)
3073 bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);
3074 else
3075 reloc_entry->addend = val;
3076
3077 if (relocatable)
3078 reloc_entry->address += input_section->output_offset;
3079
3080 return bfd_reloc_ok;
3081 }
3082
3083 /* Do a R_MIPS_SHIFT6 relocation. The MSB of the shift is stored at bit 2,
3084 the rest is at bits 6-10. The bitpos already got right by the howto. */
3085
3086 static bfd_reloc_status_type
3087 mips_elf64_shift6_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
3088 void *data, asection *input_section, bfd *output_bfd,
3089 char **error_message)
3090 {
3091 if (reloc_entry->howto->partial_inplace)
3092 {
3093 reloc_entry->addend = ((reloc_entry->addend & 0x00007c0)
3094 | (reloc_entry->addend & 0x00000800) >> 9);
3095 }
3096
3097 return _bfd_mips_elf_generic_reloc (abfd, reloc_entry, symbol, data,
3098 input_section, output_bfd,
3099 error_message);
3100 }
3101
3102 /* Handle a mips16 GP relative reloc. */
3103
3104 static bfd_reloc_status_type
3105 mips16_gprel_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
3106 void *data, asection *input_section, bfd *output_bfd,
3107 char **error_message)
3108 {
3109 bfd_boolean relocatable;
3110 bfd_reloc_status_type ret;
3111 bfd_byte *location;
3112 bfd_vma gp;
3113
3114 /* If we're relocating, and this is an external symbol, we don't want
3115 to change anything. */
3116 if (output_bfd != NULL
3117 && (symbol->flags & BSF_SECTION_SYM) == 0
3118 && (symbol->flags & BSF_LOCAL) != 0)
3119 {
3120 reloc_entry->address += input_section->output_offset;
3121 return bfd_reloc_ok;
3122 }
3123
3124 if (output_bfd != NULL)
3125 relocatable = TRUE;
3126 else
3127 {
3128 relocatable = FALSE;
3129 output_bfd = symbol->section->output_section->owner;
3130 }
3131
3132 ret = mips_elf64_final_gp (output_bfd, symbol, relocatable, error_message,
3133 &gp);
3134 if (ret != bfd_reloc_ok)
3135 return ret;
3136
3137 location = (bfd_byte *) data + reloc_entry->address;
3138 _bfd_mips_elf_reloc_unshuffle (abfd, reloc_entry->howto->type, FALSE,
3139 location);
3140 ret = _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
3141 input_section, relocatable,
3142 data, gp);
3143 _bfd_mips_elf_reloc_shuffle (abfd, reloc_entry->howto->type, !relocatable,
3144 location);
3145
3146 return ret;
3147 }
3148 \f
3149 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
3150
3151 struct elf_reloc_map {
3152 bfd_reloc_code_real_type bfd_val;
3153 enum elf_mips_reloc_type elf_val;
3154 };
3155
3156 static const struct elf_reloc_map mips_reloc_map[] =
3157 {
3158 { BFD_RELOC_NONE, R_MIPS_NONE },
3159 { BFD_RELOC_16, R_MIPS_16 },
3160 { BFD_RELOC_32, R_MIPS_32 },
3161 /* There is no BFD reloc for R_MIPS_REL32. */
3162 { BFD_RELOC_64, R_MIPS_64 },
3163 { BFD_RELOC_CTOR, R_MIPS_64 },
3164 { BFD_RELOC_16_PCREL_S2, R_MIPS_PC16 },
3165 { BFD_RELOC_HI16_S, R_MIPS_HI16 },
3166 { BFD_RELOC_LO16, R_MIPS_LO16 },
3167 { BFD_RELOC_GPREL16, R_MIPS_GPREL16 },
3168 { BFD_RELOC_GPREL32, R_MIPS_GPREL32 },
3169 { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
3170 { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
3171 { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
3172 { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
3173 { BFD_RELOC_MIPS_SHIFT5, R_MIPS_SHIFT5 },
3174 { BFD_RELOC_MIPS_SHIFT6, R_MIPS_SHIFT6 },
3175 { BFD_RELOC_MIPS_GOT_DISP, R_MIPS_GOT_DISP },
3176 { BFD_RELOC_MIPS_GOT_PAGE, R_MIPS_GOT_PAGE },
3177 { BFD_RELOC_MIPS_GOT_OFST, R_MIPS_GOT_OFST },
3178 { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
3179 { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 },
3180 { BFD_RELOC_MIPS_SUB, R_MIPS_SUB },
3181 { BFD_RELOC_MIPS_INSERT_A, R_MIPS_INSERT_A },
3182 { BFD_RELOC_MIPS_INSERT_B, R_MIPS_INSERT_B },
3183 { BFD_RELOC_MIPS_DELETE, R_MIPS_DELETE },
3184 { BFD_RELOC_MIPS_HIGHEST, R_MIPS_HIGHEST },
3185 { BFD_RELOC_MIPS_HIGHER, R_MIPS_HIGHER },
3186 { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 },
3187 { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 },
3188 { BFD_RELOC_MIPS_SCN_DISP, R_MIPS_SCN_DISP },
3189 { BFD_RELOC_MIPS_REL16, R_MIPS_REL16 },
3190 /* Use of R_MIPS_ADD_IMMEDIATE and R_MIPS_PJUMP is deprecated. */
3191 { BFD_RELOC_MIPS_RELGOT, R_MIPS_RELGOT },
3192 { BFD_RELOC_MIPS_JALR, R_MIPS_JALR },
3193 { BFD_RELOC_MIPS_TLS_DTPMOD32, R_MIPS_TLS_DTPMOD32 },
3194 { BFD_RELOC_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL32 },
3195 { BFD_RELOC_MIPS_TLS_DTPMOD64, R_MIPS_TLS_DTPMOD64 },
3196 { BFD_RELOC_MIPS_TLS_DTPREL64, R_MIPS_TLS_DTPREL64 },
3197 { BFD_RELOC_MIPS_TLS_GD, R_MIPS_TLS_GD },
3198 { BFD_RELOC_MIPS_TLS_LDM, R_MIPS_TLS_LDM },
3199 { BFD_RELOC_MIPS_TLS_DTPREL_HI16, R_MIPS_TLS_DTPREL_HI16 },
3200 { BFD_RELOC_MIPS_TLS_DTPREL_LO16, R_MIPS_TLS_DTPREL_LO16 },
3201 { BFD_RELOC_MIPS_TLS_GOTTPREL, R_MIPS_TLS_GOTTPREL },
3202 { BFD_RELOC_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL32 },
3203 { BFD_RELOC_MIPS_TLS_TPREL64, R_MIPS_TLS_TPREL64 },
3204 { BFD_RELOC_MIPS_TLS_TPREL_HI16, R_MIPS_TLS_TPREL_HI16 },
3205 { BFD_RELOC_MIPS_TLS_TPREL_LO16, R_MIPS_TLS_TPREL_LO16 }
3206 };
3207
3208 static const struct elf_reloc_map mips16_reloc_map[] =
3209 {
3210 { BFD_RELOC_MIPS16_JMP, R_MIPS16_26 - R_MIPS16_min },
3211 { BFD_RELOC_MIPS16_GPREL, R_MIPS16_GPREL - R_MIPS16_min },
3212 { BFD_RELOC_MIPS16_GOT16, R_MIPS16_GOT16 - R_MIPS16_min },
3213 { BFD_RELOC_MIPS16_CALL16, R_MIPS16_CALL16 - R_MIPS16_min },
3214 { BFD_RELOC_MIPS16_HI16_S, R_MIPS16_HI16 - R_MIPS16_min },
3215 { BFD_RELOC_MIPS16_LO16, R_MIPS16_LO16 - R_MIPS16_min },
3216 { BFD_RELOC_MIPS16_TLS_GD, R_MIPS16_TLS_GD - R_MIPS16_min },
3217 { BFD_RELOC_MIPS16_TLS_LDM, R_MIPS16_TLS_LDM - R_MIPS16_min },
3218 { BFD_RELOC_MIPS16_TLS_DTPREL_HI16,
3219 R_MIPS16_TLS_DTPREL_HI16 - R_MIPS16_min },
3220 { BFD_RELOC_MIPS16_TLS_DTPREL_LO16,
3221 R_MIPS16_TLS_DTPREL_LO16 - R_MIPS16_min },
3222 { BFD_RELOC_MIPS16_TLS_GOTTPREL, R_MIPS16_TLS_GOTTPREL - R_MIPS16_min },
3223 { BFD_RELOC_MIPS16_TLS_TPREL_HI16, R_MIPS16_TLS_TPREL_HI16 - R_MIPS16_min },
3224 { BFD_RELOC_MIPS16_TLS_TPREL_LO16, R_MIPS16_TLS_TPREL_LO16 - R_MIPS16_min }
3225 };
3226
3227 static const struct elf_reloc_map micromips_reloc_map[] =
3228 {
3229 { BFD_RELOC_MICROMIPS_JMP, R_MICROMIPS_26_S1 - R_MICROMIPS_min },
3230 { BFD_RELOC_MICROMIPS_HI16_S, R_MICROMIPS_HI16 - R_MICROMIPS_min },
3231 { BFD_RELOC_MICROMIPS_LO16, R_MICROMIPS_LO16 - R_MICROMIPS_min },
3232 { BFD_RELOC_MICROMIPS_GPREL16, R_MICROMIPS_GPREL16 - R_MICROMIPS_min },
3233 { BFD_RELOC_MICROMIPS_LITERAL, R_MICROMIPS_LITERAL - R_MICROMIPS_min },
3234 { BFD_RELOC_MICROMIPS_GOT16, R_MICROMIPS_GOT16 - R_MICROMIPS_min },
3235 { BFD_RELOC_MICROMIPS_7_PCREL_S1, R_MICROMIPS_PC7_S1 - R_MICROMIPS_min },
3236 { BFD_RELOC_MICROMIPS_10_PCREL_S1, R_MICROMIPS_PC10_S1 - R_MICROMIPS_min },
3237 { BFD_RELOC_MICROMIPS_16_PCREL_S1, R_MICROMIPS_PC16_S1 - R_MICROMIPS_min },
3238 { BFD_RELOC_MICROMIPS_CALL16, R_MICROMIPS_CALL16 - R_MICROMIPS_min },
3239 { BFD_RELOC_MICROMIPS_GOT_DISP, R_MICROMIPS_GOT_DISP - R_MICROMIPS_min },
3240 { BFD_RELOC_MICROMIPS_GOT_PAGE, R_MICROMIPS_GOT_PAGE - R_MICROMIPS_min },
3241 { BFD_RELOC_MICROMIPS_GOT_OFST, R_MICROMIPS_GOT_OFST - R_MICROMIPS_min },
3242 { BFD_RELOC_MICROMIPS_GOT_HI16, R_MICROMIPS_GOT_HI16 - R_MICROMIPS_min },
3243 { BFD_RELOC_MICROMIPS_GOT_LO16, R_MICROMIPS_GOT_LO16 - R_MICROMIPS_min },
3244 { BFD_RELOC_MICROMIPS_SUB, R_MICROMIPS_SUB - R_MICROMIPS_min },
3245 { BFD_RELOC_MICROMIPS_HIGHER, R_MICROMIPS_HIGHER - R_MICROMIPS_min },
3246 { BFD_RELOC_MICROMIPS_HIGHEST, R_MICROMIPS_HIGHEST - R_MICROMIPS_min },
3247 { BFD_RELOC_MICROMIPS_CALL_HI16, R_MICROMIPS_CALL_HI16 - R_MICROMIPS_min },
3248 { BFD_RELOC_MICROMIPS_CALL_LO16, R_MICROMIPS_CALL_LO16 - R_MICROMIPS_min },
3249 { BFD_RELOC_MICROMIPS_SCN_DISP, R_MICROMIPS_SCN_DISP - R_MICROMIPS_min },
3250 { BFD_RELOC_MICROMIPS_JALR, R_MICROMIPS_JALR - R_MICROMIPS_min },
3251 };
3252 /* Given a BFD reloc type, return a howto structure. */
3253
3254 static reloc_howto_type *
3255 bfd_elf64_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
3256 bfd_reloc_code_real_type code)
3257 {
3258 unsigned int i;
3259 /* FIXME: We default to RELA here instead of choosing the right
3260 relocation variant. */
3261 reloc_howto_type *howto_table = mips_elf64_howto_table_rela;
3262 reloc_howto_type *howto16_table = mips16_elf64_howto_table_rela;
3263 reloc_howto_type *howto_micromips_table = micromips_elf64_howto_table_rela;
3264
3265 for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map);
3266 i++)
3267 {
3268 if (mips_reloc_map[i].bfd_val == code)
3269 return &howto_table[(int) mips_reloc_map[i].elf_val];
3270 }
3271
3272 for (i = 0; i < sizeof (mips16_reloc_map) / sizeof (struct elf_reloc_map);
3273 i++)
3274 {
3275 if (mips16_reloc_map[i].bfd_val == code)
3276 return &howto16_table[(int) mips16_reloc_map[i].elf_val];
3277 }
3278
3279 for (i = 0; i < sizeof (micromips_reloc_map) / sizeof (struct elf_reloc_map);
3280 i++)
3281 {
3282 if (micromips_reloc_map[i].bfd_val == code)
3283 return &howto_micromips_table[(int) micromips_reloc_map[i].elf_val];
3284 }
3285
3286 switch (code)
3287 {
3288 case BFD_RELOC_VTABLE_INHERIT:
3289 return &elf_mips_gnu_vtinherit_howto;
3290 case BFD_RELOC_VTABLE_ENTRY:
3291 return &elf_mips_gnu_vtentry_howto;
3292 case BFD_RELOC_32_PCREL:
3293 return &elf_mips_gnu_pcrel32;
3294 case BFD_RELOC_MIPS_EH:
3295 return &elf_mips_eh_howto;
3296 case BFD_RELOC_MIPS_COPY:
3297 return &elf_mips_copy_howto;
3298 case BFD_RELOC_MIPS_JUMP_SLOT:
3299 return &elf_mips_jump_slot_howto;
3300 default:
3301 bfd_set_error (bfd_error_bad_value);
3302 return NULL;
3303 }
3304 }
3305
3306 static reloc_howto_type *
3307 bfd_elf64_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
3308 const char *r_name)
3309 {
3310 unsigned int i;
3311
3312 for (i = 0;
3313 i < (sizeof (mips_elf64_howto_table_rela)
3314 / sizeof (mips_elf64_howto_table_rela[0])); i++)
3315 if (mips_elf64_howto_table_rela[i].name != NULL
3316 && strcasecmp (mips_elf64_howto_table_rela[i].name, r_name) == 0)
3317 return &mips_elf64_howto_table_rela[i];
3318
3319 for (i = 0;
3320 i < (sizeof (mips16_elf64_howto_table_rela)
3321 / sizeof (mips16_elf64_howto_table_rela[0]));
3322 i++)
3323 if (mips16_elf64_howto_table_rela[i].name != NULL
3324 && strcasecmp (mips16_elf64_howto_table_rela[i].name, r_name) == 0)
3325 return &mips16_elf64_howto_table_rela[i];
3326
3327 for (i = 0;
3328 i < (sizeof (micromips_elf64_howto_table_rela)
3329 / sizeof (micromips_elf64_howto_table_rela[0]));
3330 i++)
3331 if (micromips_elf64_howto_table_rela[i].name != NULL
3332 && strcasecmp (micromips_elf64_howto_table_rela[i].name, r_name) == 0)
3333 return &micromips_elf64_howto_table_rela[i];
3334
3335 if (strcasecmp (elf_mips_gnu_vtinherit_howto.name, r_name) == 0)
3336 return &elf_mips_gnu_vtinherit_howto;
3337 if (strcasecmp (elf_mips_gnu_vtentry_howto.name, r_name) == 0)
3338 return &elf_mips_gnu_vtentry_howto;
3339 if (strcasecmp (elf_mips_gnu_rel16_s2.name, r_name) == 0)
3340 return &elf_mips_gnu_rel16_s2;
3341 if (strcasecmp (elf_mips_gnu_rela16_s2.name, r_name) == 0)
3342 return &elf_mips_gnu_rela16_s2;
3343 if (strcasecmp (elf_mips_gnu_pcrel32.name, r_name) == 0)
3344 return &elf_mips_gnu_pcrel32;
3345 if (strcasecmp (elf_mips_eh_howto.name, r_name) == 0)
3346 return &elf_mips_eh_howto;
3347 if (strcasecmp (elf_mips_copy_howto.name, r_name) == 0)
3348 return &elf_mips_copy_howto;
3349 if (strcasecmp (elf_mips_jump_slot_howto.name, r_name) == 0)
3350 return &elf_mips_jump_slot_howto;
3351
3352 return NULL;
3353 }
3354
3355 /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */
3356
3357 static reloc_howto_type *
3358 mips_elf64_rtype_to_howto (unsigned int r_type, bfd_boolean rela_p)
3359 {
3360 switch (r_type)
3361 {
3362 case R_MIPS_GNU_VTINHERIT:
3363 return &elf_mips_gnu_vtinherit_howto;
3364 case R_MIPS_GNU_VTENTRY:
3365 return &elf_mips_gnu_vtentry_howto;
3366 case R_MIPS_GNU_REL16_S2:
3367 if (rela_p)
3368 return &elf_mips_gnu_rela16_s2;
3369 else
3370 return &elf_mips_gnu_rel16_s2;
3371 case R_MIPS_PC32:
3372 return &elf_mips_gnu_pcrel32;
3373 case R_MIPS_EH:
3374 return &elf_mips_eh_howto;
3375 case R_MIPS_COPY:
3376 return &elf_mips_copy_howto;
3377 case R_MIPS_JUMP_SLOT:
3378 return &elf_mips_jump_slot_howto;
3379 default:
3380 if (r_type >= R_MICROMIPS_min && r_type < R_MICROMIPS_max)
3381 {
3382 if (rela_p)
3383 return &micromips_elf64_howto_table_rela[r_type - R_MICROMIPS_min];
3384 else
3385 return &micromips_elf64_howto_table_rel[r_type - R_MICROMIPS_min];
3386 }
3387 if (r_type >= R_MIPS16_min && r_type < R_MIPS16_max)
3388 {
3389 if (rela_p)
3390 return &mips16_elf64_howto_table_rela[r_type - R_MIPS16_min];
3391 else
3392 return &mips16_elf64_howto_table_rel[r_type - R_MIPS16_min];
3393 }
3394 BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
3395 if (rela_p)
3396 return &mips_elf64_howto_table_rela[r_type];
3397 else
3398 return &mips_elf64_howto_table_rel[r_type];
3399 break;
3400 }
3401 }
3402
3403 /* Prevent relocation handling by bfd for MIPS ELF64. */
3404
3405 static void
3406 mips_elf64_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
3407 arelent *cache_ptr ATTRIBUTE_UNUSED,
3408 Elf_Internal_Rela *dst ATTRIBUTE_UNUSED)
3409 {
3410 BFD_ASSERT (0);
3411 }
3412
3413 static void
3414 mips_elf64_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
3415 arelent *cache_ptr ATTRIBUTE_UNUSED,
3416 Elf_Internal_Rela *dst ATTRIBUTE_UNUSED)
3417 {
3418 BFD_ASSERT (0);
3419 }
3420
3421 /* Since each entry in an SHT_REL or SHT_RELA section can represent up
3422 to three relocs, we must tell the user to allocate more space. */
3423
3424 static long
3425 mips_elf64_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
3426 {
3427 return (sec->reloc_count * 3 + 1) * sizeof (arelent *);
3428 }
3429
3430 static long
3431 mips_elf64_get_dynamic_reloc_upper_bound (bfd *abfd)
3432 {
3433 return _bfd_elf_get_dynamic_reloc_upper_bound (abfd) * 3;
3434 }
3435
3436 /* We must also copy more relocations than the corresponding functions
3437 in elf.c would, so the two following functions are slightly
3438 modified from elf.c, that multiply the external relocation count by
3439 3 to obtain the internal relocation count. */
3440
3441 static long
3442 mips_elf64_canonicalize_reloc (bfd *abfd, sec_ptr section,
3443 arelent **relptr, asymbol **symbols)
3444 {
3445 arelent *tblptr;
3446 unsigned int i;
3447 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
3448
3449 if (! bed->s->slurp_reloc_table (abfd, section, symbols, FALSE))
3450 return -1;
3451
3452 tblptr = section->relocation;
3453 for (i = 0; i < section->reloc_count * 3; i++)
3454 *relptr++ = tblptr++;
3455
3456 *relptr = NULL;
3457
3458 return section->reloc_count * 3;
3459 }
3460
3461 static long
3462 mips_elf64_canonicalize_dynamic_reloc (bfd *abfd, arelent **storage,
3463 asymbol **syms)
3464 {
3465 bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
3466 asection *s;
3467 long ret;
3468
3469 if (elf_dynsymtab (abfd) == 0)
3470 {
3471 bfd_set_error (bfd_error_invalid_operation);
3472 return -1;
3473 }
3474
3475 slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
3476 ret = 0;
3477 for (s = abfd->sections; s != NULL; s = s->next)
3478 {
3479 if (elf_section_data (s)->this_hdr.sh_link == elf_dynsymtab (abfd)
3480 && (elf_section_data (s)->this_hdr.sh_type == SHT_REL
3481 || elf_section_data (s)->this_hdr.sh_type == SHT_RELA))
3482 {
3483 arelent *p;
3484 long count, i;
3485
3486 if (! (*slurp_relocs) (abfd, s, syms, TRUE))
3487 return -1;
3488 count = s->size / elf_section_data (s)->this_hdr.sh_entsize * 3;
3489 p = s->relocation;
3490 for (i = 0; i < count; i++)
3491 *storage++ = p++;
3492 ret += count;
3493 }
3494 }
3495
3496 *storage = NULL;
3497
3498 return ret;
3499 }
3500
3501 /* Read the relocations from one reloc section. This is mostly copied
3502 from elfcode.h, except for the changes to expand one external
3503 relocation to 3 internal ones. We must unfortunately set
3504 reloc_count to the number of external relocations, because a lot of
3505 generic code seems to depend on this. */
3506
3507 static bfd_boolean
3508 mips_elf64_slurp_one_reloc_table (bfd *abfd, asection *asect,
3509 Elf_Internal_Shdr *rel_hdr,
3510 bfd_size_type reloc_count,
3511 arelent *relents, asymbol **symbols,
3512 bfd_boolean dynamic)
3513 {
3514 void *allocated;
3515 bfd_byte *native_relocs;
3516 arelent *relent;
3517 bfd_vma i;
3518 int entsize;
3519 bfd_boolean rela_p;
3520
3521 allocated = bfd_malloc (rel_hdr->sh_size);
3522 if (allocated == NULL)
3523 return FALSE;
3524
3525 if (bfd_seek (abfd, rel_hdr->sh_offset, SEEK_SET) != 0
3526 || (bfd_bread (allocated, rel_hdr->sh_size, abfd)
3527 != rel_hdr->sh_size))
3528 goto error_return;
3529
3530 native_relocs = allocated;
3531
3532 entsize = rel_hdr->sh_entsize;
3533 BFD_ASSERT (entsize == sizeof (Elf64_Mips_External_Rel)
3534 || entsize == sizeof (Elf64_Mips_External_Rela));
3535
3536 if (entsize == sizeof (Elf64_Mips_External_Rel))
3537 rela_p = FALSE;
3538 else
3539 rela_p = TRUE;
3540
3541 for (i = 0, relent = relents;
3542 i < reloc_count;
3543 i++, native_relocs += entsize)
3544 {
3545 Elf64_Mips_Internal_Rela rela;
3546 bfd_boolean used_sym, used_ssym;
3547 int ir;
3548
3549 if (entsize == sizeof (Elf64_Mips_External_Rela))
3550 mips_elf64_swap_reloca_in (abfd,
3551 (Elf64_Mips_External_Rela *) native_relocs,
3552 &rela);
3553 else
3554 mips_elf64_swap_reloc_in (abfd,
3555 (Elf64_Mips_External_Rel *) native_relocs,
3556 &rela);
3557
3558 /* Each entry represents exactly three actual relocations. */
3559
3560 used_sym = FALSE;
3561 used_ssym = FALSE;
3562 for (ir = 0; ir < 3; ir++)
3563 {
3564 enum elf_mips_reloc_type type;
3565
3566 switch (ir)
3567 {
3568 default:
3569 abort ();
3570 case 0:
3571 type = (enum elf_mips_reloc_type) rela.r_type;
3572 break;
3573 case 1:
3574 type = (enum elf_mips_reloc_type) rela.r_type2;
3575 break;
3576 case 2:
3577 type = (enum elf_mips_reloc_type) rela.r_type3;
3578 break;
3579 }
3580
3581 /* Some types require symbols, whereas some do not. */
3582 switch (type)
3583 {
3584 case R_MIPS_NONE:
3585 case R_MIPS_LITERAL:
3586 case R_MIPS_INSERT_A:
3587 case R_MIPS_INSERT_B:
3588 case R_MIPS_DELETE:
3589 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
3590 break;
3591
3592 default:
3593 if (! used_sym)
3594 {
3595 if (rela.r_sym == STN_UNDEF)
3596 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
3597 else
3598 {
3599 asymbol **ps, *s;
3600
3601 ps = symbols + rela.r_sym - 1;
3602 s = *ps;
3603 if ((s->flags & BSF_SECTION_SYM) == 0)
3604 relent->sym_ptr_ptr = ps;
3605 else
3606 relent->sym_ptr_ptr = s->section->symbol_ptr_ptr;
3607 }
3608
3609 used_sym = TRUE;
3610 }
3611 else if (! used_ssym)
3612 {
3613 switch (rela.r_ssym)
3614 {
3615 case RSS_UNDEF:
3616 relent->sym_ptr_ptr =
3617 bfd_abs_section_ptr->symbol_ptr_ptr;
3618 break;
3619
3620 case RSS_GP:
3621 case RSS_GP0:
3622 case RSS_LOC:
3623 /* FIXME: I think these need to be handled using
3624 special howto structures. */
3625 BFD_ASSERT (0);
3626 break;
3627
3628 default:
3629 BFD_ASSERT (0);
3630 break;
3631 }
3632
3633 used_ssym = TRUE;
3634 }
3635 else
3636 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
3637
3638 break;
3639 }
3640
3641 /* The address of an ELF reloc is section relative for an
3642 object file, and absolute for an executable file or
3643 shared library. The address of a BFD reloc is always
3644 section relative. */
3645 if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0 || dynamic)
3646 relent->address = rela.r_offset;
3647 else
3648 relent->address = rela.r_offset - asect->vma;
3649
3650 relent->addend = rela.r_addend;
3651
3652 relent->howto = mips_elf64_rtype_to_howto (type, rela_p);
3653
3654 ++relent;
3655 }
3656 }
3657
3658 asect->reloc_count += (relent - relents) / 3;
3659
3660 if (allocated != NULL)
3661 free (allocated);
3662
3663 return TRUE;
3664
3665 error_return:
3666 if (allocated != NULL)
3667 free (allocated);
3668 return FALSE;
3669 }
3670
3671 /* Read the relocations. On Irix 6, there can be two reloc sections
3672 associated with a single data section. This is copied from
3673 elfcode.h as well, with changes as small as accounting for 3
3674 internal relocs per external reloc and resetting reloc_count to
3675 zero before processing the relocs of a section. */
3676
3677 static bfd_boolean
3678 mips_elf64_slurp_reloc_table (bfd *abfd, asection *asect,
3679 asymbol **symbols, bfd_boolean dynamic)
3680 {
3681 struct bfd_elf_section_data * const d = elf_section_data (asect);
3682 Elf_Internal_Shdr *rel_hdr;
3683 Elf_Internal_Shdr *rel_hdr2;
3684 bfd_size_type reloc_count;
3685 bfd_size_type reloc_count2;
3686 arelent *relents;
3687 bfd_size_type amt;
3688
3689 if (asect->relocation != NULL)
3690 return TRUE;
3691
3692 if (! dynamic)
3693 {
3694 if ((asect->flags & SEC_RELOC) == 0
3695 || asect->reloc_count == 0)
3696 return TRUE;
3697
3698 rel_hdr = d->rel.hdr;
3699 reloc_count = rel_hdr ? NUM_SHDR_ENTRIES (rel_hdr) : 0;
3700 rel_hdr2 = d->rela.hdr;
3701 reloc_count2 = (rel_hdr2 ? NUM_SHDR_ENTRIES (rel_hdr2) : 0);
3702
3703 BFD_ASSERT (asect->reloc_count == reloc_count + reloc_count2);
3704 BFD_ASSERT ((rel_hdr && asect->rel_filepos == rel_hdr->sh_offset)
3705 || (rel_hdr2 && asect->rel_filepos == rel_hdr2->sh_offset));
3706
3707 }
3708 else
3709 {
3710 /* Note that ASECT->RELOC_COUNT tends not to be accurate in this
3711 case because relocations against this section may use the
3712 dynamic symbol table, and in that case bfd_section_from_shdr
3713 in elf.c does not update the RELOC_COUNT. */
3714 if (asect->size == 0)
3715 return TRUE;
3716
3717 rel_hdr = &d->this_hdr;
3718 reloc_count = NUM_SHDR_ENTRIES (rel_hdr);
3719 rel_hdr2 = NULL;
3720 reloc_count2 = 0;
3721 }
3722
3723 /* Allocate space for 3 arelent structures for each Rel structure. */
3724 amt = (reloc_count + reloc_count2) * 3 * sizeof (arelent);
3725 relents = bfd_alloc (abfd, amt);
3726 if (relents == NULL)
3727 return FALSE;
3728
3729 /* The slurp_one_reloc_table routine increments reloc_count. */
3730 asect->reloc_count = 0;
3731
3732 if (rel_hdr != NULL
3733 && ! mips_elf64_slurp_one_reloc_table (abfd, asect,
3734 rel_hdr, reloc_count,
3735 relents,
3736 symbols, dynamic))
3737 return FALSE;
3738 if (rel_hdr2 != NULL
3739 && ! mips_elf64_slurp_one_reloc_table (abfd, asect,
3740 rel_hdr2, reloc_count2,
3741 relents + reloc_count * 3,
3742 symbols, dynamic))
3743 return FALSE;
3744
3745 asect->relocation = relents;
3746 return TRUE;
3747 }
3748
3749 /* Write out the relocations. */
3750
3751 static void
3752 mips_elf64_write_relocs (bfd *abfd, asection *sec, void *data)
3753 {
3754 bfd_boolean *failedp = data;
3755 int count;
3756 Elf_Internal_Shdr *rel_hdr;
3757 unsigned int idx;
3758
3759 /* If we have already failed, don't do anything. */
3760 if (*failedp)
3761 return;
3762
3763 if ((sec->flags & SEC_RELOC) == 0)
3764 return;
3765
3766 /* The linker backend writes the relocs out itself, and sets the
3767 reloc_count field to zero to inhibit writing them here. Also,
3768 sometimes the SEC_RELOC flag gets set even when there aren't any
3769 relocs. */
3770 if (sec->reloc_count == 0)
3771 return;
3772
3773 /* We can combine up to three relocs that refer to the same address
3774 if the latter relocs have no associated symbol. */
3775 count = 0;
3776 for (idx = 0; idx < sec->reloc_count; idx++)
3777 {
3778 bfd_vma addr;
3779 unsigned int i;
3780
3781 ++count;
3782
3783 addr = sec->orelocation[idx]->address;
3784 for (i = 0; i < 2; i++)
3785 {
3786 arelent *r;
3787
3788 if (idx + 1 >= sec->reloc_count)
3789 break;
3790 r = sec->orelocation[idx + 1];
3791 if (r->address != addr
3792 || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
3793 || (*r->sym_ptr_ptr)->value != 0)
3794 break;
3795
3796 /* We can merge the reloc at IDX + 1 with the reloc at IDX. */
3797
3798 ++idx;
3799 }
3800 }
3801
3802 rel_hdr = _bfd_elf_single_rel_hdr (sec);
3803
3804 /* Do the actual relocation. */
3805
3806 if (rel_hdr->sh_entsize == sizeof(Elf64_Mips_External_Rel))
3807 mips_elf64_write_rel (abfd, sec, rel_hdr, &count, data);
3808 else if (rel_hdr->sh_entsize == sizeof(Elf64_Mips_External_Rela))
3809 mips_elf64_write_rela (abfd, sec, rel_hdr, &count, data);
3810 else
3811 BFD_ASSERT (0);
3812 }
3813
3814 static void
3815 mips_elf64_write_rel (bfd *abfd, asection *sec,
3816 Elf_Internal_Shdr *rel_hdr,
3817 int *count, void *data)
3818 {
3819 bfd_boolean *failedp = data;
3820 Elf64_Mips_External_Rel *ext_rel;
3821 unsigned int idx;
3822 asymbol *last_sym = 0;
3823 int last_sym_idx = 0;
3824
3825 rel_hdr->sh_size = rel_hdr->sh_entsize * *count;
3826 rel_hdr->contents = bfd_alloc (abfd, rel_hdr->sh_size);
3827 if (rel_hdr->contents == NULL)
3828 {
3829 *failedp = TRUE;
3830 return;
3831 }
3832
3833 ext_rel = (Elf64_Mips_External_Rel *) rel_hdr->contents;
3834 for (idx = 0; idx < sec->reloc_count; idx++, ext_rel++)
3835 {
3836 arelent *ptr;
3837 Elf64_Mips_Internal_Rela int_rel;
3838 asymbol *sym;
3839 int n;
3840 unsigned int i;
3841
3842 ptr = sec->orelocation[idx];
3843
3844 /* The address of an ELF reloc is section relative for an object
3845 file, and absolute for an executable file or shared library.
3846 The address of a BFD reloc is always section relative. */
3847 if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
3848 int_rel.r_offset = ptr->address;
3849 else
3850 int_rel.r_offset = ptr->address + sec->vma;
3851
3852 sym = *ptr->sym_ptr_ptr;
3853 if (sym == last_sym)
3854 n = last_sym_idx;
3855 else if (bfd_is_abs_section (sym->section) && sym->value == 0)
3856 n = STN_UNDEF;
3857 else
3858 {
3859 last_sym = sym;
3860 n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym);
3861 if (n < 0)
3862 {
3863 *failedp = TRUE;
3864 return;
3865 }
3866 last_sym_idx = n;
3867 }
3868
3869 int_rel.r_sym = n;
3870 int_rel.r_ssym = RSS_UNDEF;
3871
3872 if ((*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
3873 && ! _bfd_elf_validate_reloc (abfd, ptr))
3874 {
3875 *failedp = TRUE;
3876 return;
3877 }
3878
3879 int_rel.r_type = ptr->howto->type;
3880 int_rel.r_type2 = (int) R_MIPS_NONE;
3881 int_rel.r_type3 = (int) R_MIPS_NONE;
3882
3883 for (i = 0; i < 2; i++)
3884 {
3885 arelent *r;
3886
3887 if (idx + 1 >= sec->reloc_count)
3888 break;
3889 r = sec->orelocation[idx + 1];
3890 if (r->address != ptr->address
3891 || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
3892 || (*r->sym_ptr_ptr)->value != 0)
3893 break;
3894
3895 /* We can merge the reloc at IDX + 1 with the reloc at IDX. */
3896
3897 if (i == 0)
3898 int_rel.r_type2 = r->howto->type;
3899 else
3900 int_rel.r_type3 = r->howto->type;
3901
3902 ++idx;
3903 }
3904
3905 mips_elf64_swap_reloc_out (abfd, &int_rel, ext_rel);
3906 }
3907
3908 BFD_ASSERT (ext_rel - (Elf64_Mips_External_Rel *) rel_hdr->contents
3909 == *count);
3910 }
3911
3912 static void
3913 mips_elf64_write_rela (bfd *abfd, asection *sec,
3914 Elf_Internal_Shdr *rela_hdr,
3915 int *count, void *data)
3916 {
3917 bfd_boolean *failedp = data;
3918 Elf64_Mips_External_Rela *ext_rela;
3919 unsigned int idx;
3920 asymbol *last_sym = 0;
3921 int last_sym_idx = 0;
3922
3923 rela_hdr->sh_size = rela_hdr->sh_entsize * *count;
3924 rela_hdr->contents = bfd_alloc (abfd, rela_hdr->sh_size);
3925 if (rela_hdr->contents == NULL)
3926 {
3927 *failedp = TRUE;
3928 return;
3929 }
3930
3931 ext_rela = (Elf64_Mips_External_Rela *) rela_hdr->contents;
3932 for (idx = 0; idx < sec->reloc_count; idx++, ext_rela++)
3933 {
3934 arelent *ptr;
3935 Elf64_Mips_Internal_Rela int_rela;
3936 asymbol *sym;
3937 int n;
3938 unsigned int i;
3939
3940 ptr = sec->orelocation[idx];
3941
3942 /* The address of an ELF reloc is section relative for an object
3943 file, and absolute for an executable file or shared library.
3944 The address of a BFD reloc is always section relative. */
3945 if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
3946 int_rela.r_offset = ptr->address;
3947 else
3948 int_rela.r_offset = ptr->address + sec->vma;
3949
3950 sym = *ptr->sym_ptr_ptr;
3951 if (sym == last_sym)
3952 n = last_sym_idx;
3953 else if (bfd_is_abs_section (sym->section) && sym->value == 0)
3954 n = STN_UNDEF;
3955 else
3956 {
3957 last_sym = sym;
3958 n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym);
3959 if (n < 0)
3960 {
3961 *failedp = TRUE;
3962 return;
3963 }
3964 last_sym_idx = n;
3965 }
3966
3967 int_rela.r_sym = n;
3968 int_rela.r_addend = ptr->addend;
3969 int_rela.r_ssym = RSS_UNDEF;
3970
3971 if ((*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
3972 && ! _bfd_elf_validate_reloc (abfd, ptr))
3973 {
3974 *failedp = TRUE;
3975 return;
3976 }
3977
3978 int_rela.r_type = ptr->howto->type;
3979 int_rela.r_type2 = (int) R_MIPS_NONE;
3980 int_rela.r_type3 = (int) R_MIPS_NONE;
3981
3982 for (i = 0; i < 2; i++)
3983 {
3984 arelent *r;
3985
3986 if (idx + 1 >= sec->reloc_count)
3987 break;
3988 r = sec->orelocation[idx + 1];
3989 if (r->address != ptr->address
3990 || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
3991 || (*r->sym_ptr_ptr)->value != 0)
3992 break;
3993
3994 /* We can merge the reloc at IDX + 1 with the reloc at IDX. */
3995
3996 if (i == 0)
3997 int_rela.r_type2 = r->howto->type;
3998 else
3999 int_rela.r_type3 = r->howto->type;
4000
4001 ++idx;
4002 }
4003
4004 mips_elf64_swap_reloca_out (abfd, &int_rela, ext_rela);
4005 }
4006
4007 BFD_ASSERT (ext_rela - (Elf64_Mips_External_Rela *) rela_hdr->contents
4008 == *count);
4009 }
4010 \f
4011 /* Set the right machine number for a MIPS ELF file. */
4012
4013 static bfd_boolean
4014 mips_elf64_object_p (bfd *abfd)
4015 {
4016 unsigned long mach;
4017
4018 /* Irix 6 is broken. Object file symbol tables are not always
4019 sorted correctly such that local symbols precede global symbols,
4020 and the sh_info field in the symbol table is not always right. */
4021 if (elf64_mips_irix_compat (abfd) != ict_none)
4022 elf_bad_symtab (abfd) = TRUE;
4023
4024 mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags);
4025 bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach);
4026 return TRUE;
4027 }
4028
4029 /* Depending on the target vector we generate some version of Irix
4030 executables or "normal" MIPS ELF ABI executables. */
4031 static irix_compat_t
4032 elf64_mips_irix_compat (bfd *abfd)
4033 {
4034 if ((abfd->xvec == &bfd_elf64_bigmips_vec)
4035 || (abfd->xvec == &bfd_elf64_littlemips_vec))
4036 return ict_irix6;
4037 else
4038 return ict_none;
4039 }
4040 \f
4041 /* Support for core dump NOTE sections. */
4042 static bfd_boolean
4043 elf64_mips_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
4044 {
4045 int offset;
4046 unsigned int size;
4047
4048 switch (note->descsz)
4049 {
4050 default:
4051 return FALSE;
4052
4053 case 480: /* Linux/MIPS - N64 kernel */
4054 /* pr_cursig */
4055 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
4056
4057 /* pr_pid */
4058 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 32);
4059
4060 /* pr_reg */
4061 offset = 112;
4062 size = 360;
4063
4064 break;
4065 }
4066
4067 /* Make a ".reg/999" section. */
4068 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
4069 size, note->descpos + offset);
4070 }
4071
4072 static bfd_boolean
4073 elf64_mips_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
4074 {
4075 switch (note->descsz)
4076 {
4077 default:
4078 return FALSE;
4079
4080 case 136: /* Linux/MIPS - N64 kernel elf_prpsinfo */
4081 elf_tdata (abfd)->core->program
4082 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
4083 elf_tdata (abfd)->core->command
4084 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
4085 }
4086
4087 /* Note that for some reason, a spurious space is tacked
4088 onto the end of the args in some (at least one anyway)
4089 implementations, so strip it off if it exists. */
4090
4091 {
4092 char *command = elf_tdata (abfd)->core->command;
4093 int n = strlen (command);
4094
4095 if (0 < n && command[n - 1] == ' ')
4096 command[n - 1] = '\0';
4097 }
4098
4099 return TRUE;
4100 }
4101 \f
4102 /* ECOFF swapping routines. These are used when dealing with the
4103 .mdebug section, which is in the ECOFF debugging format. */
4104 static const struct ecoff_debug_swap mips_elf64_ecoff_debug_swap =
4105 {
4106 /* Symbol table magic number. */
4107 magicSym2,
4108 /* Alignment of debugging information. E.g., 4. */
4109 8,
4110 /* Sizes of external symbolic information. */
4111 sizeof (struct hdr_ext),
4112 sizeof (struct dnr_ext),
4113 sizeof (struct pdr_ext),
4114 sizeof (struct sym_ext),
4115 sizeof (struct opt_ext),
4116 sizeof (struct fdr_ext),
4117 sizeof (struct rfd_ext),
4118 sizeof (struct ext_ext),
4119 /* Functions to swap in external symbolic data. */
4120 ecoff_swap_hdr_in,
4121 ecoff_swap_dnr_in,
4122 ecoff_swap_pdr_in,
4123 ecoff_swap_sym_in,
4124 ecoff_swap_opt_in,
4125 ecoff_swap_fdr_in,
4126 ecoff_swap_rfd_in,
4127 ecoff_swap_ext_in,
4128 _bfd_ecoff_swap_tir_in,
4129 _bfd_ecoff_swap_rndx_in,
4130 /* Functions to swap out external symbolic data. */
4131 ecoff_swap_hdr_out,
4132 ecoff_swap_dnr_out,
4133 ecoff_swap_pdr_out,
4134 ecoff_swap_sym_out,
4135 ecoff_swap_opt_out,
4136 ecoff_swap_fdr_out,
4137 ecoff_swap_rfd_out,
4138 ecoff_swap_ext_out,
4139 _bfd_ecoff_swap_tir_out,
4140 _bfd_ecoff_swap_rndx_out,
4141 /* Function to read in symbolic data. */
4142 _bfd_mips_elf_read_ecoff_info
4143 };
4144 \f
4145 /* Relocations in the 64 bit MIPS ELF ABI are more complex than in
4146 standard ELF. This structure is used to redirect the relocation
4147 handling routines. */
4148
4149 const struct elf_size_info mips_elf64_size_info =
4150 {
4151 sizeof (Elf64_External_Ehdr),
4152 sizeof (Elf64_External_Phdr),
4153 sizeof (Elf64_External_Shdr),
4154 sizeof (Elf64_Mips_External_Rel),
4155 sizeof (Elf64_Mips_External_Rela),
4156 sizeof (Elf64_External_Sym),
4157 sizeof (Elf64_External_Dyn),
4158 sizeof (Elf_External_Note),
4159 4, /* hash-table entry size */
4160 3, /* internal relocations per external relocations */
4161 64, /* arch_size */
4162 3, /* log_file_align */
4163 ELFCLASS64,
4164 EV_CURRENT,
4165 bfd_elf64_write_out_phdrs,
4166 bfd_elf64_write_shdrs_and_ehdr,
4167 bfd_elf64_checksum_contents,
4168 mips_elf64_write_relocs,
4169 bfd_elf64_swap_symbol_in,
4170 bfd_elf64_swap_symbol_out,
4171 mips_elf64_slurp_reloc_table,
4172 bfd_elf64_slurp_symbol_table,
4173 bfd_elf64_swap_dyn_in,
4174 bfd_elf64_swap_dyn_out,
4175 mips_elf64_be_swap_reloc_in,
4176 mips_elf64_be_swap_reloc_out,
4177 mips_elf64_be_swap_reloca_in,
4178 mips_elf64_be_swap_reloca_out
4179 };
4180
4181 #define ELF_ARCH bfd_arch_mips
4182 #define ELF_TARGET_ID MIPS_ELF_DATA
4183 #define ELF_MACHINE_CODE EM_MIPS
4184
4185 #define elf_backend_collect TRUE
4186 #define elf_backend_type_change_ok TRUE
4187 #define elf_backend_can_gc_sections TRUE
4188 #define elf_info_to_howto mips_elf64_info_to_howto_rela
4189 #define elf_info_to_howto_rel mips_elf64_info_to_howto_rel
4190 #define elf_backend_object_p mips_elf64_object_p
4191 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
4192 #define elf_backend_section_processing _bfd_mips_elf_section_processing
4193 #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
4194 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
4195 #define elf_backend_section_from_bfd_section \
4196 _bfd_mips_elf_section_from_bfd_section
4197 #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
4198 #define elf_backend_link_output_symbol_hook \
4199 _bfd_mips_elf_link_output_symbol_hook
4200 #define elf_backend_create_dynamic_sections \
4201 _bfd_mips_elf_create_dynamic_sections
4202 #define elf_backend_check_relocs _bfd_mips_elf_check_relocs
4203 #define elf_backend_merge_symbol_attribute \
4204 _bfd_mips_elf_merge_symbol_attribute
4205 #define elf_backend_get_target_dtag _bfd_mips_elf_get_target_dtag
4206 #define elf_backend_adjust_dynamic_symbol \
4207 _bfd_mips_elf_adjust_dynamic_symbol
4208 #define elf_backend_always_size_sections \
4209 _bfd_mips_elf_always_size_sections
4210 #define elf_backend_size_dynamic_sections \
4211 _bfd_mips_elf_size_dynamic_sections
4212 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4213 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section
4214 #define elf_backend_finish_dynamic_symbol \
4215 _bfd_mips_elf_finish_dynamic_symbol
4216 #define elf_backend_finish_dynamic_sections \
4217 _bfd_mips_elf_finish_dynamic_sections
4218 #define elf_backend_final_write_processing \
4219 _bfd_mips_elf_final_write_processing
4220 #define elf_backend_additional_program_headers \
4221 _bfd_mips_elf_additional_program_headers
4222 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
4223 #define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
4224 #define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
4225 #define elf_backend_copy_indirect_symbol \
4226 _bfd_mips_elf_copy_indirect_symbol
4227 #define elf_backend_ignore_discarded_relocs \
4228 _bfd_mips_elf_ignore_discarded_relocs
4229 #define elf_backend_mips_irix_compat elf64_mips_irix_compat
4230 #define elf_backend_mips_rtype_to_howto mips_elf64_rtype_to_howto
4231 #define elf_backend_ecoff_debug_swap &mips_elf64_ecoff_debug_swap
4232 #define elf_backend_size_info mips_elf64_size_info
4233
4234 #define elf_backend_grok_prstatus elf64_mips_grok_prstatus
4235 #define elf_backend_grok_psinfo elf64_mips_grok_psinfo
4236
4237 #define elf_backend_got_header_size (8 * MIPS_RESERVED_GOTNO)
4238
4239 /* MIPS ELF64 can use a mixture of REL and RELA, but some Relocations
4240 work better/work only in RELA, so we default to this. */
4241 #define elf_backend_may_use_rel_p 1
4242 #define elf_backend_may_use_rela_p 1
4243 #define elf_backend_default_use_rela_p 1
4244 #define elf_backend_rela_plts_and_copies_p 0
4245 #define elf_backend_plt_readonly 1
4246 #define elf_backend_plt_sym_val _bfd_mips_elf_plt_sym_val
4247
4248 #define elf_backend_sign_extend_vma TRUE
4249
4250 #define elf_backend_write_section _bfd_mips_elf_write_section
4251
4252 /* We don't set bfd_elf64_bfd_is_local_label_name because the 32-bit
4253 MIPS-specific function only applies to IRIX5, which had no 64-bit
4254 ABI. */
4255 #define bfd_elf64_bfd_is_target_special_symbol \
4256 _bfd_mips_elf_is_target_special_symbol
4257 #define bfd_elf64_find_nearest_line _bfd_mips_elf_find_nearest_line
4258 #define bfd_elf64_find_inliner_info _bfd_mips_elf_find_inliner_info
4259 #define bfd_elf64_new_section_hook _bfd_mips_elf_new_section_hook
4260 #define bfd_elf64_set_section_contents _bfd_mips_elf_set_section_contents
4261 #define bfd_elf64_bfd_get_relocated_section_contents \
4262 _bfd_elf_mips_get_relocated_section_contents
4263 #define bfd_elf64_bfd_link_hash_table_create \
4264 _bfd_mips_elf_link_hash_table_create
4265 #define bfd_elf64_bfd_final_link _bfd_mips_elf_final_link
4266 #define bfd_elf64_bfd_merge_private_bfd_data \
4267 _bfd_mips_elf_merge_private_bfd_data
4268 #define bfd_elf64_bfd_set_private_flags _bfd_mips_elf_set_private_flags
4269 #define bfd_elf64_bfd_print_private_bfd_data \
4270 _bfd_mips_elf_print_private_bfd_data
4271
4272 #define bfd_elf64_get_reloc_upper_bound mips_elf64_get_reloc_upper_bound
4273 #define bfd_elf64_canonicalize_reloc mips_elf64_canonicalize_reloc
4274 #define bfd_elf64_get_dynamic_reloc_upper_bound mips_elf64_get_dynamic_reloc_upper_bound
4275 #define bfd_elf64_canonicalize_dynamic_reloc mips_elf64_canonicalize_dynamic_reloc
4276 #define bfd_elf64_bfd_relax_section _bfd_mips_relax_section
4277 #define bfd_elf64_mkobject _bfd_mips_elf_mkobject
4278
4279 /* MIPS ELF64 archive functions. */
4280 #define bfd_elf64_archive_functions
4281 extern bfd_boolean bfd_elf64_archive_slurp_armap
4282 (bfd *);
4283 extern bfd_boolean bfd_elf64_archive_write_armap
4284 (bfd *, unsigned int, struct orl *, unsigned int, int);
4285 #define bfd_elf64_archive_slurp_extended_name_table \
4286 _bfd_archive_coff_slurp_extended_name_table
4287 #define bfd_elf64_archive_construct_extended_name_table \
4288 _bfd_archive_coff_construct_extended_name_table
4289 #define bfd_elf64_archive_truncate_arname \
4290 _bfd_archive_coff_truncate_arname
4291 #define bfd_elf64_archive_read_ar_hdr _bfd_archive_coff_read_ar_hdr
4292 #define bfd_elf64_archive_write_ar_hdr _bfd_archive_coff_write_ar_hdr
4293 #define bfd_elf64_archive_openr_next_archived_file \
4294 _bfd_archive_coff_openr_next_archived_file
4295 #define bfd_elf64_archive_get_elt_at_index \
4296 _bfd_archive_coff_get_elt_at_index
4297 #define bfd_elf64_archive_generic_stat_arch_elt \
4298 _bfd_archive_coff_generic_stat_arch_elt
4299 #define bfd_elf64_archive_update_armap_timestamp \
4300 _bfd_archive_coff_update_armap_timestamp
4301
4302 /* The SGI style (n)64 NewABI. */
4303 #define TARGET_LITTLE_SYM bfd_elf64_littlemips_vec
4304 #define TARGET_LITTLE_NAME "elf64-littlemips"
4305 #define TARGET_BIG_SYM bfd_elf64_bigmips_vec
4306 #define TARGET_BIG_NAME "elf64-bigmips"
4307
4308 #define ELF_MAXPAGESIZE 0x10000
4309 #define ELF_COMMONPAGESIZE 0x1000
4310
4311 #include "elf64-target.h"
4312
4313 /* The SYSV-style 'traditional' (n)64 NewABI. */
4314 #undef TARGET_LITTLE_SYM
4315 #undef TARGET_LITTLE_NAME
4316 #undef TARGET_BIG_SYM
4317 #undef TARGET_BIG_NAME
4318
4319 #undef ELF_MAXPAGESIZE
4320 #undef ELF_COMMONPAGESIZE
4321
4322 #define TARGET_LITTLE_SYM bfd_elf64_tradlittlemips_vec
4323 #define TARGET_LITTLE_NAME "elf64-tradlittlemips"
4324 #define TARGET_BIG_SYM bfd_elf64_tradbigmips_vec
4325 #define TARGET_BIG_NAME "elf64-tradbigmips"
4326
4327 #define ELF_MAXPAGESIZE 0x10000
4328 #define ELF_COMMONPAGESIZE 0x1000
4329 #define elf64_bed elf64_tradbed
4330
4331 /* Include the target file again for this target. */
4332 #include "elf64-target.h"
4333
4334
4335 /* FreeBSD support. */
4336
4337 #undef TARGET_LITTLE_SYM
4338 #undef TARGET_LITTLE_NAME
4339 #undef TARGET_BIG_SYM
4340 #undef TARGET_BIG_NAME
4341
4342 #define TARGET_LITTLE_SYM bfd_elf64_tradlittlemips_freebsd_vec
4343 #define TARGET_LITTLE_NAME "elf64-tradlittlemips-freebsd"
4344 #define TARGET_BIG_SYM bfd_elf64_tradbigmips_freebsd_vec
4345 #define TARGET_BIG_NAME "elf64-tradbigmips-freebsd"
4346
4347 #undef ELF_OSABI
4348 #define ELF_OSABI ELFOSABI_FREEBSD
4349
4350 #undef elf64_bed
4351 #define elf64_bed elf64_fbsd_tradbed
4352
4353 #include "elf64-target.h"