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.
5 Most of the information added by Ian Lance Taylor, Cygnus Support,
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>
12 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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. */
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. */
38 #include "elfxx-mips.h"
41 /* Get the ECOFF swapping routines. */
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"
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
,
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
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
96 extern const bfd_target bfd_elf32_nbigmips_vec
;
97 extern const bfd_target bfd_elf32_nlittlemips_vec
;
99 static bfd_vma prev_reloc_address
= -1;
100 static bfd_vma prev_reloc_addend
= 0;
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)
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)
110 /* The number of local .got entries we reserve. */
111 #define MIPS_RESERVED_GOTNO (2)
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)
117 /* The relocation table used for SHT_REL sections. */
119 static reloc_howto_type elf_mips_howto_table_rel
[] =
122 HOWTO (R_MIPS_NONE
, /* type */
124 0, /* size (0 = byte, 1 = short, 2 = long) */
126 FALSE
, /* pc_relative */
128 complain_overflow_dont
, /* complain_on_overflow */
129 mips_elf_generic_reloc
, /* special_function */
130 "R_MIPS_NONE", /* name */
131 FALSE
, /* partial_inplace */
134 FALSE
), /* pcrel_offset */
136 /* 16 bit relocation. */
137 HOWTO (R_MIPS_16
, /* type */
139 2, /* size (0 = byte, 1 = short, 2 = long) */
141 FALSE
, /* pc_relative */
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 */
151 /* 32 bit relocation. */
152 HOWTO (R_MIPS_32
, /* type */
154 2, /* size (0 = byte, 1 = short, 2 = long) */
156 FALSE
, /* pc_relative */
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 */
166 /* 32 bit symbol relative relocation. */
167 HOWTO (R_MIPS_REL32
, /* type */
169 2, /* size (0 = byte, 1 = short, 2 = long) */
171 FALSE
, /* pc_relative */
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 */
181 /* 26 bit jump address. */
182 HOWTO (R_MIPS_26
, /* type */
184 2, /* size (0 = byte, 1 = short, 2 = long) */
186 FALSE
, /* pc_relative */
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 */
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. */
202 /* High 16 bits of symbol value. */
203 HOWTO (R_MIPS_HI16
, /* type */
205 2, /* size (0 = byte, 1 = short, 2 = long) */
207 FALSE
, /* pc_relative */
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 */
217 /* Low 16 bits of symbol value. */
218 HOWTO (R_MIPS_LO16
, /* type */
220 2, /* size (0 = byte, 1 = short, 2 = long) */
222 FALSE
, /* pc_relative */
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 */
232 /* GP relative reference. */
233 HOWTO (R_MIPS_GPREL16
, /* type */
235 2, /* size (0 = byte, 1 = short, 2 = long) */
237 FALSE
, /* pc_relative */
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 */
247 /* Reference to literal section. */
248 HOWTO (R_MIPS_LITERAL
, /* type */
250 2, /* size (0 = byte, 1 = short, 2 = long) */
252 FALSE
, /* pc_relative */
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 */
262 /* Reference to global offset table. */
263 HOWTO (R_MIPS_GOT16
, /* type */
265 2, /* size (0 = byte, 1 = short, 2 = long) */
267 FALSE
, /* pc_relative */
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 */
277 /* 16 bit PC relative reference. */
278 HOWTO (R_MIPS_PC16
, /* type */
280 2, /* size (0 = byte, 1 = short, 2 = long) */
282 TRUE
, /* pc_relative */
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 */
292 /* 16 bit call through global offset table. */
293 HOWTO (R_MIPS_CALL16
, /* type */
295 2, /* size (0 = byte, 1 = short, 2 = long) */
297 FALSE
, /* pc_relative */
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 */
307 /* 32 bit GP relative reference. */
308 HOWTO (R_MIPS_GPREL32
, /* type */
310 2, /* size (0 = byte, 1 = short, 2 = long) */
312 FALSE
, /* pc_relative */
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 */
322 /* The remaining relocs are defined on Irix 5, although they are
323 not defined by the ABI. */
328 /* A 5 bit shift field. */
329 HOWTO (R_MIPS_SHIFT5
, /* type */
331 2, /* size (0 = byte, 1 = short, 2 = long) */
333 FALSE
, /* pc_relative */
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 */
343 /* A 6 bit shift field. */
344 HOWTO (R_MIPS_SHIFT6
, /* type */
346 2, /* size (0 = byte, 1 = short, 2 = long) */
348 FALSE
, /* pc_relative */
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 */
358 /* A 64 bit relocation. */
359 HOWTO (R_MIPS_64
, /* type */
361 4, /* size (0 = byte, 1 = short, 2 = long) */
363 FALSE
, /* pc_relative */
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 */
373 /* Displacement in the global offset table. */
374 HOWTO (R_MIPS_GOT_DISP
, /* type */
376 2, /* size (0 = byte, 1 = short, 2 = long) */
378 FALSE
, /* pc_relative */
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 */
388 /* Displacement to page pointer in the global offset table. */
389 HOWTO (R_MIPS_GOT_PAGE
, /* type */
391 2, /* size (0 = byte, 1 = short, 2 = long) */
393 FALSE
, /* pc_relative */
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 */
403 /* Offset from page pointer in the global offset table. */
404 HOWTO (R_MIPS_GOT_OFST
, /* type */
406 2, /* size (0 = byte, 1 = short, 2 = long) */
408 FALSE
, /* pc_relative */
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 */
418 /* High 16 bits of displacement in global offset table. */
419 HOWTO (R_MIPS_GOT_HI16
, /* type */
421 2, /* size (0 = byte, 1 = short, 2 = long) */
423 FALSE
, /* pc_relative */
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 */
433 /* Low 16 bits of displacement in global offset table. */
434 HOWTO (R_MIPS_GOT_LO16
, /* type */
436 2, /* size (0 = byte, 1 = short, 2 = long) */
438 FALSE
, /* pc_relative */
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 */
448 /* 64 bit subtraction. */
449 HOWTO (R_MIPS_SUB
, /* type */
451 4, /* size (0 = byte, 1 = short, 2 = long) */
453 FALSE
, /* pc_relative */
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 */
463 /* Insert the addend as an instruction. */
464 /* FIXME: Not handled correctly. */
465 HOWTO (R_MIPS_INSERT_A
, /* type */
467 2, /* size (0 = byte, 1 = short, 2 = long) */
469 FALSE
, /* pc_relative */
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 */
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 */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
486 FALSE
, /* pc_relative */
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 */
496 /* Delete a 32 bit instruction. */
497 /* FIXME: Not handled correctly. */
498 HOWTO (R_MIPS_DELETE
, /* type */
500 2, /* size (0 = byte, 1 = short, 2 = long) */
502 FALSE
, /* pc_relative */
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 */
512 /* The MIPS ELF64 ABI Draft wants us to support these for REL relocations.
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
517 b) No other NEwABI toolchain actually emits such relocations. */
518 EMPTY_HOWTO (R_MIPS_HIGHER
),
519 EMPTY_HOWTO (R_MIPS_HIGHEST
),
521 /* High 16 bits of displacement in global offset table. */
522 HOWTO (R_MIPS_CALL_HI16
, /* type */
524 2, /* size (0 = byte, 1 = short, 2 = long) */
526 FALSE
, /* pc_relative */
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 */
536 /* Low 16 bits of displacement in global offset table. */
537 HOWTO (R_MIPS_CALL_LO16
, /* type */
539 2, /* size (0 = byte, 1 = short, 2 = long) */
541 FALSE
, /* pc_relative */
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 */
551 /* Section displacement. */
552 HOWTO (R_MIPS_SCN_DISP
, /* type */
554 2, /* size (0 = byte, 1 = short, 2 = long) */
556 FALSE
, /* pc_relative */
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 */
566 HOWTO (R_MIPS_REL16
, /* type */
568 1, /* size (0 = byte, 1 = short, 2 = long) */
570 FALSE
, /* pc_relative */
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 */
580 /* These two are obsolete. */
581 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE
),
582 EMPTY_HOWTO (R_MIPS_PJUMP
),
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 */
588 2, /* size (0 = byte, 1 = short, 2 = long) */
590 FALSE
, /* pc_relative */
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 */
600 /* Protected jump conversion. This is an optimization hint. No
601 relocation is required for correctness. */
602 HOWTO (R_MIPS_JALR
, /* type */
604 2, /* size (0 = byte, 1 = short, 2 = long) */
606 FALSE
, /* pc_relative */
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 */
617 /* The relocation table used for SHT_RELA sections. */
619 static reloc_howto_type elf_mips_howto_table_rela
[] =
622 HOWTO (R_MIPS_NONE
, /* type */
624 0, /* size (0 = byte, 1 = short, 2 = long) */
626 FALSE
, /* pc_relative */
628 complain_overflow_dont
, /* complain_on_overflow */
629 mips_elf_generic_reloc
, /* special_function */
630 "R_MIPS_NONE", /* name */
631 FALSE
, /* partial_inplace */
634 FALSE
), /* pcrel_offset */
636 /* 16 bit relocation. */
637 HOWTO (R_MIPS_16
, /* type */
639 2, /* size (0 = byte, 1 = short, 2 = long) */
641 FALSE
, /* pc_relative */
643 complain_overflow_signed
, /* complain_on_overflow */
644 mips_elf_generic_reloc
, /* special_function */
645 "R_MIPS_16", /* name */
646 FALSE
, /* partial_inplace */
648 0x0000, /* dst_mask */
649 FALSE
), /* pcrel_offset */
651 /* 32 bit relocation. */
652 HOWTO (R_MIPS_32
, /* type */
654 2, /* size (0 = byte, 1 = short, 2 = long) */
656 FALSE
, /* pc_relative */
658 complain_overflow_dont
, /* complain_on_overflow */
659 mips_elf_generic_reloc
, /* special_function */
660 "R_MIPS_32", /* name */
661 FALSE
, /* partial_inplace */
663 0xffffffff, /* dst_mask */
664 FALSE
), /* pcrel_offset */
666 /* 32 bit symbol relative relocation. */
667 HOWTO (R_MIPS_REL32
, /* type */
669 2, /* size (0 = byte, 1 = short, 2 = long) */
671 FALSE
, /* pc_relative */
673 complain_overflow_dont
, /* complain_on_overflow */
674 mips_elf_generic_reloc
, /* special_function */
675 "R_MIPS_REL32", /* name */
676 FALSE
, /* partial_inplace */
678 0xffffffff, /* dst_mask */
679 FALSE
), /* pcrel_offset */
681 /* 26 bit jump address. */
682 HOWTO (R_MIPS_26
, /* type */
684 2, /* size (0 = byte, 1 = short, 2 = long) */
686 FALSE
, /* pc_relative */
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 */
696 0x03ffffff, /* dst_mask */
697 FALSE
), /* pcrel_offset */
699 /* High 16 bits of symbol value. */
700 HOWTO (R_MIPS_HI16
, /* type */
702 2, /* size (0 = byte, 1 = short, 2 = long) */
704 FALSE
, /* pc_relative */
706 complain_overflow_dont
, /* complain_on_overflow */
707 mips_elf_generic_reloc
, /* special_function */
708 "R_MIPS_HI16", /* name */
709 FALSE
, /* partial_inplace */
711 0x0000ffff, /* dst_mask */
712 FALSE
), /* pcrel_offset */
714 /* Low 16 bits of symbol value. */
715 HOWTO (R_MIPS_LO16
, /* type */
717 2, /* size (0 = byte, 1 = short, 2 = long) */
719 FALSE
, /* pc_relative */
721 complain_overflow_dont
, /* complain_on_overflow */
722 mips_elf_generic_reloc
, /* special_function */
723 "R_MIPS_LO16", /* name */
724 FALSE
, /* partial_inplace */
726 0x0000ffff, /* dst_mask */
727 FALSE
), /* pcrel_offset */
729 /* GP relative reference. */
730 HOWTO (R_MIPS_GPREL16
, /* type */
732 2, /* size (0 = byte, 1 = short, 2 = long) */
734 FALSE
, /* pc_relative */
736 complain_overflow_signed
, /* complain_on_overflow */
737 mips_elf_gprel16_reloc
, /* special_function */
738 "R_MIPS_GPREL16", /* name */
739 FALSE
, /* partial_inplace */
741 0x0000ffff, /* dst_mask */
742 FALSE
), /* pcrel_offset */
744 /* Reference to literal section. */
745 HOWTO (R_MIPS_LITERAL
, /* type */
747 2, /* size (0 = byte, 1 = short, 2 = long) */
749 FALSE
, /* pc_relative */
751 complain_overflow_signed
, /* complain_on_overflow */
752 mips_elf_literal_reloc
, /* special_function */
753 "R_MIPS_LITERAL", /* name */
754 FALSE
, /* partial_inplace */
756 0x0000ffff, /* dst_mask */
757 FALSE
), /* pcrel_offset */
759 /* Reference to global offset table. */
760 HOWTO (R_MIPS_GOT16
, /* type */
762 2, /* size (0 = byte, 1 = short, 2 = long) */
764 FALSE
, /* pc_relative */
766 complain_overflow_signed
, /* complain_on_overflow */
767 mips_elf_got16_reloc
, /* special_function */
768 "R_MIPS_GOT16", /* name */
769 FALSE
, /* partial_inplace */
771 0x0000ffff, /* dst_mask */
772 FALSE
), /* pcrel_offset */
774 /* 16 bit PC relative reference. */
775 HOWTO (R_MIPS_PC16
, /* type */
777 2, /* size (0 = byte, 1 = short, 2 = long) */
779 TRUE
, /* pc_relative */
781 complain_overflow_signed
, /* complain_on_overflow */
782 mips_elf_generic_reloc
, /* special_function */
783 "R_MIPS_PC16", /* name */
784 FALSE
, /* partial_inplace */
786 0x0000ffff, /* dst_mask */
787 TRUE
), /* pcrel_offset */
789 /* 16 bit call through global offset table. */
790 HOWTO (R_MIPS_CALL16
, /* type */
792 2, /* size (0 = byte, 1 = short, 2 = long) */
794 FALSE
, /* pc_relative */
796 complain_overflow_signed
, /* complain_on_overflow */
797 mips_elf_generic_reloc
, /* special_function */
798 "R_MIPS_CALL16", /* name */
799 FALSE
, /* partial_inplace */
801 0x0000ffff, /* dst_mask */
802 FALSE
), /* pcrel_offset */
804 /* 32 bit GP relative reference. */
805 HOWTO (R_MIPS_GPREL32
, /* type */
807 2, /* size (0 = byte, 1 = short, 2 = long) */
809 FALSE
, /* pc_relative */
811 complain_overflow_dont
, /* complain_on_overflow */
812 mips_elf_gprel32_reloc
, /* special_function */
813 "R_MIPS_GPREL32", /* name */
814 FALSE
, /* partial_inplace */
816 0xffffffff, /* dst_mask */
817 FALSE
), /* pcrel_offset */
823 /* A 5 bit shift field. */
824 HOWTO (R_MIPS_SHIFT5
, /* type */
826 2, /* size (0 = byte, 1 = short, 2 = long) */
828 FALSE
, /* pc_relative */
830 complain_overflow_bitfield
, /* complain_on_overflow */
831 mips_elf_generic_reloc
, /* special_function */
832 "R_MIPS_SHIFT5", /* name */
833 FALSE
, /* partial_inplace */
835 0x000007c0, /* dst_mask */
836 FALSE
), /* pcrel_offset */
838 /* A 6 bit shift field. */
839 HOWTO (R_MIPS_SHIFT6
, /* type */
841 2, /* size (0 = byte, 1 = short, 2 = long) */
843 FALSE
, /* pc_relative */
845 complain_overflow_bitfield
, /* complain_on_overflow */
846 mips_elf_shift6_reloc
, /* special_function */
847 "R_MIPS_SHIFT6", /* name */
848 FALSE
, /* partial_inplace */
850 0x000007c4, /* dst_mask */
851 FALSE
), /* pcrel_offset */
853 /* 64 bit relocation. */
854 HOWTO (R_MIPS_64
, /* type */
856 4, /* size (0 = byte, 1 = short, 2 = long) */
858 FALSE
, /* pc_relative */
860 complain_overflow_dont
, /* complain_on_overflow */
861 mips_elf_generic_reloc
, /* special_function */
862 "R_MIPS_64", /* name */
863 FALSE
, /* partial_inplace */
865 MINUS_ONE
, /* dst_mask */
866 FALSE
), /* pcrel_offset */
868 /* Displacement in the global offset table. */
869 HOWTO (R_MIPS_GOT_DISP
, /* type */
871 2, /* size (0 = byte, 1 = short, 2 = long) */
873 FALSE
, /* pc_relative */
875 complain_overflow_signed
, /* complain_on_overflow */
876 mips_elf_generic_reloc
, /* special_function */
877 "R_MIPS_GOT_DISP", /* name */
878 FALSE
, /* partial_inplace */
880 0x0000ffff, /* dst_mask */
881 FALSE
), /* pcrel_offset */
883 /* Displacement to page pointer in the global offset table. */
884 HOWTO (R_MIPS_GOT_PAGE
, /* type */
886 2, /* size (0 = byte, 1 = short, 2 = long) */
888 FALSE
, /* pc_relative */
890 complain_overflow_signed
, /* complain_on_overflow */
891 mips_elf_generic_reloc
, /* special_function */
892 "R_MIPS_GOT_PAGE", /* name */
893 FALSE
, /* partial_inplace */
895 0x0000ffff, /* dst_mask */
896 FALSE
), /* pcrel_offset */
898 /* Offset from page pointer in the global offset table. */
899 HOWTO (R_MIPS_GOT_OFST
, /* type */
901 2, /* size (0 = byte, 1 = short, 2 = long) */
903 FALSE
, /* pc_relative */
905 complain_overflow_signed
, /* complain_on_overflow */
906 mips_elf_generic_reloc
, /* special_function */
907 "R_MIPS_GOT_OFST", /* name */
908 FALSE
, /* partial_inplace */
910 0x0000ffff, /* dst_mask */
911 FALSE
), /* pcrel_offset */
913 /* High 16 bits of displacement in global offset table. */
914 HOWTO (R_MIPS_GOT_HI16
, /* type */
916 2, /* size (0 = byte, 1 = short, 2 = long) */
918 FALSE
, /* pc_relative */
920 complain_overflow_dont
, /* complain_on_overflow */
921 mips_elf_generic_reloc
, /* special_function */
922 "R_MIPS_GOT_HI16", /* name */
923 FALSE
, /* partial_inplace */
925 0x0000ffff, /* dst_mask */
926 FALSE
), /* pcrel_offset */
928 /* Low 16 bits of displacement in global offset table. */
929 HOWTO (R_MIPS_GOT_LO16
, /* type */
931 2, /* size (0 = byte, 1 = short, 2 = long) */
933 FALSE
, /* pc_relative */
935 complain_overflow_dont
, /* complain_on_overflow */
936 mips_elf_generic_reloc
, /* special_function */
937 "R_MIPS_GOT_LO16", /* name */
938 FALSE
, /* partial_inplace */
940 0x0000ffff, /* dst_mask */
941 FALSE
), /* pcrel_offset */
943 /* 64 bit substraction. */
944 HOWTO (R_MIPS_SUB
, /* type */
946 4, /* size (0 = byte, 1 = short, 2 = long) */
948 FALSE
, /* pc_relative */
950 complain_overflow_dont
, /* complain_on_overflow */
951 mips_elf_generic_reloc
, /* special_function */
952 "R_MIPS_SUB", /* name */
953 FALSE
, /* partial_inplace */
955 MINUS_ONE
, /* dst_mask */
956 FALSE
), /* pcrel_offset */
958 /* Insert the addend as an instruction. */
959 /* FIXME: Not handled correctly. */
960 HOWTO (R_MIPS_INSERT_A
, /* type */
962 2, /* size (0 = byte, 1 = short, 2 = long) */
964 FALSE
, /* pc_relative */
966 complain_overflow_dont
, /* complain_on_overflow */
967 mips_elf_generic_reloc
, /* special_function */
968 "R_MIPS_INSERT_A", /* name */
969 FALSE
, /* partial_inplace */
971 0xffffffff, /* dst_mask */
972 FALSE
), /* pcrel_offset */
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 */
979 2, /* size (0 = byte, 1 = short, 2 = long) */
981 FALSE
, /* pc_relative */
983 complain_overflow_dont
, /* complain_on_overflow */
984 mips_elf_generic_reloc
, /* special_function */
985 "R_MIPS_INSERT_B", /* name */
986 FALSE
, /* partial_inplace */
988 0xffffffff, /* dst_mask */
989 FALSE
), /* pcrel_offset */
991 /* Delete a 32 bit instruction. */
992 /* FIXME: Not handled correctly. */
993 HOWTO (R_MIPS_DELETE
, /* type */
995 2, /* size (0 = byte, 1 = short, 2 = long) */
997 FALSE
, /* pc_relative */
999 complain_overflow_dont
, /* complain_on_overflow */
1000 mips_elf_generic_reloc
, /* special_function */
1001 "R_MIPS_DELETE", /* name */
1002 FALSE
, /* partial_inplace */
1004 0xffffffff, /* dst_mask */
1005 FALSE
), /* pcrel_offset */
1007 /* Get the higher value of a 64 bit addend. */
1008 HOWTO (R_MIPS_HIGHER
, /* type */
1010 2, /* size (0 = byte, 1 = short, 2 = long) */
1012 FALSE
, /* pc_relative */
1014 complain_overflow_dont
, /* complain_on_overflow */
1015 mips_elf_generic_reloc
, /* special_function */
1016 "R_MIPS_HIGHER", /* name */
1017 FALSE
, /* partial_inplace */
1019 0x0000ffff, /* dst_mask */
1020 FALSE
), /* pcrel_offset */
1022 /* Get the highest value of a 64 bit addend. */
1023 HOWTO (R_MIPS_HIGHEST
, /* type */
1025 2, /* size (0 = byte, 1 = short, 2 = long) */
1027 FALSE
, /* pc_relative */
1029 complain_overflow_dont
, /* complain_on_overflow */
1030 mips_elf_generic_reloc
, /* special_function */
1031 "R_MIPS_HIGHEST", /* name */
1032 FALSE
, /* partial_inplace */
1034 0x0000ffff, /* dst_mask */
1035 FALSE
), /* pcrel_offset */
1037 /* High 16 bits of displacement in global offset table. */
1038 HOWTO (R_MIPS_CALL_HI16
, /* type */
1040 2, /* size (0 = byte, 1 = short, 2 = long) */
1042 FALSE
, /* pc_relative */
1044 complain_overflow_dont
, /* complain_on_overflow */
1045 mips_elf_generic_reloc
, /* special_function */
1046 "R_MIPS_CALL_HI16", /* name */
1047 FALSE
, /* partial_inplace */
1049 0x0000ffff, /* dst_mask */
1050 FALSE
), /* pcrel_offset */
1052 /* Low 16 bits of displacement in global offset table. */
1053 HOWTO (R_MIPS_CALL_LO16
, /* type */
1055 2, /* size (0 = byte, 1 = short, 2 = long) */
1057 FALSE
, /* pc_relative */
1059 complain_overflow_dont
, /* complain_on_overflow */
1060 mips_elf_generic_reloc
, /* special_function */
1061 "R_MIPS_CALL_LO16", /* name */
1062 FALSE
, /* partial_inplace */
1064 0x0000ffff, /* dst_mask */
1065 FALSE
), /* pcrel_offset */
1067 /* Section displacement, used by an associated event location section. */
1068 HOWTO (R_MIPS_SCN_DISP
, /* type */
1070 2, /* size (0 = byte, 1 = short, 2 = long) */
1072 FALSE
, /* pc_relative */
1074 complain_overflow_dont
, /* complain_on_overflow */
1075 mips_elf_generic_reloc
, /* special_function */
1076 "R_MIPS_SCN_DISP", /* name */
1077 FALSE
, /* partial_inplace */
1079 0xffffffff, /* dst_mask */
1080 FALSE
), /* pcrel_offset */
1082 /* 16 bit relocation. */
1083 HOWTO (R_MIPS_REL16
, /* type */
1085 1, /* size (0 = byte, 1 = short, 2 = long) */
1087 FALSE
, /* pc_relative */
1089 complain_overflow_signed
, /* complain_on_overflow */
1090 mips_elf_generic_reloc
, /* special_function */
1091 "R_MIPS_REL16", /* name */
1092 FALSE
, /* partial_inplace */
1094 0xffff, /* dst_mask */
1095 FALSE
), /* pcrel_offset */
1097 /* These two are obsolete. */
1098 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE
),
1099 EMPTY_HOWTO (R_MIPS_PJUMP
),
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 */
1105 2, /* size (0 = byte, 1 = short, 2 = long) */
1107 FALSE
, /* pc_relative */
1109 complain_overflow_dont
, /* complain_on_overflow */
1110 mips_elf_generic_reloc
, /* special_function */
1111 "R_MIPS_RELGOT", /* name */
1112 FALSE
, /* partial_inplace */
1114 0xffffffff, /* dst_mask */
1115 FALSE
), /* pcrel_offset */
1117 /* Protected jump conversion. This is an optimization hint. No
1118 relocation is required for correctness. */
1119 HOWTO (R_MIPS_JALR
, /* type */
1121 2, /* size (0 = byte, 1 = short, 2 = long) */
1123 FALSE
, /* pc_relative */
1125 complain_overflow_dont
, /* complain_on_overflow */
1126 mips_elf_generic_reloc
, /* special_function */
1127 "R_MIPS_JALR", /* name */
1128 FALSE
, /* partial_inplace */
1130 0xffffffff, /* dst_mask */
1131 FALSE
), /* pcrel_offset */
1134 /* The reloc used for the mips16 jump instruction. */
1135 static reloc_howto_type elf_mips16_jump_howto
=
1136 HOWTO (R_MIPS16_26
, /* type */
1138 2, /* size (0 = byte, 1 = short, 2 = long) */
1140 FALSE
, /* pc_relative */
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 */
1153 /* The reloc used for the mips16 gprel instruction. */
1154 static reloc_howto_type elf_mips16_gprel_howto
=
1155 HOWTO (R_MIPS16_GPREL
, /* type */
1157 2, /* size (0 = byte, 1 = short, 2 = long) */
1159 FALSE
, /* pc_relative */
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 */
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 */
1173 2, /* size (0 = byte, 1 = short, 2 = long) */
1175 FALSE
, /* pc_relative */
1177 complain_overflow_dont
, /* complain_on_overflow */
1178 NULL
, /* special_function */
1179 "R_MIPS_GNU_VTINHERIT", /* name */
1180 FALSE
, /* partial_inplace */
1183 FALSE
); /* pcrel_offset */
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 */
1189 2, /* size (0 = byte, 1 = short, 2 = long) */
1191 FALSE
, /* pc_relative */
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 */
1199 FALSE
); /* pcrel_offset */
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. */
1206 #define GET_RELOC_ADDEND(obfd, sym, entry, sec) \
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)) \
1215 entry->address += sec->output_offset; \
1216 return bfd_reloc_ok; \
1219 /* The addend of combined relocs is remembered and left for \
1220 subsequent relocs. */ \
1221 if (prev_reloc_address != reloc_entry->address) \
1223 prev_reloc_address = reloc_entry->address; \
1224 prev_reloc_addend = reloc_entry->addend; \
1227 reloc_entry->addend = prev_reloc_addend; \
1230 #define SET_RELOC_ADDEND(entry) \
1232 prev_reloc_addend = entry->addend; \
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
;
1241 PTR data ATTRIBUTE_UNUSED
;
1242 asection
*input_section
;
1244 char **error_message ATTRIBUTE_UNUSED
;
1246 GET_RELOC_ADDEND (output_bfd
, symbol
, reloc_entry
, input_section
)
1248 return bfd_reloc_continue
;
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.
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
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. */
1268 struct mips_hi16
*next
;
1273 /* FIXME: This should not be a static variable. */
1275 static struct mips_hi16
*mips_hi16_list
;
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
;
1284 asection
*input_section
;
1286 char **error_message ATTRIBUTE_UNUSED
;
1288 bfd_reloc_status_type ret
;
1290 struct mips_hi16
*n
;
1292 GET_RELOC_ADDEND (output_bfd
, symbol
, reloc_entry
, input_section
)
1296 if (bfd_is_und_section (symbol
->section
) && output_bfd
== (bfd
*) NULL
)
1297 ret
= bfd_reloc_undefined
;
1299 if (bfd_is_com_section (symbol
->section
))
1302 relocation
= symbol
->value
;
1304 relocation
+= symbol
->section
->output_section
->vma
;
1305 relocation
+= symbol
->section
->output_offset
;
1306 relocation
+= reloc_entry
->addend
;
1308 if (reloc_entry
->address
> input_section
->_cooked_size
)
1309 return bfd_reloc_outofrange
;
1311 /* Save the information, and let LO16 do the actual relocation. */
1312 n
= (struct mips_hi16
*) bfd_malloc ((bfd_size_type
) sizeof *n
);
1314 return bfd_reloc_outofrange
;
1315 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
1316 n
->addend
= relocation
;
1317 n
->next
= mips_hi16_list
;
1320 if (output_bfd
!= (bfd
*) NULL
)
1321 reloc_entry
->address
+= input_section
->output_offset
;
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. */
1330 static bfd_reloc_status_type
1331 mips_elf_lo16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1332 output_bfd
, error_message
)
1334 arelent
*reloc_entry
;
1337 asection
*input_section
;
1339 char **error_message
;
1341 if (mips_hi16_list
!= NULL
)
1343 struct mips_hi16
*l
;
1350 unsigned long vallo
;
1351 struct mips_hi16
*next
;
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
);
1359 /* The low order 16 bits are always treated as a signed
1361 vallo
= ((vallo
& 0xffff) ^ 0x8000) - 0x8000;
1362 val
= ((insn
& 0xffff) << 16) + vallo
;
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
;
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. */
1376 val
= (val
>> 16) & 0xffff;
1378 insn
&= ~ (bfd_vma
) 0xffff;
1380 bfd_put_32 (abfd
, (bfd_vma
) insn
, l
->addr
);
1387 mips_hi16_list
= NULL
;
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
);
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.
1406 This implementation suffices for the assembler, but the linker does
1407 not yet know how to create global offset tables. */
1409 static bfd_reloc_status_type
1410 mips_elf_got16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1411 output_bfd
, error_message
)
1413 arelent
*reloc_entry
;
1416 asection
*input_section
;
1418 char **error_message
;
1420 /* If we're relocating, and this is a local symbol, we can handle it
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
);
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
);
1432 /* Set the GP value for OUTPUT_BFD. Returns FALSE if this is a
1433 dangerous relocation. */
1436 mips_elf_assign_gp (output_bfd
, pgp
)
1444 /* If we've already figured out what GP will be, just return it. */
1445 *pgp
= _bfd_get_gp_value (output_bfd
);
1449 count
= bfd_get_symcount (output_bfd
);
1450 sym
= bfd_get_outsymbols (output_bfd
);
1452 /* The linker script will have created a symbol named `_gp' with the
1453 appropriate value. */
1454 if (sym
== (asymbol
**) NULL
)
1458 for (i
= 0; i
< count
; i
++, sym
++)
1460 register const char *name
;
1462 name
= bfd_asymbol_name (*sym
);
1463 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1465 *pgp
= bfd_asymbol_value (*sym
);
1466 _bfd_set_gp_value (output_bfd
, *pgp
);
1474 /* Only get the error once. */
1476 _bfd_set_gp_value (output_bfd
, *pgp
);
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. */
1489 static bfd_reloc_status_type
1490 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1493 bfd_boolean relocateable
;
1494 char **error_message
;
1497 if (bfd_is_und_section (symbol
->section
)
1501 return bfd_reloc_undefined
;
1504 *pgp
= _bfd_get_gp_value (output_bfd
);
1507 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1511 /* Make up a value. */
1512 *pgp
= symbol
->section
->output_section
->vma
/*+ 0x4000*/;
1513 _bfd_set_gp_value (output_bfd
, *pgp
);
1515 else if (!mips_elf_assign_gp (output_bfd
, pgp
))
1518 (char *) _("GP relative relocation when _gp not defined");
1519 return bfd_reloc_dangerous
;
1523 return bfd_reloc_ok
;
1526 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1527 become the offset from the gp register. */
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
;
1535 PTR data ATTRIBUTE_UNUSED
;
1536 asection
*input_section
;
1538 char **error_message ATTRIBUTE_UNUSED
;
1540 bfd_boolean relocateable
;
1541 bfd_reloc_status_type ret
;
1544 GET_RELOC_ADDEND (output_bfd
, symbol
, reloc_entry
, input_section
)
1546 if (output_bfd
!= (bfd
*) NULL
)
1547 relocateable
= TRUE
;
1550 relocateable
= FALSE
;
1551 output_bfd
= symbol
->section
->output_section
->owner
;
1554 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1556 if (ret
!= bfd_reloc_ok
)
1559 return _bfd_mips_elf_gprel16_with_gp (abfd
, symbol
, reloc_entry
,
1560 input_section
, relocateable
,
1564 /* Do a R_MIPS_LITERAL relocation. */
1566 static bfd_reloc_status_type
1567 mips_elf_literal_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1568 output_bfd
, error_message
)
1570 arelent
*reloc_entry
;
1573 asection
*input_section
;
1575 char **error_message
;
1577 bfd_boolean relocateable
;
1578 bfd_reloc_status_type ret
;
1581 GET_RELOC_ADDEND (output_bfd
, symbol
, reloc_entry
, input_section
)
1583 /* FIXME: The entries in the .lit8 and .lit4 sections should be merged. */
1584 if (output_bfd
!= (bfd
*) NULL
)
1585 relocateable
= TRUE
;
1588 relocateable
= FALSE
;
1589 output_bfd
= symbol
->section
->output_section
->owner
;
1592 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1594 if (ret
!= bfd_reloc_ok
)
1597 return _bfd_mips_elf_gprel16_with_gp (abfd
, symbol
, reloc_entry
,
1598 input_section
, relocateable
,
1602 /* Do a R_MIPS_GPREL32 relocation. This is a 32 bit value which must
1603 become the offset from the gp register. */
1605 static bfd_reloc_status_type
1606 mips_elf_gprel32_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1607 output_bfd
, error_message
)
1609 arelent
*reloc_entry
;
1612 asection
*input_section
;
1614 char **error_message
;
1616 bfd_boolean relocateable
;
1617 bfd_reloc_status_type ret
;
1620 GET_RELOC_ADDEND (output_bfd
, symbol
, reloc_entry
, input_section
)
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)
1629 *error_message
= (char *)
1630 _("32bits gp relative relocation occurs for an external symbol");
1631 return bfd_reloc_outofrange
;
1634 if (output_bfd
!= (bfd
*) NULL
)
1636 relocateable
= TRUE
;
1637 gp
= _bfd_get_gp_value (output_bfd
);
1641 relocateable
= FALSE
;
1642 output_bfd
= symbol
->section
->output_section
->owner
;
1644 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1645 error_message
, &gp
);
1646 if (ret
!= bfd_reloc_ok
)
1650 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1651 relocateable
, data
, gp
);
1654 static bfd_reloc_status_type
1655 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1659 arelent
*reloc_entry
;
1660 asection
*input_section
;
1661 bfd_boolean relocateable
;
1668 if (bfd_is_com_section (symbol
->section
))
1671 relocation
= symbol
->value
;
1673 relocation
+= symbol
->section
->output_section
->vma
;
1674 relocation
+= symbol
->section
->output_offset
;
1676 if (reloc_entry
->address
> input_section
->_cooked_size
)
1677 return bfd_reloc_outofrange
;
1679 if (reloc_entry
->howto
->src_mask
== 0)
1682 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1684 /* Set val to the offset into the section or symbol. */
1685 val
+= reloc_entry
->addend
;
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. */
1691 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1692 val
+= relocation
- gp
;
1694 bfd_put_32 (abfd
, (bfd_vma
) val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1697 reloc_entry
->address
+= input_section
->output_offset
;
1699 return bfd_reloc_ok
;
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. */
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
;
1711 PTR data ATTRIBUTE_UNUSED
;
1712 asection
*input_section
;
1714 char **error_message ATTRIBUTE_UNUSED
;
1716 GET_RELOC_ADDEND (output_bfd
, symbol
, reloc_entry
, input_section
)
1718 reloc_entry
->addend
= (reloc_entry
->addend
& 0x00007c0)
1719 | (reloc_entry
->addend
& 0x00000800) >> 9;
1721 SET_RELOC_ADDEND (reloc_entry
)
1723 return bfd_reloc_continue
;
1726 /* Handle a mips16 jump. */
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
;
1734 PTR data ATTRIBUTE_UNUSED
;
1735 asection
*input_section
;
1737 char **error_message ATTRIBUTE_UNUSED
;
1739 static bfd_boolean warned
= FALSE
;
1741 GET_RELOC_ADDEND (output_bfd
, symbol
, reloc_entry
, input_section
)
1745 (*_bfd_error_handler
)
1746 (_("Linking mips16 objects into %s format is not supported"),
1747 bfd_get_target (input_section
->output_section
->owner
));
1750 return bfd_reloc_undefined
;
1753 /* Handle a mips16 GP relative reloc. */
1755 static bfd_reloc_status_type
1756 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1757 output_bfd
, error_message
)
1759 arelent
*reloc_entry
;
1762 asection
*input_section
;
1764 char **error_message
;
1766 bfd_boolean relocateable
;
1767 bfd_reloc_status_type ret
;
1769 unsigned short extend
, insn
;
1770 unsigned long final
;
1772 GET_RELOC_ADDEND (output_bfd
, symbol
, reloc_entry
, input_section
)
1774 if (output_bfd
!= NULL
)
1775 relocateable
= TRUE
;
1778 relocateable
= FALSE
;
1779 output_bfd
= symbol
->section
->output_section
->owner
;
1782 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1784 if (ret
!= bfd_reloc_ok
)
1787 if (reloc_entry
->address
> input_section
->_cooked_size
)
1788 return bfd_reloc_outofrange
;
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);
1794 /* Stuff the current addend back as a 32 bit value, do the usual
1795 relocation, and then clean up. */
1797 (bfd_vma
) (((extend
& 0x1f) << 11)
1800 (bfd_byte
*) data
+ reloc_entry
->address
);
1802 ret
= _bfd_mips_elf_gprel16_with_gp (abfd
, symbol
, reloc_entry
,
1803 input_section
, relocateable
, data
, gp
);
1805 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1807 (bfd_vma
) ((extend
& 0xf800)
1808 | ((final
>> 11) & 0x1f)
1810 (bfd_byte
*) data
+ reloc_entry
->address
);
1812 (bfd_vma
) ((insn
& 0xffe0)
1814 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1819 #undef GET_RELOC_ADDEND
1820 #undef SET_RELOC_ADDEND
1822 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1824 struct elf_reloc_map
{
1825 bfd_reloc_code_real_type bfd_val
;
1826 enum elf_mips_reloc_type elf_val
;
1829 static const struct elf_reloc_map mips_reloc_map
[] =
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
}
1868 /* Given a BFD reloc type, return a howto structure. */
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
;
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
;
1880 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
);
1883 if (mips_reloc_map
[i
].bfd_val
== code
)
1884 return &howto_table
[(int) mips_reloc_map
[i
].elf_val
];
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
;
1898 bfd_set_error (bfd_error_bad_value
);
1903 /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */
1905 static reloc_howto_type
*
1906 mips_elf_n32_rtype_to_howto (r_type
, rela_p
)
1907 unsigned int r_type
;
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
;
1921 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1923 return &elf_mips_howto_table_rela
[r_type
];
1925 return &elf_mips_howto_table_rel
[r_type
];
1930 /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */
1933 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1936 Elf_Internal_Rela
*dst
;
1938 unsigned int r_type
;
1940 r_type
= ELF32_R_TYPE (dst
->r_info
);
1941 cache_ptr
->howto
= mips_elf_n32_rtype_to_howto (r_type
, FALSE
);
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
);
1953 /* Given a MIPS Elf_Internal_Rela, fill in an arelent structure. */
1956 mips_info_to_howto_rela (abfd
, cache_ptr
, dst
)
1957 bfd
*abfd ATTRIBUTE_UNUSED
;
1959 Elf_Internal_Rela
*dst
;
1961 unsigned int r_type
;
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
;
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. */
1975 mips_elf_sym_is_global (abfd
, sym
)
1976 bfd
*abfd ATTRIBUTE_UNUSED
;
1979 if (SGI_COMPAT (abfd
))
1980 return (sym
->flags
& BSF_SECTION_SYM
) == 0;
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
)));
1987 /* Set the right machine number for a MIPS ELF file. */
1990 mips_elf_n32_object_p (abfd
)
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
;
2001 mach
= _bfd_elf_mips_mach (elf_elfheader (abfd
)->e_flags
);
2002 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, mach
);
2004 if (! ABI_N32_P(abfd
))
2010 /* Support for core dump NOTE sections. */
2012 elf32_mips_grok_prstatus (abfd
, note
)
2014 Elf_Internal_Note
*note
;
2017 unsigned int raw_size
;
2019 switch (note
->descsz
)
2024 case 256: /* Linux/MIPS */
2026 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2029 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
2038 /* Make a ".reg/999" section. */
2039 return _bfd_elfcore_make_pseudosection (abfd
, ".reg", raw_size
,
2040 note
->descpos
+ offset
);
2044 elf32_mips_grok_psinfo (abfd
, note
)
2046 Elf_Internal_Note
*note
;
2048 switch (note
->descsz
)
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);
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. */
2065 char *command
= elf_tdata (abfd
)->core_command
;
2066 int n
= strlen (command
);
2068 if (0 < n
&& command
[n
- 1] == ' ')
2069 command
[n
- 1] = '\0';
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
)
2081 if ((abfd
->xvec
== &bfd_elf32_nbigmips_vec
)
2082 || (abfd
->xvec
== &bfd_elf32_nlittlemips_vec
))
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. */
2093 /* Alignment of debugging information. E.g., 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. */
2113 _bfd_ecoff_swap_tir_in
,
2114 _bfd_ecoff_swap_rndx_in
,
2115 /* Functions to swap out external symbolic data. */
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
2130 #define ELF_ARCH bfd_arch_mips
2131 #define ELF_MACHINE_CODE EM_MIPS
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
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
2182 #define elf_backend_got_header_size (4 * MIPS_RESERVED_GOTNO)
2183 #define elf_backend_plt_header_size 0
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
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
2211 /* Support for SGI-ish mips targets using n32 ABI. */
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"
2218 #include "elf32-target.h"
2220 /* Support for traditional mips targets using n32 ABI. */
2221 #define INCLUDED_TARGET_FILE /* More a type of flag. */
2223 #undef TARGET_LITTLE_SYM
2224 #undef TARGET_LITTLE_NAME
2225 #undef TARGET_BIG_SYM
2226 #undef TARGET_BIG_NAME
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"
2233 /* Include the target file again for this target. */
2234 #include "elf32-target.h"