1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
4 Most of the information added by Ian Lance Taylor, Cygnus Support,
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 /* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
24 different MIPS ELF from other targets. This matters when linking.
25 This file supports both, switching at runtime. */
35 /* Get the ECOFF swapping routines. */
37 #include "coff/symconst.h"
38 #include "coff/internal.h"
39 #include "coff/ecoff.h"
40 #include "coff/mips.h"
42 #include "ecoffswap.h"
44 static bfd_reloc_status_type mips_elf_hi16_reloc
PARAMS ((bfd
*abfd
,
51 static bfd_reloc_status_type mips_elf_got16_reloc
PARAMS ((bfd
*abfd
,
58 static bfd_reloc_status_type mips_elf_lo16_reloc
PARAMS ((bfd
*abfd
,
65 static bfd_reloc_status_type mips_elf_gprel16_reloc
PARAMS ((bfd
*abfd
,
72 static bfd_reloc_status_type mips_elf_gprel32_reloc
PARAMS ((bfd
*abfd
,
79 static reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
80 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
81 static void mips_info_to_howto_rel
82 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
83 static void bfd_mips_elf32_swap_gptab_in
84 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
85 static void bfd_mips_elf32_swap_gptab_out
86 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
87 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
88 static boolean mips_elf_object_p
PARAMS ((bfd
*));
89 static boolean mips_elf_create_procedure_table
90 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
91 struct ecoff_debug_info
*));
92 static int mips_elf_additional_program_headers
PARAMS ((bfd
*));
93 static boolean mips_elf_modify_segment_map
PARAMS ((bfd
*));
94 static void mips_elf_final_write_processing
95 PARAMS ((bfd
*, boolean
));
96 static boolean mips_elf_set_private_flags
PARAMS ((bfd
*, flagword
));
97 static boolean mips_elf_copy_private_bfd_data
PARAMS ((bfd
*, bfd
*));
98 static boolean mips_elf_merge_private_bfd_data
PARAMS ((bfd
*, bfd
*));
99 static boolean mips_elf_section_from_shdr
100 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, char *));
101 static boolean mips_elf_fake_sections
102 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, asection
*));
103 static boolean mips_elf_section_from_bfd_section
104 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, asection
*, int *));
105 static boolean mips_elf_section_processing
106 PARAMS ((bfd
*, Elf32_Internal_Shdr
*));
107 static void mips_elf_symbol_processing
PARAMS ((bfd
*, asymbol
*));
108 static boolean mips_elf_read_ecoff_info
109 PARAMS ((bfd
*, asection
*, struct ecoff_debug_info
*));
110 static boolean mips_elf_is_local_label
111 PARAMS ((bfd
*, asymbol
*));
112 static boolean mips_elf_find_nearest_line
113 PARAMS ((bfd
*, asection
*, asymbol
**, bfd_vma
, const char **,
114 const char **, unsigned int *));
115 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
116 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
117 static struct bfd_link_hash_table
*mips_elf_link_hash_table_create
119 static int gptab_compare
PARAMS ((const void *, const void *));
120 static boolean mips_elf_final_link
121 PARAMS ((bfd
*, struct bfd_link_info
*));
122 static void mips_elf_relocate_hi16
123 PARAMS ((bfd
*, Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_byte
*,
125 static void mips_elf_relocate_got_local
126 PARAMS ((bfd
*, bfd
*, asection
*, Elf_Internal_Rela
*,
127 Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
128 static void mips_elf_relocate_global_got
129 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
130 static boolean mips_elf_adjust_dynindx
131 PARAMS ((struct elf_link_hash_entry
*, PTR
));
132 static boolean mips_elf_relocate_section
133 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
134 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
135 static boolean mips_elf_create_dynamic_sections
136 PARAMS ((bfd
*, struct bfd_link_info
*));
137 static boolean mips_elf_create_compact_rel_section
138 PARAMS ((bfd
*, struct bfd_link_info
*));
139 static boolean mips_elf_create_got_section
140 PARAMS ((bfd
*, struct bfd_link_info
*));
141 static boolean mips_elf_check_relocs
142 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
143 const Elf_Internal_Rela
*));
144 static boolean mips_elf_adjust_dynamic_symbol
145 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
146 static boolean mips_elf_size_dynamic_sections
147 PARAMS ((bfd
*, struct bfd_link_info
*));
148 static boolean mips_elf_finish_dynamic_symbol
149 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
150 Elf_Internal_Sym
*));
151 static boolean mips_elf_finish_dynamic_sections
152 PARAMS ((bfd
*, struct bfd_link_info
*));
153 static boolean mips_elf_add_symbol_hook
154 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
155 const char **, flagword
*, asection
**, bfd_vma
*));
156 static bfd_reloc_status_type mips_elf_final_gp
157 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
158 static bfd_byte
*elf32_mips_get_relocated_section_contents
159 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
160 bfd_byte
*, boolean
, asymbol
**));
162 /* This is true for Irix 5 executables, false for normal MIPS ELF ABI
163 executables. FIXME: At the moment, we default to always generating
164 Irix 5 executables. */
166 #define SGI_COMPAT(abfd) (1)
168 /* This structure is used to hold .got information when linking. It
169 is stored in the tdata field of the bfd_elf_section_data structure. */
173 /* The symbol index of the first global .got symbol. */
174 unsigned long global_gotsym
;
175 /* The number of local .got entries. */
176 unsigned int local_gotno
;
179 /* The number of local .got entries we reserve. */
180 #define MIPS_RESERVED_GOTNO (2)
182 /* Instructions which appear in a stub. For some reason the stub is
183 slightly different on an SGI system. */
184 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
185 #define STUB_LW(abfd) \
187 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
188 : 0x8f998000) /* lw t9,0x8000(gp) */
189 #define STUB_MOVE 0x03e07825 /* move t7,ra */
190 #define STUB_JALR 0x0320f809 /* jal t9 */
191 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
192 #define MIPS_FUNCTION_STUB_SIZE (16)
194 /* Names of sections which appear in the .dynsym section in an Irix 5
197 static const char * const mips_elf_dynsym_sec_names
[] =
210 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
211 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
213 /* The number of entries in mips_elf_dynsym_sec_names which go in the
216 #define MIPS_TEXT_DYNSYM_SECNO (3)
218 /* The names of the runtime procedure table symbols used on Irix 5. */
220 static const char * const mips_elf_dynsym_rtproc_names
[] =
223 "_procedure_string_table",
224 "_procedure_table_size",
228 /* These structures are used to generate the .compact_rel section on
233 unsigned long id1
; /* Always one? */
234 unsigned long num
; /* Number of compact relocation entries. */
235 unsigned long id2
; /* Always two? */
236 unsigned long offset
; /* The file offset of the first relocation. */
237 unsigned long reserved0
; /* Zero? */
238 unsigned long reserved1
; /* Zero? */
247 bfd_byte reserved0
[4];
248 bfd_byte reserved1
[4];
249 } Elf32_External_compact_rel
;
253 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
254 unsigned int rtype
: 4; /* Relocation types. See below. */
255 unsigned int dist2to
: 8;
256 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
257 unsigned long konst
; /* KONST field. See below. */
258 unsigned long vaddr
; /* VADDR to be relocated. */
263 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
264 unsigned int rtype
: 4; /* Relocation types. See below. */
265 unsigned int dist2to
: 8;
266 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
267 unsigned long konst
; /* KONST field. See below. */
275 } Elf32_External_crinfo
;
281 } Elf32_External_crinfo2
;
283 /* These are the constants used to swap the bitfields in a crinfo. */
285 #define CRINFO_CTYPE (0x1)
286 #define CRINFO_CTYPE_SH (31)
287 #define CRINFO_RTYPE (0xf)
288 #define CRINFO_RTYPE_SH (27)
289 #define CRINFO_DIST2TO (0xff)
290 #define CRINFO_DIST2TO_SH (19)
291 #define CRINFO_RELVADDR (0x7ffff)
292 #define CRINFO_RELVADDR_SH (0)
294 /* A compact relocation info has long (3 words) or short (2 words)
295 formats. A short format doesn't have VADDR field and relvaddr
296 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
297 #define CRF_MIPS_LONG 1
298 #define CRF_MIPS_SHORT 0
300 /* There are 4 types of compact relocation at least. The value KONST
301 has different meaning for each type:
304 CT_MIPS_REL32 Address in data
305 CT_MIPS_WORD Address in word (XXX)
306 CT_MIPS_GPHI_LO GP - vaddr
307 CT_MIPS_JMPAD Address to jump
310 #define CRT_MIPS_REL32 0xa
311 #define CRT_MIPS_WORD 0xb
312 #define CRT_MIPS_GPHI_LO 0xc
313 #define CRT_MIPS_JMPAD 0xd
315 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
316 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
317 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
318 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
320 static void bfd_elf32_swap_compact_rel_out
321 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
322 static void bfd_elf32_swap_crinfo_out
323 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
325 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
330 R_MIPS_16
, R_MIPS_32
,
331 R_MIPS_REL32
, R_MIPS_26
,
332 R_MIPS_HI16
, R_MIPS_LO16
,
333 R_MIPS_GPREL16
, R_MIPS_LITERAL
,
334 R_MIPS_GOT16
, R_MIPS_PC16
,
335 R_MIPS_CALL16
, R_MIPS_GPREL32
,
336 /* The remaining relocs are defined on Irix, although they are not
337 in the MIPS ELF ABI. */
338 R_MIPS_UNUSED1
, R_MIPS_UNUSED2
,
340 R_MIPS_SHIFT5
, R_MIPS_SHIFT6
,
341 R_MIPS_64
, R_MIPS_GOT_DISP
,
342 R_MIPS_GOT_PAGE
, R_MIPS_GOT_OFST
,
343 R_MIPS_GOT_HI16
, R_MIPS_GOT_LO16
,
344 R_MIPS_SUB
, R_MIPS_INSERT_A
,
345 R_MIPS_INSERT_B
, R_MIPS_DELETE
,
346 R_MIPS_HIGHER
, R_MIPS_HIGHEST
,
347 R_MIPS_CALL_HI16
, R_MIPS_CALL_LO16
,
351 static reloc_howto_type elf_mips_howto_table
[] =
354 HOWTO (R_MIPS_NONE
, /* type */
356 0, /* size (0 = byte, 1 = short, 2 = long) */
358 false, /* pc_relative */
360 complain_overflow_dont
, /* complain_on_overflow */
361 bfd_elf_generic_reloc
, /* special_function */
362 "R_MIPS_NONE", /* name */
363 false, /* partial_inplace */
366 false), /* pcrel_offset */
368 /* 16 bit relocation. */
369 HOWTO (R_MIPS_16
, /* type */
371 1, /* size (0 = byte, 1 = short, 2 = long) */
373 false, /* pc_relative */
375 complain_overflow_bitfield
, /* complain_on_overflow */
376 bfd_elf_generic_reloc
, /* special_function */
377 "R_MIPS_16", /* name */
378 true, /* partial_inplace */
379 0xffff, /* src_mask */
380 0xffff, /* dst_mask */
381 false), /* pcrel_offset */
383 /* 32 bit relocation. */
384 HOWTO (R_MIPS_32
, /* type */
386 2, /* size (0 = byte, 1 = short, 2 = long) */
388 false, /* pc_relative */
390 complain_overflow_bitfield
, /* complain_on_overflow */
391 bfd_elf_generic_reloc
, /* special_function */
392 "R_MIPS_32", /* name */
393 true, /* partial_inplace */
394 0xffffffff, /* src_mask */
395 0xffffffff, /* dst_mask */
396 false), /* pcrel_offset */
398 /* 32 bit symbol relative relocation. */
399 HOWTO (R_MIPS_REL32
, /* type */
401 2, /* size (0 = byte, 1 = short, 2 = long) */
403 false, /* pc_relative */
405 complain_overflow_bitfield
, /* complain_on_overflow */
406 bfd_elf_generic_reloc
, /* special_function */
407 "R_MIPS_REL32", /* name */
408 true, /* partial_inplace */
409 0xffffffff, /* src_mask */
410 0xffffffff, /* dst_mask */
411 false), /* pcrel_offset */
413 /* 26 bit branch address. */
414 HOWTO (R_MIPS_26
, /* type */
416 2, /* size (0 = byte, 1 = short, 2 = long) */
418 false, /* pc_relative */
420 complain_overflow_dont
, /* complain_on_overflow */
421 /* This needs complex overflow
422 detection, because the upper four
423 bits must match the PC. */
424 bfd_elf_generic_reloc
, /* special_function */
425 "R_MIPS_26", /* name */
426 true, /* partial_inplace */
427 0x3ffffff, /* src_mask */
428 0x3ffffff, /* dst_mask */
429 false), /* pcrel_offset */
431 /* High 16 bits of symbol value. */
432 HOWTO (R_MIPS_HI16
, /* type */
434 2, /* size (0 = byte, 1 = short, 2 = long) */
436 false, /* pc_relative */
438 complain_overflow_dont
, /* complain_on_overflow */
439 mips_elf_hi16_reloc
, /* special_function */
440 "R_MIPS_HI16", /* name */
441 true, /* partial_inplace */
442 0xffff, /* src_mask */
443 0xffff, /* dst_mask */
444 false), /* pcrel_offset */
446 /* Low 16 bits of symbol value. */
447 HOWTO (R_MIPS_LO16
, /* type */
449 2, /* size (0 = byte, 1 = short, 2 = long) */
451 false, /* pc_relative */
453 complain_overflow_dont
, /* complain_on_overflow */
454 mips_elf_lo16_reloc
, /* special_function */
455 "R_MIPS_LO16", /* name */
456 true, /* partial_inplace */
457 0xffff, /* src_mask */
458 0xffff, /* dst_mask */
459 false), /* pcrel_offset */
461 /* GP relative reference. */
462 HOWTO (R_MIPS_GPREL16
, /* type */
464 2, /* size (0 = byte, 1 = short, 2 = long) */
466 false, /* pc_relative */
468 complain_overflow_signed
, /* complain_on_overflow */
469 mips_elf_gprel16_reloc
, /* special_function */
470 "R_MIPS_GPREL16", /* name */
471 true, /* partial_inplace */
472 0xffff, /* src_mask */
473 0xffff, /* dst_mask */
474 false), /* pcrel_offset */
476 /* Reference to literal section. */
477 HOWTO (R_MIPS_LITERAL
, /* type */
479 2, /* size (0 = byte, 1 = short, 2 = long) */
481 false, /* pc_relative */
483 complain_overflow_signed
, /* complain_on_overflow */
484 mips_elf_gprel16_reloc
, /* special_function */
485 "R_MIPS_LITERAL", /* name */
486 true, /* partial_inplace */
487 0xffff, /* src_mask */
488 0xffff, /* dst_mask */
489 false), /* pcrel_offset */
491 /* Reference to global offset table. */
492 HOWTO (R_MIPS_GOT16
, /* type */
494 2, /* size (0 = byte, 1 = short, 2 = long) */
496 false, /* pc_relative */
498 complain_overflow_signed
, /* complain_on_overflow */
499 mips_elf_got16_reloc
, /* special_function */
500 "R_MIPS_GOT16", /* name */
501 false, /* partial_inplace */
503 0xffff, /* dst_mask */
504 false), /* pcrel_offset */
506 /* 16 bit PC relative reference. */
507 HOWTO (R_MIPS_PC16
, /* type */
509 2, /* size (0 = byte, 1 = short, 2 = long) */
511 true, /* pc_relative */
513 complain_overflow_signed
, /* complain_on_overflow */
514 bfd_elf_generic_reloc
, /* special_function */
515 "R_MIPS_PC16", /* name */
516 true, /* partial_inplace */
517 0xffff, /* src_mask */
518 0xffff, /* dst_mask */
519 false), /* pcrel_offset */
521 /* 16 bit call through global offset table. */
522 /* FIXME: This is not handled correctly. */
523 HOWTO (R_MIPS_CALL16
, /* type */
525 2, /* size (0 = byte, 1 = short, 2 = long) */
527 false, /* pc_relative */
529 complain_overflow_signed
, /* complain_on_overflow */
530 bfd_elf_generic_reloc
, /* special_function */
531 "R_MIPS_CALL16", /* name */
532 false, /* partial_inplace */
534 0xffff, /* dst_mask */
535 false), /* pcrel_offset */
537 /* 32 bit GP relative reference. */
538 HOWTO (R_MIPS_GPREL32
, /* type */
540 2, /* size (0 = byte, 1 = short, 2 = long) */
542 false, /* pc_relative */
544 complain_overflow_bitfield
, /* complain_on_overflow */
545 mips_elf_gprel32_reloc
, /* special_function */
546 "R_MIPS_GPREL32", /* name */
547 true, /* partial_inplace */
548 0xffffffff, /* src_mask */
549 0xffffffff, /* dst_mask */
550 false), /* pcrel_offset */
552 /* The remaining relocs are defined on Irix 5, although they are
553 not defined by the ABI. */
558 /* A 5 bit shift field. */
559 HOWTO (R_MIPS_SHIFT5
, /* type */
561 2, /* size (0 = byte, 1 = short, 2 = long) */
563 false, /* pc_relative */
565 complain_overflow_bitfield
, /* complain_on_overflow */
566 bfd_elf_generic_reloc
, /* special_function */
567 "R_MIPS_SHIFT5", /* name */
568 true, /* partial_inplace */
569 0x000007c0, /* src_mask */
570 0x000007c0, /* dst_mask */
571 false), /* pcrel_offset */
573 /* A 6 bit shift field. */
574 /* FIXME: This is not handled correctly; a special function is
575 needed to put the most significant bit in the right place. */
576 HOWTO (R_MIPS_SHIFT6
, /* type */
578 2, /* size (0 = byte, 1 = short, 2 = long) */
580 false, /* pc_relative */
582 complain_overflow_bitfield
, /* complain_on_overflow */
583 bfd_elf_generic_reloc
, /* special_function */
584 "R_MIPS_SHIFT6", /* name */
585 true, /* partial_inplace */
586 0x000007c4, /* src_mask */
587 0x000007c4, /* dst_mask */
588 false), /* pcrel_offset */
590 /* A 64 bit relocation. Presumably not used in 32 bit ELF. */
593 /* Displacement in the global offset table. */
594 /* FIXME: Not handled correctly. */
595 HOWTO (R_MIPS_GOT_DISP
, /* type */
597 2, /* size (0 = byte, 1 = short, 2 = long) */
599 false, /* pc_relative */
601 complain_overflow_bitfield
, /* complain_on_overflow */
602 bfd_elf_generic_reloc
, /* special_function */
603 "R_MIPS_GOT_DISP", /* name */
604 true, /* partial_inplace */
605 0x0000ffff, /* src_mask */
606 0x0000ffff, /* dst_mask */
607 false), /* pcrel_offset */
609 /* Displacement to page pointer in the global offset table. */
610 /* FIXME: Not handled correctly. */
611 HOWTO (R_MIPS_GOT_PAGE
, /* type */
613 2, /* size (0 = byte, 1 = short, 2 = long) */
615 false, /* pc_relative */
617 complain_overflow_bitfield
, /* complain_on_overflow */
618 bfd_elf_generic_reloc
, /* special_function */
619 "R_MIPS_GOT_PAGE", /* name */
620 true, /* partial_inplace */
621 0x0000ffff, /* src_mask */
622 0x0000ffff, /* dst_mask */
623 false), /* pcrel_offset */
625 /* Offset from page pointer in the global offset table. */
626 /* FIXME: Not handled correctly. */
627 HOWTO (R_MIPS_GOT_OFST
, /* type */
629 2, /* size (0 = byte, 1 = short, 2 = long) */
631 false, /* pc_relative */
633 complain_overflow_bitfield
, /* complain_on_overflow */
634 bfd_elf_generic_reloc
, /* special_function */
635 "R_MIPS_GOT_OFST", /* name */
636 true, /* partial_inplace */
637 0x0000ffff, /* src_mask */
638 0x0000ffff, /* dst_mask */
639 false), /* pcrel_offset */
641 /* High 16 bits of displacement in global offset table. */
642 /* FIXME: Not handled correctly. */
643 HOWTO (R_MIPS_GOT_HI16
, /* type */
645 2, /* size (0 = byte, 1 = short, 2 = long) */
647 false, /* pc_relative */
649 complain_overflow_dont
, /* complain_on_overflow */
650 bfd_elf_generic_reloc
, /* special_function */
651 "R_MIPS_GOT_HI16", /* name */
652 true, /* partial_inplace */
653 0x0000ffff, /* src_mask */
654 0x0000ffff, /* dst_mask */
655 false), /* pcrel_offset */
657 /* Low 16 bits of displacement in global offset table. */
658 /* FIXME: Not handled correctly. */
659 HOWTO (R_MIPS_GOT_LO16
, /* type */
661 2, /* size (0 = byte, 1 = short, 2 = long) */
663 false, /* pc_relative */
665 complain_overflow_dont
, /* complain_on_overflow */
666 bfd_elf_generic_reloc
, /* special_function */
667 "R_MIPS_GOT_LO16", /* name */
668 true, /* partial_inplace */
669 0x0000ffff, /* src_mask */
670 0x0000ffff, /* dst_mask */
671 false), /* pcrel_offset */
673 /* 64 bit subtraction. Presumably not used in 32 bit ELF. */
676 /* Used to cause the linker to insert and delete instructions? */
681 /* Get the higher values of a 64 bit addend. Presumably not used in
686 /* High 16 bits of displacement in global offset table. */
687 /* FIXME: Not handled correctly. */
688 HOWTO (R_MIPS_CALL_HI16
, /* type */
690 2, /* size (0 = byte, 1 = short, 2 = long) */
692 false, /* pc_relative */
694 complain_overflow_dont
, /* complain_on_overflow */
695 bfd_elf_generic_reloc
, /* special_function */
696 "R_MIPS_CALL_HI16", /* name */
697 true, /* partial_inplace */
698 0x0000ffff, /* src_mask */
699 0x0000ffff, /* dst_mask */
700 false), /* pcrel_offset */
702 /* Low 16 bits of displacement in global offset table. */
703 /* FIXME: Not handled correctly. */
704 HOWTO (R_MIPS_CALL_LO16
, /* type */
706 2, /* size (0 = byte, 1 = short, 2 = long) */
708 false, /* pc_relative */
710 complain_overflow_dont
, /* complain_on_overflow */
711 bfd_elf_generic_reloc
, /* special_function */
712 "R_MIPS_CALL_LO16", /* name */
713 true, /* partial_inplace */
714 0x0000ffff, /* src_mask */
715 0x0000ffff, /* dst_mask */
716 false) /* pcrel_offset */
719 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
720 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
721 the HI16. Here we just save the information we need; we do the
722 actual relocation when we see the LO16. MIPS ELF requires that the
723 LO16 immediately follow the HI16. As a GNU extension, we permit an
724 arbitrary number of HI16 relocs to be associated with a single LO16
725 reloc. This extension permits gcc to output the HI and LO relocs
730 struct mips_hi16
*next
;
735 /* FIXME: This should not be a static variable. */
737 static struct mips_hi16
*mips_hi16_list
;
739 static bfd_reloc_status_type
740 mips_elf_hi16_reloc (abfd
,
748 arelent
*reloc_entry
;
751 asection
*input_section
;
753 char **error_message
;
755 bfd_reloc_status_type ret
;
759 /* If we're relocating, and this an external symbol, we don't want
760 to change anything. */
761 if (output_bfd
!= (bfd
*) NULL
762 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
763 && reloc_entry
->addend
== 0)
765 reloc_entry
->address
+= input_section
->output_offset
;
771 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
773 boolean relocateable
;
776 if (ret
== bfd_reloc_undefined
)
779 if (output_bfd
!= NULL
)
783 relocateable
= false;
784 output_bfd
= symbol
->section
->output_section
->owner
;
787 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
789 if (ret
!= bfd_reloc_ok
)
792 relocation
= gp
- reloc_entry
->address
;
796 if (bfd_is_und_section (symbol
->section
)
797 && output_bfd
== (bfd
*) NULL
)
798 ret
= bfd_reloc_undefined
;
800 if (bfd_is_com_section (symbol
->section
))
803 relocation
= symbol
->value
;
806 relocation
+= symbol
->section
->output_section
->vma
;
807 relocation
+= symbol
->section
->output_offset
;
808 relocation
+= reloc_entry
->addend
;
810 if (reloc_entry
->address
> input_section
->_cooked_size
)
811 return bfd_reloc_outofrange
;
813 /* Save the information, and let LO16 do the actual relocation. */
814 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
816 return bfd_reloc_outofrange
;
817 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
818 n
->addend
= relocation
;
819 n
->next
= mips_hi16_list
;
822 if (output_bfd
!= (bfd
*) NULL
)
823 reloc_entry
->address
+= input_section
->output_offset
;
828 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
829 inplace relocation; this function exists in order to do the
830 R_MIPS_HI16 relocation described above. */
832 static bfd_reloc_status_type
833 mips_elf_lo16_reloc (abfd
,
841 arelent
*reloc_entry
;
844 asection
*input_section
;
846 char **error_message
;
848 arelent gp_disp_relent
;
850 if (mips_hi16_list
!= NULL
)
860 struct mips_hi16
*next
;
862 /* Do the HI16 relocation. Note that we actually don't need
863 to know anything about the LO16 itself, except where to
864 find the low 16 bits of the addend needed by the LO16. */
865 insn
= bfd_get_32 (abfd
, l
->addr
);
866 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
868 val
= ((insn
& 0xffff) << 16) + vallo
;
871 /* The low order 16 bits are always treated as a signed
872 value. Therefore, a negative value in the low order bits
873 requires an adjustment in the high order bits. We need
874 to make this adjustment in two ways: once for the bits we
875 took from the data, and once for the bits we are putting
876 back in to the data. */
877 if ((vallo
& 0x8000) != 0)
879 if ((val
& 0x8000) != 0)
882 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
883 bfd_put_32 (abfd
, insn
, l
->addr
);
885 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
887 gp_disp_relent
= *reloc_entry
;
888 reloc_entry
= &gp_disp_relent
;
889 reloc_entry
->addend
= l
->addend
;
897 mips_hi16_list
= NULL
;
899 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
901 bfd_reloc_status_type ret
;
902 bfd_vma gp
, relocation
;
904 /* FIXME: Does this case ever occur? */
906 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
907 if (ret
!= bfd_reloc_ok
)
910 relocation
= gp
- reloc_entry
->address
;
911 relocation
+= symbol
->section
->output_section
->vma
;
912 relocation
+= symbol
->section
->output_offset
;
913 relocation
+= reloc_entry
->addend
;
915 if (reloc_entry
->address
> input_section
->_cooked_size
)
916 return bfd_reloc_outofrange
;
918 gp_disp_relent
= *reloc_entry
;
919 reloc_entry
= &gp_disp_relent
;
920 reloc_entry
->addend
= relocation
- 4;
923 /* Now do the LO16 reloc in the usual way. */
924 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
925 input_section
, output_bfd
, error_message
);
928 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
929 table used for PIC code. If the symbol is an external symbol, the
930 instruction is modified to contain the offset of the appropriate
931 entry in the global offset table. If the symbol is a section
932 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
933 addends are combined to form the real addend against the section
934 symbol; the GOT16 is modified to contain the offset of an entry in
935 the global offset table, and the LO16 is modified to offset it
936 appropriately. Thus an offset larger than 16 bits requires a
937 modified value in the global offset table.
939 This implementation suffices for the assembler, but the linker does
940 not yet know how to create global offset tables. */
942 static bfd_reloc_status_type
943 mips_elf_got16_reloc (abfd
,
951 arelent
*reloc_entry
;
954 asection
*input_section
;
956 char **error_message
;
958 /* If we're relocating, and this an external symbol, we don't want
959 to change anything. */
960 if (output_bfd
!= (bfd
*) NULL
961 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
962 && reloc_entry
->addend
== 0)
964 reloc_entry
->address
+= input_section
->output_offset
;
968 /* If we're relocating, and this is a local symbol, we can handle it
970 if (output_bfd
!= (bfd
*) NULL
971 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
972 return mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
973 input_section
, output_bfd
, error_message
);
978 /* We have to figure out the gp value, so that we can adjust the
979 symbol value correctly. We look up the symbol _gp in the output
980 BFD. If we can't find it, we're stuck. We cache it in the ELF
981 target data. We don't need to adjust the symbol value for an
982 external symbol if we are producing relocateable output. */
984 static bfd_reloc_status_type
985 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
988 boolean relocateable
;
989 char **error_message
;
992 if (bfd_is_und_section (symbol
->section
)
996 return bfd_reloc_undefined
;
999 *pgp
= _bfd_get_gp_value (output_bfd
);
1002 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1006 /* Make up a value. */
1007 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1008 _bfd_set_gp_value (output_bfd
, *pgp
);
1016 count
= bfd_get_symcount (output_bfd
);
1017 sym
= bfd_get_outsymbols (output_bfd
);
1019 if (sym
== (asymbol
**) NULL
)
1023 for (i
= 0; i
< count
; i
++, sym
++)
1025 register CONST
char *name
;
1027 name
= bfd_asymbol_name (*sym
);
1028 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1030 *pgp
= bfd_asymbol_value (*sym
);
1031 _bfd_set_gp_value (output_bfd
, *pgp
);
1039 /* Only get the error once. */
1041 _bfd_set_gp_value (output_bfd
, *pgp
);
1043 (char *) "GP relative relocation when _gp not defined";
1044 return bfd_reloc_dangerous
;
1049 return bfd_reloc_ok
;
1052 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1053 become the offset from the gp register. This function also handles
1054 R_MIPS_LITERAL relocations, although those can be handled more
1055 cleverly because the entries in the .lit8 and .lit4 sections can be
1058 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1059 arelent
*, asection
*,
1060 boolean
, PTR
, bfd_vma
));
1062 static bfd_reloc_status_type
1063 mips_elf_gprel16_reloc (abfd
,
1071 arelent
*reloc_entry
;
1074 asection
*input_section
;
1076 char **error_message
;
1078 boolean relocateable
;
1079 bfd_reloc_status_type ret
;
1082 /* If we're relocating, and this is an external symbol with no
1083 addend, we don't want to change anything. We will only have an
1084 addend if this is a newly created reloc, not read from an ELF
1086 if (output_bfd
!= (bfd
*) NULL
1087 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1088 && reloc_entry
->addend
== 0)
1090 reloc_entry
->address
+= input_section
->output_offset
;
1091 return bfd_reloc_ok
;
1094 if (output_bfd
!= (bfd
*) NULL
)
1095 relocateable
= true;
1098 relocateable
= false;
1099 output_bfd
= symbol
->section
->output_section
->owner
;
1102 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1104 if (ret
!= bfd_reloc_ok
)
1107 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1108 relocateable
, data
, gp
);
1111 static bfd_reloc_status_type
1112 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1116 arelent
*reloc_entry
;
1117 asection
*input_section
;
1118 boolean relocateable
;
1126 if (bfd_is_com_section (symbol
->section
))
1129 relocation
= symbol
->value
;
1131 relocation
+= symbol
->section
->output_section
->vma
;
1132 relocation
+= symbol
->section
->output_offset
;
1134 if (reloc_entry
->address
> input_section
->_cooked_size
)
1135 return bfd_reloc_outofrange
;
1137 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1139 /* Set val to the offset into the section or symbol. */
1140 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1144 /* Adjust val for the final section location and GP value. If we
1145 are producing relocateable output, we don't want to do this for
1146 an external symbol. */
1148 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1149 val
+= relocation
- gp
;
1151 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1152 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1155 reloc_entry
->address
+= input_section
->output_offset
;
1157 /* Make sure it fit in 16 bits. */
1158 if (val
>= 0x8000 && val
< 0xffff8000)
1159 return bfd_reloc_overflow
;
1161 return bfd_reloc_ok
;
1164 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1165 from the gp register? XXX */
1167 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1168 arelent
*, asection
*,
1169 boolean
, PTR
, bfd_vma
));
1171 static bfd_reloc_status_type
1172 mips_elf_gprel32_reloc (abfd
,
1180 arelent
*reloc_entry
;
1183 asection
*input_section
;
1185 char **error_message
;
1187 boolean relocateable
;
1188 bfd_reloc_status_type ret
;
1191 /* If we're relocating, and this is an external symbol with no
1192 addend, we don't want to change anything. We will only have an
1193 addend if this is a newly created reloc, not read from an ELF
1195 if (output_bfd
!= (bfd
*) NULL
1196 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1197 && reloc_entry
->addend
== 0)
1199 *error_message
= (char *)
1200 "32bits gp relative relocation occurs for an external symbol";
1201 return bfd_reloc_outofrange
;
1204 if (output_bfd
!= (bfd
*) NULL
)
1206 relocateable
= true;
1207 gp
= _bfd_get_gp_value (output_bfd
);
1211 relocateable
= false;
1212 output_bfd
= symbol
->section
->output_section
->owner
;
1214 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1215 error_message
, &gp
);
1216 if (ret
!= bfd_reloc_ok
)
1220 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1221 relocateable
, data
, gp
);
1224 static bfd_reloc_status_type
1225 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1229 arelent
*reloc_entry
;
1230 asection
*input_section
;
1231 boolean relocateable
;
1238 if (bfd_is_com_section (symbol
->section
))
1241 relocation
= symbol
->value
;
1243 relocation
+= symbol
->section
->output_section
->vma
;
1244 relocation
+= symbol
->section
->output_offset
;
1246 if (reloc_entry
->address
> input_section
->_cooked_size
)
1247 return bfd_reloc_outofrange
;
1249 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1251 /* Set val to the offset into the section or symbol. */
1252 val
+= reloc_entry
->addend
;
1254 /* Adjust val for the final section location and GP value. If we
1255 are producing relocateable output, we don't want to do this for
1256 an external symbol. */
1258 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1259 val
+= relocation
- gp
;
1261 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1264 reloc_entry
->address
+= input_section
->output_offset
;
1266 return bfd_reloc_ok
;
1269 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1271 struct elf_reloc_map
{
1272 bfd_reloc_code_real_type bfd_reloc_val
;
1273 enum reloc_type elf_reloc_val
;
1276 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1278 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1279 { BFD_RELOC_16
, R_MIPS_16
},
1280 { BFD_RELOC_32
, R_MIPS_32
},
1281 { BFD_RELOC_CTOR
, R_MIPS_32
},
1282 { BFD_RELOC_32_PCREL
, R_MIPS_REL32
},
1283 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1284 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1285 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1286 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1287 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1288 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1289 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1290 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1291 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1292 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1293 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1294 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1295 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
}
1298 /* Given a BFD reloc type, return a howto structure. */
1300 static reloc_howto_type
*
1301 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1303 bfd_reloc_code_real_type code
;
1307 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1309 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1310 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1315 /* Given a MIPS reloc type, fill in an arelent structure. */
1318 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1321 Elf32_Internal_Rel
*dst
;
1323 unsigned int r_type
;
1325 r_type
= ELF32_R_TYPE (dst
->r_info
);
1326 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1327 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1329 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1330 value for the object file. We get the addend now, rather than
1331 when we do the relocation, because the symbol manipulations done
1332 by the linker may cause us to lose track of the input BFD. */
1333 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1334 && (r_type
== (unsigned int) R_MIPS_GPREL16
1335 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1336 cache_ptr
->addend
= elf_gp (abfd
);
1339 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1340 routines swap this structure in and out. They are used outside of
1341 BFD, so they are globally visible. */
1344 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1346 const Elf32_External_RegInfo
*ex
;
1349 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1350 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1351 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1352 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1353 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1354 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1358 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1360 const Elf32_RegInfo
*in
;
1361 Elf32_External_RegInfo
*ex
;
1363 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1364 (bfd_byte
*) ex
->ri_gprmask
);
1365 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1366 (bfd_byte
*) ex
->ri_cprmask
[0]);
1367 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1368 (bfd_byte
*) ex
->ri_cprmask
[1]);
1369 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1370 (bfd_byte
*) ex
->ri_cprmask
[2]);
1371 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1372 (bfd_byte
*) ex
->ri_cprmask
[3]);
1373 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1374 (bfd_byte
*) ex
->ri_gp_value
);
1377 /* Swap an entry in a .gptab section. Note that these routines rely
1378 on the equivalence of the two elements of the union. */
1381 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1383 const Elf32_External_gptab
*ex
;
1386 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1387 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1391 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1393 const Elf32_gptab
*in
;
1394 Elf32_External_gptab
*ex
;
1396 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1397 ex
->gt_entry
.gt_g_value
);
1398 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1399 ex
->gt_entry
.gt_bytes
);
1403 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1405 const Elf32_compact_rel
*in
;
1406 Elf32_External_compact_rel
*ex
;
1408 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
1409 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
1410 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
1411 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
1412 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
1413 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
1417 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1419 const Elf32_crinfo
*in
;
1420 Elf32_External_crinfo
*ex
;
1424 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1425 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1426 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1427 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1428 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
1429 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
1430 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
1433 /* Determine whether a symbol is global for the purposes of splitting
1434 the symbol table into global symbols and local symbols. At least
1435 on Irix 5, this split must be between section symbols and all other
1436 symbols. On most ELF targets the split is between static symbols
1437 and externally visible symbols. */
1441 mips_elf_sym_is_global (abfd
, sym
)
1445 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
1448 /* Set the right machine number for a MIPS ELF file. */
1451 mips_elf_object_p (abfd
)
1454 switch (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
)
1458 /* Just use the default, which was set in elfcode.h. */
1462 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 6000);
1466 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 4000);
1470 /* Irix 5 is broken. Object file symbol tables are not always
1471 sorted correctly such that local symbols precede global symbols,
1472 and the sh_info field in the symbol table is not always right. */
1473 elf_bad_symtab (abfd
) = true;
1478 /* The final processing done just before writing out a MIPS ELF object
1479 file. This gets the MIPS architecture right based on the machine
1484 mips_elf_final_write_processing (abfd
, linker
)
1490 Elf_Internal_Shdr
**hdrpp
;
1492 switch (bfd_get_mach (abfd
))
1495 val
= E_MIPS_ARCH_1
;
1499 val
= E_MIPS_ARCH_2
;
1503 val
= E_MIPS_ARCH_3
;
1511 elf_elfheader (abfd
)->e_flags
&=~ EF_MIPS_ARCH
;
1512 elf_elfheader (abfd
)->e_flags
|= val
;
1514 /* Set the sh_info field for .gptab sections. */
1515 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
1516 i
< elf_elfheader (abfd
)->e_shnum
;
1519 if ((*hdrpp
)->sh_type
== SHT_MIPS_GPTAB
)
1524 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1525 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1526 BFD_ASSERT (name
!= NULL
1527 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
1528 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
1529 BFD_ASSERT (sec
!= NULL
);
1530 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1535 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
1538 mips_elf_set_private_flags (abfd
, flags
)
1542 BFD_ASSERT (!elf_flags_init (abfd
)
1543 || elf_elfheader (abfd
)->e_flags
== flags
);
1545 elf_elfheader (abfd
)->e_flags
= flags
;
1546 elf_flags_init (abfd
) = true;
1550 /* Copy backend specific data from one object module to another */
1553 mips_elf_copy_private_bfd_data (ibfd
, obfd
)
1557 /* This function is selected based on the input vector. We only
1558 want to copy information over if the output BFD also uses Elf
1560 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1563 BFD_ASSERT (!elf_flags_init (obfd
)
1564 || (elf_elfheader (obfd
)->e_flags
1565 == elf_elfheader (ibfd
)->e_flags
));
1567 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1568 elf_flags_init (obfd
) = true;
1572 /* Merge backend specific data from an object file to the output
1573 object file when linking. */
1576 mips_elf_merge_private_bfd_data (ibfd
, obfd
)
1583 /* Check if we have the same endianess */
1584 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1585 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1587 (*_bfd_error_handler
)
1588 ("%s: compiled for a %s endian system and target is %s endian",
1589 bfd_get_filename (ibfd
),
1590 bfd_big_endian (ibfd
) ? "big" : "little",
1591 bfd_big_endian (obfd
) ? "big" : "little");
1593 bfd_set_error (bfd_error_wrong_format
);
1597 /* This function is selected based on the input vector. We only
1598 want to copy information over if the output BFD also uses Elf
1600 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1603 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1604 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
1605 old_flags
= elf_elfheader (obfd
)->e_flags
;
1607 if (!elf_flags_init (obfd
)) /* First call, no flags set */
1609 elf_flags_init (obfd
) = true;
1610 elf_elfheader (obfd
)->e_flags
= new_flags
;
1612 else if (((new_flags
^ old_flags
) & ~EF_MIPS_NOREORDER
)
1613 == 0) /* Compatible flags are ok */
1615 else /* Incompatible flags */
1617 /* Warn about -fPIC mismatch */
1618 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
1620 new_flags
&= ~EF_MIPS_PIC
;
1621 (*_bfd_error_handler
)
1622 ("%s: needs all files compiled with -fPIC",
1623 bfd_get_filename (ibfd
));
1626 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
1628 new_flags
&= ~EF_MIPS_CPIC
;
1629 (*_bfd_error_handler
)
1630 ("%s: needs all files compiled with -mabicalls",
1631 bfd_get_filename (ibfd
));
1634 /* Warn about any other mismatches */
1635 if (new_flags
!= old_flags
)
1636 (*_bfd_error_handler
)
1637 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1638 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
1639 (unsigned long) old_flags
);
1641 bfd_set_error (bfd_error_bad_value
);
1648 /* Handle a MIPS specific section when reading an object file. This
1649 is called when elfcode.h finds a section with an unknown type.
1650 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
1654 mips_elf_section_from_shdr (abfd
, hdr
, name
)
1656 Elf32_Internal_Shdr
*hdr
;
1661 /* There ought to be a place to keep ELF backend specific flags, but
1662 at the moment there isn't one. We just keep track of the
1663 sections by their name, instead. Fortunately, the ABI gives
1664 suggested names for all the MIPS specific sections, so we will
1665 probably get away with this. */
1666 switch (hdr
->sh_type
)
1668 case SHT_MIPS_LIBLIST
:
1669 if (strcmp (name
, ".liblist") != 0)
1673 if (strcmp (name
, ".msym") != 0)
1676 case SHT_MIPS_CONFLICT
:
1677 if (strcmp (name
, ".conflict") != 0)
1680 case SHT_MIPS_GPTAB
:
1681 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
1684 case SHT_MIPS_UCODE
:
1685 if (strcmp (name
, ".ucode") != 0)
1688 case SHT_MIPS_DEBUG
:
1689 if (strcmp (name
, ".mdebug") != 0)
1692 case SHT_MIPS_REGINFO
:
1693 if (strcmp (name
, ".reginfo") != 0
1694 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
1697 case SHT_MIPS_OPTIONS
:
1698 if (strcmp (name
, ".options") != 0)
1701 case SHT_MIPS_DWARF
:
1702 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
1705 case SHT_MIPS_EVENTS
:
1706 if (strncmp (name
, ".MIPS.events.", sizeof ".MIPS.events." - 1) != 0)
1713 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1715 newsect
= hdr
->bfd_section
;
1717 if (hdr
->sh_type
== SHT_MIPS_DEBUG
)
1719 if (! bfd_set_section_flags (abfd
, newsect
,
1720 (bfd_get_section_flags (abfd
, newsect
)
1725 /* FIXME: We should record sh_info for a .gptab section. */
1727 /* For a .reginfo section, set the gp value in the tdata information
1728 from the contents of this section. We need the gp value while
1729 processing relocs, so we just get it now. */
1730 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
1732 Elf32_External_RegInfo ext
;
1735 if (! bfd_get_section_contents (abfd
, newsect
, (PTR
) &ext
,
1736 (file_ptr
) 0, sizeof ext
))
1738 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
1739 elf_gp (abfd
) = s
.ri_gp_value
;
1745 /* Set the correct type for a MIPS ELF section. We do this by the
1746 section name, which is a hack, but ought to work. */
1749 mips_elf_fake_sections (abfd
, hdr
, sec
)
1751 Elf32_Internal_Shdr
*hdr
;
1754 register const char *name
;
1756 name
= bfd_get_section_name (abfd
, sec
);
1758 if (strcmp (name
, ".liblist") == 0)
1760 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
1761 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
1762 /* FIXME: Set the sh_link field. */
1764 else if (strcmp (name
, ".msym") == 0)
1766 hdr
->sh_type
= SHT_MIPS_MSYM
;
1767 hdr
->sh_entsize
= 8;
1768 /* FIXME: Set the sh_info field. */
1770 else if (strcmp (name
, ".conflict") == 0)
1771 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
1772 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
1774 hdr
->sh_type
= SHT_MIPS_GPTAB
;
1775 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
1776 /* The sh_info field is set in mips_elf_final_write_processing. */
1778 else if (strcmp (name
, ".ucode") == 0)
1779 hdr
->sh_type
= SHT_MIPS_UCODE
;
1780 else if (strcmp (name
, ".mdebug") == 0)
1782 hdr
->sh_type
= SHT_MIPS_DEBUG
;
1783 /* In a shared object on Irix 5.3, the .mdebug section has an
1784 entsize of 0. FIXME: Does this matter? */
1785 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
1786 hdr
->sh_entsize
= 0;
1788 hdr
->sh_entsize
= 1;
1790 else if (strcmp (name
, ".reginfo") == 0)
1792 hdr
->sh_type
= SHT_MIPS_REGINFO
;
1793 /* In a shared object on Irix 5.3, the .reginfo section has an
1794 entsize of 0x18. FIXME: Does this matter? */
1795 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
1796 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
1798 hdr
->sh_entsize
= 1;
1800 /* Force the section size to the correct value, even if the
1801 linker thinks it is larger. The link routine below will only
1802 write out this much data for .reginfo. */
1803 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf32_External_RegInfo
);
1805 else if (SGI_COMPAT (abfd
)
1806 && (strcmp (name
, ".hash") == 0
1807 || strcmp (name
, ".dynamic") == 0
1808 || strcmp (name
, ".dynstr") == 0))
1810 hdr
->sh_entsize
= 0;
1811 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
1813 else if (strcmp (name
, ".got") == 0
1814 || strcmp (name
, ".sdata") == 0
1815 || strcmp (name
, ".sbss") == 0
1816 || strcmp (name
, ".lit4") == 0
1817 || strcmp (name
, ".lit8") == 0)
1818 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
1819 else if (strcmp (name
, ".options") == 0)
1821 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
1822 hdr
->sh_entsize
= 1;
1824 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
1825 hdr
->sh_type
= SHT_MIPS_DWARF
;
1826 else if (strncmp (name
, ".MIPS.events.", sizeof ".MIPS.events." - 1) == 0)
1827 hdr
->sh_type
= SHT_MIPS_EVENTS
;
1832 /* Given a BFD section, try to locate the corresponding ELF section
1836 mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
1838 Elf32_Internal_Shdr
*hdr
;
1842 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
1844 *retval
= SHN_MIPS_SCOMMON
;
1847 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
1849 *retval
= SHN_MIPS_ACOMMON
;
1855 /* Work over a section just before writing it out. We update the GP
1856 value in the .reginfo section based on the value we are using.
1857 FIXME: We recognize sections that need the SHF_MIPS_GPREL flag by
1858 name; there has to be a better way. */
1861 mips_elf_section_processing (abfd
, hdr
)
1863 Elf32_Internal_Shdr
*hdr
;
1865 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
1869 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
1870 BFD_ASSERT (hdr
->contents
== NULL
);
1873 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
1876 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
1877 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
1881 if (hdr
->bfd_section
!= NULL
)
1883 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
1885 if (strcmp (name
, ".sdata") == 0)
1887 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
1888 hdr
->sh_type
= SHT_PROGBITS
;
1890 else if (strcmp (name
, ".sbss") == 0)
1892 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
1893 hdr
->sh_type
= SHT_NOBITS
;
1895 else if (strcmp (name
, ".lit8") == 0
1896 || strcmp (name
, ".lit4") == 0)
1898 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
1899 hdr
->sh_type
= SHT_PROGBITS
;
1901 else if (strcmp (name
, ".compact_rel") == 0)
1904 hdr
->sh_type
= SHT_PROGBITS
;
1906 else if (strcmp (name
, ".rtproc") == 0)
1908 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
1910 unsigned int adjust
;
1912 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
1914 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
1922 /* MIPS ELF uses two common sections. One is the usual one, and the
1923 other is for small objects. All the small objects are kept
1924 together, and then referenced via the gp pointer, which yields
1925 faster assembler code. This is what we use for the small common
1926 section. This approach is copied from ecoff.c. */
1927 static asection mips_elf_scom_section
;
1928 static asymbol mips_elf_scom_symbol
;
1929 static asymbol
*mips_elf_scom_symbol_ptr
;
1931 /* MIPS ELF also uses an acommon section, which represents an
1932 allocated common symbol which may be overridden by a
1933 definition in a shared library. */
1934 static asection mips_elf_acom_section
;
1935 static asymbol mips_elf_acom_symbol
;
1936 static asymbol
*mips_elf_acom_symbol_ptr
;
1938 /* The Irix 5 support uses two virtual sections, which represent
1939 text/data symbols defined in dynamic objects. */
1940 static asection mips_elf_text_section
;
1941 static asection
*mips_elf_text_section_ptr
;
1942 static asymbol mips_elf_text_symbol
;
1943 static asymbol
*mips_elf_text_symbol_ptr
;
1945 static asection mips_elf_data_section
;
1946 static asection
*mips_elf_data_section_ptr
;
1947 static asymbol mips_elf_data_symbol
;
1948 static asymbol
*mips_elf_data_symbol_ptr
;
1950 /* Handle the special MIPS section numbers that a symbol may use. */
1953 mips_elf_symbol_processing (abfd
, asym
)
1957 elf_symbol_type
*elfsym
;
1959 elfsym
= (elf_symbol_type
*) asym
;
1960 switch (elfsym
->internal_elf_sym
.st_shndx
)
1962 case SHN_MIPS_ACOMMON
:
1963 /* This section is used in a dynamically linked executable file.
1964 It is an allocated common section. The dynamic linker can
1965 either resolve these symbols to something in a shared
1966 library, or it can just leave them here. For our purposes,
1967 we can consider these symbols to be in a new section. */
1968 if (mips_elf_acom_section
.name
== NULL
)
1970 /* Initialize the acommon section. */
1971 mips_elf_acom_section
.name
= ".acommon";
1972 mips_elf_acom_section
.flags
= SEC_ALLOC
;
1973 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
1974 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
1975 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
1976 mips_elf_acom_symbol
.name
= ".acommon";
1977 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
1978 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
1979 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
1981 asym
->section
= &mips_elf_acom_section
;
1985 /* Common symbols less than the GP size are automatically
1986 treated as SHN_MIPS_SCOMMON symbols. */
1987 if (asym
->value
> elf_gp_size (abfd
))
1990 case SHN_MIPS_SCOMMON
:
1991 if (mips_elf_scom_section
.name
== NULL
)
1993 /* Initialize the small common section. */
1994 mips_elf_scom_section
.name
= ".scommon";
1995 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
1996 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
1997 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
1998 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
1999 mips_elf_scom_symbol
.name
= ".scommon";
2000 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2001 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
2002 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
2004 asym
->section
= &mips_elf_scom_section
;
2005 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2008 case SHN_MIPS_SUNDEFINED
:
2009 asym
->section
= bfd_und_section_ptr
;
2012 #if 0 /* for SGI_COMPAT */
2014 asym
->section
= mips_elf_text_section_ptr
;
2018 asym
->section
= mips_elf_data_section_ptr
;
2024 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
2028 mips_elf_additional_program_headers (abfd
)
2036 if (! SGI_COMPAT (abfd
))
2039 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2040 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2042 /* We need a PT_MIPS_REGINFO segment. */
2046 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2047 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2049 /* We need a PT_MIPS_RTPROC segment. */
2056 /* Modify the segment map for an Irix 5 executable. */
2059 mips_elf_modify_segment_map (abfd
)
2063 struct elf_segment_map
*m
, **pm
;
2065 if (! SGI_COMPAT (abfd
))
2068 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
2070 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2071 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2073 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2074 if (m
->p_type
== PT_MIPS_REGINFO
)
2078 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2082 m
->p_type
= PT_MIPS_REGINFO
;
2086 /* We want to put it after the PHDR and INTERP segments. */
2087 pm
= &elf_tdata (abfd
)->segment_map
;
2089 && ((*pm
)->p_type
== PT_PHDR
2090 || (*pm
)->p_type
== PT_INTERP
))
2098 /* If there are .dynamic and .mdebug sections, we make a room for
2099 the RTPROC header. FIXME: Rewrite without section names. */
2100 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
2101 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2102 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2104 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2105 if (m
->p_type
== PT_MIPS_RTPROC
)
2109 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2113 m
->p_type
= PT_MIPS_RTPROC
;
2115 s
= bfd_get_section_by_name (abfd
, ".rtproc");
2120 m
->p_flags_valid
= 1;
2128 /* We want to put it after the DYNAMIC segment. */
2129 pm
= &elf_tdata (abfd
)->segment_map
;
2130 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
2140 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
2141 .dynsym, and .hash sections, and everything in between. */
2142 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
2143 if ((*pm
)->p_type
== PT_DYNAMIC
)
2148 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
2150 static const char *sec_names
[] =
2151 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
2154 struct elf_segment_map
*n
;
2158 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
2160 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
2161 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2167 sz
= s
->_cooked_size
;
2170 if (high
< s
->vma
+ sz
)
2176 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2177 if ((s
->flags
& SEC_LOAD
) != 0
2180 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2184 n
= ((struct elf_segment_map
*)
2185 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
2192 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2194 if ((s
->flags
& SEC_LOAD
) != 0
2197 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2211 /* The structure of the runtime procedure descriptor created by the
2212 loader for use by the static exception system. */
2214 typedef struct runtime_pdr
{
2215 bfd_vma adr
; /* memory address of start of procedure */
2216 long regmask
; /* save register mask */
2217 long regoffset
; /* save register offset */
2218 long fregmask
; /* save floating point register mask */
2219 long fregoffset
; /* save floating point register offset */
2220 long frameoffset
; /* frame size */
2221 short framereg
; /* frame pointer register */
2222 short pcreg
; /* offset or reg of return pc */
2223 long irpss
; /* index into the runtime string table */
2225 struct exception_info
*exception_info
;/* pointer to exception array */
2227 #define cbRPDR sizeof(RPDR)
2228 #define rpdNil ((pRPDR) 0)
2230 /* Swap RPDR (runtime procedure table entry) for output. */
2232 static void ecoff_swap_rpdr_out
2233 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
2236 ecoff_swap_rpdr_out (abfd
, in
, ex
)
2239 struct rpdr_ext
*ex
;
2241 /* ecoff_put_off was defined in ecoffswap.h. */
2242 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
2243 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
2244 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
2245 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
2246 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
2247 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
2249 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
2250 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
2252 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
2254 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
2258 /* Read ECOFF debugging information from a .mdebug section into a
2259 ecoff_debug_info structure. */
2262 mips_elf_read_ecoff_info (abfd
, section
, debug
)
2265 struct ecoff_debug_info
*debug
;
2268 const struct ecoff_debug_swap
*swap
;
2269 char *ext_hdr
= NULL
;
2271 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2273 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
2274 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
2277 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
2278 swap
->external_hdr_size
)
2282 symhdr
= &debug
->symbolic_header
;
2283 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
2285 /* The symbolic header contains absolute file offsets and sizes to
2287 #define READ(ptr, offset, count, size, type) \
2288 if (symhdr->count == 0) \
2289 debug->ptr = NULL; \
2292 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
2293 if (debug->ptr == NULL) \
2294 goto error_return; \
2295 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
2296 || (bfd_read (debug->ptr, size, symhdr->count, \
2297 abfd) != size * symhdr->count)) \
2298 goto error_return; \
2301 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
2302 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
2303 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
2304 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
2305 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
2306 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
2308 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
2309 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
2310 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
2311 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
2312 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
2316 debug
->adjust
= NULL
;
2321 if (ext_hdr
!= NULL
)
2323 if (debug
->line
!= NULL
)
2325 if (debug
->external_dnr
!= NULL
)
2326 free (debug
->external_dnr
);
2327 if (debug
->external_pdr
!= NULL
)
2328 free (debug
->external_pdr
);
2329 if (debug
->external_sym
!= NULL
)
2330 free (debug
->external_sym
);
2331 if (debug
->external_opt
!= NULL
)
2332 free (debug
->external_opt
);
2333 if (debug
->external_aux
!= NULL
)
2334 free (debug
->external_aux
);
2335 if (debug
->ss
!= NULL
)
2337 if (debug
->ssext
!= NULL
)
2338 free (debug
->ssext
);
2339 if (debug
->external_fdr
!= NULL
)
2340 free (debug
->external_fdr
);
2341 if (debug
->external_rfd
!= NULL
)
2342 free (debug
->external_rfd
);
2343 if (debug
->external_ext
!= NULL
)
2344 free (debug
->external_ext
);
2348 /* MIPS ELF local labels start with '$', not 'L'. */
2352 mips_elf_is_local_label (abfd
, symbol
)
2356 return symbol
->name
[0] == '$';
2359 /* MIPS ELF uses a special find_nearest_line routine in order the
2360 handle the ECOFF debugging information. */
2362 struct mips_elf_find_line
2364 struct ecoff_debug_info d
;
2365 struct ecoff_find_line i
;
2369 mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
2370 functionname_ptr
, line_ptr
)
2375 const char **filename_ptr
;
2376 const char **functionname_ptr
;
2377 unsigned int *line_ptr
;
2381 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
2385 struct mips_elf_find_line
*fi
;
2386 const struct ecoff_debug_swap
* const swap
=
2387 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2389 /* If we are called during a link, mips_elf_final_link may have
2390 cleared the SEC_HAS_CONTENTS field. We force it back on here
2391 if appropriate (which it normally will be). */
2392 origflags
= msec
->flags
;
2393 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
2394 msec
->flags
|= SEC_HAS_CONTENTS
;
2396 fi
= elf_tdata (abfd
)->find_line_info
;
2399 bfd_size_type external_fdr_size
;
2402 struct fdr
*fdr_ptr
;
2404 fi
= ((struct mips_elf_find_line
*)
2405 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
2408 msec
->flags
= origflags
;
2412 if (! mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
2414 msec
->flags
= origflags
;
2418 /* Swap in the FDR information. */
2419 fi
->d
.fdr
= ((struct fdr
*)
2421 (fi
->d
.symbolic_header
.ifdMax
*
2422 sizeof (struct fdr
))));
2423 if (fi
->d
.fdr
== NULL
)
2425 msec
->flags
= origflags
;
2428 external_fdr_size
= swap
->external_fdr_size
;
2429 fdr_ptr
= fi
->d
.fdr
;
2430 fraw_src
= (char *) fi
->d
.external_fdr
;
2431 fraw_end
= (fraw_src
2432 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
2433 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
2434 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
2436 elf_tdata (abfd
)->find_line_info
= fi
;
2438 /* Note that we don't bother to ever free this information.
2439 find_nearest_line is either called all the time, as in
2440 objdump -l, so the information should be saved, or it is
2441 rarely called, as in ld error messages, so the memory
2442 wasted is unimportant. Still, it would probably be a
2443 good idea for free_cached_info to throw it away. */
2446 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
2447 &fi
->i
, filename_ptr
, functionname_ptr
,
2450 msec
->flags
= origflags
;
2454 msec
->flags
= origflags
;
2457 /* Fall back on the generic ELF find_nearest_line routine. */
2459 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
2460 filename_ptr
, functionname_ptr
,
2464 /* The MIPS ELF linker needs additional information for each symbol in
2465 the global hash table. */
2467 struct mips_elf_link_hash_entry
2469 struct elf_link_hash_entry root
;
2471 /* External symbol information. */
2474 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
2475 unsigned int mips_32_relocs
;
2478 /* MIPS ELF linker hash table. */
2480 struct mips_elf_link_hash_table
2482 struct elf_link_hash_table root
;
2483 /* String section indices for the dynamic section symbols. */
2484 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
2485 /* The number of .rtproc entries. */
2486 bfd_size_type procedure_count
;
2487 /* The size of the .compact_rel section (if SGI_COMPAT). */
2488 bfd_size_type compact_rel_size
;
2491 /* Look up an entry in a MIPS ELF linker hash table. */
2493 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
2494 ((struct mips_elf_link_hash_entry *) \
2495 elf_link_hash_lookup (&(table)->root, (string), (create), \
2498 /* Traverse a MIPS ELF linker hash table. */
2500 #define mips_elf_link_hash_traverse(table, func, info) \
2501 (elf_link_hash_traverse \
2503 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
2506 /* Get the MIPS ELF linker hash table from a link_info structure. */
2508 #define mips_elf_hash_table(p) \
2509 ((struct mips_elf_link_hash_table *) ((p)->hash))
2511 static boolean mips_elf_output_extsym
2512 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
2514 /* Create an entry in a MIPS ELF linker hash table. */
2516 static struct bfd_hash_entry
*
2517 mips_elf_link_hash_newfunc (entry
, table
, string
)
2518 struct bfd_hash_entry
*entry
;
2519 struct bfd_hash_table
*table
;
2522 struct mips_elf_link_hash_entry
*ret
=
2523 (struct mips_elf_link_hash_entry
*) entry
;
2525 /* Allocate the structure if it has not already been allocated by a
2527 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
2528 ret
= ((struct mips_elf_link_hash_entry
*)
2529 bfd_hash_allocate (table
,
2530 sizeof (struct mips_elf_link_hash_entry
)));
2531 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
2532 return (struct bfd_hash_entry
*) ret
;
2534 /* Call the allocation method of the superclass. */
2535 ret
= ((struct mips_elf_link_hash_entry
*)
2536 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2538 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
2540 /* Set local fields. */
2541 memset (&ret
->esym
, 0, sizeof (EXTR
));
2542 /* We use -2 as a marker to indicate that the information has
2543 not been set. -1 means there is no associated ifd. */
2545 ret
->mips_32_relocs
= 0;
2548 return (struct bfd_hash_entry
*) ret
;
2551 /* Create a MIPS ELF linker hash table. */
2553 static struct bfd_link_hash_table
*
2554 mips_elf_link_hash_table_create (abfd
)
2557 struct mips_elf_link_hash_table
*ret
;
2560 ret
= ((struct mips_elf_link_hash_table
*)
2561 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
2562 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
2565 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
2566 mips_elf_link_hash_newfunc
))
2568 bfd_release (abfd
, ret
);
2572 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
2573 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
2574 ret
->procedure_count
= 0;
2575 ret
->compact_rel_size
= 0;
2577 return &ret
->root
.root
;
2580 /* Hook called by the linker routine which adds symbols from an object
2581 file. We must handle the special MIPS section numbers here. */
2585 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2587 struct bfd_link_info
*info
;
2588 const Elf_Internal_Sym
*sym
;
2594 if (SGI_COMPAT (abfd
)
2595 && (abfd
->flags
& DYNAMIC
) != 0
2596 && strcmp (*namep
, "_rld_new_interface") == 0)
2598 /* Skip Irix 5 rld entry name. */
2603 switch (sym
->st_shndx
)
2606 /* Common symbols less than the GP size are automatically
2607 treated as SHN_MIPS_SCOMMON symbols. */
2608 if (sym
->st_size
> elf_gp_size (abfd
))
2611 case SHN_MIPS_SCOMMON
:
2612 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
2613 (*secp
)->flags
|= SEC_IS_COMMON
;
2614 *valp
= sym
->st_size
;
2618 /* This section is used in a shared object. */
2619 if (mips_elf_text_section_ptr
== NULL
)
2621 /* Initialize the section. */
2622 mips_elf_text_section
.name
= ".text";
2623 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
2624 mips_elf_text_section
.output_section
= NULL
;
2625 mips_elf_text_section
.owner
= abfd
;
2626 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
2627 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
2628 mips_elf_text_symbol
.name
= ".text";
2629 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
2630 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
2631 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
2632 mips_elf_text_section_ptr
= &mips_elf_text_section
;
2635 *secp
= bfd_und_section_ptr
;
2637 *secp
= mips_elf_text_section_ptr
;
2640 case SHN_MIPS_ACOMMON
:
2641 /* Fall through. XXX Can we treat this as allocated data? */
2643 /* This section is used in a shared object. */
2644 if (mips_elf_data_section_ptr
== NULL
)
2646 /* Initialize the section. */
2647 mips_elf_data_section
.name
= ".data";
2648 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
2649 mips_elf_data_section
.output_section
= NULL
;
2650 mips_elf_data_section
.owner
= abfd
;
2651 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
2652 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
2653 mips_elf_data_symbol
.name
= ".data";
2654 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
2655 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
2656 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
2657 mips_elf_data_section_ptr
= &mips_elf_data_section
;
2660 *secp
= bfd_und_section_ptr
;
2662 *secp
= mips_elf_data_section_ptr
;
2665 case SHN_MIPS_SUNDEFINED
:
2666 *secp
= bfd_und_section_ptr
;
2673 /* Structure used to pass information to mips_elf_output_extsym. */
2678 struct bfd_link_info
*info
;
2679 struct ecoff_debug_info
*debug
;
2680 const struct ecoff_debug_swap
*swap
;
2684 /* This routine is used to write out ECOFF debugging external symbol
2685 information. It is called via mips_elf_link_hash_traverse. The
2686 ECOFF external symbol information must match the ELF external
2687 symbol information. Unfortunately, at this point we don't know
2688 whether a symbol is required by reloc information, so the two
2689 tables may wind up being different. We must sort out the external
2690 symbol information before we can set the final size of the .mdebug
2691 section, and we must set the size of the .mdebug section before we
2692 can relocate any sections, and we can't know which symbols are
2693 required by relocation until we relocate the sections.
2694 Fortunately, it is relatively unlikely that any symbol will be
2695 stripped but required by a reloc. In particular, it can not happen
2696 when generating a final executable. */
2699 mips_elf_output_extsym (h
, data
)
2700 struct mips_elf_link_hash_entry
*h
;
2703 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
2705 asection
*sec
, *output_section
;
2707 if (h
->root
.indx
== -2)
2709 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2710 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
2711 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
2712 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
2714 else if (einfo
->info
->strip
== strip_all
2715 || (einfo
->info
->strip
== strip_some
2716 && bfd_hash_lookup (einfo
->info
->keep_hash
,
2717 h
->root
.root
.root
.string
,
2718 false, false) == NULL
))
2726 if (h
->esym
.ifd
== -2)
2729 h
->esym
.cobol_main
= 0;
2730 h
->esym
.weakext
= 0;
2731 h
->esym
.reserved
= 0;
2732 h
->esym
.ifd
= ifdNil
;
2733 h
->esym
.asym
.value
= 0;
2734 h
->esym
.asym
.st
= stGlobal
;
2736 if (SGI_COMPAT (einfo
->abfd
)
2737 && (h
->root
.root
.type
== bfd_link_hash_undefined
2738 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
2742 /* Use undefined class. Also, set class and type for some
2744 name
= h
->root
.root
.root
.string
;
2745 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
2746 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
2748 h
->esym
.asym
.sc
= scData
;
2749 h
->esym
.asym
.st
= stLabel
;
2750 h
->esym
.asym
.value
= 0;
2752 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
2754 h
->esym
.asym
.sc
= scAbs
;
2755 h
->esym
.asym
.st
= stLabel
;
2756 h
->esym
.asym
.value
=
2757 mips_elf_hash_table (einfo
->info
)->procedure_count
;
2759 else if (strcmp (name
, "_gp_disp") == 0)
2761 h
->esym
.asym
.sc
= scAbs
;
2762 h
->esym
.asym
.st
= stLabel
;
2763 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
2766 h
->esym
.asym
.sc
= scUndefined
;
2768 else if (h
->root
.root
.type
!= bfd_link_hash_defined
2769 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2770 h
->esym
.asym
.sc
= scAbs
;
2775 sec
= h
->root
.root
.u
.def
.section
;
2776 output_section
= sec
->output_section
;
2778 /* When making a shared library and symbol h is the one from
2779 the another shared library, OUTPUT_SECTION may be null. */
2780 if (output_section
== NULL
)
2781 h
->esym
.asym
.sc
= scUndefined
;
2784 name
= bfd_section_name (output_section
->owner
, output_section
);
2786 if (strcmp (name
, ".text") == 0)
2787 h
->esym
.asym
.sc
= scText
;
2788 else if (strcmp (name
, ".data") == 0)
2789 h
->esym
.asym
.sc
= scData
;
2790 else if (strcmp (name
, ".sdata") == 0)
2791 h
->esym
.asym
.sc
= scSData
;
2792 else if (strcmp (name
, ".rodata") == 0
2793 || strcmp (name
, ".rdata") == 0)
2794 h
->esym
.asym
.sc
= scRData
;
2795 else if (strcmp (name
, ".bss") == 0)
2796 h
->esym
.asym
.sc
= scBss
;
2797 else if (strcmp (name
, ".sbss") == 0)
2798 h
->esym
.asym
.sc
= scSBss
;
2799 else if (strcmp (name
, ".init") == 0)
2800 h
->esym
.asym
.sc
= scInit
;
2801 else if (strcmp (name
, ".fini") == 0)
2802 h
->esym
.asym
.sc
= scFini
;
2804 h
->esym
.asym
.sc
= scAbs
;
2808 h
->esym
.asym
.reserved
= 0;
2809 h
->esym
.asym
.index
= indexNil
;
2812 if (h
->root
.root
.type
== bfd_link_hash_common
)
2813 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2814 else if (h
->root
.root
.type
== bfd_link_hash_defined
2815 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2817 if (h
->esym
.asym
.sc
== scCommon
)
2818 h
->esym
.asym
.sc
= scBss
;
2819 else if (h
->esym
.asym
.sc
== scSCommon
)
2820 h
->esym
.asym
.sc
= scSBss
;
2822 sec
= h
->root
.root
.u
.def
.section
;
2823 output_section
= sec
->output_section
;
2824 if (output_section
!= NULL
)
2825 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2826 + sec
->output_offset
2827 + output_section
->vma
);
2829 h
->esym
.asym
.value
= 0;
2831 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
2833 /* Set type and value for a symbol with a function stub. */
2834 h
->esym
.asym
.st
= stProc
;
2835 sec
= h
->root
.root
.u
.def
.section
;
2837 h
->esym
.asym
.value
= 0;
2840 output_section
= sec
->output_section
;
2841 if (output_section
!= NULL
)
2842 h
->esym
.asym
.value
= (h
->root
.plt_offset
2843 + sec
->output_offset
2844 + output_section
->vma
);
2846 h
->esym
.asym
.value
= 0;
2853 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
2854 h
->root
.root
.root
.string
,
2857 einfo
->failed
= true;
2864 /* Create a runtime procedure table from the .mdebug section. */
2867 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
2870 struct bfd_link_info
*info
;
2872 struct ecoff_debug_info
*debug
;
2874 const struct ecoff_debug_swap
*swap
;
2875 HDRR
*hdr
= &debug
->symbolic_header
;
2877 struct rpdr_ext
*erp
;
2879 struct pdr_ext
*epdr
;
2880 struct sym_ext
*esym
;
2883 unsigned long size
, count
;
2884 unsigned long sindex
;
2888 const char *no_name_func
= "static procedure (no name)";
2896 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2898 sindex
= strlen (no_name_func
) + 1;
2899 count
= hdr
->ipdMax
;
2902 size
= swap
->external_pdr_size
;
2904 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
2908 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
2911 size
= sizeof (RPDR
);
2912 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
2916 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
2920 count
= hdr
->isymMax
;
2921 size
= swap
->external_sym_size
;
2922 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
2926 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
2929 count
= hdr
->issMax
;
2930 ss
= (char *) bfd_malloc (count
);
2933 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
2936 count
= hdr
->ipdMax
;
2937 for (i
= 0; i
< count
; i
++, rp
++)
2939 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
2940 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
2941 rp
->adr
= sym
.value
;
2942 rp
->regmask
= pdr
.regmask
;
2943 rp
->regoffset
= pdr
.regoffset
;
2944 rp
->fregmask
= pdr
.fregmask
;
2945 rp
->fregoffset
= pdr
.fregoffset
;
2946 rp
->frameoffset
= pdr
.frameoffset
;
2947 rp
->framereg
= pdr
.framereg
;
2948 rp
->pcreg
= pdr
.pcreg
;
2950 sv
[i
] = ss
+ sym
.iss
;
2951 sindex
+= strlen (sv
[i
]) + 1;
2955 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
2956 size
= BFD_ALIGN (size
, 16);
2957 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
2960 mips_elf_hash_table (info
)->procedure_count
= 0;
2964 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
2966 erp
= (struct rpdr_ext
*) rtproc
;
2967 memset (erp
, 0, sizeof (struct rpdr_ext
));
2969 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
2970 strcpy (str
, no_name_func
);
2971 str
+= strlen (no_name_func
) + 1;
2972 for (i
= 0; i
< count
; i
++)
2974 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
2975 strcpy (str
, sv
[i
]);
2976 str
+= strlen (sv
[i
]) + 1;
2978 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
2980 /* Set the size and contents of .rtproc section. */
2981 s
->_raw_size
= size
;
2982 s
->contents
= rtproc
;
2984 /* Skip this section later on (I don't think this currently
2985 matters, but someday it might). */
2986 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
3015 /* A comparison routine used to sort .gptab entries. */
3018 gptab_compare (p1
, p2
)
3022 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
3023 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
3025 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
3028 /* We need to use a special link routine to handle the .reginfo and
3029 the .mdebug sections. We need to merge all instances of these
3030 sections together, not write them all out sequentially. */
3033 mips_elf_final_link (abfd
, info
)
3035 struct bfd_link_info
*info
;
3039 struct bfd_link_order
*p
;
3040 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
3041 asection
*rtproc_sec
;
3042 Elf32_RegInfo reginfo
;
3043 struct ecoff_debug_info debug
;
3044 const struct ecoff_debug_swap
*swap
3045 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3046 HDRR
*symhdr
= &debug
.symbolic_header
;
3047 PTR mdebug_handle
= NULL
;
3049 /* Drop the .options section, since it has special semantics which I
3050 haven't bothered to figure out. */
3051 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
3053 if (strcmp ((*secpp
)->name
, ".options") == 0)
3055 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
3056 if (p
->type
== bfd_indirect_link_order
)
3057 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
3058 (*secpp
)->link_order_head
= NULL
;
3059 *secpp
= (*secpp
)->next
;
3060 --abfd
->section_count
;
3065 /* Get a value for the GP register. */
3066 if (elf_gp (abfd
) == 0)
3068 struct bfd_link_hash_entry
*h
;
3070 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
3071 if (h
!= (struct bfd_link_hash_entry
*) NULL
3072 && h
->type
== bfd_link_hash_defined
)
3073 elf_gp (abfd
) = (h
->u
.def
.value
3074 + h
->u
.def
.section
->output_section
->vma
3075 + h
->u
.def
.section
->output_offset
);
3076 else if (info
->relocateable
)
3080 /* Make up a value. */
3082 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3085 && (strcmp (o
->name
, ".sbss") == 0
3086 || strcmp (o
->name
, ".sdata") == 0
3087 || strcmp (o
->name
, ".lit4") == 0
3088 || strcmp (o
->name
, ".lit8") == 0))
3091 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
3095 /* If the relocate_section function needs to do a reloc
3096 involving the GP value, it should make a reloc_dangerous
3097 callback to warn that GP is not defined. */
3101 /* Go through the sections and collect the .reginfo and .mdebug
3105 gptab_data_sec
= NULL
;
3106 gptab_bss_sec
= NULL
;
3107 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3109 if (strcmp (o
->name
, ".reginfo") == 0)
3111 memset (®info
, 0, sizeof reginfo
);
3113 /* We have found the .reginfo section in the output file.
3114 Look through all the link_orders comprising it and merge
3115 the information together. */
3116 for (p
= o
->link_order_head
;
3117 p
!= (struct bfd_link_order
*) NULL
;
3120 asection
*input_section
;
3122 Elf32_External_RegInfo ext
;
3125 if (p
->type
!= bfd_indirect_link_order
)
3127 if (p
->type
== bfd_fill_link_order
)
3132 input_section
= p
->u
.indirect
.section
;
3133 input_bfd
= input_section
->owner
;
3135 /* The linker emulation code has probably clobbered the
3136 size to be zero bytes. */
3137 if (input_section
->_raw_size
== 0)
3138 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3140 if (! bfd_get_section_contents (input_bfd
, input_section
,
3146 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
3148 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
3149 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
3150 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
3151 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
3152 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
3154 /* ri_gp_value is set by the function
3155 mips_elf_section_processing when the section is
3156 finally written out. */
3158 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3159 elf_link_input_bfd ignores this section. */
3160 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3163 /* Force the section size to the value we want. */
3164 o
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3166 /* Skip this section later on (I don't think this currently
3167 matters, but someday it might). */
3168 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3173 if (strcmp (o
->name
, ".mdebug") == 0)
3175 struct extsym_info einfo
;
3177 /* We have found the .mdebug section in the output file.
3178 Look through all the link_orders comprising it and merge
3179 the information together. */
3180 symhdr
->magic
= swap
->sym_magic
;
3181 /* FIXME: What should the version stamp be? */
3183 symhdr
->ilineMax
= 0;
3187 symhdr
->isymMax
= 0;
3188 symhdr
->ioptMax
= 0;
3189 symhdr
->iauxMax
= 0;
3191 symhdr
->issExtMax
= 0;
3194 symhdr
->iextMax
= 0;
3196 /* We accumulate the debugging information itself in the
3197 debug_info structure. */
3199 debug
.external_dnr
= NULL
;
3200 debug
.external_pdr
= NULL
;
3201 debug
.external_sym
= NULL
;
3202 debug
.external_opt
= NULL
;
3203 debug
.external_aux
= NULL
;
3205 debug
.ssext
= debug
.ssext_end
= NULL
;
3206 debug
.external_fdr
= NULL
;
3207 debug
.external_rfd
= NULL
;
3208 debug
.external_ext
= debug
.external_ext_end
= NULL
;
3210 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
3211 if (mdebug_handle
== (PTR
) NULL
)
3214 if (SGI_COMPAT (abfd
))
3220 static const char * const name
[] =
3221 { ".text", ".init", ".fini", ".data",
3222 ".rodata", ".sdata", ".sbss", ".bss" };
3223 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
3224 scRData
, scSData
, scSBss
, scBss
};
3227 esym
.cobol_main
= 0;
3231 esym
.asym
.iss
= issNil
;
3232 esym
.asym
.st
= stLocal
;
3233 esym
.asym
.reserved
= 0;
3234 esym
.asym
.index
= indexNil
;
3235 for (i
= 0; i
< 8; i
++)
3237 esym
.asym
.sc
= sc
[i
];
3238 s
= bfd_get_section_by_name (abfd
, name
[i
]);
3241 esym
.asym
.value
= s
->vma
;
3242 last
= s
->vma
+ s
->_raw_size
;
3245 esym
.asym
.value
= last
;
3247 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
3253 for (p
= o
->link_order_head
;
3254 p
!= (struct bfd_link_order
*) NULL
;
3257 asection
*input_section
;
3259 const struct ecoff_debug_swap
*input_swap
;
3260 struct ecoff_debug_info input_debug
;
3264 if (p
->type
!= bfd_indirect_link_order
)
3266 if (p
->type
== bfd_fill_link_order
)
3271 input_section
= p
->u
.indirect
.section
;
3272 input_bfd
= input_section
->owner
;
3274 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
3275 || (get_elf_backend_data (input_bfd
)
3276 ->elf_backend_ecoff_debug_swap
) == NULL
)
3278 /* I don't know what a non MIPS ELF bfd would be
3279 doing with a .mdebug section, but I don't really
3280 want to deal with it. */
3284 input_swap
= (get_elf_backend_data (input_bfd
)
3285 ->elf_backend_ecoff_debug_swap
);
3287 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
3289 /* The ECOFF linking code expects that we have already
3290 read in the debugging information and set up an
3291 ecoff_debug_info structure, so we do that now. */
3292 if (! mips_elf_read_ecoff_info (input_bfd
, input_section
,
3296 if (! (bfd_ecoff_debug_accumulate
3297 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
3298 &input_debug
, input_swap
, info
)))
3301 /* Loop through the external symbols. For each one with
3302 interesting information, try to find the symbol in
3303 the linker global hash table and save the information
3304 for the output external symbols. */
3305 eraw_src
= input_debug
.external_ext
;
3306 eraw_end
= (eraw_src
3307 + (input_debug
.symbolic_header
.iextMax
3308 * input_swap
->external_ext_size
));
3310 eraw_src
< eraw_end
;
3311 eraw_src
+= input_swap
->external_ext_size
)
3315 struct mips_elf_link_hash_entry
*h
;
3317 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
3318 if (ext
.asym
.sc
== scNil
3319 || ext
.asym
.sc
== scUndefined
3320 || ext
.asym
.sc
== scSUndefined
)
3323 name
= input_debug
.ssext
+ ext
.asym
.iss
;
3324 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
3325 name
, false, false, true);
3326 if (h
== NULL
|| h
->esym
.ifd
!= -2)
3332 < input_debug
.symbolic_header
.ifdMax
);
3333 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
3339 /* Free up the information we just read. */
3340 free (input_debug
.line
);
3341 free (input_debug
.external_dnr
);
3342 free (input_debug
.external_pdr
);
3343 free (input_debug
.external_sym
);
3344 free (input_debug
.external_opt
);
3345 free (input_debug
.external_aux
);
3346 free (input_debug
.ss
);
3347 free (input_debug
.ssext
);
3348 free (input_debug
.external_fdr
);
3349 free (input_debug
.external_rfd
);
3350 free (input_debug
.external_ext
);
3352 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3353 elf_link_input_bfd ignores this section. */
3354 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3357 if (SGI_COMPAT (abfd
) && info
->shared
)
3359 /* Create .rtproc section. */
3360 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
3361 if (rtproc_sec
== NULL
)
3363 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3366 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
3367 if (rtproc_sec
== NULL
3368 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
3369 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 12))
3373 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
3374 info
, rtproc_sec
, &debug
))
3378 /* Build the external symbol information. */
3381 einfo
.debug
= &debug
;
3383 einfo
.failed
= false;
3384 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
3385 mips_elf_output_extsym
,
3390 /* Set the size of the .mdebug section. */
3391 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
3393 /* Skip this section later on (I don't think this currently
3394 matters, but someday it might). */
3395 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3400 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
3402 const char *subname
;
3405 Elf32_External_gptab
*ext_tab
;
3408 /* The .gptab.sdata and .gptab.sbss sections hold
3409 information describing how the small data area would
3410 change depending upon the -G switch. These sections
3411 not used in executables files. */
3412 if (! info
->relocateable
)
3416 for (p
= o
->link_order_head
;
3417 p
!= (struct bfd_link_order
*) NULL
;
3420 asection
*input_section
;
3422 if (p
->type
!= bfd_indirect_link_order
)
3424 if (p
->type
== bfd_fill_link_order
)
3429 input_section
= p
->u
.indirect
.section
;
3431 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3432 elf_link_input_bfd ignores this section. */
3433 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3436 /* Skip this section later on (I don't think this
3437 currently matters, but someday it might). */
3438 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3440 /* Really remove the section. */
3441 for (secpp
= &abfd
->sections
;
3443 secpp
= &(*secpp
)->next
)
3445 *secpp
= (*secpp
)->next
;
3446 --abfd
->section_count
;
3451 /* There is one gptab for initialized data, and one for
3452 uninitialized data. */
3453 if (strcmp (o
->name
, ".gptab.sdata") == 0)
3455 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
3459 (*_bfd_error_handler
)
3460 ("%s: illegal section name `%s'",
3461 bfd_get_filename (abfd
), o
->name
);
3462 bfd_set_error (bfd_error_nonrepresentable_section
);
3466 /* The linker script always combines .gptab.data and
3467 .gptab.sdata into .gptab.sdata, and likewise for
3468 .gptab.bss and .gptab.sbss. It is possible that there is
3469 no .sdata or .sbss section in the output file, in which
3470 case we must change the name of the output section. */
3471 subname
= o
->name
+ sizeof ".gptab" - 1;
3472 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
3474 if (o
== gptab_data_sec
)
3475 o
->name
= ".gptab.data";
3477 o
->name
= ".gptab.bss";
3478 subname
= o
->name
+ sizeof ".gptab" - 1;
3479 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
3482 /* Set up the first entry. */
3484 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
3487 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
3488 tab
[0].gt_header
.gt_unused
= 0;
3490 /* Combine the input sections. */
3491 for (p
= o
->link_order_head
;
3492 p
!= (struct bfd_link_order
*) NULL
;
3495 asection
*input_section
;
3499 bfd_size_type gpentry
;
3501 if (p
->type
!= bfd_indirect_link_order
)
3503 if (p
->type
== bfd_fill_link_order
)
3508 input_section
= p
->u
.indirect
.section
;
3509 input_bfd
= input_section
->owner
;
3511 /* Combine the gptab entries for this input section one
3512 by one. We know that the input gptab entries are
3513 sorted by ascending -G value. */
3514 size
= bfd_section_size (input_bfd
, input_section
);
3516 for (gpentry
= sizeof (Elf32_External_gptab
);
3518 gpentry
+= sizeof (Elf32_External_gptab
))
3520 Elf32_External_gptab ext_gptab
;
3521 Elf32_gptab int_gptab
;
3527 if (! (bfd_get_section_contents
3528 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
3529 gpentry
, sizeof (Elf32_External_gptab
))))
3535 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
3537 val
= int_gptab
.gt_entry
.gt_g_value
;
3538 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
3541 for (look
= 1; look
< c
; look
++)
3543 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
3544 tab
[look
].gt_entry
.gt_bytes
+= add
;
3546 if (tab
[look
].gt_entry
.gt_g_value
== val
)
3552 Elf32_gptab
*new_tab
;
3555 /* We need a new table entry. */
3556 new_tab
= ((Elf32_gptab
*)
3557 bfd_realloc ((PTR
) tab
,
3558 (c
+ 1) * sizeof (Elf32_gptab
)));
3559 if (new_tab
== NULL
)
3565 tab
[c
].gt_entry
.gt_g_value
= val
;
3566 tab
[c
].gt_entry
.gt_bytes
= add
;
3568 /* Merge in the size for the next smallest -G
3569 value, since that will be implied by this new
3572 for (look
= 1; look
< c
; look
++)
3574 if (tab
[look
].gt_entry
.gt_g_value
< val
3576 || (tab
[look
].gt_entry
.gt_g_value
3577 > tab
[max
].gt_entry
.gt_g_value
)))
3581 tab
[c
].gt_entry
.gt_bytes
+=
3582 tab
[max
].gt_entry
.gt_bytes
;
3587 last
= int_gptab
.gt_entry
.gt_bytes
;
3590 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3591 elf_link_input_bfd ignores this section. */
3592 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3595 /* The table must be sorted by -G value. */
3597 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
3599 /* Swap out the table. */
3600 ext_tab
= ((Elf32_External_gptab
*)
3601 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
3602 if (ext_tab
== NULL
)
3608 for (i
= 0; i
< c
; i
++)
3609 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
3612 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
3613 o
->contents
= (bfd_byte
*) ext_tab
;
3615 /* Skip this section later on (I don't think this currently
3616 matters, but someday it might). */
3617 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3621 /* Invoke the regular ELF backend linker to do all the work. */
3622 if (! bfd_elf32_bfd_final_link (abfd
, info
))
3625 /* Now write out the computed sections. */
3627 if (reginfo_sec
!= (asection
*) NULL
)
3629 Elf32_External_RegInfo ext
;
3631 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
3632 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
3633 (file_ptr
) 0, sizeof ext
))
3637 if (mdebug_sec
!= (asection
*) NULL
)
3639 BFD_ASSERT (abfd
->output_has_begun
);
3640 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
3642 mdebug_sec
->filepos
))
3645 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
3648 if (gptab_data_sec
!= (asection
*) NULL
)
3650 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
3651 gptab_data_sec
->contents
,
3653 gptab_data_sec
->_raw_size
))
3657 if (gptab_bss_sec
!= (asection
*) NULL
)
3659 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
3660 gptab_bss_sec
->contents
,
3662 gptab_bss_sec
->_raw_size
))
3666 if (SGI_COMPAT (abfd
))
3668 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
3669 if (rtproc_sec
!= NULL
)
3671 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
3672 rtproc_sec
->contents
,
3674 rtproc_sec
->_raw_size
))
3682 /* Handle a MIPS ELF HI16 reloc. */
3685 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
3687 Elf_Internal_Rela
*relhi
;
3688 Elf_Internal_Rela
*rello
;
3695 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
3697 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
3700 addend
+= ((insn
& 0xffff) << 16) + addlo
;
3702 if ((addlo
& 0x8000) != 0)
3704 if ((addend
& 0x8000) != 0)
3707 bfd_put_32 (input_bfd
,
3708 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
3709 contents
+ relhi
->r_offset
);
3712 /* Handle a MIPS ELF local GOT16 reloc. */
3715 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
3720 Elf_Internal_Rela
*relhi
;
3721 Elf_Internal_Rela
*rello
;
3731 bfd_byte
*got_contents
;
3732 struct mips_got_info
*g
;
3734 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
3736 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
3739 addend
+= ((insn
& 0xffff) << 16) + addlo
;
3741 if ((addlo
& 0x8000) != 0)
3743 if ((addend
& 0x8000) != 0)
3746 /* Get a got entry representing requested hipage. */
3747 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
3748 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
3749 BFD_ASSERT (g
!= NULL
);
3751 local_gotno
= g
->local_gotno
;
3752 got_contents
= sgot
->contents
;
3753 hipage
= addend
& 0xffff0000;
3755 for (i
= MIPS_RESERVED_GOTNO
; i
< local_gotno
; i
++)
3757 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
3758 if (hipage
== (address
& 0xffff0000))
3760 if (address
== (bfd_vma
) 0)
3762 bfd_put_32 (input_bfd
, hipage
, got_contents
+ i
* 4);
3767 BFD_ASSERT (i
< local_gotno
);
3769 if (i
== local_gotno
)
3770 (*_bfd_error_handler
)
3771 ("ELF MIPS linker: more got entries are needed for hipage: %x",
3775 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
3776 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
3777 contents
+ relhi
->r_offset
);
3780 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
3783 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
3785 Elf_Internal_Rela
*rel
;
3791 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3792 bfd_put_32 (input_bfd
,
3793 (insn
& 0xffff0000) | (offset
& 0xffff),
3794 contents
+ rel
->r_offset
);
3797 /* Relocate a MIPS ELF section. */
3800 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3801 contents
, relocs
, local_syms
, local_sections
)
3803 struct bfd_link_info
*info
;
3805 asection
*input_section
;
3807 Elf_Internal_Rela
*relocs
;
3808 Elf_Internal_Sym
*local_syms
;
3809 asection
**local_sections
;
3811 Elf_Internal_Shdr
*symtab_hdr
;
3814 asection
*sgot
, *sreloc
, *scpt
;
3817 Elf_Internal_Rela
*rel
;
3818 Elf_Internal_Rela
*relend
;
3819 struct mips_got_info
*g
;
3821 dynobj
= elf_hash_table (info
)->dynobj
;
3822 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3826 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
3829 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
3832 if (elf_bad_symtab (input_bfd
))
3834 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
3839 locsymcount
= symtab_hdr
->sh_info
;
3840 extsymoff
= symtab_hdr
->sh_info
;
3843 gp
= _bfd_get_gp_value (output_bfd
);
3846 relend
= relocs
+ input_section
->reloc_count
;
3847 for (; rel
< relend
; rel
++)
3850 reloc_howto_type
*howto
;
3851 unsigned long r_symndx
;
3853 struct elf_link_hash_entry
*h
;
3855 Elf_Internal_Sym
*sym
;
3856 bfd_reloc_status_type r
;
3858 r_type
= ELF32_R_TYPE (rel
->r_info
);
3859 if (r_type
< 0 || r_type
>= (int) R_MIPS_max
)
3861 bfd_set_error (bfd_error_bad_value
);
3864 howto
= elf_mips_howto_table
+ r_type
;
3867 && (r_type
== R_MIPS_CALL16
3868 || r_type
== R_MIPS_GOT16
3869 || r_type
== R_MIPS_CALL_HI16
3870 || r_type
== R_MIPS_CALL_LO16
3871 || r_type
== R_MIPS_GOT_HI16
3872 || r_type
== R_MIPS_GOT_LO16
))
3874 /* We need the .got section. */
3877 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3878 BFD_ASSERT (sgot
!= NULL
);
3879 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
3880 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
3881 BFD_ASSERT (g
!= NULL
);
3885 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3887 /* Mix in the change in GP address for a GP relative reloc. */
3888 if (r_type
!= R_MIPS_GPREL16
3889 && r_type
!= R_MIPS_LITERAL
3890 && r_type
!= R_MIPS_GPREL32
)
3896 if (! ((*info
->callbacks
->reloc_dangerous
)
3898 "GP relative relocation when GP not defined",
3899 input_bfd
, input_section
,
3902 /* Only give the error once per link. */
3904 _bfd_set_gp_value (output_bfd
, gp
);
3907 if (r_symndx
< extsymoff
3908 || (elf_bad_symtab (input_bfd
)
3909 && local_sections
[r_symndx
] != NULL
))
3911 /* This is a relocation against a section. The current
3912 addend in the instruction is the difference between
3913 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
3914 must change this to be the difference between the
3915 final definition (which will end up in RELOCATION)
3916 and the GP value of OUTPUT_BFD (which is in GP). */
3917 addend
= elf_gp (input_bfd
) - gp
;
3919 else if (! info
->relocateable
)
3921 /* We are doing a final link. The current addend in the
3922 instruction is simply the desired offset into the
3923 symbol (normally zero). We want the instruction to
3924 hold the difference between the final definition of
3925 the symbol (which will end up in RELOCATION) and the
3926 GP value of OUTPUT_BFD (which is in GP). */
3931 /* We are generating relocateable output, and we aren't
3932 going to define this symbol, so we just leave the
3933 instruction alone. */
3941 if (info
->relocateable
)
3943 /* This is a relocateable link. We don't have to change
3944 anything, unless the reloc is against a section symbol,
3945 in which case we have to adjust according to where the
3946 section symbol winds up in the output section. */
3947 if (r_symndx
>= locsymcount
3948 || (elf_bad_symtab (input_bfd
)
3949 && local_sections
[r_symndx
] == NULL
))
3953 sym
= local_syms
+ r_symndx
;
3954 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
3958 sec
= local_sections
[r_symndx
];
3960 /* It would be logical to add sym->st_value here,
3961 but Irix 5 sometimes generates a garbage symbol
3963 addend
+= sec
->output_offset
;
3965 /* If this is HI16 or GOT16 with an associated LO16,
3966 adjust the addend accordingly. Otherwise, just
3968 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
3969 r
= _bfd_relocate_contents (howto
, input_bfd
,
3971 contents
+ rel
->r_offset
);
3974 Elf_Internal_Rela
*lorel
;
3976 /* As a GNU extension, permit an arbitrary
3977 number of R_MIPS_HI16 relocs before the
3978 R_MIPS_LO16 reloc. This permits gcc to emit
3979 the HI and LO relocs itself. */
3980 if (r_type
== R_MIPS_GOT16
)
3984 for (lorel
= rel
+ 1;
3986 && (ELF32_R_TYPE (lorel
->r_info
)
3992 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
3994 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
3999 r
= _bfd_relocate_contents (howto
, input_bfd
,
4001 contents
+ rel
->r_offset
);
4011 /* This is a final link. */
4013 if (r_symndx
< extsymoff
4014 || (elf_bad_symtab (input_bfd
)
4015 && local_sections
[r_symndx
] != NULL
))
4018 sym
= local_syms
+ r_symndx
;
4019 sec
= local_sections
[r_symndx
];
4020 relocation
= (sec
->output_section
->vma
4021 + sec
->output_offset
);
4023 /* It would be logical to always add sym->st_value here,
4024 but Irix 5 sometimes generates a garbage symbol
4026 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4027 relocation
+= sym
->st_value
;
4034 indx
= r_symndx
- extsymoff
;
4035 h
= elf_sym_hashes (input_bfd
)[indx
];
4036 while (h
->root
.type
== bfd_link_hash_indirect
4037 || h
->root
.type
== bfd_link_hash_warning
)
4038 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4039 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
4043 if (! ((*info
->callbacks
->reloc_dangerous
)
4045 "_gp_disp used when GP not defined",
4046 input_bfd
, input_section
,
4049 /* Only give the error once per link. */
4051 _bfd_set_gp_value (output_bfd
, gp
);
4056 sec
= input_section
;
4057 if (sec
->output_section
!= NULL
)
4060 + sec
->output_section
->vma
4061 + sec
->output_offset
));
4063 relocation
= gp
- rel
->r_offset
;
4064 if (r_type
== R_MIPS_LO16
)
4068 else if (h
->root
.type
== bfd_link_hash_defined
4069 || h
->root
.type
== bfd_link_hash_defweak
)
4071 sec
= h
->root
.u
.def
.section
;
4072 if (sec
->output_section
== NULL
)
4075 relocation
= (h
->root
.u
.def
.value
4076 + sec
->output_section
->vma
4077 + sec
->output_offset
);
4079 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4081 else if (info
->shared
&& ! info
->symbolic
)
4083 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
4085 /* If this is a dynamic link, we should have created
4086 a _DYNAMIC_LINK symbol in
4087 mips_elf_create_dynamic_sections. Otherwise, we
4088 should define the symbol with a value of 0.
4089 FIXME: It should probably get into the symbol
4090 table somehow as well. */
4091 BFD_ASSERT (! info
->shared
);
4092 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
4093 ".dynamic") == NULL
);
4098 if (! ((*info
->callbacks
->undefined_symbol
)
4099 (info
, h
->root
.root
.string
, input_bfd
,
4100 input_section
, rel
->r_offset
)))
4106 if (r_type
== R_MIPS_HI16
)
4108 Elf_Internal_Rela
*lorel
;
4110 /* As a GNU extension, permit an arbitrary number of
4111 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
4112 This permits gcc to emit the HI and LO relocs itself. */
4113 for (lorel
= rel
+ 1;
4115 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
4119 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
4121 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
4122 contents
, relocation
+ addend
);
4126 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4127 contents
, rel
->r_offset
,
4128 relocation
, addend
);
4130 else if (r_type
== R_MIPS_GOT16
&& local
)
4132 /* GOT16 must also have an associated LO16 in the local
4133 case. In this case, the addend is extracted and the
4134 section in which the referenced object is determined.
4135 Then the final address of the object is computed and
4136 the GOT entry for the hipage (an aligned 64kb chunk)
4137 is added to .got section if needed. The offset field
4138 of the GOT16-relocated instruction is replaced by the
4139 index of this GOT entry for the hipage. */
4140 if ((rel
+ 1) < relend
4141 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
4143 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
,
4146 relocation
+ addend
);
4150 r
= bfd_reloc_outofrange
;
4152 else if (r_type
== R_MIPS_CALL16
4153 || r_type
== R_MIPS_GOT16
4154 || r_type
== R_MIPS_CALL_LO16
4155 || r_type
== R_MIPS_GOT_LO16
)
4159 /* This symbol must be registered as a global symbol
4160 having the corresponding got entry. */
4161 BFD_ASSERT (h
->got_offset
!= (bfd_vma
) -1);
4163 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
4164 BFD_ASSERT (g
->local_gotno
<= offset
4165 && offset
< sgot
->_raw_size
);
4166 bfd_put_32 (output_bfd
, relocation
+ addend
,
4167 sgot
->contents
+ offset
);
4168 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
4170 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
4174 else if (r_type
== R_MIPS_CALL_HI16
4175 || r_type
== R_MIPS_GOT_HI16
)
4179 /* This must be a global symbol with a got entry. The
4180 next reloc must be the corresponding LO16 reloc. */
4181 BFD_ASSERT (h
!= NULL
&& h
->got_offset
!= (bfd_vma
) -1);
4182 BFD_ASSERT ((rel
+ 1) < relend
);
4183 BFD_ASSERT (ELF32_R_TYPE ((rel
+ 1)->r_info
)
4184 == (r_type
== R_MIPS_CALL_HI16
4186 : R_MIPS_GOT_LO16
));
4188 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
4189 BFD_ASSERT (g
->local_gotno
<= offset
4190 && offset
< sgot
->_raw_size
);
4191 bfd_put_32 (output_bfd
, relocation
+ addend
,
4192 sgot
->contents
+ offset
);
4193 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
4195 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
4199 else if (r_type
== R_MIPS_REL32
4200 || r_type
== R_MIPS_32
)
4202 Elf_Internal_Rel outrel
;
4203 Elf32_crinfo cptrel
;
4208 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
4210 && (input_section
->flags
& SEC_ALLOC
) != 0)
4212 /* When generating a shared object, these
4213 relocations are copied into the output file to be
4214 resolved at run time. */
4217 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
4218 BFD_ASSERT (sreloc
!= NULL
);
4221 outrel
.r_offset
= (rel
->r_offset
4222 + input_section
->output_section
->vma
4223 + input_section
->output_offset
);
4225 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4228 && (! info
->symbolic
4229 || (h
->elf_link_hash_flags
4230 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4232 BFD_ASSERT (h
->dynindx
!= -1);
4233 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
4234 sec
= input_section
;
4241 sec
= local_sections
[r_symndx
];
4244 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
4246 == bfd_link_hash_defweak
));
4247 sec
= h
->root
.u
.def
.section
;
4249 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
4251 else if (sec
== NULL
|| sec
->owner
== NULL
)
4253 bfd_set_error (bfd_error_bad_value
);
4260 osec
= sec
->output_section
;
4261 indx
= elf_section_data (osec
)->dynindx
;
4266 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
4267 addend
+= relocation
;
4270 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
4271 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
4272 (((Elf32_External_Rel
*)
4274 + sreloc
->reloc_count
));
4275 ++sreloc
->reloc_count
;
4277 if (SGI_COMPAT (output_bfd
))
4282 /* Make an entry of compact relocation info. */
4283 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
4284 cptrel
.vaddr
= (rel
->r_offset
4285 + input_section
->output_section
->vma
4286 + input_section
->output_offset
);
4287 if (r_type
== R_MIPS_REL32
)
4288 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
4290 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
4291 mips_elf_set_cr_dist2to (cptrel
, 0);
4292 cptrel
.konst
= addend
;
4294 cr
= (scpt
->contents
4295 + sizeof (Elf32_External_compact_rel
));
4296 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4297 ((Elf32_External_crinfo
*) cr
4298 + scpt
->reloc_count
));
4299 ++scpt
->reloc_count
;
4302 /* This reloc will be computed at runtime, so
4303 there's no need to do anything now. */
4307 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4308 contents
, rel
->r_offset
,
4309 relocation
, addend
);
4312 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4313 contents
, rel
->r_offset
,
4314 relocation
, addend
);
4316 if (SGI_COMPAT (abfd
)
4318 && (input_section
->flags
& SEC_ALLOC
) != 0)
4320 Elf32_crinfo cptrel
;
4323 /* Make an entry of compact relocation info. */
4324 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
4325 cptrel
.vaddr
= (rel
->r_offset
4326 + input_section
->output_section
->vma
4327 + input_section
->output_offset
);
4332 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
4333 /* XXX How should we set dist2to in this case. */
4334 mips_elf_set_cr_dist2to (cptrel
, 8);
4335 cptrel
.konst
= addend
+ relocation
;
4336 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
4337 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4338 ((Elf32_External_crinfo
*) cr
4339 + scpt
->reloc_count
));
4340 ++scpt
->reloc_count
;
4343 case R_MIPS_GPREL16
:
4344 case R_MIPS_LITERAL
:
4345 case R_MIPS_GPREL32
:
4346 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
4347 cptrel
.konst
= gp
- cptrel
.vaddr
;
4348 mips_elf_set_cr_dist2to (cptrel
, 4);
4349 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
4350 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4351 ((Elf32_External_crinfo
*) cr
4352 + scpt
->reloc_count
));
4353 ++scpt
->reloc_count
;
4362 if (r
!= bfd_reloc_ok
)
4367 case bfd_reloc_outofrange
:
4369 case bfd_reloc_overflow
:
4374 name
= h
->root
.root
.string
;
4377 name
= bfd_elf_string_from_elf_section (input_bfd
,
4378 symtab_hdr
->sh_link
,
4383 name
= bfd_section_name (input_bfd
, sec
);
4385 if (! ((*info
->callbacks
->reloc_overflow
)
4386 (info
, name
, howto
->name
, (bfd_vma
) 0,
4387 input_bfd
, input_section
, rel
->r_offset
)))
4398 /* Functions for the dynamic linker. */
4400 /* The name of the dynamic interpreter. This is put in the .interp
4403 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
4405 /* Create dynamic sections when linking against a dynamic object. */
4408 mips_elf_create_dynamic_sections (abfd
, info
)
4410 struct bfd_link_info
*info
;
4412 struct elf_link_hash_entry
*h
;
4414 register asection
*s
;
4415 const char * const *namep
;
4417 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4420 /* Mips ABI requests the .dynamic section to be read only. */
4421 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4424 if (! bfd_set_section_flags (abfd
, s
, flags
))
4428 /* We need to create .got section. */
4429 if (! mips_elf_create_got_section (abfd
, info
))
4432 /* Create .stub section. */
4433 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
4435 s
= bfd_make_section (abfd
, ".stub");
4437 || ! bfd_set_section_flags (abfd
, s
, flags
)
4438 || ! bfd_set_section_alignment (abfd
, s
, 2))
4442 if (SGI_COMPAT (abfd
))
4444 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
4447 if (! (_bfd_generic_link_add_one_symbol
4448 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
4449 (bfd_vma
) 0, (const char *) NULL
, false,
4450 get_elf_backend_data (abfd
)->collect
,
4451 (struct bfd_link_hash_entry
**) &h
)))
4453 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
4454 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4455 h
->type
= STT_SECTION
;
4457 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4461 /* We need to create a .compact_rel section. */
4462 if (! mips_elf_create_compact_rel_section (abfd
, info
))
4465 /* Change aligments of some sections. */
4466 s
= bfd_get_section_by_name (abfd
, ".hash");
4468 bfd_set_section_alignment (abfd
, s
, 4);
4469 s
= bfd_get_section_by_name (abfd
, ".dynsym");
4471 bfd_set_section_alignment (abfd
, s
, 4);
4472 s
= bfd_get_section_by_name (abfd
, ".dynstr");
4474 bfd_set_section_alignment (abfd
, s
, 4);
4475 s
= bfd_get_section_by_name (abfd
, ".reginfo");
4477 bfd_set_section_alignment (abfd
, s
, 4);
4478 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4480 bfd_set_section_alignment (abfd
, s
, 4);
4486 if (! (_bfd_generic_link_add_one_symbol
4487 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
4488 (bfd_vma
) 0, (const char *) NULL
, false,
4489 get_elf_backend_data (abfd
)->collect
,
4490 (struct bfd_link_hash_entry
**) &h
)))
4492 h
->elf_link_hash_flags
^=~ ELF_LINK_NON_ELF
;
4493 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4494 h
->type
= STT_SECTION
;
4496 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4503 /* Create the .compact_rel section. */
4506 mips_elf_create_compact_rel_section (abfd
, info
)
4508 struct bfd_link_info
*info
;
4511 register asection
*s
;
4513 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
4515 flags
= SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_READONLY
;
4517 s
= bfd_make_section (abfd
, ".compact_rel");
4519 || ! bfd_set_section_flags (abfd
, s
, flags
)
4520 || ! bfd_set_section_alignment (abfd
, s
, 2))
4523 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
4529 /* Create the .got section to hold the global offset table. */
4532 mips_elf_create_got_section (abfd
, info
)
4534 struct bfd_link_info
*info
;
4537 register asection
*s
;
4538 struct elf_link_hash_entry
*h
;
4539 struct mips_got_info
*g
;
4541 /* This function may be called more than once. */
4542 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
4545 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
4547 s
= bfd_make_section (abfd
, ".got");
4549 || ! bfd_set_section_flags (abfd
, s
, flags
)
4550 || ! bfd_set_section_alignment (abfd
, s
, 4))
4553 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
4554 linker script because we don't want to define the symbol if we
4555 are not creating a global offset table. */
4557 if (! (_bfd_generic_link_add_one_symbol
4558 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
4559 (bfd_vma
) 0, (const char *) NULL
, false,
4560 get_elf_backend_data (abfd
)->collect
,
4561 (struct bfd_link_hash_entry
**) &h
)))
4563 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
4564 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4565 h
->type
= STT_OBJECT
;
4568 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4571 /* The first several global offset table entries are reserved. */
4572 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
4574 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
4575 sizeof (struct mips_got_info
));
4578 g
->global_gotsym
= 0;
4579 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
4580 if (elf_section_data (s
) == NULL
)
4583 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
4584 if (elf_section_data (s
) == NULL
)
4587 elf_section_data (s
)->tdata
= (PTR
) g
;
4592 /* Look through the relocs for a section during the first phase, and
4593 allocate space in the global offset table. */
4596 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
4598 struct bfd_link_info
*info
;
4600 const Elf_Internal_Rela
*relocs
;
4603 Elf_Internal_Shdr
*symtab_hdr
;
4604 struct elf_link_hash_entry
**sym_hashes
;
4605 struct mips_got_info
*g
;
4607 const Elf_Internal_Rela
*rel
;
4608 const Elf_Internal_Rela
*rel_end
;
4612 if (info
->relocateable
)
4615 dynobj
= elf_hash_table (info
)->dynobj
;
4616 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4617 sym_hashes
= elf_sym_hashes (abfd
);
4618 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
4623 rel_end
= relocs
+ sec
->reloc_count
;
4624 for (rel
= relocs
; rel
< rel_end
; rel
++)
4626 unsigned long r_symndx
;
4627 struct elf_link_hash_entry
*h
;
4629 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4631 if (r_symndx
< extsymoff
)
4634 h
= sym_hashes
[r_symndx
- extsymoff
];
4636 /* Some relocs require a global offset table. */
4639 switch (ELF32_R_TYPE (rel
->r_info
))
4643 case R_MIPS_CALL_HI16
:
4644 case R_MIPS_CALL_LO16
:
4645 case R_MIPS_GOT_HI16
:
4646 case R_MIPS_GOT_LO16
:
4647 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
4648 if (! mips_elf_create_got_section (dynobj
, info
))
4657 switch (ELF32_R_TYPE (rel
->r_info
))
4660 case R_MIPS_CALL_HI16
:
4661 case R_MIPS_CALL_LO16
:
4662 /* This symbol requires a global offset table entry. */
4665 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4666 BFD_ASSERT (sgot
!= NULL
);
4667 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4668 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4669 BFD_ASSERT (g
!= NULL
);
4672 BFD_ASSERT (h
!= NULL
);
4674 /* Make sure this symbol is output as a dynamic symbol. */
4675 if (h
->dynindx
== -1)
4677 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4681 if (h
->got_offset
!= (bfd_vma
) -1)
4683 /* We have already allocated space in the .got. */
4687 /* Note the index of the first global got symbol in .dynsym. */
4688 if (g
->global_gotsym
== 0
4689 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
4690 g
->global_gotsym
= h
->dynindx
;
4692 /* Make this symbol to have the corresponding got entry. */
4695 /* We need a stub, not a plt entry for the undefined
4696 function. But we record it as if it needs plt. See
4697 elf_adjust_dynamic_symbol in elflink.h. */
4698 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
4704 case R_MIPS_GOT_HI16
:
4705 case R_MIPS_GOT_LO16
:
4706 /* This symbol requires a global offset table entry. */
4709 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4710 BFD_ASSERT (sgot
!= NULL
);
4711 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4712 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4713 BFD_ASSERT (g
!= NULL
);
4718 /* Make sure this symbol is output as a dynamic symbol. */
4719 if (h
->dynindx
== -1)
4721 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4725 if (h
->got_offset
!= (bfd_vma
) -1)
4727 /* We have already allocated space in the .got. */
4730 /* Note the index of the first global got symbol in
4732 if (g
->global_gotsym
== 0
4733 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
4734 g
->global_gotsym
= h
->dynindx
;
4736 /* Make this symbol to be the global got symbol. */
4744 if ((info
->shared
|| h
!= NULL
)
4745 && (sec
->flags
& SEC_ALLOC
) != 0)
4747 /* When creating a shared object, we must copy these
4748 reloc types into the output file as R_MIPS_REL32
4749 relocs. We create the .rel.dyn reloc section in
4750 dynobj and make room for this reloc. */
4753 const char *name
= ".rel.dyn";
4755 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4758 sreloc
= bfd_make_section (dynobj
, name
);
4760 || ! bfd_set_section_flags (dynobj
, sreloc
,
4766 || ! bfd_set_section_alignment (dynobj
, sreloc
, 4))
4769 /* Add a null element. */
4770 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
4771 ++sreloc
->reloc_count
;
4776 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
4779 struct mips_elf_link_hash_entry
*hmips
;
4781 /* We only need to copy this reloc if the symbol is
4782 defined in a dynamic object. */
4783 hmips
= (struct mips_elf_link_hash_entry
*) h
;
4784 ++hmips
->mips_32_relocs
;
4788 if (SGI_COMPAT (abfd
))
4789 mips_elf_hash_table (info
)->compact_rel_size
+=
4790 sizeof (Elf32_External_crinfo
);
4795 case R_MIPS_GPREL16
:
4796 case R_MIPS_LITERAL
:
4797 case R_MIPS_GPREL32
:
4798 if (SGI_COMPAT (abfd
))
4799 mips_elf_hash_table (info
)->compact_rel_size
+=
4800 sizeof (Elf32_External_crinfo
);
4811 /* Adjust a symbol defined by a dynamic object and referenced by a
4812 regular object. The current definition is in some section of the
4813 dynamic object, but we're not including those sections. We have to
4814 change the definition to something the rest of the link can
4818 mips_elf_adjust_dynamic_symbol (info
, h
)
4819 struct bfd_link_info
*info
;
4820 struct elf_link_hash_entry
*h
;
4823 struct mips_elf_link_hash_entry
*hmips
;
4826 dynobj
= elf_hash_table (info
)->dynobj
;
4828 /* Make sure we know what is going on here. */
4829 BFD_ASSERT (dynobj
!= NULL
4830 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
4831 || h
->weakdef
!= NULL
4832 || ((h
->elf_link_hash_flags
4833 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4834 && (h
->elf_link_hash_flags
4835 & ELF_LINK_HASH_REF_REGULAR
) != 0
4836 && (h
->elf_link_hash_flags
4837 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
4839 /* If this symbol is defined in a dynamic object, we need to copy
4840 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
4842 hmips
= (struct mips_elf_link_hash_entry
*) h
;
4843 if (! info
->relocateable
4844 && hmips
->mips_32_relocs
!= 0
4845 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4847 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
4848 BFD_ASSERT (s
!= NULL
);
4850 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
4853 /* For a function, create a stub, if needed. */
4854 if (h
->type
== STT_FUNC
4855 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4857 if (! elf_hash_table (info
)->dynamic_sections_created
)
4860 /* If this symbol is not defined in a regular file, then set
4861 the symbol to the stub location. This is required to make
4862 function pointers compare as equal between the normal
4863 executable and the shared library. */
4864 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4866 /* We need .stub section. */
4867 s
= bfd_get_section_by_name (dynobj
, ".stub");
4868 BFD_ASSERT (s
!= NULL
);
4870 h
->root
.u
.def
.section
= s
;
4871 h
->root
.u
.def
.value
= s
->_raw_size
;
4873 /* XXX Write this stub address somewhere. */
4874 h
->plt_offset
= s
->_raw_size
;
4876 /* Make room for this stub code. */
4877 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
4879 /* The last half word of the stub will be filled with the index
4880 of this symbol in .dynsym section. */
4885 /* If this is a weak symbol, and there is a real definition, the
4886 processor independent code will have arranged for us to see the
4887 real definition first, and we can just use the same value. */
4888 if (h
->weakdef
!= NULL
)
4890 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
4891 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
4892 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
4893 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
4897 /* This is a reference to a symbol defined by a dynamic object which
4898 is not a function. */
4903 /* Set the sizes of the dynamic sections. */
4906 mips_elf_size_dynamic_sections (output_bfd
, info
)
4908 struct bfd_link_info
*info
;
4914 struct mips_got_info
*g
;
4916 dynobj
= elf_hash_table (info
)->dynobj
;
4917 BFD_ASSERT (dynobj
!= NULL
);
4919 if (elf_hash_table (info
)->dynamic_sections_created
)
4921 /* Set the contents of the .interp section to the interpreter. */
4924 s
= bfd_get_section_by_name (dynobj
, ".interp");
4925 BFD_ASSERT (s
!= NULL
);
4926 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4927 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4931 /* Recompute the size of .got for local entires (reserved and
4932 hipages) if needed. To estimate it, get the upper bound of total
4933 size of loadable sections. */
4934 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4938 bfd_size_type loadable_size
= 0;
4939 bfd_size_type local_gotno
;
4942 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4943 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4944 BFD_ASSERT (g
!= NULL
);
4946 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
4947 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
4949 if ((s
->flags
& SEC_ALLOC
) == 0)
4951 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
4954 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
4956 /* Assume there are two loadable segments consisting of
4957 contiguous sections. Is 5 enough? */
4958 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
4959 g
->local_gotno
= local_gotno
;
4960 sgot
->_raw_size
+= local_gotno
* 4;
4963 /* The check_relocs and adjust_dynamic_symbol entry points have
4964 determined the sizes of the various dynamic sections. Allocate
4967 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4972 /* It's OK to base decisions on the section name, because none
4973 of the dynobj section names depend upon the input files. */
4974 name
= bfd_get_section_name (dynobj
, s
);
4976 if ((s
->flags
& SEC_IN_MEMORY
) == 0)
4981 if (strncmp (name
, ".rel", 4) == 0)
4983 if (s
->_raw_size
== 0)
4989 /* If this relocation section applies to a read only
4990 section, then we probably need a DT_TEXTREL entry.
4991 If the relocation section is .rel.dyn, we always
4992 assert a DT_TEXTREL entry rather than testing whether
4993 there exists a relocation to a read only section or
4995 target
= bfd_get_section_by_name (output_bfd
, name
+ 4);
4996 if ((target
!= NULL
&& (target
->flags
& SEC_READONLY
) != 0)
4997 || strcmp (name
, ".rel.dyn") == 0)
5000 /* We use the reloc_count field as a counter if we need
5001 to copy relocs into the output file. */
5002 if (strcmp (name
, ".rel.dyn") != 0)
5006 else if (strncmp (name
, ".got", 4) == 0)
5010 BFD_ASSERT (elf_section_data (s
) != NULL
);
5011 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
5012 BFD_ASSERT (g
!= NULL
);
5014 /* Fix the size of .got section for the correspondence of
5015 global symbols and got entries. This adds some useless
5016 got entries. Is this required by ABI really? */
5017 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
5018 s
->_raw_size
+= i
* 4;
5020 else if (strncmp (name
, ".stub", 5) == 0)
5022 /* Irix rld assumes that the function stub isn't at the end
5023 of .text section. So put a dummy. XXX */
5024 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
5026 else if (SGI_COMPAT (output_bfd
)
5027 && strncmp (name
, ".compact_rel", 12) == 0)
5028 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
5029 else if (strncmp (name
, ".init", 5) != 0)
5031 /* It's not one of our sections, so don't allocate space. */
5039 for (spp
= &s
->output_section
->owner
->sections
;
5040 *spp
!= s
->output_section
;
5041 spp
= &(*spp
)->next
)
5043 *spp
= s
->output_section
->next
;
5044 --s
->output_section
->owner
->section_count
;
5049 /* Allocate memory for the section contents. */
5050 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
5051 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
5053 bfd_set_error (bfd_error_no_memory
);
5056 memset (s
->contents
, 0, s
->_raw_size
);
5059 if (elf_hash_table (info
)->dynamic_sections_created
)
5061 /* Add some entries to the .dynamic section. We fill in the
5062 values later, in elf_mips_finish_dynamic_sections, but we
5063 must add the entries now so that we get the correct size for
5064 the .dynamic section. The DT_DEBUG entry is filled in by the
5065 dynamic linker and used by the debugger. */
5068 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
5074 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
5078 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
5081 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
5083 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
5086 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
5089 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
5093 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
5096 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
5099 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
5101 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
5104 s
= bfd_get_section_by_name (dynobj
, ".liblist");
5105 BFD_ASSERT (s
!= NULL
);
5107 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
5111 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
5114 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
5118 /* Time stamps in executable files are a bad idea. */
5119 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
5124 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
5129 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
5133 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
5136 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
5139 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
5142 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
5145 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
5148 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
5151 #if 0 /* (SGI_COMPAT) */
5152 if (! bfd_get_section_by_name (dynobj
, ".init"))
5153 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
5156 if (! bfd_get_section_by_name (dynobj
, ".fini"))
5157 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
5162 /* If we use dynamic linking, we generate a section symbol for each
5163 output section. These are local symbols, which means that they
5164 must come first in the dynamic symbol table.
5165 That means we must increment the dynamic symbol index of every
5166 other dynamic symbol. */
5168 const char * const *namep
;
5170 bfd_size_type strindex
;
5171 struct bfd_strtab_hash
*dynstr
;
5172 struct mips_got_info
*g
;
5174 if (elf_hash_table (info
)->dynamic_sections_created
)
5176 if (SGI_COMPAT (output_bfd
))
5178 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
5179 elf_link_hash_traverse (elf_hash_table (info
),
5180 mips_elf_adjust_dynindx
,
5182 elf_hash_table (info
)->dynsymcount
+= c
;
5184 dynstr
= elf_hash_table (info
)->dynstr
;
5185 BFD_ASSERT (dynstr
!= NULL
);
5187 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
5191 s
= bfd_get_section_by_name (output_bfd
, *namep
);
5193 elf_section_data (s
)->dynindx
= i
;
5195 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
5196 if (strindex
== (bfd_size_type
) -1)
5199 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
5204 c
= bfd_count_sections (output_bfd
);
5205 elf_link_hash_traverse (elf_hash_table (info
),
5206 mips_elf_adjust_dynindx
,
5208 elf_hash_table (info
)->dynsymcount
+= c
;
5210 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
5212 elf_section_data (s
)->dynindx
= i
;
5213 /* These symbols will have no names, so we don't need to
5214 fiddle with dynstr_index. */
5219 s
= bfd_get_section_by_name (dynobj
, ".got");
5220 BFD_ASSERT (s
!= NULL
);
5221 BFD_ASSERT (elf_section_data (s
) != NULL
);
5222 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
5223 BFD_ASSERT (g
!= NULL
);
5225 /* If there are no global got symbols, fake the last symbol so for
5227 if (g
->global_gotsym
)
5228 g
->global_gotsym
+= c
;
5230 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
5236 /* Increment the index of a dynamic symbol by a given amount. Called
5237 via elf_link_hash_traverse. */
5240 mips_elf_adjust_dynindx (h
, cparg
)
5241 struct elf_link_hash_entry
*h
;
5244 unsigned int *cp
= (unsigned int *) cparg
;
5246 if (h
->dynindx
!= -1)
5251 /* Finish up dynamic symbol handling. We set the contents of various
5252 dynamic sections here. */
5255 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
5257 struct bfd_link_info
*info
;
5258 struct elf_link_hash_entry
*h
;
5259 Elf_Internal_Sym
*sym
;
5264 struct mips_got_info
*g
;
5267 dynobj
= elf_hash_table (info
)->dynobj
;
5268 gval
= sym
->st_value
;
5270 if (h
->plt_offset
!= (bfd_vma
) -1)
5274 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
5276 /* This symbol has a stub. Set it up. */
5278 BFD_ASSERT (h
->dynindx
!= -1);
5280 s
= bfd_get_section_by_name (dynobj
, ".stub");
5281 BFD_ASSERT (s
!= NULL
);
5283 /* Fill the stub. */
5285 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
5287 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
5290 /* FIXME: Can h->dynindex be more than 64K? */
5291 if (h
->dynindx
& 0xffff0000)
5294 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
5296 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
5298 BFD_ASSERT (h
->plt_offset
<= s
->_raw_size
);
5299 memcpy (s
->contents
+ h
->plt_offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
5301 /* Mark the symbol as undefined. plt_offset != -1 occurs
5302 only for the referenced symbol. */
5303 sym
->st_shndx
= SHN_UNDEF
;
5305 /* The run-time linker uses the st_value field of the symbol
5306 to reset the global offset table entry for this external
5307 to its stub address when unlinking a shared object. */
5308 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt_offset
;
5309 sym
->st_value
= gval
;
5312 BFD_ASSERT (h
->dynindx
!= -1);
5314 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5315 BFD_ASSERT (sgot
!= NULL
);
5316 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5317 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5318 BFD_ASSERT (g
!= NULL
);
5320 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
5322 bfd_size_type offset
;
5324 /* This symbol has an entry in the global offset table. Set its
5325 value to the corresponding got entry, if needed. */
5326 if (h
->got_offset
== (bfd_vma
) -1)
5328 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5329 BFD_ASSERT (g
->local_gotno
* 4 <= offset
5330 && offset
< sgot
->_raw_size
);
5331 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
5335 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
5336 name
= h
->root
.root
.string
;
5337 if (strcmp (name
, "_DYNAMIC") == 0
5338 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
5339 sym
->st_shndx
= SHN_ABS
;
5340 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
5342 sym
->st_shndx
= SHN_ABS
;
5343 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5346 else if (SGI_COMPAT (output_bfd
))
5348 if (strcmp (name
, "_gp_disp") == 0)
5350 sym
->st_shndx
= SHN_ABS
;
5351 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5352 sym
->st_value
= elf_gp (output_bfd
);
5354 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
5355 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
5357 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5358 sym
->st_other
= STO_PROTECTED
;
5360 sym
->st_shndx
= SHN_MIPS_DATA
;
5362 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
5364 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5365 sym
->st_other
= STO_PROTECTED
;
5366 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
5367 sym
->st_shndx
= SHN_ABS
;
5369 else if (sym
->st_shndx
!= SHN_UNDEF
)
5371 if (h
->type
== STT_FUNC
)
5372 sym
->st_shndx
= SHN_MIPS_TEXT
;
5373 else if (h
->type
== STT_OBJECT
)
5374 sym
->st_shndx
= SHN_MIPS_DATA
;
5381 /* Finish up the dynamic sections. */
5384 mips_elf_finish_dynamic_sections (output_bfd
, info
)
5386 struct bfd_link_info
*info
;
5391 struct mips_got_info
*g
;
5393 dynobj
= elf_hash_table (info
)->dynobj
;
5395 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5397 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5398 BFD_ASSERT (sgot
!= NULL
);
5400 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5401 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5402 BFD_ASSERT (g
!= NULL
);
5404 if (elf_hash_table (info
)->dynamic_sections_created
)
5406 Elf32_External_Dyn
*dyncon
, *dynconend
;
5408 BFD_ASSERT (sdyn
!= NULL
);
5410 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5411 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
5412 for (; dyncon
< dynconend
; dyncon
++)
5414 Elf_Internal_Dyn dyn
;
5419 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5427 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5428 BFD_ASSERT (s
!= NULL
);
5429 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
5430 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5434 /* Rewrite DT_STRSZ. */
5436 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
5437 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5443 case DT_MIPS_CONFLICT
:
5446 case DT_MIPS_LIBLIST
:
5449 s
= bfd_get_section_by_name (output_bfd
, name
);
5450 BFD_ASSERT (s
!= NULL
);
5451 dyn
.d_un
.d_ptr
= s
->vma
;
5452 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5455 case DT_MIPS_RLD_VERSION
:
5456 dyn
.d_un
.d_val
= 1; /* XXX */
5457 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5461 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
5462 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5465 case DT_MIPS_CONFLICTNO
:
5467 elemsize
= sizeof (Elf32_Conflict
);
5470 case DT_MIPS_LIBLISTNO
:
5472 elemsize
= sizeof (Elf32_Lib
);
5474 s
= bfd_get_section_by_name (output_bfd
, name
);
5477 if (s
->_cooked_size
!= 0)
5478 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5480 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5485 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5488 case DT_MIPS_TIME_STAMP
:
5489 time ((time_t *) &dyn
.d_un
.d_val
);
5490 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5493 case DT_MIPS_ICHECKSUM
:
5497 case DT_MIPS_IVERSION
:
5501 case DT_MIPS_BASE_ADDRESS
:
5502 s
= output_bfd
->sections
;
5503 BFD_ASSERT (s
!= NULL
);
5504 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
5505 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5508 case DT_MIPS_LOCAL_GOTNO
:
5509 dyn
.d_un
.d_val
= g
->local_gotno
;
5510 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5513 case DT_MIPS_SYMTABNO
:
5515 elemsize
= sizeof (Elf32_External_Sym
);
5516 s
= bfd_get_section_by_name (output_bfd
, name
);
5517 BFD_ASSERT (s
!= NULL
);
5519 if (s
->_cooked_size
!= 0)
5520 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5522 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5523 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5526 case DT_MIPS_UNREFEXTNO
:
5528 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
5529 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5532 case DT_MIPS_GOTSYM
:
5533 dyn
.d_un
.d_val
= g
->global_gotsym
;
5534 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5537 case DT_MIPS_HIPAGENO
:
5538 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
5539 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5546 /* The first entry of the global offset table will be filled at
5547 runtime. The second entry will be used by some runtime loaders.
5548 This isn't the case of Irix rld. */
5549 if (sgot
->_raw_size
> 0)
5551 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
5552 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
5555 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
5562 Elf_Internal_Sym sym
;
5565 const char * const * namep
= mips_elf_dynsym_sec_names
;
5566 Elf32_compact_rel cpt
;
5568 /* Set up the section symbols for the output sections. SGI sets
5569 the STT_NOTYPE attribute for these symbols. Should we do so? */
5571 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
5572 if (sdynsym
!= NULL
)
5574 if (SGI_COMPAT (output_bfd
))
5578 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
5582 while ((name
= *namep
++) != NULL
)
5584 s
= bfd_get_section_by_name (output_bfd
, name
);
5587 sym
.st_value
= s
->vma
;
5588 dindx
= elf_section_data (s
)->dynindx
;
5589 last
= s
->vma
+ s
->_raw_size
;
5593 sym
.st_value
= last
;
5597 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
5602 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
5604 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
5605 (((Elf32_External_Sym
*)
5610 /* Set the sh_info field of the output .dynsym section to
5611 the index of the first global symbol. */
5612 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
5613 SIZEOF_MIPS_DYNSYM_SECNAMES
;
5619 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
5622 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
5626 sym
.st_value
= s
->vma
;
5628 indx
= elf_section_data (s
)->this_idx
;
5629 BFD_ASSERT (indx
> 0);
5630 sym
.st_shndx
= indx
;
5632 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
5633 (((Elf32_External_Sym
*)
5635 + elf_section_data (s
)->dynindx
));
5638 /* Set the sh_info field of the output .dynsym section to
5639 the index of the first global symbol. */
5640 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
5641 bfd_count_sections (output_bfd
) + 1;
5645 if (SGI_COMPAT (output_bfd
))
5647 /* Write .compact_rel section out. */
5648 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5652 cpt
.num
= s
->reloc_count
;
5654 cpt
.offset
= (s
->output_section
->filepos
5655 + sizeof (Elf32_External_compact_rel
));
5658 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
5659 ((Elf32_External_compact_rel
*)
5662 /* Clean up a dummy stub function entry in .text. */
5663 s
= bfd_get_section_by_name (dynobj
, ".stub");
5666 file_ptr dummy_offset
;
5668 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
5669 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
5670 memset (s
->contents
+ dummy_offset
, 0,
5671 MIPS_FUNCTION_STUB_SIZE
);
5676 /* Clean up a first relocation in .rel.dyn. */
5677 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5679 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
5685 /* This is almost identical to bfd_generic_get_... except that some
5686 MIPS relocations need to be handled specially. Sigh. */
5689 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
5690 relocateable
, symbols
)
5692 struct bfd_link_info
*link_info
;
5693 struct bfd_link_order
*link_order
;
5695 boolean relocateable
;
5698 /* Get enough memory to hold the stuff */
5699 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
5700 asection
*input_section
= link_order
->u
.indirect
.section
;
5702 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
5703 arelent
**reloc_vector
= NULL
;
5709 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
5710 if (reloc_vector
== NULL
&& reloc_size
!= 0)
5713 /* read in the section */
5714 if (!bfd_get_section_contents (input_bfd
,
5718 input_section
->_raw_size
))
5721 /* We're not relaxing the section, so just copy the size info */
5722 input_section
->_cooked_size
= input_section
->_raw_size
;
5723 input_section
->reloc_done
= true;
5725 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
5729 if (reloc_count
< 0)
5732 if (reloc_count
> 0)
5737 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
5740 struct bfd_hash_entry
*h
;
5741 struct bfd_link_hash_entry
*lh
;
5742 /* Skip all this stuff if we aren't mixing formats. */
5743 if (abfd
&& input_bfd
5744 && abfd
->xvec
== input_bfd
->xvec
)
5748 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
5749 lh
= (struct bfd_link_hash_entry
*) h
;
5756 case bfd_link_hash_undefined
:
5757 case bfd_link_hash_undefweak
:
5758 case bfd_link_hash_common
:
5761 case bfd_link_hash_defined
:
5762 case bfd_link_hash_defweak
:
5764 gp
= lh
->u
.def
.value
;
5766 case bfd_link_hash_indirect
:
5767 case bfd_link_hash_warning
:
5769 /* @@FIXME ignoring warning for now */
5771 case bfd_link_hash_new
:
5780 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
5783 char *error_message
= (char *) NULL
;
5784 bfd_reloc_status_type r
;
5786 /* Specific to MIPS: Deal with relocation types that require
5787 knowing the gp of the output bfd. */
5788 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
5789 if (bfd_is_abs_section (sym
->section
) && abfd
)
5791 /* The special_function wouldn't get called anyways. */
5795 /* The gp isn't there; let the special function code
5796 fall over on its own. */
5798 else if ((*parent
)->howto
->special_function
5799 == mips_elf_gprel16_reloc
)
5801 /* bypass special_function call */
5802 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
5803 relocateable
, (PTR
) data
, gp
);
5804 goto skip_bfd_perform_relocation
;
5806 /* end mips specific stuff */
5808 r
= bfd_perform_relocation (input_bfd
,
5812 relocateable
? abfd
: (bfd
*) NULL
,
5814 skip_bfd_perform_relocation
:
5818 asection
*os
= input_section
->output_section
;
5820 /* A partial link, so keep the relocs */
5821 os
->orelocation
[os
->reloc_count
] = *parent
;
5825 if (r
!= bfd_reloc_ok
)
5829 case bfd_reloc_undefined
:
5830 if (!((*link_info
->callbacks
->undefined_symbol
)
5831 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
5832 input_bfd
, input_section
, (*parent
)->address
)))
5835 case bfd_reloc_dangerous
:
5836 BFD_ASSERT (error_message
!= (char *) NULL
);
5837 if (!((*link_info
->callbacks
->reloc_dangerous
)
5838 (link_info
, error_message
, input_bfd
, input_section
,
5839 (*parent
)->address
)))
5842 case bfd_reloc_overflow
:
5843 if (!((*link_info
->callbacks
->reloc_overflow
)
5844 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
5845 (*parent
)->howto
->name
, (*parent
)->addend
,
5846 input_bfd
, input_section
, (*parent
)->address
)))
5849 case bfd_reloc_outofrange
:
5858 if (reloc_vector
!= NULL
)
5859 free (reloc_vector
);
5863 if (reloc_vector
!= NULL
)
5864 free (reloc_vector
);
5867 #define bfd_elf32_bfd_get_relocated_section_contents \
5868 elf32_mips_get_relocated_section_contents
5870 /* ECOFF swapping routines. These are used when dealing with the
5871 .mdebug section, which is in the ECOFF debugging format. */
5872 static const struct ecoff_debug_swap mips_elf_ecoff_debug_swap
=
5874 /* Symbol table magic number. */
5876 /* Alignment of debugging information. E.g., 4. */
5878 /* Sizes of external symbolic information. */
5879 sizeof (struct hdr_ext
),
5880 sizeof (struct dnr_ext
),
5881 sizeof (struct pdr_ext
),
5882 sizeof (struct sym_ext
),
5883 sizeof (struct opt_ext
),
5884 sizeof (struct fdr_ext
),
5885 sizeof (struct rfd_ext
),
5886 sizeof (struct ext_ext
),
5887 /* Functions to swap in external symbolic data. */
5896 _bfd_ecoff_swap_tir_in
,
5897 _bfd_ecoff_swap_rndx_in
,
5898 /* Functions to swap out external symbolic data. */
5907 _bfd_ecoff_swap_tir_out
,
5908 _bfd_ecoff_swap_rndx_out
,
5909 /* Function to read in symbolic data. */
5910 mips_elf_read_ecoff_info
5913 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
5914 #define TARGET_LITTLE_NAME "elf32-littlemips"
5915 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
5916 #define TARGET_BIG_NAME "elf32-bigmips"
5917 #define ELF_ARCH bfd_arch_mips
5918 #define ELF_MACHINE_CODE EM_MIPS
5919 #define ELF_MAXPAGESIZE 0x10000
5920 #define elf_backend_collect true
5921 #define elf_backend_type_change_ok true
5922 #define elf_info_to_howto 0
5923 #define elf_info_to_howto_rel mips_info_to_howto_rel
5924 #define elf_backend_sym_is_global mips_elf_sym_is_global
5925 #define elf_backend_object_p mips_elf_object_p
5926 #define elf_backend_section_from_shdr mips_elf_section_from_shdr
5927 #define elf_backend_fake_sections mips_elf_fake_sections
5928 #define elf_backend_section_from_bfd_section \
5929 mips_elf_section_from_bfd_section
5930 #define elf_backend_section_processing mips_elf_section_processing
5931 #define elf_backend_symbol_processing mips_elf_symbol_processing
5932 #define elf_backend_additional_program_headers \
5933 mips_elf_additional_program_headers
5934 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
5935 #define elf_backend_final_write_processing \
5936 mips_elf_final_write_processing
5937 #define elf_backend_ecoff_debug_swap &mips_elf_ecoff_debug_swap
5939 #define bfd_elf32_bfd_is_local_label mips_elf_is_local_label
5940 #define bfd_elf32_find_nearest_line mips_elf_find_nearest_line
5942 #define bfd_elf32_bfd_link_hash_table_create \
5943 mips_elf_link_hash_table_create
5944 #define bfd_elf32_bfd_final_link mips_elf_final_link
5945 #define bfd_elf32_bfd_copy_private_bfd_data \
5946 mips_elf_copy_private_bfd_data
5947 #define bfd_elf32_bfd_merge_private_bfd_data \
5948 mips_elf_merge_private_bfd_data
5949 #define bfd_elf32_bfd_set_private_flags mips_elf_set_private_flags
5950 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
5951 #define elf_backend_create_dynamic_sections \
5952 mips_elf_create_dynamic_sections
5953 #define elf_backend_check_relocs mips_elf_check_relocs
5954 #define elf_backend_adjust_dynamic_symbol \
5955 mips_elf_adjust_dynamic_symbol
5956 #define elf_backend_size_dynamic_sections \
5957 mips_elf_size_dynamic_sections
5958 #define elf_backend_relocate_section mips_elf_relocate_section
5959 #define elf_backend_finish_dynamic_symbol \
5960 mips_elf_finish_dynamic_symbol
5961 #define elf_backend_finish_dynamic_sections \
5962 mips_elf_finish_dynamic_sections
5964 #include "elf32-target.h"