1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
4 Most of the information added by Ian Lance Taylor, Cygnus Support,
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 /* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
24 different MIPS ELF from other targets. This matters when linking.
25 This file supports both, switching at runtime. */
35 /* Get the ECOFF swapping routines. */
37 #include "coff/symconst.h"
38 #include "coff/internal.h"
39 #include "coff/ecoff.h"
40 #include "coff/mips.h"
42 #include "ecoffswap.h"
44 static bfd_reloc_status_type mips32_64bit_reloc
45 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
46 static reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
47 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
48 static void mips_info_to_howto_rel
49 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
50 static void bfd_mips_elf32_swap_gptab_in
51 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
52 static void bfd_mips_elf32_swap_gptab_out
53 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
54 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
55 static boolean mips_elf32_object_p
PARAMS ((bfd
*));
56 static boolean mips_elf_create_procedure_table
57 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
58 struct ecoff_debug_info
*));
59 static int mips_elf_additional_program_headers
PARAMS ((bfd
*));
60 static boolean mips_elf_modify_segment_map
PARAMS ((bfd
*));
61 static INLINE
int elf_mips_isa
PARAMS ((flagword
));
62 static INLINE
int elf_mips_mach
PARAMS ((flagword
));
63 static boolean mips_elf32_section_from_shdr
64 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, char *));
65 static boolean mips_elf32_section_processing
66 PARAMS ((bfd
*, Elf32_Internal_Shdr
*));
67 static boolean mips_elf_is_local_label_name
68 PARAMS ((bfd
*, const char *));
69 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
70 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
71 static struct bfd_link_hash_table
*mips_elf_link_hash_table_create
73 static int gptab_compare
PARAMS ((const void *, const void *));
74 static boolean mips_elf_final_link
75 PARAMS ((bfd
*, struct bfd_link_info
*));
76 static void mips_elf_relocate_hi16
77 PARAMS ((bfd
*, Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_byte
*,
79 static boolean mips_elf_relocate_got_local
80 PARAMS ((bfd
*, bfd
*, asection
*, Elf_Internal_Rela
*,
81 Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
82 static void mips_elf_relocate_global_got
83 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
84 static bfd_reloc_status_type mips16_jump_reloc
85 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
86 static bfd_reloc_status_type mips16_gprel_reloc
87 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
88 /* start-sanitize-sky */
89 static bfd_reloc_status_type dvp_u15_s3_reloc
90 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
91 /* end-sanitize-sky */
92 static boolean mips_elf_adjust_dynindx
93 PARAMS ((struct elf_link_hash_entry
*, PTR
));
94 static boolean mips_elf_relocate_section
95 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
96 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
97 static boolean mips_elf_link_output_symbol_hook
98 PARAMS ((bfd
*, struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
100 static boolean mips_elf_create_dynamic_sections
101 PARAMS ((bfd
*, struct bfd_link_info
*));
102 static boolean mips_elf_create_compact_rel_section
103 PARAMS ((bfd
*, struct bfd_link_info
*));
104 static boolean mips_elf_create_got_section
105 PARAMS ((bfd
*, struct bfd_link_info
*));
106 static boolean mips_elf_check_relocs
107 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
108 const Elf_Internal_Rela
*));
109 static boolean mips_elf_adjust_dynamic_symbol
110 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
111 static boolean mips_elf_always_size_sections
112 PARAMS ((bfd
*, struct bfd_link_info
*));
113 static boolean mips_elf_size_dynamic_sections
114 PARAMS ((bfd
*, struct bfd_link_info
*));
115 static boolean mips_elf_finish_dynamic_symbol
116 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
117 Elf_Internal_Sym
*));
118 static boolean mips_elf_finish_dynamic_sections
119 PARAMS ((bfd
*, struct bfd_link_info
*));
120 static boolean mips_elf_add_symbol_hook
121 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
122 const char **, flagword
*, asection
**, bfd_vma
*));
123 static bfd_reloc_status_type mips_elf_final_gp
124 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
125 static bfd_byte
*elf32_mips_get_relocated_section_contents
126 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
127 bfd_byte
*, boolean
, asymbol
**));
129 /* This is true for Irix 5 executables, false for normal MIPS ELF ABI
130 executables. FIXME: At the moment, we default to always generating
131 Irix 5 executables. */
133 #define SGI_COMPAT(abfd) (1)
135 /* This structure is used to hold .got information when linking. It
136 is stored in the tdata field of the bfd_elf_section_data structure. */
140 /* The symbol index of the first global .got symbol. */
141 unsigned long global_gotsym
;
142 /* The number of local .got entries. */
143 unsigned int local_gotno
;
144 /* The number of local .got entries we have used. */
145 unsigned int assigned_gotno
;
148 /* The number of local .got entries we reserve. */
149 #define MIPS_RESERVED_GOTNO (2)
151 /* Instructions which appear in a stub. For some reason the stub is
152 slightly different on an SGI system. */
153 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
154 #define STUB_LW(abfd) \
156 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
157 : 0x8f998000) /* lw t9,0x8000(gp) */
158 #define STUB_MOVE 0x03e07825 /* move t7,ra */
159 #define STUB_JALR 0x0320f809 /* jal t9 */
160 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
161 #define MIPS_FUNCTION_STUB_SIZE (16)
163 /* Names of sections which appear in the .dynsym section in an Irix 5
166 static const char * const mips_elf_dynsym_sec_names
[] =
179 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
180 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
182 /* The number of entries in mips_elf_dynsym_sec_names which go in the
185 #define MIPS_TEXT_DYNSYM_SECNO (3)
187 /* The names of the runtime procedure table symbols used on Irix 5. */
189 static const char * const mips_elf_dynsym_rtproc_names
[] =
192 "_procedure_string_table",
193 "_procedure_table_size",
197 /* These structures are used to generate the .compact_rel section on
202 unsigned long id1
; /* Always one? */
203 unsigned long num
; /* Number of compact relocation entries. */
204 unsigned long id2
; /* Always two? */
205 unsigned long offset
; /* The file offset of the first relocation. */
206 unsigned long reserved0
; /* Zero? */
207 unsigned long reserved1
; /* Zero? */
216 bfd_byte reserved0
[4];
217 bfd_byte reserved1
[4];
218 } Elf32_External_compact_rel
;
222 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
223 unsigned int rtype
: 4; /* Relocation types. See below. */
224 unsigned int dist2to
: 8;
225 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
226 unsigned long konst
; /* KONST field. See below. */
227 unsigned long vaddr
; /* VADDR to be relocated. */
232 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
233 unsigned int rtype
: 4; /* Relocation types. See below. */
234 unsigned int dist2to
: 8;
235 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
236 unsigned long konst
; /* KONST field. See below. */
244 } Elf32_External_crinfo
;
250 } Elf32_External_crinfo2
;
252 /* These are the constants used to swap the bitfields in a crinfo. */
254 #define CRINFO_CTYPE (0x1)
255 #define CRINFO_CTYPE_SH (31)
256 #define CRINFO_RTYPE (0xf)
257 #define CRINFO_RTYPE_SH (27)
258 #define CRINFO_DIST2TO (0xff)
259 #define CRINFO_DIST2TO_SH (19)
260 #define CRINFO_RELVADDR (0x7ffff)
261 #define CRINFO_RELVADDR_SH (0)
263 /* A compact relocation info has long (3 words) or short (2 words)
264 formats. A short format doesn't have VADDR field and relvaddr
265 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
266 #define CRF_MIPS_LONG 1
267 #define CRF_MIPS_SHORT 0
269 /* There are 4 types of compact relocation at least. The value KONST
270 has different meaning for each type:
273 CT_MIPS_REL32 Address in data
274 CT_MIPS_WORD Address in word (XXX)
275 CT_MIPS_GPHI_LO GP - vaddr
276 CT_MIPS_JMPAD Address to jump
279 #define CRT_MIPS_REL32 0xa
280 #define CRT_MIPS_WORD 0xb
281 #define CRT_MIPS_GPHI_LO 0xc
282 #define CRT_MIPS_JMPAD 0xd
284 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
285 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
286 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
287 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
289 static void bfd_elf32_swap_compact_rel_out
290 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
291 static void bfd_elf32_swap_crinfo_out
292 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
294 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
296 static reloc_howto_type elf_mips_howto_table
[] =
299 HOWTO (R_MIPS_NONE
, /* type */
301 0, /* size (0 = byte, 1 = short, 2 = long) */
303 false, /* pc_relative */
305 complain_overflow_dont
, /* complain_on_overflow */
306 bfd_elf_generic_reloc
, /* special_function */
307 "R_MIPS_NONE", /* name */
308 false, /* partial_inplace */
311 false), /* pcrel_offset */
313 /* 16 bit relocation. */
314 HOWTO (R_MIPS_16
, /* type */
316 1, /* size (0 = byte, 1 = short, 2 = long) */
318 false, /* pc_relative */
320 complain_overflow_bitfield
, /* complain_on_overflow */
321 bfd_elf_generic_reloc
, /* special_function */
322 "R_MIPS_16", /* name */
323 true, /* partial_inplace */
324 0xffff, /* src_mask */
325 0xffff, /* dst_mask */
326 false), /* pcrel_offset */
328 /* 32 bit relocation. */
329 HOWTO (R_MIPS_32
, /* type */
331 2, /* size (0 = byte, 1 = short, 2 = long) */
333 false, /* pc_relative */
335 complain_overflow_bitfield
, /* complain_on_overflow */
336 bfd_elf_generic_reloc
, /* special_function */
337 "R_MIPS_32", /* name */
338 true, /* partial_inplace */
339 0xffffffff, /* src_mask */
340 0xffffffff, /* dst_mask */
341 false), /* pcrel_offset */
343 /* 32 bit symbol relative relocation. */
344 HOWTO (R_MIPS_REL32
, /* type */
346 2, /* size (0 = byte, 1 = short, 2 = long) */
348 false, /* pc_relative */
350 complain_overflow_bitfield
, /* complain_on_overflow */
351 bfd_elf_generic_reloc
, /* special_function */
352 "R_MIPS_REL32", /* name */
353 true, /* partial_inplace */
354 0xffffffff, /* src_mask */
355 0xffffffff, /* dst_mask */
356 false), /* pcrel_offset */
358 /* 26 bit branch address. */
359 HOWTO (R_MIPS_26
, /* type */
361 2, /* size (0 = byte, 1 = short, 2 = long) */
363 false, /* pc_relative */
365 complain_overflow_dont
, /* complain_on_overflow */
366 /* This needs complex overflow
367 detection, because the upper four
368 bits must match the PC. */
369 bfd_elf_generic_reloc
, /* special_function */
370 "R_MIPS_26", /* name */
371 true, /* partial_inplace */
372 0x3ffffff, /* src_mask */
373 0x3ffffff, /* dst_mask */
374 false), /* pcrel_offset */
376 /* High 16 bits of symbol value. */
377 HOWTO (R_MIPS_HI16
, /* type */
379 2, /* size (0 = byte, 1 = short, 2 = long) */
381 false, /* pc_relative */
383 complain_overflow_dont
, /* complain_on_overflow */
384 _bfd_mips_elf_hi16_reloc
, /* special_function */
385 "R_MIPS_HI16", /* name */
386 true, /* partial_inplace */
387 0xffff, /* src_mask */
388 0xffff, /* dst_mask */
389 false), /* pcrel_offset */
391 /* Low 16 bits of symbol value. */
392 HOWTO (R_MIPS_LO16
, /* type */
394 2, /* size (0 = byte, 1 = short, 2 = long) */
396 false, /* pc_relative */
398 complain_overflow_dont
, /* complain_on_overflow */
399 _bfd_mips_elf_lo16_reloc
, /* special_function */
400 "R_MIPS_LO16", /* name */
401 true, /* partial_inplace */
402 0xffff, /* src_mask */
403 0xffff, /* dst_mask */
404 false), /* pcrel_offset */
406 /* GP relative reference. */
407 HOWTO (R_MIPS_GPREL16
, /* type */
409 2, /* size (0 = byte, 1 = short, 2 = long) */
411 false, /* pc_relative */
413 complain_overflow_signed
, /* complain_on_overflow */
414 _bfd_mips_elf_gprel16_reloc
, /* special_function */
415 "R_MIPS_GPREL16", /* name */
416 true, /* partial_inplace */
417 0xffff, /* src_mask */
418 0xffff, /* dst_mask */
419 false), /* pcrel_offset */
421 /* Reference to literal section. */
422 HOWTO (R_MIPS_LITERAL
, /* type */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
426 false, /* pc_relative */
428 complain_overflow_signed
, /* complain_on_overflow */
429 _bfd_mips_elf_gprel16_reloc
, /* special_function */
430 "R_MIPS_LITERAL", /* name */
431 true, /* partial_inplace */
432 0xffff, /* src_mask */
433 0xffff, /* dst_mask */
434 false), /* pcrel_offset */
436 /* Reference to global offset table. */
437 HOWTO (R_MIPS_GOT16
, /* type */
439 2, /* size (0 = byte, 1 = short, 2 = long) */
441 false, /* pc_relative */
443 complain_overflow_signed
, /* complain_on_overflow */
444 _bfd_mips_elf_got16_reloc
, /* special_function */
445 "R_MIPS_GOT16", /* name */
446 false, /* partial_inplace */
448 0xffff, /* dst_mask */
449 false), /* pcrel_offset */
451 /* 16 bit PC relative reference. */
452 HOWTO (R_MIPS_PC16
, /* type */
454 2, /* size (0 = byte, 1 = short, 2 = long) */
456 true, /* pc_relative */
458 complain_overflow_signed
, /* complain_on_overflow */
459 bfd_elf_generic_reloc
, /* special_function */
460 "R_MIPS_PC16", /* name */
461 true, /* partial_inplace */
462 0xffff, /* src_mask */
463 0xffff, /* dst_mask */
464 false), /* pcrel_offset */
466 /* 16 bit call through global offset table. */
467 /* FIXME: This is not handled correctly. */
468 HOWTO (R_MIPS_CALL16
, /* type */
470 2, /* size (0 = byte, 1 = short, 2 = long) */
472 false, /* pc_relative */
474 complain_overflow_signed
, /* complain_on_overflow */
475 bfd_elf_generic_reloc
, /* special_function */
476 "R_MIPS_CALL16", /* name */
477 false, /* partial_inplace */
479 0xffff, /* dst_mask */
480 false), /* pcrel_offset */
482 /* 32 bit GP relative reference. */
483 HOWTO (R_MIPS_GPREL32
, /* type */
485 2, /* size (0 = byte, 1 = short, 2 = long) */
487 false, /* pc_relative */
489 complain_overflow_bitfield
, /* complain_on_overflow */
490 _bfd_mips_elf_gprel32_reloc
, /* special_function */
491 "R_MIPS_GPREL32", /* name */
492 true, /* partial_inplace */
493 0xffffffff, /* src_mask */
494 0xffffffff, /* dst_mask */
495 false), /* pcrel_offset */
497 /* The remaining relocs are defined on Irix 5, although they are
498 not defined by the ABI. */
503 /* A 5 bit shift field. */
504 HOWTO (R_MIPS_SHIFT5
, /* type */
506 2, /* size (0 = byte, 1 = short, 2 = long) */
508 false, /* pc_relative */
510 complain_overflow_bitfield
, /* complain_on_overflow */
511 bfd_elf_generic_reloc
, /* special_function */
512 "R_MIPS_SHIFT5", /* name */
513 true, /* partial_inplace */
514 0x000007c0, /* src_mask */
515 0x000007c0, /* dst_mask */
516 false), /* pcrel_offset */
518 /* A 6 bit shift field. */
519 /* FIXME: This is not handled correctly; a special function is
520 needed to put the most significant bit in the right place. */
521 HOWTO (R_MIPS_SHIFT6
, /* type */
523 2, /* size (0 = byte, 1 = short, 2 = long) */
525 false, /* pc_relative */
527 complain_overflow_bitfield
, /* complain_on_overflow */
528 bfd_elf_generic_reloc
, /* special_function */
529 "R_MIPS_SHIFT6", /* name */
530 true, /* partial_inplace */
531 0x000007c4, /* src_mask */
532 0x000007c4, /* dst_mask */
533 false), /* pcrel_offset */
535 /* A 64 bit relocation. This is used in 32 bit ELF when addresses
536 are 64 bits long; the upper 32 bits are simply a sign extension.
537 The fields of the howto should be the same as for R_MIPS_32,
538 other than the type, name, and special_function. */
539 HOWTO (R_MIPS_64
, /* type */
541 2, /* size (0 = byte, 1 = short, 2 = long) */
543 false, /* pc_relative */
545 complain_overflow_bitfield
, /* complain_on_overflow */
546 mips32_64bit_reloc
, /* special_function */
547 "R_MIPS_64", /* name */
548 true, /* partial_inplace */
549 0xffffffff, /* src_mask */
550 0xffffffff, /* dst_mask */
551 false), /* pcrel_offset */
553 /* Displacement in the global offset table. */
554 /* FIXME: Not handled correctly. */
555 HOWTO (R_MIPS_GOT_DISP
, /* type */
557 2, /* size (0 = byte, 1 = short, 2 = long) */
559 false, /* pc_relative */
561 complain_overflow_bitfield
, /* complain_on_overflow */
562 bfd_elf_generic_reloc
, /* special_function */
563 "R_MIPS_GOT_DISP", /* name */
564 true, /* partial_inplace */
565 0x0000ffff, /* src_mask */
566 0x0000ffff, /* dst_mask */
567 false), /* pcrel_offset */
569 /* Displacement to page pointer in the global offset table. */
570 /* FIXME: Not handled correctly. */
571 HOWTO (R_MIPS_GOT_PAGE
, /* type */
573 2, /* size (0 = byte, 1 = short, 2 = long) */
575 false, /* pc_relative */
577 complain_overflow_bitfield
, /* complain_on_overflow */
578 bfd_elf_generic_reloc
, /* special_function */
579 "R_MIPS_GOT_PAGE", /* name */
580 true, /* partial_inplace */
581 0x0000ffff, /* src_mask */
582 0x0000ffff, /* dst_mask */
583 false), /* pcrel_offset */
585 /* Offset from page pointer in the global offset table. */
586 /* FIXME: Not handled correctly. */
587 HOWTO (R_MIPS_GOT_OFST
, /* type */
589 2, /* size (0 = byte, 1 = short, 2 = long) */
591 false, /* pc_relative */
593 complain_overflow_bitfield
, /* complain_on_overflow */
594 bfd_elf_generic_reloc
, /* special_function */
595 "R_MIPS_GOT_OFST", /* name */
596 true, /* partial_inplace */
597 0x0000ffff, /* src_mask */
598 0x0000ffff, /* dst_mask */
599 false), /* pcrel_offset */
601 /* High 16 bits of displacement in global offset table. */
602 /* FIXME: Not handled correctly. */
603 HOWTO (R_MIPS_GOT_HI16
, /* type */
605 2, /* size (0 = byte, 1 = short, 2 = long) */
607 false, /* pc_relative */
609 complain_overflow_dont
, /* complain_on_overflow */
610 bfd_elf_generic_reloc
, /* special_function */
611 "R_MIPS_GOT_HI16", /* name */
612 true, /* partial_inplace */
613 0x0000ffff, /* src_mask */
614 0x0000ffff, /* dst_mask */
615 false), /* pcrel_offset */
617 /* Low 16 bits of displacement in global offset table. */
618 /* FIXME: Not handled correctly. */
619 HOWTO (R_MIPS_GOT_LO16
, /* type */
621 2, /* size (0 = byte, 1 = short, 2 = long) */
623 false, /* pc_relative */
625 complain_overflow_dont
, /* complain_on_overflow */
626 bfd_elf_generic_reloc
, /* special_function */
627 "R_MIPS_GOT_LO16", /* name */
628 true, /* partial_inplace */
629 0x0000ffff, /* src_mask */
630 0x0000ffff, /* dst_mask */
631 false), /* pcrel_offset */
633 /* 64 bit subtraction. Presumably not used in 32 bit ELF. */
636 /* Used to cause the linker to insert and delete instructions? */
641 /* Get the higher values of a 64 bit addend. Presumably not used in
646 /* High 16 bits of displacement in global offset table. */
647 /* FIXME: Not handled correctly. */
648 HOWTO (R_MIPS_CALL_HI16
, /* type */
650 2, /* size (0 = byte, 1 = short, 2 = long) */
652 false, /* pc_relative */
654 complain_overflow_dont
, /* complain_on_overflow */
655 bfd_elf_generic_reloc
, /* special_function */
656 "R_MIPS_CALL_HI16", /* name */
657 true, /* partial_inplace */
658 0x0000ffff, /* src_mask */
659 0x0000ffff, /* dst_mask */
660 false), /* pcrel_offset */
662 /* Low 16 bits of displacement in global offset table. */
663 /* FIXME: Not handled correctly. */
664 HOWTO (R_MIPS_CALL_LO16
, /* type */
666 2, /* size (0 = byte, 1 = short, 2 = long) */
668 false, /* pc_relative */
670 complain_overflow_dont
, /* complain_on_overflow */
671 bfd_elf_generic_reloc
, /* special_function */
672 "R_MIPS_CALL_LO16", /* name */
673 true, /* partial_inplace */
674 0x0000ffff, /* src_mask */
675 0x0000ffff, /* dst_mask */
676 false), /* pcrel_offset */
680 { R_MIPS_ADD_IMMEDIATE
},
685 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
686 is a hack to make the linker think that we need 64 bit values. */
687 static reloc_howto_type elf_mips_ctor64_howto
=
688 HOWTO (R_MIPS_64
, /* type */
690 4, /* size (0 = byte, 1 = short, 2 = long) */
692 false, /* pc_relative */
694 complain_overflow_signed
, /* complain_on_overflow */
695 mips32_64bit_reloc
, /* special_function */
696 "R_MIPS_64", /* name */
697 true, /* partial_inplace */
698 0xffffffff, /* src_mask */
699 0xffffffff, /* dst_mask */
700 false); /* pcrel_offset */
702 /* The reloc used for the mips16 jump instruction. */
703 static reloc_howto_type elf_mips16_jump_howto
=
704 HOWTO (R_MIPS16_26
, /* type */
706 2, /* size (0 = byte, 1 = short, 2 = long) */
708 false, /* pc_relative */
710 complain_overflow_dont
, /* complain_on_overflow */
711 /* This needs complex overflow
712 detection, because the upper four
713 bits must match the PC. */
714 mips16_jump_reloc
, /* special_function */
715 "R_MIPS16_26", /* name */
716 true, /* partial_inplace */
717 0x3ffffff, /* src_mask */
718 0x3ffffff, /* dst_mask */
719 false); /* pcrel_offset */
721 /* The reloc used for the mips16 gprel instruction. The src_mask and
722 dsk_mask for this howto do not reflect the actual instruction, in
723 which the value is not contiguous; the masks are for the
724 convenience of the relocate_section routine. */
725 static reloc_howto_type elf_mips16_gprel_howto
=
726 HOWTO (R_MIPS16_GPREL
, /* type */
728 2, /* size (0 = byte, 1 = short, 2 = long) */
730 false, /* pc_relative */
732 complain_overflow_signed
, /* complain_on_overflow */
733 mips16_gprel_reloc
, /* special_function */
734 "R_MIPS16_GPREL", /* name */
735 true, /* partial_inplace */
736 0xffff, /* src_mask */
737 0xffff, /* dst_mask */
738 false); /* pcrel_offset */
740 /* start-sanitize-r5900 */
741 static reloc_howto_type elf_mips15_s3_howto
=
742 HOWTO (R_MIPS15_S3
, /* type */
744 2, /* size (0 = byte, 1 = short, 2 = long) */
746 false, /* pc_relative */
748 complain_overflow_bitfield
, /* complain_on_overflow */
749 bfd_elf_generic_reloc
, /* special_function */
750 "R_MIPS15_S3", /* name */
751 true, /* partial_inplace */
752 0x001fffc0, /* src_mask */
753 0x001fffc0, /* dst_mask */
754 false); /* pcrel_offset */
756 /* end-sanitize-r5900 */
757 /* start-sanitize-sky */
759 Note that partial_inplace and pcrel_offset are backwards from the
760 mips port. This is intentional as it seems more reasonable. */
761 static reloc_howto_type elf_mips_dvp_11_pcrel_howto
=
762 HOWTO (R_MIPS_DVP_11_PCREL
, /* type */
764 2, /* size (0 = byte, 1 = short, 2 = long) */
766 true, /* pc_relative */
768 complain_overflow_signed
, /* complain_on_overflow */
769 bfd_elf_generic_reloc
, /* special_function */
770 "R_MIPS_DVP_11_PCREL", /* name */
771 false, /* partial_inplace */
772 0x7ff, /* src_mask */
773 0x7ff, /* dst_mask */
774 true); /* pcrel_offset */
775 static reloc_howto_type elf_mips_dvp_27_s4_howto
=
776 HOWTO (R_MIPS_DVP_27_S4
, /* type */
778 2, /* size (0 = byte, 1 = short, 2 = long) */
780 false, /* pc_relative */
782 complain_overflow_unsigned
, /* complain_on_overflow */
783 bfd_elf_generic_reloc
, /* special_function */
784 "R_MIPS_DVP_27_S4", /* name */
785 false, /* partial_inplace */
786 0x7ffffff0, /* src_mask */
787 0x7ffffff0, /* dst_mask */
788 false); /* pcrel_offset */
789 static reloc_howto_type elf_mips_dvp_11_s4_howto
=
790 HOWTO (R_MIPS_DVP_11_S4
, /* type */
792 2, /* size (0 = byte, 1 = short, 2 = long) */
794 false, /* pc_relative */
796 complain_overflow_signed
, /* complain_on_overflow */
797 bfd_elf_generic_reloc
, /* special_function */
798 "R_MIPS_DVP_11_S4", /* name */
799 false, /* partial_inplace */
800 0x03ff, /* src_mask */
801 0x03ff, /* dst_mask */
802 false); /* pcrel_offset */
803 static reloc_howto_type elf_mips_dvp_u15_s3_howto
=
804 HOWTO (R_MIPS_DVP_U15_S3
, /* type */
806 2, /* size (0 = byte, 1 = short, 2 = long) */
808 false, /* pc_relative */
810 complain_overflow_unsigned
, /* complain_on_overflow */
811 dvp_u15_s3_reloc
, /* special_function */
812 "R_MIPS_DVP_U15_S3", /* name */
813 false, /* partial_inplace */
814 0xf03ff, /* src_mask */
815 0xf03ff, /* dst_mask */
816 false); /* pcrel_offset */
817 /* end-sanitize-sky */
819 /* GNU extension to record C++ vtable hierarchy */
820 static reloc_howto_type elf_mips_gnu_vtinherit_howto
=
821 HOWTO (R_MIPS_GNU_VTINHERIT
, /* type */
823 2, /* size (0 = byte, 1 = short, 2 = long) */
825 false, /* pc_relative */
827 complain_overflow_dont
, /* complain_on_overflow */
828 NULL
, /* special_function */
829 "R_MIPS_GNU_VTINHERIT", /* name */
830 false, /* partial_inplace */
833 false); /* pcrel_offset */
835 /* GNU extension to record C++ vtable member usage */
836 static reloc_howto_type elf_mips_gnu_vtentry_howto
=
837 HOWTO (R_MIPS_GNU_VTENTRY
, /* type */
839 2, /* size (0 = byte, 1 = short, 2 = long) */
841 false, /* pc_relative */
843 complain_overflow_dont
, /* complain_on_overflow */
844 NULL
, /* special_function */
845 "R_MIPS_GNU_VTENTRY", /* name */
846 false, /* partial_inplace */
849 false); /* pcrel_offset */
851 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
852 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
853 the HI16. Here we just save the information we need; we do the
854 actual relocation when we see the LO16. MIPS ELF requires that the
855 LO16 immediately follow the HI16. As a GNU extension, we permit an
856 arbitrary number of HI16 relocs to be associated with a single LO16
857 reloc. This extension permits gcc to output the HI and LO relocs
862 struct mips_hi16
*next
;
867 /* FIXME: This should not be a static variable. */
869 static struct mips_hi16
*mips_hi16_list
;
871 bfd_reloc_status_type
872 _bfd_mips_elf_hi16_reloc (abfd
,
880 arelent
*reloc_entry
;
883 asection
*input_section
;
885 char **error_message
;
887 bfd_reloc_status_type ret
;
891 /* If we're relocating, and this an external symbol, we don't want
892 to change anything. */
893 if (output_bfd
!= (bfd
*) NULL
894 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
895 && reloc_entry
->addend
== 0)
897 reloc_entry
->address
+= input_section
->output_offset
;
903 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
905 boolean relocateable
;
908 if (ret
== bfd_reloc_undefined
)
911 if (output_bfd
!= NULL
)
915 relocateable
= false;
916 output_bfd
= symbol
->section
->output_section
->owner
;
919 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
921 if (ret
!= bfd_reloc_ok
)
924 relocation
= gp
- reloc_entry
->address
;
928 if (bfd_is_und_section (symbol
->section
)
929 && output_bfd
== (bfd
*) NULL
)
930 ret
= bfd_reloc_undefined
;
932 if (bfd_is_com_section (symbol
->section
))
935 relocation
= symbol
->value
;
938 relocation
+= symbol
->section
->output_section
->vma
;
939 relocation
+= symbol
->section
->output_offset
;
940 relocation
+= reloc_entry
->addend
;
942 if (reloc_entry
->address
> input_section
->_cooked_size
)
943 return bfd_reloc_outofrange
;
945 /* Save the information, and let LO16 do the actual relocation. */
946 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
948 return bfd_reloc_outofrange
;
949 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
950 n
->addend
= relocation
;
951 n
->next
= mips_hi16_list
;
954 if (output_bfd
!= (bfd
*) NULL
)
955 reloc_entry
->address
+= input_section
->output_offset
;
960 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
961 inplace relocation; this function exists in order to do the
962 R_MIPS_HI16 relocation described above. */
964 bfd_reloc_status_type
965 _bfd_mips_elf_lo16_reloc (abfd
,
973 arelent
*reloc_entry
;
976 asection
*input_section
;
978 char **error_message
;
980 arelent gp_disp_relent
;
982 if (mips_hi16_list
!= NULL
)
992 struct mips_hi16
*next
;
994 /* Do the HI16 relocation. Note that we actually don't need
995 to know anything about the LO16 itself, except where to
996 find the low 16 bits of the addend needed by the LO16. */
997 insn
= bfd_get_32 (abfd
, l
->addr
);
998 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
1000 val
= ((insn
& 0xffff) << 16) + vallo
;
1003 /* The low order 16 bits are always treated as a signed
1004 value. Therefore, a negative value in the low order bits
1005 requires an adjustment in the high order bits. We need
1006 to make this adjustment in two ways: once for the bits we
1007 took from the data, and once for the bits we are putting
1008 back in to the data. */
1009 if ((vallo
& 0x8000) != 0)
1011 if ((val
& 0x8000) != 0)
1014 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
1015 bfd_put_32 (abfd
, insn
, l
->addr
);
1017 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1019 gp_disp_relent
= *reloc_entry
;
1020 reloc_entry
= &gp_disp_relent
;
1021 reloc_entry
->addend
= l
->addend
;
1029 mips_hi16_list
= NULL
;
1031 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1033 bfd_reloc_status_type ret
;
1034 bfd_vma gp
, relocation
;
1036 /* FIXME: Does this case ever occur? */
1038 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
1039 if (ret
!= bfd_reloc_ok
)
1042 relocation
= gp
- reloc_entry
->address
;
1043 relocation
+= symbol
->section
->output_section
->vma
;
1044 relocation
+= symbol
->section
->output_offset
;
1045 relocation
+= reloc_entry
->addend
;
1047 if (reloc_entry
->address
> input_section
->_cooked_size
)
1048 return bfd_reloc_outofrange
;
1050 gp_disp_relent
= *reloc_entry
;
1051 reloc_entry
= &gp_disp_relent
;
1052 reloc_entry
->addend
= relocation
- 4;
1055 /* Now do the LO16 reloc in the usual way. */
1056 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1057 input_section
, output_bfd
, error_message
);
1060 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1061 table used for PIC code. If the symbol is an external symbol, the
1062 instruction is modified to contain the offset of the appropriate
1063 entry in the global offset table. If the symbol is a section
1064 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1065 addends are combined to form the real addend against the section
1066 symbol; the GOT16 is modified to contain the offset of an entry in
1067 the global offset table, and the LO16 is modified to offset it
1068 appropriately. Thus an offset larger than 16 bits requires a
1069 modified value in the global offset table.
1071 This implementation suffices for the assembler, but the linker does
1072 not yet know how to create global offset tables. */
1074 bfd_reloc_status_type
1075 _bfd_mips_elf_got16_reloc (abfd
,
1083 arelent
*reloc_entry
;
1086 asection
*input_section
;
1088 char **error_message
;
1090 /* If we're relocating, and this an external symbol, we don't want
1091 to change anything. */
1092 if (output_bfd
!= (bfd
*) NULL
1093 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1094 && reloc_entry
->addend
== 0)
1096 reloc_entry
->address
+= input_section
->output_offset
;
1097 return bfd_reloc_ok
;
1100 /* If we're relocating, and this is a local symbol, we can handle it
1102 if (output_bfd
!= (bfd
*) NULL
1103 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1104 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1105 input_section
, output_bfd
, error_message
);
1110 /* We have to figure out the gp value, so that we can adjust the
1111 symbol value correctly. We look up the symbol _gp in the output
1112 BFD. If we can't find it, we're stuck. We cache it in the ELF
1113 target data. We don't need to adjust the symbol value for an
1114 external symbol if we are producing relocateable output. */
1116 static bfd_reloc_status_type
1117 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1120 boolean relocateable
;
1121 char **error_message
;
1124 if (bfd_is_und_section (symbol
->section
)
1128 return bfd_reloc_undefined
;
1131 *pgp
= _bfd_get_gp_value (output_bfd
);
1134 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1138 /* Make up a value. */
1139 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1140 _bfd_set_gp_value (output_bfd
, *pgp
);
1148 count
= bfd_get_symcount (output_bfd
);
1149 sym
= bfd_get_outsymbols (output_bfd
);
1151 if (sym
== (asymbol
**) NULL
)
1155 for (i
= 0; i
< count
; i
++, sym
++)
1157 register CONST
char *name
;
1159 name
= bfd_asymbol_name (*sym
);
1160 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1162 *pgp
= bfd_asymbol_value (*sym
);
1163 _bfd_set_gp_value (output_bfd
, *pgp
);
1171 /* Only get the error once. */
1173 _bfd_set_gp_value (output_bfd
, *pgp
);
1175 (char *) _("GP relative relocation when _gp not defined");
1176 return bfd_reloc_dangerous
;
1181 return bfd_reloc_ok
;
1184 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1185 become the offset from the gp register. This function also handles
1186 R_MIPS_LITERAL relocations, although those can be handled more
1187 cleverly because the entries in the .lit8 and .lit4 sections can be
1190 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1191 arelent
*, asection
*,
1192 boolean
, PTR
, bfd_vma
));
1194 bfd_reloc_status_type
1195 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1196 output_bfd
, error_message
)
1198 arelent
*reloc_entry
;
1201 asection
*input_section
;
1203 char **error_message
;
1205 boolean relocateable
;
1206 bfd_reloc_status_type ret
;
1209 /* If we're relocating, and this is an external symbol with no
1210 addend, we don't want to change anything. We will only have an
1211 addend if this is a newly created reloc, not read from an ELF
1213 if (output_bfd
!= (bfd
*) NULL
1214 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1215 && reloc_entry
->addend
== 0)
1217 reloc_entry
->address
+= input_section
->output_offset
;
1218 return bfd_reloc_ok
;
1221 if (output_bfd
!= (bfd
*) NULL
)
1222 relocateable
= true;
1225 relocateable
= false;
1226 output_bfd
= symbol
->section
->output_section
->owner
;
1229 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1231 if (ret
!= bfd_reloc_ok
)
1234 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1235 relocateable
, data
, gp
);
1238 static bfd_reloc_status_type
1239 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1243 arelent
*reloc_entry
;
1244 asection
*input_section
;
1245 boolean relocateable
;
1253 if (bfd_is_com_section (symbol
->section
))
1256 relocation
= symbol
->value
;
1258 relocation
+= symbol
->section
->output_section
->vma
;
1259 relocation
+= symbol
->section
->output_offset
;
1261 if (reloc_entry
->address
> input_section
->_cooked_size
)
1262 return bfd_reloc_outofrange
;
1264 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1266 /* Set val to the offset into the section or symbol. */
1267 if (reloc_entry
->howto
->src_mask
== 0)
1269 /* This case occurs with the 64-bit MIPS ELF ABI. */
1270 val
= reloc_entry
->addend
;
1274 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1279 /* Adjust val for the final section location and GP value. If we
1280 are producing relocateable output, we don't want to do this for
1281 an external symbol. */
1283 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1284 val
+= relocation
- gp
;
1286 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1287 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1290 reloc_entry
->address
+= input_section
->output_offset
;
1292 /* Make sure it fit in 16 bits. */
1293 if (val
>= 0x8000 && val
< 0xffff8000)
1294 return bfd_reloc_overflow
;
1296 return bfd_reloc_ok
;
1299 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1300 from the gp register? XXX */
1302 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1303 arelent
*, asection
*,
1304 boolean
, PTR
, bfd_vma
));
1306 bfd_reloc_status_type
1307 _bfd_mips_elf_gprel32_reloc (abfd
,
1315 arelent
*reloc_entry
;
1318 asection
*input_section
;
1320 char **error_message
;
1322 boolean relocateable
;
1323 bfd_reloc_status_type ret
;
1326 /* If we're relocating, and this is an external symbol with no
1327 addend, we don't want to change anything. We will only have an
1328 addend if this is a newly created reloc, not read from an ELF
1330 if (output_bfd
!= (bfd
*) NULL
1331 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1332 && reloc_entry
->addend
== 0)
1334 *error_message
= (char *)
1335 _("32bits gp relative relocation occurs for an external symbol");
1336 return bfd_reloc_outofrange
;
1339 if (output_bfd
!= (bfd
*) NULL
)
1341 relocateable
= true;
1342 gp
= _bfd_get_gp_value (output_bfd
);
1346 relocateable
= false;
1347 output_bfd
= symbol
->section
->output_section
->owner
;
1349 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1350 error_message
, &gp
);
1351 if (ret
!= bfd_reloc_ok
)
1355 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1356 relocateable
, data
, gp
);
1359 static bfd_reloc_status_type
1360 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1364 arelent
*reloc_entry
;
1365 asection
*input_section
;
1366 boolean relocateable
;
1373 if (bfd_is_com_section (symbol
->section
))
1376 relocation
= symbol
->value
;
1378 relocation
+= symbol
->section
->output_section
->vma
;
1379 relocation
+= symbol
->section
->output_offset
;
1381 if (reloc_entry
->address
> input_section
->_cooked_size
)
1382 return bfd_reloc_outofrange
;
1384 if (reloc_entry
->howto
->src_mask
== 0)
1386 /* This case arises with the 64-bit MIPS ELF ABI. */
1390 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1392 /* Set val to the offset into the section or symbol. */
1393 val
+= reloc_entry
->addend
;
1395 /* Adjust val for the final section location and GP value. If we
1396 are producing relocateable output, we don't want to do this for
1397 an external symbol. */
1399 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1400 val
+= relocation
- gp
;
1402 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1405 reloc_entry
->address
+= input_section
->output_offset
;
1407 return bfd_reloc_ok
;
1410 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1411 generated when addreses are 64 bits. The upper 32 bits are a simle
1414 static bfd_reloc_status_type
1415 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1416 output_bfd
, error_message
)
1418 arelent
*reloc_entry
;
1421 asection
*input_section
;
1423 char **error_message
;
1425 bfd_reloc_status_type r
;
1430 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1431 input_section
, output_bfd
, error_message
);
1432 if (r
!= bfd_reloc_continue
)
1435 /* Do a normal 32 bit relocation on the lower 32 bits. */
1436 reloc32
= *reloc_entry
;
1437 if (bfd_big_endian (abfd
))
1438 reloc32
.address
+= 4;
1439 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1440 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1441 output_bfd
, error_message
);
1443 /* Sign extend into the upper 32 bits. */
1444 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1445 if ((val
& 0x80000000) != 0)
1449 addr
= reloc_entry
->address
;
1450 if (bfd_little_endian (abfd
))
1452 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1457 /* Handle a mips16 jump. */
1459 static bfd_reloc_status_type
1460 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1461 output_bfd
, error_message
)
1463 arelent
*reloc_entry
;
1466 asection
*input_section
;
1468 char **error_message
;
1470 if (output_bfd
!= (bfd
*) NULL
1471 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1472 && reloc_entry
->addend
== 0)
1474 reloc_entry
->address
+= input_section
->output_offset
;
1475 return bfd_reloc_ok
;
1480 static boolean warned
;
1483 (*_bfd_error_handler
)
1484 (_("Linking mips16 objects into %s format is not supported"),
1485 bfd_get_target (input_section
->output_section
->owner
));
1489 return bfd_reloc_undefined
;
1492 /* Handle a mips16 GP relative reloc. */
1494 static bfd_reloc_status_type
1495 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1496 output_bfd
, error_message
)
1498 arelent
*reloc_entry
;
1501 asection
*input_section
;
1503 char **error_message
;
1505 boolean relocateable
;
1506 bfd_reloc_status_type ret
;
1508 unsigned short extend
, insn
;
1509 unsigned long final
;
1511 /* If we're relocating, and this is an external symbol with no
1512 addend, we don't want to change anything. We will only have an
1513 addend if this is a newly created reloc, not read from an ELF
1515 if (output_bfd
!= NULL
1516 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1517 && reloc_entry
->addend
== 0)
1519 reloc_entry
->address
+= input_section
->output_offset
;
1520 return bfd_reloc_ok
;
1523 if (output_bfd
!= NULL
)
1524 relocateable
= true;
1527 relocateable
= false;
1528 output_bfd
= symbol
->section
->output_section
->owner
;
1531 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1533 if (ret
!= bfd_reloc_ok
)
1536 if (reloc_entry
->address
> input_section
->_cooked_size
)
1537 return bfd_reloc_outofrange
;
1539 /* Pick up the mips16 extend instruction and the real instruction. */
1540 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1541 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1543 /* Stuff the current addend back as a 32 bit value, do the usual
1544 relocation, and then clean up. */
1546 (((extend
& 0x1f) << 11)
1549 (bfd_byte
*) data
+ reloc_entry
->address
);
1551 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1552 relocateable
, data
, gp
);
1554 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1557 | ((final
>> 11) & 0x1f)
1559 (bfd_byte
*) data
+ reloc_entry
->address
);
1563 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1568 /* start-sanitize-sky */
1569 /* Handle a dvp R_MIPS_DVP_U15_S3 reloc.
1570 This is needed because the bits aren't contiguous. */
1572 static bfd_reloc_status_type
1573 dvp_u15_s3_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1574 output_bfd
, error_message
)
1576 arelent
*reloc_entry
;
1579 asection
*input_section
;
1581 char **error_message
;
1583 boolean relocateable
;
1584 bfd_reloc_status_type ret
;
1588 /* If we're relocating, and this is an external symbol with no
1589 addend, we don't want to change anything. We will only have an
1590 addend if this is a newly created reloc, not read from an ELF
1591 file. See bfd_elf_generic_reloc. */
1592 if (output_bfd
!= NULL
1593 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1594 /* partial_inplace is false, so this test always succeeds,
1595 but for clarity and consistency with bfd_elf_generic_reloc
1596 this is left as is. */
1597 && (! reloc_entry
->howto
->partial_inplace
1598 || reloc_entry
->addend
== 0))
1600 reloc_entry
->address
+= input_section
->output_offset
;
1601 return bfd_reloc_ok
;
1604 if (reloc_entry
->address
> input_section
->_cooked_size
)
1605 return bfd_reloc_outofrange
;
1607 relocation
= (symbol
->value
1608 + symbol
->section
->output_section
->vma
1609 + symbol
->section
->output_offset
);
1610 relocation
+= reloc_entry
->addend
;
1613 x
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1614 x
|= (((relocation
& 0x7800) << 10)
1615 | (relocation
& 0x7ff));
1616 bfd_put_32 (abfd
, x
, (bfd_byte
*) data
+ reloc_entry
->address
);
1618 if (relocation
& ~(bfd_vma
) 0x7fff)
1619 return bfd_reloc_overflow
;
1620 return bfd_reloc_ok
;
1623 /* end-sanitize-sky */
1624 /* Return the ISA for a MIPS e_flags value. */
1627 elf_mips_isa (flags
)
1630 switch (flags
& EF_MIPS_ARCH
)
1644 /* Return the MACH for a MIPS e_flags value. */
1647 elf_mips_mach (flags
)
1650 switch (flags
& EF_MIPS_MACH
)
1652 case E_MIPS_MACH_3900
:
1653 return bfd_mach_mips3900
;
1655 case E_MIPS_MACH_4010
:
1656 return bfd_mach_mips4010
;
1658 case E_MIPS_MACH_4100
:
1659 return bfd_mach_mips4100
;
1660 /* start-sanitize-vr4320 */
1662 case E_MIPS_MACH_4320
:
1663 return bfd_mach_mips4320
;
1664 /* end-sanitize-vr4320 */
1666 case E_MIPS_MACH_4650
:
1667 return bfd_mach_mips4650
;
1668 /* start-sanitize-tx49 */
1670 case E_MIPS_MACH_4900
:
1671 return bfd_mach_mips4900
;
1672 /* end-sanitize-tx49 */
1673 /* start-sanitize-cygnus */
1674 /* CYGNUS LOCAL vr5400/raeburn */
1676 case E_MIPS_MACH_5400
:
1677 return bfd_mach_mips5400
;
1678 /* end-sanitize-cygnus */
1679 /* start-sanitize-r5900 */
1681 case E_MIPS_MACH_5900
:
1682 return bfd_mach_mips5900
;
1683 /* end-sanitize-r5900 */
1686 switch (flags
& EF_MIPS_ARCH
)
1690 return bfd_mach_mips3000
;
1694 return bfd_mach_mips6000
;
1698 return bfd_mach_mips4000
;
1702 return bfd_mach_mips8000
;
1710 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1712 struct elf_reloc_map
{
1713 bfd_reloc_code_real_type bfd_reloc_val
;
1714 enum elf_mips_reloc_type elf_reloc_val
;
1717 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1719 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1720 { BFD_RELOC_16
, R_MIPS_16
},
1721 { BFD_RELOC_32
, R_MIPS_32
},
1722 { BFD_RELOC_64
, R_MIPS_64
},
1723 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1724 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1725 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1726 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1727 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1728 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1729 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1730 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1731 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1732 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1733 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1734 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1735 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
}
1738 /* Given a BFD reloc type, return a howto structure. */
1740 static reloc_howto_type
*
1741 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1743 bfd_reloc_code_real_type code
;
1747 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1749 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1750 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1756 bfd_set_error (bfd_error_bad_value
);
1759 case BFD_RELOC_CTOR
:
1760 /* We need to handle BFD_RELOC_CTOR specially.
1761 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1762 size of addresses on this architecture. */
1763 if (bfd_arch_bits_per_address (abfd
) == 32)
1764 return &elf_mips_howto_table
[(int) R_MIPS_32
];
1766 return &elf_mips_ctor64_howto
;
1768 case BFD_RELOC_MIPS16_JMP
:
1769 return &elf_mips16_jump_howto
;
1770 case BFD_RELOC_MIPS16_GPREL
:
1771 return &elf_mips16_gprel_howto
;
1772 /* start-sanitize-r5900 */
1773 case BFD_RELOC_MIPS15_S3
:
1774 return &elf_mips15_s3_howto
;
1775 /* end-sanitize-r5900 */
1776 /* start-sanitize-sky */
1777 case BFD_RELOC_MIPS_DVP_11_PCREL
:
1778 return &elf_mips_dvp_11_pcrel_howto
;
1779 case BFD_RELOC_MIPS_DVP_27_S4
:
1780 return &elf_mips_dvp_27_s4_howto
;
1781 case BFD_RELOC_MIPS_DVP_11_S4
:
1782 return &elf_mips_dvp_11_s4_howto
;
1783 case BFD_RELOC_MIPS_DVP_U15_S3
:
1784 return &elf_mips_dvp_u15_s3_howto
;
1785 /* end-sanitize-sky */
1786 case BFD_RELOC_VTABLE_INHERIT
:
1787 return &elf_mips_gnu_vtinherit_howto
;
1788 case BFD_RELOC_VTABLE_ENTRY
:
1789 return &elf_mips_gnu_vtentry_howto
;
1793 /* Given a MIPS reloc type, fill in an arelent structure. */
1796 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1799 Elf32_Internal_Rel
*dst
;
1801 unsigned int r_type
;
1803 r_type
= ELF32_R_TYPE (dst
->r_info
);
1807 cache_ptr
->howto
= &elf_mips16_jump_howto
;
1809 case R_MIPS16_GPREL
:
1810 cache_ptr
->howto
= &elf_mips16_gprel_howto
;
1812 /* start-sanitize-r5900 */
1814 cache_ptr
->howto
= &elf_mips15_s3_howto
;
1816 /* end-sanitize-r5900 */
1817 /* start-sanitize-sky */
1818 case R_MIPS_DVP_11_PCREL
:
1819 cache_ptr
->howto
= &elf_mips_dvp_11_pcrel_howto
;
1821 case R_MIPS_DVP_27_S4
:
1822 cache_ptr
->howto
= &elf_mips_dvp_27_s4_howto
;
1824 case R_MIPS_DVP_11_S4
:
1825 cache_ptr
->howto
= &elf_mips_dvp_11_s4_howto
;
1827 case R_MIPS_DVP_U15_S3
:
1828 cache_ptr
->howto
= &elf_mips_dvp_u15_s3_howto
;
1830 /* end-sanitize-sky */
1831 case R_MIPS_GNU_VTINHERIT
:
1832 cache_ptr
->howto
= &elf_mips_gnu_vtinherit_howto
;
1834 case R_MIPS_GNU_VTENTRY
:
1835 cache_ptr
->howto
= &elf_mips_gnu_vtentry_howto
;
1839 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1840 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1844 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1845 value for the object file. We get the addend now, rather than
1846 when we do the relocation, because the symbol manipulations done
1847 by the linker may cause us to lose track of the input BFD. */
1848 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1849 && (r_type
== (unsigned int) R_MIPS_GPREL16
1850 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1851 cache_ptr
->addend
= elf_gp (abfd
);
1854 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1855 routines swap this structure in and out. They are used outside of
1856 BFD, so they are globally visible. */
1859 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1861 const Elf32_External_RegInfo
*ex
;
1864 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1865 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1866 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1867 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1868 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1869 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1873 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1875 const Elf32_RegInfo
*in
;
1876 Elf32_External_RegInfo
*ex
;
1878 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1879 (bfd_byte
*) ex
->ri_gprmask
);
1880 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1881 (bfd_byte
*) ex
->ri_cprmask
[0]);
1882 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1883 (bfd_byte
*) ex
->ri_cprmask
[1]);
1884 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1885 (bfd_byte
*) ex
->ri_cprmask
[2]);
1886 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1887 (bfd_byte
*) ex
->ri_cprmask
[3]);
1888 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1889 (bfd_byte
*) ex
->ri_gp_value
);
1892 /* In the 64 bit ABI, the .MIPS.options section holds register
1893 information in an Elf64_Reginfo structure. These routines swap
1894 them in and out. They are globally visible because they are used
1895 outside of BFD. These routines are here so that gas can call them
1896 without worrying about whether the 64 bit ABI has been included. */
1899 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1901 const Elf64_External_RegInfo
*ex
;
1902 Elf64_Internal_RegInfo
*in
;
1904 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1905 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
1906 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1907 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1908 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1909 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1910 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1914 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1916 const Elf64_Internal_RegInfo
*in
;
1917 Elf64_External_RegInfo
*ex
;
1919 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1920 (bfd_byte
*) ex
->ri_gprmask
);
1921 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
1922 (bfd_byte
*) ex
->ri_pad
);
1923 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1924 (bfd_byte
*) ex
->ri_cprmask
[0]);
1925 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1926 (bfd_byte
*) ex
->ri_cprmask
[1]);
1927 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1928 (bfd_byte
*) ex
->ri_cprmask
[2]);
1929 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1930 (bfd_byte
*) ex
->ri_cprmask
[3]);
1931 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1932 (bfd_byte
*) ex
->ri_gp_value
);
1935 /* Swap an entry in a .gptab section. Note that these routines rely
1936 on the equivalence of the two elements of the union. */
1939 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1941 const Elf32_External_gptab
*ex
;
1944 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1945 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1949 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1951 const Elf32_gptab
*in
;
1952 Elf32_External_gptab
*ex
;
1954 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1955 ex
->gt_entry
.gt_g_value
);
1956 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1957 ex
->gt_entry
.gt_bytes
);
1961 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1963 const Elf32_compact_rel
*in
;
1964 Elf32_External_compact_rel
*ex
;
1966 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
1967 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
1968 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
1969 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
1970 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
1971 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
1975 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1977 const Elf32_crinfo
*in
;
1978 Elf32_External_crinfo
*ex
;
1982 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1983 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1984 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1985 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1986 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
1987 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
1988 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
1991 /* Swap in an options header. */
1994 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1996 const Elf_External_Options
*ex
;
1997 Elf_Internal_Options
*in
;
1999 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
2000 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
2001 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
2002 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
2005 /* Swap out an options header. */
2008 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
2010 const Elf_Internal_Options
*in
;
2011 Elf_External_Options
*ex
;
2013 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
2014 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
2015 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
2016 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
2019 /* Determine whether a symbol is global for the purposes of splitting
2020 the symbol table into global symbols and local symbols. At least
2021 on Irix 5, this split must be between section symbols and all other
2022 symbols. On most ELF targets the split is between static symbols
2023 and externally visible symbols. */
2027 mips_elf_sym_is_global (abfd
, sym
)
2031 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
2034 /* Set the right machine number for a MIPS ELF file. This is used for
2035 both the 32-bit and the 64-bit ABI. */
2038 _bfd_mips_elf_object_p (abfd
)
2041 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
,
2042 elf_mips_mach (elf_elfheader (abfd
)->e_flags
));
2046 /* Set the right machine number for a 32-bit MIPS ELF file. */
2049 mips_elf32_object_p (abfd
)
2052 /* Irix 5 is broken. Object file symbol tables are not always
2053 sorted correctly such that local symbols precede global symbols,
2054 and the sh_info field in the symbol table is not always right. */
2055 elf_bad_symtab (abfd
) = true;
2057 return _bfd_mips_elf_object_p (abfd
);
2060 /* The final processing done just before writing out a MIPS ELF object
2061 file. This gets the MIPS architecture right based on the machine
2062 number. This is used by both the 32-bit and the 64-bit ABI. */
2066 _bfd_mips_elf_final_write_processing (abfd
, linker
)
2072 Elf_Internal_Shdr
**hdrpp
;
2076 switch (bfd_get_mach (abfd
))
2079 case bfd_mach_mips3000
:
2080 val
= E_MIPS_ARCH_1
;
2083 case bfd_mach_mips3900
:
2084 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
2087 case bfd_mach_mips6000
:
2088 val
= E_MIPS_ARCH_2
;
2091 case bfd_mach_mips4000
:
2092 val
= E_MIPS_ARCH_3
;
2095 case bfd_mach_mips4010
:
2096 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
2099 case bfd_mach_mips4100
:
2100 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
2102 /* start-sanitize-vr4320 */
2104 case bfd_mach_mips4320
:
2105 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4320
;
2107 /* end-sanitize-vr4320 */
2109 case bfd_mach_mips4650
:
2110 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
2112 /* start-sanitize-tx49 */
2114 case bfd_mach_mips4900
:
2115 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4900
;
2117 /* end-sanitize-tx49 */
2118 /* start-sanitize-cygnus */
2119 /* CYGNUS LOCAL vr5400/raeburn */
2121 case bfd_mach_mips5400
:
2122 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_5400
;
2124 /* end-sanitize-cygnus */
2125 /* start-sanitize-r5900 */
2127 case bfd_mach_mips5900
:
2128 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_5900
;
2130 /* end-sanitize-r5900 */
2132 case bfd_mach_mips8000
:
2133 val
= E_MIPS_ARCH_4
;
2137 elf_elfheader (abfd
)->e_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2138 elf_elfheader (abfd
)->e_flags
|= val
;
2140 /* Set the sh_info field for .gptab sections and other appropriate
2141 info for each special section. */
2142 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
2143 i
< elf_elfheader (abfd
)->e_shnum
;
2146 switch ((*hdrpp
)->sh_type
)
2148 case SHT_MIPS_LIBLIST
:
2149 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
2151 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2154 case SHT_MIPS_GPTAB
:
2155 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2156 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2157 BFD_ASSERT (name
!= NULL
2158 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
2159 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
2160 BFD_ASSERT (sec
!= NULL
);
2161 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2164 case SHT_MIPS_CONTENT
:
2165 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2166 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2167 BFD_ASSERT (name
!= NULL
2168 && strncmp (name
, ".MIPS.content",
2169 sizeof ".MIPS.content" - 1) == 0);
2170 sec
= bfd_get_section_by_name (abfd
,
2171 name
+ sizeof ".MIPS.content" - 1);
2172 BFD_ASSERT (sec
!= NULL
);
2173 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2176 case SHT_MIPS_SYMBOL_LIB
:
2177 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
2179 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2180 sec
= bfd_get_section_by_name (abfd
, ".liblist");
2182 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2185 case SHT_MIPS_EVENTS
:
2186 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2187 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2188 BFD_ASSERT (name
!= NULL
);
2189 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
2190 sec
= bfd_get_section_by_name (abfd
,
2191 name
+ sizeof ".MIPS.events" - 1);
2194 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
2195 sizeof ".MIPS.post_rel" - 1) == 0);
2196 sec
= bfd_get_section_by_name (abfd
,
2198 + sizeof ".MIPS.post_rel" - 1));
2200 BFD_ASSERT (sec
!= NULL
);
2201 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2204 /* start-sanitize-sky */
2205 case SHT_DVP_OVERLAY_TABLE
:
2206 /* ??? This may not be technically necessary, just going with
2208 sec
= bfd_get_section_by_name (abfd
, SHNAME_DVP_OVERLAY_STRTAB
);
2210 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2212 /* end-sanitize-sky */
2217 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
2220 _bfd_mips_elf_set_private_flags (abfd
, flags
)
2224 BFD_ASSERT (!elf_flags_init (abfd
)
2225 || elf_elfheader (abfd
)->e_flags
== flags
);
2227 elf_elfheader (abfd
)->e_flags
= flags
;
2228 elf_flags_init (abfd
) = true;
2232 /* Copy backend specific data from one object module to another */
2235 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
2239 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2240 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2243 BFD_ASSERT (!elf_flags_init (obfd
)
2244 || (elf_elfheader (obfd
)->e_flags
2245 == elf_elfheader (ibfd
)->e_flags
));
2247 elf_gp (obfd
) = elf_gp (ibfd
);
2248 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
2249 elf_flags_init (obfd
) = true;
2253 /* Merge backend specific data from an object file to the output
2254 object file when linking. */
2257 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
2265 /* Check if we have the same endianess */
2266 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2267 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2271 if (bfd_big_endian (ibfd
))
2272 msg
= _("%s: compiled for a big endian system and target is little endian");
2274 msg
= _("%s: compiled for a little endian system and target is big endian");
2276 (*_bfd_error_handler
) (msg
, bfd_get_filename (ibfd
));
2278 bfd_set_error (bfd_error_wrong_format
);
2282 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2283 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2286 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2287 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
2288 old_flags
= elf_elfheader (obfd
)->e_flags
;
2290 if (! elf_flags_init (obfd
))
2292 elf_flags_init (obfd
) = true;
2293 elf_elfheader (obfd
)->e_flags
= new_flags
;
2295 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2296 && bfd_get_arch_info (obfd
)->the_default
)
2298 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
2299 bfd_get_mach (ibfd
)))
2306 /* Check flag compatibility. */
2308 new_flags
&= ~EF_MIPS_NOREORDER
;
2309 old_flags
&= ~EF_MIPS_NOREORDER
;
2311 if (new_flags
== old_flags
)
2316 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
2318 new_flags
&= ~EF_MIPS_PIC
;
2319 old_flags
&= ~EF_MIPS_PIC
;
2320 (*_bfd_error_handler
)
2321 (_("%s: linking PIC files with non-PIC files"),
2322 bfd_get_filename (ibfd
));
2326 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
2328 new_flags
&= ~EF_MIPS_CPIC
;
2329 old_flags
&= ~EF_MIPS_CPIC
;
2330 (*_bfd_error_handler
)
2331 (_("%s: linking abicalls files with non-abicalls files"),
2332 bfd_get_filename (ibfd
));
2336 /* Compare the ISA's. */
2337 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
2338 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
2340 /* If either has no machine specified, just compare the general isa's. */
2341 if ( !(new_flags
& EF_MIPS_MACH
) || !(old_flags
& EF_MIPS_MACH
))
2343 int new_isa
, old_isa
;
2345 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
2346 and -mips4 code. They will normally use the same data sizes and
2347 calling conventions. */
2349 new_isa
= elf_mips_isa (new_flags
);
2350 old_isa
= elf_mips_isa (old_flags
);
2351 if ((new_isa
== 1 || new_isa
== 2)
2352 ? (old_isa
!= 1 && old_isa
!= 2)
2353 : (old_isa
== 1 || old_isa
== 2))
2355 (*_bfd_error_handler
)
2356 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
2357 bfd_get_filename (ibfd
), new_isa
, old_isa
);
2364 (*_bfd_error_handler
)
2365 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
2366 bfd_get_filename (ibfd
),
2367 elf_mips_mach (new_flags
),
2368 elf_mips_mach (old_flags
));
2372 new_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2373 old_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2376 /* Warn about any other mismatches */
2377 if (new_flags
!= old_flags
)
2379 (*_bfd_error_handler
)
2380 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2381 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
2382 (unsigned long) old_flags
);
2388 bfd_set_error (bfd_error_bad_value
);
2395 /* Handle a MIPS specific section when reading an object file. This
2396 is called when elfcode.h finds a section with an unknown type.
2397 This routine supports both the 32-bit and 64-bit ELF ABI.
2399 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2403 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
2405 Elf_Internal_Shdr
*hdr
;
2408 /* There ought to be a place to keep ELF backend specific flags, but
2409 at the moment there isn't one. We just keep track of the
2410 sections by their name, instead. Fortunately, the ABI gives
2411 suggested names for all the MIPS specific sections, so we will
2412 probably get away with this. */
2413 switch (hdr
->sh_type
)
2415 case SHT_MIPS_LIBLIST
:
2416 if (strcmp (name
, ".liblist") != 0)
2420 if (strcmp (name
, ".msym") != 0)
2423 case SHT_MIPS_CONFLICT
:
2424 if (strcmp (name
, ".conflict") != 0)
2427 case SHT_MIPS_GPTAB
:
2428 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
2431 case SHT_MIPS_UCODE
:
2432 if (strcmp (name
, ".ucode") != 0)
2435 case SHT_MIPS_DEBUG
:
2436 if (strcmp (name
, ".mdebug") != 0)
2439 case SHT_MIPS_REGINFO
:
2440 if (strcmp (name
, ".reginfo") != 0
2441 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
2444 case SHT_MIPS_IFACE
:
2445 if (strcmp (name
, ".MIPS.interfaces") != 0)
2448 case SHT_MIPS_CONTENT
:
2449 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2452 case SHT_MIPS_OPTIONS
:
2453 if (strcmp (name
, ".options") != 0
2454 && strcmp (name
, ".MIPS.options") != 0)
2457 case SHT_MIPS_DWARF
:
2458 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2461 case SHT_MIPS_SYMBOL_LIB
:
2462 if (strcmp (name
, ".MIPS.symlib") != 0)
2465 case SHT_MIPS_EVENTS
:
2466 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2467 && strncmp (name
, ".MIPS.post_rel",
2468 sizeof ".MIPS.post_rel" - 1) != 0)
2471 /* start-sanitize-sky */
2472 case SHT_DVP_OVERLAY_TABLE
:
2473 if (strcmp (name
, SHNAME_DVP_OVERLAY_TABLE
) !=0)
2476 case SHT_DVP_OVERLAY
:
2477 if (strncmp (name
, SHNAME_DVP_OVERLAY_PREFIX
,
2478 sizeof (SHNAME_DVP_OVERLAY_PREFIX
) - 1) !=0)
2481 /* end-sanitize-sky */
2486 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2489 if (hdr
->sh_type
== SHT_MIPS_DEBUG
)
2491 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
2492 (bfd_get_section_flags (abfd
,
2501 /* Handle a 32-bit MIPS ELF specific section. */
2504 mips_elf32_section_from_shdr (abfd
, hdr
, name
)
2506 Elf_Internal_Shdr
*hdr
;
2509 if (! _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
))
2512 /* FIXME: We should record sh_info for a .gptab section. */
2514 /* For a .reginfo section, set the gp value in the tdata information
2515 from the contents of this section. We need the gp value while
2516 processing relocs, so we just get it now. The .reginfo section
2517 is not used in the 64-bit MIPS ELF ABI. */
2518 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2520 Elf32_External_RegInfo ext
;
2523 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
2524 (file_ptr
) 0, sizeof ext
))
2526 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
2527 elf_gp (abfd
) = s
.ri_gp_value
;
2530 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2531 set the gp value based on what we find. We may see both
2532 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2533 they should agree. */
2534 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
2536 bfd_byte
*contents
, *l
, *lend
;
2538 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
2539 if (contents
== NULL
)
2541 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
2542 (file_ptr
) 0, hdr
->sh_size
))
2548 lend
= contents
+ hdr
->sh_size
;
2549 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2551 Elf_Internal_Options intopt
;
2553 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2555 if (intopt
.kind
== ODK_REGINFO
)
2557 Elf32_RegInfo intreg
;
2559 bfd_mips_elf32_swap_reginfo_in
2561 ((Elf32_External_RegInfo
*)
2562 (l
+ sizeof (Elf_External_Options
))),
2564 elf_gp (abfd
) = intreg
.ri_gp_value
;
2574 /* Set the correct type for a MIPS ELF section. We do this by the
2575 section name, which is a hack, but ought to work. This routine is
2576 used by both the 32-bit and the 64-bit ABI. */
2579 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
2581 Elf32_Internal_Shdr
*hdr
;
2584 register const char *name
;
2586 name
= bfd_get_section_name (abfd
, sec
);
2588 if (strcmp (name
, ".liblist") == 0)
2590 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
2591 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
2592 /* The sh_link field is set in final_write_processing. */
2594 else if (strcmp (name
, ".msym") == 0)
2596 hdr
->sh_type
= SHT_MIPS_MSYM
;
2597 hdr
->sh_entsize
= 8;
2598 /* FIXME: Set the sh_info field. */
2600 else if (strcmp (name
, ".conflict") == 0)
2601 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
2602 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2604 hdr
->sh_type
= SHT_MIPS_GPTAB
;
2605 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
2606 /* The sh_info field is set in final_write_processing. */
2608 else if (strcmp (name
, ".ucode") == 0)
2609 hdr
->sh_type
= SHT_MIPS_UCODE
;
2610 else if (strcmp (name
, ".mdebug") == 0)
2612 hdr
->sh_type
= SHT_MIPS_DEBUG
;
2613 /* In a shared object on Irix 5.3, the .mdebug section has an
2614 entsize of 0. FIXME: Does this matter? */
2615 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2616 hdr
->sh_entsize
= 0;
2618 hdr
->sh_entsize
= 1;
2620 else if (strcmp (name
, ".reginfo") == 0)
2622 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2623 /* In a shared object on Irix 5.3, the .reginfo section has an
2624 entsize of 0x18. FIXME: Does this matter? */
2625 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2626 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2628 hdr
->sh_entsize
= 1;
2630 /* Force the section size to the correct value, even if the
2631 linker thinks it is larger. The link routine below will only
2632 write out this much data for .reginfo. */
2633 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf32_External_RegInfo
);
2635 else if (SGI_COMPAT (abfd
)
2636 && (strcmp (name
, ".hash") == 0
2637 || strcmp (name
, ".dynamic") == 0
2638 || strcmp (name
, ".dynstr") == 0))
2640 hdr
->sh_entsize
= 0;
2641 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2643 else if (strcmp (name
, ".got") == 0
2644 || strcmp (name
, ".sdata") == 0
2645 || strcmp (name
, ".sbss") == 0
2646 || strcmp (name
, ".lit4") == 0
2647 || strcmp (name
, ".lit8") == 0)
2648 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2649 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2651 hdr
->sh_type
= SHT_MIPS_IFACE
;
2652 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2654 else if (strcmp (name
, ".MIPS.content") == 0)
2656 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2657 /* The sh_info field is set in final_write_processing. */
2659 else if (strcmp (name
, ".options") == 0
2660 || strcmp (name
, ".MIPS.options") == 0)
2662 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2663 hdr
->sh_entsize
= 1;
2664 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2666 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2667 hdr
->sh_type
= SHT_MIPS_DWARF
;
2668 else if (strcmp (name
, ".MIPS.symlib") == 0)
2670 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2671 /* The sh_link and sh_info fields are set in
2672 final_write_processing. */
2674 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2675 || strncmp (name
, ".MIPS.post_rel",
2676 sizeof ".MIPS.post_rel" - 1) == 0)
2678 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2679 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2680 /* The sh_link field is set in final_write_processing. */
2682 /* start-sanitize-sky */
2683 else if (strcmp (name
, SHNAME_DVP_OVERLAY_TABLE
) == 0)
2685 hdr
->sh_type
= SHT_DVP_OVERLAY_TABLE
;
2686 hdr
->sh_entsize
= sizeof (Elf32_Dvp_External_Overlay
);
2687 /* The sh_link field is set in final_write_processing. */
2689 else if (strcmp (name
, SHNAME_DVP_OVERLAY_STRTAB
) == 0)
2690 hdr
->sh_type
= SHT_STRTAB
;
2691 else if (strncmp (name
, SHNAME_DVP_OVERLAY_PREFIX
,
2692 sizeof (SHNAME_DVP_OVERLAY_PREFIX
) - 1) == 0)
2693 hdr
->sh_type
= SHT_DVP_OVERLAY
;
2694 /* end-sanitize-sky */
2699 /* Given a BFD section, try to locate the corresponding ELF section
2700 index. This is used by both the 32-bit and the 64-bit ABI.
2701 Actually, it's not clear to me that the 64-bit ABI supports these,
2702 but for non-PIC objects we will certainly want support for at least
2703 the .scommon section. */
2706 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2708 Elf32_Internal_Shdr
*hdr
;
2712 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2714 *retval
= SHN_MIPS_SCOMMON
;
2717 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2719 *retval
= SHN_MIPS_ACOMMON
;
2725 /* When are writing out the .options or .MIPS.options section,
2726 remember the bytes we are writing out, so that we can install the
2727 GP value in the section_processing routine. */
2730 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2735 bfd_size_type count
;
2737 if (strcmp (section
->name
, ".options") == 0
2738 || strcmp (section
->name
, ".MIPS.options") == 0)
2742 if (elf_section_data (section
) == NULL
)
2744 section
->used_by_bfd
=
2745 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
2746 if (elf_section_data (section
) == NULL
)
2749 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
2754 if (section
->_cooked_size
!= 0)
2755 size
= section
->_cooked_size
;
2757 size
= section
->_raw_size
;
2758 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
2761 elf_section_data (section
)->tdata
= (PTR
) c
;
2764 memcpy (c
+ offset
, location
, count
);
2767 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
2771 /* Work over a section just before writing it out. This routine is
2772 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2773 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2777 _bfd_mips_elf_section_processing (abfd
, hdr
)
2779 Elf_Internal_Shdr
*hdr
;
2781 if (hdr
->bfd_section
!= NULL
)
2783 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
2785 if (strcmp (name
, ".sdata") == 0)
2787 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2788 hdr
->sh_type
= SHT_PROGBITS
;
2790 else if (strcmp (name
, ".sbss") == 0)
2792 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2793 hdr
->sh_type
= SHT_NOBITS
;
2795 else if (strcmp (name
, ".lit8") == 0
2796 || strcmp (name
, ".lit4") == 0)
2798 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2799 hdr
->sh_type
= SHT_PROGBITS
;
2801 else if (strcmp (name
, ".compact_rel") == 0)
2804 hdr
->sh_type
= SHT_PROGBITS
;
2806 else if (strcmp (name
, ".rtproc") == 0)
2808 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
2810 unsigned int adjust
;
2812 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
2814 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
2822 /* Work over a section just before writing it out. We update the GP
2823 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2824 on the value we are using. */
2827 mips_elf32_section_processing (abfd
, hdr
)
2829 Elf32_Internal_Shdr
*hdr
;
2831 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2835 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2836 BFD_ASSERT (hdr
->contents
== NULL
);
2839 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2842 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2843 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2847 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2848 && hdr
->bfd_section
!= NULL
2849 && elf_section_data (hdr
->bfd_section
) != NULL
2850 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2852 bfd_byte
*contents
, *l
, *lend
;
2854 /* We stored the section contents in the elf_section_data tdata
2855 field in the set_section_contents routine. We save the
2856 section contents so that we don't have to read them again.
2857 At this point we know that elf_gp is set, so we can look
2858 through the section contents to see if there is an
2859 ODK_REGINFO structure. */
2861 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2863 lend
= contents
+ hdr
->sh_size
;
2864 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2866 Elf_Internal_Options intopt
;
2868 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2870 if (intopt
.kind
== ODK_REGINFO
)
2877 + sizeof (Elf_External_Options
)
2878 + (sizeof (Elf32_External_RegInfo
) - 4)),
2881 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
2882 if (bfd_write (buf
, 1, 4, abfd
) != 4)
2889 return _bfd_mips_elf_section_processing (abfd
, hdr
);
2892 /* MIPS ELF uses two common sections. One is the usual one, and the
2893 other is for small objects. All the small objects are kept
2894 together, and then referenced via the gp pointer, which yields
2895 faster assembler code. This is what we use for the small common
2896 section. This approach is copied from ecoff.c. */
2897 static asection mips_elf_scom_section
;
2898 static asymbol mips_elf_scom_symbol
;
2899 static asymbol
*mips_elf_scom_symbol_ptr
;
2901 /* MIPS ELF also uses an acommon section, which represents an
2902 allocated common symbol which may be overridden by a
2903 definition in a shared library. */
2904 static asection mips_elf_acom_section
;
2905 static asymbol mips_elf_acom_symbol
;
2906 static asymbol
*mips_elf_acom_symbol_ptr
;
2908 /* The Irix 5 support uses two virtual sections, which represent
2909 text/data symbols defined in dynamic objects. */
2910 static asection mips_elf_text_section
;
2911 static asection
*mips_elf_text_section_ptr
;
2912 static asymbol mips_elf_text_symbol
;
2913 static asymbol
*mips_elf_text_symbol_ptr
;
2915 static asection mips_elf_data_section
;
2916 static asection
*mips_elf_data_section_ptr
;
2917 static asymbol mips_elf_data_symbol
;
2918 static asymbol
*mips_elf_data_symbol_ptr
;
2920 /* Handle the special MIPS section numbers that a symbol may use.
2921 This is used for both the 32-bit and the 64-bit ABI. */
2924 _bfd_mips_elf_symbol_processing (abfd
, asym
)
2928 elf_symbol_type
*elfsym
;
2930 elfsym
= (elf_symbol_type
*) asym
;
2931 switch (elfsym
->internal_elf_sym
.st_shndx
)
2933 case SHN_MIPS_ACOMMON
:
2934 /* This section is used in a dynamically linked executable file.
2935 It is an allocated common section. The dynamic linker can
2936 either resolve these symbols to something in a shared
2937 library, or it can just leave them here. For our purposes,
2938 we can consider these symbols to be in a new section. */
2939 if (mips_elf_acom_section
.name
== NULL
)
2941 /* Initialize the acommon section. */
2942 mips_elf_acom_section
.name
= ".acommon";
2943 mips_elf_acom_section
.flags
= SEC_ALLOC
;
2944 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
2945 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
2946 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
2947 mips_elf_acom_symbol
.name
= ".acommon";
2948 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
2949 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
2950 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
2952 asym
->section
= &mips_elf_acom_section
;
2956 /* Common symbols less than the GP size are automatically
2957 treated as SHN_MIPS_SCOMMON symbols. */
2958 if (asym
->value
> elf_gp_size (abfd
))
2961 case SHN_MIPS_SCOMMON
:
2962 if (mips_elf_scom_section
.name
== NULL
)
2964 /* Initialize the small common section. */
2965 mips_elf_scom_section
.name
= ".scommon";
2966 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
2967 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
2968 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
2969 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
2970 mips_elf_scom_symbol
.name
= ".scommon";
2971 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2972 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
2973 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
2975 asym
->section
= &mips_elf_scom_section
;
2976 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2979 case SHN_MIPS_SUNDEFINED
:
2980 asym
->section
= bfd_und_section_ptr
;
2983 #if 0 /* for SGI_COMPAT */
2985 asym
->section
= mips_elf_text_section_ptr
;
2989 asym
->section
= mips_elf_data_section_ptr
;
2995 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
2999 mips_elf_additional_program_headers (abfd
)
3007 if (! SGI_COMPAT (abfd
))
3010 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3011 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3013 /* We need a PT_MIPS_REGINFO segment. */
3017 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3018 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3020 /* We need a PT_MIPS_RTPROC segment. */
3027 /* Modify the segment map for an Irix 5 executable. */
3030 mips_elf_modify_segment_map (abfd
)
3034 struct elf_segment_map
*m
, **pm
;
3036 if (! SGI_COMPAT (abfd
))
3039 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
3041 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3042 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3044 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3045 if (m
->p_type
== PT_MIPS_REGINFO
)
3049 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3053 m
->p_type
= PT_MIPS_REGINFO
;
3057 /* We want to put it after the PHDR and INTERP segments. */
3058 pm
= &elf_tdata (abfd
)->segment_map
;
3060 && ((*pm
)->p_type
== PT_PHDR
3061 || (*pm
)->p_type
== PT_INTERP
))
3069 /* If there are .dynamic and .mdebug sections, we make a room for
3070 the RTPROC header. FIXME: Rewrite without section names. */
3071 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
3072 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3073 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3075 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3076 if (m
->p_type
== PT_MIPS_RTPROC
)
3080 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3084 m
->p_type
= PT_MIPS_RTPROC
;
3086 s
= bfd_get_section_by_name (abfd
, ".rtproc");
3091 m
->p_flags_valid
= 1;
3099 /* We want to put it after the DYNAMIC segment. */
3100 pm
= &elf_tdata (abfd
)->segment_map
;
3101 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
3111 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
3112 .dynsym, and .hash sections, and everything in between. */
3113 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
3114 if ((*pm
)->p_type
== PT_DYNAMIC
)
3119 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
3121 static const char *sec_names
[] =
3122 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
3125 struct elf_segment_map
*n
;
3129 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
3131 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
3132 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3138 sz
= s
->_cooked_size
;
3141 if (high
< s
->vma
+ sz
)
3147 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3148 if ((s
->flags
& SEC_LOAD
) != 0
3151 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3155 n
= ((struct elf_segment_map
*)
3156 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
3163 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3165 if ((s
->flags
& SEC_LOAD
) != 0
3168 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3182 /* The structure of the runtime procedure descriptor created by the
3183 loader for use by the static exception system. */
3185 typedef struct runtime_pdr
{
3186 bfd_vma adr
; /* memory address of start of procedure */
3187 long regmask
; /* save register mask */
3188 long regoffset
; /* save register offset */
3189 long fregmask
; /* save floating point register mask */
3190 long fregoffset
; /* save floating point register offset */
3191 long frameoffset
; /* frame size */
3192 short framereg
; /* frame pointer register */
3193 short pcreg
; /* offset or reg of return pc */
3194 long irpss
; /* index into the runtime string table */
3196 struct exception_info
*exception_info
;/* pointer to exception array */
3198 #define cbRPDR sizeof(RPDR)
3199 #define rpdNil ((pRPDR) 0)
3201 /* Swap RPDR (runtime procedure table entry) for output. */
3203 static void ecoff_swap_rpdr_out
3204 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
3207 ecoff_swap_rpdr_out (abfd
, in
, ex
)
3210 struct rpdr_ext
*ex
;
3212 /* ecoff_put_off was defined in ecoffswap.h. */
3213 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
3214 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
3215 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
3216 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
3217 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
3218 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
3220 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
3221 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
3223 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
3225 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
3229 /* Read ECOFF debugging information from a .mdebug section into a
3230 ecoff_debug_info structure. */
3233 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
3236 struct ecoff_debug_info
*debug
;
3239 const struct ecoff_debug_swap
*swap
;
3240 char *ext_hdr
= NULL
;
3242 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3244 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
3245 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
3248 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
3249 swap
->external_hdr_size
)
3253 symhdr
= &debug
->symbolic_header
;
3254 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
3256 /* The symbolic header contains absolute file offsets and sizes to
3258 #define READ(ptr, offset, count, size, type) \
3259 if (symhdr->count == 0) \
3260 debug->ptr = NULL; \
3263 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
3264 if (debug->ptr == NULL) \
3265 goto error_return; \
3266 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3267 || (bfd_read (debug->ptr, size, symhdr->count, \
3268 abfd) != size * symhdr->count)) \
3269 goto error_return; \
3272 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
3273 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
3274 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
3275 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
3276 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
3277 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
3279 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
3280 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
3281 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
3282 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
3283 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
3287 debug
->adjust
= NULL
;
3292 if (ext_hdr
!= NULL
)
3294 if (debug
->line
!= NULL
)
3296 if (debug
->external_dnr
!= NULL
)
3297 free (debug
->external_dnr
);
3298 if (debug
->external_pdr
!= NULL
)
3299 free (debug
->external_pdr
);
3300 if (debug
->external_sym
!= NULL
)
3301 free (debug
->external_sym
);
3302 if (debug
->external_opt
!= NULL
)
3303 free (debug
->external_opt
);
3304 if (debug
->external_aux
!= NULL
)
3305 free (debug
->external_aux
);
3306 if (debug
->ss
!= NULL
)
3308 if (debug
->ssext
!= NULL
)
3309 free (debug
->ssext
);
3310 if (debug
->external_fdr
!= NULL
)
3311 free (debug
->external_fdr
);
3312 if (debug
->external_rfd
!= NULL
)
3313 free (debug
->external_rfd
);
3314 if (debug
->external_ext
!= NULL
)
3315 free (debug
->external_ext
);
3319 /* MIPS ELF local labels start with '$', not 'L'. */
3323 mips_elf_is_local_label_name (abfd
, name
)
3330 /* On Irix 6, the labels go back to starting with '.', so we accept
3331 the generic ELF local label syntax as well. */
3332 return _bfd_elf_is_local_label_name (abfd
, name
);
3335 /* MIPS ELF uses a special find_nearest_line routine in order the
3336 handle the ECOFF debugging information. */
3338 struct mips_elf_find_line
3340 struct ecoff_debug_info d
;
3341 struct ecoff_find_line i
;
3345 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
3346 functionname_ptr
, line_ptr
)
3351 const char **filename_ptr
;
3352 const char **functionname_ptr
;
3353 unsigned int *line_ptr
;
3357 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3358 filename_ptr
, functionname_ptr
,
3362 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
3366 struct mips_elf_find_line
*fi
;
3367 const struct ecoff_debug_swap
* const swap
=
3368 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3370 /* If we are called during a link, mips_elf_final_link may have
3371 cleared the SEC_HAS_CONTENTS field. We force it back on here
3372 if appropriate (which it normally will be). */
3373 origflags
= msec
->flags
;
3374 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
3375 msec
->flags
|= SEC_HAS_CONTENTS
;
3377 fi
= elf_tdata (abfd
)->find_line_info
;
3380 bfd_size_type external_fdr_size
;
3383 struct fdr
*fdr_ptr
;
3385 fi
= ((struct mips_elf_find_line
*)
3386 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
3389 msec
->flags
= origflags
;
3393 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
3395 msec
->flags
= origflags
;
3399 /* Swap in the FDR information. */
3400 fi
->d
.fdr
= ((struct fdr
*)
3402 (fi
->d
.symbolic_header
.ifdMax
*
3403 sizeof (struct fdr
))));
3404 if (fi
->d
.fdr
== NULL
)
3406 msec
->flags
= origflags
;
3409 external_fdr_size
= swap
->external_fdr_size
;
3410 fdr_ptr
= fi
->d
.fdr
;
3411 fraw_src
= (char *) fi
->d
.external_fdr
;
3412 fraw_end
= (fraw_src
3413 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
3414 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
3415 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
3417 elf_tdata (abfd
)->find_line_info
= fi
;
3419 /* Note that we don't bother to ever free this information.
3420 find_nearest_line is either called all the time, as in
3421 objdump -l, so the information should be saved, or it is
3422 rarely called, as in ld error messages, so the memory
3423 wasted is unimportant. Still, it would probably be a
3424 good idea for free_cached_info to throw it away. */
3427 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
3428 &fi
->i
, filename_ptr
, functionname_ptr
,
3431 msec
->flags
= origflags
;
3435 msec
->flags
= origflags
;
3438 /* Fall back on the generic ELF find_nearest_line routine. */
3440 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
3441 filename_ptr
, functionname_ptr
,
3445 /* The mips16 compiler uses a couple of special sections to handle
3446 floating point arguments.
3448 Section names that look like .mips16.fn.FNNAME contain stubs that
3449 copy floating point arguments from the fp regs to the gp regs and
3450 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3451 call should be redirected to the stub instead. If no 32 bit
3452 function calls FNNAME, the stub should be discarded. We need to
3453 consider any reference to the function, not just a call, because
3454 if the address of the function is taken we will need the stub,
3455 since the address might be passed to a 32 bit function.
3457 Section names that look like .mips16.call.FNNAME contain stubs
3458 that copy floating point arguments from the gp regs to the fp
3459 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3460 then any 16 bit function that calls FNNAME should be redirected
3461 to the stub instead. If FNNAME is not a 32 bit function, the
3462 stub should be discarded.
3464 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3465 which call FNNAME and then copy the return value from the fp regs
3466 to the gp regs. These stubs store the return value in $18 while
3467 calling FNNAME; any function which might call one of these stubs
3468 must arrange to save $18 around the call. (This case is not
3469 needed for 32 bit functions that call 16 bit functions, because
3470 16 bit functions always return floating point values in both
3473 Note that in all cases FNNAME might be defined statically.
3474 Therefore, FNNAME is not used literally. Instead, the relocation
3475 information will indicate which symbol the section is for.
3477 We record any stubs that we find in the symbol table. */
3479 #define FN_STUB ".mips16.fn."
3480 #define CALL_STUB ".mips16.call."
3481 #define CALL_FP_STUB ".mips16.call.fp."
3483 /* The MIPS ELF linker needs additional information for each symbol in
3484 the global hash table. */
3486 struct mips_elf_link_hash_entry
3488 struct elf_link_hash_entry root
;
3490 /* External symbol information. */
3493 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
3494 unsigned int mips_32_relocs
;
3496 /* If there is a stub that 32 bit functions should use to call this
3497 16 bit function, this points to the section containing the stub. */
3500 /* Whether we need the fn_stub; this is set if this symbol appears
3501 in any relocs other than a 16 bit call. */
3502 boolean need_fn_stub
;
3504 /* If there is a stub that 16 bit functions should use to call this
3505 32 bit function, this points to the section containing the stub. */
3506 asection
*call_stub
;
3508 /* This is like the call_stub field, but it is used if the function
3509 being called returns a floating point value. */
3510 asection
*call_fp_stub
;
3513 /* MIPS ELF linker hash table. */
3515 struct mips_elf_link_hash_table
3517 struct elf_link_hash_table root
;
3518 /* String section indices for the dynamic section symbols. */
3519 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
3520 /* The number of .rtproc entries. */
3521 bfd_size_type procedure_count
;
3522 /* The size of the .compact_rel section (if SGI_COMPAT). */
3523 bfd_size_type compact_rel_size
;
3524 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3525 entry is set to the address of __rld_obj_head as in Irix 5. */
3526 boolean use_rld_obj_head
;
3527 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3529 /* This is set if we see any mips16 stub sections. */
3530 boolean mips16_stubs_seen
;
3533 /* Look up an entry in a MIPS ELF linker hash table. */
3535 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3536 ((struct mips_elf_link_hash_entry *) \
3537 elf_link_hash_lookup (&(table)->root, (string), (create), \
3540 /* Traverse a MIPS ELF linker hash table. */
3542 #define mips_elf_link_hash_traverse(table, func, info) \
3543 (elf_link_hash_traverse \
3545 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3548 /* Get the MIPS ELF linker hash table from a link_info structure. */
3550 #define mips_elf_hash_table(p) \
3551 ((struct mips_elf_link_hash_table *) ((p)->hash))
3553 static boolean mips_elf_output_extsym
3554 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3556 /* Create an entry in a MIPS ELF linker hash table. */
3558 static struct bfd_hash_entry
*
3559 mips_elf_link_hash_newfunc (entry
, table
, string
)
3560 struct bfd_hash_entry
*entry
;
3561 struct bfd_hash_table
*table
;
3564 struct mips_elf_link_hash_entry
*ret
=
3565 (struct mips_elf_link_hash_entry
*) entry
;
3567 /* Allocate the structure if it has not already been allocated by a
3569 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3570 ret
= ((struct mips_elf_link_hash_entry
*)
3571 bfd_hash_allocate (table
,
3572 sizeof (struct mips_elf_link_hash_entry
)));
3573 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3574 return (struct bfd_hash_entry
*) ret
;
3576 /* Call the allocation method of the superclass. */
3577 ret
= ((struct mips_elf_link_hash_entry
*)
3578 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3580 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3582 /* Set local fields. */
3583 memset (&ret
->esym
, 0, sizeof (EXTR
));
3584 /* We use -2 as a marker to indicate that the information has
3585 not been set. -1 means there is no associated ifd. */
3587 ret
->mips_32_relocs
= 0;
3588 ret
->fn_stub
= NULL
;
3589 ret
->need_fn_stub
= false;
3590 ret
->call_stub
= NULL
;
3591 ret
->call_fp_stub
= NULL
;
3594 return (struct bfd_hash_entry
*) ret
;
3597 /* Create a MIPS ELF linker hash table. */
3599 static struct bfd_link_hash_table
*
3600 mips_elf_link_hash_table_create (abfd
)
3603 struct mips_elf_link_hash_table
*ret
;
3606 ret
= ((struct mips_elf_link_hash_table
*)
3607 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
3608 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
3611 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3612 mips_elf_link_hash_newfunc
))
3614 bfd_release (abfd
, ret
);
3618 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
3619 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
3620 ret
->procedure_count
= 0;
3621 ret
->compact_rel_size
= 0;
3622 ret
->use_rld_obj_head
= false;
3624 ret
->mips16_stubs_seen
= false;
3626 return &ret
->root
.root
;
3629 /* Hook called by the linker routine which adds symbols from an object
3630 file. We must handle the special MIPS section numbers here. */
3634 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3636 struct bfd_link_info
*info
;
3637 const Elf_Internal_Sym
*sym
;
3643 if (SGI_COMPAT (abfd
)
3644 && (abfd
->flags
& DYNAMIC
) != 0
3645 && strcmp (*namep
, "_rld_new_interface") == 0)
3647 /* Skip Irix 5 rld entry name. */
3652 switch (sym
->st_shndx
)
3655 /* Common symbols less than the GP size are automatically
3656 treated as SHN_MIPS_SCOMMON symbols. */
3657 if (sym
->st_size
> elf_gp_size (abfd
))
3660 case SHN_MIPS_SCOMMON
:
3661 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3662 (*secp
)->flags
|= SEC_IS_COMMON
;
3663 *valp
= sym
->st_size
;
3667 /* This section is used in a shared object. */
3668 if (mips_elf_text_section_ptr
== NULL
)
3670 /* Initialize the section. */
3671 mips_elf_text_section
.name
= ".text";
3672 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
3673 mips_elf_text_section
.output_section
= NULL
;
3674 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
3675 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
3676 mips_elf_text_symbol
.name
= ".text";
3677 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
3678 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
3679 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
3680 mips_elf_text_section_ptr
= &mips_elf_text_section
;
3682 /* This code used to do *secp = bfd_und_section_ptr if
3683 info->shared. I don't know why, and that doesn't make sense,
3684 so I took it out. */
3685 *secp
= mips_elf_text_section_ptr
;
3688 case SHN_MIPS_ACOMMON
:
3689 /* Fall through. XXX Can we treat this as allocated data? */
3691 /* This section is used in a shared object. */
3692 if (mips_elf_data_section_ptr
== NULL
)
3694 /* Initialize the section. */
3695 mips_elf_data_section
.name
= ".data";
3696 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
3697 mips_elf_data_section
.output_section
= NULL
;
3698 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
3699 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
3700 mips_elf_data_symbol
.name
= ".data";
3701 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
3702 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
3703 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
3704 mips_elf_data_section_ptr
= &mips_elf_data_section
;
3706 /* This code used to do *secp = bfd_und_section_ptr if
3707 info->shared. I don't know why, and that doesn't make sense,
3708 so I took it out. */
3709 *secp
= mips_elf_data_section_ptr
;
3712 case SHN_MIPS_SUNDEFINED
:
3713 *secp
= bfd_und_section_ptr
;
3717 if (SGI_COMPAT (abfd
)
3719 && info
->hash
->creator
== abfd
->xvec
3720 && strcmp (*namep
, "__rld_obj_head") == 0)
3722 struct elf_link_hash_entry
*h
;
3724 /* Mark __rld_obj_head as dynamic. */
3726 if (! (_bfd_generic_link_add_one_symbol
3727 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3728 (bfd_vma
) *valp
, (const char *) NULL
, false,
3729 get_elf_backend_data (abfd
)->collect
,
3730 (struct bfd_link_hash_entry
**) &h
)))
3732 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
3733 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3734 h
->type
= STT_OBJECT
;
3736 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3739 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3742 /* If this is a mips16 text symbol, add 1 to the value to make it
3743 odd. This will cause something like .word SYM to come up with
3744 the right value when it is loaded into the PC. */
3745 if (sym
->st_other
== STO_MIPS16
)
3751 /* Structure used to pass information to mips_elf_output_extsym. */
3756 struct bfd_link_info
*info
;
3757 struct ecoff_debug_info
*debug
;
3758 const struct ecoff_debug_swap
*swap
;
3762 /* This routine is used to write out ECOFF debugging external symbol
3763 information. It is called via mips_elf_link_hash_traverse. The
3764 ECOFF external symbol information must match the ELF external
3765 symbol information. Unfortunately, at this point we don't know
3766 whether a symbol is required by reloc information, so the two
3767 tables may wind up being different. We must sort out the external
3768 symbol information before we can set the final size of the .mdebug
3769 section, and we must set the size of the .mdebug section before we
3770 can relocate any sections, and we can't know which symbols are
3771 required by relocation until we relocate the sections.
3772 Fortunately, it is relatively unlikely that any symbol will be
3773 stripped but required by a reloc. In particular, it can not happen
3774 when generating a final executable. */
3777 mips_elf_output_extsym (h
, data
)
3778 struct mips_elf_link_hash_entry
*h
;
3781 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
3783 asection
*sec
, *output_section
;
3785 if (h
->root
.indx
== -2)
3787 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3788 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
3789 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3790 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
3792 else if (einfo
->info
->strip
== strip_all
3793 || (einfo
->info
->strip
== strip_some
3794 && bfd_hash_lookup (einfo
->info
->keep_hash
,
3795 h
->root
.root
.root
.string
,
3796 false, false) == NULL
))
3804 if (h
->esym
.ifd
== -2)
3807 h
->esym
.cobol_main
= 0;
3808 h
->esym
.weakext
= 0;
3809 h
->esym
.reserved
= 0;
3810 h
->esym
.ifd
= ifdNil
;
3811 h
->esym
.asym
.value
= 0;
3812 h
->esym
.asym
.st
= stGlobal
;
3814 if (SGI_COMPAT (einfo
->abfd
)
3815 && (h
->root
.root
.type
== bfd_link_hash_undefined
3816 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
3820 /* Use undefined class. Also, set class and type for some
3822 name
= h
->root
.root
.root
.string
;
3823 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
3824 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
3826 h
->esym
.asym
.sc
= scData
;
3827 h
->esym
.asym
.st
= stLabel
;
3828 h
->esym
.asym
.value
= 0;
3830 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
3832 h
->esym
.asym
.sc
= scAbs
;
3833 h
->esym
.asym
.st
= stLabel
;
3834 h
->esym
.asym
.value
=
3835 mips_elf_hash_table (einfo
->info
)->procedure_count
;
3837 else if (strcmp (name
, "_gp_disp") == 0)
3839 h
->esym
.asym
.sc
= scAbs
;
3840 h
->esym
.asym
.st
= stLabel
;
3841 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
3844 h
->esym
.asym
.sc
= scUndefined
;
3846 else if (h
->root
.root
.type
!= bfd_link_hash_defined
3847 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
3848 h
->esym
.asym
.sc
= scAbs
;
3853 sec
= h
->root
.root
.u
.def
.section
;
3854 output_section
= sec
->output_section
;
3856 /* When making a shared library and symbol h is the one from
3857 the another shared library, OUTPUT_SECTION may be null. */
3858 if (output_section
== NULL
)
3859 h
->esym
.asym
.sc
= scUndefined
;
3862 name
= bfd_section_name (output_section
->owner
, output_section
);
3864 if (strcmp (name
, ".text") == 0)
3865 h
->esym
.asym
.sc
= scText
;
3866 else if (strcmp (name
, ".data") == 0)
3867 h
->esym
.asym
.sc
= scData
;
3868 else if (strcmp (name
, ".sdata") == 0)
3869 h
->esym
.asym
.sc
= scSData
;
3870 else if (strcmp (name
, ".rodata") == 0
3871 || strcmp (name
, ".rdata") == 0)
3872 h
->esym
.asym
.sc
= scRData
;
3873 else if (strcmp (name
, ".bss") == 0)
3874 h
->esym
.asym
.sc
= scBss
;
3875 else if (strcmp (name
, ".sbss") == 0)
3876 h
->esym
.asym
.sc
= scSBss
;
3877 else if (strcmp (name
, ".init") == 0)
3878 h
->esym
.asym
.sc
= scInit
;
3879 else if (strcmp (name
, ".fini") == 0)
3880 h
->esym
.asym
.sc
= scFini
;
3882 h
->esym
.asym
.sc
= scAbs
;
3886 h
->esym
.asym
.reserved
= 0;
3887 h
->esym
.asym
.index
= indexNil
;
3890 if (h
->root
.root
.type
== bfd_link_hash_common
)
3891 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
3892 else if (h
->root
.root
.type
== bfd_link_hash_defined
3893 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3895 if (h
->esym
.asym
.sc
== scCommon
)
3896 h
->esym
.asym
.sc
= scBss
;
3897 else if (h
->esym
.asym
.sc
== scSCommon
)
3898 h
->esym
.asym
.sc
= scSBss
;
3900 sec
= h
->root
.root
.u
.def
.section
;
3901 output_section
= sec
->output_section
;
3902 if (output_section
!= NULL
)
3903 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
3904 + sec
->output_offset
3905 + output_section
->vma
);
3907 h
->esym
.asym
.value
= 0;
3909 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3911 /* Set type and value for a symbol with a function stub. */
3912 h
->esym
.asym
.st
= stProc
;
3913 sec
= h
->root
.root
.u
.def
.section
;
3915 h
->esym
.asym
.value
= 0;
3918 output_section
= sec
->output_section
;
3919 if (output_section
!= NULL
)
3920 h
->esym
.asym
.value
= (h
->root
.plt
.offset
3921 + sec
->output_offset
3922 + output_section
->vma
);
3924 h
->esym
.asym
.value
= 0;
3931 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
3932 h
->root
.root
.root
.string
,
3935 einfo
->failed
= true;
3942 /* Create a runtime procedure table from the .mdebug section. */
3945 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
3948 struct bfd_link_info
*info
;
3950 struct ecoff_debug_info
*debug
;
3952 const struct ecoff_debug_swap
*swap
;
3953 HDRR
*hdr
= &debug
->symbolic_header
;
3955 struct rpdr_ext
*erp
;
3957 struct pdr_ext
*epdr
;
3958 struct sym_ext
*esym
;
3961 unsigned long size
, count
;
3962 unsigned long sindex
;
3966 const char *no_name_func
= _("static procedure (no name)");
3974 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3976 sindex
= strlen (no_name_func
) + 1;
3977 count
= hdr
->ipdMax
;
3980 size
= swap
->external_pdr_size
;
3982 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
3986 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
3989 size
= sizeof (RPDR
);
3990 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
3994 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
3998 count
= hdr
->isymMax
;
3999 size
= swap
->external_sym_size
;
4000 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
4004 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
4007 count
= hdr
->issMax
;
4008 ss
= (char *) bfd_malloc (count
);
4011 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
4014 count
= hdr
->ipdMax
;
4015 for (i
= 0; i
< count
; i
++, rp
++)
4017 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
4018 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
4019 rp
->adr
= sym
.value
;
4020 rp
->regmask
= pdr
.regmask
;
4021 rp
->regoffset
= pdr
.regoffset
;
4022 rp
->fregmask
= pdr
.fregmask
;
4023 rp
->fregoffset
= pdr
.fregoffset
;
4024 rp
->frameoffset
= pdr
.frameoffset
;
4025 rp
->framereg
= pdr
.framereg
;
4026 rp
->pcreg
= pdr
.pcreg
;
4028 sv
[i
] = ss
+ sym
.iss
;
4029 sindex
+= strlen (sv
[i
]) + 1;
4033 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
4034 size
= BFD_ALIGN (size
, 16);
4035 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
4038 mips_elf_hash_table (info
)->procedure_count
= 0;
4042 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
4044 erp
= (struct rpdr_ext
*) rtproc
;
4045 memset (erp
, 0, sizeof (struct rpdr_ext
));
4047 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
4048 strcpy (str
, no_name_func
);
4049 str
+= strlen (no_name_func
) + 1;
4050 for (i
= 0; i
< count
; i
++)
4052 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
4053 strcpy (str
, sv
[i
]);
4054 str
+= strlen (sv
[i
]) + 1;
4056 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
4058 /* Set the size and contents of .rtproc section. */
4059 s
->_raw_size
= size
;
4060 s
->contents
= (bfd_byte
*) rtproc
;
4062 /* Skip this section later on (I don't think this currently
4063 matters, but someday it might). */
4064 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
4093 /* A comparison routine used to sort .gptab entries. */
4096 gptab_compare (p1
, p2
)
4100 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
4101 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
4103 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
4106 /* We need to use a special link routine to handle the .reginfo and
4107 the .mdebug sections. We need to merge all instances of these
4108 sections together, not write them all out sequentially. */
4111 mips_elf_final_link (abfd
, info
)
4113 struct bfd_link_info
*info
;
4117 struct bfd_link_order
*p
;
4118 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
4119 asection
*rtproc_sec
;
4120 Elf32_RegInfo reginfo
;
4121 struct ecoff_debug_info debug
;
4122 const struct ecoff_debug_swap
*swap
4123 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4124 HDRR
*symhdr
= &debug
.symbolic_header
;
4125 PTR mdebug_handle
= NULL
;
4127 /* Drop the .options section, since it has special semantics which I
4128 haven't bothered to figure out. */
4129 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
4131 if (strcmp ((*secpp
)->name
, ".options") == 0)
4133 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
4134 if (p
->type
== bfd_indirect_link_order
)
4135 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
4136 (*secpp
)->link_order_head
= NULL
;
4137 *secpp
= (*secpp
)->next
;
4138 --abfd
->section_count
;
4143 /* Get a value for the GP register. */
4144 if (elf_gp (abfd
) == 0)
4146 struct bfd_link_hash_entry
*h
;
4148 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4149 if (h
!= (struct bfd_link_hash_entry
*) NULL
4150 && h
->type
== bfd_link_hash_defined
)
4151 elf_gp (abfd
) = (h
->u
.def
.value
4152 + h
->u
.def
.section
->output_section
->vma
4153 + h
->u
.def
.section
->output_offset
);
4154 else if (info
->relocateable
)
4158 /* Make up a value. */
4160 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4163 && (strcmp (o
->name
, ".sbss") == 0
4164 || strcmp (o
->name
, ".sdata") == 0
4165 || strcmp (o
->name
, ".lit4") == 0
4166 || strcmp (o
->name
, ".lit8") == 0))
4169 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
4173 /* If the relocate_section function needs to do a reloc
4174 involving the GP value, it should make a reloc_dangerous
4175 callback to warn that GP is not defined. */
4179 /* Go through the sections and collect the .reginfo and .mdebug
4183 gptab_data_sec
= NULL
;
4184 gptab_bss_sec
= NULL
;
4185 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4187 if (strcmp (o
->name
, ".reginfo") == 0)
4189 memset (®info
, 0, sizeof reginfo
);
4191 /* We have found the .reginfo section in the output file.
4192 Look through all the link_orders comprising it and merge
4193 the information together. */
4194 for (p
= o
->link_order_head
;
4195 p
!= (struct bfd_link_order
*) NULL
;
4198 asection
*input_section
;
4200 Elf32_External_RegInfo ext
;
4203 if (p
->type
!= bfd_indirect_link_order
)
4205 if (p
->type
== bfd_fill_link_order
)
4210 input_section
= p
->u
.indirect
.section
;
4211 input_bfd
= input_section
->owner
;
4213 /* The linker emulation code has probably clobbered the
4214 size to be zero bytes. */
4215 if (input_section
->_raw_size
== 0)
4216 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4218 if (! bfd_get_section_contents (input_bfd
, input_section
,
4224 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
4226 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
4227 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
4228 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
4229 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
4230 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
4232 /* ri_gp_value is set by the function
4233 mips_elf32_section_processing when the section is
4234 finally written out. */
4236 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4237 elf_link_input_bfd ignores this section. */
4238 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4241 /* Force the section size to the value we want. */
4242 o
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4244 /* Skip this section later on (I don't think this currently
4245 matters, but someday it might). */
4246 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4251 if (strcmp (o
->name
, ".mdebug") == 0)
4253 struct extsym_info einfo
;
4255 /* We have found the .mdebug section in the output file.
4256 Look through all the link_orders comprising it and merge
4257 the information together. */
4258 symhdr
->magic
= swap
->sym_magic
;
4259 /* FIXME: What should the version stamp be? */
4261 symhdr
->ilineMax
= 0;
4265 symhdr
->isymMax
= 0;
4266 symhdr
->ioptMax
= 0;
4267 symhdr
->iauxMax
= 0;
4269 symhdr
->issExtMax
= 0;
4272 symhdr
->iextMax
= 0;
4274 /* We accumulate the debugging information itself in the
4275 debug_info structure. */
4277 debug
.external_dnr
= NULL
;
4278 debug
.external_pdr
= NULL
;
4279 debug
.external_sym
= NULL
;
4280 debug
.external_opt
= NULL
;
4281 debug
.external_aux
= NULL
;
4283 debug
.ssext
= debug
.ssext_end
= NULL
;
4284 debug
.external_fdr
= NULL
;
4285 debug
.external_rfd
= NULL
;
4286 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4288 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4289 if (mdebug_handle
== (PTR
) NULL
)
4292 if (SGI_COMPAT (abfd
))
4298 static const char * const name
[] =
4299 { ".text", ".init", ".fini", ".data",
4300 ".rodata", ".sdata", ".sbss", ".bss" };
4301 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
4302 scRData
, scSData
, scSBss
, scBss
};
4305 esym
.cobol_main
= 0;
4309 esym
.asym
.iss
= issNil
;
4310 esym
.asym
.st
= stLocal
;
4311 esym
.asym
.reserved
= 0;
4312 esym
.asym
.index
= indexNil
;
4314 for (i
= 0; i
< 8; i
++)
4316 esym
.asym
.sc
= sc
[i
];
4317 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4320 esym
.asym
.value
= s
->vma
;
4321 last
= s
->vma
+ s
->_raw_size
;
4324 esym
.asym
.value
= last
;
4326 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4332 for (p
= o
->link_order_head
;
4333 p
!= (struct bfd_link_order
*) NULL
;
4336 asection
*input_section
;
4338 const struct ecoff_debug_swap
*input_swap
;
4339 struct ecoff_debug_info input_debug
;
4343 if (p
->type
!= bfd_indirect_link_order
)
4345 if (p
->type
== bfd_fill_link_order
)
4350 input_section
= p
->u
.indirect
.section
;
4351 input_bfd
= input_section
->owner
;
4353 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4354 || (get_elf_backend_data (input_bfd
)
4355 ->elf_backend_ecoff_debug_swap
) == NULL
)
4357 /* I don't know what a non MIPS ELF bfd would be
4358 doing with a .mdebug section, but I don't really
4359 want to deal with it. */
4363 input_swap
= (get_elf_backend_data (input_bfd
)
4364 ->elf_backend_ecoff_debug_swap
);
4366 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
4368 /* The ECOFF linking code expects that we have already
4369 read in the debugging information and set up an
4370 ecoff_debug_info structure, so we do that now. */
4371 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
4375 if (! (bfd_ecoff_debug_accumulate
4376 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
4377 &input_debug
, input_swap
, info
)))
4380 /* Loop through the external symbols. For each one with
4381 interesting information, try to find the symbol in
4382 the linker global hash table and save the information
4383 for the output external symbols. */
4384 eraw_src
= input_debug
.external_ext
;
4385 eraw_end
= (eraw_src
4386 + (input_debug
.symbolic_header
.iextMax
4387 * input_swap
->external_ext_size
));
4389 eraw_src
< eraw_end
;
4390 eraw_src
+= input_swap
->external_ext_size
)
4394 struct mips_elf_link_hash_entry
*h
;
4396 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4397 if (ext
.asym
.sc
== scNil
4398 || ext
.asym
.sc
== scUndefined
4399 || ext
.asym
.sc
== scSUndefined
)
4402 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4403 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
4404 name
, false, false, true);
4405 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4411 < input_debug
.symbolic_header
.ifdMax
);
4412 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4418 /* Free up the information we just read. */
4419 free (input_debug
.line
);
4420 free (input_debug
.external_dnr
);
4421 free (input_debug
.external_pdr
);
4422 free (input_debug
.external_sym
);
4423 free (input_debug
.external_opt
);
4424 free (input_debug
.external_aux
);
4425 free (input_debug
.ss
);
4426 free (input_debug
.ssext
);
4427 free (input_debug
.external_fdr
);
4428 free (input_debug
.external_rfd
);
4429 free (input_debug
.external_ext
);
4431 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4432 elf_link_input_bfd ignores this section. */
4433 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4436 if (SGI_COMPAT (abfd
) && info
->shared
)
4438 /* Create .rtproc section. */
4439 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4440 if (rtproc_sec
== NULL
)
4442 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4443 | SEC_LINKER_CREATED
| SEC_READONLY
);
4445 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4446 if (rtproc_sec
== NULL
4447 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4448 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
4452 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
4453 info
, rtproc_sec
, &debug
))
4457 /* Build the external symbol information. */
4460 einfo
.debug
= &debug
;
4462 einfo
.failed
= false;
4463 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4464 mips_elf_output_extsym
,
4469 /* Set the size of the .mdebug section. */
4470 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4472 /* Skip this section later on (I don't think this currently
4473 matters, but someday it might). */
4474 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4479 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4481 const char *subname
;
4484 Elf32_External_gptab
*ext_tab
;
4487 /* The .gptab.sdata and .gptab.sbss sections hold
4488 information describing how the small data area would
4489 change depending upon the -G switch. These sections
4490 not used in executables files. */
4491 if (! info
->relocateable
)
4495 for (p
= o
->link_order_head
;
4496 p
!= (struct bfd_link_order
*) NULL
;
4499 asection
*input_section
;
4501 if (p
->type
!= bfd_indirect_link_order
)
4503 if (p
->type
== bfd_fill_link_order
)
4508 input_section
= p
->u
.indirect
.section
;
4510 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4511 elf_link_input_bfd ignores this section. */
4512 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4515 /* Skip this section later on (I don't think this
4516 currently matters, but someday it might). */
4517 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4519 /* Really remove the section. */
4520 for (secpp
= &abfd
->sections
;
4522 secpp
= &(*secpp
)->next
)
4524 *secpp
= (*secpp
)->next
;
4525 --abfd
->section_count
;
4530 /* There is one gptab for initialized data, and one for
4531 uninitialized data. */
4532 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4534 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4538 (*_bfd_error_handler
)
4539 (_("%s: illegal section name `%s'"),
4540 bfd_get_filename (abfd
), o
->name
);
4541 bfd_set_error (bfd_error_nonrepresentable_section
);
4545 /* The linker script always combines .gptab.data and
4546 .gptab.sdata into .gptab.sdata, and likewise for
4547 .gptab.bss and .gptab.sbss. It is possible that there is
4548 no .sdata or .sbss section in the output file, in which
4549 case we must change the name of the output section. */
4550 subname
= o
->name
+ sizeof ".gptab" - 1;
4551 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4553 if (o
== gptab_data_sec
)
4554 o
->name
= ".gptab.data";
4556 o
->name
= ".gptab.bss";
4557 subname
= o
->name
+ sizeof ".gptab" - 1;
4558 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4561 /* Set up the first entry. */
4563 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
4566 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4567 tab
[0].gt_header
.gt_unused
= 0;
4569 /* Combine the input sections. */
4570 for (p
= o
->link_order_head
;
4571 p
!= (struct bfd_link_order
*) NULL
;
4574 asection
*input_section
;
4578 bfd_size_type gpentry
;
4580 if (p
->type
!= bfd_indirect_link_order
)
4582 if (p
->type
== bfd_fill_link_order
)
4587 input_section
= p
->u
.indirect
.section
;
4588 input_bfd
= input_section
->owner
;
4590 /* Combine the gptab entries for this input section one
4591 by one. We know that the input gptab entries are
4592 sorted by ascending -G value. */
4593 size
= bfd_section_size (input_bfd
, input_section
);
4595 for (gpentry
= sizeof (Elf32_External_gptab
);
4597 gpentry
+= sizeof (Elf32_External_gptab
))
4599 Elf32_External_gptab ext_gptab
;
4600 Elf32_gptab int_gptab
;
4606 if (! (bfd_get_section_contents
4607 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4608 gpentry
, sizeof (Elf32_External_gptab
))))
4614 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
4616 val
= int_gptab
.gt_entry
.gt_g_value
;
4617 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4620 for (look
= 1; look
< c
; look
++)
4622 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4623 tab
[look
].gt_entry
.gt_bytes
+= add
;
4625 if (tab
[look
].gt_entry
.gt_g_value
== val
)
4631 Elf32_gptab
*new_tab
;
4634 /* We need a new table entry. */
4635 new_tab
= ((Elf32_gptab
*)
4636 bfd_realloc ((PTR
) tab
,
4637 (c
+ 1) * sizeof (Elf32_gptab
)));
4638 if (new_tab
== NULL
)
4644 tab
[c
].gt_entry
.gt_g_value
= val
;
4645 tab
[c
].gt_entry
.gt_bytes
= add
;
4647 /* Merge in the size for the next smallest -G
4648 value, since that will be implied by this new
4651 for (look
= 1; look
< c
; look
++)
4653 if (tab
[look
].gt_entry
.gt_g_value
< val
4655 || (tab
[look
].gt_entry
.gt_g_value
4656 > tab
[max
].gt_entry
.gt_g_value
)))
4660 tab
[c
].gt_entry
.gt_bytes
+=
4661 tab
[max
].gt_entry
.gt_bytes
;
4666 last
= int_gptab
.gt_entry
.gt_bytes
;
4669 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4670 elf_link_input_bfd ignores this section. */
4671 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4674 /* The table must be sorted by -G value. */
4676 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
4678 /* Swap out the table. */
4679 ext_tab
= ((Elf32_External_gptab
*)
4680 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
4681 if (ext_tab
== NULL
)
4687 for (i
= 0; i
< c
; i
++)
4688 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
4691 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
4692 o
->contents
= (bfd_byte
*) ext_tab
;
4694 /* Skip this section later on (I don't think this currently
4695 matters, but someday it might). */
4696 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4700 /* Invoke the regular ELF backend linker to do all the work. */
4701 if (! bfd_elf32_bfd_final_link (abfd
, info
))
4704 /* Now write out the computed sections. */
4706 if (reginfo_sec
!= (asection
*) NULL
)
4708 Elf32_External_RegInfo ext
;
4710 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
4711 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4712 (file_ptr
) 0, sizeof ext
))
4716 if (mdebug_sec
!= (asection
*) NULL
)
4718 BFD_ASSERT (abfd
->output_has_begun
);
4719 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4721 mdebug_sec
->filepos
))
4724 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4727 if (gptab_data_sec
!= (asection
*) NULL
)
4729 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4730 gptab_data_sec
->contents
,
4732 gptab_data_sec
->_raw_size
))
4736 if (gptab_bss_sec
!= (asection
*) NULL
)
4738 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4739 gptab_bss_sec
->contents
,
4741 gptab_bss_sec
->_raw_size
))
4745 if (SGI_COMPAT (abfd
))
4747 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4748 if (rtproc_sec
!= NULL
)
4750 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
4751 rtproc_sec
->contents
,
4753 rtproc_sec
->_raw_size
))
4761 /* Handle a MIPS ELF HI16 reloc. */
4764 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
4766 Elf_Internal_Rela
*relhi
;
4767 Elf_Internal_Rela
*rello
;
4774 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4776 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4779 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4781 if ((addlo
& 0x8000) != 0)
4783 if ((addend
& 0x8000) != 0)
4786 bfd_put_32 (input_bfd
,
4787 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
4788 contents
+ relhi
->r_offset
);
4791 /* Handle a MIPS ELF local GOT16 reloc. */
4794 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
4799 Elf_Internal_Rela
*relhi
;
4800 Elf_Internal_Rela
*rello
;
4804 unsigned int assigned_gotno
;
4810 bfd_byte
*got_contents
;
4811 struct mips_got_info
*g
;
4813 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4815 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4818 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4820 if ((addlo
& 0x8000) != 0)
4822 if ((addend
& 0x8000) != 0)
4825 /* Get a got entry representing requested hipage. */
4826 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4827 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4828 BFD_ASSERT (g
!= NULL
);
4830 assigned_gotno
= g
->assigned_gotno
;
4831 got_contents
= sgot
->contents
;
4832 hipage
= addend
& 0xffff0000;
4834 for (i
= MIPS_RESERVED_GOTNO
; i
< assigned_gotno
; i
++)
4836 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
4837 if (hipage
== (address
& 0xffff0000))
4841 if (i
== assigned_gotno
)
4843 if (assigned_gotno
>= g
->local_gotno
)
4845 (*_bfd_error_handler
)
4846 (_("more got entries are needed for hipage relocations"));
4847 bfd_set_error (bfd_error_bad_value
);
4851 bfd_put_32 (input_bfd
, hipage
, got_contents
+ assigned_gotno
* 4);
4852 ++g
->assigned_gotno
;
4855 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
4856 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
4857 contents
+ relhi
->r_offset
);
4862 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
4865 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
4867 Elf_Internal_Rela
*rel
;
4873 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4874 bfd_put_32 (input_bfd
,
4875 (insn
& 0xffff0000) | (offset
& 0xffff),
4876 contents
+ rel
->r_offset
);
4879 /* Relocate a MIPS ELF section. */
4882 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4883 contents
, relocs
, local_syms
, local_sections
)
4885 struct bfd_link_info
*info
;
4887 asection
*input_section
;
4889 Elf_Internal_Rela
*relocs
;
4890 Elf_Internal_Sym
*local_syms
;
4891 asection
**local_sections
;
4893 Elf_Internal_Shdr
*symtab_hdr
;
4896 asection
*sgot
, *sreloc
, *scpt
;
4899 Elf_Internal_Rela
*rel
;
4900 Elf_Internal_Rela
*relend
;
4901 struct mips_got_info
*g
;
4903 dynobj
= elf_hash_table (info
)->dynobj
;
4904 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4908 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
4911 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
4914 if (elf_bad_symtab (input_bfd
))
4916 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
4921 locsymcount
= symtab_hdr
->sh_info
;
4922 extsymoff
= symtab_hdr
->sh_info
;
4925 gp
= _bfd_get_gp_value (output_bfd
);
4928 relend
= relocs
+ input_section
->reloc_count
;
4929 for (; rel
< relend
; rel
++)
4932 reloc_howto_type
*howto
;
4933 unsigned long r_symndx
;
4935 struct elf_link_hash_entry
*h
;
4937 Elf_Internal_Sym
*sym
;
4938 struct mips_elf_link_hash_entry
*mh
;
4940 bfd_reloc_status_type r
;
4942 r_type
= ELF32_R_TYPE (rel
->r_info
);
4943 if (r_type
== R_MIPS_GNU_VTINHERIT
4944 || r_type
== R_MIPS_GNU_VTENTRY
)
4946 if ((r_type
< 0 || r_type
>= (int) R_MIPS_max
)
4947 /* start-sanitize-r5900 */
4948 && r_type
!= R_MIPS15_S3
4949 /* end-sanitize-r5900 */
4950 /* start-sanitize-sky */
4951 && r_type
!= R_MIPS_DVP_11_PCREL
4952 && r_type
!= R_MIPS_DVP_27_S4
4953 && r_type
!= R_MIPS_DVP_11_S4
4954 && r_type
!= R_MIPS_DVP_U15_S3
4955 /* end-sanitize-sky */
4956 && r_type
!= R_MIPS16_26
4957 && r_type
!= R_MIPS16_GPREL
)
4959 bfd_set_error (bfd_error_bad_value
);
4962 if (r_type
== R_MIPS16_26
)
4963 howto
= &elf_mips16_jump_howto
;
4964 else if (r_type
== R_MIPS16_GPREL
)
4965 howto
= &elf_mips16_gprel_howto
;
4966 /* start-sanitize-r5900 */
4967 else if (r_type
== R_MIPS15_S3
)
4968 howto
= &elf_mips15_s3_howto
;
4969 /* end-sanitize-r5900 */
4970 /* start-sanitize-sky */
4971 else if (r_type
== R_MIPS_DVP_11_PCREL
)
4972 howto
= &elf_mips_dvp_11_pcrel_howto
;
4973 else if (r_type
== R_MIPS_DVP_27_S4
)
4974 howto
= &elf_mips_dvp_27_s4_howto
;
4975 else if (r_type
== R_MIPS_DVP_11_S4
)
4976 howto
= &elf_mips_dvp_11_s4_howto
;
4977 else if (r_type
== R_MIPS_DVP_U15_S3
)
4978 howto
= &elf_mips_dvp_u15_s3_howto
;
4979 /* end-sanitize-sky */
4981 howto
= elf_mips_howto_table
+ r_type
;
4984 && (r_type
== R_MIPS_CALL16
4985 || r_type
== R_MIPS_GOT16
4986 || r_type
== R_MIPS_CALL_HI16
4987 || r_type
== R_MIPS_CALL_LO16
4988 || r_type
== R_MIPS_GOT_HI16
4989 || r_type
== R_MIPS_GOT_LO16
))
4991 /* We need the .got section. */
4994 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4995 BFD_ASSERT (sgot
!= NULL
);
4996 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4997 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4998 BFD_ASSERT (g
!= NULL
);
5002 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5004 /* Mix in the change in GP address for a GP relative reloc. */
5005 if (r_type
!= R_MIPS_GPREL16
5006 && r_type
!= R_MIPS_LITERAL
5007 && r_type
!= R_MIPS_GPREL32
5008 && r_type
!= R_MIPS16_GPREL
)
5014 if (! ((*info
->callbacks
->reloc_dangerous
)
5016 _("GP relative relocation when GP not defined"),
5017 input_bfd
, input_section
,
5020 /* Only give the error once per link. */
5022 _bfd_set_gp_value (output_bfd
, gp
);
5025 if (r_symndx
< extsymoff
5026 || (elf_bad_symtab (input_bfd
)
5027 && local_sections
[r_symndx
] != NULL
))
5029 /* This is a relocation against a section. The current
5030 addend in the instruction is the difference between
5031 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
5032 must change this to be the difference between the
5033 final definition (which will end up in RELOCATION)
5034 and the GP value of OUTPUT_BFD (which is in GP). */
5035 addend
= elf_gp (input_bfd
) - gp
;
5037 else if (! info
->relocateable
)
5039 /* We are doing a final link. The current addend in the
5040 instruction is simply the desired offset into the
5041 symbol (normally zero). We want the instruction to
5042 hold the difference between the final definition of
5043 the symbol (which will end up in RELOCATION) and the
5044 GP value of OUTPUT_BFD (which is in GP). */
5049 /* We are generating relocateable output, and we aren't
5050 going to define this symbol, so we just leave the
5051 instruction alone. */
5059 if (info
->relocateable
)
5061 /* This is a relocateable link. We don't have to change
5062 anything, unless the reloc is against a section symbol,
5063 in which case we have to adjust according to where the
5064 section symbol winds up in the output section. */
5065 if (r_symndx
>= locsymcount
5066 || (elf_bad_symtab (input_bfd
)
5067 && local_sections
[r_symndx
] == NULL
))
5071 sym
= local_syms
+ r_symndx
;
5072 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5076 sec
= local_sections
[r_symndx
];
5078 /* It would be logical to add sym->st_value here,
5079 but Irix 5 sometimes generates a garbage symbol
5081 addend
+= sec
->output_offset
;
5083 /* If this is HI16 or GOT16 with an associated LO16,
5084 adjust the addend accordingly. Otherwise, just
5086 if (r_type
== R_MIPS_64
&& bfd_big_endian (input_bfd
))
5087 r
= _bfd_relocate_contents (howto
, input_bfd
,
5089 contents
+ rel
->r_offset
+ 4);
5090 else if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
5091 r
= _bfd_relocate_contents (howto
, input_bfd
,
5093 contents
+ rel
->r_offset
);
5096 Elf_Internal_Rela
*lorel
;
5098 /* As a GNU extension, permit an arbitrary
5099 number of R_MIPS_HI16 relocs before the
5100 R_MIPS_LO16 reloc. This permits gcc to emit
5101 the HI and LO relocs itself. */
5102 if (r_type
== R_MIPS_GOT16
)
5106 for (lorel
= rel
+ 1;
5108 && (ELF32_R_TYPE (lorel
->r_info
)
5114 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5116 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5121 r
= _bfd_relocate_contents (howto
, input_bfd
,
5123 contents
+ rel
->r_offset
);
5132 boolean undefined_error
;
5134 /* This is a final link. */
5135 undefined_error
= false;
5137 if (r_symndx
< extsymoff
5138 || (elf_bad_symtab (input_bfd
)
5139 && local_sections
[r_symndx
] != NULL
))
5142 sym
= local_syms
+ r_symndx
;
5143 sec
= local_sections
[r_symndx
];
5144 relocation
= (sec
->output_section
->vma
5145 + sec
->output_offset
);
5147 /* It would be logical to always add sym->st_value here,
5148 but Irix 5 sometimes generates a garbage symbol
5150 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5151 relocation
+= sym
->st_value
;
5153 /* mips16 text labels should be treated as odd. */
5154 if (sym
->st_other
== STO_MIPS16
)
5162 indx
= r_symndx
- extsymoff
;
5163 h
= elf_sym_hashes (input_bfd
)[indx
];
5164 while (h
->root
.type
== bfd_link_hash_indirect
5165 || h
->root
.type
== bfd_link_hash_warning
)
5166 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5167 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
5171 if (! ((*info
->callbacks
->reloc_dangerous
)
5173 _("_gp_disp used when GP not defined"),
5174 input_bfd
, input_section
,
5177 /* Only give the error once per link. */
5179 _bfd_set_gp_value (output_bfd
, gp
);
5184 sec
= input_section
;
5185 if (sec
->output_section
!= NULL
)
5188 + sec
->output_section
->vma
5189 + sec
->output_offset
));
5191 relocation
= gp
- rel
->r_offset
;
5192 if (r_type
== R_MIPS_LO16
)
5196 else if (h
->root
.type
== bfd_link_hash_defined
5197 || h
->root
.type
== bfd_link_hash_defweak
)
5199 sec
= h
->root
.u
.def
.section
;
5200 if (sec
->output_section
== NULL
)
5203 relocation
= (h
->root
.u
.def
.value
5204 + sec
->output_section
->vma
5205 + sec
->output_offset
);
5207 else if (h
->root
.type
== bfd_link_hash_undefweak
)
5209 else if (info
->shared
&& ! info
->symbolic
)
5211 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
5213 /* If this is a dynamic link, we should have created
5214 a _DYNAMIC_LINK symbol in
5215 mips_elf_create_dynamic_sections. Otherwise, we
5216 should define the symbol with a value of 0.
5217 FIXME: It should probably get into the symbol
5218 table somehow as well. */
5219 BFD_ASSERT (! info
->shared
);
5220 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
5221 ".dynamic") == NULL
);
5226 if (! ((*info
->callbacks
->undefined_symbol
)
5227 (info
, h
->root
.root
.string
, input_bfd
,
5228 input_section
, rel
->r_offset
)))
5230 undefined_error
= true;
5235 mh
= (struct mips_elf_link_hash_entry
*) h
;
5238 else if (sym
!= NULL
)
5239 other
= sym
->st_other
;
5243 /* If this function has an fn_stub, then it is a mips16
5244 function which needs a stub if it is called by a 32 bit
5245 function. If this reloc is anything other than a 16 bit
5246 call, redirect the reloc to the stub. We don't redirect
5247 relocs from other stub functions. */
5248 if (r_type
!= R_MIPS16_26
5250 && mh
->fn_stub
!= NULL
)
5252 && elf_tdata (input_bfd
)->local_stubs
!= NULL
5253 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
5254 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5255 FN_STUB
, sizeof FN_STUB
- 1) != 0
5256 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5257 CALL_STUB
, sizeof CALL_STUB
- 1) != 0
5258 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5259 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) != 0)
5263 BFD_ASSERT (mh
->need_fn_stub
);
5264 relocation
= (mh
->fn_stub
->output_section
->vma
5265 + mh
->fn_stub
->output_offset
);
5271 fn_stub
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
5272 relocation
= (fn_stub
->output_section
->vma
5273 + fn_stub
->output_offset
);
5276 /* RELOCATION now points to 32 bit code. */
5280 /* If this function has a call_stub, then it is called by a
5281 mips16 function; the call needs to go through a stub if
5282 this function is a 32 bit function. If this reloc is a
5283 16 bit call, and the symbol is not a 16 bit function,
5284 then redirect the reloc to the stub. Note that we don't
5285 need to worry about calling the function through a
5286 function pointer; such calls are handled by routing
5287 through a special mips16 routine. We don't have to check
5288 whether this call is from a stub; it can't be, because a
5289 stub contains 32 bit code, and hence can not have a 16
5291 if (r_type
== R_MIPS16_26
5293 && (mh
->call_stub
!= NULL
|| mh
->call_fp_stub
!= NULL
)
5294 && other
!= STO_MIPS16
)
5298 /* If both call_stub and call_fp_stub are defined, we
5299 can figure out which one to use by seeing which one
5300 appears in the input file. */
5301 if (mh
->call_stub
!= NULL
&& mh
->call_fp_stub
!= NULL
)
5306 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
5308 if (strncmp (bfd_get_section_name (input_bfd
, o
),
5309 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5311 stub
= mh
->call_fp_stub
;
5316 stub
= mh
->call_stub
;
5318 else if (mh
->call_stub
!= NULL
)
5319 stub
= mh
->call_stub
;
5321 stub
= mh
->call_fp_stub
;
5323 BFD_ASSERT (stub
->_raw_size
> 0);
5324 relocation
= stub
->output_section
->vma
+ stub
->output_offset
;
5327 if (r_type
== R_MIPS_HI16
)
5329 Elf_Internal_Rela
*lorel
;
5331 /* As a GNU extension, permit an arbitrary number of
5332 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
5333 This permits gcc to emit the HI and LO relocs itself. */
5334 for (lorel
= rel
+ 1;
5336 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
5340 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5342 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5343 contents
, relocation
+ addend
);
5347 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5348 contents
, rel
->r_offset
,
5349 relocation
, addend
);
5351 else if (r_type
== R_MIPS_GOT16
&& local
)
5353 /* GOT16 must also have an associated LO16 in the local
5354 case. In this case, the addend is extracted and the
5355 section in which the referenced object is determined.
5356 Then the final address of the object is computed and
5357 the GOT entry for the hipage (an aligned 64kb chunk)
5358 is added to .got section if needed. The offset field
5359 of the GOT16-relocated instruction is replaced by the
5360 index of this GOT entry for the hipage. */
5361 if ((rel
+ 1) < relend
5362 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
5364 if (! mips_elf_relocate_got_local (output_bfd
, input_bfd
,
5367 relocation
+ addend
))
5372 r
= bfd_reloc_outofrange
;
5374 else if (r_type
== R_MIPS_CALL16
5375 || r_type
== R_MIPS_GOT16
5376 || r_type
== R_MIPS_CALL_LO16
5377 || r_type
== R_MIPS_GOT_LO16
)
5381 /* This symbol must be registered as a global symbol
5382 having the corresponding got entry. */
5383 BFD_ASSERT (h
->got
.offset
!= (bfd_vma
) -1);
5385 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5386 BFD_ASSERT (g
->local_gotno
<= offset
5387 && offset
< sgot
->_raw_size
);
5388 bfd_put_32 (output_bfd
, relocation
+ addend
,
5389 sgot
->contents
+ offset
);
5390 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5392 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
5396 else if (r_type
== R_MIPS_CALL_HI16
5397 || r_type
== R_MIPS_GOT_HI16
)
5401 /* This must be a global symbol with a got entry. The
5402 next reloc must be the corresponding LO16 reloc. */
5403 BFD_ASSERT (h
!= NULL
&& h
->got
.offset
!= (bfd_vma
) -1);
5404 BFD_ASSERT ((rel
+ 1) < relend
);
5405 BFD_ASSERT ((int) ELF32_R_TYPE ((rel
+ 1)->r_info
)
5406 == (r_type
== R_MIPS_CALL_HI16
5407 ? (int) R_MIPS_CALL_LO16
5408 : (int) R_MIPS_GOT_LO16
));
5410 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5411 BFD_ASSERT (g
->local_gotno
<= offset
5412 && offset
< sgot
->_raw_size
);
5413 bfd_put_32 (output_bfd
, relocation
+ addend
,
5414 sgot
->contents
+ offset
);
5415 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5417 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
5421 else if (r_type
== R_MIPS_REL32
5422 || r_type
== R_MIPS_32
)
5424 Elf_Internal_Rel outrel
;
5425 Elf32_crinfo cptrel
;
5429 || (elf_hash_table (info
)->dynamic_sections_created
5431 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
5433 && (input_section
->flags
& SEC_ALLOC
) != 0)
5437 /* When generating a shared object, these
5438 relocations are copied into the output file to be
5439 resolved at run time. */
5442 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5443 BFD_ASSERT (sreloc
!= NULL
);
5448 if (elf_section_data (input_section
)->stab_info
== NULL
)
5449 outrel
.r_offset
= rel
->r_offset
;
5454 off
= (_bfd_stab_section_offset
5455 (output_bfd
, &elf_hash_table (info
)->stab_info
,
5457 &elf_section_data (input_section
)->stab_info
,
5459 if (off
== (bfd_vma
) -1)
5461 outrel
.r_offset
= off
;
5464 outrel
.r_offset
+= (input_section
->output_section
->vma
5465 + input_section
->output_offset
);
5467 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5470 memset (&outrel
, 0, sizeof outrel
);
5472 && (! info
->symbolic
5473 || (h
->elf_link_hash_flags
5474 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5476 BFD_ASSERT (h
->dynindx
!= -1);
5477 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
5478 sec
= input_section
;
5485 sec
= local_sections
[r_symndx
];
5488 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
5490 == bfd_link_hash_defweak
));
5491 sec
= h
->root
.u
.def
.section
;
5493 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5495 else if (sec
== NULL
|| sec
->owner
== NULL
)
5497 bfd_set_error (bfd_error_bad_value
);
5504 osec
= sec
->output_section
;
5505 indx
= elf_section_data (osec
)->dynindx
;
5510 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
5511 addend
+= relocation
;
5515 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
5517 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
5518 (((Elf32_External_Rel
*)
5520 + sreloc
->reloc_count
));
5521 ++sreloc
->reloc_count
;
5523 if (! skip
&& SGI_COMPAT (output_bfd
))
5528 /* Make an entry of compact relocation info. */
5529 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5530 cptrel
.vaddr
= (rel
->r_offset
5531 + input_section
->output_section
->vma
5532 + input_section
->output_offset
);
5533 if (r_type
== R_MIPS_REL32
)
5534 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5536 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5537 mips_elf_set_cr_dist2to (cptrel
, 0);
5538 cptrel
.konst
= addend
;
5540 cr
= (scpt
->contents
5541 + sizeof (Elf32_External_compact_rel
));
5542 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5543 ((Elf32_External_crinfo
*) cr
5544 + scpt
->reloc_count
));
5545 ++scpt
->reloc_count
;
5548 /* This reloc will be computed at runtime, so
5549 there's no need to do anything now. */
5553 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5554 contents
, rel
->r_offset
,
5555 relocation
, addend
);
5557 else if (r_type
== R_MIPS_64
)
5562 /* Do a 32 bit relocation, and sign extend to 64 bits. */
5563 addr
= rel
->r_offset
;
5564 if (bfd_big_endian (input_bfd
))
5566 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5567 contents
, addr
, relocation
,
5569 val
= bfd_get_32 (input_bfd
, contents
+ addr
);
5570 if ((val
& 0x80000000) != 0)
5574 addr
= rel
->r_offset
;
5575 if (bfd_little_endian (input_bfd
))
5577 bfd_put_32 (input_bfd
, val
, contents
+ addr
);
5579 else if (r_type
== R_MIPS_26
&& other
== STO_MIPS16
)
5583 /* This is a jump to a mips16 routine from a mips32
5584 routine. We need to change jal into jalx. */
5585 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5586 if (((insn
>> 26) & 0x3f) != 0x3
5587 && ((insn
>> 26) & 0x3f) != 0x1d)
5589 (*_bfd_error_handler
)
5590 (_("%s: %s+0x%lx: jump to mips16 routine which is not jal"),
5591 bfd_get_filename (input_bfd
),
5592 input_section
->name
,
5593 (unsigned long) rel
->r_offset
);
5594 bfd_set_error (bfd_error_bad_value
);
5597 insn
= (insn
& 0x3ffffff) | (0x1d << 26);
5598 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5599 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5600 contents
, rel
->r_offset
,
5601 relocation
, addend
);
5603 else if (r_type
== R_MIPS16_26
)
5605 /* It's easiest to do the normal relocation, and then
5606 dig out the instruction and swap the first word the
5607 way the mips16 expects it. If this is little endian,
5608 though, we need to swap the two words first, and then
5609 swap them back again later, so that the address looks
5612 if (bfd_little_endian (input_bfd
))
5616 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5617 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5618 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5621 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5622 contents
, rel
->r_offset
,
5623 relocation
, addend
);
5624 if (r
== bfd_reloc_ok
)
5628 if (bfd_little_endian (input_bfd
))
5630 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5631 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5632 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5635 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5636 insn
= ((insn
& 0xfc00)
5637 | ((insn
& 0x1f) << 5)
5638 | ((insn
& 0x3e0) >> 5));
5639 /* If this is a jump to a 32 bit routine, then make
5641 if (other
!= STO_MIPS16
)
5643 bfd_put_16 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5646 else if (r_type
== R_MIPS16_GPREL
)
5648 unsigned short extend
, insn
;
5650 unsigned long final
;
5652 /* Extract the addend into buf, run the regular reloc,
5653 and stuff the resulting value back into the
5655 if (rel
->r_offset
> input_section
->_raw_size
)
5656 r
= bfd_reloc_outofrange
;
5659 extend
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5660 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 2);
5661 bfd_put_32 (input_bfd
,
5662 (((extend
& 0x1f) << 11)
5666 r
= _bfd_final_link_relocate (howto
, input_bfd
,
5668 (bfd_vma
) 0, relocation
,
5670 final
= bfd_get_32 (input_bfd
, buf
);
5671 bfd_put_16 (input_bfd
,
5673 | ((final
>> 11) & 0x1f)
5675 contents
+ rel
->r_offset
);
5676 bfd_put_16 (input_bfd
,
5679 contents
+ rel
->r_offset
+ 2);
5682 /* start-sanitize-sky */
5683 else if (r_type
== R_MIPS_DVP_U15_S3
)
5685 if (rel
->r_offset
> input_section
->_raw_size
)
5686 r
= bfd_reloc_outofrange
;
5691 relocation
+= rel
->r_addend
;
5694 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5695 relocation
+= ((x
& (0xf << 21)) >> 10) + (x
& 0x7ff);
5696 x
&= ~ ((0xf << 21) | 0x7ff);
5697 x
|= (((relocation
& 0x7800) << 10)
5698 | (relocation
& 0x7ff));
5699 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
5701 if (relocation
& ~ (bfd_vma
) 0x7fff)
5702 r
= bfd_reloc_overflow
;
5707 /* end-sanitize-sky */
5709 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5710 contents
, rel
->r_offset
,
5711 relocation
, addend
);
5713 /* The jal instruction can only jump to an address which is
5714 divisible by 4, and it can only jump to an address with
5715 the same upper 4 bits as the PC. */
5716 if (r
== bfd_reloc_ok
5717 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
))
5722 if (other
== STO_MIPS16
)
5723 addr
&= ~ (bfd_vma
) 1;
5726 || ((addr
& 0xf0000000)
5727 != ((input_section
->output_section
->vma
5728 + input_section
->output_offset
5731 r
= bfd_reloc_overflow
;
5734 /* Don't bother to report a relocation overflow for a call
5735 to a weak undefined symbol with a value of zero. This
5738 even if we aren't in range to call address zero. */
5739 if (r
== bfd_reloc_overflow
5740 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
)
5741 && relocation
+ addend
== 0
5743 && h
->root
.type
== bfd_link_hash_undefweak
)
5746 /* If we've already issued an error for an undefined symbol,
5747 don't issue another useless error. */
5749 && (r
== bfd_reloc_undefined
|| r
== bfd_reloc_overflow
))
5752 if (SGI_COMPAT (abfd
)
5754 && (input_section
->flags
& SEC_ALLOC
) != 0)
5756 Elf32_crinfo cptrel
;
5759 /* Make an entry of compact relocation info. */
5760 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5761 cptrel
.vaddr
= (rel
->r_offset
5762 + input_section
->output_section
->vma
5763 + input_section
->output_offset
);
5768 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
5769 /* XXX How should we set dist2to in this case. */
5770 mips_elf_set_cr_dist2to (cptrel
, 8);
5771 cptrel
.konst
= addend
+ relocation
;
5772 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5773 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5774 ((Elf32_External_crinfo
*) cr
5775 + scpt
->reloc_count
));
5776 ++scpt
->reloc_count
;
5779 case R_MIPS_GPREL16
:
5780 case R_MIPS_LITERAL
:
5781 case R_MIPS_GPREL32
:
5782 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
5783 cptrel
.konst
= gp
- cptrel
.vaddr
;
5784 mips_elf_set_cr_dist2to (cptrel
, 4);
5785 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5786 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5787 ((Elf32_External_crinfo
*) cr
5788 + scpt
->reloc_count
));
5789 ++scpt
->reloc_count
;
5798 if (r
!= bfd_reloc_ok
)
5803 case bfd_reloc_outofrange
:
5805 case bfd_reloc_overflow
:
5810 name
= h
->root
.root
.string
;
5813 name
= bfd_elf_string_from_elf_section (input_bfd
,
5814 symtab_hdr
->sh_link
,
5819 name
= bfd_section_name (input_bfd
, sec
);
5821 if (! ((*info
->callbacks
->reloc_overflow
)
5822 (info
, name
, howto
->name
, (bfd_vma
) 0,
5823 input_bfd
, input_section
, rel
->r_offset
)))
5834 /* This hook function is called before the linker writes out a global
5835 symbol. We mark symbols as small common if appropriate. This is
5836 also where we undo the increment of the value for a mips16 symbol. */
5840 mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
5842 struct bfd_link_info
*info
;
5844 Elf_Internal_Sym
*sym
;
5845 asection
*input_sec
;
5847 /* If we see a common symbol, which implies a relocatable link, then
5848 if a symbol was small common in an input file, mark it as small
5849 common in the output file. */
5850 if (sym
->st_shndx
== SHN_COMMON
5851 && strcmp (input_sec
->name
, ".scommon") == 0)
5852 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
5854 if (sym
->st_other
== STO_MIPS16
5855 && (sym
->st_value
& 1) != 0)
5861 /* Functions for the dynamic linker. */
5863 /* The name of the dynamic interpreter. This is put in the .interp
5866 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
5868 /* Create dynamic sections when linking against a dynamic object. */
5871 mips_elf_create_dynamic_sections (abfd
, info
)
5873 struct bfd_link_info
*info
;
5875 struct elf_link_hash_entry
*h
;
5877 register asection
*s
;
5878 const char * const *namep
;
5880 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5881 | SEC_LINKER_CREATED
| SEC_READONLY
);
5883 /* Mips ABI requests the .dynamic section to be read only. */
5884 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5887 if (! bfd_set_section_flags (abfd
, s
, flags
))
5891 /* We need to create .got section. */
5892 if (! mips_elf_create_got_section (abfd
, info
))
5895 /* Create .stub section. */
5896 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
5898 s
= bfd_make_section (abfd
, ".stub");
5900 || ! bfd_set_section_flags (abfd
, s
, flags
)
5901 || ! bfd_set_section_alignment (abfd
, s
, 2))
5905 if (SGI_COMPAT (abfd
)
5907 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
5909 s
= bfd_make_section (abfd
, ".rld_map");
5911 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
5912 || ! bfd_set_section_alignment (abfd
, s
, 2))
5916 if (SGI_COMPAT (abfd
))
5918 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
5921 if (! (_bfd_generic_link_add_one_symbol
5922 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
5923 (bfd_vma
) 0, (const char *) NULL
, false,
5924 get_elf_backend_data (abfd
)->collect
,
5925 (struct bfd_link_hash_entry
**) &h
)))
5927 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5928 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5929 h
->type
= STT_SECTION
;
5931 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5935 /* We need to create a .compact_rel section. */
5936 if (! mips_elf_create_compact_rel_section (abfd
, info
))
5939 /* Change aligments of some sections. */
5940 s
= bfd_get_section_by_name (abfd
, ".hash");
5942 bfd_set_section_alignment (abfd
, s
, 4);
5943 s
= bfd_get_section_by_name (abfd
, ".dynsym");
5945 bfd_set_section_alignment (abfd
, s
, 4);
5946 s
= bfd_get_section_by_name (abfd
, ".dynstr");
5948 bfd_set_section_alignment (abfd
, s
, 4);
5949 s
= bfd_get_section_by_name (abfd
, ".reginfo");
5951 bfd_set_section_alignment (abfd
, s
, 4);
5952 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5954 bfd_set_section_alignment (abfd
, s
, 4);
5960 if (! (_bfd_generic_link_add_one_symbol
5961 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
5962 (bfd_vma
) 0, (const char *) NULL
, false,
5963 get_elf_backend_data (abfd
)->collect
,
5964 (struct bfd_link_hash_entry
**) &h
)))
5966 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5967 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5968 h
->type
= STT_SECTION
;
5970 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5973 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
5975 /* __rld_map is a four byte word located in the .data section
5976 and is filled in by the rtld to contain a pointer to
5977 the _r_debug structure. Its symbol value will be set in
5978 mips_elf_finish_dynamic_symbol. */
5979 s
= bfd_get_section_by_name (abfd
, ".rld_map");
5980 BFD_ASSERT (s
!= NULL
);
5983 if (! (_bfd_generic_link_add_one_symbol
5984 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
5985 (bfd_vma
) 0, (const char *) NULL
, false,
5986 get_elf_backend_data (abfd
)->collect
,
5987 (struct bfd_link_hash_entry
**) &h
)))
5989 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5990 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5991 h
->type
= STT_OBJECT
;
5993 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6001 /* Create the .compact_rel section. */
6004 mips_elf_create_compact_rel_section (abfd
, info
)
6006 struct bfd_link_info
*info
;
6009 register asection
*s
;
6011 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
6013 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
6016 s
= bfd_make_section (abfd
, ".compact_rel");
6018 || ! bfd_set_section_flags (abfd
, s
, flags
)
6019 || ! bfd_set_section_alignment (abfd
, s
, 2))
6022 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
6028 /* Create the .got section to hold the global offset table. */
6031 mips_elf_create_got_section (abfd
, info
)
6033 struct bfd_link_info
*info
;
6036 register asection
*s
;
6037 struct elf_link_hash_entry
*h
;
6038 struct mips_got_info
*g
;
6040 /* This function may be called more than once. */
6041 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
6044 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6045 | SEC_LINKER_CREATED
);
6047 s
= bfd_make_section (abfd
, ".got");
6049 || ! bfd_set_section_flags (abfd
, s
, flags
)
6050 || ! bfd_set_section_alignment (abfd
, s
, 4))
6053 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
6054 linker script because we don't want to define the symbol if we
6055 are not creating a global offset table. */
6057 if (! (_bfd_generic_link_add_one_symbol
6058 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
6059 (bfd_vma
) 0, (const char *) NULL
, false,
6060 get_elf_backend_data (abfd
)->collect
,
6061 (struct bfd_link_hash_entry
**) &h
)))
6063 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6064 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6065 h
->type
= STT_OBJECT
;
6068 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6071 /* The first several global offset table entries are reserved. */
6072 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
6074 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
6075 sizeof (struct mips_got_info
));
6078 g
->global_gotsym
= 0;
6079 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
6080 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
6081 if (elf_section_data (s
) == NULL
)
6084 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
6085 if (elf_section_data (s
) == NULL
)
6088 elf_section_data (s
)->tdata
= (PTR
) g
;
6093 /* Look through the relocs for a section during the first phase, and
6094 allocate space in the global offset table. */
6097 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
6099 struct bfd_link_info
*info
;
6101 const Elf_Internal_Rela
*relocs
;
6105 Elf_Internal_Shdr
*symtab_hdr
;
6106 struct elf_link_hash_entry
**sym_hashes
;
6107 struct mips_got_info
*g
;
6109 const Elf_Internal_Rela
*rel
;
6110 const Elf_Internal_Rela
*rel_end
;
6114 if (info
->relocateable
)
6117 dynobj
= elf_hash_table (info
)->dynobj
;
6118 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6119 sym_hashes
= elf_sym_hashes (abfd
);
6120 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
6122 /* Check for the mips16 stub sections. */
6124 name
= bfd_get_section_name (abfd
, sec
);
6125 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
6127 unsigned long r_symndx
;
6129 /* Look at the relocation information to figure out which symbol
6132 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6134 if (r_symndx
< extsymoff
6135 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6139 /* This stub is for a local symbol. This stub will only be
6140 needed if there is some relocation in this BFD, other
6141 than a 16 bit function call, which refers to this symbol. */
6142 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6144 Elf_Internal_Rela
*sec_relocs
;
6145 const Elf_Internal_Rela
*r
, *rend
;
6147 /* We can ignore stub sections when looking for relocs. */
6148 if ((o
->flags
& SEC_RELOC
) == 0
6149 || o
->reloc_count
== 0
6150 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
6151 sizeof FN_STUB
- 1) == 0
6152 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
6153 sizeof CALL_STUB
- 1) == 0
6154 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
6155 sizeof CALL_FP_STUB
- 1) == 0)
6158 sec_relocs
= (_bfd_elf32_link_read_relocs
6159 (abfd
, o
, (PTR
) NULL
,
6160 (Elf_Internal_Rela
*) NULL
,
6161 info
->keep_memory
));
6162 if (sec_relocs
== NULL
)
6165 rend
= sec_relocs
+ o
->reloc_count
;
6166 for (r
= sec_relocs
; r
< rend
; r
++)
6167 if (ELF32_R_SYM (r
->r_info
) == r_symndx
6168 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
6171 if (! info
->keep_memory
)
6180 /* There is no non-call reloc for this stub, so we do
6181 not need it. Since this function is called before
6182 the linker maps input sections to output sections, we
6183 can easily discard it by setting the SEC_EXCLUDE
6185 sec
->flags
|= SEC_EXCLUDE
;
6189 /* Record this stub in an array of local symbol stubs for
6191 if (elf_tdata (abfd
)->local_stubs
== NULL
)
6193 unsigned long symcount
;
6196 if (elf_bad_symtab (abfd
))
6197 symcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
6199 symcount
= symtab_hdr
->sh_info
;
6200 n
= (asection
**) bfd_zalloc (abfd
,
6201 symcount
* sizeof (asection
*));
6204 elf_tdata (abfd
)->local_stubs
= n
;
6207 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
6209 /* We don't need to set mips16_stubs_seen in this case.
6210 That flag is used to see whether we need to look through
6211 the global symbol table for stubs. We don't need to set
6212 it here, because we just have a local stub. */
6216 struct mips_elf_link_hash_entry
*h
;
6218 h
= ((struct mips_elf_link_hash_entry
*)
6219 sym_hashes
[r_symndx
- extsymoff
]);
6221 /* H is the symbol this stub is for. */
6224 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6227 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
6228 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6230 unsigned long r_symndx
;
6231 struct mips_elf_link_hash_entry
*h
;
6234 /* Look at the relocation information to figure out which symbol
6237 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6239 if (r_symndx
< extsymoff
6240 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6242 /* This stub was actually built for a static symbol defined
6243 in the same file. We assume that all static symbols in
6244 mips16 code are themselves mips16, so we can simply
6245 discard this stub. Since this function is called before
6246 the linker maps input sections to output sections, we can
6247 easily discard it by setting the SEC_EXCLUDE flag. */
6248 sec
->flags
|= SEC_EXCLUDE
;
6252 h
= ((struct mips_elf_link_hash_entry
*)
6253 sym_hashes
[r_symndx
- extsymoff
]);
6255 /* H is the symbol this stub is for. */
6257 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6258 loc
= &h
->call_fp_stub
;
6260 loc
= &h
->call_stub
;
6262 /* If we already have an appropriate stub for this function, we
6263 don't need another one, so we can discard this one. Since
6264 this function is called before the linker maps input sections
6265 to output sections, we can easily discard it by setting the
6266 SEC_EXCLUDE flag. We can also discard this section if we
6267 happen to already know that this is a mips16 function; it is
6268 not necessary to check this here, as it is checked later, but
6269 it is slightly faster to check now. */
6270 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
6272 sec
->flags
|= SEC_EXCLUDE
;
6277 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6287 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6292 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6293 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6294 BFD_ASSERT (g
!= NULL
);
6300 rel_end
= relocs
+ sec
->reloc_count
;
6301 for (rel
= relocs
; rel
< rel_end
; rel
++)
6303 unsigned long r_symndx
;
6304 struct elf_link_hash_entry
*h
;
6306 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6308 if (r_symndx
< extsymoff
)
6312 h
= sym_hashes
[r_symndx
- extsymoff
];
6314 /* This may be an indirect symbol created because of a version. */
6317 while (h
->root
.type
== bfd_link_hash_indirect
)
6318 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6322 /* Some relocs require a global offset table. */
6323 if (dynobj
== NULL
|| sgot
== NULL
)
6325 switch (ELF32_R_TYPE (rel
->r_info
))
6329 case R_MIPS_CALL_HI16
:
6330 case R_MIPS_CALL_LO16
:
6331 case R_MIPS_GOT_HI16
:
6332 case R_MIPS_GOT_LO16
:
6334 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6335 if (! mips_elf_create_got_section (dynobj
, info
))
6337 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6338 BFD_ASSERT (sgot
!= NULL
);
6339 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6340 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6341 BFD_ASSERT (g
!= NULL
);
6347 && (info
->shared
|| h
!= NULL
)
6348 && (sec
->flags
& SEC_ALLOC
) != 0)
6349 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6357 switch (ELF32_R_TYPE (rel
->r_info
))
6360 case R_MIPS_CALL_HI16
:
6361 case R_MIPS_CALL_LO16
:
6362 /* This symbol requires a global offset table entry. */
6366 (*_bfd_error_handler
)
6367 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
6368 bfd_get_filename (abfd
), (unsigned long) rel
->r_offset
);
6369 bfd_set_error (bfd_error_bad_value
);
6373 /* Make sure this symbol is output as a dynamic symbol. */
6374 if (h
->dynindx
== -1)
6376 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6380 if (h
->got
.offset
!= (bfd_vma
) -1)
6382 /* We have already allocated space in the .got. */
6386 /* Note the index of the first global got symbol in .dynsym. */
6387 if (g
->global_gotsym
== 0
6388 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6389 g
->global_gotsym
= h
->dynindx
;
6391 /* Make this symbol to have the corresponding got entry. */
6394 /* We need a stub, not a plt entry for the undefined
6395 function. But we record it as if it needs plt. See
6396 elf_adjust_dynamic_symbol in elflink.h. */
6397 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6403 case R_MIPS_GOT_HI16
:
6404 case R_MIPS_GOT_LO16
:
6405 /* This symbol requires a global offset table entry. */
6409 /* Make sure this symbol is output as a dynamic symbol. */
6410 if (h
->dynindx
== -1)
6412 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6416 if (h
->got
.offset
!= (bfd_vma
) -1)
6418 /* We have already allocated space in the .got. */
6421 /* Note the index of the first global got symbol in
6423 if (g
->global_gotsym
== 0
6424 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6425 g
->global_gotsym
= h
->dynindx
;
6427 /* Make this symbol to be the global got symbol. */
6435 if ((info
->shared
|| h
!= NULL
)
6436 && (sec
->flags
& SEC_ALLOC
) != 0)
6440 const char *name
= ".rel.dyn";
6442 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6445 sreloc
= bfd_make_section (dynobj
, name
);
6447 || ! bfd_set_section_flags (dynobj
, sreloc
,
6452 | SEC_LINKER_CREATED
6454 || ! bfd_set_section_alignment (dynobj
, sreloc
,
6461 /* When creating a shared object, we must copy these
6462 reloc types into the output file as R_MIPS_REL32
6463 relocs. We make room for this reloc in the
6464 .rel.dyn reloc section */
6465 if (sreloc
->_raw_size
== 0)
6467 /* Add a null element. */
6468 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6469 ++sreloc
->reloc_count
;
6471 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6475 struct mips_elf_link_hash_entry
*hmips
;
6477 /* We only need to copy this reloc if the symbol is
6478 defined in a dynamic object. */
6479 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6480 ++hmips
->mips_32_relocs
;
6484 if (SGI_COMPAT (abfd
))
6485 mips_elf_hash_table (info
)->compact_rel_size
+=
6486 sizeof (Elf32_External_crinfo
);
6491 case R_MIPS_GPREL16
:
6492 case R_MIPS_LITERAL
:
6493 case R_MIPS_GPREL32
:
6494 if (SGI_COMPAT (abfd
))
6495 mips_elf_hash_table (info
)->compact_rel_size
+=
6496 sizeof (Elf32_External_crinfo
);
6499 /* This relocation describes the C++ object vtable hierarchy.
6500 Reconstruct it for later use during GC. */
6501 case R_MIPS_GNU_VTINHERIT
:
6502 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6506 /* This relocation describes which C++ vtable entries are actually
6507 used. Record for later use during GC. */
6508 case R_MIPS_GNU_VTENTRY
:
6509 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
6517 /* If this reloc is not a 16 bit call, and it has a global
6518 symbol, then we will need the fn_stub if there is one.
6519 References from a stub section do not count. */
6521 && ELF32_R_TYPE (rel
->r_info
) != R_MIPS16_26
6522 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
6523 sizeof FN_STUB
- 1) != 0
6524 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
6525 sizeof CALL_STUB
- 1) != 0
6526 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
6527 sizeof CALL_FP_STUB
- 1) != 0)
6529 struct mips_elf_link_hash_entry
*mh
;
6531 mh
= (struct mips_elf_link_hash_entry
*) h
;
6532 mh
->need_fn_stub
= true;
6539 /* Return the section that should be marked against GC for a given
6543 mips_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
6545 struct bfd_link_info
*info
;
6546 Elf_Internal_Rela
*rel
;
6547 struct elf_link_hash_entry
*h
;
6548 Elf_Internal_Sym
*sym
;
6550 /* ??? Do mips16 stub sections need to be handled special? */
6554 switch (ELF32_R_TYPE (rel
->r_info
))
6556 case R_MIPS_GNU_VTINHERIT
:
6557 case R_MIPS_GNU_VTENTRY
:
6561 switch (h
->root
.type
)
6563 case bfd_link_hash_defined
:
6564 case bfd_link_hash_defweak
:
6565 return h
->root
.u
.def
.section
;
6567 case bfd_link_hash_common
:
6568 return h
->root
.u
.c
.p
->section
;
6574 if (!(elf_bad_symtab (abfd
)
6575 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
6576 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
6577 && sym
->st_shndx
!= SHN_COMMON
))
6579 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
6586 /* Update the got entry reference counts for the section being removed. */
6589 mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
6591 struct bfd_link_info
*info
;
6593 const Elf_Internal_Rela
*relocs
;
6596 Elf_Internal_Shdr
*symtab_hdr
;
6597 struct elf_link_hash_entry
**sym_hashes
;
6598 bfd_signed_vma
*local_got_refcounts
;
6599 const Elf_Internal_Rela
*rel
, *relend
;
6600 unsigned long r_symndx
;
6601 struct elf_link_hash_entry
*h
;
6603 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6604 sym_hashes
= elf_sym_hashes (abfd
);
6605 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6607 relend
= relocs
+ sec
->reloc_count
;
6608 for (rel
= relocs
; rel
< relend
; rel
++)
6609 switch (ELF32_R_TYPE (rel
->r_info
))
6613 case R_MIPS_CALL_HI16
:
6614 case R_MIPS_CALL_LO16
:
6615 case R_MIPS_GOT_HI16
:
6616 case R_MIPS_GOT_LO16
:
6617 /* ??? It would seem that the existing MIPS code does no sort
6618 of reference counting or whatnot on its GOT and PLT entries,
6619 so it is not possible to garbage collect them at this time. */
6631 /* Adjust a symbol defined by a dynamic object and referenced by a
6632 regular object. The current definition is in some section of the
6633 dynamic object, but we're not including those sections. We have to
6634 change the definition to something the rest of the link can
6638 mips_elf_adjust_dynamic_symbol (info
, h
)
6639 struct bfd_link_info
*info
;
6640 struct elf_link_hash_entry
*h
;
6643 struct mips_elf_link_hash_entry
*hmips
;
6646 dynobj
= elf_hash_table (info
)->dynobj
;
6648 /* Make sure we know what is going on here. */
6649 BFD_ASSERT (dynobj
!= NULL
6650 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
6651 || h
->weakdef
!= NULL
6652 || ((h
->elf_link_hash_flags
6653 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
6654 && (h
->elf_link_hash_flags
6655 & ELF_LINK_HASH_REF_REGULAR
) != 0
6656 && (h
->elf_link_hash_flags
6657 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
6659 /* If this symbol is defined in a dynamic object, we need to copy
6660 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
6662 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6663 if (! info
->relocateable
6664 && hmips
->mips_32_relocs
!= 0
6665 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6667 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6668 BFD_ASSERT (s
!= NULL
);
6670 if (s
->_raw_size
== 0)
6672 /* Make room for a null element. */
6673 s
->_raw_size
+= sizeof (Elf32_External_Rel
);
6676 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
6679 /* For a function, create a stub, if needed. */
6680 if (h
->type
== STT_FUNC
6681 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
6683 if (! elf_hash_table (info
)->dynamic_sections_created
)
6686 /* If this symbol is not defined in a regular file, then set
6687 the symbol to the stub location. This is required to make
6688 function pointers compare as equal between the normal
6689 executable and the shared library. */
6690 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6692 /* We need .stub section. */
6693 s
= bfd_get_section_by_name (dynobj
, ".stub");
6694 BFD_ASSERT (s
!= NULL
);
6696 h
->root
.u
.def
.section
= s
;
6697 h
->root
.u
.def
.value
= s
->_raw_size
;
6699 /* XXX Write this stub address somewhere. */
6700 h
->plt
.offset
= s
->_raw_size
;
6702 /* Make room for this stub code. */
6703 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6705 /* The last half word of the stub will be filled with the index
6706 of this symbol in .dynsym section. */
6711 /* If this is a weak symbol, and there is a real definition, the
6712 processor independent code will have arranged for us to see the
6713 real definition first, and we can just use the same value. */
6714 if (h
->weakdef
!= NULL
)
6716 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
6717 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
6718 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
6719 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
6723 /* This is a reference to a symbol defined by a dynamic object which
6724 is not a function. */
6729 /* This function is called after all the input files have been read,
6730 and the input sections have been assigned to output sections. We
6731 check for any mips16 stub sections that we can discard. */
6733 static boolean mips_elf_check_mips16_stubs
6734 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
6737 mips_elf_always_size_sections (output_bfd
, info
)
6739 struct bfd_link_info
*info
;
6741 if (info
->relocateable
6742 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
6745 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
6746 mips_elf_check_mips16_stubs
,
6752 /* Check the mips16 stubs for a particular symbol, and see if we can
6757 mips_elf_check_mips16_stubs (h
, data
)
6758 struct mips_elf_link_hash_entry
*h
;
6761 if (h
->fn_stub
!= NULL
6762 && ! h
->need_fn_stub
)
6764 /* We don't need the fn_stub; the only references to this symbol
6765 are 16 bit calls. Clobber the size to 0 to prevent it from
6766 being included in the link. */
6767 h
->fn_stub
->_raw_size
= 0;
6768 h
->fn_stub
->_cooked_size
= 0;
6769 h
->fn_stub
->flags
&= ~ SEC_RELOC
;
6770 h
->fn_stub
->reloc_count
= 0;
6771 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
6774 if (h
->call_stub
!= NULL
6775 && h
->root
.other
== STO_MIPS16
)
6777 /* We don't need the call_stub; this is a 16 bit function, so
6778 calls from other 16 bit functions are OK. Clobber the size
6779 to 0 to prevent it from being included in the link. */
6780 h
->call_stub
->_raw_size
= 0;
6781 h
->call_stub
->_cooked_size
= 0;
6782 h
->call_stub
->flags
&= ~ SEC_RELOC
;
6783 h
->call_stub
->reloc_count
= 0;
6784 h
->call_stub
->flags
|= SEC_EXCLUDE
;
6787 if (h
->call_fp_stub
!= NULL
6788 && h
->root
.other
== STO_MIPS16
)
6790 /* We don't need the call_stub; this is a 16 bit function, so
6791 calls from other 16 bit functions are OK. Clobber the size
6792 to 0 to prevent it from being included in the link. */
6793 h
->call_fp_stub
->_raw_size
= 0;
6794 h
->call_fp_stub
->_cooked_size
= 0;
6795 h
->call_fp_stub
->flags
&= ~ SEC_RELOC
;
6796 h
->call_fp_stub
->reloc_count
= 0;
6797 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
6803 /* Set the sizes of the dynamic sections. */
6806 mips_elf_size_dynamic_sections (output_bfd
, info
)
6808 struct bfd_link_info
*info
;
6814 struct mips_got_info
*g
;
6816 dynobj
= elf_hash_table (info
)->dynobj
;
6817 BFD_ASSERT (dynobj
!= NULL
);
6819 if (elf_hash_table (info
)->dynamic_sections_created
)
6821 /* Set the contents of the .interp section to the interpreter. */
6824 s
= bfd_get_section_by_name (dynobj
, ".interp");
6825 BFD_ASSERT (s
!= NULL
);
6826 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
6827 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
6831 /* Recompute the size of .got for local entires (reserved and
6832 hipages) if needed. To estimate it, get the upper bound of total
6833 size of loadable sections. */
6834 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6838 bfd_size_type loadable_size
= 0;
6839 bfd_size_type local_gotno
;
6842 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6843 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6844 BFD_ASSERT (g
!= NULL
);
6846 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
6847 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
6849 if ((s
->flags
& SEC_ALLOC
) == 0)
6851 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
6854 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
6856 /* Assume there are two loadable segments consisting of
6857 contiguous sections. Is 5 enough? */
6858 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
6859 g
->local_gotno
= local_gotno
;
6860 sgot
->_raw_size
+= local_gotno
* 4;
6863 /* The check_relocs and adjust_dynamic_symbol entry points have
6864 determined the sizes of the various dynamic sections. Allocate
6867 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
6872 /* It's OK to base decisions on the section name, because none
6873 of the dynobj section names depend upon the input files. */
6874 name
= bfd_get_section_name (dynobj
, s
);
6876 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
6881 if (strncmp (name
, ".rel", 4) == 0)
6883 if (s
->_raw_size
== 0)
6885 /* We only strip the section if the output section name
6886 has the same name. Otherwise, there might be several
6887 input sections for this output section. FIXME: This
6888 code is probably not needed these days anyhow, since
6889 the linker now does not create empty output sections. */
6890 if (s
->output_section
!= NULL
6892 bfd_get_section_name (s
->output_section
->owner
,
6893 s
->output_section
)) == 0)
6898 const char *outname
;
6901 /* If this relocation section applies to a read only
6902 section, then we probably need a DT_TEXTREL entry.
6903 If the relocation section is .rel.dyn, we always
6904 assert a DT_TEXTREL entry rather than testing whether
6905 there exists a relocation to a read only section or
6907 outname
= bfd_get_section_name (output_bfd
,
6909 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
6911 && (target
->flags
& SEC_READONLY
) != 0
6912 && (target
->flags
& SEC_ALLOC
) != 0)
6913 || strcmp (outname
, ".rel.dyn") == 0)
6916 /* We use the reloc_count field as a counter if we need
6917 to copy relocs into the output file. */
6918 if (strcmp (name
, ".rel.dyn") != 0)
6922 else if (strncmp (name
, ".got", 4) == 0)
6926 BFD_ASSERT (elf_section_data (s
) != NULL
);
6927 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
6928 BFD_ASSERT (g
!= NULL
);
6930 /* Fix the size of .got section for the correspondence of
6931 global symbols and got entries. This adds some useless
6932 got entries. Is this required by ABI really? */
6933 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
6934 s
->_raw_size
+= i
* 4;
6936 else if (strncmp (name
, ".stub", 5) == 0)
6938 /* Irix rld assumes that the function stub isn't at the end
6939 of .text section. So put a dummy. XXX */
6940 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6942 else if (! info
->shared
6943 && ! mips_elf_hash_table (info
)->use_rld_obj_head
6944 && strncmp (name
, ".rld_map", 8) == 0)
6946 /* We add a room for __rld_map. It will be filled in by the
6947 rtld to contain a pointer to the _r_debug structure. */
6950 else if (SGI_COMPAT (output_bfd
)
6951 && strncmp (name
, ".compact_rel", 12) == 0)
6952 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
6953 else if (strncmp (name
, ".init", 5) != 0)
6955 /* It's not one of our sections, so don't allocate space. */
6963 for (spp
= &s
->output_section
->owner
->sections
;
6964 *spp
!= s
->output_section
;
6965 spp
= &(*spp
)->next
)
6967 *spp
= s
->output_section
->next
;
6968 --s
->output_section
->owner
->section_count
;
6973 /* Allocate memory for the section contents. */
6974 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
6975 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
6977 bfd_set_error (bfd_error_no_memory
);
6980 memset (s
->contents
, 0, s
->_raw_size
);
6983 if (elf_hash_table (info
)->dynamic_sections_created
)
6985 /* Add some entries to the .dynamic section. We fill in the
6986 values later, in elf_mips_finish_dynamic_sections, but we
6987 must add the entries now so that we get the correct size for
6988 the .dynamic section. The DT_DEBUG entry is filled in by the
6989 dynamic linker and used by the debugger. */
6992 if (SGI_COMPAT (output_bfd
))
6994 /* SGI object has the equivalence of DT_DEBUG in the
6995 DT_MIPS_RLD_MAP entry. */
6996 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
7000 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
7006 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
7010 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
7013 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
7015 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
7018 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
7021 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
7025 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
7028 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
7031 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
7033 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
7036 s
= bfd_get_section_by_name (dynobj
, ".liblist");
7037 BFD_ASSERT (s
!= NULL
);
7039 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
7043 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
7046 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
7050 /* Time stamps in executable files are a bad idea. */
7051 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
7056 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
7061 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
7065 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
7068 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
7071 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
7074 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
7077 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
7080 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
7083 #if 0 /* (SGI_COMPAT) */
7084 if (! bfd_get_section_by_name (dynobj
, ".init"))
7085 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
7088 if (! bfd_get_section_by_name (dynobj
, ".fini"))
7089 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
7094 /* If we use dynamic linking, we generate a section symbol for each
7095 output section. These are local symbols, which means that they
7096 must come first in the dynamic symbol table.
7097 That means we must increment the dynamic symbol index of every
7098 other dynamic symbol. */
7100 const char * const *namep
;
7102 bfd_size_type strindex
;
7103 struct bfd_strtab_hash
*dynstr
;
7104 struct mips_got_info
*g
;
7107 if (elf_hash_table (info
)->dynamic_sections_created
)
7109 if (SGI_COMPAT (output_bfd
))
7111 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
7112 elf_link_hash_traverse (elf_hash_table (info
),
7113 mips_elf_adjust_dynindx
,
7115 elf_hash_table (info
)->dynsymcount
+= c
;
7117 dynstr
= elf_hash_table (info
)->dynstr
;
7118 BFD_ASSERT (dynstr
!= NULL
);
7120 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
7124 s
= bfd_get_section_by_name (output_bfd
, *namep
);
7126 elf_section_data (s
)->dynindx
= i
;
7128 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
7129 if (strindex
== (bfd_size_type
) -1)
7132 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
7137 c
= bfd_count_sections (output_bfd
);
7138 elf_link_hash_traverse (elf_hash_table (info
),
7139 mips_elf_adjust_dynindx
,
7141 elf_hash_table (info
)->dynsymcount
+= c
;
7143 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
7145 elf_section_data (s
)->dynindx
= i
;
7146 /* These symbols will have no names, so we don't need to
7147 fiddle with dynstr_index. */
7154 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7155 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7156 BFD_ASSERT (g
!= NULL
);
7158 /* If there are no global got symbols, fake the last symbol so
7160 if (g
->global_gotsym
)
7161 g
->global_gotsym
+= c
;
7163 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
7170 /* Increment the index of a dynamic symbol by a given amount. Called
7171 via elf_link_hash_traverse. */
7174 mips_elf_adjust_dynindx (h
, cparg
)
7175 struct elf_link_hash_entry
*h
;
7178 unsigned int *cp
= (unsigned int *) cparg
;
7180 if (h
->dynindx
!= -1)
7185 /* Finish up dynamic symbol handling. We set the contents of various
7186 dynamic sections here. */
7189 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
7191 struct bfd_link_info
*info
;
7192 struct elf_link_hash_entry
*h
;
7193 Elf_Internal_Sym
*sym
;
7198 struct mips_got_info
*g
;
7201 dynobj
= elf_hash_table (info
)->dynobj
;
7202 gval
= sym
->st_value
;
7204 if (h
->plt
.offset
!= (bfd_vma
) -1)
7208 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
7210 /* This symbol has a stub. Set it up. */
7212 BFD_ASSERT (h
->dynindx
!= -1);
7214 s
= bfd_get_section_by_name (dynobj
, ".stub");
7215 BFD_ASSERT (s
!= NULL
);
7217 /* Fill the stub. */
7219 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
7221 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
7224 /* FIXME: Can h->dynindex be more than 64K? */
7225 if (h
->dynindx
& 0xffff0000)
7228 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
7230 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
7232 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
7233 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
7235 /* Mark the symbol as undefined. plt.offset != -1 occurs
7236 only for the referenced symbol. */
7237 sym
->st_shndx
= SHN_UNDEF
;
7239 /* The run-time linker uses the st_value field of the symbol
7240 to reset the global offset table entry for this external
7241 to its stub address when unlinking a shared object. */
7242 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
7243 sym
->st_value
= gval
;
7246 BFD_ASSERT (h
->dynindx
!= -1);
7248 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7249 BFD_ASSERT (sgot
!= NULL
);
7250 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7251 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7252 BFD_ASSERT (g
!= NULL
);
7254 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
7256 bfd_size_type offset
;
7258 /* This symbol has an entry in the global offset table. Set its
7259 value to the corresponding got entry, if needed. */
7260 if (h
->got
.offset
== (bfd_vma
) -1)
7262 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
7263 BFD_ASSERT (g
->local_gotno
* 4 <= offset
7264 && offset
< sgot
->_raw_size
);
7265 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
7269 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7270 name
= h
->root
.root
.string
;
7271 if (strcmp (name
, "_DYNAMIC") == 0
7272 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
7273 sym
->st_shndx
= SHN_ABS
;
7274 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
7276 sym
->st_shndx
= SHN_ABS
;
7277 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7280 else if (SGI_COMPAT (output_bfd
))
7282 if (strcmp (name
, "_gp_disp") == 0)
7284 sym
->st_shndx
= SHN_ABS
;
7285 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7286 sym
->st_value
= elf_gp (output_bfd
);
7288 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
7289 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
7291 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7292 sym
->st_other
= STO_PROTECTED
;
7294 sym
->st_shndx
= SHN_MIPS_DATA
;
7296 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
7298 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7299 sym
->st_other
= STO_PROTECTED
;
7300 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
7301 sym
->st_shndx
= SHN_ABS
;
7303 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
7305 if (h
->type
== STT_FUNC
)
7306 sym
->st_shndx
= SHN_MIPS_TEXT
;
7307 else if (h
->type
== STT_OBJECT
)
7308 sym
->st_shndx
= SHN_MIPS_DATA
;
7312 if (SGI_COMPAT (output_bfd
)
7315 if (! mips_elf_hash_table (info
)->use_rld_obj_head
7316 && strcmp (name
, "__rld_map") == 0)
7318 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7319 BFD_ASSERT (s
!= NULL
);
7320 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
7321 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
7322 if (mips_elf_hash_table (info
)->rld_value
== 0)
7323 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7325 else if (mips_elf_hash_table (info
)->use_rld_obj_head
7326 && strcmp (name
, "__rld_obj_head") == 0)
7328 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7329 BFD_ASSERT (s
!= NULL
);
7330 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7334 /* If this is a mips16 symbol, force the value to be even. */
7335 if (sym
->st_other
== STO_MIPS16
7336 && (sym
->st_value
& 1) != 0)
7342 /* Finish up the dynamic sections. */
7345 mips_elf_finish_dynamic_sections (output_bfd
, info
)
7347 struct bfd_link_info
*info
;
7352 struct mips_got_info
*g
;
7354 dynobj
= elf_hash_table (info
)->dynobj
;
7356 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
7358 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7363 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7364 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7365 BFD_ASSERT (g
!= NULL
);
7368 if (elf_hash_table (info
)->dynamic_sections_created
)
7370 Elf32_External_Dyn
*dyncon
, *dynconend
;
7372 BFD_ASSERT (sdyn
!= NULL
);
7373 BFD_ASSERT (g
!= NULL
);
7375 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7376 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
7377 for (; dyncon
< dynconend
; dyncon
++)
7379 Elf_Internal_Dyn dyn
;
7384 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
7392 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7393 BFD_ASSERT (s
!= NULL
);
7394 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
7395 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7399 /* Rewrite DT_STRSZ. */
7401 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
7402 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7408 case DT_MIPS_CONFLICT
:
7411 case DT_MIPS_LIBLIST
:
7414 s
= bfd_get_section_by_name (output_bfd
, name
);
7415 BFD_ASSERT (s
!= NULL
);
7416 dyn
.d_un
.d_ptr
= s
->vma
;
7417 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7420 case DT_MIPS_RLD_VERSION
:
7421 dyn
.d_un
.d_val
= 1; /* XXX */
7422 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7426 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
7427 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7430 case DT_MIPS_CONFLICTNO
:
7432 elemsize
= sizeof (Elf32_Conflict
);
7435 case DT_MIPS_LIBLISTNO
:
7437 elemsize
= sizeof (Elf32_Lib
);
7439 s
= bfd_get_section_by_name (output_bfd
, name
);
7442 if (s
->_cooked_size
!= 0)
7443 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7445 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7450 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7453 case DT_MIPS_TIME_STAMP
:
7454 time ((time_t *) &dyn
.d_un
.d_val
);
7455 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7458 case DT_MIPS_ICHECKSUM
:
7462 case DT_MIPS_IVERSION
:
7466 case DT_MIPS_BASE_ADDRESS
:
7467 s
= output_bfd
->sections
;
7468 BFD_ASSERT (s
!= NULL
);
7469 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
7470 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7473 case DT_MIPS_LOCAL_GOTNO
:
7474 dyn
.d_un
.d_val
= g
->local_gotno
;
7475 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7478 case DT_MIPS_SYMTABNO
:
7480 elemsize
= sizeof (Elf32_External_Sym
);
7481 s
= bfd_get_section_by_name (output_bfd
, name
);
7482 BFD_ASSERT (s
!= NULL
);
7484 if (s
->_cooked_size
!= 0)
7485 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7487 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7488 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7491 case DT_MIPS_UNREFEXTNO
:
7493 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
7494 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7497 case DT_MIPS_GOTSYM
:
7498 dyn
.d_un
.d_val
= g
->global_gotsym
;
7499 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7502 case DT_MIPS_HIPAGENO
:
7503 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
7504 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7507 case DT_MIPS_RLD_MAP
:
7508 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
7509 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7516 /* The first entry of the global offset table will be filled at
7517 runtime. The second entry will be used by some runtime loaders.
7518 This isn't the case of Irix rld. */
7519 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
7521 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
7522 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
7526 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
7533 Elf_Internal_Sym sym
;
7536 const char * const * namep
= mips_elf_dynsym_sec_names
;
7537 Elf32_compact_rel cpt
;
7539 /* Set up the section symbols for the output sections. SGI sets
7540 the STT_NOTYPE attribute for these symbols. Should we do so? */
7542 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
7543 if (sdynsym
!= NULL
)
7545 if (SGI_COMPAT (output_bfd
))
7549 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7555 while ((name
= *namep
++) != NULL
)
7557 s
= bfd_get_section_by_name (output_bfd
, name
);
7560 sym
.st_value
= s
->vma
;
7561 dindx
= elf_section_data (s
)->dynindx
;
7562 last
= s
->vma
+ s
->_raw_size
;
7566 sym
.st_value
= last
;
7570 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
7575 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
7577 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7578 (((Elf32_External_Sym
*)
7583 /* Set the sh_info field of the output .dynsym section to
7584 the index of the first global symbol. */
7585 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7586 SIZEOF_MIPS_DYNSYM_SECNAMES
;
7592 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
7595 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
7599 sym
.st_value
= s
->vma
;
7601 indx
= elf_section_data (s
)->this_idx
;
7602 BFD_ASSERT (indx
> 0);
7603 sym
.st_shndx
= indx
;
7605 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7606 (((Elf32_External_Sym
*)
7608 + elf_section_data (s
)->dynindx
));
7611 /* Set the sh_info field of the output .dynsym section to
7612 the index of the first global symbol. */
7613 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7614 bfd_count_sections (output_bfd
) + 1;
7618 if (SGI_COMPAT (output_bfd
))
7620 /* Write .compact_rel section out. */
7621 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
7625 cpt
.num
= s
->reloc_count
;
7627 cpt
.offset
= (s
->output_section
->filepos
7628 + sizeof (Elf32_External_compact_rel
));
7631 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
7632 ((Elf32_External_compact_rel
*)
7635 /* Clean up a dummy stub function entry in .text. */
7636 s
= bfd_get_section_by_name (dynobj
, ".stub");
7639 file_ptr dummy_offset
;
7641 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
7642 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
7643 memset (s
->contents
+ dummy_offset
, 0,
7644 MIPS_FUNCTION_STUB_SIZE
);
7649 /* Clean up a first relocation in .rel.dyn. */
7650 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7651 if (s
!= NULL
&& s
->_raw_size
> 0)
7652 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
7658 /* This is almost identical to bfd_generic_get_... except that some
7659 MIPS relocations need to be handled specially. Sigh. */
7662 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
7663 relocateable
, symbols
)
7665 struct bfd_link_info
*link_info
;
7666 struct bfd_link_order
*link_order
;
7668 boolean relocateable
;
7671 /* Get enough memory to hold the stuff */
7672 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
7673 asection
*input_section
= link_order
->u
.indirect
.section
;
7675 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
7676 arelent
**reloc_vector
= NULL
;
7682 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
7683 if (reloc_vector
== NULL
&& reloc_size
!= 0)
7686 /* read in the section */
7687 if (!bfd_get_section_contents (input_bfd
,
7691 input_section
->_raw_size
))
7694 /* We're not relaxing the section, so just copy the size info */
7695 input_section
->_cooked_size
= input_section
->_raw_size
;
7696 input_section
->reloc_done
= true;
7698 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
7702 if (reloc_count
< 0)
7705 if (reloc_count
> 0)
7710 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
7713 struct bfd_hash_entry
*h
;
7714 struct bfd_link_hash_entry
*lh
;
7715 /* Skip all this stuff if we aren't mixing formats. */
7716 if (abfd
&& input_bfd
7717 && abfd
->xvec
== input_bfd
->xvec
)
7721 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
7722 lh
= (struct bfd_link_hash_entry
*) h
;
7729 case bfd_link_hash_undefined
:
7730 case bfd_link_hash_undefweak
:
7731 case bfd_link_hash_common
:
7734 case bfd_link_hash_defined
:
7735 case bfd_link_hash_defweak
:
7737 gp
= lh
->u
.def
.value
;
7739 case bfd_link_hash_indirect
:
7740 case bfd_link_hash_warning
:
7742 /* @@FIXME ignoring warning for now */
7744 case bfd_link_hash_new
:
7753 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
7756 char *error_message
= (char *) NULL
;
7757 bfd_reloc_status_type r
;
7759 /* Specific to MIPS: Deal with relocation types that require
7760 knowing the gp of the output bfd. */
7761 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
7762 if (bfd_is_abs_section (sym
->section
) && abfd
)
7764 /* The special_function wouldn't get called anyways. */
7768 /* The gp isn't there; let the special function code
7769 fall over on its own. */
7771 else if ((*parent
)->howto
->special_function
7772 == _bfd_mips_elf_gprel16_reloc
)
7774 /* bypass special_function call */
7775 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
7776 relocateable
, (PTR
) data
, gp
);
7777 goto skip_bfd_perform_relocation
;
7779 /* end mips specific stuff */
7781 r
= bfd_perform_relocation (input_bfd
,
7785 relocateable
? abfd
: (bfd
*) NULL
,
7787 skip_bfd_perform_relocation
:
7791 asection
*os
= input_section
->output_section
;
7793 /* A partial link, so keep the relocs */
7794 os
->orelocation
[os
->reloc_count
] = *parent
;
7798 if (r
!= bfd_reloc_ok
)
7802 case bfd_reloc_undefined
:
7803 if (!((*link_info
->callbacks
->undefined_symbol
)
7804 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7805 input_bfd
, input_section
, (*parent
)->address
)))
7808 case bfd_reloc_dangerous
:
7809 BFD_ASSERT (error_message
!= (char *) NULL
);
7810 if (!((*link_info
->callbacks
->reloc_dangerous
)
7811 (link_info
, error_message
, input_bfd
, input_section
,
7812 (*parent
)->address
)))
7815 case bfd_reloc_overflow
:
7816 if (!((*link_info
->callbacks
->reloc_overflow
)
7817 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7818 (*parent
)->howto
->name
, (*parent
)->addend
,
7819 input_bfd
, input_section
, (*parent
)->address
)))
7822 case bfd_reloc_outofrange
:
7831 if (reloc_vector
!= NULL
)
7832 free (reloc_vector
);
7836 if (reloc_vector
!= NULL
)
7837 free (reloc_vector
);
7840 #define bfd_elf32_bfd_get_relocated_section_contents \
7841 elf32_mips_get_relocated_section_contents
7843 /* ECOFF swapping routines. These are used when dealing with the
7844 .mdebug section, which is in the ECOFF debugging format. */
7845 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
7847 /* Symbol table magic number. */
7849 /* Alignment of debugging information. E.g., 4. */
7851 /* Sizes of external symbolic information. */
7852 sizeof (struct hdr_ext
),
7853 sizeof (struct dnr_ext
),
7854 sizeof (struct pdr_ext
),
7855 sizeof (struct sym_ext
),
7856 sizeof (struct opt_ext
),
7857 sizeof (struct fdr_ext
),
7858 sizeof (struct rfd_ext
),
7859 sizeof (struct ext_ext
),
7860 /* Functions to swap in external symbolic data. */
7869 _bfd_ecoff_swap_tir_in
,
7870 _bfd_ecoff_swap_rndx_in
,
7871 /* Functions to swap out external symbolic data. */
7880 _bfd_ecoff_swap_tir_out
,
7881 _bfd_ecoff_swap_rndx_out
,
7882 /* Function to read in symbolic data. */
7883 _bfd_mips_elf_read_ecoff_info
7886 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
7887 #define TARGET_LITTLE_NAME "elf32-littlemips"
7888 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
7889 #define TARGET_BIG_NAME "elf32-bigmips"
7890 #define ELF_ARCH bfd_arch_mips
7891 #define ELF_MACHINE_CODE EM_MIPS
7893 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
7894 a value of 0x1000, and we are compatible. */
7895 #define ELF_MAXPAGESIZE 0x1000
7897 #define elf_backend_collect true
7898 #define elf_backend_type_change_ok true
7899 #define elf_backend_can_gc_sections true
7900 #define elf_info_to_howto 0
7901 #define elf_info_to_howto_rel mips_info_to_howto_rel
7902 #define elf_backend_sym_is_global mips_elf_sym_is_global
7903 #define elf_backend_object_p mips_elf32_object_p
7904 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
7905 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
7906 #define elf_backend_section_from_bfd_section \
7907 _bfd_mips_elf_section_from_bfd_section
7908 #define elf_backend_section_processing mips_elf32_section_processing
7909 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
7910 #define elf_backend_additional_program_headers \
7911 mips_elf_additional_program_headers
7912 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
7913 #define elf_backend_final_write_processing \
7914 _bfd_mips_elf_final_write_processing
7915 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
7917 #define bfd_elf32_bfd_is_local_label_name \
7918 mips_elf_is_local_label_name
7919 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
7920 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
7921 #define bfd_elf32_bfd_link_hash_table_create \
7922 mips_elf_link_hash_table_create
7923 #define bfd_elf32_bfd_final_link mips_elf_final_link
7924 #define bfd_elf32_bfd_copy_private_bfd_data \
7925 _bfd_mips_elf_copy_private_bfd_data
7926 #define bfd_elf32_bfd_merge_private_bfd_data \
7927 _bfd_mips_elf_merge_private_bfd_data
7928 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
7929 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
7930 #define elf_backend_create_dynamic_sections \
7931 mips_elf_create_dynamic_sections
7932 #define elf_backend_check_relocs mips_elf_check_relocs
7933 #define elf_backend_adjust_dynamic_symbol \
7934 mips_elf_adjust_dynamic_symbol
7935 #define elf_backend_always_size_sections \
7936 mips_elf_always_size_sections
7937 #define elf_backend_size_dynamic_sections \
7938 mips_elf_size_dynamic_sections
7939 #define elf_backend_relocate_section mips_elf_relocate_section
7940 #define elf_backend_link_output_symbol_hook \
7941 mips_elf_link_output_symbol_hook
7942 #define elf_backend_finish_dynamic_symbol \
7943 mips_elf_finish_dynamic_symbol
7944 #define elf_backend_finish_dynamic_sections \
7945 mips_elf_finish_dynamic_sections
7946 #define elf_backend_gc_mark_hook mips_elf_gc_mark_hook
7947 #define elf_backend_gc_sweep_hook mips_elf_gc_sweep_hook
7949 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
7950 #define elf_backend_plt_header_size 0
7952 #include "elf32-target.h"