1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
4 Most of the information added by Ian Lance Taylor, Cygnus Support,
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 /* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
24 different MIPS ELF from other targets. This matters when linking.
25 This file supports both, switching at runtime. */
35 /* Get the ECOFF swapping routines. */
37 #include "coff/symconst.h"
38 #include "coff/internal.h"
39 #include "coff/ecoff.h"
40 #include "coff/mips.h"
42 #include "ecoffswap.h"
44 static bfd_reloc_status_type mips32_64bit_reloc
45 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
46 static reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
47 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
48 static void mips_info_to_howto_rel
49 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
50 static void bfd_mips_elf32_swap_gptab_in
51 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
52 static void bfd_mips_elf32_swap_gptab_out
53 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
54 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
55 static boolean mips_elf32_object_p
PARAMS ((bfd
*));
56 static boolean mips_elf_create_procedure_table
57 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
58 struct ecoff_debug_info
*));
59 static int mips_elf_additional_program_headers
PARAMS ((bfd
*));
60 static boolean mips_elf_modify_segment_map
PARAMS ((bfd
*));
61 static INLINE
int elf_mips_isa
PARAMS ((flagword
));
62 static INLINE
int elf_mips_mach
PARAMS ((flagword
));
63 static boolean mips_elf32_section_from_shdr
64 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, char *));
65 static boolean mips_elf32_section_processing
66 PARAMS ((bfd
*, Elf32_Internal_Shdr
*));
67 static boolean mips_elf_is_local_label_name
68 PARAMS ((bfd
*, const char *));
69 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
70 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
71 static struct bfd_link_hash_table
*mips_elf_link_hash_table_create
73 static int gptab_compare
PARAMS ((const void *, const void *));
74 static boolean mips_elf_final_link
75 PARAMS ((bfd
*, struct bfd_link_info
*));
76 static void mips_elf_relocate_hi16
77 PARAMS ((bfd
*, Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_byte
*,
79 static boolean mips_elf_relocate_got_local
80 PARAMS ((bfd
*, bfd
*, asection
*, Elf_Internal_Rela
*,
81 Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
82 static void mips_elf_relocate_global_got
83 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
84 static bfd_reloc_status_type mips16_jump_reloc
85 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
86 static bfd_reloc_status_type mips16_gprel_reloc
87 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
88 static boolean mips_elf_adjust_dynindx
89 PARAMS ((struct elf_link_hash_entry
*, PTR
));
90 static boolean mips_elf_relocate_section
91 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
92 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
93 static boolean mips_elf_link_output_symbol_hook
94 PARAMS ((bfd
*, struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
96 static boolean mips_elf_create_dynamic_sections
97 PARAMS ((bfd
*, struct bfd_link_info
*));
98 static boolean mips_elf_create_compact_rel_section
99 PARAMS ((bfd
*, struct bfd_link_info
*));
100 static boolean mips_elf_create_got_section
101 PARAMS ((bfd
*, struct bfd_link_info
*));
102 static boolean mips_elf_check_relocs
103 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
104 const Elf_Internal_Rela
*));
105 static boolean mips_elf_adjust_dynamic_symbol
106 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
107 static boolean mips_elf_always_size_sections
108 PARAMS ((bfd
*, struct bfd_link_info
*));
109 static boolean mips_elf_size_dynamic_sections
110 PARAMS ((bfd
*, struct bfd_link_info
*));
111 static boolean mips_elf_finish_dynamic_symbol
112 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
113 Elf_Internal_Sym
*));
114 static boolean mips_elf_finish_dynamic_sections
115 PARAMS ((bfd
*, struct bfd_link_info
*));
116 static boolean mips_elf_add_symbol_hook
117 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
118 const char **, flagword
*, asection
**, bfd_vma
*));
119 static bfd_reloc_status_type mips_elf_final_gp
120 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
121 static bfd_byte
*elf32_mips_get_relocated_section_contents
122 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
123 bfd_byte
*, boolean
, asymbol
**));
125 /* This is true for Irix 5 executables, false for normal MIPS ELF ABI
126 executables. FIXME: At the moment, we default to always generating
127 Irix 5 executables. */
129 #define SGI_COMPAT(abfd) (1)
131 /* This structure is used to hold .got information when linking. It
132 is stored in the tdata field of the bfd_elf_section_data structure. */
136 /* The symbol index of the first global .got symbol. */
137 unsigned long global_gotsym
;
138 /* The number of local .got entries. */
139 unsigned int local_gotno
;
140 /* The number of local .got entries we have used. */
141 unsigned int assigned_gotno
;
144 /* The number of local .got entries we reserve. */
145 #define MIPS_RESERVED_GOTNO (2)
147 /* Instructions which appear in a stub. For some reason the stub is
148 slightly different on an SGI system. */
149 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
150 #define STUB_LW(abfd) \
152 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
153 : 0x8f998000) /* lw t9,0x8000(gp) */
154 #define STUB_MOVE 0x03e07825 /* move t7,ra */
155 #define STUB_JALR 0x0320f809 /* jal t9 */
156 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
157 #define MIPS_FUNCTION_STUB_SIZE (16)
159 /* Names of sections which appear in the .dynsym section in an Irix 5
162 static const char * const mips_elf_dynsym_sec_names
[] =
175 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
176 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
178 /* The number of entries in mips_elf_dynsym_sec_names which go in the
181 #define MIPS_TEXT_DYNSYM_SECNO (3)
183 /* The names of the runtime procedure table symbols used on Irix 5. */
185 static const char * const mips_elf_dynsym_rtproc_names
[] =
188 "_procedure_string_table",
189 "_procedure_table_size",
193 /* These structures are used to generate the .compact_rel section on
198 unsigned long id1
; /* Always one? */
199 unsigned long num
; /* Number of compact relocation entries. */
200 unsigned long id2
; /* Always two? */
201 unsigned long offset
; /* The file offset of the first relocation. */
202 unsigned long reserved0
; /* Zero? */
203 unsigned long reserved1
; /* Zero? */
212 bfd_byte reserved0
[4];
213 bfd_byte reserved1
[4];
214 } Elf32_External_compact_rel
;
218 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
219 unsigned int rtype
: 4; /* Relocation types. See below. */
220 unsigned int dist2to
: 8;
221 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
222 unsigned long konst
; /* KONST field. See below. */
223 unsigned long vaddr
; /* VADDR to be relocated. */
228 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
229 unsigned int rtype
: 4; /* Relocation types. See below. */
230 unsigned int dist2to
: 8;
231 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
232 unsigned long konst
; /* KONST field. See below. */
240 } Elf32_External_crinfo
;
246 } Elf32_External_crinfo2
;
248 /* These are the constants used to swap the bitfields in a crinfo. */
250 #define CRINFO_CTYPE (0x1)
251 #define CRINFO_CTYPE_SH (31)
252 #define CRINFO_RTYPE (0xf)
253 #define CRINFO_RTYPE_SH (27)
254 #define CRINFO_DIST2TO (0xff)
255 #define CRINFO_DIST2TO_SH (19)
256 #define CRINFO_RELVADDR (0x7ffff)
257 #define CRINFO_RELVADDR_SH (0)
259 /* A compact relocation info has long (3 words) or short (2 words)
260 formats. A short format doesn't have VADDR field and relvaddr
261 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
262 #define CRF_MIPS_LONG 1
263 #define CRF_MIPS_SHORT 0
265 /* There are 4 types of compact relocation at least. The value KONST
266 has different meaning for each type:
269 CT_MIPS_REL32 Address in data
270 CT_MIPS_WORD Address in word (XXX)
271 CT_MIPS_GPHI_LO GP - vaddr
272 CT_MIPS_JMPAD Address to jump
275 #define CRT_MIPS_REL32 0xa
276 #define CRT_MIPS_WORD 0xb
277 #define CRT_MIPS_GPHI_LO 0xc
278 #define CRT_MIPS_JMPAD 0xd
280 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
281 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
282 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
283 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
285 static void bfd_elf32_swap_compact_rel_out
286 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
287 static void bfd_elf32_swap_crinfo_out
288 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
290 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
295 R_MIPS_16
, R_MIPS_32
,
296 R_MIPS_REL32
, R_MIPS_26
,
297 R_MIPS_HI16
, R_MIPS_LO16
,
298 R_MIPS_GPREL16
, R_MIPS_LITERAL
,
299 R_MIPS_GOT16
, R_MIPS_PC16
,
300 R_MIPS_CALL16
, R_MIPS_GPREL32
,
301 /* The remaining relocs are defined on Irix, although they are not
302 in the MIPS ELF ABI. */
303 R_MIPS_UNUSED1
, R_MIPS_UNUSED2
,
305 R_MIPS_SHIFT5
, R_MIPS_SHIFT6
,
306 R_MIPS_64
, R_MIPS_GOT_DISP
,
307 R_MIPS_GOT_PAGE
, R_MIPS_GOT_OFST
,
308 R_MIPS_GOT_HI16
, R_MIPS_GOT_LO16
,
309 R_MIPS_SUB
, R_MIPS_INSERT_A
,
310 R_MIPS_INSERT_B
, R_MIPS_DELETE
,
311 R_MIPS_HIGHER
, R_MIPS_HIGHEST
,
312 R_MIPS_CALL_HI16
, R_MIPS_CALL_LO16
,
313 /* start-sanitize-r5900 */
314 /* This is used by a mips co-processor instruction. */
316 /* end-sanitize-r5900 */
318 /* These relocs are used for the mips16. */
320 R_MIPS16_GPREL
= 101,
321 /* start-sanitize-sky */
322 /* These relocs are for the dvp. */
323 R_MIPS_DVP_11_PCREL
= 120,
324 R_MIPS_DVP_27_S4
= 121,
325 /* end-sanitize-sky */
326 /* These are GNU extensions to enable C++ vtable garbage collection. */
327 R_MIPS_GNU_VTINHERIT
= 253,
328 R_MIPS_GNU_VTENTRY
= 254
331 static reloc_howto_type elf_mips_howto_table
[] =
334 HOWTO (R_MIPS_NONE
, /* type */
336 0, /* size (0 = byte, 1 = short, 2 = long) */
338 false, /* pc_relative */
340 complain_overflow_dont
, /* complain_on_overflow */
341 bfd_elf_generic_reloc
, /* special_function */
342 "R_MIPS_NONE", /* name */
343 false, /* partial_inplace */
346 false), /* pcrel_offset */
348 /* 16 bit relocation. */
349 HOWTO (R_MIPS_16
, /* type */
351 1, /* size (0 = byte, 1 = short, 2 = long) */
353 false, /* pc_relative */
355 complain_overflow_bitfield
, /* complain_on_overflow */
356 bfd_elf_generic_reloc
, /* special_function */
357 "R_MIPS_16", /* name */
358 true, /* partial_inplace */
359 0xffff, /* src_mask */
360 0xffff, /* dst_mask */
361 false), /* pcrel_offset */
363 /* 32 bit relocation. */
364 HOWTO (R_MIPS_32
, /* type */
366 2, /* size (0 = byte, 1 = short, 2 = long) */
368 false, /* pc_relative */
370 complain_overflow_bitfield
, /* complain_on_overflow */
371 bfd_elf_generic_reloc
, /* special_function */
372 "R_MIPS_32", /* name */
373 true, /* partial_inplace */
374 0xffffffff, /* src_mask */
375 0xffffffff, /* dst_mask */
376 false), /* pcrel_offset */
378 /* 32 bit symbol relative relocation. */
379 HOWTO (R_MIPS_REL32
, /* type */
381 2, /* size (0 = byte, 1 = short, 2 = long) */
383 false, /* pc_relative */
385 complain_overflow_bitfield
, /* complain_on_overflow */
386 bfd_elf_generic_reloc
, /* special_function */
387 "R_MIPS_REL32", /* name */
388 true, /* partial_inplace */
389 0xffffffff, /* src_mask */
390 0xffffffff, /* dst_mask */
391 false), /* pcrel_offset */
393 /* 26 bit branch address. */
394 HOWTO (R_MIPS_26
, /* type */
396 2, /* size (0 = byte, 1 = short, 2 = long) */
398 false, /* pc_relative */
400 complain_overflow_dont
, /* complain_on_overflow */
401 /* This needs complex overflow
402 detection, because the upper four
403 bits must match the PC. */
404 bfd_elf_generic_reloc
, /* special_function */
405 "R_MIPS_26", /* name */
406 true, /* partial_inplace */
407 0x3ffffff, /* src_mask */
408 0x3ffffff, /* dst_mask */
409 false), /* pcrel_offset */
411 /* High 16 bits of symbol value. */
412 HOWTO (R_MIPS_HI16
, /* type */
414 2, /* size (0 = byte, 1 = short, 2 = long) */
416 false, /* pc_relative */
418 complain_overflow_dont
, /* complain_on_overflow */
419 _bfd_mips_elf_hi16_reloc
, /* special_function */
420 "R_MIPS_HI16", /* name */
421 true, /* partial_inplace */
422 0xffff, /* src_mask */
423 0xffff, /* dst_mask */
424 false), /* pcrel_offset */
426 /* Low 16 bits of symbol value. */
427 HOWTO (R_MIPS_LO16
, /* type */
429 2, /* size (0 = byte, 1 = short, 2 = long) */
431 false, /* pc_relative */
433 complain_overflow_dont
, /* complain_on_overflow */
434 _bfd_mips_elf_lo16_reloc
, /* special_function */
435 "R_MIPS_LO16", /* name */
436 true, /* partial_inplace */
437 0xffff, /* src_mask */
438 0xffff, /* dst_mask */
439 false), /* pcrel_offset */
441 /* GP relative reference. */
442 HOWTO (R_MIPS_GPREL16
, /* type */
444 2, /* size (0 = byte, 1 = short, 2 = long) */
446 false, /* pc_relative */
448 complain_overflow_signed
, /* complain_on_overflow */
449 _bfd_mips_elf_gprel16_reloc
, /* special_function */
450 "R_MIPS_GPREL16", /* name */
451 true, /* partial_inplace */
452 0xffff, /* src_mask */
453 0xffff, /* dst_mask */
454 false), /* pcrel_offset */
456 /* Reference to literal section. */
457 HOWTO (R_MIPS_LITERAL
, /* type */
459 2, /* size (0 = byte, 1 = short, 2 = long) */
461 false, /* pc_relative */
463 complain_overflow_signed
, /* complain_on_overflow */
464 _bfd_mips_elf_gprel16_reloc
, /* special_function */
465 "R_MIPS_LITERAL", /* name */
466 true, /* partial_inplace */
467 0xffff, /* src_mask */
468 0xffff, /* dst_mask */
469 false), /* pcrel_offset */
471 /* Reference to global offset table. */
472 HOWTO (R_MIPS_GOT16
, /* type */
474 2, /* size (0 = byte, 1 = short, 2 = long) */
476 false, /* pc_relative */
478 complain_overflow_signed
, /* complain_on_overflow */
479 _bfd_mips_elf_got16_reloc
, /* special_function */
480 "R_MIPS_GOT16", /* name */
481 false, /* partial_inplace */
483 0xffff, /* dst_mask */
484 false), /* pcrel_offset */
486 /* 16 bit PC relative reference. */
487 HOWTO (R_MIPS_PC16
, /* type */
489 2, /* size (0 = byte, 1 = short, 2 = long) */
491 true, /* pc_relative */
493 complain_overflow_signed
, /* complain_on_overflow */
494 bfd_elf_generic_reloc
, /* special_function */
495 "R_MIPS_PC16", /* name */
496 true, /* partial_inplace */
497 0xffff, /* src_mask */
498 0xffff, /* dst_mask */
499 false), /* pcrel_offset */
501 /* 16 bit call through global offset table. */
502 /* FIXME: This is not handled correctly. */
503 HOWTO (R_MIPS_CALL16
, /* type */
505 2, /* size (0 = byte, 1 = short, 2 = long) */
507 false, /* pc_relative */
509 complain_overflow_signed
, /* complain_on_overflow */
510 bfd_elf_generic_reloc
, /* special_function */
511 "R_MIPS_CALL16", /* name */
512 false, /* partial_inplace */
514 0xffff, /* dst_mask */
515 false), /* pcrel_offset */
517 /* 32 bit GP relative reference. */
518 HOWTO (R_MIPS_GPREL32
, /* type */
520 2, /* size (0 = byte, 1 = short, 2 = long) */
522 false, /* pc_relative */
524 complain_overflow_bitfield
, /* complain_on_overflow */
525 _bfd_mips_elf_gprel32_reloc
, /* special_function */
526 "R_MIPS_GPREL32", /* name */
527 true, /* partial_inplace */
528 0xffffffff, /* src_mask */
529 0xffffffff, /* dst_mask */
530 false), /* pcrel_offset */
532 /* The remaining relocs are defined on Irix 5, although they are
533 not defined by the ABI. */
538 /* A 5 bit shift field. */
539 HOWTO (R_MIPS_SHIFT5
, /* type */
541 2, /* size (0 = byte, 1 = short, 2 = long) */
543 false, /* pc_relative */
545 complain_overflow_bitfield
, /* complain_on_overflow */
546 bfd_elf_generic_reloc
, /* special_function */
547 "R_MIPS_SHIFT5", /* name */
548 true, /* partial_inplace */
549 0x000007c0, /* src_mask */
550 0x000007c0, /* dst_mask */
551 false), /* pcrel_offset */
553 /* A 6 bit shift field. */
554 /* FIXME: This is not handled correctly; a special function is
555 needed to put the most significant bit in the right place. */
556 HOWTO (R_MIPS_SHIFT6
, /* type */
558 2, /* size (0 = byte, 1 = short, 2 = long) */
560 false, /* pc_relative */
562 complain_overflow_bitfield
, /* complain_on_overflow */
563 bfd_elf_generic_reloc
, /* special_function */
564 "R_MIPS_SHIFT6", /* name */
565 true, /* partial_inplace */
566 0x000007c4, /* src_mask */
567 0x000007c4, /* dst_mask */
568 false), /* pcrel_offset */
570 /* A 64 bit relocation. This is used in 32 bit ELF when addresses
571 are 64 bits long; the upper 32 bits are simply a sign extension.
572 The fields of the howto should be the same as for R_MIPS_32,
573 other than the type, name, and special_function. */
574 HOWTO (R_MIPS_64
, /* type */
576 2, /* size (0 = byte, 1 = short, 2 = long) */
578 false, /* pc_relative */
580 complain_overflow_bitfield
, /* complain_on_overflow */
581 mips32_64bit_reloc
, /* special_function */
582 "R_MIPS_64", /* name */
583 true, /* partial_inplace */
584 0xffffffff, /* src_mask */
585 0xffffffff, /* dst_mask */
586 false), /* pcrel_offset */
588 /* Displacement in the global offset table. */
589 /* FIXME: Not handled correctly. */
590 HOWTO (R_MIPS_GOT_DISP
, /* type */
592 2, /* size (0 = byte, 1 = short, 2 = long) */
594 false, /* pc_relative */
596 complain_overflow_bitfield
, /* complain_on_overflow */
597 bfd_elf_generic_reloc
, /* special_function */
598 "R_MIPS_GOT_DISP", /* name */
599 true, /* partial_inplace */
600 0x0000ffff, /* src_mask */
601 0x0000ffff, /* dst_mask */
602 false), /* pcrel_offset */
604 /* Displacement to page pointer in the global offset table. */
605 /* FIXME: Not handled correctly. */
606 HOWTO (R_MIPS_GOT_PAGE
, /* type */
608 2, /* size (0 = byte, 1 = short, 2 = long) */
610 false, /* pc_relative */
612 complain_overflow_bitfield
, /* complain_on_overflow */
613 bfd_elf_generic_reloc
, /* special_function */
614 "R_MIPS_GOT_PAGE", /* name */
615 true, /* partial_inplace */
616 0x0000ffff, /* src_mask */
617 0x0000ffff, /* dst_mask */
618 false), /* pcrel_offset */
620 /* Offset from page pointer in the global offset table. */
621 /* FIXME: Not handled correctly. */
622 HOWTO (R_MIPS_GOT_OFST
, /* type */
624 2, /* size (0 = byte, 1 = short, 2 = long) */
626 false, /* pc_relative */
628 complain_overflow_bitfield
, /* complain_on_overflow */
629 bfd_elf_generic_reloc
, /* special_function */
630 "R_MIPS_GOT_OFST", /* name */
631 true, /* partial_inplace */
632 0x0000ffff, /* src_mask */
633 0x0000ffff, /* dst_mask */
634 false), /* pcrel_offset */
636 /* High 16 bits of displacement in global offset table. */
637 /* FIXME: Not handled correctly. */
638 HOWTO (R_MIPS_GOT_HI16
, /* type */
640 2, /* size (0 = byte, 1 = short, 2 = long) */
642 false, /* pc_relative */
644 complain_overflow_dont
, /* complain_on_overflow */
645 bfd_elf_generic_reloc
, /* special_function */
646 "R_MIPS_GOT_HI16", /* name */
647 true, /* partial_inplace */
648 0x0000ffff, /* src_mask */
649 0x0000ffff, /* dst_mask */
650 false), /* pcrel_offset */
652 /* Low 16 bits of displacement in global offset table. */
653 /* FIXME: Not handled correctly. */
654 HOWTO (R_MIPS_GOT_LO16
, /* type */
656 2, /* size (0 = byte, 1 = short, 2 = long) */
658 false, /* pc_relative */
660 complain_overflow_dont
, /* complain_on_overflow */
661 bfd_elf_generic_reloc
, /* special_function */
662 "R_MIPS_GOT_LO16", /* name */
663 true, /* partial_inplace */
664 0x0000ffff, /* src_mask */
665 0x0000ffff, /* dst_mask */
666 false), /* pcrel_offset */
668 /* 64 bit subtraction. Presumably not used in 32 bit ELF. */
671 /* Used to cause the linker to insert and delete instructions? */
676 /* Get the higher values of a 64 bit addend. Presumably not used in
681 /* High 16 bits of displacement in global offset table. */
682 /* FIXME: Not handled correctly. */
683 HOWTO (R_MIPS_CALL_HI16
, /* type */
685 2, /* size (0 = byte, 1 = short, 2 = long) */
687 false, /* pc_relative */
689 complain_overflow_dont
, /* complain_on_overflow */
690 bfd_elf_generic_reloc
, /* special_function */
691 "R_MIPS_CALL_HI16", /* name */
692 true, /* partial_inplace */
693 0x0000ffff, /* src_mask */
694 0x0000ffff, /* dst_mask */
695 false), /* pcrel_offset */
697 /* Low 16 bits of displacement in global offset table. */
698 /* FIXME: Not handled correctly. */
699 HOWTO (R_MIPS_CALL_LO16
, /* type */
701 2, /* size (0 = byte, 1 = short, 2 = long) */
703 false, /* pc_relative */
705 complain_overflow_dont
, /* complain_on_overflow */
706 bfd_elf_generic_reloc
, /* special_function */
707 "R_MIPS_CALL_LO16", /* name */
708 true, /* partial_inplace */
709 0x0000ffff, /* src_mask */
710 0x0000ffff, /* dst_mask */
711 false), /* pcrel_offset */
713 /* start-sanitize-r5900 */
714 HOWTO (R_MIPS15_S3
, /* type */
716 2, /* size (0 = byte, 1 = short, 2 = long) */
718 false, /* pc_relative */
720 complain_overflow_bitfield
, /* complain_on_overflow */
721 bfd_elf_generic_reloc
, /* special_function */
722 "R_MIPS15_S3", /* name */
723 true, /* partial_inplace */
724 0x001fffc0, /* src_mask */
725 0x001fffc0, /* dst_mask */
726 false) /* pcrel_offset */
727 /* end-sanitize-r5900 */
731 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
732 is a hack to make the linker think that we need 64 bit values. */
733 static reloc_howto_type elf_mips_ctor64_howto
=
734 HOWTO (R_MIPS_64
, /* type */
736 4, /* size (0 = byte, 1 = short, 2 = long) */
738 false, /* pc_relative */
740 complain_overflow_signed
, /* complain_on_overflow */
741 mips32_64bit_reloc
, /* special_function */
742 "R_MIPS_64", /* name */
743 true, /* partial_inplace */
744 0xffffffff, /* src_mask */
745 0xffffffff, /* dst_mask */
746 false); /* pcrel_offset */
748 /* The reloc used for the mips16 jump instruction. */
749 static reloc_howto_type elf_mips16_jump_howto
=
750 HOWTO (R_MIPS16_26
, /* type */
752 2, /* size (0 = byte, 1 = short, 2 = long) */
754 false, /* pc_relative */
756 complain_overflow_dont
, /* complain_on_overflow */
757 /* This needs complex overflow
758 detection, because the upper four
759 bits must match the PC. */
760 mips16_jump_reloc
, /* special_function */
761 "R_MIPS16_26", /* name */
762 true, /* partial_inplace */
763 0x3ffffff, /* src_mask */
764 0x3ffffff, /* dst_mask */
765 false); /* pcrel_offset */
767 /* The reloc used for the mips16 gprel instruction. The src_mask and
768 dsk_mask for this howto do not reflect the actual instruction, in
769 which the value is not contiguous; the masks are for the
770 convenience of the relocate_section routine. */
771 static reloc_howto_type elf_mips16_gprel_howto
=
772 HOWTO (R_MIPS16_GPREL
, /* type */
774 2, /* size (0 = byte, 1 = short, 2 = long) */
776 false, /* pc_relative */
778 complain_overflow_signed
, /* complain_on_overflow */
779 mips16_gprel_reloc
, /* special_function */
780 "R_MIPS16_GPREL", /* name */
781 true, /* partial_inplace */
782 0xffff, /* src_mask */
783 0xffff, /* dst_mask */
784 false); /* pcrel_offset */
786 /* start-sanitize-sky */
788 Note that partial_inplace and pcrel_offset are backwards from the
789 mips port. This is intentional as it seems more reasonable. */
790 static reloc_howto_type elf_mips_dvp_11_pcrel_howto
=
791 HOWTO (R_MIPS_DVP_11_PCREL
, /* type */
793 2, /* size (0 = byte, 1 = short, 2 = long) */
795 true, /* pc_relative */
797 complain_overflow_signed
, /* complain_on_overflow */
798 bfd_elf_generic_reloc
, /* special_function */
799 "R_MIPS_DVP_11_PCREL", /* name */
800 false, /* partial_inplace */
801 0x7ff, /* src_mask */
802 0x7ff, /* dst_mask */
803 true); /* pcrel_offset */
804 static reloc_howto_type elf_mips_dvp_27_s4_howto
=
805 HOWTO (R_MIPS_DVP_27_S4
, /* type */
807 2, /* size (0 = byte, 1 = short, 2 = long) */
809 false, /* pc_relative */
811 complain_overflow_unsigned
, /* complain_on_overflow */
812 bfd_elf_generic_reloc
, /* special_function */
813 "R_MIPS_DVP_27_S4", /* name */
814 false, /* partial_inplace */
815 0x7ffffff0, /* src_mask */
816 0x7ffffff0, /* dst_mask */
817 false); /* pcrel_offset */
818 /* end-sanitize-sky */
820 /* GNU extension to record C++ vtable hierarchy */
821 static reloc_howto_type elf_mips_gnu_vtinherit_howto
=
822 HOWTO (R_MIPS_GNU_VTINHERIT
, /* type */
824 2, /* size (0 = byte, 1 = short, 2 = long) */
826 false, /* pc_relative */
828 complain_overflow_dont
, /* complain_on_overflow */
829 NULL
, /* special_function */
830 "R_MIPS_GNU_VTINHERIT", /* name */
831 false, /* partial_inplace */
834 false); /* pcrel_offset */
836 /* GNU extension to record C++ vtable member usage */
837 static reloc_howto_type elf_mips_gnu_vtentry_howto
=
838 HOWTO (R_MIPS_GNU_VTENTRY
, /* type */
840 2, /* size (0 = byte, 1 = short, 2 = long) */
842 false, /* pc_relative */
844 complain_overflow_dont
, /* complain_on_overflow */
845 NULL
, /* special_function */
846 "R_MIPS_GNU_VTENTRY", /* name */
847 false, /* partial_inplace */
850 false); /* pcrel_offset */
852 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
853 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
854 the HI16. Here we just save the information we need; we do the
855 actual relocation when we see the LO16. MIPS ELF requires that the
856 LO16 immediately follow the HI16. As a GNU extension, we permit an
857 arbitrary number of HI16 relocs to be associated with a single LO16
858 reloc. This extension permits gcc to output the HI and LO relocs
863 struct mips_hi16
*next
;
868 /* FIXME: This should not be a static variable. */
870 static struct mips_hi16
*mips_hi16_list
;
872 bfd_reloc_status_type
873 _bfd_mips_elf_hi16_reloc (abfd
,
881 arelent
*reloc_entry
;
884 asection
*input_section
;
886 char **error_message
;
888 bfd_reloc_status_type ret
;
892 /* If we're relocating, and this an external symbol, we don't want
893 to change anything. */
894 if (output_bfd
!= (bfd
*) NULL
895 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
896 && reloc_entry
->addend
== 0)
898 reloc_entry
->address
+= input_section
->output_offset
;
904 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
906 boolean relocateable
;
909 if (ret
== bfd_reloc_undefined
)
912 if (output_bfd
!= NULL
)
916 relocateable
= false;
917 output_bfd
= symbol
->section
->output_section
->owner
;
920 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
922 if (ret
!= bfd_reloc_ok
)
925 relocation
= gp
- reloc_entry
->address
;
929 if (bfd_is_und_section (symbol
->section
)
930 && output_bfd
== (bfd
*) NULL
)
931 ret
= bfd_reloc_undefined
;
933 if (bfd_is_com_section (symbol
->section
))
936 relocation
= symbol
->value
;
939 relocation
+= symbol
->section
->output_section
->vma
;
940 relocation
+= symbol
->section
->output_offset
;
941 relocation
+= reloc_entry
->addend
;
943 if (reloc_entry
->address
> input_section
->_cooked_size
)
944 return bfd_reloc_outofrange
;
946 /* Save the information, and let LO16 do the actual relocation. */
947 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
949 return bfd_reloc_outofrange
;
950 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
951 n
->addend
= relocation
;
952 n
->next
= mips_hi16_list
;
955 if (output_bfd
!= (bfd
*) NULL
)
956 reloc_entry
->address
+= input_section
->output_offset
;
961 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
962 inplace relocation; this function exists in order to do the
963 R_MIPS_HI16 relocation described above. */
965 bfd_reloc_status_type
966 _bfd_mips_elf_lo16_reloc (abfd
,
974 arelent
*reloc_entry
;
977 asection
*input_section
;
979 char **error_message
;
981 arelent gp_disp_relent
;
983 if (mips_hi16_list
!= NULL
)
993 struct mips_hi16
*next
;
995 /* Do the HI16 relocation. Note that we actually don't need
996 to know anything about the LO16 itself, except where to
997 find the low 16 bits of the addend needed by the LO16. */
998 insn
= bfd_get_32 (abfd
, l
->addr
);
999 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
1001 val
= ((insn
& 0xffff) << 16) + vallo
;
1004 /* The low order 16 bits are always treated as a signed
1005 value. Therefore, a negative value in the low order bits
1006 requires an adjustment in the high order bits. We need
1007 to make this adjustment in two ways: once for the bits we
1008 took from the data, and once for the bits we are putting
1009 back in to the data. */
1010 if ((vallo
& 0x8000) != 0)
1012 if ((val
& 0x8000) != 0)
1015 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
1016 bfd_put_32 (abfd
, insn
, l
->addr
);
1018 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1020 gp_disp_relent
= *reloc_entry
;
1021 reloc_entry
= &gp_disp_relent
;
1022 reloc_entry
->addend
= l
->addend
;
1030 mips_hi16_list
= NULL
;
1032 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1034 bfd_reloc_status_type ret
;
1035 bfd_vma gp
, relocation
;
1037 /* FIXME: Does this case ever occur? */
1039 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
1040 if (ret
!= bfd_reloc_ok
)
1043 relocation
= gp
- reloc_entry
->address
;
1044 relocation
+= symbol
->section
->output_section
->vma
;
1045 relocation
+= symbol
->section
->output_offset
;
1046 relocation
+= reloc_entry
->addend
;
1048 if (reloc_entry
->address
> input_section
->_cooked_size
)
1049 return bfd_reloc_outofrange
;
1051 gp_disp_relent
= *reloc_entry
;
1052 reloc_entry
= &gp_disp_relent
;
1053 reloc_entry
->addend
= relocation
- 4;
1056 /* Now do the LO16 reloc in the usual way. */
1057 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1058 input_section
, output_bfd
, error_message
);
1061 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1062 table used for PIC code. If the symbol is an external symbol, the
1063 instruction is modified to contain the offset of the appropriate
1064 entry in the global offset table. If the symbol is a section
1065 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1066 addends are combined to form the real addend against the section
1067 symbol; the GOT16 is modified to contain the offset of an entry in
1068 the global offset table, and the LO16 is modified to offset it
1069 appropriately. Thus an offset larger than 16 bits requires a
1070 modified value in the global offset table.
1072 This implementation suffices for the assembler, but the linker does
1073 not yet know how to create global offset tables. */
1075 bfd_reloc_status_type
1076 _bfd_mips_elf_got16_reloc (abfd
,
1084 arelent
*reloc_entry
;
1087 asection
*input_section
;
1089 char **error_message
;
1091 /* If we're relocating, and this an external symbol, we don't want
1092 to change anything. */
1093 if (output_bfd
!= (bfd
*) NULL
1094 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1095 && reloc_entry
->addend
== 0)
1097 reloc_entry
->address
+= input_section
->output_offset
;
1098 return bfd_reloc_ok
;
1101 /* If we're relocating, and this is a local symbol, we can handle it
1103 if (output_bfd
!= (bfd
*) NULL
1104 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1105 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1106 input_section
, output_bfd
, error_message
);
1111 /* We have to figure out the gp value, so that we can adjust the
1112 symbol value correctly. We look up the symbol _gp in the output
1113 BFD. If we can't find it, we're stuck. We cache it in the ELF
1114 target data. We don't need to adjust the symbol value for an
1115 external symbol if we are producing relocateable output. */
1117 static bfd_reloc_status_type
1118 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1121 boolean relocateable
;
1122 char **error_message
;
1125 if (bfd_is_und_section (symbol
->section
)
1129 return bfd_reloc_undefined
;
1132 *pgp
= _bfd_get_gp_value (output_bfd
);
1135 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1139 /* Make up a value. */
1140 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1141 _bfd_set_gp_value (output_bfd
, *pgp
);
1149 count
= bfd_get_symcount (output_bfd
);
1150 sym
= bfd_get_outsymbols (output_bfd
);
1152 if (sym
== (asymbol
**) NULL
)
1156 for (i
= 0; i
< count
; i
++, sym
++)
1158 register CONST
char *name
;
1160 name
= bfd_asymbol_name (*sym
);
1161 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1163 *pgp
= bfd_asymbol_value (*sym
);
1164 _bfd_set_gp_value (output_bfd
, *pgp
);
1172 /* Only get the error once. */
1174 _bfd_set_gp_value (output_bfd
, *pgp
);
1176 (char *) _("GP relative relocation when _gp not defined");
1177 return bfd_reloc_dangerous
;
1182 return bfd_reloc_ok
;
1185 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1186 become the offset from the gp register. This function also handles
1187 R_MIPS_LITERAL relocations, although those can be handled more
1188 cleverly because the entries in the .lit8 and .lit4 sections can be
1191 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1192 arelent
*, asection
*,
1193 boolean
, PTR
, bfd_vma
));
1195 bfd_reloc_status_type
1196 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1197 output_bfd
, error_message
)
1199 arelent
*reloc_entry
;
1202 asection
*input_section
;
1204 char **error_message
;
1206 boolean relocateable
;
1207 bfd_reloc_status_type ret
;
1210 /* If we're relocating, and this is an external symbol with no
1211 addend, we don't want to change anything. We will only have an
1212 addend if this is a newly created reloc, not read from an ELF
1214 if (output_bfd
!= (bfd
*) NULL
1215 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1216 && reloc_entry
->addend
== 0)
1218 reloc_entry
->address
+= input_section
->output_offset
;
1219 return bfd_reloc_ok
;
1222 if (output_bfd
!= (bfd
*) NULL
)
1223 relocateable
= true;
1226 relocateable
= false;
1227 output_bfd
= symbol
->section
->output_section
->owner
;
1230 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1232 if (ret
!= bfd_reloc_ok
)
1235 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1236 relocateable
, data
, gp
);
1239 static bfd_reloc_status_type
1240 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1244 arelent
*reloc_entry
;
1245 asection
*input_section
;
1246 boolean relocateable
;
1254 if (bfd_is_com_section (symbol
->section
))
1257 relocation
= symbol
->value
;
1259 relocation
+= symbol
->section
->output_section
->vma
;
1260 relocation
+= symbol
->section
->output_offset
;
1262 if (reloc_entry
->address
> input_section
->_cooked_size
)
1263 return bfd_reloc_outofrange
;
1265 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1267 /* Set val to the offset into the section or symbol. */
1268 if (reloc_entry
->howto
->src_mask
== 0)
1270 /* This case occurs with the 64-bit MIPS ELF ABI. */
1271 val
= reloc_entry
->addend
;
1275 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1280 /* Adjust val for the final section location and GP value. If we
1281 are producing relocateable output, we don't want to do this for
1282 an external symbol. */
1284 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1285 val
+= relocation
- gp
;
1287 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1288 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1291 reloc_entry
->address
+= input_section
->output_offset
;
1293 /* Make sure it fit in 16 bits. */
1294 if (val
>= 0x8000 && val
< 0xffff8000)
1295 return bfd_reloc_overflow
;
1297 return bfd_reloc_ok
;
1300 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1301 from the gp register? XXX */
1303 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1304 arelent
*, asection
*,
1305 boolean
, PTR
, bfd_vma
));
1307 bfd_reloc_status_type
1308 _bfd_mips_elf_gprel32_reloc (abfd
,
1316 arelent
*reloc_entry
;
1319 asection
*input_section
;
1321 char **error_message
;
1323 boolean relocateable
;
1324 bfd_reloc_status_type ret
;
1327 /* If we're relocating, and this is an external symbol with no
1328 addend, we don't want to change anything. We will only have an
1329 addend if this is a newly created reloc, not read from an ELF
1331 if (output_bfd
!= (bfd
*) NULL
1332 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1333 && reloc_entry
->addend
== 0)
1335 *error_message
= (char *)
1336 _("32bits gp relative relocation occurs for an external symbol");
1337 return bfd_reloc_outofrange
;
1340 if (output_bfd
!= (bfd
*) NULL
)
1342 relocateable
= true;
1343 gp
= _bfd_get_gp_value (output_bfd
);
1347 relocateable
= false;
1348 output_bfd
= symbol
->section
->output_section
->owner
;
1350 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1351 error_message
, &gp
);
1352 if (ret
!= bfd_reloc_ok
)
1356 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1357 relocateable
, data
, gp
);
1360 static bfd_reloc_status_type
1361 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1365 arelent
*reloc_entry
;
1366 asection
*input_section
;
1367 boolean relocateable
;
1374 if (bfd_is_com_section (symbol
->section
))
1377 relocation
= symbol
->value
;
1379 relocation
+= symbol
->section
->output_section
->vma
;
1380 relocation
+= symbol
->section
->output_offset
;
1382 if (reloc_entry
->address
> input_section
->_cooked_size
)
1383 return bfd_reloc_outofrange
;
1385 if (reloc_entry
->howto
->src_mask
== 0)
1387 /* This case arises with the 64-bit MIPS ELF ABI. */
1391 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1393 /* Set val to the offset into the section or symbol. */
1394 val
+= reloc_entry
->addend
;
1396 /* Adjust val for the final section location and GP value. If we
1397 are producing relocateable output, we don't want to do this for
1398 an external symbol. */
1400 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1401 val
+= relocation
- gp
;
1403 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1406 reloc_entry
->address
+= input_section
->output_offset
;
1408 return bfd_reloc_ok
;
1411 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1412 generated when addreses are 64 bits. The upper 32 bits are a simle
1415 static bfd_reloc_status_type
1416 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1417 output_bfd
, error_message
)
1419 arelent
*reloc_entry
;
1422 asection
*input_section
;
1424 char **error_message
;
1426 bfd_reloc_status_type r
;
1431 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1432 input_section
, output_bfd
, error_message
);
1433 if (r
!= bfd_reloc_continue
)
1436 /* Do a normal 32 bit relocation on the lower 32 bits. */
1437 reloc32
= *reloc_entry
;
1438 if (bfd_big_endian (abfd
))
1439 reloc32
.address
+= 4;
1440 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1441 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1442 output_bfd
, error_message
);
1444 /* Sign extend into the upper 32 bits. */
1445 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1446 if ((val
& 0x80000000) != 0)
1450 addr
= reloc_entry
->address
;
1451 if (bfd_little_endian (abfd
))
1453 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1458 /* Handle a mips16 jump. */
1460 static bfd_reloc_status_type
1461 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1462 output_bfd
, error_message
)
1464 arelent
*reloc_entry
;
1467 asection
*input_section
;
1469 char **error_message
;
1471 if (output_bfd
!= (bfd
*) NULL
1472 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1473 && reloc_entry
->addend
== 0)
1475 reloc_entry
->address
+= input_section
->output_offset
;
1476 return bfd_reloc_ok
;
1481 static boolean warned
;
1484 (*_bfd_error_handler
)
1485 (_("Linking mips16 objects into %s format is not supported"),
1486 bfd_get_target (input_section
->output_section
->owner
));
1490 return bfd_reloc_undefined
;
1493 /* Handle a mips16 GP relative reloc. */
1495 static bfd_reloc_status_type
1496 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1497 output_bfd
, error_message
)
1499 arelent
*reloc_entry
;
1502 asection
*input_section
;
1504 char **error_message
;
1506 boolean relocateable
;
1507 bfd_reloc_status_type ret
;
1509 unsigned short extend
, insn
;
1510 unsigned long final
;
1512 /* If we're relocating, and this is an external symbol with no
1513 addend, we don't want to change anything. We will only have an
1514 addend if this is a newly created reloc, not read from an ELF
1516 if (output_bfd
!= NULL
1517 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1518 && reloc_entry
->addend
== 0)
1520 reloc_entry
->address
+= input_section
->output_offset
;
1521 return bfd_reloc_ok
;
1524 if (output_bfd
!= NULL
)
1525 relocateable
= true;
1528 relocateable
= false;
1529 output_bfd
= symbol
->section
->output_section
->owner
;
1532 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1534 if (ret
!= bfd_reloc_ok
)
1537 if (reloc_entry
->address
> input_section
->_cooked_size
)
1538 return bfd_reloc_outofrange
;
1540 /* Pick up the mips16 extend instruction and the real instruction. */
1541 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1542 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1544 /* Stuff the current addend back as a 32 bit value, do the usual
1545 relocation, and then clean up. */
1547 (((extend
& 0x1f) << 11)
1550 (bfd_byte
*) data
+ reloc_entry
->address
);
1552 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1553 relocateable
, data
, gp
);
1555 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1558 | ((final
>> 11) & 0x1f)
1560 (bfd_byte
*) data
+ reloc_entry
->address
);
1564 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1569 /* Return the ISA for a MIPS e_flags value. */
1572 elf_mips_isa (flags
)
1575 switch (flags
& EF_MIPS_ARCH
)
1589 /* Return the MACH for a MIPS e_flags value. */
1592 elf_mips_mach (flags
)
1595 switch (flags
& EF_MIPS_MACH
)
1597 case E_MIPS_MACH_3900
:
1598 return bfd_mach_mips3900
;
1600 case E_MIPS_MACH_4010
:
1601 return bfd_mach_mips4010
;
1603 case E_MIPS_MACH_4100
:
1604 return bfd_mach_mips4100
;
1605 /* start-sanitize-vr4320 */
1607 case E_MIPS_MACH_4320
:
1608 return bfd_mach_mips4320
;
1609 /* end-sanitize-vr4320 */
1611 case E_MIPS_MACH_4650
:
1612 return bfd_mach_mips4650
;
1613 /* start-sanitize-tx49 */
1615 case E_MIPS_MACH_4900
:
1616 return bfd_mach_mips4900
;
1617 /* end-sanitize-tx49 */
1618 /* start-sanitize-vr5400 */
1620 case E_MIPS_MACH_5400
:
1621 return bfd_mach_mips5400
;
1622 /* end-sanitize-vr5400 */
1623 /* start-sanitize-r5900 */
1625 case E_MIPS_MACH_5900
:
1626 return bfd_mach_mips5900
;
1627 /* end-sanitize-r5900 */
1630 switch (flags
& EF_MIPS_ARCH
)
1634 return bfd_mach_mips3000
;
1638 return bfd_mach_mips6000
;
1642 return bfd_mach_mips4000
;
1646 return bfd_mach_mips8000
;
1654 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1656 struct elf_reloc_map
{
1657 bfd_reloc_code_real_type bfd_reloc_val
;
1658 enum reloc_type elf_reloc_val
;
1661 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1663 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1664 { BFD_RELOC_16
, R_MIPS_16
},
1665 { BFD_RELOC_32
, R_MIPS_32
},
1666 { BFD_RELOC_64
, R_MIPS_64
},
1667 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1668 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1669 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1670 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1671 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1672 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1673 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1674 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1675 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1676 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1677 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1678 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1679 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
},
1680 /* start-sanitize-r5900 */
1681 { BFD_RELOC_MIPS15_S3
, R_MIPS15_S3
},
1682 /* end-sanitize-r5900 */
1685 /* Given a BFD reloc type, return a howto structure. */
1687 static reloc_howto_type
*
1688 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1690 bfd_reloc_code_real_type code
;
1694 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1696 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1697 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1702 case BFD_RELOC_CTOR
:
1703 /* We need to handle BFD_RELOC_CTOR specially.
1704 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1705 size of addresses on this architecture. */
1706 if (bfd_arch_bits_per_address (abfd
) == 32)
1707 return &elf_mips_howto_table
[(int) R_MIPS_32
];
1709 return &elf_mips_ctor64_howto
;
1711 case BFD_RELOC_MIPS16_JMP
:
1712 return &elf_mips16_jump_howto
;
1713 case BFD_RELOC_MIPS16_GPREL
:
1714 return &elf_mips16_gprel_howto
;
1715 /* start-sanitize-sky */
1716 case BFD_RELOC_MIPS_DVP_11_PCREL
:
1717 return &elf_mips_dvp_11_pcrel_howto
;
1718 case BFD_RELOC_MIPS_DVP_27_S4
:
1719 return &elf_mips_dvp_27_s4_howto
;
1720 /* end-sanitize-sky */
1721 case BFD_RELOC_VTABLE_INHERIT
:
1722 return &elf_mips_gnu_vtinherit_howto
;
1723 case BFD_RELOC_VTABLE_ENTRY
:
1724 return &elf_mips_gnu_vtentry_howto
;
1730 /* Given a MIPS reloc type, fill in an arelent structure. */
1733 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1736 Elf32_Internal_Rel
*dst
;
1738 unsigned int r_type
;
1740 r_type
= ELF32_R_TYPE (dst
->r_info
);
1744 cache_ptr
->howto
= &elf_mips16_jump_howto
;
1746 case R_MIPS16_GPREL
:
1747 cache_ptr
->howto
= &elf_mips16_gprel_howto
;
1749 /* start-sanitize-sky */
1750 case R_MIPS_DVP_11_PCREL
:
1751 cache_ptr
->howto
= &elf_mips_dvp_11_pcrel_howto
;
1753 case R_MIPS_DVP_27_S4
:
1754 cache_ptr
->howto
= &elf_mips_dvp_27_s4_howto
;
1756 /* end-sanitize-sky */
1757 case R_MIPS_GNU_VTINHERIT
:
1758 cache_ptr
->howto
= &elf_mips_gnu_vtinherit_howto
;
1760 case R_MIPS_GNU_VTENTRY
:
1761 cache_ptr
->howto
= &elf_mips_gnu_vtentry_howto
;
1765 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1766 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1770 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1771 value for the object file. We get the addend now, rather than
1772 when we do the relocation, because the symbol manipulations done
1773 by the linker may cause us to lose track of the input BFD. */
1774 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1775 && (r_type
== (unsigned int) R_MIPS_GPREL16
1776 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1777 cache_ptr
->addend
= elf_gp (abfd
);
1780 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1781 routines swap this structure in and out. They are used outside of
1782 BFD, so they are globally visible. */
1785 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1787 const Elf32_External_RegInfo
*ex
;
1790 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1791 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1792 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1793 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1794 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1795 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1799 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1801 const Elf32_RegInfo
*in
;
1802 Elf32_External_RegInfo
*ex
;
1804 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1805 (bfd_byte
*) ex
->ri_gprmask
);
1806 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1807 (bfd_byte
*) ex
->ri_cprmask
[0]);
1808 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1809 (bfd_byte
*) ex
->ri_cprmask
[1]);
1810 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1811 (bfd_byte
*) ex
->ri_cprmask
[2]);
1812 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1813 (bfd_byte
*) ex
->ri_cprmask
[3]);
1814 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1815 (bfd_byte
*) ex
->ri_gp_value
);
1818 /* In the 64 bit ABI, the .MIPS.options section holds register
1819 information in an Elf64_Reginfo structure. These routines swap
1820 them in and out. They are globally visible because they are used
1821 outside of BFD. These routines are here so that gas can call them
1822 without worrying about whether the 64 bit ABI has been included. */
1825 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1827 const Elf64_External_RegInfo
*ex
;
1828 Elf64_Internal_RegInfo
*in
;
1830 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1831 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
1832 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1833 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1834 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1835 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1836 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1840 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1842 const Elf64_Internal_RegInfo
*in
;
1843 Elf64_External_RegInfo
*ex
;
1845 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1846 (bfd_byte
*) ex
->ri_gprmask
);
1847 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
1848 (bfd_byte
*) ex
->ri_pad
);
1849 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1850 (bfd_byte
*) ex
->ri_cprmask
[0]);
1851 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1852 (bfd_byte
*) ex
->ri_cprmask
[1]);
1853 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1854 (bfd_byte
*) ex
->ri_cprmask
[2]);
1855 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1856 (bfd_byte
*) ex
->ri_cprmask
[3]);
1857 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1858 (bfd_byte
*) ex
->ri_gp_value
);
1861 /* Swap an entry in a .gptab section. Note that these routines rely
1862 on the equivalence of the two elements of the union. */
1865 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1867 const Elf32_External_gptab
*ex
;
1870 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1871 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1875 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1877 const Elf32_gptab
*in
;
1878 Elf32_External_gptab
*ex
;
1880 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1881 ex
->gt_entry
.gt_g_value
);
1882 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1883 ex
->gt_entry
.gt_bytes
);
1887 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1889 const Elf32_compact_rel
*in
;
1890 Elf32_External_compact_rel
*ex
;
1892 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
1893 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
1894 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
1895 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
1896 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
1897 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
1901 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1903 const Elf32_crinfo
*in
;
1904 Elf32_External_crinfo
*ex
;
1908 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1909 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1910 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1911 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1912 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
1913 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
1914 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
1917 /* Swap in an options header. */
1920 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1922 const Elf_External_Options
*ex
;
1923 Elf_Internal_Options
*in
;
1925 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
1926 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
1927 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
1928 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
1931 /* Swap out an options header. */
1934 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
1936 const Elf_Internal_Options
*in
;
1937 Elf_External_Options
*ex
;
1939 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
1940 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
1941 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
1942 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
1945 /* Determine whether a symbol is global for the purposes of splitting
1946 the symbol table into global symbols and local symbols. At least
1947 on Irix 5, this split must be between section symbols and all other
1948 symbols. On most ELF targets the split is between static symbols
1949 and externally visible symbols. */
1953 mips_elf_sym_is_global (abfd
, sym
)
1957 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
1960 /* Set the right machine number for a MIPS ELF file. This is used for
1961 both the 32-bit and the 64-bit ABI. */
1964 _bfd_mips_elf_object_p (abfd
)
1967 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
,
1968 elf_mips_mach (elf_elfheader (abfd
)->e_flags
));
1972 /* Set the right machine number for a 32-bit MIPS ELF file. */
1975 mips_elf32_object_p (abfd
)
1978 /* Irix 5 is broken. Object file symbol tables are not always
1979 sorted correctly such that local symbols precede global symbols,
1980 and the sh_info field in the symbol table is not always right. */
1981 elf_bad_symtab (abfd
) = true;
1983 return _bfd_mips_elf_object_p (abfd
);
1986 /* The final processing done just before writing out a MIPS ELF object
1987 file. This gets the MIPS architecture right based on the machine
1988 number. This is used by both the 32-bit and the 64-bit ABI. */
1992 _bfd_mips_elf_final_write_processing (abfd
, linker
)
1998 Elf_Internal_Shdr
**hdrpp
;
2002 switch (bfd_get_mach (abfd
))
2005 case bfd_mach_mips3000
:
2006 val
= E_MIPS_ARCH_1
;
2009 case bfd_mach_mips3900
:
2010 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
2013 case bfd_mach_mips6000
:
2014 val
= E_MIPS_ARCH_2
;
2017 case bfd_mach_mips4000
:
2018 val
= E_MIPS_ARCH_3
;
2021 case bfd_mach_mips4010
:
2022 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
2025 case bfd_mach_mips4100
:
2026 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
2028 /* start-sanitize-vr4320 */
2030 case bfd_mach_mips4320
:
2031 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4320
;
2033 /* end-sanitize-vr4320 */
2035 case bfd_mach_mips4650
:
2036 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
2038 /* start-sanitize-tx49 */
2040 case bfd_mach_mips4900
:
2041 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4900
;
2043 /* end-sanitize-tx49 */
2044 /* start-sanitize-vr5400 */
2046 case bfd_mach_mips5400
:
2047 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_5400
;
2049 /* end-sanitize-vr5400 */
2050 /* start-sanitize-r5900 */
2052 case bfd_mach_mips5900
:
2053 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_5900
;
2055 /* end-sanitize-r5900 */
2057 case bfd_mach_mips8000
:
2058 val
= E_MIPS_ARCH_4
;
2062 elf_elfheader (abfd
)->e_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2063 elf_elfheader (abfd
)->e_flags
|= val
;
2065 /* Set the sh_info field for .gptab sections and other appropriate
2066 info for each special section. */
2067 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
2068 i
< elf_elfheader (abfd
)->e_shnum
;
2071 switch ((*hdrpp
)->sh_type
)
2073 case SHT_MIPS_LIBLIST
:
2074 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
2076 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2079 case SHT_MIPS_GPTAB
:
2080 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2081 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2082 BFD_ASSERT (name
!= NULL
2083 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
2084 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
2085 BFD_ASSERT (sec
!= NULL
);
2086 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2089 case SHT_MIPS_CONTENT
:
2090 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2091 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2092 BFD_ASSERT (name
!= NULL
2093 && strncmp (name
, ".MIPS.content",
2094 sizeof ".MIPS.content" - 1) == 0);
2095 sec
= bfd_get_section_by_name (abfd
,
2096 name
+ sizeof ".MIPS.content" - 1);
2097 BFD_ASSERT (sec
!= NULL
);
2098 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2101 case SHT_MIPS_SYMBOL_LIB
:
2102 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
2104 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2105 sec
= bfd_get_section_by_name (abfd
, ".liblist");
2107 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2110 case SHT_MIPS_EVENTS
:
2111 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2112 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2113 BFD_ASSERT (name
!= NULL
);
2114 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
2115 sec
= bfd_get_section_by_name (abfd
,
2116 name
+ sizeof ".MIPS.events" - 1);
2119 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
2120 sizeof ".MIPS.post_rel" - 1) == 0);
2121 sec
= bfd_get_section_by_name (abfd
,
2123 + sizeof ".MIPS.post_rel" - 1));
2125 BFD_ASSERT (sec
!= NULL
);
2126 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2129 /* start-sanitize-sky */
2130 case SHT_DVP_OVERLAY_TABLE
:
2131 /* ??? This may not be technically necessary, just going with
2133 sec
= bfd_get_section_by_name (abfd
, SHNAME_DVP_OVERLAY_STRTAB
);
2135 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2137 /* end-sanitize-sky */
2142 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
2145 _bfd_mips_elf_set_private_flags (abfd
, flags
)
2149 BFD_ASSERT (!elf_flags_init (abfd
)
2150 || elf_elfheader (abfd
)->e_flags
== flags
);
2152 elf_elfheader (abfd
)->e_flags
= flags
;
2153 elf_flags_init (abfd
) = true;
2157 /* Copy backend specific data from one object module to another */
2160 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
2164 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2165 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2168 BFD_ASSERT (!elf_flags_init (obfd
)
2169 || (elf_elfheader (obfd
)->e_flags
2170 == elf_elfheader (ibfd
)->e_flags
));
2172 elf_gp (obfd
) = elf_gp (ibfd
);
2173 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
2174 elf_flags_init (obfd
) = true;
2178 /* Merge backend specific data from an object file to the output
2179 object file when linking. */
2182 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
2190 /* Check if we have the same endianess */
2191 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2192 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2196 if (bfd_big_endian (ibfd
))
2197 msg
= _("%s: compiled for a big endian system and target is little endian");
2199 msg
= _("%s: compiled for a little endian system and target is big endian");
2201 (*_bfd_error_handler
) (msg
, bfd_get_filename (ibfd
));
2203 bfd_set_error (bfd_error_wrong_format
);
2207 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2208 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2211 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2212 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
2213 old_flags
= elf_elfheader (obfd
)->e_flags
;
2215 if (! elf_flags_init (obfd
))
2217 elf_flags_init (obfd
) = true;
2218 elf_elfheader (obfd
)->e_flags
= new_flags
;
2220 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2221 && bfd_get_arch_info (obfd
)->the_default
)
2223 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
2224 bfd_get_mach (ibfd
)))
2231 /* Check flag compatibility. */
2233 new_flags
&= ~EF_MIPS_NOREORDER
;
2234 old_flags
&= ~EF_MIPS_NOREORDER
;
2236 if (new_flags
== old_flags
)
2241 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
2243 new_flags
&= ~EF_MIPS_PIC
;
2244 old_flags
&= ~EF_MIPS_PIC
;
2245 (*_bfd_error_handler
)
2246 (_("%s: linking PIC files with non-PIC files"),
2247 bfd_get_filename (ibfd
));
2251 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
2253 new_flags
&= ~EF_MIPS_CPIC
;
2254 old_flags
&= ~EF_MIPS_CPIC
;
2255 (*_bfd_error_handler
)
2256 (_("%s: linking abicalls files with non-abicalls files"),
2257 bfd_get_filename (ibfd
));
2261 /* Compare the ISA's. */
2262 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
2263 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
2265 /* If either has no machine specified, just compare the general isa's. */
2266 if ( !(new_flags
& EF_MIPS_MACH
) || !(old_flags
& EF_MIPS_MACH
))
2268 int new_isa
, old_isa
;
2270 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
2271 and -mips4 code. They will normally use the same data sizes and
2272 calling conventions. */
2274 new_isa
= elf_mips_isa (new_flags
);
2275 old_isa
= elf_mips_isa (old_flags
);
2276 if ((new_isa
== 1 || new_isa
== 2)
2277 ? (old_isa
!= 1 && old_isa
!= 2)
2278 : (old_isa
== 1 || old_isa
== 2))
2280 (*_bfd_error_handler
)
2281 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
2282 bfd_get_filename (ibfd
), new_isa
, old_isa
);
2289 (*_bfd_error_handler
)
2290 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
2291 bfd_get_filename (ibfd
),
2292 elf_mips_mach (new_flags
),
2293 elf_mips_mach (old_flags
));
2297 new_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2298 old_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2301 /* Warn about any other mismatches */
2302 if (new_flags
!= old_flags
)
2304 (*_bfd_error_handler
)
2305 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2306 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
2307 (unsigned long) old_flags
);
2313 bfd_set_error (bfd_error_bad_value
);
2320 /* Handle a MIPS specific section when reading an object file. This
2321 is called when elfcode.h finds a section with an unknown type.
2322 This routine supports both the 32-bit and 64-bit ELF ABI.
2324 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2328 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
2330 Elf_Internal_Shdr
*hdr
;
2333 /* There ought to be a place to keep ELF backend specific flags, but
2334 at the moment there isn't one. We just keep track of the
2335 sections by their name, instead. Fortunately, the ABI gives
2336 suggested names for all the MIPS specific sections, so we will
2337 probably get away with this. */
2338 switch (hdr
->sh_type
)
2340 case SHT_MIPS_LIBLIST
:
2341 if (strcmp (name
, _(".liblist")) != 0)
2345 if (strcmp (name
, ".msym") != 0)
2348 case SHT_MIPS_CONFLICT
:
2349 if (strcmp (name
, ".conflict") != 0)
2352 case SHT_MIPS_GPTAB
:
2353 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
2356 case SHT_MIPS_UCODE
:
2357 if (strcmp (name
, ".ucode") != 0)
2360 case SHT_MIPS_DEBUG
:
2361 if (strcmp (name
, ".mdebug") != 0)
2364 case SHT_MIPS_REGINFO
:
2365 if (strcmp (name
, ".reginfo") != 0
2366 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
2369 case SHT_MIPS_IFACE
:
2370 if (strcmp (name
, ".MIPS.interfaces") != 0)
2373 case SHT_MIPS_CONTENT
:
2374 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2377 case SHT_MIPS_OPTIONS
:
2378 if (strcmp (name
, ".options") != 0
2379 && strcmp (name
, ".MIPS.options") != 0)
2382 case SHT_MIPS_DWARF
:
2383 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2386 case SHT_MIPS_SYMBOL_LIB
:
2387 if (strcmp (name
, ".MIPS.symlib") != 0)
2390 case SHT_MIPS_EVENTS
:
2391 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2392 && strncmp (name
, ".MIPS.post_rel",
2393 sizeof ".MIPS.post_rel" - 1) != 0)
2396 /* start-sanitize-sky */
2397 case SHT_DVP_OVERLAY_TABLE
:
2398 if (strcmp (name
, SHNAME_DVP_OVERLAY_TABLE
) !=0)
2401 case SHT_DVP_OVERLAY
:
2402 if (strncmp (name
, SHNAME_DVP_OVERLAY_PREFIX
,
2403 sizeof (SHNAME_DVP_OVERLAY_PREFIX
) - 1) !=0)
2406 /* end-sanitize-sky */
2411 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2414 if (hdr
->sh_type
== SHT_MIPS_DEBUG
)
2416 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
2417 (bfd_get_section_flags (abfd
,
2426 /* Handle a 32-bit MIPS ELF specific section. */
2429 mips_elf32_section_from_shdr (abfd
, hdr
, name
)
2431 Elf_Internal_Shdr
*hdr
;
2434 if (! _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
))
2437 /* FIXME: We should record sh_info for a .gptab section. */
2439 /* For a .reginfo section, set the gp value in the tdata information
2440 from the contents of this section. We need the gp value while
2441 processing relocs, so we just get it now. The .reginfo section
2442 is not used in the 64-bit MIPS ELF ABI. */
2443 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2445 Elf32_External_RegInfo ext
;
2448 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
2449 (file_ptr
) 0, sizeof ext
))
2451 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
2452 elf_gp (abfd
) = s
.ri_gp_value
;
2455 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2456 set the gp value based on what we find. We may see both
2457 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2458 they should agree. */
2459 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
2461 bfd_byte
*contents
, *l
, *lend
;
2463 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
2464 if (contents
== NULL
)
2466 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
2467 (file_ptr
) 0, hdr
->sh_size
))
2473 lend
= contents
+ hdr
->sh_size
;
2474 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2476 Elf_Internal_Options intopt
;
2478 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2480 if (intopt
.kind
== ODK_REGINFO
)
2482 Elf32_RegInfo intreg
;
2484 bfd_mips_elf32_swap_reginfo_in
2486 ((Elf32_External_RegInfo
*)
2487 (l
+ sizeof (Elf_External_Options
))),
2489 elf_gp (abfd
) = intreg
.ri_gp_value
;
2499 /* Set the correct type for a MIPS ELF section. We do this by the
2500 section name, which is a hack, but ought to work. This routine is
2501 used by both the 32-bit and the 64-bit ABI. */
2504 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
2506 Elf32_Internal_Shdr
*hdr
;
2509 register const char *name
;
2511 name
= bfd_get_section_name (abfd
, sec
);
2513 if (strcmp (name
, ".liblist") == 0)
2515 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
2516 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
2517 /* The sh_link field is set in final_write_processing. */
2519 else if (strcmp (name
, ".msym") == 0)
2521 hdr
->sh_type
= SHT_MIPS_MSYM
;
2522 hdr
->sh_entsize
= 8;
2523 /* FIXME: Set the sh_info field. */
2525 else if (strcmp (name
, ".conflict") == 0)
2526 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
2527 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2529 hdr
->sh_type
= SHT_MIPS_GPTAB
;
2530 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
2531 /* The sh_info field is set in final_write_processing. */
2533 else if (strcmp (name
, ".ucode") == 0)
2534 hdr
->sh_type
= SHT_MIPS_UCODE
;
2535 else if (strcmp (name
, ".mdebug") == 0)
2537 hdr
->sh_type
= SHT_MIPS_DEBUG
;
2538 /* In a shared object on Irix 5.3, the .mdebug section has an
2539 entsize of 0. FIXME: Does this matter? */
2540 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2541 hdr
->sh_entsize
= 0;
2543 hdr
->sh_entsize
= 1;
2545 else if (strcmp (name
, ".reginfo") == 0)
2547 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2548 /* In a shared object on Irix 5.3, the .reginfo section has an
2549 entsize of 0x18. FIXME: Does this matter? */
2550 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2551 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2553 hdr
->sh_entsize
= 1;
2555 /* Force the section size to the correct value, even if the
2556 linker thinks it is larger. The link routine below will only
2557 write out this much data for .reginfo. */
2558 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf32_External_RegInfo
);
2560 else if (SGI_COMPAT (abfd
)
2561 && (strcmp (name
, ".hash") == 0
2562 || strcmp (name
, ".dynamic") == 0
2563 || strcmp (name
, ".dynstr") == 0))
2565 hdr
->sh_entsize
= 0;
2566 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2568 else if (strcmp (name
, ".got") == 0
2569 || strcmp (name
, ".sdata") == 0
2570 || strcmp (name
, ".sbss") == 0
2571 || strcmp (name
, ".lit4") == 0
2572 || strcmp (name
, ".lit8") == 0)
2573 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2574 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2576 hdr
->sh_type
= SHT_MIPS_IFACE
;
2577 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2579 else if (strcmp (name
, ".MIPS.content") == 0)
2581 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2582 /* The sh_info field is set in final_write_processing. */
2584 else if (strcmp (name
, ".options") == 0
2585 || strcmp (name
, ".MIPS.options") == 0)
2587 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2588 hdr
->sh_entsize
= 1;
2589 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2591 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2592 hdr
->sh_type
= SHT_MIPS_DWARF
;
2593 else if (strcmp (name
, ".MIPS.symlib") == 0)
2595 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2596 /* The sh_link and sh_info fields are set in
2597 final_write_processing. */
2599 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2600 || strncmp (name
, ".MIPS.post_rel",
2601 sizeof ".MIPS.post_rel" - 1) == 0)
2603 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2604 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2605 /* The sh_link field is set in final_write_processing. */
2607 /* start-sanitize-sky */
2608 else if (strcmp (name
, SHNAME_DVP_OVERLAY_TABLE
) == 0)
2610 hdr
->sh_type
= SHT_DVP_OVERLAY_TABLE
;
2611 hdr
->sh_entsize
= sizeof (Elf32_Dvp_External_Overlay
);
2612 /* The sh_link field is set in final_write_processing. */
2614 else if (strcmp (name
, SHNAME_DVP_OVERLAY_STRTAB
) == 0)
2615 hdr
->sh_type
= SHT_STRTAB
;
2616 else if (strncmp (name
, SHNAME_DVP_OVERLAY_PREFIX
,
2617 sizeof (SHNAME_DVP_OVERLAY_PREFIX
) - 1) == 0)
2618 hdr
->sh_type
= SHT_DVP_OVERLAY
;
2619 /* end-sanitize-sky */
2624 /* Given a BFD section, try to locate the corresponding ELF section
2625 index. This is used by both the 32-bit and the 64-bit ABI.
2626 Actually, it's not clear to me that the 64-bit ABI supports these,
2627 but for non-PIC objects we will certainly want support for at least
2628 the .scommon section. */
2631 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2633 Elf32_Internal_Shdr
*hdr
;
2637 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2639 *retval
= SHN_MIPS_SCOMMON
;
2642 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2644 *retval
= SHN_MIPS_ACOMMON
;
2650 /* When are writing out the .options or .MIPS.options section,
2651 remember the bytes we are writing out, so that we can install the
2652 GP value in the section_processing routine. */
2655 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2660 bfd_size_type count
;
2662 if (strcmp (section
->name
, ".options") == 0
2663 || strcmp (section
->name
, ".MIPS.options") == 0)
2667 if (elf_section_data (section
) == NULL
)
2669 section
->used_by_bfd
=
2670 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
2671 if (elf_section_data (section
) == NULL
)
2674 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
2679 if (section
->_cooked_size
!= 0)
2680 size
= section
->_cooked_size
;
2682 size
= section
->_raw_size
;
2683 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
2686 elf_section_data (section
)->tdata
= (PTR
) c
;
2689 memcpy (c
+ offset
, location
, count
);
2692 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
2696 /* Work over a section just before writing it out. This routine is
2697 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2698 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2702 _bfd_mips_elf_section_processing (abfd
, hdr
)
2704 Elf_Internal_Shdr
*hdr
;
2706 if (hdr
->bfd_section
!= NULL
)
2708 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
2710 if (strcmp (name
, ".sdata") == 0)
2712 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2713 hdr
->sh_type
= SHT_PROGBITS
;
2715 else if (strcmp (name
, ".sbss") == 0)
2717 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2718 hdr
->sh_type
= SHT_NOBITS
;
2720 else if (strcmp (name
, ".lit8") == 0
2721 || strcmp (name
, ".lit4") == 0)
2723 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2724 hdr
->sh_type
= SHT_PROGBITS
;
2726 else if (strcmp (name
, ".compact_rel") == 0)
2729 hdr
->sh_type
= SHT_PROGBITS
;
2731 else if (strcmp (name
, ".rtproc") == 0)
2733 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
2735 unsigned int adjust
;
2737 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
2739 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
2747 /* Work over a section just before writing it out. We update the GP
2748 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2749 on the value we are using. */
2752 mips_elf32_section_processing (abfd
, hdr
)
2754 Elf32_Internal_Shdr
*hdr
;
2756 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2760 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2761 BFD_ASSERT (hdr
->contents
== NULL
);
2764 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2767 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2768 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2772 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2773 && hdr
->bfd_section
!= NULL
2774 && elf_section_data (hdr
->bfd_section
) != NULL
2775 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2777 bfd_byte
*contents
, *l
, *lend
;
2779 /* We stored the section contents in the elf_section_data tdata
2780 field in the set_section_contents routine. We save the
2781 section contents so that we don't have to read them again.
2782 At this point we know that elf_gp is set, so we can look
2783 through the section contents to see if there is an
2784 ODK_REGINFO structure. */
2786 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2788 lend
= contents
+ hdr
->sh_size
;
2789 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2791 Elf_Internal_Options intopt
;
2793 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2795 if (intopt
.kind
== ODK_REGINFO
)
2802 + sizeof (Elf_External_Options
)
2803 + (sizeof (Elf32_External_RegInfo
) - 4)),
2806 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
2807 if (bfd_write (buf
, 1, 4, abfd
) != 4)
2814 return _bfd_mips_elf_section_processing (abfd
, hdr
);
2817 /* MIPS ELF uses two common sections. One is the usual one, and the
2818 other is for small objects. All the small objects are kept
2819 together, and then referenced via the gp pointer, which yields
2820 faster assembler code. This is what we use for the small common
2821 section. This approach is copied from ecoff.c. */
2822 static asection mips_elf_scom_section
;
2823 static asymbol mips_elf_scom_symbol
;
2824 static asymbol
*mips_elf_scom_symbol_ptr
;
2826 /* MIPS ELF also uses an acommon section, which represents an
2827 allocated common symbol which may be overridden by a
2828 definition in a shared library. */
2829 static asection mips_elf_acom_section
;
2830 static asymbol mips_elf_acom_symbol
;
2831 static asymbol
*mips_elf_acom_symbol_ptr
;
2833 /* The Irix 5 support uses two virtual sections, which represent
2834 text/data symbols defined in dynamic objects. */
2835 static asection mips_elf_text_section
;
2836 static asection
*mips_elf_text_section_ptr
;
2837 static asymbol mips_elf_text_symbol
;
2838 static asymbol
*mips_elf_text_symbol_ptr
;
2840 static asection mips_elf_data_section
;
2841 static asection
*mips_elf_data_section_ptr
;
2842 static asymbol mips_elf_data_symbol
;
2843 static asymbol
*mips_elf_data_symbol_ptr
;
2845 /* Handle the special MIPS section numbers that a symbol may use.
2846 This is used for both the 32-bit and the 64-bit ABI. */
2849 _bfd_mips_elf_symbol_processing (abfd
, asym
)
2853 elf_symbol_type
*elfsym
;
2855 elfsym
= (elf_symbol_type
*) asym
;
2856 switch (elfsym
->internal_elf_sym
.st_shndx
)
2858 case SHN_MIPS_ACOMMON
:
2859 /* This section is used in a dynamically linked executable file.
2860 It is an allocated common section. The dynamic linker can
2861 either resolve these symbols to something in a shared
2862 library, or it can just leave them here. For our purposes,
2863 we can consider these symbols to be in a new section. */
2864 if (mips_elf_acom_section
.name
== NULL
)
2866 /* Initialize the acommon section. */
2867 mips_elf_acom_section
.name
= ".acommon";
2868 mips_elf_acom_section
.flags
= SEC_ALLOC
;
2869 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
2870 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
2871 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
2872 mips_elf_acom_symbol
.name
= ".acommon";
2873 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
2874 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
2875 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
2877 asym
->section
= &mips_elf_acom_section
;
2881 /* Common symbols less than the GP size are automatically
2882 treated as SHN_MIPS_SCOMMON symbols. */
2883 if (asym
->value
> elf_gp_size (abfd
))
2886 case SHN_MIPS_SCOMMON
:
2887 if (mips_elf_scom_section
.name
== NULL
)
2889 /* Initialize the small common section. */
2890 mips_elf_scom_section
.name
= ".scommon";
2891 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
2892 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
2893 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
2894 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
2895 mips_elf_scom_symbol
.name
= ".scommon";
2896 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2897 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
2898 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
2900 asym
->section
= &mips_elf_scom_section
;
2901 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2904 case SHN_MIPS_SUNDEFINED
:
2905 asym
->section
= bfd_und_section_ptr
;
2908 #if 0 /* for SGI_COMPAT */
2910 asym
->section
= mips_elf_text_section_ptr
;
2914 asym
->section
= mips_elf_data_section_ptr
;
2920 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
2924 mips_elf_additional_program_headers (abfd
)
2932 if (! SGI_COMPAT (abfd
))
2935 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2936 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2938 /* We need a PT_MIPS_REGINFO segment. */
2942 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2943 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2945 /* We need a PT_MIPS_RTPROC segment. */
2952 /* Modify the segment map for an Irix 5 executable. */
2955 mips_elf_modify_segment_map (abfd
)
2959 struct elf_segment_map
*m
, **pm
;
2961 if (! SGI_COMPAT (abfd
))
2964 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
2966 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2967 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2969 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2970 if (m
->p_type
== PT_MIPS_REGINFO
)
2974 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2978 m
->p_type
= PT_MIPS_REGINFO
;
2982 /* We want to put it after the PHDR and INTERP segments. */
2983 pm
= &elf_tdata (abfd
)->segment_map
;
2985 && ((*pm
)->p_type
== PT_PHDR
2986 || (*pm
)->p_type
== PT_INTERP
))
2994 /* If there are .dynamic and .mdebug sections, we make a room for
2995 the RTPROC header. FIXME: Rewrite without section names. */
2996 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
2997 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2998 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3000 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3001 if (m
->p_type
== PT_MIPS_RTPROC
)
3005 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3009 m
->p_type
= PT_MIPS_RTPROC
;
3011 s
= bfd_get_section_by_name (abfd
, ".rtproc");
3016 m
->p_flags_valid
= 1;
3024 /* We want to put it after the DYNAMIC segment. */
3025 pm
= &elf_tdata (abfd
)->segment_map
;
3026 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
3036 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
3037 .dynsym, and .hash sections, and everything in between. */
3038 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
3039 if ((*pm
)->p_type
== PT_DYNAMIC
)
3044 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
3046 static const char *sec_names
[] =
3047 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
3050 struct elf_segment_map
*n
;
3054 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
3056 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
3057 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3063 sz
= s
->_cooked_size
;
3066 if (high
< s
->vma
+ sz
)
3072 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3073 if ((s
->flags
& SEC_LOAD
) != 0
3076 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3080 n
= ((struct elf_segment_map
*)
3081 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
3088 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3090 if ((s
->flags
& SEC_LOAD
) != 0
3093 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3107 /* The structure of the runtime procedure descriptor created by the
3108 loader for use by the static exception system. */
3110 typedef struct runtime_pdr
{
3111 bfd_vma adr
; /* memory address of start of procedure */
3112 long regmask
; /* save register mask */
3113 long regoffset
; /* save register offset */
3114 long fregmask
; /* save floating point register mask */
3115 long fregoffset
; /* save floating point register offset */
3116 long frameoffset
; /* frame size */
3117 short framereg
; /* frame pointer register */
3118 short pcreg
; /* offset or reg of return pc */
3119 long irpss
; /* index into the runtime string table */
3121 struct exception_info
*exception_info
;/* pointer to exception array */
3123 #define cbRPDR sizeof(RPDR)
3124 #define rpdNil ((pRPDR) 0)
3126 /* Swap RPDR (runtime procedure table entry) for output. */
3128 static void ecoff_swap_rpdr_out
3129 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
3132 ecoff_swap_rpdr_out (abfd
, in
, ex
)
3135 struct rpdr_ext
*ex
;
3137 /* ecoff_put_off was defined in ecoffswap.h. */
3138 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
3139 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
3140 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
3141 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
3142 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
3143 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
3145 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
3146 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
3148 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
3150 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
3154 /* Read ECOFF debugging information from a .mdebug section into a
3155 ecoff_debug_info structure. */
3158 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
3161 struct ecoff_debug_info
*debug
;
3164 const struct ecoff_debug_swap
*swap
;
3165 char *ext_hdr
= NULL
;
3167 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3169 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
3170 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
3173 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
3174 swap
->external_hdr_size
)
3178 symhdr
= &debug
->symbolic_header
;
3179 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
3181 /* The symbolic header contains absolute file offsets and sizes to
3183 #define READ(ptr, offset, count, size, type) \
3184 if (symhdr->count == 0) \
3185 debug->ptr = NULL; \
3188 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
3189 if (debug->ptr == NULL) \
3190 goto error_return; \
3191 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3192 || (bfd_read (debug->ptr, size, symhdr->count, \
3193 abfd) != size * symhdr->count)) \
3194 goto error_return; \
3197 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
3198 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
3199 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
3200 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
3201 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
3202 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
3204 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
3205 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
3206 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
3207 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
3208 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
3212 debug
->adjust
= NULL
;
3217 if (ext_hdr
!= NULL
)
3219 if (debug
->line
!= NULL
)
3221 if (debug
->external_dnr
!= NULL
)
3222 free (debug
->external_dnr
);
3223 if (debug
->external_pdr
!= NULL
)
3224 free (debug
->external_pdr
);
3225 if (debug
->external_sym
!= NULL
)
3226 free (debug
->external_sym
);
3227 if (debug
->external_opt
!= NULL
)
3228 free (debug
->external_opt
);
3229 if (debug
->external_aux
!= NULL
)
3230 free (debug
->external_aux
);
3231 if (debug
->ss
!= NULL
)
3233 if (debug
->ssext
!= NULL
)
3234 free (debug
->ssext
);
3235 if (debug
->external_fdr
!= NULL
)
3236 free (debug
->external_fdr
);
3237 if (debug
->external_rfd
!= NULL
)
3238 free (debug
->external_rfd
);
3239 if (debug
->external_ext
!= NULL
)
3240 free (debug
->external_ext
);
3244 /* MIPS ELF local labels start with '$', not 'L'. */
3248 mips_elf_is_local_label_name (abfd
, name
)
3255 /* On Irix 6, the labels go back to starting with '.', so we accept
3256 the generic ELF local label syntax as well. */
3257 return _bfd_elf_is_local_label_name (abfd
, name
);
3260 /* MIPS ELF uses a special find_nearest_line routine in order the
3261 handle the ECOFF debugging information. */
3263 struct mips_elf_find_line
3265 struct ecoff_debug_info d
;
3266 struct ecoff_find_line i
;
3270 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
3271 functionname_ptr
, line_ptr
)
3276 const char **filename_ptr
;
3277 const char **functionname_ptr
;
3278 unsigned int *line_ptr
;
3282 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3283 filename_ptr
, functionname_ptr
,
3287 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
3291 struct mips_elf_find_line
*fi
;
3292 const struct ecoff_debug_swap
* const swap
=
3293 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3295 /* If we are called during a link, mips_elf_final_link may have
3296 cleared the SEC_HAS_CONTENTS field. We force it back on here
3297 if appropriate (which it normally will be). */
3298 origflags
= msec
->flags
;
3299 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
3300 msec
->flags
|= SEC_HAS_CONTENTS
;
3302 fi
= elf_tdata (abfd
)->find_line_info
;
3305 bfd_size_type external_fdr_size
;
3308 struct fdr
*fdr_ptr
;
3310 fi
= ((struct mips_elf_find_line
*)
3311 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
3314 msec
->flags
= origflags
;
3318 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
3320 msec
->flags
= origflags
;
3324 /* Swap in the FDR information. */
3325 fi
->d
.fdr
= ((struct fdr
*)
3327 (fi
->d
.symbolic_header
.ifdMax
*
3328 sizeof (struct fdr
))));
3329 if (fi
->d
.fdr
== NULL
)
3331 msec
->flags
= origflags
;
3334 external_fdr_size
= swap
->external_fdr_size
;
3335 fdr_ptr
= fi
->d
.fdr
;
3336 fraw_src
= (char *) fi
->d
.external_fdr
;
3337 fraw_end
= (fraw_src
3338 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
3339 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
3340 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
3342 elf_tdata (abfd
)->find_line_info
= fi
;
3344 /* Note that we don't bother to ever free this information.
3345 find_nearest_line is either called all the time, as in
3346 objdump -l, so the information should be saved, or it is
3347 rarely called, as in ld error messages, so the memory
3348 wasted is unimportant. Still, it would probably be a
3349 good idea for free_cached_info to throw it away. */
3352 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
3353 &fi
->i
, filename_ptr
, functionname_ptr
,
3356 msec
->flags
= origflags
;
3360 msec
->flags
= origflags
;
3363 /* Fall back on the generic ELF find_nearest_line routine. */
3365 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
3366 filename_ptr
, functionname_ptr
,
3370 /* The mips16 compiler uses a couple of special sections to handle
3371 floating point arguments.
3373 Section names that look like .mips16.fn.FNNAME contain stubs that
3374 copy floating point arguments from the fp regs to the gp regs and
3375 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3376 call should be redirected to the stub instead. If no 32 bit
3377 function calls FNNAME, the stub should be discarded. We need to
3378 consider any reference to the function, not just a call, because
3379 if the address of the function is taken we will need the stub,
3380 since the address might be passed to a 32 bit function.
3382 Section names that look like .mips16.call.FNNAME contain stubs
3383 that copy floating point arguments from the gp regs to the fp
3384 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3385 then any 16 bit function that calls FNNAME should be redirected
3386 to the stub instead. If FNNAME is not a 32 bit function, the
3387 stub should be discarded.
3389 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3390 which call FNNAME and then copy the return value from the fp regs
3391 to the gp regs. These stubs store the return value in $18 while
3392 calling FNNAME; any function which might call one of these stubs
3393 must arrange to save $18 around the call. (This case is not
3394 needed for 32 bit functions that call 16 bit functions, because
3395 16 bit functions always return floating point values in both
3398 Note that in all cases FNNAME might be defined statically.
3399 Therefore, FNNAME is not used literally. Instead, the relocation
3400 information will indicate which symbol the section is for.
3402 We record any stubs that we find in the symbol table. */
3404 #define FN_STUB ".mips16.fn."
3405 #define CALL_STUB ".mips16.call."
3406 #define CALL_FP_STUB ".mips16.call.fp."
3408 /* The MIPS ELF linker needs additional information for each symbol in
3409 the global hash table. */
3411 struct mips_elf_link_hash_entry
3413 struct elf_link_hash_entry root
;
3415 /* External symbol information. */
3418 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
3419 unsigned int mips_32_relocs
;
3421 /* If there is a stub that 32 bit functions should use to call this
3422 16 bit function, this points to the section containing the stub. */
3425 /* Whether we need the fn_stub; this is set if this symbol appears
3426 in any relocs other than a 16 bit call. */
3427 boolean need_fn_stub
;
3429 /* If there is a stub that 16 bit functions should use to call this
3430 32 bit function, this points to the section containing the stub. */
3431 asection
*call_stub
;
3433 /* This is like the call_stub field, but it is used if the function
3434 being called returns a floating point value. */
3435 asection
*call_fp_stub
;
3438 /* MIPS ELF linker hash table. */
3440 struct mips_elf_link_hash_table
3442 struct elf_link_hash_table root
;
3443 /* String section indices for the dynamic section symbols. */
3444 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
3445 /* The number of .rtproc entries. */
3446 bfd_size_type procedure_count
;
3447 /* The size of the .compact_rel section (if SGI_COMPAT). */
3448 bfd_size_type compact_rel_size
;
3449 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3450 entry is set to the address of __rld_obj_head as in Irix 5. */
3451 boolean use_rld_obj_head
;
3452 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3454 /* This is set if we see any mips16 stub sections. */
3455 boolean mips16_stubs_seen
;
3458 /* Look up an entry in a MIPS ELF linker hash table. */
3460 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3461 ((struct mips_elf_link_hash_entry *) \
3462 elf_link_hash_lookup (&(table)->root, (string), (create), \
3465 /* Traverse a MIPS ELF linker hash table. */
3467 #define mips_elf_link_hash_traverse(table, func, info) \
3468 (elf_link_hash_traverse \
3470 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3473 /* Get the MIPS ELF linker hash table from a link_info structure. */
3475 #define mips_elf_hash_table(p) \
3476 ((struct mips_elf_link_hash_table *) ((p)->hash))
3478 static boolean mips_elf_output_extsym
3479 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3481 /* Create an entry in a MIPS ELF linker hash table. */
3483 static struct bfd_hash_entry
*
3484 mips_elf_link_hash_newfunc (entry
, table
, string
)
3485 struct bfd_hash_entry
*entry
;
3486 struct bfd_hash_table
*table
;
3489 struct mips_elf_link_hash_entry
*ret
=
3490 (struct mips_elf_link_hash_entry
*) entry
;
3492 /* Allocate the structure if it has not already been allocated by a
3494 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3495 ret
= ((struct mips_elf_link_hash_entry
*)
3496 bfd_hash_allocate (table
,
3497 sizeof (struct mips_elf_link_hash_entry
)));
3498 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3499 return (struct bfd_hash_entry
*) ret
;
3501 /* Call the allocation method of the superclass. */
3502 ret
= ((struct mips_elf_link_hash_entry
*)
3503 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3505 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3507 /* Set local fields. */
3508 memset (&ret
->esym
, 0, sizeof (EXTR
));
3509 /* We use -2 as a marker to indicate that the information has
3510 not been set. -1 means there is no associated ifd. */
3512 ret
->mips_32_relocs
= 0;
3513 ret
->fn_stub
= NULL
;
3514 ret
->need_fn_stub
= false;
3515 ret
->call_stub
= NULL
;
3516 ret
->call_fp_stub
= NULL
;
3519 return (struct bfd_hash_entry
*) ret
;
3522 /* Create a MIPS ELF linker hash table. */
3524 static struct bfd_link_hash_table
*
3525 mips_elf_link_hash_table_create (abfd
)
3528 struct mips_elf_link_hash_table
*ret
;
3531 ret
= ((struct mips_elf_link_hash_table
*)
3532 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
3533 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
3536 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3537 mips_elf_link_hash_newfunc
))
3539 bfd_release (abfd
, ret
);
3543 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
3544 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
3545 ret
->procedure_count
= 0;
3546 ret
->compact_rel_size
= 0;
3547 ret
->use_rld_obj_head
= false;
3549 ret
->mips16_stubs_seen
= false;
3551 return &ret
->root
.root
;
3554 /* Hook called by the linker routine which adds symbols from an object
3555 file. We must handle the special MIPS section numbers here. */
3559 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3561 struct bfd_link_info
*info
;
3562 const Elf_Internal_Sym
*sym
;
3568 if (SGI_COMPAT (abfd
)
3569 && (abfd
->flags
& DYNAMIC
) != 0
3570 && strcmp (*namep
, "_rld_new_interface") == 0)
3572 /* Skip Irix 5 rld entry name. */
3577 switch (sym
->st_shndx
)
3580 /* Common symbols less than the GP size are automatically
3581 treated as SHN_MIPS_SCOMMON symbols. */
3582 if (sym
->st_size
> elf_gp_size (abfd
))
3585 case SHN_MIPS_SCOMMON
:
3586 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3587 (*secp
)->flags
|= SEC_IS_COMMON
;
3588 *valp
= sym
->st_size
;
3592 /* This section is used in a shared object. */
3593 if (mips_elf_text_section_ptr
== NULL
)
3595 /* Initialize the section. */
3596 mips_elf_text_section
.name
= ".text";
3597 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
3598 mips_elf_text_section
.output_section
= NULL
;
3599 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
3600 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
3601 mips_elf_text_symbol
.name
= ".text";
3602 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
3603 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
3604 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
3605 mips_elf_text_section_ptr
= &mips_elf_text_section
;
3607 /* This code used to do *secp = bfd_und_section_ptr if
3608 info->shared. I don't know why, and that doesn't make sense,
3609 so I took it out. */
3610 *secp
= mips_elf_text_section_ptr
;
3613 case SHN_MIPS_ACOMMON
:
3614 /* Fall through. XXX Can we treat this as allocated data? */
3616 /* This section is used in a shared object. */
3617 if (mips_elf_data_section_ptr
== NULL
)
3619 /* Initialize the section. */
3620 mips_elf_data_section
.name
= ".data";
3621 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
3622 mips_elf_data_section
.output_section
= NULL
;
3623 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
3624 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
3625 mips_elf_data_symbol
.name
= ".data";
3626 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
3627 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
3628 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
3629 mips_elf_data_section_ptr
= &mips_elf_data_section
;
3631 /* This code used to do *secp = bfd_und_section_ptr if
3632 info->shared. I don't know why, and that doesn't make sense,
3633 so I took it out. */
3634 *secp
= mips_elf_data_section_ptr
;
3637 case SHN_MIPS_SUNDEFINED
:
3638 *secp
= bfd_und_section_ptr
;
3642 if (SGI_COMPAT (abfd
)
3644 && info
->hash
->creator
== abfd
->xvec
3645 && strcmp (*namep
, "__rld_obj_head") == 0)
3647 struct elf_link_hash_entry
*h
;
3649 /* Mark __rld_obj_head as dynamic. */
3651 if (! (_bfd_generic_link_add_one_symbol
3652 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3653 (bfd_vma
) *valp
, (const char *) NULL
, false,
3654 get_elf_backend_data (abfd
)->collect
,
3655 (struct bfd_link_hash_entry
**) &h
)))
3657 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
3658 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3659 h
->type
= STT_OBJECT
;
3661 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3664 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3667 /* If this is a mips16 text symbol, add 1 to the value to make it
3668 odd. This will cause something like .word SYM to come up with
3669 the right value when it is loaded into the PC. */
3670 if (sym
->st_other
== STO_MIPS16
)
3676 /* Structure used to pass information to mips_elf_output_extsym. */
3681 struct bfd_link_info
*info
;
3682 struct ecoff_debug_info
*debug
;
3683 const struct ecoff_debug_swap
*swap
;
3687 /* This routine is used to write out ECOFF debugging external symbol
3688 information. It is called via mips_elf_link_hash_traverse. The
3689 ECOFF external symbol information must match the ELF external
3690 symbol information. Unfortunately, at this point we don't know
3691 whether a symbol is required by reloc information, so the two
3692 tables may wind up being different. We must sort out the external
3693 symbol information before we can set the final size of the .mdebug
3694 section, and we must set the size of the .mdebug section before we
3695 can relocate any sections, and we can't know which symbols are
3696 required by relocation until we relocate the sections.
3697 Fortunately, it is relatively unlikely that any symbol will be
3698 stripped but required by a reloc. In particular, it can not happen
3699 when generating a final executable. */
3702 mips_elf_output_extsym (h
, data
)
3703 struct mips_elf_link_hash_entry
*h
;
3706 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
3708 asection
*sec
, *output_section
;
3710 if (h
->root
.indx
== -2)
3712 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3713 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
3714 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3715 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
3717 else if (einfo
->info
->strip
== strip_all
3718 || (einfo
->info
->strip
== strip_some
3719 && bfd_hash_lookup (einfo
->info
->keep_hash
,
3720 h
->root
.root
.root
.string
,
3721 false, false) == NULL
))
3729 if (h
->esym
.ifd
== -2)
3732 h
->esym
.cobol_main
= 0;
3733 h
->esym
.weakext
= 0;
3734 h
->esym
.reserved
= 0;
3735 h
->esym
.ifd
= ifdNil
;
3736 h
->esym
.asym
.value
= 0;
3737 h
->esym
.asym
.st
= stGlobal
;
3739 if (SGI_COMPAT (einfo
->abfd
)
3740 && (h
->root
.root
.type
== bfd_link_hash_undefined
3741 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
3745 /* Use undefined class. Also, set class and type for some
3747 name
= h
->root
.root
.root
.string
;
3748 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
3749 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
3751 h
->esym
.asym
.sc
= scData
;
3752 h
->esym
.asym
.st
= stLabel
;
3753 h
->esym
.asym
.value
= 0;
3755 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
3757 h
->esym
.asym
.sc
= scAbs
;
3758 h
->esym
.asym
.st
= stLabel
;
3759 h
->esym
.asym
.value
=
3760 mips_elf_hash_table (einfo
->info
)->procedure_count
;
3762 else if (strcmp (name
, "_gp_disp") == 0)
3764 h
->esym
.asym
.sc
= scAbs
;
3765 h
->esym
.asym
.st
= stLabel
;
3766 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
3769 h
->esym
.asym
.sc
= scUndefined
;
3771 else if (h
->root
.root
.type
!= bfd_link_hash_defined
3772 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
3773 h
->esym
.asym
.sc
= scAbs
;
3778 sec
= h
->root
.root
.u
.def
.section
;
3779 output_section
= sec
->output_section
;
3781 /* When making a shared library and symbol h is the one from
3782 the another shared library, OUTPUT_SECTION may be null. */
3783 if (output_section
== NULL
)
3784 h
->esym
.asym
.sc
= scUndefined
;
3787 name
= bfd_section_name (output_section
->owner
, output_section
);
3789 if (strcmp (name
, ".text") == 0)
3790 h
->esym
.asym
.sc
= scText
;
3791 else if (strcmp (name
, ".data") == 0)
3792 h
->esym
.asym
.sc
= scData
;
3793 else if (strcmp (name
, ".sdata") == 0)
3794 h
->esym
.asym
.sc
= scSData
;
3795 else if (strcmp (name
, ".rodata") == 0
3796 || strcmp (name
, ".rdata") == 0)
3797 h
->esym
.asym
.sc
= scRData
;
3798 else if (strcmp (name
, ".bss") == 0)
3799 h
->esym
.asym
.sc
= scBss
;
3800 else if (strcmp (name
, ".sbss") == 0)
3801 h
->esym
.asym
.sc
= scSBss
;
3802 else if (strcmp (name
, ".init") == 0)
3803 h
->esym
.asym
.sc
= scInit
;
3804 else if (strcmp (name
, ".fini") == 0)
3805 h
->esym
.asym
.sc
= scFini
;
3807 h
->esym
.asym
.sc
= scAbs
;
3811 h
->esym
.asym
.reserved
= 0;
3812 h
->esym
.asym
.index
= indexNil
;
3815 if (h
->root
.root
.type
== bfd_link_hash_common
)
3816 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
3817 else if (h
->root
.root
.type
== bfd_link_hash_defined
3818 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3820 if (h
->esym
.asym
.sc
== scCommon
)
3821 h
->esym
.asym
.sc
= scBss
;
3822 else if (h
->esym
.asym
.sc
== scSCommon
)
3823 h
->esym
.asym
.sc
= scSBss
;
3825 sec
= h
->root
.root
.u
.def
.section
;
3826 output_section
= sec
->output_section
;
3827 if (output_section
!= NULL
)
3828 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
3829 + sec
->output_offset
3830 + output_section
->vma
);
3832 h
->esym
.asym
.value
= 0;
3834 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3836 /* Set type and value for a symbol with a function stub. */
3837 h
->esym
.asym
.st
= stProc
;
3838 sec
= h
->root
.root
.u
.def
.section
;
3840 h
->esym
.asym
.value
= 0;
3843 output_section
= sec
->output_section
;
3844 if (output_section
!= NULL
)
3845 h
->esym
.asym
.value
= (h
->root
.plt
.offset
3846 + sec
->output_offset
3847 + output_section
->vma
);
3849 h
->esym
.asym
.value
= 0;
3856 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
3857 h
->root
.root
.root
.string
,
3860 einfo
->failed
= true;
3867 /* Create a runtime procedure table from the .mdebug section. */
3870 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
3873 struct bfd_link_info
*info
;
3875 struct ecoff_debug_info
*debug
;
3877 const struct ecoff_debug_swap
*swap
;
3878 HDRR
*hdr
= &debug
->symbolic_header
;
3880 struct rpdr_ext
*erp
;
3882 struct pdr_ext
*epdr
;
3883 struct sym_ext
*esym
;
3886 unsigned long size
, count
;
3887 unsigned long sindex
;
3891 const char *no_name_func
= _("static procedure (no name)");
3899 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3901 sindex
= strlen (no_name_func
) + 1;
3902 count
= hdr
->ipdMax
;
3905 size
= swap
->external_pdr_size
;
3907 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
3911 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
3914 size
= sizeof (RPDR
);
3915 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
3919 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
3923 count
= hdr
->isymMax
;
3924 size
= swap
->external_sym_size
;
3925 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
3929 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
3932 count
= hdr
->issMax
;
3933 ss
= (char *) bfd_malloc (count
);
3936 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
3939 count
= hdr
->ipdMax
;
3940 for (i
= 0; i
< count
; i
++, rp
++)
3942 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
3943 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
3944 rp
->adr
= sym
.value
;
3945 rp
->regmask
= pdr
.regmask
;
3946 rp
->regoffset
= pdr
.regoffset
;
3947 rp
->fregmask
= pdr
.fregmask
;
3948 rp
->fregoffset
= pdr
.fregoffset
;
3949 rp
->frameoffset
= pdr
.frameoffset
;
3950 rp
->framereg
= pdr
.framereg
;
3951 rp
->pcreg
= pdr
.pcreg
;
3953 sv
[i
] = ss
+ sym
.iss
;
3954 sindex
+= strlen (sv
[i
]) + 1;
3958 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
3959 size
= BFD_ALIGN (size
, 16);
3960 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
3963 mips_elf_hash_table (info
)->procedure_count
= 0;
3967 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
3969 erp
= (struct rpdr_ext
*) rtproc
;
3970 memset (erp
, 0, sizeof (struct rpdr_ext
));
3972 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
3973 strcpy (str
, no_name_func
);
3974 str
+= strlen (no_name_func
) + 1;
3975 for (i
= 0; i
< count
; i
++)
3977 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
3978 strcpy (str
, sv
[i
]);
3979 str
+= strlen (sv
[i
]) + 1;
3981 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
3983 /* Set the size and contents of .rtproc section. */
3984 s
->_raw_size
= size
;
3985 s
->contents
= (bfd_byte
*) rtproc
;
3987 /* Skip this section later on (I don't think this currently
3988 matters, but someday it might). */
3989 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
4018 /* A comparison routine used to sort .gptab entries. */
4021 gptab_compare (p1
, p2
)
4025 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
4026 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
4028 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
4031 /* We need to use a special link routine to handle the .reginfo and
4032 the .mdebug sections. We need to merge all instances of these
4033 sections together, not write them all out sequentially. */
4036 mips_elf_final_link (abfd
, info
)
4038 struct bfd_link_info
*info
;
4042 struct bfd_link_order
*p
;
4043 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
4044 asection
*rtproc_sec
;
4045 Elf32_RegInfo reginfo
;
4046 struct ecoff_debug_info debug
;
4047 const struct ecoff_debug_swap
*swap
4048 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4049 HDRR
*symhdr
= &debug
.symbolic_header
;
4050 PTR mdebug_handle
= NULL
;
4052 /* Drop the .options section, since it has special semantics which I
4053 haven't bothered to figure out. */
4054 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
4056 if (strcmp ((*secpp
)->name
, ".options") == 0)
4058 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
4059 if (p
->type
== bfd_indirect_link_order
)
4060 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
4061 (*secpp
)->link_order_head
= NULL
;
4062 *secpp
= (*secpp
)->next
;
4063 --abfd
->section_count
;
4068 /* Get a value for the GP register. */
4069 if (elf_gp (abfd
) == 0)
4071 struct bfd_link_hash_entry
*h
;
4073 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4074 if (h
!= (struct bfd_link_hash_entry
*) NULL
4075 && h
->type
== bfd_link_hash_defined
)
4076 elf_gp (abfd
) = (h
->u
.def
.value
4077 + h
->u
.def
.section
->output_section
->vma
4078 + h
->u
.def
.section
->output_offset
);
4079 else if (info
->relocateable
)
4083 /* Make up a value. */
4085 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4088 && (strcmp (o
->name
, ".sbss") == 0
4089 || strcmp (o
->name
, ".sdata") == 0
4090 || strcmp (o
->name
, ".lit4") == 0
4091 || strcmp (o
->name
, ".lit8") == 0))
4094 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
4098 /* If the relocate_section function needs to do a reloc
4099 involving the GP value, it should make a reloc_dangerous
4100 callback to warn that GP is not defined. */
4104 /* Go through the sections and collect the .reginfo and .mdebug
4108 gptab_data_sec
= NULL
;
4109 gptab_bss_sec
= NULL
;
4110 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4112 if (strcmp (o
->name
, ".reginfo") == 0)
4114 memset (®info
, 0, sizeof reginfo
);
4116 /* We have found the .reginfo section in the output file.
4117 Look through all the link_orders comprising it and merge
4118 the information together. */
4119 for (p
= o
->link_order_head
;
4120 p
!= (struct bfd_link_order
*) NULL
;
4123 asection
*input_section
;
4125 Elf32_External_RegInfo ext
;
4128 if (p
->type
!= bfd_indirect_link_order
)
4130 if (p
->type
== bfd_fill_link_order
)
4135 input_section
= p
->u
.indirect
.section
;
4136 input_bfd
= input_section
->owner
;
4138 /* The linker emulation code has probably clobbered the
4139 size to be zero bytes. */
4140 if (input_section
->_raw_size
== 0)
4141 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4143 if (! bfd_get_section_contents (input_bfd
, input_section
,
4149 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
4151 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
4152 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
4153 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
4154 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
4155 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
4157 /* ri_gp_value is set by the function
4158 mips_elf32_section_processing when the section is
4159 finally written out. */
4161 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4162 elf_link_input_bfd ignores this section. */
4163 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4166 /* Force the section size to the value we want. */
4167 o
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4169 /* Skip this section later on (I don't think this currently
4170 matters, but someday it might). */
4171 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4176 if (strcmp (o
->name
, ".mdebug") == 0)
4178 struct extsym_info einfo
;
4180 /* We have found the .mdebug section in the output file.
4181 Look through all the link_orders comprising it and merge
4182 the information together. */
4183 symhdr
->magic
= swap
->sym_magic
;
4184 /* FIXME: What should the version stamp be? */
4186 symhdr
->ilineMax
= 0;
4190 symhdr
->isymMax
= 0;
4191 symhdr
->ioptMax
= 0;
4192 symhdr
->iauxMax
= 0;
4194 symhdr
->issExtMax
= 0;
4197 symhdr
->iextMax
= 0;
4199 /* We accumulate the debugging information itself in the
4200 debug_info structure. */
4202 debug
.external_dnr
= NULL
;
4203 debug
.external_pdr
= NULL
;
4204 debug
.external_sym
= NULL
;
4205 debug
.external_opt
= NULL
;
4206 debug
.external_aux
= NULL
;
4208 debug
.ssext
= debug
.ssext_end
= NULL
;
4209 debug
.external_fdr
= NULL
;
4210 debug
.external_rfd
= NULL
;
4211 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4213 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4214 if (mdebug_handle
== (PTR
) NULL
)
4217 if (SGI_COMPAT (abfd
))
4223 static const char * const name
[] =
4224 { ".text", ".init", ".fini", ".data",
4225 ".rodata", ".sdata", ".sbss", ".bss" };
4226 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
4227 scRData
, scSData
, scSBss
, scBss
};
4230 esym
.cobol_main
= 0;
4234 esym
.asym
.iss
= issNil
;
4235 esym
.asym
.st
= stLocal
;
4236 esym
.asym
.reserved
= 0;
4237 esym
.asym
.index
= indexNil
;
4239 for (i
= 0; i
< 8; i
++)
4241 esym
.asym
.sc
= sc
[i
];
4242 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4245 esym
.asym
.value
= s
->vma
;
4246 last
= s
->vma
+ s
->_raw_size
;
4249 esym
.asym
.value
= last
;
4251 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4257 for (p
= o
->link_order_head
;
4258 p
!= (struct bfd_link_order
*) NULL
;
4261 asection
*input_section
;
4263 const struct ecoff_debug_swap
*input_swap
;
4264 struct ecoff_debug_info input_debug
;
4268 if (p
->type
!= bfd_indirect_link_order
)
4270 if (p
->type
== bfd_fill_link_order
)
4275 input_section
= p
->u
.indirect
.section
;
4276 input_bfd
= input_section
->owner
;
4278 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4279 || (get_elf_backend_data (input_bfd
)
4280 ->elf_backend_ecoff_debug_swap
) == NULL
)
4282 /* I don't know what a non MIPS ELF bfd would be
4283 doing with a .mdebug section, but I don't really
4284 want to deal with it. */
4288 input_swap
= (get_elf_backend_data (input_bfd
)
4289 ->elf_backend_ecoff_debug_swap
);
4291 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
4293 /* The ECOFF linking code expects that we have already
4294 read in the debugging information and set up an
4295 ecoff_debug_info structure, so we do that now. */
4296 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
4300 if (! (bfd_ecoff_debug_accumulate
4301 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
4302 &input_debug
, input_swap
, info
)))
4305 /* Loop through the external symbols. For each one with
4306 interesting information, try to find the symbol in
4307 the linker global hash table and save the information
4308 for the output external symbols. */
4309 eraw_src
= input_debug
.external_ext
;
4310 eraw_end
= (eraw_src
4311 + (input_debug
.symbolic_header
.iextMax
4312 * input_swap
->external_ext_size
));
4314 eraw_src
< eraw_end
;
4315 eraw_src
+= input_swap
->external_ext_size
)
4319 struct mips_elf_link_hash_entry
*h
;
4321 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4322 if (ext
.asym
.sc
== scNil
4323 || ext
.asym
.sc
== scUndefined
4324 || ext
.asym
.sc
== scSUndefined
)
4327 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4328 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
4329 name
, false, false, true);
4330 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4336 < input_debug
.symbolic_header
.ifdMax
);
4337 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4343 /* Free up the information we just read. */
4344 free (input_debug
.line
);
4345 free (input_debug
.external_dnr
);
4346 free (input_debug
.external_pdr
);
4347 free (input_debug
.external_sym
);
4348 free (input_debug
.external_opt
);
4349 free (input_debug
.external_aux
);
4350 free (input_debug
.ss
);
4351 free (input_debug
.ssext
);
4352 free (input_debug
.external_fdr
);
4353 free (input_debug
.external_rfd
);
4354 free (input_debug
.external_ext
);
4356 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4357 elf_link_input_bfd ignores this section. */
4358 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4361 if (SGI_COMPAT (abfd
) && info
->shared
)
4363 /* Create .rtproc section. */
4364 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4365 if (rtproc_sec
== NULL
)
4367 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4368 | SEC_LINKER_CREATED
| SEC_READONLY
);
4370 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4371 if (rtproc_sec
== NULL
4372 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4373 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
4377 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
4378 info
, rtproc_sec
, &debug
))
4382 /* Build the external symbol information. */
4385 einfo
.debug
= &debug
;
4387 einfo
.failed
= false;
4388 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4389 mips_elf_output_extsym
,
4394 /* Set the size of the .mdebug section. */
4395 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4397 /* Skip this section later on (I don't think this currently
4398 matters, but someday it might). */
4399 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4404 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4406 const char *subname
;
4409 Elf32_External_gptab
*ext_tab
;
4412 /* The .gptab.sdata and .gptab.sbss sections hold
4413 information describing how the small data area would
4414 change depending upon the -G switch. These sections
4415 not used in executables files. */
4416 if (! info
->relocateable
)
4420 for (p
= o
->link_order_head
;
4421 p
!= (struct bfd_link_order
*) NULL
;
4424 asection
*input_section
;
4426 if (p
->type
!= bfd_indirect_link_order
)
4428 if (p
->type
== bfd_fill_link_order
)
4433 input_section
= p
->u
.indirect
.section
;
4435 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4436 elf_link_input_bfd ignores this section. */
4437 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4440 /* Skip this section later on (I don't think this
4441 currently matters, but someday it might). */
4442 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4444 /* Really remove the section. */
4445 for (secpp
= &abfd
->sections
;
4447 secpp
= &(*secpp
)->next
)
4449 *secpp
= (*secpp
)->next
;
4450 --abfd
->section_count
;
4455 /* There is one gptab for initialized data, and one for
4456 uninitialized data. */
4457 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4459 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4463 (*_bfd_error_handler
)
4464 (_("%s: illegal section name `%s'"),
4465 bfd_get_filename (abfd
), o
->name
);
4466 bfd_set_error (bfd_error_nonrepresentable_section
);
4470 /* The linker script always combines .gptab.data and
4471 .gptab.sdata into .gptab.sdata, and likewise for
4472 .gptab.bss and .gptab.sbss. It is possible that there is
4473 no .sdata or .sbss section in the output file, in which
4474 case we must change the name of the output section. */
4475 subname
= o
->name
+ sizeof ".gptab" - 1;
4476 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4478 if (o
== gptab_data_sec
)
4479 o
->name
= ".gptab.data";
4481 o
->name
= ".gptab.bss";
4482 subname
= o
->name
+ sizeof ".gptab" - 1;
4483 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4486 /* Set up the first entry. */
4488 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
4491 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4492 tab
[0].gt_header
.gt_unused
= 0;
4494 /* Combine the input sections. */
4495 for (p
= o
->link_order_head
;
4496 p
!= (struct bfd_link_order
*) NULL
;
4499 asection
*input_section
;
4503 bfd_size_type gpentry
;
4505 if (p
->type
!= bfd_indirect_link_order
)
4507 if (p
->type
== bfd_fill_link_order
)
4512 input_section
= p
->u
.indirect
.section
;
4513 input_bfd
= input_section
->owner
;
4515 /* Combine the gptab entries for this input section one
4516 by one. We know that the input gptab entries are
4517 sorted by ascending -G value. */
4518 size
= bfd_section_size (input_bfd
, input_section
);
4520 for (gpentry
= sizeof (Elf32_External_gptab
);
4522 gpentry
+= sizeof (Elf32_External_gptab
))
4524 Elf32_External_gptab ext_gptab
;
4525 Elf32_gptab int_gptab
;
4531 if (! (bfd_get_section_contents
4532 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4533 gpentry
, sizeof (Elf32_External_gptab
))))
4539 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
4541 val
= int_gptab
.gt_entry
.gt_g_value
;
4542 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4545 for (look
= 1; look
< c
; look
++)
4547 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4548 tab
[look
].gt_entry
.gt_bytes
+= add
;
4550 if (tab
[look
].gt_entry
.gt_g_value
== val
)
4556 Elf32_gptab
*new_tab
;
4559 /* We need a new table entry. */
4560 new_tab
= ((Elf32_gptab
*)
4561 bfd_realloc ((PTR
) tab
,
4562 (c
+ 1) * sizeof (Elf32_gptab
)));
4563 if (new_tab
== NULL
)
4569 tab
[c
].gt_entry
.gt_g_value
= val
;
4570 tab
[c
].gt_entry
.gt_bytes
= add
;
4572 /* Merge in the size for the next smallest -G
4573 value, since that will be implied by this new
4576 for (look
= 1; look
< c
; look
++)
4578 if (tab
[look
].gt_entry
.gt_g_value
< val
4580 || (tab
[look
].gt_entry
.gt_g_value
4581 > tab
[max
].gt_entry
.gt_g_value
)))
4585 tab
[c
].gt_entry
.gt_bytes
+=
4586 tab
[max
].gt_entry
.gt_bytes
;
4591 last
= int_gptab
.gt_entry
.gt_bytes
;
4594 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4595 elf_link_input_bfd ignores this section. */
4596 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4599 /* The table must be sorted by -G value. */
4601 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
4603 /* Swap out the table. */
4604 ext_tab
= ((Elf32_External_gptab
*)
4605 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
4606 if (ext_tab
== NULL
)
4612 for (i
= 0; i
< c
; i
++)
4613 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
4616 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
4617 o
->contents
= (bfd_byte
*) ext_tab
;
4619 /* Skip this section later on (I don't think this currently
4620 matters, but someday it might). */
4621 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4625 /* Invoke the regular ELF backend linker to do all the work. */
4626 if (! bfd_elf32_bfd_final_link (abfd
, info
))
4629 /* Now write out the computed sections. */
4631 if (reginfo_sec
!= (asection
*) NULL
)
4633 Elf32_External_RegInfo ext
;
4635 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
4636 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4637 (file_ptr
) 0, sizeof ext
))
4641 if (mdebug_sec
!= (asection
*) NULL
)
4643 BFD_ASSERT (abfd
->output_has_begun
);
4644 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4646 mdebug_sec
->filepos
))
4649 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4652 if (gptab_data_sec
!= (asection
*) NULL
)
4654 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4655 gptab_data_sec
->contents
,
4657 gptab_data_sec
->_raw_size
))
4661 if (gptab_bss_sec
!= (asection
*) NULL
)
4663 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4664 gptab_bss_sec
->contents
,
4666 gptab_bss_sec
->_raw_size
))
4670 if (SGI_COMPAT (abfd
))
4672 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4673 if (rtproc_sec
!= NULL
)
4675 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
4676 rtproc_sec
->contents
,
4678 rtproc_sec
->_raw_size
))
4686 /* Handle a MIPS ELF HI16 reloc. */
4689 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
4691 Elf_Internal_Rela
*relhi
;
4692 Elf_Internal_Rela
*rello
;
4699 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4701 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4704 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4706 if ((addlo
& 0x8000) != 0)
4708 if ((addend
& 0x8000) != 0)
4711 bfd_put_32 (input_bfd
,
4712 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
4713 contents
+ relhi
->r_offset
);
4716 /* Handle a MIPS ELF local GOT16 reloc. */
4719 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
4724 Elf_Internal_Rela
*relhi
;
4725 Elf_Internal_Rela
*rello
;
4729 unsigned int assigned_gotno
;
4735 bfd_byte
*got_contents
;
4736 struct mips_got_info
*g
;
4738 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4740 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4743 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4745 if ((addlo
& 0x8000) != 0)
4747 if ((addend
& 0x8000) != 0)
4750 /* Get a got entry representing requested hipage. */
4751 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4752 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4753 BFD_ASSERT (g
!= NULL
);
4755 assigned_gotno
= g
->assigned_gotno
;
4756 got_contents
= sgot
->contents
;
4757 hipage
= addend
& 0xffff0000;
4759 for (i
= MIPS_RESERVED_GOTNO
; i
< assigned_gotno
; i
++)
4761 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
4762 if (hipage
== (address
& 0xffff0000))
4766 if (i
== assigned_gotno
)
4768 if (assigned_gotno
>= g
->local_gotno
)
4770 (*_bfd_error_handler
)
4771 (_("more got entries are needed for hipage relocations"));
4772 bfd_set_error (bfd_error_bad_value
);
4776 bfd_put_32 (input_bfd
, hipage
, got_contents
+ assigned_gotno
* 4);
4777 ++g
->assigned_gotno
;
4780 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
4781 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
4782 contents
+ relhi
->r_offset
);
4787 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
4790 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
4792 Elf_Internal_Rela
*rel
;
4798 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4799 bfd_put_32 (input_bfd
,
4800 (insn
& 0xffff0000) | (offset
& 0xffff),
4801 contents
+ rel
->r_offset
);
4804 /* Relocate a MIPS ELF section. */
4807 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4808 contents
, relocs
, local_syms
, local_sections
)
4810 struct bfd_link_info
*info
;
4812 asection
*input_section
;
4814 Elf_Internal_Rela
*relocs
;
4815 Elf_Internal_Sym
*local_syms
;
4816 asection
**local_sections
;
4818 Elf_Internal_Shdr
*symtab_hdr
;
4821 asection
*sgot
, *sreloc
, *scpt
;
4824 Elf_Internal_Rela
*rel
;
4825 Elf_Internal_Rela
*relend
;
4826 struct mips_got_info
*g
;
4828 dynobj
= elf_hash_table (info
)->dynobj
;
4829 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4833 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
4836 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
4839 if (elf_bad_symtab (input_bfd
))
4841 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
4846 locsymcount
= symtab_hdr
->sh_info
;
4847 extsymoff
= symtab_hdr
->sh_info
;
4850 gp
= _bfd_get_gp_value (output_bfd
);
4853 relend
= relocs
+ input_section
->reloc_count
;
4854 for (; rel
< relend
; rel
++)
4857 reloc_howto_type
*howto
;
4858 unsigned long r_symndx
;
4860 struct elf_link_hash_entry
*h
;
4862 Elf_Internal_Sym
*sym
;
4863 struct mips_elf_link_hash_entry
*mh
;
4865 bfd_reloc_status_type r
;
4867 r_type
= ELF32_R_TYPE (rel
->r_info
);
4868 if (r_type
== R_MIPS_GNU_VTINHERIT
4869 || r_type
== R_MIPS_GNU_VTENTRY
)
4871 if ((r_type
< 0 || r_type
>= (int) R_MIPS_max
)
4872 /* start-sanitize-sky */
4873 && r_type
!= R_MIPS_DVP_11_PCREL
4874 && r_type
!= R_MIPS_DVP_27_S4
4875 /* end-sanitize-sky */
4876 && r_type
!= R_MIPS16_26
4877 && r_type
!= R_MIPS16_GPREL
)
4879 bfd_set_error (bfd_error_bad_value
);
4882 if (r_type
== R_MIPS16_26
)
4883 howto
= &elf_mips16_jump_howto
;
4884 else if (r_type
== R_MIPS16_GPREL
)
4885 howto
= &elf_mips16_gprel_howto
;
4886 /* start-sanitize-sky */
4887 else if (r_type
== R_MIPS_DVP_11_PCREL
)
4888 howto
= &elf_mips_dvp_11_pcrel_howto
;
4889 else if (r_type
== R_MIPS_DVP_27_S4
)
4890 howto
= &elf_mips_dvp_27_s4_howto
;
4891 /* end-sanitize-sky */
4893 howto
= elf_mips_howto_table
+ r_type
;
4896 && (r_type
== R_MIPS_CALL16
4897 || r_type
== R_MIPS_GOT16
4898 || r_type
== R_MIPS_CALL_HI16
4899 || r_type
== R_MIPS_CALL_LO16
4900 || r_type
== R_MIPS_GOT_HI16
4901 || r_type
== R_MIPS_GOT_LO16
))
4903 /* We need the .got section. */
4906 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4907 BFD_ASSERT (sgot
!= NULL
);
4908 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4909 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4910 BFD_ASSERT (g
!= NULL
);
4914 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4916 /* Mix in the change in GP address for a GP relative reloc. */
4917 if (r_type
!= R_MIPS_GPREL16
4918 && r_type
!= R_MIPS_LITERAL
4919 && r_type
!= R_MIPS_GPREL32
4920 && r_type
!= R_MIPS16_GPREL
)
4926 if (! ((*info
->callbacks
->reloc_dangerous
)
4928 _("GP relative relocation when GP not defined"),
4929 input_bfd
, input_section
,
4932 /* Only give the error once per link. */
4934 _bfd_set_gp_value (output_bfd
, gp
);
4937 if (r_symndx
< extsymoff
4938 || (elf_bad_symtab (input_bfd
)
4939 && local_sections
[r_symndx
] != NULL
))
4941 /* This is a relocation against a section. The current
4942 addend in the instruction is the difference between
4943 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
4944 must change this to be the difference between the
4945 final definition (which will end up in RELOCATION)
4946 and the GP value of OUTPUT_BFD (which is in GP). */
4947 addend
= elf_gp (input_bfd
) - gp
;
4949 else if (! info
->relocateable
)
4951 /* We are doing a final link. The current addend in the
4952 instruction is simply the desired offset into the
4953 symbol (normally zero). We want the instruction to
4954 hold the difference between the final definition of
4955 the symbol (which will end up in RELOCATION) and the
4956 GP value of OUTPUT_BFD (which is in GP). */
4961 /* We are generating relocateable output, and we aren't
4962 going to define this symbol, so we just leave the
4963 instruction alone. */
4971 if (info
->relocateable
)
4973 /* This is a relocateable link. We don't have to change
4974 anything, unless the reloc is against a section symbol,
4975 in which case we have to adjust according to where the
4976 section symbol winds up in the output section. */
4977 if (r_symndx
>= locsymcount
4978 || (elf_bad_symtab (input_bfd
)
4979 && local_sections
[r_symndx
] == NULL
))
4983 sym
= local_syms
+ r_symndx
;
4984 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4988 sec
= local_sections
[r_symndx
];
4990 /* It would be logical to add sym->st_value here,
4991 but Irix 5 sometimes generates a garbage symbol
4993 addend
+= sec
->output_offset
;
4995 /* If this is HI16 or GOT16 with an associated LO16,
4996 adjust the addend accordingly. Otherwise, just
4998 if (r_type
== R_MIPS_64
&& bfd_big_endian (input_bfd
))
4999 r
= _bfd_relocate_contents (howto
, input_bfd
,
5001 contents
+ rel
->r_offset
+ 4);
5002 else if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
5003 r
= _bfd_relocate_contents (howto
, input_bfd
,
5005 contents
+ rel
->r_offset
);
5008 Elf_Internal_Rela
*lorel
;
5010 /* As a GNU extension, permit an arbitrary
5011 number of R_MIPS_HI16 relocs before the
5012 R_MIPS_LO16 reloc. This permits gcc to emit
5013 the HI and LO relocs itself. */
5014 if (r_type
== R_MIPS_GOT16
)
5018 for (lorel
= rel
+ 1;
5020 && (ELF32_R_TYPE (lorel
->r_info
)
5026 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5028 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5033 r
= _bfd_relocate_contents (howto
, input_bfd
,
5035 contents
+ rel
->r_offset
);
5044 boolean undefined_error
;
5046 /* This is a final link. */
5047 undefined_error
= false;
5049 if (r_symndx
< extsymoff
5050 || (elf_bad_symtab (input_bfd
)
5051 && local_sections
[r_symndx
] != NULL
))
5054 sym
= local_syms
+ r_symndx
;
5055 sec
= local_sections
[r_symndx
];
5056 relocation
= (sec
->output_section
->vma
5057 + sec
->output_offset
);
5059 /* It would be logical to always add sym->st_value here,
5060 but Irix 5 sometimes generates a garbage symbol
5062 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5063 relocation
+= sym
->st_value
;
5065 /* mips16 text labels should be treated as odd. */
5066 if (sym
->st_other
== STO_MIPS16
)
5074 indx
= r_symndx
- extsymoff
;
5075 h
= elf_sym_hashes (input_bfd
)[indx
];
5076 while (h
->root
.type
== bfd_link_hash_indirect
5077 || h
->root
.type
== bfd_link_hash_warning
)
5078 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5079 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
5083 if (! ((*info
->callbacks
->reloc_dangerous
)
5085 _("_gp_disp used when GP not defined"),
5086 input_bfd
, input_section
,
5089 /* Only give the error once per link. */
5091 _bfd_set_gp_value (output_bfd
, gp
);
5096 sec
= input_section
;
5097 if (sec
->output_section
!= NULL
)
5100 + sec
->output_section
->vma
5101 + sec
->output_offset
));
5103 relocation
= gp
- rel
->r_offset
;
5104 if (r_type
== R_MIPS_LO16
)
5108 else if (h
->root
.type
== bfd_link_hash_defined
5109 || h
->root
.type
== bfd_link_hash_defweak
)
5111 sec
= h
->root
.u
.def
.section
;
5112 if (sec
->output_section
== NULL
)
5115 relocation
= (h
->root
.u
.def
.value
5116 + sec
->output_section
->vma
5117 + sec
->output_offset
);
5119 else if (h
->root
.type
== bfd_link_hash_undefweak
)
5121 else if (info
->shared
&& ! info
->symbolic
)
5123 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
5125 /* If this is a dynamic link, we should have created
5126 a _DYNAMIC_LINK symbol in
5127 mips_elf_create_dynamic_sections. Otherwise, we
5128 should define the symbol with a value of 0.
5129 FIXME: It should probably get into the symbol
5130 table somehow as well. */
5131 BFD_ASSERT (! info
->shared
);
5132 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
5133 ".dynamic") == NULL
);
5138 if (! ((*info
->callbacks
->undefined_symbol
)
5139 (info
, h
->root
.root
.string
, input_bfd
,
5140 input_section
, rel
->r_offset
)))
5142 undefined_error
= true;
5147 mh
= (struct mips_elf_link_hash_entry
*) h
;
5150 else if (sym
!= NULL
)
5151 other
= sym
->st_other
;
5155 /* If this function has an fn_stub, then it is a mips16
5156 function which needs a stub if it is called by a 32 bit
5157 function. If this reloc is anything other than a 16 bit
5158 call, redirect the reloc to the stub. We don't redirect
5159 relocs from other stub functions. */
5160 if (r_type
!= R_MIPS16_26
5162 && mh
->fn_stub
!= NULL
)
5164 && elf_tdata (input_bfd
)->local_stubs
!= NULL
5165 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
5166 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5167 FN_STUB
, sizeof FN_STUB
- 1) != 0
5168 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5169 CALL_STUB
, sizeof CALL_STUB
- 1) != 0
5170 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5171 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) != 0)
5175 BFD_ASSERT (mh
->need_fn_stub
);
5176 relocation
= (mh
->fn_stub
->output_section
->vma
5177 + mh
->fn_stub
->output_offset
);
5183 fn_stub
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
5184 relocation
= (fn_stub
->output_section
->vma
5185 + fn_stub
->output_offset
);
5188 /* RELOCATION now points to 32 bit code. */
5192 /* If this function has a call_stub, then it is called by a
5193 mips16 function; the call needs to go through a stub if
5194 this function is a 32 bit function. If this reloc is a
5195 16 bit call, and the symbol is not a 16 bit function,
5196 then redirect the reloc to the stub. Note that we don't
5197 need to worry about calling the function through a
5198 function pointer; such calls are handled by routing
5199 through a special mips16 routine. We don't have to check
5200 whether this call is from a stub; it can't be, because a
5201 stub contains 32 bit code, and hence can not have a 16
5203 if (r_type
== R_MIPS16_26
5205 && (mh
->call_stub
!= NULL
|| mh
->call_fp_stub
!= NULL
)
5206 && other
!= STO_MIPS16
)
5210 /* If both call_stub and call_fp_stub are defined, we
5211 can figure out which one to use by seeing which one
5212 appears in the input file. */
5213 if (mh
->call_stub
!= NULL
&& mh
->call_fp_stub
!= NULL
)
5218 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
5220 if (strncmp (bfd_get_section_name (input_bfd
, o
),
5221 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5223 stub
= mh
->call_fp_stub
;
5228 stub
= mh
->call_stub
;
5230 else if (mh
->call_stub
!= NULL
)
5231 stub
= mh
->call_stub
;
5233 stub
= mh
->call_fp_stub
;
5235 BFD_ASSERT (stub
->_raw_size
> 0);
5236 relocation
= stub
->output_section
->vma
+ stub
->output_offset
;
5239 if (r_type
== R_MIPS_HI16
)
5241 Elf_Internal_Rela
*lorel
;
5243 /* As a GNU extension, permit an arbitrary number of
5244 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
5245 This permits gcc to emit the HI and LO relocs itself. */
5246 for (lorel
= rel
+ 1;
5248 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
5252 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5254 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5255 contents
, relocation
+ addend
);
5259 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5260 contents
, rel
->r_offset
,
5261 relocation
, addend
);
5263 else if (r_type
== R_MIPS_GOT16
&& local
)
5265 /* GOT16 must also have an associated LO16 in the local
5266 case. In this case, the addend is extracted and the
5267 section in which the referenced object is determined.
5268 Then the final address of the object is computed and
5269 the GOT entry for the hipage (an aligned 64kb chunk)
5270 is added to .got section if needed. The offset field
5271 of the GOT16-relocated instruction is replaced by the
5272 index of this GOT entry for the hipage. */
5273 if ((rel
+ 1) < relend
5274 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
5276 if (! mips_elf_relocate_got_local (output_bfd
, input_bfd
,
5279 relocation
+ addend
))
5284 r
= bfd_reloc_outofrange
;
5286 else if (r_type
== R_MIPS_CALL16
5287 || r_type
== R_MIPS_GOT16
5288 || r_type
== R_MIPS_CALL_LO16
5289 || r_type
== R_MIPS_GOT_LO16
)
5293 /* This symbol must be registered as a global symbol
5294 having the corresponding got entry. */
5295 BFD_ASSERT (h
->got
.offset
!= (bfd_vma
) -1);
5297 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5298 BFD_ASSERT (g
->local_gotno
<= offset
5299 && offset
< sgot
->_raw_size
);
5300 bfd_put_32 (output_bfd
, relocation
+ addend
,
5301 sgot
->contents
+ offset
);
5302 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5304 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
5308 else if (r_type
== R_MIPS_CALL_HI16
5309 || r_type
== R_MIPS_GOT_HI16
)
5313 /* This must be a global symbol with a got entry. The
5314 next reloc must be the corresponding LO16 reloc. */
5315 BFD_ASSERT (h
!= NULL
&& h
->got
.offset
!= (bfd_vma
) -1);
5316 BFD_ASSERT ((rel
+ 1) < relend
);
5317 BFD_ASSERT ((int) ELF32_R_TYPE ((rel
+ 1)->r_info
)
5318 == (r_type
== R_MIPS_CALL_HI16
5319 ? (int) R_MIPS_CALL_LO16
5320 : (int) R_MIPS_GOT_LO16
));
5322 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5323 BFD_ASSERT (g
->local_gotno
<= offset
5324 && offset
< sgot
->_raw_size
);
5325 bfd_put_32 (output_bfd
, relocation
+ addend
,
5326 sgot
->contents
+ offset
);
5327 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5329 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
5333 else if (r_type
== R_MIPS_REL32
5334 || r_type
== R_MIPS_32
)
5336 Elf_Internal_Rel outrel
;
5337 Elf32_crinfo cptrel
;
5341 || (elf_hash_table (info
)->dynamic_sections_created
5343 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
5345 && (input_section
->flags
& SEC_ALLOC
) != 0)
5349 /* When generating a shared object, these
5350 relocations are copied into the output file to be
5351 resolved at run time. */
5354 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5355 BFD_ASSERT (sreloc
!= NULL
);
5360 if (elf_section_data (input_section
)->stab_info
== NULL
)
5361 outrel
.r_offset
= rel
->r_offset
;
5366 off
= (_bfd_stab_section_offset
5367 (output_bfd
, &elf_hash_table (info
)->stab_info
,
5369 &elf_section_data (input_section
)->stab_info
,
5371 if (off
== (bfd_vma
) -1)
5373 outrel
.r_offset
= off
;
5376 outrel
.r_offset
+= (input_section
->output_section
->vma
5377 + input_section
->output_offset
);
5379 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5382 memset (&outrel
, 0, sizeof outrel
);
5384 && (! info
->symbolic
5385 || (h
->elf_link_hash_flags
5386 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5388 BFD_ASSERT (h
->dynindx
!= -1);
5389 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
5390 sec
= input_section
;
5397 sec
= local_sections
[r_symndx
];
5400 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
5402 == bfd_link_hash_defweak
));
5403 sec
= h
->root
.u
.def
.section
;
5405 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5407 else if (sec
== NULL
|| sec
->owner
== NULL
)
5409 bfd_set_error (bfd_error_bad_value
);
5416 osec
= sec
->output_section
;
5417 indx
= elf_section_data (osec
)->dynindx
;
5422 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
5423 addend
+= relocation
;
5427 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
5429 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
5430 (((Elf32_External_Rel
*)
5432 + sreloc
->reloc_count
));
5433 ++sreloc
->reloc_count
;
5435 if (! skip
&& SGI_COMPAT (output_bfd
))
5440 /* Make an entry of compact relocation info. */
5441 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5442 cptrel
.vaddr
= (rel
->r_offset
5443 + input_section
->output_section
->vma
5444 + input_section
->output_offset
);
5445 if (r_type
== R_MIPS_REL32
)
5446 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5448 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5449 mips_elf_set_cr_dist2to (cptrel
, 0);
5450 cptrel
.konst
= addend
;
5452 cr
= (scpt
->contents
5453 + sizeof (Elf32_External_compact_rel
));
5454 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5455 ((Elf32_External_crinfo
*) cr
5456 + scpt
->reloc_count
));
5457 ++scpt
->reloc_count
;
5460 /* This reloc will be computed at runtime, so
5461 there's no need to do anything now. */
5465 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5466 contents
, rel
->r_offset
,
5467 relocation
, addend
);
5469 else if (r_type
== R_MIPS_64
)
5474 /* Do a 32 bit relocation, and sign extend to 64 bits. */
5475 addr
= rel
->r_offset
;
5476 if (bfd_big_endian (input_bfd
))
5478 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5479 contents
, addr
, relocation
,
5481 val
= bfd_get_32 (input_bfd
, contents
+ addr
);
5482 if ((val
& 0x80000000) != 0)
5486 addr
= rel
->r_offset
;
5487 if (bfd_little_endian (input_bfd
))
5489 bfd_put_32 (input_bfd
, val
, contents
+ addr
);
5491 else if (r_type
== R_MIPS_26
&& other
== STO_MIPS16
)
5495 /* This is a jump to a mips16 routine from a mips32
5496 routine. We need to change jal into jalx. */
5497 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5498 if (((insn
>> 26) & 0x3f) != 0x3
5499 && ((insn
>> 26) & 0x3f) != 0x1d)
5501 (*_bfd_error_handler
)
5502 (_("%s: %s+0x%lx: jump to mips16 routine which is not jal"),
5503 bfd_get_filename (input_bfd
),
5504 input_section
->name
,
5505 (unsigned long) rel
->r_offset
);
5506 bfd_set_error (bfd_error_bad_value
);
5509 insn
= (insn
& 0x3ffffff) | (0x1d << 26);
5510 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5511 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5512 contents
, rel
->r_offset
,
5513 relocation
, addend
);
5515 else if (r_type
== R_MIPS16_26
)
5517 /* It's easiest to do the normal relocation, and then
5518 dig out the instruction and swap the first word the
5519 way the mips16 expects it. If this is little endian,
5520 though, we need to swap the two words first, and then
5521 swap them back again later, so that the address looks
5524 if (bfd_little_endian (input_bfd
))
5528 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5529 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5530 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5533 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5534 contents
, rel
->r_offset
,
5535 relocation
, addend
);
5536 if (r
== bfd_reloc_ok
)
5540 if (bfd_little_endian (input_bfd
))
5542 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5543 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5544 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5547 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5548 insn
= ((insn
& 0xfc00)
5549 | ((insn
& 0x1f) << 5)
5550 | ((insn
& 0x3e0) >> 5));
5551 /* If this is a jump to a 32 bit routine, then make
5553 if (other
!= STO_MIPS16
)
5555 bfd_put_16 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5558 else if (r_type
== R_MIPS16_GPREL
)
5560 unsigned short extend
, insn
;
5562 unsigned long final
;
5564 /* Extract the addend into buf, run the regular reloc,
5565 and stuff the resulting value back into the
5567 if (rel
->r_offset
> input_section
->_raw_size
)
5568 r
= bfd_reloc_outofrange
;
5571 extend
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5572 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 2);
5573 bfd_put_32 (input_bfd
,
5574 (((extend
& 0x1f) << 11)
5578 r
= _bfd_final_link_relocate (howto
, input_bfd
,
5580 (bfd_vma
) 0, relocation
,
5582 final
= bfd_get_32 (input_bfd
, buf
);
5583 bfd_put_16 (input_bfd
,
5585 | ((final
>> 11) & 0x1f)
5587 contents
+ rel
->r_offset
);
5588 bfd_put_16 (input_bfd
,
5591 contents
+ rel
->r_offset
+ 2);
5595 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5596 contents
, rel
->r_offset
,
5597 relocation
, addend
);
5599 /* The jal instruction can only jump to an address which is
5600 divisible by 4, and it can only jump to an address with
5601 the same upper 4 bits as the PC. */
5602 if (r
== bfd_reloc_ok
5603 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
))
5608 if (other
== STO_MIPS16
)
5609 addr
&= ~ (bfd_vma
) 1;
5612 || ((addr
& 0xf0000000)
5613 != ((input_section
->output_section
->vma
5614 + input_section
->output_offset
5617 r
= bfd_reloc_overflow
;
5620 /* Don't bother to report a relocation overflow for a call
5621 to a weak undefined symbol with a value of zero. This
5624 even if we aren't in range to call address zero. */
5625 if (r
== bfd_reloc_overflow
5626 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
)
5627 && relocation
+ addend
== 0
5629 && h
->root
.type
== bfd_link_hash_undefweak
)
5632 /* If we've already issued an error for an undefined symbol,
5633 don't issue another useless error. */
5635 && (r
== bfd_reloc_undefined
|| r
== bfd_reloc_overflow
))
5638 if (SGI_COMPAT (abfd
)
5640 && (input_section
->flags
& SEC_ALLOC
) != 0)
5642 Elf32_crinfo cptrel
;
5645 /* Make an entry of compact relocation info. */
5646 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5647 cptrel
.vaddr
= (rel
->r_offset
5648 + input_section
->output_section
->vma
5649 + input_section
->output_offset
);
5654 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
5655 /* XXX How should we set dist2to in this case. */
5656 mips_elf_set_cr_dist2to (cptrel
, 8);
5657 cptrel
.konst
= addend
+ relocation
;
5658 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5659 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5660 ((Elf32_External_crinfo
*) cr
5661 + scpt
->reloc_count
));
5662 ++scpt
->reloc_count
;
5665 case R_MIPS_GPREL16
:
5666 case R_MIPS_LITERAL
:
5667 case R_MIPS_GPREL32
:
5668 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
5669 cptrel
.konst
= gp
- cptrel
.vaddr
;
5670 mips_elf_set_cr_dist2to (cptrel
, 4);
5671 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5672 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5673 ((Elf32_External_crinfo
*) cr
5674 + scpt
->reloc_count
));
5675 ++scpt
->reloc_count
;
5684 if (r
!= bfd_reloc_ok
)
5689 case bfd_reloc_outofrange
:
5691 case bfd_reloc_overflow
:
5696 name
= h
->root
.root
.string
;
5699 name
= bfd_elf_string_from_elf_section (input_bfd
,
5700 symtab_hdr
->sh_link
,
5705 name
= bfd_section_name (input_bfd
, sec
);
5707 if (! ((*info
->callbacks
->reloc_overflow
)
5708 (info
, name
, howto
->name
, (bfd_vma
) 0,
5709 input_bfd
, input_section
, rel
->r_offset
)))
5720 /* This hook function is called before the linker writes out a global
5721 symbol. We mark symbols as small common if appropriate. This is
5722 also where we undo the increment of the value for a mips16 symbol. */
5726 mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
5728 struct bfd_link_info
*info
;
5730 Elf_Internal_Sym
*sym
;
5731 asection
*input_sec
;
5733 /* If we see a common symbol, which implies a relocatable link, then
5734 if a symbol was small common in an input file, mark it as small
5735 common in the output file. */
5736 if (sym
->st_shndx
== SHN_COMMON
5737 && strcmp (input_sec
->name
, ".scommon") == 0)
5738 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
5740 if (sym
->st_other
== STO_MIPS16
5741 && (sym
->st_value
& 1) != 0)
5747 /* Functions for the dynamic linker. */
5749 /* The name of the dynamic interpreter. This is put in the .interp
5752 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
5754 /* Create dynamic sections when linking against a dynamic object. */
5757 mips_elf_create_dynamic_sections (abfd
, info
)
5759 struct bfd_link_info
*info
;
5761 struct elf_link_hash_entry
*h
;
5763 register asection
*s
;
5764 const char * const *namep
;
5766 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5767 | SEC_LINKER_CREATED
| SEC_READONLY
);
5769 /* Mips ABI requests the .dynamic section to be read only. */
5770 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5773 if (! bfd_set_section_flags (abfd
, s
, flags
))
5777 /* We need to create .got section. */
5778 if (! mips_elf_create_got_section (abfd
, info
))
5781 /* Create .stub section. */
5782 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
5784 s
= bfd_make_section (abfd
, ".stub");
5786 || ! bfd_set_section_flags (abfd
, s
, flags
)
5787 || ! bfd_set_section_alignment (abfd
, s
, 2))
5791 if (SGI_COMPAT (abfd
)
5793 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
5795 s
= bfd_make_section (abfd
, ".rld_map");
5797 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
5798 || ! bfd_set_section_alignment (abfd
, s
, 2))
5802 if (SGI_COMPAT (abfd
))
5804 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
5807 if (! (_bfd_generic_link_add_one_symbol
5808 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
5809 (bfd_vma
) 0, (const char *) NULL
, false,
5810 get_elf_backend_data (abfd
)->collect
,
5811 (struct bfd_link_hash_entry
**) &h
)))
5813 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5814 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5815 h
->type
= STT_SECTION
;
5817 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5821 /* We need to create a .compact_rel section. */
5822 if (! mips_elf_create_compact_rel_section (abfd
, info
))
5825 /* Change aligments of some sections. */
5826 s
= bfd_get_section_by_name (abfd
, ".hash");
5828 bfd_set_section_alignment (abfd
, s
, 4);
5829 s
= bfd_get_section_by_name (abfd
, ".dynsym");
5831 bfd_set_section_alignment (abfd
, s
, 4);
5832 s
= bfd_get_section_by_name (abfd
, ".dynstr");
5834 bfd_set_section_alignment (abfd
, s
, 4);
5835 s
= bfd_get_section_by_name (abfd
, ".reginfo");
5837 bfd_set_section_alignment (abfd
, s
, 4);
5838 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5840 bfd_set_section_alignment (abfd
, s
, 4);
5846 if (! (_bfd_generic_link_add_one_symbol
5847 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
5848 (bfd_vma
) 0, (const char *) NULL
, false,
5849 get_elf_backend_data (abfd
)->collect
,
5850 (struct bfd_link_hash_entry
**) &h
)))
5852 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5853 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5854 h
->type
= STT_SECTION
;
5856 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5859 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
5861 /* __rld_map is a four byte word located in the .data section
5862 and is filled in by the rtld to contain a pointer to
5863 the _r_debug structure. Its symbol value will be set in
5864 mips_elf_finish_dynamic_symbol. */
5865 s
= bfd_get_section_by_name (abfd
, ".rld_map");
5866 BFD_ASSERT (s
!= NULL
);
5869 if (! (_bfd_generic_link_add_one_symbol
5870 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
5871 (bfd_vma
) 0, (const char *) NULL
, false,
5872 get_elf_backend_data (abfd
)->collect
,
5873 (struct bfd_link_hash_entry
**) &h
)))
5875 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5876 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5877 h
->type
= STT_OBJECT
;
5879 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5887 /* Create the .compact_rel section. */
5890 mips_elf_create_compact_rel_section (abfd
, info
)
5892 struct bfd_link_info
*info
;
5895 register asection
*s
;
5897 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
5899 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
5902 s
= bfd_make_section (abfd
, ".compact_rel");
5904 || ! bfd_set_section_flags (abfd
, s
, flags
)
5905 || ! bfd_set_section_alignment (abfd
, s
, 2))
5908 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
5914 /* Create the .got section to hold the global offset table. */
5917 mips_elf_create_got_section (abfd
, info
)
5919 struct bfd_link_info
*info
;
5922 register asection
*s
;
5923 struct elf_link_hash_entry
*h
;
5924 struct mips_got_info
*g
;
5926 /* This function may be called more than once. */
5927 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
5930 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5931 | SEC_LINKER_CREATED
);
5933 s
= bfd_make_section (abfd
, ".got");
5935 || ! bfd_set_section_flags (abfd
, s
, flags
)
5936 || ! bfd_set_section_alignment (abfd
, s
, 4))
5939 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
5940 linker script because we don't want to define the symbol if we
5941 are not creating a global offset table. */
5943 if (! (_bfd_generic_link_add_one_symbol
5944 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
5945 (bfd_vma
) 0, (const char *) NULL
, false,
5946 get_elf_backend_data (abfd
)->collect
,
5947 (struct bfd_link_hash_entry
**) &h
)))
5949 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5950 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5951 h
->type
= STT_OBJECT
;
5954 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5957 /* The first several global offset table entries are reserved. */
5958 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
5960 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
5961 sizeof (struct mips_got_info
));
5964 g
->global_gotsym
= 0;
5965 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
5966 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
5967 if (elf_section_data (s
) == NULL
)
5970 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
5971 if (elf_section_data (s
) == NULL
)
5974 elf_section_data (s
)->tdata
= (PTR
) g
;
5979 /* Look through the relocs for a section during the first phase, and
5980 allocate space in the global offset table. */
5983 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
5985 struct bfd_link_info
*info
;
5987 const Elf_Internal_Rela
*relocs
;
5991 Elf_Internal_Shdr
*symtab_hdr
;
5992 struct elf_link_hash_entry
**sym_hashes
;
5993 struct mips_got_info
*g
;
5995 const Elf_Internal_Rela
*rel
;
5996 const Elf_Internal_Rela
*rel_end
;
6000 if (info
->relocateable
)
6003 dynobj
= elf_hash_table (info
)->dynobj
;
6004 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6005 sym_hashes
= elf_sym_hashes (abfd
);
6006 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
6008 /* Check for the mips16 stub sections. */
6010 name
= bfd_get_section_name (abfd
, sec
);
6011 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
6013 unsigned long r_symndx
;
6015 /* Look at the relocation information to figure out which symbol
6018 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6020 if (r_symndx
< extsymoff
6021 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6025 /* This stub is for a local symbol. This stub will only be
6026 needed if there is some relocation in this BFD, other
6027 than a 16 bit function call, which refers to this symbol. */
6028 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6030 Elf_Internal_Rela
*sec_relocs
;
6031 const Elf_Internal_Rela
*r
, *rend
;
6033 /* We can ignore stub sections when looking for relocs. */
6034 if ((o
->flags
& SEC_RELOC
) == 0
6035 || o
->reloc_count
== 0
6036 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
6037 sizeof FN_STUB
- 1) == 0
6038 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
6039 sizeof CALL_STUB
- 1) == 0
6040 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
6041 sizeof CALL_FP_STUB
- 1) == 0)
6044 sec_relocs
= (_bfd_elf32_link_read_relocs
6045 (abfd
, o
, (PTR
) NULL
,
6046 (Elf_Internal_Rela
*) NULL
,
6047 info
->keep_memory
));
6048 if (sec_relocs
== NULL
)
6051 rend
= sec_relocs
+ o
->reloc_count
;
6052 for (r
= sec_relocs
; r
< rend
; r
++)
6053 if (ELF32_R_SYM (r
->r_info
) == r_symndx
6054 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
6057 if (! info
->keep_memory
)
6066 /* There is no non-call reloc for this stub, so we do
6067 not need it. Since this function is called before
6068 the linker maps input sections to output sections, we
6069 can easily discard it by setting the SEC_EXCLUDE
6071 sec
->flags
|= SEC_EXCLUDE
;
6075 /* Record this stub in an array of local symbol stubs for
6077 if (elf_tdata (abfd
)->local_stubs
== NULL
)
6079 unsigned long symcount
;
6082 if (elf_bad_symtab (abfd
))
6083 symcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
6085 symcount
= symtab_hdr
->sh_info
;
6086 n
= (asection
**) bfd_zalloc (abfd
,
6087 symcount
* sizeof (asection
*));
6090 elf_tdata (abfd
)->local_stubs
= n
;
6093 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
6095 /* We don't need to set mips16_stubs_seen in this case.
6096 That flag is used to see whether we need to look through
6097 the global symbol table for stubs. We don't need to set
6098 it here, because we just have a local stub. */
6102 struct mips_elf_link_hash_entry
*h
;
6104 h
= ((struct mips_elf_link_hash_entry
*)
6105 sym_hashes
[r_symndx
- extsymoff
]);
6107 /* H is the symbol this stub is for. */
6110 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6113 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
6114 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6116 unsigned long r_symndx
;
6117 struct mips_elf_link_hash_entry
*h
;
6120 /* Look at the relocation information to figure out which symbol
6123 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6125 if (r_symndx
< extsymoff
6126 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6128 /* This stub was actually built for a static symbol defined
6129 in the same file. We assume that all static symbols in
6130 mips16 code are themselves mips16, so we can simply
6131 discard this stub. Since this function is called before
6132 the linker maps input sections to output sections, we can
6133 easily discard it by setting the SEC_EXCLUDE flag. */
6134 sec
->flags
|= SEC_EXCLUDE
;
6138 h
= ((struct mips_elf_link_hash_entry
*)
6139 sym_hashes
[r_symndx
- extsymoff
]);
6141 /* H is the symbol this stub is for. */
6143 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6144 loc
= &h
->call_fp_stub
;
6146 loc
= &h
->call_stub
;
6148 /* If we already have an appropriate stub for this function, we
6149 don't need another one, so we can discard this one. Since
6150 this function is called before the linker maps input sections
6151 to output sections, we can easily discard it by setting the
6152 SEC_EXCLUDE flag. We can also discard this section if we
6153 happen to already know that this is a mips16 function; it is
6154 not necessary to check this here, as it is checked later, but
6155 it is slightly faster to check now. */
6156 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
6158 sec
->flags
|= SEC_EXCLUDE
;
6163 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6173 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6178 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6179 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6180 BFD_ASSERT (g
!= NULL
);
6186 rel_end
= relocs
+ sec
->reloc_count
;
6187 for (rel
= relocs
; rel
< rel_end
; rel
++)
6189 unsigned long r_symndx
;
6190 struct elf_link_hash_entry
*h
;
6192 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6194 if (r_symndx
< extsymoff
)
6198 h
= sym_hashes
[r_symndx
- extsymoff
];
6200 /* This may be an indirect symbol created because of a version. */
6203 while (h
->root
.type
== bfd_link_hash_indirect
)
6204 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6208 /* Some relocs require a global offset table. */
6209 if (dynobj
== NULL
|| sgot
== NULL
)
6211 switch (ELF32_R_TYPE (rel
->r_info
))
6215 case R_MIPS_CALL_HI16
:
6216 case R_MIPS_CALL_LO16
:
6217 case R_MIPS_GOT_HI16
:
6218 case R_MIPS_GOT_LO16
:
6220 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6221 if (! mips_elf_create_got_section (dynobj
, info
))
6223 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6224 BFD_ASSERT (sgot
!= NULL
);
6225 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6226 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6227 BFD_ASSERT (g
!= NULL
);
6233 && (info
->shared
|| h
!= NULL
)
6234 && (sec
->flags
& SEC_ALLOC
) != 0)
6235 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6243 switch (ELF32_R_TYPE (rel
->r_info
))
6246 case R_MIPS_CALL_HI16
:
6247 case R_MIPS_CALL_LO16
:
6248 /* This symbol requires a global offset table entry. */
6252 (*_bfd_error_handler
)
6253 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
6254 bfd_get_filename (abfd
), (unsigned long) rel
->r_offset
);
6255 bfd_set_error (bfd_error_bad_value
);
6259 /* Make sure this symbol is output as a dynamic symbol. */
6260 if (h
->dynindx
== -1)
6262 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6266 if (h
->got
.offset
!= (bfd_vma
) -1)
6268 /* We have already allocated space in the .got. */
6272 /* Note the index of the first global got symbol in .dynsym. */
6273 if (g
->global_gotsym
== 0
6274 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6275 g
->global_gotsym
= h
->dynindx
;
6277 /* Make this symbol to have the corresponding got entry. */
6280 /* We need a stub, not a plt entry for the undefined
6281 function. But we record it as if it needs plt. See
6282 elf_adjust_dynamic_symbol in elflink.h. */
6283 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6289 case R_MIPS_GOT_HI16
:
6290 case R_MIPS_GOT_LO16
:
6291 /* This symbol requires a global offset table entry. */
6295 /* Make sure this symbol is output as a dynamic symbol. */
6296 if (h
->dynindx
== -1)
6298 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6302 if (h
->got
.offset
!= (bfd_vma
) -1)
6304 /* We have already allocated space in the .got. */
6307 /* Note the index of the first global got symbol in
6309 if (g
->global_gotsym
== 0
6310 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6311 g
->global_gotsym
= h
->dynindx
;
6313 /* Make this symbol to be the global got symbol. */
6321 if ((info
->shared
|| h
!= NULL
)
6322 && (sec
->flags
& SEC_ALLOC
) != 0)
6326 const char *name
= ".rel.dyn";
6328 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6331 sreloc
= bfd_make_section (dynobj
, name
);
6333 || ! bfd_set_section_flags (dynobj
, sreloc
,
6338 | SEC_LINKER_CREATED
6340 || ! bfd_set_section_alignment (dynobj
, sreloc
,
6347 /* When creating a shared object, we must copy these
6348 reloc types into the output file as R_MIPS_REL32
6349 relocs. We make room for this reloc in the
6350 .rel.dyn reloc section */
6351 if (sreloc
->_raw_size
== 0)
6353 /* Add a null element. */
6354 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6355 ++sreloc
->reloc_count
;
6357 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6361 struct mips_elf_link_hash_entry
*hmips
;
6363 /* We only need to copy this reloc if the symbol is
6364 defined in a dynamic object. */
6365 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6366 ++hmips
->mips_32_relocs
;
6370 if (SGI_COMPAT (abfd
))
6371 mips_elf_hash_table (info
)->compact_rel_size
+=
6372 sizeof (Elf32_External_crinfo
);
6377 case R_MIPS_GPREL16
:
6378 case R_MIPS_LITERAL
:
6379 case R_MIPS_GPREL32
:
6380 if (SGI_COMPAT (abfd
))
6381 mips_elf_hash_table (info
)->compact_rel_size
+=
6382 sizeof (Elf32_External_crinfo
);
6385 /* This relocation describes the C++ object vtable hierarchy.
6386 Reconstruct it for later use during GC. */
6387 case R_MIPS_GNU_VTINHERIT
:
6388 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6392 /* This relocation describes which C++ vtable entries are actually
6393 used. Record for later use during GC. */
6394 case R_MIPS_GNU_VTENTRY
:
6395 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
6403 /* If this reloc is not a 16 bit call, and it has a global
6404 symbol, then we will need the fn_stub if there is one.
6405 References from a stub section do not count. */
6407 && ELF32_R_TYPE (rel
->r_info
) != R_MIPS16_26
6408 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
6409 sizeof FN_STUB
- 1) != 0
6410 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
6411 sizeof CALL_STUB
- 1) != 0
6412 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
6413 sizeof CALL_FP_STUB
- 1) != 0)
6415 struct mips_elf_link_hash_entry
*mh
;
6417 mh
= (struct mips_elf_link_hash_entry
*) h
;
6418 mh
->need_fn_stub
= true;
6425 /* Return the section that should be marked against GC for a given
6429 mips_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
6431 struct bfd_link_info
*info
;
6432 Elf_Internal_Rela
*rel
;
6433 struct elf_link_hash_entry
*h
;
6434 Elf_Internal_Sym
*sym
;
6436 /* ??? Do mips16 stub sections need to be handled special? */
6440 switch (ELF32_R_TYPE (rel
->r_info
))
6442 case R_MIPS_GNU_VTINHERIT
:
6443 case R_MIPS_GNU_VTENTRY
:
6447 switch (h
->root
.type
)
6449 case bfd_link_hash_defined
:
6450 case bfd_link_hash_defweak
:
6451 return h
->root
.u
.def
.section
;
6453 case bfd_link_hash_common
:
6454 return h
->root
.u
.c
.p
->section
;
6460 if (!(elf_bad_symtab (abfd
)
6461 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
6462 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
6463 && sym
->st_shndx
!= SHN_COMMON
))
6465 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
6472 /* Update the got entry reference counts for the section being removed. */
6475 mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
6477 struct bfd_link_info
*info
;
6479 const Elf_Internal_Rela
*relocs
;
6482 Elf_Internal_Shdr
*symtab_hdr
;
6483 struct elf_link_hash_entry
**sym_hashes
;
6484 bfd_signed_vma
*local_got_refcounts
;
6485 const Elf_Internal_Rela
*rel
, *relend
;
6486 unsigned long r_symndx
;
6487 struct elf_link_hash_entry
*h
;
6489 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6490 sym_hashes
= elf_sym_hashes (abfd
);
6491 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6493 relend
= relocs
+ sec
->reloc_count
;
6494 for (rel
= relocs
; rel
< relend
; rel
++)
6495 switch (ELF32_R_TYPE (rel
->r_info
))
6499 case R_MIPS_CALL_HI16
:
6500 case R_MIPS_CALL_LO16
:
6501 case R_MIPS_GOT_HI16
:
6502 case R_MIPS_GOT_LO16
:
6503 /* ??? It would seem that the existing MIPS code does no sort
6504 of reference counting or whatnot on its GOT and PLT entries,
6505 so it is not possible to garbage collect them at this time. */
6517 /* Adjust a symbol defined by a dynamic object and referenced by a
6518 regular object. The current definition is in some section of the
6519 dynamic object, but we're not including those sections. We have to
6520 change the definition to something the rest of the link can
6524 mips_elf_adjust_dynamic_symbol (info
, h
)
6525 struct bfd_link_info
*info
;
6526 struct elf_link_hash_entry
*h
;
6529 struct mips_elf_link_hash_entry
*hmips
;
6532 dynobj
= elf_hash_table (info
)->dynobj
;
6534 /* Make sure we know what is going on here. */
6535 BFD_ASSERT (dynobj
!= NULL
6536 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
6537 || h
->weakdef
!= NULL
6538 || ((h
->elf_link_hash_flags
6539 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
6540 && (h
->elf_link_hash_flags
6541 & ELF_LINK_HASH_REF_REGULAR
) != 0
6542 && (h
->elf_link_hash_flags
6543 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
6545 /* If this symbol is defined in a dynamic object, we need to copy
6546 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
6548 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6549 if (! info
->relocateable
6550 && hmips
->mips_32_relocs
!= 0
6551 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6553 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6554 BFD_ASSERT (s
!= NULL
);
6556 if (s
->_raw_size
== 0)
6558 /* Make room for a null element. */
6559 s
->_raw_size
+= sizeof (Elf32_External_Rel
);
6562 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
6565 /* For a function, create a stub, if needed. */
6566 if (h
->type
== STT_FUNC
6567 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
6569 if (! elf_hash_table (info
)->dynamic_sections_created
)
6572 /* If this symbol is not defined in a regular file, then set
6573 the symbol to the stub location. This is required to make
6574 function pointers compare as equal between the normal
6575 executable and the shared library. */
6576 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6578 /* We need .stub section. */
6579 s
= bfd_get_section_by_name (dynobj
, ".stub");
6580 BFD_ASSERT (s
!= NULL
);
6582 h
->root
.u
.def
.section
= s
;
6583 h
->root
.u
.def
.value
= s
->_raw_size
;
6585 /* XXX Write this stub address somewhere. */
6586 h
->plt
.offset
= s
->_raw_size
;
6588 /* Make room for this stub code. */
6589 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6591 /* The last half word of the stub will be filled with the index
6592 of this symbol in .dynsym section. */
6597 /* If this is a weak symbol, and there is a real definition, the
6598 processor independent code will have arranged for us to see the
6599 real definition first, and we can just use the same value. */
6600 if (h
->weakdef
!= NULL
)
6602 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
6603 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
6604 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
6605 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
6609 /* This is a reference to a symbol defined by a dynamic object which
6610 is not a function. */
6615 /* This function is called after all the input files have been read,
6616 and the input sections have been assigned to output sections. We
6617 check for any mips16 stub sections that we can discard. */
6619 static boolean mips_elf_check_mips16_stubs
6620 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
6623 mips_elf_always_size_sections (output_bfd
, info
)
6625 struct bfd_link_info
*info
;
6627 if (info
->relocateable
6628 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
6631 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
6632 mips_elf_check_mips16_stubs
,
6638 /* Check the mips16 stubs for a particular symbol, and see if we can
6643 mips_elf_check_mips16_stubs (h
, data
)
6644 struct mips_elf_link_hash_entry
*h
;
6647 if (h
->fn_stub
!= NULL
6648 && ! h
->need_fn_stub
)
6650 /* We don't need the fn_stub; the only references to this symbol
6651 are 16 bit calls. Clobber the size to 0 to prevent it from
6652 being included in the link. */
6653 h
->fn_stub
->_raw_size
= 0;
6654 h
->fn_stub
->_cooked_size
= 0;
6655 h
->fn_stub
->flags
&= ~ SEC_RELOC
;
6656 h
->fn_stub
->reloc_count
= 0;
6657 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
6660 if (h
->call_stub
!= NULL
6661 && h
->root
.other
== STO_MIPS16
)
6663 /* We don't need the call_stub; this is a 16 bit function, so
6664 calls from other 16 bit functions are OK. Clobber the size
6665 to 0 to prevent it from being included in the link. */
6666 h
->call_stub
->_raw_size
= 0;
6667 h
->call_stub
->_cooked_size
= 0;
6668 h
->call_stub
->flags
&= ~ SEC_RELOC
;
6669 h
->call_stub
->reloc_count
= 0;
6670 h
->call_stub
->flags
|= SEC_EXCLUDE
;
6673 if (h
->call_fp_stub
!= NULL
6674 && h
->root
.other
== STO_MIPS16
)
6676 /* We don't need the call_stub; this is a 16 bit function, so
6677 calls from other 16 bit functions are OK. Clobber the size
6678 to 0 to prevent it from being included in the link. */
6679 h
->call_fp_stub
->_raw_size
= 0;
6680 h
->call_fp_stub
->_cooked_size
= 0;
6681 h
->call_fp_stub
->flags
&= ~ SEC_RELOC
;
6682 h
->call_fp_stub
->reloc_count
= 0;
6683 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
6689 /* Set the sizes of the dynamic sections. */
6692 mips_elf_size_dynamic_sections (output_bfd
, info
)
6694 struct bfd_link_info
*info
;
6700 struct mips_got_info
*g
;
6702 dynobj
= elf_hash_table (info
)->dynobj
;
6703 BFD_ASSERT (dynobj
!= NULL
);
6705 if (elf_hash_table (info
)->dynamic_sections_created
)
6707 /* Set the contents of the .interp section to the interpreter. */
6710 s
= bfd_get_section_by_name (dynobj
, ".interp");
6711 BFD_ASSERT (s
!= NULL
);
6712 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
6713 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
6717 /* Recompute the size of .got for local entires (reserved and
6718 hipages) if needed. To estimate it, get the upper bound of total
6719 size of loadable sections. */
6720 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6724 bfd_size_type loadable_size
= 0;
6725 bfd_size_type local_gotno
;
6728 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6729 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6730 BFD_ASSERT (g
!= NULL
);
6732 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
6733 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
6735 if ((s
->flags
& SEC_ALLOC
) == 0)
6737 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
6740 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
6742 /* Assume there are two loadable segments consisting of
6743 contiguous sections. Is 5 enough? */
6744 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
6745 g
->local_gotno
= local_gotno
;
6746 sgot
->_raw_size
+= local_gotno
* 4;
6749 /* The check_relocs and adjust_dynamic_symbol entry points have
6750 determined the sizes of the various dynamic sections. Allocate
6753 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
6758 /* It's OK to base decisions on the section name, because none
6759 of the dynobj section names depend upon the input files. */
6760 name
= bfd_get_section_name (dynobj
, s
);
6762 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
6767 if (strncmp (name
, ".rel", 4) == 0)
6769 if (s
->_raw_size
== 0)
6771 /* We only strip the section if the output section name
6772 has the same name. Otherwise, there might be several
6773 input sections for this output section. FIXME: This
6774 code is probably not needed these days anyhow, since
6775 the linker now does not create empty output sections. */
6776 if (s
->output_section
!= NULL
6778 bfd_get_section_name (s
->output_section
->owner
,
6779 s
->output_section
)) == 0)
6784 const char *outname
;
6787 /* If this relocation section applies to a read only
6788 section, then we probably need a DT_TEXTREL entry.
6789 If the relocation section is .rel.dyn, we always
6790 assert a DT_TEXTREL entry rather than testing whether
6791 there exists a relocation to a read only section or
6793 outname
= bfd_get_section_name (output_bfd
,
6795 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
6797 && (target
->flags
& SEC_READONLY
) != 0
6798 && (target
->flags
& SEC_ALLOC
) != 0)
6799 || strcmp (outname
, ".rel.dyn") == 0)
6802 /* We use the reloc_count field as a counter if we need
6803 to copy relocs into the output file. */
6804 if (strcmp (name
, ".rel.dyn") != 0)
6808 else if (strncmp (name
, ".got", 4) == 0)
6812 BFD_ASSERT (elf_section_data (s
) != NULL
);
6813 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
6814 BFD_ASSERT (g
!= NULL
);
6816 /* Fix the size of .got section for the correspondence of
6817 global symbols and got entries. This adds some useless
6818 got entries. Is this required by ABI really? */
6819 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
6820 s
->_raw_size
+= i
* 4;
6822 else if (strncmp (name
, ".stub", 5) == 0)
6824 /* Irix rld assumes that the function stub isn't at the end
6825 of .text section. So put a dummy. XXX */
6826 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6828 else if (! info
->shared
6829 && ! mips_elf_hash_table (info
)->use_rld_obj_head
6830 && strncmp (name
, ".rld_map", 8) == 0)
6832 /* We add a room for __rld_map. It will be filled in by the
6833 rtld to contain a pointer to the _r_debug structure. */
6836 else if (SGI_COMPAT (output_bfd
)
6837 && strncmp (name
, ".compact_rel", 12) == 0)
6838 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
6839 else if (strncmp (name
, ".init", 5) != 0)
6841 /* It's not one of our sections, so don't allocate space. */
6849 for (spp
= &s
->output_section
->owner
->sections
;
6850 *spp
!= s
->output_section
;
6851 spp
= &(*spp
)->next
)
6853 *spp
= s
->output_section
->next
;
6854 --s
->output_section
->owner
->section_count
;
6859 /* Allocate memory for the section contents. */
6860 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
6861 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
6863 bfd_set_error (bfd_error_no_memory
);
6866 memset (s
->contents
, 0, s
->_raw_size
);
6869 if (elf_hash_table (info
)->dynamic_sections_created
)
6871 /* Add some entries to the .dynamic section. We fill in the
6872 values later, in elf_mips_finish_dynamic_sections, but we
6873 must add the entries now so that we get the correct size for
6874 the .dynamic section. The DT_DEBUG entry is filled in by the
6875 dynamic linker and used by the debugger. */
6878 if (SGI_COMPAT (output_bfd
))
6880 /* SGI object has the equivalence of DT_DEBUG in the
6881 DT_MIPS_RLD_MAP entry. */
6882 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
6886 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
6892 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
6896 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
6899 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
6901 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
6904 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
6907 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
6911 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
6914 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
6917 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
6919 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
6922 s
= bfd_get_section_by_name (dynobj
, ".liblist");
6923 BFD_ASSERT (s
!= NULL
);
6925 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
6929 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
6932 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
6936 /* Time stamps in executable files are a bad idea. */
6937 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
6942 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
6947 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
6951 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
6954 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
6957 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
6960 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
6963 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
6966 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
6969 #if 0 /* (SGI_COMPAT) */
6970 if (! bfd_get_section_by_name (dynobj
, ".init"))
6971 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
6974 if (! bfd_get_section_by_name (dynobj
, ".fini"))
6975 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
6980 /* If we use dynamic linking, we generate a section symbol for each
6981 output section. These are local symbols, which means that they
6982 must come first in the dynamic symbol table.
6983 That means we must increment the dynamic symbol index of every
6984 other dynamic symbol. */
6986 const char * const *namep
;
6988 bfd_size_type strindex
;
6989 struct bfd_strtab_hash
*dynstr
;
6990 struct mips_got_info
*g
;
6993 if (elf_hash_table (info
)->dynamic_sections_created
)
6995 if (SGI_COMPAT (output_bfd
))
6997 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
6998 elf_link_hash_traverse (elf_hash_table (info
),
6999 mips_elf_adjust_dynindx
,
7001 elf_hash_table (info
)->dynsymcount
+= c
;
7003 dynstr
= elf_hash_table (info
)->dynstr
;
7004 BFD_ASSERT (dynstr
!= NULL
);
7006 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
7010 s
= bfd_get_section_by_name (output_bfd
, *namep
);
7012 elf_section_data (s
)->dynindx
= i
;
7014 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
7015 if (strindex
== (bfd_size_type
) -1)
7018 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
7023 c
= bfd_count_sections (output_bfd
);
7024 elf_link_hash_traverse (elf_hash_table (info
),
7025 mips_elf_adjust_dynindx
,
7027 elf_hash_table (info
)->dynsymcount
+= c
;
7029 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
7031 elf_section_data (s
)->dynindx
= i
;
7032 /* These symbols will have no names, so we don't need to
7033 fiddle with dynstr_index. */
7040 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7041 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7042 BFD_ASSERT (g
!= NULL
);
7044 /* If there are no global got symbols, fake the last symbol so
7046 if (g
->global_gotsym
)
7047 g
->global_gotsym
+= c
;
7049 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
7056 /* Increment the index of a dynamic symbol by a given amount. Called
7057 via elf_link_hash_traverse. */
7060 mips_elf_adjust_dynindx (h
, cparg
)
7061 struct elf_link_hash_entry
*h
;
7064 unsigned int *cp
= (unsigned int *) cparg
;
7066 if (h
->dynindx
!= -1)
7071 /* Finish up dynamic symbol handling. We set the contents of various
7072 dynamic sections here. */
7075 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
7077 struct bfd_link_info
*info
;
7078 struct elf_link_hash_entry
*h
;
7079 Elf_Internal_Sym
*sym
;
7084 struct mips_got_info
*g
;
7087 dynobj
= elf_hash_table (info
)->dynobj
;
7088 gval
= sym
->st_value
;
7090 if (h
->plt
.offset
!= (bfd_vma
) -1)
7094 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
7096 /* This symbol has a stub. Set it up. */
7098 BFD_ASSERT (h
->dynindx
!= -1);
7100 s
= bfd_get_section_by_name (dynobj
, ".stub");
7101 BFD_ASSERT (s
!= NULL
);
7103 /* Fill the stub. */
7105 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
7107 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
7110 /* FIXME: Can h->dynindex be more than 64K? */
7111 if (h
->dynindx
& 0xffff0000)
7114 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
7116 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
7118 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
7119 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
7121 /* Mark the symbol as undefined. plt.offset != -1 occurs
7122 only for the referenced symbol. */
7123 sym
->st_shndx
= SHN_UNDEF
;
7125 /* The run-time linker uses the st_value field of the symbol
7126 to reset the global offset table entry for this external
7127 to its stub address when unlinking a shared object. */
7128 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
7129 sym
->st_value
= gval
;
7132 BFD_ASSERT (h
->dynindx
!= -1);
7134 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7135 BFD_ASSERT (sgot
!= NULL
);
7136 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7137 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7138 BFD_ASSERT (g
!= NULL
);
7140 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
7142 bfd_size_type offset
;
7144 /* This symbol has an entry in the global offset table. Set its
7145 value to the corresponding got entry, if needed. */
7146 if (h
->got
.offset
== (bfd_vma
) -1)
7148 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
7149 BFD_ASSERT (g
->local_gotno
* 4 <= offset
7150 && offset
< sgot
->_raw_size
);
7151 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
7155 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7156 name
= h
->root
.root
.string
;
7157 if (strcmp (name
, "_DYNAMIC") == 0
7158 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
7159 sym
->st_shndx
= SHN_ABS
;
7160 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
7162 sym
->st_shndx
= SHN_ABS
;
7163 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7166 else if (SGI_COMPAT (output_bfd
))
7168 if (strcmp (name
, "_gp_disp") == 0)
7170 sym
->st_shndx
= SHN_ABS
;
7171 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7172 sym
->st_value
= elf_gp (output_bfd
);
7174 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
7175 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
7177 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7178 sym
->st_other
= STO_PROTECTED
;
7180 sym
->st_shndx
= SHN_MIPS_DATA
;
7182 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
7184 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7185 sym
->st_other
= STO_PROTECTED
;
7186 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
7187 sym
->st_shndx
= SHN_ABS
;
7189 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
7191 if (h
->type
== STT_FUNC
)
7192 sym
->st_shndx
= SHN_MIPS_TEXT
;
7193 else if (h
->type
== STT_OBJECT
)
7194 sym
->st_shndx
= SHN_MIPS_DATA
;
7198 if (SGI_COMPAT (output_bfd
)
7201 if (! mips_elf_hash_table (info
)->use_rld_obj_head
7202 && strcmp (name
, "__rld_map") == 0)
7204 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7205 BFD_ASSERT (s
!= NULL
);
7206 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
7207 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
7208 if (mips_elf_hash_table (info
)->rld_value
== 0)
7209 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7211 else if (mips_elf_hash_table (info
)->use_rld_obj_head
7212 && strcmp (name
, "__rld_obj_head") == 0)
7214 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7215 BFD_ASSERT (s
!= NULL
);
7216 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7220 /* If this is a mips16 symbol, force the value to be even. */
7221 if (sym
->st_other
== STO_MIPS16
7222 && (sym
->st_value
& 1) != 0)
7228 /* Finish up the dynamic sections. */
7231 mips_elf_finish_dynamic_sections (output_bfd
, info
)
7233 struct bfd_link_info
*info
;
7238 struct mips_got_info
*g
;
7240 dynobj
= elf_hash_table (info
)->dynobj
;
7242 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
7244 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7249 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7250 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7251 BFD_ASSERT (g
!= NULL
);
7254 if (elf_hash_table (info
)->dynamic_sections_created
)
7256 Elf32_External_Dyn
*dyncon
, *dynconend
;
7258 BFD_ASSERT (sdyn
!= NULL
);
7259 BFD_ASSERT (g
!= NULL
);
7261 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7262 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
7263 for (; dyncon
< dynconend
; dyncon
++)
7265 Elf_Internal_Dyn dyn
;
7270 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
7278 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7279 BFD_ASSERT (s
!= NULL
);
7280 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
7281 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7285 /* Rewrite DT_STRSZ. */
7287 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
7288 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7294 case DT_MIPS_CONFLICT
:
7297 case DT_MIPS_LIBLIST
:
7300 s
= bfd_get_section_by_name (output_bfd
, name
);
7301 BFD_ASSERT (s
!= NULL
);
7302 dyn
.d_un
.d_ptr
= s
->vma
;
7303 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7306 case DT_MIPS_RLD_VERSION
:
7307 dyn
.d_un
.d_val
= 1; /* XXX */
7308 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7312 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
7313 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7316 case DT_MIPS_CONFLICTNO
:
7318 elemsize
= sizeof (Elf32_Conflict
);
7321 case DT_MIPS_LIBLISTNO
:
7323 elemsize
= sizeof (Elf32_Lib
);
7325 s
= bfd_get_section_by_name (output_bfd
, name
);
7328 if (s
->_cooked_size
!= 0)
7329 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7331 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7336 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7339 case DT_MIPS_TIME_STAMP
:
7340 time ((time_t *) &dyn
.d_un
.d_val
);
7341 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7344 case DT_MIPS_ICHECKSUM
:
7348 case DT_MIPS_IVERSION
:
7352 case DT_MIPS_BASE_ADDRESS
:
7353 s
= output_bfd
->sections
;
7354 BFD_ASSERT (s
!= NULL
);
7355 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
7356 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7359 case DT_MIPS_LOCAL_GOTNO
:
7360 dyn
.d_un
.d_val
= g
->local_gotno
;
7361 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7364 case DT_MIPS_SYMTABNO
:
7366 elemsize
= sizeof (Elf32_External_Sym
);
7367 s
= bfd_get_section_by_name (output_bfd
, name
);
7368 BFD_ASSERT (s
!= NULL
);
7370 if (s
->_cooked_size
!= 0)
7371 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7373 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7374 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7377 case DT_MIPS_UNREFEXTNO
:
7379 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
7380 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7383 case DT_MIPS_GOTSYM
:
7384 dyn
.d_un
.d_val
= g
->global_gotsym
;
7385 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7388 case DT_MIPS_HIPAGENO
:
7389 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
7390 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7393 case DT_MIPS_RLD_MAP
:
7394 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
7395 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7402 /* The first entry of the global offset table will be filled at
7403 runtime. The second entry will be used by some runtime loaders.
7404 This isn't the case of Irix rld. */
7405 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
7407 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
7408 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
7412 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
7419 Elf_Internal_Sym sym
;
7422 const char * const * namep
= mips_elf_dynsym_sec_names
;
7423 Elf32_compact_rel cpt
;
7425 /* Set up the section symbols for the output sections. SGI sets
7426 the STT_NOTYPE attribute for these symbols. Should we do so? */
7428 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
7429 if (sdynsym
!= NULL
)
7431 if (SGI_COMPAT (output_bfd
))
7435 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7441 while ((name
= *namep
++) != NULL
)
7443 s
= bfd_get_section_by_name (output_bfd
, name
);
7446 sym
.st_value
= s
->vma
;
7447 dindx
= elf_section_data (s
)->dynindx
;
7448 last
= s
->vma
+ s
->_raw_size
;
7452 sym
.st_value
= last
;
7456 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
7461 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
7463 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7464 (((Elf32_External_Sym
*)
7469 /* Set the sh_info field of the output .dynsym section to
7470 the index of the first global symbol. */
7471 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7472 SIZEOF_MIPS_DYNSYM_SECNAMES
;
7478 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
7481 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
7485 sym
.st_value
= s
->vma
;
7487 indx
= elf_section_data (s
)->this_idx
;
7488 BFD_ASSERT (indx
> 0);
7489 sym
.st_shndx
= indx
;
7491 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7492 (((Elf32_External_Sym
*)
7494 + elf_section_data (s
)->dynindx
));
7497 /* Set the sh_info field of the output .dynsym section to
7498 the index of the first global symbol. */
7499 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7500 bfd_count_sections (output_bfd
) + 1;
7504 if (SGI_COMPAT (output_bfd
))
7506 /* Write .compact_rel section out. */
7507 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
7511 cpt
.num
= s
->reloc_count
;
7513 cpt
.offset
= (s
->output_section
->filepos
7514 + sizeof (Elf32_External_compact_rel
));
7517 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
7518 ((Elf32_External_compact_rel
*)
7521 /* Clean up a dummy stub function entry in .text. */
7522 s
= bfd_get_section_by_name (dynobj
, ".stub");
7525 file_ptr dummy_offset
;
7527 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
7528 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
7529 memset (s
->contents
+ dummy_offset
, 0,
7530 MIPS_FUNCTION_STUB_SIZE
);
7535 /* Clean up a first relocation in .rel.dyn. */
7536 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7537 if (s
!= NULL
&& s
->_raw_size
> 0)
7538 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
7544 /* This is almost identical to bfd_generic_get_... except that some
7545 MIPS relocations need to be handled specially. Sigh. */
7548 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
7549 relocateable
, symbols
)
7551 struct bfd_link_info
*link_info
;
7552 struct bfd_link_order
*link_order
;
7554 boolean relocateable
;
7557 /* Get enough memory to hold the stuff */
7558 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
7559 asection
*input_section
= link_order
->u
.indirect
.section
;
7561 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
7562 arelent
**reloc_vector
= NULL
;
7568 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
7569 if (reloc_vector
== NULL
&& reloc_size
!= 0)
7572 /* read in the section */
7573 if (!bfd_get_section_contents (input_bfd
,
7577 input_section
->_raw_size
))
7580 /* We're not relaxing the section, so just copy the size info */
7581 input_section
->_cooked_size
= input_section
->_raw_size
;
7582 input_section
->reloc_done
= true;
7584 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
7588 if (reloc_count
< 0)
7591 if (reloc_count
> 0)
7596 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
7599 struct bfd_hash_entry
*h
;
7600 struct bfd_link_hash_entry
*lh
;
7601 /* Skip all this stuff if we aren't mixing formats. */
7602 if (abfd
&& input_bfd
7603 && abfd
->xvec
== input_bfd
->xvec
)
7607 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
7608 lh
= (struct bfd_link_hash_entry
*) h
;
7615 case bfd_link_hash_undefined
:
7616 case bfd_link_hash_undefweak
:
7617 case bfd_link_hash_common
:
7620 case bfd_link_hash_defined
:
7621 case bfd_link_hash_defweak
:
7623 gp
= lh
->u
.def
.value
;
7625 case bfd_link_hash_indirect
:
7626 case bfd_link_hash_warning
:
7628 /* @@FIXME ignoring warning for now */
7630 case bfd_link_hash_new
:
7639 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
7642 char *error_message
= (char *) NULL
;
7643 bfd_reloc_status_type r
;
7645 /* Specific to MIPS: Deal with relocation types that require
7646 knowing the gp of the output bfd. */
7647 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
7648 if (bfd_is_abs_section (sym
->section
) && abfd
)
7650 /* The special_function wouldn't get called anyways. */
7654 /* The gp isn't there; let the special function code
7655 fall over on its own. */
7657 else if ((*parent
)->howto
->special_function
7658 == _bfd_mips_elf_gprel16_reloc
)
7660 /* bypass special_function call */
7661 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
7662 relocateable
, (PTR
) data
, gp
);
7663 goto skip_bfd_perform_relocation
;
7665 /* end mips specific stuff */
7667 r
= bfd_perform_relocation (input_bfd
,
7671 relocateable
? abfd
: (bfd
*) NULL
,
7673 skip_bfd_perform_relocation
:
7677 asection
*os
= input_section
->output_section
;
7679 /* A partial link, so keep the relocs */
7680 os
->orelocation
[os
->reloc_count
] = *parent
;
7684 if (r
!= bfd_reloc_ok
)
7688 case bfd_reloc_undefined
:
7689 if (!((*link_info
->callbacks
->undefined_symbol
)
7690 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7691 input_bfd
, input_section
, (*parent
)->address
)))
7694 case bfd_reloc_dangerous
:
7695 BFD_ASSERT (error_message
!= (char *) NULL
);
7696 if (!((*link_info
->callbacks
->reloc_dangerous
)
7697 (link_info
, error_message
, input_bfd
, input_section
,
7698 (*parent
)->address
)))
7701 case bfd_reloc_overflow
:
7702 if (!((*link_info
->callbacks
->reloc_overflow
)
7703 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7704 (*parent
)->howto
->name
, (*parent
)->addend
,
7705 input_bfd
, input_section
, (*parent
)->address
)))
7708 case bfd_reloc_outofrange
:
7717 if (reloc_vector
!= NULL
)
7718 free (reloc_vector
);
7722 if (reloc_vector
!= NULL
)
7723 free (reloc_vector
);
7726 #define bfd_elf32_bfd_get_relocated_section_contents \
7727 elf32_mips_get_relocated_section_contents
7729 /* ECOFF swapping routines. These are used when dealing with the
7730 .mdebug section, which is in the ECOFF debugging format. */
7731 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
7733 /* Symbol table magic number. */
7735 /* Alignment of debugging information. E.g., 4. */
7737 /* Sizes of external symbolic information. */
7738 sizeof (struct hdr_ext
),
7739 sizeof (struct dnr_ext
),
7740 sizeof (struct pdr_ext
),
7741 sizeof (struct sym_ext
),
7742 sizeof (struct opt_ext
),
7743 sizeof (struct fdr_ext
),
7744 sizeof (struct rfd_ext
),
7745 sizeof (struct ext_ext
),
7746 /* Functions to swap in external symbolic data. */
7755 _bfd_ecoff_swap_tir_in
,
7756 _bfd_ecoff_swap_rndx_in
,
7757 /* Functions to swap out external symbolic data. */
7766 _bfd_ecoff_swap_tir_out
,
7767 _bfd_ecoff_swap_rndx_out
,
7768 /* Function to read in symbolic data. */
7769 _bfd_mips_elf_read_ecoff_info
7772 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
7773 #define TARGET_LITTLE_NAME "elf32-littlemips"
7774 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
7775 #define TARGET_BIG_NAME "elf32-bigmips"
7776 #define ELF_ARCH bfd_arch_mips
7777 #define ELF_MACHINE_CODE EM_MIPS
7779 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
7780 a value of 0x1000, and we are compatible. */
7781 #define ELF_MAXPAGESIZE 0x1000
7783 #define elf_backend_collect true
7784 #define elf_backend_type_change_ok true
7785 #define elf_backend_can_gc_sections true
7786 #define elf_info_to_howto 0
7787 #define elf_info_to_howto_rel mips_info_to_howto_rel
7788 #define elf_backend_sym_is_global mips_elf_sym_is_global
7789 #define elf_backend_object_p mips_elf32_object_p
7790 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
7791 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
7792 #define elf_backend_section_from_bfd_section \
7793 _bfd_mips_elf_section_from_bfd_section
7794 #define elf_backend_section_processing mips_elf32_section_processing
7795 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
7796 #define elf_backend_additional_program_headers \
7797 mips_elf_additional_program_headers
7798 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
7799 #define elf_backend_final_write_processing \
7800 _bfd_mips_elf_final_write_processing
7801 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
7803 #define bfd_elf32_bfd_is_local_label_name \
7804 mips_elf_is_local_label_name
7805 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
7806 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
7807 #define bfd_elf32_bfd_link_hash_table_create \
7808 mips_elf_link_hash_table_create
7809 #define bfd_elf32_bfd_final_link mips_elf_final_link
7810 #define bfd_elf32_bfd_copy_private_bfd_data \
7811 _bfd_mips_elf_copy_private_bfd_data
7812 #define bfd_elf32_bfd_merge_private_bfd_data \
7813 _bfd_mips_elf_merge_private_bfd_data
7814 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
7815 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
7816 #define elf_backend_create_dynamic_sections \
7817 mips_elf_create_dynamic_sections
7818 #define elf_backend_check_relocs mips_elf_check_relocs
7819 #define elf_backend_adjust_dynamic_symbol \
7820 mips_elf_adjust_dynamic_symbol
7821 #define elf_backend_always_size_sections \
7822 mips_elf_always_size_sections
7823 #define elf_backend_size_dynamic_sections \
7824 mips_elf_size_dynamic_sections
7825 #define elf_backend_relocate_section mips_elf_relocate_section
7826 #define elf_backend_link_output_symbol_hook \
7827 mips_elf_link_output_symbol_hook
7828 #define elf_backend_finish_dynamic_symbol \
7829 mips_elf_finish_dynamic_symbol
7830 #define elf_backend_finish_dynamic_sections \
7831 mips_elf_finish_dynamic_sections
7832 #define elf_backend_gc_mark_hook mips_elf_gc_mark_hook
7833 #define elf_backend_gc_sweep_hook mips_elf_gc_sweep_hook
7835 #include "elf32-target.h"