1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
4 Most of the information added by Ian Lance Taylor, Cygnus Support,
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 /* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
24 different MIPS ELF from other targets. This matters when linking.
25 This file supports both, switching at runtime. */
35 /* Get the ECOFF swapping routines. */
37 #include "coff/symconst.h"
38 #include "coff/internal.h"
39 #include "coff/ecoff.h"
40 #include "coff/mips.h"
42 #include "ecoffswap.h"
44 static bfd_reloc_status_type mips_elf_hi16_reloc PARAMS ((bfd *abfd,
51 static bfd_reloc_status_type mips_elf_got16_reloc PARAMS ((bfd *abfd,
58 static bfd_reloc_status_type mips_elf_lo16_reloc PARAMS ((bfd *abfd,
65 static bfd_reloc_status_type mips_elf_gprel16_reloc PARAMS ((bfd *abfd,
72 static bfd_reloc_status_type mips_elf_gprel32_reloc PARAMS ((bfd *abfd,
79 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
80 PARAMS ((bfd *, bfd_reloc_code_real_type));
81 static void mips_info_to_howto_rel
82 PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
83 static boolean mips_elf_sym_is_global PARAMS ((bfd *, asymbol *));
84 static boolean mips_elf_object_p PARAMS ((bfd *));
85 static boolean mips_elf_create_procedure_table
86 PARAMS ((PTR, bfd *, struct bfd_link_info *, asection *,
87 struct ecoff_debug_info *));
88 static int mips_elf_additional_program_headers PARAMS ((bfd *));
89 static boolean mips_elf_modify_segment_map PARAMS ((bfd *));
90 static void mips_elf_final_write_processing
91 PARAMS ((bfd *, boolean));
92 static boolean mips_elf_section_from_shdr
93 PARAMS ((bfd *, Elf32_Internal_Shdr *, char *));
94 static boolean mips_elf_fake_sections
95 PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *));
96 static boolean mips_elf_section_from_bfd_section
97 PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *, int *));
98 static boolean mips_elf_section_processing
99 PARAMS ((bfd *, Elf32_Internal_Shdr *));
100 static void mips_elf_symbol_processing PARAMS ((bfd *, asymbol *));
101 static boolean mips_elf_read_ecoff_info
102 PARAMS ((bfd *, asection *, struct ecoff_debug_info *));
103 static boolean mips_elf_is_local_label
104 PARAMS ((bfd *, asymbol *));
105 static boolean mips_elf_find_nearest_line
106 PARAMS ((bfd *, asection *, asymbol **, bfd_vma, const char **,
107 const char **, unsigned int *));
108 static struct bfd_hash_entry *mips_elf_link_hash_newfunc
109 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
110 static struct bfd_link_hash_table *mips_elf_link_hash_table_create
112 static int gptab_compare PARAMS ((const void *, const void *));
113 static boolean mips_elf_final_link
114 PARAMS ((bfd *, struct bfd_link_info *));
115 static void mips_elf_relocate_hi16
116 PARAMS ((bfd *, Elf_Internal_Rela *, Elf_Internal_Rela *, bfd_byte *,
118 static void mips_elf_relocate_got_local
119 PARAMS ((bfd *, bfd *, asection *, Elf_Internal_Rela *,
120 Elf_Internal_Rela *, bfd_byte *, bfd_vma));
121 static void mips_elf_relocate_global_got
122 PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
123 static boolean mips_elf_adjust_dynindx
124 PARAMS ((struct elf_link_hash_entry *, PTR));
125 static boolean mips_elf_relocate_section
126 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
127 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
128 static boolean mips_elf_add_symbol_hook
129 PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
130 const char **, flagword *, asection **, bfd_vma *));
131 static bfd_reloc_status_type mips_elf_final_gp
132 PARAMS ((bfd *, asymbol *, boolean, char **));
134 /* This is true for Irix 5 executables, false for normal MIPS ELF ABI
135 executables. FIXME: At the moment, we default to always generating
136 Irix 5 executables. */
138 #define SGI_COMPAT(abfd) (1)
140 /* This structure is used to hold .got information when linking. It
141 is stored in the tdata field of the bfd_elf_section_data structure. */
145 /* The symbol index of the first global .got symbol. */
146 unsigned long global_gotsym;
147 /* The number of local .got entries. */
148 unsigned int local_gotno;
151 /* The number of local .got entries we reserve. */
152 #define MIPS_RESERVED_GOTNO (2)
154 /* Instructions which appear in a stub. For some reason the stub is
155 slightly different on an SGI system. */
156 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
157 #define STUB_LW(abfd) \
159 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
160 : 0x8f998000) /* lw t9,0x8000(gp) */
161 #define STUB_MOVE 0x03e07825 /* move t7,ra */
162 #define STUB_JALR 0x0320f809 /* jal t9 */
163 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
164 #define MIPS_FUNCTION_STUB_SIZE (16)
166 /* Names of sections which appear in the .dynsym section in an Irix 5
169 static const char * const mips_elf_dynsym_sec_names[] =
182 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
183 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
185 /* The number of entries in mips_elf_dynsym_sec_names which go in the
188 #define MIPS_TEXT_DYNSYM_SECNO (3)
190 /* The names of the runtime procedure table symbols used on Irix 5. */
192 static const char * const mips_elf_dynsym_rtproc_names[] =
195 "_procedure_string_table",
196 "_procedure_table_size",
200 /* These structures are used to generate the .compact_rel section on
205 unsigned long id1; /* Always one? */
206 unsigned long num; /* Number of compact relocation entries. */
207 unsigned long id2; /* Always two? */
208 unsigned long offset; /* The file offset of the first relocation. */
209 unsigned long reserved0; /* Zero? */
210 unsigned long reserved1; /* Zero? */
219 bfd_byte reserved0[4];
220 bfd_byte reserved1[4];
221 } Elf32_External_compact_rel;
225 unsigned int ctype : 1; /* 1: long 0: short format. See below. */
226 unsigned int rtype : 4; /* Relocation types. See below. */
227 unsigned int dist2to : 8;
228 unsigned int relvaddr : 19; /* (VADDR - vaddr of the previous entry)/ 4 */
229 unsigned long konst; /* KONST field. See below. */
230 unsigned long vaddr; /* VADDR to be relocated. */
235 unsigned int ctype : 1; /* 1: long 0: short format. See below. */
236 unsigned int rtype : 4; /* Relocation types. See below. */
237 unsigned int dist2to : 8;
238 unsigned int relvaddr : 19; /* (VADDR - vaddr of the previous entry)/ 4 */
239 unsigned long konst; /* KONST field. See below. */
247 } Elf32_External_crinfo;
253 } Elf32_External_crinfo2;
255 /* These are the constants used to swap the bitfields in a crinfo. */
257 #define CRINFO_CTYPE (0x1)
258 #define CRINFO_CTYPE_SH (31)
259 #define CRINFO_RTYPE (0xf)
260 #define CRINFO_RTYPE_SH (27)
261 #define CRINFO_DIST2TO (0xff)
262 #define CRINFO_DIST2TO_SH (19)
263 #define CRINFO_RELVADDR (0x7ffff)
264 #define CRINFO_RELVADDR_SH (0)
266 /* A compact relocation info has long (3 words) or short (2 words)
267 formats. A short format doesn't have VADDR field and relvaddr
268 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
269 #define CRF_MIPS_LONG 1
270 #define CRF_MIPS_SHORT 0
272 /* There are 4 types of compact relocation at least. The value KONST
273 has different meaning for each type:
276 CT_MIPS_REL32 Address in data
277 CT_MIPS_WORD Address in word (XXX)
278 CT_MIPS_GPHI_LO GP - vaddr
279 CT_MIPS_JMPAD Address to jump
282 #define CRT_MIPS_REL32 0xa
283 #define CRT_MIPS_WORD 0xb
284 #define CRT_MIPS_GPHI_LO 0xc
285 #define CRT_MIPS_JMPAD 0xd
287 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
288 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
289 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
290 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
292 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
297 R_MIPS_16, R_MIPS_32,
298 R_MIPS_REL32, R_MIPS_26,
299 R_MIPS_HI16, R_MIPS_LO16,
300 R_MIPS_GPREL16, R_MIPS_LITERAL,
301 R_MIPS_GOT16, R_MIPS_PC16,
302 R_MIPS_CALL16, R_MIPS_GPREL32,
303 /* The remaining relocs are defined on Irix, although they are not
304 in the MIPS ELF ABI. */
305 R_MIPS_UNUSED1, R_MIPS_UNUSED2,
307 R_MIPS_SHIFT5, R_MIPS_SHIFT6,
308 R_MIPS_64, R_MIPS_GOT_DISP,
309 R_MIPS_GOT_PAGE, R_MIPS_GOT_OFST,
310 R_MIPS_GOT_HI16, R_MIPS_GOT_LO16,
311 R_MIPS_SUB, R_MIPS_INSERT_A,
312 R_MIPS_INSERT_B, R_MIPS_DELETE,
313 R_MIPS_HIGHER, R_MIPS_HIGHEST,
314 R_MIPS_CALL_HI16, R_MIPS_CALL_LO16,
318 static reloc_howto_type elf_mips_howto_table[] =
321 HOWTO (R_MIPS_NONE, /* type */
323 0, /* size (0 = byte, 1 = short, 2 = long) */
325 false, /* pc_relative */
327 complain_overflow_dont, /* complain_on_overflow */
328 bfd_elf_generic_reloc, /* special_function */
329 "R_MIPS_NONE", /* name */
330 false, /* partial_inplace */
333 false), /* pcrel_offset */
335 /* 16 bit relocation. */
336 HOWTO (R_MIPS_16, /* type */
338 1, /* 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_16", /* name */
345 true, /* partial_inplace */
346 0xffff, /* src_mask */
347 0xffff, /* dst_mask */
348 false), /* pcrel_offset */
350 /* 32 bit relocation. */
351 HOWTO (R_MIPS_32, /* 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_32", /* name */
360 true, /* partial_inplace */
361 0xffffffff, /* src_mask */
362 0xffffffff, /* dst_mask */
363 false), /* pcrel_offset */
365 /* 32 bit symbol relative relocation. */
366 HOWTO (R_MIPS_REL32, /* type */
368 2, /* size (0 = byte, 1 = short, 2 = long) */
370 false, /* pc_relative */
372 complain_overflow_bitfield, /* complain_on_overflow */
373 bfd_elf_generic_reloc, /* special_function */
374 "R_MIPS_REL32", /* name */
375 true, /* partial_inplace */
376 0xffffffff, /* src_mask */
377 0xffffffff, /* dst_mask */
378 false), /* pcrel_offset */
380 /* 26 bit branch address. */
381 HOWTO (R_MIPS_26, /* type */
383 2, /* size (0 = byte, 1 = short, 2 = long) */
385 false, /* pc_relative */
387 complain_overflow_dont, /* complain_on_overflow */
388 /* This needs complex overflow
389 detection, because the upper four
390 bits must match the PC. */
391 bfd_elf_generic_reloc, /* special_function */
392 "R_MIPS_26", /* name */
393 true, /* partial_inplace */
394 0x3ffffff, /* src_mask */
395 0x3ffffff, /* dst_mask */
396 false), /* pcrel_offset */
398 /* High 16 bits of symbol value. */
399 HOWTO (R_MIPS_HI16, /* type */
401 2, /* size (0 = byte, 1 = short, 2 = long) */
403 false, /* pc_relative */
405 complain_overflow_dont, /* complain_on_overflow */
406 mips_elf_hi16_reloc, /* special_function */
407 "R_MIPS_HI16", /* name */
408 true, /* partial_inplace */
409 0xffff, /* src_mask */
410 0xffff, /* dst_mask */
411 false), /* pcrel_offset */
413 /* Low 16 bits of symbol value. */
414 HOWTO (R_MIPS_LO16, /* type */
416 2, /* size (0 = byte, 1 = short, 2 = long) */
418 false, /* pc_relative */
420 complain_overflow_dont, /* complain_on_overflow */
421 mips_elf_lo16_reloc, /* special_function */
422 "R_MIPS_LO16", /* name */
423 true, /* partial_inplace */
424 0xffff, /* src_mask */
425 0xffff, /* dst_mask */
426 false), /* pcrel_offset */
428 /* GP relative reference. */
429 HOWTO (R_MIPS_GPREL16, /* type */
431 2, /* size (0 = byte, 1 = short, 2 = long) */
433 false, /* pc_relative */
435 complain_overflow_signed, /* complain_on_overflow */
436 mips_elf_gprel16_reloc, /* special_function */
437 "R_MIPS_GPREL16", /* name */
438 true, /* partial_inplace */
439 0xffff, /* src_mask */
440 0xffff, /* dst_mask */
441 false), /* pcrel_offset */
443 /* Reference to literal section. */
444 HOWTO (R_MIPS_LITERAL, /* type */
446 2, /* size (0 = byte, 1 = short, 2 = long) */
448 false, /* pc_relative */
450 complain_overflow_signed, /* complain_on_overflow */
451 mips_elf_gprel16_reloc, /* special_function */
452 "R_MIPS_LITERAL", /* name */
453 true, /* partial_inplace */
454 0xffff, /* src_mask */
455 0xffff, /* dst_mask */
456 false), /* pcrel_offset */
458 /* Reference to global offset table. */
459 HOWTO (R_MIPS_GOT16, /* type */
461 2, /* size (0 = byte, 1 = short, 2 = long) */
463 false, /* pc_relative */
465 complain_overflow_signed, /* complain_on_overflow */
466 mips_elf_got16_reloc, /* special_function */
467 "R_MIPS_GOT16", /* name */
468 false, /* partial_inplace */
470 0xffff, /* dst_mask */
471 false), /* pcrel_offset */
473 /* 16 bit PC relative reference. */
474 HOWTO (R_MIPS_PC16, /* type */
476 2, /* size (0 = byte, 1 = short, 2 = long) */
478 true, /* pc_relative */
480 complain_overflow_signed, /* complain_on_overflow */
481 bfd_elf_generic_reloc, /* special_function */
482 "R_MIPS_PC16", /* name */
483 true, /* partial_inplace */
484 0xffff, /* src_mask */
485 0xffff, /* dst_mask */
486 false), /* pcrel_offset */
488 /* 16 bit call through global offset table. */
489 /* FIXME: This is not handled correctly. */
490 HOWTO (R_MIPS_CALL16, /* type */
492 2, /* size (0 = byte, 1 = short, 2 = long) */
494 false, /* pc_relative */
496 complain_overflow_signed, /* complain_on_overflow */
497 bfd_elf_generic_reloc, /* special_function */
498 "R_MIPS_CALL16", /* name */
499 false, /* partial_inplace */
501 0xffff, /* dst_mask */
502 false), /* pcrel_offset */
504 /* 32 bit GP relative reference. */
505 HOWTO (R_MIPS_GPREL32, /* type */
507 2, /* size (0 = byte, 1 = short, 2 = long) */
509 false, /* pc_relative */
511 complain_overflow_bitfield, /* complain_on_overflow */
512 mips_elf_gprel32_reloc, /* special_function */
513 "R_MIPS_GPREL32", /* name */
514 true, /* partial_inplace */
515 0xffffffff, /* src_mask */
516 0xffffffff, /* dst_mask */
517 false), /* pcrel_offset */
519 /* The remaining relocs are defined on Irix 5, although they are
520 not defined by the ABI. */
525 /* A 5 bit shift field. */
526 HOWTO (R_MIPS_SHIFT5, /* type */
528 2, /* size (0 = byte, 1 = short, 2 = long) */
530 false, /* pc_relative */
532 complain_overflow_bitfield, /* complain_on_overflow */
533 bfd_elf_generic_reloc, /* special_function */
534 "R_MIPS_SHIFT5", /* name */
535 true, /* partial_inplace */
536 0x000007c0, /* src_mask */
537 0x000007c0, /* dst_mask */
538 false), /* pcrel_offset */
540 /* A 6 bit shift field. */
541 /* FIXME: This is not handled correctly; a special function is
542 needed to put the most significant bit in the right place. */
543 HOWTO (R_MIPS_SHIFT6, /* type */
545 2, /* size (0 = byte, 1 = short, 2 = long) */
547 false, /* pc_relative */
549 complain_overflow_bitfield, /* complain_on_overflow */
550 bfd_elf_generic_reloc, /* special_function */
551 "R_MIPS_SHIFT6", /* name */
552 true, /* partial_inplace */
553 0x000007c4, /* src_mask */
554 0x000007c4, /* dst_mask */
555 false), /* pcrel_offset */
557 /* A 64 bit relocation. Presumably not used in 32 bit ELF. */
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 */
686 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
687 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
688 the HI16. Here we just save the information we need; we do the
689 actual relocation when we see the LO16. MIPS ELF requires that the
690 LO16 immediately follow the HI16, so this ought to work. */
692 static bfd_byte *mips_hi16_addr;
693 static bfd_vma mips_hi16_addend;
695 static bfd_reloc_status_type
696 mips_elf_hi16_reloc (abfd,
704 arelent *reloc_entry;
707 asection *input_section;
709 char **error_message;
711 bfd_reloc_status_type ret;
714 /* If we're relocating, and this an external symbol, we don't want
715 to change anything. */
716 if (output_bfd != (bfd *) NULL
717 && (symbol->flags & BSF_SECTION_SYM) == 0
718 && reloc_entry->addend == 0)
720 reloc_entry->address += input_section->output_offset;
726 if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
728 boolean relocateable;
730 if (ret == bfd_reloc_undefined)
733 if (output_bfd != NULL)
737 relocateable = false;
738 output_bfd = symbol->section->output_section->owner;
741 ret = mips_elf_final_gp (output_bfd, symbol, relocateable,
743 if (ret != bfd_reloc_ok)
746 relocation = elf_gp (output_bfd) - reloc_entry->address;
750 if (bfd_is_und_section (symbol->section)
751 && output_bfd == (bfd *) NULL)
752 ret = bfd_reloc_undefined;
754 if (bfd_is_com_section (symbol->section))
757 relocation = symbol->value;
760 relocation += symbol->section->output_section->vma;
761 relocation += symbol->section->output_offset;
762 relocation += reloc_entry->addend;
764 if (reloc_entry->address > input_section->_cooked_size)
765 return bfd_reloc_outofrange;
767 /* Save the information, and let LO16 do the actual relocation. */
768 mips_hi16_addr = (bfd_byte *) data + reloc_entry->address;
769 mips_hi16_addend = relocation;
771 if (output_bfd != (bfd *) NULL)
772 reloc_entry->address += input_section->output_offset;
777 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
778 inplace relocation; this function exists in order to do the
779 R_MIPS_HI16 relocation described above. */
781 static bfd_reloc_status_type
782 mips_elf_lo16_reloc (abfd,
790 arelent *reloc_entry;
793 asection *input_section;
795 char **error_message;
797 arelent gp_disp_relent;
799 if (mips_hi16_addr != (bfd_byte *) NULL)
805 /* Do the HI16 relocation. Note that we actually don't need to
806 know anything about the LO16 itself, except where to find the
807 low 16 bits of the addend needed by the LO16. */
808 insn = bfd_get_32 (abfd, mips_hi16_addr);
809 vallo = (bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address)
811 val = ((insn & 0xffff) << 16) + vallo;
812 val += mips_hi16_addend;
814 /* The low order 16 bits are always treated as a signed value.
815 Therefore, a negative value in the low order bits requires an
816 adjustment in the high order bits. We need to make this
817 adjustment in two ways: once for the bits we took from the
818 data, and once for the bits we are putting back in to the
820 if ((vallo & 0x8000) != 0)
822 if ((val & 0x8000) != 0)
825 insn = (insn &~ 0xffff) | ((val >> 16) & 0xffff);
826 bfd_put_32 (abfd, insn, mips_hi16_addr);
828 mips_hi16_addr = (bfd_byte *) NULL;
830 if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
832 gp_disp_relent = *reloc_entry;
833 reloc_entry = &gp_disp_relent;
834 reloc_entry->addend = mips_hi16_addend;
837 else if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
839 bfd_reloc_status_type ret;
842 /* FIXME: Does this case ever occur? */
844 ret = mips_elf_final_gp (output_bfd, symbol, true, error_message);
845 if (ret != bfd_reloc_ok)
848 relocation = elf_gp (output_bfd) - reloc_entry->address;
849 relocation += symbol->section->output_section->vma;
850 relocation += symbol->section->output_offset;
851 relocation += reloc_entry->addend;
853 if (reloc_entry->address > input_section->_cooked_size)
854 return bfd_reloc_outofrange;
856 gp_disp_relent = *reloc_entry;
857 reloc_entry = &gp_disp_relent;
858 reloc_entry->addend = relocation - 4;
861 /* Now do the LO16 reloc in the usual way. */
862 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
863 input_section, output_bfd, error_message);
866 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
867 table used for PIC code. If the symbol is an external symbol, the
868 instruction is modified to contain the offset of the appropriate
869 entry in the global offset table. If the symbol is a section
870 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
871 addends are combined to form the real addend against the section
872 symbol; the GOT16 is modified to contain the offset of an entry in
873 the global offset table, and the LO16 is modified to offset it
874 appropriately. Thus an offset larger than 16 bits requires a
875 modified value in the global offset table.
877 This implementation suffices for the assembler, but the linker does
878 not yet know how to create global offset tables. */
880 static bfd_reloc_status_type
881 mips_elf_got16_reloc (abfd,
889 arelent *reloc_entry;
892 asection *input_section;
894 char **error_message;
896 /* If we're relocating, and this an external symbol, we don't want
897 to change anything. */
898 if (output_bfd != (bfd *) NULL
899 && (symbol->flags & BSF_SECTION_SYM) == 0
900 && reloc_entry->addend == 0)
902 reloc_entry->address += input_section->output_offset;
906 /* If we're relocating, and this is a local symbol, we can handle it
908 if (output_bfd != (bfd *) NULL
909 && (symbol->flags & BSF_SECTION_SYM) != 0)
910 return mips_elf_hi16_reloc (abfd, reloc_entry, symbol, data,
911 input_section, output_bfd, error_message);
916 /* We have to figure out the gp value, so that we can adjust the
917 symbol value correctly. We look up the symbol _gp in the output
918 BFD. If we can't find it, we're stuck. We cache it in the ELF
919 target data. We don't need to adjust the symbol value for an
920 external symbol if we are producing relocateable output. */
922 static bfd_reloc_status_type
923 mips_elf_final_gp (output_bfd, symbol, relocateable, error_message)
926 boolean relocateable;
927 char **error_message;
929 if (bfd_is_und_section (symbol->section)
931 return bfd_reloc_undefined;
933 /* This doesn't work if the BFD is not ELF. */
934 if (output_bfd->xvec->flavour != bfd_target_elf_flavour)
937 if (elf_gp (output_bfd) == 0
939 || (symbol->flags & BSF_SECTION_SYM) != 0))
943 /* Make up a value. */
944 elf_gp (output_bfd) =
945 symbol->section->output_section->vma + 0x4000;
953 count = bfd_get_symcount (output_bfd);
954 sym = bfd_get_outsymbols (output_bfd);
956 if (sym == (asymbol **) NULL)
960 for (i = 0; i < count; i++, sym++)
962 register CONST char *name;
964 name = bfd_asymbol_name (*sym);
965 if (*name == '_' && strcmp (name, "_gp") == 0)
967 elf_gp (output_bfd) = bfd_asymbol_value (*sym);
975 /* Only get the error once. */
976 elf_gp (output_bfd) = 4;
978 (char *) "GP relative relocation when _gp not defined";
979 return bfd_reloc_dangerous;
987 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
988 become the offset from the gp register. This function also handles
989 R_MIPS_LITERAL relocations, although those can be handled more
990 cleverly because the entries in the .lit8 and .lit4 sections can be
993 static bfd_reloc_status_type gprel16_with_gp PARAMS ((bfd *, asymbol *,
994 arelent *, asection *,
995 boolean, PTR, bfd_vma));
997 static bfd_reloc_status_type
998 mips_elf_gprel16_reloc (abfd,
1006 arelent *reloc_entry;
1009 asection *input_section;
1011 char **error_message;
1013 boolean relocateable;
1014 bfd_reloc_status_type ret;
1016 /* If we're relocating, and this is an external symbol with no
1017 addend, we don't want to change anything. We will only have an
1018 addend if this is a newly created reloc, not read from an ELF
1020 if (output_bfd != (bfd *) NULL
1021 && (symbol->flags & BSF_SECTION_SYM) == 0
1022 && reloc_entry->addend == 0)
1024 reloc_entry->address += input_section->output_offset;
1025 return bfd_reloc_ok;
1028 if (output_bfd != (bfd *) NULL)
1029 relocateable = true;
1032 relocateable = false;
1033 output_bfd = symbol->section->output_section->owner;
1036 ret = mips_elf_final_gp (output_bfd, symbol, relocateable, error_message);
1037 if (ret != bfd_reloc_ok)
1040 return gprel16_with_gp (abfd, symbol, reloc_entry, input_section,
1041 relocateable, data, elf_gp (output_bfd));
1044 static bfd_reloc_status_type
1045 gprel16_with_gp (abfd, symbol, reloc_entry, input_section, relocateable, data,
1049 arelent *reloc_entry;
1050 asection *input_section;
1051 boolean relocateable;
1059 if (bfd_is_com_section (symbol->section))
1062 relocation = symbol->value;
1064 relocation += symbol->section->output_section->vma;
1065 relocation += symbol->section->output_offset;
1067 if (reloc_entry->address > input_section->_cooked_size)
1068 return bfd_reloc_outofrange;
1070 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1072 /* Set val to the offset into the section or symbol. */
1073 val = ((insn & 0xffff) + reloc_entry->addend) & 0xffff;
1077 /* Adjust val for the final section location and GP value. If we
1078 are producing relocateable output, we don't want to do this for
1079 an external symbol. */
1081 || (symbol->flags & BSF_SECTION_SYM) != 0)
1082 val += relocation - gp;
1084 insn = (insn &~ 0xffff) | (val & 0xffff);
1085 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
1088 reloc_entry->address += input_section->output_offset;
1090 /* Make sure it fit in 16 bits. */
1091 if (val >= 0x8000 && val < 0xffff8000)
1092 return bfd_reloc_overflow;
1094 return bfd_reloc_ok;
1097 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1098 from the gp register? XXX */
1100 static bfd_reloc_status_type gprel32_with_gp PARAMS ((bfd *, asymbol *,
1101 arelent *, asection *,
1102 boolean, PTR, bfd_vma));
1104 static bfd_reloc_status_type
1105 mips_elf_gprel32_reloc (abfd,
1113 arelent *reloc_entry;
1116 asection *input_section;
1118 char **error_message;
1120 boolean relocateable;
1121 bfd_reloc_status_type ret;
1123 /* If we're relocating, and this is an external symbol with no
1124 addend, we don't want to change anything. We will only have an
1125 addend if this is a newly created reloc, not read from an ELF
1127 if (output_bfd != (bfd *) NULL
1128 && (symbol->flags & BSF_SECTION_SYM) == 0
1129 && reloc_entry->addend == 0)
1131 *error_message = (char *)
1132 "32bits gp relative relocation occurs for an external symbol";
1133 return bfd_reloc_outofrange;
1136 if (output_bfd != (bfd *) NULL)
1137 relocateable = true;
1140 relocateable = false;
1141 output_bfd = symbol->section->output_section->owner;
1143 ret = mips_elf_final_gp (output_bfd, symbol, relocateable,
1145 if (ret != bfd_reloc_ok)
1149 return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
1150 relocateable, data, elf_gp (output_bfd));
1153 static bfd_reloc_status_type
1154 gprel32_with_gp (abfd, symbol, reloc_entry, input_section, relocateable, data,
1158 arelent *reloc_entry;
1159 asection *input_section;
1160 boolean relocateable;
1167 if (bfd_is_com_section (symbol->section))
1170 relocation = symbol->value;
1172 relocation += symbol->section->output_section->vma;
1173 relocation += symbol->section->output_offset;
1175 if (reloc_entry->address > input_section->_cooked_size)
1176 return bfd_reloc_outofrange;
1178 val = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1180 /* Set val to the offset into the section or symbol. */
1181 val += reloc_entry->addend;
1183 /* Adjust val for the final section location and GP value. If we
1184 are producing relocateable output, we don't want to do this for
1185 an external symbol. */
1187 || (symbol->flags & BSF_SECTION_SYM) != 0)
1188 val += relocation - gp;
1190 bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);
1193 reloc_entry->address += input_section->output_offset;
1195 return bfd_reloc_ok;
1198 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1200 struct elf_reloc_map {
1201 bfd_reloc_code_real_type bfd_reloc_val;
1202 enum reloc_type elf_reloc_val;
1205 static CONST struct elf_reloc_map mips_reloc_map[] =
1207 { BFD_RELOC_NONE, R_MIPS_NONE, },
1208 { BFD_RELOC_16, R_MIPS_16 },
1209 { BFD_RELOC_32, R_MIPS_32 },
1210 { BFD_RELOC_CTOR, R_MIPS_32 },
1211 { BFD_RELOC_32_PCREL, R_MIPS_REL32 },
1212 { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
1213 { BFD_RELOC_HI16_S, R_MIPS_HI16 },
1214 { BFD_RELOC_LO16, R_MIPS_LO16 },
1215 { BFD_RELOC_MIPS_GPREL, R_MIPS_GPREL16 },
1216 { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
1217 { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
1218 { BFD_RELOC_16_PCREL, R_MIPS_PC16 },
1219 { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
1220 { BFD_RELOC_MIPS_GPREL32, R_MIPS_GPREL32 }
1223 /* Given a BFD reloc type, return a howto structure. */
1225 static reloc_howto_type *
1226 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
1228 bfd_reloc_code_real_type code;
1232 for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map); i++)
1234 if (mips_reloc_map[i].bfd_reloc_val == code)
1235 return &elf_mips_howto_table[(int) mips_reloc_map[i].elf_reloc_val];
1240 /* Given a MIPS reloc type, fill in an arelent structure. */
1243 mips_info_to_howto_rel (abfd, cache_ptr, dst)
1246 Elf32_Internal_Rel *dst;
1248 unsigned int r_type;
1250 r_type = ELF32_R_TYPE (dst->r_info);
1251 BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
1252 cache_ptr->howto = &elf_mips_howto_table[r_type];
1254 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1255 value for the object file. We get the addend now, rather than
1256 when we do the relocation, because the symbol manipulations done
1257 by the linker may cause us to lose track of the input BFD. */
1258 if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
1259 && (r_type == (unsigned int) R_MIPS_GPREL16
1260 || r_type == (unsigned int) R_MIPS_LITERAL))
1261 cache_ptr->addend = elf_gp (abfd);
1264 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1265 routines swap this structure in and out. They are used outside of
1266 BFD, so they are globally visible. */
1269 bfd_mips_elf32_swap_reginfo_in (abfd, ex, in)
1271 const Elf32_External_RegInfo *ex;
1274 in->ri_gprmask = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_gprmask);
1275 in->ri_cprmask[0] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[0]);
1276 in->ri_cprmask[1] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[1]);
1277 in->ri_cprmask[2] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[2]);
1278 in->ri_cprmask[3] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[3]);
1279 in->ri_gp_value = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_gp_value);
1283 bfd_mips_elf32_swap_reginfo_out (abfd, in, ex)
1285 const Elf32_RegInfo *in;
1286 Elf32_External_RegInfo *ex;
1288 bfd_h_put_32 (abfd, (bfd_vma) in->ri_gprmask,
1289 (bfd_byte *) ex->ri_gprmask);
1290 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[0],
1291 (bfd_byte *) ex->ri_cprmask[0]);
1292 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[1],
1293 (bfd_byte *) ex->ri_cprmask[1]);
1294 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[2],
1295 (bfd_byte *) ex->ri_cprmask[2]);
1296 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[3],
1297 (bfd_byte *) ex->ri_cprmask[3]);
1298 bfd_h_put_32 (abfd, (bfd_vma) in->ri_gp_value,
1299 (bfd_byte *) ex->ri_gp_value);
1302 /* Swap an entry in a .gptab section. Note that these routines rely
1303 on the equivalence of the two elements of the union. */
1306 bfd_mips_elf32_swap_gptab_in (abfd, ex, in)
1308 const Elf32_External_gptab *ex;
1311 in->gt_entry.gt_g_value = bfd_h_get_32 (abfd, ex->gt_entry.gt_g_value);
1312 in->gt_entry.gt_bytes = bfd_h_get_32 (abfd, ex->gt_entry.gt_bytes);
1316 bfd_mips_elf32_swap_gptab_out (abfd, in, ex)
1318 const Elf32_gptab *in;
1319 Elf32_External_gptab *ex;
1321 bfd_h_put_32 (abfd, (bfd_vma) in->gt_entry.gt_g_value,
1322 ex->gt_entry.gt_g_value);
1323 bfd_h_put_32 (abfd, (bfd_vma) in->gt_entry.gt_bytes,
1324 ex->gt_entry.gt_bytes);
1328 bfd_elf32_swap_compact_rel_out (abfd, in, ex)
1330 Elf32_compact_rel *in;
1331 Elf32_External_compact_rel *ex;
1333 bfd_h_put_32 (abfd, (bfd_vma) in->id1, ex->id1);
1334 bfd_h_put_32 (abfd, (bfd_vma) in->num, ex->num);
1335 bfd_h_put_32 (abfd, (bfd_vma) in->id2, ex->id2);
1336 bfd_h_put_32 (abfd, (bfd_vma) in->offset, ex->offset);
1337 bfd_h_put_32 (abfd, (bfd_vma) in->reserved0, ex->reserved0);
1338 bfd_h_put_32 (abfd, (bfd_vma) in->reserved1, ex->reserved1);
1342 bfd_elf32_swap_crinfo_out (abfd, in, ex)
1345 Elf32_External_crinfo *ex;
1349 l = (((in->ctype & CRINFO_CTYPE) << CRINFO_CTYPE_SH)
1350 | ((in->rtype & CRINFO_RTYPE) << CRINFO_RTYPE_SH)
1351 | ((in->dist2to & CRINFO_DIST2TO) << CRINFO_DIST2TO_SH)
1352 | ((in->relvaddr & CRINFO_RELVADDR) << CRINFO_RELVADDR_SH));
1353 bfd_h_put_32 (abfd, (bfd_vma) l, ex->info);
1354 bfd_h_put_32 (abfd, (bfd_vma) in->konst, ex->konst);
1355 bfd_h_put_32 (abfd, (bfd_vma) in->vaddr, ex->vaddr);
1358 /* Determine whether a symbol is global for the purposes of splitting
1359 the symbol table into global symbols and local symbols. At least
1360 on Irix 5, this split must be between section symbols and all other
1361 symbols. On most ELF targets the split is between static symbols
1362 and externally visible symbols. */
1366 mips_elf_sym_is_global (abfd, sym)
1370 return (sym->flags & BSF_SECTION_SYM) == 0 ? true : false;
1373 /* Set the right machine number for a MIPS ELF file. */
1376 mips_elf_object_p (abfd)
1379 switch (elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH)
1383 /* Just use the default, which was set in elfcode.h. */
1387 (void) bfd_default_set_arch_mach (abfd, bfd_arch_mips, 6000);
1391 (void) bfd_default_set_arch_mach (abfd, bfd_arch_mips, 4000);
1395 /* Irix 5 is broken. Object file symbol tables are not always
1396 sorted correctly such that local symbols precede global symbols,
1397 and the sh_info field in the symbol table is not always right. */
1398 elf_bad_symtab (abfd) = true;
1403 /* The final processing done just before writing out a MIPS ELF object
1404 file. This gets the MIPS architecture right based on the machine
1409 mips_elf_final_write_processing (abfd, linker)
1415 Elf_Internal_Shdr **hdrpp;
1417 switch (bfd_get_mach (abfd))
1420 val = E_MIPS_ARCH_1;
1424 val = E_MIPS_ARCH_2;
1428 val = E_MIPS_ARCH_3;
1436 elf_elfheader (abfd)->e_flags &=~ EF_MIPS_ARCH;
1437 elf_elfheader (abfd)->e_flags |= val;
1439 /* Set the sh_info field for .gptab sections. */
1440 for (i = 1, hdrpp = elf_elfsections (abfd) + 1;
1441 i < elf_elfheader (abfd)->e_shnum;
1444 if ((*hdrpp)->sh_type == SHT_MIPS_GPTAB)
1449 BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
1450 name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section);
1451 BFD_ASSERT (name != NULL
1452 && strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0);
1453 sec = bfd_get_section_by_name (abfd, name + sizeof ".gptab" - 1);
1454 BFD_ASSERT (sec != NULL);
1455 (*hdrpp)->sh_info = elf_section_data (sec)->this_idx;
1460 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
1463 mips_elf_set_private_flags (abfd, flags)
1467 BFD_ASSERT (!elf_flags_init (abfd)
1468 || elf_elfheader (abfd)->e_flags == flags);
1470 elf_elfheader (abfd)->e_flags = flags;
1471 elf_flags_init (abfd) = true;
1475 /* Copy backend specific data from one object module to another */
1478 mips_elf_copy_private_bfd_data (ibfd, obfd)
1482 /* This function is selected based on the input vector. We only
1483 want to copy information over if the output BFD also uses Elf
1485 if (bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1488 BFD_ASSERT (!elf_flags_init (obfd)
1489 || (elf_elfheader (obfd)->e_flags
1490 == elf_elfheader (ibfd)->e_flags));
1492 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
1493 elf_flags_init (obfd) = true;
1497 /* Merge backend specific data from an object file to the output
1498 object file when linking. */
1501 mips_elf_merge_private_bfd_data (ibfd, obfd)
1508 /* Check if we have the same endianess */
1509 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
1510 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
1512 (*_bfd_error_handler)
1513 ("%s: compiled for a %s endian system and target is %s endian",
1514 bfd_get_filename (ibfd),
1515 bfd_big_endian (ibfd) ? "big" : "little",
1516 bfd_big_endian (obfd) ? "big" : "little");
1518 bfd_set_error (bfd_error_wrong_format);
1522 /* This function is selected based on the input vector. We only
1523 want to copy information over if the output BFD also uses Elf
1525 if (bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1528 new_flags = elf_elfheader (ibfd)->e_flags;
1529 elf_elfheader (obfd)->e_flags |= new_flags & EF_MIPS_NOREORDER;
1530 old_flags = elf_elfheader (obfd)->e_flags;
1532 if (!elf_flags_init (obfd)) /* First call, no flags set */
1534 elf_flags_init (obfd) = true;
1535 elf_elfheader (obfd)->e_flags = new_flags;
1537 else if (((new_flags ^ old_flags) & ~EF_MIPS_NOREORDER)
1538 == 0) /* Compatible flags are ok */
1540 else /* Incompatible flags */
1542 /* Warn about -fPIC mismatch */
1543 if ((new_flags & EF_MIPS_PIC) != (old_flags & EF_MIPS_PIC))
1545 new_flags &= ~EF_MIPS_PIC;
1546 (*_bfd_error_handler)
1547 ("%s: needs all files compiled with -fPIC",
1548 bfd_get_filename (ibfd));
1551 if ((new_flags & EF_MIPS_CPIC) != (old_flags & EF_MIPS_CPIC))
1553 new_flags &= ~EF_MIPS_CPIC;
1554 (*_bfd_error_handler)
1555 ("%s: needs all files compiled with -mabicalls",
1556 bfd_get_filename (ibfd));
1559 /* Warn about any other mismatches */
1560 if (new_flags != old_flags)
1561 (*_bfd_error_handler)
1562 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1563 bfd_get_filename (ibfd), (unsigned long) new_flags,
1564 (unsigned long) old_flags);
1566 bfd_set_error (bfd_error_bad_value);
1573 /* Handle a MIPS specific section when reading an object file. This
1574 is called when elfcode.h finds a section with an unknown type.
1575 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
1579 mips_elf_section_from_shdr (abfd, hdr, name)
1581 Elf32_Internal_Shdr *hdr;
1586 /* There ought to be a place to keep ELF backend specific flags, but
1587 at the moment there isn't one. We just keep track of the
1588 sections by their name, instead. Fortunately, the ABI gives
1589 suggested names for all the MIPS specific sections, so we will
1590 probably get away with this. */
1591 switch (hdr->sh_type)
1593 case SHT_MIPS_LIBLIST:
1594 if (strcmp (name, ".liblist") != 0)
1598 if (strcmp (name, ".msym") != 0)
1601 case SHT_MIPS_CONFLICT:
1602 if (strcmp (name, ".conflict") != 0)
1605 case SHT_MIPS_GPTAB:
1606 if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) != 0)
1609 case SHT_MIPS_UCODE:
1610 if (strcmp (name, ".ucode") != 0)
1613 case SHT_MIPS_DEBUG:
1614 if (strcmp (name, ".mdebug") != 0)
1617 case SHT_MIPS_REGINFO:
1618 if (strcmp (name, ".reginfo") != 0
1619 || hdr->sh_size != sizeof (Elf32_External_RegInfo))
1622 case SHT_MIPS_OPTIONS:
1623 if (strcmp (name, ".options") != 0)
1626 case SHT_MIPS_DWARF:
1627 if (strncmp (name, ".debug_", sizeof ".debug_" - 1) != 0)
1630 case SHT_MIPS_EVENTS:
1631 if (strncmp (name, ".MIPS.events.", sizeof ".MIPS.events." - 1) != 0)
1638 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
1640 newsect = hdr->bfd_section;
1642 if (hdr->sh_type == SHT_MIPS_DEBUG)
1644 if (! bfd_set_section_flags (abfd, newsect,
1645 (bfd_get_section_flags (abfd, newsect)
1650 /* FIXME: We should record sh_info for a .gptab section. */
1652 /* For a .reginfo section, set the gp value in the tdata information
1653 from the contents of this section. We need the gp value while
1654 processing relocs, so we just get it now. */
1655 if (hdr->sh_type == SHT_MIPS_REGINFO)
1657 Elf32_External_RegInfo ext;
1660 if (! bfd_get_section_contents (abfd, newsect, (PTR) &ext,
1661 (file_ptr) 0, sizeof ext))
1663 bfd_mips_elf32_swap_reginfo_in (abfd, &ext, &s);
1664 elf_gp (abfd) = s.ri_gp_value;
1670 /* Set the correct type for a MIPS ELF section. We do this by the
1671 section name, which is a hack, but ought to work. */
1674 mips_elf_fake_sections (abfd, hdr, sec)
1676 Elf32_Internal_Shdr *hdr;
1679 register const char *name;
1681 name = bfd_get_section_name (abfd, sec);
1683 if (strcmp (name, ".liblist") == 0)
1685 hdr->sh_type = SHT_MIPS_LIBLIST;
1686 hdr->sh_info = sec->_raw_size / sizeof (Elf32_Lib);
1687 /* FIXME: Set the sh_link field. */
1689 else if (strcmp (name, ".msym") == 0)
1691 hdr->sh_type = SHT_MIPS_MSYM;
1692 hdr->sh_entsize = 8;
1693 /* FIXME: Set the sh_info field. */
1695 else if (strcmp (name, ".conflict") == 0)
1696 hdr->sh_type = SHT_MIPS_CONFLICT;
1697 else if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0)
1699 hdr->sh_type = SHT_MIPS_GPTAB;
1700 hdr->sh_entsize = sizeof (Elf32_External_gptab);
1701 /* The sh_info field is set in mips_elf_final_write_processing. */
1703 else if (strcmp (name, ".ucode") == 0)
1704 hdr->sh_type = SHT_MIPS_UCODE;
1705 else if (strcmp (name, ".mdebug") == 0)
1707 hdr->sh_type = SHT_MIPS_DEBUG;
1708 /* In a shared object on Irix 5.3, the .mdebug section has an
1709 entsize of 0. FIXME: Does this matter? */
1710 if (SGI_COMPAT (abfd) && (abfd->flags & DYNAMIC) != 0)
1711 hdr->sh_entsize = 0;
1713 hdr->sh_entsize = 1;
1715 else if (strcmp (name, ".reginfo") == 0)
1717 hdr->sh_type = SHT_MIPS_REGINFO;
1718 /* In a shared object on Irix 5.3, the .reginfo section has an
1719 entsize of 0x18. FIXME: Does this matter? */
1720 if (SGI_COMPAT (abfd) && (abfd->flags & DYNAMIC) != 0)
1721 hdr->sh_entsize = sizeof (Elf32_External_RegInfo);
1723 hdr->sh_entsize = 1;
1725 /* Force the section size to the correct value, even if the
1726 linker thinks it is larger. The link routine below will only
1727 write out this much data for .reginfo. */
1728 hdr->sh_size = sec->_raw_size = sizeof (Elf32_External_RegInfo);
1730 else if (SGI_COMPAT (abfd)
1731 && (strcmp (name, ".hash") == 0
1732 || strcmp (name, ".dynamic") == 0
1733 || strcmp (name, ".dynstr") == 0))
1735 hdr->sh_entsize = 0;
1736 hdr->sh_info = SIZEOF_MIPS_DYNSYM_SECNAMES;
1738 else if (strcmp (name, ".got") == 0
1739 || strcmp (name, ".sdata") == 0
1740 || strcmp (name, ".sbss") == 0
1741 || strcmp (name, ".lit4") == 0
1742 || strcmp (name, ".lit8") == 0)
1743 hdr->sh_flags |= SHF_MIPS_GPREL;
1744 else if (strcmp (name, ".options") == 0)
1746 hdr->sh_type = SHT_MIPS_OPTIONS;
1747 hdr->sh_entsize = 1;
1749 else if (strncmp (name, ".debug_", sizeof ".debug_" - 1) == 0)
1750 hdr->sh_type = SHT_MIPS_DWARF;
1751 else if (strncmp (name, ".MIPS.events.", sizeof ".MIPS.events." - 1) == 0)
1752 hdr->sh_type = SHT_MIPS_EVENTS;
1757 /* Given a BFD section, try to locate the corresponding ELF section
1761 mips_elf_section_from_bfd_section (abfd, hdr, sec, retval)
1763 Elf32_Internal_Shdr *hdr;
1767 if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)
1769 *retval = SHN_MIPS_SCOMMON;
1772 if (strcmp (bfd_get_section_name (abfd, sec), ".acommon") == 0)
1774 *retval = SHN_MIPS_ACOMMON;
1780 /* Work over a section just before writing it out. We update the GP
1781 value in the .reginfo section based on the value we are using.
1782 FIXME: We recognize sections that need the SHF_MIPS_GPREL flag by
1783 name; there has to be a better way. */
1786 mips_elf_section_processing (abfd, hdr)
1788 Elf32_Internal_Shdr *hdr;
1790 if (hdr->sh_type == SHT_MIPS_REGINFO)
1794 BFD_ASSERT (hdr->sh_size == sizeof (Elf32_External_RegInfo));
1795 BFD_ASSERT (hdr->contents == NULL);
1798 hdr->sh_offset + sizeof (Elf32_External_RegInfo) - 4,
1801 bfd_h_put_32 (abfd, (bfd_vma) elf_gp (abfd), buf);
1802 if (bfd_write (buf, (bfd_size_type) 1, (bfd_size_type) 4, abfd) != 4)
1806 if (hdr->bfd_section != NULL)
1808 const char *name = bfd_get_section_name (abfd, hdr->bfd_section);
1810 if (strcmp (name, ".sdata") == 0)
1812 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
1813 hdr->sh_type = SHT_PROGBITS;
1815 else if (strcmp (name, ".sbss") == 0)
1817 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
1818 hdr->sh_type = SHT_NOBITS;
1820 else if (strcmp (name, ".lit8") == 0
1821 || strcmp (name, ".lit4") == 0)
1823 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
1824 hdr->sh_type = SHT_PROGBITS;
1826 else if (strcmp (name, ".compact_rel") == 0)
1829 hdr->sh_type = SHT_PROGBITS;
1831 else if (strcmp (name, ".rtproc") == 0)
1833 if (hdr->sh_addralign != 0 && hdr->sh_entsize == 0)
1835 unsigned int adjust;
1837 adjust = hdr->sh_size % hdr->sh_addralign;
1839 hdr->sh_size += hdr->sh_addralign - adjust;
1847 /* MIPS ELF uses two common sections. One is the usual one, and the
1848 other is for small objects. All the small objects are kept
1849 together, and then referenced via the gp pointer, which yields
1850 faster assembler code. This is what we use for the small common
1851 section. This approach is copied from ecoff.c. */
1852 static asection mips_elf_scom_section;
1853 static asymbol mips_elf_scom_symbol;
1854 static asymbol *mips_elf_scom_symbol_ptr;
1856 /* MIPS ELF also uses an acommon section, which represents an
1857 allocated common symbol which may be overridden by a
1858 definition in a shared library. */
1859 static asection mips_elf_acom_section;
1860 static asymbol mips_elf_acom_symbol;
1861 static asymbol *mips_elf_acom_symbol_ptr;
1863 /* The Irix 5 support uses two virtual sections, which represent
1864 text/data symbols defined in dynamic objects. */
1865 static asection mips_elf_text_section;
1866 static asection *mips_elf_text_section_ptr;
1867 static asymbol mips_elf_text_symbol;
1868 static asymbol *mips_elf_text_symbol_ptr;
1870 static asection mips_elf_data_section;
1871 static asection *mips_elf_data_section_ptr;
1872 static asymbol mips_elf_data_symbol;
1873 static asymbol *mips_elf_data_symbol_ptr;
1875 /* Handle the special MIPS section numbers that a symbol may use. */
1878 mips_elf_symbol_processing (abfd, asym)
1882 elf_symbol_type *elfsym;
1884 elfsym = (elf_symbol_type *) asym;
1885 switch (elfsym->internal_elf_sym.st_shndx)
1887 case SHN_MIPS_ACOMMON:
1888 /* This section is used in a dynamically linked executable file.
1889 It is an allocated common section. The dynamic linker can
1890 either resolve these symbols to something in a shared
1891 library, or it can just leave them here. For our purposes,
1892 we can consider these symbols to be in a new section. */
1893 if (mips_elf_acom_section.name == NULL)
1895 /* Initialize the acommon section. */
1896 mips_elf_acom_section.name = ".acommon";
1897 mips_elf_acom_section.flags = SEC_ALLOC;
1898 mips_elf_acom_section.output_section = &mips_elf_acom_section;
1899 mips_elf_acom_section.symbol = &mips_elf_acom_symbol;
1900 mips_elf_acom_section.symbol_ptr_ptr = &mips_elf_acom_symbol_ptr;
1901 mips_elf_acom_symbol.name = ".acommon";
1902 mips_elf_acom_symbol.flags = BSF_SECTION_SYM;
1903 mips_elf_acom_symbol.section = &mips_elf_acom_section;
1904 mips_elf_acom_symbol_ptr = &mips_elf_acom_symbol;
1906 asym->section = &mips_elf_acom_section;
1910 /* Common symbols less than the GP size are automatically
1911 treated as SHN_MIPS_SCOMMON symbols. */
1912 if (asym->value > elf_gp_size (abfd))
1915 case SHN_MIPS_SCOMMON:
1916 if (mips_elf_scom_section.name == NULL)
1918 /* Initialize the small common section. */
1919 mips_elf_scom_section.name = ".scommon";
1920 mips_elf_scom_section.flags = SEC_IS_COMMON;
1921 mips_elf_scom_section.output_section = &mips_elf_scom_section;
1922 mips_elf_scom_section.symbol = &mips_elf_scom_symbol;
1923 mips_elf_scom_section.symbol_ptr_ptr = &mips_elf_scom_symbol_ptr;
1924 mips_elf_scom_symbol.name = ".scommon";
1925 mips_elf_scom_symbol.flags = BSF_SECTION_SYM;
1926 mips_elf_scom_symbol.section = &mips_elf_scom_section;
1927 mips_elf_scom_symbol_ptr = &mips_elf_scom_symbol;
1929 asym->section = &mips_elf_scom_section;
1930 asym->value = elfsym->internal_elf_sym.st_size;
1933 case SHN_MIPS_SUNDEFINED:
1934 asym->section = bfd_und_section_ptr;
1937 #if 0 /* for SGI_COMPAT */
1939 asym->section = mips_elf_text_section_ptr;
1943 asym->section = mips_elf_data_section_ptr;
1949 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
1953 mips_elf_additional_program_headers (abfd)
1961 if (! SGI_COMPAT (abfd))
1964 s = bfd_get_section_by_name (abfd, ".reginfo");
1965 if (s != NULL && (s->flags & SEC_LOAD) != 0)
1967 /* We need a PT_MIPS_REGINFO segment. */
1971 if (bfd_get_section_by_name (abfd, ".interp") == NULL
1972 && bfd_get_section_by_name (abfd, ".dynamic") != NULL
1973 && bfd_get_section_by_name (abfd, ".mdebug") != NULL)
1975 /* We need a PT_MIPS_RTPROC segment. */
1982 /* Modify the segment map for an Irix 5 executable. */
1985 mips_elf_modify_segment_map (abfd)
1989 struct elf_segment_map *m, **pm;
1991 if (! SGI_COMPAT (abfd))
1994 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
1996 s = bfd_get_section_by_name (abfd, ".reginfo");
1997 if (s != NULL && (s->flags & SEC_LOAD) != 0)
1999 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
2000 if (m->p_type == PT_MIPS_REGINFO)
2004 m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m);
2008 m->p_type = PT_MIPS_REGINFO;
2012 /* We want to put it after the PHDR and INTERP segments. */
2013 pm = &elf_tdata (abfd)->segment_map;
2015 && ((*pm)->p_type == PT_PHDR
2016 || (*pm)->p_type == PT_INTERP))
2024 /* If there are .dynamic and .mdebug sections, we make a room for
2025 the RTPROC header. FIXME: Rewrite without section names. */
2026 if (bfd_get_section_by_name (abfd, ".interp") == NULL
2027 && bfd_get_section_by_name (abfd, ".dynamic") != NULL
2028 && bfd_get_section_by_name (abfd, ".mdebug") != NULL)
2030 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
2031 if (m->p_type == PT_MIPS_RTPROC)
2035 m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m);
2039 m->p_type = PT_MIPS_RTPROC;
2041 s = bfd_get_section_by_name (abfd, ".rtproc");
2046 m->p_flags_valid = 1;
2054 /* We want to put it after the DYNAMIC segment. */
2055 pm = &elf_tdata (abfd)->segment_map;
2056 while (*pm != NULL && (*pm)->p_type != PT_DYNAMIC)
2066 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
2067 .dynsym, and .hash sections, and everything in between. */
2068 for (pm = &elf_tdata (abfd)->segment_map; *pm != NULL; pm = &(*pm)->next)
2069 if ((*pm)->p_type == PT_DYNAMIC)
2074 && strcmp (m->sections[0]->name, ".dynamic") == 0)
2076 static const char *sec_names[] =
2077 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
2080 struct elf_segment_map *n;
2084 for (i = 0; i < sizeof sec_names / sizeof sec_names[0]; i++)
2086 s = bfd_get_section_by_name (abfd, sec_names[i]);
2087 if (s != NULL && (s->flags & SEC_LOAD) != 0)
2093 sz = s->_cooked_size;
2096 if (high < s->vma + sz)
2102 for (s = abfd->sections; s != NULL; s = s->next)
2103 if ((s->flags & SEC_LOAD) != 0
2106 + (s->_cooked_size != 0 ? s->_cooked_size : s->_raw_size))
2110 n = ((struct elf_segment_map *)
2111 bfd_zalloc (abfd, sizeof *n + (c - 1) * sizeof (asection *)));
2118 for (s = abfd->sections; s != NULL; s = s->next)
2120 if ((s->flags & SEC_LOAD) != 0
2123 + (s->_cooked_size != 0 ? s->_cooked_size : s->_raw_size))
2137 /* The structure of the runtime procedure descriptor created by the
2138 loader for use by the static exception system. */
2140 typedef struct runtime_pdr {
2141 bfd_vma adr; /* memory address of start of procedure */
2142 long regmask; /* save register mask */
2143 long regoffset; /* save register offset */
2144 long fregmask; /* save floating point register mask */
2145 long fregoffset; /* save floating point register offset */
2146 long frameoffset; /* frame size */
2147 short framereg; /* frame pointer register */
2148 short pcreg; /* offset or reg of return pc */
2149 long irpss; /* index into the runtime string table */
2151 struct exception_info *exception_info;/* pointer to exception array */
2153 #define cbRPDR sizeof(RPDR)
2154 #define rpdNil ((pRPDR) 0)
2156 /* Swap RPDR (runtime procedure table entry) for output. */
2158 static void ecoff_swap_rpdr_out
2159 PARAMS ((bfd *, const RPDR *, struct rpdr_ext *));
2162 ecoff_swap_rpdr_out (abfd, in, ex)
2165 struct rpdr_ext *ex;
2167 /* ecoff_put_off was defined in ecoffswap.h. */
2168 ecoff_put_off (abfd, in->adr, (bfd_byte *) ex->p_adr);
2169 bfd_h_put_32 (abfd, in->regmask, (bfd_byte *) ex->p_regmask);
2170 bfd_h_put_32 (abfd, in->regoffset, (bfd_byte *) ex->p_regoffset);
2171 bfd_h_put_32 (abfd, in->fregmask, (bfd_byte *) ex->p_fregmask);
2172 bfd_h_put_32 (abfd, in->fregoffset, (bfd_byte *) ex->p_fregoffset);
2173 bfd_h_put_32 (abfd, in->frameoffset, (bfd_byte *) ex->p_frameoffset);
2175 bfd_h_put_16 (abfd, in->framereg, (bfd_byte *) ex->p_framereg);
2176 bfd_h_put_16 (abfd, in->pcreg, (bfd_byte *) ex->p_pcreg);
2178 bfd_h_put_32 (abfd, in->irpss, (bfd_byte *) ex->p_irpss);
2180 ecoff_put_off (abfd, in->exception_info, (bfd_byte *) ex->p_exception_info);
2184 /* Read ECOFF debugging information from a .mdebug section into a
2185 ecoff_debug_info structure. */
2188 mips_elf_read_ecoff_info (abfd, section, debug)
2191 struct ecoff_debug_info *debug;
2194 const struct ecoff_debug_swap *swap;
2195 char *ext_hdr = NULL;
2197 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
2199 ext_hdr = (char *) bfd_malloc ((size_t) swap->external_hdr_size);
2200 if (ext_hdr == NULL && swap->external_hdr_size != 0)
2203 if (bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0,
2204 swap->external_hdr_size)
2208 symhdr = &debug->symbolic_header;
2209 (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr);
2211 /* The symbolic header contains absolute file offsets and sizes to
2213 #define READ(ptr, offset, count, size, type) \
2214 if (symhdr->count == 0) \
2215 debug->ptr = NULL; \
2218 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
2219 if (debug->ptr == NULL) \
2220 goto error_return; \
2221 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
2222 || (bfd_read (debug->ptr, size, symhdr->count, \
2223 abfd) != size * symhdr->count)) \
2224 goto error_return; \
2227 READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *);
2228 READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR);
2229 READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR);
2230 READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR);
2231 READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR);
2232 READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext),
2234 READ (ss, cbSsOffset, issMax, sizeof (char), char *);
2235 READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *);
2236 READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR);
2237 READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR);
2238 READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR);
2242 debug->adjust = NULL;
2247 if (ext_hdr != NULL)
2249 if (debug->line != NULL)
2251 if (debug->external_dnr != NULL)
2252 free (debug->external_dnr);
2253 if (debug->external_pdr != NULL)
2254 free (debug->external_pdr);
2255 if (debug->external_sym != NULL)
2256 free (debug->external_sym);
2257 if (debug->external_opt != NULL)
2258 free (debug->external_opt);
2259 if (debug->external_aux != NULL)
2260 free (debug->external_aux);
2261 if (debug->ss != NULL)
2263 if (debug->ssext != NULL)
2264 free (debug->ssext);
2265 if (debug->external_fdr != NULL)
2266 free (debug->external_fdr);
2267 if (debug->external_rfd != NULL)
2268 free (debug->external_rfd);
2269 if (debug->external_ext != NULL)
2270 free (debug->external_ext);
2274 /* MIPS ELF local labels start with '$', not 'L'. */
2278 mips_elf_is_local_label (abfd, symbol)
2282 return symbol->name[0] == '$';
2285 /* MIPS ELF uses a special find_nearest_line routine in order the
2286 handle the ECOFF debugging information. */
2288 struct mips_elf_find_line
2290 struct ecoff_debug_info d;
2291 struct ecoff_find_line i;
2295 mips_elf_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
2296 functionname_ptr, line_ptr)
2301 const char **filename_ptr;
2302 const char **functionname_ptr;
2303 unsigned int *line_ptr;
2307 msec = bfd_get_section_by_name (abfd, ".mdebug");
2311 struct mips_elf_find_line *fi;
2312 const struct ecoff_debug_swap * const swap =
2313 get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
2315 /* If we are called during a link, mips_elf_final_link may have
2316 cleared the SEC_HAS_CONTENTS field. We force it back on here
2317 if appropriate (which it normally will be). */
2318 origflags = msec->flags;
2319 if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS)
2320 msec->flags |= SEC_HAS_CONTENTS;
2322 fi = elf_tdata (abfd)->find_line_info;
2325 bfd_size_type external_fdr_size;
2328 struct fdr *fdr_ptr;
2330 fi = ((struct mips_elf_find_line *)
2331 bfd_alloc (abfd, sizeof (struct mips_elf_find_line)));
2334 msec->flags = origflags;
2338 memset (fi, 0, sizeof (struct mips_elf_find_line));
2340 if (! mips_elf_read_ecoff_info (abfd, msec, &fi->d))
2342 msec->flags = origflags;
2346 /* Swap in the FDR information. */
2347 fi->d.fdr = ((struct fdr *)
2349 (fi->d.symbolic_header.ifdMax *
2350 sizeof (struct fdr))));
2351 if (fi->d.fdr == NULL)
2353 msec->flags = origflags;
2356 external_fdr_size = swap->external_fdr_size;
2357 fdr_ptr = fi->d.fdr;
2358 fraw_src = (char *) fi->d.external_fdr;
2359 fraw_end = (fraw_src
2360 + fi->d.symbolic_header.ifdMax * external_fdr_size);
2361 for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
2362 (*swap->swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr);
2364 elf_tdata (abfd)->find_line_info = fi;
2366 /* Note that we don't bother to ever free this information.
2367 find_nearest_line is either called all the time, as in
2368 objdump -l, so the information should be saved, or it is
2369 rarely called, as in ld error messages, so the memory
2370 wasted is unimportant. Still, it would probably be a
2371 good idea for free_cached_info to throw it away. */
2374 if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap,
2375 &fi->i, filename_ptr, functionname_ptr,
2378 msec->flags = origflags;
2382 msec->flags = origflags;
2385 /* Fall back on the generic ELF find_nearest_line routine. */
2387 return _bfd_elf_find_nearest_line (abfd, section, symbols, offset,
2388 filename_ptr, functionname_ptr,
2392 /* The MIPS ELF linker needs additional information for each symbol in
2393 the global hash table. */
2395 struct mips_elf_link_hash_entry
2397 struct elf_link_hash_entry root;
2399 /* External symbol information. */
2403 /* MIPS ELF linker hash table. */
2405 struct mips_elf_link_hash_table
2407 struct elf_link_hash_table root;
2408 /* String section indices for the dynamic section symbols. */
2409 bfd_size_type dynsym_sec_strindex[SIZEOF_MIPS_DYNSYM_SECNAMES];
2410 /* The number of .rtproc entries. */
2411 bfd_size_type procedure_count;
2414 /* Look up an entry in a MIPS ELF linker hash table. */
2416 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
2417 ((struct mips_elf_link_hash_entry *) \
2418 elf_link_hash_lookup (&(table)->root, (string), (create), \
2421 /* Traverse a MIPS ELF linker hash table. */
2423 #define mips_elf_link_hash_traverse(table, func, info) \
2424 (elf_link_hash_traverse \
2426 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
2429 /* Get the MIPS ELF linker hash table from a link_info structure. */
2431 #define mips_elf_hash_table(p) \
2432 ((struct mips_elf_link_hash_table *) ((p)->hash))
2434 static boolean mips_elf_output_extsym
2435 PARAMS ((struct mips_elf_link_hash_entry *, PTR));
2437 /* Create an entry in a MIPS ELF linker hash table. */
2439 static struct bfd_hash_entry *
2440 mips_elf_link_hash_newfunc (entry, table, string)
2441 struct bfd_hash_entry *entry;
2442 struct bfd_hash_table *table;
2445 struct mips_elf_link_hash_entry *ret =
2446 (struct mips_elf_link_hash_entry *) entry;
2448 /* Allocate the structure if it has not already been allocated by a
2450 if (ret == (struct mips_elf_link_hash_entry *) NULL)
2451 ret = ((struct mips_elf_link_hash_entry *)
2452 bfd_hash_allocate (table,
2453 sizeof (struct mips_elf_link_hash_entry)));
2454 if (ret == (struct mips_elf_link_hash_entry *) NULL)
2455 return (struct bfd_hash_entry *) ret;
2457 /* Call the allocation method of the superclass. */
2458 ret = ((struct mips_elf_link_hash_entry *)
2459 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2461 if (ret != (struct mips_elf_link_hash_entry *) NULL)
2463 /* Set local fields. */
2464 memset (&ret->esym, 0, sizeof (EXTR));
2465 /* We use -2 as a marker to indicate that the information has
2466 not been set. -1 means there is no associated ifd. */
2470 return (struct bfd_hash_entry *) ret;
2473 /* Create a MIPS ELF linker hash table. */
2475 static struct bfd_link_hash_table *
2476 mips_elf_link_hash_table_create (abfd)
2479 struct mips_elf_link_hash_table *ret;
2482 ret = ((struct mips_elf_link_hash_table *)
2483 bfd_alloc (abfd, sizeof (struct mips_elf_link_hash_table)));
2484 if (ret == (struct mips_elf_link_hash_table *) NULL)
2487 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
2488 mips_elf_link_hash_newfunc))
2490 bfd_release (abfd, ret);
2494 for (i = 0; i < SIZEOF_MIPS_DYNSYM_SECNAMES; i++)
2495 ret->dynsym_sec_strindex[i] = (bfd_size_type) -1;
2496 ret->procedure_count = 0;
2498 return &ret->root.root;
2501 /* Hook called by the linker routine which adds symbols from an object
2502 file. We must handle the special MIPS section numbers here. */
2506 mips_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
2508 struct bfd_link_info *info;
2509 const Elf_Internal_Sym *sym;
2515 switch (sym->st_shndx)
2518 /* Common symbols less than the GP size are automatically
2519 treated as SHN_MIPS_SCOMMON symbols. */
2520 if (sym->st_size > elf_gp_size (abfd))
2523 case SHN_MIPS_SCOMMON:
2524 *secp = bfd_make_section_old_way (abfd, ".scommon");
2525 (*secp)->flags |= SEC_IS_COMMON;
2526 *valp = sym->st_size;
2530 /* This section is used in a shared object. */
2531 if (mips_elf_text_section_ptr == NULL)
2533 /* Initialize the section. */
2534 mips_elf_text_section.name = ".text";
2535 mips_elf_text_section.flags = SEC_NO_FLAGS;
2536 mips_elf_text_section.output_section = NULL;
2537 mips_elf_text_section.owner = abfd;
2538 mips_elf_text_section.symbol = &mips_elf_text_symbol;
2539 mips_elf_text_section.symbol_ptr_ptr = &mips_elf_text_symbol_ptr;
2540 mips_elf_text_symbol.name = ".text";
2541 mips_elf_text_symbol.flags = BSF_SECTION_SYM;
2542 mips_elf_text_symbol.section = &mips_elf_text_section;
2543 mips_elf_text_symbol_ptr = &mips_elf_text_symbol;
2544 mips_elf_text_section_ptr = &mips_elf_text_section;
2547 *secp = bfd_und_section_ptr;
2549 *secp = mips_elf_text_section_ptr;
2553 /* This section is used in a shared object. */
2554 if (mips_elf_data_section_ptr == NULL)
2556 /* Initialize the section. */
2557 mips_elf_data_section.name = ".data";
2558 mips_elf_data_section.flags = SEC_NO_FLAGS;
2559 mips_elf_data_section.output_section = NULL;
2560 mips_elf_data_section.owner = abfd;
2561 mips_elf_data_section.symbol = &mips_elf_data_symbol;
2562 mips_elf_data_section.symbol_ptr_ptr = &mips_elf_data_symbol_ptr;
2563 mips_elf_data_symbol.name = ".data";
2564 mips_elf_data_symbol.flags = BSF_SECTION_SYM;
2565 mips_elf_data_symbol.section = &mips_elf_data_section;
2566 mips_elf_data_symbol_ptr = &mips_elf_data_symbol;
2567 mips_elf_data_section_ptr = &mips_elf_data_section;
2570 *secp = bfd_und_section_ptr;
2572 *secp = mips_elf_data_section_ptr;
2575 case SHN_MIPS_SUNDEFINED:
2576 *secp = bfd_und_section_ptr;
2583 /* Structure used to pass information to mips_elf_output_extsym. */
2588 struct bfd_link_info *info;
2589 struct ecoff_debug_info *debug;
2590 const struct ecoff_debug_swap *swap;
2594 /* This routine is used to write out ECOFF debugging external symbol
2595 information. It is called via mips_elf_link_hash_traverse. The
2596 ECOFF external symbol information must match the ELF external
2597 symbol information. Unfortunately, at this point we don't know
2598 whether a symbol is required by reloc information, so the two
2599 tables may wind up being different. We must sort out the external
2600 symbol information before we can set the final size of the .mdebug
2601 section, and we must set the size of the .mdebug section before we
2602 can relocate any sections, and we can't know which symbols are
2603 required by relocation until we relocate the sections.
2604 Fortunately, it is relatively unlikely that any symbol will be
2605 stripped but required by a reloc. In particular, it can not happen
2606 when generating a final executable. */
2609 mips_elf_output_extsym (h, data)
2610 struct mips_elf_link_hash_entry *h;
2613 struct extsym_info *einfo = (struct extsym_info *) data;
2615 asection *sec, *output_section;
2617 if (h->root.indx == -2)
2619 else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
2620 || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)
2621 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
2622 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
2624 else if (einfo->info->strip == strip_all
2625 || (einfo->info->strip == strip_some
2626 && bfd_hash_lookup (einfo->info->keep_hash,
2627 h->root.root.root.string,
2628 false, false) == NULL))
2636 if (h->esym.ifd == -2)
2639 h->esym.cobol_main = 0;
2640 h->esym.weakext = 0;
2641 h->esym.reserved = 0;
2642 h->esym.ifd = ifdNil;
2643 h->esym.asym.value = 0;
2644 h->esym.asym.st = stGlobal;
2646 if (SGI_COMPAT (einfo->abfd)
2647 && (h->root.root.type == bfd_link_hash_undefined
2648 || h->root.root.type == bfd_link_hash_undefweak))
2652 /* Use undefined class. Also, set class and type for some
2654 name = h->root.root.root.string;
2655 if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0
2656 || strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0)
2658 h->esym.asym.sc = scData;
2659 h->esym.asym.st = stLabel;
2660 h->esym.asym.value = 0;
2662 else if (strcmp (name, mips_elf_dynsym_rtproc_names[2]) == 0)
2664 h->esym.asym.sc = scAbs;
2665 h->esym.asym.st = stLabel;
2666 h->esym.asym.value =
2667 mips_elf_hash_table (einfo->info)->procedure_count;
2669 else if (strcmp (name, "_gp_disp") == 0)
2671 h->esym.asym.sc = scAbs;
2672 h->esym.asym.st = stLabel;
2673 h->esym.asym.value = elf_gp (einfo->abfd);
2676 h->esym.asym.sc = scUndefined;
2678 else if (h->root.root.type != bfd_link_hash_defined
2679 && h->root.root.type != bfd_link_hash_defweak)
2680 h->esym.asym.sc = scAbs;
2685 sec = h->root.root.u.def.section;
2686 output_section = sec->output_section;
2688 /* When making a shared library and symbol h is the one from
2689 the another shared library, OUTPUT_SECTION may be null. */
2690 if (output_section == NULL)
2691 h->esym.asym.sc = scUndefined;
2694 name = bfd_section_name (output_section->owner, output_section);
2696 if (strcmp (name, ".text") == 0)
2697 h->esym.asym.sc = scText;
2698 else if (strcmp (name, ".data") == 0)
2699 h->esym.asym.sc = scData;
2700 else if (strcmp (name, ".sdata") == 0)
2701 h->esym.asym.sc = scSData;
2702 else if (strcmp (name, ".rodata") == 0
2703 || strcmp (name, ".rdata") == 0)
2704 h->esym.asym.sc = scRData;
2705 else if (strcmp (name, ".bss") == 0)
2706 h->esym.asym.sc = scBss;
2707 else if (strcmp (name, ".sbss") == 0)
2708 h->esym.asym.sc = scSBss;
2709 else if (strcmp (name, ".init") == 0)
2710 h->esym.asym.sc = scInit;
2711 else if (strcmp (name, ".fini") == 0)
2712 h->esym.asym.sc = scFini;
2714 h->esym.asym.sc = scAbs;
2718 h->esym.asym.reserved = 0;
2719 h->esym.asym.index = indexNil;
2722 if (h->root.root.type == bfd_link_hash_common)
2723 h->esym.asym.value = h->root.root.u.c.size;
2724 else if (h->root.root.type == bfd_link_hash_defined
2725 || h->root.root.type == bfd_link_hash_defweak)
2727 if (h->esym.asym.sc == scCommon)
2728 h->esym.asym.sc = scBss;
2729 else if (h->esym.asym.sc == scSCommon)
2730 h->esym.asym.sc = scSBss;
2732 sec = h->root.root.u.def.section;
2733 output_section = sec->output_section;
2734 if (output_section != NULL)
2735 h->esym.asym.value = (h->root.root.u.def.value
2736 + sec->output_offset
2737 + output_section->vma);
2739 h->esym.asym.value = 0;
2741 else if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
2743 /* Set type and value for a symbol with a function stub. */
2744 h->esym.asym.st = stProc;
2745 sec = h->root.root.u.def.section;
2747 h->esym.asym.value = 0;
2750 output_section = sec->output_section;
2751 if (output_section != NULL)
2752 h->esym.asym.value = (h->root.plt_offset
2753 + sec->output_offset
2754 + output_section->vma);
2756 h->esym.asym.value = 0;
2763 if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap,
2764 h->root.root.root.string,
2767 einfo->failed = true;
2774 /* Create a runtime procedure table from the .mdebug section. */
2777 mips_elf_create_procedure_table (handle, abfd, info, s, debug)
2780 struct bfd_link_info *info;
2782 struct ecoff_debug_info *debug;
2784 const struct ecoff_debug_swap *swap;
2785 HDRR *hdr = &debug->symbolic_header;
2787 struct rpdr_ext *erp;
2789 struct pdr_ext *epdr;
2790 struct sym_ext *esym;
2793 unsigned long size, count;
2794 unsigned long sindex;
2798 const char *no_name_func = "static procedure (no name)";
2805 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
2807 sindex = strlen (no_name_func) + 1;
2808 count = hdr->ipdMax;
2811 size = swap->external_pdr_size;
2813 epdr = (struct pdr_ext *) bfd_malloc (size * count);
2817 if (! _bfd_ecoff_get_accumulated_pdr (handle, (PTR) epdr))
2820 size = sizeof (RPDR);
2821 rp = rpdr = (RPDR *) bfd_malloc (size * count);
2825 sv = (char **) bfd_malloc (sizeof (char *) * count);
2829 count = hdr->isymMax;
2830 size = swap->external_sym_size;
2831 esym = (struct sym_ext *) bfd_malloc (size * count);
2835 if (! _bfd_ecoff_get_accumulated_sym (handle, (PTR) esym))
2838 count = hdr->issMax;
2839 ss = (char *) bfd_malloc (count);
2842 if (! _bfd_ecoff_get_accumulated_ss (handle, (PTR) ss))
2845 count = hdr->ipdMax;
2846 for (i = 0; i < count; i++, rp++, epdr++)
2848 (*swap->swap_pdr_in) (abfd, (PTR) epdr, &pdr);
2849 (*swap->swap_sym_in) (abfd, (PTR) &esym[pdr.isym], &sym);
2850 rp->adr = sym.value;
2851 rp->regmask = pdr.regmask;
2852 rp->regoffset = pdr.regoffset;
2853 rp->fregmask = pdr.fregmask;
2854 rp->fregoffset = pdr.fregoffset;
2855 rp->frameoffset = pdr.frameoffset;
2856 rp->framereg = pdr.framereg;
2857 rp->pcreg = pdr.pcreg;
2859 sv[i] = ss + sym.iss;
2860 sindex += strlen (sv[i]) + 1;
2864 size = sizeof (struct rpdr_ext) * (count + 2) + sindex;
2865 size = BFD_ALIGN (size, 16);
2866 rtproc = (PTR) bfd_alloc (abfd, size);
2869 mips_elf_hash_table (info)->procedure_count = 0;
2873 mips_elf_hash_table (info)->procedure_count = count + 2;
2875 erp = (struct rpdr_ext *) rtproc;
2876 memset (rp, 0, sizeof (struct rpdr_ext));
2878 str = (char *) rtproc + sizeof (struct rpdr_ext) * (count + 2);
2879 strcpy (str, no_name_func);
2880 str += strlen (no_name_func) + 1;
2881 for (i = 0; i < count; i++)
2883 ecoff_swap_rpdr_out (abfd, rpdr + i, erp + i);
2884 strcpy (str, sv[i]);
2885 str += strlen (sv[i]) + 1;
2887 ecoff_put_off (abfd, (bfd_vma) -1, (bfd_byte *) (erp + count)->p_adr);
2889 /* Set the size and contents of .rtproc section. */
2890 s->_raw_size = size;
2891 s->contents = rtproc;
2893 /* Skip this section later on (I don't think this currently
2894 matters, but someday it might). */
2895 s->link_order_head = (struct bfd_link_order *) NULL;
2919 /* A comparison routine used to sort .gptab entries. */
2922 gptab_compare (p1, p2)
2926 const Elf32_gptab *a1 = (const Elf32_gptab *) p1;
2927 const Elf32_gptab *a2 = (const Elf32_gptab *) p2;
2929 return a1->gt_entry.gt_g_value - a2->gt_entry.gt_g_value;
2932 /* We need to use a special link routine to handle the .reginfo and
2933 the .mdebug sections. We need to merge all instances of these
2934 sections together, not write them all out sequentially. */
2937 mips_elf_final_link (abfd, info)
2939 struct bfd_link_info *info;
2943 struct bfd_link_order *p;
2944 asection *reginfo_sec, *mdebug_sec, *gptab_data_sec, *gptab_bss_sec;
2945 asection *rtproc_sec;
2946 Elf32_RegInfo reginfo;
2947 struct ecoff_debug_info debug;
2948 const struct ecoff_debug_swap *swap
2949 = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
2950 HDRR *symhdr = &debug.symbolic_header;
2951 PTR mdebug_handle = NULL;
2953 /* Drop the .options section, since it has special semantics which I
2954 haven't bothered to figure out. */
2955 for (secpp = &abfd->sections; *secpp != NULL; secpp = &(*secpp)->next)
2957 if (strcmp ((*secpp)->name, ".options") == 0)
2959 for (p = (*secpp)->link_order_head; p != NULL; p = p->next)
2960 if (p->type == bfd_indirect_link_order)
2961 p->u.indirect.section->flags &=~ SEC_HAS_CONTENTS;
2962 (*secpp)->link_order_head = NULL;
2963 *secpp = (*secpp)->next;
2964 --abfd->section_count;
2969 /* Get a value for the GP register. */
2970 if (elf_gp (abfd) == 0)
2972 struct bfd_link_hash_entry *h;
2974 h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true);
2975 if (h != (struct bfd_link_hash_entry *) NULL
2976 && h->type == bfd_link_hash_defined)
2977 elf_gp (abfd) = (h->u.def.value
2978 + h->u.def.section->output_section->vma
2979 + h->u.def.section->output_offset);
2980 else if (info->relocateable)
2984 /* Make up a value. */
2986 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2989 && (strcmp (o->name, ".sbss") == 0
2990 || strcmp (o->name, ".sdata") == 0
2991 || strcmp (o->name, ".lit4") == 0
2992 || strcmp (o->name, ".lit8") == 0))
2995 elf_gp (abfd) = lo + ELF_MIPS_GP_OFFSET (abfd);
2999 /* If the relocate_section function needs to do a reloc
3000 involving the GP value, it should make a reloc_dangerous
3001 callback to warn that GP is not defined. */
3005 /* Go through the sections and collect the .reginfo and .mdebug
3009 gptab_data_sec = NULL;
3010 gptab_bss_sec = NULL;
3011 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
3013 if (strcmp (o->name, ".reginfo") == 0)
3015 memset (®info, 0, sizeof reginfo);
3017 /* We have found the .reginfo section in the output file.
3018 Look through all the link_orders comprising it and merge
3019 the information together. */
3020 for (p = o->link_order_head;
3021 p != (struct bfd_link_order *) NULL;
3024 asection *input_section;
3026 Elf32_External_RegInfo ext;
3029 if (p->type != bfd_indirect_link_order)
3031 if (p->type == bfd_fill_link_order)
3036 input_section = p->u.indirect.section;
3037 input_bfd = input_section->owner;
3039 /* The linker emulation code has probably clobbered the
3040 size to be zero bytes. */
3041 if (input_section->_raw_size == 0)
3042 input_section->_raw_size = sizeof (Elf32_External_RegInfo);
3044 if (! bfd_get_section_contents (input_bfd, input_section,
3050 bfd_mips_elf32_swap_reginfo_in (input_bfd, &ext, &sub);
3052 reginfo.ri_gprmask |= sub.ri_gprmask;
3053 reginfo.ri_cprmask[0] |= sub.ri_cprmask[0];
3054 reginfo.ri_cprmask[1] |= sub.ri_cprmask[1];
3055 reginfo.ri_cprmask[2] |= sub.ri_cprmask[2];
3056 reginfo.ri_cprmask[3] |= sub.ri_cprmask[3];
3058 /* ri_gp_value is set by the function
3059 mips_elf_section_processing when the section is
3060 finally written out. */
3062 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3063 elf_link_input_bfd ignores this section. */
3064 input_section->flags &=~ SEC_HAS_CONTENTS;
3067 /* Force the section size to the value we want. */
3068 o->_raw_size = sizeof (Elf32_External_RegInfo);
3070 /* Skip this section later on (I don't think this currently
3071 matters, but someday it might). */
3072 o->link_order_head = (struct bfd_link_order *) NULL;
3077 if (strcmp (o->name, ".mdebug") == 0)
3079 struct extsym_info einfo;
3081 /* We have found the .mdebug section in the output file.
3082 Look through all the link_orders comprising it and merge
3083 the information together. */
3084 symhdr->magic = swap->sym_magic;
3085 /* FIXME: What should the version stamp be? */
3087 symhdr->ilineMax = 0;
3091 symhdr->isymMax = 0;
3092 symhdr->ioptMax = 0;
3093 symhdr->iauxMax = 0;
3095 symhdr->issExtMax = 0;
3098 symhdr->iextMax = 0;
3100 /* We accumulate the debugging information itself in the
3101 debug_info structure. */
3103 debug.external_dnr = NULL;
3104 debug.external_pdr = NULL;
3105 debug.external_sym = NULL;
3106 debug.external_opt = NULL;
3107 debug.external_aux = NULL;
3109 debug.ssext = debug.ssext_end = NULL;
3110 debug.external_fdr = NULL;
3111 debug.external_rfd = NULL;
3112 debug.external_ext = debug.external_ext_end = NULL;
3114 mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info);
3115 if (mdebug_handle == (PTR) NULL)
3118 if (SGI_COMPAT (abfd))
3124 static const char * const name[] =
3125 { ".text", ".init", ".fini", ".data",
3126 ".rodata", ".sdata", ".sbss", ".bss" };
3127 static const int sc[] = { scText, scInit, scFini, scData,
3128 scRData, scSData, scSBss, scBss };
3131 esym.cobol_main = 0;
3135 esym.asym.iss = issNil;
3136 esym.asym.st = stLocal;
3137 esym.asym.reserved = 0;
3138 esym.asym.index = indexNil;
3139 for (i = 0; i < 8; i++)
3141 esym.asym.sc = sc[i];
3142 s = bfd_get_section_by_name (abfd, name[i]);
3145 esym.asym.value = s->vma;
3146 last = s->vma + s->_raw_size;
3149 esym.asym.value = last;
3151 if (! bfd_ecoff_debug_one_external (abfd, &debug, swap,
3157 for (p = o->link_order_head;
3158 p != (struct bfd_link_order *) NULL;
3161 asection *input_section;
3163 const struct ecoff_debug_swap *input_swap;
3164 struct ecoff_debug_info input_debug;
3168 if (p->type != bfd_indirect_link_order)
3170 if (p->type == bfd_fill_link_order)
3175 input_section = p->u.indirect.section;
3176 input_bfd = input_section->owner;
3178 if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour
3179 || (get_elf_backend_data (input_bfd)
3180 ->elf_backend_ecoff_debug_swap) == NULL)
3182 /* I don't know what a non MIPS ELF bfd would be
3183 doing with a .mdebug section, but I don't really
3184 want to deal with it. */
3188 input_swap = (get_elf_backend_data (input_bfd)
3189 ->elf_backend_ecoff_debug_swap);
3191 BFD_ASSERT (p->size == input_section->_raw_size);
3193 /* The ECOFF linking code expects that we have already
3194 read in the debugging information and set up an
3195 ecoff_debug_info structure, so we do that now. */
3196 if (! mips_elf_read_ecoff_info (input_bfd, input_section,
3200 if (! (bfd_ecoff_debug_accumulate
3201 (mdebug_handle, abfd, &debug, swap, input_bfd,
3202 &input_debug, input_swap, info)))
3205 /* Loop through the external symbols. For each one with
3206 interesting information, try to find the symbol in
3207 the linker global hash table and save the information
3208 for the output external symbols. */
3209 eraw_src = input_debug.external_ext;
3210 eraw_end = (eraw_src
3211 + (input_debug.symbolic_header.iextMax
3212 * input_swap->external_ext_size));
3214 eraw_src < eraw_end;
3215 eraw_src += input_swap->external_ext_size)
3219 struct mips_elf_link_hash_entry *h;
3221 (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext);
3222 if (ext.asym.sc == scNil
3223 || ext.asym.sc == scUndefined
3224 || ext.asym.sc == scSUndefined)
3227 name = input_debug.ssext + ext.asym.iss;
3228 h = mips_elf_link_hash_lookup (mips_elf_hash_table (info),
3229 name, false, false, true);
3230 if (h == NULL || h->esym.ifd != -2)
3236 < input_debug.symbolic_header.ifdMax);
3237 ext.ifd = input_debug.ifdmap[ext.ifd];
3243 /* Free up the information we just read. */
3244 free (input_debug.line);
3245 free (input_debug.external_dnr);
3246 free (input_debug.external_pdr);
3247 free (input_debug.external_sym);
3248 free (input_debug.external_opt);
3249 free (input_debug.external_aux);
3250 free (input_debug.ss);
3251 free (input_debug.ssext);
3252 free (input_debug.external_fdr);
3253 free (input_debug.external_rfd);
3254 free (input_debug.external_ext);
3256 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3257 elf_link_input_bfd ignores this section. */
3258 input_section->flags &=~ SEC_HAS_CONTENTS;
3261 if (SGI_COMPAT (abfd) && info->shared)
3263 /* Create .rtproc section. */
3264 rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc");
3265 if (rtproc_sec == NULL)
3267 flagword flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY
3270 rtproc_sec = bfd_make_section (abfd, ".rtproc");
3271 if (rtproc_sec == NULL
3272 || ! bfd_set_section_flags (abfd, rtproc_sec, flags)
3273 || ! bfd_set_section_alignment (abfd, rtproc_sec, 12))
3277 if (! mips_elf_create_procedure_table (mdebug_handle, abfd,
3278 info, rtproc_sec, &debug))
3282 /* Build the external symbol information. */
3285 einfo.debug = &debug;
3287 einfo.failed = false;
3288 mips_elf_link_hash_traverse (mips_elf_hash_table (info),
3289 mips_elf_output_extsym,
3294 /* Set the size of the .mdebug section. */
3295 o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap);
3297 /* Skip this section later on (I don't think this currently
3298 matters, but someday it might). */
3299 o->link_order_head = (struct bfd_link_order *) NULL;
3304 if (strncmp (o->name, ".gptab.", sizeof ".gptab." - 1) == 0)
3306 const char *subname;
3309 Elf32_External_gptab *ext_tab;
3312 /* The .gptab.sdata and .gptab.sbss sections hold
3313 information describing how the small data area would
3314 change depending upon the -G switch. These sections
3315 not used in executables files. */
3316 if (! info->relocateable)
3320 for (p = o->link_order_head;
3321 p != (struct bfd_link_order *) NULL;
3324 asection *input_section;
3326 if (p->type != bfd_indirect_link_order)
3328 if (p->type == bfd_fill_link_order)
3333 input_section = p->u.indirect.section;
3335 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3336 elf_link_input_bfd ignores this section. */
3337 input_section->flags &=~ SEC_HAS_CONTENTS;
3340 /* Skip this section later on (I don't think this
3341 currently matters, but someday it might). */
3342 o->link_order_head = (struct bfd_link_order *) NULL;
3344 /* Really remove the section. */
3345 for (secpp = &abfd->sections;
3347 secpp = &(*secpp)->next)
3349 *secpp = (*secpp)->next;
3350 --abfd->section_count;
3355 /* There is one gptab for initialized data, and one for
3356 uninitialized data. */
3357 if (strcmp (o->name, ".gptab.sdata") == 0)
3359 else if (strcmp (o->name, ".gptab.sbss") == 0)
3363 (*_bfd_error_handler)
3364 ("%s: illegal section name `%s'",
3365 bfd_get_filename (abfd), o->name);
3366 bfd_set_error (bfd_error_nonrepresentable_section);
3370 /* The linker script always combines .gptab.data and
3371 .gptab.sdata into .gptab.sdata, and likewise for
3372 .gptab.bss and .gptab.sbss. It is possible that there is
3373 no .sdata or .sbss section in the output file, in which
3374 case we must change the name of the output section. */
3375 subname = o->name + sizeof ".gptab" - 1;
3376 if (bfd_get_section_by_name (abfd, subname) == NULL)
3378 if (o == gptab_data_sec)
3379 o->name = ".gptab.data";
3381 o->name = ".gptab.bss";
3382 subname = o->name + sizeof ".gptab" - 1;
3383 BFD_ASSERT (bfd_get_section_by_name (abfd, subname) != NULL);
3386 /* Set up the first entry. */
3388 tab = (Elf32_gptab *) bfd_malloc (c * sizeof (Elf32_gptab));
3391 tab[0].gt_header.gt_current_g_value = elf_gp_size (abfd);
3392 tab[0].gt_header.gt_unused = 0;
3394 /* Combine the input sections. */
3395 for (p = o->link_order_head;
3396 p != (struct bfd_link_order *) NULL;
3399 asection *input_section;
3403 bfd_size_type gpentry;
3405 if (p->type != bfd_indirect_link_order)
3407 if (p->type == bfd_fill_link_order)
3412 input_section = p->u.indirect.section;
3413 input_bfd = input_section->owner;
3415 /* Combine the gptab entries for this input section one
3416 by one. We know that the input gptab entries are
3417 sorted by ascending -G value. */
3418 size = bfd_section_size (input_bfd, input_section);
3420 for (gpentry = sizeof (Elf32_External_gptab);
3422 gpentry += sizeof (Elf32_External_gptab))
3424 Elf32_External_gptab ext_gptab;
3425 Elf32_gptab int_gptab;
3431 if (! (bfd_get_section_contents
3432 (input_bfd, input_section, (PTR) &ext_gptab,
3433 gpentry, sizeof (Elf32_External_gptab))))
3439 bfd_mips_elf32_swap_gptab_in (input_bfd, &ext_gptab,
3441 val = int_gptab.gt_entry.gt_g_value;
3442 add = int_gptab.gt_entry.gt_bytes - last;
3445 for (look = 1; look < c; look++)
3447 if (tab[look].gt_entry.gt_g_value >= val)
3448 tab[look].gt_entry.gt_bytes += add;
3450 if (tab[look].gt_entry.gt_g_value == val)
3456 Elf32_gptab *new_tab;
3459 /* We need a new table entry. */
3460 new_tab = ((Elf32_gptab *)
3461 bfd_realloc ((PTR) tab,
3462 (c + 1) * sizeof (Elf32_gptab)));
3463 if (new_tab == NULL)
3469 tab[c].gt_entry.gt_g_value = val;
3470 tab[c].gt_entry.gt_bytes = add;
3472 /* Merge in the size for the next smallest -G
3473 value, since that will be implied by this new
3476 for (look = 1; look < c; look++)
3478 if (tab[look].gt_entry.gt_g_value < val
3480 || (tab[look].gt_entry.gt_g_value
3481 > tab[max].gt_entry.gt_g_value)))
3485 tab[c].gt_entry.gt_bytes +=
3486 tab[max].gt_entry.gt_bytes;
3491 last = int_gptab.gt_entry.gt_bytes;
3494 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3495 elf_link_input_bfd ignores this section. */
3496 input_section->flags &=~ SEC_HAS_CONTENTS;
3499 /* The table must be sorted by -G value. */
3501 qsort (tab + 1, c - 1, sizeof (tab[0]), gptab_compare);
3503 /* Swap out the table. */
3504 ext_tab = ((Elf32_External_gptab *)
3505 bfd_alloc (abfd, c * sizeof (Elf32_External_gptab)));
3506 if (ext_tab == NULL)
3512 for (i = 0; i < c; i++)
3513 bfd_mips_elf32_swap_gptab_out (abfd, tab + i, ext_tab + i);
3516 o->_raw_size = c * sizeof (Elf32_External_gptab);
3517 o->contents = (bfd_byte *) ext_tab;
3519 /* Skip this section later on (I don't think this currently
3520 matters, but someday it might). */
3521 o->link_order_head = (struct bfd_link_order *) NULL;
3525 /* Invoke the regular ELF backend linker to do all the work. */
3526 if (! bfd_elf32_bfd_final_link (abfd, info))
3529 /* Now write out the computed sections. */
3531 if (reginfo_sec != (asection *) NULL)
3533 Elf32_External_RegInfo ext;
3535 bfd_mips_elf32_swap_reginfo_out (abfd, ®info, &ext);
3536 if (! bfd_set_section_contents (abfd, reginfo_sec, (PTR) &ext,
3537 (file_ptr) 0, sizeof ext))
3541 if (mdebug_sec != (asection *) NULL)
3543 BFD_ASSERT (abfd->output_has_begun);
3544 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug,
3546 mdebug_sec->filepos))
3549 bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info);
3552 if (gptab_data_sec != (asection *) NULL)
3554 if (! bfd_set_section_contents (abfd, gptab_data_sec,
3555 gptab_data_sec->contents,
3557 gptab_data_sec->_raw_size))
3561 if (gptab_bss_sec != (asection *) NULL)
3563 if (! bfd_set_section_contents (abfd, gptab_bss_sec,
3564 gptab_bss_sec->contents,
3566 gptab_bss_sec->_raw_size))
3570 if (SGI_COMPAT (abfd))
3572 rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc");
3573 if (rtproc_sec != NULL)
3575 if (! bfd_set_section_contents (abfd, rtproc_sec,
3576 rtproc_sec->contents,
3578 rtproc_sec->_raw_size))
3586 /* Handle a MIPS ELF HI16 reloc. */
3589 mips_elf_relocate_hi16 (input_bfd, relhi, rello, contents, addend)
3591 Elf_Internal_Rela *relhi;
3592 Elf_Internal_Rela *rello;
3599 insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
3601 addlo = bfd_get_32 (input_bfd, contents + rello->r_offset);
3604 addend += ((insn & 0xffff) << 16) + addlo;
3606 if ((addlo & 0x8000) != 0)
3608 if ((addend & 0x8000) != 0)
3611 bfd_put_32 (input_bfd,
3612 (insn & 0xffff0000) | ((addend >> 16) & 0xffff),
3613 contents + relhi->r_offset);
3616 /* Handle a MIPS ELF local GOT16 reloc. */
3619 mips_elf_relocate_got_local (output_bfd, input_bfd, sgot, relhi, rello,
3624 Elf_Internal_Rela *relhi;
3625 Elf_Internal_Rela *rello;
3635 bfd_byte *got_contents;
3636 struct mips_got_info *g;
3638 insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
3640 addlo = bfd_get_32 (input_bfd, contents + rello->r_offset);
3643 addend += ((insn & 0xffff) << 16) + addlo;
3645 if ((addlo & 0x8000) != 0)
3647 if ((addend & 0x8000) != 0)
3650 /* Get a got entry representing requested hipage. */
3651 BFD_ASSERT (elf_section_data (sgot) != NULL);
3652 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
3653 BFD_ASSERT (g != NULL);
3655 local_gotno = g->local_gotno;
3656 got_contents = sgot->contents;
3657 hipage = addend & 0xffff0000;
3659 for (i = MIPS_RESERVED_GOTNO; i < local_gotno; i++)
3661 address = bfd_get_32 (input_bfd, got_contents + i * 4);
3662 if (hipage == (address & 0xffff0000))
3664 if (address == (bfd_vma) 0)
3666 bfd_put_32 (input_bfd, hipage, got_contents + i * 4);
3671 BFD_ASSERT (i < local_gotno);
3673 if (i == local_gotno)
3674 (*_bfd_error_handler)
3675 ("ELF MIPS linker: more got entries are needed for hipage: %x",
3679 i = - ELF_MIPS_GP_OFFSET (output_bfd) + i * 4;
3680 bfd_put_32 (input_bfd, (insn & 0xffff0000) | (i & 0xffff),
3681 contents + relhi->r_offset);
3684 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
3687 mips_elf_relocate_global_got (input_bfd, rel, contents, offset)
3689 Elf_Internal_Rela *rel;
3695 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3696 bfd_put_32 (input_bfd,
3697 (insn & 0xffff0000) | (offset & 0xffff),
3698 contents + rel->r_offset);
3701 /* Relocate a MIPS ELF section. */
3704 mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
3705 contents, relocs, local_syms, local_sections)
3707 struct bfd_link_info *info;
3709 asection *input_section;
3711 Elf_Internal_Rela *relocs;
3712 Elf_Internal_Sym *local_syms;
3713 asection **local_sections;
3715 Elf_Internal_Shdr *symtab_hdr;
3718 asection *sgot, *sreloc, *scpt;
3720 Elf_Internal_Rela *rel;
3721 Elf_Internal_Rela *relend;
3722 struct mips_got_info *g;
3724 dynobj = elf_hash_table (info)->dynobj;
3725 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3729 if (dynobj == NULL || ! SGI_COMPAT (output_bfd))
3732 scpt = bfd_get_section_by_name (dynobj, ".compact_rel");
3735 if (elf_bad_symtab (input_bfd))
3737 locsymcount = symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
3742 locsymcount = symtab_hdr->sh_info;
3743 extsymoff = symtab_hdr->sh_info;
3747 relend = relocs + input_section->reloc_count;
3748 for (; rel < relend; rel++)
3751 reloc_howto_type *howto;
3752 unsigned long r_symndx;
3754 struct elf_link_hash_entry *h;
3756 Elf_Internal_Sym *sym;
3757 bfd_reloc_status_type r;
3759 r_type = ELF32_R_TYPE (rel->r_info);
3760 if (r_type < 0 || r_type >= (int) R_MIPS_max)
3762 bfd_set_error (bfd_error_bad_value);
3765 howto = elf_mips_howto_table + r_type;
3768 && (r_type == R_MIPS_CALL16
3769 || r_type == R_MIPS_GOT16
3770 || r_type == R_MIPS_CALL_HI16
3771 || r_type == R_MIPS_CALL_LO16
3772 || r_type == R_MIPS_GOT_HI16
3773 || r_type == R_MIPS_GOT_LO16))
3775 /* We need the .got section. */
3778 sgot = bfd_get_section_by_name (dynobj, ".got");
3779 BFD_ASSERT (sgot != NULL);
3780 BFD_ASSERT (elf_section_data (sgot) != NULL);
3781 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
3782 BFD_ASSERT (g != NULL);
3786 r_symndx = ELF32_R_SYM (rel->r_info);
3788 /* Mix in the change in GP address for a GP relative reloc. */
3789 if (r_type != R_MIPS_GPREL16
3790 && r_type != R_MIPS_LITERAL
3791 && r_type != R_MIPS_GPREL32)
3795 if (elf_gp (output_bfd) == 0)
3797 if (! ((*info->callbacks->reloc_dangerous)
3799 "GP relative relocation when GP not defined",
3800 input_bfd, input_section,
3803 /* Only give the error once per link. */
3804 elf_gp (output_bfd) = 4;
3807 if (r_symndx < extsymoff
3808 || (elf_bad_symtab (input_bfd)
3809 && local_sections[r_symndx] != NULL))
3811 /* This is a relocation against a section. The current
3812 addend in the instruction is the difference between
3813 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
3814 must change this to be the difference between the
3815 final definition (which will end up in RELOCATION)
3816 and the GP value of OUTPUT_BFD (which is in GP). */
3817 addend = elf_gp (input_bfd) - elf_gp (output_bfd);
3819 else if (! info->relocateable)
3821 /* We are doing a final link. The current addend in the
3822 instruction is simply the desired offset into the
3823 symbol (normally zero). We want the instruction to
3824 hold the difference between the final definition of
3825 the symbol (which will end up in RELOCATION) and the
3826 GP value of OUTPUT_BFD (which is in GP). */
3827 addend = - elf_gp (output_bfd);
3831 /* We are generating relocateable output, and we aren't
3832 going to define this symbol, so we just leave the
3833 instruction alone. */
3841 if (info->relocateable)
3843 /* This is a relocateable link. We don't have to change
3844 anything, unless the reloc is against a section symbol,
3845 in which case we have to adjust according to where the
3846 section symbol winds up in the output section. */
3847 if (r_symndx >= locsymcount
3848 || (elf_bad_symtab (input_bfd)
3849 && local_sections[r_symndx] == NULL))
3853 sym = local_syms + r_symndx;
3854 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
3858 sec = local_sections[r_symndx];
3860 /* It would be logical to add sym->st_value here,
3861 but Irix 5 sometimes generates a garbage symbol
3863 addend += sec->output_offset;
3865 /* If this is HI16 or GOT16 with an associated LO16,
3866 adjust the addend accordingly. Otherwise, just
3868 if ((r_type != R_MIPS_HI16 || r_type == R_MIPS_GOT16)
3869 || (rel + 1) >= relend
3870 || ELF32_R_TYPE ((rel + 1)->r_info) != R_MIPS_LO16)
3871 r = _bfd_relocate_contents (howto, input_bfd,
3873 contents + rel->r_offset);
3876 mips_elf_relocate_hi16 (input_bfd, rel, rel + 1,
3888 /* This is a final link. */
3890 if (r_symndx < extsymoff
3891 || (elf_bad_symtab (input_bfd)
3892 && local_sections[r_symndx] != NULL))
3895 sym = local_syms + r_symndx;
3896 sec = local_sections[r_symndx];
3897 relocation = (sec->output_section->vma
3898 + sec->output_offset);
3900 /* It would be logical to always add sym->st_value here,
3901 but Irix 5 sometimes generates a garbage symbol
3903 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
3904 relocation += sym->st_value;
3911 indx = r_symndx - extsymoff;
3912 h = elf_sym_hashes (input_bfd)[indx];
3913 if (strcmp (h->root.root.string, "_gp_disp") == 0)
3915 if (elf_gp (output_bfd) == 0)
3917 if (! ((*info->callbacks->reloc_dangerous)
3919 "_gp_disp used when GP not defined",
3920 input_bfd, input_section,
3923 /* Only give the error once per link. */
3924 elf_gp (output_bfd) = 4;
3929 sec = input_section;
3930 if (sec->output_section != NULL)
3931 relocation = (elf_gp (output_bfd)
3933 + sec->output_section->vma
3934 + sec->output_offset));
3936 relocation = elf_gp (output_bfd) - rel->r_offset;
3937 if (r_type == R_MIPS_LO16)
3941 else if (h->root.type == bfd_link_hash_defined
3942 || h->root.type == bfd_link_hash_defweak)
3944 sec = h->root.u.def.section;
3945 if (sec->output_section == NULL)
3948 relocation = (h->root.u.def.value
3949 + sec->output_section->vma
3950 + sec->output_offset);
3952 else if (h->root.type == bfd_link_hash_undefweak)
3954 else if (info->shared && ! info->symbolic)
3958 if (! ((*info->callbacks->undefined_symbol)
3959 (info, h->root.root.string, input_bfd,
3960 input_section, rel->r_offset)))
3966 if (r_type == R_MIPS_HI16
3967 && (rel + 1) < relend
3968 && ELF32_R_TYPE ((rel + 1)->r_info) == R_MIPS_LO16)
3970 mips_elf_relocate_hi16 (input_bfd, rel, rel + 1,
3971 contents, relocation + addend);
3974 else if (r_type == R_MIPS_GOT16 && local)
3976 /* GOT16 must be also with associated LO16 in the local
3977 case. In this case, the addend is extracted and the
3978 section in which the referenced object is determined.
3979 Then the final address of the object is computed and
3980 the GOT entry for the hipage (an aligned 64kb chunk)
3981 is added to .got section if needed. The offset field
3982 of the GOT16-relocated instruction is replaced by the
3983 index of this GOT entry for the hipage. */
3984 if ((rel + 1) < relend
3985 && ELF32_R_TYPE ((rel + 1)->r_info) == R_MIPS_LO16)
3987 mips_elf_relocate_got_local (output_bfd, input_bfd, sgot,
3990 relocation + addend);
3994 r = bfd_reloc_outofrange;
3996 else if (r_type == R_MIPS_CALL16
3997 || r_type == R_MIPS_GOT16
3998 || r_type == R_MIPS_CALL_LO16
3999 || r_type == R_MIPS_GOT_LO16)
4003 /* This symbol must be registered as a global symbol
4004 having the corresponding got entry. */
4005 BFD_ASSERT (h->got_offset != (bfd_vma) -1);
4007 offset = (h->dynindx - g->global_gotsym + g->local_gotno) * 4;
4008 BFD_ASSERT (g->local_gotno <= offset
4009 && offset < sgot->_raw_size);
4010 bfd_put_32 (output_bfd, relocation + addend,
4011 sgot->contents + offset);
4012 offset = (sgot->output_section->vma + sgot->output_offset
4013 + offset - elf_gp (output_bfd));
4014 mips_elf_relocate_global_got (input_bfd, rel, contents,
4018 else if (r_type == R_MIPS_CALL_HI16
4019 || r_type == R_MIPS_GOT_HI16)
4023 /* This must be a global symbol with a got entry. The
4024 next reloc must be the corresponding LO16 reloc. */
4025 BFD_ASSERT (h != NULL && h->got_offset != (bfd_vma) -1);
4026 BFD_ASSERT ((rel + 1) < relend);
4027 BFD_ASSERT (ELF32_R_TYPE ((rel + 1)->r_info)
4028 == (r_type == R_MIPS_CALL_HI16
4030 : R_MIPS_GOT_LO16));
4032 offset = (h->dynindx - g->global_gotsym + g->local_gotno) * 4;
4033 BFD_ASSERT (g->local_gotno <= offset
4034 && offset < sgot->_raw_size);
4035 bfd_put_32 (output_bfd, relocation + addend,
4036 sgot->contents + offset);
4037 offset = (sgot->output_section->vma + sgot->output_offset
4038 + offset - elf_gp (output_bfd));
4039 mips_elf_relocate_hi16 (input_bfd, rel, rel + 1, contents,
4043 else if (r_type == R_MIPS_REL32
4044 || r_type == R_MIPS_32)
4046 Elf_Internal_Rel outrel;
4047 Elf32_crinfo cptrel;
4051 && (input_section->flags & SEC_ALLOC) != 0)
4053 /* When generating a shared object, these
4054 relocations are copied into the output file to be
4055 resolved at run time. */
4058 sreloc = bfd_get_section_by_name (dynobj, ".rel.dyn");
4059 BFD_ASSERT (sreloc != NULL);
4062 outrel.r_offset = (rel->r_offset
4063 + input_section->output_section->vma
4064 + input_section->output_offset);
4066 addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
4070 BFD_ASSERT (h->dynindx != -1);
4071 outrel.r_info = ELF32_R_INFO (h->dynindx, R_MIPS_REL32);
4072 sec = input_section;
4078 sym = local_syms + r_symndx;
4080 BFD_ASSERT (ELF_ST_TYPE (sym->st_info) == STT_SECTION);
4082 sec = local_sections[r_symndx];
4083 if (sec != NULL && bfd_is_abs_section (sec))
4085 else if (sec == NULL || sec->owner == NULL)
4087 bfd_set_error (bfd_error_bad_value);
4094 osec = sec->output_section;
4095 indx = elf_section_data (osec)->dynindx;
4100 outrel.r_info = ELF32_R_INFO (indx, R_MIPS_REL32);
4101 addend += relocation;
4104 bfd_put_32 (output_bfd, addend, contents + rel->r_offset);
4105 bfd_elf32_swap_reloc_out (output_bfd, &outrel,
4106 (((Elf32_External_Rel *)
4108 + sreloc->reloc_count));
4109 ++sreloc->reloc_count;
4111 if (SGI_COMPAT (output_bfd))
4116 /* Make an entry of compact relocation info. */
4117 mips_elf_set_cr_format (cptrel, CRF_MIPS_LONG);
4118 cptrel.vaddr = (rel->r_offset
4119 + input_section->output_section->vma
4120 + input_section->output_offset);
4121 if (r_type == R_MIPS_REL32)
4122 mips_elf_set_cr_type (cptrel, CRT_MIPS_REL32);
4124 mips_elf_set_cr_type (cptrel, CRT_MIPS_WORD);
4125 cptrel.konst = addend;
4127 cr = (scpt->contents
4128 + sizeof (Elf32_External_compact_rel));
4129 bfd_elf32_swap_crinfo_out (output_bfd, &cptrel,
4130 ((Elf32_External_crinfo *) cr
4131 + scpt->reloc_count));
4132 ++scpt->reloc_count;
4135 /* This reloc will be computed at runtime, so
4136 there's no need to do anything now. */
4140 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4141 contents, rel->r_offset,
4142 relocation, addend);
4145 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4146 contents, rel->r_offset,
4147 relocation, addend);
4149 if (SGI_COMPAT (abfd)
4151 && (input_section->flags & SEC_ALLOC) != 0)
4153 Elf32_crinfo cptrel;
4156 /* Make an entry of compact relocation info. */
4157 mips_elf_set_cr_format (cptrel, CRF_MIPS_LONG);
4158 cptrel.vaddr = (rel->r_offset
4159 + input_section->output_section->vma
4160 + input_section->output_offset);
4165 mips_elf_set_cr_type (cptrel, CRT_MIPS_JMPAD);
4166 cptrel.konst = addend;
4167 cr = scpt->contents + sizeof (Elf32_External_compact_rel);
4168 bfd_elf32_swap_crinfo_out (output_bfd, &cptrel,
4169 ((Elf32_External_crinfo *) cr
4170 + scpt->reloc_count));
4171 ++scpt->reloc_count;
4174 case R_MIPS_GPREL16:
4175 case R_MIPS_LITERAL:
4176 case R_MIPS_GPREL32:
4177 mips_elf_set_cr_type (cptrel, CRT_MIPS_GPHI_LO);
4178 cptrel.konst = elf_gp (output_bfd) - cptrel.vaddr;
4179 cr = scpt->contents + sizeof (Elf32_External_compact_rel);
4180 bfd_elf32_swap_crinfo_out (output_bfd, &cptrel,
4181 ((Elf32_External_crinfo *) cr
4182 + scpt->reloc_count));
4183 ++scpt->reloc_count;
4192 if (r != bfd_reloc_ok)
4197 case bfd_reloc_outofrange:
4199 case bfd_reloc_overflow:
4204 name = h->root.root.string;
4207 name = bfd_elf_string_from_elf_section (input_bfd,
4208 symtab_hdr->sh_link,
4213 name = bfd_section_name (input_bfd, sec);
4215 if (! ((*info->callbacks->reloc_overflow)
4216 (info, name, howto->name, (bfd_vma) 0,
4217 input_bfd, input_section, rel->r_offset)))
4228 /* Functions for the dynamic linker. */
4230 /* The name of the dynamic interpreter. This is put in the .interp
4233 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
4235 /* Create dynamic sections when linking against a dynamic object. */
4236 static boolean mips_elf_create_got_section (bfd *, struct bfd_link_info *);
4239 mips_elf_create_dynamic_sections (abfd, info)
4241 struct bfd_link_info *info;
4243 struct elf_link_hash_entry *h;
4245 register asection *s;
4246 const char * const *namep;
4248 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4251 /* Mips ABI requests the .dynamic section to be read only. */
4252 s = bfd_get_section_by_name (abfd, ".dynamic");
4255 if (! bfd_set_section_flags (abfd, s, flags))
4259 /* We need to create .got section. */
4260 if (! mips_elf_create_got_section (abfd, info))
4263 /* Create .stub section. */
4264 if (bfd_get_section_by_name (abfd, ".stub") == NULL)
4266 s = bfd_make_section (abfd, ".stub");
4268 || ! bfd_set_section_flags (abfd, s, flags)
4269 || ! bfd_set_section_alignment (abfd, s, 2))
4273 if (SGI_COMPAT (abfd))
4275 for (namep = mips_elf_dynsym_rtproc_names; *namep != NULL; namep++)
4278 if (! (_bfd_generic_link_add_one_symbol
4279 (info, abfd, *namep, BSF_GLOBAL, bfd_und_section_ptr,
4280 (bfd_vma) 0, (const char *) NULL, false,
4281 get_elf_backend_data (abfd)->collect,
4282 (struct bfd_link_hash_entry **) &h)))
4284 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
4285 h->type = STT_SECTION;
4288 && ! bfd_elf32_link_record_dynamic_symbol (info, h))
4292 /* Create .compact_rel section. */
4293 if (bfd_get_section_by_name (abfd, ".compact_rel") == NULL)
4295 flags = SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_READONLY;
4297 s = bfd_make_section (abfd, ".compact_rel");
4299 || ! bfd_set_section_flags (abfd, s, flags)
4300 || ! bfd_set_section_alignment (abfd, s, 2))
4304 s->_raw_size = sizeof (Elf32_compact_rel);
4306 /* Change aligments of some sections. */
4307 s = bfd_get_section_by_name (abfd, ".hash");
4309 bfd_set_section_alignment (abfd, s, 4);
4310 s = bfd_get_section_by_name (abfd, ".dynsym");
4312 bfd_set_section_alignment (abfd, s, 4);
4313 s = bfd_get_section_by_name (abfd, ".dynstr");
4315 bfd_set_section_alignment (abfd, s, 4);
4316 s = bfd_get_section_by_name (abfd, ".reginfo");
4318 bfd_set_section_alignment (abfd, s, 4);
4319 s = bfd_get_section_by_name (abfd, ".dynamic");
4321 bfd_set_section_alignment (abfd, s, 4);
4327 /* Create the .got section to hold the global offset table. */
4330 mips_elf_create_got_section (abfd, info)
4332 struct bfd_link_info *info;
4335 register asection *s;
4336 struct elf_link_hash_entry *h;
4337 struct mips_got_info *g;
4339 /* This function may be called more than once. */
4340 if (bfd_get_section_by_name (abfd, ".got") != NULL)
4343 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
4345 s = bfd_make_section (abfd, ".got");
4347 || ! bfd_set_section_flags (abfd, s, flags)
4348 || ! bfd_set_section_alignment (abfd, s, 4))
4351 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
4352 linker script because we don't want to define the symbol if we
4353 are not creating a global offset table. XXX Should this be
4354 defined at the start of the .got section, even if .got section is
4355 accessed by using 16 bit signed offset? */
4357 if (! (_bfd_generic_link_add_one_symbol
4358 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
4359 (bfd_vma) 0, (const char *) NULL, false,
4360 get_elf_backend_data (abfd)->collect,
4361 (struct bfd_link_hash_entry **) &h)))
4363 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
4364 h->type = STT_OBJECT;
4367 && ! bfd_elf32_link_record_dynamic_symbol (info, h))
4370 /* The first several global offset table entries are reserved. */
4371 s->_raw_size = MIPS_RESERVED_GOTNO * 4;
4373 g = (struct mips_got_info *) bfd_alloc (abfd,
4374 sizeof (struct mips_got_info));
4377 g->global_gotsym = 0;
4378 g->local_gotno = MIPS_RESERVED_GOTNO;
4379 if (elf_section_data (s) == NULL)
4382 (PTR) bfd_zalloc (abfd, sizeof (struct bfd_elf_section_data));
4383 if (elf_section_data (s) == NULL)
4386 elf_section_data (s)->tdata = (PTR) g;
4391 /* Look through the relocs for a section during the first phase, and
4392 allocate space in the global offset table. */
4395 mips_elf_check_relocs (abfd, info, sec, relocs)
4397 struct bfd_link_info *info;
4399 const Elf_Internal_Rela *relocs;
4402 Elf_Internal_Shdr *symtab_hdr;
4403 struct elf_link_hash_entry **sym_hashes;
4404 struct mips_got_info *g;
4406 const Elf_Internal_Rela *rel;
4407 const Elf_Internal_Rela *rel_end;
4412 if (info->relocateable)
4415 dynobj = elf_hash_table (info)->dynobj;
4416 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4417 sym_hashes = elf_sym_hashes (abfd);
4418 extsymoff = (elf_bad_symtab (abfd)) ? 0 : symtab_hdr->sh_info;
4422 if (SGI_COMPAT (abfd) && dynobj != NULL)
4423 scpt = bfd_get_section_by_name (dynobj, ".compact_rel");
4427 rel_end = relocs + sec->reloc_count;
4428 for (rel = relocs; rel < rel_end; rel++)
4430 unsigned long r_symndx;
4431 struct elf_link_hash_entry *h;
4433 r_symndx = ELF32_R_SYM (rel->r_info);
4435 if (r_symndx < extsymoff)
4438 h = sym_hashes[r_symndx - extsymoff];
4440 /* Some relocs require a global offset table. */
4443 switch (ELF32_R_TYPE (rel->r_info))
4447 case R_MIPS_CALL_HI16:
4448 case R_MIPS_CALL_LO16:
4449 case R_MIPS_GOT_HI16:
4450 case R_MIPS_GOT_LO16:
4451 elf_hash_table (info)->dynobj = dynobj = abfd;
4452 if (! mips_elf_create_got_section (dynobj, info))
4461 switch (ELF32_R_TYPE (rel->r_info))
4464 case R_MIPS_CALL_HI16:
4465 case R_MIPS_CALL_LO16:
4466 /* This symbol requires a global offset table entry. */
4469 sgot = bfd_get_section_by_name (dynobj, ".got");
4470 BFD_ASSERT (sgot != NULL);
4471 BFD_ASSERT (elf_section_data (sgot) != NULL);
4472 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
4473 BFD_ASSERT (g != NULL);
4476 BFD_ASSERT (h != NULL);
4478 /* Make sure this symbol is output as a dynamic symbol. */
4479 if (h->dynindx == -1)
4481 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
4485 if (h->got_offset != (bfd_vma) -1)
4487 /* We have already allocated space in the .got. */
4491 /* Note the index of the first global got symbol in .dynsym. */
4492 if (g->global_gotsym == 0
4493 || g->global_gotsym > (unsigned long) h->dynindx)
4494 g->global_gotsym = h->dynindx;
4496 /* Make this symbol to have the corresponding got entry. */
4499 /* We need a stub, not a plt entry for the undefined
4500 function. But we record it as if it needs plt. See
4501 elf_adjust_dynamic_symbol in elflink.h. */
4502 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
4508 case R_MIPS_GOT_HI16:
4509 case R_MIPS_GOT_LO16:
4510 /* This symbol requires a global offset table entry. */
4513 sgot = bfd_get_section_by_name (dynobj, ".got");
4514 BFD_ASSERT (sgot != NULL);
4515 BFD_ASSERT (elf_section_data (sgot) != NULL);
4516 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
4517 BFD_ASSERT (g != NULL);
4522 /* Make sure this symbol is output as a dynamic symbol. */
4523 if (h->dynindx == -1)
4525 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
4529 if (h->got_offset != (bfd_vma) -1)
4531 /* We have already allocated space in the .got. */
4534 /* Note the index of the first global got symbol in
4536 if (g->global_gotsym == 0
4537 || g->global_gotsym > (unsigned long) h->dynindx)
4538 g->global_gotsym = h->dynindx;
4540 /* Make this symbol to be the global got symbol. */
4549 && (sec->flags & SEC_ALLOC) != 0)
4551 /* When creating a shared object, we must copy these
4552 reloc types into the output file as R_MIPS_REL32
4553 relocs. We create the .rel.dyn reloc section in
4554 dynobj and make room for this reloc. */
4557 const char *name = ".rel.dyn";
4559 sreloc = bfd_get_section_by_name (dynobj, name);
4562 sreloc = bfd_make_section (dynobj, name);
4564 || ! bfd_set_section_flags (dynobj, sreloc,
4570 || ! bfd_set_section_alignment (dynobj, sreloc, 4))
4573 /* Add a null element. */
4574 sreloc->_raw_size += sizeof (Elf32_External_Rel);
4575 ++sreloc->reloc_count;
4579 sreloc->_raw_size += sizeof (Elf32_External_Rel);
4582 scpt->_raw_size += sizeof (Elf32_External_crinfo);
4588 case R_MIPS_GPREL16:
4589 case R_MIPS_LITERAL:
4590 case R_MIPS_GPREL32:
4592 scpt->_raw_size += sizeof (Elf32_External_crinfo);
4603 /* Adjust a symbol defined by a dynamic object and referenced by a
4604 regular object. The current definition is in some section of the
4605 dynamic object, but we're not including those sections. We have to
4606 change the definition to something the rest of the link can
4610 mips_elf_adjust_dynamic_symbol (info, h)
4611 struct bfd_link_info *info;
4612 struct elf_link_hash_entry *h;
4617 dynobj = elf_hash_table (info)->dynobj;
4619 /* Make sure we know what is going on here. */
4620 BFD_ASSERT (dynobj != NULL
4621 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
4622 || h->weakdef != NULL
4623 || ((h->elf_link_hash_flags
4624 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
4625 && (h->elf_link_hash_flags
4626 & ELF_LINK_HASH_REF_REGULAR) != 0
4627 && (h->elf_link_hash_flags
4628 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
4630 /* For a function, create a stub, if needed. */
4631 if (h->type == STT_FUNC
4632 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
4634 if (! elf_hash_table (info)->dynamic_sections_created)
4637 /* If this symbol is not defined in a regular file, then set
4638 the symbol to the stub location. This is required to make
4639 function pointers compare as equal between the normal
4640 executable and the shared library. */
4641 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
4643 /* We need .stub section. */
4644 s = bfd_get_section_by_name (dynobj, ".stub");
4645 BFD_ASSERT (s != NULL);
4647 h->root.u.def.section = s;
4648 h->root.u.def.value = s->_raw_size;
4650 /* XXX Write this stub address somewhere. */
4651 h->plt_offset = s->_raw_size;
4653 /* Make room for this stub code. */
4654 s->_raw_size += MIPS_FUNCTION_STUB_SIZE;
4656 /* The last half word of the stub will be filled with the index
4657 of this symbol in .dynsym section. */
4662 /* If this is a weak symbol, and there is a real definition, the
4663 processor independent code will have arranged for us to see the
4664 real definition first, and we can just use the same value. */
4665 if (h->weakdef != NULL)
4667 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
4668 || h->weakdef->root.type == bfd_link_hash_defweak);
4669 h->root.u.def.section = h->weakdef->root.u.def.section;
4670 h->root.u.def.value = h->weakdef->root.u.def.value;
4674 /* This is a reference to a symbol defined by a dynamic object which
4675 is not a function. */
4680 /* Set the sizes of the dynamic sections. */
4683 mips_elf_size_dynamic_sections (output_bfd, info)
4685 struct bfd_link_info *info;
4691 struct mips_got_info *g;
4693 dynobj = elf_hash_table (info)->dynobj;
4694 BFD_ASSERT (dynobj != NULL);
4696 if (elf_hash_table (info)->dynamic_sections_created)
4698 /* Set the contents of the .interp section to the interpreter. */
4701 s = bfd_get_section_by_name (dynobj, ".interp");
4702 BFD_ASSERT (s != NULL);
4703 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
4704 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4708 /* Recompute the size of .got for local entires (reserved and
4709 hipages) if needed. To estimate it, get the upper bound of total
4710 size of loadable sections. */
4711 sgot = bfd_get_section_by_name (dynobj, ".got");
4715 bfd_size_type loadable_size = 0;
4716 bfd_size_type local_gotno;
4719 BFD_ASSERT (elf_section_data (sgot) != NULL);
4720 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
4721 BFD_ASSERT (g != NULL);
4723 for (sub = info->input_bfds; sub; sub = sub->link_next)
4724 for (s = sub->sections; s != NULL; s = s->next)
4726 if ((s->flags & SEC_ALLOC) == 0)
4728 loadable_size += (s->_raw_size + 0xf) & ~0xf;
4731 loadable_size += MIPS_FUNCTION_STUB_SIZE;
4733 /* Assume there are two loadable segments consisting of
4734 contiguous sections. Is 5 enough? */
4735 local_gotno = (loadable_size >> 16) + 5 + MIPS_RESERVED_GOTNO;
4736 g->local_gotno = local_gotno;
4737 sgot->_raw_size += local_gotno * 4;
4740 /* The check_relocs and adjust_dynamic_symbol entry points have
4741 determined the sizes of the various dynamic sections. Allocate
4744 for (s = dynobj->sections; s != NULL; s = s->next)
4749 /* It's OK to base decisions on the section name, because none
4750 of the dynobj section names depend upon the input files. */
4751 name = bfd_get_section_name (dynobj, s);
4753 if ((s->flags & SEC_IN_MEMORY) == 0)
4758 if (strncmp (name, ".rel", 4) == 0)
4760 if (s->_raw_size == 0)
4766 /* If this relocation section applies to a read only
4767 section, then we probably need a DT_TEXTREL entry.
4768 If the relocation section is .rel.dyn, we always
4769 assert a DT_TEXTREL entry rather than testing whether
4770 there exists a relocation to a read only section or
4772 target = bfd_get_section_by_name (output_bfd, name + 4);
4773 if ((target != NULL && (target->flags & SEC_READONLY) != 0)
4774 || strcmp (name, ".rel.dyn") == 0)
4777 /* We use the reloc_count field as a counter if we need
4778 to copy relocs into the output file. */
4779 if (strcmp (name, ".rel.dyn") != 0)
4783 else if (strncmp (name, ".got", 4) == 0)
4787 BFD_ASSERT (elf_section_data (s) != NULL);
4788 g = (struct mips_got_info *) elf_section_data (s)->tdata;
4789 BFD_ASSERT (g != NULL);
4791 /* Fix the size of .got section for the correspondence of
4792 global symbols and got entries. This adds some useless
4793 got entries. Is this required by ABI really? */
4794 i = elf_hash_table (info)->dynsymcount - g->global_gotsym;
4795 s->_raw_size += i * 4;
4797 else if (strncmp (name, ".stub", 5) == 0)
4799 /* Irix rld assumes that the function stub isn't at the end
4800 of .text section. So put a dummy. XXX */
4801 s->_raw_size += MIPS_FUNCTION_STUB_SIZE;
4803 else if (strncmp (name, ".init", 5) != 0
4804 && (! SGI_COMPAT (output_bfd)
4805 || strncmp (name, ".compact_rel", 12) != 0))
4807 /* It's not one of our sections, so don't allocate space. */
4815 for (spp = &s->output_section->owner->sections;
4816 *spp != s->output_section;
4817 spp = &(*spp)->next)
4819 *spp = s->output_section->next;
4820 --s->output_section->owner->section_count;
4825 /* Allocate memory for the section contents. */
4826 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
4827 if (s->contents == NULL && s->_raw_size != 0)
4829 bfd_set_error (bfd_error_no_memory);
4832 memset (s->contents, 0, s->_raw_size);
4835 if (elf_hash_table (info)->dynamic_sections_created)
4837 /* Add some entries to the .dynamic section. We fill in the
4838 values later, in elf_mips_finish_dynamic_sections, but we
4839 must add the entries now so that we get the correct size for
4840 the .dynamic section. The DT_DEBUG entry is filled in by the
4841 dynamic linker and used by the debugger. */
4844 if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
4850 if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
4854 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0))
4857 if (bfd_get_section_by_name (dynobj, ".rel.dyn"))
4859 if (! bfd_elf32_add_dynamic_entry (info, DT_REL, 0))
4862 if (! bfd_elf32_add_dynamic_entry (info, DT_RELSZ, 0))
4865 if (! bfd_elf32_add_dynamic_entry (info, DT_RELENT, 0))
4869 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_CONFLICTNO, 0))
4872 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_LIBLISTNO, 0))
4875 if (bfd_get_section_by_name (dynobj, ".conflict"))
4877 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_CONFLICT, 0))
4880 s = bfd_get_section_by_name (dynobj, ".liblist");
4881 BFD_ASSERT (s != NULL);
4883 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_LIBLIST, 0))
4887 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_RLD_VERSION, 0))
4890 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_FLAGS, 0))
4893 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_TIME_STAMP, 0))
4897 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_ICHECKSUM, 0))
4902 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_IVERSION, 0))
4906 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_BASE_ADDRESS, 0))
4909 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_LOCAL_GOTNO, 0))
4912 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_SYMTABNO, 0))
4915 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_UNREFEXTNO, 0))
4918 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_GOTSYM, 0))
4921 if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_HIPAGENO, 0))
4924 #if 0 /* (SGI_COMPAT) */
4925 if (! bfd_get_section_by_name (dynobj, ".init"))
4926 if (! bfd_elf32_add_dynamic_entry (info, DT_INIT, 0))
4929 if (! bfd_get_section_by_name (dynobj, ".fini"))
4930 if (! bfd_elf32_add_dynamic_entry (info, DT_FINI, 0))
4935 /* If we are generating a shared library, we generate a section
4936 symbol for each output section. These are local symbols, which
4937 means that they must come first in the dynamic symbol table.
4938 That means we must increment the dynamic symbol index of every
4939 other dynamic symbol. */
4942 const char * const *namep;
4944 bfd_size_type strindex;
4945 struct bfd_strtab_hash *dynstr;
4946 struct mips_got_info *g;
4948 if (SGI_COMPAT (output_bfd))
4950 c = SIZEOF_MIPS_DYNSYM_SECNAMES - 1;
4951 elf_link_hash_traverse (elf_hash_table (info),
4952 mips_elf_adjust_dynindx,
4954 elf_hash_table (info)->dynsymcount += c;
4956 dynstr = elf_hash_table (info)->dynstr;
4957 BFD_ASSERT (dynstr != NULL);
4959 for (i = 1, namep = mips_elf_dynsym_sec_names;
4963 s = bfd_get_section_by_name (output_bfd, *namep);
4965 elf_section_data (s)->dynindx = i;
4967 strindex = _bfd_stringtab_add (dynstr, *namep, true, false);
4968 if (strindex == (bfd_size_type) -1)
4971 mips_elf_hash_table (info)->dynsym_sec_strindex[i] = strindex;
4976 c = bfd_count_sections (output_bfd);
4977 elf_link_hash_traverse (elf_hash_table (info),
4978 mips_elf_adjust_dynindx,
4980 elf_hash_table (info)->dynsymcount += c;
4982 for (i = 1, s = output_bfd->sections; s != NULL; s = s->next, i++)
4984 elf_section_data (s)->dynindx = i;
4985 /* These symbols will have no names, so we don't need to
4986 fiddle with dynstr_index. */
4990 s = bfd_get_section_by_name (dynobj, ".got");
4991 BFD_ASSERT (s != NULL);
4992 BFD_ASSERT (elf_section_data (s) != NULL);
4993 g = (struct mips_got_info *) elf_section_data (s)->tdata;
4994 BFD_ASSERT (g != NULL);
4996 /* If there are no global got symbols, fake the last symbol so for
4998 if (g->global_gotsym)
4999 g->global_gotsym += c;
5001 g->global_gotsym = elf_hash_table (info)->dynsymcount - 1;
5007 /* Increment the index of a dynamic symbol by a given amount. Called
5008 via elf_link_hash_traverse. */
5011 mips_elf_adjust_dynindx (h, cparg)
5012 struct elf_link_hash_entry *h;
5015 int *cp = (int *) cparg;
5017 if (h->dynindx != -1)
5022 /* Finish up dynamic symbol handling. We set the contents of various
5023 dynamic sections here. */
5026 mips_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
5028 struct bfd_link_info *info;
5029 struct elf_link_hash_entry *h;
5030 Elf_Internal_Sym *sym;
5035 struct mips_got_info *g;
5038 dynobj = elf_hash_table (info)->dynobj;
5039 gval = sym->st_value;
5041 if (h->plt_offset != (bfd_vma) -1)
5045 bfd_byte stub[MIPS_FUNCTION_STUB_SIZE];
5047 /* This symbol has a stub. Set it up. */
5049 BFD_ASSERT (h->dynindx != -1);
5051 s = bfd_get_section_by_name (dynobj, ".stub");
5052 BFD_ASSERT (s != NULL);
5054 /* Fill the stub. */
5056 bfd_put_32 (output_bfd, STUB_LW(output_bfd), p);
5058 bfd_put_32 (output_bfd, STUB_MOVE, p);
5061 /* FIXME: Can h->dynindex be more than 64K? */
5062 if (h->dynindx & 0xffff0000)
5065 bfd_put_32 (output_bfd, STUB_JALR, p);
5067 bfd_put_32 (output_bfd, STUB_LI16 + h->dynindx, p);
5069 BFD_ASSERT (h->plt_offset <= s->_raw_size);
5070 memcpy (s->contents + h->plt_offset, stub, MIPS_FUNCTION_STUB_SIZE);
5072 /* Mark the symbol as undefined. plt_offset != -1 occurs
5073 only for the referenced symbol. */
5074 sym->st_shndx = SHN_UNDEF;
5076 /* The run-time linker uses the st_value field of the symbol
5077 to reset the global offset table entry for this external
5078 to its stub address when unlinking a shared object. */
5079 gval = s->output_section->vma + s->output_offset + h->plt_offset;
5080 sym->st_value = gval;
5083 BFD_ASSERT (h->dynindx != -1);
5085 sgot = bfd_get_section_by_name (dynobj, ".got");
5086 BFD_ASSERT (sgot != NULL);
5087 BFD_ASSERT (elf_section_data (sgot) != NULL);
5088 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
5089 BFD_ASSERT (g != NULL);
5091 if ((unsigned long) h->dynindx >= g->global_gotsym)
5093 bfd_size_type offset;
5095 /* This symbol has an entry in the global offset table. Set its
5096 value to the corresponding got entry, if needed. */
5097 if (h->got_offset == (bfd_vma) -1)
5099 offset = (h->dynindx - g->global_gotsym + g->local_gotno) * 4;
5100 BFD_ASSERT (g->local_gotno * 4 <= offset
5101 && offset < sgot->_raw_size);
5102 bfd_put_32 (output_bfd, gval, sgot->contents + offset);
5106 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
5107 name = h->root.root.string;
5108 if (strcmp (name, "_DYNAMIC") == 0
5109 || strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
5110 sym->st_shndx = SHN_ABS;
5112 if (SGI_COMPAT (output_bfd))
5114 if (strcmp (name, "_gp_disp") == 0)
5116 sym->st_shndx = SHN_ABS;
5117 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
5118 sym->st_value = elf_gp (output_bfd);
5120 else if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0
5121 || strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0)
5123 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
5124 sym->st_other = STO_PROTECTED;
5126 sym->st_shndx = SHN_MIPS_DATA;
5128 else if (strcmp (name, mips_elf_dynsym_rtproc_names[2]) == 0)
5130 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
5131 sym->st_other = STO_PROTECTED;
5132 sym->st_value = mips_elf_hash_table (info)->procedure_count;
5133 sym->st_shndx = SHN_ABS;
5136 if (sym->st_shndx != SHN_UNDEF)
5138 if (h->type == STT_FUNC)
5139 sym->st_shndx = SHN_MIPS_TEXT;
5140 else if (h->type == STT_OBJECT)
5141 sym->st_shndx = SHN_MIPS_DATA;
5148 /* Finish up the dynamic sections. */
5151 mips_elf_finish_dynamic_sections (output_bfd, info)
5153 struct bfd_link_info *info;
5158 struct mips_got_info *g;
5160 dynobj = elf_hash_table (info)->dynobj;
5162 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
5164 sgot = bfd_get_section_by_name (dynobj, ".got");
5165 BFD_ASSERT (sgot != NULL);
5167 BFD_ASSERT (elf_section_data (sgot) != NULL);
5168 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
5169 BFD_ASSERT (g != NULL);
5171 if (elf_hash_table (info)->dynamic_sections_created)
5173 Elf32_External_Dyn *dyncon, *dynconend;
5175 BFD_ASSERT (sdyn != NULL);
5177 dyncon = (Elf32_External_Dyn *) sdyn->contents;
5178 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
5179 for (; dyncon < dynconend; dyncon++)
5181 Elf_Internal_Dyn dyn;
5186 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
5194 s = bfd_get_section_by_name (dynobj, ".rel.dyn");
5195 BFD_ASSERT (s != NULL);
5196 dyn.d_un.d_val = sizeof (Elf32_External_Rel);
5197 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5201 /* Rewrite DT_STRSZ. */
5203 _bfd_stringtab_size (elf_hash_table (info)->dynstr);
5204 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5210 case DT_MIPS_CONFLICT:
5213 case DT_MIPS_LIBLIST:
5216 s = bfd_get_section_by_name (output_bfd, name);
5217 BFD_ASSERT (s != NULL);
5218 dyn.d_un.d_ptr = s->vma;
5219 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5222 case DT_MIPS_RLD_VERSION:
5223 dyn.d_un.d_val = 1; /* XXX */
5224 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5228 dyn.d_un.d_val = RHF_NOTPOT; /* XXX */
5229 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5232 case DT_MIPS_CONFLICTNO:
5234 elemsize = sizeof (Elf32_Conflict);
5237 case DT_MIPS_LIBLISTNO:
5239 elemsize = sizeof (Elf32_Lib);
5241 s = bfd_get_section_by_name (output_bfd, name);
5244 if (s->_cooked_size != 0)
5245 dyn.d_un.d_val = s->_cooked_size / elemsize;
5247 dyn.d_un.d_val = s->_raw_size / elemsize;
5252 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5255 case DT_MIPS_TIME_STAMP:
5256 time ((time_t *) &dyn.d_un.d_val);
5257 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5260 case DT_MIPS_ICHECKSUM:
5264 case DT_MIPS_IVERSION:
5268 case DT_MIPS_BASE_ADDRESS:
5269 s = output_bfd->sections;
5270 BFD_ASSERT (s != NULL);
5271 dyn.d_un.d_ptr = s->vma & ~(0xffff);
5272 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5275 case DT_MIPS_LOCAL_GOTNO:
5276 dyn.d_un.d_val = g->local_gotno;
5277 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5280 case DT_MIPS_SYMTABNO:
5282 elemsize = sizeof (Elf32_External_Sym);
5283 s = bfd_get_section_by_name (output_bfd, name);
5284 BFD_ASSERT (s != NULL);
5286 if (s->_cooked_size != 0)
5287 dyn.d_un.d_val = s->_cooked_size / elemsize;
5289 dyn.d_un.d_val = s->_raw_size / elemsize;
5290 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5293 case DT_MIPS_UNREFEXTNO:
5295 dyn.d_un.d_val = SIZEOF_MIPS_DYNSYM_SECNAMES;
5296 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5299 case DT_MIPS_GOTSYM:
5300 dyn.d_un.d_val = g->global_gotsym;
5301 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5304 case DT_MIPS_HIPAGENO:
5305 dyn.d_un.d_val = g->local_gotno - MIPS_RESERVED_GOTNO;
5306 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5313 /* The first entry of the global offset table will be filled at
5314 runtime. The second entry will be used by some runtime loaders.
5315 This isn't the case of Irix rld. */
5316 if (sgot->_raw_size > 0)
5318 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
5319 bfd_put_32 (output_bfd, (bfd_vma) 0x80000000, sgot->contents + 4);
5322 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
5330 Elf_Internal_Sym sym;
5333 const char * const * namep = mips_elf_dynsym_sec_names;
5334 Elf32_compact_rel cpt;
5336 /* Set up the section symbols for the output sections. SGI set
5337 STT_NOTYPE attribute for these symbols. Should we do so? */
5339 sdynsym = bfd_get_section_by_name (dynobj, ".dynsym");
5340 BFD_ASSERT (sdynsym != NULL);
5342 if (SGI_COMPAT (output_bfd))
5346 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
5350 while ((name = *namep++) != NULL)
5352 s = bfd_get_section_by_name (output_bfd, name);
5355 sym.st_value = s->vma;
5356 dindx = elf_section_data (s)->dynindx;
5357 last = s->vma + s->_raw_size;
5361 sym.st_value = last;
5365 sym.st_shndx = (i < MIPS_TEXT_DYNSYM_SECNO
5370 mips_elf_hash_table (info)->dynsym_sec_strindex[dindx];
5372 bfd_elf32_swap_symbol_out (output_bfd, &sym,
5373 (((Elf32_External_Sym *)
5378 /* Set the sh_info field of the output .dynsym section to
5379 the index of the first global symbol. */
5380 elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
5381 SIZEOF_MIPS_DYNSYM_SECNAMES;
5387 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
5390 for (s = output_bfd->sections; s != NULL; s = s->next)
5394 sym.st_value = s->vma;
5396 indx = elf_section_data (s)->this_idx;
5397 BFD_ASSERT (indx > 0);
5398 sym.st_shndx = indx;
5400 bfd_elf32_swap_symbol_out (output_bfd, &sym,
5401 (((Elf32_External_Sym *)
5403 + elf_section_data (s)->dynindx));
5406 /* Set the sh_info field of the output .dynsym section to
5407 the index of the first global symbol. */
5408 elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
5409 bfd_count_sections (output_bfd) + 1;
5412 if (SGI_COMPAT (output_bfd))
5414 /* Write .compact_rel section out. */
5415 s = bfd_get_section_by_name (dynobj, ".compact_rel");
5416 BFD_ASSERT (s != NULL);
5419 cpt.num = s->reloc_count;
5421 cpt.offset = (s->output_section->filepos
5422 + sizeof (Elf32_External_compact_rel));
5425 bfd_elf32_swap_compact_rel_out (output_bfd, &cpt,
5426 ((Elf32_External_compact_rel *)
5429 /* Clean up a dummy stub function entry in .text. */
5430 s = bfd_get_section_by_name (dynobj, ".stub");
5433 file_ptr dummy_offset;
5435 BFD_ASSERT (s->_raw_size >= MIPS_FUNCTION_STUB_SIZE);
5436 dummy_offset = s->_raw_size - MIPS_FUNCTION_STUB_SIZE;
5437 memset (s->contents + dummy_offset, 0, MIPS_FUNCTION_STUB_SIZE);
5441 /* Clean up a first relocation in .rel.dyn. */
5442 s = bfd_get_section_by_name (dynobj, ".rel.dyn");
5444 memset (s->contents, 0, sizeof (Elf32_External_Rel));
5450 /* This is almost identical to bfd_generic_get_... except that some
5451 MIPS relocations need to be handled specially. Sigh. */
5454 elf32_mips_get_relocated_section_contents (abfd, link_info, link_order, data,
5455 relocateable, symbols)
5457 struct bfd_link_info *link_info;
5458 struct bfd_link_order *link_order;
5460 boolean relocateable;
5463 /* Get enough memory to hold the stuff */
5464 bfd *input_bfd = link_order->u.indirect.section->owner;
5465 asection *input_section = link_order->u.indirect.section;
5467 long reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section);
5468 arelent **reloc_vector = NULL;
5474 reloc_vector = (arelent **) bfd_malloc (reloc_size);
5475 if (reloc_vector == NULL && reloc_size != 0)
5478 /* read in the section */
5479 if (!bfd_get_section_contents (input_bfd,
5483 input_section->_raw_size))
5486 /* We're not relaxing the section, so just copy the size info */
5487 input_section->_cooked_size = input_section->_raw_size;
5488 input_section->reloc_done = true;
5490 reloc_count = bfd_canonicalize_reloc (input_bfd,
5494 if (reloc_count < 0)
5497 if (reloc_count > 0)
5502 bfd_vma gp = 0x12345678; /* initialize just to shut gcc up */
5505 struct bfd_hash_entry *h;
5506 struct bfd_link_hash_entry *lh;
5507 /* Skip all this stuff if we aren't mixing formats. */
5508 if (abfd && input_bfd
5509 && abfd->xvec == input_bfd->xvec)
5513 h = bfd_hash_lookup (&link_info->hash->table, "_gp", false, false);
5514 lh = (struct bfd_link_hash_entry *) h;
5521 case bfd_link_hash_undefined:
5522 case bfd_link_hash_undefweak:
5523 case bfd_link_hash_common:
5526 case bfd_link_hash_defined:
5527 case bfd_link_hash_defweak:
5529 gp = lh->u.def.value;
5531 case bfd_link_hash_indirect:
5532 case bfd_link_hash_warning:
5534 /* @@FIXME ignoring warning for now */
5536 case bfd_link_hash_new:
5545 for (parent = reloc_vector; *parent != (arelent *) NULL;
5548 char *error_message = (char *) NULL;
5549 bfd_reloc_status_type r;
5551 /* Specific to MIPS: Deal with relocation types that require
5552 knowing the gp of the output bfd. */
5553 asymbol *sym = *(*parent)->sym_ptr_ptr;
5554 if (bfd_is_abs_section (sym->section) && abfd)
5556 /* The special_function wouldn't get called anyways. */
5560 /* The gp isn't there; let the special function code
5561 fall over on its own. */
5563 else if ((*parent)->howto->special_function
5564 == mips_elf_gprel16_reloc)
5566 /* bypass special_function call */
5567 r = gprel16_with_gp (input_bfd, sym, *parent, input_section,
5568 relocateable, (PTR) data, gp);
5569 goto skip_bfd_perform_relocation;
5571 /* end mips specific stuff */
5573 r = bfd_perform_relocation (input_bfd,
5577 relocateable ? abfd : (bfd *) NULL,
5579 skip_bfd_perform_relocation:
5583 asection *os = input_section->output_section;
5585 /* A partial link, so keep the relocs */
5586 os->orelocation[os->reloc_count] = *parent;
5590 if (r != bfd_reloc_ok)
5594 case bfd_reloc_undefined:
5595 if (!((*link_info->callbacks->undefined_symbol)
5596 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
5597 input_bfd, input_section, (*parent)->address)))
5600 case bfd_reloc_dangerous:
5601 BFD_ASSERT (error_message != (char *) NULL);
5602 if (!((*link_info->callbacks->reloc_dangerous)
5603 (link_info, error_message, input_bfd, input_section,
5604 (*parent)->address)))
5607 case bfd_reloc_overflow:
5608 if (!((*link_info->callbacks->reloc_overflow)
5609 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
5610 (*parent)->howto->name, (*parent)->addend,
5611 input_bfd, input_section, (*parent)->address)))
5614 case bfd_reloc_outofrange:
5623 if (reloc_vector != NULL)
5624 free (reloc_vector);
5628 if (reloc_vector != NULL)
5629 free (reloc_vector);
5632 #define bfd_elf32_bfd_get_relocated_section_contents \
5633 elf32_mips_get_relocated_section_contents
5635 /* ECOFF swapping routines. These are used when dealing with the
5636 .mdebug section, which is in the ECOFF debugging format. */
5637 static const struct ecoff_debug_swap mips_elf_ecoff_debug_swap =
5639 /* Symbol table magic number. */
5641 /* Alignment of debugging information. E.g., 4. */
5643 /* Sizes of external symbolic information. */
5644 sizeof (struct hdr_ext),
5645 sizeof (struct dnr_ext),
5646 sizeof (struct pdr_ext),
5647 sizeof (struct sym_ext),
5648 sizeof (struct opt_ext),
5649 sizeof (struct fdr_ext),
5650 sizeof (struct rfd_ext),
5651 sizeof (struct ext_ext),
5652 /* Functions to swap in external symbolic data. */
5661 _bfd_ecoff_swap_tir_in,
5662 _bfd_ecoff_swap_rndx_in,
5663 /* Functions to swap out external symbolic data. */
5672 _bfd_ecoff_swap_tir_out,
5673 _bfd_ecoff_swap_rndx_out,
5674 /* Function to read in symbolic data. */
5675 mips_elf_read_ecoff_info
5678 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
5679 #define TARGET_LITTLE_NAME "elf32-littlemips"
5680 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
5681 #define TARGET_BIG_NAME "elf32-bigmips"
5682 #define ELF_ARCH bfd_arch_mips
5683 #define ELF_MACHINE_CODE EM_MIPS
5684 #define ELF_MAXPAGESIZE 0x10000
5685 #define elf_backend_collect true
5686 #define elf_backend_type_change_ok true
5687 #define elf_info_to_howto 0
5688 #define elf_info_to_howto_rel mips_info_to_howto_rel
5689 #define elf_backend_sym_is_global mips_elf_sym_is_global
5690 #define elf_backend_object_p mips_elf_object_p
5691 #define elf_backend_section_from_shdr mips_elf_section_from_shdr
5692 #define elf_backend_fake_sections mips_elf_fake_sections
5693 #define elf_backend_section_from_bfd_section \
5694 mips_elf_section_from_bfd_section
5695 #define elf_backend_section_processing mips_elf_section_processing
5696 #define elf_backend_symbol_processing mips_elf_symbol_processing
5697 #define elf_backend_additional_program_headers \
5698 mips_elf_additional_program_headers
5699 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
5700 #define elf_backend_final_write_processing \
5701 mips_elf_final_write_processing
5702 #define elf_backend_ecoff_debug_swap &mips_elf_ecoff_debug_swap
5704 #define bfd_elf32_bfd_is_local_label mips_elf_is_local_label
5705 #define bfd_elf32_find_nearest_line mips_elf_find_nearest_line
5707 #define bfd_elf32_bfd_link_hash_table_create \
5708 mips_elf_link_hash_table_create
5709 #define bfd_elf32_bfd_final_link mips_elf_final_link
5710 #define bfd_elf32_bfd_copy_private_bfd_data \
5711 mips_elf_copy_private_bfd_data
5712 #define bfd_elf32_bfd_merge_private_bfd_data \
5713 mips_elf_merge_private_bfd_data
5714 #define bfd_elf32_bfd_set_private_flags mips_elf_set_private_flags
5715 #define elf_backend_relocate_section mips_elf_relocate_section
5716 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
5717 #define elf_backend_create_dynamic_sections \
5718 mips_elf_create_dynamic_sections
5719 #define elf_backend_check_relocs mips_elf_check_relocs
5720 #define elf_backend_adjust_dynamic_symbol \
5721 mips_elf_adjust_dynamic_symbol
5722 #define elf_backend_size_dynamic_sections \
5723 mips_elf_size_dynamic_sections
5724 #define elf_backend_relocate_section mips_elf_relocate_section
5725 #define elf_backend_finish_dynamic_symbol \
5726 mips_elf_finish_dynamic_symbol
5727 #define elf_backend_finish_dynamic_sections \
5728 mips_elf_finish_dynamic_sections
5729 #define elf_backend_want_hdr_in_seg 1
5731 #include "elf32-target.h"