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 void bfd_mips_elf_swap_msym_in
57 PARAMS ((bfd
*, const Elf32_External_Msym
*, Elf32_Internal_Msym
*));
58 static void bfd_mips_elf_swap_msym_out
59 PARAMS ((bfd
*, const Elf32_Internal_Msym
*, Elf32_External_Msym
*));
60 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
61 static boolean mips_elf32_object_p
PARAMS ((bfd
*));
62 static boolean mips_elf_create_procedure_table
63 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
64 struct ecoff_debug_info
*));
65 static int mips_elf_additional_program_headers
PARAMS ((bfd
*));
66 static boolean mips_elf_modify_segment_map
PARAMS ((bfd
*));
67 static INLINE
int elf_mips_isa
PARAMS ((flagword
));
68 static INLINE
int elf_mips_mach
PARAMS ((flagword
));
69 static INLINE
char* elf_mips_abi_name
PARAMS ((flagword
));
70 static boolean mips_elf32_section_from_shdr
71 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, char *));
72 static boolean mips_elf32_section_processing
73 PARAMS ((bfd
*, Elf32_Internal_Shdr
*));
74 static boolean mips_elf_is_local_label_name
75 PARAMS ((bfd
*, const char *));
76 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
77 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
78 static struct bfd_link_hash_table
*mips_elf_link_hash_table_create
80 static int gptab_compare
PARAMS ((const void *, const void *));
81 static boolean mips_elf_final_link
82 PARAMS ((bfd
*, struct bfd_link_info
*));
83 static void mips_elf_relocate_hi16
84 PARAMS ((bfd
*, Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_byte
*,
86 static boolean mips_elf_relocate_got_local
87 PARAMS ((bfd
*, bfd
*, asection
*, Elf_Internal_Rela
*,
88 Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
89 static void mips_elf_relocate_global_got
90 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
91 static bfd_reloc_status_type mips16_jump_reloc
92 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
93 static bfd_reloc_status_type mips16_gprel_reloc
94 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
95 static boolean mips_elf_adjust_dynindx
96 PARAMS ((struct elf_link_hash_entry
*, PTR
));
97 static boolean mips_elf_relocate_section
98 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
99 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
100 static boolean mips_elf_link_output_symbol_hook
101 PARAMS ((bfd
*, struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
103 static boolean mips_elf_create_dynamic_sections
104 PARAMS ((bfd
*, struct bfd_link_info
*));
105 static boolean mips_elf_create_compact_rel_section
106 PARAMS ((bfd
*, struct bfd_link_info
*));
107 static boolean mips_elf_create_got_section
108 PARAMS ((bfd
*, struct bfd_link_info
*));
109 static boolean mips_elf_check_relocs
110 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
111 const Elf_Internal_Rela
*));
112 static boolean mips_elf_adjust_dynamic_symbol
113 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
114 static boolean mips_elf_always_size_sections
115 PARAMS ((bfd
*, struct bfd_link_info
*));
116 static boolean mips_elf_size_dynamic_sections
117 PARAMS ((bfd
*, struct bfd_link_info
*));
118 static boolean mips_elf_finish_dynamic_symbol
119 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
120 Elf_Internal_Sym
*));
121 static boolean mips_elf_finish_dynamic_sections
122 PARAMS ((bfd
*, struct bfd_link_info
*));
123 static boolean mips_elf_add_symbol_hook
124 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
125 const char **, flagword
*, asection
**, bfd_vma
*));
126 static bfd_reloc_status_type mips_elf_final_gp
127 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
128 static bfd_byte
*elf32_mips_get_relocated_section_contents
129 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
130 bfd_byte
*, boolean
, asymbol
**));
131 static asection
*mips_elf_create_msym_section
134 /* The level of IRIX compatibility we're striving for. */
142 /* Nonzero if ABFD is using the N32 ABI. */
144 #define ABI_N32_P(abfd) \
145 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
147 /* What version of Irix we are trying to be compatible with. FIXME:
148 At the moment, we never generate "normal" MIPS ELF ABI executables;
149 we always use some version of Irix. */
151 #define IRIX_COMPAT(abfd) \
152 (ABI_N32_P (abfd) ? ict_irix6 : ict_irix5)
154 /* Whether we are trying to be compatible with IRIX at all. */
156 #define SGI_COMPAT(abfd) \
157 (IRIX_COMPAT (abfd) != ict_none)
159 /* This structure is used to hold .got information when linking. It
160 is stored in the tdata field of the bfd_elf_section_data structure. */
164 /* The symbol index of the first global .got symbol. */
165 unsigned long global_gotsym
;
166 /* The number of local .got entries. */
167 unsigned int local_gotno
;
168 /* The number of local .got entries we have used. */
169 unsigned int assigned_gotno
;
172 /* The name of the msym section. */
173 #define MIPS_ELF_MSYM_SECTION_NAME(abfd) ".msym"
175 /* The number of local .got entries we reserve. */
176 #define MIPS_RESERVED_GOTNO (2)
178 /* Instructions which appear in a stub. For some reason the stub is
179 slightly different on an SGI system. */
180 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
181 #define STUB_LW(abfd) \
183 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
184 : 0x8f998000) /* lw t9,0x8000(gp) */
185 #define STUB_MOVE 0x03e07825 /* move t7,ra */
186 #define STUB_JALR 0x0320f809 /* jal t9 */
187 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
188 #define MIPS_FUNCTION_STUB_SIZE (16)
191 /* We no longer try to identify particular sections for the .dynsym
192 section. When we do, we wind up crashing if there are other random
193 sections with relocations. */
195 /* Names of sections which appear in the .dynsym section in an Irix 5
198 static const char * const mips_elf_dynsym_sec_names
[] =
211 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
212 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
214 /* The number of entries in mips_elf_dynsym_sec_names which go in the
217 #define MIPS_TEXT_DYNSYM_SECNO (3)
221 /* The names of the runtime procedure table symbols used on Irix 5. */
223 static const char * const mips_elf_dynsym_rtproc_names
[] =
226 "_procedure_string_table",
227 "_procedure_table_size",
231 /* These structures are used to generate the .compact_rel section on
236 unsigned long id1
; /* Always one? */
237 unsigned long num
; /* Number of compact relocation entries. */
238 unsigned long id2
; /* Always two? */
239 unsigned long offset
; /* The file offset of the first relocation. */
240 unsigned long reserved0
; /* Zero? */
241 unsigned long reserved1
; /* Zero? */
250 bfd_byte reserved0
[4];
251 bfd_byte reserved1
[4];
252 } Elf32_External_compact_rel
;
256 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
257 unsigned int rtype
: 4; /* Relocation types. See below. */
258 unsigned int dist2to
: 8;
259 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
260 unsigned long konst
; /* KONST field. See below. */
261 unsigned long vaddr
; /* VADDR to be relocated. */
266 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
267 unsigned int rtype
: 4; /* Relocation types. See below. */
268 unsigned int dist2to
: 8;
269 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
270 unsigned long konst
; /* KONST field. See below. */
278 } Elf32_External_crinfo
;
284 } Elf32_External_crinfo2
;
286 /* These are the constants used to swap the bitfields in a crinfo. */
288 #define CRINFO_CTYPE (0x1)
289 #define CRINFO_CTYPE_SH (31)
290 #define CRINFO_RTYPE (0xf)
291 #define CRINFO_RTYPE_SH (27)
292 #define CRINFO_DIST2TO (0xff)
293 #define CRINFO_DIST2TO_SH (19)
294 #define CRINFO_RELVADDR (0x7ffff)
295 #define CRINFO_RELVADDR_SH (0)
297 /* A compact relocation info has long (3 words) or short (2 words)
298 formats. A short format doesn't have VADDR field and relvaddr
299 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
300 #define CRF_MIPS_LONG 1
301 #define CRF_MIPS_SHORT 0
303 /* There are 4 types of compact relocation at least. The value KONST
304 has different meaning for each type:
307 CT_MIPS_REL32 Address in data
308 CT_MIPS_WORD Address in word (XXX)
309 CT_MIPS_GPHI_LO GP - vaddr
310 CT_MIPS_JMPAD Address to jump
313 #define CRT_MIPS_REL32 0xa
314 #define CRT_MIPS_WORD 0xb
315 #define CRT_MIPS_GPHI_LO 0xc
316 #define CRT_MIPS_JMPAD 0xd
318 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
319 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
320 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
321 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
323 static void bfd_elf32_swap_compact_rel_out
324 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
325 static void bfd_elf32_swap_crinfo_out
326 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
328 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
330 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
331 from smaller values. Start with zero, widen, *then* decrement. */
332 #define MINUS_ONE (((bfd_vma)0) - 1)
334 static reloc_howto_type elf_mips_howto_table
[] =
337 HOWTO (R_MIPS_NONE
, /* type */
339 0, /* size (0 = byte, 1 = short, 2 = long) */
341 false, /* pc_relative */
343 complain_overflow_dont
, /* complain_on_overflow */
344 bfd_elf_generic_reloc
, /* special_function */
345 "R_MIPS_NONE", /* name */
346 false, /* partial_inplace */
349 false), /* pcrel_offset */
351 /* 16 bit relocation. */
352 HOWTO (R_MIPS_16
, /* type */
354 1, /* size (0 = byte, 1 = short, 2 = long) */
356 false, /* pc_relative */
358 complain_overflow_bitfield
, /* complain_on_overflow */
359 bfd_elf_generic_reloc
, /* special_function */
360 "R_MIPS_16", /* name */
361 true, /* partial_inplace */
362 0xffff, /* src_mask */
363 0xffff, /* dst_mask */
364 false), /* pcrel_offset */
366 /* 32 bit relocation. */
367 HOWTO (R_MIPS_32
, /* type */
369 2, /* size (0 = byte, 1 = short, 2 = long) */
371 false, /* pc_relative */
373 complain_overflow_bitfield
, /* complain_on_overflow */
374 bfd_elf_generic_reloc
, /* special_function */
375 "R_MIPS_32", /* name */
376 true, /* partial_inplace */
377 0xffffffff, /* src_mask */
378 0xffffffff, /* dst_mask */
379 false), /* pcrel_offset */
381 /* 32 bit symbol relative relocation. */
382 HOWTO (R_MIPS_REL32
, /* type */
384 2, /* size (0 = byte, 1 = short, 2 = long) */
386 false, /* pc_relative */
388 complain_overflow_bitfield
, /* complain_on_overflow */
389 bfd_elf_generic_reloc
, /* special_function */
390 "R_MIPS_REL32", /* name */
391 true, /* partial_inplace */
392 0xffffffff, /* src_mask */
393 0xffffffff, /* dst_mask */
394 false), /* pcrel_offset */
396 /* 26 bit branch address. */
397 HOWTO (R_MIPS_26
, /* type */
399 2, /* size (0 = byte, 1 = short, 2 = long) */
401 false, /* pc_relative */
403 complain_overflow_dont
, /* complain_on_overflow */
404 /* This needs complex overflow
405 detection, because the upper four
406 bits must match the PC. */
407 bfd_elf_generic_reloc
, /* special_function */
408 "R_MIPS_26", /* name */
409 true, /* partial_inplace */
410 0x3ffffff, /* src_mask */
411 0x3ffffff, /* dst_mask */
412 false), /* pcrel_offset */
414 /* High 16 bits of symbol value. */
415 HOWTO (R_MIPS_HI16
, /* type */
417 2, /* size (0 = byte, 1 = short, 2 = long) */
419 false, /* pc_relative */
421 complain_overflow_dont
, /* complain_on_overflow */
422 _bfd_mips_elf_hi16_reloc
, /* special_function */
423 "R_MIPS_HI16", /* name */
424 true, /* partial_inplace */
425 0xffff, /* src_mask */
426 0xffff, /* dst_mask */
427 false), /* pcrel_offset */
429 /* Low 16 bits of symbol value. */
430 HOWTO (R_MIPS_LO16
, /* type */
432 2, /* size (0 = byte, 1 = short, 2 = long) */
434 false, /* pc_relative */
436 complain_overflow_dont
, /* complain_on_overflow */
437 _bfd_mips_elf_lo16_reloc
, /* special_function */
438 "R_MIPS_LO16", /* name */
439 true, /* partial_inplace */
440 0xffff, /* src_mask */
441 0xffff, /* dst_mask */
442 false), /* pcrel_offset */
444 /* GP relative reference. */
445 HOWTO (R_MIPS_GPREL16
, /* type */
447 2, /* size (0 = byte, 1 = short, 2 = long) */
449 false, /* pc_relative */
451 complain_overflow_signed
, /* complain_on_overflow */
452 _bfd_mips_elf_gprel16_reloc
, /* special_function */
453 "R_MIPS_GPREL16", /* name */
454 true, /* partial_inplace */
455 0xffff, /* src_mask */
456 0xffff, /* dst_mask */
457 false), /* pcrel_offset */
459 /* Reference to literal section. */
460 HOWTO (R_MIPS_LITERAL
, /* type */
462 2, /* size (0 = byte, 1 = short, 2 = long) */
464 false, /* pc_relative */
466 complain_overflow_signed
, /* complain_on_overflow */
467 _bfd_mips_elf_gprel16_reloc
, /* special_function */
468 "R_MIPS_LITERAL", /* name */
469 true, /* partial_inplace */
470 0xffff, /* src_mask */
471 0xffff, /* dst_mask */
472 false), /* pcrel_offset */
474 /* Reference to global offset table. */
475 HOWTO (R_MIPS_GOT16
, /* type */
477 2, /* size (0 = byte, 1 = short, 2 = long) */
479 false, /* pc_relative */
481 complain_overflow_signed
, /* complain_on_overflow */
482 _bfd_mips_elf_got16_reloc
, /* special_function */
483 "R_MIPS_GOT16", /* name */
484 false, /* partial_inplace */
486 0xffff, /* dst_mask */
487 false), /* pcrel_offset */
489 /* 16 bit PC relative reference. */
490 HOWTO (R_MIPS_PC16
, /* type */
492 2, /* size (0 = byte, 1 = short, 2 = long) */
494 true, /* pc_relative */
496 complain_overflow_signed
, /* complain_on_overflow */
497 bfd_elf_generic_reloc
, /* special_function */
498 "R_MIPS_PC16", /* name */
499 true, /* partial_inplace */
500 0xffff, /* src_mask */
501 0xffff, /* dst_mask */
502 false), /* pcrel_offset */
504 /* 16 bit call through global offset table. */
505 /* FIXME: This is not handled correctly. */
506 HOWTO (R_MIPS_CALL16
, /* type */
508 2, /* size (0 = byte, 1 = short, 2 = long) */
510 false, /* pc_relative */
512 complain_overflow_signed
, /* complain_on_overflow */
513 bfd_elf_generic_reloc
, /* special_function */
514 "R_MIPS_CALL16", /* name */
515 false, /* partial_inplace */
517 0xffff, /* dst_mask */
518 false), /* pcrel_offset */
520 /* 32 bit GP relative reference. */
521 HOWTO (R_MIPS_GPREL32
, /* type */
523 2, /* size (0 = byte, 1 = short, 2 = long) */
525 false, /* pc_relative */
527 complain_overflow_bitfield
, /* complain_on_overflow */
528 _bfd_mips_elf_gprel32_reloc
, /* special_function */
529 "R_MIPS_GPREL32", /* name */
530 true, /* partial_inplace */
531 0xffffffff, /* src_mask */
532 0xffffffff, /* dst_mask */
533 false), /* pcrel_offset */
535 /* The remaining relocs are defined on Irix 5, although they are
536 not defined by the ABI. */
541 /* A 5 bit shift field. */
542 HOWTO (R_MIPS_SHIFT5
, /* type */
544 2, /* size (0 = byte, 1 = short, 2 = long) */
546 false, /* pc_relative */
548 complain_overflow_bitfield
, /* complain_on_overflow */
549 bfd_elf_generic_reloc
, /* special_function */
550 "R_MIPS_SHIFT5", /* name */
551 true, /* partial_inplace */
552 0x000007c0, /* src_mask */
553 0x000007c0, /* dst_mask */
554 false), /* pcrel_offset */
556 /* A 6 bit shift field. */
557 /* FIXME: This is not handled correctly; a special function is
558 needed to put the most significant bit in the right place. */
559 HOWTO (R_MIPS_SHIFT6
, /* type */
561 2, /* size (0 = byte, 1 = short, 2 = long) */
563 false, /* pc_relative */
565 complain_overflow_bitfield
, /* complain_on_overflow */
566 bfd_elf_generic_reloc
, /* special_function */
567 "R_MIPS_SHIFT6", /* name */
568 true, /* partial_inplace */
569 0x000007c4, /* src_mask */
570 0x000007c4, /* dst_mask */
571 false), /* pcrel_offset */
573 /* A 64 bit relocation. This is used in 32 bit ELF when addresses
574 are 64 bits long; the upper 32 bits are simply a sign extension.
575 The fields of the howto should be the same as for R_MIPS_32,
576 other than the type, name, and special_function. */
577 HOWTO (R_MIPS_64
, /* type */
579 2, /* size (0 = byte, 1 = short, 2 = long) */
581 false, /* pc_relative */
583 complain_overflow_bitfield
, /* complain_on_overflow */
584 mips32_64bit_reloc
, /* special_function */
585 "R_MIPS_64", /* name */
586 true, /* partial_inplace */
587 0xffffffff, /* src_mask */
588 0xffffffff, /* dst_mask */
589 false), /* pcrel_offset */
591 /* Displacement in the global offset table. */
592 /* FIXME: Not handled correctly. */
593 HOWTO (R_MIPS_GOT_DISP
, /* type */
595 2, /* size (0 = byte, 1 = short, 2 = long) */
597 false, /* pc_relative */
599 complain_overflow_bitfield
, /* complain_on_overflow */
600 bfd_elf_generic_reloc
, /* special_function */
601 "R_MIPS_GOT_DISP", /* name */
602 true, /* partial_inplace */
603 0x0000ffff, /* src_mask */
604 0x0000ffff, /* dst_mask */
605 false), /* pcrel_offset */
607 /* Displacement to page pointer in the global offset table. */
608 /* FIXME: Not handled correctly. */
609 HOWTO (R_MIPS_GOT_PAGE
, /* type */
611 2, /* size (0 = byte, 1 = short, 2 = long) */
613 false, /* pc_relative */
615 complain_overflow_bitfield
, /* complain_on_overflow */
616 bfd_elf_generic_reloc
, /* special_function */
617 "R_MIPS_GOT_PAGE", /* name */
618 true, /* partial_inplace */
619 0x0000ffff, /* src_mask */
620 0x0000ffff, /* dst_mask */
621 false), /* pcrel_offset */
623 /* Offset from page pointer in the global offset table. */
624 /* FIXME: Not handled correctly. */
625 HOWTO (R_MIPS_GOT_OFST
, /* type */
627 2, /* size (0 = byte, 1 = short, 2 = long) */
629 false, /* pc_relative */
631 complain_overflow_bitfield
, /* complain_on_overflow */
632 bfd_elf_generic_reloc
, /* special_function */
633 "R_MIPS_GOT_OFST", /* name */
634 true, /* partial_inplace */
635 0x0000ffff, /* src_mask */
636 0x0000ffff, /* dst_mask */
637 false), /* pcrel_offset */
639 /* High 16 bits of displacement in global offset table. */
640 /* FIXME: Not handled correctly. */
641 HOWTO (R_MIPS_GOT_HI16
, /* type */
643 2, /* size (0 = byte, 1 = short, 2 = long) */
645 false, /* pc_relative */
647 complain_overflow_dont
, /* complain_on_overflow */
648 bfd_elf_generic_reloc
, /* special_function */
649 "R_MIPS_GOT_HI16", /* name */
650 true, /* partial_inplace */
651 0x0000ffff, /* src_mask */
652 0x0000ffff, /* dst_mask */
653 false), /* pcrel_offset */
655 /* Low 16 bits of displacement in global offset table. */
656 /* FIXME: Not handled correctly. */
657 HOWTO (R_MIPS_GOT_LO16
, /* type */
659 2, /* size (0 = byte, 1 = short, 2 = long) */
661 false, /* pc_relative */
663 complain_overflow_dont
, /* complain_on_overflow */
664 bfd_elf_generic_reloc
, /* special_function */
665 "R_MIPS_GOT_LO16", /* name */
666 true, /* partial_inplace */
667 0x0000ffff, /* src_mask */
668 0x0000ffff, /* dst_mask */
669 false), /* pcrel_offset */
671 /* 64 bit subtraction. Used in the N32 ABI. */
672 /* FIXME: Not handled correctly. */
673 HOWTO (R_MIPS_SUB
, /* type */
675 4, /* size (0 = byte, 1 = short, 2 = long) */
677 false, /* pc_relative */
679 complain_overflow_bitfield
, /* complain_on_overflow */
680 bfd_elf_generic_reloc
, /* special_function */
681 "R_MIPS_SUB", /* name */
682 true, /* partial_inplace */
683 MINUS_ONE
, /* src_mask */
684 MINUS_ONE
, /* dst_mask */
685 false), /* pcrel_offset */
687 /* Used to cause the linker to insert and delete instructions? */
692 /* Get the higher values of a 64 bit addend. Presumably not used in
697 /* High 16 bits of displacement in global offset table. */
698 /* FIXME: Not handled correctly. */
699 HOWTO (R_MIPS_CALL_HI16
, /* type */
701 2, /* size (0 = byte, 1 = short, 2 = long) */
703 false, /* pc_relative */
705 complain_overflow_dont
, /* complain_on_overflow */
706 bfd_elf_generic_reloc
, /* special_function */
707 "R_MIPS_CALL_HI16", /* name */
708 true, /* partial_inplace */
709 0x0000ffff, /* src_mask */
710 0x0000ffff, /* dst_mask */
711 false), /* pcrel_offset */
713 /* Low 16 bits of displacement in global offset table. */
714 /* FIXME: Not handled correctly. */
715 HOWTO (R_MIPS_CALL_LO16
, /* type */
717 2, /* size (0 = byte, 1 = short, 2 = long) */
719 false, /* pc_relative */
721 complain_overflow_dont
, /* complain_on_overflow */
722 bfd_elf_generic_reloc
, /* special_function */
723 "R_MIPS_CALL_LO16", /* name */
724 true, /* partial_inplace */
725 0x0000ffff, /* src_mask */
726 0x0000ffff, /* dst_mask */
727 false), /* pcrel_offset */
731 { R_MIPS_ADD_IMMEDIATE
},
735 /* Protected jump conversion. This is an optimization hint. No
736 relocation is required for correctness. */
737 HOWTO (R_MIPS_JALR
, /* type */
739 0, /* size (0 = byte, 1 = short, 2 = long) */
741 false, /* pc_relative */
743 complain_overflow_dont
, /* complain_on_overflow */
744 bfd_elf_generic_reloc
, /* special_function */
745 "R_MIPS_JALR", /* name */
746 false, /* partial_inplace */
747 0x00000000, /* src_mask */
748 0x00000000, /* dst_mask */
749 false), /* pcrel_offset */
752 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
753 is a hack to make the linker think that we need 64 bit values. */
754 static reloc_howto_type elf_mips_ctor64_howto
=
755 HOWTO (R_MIPS_64
, /* type */
757 4, /* size (0 = byte, 1 = short, 2 = long) */
759 false, /* pc_relative */
761 complain_overflow_signed
, /* complain_on_overflow */
762 mips32_64bit_reloc
, /* special_function */
763 "R_MIPS_64", /* name */
764 true, /* partial_inplace */
765 0xffffffff, /* src_mask */
766 0xffffffff, /* dst_mask */
767 false); /* pcrel_offset */
769 /* The reloc used for the mips16 jump instruction. */
770 static reloc_howto_type elf_mips16_jump_howto
=
771 HOWTO (R_MIPS16_26
, /* type */
773 2, /* size (0 = byte, 1 = short, 2 = long) */
775 false, /* pc_relative */
777 complain_overflow_dont
, /* complain_on_overflow */
778 /* This needs complex overflow
779 detection, because the upper four
780 bits must match the PC. */
781 mips16_jump_reloc
, /* special_function */
782 "R_MIPS16_26", /* name */
783 true, /* partial_inplace */
784 0x3ffffff, /* src_mask */
785 0x3ffffff, /* dst_mask */
786 false); /* pcrel_offset */
788 /* The reloc used for the mips16 gprel instruction. The src_mask and
789 dsk_mask for this howto do not reflect the actual instruction, in
790 which the value is not contiguous; the masks are for the
791 convenience of the relocate_section routine. */
792 static reloc_howto_type elf_mips16_gprel_howto
=
793 HOWTO (R_MIPS16_GPREL
, /* type */
795 2, /* size (0 = byte, 1 = short, 2 = long) */
797 false, /* pc_relative */
799 complain_overflow_signed
, /* complain_on_overflow */
800 mips16_gprel_reloc
, /* special_function */
801 "R_MIPS16_GPREL", /* name */
802 true, /* partial_inplace */
803 0xffff, /* src_mask */
804 0xffff, /* dst_mask */
805 false); /* pcrel_offset */
808 /* GNU extension to record C++ vtable hierarchy */
809 static reloc_howto_type elf_mips_gnu_vtinherit_howto
=
810 HOWTO (R_MIPS_GNU_VTINHERIT
, /* type */
812 2, /* size (0 = byte, 1 = short, 2 = long) */
814 false, /* pc_relative */
816 complain_overflow_dont
, /* complain_on_overflow */
817 NULL
, /* special_function */
818 "R_MIPS_GNU_VTINHERIT", /* name */
819 false, /* partial_inplace */
822 false); /* pcrel_offset */
824 /* GNU extension to record C++ vtable member usage */
825 static reloc_howto_type elf_mips_gnu_vtentry_howto
=
826 HOWTO (R_MIPS_GNU_VTENTRY
, /* type */
828 2, /* size (0 = byte, 1 = short, 2 = long) */
830 false, /* pc_relative */
832 complain_overflow_dont
, /* complain_on_overflow */
833 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
834 "R_MIPS_GNU_VTENTRY", /* name */
835 false, /* partial_inplace */
838 false); /* pcrel_offset */
840 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
841 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
842 the HI16. Here we just save the information we need; we do the
843 actual relocation when we see the LO16. MIPS ELF requires that the
844 LO16 immediately follow the HI16. As a GNU extension, we permit an
845 arbitrary number of HI16 relocs to be associated with a single LO16
846 reloc. This extension permits gcc to output the HI and LO relocs
851 struct mips_hi16
*next
;
856 /* FIXME: This should not be a static variable. */
858 static struct mips_hi16
*mips_hi16_list
;
860 bfd_reloc_status_type
861 _bfd_mips_elf_hi16_reloc (abfd
,
869 arelent
*reloc_entry
;
872 asection
*input_section
;
874 char **error_message
;
876 bfd_reloc_status_type ret
;
880 /* If we're relocating, and this an external symbol, we don't want
881 to change anything. */
882 if (output_bfd
!= (bfd
*) NULL
883 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
884 && reloc_entry
->addend
== 0)
886 reloc_entry
->address
+= input_section
->output_offset
;
892 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
894 boolean relocateable
;
897 if (ret
== bfd_reloc_undefined
)
900 if (output_bfd
!= NULL
)
904 relocateable
= false;
905 output_bfd
= symbol
->section
->output_section
->owner
;
908 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
910 if (ret
!= bfd_reloc_ok
)
913 relocation
= gp
- reloc_entry
->address
;
917 if (bfd_is_und_section (symbol
->section
)
918 && output_bfd
== (bfd
*) NULL
)
919 ret
= bfd_reloc_undefined
;
921 if (bfd_is_com_section (symbol
->section
))
924 relocation
= symbol
->value
;
927 relocation
+= symbol
->section
->output_section
->vma
;
928 relocation
+= symbol
->section
->output_offset
;
929 relocation
+= reloc_entry
->addend
;
931 if (reloc_entry
->address
> input_section
->_cooked_size
)
932 return bfd_reloc_outofrange
;
934 /* Save the information, and let LO16 do the actual relocation. */
935 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
937 return bfd_reloc_outofrange
;
938 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
939 n
->addend
= relocation
;
940 n
->next
= mips_hi16_list
;
943 if (output_bfd
!= (bfd
*) NULL
)
944 reloc_entry
->address
+= input_section
->output_offset
;
949 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
950 inplace relocation; this function exists in order to do the
951 R_MIPS_HI16 relocation described above. */
953 bfd_reloc_status_type
954 _bfd_mips_elf_lo16_reloc (abfd
,
962 arelent
*reloc_entry
;
965 asection
*input_section
;
967 char **error_message
;
969 arelent gp_disp_relent
;
971 if (mips_hi16_list
!= NULL
)
981 struct mips_hi16
*next
;
983 /* Do the HI16 relocation. Note that we actually don't need
984 to know anything about the LO16 itself, except where to
985 find the low 16 bits of the addend needed by the LO16. */
986 insn
= bfd_get_32 (abfd
, l
->addr
);
987 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
989 val
= ((insn
& 0xffff) << 16) + vallo
;
992 /* The low order 16 bits are always treated as a signed
993 value. Therefore, a negative value in the low order bits
994 requires an adjustment in the high order bits. We need
995 to make this adjustment in two ways: once for the bits we
996 took from the data, and once for the bits we are putting
997 back in to the data. */
998 if ((vallo
& 0x8000) != 0)
1000 if ((val
& 0x8000) != 0)
1003 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
1004 bfd_put_32 (abfd
, insn
, l
->addr
);
1006 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1008 gp_disp_relent
= *reloc_entry
;
1009 reloc_entry
= &gp_disp_relent
;
1010 reloc_entry
->addend
= l
->addend
;
1018 mips_hi16_list
= NULL
;
1020 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1022 bfd_reloc_status_type ret
;
1023 bfd_vma gp
, relocation
;
1025 /* FIXME: Does this case ever occur? */
1027 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
1028 if (ret
!= bfd_reloc_ok
)
1031 relocation
= gp
- reloc_entry
->address
;
1032 relocation
+= symbol
->section
->output_section
->vma
;
1033 relocation
+= symbol
->section
->output_offset
;
1034 relocation
+= reloc_entry
->addend
;
1036 if (reloc_entry
->address
> input_section
->_cooked_size
)
1037 return bfd_reloc_outofrange
;
1039 gp_disp_relent
= *reloc_entry
;
1040 reloc_entry
= &gp_disp_relent
;
1041 reloc_entry
->addend
= relocation
- 4;
1044 /* Now do the LO16 reloc in the usual way. */
1045 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1046 input_section
, output_bfd
, error_message
);
1049 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1050 table used for PIC code. If the symbol is an external symbol, the
1051 instruction is modified to contain the offset of the appropriate
1052 entry in the global offset table. If the symbol is a section
1053 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1054 addends are combined to form the real addend against the section
1055 symbol; the GOT16 is modified to contain the offset of an entry in
1056 the global offset table, and the LO16 is modified to offset it
1057 appropriately. Thus an offset larger than 16 bits requires a
1058 modified value in the global offset table.
1060 This implementation suffices for the assembler, but the linker does
1061 not yet know how to create global offset tables. */
1063 bfd_reloc_status_type
1064 _bfd_mips_elf_got16_reloc (abfd
,
1072 arelent
*reloc_entry
;
1075 asection
*input_section
;
1077 char **error_message
;
1079 /* If we're relocating, and this an external symbol, we don't want
1080 to change anything. */
1081 if (output_bfd
!= (bfd
*) NULL
1082 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1083 && reloc_entry
->addend
== 0)
1085 reloc_entry
->address
+= input_section
->output_offset
;
1086 return bfd_reloc_ok
;
1089 /* If we're relocating, and this is a local symbol, we can handle it
1091 if (output_bfd
!= (bfd
*) NULL
1092 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1093 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1094 input_section
, output_bfd
, error_message
);
1099 /* We have to figure out the gp value, so that we can adjust the
1100 symbol value correctly. We look up the symbol _gp in the output
1101 BFD. If we can't find it, we're stuck. We cache it in the ELF
1102 target data. We don't need to adjust the symbol value for an
1103 external symbol if we are producing relocateable output. */
1105 static bfd_reloc_status_type
1106 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1109 boolean relocateable
;
1110 char **error_message
;
1113 if (bfd_is_und_section (symbol
->section
)
1117 return bfd_reloc_undefined
;
1120 *pgp
= _bfd_get_gp_value (output_bfd
);
1123 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1127 /* Make up a value. */
1128 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1129 _bfd_set_gp_value (output_bfd
, *pgp
);
1137 count
= bfd_get_symcount (output_bfd
);
1138 sym
= bfd_get_outsymbols (output_bfd
);
1140 if (sym
== (asymbol
**) NULL
)
1144 for (i
= 0; i
< count
; i
++, sym
++)
1146 register CONST
char *name
;
1148 name
= bfd_asymbol_name (*sym
);
1149 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1151 *pgp
= bfd_asymbol_value (*sym
);
1152 _bfd_set_gp_value (output_bfd
, *pgp
);
1160 /* Only get the error once. */
1162 _bfd_set_gp_value (output_bfd
, *pgp
);
1164 (char *) _("GP relative relocation when _gp not defined");
1165 return bfd_reloc_dangerous
;
1170 return bfd_reloc_ok
;
1173 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1174 become the offset from the gp register. This function also handles
1175 R_MIPS_LITERAL relocations, although those can be handled more
1176 cleverly because the entries in the .lit8 and .lit4 sections can be
1179 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1180 arelent
*, asection
*,
1181 boolean
, PTR
, bfd_vma
));
1183 bfd_reloc_status_type
1184 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1185 output_bfd
, error_message
)
1187 arelent
*reloc_entry
;
1190 asection
*input_section
;
1192 char **error_message
;
1194 boolean relocateable
;
1195 bfd_reloc_status_type ret
;
1198 /* If we're relocating, and this is an external symbol with no
1199 addend, we don't want to change anything. We will only have an
1200 addend if this is a newly created reloc, not read from an ELF
1202 if (output_bfd
!= (bfd
*) NULL
1203 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1204 && reloc_entry
->addend
== 0)
1206 reloc_entry
->address
+= input_section
->output_offset
;
1207 return bfd_reloc_ok
;
1210 if (output_bfd
!= (bfd
*) NULL
)
1211 relocateable
= true;
1214 relocateable
= false;
1215 output_bfd
= symbol
->section
->output_section
->owner
;
1218 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1220 if (ret
!= bfd_reloc_ok
)
1223 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1224 relocateable
, data
, gp
);
1227 static bfd_reloc_status_type
1228 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1232 arelent
*reloc_entry
;
1233 asection
*input_section
;
1234 boolean relocateable
;
1242 if (bfd_is_com_section (symbol
->section
))
1245 relocation
= symbol
->value
;
1247 relocation
+= symbol
->section
->output_section
->vma
;
1248 relocation
+= symbol
->section
->output_offset
;
1250 if (reloc_entry
->address
> input_section
->_cooked_size
)
1251 return bfd_reloc_outofrange
;
1253 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1255 /* Set val to the offset into the section or symbol. */
1256 if (reloc_entry
->howto
->src_mask
== 0)
1258 /* This case occurs with the 64-bit MIPS ELF ABI. */
1259 val
= reloc_entry
->addend
;
1263 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1268 /* Adjust val for the final section location and GP value. If we
1269 are producing relocateable output, we don't want to do this for
1270 an external symbol. */
1272 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1273 val
+= relocation
- gp
;
1275 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1276 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1279 reloc_entry
->address
+= input_section
->output_offset
;
1281 /* Make sure it fit in 16 bits. */
1282 if (val
>= 0x8000 && val
< 0xffff8000)
1283 return bfd_reloc_overflow
;
1285 return bfd_reloc_ok
;
1288 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1289 from the gp register? XXX */
1291 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1292 arelent
*, asection
*,
1293 boolean
, PTR
, bfd_vma
));
1295 bfd_reloc_status_type
1296 _bfd_mips_elf_gprel32_reloc (abfd
,
1304 arelent
*reloc_entry
;
1307 asection
*input_section
;
1309 char **error_message
;
1311 boolean relocateable
;
1312 bfd_reloc_status_type ret
;
1315 /* If we're relocating, and this is an external symbol with no
1316 addend, we don't want to change anything. We will only have an
1317 addend if this is a newly created reloc, not read from an ELF
1319 if (output_bfd
!= (bfd
*) NULL
1320 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1321 && reloc_entry
->addend
== 0)
1323 *error_message
= (char *)
1324 _("32bits gp relative relocation occurs for an external symbol");
1325 return bfd_reloc_outofrange
;
1328 if (output_bfd
!= (bfd
*) NULL
)
1330 relocateable
= true;
1331 gp
= _bfd_get_gp_value (output_bfd
);
1335 relocateable
= false;
1336 output_bfd
= symbol
->section
->output_section
->owner
;
1338 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1339 error_message
, &gp
);
1340 if (ret
!= bfd_reloc_ok
)
1344 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1345 relocateable
, data
, gp
);
1348 static bfd_reloc_status_type
1349 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1353 arelent
*reloc_entry
;
1354 asection
*input_section
;
1355 boolean relocateable
;
1362 if (bfd_is_com_section (symbol
->section
))
1365 relocation
= symbol
->value
;
1367 relocation
+= symbol
->section
->output_section
->vma
;
1368 relocation
+= symbol
->section
->output_offset
;
1370 if (reloc_entry
->address
> input_section
->_cooked_size
)
1371 return bfd_reloc_outofrange
;
1373 if (reloc_entry
->howto
->src_mask
== 0)
1375 /* This case arises with the 64-bit MIPS ELF ABI. */
1379 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1381 /* Set val to the offset into the section or symbol. */
1382 val
+= reloc_entry
->addend
;
1384 /* Adjust val for the final section location and GP value. If we
1385 are producing relocateable output, we don't want to do this for
1386 an external symbol. */
1388 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1389 val
+= relocation
- gp
;
1391 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1394 reloc_entry
->address
+= input_section
->output_offset
;
1396 return bfd_reloc_ok
;
1399 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1400 generated when addreses are 64 bits. The upper 32 bits are a simle
1403 static bfd_reloc_status_type
1404 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1405 output_bfd
, error_message
)
1407 arelent
*reloc_entry
;
1410 asection
*input_section
;
1412 char **error_message
;
1414 bfd_reloc_status_type r
;
1419 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1420 input_section
, output_bfd
, error_message
);
1421 if (r
!= bfd_reloc_continue
)
1424 /* Do a normal 32 bit relocation on the lower 32 bits. */
1425 reloc32
= *reloc_entry
;
1426 if (bfd_big_endian (abfd
))
1427 reloc32
.address
+= 4;
1428 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1429 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1430 output_bfd
, error_message
);
1432 /* Sign extend into the upper 32 bits. */
1433 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1434 if ((val
& 0x80000000) != 0)
1438 addr
= reloc_entry
->address
;
1439 if (bfd_little_endian (abfd
))
1441 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1446 /* Handle a mips16 jump. */
1448 static bfd_reloc_status_type
1449 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1450 output_bfd
, error_message
)
1452 arelent
*reloc_entry
;
1455 asection
*input_section
;
1457 char **error_message
;
1459 if (output_bfd
!= (bfd
*) NULL
1460 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1461 && reloc_entry
->addend
== 0)
1463 reloc_entry
->address
+= input_section
->output_offset
;
1464 return bfd_reloc_ok
;
1469 static boolean warned
;
1472 (*_bfd_error_handler
)
1473 (_("Linking mips16 objects into %s format is not supported"),
1474 bfd_get_target (input_section
->output_section
->owner
));
1478 return bfd_reloc_undefined
;
1481 /* Handle a mips16 GP relative reloc. */
1483 static bfd_reloc_status_type
1484 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1485 output_bfd
, error_message
)
1487 arelent
*reloc_entry
;
1490 asection
*input_section
;
1492 char **error_message
;
1494 boolean relocateable
;
1495 bfd_reloc_status_type ret
;
1497 unsigned short extend
, insn
;
1498 unsigned long final
;
1500 /* If we're relocating, and this is an external symbol with no
1501 addend, we don't want to change anything. We will only have an
1502 addend if this is a newly created reloc, not read from an ELF
1504 if (output_bfd
!= NULL
1505 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1506 && reloc_entry
->addend
== 0)
1508 reloc_entry
->address
+= input_section
->output_offset
;
1509 return bfd_reloc_ok
;
1512 if (output_bfd
!= NULL
)
1513 relocateable
= true;
1516 relocateable
= false;
1517 output_bfd
= symbol
->section
->output_section
->owner
;
1520 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1522 if (ret
!= bfd_reloc_ok
)
1525 if (reloc_entry
->address
> input_section
->_cooked_size
)
1526 return bfd_reloc_outofrange
;
1528 /* Pick up the mips16 extend instruction and the real instruction. */
1529 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1530 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1532 /* Stuff the current addend back as a 32 bit value, do the usual
1533 relocation, and then clean up. */
1535 (((extend
& 0x1f) << 11)
1538 (bfd_byte
*) data
+ reloc_entry
->address
);
1540 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1541 relocateable
, data
, gp
);
1543 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1546 | ((final
>> 11) & 0x1f)
1548 (bfd_byte
*) data
+ reloc_entry
->address
);
1552 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1557 /* Return the ISA for a MIPS e_flags value. */
1560 elf_mips_isa (flags
)
1563 switch (flags
& EF_MIPS_ARCH
)
1577 /* Return the MACH for a MIPS e_flags value. */
1580 elf_mips_mach (flags
)
1583 switch (flags
& EF_MIPS_MACH
)
1585 case E_MIPS_MACH_3900
:
1586 return bfd_mach_mips3900
;
1588 case E_MIPS_MACH_4010
:
1589 return bfd_mach_mips4010
;
1591 case E_MIPS_MACH_4100
:
1592 return bfd_mach_mips4100
;
1594 case E_MIPS_MACH_4111
:
1595 return bfd_mach_mips4111
;
1597 case E_MIPS_MACH_4650
:
1598 return bfd_mach_mips4650
;
1601 switch (flags
& EF_MIPS_ARCH
)
1605 return bfd_mach_mips3000
;
1609 return bfd_mach_mips6000
;
1613 return bfd_mach_mips4000
;
1617 return bfd_mach_mips8000
;
1625 /* Return printable name for ABI from flagword. */
1628 elf_mips_abi_name (flags
)
1631 switch (flags
& EF_MIPS_ABI
)
1635 case E_MIPS_ABI_O32
:
1637 case E_MIPS_ABI_O64
:
1639 case E_MIPS_ABI_EABI32
:
1641 case E_MIPS_ABI_EABI64
:
1644 return "unknown abi";
1648 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1650 struct elf_reloc_map
{
1651 bfd_reloc_code_real_type bfd_reloc_val
;
1652 enum elf_mips_reloc_type elf_reloc_val
;
1655 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1657 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1658 { BFD_RELOC_16
, R_MIPS_16
},
1659 { BFD_RELOC_32
, R_MIPS_32
},
1660 { BFD_RELOC_64
, R_MIPS_64
},
1661 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1662 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1663 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1664 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1665 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1666 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1667 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1668 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1669 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1670 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1671 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1672 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1673 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
},
1674 { BFD_RELOC_MIPS_SUB
, R_MIPS_SUB
},
1675 { BFD_RELOC_MIPS_GOT_PAGE
, R_MIPS_GOT_PAGE
},
1676 { BFD_RELOC_MIPS_GOT_OFST
, R_MIPS_GOT_OFST
},
1677 { BFD_RELOC_MIPS_GOT_DISP
, R_MIPS_GOT_DISP
}
1680 /* Given a BFD reloc type, return a howto structure. */
1682 static reloc_howto_type
*
1683 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1685 bfd_reloc_code_real_type code
;
1689 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1691 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1692 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1698 bfd_set_error (bfd_error_bad_value
);
1701 case BFD_RELOC_CTOR
:
1702 /* We need to handle BFD_RELOC_CTOR specially.
1703 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1704 size of addresses on this architecture. */
1705 if (bfd_arch_bits_per_address (abfd
) == 32)
1706 return &elf_mips_howto_table
[(int) R_MIPS_32
];
1708 return &elf_mips_ctor64_howto
;
1710 case BFD_RELOC_MIPS16_JMP
:
1711 return &elf_mips16_jump_howto
;
1712 case BFD_RELOC_MIPS16_GPREL
:
1713 return &elf_mips16_gprel_howto
;
1714 case BFD_RELOC_VTABLE_INHERIT
:
1715 return &elf_mips_gnu_vtinherit_howto
;
1716 case BFD_RELOC_VTABLE_ENTRY
:
1717 return &elf_mips_gnu_vtentry_howto
;
1721 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
1724 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1727 Elf32_Internal_Rel
*dst
;
1729 unsigned int r_type
;
1731 r_type
= ELF32_R_TYPE (dst
->r_info
);
1735 cache_ptr
->howto
= &elf_mips16_jump_howto
;
1737 case R_MIPS16_GPREL
:
1738 cache_ptr
->howto
= &elf_mips16_gprel_howto
;
1740 case R_MIPS_GNU_VTINHERIT
:
1741 cache_ptr
->howto
= &elf_mips_gnu_vtinherit_howto
;
1743 case R_MIPS_GNU_VTENTRY
:
1744 cache_ptr
->howto
= &elf_mips_gnu_vtentry_howto
;
1748 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1749 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1753 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1754 value for the object file. We get the addend now, rather than
1755 when we do the relocation, because the symbol manipulations done
1756 by the linker may cause us to lose track of the input BFD. */
1757 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1758 && (r_type
== (unsigned int) R_MIPS_GPREL16
1759 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1760 cache_ptr
->addend
= elf_gp (abfd
);
1763 /* Given a MIPS Elf32_Internal_Rela, fill in an arelent structure. */
1766 mips_info_to_howto_rela (abfd
, cache_ptr
, dst
)
1769 Elf32_Internal_Rela
*dst
;
1771 /* Since an Elf32_Internal_Rel is an initial prefix of an
1772 Elf32_Internal_Rela, we can just use mips_info_to_howto_rel
1774 mips_info_to_howto_rel (abfd
, cache_ptr
, (Elf32_Internal_Rel
*) dst
);
1776 /* If we ever need to do any extra processing with dst->r_addend
1777 (the field omitted in an Elf32_Internal_Rel) we can do it here. */
1780 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1781 routines swap this structure in and out. They are used outside of
1782 BFD, so they are globally visible. */
1785 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1787 const Elf32_External_RegInfo
*ex
;
1790 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1791 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1792 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1793 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1794 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1795 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1799 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1801 const Elf32_RegInfo
*in
;
1802 Elf32_External_RegInfo
*ex
;
1804 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1805 (bfd_byte
*) ex
->ri_gprmask
);
1806 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1807 (bfd_byte
*) ex
->ri_cprmask
[0]);
1808 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1809 (bfd_byte
*) ex
->ri_cprmask
[1]);
1810 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1811 (bfd_byte
*) ex
->ri_cprmask
[2]);
1812 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1813 (bfd_byte
*) ex
->ri_cprmask
[3]);
1814 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1815 (bfd_byte
*) ex
->ri_gp_value
);
1818 /* In the 64 bit ABI, the .MIPS.options section holds register
1819 information in an Elf64_Reginfo structure. These routines swap
1820 them in and out. They are globally visible because they are used
1821 outside of BFD. These routines are here so that gas can call them
1822 without worrying about whether the 64 bit ABI has been included. */
1825 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1827 const Elf64_External_RegInfo
*ex
;
1828 Elf64_Internal_RegInfo
*in
;
1830 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1831 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
1832 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1833 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1834 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1835 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1836 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1840 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1842 const Elf64_Internal_RegInfo
*in
;
1843 Elf64_External_RegInfo
*ex
;
1845 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1846 (bfd_byte
*) ex
->ri_gprmask
);
1847 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
1848 (bfd_byte
*) ex
->ri_pad
);
1849 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1850 (bfd_byte
*) ex
->ri_cprmask
[0]);
1851 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1852 (bfd_byte
*) ex
->ri_cprmask
[1]);
1853 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1854 (bfd_byte
*) ex
->ri_cprmask
[2]);
1855 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1856 (bfd_byte
*) ex
->ri_cprmask
[3]);
1857 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1858 (bfd_byte
*) ex
->ri_gp_value
);
1861 /* Swap an entry in a .gptab section. Note that these routines rely
1862 on the equivalence of the two elements of the union. */
1865 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1867 const Elf32_External_gptab
*ex
;
1870 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1871 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1875 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1877 const Elf32_gptab
*in
;
1878 Elf32_External_gptab
*ex
;
1880 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1881 ex
->gt_entry
.gt_g_value
);
1882 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1883 ex
->gt_entry
.gt_bytes
);
1887 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1889 const Elf32_compact_rel
*in
;
1890 Elf32_External_compact_rel
*ex
;
1892 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
1893 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
1894 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
1895 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
1896 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
1897 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
1901 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1903 const Elf32_crinfo
*in
;
1904 Elf32_External_crinfo
*ex
;
1908 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1909 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1910 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1911 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1912 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
1913 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
1914 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
1917 /* Swap in an options header. */
1920 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1922 const Elf_External_Options
*ex
;
1923 Elf_Internal_Options
*in
;
1925 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
1926 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
1927 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
1928 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
1931 /* Swap out an options header. */
1934 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
1936 const Elf_Internal_Options
*in
;
1937 Elf_External_Options
*ex
;
1939 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
1940 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
1941 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
1942 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
1945 /* Swap in an MSYM entry. */
1948 bfd_mips_elf_swap_msym_in (abfd
, ex
, in
)
1950 const Elf32_External_Msym
*ex
;
1951 Elf32_Internal_Msym
*in
;
1953 in
->ms_hash_value
= bfd_h_get_32 (abfd
, ex
->ms_hash_value
);
1954 in
->ms_info
= bfd_h_get_32 (abfd
, ex
->ms_info
);
1957 /* Swap out an MSYM entry. */
1960 bfd_mips_elf_swap_msym_out (abfd
, in
, ex
)
1962 const Elf32_Internal_Msym
*in
;
1963 Elf32_External_Msym
*ex
;
1965 bfd_h_put_32 (abfd
, in
->ms_hash_value
, ex
->ms_hash_value
);
1966 bfd_h_put_32 (abfd
, in
->ms_info
, ex
->ms_info
);
1970 /* Determine whether a symbol is global for the purposes of splitting
1971 the symbol table into global symbols and local symbols. At least
1972 on Irix 5, this split must be between section symbols and all other
1973 symbols. On most ELF targets the split is between static symbols
1974 and externally visible symbols. */
1978 mips_elf_sym_is_global (abfd
, sym
)
1982 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
1985 /* Set the right machine number for a MIPS ELF file. This is used for
1986 both the 32-bit and the 64-bit ABI. */
1989 _bfd_mips_elf_object_p (abfd
)
1992 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
,
1993 elf_mips_mach (elf_elfheader (abfd
)->e_flags
));
1997 /* Set the right machine number for a 32-bit MIPS ELF file. */
2000 mips_elf32_object_p (abfd
)
2003 /* Irix 5 is broken. Object file symbol tables are not always
2004 sorted correctly such that local symbols precede global symbols,
2005 and the sh_info field in the symbol table is not always right. */
2006 elf_bad_symtab (abfd
) = true;
2008 return _bfd_mips_elf_object_p (abfd
);
2011 /* The final processing done just before writing out a MIPS ELF object
2012 file. This gets the MIPS architecture right based on the machine
2013 number. This is used by both the 32-bit and the 64-bit ABI. */
2017 _bfd_mips_elf_final_write_processing (abfd
, linker
)
2023 Elf_Internal_Shdr
**hdrpp
;
2027 switch (bfd_get_mach (abfd
))
2030 case bfd_mach_mips3000
:
2031 val
= E_MIPS_ARCH_1
;
2034 case bfd_mach_mips3900
:
2035 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
2038 case bfd_mach_mips6000
:
2039 val
= E_MIPS_ARCH_2
;
2042 case bfd_mach_mips4000
:
2043 case bfd_mach_mips4300
:
2044 val
= E_MIPS_ARCH_3
;
2047 case bfd_mach_mips4010
:
2048 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
2051 case bfd_mach_mips4100
:
2052 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
2055 case bfd_mach_mips4111
:
2056 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
2059 case bfd_mach_mips4650
:
2060 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
2063 case bfd_mach_mips8000
:
2064 val
= E_MIPS_ARCH_4
;
2068 elf_elfheader (abfd
)->e_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2069 elf_elfheader (abfd
)->e_flags
|= val
;
2071 /* Set the sh_info field for .gptab sections and other appropriate
2072 info for each special section. */
2073 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
2074 i
< elf_elfheader (abfd
)->e_shnum
;
2077 switch ((*hdrpp
)->sh_type
)
2080 case SHT_MIPS_LIBLIST
:
2081 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
2083 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2086 case SHT_MIPS_GPTAB
:
2087 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2088 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2089 BFD_ASSERT (name
!= NULL
2090 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
2091 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
2092 BFD_ASSERT (sec
!= NULL
);
2093 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2096 case SHT_MIPS_CONTENT
:
2097 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2098 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2099 BFD_ASSERT (name
!= NULL
2100 && strncmp (name
, ".MIPS.content",
2101 sizeof ".MIPS.content" - 1) == 0);
2102 sec
= bfd_get_section_by_name (abfd
,
2103 name
+ sizeof ".MIPS.content" - 1);
2104 BFD_ASSERT (sec
!= NULL
);
2105 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2108 case SHT_MIPS_SYMBOL_LIB
:
2109 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
2111 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2112 sec
= bfd_get_section_by_name (abfd
, ".liblist");
2114 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2117 case SHT_MIPS_EVENTS
:
2118 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2119 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2120 BFD_ASSERT (name
!= NULL
);
2121 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
2122 sec
= bfd_get_section_by_name (abfd
,
2123 name
+ sizeof ".MIPS.events" - 1);
2126 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
2127 sizeof ".MIPS.post_rel" - 1) == 0);
2128 sec
= bfd_get_section_by_name (abfd
,
2130 + sizeof ".MIPS.post_rel" - 1));
2132 BFD_ASSERT (sec
!= NULL
);
2133 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2140 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
2143 _bfd_mips_elf_set_private_flags (abfd
, flags
)
2147 BFD_ASSERT (!elf_flags_init (abfd
)
2148 || elf_elfheader (abfd
)->e_flags
== flags
);
2150 elf_elfheader (abfd
)->e_flags
= flags
;
2151 elf_flags_init (abfd
) = true;
2155 /* Copy backend specific data from one object module to another */
2158 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
2162 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2163 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2166 BFD_ASSERT (!elf_flags_init (obfd
)
2167 || (elf_elfheader (obfd
)->e_flags
2168 == elf_elfheader (ibfd
)->e_flags
));
2170 elf_gp (obfd
) = elf_gp (ibfd
);
2171 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
2172 elf_flags_init (obfd
) = true;
2176 /* Merge backend specific data from an object file to the output
2177 object file when linking. */
2180 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
2188 /* Check if we have the same endianess */
2189 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2190 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2194 if (bfd_big_endian (ibfd
))
2195 msg
= _("%s: compiled for a big endian system and target is little endian");
2197 msg
= _("%s: compiled for a little endian system and target is big endian");
2199 (*_bfd_error_handler
) (msg
, bfd_get_filename (ibfd
));
2201 bfd_set_error (bfd_error_wrong_format
);
2205 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2206 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2209 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2210 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
2211 old_flags
= elf_elfheader (obfd
)->e_flags
;
2213 if (! elf_flags_init (obfd
))
2215 elf_flags_init (obfd
) = true;
2216 elf_elfheader (obfd
)->e_flags
= new_flags
;
2218 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2219 && bfd_get_arch_info (obfd
)->the_default
)
2221 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
2222 bfd_get_mach (ibfd
)))
2229 /* Check flag compatibility. */
2231 new_flags
&= ~EF_MIPS_NOREORDER
;
2232 old_flags
&= ~EF_MIPS_NOREORDER
;
2234 if (new_flags
== old_flags
)
2239 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
2241 new_flags
&= ~EF_MIPS_PIC
;
2242 old_flags
&= ~EF_MIPS_PIC
;
2243 (*_bfd_error_handler
)
2244 (_("%s: linking PIC files with non-PIC files"),
2245 bfd_get_filename (ibfd
));
2249 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
2251 new_flags
&= ~EF_MIPS_CPIC
;
2252 old_flags
&= ~EF_MIPS_CPIC
;
2253 (*_bfd_error_handler
)
2254 (_("%s: linking abicalls files with non-abicalls files"),
2255 bfd_get_filename (ibfd
));
2259 /* Compare the ISA's. */
2260 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
2261 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
2263 int new_mach
= new_flags
& EF_MIPS_MACH
;
2264 int old_mach
= old_flags
& EF_MIPS_MACH
;
2265 int new_isa
= elf_mips_isa (new_flags
);
2266 int old_isa
= elf_mips_isa (old_flags
);
2268 /* If either has no machine specified, just compare the general isa's.
2269 Some combinations of machines are ok, if the isa's match. */
2272 || new_mach
== old_mach
2275 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
2276 and -mips4 code. They will normally use the same data sizes and
2277 calling conventions. */
2279 if ((new_isa
== 1 || new_isa
== 2)
2280 ? (old_isa
!= 1 && old_isa
!= 2)
2281 : (old_isa
== 1 || old_isa
== 2))
2283 (*_bfd_error_handler
)
2284 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
2285 bfd_get_filename (ibfd
), new_isa
, old_isa
);
2292 (*_bfd_error_handler
)
2293 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
2294 bfd_get_filename (ibfd
),
2295 elf_mips_mach (new_flags
),
2296 elf_mips_mach (old_flags
));
2300 new_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2301 old_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2305 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
))
2307 /* Only error if both are set (to different values). */
2308 if ((new_flags
& EF_MIPS_ABI
)
2309 && (old_flags
& EF_MIPS_ABI
))
2311 (*_bfd_error_handler
)
2312 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
2313 bfd_get_filename (ibfd
),
2314 elf_mips_abi_name (new_flags
),
2315 elf_mips_abi_name (old_flags
));
2318 new_flags
&= ~EF_MIPS_ABI
;
2319 old_flags
&= ~EF_MIPS_ABI
;
2322 /* Warn about any other mismatches */
2323 if (new_flags
!= old_flags
)
2325 (*_bfd_error_handler
)
2326 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2327 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
2328 (unsigned long) old_flags
);
2334 bfd_set_error (bfd_error_bad_value
);
2342 _bfd_mips_elf_print_private_bfd_data (abfd
, ptr
)
2346 FILE *file
= (FILE *) ptr
;
2348 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
2350 /* Print normal ELF private data. */
2351 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
2353 /* xgettext:c-format */
2354 fprintf (file
, _ ("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
2356 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
2357 fprintf (file
, _ (" [abi=O32]"));
2358 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
2359 fprintf (file
, _ (" [abi=O64]"));
2360 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
2361 fprintf (file
, _ (" [abi=EABI32]"));
2362 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
2363 fprintf (file
, _ (" [abi=EABI64]"));
2364 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
2365 fprintf (file
, _ (" [abi unknown]"));
2366 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI2
))
2367 fprintf (file
, _ (" [abi=N32]"));
2369 fprintf (file
, _ (" [no abi set]"));
2371 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
2372 fprintf (file
, _ (" [mips1]"));
2373 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
2374 fprintf (file
, _ (" [mips2]"));
2375 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
2376 fprintf (file
, _ (" [mips3]"));
2377 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
2378 fprintf (file
, _ (" [mips4]"));
2380 fprintf (file
, _ (" [unknown ISA]"));
2382 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
2383 fprintf (file
, _ (" [32bitmode]"));
2385 fprintf (file
, _ (" [not 32bitmode]"));
2392 /* Handle a MIPS specific section when reading an object file. This
2393 is called when elfcode.h finds a section with an unknown type.
2394 This routine supports both the 32-bit and 64-bit ELF ABI.
2396 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2400 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
2402 Elf_Internal_Shdr
*hdr
;
2407 /* There ought to be a place to keep ELF backend specific flags, but
2408 at the moment there isn't one. We just keep track of the
2409 sections by their name, instead. Fortunately, the ABI gives
2410 suggested names for all the MIPS specific sections, so we will
2411 probably get away with this. */
2412 switch (hdr
->sh_type
)
2414 case SHT_MIPS_LIBLIST
:
2415 if (strcmp (name
, ".liblist") != 0)
2419 if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) != 0)
2422 case SHT_MIPS_CONFLICT
:
2423 if (strcmp (name
, ".conflict") != 0)
2426 case SHT_MIPS_GPTAB
:
2427 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
2430 case SHT_MIPS_UCODE
:
2431 if (strcmp (name
, ".ucode") != 0)
2434 case SHT_MIPS_DEBUG
:
2435 if (strcmp (name
, ".mdebug") != 0)
2437 flags
= SEC_DEBUGGING
;
2439 case SHT_MIPS_REGINFO
:
2440 if (strcmp (name
, ".reginfo") != 0
2441 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
2443 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
2445 case SHT_MIPS_IFACE
:
2446 if (strcmp (name
, ".MIPS.interfaces") != 0)
2449 case SHT_MIPS_CONTENT
:
2450 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2453 case SHT_MIPS_OPTIONS
:
2454 if (strcmp (name
, ".options") != 0
2455 && strcmp (name
, ".MIPS.options") != 0)
2458 case SHT_MIPS_DWARF
:
2459 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2462 case SHT_MIPS_SYMBOL_LIB
:
2463 if (strcmp (name
, ".MIPS.symlib") != 0)
2466 case SHT_MIPS_EVENTS
:
2467 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2468 && strncmp (name
, ".MIPS.post_rel",
2469 sizeof ".MIPS.post_rel" - 1) != 0)
2476 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2481 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
2482 (bfd_get_section_flags (abfd
,
2491 /* Handle a 32-bit MIPS ELF specific section. */
2494 mips_elf32_section_from_shdr (abfd
, hdr
, name
)
2496 Elf_Internal_Shdr
*hdr
;
2499 if (! _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
))
2502 /* FIXME: We should record sh_info for a .gptab section. */
2504 /* For a .reginfo section, set the gp value in the tdata information
2505 from the contents of this section. We need the gp value while
2506 processing relocs, so we just get it now. The .reginfo section
2507 is not used in the 64-bit MIPS ELF ABI. */
2508 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2510 Elf32_External_RegInfo ext
;
2513 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
2514 (file_ptr
) 0, sizeof ext
))
2516 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
2517 elf_gp (abfd
) = s
.ri_gp_value
;
2520 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2521 set the gp value based on what we find. We may see both
2522 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2523 they should agree. */
2524 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
2526 bfd_byte
*contents
, *l
, *lend
;
2528 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
2529 if (contents
== NULL
)
2531 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
2532 (file_ptr
) 0, hdr
->sh_size
))
2538 lend
= contents
+ hdr
->sh_size
;
2539 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2541 Elf_Internal_Options intopt
;
2543 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2545 if (intopt
.kind
== ODK_REGINFO
)
2547 Elf32_RegInfo intreg
;
2549 bfd_mips_elf32_swap_reginfo_in
2551 ((Elf32_External_RegInfo
*)
2552 (l
+ sizeof (Elf_External_Options
))),
2554 elf_gp (abfd
) = intreg
.ri_gp_value
;
2564 /* Set the correct type for a MIPS ELF section. We do this by the
2565 section name, which is a hack, but ought to work. This routine is
2566 used by both the 32-bit and the 64-bit ABI. */
2569 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
2571 Elf32_Internal_Shdr
*hdr
;
2574 register const char *name
;
2576 name
= bfd_get_section_name (abfd
, sec
);
2578 if (strcmp (name
, ".liblist") == 0)
2580 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
2581 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
2582 /* The sh_link field is set in final_write_processing. */
2584 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) == 0)
2586 hdr
->sh_type
= SHT_MIPS_MSYM
;
2587 hdr
->sh_entsize
= 8;
2588 /* FIXME: Set the sh_info field. */
2590 else if (strcmp (name
, ".conflict") == 0)
2591 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
2592 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2594 hdr
->sh_type
= SHT_MIPS_GPTAB
;
2595 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
2596 /* The sh_info field is set in final_write_processing. */
2598 else if (strcmp (name
, ".ucode") == 0)
2599 hdr
->sh_type
= SHT_MIPS_UCODE
;
2600 else if (strcmp (name
, ".mdebug") == 0)
2602 hdr
->sh_type
= SHT_MIPS_DEBUG
;
2603 /* In a shared object on Irix 5.3, the .mdebug section has an
2604 entsize of 0. FIXME: Does this matter? */
2605 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2606 hdr
->sh_entsize
= 0;
2608 hdr
->sh_entsize
= 1;
2610 else if (strcmp (name
, ".reginfo") == 0)
2612 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2613 /* In a shared object on Irix 5.3, the .reginfo section has an
2614 entsize of 0x18. FIXME: Does this matter? */
2615 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2616 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2618 hdr
->sh_entsize
= 1;
2620 else if (SGI_COMPAT (abfd
)
2621 && (strcmp (name
, ".hash") == 0
2622 || strcmp (name
, ".dynamic") == 0
2623 || strcmp (name
, ".dynstr") == 0))
2625 hdr
->sh_entsize
= 0;
2627 /* This isn't how the Irix 6 linker behaves. */
2628 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2631 else if (strcmp (name
, ".got") == 0
2632 || strcmp (name
, ".sdata") == 0
2633 || strcmp (name
, ".sbss") == 0
2634 || strcmp (name
, ".lit4") == 0
2635 || strcmp (name
, ".lit8") == 0)
2636 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2637 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2639 hdr
->sh_type
= SHT_MIPS_IFACE
;
2640 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2642 else if (strncmp (name
, ".MIPS.content", strlen (".MIPS.content")) == 0)
2644 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2645 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2646 /* The sh_info field is set in final_write_processing. */
2648 else if (strcmp (name
, ".options") == 0
2649 || strcmp (name
, ".MIPS.options") == 0)
2651 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2652 hdr
->sh_entsize
= 1;
2653 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2655 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2656 hdr
->sh_type
= SHT_MIPS_DWARF
;
2657 else if (strcmp (name
, ".MIPS.symlib") == 0)
2659 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2660 /* The sh_link and sh_info fields are set in
2661 final_write_processing. */
2663 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2664 || strncmp (name
, ".MIPS.post_rel",
2665 sizeof ".MIPS.post_rel" - 1) == 0)
2667 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2668 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2669 /* The sh_link field is set in final_write_processing. */
2671 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) == 0)
2673 hdr
->sh_type
= SHT_MIPS_MSYM
;
2674 hdr
->sh_flags
|= SHF_ALLOC
;
2675 hdr
->sh_entsize
= 8;
2681 /* Given a BFD section, try to locate the corresponding ELF section
2682 index. This is used by both the 32-bit and the 64-bit ABI.
2683 Actually, it's not clear to me that the 64-bit ABI supports these,
2684 but for non-PIC objects we will certainly want support for at least
2685 the .scommon section. */
2688 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2690 Elf32_Internal_Shdr
*hdr
;
2694 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2696 *retval
= SHN_MIPS_SCOMMON
;
2699 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2701 *retval
= SHN_MIPS_ACOMMON
;
2707 /* When are writing out the .options or .MIPS.options section,
2708 remember the bytes we are writing out, so that we can install the
2709 GP value in the section_processing routine. */
2712 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2717 bfd_size_type count
;
2719 if (strcmp (section
->name
, ".options") == 0
2720 || strcmp (section
->name
, ".MIPS.options") == 0)
2724 if (elf_section_data (section
) == NULL
)
2726 section
->used_by_bfd
=
2727 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
2728 if (elf_section_data (section
) == NULL
)
2731 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
2736 if (section
->_cooked_size
!= 0)
2737 size
= section
->_cooked_size
;
2739 size
= section
->_raw_size
;
2740 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
2743 elf_section_data (section
)->tdata
= (PTR
) c
;
2746 memcpy (c
+ offset
, location
, count
);
2749 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
2753 /* Work over a section just before writing it out. This routine is
2754 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2755 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2759 _bfd_mips_elf_section_processing (abfd
, hdr
)
2761 Elf_Internal_Shdr
*hdr
;
2763 if (hdr
->bfd_section
!= NULL
)
2765 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
2767 if (strcmp (name
, ".sdata") == 0)
2769 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2770 hdr
->sh_type
= SHT_PROGBITS
;
2772 else if (strcmp (name
, ".sbss") == 0)
2774 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2775 hdr
->sh_type
= SHT_NOBITS
;
2777 else if (strcmp (name
, ".lit8") == 0
2778 || strcmp (name
, ".lit4") == 0)
2780 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2781 hdr
->sh_type
= SHT_PROGBITS
;
2783 else if (strcmp (name
, ".compact_rel") == 0)
2786 hdr
->sh_type
= SHT_PROGBITS
;
2788 else if (strcmp (name
, ".rtproc") == 0)
2790 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
2792 unsigned int adjust
;
2794 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
2796 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
2804 /* Work over a section just before writing it out. We update the GP
2805 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2806 on the value we are using. */
2809 mips_elf32_section_processing (abfd
, hdr
)
2811 Elf32_Internal_Shdr
*hdr
;
2813 if (hdr
->sh_type
== SHT_MIPS_REGINFO
2814 && hdr
->sh_size
> 0)
2818 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2819 BFD_ASSERT (hdr
->contents
== NULL
);
2822 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2825 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2826 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2830 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2831 && hdr
->bfd_section
!= NULL
2832 && elf_section_data (hdr
->bfd_section
) != NULL
2833 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2835 bfd_byte
*contents
, *l
, *lend
;
2837 /* We stored the section contents in the elf_section_data tdata
2838 field in the set_section_contents routine. We save the
2839 section contents so that we don't have to read them again.
2840 At this point we know that elf_gp is set, so we can look
2841 through the section contents to see if there is an
2842 ODK_REGINFO structure. */
2844 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2846 lend
= contents
+ hdr
->sh_size
;
2847 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2849 Elf_Internal_Options intopt
;
2851 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2853 if (intopt
.kind
== ODK_REGINFO
)
2860 + sizeof (Elf_External_Options
)
2861 + (sizeof (Elf32_External_RegInfo
) - 4)),
2864 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
2865 if (bfd_write (buf
, 1, 4, abfd
) != 4)
2872 return _bfd_mips_elf_section_processing (abfd
, hdr
);
2875 /* MIPS ELF uses two common sections. One is the usual one, and the
2876 other is for small objects. All the small objects are kept
2877 together, and then referenced via the gp pointer, which yields
2878 faster assembler code. This is what we use for the small common
2879 section. This approach is copied from ecoff.c. */
2880 static asection mips_elf_scom_section
;
2881 static asymbol mips_elf_scom_symbol
;
2882 static asymbol
*mips_elf_scom_symbol_ptr
;
2884 /* MIPS ELF also uses an acommon section, which represents an
2885 allocated common symbol which may be overridden by a
2886 definition in a shared library. */
2887 static asection mips_elf_acom_section
;
2888 static asymbol mips_elf_acom_symbol
;
2889 static asymbol
*mips_elf_acom_symbol_ptr
;
2891 /* The Irix 5 support uses two virtual sections, which represent
2892 text/data symbols defined in dynamic objects. */
2893 static asection mips_elf_text_section
;
2894 static asection
*mips_elf_text_section_ptr
;
2895 static asymbol mips_elf_text_symbol
;
2896 static asymbol
*mips_elf_text_symbol_ptr
;
2898 static asection mips_elf_data_section
;
2899 static asection
*mips_elf_data_section_ptr
;
2900 static asymbol mips_elf_data_symbol
;
2901 static asymbol
*mips_elf_data_symbol_ptr
;
2903 /* Handle the special MIPS section numbers that a symbol may use.
2904 This is used for both the 32-bit and the 64-bit ABI. */
2907 _bfd_mips_elf_symbol_processing (abfd
, asym
)
2911 elf_symbol_type
*elfsym
;
2913 elfsym
= (elf_symbol_type
*) asym
;
2914 switch (elfsym
->internal_elf_sym
.st_shndx
)
2916 case SHN_MIPS_ACOMMON
:
2917 /* This section is used in a dynamically linked executable file.
2918 It is an allocated common section. The dynamic linker can
2919 either resolve these symbols to something in a shared
2920 library, or it can just leave them here. For our purposes,
2921 we can consider these symbols to be in a new section. */
2922 if (mips_elf_acom_section
.name
== NULL
)
2924 /* Initialize the acommon section. */
2925 mips_elf_acom_section
.name
= ".acommon";
2926 mips_elf_acom_section
.flags
= SEC_ALLOC
;
2927 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
2928 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
2929 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
2930 mips_elf_acom_symbol
.name
= ".acommon";
2931 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
2932 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
2933 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
2935 asym
->section
= &mips_elf_acom_section
;
2939 /* Common symbols less than the GP size are automatically
2940 treated as SHN_MIPS_SCOMMON symbols. */
2941 if (asym
->value
> elf_gp_size (abfd
))
2944 case SHN_MIPS_SCOMMON
:
2945 if (mips_elf_scom_section
.name
== NULL
)
2947 /* Initialize the small common section. */
2948 mips_elf_scom_section
.name
= ".scommon";
2949 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
2950 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
2951 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
2952 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
2953 mips_elf_scom_symbol
.name
= ".scommon";
2954 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2955 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
2956 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
2958 asym
->section
= &mips_elf_scom_section
;
2959 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2962 case SHN_MIPS_SUNDEFINED
:
2963 asym
->section
= bfd_und_section_ptr
;
2966 #if 0 /* for SGI_COMPAT */
2968 asym
->section
= mips_elf_text_section_ptr
;
2972 asym
->section
= mips_elf_data_section_ptr
;
2978 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
2982 mips_elf_additional_program_headers (abfd
)
2990 if (! SGI_COMPAT (abfd
))
2993 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2994 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2996 /* We need a PT_MIPS_REGINFO segment. */
3000 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3001 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3003 /* We need a PT_MIPS_RTPROC segment. */
3010 /* Modify the segment map for an Irix 5 executable. */
3013 mips_elf_modify_segment_map (abfd
)
3017 struct elf_segment_map
*m
, **pm
;
3019 if (! SGI_COMPAT (abfd
))
3022 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
3024 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3025 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3027 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3028 if (m
->p_type
== PT_MIPS_REGINFO
)
3032 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3036 m
->p_type
= PT_MIPS_REGINFO
;
3040 /* We want to put it after the PHDR and INTERP segments. */
3041 pm
= &elf_tdata (abfd
)->segment_map
;
3043 && ((*pm
)->p_type
== PT_PHDR
3044 || (*pm
)->p_type
== PT_INTERP
))
3052 /* If there are .dynamic and .mdebug sections, we make a room for
3053 the RTPROC header. FIXME: Rewrite without section names. */
3054 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
3055 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3056 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3058 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3059 if (m
->p_type
== PT_MIPS_RTPROC
)
3063 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3067 m
->p_type
= PT_MIPS_RTPROC
;
3069 s
= bfd_get_section_by_name (abfd
, ".rtproc");
3074 m
->p_flags_valid
= 1;
3082 /* We want to put it after the DYNAMIC segment. */
3083 pm
= &elf_tdata (abfd
)->segment_map
;
3084 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
3094 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
3095 .dynsym, and .hash sections, and everything in between. */
3096 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
3097 if ((*pm
)->p_type
== PT_DYNAMIC
)
3102 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
3104 static const char *sec_names
[] =
3105 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
3108 struct elf_segment_map
*n
;
3112 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
3114 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
3115 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3121 sz
= s
->_cooked_size
;
3124 if (high
< s
->vma
+ sz
)
3130 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3131 if ((s
->flags
& SEC_LOAD
) != 0
3134 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3138 n
= ((struct elf_segment_map
*)
3139 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
3146 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3148 if ((s
->flags
& SEC_LOAD
) != 0
3151 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3165 /* The structure of the runtime procedure descriptor created by the
3166 loader for use by the static exception system. */
3168 typedef struct runtime_pdr
{
3169 bfd_vma adr
; /* memory address of start of procedure */
3170 long regmask
; /* save register mask */
3171 long regoffset
; /* save register offset */
3172 long fregmask
; /* save floating point register mask */
3173 long fregoffset
; /* save floating point register offset */
3174 long frameoffset
; /* frame size */
3175 short framereg
; /* frame pointer register */
3176 short pcreg
; /* offset or reg of return pc */
3177 long irpss
; /* index into the runtime string table */
3179 struct exception_info
*exception_info
;/* pointer to exception array */
3181 #define cbRPDR sizeof(RPDR)
3182 #define rpdNil ((pRPDR) 0)
3184 /* Swap RPDR (runtime procedure table entry) for output. */
3186 static void ecoff_swap_rpdr_out
3187 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
3190 ecoff_swap_rpdr_out (abfd
, in
, ex
)
3193 struct rpdr_ext
*ex
;
3195 /* ecoff_put_off was defined in ecoffswap.h. */
3196 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
3197 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
3198 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
3199 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
3200 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
3201 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
3203 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
3204 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
3206 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
3208 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
3212 /* Read ECOFF debugging information from a .mdebug section into a
3213 ecoff_debug_info structure. */
3216 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
3219 struct ecoff_debug_info
*debug
;
3222 const struct ecoff_debug_swap
*swap
;
3223 char *ext_hdr
= NULL
;
3225 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3226 memset (debug
, 0, sizeof(*debug
));
3228 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
3229 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
3232 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
3233 swap
->external_hdr_size
)
3237 symhdr
= &debug
->symbolic_header
;
3238 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
3240 /* The symbolic header contains absolute file offsets and sizes to
3242 #define READ(ptr, offset, count, size, type) \
3243 if (symhdr->count == 0) \
3244 debug->ptr = NULL; \
3247 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
3248 if (debug->ptr == NULL) \
3249 goto error_return; \
3250 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3251 || (bfd_read (debug->ptr, size, symhdr->count, \
3252 abfd) != size * symhdr->count)) \
3253 goto error_return; \
3256 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
3257 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
3258 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
3259 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
3260 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
3261 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
3263 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
3264 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
3265 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
3266 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
3267 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
3271 debug
->adjust
= NULL
;
3276 if (ext_hdr
!= NULL
)
3278 if (debug
->line
!= NULL
)
3280 if (debug
->external_dnr
!= NULL
)
3281 free (debug
->external_dnr
);
3282 if (debug
->external_pdr
!= NULL
)
3283 free (debug
->external_pdr
);
3284 if (debug
->external_sym
!= NULL
)
3285 free (debug
->external_sym
);
3286 if (debug
->external_opt
!= NULL
)
3287 free (debug
->external_opt
);
3288 if (debug
->external_aux
!= NULL
)
3289 free (debug
->external_aux
);
3290 if (debug
->ss
!= NULL
)
3292 if (debug
->ssext
!= NULL
)
3293 free (debug
->ssext
);
3294 if (debug
->external_fdr
!= NULL
)
3295 free (debug
->external_fdr
);
3296 if (debug
->external_rfd
!= NULL
)
3297 free (debug
->external_rfd
);
3298 if (debug
->external_ext
!= NULL
)
3299 free (debug
->external_ext
);
3303 /* MIPS ELF local labels start with '$', not 'L'. */
3307 mips_elf_is_local_label_name (abfd
, name
)
3314 /* On Irix 6, the labels go back to starting with '.', so we accept
3315 the generic ELF local label syntax as well. */
3316 return _bfd_elf_is_local_label_name (abfd
, name
);
3319 /* MIPS ELF uses a special find_nearest_line routine in order the
3320 handle the ECOFF debugging information. */
3322 struct mips_elf_find_line
3324 struct ecoff_debug_info d
;
3325 struct ecoff_find_line i
;
3329 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
3330 functionname_ptr
, line_ptr
)
3335 const char **filename_ptr
;
3336 const char **functionname_ptr
;
3337 unsigned int *line_ptr
;
3341 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
3342 filename_ptr
, functionname_ptr
,
3346 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3347 filename_ptr
, functionname_ptr
,
3351 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
3355 struct mips_elf_find_line
*fi
;
3356 const struct ecoff_debug_swap
* const swap
=
3357 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3359 /* If we are called during a link, mips_elf_final_link may have
3360 cleared the SEC_HAS_CONTENTS field. We force it back on here
3361 if appropriate (which it normally will be). */
3362 origflags
= msec
->flags
;
3363 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
3364 msec
->flags
|= SEC_HAS_CONTENTS
;
3366 fi
= elf_tdata (abfd
)->find_line_info
;
3369 bfd_size_type external_fdr_size
;
3372 struct fdr
*fdr_ptr
;
3374 fi
= ((struct mips_elf_find_line
*)
3375 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
3378 msec
->flags
= origflags
;
3382 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
3384 msec
->flags
= origflags
;
3388 /* Swap in the FDR information. */
3389 fi
->d
.fdr
= ((struct fdr
*)
3391 (fi
->d
.symbolic_header
.ifdMax
*
3392 sizeof (struct fdr
))));
3393 if (fi
->d
.fdr
== NULL
)
3395 msec
->flags
= origflags
;
3398 external_fdr_size
= swap
->external_fdr_size
;
3399 fdr_ptr
= fi
->d
.fdr
;
3400 fraw_src
= (char *) fi
->d
.external_fdr
;
3401 fraw_end
= (fraw_src
3402 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
3403 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
3404 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
3406 elf_tdata (abfd
)->find_line_info
= fi
;
3408 /* Note that we don't bother to ever free this information.
3409 find_nearest_line is either called all the time, as in
3410 objdump -l, so the information should be saved, or it is
3411 rarely called, as in ld error messages, so the memory
3412 wasted is unimportant. Still, it would probably be a
3413 good idea for free_cached_info to throw it away. */
3416 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
3417 &fi
->i
, filename_ptr
, functionname_ptr
,
3420 msec
->flags
= origflags
;
3424 msec
->flags
= origflags
;
3427 /* Fall back on the generic ELF find_nearest_line routine. */
3429 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
3430 filename_ptr
, functionname_ptr
,
3434 /* The mips16 compiler uses a couple of special sections to handle
3435 floating point arguments.
3437 Section names that look like .mips16.fn.FNNAME contain stubs that
3438 copy floating point arguments from the fp regs to the gp regs and
3439 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3440 call should be redirected to the stub instead. If no 32 bit
3441 function calls FNNAME, the stub should be discarded. We need to
3442 consider any reference to the function, not just a call, because
3443 if the address of the function is taken we will need the stub,
3444 since the address might be passed to a 32 bit function.
3446 Section names that look like .mips16.call.FNNAME contain stubs
3447 that copy floating point arguments from the gp regs to the fp
3448 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3449 then any 16 bit function that calls FNNAME should be redirected
3450 to the stub instead. If FNNAME is not a 32 bit function, the
3451 stub should be discarded.
3453 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3454 which call FNNAME and then copy the return value from the fp regs
3455 to the gp regs. These stubs store the return value in $18 while
3456 calling FNNAME; any function which might call one of these stubs
3457 must arrange to save $18 around the call. (This case is not
3458 needed for 32 bit functions that call 16 bit functions, because
3459 16 bit functions always return floating point values in both
3462 Note that in all cases FNNAME might be defined statically.
3463 Therefore, FNNAME is not used literally. Instead, the relocation
3464 information will indicate which symbol the section is for.
3466 We record any stubs that we find in the symbol table. */
3468 #define FN_STUB ".mips16.fn."
3469 #define CALL_STUB ".mips16.call."
3470 #define CALL_FP_STUB ".mips16.call.fp."
3472 /* The MIPS ELF linker needs additional information for each symbol in
3473 the global hash table. */
3475 struct mips_elf_link_hash_entry
3477 struct elf_link_hash_entry root
;
3479 /* External symbol information. */
3482 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
3483 unsigned int mips_32_relocs
;
3485 /* The index of the first dynamic relocation (in the .rel.dyn
3486 section) against this symbol. */
3487 unsigned int min_dyn_reloc_index
;
3489 /* If there is a stub that 32 bit functions should use to call this
3490 16 bit function, this points to the section containing the stub. */
3493 /* Whether we need the fn_stub; this is set if this symbol appears
3494 in any relocs other than a 16 bit call. */
3495 boolean need_fn_stub
;
3497 /* If there is a stub that 16 bit functions should use to call this
3498 32 bit function, this points to the section containing the stub. */
3499 asection
*call_stub
;
3501 /* This is like the call_stub field, but it is used if the function
3502 being called returns a floating point value. */
3503 asection
*call_fp_stub
;
3506 /* MIPS ELF linker hash table. */
3508 struct mips_elf_link_hash_table
3510 struct elf_link_hash_table root
;
3512 /* We no longer use this. */
3513 /* String section indices for the dynamic section symbols. */
3514 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
3516 /* The number of .rtproc entries. */
3517 bfd_size_type procedure_count
;
3518 /* The size of the .compact_rel section (if SGI_COMPAT). */
3519 bfd_size_type compact_rel_size
;
3520 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3521 entry is set to the address of __rld_obj_head as in Irix 5. */
3522 boolean use_rld_obj_head
;
3523 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3525 /* This is set if we see any mips16 stub sections. */
3526 boolean mips16_stubs_seen
;
3529 /* Look up an entry in a MIPS ELF linker hash table. */
3531 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3532 ((struct mips_elf_link_hash_entry *) \
3533 elf_link_hash_lookup (&(table)->root, (string), (create), \
3536 /* Traverse a MIPS ELF linker hash table. */
3538 #define mips_elf_link_hash_traverse(table, func, info) \
3539 (elf_link_hash_traverse \
3541 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3544 /* Get the MIPS ELF linker hash table from a link_info structure. */
3546 #define mips_elf_hash_table(p) \
3547 ((struct mips_elf_link_hash_table *) ((p)->hash))
3549 static boolean mips_elf_output_extsym
3550 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3552 /* Create an entry in a MIPS ELF linker hash table. */
3554 static struct bfd_hash_entry
*
3555 mips_elf_link_hash_newfunc (entry
, table
, string
)
3556 struct bfd_hash_entry
*entry
;
3557 struct bfd_hash_table
*table
;
3560 struct mips_elf_link_hash_entry
*ret
=
3561 (struct mips_elf_link_hash_entry
*) entry
;
3563 /* Allocate the structure if it has not already been allocated by a
3565 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3566 ret
= ((struct mips_elf_link_hash_entry
*)
3567 bfd_hash_allocate (table
,
3568 sizeof (struct mips_elf_link_hash_entry
)));
3569 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3570 return (struct bfd_hash_entry
*) ret
;
3572 /* Call the allocation method of the superclass. */
3573 ret
= ((struct mips_elf_link_hash_entry
*)
3574 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3576 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3578 /* Set local fields. */
3579 memset (&ret
->esym
, 0, sizeof (EXTR
));
3580 /* We use -2 as a marker to indicate that the information has
3581 not been set. -1 means there is no associated ifd. */
3583 ret
->mips_32_relocs
= 0;
3584 ret
->min_dyn_reloc_index
= 0;
3585 ret
->fn_stub
= NULL
;
3586 ret
->need_fn_stub
= false;
3587 ret
->call_stub
= NULL
;
3588 ret
->call_fp_stub
= NULL
;
3591 return (struct bfd_hash_entry
*) ret
;
3594 /* Create a MIPS ELF linker hash table. */
3596 static struct bfd_link_hash_table
*
3597 mips_elf_link_hash_table_create (abfd
)
3600 struct mips_elf_link_hash_table
*ret
;
3602 ret
= ((struct mips_elf_link_hash_table
*)
3603 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
3604 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
3607 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3608 mips_elf_link_hash_newfunc
))
3610 bfd_release (abfd
, ret
);
3615 /* We no longer use this. */
3616 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
3617 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
3619 ret
->procedure_count
= 0;
3620 ret
->compact_rel_size
= 0;
3621 ret
->use_rld_obj_head
= false;
3623 ret
->mips16_stubs_seen
= false;
3625 return &ret
->root
.root
;
3628 /* Hook called by the linker routine which adds symbols from an object
3629 file. We must handle the special MIPS section numbers here. */
3633 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3635 struct bfd_link_info
*info
;
3636 const Elf_Internal_Sym
*sym
;
3642 if (SGI_COMPAT (abfd
)
3643 && (abfd
->flags
& DYNAMIC
) != 0
3644 && strcmp (*namep
, "_rld_new_interface") == 0)
3646 /* Skip Irix 5 rld entry name. */
3651 switch (sym
->st_shndx
)
3654 /* Common symbols less than the GP size are automatically
3655 treated as SHN_MIPS_SCOMMON symbols. */
3656 if (sym
->st_size
> elf_gp_size (abfd
))
3659 case SHN_MIPS_SCOMMON
:
3660 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3661 (*secp
)->flags
|= SEC_IS_COMMON
;
3662 *valp
= sym
->st_size
;
3666 /* This section is used in a shared object. */
3667 if (mips_elf_text_section_ptr
== NULL
)
3669 /* Initialize the section. */
3670 mips_elf_text_section
.name
= ".text";
3671 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
3672 mips_elf_text_section
.output_section
= NULL
;
3673 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
3674 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
3675 mips_elf_text_symbol
.name
= ".text";
3676 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
3677 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
3678 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
3679 mips_elf_text_section_ptr
= &mips_elf_text_section
;
3681 /* This code used to do *secp = bfd_und_section_ptr if
3682 info->shared. I don't know why, and that doesn't make sense,
3683 so I took it out. */
3684 *secp
= mips_elf_text_section_ptr
;
3687 case SHN_MIPS_ACOMMON
:
3688 /* Fall through. XXX Can we treat this as allocated data? */
3690 /* This section is used in a shared object. */
3691 if (mips_elf_data_section_ptr
== NULL
)
3693 /* Initialize the section. */
3694 mips_elf_data_section
.name
= ".data";
3695 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
3696 mips_elf_data_section
.output_section
= NULL
;
3697 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
3698 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
3699 mips_elf_data_symbol
.name
= ".data";
3700 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
3701 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
3702 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
3703 mips_elf_data_section_ptr
= &mips_elf_data_section
;
3705 /* This code used to do *secp = bfd_und_section_ptr if
3706 info->shared. I don't know why, and that doesn't make sense,
3707 so I took it out. */
3708 *secp
= mips_elf_data_section_ptr
;
3711 case SHN_MIPS_SUNDEFINED
:
3712 *secp
= bfd_und_section_ptr
;
3716 if (SGI_COMPAT (abfd
)
3718 && info
->hash
->creator
== abfd
->xvec
3719 && strcmp (*namep
, "__rld_obj_head") == 0)
3721 struct elf_link_hash_entry
*h
;
3723 /* Mark __rld_obj_head as dynamic. */
3725 if (! (_bfd_generic_link_add_one_symbol
3726 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3727 (bfd_vma
) *valp
, (const char *) NULL
, false,
3728 get_elf_backend_data (abfd
)->collect
,
3729 (struct bfd_link_hash_entry
**) &h
)))
3731 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
3732 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3733 h
->type
= STT_OBJECT
;
3735 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3738 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3741 /* If this is a mips16 text symbol, add 1 to the value to make it
3742 odd. This will cause something like .word SYM to come up with
3743 the right value when it is loaded into the PC. */
3744 if (sym
->st_other
== STO_MIPS16
)
3750 /* Structure used to pass information to mips_elf_output_extsym. */
3755 struct bfd_link_info
*info
;
3756 struct ecoff_debug_info
*debug
;
3757 const struct ecoff_debug_swap
*swap
;
3761 /* This routine is used to write out ECOFF debugging external symbol
3762 information. It is called via mips_elf_link_hash_traverse. The
3763 ECOFF external symbol information must match the ELF external
3764 symbol information. Unfortunately, at this point we don't know
3765 whether a symbol is required by reloc information, so the two
3766 tables may wind up being different. We must sort out the external
3767 symbol information before we can set the final size of the .mdebug
3768 section, and we must set the size of the .mdebug section before we
3769 can relocate any sections, and we can't know which symbols are
3770 required by relocation until we relocate the sections.
3771 Fortunately, it is relatively unlikely that any symbol will be
3772 stripped but required by a reloc. In particular, it can not happen
3773 when generating a final executable. */
3776 mips_elf_output_extsym (h
, data
)
3777 struct mips_elf_link_hash_entry
*h
;
3780 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
3782 asection
*sec
, *output_section
;
3784 if (h
->root
.indx
== -2)
3786 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3787 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
3788 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3789 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
3791 else if (einfo
->info
->strip
== strip_all
3792 || (einfo
->info
->strip
== strip_some
3793 && bfd_hash_lookup (einfo
->info
->keep_hash
,
3794 h
->root
.root
.root
.string
,
3795 false, false) == NULL
))
3803 if (h
->esym
.ifd
== -2)
3806 h
->esym
.cobol_main
= 0;
3807 h
->esym
.weakext
= 0;
3808 h
->esym
.reserved
= 0;
3809 h
->esym
.ifd
= ifdNil
;
3810 h
->esym
.asym
.value
= 0;
3811 h
->esym
.asym
.st
= stGlobal
;
3813 if (SGI_COMPAT (einfo
->abfd
)
3814 && (h
->root
.root
.type
== bfd_link_hash_undefined
3815 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
3819 /* Use undefined class. Also, set class and type for some
3821 name
= h
->root
.root
.root
.string
;
3822 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
3823 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
3825 h
->esym
.asym
.sc
= scData
;
3826 h
->esym
.asym
.st
= stLabel
;
3827 h
->esym
.asym
.value
= 0;
3829 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
3831 h
->esym
.asym
.sc
= scAbs
;
3832 h
->esym
.asym
.st
= stLabel
;
3833 h
->esym
.asym
.value
=
3834 mips_elf_hash_table (einfo
->info
)->procedure_count
;
3836 else if (strcmp (name
, "_gp_disp") == 0)
3838 h
->esym
.asym
.sc
= scAbs
;
3839 h
->esym
.asym
.st
= stLabel
;
3840 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
3843 h
->esym
.asym
.sc
= scUndefined
;
3845 else if (h
->root
.root
.type
!= bfd_link_hash_defined
3846 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
3847 h
->esym
.asym
.sc
= scAbs
;
3852 sec
= h
->root
.root
.u
.def
.section
;
3853 output_section
= sec
->output_section
;
3855 /* When making a shared library and symbol h is the one from
3856 the another shared library, OUTPUT_SECTION may be null. */
3857 if (output_section
== NULL
)
3858 h
->esym
.asym
.sc
= scUndefined
;
3861 name
= bfd_section_name (output_section
->owner
, output_section
);
3863 if (strcmp (name
, ".text") == 0)
3864 h
->esym
.asym
.sc
= scText
;
3865 else if (strcmp (name
, ".data") == 0)
3866 h
->esym
.asym
.sc
= scData
;
3867 else if (strcmp (name
, ".sdata") == 0)
3868 h
->esym
.asym
.sc
= scSData
;
3869 else if (strcmp (name
, ".rodata") == 0
3870 || strcmp (name
, ".rdata") == 0)
3871 h
->esym
.asym
.sc
= scRData
;
3872 else if (strcmp (name
, ".bss") == 0)
3873 h
->esym
.asym
.sc
= scBss
;
3874 else if (strcmp (name
, ".sbss") == 0)
3875 h
->esym
.asym
.sc
= scSBss
;
3876 else if (strcmp (name
, ".init") == 0)
3877 h
->esym
.asym
.sc
= scInit
;
3878 else if (strcmp (name
, ".fini") == 0)
3879 h
->esym
.asym
.sc
= scFini
;
3881 h
->esym
.asym
.sc
= scAbs
;
3885 h
->esym
.asym
.reserved
= 0;
3886 h
->esym
.asym
.index
= indexNil
;
3889 if (h
->root
.root
.type
== bfd_link_hash_common
)
3890 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
3891 else if (h
->root
.root
.type
== bfd_link_hash_defined
3892 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3894 if (h
->esym
.asym
.sc
== scCommon
)
3895 h
->esym
.asym
.sc
= scBss
;
3896 else if (h
->esym
.asym
.sc
== scSCommon
)
3897 h
->esym
.asym
.sc
= scSBss
;
3899 sec
= h
->root
.root
.u
.def
.section
;
3900 output_section
= sec
->output_section
;
3901 if (output_section
!= NULL
)
3902 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
3903 + sec
->output_offset
3904 + output_section
->vma
);
3906 h
->esym
.asym
.value
= 0;
3908 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3910 /* Set type and value for a symbol with a function stub. */
3911 h
->esym
.asym
.st
= stProc
;
3912 sec
= h
->root
.root
.u
.def
.section
;
3914 h
->esym
.asym
.value
= 0;
3917 output_section
= sec
->output_section
;
3918 if (output_section
!= NULL
)
3919 h
->esym
.asym
.value
= (h
->root
.plt
.offset
3920 + sec
->output_offset
3921 + output_section
->vma
);
3923 h
->esym
.asym
.value
= 0;
3930 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
3931 h
->root
.root
.root
.string
,
3934 einfo
->failed
= true;
3941 /* Create a runtime procedure table from the .mdebug section. */
3944 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
3947 struct bfd_link_info
*info
;
3949 struct ecoff_debug_info
*debug
;
3951 const struct ecoff_debug_swap
*swap
;
3952 HDRR
*hdr
= &debug
->symbolic_header
;
3954 struct rpdr_ext
*erp
;
3956 struct pdr_ext
*epdr
;
3957 struct sym_ext
*esym
;
3960 unsigned long size
, count
;
3961 unsigned long sindex
;
3965 const char *no_name_func
= _("static procedure (no name)");
3973 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3975 sindex
= strlen (no_name_func
) + 1;
3976 count
= hdr
->ipdMax
;
3979 size
= swap
->external_pdr_size
;
3981 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
3985 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
3988 size
= sizeof (RPDR
);
3989 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
3993 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
3997 count
= hdr
->isymMax
;
3998 size
= swap
->external_sym_size
;
3999 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
4003 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
4006 count
= hdr
->issMax
;
4007 ss
= (char *) bfd_malloc (count
);
4010 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
4013 count
= hdr
->ipdMax
;
4014 for (i
= 0; i
< count
; i
++, rp
++)
4016 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
4017 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
4018 rp
->adr
= sym
.value
;
4019 rp
->regmask
= pdr
.regmask
;
4020 rp
->regoffset
= pdr
.regoffset
;
4021 rp
->fregmask
= pdr
.fregmask
;
4022 rp
->fregoffset
= pdr
.fregoffset
;
4023 rp
->frameoffset
= pdr
.frameoffset
;
4024 rp
->framereg
= pdr
.framereg
;
4025 rp
->pcreg
= pdr
.pcreg
;
4027 sv
[i
] = ss
+ sym
.iss
;
4028 sindex
+= strlen (sv
[i
]) + 1;
4032 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
4033 size
= BFD_ALIGN (size
, 16);
4034 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
4037 mips_elf_hash_table (info
)->procedure_count
= 0;
4041 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
4043 erp
= (struct rpdr_ext
*) rtproc
;
4044 memset (erp
, 0, sizeof (struct rpdr_ext
));
4046 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
4047 strcpy (str
, no_name_func
);
4048 str
+= strlen (no_name_func
) + 1;
4049 for (i
= 0; i
< count
; i
++)
4051 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
4052 strcpy (str
, sv
[i
]);
4053 str
+= strlen (sv
[i
]) + 1;
4055 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
4057 /* Set the size and contents of .rtproc section. */
4058 s
->_raw_size
= size
;
4059 s
->contents
= (bfd_byte
*) rtproc
;
4061 /* Skip this section later on (I don't think this currently
4062 matters, but someday it might). */
4063 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
4092 /* A comparison routine used to sort .gptab entries. */
4095 gptab_compare (p1
, p2
)
4099 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
4100 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
4102 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
4105 /* We need to use a special link routine to handle the .reginfo and
4106 the .mdebug sections. We need to merge all instances of these
4107 sections together, not write them all out sequentially. */
4110 mips_elf_final_link (abfd
, info
)
4112 struct bfd_link_info
*info
;
4116 struct bfd_link_order
*p
;
4117 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
4118 asection
*rtproc_sec
;
4119 Elf32_RegInfo reginfo
;
4120 struct ecoff_debug_info debug
;
4121 const struct ecoff_debug_swap
*swap
4122 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4123 HDRR
*symhdr
= &debug
.symbolic_header
;
4124 PTR mdebug_handle
= NULL
;
4126 /* Drop the .options section, since it has special semantics which I
4127 haven't bothered to figure out. */
4128 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
4130 if (strcmp ((*secpp
)->name
, ".options") == 0)
4132 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
4133 if (p
->type
== bfd_indirect_link_order
)
4134 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
4135 (*secpp
)->link_order_head
= NULL
;
4136 *secpp
= (*secpp
)->next
;
4137 --abfd
->section_count
;
4142 /* Get a value for the GP register. */
4143 if (elf_gp (abfd
) == 0)
4145 struct bfd_link_hash_entry
*h
;
4147 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4148 if (h
!= (struct bfd_link_hash_entry
*) NULL
4149 && h
->type
== bfd_link_hash_defined
)
4150 elf_gp (abfd
) = (h
->u
.def
.value
4151 + h
->u
.def
.section
->output_section
->vma
4152 + h
->u
.def
.section
->output_offset
);
4153 else if (info
->relocateable
)
4157 /* Make up a value. */
4159 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4162 && (strcmp (o
->name
, ".sbss") == 0
4163 || strcmp (o
->name
, ".sdata") == 0
4164 || strcmp (o
->name
, ".lit4") == 0
4165 || strcmp (o
->name
, ".lit8") == 0))
4168 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
4172 /* If the relocate_section function needs to do a reloc
4173 involving the GP value, it should make a reloc_dangerous
4174 callback to warn that GP is not defined. */
4178 /* Go through the sections and collect the .reginfo and .mdebug
4182 gptab_data_sec
= NULL
;
4183 gptab_bss_sec
= NULL
;
4184 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4186 if (strcmp (o
->name
, ".reginfo") == 0)
4188 memset (®info
, 0, sizeof reginfo
);
4190 /* We have found the .reginfo section in the output file.
4191 Look through all the link_orders comprising it and merge
4192 the information together. */
4193 for (p
= o
->link_order_head
;
4194 p
!= (struct bfd_link_order
*) NULL
;
4197 asection
*input_section
;
4199 Elf32_External_RegInfo ext
;
4202 if (p
->type
!= bfd_indirect_link_order
)
4204 if (p
->type
== bfd_fill_link_order
)
4209 input_section
= p
->u
.indirect
.section
;
4210 input_bfd
= input_section
->owner
;
4212 /* The linker emulation code has probably clobbered the
4213 size to be zero bytes. */
4214 if (input_section
->_raw_size
== 0)
4215 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4217 if (! bfd_get_section_contents (input_bfd
, input_section
,
4223 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
4225 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
4226 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
4227 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
4228 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
4229 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
4231 /* ri_gp_value is set by the function
4232 mips_elf32_section_processing when the section is
4233 finally written out. */
4235 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4236 elf_link_input_bfd ignores this section. */
4237 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4240 /* Size has been set in mips_elf_always_size_sections */
4241 BFD_ASSERT(o
->_raw_size
== sizeof (Elf32_External_RegInfo
));
4243 /* Skip this section later on (I don't think this currently
4244 matters, but someday it might). */
4245 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4250 if (strcmp (o
->name
, ".mdebug") == 0)
4252 struct extsym_info einfo
;
4254 /* We have found the .mdebug section in the output file.
4255 Look through all the link_orders comprising it and merge
4256 the information together. */
4257 symhdr
->magic
= swap
->sym_magic
;
4258 /* FIXME: What should the version stamp be? */
4260 symhdr
->ilineMax
= 0;
4264 symhdr
->isymMax
= 0;
4265 symhdr
->ioptMax
= 0;
4266 symhdr
->iauxMax
= 0;
4268 symhdr
->issExtMax
= 0;
4271 symhdr
->iextMax
= 0;
4273 /* We accumulate the debugging information itself in the
4274 debug_info structure. */
4276 debug
.external_dnr
= NULL
;
4277 debug
.external_pdr
= NULL
;
4278 debug
.external_sym
= NULL
;
4279 debug
.external_opt
= NULL
;
4280 debug
.external_aux
= NULL
;
4282 debug
.ssext
= debug
.ssext_end
= NULL
;
4283 debug
.external_fdr
= NULL
;
4284 debug
.external_rfd
= NULL
;
4285 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4287 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4288 if (mdebug_handle
== (PTR
) NULL
)
4291 if (SGI_COMPAT (abfd
))
4297 static const char * const name
[] =
4298 { ".text", ".init", ".fini", ".data",
4299 ".rodata", ".sdata", ".sbss", ".bss" };
4300 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
4301 scRData
, scSData
, scSBss
, scBss
};
4304 esym
.cobol_main
= 0;
4308 esym
.asym
.iss
= issNil
;
4309 esym
.asym
.st
= stLocal
;
4310 esym
.asym
.reserved
= 0;
4311 esym
.asym
.index
= indexNil
;
4313 for (i
= 0; i
< 8; i
++)
4315 esym
.asym
.sc
= sc
[i
];
4316 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4319 esym
.asym
.value
= s
->vma
;
4320 last
= s
->vma
+ s
->_raw_size
;
4323 esym
.asym
.value
= last
;
4325 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4331 for (p
= o
->link_order_head
;
4332 p
!= (struct bfd_link_order
*) NULL
;
4335 asection
*input_section
;
4337 const struct ecoff_debug_swap
*input_swap
;
4338 struct ecoff_debug_info input_debug
;
4342 if (p
->type
!= bfd_indirect_link_order
)
4344 if (p
->type
== bfd_fill_link_order
)
4349 input_section
= p
->u
.indirect
.section
;
4350 input_bfd
= input_section
->owner
;
4352 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4353 || (get_elf_backend_data (input_bfd
)
4354 ->elf_backend_ecoff_debug_swap
) == NULL
)
4356 /* I don't know what a non MIPS ELF bfd would be
4357 doing with a .mdebug section, but I don't really
4358 want to deal with it. */
4362 input_swap
= (get_elf_backend_data (input_bfd
)
4363 ->elf_backend_ecoff_debug_swap
);
4365 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
4367 /* The ECOFF linking code expects that we have already
4368 read in the debugging information and set up an
4369 ecoff_debug_info structure, so we do that now. */
4370 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
4374 if (! (bfd_ecoff_debug_accumulate
4375 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
4376 &input_debug
, input_swap
, info
)))
4379 /* Loop through the external symbols. For each one with
4380 interesting information, try to find the symbol in
4381 the linker global hash table and save the information
4382 for the output external symbols. */
4383 eraw_src
= input_debug
.external_ext
;
4384 eraw_end
= (eraw_src
4385 + (input_debug
.symbolic_header
.iextMax
4386 * input_swap
->external_ext_size
));
4388 eraw_src
< eraw_end
;
4389 eraw_src
+= input_swap
->external_ext_size
)
4393 struct mips_elf_link_hash_entry
*h
;
4395 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4396 if (ext
.asym
.sc
== scNil
4397 || ext
.asym
.sc
== scUndefined
4398 || ext
.asym
.sc
== scSUndefined
)
4401 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4402 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
4403 name
, false, false, true);
4404 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4410 < input_debug
.symbolic_header
.ifdMax
);
4411 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4417 /* Free up the information we just read. */
4418 free (input_debug
.line
);
4419 free (input_debug
.external_dnr
);
4420 free (input_debug
.external_pdr
);
4421 free (input_debug
.external_sym
);
4422 free (input_debug
.external_opt
);
4423 free (input_debug
.external_aux
);
4424 free (input_debug
.ss
);
4425 free (input_debug
.ssext
);
4426 free (input_debug
.external_fdr
);
4427 free (input_debug
.external_rfd
);
4428 free (input_debug
.external_ext
);
4430 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4431 elf_link_input_bfd ignores this section. */
4432 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4435 if (SGI_COMPAT (abfd
) && info
->shared
)
4437 /* Create .rtproc section. */
4438 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4439 if (rtproc_sec
== NULL
)
4441 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4442 | SEC_LINKER_CREATED
| SEC_READONLY
);
4444 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4445 if (rtproc_sec
== NULL
4446 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4447 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
4451 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
4452 info
, rtproc_sec
, &debug
))
4456 /* Build the external symbol information. */
4459 einfo
.debug
= &debug
;
4461 einfo
.failed
= false;
4462 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4463 mips_elf_output_extsym
,
4468 /* Set the size of the .mdebug section. */
4469 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4471 /* Skip this section later on (I don't think this currently
4472 matters, but someday it might). */
4473 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4478 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4480 const char *subname
;
4483 Elf32_External_gptab
*ext_tab
;
4486 /* The .gptab.sdata and .gptab.sbss sections hold
4487 information describing how the small data area would
4488 change depending upon the -G switch. These sections
4489 not used in executables files. */
4490 if (! info
->relocateable
)
4494 for (p
= o
->link_order_head
;
4495 p
!= (struct bfd_link_order
*) NULL
;
4498 asection
*input_section
;
4500 if (p
->type
!= bfd_indirect_link_order
)
4502 if (p
->type
== bfd_fill_link_order
)
4507 input_section
= p
->u
.indirect
.section
;
4509 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4510 elf_link_input_bfd ignores this section. */
4511 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4514 /* Skip this section later on (I don't think this
4515 currently matters, but someday it might). */
4516 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4518 /* Really remove the section. */
4519 for (secpp
= &abfd
->sections
;
4521 secpp
= &(*secpp
)->next
)
4523 *secpp
= (*secpp
)->next
;
4524 --abfd
->section_count
;
4529 /* There is one gptab for initialized data, and one for
4530 uninitialized data. */
4531 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4533 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4537 (*_bfd_error_handler
)
4538 (_("%s: illegal section name `%s'"),
4539 bfd_get_filename (abfd
), o
->name
);
4540 bfd_set_error (bfd_error_nonrepresentable_section
);
4544 /* The linker script always combines .gptab.data and
4545 .gptab.sdata into .gptab.sdata, and likewise for
4546 .gptab.bss and .gptab.sbss. It is possible that there is
4547 no .sdata or .sbss section in the output file, in which
4548 case we must change the name of the output section. */
4549 subname
= o
->name
+ sizeof ".gptab" - 1;
4550 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4552 if (o
== gptab_data_sec
)
4553 o
->name
= ".gptab.data";
4555 o
->name
= ".gptab.bss";
4556 subname
= o
->name
+ sizeof ".gptab" - 1;
4557 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4560 /* Set up the first entry. */
4562 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
4565 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4566 tab
[0].gt_header
.gt_unused
= 0;
4568 /* Combine the input sections. */
4569 for (p
= o
->link_order_head
;
4570 p
!= (struct bfd_link_order
*) NULL
;
4573 asection
*input_section
;
4577 bfd_size_type gpentry
;
4579 if (p
->type
!= bfd_indirect_link_order
)
4581 if (p
->type
== bfd_fill_link_order
)
4586 input_section
= p
->u
.indirect
.section
;
4587 input_bfd
= input_section
->owner
;
4589 /* Combine the gptab entries for this input section one
4590 by one. We know that the input gptab entries are
4591 sorted by ascending -G value. */
4592 size
= bfd_section_size (input_bfd
, input_section
);
4594 for (gpentry
= sizeof (Elf32_External_gptab
);
4596 gpentry
+= sizeof (Elf32_External_gptab
))
4598 Elf32_External_gptab ext_gptab
;
4599 Elf32_gptab int_gptab
;
4605 if (! (bfd_get_section_contents
4606 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4607 gpentry
, sizeof (Elf32_External_gptab
))))
4613 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
4615 val
= int_gptab
.gt_entry
.gt_g_value
;
4616 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4619 for (look
= 1; look
< c
; look
++)
4621 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4622 tab
[look
].gt_entry
.gt_bytes
+= add
;
4624 if (tab
[look
].gt_entry
.gt_g_value
== val
)
4630 Elf32_gptab
*new_tab
;
4633 /* We need a new table entry. */
4634 new_tab
= ((Elf32_gptab
*)
4635 bfd_realloc ((PTR
) tab
,
4636 (c
+ 1) * sizeof (Elf32_gptab
)));
4637 if (new_tab
== NULL
)
4643 tab
[c
].gt_entry
.gt_g_value
= val
;
4644 tab
[c
].gt_entry
.gt_bytes
= add
;
4646 /* Merge in the size for the next smallest -G
4647 value, since that will be implied by this new
4650 for (look
= 1; look
< c
; look
++)
4652 if (tab
[look
].gt_entry
.gt_g_value
< val
4654 || (tab
[look
].gt_entry
.gt_g_value
4655 > tab
[max
].gt_entry
.gt_g_value
)))
4659 tab
[c
].gt_entry
.gt_bytes
+=
4660 tab
[max
].gt_entry
.gt_bytes
;
4665 last
= int_gptab
.gt_entry
.gt_bytes
;
4668 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4669 elf_link_input_bfd ignores this section. */
4670 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4673 /* The table must be sorted by -G value. */
4675 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
4677 /* Swap out the table. */
4678 ext_tab
= ((Elf32_External_gptab
*)
4679 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
4680 if (ext_tab
== NULL
)
4686 for (i
= 0; i
< c
; i
++)
4687 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
4690 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
4691 o
->contents
= (bfd_byte
*) ext_tab
;
4693 /* Skip this section later on (I don't think this currently
4694 matters, but someday it might). */
4695 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4699 /* Invoke the regular ELF backend linker to do all the work. */
4700 if (! bfd_elf32_bfd_final_link (abfd
, info
))
4703 /* Now write out the computed sections. */
4705 if (reginfo_sec
!= (asection
*) NULL
)
4707 Elf32_External_RegInfo ext
;
4709 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
4710 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4711 (file_ptr
) 0, sizeof ext
))
4715 if (mdebug_sec
!= (asection
*) NULL
)
4717 BFD_ASSERT (abfd
->output_has_begun
);
4718 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4720 mdebug_sec
->filepos
))
4723 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4726 if (gptab_data_sec
!= (asection
*) NULL
)
4728 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4729 gptab_data_sec
->contents
,
4731 gptab_data_sec
->_raw_size
))
4735 if (gptab_bss_sec
!= (asection
*) NULL
)
4737 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4738 gptab_bss_sec
->contents
,
4740 gptab_bss_sec
->_raw_size
))
4744 if (SGI_COMPAT (abfd
))
4746 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4747 if (rtproc_sec
!= NULL
)
4749 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
4750 rtproc_sec
->contents
,
4752 rtproc_sec
->_raw_size
))
4760 /* Handle a MIPS ELF HI16 reloc. */
4763 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
4765 Elf_Internal_Rela
*relhi
;
4766 Elf_Internal_Rela
*rello
;
4773 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4775 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4778 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4780 if ((addlo
& 0x8000) != 0)
4782 if ((addend
& 0x8000) != 0)
4785 bfd_put_32 (input_bfd
,
4786 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
4787 contents
+ relhi
->r_offset
);
4790 /* Handle a MIPS ELF local GOT16 reloc. */
4793 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
4798 Elf_Internal_Rela
*relhi
;
4799 Elf_Internal_Rela
*rello
;
4803 unsigned int assigned_gotno
;
4809 bfd_byte
*got_contents
;
4810 struct mips_got_info
*g
;
4812 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4814 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4817 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4819 if ((addlo
& 0x8000) != 0)
4821 if ((addend
& 0x8000) != 0)
4824 /* Get a got entry representing requested hipage. */
4825 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4826 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4827 BFD_ASSERT (g
!= NULL
);
4829 assigned_gotno
= g
->assigned_gotno
;
4830 got_contents
= sgot
->contents
;
4831 hipage
= addend
& 0xffff0000;
4833 for (i
= MIPS_RESERVED_GOTNO
; i
< assigned_gotno
; i
++)
4835 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
4836 if (hipage
== (address
& 0xffff0000))
4840 if (i
== assigned_gotno
)
4842 if (assigned_gotno
>= g
->local_gotno
)
4844 (*_bfd_error_handler
)
4845 (_("more got entries are needed for hipage relocations"));
4846 bfd_set_error (bfd_error_bad_value
);
4850 bfd_put_32 (input_bfd
, hipage
, got_contents
+ assigned_gotno
* 4);
4851 ++g
->assigned_gotno
;
4854 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
4855 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
4856 contents
+ relhi
->r_offset
);
4861 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
4864 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
4866 Elf_Internal_Rela
*rel
;
4872 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4873 bfd_put_32 (input_bfd
,
4874 (insn
& 0xffff0000) | (offset
& 0xffff),
4875 contents
+ rel
->r_offset
);
4878 /* Relocate a MIPS ELF section. */
4881 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4882 contents
, relocs
, local_syms
, local_sections
)
4884 struct bfd_link_info
*info
;
4886 asection
*input_section
;
4888 Elf_Internal_Rela
*relocs
;
4889 Elf_Internal_Sym
*local_syms
;
4890 asection
**local_sections
;
4892 Elf_Internal_Shdr
*symtab_hdr
;
4895 asection
*sgot
, *sreloc
, *scpt
;
4898 Elf_Internal_Rela
*rel
;
4899 Elf_Internal_Rela
*relend
;
4900 struct mips_got_info
*g
;
4902 dynobj
= elf_hash_table (info
)->dynobj
;
4903 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4907 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
4910 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
4913 if (elf_bad_symtab (input_bfd
))
4915 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
4920 locsymcount
= symtab_hdr
->sh_info
;
4921 extsymoff
= symtab_hdr
->sh_info
;
4924 gp
= _bfd_get_gp_value (output_bfd
);
4927 relend
= relocs
+ input_section
->reloc_count
;
4928 for (; rel
< relend
; rel
++)
4931 reloc_howto_type
*howto
;
4932 unsigned long r_symndx
;
4934 struct elf_link_hash_entry
*h
;
4936 Elf_Internal_Sym
*sym
;
4937 struct mips_elf_link_hash_entry
*mh
;
4939 bfd_reloc_status_type r
;
4941 r_type
= ELF32_R_TYPE (rel
->r_info
);
4942 if (r_type
== R_MIPS_GNU_VTINHERIT
4943 || r_type
== R_MIPS_GNU_VTENTRY
)
4945 if ((r_type
< 0 || r_type
>= (int) R_MIPS_max
)
4946 && r_type
!= R_MIPS16_26
4947 && r_type
!= R_MIPS16_GPREL
)
4949 bfd_set_error (bfd_error_bad_value
);
4952 if (r_type
== R_MIPS16_26
)
4953 howto
= &elf_mips16_jump_howto
;
4954 else if (r_type
== R_MIPS16_GPREL
)
4955 howto
= &elf_mips16_gprel_howto
;
4957 howto
= elf_mips_howto_table
+ r_type
;
4960 && (r_type
== R_MIPS_CALL16
4961 || r_type
== R_MIPS_GOT16
4962 || r_type
== R_MIPS_CALL_HI16
4963 || r_type
== R_MIPS_CALL_LO16
4964 || r_type
== R_MIPS_GOT_HI16
4965 || r_type
== R_MIPS_GOT_LO16
))
4967 /* We need the .got section. */
4970 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4971 BFD_ASSERT (sgot
!= NULL
);
4972 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4973 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4974 BFD_ASSERT (g
!= NULL
);
4978 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4980 /* Mix in the change in GP address for a GP relative reloc. */
4981 if (r_type
!= R_MIPS_GPREL16
4982 && r_type
!= R_MIPS_LITERAL
4983 && r_type
!= R_MIPS_GPREL32
4984 && r_type
!= R_MIPS16_GPREL
)
4990 if (! ((*info
->callbacks
->reloc_dangerous
)
4992 _("GP relative relocation when GP not defined"),
4993 input_bfd
, input_section
,
4996 /* Only give the error once per link. */
4998 _bfd_set_gp_value (output_bfd
, gp
);
5001 if (r_symndx
< extsymoff
5002 || (elf_bad_symtab (input_bfd
)
5003 && local_sections
[r_symndx
] != NULL
))
5005 /* This is a relocation against a section. The current
5006 addend in the instruction is the difference between
5007 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
5008 must change this to be the difference between the
5009 final definition (which will end up in RELOCATION)
5010 and the GP value of OUTPUT_BFD (which is in GP). */
5011 addend
= elf_gp (input_bfd
) - gp
;
5013 else if (! info
->relocateable
)
5015 /* We are doing a final link. The current addend in the
5016 instruction is simply the desired offset into the
5017 symbol (normally zero). We want the instruction to
5018 hold the difference between the final definition of
5019 the symbol (which will end up in RELOCATION) and the
5020 GP value of OUTPUT_BFD (which is in GP). */
5025 /* We are generating relocateable output, and we aren't
5026 going to define this symbol, so we just leave the
5027 instruction alone. */
5035 if (info
->relocateable
)
5037 /* This is a relocateable link. We don't have to change
5038 anything, unless the reloc is against a section symbol,
5039 in which case we have to adjust according to where the
5040 section symbol winds up in the output section. */
5041 if (r_symndx
>= locsymcount
5042 || (elf_bad_symtab (input_bfd
)
5043 && local_sections
[r_symndx
] == NULL
))
5047 sym
= local_syms
+ r_symndx
;
5048 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5052 sec
= local_sections
[r_symndx
];
5054 /* It would be logical to add sym->st_value here,
5055 but Irix 5 sometimes generates a garbage symbol
5057 addend
+= sec
->output_offset
;
5059 /* If this is HI16 or GOT16 with an associated LO16,
5060 adjust the addend accordingly. Otherwise, just
5062 if (r_type
== R_MIPS_64
&& bfd_big_endian (input_bfd
))
5063 r
= _bfd_relocate_contents (howto
, input_bfd
,
5065 contents
+ rel
->r_offset
+ 4);
5066 else if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
5067 r
= _bfd_relocate_contents (howto
, input_bfd
,
5069 contents
+ rel
->r_offset
);
5072 Elf_Internal_Rela
*lorel
;
5074 /* As a GNU extension, permit an arbitrary
5075 number of R_MIPS_HI16 relocs before the
5076 R_MIPS_LO16 reloc. This permits gcc to emit
5077 the HI and LO relocs itself. */
5078 if (r_type
== R_MIPS_GOT16
)
5082 for (lorel
= rel
+ 1;
5084 && (ELF32_R_TYPE (lorel
->r_info
)
5090 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5092 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5097 r
= _bfd_relocate_contents (howto
, input_bfd
,
5099 contents
+ rel
->r_offset
);
5108 boolean undefined_error
;
5110 /* This is a final link. */
5111 undefined_error
= false;
5113 if (r_symndx
< extsymoff
5114 || (elf_bad_symtab (input_bfd
)
5115 && local_sections
[r_symndx
] != NULL
))
5118 sym
= local_syms
+ r_symndx
;
5119 sec
= local_sections
[r_symndx
];
5120 relocation
= (sec
->output_section
->vma
5121 + sec
->output_offset
);
5123 /* It would be logical to always add sym->st_value here,
5124 but Irix 5 sometimes generates a garbage symbol
5126 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5127 relocation
+= sym
->st_value
;
5129 /* mips16 text labels should be treated as odd. */
5130 if (sym
->st_other
== STO_MIPS16
)
5138 indx
= r_symndx
- extsymoff
;
5139 h
= elf_sym_hashes (input_bfd
)[indx
];
5140 while (h
->root
.type
== bfd_link_hash_indirect
5141 || h
->root
.type
== bfd_link_hash_warning
)
5142 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5143 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
5147 if (! ((*info
->callbacks
->reloc_dangerous
)
5149 _("_gp_disp used when GP not defined"),
5150 input_bfd
, input_section
,
5153 /* Only give the error once per link. */
5155 _bfd_set_gp_value (output_bfd
, gp
);
5160 sec
= input_section
;
5161 if (sec
->output_section
!= NULL
)
5164 + sec
->output_section
->vma
5165 + sec
->output_offset
));
5167 relocation
= gp
- rel
->r_offset
;
5168 if (r_type
== R_MIPS_LO16
)
5172 else if (h
->root
.type
== bfd_link_hash_defined
5173 || h
->root
.type
== bfd_link_hash_defweak
)
5175 sec
= h
->root
.u
.def
.section
;
5176 if (sec
->output_section
== NULL
)
5179 relocation
= (h
->root
.u
.def
.value
5180 + sec
->output_section
->vma
5181 + sec
->output_offset
);
5183 else if (h
->root
.type
== bfd_link_hash_undefweak
)
5185 else if (info
->shared
&& !info
->symbolic
&& !info
->no_undefined
)
5187 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
5189 /* If this is a dynamic link, we should have created
5190 a _DYNAMIC_LINK symbol in
5191 mips_elf_create_dynamic_sections. Otherwise, we
5192 should define the symbol with a value of 0.
5193 FIXME: It should probably get into the symbol
5194 table somehow as well. */
5195 BFD_ASSERT (! info
->shared
);
5196 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
5197 ".dynamic") == NULL
);
5202 if (! ((*info
->callbacks
->undefined_symbol
)
5203 (info
, h
->root
.root
.string
, input_bfd
,
5204 input_section
, rel
->r_offset
)))
5206 undefined_error
= true;
5211 mh
= (struct mips_elf_link_hash_entry
*) h
;
5214 else if (sym
!= NULL
)
5215 other
= sym
->st_other
;
5219 /* If this function has an fn_stub, then it is a mips16
5220 function which needs a stub if it is called by a 32 bit
5221 function. If this reloc is anything other than a 16 bit
5222 call, redirect the reloc to the stub. We don't redirect
5223 relocs from other stub functions. */
5224 if (r_type
!= R_MIPS16_26
5226 && mh
->fn_stub
!= NULL
)
5228 && elf_tdata (input_bfd
)->local_stubs
!= NULL
5229 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
5230 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5231 FN_STUB
, sizeof FN_STUB
- 1) != 0
5232 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5233 CALL_STUB
, sizeof CALL_STUB
- 1) != 0
5234 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5235 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) != 0)
5239 BFD_ASSERT (mh
->need_fn_stub
);
5240 relocation
= (mh
->fn_stub
->output_section
->vma
5241 + mh
->fn_stub
->output_offset
);
5247 fn_stub
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
5248 relocation
= (fn_stub
->output_section
->vma
5249 + fn_stub
->output_offset
);
5252 /* RELOCATION now points to 32 bit code. */
5256 /* If this function has a call_stub, then it is called by a
5257 mips16 function; the call needs to go through a stub if
5258 this function is a 32 bit function. If this reloc is a
5259 16 bit call, and the symbol is not a 16 bit function,
5260 then redirect the reloc to the stub. Note that we don't
5261 need to worry about calling the function through a
5262 function pointer; such calls are handled by routing
5263 through a special mips16 routine. We don't have to check
5264 whether this call is from a stub; it can't be, because a
5265 stub contains 32 bit code, and hence can not have a 16
5267 if (r_type
== R_MIPS16_26
5269 && (mh
->call_stub
!= NULL
|| mh
->call_fp_stub
!= NULL
)
5270 && other
!= STO_MIPS16
)
5274 /* If both call_stub and call_fp_stub are defined, we
5275 can figure out which one to use by seeing which one
5276 appears in the input file. */
5277 if (mh
->call_stub
!= NULL
&& mh
->call_fp_stub
!= NULL
)
5282 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
5284 if (strncmp (bfd_get_section_name (input_bfd
, o
),
5285 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5287 stub
= mh
->call_fp_stub
;
5292 stub
= mh
->call_stub
;
5294 else if (mh
->call_stub
!= NULL
)
5295 stub
= mh
->call_stub
;
5297 stub
= mh
->call_fp_stub
;
5299 BFD_ASSERT (stub
->_raw_size
> 0);
5300 relocation
= stub
->output_section
->vma
+ stub
->output_offset
;
5303 if (r_type
== R_MIPS_HI16
)
5305 Elf_Internal_Rela
*lorel
;
5307 /* As a GNU extension, permit an arbitrary number of
5308 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
5309 This permits gcc to emit the HI and LO relocs itself. */
5310 for (lorel
= rel
+ 1;
5312 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
5316 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5318 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5319 contents
, relocation
+ addend
);
5323 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5324 contents
, rel
->r_offset
,
5325 relocation
, addend
);
5327 else if (r_type
== R_MIPS_GOT16
&& local
)
5329 /* GOT16 must also have an associated LO16 in the local
5330 case. In this case, the addend is extracted and the
5331 section in which the referenced object is determined.
5332 Then the final address of the object is computed and
5333 the GOT entry for the hipage (an aligned 64kb chunk)
5334 is added to .got section if needed. The offset field
5335 of the GOT16-relocated instruction is replaced by the
5336 index of this GOT entry for the hipage. */
5337 if ((rel
+ 1) < relend
5338 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
5340 if (! mips_elf_relocate_got_local (output_bfd
, input_bfd
,
5343 relocation
+ addend
))
5348 r
= bfd_reloc_outofrange
;
5350 else if (r_type
== R_MIPS_CALL16
5351 || r_type
== R_MIPS_GOT16
5352 || r_type
== R_MIPS_CALL_LO16
5353 || r_type
== R_MIPS_GOT_LO16
)
5357 /* This symbol must be registered as a global symbol
5358 having the corresponding got entry. */
5359 BFD_ASSERT (h
->got
.offset
!= (bfd_vma
) -1);
5361 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5362 BFD_ASSERT (g
->local_gotno
<= offset
5363 && offset
< sgot
->_raw_size
);
5364 bfd_put_32 (output_bfd
, relocation
+ addend
,
5365 sgot
->contents
+ offset
);
5366 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5368 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
5372 else if (r_type
== R_MIPS_CALL_HI16
5373 || r_type
== R_MIPS_GOT_HI16
)
5377 /* This must be a global symbol with a got entry. The
5378 next reloc must be the corresponding LO16 reloc. */
5379 BFD_ASSERT (h
!= NULL
&& h
->got
.offset
!= (bfd_vma
) -1);
5380 BFD_ASSERT ((rel
+ 1) < relend
);
5381 BFD_ASSERT ((int) ELF32_R_TYPE ((rel
+ 1)->r_info
)
5382 == (r_type
== R_MIPS_CALL_HI16
5383 ? (int) R_MIPS_CALL_LO16
5384 : (int) R_MIPS_GOT_LO16
));
5386 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5387 BFD_ASSERT (g
->local_gotno
<= offset
5388 && offset
< sgot
->_raw_size
);
5389 bfd_put_32 (output_bfd
, relocation
+ addend
,
5390 sgot
->contents
+ offset
);
5391 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5393 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
5397 else if (r_type
== R_MIPS_REL32
5398 || r_type
== R_MIPS_32
)
5400 Elf_Internal_Rel outrel
;
5401 Elf32_crinfo cptrel
;
5405 || (elf_hash_table (info
)->dynamic_sections_created
5407 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
5409 && (input_section
->flags
& SEC_ALLOC
) != 0)
5413 /* When generating a shared object, these
5414 relocations are copied into the output file to be
5415 resolved at run time. */
5418 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5419 BFD_ASSERT (sreloc
!= NULL
);
5424 if (elf_section_data (input_section
)->stab_info
== NULL
)
5425 outrel
.r_offset
= rel
->r_offset
;
5430 off
= (_bfd_stab_section_offset
5431 (output_bfd
, &elf_hash_table (info
)->stab_info
,
5433 &elf_section_data (input_section
)->stab_info
,
5435 if (off
== (bfd_vma
) -1)
5437 outrel
.r_offset
= off
;
5440 outrel
.r_offset
+= (input_section
->output_section
->vma
5441 + input_section
->output_offset
);
5443 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5446 memset (&outrel
, 0, sizeof outrel
);
5448 && (! info
->symbolic
5449 || (h
->elf_link_hash_flags
5450 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5452 BFD_ASSERT (h
->dynindx
!= -1);
5453 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
5454 sec
= input_section
;
5461 sec
= local_sections
[r_symndx
];
5464 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
5466 == bfd_link_hash_defweak
));
5467 sec
= h
->root
.u
.def
.section
;
5469 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5471 else if (sec
== NULL
|| sec
->owner
== NULL
)
5473 bfd_set_error (bfd_error_bad_value
);
5480 osec
= sec
->output_section
;
5481 indx
= elf_section_data (osec
)->dynindx
;
5486 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
5487 addend
+= relocation
;
5491 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
5493 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
5494 (((Elf32_External_Rel
*)
5496 + sreloc
->reloc_count
));
5497 ++sreloc
->reloc_count
;
5499 if (! skip
&& SGI_COMPAT (output_bfd
))
5504 /* Make an entry of compact relocation info. */
5505 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5506 cptrel
.vaddr
= (rel
->r_offset
5507 + input_section
->output_section
->vma
5508 + input_section
->output_offset
);
5509 if (r_type
== R_MIPS_REL32
)
5510 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5512 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5513 mips_elf_set_cr_dist2to (cptrel
, 0);
5514 cptrel
.konst
= addend
;
5516 cr
= (scpt
->contents
5517 + sizeof (Elf32_External_compact_rel
));
5518 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5519 ((Elf32_External_crinfo
*) cr
5520 + scpt
->reloc_count
));
5521 ++scpt
->reloc_count
;
5524 /* This reloc will be computed at runtime, so
5525 there's no need to do anything now. */
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_MIPS_64
)
5538 /* Do a 32 bit relocation, and sign extend to 64 bits. */
5539 addr
= rel
->r_offset
;
5540 if (bfd_big_endian (input_bfd
))
5542 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5543 contents
, addr
, relocation
,
5545 val
= bfd_get_32 (input_bfd
, contents
+ addr
);
5546 if ((val
& 0x80000000) != 0)
5550 addr
= rel
->r_offset
;
5551 if (bfd_little_endian (input_bfd
))
5553 bfd_put_32 (input_bfd
, val
, contents
+ addr
);
5555 else if (r_type
== R_MIPS_26
&& other
== STO_MIPS16
)
5559 /* This is a jump to a mips16 routine from a mips32
5560 routine. We need to change jal into jalx. */
5561 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5562 if (((insn
>> 26) & 0x3f) != 0x3
5563 && ((insn
>> 26) & 0x3f) != 0x1d)
5565 (*_bfd_error_handler
)
5566 (_("%s: %s+0x%lx: jump to mips16 routine which is not jal"),
5567 bfd_get_filename (input_bfd
),
5568 input_section
->name
,
5569 (unsigned long) rel
->r_offset
);
5570 bfd_set_error (bfd_error_bad_value
);
5573 insn
= (insn
& 0x3ffffff) | (0x1d << 26);
5574 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5575 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5576 contents
, rel
->r_offset
,
5577 relocation
, addend
);
5579 else if (r_type
== R_MIPS16_26
)
5581 /* It's easiest to do the normal relocation, and then
5582 dig out the instruction and swap the first word the
5583 way the mips16 expects it. If this is little endian,
5584 though, we need to swap the two words first, and then
5585 swap them back again later, so that the address looks
5588 if (bfd_little_endian (input_bfd
))
5592 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5593 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5594 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5597 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5598 contents
, rel
->r_offset
,
5599 relocation
, addend
);
5600 if (r
== bfd_reloc_ok
)
5604 if (bfd_little_endian (input_bfd
))
5606 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5607 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5608 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5611 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5612 insn
= ((insn
& 0xfc00)
5613 | ((insn
& 0x1f) << 5)
5614 | ((insn
& 0x3e0) >> 5));
5615 /* If this is a jump to a 32 bit routine, then make
5617 if (other
!= STO_MIPS16
)
5619 bfd_put_16 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5622 else if (r_type
== R_MIPS16_GPREL
)
5624 unsigned short extend
, insn
;
5626 unsigned long final
;
5628 /* Extract the addend into buf, run the regular reloc,
5629 and stuff the resulting value back into the
5631 if (rel
->r_offset
> input_section
->_raw_size
)
5632 r
= bfd_reloc_outofrange
;
5635 extend
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5636 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 2);
5637 bfd_put_32 (input_bfd
,
5638 (((extend
& 0x1f) << 11)
5642 r
= _bfd_final_link_relocate (howto
, input_bfd
,
5644 (bfd_vma
) 0, relocation
,
5646 final
= bfd_get_32 (input_bfd
, buf
);
5647 bfd_put_16 (input_bfd
,
5649 | ((final
>> 11) & 0x1f)
5651 contents
+ rel
->r_offset
);
5652 bfd_put_16 (input_bfd
,
5655 contents
+ rel
->r_offset
+ 2);
5659 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5660 contents
, rel
->r_offset
,
5661 relocation
, addend
);
5663 /* The jal instruction can only jump to an address which is
5664 divisible by 4, and it can only jump to an address with
5665 the same upper 4 bits as the PC. */
5666 if (r
== bfd_reloc_ok
5667 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
))
5673 pc
= ((input_section
->output_section
->vma
5674 + input_section
->output_offset
5677 target
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
)
5678 & (howto
->dst_mask
);
5679 addr
= (target
<< 2) + pc
;
5680 if (other
== STO_MIPS16
)
5681 addr
&= ~ (bfd_vma
) 1;
5683 || ((addr
& 0xf0000000)
5685 r
= bfd_reloc_overflow
;
5688 /* Don't bother to report a relocation overflow for a call
5689 to a weak undefined symbol with a value of zero. This
5692 even if we aren't in range to call address zero. */
5693 if (r
== bfd_reloc_overflow
5694 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
)
5695 && relocation
+ addend
== 0
5697 && h
->root
.type
== bfd_link_hash_undefweak
)
5700 /* If we've already issued an error for an undefined symbol,
5701 don't issue another useless error. */
5703 && (r
== bfd_reloc_undefined
|| r
== bfd_reloc_overflow
))
5706 if (SGI_COMPAT (output_bfd
)
5708 && (input_section
->flags
& SEC_ALLOC
) != 0)
5710 Elf32_crinfo cptrel
;
5713 /* Make an entry of compact relocation info. */
5714 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5715 cptrel
.vaddr
= (rel
->r_offset
5716 + input_section
->output_section
->vma
5717 + input_section
->output_offset
);
5722 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
5723 /* XXX How should we set dist2to in this case. */
5724 mips_elf_set_cr_dist2to (cptrel
, 8);
5725 cptrel
.konst
= addend
+ relocation
;
5726 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5727 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5728 ((Elf32_External_crinfo
*) cr
5729 + scpt
->reloc_count
));
5730 ++scpt
->reloc_count
;
5733 case R_MIPS_GPREL16
:
5734 case R_MIPS_LITERAL
:
5735 case R_MIPS_GPREL32
:
5736 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
5737 cptrel
.konst
= gp
- cptrel
.vaddr
;
5738 mips_elf_set_cr_dist2to (cptrel
, 4);
5739 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5740 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5741 ((Elf32_External_crinfo
*) cr
5742 + scpt
->reloc_count
));
5743 ++scpt
->reloc_count
;
5752 if (r
!= bfd_reloc_ok
)
5757 case bfd_reloc_outofrange
:
5759 case bfd_reloc_overflow
:
5764 name
= h
->root
.root
.string
;
5767 name
= bfd_elf_string_from_elf_section (input_bfd
,
5768 symtab_hdr
->sh_link
,
5773 name
= bfd_section_name (input_bfd
, sec
);
5775 if (! ((*info
->callbacks
->reloc_overflow
)
5776 (info
, name
, howto
->name
, (bfd_vma
) 0,
5777 input_bfd
, input_section
, rel
->r_offset
)))
5788 /* This hook function is called before the linker writes out a global
5789 symbol. We mark symbols as small common if appropriate. This is
5790 also where we undo the increment of the value for a mips16 symbol. */
5794 mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
5796 struct bfd_link_info
*info
;
5798 Elf_Internal_Sym
*sym
;
5799 asection
*input_sec
;
5801 /* If we see a common symbol, which implies a relocatable link, then
5802 if a symbol was small common in an input file, mark it as small
5803 common in the output file. */
5804 if (sym
->st_shndx
== SHN_COMMON
5805 && strcmp (input_sec
->name
, ".scommon") == 0)
5806 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
5808 if (sym
->st_other
== STO_MIPS16
5809 && (sym
->st_value
& 1) != 0)
5815 /* Functions for the dynamic linker. */
5817 /* The name of the dynamic interpreter. This is put in the .interp
5820 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
5822 /* Create dynamic sections when linking against a dynamic object. */
5825 mips_elf_create_dynamic_sections (abfd
, info
)
5827 struct bfd_link_info
*info
;
5829 struct elf_link_hash_entry
*h
;
5831 register asection
*s
;
5832 const char * const *namep
;
5834 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5835 | SEC_LINKER_CREATED
| SEC_READONLY
);
5837 /* Mips ABI requests the .dynamic section to be read only. */
5838 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5841 if (! bfd_set_section_flags (abfd
, s
, flags
))
5845 /* We need to create .got section. */
5846 if (! mips_elf_create_got_section (abfd
, info
))
5849 /* Create the .msym section on IRIX6. It is used by the dynamic
5850 linker to speed up dynamic relocations, and to avoid computing
5851 the ELF hash for symbols. */
5852 if (IRIX_COMPAT (abfd
) == ict_irix6
5853 && !mips_elf_create_msym_section (abfd
))
5856 /* Create .stub section. */
5857 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
5859 s
= bfd_make_section (abfd
, ".stub");
5861 || ! bfd_set_section_flags (abfd
, s
, flags
)
5862 || ! bfd_set_section_alignment (abfd
, s
, 2))
5866 if (SGI_COMPAT (abfd
)
5868 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
5870 s
= bfd_make_section (abfd
, ".rld_map");
5872 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
5873 || ! bfd_set_section_alignment (abfd
, s
, 2))
5877 if (SGI_COMPAT (abfd
))
5879 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
5882 if (! (_bfd_generic_link_add_one_symbol
5883 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
5884 (bfd_vma
) 0, (const char *) NULL
, false,
5885 get_elf_backend_data (abfd
)->collect
,
5886 (struct bfd_link_hash_entry
**) &h
)))
5888 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5889 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5890 h
->type
= STT_SECTION
;
5892 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5896 /* We need to create a .compact_rel section. */
5897 if (! mips_elf_create_compact_rel_section (abfd
, info
))
5900 /* Change aligments of some sections. */
5901 s
= bfd_get_section_by_name (abfd
, ".hash");
5903 bfd_set_section_alignment (abfd
, s
, 4);
5904 s
= bfd_get_section_by_name (abfd
, ".dynsym");
5906 bfd_set_section_alignment (abfd
, s
, 4);
5907 s
= bfd_get_section_by_name (abfd
, ".dynstr");
5909 bfd_set_section_alignment (abfd
, s
, 4);
5910 s
= bfd_get_section_by_name (abfd
, ".reginfo");
5912 bfd_set_section_alignment (abfd
, s
, 4);
5913 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5915 bfd_set_section_alignment (abfd
, s
, 4);
5921 if (! (_bfd_generic_link_add_one_symbol
5922 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
5923 (bfd_vma
) 0, (const char *) NULL
, false,
5924 get_elf_backend_data (abfd
)->collect
,
5925 (struct bfd_link_hash_entry
**) &h
)))
5927 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5928 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5929 h
->type
= STT_SECTION
;
5931 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5934 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
5936 /* __rld_map is a four byte word located in the .data section
5937 and is filled in by the rtld to contain a pointer to
5938 the _r_debug structure. Its symbol value will be set in
5939 mips_elf_finish_dynamic_symbol. */
5940 s
= bfd_get_section_by_name (abfd
, ".rld_map");
5941 BFD_ASSERT (s
!= NULL
);
5944 if (! (_bfd_generic_link_add_one_symbol
5945 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
5946 (bfd_vma
) 0, (const char *) NULL
, false,
5947 get_elf_backend_data (abfd
)->collect
,
5948 (struct bfd_link_hash_entry
**) &h
)))
5950 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5951 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5952 h
->type
= STT_OBJECT
;
5954 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5962 /* Create the .compact_rel section. */
5965 mips_elf_create_compact_rel_section (abfd
, info
)
5967 struct bfd_link_info
*info
;
5970 register asection
*s
;
5972 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
5974 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
5977 s
= bfd_make_section (abfd
, ".compact_rel");
5979 || ! bfd_set_section_flags (abfd
, s
, flags
)
5980 || ! bfd_set_section_alignment (abfd
, s
, 2))
5983 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
5989 /* Create the .got section to hold the global offset table. */
5992 mips_elf_create_got_section (abfd
, info
)
5994 struct bfd_link_info
*info
;
5997 register asection
*s
;
5998 struct elf_link_hash_entry
*h
;
5999 struct mips_got_info
*g
;
6001 /* This function may be called more than once. */
6002 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
6005 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6006 | SEC_LINKER_CREATED
);
6008 s
= bfd_make_section (abfd
, ".got");
6010 || ! bfd_set_section_flags (abfd
, s
, flags
)
6011 || ! bfd_set_section_alignment (abfd
, s
, 4))
6014 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
6015 linker script because we don't want to define the symbol if we
6016 are not creating a global offset table. */
6018 if (! (_bfd_generic_link_add_one_symbol
6019 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
6020 (bfd_vma
) 0, (const char *) NULL
, false,
6021 get_elf_backend_data (abfd
)->collect
,
6022 (struct bfd_link_hash_entry
**) &h
)))
6024 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6025 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6026 h
->type
= STT_OBJECT
;
6029 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6032 /* The first several global offset table entries are reserved. */
6033 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
6035 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
6036 sizeof (struct mips_got_info
));
6039 g
->global_gotsym
= 0;
6040 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
6041 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
6042 if (elf_section_data (s
) == NULL
)
6045 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
6046 if (elf_section_data (s
) == NULL
)
6049 elf_section_data (s
)->tdata
= (PTR
) g
;
6054 /* Returns the .msym section for ABFD, creating it if it does not
6055 already exist. Returns NULL to indicate error. */
6058 mips_elf_create_msym_section (abfd
)
6063 s
= bfd_get_section_by_name (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
6066 s
= bfd_make_section (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
6068 || !bfd_set_section_flags (abfd
, s
,
6072 | SEC_LINKER_CREATED
6074 || !bfd_set_section_alignment (abfd
, s
, 2))
6081 /* Look through the relocs for a section during the first phase, and
6082 allocate space in the global offset table. */
6085 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
6087 struct bfd_link_info
*info
;
6089 const Elf_Internal_Rela
*relocs
;
6093 Elf_Internal_Shdr
*symtab_hdr
;
6094 struct elf_link_hash_entry
**sym_hashes
;
6095 struct mips_got_info
*g
;
6097 const Elf_Internal_Rela
*rel
;
6098 const Elf_Internal_Rela
*rel_end
;
6102 if (info
->relocateable
)
6105 dynobj
= elf_hash_table (info
)->dynobj
;
6106 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6107 sym_hashes
= elf_sym_hashes (abfd
);
6108 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
6110 /* Check for the mips16 stub sections. */
6112 name
= bfd_get_section_name (abfd
, sec
);
6113 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
6115 unsigned long r_symndx
;
6117 /* Look at the relocation information to figure out which symbol
6120 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6122 if (r_symndx
< extsymoff
6123 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6127 /* This stub is for a local symbol. This stub will only be
6128 needed if there is some relocation in this BFD, other
6129 than a 16 bit function call, which refers to this symbol. */
6130 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6132 Elf_Internal_Rela
*sec_relocs
;
6133 const Elf_Internal_Rela
*r
, *rend
;
6135 /* We can ignore stub sections when looking for relocs. */
6136 if ((o
->flags
& SEC_RELOC
) == 0
6137 || o
->reloc_count
== 0
6138 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
6139 sizeof FN_STUB
- 1) == 0
6140 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
6141 sizeof CALL_STUB
- 1) == 0
6142 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
6143 sizeof CALL_FP_STUB
- 1) == 0)
6146 sec_relocs
= (_bfd_elf32_link_read_relocs
6147 (abfd
, o
, (PTR
) NULL
,
6148 (Elf_Internal_Rela
*) NULL
,
6149 info
->keep_memory
));
6150 if (sec_relocs
== NULL
)
6153 rend
= sec_relocs
+ o
->reloc_count
;
6154 for (r
= sec_relocs
; r
< rend
; r
++)
6155 if (ELF32_R_SYM (r
->r_info
) == r_symndx
6156 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
6159 if (! info
->keep_memory
)
6168 /* There is no non-call reloc for this stub, so we do
6169 not need it. Since this function is called before
6170 the linker maps input sections to output sections, we
6171 can easily discard it by setting the SEC_EXCLUDE
6173 sec
->flags
|= SEC_EXCLUDE
;
6177 /* Record this stub in an array of local symbol stubs for
6179 if (elf_tdata (abfd
)->local_stubs
== NULL
)
6181 unsigned long symcount
;
6184 if (elf_bad_symtab (abfd
))
6185 symcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
6187 symcount
= symtab_hdr
->sh_info
;
6188 n
= (asection
**) bfd_zalloc (abfd
,
6189 symcount
* sizeof (asection
*));
6192 elf_tdata (abfd
)->local_stubs
= n
;
6195 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
6197 /* We don't need to set mips16_stubs_seen in this case.
6198 That flag is used to see whether we need to look through
6199 the global symbol table for stubs. We don't need to set
6200 it here, because we just have a local stub. */
6204 struct mips_elf_link_hash_entry
*h
;
6206 h
= ((struct mips_elf_link_hash_entry
*)
6207 sym_hashes
[r_symndx
- extsymoff
]);
6209 /* H is the symbol this stub is for. */
6212 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6215 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
6216 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6218 unsigned long r_symndx
;
6219 struct mips_elf_link_hash_entry
*h
;
6222 /* Look at the relocation information to figure out which symbol
6225 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6227 if (r_symndx
< extsymoff
6228 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6230 /* This stub was actually built for a static symbol defined
6231 in the same file. We assume that all static symbols in
6232 mips16 code are themselves mips16, so we can simply
6233 discard this stub. Since this function is called before
6234 the linker maps input sections to output sections, we can
6235 easily discard it by setting the SEC_EXCLUDE flag. */
6236 sec
->flags
|= SEC_EXCLUDE
;
6240 h
= ((struct mips_elf_link_hash_entry
*)
6241 sym_hashes
[r_symndx
- extsymoff
]);
6243 /* H is the symbol this stub is for. */
6245 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6246 loc
= &h
->call_fp_stub
;
6248 loc
= &h
->call_stub
;
6250 /* If we already have an appropriate stub for this function, we
6251 don't need another one, so we can discard this one. Since
6252 this function is called before the linker maps input sections
6253 to output sections, we can easily discard it by setting the
6254 SEC_EXCLUDE flag. We can also discard this section if we
6255 happen to already know that this is a mips16 function; it is
6256 not necessary to check this here, as it is checked later, but
6257 it is slightly faster to check now. */
6258 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
6260 sec
->flags
|= SEC_EXCLUDE
;
6265 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6275 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6280 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6281 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6282 BFD_ASSERT (g
!= NULL
);
6288 rel_end
= relocs
+ sec
->reloc_count
;
6289 for (rel
= relocs
; rel
< rel_end
; rel
++)
6291 unsigned long r_symndx
;
6292 struct elf_link_hash_entry
*h
;
6294 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6296 if (r_symndx
< extsymoff
)
6300 h
= sym_hashes
[r_symndx
- extsymoff
];
6302 /* This may be an indirect symbol created because of a version. */
6305 while (h
->root
.type
== bfd_link_hash_indirect
)
6306 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6310 /* Some relocs require a global offset table. */
6311 if (dynobj
== NULL
|| sgot
== NULL
)
6313 switch (ELF32_R_TYPE (rel
->r_info
))
6317 case R_MIPS_CALL_HI16
:
6318 case R_MIPS_CALL_LO16
:
6319 case R_MIPS_GOT_HI16
:
6320 case R_MIPS_GOT_LO16
:
6322 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6323 if (! mips_elf_create_got_section (dynobj
, info
))
6325 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6326 BFD_ASSERT (sgot
!= NULL
);
6327 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6328 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6329 BFD_ASSERT (g
!= NULL
);
6335 && (info
->shared
|| h
!= NULL
)
6336 && (sec
->flags
& SEC_ALLOC
) != 0)
6337 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6345 switch (ELF32_R_TYPE (rel
->r_info
))
6348 case R_MIPS_CALL_HI16
:
6349 case R_MIPS_CALL_LO16
:
6350 /* This symbol requires a global offset table entry. */
6354 (*_bfd_error_handler
)
6355 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
6356 bfd_get_filename (abfd
), (unsigned long) rel
->r_offset
);
6357 bfd_set_error (bfd_error_bad_value
);
6361 /* Make sure this symbol is output as a dynamic symbol. */
6362 if (h
->dynindx
== -1)
6364 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6368 if (h
->got
.offset
!= (bfd_vma
) -1)
6370 /* We have already allocated space in the .got. */
6374 /* Note the index of the first global got symbol in .dynsym. */
6375 if (g
->global_gotsym
== 0
6376 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6377 g
->global_gotsym
= h
->dynindx
;
6379 /* Make this symbol to have the corresponding got entry. */
6382 /* We need a stub, not a plt entry for the undefined
6383 function. But we record it as if it needs plt. See
6384 elf_adjust_dynamic_symbol in elflink.h. */
6385 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6391 case R_MIPS_GOT_HI16
:
6392 case R_MIPS_GOT_LO16
:
6393 /* This symbol requires a global offset table entry. */
6397 /* Make sure this symbol is output as a dynamic symbol. */
6398 if (h
->dynindx
== -1)
6400 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6404 if (h
->got
.offset
!= (bfd_vma
) -1)
6406 /* We have already allocated space in the .got. */
6409 /* Note the index of the first global got symbol in
6411 if (g
->global_gotsym
== 0
6412 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6413 g
->global_gotsym
= h
->dynindx
;
6415 /* Make this symbol to be the global got symbol. */
6423 if ((info
->shared
|| h
!= NULL
)
6424 && (sec
->flags
& SEC_ALLOC
) != 0)
6428 const char *name
= ".rel.dyn";
6430 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6433 sreloc
= bfd_make_section (dynobj
, name
);
6435 || ! bfd_set_section_flags (dynobj
, sreloc
,
6440 | SEC_LINKER_CREATED
6442 || ! bfd_set_section_alignment (dynobj
, sreloc
,
6449 /* When creating a shared object, we must copy these
6450 reloc types into the output file as R_MIPS_REL32
6451 relocs. We make room for this reloc in the
6452 .rel.dyn reloc section */
6453 if (sreloc
->_raw_size
== 0)
6455 /* Add a null element. */
6456 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6457 ++sreloc
->reloc_count
;
6459 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6463 struct mips_elf_link_hash_entry
*hmips
;
6465 /* We only need to copy this reloc if the symbol is
6466 defined in a dynamic object. */
6467 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6468 ++hmips
->mips_32_relocs
;
6472 if (SGI_COMPAT (abfd
))
6473 mips_elf_hash_table (info
)->compact_rel_size
+=
6474 sizeof (Elf32_External_crinfo
);
6479 case R_MIPS_GPREL16
:
6480 case R_MIPS_LITERAL
:
6481 case R_MIPS_GPREL32
:
6482 if (SGI_COMPAT (abfd
))
6483 mips_elf_hash_table (info
)->compact_rel_size
+=
6484 sizeof (Elf32_External_crinfo
);
6487 /* This relocation describes the C++ object vtable hierarchy.
6488 Reconstruct it for later use during GC. */
6489 case R_MIPS_GNU_VTINHERIT
:
6490 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6494 /* This relocation describes which C++ vtable entries are actually
6495 used. Record for later use during GC. */
6496 case R_MIPS_GNU_VTENTRY
:
6497 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
6505 /* If this reloc is not a 16 bit call, and it has a global
6506 symbol, then we will need the fn_stub if there is one.
6507 References from a stub section do not count. */
6509 && ELF32_R_TYPE (rel
->r_info
) != R_MIPS16_26
6510 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
6511 sizeof FN_STUB
- 1) != 0
6512 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
6513 sizeof CALL_STUB
- 1) != 0
6514 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
6515 sizeof CALL_FP_STUB
- 1) != 0)
6517 struct mips_elf_link_hash_entry
*mh
;
6519 mh
= (struct mips_elf_link_hash_entry
*) h
;
6520 mh
->need_fn_stub
= true;
6527 /* Return the section that should be marked against GC for a given
6531 mips_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
6533 struct bfd_link_info
*info
;
6534 Elf_Internal_Rela
*rel
;
6535 struct elf_link_hash_entry
*h
;
6536 Elf_Internal_Sym
*sym
;
6538 /* ??? Do mips16 stub sections need to be handled special? */
6542 switch (ELF32_R_TYPE (rel
->r_info
))
6544 case R_MIPS_GNU_VTINHERIT
:
6545 case R_MIPS_GNU_VTENTRY
:
6549 switch (h
->root
.type
)
6551 case bfd_link_hash_defined
:
6552 case bfd_link_hash_defweak
:
6553 return h
->root
.u
.def
.section
;
6555 case bfd_link_hash_common
:
6556 return h
->root
.u
.c
.p
->section
;
6565 if (!(elf_bad_symtab (abfd
)
6566 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
6567 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
6568 && sym
->st_shndx
!= SHN_COMMON
))
6570 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
6577 /* Update the got entry reference counts for the section being removed. */
6580 mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
6582 struct bfd_link_info
*info
;
6584 const Elf_Internal_Rela
*relocs
;
6587 Elf_Internal_Shdr
*symtab_hdr
;
6588 struct elf_link_hash_entry
**sym_hashes
;
6589 bfd_signed_vma
*local_got_refcounts
;
6590 const Elf_Internal_Rela
*rel
, *relend
;
6591 unsigned long r_symndx
;
6592 struct elf_link_hash_entry
*h
;
6594 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6595 sym_hashes
= elf_sym_hashes (abfd
);
6596 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6598 relend
= relocs
+ sec
->reloc_count
;
6599 for (rel
= relocs
; rel
< relend
; rel
++)
6600 switch (ELF32_R_TYPE (rel
->r_info
))
6604 case R_MIPS_CALL_HI16
:
6605 case R_MIPS_CALL_LO16
:
6606 case R_MIPS_GOT_HI16
:
6607 case R_MIPS_GOT_LO16
:
6608 /* ??? It would seem that the existing MIPS code does no sort
6609 of reference counting or whatnot on its GOT and PLT entries,
6610 so it is not possible to garbage collect them at this time. */
6622 /* Adjust a symbol defined by a dynamic object and referenced by a
6623 regular object. The current definition is in some section of the
6624 dynamic object, but we're not including those sections. We have to
6625 change the definition to something the rest of the link can
6629 mips_elf_adjust_dynamic_symbol (info
, h
)
6630 struct bfd_link_info
*info
;
6631 struct elf_link_hash_entry
*h
;
6634 struct mips_elf_link_hash_entry
*hmips
;
6637 dynobj
= elf_hash_table (info
)->dynobj
;
6639 /* Make sure we know what is going on here. */
6640 BFD_ASSERT (dynobj
!= NULL
6641 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
6642 || h
->weakdef
!= NULL
6643 || ((h
->elf_link_hash_flags
6644 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
6645 && (h
->elf_link_hash_flags
6646 & ELF_LINK_HASH_REF_REGULAR
) != 0
6647 && (h
->elf_link_hash_flags
6648 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
6650 /* If this symbol is defined in a dynamic object, we need to copy
6651 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
6653 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6654 if (! info
->relocateable
6655 && hmips
->mips_32_relocs
!= 0
6656 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6658 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6659 BFD_ASSERT (s
!= NULL
);
6661 if (s
->_raw_size
== 0)
6663 /* Make room for a null element. */
6664 s
->_raw_size
+= sizeof (Elf32_External_Rel
);
6667 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
6670 /* For a function, create a stub, if needed. */
6671 if (h
->type
== STT_FUNC
6672 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
6674 if (! elf_hash_table (info
)->dynamic_sections_created
)
6677 /* If this symbol is not defined in a regular file, then set
6678 the symbol to the stub location. This is required to make
6679 function pointers compare as equal between the normal
6680 executable and the shared library. */
6681 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6683 /* We need .stub section. */
6684 s
= bfd_get_section_by_name (dynobj
, ".stub");
6685 BFD_ASSERT (s
!= NULL
);
6687 h
->root
.u
.def
.section
= s
;
6688 h
->root
.u
.def
.value
= s
->_raw_size
;
6690 /* XXX Write this stub address somewhere. */
6691 h
->plt
.offset
= s
->_raw_size
;
6693 /* Make room for this stub code. */
6694 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6696 /* The last half word of the stub will be filled with the index
6697 of this symbol in .dynsym section. */
6702 /* If this is a weak symbol, and there is a real definition, the
6703 processor independent code will have arranged for us to see the
6704 real definition first, and we can just use the same value. */
6705 if (h
->weakdef
!= NULL
)
6707 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
6708 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
6709 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
6710 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
6714 /* This is a reference to a symbol defined by a dynamic object which
6715 is not a function. */
6720 /* This function is called after all the input files have been read,
6721 and the input sections have been assigned to output sections. We
6722 check for any mips16 stub sections that we can discard. */
6724 static boolean mips_elf_check_mips16_stubs
6725 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
6728 mips_elf_always_size_sections (output_bfd
, info
)
6730 struct bfd_link_info
*info
;
6734 /* The .reginfo section has a fixed size. */
6735 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
6737 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
6739 if (info
->relocateable
6740 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
6743 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
6744 mips_elf_check_mips16_stubs
,
6750 /* Check the mips16 stubs for a particular symbol, and see if we can
6755 mips_elf_check_mips16_stubs (h
, data
)
6756 struct mips_elf_link_hash_entry
*h
;
6759 if (h
->fn_stub
!= NULL
6760 && ! h
->need_fn_stub
)
6762 /* We don't need the fn_stub; the only references to this symbol
6763 are 16 bit calls. Clobber the size to 0 to prevent it from
6764 being included in the link. */
6765 h
->fn_stub
->_raw_size
= 0;
6766 h
->fn_stub
->_cooked_size
= 0;
6767 h
->fn_stub
->flags
&= ~ SEC_RELOC
;
6768 h
->fn_stub
->reloc_count
= 0;
6769 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
6772 if (h
->call_stub
!= NULL
6773 && h
->root
.other
== STO_MIPS16
)
6775 /* We don't need the call_stub; this is a 16 bit function, so
6776 calls from other 16 bit functions are OK. Clobber the size
6777 to 0 to prevent it from being included in the link. */
6778 h
->call_stub
->_raw_size
= 0;
6779 h
->call_stub
->_cooked_size
= 0;
6780 h
->call_stub
->flags
&= ~ SEC_RELOC
;
6781 h
->call_stub
->reloc_count
= 0;
6782 h
->call_stub
->flags
|= SEC_EXCLUDE
;
6785 if (h
->call_fp_stub
!= NULL
6786 && h
->root
.other
== STO_MIPS16
)
6788 /* We don't need the call_stub; this is a 16 bit function, so
6789 calls from other 16 bit functions are OK. Clobber the size
6790 to 0 to prevent it from being included in the link. */
6791 h
->call_fp_stub
->_raw_size
= 0;
6792 h
->call_fp_stub
->_cooked_size
= 0;
6793 h
->call_fp_stub
->flags
&= ~ SEC_RELOC
;
6794 h
->call_fp_stub
->reloc_count
= 0;
6795 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
6801 /* Set the sizes of the dynamic sections. */
6804 mips_elf_size_dynamic_sections (output_bfd
, info
)
6806 struct bfd_link_info
*info
;
6812 struct mips_got_info
*g
;
6814 dynobj
= elf_hash_table (info
)->dynobj
;
6815 BFD_ASSERT (dynobj
!= NULL
);
6817 if (elf_hash_table (info
)->dynamic_sections_created
)
6819 /* Set the contents of the .interp section to the interpreter. */
6822 s
= bfd_get_section_by_name (dynobj
, ".interp");
6823 BFD_ASSERT (s
!= NULL
);
6824 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
6825 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
6829 /* Recompute the size of .got for local entires (reserved and
6830 hipages) if needed. To estimate it, get the upper bound of total
6831 size of loadable sections. */
6832 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6836 bfd_size_type loadable_size
= 0;
6837 bfd_size_type local_gotno
;
6840 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6841 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6842 BFD_ASSERT (g
!= NULL
);
6844 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
6845 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
6847 if ((s
->flags
& SEC_ALLOC
) == 0)
6849 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
6852 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
6854 /* Assume there are two loadable segments consisting of
6855 contiguous sections. Is 5 enough? */
6856 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
6857 g
->local_gotno
= local_gotno
;
6858 sgot
->_raw_size
+= local_gotno
* 4;
6861 /* The check_relocs and adjust_dynamic_symbol entry points have
6862 determined the sizes of the various dynamic sections. Allocate
6865 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
6870 /* It's OK to base decisions on the section name, because none
6871 of the dynobj section names depend upon the input files. */
6872 name
= bfd_get_section_name (dynobj
, s
);
6874 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
6879 if (strncmp (name
, ".rel", 4) == 0)
6881 if (s
->_raw_size
== 0)
6883 /* We only strip the section if the output section name
6884 has the same name. Otherwise, there might be several
6885 input sections for this output section. FIXME: This
6886 code is probably not needed these days anyhow, since
6887 the linker now does not create empty output sections. */
6888 if (s
->output_section
!= NULL
6890 bfd_get_section_name (s
->output_section
->owner
,
6891 s
->output_section
)) == 0)
6896 const char *outname
;
6899 /* If this relocation section applies to a read only
6900 section, then we probably need a DT_TEXTREL entry.
6901 If the relocation section is .rel.dyn, we always
6902 assert a DT_TEXTREL entry rather than testing whether
6903 there exists a relocation to a read only section or
6905 outname
= bfd_get_section_name (output_bfd
,
6907 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
6909 && (target
->flags
& SEC_READONLY
) != 0
6910 && (target
->flags
& SEC_ALLOC
) != 0)
6911 || strcmp (outname
, ".rel.dyn") == 0)
6914 /* We use the reloc_count field as a counter if we need
6915 to copy relocs into the output file. */
6916 if (strcmp (name
, ".rel.dyn") != 0)
6920 else if (strncmp (name
, ".got", 4) == 0)
6924 BFD_ASSERT (elf_section_data (s
) != NULL
);
6925 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
6926 BFD_ASSERT (g
!= NULL
);
6928 /* Fix the size of .got section for the correspondence of
6929 global symbols and got entries. This adds some useless
6930 got entries. Is this required by ABI really? */
6931 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
6932 s
->_raw_size
+= i
* 4;
6934 else if (strncmp (name
, ".stub", 5) == 0)
6936 /* Irix rld assumes that the function stub isn't at the end
6937 of .text section. So put a dummy. XXX */
6938 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6940 else if (! info
->shared
6941 && ! mips_elf_hash_table (info
)->use_rld_obj_head
6942 && strncmp (name
, ".rld_map", 8) == 0)
6944 /* We add a room for __rld_map. It will be filled in by the
6945 rtld to contain a pointer to the _r_debug structure. */
6948 else if (SGI_COMPAT (output_bfd
)
6949 && strncmp (name
, ".compact_rel", 12) == 0)
6950 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
6951 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
))
6953 s
->_raw_size
= (sizeof (Elf32_External_Msym
)
6954 * (elf_hash_table (info
)->dynsymcount
6955 + bfd_count_sections (output_bfd
)));
6956 else if (strncmp (name
, ".init", 5) != 0)
6958 /* It's not one of our sections, so don't allocate space. */
6964 _bfd_strip_section_from_output (s
);
6968 /* Allocate memory for the section contents. */
6969 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
6970 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
6972 bfd_set_error (bfd_error_no_memory
);
6975 memset (s
->contents
, 0, s
->_raw_size
);
6978 if (elf_hash_table (info
)->dynamic_sections_created
)
6980 /* Add some entries to the .dynamic section. We fill in the
6981 values later, in elf_mips_finish_dynamic_sections, but we
6982 must add the entries now so that we get the correct size for
6983 the .dynamic section. The DT_DEBUG entry is filled in by the
6984 dynamic linker and used by the debugger. */
6987 if (SGI_COMPAT (output_bfd
))
6989 /* SGI object has the equivalence of DT_DEBUG in the
6990 DT_MIPS_RLD_MAP entry. */
6991 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
6995 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
7001 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
7005 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
7008 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
7010 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
7013 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
7016 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
7020 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
7023 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
7026 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
7028 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
7031 s
= bfd_get_section_by_name (dynobj
, ".liblist");
7032 BFD_ASSERT (s
!= NULL
);
7034 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
7038 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
7041 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
7045 /* Time stamps in executable files are a bad idea. */
7046 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
7051 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
7056 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
7060 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
7063 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
7066 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
7069 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
7072 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
7075 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
7078 #if 0 /* (SGI_COMPAT) */
7079 if (! bfd_get_section_by_name (dynobj
, ".init"))
7080 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
7083 if (! bfd_get_section_by_name (dynobj
, ".fini"))
7084 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
7088 if (bfd_get_section_by_name (dynobj
,
7089 MIPS_ELF_MSYM_SECTION_NAME (dynobj
))
7090 && !bfd_elf32_add_dynamic_entry (info
, DT_MIPS_MSYM
, 0))
7094 /* If we use dynamic linking, we generate a section symbol for each
7095 output section. These are local symbols, which means that they
7096 must come first in the dynamic symbol table.
7097 That means we must increment the dynamic symbol index of every
7098 other dynamic symbol. */
7101 struct mips_got_info
*g
;
7104 if (elf_hash_table (info
)->dynamic_sections_created
)
7107 /* We no longer try to restrict the set of sections which get
7108 dynamic symbol table entries, since it fails if we have
7109 other random sections which need dynamic relocations. */
7110 const char * const *namep
;
7111 bfd_size_type strindex
;
7112 struct bfd_strtab_hash
*dynstr
;
7114 if (SGI_COMPAT (output_bfd
))
7116 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
7117 elf_link_hash_traverse (elf_hash_table (info
),
7118 mips_elf_adjust_dynindx
,
7120 elf_hash_table (info
)->dynsymcount
+= c
;
7122 dynstr
= elf_hash_table (info
)->dynstr
;
7123 BFD_ASSERT (dynstr
!= NULL
);
7125 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
7129 s
= bfd_get_section_by_name (output_bfd
, *namep
);
7131 elf_section_data (s
)->dynindx
= i
;
7133 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
7134 if (strindex
== (bfd_size_type
) -1)
7137 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
7143 c
= bfd_count_sections (output_bfd
);
7144 elf_link_hash_traverse (elf_hash_table (info
),
7145 mips_elf_adjust_dynindx
,
7147 elf_hash_table (info
)->dynsymcount
+= c
;
7149 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
7151 elf_section_data (s
)->dynindx
= i
;
7152 /* These symbols will have no names, so we don't need to
7153 fiddle with dynstr_index. */
7160 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7161 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7162 BFD_ASSERT (g
!= NULL
);
7164 /* If there are no global got symbols, fake the last symbol so
7166 if (g
->global_gotsym
)
7167 g
->global_gotsym
+= c
;
7169 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
7176 /* Increment the index of a dynamic symbol by a given amount. Called
7177 via elf_link_hash_traverse. */
7180 mips_elf_adjust_dynindx (h
, cparg
)
7181 struct elf_link_hash_entry
*h
;
7184 unsigned int *cp
= (unsigned int *) cparg
;
7186 if (h
->dynindx
!= -1)
7191 /* Finish up dynamic symbol handling. We set the contents of various
7192 dynamic sections here. */
7195 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
7197 struct bfd_link_info
*info
;
7198 struct elf_link_hash_entry
*h
;
7199 Elf_Internal_Sym
*sym
;
7205 struct mips_got_info
*g
;
7207 struct mips_elf_link_hash_entry
*mh
;
7209 dynobj
= elf_hash_table (info
)->dynobj
;
7210 gval
= sym
->st_value
;
7211 mh
= (struct mips_elf_link_hash_entry
*) h
;
7213 if (h
->plt
.offset
!= (bfd_vma
) -1)
7217 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
7219 /* This symbol has a stub. Set it up. */
7221 BFD_ASSERT (h
->dynindx
!= -1);
7223 s
= bfd_get_section_by_name (dynobj
, ".stub");
7224 BFD_ASSERT (s
!= NULL
);
7226 /* Fill the stub. */
7228 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
7230 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
7233 /* FIXME: Can h->dynindex be more than 64K? */
7234 if (h
->dynindx
& 0xffff0000)
7237 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
7239 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
7241 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
7242 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
7244 /* Mark the symbol as undefined. plt.offset != -1 occurs
7245 only for the referenced symbol. */
7246 sym
->st_shndx
= SHN_UNDEF
;
7248 /* The run-time linker uses the st_value field of the symbol
7249 to reset the global offset table entry for this external
7250 to its stub address when unlinking a shared object. */
7251 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
7252 sym
->st_value
= gval
;
7255 BFD_ASSERT (h
->dynindx
!= -1);
7257 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7258 BFD_ASSERT (sgot
!= NULL
);
7259 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7260 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7261 BFD_ASSERT (g
!= NULL
);
7263 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
7265 bfd_size_type offset
;
7267 /* This symbol has an entry in the global offset table. Set its
7268 value to the corresponding got entry, if needed. */
7269 if (h
->got
.offset
== (bfd_vma
) -1)
7271 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
7272 BFD_ASSERT (g
->local_gotno
* 4 <= offset
7273 && offset
< sgot
->_raw_size
);
7274 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
7278 /* Create a .msym entry, if appropriate. */
7279 smsym
= bfd_get_section_by_name (dynobj
,
7280 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
7283 Elf32_Internal_Msym msym
;
7285 msym
.ms_hash_value
= bfd_elf_hash (h
->root
.root
.string
);
7286 /* It is undocumented what the `1' indicates, but IRIX6 uses
7288 msym
.ms_info
= ELF32_MS_INFO (mh
->min_dyn_reloc_index
, 1);
7289 bfd_mips_elf_swap_msym_out
7291 ((Elf32_External_Msym
*) smsym
->contents
) + h
->dynindx
);
7294 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7295 name
= h
->root
.root
.string
;
7296 if (strcmp (name
, "_DYNAMIC") == 0
7297 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
7298 sym
->st_shndx
= SHN_ABS
;
7299 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
7301 sym
->st_shndx
= SHN_ABS
;
7302 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7305 else if (SGI_COMPAT (output_bfd
))
7307 if (strcmp (name
, "_gp_disp") == 0)
7309 sym
->st_shndx
= SHN_ABS
;
7310 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7311 sym
->st_value
= elf_gp (output_bfd
);
7313 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
7314 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
7316 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7317 sym
->st_other
= STO_PROTECTED
;
7319 sym
->st_shndx
= SHN_MIPS_DATA
;
7321 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
7323 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7324 sym
->st_other
= STO_PROTECTED
;
7325 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
7326 sym
->st_shndx
= SHN_ABS
;
7328 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
7330 if (h
->type
== STT_FUNC
)
7331 sym
->st_shndx
= SHN_MIPS_TEXT
;
7332 else if (h
->type
== STT_OBJECT
)
7333 sym
->st_shndx
= SHN_MIPS_DATA
;
7337 if (SGI_COMPAT (output_bfd
)
7340 if (! mips_elf_hash_table (info
)->use_rld_obj_head
7341 && strcmp (name
, "__rld_map") == 0)
7343 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7344 BFD_ASSERT (s
!= NULL
);
7345 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
7346 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
7347 if (mips_elf_hash_table (info
)->rld_value
== 0)
7348 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7350 else if (mips_elf_hash_table (info
)->use_rld_obj_head
7351 && strcmp (name
, "__rld_obj_head") == 0)
7353 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7354 BFD_ASSERT (s
!= NULL
);
7355 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7359 /* If this is a mips16 symbol, force the value to be even. */
7360 if (sym
->st_other
== STO_MIPS16
7361 && (sym
->st_value
& 1) != 0)
7367 /* Finish up the dynamic sections. */
7370 mips_elf_finish_dynamic_sections (output_bfd
, info
)
7372 struct bfd_link_info
*info
;
7377 struct mips_got_info
*g
;
7379 dynobj
= elf_hash_table (info
)->dynobj
;
7381 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
7383 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7388 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7389 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7390 BFD_ASSERT (g
!= NULL
);
7393 if (elf_hash_table (info
)->dynamic_sections_created
)
7395 Elf32_External_Dyn
*dyncon
, *dynconend
;
7397 BFD_ASSERT (sdyn
!= NULL
);
7398 BFD_ASSERT (g
!= NULL
);
7400 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7401 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
7402 for (; dyncon
< dynconend
; dyncon
++)
7404 Elf_Internal_Dyn dyn
;
7409 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
7417 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7418 BFD_ASSERT (s
!= NULL
);
7419 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
7420 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7424 /* Rewrite DT_STRSZ. */
7426 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
7427 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7433 case DT_MIPS_CONFLICT
:
7436 case DT_MIPS_LIBLIST
:
7439 s
= bfd_get_section_by_name (output_bfd
, name
);
7440 BFD_ASSERT (s
!= NULL
);
7441 dyn
.d_un
.d_ptr
= s
->vma
;
7442 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7445 case DT_MIPS_RLD_VERSION
:
7446 dyn
.d_un
.d_val
= 1; /* XXX */
7447 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7451 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
7452 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7455 case DT_MIPS_CONFLICTNO
:
7457 elemsize
= sizeof (Elf32_Conflict
);
7460 case DT_MIPS_LIBLISTNO
:
7462 elemsize
= sizeof (Elf32_Lib
);
7464 s
= bfd_get_section_by_name (output_bfd
, name
);
7467 if (s
->_cooked_size
!= 0)
7468 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7470 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7475 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7478 case DT_MIPS_TIME_STAMP
:
7479 time ((time_t *) &dyn
.d_un
.d_val
);
7480 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7483 case DT_MIPS_ICHECKSUM
:
7487 case DT_MIPS_IVERSION
:
7491 case DT_MIPS_BASE_ADDRESS
:
7492 s
= output_bfd
->sections
;
7493 BFD_ASSERT (s
!= NULL
);
7494 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
7495 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7498 case DT_MIPS_LOCAL_GOTNO
:
7499 dyn
.d_un
.d_val
= g
->local_gotno
;
7500 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7503 case DT_MIPS_SYMTABNO
:
7505 elemsize
= sizeof (Elf32_External_Sym
);
7506 s
= bfd_get_section_by_name (output_bfd
, name
);
7507 BFD_ASSERT (s
!= NULL
);
7509 if (s
->_cooked_size
!= 0)
7510 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7512 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7513 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7516 case DT_MIPS_UNREFEXTNO
:
7518 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
7520 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
);
7522 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7525 case DT_MIPS_GOTSYM
:
7526 dyn
.d_un
.d_val
= g
->global_gotsym
;
7527 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7530 case DT_MIPS_HIPAGENO
:
7531 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
7532 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7535 case DT_MIPS_RLD_MAP
:
7536 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
7537 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7541 s
= (bfd_get_section_by_name
7542 (output_bfd
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
)));
7543 dyn
.d_un
.d_ptr
= s
->vma
;
7544 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7550 /* The first entry of the global offset table will be filled at
7551 runtime. The second entry will be used by some runtime loaders.
7552 This isn't the case of Irix rld. */
7553 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
7555 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
7556 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
7560 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
7566 Elf_Internal_Sym sym
;
7567 Elf32_compact_rel cpt
;
7569 /* Set up the section symbols for the output sections. SGI sets
7570 the STT_NOTYPE attribute for these symbols. Should we do so? */
7572 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
7573 smsym
= bfd_get_section_by_name (dynobj
,
7574 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
7575 if (sdynsym
!= NULL
)
7579 const char * const * namep
= mips_elf_dynsym_sec_names
;
7584 /* We no longer try to restrict the set of sections which get
7585 dynamic symbol table entries, since it fails if we have
7586 other random sections which need dynamic relocations. */
7587 if (SGI_COMPAT (output_bfd
))
7591 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7597 while ((name
= *namep
++) != NULL
)
7599 s
= bfd_get_section_by_name (output_bfd
, name
);
7602 sym
.st_value
= s
->vma
;
7603 dindx
= elf_section_data (s
)->dynindx
;
7604 last
= s
->vma
+ s
->_raw_size
;
7608 sym
.st_value
= last
;
7612 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
7617 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
7619 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7620 (((Elf32_External_Sym
*)
7625 /* Set the sh_info field of the output .dynsym section to
7626 the index of the first global symbol. */
7627 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7628 SIZEOF_MIPS_DYNSYM_SECNAMES
;
7633 Elf32_Internal_Msym msym
;
7637 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
7640 msym
.ms_hash_value
= 0;
7641 msym
.ms_info
= ELF32_MS_INFO (0, 1);
7643 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
7648 sym
.st_value
= s
->vma
;
7650 indx
= elf_section_data (s
)->this_idx
;
7651 BFD_ASSERT (indx
> 0);
7652 sym
.st_shndx
= indx
;
7654 dynindx
= elf_section_data (s
)->dynindx
;
7656 bfd_elf32_swap_symbol_out
7658 (((Elf32_External_Sym
*) sdynsym
->contents
)
7662 bfd_mips_elf_swap_msym_out
7664 (((Elf32_External_Msym
*) smsym
->contents
)
7668 /* Set the sh_info field of the output .dynsym section to
7669 the index of the first global symbol. */
7670 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7671 bfd_count_sections (output_bfd
) + 1;
7675 if (SGI_COMPAT (output_bfd
))
7677 /* Write .compact_rel section out. */
7678 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
7682 cpt
.num
= s
->reloc_count
;
7684 cpt
.offset
= (s
->output_section
->filepos
7685 + sizeof (Elf32_External_compact_rel
));
7688 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
7689 ((Elf32_External_compact_rel
*)
7692 /* Clean up a dummy stub function entry in .text. */
7693 s
= bfd_get_section_by_name (dynobj
, ".stub");
7696 file_ptr dummy_offset
;
7698 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
7699 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
7700 memset (s
->contents
+ dummy_offset
, 0,
7701 MIPS_FUNCTION_STUB_SIZE
);
7706 /* Clean up a first relocation in .rel.dyn. */
7707 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7708 if (s
!= NULL
&& s
->_raw_size
> 0)
7709 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
7715 /* This is almost identical to bfd_generic_get_... except that some
7716 MIPS relocations need to be handled specially. Sigh. */
7719 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
7720 relocateable
, symbols
)
7722 struct bfd_link_info
*link_info
;
7723 struct bfd_link_order
*link_order
;
7725 boolean relocateable
;
7728 /* Get enough memory to hold the stuff */
7729 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
7730 asection
*input_section
= link_order
->u
.indirect
.section
;
7732 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
7733 arelent
**reloc_vector
= NULL
;
7739 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
7740 if (reloc_vector
== NULL
&& reloc_size
!= 0)
7743 /* read in the section */
7744 if (!bfd_get_section_contents (input_bfd
,
7748 input_section
->_raw_size
))
7751 /* We're not relaxing the section, so just copy the size info */
7752 input_section
->_cooked_size
= input_section
->_raw_size
;
7753 input_section
->reloc_done
= true;
7755 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
7759 if (reloc_count
< 0)
7762 if (reloc_count
> 0)
7767 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
7770 struct bfd_hash_entry
*h
;
7771 struct bfd_link_hash_entry
*lh
;
7772 /* Skip all this stuff if we aren't mixing formats. */
7773 if (abfd
&& input_bfd
7774 && abfd
->xvec
== input_bfd
->xvec
)
7778 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
7779 lh
= (struct bfd_link_hash_entry
*) h
;
7786 case bfd_link_hash_undefined
:
7787 case bfd_link_hash_undefweak
:
7788 case bfd_link_hash_common
:
7791 case bfd_link_hash_defined
:
7792 case bfd_link_hash_defweak
:
7794 gp
= lh
->u
.def
.value
;
7796 case bfd_link_hash_indirect
:
7797 case bfd_link_hash_warning
:
7799 /* @@FIXME ignoring warning for now */
7801 case bfd_link_hash_new
:
7810 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
7813 char *error_message
= (char *) NULL
;
7814 bfd_reloc_status_type r
;
7816 /* Specific to MIPS: Deal with relocation types that require
7817 knowing the gp of the output bfd. */
7818 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
7819 if (bfd_is_abs_section (sym
->section
) && abfd
)
7821 /* The special_function wouldn't get called anyways. */
7825 /* The gp isn't there; let the special function code
7826 fall over on its own. */
7828 else if ((*parent
)->howto
->special_function
7829 == _bfd_mips_elf_gprel16_reloc
)
7831 /* bypass special_function call */
7832 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
7833 relocateable
, (PTR
) data
, gp
);
7834 goto skip_bfd_perform_relocation
;
7836 /* end mips specific stuff */
7838 r
= bfd_perform_relocation (input_bfd
,
7842 relocateable
? abfd
: (bfd
*) NULL
,
7844 skip_bfd_perform_relocation
:
7848 asection
*os
= input_section
->output_section
;
7850 /* A partial link, so keep the relocs */
7851 os
->orelocation
[os
->reloc_count
] = *parent
;
7855 if (r
!= bfd_reloc_ok
)
7859 case bfd_reloc_undefined
:
7860 if (!((*link_info
->callbacks
->undefined_symbol
)
7861 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7862 input_bfd
, input_section
, (*parent
)->address
)))
7865 case bfd_reloc_dangerous
:
7866 BFD_ASSERT (error_message
!= (char *) NULL
);
7867 if (!((*link_info
->callbacks
->reloc_dangerous
)
7868 (link_info
, error_message
, input_bfd
, input_section
,
7869 (*parent
)->address
)))
7872 case bfd_reloc_overflow
:
7873 if (!((*link_info
->callbacks
->reloc_overflow
)
7874 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7875 (*parent
)->howto
->name
, (*parent
)->addend
,
7876 input_bfd
, input_section
, (*parent
)->address
)))
7879 case bfd_reloc_outofrange
:
7888 if (reloc_vector
!= NULL
)
7889 free (reloc_vector
);
7893 if (reloc_vector
!= NULL
)
7894 free (reloc_vector
);
7897 #define bfd_elf32_bfd_get_relocated_section_contents \
7898 elf32_mips_get_relocated_section_contents
7900 /* ECOFF swapping routines. These are used when dealing with the
7901 .mdebug section, which is in the ECOFF debugging format. */
7902 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
7904 /* Symbol table magic number. */
7906 /* Alignment of debugging information. E.g., 4. */
7908 /* Sizes of external symbolic information. */
7909 sizeof (struct hdr_ext
),
7910 sizeof (struct dnr_ext
),
7911 sizeof (struct pdr_ext
),
7912 sizeof (struct sym_ext
),
7913 sizeof (struct opt_ext
),
7914 sizeof (struct fdr_ext
),
7915 sizeof (struct rfd_ext
),
7916 sizeof (struct ext_ext
),
7917 /* Functions to swap in external symbolic data. */
7926 _bfd_ecoff_swap_tir_in
,
7927 _bfd_ecoff_swap_rndx_in
,
7928 /* Functions to swap out external symbolic data. */
7937 _bfd_ecoff_swap_tir_out
,
7938 _bfd_ecoff_swap_rndx_out
,
7939 /* Function to read in symbolic data. */
7940 _bfd_mips_elf_read_ecoff_info
7943 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
7944 #define TARGET_LITTLE_NAME "elf32-littlemips"
7945 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
7946 #define TARGET_BIG_NAME "elf32-bigmips"
7947 #define ELF_ARCH bfd_arch_mips
7948 #define ELF_MACHINE_CODE EM_MIPS
7950 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
7951 a value of 0x1000, and we are compatible. */
7952 #define ELF_MAXPAGESIZE 0x1000
7954 #define elf_backend_collect true
7955 #define elf_backend_type_change_ok true
7956 #define elf_backend_can_gc_sections true
7957 #define elf_info_to_howto mips_info_to_howto_rela
7958 #define elf_info_to_howto_rel mips_info_to_howto_rel
7959 #define elf_backend_sym_is_global mips_elf_sym_is_global
7960 #define elf_backend_object_p mips_elf32_object_p
7961 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
7962 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
7963 #define elf_backend_section_from_bfd_section \
7964 _bfd_mips_elf_section_from_bfd_section
7965 #define elf_backend_section_processing mips_elf32_section_processing
7966 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
7967 #define elf_backend_additional_program_headers \
7968 mips_elf_additional_program_headers
7969 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
7970 #define elf_backend_final_write_processing \
7971 _bfd_mips_elf_final_write_processing
7972 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
7974 #define bfd_elf32_bfd_is_local_label_name \
7975 mips_elf_is_local_label_name
7976 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
7977 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
7978 #define bfd_elf32_bfd_link_hash_table_create \
7979 mips_elf_link_hash_table_create
7980 #define bfd_elf32_bfd_final_link mips_elf_final_link
7981 #define bfd_elf32_bfd_copy_private_bfd_data \
7982 _bfd_mips_elf_copy_private_bfd_data
7983 #define bfd_elf32_bfd_merge_private_bfd_data \
7984 _bfd_mips_elf_merge_private_bfd_data
7985 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
7986 #define bfd_elf32_bfd_print_private_bfd_data \
7987 _bfd_mips_elf_print_private_bfd_data
7988 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
7989 #define elf_backend_create_dynamic_sections \
7990 mips_elf_create_dynamic_sections
7991 #define elf_backend_check_relocs mips_elf_check_relocs
7992 #define elf_backend_adjust_dynamic_symbol \
7993 mips_elf_adjust_dynamic_symbol
7994 #define elf_backend_always_size_sections \
7995 mips_elf_always_size_sections
7996 #define elf_backend_size_dynamic_sections \
7997 mips_elf_size_dynamic_sections
7998 #define elf_backend_relocate_section mips_elf_relocate_section
7999 #define elf_backend_link_output_symbol_hook \
8000 mips_elf_link_output_symbol_hook
8001 #define elf_backend_finish_dynamic_symbol \
8002 mips_elf_finish_dynamic_symbol
8003 #define elf_backend_finish_dynamic_sections \
8004 mips_elf_finish_dynamic_sections
8005 #define elf_backend_gc_mark_hook mips_elf_gc_mark_hook
8006 #define elf_backend_gc_sweep_hook mips_elf_gc_sweep_hook
8008 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
8009 #define elf_backend_plt_header_size 0
8011 #include "elf32-target.h"