s/boolean/bfd_boolean/ s/true/TRUE/ s/false/FALSE/. Simplify
[deliverable/binutils-gdb.git] / bfd / elfn32-mips.c
1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4
5 Most of the information added by Ian Lance Taylor, Cygnus Support,
6 <ian@cygnus.com>.
7 N32/64 ABI support added by Mark Mitchell, CodeSourcery, LLC.
8 <mark@codesourcery.com>
9 Traditional MIPS targets support added by Koundinya.K, Dansk Data
10 Elektronik & Operations Research Group. <kk@ddeorg.soft.net>
11
12 This file is part of BFD, the Binary File Descriptor library.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27
28 /* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
29 different MIPS ELF from other targets. This matters when linking.
30 This file supports both, switching at runtime. */
31
32 #include "bfd.h"
33 #include "sysdep.h"
34 #include "libbfd.h"
35 #include "bfdlink.h"
36 #include "genlink.h"
37 #include "elf-bfd.h"
38 #include "elfxx-mips.h"
39 #include "elf/mips.h"
40
41 /* Get the ECOFF swapping routines. */
42 #include "coff/sym.h"
43 #include "coff/symconst.h"
44 #include "coff/internal.h"
45 #include "coff/ecoff.h"
46 #include "coff/mips.h"
47 #define ECOFF_SIGNED_32
48 #include "ecoffswap.h"
49
50 static bfd_reloc_status_type mips_elf_generic_reloc
51 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
52 static bfd_reloc_status_type mips_elf_hi16_reloc
53 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
54 static bfd_reloc_status_type mips_elf_lo16_reloc
55 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
56 static bfd_reloc_status_type mips_elf_got16_reloc
57 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
58 static bfd_boolean mips_elf_assign_gp
59 PARAMS ((bfd *, bfd_vma *));
60 static bfd_reloc_status_type mips_elf_final_gp
61 PARAMS ((bfd *, asymbol *, bfd_boolean, char **, bfd_vma *));
62 static bfd_reloc_status_type mips_elf_gprel16_reloc
63 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
64 static bfd_reloc_status_type mips_elf_literal_reloc
65 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
66 static bfd_reloc_status_type mips_elf_gprel32_reloc
67 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
68 static bfd_reloc_status_type gprel32_with_gp
69 PARAMS ((bfd *, asymbol *, arelent *, asection *, bfd_boolean, PTR,
70 bfd_vma));
71 static bfd_reloc_status_type mips_elf_shift6_reloc
72 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
73 static bfd_reloc_status_type mips16_jump_reloc
74 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
75 static bfd_reloc_status_type mips16_gprel_reloc
76 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
77 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
78 PARAMS ((bfd *, bfd_reloc_code_real_type));
79 static reloc_howto_type *mips_elf_n32_rtype_to_howto
80 PARAMS ((unsigned int, bfd_boolean));
81 static void mips_info_to_howto_rel
82 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
83 static void mips_info_to_howto_rela
84 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
85 static bfd_boolean mips_elf_sym_is_global
86 PARAMS ((bfd *, asymbol *));
87 static bfd_boolean mips_elf_n32_object_p
88 PARAMS ((bfd *));
89 static bfd_boolean elf32_mips_grok_prstatus
90 PARAMS ((bfd *, Elf_Internal_Note *));
91 static bfd_boolean elf32_mips_grok_psinfo
92 PARAMS ((bfd *, Elf_Internal_Note *));
93 static irix_compat_t elf_n32_mips_irix_compat
94 PARAMS ((bfd *));
95
96 extern const bfd_target bfd_elf32_nbigmips_vec;
97 extern const bfd_target bfd_elf32_nlittlemips_vec;
98
99 static bfd_vma prev_reloc_address = -1;
100 static bfd_vma prev_reloc_addend = 0;
101
102 /* Nonzero if ABFD is using the N32 ABI. */
103 #define ABI_N32_P(abfd) \
104 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
105
106 /* Whether we are trying to be compatible with IRIX at all. */
107 #define SGI_COMPAT(abfd) \
108 (elf_n32_mips_irix_compat (abfd) != ict_none)
109
110 /* The number of local .got entries we reserve. */
111 #define MIPS_RESERVED_GOTNO (2)
112
113 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
114 from smaller values. Start with zero, widen, *then* decrement. */
115 #define MINUS_ONE (((bfd_vma)0) - 1)
116
117 /* The relocation table used for SHT_REL sections. */
118
119 static reloc_howto_type elf_mips_howto_table_rel[] =
120 {
121 /* No relocation. */
122 HOWTO (R_MIPS_NONE, /* type */
123 0, /* rightshift */
124 0, /* size (0 = byte, 1 = short, 2 = long) */
125 0, /* bitsize */
126 FALSE, /* pc_relative */
127 0, /* bitpos */
128 complain_overflow_dont, /* complain_on_overflow */
129 mips_elf_generic_reloc, /* special_function */
130 "R_MIPS_NONE", /* name */
131 FALSE, /* partial_inplace */
132 0, /* src_mask */
133 0, /* dst_mask */
134 FALSE), /* pcrel_offset */
135
136 /* 16 bit relocation. */
137 HOWTO (R_MIPS_16, /* type */
138 0, /* rightshift */
139 2, /* size (0 = byte, 1 = short, 2 = long) */
140 16, /* bitsize */
141 FALSE, /* pc_relative */
142 0, /* bitpos */
143 complain_overflow_signed, /* complain_on_overflow */
144 mips_elf_generic_reloc, /* special_function */
145 "R_MIPS_16", /* name */
146 TRUE, /* partial_inplace */
147 0x0000ffff, /* src_mask */
148 0x0000ffff, /* dst_mask */
149 FALSE), /* pcrel_offset */
150
151 /* 32 bit relocation. */
152 HOWTO (R_MIPS_32, /* type */
153 0, /* rightshift */
154 2, /* size (0 = byte, 1 = short, 2 = long) */
155 32, /* bitsize */
156 FALSE, /* pc_relative */
157 0, /* bitpos */
158 complain_overflow_dont, /* complain_on_overflow */
159 mips_elf_generic_reloc, /* special_function */
160 "R_MIPS_32", /* name */
161 TRUE, /* partial_inplace */
162 0xffffffff, /* src_mask */
163 0xffffffff, /* dst_mask */
164 FALSE), /* pcrel_offset */
165
166 /* 32 bit symbol relative relocation. */
167 HOWTO (R_MIPS_REL32, /* type */
168 0, /* rightshift */
169 2, /* size (0 = byte, 1 = short, 2 = long) */
170 32, /* bitsize */
171 FALSE, /* pc_relative */
172 0, /* bitpos */
173 complain_overflow_dont, /* complain_on_overflow */
174 mips_elf_generic_reloc, /* special_function */
175 "R_MIPS_REL32", /* name */
176 TRUE, /* partial_inplace */
177 0xffffffff, /* src_mask */
178 0xffffffff, /* dst_mask */
179 FALSE), /* pcrel_offset */
180
181 /* 26 bit jump address. */
182 HOWTO (R_MIPS_26, /* type */
183 2, /* rightshift */
184 2, /* size (0 = byte, 1 = short, 2 = long) */
185 26, /* bitsize */
186 FALSE, /* pc_relative */
187 0, /* bitpos */
188 complain_overflow_dont, /* complain_on_overflow */
189 /* This needs complex overflow
190 detection, because the upper four
191 bits must match the PC + 4. */
192 mips_elf_generic_reloc, /* special_function */
193 "R_MIPS_26", /* name */
194 TRUE, /* partial_inplace */
195 0x03ffffff, /* src_mask */
196 0x03ffffff, /* dst_mask */
197 FALSE), /* pcrel_offset */
198
199 /* R_MIPS_HI16 and R_MIPS_LO16 are unsupported for NewABI REL.
200 However, the native IRIX6 tools use them, so we try our best. */
201
202 /* High 16 bits of symbol value. */
203 HOWTO (R_MIPS_HI16, /* type */
204 0, /* rightshift */
205 2, /* size (0 = byte, 1 = short, 2 = long) */
206 16, /* bitsize */
207 FALSE, /* pc_relative */
208 0, /* bitpos */
209 complain_overflow_dont, /* complain_on_overflow */
210 mips_elf_hi16_reloc, /* special_function */
211 "R_MIPS_HI16", /* name */
212 TRUE, /* partial_inplace */
213 0x0000ffff, /* src_mask */
214 0x0000ffff, /* dst_mask */
215 FALSE), /* pcrel_offset */
216
217 /* Low 16 bits of symbol value. */
218 HOWTO (R_MIPS_LO16, /* type */
219 0, /* rightshift */
220 2, /* size (0 = byte, 1 = short, 2 = long) */
221 16, /* bitsize */
222 FALSE, /* pc_relative */
223 0, /* bitpos */
224 complain_overflow_dont, /* complain_on_overflow */
225 mips_elf_lo16_reloc, /* special_function */
226 "R_MIPS_LO16", /* name */
227 TRUE, /* partial_inplace */
228 0x0000ffff, /* src_mask */
229 0x0000ffff, /* dst_mask */
230 FALSE), /* pcrel_offset */
231
232 /* GP relative reference. */
233 HOWTO (R_MIPS_GPREL16, /* type */
234 0, /* rightshift */
235 2, /* size (0 = byte, 1 = short, 2 = long) */
236 16, /* bitsize */
237 FALSE, /* pc_relative */
238 0, /* bitpos */
239 complain_overflow_signed, /* complain_on_overflow */
240 mips_elf_gprel16_reloc, /* special_function */
241 "R_MIPS_GPREL16", /* name */
242 TRUE, /* partial_inplace */
243 0x0000ffff, /* src_mask */
244 0x0000ffff, /* dst_mask */
245 FALSE), /* pcrel_offset */
246
247 /* Reference to literal section. */
248 HOWTO (R_MIPS_LITERAL, /* type */
249 0, /* rightshift */
250 2, /* size (0 = byte, 1 = short, 2 = long) */
251 16, /* bitsize */
252 FALSE, /* pc_relative */
253 0, /* bitpos */
254 complain_overflow_signed, /* complain_on_overflow */
255 mips_elf_literal_reloc, /* special_function */
256 "R_MIPS_LITERAL", /* name */
257 TRUE, /* partial_inplace */
258 0x0000ffff, /* src_mask */
259 0x0000ffff, /* dst_mask */
260 FALSE), /* pcrel_offset */
261
262 /* Reference to global offset table. */
263 HOWTO (R_MIPS_GOT16, /* type */
264 0, /* rightshift */
265 2, /* size (0 = byte, 1 = short, 2 = long) */
266 16, /* bitsize */
267 FALSE, /* pc_relative */
268 0, /* bitpos */
269 complain_overflow_signed, /* complain_on_overflow */
270 mips_elf_got16_reloc, /* special_function */
271 "R_MIPS_GOT16", /* name */
272 TRUE, /* partial_inplace */
273 0x0000ffff, /* src_mask */
274 0x0000ffff, /* dst_mask */
275 FALSE), /* pcrel_offset */
276
277 /* 16 bit PC relative reference. */
278 HOWTO (R_MIPS_PC16, /* type */
279 0, /* rightshift */
280 2, /* size (0 = byte, 1 = short, 2 = long) */
281 16, /* bitsize */
282 TRUE, /* pc_relative */
283 0, /* bitpos */
284 complain_overflow_signed, /* complain_on_overflow */
285 mips_elf_generic_reloc, /* special_function */
286 "R_MIPS_PC16", /* name */
287 TRUE, /* partial_inplace */
288 0x0000ffff, /* src_mask */
289 0x0000ffff, /* dst_mask */
290 TRUE), /* pcrel_offset */
291
292 /* 16 bit call through global offset table. */
293 HOWTO (R_MIPS_CALL16, /* type */
294 0, /* rightshift */
295 2, /* size (0 = byte, 1 = short, 2 = long) */
296 16, /* bitsize */
297 FALSE, /* pc_relative */
298 0, /* bitpos */
299 complain_overflow_signed, /* complain_on_overflow */
300 mips_elf_generic_reloc, /* special_function */
301 "R_MIPS_CALL16", /* name */
302 TRUE, /* partial_inplace */
303 0x0000ffff, /* src_mask */
304 0x0000ffff, /* dst_mask */
305 FALSE), /* pcrel_offset */
306
307 /* 32 bit GP relative reference. */
308 HOWTO (R_MIPS_GPREL32, /* type */
309 0, /* rightshift */
310 2, /* size (0 = byte, 1 = short, 2 = long) */
311 32, /* bitsize */
312 FALSE, /* pc_relative */
313 0, /* bitpos */
314 complain_overflow_dont, /* complain_on_overflow */
315 mips_elf_gprel32_reloc, /* special_function */
316 "R_MIPS_GPREL32", /* name */
317 TRUE, /* partial_inplace */
318 0xffffffff, /* src_mask */
319 0xffffffff, /* dst_mask */
320 FALSE), /* pcrel_offset */
321
322 /* The remaining relocs are defined on Irix 5, although they are
323 not defined by the ABI. */
324 EMPTY_HOWTO (13),
325 EMPTY_HOWTO (14),
326 EMPTY_HOWTO (15),
327
328 /* A 5 bit shift field. */
329 HOWTO (R_MIPS_SHIFT5, /* type */
330 0, /* rightshift */
331 2, /* size (0 = byte, 1 = short, 2 = long) */
332 5, /* bitsize */
333 FALSE, /* pc_relative */
334 6, /* bitpos */
335 complain_overflow_bitfield, /* complain_on_overflow */
336 mips_elf_generic_reloc, /* special_function */
337 "R_MIPS_SHIFT5", /* name */
338 TRUE, /* partial_inplace */
339 0x000007c0, /* src_mask */
340 0x000007c0, /* dst_mask */
341 FALSE), /* pcrel_offset */
342
343 /* A 6 bit shift field. */
344 HOWTO (R_MIPS_SHIFT6, /* type */
345 0, /* rightshift */
346 2, /* size (0 = byte, 1 = short, 2 = long) */
347 6, /* bitsize */
348 FALSE, /* pc_relative */
349 6, /* bitpos */
350 complain_overflow_bitfield, /* complain_on_overflow */
351 mips_elf_shift6_reloc, /* special_function */
352 "R_MIPS_SHIFT6", /* name */
353 TRUE, /* partial_inplace */
354 0x000007c4, /* src_mask */
355 0x000007c4, /* dst_mask */
356 FALSE), /* pcrel_offset */
357
358 /* A 64 bit relocation. */
359 HOWTO (R_MIPS_64, /* type */
360 0, /* rightshift */
361 4, /* size (0 = byte, 1 = short, 2 = long) */
362 64, /* bitsize */
363 FALSE, /* pc_relative */
364 0, /* bitpos */
365 complain_overflow_dont, /* complain_on_overflow */
366 mips_elf_generic_reloc, /* special_function */
367 "R_MIPS_64", /* name */
368 TRUE, /* partial_inplace */
369 MINUS_ONE, /* src_mask */
370 MINUS_ONE, /* dst_mask */
371 FALSE), /* pcrel_offset */
372
373 /* Displacement in the global offset table. */
374 HOWTO (R_MIPS_GOT_DISP, /* type */
375 0, /* rightshift */
376 2, /* size (0 = byte, 1 = short, 2 = long) */
377 16, /* bitsize */
378 FALSE, /* pc_relative */
379 0, /* bitpos */
380 complain_overflow_signed, /* complain_on_overflow */
381 mips_elf_generic_reloc, /* special_function */
382 "R_MIPS_GOT_DISP", /* name */
383 TRUE, /* partial_inplace */
384 0x0000ffff, /* src_mask */
385 0x0000ffff, /* dst_mask */
386 FALSE), /* pcrel_offset */
387
388 /* Displacement to page pointer in the global offset table. */
389 HOWTO (R_MIPS_GOT_PAGE, /* type */
390 0, /* rightshift */
391 2, /* size (0 = byte, 1 = short, 2 = long) */
392 16, /* bitsize */
393 FALSE, /* pc_relative */
394 0, /* bitpos */
395 complain_overflow_signed, /* complain_on_overflow */
396 mips_elf_generic_reloc, /* special_function */
397 "R_MIPS_GOT_PAGE", /* name */
398 TRUE, /* partial_inplace */
399 0x0000ffff, /* src_mask */
400 0x0000ffff, /* dst_mask */
401 FALSE), /* pcrel_offset */
402
403 /* Offset from page pointer in the global offset table. */
404 HOWTO (R_MIPS_GOT_OFST, /* type */
405 0, /* rightshift */
406 2, /* size (0 = byte, 1 = short, 2 = long) */
407 16, /* bitsize */
408 FALSE, /* pc_relative */
409 0, /* bitpos */
410 complain_overflow_signed, /* complain_on_overflow */
411 mips_elf_generic_reloc, /* special_function */
412 "R_MIPS_GOT_OFST", /* name */
413 TRUE, /* partial_inplace */
414 0x0000ffff, /* src_mask */
415 0x0000ffff, /* dst_mask */
416 FALSE), /* pcrel_offset */
417
418 /* High 16 bits of displacement in global offset table. */
419 HOWTO (R_MIPS_GOT_HI16, /* type */
420 0, /* rightshift */
421 2, /* size (0 = byte, 1 = short, 2 = long) */
422 16, /* bitsize */
423 FALSE, /* pc_relative */
424 0, /* bitpos */
425 complain_overflow_dont, /* complain_on_overflow */
426 mips_elf_generic_reloc, /* special_function */
427 "R_MIPS_GOT_HI16", /* name */
428 TRUE, /* partial_inplace */
429 0x0000ffff, /* src_mask */
430 0x0000ffff, /* dst_mask */
431 FALSE), /* pcrel_offset */
432
433 /* Low 16 bits of displacement in global offset table. */
434 HOWTO (R_MIPS_GOT_LO16, /* type */
435 0, /* rightshift */
436 2, /* size (0 = byte, 1 = short, 2 = long) */
437 16, /* bitsize */
438 FALSE, /* pc_relative */
439 0, /* bitpos */
440 complain_overflow_dont, /* complain_on_overflow */
441 mips_elf_generic_reloc, /* special_function */
442 "R_MIPS_GOT_LO16", /* name */
443 TRUE, /* partial_inplace */
444 0x0000ffff, /* src_mask */
445 0x0000ffff, /* dst_mask */
446 FALSE), /* pcrel_offset */
447
448 /* 64 bit subtraction. */
449 HOWTO (R_MIPS_SUB, /* type */
450 0, /* rightshift */
451 4, /* size (0 = byte, 1 = short, 2 = long) */
452 64, /* bitsize */
453 FALSE, /* pc_relative */
454 0, /* bitpos */
455 complain_overflow_dont, /* complain_on_overflow */
456 mips_elf_generic_reloc, /* special_function */
457 "R_MIPS_SUB", /* name */
458 TRUE, /* partial_inplace */
459 MINUS_ONE, /* src_mask */
460 MINUS_ONE, /* dst_mask */
461 FALSE), /* pcrel_offset */
462
463 /* Insert the addend as an instruction. */
464 /* FIXME: Not handled correctly. */
465 HOWTO (R_MIPS_INSERT_A, /* type */
466 0, /* rightshift */
467 2, /* size (0 = byte, 1 = short, 2 = long) */
468 32, /* bitsize */
469 FALSE, /* pc_relative */
470 0, /* bitpos */
471 complain_overflow_dont, /* complain_on_overflow */
472 mips_elf_generic_reloc, /* special_function */
473 "R_MIPS_INSERT_A", /* name */
474 TRUE, /* partial_inplace */
475 0xffffffff, /* src_mask */
476 0xffffffff, /* dst_mask */
477 FALSE), /* pcrel_offset */
478
479 /* Insert the addend as an instruction, and change all relocations
480 to refer to the old instruction at the address. */
481 /* FIXME: Not handled correctly. */
482 HOWTO (R_MIPS_INSERT_B, /* type */
483 0, /* rightshift */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
485 32, /* bitsize */
486 FALSE, /* pc_relative */
487 0, /* bitpos */
488 complain_overflow_dont, /* complain_on_overflow */
489 mips_elf_generic_reloc, /* special_function */
490 "R_MIPS_INSERT_B", /* name */
491 TRUE, /* partial_inplace */
492 0xffffffff, /* src_mask */
493 0xffffffff, /* dst_mask */
494 FALSE), /* pcrel_offset */
495
496 /* Delete a 32 bit instruction. */
497 /* FIXME: Not handled correctly. */
498 HOWTO (R_MIPS_DELETE, /* type */
499 0, /* rightshift */
500 2, /* size (0 = byte, 1 = short, 2 = long) */
501 32, /* bitsize */
502 FALSE, /* pc_relative */
503 0, /* bitpos */
504 complain_overflow_dont, /* complain_on_overflow */
505 mips_elf_generic_reloc, /* special_function */
506 "R_MIPS_DELETE", /* name */
507 TRUE, /* partial_inplace */
508 0xffffffff, /* src_mask */
509 0xffffffff, /* dst_mask */
510 FALSE), /* pcrel_offset */
511
512 /* The MIPS ELF64 ABI Draft wants us to support these for REL relocations.
513 We don't, because
514 a) It means building the addend from a R_MIPS_HIGHEST/R_MIPS_HIGHER/
515 R_MIPS_HI16/R_MIPS_LO16 sequence with varying ordering, using
516 fallable heuristics.
517 b) No other NEwABI toolchain actually emits such relocations. */
518 EMPTY_HOWTO (R_MIPS_HIGHER),
519 EMPTY_HOWTO (R_MIPS_HIGHEST),
520
521 /* High 16 bits of displacement in global offset table. */
522 HOWTO (R_MIPS_CALL_HI16, /* type */
523 0, /* rightshift */
524 2, /* size (0 = byte, 1 = short, 2 = long) */
525 16, /* bitsize */
526 FALSE, /* pc_relative */
527 0, /* bitpos */
528 complain_overflow_dont, /* complain_on_overflow */
529 mips_elf_generic_reloc, /* special_function */
530 "R_MIPS_CALL_HI16", /* name */
531 TRUE, /* partial_inplace */
532 0x0000ffff, /* src_mask */
533 0x0000ffff, /* dst_mask */
534 FALSE), /* pcrel_offset */
535
536 /* Low 16 bits of displacement in global offset table. */
537 HOWTO (R_MIPS_CALL_LO16, /* type */
538 0, /* rightshift */
539 2, /* size (0 = byte, 1 = short, 2 = long) */
540 16, /* bitsize */
541 FALSE, /* pc_relative */
542 0, /* bitpos */
543 complain_overflow_dont, /* complain_on_overflow */
544 mips_elf_generic_reloc, /* special_function */
545 "R_MIPS_CALL_LO16", /* name */
546 TRUE, /* partial_inplace */
547 0x0000ffff, /* src_mask */
548 0x0000ffff, /* dst_mask */
549 FALSE), /* pcrel_offset */
550
551 /* Section displacement. */
552 HOWTO (R_MIPS_SCN_DISP, /* type */
553 0, /* rightshift */
554 2, /* size (0 = byte, 1 = short, 2 = long) */
555 32, /* bitsize */
556 FALSE, /* pc_relative */
557 0, /* bitpos */
558 complain_overflow_dont, /* complain_on_overflow */
559 mips_elf_generic_reloc, /* special_function */
560 "R_MIPS_SCN_DISP", /* name */
561 TRUE, /* partial_inplace */
562 0xffffffff, /* src_mask */
563 0xffffffff, /* dst_mask */
564 FALSE), /* pcrel_offset */
565
566 HOWTO (R_MIPS_REL16, /* type */
567 0, /* rightshift */
568 1, /* size (0 = byte, 1 = short, 2 = long) */
569 16, /* bitsize */
570 FALSE, /* pc_relative */
571 0, /* bitpos */
572 complain_overflow_signed, /* complain_on_overflow */
573 mips_elf_generic_reloc, /* special_function */
574 "R_MIPS_REL16", /* name */
575 TRUE, /* partial_inplace */
576 0xffff, /* src_mask */
577 0xffff, /* dst_mask */
578 FALSE), /* pcrel_offset */
579
580 /* These two are obsolete. */
581 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
582 EMPTY_HOWTO (R_MIPS_PJUMP),
583
584 /* Similiar to R_MIPS_REL32, but used for relocations in a GOT section.
585 It must be used for multigot GOT's (and only there). */
586 HOWTO (R_MIPS_RELGOT, /* type */
587 0, /* rightshift */
588 2, /* size (0 = byte, 1 = short, 2 = long) */
589 32, /* bitsize */
590 FALSE, /* pc_relative */
591 0, /* bitpos */
592 complain_overflow_dont, /* complain_on_overflow */
593 mips_elf_generic_reloc, /* special_function */
594 "R_MIPS_RELGOT", /* name */
595 TRUE, /* partial_inplace */
596 0xffffffff, /* src_mask */
597 0xffffffff, /* dst_mask */
598 FALSE), /* pcrel_offset */
599
600 /* Protected jump conversion. This is an optimization hint. No
601 relocation is required for correctness. */
602 HOWTO (R_MIPS_JALR, /* type */
603 0, /* rightshift */
604 2, /* size (0 = byte, 1 = short, 2 = long) */
605 32, /* bitsize */
606 FALSE, /* pc_relative */
607 0, /* bitpos */
608 complain_overflow_dont, /* complain_on_overflow */
609 mips_elf_generic_reloc, /* special_function */
610 "R_MIPS_JALR", /* name */
611 FALSE, /* partial_inplace */
612 0x00000000, /* src_mask */
613 0x00000000, /* dst_mask */
614 FALSE), /* pcrel_offset */
615 };
616
617 /* The relocation table used for SHT_RELA sections. */
618
619 static reloc_howto_type elf_mips_howto_table_rela[] =
620 {
621 /* No relocation. */
622 HOWTO (R_MIPS_NONE, /* type */
623 0, /* rightshift */
624 0, /* size (0 = byte, 1 = short, 2 = long) */
625 0, /* bitsize */
626 FALSE, /* pc_relative */
627 0, /* bitpos */
628 complain_overflow_dont, /* complain_on_overflow */
629 mips_elf_generic_reloc, /* special_function */
630 "R_MIPS_NONE", /* name */
631 FALSE, /* partial_inplace */
632 0, /* src_mask */
633 0, /* dst_mask */
634 FALSE), /* pcrel_offset */
635
636 /* 16 bit relocation. */
637 HOWTO (R_MIPS_16, /* type */
638 0, /* rightshift */
639 2, /* size (0 = byte, 1 = short, 2 = long) */
640 16, /* bitsize */
641 FALSE, /* pc_relative */
642 0, /* bitpos */
643 complain_overflow_signed, /* complain_on_overflow */
644 mips_elf_generic_reloc, /* special_function */
645 "R_MIPS_16", /* name */
646 FALSE, /* partial_inplace */
647 0, /* src_mask */
648 0x0000, /* dst_mask */
649 FALSE), /* pcrel_offset */
650
651 /* 32 bit relocation. */
652 HOWTO (R_MIPS_32, /* type */
653 0, /* rightshift */
654 2, /* size (0 = byte, 1 = short, 2 = long) */
655 32, /* bitsize */
656 FALSE, /* pc_relative */
657 0, /* bitpos */
658 complain_overflow_dont, /* complain_on_overflow */
659 mips_elf_generic_reloc, /* special_function */
660 "R_MIPS_32", /* name */
661 FALSE, /* partial_inplace */
662 0, /* src_mask */
663 0xffffffff, /* dst_mask */
664 FALSE), /* pcrel_offset */
665
666 /* 32 bit symbol relative relocation. */
667 HOWTO (R_MIPS_REL32, /* type */
668 0, /* rightshift */
669 2, /* size (0 = byte, 1 = short, 2 = long) */
670 32, /* bitsize */
671 FALSE, /* pc_relative */
672 0, /* bitpos */
673 complain_overflow_dont, /* complain_on_overflow */
674 mips_elf_generic_reloc, /* special_function */
675 "R_MIPS_REL32", /* name */
676 FALSE, /* partial_inplace */
677 0, /* src_mask */
678 0xffffffff, /* dst_mask */
679 FALSE), /* pcrel_offset */
680
681 /* 26 bit jump address. */
682 HOWTO (R_MIPS_26, /* type */
683 2, /* rightshift */
684 2, /* size (0 = byte, 1 = short, 2 = long) */
685 26, /* bitsize */
686 FALSE, /* pc_relative */
687 0, /* bitpos */
688 complain_overflow_dont, /* complain_on_overflow */
689 /* This needs complex overflow
690 detection, because the upper 36
691 bits must match the PC + 4. */
692 mips_elf_generic_reloc, /* special_function */
693 "R_MIPS_26", /* name */
694 FALSE, /* partial_inplace */
695 0, /* src_mask */
696 0x03ffffff, /* dst_mask */
697 FALSE), /* pcrel_offset */
698
699 /* High 16 bits of symbol value. */
700 HOWTO (R_MIPS_HI16, /* type */
701 0, /* rightshift */
702 2, /* size (0 = byte, 1 = short, 2 = long) */
703 16, /* bitsize */
704 FALSE, /* pc_relative */
705 0, /* bitpos */
706 complain_overflow_dont, /* complain_on_overflow */
707 mips_elf_generic_reloc, /* special_function */
708 "R_MIPS_HI16", /* name */
709 FALSE, /* partial_inplace */
710 0, /* src_mask */
711 0x0000ffff, /* dst_mask */
712 FALSE), /* pcrel_offset */
713
714 /* Low 16 bits of symbol value. */
715 HOWTO (R_MIPS_LO16, /* type */
716 0, /* rightshift */
717 2, /* size (0 = byte, 1 = short, 2 = long) */
718 16, /* bitsize */
719 FALSE, /* pc_relative */
720 0, /* bitpos */
721 complain_overflow_dont, /* complain_on_overflow */
722 mips_elf_generic_reloc, /* special_function */
723 "R_MIPS_LO16", /* name */
724 FALSE, /* partial_inplace */
725 0, /* src_mask */
726 0x0000ffff, /* dst_mask */
727 FALSE), /* pcrel_offset */
728
729 /* GP relative reference. */
730 HOWTO (R_MIPS_GPREL16, /* type */
731 0, /* rightshift */
732 2, /* size (0 = byte, 1 = short, 2 = long) */
733 16, /* bitsize */
734 FALSE, /* pc_relative */
735 0, /* bitpos */
736 complain_overflow_signed, /* complain_on_overflow */
737 mips_elf_gprel16_reloc, /* special_function */
738 "R_MIPS_GPREL16", /* name */
739 FALSE, /* partial_inplace */
740 0, /* src_mask */
741 0x0000ffff, /* dst_mask */
742 FALSE), /* pcrel_offset */
743
744 /* Reference to literal section. */
745 HOWTO (R_MIPS_LITERAL, /* type */
746 0, /* rightshift */
747 2, /* size (0 = byte, 1 = short, 2 = long) */
748 16, /* bitsize */
749 FALSE, /* pc_relative */
750 0, /* bitpos */
751 complain_overflow_signed, /* complain_on_overflow */
752 mips_elf_literal_reloc, /* special_function */
753 "R_MIPS_LITERAL", /* name */
754 FALSE, /* partial_inplace */
755 0, /* src_mask */
756 0x0000ffff, /* dst_mask */
757 FALSE), /* pcrel_offset */
758
759 /* Reference to global offset table. */
760 HOWTO (R_MIPS_GOT16, /* type */
761 0, /* rightshift */
762 2, /* size (0 = byte, 1 = short, 2 = long) */
763 16, /* bitsize */
764 FALSE, /* pc_relative */
765 0, /* bitpos */
766 complain_overflow_signed, /* complain_on_overflow */
767 mips_elf_got16_reloc, /* special_function */
768 "R_MIPS_GOT16", /* name */
769 FALSE, /* partial_inplace */
770 0, /* src_mask */
771 0x0000ffff, /* dst_mask */
772 FALSE), /* pcrel_offset */
773
774 /* 16 bit PC relative reference. */
775 HOWTO (R_MIPS_PC16, /* type */
776 0, /* rightshift */
777 2, /* size (0 = byte, 1 = short, 2 = long) */
778 16, /* bitsize */
779 TRUE, /* pc_relative */
780 0, /* bitpos */
781 complain_overflow_signed, /* complain_on_overflow */
782 mips_elf_generic_reloc, /* special_function */
783 "R_MIPS_PC16", /* name */
784 FALSE, /* partial_inplace */
785 0, /* src_mask */
786 0x0000ffff, /* dst_mask */
787 TRUE), /* pcrel_offset */
788
789 /* 16 bit call through global offset table. */
790 HOWTO (R_MIPS_CALL16, /* type */
791 0, /* rightshift */
792 2, /* size (0 = byte, 1 = short, 2 = long) */
793 16, /* bitsize */
794 FALSE, /* pc_relative */
795 0, /* bitpos */
796 complain_overflow_signed, /* complain_on_overflow */
797 mips_elf_generic_reloc, /* special_function */
798 "R_MIPS_CALL16", /* name */
799 FALSE, /* partial_inplace */
800 0, /* src_mask */
801 0x0000ffff, /* dst_mask */
802 FALSE), /* pcrel_offset */
803
804 /* 32 bit GP relative reference. */
805 HOWTO (R_MIPS_GPREL32, /* type */
806 0, /* rightshift */
807 2, /* size (0 = byte, 1 = short, 2 = long) */
808 32, /* bitsize */
809 FALSE, /* pc_relative */
810 0, /* bitpos */
811 complain_overflow_dont, /* complain_on_overflow */
812 mips_elf_gprel32_reloc, /* special_function */
813 "R_MIPS_GPREL32", /* name */
814 FALSE, /* partial_inplace */
815 0, /* src_mask */
816 0xffffffff, /* dst_mask */
817 FALSE), /* pcrel_offset */
818
819 EMPTY_HOWTO (13),
820 EMPTY_HOWTO (14),
821 EMPTY_HOWTO (15),
822
823 /* A 5 bit shift field. */
824 HOWTO (R_MIPS_SHIFT5, /* type */
825 0, /* rightshift */
826 2, /* size (0 = byte, 1 = short, 2 = long) */
827 5, /* bitsize */
828 FALSE, /* pc_relative */
829 6, /* bitpos */
830 complain_overflow_bitfield, /* complain_on_overflow */
831 mips_elf_generic_reloc, /* special_function */
832 "R_MIPS_SHIFT5", /* name */
833 FALSE, /* partial_inplace */
834 0, /* src_mask */
835 0x000007c0, /* dst_mask */
836 FALSE), /* pcrel_offset */
837
838 /* A 6 bit shift field. */
839 HOWTO (R_MIPS_SHIFT6, /* type */
840 0, /* rightshift */
841 2, /* size (0 = byte, 1 = short, 2 = long) */
842 6, /* bitsize */
843 FALSE, /* pc_relative */
844 6, /* bitpos */
845 complain_overflow_bitfield, /* complain_on_overflow */
846 mips_elf_shift6_reloc, /* special_function */
847 "R_MIPS_SHIFT6", /* name */
848 FALSE, /* partial_inplace */
849 0, /* src_mask */
850 0x000007c4, /* dst_mask */
851 FALSE), /* pcrel_offset */
852
853 /* 64 bit relocation. */
854 HOWTO (R_MIPS_64, /* type */
855 0, /* rightshift */
856 4, /* size (0 = byte, 1 = short, 2 = long) */
857 64, /* bitsize */
858 FALSE, /* pc_relative */
859 0, /* bitpos */
860 complain_overflow_dont, /* complain_on_overflow */
861 mips_elf_generic_reloc, /* special_function */
862 "R_MIPS_64", /* name */
863 FALSE, /* partial_inplace */
864 0, /* src_mask */
865 MINUS_ONE, /* dst_mask */
866 FALSE), /* pcrel_offset */
867
868 /* Displacement in the global offset table. */
869 HOWTO (R_MIPS_GOT_DISP, /* type */
870 0, /* rightshift */
871 2, /* size (0 = byte, 1 = short, 2 = long) */
872 16, /* bitsize */
873 FALSE, /* pc_relative */
874 0, /* bitpos */
875 complain_overflow_signed, /* complain_on_overflow */
876 mips_elf_generic_reloc, /* special_function */
877 "R_MIPS_GOT_DISP", /* name */
878 FALSE, /* partial_inplace */
879 0, /* src_mask */
880 0x0000ffff, /* dst_mask */
881 FALSE), /* pcrel_offset */
882
883 /* Displacement to page pointer in the global offset table. */
884 HOWTO (R_MIPS_GOT_PAGE, /* type */
885 0, /* rightshift */
886 2, /* size (0 = byte, 1 = short, 2 = long) */
887 16, /* bitsize */
888 FALSE, /* pc_relative */
889 0, /* bitpos */
890 complain_overflow_signed, /* complain_on_overflow */
891 mips_elf_generic_reloc, /* special_function */
892 "R_MIPS_GOT_PAGE", /* name */
893 FALSE, /* partial_inplace */
894 0, /* src_mask */
895 0x0000ffff, /* dst_mask */
896 FALSE), /* pcrel_offset */
897
898 /* Offset from page pointer in the global offset table. */
899 HOWTO (R_MIPS_GOT_OFST, /* type */
900 0, /* rightshift */
901 2, /* size (0 = byte, 1 = short, 2 = long) */
902 16, /* bitsize */
903 FALSE, /* pc_relative */
904 0, /* bitpos */
905 complain_overflow_signed, /* complain_on_overflow */
906 mips_elf_generic_reloc, /* special_function */
907 "R_MIPS_GOT_OFST", /* name */
908 FALSE, /* partial_inplace */
909 0, /* src_mask */
910 0x0000ffff, /* dst_mask */
911 FALSE), /* pcrel_offset */
912
913 /* High 16 bits of displacement in global offset table. */
914 HOWTO (R_MIPS_GOT_HI16, /* type */
915 0, /* rightshift */
916 2, /* size (0 = byte, 1 = short, 2 = long) */
917 16, /* bitsize */
918 FALSE, /* pc_relative */
919 0, /* bitpos */
920 complain_overflow_dont, /* complain_on_overflow */
921 mips_elf_generic_reloc, /* special_function */
922 "R_MIPS_GOT_HI16", /* name */
923 FALSE, /* partial_inplace */
924 0, /* src_mask */
925 0x0000ffff, /* dst_mask */
926 FALSE), /* pcrel_offset */
927
928 /* Low 16 bits of displacement in global offset table. */
929 HOWTO (R_MIPS_GOT_LO16, /* type */
930 0, /* rightshift */
931 2, /* size (0 = byte, 1 = short, 2 = long) */
932 16, /* bitsize */
933 FALSE, /* pc_relative */
934 0, /* bitpos */
935 complain_overflow_dont, /* complain_on_overflow */
936 mips_elf_generic_reloc, /* special_function */
937 "R_MIPS_GOT_LO16", /* name */
938 FALSE, /* partial_inplace */
939 0, /* src_mask */
940 0x0000ffff, /* dst_mask */
941 FALSE), /* pcrel_offset */
942
943 /* 64 bit substraction. */
944 HOWTO (R_MIPS_SUB, /* type */
945 0, /* rightshift */
946 4, /* size (0 = byte, 1 = short, 2 = long) */
947 64, /* bitsize */
948 FALSE, /* pc_relative */
949 0, /* bitpos */
950 complain_overflow_dont, /* complain_on_overflow */
951 mips_elf_generic_reloc, /* special_function */
952 "R_MIPS_SUB", /* name */
953 FALSE, /* partial_inplace */
954 0, /* src_mask */
955 MINUS_ONE, /* dst_mask */
956 FALSE), /* pcrel_offset */
957
958 /* Insert the addend as an instruction. */
959 /* FIXME: Not handled correctly. */
960 HOWTO (R_MIPS_INSERT_A, /* type */
961 0, /* rightshift */
962 2, /* size (0 = byte, 1 = short, 2 = long) */
963 32, /* bitsize */
964 FALSE, /* pc_relative */
965 0, /* bitpos */
966 complain_overflow_dont, /* complain_on_overflow */
967 mips_elf_generic_reloc, /* special_function */
968 "R_MIPS_INSERT_A", /* name */
969 FALSE, /* partial_inplace */
970 0, /* src_mask */
971 0xffffffff, /* dst_mask */
972 FALSE), /* pcrel_offset */
973
974 /* Insert the addend as an instruction, and change all relocations
975 to refer to the old instruction at the address. */
976 /* FIXME: Not handled correctly. */
977 HOWTO (R_MIPS_INSERT_B, /* type */
978 0, /* rightshift */
979 2, /* size (0 = byte, 1 = short, 2 = long) */
980 32, /* bitsize */
981 FALSE, /* pc_relative */
982 0, /* bitpos */
983 complain_overflow_dont, /* complain_on_overflow */
984 mips_elf_generic_reloc, /* special_function */
985 "R_MIPS_INSERT_B", /* name */
986 FALSE, /* partial_inplace */
987 0, /* src_mask */
988 0xffffffff, /* dst_mask */
989 FALSE), /* pcrel_offset */
990
991 /* Delete a 32 bit instruction. */
992 /* FIXME: Not handled correctly. */
993 HOWTO (R_MIPS_DELETE, /* type */
994 0, /* rightshift */
995 2, /* size (0 = byte, 1 = short, 2 = long) */
996 32, /* bitsize */
997 FALSE, /* pc_relative */
998 0, /* bitpos */
999 complain_overflow_dont, /* complain_on_overflow */
1000 mips_elf_generic_reloc, /* special_function */
1001 "R_MIPS_DELETE", /* name */
1002 FALSE, /* partial_inplace */
1003 0, /* src_mask */
1004 0xffffffff, /* dst_mask */
1005 FALSE), /* pcrel_offset */
1006
1007 /* Get the higher value of a 64 bit addend. */
1008 HOWTO (R_MIPS_HIGHER, /* type */
1009 0, /* rightshift */
1010 2, /* size (0 = byte, 1 = short, 2 = long) */
1011 16, /* bitsize */
1012 FALSE, /* pc_relative */
1013 0, /* bitpos */
1014 complain_overflow_dont, /* complain_on_overflow */
1015 mips_elf_generic_reloc, /* special_function */
1016 "R_MIPS_HIGHER", /* name */
1017 FALSE, /* partial_inplace */
1018 0, /* src_mask */
1019 0x0000ffff, /* dst_mask */
1020 FALSE), /* pcrel_offset */
1021
1022 /* Get the highest value of a 64 bit addend. */
1023 HOWTO (R_MIPS_HIGHEST, /* type */
1024 0, /* rightshift */
1025 2, /* size (0 = byte, 1 = short, 2 = long) */
1026 16, /* bitsize */
1027 FALSE, /* pc_relative */
1028 0, /* bitpos */
1029 complain_overflow_dont, /* complain_on_overflow */
1030 mips_elf_generic_reloc, /* special_function */
1031 "R_MIPS_HIGHEST", /* name */
1032 FALSE, /* partial_inplace */
1033 0, /* src_mask */
1034 0x0000ffff, /* dst_mask */
1035 FALSE), /* pcrel_offset */
1036
1037 /* High 16 bits of displacement in global offset table. */
1038 HOWTO (R_MIPS_CALL_HI16, /* type */
1039 0, /* rightshift */
1040 2, /* size (0 = byte, 1 = short, 2 = long) */
1041 16, /* bitsize */
1042 FALSE, /* pc_relative */
1043 0, /* bitpos */
1044 complain_overflow_dont, /* complain_on_overflow */
1045 mips_elf_generic_reloc, /* special_function */
1046 "R_MIPS_CALL_HI16", /* name */
1047 FALSE, /* partial_inplace */
1048 0, /* src_mask */
1049 0x0000ffff, /* dst_mask */
1050 FALSE), /* pcrel_offset */
1051
1052 /* Low 16 bits of displacement in global offset table. */
1053 HOWTO (R_MIPS_CALL_LO16, /* type */
1054 0, /* rightshift */
1055 2, /* size (0 = byte, 1 = short, 2 = long) */
1056 16, /* bitsize */
1057 FALSE, /* pc_relative */
1058 0, /* bitpos */
1059 complain_overflow_dont, /* complain_on_overflow */
1060 mips_elf_generic_reloc, /* special_function */
1061 "R_MIPS_CALL_LO16", /* name */
1062 FALSE, /* partial_inplace */
1063 0, /* src_mask */
1064 0x0000ffff, /* dst_mask */
1065 FALSE), /* pcrel_offset */
1066
1067 /* Section displacement, used by an associated event location section. */
1068 HOWTO (R_MIPS_SCN_DISP, /* type */
1069 0, /* rightshift */
1070 2, /* size (0 = byte, 1 = short, 2 = long) */
1071 32, /* bitsize */
1072 FALSE, /* pc_relative */
1073 0, /* bitpos */
1074 complain_overflow_dont, /* complain_on_overflow */
1075 mips_elf_generic_reloc, /* special_function */
1076 "R_MIPS_SCN_DISP", /* name */
1077 FALSE, /* partial_inplace */
1078 0, /* src_mask */
1079 0xffffffff, /* dst_mask */
1080 FALSE), /* pcrel_offset */
1081
1082 /* 16 bit relocation. */
1083 HOWTO (R_MIPS_REL16, /* type */
1084 0, /* rightshift */
1085 1, /* size (0 = byte, 1 = short, 2 = long) */
1086 16, /* bitsize */
1087 FALSE, /* pc_relative */
1088 0, /* bitpos */
1089 complain_overflow_signed, /* complain_on_overflow */
1090 mips_elf_generic_reloc, /* special_function */
1091 "R_MIPS_REL16", /* name */
1092 FALSE, /* partial_inplace */
1093 0, /* src_mask */
1094 0xffff, /* dst_mask */
1095 FALSE), /* pcrel_offset */
1096
1097 /* These two are obsolete. */
1098 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
1099 EMPTY_HOWTO (R_MIPS_PJUMP),
1100
1101 /* Similiar to R_MIPS_REL32, but used for relocations in a GOT section.
1102 It must be used for multigot GOT's (and only there). */
1103 HOWTO (R_MIPS_RELGOT, /* type */
1104 0, /* rightshift */
1105 2, /* size (0 = byte, 1 = short, 2 = long) */
1106 32, /* bitsize */
1107 FALSE, /* pc_relative */
1108 0, /* bitpos */
1109 complain_overflow_dont, /* complain_on_overflow */
1110 mips_elf_generic_reloc, /* special_function */
1111 "R_MIPS_RELGOT", /* name */
1112 FALSE, /* partial_inplace */
1113 0, /* src_mask */
1114 0xffffffff, /* dst_mask */
1115 FALSE), /* pcrel_offset */
1116
1117 /* Protected jump conversion. This is an optimization hint. No
1118 relocation is required for correctness. */
1119 HOWTO (R_MIPS_JALR, /* type */
1120 0, /* rightshift */
1121 2, /* size (0 = byte, 1 = short, 2 = long) */
1122 32, /* bitsize */
1123 FALSE, /* pc_relative */
1124 0, /* bitpos */
1125 complain_overflow_dont, /* complain_on_overflow */
1126 mips_elf_generic_reloc, /* special_function */
1127 "R_MIPS_JALR", /* name */
1128 FALSE, /* partial_inplace */
1129 0, /* src_mask */
1130 0xffffffff, /* dst_mask */
1131 FALSE), /* pcrel_offset */
1132 };
1133
1134 /* The reloc used for the mips16 jump instruction. */
1135 static reloc_howto_type elf_mips16_jump_howto =
1136 HOWTO (R_MIPS16_26, /* type */
1137 2, /* rightshift */
1138 2, /* size (0 = byte, 1 = short, 2 = long) */
1139 26, /* bitsize */
1140 FALSE, /* pc_relative */
1141 0, /* bitpos */
1142 complain_overflow_dont, /* complain_on_overflow */
1143 /* This needs complex overflow
1144 detection, because the upper four
1145 bits must match the PC. */
1146 mips16_jump_reloc, /* special_function */
1147 "R_MIPS16_26", /* name */
1148 TRUE, /* partial_inplace */
1149 0x3ffffff, /* src_mask */
1150 0x3ffffff, /* dst_mask */
1151 FALSE); /* pcrel_offset */
1152
1153 /* The reloc used for the mips16 gprel instruction. */
1154 static reloc_howto_type elf_mips16_gprel_howto =
1155 HOWTO (R_MIPS16_GPREL, /* type */
1156 0, /* rightshift */
1157 2, /* size (0 = byte, 1 = short, 2 = long) */
1158 16, /* bitsize */
1159 FALSE, /* pc_relative */
1160 0, /* bitpos */
1161 complain_overflow_signed, /* complain_on_overflow */
1162 mips16_gprel_reloc, /* special_function */
1163 "R_MIPS16_GPREL", /* name */
1164 TRUE, /* partial_inplace */
1165 0x07ff001f, /* src_mask */
1166 0x07ff001f, /* dst_mask */
1167 FALSE); /* pcrel_offset */
1168
1169 /* GNU extension to record C++ vtable hierarchy */
1170 static reloc_howto_type elf_mips_gnu_vtinherit_howto =
1171 HOWTO (R_MIPS_GNU_VTINHERIT, /* type */
1172 0, /* rightshift */
1173 2, /* size (0 = byte, 1 = short, 2 = long) */
1174 0, /* bitsize */
1175 FALSE, /* pc_relative */
1176 0, /* bitpos */
1177 complain_overflow_dont, /* complain_on_overflow */
1178 NULL, /* special_function */
1179 "R_MIPS_GNU_VTINHERIT", /* name */
1180 FALSE, /* partial_inplace */
1181 0, /* src_mask */
1182 0, /* dst_mask */
1183 FALSE); /* pcrel_offset */
1184
1185 /* GNU extension to record C++ vtable member usage */
1186 static reloc_howto_type elf_mips_gnu_vtentry_howto =
1187 HOWTO (R_MIPS_GNU_VTENTRY, /* type */
1188 0, /* rightshift */
1189 2, /* size (0 = byte, 1 = short, 2 = long) */
1190 0, /* bitsize */
1191 FALSE, /* pc_relative */
1192 0, /* bitpos */
1193 complain_overflow_dont, /* complain_on_overflow */
1194 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1195 "R_MIPS_GNU_VTENTRY", /* name */
1196 FALSE, /* partial_inplace */
1197 0, /* src_mask */
1198 0, /* dst_mask */
1199 FALSE); /* pcrel_offset */
1200 \f
1201 /* This is derived from bfd_elf_generic_reloc. NewABI allows us to have
1202 several relocations against the same address. The addend is derived
1203 from the addends of preceding relocations. If we don't need to
1204 do something special, we simply keep track of the addend. */
1205
1206 #define GET_RELOC_ADDEND(obfd, sym, entry, sec) \
1207 { \
1208 /* If we're relocating, and this is an external symbol, we don't \
1209 want to change anything. */ \
1210 if (obfd != (bfd *) NULL \
1211 && (sym->flags & BSF_SECTION_SYM) == 0 \
1212 && (! entry->howto->partial_inplace \
1213 || entry->addend == 0)) \
1214 { \
1215 entry->address += sec->output_offset; \
1216 return bfd_reloc_ok; \
1217 } \
1218 \
1219 /* The addend of combined relocs is remembered and left for \
1220 subsequent relocs. */ \
1221 if (prev_reloc_address != reloc_entry->address) \
1222 { \
1223 prev_reloc_address = reloc_entry->address; \
1224 prev_reloc_addend = reloc_entry->addend; \
1225 } \
1226 else \
1227 reloc_entry->addend = prev_reloc_addend; \
1228 }
1229
1230 #define SET_RELOC_ADDEND(entry) \
1231 { \
1232 prev_reloc_addend = entry->addend; \
1233 }
1234
1235 static bfd_reloc_status_type
1236 mips_elf_generic_reloc (abfd, reloc_entry, symbol, data, input_section,
1237 output_bfd, error_message)
1238 bfd *abfd ATTRIBUTE_UNUSED;
1239 arelent *reloc_entry;
1240 asymbol *symbol;
1241 PTR data ATTRIBUTE_UNUSED;
1242 asection *input_section;
1243 bfd *output_bfd;
1244 char **error_message ATTRIBUTE_UNUSED;
1245 {
1246 GET_RELOC_ADDEND (output_bfd, symbol, reloc_entry, input_section)
1247
1248 return bfd_reloc_continue;
1249 }
1250 \f
1251 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
1252 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
1253 the HI16. Here we just save the information we need; we do the
1254 actual relocation when we see the LO16.
1255
1256 MIPS ELF requires that the LO16 immediately follow the HI16. As a
1257 GNU extension, for non-pc-relative relocations, we permit an
1258 arbitrary number of HI16 relocs to be associated with a single LO16
1259 reloc. This extension permits gcc to output the HI and LO relocs
1260 itself.
1261
1262 This cannot be done for PC-relative relocations because both the HI16
1263 and LO16 parts of the relocations must be done relative to the LO16
1264 part, and there can be carry to or borrow from the HI16 part. */
1265
1266 struct mips_hi16
1267 {
1268 struct mips_hi16 *next;
1269 bfd_byte *addr;
1270 bfd_vma addend;
1271 };
1272
1273 /* FIXME: This should not be a static variable. */
1274
1275 static struct mips_hi16 *mips_hi16_list;
1276
1277 static bfd_reloc_status_type
1278 mips_elf_hi16_reloc (abfd, reloc_entry, symbol, data, input_section,
1279 output_bfd, error_message)
1280 bfd *abfd ATTRIBUTE_UNUSED;
1281 arelent *reloc_entry;
1282 asymbol *symbol;
1283 PTR data;
1284 asection *input_section;
1285 bfd *output_bfd;
1286 char **error_message ATTRIBUTE_UNUSED;
1287 {
1288 bfd_reloc_status_type ret;
1289 bfd_vma relocation;
1290 struct mips_hi16 *n;
1291
1292 GET_RELOC_ADDEND (output_bfd, symbol, reloc_entry, input_section)
1293
1294 ret = bfd_reloc_ok;
1295
1296 if (bfd_is_und_section (symbol->section) && output_bfd == (bfd *) NULL)
1297 ret = bfd_reloc_undefined;
1298
1299 if (bfd_is_com_section (symbol->section))
1300 relocation = 0;
1301 else
1302 relocation = symbol->value;
1303
1304 relocation += symbol->section->output_section->vma;
1305 relocation += symbol->section->output_offset;
1306 relocation += reloc_entry->addend;
1307
1308 if (reloc_entry->address > input_section->_cooked_size)
1309 return bfd_reloc_outofrange;
1310
1311 /* Save the information, and let LO16 do the actual relocation. */
1312 n = (struct mips_hi16 *) bfd_malloc ((bfd_size_type) sizeof *n);
1313 if (n == NULL)
1314 return bfd_reloc_outofrange;
1315 n->addr = (bfd_byte *) data + reloc_entry->address;
1316 n->addend = relocation;
1317 n->next = mips_hi16_list;
1318 mips_hi16_list = n;
1319
1320 if (output_bfd != (bfd *) NULL)
1321 reloc_entry->address += input_section->output_offset;
1322
1323 return ret;
1324 }
1325
1326 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
1327 inplace relocation; this function exists in order to do the
1328 R_MIPS_HI16 relocation described above. */
1329
1330 static bfd_reloc_status_type
1331 mips_elf_lo16_reloc (abfd, reloc_entry, symbol, data, input_section,
1332 output_bfd, error_message)
1333 bfd *abfd;
1334 arelent *reloc_entry;
1335 asymbol *symbol;
1336 PTR data;
1337 asection *input_section;
1338 bfd *output_bfd;
1339 char **error_message;
1340 {
1341 if (mips_hi16_list != NULL)
1342 {
1343 struct mips_hi16 *l;
1344
1345 l = mips_hi16_list;
1346 while (l != NULL)
1347 {
1348 unsigned long insn;
1349 unsigned long val;
1350 unsigned long vallo;
1351 struct mips_hi16 *next;
1352
1353 /* Do the HI16 relocation. Note that we actually don't need
1354 to know anything about the LO16 itself, except where to
1355 find the low 16 bits of the addend needed by the LO16. */
1356 insn = bfd_get_32 (abfd, l->addr);
1357 vallo = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1358
1359 /* The low order 16 bits are always treated as a signed
1360 value. */
1361 vallo = ((vallo & 0xffff) ^ 0x8000) - 0x8000;
1362 val = ((insn & 0xffff) << 16) + vallo;
1363 val += l->addend;
1364
1365 /* If PC-relative, we need to subtract out the address of the LO
1366 half of the HI/LO. (The actual relocation is relative
1367 to that instruction.) */
1368 if (reloc_entry->howto->pc_relative)
1369 val -= reloc_entry->address;
1370
1371 /* At this point, "val" has the value of the combined HI/LO
1372 pair. If the low order 16 bits (which will be used for
1373 the LO16 insn) are negative, then we will need an
1374 adjustment for the high order 16 bits. */
1375 val += 0x8000;
1376 val = (val >> 16) & 0xffff;
1377
1378 insn &= ~ (bfd_vma) 0xffff;
1379 insn |= val;
1380 bfd_put_32 (abfd, (bfd_vma) insn, l->addr);
1381
1382 next = l->next;
1383 free (l);
1384 l = next;
1385 }
1386
1387 mips_hi16_list = NULL;
1388 }
1389
1390 /* Now do the LO16 reloc in the usual way. */
1391 return mips_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1392 input_section, output_bfd, error_message);
1393 }
1394
1395 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1396 table used for PIC code. If the symbol is an external symbol, the
1397 instruction is modified to contain the offset of the appropriate
1398 entry in the global offset table. If the symbol is a section
1399 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1400 addends are combined to form the real addend against the section
1401 symbol; the GOT16 is modified to contain the offset of an entry in
1402 the global offset table, and the LO16 is modified to offset it
1403 appropriately. Thus an offset larger than 16 bits requires a
1404 modified value in the global offset table.
1405
1406 This implementation suffices for the assembler, but the linker does
1407 not yet know how to create global offset tables. */
1408
1409 static bfd_reloc_status_type
1410 mips_elf_got16_reloc (abfd, reloc_entry, symbol, data, input_section,
1411 output_bfd, error_message)
1412 bfd *abfd;
1413 arelent *reloc_entry;
1414 asymbol *symbol;
1415 PTR data;
1416 asection *input_section;
1417 bfd *output_bfd;
1418 char **error_message;
1419 {
1420 /* If we're relocating, and this is a local symbol, we can handle it
1421 just like HI16. */
1422 if (output_bfd != (bfd *) NULL
1423 && (symbol->flags & BSF_SECTION_SYM) != 0)
1424 return mips_elf_hi16_reloc (abfd, reloc_entry, symbol, data,
1425 input_section, output_bfd, error_message);
1426
1427 /* Otherwise we try to handle it as R_MIPS_GOT_DISP. */
1428 return mips_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1429 input_section, output_bfd, error_message);
1430 }
1431
1432 /* Set the GP value for OUTPUT_BFD. Returns FALSE if this is a
1433 dangerous relocation. */
1434
1435 static bfd_boolean
1436 mips_elf_assign_gp (output_bfd, pgp)
1437 bfd *output_bfd;
1438 bfd_vma *pgp;
1439 {
1440 unsigned int count;
1441 asymbol **sym;
1442 unsigned int i;
1443
1444 /* If we've already figured out what GP will be, just return it. */
1445 *pgp = _bfd_get_gp_value (output_bfd);
1446 if (*pgp)
1447 return TRUE;
1448
1449 count = bfd_get_symcount (output_bfd);
1450 sym = bfd_get_outsymbols (output_bfd);
1451
1452 /* The linker script will have created a symbol named `_gp' with the
1453 appropriate value. */
1454 if (sym == (asymbol **) NULL)
1455 i = count;
1456 else
1457 {
1458 for (i = 0; i < count; i++, sym++)
1459 {
1460 register const char *name;
1461
1462 name = bfd_asymbol_name (*sym);
1463 if (*name == '_' && strcmp (name, "_gp") == 0)
1464 {
1465 *pgp = bfd_asymbol_value (*sym);
1466 _bfd_set_gp_value (output_bfd, *pgp);
1467 break;
1468 }
1469 }
1470 }
1471
1472 if (i >= count)
1473 {
1474 /* Only get the error once. */
1475 *pgp = 4;
1476 _bfd_set_gp_value (output_bfd, *pgp);
1477 return FALSE;
1478 }
1479
1480 return TRUE;
1481 }
1482
1483 /* We have to figure out the gp value, so that we can adjust the
1484 symbol value correctly. We look up the symbol _gp in the output
1485 BFD. If we can't find it, we're stuck. We cache it in the ELF
1486 target data. We don't need to adjust the symbol value for an
1487 external symbol if we are producing relocateable output. */
1488
1489 static bfd_reloc_status_type
1490 mips_elf_final_gp (output_bfd, symbol, relocateable, error_message, pgp)
1491 bfd *output_bfd;
1492 asymbol *symbol;
1493 bfd_boolean relocateable;
1494 char **error_message;
1495 bfd_vma *pgp;
1496 {
1497 if (bfd_is_und_section (symbol->section)
1498 && ! relocateable)
1499 {
1500 *pgp = 0;
1501 return bfd_reloc_undefined;
1502 }
1503
1504 *pgp = _bfd_get_gp_value (output_bfd);
1505 if (*pgp == 0
1506 && (! relocateable
1507 || (symbol->flags & BSF_SECTION_SYM) != 0))
1508 {
1509 if (relocateable)
1510 {
1511 /* Make up a value. */
1512 *pgp = symbol->section->output_section->vma /*+ 0x4000*/;
1513 _bfd_set_gp_value (output_bfd, *pgp);
1514 }
1515 else if (!mips_elf_assign_gp (output_bfd, pgp))
1516 {
1517 *error_message =
1518 (char *) _("GP relative relocation when _gp not defined");
1519 return bfd_reloc_dangerous;
1520 }
1521 }
1522
1523 return bfd_reloc_ok;
1524 }
1525
1526 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1527 become the offset from the gp register. */
1528
1529 static bfd_reloc_status_type
1530 mips_elf_gprel16_reloc (abfd, reloc_entry, symbol, data, input_section,
1531 output_bfd, error_message)
1532 bfd *abfd ATTRIBUTE_UNUSED;
1533 arelent *reloc_entry;
1534 asymbol *symbol;
1535 PTR data ATTRIBUTE_UNUSED;
1536 asection *input_section;
1537 bfd *output_bfd;
1538 char **error_message ATTRIBUTE_UNUSED;
1539 {
1540 bfd_boolean relocateable;
1541 bfd_reloc_status_type ret;
1542 bfd_vma gp;
1543
1544 GET_RELOC_ADDEND (output_bfd, symbol, reloc_entry, input_section)
1545
1546 if (output_bfd != (bfd *) NULL)
1547 relocateable = TRUE;
1548 else
1549 {
1550 relocateable = FALSE;
1551 output_bfd = symbol->section->output_section->owner;
1552 }
1553
1554 ret = mips_elf_final_gp (output_bfd, symbol, relocateable, error_message,
1555 &gp);
1556 if (ret != bfd_reloc_ok)
1557 return ret;
1558
1559 return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1560 input_section, relocateable,
1561 data, gp);
1562 }
1563
1564 /* Do a R_MIPS_LITERAL relocation. */
1565
1566 static bfd_reloc_status_type
1567 mips_elf_literal_reloc (abfd, reloc_entry, symbol, data, input_section,
1568 output_bfd, error_message)
1569 bfd *abfd;
1570 arelent *reloc_entry;
1571 asymbol *symbol;
1572 PTR data;
1573 asection *input_section;
1574 bfd *output_bfd;
1575 char **error_message;
1576 {
1577 bfd_boolean relocateable;
1578 bfd_reloc_status_type ret;
1579 bfd_vma gp;
1580
1581 GET_RELOC_ADDEND (output_bfd, symbol, reloc_entry, input_section)
1582
1583 /* FIXME: The entries in the .lit8 and .lit4 sections should be merged. */
1584 if (output_bfd != (bfd *) NULL)
1585 relocateable = TRUE;
1586 else
1587 {
1588 relocateable = FALSE;
1589 output_bfd = symbol->section->output_section->owner;
1590 }
1591
1592 ret = mips_elf_final_gp (output_bfd, symbol, relocateable, error_message,
1593 &gp);
1594 if (ret != bfd_reloc_ok)
1595 return ret;
1596
1597 return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1598 input_section, relocateable,
1599 data, gp);
1600 }
1601
1602 /* Do a R_MIPS_GPREL32 relocation. This is a 32 bit value which must
1603 become the offset from the gp register. */
1604
1605 static bfd_reloc_status_type
1606 mips_elf_gprel32_reloc (abfd, reloc_entry, symbol, data, input_section,
1607 output_bfd, error_message)
1608 bfd *abfd;
1609 arelent *reloc_entry;
1610 asymbol *symbol;
1611 PTR data;
1612 asection *input_section;
1613 bfd *output_bfd;
1614 char **error_message;
1615 {
1616 bfd_boolean relocateable;
1617 bfd_reloc_status_type ret;
1618 bfd_vma gp;
1619
1620 GET_RELOC_ADDEND (output_bfd, symbol, reloc_entry, input_section)
1621
1622 /* R_MIPS_GPREL32 relocations are defined for local symbols only.
1623 We will only have an addend if this is a newly created reloc,
1624 not read from an ELF file. */
1625 if (output_bfd != (bfd *) NULL
1626 && (symbol->flags & BSF_SECTION_SYM) == 0
1627 && reloc_entry->addend == 0)
1628 {
1629 *error_message = (char *)
1630 _("32bits gp relative relocation occurs for an external symbol");
1631 return bfd_reloc_outofrange;
1632 }
1633
1634 if (output_bfd != (bfd *) NULL)
1635 {
1636 relocateable = TRUE;
1637 gp = _bfd_get_gp_value (output_bfd);
1638 }
1639 else
1640 {
1641 relocateable = FALSE;
1642 output_bfd = symbol->section->output_section->owner;
1643
1644 ret = mips_elf_final_gp (output_bfd, symbol, relocateable,
1645 error_message, &gp);
1646 if (ret != bfd_reloc_ok)
1647 return ret;
1648 }
1649
1650 return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
1651 relocateable, data, gp);
1652 }
1653
1654 static bfd_reloc_status_type
1655 gprel32_with_gp (abfd, symbol, reloc_entry, input_section, relocateable, data,
1656 gp)
1657 bfd *abfd;
1658 asymbol *symbol;
1659 arelent *reloc_entry;
1660 asection *input_section;
1661 bfd_boolean relocateable;
1662 PTR data;
1663 bfd_vma gp;
1664 {
1665 bfd_vma relocation;
1666 unsigned long val;
1667
1668 if (bfd_is_com_section (symbol->section))
1669 relocation = 0;
1670 else
1671 relocation = symbol->value;
1672
1673 relocation += symbol->section->output_section->vma;
1674 relocation += symbol->section->output_offset;
1675
1676 if (reloc_entry->address > input_section->_cooked_size)
1677 return bfd_reloc_outofrange;
1678
1679 if (reloc_entry->howto->src_mask == 0)
1680 val = 0;
1681 else
1682 val = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1683
1684 /* Set val to the offset into the section or symbol. */
1685 val += reloc_entry->addend;
1686
1687 /* Adjust val for the final section location and GP value. If we
1688 are producing relocateable output, we don't want to do this for
1689 an external symbol. */
1690 if (! relocateable
1691 || (symbol->flags & BSF_SECTION_SYM) != 0)
1692 val += relocation - gp;
1693
1694 bfd_put_32 (abfd, (bfd_vma) val, (bfd_byte *) data + reloc_entry->address);
1695
1696 if (relocateable)
1697 reloc_entry->address += input_section->output_offset;
1698
1699 return bfd_reloc_ok;
1700 }
1701
1702 /* Do a R_MIPS_SHIFT6 relocation. The MSB of the shift is stored at bit 2,
1703 the rest is at bits 6-10. The bitpos already got right by the howto. */
1704
1705 static bfd_reloc_status_type
1706 mips_elf_shift6_reloc (abfd, reloc_entry, symbol, data, input_section,
1707 output_bfd, error_message)
1708 bfd *abfd ATTRIBUTE_UNUSED;
1709 arelent *reloc_entry;
1710 asymbol *symbol;
1711 PTR data ATTRIBUTE_UNUSED;
1712 asection *input_section;
1713 bfd *output_bfd;
1714 char **error_message ATTRIBUTE_UNUSED;
1715 {
1716 GET_RELOC_ADDEND (output_bfd, symbol, reloc_entry, input_section)
1717
1718 reloc_entry->addend = (reloc_entry->addend & 0x00007c0)
1719 | (reloc_entry->addend & 0x00000800) >> 9;
1720
1721 SET_RELOC_ADDEND (reloc_entry)
1722
1723 return bfd_reloc_continue;
1724 }
1725 \f
1726 /* Handle a mips16 jump. */
1727
1728 static bfd_reloc_status_type
1729 mips16_jump_reloc (abfd, reloc_entry, symbol, data, input_section,
1730 output_bfd, error_message)
1731 bfd *abfd ATTRIBUTE_UNUSED;
1732 arelent *reloc_entry;
1733 asymbol *symbol;
1734 PTR data ATTRIBUTE_UNUSED;
1735 asection *input_section;
1736 bfd *output_bfd;
1737 char **error_message ATTRIBUTE_UNUSED;
1738 {
1739 static bfd_boolean warned = FALSE;
1740
1741 GET_RELOC_ADDEND (output_bfd, symbol, reloc_entry, input_section)
1742
1743 /* FIXME. */
1744 if (! warned)
1745 (*_bfd_error_handler)
1746 (_("Linking mips16 objects into %s format is not supported"),
1747 bfd_get_target (input_section->output_section->owner));
1748 warned = TRUE;
1749
1750 return bfd_reloc_undefined;
1751 }
1752
1753 /* Handle a mips16 GP relative reloc. */
1754
1755 static bfd_reloc_status_type
1756 mips16_gprel_reloc (abfd, reloc_entry, symbol, data, input_section,
1757 output_bfd, error_message)
1758 bfd *abfd;
1759 arelent *reloc_entry;
1760 asymbol *symbol;
1761 PTR data;
1762 asection *input_section;
1763 bfd *output_bfd;
1764 char **error_message;
1765 {
1766 bfd_boolean relocateable;
1767 bfd_reloc_status_type ret;
1768 bfd_vma gp;
1769 unsigned short extend, insn;
1770 unsigned long final;
1771
1772 GET_RELOC_ADDEND (output_bfd, symbol, reloc_entry, input_section)
1773
1774 if (output_bfd != NULL)
1775 relocateable = TRUE;
1776 else
1777 {
1778 relocateable = FALSE;
1779 output_bfd = symbol->section->output_section->owner;
1780 }
1781
1782 ret = mips_elf_final_gp (output_bfd, symbol, relocateable, error_message,
1783 &gp);
1784 if (ret != bfd_reloc_ok)
1785 return ret;
1786
1787 if (reloc_entry->address > input_section->_cooked_size)
1788 return bfd_reloc_outofrange;
1789
1790 /* Pick up the mips16 extend instruction and the real instruction. */
1791 extend = bfd_get_16 (abfd, (bfd_byte *) data + reloc_entry->address);
1792 insn = bfd_get_16 (abfd, (bfd_byte *) data + reloc_entry->address + 2);
1793
1794 /* Stuff the current addend back as a 32 bit value, do the usual
1795 relocation, and then clean up. */
1796 bfd_put_32 (abfd,
1797 (bfd_vma) (((extend & 0x1f) << 11)
1798 | (extend & 0x7e0)
1799 | (insn & 0x1f)),
1800 (bfd_byte *) data + reloc_entry->address);
1801
1802 ret = _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1803 input_section, relocateable, data, gp);
1804
1805 final = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1806 bfd_put_16 (abfd,
1807 (bfd_vma) ((extend & 0xf800)
1808 | ((final >> 11) & 0x1f)
1809 | (final & 0x7e0)),
1810 (bfd_byte *) data + reloc_entry->address);
1811 bfd_put_16 (abfd,
1812 (bfd_vma) ((insn & 0xffe0)
1813 | (final & 0x1f)),
1814 (bfd_byte *) data + reloc_entry->address + 2);
1815
1816 return ret;
1817 }
1818
1819 #undef GET_RELOC_ADDEND
1820 #undef SET_RELOC_ADDEND
1821 \f
1822 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1823
1824 struct elf_reloc_map {
1825 bfd_reloc_code_real_type bfd_val;
1826 enum elf_mips_reloc_type elf_val;
1827 };
1828
1829 static const struct elf_reloc_map mips_reloc_map[] =
1830 {
1831 { BFD_RELOC_NONE, R_MIPS_NONE },
1832 { BFD_RELOC_16, R_MIPS_16 },
1833 { BFD_RELOC_32, R_MIPS_32 },
1834 /* There is no BFD reloc for R_MIPS_REL32. */
1835 { BFD_RELOC_CTOR, R_MIPS_32 },
1836 { BFD_RELOC_64, R_MIPS_64 },
1837 { BFD_RELOC_16_PCREL, R_MIPS_PC16 },
1838 { BFD_RELOC_HI16_S, R_MIPS_HI16 },
1839 { BFD_RELOC_LO16, R_MIPS_LO16 },
1840 { BFD_RELOC_GPREL16, R_MIPS_GPREL16 },
1841 { BFD_RELOC_GPREL32, R_MIPS_GPREL32 },
1842 { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
1843 { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
1844 { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
1845 { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
1846 { BFD_RELOC_MIPS_SHIFT5, R_MIPS_SHIFT5 },
1847 { BFD_RELOC_MIPS_SHIFT6, R_MIPS_SHIFT6 },
1848 { BFD_RELOC_MIPS_GOT_DISP, R_MIPS_GOT_DISP },
1849 { BFD_RELOC_MIPS_GOT_PAGE, R_MIPS_GOT_PAGE },
1850 { BFD_RELOC_MIPS_GOT_OFST, R_MIPS_GOT_OFST },
1851 { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
1852 { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 },
1853 { BFD_RELOC_MIPS_SUB, R_MIPS_SUB },
1854 { BFD_RELOC_MIPS_INSERT_A, R_MIPS_INSERT_A },
1855 { BFD_RELOC_MIPS_INSERT_B, R_MIPS_INSERT_B },
1856 { BFD_RELOC_MIPS_DELETE, R_MIPS_DELETE },
1857 { BFD_RELOC_MIPS_HIGHEST, R_MIPS_HIGHEST },
1858 { BFD_RELOC_MIPS_HIGHER, R_MIPS_HIGHER },
1859 { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 },
1860 { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 },
1861 { BFD_RELOC_MIPS_SCN_DISP, R_MIPS_SCN_DISP },
1862 { BFD_RELOC_MIPS_REL16, R_MIPS_REL16 },
1863 /* Use of R_MIPS_ADD_IMMEDIATE and R_MIPS_PJUMP is deprecated. */
1864 { BFD_RELOC_MIPS_RELGOT, R_MIPS_RELGOT },
1865 { BFD_RELOC_MIPS_JALR, R_MIPS_JALR }
1866 };
1867
1868 /* Given a BFD reloc type, return a howto structure. */
1869
1870 static reloc_howto_type *
1871 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
1872 bfd *abfd ATTRIBUTE_UNUSED;
1873 bfd_reloc_code_real_type code;
1874 {
1875 unsigned int i;
1876 /* FIXME: We default to RELA here instead of choosing the right
1877 relocation variant. */
1878 reloc_howto_type *howto_table = elf_mips_howto_table_rela;
1879
1880 for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map);
1881 i++)
1882 {
1883 if (mips_reloc_map[i].bfd_val == code)
1884 return &howto_table[(int) mips_reloc_map[i].elf_val];
1885 }
1886
1887 switch (code)
1888 {
1889 case BFD_RELOC_MIPS16_JMP:
1890 return &elf_mips16_jump_howto;
1891 case BFD_RELOC_MIPS16_GPREL:
1892 return &elf_mips16_gprel_howto;
1893 case BFD_RELOC_VTABLE_INHERIT:
1894 return &elf_mips_gnu_vtinherit_howto;
1895 case BFD_RELOC_VTABLE_ENTRY:
1896 return &elf_mips_gnu_vtentry_howto;
1897 default:
1898 bfd_set_error (bfd_error_bad_value);
1899 return NULL;
1900 }
1901 }
1902
1903 /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */
1904
1905 static reloc_howto_type *
1906 mips_elf_n32_rtype_to_howto (r_type, rela_p)
1907 unsigned int r_type;
1908 bfd_boolean rela_p;
1909 {
1910 switch (r_type)
1911 {
1912 case R_MIPS16_26:
1913 return &elf_mips16_jump_howto;
1914 case R_MIPS16_GPREL:
1915 return &elf_mips16_gprel_howto;
1916 case R_MIPS_GNU_VTINHERIT:
1917 return &elf_mips_gnu_vtinherit_howto;
1918 case R_MIPS_GNU_VTENTRY:
1919 return &elf_mips_gnu_vtentry_howto;
1920 default:
1921 BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
1922 if (rela_p)
1923 return &elf_mips_howto_table_rela[r_type];
1924 else
1925 return &elf_mips_howto_table_rel[r_type];
1926 break;
1927 }
1928 }
1929
1930 /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */
1931
1932 static void
1933 mips_info_to_howto_rel (abfd, cache_ptr, dst)
1934 bfd *abfd;
1935 arelent *cache_ptr;
1936 Elf_Internal_Rela *dst;
1937 {
1938 unsigned int r_type;
1939
1940 r_type = ELF32_R_TYPE (dst->r_info);
1941 cache_ptr->howto = mips_elf_n32_rtype_to_howto (r_type, FALSE);
1942
1943 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1944 value for the object file. We get the addend now, rather than
1945 when we do the relocation, because the symbol manipulations done
1946 by the linker may cause us to lose track of the input BFD. */
1947 if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
1948 && (r_type == (unsigned int) R_MIPS_GPREL16
1949 || r_type == (unsigned int) R_MIPS_LITERAL))
1950 cache_ptr->addend = elf_gp (abfd);
1951 }
1952
1953 /* Given a MIPS Elf_Internal_Rela, fill in an arelent structure. */
1954
1955 static void
1956 mips_info_to_howto_rela (abfd, cache_ptr, dst)
1957 bfd *abfd ATTRIBUTE_UNUSED;
1958 arelent *cache_ptr;
1959 Elf_Internal_Rela *dst;
1960 {
1961 unsigned int r_type;
1962
1963 r_type = ELF32_R_TYPE (dst->r_info);
1964 cache_ptr->howto = mips_elf_n32_rtype_to_howto (r_type, TRUE);
1965 cache_ptr->addend = dst->r_addend;
1966 }
1967 \f
1968 /* Determine whether a symbol is global for the purposes of splitting
1969 the symbol table into global symbols and local symbols. At least
1970 on Irix 5, this split must be between section symbols and all other
1971 symbols. On most ELF targets the split is between static symbols
1972 and externally visible symbols. */
1973
1974 static bfd_boolean
1975 mips_elf_sym_is_global (abfd, sym)
1976 bfd *abfd ATTRIBUTE_UNUSED;
1977 asymbol *sym;
1978 {
1979 if (SGI_COMPAT (abfd))
1980 return (sym->flags & BSF_SECTION_SYM) == 0;
1981 else
1982 return ((sym->flags & (BSF_GLOBAL | BSF_WEAK)) != 0
1983 || bfd_is_und_section (bfd_get_section (sym))
1984 || bfd_is_com_section (bfd_get_section (sym)));
1985 }
1986 \f
1987 /* Set the right machine number for a MIPS ELF file. */
1988
1989 static bfd_boolean
1990 mips_elf_n32_object_p (abfd)
1991 bfd *abfd;
1992 {
1993 unsigned long mach;
1994
1995 /* Irix 5 and 6 are broken. Object file symbol tables are not always
1996 sorted correctly such that local symbols precede global symbols,
1997 and the sh_info field in the symbol table is not always right. */
1998 if (SGI_COMPAT (abfd))
1999 elf_bad_symtab (abfd) = TRUE;
2000
2001 mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags);
2002 bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach);
2003
2004 if (! ABI_N32_P(abfd))
2005 return FALSE;
2006
2007 return TRUE;
2008 }
2009 \f
2010 /* Support for core dump NOTE sections. */
2011 static bfd_boolean
2012 elf32_mips_grok_prstatus (abfd, note)
2013 bfd *abfd;
2014 Elf_Internal_Note *note;
2015 {
2016 int offset;
2017 unsigned int raw_size;
2018
2019 switch (note->descsz)
2020 {
2021 default:
2022 return FALSE;
2023
2024 case 256: /* Linux/MIPS */
2025 /* pr_cursig */
2026 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
2027
2028 /* pr_pid */
2029 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
2030
2031 /* pr_reg */
2032 offset = 72;
2033 raw_size = 180;
2034
2035 break;
2036 }
2037
2038 /* Make a ".reg/999" section. */
2039 return _bfd_elfcore_make_pseudosection (abfd, ".reg", raw_size,
2040 note->descpos + offset);
2041 }
2042
2043 static bfd_boolean
2044 elf32_mips_grok_psinfo (abfd, note)
2045 bfd *abfd;
2046 Elf_Internal_Note *note;
2047 {
2048 switch (note->descsz)
2049 {
2050 default:
2051 return FALSE;
2052
2053 case 128: /* Linux/MIPS elf_prpsinfo */
2054 elf_tdata (abfd)->core_program
2055 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
2056 elf_tdata (abfd)->core_command
2057 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
2058 }
2059
2060 /* Note that for some reason, a spurious space is tacked
2061 onto the end of the args in some (at least one anyway)
2062 implementations, so strip it off if it exists. */
2063
2064 {
2065 char *command = elf_tdata (abfd)->core_command;
2066 int n = strlen (command);
2067
2068 if (0 < n && command[n - 1] == ' ')
2069 command[n - 1] = '\0';
2070 }
2071
2072 return TRUE;
2073 }
2074 \f
2075 /* Depending on the target vector we generate some version of Irix
2076 executables or "normal" MIPS ELF ABI executables. */
2077 static irix_compat_t
2078 elf_n32_mips_irix_compat (abfd)
2079 bfd *abfd;
2080 {
2081 if ((abfd->xvec == &bfd_elf32_nbigmips_vec)
2082 || (abfd->xvec == &bfd_elf32_nlittlemips_vec))
2083 return ict_irix6;
2084 else
2085 return ict_none;
2086 }
2087 \f
2088 /* ECOFF swapping routines. These are used when dealing with the
2089 .mdebug section, which is in the ECOFF debugging format. */
2090 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = {
2091 /* Symbol table magic number. */
2092 magicSym,
2093 /* Alignment of debugging information. E.g., 4. */
2094 4,
2095 /* Sizes of external symbolic information. */
2096 sizeof (struct hdr_ext),
2097 sizeof (struct dnr_ext),
2098 sizeof (struct pdr_ext),
2099 sizeof (struct sym_ext),
2100 sizeof (struct opt_ext),
2101 sizeof (struct fdr_ext),
2102 sizeof (struct rfd_ext),
2103 sizeof (struct ext_ext),
2104 /* Functions to swap in external symbolic data. */
2105 ecoff_swap_hdr_in,
2106 ecoff_swap_dnr_in,
2107 ecoff_swap_pdr_in,
2108 ecoff_swap_sym_in,
2109 ecoff_swap_opt_in,
2110 ecoff_swap_fdr_in,
2111 ecoff_swap_rfd_in,
2112 ecoff_swap_ext_in,
2113 _bfd_ecoff_swap_tir_in,
2114 _bfd_ecoff_swap_rndx_in,
2115 /* Functions to swap out external symbolic data. */
2116 ecoff_swap_hdr_out,
2117 ecoff_swap_dnr_out,
2118 ecoff_swap_pdr_out,
2119 ecoff_swap_sym_out,
2120 ecoff_swap_opt_out,
2121 ecoff_swap_fdr_out,
2122 ecoff_swap_rfd_out,
2123 ecoff_swap_ext_out,
2124 _bfd_ecoff_swap_tir_out,
2125 _bfd_ecoff_swap_rndx_out,
2126 /* Function to read in symbolic data. */
2127 _bfd_mips_elf_read_ecoff_info
2128 };
2129 \f
2130 #define ELF_ARCH bfd_arch_mips
2131 #define ELF_MACHINE_CODE EM_MIPS
2132
2133 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
2134 a value of 0x1000, and we are compatible.
2135 FIXME: How does this affect NewABI? */
2136 #define ELF_MAXPAGESIZE 0x1000
2137
2138 #define elf_backend_collect TRUE
2139 #define elf_backend_type_change_ok TRUE
2140 #define elf_backend_can_gc_sections TRUE
2141 #define elf_info_to_howto mips_info_to_howto_rela
2142 #define elf_info_to_howto_rel mips_info_to_howto_rel
2143 #define elf_backend_sym_is_global mips_elf_sym_is_global
2144 #define elf_backend_object_p mips_elf_n32_object_p
2145 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
2146 #define elf_backend_section_processing _bfd_mips_elf_section_processing
2147 #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
2148 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
2149 #define elf_backend_section_from_bfd_section \
2150 _bfd_mips_elf_section_from_bfd_section
2151 #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
2152 #define elf_backend_link_output_symbol_hook \
2153 _bfd_mips_elf_link_output_symbol_hook
2154 #define elf_backend_create_dynamic_sections \
2155 _bfd_mips_elf_create_dynamic_sections
2156 #define elf_backend_check_relocs _bfd_mips_elf_check_relocs
2157 #define elf_backend_adjust_dynamic_symbol \
2158 _bfd_mips_elf_adjust_dynamic_symbol
2159 #define elf_backend_always_size_sections \
2160 _bfd_mips_elf_always_size_sections
2161 #define elf_backend_size_dynamic_sections \
2162 _bfd_mips_elf_size_dynamic_sections
2163 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section
2164 #define elf_backend_finish_dynamic_symbol \
2165 _bfd_mips_elf_finish_dynamic_symbol
2166 #define elf_backend_finish_dynamic_sections \
2167 _bfd_mips_elf_finish_dynamic_sections
2168 #define elf_backend_final_write_processing \
2169 _bfd_mips_elf_final_write_processing
2170 #define elf_backend_additional_program_headers \
2171 _bfd_mips_elf_additional_program_headers
2172 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
2173 #define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
2174 #define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
2175 #define elf_backend_copy_indirect_symbol \
2176 _bfd_mips_elf_copy_indirect_symbol
2177 #define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
2178 #define elf_backend_grok_prstatus elf32_mips_grok_prstatus
2179 #define elf_backend_grok_psinfo elf32_mips_grok_psinfo
2180 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
2181
2182 #define elf_backend_got_header_size (4 * MIPS_RESERVED_GOTNO)
2183 #define elf_backend_plt_header_size 0
2184
2185 /* MIPS n32 ELF can use a mixture of REL and RELA, but some Relocations
2186 work better/work only in RELA, so we default to this. */
2187 #define elf_backend_may_use_rel_p 1
2188 #define elf_backend_may_use_rela_p 1
2189 #define elf_backend_default_use_rela_p 1
2190 #define elf_backend_sign_extend_vma TRUE
2191
2192 #define elf_backend_discard_info _bfd_mips_elf_discard_info
2193 #define elf_backend_ignore_discarded_relocs \
2194 _bfd_mips_elf_ignore_discarded_relocs
2195 #define elf_backend_write_section _bfd_mips_elf_write_section
2196 #define elf_backend_mips_irix_compat elf_n32_mips_irix_compat
2197 #define elf_backend_mips_rtype_to_howto mips_elf_n32_rtype_to_howto
2198 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
2199 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
2200 #define bfd_elf32_bfd_get_relocated_section_contents \
2201 _bfd_elf_mips_get_relocated_section_contents
2202 #define bfd_elf32_bfd_link_hash_table_create \
2203 _bfd_mips_elf_link_hash_table_create
2204 #define bfd_elf32_bfd_final_link _bfd_mips_elf_final_link
2205 #define bfd_elf32_bfd_merge_private_bfd_data \
2206 _bfd_mips_elf_merge_private_bfd_data
2207 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
2208 #define bfd_elf32_bfd_print_private_bfd_data \
2209 _bfd_mips_elf_print_private_bfd_data
2210
2211 /* Support for SGI-ish mips targets using n32 ABI. */
2212
2213 #define TARGET_LITTLE_SYM bfd_elf32_nlittlemips_vec
2214 #define TARGET_LITTLE_NAME "elf32-nlittlemips"
2215 #define TARGET_BIG_SYM bfd_elf32_nbigmips_vec
2216 #define TARGET_BIG_NAME "elf32-nbigmips"
2217
2218 #include "elf32-target.h"
2219
2220 /* Support for traditional mips targets using n32 ABI. */
2221 #define INCLUDED_TARGET_FILE /* More a type of flag. */
2222
2223 #undef TARGET_LITTLE_SYM
2224 #undef TARGET_LITTLE_NAME
2225 #undef TARGET_BIG_SYM
2226 #undef TARGET_BIG_NAME
2227
2228 #define TARGET_LITTLE_SYM bfd_elf32_ntradlittlemips_vec
2229 #define TARGET_LITTLE_NAME "elf32-ntradlittlemips"
2230 #define TARGET_BIG_SYM bfd_elf32_ntradbigmips_vec
2231 #define TARGET_BIG_NAME "elf32-ntradbigmips"
2232
2233 /* Include the target file again for this target. */
2234 #include "elf32-target.h"
This page took 0.097684 seconds and 4 git commands to generate.