1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
4 Most of the information added by Ian Lance Taylor, Cygnus Support,
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 /* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
24 different MIPS ELF from other targets. This matters when linking.
25 This file supports both, switching at runtime. */
35 /* Get the ECOFF swapping routines. */
37 #include "coff/symconst.h"
38 #include "coff/internal.h"
39 #include "coff/ecoff.h"
40 #include "coff/mips.h"
42 #include "ecoffswap.h"
44 static bfd_reloc_status_type mips32_64bit_reloc
45 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
46 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
47 PARAMS ((bfd *, bfd_reloc_code_real_type));
48 static void mips_info_to_howto_rel
49 PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
50 static void bfd_mips_elf32_swap_gptab_in
51 PARAMS ((bfd *, const Elf32_External_gptab *, Elf32_gptab *));
52 static void bfd_mips_elf32_swap_gptab_out
53 PARAMS ((bfd *, const Elf32_gptab *, Elf32_External_gptab *));
54 static boolean mips_elf_sym_is_global PARAMS ((bfd *, asymbol *));
55 static boolean mips_elf32_object_p PARAMS ((bfd *));
56 static boolean mips_elf_create_procedure_table
57 PARAMS ((PTR, bfd *, struct bfd_link_info *, asection *,
58 struct ecoff_debug_info *));
59 static int mips_elf_additional_program_headers PARAMS ((bfd *));
60 static boolean mips_elf_modify_segment_map PARAMS ((bfd *));
61 static INLINE int elf_mips_isa PARAMS ((flagword));
62 static INLINE int elf_mips_mach PARAMS ((flagword));
63 static boolean mips_elf32_section_from_shdr
64 PARAMS ((bfd *, Elf32_Internal_Shdr *, char *));
65 static boolean mips_elf32_section_processing
66 PARAMS ((bfd *, Elf32_Internal_Shdr *));
67 static boolean mips_elf_is_local_label_name
68 PARAMS ((bfd *, const char *));
69 static struct bfd_hash_entry *mips_elf_link_hash_newfunc
70 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
71 static struct bfd_link_hash_table *mips_elf_link_hash_table_create
73 static int gptab_compare PARAMS ((const void *, const void *));
74 static boolean mips_elf_final_link
75 PARAMS ((bfd *, struct bfd_link_info *));
76 static void mips_elf_relocate_hi16
77 PARAMS ((bfd *, Elf_Internal_Rela *, Elf_Internal_Rela *, bfd_byte *,
79 static boolean mips_elf_relocate_got_local
80 PARAMS ((bfd *, bfd *, asection *, Elf_Internal_Rela *,
81 Elf_Internal_Rela *, bfd_byte *, bfd_vma));
82 static void mips_elf_relocate_global_got
83 PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
84 static bfd_reloc_status_type mips16_jump_reloc
85 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
86 static bfd_reloc_status_type mips16_gprel_reloc
87 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
88 /* start-sanitize-sky */
89 static bfd_reloc_status_type dvp_u15_s3_reloc
90 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
91 /* end-sanitize-sky */
92 static boolean mips_elf_adjust_dynindx
93 PARAMS ((struct elf_link_hash_entry *, PTR));
94 static boolean mips_elf_relocate_section
95 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
96 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
97 static boolean mips_elf_link_output_symbol_hook
98 PARAMS ((bfd *, struct bfd_link_info *, const char *, Elf_Internal_Sym *,
100 static boolean mips_elf_create_dynamic_sections
101 PARAMS ((bfd *, struct bfd_link_info *));
102 static boolean mips_elf_create_compact_rel_section
103 PARAMS ((bfd *, struct bfd_link_info *));
104 static boolean mips_elf_create_got_section
105 PARAMS ((bfd *, struct bfd_link_info *));
106 static boolean mips_elf_check_relocs
107 PARAMS ((bfd *, struct bfd_link_info *, asection *,
108 const Elf_Internal_Rela *));
109 static boolean mips_elf_adjust_dynamic_symbol
110 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
111 static boolean mips_elf_always_size_sections
112 PARAMS ((bfd *, struct bfd_link_info *));
113 static boolean mips_elf_size_dynamic_sections
114 PARAMS ((bfd *, struct bfd_link_info *));
115 static boolean mips_elf_finish_dynamic_symbol
116 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
117 Elf_Internal_Sym *));
118 static boolean mips_elf_finish_dynamic_sections
119 PARAMS ((bfd *, struct bfd_link_info *));
120 static boolean mips_elf_add_symbol_hook
121 PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
122 const char **, flagword *, asection **, bfd_vma *));
123 static bfd_reloc_status_type mips_elf_final_gp
124 PARAMS ((bfd *, asymbol *, boolean, char **, bfd_vma *));
125 static bfd_byte *elf32_mips_get_relocated_section_contents
126 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
127 bfd_byte *, boolean, asymbol **));
129 /* This is true for Irix 5 executables, false for normal MIPS ELF ABI
130 executables. FIXME: At the moment, we default to always generating
131 Irix 5 executables. */
133 #define SGI_COMPAT(abfd) (1)
135 /* This structure is used to hold .got information when linking. It
136 is stored in the tdata field of the bfd_elf_section_data structure. */
140 /* The symbol index of the first global .got symbol. */
141 unsigned long global_gotsym;
142 /* The number of local .got entries. */
143 unsigned int local_gotno;
144 /* The number of local .got entries we have used. */
145 unsigned int assigned_gotno;
148 /* The number of local .got entries we reserve. */
149 #define MIPS_RESERVED_GOTNO (2)
151 /* Instructions which appear in a stub. For some reason the stub is
152 slightly different on an SGI system. */
153 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
154 #define STUB_LW(abfd) \
156 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
157 : 0x8f998000) /* lw t9,0x8000(gp) */
158 #define STUB_MOVE 0x03e07825 /* move t7,ra */
159 #define STUB_JALR 0x0320f809 /* jal t9 */
160 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
161 #define MIPS_FUNCTION_STUB_SIZE (16)
164 /* We no longer try to identify particular sections for the .dynsym
165 section. When we do, we wind up crashing if there are other random
166 sections with relocations. */
168 /* Names of sections which appear in the .dynsym section in an Irix 5
171 static const char * const mips_elf_dynsym_sec_names[] =
184 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
185 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
187 /* The number of entries in mips_elf_dynsym_sec_names which go in the
190 #define MIPS_TEXT_DYNSYM_SECNO (3)
194 /* The names of the runtime procedure table symbols used on Irix 5. */
196 static const char * const mips_elf_dynsym_rtproc_names[] =
199 "_procedure_string_table",
200 "_procedure_table_size",
204 /* These structures are used to generate the .compact_rel section on
209 unsigned long id1; /* Always one? */
210 unsigned long num; /* Number of compact relocation entries. */
211 unsigned long id2; /* Always two? */
212 unsigned long offset; /* The file offset of the first relocation. */
213 unsigned long reserved0; /* Zero? */
214 unsigned long reserved1; /* Zero? */
223 bfd_byte reserved0[4];
224 bfd_byte reserved1[4];
225 } Elf32_External_compact_rel;
229 unsigned int ctype : 1; /* 1: long 0: short format. See below. */
230 unsigned int rtype : 4; /* Relocation types. See below. */
231 unsigned int dist2to : 8;
232 unsigned int relvaddr : 19; /* (VADDR - vaddr of the previous entry)/ 4 */
233 unsigned long konst; /* KONST field. See below. */
234 unsigned long vaddr; /* VADDR to be relocated. */
239 unsigned int ctype : 1; /* 1: long 0: short format. See below. */
240 unsigned int rtype : 4; /* Relocation types. See below. */
241 unsigned int dist2to : 8;
242 unsigned int relvaddr : 19; /* (VADDR - vaddr of the previous entry)/ 4 */
243 unsigned long konst; /* KONST field. See below. */
251 } Elf32_External_crinfo;
257 } Elf32_External_crinfo2;
259 /* These are the constants used to swap the bitfields in a crinfo. */
261 #define CRINFO_CTYPE (0x1)
262 #define CRINFO_CTYPE_SH (31)
263 #define CRINFO_RTYPE (0xf)
264 #define CRINFO_RTYPE_SH (27)
265 #define CRINFO_DIST2TO (0xff)
266 #define CRINFO_DIST2TO_SH (19)
267 #define CRINFO_RELVADDR (0x7ffff)
268 #define CRINFO_RELVADDR_SH (0)
270 /* A compact relocation info has long (3 words) or short (2 words)
271 formats. A short format doesn't have VADDR field and relvaddr
272 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
273 #define CRF_MIPS_LONG 1
274 #define CRF_MIPS_SHORT 0
276 /* There are 4 types of compact relocation at least. The value KONST
277 has different meaning for each type:
280 CT_MIPS_REL32 Address in data
281 CT_MIPS_WORD Address in word (XXX)
282 CT_MIPS_GPHI_LO GP - vaddr
283 CT_MIPS_JMPAD Address to jump
286 #define CRT_MIPS_REL32 0xa
287 #define CRT_MIPS_WORD 0xb
288 #define CRT_MIPS_GPHI_LO 0xc
289 #define CRT_MIPS_JMPAD 0xd
291 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
292 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
293 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
294 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
296 static void bfd_elf32_swap_compact_rel_out
297 PARAMS ((bfd *, const Elf32_compact_rel *, Elf32_External_compact_rel *));
298 static void bfd_elf32_swap_crinfo_out
299 PARAMS ((bfd *, const Elf32_crinfo *, Elf32_External_crinfo *));
301 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
303 static reloc_howto_type elf_mips_howto_table[] =
306 HOWTO (R_MIPS_NONE, /* type */
308 0, /* size (0 = byte, 1 = short, 2 = long) */
310 false, /* pc_relative */
312 complain_overflow_dont, /* complain_on_overflow */
313 bfd_elf_generic_reloc, /* special_function */
314 "R_MIPS_NONE", /* name */
315 false, /* partial_inplace */
318 false), /* pcrel_offset */
320 /* 16 bit relocation. */
321 HOWTO (R_MIPS_16, /* type */
323 1, /* size (0 = byte, 1 = short, 2 = long) */
325 false, /* pc_relative */
327 complain_overflow_bitfield, /* complain_on_overflow */
328 bfd_elf_generic_reloc, /* special_function */
329 "R_MIPS_16", /* name */
330 true, /* partial_inplace */
331 0xffff, /* src_mask */
332 0xffff, /* dst_mask */
333 false), /* pcrel_offset */
335 /* 32 bit relocation. */
336 HOWTO (R_MIPS_32, /* type */
338 2, /* size (0 = byte, 1 = short, 2 = long) */
340 false, /* pc_relative */
342 complain_overflow_bitfield, /* complain_on_overflow */
343 bfd_elf_generic_reloc, /* special_function */
344 "R_MIPS_32", /* name */
345 true, /* partial_inplace */
346 0xffffffff, /* src_mask */
347 0xffffffff, /* dst_mask */
348 false), /* pcrel_offset */
350 /* 32 bit symbol relative relocation. */
351 HOWTO (R_MIPS_REL32, /* type */
353 2, /* size (0 = byte, 1 = short, 2 = long) */
355 false, /* pc_relative */
357 complain_overflow_bitfield, /* complain_on_overflow */
358 bfd_elf_generic_reloc, /* special_function */
359 "R_MIPS_REL32", /* name */
360 true, /* partial_inplace */
361 0xffffffff, /* src_mask */
362 0xffffffff, /* dst_mask */
363 false), /* pcrel_offset */
365 /* 26 bit branch address. */
366 HOWTO (R_MIPS_26, /* type */
368 2, /* size (0 = byte, 1 = short, 2 = long) */
370 false, /* pc_relative */
372 complain_overflow_dont, /* complain_on_overflow */
373 /* This needs complex overflow
374 detection, because the upper four
375 bits must match the PC. */
376 bfd_elf_generic_reloc, /* special_function */
377 "R_MIPS_26", /* name */
378 true, /* partial_inplace */
379 0x3ffffff, /* src_mask */
380 0x3ffffff, /* dst_mask */
381 false), /* pcrel_offset */
383 /* High 16 bits of symbol value. */
384 HOWTO (R_MIPS_HI16, /* type */
386 2, /* size (0 = byte, 1 = short, 2 = long) */
388 false, /* pc_relative */
390 complain_overflow_dont, /* complain_on_overflow */
391 _bfd_mips_elf_hi16_reloc, /* special_function */
392 "R_MIPS_HI16", /* name */
393 true, /* partial_inplace */
394 0xffff, /* src_mask */
395 0xffff, /* dst_mask */
396 false), /* pcrel_offset */
398 /* Low 16 bits of symbol value. */
399 HOWTO (R_MIPS_LO16, /* type */
401 2, /* size (0 = byte, 1 = short, 2 = long) */
403 false, /* pc_relative */
405 complain_overflow_dont, /* complain_on_overflow */
406 _bfd_mips_elf_lo16_reloc, /* special_function */
407 "R_MIPS_LO16", /* name */
408 true, /* partial_inplace */
409 0xffff, /* src_mask */
410 0xffff, /* dst_mask */
411 false), /* pcrel_offset */
413 /* GP relative reference. */
414 HOWTO (R_MIPS_GPREL16, /* type */
416 2, /* size (0 = byte, 1 = short, 2 = long) */
418 false, /* pc_relative */
420 complain_overflow_signed, /* complain_on_overflow */
421 _bfd_mips_elf_gprel16_reloc, /* special_function */
422 "R_MIPS_GPREL16", /* name */
423 true, /* partial_inplace */
424 0xffff, /* src_mask */
425 0xffff, /* dst_mask */
426 false), /* pcrel_offset */
428 /* Reference to literal section. */
429 HOWTO (R_MIPS_LITERAL, /* type */
431 2, /* size (0 = byte, 1 = short, 2 = long) */
433 false, /* pc_relative */
435 complain_overflow_signed, /* complain_on_overflow */
436 _bfd_mips_elf_gprel16_reloc, /* special_function */
437 "R_MIPS_LITERAL", /* name */
438 true, /* partial_inplace */
439 0xffff, /* src_mask */
440 0xffff, /* dst_mask */
441 false), /* pcrel_offset */
443 /* Reference to global offset table. */
444 HOWTO (R_MIPS_GOT16, /* type */
446 2, /* size (0 = byte, 1 = short, 2 = long) */
448 false, /* pc_relative */
450 complain_overflow_signed, /* complain_on_overflow */
451 _bfd_mips_elf_got16_reloc, /* special_function */
452 "R_MIPS_GOT16", /* name */
453 false, /* partial_inplace */
455 0xffff, /* dst_mask */
456 false), /* pcrel_offset */
458 /* 16 bit PC relative reference. */
459 HOWTO (R_MIPS_PC16, /* type */
461 2, /* size (0 = byte, 1 = short, 2 = long) */
463 true, /* pc_relative */
465 complain_overflow_signed, /* complain_on_overflow */
466 bfd_elf_generic_reloc, /* special_function */
467 "R_MIPS_PC16", /* name */
468 true, /* partial_inplace */
469 0xffff, /* src_mask */
470 0xffff, /* dst_mask */
471 false), /* pcrel_offset */
473 /* 16 bit call through global offset table. */
474 /* FIXME: This is not handled correctly. */
475 HOWTO (R_MIPS_CALL16, /* type */
477 2, /* size (0 = byte, 1 = short, 2 = long) */
479 false, /* pc_relative */
481 complain_overflow_signed, /* complain_on_overflow */
482 bfd_elf_generic_reloc, /* special_function */
483 "R_MIPS_CALL16", /* name */
484 false, /* partial_inplace */
486 0xffff, /* dst_mask */
487 false), /* pcrel_offset */
489 /* 32 bit GP relative reference. */
490 HOWTO (R_MIPS_GPREL32, /* type */
492 2, /* size (0 = byte, 1 = short, 2 = long) */
494 false, /* pc_relative */
496 complain_overflow_bitfield, /* complain_on_overflow */
497 _bfd_mips_elf_gprel32_reloc, /* special_function */
498 "R_MIPS_GPREL32", /* name */
499 true, /* partial_inplace */
500 0xffffffff, /* src_mask */
501 0xffffffff, /* dst_mask */
502 false), /* pcrel_offset */
504 /* The remaining relocs are defined on Irix 5, although they are
505 not defined by the ABI. */
510 /* A 5 bit shift field. */
511 HOWTO (R_MIPS_SHIFT5, /* type */
513 2, /* size (0 = byte, 1 = short, 2 = long) */
515 false, /* pc_relative */
517 complain_overflow_bitfield, /* complain_on_overflow */
518 bfd_elf_generic_reloc, /* special_function */
519 "R_MIPS_SHIFT5", /* name */
520 true, /* partial_inplace */
521 0x000007c0, /* src_mask */
522 0x000007c0, /* dst_mask */
523 false), /* pcrel_offset */
525 /* A 6 bit shift field. */
526 /* FIXME: This is not handled correctly; a special function is
527 needed to put the most significant bit in the right place. */
528 HOWTO (R_MIPS_SHIFT6, /* type */
530 2, /* size (0 = byte, 1 = short, 2 = long) */
532 false, /* pc_relative */
534 complain_overflow_bitfield, /* complain_on_overflow */
535 bfd_elf_generic_reloc, /* special_function */
536 "R_MIPS_SHIFT6", /* name */
537 true, /* partial_inplace */
538 0x000007c4, /* src_mask */
539 0x000007c4, /* dst_mask */
540 false), /* pcrel_offset */
542 /* A 64 bit relocation. This is used in 32 bit ELF when addresses
543 are 64 bits long; the upper 32 bits are simply a sign extension.
544 The fields of the howto should be the same as for R_MIPS_32,
545 other than the type, name, and special_function. */
546 HOWTO (R_MIPS_64, /* type */
548 2, /* size (0 = byte, 1 = short, 2 = long) */
550 false, /* pc_relative */
552 complain_overflow_bitfield, /* complain_on_overflow */
553 mips32_64bit_reloc, /* special_function */
554 "R_MIPS_64", /* name */
555 true, /* partial_inplace */
556 0xffffffff, /* src_mask */
557 0xffffffff, /* dst_mask */
558 false), /* pcrel_offset */
560 /* Displacement in the global offset table. */
561 /* FIXME: Not handled correctly. */
562 HOWTO (R_MIPS_GOT_DISP, /* type */
564 2, /* size (0 = byte, 1 = short, 2 = long) */
566 false, /* pc_relative */
568 complain_overflow_bitfield, /* complain_on_overflow */
569 bfd_elf_generic_reloc, /* special_function */
570 "R_MIPS_GOT_DISP", /* name */
571 true, /* partial_inplace */
572 0x0000ffff, /* src_mask */
573 0x0000ffff, /* dst_mask */
574 false), /* pcrel_offset */
576 /* Displacement to page pointer in the global offset table. */
577 /* FIXME: Not handled correctly. */
578 HOWTO (R_MIPS_GOT_PAGE, /* type */
580 2, /* size (0 = byte, 1 = short, 2 = long) */
582 false, /* pc_relative */
584 complain_overflow_bitfield, /* complain_on_overflow */
585 bfd_elf_generic_reloc, /* special_function */
586 "R_MIPS_GOT_PAGE", /* name */
587 true, /* partial_inplace */
588 0x0000ffff, /* src_mask */
589 0x0000ffff, /* dst_mask */
590 false), /* pcrel_offset */
592 /* Offset from page pointer in the global offset table. */
593 /* FIXME: Not handled correctly. */
594 HOWTO (R_MIPS_GOT_OFST, /* type */
596 2, /* size (0 = byte, 1 = short, 2 = long) */
598 false, /* pc_relative */
600 complain_overflow_bitfield, /* complain_on_overflow */
601 bfd_elf_generic_reloc, /* special_function */
602 "R_MIPS_GOT_OFST", /* name */
603 true, /* partial_inplace */
604 0x0000ffff, /* src_mask */
605 0x0000ffff, /* dst_mask */
606 false), /* pcrel_offset */
608 /* High 16 bits of displacement in global offset table. */
609 /* FIXME: Not handled correctly. */
610 HOWTO (R_MIPS_GOT_HI16, /* type */
612 2, /* size (0 = byte, 1 = short, 2 = long) */
614 false, /* pc_relative */
616 complain_overflow_dont, /* complain_on_overflow */
617 bfd_elf_generic_reloc, /* special_function */
618 "R_MIPS_GOT_HI16", /* name */
619 true, /* partial_inplace */
620 0x0000ffff, /* src_mask */
621 0x0000ffff, /* dst_mask */
622 false), /* pcrel_offset */
624 /* Low 16 bits of displacement in global offset table. */
625 /* FIXME: Not handled correctly. */
626 HOWTO (R_MIPS_GOT_LO16, /* type */
628 2, /* size (0 = byte, 1 = short, 2 = long) */
630 false, /* pc_relative */
632 complain_overflow_dont, /* complain_on_overflow */
633 bfd_elf_generic_reloc, /* special_function */
634 "R_MIPS_GOT_LO16", /* name */
635 true, /* partial_inplace */
636 0x0000ffff, /* src_mask */
637 0x0000ffff, /* dst_mask */
638 false), /* pcrel_offset */
640 /* 64 bit subtraction. Presumably not used in 32 bit ELF. */
643 /* Used to cause the linker to insert and delete instructions? */
648 /* Get the higher values of a 64 bit addend. Presumably not used in
653 /* High 16 bits of displacement in global offset table. */
654 /* FIXME: Not handled correctly. */
655 HOWTO (R_MIPS_CALL_HI16, /* type */
657 2, /* size (0 = byte, 1 = short, 2 = long) */
659 false, /* pc_relative */
661 complain_overflow_dont, /* complain_on_overflow */
662 bfd_elf_generic_reloc, /* special_function */
663 "R_MIPS_CALL_HI16", /* name */
664 true, /* partial_inplace */
665 0x0000ffff, /* src_mask */
666 0x0000ffff, /* dst_mask */
667 false), /* pcrel_offset */
669 /* Low 16 bits of displacement in global offset table. */
670 /* FIXME: Not handled correctly. */
671 HOWTO (R_MIPS_CALL_LO16, /* type */
673 2, /* size (0 = byte, 1 = short, 2 = long) */
675 false, /* pc_relative */
677 complain_overflow_dont, /* complain_on_overflow */
678 bfd_elf_generic_reloc, /* special_function */
679 "R_MIPS_CALL_LO16", /* name */
680 true, /* partial_inplace */
681 0x0000ffff, /* src_mask */
682 0x0000ffff, /* dst_mask */
683 false), /* pcrel_offset */
687 { R_MIPS_ADD_IMMEDIATE },
692 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
693 is a hack to make the linker think that we need 64 bit values. */
694 static reloc_howto_type elf_mips_ctor64_howto =
695 HOWTO (R_MIPS_64, /* type */
697 4, /* size (0 = byte, 1 = short, 2 = long) */
699 false, /* pc_relative */
701 complain_overflow_signed, /* complain_on_overflow */
702 mips32_64bit_reloc, /* special_function */
703 "R_MIPS_64", /* name */
704 true, /* partial_inplace */
705 0xffffffff, /* src_mask */
706 0xffffffff, /* dst_mask */
707 false); /* pcrel_offset */
709 /* The reloc used for the mips16 jump instruction. */
710 static reloc_howto_type elf_mips16_jump_howto =
711 HOWTO (R_MIPS16_26, /* type */
713 2, /* size (0 = byte, 1 = short, 2 = long) */
715 false, /* pc_relative */
717 complain_overflow_dont, /* complain_on_overflow */
718 /* This needs complex overflow
719 detection, because the upper four
720 bits must match the PC. */
721 mips16_jump_reloc, /* special_function */
722 "R_MIPS16_26", /* name */
723 true, /* partial_inplace */
724 0x3ffffff, /* src_mask */
725 0x3ffffff, /* dst_mask */
726 false); /* pcrel_offset */
728 /* The reloc used for the mips16 gprel instruction. The src_mask and
729 dsk_mask for this howto do not reflect the actual instruction, in
730 which the value is not contiguous; the masks are for the
731 convenience of the relocate_section routine. */
732 static reloc_howto_type elf_mips16_gprel_howto =
733 HOWTO (R_MIPS16_GPREL, /* type */
735 2, /* size (0 = byte, 1 = short, 2 = long) */
737 false, /* pc_relative */
739 complain_overflow_signed, /* complain_on_overflow */
740 mips16_gprel_reloc, /* special_function */
741 "R_MIPS16_GPREL", /* name */
742 true, /* partial_inplace */
743 0xffff, /* src_mask */
744 0xffff, /* dst_mask */
745 false); /* pcrel_offset */
747 /* start-sanitize-r5900 */
748 static reloc_howto_type elf_mips15_s3_howto =
749 HOWTO (R_MIPS15_S3, /* type */
751 2, /* size (0 = byte, 1 = short, 2 = long) */
753 false, /* pc_relative */
755 complain_overflow_bitfield, /* complain_on_overflow */
756 bfd_elf_generic_reloc, /* special_function */
757 "R_MIPS15_S3", /* name */
758 true, /* partial_inplace */
759 0x001fffc0, /* src_mask */
760 0x001fffc0, /* dst_mask */
761 false); /* pcrel_offset */
763 /* end-sanitize-r5900 */
764 /* start-sanitize-sky */
766 Note that partial_inplace and pcrel_offset are backwards from the
767 mips port. This is intentional as it seems more reasonable. */
768 static reloc_howto_type elf_mips_dvp_11_pcrel_howto =
769 HOWTO (R_MIPS_DVP_11_PCREL, /* type */
771 2, /* size (0 = byte, 1 = short, 2 = long) */
773 true, /* pc_relative */
775 complain_overflow_signed, /* complain_on_overflow */
776 bfd_elf_generic_reloc, /* special_function */
777 "R_MIPS_DVP_11_PCREL", /* name */
778 false, /* partial_inplace */
779 0x7ff, /* src_mask */
780 0x7ff, /* dst_mask */
781 true); /* pcrel_offset */
782 static reloc_howto_type elf_mips_dvp_27_s4_howto =
783 HOWTO (R_MIPS_DVP_27_S4, /* type */
785 2, /* size (0 = byte, 1 = short, 2 = long) */
787 false, /* pc_relative */
789 complain_overflow_unsigned, /* complain_on_overflow */
790 bfd_elf_generic_reloc, /* special_function */
791 "R_MIPS_DVP_27_S4", /* name */
792 false, /* partial_inplace */
793 0x7ffffff0, /* src_mask */
794 0x7ffffff0, /* dst_mask */
795 false); /* pcrel_offset */
796 static reloc_howto_type elf_mips_dvp_11_s4_howto =
797 HOWTO (R_MIPS_DVP_11_S4, /* type */
799 2, /* size (0 = byte, 1 = short, 2 = long) */
801 false, /* pc_relative */
803 complain_overflow_signed, /* complain_on_overflow */
804 bfd_elf_generic_reloc, /* special_function */
805 "R_MIPS_DVP_11_S4", /* name */
806 false, /* partial_inplace */
807 0x03ff, /* src_mask */
808 0x03ff, /* dst_mask */
809 false); /* pcrel_offset */
810 static reloc_howto_type elf_mips_dvp_u15_s3_howto =
811 HOWTO (R_MIPS_DVP_U15_S3, /* type */
813 2, /* size (0 = byte, 1 = short, 2 = long) */
815 false, /* pc_relative */
817 complain_overflow_unsigned, /* complain_on_overflow */
818 dvp_u15_s3_reloc, /* special_function */
819 "R_MIPS_DVP_U15_S3", /* name */
820 false, /* partial_inplace */
821 0xf03ff, /* src_mask */
822 0xf03ff, /* dst_mask */
823 false); /* pcrel_offset */
824 /* end-sanitize-sky */
826 /* GNU extension to record C++ vtable hierarchy */
827 static reloc_howto_type elf_mips_gnu_vtinherit_howto =
828 HOWTO (R_MIPS_GNU_VTINHERIT, /* type */
830 2, /* size (0 = byte, 1 = short, 2 = long) */
832 false, /* pc_relative */
834 complain_overflow_dont, /* complain_on_overflow */
835 NULL, /* special_function */
836 "R_MIPS_GNU_VTINHERIT", /* name */
837 false, /* partial_inplace */
840 false); /* pcrel_offset */
842 /* GNU extension to record C++ vtable member usage */
843 static reloc_howto_type elf_mips_gnu_vtentry_howto =
844 HOWTO (R_MIPS_GNU_VTENTRY, /* type */
846 2, /* size (0 = byte, 1 = short, 2 = long) */
848 false, /* pc_relative */
850 complain_overflow_dont, /* complain_on_overflow */
851 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
852 "R_MIPS_GNU_VTENTRY", /* name */
853 false, /* partial_inplace */
856 false); /* pcrel_offset */
858 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
859 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
860 the HI16. Here we just save the information we need; we do the
861 actual relocation when we see the LO16. MIPS ELF requires that the
862 LO16 immediately follow the HI16. As a GNU extension, we permit an
863 arbitrary number of HI16 relocs to be associated with a single LO16
864 reloc. This extension permits gcc to output the HI and LO relocs
869 struct mips_hi16 *next;
874 /* FIXME: This should not be a static variable. */
876 static struct mips_hi16 *mips_hi16_list;
878 bfd_reloc_status_type
879 _bfd_mips_elf_hi16_reloc (abfd,
887 arelent *reloc_entry;
890 asection *input_section;
892 char **error_message;
894 bfd_reloc_status_type ret;
898 /* If we're relocating, and this an external symbol, we don't want
899 to change anything. */
900 if (output_bfd != (bfd *) NULL
901 && (symbol->flags & BSF_SECTION_SYM) == 0
902 && reloc_entry->addend == 0)
904 reloc_entry->address += input_section->output_offset;
910 if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
912 boolean relocateable;
915 if (ret == bfd_reloc_undefined)
918 if (output_bfd != NULL)
922 relocateable = false;
923 output_bfd = symbol->section->output_section->owner;
926 ret = mips_elf_final_gp (output_bfd, symbol, relocateable,
928 if (ret != bfd_reloc_ok)
931 relocation = gp - reloc_entry->address;
935 if (bfd_is_und_section (symbol->section)
936 && output_bfd == (bfd *) NULL)
937 ret = bfd_reloc_undefined;
939 if (bfd_is_com_section (symbol->section))
942 relocation = symbol->value;
945 relocation += symbol->section->output_section->vma;
946 relocation += symbol->section->output_offset;
947 relocation += reloc_entry->addend;
949 if (reloc_entry->address > input_section->_cooked_size)
950 return bfd_reloc_outofrange;
952 /* Save the information, and let LO16 do the actual relocation. */
953 n = (struct mips_hi16 *) bfd_malloc (sizeof *n);
955 return bfd_reloc_outofrange;
956 n->addr = (bfd_byte *) data + reloc_entry->address;
957 n->addend = relocation;
958 n->next = mips_hi16_list;
961 if (output_bfd != (bfd *) NULL)
962 reloc_entry->address += input_section->output_offset;
967 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
968 inplace relocation; this function exists in order to do the
969 R_MIPS_HI16 relocation described above. */
971 bfd_reloc_status_type
972 _bfd_mips_elf_lo16_reloc (abfd,
980 arelent *reloc_entry;
983 asection *input_section;
985 char **error_message;
987 arelent gp_disp_relent;
989 if (mips_hi16_list != NULL)
999 struct mips_hi16 *next;
1001 /* Do the HI16 relocation. Note that we actually don't need
1002 to know anything about the LO16 itself, except where to
1003 find the low 16 bits of the addend needed by the LO16. */
1004 insn = bfd_get_32 (abfd, l->addr);
1005 vallo = (bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address)
1007 val = ((insn & 0xffff) << 16) + vallo;
1010 /* The low order 16 bits are always treated as a signed
1011 value. Therefore, a negative value in the low order bits
1012 requires an adjustment in the high order bits. We need
1013 to make this adjustment in two ways: once for the bits we
1014 took from the data, and once for the bits we are putting
1015 back in to the data. */
1016 if ((vallo & 0x8000) != 0)
1018 if ((val & 0x8000) != 0)
1021 insn = (insn &~ 0xffff) | ((val >> 16) & 0xffff);
1022 bfd_put_32 (abfd, insn, l->addr);
1024 if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
1026 gp_disp_relent = *reloc_entry;
1027 reloc_entry = &gp_disp_relent;
1028 reloc_entry->addend = l->addend;
1036 mips_hi16_list = NULL;
1038 else if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
1040 bfd_reloc_status_type ret;
1041 bfd_vma gp, relocation;
1043 /* FIXME: Does this case ever occur? */
1045 ret = mips_elf_final_gp (output_bfd, symbol, true, error_message, &gp);
1046 if (ret != bfd_reloc_ok)
1049 relocation = gp - reloc_entry->address;
1050 relocation += symbol->section->output_section->vma;
1051 relocation += symbol->section->output_offset;
1052 relocation += reloc_entry->addend;
1054 if (reloc_entry->address > input_section->_cooked_size)
1055 return bfd_reloc_outofrange;
1057 gp_disp_relent = *reloc_entry;
1058 reloc_entry = &gp_disp_relent;
1059 reloc_entry->addend = relocation - 4;
1062 /* Now do the LO16 reloc in the usual way. */
1063 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1064 input_section, output_bfd, error_message);
1067 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1068 table used for PIC code. If the symbol is an external symbol, the
1069 instruction is modified to contain the offset of the appropriate
1070 entry in the global offset table. If the symbol is a section
1071 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1072 addends are combined to form the real addend against the section
1073 symbol; the GOT16 is modified to contain the offset of an entry in
1074 the global offset table, and the LO16 is modified to offset it
1075 appropriately. Thus an offset larger than 16 bits requires a
1076 modified value in the global offset table.
1078 This implementation suffices for the assembler, but the linker does
1079 not yet know how to create global offset tables. */
1081 bfd_reloc_status_type
1082 _bfd_mips_elf_got16_reloc (abfd,
1090 arelent *reloc_entry;
1093 asection *input_section;
1095 char **error_message;
1097 /* If we're relocating, and this an external symbol, we don't want
1098 to change anything. */
1099 if (output_bfd != (bfd *) NULL
1100 && (symbol->flags & BSF_SECTION_SYM) == 0
1101 && reloc_entry->addend == 0)
1103 reloc_entry->address += input_section->output_offset;
1104 return bfd_reloc_ok;
1107 /* If we're relocating, and this is a local symbol, we can handle it
1109 if (output_bfd != (bfd *) NULL
1110 && (symbol->flags & BSF_SECTION_SYM) != 0)
1111 return _bfd_mips_elf_hi16_reloc (abfd, reloc_entry, symbol, data,
1112 input_section, output_bfd, error_message);
1117 /* We have to figure out the gp value, so that we can adjust the
1118 symbol value correctly. We look up the symbol _gp in the output
1119 BFD. If we can't find it, we're stuck. We cache it in the ELF
1120 target data. We don't need to adjust the symbol value for an
1121 external symbol if we are producing relocateable output. */
1123 static bfd_reloc_status_type
1124 mips_elf_final_gp (output_bfd, symbol, relocateable, error_message, pgp)
1127 boolean relocateable;
1128 char **error_message;
1131 if (bfd_is_und_section (symbol->section)
1135 return bfd_reloc_undefined;
1138 *pgp = _bfd_get_gp_value (output_bfd);
1141 || (symbol->flags & BSF_SECTION_SYM) != 0))
1145 /* Make up a value. */
1146 *pgp = symbol->section->output_section->vma + 0x4000;
1147 _bfd_set_gp_value (output_bfd, *pgp);
1155 count = bfd_get_symcount (output_bfd);
1156 sym = bfd_get_outsymbols (output_bfd);
1158 if (sym == (asymbol **) NULL)
1162 for (i = 0; i < count; i++, sym++)
1164 register CONST char *name;
1166 name = bfd_asymbol_name (*sym);
1167 if (*name == '_' && strcmp (name, "_gp") == 0)
1169 *pgp = bfd_asymbol_value (*sym);
1170 _bfd_set_gp_value (output_bfd, *pgp);
1178 /* Only get the error once. */
1180 _bfd_set_gp_value (output_bfd, *pgp);
1182 (char *) _("GP relative relocation when _gp not defined");
1183 return bfd_reloc_dangerous;
1188 return bfd_reloc_ok;
1191 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1192 become the offset from the gp register. This function also handles
1193 R_MIPS_LITERAL relocations, although those can be handled more
1194 cleverly because the entries in the .lit8 and .lit4 sections can be
1197 static bfd_reloc_status_type gprel16_with_gp PARAMS ((bfd *, asymbol *,
1198 arelent *, asection *,
1199 boolean, PTR, bfd_vma));
1201 bfd_reloc_status_type
1202 _bfd_mips_elf_gprel16_reloc (abfd, reloc_entry, symbol, data, input_section,
1203 output_bfd, error_message)
1205 arelent *reloc_entry;
1208 asection *input_section;
1210 char **error_message;
1212 boolean relocateable;
1213 bfd_reloc_status_type ret;
1216 /* If we're relocating, and this is an external symbol with no
1217 addend, we don't want to change anything. We will only have an
1218 addend if this is a newly created reloc, not read from an ELF
1220 if (output_bfd != (bfd *) NULL
1221 && (symbol->flags & BSF_SECTION_SYM) == 0
1222 && reloc_entry->addend == 0)
1224 reloc_entry->address += input_section->output_offset;
1225 return bfd_reloc_ok;
1228 if (output_bfd != (bfd *) NULL)
1229 relocateable = true;
1232 relocateable = false;
1233 output_bfd = symbol->section->output_section->owner;
1236 ret = mips_elf_final_gp (output_bfd, symbol, relocateable, error_message,
1238 if (ret != bfd_reloc_ok)
1241 return gprel16_with_gp (abfd, symbol, reloc_entry, input_section,
1242 relocateable, data, gp);
1245 static bfd_reloc_status_type
1246 gprel16_with_gp (abfd, symbol, reloc_entry, input_section, relocateable, data,
1250 arelent *reloc_entry;
1251 asection *input_section;
1252 boolean relocateable;
1260 if (bfd_is_com_section (symbol->section))
1263 relocation = symbol->value;
1265 relocation += symbol->section->output_section->vma;
1266 relocation += symbol->section->output_offset;
1268 if (reloc_entry->address > input_section->_cooked_size)
1269 return bfd_reloc_outofrange;
1271 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1273 /* Set val to the offset into the section or symbol. */
1274 if (reloc_entry->howto->src_mask == 0)
1276 /* This case occurs with the 64-bit MIPS ELF ABI. */
1277 val = reloc_entry->addend;
1281 val = ((insn & 0xffff) + reloc_entry->addend) & 0xffff;
1286 /* Adjust val for the final section location and GP value. If we
1287 are producing relocateable output, we don't want to do this for
1288 an external symbol. */
1290 || (symbol->flags & BSF_SECTION_SYM) != 0)
1291 val += relocation - gp;
1293 insn = (insn &~ 0xffff) | (val & 0xffff);
1294 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
1297 reloc_entry->address += input_section->output_offset;
1299 /* Make sure it fit in 16 bits. */
1300 if (val >= 0x8000 && val < 0xffff8000)
1301 return bfd_reloc_overflow;
1303 return bfd_reloc_ok;
1306 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1307 from the gp register? XXX */
1309 static bfd_reloc_status_type gprel32_with_gp PARAMS ((bfd *, asymbol *,
1310 arelent *, asection *,
1311 boolean, PTR, bfd_vma));
1313 bfd_reloc_status_type
1314 _bfd_mips_elf_gprel32_reloc (abfd,
1322 arelent *reloc_entry;
1325 asection *input_section;
1327 char **error_message;
1329 boolean relocateable;
1330 bfd_reloc_status_type ret;
1333 /* If we're relocating, and this is an external symbol with no
1334 addend, we don't want to change anything. We will only have an
1335 addend if this is a newly created reloc, not read from an ELF
1337 if (output_bfd != (bfd *) NULL
1338 && (symbol->flags & BSF_SECTION_SYM) == 0
1339 && reloc_entry->addend == 0)
1341 *error_message = (char *)
1342 _("32bits gp relative relocation occurs for an external symbol");
1343 return bfd_reloc_outofrange;
1346 if (output_bfd != (bfd *) NULL)
1348 relocateable = true;
1349 gp = _bfd_get_gp_value (output_bfd);
1353 relocateable = false;
1354 output_bfd = symbol->section->output_section->owner;
1356 ret = mips_elf_final_gp (output_bfd, symbol, relocateable,
1357 error_message, &gp);
1358 if (ret != bfd_reloc_ok)
1362 return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
1363 relocateable, data, gp);
1366 static bfd_reloc_status_type
1367 gprel32_with_gp (abfd, symbol, reloc_entry, input_section, relocateable, data,
1371 arelent *reloc_entry;
1372 asection *input_section;
1373 boolean relocateable;
1380 if (bfd_is_com_section (symbol->section))
1383 relocation = symbol->value;
1385 relocation += symbol->section->output_section->vma;
1386 relocation += symbol->section->output_offset;
1388 if (reloc_entry->address > input_section->_cooked_size)
1389 return bfd_reloc_outofrange;
1391 if (reloc_entry->howto->src_mask == 0)
1393 /* This case arises with the 64-bit MIPS ELF ABI. */
1397 val = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1399 /* Set val to the offset into the section or symbol. */
1400 val += reloc_entry->addend;
1402 /* Adjust val for the final section location and GP value. If we
1403 are producing relocateable output, we don't want to do this for
1404 an external symbol. */
1406 || (symbol->flags & BSF_SECTION_SYM) != 0)
1407 val += relocation - gp;
1409 bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);
1412 reloc_entry->address += input_section->output_offset;
1414 return bfd_reloc_ok;
1417 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1418 generated when addreses are 64 bits. The upper 32 bits are a simle
1421 static bfd_reloc_status_type
1422 mips32_64bit_reloc (abfd, reloc_entry, symbol, data, input_section,
1423 output_bfd, error_message)
1425 arelent *reloc_entry;
1428 asection *input_section;
1430 char **error_message;
1432 bfd_reloc_status_type r;
1437 r = bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1438 input_section, output_bfd, error_message);
1439 if (r != bfd_reloc_continue)
1442 /* Do a normal 32 bit relocation on the lower 32 bits. */
1443 reloc32 = *reloc_entry;
1444 if (bfd_big_endian (abfd))
1445 reloc32.address += 4;
1446 reloc32.howto = &elf_mips_howto_table[R_MIPS_32];
1447 r = bfd_perform_relocation (abfd, &reloc32, data, input_section,
1448 output_bfd, error_message);
1450 /* Sign extend into the upper 32 bits. */
1451 val = bfd_get_32 (abfd, (bfd_byte *) data + reloc32.address);
1452 if ((val & 0x80000000) != 0)
1456 addr = reloc_entry->address;
1457 if (bfd_little_endian (abfd))
1459 bfd_put_32 (abfd, val, (bfd_byte *) data + addr);
1464 /* Handle a mips16 jump. */
1466 static bfd_reloc_status_type
1467 mips16_jump_reloc (abfd, reloc_entry, symbol, data, input_section,
1468 output_bfd, error_message)
1470 arelent *reloc_entry;
1473 asection *input_section;
1475 char **error_message;
1477 if (output_bfd != (bfd *) NULL
1478 && (symbol->flags & BSF_SECTION_SYM) == 0
1479 && reloc_entry->addend == 0)
1481 reloc_entry->address += input_section->output_offset;
1482 return bfd_reloc_ok;
1487 static boolean warned;
1490 (*_bfd_error_handler)
1491 (_("Linking mips16 objects into %s format is not supported"),
1492 bfd_get_target (input_section->output_section->owner));
1496 return bfd_reloc_undefined;
1499 /* Handle a mips16 GP relative reloc. */
1501 static bfd_reloc_status_type
1502 mips16_gprel_reloc (abfd, reloc_entry, symbol, data, input_section,
1503 output_bfd, error_message)
1505 arelent *reloc_entry;
1508 asection *input_section;
1510 char **error_message;
1512 boolean relocateable;
1513 bfd_reloc_status_type ret;
1515 unsigned short extend, insn;
1516 unsigned long final;
1518 /* If we're relocating, and this is an external symbol with no
1519 addend, we don't want to change anything. We will only have an
1520 addend if this is a newly created reloc, not read from an ELF
1522 if (output_bfd != NULL
1523 && (symbol->flags & BSF_SECTION_SYM) == 0
1524 && reloc_entry->addend == 0)
1526 reloc_entry->address += input_section->output_offset;
1527 return bfd_reloc_ok;
1530 if (output_bfd != NULL)
1531 relocateable = true;
1534 relocateable = false;
1535 output_bfd = symbol->section->output_section->owner;
1538 ret = mips_elf_final_gp (output_bfd, symbol, relocateable, error_message,
1540 if (ret != bfd_reloc_ok)
1543 if (reloc_entry->address > input_section->_cooked_size)
1544 return bfd_reloc_outofrange;
1546 /* Pick up the mips16 extend instruction and the real instruction. */
1547 extend = bfd_get_16 (abfd, (bfd_byte *) data + reloc_entry->address);
1548 insn = bfd_get_16 (abfd, (bfd_byte *) data + reloc_entry->address + 2);
1550 /* Stuff the current addend back as a 32 bit value, do the usual
1551 relocation, and then clean up. */
1553 (((extend & 0x1f) << 11)
1556 (bfd_byte *) data + reloc_entry->address);
1558 ret = gprel16_with_gp (abfd, symbol, reloc_entry, input_section,
1559 relocateable, data, gp);
1561 final = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1564 | ((final >> 11) & 0x1f)
1566 (bfd_byte *) data + reloc_entry->address);
1570 (bfd_byte *) data + reloc_entry->address + 2);
1575 /* start-sanitize-sky */
1576 /* Handle a dvp R_MIPS_DVP_U15_S3 reloc.
1577 This is needed because the bits aren't contiguous. */
1579 static bfd_reloc_status_type
1580 dvp_u15_s3_reloc (abfd, reloc_entry, symbol, data, input_section,
1581 output_bfd, error_message)
1583 arelent *reloc_entry;
1586 asection *input_section;
1588 char **error_message;
1593 /* If we're relocating, and this is an external symbol with no
1594 addend, we don't want to change anything. We will only have an
1595 addend if this is a newly created reloc, not read from an ELF
1596 file. See bfd_elf_generic_reloc. */
1597 if (output_bfd != NULL
1598 && (symbol->flags & BSF_SECTION_SYM) == 0
1599 /* partial_inplace is false, so this test always succeeds,
1600 but for clarity and consistency with bfd_elf_generic_reloc
1601 this is left as is. */
1602 && (! reloc_entry->howto->partial_inplace
1603 || reloc_entry->addend == 0))
1605 reloc_entry->address += input_section->output_offset;
1606 return bfd_reloc_ok;
1609 if (reloc_entry->address > input_section->_cooked_size)
1610 return bfd_reloc_outofrange;
1612 relocation = (symbol->value
1613 + symbol->section->output_section->vma
1614 + symbol->section->output_offset);
1615 relocation += reloc_entry->addend;
1618 x = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1619 x |= (((relocation & 0x7800) << 10)
1620 | (relocation & 0x7ff));
1621 bfd_put_32 (abfd, x, (bfd_byte *) data + reloc_entry->address);
1623 if (relocation & ~(bfd_vma) 0x7fff)
1624 return bfd_reloc_overflow;
1625 return bfd_reloc_ok;
1628 /* end-sanitize-sky */
1629 /* Return the ISA for a MIPS e_flags value. */
1632 elf_mips_isa (flags)
1635 switch (flags & EF_MIPS_ARCH)
1649 /* Return the MACH for a MIPS e_flags value. */
1652 elf_mips_mach (flags)
1655 switch (flags & EF_MIPS_MACH)
1657 case E_MIPS_MACH_3900:
1658 return bfd_mach_mips3900;
1660 case E_MIPS_MACH_4010:
1661 return bfd_mach_mips4010;
1663 case E_MIPS_MACH_4100:
1664 return bfd_mach_mips4100;
1665 /* start-sanitize-vr4320 */
1667 case E_MIPS_MACH_4320:
1668 return bfd_mach_mips4320;
1669 /* end-sanitize-vr4320 */
1671 case E_MIPS_MACH_4650:
1672 return bfd_mach_mips4650;
1673 /* start-sanitize-tx49 */
1675 case E_MIPS_MACH_4900:
1676 return bfd_mach_mips4900;
1677 /* end-sanitize-tx49 */
1678 /* start-sanitize-cygnus */
1680 case E_MIPS_MACH_5400:
1681 return bfd_mach_mips5400;
1682 /* end-sanitize-cygnus */
1683 /* start-sanitize-r5900 */
1685 case E_MIPS_MACH_5900:
1686 return bfd_mach_mips5900;
1687 /* end-sanitize-r5900 */
1690 switch (flags & EF_MIPS_ARCH)
1694 return bfd_mach_mips3000;
1698 return bfd_mach_mips6000;
1702 return bfd_mach_mips4000;
1706 return bfd_mach_mips8000;
1714 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1716 struct elf_reloc_map {
1717 bfd_reloc_code_real_type bfd_reloc_val;
1718 enum elf_mips_reloc_type elf_reloc_val;
1721 static CONST struct elf_reloc_map mips_reloc_map[] =
1723 { BFD_RELOC_NONE, R_MIPS_NONE, },
1724 { BFD_RELOC_16, R_MIPS_16 },
1725 { BFD_RELOC_32, R_MIPS_32 },
1726 { BFD_RELOC_64, R_MIPS_64 },
1727 { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
1728 { BFD_RELOC_HI16_S, R_MIPS_HI16 },
1729 { BFD_RELOC_LO16, R_MIPS_LO16 },
1730 { BFD_RELOC_MIPS_GPREL, R_MIPS_GPREL16 },
1731 { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
1732 { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
1733 { BFD_RELOC_16_PCREL, R_MIPS_PC16 },
1734 { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
1735 { BFD_RELOC_MIPS_GPREL32, R_MIPS_GPREL32 },
1736 { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
1737 { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 },
1738 { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 },
1739 { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 }
1742 /* Given a BFD reloc type, return a howto structure. */
1744 static reloc_howto_type *
1745 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
1747 bfd_reloc_code_real_type code;
1751 for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map); i++)
1753 if (mips_reloc_map[i].bfd_reloc_val == code)
1754 return &elf_mips_howto_table[(int) mips_reloc_map[i].elf_reloc_val];
1760 bfd_set_error (bfd_error_bad_value);
1763 case BFD_RELOC_CTOR:
1764 /* We need to handle BFD_RELOC_CTOR specially.
1765 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1766 size of addresses on this architecture. */
1767 if (bfd_arch_bits_per_address (abfd) == 32)
1768 return &elf_mips_howto_table[(int) R_MIPS_32];
1770 return &elf_mips_ctor64_howto;
1772 case BFD_RELOC_MIPS16_JMP:
1773 return &elf_mips16_jump_howto;
1774 case BFD_RELOC_MIPS16_GPREL:
1775 return &elf_mips16_gprel_howto;
1776 /* start-sanitize-r5900 */
1777 case BFD_RELOC_MIPS15_S3:
1778 return &elf_mips15_s3_howto;
1779 /* end-sanitize-r5900 */
1780 /* start-sanitize-sky */
1781 case BFD_RELOC_MIPS_DVP_11_PCREL:
1782 return &elf_mips_dvp_11_pcrel_howto;
1783 case BFD_RELOC_MIPS_DVP_27_S4:
1784 return &elf_mips_dvp_27_s4_howto;
1785 case BFD_RELOC_MIPS_DVP_11_S4:
1786 return &elf_mips_dvp_11_s4_howto;
1787 case BFD_RELOC_MIPS_DVP_U15_S3:
1788 return &elf_mips_dvp_u15_s3_howto;
1789 /* end-sanitize-sky */
1790 case BFD_RELOC_VTABLE_INHERIT:
1791 return &elf_mips_gnu_vtinherit_howto;
1792 case BFD_RELOC_VTABLE_ENTRY:
1793 return &elf_mips_gnu_vtentry_howto;
1797 /* Given a MIPS reloc type, fill in an arelent structure. */
1800 mips_info_to_howto_rel (abfd, cache_ptr, dst)
1803 Elf32_Internal_Rel *dst;
1805 unsigned int r_type;
1807 r_type = ELF32_R_TYPE (dst->r_info);
1811 cache_ptr->howto = &elf_mips16_jump_howto;
1813 case R_MIPS16_GPREL:
1814 cache_ptr->howto = &elf_mips16_gprel_howto;
1816 /* start-sanitize-r5900 */
1818 cache_ptr->howto = &elf_mips15_s3_howto;
1820 /* end-sanitize-r5900 */
1821 /* start-sanitize-sky */
1822 case R_MIPS_DVP_11_PCREL:
1823 cache_ptr->howto = &elf_mips_dvp_11_pcrel_howto;
1825 case R_MIPS_DVP_27_S4:
1826 cache_ptr->howto = &elf_mips_dvp_27_s4_howto;
1828 case R_MIPS_DVP_11_S4:
1829 cache_ptr->howto = &elf_mips_dvp_11_s4_howto;
1831 case R_MIPS_DVP_U15_S3:
1832 cache_ptr->howto = &elf_mips_dvp_u15_s3_howto;
1834 /* end-sanitize-sky */
1835 case R_MIPS_GNU_VTINHERIT:
1836 cache_ptr->howto = &elf_mips_gnu_vtinherit_howto;
1838 case R_MIPS_GNU_VTENTRY:
1839 cache_ptr->howto = &elf_mips_gnu_vtentry_howto;
1843 BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
1844 cache_ptr->howto = &elf_mips_howto_table[r_type];
1848 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1849 value for the object file. We get the addend now, rather than
1850 when we do the relocation, because the symbol manipulations done
1851 by the linker may cause us to lose track of the input BFD. */
1852 if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
1853 && (r_type == (unsigned int) R_MIPS_GPREL16
1854 || r_type == (unsigned int) R_MIPS_LITERAL))
1855 cache_ptr->addend = elf_gp (abfd);
1858 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1859 routines swap this structure in and out. They are used outside of
1860 BFD, so they are globally visible. */
1863 bfd_mips_elf32_swap_reginfo_in (abfd, ex, in)
1865 const Elf32_External_RegInfo *ex;
1868 in->ri_gprmask = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_gprmask);
1869 in->ri_cprmask[0] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[0]);
1870 in->ri_cprmask[1] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[1]);
1871 in->ri_cprmask[2] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[2]);
1872 in->ri_cprmask[3] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[3]);
1873 in->ri_gp_value = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_gp_value);
1877 bfd_mips_elf32_swap_reginfo_out (abfd, in, ex)
1879 const Elf32_RegInfo *in;
1880 Elf32_External_RegInfo *ex;
1882 bfd_h_put_32 (abfd, (bfd_vma) in->ri_gprmask,
1883 (bfd_byte *) ex->ri_gprmask);
1884 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[0],
1885 (bfd_byte *) ex->ri_cprmask[0]);
1886 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[1],
1887 (bfd_byte *) ex->ri_cprmask[1]);
1888 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[2],
1889 (bfd_byte *) ex->ri_cprmask[2]);
1890 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[3],
1891 (bfd_byte *) ex->ri_cprmask[3]);
1892 bfd_h_put_32 (abfd, (bfd_vma) in->ri_gp_value,
1893 (bfd_byte *) ex->ri_gp_value);
1896 /* In the 64 bit ABI, the .MIPS.options section holds register
1897 information in an Elf64_Reginfo structure. These routines swap
1898 them in and out. They are globally visible because they are used
1899 outside of BFD. These routines are here so that gas can call them
1900 without worrying about whether the 64 bit ABI has been included. */
1903 bfd_mips_elf64_swap_reginfo_in (abfd, ex, in)
1905 const Elf64_External_RegInfo *ex;
1906 Elf64_Internal_RegInfo *in;
1908 in->ri_gprmask = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_gprmask);
1909 in->ri_pad = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_pad);
1910 in->ri_cprmask[0] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[0]);
1911 in->ri_cprmask[1] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[1]);
1912 in->ri_cprmask[2] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[2]);
1913 in->ri_cprmask[3] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[3]);
1914 in->ri_gp_value = bfd_h_get_64 (abfd, (bfd_byte *) ex->ri_gp_value);
1918 bfd_mips_elf64_swap_reginfo_out (abfd, in, ex)
1920 const Elf64_Internal_RegInfo *in;
1921 Elf64_External_RegInfo *ex;
1923 bfd_h_put_32 (abfd, (bfd_vma) in->ri_gprmask,
1924 (bfd_byte *) ex->ri_gprmask);
1925 bfd_h_put_32 (abfd, (bfd_vma) in->ri_pad,
1926 (bfd_byte *) ex->ri_pad);
1927 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[0],
1928 (bfd_byte *) ex->ri_cprmask[0]);
1929 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[1],
1930 (bfd_byte *) ex->ri_cprmask[1]);
1931 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[2],
1932 (bfd_byte *) ex->ri_cprmask[2]);
1933 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[3],
1934 (bfd_byte *) ex->ri_cprmask[3]);
1935 bfd_h_put_64 (abfd, (bfd_vma) in->ri_gp_value,
1936 (bfd_byte *) ex->ri_gp_value);
1939 /* Swap an entry in a .gptab section. Note that these routines rely
1940 on the equivalence of the two elements of the union. */
1943 bfd_mips_elf32_swap_gptab_in (abfd, ex, in)
1945 const Elf32_External_gptab *ex;
1948 in->gt_entry.gt_g_value = bfd_h_get_32 (abfd, ex->gt_entry.gt_g_value);
1949 in->gt_entry.gt_bytes = bfd_h_get_32 (abfd, ex->gt_entry.gt_bytes);
1953 bfd_mips_elf32_swap_gptab_out (abfd, in, ex)
1955 const Elf32_gptab *in;
1956 Elf32_External_gptab *ex;
1958 bfd_h_put_32 (abfd, (bfd_vma) in->gt_entry.gt_g_value,
1959 ex->gt_entry.gt_g_value);
1960 bfd_h_put_32 (abfd, (bfd_vma) in->gt_entry.gt_bytes,
1961 ex->gt_entry.gt_bytes);
1965 bfd_elf32_swap_compact_rel_out (abfd, in, ex)
1967 const Elf32_compact_rel *in;
1968 Elf32_External_compact_rel *ex;
1970 bfd_h_put_32 (abfd, (bfd_vma) in->id1, ex->id1);
1971 bfd_h_put_32 (abfd, (bfd_vma) in->num, ex->num);
1972 bfd_h_put_32 (abfd, (bfd_vma) in->id2, ex->id2);
1973 bfd_h_put_32 (abfd, (bfd_vma) in->offset, ex->offset);
1974 bfd_h_put_32 (abfd, (bfd_vma) in->reserved0, ex->reserved0);
1975 bfd_h_put_32 (abfd, (bfd_vma) in->reserved1, ex->reserved1);
1979 bfd_elf32_swap_crinfo_out (abfd, in, ex)
1981 const Elf32_crinfo *in;
1982 Elf32_External_crinfo *ex;
1986 l = (((in->ctype & CRINFO_CTYPE) << CRINFO_CTYPE_SH)
1987 | ((in->rtype & CRINFO_RTYPE) << CRINFO_RTYPE_SH)
1988 | ((in->dist2to & CRINFO_DIST2TO) << CRINFO_DIST2TO_SH)
1989 | ((in->relvaddr & CRINFO_RELVADDR) << CRINFO_RELVADDR_SH));
1990 bfd_h_put_32 (abfd, (bfd_vma) l, ex->info);
1991 bfd_h_put_32 (abfd, (bfd_vma) in->konst, ex->konst);
1992 bfd_h_put_32 (abfd, (bfd_vma) in->vaddr, ex->vaddr);
1995 /* Swap in an options header. */
1998 bfd_mips_elf_swap_options_in (abfd, ex, in)
2000 const Elf_External_Options *ex;
2001 Elf_Internal_Options *in;
2003 in->kind = bfd_h_get_8 (abfd, ex->kind);
2004 in->size = bfd_h_get_8 (abfd, ex->size);
2005 in->section = bfd_h_get_16 (abfd, ex->section);
2006 in->info = bfd_h_get_32 (abfd, ex->info);
2009 /* Swap out an options header. */
2012 bfd_mips_elf_swap_options_out (abfd, in, ex)
2014 const Elf_Internal_Options *in;
2015 Elf_External_Options *ex;
2017 bfd_h_put_8 (abfd, in->kind, ex->kind);
2018 bfd_h_put_8 (abfd, in->size, ex->size);
2019 bfd_h_put_16 (abfd, in->section, ex->section);
2020 bfd_h_put_32 (abfd, in->info, ex->info);
2023 /* Determine whether a symbol is global for the purposes of splitting
2024 the symbol table into global symbols and local symbols. At least
2025 on Irix 5, this split must be between section symbols and all other
2026 symbols. On most ELF targets the split is between static symbols
2027 and externally visible symbols. */
2031 mips_elf_sym_is_global (abfd, sym)
2035 return (sym->flags & BSF_SECTION_SYM) == 0 ? true : false;
2038 /* Set the right machine number for a MIPS ELF file. This is used for
2039 both the 32-bit and the 64-bit ABI. */
2042 _bfd_mips_elf_object_p (abfd)
2045 bfd_default_set_arch_mach (abfd, bfd_arch_mips,
2046 elf_mips_mach (elf_elfheader (abfd)->e_flags));
2050 /* Set the right machine number for a 32-bit MIPS ELF file. */
2053 mips_elf32_object_p (abfd)
2056 /* Irix 5 is broken. Object file symbol tables are not always
2057 sorted correctly such that local symbols precede global symbols,
2058 and the sh_info field in the symbol table is not always right. */
2059 elf_bad_symtab (abfd) = true;
2061 return _bfd_mips_elf_object_p (abfd);
2064 /* The final processing done just before writing out a MIPS ELF object
2065 file. This gets the MIPS architecture right based on the machine
2066 number. This is used by both the 32-bit and the 64-bit ABI. */
2070 _bfd_mips_elf_final_write_processing (abfd, linker)
2076 Elf_Internal_Shdr **hdrpp;
2080 switch (bfd_get_mach (abfd))
2083 case bfd_mach_mips3000:
2084 val = E_MIPS_ARCH_1;
2087 case bfd_mach_mips3900:
2088 val = E_MIPS_ARCH_1 | E_MIPS_MACH_3900;
2091 case bfd_mach_mips6000:
2092 val = E_MIPS_ARCH_2;
2095 case bfd_mach_mips4000:
2096 case bfd_mach_mips4300:
2097 val = E_MIPS_ARCH_3;
2100 case bfd_mach_mips4010:
2101 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4010;
2104 case bfd_mach_mips4100:
2105 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4100;
2107 /* start-sanitize-vr4320 */
2109 case bfd_mach_mips4320:
2110 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4320;
2112 /* end-sanitize-vr4320 */
2114 case bfd_mach_mips4650:
2115 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4650;
2117 /* start-sanitize-tx49 */
2119 case bfd_mach_mips4900:
2120 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4900;
2122 /* end-sanitize-tx49 */
2123 /* start-sanitize-cygnus */
2125 case bfd_mach_mips5400:
2126 val = E_MIPS_ARCH_3 | E_MIPS_MACH_5400;
2128 /* end-sanitize-cygnus */
2129 /* start-sanitize-r5900 */
2131 case bfd_mach_mips5900:
2132 val = E_MIPS_ARCH_3 | E_MIPS_MACH_5900;
2134 /* end-sanitize-r5900 */
2136 case bfd_mach_mips8000:
2137 val = E_MIPS_ARCH_4;
2141 elf_elfheader (abfd)->e_flags &= ~ (EF_MIPS_ARCH | EF_MIPS_MACH);
2142 elf_elfheader (abfd)->e_flags |= val;
2144 /* Set the sh_info field for .gptab sections and other appropriate
2145 info for each special section. */
2146 for (i = 1, hdrpp = elf_elfsections (abfd) + 1;
2147 i < elf_elfheader (abfd)->e_shnum;
2150 switch ((*hdrpp)->sh_type)
2152 case SHT_MIPS_LIBLIST:
2153 sec = bfd_get_section_by_name (abfd, ".dynstr");
2155 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx;
2158 case SHT_MIPS_GPTAB:
2159 BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
2160 name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section);
2161 BFD_ASSERT (name != NULL
2162 && strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0);
2163 sec = bfd_get_section_by_name (abfd, name + sizeof ".gptab" - 1);
2164 BFD_ASSERT (sec != NULL);
2165 (*hdrpp)->sh_info = elf_section_data (sec)->this_idx;
2168 case SHT_MIPS_CONTENT:
2169 BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
2170 name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section);
2171 BFD_ASSERT (name != NULL
2172 && strncmp (name, ".MIPS.content",
2173 sizeof ".MIPS.content" - 1) == 0);
2174 sec = bfd_get_section_by_name (abfd,
2175 name + sizeof ".MIPS.content" - 1);
2176 BFD_ASSERT (sec != NULL);
2177 (*hdrpp)->sh_info = elf_section_data (sec)->this_idx;
2180 case SHT_MIPS_SYMBOL_LIB:
2181 sec = bfd_get_section_by_name (abfd, ".dynsym");
2183 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx;
2184 sec = bfd_get_section_by_name (abfd, ".liblist");
2186 (*hdrpp)->sh_info = elf_section_data (sec)->this_idx;
2189 case SHT_MIPS_EVENTS:
2190 BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
2191 name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section);
2192 BFD_ASSERT (name != NULL);
2193 if (strncmp (name, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
2194 sec = bfd_get_section_by_name (abfd,
2195 name + sizeof ".MIPS.events" - 1);
2198 BFD_ASSERT (strncmp (name, ".MIPS.post_rel",
2199 sizeof ".MIPS.post_rel" - 1) == 0);
2200 sec = bfd_get_section_by_name (abfd,
2202 + sizeof ".MIPS.post_rel" - 1));
2204 BFD_ASSERT (sec != NULL);
2205 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx;
2208 /* start-sanitize-sky */
2209 case SHT_DVP_OVERLAY_TABLE:
2210 /* ??? This may not be technically necessary, just going with
2212 sec = bfd_get_section_by_name (abfd, SHNAME_DVP_OVERLAY_STRTAB);
2214 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx;
2216 /* end-sanitize-sky */
2221 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
2224 _bfd_mips_elf_set_private_flags (abfd, flags)
2228 BFD_ASSERT (!elf_flags_init (abfd)
2229 || elf_elfheader (abfd)->e_flags == flags);
2231 elf_elfheader (abfd)->e_flags = flags;
2232 elf_flags_init (abfd) = true;
2236 /* Copy backend specific data from one object module to another */
2239 _bfd_mips_elf_copy_private_bfd_data (ibfd, obfd)
2243 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
2244 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
2247 BFD_ASSERT (!elf_flags_init (obfd)
2248 || (elf_elfheader (obfd)->e_flags
2249 == elf_elfheader (ibfd)->e_flags));
2251 elf_gp (obfd) = elf_gp (ibfd);
2252 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
2253 elf_flags_init (obfd) = true;
2257 /* Merge backend specific data from an object file to the output
2258 object file when linking. */
2261 _bfd_mips_elf_merge_private_bfd_data (ibfd, obfd)
2269 /* Check if we have the same endianess */
2270 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
2271 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
2275 if (bfd_big_endian (ibfd))
2276 msg = _("%s: compiled for a big endian system and target is little endian");
2278 msg = _("%s: compiled for a little endian system and target is big endian");
2280 (*_bfd_error_handler) (msg, bfd_get_filename (ibfd));
2282 bfd_set_error (bfd_error_wrong_format);
2286 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
2287 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
2290 new_flags = elf_elfheader (ibfd)->e_flags;
2291 elf_elfheader (obfd)->e_flags |= new_flags & EF_MIPS_NOREORDER;
2292 old_flags = elf_elfheader (obfd)->e_flags;
2294 if (! elf_flags_init (obfd))
2296 elf_flags_init (obfd) = true;
2297 elf_elfheader (obfd)->e_flags = new_flags;
2299 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
2300 && bfd_get_arch_info (obfd)->the_default)
2302 if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
2303 bfd_get_mach (ibfd)))
2310 /* Check flag compatibility. */
2312 new_flags &= ~EF_MIPS_NOREORDER;
2313 old_flags &= ~EF_MIPS_NOREORDER;
2315 if (new_flags == old_flags)
2320 if ((new_flags & EF_MIPS_PIC) != (old_flags & EF_MIPS_PIC))
2322 new_flags &= ~EF_MIPS_PIC;
2323 old_flags &= ~EF_MIPS_PIC;
2324 (*_bfd_error_handler)
2325 (_("%s: linking PIC files with non-PIC files"),
2326 bfd_get_filename (ibfd));
2330 if ((new_flags & EF_MIPS_CPIC) != (old_flags & EF_MIPS_CPIC))
2332 new_flags &= ~EF_MIPS_CPIC;
2333 old_flags &= ~EF_MIPS_CPIC;
2334 (*_bfd_error_handler)
2335 (_("%s: linking abicalls files with non-abicalls files"),
2336 bfd_get_filename (ibfd));
2340 /* Compare the ISA's. */
2341 if ((new_flags & (EF_MIPS_ARCH | EF_MIPS_MACH))
2342 != (old_flags & (EF_MIPS_ARCH | EF_MIPS_MACH)))
2344 /* If either has no machine specified, just compare the general isa's. */
2345 if ( !(new_flags & EF_MIPS_MACH) || !(old_flags & EF_MIPS_MACH))
2347 int new_isa, old_isa;
2349 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
2350 and -mips4 code. They will normally use the same data sizes and
2351 calling conventions. */
2353 new_isa = elf_mips_isa (new_flags);
2354 old_isa = elf_mips_isa (old_flags);
2355 if ((new_isa == 1 || new_isa == 2)
2356 ? (old_isa != 1 && old_isa != 2)
2357 : (old_isa == 1 || old_isa == 2))
2359 (*_bfd_error_handler)
2360 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
2361 bfd_get_filename (ibfd), new_isa, old_isa);
2368 (*_bfd_error_handler)
2369 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
2370 bfd_get_filename (ibfd),
2371 elf_mips_mach (new_flags),
2372 elf_mips_mach (old_flags));
2376 new_flags &= ~ (EF_MIPS_ARCH | EF_MIPS_MACH);
2377 old_flags &= ~ (EF_MIPS_ARCH | EF_MIPS_MACH);
2380 /* Warn about any other mismatches */
2381 if (new_flags != old_flags)
2383 (*_bfd_error_handler)
2384 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2385 bfd_get_filename (ibfd), (unsigned long) new_flags,
2386 (unsigned long) old_flags);
2392 bfd_set_error (bfd_error_bad_value);
2399 /* Handle a MIPS specific section when reading an object file. This
2400 is called when elfcode.h finds a section with an unknown type.
2401 This routine supports both the 32-bit and 64-bit ELF ABI.
2403 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2407 _bfd_mips_elf_section_from_shdr (abfd, hdr, name)
2409 Elf_Internal_Shdr *hdr;
2412 /* There ought to be a place to keep ELF backend specific flags, but
2413 at the moment there isn't one. We just keep track of the
2414 sections by their name, instead. Fortunately, the ABI gives
2415 suggested names for all the MIPS specific sections, so we will
2416 probably get away with this. */
2417 switch (hdr->sh_type)
2419 case SHT_MIPS_LIBLIST:
2420 if (strcmp (name, ".liblist") != 0)
2424 if (strcmp (name, ".msym") != 0)
2427 case SHT_MIPS_CONFLICT:
2428 if (strcmp (name, ".conflict") != 0)
2431 case SHT_MIPS_GPTAB:
2432 if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) != 0)
2435 case SHT_MIPS_UCODE:
2436 if (strcmp (name, ".ucode") != 0)
2439 case SHT_MIPS_DEBUG:
2440 if (strcmp (name, ".mdebug") != 0)
2443 case SHT_MIPS_REGINFO:
2444 if (strcmp (name, ".reginfo") != 0
2445 || hdr->sh_size != sizeof (Elf32_External_RegInfo))
2448 case SHT_MIPS_IFACE:
2449 if (strcmp (name, ".MIPS.interfaces") != 0)
2452 case SHT_MIPS_CONTENT:
2453 if (strncmp (name, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2456 case SHT_MIPS_OPTIONS:
2457 if (strcmp (name, ".options") != 0
2458 && strcmp (name, ".MIPS.options") != 0)
2461 case SHT_MIPS_DWARF:
2462 if (strncmp (name, ".debug_", sizeof ".debug_" - 1) != 0)
2465 case SHT_MIPS_SYMBOL_LIB:
2466 if (strcmp (name, ".MIPS.symlib") != 0)
2469 case SHT_MIPS_EVENTS:
2470 if (strncmp (name, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2471 && strncmp (name, ".MIPS.post_rel",
2472 sizeof ".MIPS.post_rel" - 1) != 0)
2475 /* start-sanitize-sky */
2476 case SHT_DVP_OVERLAY_TABLE:
2477 if (strcmp (name, SHNAME_DVP_OVERLAY_TABLE) !=0)
2480 case SHT_DVP_OVERLAY:
2481 if (strncmp (name, SHNAME_DVP_OVERLAY_PREFIX,
2482 sizeof (SHNAME_DVP_OVERLAY_PREFIX) - 1) !=0)
2485 /* end-sanitize-sky */
2490 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
2493 if (hdr->sh_type == SHT_MIPS_DEBUG)
2495 if (! bfd_set_section_flags (abfd, hdr->bfd_section,
2496 (bfd_get_section_flags (abfd,
2505 /* Handle a 32-bit MIPS ELF specific section. */
2508 mips_elf32_section_from_shdr (abfd, hdr, name)
2510 Elf_Internal_Shdr *hdr;
2513 if (! _bfd_mips_elf_section_from_shdr (abfd, hdr, name))
2516 /* FIXME: We should record sh_info for a .gptab section. */
2518 /* For a .reginfo section, set the gp value in the tdata information
2519 from the contents of this section. We need the gp value while
2520 processing relocs, so we just get it now. The .reginfo section
2521 is not used in the 64-bit MIPS ELF ABI. */
2522 if (hdr->sh_type == SHT_MIPS_REGINFO)
2524 Elf32_External_RegInfo ext;
2527 if (! bfd_get_section_contents (abfd, hdr->bfd_section, (PTR) &ext,
2528 (file_ptr) 0, sizeof ext))
2530 bfd_mips_elf32_swap_reginfo_in (abfd, &ext, &s);
2531 elf_gp (abfd) = s.ri_gp_value;
2534 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2535 set the gp value based on what we find. We may see both
2536 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2537 they should agree. */
2538 if (hdr->sh_type == SHT_MIPS_OPTIONS)
2540 bfd_byte *contents, *l, *lend;
2542 contents = (bfd_byte *) bfd_malloc (hdr->sh_size);
2543 if (contents == NULL)
2545 if (! bfd_get_section_contents (abfd, hdr->bfd_section, contents,
2546 (file_ptr) 0, hdr->sh_size))
2552 lend = contents + hdr->sh_size;
2553 while (l + sizeof (Elf_External_Options) <= lend)
2555 Elf_Internal_Options intopt;
2557 bfd_mips_elf_swap_options_in (abfd, (Elf_External_Options *) l,
2559 if (intopt.kind == ODK_REGINFO)
2561 Elf32_RegInfo intreg;
2563 bfd_mips_elf32_swap_reginfo_in
2565 ((Elf32_External_RegInfo *)
2566 (l + sizeof (Elf_External_Options))),
2568 elf_gp (abfd) = intreg.ri_gp_value;
2578 /* Set the correct type for a MIPS ELF section. We do this by the
2579 section name, which is a hack, but ought to work. This routine is
2580 used by both the 32-bit and the 64-bit ABI. */
2583 _bfd_mips_elf_fake_sections (abfd, hdr, sec)
2585 Elf32_Internal_Shdr *hdr;
2588 register const char *name;
2590 name = bfd_get_section_name (abfd, sec);
2592 if (strcmp (name, ".liblist") == 0)
2594 hdr->sh_type = SHT_MIPS_LIBLIST;
2595 hdr->sh_info = sec->_raw_size / sizeof (Elf32_Lib);
2596 /* The sh_link field is set in final_write_processing. */
2598 else if (strcmp (name, ".msym") == 0)
2600 hdr->sh_type = SHT_MIPS_MSYM;
2601 hdr->sh_entsize = 8;
2602 /* FIXME: Set the sh_info field. */
2604 else if (strcmp (name, ".conflict") == 0)
2605 hdr->sh_type = SHT_MIPS_CONFLICT;
2606 else if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0)
2608 hdr->sh_type = SHT_MIPS_GPTAB;
2609 hdr->sh_entsize = sizeof (Elf32_External_gptab);
2610 /* The sh_info field is set in final_write_processing. */
2612 else if (strcmp (name, ".ucode") == 0)
2613 hdr->sh_type = SHT_MIPS_UCODE;
2614 else if (strcmp (name, ".mdebug") == 0)
2616 hdr->sh_type = SHT_MIPS_DEBUG;
2617 /* In a shared object on Irix 5.3, the .mdebug section has an
2618 entsize of 0. FIXME: Does this matter? */
2619 if (SGI_COMPAT (abfd) && (abfd->flags & DYNAMIC) != 0)
2620 hdr->sh_entsize = 0;
2622 hdr->sh_entsize = 1;
2624 else if (strcmp (name, ".reginfo") == 0)
2626 hdr->sh_type = SHT_MIPS_REGINFO;
2627 /* In a shared object on Irix 5.3, the .reginfo section has an
2628 entsize of 0x18. FIXME: Does this matter? */
2629 if (SGI_COMPAT (abfd) && (abfd->flags & DYNAMIC) != 0)
2630 hdr->sh_entsize = sizeof (Elf32_External_RegInfo);
2632 hdr->sh_entsize = 1;
2634 /* Force the section size to the correct value, even if the
2635 linker thinks it is larger. The link routine below will only
2636 write out this much data for .reginfo. */
2637 hdr->sh_size = sec->_raw_size = sizeof (Elf32_External_RegInfo);
2639 else if (SGI_COMPAT (abfd)
2640 && (strcmp (name, ".hash") == 0
2641 || strcmp (name, ".dynamic") == 0
2642 || strcmp (name, ".dynstr") == 0))
2644 hdr->sh_entsize = 0;
2646 /* This isn't how the Irix 6 linker behaves. */
2647 hdr->sh_info = SIZEOF_MIPS_DYNSYM_SECNAMES;
2650 else if (strcmp (name, ".got") == 0
2651 || strcmp (name, ".sdata") == 0
2652 || strcmp (name, ".sbss") == 0
2653 || strcmp (name, ".lit4") == 0
2654 || strcmp (name, ".lit8") == 0)
2655 hdr->sh_flags |= SHF_MIPS_GPREL;
2656 else if (strcmp (name, ".MIPS.interfaces") == 0)
2658 hdr->sh_type = SHT_MIPS_IFACE;
2659 hdr->sh_flags |= SHF_MIPS_NOSTRIP;
2661 else if (strcmp (name, ".MIPS.content") == 0)
2663 hdr->sh_type = SHT_MIPS_CONTENT;
2664 /* The sh_info field is set in final_write_processing. */
2666 else if (strcmp (name, ".options") == 0
2667 || strcmp (name, ".MIPS.options") == 0)
2669 hdr->sh_type = SHT_MIPS_OPTIONS;
2670 hdr->sh_entsize = 1;
2671 hdr->sh_flags |= SHF_MIPS_NOSTRIP;
2673 else if (strncmp (name, ".debug_", sizeof ".debug_" - 1) == 0)
2674 hdr->sh_type = SHT_MIPS_DWARF;
2675 else if (strcmp (name, ".MIPS.symlib") == 0)
2677 hdr->sh_type = SHT_MIPS_SYMBOL_LIB;
2678 /* The sh_link and sh_info fields are set in
2679 final_write_processing. */
2681 else if (strncmp (name, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2682 || strncmp (name, ".MIPS.post_rel",
2683 sizeof ".MIPS.post_rel" - 1) == 0)
2685 hdr->sh_type = SHT_MIPS_EVENTS;
2686 hdr->sh_flags |= SHF_MIPS_NOSTRIP;
2687 /* The sh_link field is set in final_write_processing. */
2689 /* start-sanitize-sky */
2690 else if (strcmp (name, SHNAME_DVP_OVERLAY_TABLE) == 0)
2692 hdr->sh_type = SHT_DVP_OVERLAY_TABLE;
2693 hdr->sh_entsize = sizeof (Elf32_Dvp_External_Overlay);
2694 /* The sh_link field is set in final_write_processing. */
2696 else if (strcmp (name, SHNAME_DVP_OVERLAY_STRTAB) == 0)
2697 hdr->sh_type = SHT_STRTAB;
2698 else if (strncmp (name, SHNAME_DVP_OVERLAY_PREFIX,
2699 sizeof (SHNAME_DVP_OVERLAY_PREFIX) - 1) == 0)
2700 hdr->sh_type = SHT_DVP_OVERLAY;
2701 /* end-sanitize-sky */
2706 /* Given a BFD section, try to locate the corresponding ELF section
2707 index. This is used by both the 32-bit and the 64-bit ABI.
2708 Actually, it's not clear to me that the 64-bit ABI supports these,
2709 but for non-PIC objects we will certainly want support for at least
2710 the .scommon section. */
2713 _bfd_mips_elf_section_from_bfd_section (abfd, hdr, sec, retval)
2715 Elf32_Internal_Shdr *hdr;
2719 if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)
2721 *retval = SHN_MIPS_SCOMMON;
2724 if (strcmp (bfd_get_section_name (abfd, sec), ".acommon") == 0)
2726 *retval = SHN_MIPS_ACOMMON;
2732 /* When are writing out the .options or .MIPS.options section,
2733 remember the bytes we are writing out, so that we can install the
2734 GP value in the section_processing routine. */
2737 _bfd_mips_elf_set_section_contents (abfd, section, location, offset, count)
2742 bfd_size_type count;
2744 if (strcmp (section->name, ".options") == 0
2745 || strcmp (section->name, ".MIPS.options") == 0)
2749 if (elf_section_data (section) == NULL)
2751 section->used_by_bfd =
2752 (PTR) bfd_zalloc (abfd, sizeof (struct bfd_elf_section_data));
2753 if (elf_section_data (section) == NULL)
2756 c = (bfd_byte *) elf_section_data (section)->tdata;
2761 if (section->_cooked_size != 0)
2762 size = section->_cooked_size;
2764 size = section->_raw_size;
2765 c = (bfd_byte *) bfd_zalloc (abfd, size);
2768 elf_section_data (section)->tdata = (PTR) c;
2771 memcpy (c + offset, location, count);
2774 return _bfd_elf_set_section_contents (abfd, section, location, offset,
2778 /* Work over a section just before writing it out. This routine is
2779 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2780 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2784 _bfd_mips_elf_section_processing (abfd, hdr)
2786 Elf_Internal_Shdr *hdr;
2788 if (hdr->bfd_section != NULL)
2790 const char *name = bfd_get_section_name (abfd, hdr->bfd_section);
2792 if (strcmp (name, ".sdata") == 0)
2794 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
2795 hdr->sh_type = SHT_PROGBITS;
2797 else if (strcmp (name, ".sbss") == 0)
2799 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
2800 hdr->sh_type = SHT_NOBITS;
2802 else if (strcmp (name, ".lit8") == 0
2803 || strcmp (name, ".lit4") == 0)
2805 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
2806 hdr->sh_type = SHT_PROGBITS;
2808 else if (strcmp (name, ".compact_rel") == 0)
2811 hdr->sh_type = SHT_PROGBITS;
2813 else if (strcmp (name, ".rtproc") == 0)
2815 if (hdr->sh_addralign != 0 && hdr->sh_entsize == 0)
2817 unsigned int adjust;
2819 adjust = hdr->sh_size % hdr->sh_addralign;
2821 hdr->sh_size += hdr->sh_addralign - adjust;
2829 /* Work over a section just before writing it out. We update the GP
2830 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2831 on the value we are using. */
2834 mips_elf32_section_processing (abfd, hdr)
2836 Elf32_Internal_Shdr *hdr;
2838 if (hdr->sh_type == SHT_MIPS_REGINFO)
2842 BFD_ASSERT (hdr->sh_size == sizeof (Elf32_External_RegInfo));
2843 BFD_ASSERT (hdr->contents == NULL);
2846 hdr->sh_offset + sizeof (Elf32_External_RegInfo) - 4,
2849 bfd_h_put_32 (abfd, (bfd_vma) elf_gp (abfd), buf);
2850 if (bfd_write (buf, (bfd_size_type) 1, (bfd_size_type) 4, abfd) != 4)
2854 if (hdr->sh_type == SHT_MIPS_OPTIONS
2855 && hdr->bfd_section != NULL
2856 && elf_section_data (hdr->bfd_section) != NULL
2857 && elf_section_data (hdr->bfd_section)->tdata != NULL)
2859 bfd_byte *contents, *l, *lend;
2861 /* We stored the section contents in the elf_section_data tdata
2862 field in the set_section_contents routine. We save the
2863 section contents so that we don't have to read them again.
2864 At this point we know that elf_gp is set, so we can look
2865 through the section contents to see if there is an
2866 ODK_REGINFO structure. */
2868 contents = (bfd_byte *) elf_section_data (hdr->bfd_section)->tdata;
2870 lend = contents + hdr->sh_size;
2871 while (l + sizeof (Elf_External_Options) <= lend)
2873 Elf_Internal_Options intopt;
2875 bfd_mips_elf_swap_options_in (abfd, (Elf_External_Options *) l,
2877 if (intopt.kind == ODK_REGINFO)
2884 + sizeof (Elf_External_Options)
2885 + (sizeof (Elf32_External_RegInfo) - 4)),
2888 bfd_h_put_32 (abfd, elf_gp (abfd), buf);
2889 if (bfd_write (buf, 1, 4, abfd) != 4)
2896 return _bfd_mips_elf_section_processing (abfd, hdr);
2899 /* MIPS ELF uses two common sections. One is the usual one, and the
2900 other is for small objects. All the small objects are kept
2901 together, and then referenced via the gp pointer, which yields
2902 faster assembler code. This is what we use for the small common
2903 section. This approach is copied from ecoff.c. */
2904 static asection mips_elf_scom_section;
2905 static asymbol mips_elf_scom_symbol;
2906 static asymbol *mips_elf_scom_symbol_ptr;
2908 /* MIPS ELF also uses an acommon section, which represents an
2909 allocated common symbol which may be overridden by a
2910 definition in a shared library. */
2911 static asection mips_elf_acom_section;
2912 static asymbol mips_elf_acom_symbol;
2913 static asymbol *mips_elf_acom_symbol_ptr;
2915 /* The Irix 5 support uses two virtual sections, which represent
2916 text/data symbols defined in dynamic objects. */
2917 static asection mips_elf_text_section;
2918 static asection *mips_elf_text_section_ptr;
2919 static asymbol mips_elf_text_symbol;
2920 static asymbol *mips_elf_text_symbol_ptr;
2922 static asection mips_elf_data_section;
2923 static asection *mips_elf_data_section_ptr;
2924 static asymbol mips_elf_data_symbol;
2925 static asymbol *mips_elf_data_symbol_ptr;
2927 /* Handle the special MIPS section numbers that a symbol may use.
2928 This is used for both the 32-bit and the 64-bit ABI. */
2931 _bfd_mips_elf_symbol_processing (abfd, asym)
2935 elf_symbol_type *elfsym;
2937 elfsym = (elf_symbol_type *) asym;
2938 switch (elfsym->internal_elf_sym.st_shndx)
2940 case SHN_MIPS_ACOMMON:
2941 /* This section is used in a dynamically linked executable file.
2942 It is an allocated common section. The dynamic linker can
2943 either resolve these symbols to something in a shared
2944 library, or it can just leave them here. For our purposes,
2945 we can consider these symbols to be in a new section. */
2946 if (mips_elf_acom_section.name == NULL)
2948 /* Initialize the acommon section. */
2949 mips_elf_acom_section.name = ".acommon";
2950 mips_elf_acom_section.flags = SEC_ALLOC;
2951 mips_elf_acom_section.output_section = &mips_elf_acom_section;
2952 mips_elf_acom_section.symbol = &mips_elf_acom_symbol;
2953 mips_elf_acom_section.symbol_ptr_ptr = &mips_elf_acom_symbol_ptr;
2954 mips_elf_acom_symbol.name = ".acommon";
2955 mips_elf_acom_symbol.flags = BSF_SECTION_SYM;
2956 mips_elf_acom_symbol.section = &mips_elf_acom_section;
2957 mips_elf_acom_symbol_ptr = &mips_elf_acom_symbol;
2959 asym->section = &mips_elf_acom_section;
2963 /* Common symbols less than the GP size are automatically
2964 treated as SHN_MIPS_SCOMMON symbols. */
2965 if (asym->value > elf_gp_size (abfd))
2968 case SHN_MIPS_SCOMMON:
2969 if (mips_elf_scom_section.name == NULL)
2971 /* Initialize the small common section. */
2972 mips_elf_scom_section.name = ".scommon";
2973 mips_elf_scom_section.flags = SEC_IS_COMMON;
2974 mips_elf_scom_section.output_section = &mips_elf_scom_section;
2975 mips_elf_scom_section.symbol = &mips_elf_scom_symbol;
2976 mips_elf_scom_section.symbol_ptr_ptr = &mips_elf_scom_symbol_ptr;
2977 mips_elf_scom_symbol.name = ".scommon";
2978 mips_elf_scom_symbol.flags = BSF_SECTION_SYM;
2979 mips_elf_scom_symbol.section = &mips_elf_scom_section;
2980 mips_elf_scom_symbol_ptr = &mips_elf_scom_symbol;
2982 asym->section = &mips_elf_scom_section;
2983 asym->value = elfsym->internal_elf_sym.st_size;
2986 case SHN_MIPS_SUNDEFINED:
2987 asym->section = bfd_und_section_ptr;
2990 #if 0 /* for SGI_COMPAT */
2992 asym->section = mips_elf_text_section_ptr;
2996 asym->section = mips_elf_data_section_ptr;
3002 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
3006 mips_elf_additional_program_headers (abfd)
3014 if (! SGI_COMPAT (abfd))
3017 s = bfd_get_section_by_name (abfd, ".reginfo");
3018 if (s != NULL && (s->flags & SEC_LOAD) != 0)
3020 /* We need a PT_MIPS_REGINFO segment. */
3024 if (bfd_get_section_by_name (abfd, ".dynamic") != NULL
3025 && bfd_get_section_by_name (abfd, ".mdebug") != NULL)
3027 /* We need a PT_MIPS_RTPROC segment. */
3034 /* Modify the segment map for an Irix 5 executable. */
3037 mips_elf_modify_segment_map (abfd)
3041 struct elf_segment_map *m, **pm;
3043 if (! SGI_COMPAT (abfd))
3046 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
3048 s = bfd_get_section_by_name (abfd, ".reginfo");
3049 if (s != NULL && (s->flags & SEC_LOAD) != 0)
3051 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
3052 if (m->p_type == PT_MIPS_REGINFO)
3056 m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m);
3060 m->p_type = PT_MIPS_REGINFO;
3064 /* We want to put it after the PHDR and INTERP segments. */
3065 pm = &elf_tdata (abfd)->segment_map;
3067 && ((*pm)->p_type == PT_PHDR
3068 || (*pm)->p_type == PT_INTERP))
3076 /* If there are .dynamic and .mdebug sections, we make a room for
3077 the RTPROC header. FIXME: Rewrite without section names. */
3078 if (bfd_get_section_by_name (abfd, ".interp") == NULL
3079 && bfd_get_section_by_name (abfd, ".dynamic") != NULL
3080 && bfd_get_section_by_name (abfd, ".mdebug") != NULL)
3082 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
3083 if (m->p_type == PT_MIPS_RTPROC)
3087 m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m);
3091 m->p_type = PT_MIPS_RTPROC;
3093 s = bfd_get_section_by_name (abfd, ".rtproc");
3098 m->p_flags_valid = 1;
3106 /* We want to put it after the DYNAMIC segment. */
3107 pm = &elf_tdata (abfd)->segment_map;
3108 while (*pm != NULL && (*pm)->p_type != PT_DYNAMIC)
3118 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
3119 .dynsym, and .hash sections, and everything in between. */
3120 for (pm = &elf_tdata (abfd)->segment_map; *pm != NULL; pm = &(*pm)->next)
3121 if ((*pm)->p_type == PT_DYNAMIC)
3126 && strcmp (m->sections[0]->name, ".dynamic") == 0)
3128 static const char *sec_names[] =
3129 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
3132 struct elf_segment_map *n;
3136 for (i = 0; i < sizeof sec_names / sizeof sec_names[0]; i++)
3138 s = bfd_get_section_by_name (abfd, sec_names[i]);
3139 if (s != NULL && (s->flags & SEC_LOAD) != 0)
3145 sz = s->_cooked_size;
3148 if (high < s->vma + sz)
3154 for (s = abfd->sections; s != NULL; s = s->next)
3155 if ((s->flags & SEC_LOAD) != 0
3158 + (s->_cooked_size != 0 ? s->_cooked_size : s->_raw_size))
3162 n = ((struct elf_segment_map *)
3163 bfd_zalloc (abfd, sizeof *n + (c - 1) * sizeof (asection *)));
3170 for (s = abfd->sections; s != NULL; s = s->next)
3172 if ((s->flags & SEC_LOAD) != 0
3175 + (s->_cooked_size != 0 ? s->_cooked_size : s->_raw_size))
3189 /* The structure of the runtime procedure descriptor created by the
3190 loader for use by the static exception system. */
3192 typedef struct runtime_pdr {
3193 bfd_vma adr; /* memory address of start of procedure */
3194 long regmask; /* save register mask */
3195 long regoffset; /* save register offset */
3196 long fregmask; /* save floating point register mask */
3197 long fregoffset; /* save floating point register offset */
3198 long frameoffset; /* frame size */
3199 short framereg; /* frame pointer register */
3200 short pcreg; /* offset or reg of return pc */
3201 long irpss; /* index into the runtime string table */
3203 struct exception_info *exception_info;/* pointer to exception array */
3205 #define cbRPDR sizeof(RPDR)
3206 #define rpdNil ((pRPDR) 0)
3208 /* Swap RPDR (runtime procedure table entry) for output. */
3210 static void ecoff_swap_rpdr_out
3211 PARAMS ((bfd *, const RPDR *, struct rpdr_ext *));
3214 ecoff_swap_rpdr_out (abfd, in, ex)
3217 struct rpdr_ext *ex;
3219 /* ecoff_put_off was defined in ecoffswap.h. */
3220 ecoff_put_off (abfd, in->adr, (bfd_byte *) ex->p_adr);
3221 bfd_h_put_32 (abfd, in->regmask, (bfd_byte *) ex->p_regmask);
3222 bfd_h_put_32 (abfd, in->regoffset, (bfd_byte *) ex->p_regoffset);
3223 bfd_h_put_32 (abfd, in->fregmask, (bfd_byte *) ex->p_fregmask);
3224 bfd_h_put_32 (abfd, in->fregoffset, (bfd_byte *) ex->p_fregoffset);
3225 bfd_h_put_32 (abfd, in->frameoffset, (bfd_byte *) ex->p_frameoffset);
3227 bfd_h_put_16 (abfd, in->framereg, (bfd_byte *) ex->p_framereg);
3228 bfd_h_put_16 (abfd, in->pcreg, (bfd_byte *) ex->p_pcreg);
3230 bfd_h_put_32 (abfd, in->irpss, (bfd_byte *) ex->p_irpss);
3232 ecoff_put_off (abfd, in->exception_info, (bfd_byte *) ex->p_exception_info);
3236 /* Read ECOFF debugging information from a .mdebug section into a
3237 ecoff_debug_info structure. */
3240 _bfd_mips_elf_read_ecoff_info (abfd, section, debug)
3243 struct ecoff_debug_info *debug;
3246 const struct ecoff_debug_swap *swap;
3247 char *ext_hdr = NULL;
3249 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
3251 ext_hdr = (char *) bfd_malloc ((size_t) swap->external_hdr_size);
3252 if (ext_hdr == NULL && swap->external_hdr_size != 0)
3255 if (bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0,
3256 swap->external_hdr_size)
3260 symhdr = &debug->symbolic_header;
3261 (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr);
3263 /* The symbolic header contains absolute file offsets and sizes to
3265 #define READ(ptr, offset, count, size, type) \
3266 if (symhdr->count == 0) \
3267 debug->ptr = NULL; \
3270 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
3271 if (debug->ptr == NULL) \
3272 goto error_return; \
3273 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3274 || (bfd_read (debug->ptr, size, symhdr->count, \
3275 abfd) != size * symhdr->count)) \
3276 goto error_return; \
3279 READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *);
3280 READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR);
3281 READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR);
3282 READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR);
3283 READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR);
3284 READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext),
3286 READ (ss, cbSsOffset, issMax, sizeof (char), char *);
3287 READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *);
3288 READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR);
3289 READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR);
3290 READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR);
3294 debug->adjust = NULL;
3299 if (ext_hdr != NULL)
3301 if (debug->line != NULL)
3303 if (debug->external_dnr != NULL)
3304 free (debug->external_dnr);
3305 if (debug->external_pdr != NULL)
3306 free (debug->external_pdr);
3307 if (debug->external_sym != NULL)
3308 free (debug->external_sym);
3309 if (debug->external_opt != NULL)
3310 free (debug->external_opt);
3311 if (debug->external_aux != NULL)
3312 free (debug->external_aux);
3313 if (debug->ss != NULL)
3315 if (debug->ssext != NULL)
3316 free (debug->ssext);
3317 if (debug->external_fdr != NULL)
3318 free (debug->external_fdr);
3319 if (debug->external_rfd != NULL)
3320 free (debug->external_rfd);
3321 if (debug->external_ext != NULL)
3322 free (debug->external_ext);
3326 /* MIPS ELF local labels start with '$', not 'L'. */
3330 mips_elf_is_local_label_name (abfd, name)
3337 /* On Irix 6, the labels go back to starting with '.', so we accept
3338 the generic ELF local label syntax as well. */
3339 return _bfd_elf_is_local_label_name (abfd, name);
3342 /* MIPS ELF uses a special find_nearest_line routine in order the
3343 handle the ECOFF debugging information. */
3345 struct mips_elf_find_line
3347 struct ecoff_debug_info d;
3348 struct ecoff_find_line i;
3352 _bfd_mips_elf_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
3353 functionname_ptr, line_ptr)
3358 const char **filename_ptr;
3359 const char **functionname_ptr;
3360 unsigned int *line_ptr;
3364 if (_bfd_dwarf1_find_nearest_line (abfd, section, symbols, offset,
3365 filename_ptr, functionname_ptr,
3369 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
3370 filename_ptr, functionname_ptr,
3374 msec = bfd_get_section_by_name (abfd, ".mdebug");
3378 struct mips_elf_find_line *fi;
3379 const struct ecoff_debug_swap * const swap =
3380 get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
3382 /* If we are called during a link, mips_elf_final_link may have
3383 cleared the SEC_HAS_CONTENTS field. We force it back on here
3384 if appropriate (which it normally will be). */
3385 origflags = msec->flags;
3386 if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS)
3387 msec->flags |= SEC_HAS_CONTENTS;
3389 fi = elf_tdata (abfd)->find_line_info;
3392 bfd_size_type external_fdr_size;
3395 struct fdr *fdr_ptr;
3397 fi = ((struct mips_elf_find_line *)
3398 bfd_zalloc (abfd, sizeof (struct mips_elf_find_line)));
3401 msec->flags = origflags;
3405 if (! _bfd_mips_elf_read_ecoff_info (abfd, msec, &fi->d))
3407 msec->flags = origflags;
3411 /* Swap in the FDR information. */
3412 fi->d.fdr = ((struct fdr *)
3414 (fi->d.symbolic_header.ifdMax *
3415 sizeof (struct fdr))));
3416 if (fi->d.fdr == NULL)
3418 msec->flags = origflags;
3421 external_fdr_size = swap->external_fdr_size;
3422 fdr_ptr = fi->d.fdr;
3423 fraw_src = (char *) fi->d.external_fdr;
3424 fraw_end = (fraw_src
3425 + fi->d.symbolic_header.ifdMax * external_fdr_size);
3426 for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
3427 (*swap->swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr);
3429 elf_tdata (abfd)->find_line_info = fi;
3431 /* Note that we don't bother to ever free this information.
3432 find_nearest_line is either called all the time, as in
3433 objdump -l, so the information should be saved, or it is
3434 rarely called, as in ld error messages, so the memory
3435 wasted is unimportant. Still, it would probably be a
3436 good idea for free_cached_info to throw it away. */
3439 if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap,
3440 &fi->i, filename_ptr, functionname_ptr,
3443 msec->flags = origflags;
3447 msec->flags = origflags;
3450 /* Fall back on the generic ELF find_nearest_line routine. */
3452 return _bfd_elf_find_nearest_line (abfd, section, symbols, offset,
3453 filename_ptr, functionname_ptr,
3457 /* The mips16 compiler uses a couple of special sections to handle
3458 floating point arguments.
3460 Section names that look like .mips16.fn.FNNAME contain stubs that
3461 copy floating point arguments from the fp regs to the gp regs and
3462 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3463 call should be redirected to the stub instead. If no 32 bit
3464 function calls FNNAME, the stub should be discarded. We need to
3465 consider any reference to the function, not just a call, because
3466 if the address of the function is taken we will need the stub,
3467 since the address might be passed to a 32 bit function.
3469 Section names that look like .mips16.call.FNNAME contain stubs
3470 that copy floating point arguments from the gp regs to the fp
3471 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3472 then any 16 bit function that calls FNNAME should be redirected
3473 to the stub instead. If FNNAME is not a 32 bit function, the
3474 stub should be discarded.
3476 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3477 which call FNNAME and then copy the return value from the fp regs
3478 to the gp regs. These stubs store the return value in $18 while
3479 calling FNNAME; any function which might call one of these stubs
3480 must arrange to save $18 around the call. (This case is not
3481 needed for 32 bit functions that call 16 bit functions, because
3482 16 bit functions always return floating point values in both
3485 Note that in all cases FNNAME might be defined statically.
3486 Therefore, FNNAME is not used literally. Instead, the relocation
3487 information will indicate which symbol the section is for.
3489 We record any stubs that we find in the symbol table. */
3491 #define FN_STUB ".mips16.fn."
3492 #define CALL_STUB ".mips16.call."
3493 #define CALL_FP_STUB ".mips16.call.fp."
3495 /* The MIPS ELF linker needs additional information for each symbol in
3496 the global hash table. */
3498 struct mips_elf_link_hash_entry
3500 struct elf_link_hash_entry root;
3502 /* External symbol information. */
3505 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
3506 unsigned int mips_32_relocs;
3508 /* If there is a stub that 32 bit functions should use to call this
3509 16 bit function, this points to the section containing the stub. */
3512 /* Whether we need the fn_stub; this is set if this symbol appears
3513 in any relocs other than a 16 bit call. */
3514 boolean need_fn_stub;
3516 /* If there is a stub that 16 bit functions should use to call this
3517 32 bit function, this points to the section containing the stub. */
3518 asection *call_stub;
3520 /* This is like the call_stub field, but it is used if the function
3521 being called returns a floating point value. */
3522 asection *call_fp_stub;
3525 /* MIPS ELF linker hash table. */
3527 struct mips_elf_link_hash_table
3529 struct elf_link_hash_table root;
3531 /* We no longer use this. */
3532 /* String section indices for the dynamic section symbols. */
3533 bfd_size_type dynsym_sec_strindex[SIZEOF_MIPS_DYNSYM_SECNAMES];
3535 /* The number of .rtproc entries. */
3536 bfd_size_type procedure_count;
3537 /* The size of the .compact_rel section (if SGI_COMPAT). */
3538 bfd_size_type compact_rel_size;
3539 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3540 entry is set to the address of __rld_obj_head as in Irix 5. */
3541 boolean use_rld_obj_head;
3542 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3544 /* This is set if we see any mips16 stub sections. */
3545 boolean mips16_stubs_seen;
3548 /* Look up an entry in a MIPS ELF linker hash table. */
3550 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3551 ((struct mips_elf_link_hash_entry *) \
3552 elf_link_hash_lookup (&(table)->root, (string), (create), \
3555 /* Traverse a MIPS ELF linker hash table. */
3557 #define mips_elf_link_hash_traverse(table, func, info) \
3558 (elf_link_hash_traverse \
3560 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3563 /* Get the MIPS ELF linker hash table from a link_info structure. */
3565 #define mips_elf_hash_table(p) \
3566 ((struct mips_elf_link_hash_table *) ((p)->hash))
3568 static boolean mips_elf_output_extsym
3569 PARAMS ((struct mips_elf_link_hash_entry *, PTR));
3571 /* Create an entry in a MIPS ELF linker hash table. */
3573 static struct bfd_hash_entry *
3574 mips_elf_link_hash_newfunc (entry, table, string)
3575 struct bfd_hash_entry *entry;
3576 struct bfd_hash_table *table;
3579 struct mips_elf_link_hash_entry *ret =
3580 (struct mips_elf_link_hash_entry *) entry;
3582 /* Allocate the structure if it has not already been allocated by a
3584 if (ret == (struct mips_elf_link_hash_entry *) NULL)
3585 ret = ((struct mips_elf_link_hash_entry *)
3586 bfd_hash_allocate (table,
3587 sizeof (struct mips_elf_link_hash_entry)));
3588 if (ret == (struct mips_elf_link_hash_entry *) NULL)
3589 return (struct bfd_hash_entry *) ret;
3591 /* Call the allocation method of the superclass. */
3592 ret = ((struct mips_elf_link_hash_entry *)
3593 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
3595 if (ret != (struct mips_elf_link_hash_entry *) NULL)
3597 /* Set local fields. */
3598 memset (&ret->esym, 0, sizeof (EXTR));
3599 /* We use -2 as a marker to indicate that the information has
3600 not been set. -1 means there is no associated ifd. */
3602 ret->mips_32_relocs = 0;
3603 ret->fn_stub = NULL;
3604 ret->need_fn_stub = false;
3605 ret->call_stub = NULL;
3606 ret->call_fp_stub = NULL;
3609 return (struct bfd_hash_entry *) ret;
3612 /* Create a MIPS ELF linker hash table. */
3614 static struct bfd_link_hash_table *
3615 mips_elf_link_hash_table_create (abfd)
3618 struct mips_elf_link_hash_table *ret;
3620 ret = ((struct mips_elf_link_hash_table *)
3621 bfd_alloc (abfd, sizeof (struct mips_elf_link_hash_table)));
3622 if (ret == (struct mips_elf_link_hash_table *) NULL)
3625 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
3626 mips_elf_link_hash_newfunc))
3628 bfd_release (abfd, ret);
3633 /* We no longer use this. */
3634 for (i = 0; i < SIZEOF_MIPS_DYNSYM_SECNAMES; i++)
3635 ret->dynsym_sec_strindex[i] = (bfd_size_type) -1;
3637 ret->procedure_count = 0;
3638 ret->compact_rel_size = 0;
3639 ret->use_rld_obj_head = false;
3641 ret->mips16_stubs_seen = false;
3643 return &ret->root.root;
3646 /* Hook called by the linker routine which adds symbols from an object
3647 file. We must handle the special MIPS section numbers here. */
3651 mips_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
3653 struct bfd_link_info *info;
3654 const Elf_Internal_Sym *sym;
3660 if (SGI_COMPAT (abfd)
3661 && (abfd->flags & DYNAMIC) != 0
3662 && strcmp (*namep, "_rld_new_interface") == 0)
3664 /* Skip Irix 5 rld entry name. */
3669 switch (sym->st_shndx)
3672 /* Common symbols less than the GP size are automatically
3673 treated as SHN_MIPS_SCOMMON symbols. */
3674 if (sym->st_size > elf_gp_size (abfd))
3677 case SHN_MIPS_SCOMMON:
3678 *secp = bfd_make_section_old_way (abfd, ".scommon");
3679 (*secp)->flags |= SEC_IS_COMMON;
3680 *valp = sym->st_size;
3684 /* This section is used in a shared object. */
3685 if (mips_elf_text_section_ptr == NULL)
3687 /* Initialize the section. */
3688 mips_elf_text_section.name = ".text";
3689 mips_elf_text_section.flags = SEC_NO_FLAGS;
3690 mips_elf_text_section.output_section = NULL;
3691 mips_elf_text_section.symbol = &mips_elf_text_symbol;
3692 mips_elf_text_section.symbol_ptr_ptr = &mips_elf_text_symbol_ptr;
3693 mips_elf_text_symbol.name = ".text";
3694 mips_elf_text_symbol.flags = BSF_SECTION_SYM;
3695 mips_elf_text_symbol.section = &mips_elf_text_section;
3696 mips_elf_text_symbol_ptr = &mips_elf_text_symbol;
3697 mips_elf_text_section_ptr = &mips_elf_text_section;
3699 /* This code used to do *secp = bfd_und_section_ptr if
3700 info->shared. I don't know why, and that doesn't make sense,
3701 so I took it out. */
3702 *secp = mips_elf_text_section_ptr;
3705 case SHN_MIPS_ACOMMON:
3706 /* Fall through. XXX Can we treat this as allocated data? */
3708 /* This section is used in a shared object. */
3709 if (mips_elf_data_section_ptr == NULL)
3711 /* Initialize the section. */
3712 mips_elf_data_section.name = ".data";
3713 mips_elf_data_section.flags = SEC_NO_FLAGS;
3714 mips_elf_data_section.output_section = NULL;
3715 mips_elf_data_section.symbol = &mips_elf_data_symbol;
3716 mips_elf_data_section.symbol_ptr_ptr = &mips_elf_data_symbol_ptr;
3717 mips_elf_data_symbol.name = ".data";
3718 mips_elf_data_symbol.flags = BSF_SECTION_SYM;
3719 mips_elf_data_symbol.section = &mips_elf_data_section;
3720 mips_elf_data_symbol_ptr = &mips_elf_data_symbol;
3721 mips_elf_data_section_ptr = &mips_elf_data_section;
3723 /* This code used to do *secp = bfd_und_section_ptr if
3724 info->shared. I don't know why, and that doesn't make sense,
3725 so I took it out. */
3726 *secp = mips_elf_data_section_ptr;
3729 case SHN_MIPS_SUNDEFINED:
3730 *secp = bfd_und_section_ptr;
3734 if (SGI_COMPAT (abfd)
3736 && info->hash->creator == abfd->xvec
3737 && strcmp (*namep, "__rld_obj_head") == 0)
3739 struct elf_link_hash_entry *h;
3741 /* Mark __rld_obj_head as dynamic. */
3743 if (! (_bfd_generic_link_add_one_symbol
3744 (info, abfd, *namep, BSF_GLOBAL, *secp,
3745 (bfd_vma) *valp, (const char *) NULL, false,
3746 get_elf_backend_data (abfd)->collect,
3747 (struct bfd_link_hash_entry **) &h)))
3749 h->elf_link_hash_flags &=~ ELF_LINK_NON_ELF;
3750 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3751 h->type = STT_OBJECT;
3753 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
3756 mips_elf_hash_table (info)->use_rld_obj_head = true;
3759 /* If this is a mips16 text symbol, add 1 to the value to make it
3760 odd. This will cause something like .word SYM to come up with
3761 the right value when it is loaded into the PC. */
3762 if (sym->st_other == STO_MIPS16)
3768 /* Structure used to pass information to mips_elf_output_extsym. */
3773 struct bfd_link_info *info;
3774 struct ecoff_debug_info *debug;
3775 const struct ecoff_debug_swap *swap;
3779 /* This routine is used to write out ECOFF debugging external symbol
3780 information. It is called via mips_elf_link_hash_traverse. The
3781 ECOFF external symbol information must match the ELF external
3782 symbol information. Unfortunately, at this point we don't know
3783 whether a symbol is required by reloc information, so the two
3784 tables may wind up being different. We must sort out the external
3785 symbol information before we can set the final size of the .mdebug
3786 section, and we must set the size of the .mdebug section before we
3787 can relocate any sections, and we can't know which symbols are
3788 required by relocation until we relocate the sections.
3789 Fortunately, it is relatively unlikely that any symbol will be
3790 stripped but required by a reloc. In particular, it can not happen
3791 when generating a final executable. */
3794 mips_elf_output_extsym (h, data)
3795 struct mips_elf_link_hash_entry *h;
3798 struct extsym_info *einfo = (struct extsym_info *) data;
3800 asection *sec, *output_section;
3802 if (h->root.indx == -2)
3804 else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3805 || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)
3806 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
3807 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
3809 else if (einfo->info->strip == strip_all
3810 || (einfo->info->strip == strip_some
3811 && bfd_hash_lookup (einfo->info->keep_hash,
3812 h->root.root.root.string,
3813 false, false) == NULL))
3821 if (h->esym.ifd == -2)
3824 h->esym.cobol_main = 0;
3825 h->esym.weakext = 0;
3826 h->esym.reserved = 0;
3827 h->esym.ifd = ifdNil;
3828 h->esym.asym.value = 0;
3829 h->esym.asym.st = stGlobal;
3831 if (SGI_COMPAT (einfo->abfd)
3832 && (h->root.root.type == bfd_link_hash_undefined
3833 || h->root.root.type == bfd_link_hash_undefweak))
3837 /* Use undefined class. Also, set class and type for some
3839 name = h->root.root.root.string;
3840 if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0
3841 || strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0)
3843 h->esym.asym.sc = scData;
3844 h->esym.asym.st = stLabel;
3845 h->esym.asym.value = 0;
3847 else if (strcmp (name, mips_elf_dynsym_rtproc_names[2]) == 0)
3849 h->esym.asym.sc = scAbs;
3850 h->esym.asym.st = stLabel;
3851 h->esym.asym.value =
3852 mips_elf_hash_table (einfo->info)->procedure_count;
3854 else if (strcmp (name, "_gp_disp") == 0)
3856 h->esym.asym.sc = scAbs;
3857 h->esym.asym.st = stLabel;
3858 h->esym.asym.value = elf_gp (einfo->abfd);
3861 h->esym.asym.sc = scUndefined;
3863 else if (h->root.root.type != bfd_link_hash_defined
3864 && h->root.root.type != bfd_link_hash_defweak)
3865 h->esym.asym.sc = scAbs;
3870 sec = h->root.root.u.def.section;
3871 output_section = sec->output_section;
3873 /* When making a shared library and symbol h is the one from
3874 the another shared library, OUTPUT_SECTION may be null. */
3875 if (output_section == NULL)
3876 h->esym.asym.sc = scUndefined;
3879 name = bfd_section_name (output_section->owner, output_section);
3881 if (strcmp (name, ".text") == 0)
3882 h->esym.asym.sc = scText;
3883 else if (strcmp (name, ".data") == 0)
3884 h->esym.asym.sc = scData;
3885 else if (strcmp (name, ".sdata") == 0)
3886 h->esym.asym.sc = scSData;
3887 else if (strcmp (name, ".rodata") == 0
3888 || strcmp (name, ".rdata") == 0)
3889 h->esym.asym.sc = scRData;
3890 else if (strcmp (name, ".bss") == 0)
3891 h->esym.asym.sc = scBss;
3892 else if (strcmp (name, ".sbss") == 0)
3893 h->esym.asym.sc = scSBss;
3894 else if (strcmp (name, ".init") == 0)
3895 h->esym.asym.sc = scInit;
3896 else if (strcmp (name, ".fini") == 0)
3897 h->esym.asym.sc = scFini;
3899 h->esym.asym.sc = scAbs;
3903 h->esym.asym.reserved = 0;
3904 h->esym.asym.index = indexNil;
3907 if (h->root.root.type == bfd_link_hash_common)
3908 h->esym.asym.value = h->root.root.u.c.size;
3909 else if (h->root.root.type == bfd_link_hash_defined
3910 || h->root.root.type == bfd_link_hash_defweak)
3912 if (h->esym.asym.sc == scCommon)
3913 h->esym.asym.sc = scBss;
3914 else if (h->esym.asym.sc == scSCommon)
3915 h->esym.asym.sc = scSBss;
3917 sec = h->root.root.u.def.section;
3918 output_section = sec->output_section;
3919 if (output_section != NULL)
3920 h->esym.asym.value = (h->root.root.u.def.value
3921 + sec->output_offset
3922 + output_section->vma);
3924 h->esym.asym.value = 0;
3926 else if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
3928 /* Set type and value for a symbol with a function stub. */
3929 h->esym.asym.st = stProc;
3930 sec = h->root.root.u.def.section;
3932 h->esym.asym.value = 0;
3935 output_section = sec->output_section;
3936 if (output_section != NULL)
3937 h->esym.asym.value = (h->root.plt.offset
3938 + sec->output_offset
3939 + output_section->vma);
3941 h->esym.asym.value = 0;
3948 if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap,
3949 h->root.root.root.string,
3952 einfo->failed = true;
3959 /* Create a runtime procedure table from the .mdebug section. */
3962 mips_elf_create_procedure_table (handle, abfd, info, s, debug)
3965 struct bfd_link_info *info;
3967 struct ecoff_debug_info *debug;
3969 const struct ecoff_debug_swap *swap;
3970 HDRR *hdr = &debug->symbolic_header;
3972 struct rpdr_ext *erp;
3974 struct pdr_ext *epdr;
3975 struct sym_ext *esym;
3978 unsigned long size, count;
3979 unsigned long sindex;
3983 const char *no_name_func = _("static procedure (no name)");
3991 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
3993 sindex = strlen (no_name_func) + 1;
3994 count = hdr->ipdMax;
3997 size = swap->external_pdr_size;
3999 epdr = (struct pdr_ext *) bfd_malloc (size * count);
4003 if (! _bfd_ecoff_get_accumulated_pdr (handle, (PTR) epdr))
4006 size = sizeof (RPDR);
4007 rp = rpdr = (RPDR *) bfd_malloc (size * count);
4011 sv = (char **) bfd_malloc (sizeof (char *) * count);
4015 count = hdr->isymMax;
4016 size = swap->external_sym_size;
4017 esym = (struct sym_ext *) bfd_malloc (size * count);
4021 if (! _bfd_ecoff_get_accumulated_sym (handle, (PTR) esym))
4024 count = hdr->issMax;
4025 ss = (char *) bfd_malloc (count);
4028 if (! _bfd_ecoff_get_accumulated_ss (handle, (PTR) ss))
4031 count = hdr->ipdMax;
4032 for (i = 0; i < count; i++, rp++)
4034 (*swap->swap_pdr_in) (abfd, (PTR) (epdr + i), &pdr);
4035 (*swap->swap_sym_in) (abfd, (PTR) &esym[pdr.isym], &sym);
4036 rp->adr = sym.value;
4037 rp->regmask = pdr.regmask;
4038 rp->regoffset = pdr.regoffset;
4039 rp->fregmask = pdr.fregmask;
4040 rp->fregoffset = pdr.fregoffset;
4041 rp->frameoffset = pdr.frameoffset;
4042 rp->framereg = pdr.framereg;
4043 rp->pcreg = pdr.pcreg;
4045 sv[i] = ss + sym.iss;
4046 sindex += strlen (sv[i]) + 1;
4050 size = sizeof (struct rpdr_ext) * (count + 2) + sindex;
4051 size = BFD_ALIGN (size, 16);
4052 rtproc = (PTR) bfd_alloc (abfd, size);
4055 mips_elf_hash_table (info)->procedure_count = 0;
4059 mips_elf_hash_table (info)->procedure_count = count + 2;
4061 erp = (struct rpdr_ext *) rtproc;
4062 memset (erp, 0, sizeof (struct rpdr_ext));
4064 str = (char *) rtproc + sizeof (struct rpdr_ext) * (count + 2);
4065 strcpy (str, no_name_func);
4066 str += strlen (no_name_func) + 1;
4067 for (i = 0; i < count; i++)
4069 ecoff_swap_rpdr_out (abfd, rpdr + i, erp + i);
4070 strcpy (str, sv[i]);
4071 str += strlen (sv[i]) + 1;
4073 ecoff_put_off (abfd, (bfd_vma) -1, (bfd_byte *) (erp + count)->p_adr);
4075 /* Set the size and contents of .rtproc section. */
4076 s->_raw_size = size;
4077 s->contents = (bfd_byte *) rtproc;
4079 /* Skip this section later on (I don't think this currently
4080 matters, but someday it might). */
4081 s->link_order_head = (struct bfd_link_order *) NULL;
4110 /* A comparison routine used to sort .gptab entries. */
4113 gptab_compare (p1, p2)
4117 const Elf32_gptab *a1 = (const Elf32_gptab *) p1;
4118 const Elf32_gptab *a2 = (const Elf32_gptab *) p2;
4120 return a1->gt_entry.gt_g_value - a2->gt_entry.gt_g_value;
4123 /* We need to use a special link routine to handle the .reginfo and
4124 the .mdebug sections. We need to merge all instances of these
4125 sections together, not write them all out sequentially. */
4128 mips_elf_final_link (abfd, info)
4130 struct bfd_link_info *info;
4134 struct bfd_link_order *p;
4135 asection *reginfo_sec, *mdebug_sec, *gptab_data_sec, *gptab_bss_sec;
4136 asection *rtproc_sec;
4137 Elf32_RegInfo reginfo;
4138 struct ecoff_debug_info debug;
4139 const struct ecoff_debug_swap *swap
4140 = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
4141 HDRR *symhdr = &debug.symbolic_header;
4142 PTR mdebug_handle = NULL;
4144 /* Drop the .options section, since it has special semantics which I
4145 haven't bothered to figure out. */
4146 for (secpp = &abfd->sections; *secpp != NULL; secpp = &(*secpp)->next)
4148 if (strcmp ((*secpp)->name, ".options") == 0)
4150 for (p = (*secpp)->link_order_head; p != NULL; p = p->next)
4151 if (p->type == bfd_indirect_link_order)
4152 p->u.indirect.section->flags &=~ SEC_HAS_CONTENTS;
4153 (*secpp)->link_order_head = NULL;
4154 *secpp = (*secpp)->next;
4155 --abfd->section_count;
4160 /* Get a value for the GP register. */
4161 if (elf_gp (abfd) == 0)
4163 struct bfd_link_hash_entry *h;
4165 h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true);
4166 if (h != (struct bfd_link_hash_entry *) NULL
4167 && h->type == bfd_link_hash_defined)
4168 elf_gp (abfd) = (h->u.def.value
4169 + h->u.def.section->output_section->vma
4170 + h->u.def.section->output_offset);
4171 else if (info->relocateable)
4175 /* Make up a value. */
4177 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
4180 && (strcmp (o->name, ".sbss") == 0
4181 || strcmp (o->name, ".sdata") == 0
4182 || strcmp (o->name, ".lit4") == 0
4183 || strcmp (o->name, ".lit8") == 0))
4186 elf_gp (abfd) = lo + ELF_MIPS_GP_OFFSET (abfd);
4190 /* If the relocate_section function needs to do a reloc
4191 involving the GP value, it should make a reloc_dangerous
4192 callback to warn that GP is not defined. */
4196 /* Go through the sections and collect the .reginfo and .mdebug
4200 gptab_data_sec = NULL;
4201 gptab_bss_sec = NULL;
4202 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
4204 if (strcmp (o->name, ".reginfo") == 0)
4206 memset (®info, 0, sizeof reginfo);
4208 /* We have found the .reginfo section in the output file.
4209 Look through all the link_orders comprising it and merge
4210 the information together. */
4211 for (p = o->link_order_head;
4212 p != (struct bfd_link_order *) NULL;
4215 asection *input_section;
4217 Elf32_External_RegInfo ext;
4220 if (p->type != bfd_indirect_link_order)
4222 if (p->type == bfd_fill_link_order)
4227 input_section = p->u.indirect.section;
4228 input_bfd = input_section->owner;
4230 /* The linker emulation code has probably clobbered the
4231 size to be zero bytes. */
4232 if (input_section->_raw_size == 0)
4233 input_section->_raw_size = sizeof (Elf32_External_RegInfo);
4235 if (! bfd_get_section_contents (input_bfd, input_section,
4241 bfd_mips_elf32_swap_reginfo_in (input_bfd, &ext, &sub);
4243 reginfo.ri_gprmask |= sub.ri_gprmask;
4244 reginfo.ri_cprmask[0] |= sub.ri_cprmask[0];
4245 reginfo.ri_cprmask[1] |= sub.ri_cprmask[1];
4246 reginfo.ri_cprmask[2] |= sub.ri_cprmask[2];
4247 reginfo.ri_cprmask[3] |= sub.ri_cprmask[3];
4249 /* ri_gp_value is set by the function
4250 mips_elf32_section_processing when the section is
4251 finally written out. */
4253 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4254 elf_link_input_bfd ignores this section. */
4255 input_section->flags &=~ SEC_HAS_CONTENTS;
4258 /* Force the section size to the value we want. */
4259 o->_raw_size = sizeof (Elf32_External_RegInfo);
4261 /* Skip this section later on (I don't think this currently
4262 matters, but someday it might). */
4263 o->link_order_head = (struct bfd_link_order *) NULL;
4268 if (strcmp (o->name, ".mdebug") == 0)
4270 struct extsym_info einfo;
4272 /* We have found the .mdebug section in the output file.
4273 Look through all the link_orders comprising it and merge
4274 the information together. */
4275 symhdr->magic = swap->sym_magic;
4276 /* FIXME: What should the version stamp be? */
4278 symhdr->ilineMax = 0;
4282 symhdr->isymMax = 0;
4283 symhdr->ioptMax = 0;
4284 symhdr->iauxMax = 0;
4286 symhdr->issExtMax = 0;
4289 symhdr->iextMax = 0;
4291 /* We accumulate the debugging information itself in the
4292 debug_info structure. */
4294 debug.external_dnr = NULL;
4295 debug.external_pdr = NULL;
4296 debug.external_sym = NULL;
4297 debug.external_opt = NULL;
4298 debug.external_aux = NULL;
4300 debug.ssext = debug.ssext_end = NULL;
4301 debug.external_fdr = NULL;
4302 debug.external_rfd = NULL;
4303 debug.external_ext = debug.external_ext_end = NULL;
4305 mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info);
4306 if (mdebug_handle == (PTR) NULL)
4309 if (SGI_COMPAT (abfd))
4315 static const char * const name[] =
4316 { ".text", ".init", ".fini", ".data",
4317 ".rodata", ".sdata", ".sbss", ".bss" };
4318 static const int sc[] = { scText, scInit, scFini, scData,
4319 scRData, scSData, scSBss, scBss };
4322 esym.cobol_main = 0;
4326 esym.asym.iss = issNil;
4327 esym.asym.st = stLocal;
4328 esym.asym.reserved = 0;
4329 esym.asym.index = indexNil;
4331 for (i = 0; i < 8; i++)
4333 esym.asym.sc = sc[i];
4334 s = bfd_get_section_by_name (abfd, name[i]);
4337 esym.asym.value = s->vma;
4338 last = s->vma + s->_raw_size;
4341 esym.asym.value = last;
4343 if (! bfd_ecoff_debug_one_external (abfd, &debug, swap,
4349 for (p = o->link_order_head;
4350 p != (struct bfd_link_order *) NULL;
4353 asection *input_section;
4355 const struct ecoff_debug_swap *input_swap;
4356 struct ecoff_debug_info input_debug;
4360 if (p->type != bfd_indirect_link_order)
4362 if (p->type == bfd_fill_link_order)
4367 input_section = p->u.indirect.section;
4368 input_bfd = input_section->owner;
4370 if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour
4371 || (get_elf_backend_data (input_bfd)
4372 ->elf_backend_ecoff_debug_swap) == NULL)
4374 /* I don't know what a non MIPS ELF bfd would be
4375 doing with a .mdebug section, but I don't really
4376 want to deal with it. */
4380 input_swap = (get_elf_backend_data (input_bfd)
4381 ->elf_backend_ecoff_debug_swap);
4383 BFD_ASSERT (p->size == input_section->_raw_size);
4385 /* The ECOFF linking code expects that we have already
4386 read in the debugging information and set up an
4387 ecoff_debug_info structure, so we do that now. */
4388 if (! _bfd_mips_elf_read_ecoff_info (input_bfd, input_section,
4392 if (! (bfd_ecoff_debug_accumulate
4393 (mdebug_handle, abfd, &debug, swap, input_bfd,
4394 &input_debug, input_swap, info)))
4397 /* Loop through the external symbols. For each one with
4398 interesting information, try to find the symbol in
4399 the linker global hash table and save the information
4400 for the output external symbols. */
4401 eraw_src = input_debug.external_ext;
4402 eraw_end = (eraw_src
4403 + (input_debug.symbolic_header.iextMax
4404 * input_swap->external_ext_size));
4406 eraw_src < eraw_end;
4407 eraw_src += input_swap->external_ext_size)
4411 struct mips_elf_link_hash_entry *h;
4413 (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext);
4414 if (ext.asym.sc == scNil
4415 || ext.asym.sc == scUndefined
4416 || ext.asym.sc == scSUndefined)
4419 name = input_debug.ssext + ext.asym.iss;
4420 h = mips_elf_link_hash_lookup (mips_elf_hash_table (info),
4421 name, false, false, true);
4422 if (h == NULL || h->esym.ifd != -2)
4428 < input_debug.symbolic_header.ifdMax);
4429 ext.ifd = input_debug.ifdmap[ext.ifd];
4435 /* Free up the information we just read. */
4436 free (input_debug.line);
4437 free (input_debug.external_dnr);
4438 free (input_debug.external_pdr);
4439 free (input_debug.external_sym);
4440 free (input_debug.external_opt);
4441 free (input_debug.external_aux);
4442 free (input_debug.ss);
4443 free (input_debug.ssext);
4444 free (input_debug.external_fdr);
4445 free (input_debug.external_rfd);
4446 free (input_debug.external_ext);
4448 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4449 elf_link_input_bfd ignores this section. */
4450 input_section->flags &=~ SEC_HAS_CONTENTS;
4453 if (SGI_COMPAT (abfd) && info->shared)
4455 /* Create .rtproc section. */
4456 rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc");
4457 if (rtproc_sec == NULL)
4459 flagword flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY
4460 | SEC_LINKER_CREATED | SEC_READONLY);
4462 rtproc_sec = bfd_make_section (abfd, ".rtproc");
4463 if (rtproc_sec == NULL
4464 || ! bfd_set_section_flags (abfd, rtproc_sec, flags)
4465 || ! bfd_set_section_alignment (abfd, rtproc_sec, 4))
4469 if (! mips_elf_create_procedure_table (mdebug_handle, abfd,
4470 info, rtproc_sec, &debug))
4474 /* Build the external symbol information. */
4477 einfo.debug = &debug;
4479 einfo.failed = false;
4480 mips_elf_link_hash_traverse (mips_elf_hash_table (info),
4481 mips_elf_output_extsym,
4486 /* Set the size of the .mdebug section. */
4487 o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap);
4489 /* Skip this section later on (I don't think this currently
4490 matters, but someday it might). */
4491 o->link_order_head = (struct bfd_link_order *) NULL;
4496 if (strncmp (o->name, ".gptab.", sizeof ".gptab." - 1) == 0)
4498 const char *subname;
4501 Elf32_External_gptab *ext_tab;
4504 /* The .gptab.sdata and .gptab.sbss sections hold
4505 information describing how the small data area would
4506 change depending upon the -G switch. These sections
4507 not used in executables files. */
4508 if (! info->relocateable)
4512 for (p = o->link_order_head;
4513 p != (struct bfd_link_order *) NULL;
4516 asection *input_section;
4518 if (p->type != bfd_indirect_link_order)
4520 if (p->type == bfd_fill_link_order)
4525 input_section = p->u.indirect.section;
4527 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4528 elf_link_input_bfd ignores this section. */
4529 input_section->flags &=~ SEC_HAS_CONTENTS;
4532 /* Skip this section later on (I don't think this
4533 currently matters, but someday it might). */
4534 o->link_order_head = (struct bfd_link_order *) NULL;
4536 /* Really remove the section. */
4537 for (secpp = &abfd->sections;
4539 secpp = &(*secpp)->next)
4541 *secpp = (*secpp)->next;
4542 --abfd->section_count;
4547 /* There is one gptab for initialized data, and one for
4548 uninitialized data. */
4549 if (strcmp (o->name, ".gptab.sdata") == 0)
4551 else if (strcmp (o->name, ".gptab.sbss") == 0)
4555 (*_bfd_error_handler)
4556 (_("%s: illegal section name `%s'"),
4557 bfd_get_filename (abfd), o->name);
4558 bfd_set_error (bfd_error_nonrepresentable_section);
4562 /* The linker script always combines .gptab.data and
4563 .gptab.sdata into .gptab.sdata, and likewise for
4564 .gptab.bss and .gptab.sbss. It is possible that there is
4565 no .sdata or .sbss section in the output file, in which
4566 case we must change the name of the output section. */
4567 subname = o->name + sizeof ".gptab" - 1;
4568 if (bfd_get_section_by_name (abfd, subname) == NULL)
4570 if (o == gptab_data_sec)
4571 o->name = ".gptab.data";
4573 o->name = ".gptab.bss";
4574 subname = o->name + sizeof ".gptab" - 1;
4575 BFD_ASSERT (bfd_get_section_by_name (abfd, subname) != NULL);
4578 /* Set up the first entry. */
4580 tab = (Elf32_gptab *) bfd_malloc (c * sizeof (Elf32_gptab));
4583 tab[0].gt_header.gt_current_g_value = elf_gp_size (abfd);
4584 tab[0].gt_header.gt_unused = 0;
4586 /* Combine the input sections. */
4587 for (p = o->link_order_head;
4588 p != (struct bfd_link_order *) NULL;
4591 asection *input_section;
4595 bfd_size_type gpentry;
4597 if (p->type != bfd_indirect_link_order)
4599 if (p->type == bfd_fill_link_order)
4604 input_section = p->u.indirect.section;
4605 input_bfd = input_section->owner;
4607 /* Combine the gptab entries for this input section one
4608 by one. We know that the input gptab entries are
4609 sorted by ascending -G value. */
4610 size = bfd_section_size (input_bfd, input_section);
4612 for (gpentry = sizeof (Elf32_External_gptab);
4614 gpentry += sizeof (Elf32_External_gptab))
4616 Elf32_External_gptab ext_gptab;
4617 Elf32_gptab int_gptab;
4623 if (! (bfd_get_section_contents
4624 (input_bfd, input_section, (PTR) &ext_gptab,
4625 gpentry, sizeof (Elf32_External_gptab))))
4631 bfd_mips_elf32_swap_gptab_in (input_bfd, &ext_gptab,
4633 val = int_gptab.gt_entry.gt_g_value;
4634 add = int_gptab.gt_entry.gt_bytes - last;
4637 for (look = 1; look < c; look++)
4639 if (tab[look].gt_entry.gt_g_value >= val)
4640 tab[look].gt_entry.gt_bytes += add;
4642 if (tab[look].gt_entry.gt_g_value == val)
4648 Elf32_gptab *new_tab;
4651 /* We need a new table entry. */
4652 new_tab = ((Elf32_gptab *)
4653 bfd_realloc ((PTR) tab,
4654 (c + 1) * sizeof (Elf32_gptab)));
4655 if (new_tab == NULL)
4661 tab[c].gt_entry.gt_g_value = val;
4662 tab[c].gt_entry.gt_bytes = add;
4664 /* Merge in the size for the next smallest -G
4665 value, since that will be implied by this new
4668 for (look = 1; look < c; look++)
4670 if (tab[look].gt_entry.gt_g_value < val
4672 || (tab[look].gt_entry.gt_g_value
4673 > tab[max].gt_entry.gt_g_value)))
4677 tab[c].gt_entry.gt_bytes +=
4678 tab[max].gt_entry.gt_bytes;
4683 last = int_gptab.gt_entry.gt_bytes;
4686 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4687 elf_link_input_bfd ignores this section. */
4688 input_section->flags &=~ SEC_HAS_CONTENTS;
4691 /* The table must be sorted by -G value. */
4693 qsort (tab + 1, c - 1, sizeof (tab[0]), gptab_compare);
4695 /* Swap out the table. */
4696 ext_tab = ((Elf32_External_gptab *)
4697 bfd_alloc (abfd, c * sizeof (Elf32_External_gptab)));
4698 if (ext_tab == NULL)
4704 for (i = 0; i < c; i++)
4705 bfd_mips_elf32_swap_gptab_out (abfd, tab + i, ext_tab + i);
4708 o->_raw_size = c * sizeof (Elf32_External_gptab);
4709 o->contents = (bfd_byte *) ext_tab;
4711 /* Skip this section later on (I don't think this currently
4712 matters, but someday it might). */
4713 o->link_order_head = (struct bfd_link_order *) NULL;
4717 /* Invoke the regular ELF backend linker to do all the work. */
4718 if (! bfd_elf32_bfd_final_link (abfd, info))
4721 /* Now write out the computed sections. */
4723 if (reginfo_sec != (asection *) NULL)
4725 Elf32_External_RegInfo ext;
4727 bfd_mips_elf32_swap_reginfo_out (abfd, ®info, &ext);
4728 if (! bfd_set_section_contents (abfd, reginfo_sec, (PTR) &ext,
4729 (file_ptr) 0, sizeof ext))
4733 if (mdebug_sec != (asection *) NULL)
4735 BFD_ASSERT (abfd->output_has_begun);
4736 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug,
4738 mdebug_sec->filepos))
4741 bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info);
4744 if (gptab_data_sec != (asection *) NULL)
4746 if (! bfd_set_section_contents (abfd, gptab_data_sec,
4747 gptab_data_sec->contents,
4749 gptab_data_sec->_raw_size))
4753 if (gptab_bss_sec != (asection *) NULL)
4755 if (! bfd_set_section_contents (abfd, gptab_bss_sec,
4756 gptab_bss_sec->contents,
4758 gptab_bss_sec->_raw_size))
4762 if (SGI_COMPAT (abfd))
4764 rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc");
4765 if (rtproc_sec != NULL)
4767 if (! bfd_set_section_contents (abfd, rtproc_sec,
4768 rtproc_sec->contents,
4770 rtproc_sec->_raw_size))
4778 /* Handle a MIPS ELF HI16 reloc. */
4781 mips_elf_relocate_hi16 (input_bfd, relhi, rello, contents, addend)
4783 Elf_Internal_Rela *relhi;
4784 Elf_Internal_Rela *rello;
4791 insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
4793 addlo = bfd_get_32 (input_bfd, contents + rello->r_offset);
4796 addend += ((insn & 0xffff) << 16) + addlo;
4798 if ((addlo & 0x8000) != 0)
4800 if ((addend & 0x8000) != 0)
4803 bfd_put_32 (input_bfd,
4804 (insn & 0xffff0000) | ((addend >> 16) & 0xffff),
4805 contents + relhi->r_offset);
4808 /* Handle a MIPS ELF local GOT16 reloc. */
4811 mips_elf_relocate_got_local (output_bfd, input_bfd, sgot, relhi, rello,
4816 Elf_Internal_Rela *relhi;
4817 Elf_Internal_Rela *rello;
4821 unsigned int assigned_gotno;
4827 bfd_byte *got_contents;
4828 struct mips_got_info *g;
4830 insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
4832 addlo = bfd_get_32 (input_bfd, contents + rello->r_offset);
4835 addend += ((insn & 0xffff) << 16) + addlo;
4837 if ((addlo & 0x8000) != 0)
4839 if ((addend & 0x8000) != 0)
4842 /* Get a got entry representing requested hipage. */
4843 BFD_ASSERT (elf_section_data (sgot) != NULL);
4844 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
4845 BFD_ASSERT (g != NULL);
4847 assigned_gotno = g->assigned_gotno;
4848 got_contents = sgot->contents;
4849 hipage = addend & 0xffff0000;
4851 for (i = MIPS_RESERVED_GOTNO; i < assigned_gotno; i++)
4853 address = bfd_get_32 (input_bfd, got_contents + i * 4);
4854 if (hipage == (address & 0xffff0000))
4858 if (i == assigned_gotno)
4860 if (assigned_gotno >= g->local_gotno)
4862 (*_bfd_error_handler)
4863 (_("more got entries are needed for hipage relocations"));
4864 bfd_set_error (bfd_error_bad_value);
4868 bfd_put_32 (input_bfd, hipage, got_contents + assigned_gotno * 4);
4869 ++g->assigned_gotno;
4872 i = - ELF_MIPS_GP_OFFSET (output_bfd) + i * 4;
4873 bfd_put_32 (input_bfd, (insn & 0xffff0000) | (i & 0xffff),
4874 contents + relhi->r_offset);
4879 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
4882 mips_elf_relocate_global_got (input_bfd, rel, contents, offset)
4884 Elf_Internal_Rela *rel;
4890 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
4891 bfd_put_32 (input_bfd,
4892 (insn & 0xffff0000) | (offset & 0xffff),
4893 contents + rel->r_offset);
4896 /* Relocate a MIPS ELF section. */
4899 mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
4900 contents, relocs, local_syms, local_sections)
4902 struct bfd_link_info *info;
4904 asection *input_section;
4906 Elf_Internal_Rela *relocs;
4907 Elf_Internal_Sym *local_syms;
4908 asection **local_sections;
4910 Elf_Internal_Shdr *symtab_hdr;
4913 asection *sgot, *sreloc, *scpt;
4916 Elf_Internal_Rela *rel;
4917 Elf_Internal_Rela *relend;
4918 struct mips_got_info *g;
4920 dynobj = elf_hash_table (info)->dynobj;
4921 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4925 if (dynobj == NULL || ! SGI_COMPAT (output_bfd))
4928 scpt = bfd_get_section_by_name (dynobj, ".compact_rel");
4931 if (elf_bad_symtab (input_bfd))
4933 locsymcount = symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
4938 locsymcount = symtab_hdr->sh_info;
4939 extsymoff = symtab_hdr->sh_info;
4942 gp = _bfd_get_gp_value (output_bfd);
4945 relend = relocs + input_section->reloc_count;
4946 for (; rel < relend; rel++)
4949 reloc_howto_type *howto;
4950 unsigned long r_symndx;
4952 struct elf_link_hash_entry *h;
4954 Elf_Internal_Sym *sym;
4955 struct mips_elf_link_hash_entry *mh;
4957 bfd_reloc_status_type r;
4959 r_type = ELF32_R_TYPE (rel->r_info);
4960 if (r_type == R_MIPS_GNU_VTINHERIT
4961 || r_type == R_MIPS_GNU_VTENTRY)
4963 if ((r_type < 0 || r_type >= (int) R_MIPS_max)
4964 /* start-sanitize-r5900 */
4965 && r_type != R_MIPS15_S3
4966 /* end-sanitize-r5900 */
4967 /* start-sanitize-sky */
4968 && r_type != R_MIPS_DVP_11_PCREL
4969 && r_type != R_MIPS_DVP_27_S4
4970 && r_type != R_MIPS_DVP_11_S4
4971 && r_type != R_MIPS_DVP_U15_S3
4972 /* end-sanitize-sky */
4973 && r_type != R_MIPS16_26
4974 && r_type != R_MIPS16_GPREL)
4976 bfd_set_error (bfd_error_bad_value);
4979 if (r_type == R_MIPS16_26)
4980 howto = &elf_mips16_jump_howto;
4981 else if (r_type == R_MIPS16_GPREL)
4982 howto = &elf_mips16_gprel_howto;
4983 /* start-sanitize-r5900 */
4984 else if (r_type == R_MIPS15_S3)
4985 howto = &elf_mips15_s3_howto;
4986 /* end-sanitize-r5900 */
4987 /* start-sanitize-sky */
4988 else if (r_type == R_MIPS_DVP_11_PCREL)
4989 howto = &elf_mips_dvp_11_pcrel_howto;
4990 else if (r_type == R_MIPS_DVP_27_S4)
4991 howto = &elf_mips_dvp_27_s4_howto;
4992 else if (r_type == R_MIPS_DVP_11_S4)
4993 howto = &elf_mips_dvp_11_s4_howto;
4994 else if (r_type == R_MIPS_DVP_U15_S3)
4995 howto = &elf_mips_dvp_u15_s3_howto;
4996 /* end-sanitize-sky */
4998 howto = elf_mips_howto_table + r_type;
5001 && (r_type == R_MIPS_CALL16
5002 || r_type == R_MIPS_GOT16
5003 || r_type == R_MIPS_CALL_HI16
5004 || r_type == R_MIPS_CALL_LO16
5005 || r_type == R_MIPS_GOT_HI16
5006 || r_type == R_MIPS_GOT_LO16))
5008 /* We need the .got section. */
5011 sgot = bfd_get_section_by_name (dynobj, ".got");
5012 BFD_ASSERT (sgot != NULL);
5013 BFD_ASSERT (elf_section_data (sgot) != NULL);
5014 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
5015 BFD_ASSERT (g != NULL);
5019 r_symndx = ELF32_R_SYM (rel->r_info);
5021 /* Mix in the change in GP address for a GP relative reloc. */
5022 if (r_type != R_MIPS_GPREL16
5023 && r_type != R_MIPS_LITERAL
5024 && r_type != R_MIPS_GPREL32
5025 && r_type != R_MIPS16_GPREL)
5031 if (! ((*info->callbacks->reloc_dangerous)
5033 _("GP relative relocation when GP not defined"),
5034 input_bfd, input_section,
5037 /* Only give the error once per link. */
5039 _bfd_set_gp_value (output_bfd, gp);
5042 if (r_symndx < extsymoff
5043 || (elf_bad_symtab (input_bfd)
5044 && local_sections[r_symndx] != NULL))
5046 /* This is a relocation against a section. The current
5047 addend in the instruction is the difference between
5048 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
5049 must change this to be the difference between the
5050 final definition (which will end up in RELOCATION)
5051 and the GP value of OUTPUT_BFD (which is in GP). */
5052 addend = elf_gp (input_bfd) - gp;
5054 else if (! info->relocateable)
5056 /* We are doing a final link. The current addend in the
5057 instruction is simply the desired offset into the
5058 symbol (normally zero). We want the instruction to
5059 hold the difference between the final definition of
5060 the symbol (which will end up in RELOCATION) and the
5061 GP value of OUTPUT_BFD (which is in GP). */
5066 /* We are generating relocateable output, and we aren't
5067 going to define this symbol, so we just leave the
5068 instruction alone. */
5076 if (info->relocateable)
5078 /* This is a relocateable link. We don't have to change
5079 anything, unless the reloc is against a section symbol,
5080 in which case we have to adjust according to where the
5081 section symbol winds up in the output section. */
5082 if (r_symndx >= locsymcount
5083 || (elf_bad_symtab (input_bfd)
5084 && local_sections[r_symndx] == NULL))
5088 sym = local_syms + r_symndx;
5089 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
5093 sec = local_sections[r_symndx];
5095 /* It would be logical to add sym->st_value here,
5096 but Irix 5 sometimes generates a garbage symbol
5098 addend += sec->output_offset;
5100 /* If this is HI16 or GOT16 with an associated LO16,
5101 adjust the addend accordingly. Otherwise, just
5103 if (r_type == R_MIPS_64 && bfd_big_endian (input_bfd))
5104 r = _bfd_relocate_contents (howto, input_bfd,
5106 contents + rel->r_offset + 4);
5107 else if (r_type != R_MIPS_HI16 && r_type != R_MIPS_GOT16)
5108 r = _bfd_relocate_contents (howto, input_bfd,
5110 contents + rel->r_offset);
5113 Elf_Internal_Rela *lorel;
5115 /* As a GNU extension, permit an arbitrary
5116 number of R_MIPS_HI16 relocs before the
5117 R_MIPS_LO16 reloc. This permits gcc to emit
5118 the HI and LO relocs itself. */
5119 if (r_type == R_MIPS_GOT16)
5123 for (lorel = rel + 1;
5125 && (ELF32_R_TYPE (lorel->r_info)
5131 && ELF32_R_TYPE (lorel->r_info) == R_MIPS_LO16)
5133 mips_elf_relocate_hi16 (input_bfd, rel, lorel,
5138 r = _bfd_relocate_contents (howto, input_bfd,
5140 contents + rel->r_offset);
5149 boolean undefined_error;
5151 /* This is a final link. */
5152 undefined_error = false;
5154 if (r_symndx < extsymoff
5155 || (elf_bad_symtab (input_bfd)
5156 && local_sections[r_symndx] != NULL))
5159 sym = local_syms + r_symndx;
5160 sec = local_sections[r_symndx];
5161 relocation = (sec->output_section->vma
5162 + sec->output_offset);
5164 /* It would be logical to always add sym->st_value here,
5165 but Irix 5 sometimes generates a garbage symbol
5167 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
5168 relocation += sym->st_value;
5170 /* mips16 text labels should be treated as odd. */
5171 if (sym->st_other == STO_MIPS16)
5179 indx = r_symndx - extsymoff;
5180 h = elf_sym_hashes (input_bfd)[indx];
5181 while (h->root.type == bfd_link_hash_indirect
5182 || h->root.type == bfd_link_hash_warning)
5183 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5184 if (strcmp (h->root.root.string, "_gp_disp") == 0)
5188 if (! ((*info->callbacks->reloc_dangerous)
5190 _("_gp_disp used when GP not defined"),
5191 input_bfd, input_section,
5194 /* Only give the error once per link. */
5196 _bfd_set_gp_value (output_bfd, gp);
5201 sec = input_section;
5202 if (sec->output_section != NULL)
5205 + sec->output_section->vma
5206 + sec->output_offset));
5208 relocation = gp - rel->r_offset;
5209 if (r_type == R_MIPS_LO16)
5213 else if (h->root.type == bfd_link_hash_defined
5214 || h->root.type == bfd_link_hash_defweak)
5216 sec = h->root.u.def.section;
5217 if (sec->output_section == NULL)
5220 relocation = (h->root.u.def.value
5221 + sec->output_section->vma
5222 + sec->output_offset);
5224 else if (h->root.type == bfd_link_hash_undefweak)
5226 else if (info->shared && ! info->symbolic)
5228 else if (strcmp (h->root.root.string, "_DYNAMIC_LINK") == 0)
5230 /* If this is a dynamic link, we should have created
5231 a _DYNAMIC_LINK symbol in
5232 mips_elf_create_dynamic_sections. Otherwise, we
5233 should define the symbol with a value of 0.
5234 FIXME: It should probably get into the symbol
5235 table somehow as well. */
5236 BFD_ASSERT (! info->shared);
5237 BFD_ASSERT (bfd_get_section_by_name (output_bfd,
5238 ".dynamic") == NULL);
5243 if (! ((*info->callbacks->undefined_symbol)
5244 (info, h->root.root.string, input_bfd,
5245 input_section, rel->r_offset)))
5247 undefined_error = true;
5252 mh = (struct mips_elf_link_hash_entry *) h;
5255 else if (sym != NULL)
5256 other = sym->st_other;
5260 /* If this function has an fn_stub, then it is a mips16
5261 function which needs a stub if it is called by a 32 bit
5262 function. If this reloc is anything other than a 16 bit
5263 call, redirect the reloc to the stub. We don't redirect
5264 relocs from other stub functions. */
5265 if (r_type != R_MIPS16_26
5267 && mh->fn_stub != NULL)
5269 && elf_tdata (input_bfd)->local_stubs != NULL
5270 && elf_tdata (input_bfd)->local_stubs[r_symndx] != NULL))
5271 && strncmp (bfd_get_section_name (input_bfd, input_section),
5272 FN_STUB, sizeof FN_STUB - 1) != 0
5273 && strncmp (bfd_get_section_name (input_bfd, input_section),
5274 CALL_STUB, sizeof CALL_STUB - 1) != 0
5275 && strncmp (bfd_get_section_name (input_bfd, input_section),
5276 CALL_FP_STUB, sizeof CALL_FP_STUB - 1) != 0)
5280 BFD_ASSERT (mh->need_fn_stub);
5281 relocation = (mh->fn_stub->output_section->vma
5282 + mh->fn_stub->output_offset);
5288 fn_stub = elf_tdata (input_bfd)->local_stubs[r_symndx];
5289 relocation = (fn_stub->output_section->vma
5290 + fn_stub->output_offset);
5293 /* RELOCATION now points to 32 bit code. */
5297 /* If this function has a call_stub, then it is called by a
5298 mips16 function; the call needs to go through a stub if
5299 this function is a 32 bit function. If this reloc is a
5300 16 bit call, and the symbol is not a 16 bit function,
5301 then redirect the reloc to the stub. Note that we don't
5302 need to worry about calling the function through a
5303 function pointer; such calls are handled by routing
5304 through a special mips16 routine. We don't have to check
5305 whether this call is from a stub; it can't be, because a
5306 stub contains 32 bit code, and hence can not have a 16
5308 if (r_type == R_MIPS16_26
5310 && (mh->call_stub != NULL || mh->call_fp_stub != NULL)
5311 && other != STO_MIPS16)
5315 /* If both call_stub and call_fp_stub are defined, we
5316 can figure out which one to use by seeing which one
5317 appears in the input file. */
5318 if (mh->call_stub != NULL && mh->call_fp_stub != NULL)
5323 for (o = input_bfd->sections; o != NULL; o = o->next)
5325 if (strncmp (bfd_get_section_name (input_bfd, o),
5326 CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0)
5328 stub = mh->call_fp_stub;
5333 stub = mh->call_stub;
5335 else if (mh->call_stub != NULL)
5336 stub = mh->call_stub;
5338 stub = mh->call_fp_stub;
5340 BFD_ASSERT (stub->_raw_size > 0);
5341 relocation = stub->output_section->vma + stub->output_offset;
5344 if (r_type == R_MIPS_HI16)
5346 Elf_Internal_Rela *lorel;
5348 /* As a GNU extension, permit an arbitrary number of
5349 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
5350 This permits gcc to emit the HI and LO relocs itself. */
5351 for (lorel = rel + 1;
5353 && ELF32_R_TYPE (lorel->r_info) == R_MIPS_HI16);
5357 && ELF32_R_TYPE (lorel->r_info) == R_MIPS_LO16)
5359 mips_elf_relocate_hi16 (input_bfd, rel, lorel,
5360 contents, relocation + addend);
5364 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
5365 contents, rel->r_offset,
5366 relocation, addend);
5368 else if (r_type == R_MIPS_GOT16 && local)
5370 /* GOT16 must also have an associated LO16 in the local
5371 case. In this case, the addend is extracted and the
5372 section in which the referenced object is determined.
5373 Then the final address of the object is computed and
5374 the GOT entry for the hipage (an aligned 64kb chunk)
5375 is added to .got section if needed. The offset field
5376 of the GOT16-relocated instruction is replaced by the
5377 index of this GOT entry for the hipage. */
5378 if ((rel + 1) < relend
5379 && ELF32_R_TYPE ((rel + 1)->r_info) == R_MIPS_LO16)
5381 if (! mips_elf_relocate_got_local (output_bfd, input_bfd,
5384 relocation + addend))
5389 r = bfd_reloc_outofrange;
5391 else if (r_type == R_MIPS_CALL16
5392 || r_type == R_MIPS_GOT16
5393 || r_type == R_MIPS_CALL_LO16
5394 || r_type == R_MIPS_GOT_LO16)
5398 /* This symbol must be registered as a global symbol
5399 having the corresponding got entry. */
5400 BFD_ASSERT (h->got.offset != (bfd_vma) -1);
5402 offset = (h->dynindx - g->global_gotsym + g->local_gotno) * 4;
5403 BFD_ASSERT (g->local_gotno <= offset
5404 && offset < sgot->_raw_size);
5405 bfd_put_32 (output_bfd, relocation + addend,
5406 sgot->contents + offset);
5407 offset = (sgot->output_section->vma + sgot->output_offset
5409 mips_elf_relocate_global_got (input_bfd, rel, contents,
5413 else if (r_type == R_MIPS_CALL_HI16
5414 || r_type == R_MIPS_GOT_HI16)
5418 /* This must be a global symbol with a got entry. The
5419 next reloc must be the corresponding LO16 reloc. */
5420 BFD_ASSERT (h != NULL && h->got.offset != (bfd_vma) -1);
5421 BFD_ASSERT ((rel + 1) < relend);
5422 BFD_ASSERT ((int) ELF32_R_TYPE ((rel + 1)->r_info)
5423 == (r_type == R_MIPS_CALL_HI16
5424 ? (int) R_MIPS_CALL_LO16
5425 : (int) R_MIPS_GOT_LO16));
5427 offset = (h->dynindx - g->global_gotsym + g->local_gotno) * 4;
5428 BFD_ASSERT (g->local_gotno <= offset
5429 && offset < sgot->_raw_size);
5430 bfd_put_32 (output_bfd, relocation + addend,
5431 sgot->contents + offset);
5432 offset = (sgot->output_section->vma + sgot->output_offset
5434 mips_elf_relocate_hi16 (input_bfd, rel, rel + 1, contents,
5438 else if (r_type == R_MIPS_REL32
5439 || r_type == R_MIPS_32)
5441 Elf_Internal_Rel outrel;
5442 Elf32_crinfo cptrel;
5446 || (elf_hash_table (info)->dynamic_sections_created
5448 && ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)
5450 && (input_section->flags & SEC_ALLOC) != 0)
5454 /* When generating a shared object, these
5455 relocations are copied into the output file to be
5456 resolved at run time. */
5459 sreloc = bfd_get_section_by_name (dynobj, ".rel.dyn");
5460 BFD_ASSERT (sreloc != NULL);
5465 if (elf_section_data (input_section)->stab_info == NULL)
5466 outrel.r_offset = rel->r_offset;
5471 off = (_bfd_stab_section_offset
5472 (output_bfd, &elf_hash_table (info)->stab_info,
5474 &elf_section_data (input_section)->stab_info,
5476 if (off == (bfd_vma) -1)
5478 outrel.r_offset = off;
5481 outrel.r_offset += (input_section->output_section->vma
5482 + input_section->output_offset);
5484 addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
5487 memset (&outrel, 0, sizeof outrel);
5489 && (! info->symbolic
5490 || (h->elf_link_hash_flags
5491 & ELF_LINK_HASH_DEF_REGULAR) == 0))
5493 BFD_ASSERT (h->dynindx != -1);
5494 outrel.r_info = ELF32_R_INFO (h->dynindx, R_MIPS_REL32);
5495 sec = input_section;
5502 sec = local_sections[r_symndx];
5505 BFD_ASSERT (h->root.type == bfd_link_hash_defined
5507 == bfd_link_hash_defweak));
5508 sec = h->root.u.def.section;
5510 if (sec != NULL && bfd_is_abs_section (sec))
5512 else if (sec == NULL || sec->owner == NULL)
5514 bfd_set_error (bfd_error_bad_value);
5521 osec = sec->output_section;
5522 indx = elf_section_data (osec)->dynindx;
5527 outrel.r_info = ELF32_R_INFO (indx, R_MIPS_REL32);
5528 addend += relocation;
5532 bfd_put_32 (output_bfd, addend, contents + rel->r_offset);
5534 bfd_elf32_swap_reloc_out (output_bfd, &outrel,
5535 (((Elf32_External_Rel *)
5537 + sreloc->reloc_count));
5538 ++sreloc->reloc_count;
5540 if (! skip && SGI_COMPAT (output_bfd))
5545 /* Make an entry of compact relocation info. */
5546 mips_elf_set_cr_format (cptrel, CRF_MIPS_LONG);
5547 cptrel.vaddr = (rel->r_offset
5548 + input_section->output_section->vma
5549 + input_section->output_offset);
5550 if (r_type == R_MIPS_REL32)
5551 mips_elf_set_cr_type (cptrel, CRT_MIPS_REL32);
5553 mips_elf_set_cr_type (cptrel, CRT_MIPS_WORD);
5554 mips_elf_set_cr_dist2to (cptrel, 0);
5555 cptrel.konst = addend;
5557 cr = (scpt->contents
5558 + sizeof (Elf32_External_compact_rel));
5559 bfd_elf32_swap_crinfo_out (output_bfd, &cptrel,
5560 ((Elf32_External_crinfo *) cr
5561 + scpt->reloc_count));
5562 ++scpt->reloc_count;
5565 /* This reloc will be computed at runtime, so
5566 there's no need to do anything now. */
5570 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
5571 contents, rel->r_offset,
5572 relocation, addend);
5574 else if (r_type == R_MIPS_64)
5579 /* Do a 32 bit relocation, and sign extend to 64 bits. */
5580 addr = rel->r_offset;
5581 if (bfd_big_endian (input_bfd))
5583 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
5584 contents, addr, relocation,
5586 val = bfd_get_32 (input_bfd, contents + addr);
5587 if ((val & 0x80000000) != 0)
5591 addr = rel->r_offset;
5592 if (bfd_little_endian (input_bfd))
5594 bfd_put_32 (input_bfd, val, contents + addr);
5596 else if (r_type == R_MIPS_26 && other == STO_MIPS16)
5600 /* This is a jump to a mips16 routine from a mips32
5601 routine. We need to change jal into jalx. */
5602 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
5603 if (((insn >> 26) & 0x3f) != 0x3
5604 && ((insn >> 26) & 0x3f) != 0x1d)
5606 (*_bfd_error_handler)
5607 (_("%s: %s+0x%lx: jump to mips16 routine which is not jal"),
5608 bfd_get_filename (input_bfd),
5609 input_section->name,
5610 (unsigned long) rel->r_offset);
5611 bfd_set_error (bfd_error_bad_value);
5614 insn = (insn & 0x3ffffff) | (0x1d << 26);
5615 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
5616 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
5617 contents, rel->r_offset,
5618 relocation, addend);
5620 else if (r_type == R_MIPS16_26)
5622 /* It's easiest to do the normal relocation, and then
5623 dig out the instruction and swap the first word the
5624 way the mips16 expects it. If this is little endian,
5625 though, we need to swap the two words first, and then
5626 swap them back again later, so that the address looks
5629 if (bfd_little_endian (input_bfd))
5633 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
5634 insn = ((insn >> 16) & 0xffff) | ((insn & 0xffff) << 16);
5635 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
5638 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
5639 contents, rel->r_offset,
5640 relocation, addend);
5641 if (r == bfd_reloc_ok)
5645 if (bfd_little_endian (input_bfd))
5647 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
5648 insn = ((insn >> 16) & 0xffff) | ((insn & 0xffff) << 16);
5649 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
5652 insn = bfd_get_16 (input_bfd, contents + rel->r_offset);
5653 insn = ((insn & 0xfc00)
5654 | ((insn & 0x1f) << 5)
5655 | ((insn & 0x3e0) >> 5));
5656 /* If this is a jump to a 32 bit routine, then make
5658 if (other != STO_MIPS16)
5660 bfd_put_16 (input_bfd, insn, contents + rel->r_offset);
5663 else if (r_type == R_MIPS16_GPREL)
5665 unsigned short extend, insn;
5667 unsigned long final;
5669 /* Extract the addend into buf, run the regular reloc,
5670 and stuff the resulting value back into the
5672 if (rel->r_offset > input_section->_raw_size)
5673 r = bfd_reloc_outofrange;
5676 extend = bfd_get_16 (input_bfd, contents + rel->r_offset);
5677 insn = bfd_get_16 (input_bfd, contents + rel->r_offset + 2);
5678 bfd_put_32 (input_bfd,
5679 (((extend & 0x1f) << 11)
5683 r = _bfd_final_link_relocate (howto, input_bfd,
5685 (bfd_vma) 0, relocation,
5687 final = bfd_get_32 (input_bfd, buf);
5688 bfd_put_16 (input_bfd,
5690 | ((final >> 11) & 0x1f)
5692 contents + rel->r_offset);
5693 bfd_put_16 (input_bfd,
5696 contents + rel->r_offset + 2);
5699 /* start-sanitize-sky */
5700 else if (r_type == R_MIPS_DVP_U15_S3)
5702 if (rel->r_offset > input_section->_raw_size)
5703 r = bfd_reloc_outofrange;
5708 relocation += rel->r_addend;
5711 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
5712 relocation += ((x & (0xf << 21)) >> 10) + (x & 0x7ff);
5713 x &= ~ ((0xf << 21) | 0x7ff);
5714 x |= (((relocation & 0x7800) << 10)
5715 | (relocation & 0x7ff));
5716 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
5718 if (relocation & ~ (bfd_vma) 0x7fff)
5719 r = bfd_reloc_overflow;
5724 /* end-sanitize-sky */
5726 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
5727 contents, rel->r_offset,
5728 relocation, addend);
5730 /* The jal instruction can only jump to an address which is
5731 divisible by 4, and it can only jump to an address with
5732 the same upper 4 bits as the PC. */
5733 if (r == bfd_reloc_ok
5734 && (r_type == R_MIPS16_26 || r_type == R_MIPS_26))
5739 if (other == STO_MIPS16)
5740 addr &= ~ (bfd_vma) 1;
5743 || ((addr & 0xf0000000)
5744 != ((input_section->output_section->vma
5745 + input_section->output_offset
5748 r = bfd_reloc_overflow;
5751 /* Don't bother to report a relocation overflow for a call
5752 to a weak undefined symbol with a value of zero. This
5755 even if we aren't in range to call address zero. */
5756 if (r == bfd_reloc_overflow
5757 && (r_type == R_MIPS16_26 || r_type == R_MIPS_26)
5758 && relocation + addend == 0
5760 && h->root.type == bfd_link_hash_undefweak)
5763 /* If we've already issued an error for an undefined symbol,
5764 don't issue another useless error. */
5766 && (r == bfd_reloc_undefined || r == bfd_reloc_overflow))
5769 if (SGI_COMPAT (abfd)
5771 && (input_section->flags & SEC_ALLOC) != 0)
5773 Elf32_crinfo cptrel;
5776 /* Make an entry of compact relocation info. */
5777 mips_elf_set_cr_format (cptrel, CRF_MIPS_LONG);
5778 cptrel.vaddr = (rel->r_offset
5779 + input_section->output_section->vma
5780 + input_section->output_offset);
5785 mips_elf_set_cr_type (cptrel, CRT_MIPS_JMPAD);
5786 /* XXX How should we set dist2to in this case. */
5787 mips_elf_set_cr_dist2to (cptrel, 8);
5788 cptrel.konst = addend + relocation;
5789 cr = scpt->contents + sizeof (Elf32_External_compact_rel);
5790 bfd_elf32_swap_crinfo_out (output_bfd, &cptrel,
5791 ((Elf32_External_crinfo *) cr
5792 + scpt->reloc_count));
5793 ++scpt->reloc_count;
5796 case R_MIPS_GPREL16:
5797 case R_MIPS_LITERAL:
5798 case R_MIPS_GPREL32:
5799 mips_elf_set_cr_type (cptrel, CRT_MIPS_GPHI_LO);
5800 cptrel.konst = gp - cptrel.vaddr;
5801 mips_elf_set_cr_dist2to (cptrel, 4);
5802 cr = scpt->contents + sizeof (Elf32_External_compact_rel);
5803 bfd_elf32_swap_crinfo_out (output_bfd, &cptrel,
5804 ((Elf32_External_crinfo *) cr
5805 + scpt->reloc_count));
5806 ++scpt->reloc_count;
5815 if (r != bfd_reloc_ok)
5820 case bfd_reloc_outofrange:
5822 case bfd_reloc_overflow:
5827 name = h->root.root.string;
5830 name = bfd_elf_string_from_elf_section (input_bfd,
5831 symtab_hdr->sh_link,
5836 name = bfd_section_name (input_bfd, sec);
5838 if (! ((*info->callbacks->reloc_overflow)
5839 (info, name, howto->name, (bfd_vma) 0,
5840 input_bfd, input_section, rel->r_offset)))
5851 /* This hook function is called before the linker writes out a global
5852 symbol. We mark symbols as small common if appropriate. This is
5853 also where we undo the increment of the value for a mips16 symbol. */
5857 mips_elf_link_output_symbol_hook (abfd, info, name, sym, input_sec)
5859 struct bfd_link_info *info;
5861 Elf_Internal_Sym *sym;
5862 asection *input_sec;
5864 /* If we see a common symbol, which implies a relocatable link, then
5865 if a symbol was small common in an input file, mark it as small
5866 common in the output file. */
5867 if (sym->st_shndx == SHN_COMMON
5868 && strcmp (input_sec->name, ".scommon") == 0)
5869 sym->st_shndx = SHN_MIPS_SCOMMON;
5871 if (sym->st_other == STO_MIPS16
5872 && (sym->st_value & 1) != 0)
5878 /* Functions for the dynamic linker. */
5880 /* The name of the dynamic interpreter. This is put in the .interp
5883 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
5885 /* Create dynamic sections when linking against a dynamic object. */
5888 mips_elf_create_dynamic_sections (abfd, info)
5890 struct bfd_link_info *info;
5892 struct elf_link_hash_entry *h;
5894 register asection *s;
5895 const char * const *namep;
5897 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
5898 | SEC_LINKER_CREATED | SEC_READONLY);
5900 /* Mips ABI requests the .dynamic section to be read only. */
5901 s = bfd_get_section_by_name (abfd, ".dynamic");
5904 if (! bfd_set_section_flags (abfd, s, flags))
5908 /* We need to create .got section. */
5909 if (! mips_elf_create_got_section (abfd, info))
5912 /* Create .stub section. */
5913 if (bfd_get_section_by_name (abfd, ".stub") == NULL)
5915 s = bfd_make_section (abfd, ".stub");
5917 || ! bfd_set_section_flags (abfd, s, flags)
5918 || ! bfd_set_section_alignment (abfd, s, 2))
5922 if (SGI_COMPAT (abfd)
5924 && bfd_get_section_by_name (abfd, ".rld_map") == NULL)
5926 s = bfd_make_section (abfd, ".rld_map");
5928 || ! bfd_set_section_flags (abfd, s, flags & ~SEC_READONLY)
5929 || ! bfd_set_section_alignment (abfd, s, 2))
5933 if (SGI_COMPAT (abfd))
5935 for (namep = mips_elf_dynsym_rtproc_names; *namep != NULL; namep++)
5938 if (! (_bfd_generic_link_add_one_symbol
5939 (info, abfd, *namep, BSF_GLOBAL, bfd_und_section_ptr,
5940 (bfd_vma) 0, (const char *) NULL, false,
5941 get_elf_backend_data (abfd)->collect,
5942 (struct bfd_link_hash_entry **) &h)))
5944 h->elf_link_hash_flags &=~ ELF_LINK_NON_ELF;
5945 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
5946 h->type = STT_SECTION;
5948 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
5952 /* We need to create a .compact_rel section. */
5953 if (! mips_elf_create_compact_rel_section (abfd, info))
5956 /* Change aligments of some sections. */
5957 s = bfd_get_section_by_name (abfd, ".hash");
5959 bfd_set_section_alignment (abfd, s, 4);
5960 s = bfd_get_section_by_name (abfd, ".dynsym");
5962 bfd_set_section_alignment (abfd, s, 4);
5963 s = bfd_get_section_by_name (abfd, ".dynstr");
5965 bfd_set_section_alignment (abfd, s, 4);
5966 s = bfd_get_section_by_name (abfd, ".reginfo");
5968 bfd_set_section_alignment (abfd, s, 4);
5969 s = bfd_get_section_by_name (abfd, ".dynamic");
5971 bfd_set_section_alignment (abfd, s, 4);
5977 if (! (_bfd_generic_link_add_one_symbol
5978 (info, abfd, "_DYNAMIC_LINK", BSF_GLOBAL, bfd_abs_section_ptr,
5979 (bfd_vma) 0, (const char *) NULL, false,
5980 get_elf_backend_data (abfd)->collect,
5981 (struct bfd_link_hash_entry **) &h)))
5983 h->elf_link_hash_flags &=~ ELF_LINK_NON_ELF;
5984 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
5985 h->type = STT_SECTION;
5987 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
5990 if (! mips_elf_hash_table (info)->use_rld_obj_head)
5992 /* __rld_map is a four byte word located in the .data section
5993 and is filled in by the rtld to contain a pointer to
5994 the _r_debug structure. Its symbol value will be set in
5995 mips_elf_finish_dynamic_symbol. */
5996 s = bfd_get_section_by_name (abfd, ".rld_map");
5997 BFD_ASSERT (s != NULL);
6000 if (! (_bfd_generic_link_add_one_symbol
6001 (info, abfd, "__rld_map", BSF_GLOBAL, s,
6002 (bfd_vma) 0, (const char *) NULL, false,
6003 get_elf_backend_data (abfd)->collect,
6004 (struct bfd_link_hash_entry **) &h)))
6006 h->elf_link_hash_flags &=~ ELF_LINK_NON_ELF;
6007 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
6008 h->type = STT_OBJECT;
6010 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
6018 /* Create the .compact_rel section. */
6021 mips_elf_create_compact_rel_section (abfd, info)
6023 struct bfd_link_info *info;
6026 register asection *s;
6028 if (bfd_get_section_by_name (abfd, ".compact_rel") == NULL)
6030 flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED
6033 s = bfd_make_section (abfd, ".compact_rel");
6035 || ! bfd_set_section_flags (abfd, s, flags)
6036 || ! bfd_set_section_alignment (abfd, s, 2))
6039 s->_raw_size = sizeof (Elf32_External_compact_rel);
6045 /* Create the .got section to hold the global offset table. */
6048 mips_elf_create_got_section (abfd, info)
6050 struct bfd_link_info *info;
6053 register asection *s;
6054 struct elf_link_hash_entry *h;
6055 struct mips_got_info *g;
6057 /* This function may be called more than once. */
6058 if (bfd_get_section_by_name (abfd, ".got") != NULL)
6061 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
6062 | SEC_LINKER_CREATED);
6064 s = bfd_make_section (abfd, ".got");
6066 || ! bfd_set_section_flags (abfd, s, flags)
6067 || ! bfd_set_section_alignment (abfd, s, 4))
6070 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
6071 linker script because we don't want to define the symbol if we
6072 are not creating a global offset table. */
6074 if (! (_bfd_generic_link_add_one_symbol
6075 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
6076 (bfd_vma) 0, (const char *) NULL, false,
6077 get_elf_backend_data (abfd)->collect,
6078 (struct bfd_link_hash_entry **) &h)))
6080 h->elf_link_hash_flags &=~ ELF_LINK_NON_ELF;
6081 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
6082 h->type = STT_OBJECT;
6085 && ! bfd_elf32_link_record_dynamic_symbol (info, h))
6088 /* The first several global offset table entries are reserved. */
6089 s->_raw_size = MIPS_RESERVED_GOTNO * 4;
6091 g = (struct mips_got_info *) bfd_alloc (abfd,
6092 sizeof (struct mips_got_info));
6095 g->global_gotsym = 0;
6096 g->local_gotno = MIPS_RESERVED_GOTNO;
6097 g->assigned_gotno = MIPS_RESERVED_GOTNO;
6098 if (elf_section_data (s) == NULL)
6101 (PTR) bfd_zalloc (abfd, sizeof (struct bfd_elf_section_data));
6102 if (elf_section_data (s) == NULL)
6105 elf_section_data (s)->tdata = (PTR) g;
6110 /* Look through the relocs for a section during the first phase, and
6111 allocate space in the global offset table. */
6114 mips_elf_check_relocs (abfd, info, sec, relocs)
6116 struct bfd_link_info *info;
6118 const Elf_Internal_Rela *relocs;
6122 Elf_Internal_Shdr *symtab_hdr;
6123 struct elf_link_hash_entry **sym_hashes;
6124 struct mips_got_info *g;
6126 const Elf_Internal_Rela *rel;
6127 const Elf_Internal_Rela *rel_end;
6131 if (info->relocateable)
6134 dynobj = elf_hash_table (info)->dynobj;
6135 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
6136 sym_hashes = elf_sym_hashes (abfd);
6137 extsymoff = (elf_bad_symtab (abfd)) ? 0 : symtab_hdr->sh_info;
6139 /* Check for the mips16 stub sections. */
6141 name = bfd_get_section_name (abfd, sec);
6142 if (strncmp (name, FN_STUB, sizeof FN_STUB - 1) == 0)
6144 unsigned long r_symndx;
6146 /* Look at the relocation information to figure out which symbol
6149 r_symndx = ELF32_R_SYM (relocs->r_info);
6151 if (r_symndx < extsymoff
6152 || sym_hashes[r_symndx - extsymoff] == NULL)
6156 /* This stub is for a local symbol. This stub will only be
6157 needed if there is some relocation in this BFD, other
6158 than a 16 bit function call, which refers to this symbol. */
6159 for (o = abfd->sections; o != NULL; o = o->next)
6161 Elf_Internal_Rela *sec_relocs;
6162 const Elf_Internal_Rela *r, *rend;
6164 /* We can ignore stub sections when looking for relocs. */
6165 if ((o->flags & SEC_RELOC) == 0
6166 || o->reloc_count == 0
6167 || strncmp (bfd_get_section_name (abfd, o), FN_STUB,
6168 sizeof FN_STUB - 1) == 0
6169 || strncmp (bfd_get_section_name (abfd, o), CALL_STUB,
6170 sizeof CALL_STUB - 1) == 0
6171 || strncmp (bfd_get_section_name (abfd, o), CALL_FP_STUB,
6172 sizeof CALL_FP_STUB - 1) == 0)
6175 sec_relocs = (_bfd_elf32_link_read_relocs
6176 (abfd, o, (PTR) NULL,
6177 (Elf_Internal_Rela *) NULL,
6178 info->keep_memory));
6179 if (sec_relocs == NULL)
6182 rend = sec_relocs + o->reloc_count;
6183 for (r = sec_relocs; r < rend; r++)
6184 if (ELF32_R_SYM (r->r_info) == r_symndx
6185 && ELF32_R_TYPE (r->r_info) != R_MIPS16_26)
6188 if (! info->keep_memory)
6197 /* There is no non-call reloc for this stub, so we do
6198 not need it. Since this function is called before
6199 the linker maps input sections to output sections, we
6200 can easily discard it by setting the SEC_EXCLUDE
6202 sec->flags |= SEC_EXCLUDE;
6206 /* Record this stub in an array of local symbol stubs for
6208 if (elf_tdata (abfd)->local_stubs == NULL)
6210 unsigned long symcount;
6213 if (elf_bad_symtab (abfd))
6214 symcount = symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
6216 symcount = symtab_hdr->sh_info;
6217 n = (asection **) bfd_zalloc (abfd,
6218 symcount * sizeof (asection *));
6221 elf_tdata (abfd)->local_stubs = n;
6224 elf_tdata (abfd)->local_stubs[r_symndx] = sec;
6226 /* We don't need to set mips16_stubs_seen in this case.
6227 That flag is used to see whether we need to look through
6228 the global symbol table for stubs. We don't need to set
6229 it here, because we just have a local stub. */
6233 struct mips_elf_link_hash_entry *h;
6235 h = ((struct mips_elf_link_hash_entry *)
6236 sym_hashes[r_symndx - extsymoff]);
6238 /* H is the symbol this stub is for. */
6241 mips_elf_hash_table (info)->mips16_stubs_seen = true;
6244 else if (strncmp (name, CALL_STUB, sizeof CALL_STUB - 1) == 0
6245 || strncmp (name, CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0)
6247 unsigned long r_symndx;
6248 struct mips_elf_link_hash_entry *h;
6251 /* Look at the relocation information to figure out which symbol
6254 r_symndx = ELF32_R_SYM (relocs->r_info);
6256 if (r_symndx < extsymoff
6257 || sym_hashes[r_symndx - extsymoff] == NULL)
6259 /* This stub was actually built for a static symbol defined
6260 in the same file. We assume that all static symbols in
6261 mips16 code are themselves mips16, so we can simply
6262 discard this stub. Since this function is called before
6263 the linker maps input sections to output sections, we can
6264 easily discard it by setting the SEC_EXCLUDE flag. */
6265 sec->flags |= SEC_EXCLUDE;
6269 h = ((struct mips_elf_link_hash_entry *)
6270 sym_hashes[r_symndx - extsymoff]);
6272 /* H is the symbol this stub is for. */
6274 if (strncmp (name, CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0)
6275 loc = &h->call_fp_stub;
6277 loc = &h->call_stub;
6279 /* If we already have an appropriate stub for this function, we
6280 don't need another one, so we can discard this one. Since
6281 this function is called before the linker maps input sections
6282 to output sections, we can easily discard it by setting the
6283 SEC_EXCLUDE flag. We can also discard this section if we
6284 happen to already know that this is a mips16 function; it is
6285 not necessary to check this here, as it is checked later, but
6286 it is slightly faster to check now. */
6287 if (*loc != NULL || h->root.other == STO_MIPS16)
6289 sec->flags |= SEC_EXCLUDE;
6294 mips_elf_hash_table (info)->mips16_stubs_seen = true;
6304 sgot = bfd_get_section_by_name (dynobj, ".got");
6309 BFD_ASSERT (elf_section_data (sgot) != NULL);
6310 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
6311 BFD_ASSERT (g != NULL);
6317 rel_end = relocs + sec->reloc_count;
6318 for (rel = relocs; rel < rel_end; rel++)
6320 unsigned long r_symndx;
6321 struct elf_link_hash_entry *h;
6323 r_symndx = ELF32_R_SYM (rel->r_info);
6325 if (r_symndx < extsymoff)
6329 h = sym_hashes[r_symndx - extsymoff];
6331 /* This may be an indirect symbol created because of a version. */
6334 while (h->root.type == bfd_link_hash_indirect)
6335 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6339 /* Some relocs require a global offset table. */
6340 if (dynobj == NULL || sgot == NULL)
6342 switch (ELF32_R_TYPE (rel->r_info))
6346 case R_MIPS_CALL_HI16:
6347 case R_MIPS_CALL_LO16:
6348 case R_MIPS_GOT_HI16:
6349 case R_MIPS_GOT_LO16:
6351 elf_hash_table (info)->dynobj = dynobj = abfd;
6352 if (! mips_elf_create_got_section (dynobj, info))
6354 sgot = bfd_get_section_by_name (dynobj, ".got");
6355 BFD_ASSERT (sgot != NULL);
6356 BFD_ASSERT (elf_section_data (sgot) != NULL);
6357 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
6358 BFD_ASSERT (g != NULL);
6364 && (info->shared || h != NULL)
6365 && (sec->flags & SEC_ALLOC) != 0)
6366 elf_hash_table (info)->dynobj = dynobj = abfd;
6374 switch (ELF32_R_TYPE (rel->r_info))
6377 case R_MIPS_CALL_HI16:
6378 case R_MIPS_CALL_LO16:
6379 /* This symbol requires a global offset table entry. */
6383 (*_bfd_error_handler)
6384 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
6385 bfd_get_filename (abfd), (unsigned long) rel->r_offset);
6386 bfd_set_error (bfd_error_bad_value);
6390 /* Make sure this symbol is output as a dynamic symbol. */
6391 if (h->dynindx == -1)
6393 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
6397 if (h->got.offset != (bfd_vma) -1)
6399 /* We have already allocated space in the .got. */
6403 /* Note the index of the first global got symbol in .dynsym. */
6404 if (g->global_gotsym == 0
6405 || g->global_gotsym > (unsigned long) h->dynindx)
6406 g->global_gotsym = h->dynindx;
6408 /* Make this symbol to have the corresponding got entry. */
6411 /* We need a stub, not a plt entry for the undefined
6412 function. But we record it as if it needs plt. See
6413 elf_adjust_dynamic_symbol in elflink.h. */
6414 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
6420 case R_MIPS_GOT_HI16:
6421 case R_MIPS_GOT_LO16:
6422 /* This symbol requires a global offset table entry. */
6426 /* Make sure this symbol is output as a dynamic symbol. */
6427 if (h->dynindx == -1)
6429 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
6433 if (h->got.offset != (bfd_vma) -1)
6435 /* We have already allocated space in the .got. */
6438 /* Note the index of the first global got symbol in
6440 if (g->global_gotsym == 0
6441 || g->global_gotsym > (unsigned long) h->dynindx)
6442 g->global_gotsym = h->dynindx;
6444 /* Make this symbol to be the global got symbol. */
6452 if ((info->shared || h != NULL)
6453 && (sec->flags & SEC_ALLOC) != 0)
6457 const char *name = ".rel.dyn";
6459 sreloc = bfd_get_section_by_name (dynobj, name);
6462 sreloc = bfd_make_section (dynobj, name);
6464 || ! bfd_set_section_flags (dynobj, sreloc,
6469 | SEC_LINKER_CREATED
6471 || ! bfd_set_section_alignment (dynobj, sreloc,
6478 /* When creating a shared object, we must copy these
6479 reloc types into the output file as R_MIPS_REL32
6480 relocs. We make room for this reloc in the
6481 .rel.dyn reloc section */
6482 if (sreloc->_raw_size == 0)
6484 /* Add a null element. */
6485 sreloc->_raw_size += sizeof (Elf32_External_Rel);
6486 ++sreloc->reloc_count;
6488 sreloc->_raw_size += sizeof (Elf32_External_Rel);
6492 struct mips_elf_link_hash_entry *hmips;
6494 /* We only need to copy this reloc if the symbol is
6495 defined in a dynamic object. */
6496 hmips = (struct mips_elf_link_hash_entry *) h;
6497 ++hmips->mips_32_relocs;
6501 if (SGI_COMPAT (abfd))
6502 mips_elf_hash_table (info)->compact_rel_size +=
6503 sizeof (Elf32_External_crinfo);
6508 case R_MIPS_GPREL16:
6509 case R_MIPS_LITERAL:
6510 case R_MIPS_GPREL32:
6511 if (SGI_COMPAT (abfd))
6512 mips_elf_hash_table (info)->compact_rel_size +=
6513 sizeof (Elf32_External_crinfo);
6516 /* This relocation describes the C++ object vtable hierarchy.
6517 Reconstruct it for later use during GC. */
6518 case R_MIPS_GNU_VTINHERIT:
6519 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
6523 /* This relocation describes which C++ vtable entries are actually
6524 used. Record for later use during GC. */
6525 case R_MIPS_GNU_VTENTRY:
6526 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_offset))
6534 /* If this reloc is not a 16 bit call, and it has a global
6535 symbol, then we will need the fn_stub if there is one.
6536 References from a stub section do not count. */
6538 && ELF32_R_TYPE (rel->r_info) != R_MIPS16_26
6539 && strncmp (bfd_get_section_name (abfd, sec), FN_STUB,
6540 sizeof FN_STUB - 1) != 0
6541 && strncmp (bfd_get_section_name (abfd, sec), CALL_STUB,
6542 sizeof CALL_STUB - 1) != 0
6543 && strncmp (bfd_get_section_name (abfd, sec), CALL_FP_STUB,
6544 sizeof CALL_FP_STUB - 1) != 0)
6546 struct mips_elf_link_hash_entry *mh;
6548 mh = (struct mips_elf_link_hash_entry *) h;
6549 mh->need_fn_stub = true;
6556 /* Return the section that should be marked against GC for a given
6560 mips_elf_gc_mark_hook (abfd, info, rel, h, sym)
6562 struct bfd_link_info *info;
6563 Elf_Internal_Rela *rel;
6564 struct elf_link_hash_entry *h;
6565 Elf_Internal_Sym *sym;
6567 /* ??? Do mips16 stub sections need to be handled special? */
6571 switch (ELF32_R_TYPE (rel->r_info))
6573 case R_MIPS_GNU_VTINHERIT:
6574 case R_MIPS_GNU_VTENTRY:
6578 switch (h->root.type)
6580 case bfd_link_hash_defined:
6581 case bfd_link_hash_defweak:
6582 return h->root.u.def.section;
6584 case bfd_link_hash_common:
6585 return h->root.u.c.p->section;
6594 if (!(elf_bad_symtab (abfd)
6595 && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
6596 && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
6597 && sym->st_shndx != SHN_COMMON))
6599 return bfd_section_from_elf_index (abfd, sym->st_shndx);
6606 /* Update the got entry reference counts for the section being removed. */
6609 mips_elf_gc_sweep_hook (abfd, info, sec, relocs)
6611 struct bfd_link_info *info;
6613 const Elf_Internal_Rela *relocs;
6616 Elf_Internal_Shdr *symtab_hdr;
6617 struct elf_link_hash_entry **sym_hashes;
6618 bfd_signed_vma *local_got_refcounts;
6619 const Elf_Internal_Rela *rel, *relend;
6620 unsigned long r_symndx;
6621 struct elf_link_hash_entry *h;
6623 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
6624 sym_hashes = elf_sym_hashes (abfd);
6625 local_got_refcounts = elf_local_got_refcounts (abfd);
6627 relend = relocs + sec->reloc_count;
6628 for (rel = relocs; rel < relend; rel++)
6629 switch (ELF32_R_TYPE (rel->r_info))
6633 case R_MIPS_CALL_HI16:
6634 case R_MIPS_CALL_LO16:
6635 case R_MIPS_GOT_HI16:
6636 case R_MIPS_GOT_LO16:
6637 /* ??? It would seem that the existing MIPS code does no sort
6638 of reference counting or whatnot on its GOT and PLT entries,
6639 so it is not possible to garbage collect them at this time. */
6651 /* Adjust a symbol defined by a dynamic object and referenced by a
6652 regular object. The current definition is in some section of the
6653 dynamic object, but we're not including those sections. We have to
6654 change the definition to something the rest of the link can
6658 mips_elf_adjust_dynamic_symbol (info, h)
6659 struct bfd_link_info *info;
6660 struct elf_link_hash_entry *h;
6663 struct mips_elf_link_hash_entry *hmips;
6666 dynobj = elf_hash_table (info)->dynobj;
6668 /* Make sure we know what is going on here. */
6669 BFD_ASSERT (dynobj != NULL
6670 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
6671 || h->weakdef != NULL
6672 || ((h->elf_link_hash_flags
6673 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
6674 && (h->elf_link_hash_flags
6675 & ELF_LINK_HASH_REF_REGULAR) != 0
6676 && (h->elf_link_hash_flags
6677 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
6679 /* If this symbol is defined in a dynamic object, we need to copy
6680 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
6682 hmips = (struct mips_elf_link_hash_entry *) h;
6683 if (! info->relocateable
6684 && hmips->mips_32_relocs != 0
6685 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
6687 s = bfd_get_section_by_name (dynobj, ".rel.dyn");
6688 BFD_ASSERT (s != NULL);
6690 if (s->_raw_size == 0)
6692 /* Make room for a null element. */
6693 s->_raw_size += sizeof (Elf32_External_Rel);
6696 s->_raw_size += hmips->mips_32_relocs * sizeof (Elf32_External_Rel);
6699 /* For a function, create a stub, if needed. */
6700 if (h->type == STT_FUNC
6701 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
6703 if (! elf_hash_table (info)->dynamic_sections_created)
6706 /* If this symbol is not defined in a regular file, then set
6707 the symbol to the stub location. This is required to make
6708 function pointers compare as equal between the normal
6709 executable and the shared library. */
6710 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
6712 /* We need .stub section. */
6713 s = bfd_get_section_by_name (dynobj, ".stub");
6714 BFD_ASSERT (s != NULL);
6716 h->root.u.def.section = s;
6717 h->root.u.def.value = s->_raw_size;
6719 /* XXX Write this stub address somewhere. */
6720 h->plt.offset = s->_raw_size;
6722 /* Make room for this stub code. */
6723 s->_raw_size += MIPS_FUNCTION_STUB_SIZE;
6725 /* The last half word of the stub will be filled with the index
6726 of this symbol in .dynsym section. */
6731 /* If this is a weak symbol, and there is a real definition, the
6732 processor independent code will have arranged for us to see the
6733 real definition first, and we can just use the same value. */
6734 if (h->weakdef != NULL)
6736 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
6737 || h->weakdef->root.type == bfd_link_hash_defweak);
6738 h->root.u.def.section = h->weakdef->root.u.def.section;
6739 h->root.u.def.value = h->weakdef->root.u.def.value;
6743 /* This is a reference to a symbol defined by a dynamic object which
6744 is not a function. */
6749 /* This function is called after all the input files have been read,
6750 and the input sections have been assigned to output sections. We
6751 check for any mips16 stub sections that we can discard. */
6753 static boolean mips_elf_check_mips16_stubs
6754 PARAMS ((struct mips_elf_link_hash_entry *, PTR));
6757 mips_elf_always_size_sections (output_bfd, info)
6759 struct bfd_link_info *info;
6761 if (info->relocateable
6762 || ! mips_elf_hash_table (info)->mips16_stubs_seen)
6765 mips_elf_link_hash_traverse (mips_elf_hash_table (info),
6766 mips_elf_check_mips16_stubs,
6772 /* Check the mips16 stubs for a particular symbol, and see if we can
6777 mips_elf_check_mips16_stubs (h, data)
6778 struct mips_elf_link_hash_entry *h;
6781 if (h->fn_stub != NULL
6782 && ! h->need_fn_stub)
6784 /* We don't need the fn_stub; the only references to this symbol
6785 are 16 bit calls. Clobber the size to 0 to prevent it from
6786 being included in the link. */
6787 h->fn_stub->_raw_size = 0;
6788 h->fn_stub->_cooked_size = 0;
6789 h->fn_stub->flags &= ~ SEC_RELOC;
6790 h->fn_stub->reloc_count = 0;
6791 h->fn_stub->flags |= SEC_EXCLUDE;
6794 if (h->call_stub != NULL
6795 && h->root.other == STO_MIPS16)
6797 /* We don't need the call_stub; this is a 16 bit function, so
6798 calls from other 16 bit functions are OK. Clobber the size
6799 to 0 to prevent it from being included in the link. */
6800 h->call_stub->_raw_size = 0;
6801 h->call_stub->_cooked_size = 0;
6802 h->call_stub->flags &= ~ SEC_RELOC;
6803 h->call_stub->reloc_count = 0;
6804 h->call_stub->flags |= SEC_EXCLUDE;
6807 if (h->call_fp_stub != NULL
6808 && h->root.other == STO_MIPS16)
6810 /* We don't need the call_stub; this is a 16 bit function, so
6811 calls from other 16 bit functions are OK. Clobber the size
6812 to 0 to prevent it from being included in the link. */
6813 h->call_fp_stub->_raw_size = 0;
6814 h->call_fp_stub->_cooked_size = 0;
6815 h->call_fp_stub->flags &= ~ SEC_RELOC;
6816 h->call_fp_stub->reloc_count = 0;
6817 h->call_fp_stub->flags |= SEC_EXCLUDE;
6823 /* Set the sizes of the dynamic sections. */
6826 mips_elf_size_dynamic_sections (output_bfd, info)
6828 struct bfd_link_info *info;
6834 struct mips_got_info *g;
6836 dynobj = elf_hash_table (info)->dynobj;
6837 BFD_ASSERT (dynobj != NULL);
6839 if (elf_hash_table (info)->dynamic_sections_created)
6841 /* Set the contents of the .interp section to the interpreter. */
6844 s = bfd_get_section_by_name (dynobj, ".interp");
6845 BFD_ASSERT (s != NULL);
6846 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
6847 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
6851 /* Recompute the size of .got for local entires (reserved and
6852 hipages) if needed. To estimate it, get the upper bound of total
6853 size of loadable sections. */
6854 sgot = bfd_get_section_by_name (dynobj, ".got");
6858 bfd_size_type loadable_size = 0;
6859 bfd_size_type local_gotno;
6862 BFD_ASSERT (elf_section_data (sgot) != NULL);
6863 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
6864 BFD_ASSERT (g != NULL);
6866 for (sub = info->input_bfds; sub; sub = sub->link_next)
6867 for (s = sub->sections; s != NULL; s = s->next)
6869 if ((s->flags & SEC_ALLOC) == 0)
6871 loadable_size += (s->_raw_size + 0xf) & ~0xf;
6874 loadable_size += MIPS_FUNCTION_STUB_SIZE;
6876 /* Assume there are two loadable segments consisting of
6877 contiguous sections. Is 5 enough? */
6878 local_gotno = (loadable_size >> 16) + 5 + MIPS_RESERVED_GOTNO;
6879 g->local_gotno = local_gotno;
6880 sgot->_raw_size += local_gotno * 4;
6883 /* The check_relocs and adjust_dynamic_symbol entry points have
6884 determined the sizes of the various dynamic sections. Allocate
6887 for (s = dynobj->sections; s != NULL; s = s->next)
6892 /* It's OK to base decisions on the section name, because none
6893 of the dynobj section names depend upon the input files. */
6894 name = bfd_get_section_name (dynobj, s);
6896 if ((s->flags & SEC_LINKER_CREATED) == 0)
6901 if (strncmp (name, ".rel", 4) == 0)
6903 if (s->_raw_size == 0)
6905 /* We only strip the section if the output section name
6906 has the same name. Otherwise, there might be several
6907 input sections for this output section. FIXME: This
6908 code is probably not needed these days anyhow, since
6909 the linker now does not create empty output sections. */
6910 if (s->output_section != NULL
6912 bfd_get_section_name (s->output_section->owner,
6913 s->output_section)) == 0)
6918 const char *outname;
6921 /* If this relocation section applies to a read only
6922 section, then we probably need a DT_TEXTREL entry.
6923 If the relocation section is .rel.dyn, we always
6924 assert a DT_TEXTREL entry rather than testing whether
6925 there exists a relocation to a read only section or
6927 outname = bfd_get_section_name (output_bfd,
6929 target = bfd_get_section_by_name (output_bfd, outname + 4);
6931 && (target->flags & SEC_READONLY) != 0
6932 && (target->flags & SEC_ALLOC) != 0)
6933 || strcmp (outname, ".rel.dyn") == 0)
6936 /* We use the reloc_count field as a counter if we need
6937 to copy relocs into the output file. */
6938 if (strcmp (name, ".rel.dyn") != 0)
6942 else if (strncmp (name, ".got", 4) == 0)
6946 BFD_ASSERT (elf_section_data (s) != NULL);
6947 g = (struct mips_got_info *) elf_section_data (s)->tdata;
6948 BFD_ASSERT (g != NULL);
6950 /* Fix the size of .got section for the correspondence of
6951 global symbols and got entries. This adds some useless
6952 got entries. Is this required by ABI really? */
6953 i = elf_hash_table (info)->dynsymcount - g->global_gotsym;
6954 s->_raw_size += i * 4;
6956 else if (strncmp (name, ".stub", 5) == 0)
6958 /* Irix rld assumes that the function stub isn't at the end
6959 of .text section. So put a dummy. XXX */
6960 s->_raw_size += MIPS_FUNCTION_STUB_SIZE;
6962 else if (! info->shared
6963 && ! mips_elf_hash_table (info)->use_rld_obj_head
6964 && strncmp (name, ".rld_map", 8) == 0)
6966 /* We add a room for __rld_map. It will be filled in by the
6967 rtld to contain a pointer to the _r_debug structure. */
6970 else if (SGI_COMPAT (output_bfd)
6971 && strncmp (name, ".compact_rel", 12) == 0)
6972 s->_raw_size += mips_elf_hash_table (info)->compact_rel_size;
6973 else if (strncmp (name, ".init", 5) != 0)
6975 /* It's not one of our sections, so don't allocate space. */
6983 for (spp = &s->output_section->owner->sections;
6984 *spp != s->output_section;
6985 spp = &(*spp)->next)
6987 *spp = s->output_section->next;
6988 --s->output_section->owner->section_count;
6993 /* Allocate memory for the section contents. */
6994 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
6995 if (s->contents == NULL && s->_raw_size != 0)
6997 bfd_set_error (bfd_error_no_memory);
7000 memset (s->contents, 0, s->_raw_size);
7003 if (elf_hash_table (info)->dynamic_sections_created)
7005 /* Add some entries to the .dynamic section. We fill in the
7006 values later, in elf_mips_finish_dynamic_sections, but we
7007 must add the entries now so that we get the correct size for
7008 the .dynamic section. The DT_DEBUG entry is filled in by the
7009 dynamic linker and used by the debugger. */
7012 if (SGI_COMPAT (output_bfd))
7014 /* SGI object has the equivalence of DT_DEBUG in the
7015 DT_MIPS_RLD_MAP entry. */
7016 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_RLD_MAP, 0))
7020 if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
7026 if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
7030 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0))
7033 if (bfd_get_section_by_name (dynobj, ".rel.dyn"))
7035 if (! bfd_elf32_add_dynamic_entry (info, DT_REL, 0))
7038 if (! bfd_elf32_add_dynamic_entry (info, DT_RELSZ, 0))
7041 if (! bfd_elf32_add_dynamic_entry (info, DT_RELENT, 0))
7045 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_CONFLICTNO, 0))
7048 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_LIBLISTNO, 0))
7051 if (bfd_get_section_by_name (dynobj, ".conflict") != NULL)
7053 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_CONFLICT, 0))
7056 s = bfd_get_section_by_name (dynobj, ".liblist");
7057 BFD_ASSERT (s != NULL);
7059 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_LIBLIST, 0))
7063 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_RLD_VERSION, 0))
7066 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_FLAGS, 0))
7070 /* Time stamps in executable files are a bad idea. */
7071 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_TIME_STAMP, 0))
7076 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_ICHECKSUM, 0))
7081 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_IVERSION, 0))
7085 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_BASE_ADDRESS, 0))
7088 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_LOCAL_GOTNO, 0))
7091 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_SYMTABNO, 0))
7094 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_UNREFEXTNO, 0))
7097 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_GOTSYM, 0))
7100 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_HIPAGENO, 0))
7103 #if 0 /* (SGI_COMPAT) */
7104 if (! bfd_get_section_by_name (dynobj, ".init"))
7105 if (! bfd_elf32_add_dynamic_entry (info, DT_INIT, 0))
7108 if (! bfd_get_section_by_name (dynobj, ".fini"))
7109 if (! bfd_elf32_add_dynamic_entry (info, DT_FINI, 0))
7114 /* If we use dynamic linking, we generate a section symbol for each
7115 output section. These are local symbols, which means that they
7116 must come first in the dynamic symbol table.
7117 That means we must increment the dynamic symbol index of every
7118 other dynamic symbol. */
7121 struct mips_got_info *g;
7124 if (elf_hash_table (info)->dynamic_sections_created)
7127 /* We no longer try to restrict the set of sections which get
7128 dynamic symbol table entries, since it fails if we have
7129 other random sections which need dynamic relocations. */
7130 const char * const *namep;
7131 bfd_size_type strindex;
7132 struct bfd_strtab_hash *dynstr;
7134 if (SGI_COMPAT (output_bfd))
7136 c = SIZEOF_MIPS_DYNSYM_SECNAMES - 1;
7137 elf_link_hash_traverse (elf_hash_table (info),
7138 mips_elf_adjust_dynindx,
7140 elf_hash_table (info)->dynsymcount += c;
7142 dynstr = elf_hash_table (info)->dynstr;
7143 BFD_ASSERT (dynstr != NULL);
7145 for (i = 1, namep = mips_elf_dynsym_sec_names;
7149 s = bfd_get_section_by_name (output_bfd, *namep);
7151 elf_section_data (s)->dynindx = i;
7153 strindex = _bfd_stringtab_add (dynstr, *namep, true, false);
7154 if (strindex == (bfd_size_type) -1)
7157 mips_elf_hash_table (info)->dynsym_sec_strindex[i] = strindex;
7163 c = bfd_count_sections (output_bfd);
7164 elf_link_hash_traverse (elf_hash_table (info),
7165 mips_elf_adjust_dynindx,
7167 elf_hash_table (info)->dynsymcount += c;
7169 for (i = 1, s = output_bfd->sections; s != NULL; s = s->next, i++)
7171 elf_section_data (s)->dynindx = i;
7172 /* These symbols will have no names, so we don't need to
7173 fiddle with dynstr_index. */
7180 BFD_ASSERT (elf_section_data (sgot) != NULL);
7181 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
7182 BFD_ASSERT (g != NULL);
7184 /* If there are no global got symbols, fake the last symbol so
7186 if (g->global_gotsym)
7187 g->global_gotsym += c;
7189 g->global_gotsym = elf_hash_table (info)->dynsymcount - 1;
7196 /* Increment the index of a dynamic symbol by a given amount. Called
7197 via elf_link_hash_traverse. */
7200 mips_elf_adjust_dynindx (h, cparg)
7201 struct elf_link_hash_entry *h;
7204 unsigned int *cp = (unsigned int *) cparg;
7206 if (h->dynindx != -1)
7211 /* Finish up dynamic symbol handling. We set the contents of various
7212 dynamic sections here. */
7215 mips_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
7217 struct bfd_link_info *info;
7218 struct elf_link_hash_entry *h;
7219 Elf_Internal_Sym *sym;
7224 struct mips_got_info *g;
7227 dynobj = elf_hash_table (info)->dynobj;
7228 gval = sym->st_value;
7230 if (h->plt.offset != (bfd_vma) -1)
7234 bfd_byte stub[MIPS_FUNCTION_STUB_SIZE];
7236 /* This symbol has a stub. Set it up. */
7238 BFD_ASSERT (h->dynindx != -1);
7240 s = bfd_get_section_by_name (dynobj, ".stub");
7241 BFD_ASSERT (s != NULL);
7243 /* Fill the stub. */
7245 bfd_put_32 (output_bfd, STUB_LW(output_bfd), p);
7247 bfd_put_32 (output_bfd, STUB_MOVE, p);
7250 /* FIXME: Can h->dynindex be more than 64K? */
7251 if (h->dynindx & 0xffff0000)
7254 bfd_put_32 (output_bfd, STUB_JALR, p);
7256 bfd_put_32 (output_bfd, STUB_LI16 + h->dynindx, p);
7258 BFD_ASSERT (h->plt.offset <= s->_raw_size);
7259 memcpy (s->contents + h->plt.offset, stub, MIPS_FUNCTION_STUB_SIZE);
7261 /* Mark the symbol as undefined. plt.offset != -1 occurs
7262 only for the referenced symbol. */
7263 sym->st_shndx = SHN_UNDEF;
7265 /* The run-time linker uses the st_value field of the symbol
7266 to reset the global offset table entry for this external
7267 to its stub address when unlinking a shared object. */
7268 gval = s->output_section->vma + s->output_offset + h->plt.offset;
7269 sym->st_value = gval;
7272 BFD_ASSERT (h->dynindx != -1);
7274 sgot = bfd_get_section_by_name (dynobj, ".got");
7275 BFD_ASSERT (sgot != NULL);
7276 BFD_ASSERT (elf_section_data (sgot) != NULL);
7277 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
7278 BFD_ASSERT (g != NULL);
7280 if ((unsigned long) h->dynindx >= g->global_gotsym)
7282 bfd_size_type offset;
7284 /* This symbol has an entry in the global offset table. Set its
7285 value to the corresponding got entry, if needed. */
7286 if (h->got.offset == (bfd_vma) -1)
7288 offset = (h->dynindx - g->global_gotsym + g->local_gotno) * 4;
7289 BFD_ASSERT (g->local_gotno * 4 <= offset
7290 && offset < sgot->_raw_size);
7291 bfd_put_32 (output_bfd, gval, sgot->contents + offset);
7295 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7296 name = h->root.root.string;
7297 if (strcmp (name, "_DYNAMIC") == 0
7298 || strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
7299 sym->st_shndx = SHN_ABS;
7300 else if (strcmp (name, "_DYNAMIC_LINK") == 0)
7302 sym->st_shndx = SHN_ABS;
7303 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
7306 else if (SGI_COMPAT (output_bfd))
7308 if (strcmp (name, "_gp_disp") == 0)
7310 sym->st_shndx = SHN_ABS;
7311 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
7312 sym->st_value = elf_gp (output_bfd);
7314 else if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0
7315 || strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0)
7317 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
7318 sym->st_other = STO_PROTECTED;
7320 sym->st_shndx = SHN_MIPS_DATA;
7322 else if (strcmp (name, mips_elf_dynsym_rtproc_names[2]) == 0)
7324 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
7325 sym->st_other = STO_PROTECTED;
7326 sym->st_value = mips_elf_hash_table (info)->procedure_count;
7327 sym->st_shndx = SHN_ABS;
7329 else if (sym->st_shndx != SHN_UNDEF && sym->st_shndx != SHN_ABS)
7331 if (h->type == STT_FUNC)
7332 sym->st_shndx = SHN_MIPS_TEXT;
7333 else if (h->type == STT_OBJECT)
7334 sym->st_shndx = SHN_MIPS_DATA;
7338 if (SGI_COMPAT (output_bfd)
7341 if (! mips_elf_hash_table (info)->use_rld_obj_head
7342 && strcmp (name, "__rld_map") == 0)
7344 asection *s = bfd_get_section_by_name (dynobj, ".rld_map");
7345 BFD_ASSERT (s != NULL);
7346 sym->st_value = s->output_section->vma + s->output_offset;
7347 bfd_put_32 (output_bfd, (bfd_vma) 0, s->contents);
7348 if (mips_elf_hash_table (info)->rld_value == 0)
7349 mips_elf_hash_table (info)->rld_value = sym->st_value;
7351 else if (mips_elf_hash_table (info)->use_rld_obj_head
7352 && strcmp (name, "__rld_obj_head") == 0)
7354 asection *s = bfd_get_section_by_name (dynobj, ".rld_map");
7355 BFD_ASSERT (s != NULL);
7356 mips_elf_hash_table (info)->rld_value = sym->st_value;
7360 /* If this is a mips16 symbol, force the value to be even. */
7361 if (sym->st_other == STO_MIPS16
7362 && (sym->st_value & 1) != 0)
7368 /* Finish up the dynamic sections. */
7371 mips_elf_finish_dynamic_sections (output_bfd, info)
7373 struct bfd_link_info *info;
7378 struct mips_got_info *g;
7380 dynobj = elf_hash_table (info)->dynobj;
7382 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
7384 sgot = bfd_get_section_by_name (dynobj, ".got");
7389 BFD_ASSERT (elf_section_data (sgot) != NULL);
7390 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
7391 BFD_ASSERT (g != NULL);
7394 if (elf_hash_table (info)->dynamic_sections_created)
7396 Elf32_External_Dyn *dyncon, *dynconend;
7398 BFD_ASSERT (sdyn != NULL);
7399 BFD_ASSERT (g != NULL);
7401 dyncon = (Elf32_External_Dyn *) sdyn->contents;
7402 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
7403 for (; dyncon < dynconend; dyncon++)
7405 Elf_Internal_Dyn dyn;
7410 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
7418 s = bfd_get_section_by_name (dynobj, ".rel.dyn");
7419 BFD_ASSERT (s != NULL);
7420 dyn.d_un.d_val = sizeof (Elf32_External_Rel);
7421 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7425 /* Rewrite DT_STRSZ. */
7427 _bfd_stringtab_size (elf_hash_table (info)->dynstr);
7428 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7434 case DT_MIPS_CONFLICT:
7437 case DT_MIPS_LIBLIST:
7440 s = bfd_get_section_by_name (output_bfd, name);
7441 BFD_ASSERT (s != NULL);
7442 dyn.d_un.d_ptr = s->vma;
7443 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7446 case DT_MIPS_RLD_VERSION:
7447 dyn.d_un.d_val = 1; /* XXX */
7448 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7452 dyn.d_un.d_val = RHF_NOTPOT; /* XXX */
7453 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7456 case DT_MIPS_CONFLICTNO:
7458 elemsize = sizeof (Elf32_Conflict);
7461 case DT_MIPS_LIBLISTNO:
7463 elemsize = sizeof (Elf32_Lib);
7465 s = bfd_get_section_by_name (output_bfd, name);
7468 if (s->_cooked_size != 0)
7469 dyn.d_un.d_val = s->_cooked_size / elemsize;
7471 dyn.d_un.d_val = s->_raw_size / elemsize;
7476 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7479 case DT_MIPS_TIME_STAMP:
7480 time ((time_t *) &dyn.d_un.d_val);
7481 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7484 case DT_MIPS_ICHECKSUM:
7488 case DT_MIPS_IVERSION:
7492 case DT_MIPS_BASE_ADDRESS:
7493 s = output_bfd->sections;
7494 BFD_ASSERT (s != NULL);
7495 dyn.d_un.d_ptr = s->vma & ~(0xffff);
7496 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7499 case DT_MIPS_LOCAL_GOTNO:
7500 dyn.d_un.d_val = g->local_gotno;
7501 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7504 case DT_MIPS_SYMTABNO:
7506 elemsize = sizeof (Elf32_External_Sym);
7507 s = bfd_get_section_by_name (output_bfd, name);
7508 BFD_ASSERT (s != NULL);
7510 if (s->_cooked_size != 0)
7511 dyn.d_un.d_val = s->_cooked_size / elemsize;
7513 dyn.d_un.d_val = s->_raw_size / elemsize;
7514 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7517 case DT_MIPS_UNREFEXTNO:
7519 dyn.d_un.d_val = SIZEOF_MIPS_DYNSYM_SECNAMES;
7521 dyn.d_un.d_val = bfd_count_sections (output_bfd);
7523 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7526 case DT_MIPS_GOTSYM:
7527 dyn.d_un.d_val = g->global_gotsym;
7528 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7531 case DT_MIPS_HIPAGENO:
7532 dyn.d_un.d_val = g->local_gotno - MIPS_RESERVED_GOTNO;
7533 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7536 case DT_MIPS_RLD_MAP:
7537 dyn.d_un.d_ptr = mips_elf_hash_table (info)->rld_value;
7538 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7545 /* The first entry of the global offset table will be filled at
7546 runtime. The second entry will be used by some runtime loaders.
7547 This isn't the case of Irix rld. */
7548 if (sgot != NULL && sgot->_raw_size > 0)
7550 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
7551 bfd_put_32 (output_bfd, (bfd_vma) 0x80000000, sgot->contents + 4);
7555 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
7560 Elf_Internal_Sym sym;
7561 Elf32_compact_rel cpt;
7563 /* Set up the section symbols for the output sections. SGI sets
7564 the STT_NOTYPE attribute for these symbols. Should we do so? */
7566 sdynsym = bfd_get_section_by_name (dynobj, ".dynsym");
7567 if (sdynsym != NULL)
7571 const char * const * namep = mips_elf_dynsym_sec_names;
7576 /* We no longer try to restrict the set of sections which get
7577 dynamic symbol table entries, since it fails if we have
7578 other random sections which need dynamic relocations. */
7579 if (SGI_COMPAT (output_bfd))
7583 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
7589 while ((name = *namep++) != NULL)
7591 s = bfd_get_section_by_name (output_bfd, name);
7594 sym.st_value = s->vma;
7595 dindx = elf_section_data (s)->dynindx;
7596 last = s->vma + s->_raw_size;
7600 sym.st_value = last;
7604 sym.st_shndx = (i < MIPS_TEXT_DYNSYM_SECNO
7609 mips_elf_hash_table (info)->dynsym_sec_strindex[dindx];
7611 bfd_elf32_swap_symbol_out (output_bfd, &sym,
7612 (((Elf32_External_Sym *)
7617 /* Set the sh_info field of the output .dynsym section to
7618 the index of the first global symbol. */
7619 elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
7620 SIZEOF_MIPS_DYNSYM_SECNAMES;
7627 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
7630 for (s = output_bfd->sections; s != NULL; s = s->next)
7634 sym.st_value = s->vma;
7636 indx = elf_section_data (s)->this_idx;
7637 BFD_ASSERT (indx > 0);
7638 sym.st_shndx = indx;
7640 bfd_elf32_swap_symbol_out (output_bfd, &sym,
7641 (((Elf32_External_Sym *)
7643 + elf_section_data (s)->dynindx));
7646 /* Set the sh_info field of the output .dynsym section to
7647 the index of the first global symbol. */
7648 elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
7649 bfd_count_sections (output_bfd) + 1;
7653 if (SGI_COMPAT (output_bfd))
7655 /* Write .compact_rel section out. */
7656 s = bfd_get_section_by_name (dynobj, ".compact_rel");
7660 cpt.num = s->reloc_count;
7662 cpt.offset = (s->output_section->filepos
7663 + sizeof (Elf32_External_compact_rel));
7666 bfd_elf32_swap_compact_rel_out (output_bfd, &cpt,
7667 ((Elf32_External_compact_rel *)
7670 /* Clean up a dummy stub function entry in .text. */
7671 s = bfd_get_section_by_name (dynobj, ".stub");
7674 file_ptr dummy_offset;
7676 BFD_ASSERT (s->_raw_size >= MIPS_FUNCTION_STUB_SIZE);
7677 dummy_offset = s->_raw_size - MIPS_FUNCTION_STUB_SIZE;
7678 memset (s->contents + dummy_offset, 0,
7679 MIPS_FUNCTION_STUB_SIZE);
7684 /* Clean up a first relocation in .rel.dyn. */
7685 s = bfd_get_section_by_name (dynobj, ".rel.dyn");
7686 if (s != NULL && s->_raw_size > 0)
7687 memset (s->contents, 0, sizeof (Elf32_External_Rel));
7693 /* This is almost identical to bfd_generic_get_... except that some
7694 MIPS relocations need to be handled specially. Sigh. */
7697 elf32_mips_get_relocated_section_contents (abfd, link_info, link_order, data,
7698 relocateable, symbols)
7700 struct bfd_link_info *link_info;
7701 struct bfd_link_order *link_order;
7703 boolean relocateable;
7706 /* Get enough memory to hold the stuff */
7707 bfd *input_bfd = link_order->u.indirect.section->owner;
7708 asection *input_section = link_order->u.indirect.section;
7710 long reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section);
7711 arelent **reloc_vector = NULL;
7717 reloc_vector = (arelent **) bfd_malloc (reloc_size);
7718 if (reloc_vector == NULL && reloc_size != 0)
7721 /* read in the section */
7722 if (!bfd_get_section_contents (input_bfd,
7726 input_section->_raw_size))
7729 /* We're not relaxing the section, so just copy the size info */
7730 input_section->_cooked_size = input_section->_raw_size;
7731 input_section->reloc_done = true;
7733 reloc_count = bfd_canonicalize_reloc (input_bfd,
7737 if (reloc_count < 0)
7740 if (reloc_count > 0)
7745 bfd_vma gp = 0x12345678; /* initialize just to shut gcc up */
7748 struct bfd_hash_entry *h;
7749 struct bfd_link_hash_entry *lh;
7750 /* Skip all this stuff if we aren't mixing formats. */
7751 if (abfd && input_bfd
7752 && abfd->xvec == input_bfd->xvec)
7756 h = bfd_hash_lookup (&link_info->hash->table, "_gp", false, false);
7757 lh = (struct bfd_link_hash_entry *) h;
7764 case bfd_link_hash_undefined:
7765 case bfd_link_hash_undefweak:
7766 case bfd_link_hash_common:
7769 case bfd_link_hash_defined:
7770 case bfd_link_hash_defweak:
7772 gp = lh->u.def.value;
7774 case bfd_link_hash_indirect:
7775 case bfd_link_hash_warning:
7777 /* @@FIXME ignoring warning for now */
7779 case bfd_link_hash_new:
7788 for (parent = reloc_vector; *parent != (arelent *) NULL;
7791 char *error_message = (char *) NULL;
7792 bfd_reloc_status_type r;
7794 /* Specific to MIPS: Deal with relocation types that require
7795 knowing the gp of the output bfd. */
7796 asymbol *sym = *(*parent)->sym_ptr_ptr;
7797 if (bfd_is_abs_section (sym->section) && abfd)
7799 /* The special_function wouldn't get called anyways. */
7803 /* The gp isn't there; let the special function code
7804 fall over on its own. */
7806 else if ((*parent)->howto->special_function
7807 == _bfd_mips_elf_gprel16_reloc)
7809 /* bypass special_function call */
7810 r = gprel16_with_gp (input_bfd, sym, *parent, input_section,
7811 relocateable, (PTR) data, gp);
7812 goto skip_bfd_perform_relocation;
7814 /* end mips specific stuff */
7816 r = bfd_perform_relocation (input_bfd,
7820 relocateable ? abfd : (bfd *) NULL,
7822 skip_bfd_perform_relocation:
7826 asection *os = input_section->output_section;
7828 /* A partial link, so keep the relocs */
7829 os->orelocation[os->reloc_count] = *parent;
7833 if (r != bfd_reloc_ok)
7837 case bfd_reloc_undefined:
7838 if (!((*link_info->callbacks->undefined_symbol)
7839 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
7840 input_bfd, input_section, (*parent)->address)))
7843 case bfd_reloc_dangerous:
7844 BFD_ASSERT (error_message != (char *) NULL);
7845 if (!((*link_info->callbacks->reloc_dangerous)
7846 (link_info, error_message, input_bfd, input_section,
7847 (*parent)->address)))
7850 case bfd_reloc_overflow:
7851 if (!((*link_info->callbacks->reloc_overflow)
7852 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
7853 (*parent)->howto->name, (*parent)->addend,
7854 input_bfd, input_section, (*parent)->address)))
7857 case bfd_reloc_outofrange:
7866 if (reloc_vector != NULL)
7867 free (reloc_vector);
7871 if (reloc_vector != NULL)
7872 free (reloc_vector);
7875 #define bfd_elf32_bfd_get_relocated_section_contents \
7876 elf32_mips_get_relocated_section_contents
7878 /* ECOFF swapping routines. These are used when dealing with the
7879 .mdebug section, which is in the ECOFF debugging format. */
7880 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap =
7882 /* Symbol table magic number. */
7884 /* Alignment of debugging information. E.g., 4. */
7886 /* Sizes of external symbolic information. */
7887 sizeof (struct hdr_ext),
7888 sizeof (struct dnr_ext),
7889 sizeof (struct pdr_ext),
7890 sizeof (struct sym_ext),
7891 sizeof (struct opt_ext),
7892 sizeof (struct fdr_ext),
7893 sizeof (struct rfd_ext),
7894 sizeof (struct ext_ext),
7895 /* Functions to swap in external symbolic data. */
7904 _bfd_ecoff_swap_tir_in,
7905 _bfd_ecoff_swap_rndx_in,
7906 /* Functions to swap out external symbolic data. */
7915 _bfd_ecoff_swap_tir_out,
7916 _bfd_ecoff_swap_rndx_out,
7917 /* Function to read in symbolic data. */
7918 _bfd_mips_elf_read_ecoff_info
7921 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
7922 #define TARGET_LITTLE_NAME "elf32-littlemips"
7923 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
7924 #define TARGET_BIG_NAME "elf32-bigmips"
7925 #define ELF_ARCH bfd_arch_mips
7926 #define ELF_MACHINE_CODE EM_MIPS
7928 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
7929 a value of 0x1000, and we are compatible. */
7930 #define ELF_MAXPAGESIZE 0x1000
7932 #define elf_backend_collect true
7933 #define elf_backend_type_change_ok true
7934 #define elf_backend_can_gc_sections true
7935 #define elf_info_to_howto 0
7936 #define elf_info_to_howto_rel mips_info_to_howto_rel
7937 #define elf_backend_sym_is_global mips_elf_sym_is_global
7938 #define elf_backend_object_p mips_elf32_object_p
7939 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
7940 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
7941 #define elf_backend_section_from_bfd_section \
7942 _bfd_mips_elf_section_from_bfd_section
7943 #define elf_backend_section_processing mips_elf32_section_processing
7944 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
7945 #define elf_backend_additional_program_headers \
7946 mips_elf_additional_program_headers
7947 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
7948 #define elf_backend_final_write_processing \
7949 _bfd_mips_elf_final_write_processing
7950 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
7952 #define bfd_elf32_bfd_is_local_label_name \
7953 mips_elf_is_local_label_name
7954 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
7955 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
7956 #define bfd_elf32_bfd_link_hash_table_create \
7957 mips_elf_link_hash_table_create
7958 #define bfd_elf32_bfd_final_link mips_elf_final_link
7959 #define bfd_elf32_bfd_copy_private_bfd_data \
7960 _bfd_mips_elf_copy_private_bfd_data
7961 #define bfd_elf32_bfd_merge_private_bfd_data \
7962 _bfd_mips_elf_merge_private_bfd_data
7963 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
7964 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
7965 #define elf_backend_create_dynamic_sections \
7966 mips_elf_create_dynamic_sections
7967 #define elf_backend_check_relocs mips_elf_check_relocs
7968 #define elf_backend_adjust_dynamic_symbol \
7969 mips_elf_adjust_dynamic_symbol
7970 #define elf_backend_always_size_sections \
7971 mips_elf_always_size_sections
7972 #define elf_backend_size_dynamic_sections \
7973 mips_elf_size_dynamic_sections
7974 #define elf_backend_relocate_section mips_elf_relocate_section
7975 #define elf_backend_link_output_symbol_hook \
7976 mips_elf_link_output_symbol_hook
7977 #define elf_backend_finish_dynamic_symbol \
7978 mips_elf_finish_dynamic_symbol
7979 #define elf_backend_finish_dynamic_sections \
7980 mips_elf_finish_dynamic_sections
7981 #define elf_backend_gc_mark_hook mips_elf_gc_mark_hook
7982 #define elf_backend_gc_sweep_hook mips_elf_gc_sweep_hook
7984 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
7985 #define elf_backend_plt_header_size 0
7987 #include "elf32-target.h"