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_relocate_section
96 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
97 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
98 static boolean mips_elf_link_output_symbol_hook
99 PARAMS ((bfd
*, struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
101 static boolean mips_elf_create_dynamic_sections
102 PARAMS ((bfd
*, struct bfd_link_info
*));
103 static boolean mips_elf_create_compact_rel_section
104 PARAMS ((bfd
*, struct bfd_link_info
*));
105 static boolean mips_elf_create_got_section
106 PARAMS ((bfd
*, struct bfd_link_info
*));
107 static boolean mips_elf_check_relocs
108 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
109 const Elf_Internal_Rela
*));
110 static boolean mips_elf_adjust_dynamic_symbol
111 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
112 static boolean mips_elf_always_size_sections
113 PARAMS ((bfd
*, struct bfd_link_info
*));
114 static boolean mips_elf_size_dynamic_sections
115 PARAMS ((bfd
*, struct bfd_link_info
*));
116 static boolean mips_elf_finish_dynamic_symbol
117 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
118 Elf_Internal_Sym
*));
119 static boolean mips_elf_finish_dynamic_sections
120 PARAMS ((bfd
*, struct bfd_link_info
*));
121 static boolean mips_elf_add_symbol_hook
122 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
123 const char **, flagword
*, asection
**, bfd_vma
*));
124 static bfd_reloc_status_type mips_elf_final_gp
125 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
126 static bfd_byte
*elf32_mips_get_relocated_section_contents
127 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
128 bfd_byte
*, boolean
, asymbol
**));
129 static asection
*mips_elf_create_msym_section
132 /* The level of IRIX compatibility we're striving for. */
140 /* Nonzero if ABFD is using the N32 ABI. */
142 #define ABI_N32_P(abfd) \
143 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
145 /* What version of Irix we are trying to be compatible with. FIXME:
146 At the moment, we never generate "normal" MIPS ELF ABI executables;
147 we always use some version of Irix. */
149 #define IRIX_COMPAT(abfd) \
150 (ABI_N32_P (abfd) ? ict_irix6 : ict_irix5)
152 /* Whether we are trying to be compatible with IRIX at all. */
154 #define SGI_COMPAT(abfd) \
155 (IRIX_COMPAT (abfd) != ict_none)
157 /* This structure is used to hold .got information when linking. It
158 is stored in the tdata field of the bfd_elf_section_data structure. */
162 /* The symbol index of the first global .got symbol. */
163 unsigned long global_gotsym
;
164 /* The number of local .got entries. */
165 unsigned int local_gotno
;
166 /* The number of local .got entries we have used. */
167 unsigned int assigned_gotno
;
170 /* The name of the msym section. */
171 #define MIPS_ELF_MSYM_SECTION_NAME(abfd) ".msym"
173 /* The number of local .got entries we reserve. */
174 #define MIPS_RESERVED_GOTNO (2)
176 /* Instructions which appear in a stub. For some reason the stub is
177 slightly different on an SGI system. */
178 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
179 #define STUB_LW(abfd) \
181 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
182 : 0x8f998000) /* lw t9,0x8000(gp) */
183 #define STUB_MOVE 0x03e07825 /* move t7,ra */
184 #define STUB_JALR 0x0320f809 /* jal t9 */
185 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
186 #define MIPS_FUNCTION_STUB_SIZE (16)
189 /* We no longer try to identify particular sections for the .dynsym
190 section. When we do, we wind up crashing if there are other random
191 sections with relocations. */
193 /* Names of sections which appear in the .dynsym section in an Irix 5
196 static const char * const mips_elf_dynsym_sec_names
[] =
209 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
210 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
212 /* The number of entries in mips_elf_dynsym_sec_names which go in the
215 #define MIPS_TEXT_DYNSYM_SECNO (3)
219 /* The names of the runtime procedure table symbols used on Irix 5. */
221 static const char * const mips_elf_dynsym_rtproc_names
[] =
224 "_procedure_string_table",
225 "_procedure_table_size",
229 /* These structures are used to generate the .compact_rel section on
234 unsigned long id1
; /* Always one? */
235 unsigned long num
; /* Number of compact relocation entries. */
236 unsigned long id2
; /* Always two? */
237 unsigned long offset
; /* The file offset of the first relocation. */
238 unsigned long reserved0
; /* Zero? */
239 unsigned long reserved1
; /* Zero? */
248 bfd_byte reserved0
[4];
249 bfd_byte reserved1
[4];
250 } Elf32_External_compact_rel
;
254 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
255 unsigned int rtype
: 4; /* Relocation types. See below. */
256 unsigned int dist2to
: 8;
257 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
258 unsigned long konst
; /* KONST field. See below. */
259 unsigned long vaddr
; /* VADDR to be relocated. */
264 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
265 unsigned int rtype
: 4; /* Relocation types. See below. */
266 unsigned int dist2to
: 8;
267 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
268 unsigned long konst
; /* KONST field. See below. */
276 } Elf32_External_crinfo
;
282 } Elf32_External_crinfo2
;
284 /* These are the constants used to swap the bitfields in a crinfo. */
286 #define CRINFO_CTYPE (0x1)
287 #define CRINFO_CTYPE_SH (31)
288 #define CRINFO_RTYPE (0xf)
289 #define CRINFO_RTYPE_SH (27)
290 #define CRINFO_DIST2TO (0xff)
291 #define CRINFO_DIST2TO_SH (19)
292 #define CRINFO_RELVADDR (0x7ffff)
293 #define CRINFO_RELVADDR_SH (0)
295 /* A compact relocation info has long (3 words) or short (2 words)
296 formats. A short format doesn't have VADDR field and relvaddr
297 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
298 #define CRF_MIPS_LONG 1
299 #define CRF_MIPS_SHORT 0
301 /* There are 4 types of compact relocation at least. The value KONST
302 has different meaning for each type:
305 CT_MIPS_REL32 Address in data
306 CT_MIPS_WORD Address in word (XXX)
307 CT_MIPS_GPHI_LO GP - vaddr
308 CT_MIPS_JMPAD Address to jump
311 #define CRT_MIPS_REL32 0xa
312 #define CRT_MIPS_WORD 0xb
313 #define CRT_MIPS_GPHI_LO 0xc
314 #define CRT_MIPS_JMPAD 0xd
316 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
317 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
318 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
319 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
321 static void bfd_elf32_swap_compact_rel_out
322 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
323 static void bfd_elf32_swap_crinfo_out
324 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
326 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
328 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
329 from smaller values. Start with zero, widen, *then* decrement. */
330 #define MINUS_ONE (((bfd_vma)0) - 1)
332 static reloc_howto_type elf_mips_howto_table
[] =
335 HOWTO (R_MIPS_NONE
, /* type */
337 0, /* size (0 = byte, 1 = short, 2 = long) */
339 false, /* pc_relative */
341 complain_overflow_dont
, /* complain_on_overflow */
342 bfd_elf_generic_reloc
, /* special_function */
343 "R_MIPS_NONE", /* name */
344 false, /* partial_inplace */
347 false), /* pcrel_offset */
349 /* 16 bit relocation. */
350 HOWTO (R_MIPS_16
, /* type */
352 1, /* size (0 = byte, 1 = short, 2 = long) */
354 false, /* pc_relative */
356 complain_overflow_bitfield
, /* complain_on_overflow */
357 bfd_elf_generic_reloc
, /* special_function */
358 "R_MIPS_16", /* name */
359 true, /* partial_inplace */
360 0xffff, /* src_mask */
361 0xffff, /* dst_mask */
362 false), /* pcrel_offset */
364 /* 32 bit relocation. */
365 HOWTO (R_MIPS_32
, /* type */
367 2, /* size (0 = byte, 1 = short, 2 = long) */
369 false, /* pc_relative */
371 complain_overflow_bitfield
, /* complain_on_overflow */
372 bfd_elf_generic_reloc
, /* special_function */
373 "R_MIPS_32", /* name */
374 true, /* partial_inplace */
375 0xffffffff, /* src_mask */
376 0xffffffff, /* dst_mask */
377 false), /* pcrel_offset */
379 /* 32 bit symbol relative relocation. */
380 HOWTO (R_MIPS_REL32
, /* type */
382 2, /* size (0 = byte, 1 = short, 2 = long) */
384 false, /* pc_relative */
386 complain_overflow_bitfield
, /* complain_on_overflow */
387 bfd_elf_generic_reloc
, /* special_function */
388 "R_MIPS_REL32", /* name */
389 true, /* partial_inplace */
390 0xffffffff, /* src_mask */
391 0xffffffff, /* dst_mask */
392 false), /* pcrel_offset */
394 /* 26 bit branch address. */
395 HOWTO (R_MIPS_26
, /* type */
397 2, /* size (0 = byte, 1 = short, 2 = long) */
399 false, /* pc_relative */
401 complain_overflow_dont
, /* complain_on_overflow */
402 /* This needs complex overflow
403 detection, because the upper four
404 bits must match the PC. */
405 bfd_elf_generic_reloc
, /* special_function */
406 "R_MIPS_26", /* name */
407 true, /* partial_inplace */
408 0x3ffffff, /* src_mask */
409 0x3ffffff, /* dst_mask */
410 false), /* pcrel_offset */
412 /* High 16 bits of symbol value. */
413 HOWTO (R_MIPS_HI16
, /* type */
415 2, /* size (0 = byte, 1 = short, 2 = long) */
417 false, /* pc_relative */
419 complain_overflow_dont
, /* complain_on_overflow */
420 _bfd_mips_elf_hi16_reloc
, /* special_function */
421 "R_MIPS_HI16", /* name */
422 true, /* partial_inplace */
423 0xffff, /* src_mask */
424 0xffff, /* dst_mask */
425 false), /* pcrel_offset */
427 /* Low 16 bits of symbol value. */
428 HOWTO (R_MIPS_LO16
, /* type */
430 2, /* size (0 = byte, 1 = short, 2 = long) */
432 false, /* pc_relative */
434 complain_overflow_dont
, /* complain_on_overflow */
435 _bfd_mips_elf_lo16_reloc
, /* special_function */
436 "R_MIPS_LO16", /* name */
437 true, /* partial_inplace */
438 0xffff, /* src_mask */
439 0xffff, /* dst_mask */
440 false), /* pcrel_offset */
442 /* GP relative reference. */
443 HOWTO (R_MIPS_GPREL16
, /* type */
445 2, /* size (0 = byte, 1 = short, 2 = long) */
447 false, /* pc_relative */
449 complain_overflow_signed
, /* complain_on_overflow */
450 _bfd_mips_elf_gprel16_reloc
, /* special_function */
451 "R_MIPS_GPREL16", /* name */
452 true, /* partial_inplace */
453 0xffff, /* src_mask */
454 0xffff, /* dst_mask */
455 false), /* pcrel_offset */
457 /* Reference to literal section. */
458 HOWTO (R_MIPS_LITERAL
, /* type */
460 2, /* size (0 = byte, 1 = short, 2 = long) */
462 false, /* pc_relative */
464 complain_overflow_signed
, /* complain_on_overflow */
465 _bfd_mips_elf_gprel16_reloc
, /* special_function */
466 "R_MIPS_LITERAL", /* name */
467 true, /* partial_inplace */
468 0xffff, /* src_mask */
469 0xffff, /* dst_mask */
470 false), /* pcrel_offset */
472 /* Reference to global offset table. */
473 HOWTO (R_MIPS_GOT16
, /* type */
475 2, /* size (0 = byte, 1 = short, 2 = long) */
477 false, /* pc_relative */
479 complain_overflow_signed
, /* complain_on_overflow */
480 _bfd_mips_elf_got16_reloc
, /* special_function */
481 "R_MIPS_GOT16", /* name */
482 false, /* partial_inplace */
484 0xffff, /* dst_mask */
485 false), /* pcrel_offset */
487 /* 16 bit PC relative reference. */
488 HOWTO (R_MIPS_PC16
, /* type */
490 2, /* size (0 = byte, 1 = short, 2 = long) */
492 true, /* pc_relative */
494 complain_overflow_signed
, /* complain_on_overflow */
495 bfd_elf_generic_reloc
, /* special_function */
496 "R_MIPS_PC16", /* name */
497 true, /* partial_inplace */
498 0xffff, /* src_mask */
499 0xffff, /* dst_mask */
500 false), /* pcrel_offset */
502 /* 16 bit call through global offset table. */
503 /* FIXME: This is not handled correctly. */
504 HOWTO (R_MIPS_CALL16
, /* type */
506 2, /* size (0 = byte, 1 = short, 2 = long) */
508 false, /* pc_relative */
510 complain_overflow_signed
, /* complain_on_overflow */
511 bfd_elf_generic_reloc
, /* special_function */
512 "R_MIPS_CALL16", /* name */
513 false, /* partial_inplace */
515 0xffff, /* dst_mask */
516 false), /* pcrel_offset */
518 /* 32 bit GP relative reference. */
519 HOWTO (R_MIPS_GPREL32
, /* type */
521 2, /* size (0 = byte, 1 = short, 2 = long) */
523 false, /* pc_relative */
525 complain_overflow_bitfield
, /* complain_on_overflow */
526 _bfd_mips_elf_gprel32_reloc
, /* special_function */
527 "R_MIPS_GPREL32", /* name */
528 true, /* partial_inplace */
529 0xffffffff, /* src_mask */
530 0xffffffff, /* dst_mask */
531 false), /* pcrel_offset */
533 /* The remaining relocs are defined on Irix 5, although they are
534 not defined by the ABI. */
539 /* A 5 bit shift field. */
540 HOWTO (R_MIPS_SHIFT5
, /* type */
542 2, /* size (0 = byte, 1 = short, 2 = long) */
544 false, /* pc_relative */
546 complain_overflow_bitfield
, /* complain_on_overflow */
547 bfd_elf_generic_reloc
, /* special_function */
548 "R_MIPS_SHIFT5", /* name */
549 true, /* partial_inplace */
550 0x000007c0, /* src_mask */
551 0x000007c0, /* dst_mask */
552 false), /* pcrel_offset */
554 /* A 6 bit shift field. */
555 /* FIXME: This is not handled correctly; a special function is
556 needed to put the most significant bit in the right place. */
557 HOWTO (R_MIPS_SHIFT6
, /* type */
559 2, /* size (0 = byte, 1 = short, 2 = long) */
561 false, /* pc_relative */
563 complain_overflow_bitfield
, /* complain_on_overflow */
564 bfd_elf_generic_reloc
, /* special_function */
565 "R_MIPS_SHIFT6", /* name */
566 true, /* partial_inplace */
567 0x000007c4, /* src_mask */
568 0x000007c4, /* dst_mask */
569 false), /* pcrel_offset */
571 /* A 64 bit relocation. This is used in 32 bit ELF when addresses
572 are 64 bits long; the upper 32 bits are simply a sign extension.
573 The fields of the howto should be the same as for R_MIPS_32,
574 other than the type, name, and special_function. */
575 HOWTO (R_MIPS_64
, /* type */
577 2, /* size (0 = byte, 1 = short, 2 = long) */
579 false, /* pc_relative */
581 complain_overflow_bitfield
, /* complain_on_overflow */
582 mips32_64bit_reloc
, /* special_function */
583 "R_MIPS_64", /* name */
584 true, /* partial_inplace */
585 0xffffffff, /* src_mask */
586 0xffffffff, /* dst_mask */
587 false), /* pcrel_offset */
589 /* Displacement in the global offset table. */
590 /* FIXME: Not handled correctly. */
591 HOWTO (R_MIPS_GOT_DISP
, /* type */
593 2, /* size (0 = byte, 1 = short, 2 = long) */
595 false, /* pc_relative */
597 complain_overflow_bitfield
, /* complain_on_overflow */
598 bfd_elf_generic_reloc
, /* special_function */
599 "R_MIPS_GOT_DISP", /* name */
600 true, /* partial_inplace */
601 0x0000ffff, /* src_mask */
602 0x0000ffff, /* dst_mask */
603 false), /* pcrel_offset */
605 /* Displacement to page pointer in the global offset table. */
606 /* FIXME: Not handled correctly. */
607 HOWTO (R_MIPS_GOT_PAGE
, /* type */
609 2, /* size (0 = byte, 1 = short, 2 = long) */
611 false, /* pc_relative */
613 complain_overflow_bitfield
, /* complain_on_overflow */
614 bfd_elf_generic_reloc
, /* special_function */
615 "R_MIPS_GOT_PAGE", /* name */
616 true, /* partial_inplace */
617 0x0000ffff, /* src_mask */
618 0x0000ffff, /* dst_mask */
619 false), /* pcrel_offset */
621 /* Offset from page pointer in the global offset table. */
622 /* FIXME: Not handled correctly. */
623 HOWTO (R_MIPS_GOT_OFST
, /* type */
625 2, /* size (0 = byte, 1 = short, 2 = long) */
627 false, /* pc_relative */
629 complain_overflow_bitfield
, /* complain_on_overflow */
630 bfd_elf_generic_reloc
, /* special_function */
631 "R_MIPS_GOT_OFST", /* name */
632 true, /* partial_inplace */
633 0x0000ffff, /* src_mask */
634 0x0000ffff, /* dst_mask */
635 false), /* pcrel_offset */
637 /* High 16 bits of displacement in global offset table. */
638 /* FIXME: Not handled correctly. */
639 HOWTO (R_MIPS_GOT_HI16
, /* type */
641 2, /* size (0 = byte, 1 = short, 2 = long) */
643 false, /* pc_relative */
645 complain_overflow_dont
, /* complain_on_overflow */
646 bfd_elf_generic_reloc
, /* special_function */
647 "R_MIPS_GOT_HI16", /* name */
648 true, /* partial_inplace */
649 0x0000ffff, /* src_mask */
650 0x0000ffff, /* dst_mask */
651 false), /* pcrel_offset */
653 /* Low 16 bits of displacement in global offset table. */
654 /* FIXME: Not handled correctly. */
655 HOWTO (R_MIPS_GOT_LO16
, /* type */
657 2, /* size (0 = byte, 1 = short, 2 = long) */
659 false, /* pc_relative */
661 complain_overflow_dont
, /* complain_on_overflow */
662 bfd_elf_generic_reloc
, /* special_function */
663 "R_MIPS_GOT_LO16", /* name */
664 true, /* partial_inplace */
665 0x0000ffff, /* src_mask */
666 0x0000ffff, /* dst_mask */
667 false), /* pcrel_offset */
669 /* 64 bit subtraction. Used in the N32 ABI. */
670 /* FIXME: Not handled correctly. */
671 HOWTO (R_MIPS_SUB
, /* type */
673 4, /* size (0 = byte, 1 = short, 2 = long) */
675 false, /* pc_relative */
677 complain_overflow_bitfield
, /* complain_on_overflow */
678 bfd_elf_generic_reloc
, /* special_function */
679 "R_MIPS_SUB", /* name */
680 true, /* partial_inplace */
681 MINUS_ONE
, /* src_mask */
682 MINUS_ONE
, /* dst_mask */
683 false), /* pcrel_offset */
685 /* Used to cause the linker to insert and delete instructions? */
690 /* Get the higher values of a 64 bit addend. Presumably not used in
695 /* High 16 bits of displacement in global offset table. */
696 /* FIXME: Not handled correctly. */
697 HOWTO (R_MIPS_CALL_HI16
, /* type */
699 2, /* size (0 = byte, 1 = short, 2 = long) */
701 false, /* pc_relative */
703 complain_overflow_dont
, /* complain_on_overflow */
704 bfd_elf_generic_reloc
, /* special_function */
705 "R_MIPS_CALL_HI16", /* name */
706 true, /* partial_inplace */
707 0x0000ffff, /* src_mask */
708 0x0000ffff, /* dst_mask */
709 false), /* pcrel_offset */
711 /* Low 16 bits of displacement in global offset table. */
712 /* FIXME: Not handled correctly. */
713 HOWTO (R_MIPS_CALL_LO16
, /* type */
715 2, /* size (0 = byte, 1 = short, 2 = long) */
717 false, /* pc_relative */
719 complain_overflow_dont
, /* complain_on_overflow */
720 bfd_elf_generic_reloc
, /* special_function */
721 "R_MIPS_CALL_LO16", /* name */
722 true, /* partial_inplace */
723 0x0000ffff, /* src_mask */
724 0x0000ffff, /* dst_mask */
725 false), /* pcrel_offset */
729 { R_MIPS_ADD_IMMEDIATE
},
733 /* Protected jump conversion. This is an optimization hint. No
734 relocation is required for correctness. */
735 HOWTO (R_MIPS_JALR
, /* type */
737 0, /* size (0 = byte, 1 = short, 2 = long) */
739 false, /* pc_relative */
741 complain_overflow_dont
, /* complain_on_overflow */
742 bfd_elf_generic_reloc
, /* special_function */
743 "R_MIPS_JALR", /* name */
744 false, /* partial_inplace */
745 0x00000000, /* src_mask */
746 0x00000000, /* dst_mask */
747 false), /* pcrel_offset */
750 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
751 is a hack to make the linker think that we need 64 bit values. */
752 static reloc_howto_type elf_mips_ctor64_howto
=
753 HOWTO (R_MIPS_64
, /* type */
755 4, /* size (0 = byte, 1 = short, 2 = long) */
757 false, /* pc_relative */
759 complain_overflow_signed
, /* complain_on_overflow */
760 mips32_64bit_reloc
, /* special_function */
761 "R_MIPS_64", /* name */
762 true, /* partial_inplace */
763 0xffffffff, /* src_mask */
764 0xffffffff, /* dst_mask */
765 false); /* pcrel_offset */
767 /* The reloc used for the mips16 jump instruction. */
768 static reloc_howto_type elf_mips16_jump_howto
=
769 HOWTO (R_MIPS16_26
, /* type */
771 2, /* size (0 = byte, 1 = short, 2 = long) */
773 false, /* pc_relative */
775 complain_overflow_dont
, /* complain_on_overflow */
776 /* This needs complex overflow
777 detection, because the upper four
778 bits must match the PC. */
779 mips16_jump_reloc
, /* special_function */
780 "R_MIPS16_26", /* name */
781 true, /* partial_inplace */
782 0x3ffffff, /* src_mask */
783 0x3ffffff, /* dst_mask */
784 false); /* pcrel_offset */
786 /* The reloc used for the mips16 gprel instruction. The src_mask and
787 dsk_mask for this howto do not reflect the actual instruction, in
788 which the value is not contiguous; the masks are for the
789 convenience of the relocate_section routine. */
790 static reloc_howto_type elf_mips16_gprel_howto
=
791 HOWTO (R_MIPS16_GPREL
, /* type */
793 2, /* size (0 = byte, 1 = short, 2 = long) */
795 false, /* pc_relative */
797 complain_overflow_signed
, /* complain_on_overflow */
798 mips16_gprel_reloc
, /* special_function */
799 "R_MIPS16_GPREL", /* name */
800 true, /* partial_inplace */
801 0xffff, /* src_mask */
802 0xffff, /* dst_mask */
803 false); /* pcrel_offset */
806 /* GNU extension to record C++ vtable hierarchy */
807 static reloc_howto_type elf_mips_gnu_vtinherit_howto
=
808 HOWTO (R_MIPS_GNU_VTINHERIT
, /* type */
810 2, /* size (0 = byte, 1 = short, 2 = long) */
812 false, /* pc_relative */
814 complain_overflow_dont
, /* complain_on_overflow */
815 NULL
, /* special_function */
816 "R_MIPS_GNU_VTINHERIT", /* name */
817 false, /* partial_inplace */
820 false); /* pcrel_offset */
822 /* GNU extension to record C++ vtable member usage */
823 static reloc_howto_type elf_mips_gnu_vtentry_howto
=
824 HOWTO (R_MIPS_GNU_VTENTRY
, /* type */
826 2, /* size (0 = byte, 1 = short, 2 = long) */
828 false, /* pc_relative */
830 complain_overflow_dont
, /* complain_on_overflow */
831 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
832 "R_MIPS_GNU_VTENTRY", /* name */
833 false, /* partial_inplace */
836 false); /* pcrel_offset */
838 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
839 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
840 the HI16. Here we just save the information we need; we do the
841 actual relocation when we see the LO16. MIPS ELF requires that the
842 LO16 immediately follow the HI16. As a GNU extension, we permit an
843 arbitrary number of HI16 relocs to be associated with a single LO16
844 reloc. This extension permits gcc to output the HI and LO relocs
849 struct mips_hi16
*next
;
854 /* FIXME: This should not be a static variable. */
856 static struct mips_hi16
*mips_hi16_list
;
858 bfd_reloc_status_type
859 _bfd_mips_elf_hi16_reloc (abfd
,
867 arelent
*reloc_entry
;
870 asection
*input_section
;
872 char **error_message
;
874 bfd_reloc_status_type ret
;
878 /* If we're relocating, and this an external symbol, we don't want
879 to change anything. */
880 if (output_bfd
!= (bfd
*) NULL
881 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
882 && reloc_entry
->addend
== 0)
884 reloc_entry
->address
+= input_section
->output_offset
;
890 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
892 boolean relocateable
;
895 if (ret
== bfd_reloc_undefined
)
898 if (output_bfd
!= NULL
)
902 relocateable
= false;
903 output_bfd
= symbol
->section
->output_section
->owner
;
906 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
908 if (ret
!= bfd_reloc_ok
)
911 relocation
= gp
- reloc_entry
->address
;
915 if (bfd_is_und_section (symbol
->section
)
916 && output_bfd
== (bfd
*) NULL
)
917 ret
= bfd_reloc_undefined
;
919 if (bfd_is_com_section (symbol
->section
))
922 relocation
= symbol
->value
;
925 relocation
+= symbol
->section
->output_section
->vma
;
926 relocation
+= symbol
->section
->output_offset
;
927 relocation
+= reloc_entry
->addend
;
929 if (reloc_entry
->address
> input_section
->_cooked_size
)
930 return bfd_reloc_outofrange
;
932 /* Save the information, and let LO16 do the actual relocation. */
933 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
935 return bfd_reloc_outofrange
;
936 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
937 n
->addend
= relocation
;
938 n
->next
= mips_hi16_list
;
941 if (output_bfd
!= (bfd
*) NULL
)
942 reloc_entry
->address
+= input_section
->output_offset
;
947 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
948 inplace relocation; this function exists in order to do the
949 R_MIPS_HI16 relocation described above. */
951 bfd_reloc_status_type
952 _bfd_mips_elf_lo16_reloc (abfd
,
960 arelent
*reloc_entry
;
963 asection
*input_section
;
965 char **error_message
;
967 arelent gp_disp_relent
;
969 if (mips_hi16_list
!= NULL
)
979 struct mips_hi16
*next
;
981 /* Do the HI16 relocation. Note that we actually don't need
982 to know anything about the LO16 itself, except where to
983 find the low 16 bits of the addend needed by the LO16. */
984 insn
= bfd_get_32 (abfd
, l
->addr
);
985 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
987 val
= ((insn
& 0xffff) << 16) + vallo
;
990 /* The low order 16 bits are always treated as a signed
991 value. Therefore, a negative value in the low order bits
992 requires an adjustment in the high order bits. We need
993 to make this adjustment in two ways: once for the bits we
994 took from the data, and once for the bits we are putting
995 back in to the data. */
996 if ((vallo
& 0x8000) != 0)
998 if ((val
& 0x8000) != 0)
1001 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
1002 bfd_put_32 (abfd
, insn
, l
->addr
);
1004 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1006 gp_disp_relent
= *reloc_entry
;
1007 reloc_entry
= &gp_disp_relent
;
1008 reloc_entry
->addend
= l
->addend
;
1016 mips_hi16_list
= NULL
;
1018 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1020 bfd_reloc_status_type ret
;
1021 bfd_vma gp
, relocation
;
1023 /* FIXME: Does this case ever occur? */
1025 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
1026 if (ret
!= bfd_reloc_ok
)
1029 relocation
= gp
- reloc_entry
->address
;
1030 relocation
+= symbol
->section
->output_section
->vma
;
1031 relocation
+= symbol
->section
->output_offset
;
1032 relocation
+= reloc_entry
->addend
;
1034 if (reloc_entry
->address
> input_section
->_cooked_size
)
1035 return bfd_reloc_outofrange
;
1037 gp_disp_relent
= *reloc_entry
;
1038 reloc_entry
= &gp_disp_relent
;
1039 reloc_entry
->addend
= relocation
- 4;
1042 /* Now do the LO16 reloc in the usual way. */
1043 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1044 input_section
, output_bfd
, error_message
);
1047 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1048 table used for PIC code. If the symbol is an external symbol, the
1049 instruction is modified to contain the offset of the appropriate
1050 entry in the global offset table. If the symbol is a section
1051 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1052 addends are combined to form the real addend against the section
1053 symbol; the GOT16 is modified to contain the offset of an entry in
1054 the global offset table, and the LO16 is modified to offset it
1055 appropriately. Thus an offset larger than 16 bits requires a
1056 modified value in the global offset table.
1058 This implementation suffices for the assembler, but the linker does
1059 not yet know how to create global offset tables. */
1061 bfd_reloc_status_type
1062 _bfd_mips_elf_got16_reloc (abfd
,
1070 arelent
*reloc_entry
;
1073 asection
*input_section
;
1075 char **error_message
;
1077 /* If we're relocating, and this an external symbol, we don't want
1078 to change anything. */
1079 if (output_bfd
!= (bfd
*) NULL
1080 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1081 && reloc_entry
->addend
== 0)
1083 reloc_entry
->address
+= input_section
->output_offset
;
1084 return bfd_reloc_ok
;
1087 /* If we're relocating, and this is a local symbol, we can handle it
1089 if (output_bfd
!= (bfd
*) NULL
1090 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1091 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1092 input_section
, output_bfd
, error_message
);
1097 /* We have to figure out the gp value, so that we can adjust the
1098 symbol value correctly. We look up the symbol _gp in the output
1099 BFD. If we can't find it, we're stuck. We cache it in the ELF
1100 target data. We don't need to adjust the symbol value for an
1101 external symbol if we are producing relocateable output. */
1103 static bfd_reloc_status_type
1104 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1107 boolean relocateable
;
1108 char **error_message
;
1111 if (bfd_is_und_section (symbol
->section
)
1115 return bfd_reloc_undefined
;
1118 *pgp
= _bfd_get_gp_value (output_bfd
);
1121 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1125 /* Make up a value. */
1126 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1127 _bfd_set_gp_value (output_bfd
, *pgp
);
1135 count
= bfd_get_symcount (output_bfd
);
1136 sym
= bfd_get_outsymbols (output_bfd
);
1138 if (sym
== (asymbol
**) NULL
)
1142 for (i
= 0; i
< count
; i
++, sym
++)
1144 register CONST
char *name
;
1146 name
= bfd_asymbol_name (*sym
);
1147 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1149 *pgp
= bfd_asymbol_value (*sym
);
1150 _bfd_set_gp_value (output_bfd
, *pgp
);
1158 /* Only get the error once. */
1160 _bfd_set_gp_value (output_bfd
, *pgp
);
1162 (char *) _("GP relative relocation when _gp not defined");
1163 return bfd_reloc_dangerous
;
1168 return bfd_reloc_ok
;
1171 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1172 become the offset from the gp register. This function also handles
1173 R_MIPS_LITERAL relocations, although those can be handled more
1174 cleverly because the entries in the .lit8 and .lit4 sections can be
1177 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1178 arelent
*, asection
*,
1179 boolean
, PTR
, bfd_vma
));
1181 bfd_reloc_status_type
1182 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1183 output_bfd
, error_message
)
1185 arelent
*reloc_entry
;
1188 asection
*input_section
;
1190 char **error_message
;
1192 boolean relocateable
;
1193 bfd_reloc_status_type ret
;
1196 /* If we're relocating, and this is an external symbol with no
1197 addend, we don't want to change anything. We will only have an
1198 addend if this is a newly created reloc, not read from an ELF
1200 if (output_bfd
!= (bfd
*) NULL
1201 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1202 && reloc_entry
->addend
== 0)
1204 reloc_entry
->address
+= input_section
->output_offset
;
1205 return bfd_reloc_ok
;
1208 if (output_bfd
!= (bfd
*) NULL
)
1209 relocateable
= true;
1212 relocateable
= false;
1213 output_bfd
= symbol
->section
->output_section
->owner
;
1216 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1218 if (ret
!= bfd_reloc_ok
)
1221 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1222 relocateable
, data
, gp
);
1225 static bfd_reloc_status_type
1226 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1230 arelent
*reloc_entry
;
1231 asection
*input_section
;
1232 boolean relocateable
;
1240 if (bfd_is_com_section (symbol
->section
))
1243 relocation
= symbol
->value
;
1245 relocation
+= symbol
->section
->output_section
->vma
;
1246 relocation
+= symbol
->section
->output_offset
;
1248 if (reloc_entry
->address
> input_section
->_cooked_size
)
1249 return bfd_reloc_outofrange
;
1251 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1253 /* Set val to the offset into the section or symbol. */
1254 if (reloc_entry
->howto
->src_mask
== 0)
1256 /* This case occurs with the 64-bit MIPS ELF ABI. */
1257 val
= reloc_entry
->addend
;
1261 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1266 /* Adjust val for the final section location and GP value. If we
1267 are producing relocateable output, we don't want to do this for
1268 an external symbol. */
1270 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1271 val
+= relocation
- gp
;
1273 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1274 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1277 reloc_entry
->address
+= input_section
->output_offset
;
1279 /* Make sure it fit in 16 bits. */
1280 if (val
>= 0x8000 && val
< 0xffff8000)
1281 return bfd_reloc_overflow
;
1283 return bfd_reloc_ok
;
1286 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1287 from the gp register? XXX */
1289 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1290 arelent
*, asection
*,
1291 boolean
, PTR
, bfd_vma
));
1293 bfd_reloc_status_type
1294 _bfd_mips_elf_gprel32_reloc (abfd
,
1302 arelent
*reloc_entry
;
1305 asection
*input_section
;
1307 char **error_message
;
1309 boolean relocateable
;
1310 bfd_reloc_status_type ret
;
1313 /* If we're relocating, and this is an external symbol with no
1314 addend, we don't want to change anything. We will only have an
1315 addend if this is a newly created reloc, not read from an ELF
1317 if (output_bfd
!= (bfd
*) NULL
1318 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1319 && reloc_entry
->addend
== 0)
1321 *error_message
= (char *)
1322 _("32bits gp relative relocation occurs for an external symbol");
1323 return bfd_reloc_outofrange
;
1326 if (output_bfd
!= (bfd
*) NULL
)
1328 relocateable
= true;
1329 gp
= _bfd_get_gp_value (output_bfd
);
1333 relocateable
= false;
1334 output_bfd
= symbol
->section
->output_section
->owner
;
1336 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1337 error_message
, &gp
);
1338 if (ret
!= bfd_reloc_ok
)
1342 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1343 relocateable
, data
, gp
);
1346 static bfd_reloc_status_type
1347 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1351 arelent
*reloc_entry
;
1352 asection
*input_section
;
1353 boolean relocateable
;
1360 if (bfd_is_com_section (symbol
->section
))
1363 relocation
= symbol
->value
;
1365 relocation
+= symbol
->section
->output_section
->vma
;
1366 relocation
+= symbol
->section
->output_offset
;
1368 if (reloc_entry
->address
> input_section
->_cooked_size
)
1369 return bfd_reloc_outofrange
;
1371 if (reloc_entry
->howto
->src_mask
== 0)
1373 /* This case arises with the 64-bit MIPS ELF ABI. */
1377 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1379 /* Set val to the offset into the section or symbol. */
1380 val
+= reloc_entry
->addend
;
1382 /* Adjust val for the final section location and GP value. If we
1383 are producing relocateable output, we don't want to do this for
1384 an external symbol. */
1386 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1387 val
+= relocation
- gp
;
1389 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1392 reloc_entry
->address
+= input_section
->output_offset
;
1394 return bfd_reloc_ok
;
1397 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1398 generated when addreses are 64 bits. The upper 32 bits are a simle
1401 static bfd_reloc_status_type
1402 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1403 output_bfd
, error_message
)
1405 arelent
*reloc_entry
;
1408 asection
*input_section
;
1410 char **error_message
;
1412 bfd_reloc_status_type r
;
1417 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1418 input_section
, output_bfd
, error_message
);
1419 if (r
!= bfd_reloc_continue
)
1422 /* Do a normal 32 bit relocation on the lower 32 bits. */
1423 reloc32
= *reloc_entry
;
1424 if (bfd_big_endian (abfd
))
1425 reloc32
.address
+= 4;
1426 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1427 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1428 output_bfd
, error_message
);
1430 /* Sign extend into the upper 32 bits. */
1431 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1432 if ((val
& 0x80000000) != 0)
1436 addr
= reloc_entry
->address
;
1437 if (bfd_little_endian (abfd
))
1439 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1444 /* Handle a mips16 jump. */
1446 static bfd_reloc_status_type
1447 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1448 output_bfd
, error_message
)
1450 arelent
*reloc_entry
;
1453 asection
*input_section
;
1455 char **error_message
;
1457 if (output_bfd
!= (bfd
*) NULL
1458 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1459 && reloc_entry
->addend
== 0)
1461 reloc_entry
->address
+= input_section
->output_offset
;
1462 return bfd_reloc_ok
;
1467 static boolean warned
;
1470 (*_bfd_error_handler
)
1471 (_("Linking mips16 objects into %s format is not supported"),
1472 bfd_get_target (input_section
->output_section
->owner
));
1476 return bfd_reloc_undefined
;
1479 /* Handle a mips16 GP relative reloc. */
1481 static bfd_reloc_status_type
1482 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1483 output_bfd
, error_message
)
1485 arelent
*reloc_entry
;
1488 asection
*input_section
;
1490 char **error_message
;
1492 boolean relocateable
;
1493 bfd_reloc_status_type ret
;
1495 unsigned short extend
, insn
;
1496 unsigned long final
;
1498 /* If we're relocating, and this is an external symbol with no
1499 addend, we don't want to change anything. We will only have an
1500 addend if this is a newly created reloc, not read from an ELF
1502 if (output_bfd
!= NULL
1503 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1504 && reloc_entry
->addend
== 0)
1506 reloc_entry
->address
+= input_section
->output_offset
;
1507 return bfd_reloc_ok
;
1510 if (output_bfd
!= NULL
)
1511 relocateable
= true;
1514 relocateable
= false;
1515 output_bfd
= symbol
->section
->output_section
->owner
;
1518 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1520 if (ret
!= bfd_reloc_ok
)
1523 if (reloc_entry
->address
> input_section
->_cooked_size
)
1524 return bfd_reloc_outofrange
;
1526 /* Pick up the mips16 extend instruction and the real instruction. */
1527 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1528 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1530 /* Stuff the current addend back as a 32 bit value, do the usual
1531 relocation, and then clean up. */
1533 (((extend
& 0x1f) << 11)
1536 (bfd_byte
*) data
+ reloc_entry
->address
);
1538 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1539 relocateable
, data
, gp
);
1541 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1544 | ((final
>> 11) & 0x1f)
1546 (bfd_byte
*) data
+ reloc_entry
->address
);
1550 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1555 /* Return the ISA for a MIPS e_flags value. */
1558 elf_mips_isa (flags
)
1561 switch (flags
& EF_MIPS_ARCH
)
1575 /* Return the MACH for a MIPS e_flags value. */
1578 elf_mips_mach (flags
)
1581 switch (flags
& EF_MIPS_MACH
)
1583 case E_MIPS_MACH_3900
:
1584 return bfd_mach_mips3900
;
1586 case E_MIPS_MACH_4010
:
1587 return bfd_mach_mips4010
;
1589 case E_MIPS_MACH_4100
:
1590 return bfd_mach_mips4100
;
1592 case E_MIPS_MACH_4111
:
1593 return bfd_mach_mips4111
;
1595 case E_MIPS_MACH_4650
:
1596 return bfd_mach_mips4650
;
1599 switch (flags
& EF_MIPS_ARCH
)
1603 return bfd_mach_mips3000
;
1607 return bfd_mach_mips6000
;
1611 return bfd_mach_mips4000
;
1615 return bfd_mach_mips8000
;
1623 /* Return printable name for ABI from flagword. */
1626 elf_mips_abi_name (flags
)
1629 switch (flags
& EF_MIPS_ABI
)
1633 case E_MIPS_ABI_O32
:
1635 case E_MIPS_ABI_O64
:
1637 case E_MIPS_ABI_EABI32
:
1639 case E_MIPS_ABI_EABI64
:
1642 return "unknown abi";
1646 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1648 struct elf_reloc_map
{
1649 bfd_reloc_code_real_type bfd_reloc_val
;
1650 enum elf_mips_reloc_type elf_reloc_val
;
1653 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1655 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1656 { BFD_RELOC_16
, R_MIPS_16
},
1657 { BFD_RELOC_32
, R_MIPS_32
},
1658 { BFD_RELOC_64
, R_MIPS_64
},
1659 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1660 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1661 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1662 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1663 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1664 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1665 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1666 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1667 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1668 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1669 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1670 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1671 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
},
1672 { BFD_RELOC_MIPS_SUB
, R_MIPS_SUB
},
1673 { BFD_RELOC_MIPS_GOT_PAGE
, R_MIPS_GOT_PAGE
},
1674 { BFD_RELOC_MIPS_GOT_OFST
, R_MIPS_GOT_OFST
},
1675 { BFD_RELOC_MIPS_GOT_DISP
, R_MIPS_GOT_DISP
}
1678 /* Given a BFD reloc type, return a howto structure. */
1680 static reloc_howto_type
*
1681 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1683 bfd_reloc_code_real_type code
;
1687 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1689 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1690 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1696 bfd_set_error (bfd_error_bad_value
);
1699 case BFD_RELOC_CTOR
:
1700 /* We need to handle BFD_RELOC_CTOR specially.
1701 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1702 size of addresses on this architecture. */
1703 if (bfd_arch_bits_per_address (abfd
) == 32)
1704 return &elf_mips_howto_table
[(int) R_MIPS_32
];
1706 return &elf_mips_ctor64_howto
;
1708 case BFD_RELOC_MIPS16_JMP
:
1709 return &elf_mips16_jump_howto
;
1710 case BFD_RELOC_MIPS16_GPREL
:
1711 return &elf_mips16_gprel_howto
;
1712 case BFD_RELOC_VTABLE_INHERIT
:
1713 return &elf_mips_gnu_vtinherit_howto
;
1714 case BFD_RELOC_VTABLE_ENTRY
:
1715 return &elf_mips_gnu_vtentry_howto
;
1719 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
1722 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1725 Elf32_Internal_Rel
*dst
;
1727 unsigned int r_type
;
1729 r_type
= ELF32_R_TYPE (dst
->r_info
);
1733 cache_ptr
->howto
= &elf_mips16_jump_howto
;
1735 case R_MIPS16_GPREL
:
1736 cache_ptr
->howto
= &elf_mips16_gprel_howto
;
1738 case R_MIPS_GNU_VTINHERIT
:
1739 cache_ptr
->howto
= &elf_mips_gnu_vtinherit_howto
;
1741 case R_MIPS_GNU_VTENTRY
:
1742 cache_ptr
->howto
= &elf_mips_gnu_vtentry_howto
;
1746 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1747 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1751 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1752 value for the object file. We get the addend now, rather than
1753 when we do the relocation, because the symbol manipulations done
1754 by the linker may cause us to lose track of the input BFD. */
1755 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1756 && (r_type
== (unsigned int) R_MIPS_GPREL16
1757 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1758 cache_ptr
->addend
= elf_gp (abfd
);
1761 /* Given a MIPS Elf32_Internal_Rela, fill in an arelent structure. */
1764 mips_info_to_howto_rela (abfd
, cache_ptr
, dst
)
1767 Elf32_Internal_Rela
*dst
;
1769 /* Since an Elf32_Internal_Rel is an initial prefix of an
1770 Elf32_Internal_Rela, we can just use mips_info_to_howto_rel
1772 mips_info_to_howto_rel (abfd
, cache_ptr
, (Elf32_Internal_Rel
*) dst
);
1774 /* If we ever need to do any extra processing with dst->r_addend
1775 (the field omitted in an Elf32_Internal_Rel) we can do it here. */
1778 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1779 routines swap this structure in and out. They are used outside of
1780 BFD, so they are globally visible. */
1783 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1785 const Elf32_External_RegInfo
*ex
;
1788 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1789 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1790 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1791 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1792 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1793 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1797 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1799 const Elf32_RegInfo
*in
;
1800 Elf32_External_RegInfo
*ex
;
1802 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1803 (bfd_byte
*) ex
->ri_gprmask
);
1804 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1805 (bfd_byte
*) ex
->ri_cprmask
[0]);
1806 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1807 (bfd_byte
*) ex
->ri_cprmask
[1]);
1808 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1809 (bfd_byte
*) ex
->ri_cprmask
[2]);
1810 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1811 (bfd_byte
*) ex
->ri_cprmask
[3]);
1812 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1813 (bfd_byte
*) ex
->ri_gp_value
);
1816 /* In the 64 bit ABI, the .MIPS.options section holds register
1817 information in an Elf64_Reginfo structure. These routines swap
1818 them in and out. They are globally visible because they are used
1819 outside of BFD. These routines are here so that gas can call them
1820 without worrying about whether the 64 bit ABI has been included. */
1823 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1825 const Elf64_External_RegInfo
*ex
;
1826 Elf64_Internal_RegInfo
*in
;
1828 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1829 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
1830 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1831 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1832 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1833 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1834 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1838 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1840 const Elf64_Internal_RegInfo
*in
;
1841 Elf64_External_RegInfo
*ex
;
1843 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1844 (bfd_byte
*) ex
->ri_gprmask
);
1845 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
1846 (bfd_byte
*) ex
->ri_pad
);
1847 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1848 (bfd_byte
*) ex
->ri_cprmask
[0]);
1849 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1850 (bfd_byte
*) ex
->ri_cprmask
[1]);
1851 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1852 (bfd_byte
*) ex
->ri_cprmask
[2]);
1853 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1854 (bfd_byte
*) ex
->ri_cprmask
[3]);
1855 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1856 (bfd_byte
*) ex
->ri_gp_value
);
1859 /* Swap an entry in a .gptab section. Note that these routines rely
1860 on the equivalence of the two elements of the union. */
1863 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1865 const Elf32_External_gptab
*ex
;
1868 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1869 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1873 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1875 const Elf32_gptab
*in
;
1876 Elf32_External_gptab
*ex
;
1878 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1879 ex
->gt_entry
.gt_g_value
);
1880 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1881 ex
->gt_entry
.gt_bytes
);
1885 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1887 const Elf32_compact_rel
*in
;
1888 Elf32_External_compact_rel
*ex
;
1890 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
1891 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
1892 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
1893 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
1894 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
1895 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
1899 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1901 const Elf32_crinfo
*in
;
1902 Elf32_External_crinfo
*ex
;
1906 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1907 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1908 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1909 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1910 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
1911 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
1912 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
1915 /* Swap in an options header. */
1918 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1920 const Elf_External_Options
*ex
;
1921 Elf_Internal_Options
*in
;
1923 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
1924 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
1925 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
1926 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
1929 /* Swap out an options header. */
1932 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
1934 const Elf_Internal_Options
*in
;
1935 Elf_External_Options
*ex
;
1937 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
1938 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
1939 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
1940 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
1943 /* Swap in an MSYM entry. */
1946 bfd_mips_elf_swap_msym_in (abfd
, ex
, in
)
1948 const Elf32_External_Msym
*ex
;
1949 Elf32_Internal_Msym
*in
;
1951 in
->ms_hash_value
= bfd_h_get_32 (abfd
, ex
->ms_hash_value
);
1952 in
->ms_info
= bfd_h_get_32 (abfd
, ex
->ms_info
);
1955 /* Swap out an MSYM entry. */
1958 bfd_mips_elf_swap_msym_out (abfd
, in
, ex
)
1960 const Elf32_Internal_Msym
*in
;
1961 Elf32_External_Msym
*ex
;
1963 bfd_h_put_32 (abfd
, in
->ms_hash_value
, ex
->ms_hash_value
);
1964 bfd_h_put_32 (abfd
, in
->ms_info
, ex
->ms_info
);
1968 /* Determine whether a symbol is global for the purposes of splitting
1969 the symbol table into global symbols and local symbols. At least
1970 on Irix 5, this split must be between section symbols and all other
1971 symbols. On most ELF targets the split is between static symbols
1972 and externally visible symbols. */
1976 mips_elf_sym_is_global (abfd
, sym
)
1980 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
1983 /* Set the right machine number for a MIPS ELF file. This is used for
1984 both the 32-bit and the 64-bit ABI. */
1987 _bfd_mips_elf_object_p (abfd
)
1990 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
,
1991 elf_mips_mach (elf_elfheader (abfd
)->e_flags
));
1995 /* Set the right machine number for a 32-bit MIPS ELF file. */
1998 mips_elf32_object_p (abfd
)
2001 /* Irix 5 is broken. Object file symbol tables are not always
2002 sorted correctly such that local symbols precede global symbols,
2003 and the sh_info field in the symbol table is not always right. */
2004 elf_bad_symtab (abfd
) = true;
2006 return _bfd_mips_elf_object_p (abfd
);
2009 /* The final processing done just before writing out a MIPS ELF object
2010 file. This gets the MIPS architecture right based on the machine
2011 number. This is used by both the 32-bit and the 64-bit ABI. */
2015 _bfd_mips_elf_final_write_processing (abfd
, linker
)
2021 Elf_Internal_Shdr
**hdrpp
;
2025 switch (bfd_get_mach (abfd
))
2028 case bfd_mach_mips3000
:
2029 val
= E_MIPS_ARCH_1
;
2032 case bfd_mach_mips3900
:
2033 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
2036 case bfd_mach_mips6000
:
2037 val
= E_MIPS_ARCH_2
;
2040 case bfd_mach_mips4000
:
2041 case bfd_mach_mips4300
:
2042 val
= E_MIPS_ARCH_3
;
2045 case bfd_mach_mips4010
:
2046 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
2049 case bfd_mach_mips4100
:
2050 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
2053 case bfd_mach_mips4111
:
2054 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
2057 case bfd_mach_mips4650
:
2058 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
2061 case bfd_mach_mips8000
:
2062 val
= E_MIPS_ARCH_4
;
2066 elf_elfheader (abfd
)->e_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2067 elf_elfheader (abfd
)->e_flags
|= val
;
2069 /* Set the sh_info field for .gptab sections and other appropriate
2070 info for each special section. */
2071 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
2072 i
< elf_elfheader (abfd
)->e_shnum
;
2075 switch ((*hdrpp
)->sh_type
)
2078 case SHT_MIPS_LIBLIST
:
2079 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
2081 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2084 case SHT_MIPS_GPTAB
:
2085 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2086 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2087 BFD_ASSERT (name
!= NULL
2088 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
2089 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
2090 BFD_ASSERT (sec
!= NULL
);
2091 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2094 case SHT_MIPS_CONTENT
:
2095 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2096 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2097 BFD_ASSERT (name
!= NULL
2098 && strncmp (name
, ".MIPS.content",
2099 sizeof ".MIPS.content" - 1) == 0);
2100 sec
= bfd_get_section_by_name (abfd
,
2101 name
+ sizeof ".MIPS.content" - 1);
2102 BFD_ASSERT (sec
!= NULL
);
2103 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2106 case SHT_MIPS_SYMBOL_LIB
:
2107 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
2109 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2110 sec
= bfd_get_section_by_name (abfd
, ".liblist");
2112 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2115 case SHT_MIPS_EVENTS
:
2116 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2117 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2118 BFD_ASSERT (name
!= NULL
);
2119 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
2120 sec
= bfd_get_section_by_name (abfd
,
2121 name
+ sizeof ".MIPS.events" - 1);
2124 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
2125 sizeof ".MIPS.post_rel" - 1) == 0);
2126 sec
= bfd_get_section_by_name (abfd
,
2128 + sizeof ".MIPS.post_rel" - 1));
2130 BFD_ASSERT (sec
!= NULL
);
2131 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2138 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
2141 _bfd_mips_elf_set_private_flags (abfd
, flags
)
2145 BFD_ASSERT (!elf_flags_init (abfd
)
2146 || elf_elfheader (abfd
)->e_flags
== flags
);
2148 elf_elfheader (abfd
)->e_flags
= flags
;
2149 elf_flags_init (abfd
) = true;
2153 /* Copy backend specific data from one object module to another */
2156 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
2160 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2161 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2164 BFD_ASSERT (!elf_flags_init (obfd
)
2165 || (elf_elfheader (obfd
)->e_flags
2166 == elf_elfheader (ibfd
)->e_flags
));
2168 elf_gp (obfd
) = elf_gp (ibfd
);
2169 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
2170 elf_flags_init (obfd
) = true;
2174 /* Merge backend specific data from an object file to the output
2175 object file when linking. */
2178 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
2186 /* Check if we have the same endianess */
2187 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2188 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2192 if (bfd_big_endian (ibfd
))
2193 msg
= _("%s: compiled for a big endian system and target is little endian");
2195 msg
= _("%s: compiled for a little endian system and target is big endian");
2197 (*_bfd_error_handler
) (msg
, bfd_get_filename (ibfd
));
2199 bfd_set_error (bfd_error_wrong_format
);
2203 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2204 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2207 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2208 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
2209 old_flags
= elf_elfheader (obfd
)->e_flags
;
2211 if (! elf_flags_init (obfd
))
2213 elf_flags_init (obfd
) = true;
2214 elf_elfheader (obfd
)->e_flags
= new_flags
;
2216 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2217 && bfd_get_arch_info (obfd
)->the_default
)
2219 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
2220 bfd_get_mach (ibfd
)))
2227 /* Check flag compatibility. */
2229 new_flags
&= ~EF_MIPS_NOREORDER
;
2230 old_flags
&= ~EF_MIPS_NOREORDER
;
2232 if (new_flags
== old_flags
)
2237 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
2239 new_flags
&= ~EF_MIPS_PIC
;
2240 old_flags
&= ~EF_MIPS_PIC
;
2241 (*_bfd_error_handler
)
2242 (_("%s: linking PIC files with non-PIC files"),
2243 bfd_get_filename (ibfd
));
2247 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
2249 new_flags
&= ~EF_MIPS_CPIC
;
2250 old_flags
&= ~EF_MIPS_CPIC
;
2251 (*_bfd_error_handler
)
2252 (_("%s: linking abicalls files with non-abicalls files"),
2253 bfd_get_filename (ibfd
));
2257 /* Compare the ISA's. */
2258 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
2259 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
2261 int new_mach
= new_flags
& EF_MIPS_MACH
;
2262 int old_mach
= old_flags
& EF_MIPS_MACH
;
2263 int new_isa
= elf_mips_isa (new_flags
);
2264 int old_isa
= elf_mips_isa (old_flags
);
2266 /* If either has no machine specified, just compare the general isa's.
2267 Some combinations of machines are ok, if the isa's match. */
2270 || new_mach
== old_mach
2273 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
2274 and -mips4 code. They will normally use the same data sizes and
2275 calling conventions. */
2277 if ((new_isa
== 1 || new_isa
== 2)
2278 ? (old_isa
!= 1 && old_isa
!= 2)
2279 : (old_isa
== 1 || old_isa
== 2))
2281 (*_bfd_error_handler
)
2282 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
2283 bfd_get_filename (ibfd
), new_isa
, old_isa
);
2290 (*_bfd_error_handler
)
2291 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
2292 bfd_get_filename (ibfd
),
2293 elf_mips_mach (new_flags
),
2294 elf_mips_mach (old_flags
));
2298 new_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2299 old_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2303 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
))
2305 /* Only error if both are set (to different values). */
2306 if ((new_flags
& EF_MIPS_ABI
)
2307 && (old_flags
& EF_MIPS_ABI
))
2309 (*_bfd_error_handler
)
2310 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
2311 bfd_get_filename (ibfd
),
2312 elf_mips_abi_name (new_flags
),
2313 elf_mips_abi_name (old_flags
));
2316 new_flags
&= ~EF_MIPS_ABI
;
2317 old_flags
&= ~EF_MIPS_ABI
;
2320 /* Warn about any other mismatches */
2321 if (new_flags
!= old_flags
)
2323 (*_bfd_error_handler
)
2324 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2325 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
2326 (unsigned long) old_flags
);
2332 bfd_set_error (bfd_error_bad_value
);
2340 _bfd_mips_elf_print_private_bfd_data (abfd
, ptr
)
2344 FILE *file
= (FILE *) ptr
;
2346 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
2348 /* Print normal ELF private data. */
2349 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
2351 /* xgettext:c-format */
2352 fprintf (file
, _ ("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
2354 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
2355 fprintf (file
, _ (" [abi=O32]"));
2356 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
2357 fprintf (file
, _ (" [abi=O64]"));
2358 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
2359 fprintf (file
, _ (" [abi=EABI32]"));
2360 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
2361 fprintf (file
, _ (" [abi=EABI64]"));
2362 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
2363 fprintf (file
, _ (" [abi unknown]"));
2364 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI2
))
2365 fprintf (file
, _ (" [abi=N32]"));
2367 fprintf (file
, _ (" [no abi set]"));
2369 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
2370 fprintf (file
, _ (" [mips1]"));
2371 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
2372 fprintf (file
, _ (" [mips2]"));
2373 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
2374 fprintf (file
, _ (" [mips3]"));
2375 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
2376 fprintf (file
, _ (" [mips4]"));
2378 fprintf (file
, _ (" [unknown ISA]"));
2380 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
2381 fprintf (file
, _ (" [32bitmode]"));
2383 fprintf (file
, _ (" [not 32bitmode]"));
2390 /* Handle a MIPS specific section when reading an object file. This
2391 is called when elfcode.h finds a section with an unknown type.
2392 This routine supports both the 32-bit and 64-bit ELF ABI.
2394 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2398 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
2400 Elf_Internal_Shdr
*hdr
;
2405 /* There ought to be a place to keep ELF backend specific flags, but
2406 at the moment there isn't one. We just keep track of the
2407 sections by their name, instead. Fortunately, the ABI gives
2408 suggested names for all the MIPS specific sections, so we will
2409 probably get away with this. */
2410 switch (hdr
->sh_type
)
2412 case SHT_MIPS_LIBLIST
:
2413 if (strcmp (name
, ".liblist") != 0)
2417 if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) != 0)
2420 case SHT_MIPS_CONFLICT
:
2421 if (strcmp (name
, ".conflict") != 0)
2424 case SHT_MIPS_GPTAB
:
2425 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
2428 case SHT_MIPS_UCODE
:
2429 if (strcmp (name
, ".ucode") != 0)
2432 case SHT_MIPS_DEBUG
:
2433 if (strcmp (name
, ".mdebug") != 0)
2435 flags
= SEC_DEBUGGING
;
2437 case SHT_MIPS_REGINFO
:
2438 if (strcmp (name
, ".reginfo") != 0
2439 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
2441 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
2443 case SHT_MIPS_IFACE
:
2444 if (strcmp (name
, ".MIPS.interfaces") != 0)
2447 case SHT_MIPS_CONTENT
:
2448 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2451 case SHT_MIPS_OPTIONS
:
2452 if (strcmp (name
, ".options") != 0
2453 && strcmp (name
, ".MIPS.options") != 0)
2456 case SHT_MIPS_DWARF
:
2457 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2460 case SHT_MIPS_SYMBOL_LIB
:
2461 if (strcmp (name
, ".MIPS.symlib") != 0)
2464 case SHT_MIPS_EVENTS
:
2465 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2466 && strncmp (name
, ".MIPS.post_rel",
2467 sizeof ".MIPS.post_rel" - 1) != 0)
2474 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2479 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
2480 (bfd_get_section_flags (abfd
,
2489 /* Handle a 32-bit MIPS ELF specific section. */
2492 mips_elf32_section_from_shdr (abfd
, hdr
, name
)
2494 Elf_Internal_Shdr
*hdr
;
2497 if (! _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
))
2500 /* FIXME: We should record sh_info for a .gptab section. */
2502 /* For a .reginfo section, set the gp value in the tdata information
2503 from the contents of this section. We need the gp value while
2504 processing relocs, so we just get it now. The .reginfo section
2505 is not used in the 64-bit MIPS ELF ABI. */
2506 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2508 Elf32_External_RegInfo ext
;
2511 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
2512 (file_ptr
) 0, sizeof ext
))
2514 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
2515 elf_gp (abfd
) = s
.ri_gp_value
;
2518 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2519 set the gp value based on what we find. We may see both
2520 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2521 they should agree. */
2522 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
2524 bfd_byte
*contents
, *l
, *lend
;
2526 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
2527 if (contents
== NULL
)
2529 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
2530 (file_ptr
) 0, hdr
->sh_size
))
2536 lend
= contents
+ hdr
->sh_size
;
2537 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2539 Elf_Internal_Options intopt
;
2541 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2543 if (intopt
.kind
== ODK_REGINFO
)
2545 Elf32_RegInfo intreg
;
2547 bfd_mips_elf32_swap_reginfo_in
2549 ((Elf32_External_RegInfo
*)
2550 (l
+ sizeof (Elf_External_Options
))),
2552 elf_gp (abfd
) = intreg
.ri_gp_value
;
2562 /* Set the correct type for a MIPS ELF section. We do this by the
2563 section name, which is a hack, but ought to work. This routine is
2564 used by both the 32-bit and the 64-bit ABI. */
2567 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
2569 Elf32_Internal_Shdr
*hdr
;
2572 register const char *name
;
2574 name
= bfd_get_section_name (abfd
, sec
);
2576 if (strcmp (name
, ".liblist") == 0)
2578 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
2579 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
2580 /* The sh_link field is set in final_write_processing. */
2582 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) == 0)
2584 hdr
->sh_type
= SHT_MIPS_MSYM
;
2585 hdr
->sh_entsize
= 8;
2586 /* FIXME: Set the sh_info field. */
2588 else if (strcmp (name
, ".conflict") == 0)
2589 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
2590 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2592 hdr
->sh_type
= SHT_MIPS_GPTAB
;
2593 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
2594 /* The sh_info field is set in final_write_processing. */
2596 else if (strcmp (name
, ".ucode") == 0)
2597 hdr
->sh_type
= SHT_MIPS_UCODE
;
2598 else if (strcmp (name
, ".mdebug") == 0)
2600 hdr
->sh_type
= SHT_MIPS_DEBUG
;
2601 /* In a shared object on Irix 5.3, the .mdebug section has an
2602 entsize of 0. FIXME: Does this matter? */
2603 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2604 hdr
->sh_entsize
= 0;
2606 hdr
->sh_entsize
= 1;
2608 else if (strcmp (name
, ".reginfo") == 0)
2610 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2611 /* In a shared object on Irix 5.3, the .reginfo section has an
2612 entsize of 0x18. FIXME: Does this matter? */
2613 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2614 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2616 hdr
->sh_entsize
= 1;
2618 else if (SGI_COMPAT (abfd
)
2619 && (strcmp (name
, ".hash") == 0
2620 || strcmp (name
, ".dynamic") == 0
2621 || strcmp (name
, ".dynstr") == 0))
2623 hdr
->sh_entsize
= 0;
2625 /* This isn't how the Irix 6 linker behaves. */
2626 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2629 else if (strcmp (name
, ".got") == 0
2630 || strcmp (name
, ".sdata") == 0
2631 || strcmp (name
, ".sbss") == 0
2632 || strcmp (name
, ".lit4") == 0
2633 || strcmp (name
, ".lit8") == 0)
2634 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2635 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2637 hdr
->sh_type
= SHT_MIPS_IFACE
;
2638 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2640 else if (strncmp (name
, ".MIPS.content", strlen (".MIPS.content")) == 0)
2642 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2643 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2644 /* The sh_info field is set in final_write_processing. */
2646 else if (strcmp (name
, ".options") == 0
2647 || strcmp (name
, ".MIPS.options") == 0)
2649 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2650 hdr
->sh_entsize
= 1;
2651 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2653 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2654 hdr
->sh_type
= SHT_MIPS_DWARF
;
2655 else if (strcmp (name
, ".MIPS.symlib") == 0)
2657 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2658 /* The sh_link and sh_info fields are set in
2659 final_write_processing. */
2661 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2662 || strncmp (name
, ".MIPS.post_rel",
2663 sizeof ".MIPS.post_rel" - 1) == 0)
2665 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2666 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2667 /* The sh_link field is set in final_write_processing. */
2669 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) == 0)
2671 hdr
->sh_type
= SHT_MIPS_MSYM
;
2672 hdr
->sh_flags
|= SHF_ALLOC
;
2673 hdr
->sh_entsize
= 8;
2679 /* Given a BFD section, try to locate the corresponding ELF section
2680 index. This is used by both the 32-bit and the 64-bit ABI.
2681 Actually, it's not clear to me that the 64-bit ABI supports these,
2682 but for non-PIC objects we will certainly want support for at least
2683 the .scommon section. */
2686 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2688 Elf32_Internal_Shdr
*hdr
;
2692 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2694 *retval
= SHN_MIPS_SCOMMON
;
2697 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2699 *retval
= SHN_MIPS_ACOMMON
;
2705 /* When are writing out the .options or .MIPS.options section,
2706 remember the bytes we are writing out, so that we can install the
2707 GP value in the section_processing routine. */
2710 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2715 bfd_size_type count
;
2717 if (strcmp (section
->name
, ".options") == 0
2718 || strcmp (section
->name
, ".MIPS.options") == 0)
2722 if (elf_section_data (section
) == NULL
)
2724 section
->used_by_bfd
=
2725 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
2726 if (elf_section_data (section
) == NULL
)
2729 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
2734 if (section
->_cooked_size
!= 0)
2735 size
= section
->_cooked_size
;
2737 size
= section
->_raw_size
;
2738 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
2741 elf_section_data (section
)->tdata
= (PTR
) c
;
2744 memcpy (c
+ offset
, location
, count
);
2747 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
2751 /* Work over a section just before writing it out. This routine is
2752 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2753 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2757 _bfd_mips_elf_section_processing (abfd
, hdr
)
2759 Elf_Internal_Shdr
*hdr
;
2761 if (hdr
->bfd_section
!= NULL
)
2763 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
2765 if (strcmp (name
, ".sdata") == 0)
2767 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2768 hdr
->sh_type
= SHT_PROGBITS
;
2770 else if (strcmp (name
, ".sbss") == 0)
2772 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2773 hdr
->sh_type
= SHT_NOBITS
;
2775 else if (strcmp (name
, ".lit8") == 0
2776 || strcmp (name
, ".lit4") == 0)
2778 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2779 hdr
->sh_type
= SHT_PROGBITS
;
2781 else if (strcmp (name
, ".compact_rel") == 0)
2784 hdr
->sh_type
= SHT_PROGBITS
;
2786 else if (strcmp (name
, ".rtproc") == 0)
2788 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
2790 unsigned int adjust
;
2792 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
2794 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
2802 /* Work over a section just before writing it out. We update the GP
2803 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2804 on the value we are using. */
2807 mips_elf32_section_processing (abfd
, hdr
)
2809 Elf32_Internal_Shdr
*hdr
;
2811 if (hdr
->sh_type
== SHT_MIPS_REGINFO
2812 && hdr
->sh_size
> 0)
2816 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2817 BFD_ASSERT (hdr
->contents
== NULL
);
2820 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2823 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2824 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2828 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2829 && hdr
->bfd_section
!= NULL
2830 && elf_section_data (hdr
->bfd_section
) != NULL
2831 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2833 bfd_byte
*contents
, *l
, *lend
;
2835 /* We stored the section contents in the elf_section_data tdata
2836 field in the set_section_contents routine. We save the
2837 section contents so that we don't have to read them again.
2838 At this point we know that elf_gp is set, so we can look
2839 through the section contents to see if there is an
2840 ODK_REGINFO structure. */
2842 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2844 lend
= contents
+ hdr
->sh_size
;
2845 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2847 Elf_Internal_Options intopt
;
2849 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2851 if (intopt
.kind
== ODK_REGINFO
)
2858 + sizeof (Elf_External_Options
)
2859 + (sizeof (Elf32_External_RegInfo
) - 4)),
2862 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
2863 if (bfd_write (buf
, 1, 4, abfd
) != 4)
2870 return _bfd_mips_elf_section_processing (abfd
, hdr
);
2873 /* MIPS ELF uses two common sections. One is the usual one, and the
2874 other is for small objects. All the small objects are kept
2875 together, and then referenced via the gp pointer, which yields
2876 faster assembler code. This is what we use for the small common
2877 section. This approach is copied from ecoff.c. */
2878 static asection mips_elf_scom_section
;
2879 static asymbol mips_elf_scom_symbol
;
2880 static asymbol
*mips_elf_scom_symbol_ptr
;
2882 /* MIPS ELF also uses an acommon section, which represents an
2883 allocated common symbol which may be overridden by a
2884 definition in a shared library. */
2885 static asection mips_elf_acom_section
;
2886 static asymbol mips_elf_acom_symbol
;
2887 static asymbol
*mips_elf_acom_symbol_ptr
;
2889 /* The Irix 5 support uses two virtual sections, which represent
2890 text/data symbols defined in dynamic objects. */
2891 static asection mips_elf_text_section
;
2892 static asection
*mips_elf_text_section_ptr
;
2893 static asymbol mips_elf_text_symbol
;
2894 static asymbol
*mips_elf_text_symbol_ptr
;
2896 static asection mips_elf_data_section
;
2897 static asection
*mips_elf_data_section_ptr
;
2898 static asymbol mips_elf_data_symbol
;
2899 static asymbol
*mips_elf_data_symbol_ptr
;
2901 /* Handle the special MIPS section numbers that a symbol may use.
2902 This is used for both the 32-bit and the 64-bit ABI. */
2905 _bfd_mips_elf_symbol_processing (abfd
, asym
)
2909 elf_symbol_type
*elfsym
;
2911 elfsym
= (elf_symbol_type
*) asym
;
2912 switch (elfsym
->internal_elf_sym
.st_shndx
)
2914 case SHN_MIPS_ACOMMON
:
2915 /* This section is used in a dynamically linked executable file.
2916 It is an allocated common section. The dynamic linker can
2917 either resolve these symbols to something in a shared
2918 library, or it can just leave them here. For our purposes,
2919 we can consider these symbols to be in a new section. */
2920 if (mips_elf_acom_section
.name
== NULL
)
2922 /* Initialize the acommon section. */
2923 mips_elf_acom_section
.name
= ".acommon";
2924 mips_elf_acom_section
.flags
= SEC_ALLOC
;
2925 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
2926 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
2927 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
2928 mips_elf_acom_symbol
.name
= ".acommon";
2929 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
2930 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
2931 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
2933 asym
->section
= &mips_elf_acom_section
;
2937 /* Common symbols less than the GP size are automatically
2938 treated as SHN_MIPS_SCOMMON symbols. */
2939 if (asym
->value
> elf_gp_size (abfd
))
2942 case SHN_MIPS_SCOMMON
:
2943 if (mips_elf_scom_section
.name
== NULL
)
2945 /* Initialize the small common section. */
2946 mips_elf_scom_section
.name
= ".scommon";
2947 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
2948 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
2949 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
2950 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
2951 mips_elf_scom_symbol
.name
= ".scommon";
2952 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2953 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
2954 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
2956 asym
->section
= &mips_elf_scom_section
;
2957 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2960 case SHN_MIPS_SUNDEFINED
:
2961 asym
->section
= bfd_und_section_ptr
;
2964 #if 0 /* for SGI_COMPAT */
2966 asym
->section
= mips_elf_text_section_ptr
;
2970 asym
->section
= mips_elf_data_section_ptr
;
2976 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
2980 mips_elf_additional_program_headers (abfd
)
2988 if (! SGI_COMPAT (abfd
))
2991 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2992 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2994 /* We need a PT_MIPS_REGINFO segment. */
2998 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2999 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3001 /* We need a PT_MIPS_RTPROC segment. */
3008 /* Modify the segment map for an Irix 5 executable. */
3011 mips_elf_modify_segment_map (abfd
)
3015 struct elf_segment_map
*m
, **pm
;
3017 if (! SGI_COMPAT (abfd
))
3020 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
3022 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3023 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3025 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3026 if (m
->p_type
== PT_MIPS_REGINFO
)
3030 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3034 m
->p_type
= PT_MIPS_REGINFO
;
3038 /* We want to put it after the PHDR and INTERP segments. */
3039 pm
= &elf_tdata (abfd
)->segment_map
;
3041 && ((*pm
)->p_type
== PT_PHDR
3042 || (*pm
)->p_type
== PT_INTERP
))
3050 /* If there are .dynamic and .mdebug sections, we make a room for
3051 the RTPROC header. FIXME: Rewrite without section names. */
3052 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
3053 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3054 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3056 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3057 if (m
->p_type
== PT_MIPS_RTPROC
)
3061 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3065 m
->p_type
= PT_MIPS_RTPROC
;
3067 s
= bfd_get_section_by_name (abfd
, ".rtproc");
3072 m
->p_flags_valid
= 1;
3080 /* We want to put it after the DYNAMIC segment. */
3081 pm
= &elf_tdata (abfd
)->segment_map
;
3082 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
3092 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
3093 .dynsym, and .hash sections, and everything in between. */
3094 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
3095 if ((*pm
)->p_type
== PT_DYNAMIC
)
3100 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
3102 static const char *sec_names
[] =
3103 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
3106 struct elf_segment_map
*n
;
3110 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
3112 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
3113 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3119 sz
= s
->_cooked_size
;
3122 if (high
< s
->vma
+ sz
)
3128 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3129 if ((s
->flags
& SEC_LOAD
) != 0
3132 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3136 n
= ((struct elf_segment_map
*)
3137 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
3144 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3146 if ((s
->flags
& SEC_LOAD
) != 0
3149 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3163 /* The structure of the runtime procedure descriptor created by the
3164 loader for use by the static exception system. */
3166 typedef struct runtime_pdr
{
3167 bfd_vma adr
; /* memory address of start of procedure */
3168 long regmask
; /* save register mask */
3169 long regoffset
; /* save register offset */
3170 long fregmask
; /* save floating point register mask */
3171 long fregoffset
; /* save floating point register offset */
3172 long frameoffset
; /* frame size */
3173 short framereg
; /* frame pointer register */
3174 short pcreg
; /* offset or reg of return pc */
3175 long irpss
; /* index into the runtime string table */
3177 struct exception_info
*exception_info
;/* pointer to exception array */
3179 #define cbRPDR sizeof(RPDR)
3180 #define rpdNil ((pRPDR) 0)
3182 /* Swap RPDR (runtime procedure table entry) for output. */
3184 static void ecoff_swap_rpdr_out
3185 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
3188 ecoff_swap_rpdr_out (abfd
, in
, ex
)
3191 struct rpdr_ext
*ex
;
3193 /* ecoff_put_off was defined in ecoffswap.h. */
3194 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
3195 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
3196 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
3197 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
3198 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
3199 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
3201 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
3202 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
3204 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
3206 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
3210 /* Read ECOFF debugging information from a .mdebug section into a
3211 ecoff_debug_info structure. */
3214 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
3217 struct ecoff_debug_info
*debug
;
3220 const struct ecoff_debug_swap
*swap
;
3221 char *ext_hdr
= NULL
;
3223 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3224 memset (debug
, 0, sizeof(*debug
));
3226 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
3227 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
3230 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
3231 swap
->external_hdr_size
)
3235 symhdr
= &debug
->symbolic_header
;
3236 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
3238 /* The symbolic header contains absolute file offsets and sizes to
3240 #define READ(ptr, offset, count, size, type) \
3241 if (symhdr->count == 0) \
3242 debug->ptr = NULL; \
3245 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
3246 if (debug->ptr == NULL) \
3247 goto error_return; \
3248 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3249 || (bfd_read (debug->ptr, size, symhdr->count, \
3250 abfd) != size * symhdr->count)) \
3251 goto error_return; \
3254 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
3255 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
3256 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
3257 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
3258 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
3259 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
3261 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
3262 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
3263 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
3264 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
3265 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
3269 debug
->adjust
= NULL
;
3274 if (ext_hdr
!= NULL
)
3276 if (debug
->line
!= NULL
)
3278 if (debug
->external_dnr
!= NULL
)
3279 free (debug
->external_dnr
);
3280 if (debug
->external_pdr
!= NULL
)
3281 free (debug
->external_pdr
);
3282 if (debug
->external_sym
!= NULL
)
3283 free (debug
->external_sym
);
3284 if (debug
->external_opt
!= NULL
)
3285 free (debug
->external_opt
);
3286 if (debug
->external_aux
!= NULL
)
3287 free (debug
->external_aux
);
3288 if (debug
->ss
!= NULL
)
3290 if (debug
->ssext
!= NULL
)
3291 free (debug
->ssext
);
3292 if (debug
->external_fdr
!= NULL
)
3293 free (debug
->external_fdr
);
3294 if (debug
->external_rfd
!= NULL
)
3295 free (debug
->external_rfd
);
3296 if (debug
->external_ext
!= NULL
)
3297 free (debug
->external_ext
);
3301 /* MIPS ELF local labels start with '$', not 'L'. */
3305 mips_elf_is_local_label_name (abfd
, name
)
3312 /* On Irix 6, the labels go back to starting with '.', so we accept
3313 the generic ELF local label syntax as well. */
3314 return _bfd_elf_is_local_label_name (abfd
, name
);
3317 /* MIPS ELF uses a special find_nearest_line routine in order the
3318 handle the ECOFF debugging information. */
3320 struct mips_elf_find_line
3322 struct ecoff_debug_info d
;
3323 struct ecoff_find_line i
;
3327 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
3328 functionname_ptr
, line_ptr
)
3333 const char **filename_ptr
;
3334 const char **functionname_ptr
;
3335 unsigned int *line_ptr
;
3339 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
3340 filename_ptr
, functionname_ptr
,
3344 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3345 filename_ptr
, functionname_ptr
,
3349 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
3353 struct mips_elf_find_line
*fi
;
3354 const struct ecoff_debug_swap
* const swap
=
3355 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3357 /* If we are called during a link, mips_elf_final_link may have
3358 cleared the SEC_HAS_CONTENTS field. We force it back on here
3359 if appropriate (which it normally will be). */
3360 origflags
= msec
->flags
;
3361 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
3362 msec
->flags
|= SEC_HAS_CONTENTS
;
3364 fi
= elf_tdata (abfd
)->find_line_info
;
3367 bfd_size_type external_fdr_size
;
3370 struct fdr
*fdr_ptr
;
3372 fi
= ((struct mips_elf_find_line
*)
3373 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
3376 msec
->flags
= origflags
;
3380 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
3382 msec
->flags
= origflags
;
3386 /* Swap in the FDR information. */
3387 fi
->d
.fdr
= ((struct fdr
*)
3389 (fi
->d
.symbolic_header
.ifdMax
*
3390 sizeof (struct fdr
))));
3391 if (fi
->d
.fdr
== NULL
)
3393 msec
->flags
= origflags
;
3396 external_fdr_size
= swap
->external_fdr_size
;
3397 fdr_ptr
= fi
->d
.fdr
;
3398 fraw_src
= (char *) fi
->d
.external_fdr
;
3399 fraw_end
= (fraw_src
3400 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
3401 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
3402 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
3404 elf_tdata (abfd
)->find_line_info
= fi
;
3406 /* Note that we don't bother to ever free this information.
3407 find_nearest_line is either called all the time, as in
3408 objdump -l, so the information should be saved, or it is
3409 rarely called, as in ld error messages, so the memory
3410 wasted is unimportant. Still, it would probably be a
3411 good idea for free_cached_info to throw it away. */
3414 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
3415 &fi
->i
, filename_ptr
, functionname_ptr
,
3418 msec
->flags
= origflags
;
3422 msec
->flags
= origflags
;
3425 /* Fall back on the generic ELF find_nearest_line routine. */
3427 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
3428 filename_ptr
, functionname_ptr
,
3432 /* The mips16 compiler uses a couple of special sections to handle
3433 floating point arguments.
3435 Section names that look like .mips16.fn.FNNAME contain stubs that
3436 copy floating point arguments from the fp regs to the gp regs and
3437 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3438 call should be redirected to the stub instead. If no 32 bit
3439 function calls FNNAME, the stub should be discarded. We need to
3440 consider any reference to the function, not just a call, because
3441 if the address of the function is taken we will need the stub,
3442 since the address might be passed to a 32 bit function.
3444 Section names that look like .mips16.call.FNNAME contain stubs
3445 that copy floating point arguments from the gp regs to the fp
3446 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3447 then any 16 bit function that calls FNNAME should be redirected
3448 to the stub instead. If FNNAME is not a 32 bit function, the
3449 stub should be discarded.
3451 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3452 which call FNNAME and then copy the return value from the fp regs
3453 to the gp regs. These stubs store the return value in $18 while
3454 calling FNNAME; any function which might call one of these stubs
3455 must arrange to save $18 around the call. (This case is not
3456 needed for 32 bit functions that call 16 bit functions, because
3457 16 bit functions always return floating point values in both
3460 Note that in all cases FNNAME might be defined statically.
3461 Therefore, FNNAME is not used literally. Instead, the relocation
3462 information will indicate which symbol the section is for.
3464 We record any stubs that we find in the symbol table. */
3466 #define FN_STUB ".mips16.fn."
3467 #define CALL_STUB ".mips16.call."
3468 #define CALL_FP_STUB ".mips16.call.fp."
3470 /* The MIPS ELF linker needs additional information for each symbol in
3471 the global hash table. */
3473 struct mips_elf_link_hash_entry
3475 struct elf_link_hash_entry root
;
3477 /* External symbol information. */
3480 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
3481 unsigned int mips_32_relocs
;
3483 /* The index of the first dynamic relocation (in the .rel.dyn
3484 section) against this symbol. */
3485 unsigned int min_dyn_reloc_index
;
3487 /* If there is a stub that 32 bit functions should use to call this
3488 16 bit function, this points to the section containing the stub. */
3491 /* Whether we need the fn_stub; this is set if this symbol appears
3492 in any relocs other than a 16 bit call. */
3493 boolean need_fn_stub
;
3495 /* If there is a stub that 16 bit functions should use to call this
3496 32 bit function, this points to the section containing the stub. */
3497 asection
*call_stub
;
3499 /* This is like the call_stub field, but it is used if the function
3500 being called returns a floating point value. */
3501 asection
*call_fp_stub
;
3504 /* MIPS ELF linker hash table. */
3506 struct mips_elf_link_hash_table
3508 struct elf_link_hash_table root
;
3510 /* We no longer use this. */
3511 /* String section indices for the dynamic section symbols. */
3512 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
3514 /* The number of .rtproc entries. */
3515 bfd_size_type procedure_count
;
3516 /* The size of the .compact_rel section (if SGI_COMPAT). */
3517 bfd_size_type compact_rel_size
;
3518 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3519 entry is set to the address of __rld_obj_head as in Irix 5. */
3520 boolean use_rld_obj_head
;
3521 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3523 /* This is set if we see any mips16 stub sections. */
3524 boolean mips16_stubs_seen
;
3527 /* Look up an entry in a MIPS ELF linker hash table. */
3529 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3530 ((struct mips_elf_link_hash_entry *) \
3531 elf_link_hash_lookup (&(table)->root, (string), (create), \
3534 /* Traverse a MIPS ELF linker hash table. */
3536 #define mips_elf_link_hash_traverse(table, func, info) \
3537 (elf_link_hash_traverse \
3539 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3542 /* Get the MIPS ELF linker hash table from a link_info structure. */
3544 #define mips_elf_hash_table(p) \
3545 ((struct mips_elf_link_hash_table *) ((p)->hash))
3547 static boolean mips_elf_output_extsym
3548 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3550 /* Create an entry in a MIPS ELF linker hash table. */
3552 static struct bfd_hash_entry
*
3553 mips_elf_link_hash_newfunc (entry
, table
, string
)
3554 struct bfd_hash_entry
*entry
;
3555 struct bfd_hash_table
*table
;
3558 struct mips_elf_link_hash_entry
*ret
=
3559 (struct mips_elf_link_hash_entry
*) entry
;
3561 /* Allocate the structure if it has not already been allocated by a
3563 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3564 ret
= ((struct mips_elf_link_hash_entry
*)
3565 bfd_hash_allocate (table
,
3566 sizeof (struct mips_elf_link_hash_entry
)));
3567 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3568 return (struct bfd_hash_entry
*) ret
;
3570 /* Call the allocation method of the superclass. */
3571 ret
= ((struct mips_elf_link_hash_entry
*)
3572 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3574 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3576 /* Set local fields. */
3577 memset (&ret
->esym
, 0, sizeof (EXTR
));
3578 /* We use -2 as a marker to indicate that the information has
3579 not been set. -1 means there is no associated ifd. */
3581 ret
->mips_32_relocs
= 0;
3582 ret
->min_dyn_reloc_index
= 0;
3583 ret
->fn_stub
= NULL
;
3584 ret
->need_fn_stub
= false;
3585 ret
->call_stub
= NULL
;
3586 ret
->call_fp_stub
= NULL
;
3589 return (struct bfd_hash_entry
*) ret
;
3592 /* Create a MIPS ELF linker hash table. */
3594 static struct bfd_link_hash_table
*
3595 mips_elf_link_hash_table_create (abfd
)
3598 struct mips_elf_link_hash_table
*ret
;
3600 ret
= ((struct mips_elf_link_hash_table
*)
3601 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
3602 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
3605 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3606 mips_elf_link_hash_newfunc
))
3608 bfd_release (abfd
, ret
);
3613 /* We no longer use this. */
3614 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
3615 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
3617 ret
->procedure_count
= 0;
3618 ret
->compact_rel_size
= 0;
3619 ret
->use_rld_obj_head
= false;
3621 ret
->mips16_stubs_seen
= false;
3623 return &ret
->root
.root
;
3626 /* Hook called by the linker routine which adds symbols from an object
3627 file. We must handle the special MIPS section numbers here. */
3631 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3633 struct bfd_link_info
*info
;
3634 const Elf_Internal_Sym
*sym
;
3640 if (SGI_COMPAT (abfd
)
3641 && (abfd
->flags
& DYNAMIC
) != 0
3642 && strcmp (*namep
, "_rld_new_interface") == 0)
3644 /* Skip Irix 5 rld entry name. */
3649 switch (sym
->st_shndx
)
3652 /* Common symbols less than the GP size are automatically
3653 treated as SHN_MIPS_SCOMMON symbols. */
3654 if (sym
->st_size
> elf_gp_size (abfd
))
3657 case SHN_MIPS_SCOMMON
:
3658 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3659 (*secp
)->flags
|= SEC_IS_COMMON
;
3660 *valp
= sym
->st_size
;
3664 /* This section is used in a shared object. */
3665 if (mips_elf_text_section_ptr
== NULL
)
3667 /* Initialize the section. */
3668 mips_elf_text_section
.name
= ".text";
3669 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
3670 mips_elf_text_section
.output_section
= NULL
;
3671 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
3672 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
3673 mips_elf_text_symbol
.name
= ".text";
3674 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
3675 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
3676 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
3677 mips_elf_text_section_ptr
= &mips_elf_text_section
;
3679 /* This code used to do *secp = bfd_und_section_ptr if
3680 info->shared. I don't know why, and that doesn't make sense,
3681 so I took it out. */
3682 *secp
= mips_elf_text_section_ptr
;
3685 case SHN_MIPS_ACOMMON
:
3686 /* Fall through. XXX Can we treat this as allocated data? */
3688 /* This section is used in a shared object. */
3689 if (mips_elf_data_section_ptr
== NULL
)
3691 /* Initialize the section. */
3692 mips_elf_data_section
.name
= ".data";
3693 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
3694 mips_elf_data_section
.output_section
= NULL
;
3695 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
3696 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
3697 mips_elf_data_symbol
.name
= ".data";
3698 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
3699 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
3700 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
3701 mips_elf_data_section_ptr
= &mips_elf_data_section
;
3703 /* This code used to do *secp = bfd_und_section_ptr if
3704 info->shared. I don't know why, and that doesn't make sense,
3705 so I took it out. */
3706 *secp
= mips_elf_data_section_ptr
;
3709 case SHN_MIPS_SUNDEFINED
:
3710 *secp
= bfd_und_section_ptr
;
3714 if (SGI_COMPAT (abfd
)
3716 && info
->hash
->creator
== abfd
->xvec
3717 && strcmp (*namep
, "__rld_obj_head") == 0)
3719 struct elf_link_hash_entry
*h
;
3721 /* Mark __rld_obj_head as dynamic. */
3723 if (! (_bfd_generic_link_add_one_symbol
3724 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3725 (bfd_vma
) *valp
, (const char *) NULL
, false,
3726 get_elf_backend_data (abfd
)->collect
,
3727 (struct bfd_link_hash_entry
**) &h
)))
3729 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
3730 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3731 h
->type
= STT_OBJECT
;
3733 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3736 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3739 /* If this is a mips16 text symbol, add 1 to the value to make it
3740 odd. This will cause something like .word SYM to come up with
3741 the right value when it is loaded into the PC. */
3742 if (sym
->st_other
== STO_MIPS16
)
3748 /* Structure used to pass information to mips_elf_output_extsym. */
3753 struct bfd_link_info
*info
;
3754 struct ecoff_debug_info
*debug
;
3755 const struct ecoff_debug_swap
*swap
;
3759 /* This routine is used to write out ECOFF debugging external symbol
3760 information. It is called via mips_elf_link_hash_traverse. The
3761 ECOFF external symbol information must match the ELF external
3762 symbol information. Unfortunately, at this point we don't know
3763 whether a symbol is required by reloc information, so the two
3764 tables may wind up being different. We must sort out the external
3765 symbol information before we can set the final size of the .mdebug
3766 section, and we must set the size of the .mdebug section before we
3767 can relocate any sections, and we can't know which symbols are
3768 required by relocation until we relocate the sections.
3769 Fortunately, it is relatively unlikely that any symbol will be
3770 stripped but required by a reloc. In particular, it can not happen
3771 when generating a final executable. */
3774 mips_elf_output_extsym (h
, data
)
3775 struct mips_elf_link_hash_entry
*h
;
3778 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
3780 asection
*sec
, *output_section
;
3782 if (h
->root
.indx
== -2)
3784 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3785 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
3786 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3787 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
3789 else if (einfo
->info
->strip
== strip_all
3790 || (einfo
->info
->strip
== strip_some
3791 && bfd_hash_lookup (einfo
->info
->keep_hash
,
3792 h
->root
.root
.root
.string
,
3793 false, false) == NULL
))
3801 if (h
->esym
.ifd
== -2)
3804 h
->esym
.cobol_main
= 0;
3805 h
->esym
.weakext
= 0;
3806 h
->esym
.reserved
= 0;
3807 h
->esym
.ifd
= ifdNil
;
3808 h
->esym
.asym
.value
= 0;
3809 h
->esym
.asym
.st
= stGlobal
;
3811 if (SGI_COMPAT (einfo
->abfd
)
3812 && (h
->root
.root
.type
== bfd_link_hash_undefined
3813 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
3817 /* Use undefined class. Also, set class and type for some
3819 name
= h
->root
.root
.root
.string
;
3820 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
3821 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
3823 h
->esym
.asym
.sc
= scData
;
3824 h
->esym
.asym
.st
= stLabel
;
3825 h
->esym
.asym
.value
= 0;
3827 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
3829 h
->esym
.asym
.sc
= scAbs
;
3830 h
->esym
.asym
.st
= stLabel
;
3831 h
->esym
.asym
.value
=
3832 mips_elf_hash_table (einfo
->info
)->procedure_count
;
3834 else if (strcmp (name
, "_gp_disp") == 0)
3836 h
->esym
.asym
.sc
= scAbs
;
3837 h
->esym
.asym
.st
= stLabel
;
3838 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
3841 h
->esym
.asym
.sc
= scUndefined
;
3843 else if (h
->root
.root
.type
!= bfd_link_hash_defined
3844 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
3845 h
->esym
.asym
.sc
= scAbs
;
3850 sec
= h
->root
.root
.u
.def
.section
;
3851 output_section
= sec
->output_section
;
3853 /* When making a shared library and symbol h is the one from
3854 the another shared library, OUTPUT_SECTION may be null. */
3855 if (output_section
== NULL
)
3856 h
->esym
.asym
.sc
= scUndefined
;
3859 name
= bfd_section_name (output_section
->owner
, output_section
);
3861 if (strcmp (name
, ".text") == 0)
3862 h
->esym
.asym
.sc
= scText
;
3863 else if (strcmp (name
, ".data") == 0)
3864 h
->esym
.asym
.sc
= scData
;
3865 else if (strcmp (name
, ".sdata") == 0)
3866 h
->esym
.asym
.sc
= scSData
;
3867 else if (strcmp (name
, ".rodata") == 0
3868 || strcmp (name
, ".rdata") == 0)
3869 h
->esym
.asym
.sc
= scRData
;
3870 else if (strcmp (name
, ".bss") == 0)
3871 h
->esym
.asym
.sc
= scBss
;
3872 else if (strcmp (name
, ".sbss") == 0)
3873 h
->esym
.asym
.sc
= scSBss
;
3874 else if (strcmp (name
, ".init") == 0)
3875 h
->esym
.asym
.sc
= scInit
;
3876 else if (strcmp (name
, ".fini") == 0)
3877 h
->esym
.asym
.sc
= scFini
;
3879 h
->esym
.asym
.sc
= scAbs
;
3883 h
->esym
.asym
.reserved
= 0;
3884 h
->esym
.asym
.index
= indexNil
;
3887 if (h
->root
.root
.type
== bfd_link_hash_common
)
3888 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
3889 else if (h
->root
.root
.type
== bfd_link_hash_defined
3890 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3892 if (h
->esym
.asym
.sc
== scCommon
)
3893 h
->esym
.asym
.sc
= scBss
;
3894 else if (h
->esym
.asym
.sc
== scSCommon
)
3895 h
->esym
.asym
.sc
= scSBss
;
3897 sec
= h
->root
.root
.u
.def
.section
;
3898 output_section
= sec
->output_section
;
3899 if (output_section
!= NULL
)
3900 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
3901 + sec
->output_offset
3902 + output_section
->vma
);
3904 h
->esym
.asym
.value
= 0;
3906 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3908 /* Set type and value for a symbol with a function stub. */
3909 h
->esym
.asym
.st
= stProc
;
3910 sec
= h
->root
.root
.u
.def
.section
;
3912 h
->esym
.asym
.value
= 0;
3915 output_section
= sec
->output_section
;
3916 if (output_section
!= NULL
)
3917 h
->esym
.asym
.value
= (h
->root
.plt
.offset
3918 + sec
->output_offset
3919 + output_section
->vma
);
3921 h
->esym
.asym
.value
= 0;
3928 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
3929 h
->root
.root
.root
.string
,
3932 einfo
->failed
= true;
3939 /* Create a runtime procedure table from the .mdebug section. */
3942 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
3945 struct bfd_link_info
*info
;
3947 struct ecoff_debug_info
*debug
;
3949 const struct ecoff_debug_swap
*swap
;
3950 HDRR
*hdr
= &debug
->symbolic_header
;
3952 struct rpdr_ext
*erp
;
3954 struct pdr_ext
*epdr
;
3955 struct sym_ext
*esym
;
3958 unsigned long size
, count
;
3959 unsigned long sindex
;
3963 const char *no_name_func
= _("static procedure (no name)");
3971 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3973 sindex
= strlen (no_name_func
) + 1;
3974 count
= hdr
->ipdMax
;
3977 size
= swap
->external_pdr_size
;
3979 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
3983 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
3986 size
= sizeof (RPDR
);
3987 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
3991 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
3995 count
= hdr
->isymMax
;
3996 size
= swap
->external_sym_size
;
3997 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
4001 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
4004 count
= hdr
->issMax
;
4005 ss
= (char *) bfd_malloc (count
);
4008 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
4011 count
= hdr
->ipdMax
;
4012 for (i
= 0; i
< count
; i
++, rp
++)
4014 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
4015 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
4016 rp
->adr
= sym
.value
;
4017 rp
->regmask
= pdr
.regmask
;
4018 rp
->regoffset
= pdr
.regoffset
;
4019 rp
->fregmask
= pdr
.fregmask
;
4020 rp
->fregoffset
= pdr
.fregoffset
;
4021 rp
->frameoffset
= pdr
.frameoffset
;
4022 rp
->framereg
= pdr
.framereg
;
4023 rp
->pcreg
= pdr
.pcreg
;
4025 sv
[i
] = ss
+ sym
.iss
;
4026 sindex
+= strlen (sv
[i
]) + 1;
4030 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
4031 size
= BFD_ALIGN (size
, 16);
4032 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
4035 mips_elf_hash_table (info
)->procedure_count
= 0;
4039 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
4041 erp
= (struct rpdr_ext
*) rtproc
;
4042 memset (erp
, 0, sizeof (struct rpdr_ext
));
4044 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
4045 strcpy (str
, no_name_func
);
4046 str
+= strlen (no_name_func
) + 1;
4047 for (i
= 0; i
< count
; i
++)
4049 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
4050 strcpy (str
, sv
[i
]);
4051 str
+= strlen (sv
[i
]) + 1;
4053 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
4055 /* Set the size and contents of .rtproc section. */
4056 s
->_raw_size
= size
;
4057 s
->contents
= (bfd_byte
*) rtproc
;
4059 /* Skip this section later on (I don't think this currently
4060 matters, but someday it might). */
4061 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
4090 /* A comparison routine used to sort .gptab entries. */
4093 gptab_compare (p1
, p2
)
4097 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
4098 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
4100 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
4103 /* We need to use a special link routine to handle the .reginfo and
4104 the .mdebug sections. We need to merge all instances of these
4105 sections together, not write them all out sequentially. */
4108 mips_elf_final_link (abfd
, info
)
4110 struct bfd_link_info
*info
;
4114 struct bfd_link_order
*p
;
4115 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
4116 asection
*rtproc_sec
;
4117 Elf32_RegInfo reginfo
;
4118 struct ecoff_debug_info debug
;
4119 const struct ecoff_debug_swap
*swap
4120 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4121 HDRR
*symhdr
= &debug
.symbolic_header
;
4122 PTR mdebug_handle
= NULL
;
4124 /* Drop the .options section, since it has special semantics which I
4125 haven't bothered to figure out. */
4126 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
4128 if (strcmp ((*secpp
)->name
, ".options") == 0)
4130 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
4131 if (p
->type
== bfd_indirect_link_order
)
4132 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
4133 (*secpp
)->link_order_head
= NULL
;
4134 *secpp
= (*secpp
)->next
;
4135 --abfd
->section_count
;
4140 /* Get a value for the GP register. */
4141 if (elf_gp (abfd
) == 0)
4143 struct bfd_link_hash_entry
*h
;
4145 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4146 if (h
!= (struct bfd_link_hash_entry
*) NULL
4147 && h
->type
== bfd_link_hash_defined
)
4148 elf_gp (abfd
) = (h
->u
.def
.value
4149 + h
->u
.def
.section
->output_section
->vma
4150 + h
->u
.def
.section
->output_offset
);
4151 else if (info
->relocateable
)
4155 /* Make up a value. */
4157 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4160 && (strcmp (o
->name
, ".sbss") == 0
4161 || strcmp (o
->name
, ".sdata") == 0
4162 || strcmp (o
->name
, ".lit4") == 0
4163 || strcmp (o
->name
, ".lit8") == 0))
4166 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
4170 /* If the relocate_section function needs to do a reloc
4171 involving the GP value, it should make a reloc_dangerous
4172 callback to warn that GP is not defined. */
4176 /* Go through the sections and collect the .reginfo and .mdebug
4180 gptab_data_sec
= NULL
;
4181 gptab_bss_sec
= NULL
;
4182 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4184 if (strcmp (o
->name
, ".reginfo") == 0)
4186 memset (®info
, 0, sizeof reginfo
);
4188 /* We have found the .reginfo section in the output file.
4189 Look through all the link_orders comprising it and merge
4190 the information together. */
4191 for (p
= o
->link_order_head
;
4192 p
!= (struct bfd_link_order
*) NULL
;
4195 asection
*input_section
;
4197 Elf32_External_RegInfo ext
;
4200 if (p
->type
!= bfd_indirect_link_order
)
4202 if (p
->type
== bfd_fill_link_order
)
4207 input_section
= p
->u
.indirect
.section
;
4208 input_bfd
= input_section
->owner
;
4210 /* The linker emulation code has probably clobbered the
4211 size to be zero bytes. */
4212 if (input_section
->_raw_size
== 0)
4213 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4215 if (! bfd_get_section_contents (input_bfd
, input_section
,
4221 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
4223 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
4224 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
4225 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
4226 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
4227 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
4229 /* ri_gp_value is set by the function
4230 mips_elf32_section_processing when the section is
4231 finally written out. */
4233 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4234 elf_link_input_bfd ignores this section. */
4235 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4238 /* Size has been set in mips_elf_always_size_sections */
4239 BFD_ASSERT(o
->_raw_size
== sizeof (Elf32_External_RegInfo
));
4241 /* Skip this section later on (I don't think this currently
4242 matters, but someday it might). */
4243 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4248 if (strcmp (o
->name
, ".mdebug") == 0)
4250 struct extsym_info einfo
;
4252 /* We have found the .mdebug section in the output file.
4253 Look through all the link_orders comprising it and merge
4254 the information together. */
4255 symhdr
->magic
= swap
->sym_magic
;
4256 /* FIXME: What should the version stamp be? */
4258 symhdr
->ilineMax
= 0;
4262 symhdr
->isymMax
= 0;
4263 symhdr
->ioptMax
= 0;
4264 symhdr
->iauxMax
= 0;
4266 symhdr
->issExtMax
= 0;
4269 symhdr
->iextMax
= 0;
4271 /* We accumulate the debugging information itself in the
4272 debug_info structure. */
4274 debug
.external_dnr
= NULL
;
4275 debug
.external_pdr
= NULL
;
4276 debug
.external_sym
= NULL
;
4277 debug
.external_opt
= NULL
;
4278 debug
.external_aux
= NULL
;
4280 debug
.ssext
= debug
.ssext_end
= NULL
;
4281 debug
.external_fdr
= NULL
;
4282 debug
.external_rfd
= NULL
;
4283 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4285 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4286 if (mdebug_handle
== (PTR
) NULL
)
4289 if (SGI_COMPAT (abfd
))
4295 static const char * const name
[] =
4296 { ".text", ".init", ".fini", ".data",
4297 ".rodata", ".sdata", ".sbss", ".bss" };
4298 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
4299 scRData
, scSData
, scSBss
, scBss
};
4302 esym
.cobol_main
= 0;
4306 esym
.asym
.iss
= issNil
;
4307 esym
.asym
.st
= stLocal
;
4308 esym
.asym
.reserved
= 0;
4309 esym
.asym
.index
= indexNil
;
4311 for (i
= 0; i
< 8; i
++)
4313 esym
.asym
.sc
= sc
[i
];
4314 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4317 esym
.asym
.value
= s
->vma
;
4318 last
= s
->vma
+ s
->_raw_size
;
4321 esym
.asym
.value
= last
;
4323 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4329 for (p
= o
->link_order_head
;
4330 p
!= (struct bfd_link_order
*) NULL
;
4333 asection
*input_section
;
4335 const struct ecoff_debug_swap
*input_swap
;
4336 struct ecoff_debug_info input_debug
;
4340 if (p
->type
!= bfd_indirect_link_order
)
4342 if (p
->type
== bfd_fill_link_order
)
4347 input_section
= p
->u
.indirect
.section
;
4348 input_bfd
= input_section
->owner
;
4350 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4351 || (get_elf_backend_data (input_bfd
)
4352 ->elf_backend_ecoff_debug_swap
) == NULL
)
4354 /* I don't know what a non MIPS ELF bfd would be
4355 doing with a .mdebug section, but I don't really
4356 want to deal with it. */
4360 input_swap
= (get_elf_backend_data (input_bfd
)
4361 ->elf_backend_ecoff_debug_swap
);
4363 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
4365 /* The ECOFF linking code expects that we have already
4366 read in the debugging information and set up an
4367 ecoff_debug_info structure, so we do that now. */
4368 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
4372 if (! (bfd_ecoff_debug_accumulate
4373 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
4374 &input_debug
, input_swap
, info
)))
4377 /* Loop through the external symbols. For each one with
4378 interesting information, try to find the symbol in
4379 the linker global hash table and save the information
4380 for the output external symbols. */
4381 eraw_src
= input_debug
.external_ext
;
4382 eraw_end
= (eraw_src
4383 + (input_debug
.symbolic_header
.iextMax
4384 * input_swap
->external_ext_size
));
4386 eraw_src
< eraw_end
;
4387 eraw_src
+= input_swap
->external_ext_size
)
4391 struct mips_elf_link_hash_entry
*h
;
4393 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4394 if (ext
.asym
.sc
== scNil
4395 || ext
.asym
.sc
== scUndefined
4396 || ext
.asym
.sc
== scSUndefined
)
4399 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4400 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
4401 name
, false, false, true);
4402 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4408 < input_debug
.symbolic_header
.ifdMax
);
4409 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4415 /* Free up the information we just read. */
4416 free (input_debug
.line
);
4417 free (input_debug
.external_dnr
);
4418 free (input_debug
.external_pdr
);
4419 free (input_debug
.external_sym
);
4420 free (input_debug
.external_opt
);
4421 free (input_debug
.external_aux
);
4422 free (input_debug
.ss
);
4423 free (input_debug
.ssext
);
4424 free (input_debug
.external_fdr
);
4425 free (input_debug
.external_rfd
);
4426 free (input_debug
.external_ext
);
4428 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4429 elf_link_input_bfd ignores this section. */
4430 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4433 if (SGI_COMPAT (abfd
) && info
->shared
)
4435 /* Create .rtproc section. */
4436 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4437 if (rtproc_sec
== NULL
)
4439 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4440 | SEC_LINKER_CREATED
| SEC_READONLY
);
4442 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4443 if (rtproc_sec
== NULL
4444 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4445 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
4449 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
4450 info
, rtproc_sec
, &debug
))
4454 /* Build the external symbol information. */
4457 einfo
.debug
= &debug
;
4459 einfo
.failed
= false;
4460 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4461 mips_elf_output_extsym
,
4466 /* Set the size of the .mdebug section. */
4467 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4469 /* Skip this section later on (I don't think this currently
4470 matters, but someday it might). */
4471 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4476 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4478 const char *subname
;
4481 Elf32_External_gptab
*ext_tab
;
4484 /* The .gptab.sdata and .gptab.sbss sections hold
4485 information describing how the small data area would
4486 change depending upon the -G switch. These sections
4487 not used in executables files. */
4488 if (! info
->relocateable
)
4492 for (p
= o
->link_order_head
;
4493 p
!= (struct bfd_link_order
*) NULL
;
4496 asection
*input_section
;
4498 if (p
->type
!= bfd_indirect_link_order
)
4500 if (p
->type
== bfd_fill_link_order
)
4505 input_section
= p
->u
.indirect
.section
;
4507 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4508 elf_link_input_bfd ignores this section. */
4509 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4512 /* Skip this section later on (I don't think this
4513 currently matters, but someday it might). */
4514 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4516 /* Really remove the section. */
4517 for (secpp
= &abfd
->sections
;
4519 secpp
= &(*secpp
)->next
)
4521 *secpp
= (*secpp
)->next
;
4522 --abfd
->section_count
;
4527 /* There is one gptab for initialized data, and one for
4528 uninitialized data. */
4529 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4531 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4535 (*_bfd_error_handler
)
4536 (_("%s: illegal section name `%s'"),
4537 bfd_get_filename (abfd
), o
->name
);
4538 bfd_set_error (bfd_error_nonrepresentable_section
);
4542 /* The linker script always combines .gptab.data and
4543 .gptab.sdata into .gptab.sdata, and likewise for
4544 .gptab.bss and .gptab.sbss. It is possible that there is
4545 no .sdata or .sbss section in the output file, in which
4546 case we must change the name of the output section. */
4547 subname
= o
->name
+ sizeof ".gptab" - 1;
4548 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4550 if (o
== gptab_data_sec
)
4551 o
->name
= ".gptab.data";
4553 o
->name
= ".gptab.bss";
4554 subname
= o
->name
+ sizeof ".gptab" - 1;
4555 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4558 /* Set up the first entry. */
4560 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
4563 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4564 tab
[0].gt_header
.gt_unused
= 0;
4566 /* Combine the input sections. */
4567 for (p
= o
->link_order_head
;
4568 p
!= (struct bfd_link_order
*) NULL
;
4571 asection
*input_section
;
4575 bfd_size_type gpentry
;
4577 if (p
->type
!= bfd_indirect_link_order
)
4579 if (p
->type
== bfd_fill_link_order
)
4584 input_section
= p
->u
.indirect
.section
;
4585 input_bfd
= input_section
->owner
;
4587 /* Combine the gptab entries for this input section one
4588 by one. We know that the input gptab entries are
4589 sorted by ascending -G value. */
4590 size
= bfd_section_size (input_bfd
, input_section
);
4592 for (gpentry
= sizeof (Elf32_External_gptab
);
4594 gpentry
+= sizeof (Elf32_External_gptab
))
4596 Elf32_External_gptab ext_gptab
;
4597 Elf32_gptab int_gptab
;
4603 if (! (bfd_get_section_contents
4604 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4605 gpentry
, sizeof (Elf32_External_gptab
))))
4611 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
4613 val
= int_gptab
.gt_entry
.gt_g_value
;
4614 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4617 for (look
= 1; look
< c
; look
++)
4619 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4620 tab
[look
].gt_entry
.gt_bytes
+= add
;
4622 if (tab
[look
].gt_entry
.gt_g_value
== val
)
4628 Elf32_gptab
*new_tab
;
4631 /* We need a new table entry. */
4632 new_tab
= ((Elf32_gptab
*)
4633 bfd_realloc ((PTR
) tab
,
4634 (c
+ 1) * sizeof (Elf32_gptab
)));
4635 if (new_tab
== NULL
)
4641 tab
[c
].gt_entry
.gt_g_value
= val
;
4642 tab
[c
].gt_entry
.gt_bytes
= add
;
4644 /* Merge in the size for the next smallest -G
4645 value, since that will be implied by this new
4648 for (look
= 1; look
< c
; look
++)
4650 if (tab
[look
].gt_entry
.gt_g_value
< val
4652 || (tab
[look
].gt_entry
.gt_g_value
4653 > tab
[max
].gt_entry
.gt_g_value
)))
4657 tab
[c
].gt_entry
.gt_bytes
+=
4658 tab
[max
].gt_entry
.gt_bytes
;
4663 last
= int_gptab
.gt_entry
.gt_bytes
;
4666 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4667 elf_link_input_bfd ignores this section. */
4668 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4671 /* The table must be sorted by -G value. */
4673 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
4675 /* Swap out the table. */
4676 ext_tab
= ((Elf32_External_gptab
*)
4677 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
4678 if (ext_tab
== NULL
)
4684 for (i
= 0; i
< c
; i
++)
4685 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
4688 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
4689 o
->contents
= (bfd_byte
*) ext_tab
;
4691 /* Skip this section later on (I don't think this currently
4692 matters, but someday it might). */
4693 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4697 /* Invoke the regular ELF backend linker to do all the work. */
4698 if (! bfd_elf32_bfd_final_link (abfd
, info
))
4701 /* Now write out the computed sections. */
4703 if (reginfo_sec
!= (asection
*) NULL
)
4705 Elf32_External_RegInfo ext
;
4707 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
4708 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4709 (file_ptr
) 0, sizeof ext
))
4713 if (mdebug_sec
!= (asection
*) NULL
)
4715 BFD_ASSERT (abfd
->output_has_begun
);
4716 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4718 mdebug_sec
->filepos
))
4721 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4724 if (gptab_data_sec
!= (asection
*) NULL
)
4726 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4727 gptab_data_sec
->contents
,
4729 gptab_data_sec
->_raw_size
))
4733 if (gptab_bss_sec
!= (asection
*) NULL
)
4735 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4736 gptab_bss_sec
->contents
,
4738 gptab_bss_sec
->_raw_size
))
4742 if (SGI_COMPAT (abfd
))
4744 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4745 if (rtproc_sec
!= NULL
)
4747 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
4748 rtproc_sec
->contents
,
4750 rtproc_sec
->_raw_size
))
4758 /* Handle a MIPS ELF HI16 reloc. */
4761 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
4763 Elf_Internal_Rela
*relhi
;
4764 Elf_Internal_Rela
*rello
;
4771 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4773 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4776 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4778 if ((addlo
& 0x8000) != 0)
4780 if ((addend
& 0x8000) != 0)
4783 bfd_put_32 (input_bfd
,
4784 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
4785 contents
+ relhi
->r_offset
);
4788 /* Handle a MIPS ELF local GOT16 reloc. */
4791 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
4796 Elf_Internal_Rela
*relhi
;
4797 Elf_Internal_Rela
*rello
;
4801 unsigned int assigned_gotno
;
4807 bfd_byte
*got_contents
;
4808 struct mips_got_info
*g
;
4810 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4812 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4815 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4817 if ((addlo
& 0x8000) != 0)
4819 if ((addend
& 0x8000) != 0)
4822 /* Get a got entry representing requested hipage. */
4823 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4824 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4825 BFD_ASSERT (g
!= NULL
);
4827 assigned_gotno
= g
->assigned_gotno
;
4828 got_contents
= sgot
->contents
;
4829 hipage
= addend
& 0xffff0000;
4831 for (i
= MIPS_RESERVED_GOTNO
; i
< assigned_gotno
; i
++)
4833 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
4834 if (hipage
== (address
& 0xffff0000))
4838 if (i
== assigned_gotno
)
4840 if (assigned_gotno
>= g
->local_gotno
)
4842 (*_bfd_error_handler
)
4843 (_("more got entries are needed for hipage relocations"));
4844 bfd_set_error (bfd_error_bad_value
);
4848 bfd_put_32 (input_bfd
, hipage
, got_contents
+ assigned_gotno
* 4);
4849 ++g
->assigned_gotno
;
4852 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
4853 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
4854 contents
+ relhi
->r_offset
);
4859 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
4862 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
4864 Elf_Internal_Rela
*rel
;
4870 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4871 bfd_put_32 (input_bfd
,
4872 (insn
& 0xffff0000) | (offset
& 0xffff),
4873 contents
+ rel
->r_offset
);
4876 /* Relocate a MIPS ELF section. */
4879 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4880 contents
, relocs
, local_syms
, local_sections
)
4882 struct bfd_link_info
*info
;
4884 asection
*input_section
;
4886 Elf_Internal_Rela
*relocs
;
4887 Elf_Internal_Sym
*local_syms
;
4888 asection
**local_sections
;
4890 Elf_Internal_Shdr
*symtab_hdr
;
4893 asection
*sgot
, *sreloc
, *scpt
;
4896 Elf_Internal_Rela
*rel
;
4897 Elf_Internal_Rela
*relend
;
4898 struct mips_got_info
*g
;
4900 dynobj
= elf_hash_table (info
)->dynobj
;
4901 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4905 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
4908 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
4911 if (elf_bad_symtab (input_bfd
))
4913 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
4918 locsymcount
= symtab_hdr
->sh_info
;
4919 extsymoff
= symtab_hdr
->sh_info
;
4922 gp
= _bfd_get_gp_value (output_bfd
);
4925 relend
= relocs
+ input_section
->reloc_count
;
4926 for (; rel
< relend
; rel
++)
4929 reloc_howto_type
*howto
;
4930 unsigned long r_symndx
;
4932 struct elf_link_hash_entry
*h
;
4934 Elf_Internal_Sym
*sym
;
4935 struct mips_elf_link_hash_entry
*mh
;
4937 bfd_reloc_status_type r
;
4939 r_type
= ELF32_R_TYPE (rel
->r_info
);
4940 if (r_type
== R_MIPS_GNU_VTINHERIT
4941 || r_type
== R_MIPS_GNU_VTENTRY
)
4943 if ((r_type
< 0 || r_type
>= (int) R_MIPS_max
)
4944 && r_type
!= R_MIPS16_26
4945 && r_type
!= R_MIPS16_GPREL
)
4947 bfd_set_error (bfd_error_bad_value
);
4950 if (r_type
== R_MIPS16_26
)
4951 howto
= &elf_mips16_jump_howto
;
4952 else if (r_type
== R_MIPS16_GPREL
)
4953 howto
= &elf_mips16_gprel_howto
;
4955 howto
= elf_mips_howto_table
+ r_type
;
4958 && (r_type
== R_MIPS_CALL16
4959 || r_type
== R_MIPS_GOT16
4960 || r_type
== R_MIPS_CALL_HI16
4961 || r_type
== R_MIPS_CALL_LO16
4962 || r_type
== R_MIPS_GOT_HI16
4963 || r_type
== R_MIPS_GOT_LO16
))
4965 /* We need the .got section. */
4968 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4969 BFD_ASSERT (sgot
!= NULL
);
4970 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4971 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4972 BFD_ASSERT (g
!= NULL
);
4976 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4978 /* Mix in the change in GP address for a GP relative reloc. */
4979 if (r_type
!= R_MIPS_GPREL16
4980 && r_type
!= R_MIPS_LITERAL
4981 && r_type
!= R_MIPS_GPREL32
4982 && r_type
!= R_MIPS16_GPREL
)
4988 if (! ((*info
->callbacks
->reloc_dangerous
)
4990 _("GP relative relocation when GP not defined"),
4991 input_bfd
, input_section
,
4994 /* Only give the error once per link. */
4996 _bfd_set_gp_value (output_bfd
, gp
);
4999 if (r_symndx
< extsymoff
5000 || (elf_bad_symtab (input_bfd
)
5001 && local_sections
[r_symndx
] != NULL
))
5003 /* This is a relocation against a section. The current
5004 addend in the instruction is the difference between
5005 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
5006 must change this to be the difference between the
5007 final definition (which will end up in RELOCATION)
5008 and the GP value of OUTPUT_BFD (which is in GP). */
5009 addend
= elf_gp (input_bfd
) - gp
;
5011 else if (! info
->relocateable
)
5013 /* We are doing a final link. The current addend in the
5014 instruction is simply the desired offset into the
5015 symbol (normally zero). We want the instruction to
5016 hold the difference between the final definition of
5017 the symbol (which will end up in RELOCATION) and the
5018 GP value of OUTPUT_BFD (which is in GP). */
5023 /* We are generating relocateable output, and we aren't
5024 going to define this symbol, so we just leave the
5025 instruction alone. */
5033 if (info
->relocateable
)
5035 /* This is a relocateable link. We don't have to change
5036 anything, unless the reloc is against a section symbol,
5037 in which case we have to adjust according to where the
5038 section symbol winds up in the output section. */
5039 if (r_symndx
>= locsymcount
5040 || (elf_bad_symtab (input_bfd
)
5041 && local_sections
[r_symndx
] == NULL
))
5045 sym
= local_syms
+ r_symndx
;
5046 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5050 sec
= local_sections
[r_symndx
];
5052 /* It would be logical to add sym->st_value here,
5053 but Irix 5 sometimes generates a garbage symbol
5055 addend
+= sec
->output_offset
;
5057 /* If this is HI16 or GOT16 with an associated LO16,
5058 adjust the addend accordingly. Otherwise, just
5060 if (r_type
== R_MIPS_64
&& bfd_big_endian (input_bfd
))
5061 r
= _bfd_relocate_contents (howto
, input_bfd
,
5063 contents
+ rel
->r_offset
+ 4);
5064 else if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
5065 r
= _bfd_relocate_contents (howto
, input_bfd
,
5067 contents
+ rel
->r_offset
);
5070 Elf_Internal_Rela
*lorel
;
5072 /* As a GNU extension, permit an arbitrary
5073 number of R_MIPS_HI16 relocs before the
5074 R_MIPS_LO16 reloc. This permits gcc to emit
5075 the HI and LO relocs itself. */
5076 if (r_type
== R_MIPS_GOT16
)
5080 for (lorel
= rel
+ 1;
5082 && (ELF32_R_TYPE (lorel
->r_info
)
5088 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5090 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5095 r
= _bfd_relocate_contents (howto
, input_bfd
,
5097 contents
+ rel
->r_offset
);
5106 boolean undefined_error
;
5108 /* This is a final link. */
5109 undefined_error
= false;
5111 if (r_symndx
< extsymoff
5112 || (elf_bad_symtab (input_bfd
)
5113 && local_sections
[r_symndx
] != NULL
))
5116 sym
= local_syms
+ r_symndx
;
5117 sec
= local_sections
[r_symndx
];
5118 relocation
= (sec
->output_section
->vma
5119 + sec
->output_offset
);
5121 /* It would be logical to always add sym->st_value here,
5122 but Irix 5 sometimes generates a garbage symbol
5124 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5125 relocation
+= sym
->st_value
;
5127 /* mips16 text labels should be treated as odd. */
5128 if (sym
->st_other
== STO_MIPS16
)
5136 indx
= r_symndx
- extsymoff
;
5137 h
= elf_sym_hashes (input_bfd
)[indx
];
5138 while (h
->root
.type
== bfd_link_hash_indirect
5139 || h
->root
.type
== bfd_link_hash_warning
)
5140 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5141 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
5145 if (! ((*info
->callbacks
->reloc_dangerous
)
5147 _("_gp_disp used when GP not defined"),
5148 input_bfd
, input_section
,
5151 /* Only give the error once per link. */
5153 _bfd_set_gp_value (output_bfd
, gp
);
5158 sec
= input_section
;
5159 if (sec
->output_section
!= NULL
)
5162 + sec
->output_section
->vma
5163 + sec
->output_offset
));
5165 relocation
= gp
- rel
->r_offset
;
5166 if (r_type
== R_MIPS_LO16
)
5170 else if (h
->root
.type
== bfd_link_hash_defined
5171 || h
->root
.type
== bfd_link_hash_defweak
)
5173 sec
= h
->root
.u
.def
.section
;
5174 if (sec
->output_section
== NULL
)
5177 relocation
= (h
->root
.u
.def
.value
5178 + sec
->output_section
->vma
5179 + sec
->output_offset
);
5181 else if (h
->root
.type
== bfd_link_hash_undefweak
)
5183 else if (info
->shared
&& !info
->symbolic
&& !info
->no_undefined
)
5185 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
5187 /* If this is a dynamic link, we should have created
5188 a _DYNAMIC_LINK symbol in
5189 mips_elf_create_dynamic_sections. Otherwise, we
5190 should define the symbol with a value of 0.
5191 FIXME: It should probably get into the symbol
5192 table somehow as well. */
5193 BFD_ASSERT (! info
->shared
);
5194 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
5195 ".dynamic") == NULL
);
5200 if (! ((*info
->callbacks
->undefined_symbol
)
5201 (info
, h
->root
.root
.string
, input_bfd
,
5202 input_section
, rel
->r_offset
)))
5204 undefined_error
= true;
5209 mh
= (struct mips_elf_link_hash_entry
*) h
;
5212 else if (sym
!= NULL
)
5213 other
= sym
->st_other
;
5217 /* If this function has an fn_stub, then it is a mips16
5218 function which needs a stub if it is called by a 32 bit
5219 function. If this reloc is anything other than a 16 bit
5220 call, redirect the reloc to the stub. We don't redirect
5221 relocs from other stub functions. */
5222 if (r_type
!= R_MIPS16_26
5224 && mh
->fn_stub
!= NULL
)
5226 && elf_tdata (input_bfd
)->local_stubs
!= NULL
5227 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
5228 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5229 FN_STUB
, sizeof FN_STUB
- 1) != 0
5230 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5231 CALL_STUB
, sizeof CALL_STUB
- 1) != 0
5232 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5233 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) != 0)
5237 BFD_ASSERT (mh
->need_fn_stub
);
5238 relocation
= (mh
->fn_stub
->output_section
->vma
5239 + mh
->fn_stub
->output_offset
);
5245 fn_stub
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
5246 relocation
= (fn_stub
->output_section
->vma
5247 + fn_stub
->output_offset
);
5250 /* RELOCATION now points to 32 bit code. */
5254 /* If this function has a call_stub, then it is called by a
5255 mips16 function; the call needs to go through a stub if
5256 this function is a 32 bit function. If this reloc is a
5257 16 bit call, and the symbol is not a 16 bit function,
5258 then redirect the reloc to the stub. Note that we don't
5259 need to worry about calling the function through a
5260 function pointer; such calls are handled by routing
5261 through a special mips16 routine. We don't have to check
5262 whether this call is from a stub; it can't be, because a
5263 stub contains 32 bit code, and hence can not have a 16
5265 if (r_type
== R_MIPS16_26
5267 && (mh
->call_stub
!= NULL
|| mh
->call_fp_stub
!= NULL
)
5268 && other
!= STO_MIPS16
)
5272 /* If both call_stub and call_fp_stub are defined, we
5273 can figure out which one to use by seeing which one
5274 appears in the input file. */
5275 if (mh
->call_stub
!= NULL
&& mh
->call_fp_stub
!= NULL
)
5280 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
5282 if (strncmp (bfd_get_section_name (input_bfd
, o
),
5283 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5285 stub
= mh
->call_fp_stub
;
5290 stub
= mh
->call_stub
;
5292 else if (mh
->call_stub
!= NULL
)
5293 stub
= mh
->call_stub
;
5295 stub
= mh
->call_fp_stub
;
5297 BFD_ASSERT (stub
->_raw_size
> 0);
5298 relocation
= stub
->output_section
->vma
+ stub
->output_offset
;
5301 if (r_type
== R_MIPS_HI16
)
5303 Elf_Internal_Rela
*lorel
;
5305 /* As a GNU extension, permit an arbitrary number of
5306 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
5307 This permits gcc to emit the HI and LO relocs itself. */
5308 for (lorel
= rel
+ 1;
5310 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
5314 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5316 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5317 contents
, relocation
+ addend
);
5321 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5322 contents
, rel
->r_offset
,
5323 relocation
, addend
);
5325 else if (r_type
== R_MIPS_GOT16
&& local
)
5327 /* GOT16 must also have an associated LO16 in the local
5328 case. In this case, the addend is extracted and the
5329 section in which the referenced object is determined.
5330 Then the final address of the object is computed and
5331 the GOT entry for the hipage (an aligned 64kb chunk)
5332 is added to .got section if needed. The offset field
5333 of the GOT16-relocated instruction is replaced by the
5334 index of this GOT entry for the hipage. */
5335 if ((rel
+ 1) < relend
5336 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
5338 if (! mips_elf_relocate_got_local (output_bfd
, input_bfd
,
5341 relocation
+ addend
))
5346 r
= bfd_reloc_outofrange
;
5348 else if (r_type
== R_MIPS_CALL16
5349 || r_type
== R_MIPS_GOT16
5350 || r_type
== R_MIPS_CALL_LO16
5351 || r_type
== R_MIPS_GOT_LO16
)
5355 /* This symbol must be registered as a global symbol
5356 having the corresponding got entry. */
5357 BFD_ASSERT (h
->got
.offset
!= (bfd_vma
) -1);
5359 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5360 BFD_ASSERT (g
->local_gotno
<= offset
5361 && offset
< sgot
->_raw_size
);
5362 bfd_put_32 (output_bfd
, relocation
+ addend
,
5363 sgot
->contents
+ offset
);
5364 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5366 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
5370 else if (r_type
== R_MIPS_CALL_HI16
5371 || r_type
== R_MIPS_GOT_HI16
)
5375 /* This must be a global symbol with a got entry. The
5376 next reloc must be the corresponding LO16 reloc. */
5377 BFD_ASSERT (h
!= NULL
&& h
->got
.offset
!= (bfd_vma
) -1);
5378 BFD_ASSERT ((rel
+ 1) < relend
);
5379 BFD_ASSERT ((int) ELF32_R_TYPE ((rel
+ 1)->r_info
)
5380 == (r_type
== R_MIPS_CALL_HI16
5381 ? (int) R_MIPS_CALL_LO16
5382 : (int) R_MIPS_GOT_LO16
));
5384 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5385 BFD_ASSERT (g
->local_gotno
<= offset
5386 && offset
< sgot
->_raw_size
);
5387 bfd_put_32 (output_bfd
, relocation
+ addend
,
5388 sgot
->contents
+ offset
);
5389 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5391 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
5395 else if (r_type
== R_MIPS_REL32
5396 || r_type
== R_MIPS_32
)
5398 Elf_Internal_Rel outrel
;
5399 Elf32_crinfo cptrel
;
5403 || (elf_hash_table (info
)->dynamic_sections_created
5405 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
5407 && (input_section
->flags
& SEC_ALLOC
) != 0)
5411 /* When generating a shared object, these
5412 relocations are copied into the output file to be
5413 resolved at run time. */
5416 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5417 BFD_ASSERT (sreloc
!= NULL
);
5422 if (elf_section_data (input_section
)->stab_info
== NULL
)
5423 outrel
.r_offset
= rel
->r_offset
;
5428 off
= (_bfd_stab_section_offset
5429 (output_bfd
, &elf_hash_table (info
)->stab_info
,
5431 &elf_section_data (input_section
)->stab_info
,
5433 if (off
== (bfd_vma
) -1)
5435 outrel
.r_offset
= off
;
5438 outrel
.r_offset
+= (input_section
->output_section
->vma
5439 + input_section
->output_offset
);
5441 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5444 memset (&outrel
, 0, sizeof outrel
);
5446 && (! info
->symbolic
5447 || (h
->elf_link_hash_flags
5448 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5450 BFD_ASSERT (h
->dynindx
!= -1);
5451 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
5452 sec
= input_section
;
5459 sec
= local_sections
[r_symndx
];
5462 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
5464 == bfd_link_hash_defweak
));
5465 sec
= h
->root
.u
.def
.section
;
5467 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5469 else if (sec
== NULL
|| sec
->owner
== NULL
)
5471 bfd_set_error (bfd_error_bad_value
);
5478 osec
= sec
->output_section
;
5479 indx
= elf_section_data (osec
)->dynindx
;
5484 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
5485 addend
+= relocation
;
5489 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
5491 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
5492 (((Elf32_External_Rel
*)
5494 + sreloc
->reloc_count
));
5495 ++sreloc
->reloc_count
;
5497 if (! skip
&& SGI_COMPAT (output_bfd
))
5502 /* Make an entry of compact relocation info. */
5503 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5504 cptrel
.vaddr
= (rel
->r_offset
5505 + input_section
->output_section
->vma
5506 + input_section
->output_offset
);
5507 if (r_type
== R_MIPS_REL32
)
5508 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5510 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5511 mips_elf_set_cr_dist2to (cptrel
, 0);
5512 cptrel
.konst
= addend
;
5514 cr
= (scpt
->contents
5515 + sizeof (Elf32_External_compact_rel
));
5516 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5517 ((Elf32_External_crinfo
*) cr
5518 + scpt
->reloc_count
));
5519 ++scpt
->reloc_count
;
5522 /* This reloc will be computed at runtime, so
5523 there's no need to do anything now. */
5527 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5528 contents
, rel
->r_offset
,
5529 relocation
, addend
);
5531 else if (r_type
== R_MIPS_64
)
5536 /* Do a 32 bit relocation, and sign extend to 64 bits. */
5537 addr
= rel
->r_offset
;
5538 if (bfd_big_endian (input_bfd
))
5540 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5541 contents
, addr
, relocation
,
5543 val
= bfd_get_32 (input_bfd
, contents
+ addr
);
5544 if ((val
& 0x80000000) != 0)
5548 addr
= rel
->r_offset
;
5549 if (bfd_little_endian (input_bfd
))
5551 bfd_put_32 (input_bfd
, val
, contents
+ addr
);
5553 else if (r_type
== R_MIPS_26
&& other
== STO_MIPS16
)
5557 /* This is a jump to a mips16 routine from a mips32
5558 routine. We need to change jal into jalx. */
5559 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5560 if (((insn
>> 26) & 0x3f) != 0x3
5561 && ((insn
>> 26) & 0x3f) != 0x1d)
5563 (*_bfd_error_handler
)
5564 (_("%s: %s+0x%lx: jump to mips16 routine which is not jal"),
5565 bfd_get_filename (input_bfd
),
5566 input_section
->name
,
5567 (unsigned long) rel
->r_offset
);
5568 bfd_set_error (bfd_error_bad_value
);
5571 insn
= (insn
& 0x3ffffff) | (0x1d << 26);
5572 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5573 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5574 contents
, rel
->r_offset
,
5575 relocation
, addend
);
5577 else if (r_type
== R_MIPS16_26
)
5579 /* It's easiest to do the normal relocation, and then
5580 dig out the instruction and swap the first word the
5581 way the mips16 expects it. If this is little endian,
5582 though, we need to swap the two words first, and then
5583 swap them back again later, so that the address looks
5586 if (bfd_little_endian (input_bfd
))
5590 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5591 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5592 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5595 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5596 contents
, rel
->r_offset
,
5597 relocation
, addend
);
5598 if (r
== bfd_reloc_ok
)
5602 if (bfd_little_endian (input_bfd
))
5604 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5605 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5606 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5609 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5610 insn
= ((insn
& 0xfc00)
5611 | ((insn
& 0x1f) << 5)
5612 | ((insn
& 0x3e0) >> 5));
5613 /* If this is a jump to a 32 bit routine, then make
5615 if (other
!= STO_MIPS16
)
5617 bfd_put_16 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5620 else if (r_type
== R_MIPS16_GPREL
)
5622 unsigned short extend
, insn
;
5624 unsigned long final
;
5626 /* Extract the addend into buf, run the regular reloc,
5627 and stuff the resulting value back into the
5629 if (rel
->r_offset
> input_section
->_raw_size
)
5630 r
= bfd_reloc_outofrange
;
5633 extend
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5634 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 2);
5635 bfd_put_32 (input_bfd
,
5636 (((extend
& 0x1f) << 11)
5640 r
= _bfd_final_link_relocate (howto
, input_bfd
,
5642 (bfd_vma
) 0, relocation
,
5644 final
= bfd_get_32 (input_bfd
, buf
);
5645 bfd_put_16 (input_bfd
,
5647 | ((final
>> 11) & 0x1f)
5649 contents
+ rel
->r_offset
);
5650 bfd_put_16 (input_bfd
,
5653 contents
+ rel
->r_offset
+ 2);
5657 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5658 contents
, rel
->r_offset
,
5659 relocation
, addend
);
5661 /* The jal instruction can only jump to an address which is
5662 divisible by 4, and it can only jump to an address with
5663 the same upper 4 bits as the PC. */
5664 if (r
== bfd_reloc_ok
5665 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
))
5671 pc
= ((input_section
->output_section
->vma
5672 + input_section
->output_offset
5675 target
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
)
5676 & (howto
->dst_mask
);
5677 addr
= (target
<< 2) + pc
;
5678 if (other
== STO_MIPS16
)
5679 addr
&= ~ (bfd_vma
) 1;
5681 || ((addr
& 0xf0000000)
5683 r
= bfd_reloc_overflow
;
5686 /* Don't bother to report a relocation overflow for a call
5687 to a weak undefined symbol with a value of zero. This
5690 even if we aren't in range to call address zero. */
5691 if (r
== bfd_reloc_overflow
5692 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
)
5693 && relocation
+ addend
== 0
5695 && h
->root
.type
== bfd_link_hash_undefweak
)
5698 /* If we've already issued an error for an undefined symbol,
5699 don't issue another useless error. */
5701 && (r
== bfd_reloc_undefined
|| r
== bfd_reloc_overflow
))
5704 if (SGI_COMPAT (output_bfd
)
5706 && (input_section
->flags
& SEC_ALLOC
) != 0)
5708 Elf32_crinfo cptrel
;
5711 /* Make an entry of compact relocation info. */
5712 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5713 cptrel
.vaddr
= (rel
->r_offset
5714 + input_section
->output_section
->vma
5715 + input_section
->output_offset
);
5720 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
5721 /* XXX How should we set dist2to in this case. */
5722 mips_elf_set_cr_dist2to (cptrel
, 8);
5723 cptrel
.konst
= addend
+ relocation
;
5724 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5725 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5726 ((Elf32_External_crinfo
*) cr
5727 + scpt
->reloc_count
));
5728 ++scpt
->reloc_count
;
5731 case R_MIPS_GPREL16
:
5732 case R_MIPS_LITERAL
:
5733 case R_MIPS_GPREL32
:
5734 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
5735 cptrel
.konst
= gp
- cptrel
.vaddr
;
5736 mips_elf_set_cr_dist2to (cptrel
, 4);
5737 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5738 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5739 ((Elf32_External_crinfo
*) cr
5740 + scpt
->reloc_count
));
5741 ++scpt
->reloc_count
;
5750 if (r
!= bfd_reloc_ok
)
5755 case bfd_reloc_outofrange
:
5757 case bfd_reloc_overflow
:
5762 name
= h
->root
.root
.string
;
5765 name
= bfd_elf_string_from_elf_section (input_bfd
,
5766 symtab_hdr
->sh_link
,
5771 name
= bfd_section_name (input_bfd
, sec
);
5773 if (! ((*info
->callbacks
->reloc_overflow
)
5774 (info
, name
, howto
->name
, (bfd_vma
) 0,
5775 input_bfd
, input_section
, rel
->r_offset
)))
5786 /* This hook function is called before the linker writes out a global
5787 symbol. We mark symbols as small common if appropriate. This is
5788 also where we undo the increment of the value for a mips16 symbol. */
5792 mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
5794 struct bfd_link_info
*info
;
5796 Elf_Internal_Sym
*sym
;
5797 asection
*input_sec
;
5799 /* If we see a common symbol, which implies a relocatable link, then
5800 if a symbol was small common in an input file, mark it as small
5801 common in the output file. */
5802 if (sym
->st_shndx
== SHN_COMMON
5803 && strcmp (input_sec
->name
, ".scommon") == 0)
5804 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
5806 if (sym
->st_other
== STO_MIPS16
5807 && (sym
->st_value
& 1) != 0)
5813 /* Functions for the dynamic linker. */
5815 /* The name of the dynamic interpreter. This is put in the .interp
5818 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
5820 /* Create dynamic sections when linking against a dynamic object. */
5823 mips_elf_create_dynamic_sections (abfd
, info
)
5825 struct bfd_link_info
*info
;
5827 struct elf_link_hash_entry
*h
;
5829 register asection
*s
;
5830 const char * const *namep
;
5832 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5833 | SEC_LINKER_CREATED
| SEC_READONLY
);
5835 /* Mips ABI requests the .dynamic section to be read only. */
5836 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5839 if (! bfd_set_section_flags (abfd
, s
, flags
))
5843 /* We need to create .got section. */
5844 if (! mips_elf_create_got_section (abfd
, info
))
5847 /* Create the .msym section on IRIX6. It is used by the dynamic
5848 linker to speed up dynamic relocations, and to avoid computing
5849 the ELF hash for symbols. */
5850 if (IRIX_COMPAT (abfd
) == ict_irix6
5851 && !mips_elf_create_msym_section (abfd
))
5854 /* Create .stub section. */
5855 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
5857 s
= bfd_make_section (abfd
, ".stub");
5859 || ! bfd_set_section_flags (abfd
, s
, flags
)
5860 || ! bfd_set_section_alignment (abfd
, s
, 2))
5864 if (SGI_COMPAT (abfd
)
5866 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
5868 s
= bfd_make_section (abfd
, ".rld_map");
5870 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
5871 || ! bfd_set_section_alignment (abfd
, s
, 2))
5875 if (SGI_COMPAT (abfd
))
5877 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
5880 if (! (_bfd_generic_link_add_one_symbol
5881 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
5882 (bfd_vma
) 0, (const char *) NULL
, false,
5883 get_elf_backend_data (abfd
)->collect
,
5884 (struct bfd_link_hash_entry
**) &h
)))
5886 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5887 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5888 h
->type
= STT_SECTION
;
5890 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5894 /* We need to create a .compact_rel section. */
5895 if (! mips_elf_create_compact_rel_section (abfd
, info
))
5898 /* Change aligments of some sections. */
5899 s
= bfd_get_section_by_name (abfd
, ".hash");
5901 bfd_set_section_alignment (abfd
, s
, 4);
5902 s
= bfd_get_section_by_name (abfd
, ".dynsym");
5904 bfd_set_section_alignment (abfd
, s
, 4);
5905 s
= bfd_get_section_by_name (abfd
, ".dynstr");
5907 bfd_set_section_alignment (abfd
, s
, 4);
5908 s
= bfd_get_section_by_name (abfd
, ".reginfo");
5910 bfd_set_section_alignment (abfd
, s
, 4);
5911 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5913 bfd_set_section_alignment (abfd
, s
, 4);
5919 if (! (_bfd_generic_link_add_one_symbol
5920 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
5921 (bfd_vma
) 0, (const char *) NULL
, false,
5922 get_elf_backend_data (abfd
)->collect
,
5923 (struct bfd_link_hash_entry
**) &h
)))
5925 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5926 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5927 h
->type
= STT_SECTION
;
5929 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5932 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
5934 /* __rld_map is a four byte word located in the .data section
5935 and is filled in by the rtld to contain a pointer to
5936 the _r_debug structure. Its symbol value will be set in
5937 mips_elf_finish_dynamic_symbol. */
5938 s
= bfd_get_section_by_name (abfd
, ".rld_map");
5939 BFD_ASSERT (s
!= NULL
);
5942 if (! (_bfd_generic_link_add_one_symbol
5943 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
5944 (bfd_vma
) 0, (const char *) NULL
, false,
5945 get_elf_backend_data (abfd
)->collect
,
5946 (struct bfd_link_hash_entry
**) &h
)))
5948 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5949 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5950 h
->type
= STT_OBJECT
;
5952 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5960 /* Create the .compact_rel section. */
5963 mips_elf_create_compact_rel_section (abfd
, info
)
5965 struct bfd_link_info
*info
;
5968 register asection
*s
;
5970 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
5972 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
5975 s
= bfd_make_section (abfd
, ".compact_rel");
5977 || ! bfd_set_section_flags (abfd
, s
, flags
)
5978 || ! bfd_set_section_alignment (abfd
, s
, 2))
5981 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
5987 /* Create the .got section to hold the global offset table. */
5990 mips_elf_create_got_section (abfd
, info
)
5992 struct bfd_link_info
*info
;
5995 register asection
*s
;
5996 struct elf_link_hash_entry
*h
;
5997 struct mips_got_info
*g
;
5999 /* This function may be called more than once. */
6000 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
6003 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6004 | SEC_LINKER_CREATED
);
6006 s
= bfd_make_section (abfd
, ".got");
6008 || ! bfd_set_section_flags (abfd
, s
, flags
)
6009 || ! bfd_set_section_alignment (abfd
, s
, 4))
6012 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
6013 linker script because we don't want to define the symbol if we
6014 are not creating a global offset table. */
6016 if (! (_bfd_generic_link_add_one_symbol
6017 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
6018 (bfd_vma
) 0, (const char *) NULL
, false,
6019 get_elf_backend_data (abfd
)->collect
,
6020 (struct bfd_link_hash_entry
**) &h
)))
6022 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6023 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6024 h
->type
= STT_OBJECT
;
6027 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6030 /* The first several global offset table entries are reserved. */
6031 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
6033 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
6034 sizeof (struct mips_got_info
));
6037 g
->global_gotsym
= 0;
6038 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
6039 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
6040 if (elf_section_data (s
) == NULL
)
6043 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
6044 if (elf_section_data (s
) == NULL
)
6047 elf_section_data (s
)->tdata
= (PTR
) g
;
6052 /* Returns the .msym section for ABFD, creating it if it does not
6053 already exist. Returns NULL to indicate error. */
6056 mips_elf_create_msym_section (abfd
)
6061 s
= bfd_get_section_by_name (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
6064 s
= bfd_make_section (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
6066 || !bfd_set_section_flags (abfd
, s
,
6070 | SEC_LINKER_CREATED
6072 || !bfd_set_section_alignment (abfd
, s
, 2))
6079 /* Look through the relocs for a section during the first phase, and
6080 allocate space in the global offset table. */
6083 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
6085 struct bfd_link_info
*info
;
6087 const Elf_Internal_Rela
*relocs
;
6091 Elf_Internal_Shdr
*symtab_hdr
;
6092 struct elf_link_hash_entry
**sym_hashes
;
6093 struct mips_got_info
*g
;
6095 const Elf_Internal_Rela
*rel
;
6096 const Elf_Internal_Rela
*rel_end
;
6100 if (info
->relocateable
)
6103 dynobj
= elf_hash_table (info
)->dynobj
;
6104 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6105 sym_hashes
= elf_sym_hashes (abfd
);
6106 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
6108 /* Check for the mips16 stub sections. */
6110 name
= bfd_get_section_name (abfd
, sec
);
6111 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
6113 unsigned long r_symndx
;
6115 /* Look at the relocation information to figure out which symbol
6118 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6120 if (r_symndx
< extsymoff
6121 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6125 /* This stub is for a local symbol. This stub will only be
6126 needed if there is some relocation in this BFD, other
6127 than a 16 bit function call, which refers to this symbol. */
6128 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6130 Elf_Internal_Rela
*sec_relocs
;
6131 const Elf_Internal_Rela
*r
, *rend
;
6133 /* We can ignore stub sections when looking for relocs. */
6134 if ((o
->flags
& SEC_RELOC
) == 0
6135 || o
->reloc_count
== 0
6136 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
6137 sizeof FN_STUB
- 1) == 0
6138 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
6139 sizeof CALL_STUB
- 1) == 0
6140 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
6141 sizeof CALL_FP_STUB
- 1) == 0)
6144 sec_relocs
= (_bfd_elf32_link_read_relocs
6145 (abfd
, o
, (PTR
) NULL
,
6146 (Elf_Internal_Rela
*) NULL
,
6147 info
->keep_memory
));
6148 if (sec_relocs
== NULL
)
6151 rend
= sec_relocs
+ o
->reloc_count
;
6152 for (r
= sec_relocs
; r
< rend
; r
++)
6153 if (ELF32_R_SYM (r
->r_info
) == r_symndx
6154 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
6157 if (! info
->keep_memory
)
6166 /* There is no non-call reloc for this stub, so we do
6167 not need it. Since this function is called before
6168 the linker maps input sections to output sections, we
6169 can easily discard it by setting the SEC_EXCLUDE
6171 sec
->flags
|= SEC_EXCLUDE
;
6175 /* Record this stub in an array of local symbol stubs for
6177 if (elf_tdata (abfd
)->local_stubs
== NULL
)
6179 unsigned long symcount
;
6182 if (elf_bad_symtab (abfd
))
6183 symcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
6185 symcount
= symtab_hdr
->sh_info
;
6186 n
= (asection
**) bfd_zalloc (abfd
,
6187 symcount
* sizeof (asection
*));
6190 elf_tdata (abfd
)->local_stubs
= n
;
6193 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
6195 /* We don't need to set mips16_stubs_seen in this case.
6196 That flag is used to see whether we need to look through
6197 the global symbol table for stubs. We don't need to set
6198 it here, because we just have a local stub. */
6202 struct mips_elf_link_hash_entry
*h
;
6204 h
= ((struct mips_elf_link_hash_entry
*)
6205 sym_hashes
[r_symndx
- extsymoff
]);
6207 /* H is the symbol this stub is for. */
6210 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6213 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
6214 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6216 unsigned long r_symndx
;
6217 struct mips_elf_link_hash_entry
*h
;
6220 /* Look at the relocation information to figure out which symbol
6223 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6225 if (r_symndx
< extsymoff
6226 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6228 /* This stub was actually built for a static symbol defined
6229 in the same file. We assume that all static symbols in
6230 mips16 code are themselves mips16, so we can simply
6231 discard this stub. Since this function is called before
6232 the linker maps input sections to output sections, we can
6233 easily discard it by setting the SEC_EXCLUDE flag. */
6234 sec
->flags
|= SEC_EXCLUDE
;
6238 h
= ((struct mips_elf_link_hash_entry
*)
6239 sym_hashes
[r_symndx
- extsymoff
]);
6241 /* H is the symbol this stub is for. */
6243 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6244 loc
= &h
->call_fp_stub
;
6246 loc
= &h
->call_stub
;
6248 /* If we already have an appropriate stub for this function, we
6249 don't need another one, so we can discard this one. Since
6250 this function is called before the linker maps input sections
6251 to output sections, we can easily discard it by setting the
6252 SEC_EXCLUDE flag. We can also discard this section if we
6253 happen to already know that this is a mips16 function; it is
6254 not necessary to check this here, as it is checked later, but
6255 it is slightly faster to check now. */
6256 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
6258 sec
->flags
|= SEC_EXCLUDE
;
6263 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6273 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6278 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6279 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6280 BFD_ASSERT (g
!= NULL
);
6286 rel_end
= relocs
+ sec
->reloc_count
;
6287 for (rel
= relocs
; rel
< rel_end
; rel
++)
6289 unsigned long r_symndx
;
6290 struct elf_link_hash_entry
*h
;
6292 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6294 if (r_symndx
< extsymoff
)
6298 h
= sym_hashes
[r_symndx
- extsymoff
];
6300 /* This may be an indirect symbol created because of a version. */
6303 while (h
->root
.type
== bfd_link_hash_indirect
)
6304 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6308 /* Some relocs require a global offset table. */
6309 if (dynobj
== NULL
|| sgot
== NULL
)
6311 switch (ELF32_R_TYPE (rel
->r_info
))
6315 case R_MIPS_CALL_HI16
:
6316 case R_MIPS_CALL_LO16
:
6317 case R_MIPS_GOT_HI16
:
6318 case R_MIPS_GOT_LO16
:
6320 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6321 if (! mips_elf_create_got_section (dynobj
, info
))
6323 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6324 BFD_ASSERT (sgot
!= NULL
);
6325 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6326 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6327 BFD_ASSERT (g
!= NULL
);
6333 && (info
->shared
|| h
!= NULL
)
6334 && (sec
->flags
& SEC_ALLOC
) != 0)
6335 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6343 switch (ELF32_R_TYPE (rel
->r_info
))
6346 case R_MIPS_CALL_HI16
:
6347 case R_MIPS_CALL_LO16
:
6348 /* This symbol requires a global offset table entry. */
6352 (*_bfd_error_handler
)
6353 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
6354 bfd_get_filename (abfd
), (unsigned long) rel
->r_offset
);
6355 bfd_set_error (bfd_error_bad_value
);
6359 /* Make sure this symbol is output as a dynamic symbol. */
6360 if (h
->dynindx
== -1)
6362 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6366 if (h
->got
.offset
!= (bfd_vma
) -1)
6368 /* We have already allocated space in the .got. */
6372 /* Note the index of the first global got symbol in .dynsym. */
6373 if (g
->global_gotsym
== 0
6374 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6375 g
->global_gotsym
= h
->dynindx
;
6377 /* Make this symbol to have the corresponding got entry. */
6380 /* We need a stub, not a plt entry for the undefined
6381 function. But we record it as if it needs plt. See
6382 elf_adjust_dynamic_symbol in elflink.h. */
6383 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6389 case R_MIPS_GOT_HI16
:
6390 case R_MIPS_GOT_LO16
:
6391 /* This symbol requires a global offset table entry. */
6395 /* Make sure this symbol is output as a dynamic symbol. */
6396 if (h
->dynindx
== -1)
6398 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6402 if (h
->got
.offset
!= (bfd_vma
) -1)
6404 /* We have already allocated space in the .got. */
6407 /* Note the index of the first global got symbol in
6409 if (g
->global_gotsym
== 0
6410 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6411 g
->global_gotsym
= h
->dynindx
;
6413 /* Make this symbol to be the global got symbol. */
6421 if ((info
->shared
|| h
!= NULL
)
6422 && (sec
->flags
& SEC_ALLOC
) != 0)
6426 const char *name
= ".rel.dyn";
6428 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6431 sreloc
= bfd_make_section (dynobj
, name
);
6433 || ! bfd_set_section_flags (dynobj
, sreloc
,
6438 | SEC_LINKER_CREATED
6440 || ! bfd_set_section_alignment (dynobj
, sreloc
,
6447 /* When creating a shared object, we must copy these
6448 reloc types into the output file as R_MIPS_REL32
6449 relocs. We make room for this reloc in the
6450 .rel.dyn reloc section */
6451 if (sreloc
->_raw_size
== 0)
6453 /* Add a null element. */
6454 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6455 ++sreloc
->reloc_count
;
6457 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6461 struct mips_elf_link_hash_entry
*hmips
;
6463 /* We only need to copy this reloc if the symbol is
6464 defined in a dynamic object. */
6465 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6466 ++hmips
->mips_32_relocs
;
6470 if (SGI_COMPAT (abfd
))
6471 mips_elf_hash_table (info
)->compact_rel_size
+=
6472 sizeof (Elf32_External_crinfo
);
6477 case R_MIPS_GPREL16
:
6478 case R_MIPS_LITERAL
:
6479 case R_MIPS_GPREL32
:
6480 if (SGI_COMPAT (abfd
))
6481 mips_elf_hash_table (info
)->compact_rel_size
+=
6482 sizeof (Elf32_External_crinfo
);
6485 /* This relocation describes the C++ object vtable hierarchy.
6486 Reconstruct it for later use during GC. */
6487 case R_MIPS_GNU_VTINHERIT
:
6488 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6492 /* This relocation describes which C++ vtable entries are actually
6493 used. Record for later use during GC. */
6494 case R_MIPS_GNU_VTENTRY
:
6495 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
6503 /* If this reloc is not a 16 bit call, and it has a global
6504 symbol, then we will need the fn_stub if there is one.
6505 References from a stub section do not count. */
6507 && ELF32_R_TYPE (rel
->r_info
) != R_MIPS16_26
6508 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
6509 sizeof FN_STUB
- 1) != 0
6510 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
6511 sizeof CALL_STUB
- 1) != 0
6512 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
6513 sizeof CALL_FP_STUB
- 1) != 0)
6515 struct mips_elf_link_hash_entry
*mh
;
6517 mh
= (struct mips_elf_link_hash_entry
*) h
;
6518 mh
->need_fn_stub
= true;
6525 /* Return the section that should be marked against GC for a given
6529 mips_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
6531 struct bfd_link_info
*info
;
6532 Elf_Internal_Rela
*rel
;
6533 struct elf_link_hash_entry
*h
;
6534 Elf_Internal_Sym
*sym
;
6536 /* ??? Do mips16 stub sections need to be handled special? */
6540 switch (ELF32_R_TYPE (rel
->r_info
))
6542 case R_MIPS_GNU_VTINHERIT
:
6543 case R_MIPS_GNU_VTENTRY
:
6547 switch (h
->root
.type
)
6549 case bfd_link_hash_defined
:
6550 case bfd_link_hash_defweak
:
6551 return h
->root
.u
.def
.section
;
6553 case bfd_link_hash_common
:
6554 return h
->root
.u
.c
.p
->section
;
6563 if (!(elf_bad_symtab (abfd
)
6564 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
6565 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
6566 && sym
->st_shndx
!= SHN_COMMON
))
6568 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
6575 /* Update the got entry reference counts for the section being removed. */
6578 mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
6580 struct bfd_link_info
*info
;
6582 const Elf_Internal_Rela
*relocs
;
6585 Elf_Internal_Shdr
*symtab_hdr
;
6586 struct elf_link_hash_entry
**sym_hashes
;
6587 bfd_signed_vma
*local_got_refcounts
;
6588 const Elf_Internal_Rela
*rel
, *relend
;
6589 unsigned long r_symndx
;
6590 struct elf_link_hash_entry
*h
;
6592 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6593 sym_hashes
= elf_sym_hashes (abfd
);
6594 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6596 relend
= relocs
+ sec
->reloc_count
;
6597 for (rel
= relocs
; rel
< relend
; rel
++)
6598 switch (ELF32_R_TYPE (rel
->r_info
))
6602 case R_MIPS_CALL_HI16
:
6603 case R_MIPS_CALL_LO16
:
6604 case R_MIPS_GOT_HI16
:
6605 case R_MIPS_GOT_LO16
:
6606 /* ??? It would seem that the existing MIPS code does no sort
6607 of reference counting or whatnot on its GOT and PLT entries,
6608 so it is not possible to garbage collect them at this time. */
6620 /* Adjust a symbol defined by a dynamic object and referenced by a
6621 regular object. The current definition is in some section of the
6622 dynamic object, but we're not including those sections. We have to
6623 change the definition to something the rest of the link can
6627 mips_elf_adjust_dynamic_symbol (info
, h
)
6628 struct bfd_link_info
*info
;
6629 struct elf_link_hash_entry
*h
;
6632 struct mips_elf_link_hash_entry
*hmips
;
6635 dynobj
= elf_hash_table (info
)->dynobj
;
6637 /* Make sure we know what is going on here. */
6638 BFD_ASSERT (dynobj
!= NULL
6639 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
6640 || h
->weakdef
!= NULL
6641 || ((h
->elf_link_hash_flags
6642 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
6643 && (h
->elf_link_hash_flags
6644 & ELF_LINK_HASH_REF_REGULAR
) != 0
6645 && (h
->elf_link_hash_flags
6646 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
6648 /* If this symbol is defined in a dynamic object, we need to copy
6649 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
6651 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6652 if (! info
->relocateable
6653 && hmips
->mips_32_relocs
!= 0
6654 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6656 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6657 BFD_ASSERT (s
!= NULL
);
6659 if (s
->_raw_size
== 0)
6661 /* Make room for a null element. */
6662 s
->_raw_size
+= sizeof (Elf32_External_Rel
);
6665 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
6668 /* For a function, create a stub, if needed. */
6669 if (h
->type
== STT_FUNC
6670 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
6672 if (! elf_hash_table (info
)->dynamic_sections_created
)
6675 /* If this symbol is not defined in a regular file, then set
6676 the symbol to the stub location. This is required to make
6677 function pointers compare as equal between the normal
6678 executable and the shared library. */
6679 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6681 /* We need .stub section. */
6682 s
= bfd_get_section_by_name (dynobj
, ".stub");
6683 BFD_ASSERT (s
!= NULL
);
6685 h
->root
.u
.def
.section
= s
;
6686 h
->root
.u
.def
.value
= s
->_raw_size
;
6688 /* XXX Write this stub address somewhere. */
6689 h
->plt
.offset
= s
->_raw_size
;
6691 /* Make room for this stub code. */
6692 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6694 /* The last half word of the stub will be filled with the index
6695 of this symbol in .dynsym section. */
6700 /* If this is a weak symbol, and there is a real definition, the
6701 processor independent code will have arranged for us to see the
6702 real definition first, and we can just use the same value. */
6703 if (h
->weakdef
!= NULL
)
6705 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
6706 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
6707 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
6708 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
6712 /* This is a reference to a symbol defined by a dynamic object which
6713 is not a function. */
6718 /* This function is called after all the input files have been read,
6719 and the input sections have been assigned to output sections. We
6720 check for any mips16 stub sections that we can discard. */
6722 static boolean mips_elf_check_mips16_stubs
6723 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
6726 mips_elf_always_size_sections (output_bfd
, info
)
6728 struct bfd_link_info
*info
;
6732 /* The .reginfo section has a fixed size. */
6733 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
6735 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
6737 if (info
->relocateable
6738 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
6741 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
6742 mips_elf_check_mips16_stubs
,
6748 /* Check the mips16 stubs for a particular symbol, and see if we can
6753 mips_elf_check_mips16_stubs (h
, data
)
6754 struct mips_elf_link_hash_entry
*h
;
6757 if (h
->fn_stub
!= NULL
6758 && ! h
->need_fn_stub
)
6760 /* We don't need the fn_stub; the only references to this symbol
6761 are 16 bit calls. Clobber the size to 0 to prevent it from
6762 being included in the link. */
6763 h
->fn_stub
->_raw_size
= 0;
6764 h
->fn_stub
->_cooked_size
= 0;
6765 h
->fn_stub
->flags
&= ~ SEC_RELOC
;
6766 h
->fn_stub
->reloc_count
= 0;
6767 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
6770 if (h
->call_stub
!= NULL
6771 && h
->root
.other
== STO_MIPS16
)
6773 /* We don't need the call_stub; this is a 16 bit function, so
6774 calls from other 16 bit functions are OK. Clobber the size
6775 to 0 to prevent it from being included in the link. */
6776 h
->call_stub
->_raw_size
= 0;
6777 h
->call_stub
->_cooked_size
= 0;
6778 h
->call_stub
->flags
&= ~ SEC_RELOC
;
6779 h
->call_stub
->reloc_count
= 0;
6780 h
->call_stub
->flags
|= SEC_EXCLUDE
;
6783 if (h
->call_fp_stub
!= NULL
6784 && h
->root
.other
== STO_MIPS16
)
6786 /* We don't need the call_stub; this is a 16 bit function, so
6787 calls from other 16 bit functions are OK. Clobber the size
6788 to 0 to prevent it from being included in the link. */
6789 h
->call_fp_stub
->_raw_size
= 0;
6790 h
->call_fp_stub
->_cooked_size
= 0;
6791 h
->call_fp_stub
->flags
&= ~ SEC_RELOC
;
6792 h
->call_fp_stub
->reloc_count
= 0;
6793 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
6799 /* Set the sizes of the dynamic sections. */
6802 mips_elf_size_dynamic_sections (output_bfd
, info
)
6804 struct bfd_link_info
*info
;
6810 struct mips_got_info
*g
;
6812 dynobj
= elf_hash_table (info
)->dynobj
;
6813 BFD_ASSERT (dynobj
!= NULL
);
6815 if (elf_hash_table (info
)->dynamic_sections_created
)
6817 /* Set the contents of the .interp section to the interpreter. */
6820 s
= bfd_get_section_by_name (dynobj
, ".interp");
6821 BFD_ASSERT (s
!= NULL
);
6822 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
6823 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
6827 /* Recompute the size of .got for local entires (reserved and
6828 hipages) if needed. To estimate it, get the upper bound of total
6829 size of loadable sections. */
6830 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6834 bfd_size_type loadable_size
= 0;
6835 bfd_size_type local_gotno
;
6838 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6839 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6840 BFD_ASSERT (g
!= NULL
);
6842 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
6843 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
6845 if ((s
->flags
& SEC_ALLOC
) == 0)
6847 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
6850 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
6852 /* Assume there are two loadable segments consisting of
6853 contiguous sections. Is 5 enough? */
6854 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
6855 g
->local_gotno
= local_gotno
;
6856 sgot
->_raw_size
+= local_gotno
* 4;
6859 /* The check_relocs and adjust_dynamic_symbol entry points have
6860 determined the sizes of the various dynamic sections. Allocate
6863 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
6868 /* It's OK to base decisions on the section name, because none
6869 of the dynobj section names depend upon the input files. */
6870 name
= bfd_get_section_name (dynobj
, s
);
6872 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
6877 if (strncmp (name
, ".rel", 4) == 0)
6879 if (s
->_raw_size
== 0)
6881 /* We only strip the section if the output section name
6882 has the same name. Otherwise, there might be several
6883 input sections for this output section. FIXME: This
6884 code is probably not needed these days anyhow, since
6885 the linker now does not create empty output sections. */
6886 if (s
->output_section
!= NULL
6888 bfd_get_section_name (s
->output_section
->owner
,
6889 s
->output_section
)) == 0)
6894 const char *outname
;
6897 /* If this relocation section applies to a read only
6898 section, then we probably need a DT_TEXTREL entry.
6899 If the relocation section is .rel.dyn, we always
6900 assert a DT_TEXTREL entry rather than testing whether
6901 there exists a relocation to a read only section or
6903 outname
= bfd_get_section_name (output_bfd
,
6905 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
6907 && (target
->flags
& SEC_READONLY
) != 0
6908 && (target
->flags
& SEC_ALLOC
) != 0)
6909 || strcmp (outname
, ".rel.dyn") == 0)
6912 /* We use the reloc_count field as a counter if we need
6913 to copy relocs into the output file. */
6914 if (strcmp (name
, ".rel.dyn") != 0)
6918 else if (strncmp (name
, ".got", 4) == 0)
6922 BFD_ASSERT (elf_section_data (s
) != NULL
);
6923 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
6924 BFD_ASSERT (g
!= NULL
);
6926 /* Fix the size of .got section for the correspondence of
6927 global symbols and got entries. This adds some useless
6928 got entries. Is this required by ABI really? */
6929 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
6930 s
->_raw_size
+= i
* 4;
6932 else if (strncmp (name
, ".stub", 5) == 0)
6934 /* Irix rld assumes that the function stub isn't at the end
6935 of .text section. So put a dummy. XXX */
6936 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6938 else if (! info
->shared
6939 && ! mips_elf_hash_table (info
)->use_rld_obj_head
6940 && strncmp (name
, ".rld_map", 8) == 0)
6942 /* We add a room for __rld_map. It will be filled in by the
6943 rtld to contain a pointer to the _r_debug structure. */
6946 else if (SGI_COMPAT (output_bfd
)
6947 && strncmp (name
, ".compact_rel", 12) == 0)
6948 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
6949 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
))
6951 s
->_raw_size
= (sizeof (Elf32_External_Msym
)
6952 * (elf_hash_table (info
)->dynsymcount
6953 + bfd_count_sections (output_bfd
)));
6954 else if (strncmp (name
, ".init", 5) != 0)
6956 /* It's not one of our sections, so don't allocate space. */
6962 _bfd_strip_section_from_output (s
);
6966 /* Allocate memory for the section contents. */
6967 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
6968 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
6970 bfd_set_error (bfd_error_no_memory
);
6973 memset (s
->contents
, 0, s
->_raw_size
);
6976 if (elf_hash_table (info
)->dynamic_sections_created
)
6978 /* Add some entries to the .dynamic section. We fill in the
6979 values later, in elf_mips_finish_dynamic_sections, but we
6980 must add the entries now so that we get the correct size for
6981 the .dynamic section. The DT_DEBUG entry is filled in by the
6982 dynamic linker and used by the debugger. */
6985 if (SGI_COMPAT (output_bfd
))
6987 /* SGI object has the equivalence of DT_DEBUG in the
6988 DT_MIPS_RLD_MAP entry. */
6989 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
6993 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
6999 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
7003 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
7006 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
7008 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
7011 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
7014 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
7018 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
7021 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
7024 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
7026 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
7029 s
= bfd_get_section_by_name (dynobj
, ".liblist");
7030 BFD_ASSERT (s
!= NULL
);
7032 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
7036 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
7039 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
7043 /* Time stamps in executable files are a bad idea. */
7044 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
7049 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
7054 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
7058 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
7061 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
7064 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
7067 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
7070 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
7073 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
7076 #if 0 /* (SGI_COMPAT) */
7077 if (! bfd_get_section_by_name (dynobj
, ".init"))
7078 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
7081 if (! bfd_get_section_by_name (dynobj
, ".fini"))
7082 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
7086 if (bfd_get_section_by_name (dynobj
,
7087 MIPS_ELF_MSYM_SECTION_NAME (dynobj
))
7088 && !bfd_elf32_add_dynamic_entry (info
, DT_MIPS_MSYM
, 0))
7092 /* If we use dynamic linking, we generate a section symbol for each
7093 output section. These are local symbols, which means that they
7094 must come first in the dynamic symbol table.
7095 That means we must increment the dynamic symbol index of every
7096 other dynamic symbol. */
7099 struct mips_got_info
*g
;
7102 if (elf_hash_table (info
)->dynamic_sections_created
)
7105 /* We no longer try to restrict the set of sections which get
7106 dynamic symbol table entries, since it fails if we have
7107 other random sections which need dynamic relocations. */
7108 const char * const *namep
;
7109 bfd_size_type strindex
;
7110 struct bfd_strtab_hash
*dynstr
;
7112 if (SGI_COMPAT (output_bfd
))
7114 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
7115 elf_link_hash_traverse (elf_hash_table (info
),
7116 mips_elf_adjust_dynindx
,
7118 elf_hash_table (info
)->dynsymcount
+= c
;
7120 dynstr
= elf_hash_table (info
)->dynstr
;
7121 BFD_ASSERT (dynstr
!= NULL
);
7123 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
7127 s
= bfd_get_section_by_name (output_bfd
, *namep
);
7129 elf_section_data (s
)->dynindx
= i
;
7131 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
7132 if (strindex
== (bfd_size_type
) -1)
7135 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
7141 c
= bfd_count_sections (output_bfd
);
7142 elf_link_hash_traverse (elf_hash_table (info
),
7143 _bfd_elf_link_adjust_dynindx
,
7145 elf_hash_table (info
)->dynsymcount
+= c
;
7147 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
7149 elf_section_data (s
)->dynindx
= i
;
7150 /* These symbols will have no names, so we don't need to
7151 fiddle with dynstr_index. */
7158 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7159 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7160 BFD_ASSERT (g
!= NULL
);
7162 /* If there are no global got symbols, fake the last symbol so
7164 if (g
->global_gotsym
)
7165 g
->global_gotsym
+= c
;
7167 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
7174 /* Finish up dynamic symbol handling. We set the contents of various
7175 dynamic sections here. */
7178 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
7180 struct bfd_link_info
*info
;
7181 struct elf_link_hash_entry
*h
;
7182 Elf_Internal_Sym
*sym
;
7188 struct mips_got_info
*g
;
7190 struct mips_elf_link_hash_entry
*mh
;
7192 dynobj
= elf_hash_table (info
)->dynobj
;
7193 gval
= sym
->st_value
;
7194 mh
= (struct mips_elf_link_hash_entry
*) h
;
7196 if (h
->plt
.offset
!= (bfd_vma
) -1)
7200 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
7202 /* This symbol has a stub. Set it up. */
7204 BFD_ASSERT (h
->dynindx
!= -1);
7206 s
= bfd_get_section_by_name (dynobj
, ".stub");
7207 BFD_ASSERT (s
!= NULL
);
7209 /* Fill the stub. */
7211 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
7213 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
7216 /* FIXME: Can h->dynindex be more than 64K? */
7217 if (h
->dynindx
& 0xffff0000)
7220 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
7222 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
7224 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
7225 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
7227 /* Mark the symbol as undefined. plt.offset != -1 occurs
7228 only for the referenced symbol. */
7229 sym
->st_shndx
= SHN_UNDEF
;
7231 /* The run-time linker uses the st_value field of the symbol
7232 to reset the global offset table entry for this external
7233 to its stub address when unlinking a shared object. */
7234 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
7235 sym
->st_value
= gval
;
7238 BFD_ASSERT (h
->dynindx
!= -1);
7240 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7241 BFD_ASSERT (sgot
!= NULL
);
7242 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7243 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7244 BFD_ASSERT (g
!= NULL
);
7246 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
7248 bfd_size_type offset
;
7250 /* This symbol has an entry in the global offset table. Set its
7251 value to the corresponding got entry, if needed. */
7252 if (h
->got
.offset
== (bfd_vma
) -1)
7254 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
7255 BFD_ASSERT (g
->local_gotno
* 4 <= offset
7256 && offset
< sgot
->_raw_size
);
7257 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
7261 /* Create a .msym entry, if appropriate. */
7262 smsym
= bfd_get_section_by_name (dynobj
,
7263 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
7266 Elf32_Internal_Msym msym
;
7268 msym
.ms_hash_value
= bfd_elf_hash (h
->root
.root
.string
);
7269 /* It is undocumented what the `1' indicates, but IRIX6 uses
7271 msym
.ms_info
= ELF32_MS_INFO (mh
->min_dyn_reloc_index
, 1);
7272 bfd_mips_elf_swap_msym_out
7274 ((Elf32_External_Msym
*) smsym
->contents
) + h
->dynindx
);
7277 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7278 name
= h
->root
.root
.string
;
7279 if (strcmp (name
, "_DYNAMIC") == 0
7280 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
7281 sym
->st_shndx
= SHN_ABS
;
7282 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
7284 sym
->st_shndx
= SHN_ABS
;
7285 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7288 else if (SGI_COMPAT (output_bfd
))
7290 if (strcmp (name
, "_gp_disp") == 0)
7292 sym
->st_shndx
= SHN_ABS
;
7293 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7294 sym
->st_value
= elf_gp (output_bfd
);
7296 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
7297 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
7299 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7300 sym
->st_other
= STO_PROTECTED
;
7302 sym
->st_shndx
= SHN_MIPS_DATA
;
7304 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
7306 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7307 sym
->st_other
= STO_PROTECTED
;
7308 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
7309 sym
->st_shndx
= SHN_ABS
;
7311 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
7313 if (h
->type
== STT_FUNC
)
7314 sym
->st_shndx
= SHN_MIPS_TEXT
;
7315 else if (h
->type
== STT_OBJECT
)
7316 sym
->st_shndx
= SHN_MIPS_DATA
;
7320 if (SGI_COMPAT (output_bfd
)
7323 if (! mips_elf_hash_table (info
)->use_rld_obj_head
7324 && strcmp (name
, "__rld_map") == 0)
7326 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7327 BFD_ASSERT (s
!= NULL
);
7328 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
7329 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
7330 if (mips_elf_hash_table (info
)->rld_value
== 0)
7331 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7333 else if (mips_elf_hash_table (info
)->use_rld_obj_head
7334 && strcmp (name
, "__rld_obj_head") == 0)
7336 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7337 BFD_ASSERT (s
!= NULL
);
7338 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7342 /* If this is a mips16 symbol, force the value to be even. */
7343 if (sym
->st_other
== STO_MIPS16
7344 && (sym
->st_value
& 1) != 0)
7350 /* Finish up the dynamic sections. */
7353 mips_elf_finish_dynamic_sections (output_bfd
, info
)
7355 struct bfd_link_info
*info
;
7360 struct mips_got_info
*g
;
7362 dynobj
= elf_hash_table (info
)->dynobj
;
7364 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
7366 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7371 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7372 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7373 BFD_ASSERT (g
!= NULL
);
7376 if (elf_hash_table (info
)->dynamic_sections_created
)
7378 Elf32_External_Dyn
*dyncon
, *dynconend
;
7380 BFD_ASSERT (sdyn
!= NULL
);
7381 BFD_ASSERT (g
!= NULL
);
7383 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7384 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
7385 for (; dyncon
< dynconend
; dyncon
++)
7387 Elf_Internal_Dyn dyn
;
7392 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
7400 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7401 BFD_ASSERT (s
!= NULL
);
7402 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
7403 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7407 /* Rewrite DT_STRSZ. */
7409 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
7410 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7416 case DT_MIPS_CONFLICT
:
7419 case DT_MIPS_LIBLIST
:
7422 s
= bfd_get_section_by_name (output_bfd
, name
);
7423 BFD_ASSERT (s
!= NULL
);
7424 dyn
.d_un
.d_ptr
= s
->vma
;
7425 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7428 case DT_MIPS_RLD_VERSION
:
7429 dyn
.d_un
.d_val
= 1; /* XXX */
7430 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7434 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
7435 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7438 case DT_MIPS_CONFLICTNO
:
7440 elemsize
= sizeof (Elf32_Conflict
);
7443 case DT_MIPS_LIBLISTNO
:
7445 elemsize
= sizeof (Elf32_Lib
);
7447 s
= bfd_get_section_by_name (output_bfd
, name
);
7450 if (s
->_cooked_size
!= 0)
7451 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7453 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7458 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7461 case DT_MIPS_TIME_STAMP
:
7462 time ((time_t *) &dyn
.d_un
.d_val
);
7463 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7466 case DT_MIPS_ICHECKSUM
:
7470 case DT_MIPS_IVERSION
:
7474 case DT_MIPS_BASE_ADDRESS
:
7475 s
= output_bfd
->sections
;
7476 BFD_ASSERT (s
!= NULL
);
7477 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
7478 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7481 case DT_MIPS_LOCAL_GOTNO
:
7482 dyn
.d_un
.d_val
= g
->local_gotno
;
7483 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7486 case DT_MIPS_SYMTABNO
:
7488 elemsize
= sizeof (Elf32_External_Sym
);
7489 s
= bfd_get_section_by_name (output_bfd
, name
);
7490 BFD_ASSERT (s
!= NULL
);
7492 if (s
->_cooked_size
!= 0)
7493 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7495 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7496 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7499 case DT_MIPS_UNREFEXTNO
:
7501 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
7503 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
);
7505 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7508 case DT_MIPS_GOTSYM
:
7509 dyn
.d_un
.d_val
= g
->global_gotsym
;
7510 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7513 case DT_MIPS_HIPAGENO
:
7514 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
7515 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7518 case DT_MIPS_RLD_MAP
:
7519 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
7520 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7524 s
= (bfd_get_section_by_name
7525 (output_bfd
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
)));
7526 dyn
.d_un
.d_ptr
= s
->vma
;
7527 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7533 /* The first entry of the global offset table will be filled at
7534 runtime. The second entry will be used by some runtime loaders.
7535 This isn't the case of Irix rld. */
7536 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
7538 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
7539 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
7543 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
7549 Elf_Internal_Sym sym
;
7550 Elf32_compact_rel cpt
;
7552 /* Set up the section symbols for the output sections. SGI sets
7553 the STT_NOTYPE attribute for these symbols. Should we do so? */
7555 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
7556 smsym
= bfd_get_section_by_name (dynobj
,
7557 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
7558 if (sdynsym
!= NULL
)
7562 const char * const * namep
= mips_elf_dynsym_sec_names
;
7567 /* We no longer try to restrict the set of sections which get
7568 dynamic symbol table entries, since it fails if we have
7569 other random sections which need dynamic relocations. */
7570 if (SGI_COMPAT (output_bfd
))
7574 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7580 while ((name
= *namep
++) != NULL
)
7582 s
= bfd_get_section_by_name (output_bfd
, name
);
7585 sym
.st_value
= s
->vma
;
7586 dindx
= elf_section_data (s
)->dynindx
;
7587 last
= s
->vma
+ s
->_raw_size
;
7591 sym
.st_value
= last
;
7595 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
7600 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
7602 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7603 (((Elf32_External_Sym
*)
7608 /* Set the sh_info field of the output .dynsym section to
7609 the index of the first global symbol. */
7610 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7611 SIZEOF_MIPS_DYNSYM_SECNAMES
;
7616 Elf32_Internal_Msym msym
;
7620 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
7623 msym
.ms_hash_value
= 0;
7624 msym
.ms_info
= ELF32_MS_INFO (0, 1);
7626 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
7631 sym
.st_value
= s
->vma
;
7633 indx
= elf_section_data (s
)->this_idx
;
7634 BFD_ASSERT (indx
> 0);
7635 sym
.st_shndx
= indx
;
7637 dynindx
= elf_section_data (s
)->dynindx
;
7639 bfd_elf32_swap_symbol_out
7641 (((Elf32_External_Sym
*) sdynsym
->contents
)
7645 bfd_mips_elf_swap_msym_out
7647 (((Elf32_External_Msym
*) smsym
->contents
)
7651 /* Set the sh_info field of the output .dynsym section to
7652 the index of the first global symbol. */
7653 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7654 bfd_count_sections (output_bfd
) + 1;
7658 if (SGI_COMPAT (output_bfd
))
7660 /* Write .compact_rel section out. */
7661 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
7665 cpt
.num
= s
->reloc_count
;
7667 cpt
.offset
= (s
->output_section
->filepos
7668 + sizeof (Elf32_External_compact_rel
));
7671 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
7672 ((Elf32_External_compact_rel
*)
7675 /* Clean up a dummy stub function entry in .text. */
7676 s
= bfd_get_section_by_name (dynobj
, ".stub");
7679 file_ptr dummy_offset
;
7681 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
7682 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
7683 memset (s
->contents
+ dummy_offset
, 0,
7684 MIPS_FUNCTION_STUB_SIZE
);
7689 /* Clean up a first relocation in .rel.dyn. */
7690 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7691 if (s
!= NULL
&& s
->_raw_size
> 0)
7692 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
7698 /* This is almost identical to bfd_generic_get_... except that some
7699 MIPS relocations need to be handled specially. Sigh. */
7702 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
7703 relocateable
, symbols
)
7705 struct bfd_link_info
*link_info
;
7706 struct bfd_link_order
*link_order
;
7708 boolean relocateable
;
7711 /* Get enough memory to hold the stuff */
7712 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
7713 asection
*input_section
= link_order
->u
.indirect
.section
;
7715 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
7716 arelent
**reloc_vector
= NULL
;
7722 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
7723 if (reloc_vector
== NULL
&& reloc_size
!= 0)
7726 /* read in the section */
7727 if (!bfd_get_section_contents (input_bfd
,
7731 input_section
->_raw_size
))
7734 /* We're not relaxing the section, so just copy the size info */
7735 input_section
->_cooked_size
= input_section
->_raw_size
;
7736 input_section
->reloc_done
= true;
7738 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
7742 if (reloc_count
< 0)
7745 if (reloc_count
> 0)
7750 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
7753 struct bfd_hash_entry
*h
;
7754 struct bfd_link_hash_entry
*lh
;
7755 /* Skip all this stuff if we aren't mixing formats. */
7756 if (abfd
&& input_bfd
7757 && abfd
->xvec
== input_bfd
->xvec
)
7761 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
7762 lh
= (struct bfd_link_hash_entry
*) h
;
7769 case bfd_link_hash_undefined
:
7770 case bfd_link_hash_undefweak
:
7771 case bfd_link_hash_common
:
7774 case bfd_link_hash_defined
:
7775 case bfd_link_hash_defweak
:
7777 gp
= lh
->u
.def
.value
;
7779 case bfd_link_hash_indirect
:
7780 case bfd_link_hash_warning
:
7782 /* @@FIXME ignoring warning for now */
7784 case bfd_link_hash_new
:
7793 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
7796 char *error_message
= (char *) NULL
;
7797 bfd_reloc_status_type r
;
7799 /* Specific to MIPS: Deal with relocation types that require
7800 knowing the gp of the output bfd. */
7801 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
7802 if (bfd_is_abs_section (sym
->section
) && abfd
)
7804 /* The special_function wouldn't get called anyways. */
7808 /* The gp isn't there; let the special function code
7809 fall over on its own. */
7811 else if ((*parent
)->howto
->special_function
7812 == _bfd_mips_elf_gprel16_reloc
)
7814 /* bypass special_function call */
7815 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
7816 relocateable
, (PTR
) data
, gp
);
7817 goto skip_bfd_perform_relocation
;
7819 /* end mips specific stuff */
7821 r
= bfd_perform_relocation (input_bfd
,
7825 relocateable
? abfd
: (bfd
*) NULL
,
7827 skip_bfd_perform_relocation
:
7831 asection
*os
= input_section
->output_section
;
7833 /* A partial link, so keep the relocs */
7834 os
->orelocation
[os
->reloc_count
] = *parent
;
7838 if (r
!= bfd_reloc_ok
)
7842 case bfd_reloc_undefined
:
7843 if (!((*link_info
->callbacks
->undefined_symbol
)
7844 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7845 input_bfd
, input_section
, (*parent
)->address
)))
7848 case bfd_reloc_dangerous
:
7849 BFD_ASSERT (error_message
!= (char *) NULL
);
7850 if (!((*link_info
->callbacks
->reloc_dangerous
)
7851 (link_info
, error_message
, input_bfd
, input_section
,
7852 (*parent
)->address
)))
7855 case bfd_reloc_overflow
:
7856 if (!((*link_info
->callbacks
->reloc_overflow
)
7857 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7858 (*parent
)->howto
->name
, (*parent
)->addend
,
7859 input_bfd
, input_section
, (*parent
)->address
)))
7862 case bfd_reloc_outofrange
:
7871 if (reloc_vector
!= NULL
)
7872 free (reloc_vector
);
7876 if (reloc_vector
!= NULL
)
7877 free (reloc_vector
);
7880 #define bfd_elf32_bfd_get_relocated_section_contents \
7881 elf32_mips_get_relocated_section_contents
7883 /* ECOFF swapping routines. These are used when dealing with the
7884 .mdebug section, which is in the ECOFF debugging format. */
7885 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
7887 /* Symbol table magic number. */
7889 /* Alignment of debugging information. E.g., 4. */
7891 /* Sizes of external symbolic information. */
7892 sizeof (struct hdr_ext
),
7893 sizeof (struct dnr_ext
),
7894 sizeof (struct pdr_ext
),
7895 sizeof (struct sym_ext
),
7896 sizeof (struct opt_ext
),
7897 sizeof (struct fdr_ext
),
7898 sizeof (struct rfd_ext
),
7899 sizeof (struct ext_ext
),
7900 /* Functions to swap in external symbolic data. */
7909 _bfd_ecoff_swap_tir_in
,
7910 _bfd_ecoff_swap_rndx_in
,
7911 /* Functions to swap out external symbolic data. */
7920 _bfd_ecoff_swap_tir_out
,
7921 _bfd_ecoff_swap_rndx_out
,
7922 /* Function to read in symbolic data. */
7923 _bfd_mips_elf_read_ecoff_info
7926 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
7927 #define TARGET_LITTLE_NAME "elf32-littlemips"
7928 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
7929 #define TARGET_BIG_NAME "elf32-bigmips"
7930 #define ELF_ARCH bfd_arch_mips
7931 #define ELF_MACHINE_CODE EM_MIPS
7933 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
7934 a value of 0x1000, and we are compatible. */
7935 #define ELF_MAXPAGESIZE 0x1000
7937 #define elf_backend_collect true
7938 #define elf_backend_type_change_ok true
7939 #define elf_backend_can_gc_sections true
7940 #define elf_info_to_howto mips_info_to_howto_rela
7941 #define elf_info_to_howto_rel mips_info_to_howto_rel
7942 #define elf_backend_sym_is_global mips_elf_sym_is_global
7943 #define elf_backend_object_p mips_elf32_object_p
7944 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
7945 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
7946 #define elf_backend_section_from_bfd_section \
7947 _bfd_mips_elf_section_from_bfd_section
7948 #define elf_backend_section_processing mips_elf32_section_processing
7949 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
7950 #define elf_backend_additional_program_headers \
7951 mips_elf_additional_program_headers
7952 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
7953 #define elf_backend_final_write_processing \
7954 _bfd_mips_elf_final_write_processing
7955 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
7957 #define bfd_elf32_bfd_is_local_label_name \
7958 mips_elf_is_local_label_name
7959 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
7960 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
7961 #define bfd_elf32_bfd_link_hash_table_create \
7962 mips_elf_link_hash_table_create
7963 #define bfd_elf32_bfd_final_link mips_elf_final_link
7964 #define bfd_elf32_bfd_copy_private_bfd_data \
7965 _bfd_mips_elf_copy_private_bfd_data
7966 #define bfd_elf32_bfd_merge_private_bfd_data \
7967 _bfd_mips_elf_merge_private_bfd_data
7968 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
7969 #define bfd_elf32_bfd_print_private_bfd_data \
7970 _bfd_mips_elf_print_private_bfd_data
7971 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
7972 #define elf_backend_create_dynamic_sections \
7973 mips_elf_create_dynamic_sections
7974 #define elf_backend_check_relocs mips_elf_check_relocs
7975 #define elf_backend_adjust_dynamic_symbol \
7976 mips_elf_adjust_dynamic_symbol
7977 #define elf_backend_always_size_sections \
7978 mips_elf_always_size_sections
7979 #define elf_backend_size_dynamic_sections \
7980 mips_elf_size_dynamic_sections
7981 #define elf_backend_relocate_section mips_elf_relocate_section
7982 #define elf_backend_link_output_symbol_hook \
7983 mips_elf_link_output_symbol_hook
7984 #define elf_backend_finish_dynamic_symbol \
7985 mips_elf_finish_dynamic_symbol
7986 #define elf_backend_finish_dynamic_sections \
7987 mips_elf_finish_dynamic_sections
7988 #define elf_backend_gc_mark_hook mips_elf_gc_mark_hook
7989 #define elf_backend_gc_sweep_hook mips_elf_gc_sweep_hook
7991 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
7992 #define elf_backend_plt_header_size 0
7994 #include "elf32-target.h"