1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 94, 95, 96, 97, 98, 1999 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 mips_info_to_howto_rela
51 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rela
*));
52 static void bfd_mips_elf32_swap_gptab_in
53 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
54 static void bfd_mips_elf32_swap_gptab_out
55 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
56 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
57 static boolean mips_elf32_object_p
PARAMS ((bfd
*));
58 static boolean mips_elf_create_procedure_table
59 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
60 struct ecoff_debug_info
*));
61 static int mips_elf_additional_program_headers
PARAMS ((bfd
*));
62 static boolean mips_elf_modify_segment_map
PARAMS ((bfd
*));
63 static INLINE
int elf_mips_isa
PARAMS ((flagword
));
64 static INLINE
int elf_mips_mach
PARAMS ((flagword
));
65 static INLINE
char* elf_mips_abi_name
PARAMS ((flagword
));
66 static boolean mips_elf32_section_from_shdr
67 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, char *));
68 static boolean mips_elf32_section_processing
69 PARAMS ((bfd
*, Elf32_Internal_Shdr
*));
70 static boolean mips_elf_is_local_label_name
71 PARAMS ((bfd
*, const char *));
72 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
73 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
74 static struct bfd_link_hash_table
*mips_elf_link_hash_table_create
76 static int gptab_compare
PARAMS ((const void *, const void *));
77 static boolean mips_elf_final_link
78 PARAMS ((bfd
*, struct bfd_link_info
*));
79 static void mips_elf_relocate_hi16
80 PARAMS ((bfd
*, Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_byte
*,
82 static boolean mips_elf_relocate_got_local
83 PARAMS ((bfd
*, bfd
*, asection
*, Elf_Internal_Rela
*,
84 Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
85 static void mips_elf_relocate_global_got
86 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
87 static bfd_reloc_status_type mips16_jump_reloc
88 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
89 static bfd_reloc_status_type mips16_gprel_reloc
90 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
91 static boolean mips_elf_adjust_dynindx
92 PARAMS ((struct elf_link_hash_entry
*, PTR
));
93 static boolean mips_elf_relocate_section
94 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
95 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
96 static boolean mips_elf_link_output_symbol_hook
97 PARAMS ((bfd
*, struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
99 static boolean mips_elf_create_dynamic_sections
100 PARAMS ((bfd
*, struct bfd_link_info
*));
101 static boolean mips_elf_create_compact_rel_section
102 PARAMS ((bfd
*, struct bfd_link_info
*));
103 static boolean mips_elf_create_got_section
104 PARAMS ((bfd
*, struct bfd_link_info
*));
105 static boolean mips_elf_check_relocs
106 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
107 const Elf_Internal_Rela
*));
108 static boolean mips_elf_adjust_dynamic_symbol
109 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
110 static boolean mips_elf_always_size_sections
111 PARAMS ((bfd
*, struct bfd_link_info
*));
112 static boolean mips_elf_size_dynamic_sections
113 PARAMS ((bfd
*, struct bfd_link_info
*));
114 static boolean mips_elf_finish_dynamic_symbol
115 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
116 Elf_Internal_Sym
*));
117 static boolean mips_elf_finish_dynamic_sections
118 PARAMS ((bfd
*, struct bfd_link_info
*));
119 static boolean mips_elf_add_symbol_hook
120 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
121 const char **, flagword
*, asection
**, bfd_vma
*));
122 static bfd_reloc_status_type mips_elf_final_gp
123 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
124 static bfd_byte
*elf32_mips_get_relocated_section_contents
125 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
126 bfd_byte
*, boolean
, asymbol
**));
128 /* The level of IRIX compatibility we're striving for. */
136 /* Nonzero if ABFD is using the N32 ABI. */
138 #define ABI_N32_P(abfd) \
139 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
141 /* What version of Irix we are trying to be compatible with. FIXME:
142 At the moment, we never generate "normal" MIPS ELF ABI executables;
143 we always use some version of Irix. */
145 #define IRIX_COMPAT(abfd) \
146 (ABI_N32_P (abfd) ? ict_irix6 : ict_irix5)
148 /* Whether we are trying to be compatible with IRIX at all. */
150 #define SGI_COMPAT(abfd) \
151 (IRIX_COMPAT (abfd) != ict_none)
153 /* This structure is used to hold .got information when linking. It
154 is stored in the tdata field of the bfd_elf_section_data structure. */
158 /* The symbol index of the first global .got symbol. */
159 unsigned long global_gotsym
;
160 /* The number of local .got entries. */
161 unsigned int local_gotno
;
162 /* The number of local .got entries we have used. */
163 unsigned int assigned_gotno
;
166 /* The number of local .got entries we reserve. */
167 #define MIPS_RESERVED_GOTNO (2)
169 /* Instructions which appear in a stub. For some reason the stub is
170 slightly different on an SGI system. */
171 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
172 #define STUB_LW(abfd) \
174 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
175 : 0x8f998000) /* lw t9,0x8000(gp) */
176 #define STUB_MOVE 0x03e07825 /* move t7,ra */
177 #define STUB_JALR 0x0320f809 /* jal t9 */
178 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
179 #define MIPS_FUNCTION_STUB_SIZE (16)
182 /* We no longer try to identify particular sections for the .dynsym
183 section. When we do, we wind up crashing if there are other random
184 sections with relocations. */
186 /* Names of sections which appear in the .dynsym section in an Irix 5
189 static const char * const mips_elf_dynsym_sec_names
[] =
202 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
203 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
205 /* The number of entries in mips_elf_dynsym_sec_names which go in the
208 #define MIPS_TEXT_DYNSYM_SECNO (3)
212 /* The names of the runtime procedure table symbols used on Irix 5. */
214 static const char * const mips_elf_dynsym_rtproc_names
[] =
217 "_procedure_string_table",
218 "_procedure_table_size",
222 /* These structures are used to generate the .compact_rel section on
227 unsigned long id1
; /* Always one? */
228 unsigned long num
; /* Number of compact relocation entries. */
229 unsigned long id2
; /* Always two? */
230 unsigned long offset
; /* The file offset of the first relocation. */
231 unsigned long reserved0
; /* Zero? */
232 unsigned long reserved1
; /* Zero? */
241 bfd_byte reserved0
[4];
242 bfd_byte reserved1
[4];
243 } Elf32_External_compact_rel
;
247 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
248 unsigned int rtype
: 4; /* Relocation types. See below. */
249 unsigned int dist2to
: 8;
250 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
251 unsigned long konst
; /* KONST field. See below. */
252 unsigned long vaddr
; /* VADDR to be relocated. */
257 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
258 unsigned int rtype
: 4; /* Relocation types. See below. */
259 unsigned int dist2to
: 8;
260 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
261 unsigned long konst
; /* KONST field. See below. */
269 } Elf32_External_crinfo
;
275 } Elf32_External_crinfo2
;
277 /* These are the constants used to swap the bitfields in a crinfo. */
279 #define CRINFO_CTYPE (0x1)
280 #define CRINFO_CTYPE_SH (31)
281 #define CRINFO_RTYPE (0xf)
282 #define CRINFO_RTYPE_SH (27)
283 #define CRINFO_DIST2TO (0xff)
284 #define CRINFO_DIST2TO_SH (19)
285 #define CRINFO_RELVADDR (0x7ffff)
286 #define CRINFO_RELVADDR_SH (0)
288 /* A compact relocation info has long (3 words) or short (2 words)
289 formats. A short format doesn't have VADDR field and relvaddr
290 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
291 #define CRF_MIPS_LONG 1
292 #define CRF_MIPS_SHORT 0
294 /* There are 4 types of compact relocation at least. The value KONST
295 has different meaning for each type:
298 CT_MIPS_REL32 Address in data
299 CT_MIPS_WORD Address in word (XXX)
300 CT_MIPS_GPHI_LO GP - vaddr
301 CT_MIPS_JMPAD Address to jump
304 #define CRT_MIPS_REL32 0xa
305 #define CRT_MIPS_WORD 0xb
306 #define CRT_MIPS_GPHI_LO 0xc
307 #define CRT_MIPS_JMPAD 0xd
309 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
310 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
311 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
312 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
314 static void bfd_elf32_swap_compact_rel_out
315 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
316 static void bfd_elf32_swap_crinfo_out
317 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
319 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
321 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
322 from smaller values. Start with zero, widen, *then* decrement. */
323 #define MINUS_ONE (((bfd_vma)0) - 1)
325 static reloc_howto_type elf_mips_howto_table
[] =
328 HOWTO (R_MIPS_NONE
, /* type */
330 0, /* size (0 = byte, 1 = short, 2 = long) */
332 false, /* pc_relative */
334 complain_overflow_dont
, /* complain_on_overflow */
335 bfd_elf_generic_reloc
, /* special_function */
336 "R_MIPS_NONE", /* name */
337 false, /* partial_inplace */
340 false), /* pcrel_offset */
342 /* 16 bit relocation. */
343 HOWTO (R_MIPS_16
, /* type */
345 1, /* size (0 = byte, 1 = short, 2 = long) */
347 false, /* pc_relative */
349 complain_overflow_bitfield
, /* complain_on_overflow */
350 bfd_elf_generic_reloc
, /* special_function */
351 "R_MIPS_16", /* name */
352 true, /* partial_inplace */
353 0xffff, /* src_mask */
354 0xffff, /* dst_mask */
355 false), /* pcrel_offset */
357 /* 32 bit relocation. */
358 HOWTO (R_MIPS_32
, /* type */
360 2, /* size (0 = byte, 1 = short, 2 = long) */
362 false, /* pc_relative */
364 complain_overflow_bitfield
, /* complain_on_overflow */
365 bfd_elf_generic_reloc
, /* special_function */
366 "R_MIPS_32", /* name */
367 true, /* partial_inplace */
368 0xffffffff, /* src_mask */
369 0xffffffff, /* dst_mask */
370 false), /* pcrel_offset */
372 /* 32 bit symbol relative relocation. */
373 HOWTO (R_MIPS_REL32
, /* type */
375 2, /* size (0 = byte, 1 = short, 2 = long) */
377 false, /* pc_relative */
379 complain_overflow_bitfield
, /* complain_on_overflow */
380 bfd_elf_generic_reloc
, /* special_function */
381 "R_MIPS_REL32", /* name */
382 true, /* partial_inplace */
383 0xffffffff, /* src_mask */
384 0xffffffff, /* dst_mask */
385 false), /* pcrel_offset */
387 /* 26 bit branch address. */
388 HOWTO (R_MIPS_26
, /* type */
390 2, /* size (0 = byte, 1 = short, 2 = long) */
392 false, /* pc_relative */
394 complain_overflow_dont
, /* complain_on_overflow */
395 /* This needs complex overflow
396 detection, because the upper four
397 bits must match the PC. */
398 bfd_elf_generic_reloc
, /* special_function */
399 "R_MIPS_26", /* name */
400 true, /* partial_inplace */
401 0x3ffffff, /* src_mask */
402 0x3ffffff, /* dst_mask */
403 false), /* pcrel_offset */
405 /* High 16 bits of symbol value. */
406 HOWTO (R_MIPS_HI16
, /* type */
408 2, /* size (0 = byte, 1 = short, 2 = long) */
410 false, /* pc_relative */
412 complain_overflow_dont
, /* complain_on_overflow */
413 _bfd_mips_elf_hi16_reloc
, /* special_function */
414 "R_MIPS_HI16", /* name */
415 true, /* partial_inplace */
416 0xffff, /* src_mask */
417 0xffff, /* dst_mask */
418 false), /* pcrel_offset */
420 /* Low 16 bits of symbol value. */
421 HOWTO (R_MIPS_LO16
, /* type */
423 2, /* size (0 = byte, 1 = short, 2 = long) */
425 false, /* pc_relative */
427 complain_overflow_dont
, /* complain_on_overflow */
428 _bfd_mips_elf_lo16_reloc
, /* special_function */
429 "R_MIPS_LO16", /* name */
430 true, /* partial_inplace */
431 0xffff, /* src_mask */
432 0xffff, /* dst_mask */
433 false), /* pcrel_offset */
435 /* GP relative reference. */
436 HOWTO (R_MIPS_GPREL16
, /* type */
438 2, /* size (0 = byte, 1 = short, 2 = long) */
440 false, /* pc_relative */
442 complain_overflow_signed
, /* complain_on_overflow */
443 _bfd_mips_elf_gprel16_reloc
, /* special_function */
444 "R_MIPS_GPREL16", /* name */
445 true, /* partial_inplace */
446 0xffff, /* src_mask */
447 0xffff, /* dst_mask */
448 false), /* pcrel_offset */
450 /* Reference to literal section. */
451 HOWTO (R_MIPS_LITERAL
, /* type */
453 2, /* size (0 = byte, 1 = short, 2 = long) */
455 false, /* pc_relative */
457 complain_overflow_signed
, /* complain_on_overflow */
458 _bfd_mips_elf_gprel16_reloc
, /* special_function */
459 "R_MIPS_LITERAL", /* name */
460 true, /* partial_inplace */
461 0xffff, /* src_mask */
462 0xffff, /* dst_mask */
463 false), /* pcrel_offset */
465 /* Reference to global offset table. */
466 HOWTO (R_MIPS_GOT16
, /* type */
468 2, /* size (0 = byte, 1 = short, 2 = long) */
470 false, /* pc_relative */
472 complain_overflow_signed
, /* complain_on_overflow */
473 _bfd_mips_elf_got16_reloc
, /* special_function */
474 "R_MIPS_GOT16", /* name */
475 false, /* partial_inplace */
477 0xffff, /* dst_mask */
478 false), /* pcrel_offset */
480 /* 16 bit PC relative reference. */
481 HOWTO (R_MIPS_PC16
, /* type */
483 2, /* size (0 = byte, 1 = short, 2 = long) */
485 true, /* pc_relative */
487 complain_overflow_signed
, /* complain_on_overflow */
488 bfd_elf_generic_reloc
, /* special_function */
489 "R_MIPS_PC16", /* name */
490 true, /* partial_inplace */
491 0xffff, /* src_mask */
492 0xffff, /* dst_mask */
493 false), /* pcrel_offset */
495 /* 16 bit call through global offset table. */
496 /* FIXME: This is not handled correctly. */
497 HOWTO (R_MIPS_CALL16
, /* type */
499 2, /* size (0 = byte, 1 = short, 2 = long) */
501 false, /* pc_relative */
503 complain_overflow_signed
, /* complain_on_overflow */
504 bfd_elf_generic_reloc
, /* special_function */
505 "R_MIPS_CALL16", /* name */
506 false, /* partial_inplace */
508 0xffff, /* dst_mask */
509 false), /* pcrel_offset */
511 /* 32 bit GP relative reference. */
512 HOWTO (R_MIPS_GPREL32
, /* type */
514 2, /* size (0 = byte, 1 = short, 2 = long) */
516 false, /* pc_relative */
518 complain_overflow_bitfield
, /* complain_on_overflow */
519 _bfd_mips_elf_gprel32_reloc
, /* special_function */
520 "R_MIPS_GPREL32", /* name */
521 true, /* partial_inplace */
522 0xffffffff, /* src_mask */
523 0xffffffff, /* dst_mask */
524 false), /* pcrel_offset */
526 /* The remaining relocs are defined on Irix 5, although they are
527 not defined by the ABI. */
532 /* A 5 bit shift field. */
533 HOWTO (R_MIPS_SHIFT5
, /* type */
535 2, /* size (0 = byte, 1 = short, 2 = long) */
537 false, /* pc_relative */
539 complain_overflow_bitfield
, /* complain_on_overflow */
540 bfd_elf_generic_reloc
, /* special_function */
541 "R_MIPS_SHIFT5", /* name */
542 true, /* partial_inplace */
543 0x000007c0, /* src_mask */
544 0x000007c0, /* dst_mask */
545 false), /* pcrel_offset */
547 /* A 6 bit shift field. */
548 /* FIXME: This is not handled correctly; a special function is
549 needed to put the most significant bit in the right place. */
550 HOWTO (R_MIPS_SHIFT6
, /* type */
552 2, /* size (0 = byte, 1 = short, 2 = long) */
554 false, /* pc_relative */
556 complain_overflow_bitfield
, /* complain_on_overflow */
557 bfd_elf_generic_reloc
, /* special_function */
558 "R_MIPS_SHIFT6", /* name */
559 true, /* partial_inplace */
560 0x000007c4, /* src_mask */
561 0x000007c4, /* dst_mask */
562 false), /* pcrel_offset */
564 /* A 64 bit relocation. This is used in 32 bit ELF when addresses
565 are 64 bits long; the upper 32 bits are simply a sign extension.
566 The fields of the howto should be the same as for R_MIPS_32,
567 other than the type, name, and special_function. */
568 HOWTO (R_MIPS_64
, /* type */
570 2, /* size (0 = byte, 1 = short, 2 = long) */
572 false, /* pc_relative */
574 complain_overflow_bitfield
, /* complain_on_overflow */
575 mips32_64bit_reloc
, /* special_function */
576 "R_MIPS_64", /* name */
577 true, /* partial_inplace */
578 0xffffffff, /* src_mask */
579 0xffffffff, /* dst_mask */
580 false), /* pcrel_offset */
582 /* Displacement in the global offset table. */
583 /* FIXME: Not handled correctly. */
584 HOWTO (R_MIPS_GOT_DISP
, /* type */
586 2, /* size (0 = byte, 1 = short, 2 = long) */
588 false, /* pc_relative */
590 complain_overflow_bitfield
, /* complain_on_overflow */
591 bfd_elf_generic_reloc
, /* special_function */
592 "R_MIPS_GOT_DISP", /* name */
593 true, /* partial_inplace */
594 0x0000ffff, /* src_mask */
595 0x0000ffff, /* dst_mask */
596 false), /* pcrel_offset */
598 /* Displacement to page pointer in the global offset table. */
599 /* FIXME: Not handled correctly. */
600 HOWTO (R_MIPS_GOT_PAGE
, /* type */
602 2, /* size (0 = byte, 1 = short, 2 = long) */
604 false, /* pc_relative */
606 complain_overflow_bitfield
, /* complain_on_overflow */
607 bfd_elf_generic_reloc
, /* special_function */
608 "R_MIPS_GOT_PAGE", /* name */
609 true, /* partial_inplace */
610 0x0000ffff, /* src_mask */
611 0x0000ffff, /* dst_mask */
612 false), /* pcrel_offset */
614 /* Offset from page pointer in the global offset table. */
615 /* FIXME: Not handled correctly. */
616 HOWTO (R_MIPS_GOT_OFST
, /* type */
618 2, /* size (0 = byte, 1 = short, 2 = long) */
620 false, /* pc_relative */
622 complain_overflow_bitfield
, /* complain_on_overflow */
623 bfd_elf_generic_reloc
, /* special_function */
624 "R_MIPS_GOT_OFST", /* name */
625 true, /* partial_inplace */
626 0x0000ffff, /* src_mask */
627 0x0000ffff, /* dst_mask */
628 false), /* pcrel_offset */
630 /* High 16 bits of displacement in global offset table. */
631 /* FIXME: Not handled correctly. */
632 HOWTO (R_MIPS_GOT_HI16
, /* type */
634 2, /* size (0 = byte, 1 = short, 2 = long) */
636 false, /* pc_relative */
638 complain_overflow_dont
, /* complain_on_overflow */
639 bfd_elf_generic_reloc
, /* special_function */
640 "R_MIPS_GOT_HI16", /* name */
641 true, /* partial_inplace */
642 0x0000ffff, /* src_mask */
643 0x0000ffff, /* dst_mask */
644 false), /* pcrel_offset */
646 /* Low 16 bits of displacement in global offset table. */
647 /* FIXME: Not handled correctly. */
648 HOWTO (R_MIPS_GOT_LO16
, /* type */
650 2, /* size (0 = byte, 1 = short, 2 = long) */
652 false, /* pc_relative */
654 complain_overflow_dont
, /* complain_on_overflow */
655 bfd_elf_generic_reloc
, /* special_function */
656 "R_MIPS_GOT_LO16", /* name */
657 true, /* partial_inplace */
658 0x0000ffff, /* src_mask */
659 0x0000ffff, /* dst_mask */
660 false), /* pcrel_offset */
662 /* 64 bit subtraction. Used in the N32 ABI. */
663 /* FIXME: Not handled correctly. */
664 HOWTO (R_MIPS_SUB
, /* type */
666 4, /* size (0 = byte, 1 = short, 2 = long) */
668 false, /* pc_relative */
670 complain_overflow_bitfield
, /* complain_on_overflow */
671 bfd_elf_generic_reloc
, /* special_function */
672 "R_MIPS_SUB", /* name */
673 true, /* partial_inplace */
674 MINUS_ONE
, /* src_mask */
675 MINUS_ONE
, /* dst_mask */
676 false), /* pcrel_offset */
678 /* Used to cause the linker to insert and delete instructions? */
683 /* Get the higher values of a 64 bit addend. Presumably not used in
688 /* High 16 bits of displacement in global offset table. */
689 /* FIXME: Not handled correctly. */
690 HOWTO (R_MIPS_CALL_HI16
, /* type */
692 2, /* size (0 = byte, 1 = short, 2 = long) */
694 false, /* pc_relative */
696 complain_overflow_dont
, /* complain_on_overflow */
697 bfd_elf_generic_reloc
, /* special_function */
698 "R_MIPS_CALL_HI16", /* name */
699 true, /* partial_inplace */
700 0x0000ffff, /* src_mask */
701 0x0000ffff, /* dst_mask */
702 false), /* pcrel_offset */
704 /* Low 16 bits of displacement in global offset table. */
705 /* FIXME: Not handled correctly. */
706 HOWTO (R_MIPS_CALL_LO16
, /* type */
708 2, /* size (0 = byte, 1 = short, 2 = long) */
710 false, /* pc_relative */
712 complain_overflow_dont
, /* complain_on_overflow */
713 bfd_elf_generic_reloc
, /* special_function */
714 "R_MIPS_CALL_LO16", /* name */
715 true, /* partial_inplace */
716 0x0000ffff, /* src_mask */
717 0x0000ffff, /* dst_mask */
718 false), /* pcrel_offset */
722 { R_MIPS_ADD_IMMEDIATE
},
726 /* Protected jump conversion. This is an optimization hint. No
727 relocation is required for correctness. */
728 HOWTO (R_MIPS_JALR
, /* type */
730 0, /* size (0 = byte, 1 = short, 2 = long) */
732 false, /* pc_relative */
734 complain_overflow_dont
, /* complain_on_overflow */
735 bfd_elf_generic_reloc
, /* special_function */
736 "R_MIPS_JALR", /* name */
737 false, /* partial_inplace */
738 0x00000000, /* src_mask */
739 0x00000000, /* dst_mask */
740 false), /* pcrel_offset */
743 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
744 is a hack to make the linker think that we need 64 bit values. */
745 static reloc_howto_type elf_mips_ctor64_howto
=
746 HOWTO (R_MIPS_64
, /* type */
748 4, /* size (0 = byte, 1 = short, 2 = long) */
750 false, /* pc_relative */
752 complain_overflow_signed
, /* complain_on_overflow */
753 mips32_64bit_reloc
, /* special_function */
754 "R_MIPS_64", /* name */
755 true, /* partial_inplace */
756 0xffffffff, /* src_mask */
757 0xffffffff, /* dst_mask */
758 false); /* pcrel_offset */
760 /* The reloc used for the mips16 jump instruction. */
761 static reloc_howto_type elf_mips16_jump_howto
=
762 HOWTO (R_MIPS16_26
, /* type */
764 2, /* size (0 = byte, 1 = short, 2 = long) */
766 false, /* pc_relative */
768 complain_overflow_dont
, /* complain_on_overflow */
769 /* This needs complex overflow
770 detection, because the upper four
771 bits must match the PC. */
772 mips16_jump_reloc
, /* special_function */
773 "R_MIPS16_26", /* name */
774 true, /* partial_inplace */
775 0x3ffffff, /* src_mask */
776 0x3ffffff, /* dst_mask */
777 false); /* pcrel_offset */
779 /* The reloc used for the mips16 gprel instruction. The src_mask and
780 dsk_mask for this howto do not reflect the actual instruction, in
781 which the value is not contiguous; the masks are for the
782 convenience of the relocate_section routine. */
783 static reloc_howto_type elf_mips16_gprel_howto
=
784 HOWTO (R_MIPS16_GPREL
, /* type */
786 2, /* size (0 = byte, 1 = short, 2 = long) */
788 false, /* pc_relative */
790 complain_overflow_signed
, /* complain_on_overflow */
791 mips16_gprel_reloc
, /* special_function */
792 "R_MIPS16_GPREL", /* name */
793 true, /* partial_inplace */
794 0xffff, /* src_mask */
795 0xffff, /* dst_mask */
796 false); /* pcrel_offset */
799 /* GNU extension to record C++ vtable hierarchy */
800 static reloc_howto_type elf_mips_gnu_vtinherit_howto
=
801 HOWTO (R_MIPS_GNU_VTINHERIT
, /* type */
803 2, /* size (0 = byte, 1 = short, 2 = long) */
805 false, /* pc_relative */
807 complain_overflow_dont
, /* complain_on_overflow */
808 NULL
, /* special_function */
809 "R_MIPS_GNU_VTINHERIT", /* name */
810 false, /* partial_inplace */
813 false); /* pcrel_offset */
815 /* GNU extension to record C++ vtable member usage */
816 static reloc_howto_type elf_mips_gnu_vtentry_howto
=
817 HOWTO (R_MIPS_GNU_VTENTRY
, /* type */
819 2, /* size (0 = byte, 1 = short, 2 = long) */
821 false, /* pc_relative */
823 complain_overflow_dont
, /* complain_on_overflow */
824 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
825 "R_MIPS_GNU_VTENTRY", /* name */
826 false, /* partial_inplace */
829 false); /* pcrel_offset */
831 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
832 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
833 the HI16. Here we just save the information we need; we do the
834 actual relocation when we see the LO16. MIPS ELF requires that the
835 LO16 immediately follow the HI16. As a GNU extension, we permit an
836 arbitrary number of HI16 relocs to be associated with a single LO16
837 reloc. This extension permits gcc to output the HI and LO relocs
842 struct mips_hi16
*next
;
847 /* FIXME: This should not be a static variable. */
849 static struct mips_hi16
*mips_hi16_list
;
851 bfd_reloc_status_type
852 _bfd_mips_elf_hi16_reloc (abfd
,
860 arelent
*reloc_entry
;
863 asection
*input_section
;
865 char **error_message
;
867 bfd_reloc_status_type ret
;
871 /* If we're relocating, and this an external symbol, we don't want
872 to change anything. */
873 if (output_bfd
!= (bfd
*) NULL
874 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
875 && reloc_entry
->addend
== 0)
877 reloc_entry
->address
+= input_section
->output_offset
;
883 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
885 boolean relocateable
;
888 if (ret
== bfd_reloc_undefined
)
891 if (output_bfd
!= NULL
)
895 relocateable
= false;
896 output_bfd
= symbol
->section
->output_section
->owner
;
899 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
901 if (ret
!= bfd_reloc_ok
)
904 relocation
= gp
- reloc_entry
->address
;
908 if (bfd_is_und_section (symbol
->section
)
909 && output_bfd
== (bfd
*) NULL
)
910 ret
= bfd_reloc_undefined
;
912 if (bfd_is_com_section (symbol
->section
))
915 relocation
= symbol
->value
;
918 relocation
+= symbol
->section
->output_section
->vma
;
919 relocation
+= symbol
->section
->output_offset
;
920 relocation
+= reloc_entry
->addend
;
922 if (reloc_entry
->address
> input_section
->_cooked_size
)
923 return bfd_reloc_outofrange
;
925 /* Save the information, and let LO16 do the actual relocation. */
926 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
928 return bfd_reloc_outofrange
;
929 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
930 n
->addend
= relocation
;
931 n
->next
= mips_hi16_list
;
934 if (output_bfd
!= (bfd
*) NULL
)
935 reloc_entry
->address
+= input_section
->output_offset
;
940 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
941 inplace relocation; this function exists in order to do the
942 R_MIPS_HI16 relocation described above. */
944 bfd_reloc_status_type
945 _bfd_mips_elf_lo16_reloc (abfd
,
953 arelent
*reloc_entry
;
956 asection
*input_section
;
958 char **error_message
;
960 arelent gp_disp_relent
;
962 if (mips_hi16_list
!= NULL
)
972 struct mips_hi16
*next
;
974 /* Do the HI16 relocation. Note that we actually don't need
975 to know anything about the LO16 itself, except where to
976 find the low 16 bits of the addend needed by the LO16. */
977 insn
= bfd_get_32 (abfd
, l
->addr
);
978 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
980 val
= ((insn
& 0xffff) << 16) + vallo
;
983 /* The low order 16 bits are always treated as a signed
984 value. Therefore, a negative value in the low order bits
985 requires an adjustment in the high order bits. We need
986 to make this adjustment in two ways: once for the bits we
987 took from the data, and once for the bits we are putting
988 back in to the data. */
989 if ((vallo
& 0x8000) != 0)
991 if ((val
& 0x8000) != 0)
994 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
995 bfd_put_32 (abfd
, insn
, l
->addr
);
997 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
999 gp_disp_relent
= *reloc_entry
;
1000 reloc_entry
= &gp_disp_relent
;
1001 reloc_entry
->addend
= l
->addend
;
1009 mips_hi16_list
= NULL
;
1011 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1013 bfd_reloc_status_type ret
;
1014 bfd_vma gp
, relocation
;
1016 /* FIXME: Does this case ever occur? */
1018 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
1019 if (ret
!= bfd_reloc_ok
)
1022 relocation
= gp
- reloc_entry
->address
;
1023 relocation
+= symbol
->section
->output_section
->vma
;
1024 relocation
+= symbol
->section
->output_offset
;
1025 relocation
+= reloc_entry
->addend
;
1027 if (reloc_entry
->address
> input_section
->_cooked_size
)
1028 return bfd_reloc_outofrange
;
1030 gp_disp_relent
= *reloc_entry
;
1031 reloc_entry
= &gp_disp_relent
;
1032 reloc_entry
->addend
= relocation
- 4;
1035 /* Now do the LO16 reloc in the usual way. */
1036 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1037 input_section
, output_bfd
, error_message
);
1040 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1041 table used for PIC code. If the symbol is an external symbol, the
1042 instruction is modified to contain the offset of the appropriate
1043 entry in the global offset table. If the symbol is a section
1044 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1045 addends are combined to form the real addend against the section
1046 symbol; the GOT16 is modified to contain the offset of an entry in
1047 the global offset table, and the LO16 is modified to offset it
1048 appropriately. Thus an offset larger than 16 bits requires a
1049 modified value in the global offset table.
1051 This implementation suffices for the assembler, but the linker does
1052 not yet know how to create global offset tables. */
1054 bfd_reloc_status_type
1055 _bfd_mips_elf_got16_reloc (abfd
,
1063 arelent
*reloc_entry
;
1066 asection
*input_section
;
1068 char **error_message
;
1070 /* If we're relocating, and this an external symbol, we don't want
1071 to change anything. */
1072 if (output_bfd
!= (bfd
*) NULL
1073 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1074 && reloc_entry
->addend
== 0)
1076 reloc_entry
->address
+= input_section
->output_offset
;
1077 return bfd_reloc_ok
;
1080 /* If we're relocating, and this is a local symbol, we can handle it
1082 if (output_bfd
!= (bfd
*) NULL
1083 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1084 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1085 input_section
, output_bfd
, error_message
);
1090 /* We have to figure out the gp value, so that we can adjust the
1091 symbol value correctly. We look up the symbol _gp in the output
1092 BFD. If we can't find it, we're stuck. We cache it in the ELF
1093 target data. We don't need to adjust the symbol value for an
1094 external symbol if we are producing relocateable output. */
1096 static bfd_reloc_status_type
1097 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1100 boolean relocateable
;
1101 char **error_message
;
1104 if (bfd_is_und_section (symbol
->section
)
1108 return bfd_reloc_undefined
;
1111 *pgp
= _bfd_get_gp_value (output_bfd
);
1114 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1118 /* Make up a value. */
1119 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1120 _bfd_set_gp_value (output_bfd
, *pgp
);
1128 count
= bfd_get_symcount (output_bfd
);
1129 sym
= bfd_get_outsymbols (output_bfd
);
1131 if (sym
== (asymbol
**) NULL
)
1135 for (i
= 0; i
< count
; i
++, sym
++)
1137 register CONST
char *name
;
1139 name
= bfd_asymbol_name (*sym
);
1140 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1142 *pgp
= bfd_asymbol_value (*sym
);
1143 _bfd_set_gp_value (output_bfd
, *pgp
);
1151 /* Only get the error once. */
1153 _bfd_set_gp_value (output_bfd
, *pgp
);
1155 (char *) _("GP relative relocation when _gp not defined");
1156 return bfd_reloc_dangerous
;
1161 return bfd_reloc_ok
;
1164 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1165 become the offset from the gp register. This function also handles
1166 R_MIPS_LITERAL relocations, although those can be handled more
1167 cleverly because the entries in the .lit8 and .lit4 sections can be
1170 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1171 arelent
*, asection
*,
1172 boolean
, PTR
, bfd_vma
));
1174 bfd_reloc_status_type
1175 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1176 output_bfd
, error_message
)
1178 arelent
*reloc_entry
;
1181 asection
*input_section
;
1183 char **error_message
;
1185 boolean relocateable
;
1186 bfd_reloc_status_type ret
;
1189 /* If we're relocating, and this is an external symbol with no
1190 addend, we don't want to change anything. We will only have an
1191 addend if this is a newly created reloc, not read from an ELF
1193 if (output_bfd
!= (bfd
*) NULL
1194 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1195 && reloc_entry
->addend
== 0)
1197 reloc_entry
->address
+= input_section
->output_offset
;
1198 return bfd_reloc_ok
;
1201 if (output_bfd
!= (bfd
*) NULL
)
1202 relocateable
= true;
1205 relocateable
= false;
1206 output_bfd
= symbol
->section
->output_section
->owner
;
1209 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1211 if (ret
!= bfd_reloc_ok
)
1214 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1215 relocateable
, data
, gp
);
1218 static bfd_reloc_status_type
1219 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1223 arelent
*reloc_entry
;
1224 asection
*input_section
;
1225 boolean relocateable
;
1233 if (bfd_is_com_section (symbol
->section
))
1236 relocation
= symbol
->value
;
1238 relocation
+= symbol
->section
->output_section
->vma
;
1239 relocation
+= symbol
->section
->output_offset
;
1241 if (reloc_entry
->address
> input_section
->_cooked_size
)
1242 return bfd_reloc_outofrange
;
1244 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1246 /* Set val to the offset into the section or symbol. */
1247 if (reloc_entry
->howto
->src_mask
== 0)
1249 /* This case occurs with the 64-bit MIPS ELF ABI. */
1250 val
= reloc_entry
->addend
;
1254 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1259 /* Adjust val for the final section location and GP value. If we
1260 are producing relocateable output, we don't want to do this for
1261 an external symbol. */
1263 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1264 val
+= relocation
- gp
;
1266 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1267 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1270 reloc_entry
->address
+= input_section
->output_offset
;
1272 /* Make sure it fit in 16 bits. */
1273 if (val
>= 0x8000 && val
< 0xffff8000)
1274 return bfd_reloc_overflow
;
1276 return bfd_reloc_ok
;
1279 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1280 from the gp register? XXX */
1282 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1283 arelent
*, asection
*,
1284 boolean
, PTR
, bfd_vma
));
1286 bfd_reloc_status_type
1287 _bfd_mips_elf_gprel32_reloc (abfd
,
1295 arelent
*reloc_entry
;
1298 asection
*input_section
;
1300 char **error_message
;
1302 boolean relocateable
;
1303 bfd_reloc_status_type ret
;
1306 /* If we're relocating, and this is an external symbol with no
1307 addend, we don't want to change anything. We will only have an
1308 addend if this is a newly created reloc, not read from an ELF
1310 if (output_bfd
!= (bfd
*) NULL
1311 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1312 && reloc_entry
->addend
== 0)
1314 *error_message
= (char *)
1315 _("32bits gp relative relocation occurs for an external symbol");
1316 return bfd_reloc_outofrange
;
1319 if (output_bfd
!= (bfd
*) NULL
)
1321 relocateable
= true;
1322 gp
= _bfd_get_gp_value (output_bfd
);
1326 relocateable
= false;
1327 output_bfd
= symbol
->section
->output_section
->owner
;
1329 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1330 error_message
, &gp
);
1331 if (ret
!= bfd_reloc_ok
)
1335 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1336 relocateable
, data
, gp
);
1339 static bfd_reloc_status_type
1340 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1344 arelent
*reloc_entry
;
1345 asection
*input_section
;
1346 boolean relocateable
;
1353 if (bfd_is_com_section (symbol
->section
))
1356 relocation
= symbol
->value
;
1358 relocation
+= symbol
->section
->output_section
->vma
;
1359 relocation
+= symbol
->section
->output_offset
;
1361 if (reloc_entry
->address
> input_section
->_cooked_size
)
1362 return bfd_reloc_outofrange
;
1364 if (reloc_entry
->howto
->src_mask
== 0)
1366 /* This case arises with the 64-bit MIPS ELF ABI. */
1370 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1372 /* Set val to the offset into the section or symbol. */
1373 val
+= reloc_entry
->addend
;
1375 /* Adjust val for the final section location and GP value. If we
1376 are producing relocateable output, we don't want to do this for
1377 an external symbol. */
1379 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1380 val
+= relocation
- gp
;
1382 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1385 reloc_entry
->address
+= input_section
->output_offset
;
1387 return bfd_reloc_ok
;
1390 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1391 generated when addreses are 64 bits. The upper 32 bits are a simle
1394 static bfd_reloc_status_type
1395 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1396 output_bfd
, error_message
)
1398 arelent
*reloc_entry
;
1401 asection
*input_section
;
1403 char **error_message
;
1405 bfd_reloc_status_type r
;
1410 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1411 input_section
, output_bfd
, error_message
);
1412 if (r
!= bfd_reloc_continue
)
1415 /* Do a normal 32 bit relocation on the lower 32 bits. */
1416 reloc32
= *reloc_entry
;
1417 if (bfd_big_endian (abfd
))
1418 reloc32
.address
+= 4;
1419 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1420 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1421 output_bfd
, error_message
);
1423 /* Sign extend into the upper 32 bits. */
1424 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1425 if ((val
& 0x80000000) != 0)
1429 addr
= reloc_entry
->address
;
1430 if (bfd_little_endian (abfd
))
1432 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1437 /* Handle a mips16 jump. */
1439 static bfd_reloc_status_type
1440 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1441 output_bfd
, error_message
)
1443 arelent
*reloc_entry
;
1446 asection
*input_section
;
1448 char **error_message
;
1450 if (output_bfd
!= (bfd
*) NULL
1451 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1452 && reloc_entry
->addend
== 0)
1454 reloc_entry
->address
+= input_section
->output_offset
;
1455 return bfd_reloc_ok
;
1460 static boolean warned
;
1463 (*_bfd_error_handler
)
1464 (_("Linking mips16 objects into %s format is not supported"),
1465 bfd_get_target (input_section
->output_section
->owner
));
1469 return bfd_reloc_undefined
;
1472 /* Handle a mips16 GP relative reloc. */
1474 static bfd_reloc_status_type
1475 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1476 output_bfd
, error_message
)
1478 arelent
*reloc_entry
;
1481 asection
*input_section
;
1483 char **error_message
;
1485 boolean relocateable
;
1486 bfd_reloc_status_type ret
;
1488 unsigned short extend
, insn
;
1489 unsigned long final
;
1491 /* If we're relocating, and this is an external symbol with no
1492 addend, we don't want to change anything. We will only have an
1493 addend if this is a newly created reloc, not read from an ELF
1495 if (output_bfd
!= NULL
1496 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1497 && reloc_entry
->addend
== 0)
1499 reloc_entry
->address
+= input_section
->output_offset
;
1500 return bfd_reloc_ok
;
1503 if (output_bfd
!= NULL
)
1504 relocateable
= true;
1507 relocateable
= false;
1508 output_bfd
= symbol
->section
->output_section
->owner
;
1511 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1513 if (ret
!= bfd_reloc_ok
)
1516 if (reloc_entry
->address
> input_section
->_cooked_size
)
1517 return bfd_reloc_outofrange
;
1519 /* Pick up the mips16 extend instruction and the real instruction. */
1520 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1521 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1523 /* Stuff the current addend back as a 32 bit value, do the usual
1524 relocation, and then clean up. */
1526 (((extend
& 0x1f) << 11)
1529 (bfd_byte
*) data
+ reloc_entry
->address
);
1531 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1532 relocateable
, data
, gp
);
1534 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1537 | ((final
>> 11) & 0x1f)
1539 (bfd_byte
*) data
+ reloc_entry
->address
);
1543 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1548 /* Return the ISA for a MIPS e_flags value. */
1551 elf_mips_isa (flags
)
1554 switch (flags
& EF_MIPS_ARCH
)
1568 /* Return the MACH for a MIPS e_flags value. */
1571 elf_mips_mach (flags
)
1574 switch (flags
& EF_MIPS_MACH
)
1576 case E_MIPS_MACH_3900
:
1577 return bfd_mach_mips3900
;
1579 case E_MIPS_MACH_4010
:
1580 return bfd_mach_mips4010
;
1582 case E_MIPS_MACH_4100
:
1583 return bfd_mach_mips4100
;
1585 case E_MIPS_MACH_4111
:
1586 return bfd_mach_mips4111
;
1588 case E_MIPS_MACH_4650
:
1589 return bfd_mach_mips4650
;
1592 switch (flags
& EF_MIPS_ARCH
)
1596 return bfd_mach_mips3000
;
1600 return bfd_mach_mips6000
;
1604 return bfd_mach_mips4000
;
1608 return bfd_mach_mips8000
;
1616 /* Return printable name for ABI from flagword. */
1619 elf_mips_abi_name (flags
)
1622 switch (flags
& EF_MIPS_ABI
)
1626 case E_MIPS_ABI_O32
:
1628 case E_MIPS_ABI_O64
:
1630 case E_MIPS_ABI_EABI32
:
1632 case E_MIPS_ABI_EABI64
:
1635 return "unknown abi";
1639 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1641 struct elf_reloc_map
{
1642 bfd_reloc_code_real_type bfd_reloc_val
;
1643 enum elf_mips_reloc_type elf_reloc_val
;
1646 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1648 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1649 { BFD_RELOC_16
, R_MIPS_16
},
1650 { BFD_RELOC_32
, R_MIPS_32
},
1651 { BFD_RELOC_64
, R_MIPS_64
},
1652 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1653 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1654 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1655 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1656 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1657 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1658 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1659 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1660 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1661 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1662 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1663 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1664 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
},
1665 { BFD_RELOC_MIPS_SUB
, R_MIPS_SUB
},
1666 { BFD_RELOC_MIPS_GOT_PAGE
, R_MIPS_GOT_PAGE
},
1667 { BFD_RELOC_MIPS_GOT_OFST
, R_MIPS_GOT_OFST
},
1668 { BFD_RELOC_MIPS_GOT_DISP
, R_MIPS_GOT_DISP
}
1671 /* Given a BFD reloc type, return a howto structure. */
1673 static reloc_howto_type
*
1674 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1676 bfd_reloc_code_real_type code
;
1680 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1682 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1683 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1689 bfd_set_error (bfd_error_bad_value
);
1692 case BFD_RELOC_CTOR
:
1693 /* We need to handle BFD_RELOC_CTOR specially.
1694 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1695 size of addresses on this architecture. */
1696 if (bfd_arch_bits_per_address (abfd
) == 32)
1697 return &elf_mips_howto_table
[(int) R_MIPS_32
];
1699 return &elf_mips_ctor64_howto
;
1701 case BFD_RELOC_MIPS16_JMP
:
1702 return &elf_mips16_jump_howto
;
1703 case BFD_RELOC_MIPS16_GPREL
:
1704 return &elf_mips16_gprel_howto
;
1705 case BFD_RELOC_VTABLE_INHERIT
:
1706 return &elf_mips_gnu_vtinherit_howto
;
1707 case BFD_RELOC_VTABLE_ENTRY
:
1708 return &elf_mips_gnu_vtentry_howto
;
1712 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
1715 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1718 Elf32_Internal_Rel
*dst
;
1720 unsigned int r_type
;
1722 r_type
= ELF32_R_TYPE (dst
->r_info
);
1726 cache_ptr
->howto
= &elf_mips16_jump_howto
;
1728 case R_MIPS16_GPREL
:
1729 cache_ptr
->howto
= &elf_mips16_gprel_howto
;
1731 case R_MIPS_GNU_VTINHERIT
:
1732 cache_ptr
->howto
= &elf_mips_gnu_vtinherit_howto
;
1734 case R_MIPS_GNU_VTENTRY
:
1735 cache_ptr
->howto
= &elf_mips_gnu_vtentry_howto
;
1739 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1740 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1744 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1745 value for the object file. We get the addend now, rather than
1746 when we do the relocation, because the symbol manipulations done
1747 by the linker may cause us to lose track of the input BFD. */
1748 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1749 && (r_type
== (unsigned int) R_MIPS_GPREL16
1750 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1751 cache_ptr
->addend
= elf_gp (abfd
);
1754 /* Given a MIPS Elf32_Internal_Rela, fill in an arelent structure. */
1757 mips_info_to_howto_rela (abfd
, cache_ptr
, dst
)
1760 Elf32_Internal_Rela
*dst
;
1762 /* Since an Elf32_Internal_Rel is an initial prefix of an
1763 Elf32_Internal_Rela, we can just use mips_info_to_howto_rel
1765 mips_info_to_howto_rel (abfd
, cache_ptr
, (Elf32_Internal_Rel
*) dst
);
1767 /* If we ever need to do any extra processing with dst->r_addend
1768 (the field omitted in an Elf32_Internal_Rel) we can do it here. */
1771 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1772 routines swap this structure in and out. They are used outside of
1773 BFD, so they are globally visible. */
1776 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1778 const Elf32_External_RegInfo
*ex
;
1781 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1782 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1783 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1784 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1785 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1786 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1790 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1792 const Elf32_RegInfo
*in
;
1793 Elf32_External_RegInfo
*ex
;
1795 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1796 (bfd_byte
*) ex
->ri_gprmask
);
1797 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1798 (bfd_byte
*) ex
->ri_cprmask
[0]);
1799 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1800 (bfd_byte
*) ex
->ri_cprmask
[1]);
1801 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1802 (bfd_byte
*) ex
->ri_cprmask
[2]);
1803 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1804 (bfd_byte
*) ex
->ri_cprmask
[3]);
1805 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1806 (bfd_byte
*) ex
->ri_gp_value
);
1809 /* In the 64 bit ABI, the .MIPS.options section holds register
1810 information in an Elf64_Reginfo structure. These routines swap
1811 them in and out. They are globally visible because they are used
1812 outside of BFD. These routines are here so that gas can call them
1813 without worrying about whether the 64 bit ABI has been included. */
1816 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1818 const Elf64_External_RegInfo
*ex
;
1819 Elf64_Internal_RegInfo
*in
;
1821 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1822 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
1823 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1824 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1825 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1826 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1827 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1831 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1833 const Elf64_Internal_RegInfo
*in
;
1834 Elf64_External_RegInfo
*ex
;
1836 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1837 (bfd_byte
*) ex
->ri_gprmask
);
1838 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
1839 (bfd_byte
*) ex
->ri_pad
);
1840 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1841 (bfd_byte
*) ex
->ri_cprmask
[0]);
1842 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1843 (bfd_byte
*) ex
->ri_cprmask
[1]);
1844 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1845 (bfd_byte
*) ex
->ri_cprmask
[2]);
1846 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1847 (bfd_byte
*) ex
->ri_cprmask
[3]);
1848 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1849 (bfd_byte
*) ex
->ri_gp_value
);
1852 /* Swap an entry in a .gptab section. Note that these routines rely
1853 on the equivalence of the two elements of the union. */
1856 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1858 const Elf32_External_gptab
*ex
;
1861 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1862 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1866 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1868 const Elf32_gptab
*in
;
1869 Elf32_External_gptab
*ex
;
1871 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1872 ex
->gt_entry
.gt_g_value
);
1873 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1874 ex
->gt_entry
.gt_bytes
);
1878 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1880 const Elf32_compact_rel
*in
;
1881 Elf32_External_compact_rel
*ex
;
1883 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
1884 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
1885 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
1886 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
1887 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
1888 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
1892 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1894 const Elf32_crinfo
*in
;
1895 Elf32_External_crinfo
*ex
;
1899 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1900 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1901 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1902 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1903 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
1904 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
1905 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
1908 /* Swap in an options header. */
1911 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1913 const Elf_External_Options
*ex
;
1914 Elf_Internal_Options
*in
;
1916 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
1917 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
1918 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
1919 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
1922 /* Swap out an options header. */
1925 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
1927 const Elf_Internal_Options
*in
;
1928 Elf_External_Options
*ex
;
1930 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
1931 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
1932 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
1933 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
1936 /* Determine whether a symbol is global for the purposes of splitting
1937 the symbol table into global symbols and local symbols. At least
1938 on Irix 5, this split must be between section symbols and all other
1939 symbols. On most ELF targets the split is between static symbols
1940 and externally visible symbols. */
1944 mips_elf_sym_is_global (abfd
, sym
)
1948 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
1951 /* Set the right machine number for a MIPS ELF file. This is used for
1952 both the 32-bit and the 64-bit ABI. */
1955 _bfd_mips_elf_object_p (abfd
)
1958 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
,
1959 elf_mips_mach (elf_elfheader (abfd
)->e_flags
));
1963 /* Set the right machine number for a 32-bit MIPS ELF file. */
1966 mips_elf32_object_p (abfd
)
1969 /* Irix 5 is broken. Object file symbol tables are not always
1970 sorted correctly such that local symbols precede global symbols,
1971 and the sh_info field in the symbol table is not always right. */
1972 elf_bad_symtab (abfd
) = true;
1974 return _bfd_mips_elf_object_p (abfd
);
1977 /* The final processing done just before writing out a MIPS ELF object
1978 file. This gets the MIPS architecture right based on the machine
1979 number. This is used by both the 32-bit and the 64-bit ABI. */
1983 _bfd_mips_elf_final_write_processing (abfd
, linker
)
1989 Elf_Internal_Shdr
**hdrpp
;
1993 switch (bfd_get_mach (abfd
))
1996 case bfd_mach_mips3000
:
1997 val
= E_MIPS_ARCH_1
;
2000 case bfd_mach_mips3900
:
2001 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
2004 case bfd_mach_mips6000
:
2005 val
= E_MIPS_ARCH_2
;
2008 case bfd_mach_mips4000
:
2009 case bfd_mach_mips4300
:
2010 val
= E_MIPS_ARCH_3
;
2013 case bfd_mach_mips4010
:
2014 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
2017 case bfd_mach_mips4100
:
2018 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
2021 case bfd_mach_mips4111
:
2022 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
2025 case bfd_mach_mips4650
:
2026 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
2029 case bfd_mach_mips8000
:
2030 val
= E_MIPS_ARCH_4
;
2034 elf_elfheader (abfd
)->e_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2035 elf_elfheader (abfd
)->e_flags
|= val
;
2037 /* Set the sh_info field for .gptab sections and other appropriate
2038 info for each special section. */
2039 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
2040 i
< elf_elfheader (abfd
)->e_shnum
;
2043 switch ((*hdrpp
)->sh_type
)
2045 case SHT_MIPS_LIBLIST
:
2046 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
2048 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2051 case SHT_MIPS_GPTAB
:
2052 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2053 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2054 BFD_ASSERT (name
!= NULL
2055 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
2056 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
2057 BFD_ASSERT (sec
!= NULL
);
2058 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2061 case SHT_MIPS_CONTENT
:
2062 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2063 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2064 BFD_ASSERT (name
!= NULL
2065 && strncmp (name
, ".MIPS.content",
2066 sizeof ".MIPS.content" - 1) == 0);
2067 sec
= bfd_get_section_by_name (abfd
,
2068 name
+ sizeof ".MIPS.content" - 1);
2069 BFD_ASSERT (sec
!= NULL
);
2070 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2073 case SHT_MIPS_SYMBOL_LIB
:
2074 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
2076 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2077 sec
= bfd_get_section_by_name (abfd
, ".liblist");
2079 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2082 case SHT_MIPS_EVENTS
:
2083 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2084 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2085 BFD_ASSERT (name
!= NULL
);
2086 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
2087 sec
= bfd_get_section_by_name (abfd
,
2088 name
+ sizeof ".MIPS.events" - 1);
2091 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
2092 sizeof ".MIPS.post_rel" - 1) == 0);
2093 sec
= bfd_get_section_by_name (abfd
,
2095 + sizeof ".MIPS.post_rel" - 1));
2097 BFD_ASSERT (sec
!= NULL
);
2098 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2105 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
2108 _bfd_mips_elf_set_private_flags (abfd
, flags
)
2112 BFD_ASSERT (!elf_flags_init (abfd
)
2113 || elf_elfheader (abfd
)->e_flags
== flags
);
2115 elf_elfheader (abfd
)->e_flags
= flags
;
2116 elf_flags_init (abfd
) = true;
2120 /* Copy backend specific data from one object module to another */
2123 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
2127 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2128 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2131 BFD_ASSERT (!elf_flags_init (obfd
)
2132 || (elf_elfheader (obfd
)->e_flags
2133 == elf_elfheader (ibfd
)->e_flags
));
2135 elf_gp (obfd
) = elf_gp (ibfd
);
2136 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
2137 elf_flags_init (obfd
) = true;
2141 /* Merge backend specific data from an object file to the output
2142 object file when linking. */
2145 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
2153 /* Check if we have the same endianess */
2154 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2155 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2159 if (bfd_big_endian (ibfd
))
2160 msg
= _("%s: compiled for a big endian system and target is little endian");
2162 msg
= _("%s: compiled for a little endian system and target is big endian");
2164 (*_bfd_error_handler
) (msg
, bfd_get_filename (ibfd
));
2166 bfd_set_error (bfd_error_wrong_format
);
2170 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2171 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2174 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2175 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
2176 old_flags
= elf_elfheader (obfd
)->e_flags
;
2178 if (! elf_flags_init (obfd
))
2180 elf_flags_init (obfd
) = true;
2181 elf_elfheader (obfd
)->e_flags
= new_flags
;
2183 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2184 && bfd_get_arch_info (obfd
)->the_default
)
2186 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
2187 bfd_get_mach (ibfd
)))
2194 /* Check flag compatibility. */
2196 new_flags
&= ~EF_MIPS_NOREORDER
;
2197 old_flags
&= ~EF_MIPS_NOREORDER
;
2199 if (new_flags
== old_flags
)
2204 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
2206 new_flags
&= ~EF_MIPS_PIC
;
2207 old_flags
&= ~EF_MIPS_PIC
;
2208 (*_bfd_error_handler
)
2209 (_("%s: linking PIC files with non-PIC files"),
2210 bfd_get_filename (ibfd
));
2214 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
2216 new_flags
&= ~EF_MIPS_CPIC
;
2217 old_flags
&= ~EF_MIPS_CPIC
;
2218 (*_bfd_error_handler
)
2219 (_("%s: linking abicalls files with non-abicalls files"),
2220 bfd_get_filename (ibfd
));
2224 /* Compare the ISA's. */
2225 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
2226 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
2228 int new_mach
= new_flags
& EF_MIPS_MACH
;
2229 int old_mach
= old_flags
& EF_MIPS_MACH
;
2230 int new_isa
= elf_mips_isa (new_flags
);
2231 int old_isa
= elf_mips_isa (old_flags
);
2233 /* If either has no machine specified, just compare the general isa's.
2234 Some combinations of machines are ok, if the isa's match. */
2237 || new_mach
== old_mach
2240 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
2241 and -mips4 code. They will normally use the same data sizes and
2242 calling conventions. */
2244 if ((new_isa
== 1 || new_isa
== 2)
2245 ? (old_isa
!= 1 && old_isa
!= 2)
2246 : (old_isa
== 1 || old_isa
== 2))
2248 (*_bfd_error_handler
)
2249 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
2250 bfd_get_filename (ibfd
), new_isa
, old_isa
);
2257 (*_bfd_error_handler
)
2258 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
2259 bfd_get_filename (ibfd
),
2260 elf_mips_mach (new_flags
),
2261 elf_mips_mach (old_flags
));
2265 new_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2266 old_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2270 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
))
2272 /* Only error if both are set (to different values). */
2273 if ((new_flags
& EF_MIPS_ABI
)
2274 && (old_flags
& EF_MIPS_ABI
))
2276 (*_bfd_error_handler
)
2277 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
2278 bfd_get_filename (ibfd
),
2279 elf_mips_abi_name (new_flags
),
2280 elf_mips_abi_name (old_flags
));
2283 new_flags
&= ~EF_MIPS_ABI
;
2284 old_flags
&= ~EF_MIPS_ABI
;
2287 /* Warn about any other mismatches */
2288 if (new_flags
!= old_flags
)
2290 (*_bfd_error_handler
)
2291 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2292 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
2293 (unsigned long) old_flags
);
2299 bfd_set_error (bfd_error_bad_value
);
2307 _bfd_mips_elf_print_private_bfd_data (abfd
, ptr
)
2311 FILE *file
= (FILE *) ptr
;
2313 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
2315 /* Print normal ELF private data. */
2316 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
2318 /* xgettext:c-format */
2319 fprintf (file
, _ ("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
2321 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
2322 fprintf (file
, _ (" [abi=O32]"));
2323 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
2324 fprintf (file
, _ (" [abi=O64]"));
2325 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
2326 fprintf (file
, _ (" [abi=EABI32]"));
2327 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
2328 fprintf (file
, _ (" [abi=EABI64]"));
2329 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
2330 fprintf (file
, _ (" [abi unknown]"));
2331 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI2
))
2332 fprintf (file
, _ (" [abi=N32]"));
2334 fprintf (file
, _ (" [no abi set]"));
2336 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
2337 fprintf (file
, _ (" [mips1]"));
2338 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
2339 fprintf (file
, _ (" [mips2]"));
2340 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
2341 fprintf (file
, _ (" [mips3]"));
2342 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
2343 fprintf (file
, _ (" [mips4]"));
2345 fprintf (file
, _ (" [unknown ISA]"));
2347 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
2348 fprintf (file
, _ (" [32bitmode]"));
2350 fprintf (file
, _ (" [not 32bitmode]"));
2357 /* Handle a MIPS specific section when reading an object file. This
2358 is called when elfcode.h finds a section with an unknown type.
2359 This routine supports both the 32-bit and 64-bit ELF ABI.
2361 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2365 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
2367 Elf_Internal_Shdr
*hdr
;
2372 /* There ought to be a place to keep ELF backend specific flags, but
2373 at the moment there isn't one. We just keep track of the
2374 sections by their name, instead. Fortunately, the ABI gives
2375 suggested names for all the MIPS specific sections, so we will
2376 probably get away with this. */
2377 switch (hdr
->sh_type
)
2379 case SHT_MIPS_LIBLIST
:
2380 if (strcmp (name
, ".liblist") != 0)
2384 if (strcmp (name
, ".msym") != 0)
2387 case SHT_MIPS_CONFLICT
:
2388 if (strcmp (name
, ".conflict") != 0)
2391 case SHT_MIPS_GPTAB
:
2392 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
2395 case SHT_MIPS_UCODE
:
2396 if (strcmp (name
, ".ucode") != 0)
2399 case SHT_MIPS_DEBUG
:
2400 if (strcmp (name
, ".mdebug") != 0)
2402 flags
= SEC_DEBUGGING
;
2404 case SHT_MIPS_REGINFO
:
2405 if (strcmp (name
, ".reginfo") != 0
2406 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
2408 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
2410 case SHT_MIPS_IFACE
:
2411 if (strcmp (name
, ".MIPS.interfaces") != 0)
2414 case SHT_MIPS_CONTENT
:
2415 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2418 case SHT_MIPS_OPTIONS
:
2419 if (strcmp (name
, ".options") != 0
2420 && strcmp (name
, ".MIPS.options") != 0)
2423 case SHT_MIPS_DWARF
:
2424 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2427 case SHT_MIPS_SYMBOL_LIB
:
2428 if (strcmp (name
, ".MIPS.symlib") != 0)
2431 case SHT_MIPS_EVENTS
:
2432 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2433 && strncmp (name
, ".MIPS.post_rel",
2434 sizeof ".MIPS.post_rel" - 1) != 0)
2441 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2446 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
2447 (bfd_get_section_flags (abfd
,
2456 /* Handle a 32-bit MIPS ELF specific section. */
2459 mips_elf32_section_from_shdr (abfd
, hdr
, name
)
2461 Elf_Internal_Shdr
*hdr
;
2464 if (! _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
))
2467 /* FIXME: We should record sh_info for a .gptab section. */
2469 /* For a .reginfo section, set the gp value in the tdata information
2470 from the contents of this section. We need the gp value while
2471 processing relocs, so we just get it now. The .reginfo section
2472 is not used in the 64-bit MIPS ELF ABI. */
2473 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2475 Elf32_External_RegInfo ext
;
2478 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
2479 (file_ptr
) 0, sizeof ext
))
2481 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
2482 elf_gp (abfd
) = s
.ri_gp_value
;
2485 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2486 set the gp value based on what we find. We may see both
2487 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2488 they should agree. */
2489 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
2491 bfd_byte
*contents
, *l
, *lend
;
2493 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
2494 if (contents
== NULL
)
2496 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
2497 (file_ptr
) 0, hdr
->sh_size
))
2503 lend
= contents
+ hdr
->sh_size
;
2504 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2506 Elf_Internal_Options intopt
;
2508 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2510 if (intopt
.kind
== ODK_REGINFO
)
2512 Elf32_RegInfo intreg
;
2514 bfd_mips_elf32_swap_reginfo_in
2516 ((Elf32_External_RegInfo
*)
2517 (l
+ sizeof (Elf_External_Options
))),
2519 elf_gp (abfd
) = intreg
.ri_gp_value
;
2529 /* Set the correct type for a MIPS ELF section. We do this by the
2530 section name, which is a hack, but ought to work. This routine is
2531 used by both the 32-bit and the 64-bit ABI. */
2534 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
2536 Elf32_Internal_Shdr
*hdr
;
2539 register const char *name
;
2541 name
= bfd_get_section_name (abfd
, sec
);
2543 if (strcmp (name
, ".liblist") == 0)
2545 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
2546 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
2547 /* The sh_link field is set in final_write_processing. */
2549 else if (strcmp (name
, ".msym") == 0)
2551 hdr
->sh_type
= SHT_MIPS_MSYM
;
2552 hdr
->sh_entsize
= 8;
2553 /* FIXME: Set the sh_info field. */
2555 else if (strcmp (name
, ".conflict") == 0)
2556 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
2557 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2559 hdr
->sh_type
= SHT_MIPS_GPTAB
;
2560 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
2561 /* The sh_info field is set in final_write_processing. */
2563 else if (strcmp (name
, ".ucode") == 0)
2564 hdr
->sh_type
= SHT_MIPS_UCODE
;
2565 else if (strcmp (name
, ".mdebug") == 0)
2567 hdr
->sh_type
= SHT_MIPS_DEBUG
;
2568 /* In a shared object on Irix 5.3, the .mdebug section has an
2569 entsize of 0. FIXME: Does this matter? */
2570 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2571 hdr
->sh_entsize
= 0;
2573 hdr
->sh_entsize
= 1;
2575 else if (strcmp (name
, ".reginfo") == 0)
2577 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2578 /* In a shared object on Irix 5.3, the .reginfo section has an
2579 entsize of 0x18. FIXME: Does this matter? */
2580 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2581 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2583 hdr
->sh_entsize
= 1;
2585 else if (SGI_COMPAT (abfd
)
2586 && (strcmp (name
, ".hash") == 0
2587 || strcmp (name
, ".dynamic") == 0
2588 || strcmp (name
, ".dynstr") == 0))
2590 hdr
->sh_entsize
= 0;
2592 /* This isn't how the Irix 6 linker behaves. */
2593 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2596 else if (strcmp (name
, ".got") == 0
2597 || strcmp (name
, ".sdata") == 0
2598 || strcmp (name
, ".sbss") == 0
2599 || strcmp (name
, ".lit4") == 0
2600 || strcmp (name
, ".lit8") == 0)
2601 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2602 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2604 hdr
->sh_type
= SHT_MIPS_IFACE
;
2605 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2607 else if (strncmp (name
, ".MIPS.content", strlen (".MIPS.content")) == 0)
2609 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2610 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2611 /* The sh_info field is set in final_write_processing. */
2613 else if (strcmp (name
, ".options") == 0
2614 || strcmp (name
, ".MIPS.options") == 0)
2616 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2617 hdr
->sh_entsize
= 1;
2618 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2620 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2621 hdr
->sh_type
= SHT_MIPS_DWARF
;
2622 else if (strcmp (name
, ".MIPS.symlib") == 0)
2624 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2625 /* The sh_link and sh_info fields are set in
2626 final_write_processing. */
2628 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2629 || strncmp (name
, ".MIPS.post_rel",
2630 sizeof ".MIPS.post_rel" - 1) == 0)
2632 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2633 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2634 /* The sh_link field is set in final_write_processing. */
2640 /* Given a BFD section, try to locate the corresponding ELF section
2641 index. This is used by both the 32-bit and the 64-bit ABI.
2642 Actually, it's not clear to me that the 64-bit ABI supports these,
2643 but for non-PIC objects we will certainly want support for at least
2644 the .scommon section. */
2647 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2649 Elf32_Internal_Shdr
*hdr
;
2653 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2655 *retval
= SHN_MIPS_SCOMMON
;
2658 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2660 *retval
= SHN_MIPS_ACOMMON
;
2666 /* When are writing out the .options or .MIPS.options section,
2667 remember the bytes we are writing out, so that we can install the
2668 GP value in the section_processing routine. */
2671 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2676 bfd_size_type count
;
2678 if (strcmp (section
->name
, ".options") == 0
2679 || strcmp (section
->name
, ".MIPS.options") == 0)
2683 if (elf_section_data (section
) == NULL
)
2685 section
->used_by_bfd
=
2686 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
2687 if (elf_section_data (section
) == NULL
)
2690 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
2695 if (section
->_cooked_size
!= 0)
2696 size
= section
->_cooked_size
;
2698 size
= section
->_raw_size
;
2699 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
2702 elf_section_data (section
)->tdata
= (PTR
) c
;
2705 memcpy (c
+ offset
, location
, count
);
2708 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
2712 /* Work over a section just before writing it out. This routine is
2713 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2714 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2718 _bfd_mips_elf_section_processing (abfd
, hdr
)
2720 Elf_Internal_Shdr
*hdr
;
2722 if (hdr
->bfd_section
!= NULL
)
2724 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
2726 if (strcmp (name
, ".sdata") == 0)
2728 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2729 hdr
->sh_type
= SHT_PROGBITS
;
2731 else if (strcmp (name
, ".sbss") == 0)
2733 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2734 hdr
->sh_type
= SHT_NOBITS
;
2736 else if (strcmp (name
, ".lit8") == 0
2737 || strcmp (name
, ".lit4") == 0)
2739 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2740 hdr
->sh_type
= SHT_PROGBITS
;
2742 else if (strcmp (name
, ".compact_rel") == 0)
2745 hdr
->sh_type
= SHT_PROGBITS
;
2747 else if (strcmp (name
, ".rtproc") == 0)
2749 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
2751 unsigned int adjust
;
2753 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
2755 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
2763 /* Work over a section just before writing it out. We update the GP
2764 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2765 on the value we are using. */
2768 mips_elf32_section_processing (abfd
, hdr
)
2770 Elf32_Internal_Shdr
*hdr
;
2772 if (hdr
->sh_type
== SHT_MIPS_REGINFO
2773 && hdr
->sh_size
> 0)
2777 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2778 BFD_ASSERT (hdr
->contents
== NULL
);
2781 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2784 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2785 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2789 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2790 && hdr
->bfd_section
!= NULL
2791 && elf_section_data (hdr
->bfd_section
) != NULL
2792 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2794 bfd_byte
*contents
, *l
, *lend
;
2796 /* We stored the section contents in the elf_section_data tdata
2797 field in the set_section_contents routine. We save the
2798 section contents so that we don't have to read them again.
2799 At this point we know that elf_gp is set, so we can look
2800 through the section contents to see if there is an
2801 ODK_REGINFO structure. */
2803 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2805 lend
= contents
+ hdr
->sh_size
;
2806 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2808 Elf_Internal_Options intopt
;
2810 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2812 if (intopt
.kind
== ODK_REGINFO
)
2819 + sizeof (Elf_External_Options
)
2820 + (sizeof (Elf32_External_RegInfo
) - 4)),
2823 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
2824 if (bfd_write (buf
, 1, 4, abfd
) != 4)
2831 return _bfd_mips_elf_section_processing (abfd
, hdr
);
2834 /* MIPS ELF uses two common sections. One is the usual one, and the
2835 other is for small objects. All the small objects are kept
2836 together, and then referenced via the gp pointer, which yields
2837 faster assembler code. This is what we use for the small common
2838 section. This approach is copied from ecoff.c. */
2839 static asection mips_elf_scom_section
;
2840 static asymbol mips_elf_scom_symbol
;
2841 static asymbol
*mips_elf_scom_symbol_ptr
;
2843 /* MIPS ELF also uses an acommon section, which represents an
2844 allocated common symbol which may be overridden by a
2845 definition in a shared library. */
2846 static asection mips_elf_acom_section
;
2847 static asymbol mips_elf_acom_symbol
;
2848 static asymbol
*mips_elf_acom_symbol_ptr
;
2850 /* The Irix 5 support uses two virtual sections, which represent
2851 text/data symbols defined in dynamic objects. */
2852 static asection mips_elf_text_section
;
2853 static asection
*mips_elf_text_section_ptr
;
2854 static asymbol mips_elf_text_symbol
;
2855 static asymbol
*mips_elf_text_symbol_ptr
;
2857 static asection mips_elf_data_section
;
2858 static asection
*mips_elf_data_section_ptr
;
2859 static asymbol mips_elf_data_symbol
;
2860 static asymbol
*mips_elf_data_symbol_ptr
;
2862 /* Handle the special MIPS section numbers that a symbol may use.
2863 This is used for both the 32-bit and the 64-bit ABI. */
2866 _bfd_mips_elf_symbol_processing (abfd
, asym
)
2870 elf_symbol_type
*elfsym
;
2872 elfsym
= (elf_symbol_type
*) asym
;
2873 switch (elfsym
->internal_elf_sym
.st_shndx
)
2875 case SHN_MIPS_ACOMMON
:
2876 /* This section is used in a dynamically linked executable file.
2877 It is an allocated common section. The dynamic linker can
2878 either resolve these symbols to something in a shared
2879 library, or it can just leave them here. For our purposes,
2880 we can consider these symbols to be in a new section. */
2881 if (mips_elf_acom_section
.name
== NULL
)
2883 /* Initialize the acommon section. */
2884 mips_elf_acom_section
.name
= ".acommon";
2885 mips_elf_acom_section
.flags
= SEC_ALLOC
;
2886 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
2887 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
2888 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
2889 mips_elf_acom_symbol
.name
= ".acommon";
2890 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
2891 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
2892 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
2894 asym
->section
= &mips_elf_acom_section
;
2898 /* Common symbols less than the GP size are automatically
2899 treated as SHN_MIPS_SCOMMON symbols. */
2900 if (asym
->value
> elf_gp_size (abfd
))
2903 case SHN_MIPS_SCOMMON
:
2904 if (mips_elf_scom_section
.name
== NULL
)
2906 /* Initialize the small common section. */
2907 mips_elf_scom_section
.name
= ".scommon";
2908 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
2909 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
2910 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
2911 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
2912 mips_elf_scom_symbol
.name
= ".scommon";
2913 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2914 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
2915 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
2917 asym
->section
= &mips_elf_scom_section
;
2918 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2921 case SHN_MIPS_SUNDEFINED
:
2922 asym
->section
= bfd_und_section_ptr
;
2925 #if 0 /* for SGI_COMPAT */
2927 asym
->section
= mips_elf_text_section_ptr
;
2931 asym
->section
= mips_elf_data_section_ptr
;
2937 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
2941 mips_elf_additional_program_headers (abfd
)
2949 if (! SGI_COMPAT (abfd
))
2952 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2953 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2955 /* We need a PT_MIPS_REGINFO segment. */
2959 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2960 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2962 /* We need a PT_MIPS_RTPROC segment. */
2969 /* Modify the segment map for an Irix 5 executable. */
2972 mips_elf_modify_segment_map (abfd
)
2976 struct elf_segment_map
*m
, **pm
;
2978 if (! SGI_COMPAT (abfd
))
2981 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
2983 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2984 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2986 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2987 if (m
->p_type
== PT_MIPS_REGINFO
)
2991 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2995 m
->p_type
= PT_MIPS_REGINFO
;
2999 /* We want to put it after the PHDR and INTERP segments. */
3000 pm
= &elf_tdata (abfd
)->segment_map
;
3002 && ((*pm
)->p_type
== PT_PHDR
3003 || (*pm
)->p_type
== PT_INTERP
))
3011 /* If there are .dynamic and .mdebug sections, we make a room for
3012 the RTPROC header. FIXME: Rewrite without section names. */
3013 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
3014 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3015 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3017 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3018 if (m
->p_type
== PT_MIPS_RTPROC
)
3022 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3026 m
->p_type
= PT_MIPS_RTPROC
;
3028 s
= bfd_get_section_by_name (abfd
, ".rtproc");
3033 m
->p_flags_valid
= 1;
3041 /* We want to put it after the DYNAMIC segment. */
3042 pm
= &elf_tdata (abfd
)->segment_map
;
3043 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
3053 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
3054 .dynsym, and .hash sections, and everything in between. */
3055 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
3056 if ((*pm
)->p_type
== PT_DYNAMIC
)
3061 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
3063 static const char *sec_names
[] =
3064 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
3067 struct elf_segment_map
*n
;
3071 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
3073 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
3074 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3080 sz
= s
->_cooked_size
;
3083 if (high
< s
->vma
+ sz
)
3089 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
))
3097 n
= ((struct elf_segment_map
*)
3098 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
3105 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3107 if ((s
->flags
& SEC_LOAD
) != 0
3110 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3124 /* The structure of the runtime procedure descriptor created by the
3125 loader for use by the static exception system. */
3127 typedef struct runtime_pdr
{
3128 bfd_vma adr
; /* memory address of start of procedure */
3129 long regmask
; /* save register mask */
3130 long regoffset
; /* save register offset */
3131 long fregmask
; /* save floating point register mask */
3132 long fregoffset
; /* save floating point register offset */
3133 long frameoffset
; /* frame size */
3134 short framereg
; /* frame pointer register */
3135 short pcreg
; /* offset or reg of return pc */
3136 long irpss
; /* index into the runtime string table */
3138 struct exception_info
*exception_info
;/* pointer to exception array */
3140 #define cbRPDR sizeof(RPDR)
3141 #define rpdNil ((pRPDR) 0)
3143 /* Swap RPDR (runtime procedure table entry) for output. */
3145 static void ecoff_swap_rpdr_out
3146 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
3149 ecoff_swap_rpdr_out (abfd
, in
, ex
)
3152 struct rpdr_ext
*ex
;
3154 /* ecoff_put_off was defined in ecoffswap.h. */
3155 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
3156 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
3157 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
3158 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
3159 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
3160 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
3162 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
3163 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
3165 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
3167 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
3171 /* Read ECOFF debugging information from a .mdebug section into a
3172 ecoff_debug_info structure. */
3175 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
3178 struct ecoff_debug_info
*debug
;
3181 const struct ecoff_debug_swap
*swap
;
3182 char *ext_hdr
= NULL
;
3184 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3185 memset (debug
, 0, sizeof(*debug
));
3187 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
3188 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
3191 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
3192 swap
->external_hdr_size
)
3196 symhdr
= &debug
->symbolic_header
;
3197 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
3199 /* The symbolic header contains absolute file offsets and sizes to
3201 #define READ(ptr, offset, count, size, type) \
3202 if (symhdr->count == 0) \
3203 debug->ptr = NULL; \
3206 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
3207 if (debug->ptr == NULL) \
3208 goto error_return; \
3209 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3210 || (bfd_read (debug->ptr, size, symhdr->count, \
3211 abfd) != size * symhdr->count)) \
3212 goto error_return; \
3215 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
3216 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
3217 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
3218 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
3219 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
3220 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
3222 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
3223 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
3224 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
3225 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
3226 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
3230 debug
->adjust
= NULL
;
3235 if (ext_hdr
!= NULL
)
3237 if (debug
->line
!= NULL
)
3239 if (debug
->external_dnr
!= NULL
)
3240 free (debug
->external_dnr
);
3241 if (debug
->external_pdr
!= NULL
)
3242 free (debug
->external_pdr
);
3243 if (debug
->external_sym
!= NULL
)
3244 free (debug
->external_sym
);
3245 if (debug
->external_opt
!= NULL
)
3246 free (debug
->external_opt
);
3247 if (debug
->external_aux
!= NULL
)
3248 free (debug
->external_aux
);
3249 if (debug
->ss
!= NULL
)
3251 if (debug
->ssext
!= NULL
)
3252 free (debug
->ssext
);
3253 if (debug
->external_fdr
!= NULL
)
3254 free (debug
->external_fdr
);
3255 if (debug
->external_rfd
!= NULL
)
3256 free (debug
->external_rfd
);
3257 if (debug
->external_ext
!= NULL
)
3258 free (debug
->external_ext
);
3262 /* MIPS ELF local labels start with '$', not 'L'. */
3266 mips_elf_is_local_label_name (abfd
, name
)
3273 /* On Irix 6, the labels go back to starting with '.', so we accept
3274 the generic ELF local label syntax as well. */
3275 return _bfd_elf_is_local_label_name (abfd
, name
);
3278 /* MIPS ELF uses a special find_nearest_line routine in order the
3279 handle the ECOFF debugging information. */
3281 struct mips_elf_find_line
3283 struct ecoff_debug_info d
;
3284 struct ecoff_find_line i
;
3288 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
3289 functionname_ptr
, line_ptr
)
3294 const char **filename_ptr
;
3295 const char **functionname_ptr
;
3296 unsigned int *line_ptr
;
3300 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
3301 filename_ptr
, functionname_ptr
,
3305 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3306 filename_ptr
, functionname_ptr
,
3310 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
3314 struct mips_elf_find_line
*fi
;
3315 const struct ecoff_debug_swap
* const swap
=
3316 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3318 /* If we are called during a link, mips_elf_final_link may have
3319 cleared the SEC_HAS_CONTENTS field. We force it back on here
3320 if appropriate (which it normally will be). */
3321 origflags
= msec
->flags
;
3322 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
3323 msec
->flags
|= SEC_HAS_CONTENTS
;
3325 fi
= elf_tdata (abfd
)->find_line_info
;
3328 bfd_size_type external_fdr_size
;
3331 struct fdr
*fdr_ptr
;
3333 fi
= ((struct mips_elf_find_line
*)
3334 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
3337 msec
->flags
= origflags
;
3341 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
3343 msec
->flags
= origflags
;
3347 /* Swap in the FDR information. */
3348 fi
->d
.fdr
= ((struct fdr
*)
3350 (fi
->d
.symbolic_header
.ifdMax
*
3351 sizeof (struct fdr
))));
3352 if (fi
->d
.fdr
== NULL
)
3354 msec
->flags
= origflags
;
3357 external_fdr_size
= swap
->external_fdr_size
;
3358 fdr_ptr
= fi
->d
.fdr
;
3359 fraw_src
= (char *) fi
->d
.external_fdr
;
3360 fraw_end
= (fraw_src
3361 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
3362 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
3363 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
3365 elf_tdata (abfd
)->find_line_info
= fi
;
3367 /* Note that we don't bother to ever free this information.
3368 find_nearest_line is either called all the time, as in
3369 objdump -l, so the information should be saved, or it is
3370 rarely called, as in ld error messages, so the memory
3371 wasted is unimportant. Still, it would probably be a
3372 good idea for free_cached_info to throw it away. */
3375 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
3376 &fi
->i
, filename_ptr
, functionname_ptr
,
3379 msec
->flags
= origflags
;
3383 msec
->flags
= origflags
;
3386 /* Fall back on the generic ELF find_nearest_line routine. */
3388 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
3389 filename_ptr
, functionname_ptr
,
3393 /* The mips16 compiler uses a couple of special sections to handle
3394 floating point arguments.
3396 Section names that look like .mips16.fn.FNNAME contain stubs that
3397 copy floating point arguments from the fp regs to the gp regs and
3398 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3399 call should be redirected to the stub instead. If no 32 bit
3400 function calls FNNAME, the stub should be discarded. We need to
3401 consider any reference to the function, not just a call, because
3402 if the address of the function is taken we will need the stub,
3403 since the address might be passed to a 32 bit function.
3405 Section names that look like .mips16.call.FNNAME contain stubs
3406 that copy floating point arguments from the gp regs to the fp
3407 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3408 then any 16 bit function that calls FNNAME should be redirected
3409 to the stub instead. If FNNAME is not a 32 bit function, the
3410 stub should be discarded.
3412 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3413 which call FNNAME and then copy the return value from the fp regs
3414 to the gp regs. These stubs store the return value in $18 while
3415 calling FNNAME; any function which might call one of these stubs
3416 must arrange to save $18 around the call. (This case is not
3417 needed for 32 bit functions that call 16 bit functions, because
3418 16 bit functions always return floating point values in both
3421 Note that in all cases FNNAME might be defined statically.
3422 Therefore, FNNAME is not used literally. Instead, the relocation
3423 information will indicate which symbol the section is for.
3425 We record any stubs that we find in the symbol table. */
3427 #define FN_STUB ".mips16.fn."
3428 #define CALL_STUB ".mips16.call."
3429 #define CALL_FP_STUB ".mips16.call.fp."
3431 /* The MIPS ELF linker needs additional information for each symbol in
3432 the global hash table. */
3434 struct mips_elf_link_hash_entry
3436 struct elf_link_hash_entry root
;
3438 /* External symbol information. */
3441 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
3442 unsigned int mips_32_relocs
;
3444 /* If there is a stub that 32 bit functions should use to call this
3445 16 bit function, this points to the section containing the stub. */
3448 /* Whether we need the fn_stub; this is set if this symbol appears
3449 in any relocs other than a 16 bit call. */
3450 boolean need_fn_stub
;
3452 /* If there is a stub that 16 bit functions should use to call this
3453 32 bit function, this points to the section containing the stub. */
3454 asection
*call_stub
;
3456 /* This is like the call_stub field, but it is used if the function
3457 being called returns a floating point value. */
3458 asection
*call_fp_stub
;
3461 /* MIPS ELF linker hash table. */
3463 struct mips_elf_link_hash_table
3465 struct elf_link_hash_table root
;
3467 /* We no longer use this. */
3468 /* String section indices for the dynamic section symbols. */
3469 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
3471 /* The number of .rtproc entries. */
3472 bfd_size_type procedure_count
;
3473 /* The size of the .compact_rel section (if SGI_COMPAT). */
3474 bfd_size_type compact_rel_size
;
3475 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3476 entry is set to the address of __rld_obj_head as in Irix 5. */
3477 boolean use_rld_obj_head
;
3478 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3480 /* This is set if we see any mips16 stub sections. */
3481 boolean mips16_stubs_seen
;
3484 /* Look up an entry in a MIPS ELF linker hash table. */
3486 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3487 ((struct mips_elf_link_hash_entry *) \
3488 elf_link_hash_lookup (&(table)->root, (string), (create), \
3491 /* Traverse a MIPS ELF linker hash table. */
3493 #define mips_elf_link_hash_traverse(table, func, info) \
3494 (elf_link_hash_traverse \
3496 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3499 /* Get the MIPS ELF linker hash table from a link_info structure. */
3501 #define mips_elf_hash_table(p) \
3502 ((struct mips_elf_link_hash_table *) ((p)->hash))
3504 static boolean mips_elf_output_extsym
3505 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3507 /* Create an entry in a MIPS ELF linker hash table. */
3509 static struct bfd_hash_entry
*
3510 mips_elf_link_hash_newfunc (entry
, table
, string
)
3511 struct bfd_hash_entry
*entry
;
3512 struct bfd_hash_table
*table
;
3515 struct mips_elf_link_hash_entry
*ret
=
3516 (struct mips_elf_link_hash_entry
*) entry
;
3518 /* Allocate the structure if it has not already been allocated by a
3520 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3521 ret
= ((struct mips_elf_link_hash_entry
*)
3522 bfd_hash_allocate (table
,
3523 sizeof (struct mips_elf_link_hash_entry
)));
3524 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3525 return (struct bfd_hash_entry
*) ret
;
3527 /* Call the allocation method of the superclass. */
3528 ret
= ((struct mips_elf_link_hash_entry
*)
3529 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3531 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3533 /* Set local fields. */
3534 memset (&ret
->esym
, 0, sizeof (EXTR
));
3535 /* We use -2 as a marker to indicate that the information has
3536 not been set. -1 means there is no associated ifd. */
3538 ret
->mips_32_relocs
= 0;
3539 ret
->fn_stub
= NULL
;
3540 ret
->need_fn_stub
= false;
3541 ret
->call_stub
= NULL
;
3542 ret
->call_fp_stub
= NULL
;
3545 return (struct bfd_hash_entry
*) ret
;
3548 /* Create a MIPS ELF linker hash table. */
3550 static struct bfd_link_hash_table
*
3551 mips_elf_link_hash_table_create (abfd
)
3554 struct mips_elf_link_hash_table
*ret
;
3556 ret
= ((struct mips_elf_link_hash_table
*)
3557 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
3558 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
3561 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3562 mips_elf_link_hash_newfunc
))
3564 bfd_release (abfd
, ret
);
3569 /* We no longer use this. */
3570 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
3571 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
3573 ret
->procedure_count
= 0;
3574 ret
->compact_rel_size
= 0;
3575 ret
->use_rld_obj_head
= false;
3577 ret
->mips16_stubs_seen
= false;
3579 return &ret
->root
.root
;
3582 /* Hook called by the linker routine which adds symbols from an object
3583 file. We must handle the special MIPS section numbers here. */
3587 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3589 struct bfd_link_info
*info
;
3590 const Elf_Internal_Sym
*sym
;
3596 if (SGI_COMPAT (abfd
)
3597 && (abfd
->flags
& DYNAMIC
) != 0
3598 && strcmp (*namep
, "_rld_new_interface") == 0)
3600 /* Skip Irix 5 rld entry name. */
3605 switch (sym
->st_shndx
)
3608 /* Common symbols less than the GP size are automatically
3609 treated as SHN_MIPS_SCOMMON symbols. */
3610 if (sym
->st_size
> elf_gp_size (abfd
))
3613 case SHN_MIPS_SCOMMON
:
3614 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3615 (*secp
)->flags
|= SEC_IS_COMMON
;
3616 *valp
= sym
->st_size
;
3620 /* This section is used in a shared object. */
3621 if (mips_elf_text_section_ptr
== NULL
)
3623 /* Initialize the section. */
3624 mips_elf_text_section
.name
= ".text";
3625 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
3626 mips_elf_text_section
.output_section
= NULL
;
3627 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
3628 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
3629 mips_elf_text_symbol
.name
= ".text";
3630 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
3631 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
3632 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
3633 mips_elf_text_section_ptr
= &mips_elf_text_section
;
3635 /* This code used to do *secp = bfd_und_section_ptr if
3636 info->shared. I don't know why, and that doesn't make sense,
3637 so I took it out. */
3638 *secp
= mips_elf_text_section_ptr
;
3641 case SHN_MIPS_ACOMMON
:
3642 /* Fall through. XXX Can we treat this as allocated data? */
3644 /* This section is used in a shared object. */
3645 if (mips_elf_data_section_ptr
== NULL
)
3647 /* Initialize the section. */
3648 mips_elf_data_section
.name
= ".data";
3649 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
3650 mips_elf_data_section
.output_section
= NULL
;
3651 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
3652 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
3653 mips_elf_data_symbol
.name
= ".data";
3654 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
3655 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
3656 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
3657 mips_elf_data_section_ptr
= &mips_elf_data_section
;
3659 /* This code used to do *secp = bfd_und_section_ptr if
3660 info->shared. I don't know why, and that doesn't make sense,
3661 so I took it out. */
3662 *secp
= mips_elf_data_section_ptr
;
3665 case SHN_MIPS_SUNDEFINED
:
3666 *secp
= bfd_und_section_ptr
;
3670 if (SGI_COMPAT (abfd
)
3672 && info
->hash
->creator
== abfd
->xvec
3673 && strcmp (*namep
, "__rld_obj_head") == 0)
3675 struct elf_link_hash_entry
*h
;
3677 /* Mark __rld_obj_head as dynamic. */
3679 if (! (_bfd_generic_link_add_one_symbol
3680 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3681 (bfd_vma
) *valp
, (const char *) NULL
, false,
3682 get_elf_backend_data (abfd
)->collect
,
3683 (struct bfd_link_hash_entry
**) &h
)))
3685 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
3686 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3687 h
->type
= STT_OBJECT
;
3689 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3692 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3695 /* If this is a mips16 text symbol, add 1 to the value to make it
3696 odd. This will cause something like .word SYM to come up with
3697 the right value when it is loaded into the PC. */
3698 if (sym
->st_other
== STO_MIPS16
)
3704 /* Structure used to pass information to mips_elf_output_extsym. */
3709 struct bfd_link_info
*info
;
3710 struct ecoff_debug_info
*debug
;
3711 const struct ecoff_debug_swap
*swap
;
3715 /* This routine is used to write out ECOFF debugging external symbol
3716 information. It is called via mips_elf_link_hash_traverse. The
3717 ECOFF external symbol information must match the ELF external
3718 symbol information. Unfortunately, at this point we don't know
3719 whether a symbol is required by reloc information, so the two
3720 tables may wind up being different. We must sort out the external
3721 symbol information before we can set the final size of the .mdebug
3722 section, and we must set the size of the .mdebug section before we
3723 can relocate any sections, and we can't know which symbols are
3724 required by relocation until we relocate the sections.
3725 Fortunately, it is relatively unlikely that any symbol will be
3726 stripped but required by a reloc. In particular, it can not happen
3727 when generating a final executable. */
3730 mips_elf_output_extsym (h
, data
)
3731 struct mips_elf_link_hash_entry
*h
;
3734 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
3736 asection
*sec
, *output_section
;
3738 if (h
->root
.indx
== -2)
3740 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3741 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
3742 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3743 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
3745 else if (einfo
->info
->strip
== strip_all
3746 || (einfo
->info
->strip
== strip_some
3747 && bfd_hash_lookup (einfo
->info
->keep_hash
,
3748 h
->root
.root
.root
.string
,
3749 false, false) == NULL
))
3757 if (h
->esym
.ifd
== -2)
3760 h
->esym
.cobol_main
= 0;
3761 h
->esym
.weakext
= 0;
3762 h
->esym
.reserved
= 0;
3763 h
->esym
.ifd
= ifdNil
;
3764 h
->esym
.asym
.value
= 0;
3765 h
->esym
.asym
.st
= stGlobal
;
3767 if (SGI_COMPAT (einfo
->abfd
)
3768 && (h
->root
.root
.type
== bfd_link_hash_undefined
3769 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
3773 /* Use undefined class. Also, set class and type for some
3775 name
= h
->root
.root
.root
.string
;
3776 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
3777 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
3779 h
->esym
.asym
.sc
= scData
;
3780 h
->esym
.asym
.st
= stLabel
;
3781 h
->esym
.asym
.value
= 0;
3783 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
3785 h
->esym
.asym
.sc
= scAbs
;
3786 h
->esym
.asym
.st
= stLabel
;
3787 h
->esym
.asym
.value
=
3788 mips_elf_hash_table (einfo
->info
)->procedure_count
;
3790 else if (strcmp (name
, "_gp_disp") == 0)
3792 h
->esym
.asym
.sc
= scAbs
;
3793 h
->esym
.asym
.st
= stLabel
;
3794 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
3797 h
->esym
.asym
.sc
= scUndefined
;
3799 else if (h
->root
.root
.type
!= bfd_link_hash_defined
3800 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
3801 h
->esym
.asym
.sc
= scAbs
;
3806 sec
= h
->root
.root
.u
.def
.section
;
3807 output_section
= sec
->output_section
;
3809 /* When making a shared library and symbol h is the one from
3810 the another shared library, OUTPUT_SECTION may be null. */
3811 if (output_section
== NULL
)
3812 h
->esym
.asym
.sc
= scUndefined
;
3815 name
= bfd_section_name (output_section
->owner
, output_section
);
3817 if (strcmp (name
, ".text") == 0)
3818 h
->esym
.asym
.sc
= scText
;
3819 else if (strcmp (name
, ".data") == 0)
3820 h
->esym
.asym
.sc
= scData
;
3821 else if (strcmp (name
, ".sdata") == 0)
3822 h
->esym
.asym
.sc
= scSData
;
3823 else if (strcmp (name
, ".rodata") == 0
3824 || strcmp (name
, ".rdata") == 0)
3825 h
->esym
.asym
.sc
= scRData
;
3826 else if (strcmp (name
, ".bss") == 0)
3827 h
->esym
.asym
.sc
= scBss
;
3828 else if (strcmp (name
, ".sbss") == 0)
3829 h
->esym
.asym
.sc
= scSBss
;
3830 else if (strcmp (name
, ".init") == 0)
3831 h
->esym
.asym
.sc
= scInit
;
3832 else if (strcmp (name
, ".fini") == 0)
3833 h
->esym
.asym
.sc
= scFini
;
3835 h
->esym
.asym
.sc
= scAbs
;
3839 h
->esym
.asym
.reserved
= 0;
3840 h
->esym
.asym
.index
= indexNil
;
3843 if (h
->root
.root
.type
== bfd_link_hash_common
)
3844 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
3845 else if (h
->root
.root
.type
== bfd_link_hash_defined
3846 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3848 if (h
->esym
.asym
.sc
== scCommon
)
3849 h
->esym
.asym
.sc
= scBss
;
3850 else if (h
->esym
.asym
.sc
== scSCommon
)
3851 h
->esym
.asym
.sc
= scSBss
;
3853 sec
= h
->root
.root
.u
.def
.section
;
3854 output_section
= sec
->output_section
;
3855 if (output_section
!= NULL
)
3856 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
3857 + sec
->output_offset
3858 + output_section
->vma
);
3860 h
->esym
.asym
.value
= 0;
3862 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3864 /* Set type and value for a symbol with a function stub. */
3865 h
->esym
.asym
.st
= stProc
;
3866 sec
= h
->root
.root
.u
.def
.section
;
3868 h
->esym
.asym
.value
= 0;
3871 output_section
= sec
->output_section
;
3872 if (output_section
!= NULL
)
3873 h
->esym
.asym
.value
= (h
->root
.plt
.offset
3874 + sec
->output_offset
3875 + output_section
->vma
);
3877 h
->esym
.asym
.value
= 0;
3884 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
3885 h
->root
.root
.root
.string
,
3888 einfo
->failed
= true;
3895 /* Create a runtime procedure table from the .mdebug section. */
3898 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
3901 struct bfd_link_info
*info
;
3903 struct ecoff_debug_info
*debug
;
3905 const struct ecoff_debug_swap
*swap
;
3906 HDRR
*hdr
= &debug
->symbolic_header
;
3908 struct rpdr_ext
*erp
;
3910 struct pdr_ext
*epdr
;
3911 struct sym_ext
*esym
;
3914 unsigned long size
, count
;
3915 unsigned long sindex
;
3919 const char *no_name_func
= _("static procedure (no name)");
3927 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3929 sindex
= strlen (no_name_func
) + 1;
3930 count
= hdr
->ipdMax
;
3933 size
= swap
->external_pdr_size
;
3935 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
3939 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
3942 size
= sizeof (RPDR
);
3943 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
3947 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
3951 count
= hdr
->isymMax
;
3952 size
= swap
->external_sym_size
;
3953 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
3957 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
3960 count
= hdr
->issMax
;
3961 ss
= (char *) bfd_malloc (count
);
3964 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
3967 count
= hdr
->ipdMax
;
3968 for (i
= 0; i
< count
; i
++, rp
++)
3970 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
3971 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
3972 rp
->adr
= sym
.value
;
3973 rp
->regmask
= pdr
.regmask
;
3974 rp
->regoffset
= pdr
.regoffset
;
3975 rp
->fregmask
= pdr
.fregmask
;
3976 rp
->fregoffset
= pdr
.fregoffset
;
3977 rp
->frameoffset
= pdr
.frameoffset
;
3978 rp
->framereg
= pdr
.framereg
;
3979 rp
->pcreg
= pdr
.pcreg
;
3981 sv
[i
] = ss
+ sym
.iss
;
3982 sindex
+= strlen (sv
[i
]) + 1;
3986 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
3987 size
= BFD_ALIGN (size
, 16);
3988 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
3991 mips_elf_hash_table (info
)->procedure_count
= 0;
3995 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
3997 erp
= (struct rpdr_ext
*) rtproc
;
3998 memset (erp
, 0, sizeof (struct rpdr_ext
));
4000 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
4001 strcpy (str
, no_name_func
);
4002 str
+= strlen (no_name_func
) + 1;
4003 for (i
= 0; i
< count
; i
++)
4005 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
4006 strcpy (str
, sv
[i
]);
4007 str
+= strlen (sv
[i
]) + 1;
4009 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
4011 /* Set the size and contents of .rtproc section. */
4012 s
->_raw_size
= size
;
4013 s
->contents
= (bfd_byte
*) rtproc
;
4015 /* Skip this section later on (I don't think this currently
4016 matters, but someday it might). */
4017 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
4046 /* A comparison routine used to sort .gptab entries. */
4049 gptab_compare (p1
, p2
)
4053 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
4054 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
4056 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
4059 /* We need to use a special link routine to handle the .reginfo and
4060 the .mdebug sections. We need to merge all instances of these
4061 sections together, not write them all out sequentially. */
4064 mips_elf_final_link (abfd
, info
)
4066 struct bfd_link_info
*info
;
4070 struct bfd_link_order
*p
;
4071 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
4072 asection
*rtproc_sec
;
4073 Elf32_RegInfo reginfo
;
4074 struct ecoff_debug_info debug
;
4075 const struct ecoff_debug_swap
*swap
4076 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4077 HDRR
*symhdr
= &debug
.symbolic_header
;
4078 PTR mdebug_handle
= NULL
;
4080 /* Drop the .options section, since it has special semantics which I
4081 haven't bothered to figure out. */
4082 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
4084 if (strcmp ((*secpp
)->name
, ".options") == 0)
4086 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
4087 if (p
->type
== bfd_indirect_link_order
)
4088 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
4089 (*secpp
)->link_order_head
= NULL
;
4090 *secpp
= (*secpp
)->next
;
4091 --abfd
->section_count
;
4096 /* Get a value for the GP register. */
4097 if (elf_gp (abfd
) == 0)
4099 struct bfd_link_hash_entry
*h
;
4101 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4102 if (h
!= (struct bfd_link_hash_entry
*) NULL
4103 && h
->type
== bfd_link_hash_defined
)
4104 elf_gp (abfd
) = (h
->u
.def
.value
4105 + h
->u
.def
.section
->output_section
->vma
4106 + h
->u
.def
.section
->output_offset
);
4107 else if (info
->relocateable
)
4111 /* Make up a value. */
4113 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4116 && (strcmp (o
->name
, ".sbss") == 0
4117 || strcmp (o
->name
, ".sdata") == 0
4118 || strcmp (o
->name
, ".lit4") == 0
4119 || strcmp (o
->name
, ".lit8") == 0))
4122 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
4126 /* If the relocate_section function needs to do a reloc
4127 involving the GP value, it should make a reloc_dangerous
4128 callback to warn that GP is not defined. */
4132 /* Go through the sections and collect the .reginfo and .mdebug
4136 gptab_data_sec
= NULL
;
4137 gptab_bss_sec
= NULL
;
4138 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4140 if (strcmp (o
->name
, ".reginfo") == 0)
4142 memset (®info
, 0, sizeof reginfo
);
4144 /* We have found the .reginfo section in the output file.
4145 Look through all the link_orders comprising it and merge
4146 the information together. */
4147 for (p
= o
->link_order_head
;
4148 p
!= (struct bfd_link_order
*) NULL
;
4151 asection
*input_section
;
4153 Elf32_External_RegInfo ext
;
4156 if (p
->type
!= bfd_indirect_link_order
)
4158 if (p
->type
== bfd_fill_link_order
)
4163 input_section
= p
->u
.indirect
.section
;
4164 input_bfd
= input_section
->owner
;
4166 /* The linker emulation code has probably clobbered the
4167 size to be zero bytes. */
4168 if (input_section
->_raw_size
== 0)
4169 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4171 if (! bfd_get_section_contents (input_bfd
, input_section
,
4177 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
4179 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
4180 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
4181 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
4182 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
4183 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
4185 /* ri_gp_value is set by the function
4186 mips_elf32_section_processing when the section is
4187 finally written out. */
4189 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4190 elf_link_input_bfd ignores this section. */
4191 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4194 /* Size has been set in mips_elf_always_size_sections */
4195 BFD_ASSERT(o
->_raw_size
== sizeof (Elf32_External_RegInfo
));
4197 /* Skip this section later on (I don't think this currently
4198 matters, but someday it might). */
4199 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4204 if (strcmp (o
->name
, ".mdebug") == 0)
4206 struct extsym_info einfo
;
4208 /* We have found the .mdebug section in the output file.
4209 Look through all the link_orders comprising it and merge
4210 the information together. */
4211 symhdr
->magic
= swap
->sym_magic
;
4212 /* FIXME: What should the version stamp be? */
4214 symhdr
->ilineMax
= 0;
4218 symhdr
->isymMax
= 0;
4219 symhdr
->ioptMax
= 0;
4220 symhdr
->iauxMax
= 0;
4222 symhdr
->issExtMax
= 0;
4225 symhdr
->iextMax
= 0;
4227 /* We accumulate the debugging information itself in the
4228 debug_info structure. */
4230 debug
.external_dnr
= NULL
;
4231 debug
.external_pdr
= NULL
;
4232 debug
.external_sym
= NULL
;
4233 debug
.external_opt
= NULL
;
4234 debug
.external_aux
= NULL
;
4236 debug
.ssext
= debug
.ssext_end
= NULL
;
4237 debug
.external_fdr
= NULL
;
4238 debug
.external_rfd
= NULL
;
4239 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4241 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4242 if (mdebug_handle
== (PTR
) NULL
)
4245 if (SGI_COMPAT (abfd
))
4251 static const char * const name
[] =
4252 { ".text", ".init", ".fini", ".data",
4253 ".rodata", ".sdata", ".sbss", ".bss" };
4254 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
4255 scRData
, scSData
, scSBss
, scBss
};
4258 esym
.cobol_main
= 0;
4262 esym
.asym
.iss
= issNil
;
4263 esym
.asym
.st
= stLocal
;
4264 esym
.asym
.reserved
= 0;
4265 esym
.asym
.index
= indexNil
;
4267 for (i
= 0; i
< 8; i
++)
4269 esym
.asym
.sc
= sc
[i
];
4270 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4273 esym
.asym
.value
= s
->vma
;
4274 last
= s
->vma
+ s
->_raw_size
;
4277 esym
.asym
.value
= last
;
4279 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4285 for (p
= o
->link_order_head
;
4286 p
!= (struct bfd_link_order
*) NULL
;
4289 asection
*input_section
;
4291 const struct ecoff_debug_swap
*input_swap
;
4292 struct ecoff_debug_info input_debug
;
4296 if (p
->type
!= bfd_indirect_link_order
)
4298 if (p
->type
== bfd_fill_link_order
)
4303 input_section
= p
->u
.indirect
.section
;
4304 input_bfd
= input_section
->owner
;
4306 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4307 || (get_elf_backend_data (input_bfd
)
4308 ->elf_backend_ecoff_debug_swap
) == NULL
)
4310 /* I don't know what a non MIPS ELF bfd would be
4311 doing with a .mdebug section, but I don't really
4312 want to deal with it. */
4316 input_swap
= (get_elf_backend_data (input_bfd
)
4317 ->elf_backend_ecoff_debug_swap
);
4319 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
4321 /* The ECOFF linking code expects that we have already
4322 read in the debugging information and set up an
4323 ecoff_debug_info structure, so we do that now. */
4324 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
4328 if (! (bfd_ecoff_debug_accumulate
4329 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
4330 &input_debug
, input_swap
, info
)))
4333 /* Loop through the external symbols. For each one with
4334 interesting information, try to find the symbol in
4335 the linker global hash table and save the information
4336 for the output external symbols. */
4337 eraw_src
= input_debug
.external_ext
;
4338 eraw_end
= (eraw_src
4339 + (input_debug
.symbolic_header
.iextMax
4340 * input_swap
->external_ext_size
));
4342 eraw_src
< eraw_end
;
4343 eraw_src
+= input_swap
->external_ext_size
)
4347 struct mips_elf_link_hash_entry
*h
;
4349 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4350 if (ext
.asym
.sc
== scNil
4351 || ext
.asym
.sc
== scUndefined
4352 || ext
.asym
.sc
== scSUndefined
)
4355 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4356 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
4357 name
, false, false, true);
4358 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4364 < input_debug
.symbolic_header
.ifdMax
);
4365 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4371 /* Free up the information we just read. */
4372 free (input_debug
.line
);
4373 free (input_debug
.external_dnr
);
4374 free (input_debug
.external_pdr
);
4375 free (input_debug
.external_sym
);
4376 free (input_debug
.external_opt
);
4377 free (input_debug
.external_aux
);
4378 free (input_debug
.ss
);
4379 free (input_debug
.ssext
);
4380 free (input_debug
.external_fdr
);
4381 free (input_debug
.external_rfd
);
4382 free (input_debug
.external_ext
);
4384 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4385 elf_link_input_bfd ignores this section. */
4386 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4389 if (SGI_COMPAT (abfd
) && info
->shared
)
4391 /* Create .rtproc section. */
4392 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4393 if (rtproc_sec
== NULL
)
4395 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4396 | SEC_LINKER_CREATED
| SEC_READONLY
);
4398 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4399 if (rtproc_sec
== NULL
4400 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4401 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
4405 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
4406 info
, rtproc_sec
, &debug
))
4410 /* Build the external symbol information. */
4413 einfo
.debug
= &debug
;
4415 einfo
.failed
= false;
4416 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4417 mips_elf_output_extsym
,
4422 /* Set the size of the .mdebug section. */
4423 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4425 /* Skip this section later on (I don't think this currently
4426 matters, but someday it might). */
4427 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4432 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4434 const char *subname
;
4437 Elf32_External_gptab
*ext_tab
;
4440 /* The .gptab.sdata and .gptab.sbss sections hold
4441 information describing how the small data area would
4442 change depending upon the -G switch. These sections
4443 not used in executables files. */
4444 if (! info
->relocateable
)
4448 for (p
= o
->link_order_head
;
4449 p
!= (struct bfd_link_order
*) NULL
;
4452 asection
*input_section
;
4454 if (p
->type
!= bfd_indirect_link_order
)
4456 if (p
->type
== bfd_fill_link_order
)
4461 input_section
= p
->u
.indirect
.section
;
4463 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4464 elf_link_input_bfd ignores this section. */
4465 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4468 /* Skip this section later on (I don't think this
4469 currently matters, but someday it might). */
4470 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4472 /* Really remove the section. */
4473 for (secpp
= &abfd
->sections
;
4475 secpp
= &(*secpp
)->next
)
4477 *secpp
= (*secpp
)->next
;
4478 --abfd
->section_count
;
4483 /* There is one gptab for initialized data, and one for
4484 uninitialized data. */
4485 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4487 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4491 (*_bfd_error_handler
)
4492 (_("%s: illegal section name `%s'"),
4493 bfd_get_filename (abfd
), o
->name
);
4494 bfd_set_error (bfd_error_nonrepresentable_section
);
4498 /* The linker script always combines .gptab.data and
4499 .gptab.sdata into .gptab.sdata, and likewise for
4500 .gptab.bss and .gptab.sbss. It is possible that there is
4501 no .sdata or .sbss section in the output file, in which
4502 case we must change the name of the output section. */
4503 subname
= o
->name
+ sizeof ".gptab" - 1;
4504 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4506 if (o
== gptab_data_sec
)
4507 o
->name
= ".gptab.data";
4509 o
->name
= ".gptab.bss";
4510 subname
= o
->name
+ sizeof ".gptab" - 1;
4511 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4514 /* Set up the first entry. */
4516 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
4519 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4520 tab
[0].gt_header
.gt_unused
= 0;
4522 /* Combine the input sections. */
4523 for (p
= o
->link_order_head
;
4524 p
!= (struct bfd_link_order
*) NULL
;
4527 asection
*input_section
;
4531 bfd_size_type gpentry
;
4533 if (p
->type
!= bfd_indirect_link_order
)
4535 if (p
->type
== bfd_fill_link_order
)
4540 input_section
= p
->u
.indirect
.section
;
4541 input_bfd
= input_section
->owner
;
4543 /* Combine the gptab entries for this input section one
4544 by one. We know that the input gptab entries are
4545 sorted by ascending -G value. */
4546 size
= bfd_section_size (input_bfd
, input_section
);
4548 for (gpentry
= sizeof (Elf32_External_gptab
);
4550 gpentry
+= sizeof (Elf32_External_gptab
))
4552 Elf32_External_gptab ext_gptab
;
4553 Elf32_gptab int_gptab
;
4559 if (! (bfd_get_section_contents
4560 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4561 gpentry
, sizeof (Elf32_External_gptab
))))
4567 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
4569 val
= int_gptab
.gt_entry
.gt_g_value
;
4570 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4573 for (look
= 1; look
< c
; look
++)
4575 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4576 tab
[look
].gt_entry
.gt_bytes
+= add
;
4578 if (tab
[look
].gt_entry
.gt_g_value
== val
)
4584 Elf32_gptab
*new_tab
;
4587 /* We need a new table entry. */
4588 new_tab
= ((Elf32_gptab
*)
4589 bfd_realloc ((PTR
) tab
,
4590 (c
+ 1) * sizeof (Elf32_gptab
)));
4591 if (new_tab
== NULL
)
4597 tab
[c
].gt_entry
.gt_g_value
= val
;
4598 tab
[c
].gt_entry
.gt_bytes
= add
;
4600 /* Merge in the size for the next smallest -G
4601 value, since that will be implied by this new
4604 for (look
= 1; look
< c
; look
++)
4606 if (tab
[look
].gt_entry
.gt_g_value
< val
4608 || (tab
[look
].gt_entry
.gt_g_value
4609 > tab
[max
].gt_entry
.gt_g_value
)))
4613 tab
[c
].gt_entry
.gt_bytes
+=
4614 tab
[max
].gt_entry
.gt_bytes
;
4619 last
= int_gptab
.gt_entry
.gt_bytes
;
4622 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4623 elf_link_input_bfd ignores this section. */
4624 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4627 /* The table must be sorted by -G value. */
4629 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
4631 /* Swap out the table. */
4632 ext_tab
= ((Elf32_External_gptab
*)
4633 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
4634 if (ext_tab
== NULL
)
4640 for (i
= 0; i
< c
; i
++)
4641 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
4644 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
4645 o
->contents
= (bfd_byte
*) ext_tab
;
4647 /* Skip this section later on (I don't think this currently
4648 matters, but someday it might). */
4649 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4653 /* Invoke the regular ELF backend linker to do all the work. */
4654 if (! bfd_elf32_bfd_final_link (abfd
, info
))
4657 /* Now write out the computed sections. */
4659 if (reginfo_sec
!= (asection
*) NULL
)
4661 Elf32_External_RegInfo ext
;
4663 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
4664 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4665 (file_ptr
) 0, sizeof ext
))
4669 if (mdebug_sec
!= (asection
*) NULL
)
4671 BFD_ASSERT (abfd
->output_has_begun
);
4672 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4674 mdebug_sec
->filepos
))
4677 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4680 if (gptab_data_sec
!= (asection
*) NULL
)
4682 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4683 gptab_data_sec
->contents
,
4685 gptab_data_sec
->_raw_size
))
4689 if (gptab_bss_sec
!= (asection
*) NULL
)
4691 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4692 gptab_bss_sec
->contents
,
4694 gptab_bss_sec
->_raw_size
))
4698 if (SGI_COMPAT (abfd
))
4700 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4701 if (rtproc_sec
!= NULL
)
4703 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
4704 rtproc_sec
->contents
,
4706 rtproc_sec
->_raw_size
))
4714 /* Handle a MIPS ELF HI16 reloc. */
4717 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
4719 Elf_Internal_Rela
*relhi
;
4720 Elf_Internal_Rela
*rello
;
4727 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4729 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4732 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4734 if ((addlo
& 0x8000) != 0)
4736 if ((addend
& 0x8000) != 0)
4739 bfd_put_32 (input_bfd
,
4740 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
4741 contents
+ relhi
->r_offset
);
4744 /* Handle a MIPS ELF local GOT16 reloc. */
4747 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
4752 Elf_Internal_Rela
*relhi
;
4753 Elf_Internal_Rela
*rello
;
4757 unsigned int assigned_gotno
;
4763 bfd_byte
*got_contents
;
4764 struct mips_got_info
*g
;
4766 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4768 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4771 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4773 if ((addlo
& 0x8000) != 0)
4775 if ((addend
& 0x8000) != 0)
4778 /* Get a got entry representing requested hipage. */
4779 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4780 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4781 BFD_ASSERT (g
!= NULL
);
4783 assigned_gotno
= g
->assigned_gotno
;
4784 got_contents
= sgot
->contents
;
4785 hipage
= addend
& 0xffff0000;
4787 for (i
= MIPS_RESERVED_GOTNO
; i
< assigned_gotno
; i
++)
4789 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
4790 if (hipage
== (address
& 0xffff0000))
4794 if (i
== assigned_gotno
)
4796 if (assigned_gotno
>= g
->local_gotno
)
4798 (*_bfd_error_handler
)
4799 (_("more got entries are needed for hipage relocations"));
4800 bfd_set_error (bfd_error_bad_value
);
4804 bfd_put_32 (input_bfd
, hipage
, got_contents
+ assigned_gotno
* 4);
4805 ++g
->assigned_gotno
;
4808 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
4809 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
4810 contents
+ relhi
->r_offset
);
4815 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
4818 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
4820 Elf_Internal_Rela
*rel
;
4826 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4827 bfd_put_32 (input_bfd
,
4828 (insn
& 0xffff0000) | (offset
& 0xffff),
4829 contents
+ rel
->r_offset
);
4832 /* Relocate a MIPS ELF section. */
4835 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4836 contents
, relocs
, local_syms
, local_sections
)
4838 struct bfd_link_info
*info
;
4840 asection
*input_section
;
4842 Elf_Internal_Rela
*relocs
;
4843 Elf_Internal_Sym
*local_syms
;
4844 asection
**local_sections
;
4846 Elf_Internal_Shdr
*symtab_hdr
;
4849 asection
*sgot
, *sreloc
, *scpt
;
4852 Elf_Internal_Rela
*rel
;
4853 Elf_Internal_Rela
*relend
;
4854 struct mips_got_info
*g
;
4856 dynobj
= elf_hash_table (info
)->dynobj
;
4857 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4861 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
4864 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
4867 if (elf_bad_symtab (input_bfd
))
4869 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
4874 locsymcount
= symtab_hdr
->sh_info
;
4875 extsymoff
= symtab_hdr
->sh_info
;
4878 gp
= _bfd_get_gp_value (output_bfd
);
4881 relend
= relocs
+ input_section
->reloc_count
;
4882 for (; rel
< relend
; rel
++)
4885 reloc_howto_type
*howto
;
4886 unsigned long r_symndx
;
4888 struct elf_link_hash_entry
*h
;
4890 Elf_Internal_Sym
*sym
;
4891 struct mips_elf_link_hash_entry
*mh
;
4893 bfd_reloc_status_type r
;
4895 r_type
= ELF32_R_TYPE (rel
->r_info
);
4896 if (r_type
== R_MIPS_GNU_VTINHERIT
4897 || r_type
== R_MIPS_GNU_VTENTRY
)
4899 if ((r_type
< 0 || r_type
>= (int) R_MIPS_max
)
4900 && r_type
!= R_MIPS16_26
4901 && r_type
!= R_MIPS16_GPREL
)
4903 bfd_set_error (bfd_error_bad_value
);
4906 if (r_type
== R_MIPS16_26
)
4907 howto
= &elf_mips16_jump_howto
;
4908 else if (r_type
== R_MIPS16_GPREL
)
4909 howto
= &elf_mips16_gprel_howto
;
4911 howto
= elf_mips_howto_table
+ r_type
;
4914 && (r_type
== R_MIPS_CALL16
4915 || r_type
== R_MIPS_GOT16
4916 || r_type
== R_MIPS_CALL_HI16
4917 || r_type
== R_MIPS_CALL_LO16
4918 || r_type
== R_MIPS_GOT_HI16
4919 || r_type
== R_MIPS_GOT_LO16
))
4921 /* We need the .got section. */
4924 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4925 BFD_ASSERT (sgot
!= NULL
);
4926 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4927 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4928 BFD_ASSERT (g
!= NULL
);
4932 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4934 /* Mix in the change in GP address for a GP relative reloc. */
4935 if (r_type
!= R_MIPS_GPREL16
4936 && r_type
!= R_MIPS_LITERAL
4937 && r_type
!= R_MIPS_GPREL32
4938 && r_type
!= R_MIPS16_GPREL
)
4944 if (! ((*info
->callbacks
->reloc_dangerous
)
4946 _("GP relative relocation when GP not defined"),
4947 input_bfd
, input_section
,
4950 /* Only give the error once per link. */
4952 _bfd_set_gp_value (output_bfd
, gp
);
4955 if (r_symndx
< extsymoff
4956 || (elf_bad_symtab (input_bfd
)
4957 && local_sections
[r_symndx
] != NULL
))
4959 /* This is a relocation against a section. The current
4960 addend in the instruction is the difference between
4961 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
4962 must change this to be the difference between the
4963 final definition (which will end up in RELOCATION)
4964 and the GP value of OUTPUT_BFD (which is in GP). */
4965 addend
= elf_gp (input_bfd
) - gp
;
4967 else if (! info
->relocateable
)
4969 /* We are doing a final link. The current addend in the
4970 instruction is simply the desired offset into the
4971 symbol (normally zero). We want the instruction to
4972 hold the difference between the final definition of
4973 the symbol (which will end up in RELOCATION) and the
4974 GP value of OUTPUT_BFD (which is in GP). */
4979 /* We are generating relocateable output, and we aren't
4980 going to define this symbol, so we just leave the
4981 instruction alone. */
4989 if (info
->relocateable
)
4991 /* This is a relocateable link. We don't have to change
4992 anything, unless the reloc is against a section symbol,
4993 in which case we have to adjust according to where the
4994 section symbol winds up in the output section. */
4995 if (r_symndx
>= locsymcount
4996 || (elf_bad_symtab (input_bfd
)
4997 && local_sections
[r_symndx
] == NULL
))
5001 sym
= local_syms
+ r_symndx
;
5002 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5006 sec
= local_sections
[r_symndx
];
5008 /* It would be logical to add sym->st_value here,
5009 but Irix 5 sometimes generates a garbage symbol
5011 addend
+= sec
->output_offset
;
5013 /* If this is HI16 or GOT16 with an associated LO16,
5014 adjust the addend accordingly. Otherwise, just
5016 if (r_type
== R_MIPS_64
&& bfd_big_endian (input_bfd
))
5017 r
= _bfd_relocate_contents (howto
, input_bfd
,
5019 contents
+ rel
->r_offset
+ 4);
5020 else if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
5021 r
= _bfd_relocate_contents (howto
, input_bfd
,
5023 contents
+ rel
->r_offset
);
5026 Elf_Internal_Rela
*lorel
;
5028 /* As a GNU extension, permit an arbitrary
5029 number of R_MIPS_HI16 relocs before the
5030 R_MIPS_LO16 reloc. This permits gcc to emit
5031 the HI and LO relocs itself. */
5032 if (r_type
== R_MIPS_GOT16
)
5036 for (lorel
= rel
+ 1;
5038 && (ELF32_R_TYPE (lorel
->r_info
)
5044 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5046 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5051 r
= _bfd_relocate_contents (howto
, input_bfd
,
5053 contents
+ rel
->r_offset
);
5062 boolean undefined_error
;
5064 /* This is a final link. */
5065 undefined_error
= false;
5067 if (r_symndx
< extsymoff
5068 || (elf_bad_symtab (input_bfd
)
5069 && local_sections
[r_symndx
] != NULL
))
5072 sym
= local_syms
+ r_symndx
;
5073 sec
= local_sections
[r_symndx
];
5074 relocation
= (sec
->output_section
->vma
5075 + sec
->output_offset
);
5077 /* It would be logical to always add sym->st_value here,
5078 but Irix 5 sometimes generates a garbage symbol
5080 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5081 relocation
+= sym
->st_value
;
5083 /* mips16 text labels should be treated as odd. */
5084 if (sym
->st_other
== STO_MIPS16
)
5092 indx
= r_symndx
- extsymoff
;
5093 h
= elf_sym_hashes (input_bfd
)[indx
];
5094 while (h
->root
.type
== bfd_link_hash_indirect
5095 || h
->root
.type
== bfd_link_hash_warning
)
5096 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5097 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
5101 if (! ((*info
->callbacks
->reloc_dangerous
)
5103 _("_gp_disp used when GP not defined"),
5104 input_bfd
, input_section
,
5107 /* Only give the error once per link. */
5109 _bfd_set_gp_value (output_bfd
, gp
);
5114 sec
= input_section
;
5115 if (sec
->output_section
!= NULL
)
5118 + sec
->output_section
->vma
5119 + sec
->output_offset
));
5121 relocation
= gp
- rel
->r_offset
;
5122 if (r_type
== R_MIPS_LO16
)
5126 else if (h
->root
.type
== bfd_link_hash_defined
5127 || h
->root
.type
== bfd_link_hash_defweak
)
5129 sec
= h
->root
.u
.def
.section
;
5130 if (sec
->output_section
== NULL
)
5133 relocation
= (h
->root
.u
.def
.value
5134 + sec
->output_section
->vma
5135 + sec
->output_offset
);
5137 else if (h
->root
.type
== bfd_link_hash_undefweak
)
5139 else if (info
->shared
&& !info
->symbolic
&& !info
->no_undefined
)
5141 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
5143 /* If this is a dynamic link, we should have created
5144 a _DYNAMIC_LINK symbol in
5145 mips_elf_create_dynamic_sections. Otherwise, we
5146 should define the symbol with a value of 0.
5147 FIXME: It should probably get into the symbol
5148 table somehow as well. */
5149 BFD_ASSERT (! info
->shared
);
5150 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
5151 ".dynamic") == NULL
);
5156 if (! ((*info
->callbacks
->undefined_symbol
)
5157 (info
, h
->root
.root
.string
, input_bfd
,
5158 input_section
, rel
->r_offset
)))
5160 undefined_error
= true;
5165 mh
= (struct mips_elf_link_hash_entry
*) h
;
5168 else if (sym
!= NULL
)
5169 other
= sym
->st_other
;
5173 /* If this function has an fn_stub, then it is a mips16
5174 function which needs a stub if it is called by a 32 bit
5175 function. If this reloc is anything other than a 16 bit
5176 call, redirect the reloc to the stub. We don't redirect
5177 relocs from other stub functions. */
5178 if (r_type
!= R_MIPS16_26
5180 && mh
->fn_stub
!= NULL
)
5182 && elf_tdata (input_bfd
)->local_stubs
!= NULL
5183 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
5184 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5185 FN_STUB
, sizeof FN_STUB
- 1) != 0
5186 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5187 CALL_STUB
, sizeof CALL_STUB
- 1) != 0
5188 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5189 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) != 0)
5193 BFD_ASSERT (mh
->need_fn_stub
);
5194 relocation
= (mh
->fn_stub
->output_section
->vma
5195 + mh
->fn_stub
->output_offset
);
5201 fn_stub
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
5202 relocation
= (fn_stub
->output_section
->vma
5203 + fn_stub
->output_offset
);
5206 /* RELOCATION now points to 32 bit code. */
5210 /* If this function has a call_stub, then it is called by a
5211 mips16 function; the call needs to go through a stub if
5212 this function is a 32 bit function. If this reloc is a
5213 16 bit call, and the symbol is not a 16 bit function,
5214 then redirect the reloc to the stub. Note that we don't
5215 need to worry about calling the function through a
5216 function pointer; such calls are handled by routing
5217 through a special mips16 routine. We don't have to check
5218 whether this call is from a stub; it can't be, because a
5219 stub contains 32 bit code, and hence can not have a 16
5221 if (r_type
== R_MIPS16_26
5223 && (mh
->call_stub
!= NULL
|| mh
->call_fp_stub
!= NULL
)
5224 && other
!= STO_MIPS16
)
5228 /* If both call_stub and call_fp_stub are defined, we
5229 can figure out which one to use by seeing which one
5230 appears in the input file. */
5231 if (mh
->call_stub
!= NULL
&& mh
->call_fp_stub
!= NULL
)
5236 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
5238 if (strncmp (bfd_get_section_name (input_bfd
, o
),
5239 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5241 stub
= mh
->call_fp_stub
;
5246 stub
= mh
->call_stub
;
5248 else if (mh
->call_stub
!= NULL
)
5249 stub
= mh
->call_stub
;
5251 stub
= mh
->call_fp_stub
;
5253 BFD_ASSERT (stub
->_raw_size
> 0);
5254 relocation
= stub
->output_section
->vma
+ stub
->output_offset
;
5257 if (r_type
== R_MIPS_HI16
)
5259 Elf_Internal_Rela
*lorel
;
5261 /* As a GNU extension, permit an arbitrary number of
5262 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
5263 This permits gcc to emit the HI and LO relocs itself. */
5264 for (lorel
= rel
+ 1;
5266 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
5270 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5272 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5273 contents
, relocation
+ addend
);
5277 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5278 contents
, rel
->r_offset
,
5279 relocation
, addend
);
5281 else if (r_type
== R_MIPS_GOT16
&& local
)
5283 /* GOT16 must also have an associated LO16 in the local
5284 case. In this case, the addend is extracted and the
5285 section in which the referenced object is determined.
5286 Then the final address of the object is computed and
5287 the GOT entry for the hipage (an aligned 64kb chunk)
5288 is added to .got section if needed. The offset field
5289 of the GOT16-relocated instruction is replaced by the
5290 index of this GOT entry for the hipage. */
5291 if ((rel
+ 1) < relend
5292 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
5294 if (! mips_elf_relocate_got_local (output_bfd
, input_bfd
,
5297 relocation
+ addend
))
5302 r
= bfd_reloc_outofrange
;
5304 else if (r_type
== R_MIPS_CALL16
5305 || r_type
== R_MIPS_GOT16
5306 || r_type
== R_MIPS_CALL_LO16
5307 || r_type
== R_MIPS_GOT_LO16
)
5311 /* This symbol must be registered as a global symbol
5312 having the corresponding got entry. */
5313 BFD_ASSERT (h
->got
.offset
!= (bfd_vma
) -1);
5315 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5316 BFD_ASSERT (g
->local_gotno
<= offset
5317 && offset
< sgot
->_raw_size
);
5318 bfd_put_32 (output_bfd
, relocation
+ addend
,
5319 sgot
->contents
+ offset
);
5320 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5322 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
5326 else if (r_type
== R_MIPS_CALL_HI16
5327 || r_type
== R_MIPS_GOT_HI16
)
5331 /* This must be a global symbol with a got entry. The
5332 next reloc must be the corresponding LO16 reloc. */
5333 BFD_ASSERT (h
!= NULL
&& h
->got
.offset
!= (bfd_vma
) -1);
5334 BFD_ASSERT ((rel
+ 1) < relend
);
5335 BFD_ASSERT ((int) ELF32_R_TYPE ((rel
+ 1)->r_info
)
5336 == (r_type
== R_MIPS_CALL_HI16
5337 ? (int) R_MIPS_CALL_LO16
5338 : (int) R_MIPS_GOT_LO16
));
5340 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5341 BFD_ASSERT (g
->local_gotno
<= offset
5342 && offset
< sgot
->_raw_size
);
5343 bfd_put_32 (output_bfd
, relocation
+ addend
,
5344 sgot
->contents
+ offset
);
5345 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5347 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
5351 else if (r_type
== R_MIPS_REL32
5352 || r_type
== R_MIPS_32
)
5354 Elf_Internal_Rel outrel
;
5355 Elf32_crinfo cptrel
;
5359 || (elf_hash_table (info
)->dynamic_sections_created
5361 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
5363 && (input_section
->flags
& SEC_ALLOC
) != 0)
5367 /* When generating a shared object, these
5368 relocations are copied into the output file to be
5369 resolved at run time. */
5372 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5373 BFD_ASSERT (sreloc
!= NULL
);
5378 if (elf_section_data (input_section
)->stab_info
== NULL
)
5379 outrel
.r_offset
= rel
->r_offset
;
5384 off
= (_bfd_stab_section_offset
5385 (output_bfd
, &elf_hash_table (info
)->stab_info
,
5387 &elf_section_data (input_section
)->stab_info
,
5389 if (off
== (bfd_vma
) -1)
5391 outrel
.r_offset
= off
;
5394 outrel
.r_offset
+= (input_section
->output_section
->vma
5395 + input_section
->output_offset
);
5397 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5400 memset (&outrel
, 0, sizeof outrel
);
5402 && (! info
->symbolic
5403 || (h
->elf_link_hash_flags
5404 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5406 BFD_ASSERT (h
->dynindx
!= -1);
5407 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
5408 sec
= input_section
;
5415 sec
= local_sections
[r_symndx
];
5418 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
5420 == bfd_link_hash_defweak
));
5421 sec
= h
->root
.u
.def
.section
;
5423 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5425 else if (sec
== NULL
|| sec
->owner
== NULL
)
5427 bfd_set_error (bfd_error_bad_value
);
5434 osec
= sec
->output_section
;
5435 indx
= elf_section_data (osec
)->dynindx
;
5440 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
5441 addend
+= relocation
;
5445 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
5447 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
5448 (((Elf32_External_Rel
*)
5450 + sreloc
->reloc_count
));
5451 ++sreloc
->reloc_count
;
5453 if (! skip
&& SGI_COMPAT (output_bfd
))
5458 /* Make an entry of compact relocation info. */
5459 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5460 cptrel
.vaddr
= (rel
->r_offset
5461 + input_section
->output_section
->vma
5462 + input_section
->output_offset
);
5463 if (r_type
== R_MIPS_REL32
)
5464 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5466 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5467 mips_elf_set_cr_dist2to (cptrel
, 0);
5468 cptrel
.konst
= addend
;
5470 cr
= (scpt
->contents
5471 + sizeof (Elf32_External_compact_rel
));
5472 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5473 ((Elf32_External_crinfo
*) cr
5474 + scpt
->reloc_count
));
5475 ++scpt
->reloc_count
;
5478 /* This reloc will be computed at runtime, so
5479 there's no need to do anything now. */
5483 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5484 contents
, rel
->r_offset
,
5485 relocation
, addend
);
5487 else if (r_type
== R_MIPS_64
)
5492 /* Do a 32 bit relocation, and sign extend to 64 bits. */
5493 addr
= rel
->r_offset
;
5494 if (bfd_big_endian (input_bfd
))
5496 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5497 contents
, addr
, relocation
,
5499 val
= bfd_get_32 (input_bfd
, contents
+ addr
);
5500 if ((val
& 0x80000000) != 0)
5504 addr
= rel
->r_offset
;
5505 if (bfd_little_endian (input_bfd
))
5507 bfd_put_32 (input_bfd
, val
, contents
+ addr
);
5509 else if (r_type
== R_MIPS_26
&& other
== STO_MIPS16
)
5513 /* This is a jump to a mips16 routine from a mips32
5514 routine. We need to change jal into jalx. */
5515 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5516 if (((insn
>> 26) & 0x3f) != 0x3
5517 && ((insn
>> 26) & 0x3f) != 0x1d)
5519 (*_bfd_error_handler
)
5520 (_("%s: %s+0x%lx: jump to mips16 routine which is not jal"),
5521 bfd_get_filename (input_bfd
),
5522 input_section
->name
,
5523 (unsigned long) rel
->r_offset
);
5524 bfd_set_error (bfd_error_bad_value
);
5527 insn
= (insn
& 0x3ffffff) | (0x1d << 26);
5528 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5529 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5530 contents
, rel
->r_offset
,
5531 relocation
, addend
);
5533 else if (r_type
== R_MIPS16_26
)
5535 /* It's easiest to do the normal relocation, and then
5536 dig out the instruction and swap the first word the
5537 way the mips16 expects it. If this is little endian,
5538 though, we need to swap the two words first, and then
5539 swap them back again later, so that the address looks
5542 if (bfd_little_endian (input_bfd
))
5546 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5547 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5548 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5551 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5552 contents
, rel
->r_offset
,
5553 relocation
, addend
);
5554 if (r
== bfd_reloc_ok
)
5558 if (bfd_little_endian (input_bfd
))
5560 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5561 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5562 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5565 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5566 insn
= ((insn
& 0xfc00)
5567 | ((insn
& 0x1f) << 5)
5568 | ((insn
& 0x3e0) >> 5));
5569 /* If this is a jump to a 32 bit routine, then make
5571 if (other
!= STO_MIPS16
)
5573 bfd_put_16 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5576 else if (r_type
== R_MIPS16_GPREL
)
5578 unsigned short extend
, insn
;
5580 unsigned long final
;
5582 /* Extract the addend into buf, run the regular reloc,
5583 and stuff the resulting value back into the
5585 if (rel
->r_offset
> input_section
->_raw_size
)
5586 r
= bfd_reloc_outofrange
;
5589 extend
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5590 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 2);
5591 bfd_put_32 (input_bfd
,
5592 (((extend
& 0x1f) << 11)
5596 r
= _bfd_final_link_relocate (howto
, input_bfd
,
5598 (bfd_vma
) 0, relocation
,
5600 final
= bfd_get_32 (input_bfd
, buf
);
5601 bfd_put_16 (input_bfd
,
5603 | ((final
>> 11) & 0x1f)
5605 contents
+ rel
->r_offset
);
5606 bfd_put_16 (input_bfd
,
5609 contents
+ rel
->r_offset
+ 2);
5613 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5614 contents
, rel
->r_offset
,
5615 relocation
, addend
);
5617 /* The jal instruction can only jump to an address which is
5618 divisible by 4, and it can only jump to an address with
5619 the same upper 4 bits as the PC. */
5620 if (r
== bfd_reloc_ok
5621 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
))
5627 pc
= ((input_section
->output_section
->vma
5628 + input_section
->output_offset
5631 target
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
)
5632 & (howto
->dst_mask
);
5633 addr
= (target
<< 2) + pc
;
5634 if (other
== STO_MIPS16
)
5635 addr
&= ~ (bfd_vma
) 1;
5637 || ((addr
& 0xf0000000)
5639 r
= bfd_reloc_overflow
;
5642 /* Don't bother to report a relocation overflow for a call
5643 to a weak undefined symbol with a value of zero. This
5646 even if we aren't in range to call address zero. */
5647 if (r
== bfd_reloc_overflow
5648 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
)
5649 && relocation
+ addend
== 0
5651 && h
->root
.type
== bfd_link_hash_undefweak
)
5654 /* If we've already issued an error for an undefined symbol,
5655 don't issue another useless error. */
5657 && (r
== bfd_reloc_undefined
|| r
== bfd_reloc_overflow
))
5660 if (SGI_COMPAT (output_bfd
)
5662 && (input_section
->flags
& SEC_ALLOC
) != 0)
5664 Elf32_crinfo cptrel
;
5667 /* Make an entry of compact relocation info. */
5668 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5669 cptrel
.vaddr
= (rel
->r_offset
5670 + input_section
->output_section
->vma
5671 + input_section
->output_offset
);
5676 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
5677 /* XXX How should we set dist2to in this case. */
5678 mips_elf_set_cr_dist2to (cptrel
, 8);
5679 cptrel
.konst
= addend
+ relocation
;
5680 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5681 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5682 ((Elf32_External_crinfo
*) cr
5683 + scpt
->reloc_count
));
5684 ++scpt
->reloc_count
;
5687 case R_MIPS_GPREL16
:
5688 case R_MIPS_LITERAL
:
5689 case R_MIPS_GPREL32
:
5690 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
5691 cptrel
.konst
= gp
- cptrel
.vaddr
;
5692 mips_elf_set_cr_dist2to (cptrel
, 4);
5693 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5694 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5695 ((Elf32_External_crinfo
*) cr
5696 + scpt
->reloc_count
));
5697 ++scpt
->reloc_count
;
5706 if (r
!= bfd_reloc_ok
)
5711 case bfd_reloc_outofrange
:
5713 case bfd_reloc_overflow
:
5718 name
= h
->root
.root
.string
;
5721 name
= bfd_elf_string_from_elf_section (input_bfd
,
5722 symtab_hdr
->sh_link
,
5727 name
= bfd_section_name (input_bfd
, sec
);
5729 if (! ((*info
->callbacks
->reloc_overflow
)
5730 (info
, name
, howto
->name
, (bfd_vma
) 0,
5731 input_bfd
, input_section
, rel
->r_offset
)))
5742 /* This hook function is called before the linker writes out a global
5743 symbol. We mark symbols as small common if appropriate. This is
5744 also where we undo the increment of the value for a mips16 symbol. */
5748 mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
5750 struct bfd_link_info
*info
;
5752 Elf_Internal_Sym
*sym
;
5753 asection
*input_sec
;
5755 /* If we see a common symbol, which implies a relocatable link, then
5756 if a symbol was small common in an input file, mark it as small
5757 common in the output file. */
5758 if (sym
->st_shndx
== SHN_COMMON
5759 && strcmp (input_sec
->name
, ".scommon") == 0)
5760 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
5762 if (sym
->st_other
== STO_MIPS16
5763 && (sym
->st_value
& 1) != 0)
5769 /* Functions for the dynamic linker. */
5771 /* The name of the dynamic interpreter. This is put in the .interp
5774 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
5776 /* Create dynamic sections when linking against a dynamic object. */
5779 mips_elf_create_dynamic_sections (abfd
, info
)
5781 struct bfd_link_info
*info
;
5783 struct elf_link_hash_entry
*h
;
5785 register asection
*s
;
5786 const char * const *namep
;
5788 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5789 | SEC_LINKER_CREATED
| SEC_READONLY
);
5791 /* Mips ABI requests the .dynamic section to be read only. */
5792 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5795 if (! bfd_set_section_flags (abfd
, s
, flags
))
5799 /* We need to create .got section. */
5800 if (! mips_elf_create_got_section (abfd
, info
))
5803 /* Create .stub section. */
5804 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
5806 s
= bfd_make_section (abfd
, ".stub");
5808 || ! bfd_set_section_flags (abfd
, s
, flags
)
5809 || ! bfd_set_section_alignment (abfd
, s
, 2))
5813 if (SGI_COMPAT (abfd
)
5815 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
5817 s
= bfd_make_section (abfd
, ".rld_map");
5819 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
5820 || ! bfd_set_section_alignment (abfd
, s
, 2))
5824 if (SGI_COMPAT (abfd
))
5826 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
5829 if (! (_bfd_generic_link_add_one_symbol
5830 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
5831 (bfd_vma
) 0, (const char *) NULL
, false,
5832 get_elf_backend_data (abfd
)->collect
,
5833 (struct bfd_link_hash_entry
**) &h
)))
5835 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5836 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5837 h
->type
= STT_SECTION
;
5839 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5843 /* We need to create a .compact_rel section. */
5844 if (! mips_elf_create_compact_rel_section (abfd
, info
))
5847 /* Change aligments of some sections. */
5848 s
= bfd_get_section_by_name (abfd
, ".hash");
5850 bfd_set_section_alignment (abfd
, s
, 4);
5851 s
= bfd_get_section_by_name (abfd
, ".dynsym");
5853 bfd_set_section_alignment (abfd
, s
, 4);
5854 s
= bfd_get_section_by_name (abfd
, ".dynstr");
5856 bfd_set_section_alignment (abfd
, s
, 4);
5857 s
= bfd_get_section_by_name (abfd
, ".reginfo");
5859 bfd_set_section_alignment (abfd
, s
, 4);
5860 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5862 bfd_set_section_alignment (abfd
, s
, 4);
5868 if (! (_bfd_generic_link_add_one_symbol
5869 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
5870 (bfd_vma
) 0, (const char *) NULL
, false,
5871 get_elf_backend_data (abfd
)->collect
,
5872 (struct bfd_link_hash_entry
**) &h
)))
5874 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5875 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5876 h
->type
= STT_SECTION
;
5878 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5881 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
5883 /* __rld_map is a four byte word located in the .data section
5884 and is filled in by the rtld to contain a pointer to
5885 the _r_debug structure. Its symbol value will be set in
5886 mips_elf_finish_dynamic_symbol. */
5887 s
= bfd_get_section_by_name (abfd
, ".rld_map");
5888 BFD_ASSERT (s
!= NULL
);
5891 if (! (_bfd_generic_link_add_one_symbol
5892 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
5893 (bfd_vma
) 0, (const char *) NULL
, false,
5894 get_elf_backend_data (abfd
)->collect
,
5895 (struct bfd_link_hash_entry
**) &h
)))
5897 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5898 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5899 h
->type
= STT_OBJECT
;
5901 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5909 /* Create the .compact_rel section. */
5912 mips_elf_create_compact_rel_section (abfd
, info
)
5914 struct bfd_link_info
*info
;
5917 register asection
*s
;
5919 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
5921 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
5924 s
= bfd_make_section (abfd
, ".compact_rel");
5926 || ! bfd_set_section_flags (abfd
, s
, flags
)
5927 || ! bfd_set_section_alignment (abfd
, s
, 2))
5930 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
5936 /* Create the .got section to hold the global offset table. */
5939 mips_elf_create_got_section (abfd
, info
)
5941 struct bfd_link_info
*info
;
5944 register asection
*s
;
5945 struct elf_link_hash_entry
*h
;
5946 struct mips_got_info
*g
;
5948 /* This function may be called more than once. */
5949 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
5952 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5953 | SEC_LINKER_CREATED
);
5955 s
= bfd_make_section (abfd
, ".got");
5957 || ! bfd_set_section_flags (abfd
, s
, flags
)
5958 || ! bfd_set_section_alignment (abfd
, s
, 4))
5961 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
5962 linker script because we don't want to define the symbol if we
5963 are not creating a global offset table. */
5965 if (! (_bfd_generic_link_add_one_symbol
5966 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
5967 (bfd_vma
) 0, (const char *) NULL
, false,
5968 get_elf_backend_data (abfd
)->collect
,
5969 (struct bfd_link_hash_entry
**) &h
)))
5971 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5972 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5973 h
->type
= STT_OBJECT
;
5976 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5979 /* The first several global offset table entries are reserved. */
5980 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
5982 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
5983 sizeof (struct mips_got_info
));
5986 g
->global_gotsym
= 0;
5987 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
5988 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
5989 if (elf_section_data (s
) == NULL
)
5992 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
5993 if (elf_section_data (s
) == NULL
)
5996 elf_section_data (s
)->tdata
= (PTR
) g
;
6001 /* Look through the relocs for a section during the first phase, and
6002 allocate space in the global offset table. */
6005 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
6007 struct bfd_link_info
*info
;
6009 const Elf_Internal_Rela
*relocs
;
6013 Elf_Internal_Shdr
*symtab_hdr
;
6014 struct elf_link_hash_entry
**sym_hashes
;
6015 struct mips_got_info
*g
;
6017 const Elf_Internal_Rela
*rel
;
6018 const Elf_Internal_Rela
*rel_end
;
6022 if (info
->relocateable
)
6025 dynobj
= elf_hash_table (info
)->dynobj
;
6026 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6027 sym_hashes
= elf_sym_hashes (abfd
);
6028 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
6030 /* Check for the mips16 stub sections. */
6032 name
= bfd_get_section_name (abfd
, sec
);
6033 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
6035 unsigned long r_symndx
;
6037 /* Look at the relocation information to figure out which symbol
6040 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6042 if (r_symndx
< extsymoff
6043 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6047 /* This stub is for a local symbol. This stub will only be
6048 needed if there is some relocation in this BFD, other
6049 than a 16 bit function call, which refers to this symbol. */
6050 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6052 Elf_Internal_Rela
*sec_relocs
;
6053 const Elf_Internal_Rela
*r
, *rend
;
6055 /* We can ignore stub sections when looking for relocs. */
6056 if ((o
->flags
& SEC_RELOC
) == 0
6057 || o
->reloc_count
== 0
6058 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
6059 sizeof FN_STUB
- 1) == 0
6060 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
6061 sizeof CALL_STUB
- 1) == 0
6062 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
6063 sizeof CALL_FP_STUB
- 1) == 0)
6066 sec_relocs
= (_bfd_elf32_link_read_relocs
6067 (abfd
, o
, (PTR
) NULL
,
6068 (Elf_Internal_Rela
*) NULL
,
6069 info
->keep_memory
));
6070 if (sec_relocs
== NULL
)
6073 rend
= sec_relocs
+ o
->reloc_count
;
6074 for (r
= sec_relocs
; r
< rend
; r
++)
6075 if (ELF32_R_SYM (r
->r_info
) == r_symndx
6076 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
6079 if (! info
->keep_memory
)
6088 /* There is no non-call reloc for this stub, so we do
6089 not need it. Since this function is called before
6090 the linker maps input sections to output sections, we
6091 can easily discard it by setting the SEC_EXCLUDE
6093 sec
->flags
|= SEC_EXCLUDE
;
6097 /* Record this stub in an array of local symbol stubs for
6099 if (elf_tdata (abfd
)->local_stubs
== NULL
)
6101 unsigned long symcount
;
6104 if (elf_bad_symtab (abfd
))
6105 symcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
6107 symcount
= symtab_hdr
->sh_info
;
6108 n
= (asection
**) bfd_zalloc (abfd
,
6109 symcount
* sizeof (asection
*));
6112 elf_tdata (abfd
)->local_stubs
= n
;
6115 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
6117 /* We don't need to set mips16_stubs_seen in this case.
6118 That flag is used to see whether we need to look through
6119 the global symbol table for stubs. We don't need to set
6120 it here, because we just have a local stub. */
6124 struct mips_elf_link_hash_entry
*h
;
6126 h
= ((struct mips_elf_link_hash_entry
*)
6127 sym_hashes
[r_symndx
- extsymoff
]);
6129 /* H is the symbol this stub is for. */
6132 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6135 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
6136 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6138 unsigned long r_symndx
;
6139 struct mips_elf_link_hash_entry
*h
;
6142 /* Look at the relocation information to figure out which symbol
6145 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6147 if (r_symndx
< extsymoff
6148 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6150 /* This stub was actually built for a static symbol defined
6151 in the same file. We assume that all static symbols in
6152 mips16 code are themselves mips16, so we can simply
6153 discard this stub. Since this function is called before
6154 the linker maps input sections to output sections, we can
6155 easily discard it by setting the SEC_EXCLUDE flag. */
6156 sec
->flags
|= SEC_EXCLUDE
;
6160 h
= ((struct mips_elf_link_hash_entry
*)
6161 sym_hashes
[r_symndx
- extsymoff
]);
6163 /* H is the symbol this stub is for. */
6165 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6166 loc
= &h
->call_fp_stub
;
6168 loc
= &h
->call_stub
;
6170 /* If we already have an appropriate stub for this function, we
6171 don't need another one, so we can discard this one. Since
6172 this function is called before the linker maps input sections
6173 to output sections, we can easily discard it by setting the
6174 SEC_EXCLUDE flag. We can also discard this section if we
6175 happen to already know that this is a mips16 function; it is
6176 not necessary to check this here, as it is checked later, but
6177 it is slightly faster to check now. */
6178 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
6180 sec
->flags
|= SEC_EXCLUDE
;
6185 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6195 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6200 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6201 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6202 BFD_ASSERT (g
!= NULL
);
6208 rel_end
= relocs
+ sec
->reloc_count
;
6209 for (rel
= relocs
; rel
< rel_end
; rel
++)
6211 unsigned long r_symndx
;
6212 struct elf_link_hash_entry
*h
;
6214 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6216 if (r_symndx
< extsymoff
)
6220 h
= sym_hashes
[r_symndx
- extsymoff
];
6222 /* This may be an indirect symbol created because of a version. */
6225 while (h
->root
.type
== bfd_link_hash_indirect
)
6226 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6230 /* Some relocs require a global offset table. */
6231 if (dynobj
== NULL
|| sgot
== NULL
)
6233 switch (ELF32_R_TYPE (rel
->r_info
))
6237 case R_MIPS_CALL_HI16
:
6238 case R_MIPS_CALL_LO16
:
6239 case R_MIPS_GOT_HI16
:
6240 case R_MIPS_GOT_LO16
:
6242 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6243 if (! mips_elf_create_got_section (dynobj
, info
))
6245 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6246 BFD_ASSERT (sgot
!= NULL
);
6247 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6248 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6249 BFD_ASSERT (g
!= NULL
);
6255 && (info
->shared
|| h
!= NULL
)
6256 && (sec
->flags
& SEC_ALLOC
) != 0)
6257 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6265 switch (ELF32_R_TYPE (rel
->r_info
))
6268 case R_MIPS_CALL_HI16
:
6269 case R_MIPS_CALL_LO16
:
6270 /* This symbol requires a global offset table entry. */
6274 (*_bfd_error_handler
)
6275 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
6276 bfd_get_filename (abfd
), (unsigned long) rel
->r_offset
);
6277 bfd_set_error (bfd_error_bad_value
);
6281 /* Make sure this symbol is output as a dynamic symbol. */
6282 if (h
->dynindx
== -1)
6284 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6288 if (h
->got
.offset
!= (bfd_vma
) -1)
6290 /* We have already allocated space in the .got. */
6294 /* Note the index of the first global got symbol in .dynsym. */
6295 if (g
->global_gotsym
== 0
6296 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6297 g
->global_gotsym
= h
->dynindx
;
6299 /* Make this symbol to have the corresponding got entry. */
6302 /* We need a stub, not a plt entry for the undefined
6303 function. But we record it as if it needs plt. See
6304 elf_adjust_dynamic_symbol in elflink.h. */
6305 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6311 case R_MIPS_GOT_HI16
:
6312 case R_MIPS_GOT_LO16
:
6313 /* This symbol requires a global offset table entry. */
6317 /* Make sure this symbol is output as a dynamic symbol. */
6318 if (h
->dynindx
== -1)
6320 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6324 if (h
->got
.offset
!= (bfd_vma
) -1)
6326 /* We have already allocated space in the .got. */
6329 /* Note the index of the first global got symbol in
6331 if (g
->global_gotsym
== 0
6332 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6333 g
->global_gotsym
= h
->dynindx
;
6335 /* Make this symbol to be the global got symbol. */
6343 if ((info
->shared
|| h
!= NULL
)
6344 && (sec
->flags
& SEC_ALLOC
) != 0)
6348 const char *name
= ".rel.dyn";
6350 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6353 sreloc
= bfd_make_section (dynobj
, name
);
6355 || ! bfd_set_section_flags (dynobj
, sreloc
,
6360 | SEC_LINKER_CREATED
6362 || ! bfd_set_section_alignment (dynobj
, sreloc
,
6369 /* When creating a shared object, we must copy these
6370 reloc types into the output file as R_MIPS_REL32
6371 relocs. We make room for this reloc in the
6372 .rel.dyn reloc section */
6373 if (sreloc
->_raw_size
== 0)
6375 /* Add a null element. */
6376 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6377 ++sreloc
->reloc_count
;
6379 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6383 struct mips_elf_link_hash_entry
*hmips
;
6385 /* We only need to copy this reloc if the symbol is
6386 defined in a dynamic object. */
6387 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6388 ++hmips
->mips_32_relocs
;
6392 if (SGI_COMPAT (abfd
))
6393 mips_elf_hash_table (info
)->compact_rel_size
+=
6394 sizeof (Elf32_External_crinfo
);
6399 case R_MIPS_GPREL16
:
6400 case R_MIPS_LITERAL
:
6401 case R_MIPS_GPREL32
:
6402 if (SGI_COMPAT (abfd
))
6403 mips_elf_hash_table (info
)->compact_rel_size
+=
6404 sizeof (Elf32_External_crinfo
);
6407 /* This relocation describes the C++ object vtable hierarchy.
6408 Reconstruct it for later use during GC. */
6409 case R_MIPS_GNU_VTINHERIT
:
6410 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6414 /* This relocation describes which C++ vtable entries are actually
6415 used. Record for later use during GC. */
6416 case R_MIPS_GNU_VTENTRY
:
6417 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
6425 /* If this reloc is not a 16 bit call, and it has a global
6426 symbol, then we will need the fn_stub if there is one.
6427 References from a stub section do not count. */
6429 && ELF32_R_TYPE (rel
->r_info
) != R_MIPS16_26
6430 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
6431 sizeof FN_STUB
- 1) != 0
6432 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
6433 sizeof CALL_STUB
- 1) != 0
6434 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
6435 sizeof CALL_FP_STUB
- 1) != 0)
6437 struct mips_elf_link_hash_entry
*mh
;
6439 mh
= (struct mips_elf_link_hash_entry
*) h
;
6440 mh
->need_fn_stub
= true;
6447 /* Return the section that should be marked against GC for a given
6451 mips_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
6453 struct bfd_link_info
*info
;
6454 Elf_Internal_Rela
*rel
;
6455 struct elf_link_hash_entry
*h
;
6456 Elf_Internal_Sym
*sym
;
6458 /* ??? Do mips16 stub sections need to be handled special? */
6462 switch (ELF32_R_TYPE (rel
->r_info
))
6464 case R_MIPS_GNU_VTINHERIT
:
6465 case R_MIPS_GNU_VTENTRY
:
6469 switch (h
->root
.type
)
6471 case bfd_link_hash_defined
:
6472 case bfd_link_hash_defweak
:
6473 return h
->root
.u
.def
.section
;
6475 case bfd_link_hash_common
:
6476 return h
->root
.u
.c
.p
->section
;
6485 if (!(elf_bad_symtab (abfd
)
6486 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
6487 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
6488 && sym
->st_shndx
!= SHN_COMMON
))
6490 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
6497 /* Update the got entry reference counts for the section being removed. */
6500 mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
6502 struct bfd_link_info
*info
;
6504 const Elf_Internal_Rela
*relocs
;
6507 Elf_Internal_Shdr
*symtab_hdr
;
6508 struct elf_link_hash_entry
**sym_hashes
;
6509 bfd_signed_vma
*local_got_refcounts
;
6510 const Elf_Internal_Rela
*rel
, *relend
;
6511 unsigned long r_symndx
;
6512 struct elf_link_hash_entry
*h
;
6514 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6515 sym_hashes
= elf_sym_hashes (abfd
);
6516 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6518 relend
= relocs
+ sec
->reloc_count
;
6519 for (rel
= relocs
; rel
< relend
; rel
++)
6520 switch (ELF32_R_TYPE (rel
->r_info
))
6524 case R_MIPS_CALL_HI16
:
6525 case R_MIPS_CALL_LO16
:
6526 case R_MIPS_GOT_HI16
:
6527 case R_MIPS_GOT_LO16
:
6528 /* ??? It would seem that the existing MIPS code does no sort
6529 of reference counting or whatnot on its GOT and PLT entries,
6530 so it is not possible to garbage collect them at this time. */
6542 /* Adjust a symbol defined by a dynamic object and referenced by a
6543 regular object. The current definition is in some section of the
6544 dynamic object, but we're not including those sections. We have to
6545 change the definition to something the rest of the link can
6549 mips_elf_adjust_dynamic_symbol (info
, h
)
6550 struct bfd_link_info
*info
;
6551 struct elf_link_hash_entry
*h
;
6554 struct mips_elf_link_hash_entry
*hmips
;
6557 dynobj
= elf_hash_table (info
)->dynobj
;
6559 /* Make sure we know what is going on here. */
6560 BFD_ASSERT (dynobj
!= NULL
6561 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
6562 || h
->weakdef
!= NULL
6563 || ((h
->elf_link_hash_flags
6564 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
6565 && (h
->elf_link_hash_flags
6566 & ELF_LINK_HASH_REF_REGULAR
) != 0
6567 && (h
->elf_link_hash_flags
6568 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
6570 /* If this symbol is defined in a dynamic object, we need to copy
6571 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
6573 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6574 if (! info
->relocateable
6575 && hmips
->mips_32_relocs
!= 0
6576 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6578 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6579 BFD_ASSERT (s
!= NULL
);
6581 if (s
->_raw_size
== 0)
6583 /* Make room for a null element. */
6584 s
->_raw_size
+= sizeof (Elf32_External_Rel
);
6587 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
6590 /* For a function, create a stub, if needed. */
6591 if (h
->type
== STT_FUNC
6592 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
6594 if (! elf_hash_table (info
)->dynamic_sections_created
)
6597 /* If this symbol is not defined in a regular file, then set
6598 the symbol to the stub location. This is required to make
6599 function pointers compare as equal between the normal
6600 executable and the shared library. */
6601 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6603 /* We need .stub section. */
6604 s
= bfd_get_section_by_name (dynobj
, ".stub");
6605 BFD_ASSERT (s
!= NULL
);
6607 h
->root
.u
.def
.section
= s
;
6608 h
->root
.u
.def
.value
= s
->_raw_size
;
6610 /* XXX Write this stub address somewhere. */
6611 h
->plt
.offset
= s
->_raw_size
;
6613 /* Make room for this stub code. */
6614 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6616 /* The last half word of the stub will be filled with the index
6617 of this symbol in .dynsym section. */
6622 /* If this is a weak symbol, and there is a real definition, the
6623 processor independent code will have arranged for us to see the
6624 real definition first, and we can just use the same value. */
6625 if (h
->weakdef
!= NULL
)
6627 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
6628 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
6629 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
6630 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
6634 /* This is a reference to a symbol defined by a dynamic object which
6635 is not a function. */
6640 /* This function is called after all the input files have been read,
6641 and the input sections have been assigned to output sections. We
6642 check for any mips16 stub sections that we can discard. */
6644 static boolean mips_elf_check_mips16_stubs
6645 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
6648 mips_elf_always_size_sections (output_bfd
, info
)
6650 struct bfd_link_info
*info
;
6654 /* The .reginfo section has a fixed size. */
6655 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
6657 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
6659 if (info
->relocateable
6660 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
6663 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
6664 mips_elf_check_mips16_stubs
,
6670 /* Check the mips16 stubs for a particular symbol, and see if we can
6675 mips_elf_check_mips16_stubs (h
, data
)
6676 struct mips_elf_link_hash_entry
*h
;
6679 if (h
->fn_stub
!= NULL
6680 && ! h
->need_fn_stub
)
6682 /* We don't need the fn_stub; the only references to this symbol
6683 are 16 bit calls. Clobber the size to 0 to prevent it from
6684 being included in the link. */
6685 h
->fn_stub
->_raw_size
= 0;
6686 h
->fn_stub
->_cooked_size
= 0;
6687 h
->fn_stub
->flags
&= ~ SEC_RELOC
;
6688 h
->fn_stub
->reloc_count
= 0;
6689 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
6692 if (h
->call_stub
!= NULL
6693 && h
->root
.other
== STO_MIPS16
)
6695 /* We don't need the call_stub; this is a 16 bit function, so
6696 calls from other 16 bit functions are OK. Clobber the size
6697 to 0 to prevent it from being included in the link. */
6698 h
->call_stub
->_raw_size
= 0;
6699 h
->call_stub
->_cooked_size
= 0;
6700 h
->call_stub
->flags
&= ~ SEC_RELOC
;
6701 h
->call_stub
->reloc_count
= 0;
6702 h
->call_stub
->flags
|= SEC_EXCLUDE
;
6705 if (h
->call_fp_stub
!= NULL
6706 && h
->root
.other
== STO_MIPS16
)
6708 /* We don't need the call_stub; this is a 16 bit function, so
6709 calls from other 16 bit functions are OK. Clobber the size
6710 to 0 to prevent it from being included in the link. */
6711 h
->call_fp_stub
->_raw_size
= 0;
6712 h
->call_fp_stub
->_cooked_size
= 0;
6713 h
->call_fp_stub
->flags
&= ~ SEC_RELOC
;
6714 h
->call_fp_stub
->reloc_count
= 0;
6715 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
6721 /* Set the sizes of the dynamic sections. */
6724 mips_elf_size_dynamic_sections (output_bfd
, info
)
6726 struct bfd_link_info
*info
;
6732 struct mips_got_info
*g
;
6734 dynobj
= elf_hash_table (info
)->dynobj
;
6735 BFD_ASSERT (dynobj
!= NULL
);
6737 if (elf_hash_table (info
)->dynamic_sections_created
)
6739 /* Set the contents of the .interp section to the interpreter. */
6742 s
= bfd_get_section_by_name (dynobj
, ".interp");
6743 BFD_ASSERT (s
!= NULL
);
6744 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
6745 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
6749 /* Recompute the size of .got for local entires (reserved and
6750 hipages) if needed. To estimate it, get the upper bound of total
6751 size of loadable sections. */
6752 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6756 bfd_size_type loadable_size
= 0;
6757 bfd_size_type local_gotno
;
6760 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6761 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6762 BFD_ASSERT (g
!= NULL
);
6764 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
6765 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
6767 if ((s
->flags
& SEC_ALLOC
) == 0)
6769 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
6772 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
6774 /* Assume there are two loadable segments consisting of
6775 contiguous sections. Is 5 enough? */
6776 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
6777 g
->local_gotno
= local_gotno
;
6778 sgot
->_raw_size
+= local_gotno
* 4;
6781 /* The check_relocs and adjust_dynamic_symbol entry points have
6782 determined the sizes of the various dynamic sections. Allocate
6785 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
6790 /* It's OK to base decisions on the section name, because none
6791 of the dynobj section names depend upon the input files. */
6792 name
= bfd_get_section_name (dynobj
, s
);
6794 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
6799 if (strncmp (name
, ".rel", 4) == 0)
6801 if (s
->_raw_size
== 0)
6803 /* We only strip the section if the output section name
6804 has the same name. Otherwise, there might be several
6805 input sections for this output section. FIXME: This
6806 code is probably not needed these days anyhow, since
6807 the linker now does not create empty output sections. */
6808 if (s
->output_section
!= NULL
6810 bfd_get_section_name (s
->output_section
->owner
,
6811 s
->output_section
)) == 0)
6816 const char *outname
;
6819 /* If this relocation section applies to a read only
6820 section, then we probably need a DT_TEXTREL entry.
6821 If the relocation section is .rel.dyn, we always
6822 assert a DT_TEXTREL entry rather than testing whether
6823 there exists a relocation to a read only section or
6825 outname
= bfd_get_section_name (output_bfd
,
6827 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
6829 && (target
->flags
& SEC_READONLY
) != 0
6830 && (target
->flags
& SEC_ALLOC
) != 0)
6831 || strcmp (outname
, ".rel.dyn") == 0)
6834 /* We use the reloc_count field as a counter if we need
6835 to copy relocs into the output file. */
6836 if (strcmp (name
, ".rel.dyn") != 0)
6840 else if (strncmp (name
, ".got", 4) == 0)
6844 BFD_ASSERT (elf_section_data (s
) != NULL
);
6845 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
6846 BFD_ASSERT (g
!= NULL
);
6848 /* Fix the size of .got section for the correspondence of
6849 global symbols and got entries. This adds some useless
6850 got entries. Is this required by ABI really? */
6851 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
6852 s
->_raw_size
+= i
* 4;
6854 else if (strncmp (name
, ".stub", 5) == 0)
6856 /* Irix rld assumes that the function stub isn't at the end
6857 of .text section. So put a dummy. XXX */
6858 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6860 else if (! info
->shared
6861 && ! mips_elf_hash_table (info
)->use_rld_obj_head
6862 && strncmp (name
, ".rld_map", 8) == 0)
6864 /* We add a room for __rld_map. It will be filled in by the
6865 rtld to contain a pointer to the _r_debug structure. */
6868 else if (SGI_COMPAT (output_bfd
)
6869 && strncmp (name
, ".compact_rel", 12) == 0)
6870 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
6871 else if (strncmp (name
, ".init", 5) != 0)
6873 /* It's not one of our sections, so don't allocate space. */
6879 _bfd_strip_section_from_output (s
);
6883 /* Allocate memory for the section contents. */
6884 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
6885 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
6887 bfd_set_error (bfd_error_no_memory
);
6890 memset (s
->contents
, 0, s
->_raw_size
);
6893 if (elf_hash_table (info
)->dynamic_sections_created
)
6895 /* Add some entries to the .dynamic section. We fill in the
6896 values later, in elf_mips_finish_dynamic_sections, but we
6897 must add the entries now so that we get the correct size for
6898 the .dynamic section. The DT_DEBUG entry is filled in by the
6899 dynamic linker and used by the debugger. */
6902 if (SGI_COMPAT (output_bfd
))
6904 /* SGI object has the equivalence of DT_DEBUG in the
6905 DT_MIPS_RLD_MAP entry. */
6906 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
6910 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
6916 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
6920 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
6923 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
6925 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
6928 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
6931 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
6935 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
6938 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
6941 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
6943 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
6946 s
= bfd_get_section_by_name (dynobj
, ".liblist");
6947 BFD_ASSERT (s
!= NULL
);
6949 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
6953 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
6956 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
6960 /* Time stamps in executable files are a bad idea. */
6961 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
6966 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
6971 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
6975 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
6978 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
6981 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
6984 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
6987 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
6990 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
6993 #if 0 /* (SGI_COMPAT) */
6994 if (! bfd_get_section_by_name (dynobj
, ".init"))
6995 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
6998 if (! bfd_get_section_by_name (dynobj
, ".fini"))
6999 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
7004 /* If we use dynamic linking, we generate a section symbol for each
7005 output section. These are local symbols, which means that they
7006 must come first in the dynamic symbol table.
7007 That means we must increment the dynamic symbol index of every
7008 other dynamic symbol. */
7011 struct mips_got_info
*g
;
7014 if (elf_hash_table (info
)->dynamic_sections_created
)
7017 /* We no longer try to restrict the set of sections which get
7018 dynamic symbol table entries, since it fails if we have
7019 other random sections which need dynamic relocations. */
7020 const char * const *namep
;
7021 bfd_size_type strindex
;
7022 struct bfd_strtab_hash
*dynstr
;
7024 if (SGI_COMPAT (output_bfd
))
7026 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
7027 elf_link_hash_traverse (elf_hash_table (info
),
7028 mips_elf_adjust_dynindx
,
7030 elf_hash_table (info
)->dynsymcount
+= c
;
7032 dynstr
= elf_hash_table (info
)->dynstr
;
7033 BFD_ASSERT (dynstr
!= NULL
);
7035 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
7039 s
= bfd_get_section_by_name (output_bfd
, *namep
);
7041 elf_section_data (s
)->dynindx
= i
;
7043 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
7044 if (strindex
== (bfd_size_type
) -1)
7047 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
7053 c
= bfd_count_sections (output_bfd
);
7054 elf_link_hash_traverse (elf_hash_table (info
),
7055 mips_elf_adjust_dynindx
,
7057 elf_hash_table (info
)->dynsymcount
+= c
;
7059 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
7061 elf_section_data (s
)->dynindx
= i
;
7062 /* These symbols will have no names, so we don't need to
7063 fiddle with dynstr_index. */
7070 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7071 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7072 BFD_ASSERT (g
!= NULL
);
7074 /* If there are no global got symbols, fake the last symbol so
7076 if (g
->global_gotsym
)
7077 g
->global_gotsym
+= c
;
7079 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
7086 /* Increment the index of a dynamic symbol by a given amount. Called
7087 via elf_link_hash_traverse. */
7090 mips_elf_adjust_dynindx (h
, cparg
)
7091 struct elf_link_hash_entry
*h
;
7094 unsigned int *cp
= (unsigned int *) cparg
;
7096 if (h
->dynindx
!= -1)
7101 /* Finish up dynamic symbol handling. We set the contents of various
7102 dynamic sections here. */
7105 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
7107 struct bfd_link_info
*info
;
7108 struct elf_link_hash_entry
*h
;
7109 Elf_Internal_Sym
*sym
;
7114 struct mips_got_info
*g
;
7117 dynobj
= elf_hash_table (info
)->dynobj
;
7118 gval
= sym
->st_value
;
7120 if (h
->plt
.offset
!= (bfd_vma
) -1)
7124 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
7126 /* This symbol has a stub. Set it up. */
7128 BFD_ASSERT (h
->dynindx
!= -1);
7130 s
= bfd_get_section_by_name (dynobj
, ".stub");
7131 BFD_ASSERT (s
!= NULL
);
7133 /* Fill the stub. */
7135 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
7137 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
7140 /* FIXME: Can h->dynindex be more than 64K? */
7141 if (h
->dynindx
& 0xffff0000)
7144 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
7146 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
7148 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
7149 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
7151 /* Mark the symbol as undefined. plt.offset != -1 occurs
7152 only for the referenced symbol. */
7153 sym
->st_shndx
= SHN_UNDEF
;
7155 /* The run-time linker uses the st_value field of the symbol
7156 to reset the global offset table entry for this external
7157 to its stub address when unlinking a shared object. */
7158 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
7159 sym
->st_value
= gval
;
7162 BFD_ASSERT (h
->dynindx
!= -1);
7164 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7165 BFD_ASSERT (sgot
!= NULL
);
7166 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7167 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7168 BFD_ASSERT (g
!= NULL
);
7170 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
7172 bfd_size_type offset
;
7174 /* This symbol has an entry in the global offset table. Set its
7175 value to the corresponding got entry, if needed. */
7176 if (h
->got
.offset
== (bfd_vma
) -1)
7178 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
7179 BFD_ASSERT (g
->local_gotno
* 4 <= offset
7180 && offset
< sgot
->_raw_size
);
7181 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
7185 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7186 name
= h
->root
.root
.string
;
7187 if (strcmp (name
, "_DYNAMIC") == 0
7188 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
7189 sym
->st_shndx
= SHN_ABS
;
7190 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
7192 sym
->st_shndx
= SHN_ABS
;
7193 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7196 else if (SGI_COMPAT (output_bfd
))
7198 if (strcmp (name
, "_gp_disp") == 0)
7200 sym
->st_shndx
= SHN_ABS
;
7201 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7202 sym
->st_value
= elf_gp (output_bfd
);
7204 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
7205 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
7207 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7208 sym
->st_other
= STO_PROTECTED
;
7210 sym
->st_shndx
= SHN_MIPS_DATA
;
7212 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
7214 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7215 sym
->st_other
= STO_PROTECTED
;
7216 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
7217 sym
->st_shndx
= SHN_ABS
;
7219 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
7221 if (h
->type
== STT_FUNC
)
7222 sym
->st_shndx
= SHN_MIPS_TEXT
;
7223 else if (h
->type
== STT_OBJECT
)
7224 sym
->st_shndx
= SHN_MIPS_DATA
;
7228 if (SGI_COMPAT (output_bfd
)
7231 if (! mips_elf_hash_table (info
)->use_rld_obj_head
7232 && strcmp (name
, "__rld_map") == 0)
7234 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7235 BFD_ASSERT (s
!= NULL
);
7236 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
7237 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
7238 if (mips_elf_hash_table (info
)->rld_value
== 0)
7239 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7241 else if (mips_elf_hash_table (info
)->use_rld_obj_head
7242 && strcmp (name
, "__rld_obj_head") == 0)
7244 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7245 BFD_ASSERT (s
!= NULL
);
7246 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7250 /* If this is a mips16 symbol, force the value to be even. */
7251 if (sym
->st_other
== STO_MIPS16
7252 && (sym
->st_value
& 1) != 0)
7258 /* Finish up the dynamic sections. */
7261 mips_elf_finish_dynamic_sections (output_bfd
, info
)
7263 struct bfd_link_info
*info
;
7268 struct mips_got_info
*g
;
7270 dynobj
= elf_hash_table (info
)->dynobj
;
7272 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
7274 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7279 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7280 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7281 BFD_ASSERT (g
!= NULL
);
7284 if (elf_hash_table (info
)->dynamic_sections_created
)
7286 Elf32_External_Dyn
*dyncon
, *dynconend
;
7288 BFD_ASSERT (sdyn
!= NULL
);
7289 BFD_ASSERT (g
!= NULL
);
7291 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7292 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
7293 for (; dyncon
< dynconend
; dyncon
++)
7295 Elf_Internal_Dyn dyn
;
7300 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
7308 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7309 BFD_ASSERT (s
!= NULL
);
7310 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
7311 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7315 /* Rewrite DT_STRSZ. */
7317 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
7318 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7324 case DT_MIPS_CONFLICT
:
7327 case DT_MIPS_LIBLIST
:
7330 s
= bfd_get_section_by_name (output_bfd
, name
);
7331 BFD_ASSERT (s
!= NULL
);
7332 dyn
.d_un
.d_ptr
= s
->vma
;
7333 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7336 case DT_MIPS_RLD_VERSION
:
7337 dyn
.d_un
.d_val
= 1; /* XXX */
7338 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7342 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
7343 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7346 case DT_MIPS_CONFLICTNO
:
7348 elemsize
= sizeof (Elf32_Conflict
);
7351 case DT_MIPS_LIBLISTNO
:
7353 elemsize
= sizeof (Elf32_Lib
);
7355 s
= bfd_get_section_by_name (output_bfd
, name
);
7358 if (s
->_cooked_size
!= 0)
7359 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7361 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7366 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7369 case DT_MIPS_TIME_STAMP
:
7370 time ((time_t *) &dyn
.d_un
.d_val
);
7371 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7374 case DT_MIPS_ICHECKSUM
:
7378 case DT_MIPS_IVERSION
:
7382 case DT_MIPS_BASE_ADDRESS
:
7383 s
= output_bfd
->sections
;
7384 BFD_ASSERT (s
!= NULL
);
7385 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
7386 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7389 case DT_MIPS_LOCAL_GOTNO
:
7390 dyn
.d_un
.d_val
= g
->local_gotno
;
7391 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7394 case DT_MIPS_SYMTABNO
:
7396 elemsize
= sizeof (Elf32_External_Sym
);
7397 s
= bfd_get_section_by_name (output_bfd
, name
);
7398 BFD_ASSERT (s
!= NULL
);
7400 if (s
->_cooked_size
!= 0)
7401 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7403 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7404 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7407 case DT_MIPS_UNREFEXTNO
:
7409 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
7411 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
);
7413 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7416 case DT_MIPS_GOTSYM
:
7417 dyn
.d_un
.d_val
= g
->global_gotsym
;
7418 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7421 case DT_MIPS_HIPAGENO
:
7422 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
7423 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7426 case DT_MIPS_RLD_MAP
:
7427 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
7428 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7435 /* The first entry of the global offset table will be filled at
7436 runtime. The second entry will be used by some runtime loaders.
7437 This isn't the case of Irix rld. */
7438 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
7440 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
7441 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
7445 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
7450 Elf_Internal_Sym sym
;
7451 Elf32_compact_rel cpt
;
7453 /* Set up the section symbols for the output sections. SGI sets
7454 the STT_NOTYPE attribute for these symbols. Should we do so? */
7456 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
7457 if (sdynsym
!= NULL
)
7461 const char * const * namep
= mips_elf_dynsym_sec_names
;
7466 /* We no longer try to restrict the set of sections which get
7467 dynamic symbol table entries, since it fails if we have
7468 other random sections which need dynamic relocations. */
7469 if (SGI_COMPAT (output_bfd
))
7473 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7479 while ((name
= *namep
++) != NULL
)
7481 s
= bfd_get_section_by_name (output_bfd
, name
);
7484 sym
.st_value
= s
->vma
;
7485 dindx
= elf_section_data (s
)->dynindx
;
7486 last
= s
->vma
+ s
->_raw_size
;
7490 sym
.st_value
= last
;
7494 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
7499 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
7501 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7502 (((Elf32_External_Sym
*)
7507 /* Set the sh_info field of the output .dynsym section to
7508 the index of the first global symbol. */
7509 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7510 SIZEOF_MIPS_DYNSYM_SECNAMES
;
7517 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
7520 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
7524 sym
.st_value
= s
->vma
;
7526 indx
= elf_section_data (s
)->this_idx
;
7527 BFD_ASSERT (indx
> 0);
7528 sym
.st_shndx
= indx
;
7530 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7531 (((Elf32_External_Sym
*)
7533 + elf_section_data (s
)->dynindx
));
7536 /* Set the sh_info field of the output .dynsym section to
7537 the index of the first global symbol. */
7538 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7539 bfd_count_sections (output_bfd
) + 1;
7543 if (SGI_COMPAT (output_bfd
))
7545 /* Write .compact_rel section out. */
7546 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
7550 cpt
.num
= s
->reloc_count
;
7552 cpt
.offset
= (s
->output_section
->filepos
7553 + sizeof (Elf32_External_compact_rel
));
7556 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
7557 ((Elf32_External_compact_rel
*)
7560 /* Clean up a dummy stub function entry in .text. */
7561 s
= bfd_get_section_by_name (dynobj
, ".stub");
7564 file_ptr dummy_offset
;
7566 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
7567 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
7568 memset (s
->contents
+ dummy_offset
, 0,
7569 MIPS_FUNCTION_STUB_SIZE
);
7574 /* Clean up a first relocation in .rel.dyn. */
7575 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7576 if (s
!= NULL
&& s
->_raw_size
> 0)
7577 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
7583 /* This is almost identical to bfd_generic_get_... except that some
7584 MIPS relocations need to be handled specially. Sigh. */
7587 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
7588 relocateable
, symbols
)
7590 struct bfd_link_info
*link_info
;
7591 struct bfd_link_order
*link_order
;
7593 boolean relocateable
;
7596 /* Get enough memory to hold the stuff */
7597 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
7598 asection
*input_section
= link_order
->u
.indirect
.section
;
7600 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
7601 arelent
**reloc_vector
= NULL
;
7607 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
7608 if (reloc_vector
== NULL
&& reloc_size
!= 0)
7611 /* read in the section */
7612 if (!bfd_get_section_contents (input_bfd
,
7616 input_section
->_raw_size
))
7619 /* We're not relaxing the section, so just copy the size info */
7620 input_section
->_cooked_size
= input_section
->_raw_size
;
7621 input_section
->reloc_done
= true;
7623 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
7627 if (reloc_count
< 0)
7630 if (reloc_count
> 0)
7635 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
7638 struct bfd_hash_entry
*h
;
7639 struct bfd_link_hash_entry
*lh
;
7640 /* Skip all this stuff if we aren't mixing formats. */
7641 if (abfd
&& input_bfd
7642 && abfd
->xvec
== input_bfd
->xvec
)
7646 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
7647 lh
= (struct bfd_link_hash_entry
*) h
;
7654 case bfd_link_hash_undefined
:
7655 case bfd_link_hash_undefweak
:
7656 case bfd_link_hash_common
:
7659 case bfd_link_hash_defined
:
7660 case bfd_link_hash_defweak
:
7662 gp
= lh
->u
.def
.value
;
7664 case bfd_link_hash_indirect
:
7665 case bfd_link_hash_warning
:
7667 /* @@FIXME ignoring warning for now */
7669 case bfd_link_hash_new
:
7678 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
7681 char *error_message
= (char *) NULL
;
7682 bfd_reloc_status_type r
;
7684 /* Specific to MIPS: Deal with relocation types that require
7685 knowing the gp of the output bfd. */
7686 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
7687 if (bfd_is_abs_section (sym
->section
) && abfd
)
7689 /* The special_function wouldn't get called anyways. */
7693 /* The gp isn't there; let the special function code
7694 fall over on its own. */
7696 else if ((*parent
)->howto
->special_function
7697 == _bfd_mips_elf_gprel16_reloc
)
7699 /* bypass special_function call */
7700 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
7701 relocateable
, (PTR
) data
, gp
);
7702 goto skip_bfd_perform_relocation
;
7704 /* end mips specific stuff */
7706 r
= bfd_perform_relocation (input_bfd
,
7710 relocateable
? abfd
: (bfd
*) NULL
,
7712 skip_bfd_perform_relocation
:
7716 asection
*os
= input_section
->output_section
;
7718 /* A partial link, so keep the relocs */
7719 os
->orelocation
[os
->reloc_count
] = *parent
;
7723 if (r
!= bfd_reloc_ok
)
7727 case bfd_reloc_undefined
:
7728 if (!((*link_info
->callbacks
->undefined_symbol
)
7729 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7730 input_bfd
, input_section
, (*parent
)->address
)))
7733 case bfd_reloc_dangerous
:
7734 BFD_ASSERT (error_message
!= (char *) NULL
);
7735 if (!((*link_info
->callbacks
->reloc_dangerous
)
7736 (link_info
, error_message
, input_bfd
, input_section
,
7737 (*parent
)->address
)))
7740 case bfd_reloc_overflow
:
7741 if (!((*link_info
->callbacks
->reloc_overflow
)
7742 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7743 (*parent
)->howto
->name
, (*parent
)->addend
,
7744 input_bfd
, input_section
, (*parent
)->address
)))
7747 case bfd_reloc_outofrange
:
7756 if (reloc_vector
!= NULL
)
7757 free (reloc_vector
);
7761 if (reloc_vector
!= NULL
)
7762 free (reloc_vector
);
7765 #define bfd_elf32_bfd_get_relocated_section_contents \
7766 elf32_mips_get_relocated_section_contents
7768 /* ECOFF swapping routines. These are used when dealing with the
7769 .mdebug section, which is in the ECOFF debugging format. */
7770 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
7772 /* Symbol table magic number. */
7774 /* Alignment of debugging information. E.g., 4. */
7776 /* Sizes of external symbolic information. */
7777 sizeof (struct hdr_ext
),
7778 sizeof (struct dnr_ext
),
7779 sizeof (struct pdr_ext
),
7780 sizeof (struct sym_ext
),
7781 sizeof (struct opt_ext
),
7782 sizeof (struct fdr_ext
),
7783 sizeof (struct rfd_ext
),
7784 sizeof (struct ext_ext
),
7785 /* Functions to swap in external symbolic data. */
7794 _bfd_ecoff_swap_tir_in
,
7795 _bfd_ecoff_swap_rndx_in
,
7796 /* Functions to swap out external symbolic data. */
7805 _bfd_ecoff_swap_tir_out
,
7806 _bfd_ecoff_swap_rndx_out
,
7807 /* Function to read in symbolic data. */
7808 _bfd_mips_elf_read_ecoff_info
7811 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
7812 #define TARGET_LITTLE_NAME "elf32-littlemips"
7813 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
7814 #define TARGET_BIG_NAME "elf32-bigmips"
7815 #define ELF_ARCH bfd_arch_mips
7816 #define ELF_MACHINE_CODE EM_MIPS
7818 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
7819 a value of 0x1000, and we are compatible. */
7820 #define ELF_MAXPAGESIZE 0x1000
7822 #define elf_backend_collect true
7823 #define elf_backend_type_change_ok true
7824 #define elf_backend_can_gc_sections true
7825 #define elf_info_to_howto mips_info_to_howto_rela
7826 #define elf_info_to_howto_rel mips_info_to_howto_rel
7827 #define elf_backend_sym_is_global mips_elf_sym_is_global
7828 #define elf_backend_object_p mips_elf32_object_p
7829 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
7830 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
7831 #define elf_backend_section_from_bfd_section \
7832 _bfd_mips_elf_section_from_bfd_section
7833 #define elf_backend_section_processing mips_elf32_section_processing
7834 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
7835 #define elf_backend_additional_program_headers \
7836 mips_elf_additional_program_headers
7837 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
7838 #define elf_backend_final_write_processing \
7839 _bfd_mips_elf_final_write_processing
7840 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
7842 #define bfd_elf32_bfd_is_local_label_name \
7843 mips_elf_is_local_label_name
7844 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
7845 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
7846 #define bfd_elf32_bfd_link_hash_table_create \
7847 mips_elf_link_hash_table_create
7848 #define bfd_elf32_bfd_final_link mips_elf_final_link
7849 #define bfd_elf32_bfd_copy_private_bfd_data \
7850 _bfd_mips_elf_copy_private_bfd_data
7851 #define bfd_elf32_bfd_merge_private_bfd_data \
7852 _bfd_mips_elf_merge_private_bfd_data
7853 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
7854 #define bfd_elf32_bfd_print_private_bfd_data \
7855 _bfd_mips_elf_print_private_bfd_data
7856 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
7857 #define elf_backend_create_dynamic_sections \
7858 mips_elf_create_dynamic_sections
7859 #define elf_backend_check_relocs mips_elf_check_relocs
7860 #define elf_backend_adjust_dynamic_symbol \
7861 mips_elf_adjust_dynamic_symbol
7862 #define elf_backend_always_size_sections \
7863 mips_elf_always_size_sections
7864 #define elf_backend_size_dynamic_sections \
7865 mips_elf_size_dynamic_sections
7866 #define elf_backend_relocate_section mips_elf_relocate_section
7867 #define elf_backend_link_output_symbol_hook \
7868 mips_elf_link_output_symbol_hook
7869 #define elf_backend_finish_dynamic_symbol \
7870 mips_elf_finish_dynamic_symbol
7871 #define elf_backend_finish_dynamic_sections \
7872 mips_elf_finish_dynamic_sections
7873 #define elf_backend_gc_mark_hook mips_elf_gc_mark_hook
7874 #define elf_backend_gc_sweep_hook mips_elf_gc_sweep_hook
7876 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
7877 #define elf_backend_plt_header_size 0
7879 #include "elf32-target.h"