1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996 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 mips_elf_hi16_reloc PARAMS ((bfd *abfd,
51 static bfd_reloc_status_type mips_elf_got16_reloc PARAMS ((bfd *abfd,
58 static bfd_reloc_status_type mips_elf_lo16_reloc PARAMS ((bfd *abfd,
65 static bfd_reloc_status_type mips_elf_gprel16_reloc PARAMS ((bfd *abfd,
72 static bfd_reloc_status_type mips_elf_gprel32_reloc PARAMS ((bfd *abfd,
79 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
80 PARAMS ((bfd *, bfd_reloc_code_real_type));
81 static void mips_info_to_howto_rel
82 PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
83 static void bfd_mips_elf32_swap_gptab_in
84 PARAMS ((bfd *, const Elf32_External_gptab *, Elf32_gptab *));
85 static void bfd_mips_elf32_swap_gptab_out
86 PARAMS ((bfd *, const Elf32_gptab *, Elf32_External_gptab *));
87 static boolean mips_elf_sym_is_global PARAMS ((bfd *, asymbol *));
88 static boolean mips_elf_object_p PARAMS ((bfd *));
89 static boolean mips_elf_create_procedure_table
90 PARAMS ((PTR, bfd *, struct bfd_link_info *, asection *,
91 struct ecoff_debug_info *));
92 static int mips_elf_additional_program_headers PARAMS ((bfd *));
93 static boolean mips_elf_modify_segment_map PARAMS ((bfd *));
94 static void mips_elf_final_write_processing
95 PARAMS ((bfd *, boolean));
96 static boolean mips_elf_set_private_flags PARAMS ((bfd *, flagword));
97 static boolean mips_elf_copy_private_bfd_data PARAMS ((bfd *, bfd *));
98 static boolean mips_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
99 static boolean mips_elf_section_from_shdr
100 PARAMS ((bfd *, Elf32_Internal_Shdr *, char *));
101 static boolean mips_elf_fake_sections
102 PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *));
103 static boolean mips_elf_section_from_bfd_section
104 PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *, int *));
105 static boolean mips_elf_section_processing
106 PARAMS ((bfd *, Elf32_Internal_Shdr *));
107 static void mips_elf_symbol_processing PARAMS ((bfd *, asymbol *));
108 static boolean mips_elf_read_ecoff_info
109 PARAMS ((bfd *, asection *, struct ecoff_debug_info *));
110 static boolean mips_elf_is_local_label
111 PARAMS ((bfd *, asymbol *));
112 static boolean mips_elf_find_nearest_line
113 PARAMS ((bfd *, asection *, asymbol **, bfd_vma, const char **,
114 const char **, unsigned int *));
115 static struct bfd_hash_entry *mips_elf_link_hash_newfunc
116 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
117 static struct bfd_link_hash_table *mips_elf_link_hash_table_create
119 static int gptab_compare PARAMS ((const void *, const void *));
120 static boolean mips_elf_final_link
121 PARAMS ((bfd *, struct bfd_link_info *));
122 static void mips_elf_relocate_hi16
123 PARAMS ((bfd *, Elf_Internal_Rela *, Elf_Internal_Rela *, bfd_byte *,
125 static void mips_elf_relocate_got_local
126 PARAMS ((bfd *, bfd *, asection *, Elf_Internal_Rela *,
127 Elf_Internal_Rela *, bfd_byte *, bfd_vma));
128 static void mips_elf_relocate_global_got
129 PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
130 static boolean mips_elf_adjust_dynindx
131 PARAMS ((struct elf_link_hash_entry *, PTR));
132 static boolean mips_elf_relocate_section
133 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
134 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
135 static boolean mips_elf_create_dynamic_sections
136 PARAMS ((bfd *, struct bfd_link_info *));
137 static boolean mips_elf_create_compact_rel_section
138 PARAMS ((bfd *, struct bfd_link_info *));
139 static boolean mips_elf_create_got_section
140 PARAMS ((bfd *, struct bfd_link_info *));
141 static boolean mips_elf_check_relocs
142 PARAMS ((bfd *, struct bfd_link_info *, asection *,
143 const Elf_Internal_Rela *));
144 static boolean mips_elf_adjust_dynamic_symbol
145 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
146 static boolean mips_elf_size_dynamic_sections
147 PARAMS ((bfd *, struct bfd_link_info *));
148 static boolean mips_elf_finish_dynamic_symbol
149 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
150 Elf_Internal_Sym *));
151 static boolean mips_elf_finish_dynamic_sections
152 PARAMS ((bfd *, struct bfd_link_info *));
153 static boolean mips_elf_add_symbol_hook
154 PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
155 const char **, flagword *, asection **, bfd_vma *));
156 static bfd_reloc_status_type mips_elf_final_gp
157 PARAMS ((bfd *, asymbol *, boolean, char **));
158 static bfd_byte *elf32_mips_get_relocated_section_contents
159 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
160 bfd_byte *, boolean, asymbol **));
162 /* This is true for Irix 5 executables, false for normal MIPS ELF ABI
163 executables. FIXME: At the moment, we default to always generating
164 Irix 5 executables. */
166 #define SGI_COMPAT(abfd) (1)
168 /* This structure is used to hold .got information when linking. It
169 is stored in the tdata field of the bfd_elf_section_data structure. */
173 /* The symbol index of the first global .got symbol. */
174 unsigned long global_gotsym;
175 /* The number of local .got entries. */
176 unsigned int local_gotno;
179 /* The number of local .got entries we reserve. */
180 #define MIPS_RESERVED_GOTNO (2)
182 /* Instructions which appear in a stub. For some reason the stub is
183 slightly different on an SGI system. */
184 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
185 #define STUB_LW(abfd) \
187 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
188 : 0x8f998000) /* lw t9,0x8000(gp) */
189 #define STUB_MOVE 0x03e07825 /* move t7,ra */
190 #define STUB_JALR 0x0320f809 /* jal t9 */
191 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
192 #define MIPS_FUNCTION_STUB_SIZE (16)
194 /* Names of sections which appear in the .dynsym section in an Irix 5
197 static const char * const mips_elf_dynsym_sec_names[] =
210 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
211 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
213 /* The number of entries in mips_elf_dynsym_sec_names which go in the
216 #define MIPS_TEXT_DYNSYM_SECNO (3)
218 /* The names of the runtime procedure table symbols used on Irix 5. */
220 static const char * const mips_elf_dynsym_rtproc_names[] =
223 "_procedure_string_table",
224 "_procedure_table_size",
228 /* These structures are used to generate the .compact_rel section on
233 unsigned long id1; /* Always one? */
234 unsigned long num; /* Number of compact relocation entries. */
235 unsigned long id2; /* Always two? */
236 unsigned long offset; /* The file offset of the first relocation. */
237 unsigned long reserved0; /* Zero? */
238 unsigned long reserved1; /* Zero? */
247 bfd_byte reserved0[4];
248 bfd_byte reserved1[4];
249 } Elf32_External_compact_rel;
253 unsigned int ctype : 1; /* 1: long 0: short format. See below. */
254 unsigned int rtype : 4; /* Relocation types. See below. */
255 unsigned int dist2to : 8;
256 unsigned int relvaddr : 19; /* (VADDR - vaddr of the previous entry)/ 4 */
257 unsigned long konst; /* KONST field. See below. */
258 unsigned long vaddr; /* VADDR to be relocated. */
263 unsigned int ctype : 1; /* 1: long 0: short format. See below. */
264 unsigned int rtype : 4; /* Relocation types. See below. */
265 unsigned int dist2to : 8;
266 unsigned int relvaddr : 19; /* (VADDR - vaddr of the previous entry)/ 4 */
267 unsigned long konst; /* KONST field. See below. */
275 } Elf32_External_crinfo;
281 } Elf32_External_crinfo2;
283 /* These are the constants used to swap the bitfields in a crinfo. */
285 #define CRINFO_CTYPE (0x1)
286 #define CRINFO_CTYPE_SH (31)
287 #define CRINFO_RTYPE (0xf)
288 #define CRINFO_RTYPE_SH (27)
289 #define CRINFO_DIST2TO (0xff)
290 #define CRINFO_DIST2TO_SH (19)
291 #define CRINFO_RELVADDR (0x7ffff)
292 #define CRINFO_RELVADDR_SH (0)
294 /* A compact relocation info has long (3 words) or short (2 words)
295 formats. A short format doesn't have VADDR field and relvaddr
296 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
297 #define CRF_MIPS_LONG 1
298 #define CRF_MIPS_SHORT 0
300 /* There are 4 types of compact relocation at least. The value KONST
301 has different meaning for each type:
304 CT_MIPS_REL32 Address in data
305 CT_MIPS_WORD Address in word (XXX)
306 CT_MIPS_GPHI_LO GP - vaddr
307 CT_MIPS_JMPAD Address to jump
310 #define CRT_MIPS_REL32 0xa
311 #define CRT_MIPS_WORD 0xb
312 #define CRT_MIPS_GPHI_LO 0xc
313 #define CRT_MIPS_JMPAD 0xd
315 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
316 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
317 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
318 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
320 static void bfd_elf32_swap_compact_rel_out
321 PARAMS ((bfd *, const Elf32_compact_rel *, Elf32_External_compact_rel *));
322 static void bfd_elf32_swap_crinfo_out
323 PARAMS ((bfd *, const Elf32_crinfo *, Elf32_External_crinfo *));
325 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
330 R_MIPS_16, R_MIPS_32,
331 R_MIPS_REL32, R_MIPS_26,
332 R_MIPS_HI16, R_MIPS_LO16,
333 R_MIPS_GPREL16, R_MIPS_LITERAL,
334 R_MIPS_GOT16, R_MIPS_PC16,
335 R_MIPS_CALL16, R_MIPS_GPREL32,
336 /* The remaining relocs are defined on Irix, although they are not
337 in the MIPS ELF ABI. */
338 R_MIPS_UNUSED1, R_MIPS_UNUSED2,
340 R_MIPS_SHIFT5, R_MIPS_SHIFT6,
341 R_MIPS_64, R_MIPS_GOT_DISP,
342 R_MIPS_GOT_PAGE, R_MIPS_GOT_OFST,
343 R_MIPS_GOT_HI16, R_MIPS_GOT_LO16,
344 R_MIPS_SUB, R_MIPS_INSERT_A,
345 R_MIPS_INSERT_B, R_MIPS_DELETE,
346 R_MIPS_HIGHER, R_MIPS_HIGHEST,
347 R_MIPS_CALL_HI16, R_MIPS_CALL_LO16,
351 static reloc_howto_type elf_mips_howto_table[] =
354 HOWTO (R_MIPS_NONE, /* type */
356 0, /* size (0 = byte, 1 = short, 2 = long) */
358 false, /* pc_relative */
360 complain_overflow_dont, /* complain_on_overflow */
361 bfd_elf_generic_reloc, /* special_function */
362 "R_MIPS_NONE", /* name */
363 false, /* partial_inplace */
366 false), /* pcrel_offset */
368 /* 16 bit relocation. */
369 HOWTO (R_MIPS_16, /* type */
371 1, /* size (0 = byte, 1 = short, 2 = long) */
373 false, /* pc_relative */
375 complain_overflow_bitfield, /* complain_on_overflow */
376 bfd_elf_generic_reloc, /* special_function */
377 "R_MIPS_16", /* name */
378 true, /* partial_inplace */
379 0xffff, /* src_mask */
380 0xffff, /* dst_mask */
381 false), /* pcrel_offset */
383 /* 32 bit relocation. */
384 HOWTO (R_MIPS_32, /* type */
386 2, /* size (0 = byte, 1 = short, 2 = long) */
388 false, /* pc_relative */
390 complain_overflow_bitfield, /* complain_on_overflow */
391 bfd_elf_generic_reloc, /* special_function */
392 "R_MIPS_32", /* name */
393 true, /* partial_inplace */
394 0xffffffff, /* src_mask */
395 0xffffffff, /* dst_mask */
396 false), /* pcrel_offset */
398 /* 32 bit symbol relative relocation. */
399 HOWTO (R_MIPS_REL32, /* type */
401 2, /* size (0 = byte, 1 = short, 2 = long) */
403 false, /* pc_relative */
405 complain_overflow_bitfield, /* complain_on_overflow */
406 bfd_elf_generic_reloc, /* special_function */
407 "R_MIPS_REL32", /* name */
408 true, /* partial_inplace */
409 0xffffffff, /* src_mask */
410 0xffffffff, /* dst_mask */
411 false), /* pcrel_offset */
413 /* 26 bit branch address. */
414 HOWTO (R_MIPS_26, /* type */
416 2, /* size (0 = byte, 1 = short, 2 = long) */
418 false, /* pc_relative */
420 complain_overflow_dont, /* complain_on_overflow */
421 /* This needs complex overflow
422 detection, because the upper four
423 bits must match the PC. */
424 bfd_elf_generic_reloc, /* special_function */
425 "R_MIPS_26", /* name */
426 true, /* partial_inplace */
427 0x3ffffff, /* src_mask */
428 0x3ffffff, /* dst_mask */
429 false), /* pcrel_offset */
431 /* High 16 bits of symbol value. */
432 HOWTO (R_MIPS_HI16, /* type */
434 2, /* size (0 = byte, 1 = short, 2 = long) */
436 false, /* pc_relative */
438 complain_overflow_dont, /* complain_on_overflow */
439 mips_elf_hi16_reloc, /* special_function */
440 "R_MIPS_HI16", /* name */
441 true, /* partial_inplace */
442 0xffff, /* src_mask */
443 0xffff, /* dst_mask */
444 false), /* pcrel_offset */
446 /* Low 16 bits of symbol value. */
447 HOWTO (R_MIPS_LO16, /* type */
449 2, /* size (0 = byte, 1 = short, 2 = long) */
451 false, /* pc_relative */
453 complain_overflow_dont, /* complain_on_overflow */
454 mips_elf_lo16_reloc, /* special_function */
455 "R_MIPS_LO16", /* name */
456 true, /* partial_inplace */
457 0xffff, /* src_mask */
458 0xffff, /* dst_mask */
459 false), /* pcrel_offset */
461 /* GP relative reference. */
462 HOWTO (R_MIPS_GPREL16, /* type */
464 2, /* size (0 = byte, 1 = short, 2 = long) */
466 false, /* pc_relative */
468 complain_overflow_signed, /* complain_on_overflow */
469 mips_elf_gprel16_reloc, /* special_function */
470 "R_MIPS_GPREL16", /* name */
471 true, /* partial_inplace */
472 0xffff, /* src_mask */
473 0xffff, /* dst_mask */
474 false), /* pcrel_offset */
476 /* Reference to literal section. */
477 HOWTO (R_MIPS_LITERAL, /* type */
479 2, /* size (0 = byte, 1 = short, 2 = long) */
481 false, /* pc_relative */
483 complain_overflow_signed, /* complain_on_overflow */
484 mips_elf_gprel16_reloc, /* special_function */
485 "R_MIPS_LITERAL", /* name */
486 true, /* partial_inplace */
487 0xffff, /* src_mask */
488 0xffff, /* dst_mask */
489 false), /* pcrel_offset */
491 /* Reference to global offset table. */
492 HOWTO (R_MIPS_GOT16, /* type */
494 2, /* size (0 = byte, 1 = short, 2 = long) */
496 false, /* pc_relative */
498 complain_overflow_signed, /* complain_on_overflow */
499 mips_elf_got16_reloc, /* special_function */
500 "R_MIPS_GOT16", /* name */
501 false, /* partial_inplace */
503 0xffff, /* dst_mask */
504 false), /* pcrel_offset */
506 /* 16 bit PC relative reference. */
507 HOWTO (R_MIPS_PC16, /* type */
509 2, /* size (0 = byte, 1 = short, 2 = long) */
511 true, /* pc_relative */
513 complain_overflow_signed, /* complain_on_overflow */
514 bfd_elf_generic_reloc, /* special_function */
515 "R_MIPS_PC16", /* name */
516 true, /* partial_inplace */
517 0xffff, /* src_mask */
518 0xffff, /* dst_mask */
519 false), /* pcrel_offset */
521 /* 16 bit call through global offset table. */
522 /* FIXME: This is not handled correctly. */
523 HOWTO (R_MIPS_CALL16, /* type */
525 2, /* size (0 = byte, 1 = short, 2 = long) */
527 false, /* pc_relative */
529 complain_overflow_signed, /* complain_on_overflow */
530 bfd_elf_generic_reloc, /* special_function */
531 "R_MIPS_CALL16", /* name */
532 false, /* partial_inplace */
534 0xffff, /* dst_mask */
535 false), /* pcrel_offset */
537 /* 32 bit GP relative reference. */
538 HOWTO (R_MIPS_GPREL32, /* type */
540 2, /* size (0 = byte, 1 = short, 2 = long) */
542 false, /* pc_relative */
544 complain_overflow_bitfield, /* complain_on_overflow */
545 mips_elf_gprel32_reloc, /* special_function */
546 "R_MIPS_GPREL32", /* name */
547 true, /* partial_inplace */
548 0xffffffff, /* src_mask */
549 0xffffffff, /* dst_mask */
550 false), /* pcrel_offset */
552 /* The remaining relocs are defined on Irix 5, although they are
553 not defined by the ABI. */
558 /* A 5 bit shift field. */
559 HOWTO (R_MIPS_SHIFT5, /* type */
561 2, /* size (0 = byte, 1 = short, 2 = long) */
563 false, /* pc_relative */
565 complain_overflow_bitfield, /* complain_on_overflow */
566 bfd_elf_generic_reloc, /* special_function */
567 "R_MIPS_SHIFT5", /* name */
568 true, /* partial_inplace */
569 0x000007c0, /* src_mask */
570 0x000007c0, /* dst_mask */
571 false), /* pcrel_offset */
573 /* A 6 bit shift field. */
574 /* FIXME: This is not handled correctly; a special function is
575 needed to put the most significant bit in the right place. */
576 HOWTO (R_MIPS_SHIFT6, /* type */
578 2, /* size (0 = byte, 1 = short, 2 = long) */
580 false, /* pc_relative */
582 complain_overflow_bitfield, /* complain_on_overflow */
583 bfd_elf_generic_reloc, /* special_function */
584 "R_MIPS_SHIFT6", /* name */
585 true, /* partial_inplace */
586 0x000007c4, /* src_mask */
587 0x000007c4, /* dst_mask */
588 false), /* pcrel_offset */
590 /* A 64 bit relocation. Presumably not used in 32 bit ELF. */
593 /* Displacement in the global offset table. */
594 /* FIXME: Not handled correctly. */
595 HOWTO (R_MIPS_GOT_DISP, /* type */
597 2, /* size (0 = byte, 1 = short, 2 = long) */
599 false, /* pc_relative */
601 complain_overflow_bitfield, /* complain_on_overflow */
602 bfd_elf_generic_reloc, /* special_function */
603 "R_MIPS_GOT_DISP", /* name */
604 true, /* partial_inplace */
605 0x0000ffff, /* src_mask */
606 0x0000ffff, /* dst_mask */
607 false), /* pcrel_offset */
609 /* Displacement to page pointer in the global offset table. */
610 /* FIXME: Not handled correctly. */
611 HOWTO (R_MIPS_GOT_PAGE, /* type */
613 2, /* size (0 = byte, 1 = short, 2 = long) */
615 false, /* pc_relative */
617 complain_overflow_bitfield, /* complain_on_overflow */
618 bfd_elf_generic_reloc, /* special_function */
619 "R_MIPS_GOT_PAGE", /* name */
620 true, /* partial_inplace */
621 0x0000ffff, /* src_mask */
622 0x0000ffff, /* dst_mask */
623 false), /* pcrel_offset */
625 /* Offset from page pointer in the global offset table. */
626 /* FIXME: Not handled correctly. */
627 HOWTO (R_MIPS_GOT_OFST, /* type */
629 2, /* size (0 = byte, 1 = short, 2 = long) */
631 false, /* pc_relative */
633 complain_overflow_bitfield, /* complain_on_overflow */
634 bfd_elf_generic_reloc, /* special_function */
635 "R_MIPS_GOT_OFST", /* name */
636 true, /* partial_inplace */
637 0x0000ffff, /* src_mask */
638 0x0000ffff, /* dst_mask */
639 false), /* pcrel_offset */
641 /* High 16 bits of displacement in global offset table. */
642 /* FIXME: Not handled correctly. */
643 HOWTO (R_MIPS_GOT_HI16, /* type */
645 2, /* size (0 = byte, 1 = short, 2 = long) */
647 false, /* pc_relative */
649 complain_overflow_dont, /* complain_on_overflow */
650 bfd_elf_generic_reloc, /* special_function */
651 "R_MIPS_GOT_HI16", /* name */
652 true, /* partial_inplace */
653 0x0000ffff, /* src_mask */
654 0x0000ffff, /* dst_mask */
655 false), /* pcrel_offset */
657 /* Low 16 bits of displacement in global offset table. */
658 /* FIXME: Not handled correctly. */
659 HOWTO (R_MIPS_GOT_LO16, /* type */
661 2, /* size (0 = byte, 1 = short, 2 = long) */
663 false, /* pc_relative */
665 complain_overflow_dont, /* complain_on_overflow */
666 bfd_elf_generic_reloc, /* special_function */
667 "R_MIPS_GOT_LO16", /* name */
668 true, /* partial_inplace */
669 0x0000ffff, /* src_mask */
670 0x0000ffff, /* dst_mask */
671 false), /* pcrel_offset */
673 /* 64 bit subtraction. Presumably not used in 32 bit ELF. */
676 /* Used to cause the linker to insert and delete instructions? */
681 /* Get the higher values of a 64 bit addend. Presumably not used in
686 /* High 16 bits of displacement in global offset table. */
687 /* FIXME: Not handled correctly. */
688 HOWTO (R_MIPS_CALL_HI16, /* type */
690 2, /* size (0 = byte, 1 = short, 2 = long) */
692 false, /* pc_relative */
694 complain_overflow_dont, /* complain_on_overflow */
695 bfd_elf_generic_reloc, /* special_function */
696 "R_MIPS_CALL_HI16", /* name */
697 true, /* partial_inplace */
698 0x0000ffff, /* src_mask */
699 0x0000ffff, /* dst_mask */
700 false), /* pcrel_offset */
702 /* Low 16 bits of displacement in global offset table. */
703 /* FIXME: Not handled correctly. */
704 HOWTO (R_MIPS_CALL_LO16, /* type */
706 2, /* size (0 = byte, 1 = short, 2 = long) */
708 false, /* pc_relative */
710 complain_overflow_dont, /* complain_on_overflow */
711 bfd_elf_generic_reloc, /* special_function */
712 "R_MIPS_CALL_LO16", /* name */
713 true, /* partial_inplace */
714 0x0000ffff, /* src_mask */
715 0x0000ffff, /* dst_mask */
716 false) /* pcrel_offset */
719 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
720 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
721 the HI16. Here we just save the information we need; we do the
722 actual relocation when we see the LO16. MIPS ELF requires that the
723 LO16 immediately follow the HI16, so this ought to work. */
725 static bfd_byte *mips_hi16_addr;
726 static bfd_vma mips_hi16_addend;
728 static bfd_reloc_status_type
729 mips_elf_hi16_reloc (abfd,
737 arelent *reloc_entry;
740 asection *input_section;
742 char **error_message;
744 bfd_reloc_status_type ret;
747 /* If we're relocating, and this an external symbol, we don't want
748 to change anything. */
749 if (output_bfd != (bfd *) NULL
750 && (symbol->flags & BSF_SECTION_SYM) == 0
751 && reloc_entry->addend == 0)
753 reloc_entry->address += input_section->output_offset;
759 if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
761 boolean relocateable;
763 if (ret == bfd_reloc_undefined)
766 if (output_bfd != NULL)
770 relocateable = false;
771 output_bfd = symbol->section->output_section->owner;
774 ret = mips_elf_final_gp (output_bfd, symbol, relocateable,
776 if (ret != bfd_reloc_ok)
779 relocation = _bfd_get_gp_value (output_bfd) - reloc_entry->address;
783 if (bfd_is_und_section (symbol->section)
784 && output_bfd == (bfd *) NULL)
785 ret = bfd_reloc_undefined;
787 if (bfd_is_com_section (symbol->section))
790 relocation = symbol->value;
793 relocation += symbol->section->output_section->vma;
794 relocation += symbol->section->output_offset;
795 relocation += reloc_entry->addend;
797 if (reloc_entry->address > input_section->_cooked_size)
798 return bfd_reloc_outofrange;
800 /* Save the information, and let LO16 do the actual relocation. */
801 mips_hi16_addr = (bfd_byte *) data + reloc_entry->address;
802 mips_hi16_addend = relocation;
804 if (output_bfd != (bfd *) NULL)
805 reloc_entry->address += input_section->output_offset;
810 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
811 inplace relocation; this function exists in order to do the
812 R_MIPS_HI16 relocation described above. */
814 static bfd_reloc_status_type
815 mips_elf_lo16_reloc (abfd,
823 arelent *reloc_entry;
826 asection *input_section;
828 char **error_message;
830 arelent gp_disp_relent;
832 if (mips_hi16_addr != (bfd_byte *) NULL)
838 /* Do the HI16 relocation. Note that we actually don't need to
839 know anything about the LO16 itself, except where to find the
840 low 16 bits of the addend needed by the LO16. */
841 insn = bfd_get_32 (abfd, mips_hi16_addr);
842 vallo = (bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address)
844 val = ((insn & 0xffff) << 16) + vallo;
845 val += mips_hi16_addend;
847 /* The low order 16 bits are always treated as a signed value.
848 Therefore, a negative value in the low order bits requires an
849 adjustment in the high order bits. We need to make this
850 adjustment in two ways: once for the bits we took from the
851 data, and once for the bits we are putting back in to the
853 if ((vallo & 0x8000) != 0)
855 if ((val & 0x8000) != 0)
858 insn = (insn &~ 0xffff) | ((val >> 16) & 0xffff);
859 bfd_put_32 (abfd, insn, mips_hi16_addr);
861 mips_hi16_addr = (bfd_byte *) NULL;
863 if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
865 gp_disp_relent = *reloc_entry;
866 reloc_entry = &gp_disp_relent;
867 reloc_entry->addend = mips_hi16_addend;
870 else if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
872 bfd_reloc_status_type ret;
875 /* FIXME: Does this case ever occur? */
877 ret = mips_elf_final_gp (output_bfd, symbol, true, error_message);
878 if (ret != bfd_reloc_ok)
881 relocation = _bfd_get_gp_value (output_bfd) - reloc_entry->address;
882 relocation += symbol->section->output_section->vma;
883 relocation += symbol->section->output_offset;
884 relocation += reloc_entry->addend;
886 if (reloc_entry->address > input_section->_cooked_size)
887 return bfd_reloc_outofrange;
889 gp_disp_relent = *reloc_entry;
890 reloc_entry = &gp_disp_relent;
891 reloc_entry->addend = relocation - 4;
894 /* Now do the LO16 reloc in the usual way. */
895 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
896 input_section, output_bfd, error_message);
899 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
900 table used for PIC code. If the symbol is an external symbol, the
901 instruction is modified to contain the offset of the appropriate
902 entry in the global offset table. If the symbol is a section
903 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
904 addends are combined to form the real addend against the section
905 symbol; the GOT16 is modified to contain the offset of an entry in
906 the global offset table, and the LO16 is modified to offset it
907 appropriately. Thus an offset larger than 16 bits requires a
908 modified value in the global offset table.
910 This implementation suffices for the assembler, but the linker does
911 not yet know how to create global offset tables. */
913 static bfd_reloc_status_type
914 mips_elf_got16_reloc (abfd,
922 arelent *reloc_entry;
925 asection *input_section;
927 char **error_message;
929 /* If we're relocating, and this an external symbol, we don't want
930 to change anything. */
931 if (output_bfd != (bfd *) NULL
932 && (symbol->flags & BSF_SECTION_SYM) == 0
933 && reloc_entry->addend == 0)
935 reloc_entry->address += input_section->output_offset;
939 /* If we're relocating, and this is a local symbol, we can handle it
941 if (output_bfd != (bfd *) NULL
942 && (symbol->flags & BSF_SECTION_SYM) != 0)
943 return mips_elf_hi16_reloc (abfd, reloc_entry, symbol, data,
944 input_section, output_bfd, error_message);
949 /* We have to figure out the gp value, so that we can adjust the
950 symbol value correctly. We look up the symbol _gp in the output
951 BFD. If we can't find it, we're stuck. We cache it in the ELF
952 target data. We don't need to adjust the symbol value for an
953 external symbol if we are producing relocateable output. */
955 static bfd_reloc_status_type
956 mips_elf_final_gp (output_bfd, symbol, relocateable, error_message)
959 boolean relocateable;
960 char **error_message;
962 if (bfd_is_und_section (symbol->section)
964 return bfd_reloc_undefined;
966 /* This doesn't work if the BFD is not ELF. */
967 if (output_bfd->xvec->flavour != bfd_target_elf_flavour)
970 if (_bfd_get_gp_value (output_bfd) == 0
972 || (symbol->flags & BSF_SECTION_SYM) != 0))
976 /* Make up a value. */
977 _bfd_set_gp_value (output_bfd,
978 symbol->section->output_section->vma + 0x4000);
986 count = bfd_get_symcount (output_bfd);
987 sym = bfd_get_outsymbols (output_bfd);
989 if (sym == (asymbol **) NULL)
993 for (i = 0; i < count; i++, sym++)
995 register CONST char *name;
997 name = bfd_asymbol_name (*sym);
998 if (*name == '_' && strcmp (name, "_gp") == 0)
1000 _bfd_set_gp_value (output_bfd, bfd_asymbol_value (*sym));
1008 /* Only get the error once. */
1009 _bfd_set_gp_value (output_bfd, 4);
1011 (char *) "GP relative relocation when _gp not defined";
1012 return bfd_reloc_dangerous;
1017 return bfd_reloc_ok;
1020 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1021 become the offset from the gp register. This function also handles
1022 R_MIPS_LITERAL relocations, although those can be handled more
1023 cleverly because the entries in the .lit8 and .lit4 sections can be
1026 static bfd_reloc_status_type gprel16_with_gp PARAMS ((bfd *, asymbol *,
1027 arelent *, asection *,
1028 boolean, PTR, bfd_vma));
1030 static bfd_reloc_status_type
1031 mips_elf_gprel16_reloc (abfd,
1039 arelent *reloc_entry;
1042 asection *input_section;
1044 char **error_message;
1046 boolean relocateable;
1047 bfd_reloc_status_type ret;
1049 /* If we're relocating, and this is an external symbol with no
1050 addend, we don't want to change anything. We will only have an
1051 addend if this is a newly created reloc, not read from an ELF
1053 if (output_bfd != (bfd *) NULL
1054 && (symbol->flags & BSF_SECTION_SYM) == 0
1055 && reloc_entry->addend == 0)
1057 reloc_entry->address += input_section->output_offset;
1058 return bfd_reloc_ok;
1061 if (output_bfd != (bfd *) NULL)
1062 relocateable = true;
1065 relocateable = false;
1066 output_bfd = symbol->section->output_section->owner;
1069 ret = mips_elf_final_gp (output_bfd, symbol, relocateable, error_message);
1070 if (ret != bfd_reloc_ok)
1073 return gprel16_with_gp (abfd, symbol, reloc_entry, input_section,
1075 _bfd_get_gp_value (output_bfd));
1078 static bfd_reloc_status_type
1079 gprel16_with_gp (abfd, symbol, reloc_entry, input_section, relocateable, data,
1083 arelent *reloc_entry;
1084 asection *input_section;
1085 boolean relocateable;
1093 if (bfd_is_com_section (symbol->section))
1096 relocation = symbol->value;
1098 relocation += symbol->section->output_section->vma;
1099 relocation += symbol->section->output_offset;
1101 if (reloc_entry->address > input_section->_cooked_size)
1102 return bfd_reloc_outofrange;
1104 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1106 /* Set val to the offset into the section or symbol. */
1107 val = ((insn & 0xffff) + reloc_entry->addend) & 0xffff;
1111 /* Adjust val for the final section location and GP value. If we
1112 are producing relocateable output, we don't want to do this for
1113 an external symbol. */
1115 || (symbol->flags & BSF_SECTION_SYM) != 0)
1116 val += relocation - gp;
1118 insn = (insn &~ 0xffff) | (val & 0xffff);
1119 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
1122 reloc_entry->address += input_section->output_offset;
1124 /* Make sure it fit in 16 bits. */
1125 if (val >= 0x8000 && val < 0xffff8000)
1126 return bfd_reloc_overflow;
1128 return bfd_reloc_ok;
1131 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1132 from the gp register? XXX */
1134 static bfd_reloc_status_type gprel32_with_gp PARAMS ((bfd *, asymbol *,
1135 arelent *, asection *,
1136 boolean, PTR, bfd_vma));
1138 static bfd_reloc_status_type
1139 mips_elf_gprel32_reloc (abfd,
1147 arelent *reloc_entry;
1150 asection *input_section;
1152 char **error_message;
1154 boolean relocateable;
1155 bfd_reloc_status_type ret;
1157 /* If we're relocating, and this is an external symbol with no
1158 addend, we don't want to change anything. We will only have an
1159 addend if this is a newly created reloc, not read from an ELF
1161 if (output_bfd != (bfd *) NULL
1162 && (symbol->flags & BSF_SECTION_SYM) == 0
1163 && reloc_entry->addend == 0)
1165 *error_message = (char *)
1166 "32bits gp relative relocation occurs for an external symbol";
1167 return bfd_reloc_outofrange;
1170 if (output_bfd != (bfd *) NULL)
1171 relocateable = true;
1174 relocateable = false;
1175 output_bfd = symbol->section->output_section->owner;
1177 ret = mips_elf_final_gp (output_bfd, symbol, relocateable,
1179 if (ret != bfd_reloc_ok)
1183 return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
1185 _bfd_get_gp_value (output_bfd));
1188 static bfd_reloc_status_type
1189 gprel32_with_gp (abfd, symbol, reloc_entry, input_section, relocateable, data,
1193 arelent *reloc_entry;
1194 asection *input_section;
1195 boolean relocateable;
1202 if (bfd_is_com_section (symbol->section))
1205 relocation = symbol->value;
1207 relocation += symbol->section->output_section->vma;
1208 relocation += symbol->section->output_offset;
1210 if (reloc_entry->address > input_section->_cooked_size)
1211 return bfd_reloc_outofrange;
1213 val = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1215 /* Set val to the offset into the section or symbol. */
1216 val += reloc_entry->addend;
1218 /* Adjust val for the final section location and GP value. If we
1219 are producing relocateable output, we don't want to do this for
1220 an external symbol. */
1222 || (symbol->flags & BSF_SECTION_SYM) != 0)
1223 val += relocation - gp;
1225 bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);
1228 reloc_entry->address += input_section->output_offset;
1230 return bfd_reloc_ok;
1233 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1235 struct elf_reloc_map {
1236 bfd_reloc_code_real_type bfd_reloc_val;
1237 enum reloc_type elf_reloc_val;
1240 static CONST struct elf_reloc_map mips_reloc_map[] =
1242 { BFD_RELOC_NONE, R_MIPS_NONE, },
1243 { BFD_RELOC_16, R_MIPS_16 },
1244 { BFD_RELOC_32, R_MIPS_32 },
1245 { BFD_RELOC_CTOR, R_MIPS_32 },
1246 { BFD_RELOC_32_PCREL, R_MIPS_REL32 },
1247 { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
1248 { BFD_RELOC_HI16_S, R_MIPS_HI16 },
1249 { BFD_RELOC_LO16, R_MIPS_LO16 },
1250 { BFD_RELOC_MIPS_GPREL, R_MIPS_GPREL16 },
1251 { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
1252 { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
1253 { BFD_RELOC_16_PCREL, R_MIPS_PC16 },
1254 { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
1255 { BFD_RELOC_MIPS_GPREL32, R_MIPS_GPREL32 },
1256 { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
1257 { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 },
1258 { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 },
1259 { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 }
1262 /* Given a BFD reloc type, return a howto structure. */
1264 static reloc_howto_type *
1265 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
1267 bfd_reloc_code_real_type code;
1271 for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map); i++)
1273 if (mips_reloc_map[i].bfd_reloc_val == code)
1274 return &elf_mips_howto_table[(int) mips_reloc_map[i].elf_reloc_val];
1279 /* Given a MIPS reloc type, fill in an arelent structure. */
1282 mips_info_to_howto_rel (abfd, cache_ptr, dst)
1285 Elf32_Internal_Rel *dst;
1287 unsigned int r_type;
1289 r_type = ELF32_R_TYPE (dst->r_info);
1290 BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
1291 cache_ptr->howto = &elf_mips_howto_table[r_type];
1293 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1294 value for the object file. We get the addend now, rather than
1295 when we do the relocation, because the symbol manipulations done
1296 by the linker may cause us to lose track of the input BFD. */
1297 if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
1298 && (r_type == (unsigned int) R_MIPS_GPREL16
1299 || r_type == (unsigned int) R_MIPS_LITERAL))
1300 cache_ptr->addend = elf_gp (abfd);
1303 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1304 routines swap this structure in and out. They are used outside of
1305 BFD, so they are globally visible. */
1308 bfd_mips_elf32_swap_reginfo_in (abfd, ex, in)
1310 const Elf32_External_RegInfo *ex;
1313 in->ri_gprmask = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_gprmask);
1314 in->ri_cprmask[0] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[0]);
1315 in->ri_cprmask[1] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[1]);
1316 in->ri_cprmask[2] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[2]);
1317 in->ri_cprmask[3] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[3]);
1318 in->ri_gp_value = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_gp_value);
1322 bfd_mips_elf32_swap_reginfo_out (abfd, in, ex)
1324 const Elf32_RegInfo *in;
1325 Elf32_External_RegInfo *ex;
1327 bfd_h_put_32 (abfd, (bfd_vma) in->ri_gprmask,
1328 (bfd_byte *) ex->ri_gprmask);
1329 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[0],
1330 (bfd_byte *) ex->ri_cprmask[0]);
1331 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[1],
1332 (bfd_byte *) ex->ri_cprmask[1]);
1333 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[2],
1334 (bfd_byte *) ex->ri_cprmask[2]);
1335 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[3],
1336 (bfd_byte *) ex->ri_cprmask[3]);
1337 bfd_h_put_32 (abfd, (bfd_vma) in->ri_gp_value,
1338 (bfd_byte *) ex->ri_gp_value);
1341 /* Swap an entry in a .gptab section. Note that these routines rely
1342 on the equivalence of the two elements of the union. */
1345 bfd_mips_elf32_swap_gptab_in (abfd, ex, in)
1347 const Elf32_External_gptab *ex;
1350 in->gt_entry.gt_g_value = bfd_h_get_32 (abfd, ex->gt_entry.gt_g_value);
1351 in->gt_entry.gt_bytes = bfd_h_get_32 (abfd, ex->gt_entry.gt_bytes);
1355 bfd_mips_elf32_swap_gptab_out (abfd, in, ex)
1357 const Elf32_gptab *in;
1358 Elf32_External_gptab *ex;
1360 bfd_h_put_32 (abfd, (bfd_vma) in->gt_entry.gt_g_value,
1361 ex->gt_entry.gt_g_value);
1362 bfd_h_put_32 (abfd, (bfd_vma) in->gt_entry.gt_bytes,
1363 ex->gt_entry.gt_bytes);
1367 bfd_elf32_swap_compact_rel_out (abfd, in, ex)
1369 const Elf32_compact_rel *in;
1370 Elf32_External_compact_rel *ex;
1372 bfd_h_put_32 (abfd, (bfd_vma) in->id1, ex->id1);
1373 bfd_h_put_32 (abfd, (bfd_vma) in->num, ex->num);
1374 bfd_h_put_32 (abfd, (bfd_vma) in->id2, ex->id2);
1375 bfd_h_put_32 (abfd, (bfd_vma) in->offset, ex->offset);
1376 bfd_h_put_32 (abfd, (bfd_vma) in->reserved0, ex->reserved0);
1377 bfd_h_put_32 (abfd, (bfd_vma) in->reserved1, ex->reserved1);
1381 bfd_elf32_swap_crinfo_out (abfd, in, ex)
1383 const Elf32_crinfo *in;
1384 Elf32_External_crinfo *ex;
1388 l = (((in->ctype & CRINFO_CTYPE) << CRINFO_CTYPE_SH)
1389 | ((in->rtype & CRINFO_RTYPE) << CRINFO_RTYPE_SH)
1390 | ((in->dist2to & CRINFO_DIST2TO) << CRINFO_DIST2TO_SH)
1391 | ((in->relvaddr & CRINFO_RELVADDR) << CRINFO_RELVADDR_SH));
1392 bfd_h_put_32 (abfd, (bfd_vma) l, ex->info);
1393 bfd_h_put_32 (abfd, (bfd_vma) in->konst, ex->konst);
1394 bfd_h_put_32 (abfd, (bfd_vma) in->vaddr, ex->vaddr);
1397 /* Determine whether a symbol is global for the purposes of splitting
1398 the symbol table into global symbols and local symbols. At least
1399 on Irix 5, this split must be between section symbols and all other
1400 symbols. On most ELF targets the split is between static symbols
1401 and externally visible symbols. */
1405 mips_elf_sym_is_global (abfd, sym)
1409 return (sym->flags & BSF_SECTION_SYM) == 0 ? true : false;
1412 /* Set the right machine number for a MIPS ELF file. */
1415 mips_elf_object_p (abfd)
1418 switch (elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH)
1422 /* Just use the default, which was set in elfcode.h. */
1426 (void) bfd_default_set_arch_mach (abfd, bfd_arch_mips, 6000);
1430 (void) bfd_default_set_arch_mach (abfd, bfd_arch_mips, 4000);
1434 /* Irix 5 is broken. Object file symbol tables are not always
1435 sorted correctly such that local symbols precede global symbols,
1436 and the sh_info field in the symbol table is not always right. */
1437 elf_bad_symtab (abfd) = true;
1442 /* The final processing done just before writing out a MIPS ELF object
1443 file. This gets the MIPS architecture right based on the machine
1448 mips_elf_final_write_processing (abfd, linker)
1454 Elf_Internal_Shdr **hdrpp;
1456 switch (bfd_get_mach (abfd))
1459 val = E_MIPS_ARCH_1;
1463 val = E_MIPS_ARCH_2;
1467 val = E_MIPS_ARCH_3;
1475 elf_elfheader (abfd)->e_flags &=~ EF_MIPS_ARCH;
1476 elf_elfheader (abfd)->e_flags |= val;
1478 /* Set the sh_info field for .gptab sections. */
1479 for (i = 1, hdrpp = elf_elfsections (abfd) + 1;
1480 i < elf_elfheader (abfd)->e_shnum;
1483 if ((*hdrpp)->sh_type == SHT_MIPS_GPTAB)
1488 BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
1489 name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section);
1490 BFD_ASSERT (name != NULL
1491 && strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0);
1492 sec = bfd_get_section_by_name (abfd, name + sizeof ".gptab" - 1);
1493 BFD_ASSERT (sec != NULL);
1494 (*hdrpp)->sh_info = elf_section_data (sec)->this_idx;
1499 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
1502 mips_elf_set_private_flags (abfd, flags)
1506 BFD_ASSERT (!elf_flags_init (abfd)
1507 || elf_elfheader (abfd)->e_flags == flags);
1509 elf_elfheader (abfd)->e_flags = flags;
1510 elf_flags_init (abfd) = true;
1514 /* Copy backend specific data from one object module to another */
1517 mips_elf_copy_private_bfd_data (ibfd, obfd)
1521 /* This function is selected based on the input vector. We only
1522 want to copy information over if the output BFD also uses Elf
1524 if (bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1527 BFD_ASSERT (!elf_flags_init (obfd)
1528 || (elf_elfheader (obfd)->e_flags
1529 == elf_elfheader (ibfd)->e_flags));
1531 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
1532 elf_flags_init (obfd) = true;
1536 /* Merge backend specific data from an object file to the output
1537 object file when linking. */
1540 mips_elf_merge_private_bfd_data (ibfd, obfd)
1547 /* Check if we have the same endianess */
1548 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
1549 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
1551 (*_bfd_error_handler)
1552 ("%s: compiled for a %s endian system and target is %s endian",
1553 bfd_get_filename (ibfd),
1554 bfd_big_endian (ibfd) ? "big" : "little",
1555 bfd_big_endian (obfd) ? "big" : "little");
1557 bfd_set_error (bfd_error_wrong_format);
1561 /* This function is selected based on the input vector. We only
1562 want to copy information over if the output BFD also uses Elf
1564 if (bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1567 new_flags = elf_elfheader (ibfd)->e_flags;
1568 elf_elfheader (obfd)->e_flags |= new_flags & EF_MIPS_NOREORDER;
1569 old_flags = elf_elfheader (obfd)->e_flags;
1571 if (!elf_flags_init (obfd)) /* First call, no flags set */
1573 elf_flags_init (obfd) = true;
1574 elf_elfheader (obfd)->e_flags = new_flags;
1576 else if (((new_flags ^ old_flags) & ~EF_MIPS_NOREORDER)
1577 == 0) /* Compatible flags are ok */
1579 else /* Incompatible flags */
1581 /* Warn about -fPIC mismatch */
1582 if ((new_flags & EF_MIPS_PIC) != (old_flags & EF_MIPS_PIC))
1584 new_flags &= ~EF_MIPS_PIC;
1585 (*_bfd_error_handler)
1586 ("%s: needs all files compiled with -fPIC",
1587 bfd_get_filename (ibfd));
1590 if ((new_flags & EF_MIPS_CPIC) != (old_flags & EF_MIPS_CPIC))
1592 new_flags &= ~EF_MIPS_CPIC;
1593 (*_bfd_error_handler)
1594 ("%s: needs all files compiled with -mabicalls",
1595 bfd_get_filename (ibfd));
1598 /* Warn about any other mismatches */
1599 if (new_flags != old_flags)
1600 (*_bfd_error_handler)
1601 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1602 bfd_get_filename (ibfd), (unsigned long) new_flags,
1603 (unsigned long) old_flags);
1605 bfd_set_error (bfd_error_bad_value);
1612 /* Handle a MIPS specific section when reading an object file. This
1613 is called when elfcode.h finds a section with an unknown type.
1614 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
1618 mips_elf_section_from_shdr (abfd, hdr, name)
1620 Elf32_Internal_Shdr *hdr;
1625 /* There ought to be a place to keep ELF backend specific flags, but
1626 at the moment there isn't one. We just keep track of the
1627 sections by their name, instead. Fortunately, the ABI gives
1628 suggested names for all the MIPS specific sections, so we will
1629 probably get away with this. */
1630 switch (hdr->sh_type)
1632 case SHT_MIPS_LIBLIST:
1633 if (strcmp (name, ".liblist") != 0)
1637 if (strcmp (name, ".msym") != 0)
1640 case SHT_MIPS_CONFLICT:
1641 if (strcmp (name, ".conflict") != 0)
1644 case SHT_MIPS_GPTAB:
1645 if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) != 0)
1648 case SHT_MIPS_UCODE:
1649 if (strcmp (name, ".ucode") != 0)
1652 case SHT_MIPS_DEBUG:
1653 if (strcmp (name, ".mdebug") != 0)
1656 case SHT_MIPS_REGINFO:
1657 if (strcmp (name, ".reginfo") != 0
1658 || hdr->sh_size != sizeof (Elf32_External_RegInfo))
1661 case SHT_MIPS_OPTIONS:
1662 if (strcmp (name, ".options") != 0)
1665 case SHT_MIPS_DWARF:
1666 if (strncmp (name, ".debug_", sizeof ".debug_" - 1) != 0)
1669 case SHT_MIPS_EVENTS:
1670 if (strncmp (name, ".MIPS.events.", sizeof ".MIPS.events." - 1) != 0)
1677 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
1679 newsect = hdr->bfd_section;
1681 if (hdr->sh_type == SHT_MIPS_DEBUG)
1683 if (! bfd_set_section_flags (abfd, newsect,
1684 (bfd_get_section_flags (abfd, newsect)
1689 /* FIXME: We should record sh_info for a .gptab section. */
1691 /* For a .reginfo section, set the gp value in the tdata information
1692 from the contents of this section. We need the gp value while
1693 processing relocs, so we just get it now. */
1694 if (hdr->sh_type == SHT_MIPS_REGINFO)
1696 Elf32_External_RegInfo ext;
1699 if (! bfd_get_section_contents (abfd, newsect, (PTR) &ext,
1700 (file_ptr) 0, sizeof ext))
1702 bfd_mips_elf32_swap_reginfo_in (abfd, &ext, &s);
1703 elf_gp (abfd) = s.ri_gp_value;
1709 /* Set the correct type for a MIPS ELF section. We do this by the
1710 section name, which is a hack, but ought to work. */
1713 mips_elf_fake_sections (abfd, hdr, sec)
1715 Elf32_Internal_Shdr *hdr;
1718 register const char *name;
1720 name = bfd_get_section_name (abfd, sec);
1722 if (strcmp (name, ".liblist") == 0)
1724 hdr->sh_type = SHT_MIPS_LIBLIST;
1725 hdr->sh_info = sec->_raw_size / sizeof (Elf32_Lib);
1726 /* FIXME: Set the sh_link field. */
1728 else if (strcmp (name, ".msym") == 0)
1730 hdr->sh_type = SHT_MIPS_MSYM;
1731 hdr->sh_entsize = 8;
1732 /* FIXME: Set the sh_info field. */
1734 else if (strcmp (name, ".conflict") == 0)
1735 hdr->sh_type = SHT_MIPS_CONFLICT;
1736 else if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0)
1738 hdr->sh_type = SHT_MIPS_GPTAB;
1739 hdr->sh_entsize = sizeof (Elf32_External_gptab);
1740 /* The sh_info field is set in mips_elf_final_write_processing. */
1742 else if (strcmp (name, ".ucode") == 0)
1743 hdr->sh_type = SHT_MIPS_UCODE;
1744 else if (strcmp (name, ".mdebug") == 0)
1746 hdr->sh_type = SHT_MIPS_DEBUG;
1747 /* In a shared object on Irix 5.3, the .mdebug section has an
1748 entsize of 0. FIXME: Does this matter? */
1749 if (SGI_COMPAT (abfd) && (abfd->flags & DYNAMIC) != 0)
1750 hdr->sh_entsize = 0;
1752 hdr->sh_entsize = 1;
1754 else if (strcmp (name, ".reginfo") == 0)
1756 hdr->sh_type = SHT_MIPS_REGINFO;
1757 /* In a shared object on Irix 5.3, the .reginfo section has an
1758 entsize of 0x18. FIXME: Does this matter? */
1759 if (SGI_COMPAT (abfd) && (abfd->flags & DYNAMIC) != 0)
1760 hdr->sh_entsize = sizeof (Elf32_External_RegInfo);
1762 hdr->sh_entsize = 1;
1764 /* Force the section size to the correct value, even if the
1765 linker thinks it is larger. The link routine below will only
1766 write out this much data for .reginfo. */
1767 hdr->sh_size = sec->_raw_size = sizeof (Elf32_External_RegInfo);
1769 else if (SGI_COMPAT (abfd)
1770 && (strcmp (name, ".hash") == 0
1771 || strcmp (name, ".dynamic") == 0
1772 || strcmp (name, ".dynstr") == 0))
1774 hdr->sh_entsize = 0;
1775 hdr->sh_info = SIZEOF_MIPS_DYNSYM_SECNAMES;
1777 else if (strcmp (name, ".got") == 0
1778 || strcmp (name, ".sdata") == 0
1779 || strcmp (name, ".sbss") == 0
1780 || strcmp (name, ".lit4") == 0
1781 || strcmp (name, ".lit8") == 0)
1782 hdr->sh_flags |= SHF_MIPS_GPREL;
1783 else if (strcmp (name, ".options") == 0)
1785 hdr->sh_type = SHT_MIPS_OPTIONS;
1786 hdr->sh_entsize = 1;
1788 else if (strncmp (name, ".debug_", sizeof ".debug_" - 1) == 0)
1789 hdr->sh_type = SHT_MIPS_DWARF;
1790 else if (strncmp (name, ".MIPS.events.", sizeof ".MIPS.events." - 1) == 0)
1791 hdr->sh_type = SHT_MIPS_EVENTS;
1796 /* Given a BFD section, try to locate the corresponding ELF section
1800 mips_elf_section_from_bfd_section (abfd, hdr, sec, retval)
1802 Elf32_Internal_Shdr *hdr;
1806 if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)
1808 *retval = SHN_MIPS_SCOMMON;
1811 if (strcmp (bfd_get_section_name (abfd, sec), ".acommon") == 0)
1813 *retval = SHN_MIPS_ACOMMON;
1819 /* Work over a section just before writing it out. We update the GP
1820 value in the .reginfo section based on the value we are using.
1821 FIXME: We recognize sections that need the SHF_MIPS_GPREL flag by
1822 name; there has to be a better way. */
1825 mips_elf_section_processing (abfd, hdr)
1827 Elf32_Internal_Shdr *hdr;
1829 if (hdr->sh_type == SHT_MIPS_REGINFO)
1833 BFD_ASSERT (hdr->sh_size == sizeof (Elf32_External_RegInfo));
1834 BFD_ASSERT (hdr->contents == NULL);
1837 hdr->sh_offset + sizeof (Elf32_External_RegInfo) - 4,
1840 bfd_h_put_32 (abfd, (bfd_vma) elf_gp (abfd), buf);
1841 if (bfd_write (buf, (bfd_size_type) 1, (bfd_size_type) 4, abfd) != 4)
1845 if (hdr->bfd_section != NULL)
1847 const char *name = bfd_get_section_name (abfd, hdr->bfd_section);
1849 if (strcmp (name, ".sdata") == 0)
1851 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
1852 hdr->sh_type = SHT_PROGBITS;
1854 else if (strcmp (name, ".sbss") == 0)
1856 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
1857 hdr->sh_type = SHT_NOBITS;
1859 else if (strcmp (name, ".lit8") == 0
1860 || strcmp (name, ".lit4") == 0)
1862 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
1863 hdr->sh_type = SHT_PROGBITS;
1865 else if (strcmp (name, ".compact_rel") == 0)
1868 hdr->sh_type = SHT_PROGBITS;
1870 else if (strcmp (name, ".rtproc") == 0)
1872 if (hdr->sh_addralign != 0 && hdr->sh_entsize == 0)
1874 unsigned int adjust;
1876 adjust = hdr->sh_size % hdr->sh_addralign;
1878 hdr->sh_size += hdr->sh_addralign - adjust;
1886 /* MIPS ELF uses two common sections. One is the usual one, and the
1887 other is for small objects. All the small objects are kept
1888 together, and then referenced via the gp pointer, which yields
1889 faster assembler code. This is what we use for the small common
1890 section. This approach is copied from ecoff.c. */
1891 static asection mips_elf_scom_section;
1892 static asymbol mips_elf_scom_symbol;
1893 static asymbol *mips_elf_scom_symbol_ptr;
1895 /* MIPS ELF also uses an acommon section, which represents an
1896 allocated common symbol which may be overridden by a
1897 definition in a shared library. */
1898 static asection mips_elf_acom_section;
1899 static asymbol mips_elf_acom_symbol;
1900 static asymbol *mips_elf_acom_symbol_ptr;
1902 /* The Irix 5 support uses two virtual sections, which represent
1903 text/data symbols defined in dynamic objects. */
1904 static asection mips_elf_text_section;
1905 static asection *mips_elf_text_section_ptr;
1906 static asymbol mips_elf_text_symbol;
1907 static asymbol *mips_elf_text_symbol_ptr;
1909 static asection mips_elf_data_section;
1910 static asection *mips_elf_data_section_ptr;
1911 static asymbol mips_elf_data_symbol;
1912 static asymbol *mips_elf_data_symbol_ptr;
1914 /* Handle the special MIPS section numbers that a symbol may use. */
1917 mips_elf_symbol_processing (abfd, asym)
1921 elf_symbol_type *elfsym;
1923 elfsym = (elf_symbol_type *) asym;
1924 switch (elfsym->internal_elf_sym.st_shndx)
1926 case SHN_MIPS_ACOMMON:
1927 /* This section is used in a dynamically linked executable file.
1928 It is an allocated common section. The dynamic linker can
1929 either resolve these symbols to something in a shared
1930 library, or it can just leave them here. For our purposes,
1931 we can consider these symbols to be in a new section. */
1932 if (mips_elf_acom_section.name == NULL)
1934 /* Initialize the acommon section. */
1935 mips_elf_acom_section.name = ".acommon";
1936 mips_elf_acom_section.flags = SEC_ALLOC;
1937 mips_elf_acom_section.output_section = &mips_elf_acom_section;
1938 mips_elf_acom_section.symbol = &mips_elf_acom_symbol;
1939 mips_elf_acom_section.symbol_ptr_ptr = &mips_elf_acom_symbol_ptr;
1940 mips_elf_acom_symbol.name = ".acommon";
1941 mips_elf_acom_symbol.flags = BSF_SECTION_SYM;
1942 mips_elf_acom_symbol.section = &mips_elf_acom_section;
1943 mips_elf_acom_symbol_ptr = &mips_elf_acom_symbol;
1945 asym->section = &mips_elf_acom_section;
1949 /* Common symbols less than the GP size are automatically
1950 treated as SHN_MIPS_SCOMMON symbols. */
1951 if (asym->value > elf_gp_size (abfd))
1954 case SHN_MIPS_SCOMMON:
1955 if (mips_elf_scom_section.name == NULL)
1957 /* Initialize the small common section. */
1958 mips_elf_scom_section.name = ".scommon";
1959 mips_elf_scom_section.flags = SEC_IS_COMMON;
1960 mips_elf_scom_section.output_section = &mips_elf_scom_section;
1961 mips_elf_scom_section.symbol = &mips_elf_scom_symbol;
1962 mips_elf_scom_section.symbol_ptr_ptr = &mips_elf_scom_symbol_ptr;
1963 mips_elf_scom_symbol.name = ".scommon";
1964 mips_elf_scom_symbol.flags = BSF_SECTION_SYM;
1965 mips_elf_scom_symbol.section = &mips_elf_scom_section;
1966 mips_elf_scom_symbol_ptr = &mips_elf_scom_symbol;
1968 asym->section = &mips_elf_scom_section;
1969 asym->value = elfsym->internal_elf_sym.st_size;
1972 case SHN_MIPS_SUNDEFINED:
1973 asym->section = bfd_und_section_ptr;
1976 #if 0 /* for SGI_COMPAT */
1978 asym->section = mips_elf_text_section_ptr;
1982 asym->section = mips_elf_data_section_ptr;
1988 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
1992 mips_elf_additional_program_headers (abfd)
2000 if (! SGI_COMPAT (abfd))
2003 s = bfd_get_section_by_name (abfd, ".reginfo");
2004 if (s != NULL && (s->flags & SEC_LOAD) != 0)
2006 /* We need a PT_MIPS_REGINFO segment. */
2010 if (bfd_get_section_by_name (abfd, ".dynamic") != NULL
2011 && bfd_get_section_by_name (abfd, ".mdebug") != NULL)
2013 /* We need a PT_MIPS_RTPROC segment. */
2020 /* Modify the segment map for an Irix 5 executable. */
2023 mips_elf_modify_segment_map (abfd)
2027 struct elf_segment_map *m, **pm;
2029 if (! SGI_COMPAT (abfd))
2032 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
2034 s = bfd_get_section_by_name (abfd, ".reginfo");
2035 if (s != NULL && (s->flags & SEC_LOAD) != 0)
2037 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
2038 if (m->p_type == PT_MIPS_REGINFO)
2042 m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m);
2046 m->p_type = PT_MIPS_REGINFO;
2050 /* We want to put it after the PHDR and INTERP segments. */
2051 pm = &elf_tdata (abfd)->segment_map;
2053 && ((*pm)->p_type == PT_PHDR
2054 || (*pm)->p_type == PT_INTERP))
2062 /* If there are .dynamic and .mdebug sections, we make a room for
2063 the RTPROC header. FIXME: Rewrite without section names. */
2064 if (bfd_get_section_by_name (abfd, ".interp") == NULL
2065 && bfd_get_section_by_name (abfd, ".dynamic") != NULL
2066 && bfd_get_section_by_name (abfd, ".mdebug") != NULL)
2068 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
2069 if (m->p_type == PT_MIPS_RTPROC)
2073 m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m);
2077 m->p_type = PT_MIPS_RTPROC;
2079 s = bfd_get_section_by_name (abfd, ".rtproc");
2084 m->p_flags_valid = 1;
2092 /* We want to put it after the DYNAMIC segment. */
2093 pm = &elf_tdata (abfd)->segment_map;
2094 while (*pm != NULL && (*pm)->p_type != PT_DYNAMIC)
2104 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
2105 .dynsym, and .hash sections, and everything in between. */
2106 for (pm = &elf_tdata (abfd)->segment_map; *pm != NULL; pm = &(*pm)->next)
2107 if ((*pm)->p_type == PT_DYNAMIC)
2112 && strcmp (m->sections[0]->name, ".dynamic") == 0)
2114 static const char *sec_names[] =
2115 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
2118 struct elf_segment_map *n;
2122 for (i = 0; i < sizeof sec_names / sizeof sec_names[0]; i++)
2124 s = bfd_get_section_by_name (abfd, sec_names[i]);
2125 if (s != NULL && (s->flags & SEC_LOAD) != 0)
2131 sz = s->_cooked_size;
2134 if (high < s->vma + sz)
2140 for (s = abfd->sections; s != NULL; s = s->next)
2141 if ((s->flags & SEC_LOAD) != 0
2144 + (s->_cooked_size != 0 ? s->_cooked_size : s->_raw_size))
2148 n = ((struct elf_segment_map *)
2149 bfd_zalloc (abfd, sizeof *n + (c - 1) * sizeof (asection *)));
2156 for (s = abfd->sections; s != NULL; s = s->next)
2158 if ((s->flags & SEC_LOAD) != 0
2161 + (s->_cooked_size != 0 ? s->_cooked_size : s->_raw_size))
2175 /* The structure of the runtime procedure descriptor created by the
2176 loader for use by the static exception system. */
2178 typedef struct runtime_pdr {
2179 bfd_vma adr; /* memory address of start of procedure */
2180 long regmask; /* save register mask */
2181 long regoffset; /* save register offset */
2182 long fregmask; /* save floating point register mask */
2183 long fregoffset; /* save floating point register offset */
2184 long frameoffset; /* frame size */
2185 short framereg; /* frame pointer register */
2186 short pcreg; /* offset or reg of return pc */
2187 long irpss; /* index into the runtime string table */
2189 struct exception_info *exception_info;/* pointer to exception array */
2191 #define cbRPDR sizeof(RPDR)
2192 #define rpdNil ((pRPDR) 0)
2194 /* Swap RPDR (runtime procedure table entry) for output. */
2196 static void ecoff_swap_rpdr_out
2197 PARAMS ((bfd *, const RPDR *, struct rpdr_ext *));
2200 ecoff_swap_rpdr_out (abfd, in, ex)
2203 struct rpdr_ext *ex;
2205 /* ecoff_put_off was defined in ecoffswap.h. */
2206 ecoff_put_off (abfd, in->adr, (bfd_byte *) ex->p_adr);
2207 bfd_h_put_32 (abfd, in->regmask, (bfd_byte *) ex->p_regmask);
2208 bfd_h_put_32 (abfd, in->regoffset, (bfd_byte *) ex->p_regoffset);
2209 bfd_h_put_32 (abfd, in->fregmask, (bfd_byte *) ex->p_fregmask);
2210 bfd_h_put_32 (abfd, in->fregoffset, (bfd_byte *) ex->p_fregoffset);
2211 bfd_h_put_32 (abfd, in->frameoffset, (bfd_byte *) ex->p_frameoffset);
2213 bfd_h_put_16 (abfd, in->framereg, (bfd_byte *) ex->p_framereg);
2214 bfd_h_put_16 (abfd, in->pcreg, (bfd_byte *) ex->p_pcreg);
2216 bfd_h_put_32 (abfd, in->irpss, (bfd_byte *) ex->p_irpss);
2218 ecoff_put_off (abfd, in->exception_info, (bfd_byte *) ex->p_exception_info);
2222 /* Read ECOFF debugging information from a .mdebug section into a
2223 ecoff_debug_info structure. */
2226 mips_elf_read_ecoff_info (abfd, section, debug)
2229 struct ecoff_debug_info *debug;
2232 const struct ecoff_debug_swap *swap;
2233 char *ext_hdr = NULL;
2235 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
2237 ext_hdr = (char *) bfd_malloc ((size_t) swap->external_hdr_size);
2238 if (ext_hdr == NULL && swap->external_hdr_size != 0)
2241 if (bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0,
2242 swap->external_hdr_size)
2246 symhdr = &debug->symbolic_header;
2247 (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr);
2249 /* The symbolic header contains absolute file offsets and sizes to
2251 #define READ(ptr, offset, count, size, type) \
2252 if (symhdr->count == 0) \
2253 debug->ptr = NULL; \
2256 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
2257 if (debug->ptr == NULL) \
2258 goto error_return; \
2259 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
2260 || (bfd_read (debug->ptr, size, symhdr->count, \
2261 abfd) != size * symhdr->count)) \
2262 goto error_return; \
2265 READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *);
2266 READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR);
2267 READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR);
2268 READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR);
2269 READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR);
2270 READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext),
2272 READ (ss, cbSsOffset, issMax, sizeof (char), char *);
2273 READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *);
2274 READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR);
2275 READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR);
2276 READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR);
2280 debug->adjust = NULL;
2285 if (ext_hdr != NULL)
2287 if (debug->line != NULL)
2289 if (debug->external_dnr != NULL)
2290 free (debug->external_dnr);
2291 if (debug->external_pdr != NULL)
2292 free (debug->external_pdr);
2293 if (debug->external_sym != NULL)
2294 free (debug->external_sym);
2295 if (debug->external_opt != NULL)
2296 free (debug->external_opt);
2297 if (debug->external_aux != NULL)
2298 free (debug->external_aux);
2299 if (debug->ss != NULL)
2301 if (debug->ssext != NULL)
2302 free (debug->ssext);
2303 if (debug->external_fdr != NULL)
2304 free (debug->external_fdr);
2305 if (debug->external_rfd != NULL)
2306 free (debug->external_rfd);
2307 if (debug->external_ext != NULL)
2308 free (debug->external_ext);
2312 /* MIPS ELF local labels start with '$', not 'L'. */
2316 mips_elf_is_local_label (abfd, symbol)
2320 return symbol->name[0] == '$';
2323 /* MIPS ELF uses a special find_nearest_line routine in order the
2324 handle the ECOFF debugging information. */
2326 struct mips_elf_find_line
2328 struct ecoff_debug_info d;
2329 struct ecoff_find_line i;
2333 mips_elf_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
2334 functionname_ptr, line_ptr)
2339 const char **filename_ptr;
2340 const char **functionname_ptr;
2341 unsigned int *line_ptr;
2345 msec = bfd_get_section_by_name (abfd, ".mdebug");
2349 struct mips_elf_find_line *fi;
2350 const struct ecoff_debug_swap * const swap =
2351 get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
2353 /* If we are called during a link, mips_elf_final_link may have
2354 cleared the SEC_HAS_CONTENTS field. We force it back on here
2355 if appropriate (which it normally will be). */
2356 origflags = msec->flags;
2357 if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS)
2358 msec->flags |= SEC_HAS_CONTENTS;
2360 fi = elf_tdata (abfd)->find_line_info;
2363 bfd_size_type external_fdr_size;
2366 struct fdr *fdr_ptr;
2368 fi = ((struct mips_elf_find_line *)
2369 bfd_alloc (abfd, sizeof (struct mips_elf_find_line)));
2372 msec->flags = origflags;
2376 memset (fi, 0, sizeof (struct mips_elf_find_line));
2378 if (! mips_elf_read_ecoff_info (abfd, msec, &fi->d))
2380 msec->flags = origflags;
2384 /* Swap in the FDR information. */
2385 fi->d.fdr = ((struct fdr *)
2387 (fi->d.symbolic_header.ifdMax *
2388 sizeof (struct fdr))));
2389 if (fi->d.fdr == NULL)
2391 msec->flags = origflags;
2394 external_fdr_size = swap->external_fdr_size;
2395 fdr_ptr = fi->d.fdr;
2396 fraw_src = (char *) fi->d.external_fdr;
2397 fraw_end = (fraw_src
2398 + fi->d.symbolic_header.ifdMax * external_fdr_size);
2399 for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
2400 (*swap->swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr);
2402 elf_tdata (abfd)->find_line_info = fi;
2404 /* Note that we don't bother to ever free this information.
2405 find_nearest_line is either called all the time, as in
2406 objdump -l, so the information should be saved, or it is
2407 rarely called, as in ld error messages, so the memory
2408 wasted is unimportant. Still, it would probably be a
2409 good idea for free_cached_info to throw it away. */
2412 if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap,
2413 &fi->i, filename_ptr, functionname_ptr,
2416 msec->flags = origflags;
2420 msec->flags = origflags;
2423 /* Fall back on the generic ELF find_nearest_line routine. */
2425 return _bfd_elf_find_nearest_line (abfd, section, symbols, offset,
2426 filename_ptr, functionname_ptr,
2430 /* The MIPS ELF linker needs additional information for each symbol in
2431 the global hash table. */
2433 struct mips_elf_link_hash_entry
2435 struct elf_link_hash_entry root;
2437 /* External symbol information. */
2441 /* MIPS ELF linker hash table. */
2443 struct mips_elf_link_hash_table
2445 struct elf_link_hash_table root;
2446 /* String section indices for the dynamic section symbols. */
2447 bfd_size_type dynsym_sec_strindex[SIZEOF_MIPS_DYNSYM_SECNAMES];
2448 /* The number of .rtproc entries. */
2449 bfd_size_type procedure_count;
2450 /* The size of the .compact_rel section (if SGI_COMPAT). */
2451 bfd_size_type compact_rel_size;
2454 /* Look up an entry in a MIPS ELF linker hash table. */
2456 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
2457 ((struct mips_elf_link_hash_entry *) \
2458 elf_link_hash_lookup (&(table)->root, (string), (create), \
2461 /* Traverse a MIPS ELF linker hash table. */
2463 #define mips_elf_link_hash_traverse(table, func, info) \
2464 (elf_link_hash_traverse \
2466 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
2469 /* Get the MIPS ELF linker hash table from a link_info structure. */
2471 #define mips_elf_hash_table(p) \
2472 ((struct mips_elf_link_hash_table *) ((p)->hash))
2474 static boolean mips_elf_output_extsym
2475 PARAMS ((struct mips_elf_link_hash_entry *, PTR));
2477 /* Create an entry in a MIPS ELF linker hash table. */
2479 static struct bfd_hash_entry *
2480 mips_elf_link_hash_newfunc (entry, table, string)
2481 struct bfd_hash_entry *entry;
2482 struct bfd_hash_table *table;
2485 struct mips_elf_link_hash_entry *ret =
2486 (struct mips_elf_link_hash_entry *) entry;
2488 /* Allocate the structure if it has not already been allocated by a
2490 if (ret == (struct mips_elf_link_hash_entry *) NULL)
2491 ret = ((struct mips_elf_link_hash_entry *)
2492 bfd_hash_allocate (table,
2493 sizeof (struct mips_elf_link_hash_entry)));
2494 if (ret == (struct mips_elf_link_hash_entry *) NULL)
2495 return (struct bfd_hash_entry *) ret;
2497 /* Call the allocation method of the superclass. */
2498 ret = ((struct mips_elf_link_hash_entry *)
2499 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2501 if (ret != (struct mips_elf_link_hash_entry *) NULL)
2503 /* Set local fields. */
2504 memset (&ret->esym, 0, sizeof (EXTR));
2505 /* We use -2 as a marker to indicate that the information has
2506 not been set. -1 means there is no associated ifd. */
2510 return (struct bfd_hash_entry *) ret;
2513 /* Create a MIPS ELF linker hash table. */
2515 static struct bfd_link_hash_table *
2516 mips_elf_link_hash_table_create (abfd)
2519 struct mips_elf_link_hash_table *ret;
2522 ret = ((struct mips_elf_link_hash_table *)
2523 bfd_alloc (abfd, sizeof (struct mips_elf_link_hash_table)));
2524 if (ret == (struct mips_elf_link_hash_table *) NULL)
2527 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
2528 mips_elf_link_hash_newfunc))
2530 bfd_release (abfd, ret);
2534 for (i = 0; i < SIZEOF_MIPS_DYNSYM_SECNAMES; i++)
2535 ret->dynsym_sec_strindex[i] = (bfd_size_type) -1;
2536 ret->procedure_count = 0;
2537 ret->compact_rel_size = 0;
2539 return &ret->root.root;
2542 /* Hook called by the linker routine which adds symbols from an object
2543 file. We must handle the special MIPS section numbers here. */
2547 mips_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
2549 struct bfd_link_info *info;
2550 const Elf_Internal_Sym *sym;
2556 if (SGI_COMPAT (abfd)
2557 && (abfd->flags & DYNAMIC) != 0
2558 && strcmp (*namep, "_rld_new_interface") == 0)
2560 /* Skip Irix 5 rld entry name. */
2565 switch (sym->st_shndx)
2568 /* Common symbols less than the GP size are automatically
2569 treated as SHN_MIPS_SCOMMON symbols. */
2570 if (sym->st_size > elf_gp_size (abfd))
2573 case SHN_MIPS_SCOMMON:
2574 *secp = bfd_make_section_old_way (abfd, ".scommon");
2575 (*secp)->flags |= SEC_IS_COMMON;
2576 *valp = sym->st_size;
2580 /* This section is used in a shared object. */
2581 if (mips_elf_text_section_ptr == NULL)
2583 /* Initialize the section. */
2584 mips_elf_text_section.name = ".text";
2585 mips_elf_text_section.flags = SEC_NO_FLAGS;
2586 mips_elf_text_section.output_section = NULL;
2587 mips_elf_text_section.owner = abfd;
2588 mips_elf_text_section.symbol = &mips_elf_text_symbol;
2589 mips_elf_text_section.symbol_ptr_ptr = &mips_elf_text_symbol_ptr;
2590 mips_elf_text_symbol.name = ".text";
2591 mips_elf_text_symbol.flags = BSF_SECTION_SYM;
2592 mips_elf_text_symbol.section = &mips_elf_text_section;
2593 mips_elf_text_symbol_ptr = &mips_elf_text_symbol;
2594 mips_elf_text_section_ptr = &mips_elf_text_section;
2597 *secp = bfd_und_section_ptr;
2599 *secp = mips_elf_text_section_ptr;
2602 case SHN_MIPS_ACOMMON:
2603 /* Fall through. XXX Can we treat this as allocated data? */
2605 /* This section is used in a shared object. */
2606 if (mips_elf_data_section_ptr == NULL)
2608 /* Initialize the section. */
2609 mips_elf_data_section.name = ".data";
2610 mips_elf_data_section.flags = SEC_NO_FLAGS;
2611 mips_elf_data_section.output_section = NULL;
2612 mips_elf_data_section.owner = abfd;
2613 mips_elf_data_section.symbol = &mips_elf_data_symbol;
2614 mips_elf_data_section.symbol_ptr_ptr = &mips_elf_data_symbol_ptr;
2615 mips_elf_data_symbol.name = ".data";
2616 mips_elf_data_symbol.flags = BSF_SECTION_SYM;
2617 mips_elf_data_symbol.section = &mips_elf_data_section;
2618 mips_elf_data_symbol_ptr = &mips_elf_data_symbol;
2619 mips_elf_data_section_ptr = &mips_elf_data_section;
2622 *secp = bfd_und_section_ptr;
2624 *secp = mips_elf_data_section_ptr;
2627 case SHN_MIPS_SUNDEFINED:
2628 *secp = bfd_und_section_ptr;
2635 /* Structure used to pass information to mips_elf_output_extsym. */
2640 struct bfd_link_info *info;
2641 struct ecoff_debug_info *debug;
2642 const struct ecoff_debug_swap *swap;
2646 /* This routine is used to write out ECOFF debugging external symbol
2647 information. It is called via mips_elf_link_hash_traverse. The
2648 ECOFF external symbol information must match the ELF external
2649 symbol information. Unfortunately, at this point we don't know
2650 whether a symbol is required by reloc information, so the two
2651 tables may wind up being different. We must sort out the external
2652 symbol information before we can set the final size of the .mdebug
2653 section, and we must set the size of the .mdebug section before we
2654 can relocate any sections, and we can't know which symbols are
2655 required by relocation until we relocate the sections.
2656 Fortunately, it is relatively unlikely that any symbol will be
2657 stripped but required by a reloc. In particular, it can not happen
2658 when generating a final executable. */
2661 mips_elf_output_extsym (h, data)
2662 struct mips_elf_link_hash_entry *h;
2665 struct extsym_info *einfo = (struct extsym_info *) data;
2667 asection *sec, *output_section;
2669 if (h->root.indx == -2)
2671 else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
2672 || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)
2673 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
2674 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
2676 else if (einfo->info->strip == strip_all
2677 || (einfo->info->strip == strip_some
2678 && bfd_hash_lookup (einfo->info->keep_hash,
2679 h->root.root.root.string,
2680 false, false) == NULL))
2688 if (h->esym.ifd == -2)
2691 h->esym.cobol_main = 0;
2692 h->esym.weakext = 0;
2693 h->esym.reserved = 0;
2694 h->esym.ifd = ifdNil;
2695 h->esym.asym.value = 0;
2696 h->esym.asym.st = stGlobal;
2698 if (SGI_COMPAT (einfo->abfd)
2699 && (h->root.root.type == bfd_link_hash_undefined
2700 || h->root.root.type == bfd_link_hash_undefweak))
2704 /* Use undefined class. Also, set class and type for some
2706 name = h->root.root.root.string;
2707 if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0
2708 || strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0)
2710 h->esym.asym.sc = scData;
2711 h->esym.asym.st = stLabel;
2712 h->esym.asym.value = 0;
2714 else if (strcmp (name, mips_elf_dynsym_rtproc_names[2]) == 0)
2716 h->esym.asym.sc = scAbs;
2717 h->esym.asym.st = stLabel;
2718 h->esym.asym.value =
2719 mips_elf_hash_table (einfo->info)->procedure_count;
2721 else if (strcmp (name, "_gp_disp") == 0)
2723 h->esym.asym.sc = scAbs;
2724 h->esym.asym.st = stLabel;
2725 h->esym.asym.value = elf_gp (einfo->abfd);
2728 h->esym.asym.sc = scUndefined;
2730 else if (h->root.root.type != bfd_link_hash_defined
2731 && h->root.root.type != bfd_link_hash_defweak)
2732 h->esym.asym.sc = scAbs;
2737 sec = h->root.root.u.def.section;
2738 output_section = sec->output_section;
2740 /* When making a shared library and symbol h is the one from
2741 the another shared library, OUTPUT_SECTION may be null. */
2742 if (output_section == NULL)
2743 h->esym.asym.sc = scUndefined;
2746 name = bfd_section_name (output_section->owner, output_section);
2748 if (strcmp (name, ".text") == 0)
2749 h->esym.asym.sc = scText;
2750 else if (strcmp (name, ".data") == 0)
2751 h->esym.asym.sc = scData;
2752 else if (strcmp (name, ".sdata") == 0)
2753 h->esym.asym.sc = scSData;
2754 else if (strcmp (name, ".rodata") == 0
2755 || strcmp (name, ".rdata") == 0)
2756 h->esym.asym.sc = scRData;
2757 else if (strcmp (name, ".bss") == 0)
2758 h->esym.asym.sc = scBss;
2759 else if (strcmp (name, ".sbss") == 0)
2760 h->esym.asym.sc = scSBss;
2761 else if (strcmp (name, ".init") == 0)
2762 h->esym.asym.sc = scInit;
2763 else if (strcmp (name, ".fini") == 0)
2764 h->esym.asym.sc = scFini;
2766 h->esym.asym.sc = scAbs;
2770 h->esym.asym.reserved = 0;
2771 h->esym.asym.index = indexNil;
2774 if (h->root.root.type == bfd_link_hash_common)
2775 h->esym.asym.value = h->root.root.u.c.size;
2776 else if (h->root.root.type == bfd_link_hash_defined
2777 || h->root.root.type == bfd_link_hash_defweak)
2779 if (h->esym.asym.sc == scCommon)
2780 h->esym.asym.sc = scBss;
2781 else if (h->esym.asym.sc == scSCommon)
2782 h->esym.asym.sc = scSBss;
2784 sec = h->root.root.u.def.section;
2785 output_section = sec->output_section;
2786 if (output_section != NULL)
2787 h->esym.asym.value = (h->root.root.u.def.value
2788 + sec->output_offset
2789 + output_section->vma);
2791 h->esym.asym.value = 0;
2793 else if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
2795 /* Set type and value for a symbol with a function stub. */
2796 h->esym.asym.st = stProc;
2797 sec = h->root.root.u.def.section;
2799 h->esym.asym.value = 0;
2802 output_section = sec->output_section;
2803 if (output_section != NULL)
2804 h->esym.asym.value = (h->root.plt_offset
2805 + sec->output_offset
2806 + output_section->vma);
2808 h->esym.asym.value = 0;
2815 if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap,
2816 h->root.root.root.string,
2819 einfo->failed = true;
2826 /* Create a runtime procedure table from the .mdebug section. */
2829 mips_elf_create_procedure_table (handle, abfd, info, s, debug)
2832 struct bfd_link_info *info;
2834 struct ecoff_debug_info *debug;
2836 const struct ecoff_debug_swap *swap;
2837 HDRR *hdr = &debug->symbolic_header;
2839 struct rpdr_ext *erp;
2841 struct pdr_ext *epdr;
2842 struct sym_ext *esym;
2845 unsigned long size, count;
2846 unsigned long sindex;
2850 const char *no_name_func = "static procedure (no name)";
2857 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
2859 sindex = strlen (no_name_func) + 1;
2860 count = hdr->ipdMax;
2863 size = swap->external_pdr_size;
2865 epdr = (struct pdr_ext *) bfd_malloc (size * count);
2869 if (! _bfd_ecoff_get_accumulated_pdr (handle, (PTR) epdr))
2872 size = sizeof (RPDR);
2873 rp = rpdr = (RPDR *) bfd_malloc (size * count);
2877 sv = (char **) bfd_malloc (sizeof (char *) * count);
2881 count = hdr->isymMax;
2882 size = swap->external_sym_size;
2883 esym = (struct sym_ext *) bfd_malloc (size * count);
2887 if (! _bfd_ecoff_get_accumulated_sym (handle, (PTR) esym))
2890 count = hdr->issMax;
2891 ss = (char *) bfd_malloc (count);
2894 if (! _bfd_ecoff_get_accumulated_ss (handle, (PTR) ss))
2897 count = hdr->ipdMax;
2898 for (i = 0; i < count; i++, rp++, epdr++)
2900 (*swap->swap_pdr_in) (abfd, (PTR) epdr, &pdr);
2901 (*swap->swap_sym_in) (abfd, (PTR) &esym[pdr.isym], &sym);
2902 rp->adr = sym.value;
2903 rp->regmask = pdr.regmask;
2904 rp->regoffset = pdr.regoffset;
2905 rp->fregmask = pdr.fregmask;
2906 rp->fregoffset = pdr.fregoffset;
2907 rp->frameoffset = pdr.frameoffset;
2908 rp->framereg = pdr.framereg;
2909 rp->pcreg = pdr.pcreg;
2911 sv[i] = ss + sym.iss;
2912 sindex += strlen (sv[i]) + 1;
2916 size = sizeof (struct rpdr_ext) * (count + 2) + sindex;
2917 size = BFD_ALIGN (size, 16);
2918 rtproc = (PTR) bfd_alloc (abfd, size);
2921 mips_elf_hash_table (info)->procedure_count = 0;
2925 mips_elf_hash_table (info)->procedure_count = count + 2;
2927 erp = (struct rpdr_ext *) rtproc;
2928 memset (rp, 0, sizeof (struct rpdr_ext));
2930 str = (char *) rtproc + sizeof (struct rpdr_ext) * (count + 2);
2931 strcpy (str, no_name_func);
2932 str += strlen (no_name_func) + 1;
2933 for (i = 0; i < count; i++)
2935 ecoff_swap_rpdr_out (abfd, rpdr + i, erp + i);
2936 strcpy (str, sv[i]);
2937 str += strlen (sv[i]) + 1;
2939 ecoff_put_off (abfd, (bfd_vma) -1, (bfd_byte *) (erp + count)->p_adr);
2941 /* Set the size and contents of .rtproc section. */
2942 s->_raw_size = size;
2943 s->contents = rtproc;
2945 /* Skip this section later on (I don't think this currently
2946 matters, but someday it might). */
2947 s->link_order_head = (struct bfd_link_order *) NULL;
2971 /* A comparison routine used to sort .gptab entries. */
2974 gptab_compare (p1, p2)
2978 const Elf32_gptab *a1 = (const Elf32_gptab *) p1;
2979 const Elf32_gptab *a2 = (const Elf32_gptab *) p2;
2981 return a1->gt_entry.gt_g_value - a2->gt_entry.gt_g_value;
2984 /* We need to use a special link routine to handle the .reginfo and
2985 the .mdebug sections. We need to merge all instances of these
2986 sections together, not write them all out sequentially. */
2989 mips_elf_final_link (abfd, info)
2991 struct bfd_link_info *info;
2995 struct bfd_link_order *p;
2996 asection *reginfo_sec, *mdebug_sec, *gptab_data_sec, *gptab_bss_sec;
2997 asection *rtproc_sec;
2998 Elf32_RegInfo reginfo;
2999 struct ecoff_debug_info debug;
3000 const struct ecoff_debug_swap *swap
3001 = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
3002 HDRR *symhdr = &debug.symbolic_header;
3003 PTR mdebug_handle = NULL;
3005 /* Drop the .options section, since it has special semantics which I
3006 haven't bothered to figure out. */
3007 for (secpp = &abfd->sections; *secpp != NULL; secpp = &(*secpp)->next)
3009 if (strcmp ((*secpp)->name, ".options") == 0)
3011 for (p = (*secpp)->link_order_head; p != NULL; p = p->next)
3012 if (p->type == bfd_indirect_link_order)
3013 p->u.indirect.section->flags &=~ SEC_HAS_CONTENTS;
3014 (*secpp)->link_order_head = NULL;
3015 *secpp = (*secpp)->next;
3016 --abfd->section_count;
3021 /* Get a value for the GP register. */
3022 if (elf_gp (abfd) == 0)
3024 struct bfd_link_hash_entry *h;
3026 h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true);
3027 if (h != (struct bfd_link_hash_entry *) NULL
3028 && h->type == bfd_link_hash_defined)
3029 elf_gp (abfd) = (h->u.def.value
3030 + h->u.def.section->output_section->vma
3031 + h->u.def.section->output_offset);
3032 else if (info->relocateable)
3036 /* Make up a value. */
3038 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
3041 && (strcmp (o->name, ".sbss") == 0
3042 || strcmp (o->name, ".sdata") == 0
3043 || strcmp (o->name, ".lit4") == 0
3044 || strcmp (o->name, ".lit8") == 0))
3047 elf_gp (abfd) = lo + ELF_MIPS_GP_OFFSET (abfd);
3051 /* If the relocate_section function needs to do a reloc
3052 involving the GP value, it should make a reloc_dangerous
3053 callback to warn that GP is not defined. */
3057 /* Go through the sections and collect the .reginfo and .mdebug
3061 gptab_data_sec = NULL;
3062 gptab_bss_sec = NULL;
3063 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
3065 if (strcmp (o->name, ".reginfo") == 0)
3067 memset (®info, 0, sizeof reginfo);
3069 /* We have found the .reginfo section in the output file.
3070 Look through all the link_orders comprising it and merge
3071 the information together. */
3072 for (p = o->link_order_head;
3073 p != (struct bfd_link_order *) NULL;
3076 asection *input_section;
3078 Elf32_External_RegInfo ext;
3081 if (p->type != bfd_indirect_link_order)
3083 if (p->type == bfd_fill_link_order)
3088 input_section = p->u.indirect.section;
3089 input_bfd = input_section->owner;
3091 /* The linker emulation code has probably clobbered the
3092 size to be zero bytes. */
3093 if (input_section->_raw_size == 0)
3094 input_section->_raw_size = sizeof (Elf32_External_RegInfo);
3096 if (! bfd_get_section_contents (input_bfd, input_section,
3102 bfd_mips_elf32_swap_reginfo_in (input_bfd, &ext, &sub);
3104 reginfo.ri_gprmask |= sub.ri_gprmask;
3105 reginfo.ri_cprmask[0] |= sub.ri_cprmask[0];
3106 reginfo.ri_cprmask[1] |= sub.ri_cprmask[1];
3107 reginfo.ri_cprmask[2] |= sub.ri_cprmask[2];
3108 reginfo.ri_cprmask[3] |= sub.ri_cprmask[3];
3110 /* ri_gp_value is set by the function
3111 mips_elf_section_processing when the section is
3112 finally written out. */
3114 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3115 elf_link_input_bfd ignores this section. */
3116 input_section->flags &=~ SEC_HAS_CONTENTS;
3119 /* Force the section size to the value we want. */
3120 o->_raw_size = sizeof (Elf32_External_RegInfo);
3122 /* Skip this section later on (I don't think this currently
3123 matters, but someday it might). */
3124 o->link_order_head = (struct bfd_link_order *) NULL;
3129 if (strcmp (o->name, ".mdebug") == 0)
3131 struct extsym_info einfo;
3133 /* We have found the .mdebug section in the output file.
3134 Look through all the link_orders comprising it and merge
3135 the information together. */
3136 symhdr->magic = swap->sym_magic;
3137 /* FIXME: What should the version stamp be? */
3139 symhdr->ilineMax = 0;
3143 symhdr->isymMax = 0;
3144 symhdr->ioptMax = 0;
3145 symhdr->iauxMax = 0;
3147 symhdr->issExtMax = 0;
3150 symhdr->iextMax = 0;
3152 /* We accumulate the debugging information itself in the
3153 debug_info structure. */
3155 debug.external_dnr = NULL;
3156 debug.external_pdr = NULL;
3157 debug.external_sym = NULL;
3158 debug.external_opt = NULL;
3159 debug.external_aux = NULL;
3161 debug.ssext = debug.ssext_end = NULL;
3162 debug.external_fdr = NULL;
3163 debug.external_rfd = NULL;
3164 debug.external_ext = debug.external_ext_end = NULL;
3166 mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info);
3167 if (mdebug_handle == (PTR) NULL)
3170 if (SGI_COMPAT (abfd))
3176 static const char * const name[] =
3177 { ".text", ".init", ".fini", ".data",
3178 ".rodata", ".sdata", ".sbss", ".bss" };
3179 static const int sc[] = { scText, scInit, scFini, scData,
3180 scRData, scSData, scSBss, scBss };
3183 esym.cobol_main = 0;
3187 esym.asym.iss = issNil;
3188 esym.asym.st = stLocal;
3189 esym.asym.reserved = 0;
3190 esym.asym.index = indexNil;
3191 for (i = 0; i < 8; i++)
3193 esym.asym.sc = sc[i];
3194 s = bfd_get_section_by_name (abfd, name[i]);
3197 esym.asym.value = s->vma;
3198 last = s->vma + s->_raw_size;
3201 esym.asym.value = last;
3203 if (! bfd_ecoff_debug_one_external (abfd, &debug, swap,
3209 for (p = o->link_order_head;
3210 p != (struct bfd_link_order *) NULL;
3213 asection *input_section;
3215 const struct ecoff_debug_swap *input_swap;
3216 struct ecoff_debug_info input_debug;
3220 if (p->type != bfd_indirect_link_order)
3222 if (p->type == bfd_fill_link_order)
3227 input_section = p->u.indirect.section;
3228 input_bfd = input_section->owner;
3230 if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour
3231 || (get_elf_backend_data (input_bfd)
3232 ->elf_backend_ecoff_debug_swap) == NULL)
3234 /* I don't know what a non MIPS ELF bfd would be
3235 doing with a .mdebug section, but I don't really
3236 want to deal with it. */
3240 input_swap = (get_elf_backend_data (input_bfd)
3241 ->elf_backend_ecoff_debug_swap);
3243 BFD_ASSERT (p->size == input_section->_raw_size);
3245 /* The ECOFF linking code expects that we have already
3246 read in the debugging information and set up an
3247 ecoff_debug_info structure, so we do that now. */
3248 if (! mips_elf_read_ecoff_info (input_bfd, input_section,
3252 if (! (bfd_ecoff_debug_accumulate
3253 (mdebug_handle, abfd, &debug, swap, input_bfd,
3254 &input_debug, input_swap, info)))
3257 /* Loop through the external symbols. For each one with
3258 interesting information, try to find the symbol in
3259 the linker global hash table and save the information
3260 for the output external symbols. */
3261 eraw_src = input_debug.external_ext;
3262 eraw_end = (eraw_src
3263 + (input_debug.symbolic_header.iextMax
3264 * input_swap->external_ext_size));
3266 eraw_src < eraw_end;
3267 eraw_src += input_swap->external_ext_size)
3271 struct mips_elf_link_hash_entry *h;
3273 (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext);
3274 if (ext.asym.sc == scNil
3275 || ext.asym.sc == scUndefined
3276 || ext.asym.sc == scSUndefined)
3279 name = input_debug.ssext + ext.asym.iss;
3280 h = mips_elf_link_hash_lookup (mips_elf_hash_table (info),
3281 name, false, false, true);
3282 if (h == NULL || h->esym.ifd != -2)
3288 < input_debug.symbolic_header.ifdMax);
3289 ext.ifd = input_debug.ifdmap[ext.ifd];
3295 /* Free up the information we just read. */
3296 free (input_debug.line);
3297 free (input_debug.external_dnr);
3298 free (input_debug.external_pdr);
3299 free (input_debug.external_sym);
3300 free (input_debug.external_opt);
3301 free (input_debug.external_aux);
3302 free (input_debug.ss);
3303 free (input_debug.ssext);
3304 free (input_debug.external_fdr);
3305 free (input_debug.external_rfd);
3306 free (input_debug.external_ext);
3308 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3309 elf_link_input_bfd ignores this section. */
3310 input_section->flags &=~ SEC_HAS_CONTENTS;
3313 if (SGI_COMPAT (abfd) && info->shared)
3315 /* Create .rtproc section. */
3316 rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc");
3317 if (rtproc_sec == NULL)
3319 flagword flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY
3322 rtproc_sec = bfd_make_section (abfd, ".rtproc");
3323 if (rtproc_sec == NULL
3324 || ! bfd_set_section_flags (abfd, rtproc_sec, flags)
3325 || ! bfd_set_section_alignment (abfd, rtproc_sec, 12))
3329 if (! mips_elf_create_procedure_table (mdebug_handle, abfd,
3330 info, rtproc_sec, &debug))
3334 /* Build the external symbol information. */
3337 einfo.debug = &debug;
3339 einfo.failed = false;
3340 mips_elf_link_hash_traverse (mips_elf_hash_table (info),
3341 mips_elf_output_extsym,
3346 /* Set the size of the .mdebug section. */
3347 o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap);
3349 /* Skip this section later on (I don't think this currently
3350 matters, but someday it might). */
3351 o->link_order_head = (struct bfd_link_order *) NULL;
3356 if (strncmp (o->name, ".gptab.", sizeof ".gptab." - 1) == 0)
3358 const char *subname;
3361 Elf32_External_gptab *ext_tab;
3364 /* The .gptab.sdata and .gptab.sbss sections hold
3365 information describing how the small data area would
3366 change depending upon the -G switch. These sections
3367 not used in executables files. */
3368 if (! info->relocateable)
3372 for (p = o->link_order_head;
3373 p != (struct bfd_link_order *) NULL;
3376 asection *input_section;
3378 if (p->type != bfd_indirect_link_order)
3380 if (p->type == bfd_fill_link_order)
3385 input_section = p->u.indirect.section;
3387 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3388 elf_link_input_bfd ignores this section. */
3389 input_section->flags &=~ SEC_HAS_CONTENTS;
3392 /* Skip this section later on (I don't think this
3393 currently matters, but someday it might). */
3394 o->link_order_head = (struct bfd_link_order *) NULL;
3396 /* Really remove the section. */
3397 for (secpp = &abfd->sections;
3399 secpp = &(*secpp)->next)
3401 *secpp = (*secpp)->next;
3402 --abfd->section_count;
3407 /* There is one gptab for initialized data, and one for
3408 uninitialized data. */
3409 if (strcmp (o->name, ".gptab.sdata") == 0)
3411 else if (strcmp (o->name, ".gptab.sbss") == 0)
3415 (*_bfd_error_handler)
3416 ("%s: illegal section name `%s'",
3417 bfd_get_filename (abfd), o->name);
3418 bfd_set_error (bfd_error_nonrepresentable_section);
3422 /* The linker script always combines .gptab.data and
3423 .gptab.sdata into .gptab.sdata, and likewise for
3424 .gptab.bss and .gptab.sbss. It is possible that there is
3425 no .sdata or .sbss section in the output file, in which
3426 case we must change the name of the output section. */
3427 subname = o->name + sizeof ".gptab" - 1;
3428 if (bfd_get_section_by_name (abfd, subname) == NULL)
3430 if (o == gptab_data_sec)
3431 o->name = ".gptab.data";
3433 o->name = ".gptab.bss";
3434 subname = o->name + sizeof ".gptab" - 1;
3435 BFD_ASSERT (bfd_get_section_by_name (abfd, subname) != NULL);
3438 /* Set up the first entry. */
3440 tab = (Elf32_gptab *) bfd_malloc (c * sizeof (Elf32_gptab));
3443 tab[0].gt_header.gt_current_g_value = elf_gp_size (abfd);
3444 tab[0].gt_header.gt_unused = 0;
3446 /* Combine the input sections. */
3447 for (p = o->link_order_head;
3448 p != (struct bfd_link_order *) NULL;
3451 asection *input_section;
3455 bfd_size_type gpentry;
3457 if (p->type != bfd_indirect_link_order)
3459 if (p->type == bfd_fill_link_order)
3464 input_section = p->u.indirect.section;
3465 input_bfd = input_section->owner;
3467 /* Combine the gptab entries for this input section one
3468 by one. We know that the input gptab entries are
3469 sorted by ascending -G value. */
3470 size = bfd_section_size (input_bfd, input_section);
3472 for (gpentry = sizeof (Elf32_External_gptab);
3474 gpentry += sizeof (Elf32_External_gptab))
3476 Elf32_External_gptab ext_gptab;
3477 Elf32_gptab int_gptab;
3483 if (! (bfd_get_section_contents
3484 (input_bfd, input_section, (PTR) &ext_gptab,
3485 gpentry, sizeof (Elf32_External_gptab))))
3491 bfd_mips_elf32_swap_gptab_in (input_bfd, &ext_gptab,
3493 val = int_gptab.gt_entry.gt_g_value;
3494 add = int_gptab.gt_entry.gt_bytes - last;
3497 for (look = 1; look < c; look++)
3499 if (tab[look].gt_entry.gt_g_value >= val)
3500 tab[look].gt_entry.gt_bytes += add;
3502 if (tab[look].gt_entry.gt_g_value == val)
3508 Elf32_gptab *new_tab;
3511 /* We need a new table entry. */
3512 new_tab = ((Elf32_gptab *)
3513 bfd_realloc ((PTR) tab,
3514 (c + 1) * sizeof (Elf32_gptab)));
3515 if (new_tab == NULL)
3521 tab[c].gt_entry.gt_g_value = val;
3522 tab[c].gt_entry.gt_bytes = add;
3524 /* Merge in the size for the next smallest -G
3525 value, since that will be implied by this new
3528 for (look = 1; look < c; look++)
3530 if (tab[look].gt_entry.gt_g_value < val
3532 || (tab[look].gt_entry.gt_g_value
3533 > tab[max].gt_entry.gt_g_value)))
3537 tab[c].gt_entry.gt_bytes +=
3538 tab[max].gt_entry.gt_bytes;
3543 last = int_gptab.gt_entry.gt_bytes;
3546 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3547 elf_link_input_bfd ignores this section. */
3548 input_section->flags &=~ SEC_HAS_CONTENTS;
3551 /* The table must be sorted by -G value. */
3553 qsort (tab + 1, c - 1, sizeof (tab[0]), gptab_compare);
3555 /* Swap out the table. */
3556 ext_tab = ((Elf32_External_gptab *)
3557 bfd_alloc (abfd, c * sizeof (Elf32_External_gptab)));
3558 if (ext_tab == NULL)
3564 for (i = 0; i < c; i++)
3565 bfd_mips_elf32_swap_gptab_out (abfd, tab + i, ext_tab + i);
3568 o->_raw_size = c * sizeof (Elf32_External_gptab);
3569 o->contents = (bfd_byte *) ext_tab;
3571 /* Skip this section later on (I don't think this currently
3572 matters, but someday it might). */
3573 o->link_order_head = (struct bfd_link_order *) NULL;
3577 /* Invoke the regular ELF backend linker to do all the work. */
3578 if (! bfd_elf32_bfd_final_link (abfd, info))
3581 /* Now write out the computed sections. */
3583 if (reginfo_sec != (asection *) NULL)
3585 Elf32_External_RegInfo ext;
3587 bfd_mips_elf32_swap_reginfo_out (abfd, ®info, &ext);
3588 if (! bfd_set_section_contents (abfd, reginfo_sec, (PTR) &ext,
3589 (file_ptr) 0, sizeof ext))
3593 if (mdebug_sec != (asection *) NULL)
3595 BFD_ASSERT (abfd->output_has_begun);
3596 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug,
3598 mdebug_sec->filepos))
3601 bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info);
3604 if (gptab_data_sec != (asection *) NULL)
3606 if (! bfd_set_section_contents (abfd, gptab_data_sec,
3607 gptab_data_sec->contents,
3609 gptab_data_sec->_raw_size))
3613 if (gptab_bss_sec != (asection *) NULL)
3615 if (! bfd_set_section_contents (abfd, gptab_bss_sec,
3616 gptab_bss_sec->contents,
3618 gptab_bss_sec->_raw_size))
3622 if (SGI_COMPAT (abfd))
3624 rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc");
3625 if (rtproc_sec != NULL)
3627 if (! bfd_set_section_contents (abfd, rtproc_sec,
3628 rtproc_sec->contents,
3630 rtproc_sec->_raw_size))
3638 /* Handle a MIPS ELF HI16 reloc. */
3641 mips_elf_relocate_hi16 (input_bfd, relhi, rello, contents, addend)
3643 Elf_Internal_Rela *relhi;
3644 Elf_Internal_Rela *rello;
3651 insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
3653 addlo = bfd_get_32 (input_bfd, contents + rello->r_offset);
3656 addend += ((insn & 0xffff) << 16) + addlo;
3658 if ((addlo & 0x8000) != 0)
3660 if ((addend & 0x8000) != 0)
3663 bfd_put_32 (input_bfd,
3664 (insn & 0xffff0000) | ((addend >> 16) & 0xffff),
3665 contents + relhi->r_offset);
3668 /* Handle a MIPS ELF local GOT16 reloc. */
3671 mips_elf_relocate_got_local (output_bfd, input_bfd, sgot, relhi, rello,
3676 Elf_Internal_Rela *relhi;
3677 Elf_Internal_Rela *rello;
3687 bfd_byte *got_contents;
3688 struct mips_got_info *g;
3690 insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
3692 addlo = bfd_get_32 (input_bfd, contents + rello->r_offset);
3695 addend += ((insn & 0xffff) << 16) + addlo;
3697 if ((addlo & 0x8000) != 0)
3699 if ((addend & 0x8000) != 0)
3702 /* Get a got entry representing requested hipage. */
3703 BFD_ASSERT (elf_section_data (sgot) != NULL);
3704 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
3705 BFD_ASSERT (g != NULL);
3707 local_gotno = g->local_gotno;
3708 got_contents = sgot->contents;
3709 hipage = addend & 0xffff0000;
3711 for (i = MIPS_RESERVED_GOTNO; i < local_gotno; i++)
3713 address = bfd_get_32 (input_bfd, got_contents + i * 4);
3714 if (hipage == (address & 0xffff0000))
3716 if (address == (bfd_vma) 0)
3718 bfd_put_32 (input_bfd, hipage, got_contents + i * 4);
3723 BFD_ASSERT (i < local_gotno);
3725 if (i == local_gotno)
3726 (*_bfd_error_handler)
3727 ("ELF MIPS linker: more got entries are needed for hipage: %x",
3731 i = - ELF_MIPS_GP_OFFSET (output_bfd) + i * 4;
3732 bfd_put_32 (input_bfd, (insn & 0xffff0000) | (i & 0xffff),
3733 contents + relhi->r_offset);
3736 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
3739 mips_elf_relocate_global_got (input_bfd, rel, contents, offset)
3741 Elf_Internal_Rela *rel;
3747 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3748 bfd_put_32 (input_bfd,
3749 (insn & 0xffff0000) | (offset & 0xffff),
3750 contents + rel->r_offset);
3753 /* Relocate a MIPS ELF section. */
3756 mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
3757 contents, relocs, local_syms, local_sections)
3759 struct bfd_link_info *info;
3761 asection *input_section;
3763 Elf_Internal_Rela *relocs;
3764 Elf_Internal_Sym *local_syms;
3765 asection **local_sections;
3767 Elf_Internal_Shdr *symtab_hdr;
3770 asection *sgot, *sreloc, *scpt;
3772 Elf_Internal_Rela *rel;
3773 Elf_Internal_Rela *relend;
3774 struct mips_got_info *g;
3776 dynobj = elf_hash_table (info)->dynobj;
3777 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3781 if (dynobj == NULL || ! SGI_COMPAT (output_bfd))
3784 scpt = bfd_get_section_by_name (dynobj, ".compact_rel");
3787 if (elf_bad_symtab (input_bfd))
3789 locsymcount = symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
3794 locsymcount = symtab_hdr->sh_info;
3795 extsymoff = symtab_hdr->sh_info;
3799 relend = relocs + input_section->reloc_count;
3800 for (; rel < relend; rel++)
3803 reloc_howto_type *howto;
3804 unsigned long r_symndx;
3807 struct elf_link_hash_entry *h;
3809 Elf_Internal_Sym *sym;
3810 bfd_reloc_status_type r;
3812 r_type = ELF32_R_TYPE (rel->r_info);
3813 if (r_type < 0 || r_type >= (int) R_MIPS_max)
3815 bfd_set_error (bfd_error_bad_value);
3818 howto = elf_mips_howto_table + r_type;
3821 && (r_type == R_MIPS_CALL16
3822 || r_type == R_MIPS_GOT16
3823 || r_type == R_MIPS_CALL_HI16
3824 || r_type == R_MIPS_CALL_LO16
3825 || r_type == R_MIPS_GOT_HI16
3826 || r_type == R_MIPS_GOT_LO16))
3828 /* We need the .got section. */
3831 sgot = bfd_get_section_by_name (dynobj, ".got");
3832 BFD_ASSERT (sgot != NULL);
3833 BFD_ASSERT (elf_section_data (sgot) != NULL);
3834 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
3835 BFD_ASSERT (g != NULL);
3839 r_symndx = ELF32_R_SYM (rel->r_info);
3841 gp = _bfd_get_gp_value (output_bfd);
3843 /* Mix in the change in GP address for a GP relative reloc. */
3844 if (r_type != R_MIPS_GPREL16
3845 && r_type != R_MIPS_LITERAL
3846 && r_type != R_MIPS_GPREL32)
3852 if (! ((*info->callbacks->reloc_dangerous)
3854 "GP relative relocation when GP not defined",
3855 input_bfd, input_section,
3858 /* Only give the error once per link. */
3860 _bfd_set_gp_value (output_bfd, gp);
3863 if (r_symndx < extsymoff
3864 || (elf_bad_symtab (input_bfd)
3865 && local_sections[r_symndx] != NULL))
3867 /* This is a relocation against a section. The current
3868 addend in the instruction is the difference between
3869 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
3870 must change this to be the difference between the
3871 final definition (which will end up in RELOCATION)
3872 and the GP value of OUTPUT_BFD (which is in GP). */
3873 addend = elf_gp (input_bfd) - gp;
3875 else if (! info->relocateable)
3877 /* We are doing a final link. The current addend in the
3878 instruction is simply the desired offset into the
3879 symbol (normally zero). We want the instruction to
3880 hold the difference between the final definition of
3881 the symbol (which will end up in RELOCATION) and the
3882 GP value of OUTPUT_BFD (which is in GP). */
3887 /* We are generating relocateable output, and we aren't
3888 going to define this symbol, so we just leave the
3889 instruction alone. */
3897 if (info->relocateable)
3899 /* This is a relocateable link. We don't have to change
3900 anything, unless the reloc is against a section symbol,
3901 in which case we have to adjust according to where the
3902 section symbol winds up in the output section. */
3903 if (r_symndx >= locsymcount
3904 || (elf_bad_symtab (input_bfd)
3905 && local_sections[r_symndx] == NULL))
3909 sym = local_syms + r_symndx;
3910 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
3914 sec = local_sections[r_symndx];
3916 /* It would be logical to add sym->st_value here,
3917 but Irix 5 sometimes generates a garbage symbol
3919 addend += sec->output_offset;
3921 /* If this is HI16 or GOT16 with an associated LO16,
3922 adjust the addend accordingly. Otherwise, just
3924 if ((r_type != R_MIPS_HI16 && r_type != R_MIPS_GOT16)
3925 || (rel + 1) >= relend
3926 || ELF32_R_TYPE ((rel + 1)->r_info) != R_MIPS_LO16)
3927 r = _bfd_relocate_contents (howto, input_bfd,
3929 contents + rel->r_offset);
3932 mips_elf_relocate_hi16 (input_bfd, rel, rel + 1,
3944 /* This is a final link. */
3946 if (r_symndx < extsymoff
3947 || (elf_bad_symtab (input_bfd)
3948 && local_sections[r_symndx] != NULL))
3951 sym = local_syms + r_symndx;
3952 sec = local_sections[r_symndx];
3953 relocation = (sec->output_section->vma
3954 + sec->output_offset);
3956 /* It would be logical to always add sym->st_value here,
3957 but Irix 5 sometimes generates a garbage symbol
3959 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
3960 relocation += sym->st_value;
3967 indx = r_symndx - extsymoff;
3968 h = elf_sym_hashes (input_bfd)[indx];
3969 while (h->root.type == bfd_link_hash_indirect
3970 || h->root.type == bfd_link_hash_warning)
3971 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3972 if (strcmp (h->root.root.string, "_gp_disp") == 0)
3976 if (! ((*info->callbacks->reloc_dangerous)
3978 "_gp_disp used when GP not defined",
3979 input_bfd, input_section,
3982 /* Only give the error once per link. */
3984 _bfd_set_gp_value (output_bfd, gp);
3989 sec = input_section;
3990 if (sec->output_section != NULL)
3993 + sec->output_section->vma
3994 + sec->output_offset));
3996 relocation = gp - rel->r_offset;
3997 if (r_type == R_MIPS_LO16)
4001 else if (h->root.type == bfd_link_hash_defined
4002 || h->root.type == bfd_link_hash_defweak)
4004 sec = h->root.u.def.section;
4005 if (sec->output_section == NULL)
4008 relocation = (h->root.u.def.value
4009 + sec->output_section->vma
4010 + sec->output_offset);
4012 else if (h->root.type == bfd_link_hash_undefweak)
4014 else if (info->shared && ! info->symbolic)
4016 else if (strcmp (h->root.root.string, "_DYNAMIC_LINK") == 0)
4018 /* If this is a dynamic link, we should have created
4019 a _DYNAMIC_LINK symbol in
4020 mips_elf_create_dynamic_sections. Otherwise, we
4021 should define the symbol with a value of 0.
4022 FIXME: It should probably get into the symbol
4023 table somehow as well. */
4024 BFD_ASSERT (! info->shared);
4025 BFD_ASSERT (bfd_get_section_by_name (output_bfd,
4026 ".dynamic") == NULL);
4031 if (! ((*info->callbacks->undefined_symbol)
4032 (info, h->root.root.string, input_bfd,
4033 input_section, rel->r_offset)))
4039 if (r_type == R_MIPS_HI16
4040 && (rel + 1) < relend
4041 && ELF32_R_TYPE ((rel + 1)->r_info) == R_MIPS_LO16)
4043 mips_elf_relocate_hi16 (input_bfd, rel, rel + 1,
4044 contents, relocation + addend);
4047 else if (r_type == R_MIPS_GOT16 && local)
4049 /* GOT16 must be also with associated LO16 in the local
4050 case. In this case, the addend is extracted and the
4051 section in which the referenced object is determined.
4052 Then the final address of the object is computed and
4053 the GOT entry for the hipage (an aligned 64kb chunk)
4054 is added to .got section if needed. The offset field
4055 of the GOT16-relocated instruction is replaced by the
4056 index of this GOT entry for the hipage. */
4057 if ((rel + 1) < relend
4058 && ELF32_R_TYPE ((rel + 1)->r_info) == R_MIPS_LO16)
4060 mips_elf_relocate_got_local (output_bfd, input_bfd, sgot,
4063 relocation + addend);
4067 r = bfd_reloc_outofrange;
4069 else if (r_type == R_MIPS_CALL16
4070 || r_type == R_MIPS_GOT16
4071 || r_type == R_MIPS_CALL_LO16
4072 || r_type == R_MIPS_GOT_LO16)
4076 /* This symbol must be registered as a global symbol
4077 having the corresponding got entry. */
4078 BFD_ASSERT (h->got_offset != (bfd_vma) -1);
4080 offset = (h->dynindx - g->global_gotsym + g->local_gotno) * 4;
4081 BFD_ASSERT (g->local_gotno <= offset
4082 && offset < sgot->_raw_size);
4083 bfd_put_32 (output_bfd, relocation + addend,
4084 sgot->contents + offset);
4085 offset = (sgot->output_section->vma + sgot->output_offset
4087 mips_elf_relocate_global_got (input_bfd, rel, contents,
4091 else if (r_type == R_MIPS_CALL_HI16
4092 || r_type == R_MIPS_GOT_HI16)
4096 /* This must be a global symbol with a got entry. The
4097 next reloc must be the corresponding LO16 reloc. */
4098 BFD_ASSERT (h != NULL && h->got_offset != (bfd_vma) -1);
4099 BFD_ASSERT ((rel + 1) < relend);
4100 BFD_ASSERT (ELF32_R_TYPE ((rel + 1)->r_info)
4101 == (r_type == R_MIPS_CALL_HI16
4103 : R_MIPS_GOT_LO16));
4105 offset = (h->dynindx - g->global_gotsym + g->local_gotno) * 4;
4106 BFD_ASSERT (g->local_gotno <= offset
4107 && offset < sgot->_raw_size);
4108 bfd_put_32 (output_bfd, relocation + addend,
4109 sgot->contents + offset);
4110 offset = (sgot->output_section->vma + sgot->output_offset
4112 mips_elf_relocate_hi16 (input_bfd, rel, rel + 1, contents,
4116 else if (r_type == R_MIPS_REL32
4117 || r_type == R_MIPS_32)
4119 Elf_Internal_Rel outrel;
4120 Elf32_crinfo cptrel;
4124 && (input_section->flags & SEC_ALLOC) != 0)
4126 /* When generating a shared object, these
4127 relocations are copied into the output file to be
4128 resolved at run time. */
4131 sreloc = bfd_get_section_by_name (dynobj, ".rel.dyn");
4132 BFD_ASSERT (sreloc != NULL);
4135 outrel.r_offset = (rel->r_offset
4136 + input_section->output_section->vma
4137 + input_section->output_offset);
4139 addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
4142 && (! info->symbolic
4143 || (h->elf_link_hash_flags
4144 & ELF_LINK_HASH_DEF_REGULAR) == 0))
4146 BFD_ASSERT (h->dynindx != -1);
4147 outrel.r_info = ELF32_R_INFO (h->dynindx, R_MIPS_REL32);
4148 sec = input_section;
4155 sec = local_sections[r_symndx];
4158 BFD_ASSERT (h->root.type == bfd_link_hash_defined
4160 == bfd_link_hash_defweak));
4161 sec = h->root.u.def.section;
4163 if (sec != NULL && bfd_is_abs_section (sec))
4165 else if (sec == NULL || sec->owner == NULL)
4167 bfd_set_error (bfd_error_bad_value);
4174 osec = sec->output_section;
4175 indx = elf_section_data (osec)->dynindx;
4180 outrel.r_info = ELF32_R_INFO (indx, R_MIPS_REL32);
4181 addend += relocation;
4184 bfd_put_32 (output_bfd, addend, contents + rel->r_offset);
4185 bfd_elf32_swap_reloc_out (output_bfd, &outrel,
4186 (((Elf32_External_Rel *)
4188 + sreloc->reloc_count));
4189 ++sreloc->reloc_count;
4191 if (SGI_COMPAT (output_bfd))
4196 /* Make an entry of compact relocation info. */
4197 mips_elf_set_cr_format (cptrel, CRF_MIPS_LONG);
4198 cptrel.vaddr = (rel->r_offset
4199 + input_section->output_section->vma
4200 + input_section->output_offset);
4201 if (r_type == R_MIPS_REL32)
4202 mips_elf_set_cr_type (cptrel, CRT_MIPS_REL32);
4204 mips_elf_set_cr_type (cptrel, CRT_MIPS_WORD);
4205 mips_elf_set_cr_dist2to (cptrel, 0);
4206 cptrel.konst = addend;
4208 cr = (scpt->contents
4209 + sizeof (Elf32_External_compact_rel));
4210 bfd_elf32_swap_crinfo_out (output_bfd, &cptrel,
4211 ((Elf32_External_crinfo *) cr
4212 + scpt->reloc_count));
4213 ++scpt->reloc_count;
4216 /* This reloc will be computed at runtime, so
4217 there's no need to do anything now. */
4221 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4222 contents, rel->r_offset,
4223 relocation, addend);
4226 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4227 contents, rel->r_offset,
4228 relocation, addend);
4230 if (SGI_COMPAT (abfd)
4232 && (input_section->flags & SEC_ALLOC) != 0)
4234 Elf32_crinfo cptrel;
4237 /* Make an entry of compact relocation info. */
4238 mips_elf_set_cr_format (cptrel, CRF_MIPS_LONG);
4239 cptrel.vaddr = (rel->r_offset
4240 + input_section->output_section->vma
4241 + input_section->output_offset);
4246 mips_elf_set_cr_type (cptrel, CRT_MIPS_JMPAD);
4247 /* XXX How should we set dist2to in this case. */
4248 mips_elf_set_cr_dist2to (cptrel, 8);
4249 cptrel.konst = addend + relocation;
4250 cr = scpt->contents + sizeof (Elf32_External_compact_rel);
4251 bfd_elf32_swap_crinfo_out (output_bfd, &cptrel,
4252 ((Elf32_External_crinfo *) cr
4253 + scpt->reloc_count));
4254 ++scpt->reloc_count;
4257 case R_MIPS_GPREL16:
4258 case R_MIPS_LITERAL:
4259 case R_MIPS_GPREL32:
4260 mips_elf_set_cr_type (cptrel, CRT_MIPS_GPHI_LO);
4261 cptrel.konst = gp - cptrel.vaddr;
4262 mips_elf_set_cr_dist2to (cptrel, 4);
4263 cr = scpt->contents + sizeof (Elf32_External_compact_rel);
4264 bfd_elf32_swap_crinfo_out (output_bfd, &cptrel,
4265 ((Elf32_External_crinfo *) cr
4266 + scpt->reloc_count));
4267 ++scpt->reloc_count;
4276 if (r != bfd_reloc_ok)
4281 case bfd_reloc_outofrange:
4283 case bfd_reloc_overflow:
4288 name = h->root.root.string;
4291 name = bfd_elf_string_from_elf_section (input_bfd,
4292 symtab_hdr->sh_link,
4297 name = bfd_section_name (input_bfd, sec);
4299 if (! ((*info->callbacks->reloc_overflow)
4300 (info, name, howto->name, (bfd_vma) 0,
4301 input_bfd, input_section, rel->r_offset)))
4312 /* Functions for the dynamic linker. */
4314 /* The name of the dynamic interpreter. This is put in the .interp
4317 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
4319 /* Create dynamic sections when linking against a dynamic object. */
4322 mips_elf_create_dynamic_sections (abfd, info)
4324 struct bfd_link_info *info;
4326 struct elf_link_hash_entry *h;
4328 register asection *s;
4329 const char * const *namep;
4331 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4334 /* Mips ABI requests the .dynamic section to be read only. */
4335 s = bfd_get_section_by_name (abfd, ".dynamic");
4338 if (! bfd_set_section_flags (abfd, s, flags))
4342 /* We need to create .got section. */
4343 if (! mips_elf_create_got_section (abfd, info))
4346 /* Create .stub section. */
4347 if (bfd_get_section_by_name (abfd, ".stub") == NULL)
4349 s = bfd_make_section (abfd, ".stub");
4351 || ! bfd_set_section_flags (abfd, s, flags)
4352 || ! bfd_set_section_alignment (abfd, s, 2))
4356 if (SGI_COMPAT (abfd))
4358 for (namep = mips_elf_dynsym_rtproc_names; *namep != NULL; namep++)
4361 if (! (_bfd_generic_link_add_one_symbol
4362 (info, abfd, *namep, BSF_GLOBAL, bfd_und_section_ptr,
4363 (bfd_vma) 0, (const char *) NULL, false,
4364 get_elf_backend_data (abfd)->collect,
4365 (struct bfd_link_hash_entry **) &h)))
4367 h->elf_link_hash_flags &=~ ELF_LINK_NON_ELF;
4368 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
4369 h->type = STT_SECTION;
4371 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
4375 /* We need to create a .compact_rel section. */
4376 if (! mips_elf_create_compact_rel_section (abfd, info))
4379 /* Change aligments of some sections. */
4380 s = bfd_get_section_by_name (abfd, ".hash");
4382 bfd_set_section_alignment (abfd, s, 4);
4383 s = bfd_get_section_by_name (abfd, ".dynsym");
4385 bfd_set_section_alignment (abfd, s, 4);
4386 s = bfd_get_section_by_name (abfd, ".dynstr");
4388 bfd_set_section_alignment (abfd, s, 4);
4389 s = bfd_get_section_by_name (abfd, ".reginfo");
4391 bfd_set_section_alignment (abfd, s, 4);
4392 s = bfd_get_section_by_name (abfd, ".dynamic");
4394 bfd_set_section_alignment (abfd, s, 4);
4400 if (! (_bfd_generic_link_add_one_symbol
4401 (info, abfd, "_DYNAMIC_LINK", BSF_GLOBAL, bfd_abs_section_ptr,
4402 (bfd_vma) 0, (const char *) NULL, false,
4403 get_elf_backend_data (abfd)->collect,
4404 (struct bfd_link_hash_entry **) &h)))
4406 h->elf_link_hash_flags ^=~ ELF_LINK_NON_ELF;
4407 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
4408 h->type = STT_SECTION;
4410 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
4417 /* Create the .compact_rel section. */
4420 mips_elf_create_compact_rel_section (abfd, info)
4422 struct bfd_link_info *info;
4425 register asection *s;
4427 if (bfd_get_section_by_name (abfd, ".compact_rel") == NULL)
4429 flags = SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_READONLY;
4431 s = bfd_make_section (abfd, ".compact_rel");
4433 || ! bfd_set_section_flags (abfd, s, flags)
4434 || ! bfd_set_section_alignment (abfd, s, 2))
4437 s->_raw_size = sizeof (Elf32_External_compact_rel);
4443 /* Create the .got section to hold the global offset table. */
4446 mips_elf_create_got_section (abfd, info)
4448 struct bfd_link_info *info;
4451 register asection *s;
4452 struct elf_link_hash_entry *h;
4453 struct mips_got_info *g;
4455 /* This function may be called more than once. */
4456 if (bfd_get_section_by_name (abfd, ".got") != NULL)
4459 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
4461 s = bfd_make_section (abfd, ".got");
4463 || ! bfd_set_section_flags (abfd, s, flags)
4464 || ! bfd_set_section_alignment (abfd, s, 4))
4467 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
4468 linker script because we don't want to define the symbol if we
4469 are not creating a global offset table. */
4471 if (! (_bfd_generic_link_add_one_symbol
4472 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
4473 (bfd_vma) 0, (const char *) NULL, false,
4474 get_elf_backend_data (abfd)->collect,
4475 (struct bfd_link_hash_entry **) &h)))
4477 h->elf_link_hash_flags &=~ ELF_LINK_NON_ELF;
4478 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
4479 h->type = STT_OBJECT;
4482 && ! bfd_elf32_link_record_dynamic_symbol (info, h))
4485 /* The first several global offset table entries are reserved. */
4486 s->_raw_size = MIPS_RESERVED_GOTNO * 4;
4488 g = (struct mips_got_info *) bfd_alloc (abfd,
4489 sizeof (struct mips_got_info));
4492 g->global_gotsym = 0;
4493 g->local_gotno = MIPS_RESERVED_GOTNO;
4494 if (elf_section_data (s) == NULL)
4497 (PTR) bfd_zalloc (abfd, sizeof (struct bfd_elf_section_data));
4498 if (elf_section_data (s) == NULL)
4501 elf_section_data (s)->tdata = (PTR) g;
4506 /* Look through the relocs for a section during the first phase, and
4507 allocate space in the global offset table. */
4510 mips_elf_check_relocs (abfd, info, sec, relocs)
4512 struct bfd_link_info *info;
4514 const Elf_Internal_Rela *relocs;
4517 Elf_Internal_Shdr *symtab_hdr;
4518 struct elf_link_hash_entry **sym_hashes;
4519 struct mips_got_info *g;
4521 const Elf_Internal_Rela *rel;
4522 const Elf_Internal_Rela *rel_end;
4526 if (info->relocateable)
4529 dynobj = elf_hash_table (info)->dynobj;
4530 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4531 sym_hashes = elf_sym_hashes (abfd);
4532 extsymoff = (elf_bad_symtab (abfd)) ? 0 : symtab_hdr->sh_info;
4537 rel_end = relocs + sec->reloc_count;
4538 for (rel = relocs; rel < rel_end; rel++)
4540 unsigned long r_symndx;
4541 struct elf_link_hash_entry *h;
4543 r_symndx = ELF32_R_SYM (rel->r_info);
4545 if (r_symndx < extsymoff)
4548 h = sym_hashes[r_symndx - extsymoff];
4550 /* Some relocs require a global offset table. */
4553 switch (ELF32_R_TYPE (rel->r_info))
4557 case R_MIPS_CALL_HI16:
4558 case R_MIPS_CALL_LO16:
4559 case R_MIPS_GOT_HI16:
4560 case R_MIPS_GOT_LO16:
4561 elf_hash_table (info)->dynobj = dynobj = abfd;
4562 if (! mips_elf_create_got_section (dynobj, info))
4571 switch (ELF32_R_TYPE (rel->r_info))
4574 case R_MIPS_CALL_HI16:
4575 case R_MIPS_CALL_LO16:
4576 /* This symbol requires a global offset table entry. */
4579 sgot = bfd_get_section_by_name (dynobj, ".got");
4580 BFD_ASSERT (sgot != NULL);
4581 BFD_ASSERT (elf_section_data (sgot) != NULL);
4582 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
4583 BFD_ASSERT (g != NULL);
4586 BFD_ASSERT (h != NULL);
4588 /* Make sure this symbol is output as a dynamic symbol. */
4589 if (h->dynindx == -1)
4591 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
4595 if (h->got_offset != (bfd_vma) -1)
4597 /* We have already allocated space in the .got. */
4601 /* Note the index of the first global got symbol in .dynsym. */
4602 if (g->global_gotsym == 0
4603 || g->global_gotsym > (unsigned long) h->dynindx)
4604 g->global_gotsym = h->dynindx;
4606 /* Make this symbol to have the corresponding got entry. */
4609 /* We need a stub, not a plt entry for the undefined
4610 function. But we record it as if it needs plt. See
4611 elf_adjust_dynamic_symbol in elflink.h. */
4612 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
4618 case R_MIPS_GOT_HI16:
4619 case R_MIPS_GOT_LO16:
4620 /* This symbol requires a global offset table entry. */
4623 sgot = bfd_get_section_by_name (dynobj, ".got");
4624 BFD_ASSERT (sgot != NULL);
4625 BFD_ASSERT (elf_section_data (sgot) != NULL);
4626 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
4627 BFD_ASSERT (g != NULL);
4632 /* Make sure this symbol is output as a dynamic symbol. */
4633 if (h->dynindx == -1)
4635 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
4639 if (h->got_offset != (bfd_vma) -1)
4641 /* We have already allocated space in the .got. */
4644 /* Note the index of the first global got symbol in
4646 if (g->global_gotsym == 0
4647 || g->global_gotsym > (unsigned long) h->dynindx)
4648 g->global_gotsym = h->dynindx;
4650 /* Make this symbol to be the global got symbol. */
4659 && (sec->flags & SEC_ALLOC) != 0)
4661 /* When creating a shared object, we must copy these
4662 reloc types into the output file as R_MIPS_REL32
4663 relocs. We create the .rel.dyn reloc section in
4664 dynobj and make room for this reloc. */
4667 const char *name = ".rel.dyn";
4669 sreloc = bfd_get_section_by_name (dynobj, name);
4672 sreloc = bfd_make_section (dynobj, name);
4674 || ! bfd_set_section_flags (dynobj, sreloc,
4680 || ! bfd_set_section_alignment (dynobj, sreloc, 4))
4683 /* Add a null element. */
4684 sreloc->_raw_size += sizeof (Elf32_External_Rel);
4685 ++sreloc->reloc_count;
4689 sreloc->_raw_size += sizeof (Elf32_External_Rel);
4692 if (SGI_COMPAT (abfd))
4693 mips_elf_hash_table (info)->compact_rel_size +=
4694 sizeof (Elf32_External_crinfo);
4699 case R_MIPS_GPREL16:
4700 case R_MIPS_LITERAL:
4701 case R_MIPS_GPREL32:
4702 if (SGI_COMPAT (abfd))
4703 mips_elf_hash_table (info)->compact_rel_size +=
4704 sizeof (Elf32_External_crinfo);
4715 /* Adjust a symbol defined by a dynamic object and referenced by a
4716 regular object. The current definition is in some section of the
4717 dynamic object, but we're not including those sections. We have to
4718 change the definition to something the rest of the link can
4722 mips_elf_adjust_dynamic_symbol (info, h)
4723 struct bfd_link_info *info;
4724 struct elf_link_hash_entry *h;
4729 dynobj = elf_hash_table (info)->dynobj;
4731 /* Make sure we know what is going on here. */
4732 BFD_ASSERT (dynobj != NULL
4733 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
4734 || h->weakdef != NULL
4735 || ((h->elf_link_hash_flags
4736 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
4737 && (h->elf_link_hash_flags
4738 & ELF_LINK_HASH_REF_REGULAR) != 0
4739 && (h->elf_link_hash_flags
4740 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
4742 /* For a function, create a stub, if needed. */
4743 if (h->type == STT_FUNC
4744 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
4746 if (! elf_hash_table (info)->dynamic_sections_created)
4749 /* If this symbol is not defined in a regular file, then set
4750 the symbol to the stub location. This is required to make
4751 function pointers compare as equal between the normal
4752 executable and the shared library. */
4753 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
4755 /* We need .stub section. */
4756 s = bfd_get_section_by_name (dynobj, ".stub");
4757 BFD_ASSERT (s != NULL);
4759 h->root.u.def.section = s;
4760 h->root.u.def.value = s->_raw_size;
4762 /* XXX Write this stub address somewhere. */
4763 h->plt_offset = s->_raw_size;
4765 /* Make room for this stub code. */
4766 s->_raw_size += MIPS_FUNCTION_STUB_SIZE;
4768 /* The last half word of the stub will be filled with the index
4769 of this symbol in .dynsym section. */
4774 /* If this is a weak symbol, and there is a real definition, the
4775 processor independent code will have arranged for us to see the
4776 real definition first, and we can just use the same value. */
4777 if (h->weakdef != NULL)
4779 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
4780 || h->weakdef->root.type == bfd_link_hash_defweak);
4781 h->root.u.def.section = h->weakdef->root.u.def.section;
4782 h->root.u.def.value = h->weakdef->root.u.def.value;
4786 /* This is a reference to a symbol defined by a dynamic object which
4787 is not a function. */
4792 /* Set the sizes of the dynamic sections. */
4795 mips_elf_size_dynamic_sections (output_bfd, info)
4797 struct bfd_link_info *info;
4803 struct mips_got_info *g;
4805 dynobj = elf_hash_table (info)->dynobj;
4806 BFD_ASSERT (dynobj != NULL);
4808 if (elf_hash_table (info)->dynamic_sections_created)
4810 /* Set the contents of the .interp section to the interpreter. */
4813 s = bfd_get_section_by_name (dynobj, ".interp");
4814 BFD_ASSERT (s != NULL);
4815 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
4816 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4820 /* Recompute the size of .got for local entires (reserved and
4821 hipages) if needed. To estimate it, get the upper bound of total
4822 size of loadable sections. */
4823 sgot = bfd_get_section_by_name (dynobj, ".got");
4827 bfd_size_type loadable_size = 0;
4828 bfd_size_type local_gotno;
4831 BFD_ASSERT (elf_section_data (sgot) != NULL);
4832 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
4833 BFD_ASSERT (g != NULL);
4835 for (sub = info->input_bfds; sub; sub = sub->link_next)
4836 for (s = sub->sections; s != NULL; s = s->next)
4838 if ((s->flags & SEC_ALLOC) == 0)
4840 loadable_size += (s->_raw_size + 0xf) & ~0xf;
4843 loadable_size += MIPS_FUNCTION_STUB_SIZE;
4845 /* Assume there are two loadable segments consisting of
4846 contiguous sections. Is 5 enough? */
4847 local_gotno = (loadable_size >> 16) + 5 + MIPS_RESERVED_GOTNO;
4848 g->local_gotno = local_gotno;
4849 sgot->_raw_size += local_gotno * 4;
4852 /* The check_relocs and adjust_dynamic_symbol entry points have
4853 determined the sizes of the various dynamic sections. Allocate
4856 for (s = dynobj->sections; s != NULL; s = s->next)
4861 /* It's OK to base decisions on the section name, because none
4862 of the dynobj section names depend upon the input files. */
4863 name = bfd_get_section_name (dynobj, s);
4865 if ((s->flags & SEC_IN_MEMORY) == 0)
4870 if (strncmp (name, ".rel", 4) == 0)
4872 if (s->_raw_size == 0)
4878 /* If this relocation section applies to a read only
4879 section, then we probably need a DT_TEXTREL entry.
4880 If the relocation section is .rel.dyn, we always
4881 assert a DT_TEXTREL entry rather than testing whether
4882 there exists a relocation to a read only section or
4884 target = bfd_get_section_by_name (output_bfd, name + 4);
4885 if ((target != NULL && (target->flags & SEC_READONLY) != 0)
4886 || strcmp (name, ".rel.dyn") == 0)
4889 /* We use the reloc_count field as a counter if we need
4890 to copy relocs into the output file. */
4891 if (strcmp (name, ".rel.dyn") != 0)
4895 else if (strncmp (name, ".got", 4) == 0)
4899 BFD_ASSERT (elf_section_data (s) != NULL);
4900 g = (struct mips_got_info *) elf_section_data (s)->tdata;
4901 BFD_ASSERT (g != NULL);
4903 /* Fix the size of .got section for the correspondence of
4904 global symbols and got entries. This adds some useless
4905 got entries. Is this required by ABI really? */
4906 i = elf_hash_table (info)->dynsymcount - g->global_gotsym;
4907 s->_raw_size += i * 4;
4909 else if (strncmp (name, ".stub", 5) == 0)
4911 /* Irix rld assumes that the function stub isn't at the end
4912 of .text section. So put a dummy. XXX */
4913 s->_raw_size += MIPS_FUNCTION_STUB_SIZE;
4915 else if (SGI_COMPAT (output_bfd)
4916 && strncmp (name, ".compact_rel", 12) == 0)
4917 s->_raw_size += mips_elf_hash_table (info)->compact_rel_size;
4918 else if (strncmp (name, ".init", 5) != 0)
4920 /* It's not one of our sections, so don't allocate space. */
4928 for (spp = &s->output_section->owner->sections;
4929 *spp != s->output_section;
4930 spp = &(*spp)->next)
4932 *spp = s->output_section->next;
4933 --s->output_section->owner->section_count;
4938 /* Allocate memory for the section contents. */
4939 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
4940 if (s->contents == NULL && s->_raw_size != 0)
4942 bfd_set_error (bfd_error_no_memory);
4945 memset (s->contents, 0, s->_raw_size);
4948 if (elf_hash_table (info)->dynamic_sections_created)
4950 /* Add some entries to the .dynamic section. We fill in the
4951 values later, in elf_mips_finish_dynamic_sections, but we
4952 must add the entries now so that we get the correct size for
4953 the .dynamic section. The DT_DEBUG entry is filled in by the
4954 dynamic linker and used by the debugger. */
4957 if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
4963 if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
4967 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0))
4970 if (bfd_get_section_by_name (dynobj, ".rel.dyn"))
4972 if (! bfd_elf32_add_dynamic_entry (info, DT_REL, 0))
4975 if (! bfd_elf32_add_dynamic_entry (info, DT_RELSZ, 0))
4978 if (! bfd_elf32_add_dynamic_entry (info, DT_RELENT, 0))
4982 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_CONFLICTNO, 0))
4985 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_LIBLISTNO, 0))
4988 if (bfd_get_section_by_name (dynobj, ".conflict") != NULL)
4990 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_CONFLICT, 0))
4993 s = bfd_get_section_by_name (dynobj, ".liblist");
4994 BFD_ASSERT (s != NULL);
4996 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_LIBLIST, 0))
5000 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_RLD_VERSION, 0))
5003 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_FLAGS, 0))
5007 /* Time stamps in executable files are a bad idea. */
5008 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_TIME_STAMP, 0))
5013 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_ICHECKSUM, 0))
5018 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_IVERSION, 0))
5022 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_BASE_ADDRESS, 0))
5025 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_LOCAL_GOTNO, 0))
5028 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_SYMTABNO, 0))
5031 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_UNREFEXTNO, 0))
5034 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_GOTSYM, 0))
5037 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_HIPAGENO, 0))
5040 #if 0 /* (SGI_COMPAT) */
5041 if (! bfd_get_section_by_name (dynobj, ".init"))
5042 if (! bfd_elf32_add_dynamic_entry (info, DT_INIT, 0))
5045 if (! bfd_get_section_by_name (dynobj, ".fini"))
5046 if (! bfd_elf32_add_dynamic_entry (info, DT_FINI, 0))
5051 /* If we use dynamic linking, we generate a section symbol for each
5052 output section. These are local symbols, which means that they
5053 must come first in the dynamic symbol table.
5054 That means we must increment the dynamic symbol index of every
5055 other dynamic symbol. */
5057 const char * const *namep;
5059 bfd_size_type strindex;
5060 struct bfd_strtab_hash *dynstr;
5061 struct mips_got_info *g;
5063 if (elf_hash_table (info)->dynamic_sections_created)
5065 if (SGI_COMPAT (output_bfd))
5067 c = SIZEOF_MIPS_DYNSYM_SECNAMES - 1;
5068 elf_link_hash_traverse (elf_hash_table (info),
5069 mips_elf_adjust_dynindx,
5071 elf_hash_table (info)->dynsymcount += c;
5073 dynstr = elf_hash_table (info)->dynstr;
5074 BFD_ASSERT (dynstr != NULL);
5076 for (i = 1, namep = mips_elf_dynsym_sec_names;
5080 s = bfd_get_section_by_name (output_bfd, *namep);
5082 elf_section_data (s)->dynindx = i;
5084 strindex = _bfd_stringtab_add (dynstr, *namep, true, false);
5085 if (strindex == (bfd_size_type) -1)
5088 mips_elf_hash_table (info)->dynsym_sec_strindex[i] = strindex;
5093 c = bfd_count_sections (output_bfd);
5094 elf_link_hash_traverse (elf_hash_table (info),
5095 mips_elf_adjust_dynindx,
5097 elf_hash_table (info)->dynsymcount += c;
5099 for (i = 1, s = output_bfd->sections; s != NULL; s = s->next, i++)
5101 elf_section_data (s)->dynindx = i;
5102 /* These symbols will have no names, so we don't need to
5103 fiddle with dynstr_index. */
5108 s = bfd_get_section_by_name (dynobj, ".got");
5109 BFD_ASSERT (s != NULL);
5110 BFD_ASSERT (elf_section_data (s) != NULL);
5111 g = (struct mips_got_info *) elf_section_data (s)->tdata;
5112 BFD_ASSERT (g != NULL);
5114 /* If there are no global got symbols, fake the last symbol so for
5116 if (g->global_gotsym)
5117 g->global_gotsym += c;
5119 g->global_gotsym = elf_hash_table (info)->dynsymcount - 1;
5125 /* Increment the index of a dynamic symbol by a given amount. Called
5126 via elf_link_hash_traverse. */
5129 mips_elf_adjust_dynindx (h, cparg)
5130 struct elf_link_hash_entry *h;
5133 unsigned int *cp = (unsigned int *) cparg;
5135 if (h->dynindx != -1)
5140 /* Finish up dynamic symbol handling. We set the contents of various
5141 dynamic sections here. */
5144 mips_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
5146 struct bfd_link_info *info;
5147 struct elf_link_hash_entry *h;
5148 Elf_Internal_Sym *sym;
5153 struct mips_got_info *g;
5156 dynobj = elf_hash_table (info)->dynobj;
5157 gval = sym->st_value;
5159 if (h->plt_offset != (bfd_vma) -1)
5163 bfd_byte stub[MIPS_FUNCTION_STUB_SIZE];
5165 /* This symbol has a stub. Set it up. */
5167 BFD_ASSERT (h->dynindx != -1);
5169 s = bfd_get_section_by_name (dynobj, ".stub");
5170 BFD_ASSERT (s != NULL);
5172 /* Fill the stub. */
5174 bfd_put_32 (output_bfd, STUB_LW(output_bfd), p);
5176 bfd_put_32 (output_bfd, STUB_MOVE, p);
5179 /* FIXME: Can h->dynindex be more than 64K? */
5180 if (h->dynindx & 0xffff0000)
5183 bfd_put_32 (output_bfd, STUB_JALR, p);
5185 bfd_put_32 (output_bfd, STUB_LI16 + h->dynindx, p);
5187 BFD_ASSERT (h->plt_offset <= s->_raw_size);
5188 memcpy (s->contents + h->plt_offset, stub, MIPS_FUNCTION_STUB_SIZE);
5190 /* Mark the symbol as undefined. plt_offset != -1 occurs
5191 only for the referenced symbol. */
5192 sym->st_shndx = SHN_UNDEF;
5194 /* The run-time linker uses the st_value field of the symbol
5195 to reset the global offset table entry for this external
5196 to its stub address when unlinking a shared object. */
5197 gval = s->output_section->vma + s->output_offset + h->plt_offset;
5198 sym->st_value = gval;
5201 BFD_ASSERT (h->dynindx != -1);
5203 sgot = bfd_get_section_by_name (dynobj, ".got");
5204 BFD_ASSERT (sgot != NULL);
5205 BFD_ASSERT (elf_section_data (sgot) != NULL);
5206 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
5207 BFD_ASSERT (g != NULL);
5209 if ((unsigned long) h->dynindx >= g->global_gotsym)
5211 bfd_size_type offset;
5213 /* This symbol has an entry in the global offset table. Set its
5214 value to the corresponding got entry, if needed. */
5215 if (h->got_offset == (bfd_vma) -1)
5217 offset = (h->dynindx - g->global_gotsym + g->local_gotno) * 4;
5218 BFD_ASSERT (g->local_gotno * 4 <= offset
5219 && offset < sgot->_raw_size);
5220 bfd_put_32 (output_bfd, gval, sgot->contents + offset);
5224 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
5225 name = h->root.root.string;
5226 if (strcmp (name, "_DYNAMIC") == 0
5227 || strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
5228 sym->st_shndx = SHN_ABS;
5229 else if (strcmp (name, "_DYNAMIC_LINK") == 0)
5231 sym->st_shndx = SHN_ABS;
5232 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
5235 else if (SGI_COMPAT (output_bfd))
5237 if (strcmp (name, "_gp_disp") == 0)
5239 sym->st_shndx = SHN_ABS;
5240 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
5241 sym->st_value = _bfd_get_gp_value (output_bfd);
5243 else if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0
5244 || strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0)
5246 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
5247 sym->st_other = STO_PROTECTED;
5249 sym->st_shndx = SHN_MIPS_DATA;
5251 else if (strcmp (name, mips_elf_dynsym_rtproc_names[2]) == 0)
5253 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
5254 sym->st_other = STO_PROTECTED;
5255 sym->st_value = mips_elf_hash_table (info)->procedure_count;
5256 sym->st_shndx = SHN_ABS;
5258 else if (sym->st_shndx != SHN_UNDEF)
5260 if (h->type == STT_FUNC)
5261 sym->st_shndx = SHN_MIPS_TEXT;
5262 else if (h->type == STT_OBJECT)
5263 sym->st_shndx = SHN_MIPS_DATA;
5270 /* Finish up the dynamic sections. */
5273 mips_elf_finish_dynamic_sections (output_bfd, info)
5275 struct bfd_link_info *info;
5280 struct mips_got_info *g;
5282 dynobj = elf_hash_table (info)->dynobj;
5284 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
5286 sgot = bfd_get_section_by_name (dynobj, ".got");
5287 BFD_ASSERT (sgot != NULL);
5289 BFD_ASSERT (elf_section_data (sgot) != NULL);
5290 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
5291 BFD_ASSERT (g != NULL);
5293 if (elf_hash_table (info)->dynamic_sections_created)
5295 Elf32_External_Dyn *dyncon, *dynconend;
5297 BFD_ASSERT (sdyn != NULL);
5299 dyncon = (Elf32_External_Dyn *) sdyn->contents;
5300 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
5301 for (; dyncon < dynconend; dyncon++)
5303 Elf_Internal_Dyn dyn;
5308 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
5316 s = bfd_get_section_by_name (dynobj, ".rel.dyn");
5317 BFD_ASSERT (s != NULL);
5318 dyn.d_un.d_val = sizeof (Elf32_External_Rel);
5319 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5323 /* Rewrite DT_STRSZ. */
5325 _bfd_stringtab_size (elf_hash_table (info)->dynstr);
5326 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5332 case DT_MIPS_CONFLICT:
5335 case DT_MIPS_LIBLIST:
5338 s = bfd_get_section_by_name (output_bfd, name);
5339 BFD_ASSERT (s != NULL);
5340 dyn.d_un.d_ptr = s->vma;
5341 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5344 case DT_MIPS_RLD_VERSION:
5345 dyn.d_un.d_val = 1; /* XXX */
5346 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5350 dyn.d_un.d_val = RHF_NOTPOT; /* XXX */
5351 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5354 case DT_MIPS_CONFLICTNO:
5356 elemsize = sizeof (Elf32_Conflict);
5359 case DT_MIPS_LIBLISTNO:
5361 elemsize = sizeof (Elf32_Lib);
5363 s = bfd_get_section_by_name (output_bfd, name);
5366 if (s->_cooked_size != 0)
5367 dyn.d_un.d_val = s->_cooked_size / elemsize;
5369 dyn.d_un.d_val = s->_raw_size / elemsize;
5374 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5377 case DT_MIPS_TIME_STAMP:
5378 time ((time_t *) &dyn.d_un.d_val);
5379 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5382 case DT_MIPS_ICHECKSUM:
5386 case DT_MIPS_IVERSION:
5390 case DT_MIPS_BASE_ADDRESS:
5391 s = output_bfd->sections;
5392 BFD_ASSERT (s != NULL);
5393 dyn.d_un.d_ptr = s->vma & ~(0xffff);
5394 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5397 case DT_MIPS_LOCAL_GOTNO:
5398 dyn.d_un.d_val = g->local_gotno;
5399 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5402 case DT_MIPS_SYMTABNO:
5404 elemsize = sizeof (Elf32_External_Sym);
5405 s = bfd_get_section_by_name (output_bfd, name);
5406 BFD_ASSERT (s != NULL);
5408 if (s->_cooked_size != 0)
5409 dyn.d_un.d_val = s->_cooked_size / elemsize;
5411 dyn.d_un.d_val = s->_raw_size / elemsize;
5412 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5415 case DT_MIPS_UNREFEXTNO:
5417 dyn.d_un.d_val = SIZEOF_MIPS_DYNSYM_SECNAMES;
5418 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5421 case DT_MIPS_GOTSYM:
5422 dyn.d_un.d_val = g->global_gotsym;
5423 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5426 case DT_MIPS_HIPAGENO:
5427 dyn.d_un.d_val = g->local_gotno - MIPS_RESERVED_GOTNO;
5428 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5435 /* The first entry of the global offset table will be filled at
5436 runtime. The second entry will be used by some runtime loaders.
5437 This isn't the case of Irix rld. */
5438 if (sgot->_raw_size > 0)
5440 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
5441 bfd_put_32 (output_bfd, (bfd_vma) 0x80000000, sgot->contents + 4);
5444 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
5451 Elf_Internal_Sym sym;
5454 const char * const * namep = mips_elf_dynsym_sec_names;
5455 Elf32_compact_rel cpt;
5457 /* Set up the section symbols for the output sections. SGI sets
5458 the STT_NOTYPE attribute for these symbols. Should we do so? */
5460 sdynsym = bfd_get_section_by_name (dynobj, ".dynsym");
5461 if (sdynsym != NULL)
5463 if (SGI_COMPAT (output_bfd))
5467 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
5471 while ((name = *namep++) != NULL)
5473 s = bfd_get_section_by_name (output_bfd, name);
5476 sym.st_value = s->vma;
5477 dindx = elf_section_data (s)->dynindx;
5478 last = s->vma + s->_raw_size;
5482 sym.st_value = last;
5486 sym.st_shndx = (i < MIPS_TEXT_DYNSYM_SECNO
5491 mips_elf_hash_table (info)->dynsym_sec_strindex[dindx];
5493 bfd_elf32_swap_symbol_out (output_bfd, &sym,
5494 (((Elf32_External_Sym *)
5499 /* Set the sh_info field of the output .dynsym section to
5500 the index of the first global symbol. */
5501 elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
5502 SIZEOF_MIPS_DYNSYM_SECNAMES;
5508 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
5511 for (s = output_bfd->sections; s != NULL; s = s->next)
5515 sym.st_value = s->vma;
5517 indx = elf_section_data (s)->this_idx;
5518 BFD_ASSERT (indx > 0);
5519 sym.st_shndx = indx;
5521 bfd_elf32_swap_symbol_out (output_bfd, &sym,
5522 (((Elf32_External_Sym *)
5524 + elf_section_data (s)->dynindx));
5527 /* Set the sh_info field of the output .dynsym section to
5528 the index of the first global symbol. */
5529 elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
5530 bfd_count_sections (output_bfd) + 1;
5534 if (SGI_COMPAT (output_bfd))
5536 /* Write .compact_rel section out. */
5537 s = bfd_get_section_by_name (dynobj, ".compact_rel");
5541 cpt.num = s->reloc_count;
5543 cpt.offset = (s->output_section->filepos
5544 + sizeof (Elf32_External_compact_rel));
5547 bfd_elf32_swap_compact_rel_out (output_bfd, &cpt,
5548 ((Elf32_External_compact_rel *)
5551 /* Clean up a dummy stub function entry in .text. */
5552 s = bfd_get_section_by_name (dynobj, ".stub");
5555 file_ptr dummy_offset;
5557 BFD_ASSERT (s->_raw_size >= MIPS_FUNCTION_STUB_SIZE);
5558 dummy_offset = s->_raw_size - MIPS_FUNCTION_STUB_SIZE;
5559 memset (s->contents + dummy_offset, 0,
5560 MIPS_FUNCTION_STUB_SIZE);
5565 /* Clean up a first relocation in .rel.dyn. */
5566 s = bfd_get_section_by_name (dynobj, ".rel.dyn");
5568 memset (s->contents, 0, sizeof (Elf32_External_Rel));
5574 /* This is almost identical to bfd_generic_get_... except that some
5575 MIPS relocations need to be handled specially. Sigh. */
5578 elf32_mips_get_relocated_section_contents (abfd, link_info, link_order, data,
5579 relocateable, symbols)
5581 struct bfd_link_info *link_info;
5582 struct bfd_link_order *link_order;
5584 boolean relocateable;
5587 /* Get enough memory to hold the stuff */
5588 bfd *input_bfd = link_order->u.indirect.section->owner;
5589 asection *input_section = link_order->u.indirect.section;
5591 long reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section);
5592 arelent **reloc_vector = NULL;
5598 reloc_vector = (arelent **) bfd_malloc (reloc_size);
5599 if (reloc_vector == NULL && reloc_size != 0)
5602 /* read in the section */
5603 if (!bfd_get_section_contents (input_bfd,
5607 input_section->_raw_size))
5610 /* We're not relaxing the section, so just copy the size info */
5611 input_section->_cooked_size = input_section->_raw_size;
5612 input_section->reloc_done = true;
5614 reloc_count = bfd_canonicalize_reloc (input_bfd,
5618 if (reloc_count < 0)
5621 if (reloc_count > 0)
5626 bfd_vma gp = 0x12345678; /* initialize just to shut gcc up */
5629 struct bfd_hash_entry *h;
5630 struct bfd_link_hash_entry *lh;
5631 /* Skip all this stuff if we aren't mixing formats. */
5632 if (abfd && input_bfd
5633 && abfd->xvec == input_bfd->xvec)
5637 h = bfd_hash_lookup (&link_info->hash->table, "_gp", false, false);
5638 lh = (struct bfd_link_hash_entry *) h;
5645 case bfd_link_hash_undefined:
5646 case bfd_link_hash_undefweak:
5647 case bfd_link_hash_common:
5650 case bfd_link_hash_defined:
5651 case bfd_link_hash_defweak:
5653 gp = lh->u.def.value;
5655 case bfd_link_hash_indirect:
5656 case bfd_link_hash_warning:
5658 /* @@FIXME ignoring warning for now */
5660 case bfd_link_hash_new:
5669 for (parent = reloc_vector; *parent != (arelent *) NULL;
5672 char *error_message = (char *) NULL;
5673 bfd_reloc_status_type r;
5675 /* Specific to MIPS: Deal with relocation types that require
5676 knowing the gp of the output bfd. */
5677 asymbol *sym = *(*parent)->sym_ptr_ptr;
5678 if (bfd_is_abs_section (sym->section) && abfd)
5680 /* The special_function wouldn't get called anyways. */
5684 /* The gp isn't there; let the special function code
5685 fall over on its own. */
5687 else if ((*parent)->howto->special_function
5688 == mips_elf_gprel16_reloc)
5690 /* bypass special_function call */
5691 r = gprel16_with_gp (input_bfd, sym, *parent, input_section,
5692 relocateable, (PTR) data, gp);
5693 goto skip_bfd_perform_relocation;
5695 /* end mips specific stuff */
5697 r = bfd_perform_relocation (input_bfd,
5701 relocateable ? abfd : (bfd *) NULL,
5703 skip_bfd_perform_relocation:
5707 asection *os = input_section->output_section;
5709 /* A partial link, so keep the relocs */
5710 os->orelocation[os->reloc_count] = *parent;
5714 if (r != bfd_reloc_ok)
5718 case bfd_reloc_undefined:
5719 if (!((*link_info->callbacks->undefined_symbol)
5720 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
5721 input_bfd, input_section, (*parent)->address)))
5724 case bfd_reloc_dangerous:
5725 BFD_ASSERT (error_message != (char *) NULL);
5726 if (!((*link_info->callbacks->reloc_dangerous)
5727 (link_info, error_message, input_bfd, input_section,
5728 (*parent)->address)))
5731 case bfd_reloc_overflow:
5732 if (!((*link_info->callbacks->reloc_overflow)
5733 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
5734 (*parent)->howto->name, (*parent)->addend,
5735 input_bfd, input_section, (*parent)->address)))
5738 case bfd_reloc_outofrange:
5747 if (reloc_vector != NULL)
5748 free (reloc_vector);
5752 if (reloc_vector != NULL)
5753 free (reloc_vector);
5756 #define bfd_elf32_bfd_get_relocated_section_contents \
5757 elf32_mips_get_relocated_section_contents
5759 /* ECOFF swapping routines. These are used when dealing with the
5760 .mdebug section, which is in the ECOFF debugging format. */
5761 static const struct ecoff_debug_swap mips_elf_ecoff_debug_swap =
5763 /* Symbol table magic number. */
5765 /* Alignment of debugging information. E.g., 4. */
5767 /* Sizes of external symbolic information. */
5768 sizeof (struct hdr_ext),
5769 sizeof (struct dnr_ext),
5770 sizeof (struct pdr_ext),
5771 sizeof (struct sym_ext),
5772 sizeof (struct opt_ext),
5773 sizeof (struct fdr_ext),
5774 sizeof (struct rfd_ext),
5775 sizeof (struct ext_ext),
5776 /* Functions to swap in external symbolic data. */
5785 _bfd_ecoff_swap_tir_in,
5786 _bfd_ecoff_swap_rndx_in,
5787 /* Functions to swap out external symbolic data. */
5796 _bfd_ecoff_swap_tir_out,
5797 _bfd_ecoff_swap_rndx_out,
5798 /* Function to read in symbolic data. */
5799 mips_elf_read_ecoff_info
5802 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
5803 #define TARGET_LITTLE_NAME "elf32-littlemips"
5804 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
5805 #define TARGET_BIG_NAME "elf32-bigmips"
5806 #define ELF_ARCH bfd_arch_mips
5807 #define ELF_MACHINE_CODE EM_MIPS
5808 #define ELF_MAXPAGESIZE 0x10000
5809 #define elf_backend_collect true
5810 #define elf_backend_type_change_ok true
5811 #define elf_info_to_howto 0
5812 #define elf_info_to_howto_rel mips_info_to_howto_rel
5813 #define elf_backend_sym_is_global mips_elf_sym_is_global
5814 #define elf_backend_object_p mips_elf_object_p
5815 #define elf_backend_section_from_shdr mips_elf_section_from_shdr
5816 #define elf_backend_fake_sections mips_elf_fake_sections
5817 #define elf_backend_section_from_bfd_section \
5818 mips_elf_section_from_bfd_section
5819 #define elf_backend_section_processing mips_elf_section_processing
5820 #define elf_backend_symbol_processing mips_elf_symbol_processing
5821 #define elf_backend_additional_program_headers \
5822 mips_elf_additional_program_headers
5823 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
5824 #define elf_backend_final_write_processing \
5825 mips_elf_final_write_processing
5826 #define elf_backend_ecoff_debug_swap &mips_elf_ecoff_debug_swap
5828 #define bfd_elf32_bfd_is_local_label mips_elf_is_local_label
5829 #define bfd_elf32_find_nearest_line mips_elf_find_nearest_line
5831 #define bfd_elf32_bfd_link_hash_table_create \
5832 mips_elf_link_hash_table_create
5833 #define bfd_elf32_bfd_final_link mips_elf_final_link
5834 #define bfd_elf32_bfd_copy_private_bfd_data \
5835 mips_elf_copy_private_bfd_data
5836 #define bfd_elf32_bfd_merge_private_bfd_data \
5837 mips_elf_merge_private_bfd_data
5838 #define bfd_elf32_bfd_set_private_flags mips_elf_set_private_flags
5839 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
5840 #define elf_backend_create_dynamic_sections \
5841 mips_elf_create_dynamic_sections
5842 #define elf_backend_check_relocs mips_elf_check_relocs
5843 #define elf_backend_adjust_dynamic_symbol \
5844 mips_elf_adjust_dynamic_symbol
5845 #define elf_backend_size_dynamic_sections \
5846 mips_elf_size_dynamic_sections
5847 #define elf_backend_relocate_section mips_elf_relocate_section
5848 #define elf_backend_finish_dynamic_symbol \
5849 mips_elf_finish_dynamic_symbol
5850 #define elf_backend_finish_dynamic_sections \
5851 mips_elf_finish_dynamic_sections
5853 #include "elf32-target.h"