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_elf32_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_gp (obfd
) = elf_gp (ibfd
);
1568 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1569 elf_flags_init (obfd
) = true;
1573 /* Merge backend specific data from an object file to the output
1574 object file when linking. */
1577 mips_elf_merge_private_bfd_data (ibfd
, obfd
)
1584 /* Check if we have the same endianess */
1585 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1586 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1588 (*_bfd_error_handler
)
1589 ("%s: compiled for a %s endian system and target is %s endian",
1590 bfd_get_filename (ibfd
),
1591 bfd_big_endian (ibfd
) ? "big" : "little",
1592 bfd_big_endian (obfd
) ? "big" : "little");
1594 bfd_set_error (bfd_error_wrong_format
);
1598 /* This function is selected based on the input vector. We only
1599 want to copy information over if the output BFD also uses Elf
1601 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1604 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1605 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
1606 old_flags
= elf_elfheader (obfd
)->e_flags
;
1608 if (!elf_flags_init (obfd
)) /* First call, no flags set */
1610 elf_flags_init (obfd
) = true;
1611 elf_elfheader (obfd
)->e_flags
= new_flags
;
1613 else if (((new_flags
^ old_flags
) & ~EF_MIPS_NOREORDER
)
1614 == 0) /* Compatible flags are ok */
1616 else /* Incompatible flags */
1618 /* Warn about -fPIC mismatch */
1619 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
1621 new_flags
&= ~EF_MIPS_PIC
;
1622 (*_bfd_error_handler
)
1623 ("%s: needs all files compiled with -fPIC",
1624 bfd_get_filename (ibfd
));
1627 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
1629 new_flags
&= ~EF_MIPS_CPIC
;
1630 (*_bfd_error_handler
)
1631 ("%s: needs all files compiled with -mabicalls",
1632 bfd_get_filename (ibfd
));
1635 /* Warn about any other mismatches */
1636 if (new_flags
!= old_flags
)
1637 (*_bfd_error_handler
)
1638 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1639 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
1640 (unsigned long) old_flags
);
1642 bfd_set_error (bfd_error_bad_value
);
1649 /* Handle a MIPS specific section when reading an object file. This
1650 is called when elfcode.h finds a section with an unknown type.
1651 This routine supports both the 32-bit and 64-bit ELF ABI.
1653 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
1657 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
1659 Elf_Internal_Shdr
*hdr
;
1662 /* There ought to be a place to keep ELF backend specific flags, but
1663 at the moment there isn't one. We just keep track of the
1664 sections by their name, instead. Fortunately, the ABI gives
1665 suggested names for all the MIPS specific sections, so we will
1666 probably get away with this. */
1667 switch (hdr
->sh_type
)
1669 case SHT_MIPS_LIBLIST
:
1670 if (strcmp (name
, ".liblist") != 0)
1674 if (strcmp (name
, ".msym") != 0)
1677 case SHT_MIPS_CONFLICT
:
1678 if (strcmp (name
, ".conflict") != 0)
1681 case SHT_MIPS_GPTAB
:
1682 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
1685 case SHT_MIPS_UCODE
:
1686 if (strcmp (name
, ".ucode") != 0)
1689 case SHT_MIPS_DEBUG
:
1690 if (strcmp (name
, ".mdebug") != 0)
1693 case SHT_MIPS_REGINFO
:
1694 if (strcmp (name
, ".reginfo") != 0
1695 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
1698 case SHT_MIPS_OPTIONS
:
1699 if (strcmp (name
, ".options") != 0)
1702 case SHT_MIPS_DWARF
:
1703 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
1706 case SHT_MIPS_EVENTS
:
1707 if (strncmp (name
, ".MIPS.events.", sizeof ".MIPS.events." - 1) != 0)
1714 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1717 if (hdr
->sh_type
== SHT_MIPS_DEBUG
)
1719 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
1720 (bfd_get_section_flags (abfd
,
1729 /* Handle a 32-bit MIPS ELF specific section. */
1732 mips_elf32_section_from_shdr (abfd
, hdr
, name
)
1734 Elf_Internal_Shdr
*hdr
;
1737 if (! _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
))
1740 /* FIXME: We should record sh_info for a .gptab section. */
1742 /* For a .reginfo section, set the gp value in the tdata information
1743 from the contents of this section. We need the gp value while
1744 processing relocs, so we just get it now. The .reginfo section
1745 is not used in the 64-bit MIPS ELF ABI. */
1746 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
1748 Elf32_External_RegInfo ext
;
1751 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
1752 (file_ptr
) 0, sizeof ext
))
1754 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
1755 elf_gp (abfd
) = s
.ri_gp_value
;
1761 /* Set the correct type for a MIPS ELF section. We do this by the
1762 section name, which is a hack, but ought to work. */
1765 mips_elf_fake_sections (abfd
, hdr
, sec
)
1767 Elf32_Internal_Shdr
*hdr
;
1770 register const char *name
;
1772 name
= bfd_get_section_name (abfd
, sec
);
1774 if (strcmp (name
, ".liblist") == 0)
1776 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
1777 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
1778 /* FIXME: Set the sh_link field. */
1780 else if (strcmp (name
, ".msym") == 0)
1782 hdr
->sh_type
= SHT_MIPS_MSYM
;
1783 hdr
->sh_entsize
= 8;
1784 /* FIXME: Set the sh_info field. */
1786 else if (strcmp (name
, ".conflict") == 0)
1787 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
1788 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
1790 hdr
->sh_type
= SHT_MIPS_GPTAB
;
1791 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
1792 /* The sh_info field is set in mips_elf_final_write_processing. */
1794 else if (strcmp (name
, ".ucode") == 0)
1795 hdr
->sh_type
= SHT_MIPS_UCODE
;
1796 else if (strcmp (name
, ".mdebug") == 0)
1798 hdr
->sh_type
= SHT_MIPS_DEBUG
;
1799 /* In a shared object on Irix 5.3, the .mdebug section has an
1800 entsize of 0. FIXME: Does this matter? */
1801 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
1802 hdr
->sh_entsize
= 0;
1804 hdr
->sh_entsize
= 1;
1806 else if (strcmp (name
, ".reginfo") == 0)
1808 hdr
->sh_type
= SHT_MIPS_REGINFO
;
1809 /* In a shared object on Irix 5.3, the .reginfo section has an
1810 entsize of 0x18. FIXME: Does this matter? */
1811 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
1812 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
1814 hdr
->sh_entsize
= 1;
1816 /* Force the section size to the correct value, even if the
1817 linker thinks it is larger. The link routine below will only
1818 write out this much data for .reginfo. */
1819 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf32_External_RegInfo
);
1821 else if (SGI_COMPAT (abfd
)
1822 && (strcmp (name
, ".hash") == 0
1823 || strcmp (name
, ".dynamic") == 0
1824 || strcmp (name
, ".dynstr") == 0))
1826 hdr
->sh_entsize
= 0;
1827 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
1829 else if (strcmp (name
, ".got") == 0
1830 || strcmp (name
, ".sdata") == 0
1831 || strcmp (name
, ".sbss") == 0
1832 || strcmp (name
, ".lit4") == 0
1833 || strcmp (name
, ".lit8") == 0)
1834 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
1835 else if (strcmp (name
, ".options") == 0)
1837 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
1838 hdr
->sh_entsize
= 1;
1840 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
1841 hdr
->sh_type
= SHT_MIPS_DWARF
;
1842 else if (strncmp (name
, ".MIPS.events.", sizeof ".MIPS.events." - 1) == 0)
1843 hdr
->sh_type
= SHT_MIPS_EVENTS
;
1848 /* Given a BFD section, try to locate the corresponding ELF section
1852 mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
1854 Elf32_Internal_Shdr
*hdr
;
1858 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
1860 *retval
= SHN_MIPS_SCOMMON
;
1863 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
1865 *retval
= SHN_MIPS_ACOMMON
;
1871 /* Work over a section just before writing it out. We update the GP
1872 value in the .reginfo section based on the value we are using.
1873 FIXME: We recognize sections that need the SHF_MIPS_GPREL flag by
1874 name; there has to be a better way. */
1877 mips_elf_section_processing (abfd
, hdr
)
1879 Elf32_Internal_Shdr
*hdr
;
1881 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
1885 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
1886 BFD_ASSERT (hdr
->contents
== NULL
);
1889 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
1892 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
1893 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
1897 if (hdr
->bfd_section
!= NULL
)
1899 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
1901 if (strcmp (name
, ".sdata") == 0)
1903 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
1904 hdr
->sh_type
= SHT_PROGBITS
;
1906 else if (strcmp (name
, ".sbss") == 0)
1908 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
1909 hdr
->sh_type
= SHT_NOBITS
;
1911 else if (strcmp (name
, ".lit8") == 0
1912 || strcmp (name
, ".lit4") == 0)
1914 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
1915 hdr
->sh_type
= SHT_PROGBITS
;
1917 else if (strcmp (name
, ".compact_rel") == 0)
1920 hdr
->sh_type
= SHT_PROGBITS
;
1922 else if (strcmp (name
, ".rtproc") == 0)
1924 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
1926 unsigned int adjust
;
1928 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
1930 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
1938 /* MIPS ELF uses two common sections. One is the usual one, and the
1939 other is for small objects. All the small objects are kept
1940 together, and then referenced via the gp pointer, which yields
1941 faster assembler code. This is what we use for the small common
1942 section. This approach is copied from ecoff.c. */
1943 static asection mips_elf_scom_section
;
1944 static asymbol mips_elf_scom_symbol
;
1945 static asymbol
*mips_elf_scom_symbol_ptr
;
1947 /* MIPS ELF also uses an acommon section, which represents an
1948 allocated common symbol which may be overridden by a
1949 definition in a shared library. */
1950 static asection mips_elf_acom_section
;
1951 static asymbol mips_elf_acom_symbol
;
1952 static asymbol
*mips_elf_acom_symbol_ptr
;
1954 /* The Irix 5 support uses two virtual sections, which represent
1955 text/data symbols defined in dynamic objects. */
1956 static asection mips_elf_text_section
;
1957 static asection
*mips_elf_text_section_ptr
;
1958 static asymbol mips_elf_text_symbol
;
1959 static asymbol
*mips_elf_text_symbol_ptr
;
1961 static asection mips_elf_data_section
;
1962 static asection
*mips_elf_data_section_ptr
;
1963 static asymbol mips_elf_data_symbol
;
1964 static asymbol
*mips_elf_data_symbol_ptr
;
1966 /* Handle the special MIPS section numbers that a symbol may use. */
1969 mips_elf_symbol_processing (abfd
, asym
)
1973 elf_symbol_type
*elfsym
;
1975 elfsym
= (elf_symbol_type
*) asym
;
1976 switch (elfsym
->internal_elf_sym
.st_shndx
)
1978 case SHN_MIPS_ACOMMON
:
1979 /* This section is used in a dynamically linked executable file.
1980 It is an allocated common section. The dynamic linker can
1981 either resolve these symbols to something in a shared
1982 library, or it can just leave them here. For our purposes,
1983 we can consider these symbols to be in a new section. */
1984 if (mips_elf_acom_section
.name
== NULL
)
1986 /* Initialize the acommon section. */
1987 mips_elf_acom_section
.name
= ".acommon";
1988 mips_elf_acom_section
.flags
= SEC_ALLOC
;
1989 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
1990 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
1991 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
1992 mips_elf_acom_symbol
.name
= ".acommon";
1993 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
1994 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
1995 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
1997 asym
->section
= &mips_elf_acom_section
;
2001 /* Common symbols less than the GP size are automatically
2002 treated as SHN_MIPS_SCOMMON symbols. */
2003 if (asym
->value
> elf_gp_size (abfd
))
2006 case SHN_MIPS_SCOMMON
:
2007 if (mips_elf_scom_section
.name
== NULL
)
2009 /* Initialize the small common section. */
2010 mips_elf_scom_section
.name
= ".scommon";
2011 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
2012 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
2013 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
2014 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
2015 mips_elf_scom_symbol
.name
= ".scommon";
2016 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2017 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
2018 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
2020 asym
->section
= &mips_elf_scom_section
;
2021 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2024 case SHN_MIPS_SUNDEFINED
:
2025 asym
->section
= bfd_und_section_ptr
;
2028 #if 0 /* for SGI_COMPAT */
2030 asym
->section
= mips_elf_text_section_ptr
;
2034 asym
->section
= mips_elf_data_section_ptr
;
2040 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
2044 mips_elf_additional_program_headers (abfd
)
2052 if (! SGI_COMPAT (abfd
))
2055 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2056 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2058 /* We need a PT_MIPS_REGINFO segment. */
2062 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2063 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2065 /* We need a PT_MIPS_RTPROC segment. */
2072 /* Modify the segment map for an Irix 5 executable. */
2075 mips_elf_modify_segment_map (abfd
)
2079 struct elf_segment_map
*m
, **pm
;
2081 if (! SGI_COMPAT (abfd
))
2084 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
2086 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2087 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2089 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2090 if (m
->p_type
== PT_MIPS_REGINFO
)
2094 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2098 m
->p_type
= PT_MIPS_REGINFO
;
2102 /* We want to put it after the PHDR and INTERP segments. */
2103 pm
= &elf_tdata (abfd
)->segment_map
;
2105 && ((*pm
)->p_type
== PT_PHDR
2106 || (*pm
)->p_type
== PT_INTERP
))
2114 /* If there are .dynamic and .mdebug sections, we make a room for
2115 the RTPROC header. FIXME: Rewrite without section names. */
2116 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
2117 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2118 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2120 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2121 if (m
->p_type
== PT_MIPS_RTPROC
)
2125 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2129 m
->p_type
= PT_MIPS_RTPROC
;
2131 s
= bfd_get_section_by_name (abfd
, ".rtproc");
2136 m
->p_flags_valid
= 1;
2144 /* We want to put it after the DYNAMIC segment. */
2145 pm
= &elf_tdata (abfd
)->segment_map
;
2146 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
2156 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
2157 .dynsym, and .hash sections, and everything in between. */
2158 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
2159 if ((*pm
)->p_type
== PT_DYNAMIC
)
2164 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
2166 static const char *sec_names
[] =
2167 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
2170 struct elf_segment_map
*n
;
2174 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
2176 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
2177 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2183 sz
= s
->_cooked_size
;
2186 if (high
< s
->vma
+ sz
)
2192 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2193 if ((s
->flags
& SEC_LOAD
) != 0
2196 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2200 n
= ((struct elf_segment_map
*)
2201 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
2208 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2210 if ((s
->flags
& SEC_LOAD
) != 0
2213 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2227 /* The structure of the runtime procedure descriptor created by the
2228 loader for use by the static exception system. */
2230 typedef struct runtime_pdr
{
2231 bfd_vma adr
; /* memory address of start of procedure */
2232 long regmask
; /* save register mask */
2233 long regoffset
; /* save register offset */
2234 long fregmask
; /* save floating point register mask */
2235 long fregoffset
; /* save floating point register offset */
2236 long frameoffset
; /* frame size */
2237 short framereg
; /* frame pointer register */
2238 short pcreg
; /* offset or reg of return pc */
2239 long irpss
; /* index into the runtime string table */
2241 struct exception_info
*exception_info
;/* pointer to exception array */
2243 #define cbRPDR sizeof(RPDR)
2244 #define rpdNil ((pRPDR) 0)
2246 /* Swap RPDR (runtime procedure table entry) for output. */
2248 static void ecoff_swap_rpdr_out
2249 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
2252 ecoff_swap_rpdr_out (abfd
, in
, ex
)
2255 struct rpdr_ext
*ex
;
2257 /* ecoff_put_off was defined in ecoffswap.h. */
2258 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
2259 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
2260 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
2261 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
2262 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
2263 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
2265 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
2266 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
2268 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
2270 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
2274 /* Read ECOFF debugging information from a .mdebug section into a
2275 ecoff_debug_info structure. */
2278 mips_elf_read_ecoff_info (abfd
, section
, debug
)
2281 struct ecoff_debug_info
*debug
;
2284 const struct ecoff_debug_swap
*swap
;
2285 char *ext_hdr
= NULL
;
2287 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2289 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
2290 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
2293 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
2294 swap
->external_hdr_size
)
2298 symhdr
= &debug
->symbolic_header
;
2299 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
2301 /* The symbolic header contains absolute file offsets and sizes to
2303 #define READ(ptr, offset, count, size, type) \
2304 if (symhdr->count == 0) \
2305 debug->ptr = NULL; \
2308 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
2309 if (debug->ptr == NULL) \
2310 goto error_return; \
2311 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
2312 || (bfd_read (debug->ptr, size, symhdr->count, \
2313 abfd) != size * symhdr->count)) \
2314 goto error_return; \
2317 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
2318 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
2319 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
2320 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
2321 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
2322 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
2324 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
2325 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
2326 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
2327 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
2328 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
2332 debug
->adjust
= NULL
;
2337 if (ext_hdr
!= NULL
)
2339 if (debug
->line
!= NULL
)
2341 if (debug
->external_dnr
!= NULL
)
2342 free (debug
->external_dnr
);
2343 if (debug
->external_pdr
!= NULL
)
2344 free (debug
->external_pdr
);
2345 if (debug
->external_sym
!= NULL
)
2346 free (debug
->external_sym
);
2347 if (debug
->external_opt
!= NULL
)
2348 free (debug
->external_opt
);
2349 if (debug
->external_aux
!= NULL
)
2350 free (debug
->external_aux
);
2351 if (debug
->ss
!= NULL
)
2353 if (debug
->ssext
!= NULL
)
2354 free (debug
->ssext
);
2355 if (debug
->external_fdr
!= NULL
)
2356 free (debug
->external_fdr
);
2357 if (debug
->external_rfd
!= NULL
)
2358 free (debug
->external_rfd
);
2359 if (debug
->external_ext
!= NULL
)
2360 free (debug
->external_ext
);
2364 /* MIPS ELF local labels start with '$', not 'L'. */
2368 mips_elf_is_local_label (abfd
, symbol
)
2372 return symbol
->name
[0] == '$';
2375 /* MIPS ELF uses a special find_nearest_line routine in order the
2376 handle the ECOFF debugging information. */
2378 struct mips_elf_find_line
2380 struct ecoff_debug_info d
;
2381 struct ecoff_find_line i
;
2385 mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
2386 functionname_ptr
, line_ptr
)
2391 const char **filename_ptr
;
2392 const char **functionname_ptr
;
2393 unsigned int *line_ptr
;
2397 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
2401 struct mips_elf_find_line
*fi
;
2402 const struct ecoff_debug_swap
* const swap
=
2403 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2405 /* If we are called during a link, mips_elf_final_link may have
2406 cleared the SEC_HAS_CONTENTS field. We force it back on here
2407 if appropriate (which it normally will be). */
2408 origflags
= msec
->flags
;
2409 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
2410 msec
->flags
|= SEC_HAS_CONTENTS
;
2412 fi
= elf_tdata (abfd
)->find_line_info
;
2415 bfd_size_type external_fdr_size
;
2418 struct fdr
*fdr_ptr
;
2420 fi
= ((struct mips_elf_find_line
*)
2421 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
2424 msec
->flags
= origflags
;
2428 if (! mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
2430 msec
->flags
= origflags
;
2434 /* Swap in the FDR information. */
2435 fi
->d
.fdr
= ((struct fdr
*)
2437 (fi
->d
.symbolic_header
.ifdMax
*
2438 sizeof (struct fdr
))));
2439 if (fi
->d
.fdr
== NULL
)
2441 msec
->flags
= origflags
;
2444 external_fdr_size
= swap
->external_fdr_size
;
2445 fdr_ptr
= fi
->d
.fdr
;
2446 fraw_src
= (char *) fi
->d
.external_fdr
;
2447 fraw_end
= (fraw_src
2448 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
2449 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
2450 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
2452 elf_tdata (abfd
)->find_line_info
= fi
;
2454 /* Note that we don't bother to ever free this information.
2455 find_nearest_line is either called all the time, as in
2456 objdump -l, so the information should be saved, or it is
2457 rarely called, as in ld error messages, so the memory
2458 wasted is unimportant. Still, it would probably be a
2459 good idea for free_cached_info to throw it away. */
2462 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
2463 &fi
->i
, filename_ptr
, functionname_ptr
,
2466 msec
->flags
= origflags
;
2470 msec
->flags
= origflags
;
2473 /* Fall back on the generic ELF find_nearest_line routine. */
2475 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
2476 filename_ptr
, functionname_ptr
,
2480 /* The MIPS ELF linker needs additional information for each symbol in
2481 the global hash table. */
2483 struct mips_elf_link_hash_entry
2485 struct elf_link_hash_entry root
;
2487 /* External symbol information. */
2490 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
2491 unsigned int mips_32_relocs
;
2494 /* MIPS ELF linker hash table. */
2496 struct mips_elf_link_hash_table
2498 struct elf_link_hash_table root
;
2499 /* String section indices for the dynamic section symbols. */
2500 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
2501 /* The number of .rtproc entries. */
2502 bfd_size_type procedure_count
;
2503 /* The size of the .compact_rel section (if SGI_COMPAT). */
2504 bfd_size_type compact_rel_size
;
2507 /* Look up an entry in a MIPS ELF linker hash table. */
2509 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
2510 ((struct mips_elf_link_hash_entry *) \
2511 elf_link_hash_lookup (&(table)->root, (string), (create), \
2514 /* Traverse a MIPS ELF linker hash table. */
2516 #define mips_elf_link_hash_traverse(table, func, info) \
2517 (elf_link_hash_traverse \
2519 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
2522 /* Get the MIPS ELF linker hash table from a link_info structure. */
2524 #define mips_elf_hash_table(p) \
2525 ((struct mips_elf_link_hash_table *) ((p)->hash))
2527 static boolean mips_elf_output_extsym
2528 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
2530 /* Create an entry in a MIPS ELF linker hash table. */
2532 static struct bfd_hash_entry
*
2533 mips_elf_link_hash_newfunc (entry
, table
, string
)
2534 struct bfd_hash_entry
*entry
;
2535 struct bfd_hash_table
*table
;
2538 struct mips_elf_link_hash_entry
*ret
=
2539 (struct mips_elf_link_hash_entry
*) entry
;
2541 /* Allocate the structure if it has not already been allocated by a
2543 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
2544 ret
= ((struct mips_elf_link_hash_entry
*)
2545 bfd_hash_allocate (table
,
2546 sizeof (struct mips_elf_link_hash_entry
)));
2547 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
2548 return (struct bfd_hash_entry
*) ret
;
2550 /* Call the allocation method of the superclass. */
2551 ret
= ((struct mips_elf_link_hash_entry
*)
2552 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2554 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
2556 /* Set local fields. */
2557 memset (&ret
->esym
, 0, sizeof (EXTR
));
2558 /* We use -2 as a marker to indicate that the information has
2559 not been set. -1 means there is no associated ifd. */
2561 ret
->mips_32_relocs
= 0;
2564 return (struct bfd_hash_entry
*) ret
;
2567 /* Create a MIPS ELF linker hash table. */
2569 static struct bfd_link_hash_table
*
2570 mips_elf_link_hash_table_create (abfd
)
2573 struct mips_elf_link_hash_table
*ret
;
2576 ret
= ((struct mips_elf_link_hash_table
*)
2577 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
2578 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
2581 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
2582 mips_elf_link_hash_newfunc
))
2584 bfd_release (abfd
, ret
);
2588 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
2589 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
2590 ret
->procedure_count
= 0;
2591 ret
->compact_rel_size
= 0;
2593 return &ret
->root
.root
;
2596 /* Hook called by the linker routine which adds symbols from an object
2597 file. We must handle the special MIPS section numbers here. */
2601 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2603 struct bfd_link_info
*info
;
2604 const Elf_Internal_Sym
*sym
;
2610 if (SGI_COMPAT (abfd
)
2611 && (abfd
->flags
& DYNAMIC
) != 0
2612 && strcmp (*namep
, "_rld_new_interface") == 0)
2614 /* Skip Irix 5 rld entry name. */
2619 switch (sym
->st_shndx
)
2622 /* Common symbols less than the GP size are automatically
2623 treated as SHN_MIPS_SCOMMON symbols. */
2624 if (sym
->st_size
> elf_gp_size (abfd
))
2627 case SHN_MIPS_SCOMMON
:
2628 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
2629 (*secp
)->flags
|= SEC_IS_COMMON
;
2630 *valp
= sym
->st_size
;
2634 /* This section is used in a shared object. */
2635 if (mips_elf_text_section_ptr
== NULL
)
2637 /* Initialize the section. */
2638 mips_elf_text_section
.name
= ".text";
2639 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
2640 mips_elf_text_section
.output_section
= NULL
;
2641 mips_elf_text_section
.owner
= abfd
;
2642 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
2643 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
2644 mips_elf_text_symbol
.name
= ".text";
2645 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
2646 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
2647 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
2648 mips_elf_text_section_ptr
= &mips_elf_text_section
;
2651 *secp
= bfd_und_section_ptr
;
2653 *secp
= mips_elf_text_section_ptr
;
2656 case SHN_MIPS_ACOMMON
:
2657 /* Fall through. XXX Can we treat this as allocated data? */
2659 /* This section is used in a shared object. */
2660 if (mips_elf_data_section_ptr
== NULL
)
2662 /* Initialize the section. */
2663 mips_elf_data_section
.name
= ".data";
2664 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
2665 mips_elf_data_section
.output_section
= NULL
;
2666 mips_elf_data_section
.owner
= abfd
;
2667 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
2668 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
2669 mips_elf_data_symbol
.name
= ".data";
2670 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
2671 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
2672 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
2673 mips_elf_data_section_ptr
= &mips_elf_data_section
;
2676 *secp
= bfd_und_section_ptr
;
2678 *secp
= mips_elf_data_section_ptr
;
2681 case SHN_MIPS_SUNDEFINED
:
2682 *secp
= bfd_und_section_ptr
;
2689 /* Structure used to pass information to mips_elf_output_extsym. */
2694 struct bfd_link_info
*info
;
2695 struct ecoff_debug_info
*debug
;
2696 const struct ecoff_debug_swap
*swap
;
2700 /* This routine is used to write out ECOFF debugging external symbol
2701 information. It is called via mips_elf_link_hash_traverse. The
2702 ECOFF external symbol information must match the ELF external
2703 symbol information. Unfortunately, at this point we don't know
2704 whether a symbol is required by reloc information, so the two
2705 tables may wind up being different. We must sort out the external
2706 symbol information before we can set the final size of the .mdebug
2707 section, and we must set the size of the .mdebug section before we
2708 can relocate any sections, and we can't know which symbols are
2709 required by relocation until we relocate the sections.
2710 Fortunately, it is relatively unlikely that any symbol will be
2711 stripped but required by a reloc. In particular, it can not happen
2712 when generating a final executable. */
2715 mips_elf_output_extsym (h
, data
)
2716 struct mips_elf_link_hash_entry
*h
;
2719 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
2721 asection
*sec
, *output_section
;
2723 if (h
->root
.indx
== -2)
2725 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2726 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
2727 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
2728 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
2730 else if (einfo
->info
->strip
== strip_all
2731 || (einfo
->info
->strip
== strip_some
2732 && bfd_hash_lookup (einfo
->info
->keep_hash
,
2733 h
->root
.root
.root
.string
,
2734 false, false) == NULL
))
2742 if (h
->esym
.ifd
== -2)
2745 h
->esym
.cobol_main
= 0;
2746 h
->esym
.weakext
= 0;
2747 h
->esym
.reserved
= 0;
2748 h
->esym
.ifd
= ifdNil
;
2749 h
->esym
.asym
.value
= 0;
2750 h
->esym
.asym
.st
= stGlobal
;
2752 if (SGI_COMPAT (einfo
->abfd
)
2753 && (h
->root
.root
.type
== bfd_link_hash_undefined
2754 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
2758 /* Use undefined class. Also, set class and type for some
2760 name
= h
->root
.root
.root
.string
;
2761 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
2762 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
2764 h
->esym
.asym
.sc
= scData
;
2765 h
->esym
.asym
.st
= stLabel
;
2766 h
->esym
.asym
.value
= 0;
2768 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
2770 h
->esym
.asym
.sc
= scAbs
;
2771 h
->esym
.asym
.st
= stLabel
;
2772 h
->esym
.asym
.value
=
2773 mips_elf_hash_table (einfo
->info
)->procedure_count
;
2775 else if (strcmp (name
, "_gp_disp") == 0)
2777 h
->esym
.asym
.sc
= scAbs
;
2778 h
->esym
.asym
.st
= stLabel
;
2779 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
2782 h
->esym
.asym
.sc
= scUndefined
;
2784 else if (h
->root
.root
.type
!= bfd_link_hash_defined
2785 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2786 h
->esym
.asym
.sc
= scAbs
;
2791 sec
= h
->root
.root
.u
.def
.section
;
2792 output_section
= sec
->output_section
;
2794 /* When making a shared library and symbol h is the one from
2795 the another shared library, OUTPUT_SECTION may be null. */
2796 if (output_section
== NULL
)
2797 h
->esym
.asym
.sc
= scUndefined
;
2800 name
= bfd_section_name (output_section
->owner
, output_section
);
2802 if (strcmp (name
, ".text") == 0)
2803 h
->esym
.asym
.sc
= scText
;
2804 else if (strcmp (name
, ".data") == 0)
2805 h
->esym
.asym
.sc
= scData
;
2806 else if (strcmp (name
, ".sdata") == 0)
2807 h
->esym
.asym
.sc
= scSData
;
2808 else if (strcmp (name
, ".rodata") == 0
2809 || strcmp (name
, ".rdata") == 0)
2810 h
->esym
.asym
.sc
= scRData
;
2811 else if (strcmp (name
, ".bss") == 0)
2812 h
->esym
.asym
.sc
= scBss
;
2813 else if (strcmp (name
, ".sbss") == 0)
2814 h
->esym
.asym
.sc
= scSBss
;
2815 else if (strcmp (name
, ".init") == 0)
2816 h
->esym
.asym
.sc
= scInit
;
2817 else if (strcmp (name
, ".fini") == 0)
2818 h
->esym
.asym
.sc
= scFini
;
2820 h
->esym
.asym
.sc
= scAbs
;
2824 h
->esym
.asym
.reserved
= 0;
2825 h
->esym
.asym
.index
= indexNil
;
2828 if (h
->root
.root
.type
== bfd_link_hash_common
)
2829 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2830 else if (h
->root
.root
.type
== bfd_link_hash_defined
2831 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2833 if (h
->esym
.asym
.sc
== scCommon
)
2834 h
->esym
.asym
.sc
= scBss
;
2835 else if (h
->esym
.asym
.sc
== scSCommon
)
2836 h
->esym
.asym
.sc
= scSBss
;
2838 sec
= h
->root
.root
.u
.def
.section
;
2839 output_section
= sec
->output_section
;
2840 if (output_section
!= NULL
)
2841 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2842 + sec
->output_offset
2843 + output_section
->vma
);
2845 h
->esym
.asym
.value
= 0;
2847 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
2849 /* Set type and value for a symbol with a function stub. */
2850 h
->esym
.asym
.st
= stProc
;
2851 sec
= h
->root
.root
.u
.def
.section
;
2853 h
->esym
.asym
.value
= 0;
2856 output_section
= sec
->output_section
;
2857 if (output_section
!= NULL
)
2858 h
->esym
.asym
.value
= (h
->root
.plt_offset
2859 + sec
->output_offset
2860 + output_section
->vma
);
2862 h
->esym
.asym
.value
= 0;
2869 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
2870 h
->root
.root
.root
.string
,
2873 einfo
->failed
= true;
2880 /* Create a runtime procedure table from the .mdebug section. */
2883 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
2886 struct bfd_link_info
*info
;
2888 struct ecoff_debug_info
*debug
;
2890 const struct ecoff_debug_swap
*swap
;
2891 HDRR
*hdr
= &debug
->symbolic_header
;
2893 struct rpdr_ext
*erp
;
2895 struct pdr_ext
*epdr
;
2896 struct sym_ext
*esym
;
2899 unsigned long size
, count
;
2900 unsigned long sindex
;
2904 const char *no_name_func
= "static procedure (no name)";
2912 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2914 sindex
= strlen (no_name_func
) + 1;
2915 count
= hdr
->ipdMax
;
2918 size
= swap
->external_pdr_size
;
2920 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
2924 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
2927 size
= sizeof (RPDR
);
2928 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
2932 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
2936 count
= hdr
->isymMax
;
2937 size
= swap
->external_sym_size
;
2938 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
2942 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
2945 count
= hdr
->issMax
;
2946 ss
= (char *) bfd_malloc (count
);
2949 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
2952 count
= hdr
->ipdMax
;
2953 for (i
= 0; i
< count
; i
++, rp
++)
2955 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
2956 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
2957 rp
->adr
= sym
.value
;
2958 rp
->regmask
= pdr
.regmask
;
2959 rp
->regoffset
= pdr
.regoffset
;
2960 rp
->fregmask
= pdr
.fregmask
;
2961 rp
->fregoffset
= pdr
.fregoffset
;
2962 rp
->frameoffset
= pdr
.frameoffset
;
2963 rp
->framereg
= pdr
.framereg
;
2964 rp
->pcreg
= pdr
.pcreg
;
2966 sv
[i
] = ss
+ sym
.iss
;
2967 sindex
+= strlen (sv
[i
]) + 1;
2971 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
2972 size
= BFD_ALIGN (size
, 16);
2973 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
2976 mips_elf_hash_table (info
)->procedure_count
= 0;
2980 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
2982 erp
= (struct rpdr_ext
*) rtproc
;
2983 memset (erp
, 0, sizeof (struct rpdr_ext
));
2985 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
2986 strcpy (str
, no_name_func
);
2987 str
+= strlen (no_name_func
) + 1;
2988 for (i
= 0; i
< count
; i
++)
2990 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
2991 strcpy (str
, sv
[i
]);
2992 str
+= strlen (sv
[i
]) + 1;
2994 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
2996 /* Set the size and contents of .rtproc section. */
2997 s
->_raw_size
= size
;
2998 s
->contents
= rtproc
;
3000 /* Skip this section later on (I don't think this currently
3001 matters, but someday it might). */
3002 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
3031 /* A comparison routine used to sort .gptab entries. */
3034 gptab_compare (p1
, p2
)
3038 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
3039 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
3041 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
3044 /* We need to use a special link routine to handle the .reginfo and
3045 the .mdebug sections. We need to merge all instances of these
3046 sections together, not write them all out sequentially. */
3049 mips_elf_final_link (abfd
, info
)
3051 struct bfd_link_info
*info
;
3055 struct bfd_link_order
*p
;
3056 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
3057 asection
*rtproc_sec
;
3058 Elf32_RegInfo reginfo
;
3059 struct ecoff_debug_info debug
;
3060 const struct ecoff_debug_swap
*swap
3061 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3062 HDRR
*symhdr
= &debug
.symbolic_header
;
3063 PTR mdebug_handle
= NULL
;
3065 /* Drop the .options section, since it has special semantics which I
3066 haven't bothered to figure out. */
3067 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
3069 if (strcmp ((*secpp
)->name
, ".options") == 0)
3071 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
3072 if (p
->type
== bfd_indirect_link_order
)
3073 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
3074 (*secpp
)->link_order_head
= NULL
;
3075 *secpp
= (*secpp
)->next
;
3076 --abfd
->section_count
;
3081 /* Get a value for the GP register. */
3082 if (elf_gp (abfd
) == 0)
3084 struct bfd_link_hash_entry
*h
;
3086 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
3087 if (h
!= (struct bfd_link_hash_entry
*) NULL
3088 && h
->type
== bfd_link_hash_defined
)
3089 elf_gp (abfd
) = (h
->u
.def
.value
3090 + h
->u
.def
.section
->output_section
->vma
3091 + h
->u
.def
.section
->output_offset
);
3092 else if (info
->relocateable
)
3096 /* Make up a value. */
3098 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3101 && (strcmp (o
->name
, ".sbss") == 0
3102 || strcmp (o
->name
, ".sdata") == 0
3103 || strcmp (o
->name
, ".lit4") == 0
3104 || strcmp (o
->name
, ".lit8") == 0))
3107 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
3111 /* If the relocate_section function needs to do a reloc
3112 involving the GP value, it should make a reloc_dangerous
3113 callback to warn that GP is not defined. */
3117 /* Go through the sections and collect the .reginfo and .mdebug
3121 gptab_data_sec
= NULL
;
3122 gptab_bss_sec
= NULL
;
3123 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3125 if (strcmp (o
->name
, ".reginfo") == 0)
3127 memset (®info
, 0, sizeof reginfo
);
3129 /* We have found the .reginfo section in the output file.
3130 Look through all the link_orders comprising it and merge
3131 the information together. */
3132 for (p
= o
->link_order_head
;
3133 p
!= (struct bfd_link_order
*) NULL
;
3136 asection
*input_section
;
3138 Elf32_External_RegInfo ext
;
3141 if (p
->type
!= bfd_indirect_link_order
)
3143 if (p
->type
== bfd_fill_link_order
)
3148 input_section
= p
->u
.indirect
.section
;
3149 input_bfd
= input_section
->owner
;
3151 /* The linker emulation code has probably clobbered the
3152 size to be zero bytes. */
3153 if (input_section
->_raw_size
== 0)
3154 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3156 if (! bfd_get_section_contents (input_bfd
, input_section
,
3162 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
3164 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
3165 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
3166 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
3167 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
3168 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
3170 /* ri_gp_value is set by the function
3171 mips_elf_section_processing when the section is
3172 finally written out. */
3174 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3175 elf_link_input_bfd ignores this section. */
3176 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3179 /* Force the section size to the value we want. */
3180 o
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3182 /* Skip this section later on (I don't think this currently
3183 matters, but someday it might). */
3184 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3189 if (strcmp (o
->name
, ".mdebug") == 0)
3191 struct extsym_info einfo
;
3193 /* We have found the .mdebug section in the output file.
3194 Look through all the link_orders comprising it and merge
3195 the information together. */
3196 symhdr
->magic
= swap
->sym_magic
;
3197 /* FIXME: What should the version stamp be? */
3199 symhdr
->ilineMax
= 0;
3203 symhdr
->isymMax
= 0;
3204 symhdr
->ioptMax
= 0;
3205 symhdr
->iauxMax
= 0;
3207 symhdr
->issExtMax
= 0;
3210 symhdr
->iextMax
= 0;
3212 /* We accumulate the debugging information itself in the
3213 debug_info structure. */
3215 debug
.external_dnr
= NULL
;
3216 debug
.external_pdr
= NULL
;
3217 debug
.external_sym
= NULL
;
3218 debug
.external_opt
= NULL
;
3219 debug
.external_aux
= NULL
;
3221 debug
.ssext
= debug
.ssext_end
= NULL
;
3222 debug
.external_fdr
= NULL
;
3223 debug
.external_rfd
= NULL
;
3224 debug
.external_ext
= debug
.external_ext_end
= NULL
;
3226 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
3227 if (mdebug_handle
== (PTR
) NULL
)
3230 if (SGI_COMPAT (abfd
))
3236 static const char * const name
[] =
3237 { ".text", ".init", ".fini", ".data",
3238 ".rodata", ".sdata", ".sbss", ".bss" };
3239 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
3240 scRData
, scSData
, scSBss
, scBss
};
3243 esym
.cobol_main
= 0;
3247 esym
.asym
.iss
= issNil
;
3248 esym
.asym
.st
= stLocal
;
3249 esym
.asym
.reserved
= 0;
3250 esym
.asym
.index
= indexNil
;
3251 for (i
= 0; i
< 8; i
++)
3253 esym
.asym
.sc
= sc
[i
];
3254 s
= bfd_get_section_by_name (abfd
, name
[i
]);
3257 esym
.asym
.value
= s
->vma
;
3258 last
= s
->vma
+ s
->_raw_size
;
3261 esym
.asym
.value
= last
;
3263 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
3269 for (p
= o
->link_order_head
;
3270 p
!= (struct bfd_link_order
*) NULL
;
3273 asection
*input_section
;
3275 const struct ecoff_debug_swap
*input_swap
;
3276 struct ecoff_debug_info input_debug
;
3280 if (p
->type
!= bfd_indirect_link_order
)
3282 if (p
->type
== bfd_fill_link_order
)
3287 input_section
= p
->u
.indirect
.section
;
3288 input_bfd
= input_section
->owner
;
3290 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
3291 || (get_elf_backend_data (input_bfd
)
3292 ->elf_backend_ecoff_debug_swap
) == NULL
)
3294 /* I don't know what a non MIPS ELF bfd would be
3295 doing with a .mdebug section, but I don't really
3296 want to deal with it. */
3300 input_swap
= (get_elf_backend_data (input_bfd
)
3301 ->elf_backend_ecoff_debug_swap
);
3303 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
3305 /* The ECOFF linking code expects that we have already
3306 read in the debugging information and set up an
3307 ecoff_debug_info structure, so we do that now. */
3308 if (! mips_elf_read_ecoff_info (input_bfd
, input_section
,
3312 if (! (bfd_ecoff_debug_accumulate
3313 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
3314 &input_debug
, input_swap
, info
)))
3317 /* Loop through the external symbols. For each one with
3318 interesting information, try to find the symbol in
3319 the linker global hash table and save the information
3320 for the output external symbols. */
3321 eraw_src
= input_debug
.external_ext
;
3322 eraw_end
= (eraw_src
3323 + (input_debug
.symbolic_header
.iextMax
3324 * input_swap
->external_ext_size
));
3326 eraw_src
< eraw_end
;
3327 eraw_src
+= input_swap
->external_ext_size
)
3331 struct mips_elf_link_hash_entry
*h
;
3333 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
3334 if (ext
.asym
.sc
== scNil
3335 || ext
.asym
.sc
== scUndefined
3336 || ext
.asym
.sc
== scSUndefined
)
3339 name
= input_debug
.ssext
+ ext
.asym
.iss
;
3340 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
3341 name
, false, false, true);
3342 if (h
== NULL
|| h
->esym
.ifd
!= -2)
3348 < input_debug
.symbolic_header
.ifdMax
);
3349 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
3355 /* Free up the information we just read. */
3356 free (input_debug
.line
);
3357 free (input_debug
.external_dnr
);
3358 free (input_debug
.external_pdr
);
3359 free (input_debug
.external_sym
);
3360 free (input_debug
.external_opt
);
3361 free (input_debug
.external_aux
);
3362 free (input_debug
.ss
);
3363 free (input_debug
.ssext
);
3364 free (input_debug
.external_fdr
);
3365 free (input_debug
.external_rfd
);
3366 free (input_debug
.external_ext
);
3368 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3369 elf_link_input_bfd ignores this section. */
3370 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3373 if (SGI_COMPAT (abfd
) && info
->shared
)
3375 /* Create .rtproc section. */
3376 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
3377 if (rtproc_sec
== NULL
)
3379 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3382 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
3383 if (rtproc_sec
== NULL
3384 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
3385 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 12))
3389 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
3390 info
, rtproc_sec
, &debug
))
3394 /* Build the external symbol information. */
3397 einfo
.debug
= &debug
;
3399 einfo
.failed
= false;
3400 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
3401 mips_elf_output_extsym
,
3406 /* Set the size of the .mdebug section. */
3407 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
3409 /* Skip this section later on (I don't think this currently
3410 matters, but someday it might). */
3411 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3416 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
3418 const char *subname
;
3421 Elf32_External_gptab
*ext_tab
;
3424 /* The .gptab.sdata and .gptab.sbss sections hold
3425 information describing how the small data area would
3426 change depending upon the -G switch. These sections
3427 not used in executables files. */
3428 if (! info
->relocateable
)
3432 for (p
= o
->link_order_head
;
3433 p
!= (struct bfd_link_order
*) NULL
;
3436 asection
*input_section
;
3438 if (p
->type
!= bfd_indirect_link_order
)
3440 if (p
->type
== bfd_fill_link_order
)
3445 input_section
= p
->u
.indirect
.section
;
3447 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3448 elf_link_input_bfd ignores this section. */
3449 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3452 /* Skip this section later on (I don't think this
3453 currently matters, but someday it might). */
3454 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3456 /* Really remove the section. */
3457 for (secpp
= &abfd
->sections
;
3459 secpp
= &(*secpp
)->next
)
3461 *secpp
= (*secpp
)->next
;
3462 --abfd
->section_count
;
3467 /* There is one gptab for initialized data, and one for
3468 uninitialized data. */
3469 if (strcmp (o
->name
, ".gptab.sdata") == 0)
3471 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
3475 (*_bfd_error_handler
)
3476 ("%s: illegal section name `%s'",
3477 bfd_get_filename (abfd
), o
->name
);
3478 bfd_set_error (bfd_error_nonrepresentable_section
);
3482 /* The linker script always combines .gptab.data and
3483 .gptab.sdata into .gptab.sdata, and likewise for
3484 .gptab.bss and .gptab.sbss. It is possible that there is
3485 no .sdata or .sbss section in the output file, in which
3486 case we must change the name of the output section. */
3487 subname
= o
->name
+ sizeof ".gptab" - 1;
3488 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
3490 if (o
== gptab_data_sec
)
3491 o
->name
= ".gptab.data";
3493 o
->name
= ".gptab.bss";
3494 subname
= o
->name
+ sizeof ".gptab" - 1;
3495 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
3498 /* Set up the first entry. */
3500 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
3503 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
3504 tab
[0].gt_header
.gt_unused
= 0;
3506 /* Combine the input sections. */
3507 for (p
= o
->link_order_head
;
3508 p
!= (struct bfd_link_order
*) NULL
;
3511 asection
*input_section
;
3515 bfd_size_type gpentry
;
3517 if (p
->type
!= bfd_indirect_link_order
)
3519 if (p
->type
== bfd_fill_link_order
)
3524 input_section
= p
->u
.indirect
.section
;
3525 input_bfd
= input_section
->owner
;
3527 /* Combine the gptab entries for this input section one
3528 by one. We know that the input gptab entries are
3529 sorted by ascending -G value. */
3530 size
= bfd_section_size (input_bfd
, input_section
);
3532 for (gpentry
= sizeof (Elf32_External_gptab
);
3534 gpentry
+= sizeof (Elf32_External_gptab
))
3536 Elf32_External_gptab ext_gptab
;
3537 Elf32_gptab int_gptab
;
3543 if (! (bfd_get_section_contents
3544 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
3545 gpentry
, sizeof (Elf32_External_gptab
))))
3551 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
3553 val
= int_gptab
.gt_entry
.gt_g_value
;
3554 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
3557 for (look
= 1; look
< c
; look
++)
3559 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
3560 tab
[look
].gt_entry
.gt_bytes
+= add
;
3562 if (tab
[look
].gt_entry
.gt_g_value
== val
)
3568 Elf32_gptab
*new_tab
;
3571 /* We need a new table entry. */
3572 new_tab
= ((Elf32_gptab
*)
3573 bfd_realloc ((PTR
) tab
,
3574 (c
+ 1) * sizeof (Elf32_gptab
)));
3575 if (new_tab
== NULL
)
3581 tab
[c
].gt_entry
.gt_g_value
= val
;
3582 tab
[c
].gt_entry
.gt_bytes
= add
;
3584 /* Merge in the size for the next smallest -G
3585 value, since that will be implied by this new
3588 for (look
= 1; look
< c
; look
++)
3590 if (tab
[look
].gt_entry
.gt_g_value
< val
3592 || (tab
[look
].gt_entry
.gt_g_value
3593 > tab
[max
].gt_entry
.gt_g_value
)))
3597 tab
[c
].gt_entry
.gt_bytes
+=
3598 tab
[max
].gt_entry
.gt_bytes
;
3603 last
= int_gptab
.gt_entry
.gt_bytes
;
3606 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3607 elf_link_input_bfd ignores this section. */
3608 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3611 /* The table must be sorted by -G value. */
3613 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
3615 /* Swap out the table. */
3616 ext_tab
= ((Elf32_External_gptab
*)
3617 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
3618 if (ext_tab
== NULL
)
3624 for (i
= 0; i
< c
; i
++)
3625 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
3628 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
3629 o
->contents
= (bfd_byte
*) ext_tab
;
3631 /* Skip this section later on (I don't think this currently
3632 matters, but someday it might). */
3633 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3637 /* Invoke the regular ELF backend linker to do all the work. */
3638 if (! bfd_elf32_bfd_final_link (abfd
, info
))
3641 /* Now write out the computed sections. */
3643 if (reginfo_sec
!= (asection
*) NULL
)
3645 Elf32_External_RegInfo ext
;
3647 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
3648 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
3649 (file_ptr
) 0, sizeof ext
))
3653 if (mdebug_sec
!= (asection
*) NULL
)
3655 BFD_ASSERT (abfd
->output_has_begun
);
3656 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
3658 mdebug_sec
->filepos
))
3661 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
3664 if (gptab_data_sec
!= (asection
*) NULL
)
3666 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
3667 gptab_data_sec
->contents
,
3669 gptab_data_sec
->_raw_size
))
3673 if (gptab_bss_sec
!= (asection
*) NULL
)
3675 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
3676 gptab_bss_sec
->contents
,
3678 gptab_bss_sec
->_raw_size
))
3682 if (SGI_COMPAT (abfd
))
3684 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
3685 if (rtproc_sec
!= NULL
)
3687 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
3688 rtproc_sec
->contents
,
3690 rtproc_sec
->_raw_size
))
3698 /* Handle a MIPS ELF HI16 reloc. */
3701 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
3703 Elf_Internal_Rela
*relhi
;
3704 Elf_Internal_Rela
*rello
;
3711 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
3713 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
3716 addend
+= ((insn
& 0xffff) << 16) + addlo
;
3718 if ((addlo
& 0x8000) != 0)
3720 if ((addend
& 0x8000) != 0)
3723 bfd_put_32 (input_bfd
,
3724 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
3725 contents
+ relhi
->r_offset
);
3728 /* Handle a MIPS ELF local GOT16 reloc. */
3731 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
3736 Elf_Internal_Rela
*relhi
;
3737 Elf_Internal_Rela
*rello
;
3747 bfd_byte
*got_contents
;
3748 struct mips_got_info
*g
;
3750 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
3752 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
3755 addend
+= ((insn
& 0xffff) << 16) + addlo
;
3757 if ((addlo
& 0x8000) != 0)
3759 if ((addend
& 0x8000) != 0)
3762 /* Get a got entry representing requested hipage. */
3763 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
3764 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
3765 BFD_ASSERT (g
!= NULL
);
3767 local_gotno
= g
->local_gotno
;
3768 got_contents
= sgot
->contents
;
3769 hipage
= addend
& 0xffff0000;
3771 for (i
= MIPS_RESERVED_GOTNO
; i
< local_gotno
; i
++)
3773 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
3774 if (hipage
== (address
& 0xffff0000))
3776 if (address
== (bfd_vma
) 0)
3778 bfd_put_32 (input_bfd
, hipage
, got_contents
+ i
* 4);
3783 BFD_ASSERT (i
< local_gotno
);
3785 if (i
== local_gotno
)
3786 (*_bfd_error_handler
)
3787 ("ELF MIPS linker: more got entries are needed for hipage: %x",
3791 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
3792 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
3793 contents
+ relhi
->r_offset
);
3796 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
3799 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
3801 Elf_Internal_Rela
*rel
;
3807 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3808 bfd_put_32 (input_bfd
,
3809 (insn
& 0xffff0000) | (offset
& 0xffff),
3810 contents
+ rel
->r_offset
);
3813 /* Relocate a MIPS ELF section. */
3816 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3817 contents
, relocs
, local_syms
, local_sections
)
3819 struct bfd_link_info
*info
;
3821 asection
*input_section
;
3823 Elf_Internal_Rela
*relocs
;
3824 Elf_Internal_Sym
*local_syms
;
3825 asection
**local_sections
;
3827 Elf_Internal_Shdr
*symtab_hdr
;
3830 asection
*sgot
, *sreloc
, *scpt
;
3833 Elf_Internal_Rela
*rel
;
3834 Elf_Internal_Rela
*relend
;
3835 struct mips_got_info
*g
;
3837 dynobj
= elf_hash_table (info
)->dynobj
;
3838 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3842 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
3845 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
3848 if (elf_bad_symtab (input_bfd
))
3850 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
3855 locsymcount
= symtab_hdr
->sh_info
;
3856 extsymoff
= symtab_hdr
->sh_info
;
3859 gp
= _bfd_get_gp_value (output_bfd
);
3862 relend
= relocs
+ input_section
->reloc_count
;
3863 for (; rel
< relend
; rel
++)
3866 reloc_howto_type
*howto
;
3867 unsigned long r_symndx
;
3869 struct elf_link_hash_entry
*h
;
3871 Elf_Internal_Sym
*sym
;
3872 bfd_reloc_status_type r
;
3874 r_type
= ELF32_R_TYPE (rel
->r_info
);
3875 if (r_type
< 0 || r_type
>= (int) R_MIPS_max
)
3877 bfd_set_error (bfd_error_bad_value
);
3880 howto
= elf_mips_howto_table
+ r_type
;
3883 && (r_type
== R_MIPS_CALL16
3884 || r_type
== R_MIPS_GOT16
3885 || r_type
== R_MIPS_CALL_HI16
3886 || r_type
== R_MIPS_CALL_LO16
3887 || r_type
== R_MIPS_GOT_HI16
3888 || r_type
== R_MIPS_GOT_LO16
))
3890 /* We need the .got section. */
3893 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3894 BFD_ASSERT (sgot
!= NULL
);
3895 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
3896 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
3897 BFD_ASSERT (g
!= NULL
);
3901 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3903 /* Mix in the change in GP address for a GP relative reloc. */
3904 if (r_type
!= R_MIPS_GPREL16
3905 && r_type
!= R_MIPS_LITERAL
3906 && r_type
!= R_MIPS_GPREL32
)
3912 if (! ((*info
->callbacks
->reloc_dangerous
)
3914 "GP relative relocation when GP not defined",
3915 input_bfd
, input_section
,
3918 /* Only give the error once per link. */
3920 _bfd_set_gp_value (output_bfd
, gp
);
3923 if (r_symndx
< extsymoff
3924 || (elf_bad_symtab (input_bfd
)
3925 && local_sections
[r_symndx
] != NULL
))
3927 /* This is a relocation against a section. The current
3928 addend in the instruction is the difference between
3929 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
3930 must change this to be the difference between the
3931 final definition (which will end up in RELOCATION)
3932 and the GP value of OUTPUT_BFD (which is in GP). */
3933 addend
= elf_gp (input_bfd
) - gp
;
3935 else if (! info
->relocateable
)
3937 /* We are doing a final link. The current addend in the
3938 instruction is simply the desired offset into the
3939 symbol (normally zero). We want the instruction to
3940 hold the difference between the final definition of
3941 the symbol (which will end up in RELOCATION) and the
3942 GP value of OUTPUT_BFD (which is in GP). */
3947 /* We are generating relocateable output, and we aren't
3948 going to define this symbol, so we just leave the
3949 instruction alone. */
3957 if (info
->relocateable
)
3959 /* This is a relocateable link. We don't have to change
3960 anything, unless the reloc is against a section symbol,
3961 in which case we have to adjust according to where the
3962 section symbol winds up in the output section. */
3963 if (r_symndx
>= locsymcount
3964 || (elf_bad_symtab (input_bfd
)
3965 && local_sections
[r_symndx
] == NULL
))
3969 sym
= local_syms
+ r_symndx
;
3970 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
3974 sec
= local_sections
[r_symndx
];
3976 /* It would be logical to add sym->st_value here,
3977 but Irix 5 sometimes generates a garbage symbol
3979 addend
+= sec
->output_offset
;
3981 /* If this is HI16 or GOT16 with an associated LO16,
3982 adjust the addend accordingly. Otherwise, just
3984 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
3985 r
= _bfd_relocate_contents (howto
, input_bfd
,
3987 contents
+ rel
->r_offset
);
3990 Elf_Internal_Rela
*lorel
;
3992 /* As a GNU extension, permit an arbitrary
3993 number of R_MIPS_HI16 relocs before the
3994 R_MIPS_LO16 reloc. This permits gcc to emit
3995 the HI and LO relocs itself. */
3996 if (r_type
== R_MIPS_GOT16
)
4000 for (lorel
= rel
+ 1;
4002 && (ELF32_R_TYPE (lorel
->r_info
)
4008 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
4010 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
4015 r
= _bfd_relocate_contents (howto
, input_bfd
,
4017 contents
+ rel
->r_offset
);
4027 /* This is a final link. */
4029 if (r_symndx
< extsymoff
4030 || (elf_bad_symtab (input_bfd
)
4031 && local_sections
[r_symndx
] != NULL
))
4034 sym
= local_syms
+ r_symndx
;
4035 sec
= local_sections
[r_symndx
];
4036 relocation
= (sec
->output_section
->vma
4037 + sec
->output_offset
);
4039 /* It would be logical to always add sym->st_value here,
4040 but Irix 5 sometimes generates a garbage symbol
4042 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4043 relocation
+= sym
->st_value
;
4050 indx
= r_symndx
- extsymoff
;
4051 h
= elf_sym_hashes (input_bfd
)[indx
];
4052 while (h
->root
.type
== bfd_link_hash_indirect
4053 || h
->root
.type
== bfd_link_hash_warning
)
4054 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4055 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
4059 if (! ((*info
->callbacks
->reloc_dangerous
)
4061 "_gp_disp used when GP not defined",
4062 input_bfd
, input_section
,
4065 /* Only give the error once per link. */
4067 _bfd_set_gp_value (output_bfd
, gp
);
4072 sec
= input_section
;
4073 if (sec
->output_section
!= NULL
)
4076 + sec
->output_section
->vma
4077 + sec
->output_offset
));
4079 relocation
= gp
- rel
->r_offset
;
4080 if (r_type
== R_MIPS_LO16
)
4084 else if (h
->root
.type
== bfd_link_hash_defined
4085 || h
->root
.type
== bfd_link_hash_defweak
)
4087 sec
= h
->root
.u
.def
.section
;
4088 if (sec
->output_section
== NULL
)
4091 relocation
= (h
->root
.u
.def
.value
4092 + sec
->output_section
->vma
4093 + sec
->output_offset
);
4095 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4097 else if (info
->shared
&& ! info
->symbolic
)
4099 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
4101 /* If this is a dynamic link, we should have created
4102 a _DYNAMIC_LINK symbol in
4103 mips_elf_create_dynamic_sections. Otherwise, we
4104 should define the symbol with a value of 0.
4105 FIXME: It should probably get into the symbol
4106 table somehow as well. */
4107 BFD_ASSERT (! info
->shared
);
4108 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
4109 ".dynamic") == NULL
);
4114 if (! ((*info
->callbacks
->undefined_symbol
)
4115 (info
, h
->root
.root
.string
, input_bfd
,
4116 input_section
, rel
->r_offset
)))
4122 if (r_type
== R_MIPS_HI16
)
4124 Elf_Internal_Rela
*lorel
;
4126 /* As a GNU extension, permit an arbitrary number of
4127 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
4128 This permits gcc to emit the HI and LO relocs itself. */
4129 for (lorel
= rel
+ 1;
4131 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
4135 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
4137 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
4138 contents
, relocation
+ addend
);
4142 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4143 contents
, rel
->r_offset
,
4144 relocation
, addend
);
4146 else if (r_type
== R_MIPS_GOT16
&& local
)
4148 /* GOT16 must also have an associated LO16 in the local
4149 case. In this case, the addend is extracted and the
4150 section in which the referenced object is determined.
4151 Then the final address of the object is computed and
4152 the GOT entry for the hipage (an aligned 64kb chunk)
4153 is added to .got section if needed. The offset field
4154 of the GOT16-relocated instruction is replaced by the
4155 index of this GOT entry for the hipage. */
4156 if ((rel
+ 1) < relend
4157 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
4159 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
,
4162 relocation
+ addend
);
4166 r
= bfd_reloc_outofrange
;
4168 else if (r_type
== R_MIPS_CALL16
4169 || r_type
== R_MIPS_GOT16
4170 || r_type
== R_MIPS_CALL_LO16
4171 || r_type
== R_MIPS_GOT_LO16
)
4175 /* This symbol must be registered as a global symbol
4176 having the corresponding got entry. */
4177 BFD_ASSERT (h
->got_offset
!= (bfd_vma
) -1);
4179 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
4180 BFD_ASSERT (g
->local_gotno
<= offset
4181 && offset
< sgot
->_raw_size
);
4182 bfd_put_32 (output_bfd
, relocation
+ addend
,
4183 sgot
->contents
+ offset
);
4184 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
4186 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
4190 else if (r_type
== R_MIPS_CALL_HI16
4191 || r_type
== R_MIPS_GOT_HI16
)
4195 /* This must be a global symbol with a got entry. The
4196 next reloc must be the corresponding LO16 reloc. */
4197 BFD_ASSERT (h
!= NULL
&& h
->got_offset
!= (bfd_vma
) -1);
4198 BFD_ASSERT ((rel
+ 1) < relend
);
4199 BFD_ASSERT (ELF32_R_TYPE ((rel
+ 1)->r_info
)
4200 == (r_type
== R_MIPS_CALL_HI16
4202 : R_MIPS_GOT_LO16
));
4204 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
4205 BFD_ASSERT (g
->local_gotno
<= offset
4206 && offset
< sgot
->_raw_size
);
4207 bfd_put_32 (output_bfd
, relocation
+ addend
,
4208 sgot
->contents
+ offset
);
4209 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
4211 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
4215 else if (r_type
== R_MIPS_REL32
4216 || r_type
== R_MIPS_32
)
4218 Elf_Internal_Rel outrel
;
4219 Elf32_crinfo cptrel
;
4224 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
4226 && (input_section
->flags
& SEC_ALLOC
) != 0)
4228 /* When generating a shared object, these
4229 relocations are copied into the output file to be
4230 resolved at run time. */
4233 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
4234 BFD_ASSERT (sreloc
!= NULL
);
4237 outrel
.r_offset
= (rel
->r_offset
4238 + input_section
->output_section
->vma
4239 + input_section
->output_offset
);
4241 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4244 && (! info
->symbolic
4245 || (h
->elf_link_hash_flags
4246 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4248 BFD_ASSERT (h
->dynindx
!= -1);
4249 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
4250 sec
= input_section
;
4257 sec
= local_sections
[r_symndx
];
4260 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
4262 == bfd_link_hash_defweak
));
4263 sec
= h
->root
.u
.def
.section
;
4265 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
4267 else if (sec
== NULL
|| sec
->owner
== NULL
)
4269 bfd_set_error (bfd_error_bad_value
);
4276 osec
= sec
->output_section
;
4277 indx
= elf_section_data (osec
)->dynindx
;
4282 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
4283 addend
+= relocation
;
4286 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
4287 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
4288 (((Elf32_External_Rel
*)
4290 + sreloc
->reloc_count
));
4291 ++sreloc
->reloc_count
;
4293 if (SGI_COMPAT (output_bfd
))
4298 /* Make an entry of compact relocation info. */
4299 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
4300 cptrel
.vaddr
= (rel
->r_offset
4301 + input_section
->output_section
->vma
4302 + input_section
->output_offset
);
4303 if (r_type
== R_MIPS_REL32
)
4304 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
4306 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
4307 mips_elf_set_cr_dist2to (cptrel
, 0);
4308 cptrel
.konst
= addend
;
4310 cr
= (scpt
->contents
4311 + sizeof (Elf32_External_compact_rel
));
4312 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4313 ((Elf32_External_crinfo
*) cr
4314 + scpt
->reloc_count
));
4315 ++scpt
->reloc_count
;
4318 /* This reloc will be computed at runtime, so
4319 there's no need to do anything now. */
4323 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4324 contents
, rel
->r_offset
,
4325 relocation
, addend
);
4328 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4329 contents
, rel
->r_offset
,
4330 relocation
, addend
);
4332 if (SGI_COMPAT (abfd
)
4334 && (input_section
->flags
& SEC_ALLOC
) != 0)
4336 Elf32_crinfo cptrel
;
4339 /* Make an entry of compact relocation info. */
4340 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
4341 cptrel
.vaddr
= (rel
->r_offset
4342 + input_section
->output_section
->vma
4343 + input_section
->output_offset
);
4348 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
4349 /* XXX How should we set dist2to in this case. */
4350 mips_elf_set_cr_dist2to (cptrel
, 8);
4351 cptrel
.konst
= addend
+ relocation
;
4352 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
4353 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4354 ((Elf32_External_crinfo
*) cr
4355 + scpt
->reloc_count
));
4356 ++scpt
->reloc_count
;
4359 case R_MIPS_GPREL16
:
4360 case R_MIPS_LITERAL
:
4361 case R_MIPS_GPREL32
:
4362 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
4363 cptrel
.konst
= gp
- cptrel
.vaddr
;
4364 mips_elf_set_cr_dist2to (cptrel
, 4);
4365 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
4366 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4367 ((Elf32_External_crinfo
*) cr
4368 + scpt
->reloc_count
));
4369 ++scpt
->reloc_count
;
4378 if (r
!= bfd_reloc_ok
)
4383 case bfd_reloc_outofrange
:
4385 case bfd_reloc_overflow
:
4390 name
= h
->root
.root
.string
;
4393 name
= bfd_elf_string_from_elf_section (input_bfd
,
4394 symtab_hdr
->sh_link
,
4399 name
= bfd_section_name (input_bfd
, sec
);
4401 if (! ((*info
->callbacks
->reloc_overflow
)
4402 (info
, name
, howto
->name
, (bfd_vma
) 0,
4403 input_bfd
, input_section
, rel
->r_offset
)))
4414 /* Functions for the dynamic linker. */
4416 /* The name of the dynamic interpreter. This is put in the .interp
4419 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
4421 /* Create dynamic sections when linking against a dynamic object. */
4424 mips_elf_create_dynamic_sections (abfd
, info
)
4426 struct bfd_link_info
*info
;
4428 struct elf_link_hash_entry
*h
;
4430 register asection
*s
;
4431 const char * const *namep
;
4433 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4436 /* Mips ABI requests the .dynamic section to be read only. */
4437 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4440 if (! bfd_set_section_flags (abfd
, s
, flags
))
4444 /* We need to create .got section. */
4445 if (! mips_elf_create_got_section (abfd
, info
))
4448 /* Create .stub section. */
4449 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
4451 s
= bfd_make_section (abfd
, ".stub");
4453 || ! bfd_set_section_flags (abfd
, s
, flags
)
4454 || ! bfd_set_section_alignment (abfd
, s
, 2))
4458 if (SGI_COMPAT (abfd
))
4460 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
4463 if (! (_bfd_generic_link_add_one_symbol
4464 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
4465 (bfd_vma
) 0, (const char *) NULL
, false,
4466 get_elf_backend_data (abfd
)->collect
,
4467 (struct bfd_link_hash_entry
**) &h
)))
4469 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
4470 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4471 h
->type
= STT_SECTION
;
4473 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4477 /* We need to create a .compact_rel section. */
4478 if (! mips_elf_create_compact_rel_section (abfd
, info
))
4481 /* Change aligments of some sections. */
4482 s
= bfd_get_section_by_name (abfd
, ".hash");
4484 bfd_set_section_alignment (abfd
, s
, 4);
4485 s
= bfd_get_section_by_name (abfd
, ".dynsym");
4487 bfd_set_section_alignment (abfd
, s
, 4);
4488 s
= bfd_get_section_by_name (abfd
, ".dynstr");
4490 bfd_set_section_alignment (abfd
, s
, 4);
4491 s
= bfd_get_section_by_name (abfd
, ".reginfo");
4493 bfd_set_section_alignment (abfd
, s
, 4);
4494 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4496 bfd_set_section_alignment (abfd
, s
, 4);
4502 if (! (_bfd_generic_link_add_one_symbol
4503 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
4504 (bfd_vma
) 0, (const char *) NULL
, false,
4505 get_elf_backend_data (abfd
)->collect
,
4506 (struct bfd_link_hash_entry
**) &h
)))
4508 h
->elf_link_hash_flags
^=~ ELF_LINK_NON_ELF
;
4509 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4510 h
->type
= STT_SECTION
;
4512 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4519 /* Create the .compact_rel section. */
4522 mips_elf_create_compact_rel_section (abfd
, info
)
4524 struct bfd_link_info
*info
;
4527 register asection
*s
;
4529 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
4531 flags
= SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_READONLY
;
4533 s
= bfd_make_section (abfd
, ".compact_rel");
4535 || ! bfd_set_section_flags (abfd
, s
, flags
)
4536 || ! bfd_set_section_alignment (abfd
, s
, 2))
4539 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
4545 /* Create the .got section to hold the global offset table. */
4548 mips_elf_create_got_section (abfd
, info
)
4550 struct bfd_link_info
*info
;
4553 register asection
*s
;
4554 struct elf_link_hash_entry
*h
;
4555 struct mips_got_info
*g
;
4557 /* This function may be called more than once. */
4558 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
4561 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
4563 s
= bfd_make_section (abfd
, ".got");
4565 || ! bfd_set_section_flags (abfd
, s
, flags
)
4566 || ! bfd_set_section_alignment (abfd
, s
, 4))
4569 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
4570 linker script because we don't want to define the symbol if we
4571 are not creating a global offset table. */
4573 if (! (_bfd_generic_link_add_one_symbol
4574 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
4575 (bfd_vma
) 0, (const char *) NULL
, false,
4576 get_elf_backend_data (abfd
)->collect
,
4577 (struct bfd_link_hash_entry
**) &h
)))
4579 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
4580 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4581 h
->type
= STT_OBJECT
;
4584 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4587 /* The first several global offset table entries are reserved. */
4588 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
4590 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
4591 sizeof (struct mips_got_info
));
4594 g
->global_gotsym
= 0;
4595 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
4596 if (elf_section_data (s
) == NULL
)
4599 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
4600 if (elf_section_data (s
) == NULL
)
4603 elf_section_data (s
)->tdata
= (PTR
) g
;
4608 /* Look through the relocs for a section during the first phase, and
4609 allocate space in the global offset table. */
4612 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
4614 struct bfd_link_info
*info
;
4616 const Elf_Internal_Rela
*relocs
;
4619 Elf_Internal_Shdr
*symtab_hdr
;
4620 struct elf_link_hash_entry
**sym_hashes
;
4621 struct mips_got_info
*g
;
4623 const Elf_Internal_Rela
*rel
;
4624 const Elf_Internal_Rela
*rel_end
;
4628 if (info
->relocateable
)
4631 dynobj
= elf_hash_table (info
)->dynobj
;
4632 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4633 sym_hashes
= elf_sym_hashes (abfd
);
4634 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
4639 rel_end
= relocs
+ sec
->reloc_count
;
4640 for (rel
= relocs
; rel
< rel_end
; rel
++)
4642 unsigned long r_symndx
;
4643 struct elf_link_hash_entry
*h
;
4645 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4647 if (r_symndx
< extsymoff
)
4650 h
= sym_hashes
[r_symndx
- extsymoff
];
4652 /* Some relocs require a global offset table. */
4655 switch (ELF32_R_TYPE (rel
->r_info
))
4659 case R_MIPS_CALL_HI16
:
4660 case R_MIPS_CALL_LO16
:
4661 case R_MIPS_GOT_HI16
:
4662 case R_MIPS_GOT_LO16
:
4663 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
4664 if (! mips_elf_create_got_section (dynobj
, info
))
4673 switch (ELF32_R_TYPE (rel
->r_info
))
4676 case R_MIPS_CALL_HI16
:
4677 case R_MIPS_CALL_LO16
:
4678 /* This symbol requires a global offset table entry. */
4681 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4682 BFD_ASSERT (sgot
!= NULL
);
4683 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4684 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4685 BFD_ASSERT (g
!= NULL
);
4688 BFD_ASSERT (h
!= NULL
);
4690 /* Make sure this symbol is output as a dynamic symbol. */
4691 if (h
->dynindx
== -1)
4693 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4697 if (h
->got_offset
!= (bfd_vma
) -1)
4699 /* We have already allocated space in the .got. */
4703 /* Note the index of the first global got symbol in .dynsym. */
4704 if (g
->global_gotsym
== 0
4705 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
4706 g
->global_gotsym
= h
->dynindx
;
4708 /* Make this symbol to have the corresponding got entry. */
4711 /* We need a stub, not a plt entry for the undefined
4712 function. But we record it as if it needs plt. See
4713 elf_adjust_dynamic_symbol in elflink.h. */
4714 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
4720 case R_MIPS_GOT_HI16
:
4721 case R_MIPS_GOT_LO16
:
4722 /* This symbol requires a global offset table entry. */
4725 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4726 BFD_ASSERT (sgot
!= NULL
);
4727 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4728 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4729 BFD_ASSERT (g
!= NULL
);
4734 /* Make sure this symbol is output as a dynamic symbol. */
4735 if (h
->dynindx
== -1)
4737 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4741 if (h
->got_offset
!= (bfd_vma
) -1)
4743 /* We have already allocated space in the .got. */
4746 /* Note the index of the first global got symbol in
4748 if (g
->global_gotsym
== 0
4749 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
4750 g
->global_gotsym
= h
->dynindx
;
4752 /* Make this symbol to be the global got symbol. */
4760 if ((info
->shared
|| h
!= NULL
)
4761 && (sec
->flags
& SEC_ALLOC
) != 0)
4763 /* When creating a shared object, we must copy these
4764 reloc types into the output file as R_MIPS_REL32
4765 relocs. We create the .rel.dyn reloc section in
4766 dynobj and make room for this reloc. */
4769 const char *name
= ".rel.dyn";
4771 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4774 sreloc
= bfd_make_section (dynobj
, name
);
4776 || ! bfd_set_section_flags (dynobj
, sreloc
,
4782 || ! bfd_set_section_alignment (dynobj
, sreloc
, 4))
4785 /* Add a null element. */
4786 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
4787 ++sreloc
->reloc_count
;
4792 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
4795 struct mips_elf_link_hash_entry
*hmips
;
4797 /* We only need to copy this reloc if the symbol is
4798 defined in a dynamic object. */
4799 hmips
= (struct mips_elf_link_hash_entry
*) h
;
4800 ++hmips
->mips_32_relocs
;
4804 if (SGI_COMPAT (abfd
))
4805 mips_elf_hash_table (info
)->compact_rel_size
+=
4806 sizeof (Elf32_External_crinfo
);
4811 case R_MIPS_GPREL16
:
4812 case R_MIPS_LITERAL
:
4813 case R_MIPS_GPREL32
:
4814 if (SGI_COMPAT (abfd
))
4815 mips_elf_hash_table (info
)->compact_rel_size
+=
4816 sizeof (Elf32_External_crinfo
);
4827 /* Adjust a symbol defined by a dynamic object and referenced by a
4828 regular object. The current definition is in some section of the
4829 dynamic object, but we're not including those sections. We have to
4830 change the definition to something the rest of the link can
4834 mips_elf_adjust_dynamic_symbol (info
, h
)
4835 struct bfd_link_info
*info
;
4836 struct elf_link_hash_entry
*h
;
4839 struct mips_elf_link_hash_entry
*hmips
;
4842 dynobj
= elf_hash_table (info
)->dynobj
;
4844 /* Make sure we know what is going on here. */
4845 BFD_ASSERT (dynobj
!= NULL
4846 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
4847 || h
->weakdef
!= NULL
4848 || ((h
->elf_link_hash_flags
4849 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4850 && (h
->elf_link_hash_flags
4851 & ELF_LINK_HASH_REF_REGULAR
) != 0
4852 && (h
->elf_link_hash_flags
4853 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
4855 /* If this symbol is defined in a dynamic object, we need to copy
4856 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
4858 hmips
= (struct mips_elf_link_hash_entry
*) h
;
4859 if (! info
->relocateable
4860 && hmips
->mips_32_relocs
!= 0
4861 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4863 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
4864 BFD_ASSERT (s
!= NULL
);
4866 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
4869 /* For a function, create a stub, if needed. */
4870 if (h
->type
== STT_FUNC
4871 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4873 if (! elf_hash_table (info
)->dynamic_sections_created
)
4876 /* If this symbol is not defined in a regular file, then set
4877 the symbol to the stub location. This is required to make
4878 function pointers compare as equal between the normal
4879 executable and the shared library. */
4880 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4882 /* We need .stub section. */
4883 s
= bfd_get_section_by_name (dynobj
, ".stub");
4884 BFD_ASSERT (s
!= NULL
);
4886 h
->root
.u
.def
.section
= s
;
4887 h
->root
.u
.def
.value
= s
->_raw_size
;
4889 /* XXX Write this stub address somewhere. */
4890 h
->plt_offset
= s
->_raw_size
;
4892 /* Make room for this stub code. */
4893 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
4895 /* The last half word of the stub will be filled with the index
4896 of this symbol in .dynsym section. */
4901 /* If this is a weak symbol, and there is a real definition, the
4902 processor independent code will have arranged for us to see the
4903 real definition first, and we can just use the same value. */
4904 if (h
->weakdef
!= NULL
)
4906 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
4907 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
4908 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
4909 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
4913 /* This is a reference to a symbol defined by a dynamic object which
4914 is not a function. */
4919 /* Set the sizes of the dynamic sections. */
4922 mips_elf_size_dynamic_sections (output_bfd
, info
)
4924 struct bfd_link_info
*info
;
4930 struct mips_got_info
*g
;
4932 dynobj
= elf_hash_table (info
)->dynobj
;
4933 BFD_ASSERT (dynobj
!= NULL
);
4935 if (elf_hash_table (info
)->dynamic_sections_created
)
4937 /* Set the contents of the .interp section to the interpreter. */
4940 s
= bfd_get_section_by_name (dynobj
, ".interp");
4941 BFD_ASSERT (s
!= NULL
);
4942 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4943 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4947 /* Recompute the size of .got for local entires (reserved and
4948 hipages) if needed. To estimate it, get the upper bound of total
4949 size of loadable sections. */
4950 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4954 bfd_size_type loadable_size
= 0;
4955 bfd_size_type local_gotno
;
4958 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4959 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4960 BFD_ASSERT (g
!= NULL
);
4962 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
4963 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
4965 if ((s
->flags
& SEC_ALLOC
) == 0)
4967 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
4970 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
4972 /* Assume there are two loadable segments consisting of
4973 contiguous sections. Is 5 enough? */
4974 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
4975 g
->local_gotno
= local_gotno
;
4976 sgot
->_raw_size
+= local_gotno
* 4;
4979 /* The check_relocs and adjust_dynamic_symbol entry points have
4980 determined the sizes of the various dynamic sections. Allocate
4983 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4988 /* It's OK to base decisions on the section name, because none
4989 of the dynobj section names depend upon the input files. */
4990 name
= bfd_get_section_name (dynobj
, s
);
4992 if ((s
->flags
& SEC_IN_MEMORY
) == 0)
4997 if (strncmp (name
, ".rel", 4) == 0)
4999 if (s
->_raw_size
== 0)
5005 /* If this relocation section applies to a read only
5006 section, then we probably need a DT_TEXTREL entry.
5007 If the relocation section is .rel.dyn, we always
5008 assert a DT_TEXTREL entry rather than testing whether
5009 there exists a relocation to a read only section or
5011 target
= bfd_get_section_by_name (output_bfd
, name
+ 4);
5012 if ((target
!= NULL
&& (target
->flags
& SEC_READONLY
) != 0)
5013 || strcmp (name
, ".rel.dyn") == 0)
5016 /* We use the reloc_count field as a counter if we need
5017 to copy relocs into the output file. */
5018 if (strcmp (name
, ".rel.dyn") != 0)
5022 else if (strncmp (name
, ".got", 4) == 0)
5026 BFD_ASSERT (elf_section_data (s
) != NULL
);
5027 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
5028 BFD_ASSERT (g
!= NULL
);
5030 /* Fix the size of .got section for the correspondence of
5031 global symbols and got entries. This adds some useless
5032 got entries. Is this required by ABI really? */
5033 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
5034 s
->_raw_size
+= i
* 4;
5036 else if (strncmp (name
, ".stub", 5) == 0)
5038 /* Irix rld assumes that the function stub isn't at the end
5039 of .text section. So put a dummy. XXX */
5040 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
5042 else if (SGI_COMPAT (output_bfd
)
5043 && strncmp (name
, ".compact_rel", 12) == 0)
5044 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
5045 else if (strncmp (name
, ".init", 5) != 0)
5047 /* It's not one of our sections, so don't allocate space. */
5055 for (spp
= &s
->output_section
->owner
->sections
;
5056 *spp
!= s
->output_section
;
5057 spp
= &(*spp
)->next
)
5059 *spp
= s
->output_section
->next
;
5060 --s
->output_section
->owner
->section_count
;
5065 /* Allocate memory for the section contents. */
5066 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
5067 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
5069 bfd_set_error (bfd_error_no_memory
);
5072 memset (s
->contents
, 0, s
->_raw_size
);
5075 if (elf_hash_table (info
)->dynamic_sections_created
)
5077 /* Add some entries to the .dynamic section. We fill in the
5078 values later, in elf_mips_finish_dynamic_sections, but we
5079 must add the entries now so that we get the correct size for
5080 the .dynamic section. The DT_DEBUG entry is filled in by the
5081 dynamic linker and used by the debugger. */
5084 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
5090 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
5094 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
5097 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
5099 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
5102 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
5105 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
5109 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
5112 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
5115 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
5117 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
5120 s
= bfd_get_section_by_name (dynobj
, ".liblist");
5121 BFD_ASSERT (s
!= NULL
);
5123 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
5127 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
5130 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
5134 /* Time stamps in executable files are a bad idea. */
5135 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
5140 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
5145 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
5149 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
5152 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
5155 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
5158 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
5161 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
5164 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
5167 #if 0 /* (SGI_COMPAT) */
5168 if (! bfd_get_section_by_name (dynobj
, ".init"))
5169 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
5172 if (! bfd_get_section_by_name (dynobj
, ".fini"))
5173 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
5178 /* If we use dynamic linking, we generate a section symbol for each
5179 output section. These are local symbols, which means that they
5180 must come first in the dynamic symbol table.
5181 That means we must increment the dynamic symbol index of every
5182 other dynamic symbol. */
5184 const char * const *namep
;
5186 bfd_size_type strindex
;
5187 struct bfd_strtab_hash
*dynstr
;
5188 struct mips_got_info
*g
;
5190 if (elf_hash_table (info
)->dynamic_sections_created
)
5192 if (SGI_COMPAT (output_bfd
))
5194 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
5195 elf_link_hash_traverse (elf_hash_table (info
),
5196 mips_elf_adjust_dynindx
,
5198 elf_hash_table (info
)->dynsymcount
+= c
;
5200 dynstr
= elf_hash_table (info
)->dynstr
;
5201 BFD_ASSERT (dynstr
!= NULL
);
5203 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
5207 s
= bfd_get_section_by_name (output_bfd
, *namep
);
5209 elf_section_data (s
)->dynindx
= i
;
5211 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
5212 if (strindex
== (bfd_size_type
) -1)
5215 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
5220 c
= bfd_count_sections (output_bfd
);
5221 elf_link_hash_traverse (elf_hash_table (info
),
5222 mips_elf_adjust_dynindx
,
5224 elf_hash_table (info
)->dynsymcount
+= c
;
5226 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
5228 elf_section_data (s
)->dynindx
= i
;
5229 /* These symbols will have no names, so we don't need to
5230 fiddle with dynstr_index. */
5235 s
= bfd_get_section_by_name (dynobj
, ".got");
5236 BFD_ASSERT (s
!= NULL
);
5237 BFD_ASSERT (elf_section_data (s
) != NULL
);
5238 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
5239 BFD_ASSERT (g
!= NULL
);
5241 /* If there are no global got symbols, fake the last symbol so for
5243 if (g
->global_gotsym
)
5244 g
->global_gotsym
+= c
;
5246 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
5252 /* Increment the index of a dynamic symbol by a given amount. Called
5253 via elf_link_hash_traverse. */
5256 mips_elf_adjust_dynindx (h
, cparg
)
5257 struct elf_link_hash_entry
*h
;
5260 unsigned int *cp
= (unsigned int *) cparg
;
5262 if (h
->dynindx
!= -1)
5267 /* Finish up dynamic symbol handling. We set the contents of various
5268 dynamic sections here. */
5271 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
5273 struct bfd_link_info
*info
;
5274 struct elf_link_hash_entry
*h
;
5275 Elf_Internal_Sym
*sym
;
5280 struct mips_got_info
*g
;
5283 dynobj
= elf_hash_table (info
)->dynobj
;
5284 gval
= sym
->st_value
;
5286 if (h
->plt_offset
!= (bfd_vma
) -1)
5290 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
5292 /* This symbol has a stub. Set it up. */
5294 BFD_ASSERT (h
->dynindx
!= -1);
5296 s
= bfd_get_section_by_name (dynobj
, ".stub");
5297 BFD_ASSERT (s
!= NULL
);
5299 /* Fill the stub. */
5301 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
5303 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
5306 /* FIXME: Can h->dynindex be more than 64K? */
5307 if (h
->dynindx
& 0xffff0000)
5310 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
5312 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
5314 BFD_ASSERT (h
->plt_offset
<= s
->_raw_size
);
5315 memcpy (s
->contents
+ h
->plt_offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
5317 /* Mark the symbol as undefined. plt_offset != -1 occurs
5318 only for the referenced symbol. */
5319 sym
->st_shndx
= SHN_UNDEF
;
5321 /* The run-time linker uses the st_value field of the symbol
5322 to reset the global offset table entry for this external
5323 to its stub address when unlinking a shared object. */
5324 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt_offset
;
5325 sym
->st_value
= gval
;
5328 BFD_ASSERT (h
->dynindx
!= -1);
5330 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5331 BFD_ASSERT (sgot
!= NULL
);
5332 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5333 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5334 BFD_ASSERT (g
!= NULL
);
5336 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
5338 bfd_size_type offset
;
5340 /* This symbol has an entry in the global offset table. Set its
5341 value to the corresponding got entry, if needed. */
5342 if (h
->got_offset
== (bfd_vma
) -1)
5344 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5345 BFD_ASSERT (g
->local_gotno
* 4 <= offset
5346 && offset
< sgot
->_raw_size
);
5347 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
5351 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
5352 name
= h
->root
.root
.string
;
5353 if (strcmp (name
, "_DYNAMIC") == 0
5354 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
5355 sym
->st_shndx
= SHN_ABS
;
5356 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
5358 sym
->st_shndx
= SHN_ABS
;
5359 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5362 else if (SGI_COMPAT (output_bfd
))
5364 if (strcmp (name
, "_gp_disp") == 0)
5366 sym
->st_shndx
= SHN_ABS
;
5367 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5368 sym
->st_value
= elf_gp (output_bfd
);
5370 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
5371 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
5373 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5374 sym
->st_other
= STO_PROTECTED
;
5376 sym
->st_shndx
= SHN_MIPS_DATA
;
5378 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
5380 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5381 sym
->st_other
= STO_PROTECTED
;
5382 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
5383 sym
->st_shndx
= SHN_ABS
;
5385 else if (sym
->st_shndx
!= SHN_UNDEF
)
5387 if (h
->type
== STT_FUNC
)
5388 sym
->st_shndx
= SHN_MIPS_TEXT
;
5389 else if (h
->type
== STT_OBJECT
)
5390 sym
->st_shndx
= SHN_MIPS_DATA
;
5397 /* Finish up the dynamic sections. */
5400 mips_elf_finish_dynamic_sections (output_bfd
, info
)
5402 struct bfd_link_info
*info
;
5407 struct mips_got_info
*g
;
5409 dynobj
= elf_hash_table (info
)->dynobj
;
5411 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5413 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5414 BFD_ASSERT (sgot
!= NULL
);
5416 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5417 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5418 BFD_ASSERT (g
!= NULL
);
5420 if (elf_hash_table (info
)->dynamic_sections_created
)
5422 Elf32_External_Dyn
*dyncon
, *dynconend
;
5424 BFD_ASSERT (sdyn
!= NULL
);
5426 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5427 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
5428 for (; dyncon
< dynconend
; dyncon
++)
5430 Elf_Internal_Dyn dyn
;
5435 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5443 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5444 BFD_ASSERT (s
!= NULL
);
5445 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
5446 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5450 /* Rewrite DT_STRSZ. */
5452 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
5453 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5459 case DT_MIPS_CONFLICT
:
5462 case DT_MIPS_LIBLIST
:
5465 s
= bfd_get_section_by_name (output_bfd
, name
);
5466 BFD_ASSERT (s
!= NULL
);
5467 dyn
.d_un
.d_ptr
= s
->vma
;
5468 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5471 case DT_MIPS_RLD_VERSION
:
5472 dyn
.d_un
.d_val
= 1; /* XXX */
5473 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5477 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
5478 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5481 case DT_MIPS_CONFLICTNO
:
5483 elemsize
= sizeof (Elf32_Conflict
);
5486 case DT_MIPS_LIBLISTNO
:
5488 elemsize
= sizeof (Elf32_Lib
);
5490 s
= bfd_get_section_by_name (output_bfd
, name
);
5493 if (s
->_cooked_size
!= 0)
5494 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5496 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5501 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5504 case DT_MIPS_TIME_STAMP
:
5505 time ((time_t *) &dyn
.d_un
.d_val
);
5506 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5509 case DT_MIPS_ICHECKSUM
:
5513 case DT_MIPS_IVERSION
:
5517 case DT_MIPS_BASE_ADDRESS
:
5518 s
= output_bfd
->sections
;
5519 BFD_ASSERT (s
!= NULL
);
5520 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
5521 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5524 case DT_MIPS_LOCAL_GOTNO
:
5525 dyn
.d_un
.d_val
= g
->local_gotno
;
5526 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5529 case DT_MIPS_SYMTABNO
:
5531 elemsize
= sizeof (Elf32_External_Sym
);
5532 s
= bfd_get_section_by_name (output_bfd
, name
);
5533 BFD_ASSERT (s
!= NULL
);
5535 if (s
->_cooked_size
!= 0)
5536 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5538 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5539 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5542 case DT_MIPS_UNREFEXTNO
:
5544 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
5545 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5548 case DT_MIPS_GOTSYM
:
5549 dyn
.d_un
.d_val
= g
->global_gotsym
;
5550 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5553 case DT_MIPS_HIPAGENO
:
5554 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
5555 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5562 /* The first entry of the global offset table will be filled at
5563 runtime. The second entry will be used by some runtime loaders.
5564 This isn't the case of Irix rld. */
5565 if (sgot
->_raw_size
> 0)
5567 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
5568 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
5571 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
5578 Elf_Internal_Sym sym
;
5581 const char * const * namep
= mips_elf_dynsym_sec_names
;
5582 Elf32_compact_rel cpt
;
5584 /* Set up the section symbols for the output sections. SGI sets
5585 the STT_NOTYPE attribute for these symbols. Should we do so? */
5587 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
5588 if (sdynsym
!= NULL
)
5590 if (SGI_COMPAT (output_bfd
))
5594 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
5598 while ((name
= *namep
++) != NULL
)
5600 s
= bfd_get_section_by_name (output_bfd
, name
);
5603 sym
.st_value
= s
->vma
;
5604 dindx
= elf_section_data (s
)->dynindx
;
5605 last
= s
->vma
+ s
->_raw_size
;
5609 sym
.st_value
= last
;
5613 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
5618 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
5620 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
5621 (((Elf32_External_Sym
*)
5626 /* Set the sh_info field of the output .dynsym section to
5627 the index of the first global symbol. */
5628 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
5629 SIZEOF_MIPS_DYNSYM_SECNAMES
;
5635 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
5638 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
5642 sym
.st_value
= s
->vma
;
5644 indx
= elf_section_data (s
)->this_idx
;
5645 BFD_ASSERT (indx
> 0);
5646 sym
.st_shndx
= indx
;
5648 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
5649 (((Elf32_External_Sym
*)
5651 + elf_section_data (s
)->dynindx
));
5654 /* Set the sh_info field of the output .dynsym section to
5655 the index of the first global symbol. */
5656 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
5657 bfd_count_sections (output_bfd
) + 1;
5661 if (SGI_COMPAT (output_bfd
))
5663 /* Write .compact_rel section out. */
5664 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5668 cpt
.num
= s
->reloc_count
;
5670 cpt
.offset
= (s
->output_section
->filepos
5671 + sizeof (Elf32_External_compact_rel
));
5674 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
5675 ((Elf32_External_compact_rel
*)
5678 /* Clean up a dummy stub function entry in .text. */
5679 s
= bfd_get_section_by_name (dynobj
, ".stub");
5682 file_ptr dummy_offset
;
5684 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
5685 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
5686 memset (s
->contents
+ dummy_offset
, 0,
5687 MIPS_FUNCTION_STUB_SIZE
);
5692 /* Clean up a first relocation in .rel.dyn. */
5693 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5695 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
5701 /* This is almost identical to bfd_generic_get_... except that some
5702 MIPS relocations need to be handled specially. Sigh. */
5705 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
5706 relocateable
, symbols
)
5708 struct bfd_link_info
*link_info
;
5709 struct bfd_link_order
*link_order
;
5711 boolean relocateable
;
5714 /* Get enough memory to hold the stuff */
5715 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
5716 asection
*input_section
= link_order
->u
.indirect
.section
;
5718 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
5719 arelent
**reloc_vector
= NULL
;
5725 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
5726 if (reloc_vector
== NULL
&& reloc_size
!= 0)
5729 /* read in the section */
5730 if (!bfd_get_section_contents (input_bfd
,
5734 input_section
->_raw_size
))
5737 /* We're not relaxing the section, so just copy the size info */
5738 input_section
->_cooked_size
= input_section
->_raw_size
;
5739 input_section
->reloc_done
= true;
5741 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
5745 if (reloc_count
< 0)
5748 if (reloc_count
> 0)
5753 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
5756 struct bfd_hash_entry
*h
;
5757 struct bfd_link_hash_entry
*lh
;
5758 /* Skip all this stuff if we aren't mixing formats. */
5759 if (abfd
&& input_bfd
5760 && abfd
->xvec
== input_bfd
->xvec
)
5764 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
5765 lh
= (struct bfd_link_hash_entry
*) h
;
5772 case bfd_link_hash_undefined
:
5773 case bfd_link_hash_undefweak
:
5774 case bfd_link_hash_common
:
5777 case bfd_link_hash_defined
:
5778 case bfd_link_hash_defweak
:
5780 gp
= lh
->u
.def
.value
;
5782 case bfd_link_hash_indirect
:
5783 case bfd_link_hash_warning
:
5785 /* @@FIXME ignoring warning for now */
5787 case bfd_link_hash_new
:
5796 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
5799 char *error_message
= (char *) NULL
;
5800 bfd_reloc_status_type r
;
5802 /* Specific to MIPS: Deal with relocation types that require
5803 knowing the gp of the output bfd. */
5804 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
5805 if (bfd_is_abs_section (sym
->section
) && abfd
)
5807 /* The special_function wouldn't get called anyways. */
5811 /* The gp isn't there; let the special function code
5812 fall over on its own. */
5814 else if ((*parent
)->howto
->special_function
5815 == mips_elf_gprel16_reloc
)
5817 /* bypass special_function call */
5818 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
5819 relocateable
, (PTR
) data
, gp
);
5820 goto skip_bfd_perform_relocation
;
5822 /* end mips specific stuff */
5824 r
= bfd_perform_relocation (input_bfd
,
5828 relocateable
? abfd
: (bfd
*) NULL
,
5830 skip_bfd_perform_relocation
:
5834 asection
*os
= input_section
->output_section
;
5836 /* A partial link, so keep the relocs */
5837 os
->orelocation
[os
->reloc_count
] = *parent
;
5841 if (r
!= bfd_reloc_ok
)
5845 case bfd_reloc_undefined
:
5846 if (!((*link_info
->callbacks
->undefined_symbol
)
5847 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
5848 input_bfd
, input_section
, (*parent
)->address
)))
5851 case bfd_reloc_dangerous
:
5852 BFD_ASSERT (error_message
!= (char *) NULL
);
5853 if (!((*link_info
->callbacks
->reloc_dangerous
)
5854 (link_info
, error_message
, input_bfd
, input_section
,
5855 (*parent
)->address
)))
5858 case bfd_reloc_overflow
:
5859 if (!((*link_info
->callbacks
->reloc_overflow
)
5860 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
5861 (*parent
)->howto
->name
, (*parent
)->addend
,
5862 input_bfd
, input_section
, (*parent
)->address
)))
5865 case bfd_reloc_outofrange
:
5874 if (reloc_vector
!= NULL
)
5875 free (reloc_vector
);
5879 if (reloc_vector
!= NULL
)
5880 free (reloc_vector
);
5883 #define bfd_elf32_bfd_get_relocated_section_contents \
5884 elf32_mips_get_relocated_section_contents
5886 /* ECOFF swapping routines. These are used when dealing with the
5887 .mdebug section, which is in the ECOFF debugging format. */
5888 static const struct ecoff_debug_swap mips_elf_ecoff_debug_swap
=
5890 /* Symbol table magic number. */
5892 /* Alignment of debugging information. E.g., 4. */
5894 /* Sizes of external symbolic information. */
5895 sizeof (struct hdr_ext
),
5896 sizeof (struct dnr_ext
),
5897 sizeof (struct pdr_ext
),
5898 sizeof (struct sym_ext
),
5899 sizeof (struct opt_ext
),
5900 sizeof (struct fdr_ext
),
5901 sizeof (struct rfd_ext
),
5902 sizeof (struct ext_ext
),
5903 /* Functions to swap in external symbolic data. */
5912 _bfd_ecoff_swap_tir_in
,
5913 _bfd_ecoff_swap_rndx_in
,
5914 /* Functions to swap out external symbolic data. */
5923 _bfd_ecoff_swap_tir_out
,
5924 _bfd_ecoff_swap_rndx_out
,
5925 /* Function to read in symbolic data. */
5926 mips_elf_read_ecoff_info
5929 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
5930 #define TARGET_LITTLE_NAME "elf32-littlemips"
5931 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
5932 #define TARGET_BIG_NAME "elf32-bigmips"
5933 #define ELF_ARCH bfd_arch_mips
5934 #define ELF_MACHINE_CODE EM_MIPS
5935 #define ELF_MAXPAGESIZE 0x10000
5936 #define elf_backend_collect true
5937 #define elf_backend_type_change_ok true
5938 #define elf_info_to_howto 0
5939 #define elf_info_to_howto_rel mips_info_to_howto_rel
5940 #define elf_backend_sym_is_global mips_elf_sym_is_global
5941 #define elf_backend_object_p mips_elf_object_p
5942 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
5943 #define elf_backend_fake_sections mips_elf_fake_sections
5944 #define elf_backend_section_from_bfd_section \
5945 mips_elf_section_from_bfd_section
5946 #define elf_backend_section_processing mips_elf_section_processing
5947 #define elf_backend_symbol_processing mips_elf_symbol_processing
5948 #define elf_backend_additional_program_headers \
5949 mips_elf_additional_program_headers
5950 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
5951 #define elf_backend_final_write_processing \
5952 mips_elf_final_write_processing
5953 #define elf_backend_ecoff_debug_swap &mips_elf_ecoff_debug_swap
5955 #define bfd_elf32_bfd_is_local_label mips_elf_is_local_label
5956 #define bfd_elf32_find_nearest_line mips_elf_find_nearest_line
5958 #define bfd_elf32_bfd_link_hash_table_create \
5959 mips_elf_link_hash_table_create
5960 #define bfd_elf32_bfd_final_link mips_elf_final_link
5961 #define bfd_elf32_bfd_copy_private_bfd_data \
5962 mips_elf_copy_private_bfd_data
5963 #define bfd_elf32_bfd_merge_private_bfd_data \
5964 mips_elf_merge_private_bfd_data
5965 #define bfd_elf32_bfd_set_private_flags mips_elf_set_private_flags
5966 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
5967 #define elf_backend_create_dynamic_sections \
5968 mips_elf_create_dynamic_sections
5969 #define elf_backend_check_relocs mips_elf_check_relocs
5970 #define elf_backend_adjust_dynamic_symbol \
5971 mips_elf_adjust_dynamic_symbol
5972 #define elf_backend_size_dynamic_sections \
5973 mips_elf_size_dynamic_sections
5974 #define elf_backend_relocate_section mips_elf_relocate_section
5975 #define elf_backend_finish_dynamic_symbol \
5976 mips_elf_finish_dynamic_symbol
5977 #define elf_backend_finish_dynamic_sections \
5978 mips_elf_finish_dynamic_sections
5980 #include "elf32-target.h"