1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
4 Most of the information added by Ian Lance Taylor, Cygnus Support,
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 /* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
24 different MIPS ELF from other targets. This matters when linking.
25 This file supports both, switching at runtime. */
35 /* Get the ECOFF swapping routines. */
37 #include "coff/symconst.h"
38 #include "coff/internal.h"
39 #include "coff/ecoff.h"
40 #include "coff/mips.h"
42 #include "ecoffswap.h"
44 static bfd_reloc_status_type mips_elf_hi16_reloc
PARAMS ((bfd
*abfd
,
51 static bfd_reloc_status_type mips_elf_got16_reloc
PARAMS ((bfd
*abfd
,
58 static bfd_reloc_status_type mips_elf_lo16_reloc
PARAMS ((bfd
*abfd
,
65 static bfd_reloc_status_type mips_elf_gprel16_reloc
PARAMS ((bfd
*abfd
,
72 static bfd_reloc_status_type mips_elf_gprel32_reloc
PARAMS ((bfd
*abfd
,
79 static reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
80 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
81 static void mips_info_to_howto_rel
82 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
83 static void bfd_mips_elf32_swap_gptab_in
84 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
85 static void bfd_mips_elf32_swap_gptab_out
86 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
87 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
88 static boolean mips_elf_object_p
PARAMS ((bfd
*));
89 static boolean mips_elf_create_procedure_table
90 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
91 struct ecoff_debug_info
*));
92 static int mips_elf_additional_program_headers
PARAMS ((bfd
*));
93 static boolean mips_elf_modify_segment_map
PARAMS ((bfd
*));
94 static void mips_elf_final_write_processing
95 PARAMS ((bfd
*, boolean
));
96 static boolean mips_elf_set_private_flags
PARAMS ((bfd
*, flagword
));
97 static boolean mips_elf_copy_private_bfd_data
PARAMS ((bfd
*, bfd
*));
98 static boolean mips_elf_merge_private_bfd_data
PARAMS ((bfd
*, bfd
*));
99 static boolean mips_elf_section_from_shdr
100 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, char *));
101 static boolean mips_elf_fake_sections
102 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, asection
*));
103 static boolean mips_elf_section_from_bfd_section
104 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, asection
*, int *));
105 static boolean mips_elf_section_processing
106 PARAMS ((bfd
*, Elf32_Internal_Shdr
*));
107 static void mips_elf_symbol_processing
PARAMS ((bfd
*, asymbol
*));
108 static boolean mips_elf_read_ecoff_info
109 PARAMS ((bfd
*, asection
*, struct ecoff_debug_info
*));
110 static boolean mips_elf_is_local_label
111 PARAMS ((bfd
*, asymbol
*));
112 static boolean mips_elf_find_nearest_line
113 PARAMS ((bfd
*, asection
*, asymbol
**, bfd_vma
, const char **,
114 const char **, unsigned int *));
115 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
116 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
117 static struct bfd_link_hash_table
*mips_elf_link_hash_table_create
119 static int gptab_compare
PARAMS ((const void *, const void *));
120 static boolean mips_elf_final_link
121 PARAMS ((bfd
*, struct bfd_link_info
*));
122 static void mips_elf_relocate_hi16
123 PARAMS ((bfd
*, Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_byte
*,
125 static void mips_elf_relocate_got_local
126 PARAMS ((bfd
*, bfd
*, asection
*, Elf_Internal_Rela
*,
127 Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
128 static void mips_elf_relocate_global_got
129 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
130 static boolean mips_elf_adjust_dynindx
131 PARAMS ((struct elf_link_hash_entry
*, PTR
));
132 static boolean mips_elf_relocate_section
133 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
134 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
135 static boolean mips_elf_create_dynamic_sections
136 PARAMS ((bfd
*, struct bfd_link_info
*));
137 static boolean mips_elf_create_compact_rel_section
138 PARAMS ((bfd
*, struct bfd_link_info
*));
139 static boolean mips_elf_create_got_section
140 PARAMS ((bfd
*, struct bfd_link_info
*));
141 static boolean mips_elf_check_relocs
142 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
143 const Elf_Internal_Rela
*));
144 static boolean mips_elf_adjust_dynamic_symbol
145 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
146 static boolean mips_elf_size_dynamic_sections
147 PARAMS ((bfd
*, struct bfd_link_info
*));
148 static boolean mips_elf_finish_dynamic_symbol
149 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
150 Elf_Internal_Sym
*));
151 static boolean mips_elf_finish_dynamic_sections
152 PARAMS ((bfd
*, struct bfd_link_info
*));
153 static boolean mips_elf_add_symbol_hook
154 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
155 const char **, flagword
*, asection
**, bfd_vma
*));
156 static bfd_reloc_status_type mips_elf_final_gp
157 PARAMS ((bfd
*, asymbol
*, boolean
, char **));
158 static bfd_byte
*elf32_mips_get_relocated_section_contents
159 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
160 bfd_byte
*, boolean
, asymbol
**));
162 /* This is true for Irix 5 executables, false for normal MIPS ELF ABI
163 executables. FIXME: At the moment, we default to always generating
164 Irix 5 executables. */
166 #define SGI_COMPAT(abfd) (1)
168 /* This structure is used to hold .got information when linking. It
169 is stored in the tdata field of the bfd_elf_section_data structure. */
173 /* The symbol index of the first global .got symbol. */
174 unsigned long global_gotsym
;
175 /* The number of local .got entries. */
176 unsigned int local_gotno
;
179 /* The number of local .got entries we reserve. */
180 #define MIPS_RESERVED_GOTNO (2)
182 /* Instructions which appear in a stub. For some reason the stub is
183 slightly different on an SGI system. */
184 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
185 #define STUB_LW(abfd) \
187 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
188 : 0x8f998000) /* lw t9,0x8000(gp) */
189 #define STUB_MOVE 0x03e07825 /* move t7,ra */
190 #define STUB_JALR 0x0320f809 /* jal t9 */
191 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
192 #define MIPS_FUNCTION_STUB_SIZE (16)
194 /* Names of sections which appear in the .dynsym section in an Irix 5
197 static const char * const mips_elf_dynsym_sec_names
[] =
210 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
211 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
213 /* The number of entries in mips_elf_dynsym_sec_names which go in the
216 #define MIPS_TEXT_DYNSYM_SECNO (3)
218 /* The names of the runtime procedure table symbols used on Irix 5. */
220 static const char * const mips_elf_dynsym_rtproc_names
[] =
223 "_procedure_string_table",
224 "_procedure_table_size",
228 /* These structures are used to generate the .compact_rel section on
233 unsigned long id1
; /* Always one? */
234 unsigned long num
; /* Number of compact relocation entries. */
235 unsigned long id2
; /* Always two? */
236 unsigned long offset
; /* The file offset of the first relocation. */
237 unsigned long reserved0
; /* Zero? */
238 unsigned long reserved1
; /* Zero? */
247 bfd_byte reserved0
[4];
248 bfd_byte reserved1
[4];
249 } Elf32_External_compact_rel
;
253 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
254 unsigned int rtype
: 4; /* Relocation types. See below. */
255 unsigned int dist2to
: 8;
256 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
257 unsigned long konst
; /* KONST field. See below. */
258 unsigned long vaddr
; /* VADDR to be relocated. */
263 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
264 unsigned int rtype
: 4; /* Relocation types. See below. */
265 unsigned int dist2to
: 8;
266 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
267 unsigned long konst
; /* KONST field. See below. */
275 } Elf32_External_crinfo
;
281 } Elf32_External_crinfo2
;
283 /* These are the constants used to swap the bitfields in a crinfo. */
285 #define CRINFO_CTYPE (0x1)
286 #define CRINFO_CTYPE_SH (31)
287 #define CRINFO_RTYPE (0xf)
288 #define CRINFO_RTYPE_SH (27)
289 #define CRINFO_DIST2TO (0xff)
290 #define CRINFO_DIST2TO_SH (19)
291 #define CRINFO_RELVADDR (0x7ffff)
292 #define CRINFO_RELVADDR_SH (0)
294 /* A compact relocation info has long (3 words) or short (2 words)
295 formats. A short format doesn't have VADDR field and relvaddr
296 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
297 #define CRF_MIPS_LONG 1
298 #define CRF_MIPS_SHORT 0
300 /* There are 4 types of compact relocation at least. The value KONST
301 has different meaning for each type:
304 CT_MIPS_REL32 Address in data
305 CT_MIPS_WORD Address in word (XXX)
306 CT_MIPS_GPHI_LO GP - vaddr
307 CT_MIPS_JMPAD Address to jump
310 #define CRT_MIPS_REL32 0xa
311 #define CRT_MIPS_WORD 0xb
312 #define CRT_MIPS_GPHI_LO 0xc
313 #define CRT_MIPS_JMPAD 0xd
315 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
316 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
317 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
318 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
320 static void bfd_elf32_swap_compact_rel_out
321 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
322 static void bfd_elf32_swap_crinfo_out
323 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
325 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
330 R_MIPS_16
, R_MIPS_32
,
331 R_MIPS_REL32
, R_MIPS_26
,
332 R_MIPS_HI16
, R_MIPS_LO16
,
333 R_MIPS_GPREL16
, R_MIPS_LITERAL
,
334 R_MIPS_GOT16
, R_MIPS_PC16
,
335 R_MIPS_CALL16
, R_MIPS_GPREL32
,
336 /* The remaining relocs are defined on Irix, although they are not
337 in the MIPS ELF ABI. */
338 R_MIPS_UNUSED1
, R_MIPS_UNUSED2
,
340 R_MIPS_SHIFT5
, R_MIPS_SHIFT6
,
341 R_MIPS_64
, R_MIPS_GOT_DISP
,
342 R_MIPS_GOT_PAGE
, R_MIPS_GOT_OFST
,
343 R_MIPS_GOT_HI16
, R_MIPS_GOT_LO16
,
344 R_MIPS_SUB
, R_MIPS_INSERT_A
,
345 R_MIPS_INSERT_B
, R_MIPS_DELETE
,
346 R_MIPS_HIGHER
, R_MIPS_HIGHEST
,
347 R_MIPS_CALL_HI16
, R_MIPS_CALL_LO16
,
351 static reloc_howto_type elf_mips_howto_table
[] =
354 HOWTO (R_MIPS_NONE
, /* type */
356 0, /* size (0 = byte, 1 = short, 2 = long) */
358 false, /* pc_relative */
360 complain_overflow_dont
, /* complain_on_overflow */
361 bfd_elf_generic_reloc
, /* special_function */
362 "R_MIPS_NONE", /* name */
363 false, /* partial_inplace */
366 false), /* pcrel_offset */
368 /* 16 bit relocation. */
369 HOWTO (R_MIPS_16
, /* type */
371 1, /* size (0 = byte, 1 = short, 2 = long) */
373 false, /* pc_relative */
375 complain_overflow_bitfield
, /* complain_on_overflow */
376 bfd_elf_generic_reloc
, /* special_function */
377 "R_MIPS_16", /* name */
378 true, /* partial_inplace */
379 0xffff, /* src_mask */
380 0xffff, /* dst_mask */
381 false), /* pcrel_offset */
383 /* 32 bit relocation. */
384 HOWTO (R_MIPS_32
, /* type */
386 2, /* size (0 = byte, 1 = short, 2 = long) */
388 false, /* pc_relative */
390 complain_overflow_bitfield
, /* complain_on_overflow */
391 bfd_elf_generic_reloc
, /* special_function */
392 "R_MIPS_32", /* name */
393 true, /* partial_inplace */
394 0xffffffff, /* src_mask */
395 0xffffffff, /* dst_mask */
396 false), /* pcrel_offset */
398 /* 32 bit symbol relative relocation. */
399 HOWTO (R_MIPS_REL32
, /* type */
401 2, /* size (0 = byte, 1 = short, 2 = long) */
403 false, /* pc_relative */
405 complain_overflow_bitfield
, /* complain_on_overflow */
406 bfd_elf_generic_reloc
, /* special_function */
407 "R_MIPS_REL32", /* name */
408 true, /* partial_inplace */
409 0xffffffff, /* src_mask */
410 0xffffffff, /* dst_mask */
411 false), /* pcrel_offset */
413 /* 26 bit branch address. */
414 HOWTO (R_MIPS_26
, /* type */
416 2, /* size (0 = byte, 1 = short, 2 = long) */
418 false, /* pc_relative */
420 complain_overflow_dont
, /* complain_on_overflow */
421 /* This needs complex overflow
422 detection, because the upper four
423 bits must match the PC. */
424 bfd_elf_generic_reloc
, /* special_function */
425 "R_MIPS_26", /* name */
426 true, /* partial_inplace */
427 0x3ffffff, /* src_mask */
428 0x3ffffff, /* dst_mask */
429 false), /* pcrel_offset */
431 /* High 16 bits of symbol value. */
432 HOWTO (R_MIPS_HI16
, /* type */
434 2, /* size (0 = byte, 1 = short, 2 = long) */
436 false, /* pc_relative */
438 complain_overflow_dont
, /* complain_on_overflow */
439 mips_elf_hi16_reloc
, /* special_function */
440 "R_MIPS_HI16", /* name */
441 true, /* partial_inplace */
442 0xffff, /* src_mask */
443 0xffff, /* dst_mask */
444 false), /* pcrel_offset */
446 /* Low 16 bits of symbol value. */
447 HOWTO (R_MIPS_LO16
, /* type */
449 2, /* size (0 = byte, 1 = short, 2 = long) */
451 false, /* pc_relative */
453 complain_overflow_dont
, /* complain_on_overflow */
454 mips_elf_lo16_reloc
, /* special_function */
455 "R_MIPS_LO16", /* name */
456 true, /* partial_inplace */
457 0xffff, /* src_mask */
458 0xffff, /* dst_mask */
459 false), /* pcrel_offset */
461 /* GP relative reference. */
462 HOWTO (R_MIPS_GPREL16
, /* type */
464 2, /* size (0 = byte, 1 = short, 2 = long) */
466 false, /* pc_relative */
468 complain_overflow_signed
, /* complain_on_overflow */
469 mips_elf_gprel16_reloc
, /* special_function */
470 "R_MIPS_GPREL16", /* name */
471 true, /* partial_inplace */
472 0xffff, /* src_mask */
473 0xffff, /* dst_mask */
474 false), /* pcrel_offset */
476 /* Reference to literal section. */
477 HOWTO (R_MIPS_LITERAL
, /* type */
479 2, /* size (0 = byte, 1 = short, 2 = long) */
481 false, /* pc_relative */
483 complain_overflow_signed
, /* complain_on_overflow */
484 mips_elf_gprel16_reloc
, /* special_function */
485 "R_MIPS_LITERAL", /* name */
486 true, /* partial_inplace */
487 0xffff, /* src_mask */
488 0xffff, /* dst_mask */
489 false), /* pcrel_offset */
491 /* Reference to global offset table. */
492 HOWTO (R_MIPS_GOT16
, /* type */
494 2, /* size (0 = byte, 1 = short, 2 = long) */
496 false, /* pc_relative */
498 complain_overflow_signed
, /* complain_on_overflow */
499 mips_elf_got16_reloc
, /* special_function */
500 "R_MIPS_GOT16", /* name */
501 false, /* partial_inplace */
503 0xffff, /* dst_mask */
504 false), /* pcrel_offset */
506 /* 16 bit PC relative reference. */
507 HOWTO (R_MIPS_PC16
, /* type */
509 2, /* size (0 = byte, 1 = short, 2 = long) */
511 true, /* pc_relative */
513 complain_overflow_signed
, /* complain_on_overflow */
514 bfd_elf_generic_reloc
, /* special_function */
515 "R_MIPS_PC16", /* name */
516 true, /* partial_inplace */
517 0xffff, /* src_mask */
518 0xffff, /* dst_mask */
519 false), /* pcrel_offset */
521 /* 16 bit call through global offset table. */
522 /* FIXME: This is not handled correctly. */
523 HOWTO (R_MIPS_CALL16
, /* type */
525 2, /* size (0 = byte, 1 = short, 2 = long) */
527 false, /* pc_relative */
529 complain_overflow_signed
, /* complain_on_overflow */
530 bfd_elf_generic_reloc
, /* special_function */
531 "R_MIPS_CALL16", /* name */
532 false, /* partial_inplace */
534 0xffff, /* dst_mask */
535 false), /* pcrel_offset */
537 /* 32 bit GP relative reference. */
538 HOWTO (R_MIPS_GPREL32
, /* type */
540 2, /* size (0 = byte, 1 = short, 2 = long) */
542 false, /* pc_relative */
544 complain_overflow_bitfield
, /* complain_on_overflow */
545 mips_elf_gprel32_reloc
, /* special_function */
546 "R_MIPS_GPREL32", /* name */
547 true, /* partial_inplace */
548 0xffffffff, /* src_mask */
549 0xffffffff, /* dst_mask */
550 false), /* pcrel_offset */
552 /* The remaining relocs are defined on Irix 5, although they are
553 not defined by the ABI. */
558 /* A 5 bit shift field. */
559 HOWTO (R_MIPS_SHIFT5
, /* type */
561 2, /* size (0 = byte, 1 = short, 2 = long) */
563 false, /* pc_relative */
565 complain_overflow_bitfield
, /* complain_on_overflow */
566 bfd_elf_generic_reloc
, /* special_function */
567 "R_MIPS_SHIFT5", /* name */
568 true, /* partial_inplace */
569 0x000007c0, /* src_mask */
570 0x000007c0, /* dst_mask */
571 false), /* pcrel_offset */
573 /* A 6 bit shift field. */
574 /* FIXME: This is not handled correctly; a special function is
575 needed to put the most significant bit in the right place. */
576 HOWTO (R_MIPS_SHIFT6
, /* type */
578 2, /* size (0 = byte, 1 = short, 2 = long) */
580 false, /* pc_relative */
582 complain_overflow_bitfield
, /* complain_on_overflow */
583 bfd_elf_generic_reloc
, /* special_function */
584 "R_MIPS_SHIFT6", /* name */
585 true, /* partial_inplace */
586 0x000007c4, /* src_mask */
587 0x000007c4, /* dst_mask */
588 false), /* pcrel_offset */
590 /* A 64 bit relocation. Presumably not used in 32 bit ELF. */
593 /* Displacement in the global offset table. */
594 /* FIXME: Not handled correctly. */
595 HOWTO (R_MIPS_GOT_DISP
, /* type */
597 2, /* size (0 = byte, 1 = short, 2 = long) */
599 false, /* pc_relative */
601 complain_overflow_bitfield
, /* complain_on_overflow */
602 bfd_elf_generic_reloc
, /* special_function */
603 "R_MIPS_GOT_DISP", /* name */
604 true, /* partial_inplace */
605 0x0000ffff, /* src_mask */
606 0x0000ffff, /* dst_mask */
607 false), /* pcrel_offset */
609 /* Displacement to page pointer in the global offset table. */
610 /* FIXME: Not handled correctly. */
611 HOWTO (R_MIPS_GOT_PAGE
, /* type */
613 2, /* size (0 = byte, 1 = short, 2 = long) */
615 false, /* pc_relative */
617 complain_overflow_bitfield
, /* complain_on_overflow */
618 bfd_elf_generic_reloc
, /* special_function */
619 "R_MIPS_GOT_PAGE", /* name */
620 true, /* partial_inplace */
621 0x0000ffff, /* src_mask */
622 0x0000ffff, /* dst_mask */
623 false), /* pcrel_offset */
625 /* Offset from page pointer in the global offset table. */
626 /* FIXME: Not handled correctly. */
627 HOWTO (R_MIPS_GOT_OFST
, /* type */
629 2, /* size (0 = byte, 1 = short, 2 = long) */
631 false, /* pc_relative */
633 complain_overflow_bitfield
, /* complain_on_overflow */
634 bfd_elf_generic_reloc
, /* special_function */
635 "R_MIPS_GOT_OFST", /* name */
636 true, /* partial_inplace */
637 0x0000ffff, /* src_mask */
638 0x0000ffff, /* dst_mask */
639 false), /* pcrel_offset */
641 /* High 16 bits of displacement in global offset table. */
642 /* FIXME: Not handled correctly. */
643 HOWTO (R_MIPS_GOT_HI16
, /* type */
645 2, /* size (0 = byte, 1 = short, 2 = long) */
647 false, /* pc_relative */
649 complain_overflow_dont
, /* complain_on_overflow */
650 bfd_elf_generic_reloc
, /* special_function */
651 "R_MIPS_GOT_HI16", /* name */
652 true, /* partial_inplace */
653 0x0000ffff, /* src_mask */
654 0x0000ffff, /* dst_mask */
655 false), /* pcrel_offset */
657 /* Low 16 bits of displacement in global offset table. */
658 /* FIXME: Not handled correctly. */
659 HOWTO (R_MIPS_GOT_LO16
, /* type */
661 2, /* size (0 = byte, 1 = short, 2 = long) */
663 false, /* pc_relative */
665 complain_overflow_dont
, /* complain_on_overflow */
666 bfd_elf_generic_reloc
, /* special_function */
667 "R_MIPS_GOT_LO16", /* name */
668 true, /* partial_inplace */
669 0x0000ffff, /* src_mask */
670 0x0000ffff, /* dst_mask */
671 false), /* pcrel_offset */
673 /* 64 bit subtraction. Presumably not used in 32 bit ELF. */
676 /* Used to cause the linker to insert and delete instructions? */
681 /* Get the higher values of a 64 bit addend. Presumably not used in
686 /* High 16 bits of displacement in global offset table. */
687 /* FIXME: Not handled correctly. */
688 HOWTO (R_MIPS_CALL_HI16
, /* type */
690 2, /* size (0 = byte, 1 = short, 2 = long) */
692 false, /* pc_relative */
694 complain_overflow_dont
, /* complain_on_overflow */
695 bfd_elf_generic_reloc
, /* special_function */
696 "R_MIPS_CALL_HI16", /* name */
697 true, /* partial_inplace */
698 0x0000ffff, /* src_mask */
699 0x0000ffff, /* dst_mask */
700 false), /* pcrel_offset */
702 /* Low 16 bits of displacement in global offset table. */
703 /* FIXME: Not handled correctly. */
704 HOWTO (R_MIPS_CALL_LO16
, /* type */
706 2, /* size (0 = byte, 1 = short, 2 = long) */
708 false, /* pc_relative */
710 complain_overflow_dont
, /* complain_on_overflow */
711 bfd_elf_generic_reloc
, /* special_function */
712 "R_MIPS_CALL_LO16", /* name */
713 true, /* partial_inplace */
714 0x0000ffff, /* src_mask */
715 0x0000ffff, /* dst_mask */
716 false) /* pcrel_offset */
719 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
720 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
721 the HI16. Here we just save the information we need; we do the
722 actual relocation when we see the LO16. MIPS ELF requires that the
723 LO16 immediately follow the HI16, so this ought to work. */
725 static bfd_byte
*mips_hi16_addr
;
726 static bfd_vma mips_hi16_addend
;
728 static bfd_reloc_status_type
729 mips_elf_hi16_reloc (abfd
,
737 arelent
*reloc_entry
;
740 asection
*input_section
;
742 char **error_message
;
744 bfd_reloc_status_type ret
;
747 /* If we're relocating, and this an external symbol, we don't want
748 to change anything. */
749 if (output_bfd
!= (bfd
*) NULL
750 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
751 && reloc_entry
->addend
== 0)
753 reloc_entry
->address
+= input_section
->output_offset
;
759 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
761 boolean relocateable
;
763 if (ret
== bfd_reloc_undefined
)
766 if (output_bfd
!= NULL
)
770 relocateable
= false;
771 output_bfd
= symbol
->section
->output_section
->owner
;
774 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
776 if (ret
!= bfd_reloc_ok
)
779 relocation
= elf_gp (output_bfd
) - reloc_entry
->address
;
783 if (bfd_is_und_section (symbol
->section
)
784 && output_bfd
== (bfd
*) NULL
)
785 ret
= bfd_reloc_undefined
;
787 if (bfd_is_com_section (symbol
->section
))
790 relocation
= symbol
->value
;
793 relocation
+= symbol
->section
->output_section
->vma
;
794 relocation
+= symbol
->section
->output_offset
;
795 relocation
+= reloc_entry
->addend
;
797 if (reloc_entry
->address
> input_section
->_cooked_size
)
798 return bfd_reloc_outofrange
;
800 /* Save the information, and let LO16 do the actual relocation. */
801 mips_hi16_addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
802 mips_hi16_addend
= relocation
;
804 if (output_bfd
!= (bfd
*) NULL
)
805 reloc_entry
->address
+= input_section
->output_offset
;
810 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
811 inplace relocation; this function exists in order to do the
812 R_MIPS_HI16 relocation described above. */
814 static bfd_reloc_status_type
815 mips_elf_lo16_reloc (abfd
,
823 arelent
*reloc_entry
;
826 asection
*input_section
;
828 char **error_message
;
830 arelent gp_disp_relent
;
832 if (mips_hi16_addr
!= (bfd_byte
*) NULL
)
838 /* Do the HI16 relocation. Note that we actually don't need to
839 know anything about the LO16 itself, except where to find the
840 low 16 bits of the addend needed by the LO16. */
841 insn
= bfd_get_32 (abfd
, mips_hi16_addr
);
842 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
844 val
= ((insn
& 0xffff) << 16) + vallo
;
845 val
+= mips_hi16_addend
;
847 /* The low order 16 bits are always treated as a signed value.
848 Therefore, a negative value in the low order bits requires an
849 adjustment in the high order bits. We need to make this
850 adjustment in two ways: once for the bits we took from the
851 data, and once for the bits we are putting back in to the
853 if ((vallo
& 0x8000) != 0)
855 if ((val
& 0x8000) != 0)
858 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
859 bfd_put_32 (abfd
, insn
, mips_hi16_addr
);
861 mips_hi16_addr
= (bfd_byte
*) NULL
;
863 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
865 gp_disp_relent
= *reloc_entry
;
866 reloc_entry
= &gp_disp_relent
;
867 reloc_entry
->addend
= mips_hi16_addend
;
870 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
872 bfd_reloc_status_type ret
;
875 /* FIXME: Does this case ever occur? */
877 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
);
878 if (ret
!= bfd_reloc_ok
)
881 relocation
= elf_gp (output_bfd
) - reloc_entry
->address
;
882 relocation
+= symbol
->section
->output_section
->vma
;
883 relocation
+= symbol
->section
->output_offset
;
884 relocation
+= reloc_entry
->addend
;
886 if (reloc_entry
->address
> input_section
->_cooked_size
)
887 return bfd_reloc_outofrange
;
889 gp_disp_relent
= *reloc_entry
;
890 reloc_entry
= &gp_disp_relent
;
891 reloc_entry
->addend
= relocation
- 4;
894 /* Now do the LO16 reloc in the usual way. */
895 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
896 input_section
, output_bfd
, error_message
);
899 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
900 table used for PIC code. If the symbol is an external symbol, the
901 instruction is modified to contain the offset of the appropriate
902 entry in the global offset table. If the symbol is a section
903 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
904 addends are combined to form the real addend against the section
905 symbol; the GOT16 is modified to contain the offset of an entry in
906 the global offset table, and the LO16 is modified to offset it
907 appropriately. Thus an offset larger than 16 bits requires a
908 modified value in the global offset table.
910 This implementation suffices for the assembler, but the linker does
911 not yet know how to create global offset tables. */
913 static bfd_reloc_status_type
914 mips_elf_got16_reloc (abfd
,
922 arelent
*reloc_entry
;
925 asection
*input_section
;
927 char **error_message
;
929 /* If we're relocating, and this an external symbol, we don't want
930 to change anything. */
931 if (output_bfd
!= (bfd
*) NULL
932 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
933 && reloc_entry
->addend
== 0)
935 reloc_entry
->address
+= input_section
->output_offset
;
939 /* If we're relocating, and this is a local symbol, we can handle it
941 if (output_bfd
!= (bfd
*) NULL
942 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
943 return mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
944 input_section
, output_bfd
, error_message
);
949 /* We have to figure out the gp value, so that we can adjust the
950 symbol value correctly. We look up the symbol _gp in the output
951 BFD. If we can't find it, we're stuck. We cache it in the ELF
952 target data. We don't need to adjust the symbol value for an
953 external symbol if we are producing relocateable output. */
955 static bfd_reloc_status_type
956 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
)
959 boolean relocateable
;
960 char **error_message
;
962 if (bfd_is_und_section (symbol
->section
)
964 return bfd_reloc_undefined
;
966 /* This doesn't work if the BFD is not ELF. */
967 if (output_bfd
->xvec
->flavour
!= bfd_target_elf_flavour
)
970 if (elf_gp (output_bfd
) == 0
972 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
976 /* Make up a value. */
977 elf_gp (output_bfd
) =
978 symbol
->section
->output_section
->vma
+ 0x4000;
986 count
= bfd_get_symcount (output_bfd
);
987 sym
= bfd_get_outsymbols (output_bfd
);
989 if (sym
== (asymbol
**) NULL
)
993 for (i
= 0; i
< count
; i
++, sym
++)
995 register CONST
char *name
;
997 name
= bfd_asymbol_name (*sym
);
998 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1000 elf_gp (output_bfd
) = bfd_asymbol_value (*sym
);
1008 /* Only get the error once. */
1009 elf_gp (output_bfd
) = 4;
1011 (char *) "GP relative relocation when _gp not defined";
1012 return bfd_reloc_dangerous
;
1017 return bfd_reloc_ok
;
1020 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1021 become the offset from the gp register. This function also handles
1022 R_MIPS_LITERAL relocations, although those can be handled more
1023 cleverly because the entries in the .lit8 and .lit4 sections can be
1026 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1027 arelent
*, asection
*,
1028 boolean
, PTR
, bfd_vma
));
1030 static bfd_reloc_status_type
1031 mips_elf_gprel16_reloc (abfd
,
1039 arelent
*reloc_entry
;
1042 asection
*input_section
;
1044 char **error_message
;
1046 boolean relocateable
;
1047 bfd_reloc_status_type ret
;
1049 /* If we're relocating, and this is an external symbol with no
1050 addend, we don't want to change anything. We will only have an
1051 addend if this is a newly created reloc, not read from an ELF
1053 if (output_bfd
!= (bfd
*) NULL
1054 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1055 && reloc_entry
->addend
== 0)
1057 reloc_entry
->address
+= input_section
->output_offset
;
1058 return bfd_reloc_ok
;
1061 if (output_bfd
!= (bfd
*) NULL
)
1062 relocateable
= true;
1065 relocateable
= false;
1066 output_bfd
= symbol
->section
->output_section
->owner
;
1069 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
);
1070 if (ret
!= bfd_reloc_ok
)
1073 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1074 relocateable
, data
, elf_gp (output_bfd
));
1077 static bfd_reloc_status_type
1078 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1082 arelent
*reloc_entry
;
1083 asection
*input_section
;
1084 boolean relocateable
;
1092 if (bfd_is_com_section (symbol
->section
))
1095 relocation
= symbol
->value
;
1097 relocation
+= symbol
->section
->output_section
->vma
;
1098 relocation
+= symbol
->section
->output_offset
;
1100 if (reloc_entry
->address
> input_section
->_cooked_size
)
1101 return bfd_reloc_outofrange
;
1103 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1105 /* Set val to the offset into the section or symbol. */
1106 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1110 /* Adjust val for the final section location and GP value. If we
1111 are producing relocateable output, we don't want to do this for
1112 an external symbol. */
1114 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1115 val
+= relocation
- gp
;
1117 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1118 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1121 reloc_entry
->address
+= input_section
->output_offset
;
1123 /* Make sure it fit in 16 bits. */
1124 if (val
>= 0x8000 && val
< 0xffff8000)
1125 return bfd_reloc_overflow
;
1127 return bfd_reloc_ok
;
1130 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1131 from the gp register? XXX */
1133 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1134 arelent
*, asection
*,
1135 boolean
, PTR
, bfd_vma
));
1137 static bfd_reloc_status_type
1138 mips_elf_gprel32_reloc (abfd
,
1146 arelent
*reloc_entry
;
1149 asection
*input_section
;
1151 char **error_message
;
1153 boolean relocateable
;
1154 bfd_reloc_status_type ret
;
1156 /* If we're relocating, and this is an external symbol with no
1157 addend, we don't want to change anything. We will only have an
1158 addend if this is a newly created reloc, not read from an ELF
1160 if (output_bfd
!= (bfd
*) NULL
1161 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1162 && reloc_entry
->addend
== 0)
1164 *error_message
= (char *)
1165 "32bits gp relative relocation occurs for an external symbol";
1166 return bfd_reloc_outofrange
;
1169 if (output_bfd
!= (bfd
*) NULL
)
1170 relocateable
= true;
1173 relocateable
= false;
1174 output_bfd
= symbol
->section
->output_section
->owner
;
1176 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1178 if (ret
!= bfd_reloc_ok
)
1182 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1183 relocateable
, data
, elf_gp (output_bfd
));
1186 static bfd_reloc_status_type
1187 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1191 arelent
*reloc_entry
;
1192 asection
*input_section
;
1193 boolean relocateable
;
1200 if (bfd_is_com_section (symbol
->section
))
1203 relocation
= symbol
->value
;
1205 relocation
+= symbol
->section
->output_section
->vma
;
1206 relocation
+= symbol
->section
->output_offset
;
1208 if (reloc_entry
->address
> input_section
->_cooked_size
)
1209 return bfd_reloc_outofrange
;
1211 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1213 /* Set val to the offset into the section or symbol. */
1214 val
+= reloc_entry
->addend
;
1216 /* Adjust val for the final section location and GP value. If we
1217 are producing relocateable output, we don't want to do this for
1218 an external symbol. */
1220 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1221 val
+= relocation
- gp
;
1223 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1226 reloc_entry
->address
+= input_section
->output_offset
;
1228 return bfd_reloc_ok
;
1231 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1233 struct elf_reloc_map
{
1234 bfd_reloc_code_real_type bfd_reloc_val
;
1235 enum reloc_type elf_reloc_val
;
1238 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1240 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1241 { BFD_RELOC_16
, R_MIPS_16
},
1242 { BFD_RELOC_32
, R_MIPS_32
},
1243 { BFD_RELOC_CTOR
, R_MIPS_32
},
1244 { BFD_RELOC_32_PCREL
, R_MIPS_REL32
},
1245 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1246 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1247 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1248 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1249 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1250 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1251 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1252 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1253 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1254 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1255 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
}
1258 /* Given a BFD reloc type, return a howto structure. */
1260 static reloc_howto_type
*
1261 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1263 bfd_reloc_code_real_type code
;
1267 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1269 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1270 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1275 /* Given a MIPS reloc type, fill in an arelent structure. */
1278 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1281 Elf32_Internal_Rel
*dst
;
1283 unsigned int r_type
;
1285 r_type
= ELF32_R_TYPE (dst
->r_info
);
1286 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1287 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1289 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1290 value for the object file. We get the addend now, rather than
1291 when we do the relocation, because the symbol manipulations done
1292 by the linker may cause us to lose track of the input BFD. */
1293 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1294 && (r_type
== (unsigned int) R_MIPS_GPREL16
1295 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1296 cache_ptr
->addend
= elf_gp (abfd
);
1299 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1300 routines swap this structure in and out. They are used outside of
1301 BFD, so they are globally visible. */
1304 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1306 const Elf32_External_RegInfo
*ex
;
1309 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1310 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1311 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1312 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1313 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1314 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1318 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1320 const Elf32_RegInfo
*in
;
1321 Elf32_External_RegInfo
*ex
;
1323 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1324 (bfd_byte
*) ex
->ri_gprmask
);
1325 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1326 (bfd_byte
*) ex
->ri_cprmask
[0]);
1327 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1328 (bfd_byte
*) ex
->ri_cprmask
[1]);
1329 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1330 (bfd_byte
*) ex
->ri_cprmask
[2]);
1331 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1332 (bfd_byte
*) ex
->ri_cprmask
[3]);
1333 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1334 (bfd_byte
*) ex
->ri_gp_value
);
1337 /* Swap an entry in a .gptab section. Note that these routines rely
1338 on the equivalence of the two elements of the union. */
1341 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1343 const Elf32_External_gptab
*ex
;
1346 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1347 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1351 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1353 const Elf32_gptab
*in
;
1354 Elf32_External_gptab
*ex
;
1356 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1357 ex
->gt_entry
.gt_g_value
);
1358 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1359 ex
->gt_entry
.gt_bytes
);
1363 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1365 const Elf32_compact_rel
*in
;
1366 Elf32_External_compact_rel
*ex
;
1368 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
1369 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
1370 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
1371 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
1372 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
1373 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
1377 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1379 const Elf32_crinfo
*in
;
1380 Elf32_External_crinfo
*ex
;
1384 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1385 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1386 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1387 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1388 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
1389 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
1390 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
1393 /* Determine whether a symbol is global for the purposes of splitting
1394 the symbol table into global symbols and local symbols. At least
1395 on Irix 5, this split must be between section symbols and all other
1396 symbols. On most ELF targets the split is between static symbols
1397 and externally visible symbols. */
1401 mips_elf_sym_is_global (abfd
, sym
)
1405 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
1408 /* Set the right machine number for a MIPS ELF file. */
1411 mips_elf_object_p (abfd
)
1414 switch (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
)
1418 /* Just use the default, which was set in elfcode.h. */
1422 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 6000);
1426 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 4000);
1430 /* Irix 5 is broken. Object file symbol tables are not always
1431 sorted correctly such that local symbols precede global symbols,
1432 and the sh_info field in the symbol table is not always right. */
1433 elf_bad_symtab (abfd
) = true;
1438 /* The final processing done just before writing out a MIPS ELF object
1439 file. This gets the MIPS architecture right based on the machine
1444 mips_elf_final_write_processing (abfd
, linker
)
1450 Elf_Internal_Shdr
**hdrpp
;
1452 switch (bfd_get_mach (abfd
))
1455 val
= E_MIPS_ARCH_1
;
1459 val
= E_MIPS_ARCH_2
;
1463 val
= E_MIPS_ARCH_3
;
1471 elf_elfheader (abfd
)->e_flags
&=~ EF_MIPS_ARCH
;
1472 elf_elfheader (abfd
)->e_flags
|= val
;
1474 /* Set the sh_info field for .gptab sections. */
1475 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
1476 i
< elf_elfheader (abfd
)->e_shnum
;
1479 if ((*hdrpp
)->sh_type
== SHT_MIPS_GPTAB
)
1484 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1485 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1486 BFD_ASSERT (name
!= NULL
1487 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
1488 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
1489 BFD_ASSERT (sec
!= NULL
);
1490 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1495 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
1498 mips_elf_set_private_flags (abfd
, flags
)
1502 BFD_ASSERT (!elf_flags_init (abfd
)
1503 || elf_elfheader (abfd
)->e_flags
== flags
);
1505 elf_elfheader (abfd
)->e_flags
= flags
;
1506 elf_flags_init (abfd
) = true;
1510 /* Copy backend specific data from one object module to another */
1513 mips_elf_copy_private_bfd_data (ibfd
, obfd
)
1517 /* This function is selected based on the input vector. We only
1518 want to copy information over if the output BFD also uses Elf
1520 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1523 BFD_ASSERT (!elf_flags_init (obfd
)
1524 || (elf_elfheader (obfd
)->e_flags
1525 == elf_elfheader (ibfd
)->e_flags
));
1527 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1528 elf_flags_init (obfd
) = true;
1532 /* Merge backend specific data from an object file to the output
1533 object file when linking. */
1536 mips_elf_merge_private_bfd_data (ibfd
, obfd
)
1543 /* Check if we have the same endianess */
1544 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1545 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1547 (*_bfd_error_handler
)
1548 ("%s: compiled for a %s endian system and target is %s endian",
1549 bfd_get_filename (ibfd
),
1550 bfd_big_endian (ibfd
) ? "big" : "little",
1551 bfd_big_endian (obfd
) ? "big" : "little");
1553 bfd_set_error (bfd_error_wrong_format
);
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 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1564 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
1565 old_flags
= elf_elfheader (obfd
)->e_flags
;
1567 if (!elf_flags_init (obfd
)) /* First call, no flags set */
1569 elf_flags_init (obfd
) = true;
1570 elf_elfheader (obfd
)->e_flags
= new_flags
;
1572 else if (((new_flags
^ old_flags
) & ~EF_MIPS_NOREORDER
)
1573 == 0) /* Compatible flags are ok */
1575 else /* Incompatible flags */
1577 /* Warn about -fPIC mismatch */
1578 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
1580 new_flags
&= ~EF_MIPS_PIC
;
1581 (*_bfd_error_handler
)
1582 ("%s: needs all files compiled with -fPIC",
1583 bfd_get_filename (ibfd
));
1586 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
1588 new_flags
&= ~EF_MIPS_CPIC
;
1589 (*_bfd_error_handler
)
1590 ("%s: needs all files compiled with -mabicalls",
1591 bfd_get_filename (ibfd
));
1594 /* Warn about any other mismatches */
1595 if (new_flags
!= old_flags
)
1596 (*_bfd_error_handler
)
1597 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1598 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
1599 (unsigned long) old_flags
);
1601 bfd_set_error (bfd_error_bad_value
);
1608 /* Handle a MIPS specific section when reading an object file. This
1609 is called when elfcode.h finds a section with an unknown type.
1610 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
1614 mips_elf_section_from_shdr (abfd
, hdr
, name
)
1616 Elf32_Internal_Shdr
*hdr
;
1621 /* There ought to be a place to keep ELF backend specific flags, but
1622 at the moment there isn't one. We just keep track of the
1623 sections by their name, instead. Fortunately, the ABI gives
1624 suggested names for all the MIPS specific sections, so we will
1625 probably get away with this. */
1626 switch (hdr
->sh_type
)
1628 case SHT_MIPS_LIBLIST
:
1629 if (strcmp (name
, ".liblist") != 0)
1633 if (strcmp (name
, ".msym") != 0)
1636 case SHT_MIPS_CONFLICT
:
1637 if (strcmp (name
, ".conflict") != 0)
1640 case SHT_MIPS_GPTAB
:
1641 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
1644 case SHT_MIPS_UCODE
:
1645 if (strcmp (name
, ".ucode") != 0)
1648 case SHT_MIPS_DEBUG
:
1649 if (strcmp (name
, ".mdebug") != 0)
1652 case SHT_MIPS_REGINFO
:
1653 if (strcmp (name
, ".reginfo") != 0
1654 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
1657 case SHT_MIPS_OPTIONS
:
1658 if (strcmp (name
, ".options") != 0)
1661 case SHT_MIPS_DWARF
:
1662 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
1665 case SHT_MIPS_EVENTS
:
1666 if (strncmp (name
, ".MIPS.events.", sizeof ".MIPS.events." - 1) != 0)
1673 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1675 newsect
= hdr
->bfd_section
;
1677 if (hdr
->sh_type
== SHT_MIPS_DEBUG
)
1679 if (! bfd_set_section_flags (abfd
, newsect
,
1680 (bfd_get_section_flags (abfd
, newsect
)
1685 /* FIXME: We should record sh_info for a .gptab section. */
1687 /* For a .reginfo section, set the gp value in the tdata information
1688 from the contents of this section. We need the gp value while
1689 processing relocs, so we just get it now. */
1690 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
1692 Elf32_External_RegInfo ext
;
1695 if (! bfd_get_section_contents (abfd
, newsect
, (PTR
) &ext
,
1696 (file_ptr
) 0, sizeof ext
))
1698 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
1699 elf_gp (abfd
) = s
.ri_gp_value
;
1705 /* Set the correct type for a MIPS ELF section. We do this by the
1706 section name, which is a hack, but ought to work. */
1709 mips_elf_fake_sections (abfd
, hdr
, sec
)
1711 Elf32_Internal_Shdr
*hdr
;
1714 register const char *name
;
1716 name
= bfd_get_section_name (abfd
, sec
);
1718 if (strcmp (name
, ".liblist") == 0)
1720 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
1721 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
1722 /* FIXME: Set the sh_link field. */
1724 else if (strcmp (name
, ".msym") == 0)
1726 hdr
->sh_type
= SHT_MIPS_MSYM
;
1727 hdr
->sh_entsize
= 8;
1728 /* FIXME: Set the sh_info field. */
1730 else if (strcmp (name
, ".conflict") == 0)
1731 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
1732 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
1734 hdr
->sh_type
= SHT_MIPS_GPTAB
;
1735 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
1736 /* The sh_info field is set in mips_elf_final_write_processing. */
1738 else if (strcmp (name
, ".ucode") == 0)
1739 hdr
->sh_type
= SHT_MIPS_UCODE
;
1740 else if (strcmp (name
, ".mdebug") == 0)
1742 hdr
->sh_type
= SHT_MIPS_DEBUG
;
1743 /* In a shared object on Irix 5.3, the .mdebug section has an
1744 entsize of 0. FIXME: Does this matter? */
1745 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
1746 hdr
->sh_entsize
= 0;
1748 hdr
->sh_entsize
= 1;
1750 else if (strcmp (name
, ".reginfo") == 0)
1752 hdr
->sh_type
= SHT_MIPS_REGINFO
;
1753 /* In a shared object on Irix 5.3, the .reginfo section has an
1754 entsize of 0x18. FIXME: Does this matter? */
1755 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
1756 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
1758 hdr
->sh_entsize
= 1;
1760 /* Force the section size to the correct value, even if the
1761 linker thinks it is larger. The link routine below will only
1762 write out this much data for .reginfo. */
1763 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf32_External_RegInfo
);
1765 else if (SGI_COMPAT (abfd
)
1766 && (strcmp (name
, ".hash") == 0
1767 || strcmp (name
, ".dynamic") == 0
1768 || strcmp (name
, ".dynstr") == 0))
1770 hdr
->sh_entsize
= 0;
1771 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
1773 else if (strcmp (name
, ".got") == 0
1774 || strcmp (name
, ".sdata") == 0
1775 || strcmp (name
, ".sbss") == 0
1776 || strcmp (name
, ".lit4") == 0
1777 || strcmp (name
, ".lit8") == 0)
1778 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
1779 else if (strcmp (name
, ".options") == 0)
1781 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
1782 hdr
->sh_entsize
= 1;
1784 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
1785 hdr
->sh_type
= SHT_MIPS_DWARF
;
1786 else if (strncmp (name
, ".MIPS.events.", sizeof ".MIPS.events." - 1) == 0)
1787 hdr
->sh_type
= SHT_MIPS_EVENTS
;
1792 /* Given a BFD section, try to locate the corresponding ELF section
1796 mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
1798 Elf32_Internal_Shdr
*hdr
;
1802 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
1804 *retval
= SHN_MIPS_SCOMMON
;
1807 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
1809 *retval
= SHN_MIPS_ACOMMON
;
1815 /* Work over a section just before writing it out. We update the GP
1816 value in the .reginfo section based on the value we are using.
1817 FIXME: We recognize sections that need the SHF_MIPS_GPREL flag by
1818 name; there has to be a better way. */
1821 mips_elf_section_processing (abfd
, hdr
)
1823 Elf32_Internal_Shdr
*hdr
;
1825 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
1829 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
1830 BFD_ASSERT (hdr
->contents
== NULL
);
1833 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
1836 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
1837 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
1841 if (hdr
->bfd_section
!= NULL
)
1843 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
1845 if (strcmp (name
, ".sdata") == 0)
1847 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
1848 hdr
->sh_type
= SHT_PROGBITS
;
1850 else if (strcmp (name
, ".sbss") == 0)
1852 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
1853 hdr
->sh_type
= SHT_NOBITS
;
1855 else if (strcmp (name
, ".lit8") == 0
1856 || strcmp (name
, ".lit4") == 0)
1858 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
1859 hdr
->sh_type
= SHT_PROGBITS
;
1861 else if (strcmp (name
, ".compact_rel") == 0)
1864 hdr
->sh_type
= SHT_PROGBITS
;
1866 else if (strcmp (name
, ".rtproc") == 0)
1868 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
1870 unsigned int adjust
;
1872 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
1874 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
1882 /* MIPS ELF uses two common sections. One is the usual one, and the
1883 other is for small objects. All the small objects are kept
1884 together, and then referenced via the gp pointer, which yields
1885 faster assembler code. This is what we use for the small common
1886 section. This approach is copied from ecoff.c. */
1887 static asection mips_elf_scom_section
;
1888 static asymbol mips_elf_scom_symbol
;
1889 static asymbol
*mips_elf_scom_symbol_ptr
;
1891 /* MIPS ELF also uses an acommon section, which represents an
1892 allocated common symbol which may be overridden by a
1893 definition in a shared library. */
1894 static asection mips_elf_acom_section
;
1895 static asymbol mips_elf_acom_symbol
;
1896 static asymbol
*mips_elf_acom_symbol_ptr
;
1898 /* The Irix 5 support uses two virtual sections, which represent
1899 text/data symbols defined in dynamic objects. */
1900 static asection mips_elf_text_section
;
1901 static asection
*mips_elf_text_section_ptr
;
1902 static asymbol mips_elf_text_symbol
;
1903 static asymbol
*mips_elf_text_symbol_ptr
;
1905 static asection mips_elf_data_section
;
1906 static asection
*mips_elf_data_section_ptr
;
1907 static asymbol mips_elf_data_symbol
;
1908 static asymbol
*mips_elf_data_symbol_ptr
;
1910 /* Handle the special MIPS section numbers that a symbol may use. */
1913 mips_elf_symbol_processing (abfd
, asym
)
1917 elf_symbol_type
*elfsym
;
1919 elfsym
= (elf_symbol_type
*) asym
;
1920 switch (elfsym
->internal_elf_sym
.st_shndx
)
1922 case SHN_MIPS_ACOMMON
:
1923 /* This section is used in a dynamically linked executable file.
1924 It is an allocated common section. The dynamic linker can
1925 either resolve these symbols to something in a shared
1926 library, or it can just leave them here. For our purposes,
1927 we can consider these symbols to be in a new section. */
1928 if (mips_elf_acom_section
.name
== NULL
)
1930 /* Initialize the acommon section. */
1931 mips_elf_acom_section
.name
= ".acommon";
1932 mips_elf_acom_section
.flags
= SEC_ALLOC
;
1933 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
1934 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
1935 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
1936 mips_elf_acom_symbol
.name
= ".acommon";
1937 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
1938 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
1939 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
1941 asym
->section
= &mips_elf_acom_section
;
1945 /* Common symbols less than the GP size are automatically
1946 treated as SHN_MIPS_SCOMMON symbols. */
1947 if (asym
->value
> elf_gp_size (abfd
))
1950 case SHN_MIPS_SCOMMON
:
1951 if (mips_elf_scom_section
.name
== NULL
)
1953 /* Initialize the small common section. */
1954 mips_elf_scom_section
.name
= ".scommon";
1955 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
1956 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
1957 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
1958 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
1959 mips_elf_scom_symbol
.name
= ".scommon";
1960 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
1961 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
1962 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
1964 asym
->section
= &mips_elf_scom_section
;
1965 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
1968 case SHN_MIPS_SUNDEFINED
:
1969 asym
->section
= bfd_und_section_ptr
;
1972 #if 0 /* for SGI_COMPAT */
1974 asym
->section
= mips_elf_text_section_ptr
;
1978 asym
->section
= mips_elf_data_section_ptr
;
1984 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
1988 mips_elf_additional_program_headers (abfd
)
1996 if (! SGI_COMPAT (abfd
))
1999 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2000 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2002 /* We need a PT_MIPS_REGINFO segment. */
2006 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2007 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2009 /* We need a PT_MIPS_RTPROC segment. */
2016 /* Modify the segment map for an Irix 5 executable. */
2019 mips_elf_modify_segment_map (abfd
)
2023 struct elf_segment_map
*m
, **pm
;
2025 if (! SGI_COMPAT (abfd
))
2028 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
2030 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2031 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2033 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2034 if (m
->p_type
== PT_MIPS_REGINFO
)
2038 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2042 m
->p_type
= PT_MIPS_REGINFO
;
2046 /* We want to put it after the PHDR and INTERP segments. */
2047 pm
= &elf_tdata (abfd
)->segment_map
;
2049 && ((*pm
)->p_type
== PT_PHDR
2050 || (*pm
)->p_type
== PT_INTERP
))
2058 /* If there are .dynamic and .mdebug sections, we make a room for
2059 the RTPROC header. FIXME: Rewrite without section names. */
2060 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
2061 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2062 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2064 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2065 if (m
->p_type
== PT_MIPS_RTPROC
)
2069 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2073 m
->p_type
= PT_MIPS_RTPROC
;
2075 s
= bfd_get_section_by_name (abfd
, ".rtproc");
2080 m
->p_flags_valid
= 1;
2088 /* We want to put it after the DYNAMIC segment. */
2089 pm
= &elf_tdata (abfd
)->segment_map
;
2090 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
2100 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
2101 .dynsym, and .hash sections, and everything in between. */
2102 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
2103 if ((*pm
)->p_type
== PT_DYNAMIC
)
2108 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
2110 static const char *sec_names
[] =
2111 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
2114 struct elf_segment_map
*n
;
2118 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
2120 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
2121 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2127 sz
= s
->_cooked_size
;
2130 if (high
< s
->vma
+ sz
)
2136 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2137 if ((s
->flags
& SEC_LOAD
) != 0
2140 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2144 n
= ((struct elf_segment_map
*)
2145 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
2152 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2154 if ((s
->flags
& SEC_LOAD
) != 0
2157 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2171 /* The structure of the runtime procedure descriptor created by the
2172 loader for use by the static exception system. */
2174 typedef struct runtime_pdr
{
2175 bfd_vma adr
; /* memory address of start of procedure */
2176 long regmask
; /* save register mask */
2177 long regoffset
; /* save register offset */
2178 long fregmask
; /* save floating point register mask */
2179 long fregoffset
; /* save floating point register offset */
2180 long frameoffset
; /* frame size */
2181 short framereg
; /* frame pointer register */
2182 short pcreg
; /* offset or reg of return pc */
2183 long irpss
; /* index into the runtime string table */
2185 struct exception_info
*exception_info
;/* pointer to exception array */
2187 #define cbRPDR sizeof(RPDR)
2188 #define rpdNil ((pRPDR) 0)
2190 /* Swap RPDR (runtime procedure table entry) for output. */
2192 static void ecoff_swap_rpdr_out
2193 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
2196 ecoff_swap_rpdr_out (abfd
, in
, ex
)
2199 struct rpdr_ext
*ex
;
2201 /* ecoff_put_off was defined in ecoffswap.h. */
2202 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
2203 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
2204 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
2205 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
2206 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
2207 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
2209 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
2210 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
2212 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
2214 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
2218 /* Read ECOFF debugging information from a .mdebug section into a
2219 ecoff_debug_info structure. */
2222 mips_elf_read_ecoff_info (abfd
, section
, debug
)
2225 struct ecoff_debug_info
*debug
;
2228 const struct ecoff_debug_swap
*swap
;
2229 char *ext_hdr
= NULL
;
2231 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2233 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
2234 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
2237 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
2238 swap
->external_hdr_size
)
2242 symhdr
= &debug
->symbolic_header
;
2243 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
2245 /* The symbolic header contains absolute file offsets and sizes to
2247 #define READ(ptr, offset, count, size, type) \
2248 if (symhdr->count == 0) \
2249 debug->ptr = NULL; \
2252 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
2253 if (debug->ptr == NULL) \
2254 goto error_return; \
2255 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
2256 || (bfd_read (debug->ptr, size, symhdr->count, \
2257 abfd) != size * symhdr->count)) \
2258 goto error_return; \
2261 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
2262 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
2263 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
2264 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
2265 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
2266 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
2268 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
2269 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
2270 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
2271 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
2272 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
2276 debug
->adjust
= NULL
;
2281 if (ext_hdr
!= NULL
)
2283 if (debug
->line
!= NULL
)
2285 if (debug
->external_dnr
!= NULL
)
2286 free (debug
->external_dnr
);
2287 if (debug
->external_pdr
!= NULL
)
2288 free (debug
->external_pdr
);
2289 if (debug
->external_sym
!= NULL
)
2290 free (debug
->external_sym
);
2291 if (debug
->external_opt
!= NULL
)
2292 free (debug
->external_opt
);
2293 if (debug
->external_aux
!= NULL
)
2294 free (debug
->external_aux
);
2295 if (debug
->ss
!= NULL
)
2297 if (debug
->ssext
!= NULL
)
2298 free (debug
->ssext
);
2299 if (debug
->external_fdr
!= NULL
)
2300 free (debug
->external_fdr
);
2301 if (debug
->external_rfd
!= NULL
)
2302 free (debug
->external_rfd
);
2303 if (debug
->external_ext
!= NULL
)
2304 free (debug
->external_ext
);
2308 /* MIPS ELF local labels start with '$', not 'L'. */
2312 mips_elf_is_local_label (abfd
, symbol
)
2316 return symbol
->name
[0] == '$';
2319 /* MIPS ELF uses a special find_nearest_line routine in order the
2320 handle the ECOFF debugging information. */
2322 struct mips_elf_find_line
2324 struct ecoff_debug_info d
;
2325 struct ecoff_find_line i
;
2329 mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
2330 functionname_ptr
, line_ptr
)
2335 const char **filename_ptr
;
2336 const char **functionname_ptr
;
2337 unsigned int *line_ptr
;
2341 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
2345 struct mips_elf_find_line
*fi
;
2346 const struct ecoff_debug_swap
* const swap
=
2347 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2349 /* If we are called during a link, mips_elf_final_link may have
2350 cleared the SEC_HAS_CONTENTS field. We force it back on here
2351 if appropriate (which it normally will be). */
2352 origflags
= msec
->flags
;
2353 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
2354 msec
->flags
|= SEC_HAS_CONTENTS
;
2356 fi
= elf_tdata (abfd
)->find_line_info
;
2359 bfd_size_type external_fdr_size
;
2362 struct fdr
*fdr_ptr
;
2364 fi
= ((struct mips_elf_find_line
*)
2365 bfd_alloc (abfd
, sizeof (struct mips_elf_find_line
)));
2368 msec
->flags
= origflags
;
2372 memset (fi
, 0, sizeof (struct mips_elf_find_line
));
2374 if (! mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
2376 msec
->flags
= origflags
;
2380 /* Swap in the FDR information. */
2381 fi
->d
.fdr
= ((struct fdr
*)
2383 (fi
->d
.symbolic_header
.ifdMax
*
2384 sizeof (struct fdr
))));
2385 if (fi
->d
.fdr
== NULL
)
2387 msec
->flags
= origflags
;
2390 external_fdr_size
= swap
->external_fdr_size
;
2391 fdr_ptr
= fi
->d
.fdr
;
2392 fraw_src
= (char *) fi
->d
.external_fdr
;
2393 fraw_end
= (fraw_src
2394 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
2395 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
2396 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
2398 elf_tdata (abfd
)->find_line_info
= fi
;
2400 /* Note that we don't bother to ever free this information.
2401 find_nearest_line is either called all the time, as in
2402 objdump -l, so the information should be saved, or it is
2403 rarely called, as in ld error messages, so the memory
2404 wasted is unimportant. Still, it would probably be a
2405 good idea for free_cached_info to throw it away. */
2408 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
2409 &fi
->i
, filename_ptr
, functionname_ptr
,
2412 msec
->flags
= origflags
;
2416 msec
->flags
= origflags
;
2419 /* Fall back on the generic ELF find_nearest_line routine. */
2421 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
2422 filename_ptr
, functionname_ptr
,
2426 /* The MIPS ELF linker needs additional information for each symbol in
2427 the global hash table. */
2429 struct mips_elf_link_hash_entry
2431 struct elf_link_hash_entry root
;
2433 /* External symbol information. */
2437 /* MIPS ELF linker hash table. */
2439 struct mips_elf_link_hash_table
2441 struct elf_link_hash_table root
;
2442 /* String section indices for the dynamic section symbols. */
2443 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
2444 /* The number of .rtproc entries. */
2445 bfd_size_type procedure_count
;
2446 /* The size of the .compact_rel section (if SGI_COMPAT). */
2447 bfd_size_type compact_rel_size
;
2450 /* Look up an entry in a MIPS ELF linker hash table. */
2452 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
2453 ((struct mips_elf_link_hash_entry *) \
2454 elf_link_hash_lookup (&(table)->root, (string), (create), \
2457 /* Traverse a MIPS ELF linker hash table. */
2459 #define mips_elf_link_hash_traverse(table, func, info) \
2460 (elf_link_hash_traverse \
2462 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
2465 /* Get the MIPS ELF linker hash table from a link_info structure. */
2467 #define mips_elf_hash_table(p) \
2468 ((struct mips_elf_link_hash_table *) ((p)->hash))
2470 static boolean mips_elf_output_extsym
2471 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
2473 /* Create an entry in a MIPS ELF linker hash table. */
2475 static struct bfd_hash_entry
*
2476 mips_elf_link_hash_newfunc (entry
, table
, string
)
2477 struct bfd_hash_entry
*entry
;
2478 struct bfd_hash_table
*table
;
2481 struct mips_elf_link_hash_entry
*ret
=
2482 (struct mips_elf_link_hash_entry
*) entry
;
2484 /* Allocate the structure if it has not already been allocated by a
2486 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
2487 ret
= ((struct mips_elf_link_hash_entry
*)
2488 bfd_hash_allocate (table
,
2489 sizeof (struct mips_elf_link_hash_entry
)));
2490 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
2491 return (struct bfd_hash_entry
*) ret
;
2493 /* Call the allocation method of the superclass. */
2494 ret
= ((struct mips_elf_link_hash_entry
*)
2495 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2497 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
2499 /* Set local fields. */
2500 memset (&ret
->esym
, 0, sizeof (EXTR
));
2501 /* We use -2 as a marker to indicate that the information has
2502 not been set. -1 means there is no associated ifd. */
2506 return (struct bfd_hash_entry
*) ret
;
2509 /* Create a MIPS ELF linker hash table. */
2511 static struct bfd_link_hash_table
*
2512 mips_elf_link_hash_table_create (abfd
)
2515 struct mips_elf_link_hash_table
*ret
;
2518 ret
= ((struct mips_elf_link_hash_table
*)
2519 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
2520 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
2523 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
2524 mips_elf_link_hash_newfunc
))
2526 bfd_release (abfd
, ret
);
2530 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
2531 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
2532 ret
->procedure_count
= 0;
2533 ret
->compact_rel_size
= 0;
2535 return &ret
->root
.root
;
2538 /* Hook called by the linker routine which adds symbols from an object
2539 file. We must handle the special MIPS section numbers here. */
2543 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2545 struct bfd_link_info
*info
;
2546 const Elf_Internal_Sym
*sym
;
2552 if (SGI_COMPAT (abfd
)
2553 && (abfd
->flags
& DYNAMIC
) != 0
2554 && strcmp (*namep
, "_rld_new_interface") == 0)
2556 /* Skip Irix 5 rld entry name. */
2561 switch (sym
->st_shndx
)
2564 /* Common symbols less than the GP size are automatically
2565 treated as SHN_MIPS_SCOMMON symbols. */
2566 if (sym
->st_size
> elf_gp_size (abfd
))
2569 case SHN_MIPS_SCOMMON
:
2570 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
2571 (*secp
)->flags
|= SEC_IS_COMMON
;
2572 *valp
= sym
->st_size
;
2576 /* This section is used in a shared object. */
2577 if (mips_elf_text_section_ptr
== NULL
)
2579 /* Initialize the section. */
2580 mips_elf_text_section
.name
= ".text";
2581 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
2582 mips_elf_text_section
.output_section
= NULL
;
2583 mips_elf_text_section
.owner
= abfd
;
2584 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
2585 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
2586 mips_elf_text_symbol
.name
= ".text";
2587 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
2588 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
2589 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
2590 mips_elf_text_section_ptr
= &mips_elf_text_section
;
2593 *secp
= bfd_und_section_ptr
;
2595 *secp
= mips_elf_text_section_ptr
;
2598 case SHN_MIPS_ACOMMON
:
2599 /* Fall through. XXX Can we treat this as allocated data? */
2601 /* This section is used in a shared object. */
2602 if (mips_elf_data_section_ptr
== NULL
)
2604 /* Initialize the section. */
2605 mips_elf_data_section
.name
= ".data";
2606 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
2607 mips_elf_data_section
.output_section
= NULL
;
2608 mips_elf_data_section
.owner
= abfd
;
2609 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
2610 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
2611 mips_elf_data_symbol
.name
= ".data";
2612 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
2613 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
2614 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
2615 mips_elf_data_section_ptr
= &mips_elf_data_section
;
2618 *secp
= bfd_und_section_ptr
;
2620 *secp
= mips_elf_data_section_ptr
;
2623 case SHN_MIPS_SUNDEFINED
:
2624 *secp
= bfd_und_section_ptr
;
2631 /* Structure used to pass information to mips_elf_output_extsym. */
2636 struct bfd_link_info
*info
;
2637 struct ecoff_debug_info
*debug
;
2638 const struct ecoff_debug_swap
*swap
;
2642 /* This routine is used to write out ECOFF debugging external symbol
2643 information. It is called via mips_elf_link_hash_traverse. The
2644 ECOFF external symbol information must match the ELF external
2645 symbol information. Unfortunately, at this point we don't know
2646 whether a symbol is required by reloc information, so the two
2647 tables may wind up being different. We must sort out the external
2648 symbol information before we can set the final size of the .mdebug
2649 section, and we must set the size of the .mdebug section before we
2650 can relocate any sections, and we can't know which symbols are
2651 required by relocation until we relocate the sections.
2652 Fortunately, it is relatively unlikely that any symbol will be
2653 stripped but required by a reloc. In particular, it can not happen
2654 when generating a final executable. */
2657 mips_elf_output_extsym (h
, data
)
2658 struct mips_elf_link_hash_entry
*h
;
2661 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
2663 asection
*sec
, *output_section
;
2665 if (h
->root
.indx
== -2)
2667 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2668 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
2669 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
2670 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
2672 else if (einfo
->info
->strip
== strip_all
2673 || (einfo
->info
->strip
== strip_some
2674 && bfd_hash_lookup (einfo
->info
->keep_hash
,
2675 h
->root
.root
.root
.string
,
2676 false, false) == NULL
))
2684 if (h
->esym
.ifd
== -2)
2687 h
->esym
.cobol_main
= 0;
2688 h
->esym
.weakext
= 0;
2689 h
->esym
.reserved
= 0;
2690 h
->esym
.ifd
= ifdNil
;
2691 h
->esym
.asym
.value
= 0;
2692 h
->esym
.asym
.st
= stGlobal
;
2694 if (SGI_COMPAT (einfo
->abfd
)
2695 && (h
->root
.root
.type
== bfd_link_hash_undefined
2696 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
2700 /* Use undefined class. Also, set class and type for some
2702 name
= h
->root
.root
.root
.string
;
2703 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
2704 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
2706 h
->esym
.asym
.sc
= scData
;
2707 h
->esym
.asym
.st
= stLabel
;
2708 h
->esym
.asym
.value
= 0;
2710 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
2712 h
->esym
.asym
.sc
= scAbs
;
2713 h
->esym
.asym
.st
= stLabel
;
2714 h
->esym
.asym
.value
=
2715 mips_elf_hash_table (einfo
->info
)->procedure_count
;
2717 else if (strcmp (name
, "_gp_disp") == 0)
2719 h
->esym
.asym
.sc
= scAbs
;
2720 h
->esym
.asym
.st
= stLabel
;
2721 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
2724 h
->esym
.asym
.sc
= scUndefined
;
2726 else if (h
->root
.root
.type
!= bfd_link_hash_defined
2727 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2728 h
->esym
.asym
.sc
= scAbs
;
2733 sec
= h
->root
.root
.u
.def
.section
;
2734 output_section
= sec
->output_section
;
2736 /* When making a shared library and symbol h is the one from
2737 the another shared library, OUTPUT_SECTION may be null. */
2738 if (output_section
== NULL
)
2739 h
->esym
.asym
.sc
= scUndefined
;
2742 name
= bfd_section_name (output_section
->owner
, output_section
);
2744 if (strcmp (name
, ".text") == 0)
2745 h
->esym
.asym
.sc
= scText
;
2746 else if (strcmp (name
, ".data") == 0)
2747 h
->esym
.asym
.sc
= scData
;
2748 else if (strcmp (name
, ".sdata") == 0)
2749 h
->esym
.asym
.sc
= scSData
;
2750 else if (strcmp (name
, ".rodata") == 0
2751 || strcmp (name
, ".rdata") == 0)
2752 h
->esym
.asym
.sc
= scRData
;
2753 else if (strcmp (name
, ".bss") == 0)
2754 h
->esym
.asym
.sc
= scBss
;
2755 else if (strcmp (name
, ".sbss") == 0)
2756 h
->esym
.asym
.sc
= scSBss
;
2757 else if (strcmp (name
, ".init") == 0)
2758 h
->esym
.asym
.sc
= scInit
;
2759 else if (strcmp (name
, ".fini") == 0)
2760 h
->esym
.asym
.sc
= scFini
;
2762 h
->esym
.asym
.sc
= scAbs
;
2766 h
->esym
.asym
.reserved
= 0;
2767 h
->esym
.asym
.index
= indexNil
;
2770 if (h
->root
.root
.type
== bfd_link_hash_common
)
2771 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2772 else if (h
->root
.root
.type
== bfd_link_hash_defined
2773 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2775 if (h
->esym
.asym
.sc
== scCommon
)
2776 h
->esym
.asym
.sc
= scBss
;
2777 else if (h
->esym
.asym
.sc
== scSCommon
)
2778 h
->esym
.asym
.sc
= scSBss
;
2780 sec
= h
->root
.root
.u
.def
.section
;
2781 output_section
= sec
->output_section
;
2782 if (output_section
!= NULL
)
2783 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2784 + sec
->output_offset
2785 + output_section
->vma
);
2787 h
->esym
.asym
.value
= 0;
2789 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
2791 /* Set type and value for a symbol with a function stub. */
2792 h
->esym
.asym
.st
= stProc
;
2793 sec
= h
->root
.root
.u
.def
.section
;
2795 h
->esym
.asym
.value
= 0;
2798 output_section
= sec
->output_section
;
2799 if (output_section
!= NULL
)
2800 h
->esym
.asym
.value
= (h
->root
.plt_offset
2801 + sec
->output_offset
2802 + output_section
->vma
);
2804 h
->esym
.asym
.value
= 0;
2811 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
2812 h
->root
.root
.root
.string
,
2815 einfo
->failed
= true;
2822 /* Create a runtime procedure table from the .mdebug section. */
2825 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
2828 struct bfd_link_info
*info
;
2830 struct ecoff_debug_info
*debug
;
2832 const struct ecoff_debug_swap
*swap
;
2833 HDRR
*hdr
= &debug
->symbolic_header
;
2835 struct rpdr_ext
*erp
;
2837 struct pdr_ext
*epdr
;
2838 struct sym_ext
*esym
;
2841 unsigned long size
, count
;
2842 unsigned long sindex
;
2846 const char *no_name_func
= "static procedure (no name)";
2853 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2855 sindex
= strlen (no_name_func
) + 1;
2856 count
= hdr
->ipdMax
;
2859 size
= swap
->external_pdr_size
;
2861 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
2865 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
2868 size
= sizeof (RPDR
);
2869 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
2873 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
2877 count
= hdr
->isymMax
;
2878 size
= swap
->external_sym_size
;
2879 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
2883 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
2886 count
= hdr
->issMax
;
2887 ss
= (char *) bfd_malloc (count
);
2890 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
2893 count
= hdr
->ipdMax
;
2894 for (i
= 0; i
< count
; i
++, rp
++, epdr
++)
2896 (*swap
->swap_pdr_in
) (abfd
, (PTR
) epdr
, &pdr
);
2897 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
2898 rp
->adr
= sym
.value
;
2899 rp
->regmask
= pdr
.regmask
;
2900 rp
->regoffset
= pdr
.regoffset
;
2901 rp
->fregmask
= pdr
.fregmask
;
2902 rp
->fregoffset
= pdr
.fregoffset
;
2903 rp
->frameoffset
= pdr
.frameoffset
;
2904 rp
->framereg
= pdr
.framereg
;
2905 rp
->pcreg
= pdr
.pcreg
;
2907 sv
[i
] = ss
+ sym
.iss
;
2908 sindex
+= strlen (sv
[i
]) + 1;
2912 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
2913 size
= BFD_ALIGN (size
, 16);
2914 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
2917 mips_elf_hash_table (info
)->procedure_count
= 0;
2921 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
2923 erp
= (struct rpdr_ext
*) rtproc
;
2924 memset (rp
, 0, sizeof (struct rpdr_ext
));
2926 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
2927 strcpy (str
, no_name_func
);
2928 str
+= strlen (no_name_func
) + 1;
2929 for (i
= 0; i
< count
; i
++)
2931 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
2932 strcpy (str
, sv
[i
]);
2933 str
+= strlen (sv
[i
]) + 1;
2935 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
2937 /* Set the size and contents of .rtproc section. */
2938 s
->_raw_size
= size
;
2939 s
->contents
= rtproc
;
2941 /* Skip this section later on (I don't think this currently
2942 matters, but someday it might). */
2943 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
2967 /* A comparison routine used to sort .gptab entries. */
2970 gptab_compare (p1
, p2
)
2974 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
2975 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
2977 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
2980 /* We need to use a special link routine to handle the .reginfo and
2981 the .mdebug sections. We need to merge all instances of these
2982 sections together, not write them all out sequentially. */
2985 mips_elf_final_link (abfd
, info
)
2987 struct bfd_link_info
*info
;
2991 struct bfd_link_order
*p
;
2992 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
2993 asection
*rtproc_sec
;
2994 Elf32_RegInfo reginfo
;
2995 struct ecoff_debug_info debug
;
2996 const struct ecoff_debug_swap
*swap
2997 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2998 HDRR
*symhdr
= &debug
.symbolic_header
;
2999 PTR mdebug_handle
= NULL
;
3001 /* Drop the .options section, since it has special semantics which I
3002 haven't bothered to figure out. */
3003 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
3005 if (strcmp ((*secpp
)->name
, ".options") == 0)
3007 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
3008 if (p
->type
== bfd_indirect_link_order
)
3009 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
3010 (*secpp
)->link_order_head
= NULL
;
3011 *secpp
= (*secpp
)->next
;
3012 --abfd
->section_count
;
3017 /* Get a value for the GP register. */
3018 if (elf_gp (abfd
) == 0)
3020 struct bfd_link_hash_entry
*h
;
3022 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
3023 if (h
!= (struct bfd_link_hash_entry
*) NULL
3024 && h
->type
== bfd_link_hash_defined
)
3025 elf_gp (abfd
) = (h
->u
.def
.value
3026 + h
->u
.def
.section
->output_section
->vma
3027 + h
->u
.def
.section
->output_offset
);
3028 else if (info
->relocateable
)
3032 /* Make up a value. */
3034 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3037 && (strcmp (o
->name
, ".sbss") == 0
3038 || strcmp (o
->name
, ".sdata") == 0
3039 || strcmp (o
->name
, ".lit4") == 0
3040 || strcmp (o
->name
, ".lit8") == 0))
3043 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
3047 /* If the relocate_section function needs to do a reloc
3048 involving the GP value, it should make a reloc_dangerous
3049 callback to warn that GP is not defined. */
3053 /* Go through the sections and collect the .reginfo and .mdebug
3057 gptab_data_sec
= NULL
;
3058 gptab_bss_sec
= NULL
;
3059 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3061 if (strcmp (o
->name
, ".reginfo") == 0)
3063 memset (®info
, 0, sizeof reginfo
);
3065 /* We have found the .reginfo section in the output file.
3066 Look through all the link_orders comprising it and merge
3067 the information together. */
3068 for (p
= o
->link_order_head
;
3069 p
!= (struct bfd_link_order
*) NULL
;
3072 asection
*input_section
;
3074 Elf32_External_RegInfo ext
;
3077 if (p
->type
!= bfd_indirect_link_order
)
3079 if (p
->type
== bfd_fill_link_order
)
3084 input_section
= p
->u
.indirect
.section
;
3085 input_bfd
= input_section
->owner
;
3087 /* The linker emulation code has probably clobbered the
3088 size to be zero bytes. */
3089 if (input_section
->_raw_size
== 0)
3090 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3092 if (! bfd_get_section_contents (input_bfd
, input_section
,
3098 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
3100 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
3101 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
3102 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
3103 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
3104 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
3106 /* ri_gp_value is set by the function
3107 mips_elf_section_processing when the section is
3108 finally written out. */
3110 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3111 elf_link_input_bfd ignores this section. */
3112 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3115 /* Force the section size to the value we want. */
3116 o
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3118 /* Skip this section later on (I don't think this currently
3119 matters, but someday it might). */
3120 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3125 if (strcmp (o
->name
, ".mdebug") == 0)
3127 struct extsym_info einfo
;
3129 /* We have found the .mdebug section in the output file.
3130 Look through all the link_orders comprising it and merge
3131 the information together. */
3132 symhdr
->magic
= swap
->sym_magic
;
3133 /* FIXME: What should the version stamp be? */
3135 symhdr
->ilineMax
= 0;
3139 symhdr
->isymMax
= 0;
3140 symhdr
->ioptMax
= 0;
3141 symhdr
->iauxMax
= 0;
3143 symhdr
->issExtMax
= 0;
3146 symhdr
->iextMax
= 0;
3148 /* We accumulate the debugging information itself in the
3149 debug_info structure. */
3151 debug
.external_dnr
= NULL
;
3152 debug
.external_pdr
= NULL
;
3153 debug
.external_sym
= NULL
;
3154 debug
.external_opt
= NULL
;
3155 debug
.external_aux
= NULL
;
3157 debug
.ssext
= debug
.ssext_end
= NULL
;
3158 debug
.external_fdr
= NULL
;
3159 debug
.external_rfd
= NULL
;
3160 debug
.external_ext
= debug
.external_ext_end
= NULL
;
3162 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
3163 if (mdebug_handle
== (PTR
) NULL
)
3166 if (SGI_COMPAT (abfd
))
3172 static const char * const name
[] =
3173 { ".text", ".init", ".fini", ".data",
3174 ".rodata", ".sdata", ".sbss", ".bss" };
3175 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
3176 scRData
, scSData
, scSBss
, scBss
};
3179 esym
.cobol_main
= 0;
3183 esym
.asym
.iss
= issNil
;
3184 esym
.asym
.st
= stLocal
;
3185 esym
.asym
.reserved
= 0;
3186 esym
.asym
.index
= indexNil
;
3187 for (i
= 0; i
< 8; i
++)
3189 esym
.asym
.sc
= sc
[i
];
3190 s
= bfd_get_section_by_name (abfd
, name
[i
]);
3193 esym
.asym
.value
= s
->vma
;
3194 last
= s
->vma
+ s
->_raw_size
;
3197 esym
.asym
.value
= last
;
3199 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
3205 for (p
= o
->link_order_head
;
3206 p
!= (struct bfd_link_order
*) NULL
;
3209 asection
*input_section
;
3211 const struct ecoff_debug_swap
*input_swap
;
3212 struct ecoff_debug_info input_debug
;
3216 if (p
->type
!= bfd_indirect_link_order
)
3218 if (p
->type
== bfd_fill_link_order
)
3223 input_section
= p
->u
.indirect
.section
;
3224 input_bfd
= input_section
->owner
;
3226 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
3227 || (get_elf_backend_data (input_bfd
)
3228 ->elf_backend_ecoff_debug_swap
) == NULL
)
3230 /* I don't know what a non MIPS ELF bfd would be
3231 doing with a .mdebug section, but I don't really
3232 want to deal with it. */
3236 input_swap
= (get_elf_backend_data (input_bfd
)
3237 ->elf_backend_ecoff_debug_swap
);
3239 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
3241 /* The ECOFF linking code expects that we have already
3242 read in the debugging information and set up an
3243 ecoff_debug_info structure, so we do that now. */
3244 if (! mips_elf_read_ecoff_info (input_bfd
, input_section
,
3248 if (! (bfd_ecoff_debug_accumulate
3249 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
3250 &input_debug
, input_swap
, info
)))
3253 /* Loop through the external symbols. For each one with
3254 interesting information, try to find the symbol in
3255 the linker global hash table and save the information
3256 for the output external symbols. */
3257 eraw_src
= input_debug
.external_ext
;
3258 eraw_end
= (eraw_src
3259 + (input_debug
.symbolic_header
.iextMax
3260 * input_swap
->external_ext_size
));
3262 eraw_src
< eraw_end
;
3263 eraw_src
+= input_swap
->external_ext_size
)
3267 struct mips_elf_link_hash_entry
*h
;
3269 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
3270 if (ext
.asym
.sc
== scNil
3271 || ext
.asym
.sc
== scUndefined
3272 || ext
.asym
.sc
== scSUndefined
)
3275 name
= input_debug
.ssext
+ ext
.asym
.iss
;
3276 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
3277 name
, false, false, true);
3278 if (h
== NULL
|| h
->esym
.ifd
!= -2)
3284 < input_debug
.symbolic_header
.ifdMax
);
3285 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
3291 /* Free up the information we just read. */
3292 free (input_debug
.line
);
3293 free (input_debug
.external_dnr
);
3294 free (input_debug
.external_pdr
);
3295 free (input_debug
.external_sym
);
3296 free (input_debug
.external_opt
);
3297 free (input_debug
.external_aux
);
3298 free (input_debug
.ss
);
3299 free (input_debug
.ssext
);
3300 free (input_debug
.external_fdr
);
3301 free (input_debug
.external_rfd
);
3302 free (input_debug
.external_ext
);
3304 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3305 elf_link_input_bfd ignores this section. */
3306 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3309 if (SGI_COMPAT (abfd
) && info
->shared
)
3311 /* Create .rtproc section. */
3312 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
3313 if (rtproc_sec
== NULL
)
3315 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3318 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
3319 if (rtproc_sec
== NULL
3320 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
3321 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 12))
3325 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
3326 info
, rtproc_sec
, &debug
))
3330 /* Build the external symbol information. */
3333 einfo
.debug
= &debug
;
3335 einfo
.failed
= false;
3336 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
3337 mips_elf_output_extsym
,
3342 /* Set the size of the .mdebug section. */
3343 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
3345 /* Skip this section later on (I don't think this currently
3346 matters, but someday it might). */
3347 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3352 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
3354 const char *subname
;
3357 Elf32_External_gptab
*ext_tab
;
3360 /* The .gptab.sdata and .gptab.sbss sections hold
3361 information describing how the small data area would
3362 change depending upon the -G switch. These sections
3363 not used in executables files. */
3364 if (! info
->relocateable
)
3368 for (p
= o
->link_order_head
;
3369 p
!= (struct bfd_link_order
*) NULL
;
3372 asection
*input_section
;
3374 if (p
->type
!= bfd_indirect_link_order
)
3376 if (p
->type
== bfd_fill_link_order
)
3381 input_section
= p
->u
.indirect
.section
;
3383 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3384 elf_link_input_bfd ignores this section. */
3385 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3388 /* Skip this section later on (I don't think this
3389 currently matters, but someday it might). */
3390 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3392 /* Really remove the section. */
3393 for (secpp
= &abfd
->sections
;
3395 secpp
= &(*secpp
)->next
)
3397 *secpp
= (*secpp
)->next
;
3398 --abfd
->section_count
;
3403 /* There is one gptab for initialized data, and one for
3404 uninitialized data. */
3405 if (strcmp (o
->name
, ".gptab.sdata") == 0)
3407 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
3411 (*_bfd_error_handler
)
3412 ("%s: illegal section name `%s'",
3413 bfd_get_filename (abfd
), o
->name
);
3414 bfd_set_error (bfd_error_nonrepresentable_section
);
3418 /* The linker script always combines .gptab.data and
3419 .gptab.sdata into .gptab.sdata, and likewise for
3420 .gptab.bss and .gptab.sbss. It is possible that there is
3421 no .sdata or .sbss section in the output file, in which
3422 case we must change the name of the output section. */
3423 subname
= o
->name
+ sizeof ".gptab" - 1;
3424 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
3426 if (o
== gptab_data_sec
)
3427 o
->name
= ".gptab.data";
3429 o
->name
= ".gptab.bss";
3430 subname
= o
->name
+ sizeof ".gptab" - 1;
3431 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
3434 /* Set up the first entry. */
3436 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
3439 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
3440 tab
[0].gt_header
.gt_unused
= 0;
3442 /* Combine the input sections. */
3443 for (p
= o
->link_order_head
;
3444 p
!= (struct bfd_link_order
*) NULL
;
3447 asection
*input_section
;
3451 bfd_size_type gpentry
;
3453 if (p
->type
!= bfd_indirect_link_order
)
3455 if (p
->type
== bfd_fill_link_order
)
3460 input_section
= p
->u
.indirect
.section
;
3461 input_bfd
= input_section
->owner
;
3463 /* Combine the gptab entries for this input section one
3464 by one. We know that the input gptab entries are
3465 sorted by ascending -G value. */
3466 size
= bfd_section_size (input_bfd
, input_section
);
3468 for (gpentry
= sizeof (Elf32_External_gptab
);
3470 gpentry
+= sizeof (Elf32_External_gptab
))
3472 Elf32_External_gptab ext_gptab
;
3473 Elf32_gptab int_gptab
;
3479 if (! (bfd_get_section_contents
3480 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
3481 gpentry
, sizeof (Elf32_External_gptab
))))
3487 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
3489 val
= int_gptab
.gt_entry
.gt_g_value
;
3490 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
3493 for (look
= 1; look
< c
; look
++)
3495 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
3496 tab
[look
].gt_entry
.gt_bytes
+= add
;
3498 if (tab
[look
].gt_entry
.gt_g_value
== val
)
3504 Elf32_gptab
*new_tab
;
3507 /* We need a new table entry. */
3508 new_tab
= ((Elf32_gptab
*)
3509 bfd_realloc ((PTR
) tab
,
3510 (c
+ 1) * sizeof (Elf32_gptab
)));
3511 if (new_tab
== NULL
)
3517 tab
[c
].gt_entry
.gt_g_value
= val
;
3518 tab
[c
].gt_entry
.gt_bytes
= add
;
3520 /* Merge in the size for the next smallest -G
3521 value, since that will be implied by this new
3524 for (look
= 1; look
< c
; look
++)
3526 if (tab
[look
].gt_entry
.gt_g_value
< val
3528 || (tab
[look
].gt_entry
.gt_g_value
3529 > tab
[max
].gt_entry
.gt_g_value
)))
3533 tab
[c
].gt_entry
.gt_bytes
+=
3534 tab
[max
].gt_entry
.gt_bytes
;
3539 last
= int_gptab
.gt_entry
.gt_bytes
;
3542 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3543 elf_link_input_bfd ignores this section. */
3544 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3547 /* The table must be sorted by -G value. */
3549 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
3551 /* Swap out the table. */
3552 ext_tab
= ((Elf32_External_gptab
*)
3553 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
3554 if (ext_tab
== NULL
)
3560 for (i
= 0; i
< c
; i
++)
3561 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
3564 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
3565 o
->contents
= (bfd_byte
*) ext_tab
;
3567 /* Skip this section later on (I don't think this currently
3568 matters, but someday it might). */
3569 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3573 /* Invoke the regular ELF backend linker to do all the work. */
3574 if (! bfd_elf32_bfd_final_link (abfd
, info
))
3577 /* Now write out the computed sections. */
3579 if (reginfo_sec
!= (asection
*) NULL
)
3581 Elf32_External_RegInfo ext
;
3583 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
3584 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
3585 (file_ptr
) 0, sizeof ext
))
3589 if (mdebug_sec
!= (asection
*) NULL
)
3591 BFD_ASSERT (abfd
->output_has_begun
);
3592 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
3594 mdebug_sec
->filepos
))
3597 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
3600 if (gptab_data_sec
!= (asection
*) NULL
)
3602 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
3603 gptab_data_sec
->contents
,
3605 gptab_data_sec
->_raw_size
))
3609 if (gptab_bss_sec
!= (asection
*) NULL
)
3611 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
3612 gptab_bss_sec
->contents
,
3614 gptab_bss_sec
->_raw_size
))
3618 if (SGI_COMPAT (abfd
))
3620 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
3621 if (rtproc_sec
!= NULL
)
3623 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
3624 rtproc_sec
->contents
,
3626 rtproc_sec
->_raw_size
))
3634 /* Handle a MIPS ELF HI16 reloc. */
3637 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
3639 Elf_Internal_Rela
*relhi
;
3640 Elf_Internal_Rela
*rello
;
3647 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
3649 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
3652 addend
+= ((insn
& 0xffff) << 16) + addlo
;
3654 if ((addlo
& 0x8000) != 0)
3656 if ((addend
& 0x8000) != 0)
3659 bfd_put_32 (input_bfd
,
3660 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
3661 contents
+ relhi
->r_offset
);
3664 /* Handle a MIPS ELF local GOT16 reloc. */
3667 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
3672 Elf_Internal_Rela
*relhi
;
3673 Elf_Internal_Rela
*rello
;
3683 bfd_byte
*got_contents
;
3684 struct mips_got_info
*g
;
3686 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
3688 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
3691 addend
+= ((insn
& 0xffff) << 16) + addlo
;
3693 if ((addlo
& 0x8000) != 0)
3695 if ((addend
& 0x8000) != 0)
3698 /* Get a got entry representing requested hipage. */
3699 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
3700 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
3701 BFD_ASSERT (g
!= NULL
);
3703 local_gotno
= g
->local_gotno
;
3704 got_contents
= sgot
->contents
;
3705 hipage
= addend
& 0xffff0000;
3707 for (i
= MIPS_RESERVED_GOTNO
; i
< local_gotno
; i
++)
3709 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
3710 if (hipage
== (address
& 0xffff0000))
3712 if (address
== (bfd_vma
) 0)
3714 bfd_put_32 (input_bfd
, hipage
, got_contents
+ i
* 4);
3719 BFD_ASSERT (i
< local_gotno
);
3721 if (i
== local_gotno
)
3722 (*_bfd_error_handler
)
3723 ("ELF MIPS linker: more got entries are needed for hipage: %x",
3727 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
3728 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
3729 contents
+ relhi
->r_offset
);
3732 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
3735 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
3737 Elf_Internal_Rela
*rel
;
3743 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3744 bfd_put_32 (input_bfd
,
3745 (insn
& 0xffff0000) | (offset
& 0xffff),
3746 contents
+ rel
->r_offset
);
3749 /* Relocate a MIPS ELF section. */
3752 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3753 contents
, relocs
, local_syms
, local_sections
)
3755 struct bfd_link_info
*info
;
3757 asection
*input_section
;
3759 Elf_Internal_Rela
*relocs
;
3760 Elf_Internal_Sym
*local_syms
;
3761 asection
**local_sections
;
3763 Elf_Internal_Shdr
*symtab_hdr
;
3766 asection
*sgot
, *sreloc
, *scpt
;
3768 Elf_Internal_Rela
*rel
;
3769 Elf_Internal_Rela
*relend
;
3770 struct mips_got_info
*g
;
3772 dynobj
= elf_hash_table (info
)->dynobj
;
3773 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3777 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
3780 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
3783 if (elf_bad_symtab (input_bfd
))
3785 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
3790 locsymcount
= symtab_hdr
->sh_info
;
3791 extsymoff
= symtab_hdr
->sh_info
;
3795 relend
= relocs
+ input_section
->reloc_count
;
3796 for (; rel
< relend
; rel
++)
3799 reloc_howto_type
*howto
;
3800 unsigned long r_symndx
;
3802 struct elf_link_hash_entry
*h
;
3804 Elf_Internal_Sym
*sym
;
3805 bfd_reloc_status_type r
;
3807 r_type
= ELF32_R_TYPE (rel
->r_info
);
3808 if (r_type
< 0 || r_type
>= (int) R_MIPS_max
)
3810 bfd_set_error (bfd_error_bad_value
);
3813 howto
= elf_mips_howto_table
+ r_type
;
3816 && (r_type
== R_MIPS_CALL16
3817 || r_type
== R_MIPS_GOT16
3818 || r_type
== R_MIPS_CALL_HI16
3819 || r_type
== R_MIPS_CALL_LO16
3820 || r_type
== R_MIPS_GOT_HI16
3821 || r_type
== R_MIPS_GOT_LO16
))
3823 /* We need the .got section. */
3826 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3827 BFD_ASSERT (sgot
!= NULL
);
3828 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
3829 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
3830 BFD_ASSERT (g
!= NULL
);
3834 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3836 /* Mix in the change in GP address for a GP relative reloc. */
3837 if (r_type
!= R_MIPS_GPREL16
3838 && r_type
!= R_MIPS_LITERAL
3839 && r_type
!= R_MIPS_GPREL32
)
3843 if (elf_gp (output_bfd
) == 0)
3845 if (! ((*info
->callbacks
->reloc_dangerous
)
3847 "GP relative relocation when GP not defined",
3848 input_bfd
, input_section
,
3851 /* Only give the error once per link. */
3852 elf_gp (output_bfd
) = 4;
3855 if (r_symndx
< extsymoff
3856 || (elf_bad_symtab (input_bfd
)
3857 && local_sections
[r_symndx
] != NULL
))
3859 /* This is a relocation against a section. The current
3860 addend in the instruction is the difference between
3861 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
3862 must change this to be the difference between the
3863 final definition (which will end up in RELOCATION)
3864 and the GP value of OUTPUT_BFD (which is in GP). */
3865 addend
= elf_gp (input_bfd
) - elf_gp (output_bfd
);
3867 else if (! info
->relocateable
)
3869 /* We are doing a final link. The current addend in the
3870 instruction is simply the desired offset into the
3871 symbol (normally zero). We want the instruction to
3872 hold the difference between the final definition of
3873 the symbol (which will end up in RELOCATION) and the
3874 GP value of OUTPUT_BFD (which is in GP). */
3875 addend
= - elf_gp (output_bfd
);
3879 /* We are generating relocateable output, and we aren't
3880 going to define this symbol, so we just leave the
3881 instruction alone. */
3889 if (info
->relocateable
)
3891 /* This is a relocateable link. We don't have to change
3892 anything, unless the reloc is against a section symbol,
3893 in which case we have to adjust according to where the
3894 section symbol winds up in the output section. */
3895 if (r_symndx
>= locsymcount
3896 || (elf_bad_symtab (input_bfd
)
3897 && local_sections
[r_symndx
] == NULL
))
3901 sym
= local_syms
+ r_symndx
;
3902 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
3906 sec
= local_sections
[r_symndx
];
3908 /* It would be logical to add sym->st_value here,
3909 but Irix 5 sometimes generates a garbage symbol
3911 addend
+= sec
->output_offset
;
3913 /* If this is HI16 or GOT16 with an associated LO16,
3914 adjust the addend accordingly. Otherwise, just
3916 if ((r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
3917 || (rel
+ 1) >= relend
3918 || ELF32_R_TYPE ((rel
+ 1)->r_info
) != R_MIPS_LO16
)
3919 r
= _bfd_relocate_contents (howto
, input_bfd
,
3921 contents
+ rel
->r_offset
);
3924 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1,
3936 /* This is a final link. */
3938 if (r_symndx
< extsymoff
3939 || (elf_bad_symtab (input_bfd
)
3940 && local_sections
[r_symndx
] != NULL
))
3943 sym
= local_syms
+ r_symndx
;
3944 sec
= local_sections
[r_symndx
];
3945 relocation
= (sec
->output_section
->vma
3946 + sec
->output_offset
);
3948 /* It would be logical to always add sym->st_value here,
3949 but Irix 5 sometimes generates a garbage symbol
3951 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
3952 relocation
+= sym
->st_value
;
3959 indx
= r_symndx
- extsymoff
;
3960 h
= elf_sym_hashes (input_bfd
)[indx
];
3961 while (h
->root
.type
== bfd_link_hash_indirect
3962 || h
->root
.type
== bfd_link_hash_warning
)
3963 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3964 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
3966 if (elf_gp (output_bfd
) == 0)
3968 if (! ((*info
->callbacks
->reloc_dangerous
)
3970 "_gp_disp used when GP not defined",
3971 input_bfd
, input_section
,
3974 /* Only give the error once per link. */
3975 elf_gp (output_bfd
) = 4;
3980 sec
= input_section
;
3981 if (sec
->output_section
!= NULL
)
3982 relocation
= (elf_gp (output_bfd
)
3984 + sec
->output_section
->vma
3985 + sec
->output_offset
));
3987 relocation
= elf_gp (output_bfd
) - rel
->r_offset
;
3988 if (r_type
== R_MIPS_LO16
)
3992 else if (h
->root
.type
== bfd_link_hash_defined
3993 || h
->root
.type
== bfd_link_hash_defweak
)
3995 sec
= h
->root
.u
.def
.section
;
3996 if (sec
->output_section
== NULL
)
3999 relocation
= (h
->root
.u
.def
.value
4000 + sec
->output_section
->vma
4001 + sec
->output_offset
);
4003 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4005 else if (info
->shared
&& ! info
->symbolic
)
4007 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
4009 /* If this is a dynamic link, we should have created
4010 a _DYNAMIC_LINK symbol in
4011 mips_elf_create_dynamic_sections. Otherwise, we
4012 should define the symbol with a value of 0.
4013 FIXME: It should probably get into the symbol
4014 table somehow as well. */
4015 BFD_ASSERT (! info
->shared
);
4016 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
4017 ".dynamic") == NULL
);
4022 if (! ((*info
->callbacks
->undefined_symbol
)
4023 (info
, h
->root
.root
.string
, input_bfd
,
4024 input_section
, rel
->r_offset
)))
4030 if (r_type
== R_MIPS_HI16
4031 && (rel
+ 1) < relend
4032 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
4034 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1,
4035 contents
, relocation
+ addend
);
4038 else if (r_type
== R_MIPS_GOT16
&& local
)
4040 /* GOT16 must be also with associated LO16 in the local
4041 case. In this case, the addend is extracted and the
4042 section in which the referenced object is determined.
4043 Then the final address of the object is computed and
4044 the GOT entry for the hipage (an aligned 64kb chunk)
4045 is added to .got section if needed. The offset field
4046 of the GOT16-relocated instruction is replaced by the
4047 index of this GOT entry for the hipage. */
4048 if ((rel
+ 1) < relend
4049 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
4051 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
,
4054 relocation
+ addend
);
4058 r
= bfd_reloc_outofrange
;
4060 else if (r_type
== R_MIPS_CALL16
4061 || r_type
== R_MIPS_GOT16
4062 || r_type
== R_MIPS_CALL_LO16
4063 || r_type
== R_MIPS_GOT_LO16
)
4067 /* This symbol must be registered as a global symbol
4068 having the corresponding got entry. */
4069 BFD_ASSERT (h
->got_offset
!= (bfd_vma
) -1);
4071 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
4072 BFD_ASSERT (g
->local_gotno
<= offset
4073 && offset
< sgot
->_raw_size
);
4074 bfd_put_32 (output_bfd
, relocation
+ addend
,
4075 sgot
->contents
+ offset
);
4076 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
4077 + offset
- elf_gp (output_bfd
));
4078 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
4082 else if (r_type
== R_MIPS_CALL_HI16
4083 || r_type
== R_MIPS_GOT_HI16
)
4087 /* This must be a global symbol with a got entry. The
4088 next reloc must be the corresponding LO16 reloc. */
4089 BFD_ASSERT (h
!= NULL
&& h
->got_offset
!= (bfd_vma
) -1);
4090 BFD_ASSERT ((rel
+ 1) < relend
);
4091 BFD_ASSERT (ELF32_R_TYPE ((rel
+ 1)->r_info
)
4092 == (r_type
== R_MIPS_CALL_HI16
4094 : R_MIPS_GOT_LO16
));
4096 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
4097 BFD_ASSERT (g
->local_gotno
<= offset
4098 && offset
< sgot
->_raw_size
);
4099 bfd_put_32 (output_bfd
, relocation
+ addend
,
4100 sgot
->contents
+ offset
);
4101 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
4102 + offset
- elf_gp (output_bfd
));
4103 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
4107 else if (r_type
== R_MIPS_REL32
4108 || r_type
== R_MIPS_32
)
4110 Elf_Internal_Rel outrel
;
4111 Elf32_crinfo cptrel
;
4115 && (input_section
->flags
& SEC_ALLOC
) != 0)
4117 /* When generating a shared object, these
4118 relocations are copied into the output file to be
4119 resolved at run time. */
4122 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
4123 BFD_ASSERT (sreloc
!= NULL
);
4126 outrel
.r_offset
= (rel
->r_offset
4127 + input_section
->output_section
->vma
4128 + input_section
->output_offset
);
4130 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4133 && (! info
->symbolic
4134 || (h
->elf_link_hash_flags
4135 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4137 BFD_ASSERT (h
->dynindx
!= -1);
4138 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
4139 sec
= input_section
;
4146 sec
= local_sections
[r_symndx
];
4149 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
4151 == bfd_link_hash_defweak
));
4152 sec
= h
->root
.u
.def
.section
;
4154 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
4156 else if (sec
== NULL
|| sec
->owner
== NULL
)
4158 bfd_set_error (bfd_error_bad_value
);
4165 osec
= sec
->output_section
;
4166 indx
= elf_section_data (osec
)->dynindx
;
4171 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
4172 addend
+= relocation
;
4175 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
4176 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
4177 (((Elf32_External_Rel
*)
4179 + sreloc
->reloc_count
));
4180 ++sreloc
->reloc_count
;
4182 if (SGI_COMPAT (output_bfd
))
4187 /* Make an entry of compact relocation info. */
4188 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
4189 cptrel
.vaddr
= (rel
->r_offset
4190 + input_section
->output_section
->vma
4191 + input_section
->output_offset
);
4192 if (r_type
== R_MIPS_REL32
)
4193 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
4195 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
4196 mips_elf_set_cr_dist2to (cptrel
, 0);
4197 cptrel
.konst
= addend
;
4199 cr
= (scpt
->contents
4200 + sizeof (Elf32_External_compact_rel
));
4201 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4202 ((Elf32_External_crinfo
*) cr
4203 + scpt
->reloc_count
));
4204 ++scpt
->reloc_count
;
4207 /* This reloc will be computed at runtime, so
4208 there's no need to do anything now. */
4212 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4213 contents
, rel
->r_offset
,
4214 relocation
, addend
);
4217 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4218 contents
, rel
->r_offset
,
4219 relocation
, addend
);
4221 if (SGI_COMPAT (abfd
)
4223 && (input_section
->flags
& SEC_ALLOC
) != 0)
4225 Elf32_crinfo cptrel
;
4228 /* Make an entry of compact relocation info. */
4229 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
4230 cptrel
.vaddr
= (rel
->r_offset
4231 + input_section
->output_section
->vma
4232 + input_section
->output_offset
);
4237 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
4238 /* XXX How should we set dist2to in this case. */
4239 mips_elf_set_cr_dist2to (cptrel
, 8);
4240 cptrel
.konst
= addend
+ relocation
;
4241 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
4242 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4243 ((Elf32_External_crinfo
*) cr
4244 + scpt
->reloc_count
));
4245 ++scpt
->reloc_count
;
4248 case R_MIPS_GPREL16
:
4249 case R_MIPS_LITERAL
:
4250 case R_MIPS_GPREL32
:
4251 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
4252 cptrel
.konst
= elf_gp (output_bfd
) - cptrel
.vaddr
;
4253 mips_elf_set_cr_dist2to (cptrel
, 4);
4254 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
4255 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4256 ((Elf32_External_crinfo
*) cr
4257 + scpt
->reloc_count
));
4258 ++scpt
->reloc_count
;
4267 if (r
!= bfd_reloc_ok
)
4272 case bfd_reloc_outofrange
:
4274 case bfd_reloc_overflow
:
4279 name
= h
->root
.root
.string
;
4282 name
= bfd_elf_string_from_elf_section (input_bfd
,
4283 symtab_hdr
->sh_link
,
4288 name
= bfd_section_name (input_bfd
, sec
);
4290 if (! ((*info
->callbacks
->reloc_overflow
)
4291 (info
, name
, howto
->name
, (bfd_vma
) 0,
4292 input_bfd
, input_section
, rel
->r_offset
)))
4303 /* Functions for the dynamic linker. */
4305 /* The name of the dynamic interpreter. This is put in the .interp
4308 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
4310 /* Create dynamic sections when linking against a dynamic object. */
4313 mips_elf_create_dynamic_sections (abfd
, info
)
4315 struct bfd_link_info
*info
;
4317 struct elf_link_hash_entry
*h
;
4319 register asection
*s
;
4320 const char * const *namep
;
4322 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4325 /* Mips ABI requests the .dynamic section to be read only. */
4326 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4329 if (! bfd_set_section_flags (abfd
, s
, flags
))
4333 /* We need to create .got section. */
4334 if (! mips_elf_create_got_section (abfd
, info
))
4337 /* Create .stub section. */
4338 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
4340 s
= bfd_make_section (abfd
, ".stub");
4342 || ! bfd_set_section_flags (abfd
, s
, flags
)
4343 || ! bfd_set_section_alignment (abfd
, s
, 2))
4347 if (SGI_COMPAT (abfd
))
4349 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
4352 if (! (_bfd_generic_link_add_one_symbol
4353 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
4354 (bfd_vma
) 0, (const char *) NULL
, false,
4355 get_elf_backend_data (abfd
)->collect
,
4356 (struct bfd_link_hash_entry
**) &h
)))
4358 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
4359 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4360 h
->type
= STT_SECTION
;
4362 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4366 /* We need to create a .compact_rel section. */
4367 if (! mips_elf_create_compact_rel_section (abfd
, info
))
4370 /* Change aligments of some sections. */
4371 s
= bfd_get_section_by_name (abfd
, ".hash");
4373 bfd_set_section_alignment (abfd
, s
, 4);
4374 s
= bfd_get_section_by_name (abfd
, ".dynsym");
4376 bfd_set_section_alignment (abfd
, s
, 4);
4377 s
= bfd_get_section_by_name (abfd
, ".dynstr");
4379 bfd_set_section_alignment (abfd
, s
, 4);
4380 s
= bfd_get_section_by_name (abfd
, ".reginfo");
4382 bfd_set_section_alignment (abfd
, s
, 4);
4383 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4385 bfd_set_section_alignment (abfd
, s
, 4);
4391 if (! (_bfd_generic_link_add_one_symbol
4392 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
4393 (bfd_vma
) 0, (const char *) NULL
, false,
4394 get_elf_backend_data (abfd
)->collect
,
4395 (struct bfd_link_hash_entry
**) &h
)))
4397 h
->elf_link_hash_flags
^=~ ELF_LINK_NON_ELF
;
4398 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4399 h
->type
= STT_SECTION
;
4401 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4408 /* Create the .compact_rel section. */
4411 mips_elf_create_compact_rel_section (abfd
, info
)
4413 struct bfd_link_info
*info
;
4416 register asection
*s
;
4418 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
4420 flags
= SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_READONLY
;
4422 s
= bfd_make_section (abfd
, ".compact_rel");
4424 || ! bfd_set_section_flags (abfd
, s
, flags
)
4425 || ! bfd_set_section_alignment (abfd
, s
, 2))
4428 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
4434 /* Create the .got section to hold the global offset table. */
4437 mips_elf_create_got_section (abfd
, info
)
4439 struct bfd_link_info
*info
;
4442 register asection
*s
;
4443 struct elf_link_hash_entry
*h
;
4444 struct mips_got_info
*g
;
4446 /* This function may be called more than once. */
4447 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
4450 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
4452 s
= bfd_make_section (abfd
, ".got");
4454 || ! bfd_set_section_flags (abfd
, s
, flags
)
4455 || ! bfd_set_section_alignment (abfd
, s
, 4))
4458 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
4459 linker script because we don't want to define the symbol if we
4460 are not creating a global offset table. */
4462 if (! (_bfd_generic_link_add_one_symbol
4463 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
4464 (bfd_vma
) 0, (const char *) NULL
, false,
4465 get_elf_backend_data (abfd
)->collect
,
4466 (struct bfd_link_hash_entry
**) &h
)))
4468 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
4469 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4470 h
->type
= STT_OBJECT
;
4473 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4476 /* The first several global offset table entries are reserved. */
4477 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
4479 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
4480 sizeof (struct mips_got_info
));
4483 g
->global_gotsym
= 0;
4484 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
4485 if (elf_section_data (s
) == NULL
)
4488 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
4489 if (elf_section_data (s
) == NULL
)
4492 elf_section_data (s
)->tdata
= (PTR
) g
;
4497 /* Look through the relocs for a section during the first phase, and
4498 allocate space in the global offset table. */
4501 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
4503 struct bfd_link_info
*info
;
4505 const Elf_Internal_Rela
*relocs
;
4508 Elf_Internal_Shdr
*symtab_hdr
;
4509 struct elf_link_hash_entry
**sym_hashes
;
4510 struct mips_got_info
*g
;
4512 const Elf_Internal_Rela
*rel
;
4513 const Elf_Internal_Rela
*rel_end
;
4517 if (info
->relocateable
)
4520 dynobj
= elf_hash_table (info
)->dynobj
;
4521 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4522 sym_hashes
= elf_sym_hashes (abfd
);
4523 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
4528 rel_end
= relocs
+ sec
->reloc_count
;
4529 for (rel
= relocs
; rel
< rel_end
; rel
++)
4531 unsigned long r_symndx
;
4532 struct elf_link_hash_entry
*h
;
4534 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4536 if (r_symndx
< extsymoff
)
4539 h
= sym_hashes
[r_symndx
- extsymoff
];
4541 /* Some relocs require a global offset table. */
4544 switch (ELF32_R_TYPE (rel
->r_info
))
4548 case R_MIPS_CALL_HI16
:
4549 case R_MIPS_CALL_LO16
:
4550 case R_MIPS_GOT_HI16
:
4551 case R_MIPS_GOT_LO16
:
4552 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
4553 if (! mips_elf_create_got_section (dynobj
, info
))
4562 switch (ELF32_R_TYPE (rel
->r_info
))
4565 case R_MIPS_CALL_HI16
:
4566 case R_MIPS_CALL_LO16
:
4567 /* This symbol requires a global offset table entry. */
4570 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4571 BFD_ASSERT (sgot
!= NULL
);
4572 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4573 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4574 BFD_ASSERT (g
!= NULL
);
4577 BFD_ASSERT (h
!= NULL
);
4579 /* Make sure this symbol is output as a dynamic symbol. */
4580 if (h
->dynindx
== -1)
4582 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4586 if (h
->got_offset
!= (bfd_vma
) -1)
4588 /* We have already allocated space in the .got. */
4592 /* Note the index of the first global got symbol in .dynsym. */
4593 if (g
->global_gotsym
== 0
4594 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
4595 g
->global_gotsym
= h
->dynindx
;
4597 /* Make this symbol to have the corresponding got entry. */
4600 /* We need a stub, not a plt entry for the undefined
4601 function. But we record it as if it needs plt. See
4602 elf_adjust_dynamic_symbol in elflink.h. */
4603 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
4609 case R_MIPS_GOT_HI16
:
4610 case R_MIPS_GOT_LO16
:
4611 /* This symbol requires a global offset table entry. */
4614 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4615 BFD_ASSERT (sgot
!= NULL
);
4616 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4617 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4618 BFD_ASSERT (g
!= NULL
);
4623 /* Make sure this symbol is output as a dynamic symbol. */
4624 if (h
->dynindx
== -1)
4626 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4630 if (h
->got_offset
!= (bfd_vma
) -1)
4632 /* We have already allocated space in the .got. */
4635 /* Note the index of the first global got symbol in
4637 if (g
->global_gotsym
== 0
4638 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
4639 g
->global_gotsym
= h
->dynindx
;
4641 /* Make this symbol to be the global got symbol. */
4650 && (sec
->flags
& SEC_ALLOC
) != 0)
4652 /* When creating a shared object, we must copy these
4653 reloc types into the output file as R_MIPS_REL32
4654 relocs. We create the .rel.dyn reloc section in
4655 dynobj and make room for this reloc. */
4658 const char *name
= ".rel.dyn";
4660 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4663 sreloc
= bfd_make_section (dynobj
, name
);
4665 || ! bfd_set_section_flags (dynobj
, sreloc
,
4671 || ! bfd_set_section_alignment (dynobj
, sreloc
, 4))
4674 /* Add a null element. */
4675 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
4676 ++sreloc
->reloc_count
;
4680 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
4683 if (SGI_COMPAT (abfd
))
4684 mips_elf_hash_table (info
)->compact_rel_size
+=
4685 sizeof (Elf32_External_crinfo
);
4690 case R_MIPS_GPREL16
:
4691 case R_MIPS_LITERAL
:
4692 case R_MIPS_GPREL32
:
4693 if (SGI_COMPAT (abfd
))
4694 mips_elf_hash_table (info
)->compact_rel_size
+=
4695 sizeof (Elf32_External_crinfo
);
4706 /* Adjust a symbol defined by a dynamic object and referenced by a
4707 regular object. The current definition is in some section of the
4708 dynamic object, but we're not including those sections. We have to
4709 change the definition to something the rest of the link can
4713 mips_elf_adjust_dynamic_symbol (info
, h
)
4714 struct bfd_link_info
*info
;
4715 struct elf_link_hash_entry
*h
;
4720 dynobj
= elf_hash_table (info
)->dynobj
;
4722 /* Make sure we know what is going on here. */
4723 BFD_ASSERT (dynobj
!= NULL
4724 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
4725 || h
->weakdef
!= NULL
4726 || ((h
->elf_link_hash_flags
4727 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4728 && (h
->elf_link_hash_flags
4729 & ELF_LINK_HASH_REF_REGULAR
) != 0
4730 && (h
->elf_link_hash_flags
4731 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
4733 /* For a function, create a stub, if needed. */
4734 if (h
->type
== STT_FUNC
4735 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4737 if (! elf_hash_table (info
)->dynamic_sections_created
)
4740 /* If this symbol is not defined in a regular file, then set
4741 the symbol to the stub location. This is required to make
4742 function pointers compare as equal between the normal
4743 executable and the shared library. */
4744 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4746 /* We need .stub section. */
4747 s
= bfd_get_section_by_name (dynobj
, ".stub");
4748 BFD_ASSERT (s
!= NULL
);
4750 h
->root
.u
.def
.section
= s
;
4751 h
->root
.u
.def
.value
= s
->_raw_size
;
4753 /* XXX Write this stub address somewhere. */
4754 h
->plt_offset
= s
->_raw_size
;
4756 /* Make room for this stub code. */
4757 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
4759 /* The last half word of the stub will be filled with the index
4760 of this symbol in .dynsym section. */
4765 /* If this is a weak symbol, and there is a real definition, the
4766 processor independent code will have arranged for us to see the
4767 real definition first, and we can just use the same value. */
4768 if (h
->weakdef
!= NULL
)
4770 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
4771 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
4772 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
4773 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
4777 /* This is a reference to a symbol defined by a dynamic object which
4778 is not a function. */
4783 /* Set the sizes of the dynamic sections. */
4786 mips_elf_size_dynamic_sections (output_bfd
, info
)
4788 struct bfd_link_info
*info
;
4794 struct mips_got_info
*g
;
4796 dynobj
= elf_hash_table (info
)->dynobj
;
4797 BFD_ASSERT (dynobj
!= NULL
);
4799 if (elf_hash_table (info
)->dynamic_sections_created
)
4801 /* Set the contents of the .interp section to the interpreter. */
4804 s
= bfd_get_section_by_name (dynobj
, ".interp");
4805 BFD_ASSERT (s
!= NULL
);
4806 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4807 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4811 /* Recompute the size of .got for local entires (reserved and
4812 hipages) if needed. To estimate it, get the upper bound of total
4813 size of loadable sections. */
4814 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4818 bfd_size_type loadable_size
= 0;
4819 bfd_size_type local_gotno
;
4822 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4823 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4824 BFD_ASSERT (g
!= NULL
);
4826 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
4827 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
4829 if ((s
->flags
& SEC_ALLOC
) == 0)
4831 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
4834 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
4836 /* Assume there are two loadable segments consisting of
4837 contiguous sections. Is 5 enough? */
4838 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
4839 g
->local_gotno
= local_gotno
;
4840 sgot
->_raw_size
+= local_gotno
* 4;
4843 /* The check_relocs and adjust_dynamic_symbol entry points have
4844 determined the sizes of the various dynamic sections. Allocate
4847 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4852 /* It's OK to base decisions on the section name, because none
4853 of the dynobj section names depend upon the input files. */
4854 name
= bfd_get_section_name (dynobj
, s
);
4856 if ((s
->flags
& SEC_IN_MEMORY
) == 0)
4861 if (strncmp (name
, ".rel", 4) == 0)
4863 if (s
->_raw_size
== 0)
4869 /* If this relocation section applies to a read only
4870 section, then we probably need a DT_TEXTREL entry.
4871 If the relocation section is .rel.dyn, we always
4872 assert a DT_TEXTREL entry rather than testing whether
4873 there exists a relocation to a read only section or
4875 target
= bfd_get_section_by_name (output_bfd
, name
+ 4);
4876 if ((target
!= NULL
&& (target
->flags
& SEC_READONLY
) != 0)
4877 || strcmp (name
, ".rel.dyn") == 0)
4880 /* We use the reloc_count field as a counter if we need
4881 to copy relocs into the output file. */
4882 if (strcmp (name
, ".rel.dyn") != 0)
4886 else if (strncmp (name
, ".got", 4) == 0)
4890 BFD_ASSERT (elf_section_data (s
) != NULL
);
4891 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
4892 BFD_ASSERT (g
!= NULL
);
4894 /* Fix the size of .got section for the correspondence of
4895 global symbols and got entries. This adds some useless
4896 got entries. Is this required by ABI really? */
4897 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
4898 s
->_raw_size
+= i
* 4;
4900 else if (strncmp (name
, ".stub", 5) == 0)
4902 /* Irix rld assumes that the function stub isn't at the end
4903 of .text section. So put a dummy. XXX */
4904 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
4906 else if (SGI_COMPAT (output_bfd
)
4907 && strncmp (name
, ".compact_rel", 12) == 0)
4908 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
4909 else if (strncmp (name
, ".init", 5) != 0)
4911 /* It's not one of our sections, so don't allocate space. */
4919 for (spp
= &s
->output_section
->owner
->sections
;
4920 *spp
!= s
->output_section
;
4921 spp
= &(*spp
)->next
)
4923 *spp
= s
->output_section
->next
;
4924 --s
->output_section
->owner
->section_count
;
4929 /* Allocate memory for the section contents. */
4930 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
4931 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
4933 bfd_set_error (bfd_error_no_memory
);
4936 memset (s
->contents
, 0, s
->_raw_size
);
4939 if (elf_hash_table (info
)->dynamic_sections_created
)
4941 /* Add some entries to the .dynamic section. We fill in the
4942 values later, in elf_mips_finish_dynamic_sections, but we
4943 must add the entries now so that we get the correct size for
4944 the .dynamic section. The DT_DEBUG entry is filled in by the
4945 dynamic linker and used by the debugger. */
4948 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
4954 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
4958 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
4961 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
4963 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
4966 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
4969 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
4973 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
4976 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
4979 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
4981 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
4984 s
= bfd_get_section_by_name (dynobj
, ".liblist");
4985 BFD_ASSERT (s
!= NULL
);
4987 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
4991 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
4994 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
4998 /* Time stamps in executable files are a bad idea. */
4999 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
5004 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
5009 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
5013 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
5016 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
5019 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
5022 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
5025 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
5028 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
5031 #if 0 /* (SGI_COMPAT) */
5032 if (! bfd_get_section_by_name (dynobj
, ".init"))
5033 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
5036 if (! bfd_get_section_by_name (dynobj
, ".fini"))
5037 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
5042 /* If we use dynamic linking, we generate a section symbol for each
5043 output section. These are local symbols, which means that they
5044 must come first in the dynamic symbol table.
5045 That means we must increment the dynamic symbol index of every
5046 other dynamic symbol. */
5048 const char * const *namep
;
5050 bfd_size_type strindex
;
5051 struct bfd_strtab_hash
*dynstr
;
5052 struct mips_got_info
*g
;
5054 if (elf_hash_table (info
)->dynamic_sections_created
)
5056 if (SGI_COMPAT (output_bfd
))
5058 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
5059 elf_link_hash_traverse (elf_hash_table (info
),
5060 mips_elf_adjust_dynindx
,
5062 elf_hash_table (info
)->dynsymcount
+= c
;
5064 dynstr
= elf_hash_table (info
)->dynstr
;
5065 BFD_ASSERT (dynstr
!= NULL
);
5067 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
5071 s
= bfd_get_section_by_name (output_bfd
, *namep
);
5073 elf_section_data (s
)->dynindx
= i
;
5075 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
5076 if (strindex
== (bfd_size_type
) -1)
5079 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
5084 c
= bfd_count_sections (output_bfd
);
5085 elf_link_hash_traverse (elf_hash_table (info
),
5086 mips_elf_adjust_dynindx
,
5088 elf_hash_table (info
)->dynsymcount
+= c
;
5090 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
5092 elf_section_data (s
)->dynindx
= i
;
5093 /* These symbols will have no names, so we don't need to
5094 fiddle with dynstr_index. */
5099 s
= bfd_get_section_by_name (dynobj
, ".got");
5100 BFD_ASSERT (s
!= NULL
);
5101 BFD_ASSERT (elf_section_data (s
) != NULL
);
5102 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
5103 BFD_ASSERT (g
!= NULL
);
5105 /* If there are no global got symbols, fake the last symbol so for
5107 if (g
->global_gotsym
)
5108 g
->global_gotsym
+= c
;
5110 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
5116 /* Increment the index of a dynamic symbol by a given amount. Called
5117 via elf_link_hash_traverse. */
5120 mips_elf_adjust_dynindx (h
, cparg
)
5121 struct elf_link_hash_entry
*h
;
5124 unsigned int *cp
= (unsigned int *) cparg
;
5126 if (h
->dynindx
!= -1)
5131 /* Finish up dynamic symbol handling. We set the contents of various
5132 dynamic sections here. */
5135 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
5137 struct bfd_link_info
*info
;
5138 struct elf_link_hash_entry
*h
;
5139 Elf_Internal_Sym
*sym
;
5144 struct mips_got_info
*g
;
5147 dynobj
= elf_hash_table (info
)->dynobj
;
5148 gval
= sym
->st_value
;
5150 if (h
->plt_offset
!= (bfd_vma
) -1)
5154 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
5156 /* This symbol has a stub. Set it up. */
5158 BFD_ASSERT (h
->dynindx
!= -1);
5160 s
= bfd_get_section_by_name (dynobj
, ".stub");
5161 BFD_ASSERT (s
!= NULL
);
5163 /* Fill the stub. */
5165 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
5167 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
5170 /* FIXME: Can h->dynindex be more than 64K? */
5171 if (h
->dynindx
& 0xffff0000)
5174 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
5176 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
5178 BFD_ASSERT (h
->plt_offset
<= s
->_raw_size
);
5179 memcpy (s
->contents
+ h
->plt_offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
5181 /* Mark the symbol as undefined. plt_offset != -1 occurs
5182 only for the referenced symbol. */
5183 sym
->st_shndx
= SHN_UNDEF
;
5185 /* The run-time linker uses the st_value field of the symbol
5186 to reset the global offset table entry for this external
5187 to its stub address when unlinking a shared object. */
5188 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt_offset
;
5189 sym
->st_value
= gval
;
5192 BFD_ASSERT (h
->dynindx
!= -1);
5194 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5195 BFD_ASSERT (sgot
!= NULL
);
5196 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5197 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5198 BFD_ASSERT (g
!= NULL
);
5200 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
5202 bfd_size_type offset
;
5204 /* This symbol has an entry in the global offset table. Set its
5205 value to the corresponding got entry, if needed. */
5206 if (h
->got_offset
== (bfd_vma
) -1)
5208 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5209 BFD_ASSERT (g
->local_gotno
* 4 <= offset
5210 && offset
< sgot
->_raw_size
);
5211 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
5215 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
5216 name
= h
->root
.root
.string
;
5217 if (strcmp (name
, "_DYNAMIC") == 0
5218 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
5219 sym
->st_shndx
= SHN_ABS
;
5220 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
5222 sym
->st_shndx
= SHN_ABS
;
5223 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5226 else if (SGI_COMPAT (output_bfd
))
5228 if (strcmp (name
, "_gp_disp") == 0)
5230 sym
->st_shndx
= SHN_ABS
;
5231 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5232 sym
->st_value
= elf_gp (output_bfd
);
5234 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
5235 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
5237 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5238 sym
->st_other
= STO_PROTECTED
;
5240 sym
->st_shndx
= SHN_MIPS_DATA
;
5242 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
5244 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5245 sym
->st_other
= STO_PROTECTED
;
5246 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
5247 sym
->st_shndx
= SHN_ABS
;
5249 else if (sym
->st_shndx
!= SHN_UNDEF
)
5251 if (h
->type
== STT_FUNC
)
5252 sym
->st_shndx
= SHN_MIPS_TEXT
;
5253 else if (h
->type
== STT_OBJECT
)
5254 sym
->st_shndx
= SHN_MIPS_DATA
;
5261 /* Finish up the dynamic sections. */
5264 mips_elf_finish_dynamic_sections (output_bfd
, info
)
5266 struct bfd_link_info
*info
;
5271 struct mips_got_info
*g
;
5273 dynobj
= elf_hash_table (info
)->dynobj
;
5275 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5277 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5278 BFD_ASSERT (sgot
!= NULL
);
5280 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5281 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5282 BFD_ASSERT (g
!= NULL
);
5284 if (elf_hash_table (info
)->dynamic_sections_created
)
5286 Elf32_External_Dyn
*dyncon
, *dynconend
;
5288 BFD_ASSERT (sdyn
!= NULL
);
5290 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5291 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
5292 for (; dyncon
< dynconend
; dyncon
++)
5294 Elf_Internal_Dyn dyn
;
5299 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5307 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5308 BFD_ASSERT (s
!= NULL
);
5309 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
5310 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5314 /* Rewrite DT_STRSZ. */
5316 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
5317 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5323 case DT_MIPS_CONFLICT
:
5326 case DT_MIPS_LIBLIST
:
5329 s
= bfd_get_section_by_name (output_bfd
, name
);
5330 BFD_ASSERT (s
!= NULL
);
5331 dyn
.d_un
.d_ptr
= s
->vma
;
5332 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5335 case DT_MIPS_RLD_VERSION
:
5336 dyn
.d_un
.d_val
= 1; /* XXX */
5337 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5341 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
5342 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5345 case DT_MIPS_CONFLICTNO
:
5347 elemsize
= sizeof (Elf32_Conflict
);
5350 case DT_MIPS_LIBLISTNO
:
5352 elemsize
= sizeof (Elf32_Lib
);
5354 s
= bfd_get_section_by_name (output_bfd
, name
);
5357 if (s
->_cooked_size
!= 0)
5358 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5360 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5365 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5368 case DT_MIPS_TIME_STAMP
:
5369 time ((time_t *) &dyn
.d_un
.d_val
);
5370 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5373 case DT_MIPS_ICHECKSUM
:
5377 case DT_MIPS_IVERSION
:
5381 case DT_MIPS_BASE_ADDRESS
:
5382 s
= output_bfd
->sections
;
5383 BFD_ASSERT (s
!= NULL
);
5384 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
5385 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5388 case DT_MIPS_LOCAL_GOTNO
:
5389 dyn
.d_un
.d_val
= g
->local_gotno
;
5390 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5393 case DT_MIPS_SYMTABNO
:
5395 elemsize
= sizeof (Elf32_External_Sym
);
5396 s
= bfd_get_section_by_name (output_bfd
, name
);
5397 BFD_ASSERT (s
!= NULL
);
5399 if (s
->_cooked_size
!= 0)
5400 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5402 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5403 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5406 case DT_MIPS_UNREFEXTNO
:
5408 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
5409 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5412 case DT_MIPS_GOTSYM
:
5413 dyn
.d_un
.d_val
= g
->global_gotsym
;
5414 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5417 case DT_MIPS_HIPAGENO
:
5418 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
5419 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5426 /* The first entry of the global offset table will be filled at
5427 runtime. The second entry will be used by some runtime loaders.
5428 This isn't the case of Irix rld. */
5429 if (sgot
->_raw_size
> 0)
5431 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
5432 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
5435 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
5442 Elf_Internal_Sym sym
;
5445 const char * const * namep
= mips_elf_dynsym_sec_names
;
5446 Elf32_compact_rel cpt
;
5448 /* Set up the section symbols for the output sections. SGI sets
5449 the STT_NOTYPE attribute for these symbols. Should we do so? */
5451 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
5452 if (sdynsym
!= NULL
)
5454 if (SGI_COMPAT (output_bfd
))
5458 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
5462 while ((name
= *namep
++) != NULL
)
5464 s
= bfd_get_section_by_name (output_bfd
, name
);
5467 sym
.st_value
= s
->vma
;
5468 dindx
= elf_section_data (s
)->dynindx
;
5469 last
= s
->vma
+ s
->_raw_size
;
5473 sym
.st_value
= last
;
5477 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
5482 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
5484 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
5485 (((Elf32_External_Sym
*)
5490 /* Set the sh_info field of the output .dynsym section to
5491 the index of the first global symbol. */
5492 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
5493 SIZEOF_MIPS_DYNSYM_SECNAMES
;
5499 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
5502 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
5506 sym
.st_value
= s
->vma
;
5508 indx
= elf_section_data (s
)->this_idx
;
5509 BFD_ASSERT (indx
> 0);
5510 sym
.st_shndx
= indx
;
5512 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
5513 (((Elf32_External_Sym
*)
5515 + elf_section_data (s
)->dynindx
));
5518 /* Set the sh_info field of the output .dynsym section to
5519 the index of the first global symbol. */
5520 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
5521 bfd_count_sections (output_bfd
) + 1;
5525 if (SGI_COMPAT (output_bfd
))
5527 /* Write .compact_rel section out. */
5528 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5532 cpt
.num
= s
->reloc_count
;
5534 cpt
.offset
= (s
->output_section
->filepos
5535 + sizeof (Elf32_External_compact_rel
));
5538 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
5539 ((Elf32_External_compact_rel
*)
5542 /* Clean up a dummy stub function entry in .text. */
5543 s
= bfd_get_section_by_name (dynobj
, ".stub");
5546 file_ptr dummy_offset
;
5548 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
5549 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
5550 memset (s
->contents
+ dummy_offset
, 0,
5551 MIPS_FUNCTION_STUB_SIZE
);
5556 /* Clean up a first relocation in .rel.dyn. */
5557 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5559 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
5565 /* This is almost identical to bfd_generic_get_... except that some
5566 MIPS relocations need to be handled specially. Sigh. */
5569 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
5570 relocateable
, symbols
)
5572 struct bfd_link_info
*link_info
;
5573 struct bfd_link_order
*link_order
;
5575 boolean relocateable
;
5578 /* Get enough memory to hold the stuff */
5579 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
5580 asection
*input_section
= link_order
->u
.indirect
.section
;
5582 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
5583 arelent
**reloc_vector
= NULL
;
5589 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
5590 if (reloc_vector
== NULL
&& reloc_size
!= 0)
5593 /* read in the section */
5594 if (!bfd_get_section_contents (input_bfd
,
5598 input_section
->_raw_size
))
5601 /* We're not relaxing the section, so just copy the size info */
5602 input_section
->_cooked_size
= input_section
->_raw_size
;
5603 input_section
->reloc_done
= true;
5605 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
5609 if (reloc_count
< 0)
5612 if (reloc_count
> 0)
5617 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
5620 struct bfd_hash_entry
*h
;
5621 struct bfd_link_hash_entry
*lh
;
5622 /* Skip all this stuff if we aren't mixing formats. */
5623 if (abfd
&& input_bfd
5624 && abfd
->xvec
== input_bfd
->xvec
)
5628 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
5629 lh
= (struct bfd_link_hash_entry
*) h
;
5636 case bfd_link_hash_undefined
:
5637 case bfd_link_hash_undefweak
:
5638 case bfd_link_hash_common
:
5641 case bfd_link_hash_defined
:
5642 case bfd_link_hash_defweak
:
5644 gp
= lh
->u
.def
.value
;
5646 case bfd_link_hash_indirect
:
5647 case bfd_link_hash_warning
:
5649 /* @@FIXME ignoring warning for now */
5651 case bfd_link_hash_new
:
5660 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
5663 char *error_message
= (char *) NULL
;
5664 bfd_reloc_status_type r
;
5666 /* Specific to MIPS: Deal with relocation types that require
5667 knowing the gp of the output bfd. */
5668 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
5669 if (bfd_is_abs_section (sym
->section
) && abfd
)
5671 /* The special_function wouldn't get called anyways. */
5675 /* The gp isn't there; let the special function code
5676 fall over on its own. */
5678 else if ((*parent
)->howto
->special_function
5679 == mips_elf_gprel16_reloc
)
5681 /* bypass special_function call */
5682 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
5683 relocateable
, (PTR
) data
, gp
);
5684 goto skip_bfd_perform_relocation
;
5686 /* end mips specific stuff */
5688 r
= bfd_perform_relocation (input_bfd
,
5692 relocateable
? abfd
: (bfd
*) NULL
,
5694 skip_bfd_perform_relocation
:
5698 asection
*os
= input_section
->output_section
;
5700 /* A partial link, so keep the relocs */
5701 os
->orelocation
[os
->reloc_count
] = *parent
;
5705 if (r
!= bfd_reloc_ok
)
5709 case bfd_reloc_undefined
:
5710 if (!((*link_info
->callbacks
->undefined_symbol
)
5711 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
5712 input_bfd
, input_section
, (*parent
)->address
)))
5715 case bfd_reloc_dangerous
:
5716 BFD_ASSERT (error_message
!= (char *) NULL
);
5717 if (!((*link_info
->callbacks
->reloc_dangerous
)
5718 (link_info
, error_message
, input_bfd
, input_section
,
5719 (*parent
)->address
)))
5722 case bfd_reloc_overflow
:
5723 if (!((*link_info
->callbacks
->reloc_overflow
)
5724 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
5725 (*parent
)->howto
->name
, (*parent
)->addend
,
5726 input_bfd
, input_section
, (*parent
)->address
)))
5729 case bfd_reloc_outofrange
:
5738 if (reloc_vector
!= NULL
)
5739 free (reloc_vector
);
5743 if (reloc_vector
!= NULL
)
5744 free (reloc_vector
);
5747 #define bfd_elf32_bfd_get_relocated_section_contents \
5748 elf32_mips_get_relocated_section_contents
5750 /* ECOFF swapping routines. These are used when dealing with the
5751 .mdebug section, which is in the ECOFF debugging format. */
5752 static const struct ecoff_debug_swap mips_elf_ecoff_debug_swap
=
5754 /* Symbol table magic number. */
5756 /* Alignment of debugging information. E.g., 4. */
5758 /* Sizes of external symbolic information. */
5759 sizeof (struct hdr_ext
),
5760 sizeof (struct dnr_ext
),
5761 sizeof (struct pdr_ext
),
5762 sizeof (struct sym_ext
),
5763 sizeof (struct opt_ext
),
5764 sizeof (struct fdr_ext
),
5765 sizeof (struct rfd_ext
),
5766 sizeof (struct ext_ext
),
5767 /* Functions to swap in external symbolic data. */
5776 _bfd_ecoff_swap_tir_in
,
5777 _bfd_ecoff_swap_rndx_in
,
5778 /* Functions to swap out external symbolic data. */
5787 _bfd_ecoff_swap_tir_out
,
5788 _bfd_ecoff_swap_rndx_out
,
5789 /* Function to read in symbolic data. */
5790 mips_elf_read_ecoff_info
5793 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
5794 #define TARGET_LITTLE_NAME "elf32-littlemips"
5795 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
5796 #define TARGET_BIG_NAME "elf32-bigmips"
5797 #define ELF_ARCH bfd_arch_mips
5798 #define ELF_MACHINE_CODE EM_MIPS
5799 #define ELF_MAXPAGESIZE 0x10000
5800 #define elf_backend_collect true
5801 #define elf_backend_type_change_ok true
5802 #define elf_info_to_howto 0
5803 #define elf_info_to_howto_rel mips_info_to_howto_rel
5804 #define elf_backend_sym_is_global mips_elf_sym_is_global
5805 #define elf_backend_object_p mips_elf_object_p
5806 #define elf_backend_section_from_shdr mips_elf_section_from_shdr
5807 #define elf_backend_fake_sections mips_elf_fake_sections
5808 #define elf_backend_section_from_bfd_section \
5809 mips_elf_section_from_bfd_section
5810 #define elf_backend_section_processing mips_elf_section_processing
5811 #define elf_backend_symbol_processing mips_elf_symbol_processing
5812 #define elf_backend_additional_program_headers \
5813 mips_elf_additional_program_headers
5814 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
5815 #define elf_backend_final_write_processing \
5816 mips_elf_final_write_processing
5817 #define elf_backend_ecoff_debug_swap &mips_elf_ecoff_debug_swap
5819 #define bfd_elf32_bfd_is_local_label mips_elf_is_local_label
5820 #define bfd_elf32_find_nearest_line mips_elf_find_nearest_line
5822 #define bfd_elf32_bfd_link_hash_table_create \
5823 mips_elf_link_hash_table_create
5824 #define bfd_elf32_bfd_final_link mips_elf_final_link
5825 #define bfd_elf32_bfd_copy_private_bfd_data \
5826 mips_elf_copy_private_bfd_data
5827 #define bfd_elf32_bfd_merge_private_bfd_data \
5828 mips_elf_merge_private_bfd_data
5829 #define bfd_elf32_bfd_set_private_flags mips_elf_set_private_flags
5830 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
5831 #define elf_backend_create_dynamic_sections \
5832 mips_elf_create_dynamic_sections
5833 #define elf_backend_check_relocs mips_elf_check_relocs
5834 #define elf_backend_adjust_dynamic_symbol \
5835 mips_elf_adjust_dynamic_symbol
5836 #define elf_backend_size_dynamic_sections \
5837 mips_elf_size_dynamic_sections
5838 #define elf_backend_relocate_section mips_elf_relocate_section
5839 #define elf_backend_finish_dynamic_symbol \
5840 mips_elf_finish_dynamic_symbol
5841 #define elf_backend_finish_dynamic_sections \
5842 mips_elf_finish_dynamic_sections
5844 #include "elf32-target.h"