1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
4 Most of the information added by Ian Lance Taylor, Cygnus Support,
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 /* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
24 different MIPS ELF from other targets. This matters when linking.
25 This file supports both, switching at runtime. */
34 #define START_RELOC_NUMBERS(name) enum name {
35 #define RELOC_NUMBER(name, number) name = number ,
36 #define END_RELOC_NUMBERS };
39 /* Get the ECOFF swapping routines. */
41 #include "coff/symconst.h"
42 #include "coff/internal.h"
43 #include "coff/ecoff.h"
44 #include "coff/mips.h"
46 #include "ecoffswap.h"
48 static bfd_reloc_status_type mips32_64bit_reloc
49 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
50 static reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
51 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
52 static void mips_info_to_howto_rel
53 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
54 static void bfd_mips_elf32_swap_gptab_in
55 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
56 static void bfd_mips_elf32_swap_gptab_out
57 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
58 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
59 static boolean mips_elf32_object_p
PARAMS ((bfd
*));
60 static boolean mips_elf_create_procedure_table
61 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
62 struct ecoff_debug_info
*));
63 static int mips_elf_additional_program_headers
PARAMS ((bfd
*));
64 static boolean mips_elf_modify_segment_map
PARAMS ((bfd
*));
65 static INLINE
int elf_mips_isa
PARAMS ((flagword
));
66 static INLINE
int elf_mips_mach
PARAMS ((flagword
));
67 static boolean mips_elf32_section_from_shdr
68 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, char *));
69 static boolean mips_elf32_section_processing
70 PARAMS ((bfd
*, Elf32_Internal_Shdr
*));
71 static boolean mips_elf_is_local_label_name
72 PARAMS ((bfd
*, const char *));
73 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
74 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
75 static struct bfd_link_hash_table
*mips_elf_link_hash_table_create
77 static int gptab_compare
PARAMS ((const void *, const void *));
78 static boolean mips_elf_final_link
79 PARAMS ((bfd
*, struct bfd_link_info
*));
80 static void mips_elf_relocate_hi16
81 PARAMS ((bfd
*, Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_byte
*,
83 static boolean mips_elf_relocate_got_local
84 PARAMS ((bfd
*, bfd
*, asection
*, Elf_Internal_Rela
*,
85 Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
86 static void mips_elf_relocate_global_got
87 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
88 static bfd_reloc_status_type mips16_jump_reloc
89 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
90 static bfd_reloc_status_type mips16_gprel_reloc
91 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
92 /* start-sanitize-sky */
93 static bfd_reloc_status_type dvp_u15_s3_reloc
94 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
95 /* end-sanitize-sky */
96 static boolean mips_elf_adjust_dynindx
97 PARAMS ((struct elf_link_hash_entry
*, PTR
));
98 static boolean mips_elf_relocate_section
99 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
100 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
101 static boolean mips_elf_link_output_symbol_hook
102 PARAMS ((bfd
*, struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
104 static boolean mips_elf_create_dynamic_sections
105 PARAMS ((bfd
*, struct bfd_link_info
*));
106 static boolean mips_elf_create_compact_rel_section
107 PARAMS ((bfd
*, struct bfd_link_info
*));
108 static boolean mips_elf_create_got_section
109 PARAMS ((bfd
*, struct bfd_link_info
*));
110 static boolean mips_elf_check_relocs
111 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
112 const Elf_Internal_Rela
*));
113 static boolean mips_elf_adjust_dynamic_symbol
114 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
115 static boolean mips_elf_always_size_sections
116 PARAMS ((bfd
*, struct bfd_link_info
*));
117 static boolean mips_elf_size_dynamic_sections
118 PARAMS ((bfd
*, struct bfd_link_info
*));
119 static boolean mips_elf_finish_dynamic_symbol
120 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
121 Elf_Internal_Sym
*));
122 static boolean mips_elf_finish_dynamic_sections
123 PARAMS ((bfd
*, struct bfd_link_info
*));
124 static boolean mips_elf_add_symbol_hook
125 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
126 const char **, flagword
*, asection
**, bfd_vma
*));
127 static bfd_reloc_status_type mips_elf_final_gp
128 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
129 static bfd_byte
*elf32_mips_get_relocated_section_contents
130 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
131 bfd_byte
*, boolean
, asymbol
**));
133 /* This is true for Irix 5 executables, false for normal MIPS ELF ABI
134 executables. FIXME: At the moment, we default to always generating
135 Irix 5 executables. */
137 #define SGI_COMPAT(abfd) (1)
139 /* This structure is used to hold .got information when linking. It
140 is stored in the tdata field of the bfd_elf_section_data structure. */
144 /* The symbol index of the first global .got symbol. */
145 unsigned long global_gotsym
;
146 /* The number of local .got entries. */
147 unsigned int local_gotno
;
148 /* The number of local .got entries we have used. */
149 unsigned int assigned_gotno
;
152 /* The number of local .got entries we reserve. */
153 #define MIPS_RESERVED_GOTNO (2)
155 /* Instructions which appear in a stub. For some reason the stub is
156 slightly different on an SGI system. */
157 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
158 #define STUB_LW(abfd) \
160 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
161 : 0x8f998000) /* lw t9,0x8000(gp) */
162 #define STUB_MOVE 0x03e07825 /* move t7,ra */
163 #define STUB_JALR 0x0320f809 /* jal t9 */
164 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
165 #define MIPS_FUNCTION_STUB_SIZE (16)
167 /* Names of sections which appear in the .dynsym section in an Irix 5
170 static const char * const mips_elf_dynsym_sec_names
[] =
183 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
184 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
186 /* The number of entries in mips_elf_dynsym_sec_names which go in the
189 #define MIPS_TEXT_DYNSYM_SECNO (3)
191 /* The names of the runtime procedure table symbols used on Irix 5. */
193 static const char * const mips_elf_dynsym_rtproc_names
[] =
196 "_procedure_string_table",
197 "_procedure_table_size",
201 /* These structures are used to generate the .compact_rel section on
206 unsigned long id1
; /* Always one? */
207 unsigned long num
; /* Number of compact relocation entries. */
208 unsigned long id2
; /* Always two? */
209 unsigned long offset
; /* The file offset of the first relocation. */
210 unsigned long reserved0
; /* Zero? */
211 unsigned long reserved1
; /* Zero? */
220 bfd_byte reserved0
[4];
221 bfd_byte reserved1
[4];
222 } Elf32_External_compact_rel
;
226 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
227 unsigned int rtype
: 4; /* Relocation types. See below. */
228 unsigned int dist2to
: 8;
229 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
230 unsigned long konst
; /* KONST field. See below. */
231 unsigned long vaddr
; /* VADDR to be relocated. */
236 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
237 unsigned int rtype
: 4; /* Relocation types. See below. */
238 unsigned int dist2to
: 8;
239 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
240 unsigned long konst
; /* KONST field. See below. */
248 } Elf32_External_crinfo
;
254 } Elf32_External_crinfo2
;
256 /* These are the constants used to swap the bitfields in a crinfo. */
258 #define CRINFO_CTYPE (0x1)
259 #define CRINFO_CTYPE_SH (31)
260 #define CRINFO_RTYPE (0xf)
261 #define CRINFO_RTYPE_SH (27)
262 #define CRINFO_DIST2TO (0xff)
263 #define CRINFO_DIST2TO_SH (19)
264 #define CRINFO_RELVADDR (0x7ffff)
265 #define CRINFO_RELVADDR_SH (0)
267 /* A compact relocation info has long (3 words) or short (2 words)
268 formats. A short format doesn't have VADDR field and relvaddr
269 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
270 #define CRF_MIPS_LONG 1
271 #define CRF_MIPS_SHORT 0
273 /* There are 4 types of compact relocation at least. The value KONST
274 has different meaning for each type:
277 CT_MIPS_REL32 Address in data
278 CT_MIPS_WORD Address in word (XXX)
279 CT_MIPS_GPHI_LO GP - vaddr
280 CT_MIPS_JMPAD Address to jump
283 #define CRT_MIPS_REL32 0xa
284 #define CRT_MIPS_WORD 0xb
285 #define CRT_MIPS_GPHI_LO 0xc
286 #define CRT_MIPS_JMPAD 0xd
288 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
289 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
290 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
291 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
293 static void bfd_elf32_swap_compact_rel_out
294 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
295 static void bfd_elf32_swap_crinfo_out
296 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
298 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
300 static reloc_howto_type elf_mips_howto_table
[] =
303 HOWTO (R_MIPS_NONE
, /* type */
305 0, /* size (0 = byte, 1 = short, 2 = long) */
307 false, /* pc_relative */
309 complain_overflow_dont
, /* complain_on_overflow */
310 bfd_elf_generic_reloc
, /* special_function */
311 "R_MIPS_NONE", /* name */
312 false, /* partial_inplace */
315 false), /* pcrel_offset */
317 /* 16 bit relocation. */
318 HOWTO (R_MIPS_16
, /* type */
320 1, /* size (0 = byte, 1 = short, 2 = long) */
322 false, /* pc_relative */
324 complain_overflow_bitfield
, /* complain_on_overflow */
325 bfd_elf_generic_reloc
, /* special_function */
326 "R_MIPS_16", /* name */
327 true, /* partial_inplace */
328 0xffff, /* src_mask */
329 0xffff, /* dst_mask */
330 false), /* pcrel_offset */
332 /* 32 bit relocation. */
333 HOWTO (R_MIPS_32
, /* type */
335 2, /* size (0 = byte, 1 = short, 2 = long) */
337 false, /* pc_relative */
339 complain_overflow_bitfield
, /* complain_on_overflow */
340 bfd_elf_generic_reloc
, /* special_function */
341 "R_MIPS_32", /* name */
342 true, /* partial_inplace */
343 0xffffffff, /* src_mask */
344 0xffffffff, /* dst_mask */
345 false), /* pcrel_offset */
347 /* 32 bit symbol relative relocation. */
348 HOWTO (R_MIPS_REL32
, /* type */
350 2, /* size (0 = byte, 1 = short, 2 = long) */
352 false, /* pc_relative */
354 complain_overflow_bitfield
, /* complain_on_overflow */
355 bfd_elf_generic_reloc
, /* special_function */
356 "R_MIPS_REL32", /* name */
357 true, /* partial_inplace */
358 0xffffffff, /* src_mask */
359 0xffffffff, /* dst_mask */
360 false), /* pcrel_offset */
362 /* 26 bit branch address. */
363 HOWTO (R_MIPS_26
, /* type */
365 2, /* size (0 = byte, 1 = short, 2 = long) */
367 false, /* pc_relative */
369 complain_overflow_dont
, /* complain_on_overflow */
370 /* This needs complex overflow
371 detection, because the upper four
372 bits must match the PC. */
373 bfd_elf_generic_reloc
, /* special_function */
374 "R_MIPS_26", /* name */
375 true, /* partial_inplace */
376 0x3ffffff, /* src_mask */
377 0x3ffffff, /* dst_mask */
378 false), /* pcrel_offset */
380 /* High 16 bits of symbol value. */
381 HOWTO (R_MIPS_HI16
, /* type */
383 2, /* size (0 = byte, 1 = short, 2 = long) */
385 false, /* pc_relative */
387 complain_overflow_dont
, /* complain_on_overflow */
388 _bfd_mips_elf_hi16_reloc
, /* special_function */
389 "R_MIPS_HI16", /* name */
390 true, /* partial_inplace */
391 0xffff, /* src_mask */
392 0xffff, /* dst_mask */
393 false), /* pcrel_offset */
395 /* Low 16 bits of symbol value. */
396 HOWTO (R_MIPS_LO16
, /* type */
398 2, /* size (0 = byte, 1 = short, 2 = long) */
400 false, /* pc_relative */
402 complain_overflow_dont
, /* complain_on_overflow */
403 _bfd_mips_elf_lo16_reloc
, /* special_function */
404 "R_MIPS_LO16", /* name */
405 true, /* partial_inplace */
406 0xffff, /* src_mask */
407 0xffff, /* dst_mask */
408 false), /* pcrel_offset */
410 /* GP relative reference. */
411 HOWTO (R_MIPS_GPREL16
, /* type */
413 2, /* size (0 = byte, 1 = short, 2 = long) */
415 false, /* pc_relative */
417 complain_overflow_signed
, /* complain_on_overflow */
418 _bfd_mips_elf_gprel16_reloc
, /* special_function */
419 "R_MIPS_GPREL16", /* name */
420 true, /* partial_inplace */
421 0xffff, /* src_mask */
422 0xffff, /* dst_mask */
423 false), /* pcrel_offset */
425 /* Reference to literal section. */
426 HOWTO (R_MIPS_LITERAL
, /* type */
428 2, /* size (0 = byte, 1 = short, 2 = long) */
430 false, /* pc_relative */
432 complain_overflow_signed
, /* complain_on_overflow */
433 _bfd_mips_elf_gprel16_reloc
, /* special_function */
434 "R_MIPS_LITERAL", /* name */
435 true, /* partial_inplace */
436 0xffff, /* src_mask */
437 0xffff, /* dst_mask */
438 false), /* pcrel_offset */
440 /* Reference to global offset table. */
441 HOWTO (R_MIPS_GOT16
, /* type */
443 2, /* size (0 = byte, 1 = short, 2 = long) */
445 false, /* pc_relative */
447 complain_overflow_signed
, /* complain_on_overflow */
448 _bfd_mips_elf_got16_reloc
, /* special_function */
449 "R_MIPS_GOT16", /* name */
450 false, /* partial_inplace */
452 0xffff, /* dst_mask */
453 false), /* pcrel_offset */
455 /* 16 bit PC relative reference. */
456 HOWTO (R_MIPS_PC16
, /* type */
458 2, /* size (0 = byte, 1 = short, 2 = long) */
460 true, /* pc_relative */
462 complain_overflow_signed
, /* complain_on_overflow */
463 bfd_elf_generic_reloc
, /* special_function */
464 "R_MIPS_PC16", /* name */
465 true, /* partial_inplace */
466 0xffff, /* src_mask */
467 0xffff, /* dst_mask */
468 false), /* pcrel_offset */
470 /* 16 bit call through global offset table. */
471 /* FIXME: This is not handled correctly. */
472 HOWTO (R_MIPS_CALL16
, /* type */
474 2, /* size (0 = byte, 1 = short, 2 = long) */
476 false, /* pc_relative */
478 complain_overflow_signed
, /* complain_on_overflow */
479 bfd_elf_generic_reloc
, /* special_function */
480 "R_MIPS_CALL16", /* name */
481 false, /* partial_inplace */
483 0xffff, /* dst_mask */
484 false), /* pcrel_offset */
486 /* 32 bit GP relative reference. */
487 HOWTO (R_MIPS_GPREL32
, /* type */
489 2, /* size (0 = byte, 1 = short, 2 = long) */
491 false, /* pc_relative */
493 complain_overflow_bitfield
, /* complain_on_overflow */
494 _bfd_mips_elf_gprel32_reloc
, /* special_function */
495 "R_MIPS_GPREL32", /* name */
496 true, /* partial_inplace */
497 0xffffffff, /* src_mask */
498 0xffffffff, /* dst_mask */
499 false), /* pcrel_offset */
501 /* The remaining relocs are defined on Irix 5, although they are
502 not defined by the ABI. */
507 /* A 5 bit shift field. */
508 HOWTO (R_MIPS_SHIFT5
, /* type */
510 2, /* size (0 = byte, 1 = short, 2 = long) */
512 false, /* pc_relative */
514 complain_overflow_bitfield
, /* complain_on_overflow */
515 bfd_elf_generic_reloc
, /* special_function */
516 "R_MIPS_SHIFT5", /* name */
517 true, /* partial_inplace */
518 0x000007c0, /* src_mask */
519 0x000007c0, /* dst_mask */
520 false), /* pcrel_offset */
522 /* A 6 bit shift field. */
523 /* FIXME: This is not handled correctly; a special function is
524 needed to put the most significant bit in the right place. */
525 HOWTO (R_MIPS_SHIFT6
, /* type */
527 2, /* size (0 = byte, 1 = short, 2 = long) */
529 false, /* pc_relative */
531 complain_overflow_bitfield
, /* complain_on_overflow */
532 bfd_elf_generic_reloc
, /* special_function */
533 "R_MIPS_SHIFT6", /* name */
534 true, /* partial_inplace */
535 0x000007c4, /* src_mask */
536 0x000007c4, /* dst_mask */
537 false), /* pcrel_offset */
539 /* A 64 bit relocation. This is used in 32 bit ELF when addresses
540 are 64 bits long; the upper 32 bits are simply a sign extension.
541 The fields of the howto should be the same as for R_MIPS_32,
542 other than the type, name, and special_function. */
543 HOWTO (R_MIPS_64
, /* type */
545 2, /* size (0 = byte, 1 = short, 2 = long) */
547 false, /* pc_relative */
549 complain_overflow_bitfield
, /* complain_on_overflow */
550 mips32_64bit_reloc
, /* special_function */
551 "R_MIPS_64", /* name */
552 true, /* partial_inplace */
553 0xffffffff, /* src_mask */
554 0xffffffff, /* dst_mask */
555 false), /* pcrel_offset */
557 /* Displacement in the global offset table. */
558 /* FIXME: Not handled correctly. */
559 HOWTO (R_MIPS_GOT_DISP
, /* type */
561 2, /* size (0 = byte, 1 = short, 2 = long) */
563 false, /* pc_relative */
565 complain_overflow_bitfield
, /* complain_on_overflow */
566 bfd_elf_generic_reloc
, /* special_function */
567 "R_MIPS_GOT_DISP", /* name */
568 true, /* partial_inplace */
569 0x0000ffff, /* src_mask */
570 0x0000ffff, /* dst_mask */
571 false), /* pcrel_offset */
573 /* Displacement to page pointer in the global offset table. */
574 /* FIXME: Not handled correctly. */
575 HOWTO (R_MIPS_GOT_PAGE
, /* type */
577 2, /* size (0 = byte, 1 = short, 2 = long) */
579 false, /* pc_relative */
581 complain_overflow_bitfield
, /* complain_on_overflow */
582 bfd_elf_generic_reloc
, /* special_function */
583 "R_MIPS_GOT_PAGE", /* name */
584 true, /* partial_inplace */
585 0x0000ffff, /* src_mask */
586 0x0000ffff, /* dst_mask */
587 false), /* pcrel_offset */
589 /* Offset from page pointer in the global offset table. */
590 /* FIXME: Not handled correctly. */
591 HOWTO (R_MIPS_GOT_OFST
, /* 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_OFST", /* name */
600 true, /* partial_inplace */
601 0x0000ffff, /* src_mask */
602 0x0000ffff, /* dst_mask */
603 false), /* pcrel_offset */
605 /* High 16 bits of displacement in global offset table. */
606 /* FIXME: Not handled correctly. */
607 HOWTO (R_MIPS_GOT_HI16
, /* type */
609 2, /* size (0 = byte, 1 = short, 2 = long) */
611 false, /* pc_relative */
613 complain_overflow_dont
, /* complain_on_overflow */
614 bfd_elf_generic_reloc
, /* special_function */
615 "R_MIPS_GOT_HI16", /* name */
616 true, /* partial_inplace */
617 0x0000ffff, /* src_mask */
618 0x0000ffff, /* dst_mask */
619 false), /* pcrel_offset */
621 /* Low 16 bits of displacement in global offset table. */
622 /* FIXME: Not handled correctly. */
623 HOWTO (R_MIPS_GOT_LO16
, /* type */
625 2, /* size (0 = byte, 1 = short, 2 = long) */
627 false, /* pc_relative */
629 complain_overflow_dont
, /* complain_on_overflow */
630 bfd_elf_generic_reloc
, /* special_function */
631 "R_MIPS_GOT_LO16", /* name */
632 true, /* partial_inplace */
633 0x0000ffff, /* src_mask */
634 0x0000ffff, /* dst_mask */
635 false), /* pcrel_offset */
637 /* 64 bit subtraction. Presumably not used in 32 bit ELF. */
640 /* Used to cause the linker to insert and delete instructions? */
645 /* Get the higher values of a 64 bit addend. Presumably not used in
650 /* High 16 bits of displacement in global offset table. */
651 /* FIXME: Not handled correctly. */
652 HOWTO (R_MIPS_CALL_HI16
, /* type */
654 2, /* size (0 = byte, 1 = short, 2 = long) */
656 false, /* pc_relative */
658 complain_overflow_dont
, /* complain_on_overflow */
659 bfd_elf_generic_reloc
, /* special_function */
660 "R_MIPS_CALL_HI16", /* name */
661 true, /* partial_inplace */
662 0x0000ffff, /* src_mask */
663 0x0000ffff, /* dst_mask */
664 false), /* pcrel_offset */
666 /* Low 16 bits of displacement in global offset table. */
667 /* FIXME: Not handled correctly. */
668 HOWTO (R_MIPS_CALL_LO16
, /* type */
670 2, /* size (0 = byte, 1 = short, 2 = long) */
672 false, /* pc_relative */
674 complain_overflow_dont
, /* complain_on_overflow */
675 bfd_elf_generic_reloc
, /* special_function */
676 "R_MIPS_CALL_LO16", /* name */
677 true, /* partial_inplace */
678 0x0000ffff, /* src_mask */
679 0x0000ffff, /* dst_mask */
680 false), /* pcrel_offset */
682 /* start-sanitize-r5900 */
683 HOWTO (R_MIPS15_S3
, /* type */
685 2, /* size (0 = byte, 1 = short, 2 = long) */
687 false, /* pc_relative */
689 complain_overflow_bitfield
, /* complain_on_overflow */
690 bfd_elf_generic_reloc
, /* special_function */
691 "R_MIPS15_S3", /* name */
692 true, /* partial_inplace */
693 0x001fffc0, /* src_mask */
694 0x001fffc0, /* dst_mask */
695 false) /* pcrel_offset */
696 /* end-sanitize-r5900 */
700 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
701 is a hack to make the linker think that we need 64 bit values. */
702 static reloc_howto_type elf_mips_ctor64_howto
=
703 HOWTO (R_MIPS_64
, /* type */
705 4, /* size (0 = byte, 1 = short, 2 = long) */
707 false, /* pc_relative */
709 complain_overflow_signed
, /* complain_on_overflow */
710 mips32_64bit_reloc
, /* special_function */
711 "R_MIPS_64", /* name */
712 true, /* partial_inplace */
713 0xffffffff, /* src_mask */
714 0xffffffff, /* dst_mask */
715 false); /* pcrel_offset */
717 /* The reloc used for the mips16 jump instruction. */
718 static reloc_howto_type elf_mips16_jump_howto
=
719 HOWTO (R_MIPS16_26
, /* type */
721 2, /* size (0 = byte, 1 = short, 2 = long) */
723 false, /* pc_relative */
725 complain_overflow_dont
, /* complain_on_overflow */
726 /* This needs complex overflow
727 detection, because the upper four
728 bits must match the PC. */
729 mips16_jump_reloc
, /* special_function */
730 "R_MIPS16_26", /* name */
731 true, /* partial_inplace */
732 0x3ffffff, /* src_mask */
733 0x3ffffff, /* dst_mask */
734 false); /* pcrel_offset */
736 /* The reloc used for the mips16 gprel instruction. The src_mask and
737 dsk_mask for this howto do not reflect the actual instruction, in
738 which the value is not contiguous; the masks are for the
739 convenience of the relocate_section routine. */
740 static reloc_howto_type elf_mips16_gprel_howto
=
741 HOWTO (R_MIPS16_GPREL
, /* type */
743 2, /* size (0 = byte, 1 = short, 2 = long) */
745 false, /* pc_relative */
747 complain_overflow_signed
, /* complain_on_overflow */
748 mips16_gprel_reloc
, /* special_function */
749 "R_MIPS16_GPREL", /* name */
750 true, /* partial_inplace */
751 0xffff, /* src_mask */
752 0xffff, /* dst_mask */
753 false); /* pcrel_offset */
755 /* start-sanitize-sky */
757 Note that partial_inplace and pcrel_offset are backwards from the
758 mips port. This is intentional as it seems more reasonable. */
759 static reloc_howto_type elf_mips_dvp_11_pcrel_howto
=
760 HOWTO (R_MIPS_DVP_11_PCREL
, /* type */
762 2, /* size (0 = byte, 1 = short, 2 = long) */
764 true, /* pc_relative */
766 complain_overflow_signed
, /* complain_on_overflow */
767 bfd_elf_generic_reloc
, /* special_function */
768 "R_MIPS_DVP_11_PCREL", /* name */
769 false, /* partial_inplace */
770 0x7ff, /* src_mask */
771 0x7ff, /* dst_mask */
772 true); /* pcrel_offset */
773 static reloc_howto_type elf_mips_dvp_27_s4_howto
=
774 HOWTO (R_MIPS_DVP_27_S4
, /* type */
776 2, /* size (0 = byte, 1 = short, 2 = long) */
778 false, /* pc_relative */
780 complain_overflow_unsigned
, /* complain_on_overflow */
781 bfd_elf_generic_reloc
, /* special_function */
782 "R_MIPS_DVP_27_S4", /* name */
783 false, /* partial_inplace */
784 0x7ffffff0, /* src_mask */
785 0x7ffffff0, /* dst_mask */
786 false); /* pcrel_offset */
787 static reloc_howto_type elf_mips_dvp_11_s4_howto
=
788 HOWTO (R_MIPS_DVP_11_S4
, /* type */
790 2, /* size (0 = byte, 1 = short, 2 = long) */
792 false, /* pc_relative */
794 complain_overflow_signed
, /* complain_on_overflow */
795 bfd_elf_generic_reloc
, /* special_function */
796 "R_MIPS_DVP_11_S4", /* name */
797 false, /* partial_inplace */
798 0x03ff, /* src_mask */
799 0x03ff, /* dst_mask */
800 false); /* pcrel_offset */
801 static reloc_howto_type elf_mips_dvp_u15_s3_howto
=
802 HOWTO (R_MIPS_DVP_U15_S3
, /* type */
804 2, /* size (0 = byte, 1 = short, 2 = long) */
806 false, /* pc_relative */
808 complain_overflow_unsigned
, /* complain_on_overflow */
809 dvp_u15_s3_reloc
, /* special_function */
810 "R_MIPS_DVP_U15_S3", /* name */
811 false, /* partial_inplace */
812 0xf03ff, /* src_mask */
813 0xf03ff, /* dst_mask */
814 false); /* pcrel_offset */
815 /* end-sanitize-sky */
817 /* GNU extension to record C++ vtable hierarchy */
818 static reloc_howto_type elf_mips_gnu_vtinherit_howto
=
819 HOWTO (R_MIPS_GNU_VTINHERIT
, /* type */
821 2, /* size (0 = byte, 1 = short, 2 = long) */
823 false, /* pc_relative */
825 complain_overflow_dont
, /* complain_on_overflow */
826 NULL
, /* special_function */
827 "R_MIPS_GNU_VTINHERIT", /* name */
828 false, /* partial_inplace */
831 false); /* pcrel_offset */
833 /* GNU extension to record C++ vtable member usage */
834 static reloc_howto_type elf_mips_gnu_vtentry_howto
=
835 HOWTO (R_MIPS_GNU_VTENTRY
, /* type */
837 2, /* size (0 = byte, 1 = short, 2 = long) */
839 false, /* pc_relative */
841 complain_overflow_dont
, /* complain_on_overflow */
842 NULL
, /* special_function */
843 "R_MIPS_GNU_VTENTRY", /* name */
844 false, /* partial_inplace */
847 false); /* pcrel_offset */
849 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
850 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
851 the HI16. Here we just save the information we need; we do the
852 actual relocation when we see the LO16. MIPS ELF requires that the
853 LO16 immediately follow the HI16. As a GNU extension, we permit an
854 arbitrary number of HI16 relocs to be associated with a single LO16
855 reloc. This extension permits gcc to output the HI and LO relocs
860 struct mips_hi16
*next
;
865 /* FIXME: This should not be a static variable. */
867 static struct mips_hi16
*mips_hi16_list
;
869 bfd_reloc_status_type
870 _bfd_mips_elf_hi16_reloc (abfd
,
878 arelent
*reloc_entry
;
881 asection
*input_section
;
883 char **error_message
;
885 bfd_reloc_status_type ret
;
889 /* If we're relocating, and this an external symbol, we don't want
890 to change anything. */
891 if (output_bfd
!= (bfd
*) NULL
892 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
893 && reloc_entry
->addend
== 0)
895 reloc_entry
->address
+= input_section
->output_offset
;
901 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
903 boolean relocateable
;
906 if (ret
== bfd_reloc_undefined
)
909 if (output_bfd
!= NULL
)
913 relocateable
= false;
914 output_bfd
= symbol
->section
->output_section
->owner
;
917 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
919 if (ret
!= bfd_reloc_ok
)
922 relocation
= gp
- reloc_entry
->address
;
926 if (bfd_is_und_section (symbol
->section
)
927 && output_bfd
== (bfd
*) NULL
)
928 ret
= bfd_reloc_undefined
;
930 if (bfd_is_com_section (symbol
->section
))
933 relocation
= symbol
->value
;
936 relocation
+= symbol
->section
->output_section
->vma
;
937 relocation
+= symbol
->section
->output_offset
;
938 relocation
+= reloc_entry
->addend
;
940 if (reloc_entry
->address
> input_section
->_cooked_size
)
941 return bfd_reloc_outofrange
;
943 /* Save the information, and let LO16 do the actual relocation. */
944 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
946 return bfd_reloc_outofrange
;
947 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
948 n
->addend
= relocation
;
949 n
->next
= mips_hi16_list
;
952 if (output_bfd
!= (bfd
*) NULL
)
953 reloc_entry
->address
+= input_section
->output_offset
;
958 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
959 inplace relocation; this function exists in order to do the
960 R_MIPS_HI16 relocation described above. */
962 bfd_reloc_status_type
963 _bfd_mips_elf_lo16_reloc (abfd
,
971 arelent
*reloc_entry
;
974 asection
*input_section
;
976 char **error_message
;
978 arelent gp_disp_relent
;
980 if (mips_hi16_list
!= NULL
)
990 struct mips_hi16
*next
;
992 /* Do the HI16 relocation. Note that we actually don't need
993 to know anything about the LO16 itself, except where to
994 find the low 16 bits of the addend needed by the LO16. */
995 insn
= bfd_get_32 (abfd
, l
->addr
);
996 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
998 val
= ((insn
& 0xffff) << 16) + vallo
;
1001 /* The low order 16 bits are always treated as a signed
1002 value. Therefore, a negative value in the low order bits
1003 requires an adjustment in the high order bits. We need
1004 to make this adjustment in two ways: once for the bits we
1005 took from the data, and once for the bits we are putting
1006 back in to the data. */
1007 if ((vallo
& 0x8000) != 0)
1009 if ((val
& 0x8000) != 0)
1012 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
1013 bfd_put_32 (abfd
, insn
, l
->addr
);
1015 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1017 gp_disp_relent
= *reloc_entry
;
1018 reloc_entry
= &gp_disp_relent
;
1019 reloc_entry
->addend
= l
->addend
;
1027 mips_hi16_list
= NULL
;
1029 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1031 bfd_reloc_status_type ret
;
1032 bfd_vma gp
, relocation
;
1034 /* FIXME: Does this case ever occur? */
1036 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
1037 if (ret
!= bfd_reloc_ok
)
1040 relocation
= gp
- reloc_entry
->address
;
1041 relocation
+= symbol
->section
->output_section
->vma
;
1042 relocation
+= symbol
->section
->output_offset
;
1043 relocation
+= reloc_entry
->addend
;
1045 if (reloc_entry
->address
> input_section
->_cooked_size
)
1046 return bfd_reloc_outofrange
;
1048 gp_disp_relent
= *reloc_entry
;
1049 reloc_entry
= &gp_disp_relent
;
1050 reloc_entry
->addend
= relocation
- 4;
1053 /* Now do the LO16 reloc in the usual way. */
1054 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1055 input_section
, output_bfd
, error_message
);
1058 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1059 table used for PIC code. If the symbol is an external symbol, the
1060 instruction is modified to contain the offset of the appropriate
1061 entry in the global offset table. If the symbol is a section
1062 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1063 addends are combined to form the real addend against the section
1064 symbol; the GOT16 is modified to contain the offset of an entry in
1065 the global offset table, and the LO16 is modified to offset it
1066 appropriately. Thus an offset larger than 16 bits requires a
1067 modified value in the global offset table.
1069 This implementation suffices for the assembler, but the linker does
1070 not yet know how to create global offset tables. */
1072 bfd_reloc_status_type
1073 _bfd_mips_elf_got16_reloc (abfd
,
1081 arelent
*reloc_entry
;
1084 asection
*input_section
;
1086 char **error_message
;
1088 /* If we're relocating, and this an external symbol, we don't want
1089 to change anything. */
1090 if (output_bfd
!= (bfd
*) NULL
1091 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1092 && reloc_entry
->addend
== 0)
1094 reloc_entry
->address
+= input_section
->output_offset
;
1095 return bfd_reloc_ok
;
1098 /* If we're relocating, and this is a local symbol, we can handle it
1100 if (output_bfd
!= (bfd
*) NULL
1101 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1102 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1103 input_section
, output_bfd
, error_message
);
1108 /* We have to figure out the gp value, so that we can adjust the
1109 symbol value correctly. We look up the symbol _gp in the output
1110 BFD. If we can't find it, we're stuck. We cache it in the ELF
1111 target data. We don't need to adjust the symbol value for an
1112 external symbol if we are producing relocateable output. */
1114 static bfd_reloc_status_type
1115 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1118 boolean relocateable
;
1119 char **error_message
;
1122 if (bfd_is_und_section (symbol
->section
)
1126 return bfd_reloc_undefined
;
1129 *pgp
= _bfd_get_gp_value (output_bfd
);
1132 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1136 /* Make up a value. */
1137 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1138 _bfd_set_gp_value (output_bfd
, *pgp
);
1146 count
= bfd_get_symcount (output_bfd
);
1147 sym
= bfd_get_outsymbols (output_bfd
);
1149 if (sym
== (asymbol
**) NULL
)
1153 for (i
= 0; i
< count
; i
++, sym
++)
1155 register CONST
char *name
;
1157 name
= bfd_asymbol_name (*sym
);
1158 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1160 *pgp
= bfd_asymbol_value (*sym
);
1161 _bfd_set_gp_value (output_bfd
, *pgp
);
1169 /* Only get the error once. */
1171 _bfd_set_gp_value (output_bfd
, *pgp
);
1173 (char *) _("GP relative relocation when _gp not defined");
1174 return bfd_reloc_dangerous
;
1179 return bfd_reloc_ok
;
1182 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1183 become the offset from the gp register. This function also handles
1184 R_MIPS_LITERAL relocations, although those can be handled more
1185 cleverly because the entries in the .lit8 and .lit4 sections can be
1188 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1189 arelent
*, asection
*,
1190 boolean
, PTR
, bfd_vma
));
1192 bfd_reloc_status_type
1193 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1194 output_bfd
, error_message
)
1196 arelent
*reloc_entry
;
1199 asection
*input_section
;
1201 char **error_message
;
1203 boolean relocateable
;
1204 bfd_reloc_status_type ret
;
1207 /* If we're relocating, and this is an external symbol with no
1208 addend, we don't want to change anything. We will only have an
1209 addend if this is a newly created reloc, not read from an ELF
1211 if (output_bfd
!= (bfd
*) NULL
1212 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1213 && reloc_entry
->addend
== 0)
1215 reloc_entry
->address
+= input_section
->output_offset
;
1216 return bfd_reloc_ok
;
1219 if (output_bfd
!= (bfd
*) NULL
)
1220 relocateable
= true;
1223 relocateable
= false;
1224 output_bfd
= symbol
->section
->output_section
->owner
;
1227 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1229 if (ret
!= bfd_reloc_ok
)
1232 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1233 relocateable
, data
, gp
);
1236 static bfd_reloc_status_type
1237 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1241 arelent
*reloc_entry
;
1242 asection
*input_section
;
1243 boolean relocateable
;
1251 if (bfd_is_com_section (symbol
->section
))
1254 relocation
= symbol
->value
;
1256 relocation
+= symbol
->section
->output_section
->vma
;
1257 relocation
+= symbol
->section
->output_offset
;
1259 if (reloc_entry
->address
> input_section
->_cooked_size
)
1260 return bfd_reloc_outofrange
;
1262 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1264 /* Set val to the offset into the section or symbol. */
1265 if (reloc_entry
->howto
->src_mask
== 0)
1267 /* This case occurs with the 64-bit MIPS ELF ABI. */
1268 val
= reloc_entry
->addend
;
1272 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1277 /* Adjust val for the final section location and GP value. If we
1278 are producing relocateable output, we don't want to do this for
1279 an external symbol. */
1281 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1282 val
+= relocation
- gp
;
1284 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1285 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1288 reloc_entry
->address
+= input_section
->output_offset
;
1290 /* Make sure it fit in 16 bits. */
1291 if (val
>= 0x8000 && val
< 0xffff8000)
1292 return bfd_reloc_overflow
;
1294 return bfd_reloc_ok
;
1297 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1298 from the gp register? XXX */
1300 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1301 arelent
*, asection
*,
1302 boolean
, PTR
, bfd_vma
));
1304 bfd_reloc_status_type
1305 _bfd_mips_elf_gprel32_reloc (abfd
,
1313 arelent
*reloc_entry
;
1316 asection
*input_section
;
1318 char **error_message
;
1320 boolean relocateable
;
1321 bfd_reloc_status_type ret
;
1324 /* If we're relocating, and this is an external symbol with no
1325 addend, we don't want to change anything. We will only have an
1326 addend if this is a newly created reloc, not read from an ELF
1328 if (output_bfd
!= (bfd
*) NULL
1329 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1330 && reloc_entry
->addend
== 0)
1332 *error_message
= (char *)
1333 _("32bits gp relative relocation occurs for an external symbol");
1334 return bfd_reloc_outofrange
;
1337 if (output_bfd
!= (bfd
*) NULL
)
1339 relocateable
= true;
1340 gp
= _bfd_get_gp_value (output_bfd
);
1344 relocateable
= false;
1345 output_bfd
= symbol
->section
->output_section
->owner
;
1347 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1348 error_message
, &gp
);
1349 if (ret
!= bfd_reloc_ok
)
1353 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1354 relocateable
, data
, gp
);
1357 static bfd_reloc_status_type
1358 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1362 arelent
*reloc_entry
;
1363 asection
*input_section
;
1364 boolean relocateable
;
1371 if (bfd_is_com_section (symbol
->section
))
1374 relocation
= symbol
->value
;
1376 relocation
+= symbol
->section
->output_section
->vma
;
1377 relocation
+= symbol
->section
->output_offset
;
1379 if (reloc_entry
->address
> input_section
->_cooked_size
)
1380 return bfd_reloc_outofrange
;
1382 if (reloc_entry
->howto
->src_mask
== 0)
1384 /* This case arises with the 64-bit MIPS ELF ABI. */
1388 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1390 /* Set val to the offset into the section or symbol. */
1391 val
+= reloc_entry
->addend
;
1393 /* Adjust val for the final section location and GP value. If we
1394 are producing relocateable output, we don't want to do this for
1395 an external symbol. */
1397 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1398 val
+= relocation
- gp
;
1400 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1403 reloc_entry
->address
+= input_section
->output_offset
;
1405 return bfd_reloc_ok
;
1408 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1409 generated when addreses are 64 bits. The upper 32 bits are a simle
1412 static bfd_reloc_status_type
1413 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1414 output_bfd
, error_message
)
1416 arelent
*reloc_entry
;
1419 asection
*input_section
;
1421 char **error_message
;
1423 bfd_reloc_status_type r
;
1428 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1429 input_section
, output_bfd
, error_message
);
1430 if (r
!= bfd_reloc_continue
)
1433 /* Do a normal 32 bit relocation on the lower 32 bits. */
1434 reloc32
= *reloc_entry
;
1435 if (bfd_big_endian (abfd
))
1436 reloc32
.address
+= 4;
1437 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1438 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1439 output_bfd
, error_message
);
1441 /* Sign extend into the upper 32 bits. */
1442 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1443 if ((val
& 0x80000000) != 0)
1447 addr
= reloc_entry
->address
;
1448 if (bfd_little_endian (abfd
))
1450 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1455 /* Handle a mips16 jump. */
1457 static bfd_reloc_status_type
1458 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1459 output_bfd
, error_message
)
1461 arelent
*reloc_entry
;
1464 asection
*input_section
;
1466 char **error_message
;
1468 if (output_bfd
!= (bfd
*) NULL
1469 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1470 && reloc_entry
->addend
== 0)
1472 reloc_entry
->address
+= input_section
->output_offset
;
1473 return bfd_reloc_ok
;
1478 static boolean warned
;
1481 (*_bfd_error_handler
)
1482 (_("Linking mips16 objects into %s format is not supported"),
1483 bfd_get_target (input_section
->output_section
->owner
));
1487 return bfd_reloc_undefined
;
1490 /* Handle a mips16 GP relative reloc. */
1492 static bfd_reloc_status_type
1493 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1494 output_bfd
, error_message
)
1496 arelent
*reloc_entry
;
1499 asection
*input_section
;
1501 char **error_message
;
1503 boolean relocateable
;
1504 bfd_reloc_status_type ret
;
1506 unsigned short extend
, insn
;
1507 unsigned long final
;
1509 /* If we're relocating, and this is an external symbol with no
1510 addend, we don't want to change anything. We will only have an
1511 addend if this is a newly created reloc, not read from an ELF
1513 if (output_bfd
!= NULL
1514 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1515 && reloc_entry
->addend
== 0)
1517 reloc_entry
->address
+= input_section
->output_offset
;
1518 return bfd_reloc_ok
;
1521 if (output_bfd
!= NULL
)
1522 relocateable
= true;
1525 relocateable
= false;
1526 output_bfd
= symbol
->section
->output_section
->owner
;
1529 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1531 if (ret
!= bfd_reloc_ok
)
1534 if (reloc_entry
->address
> input_section
->_cooked_size
)
1535 return bfd_reloc_outofrange
;
1537 /* Pick up the mips16 extend instruction and the real instruction. */
1538 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1539 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1541 /* Stuff the current addend back as a 32 bit value, do the usual
1542 relocation, and then clean up. */
1544 (((extend
& 0x1f) << 11)
1547 (bfd_byte
*) data
+ reloc_entry
->address
);
1549 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1550 relocateable
, data
, gp
);
1552 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1555 | ((final
>> 11) & 0x1f)
1557 (bfd_byte
*) data
+ reloc_entry
->address
);
1561 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1566 /* start-sanitize-sky */
1567 /* Handle a dvp R_MIPS_DVP_U15_S3 reloc.
1568 This is needed because the bits aren't contiguous. */
1570 static bfd_reloc_status_type
1571 dvp_u15_s3_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1572 output_bfd
, error_message
)
1574 arelent
*reloc_entry
;
1577 asection
*input_section
;
1579 char **error_message
;
1581 boolean relocateable
;
1582 bfd_reloc_status_type ret
;
1586 /* If we're relocating, and this is an external symbol with no
1587 addend, we don't want to change anything. We will only have an
1588 addend if this is a newly created reloc, not read from an ELF
1589 file. See bfd_elf_generic_reloc. */
1590 if (output_bfd
!= NULL
1591 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1592 /* partial_inplace is false, so this test always succeeds,
1593 but for clarity and consistency with bfd_elf_generic_reloc
1594 this is left as is. */
1595 && (! reloc_entry
->howto
->partial_inplace
1596 || reloc_entry
->addend
== 0))
1598 reloc_entry
->address
+= input_section
->output_offset
;
1599 return bfd_reloc_ok
;
1602 if (reloc_entry
->address
> input_section
->_cooked_size
)
1603 return bfd_reloc_outofrange
;
1605 relocation
= (symbol
->value
1606 + symbol
->section
->output_section
->vma
1607 + symbol
->section
->output_offset
);
1608 relocation
+= reloc_entry
->addend
;
1611 x
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1612 x
|= (((relocation
& 0x7800) << 10)
1613 | (relocation
& 0x7ff));
1614 bfd_put_32 (abfd
, x
, (bfd_byte
*) data
+ reloc_entry
->address
);
1616 if (relocation
& ~(bfd_vma
) 0x7fff)
1617 return bfd_reloc_overflow
;
1618 return bfd_reloc_ok
;
1621 /* end-sanitize-sky */
1622 /* Return the ISA for a MIPS e_flags value. */
1625 elf_mips_isa (flags
)
1628 switch (flags
& EF_MIPS_ARCH
)
1642 /* Return the MACH for a MIPS e_flags value. */
1645 elf_mips_mach (flags
)
1648 switch (flags
& EF_MIPS_MACH
)
1650 case E_MIPS_MACH_3900
:
1651 return bfd_mach_mips3900
;
1653 case E_MIPS_MACH_4010
:
1654 return bfd_mach_mips4010
;
1656 case E_MIPS_MACH_4100
:
1657 return bfd_mach_mips4100
;
1658 /* start-sanitize-vr4320 */
1660 case E_MIPS_MACH_4320
:
1661 return bfd_mach_mips4320
;
1662 /* end-sanitize-vr4320 */
1664 case E_MIPS_MACH_4650
:
1665 return bfd_mach_mips4650
;
1666 /* start-sanitize-tx49 */
1668 case E_MIPS_MACH_4900
:
1669 return bfd_mach_mips4900
;
1670 /* end-sanitize-tx49 */
1671 /* start-sanitize-vr5400 */
1673 case E_MIPS_MACH_5400
:
1674 return bfd_mach_mips5400
;
1675 /* end-sanitize-vr5400 */
1676 /* start-sanitize-r5900 */
1678 case E_MIPS_MACH_5900
:
1679 return bfd_mach_mips5900
;
1680 /* end-sanitize-r5900 */
1683 switch (flags
& EF_MIPS_ARCH
)
1687 return bfd_mach_mips3000
;
1691 return bfd_mach_mips6000
;
1695 return bfd_mach_mips4000
;
1699 return bfd_mach_mips8000
;
1707 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1709 struct elf_reloc_map
{
1710 bfd_reloc_code_real_type bfd_reloc_val
;
1711 enum elf_mips_reloc_type elf_reloc_val
;
1714 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1716 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1717 { BFD_RELOC_16
, R_MIPS_16
},
1718 { BFD_RELOC_32
, R_MIPS_32
},
1719 { BFD_RELOC_64
, R_MIPS_64
},
1720 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1721 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1722 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1723 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1724 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1725 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1726 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1727 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1728 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1729 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1730 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1731 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1732 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
},
1733 /* start-sanitize-r5900 */
1734 { BFD_RELOC_MIPS15_S3
, R_MIPS15_S3
},
1735 /* end-sanitize-r5900 */
1738 /* Given a BFD reloc type, return a howto structure. */
1740 static reloc_howto_type
*
1741 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1743 bfd_reloc_code_real_type code
;
1747 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1749 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1750 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1755 case BFD_RELOC_CTOR
:
1756 /* We need to handle BFD_RELOC_CTOR specially.
1757 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1758 size of addresses on this architecture. */
1759 if (bfd_arch_bits_per_address (abfd
) == 32)
1760 return &elf_mips_howto_table
[(int) R_MIPS_32
];
1762 return &elf_mips_ctor64_howto
;
1764 case BFD_RELOC_MIPS16_JMP
:
1765 return &elf_mips16_jump_howto
;
1766 case BFD_RELOC_MIPS16_GPREL
:
1767 return &elf_mips16_gprel_howto
;
1768 /* start-sanitize-sky */
1769 case BFD_RELOC_MIPS_DVP_11_PCREL
:
1770 return &elf_mips_dvp_11_pcrel_howto
;
1771 case BFD_RELOC_MIPS_DVP_27_S4
:
1772 return &elf_mips_dvp_27_s4_howto
;
1773 case BFD_RELOC_MIPS_DVP_11_S4
:
1774 return &elf_mips_dvp_11_s4_howto
;
1775 case BFD_RELOC_MIPS_DVP_U15_S3
:
1776 return &elf_mips_dvp_u15_s3_howto
;
1777 /* end-sanitize-sky */
1778 case BFD_RELOC_VTABLE_INHERIT
:
1779 return &elf_mips_gnu_vtinherit_howto
;
1780 case BFD_RELOC_VTABLE_ENTRY
:
1781 return &elf_mips_gnu_vtentry_howto
;
1787 /* Given a MIPS reloc type, fill in an arelent structure. */
1790 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1793 Elf32_Internal_Rel
*dst
;
1795 unsigned int r_type
;
1797 r_type
= ELF32_R_TYPE (dst
->r_info
);
1801 cache_ptr
->howto
= &elf_mips16_jump_howto
;
1803 case R_MIPS16_GPREL
:
1804 cache_ptr
->howto
= &elf_mips16_gprel_howto
;
1806 /* start-sanitize-sky */
1807 case R_MIPS_DVP_11_PCREL
:
1808 cache_ptr
->howto
= &elf_mips_dvp_11_pcrel_howto
;
1810 case R_MIPS_DVP_27_S4
:
1811 cache_ptr
->howto
= &elf_mips_dvp_27_s4_howto
;
1813 case R_MIPS_DVP_11_S4
:
1814 cache_ptr
->howto
= &elf_mips_dvp_11_s4_howto
;
1816 case R_MIPS_DVP_U15_S3
:
1817 cache_ptr
->howto
= &elf_mips_dvp_u15_s3_howto
;
1819 /* end-sanitize-sky */
1820 case R_MIPS_GNU_VTINHERIT
:
1821 cache_ptr
->howto
= &elf_mips_gnu_vtinherit_howto
;
1823 case R_MIPS_GNU_VTENTRY
:
1824 cache_ptr
->howto
= &elf_mips_gnu_vtentry_howto
;
1828 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1829 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1833 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1834 value for the object file. We get the addend now, rather than
1835 when we do the relocation, because the symbol manipulations done
1836 by the linker may cause us to lose track of the input BFD. */
1837 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1838 && (r_type
== (unsigned int) R_MIPS_GPREL16
1839 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1840 cache_ptr
->addend
= elf_gp (abfd
);
1843 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1844 routines swap this structure in and out. They are used outside of
1845 BFD, so they are globally visible. */
1848 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1850 const Elf32_External_RegInfo
*ex
;
1853 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1854 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1855 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1856 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1857 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1858 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1862 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1864 const Elf32_RegInfo
*in
;
1865 Elf32_External_RegInfo
*ex
;
1867 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1868 (bfd_byte
*) ex
->ri_gprmask
);
1869 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1870 (bfd_byte
*) ex
->ri_cprmask
[0]);
1871 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1872 (bfd_byte
*) ex
->ri_cprmask
[1]);
1873 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1874 (bfd_byte
*) ex
->ri_cprmask
[2]);
1875 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1876 (bfd_byte
*) ex
->ri_cprmask
[3]);
1877 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1878 (bfd_byte
*) ex
->ri_gp_value
);
1881 /* In the 64 bit ABI, the .MIPS.options section holds register
1882 information in an Elf64_Reginfo structure. These routines swap
1883 them in and out. They are globally visible because they are used
1884 outside of BFD. These routines are here so that gas can call them
1885 without worrying about whether the 64 bit ABI has been included. */
1888 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1890 const Elf64_External_RegInfo
*ex
;
1891 Elf64_Internal_RegInfo
*in
;
1893 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1894 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
1895 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1896 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1897 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1898 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1899 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1903 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1905 const Elf64_Internal_RegInfo
*in
;
1906 Elf64_External_RegInfo
*ex
;
1908 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1909 (bfd_byte
*) ex
->ri_gprmask
);
1910 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
1911 (bfd_byte
*) ex
->ri_pad
);
1912 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1913 (bfd_byte
*) ex
->ri_cprmask
[0]);
1914 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1915 (bfd_byte
*) ex
->ri_cprmask
[1]);
1916 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1917 (bfd_byte
*) ex
->ri_cprmask
[2]);
1918 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1919 (bfd_byte
*) ex
->ri_cprmask
[3]);
1920 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1921 (bfd_byte
*) ex
->ri_gp_value
);
1924 /* Swap an entry in a .gptab section. Note that these routines rely
1925 on the equivalence of the two elements of the union. */
1928 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1930 const Elf32_External_gptab
*ex
;
1933 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1934 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1938 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1940 const Elf32_gptab
*in
;
1941 Elf32_External_gptab
*ex
;
1943 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1944 ex
->gt_entry
.gt_g_value
);
1945 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1946 ex
->gt_entry
.gt_bytes
);
1950 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1952 const Elf32_compact_rel
*in
;
1953 Elf32_External_compact_rel
*ex
;
1955 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
1956 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
1957 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
1958 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
1959 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
1960 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
1964 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1966 const Elf32_crinfo
*in
;
1967 Elf32_External_crinfo
*ex
;
1971 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1972 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1973 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1974 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1975 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
1976 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
1977 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
1980 /* Swap in an options header. */
1983 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1985 const Elf_External_Options
*ex
;
1986 Elf_Internal_Options
*in
;
1988 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
1989 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
1990 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
1991 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
1994 /* Swap out an options header. */
1997 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
1999 const Elf_Internal_Options
*in
;
2000 Elf_External_Options
*ex
;
2002 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
2003 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
2004 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
2005 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
2008 /* Determine whether a symbol is global for the purposes of splitting
2009 the symbol table into global symbols and local symbols. At least
2010 on Irix 5, this split must be between section symbols and all other
2011 symbols. On most ELF targets the split is between static symbols
2012 and externally visible symbols. */
2016 mips_elf_sym_is_global (abfd
, sym
)
2020 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
2023 /* Set the right machine number for a MIPS ELF file. This is used for
2024 both the 32-bit and the 64-bit ABI. */
2027 _bfd_mips_elf_object_p (abfd
)
2030 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
,
2031 elf_mips_mach (elf_elfheader (abfd
)->e_flags
));
2035 /* Set the right machine number for a 32-bit MIPS ELF file. */
2038 mips_elf32_object_p (abfd
)
2041 /* Irix 5 is broken. Object file symbol tables are not always
2042 sorted correctly such that local symbols precede global symbols,
2043 and the sh_info field in the symbol table is not always right. */
2044 elf_bad_symtab (abfd
) = true;
2046 return _bfd_mips_elf_object_p (abfd
);
2049 /* The final processing done just before writing out a MIPS ELF object
2050 file. This gets the MIPS architecture right based on the machine
2051 number. This is used by both the 32-bit and the 64-bit ABI. */
2055 _bfd_mips_elf_final_write_processing (abfd
, linker
)
2061 Elf_Internal_Shdr
**hdrpp
;
2065 switch (bfd_get_mach (abfd
))
2068 case bfd_mach_mips3000
:
2069 val
= E_MIPS_ARCH_1
;
2072 case bfd_mach_mips3900
:
2073 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
2076 case bfd_mach_mips6000
:
2077 val
= E_MIPS_ARCH_2
;
2080 case bfd_mach_mips4000
:
2081 val
= E_MIPS_ARCH_3
;
2084 case bfd_mach_mips4010
:
2085 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
2088 case bfd_mach_mips4100
:
2089 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
2091 /* start-sanitize-vr4320 */
2093 case bfd_mach_mips4320
:
2094 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4320
;
2096 /* end-sanitize-vr4320 */
2098 case bfd_mach_mips4650
:
2099 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
2101 /* start-sanitize-tx49 */
2103 case bfd_mach_mips4900
:
2104 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4900
;
2106 /* end-sanitize-tx49 */
2107 /* start-sanitize-vr5400 */
2109 case bfd_mach_mips5400
:
2110 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_5400
;
2112 /* end-sanitize-vr5400 */
2113 /* start-sanitize-r5900 */
2115 case bfd_mach_mips5900
:
2116 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_5900
;
2118 /* end-sanitize-r5900 */
2120 case bfd_mach_mips8000
:
2121 val
= E_MIPS_ARCH_4
;
2125 elf_elfheader (abfd
)->e_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2126 elf_elfheader (abfd
)->e_flags
|= val
;
2128 /* Set the sh_info field for .gptab sections and other appropriate
2129 info for each special section. */
2130 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
2131 i
< elf_elfheader (abfd
)->e_shnum
;
2134 switch ((*hdrpp
)->sh_type
)
2136 case SHT_MIPS_LIBLIST
:
2137 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
2139 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2142 case SHT_MIPS_GPTAB
:
2143 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2144 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2145 BFD_ASSERT (name
!= NULL
2146 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
2147 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
2148 BFD_ASSERT (sec
!= NULL
);
2149 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2152 case SHT_MIPS_CONTENT
:
2153 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2154 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2155 BFD_ASSERT (name
!= NULL
2156 && strncmp (name
, ".MIPS.content",
2157 sizeof ".MIPS.content" - 1) == 0);
2158 sec
= bfd_get_section_by_name (abfd
,
2159 name
+ sizeof ".MIPS.content" - 1);
2160 BFD_ASSERT (sec
!= NULL
);
2161 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2164 case SHT_MIPS_SYMBOL_LIB
:
2165 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
2167 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2168 sec
= bfd_get_section_by_name (abfd
, ".liblist");
2170 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2173 case SHT_MIPS_EVENTS
:
2174 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2175 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2176 BFD_ASSERT (name
!= NULL
);
2177 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
2178 sec
= bfd_get_section_by_name (abfd
,
2179 name
+ sizeof ".MIPS.events" - 1);
2182 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
2183 sizeof ".MIPS.post_rel" - 1) == 0);
2184 sec
= bfd_get_section_by_name (abfd
,
2186 + sizeof ".MIPS.post_rel" - 1));
2188 BFD_ASSERT (sec
!= NULL
);
2189 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2192 /* start-sanitize-sky */
2193 case SHT_DVP_OVERLAY_TABLE
:
2194 /* ??? This may not be technically necessary, just going with
2196 sec
= bfd_get_section_by_name (abfd
, SHNAME_DVP_OVERLAY_STRTAB
);
2198 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2200 /* end-sanitize-sky */
2205 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
2208 _bfd_mips_elf_set_private_flags (abfd
, flags
)
2212 BFD_ASSERT (!elf_flags_init (abfd
)
2213 || elf_elfheader (abfd
)->e_flags
== flags
);
2215 elf_elfheader (abfd
)->e_flags
= flags
;
2216 elf_flags_init (abfd
) = true;
2220 /* Copy backend specific data from one object module to another */
2223 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
2227 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2228 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2231 BFD_ASSERT (!elf_flags_init (obfd
)
2232 || (elf_elfheader (obfd
)->e_flags
2233 == elf_elfheader (ibfd
)->e_flags
));
2235 elf_gp (obfd
) = elf_gp (ibfd
);
2236 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
2237 elf_flags_init (obfd
) = true;
2241 /* Merge backend specific data from an object file to the output
2242 object file when linking. */
2245 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
2253 /* Check if we have the same endianess */
2254 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2255 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2259 if (bfd_big_endian (ibfd
))
2260 msg
= _("%s: compiled for a big endian system and target is little endian");
2262 msg
= _("%s: compiled for a little endian system and target is big endian");
2264 (*_bfd_error_handler
) (msg
, bfd_get_filename (ibfd
));
2266 bfd_set_error (bfd_error_wrong_format
);
2270 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2271 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2274 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2275 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
2276 old_flags
= elf_elfheader (obfd
)->e_flags
;
2278 if (! elf_flags_init (obfd
))
2280 elf_flags_init (obfd
) = true;
2281 elf_elfheader (obfd
)->e_flags
= new_flags
;
2283 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2284 && bfd_get_arch_info (obfd
)->the_default
)
2286 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
2287 bfd_get_mach (ibfd
)))
2294 /* Check flag compatibility. */
2296 new_flags
&= ~EF_MIPS_NOREORDER
;
2297 old_flags
&= ~EF_MIPS_NOREORDER
;
2299 if (new_flags
== old_flags
)
2304 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
2306 new_flags
&= ~EF_MIPS_PIC
;
2307 old_flags
&= ~EF_MIPS_PIC
;
2308 (*_bfd_error_handler
)
2309 (_("%s: linking PIC files with non-PIC files"),
2310 bfd_get_filename (ibfd
));
2314 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
2316 new_flags
&= ~EF_MIPS_CPIC
;
2317 old_flags
&= ~EF_MIPS_CPIC
;
2318 (*_bfd_error_handler
)
2319 (_("%s: linking abicalls files with non-abicalls files"),
2320 bfd_get_filename (ibfd
));
2324 /* Compare the ISA's. */
2325 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
2326 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
2328 /* If either has no machine specified, just compare the general isa's. */
2329 if ( !(new_flags
& EF_MIPS_MACH
) || !(old_flags
& EF_MIPS_MACH
))
2331 int new_isa
, old_isa
;
2333 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
2334 and -mips4 code. They will normally use the same data sizes and
2335 calling conventions. */
2337 new_isa
= elf_mips_isa (new_flags
);
2338 old_isa
= elf_mips_isa (old_flags
);
2339 if ((new_isa
== 1 || new_isa
== 2)
2340 ? (old_isa
!= 1 && old_isa
!= 2)
2341 : (old_isa
== 1 || old_isa
== 2))
2343 (*_bfd_error_handler
)
2344 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
2345 bfd_get_filename (ibfd
), new_isa
, old_isa
);
2352 (*_bfd_error_handler
)
2353 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
2354 bfd_get_filename (ibfd
),
2355 elf_mips_mach (new_flags
),
2356 elf_mips_mach (old_flags
));
2360 new_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2361 old_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2364 /* Warn about any other mismatches */
2365 if (new_flags
!= old_flags
)
2367 (*_bfd_error_handler
)
2368 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2369 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
2370 (unsigned long) old_flags
);
2376 bfd_set_error (bfd_error_bad_value
);
2383 /* Handle a MIPS specific section when reading an object file. This
2384 is called when elfcode.h finds a section with an unknown type.
2385 This routine supports both the 32-bit and 64-bit ELF ABI.
2387 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2391 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
2393 Elf_Internal_Shdr
*hdr
;
2396 /* There ought to be a place to keep ELF backend specific flags, but
2397 at the moment there isn't one. We just keep track of the
2398 sections by their name, instead. Fortunately, the ABI gives
2399 suggested names for all the MIPS specific sections, so we will
2400 probably get away with this. */
2401 switch (hdr
->sh_type
)
2403 case SHT_MIPS_LIBLIST
:
2404 if (strcmp (name
, _(".liblist")) != 0)
2408 if (strcmp (name
, ".msym") != 0)
2411 case SHT_MIPS_CONFLICT
:
2412 if (strcmp (name
, ".conflict") != 0)
2415 case SHT_MIPS_GPTAB
:
2416 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
2419 case SHT_MIPS_UCODE
:
2420 if (strcmp (name
, ".ucode") != 0)
2423 case SHT_MIPS_DEBUG
:
2424 if (strcmp (name
, ".mdebug") != 0)
2427 case SHT_MIPS_REGINFO
:
2428 if (strcmp (name
, ".reginfo") != 0
2429 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
2432 case SHT_MIPS_IFACE
:
2433 if (strcmp (name
, ".MIPS.interfaces") != 0)
2436 case SHT_MIPS_CONTENT
:
2437 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2440 case SHT_MIPS_OPTIONS
:
2441 if (strcmp (name
, ".options") != 0
2442 && strcmp (name
, ".MIPS.options") != 0)
2445 case SHT_MIPS_DWARF
:
2446 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2449 case SHT_MIPS_SYMBOL_LIB
:
2450 if (strcmp (name
, ".MIPS.symlib") != 0)
2453 case SHT_MIPS_EVENTS
:
2454 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2455 && strncmp (name
, ".MIPS.post_rel",
2456 sizeof ".MIPS.post_rel" - 1) != 0)
2459 /* start-sanitize-sky */
2460 case SHT_DVP_OVERLAY_TABLE
:
2461 if (strcmp (name
, SHNAME_DVP_OVERLAY_TABLE
) !=0)
2464 case SHT_DVP_OVERLAY
:
2465 if (strncmp (name
, SHNAME_DVP_OVERLAY_PREFIX
,
2466 sizeof (SHNAME_DVP_OVERLAY_PREFIX
) - 1) !=0)
2469 /* end-sanitize-sky */
2474 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2477 if (hdr
->sh_type
== SHT_MIPS_DEBUG
)
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
, ".msym") == 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 /* Force the section size to the correct value, even if the
2619 linker thinks it is larger. The link routine below will only
2620 write out this much data for .reginfo. */
2621 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf32_External_RegInfo
);
2623 else if (SGI_COMPAT (abfd
)
2624 && (strcmp (name
, ".hash") == 0
2625 || strcmp (name
, ".dynamic") == 0
2626 || strcmp (name
, ".dynstr") == 0))
2628 hdr
->sh_entsize
= 0;
2629 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2631 else if (strcmp (name
, ".got") == 0
2632 || strcmp (name
, ".sdata") == 0
2633 || strcmp (name
, ".sbss") == 0
2634 || strcmp (name
, ".lit4") == 0
2635 || strcmp (name
, ".lit8") == 0)
2636 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2637 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2639 hdr
->sh_type
= SHT_MIPS_IFACE
;
2640 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2642 else if (strcmp (name
, ".MIPS.content") == 0)
2644 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2645 /* The sh_info field is set in final_write_processing. */
2647 else if (strcmp (name
, ".options") == 0
2648 || strcmp (name
, ".MIPS.options") == 0)
2650 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2651 hdr
->sh_entsize
= 1;
2652 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2654 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2655 hdr
->sh_type
= SHT_MIPS_DWARF
;
2656 else if (strcmp (name
, ".MIPS.symlib") == 0)
2658 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2659 /* The sh_link and sh_info fields are set in
2660 final_write_processing. */
2662 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2663 || strncmp (name
, ".MIPS.post_rel",
2664 sizeof ".MIPS.post_rel" - 1) == 0)
2666 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2667 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2668 /* The sh_link field is set in final_write_processing. */
2670 /* start-sanitize-sky */
2671 else if (strcmp (name
, SHNAME_DVP_OVERLAY_TABLE
) == 0)
2673 hdr
->sh_type
= SHT_DVP_OVERLAY_TABLE
;
2674 hdr
->sh_entsize
= sizeof (Elf32_Dvp_External_Overlay
);
2675 /* The sh_link field is set in final_write_processing. */
2677 else if (strcmp (name
, SHNAME_DVP_OVERLAY_STRTAB
) == 0)
2678 hdr
->sh_type
= SHT_STRTAB
;
2679 else if (strncmp (name
, SHNAME_DVP_OVERLAY_PREFIX
,
2680 sizeof (SHNAME_DVP_OVERLAY_PREFIX
) - 1) == 0)
2681 hdr
->sh_type
= SHT_DVP_OVERLAY
;
2682 /* end-sanitize-sky */
2687 /* Given a BFD section, try to locate the corresponding ELF section
2688 index. This is used by both the 32-bit and the 64-bit ABI.
2689 Actually, it's not clear to me that the 64-bit ABI supports these,
2690 but for non-PIC objects we will certainly want support for at least
2691 the .scommon section. */
2694 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2696 Elf32_Internal_Shdr
*hdr
;
2700 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2702 *retval
= SHN_MIPS_SCOMMON
;
2705 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2707 *retval
= SHN_MIPS_ACOMMON
;
2713 /* When are writing out the .options or .MIPS.options section,
2714 remember the bytes we are writing out, so that we can install the
2715 GP value in the section_processing routine. */
2718 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2723 bfd_size_type count
;
2725 if (strcmp (section
->name
, ".options") == 0
2726 || strcmp (section
->name
, ".MIPS.options") == 0)
2730 if (elf_section_data (section
) == NULL
)
2732 section
->used_by_bfd
=
2733 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
2734 if (elf_section_data (section
) == NULL
)
2737 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
2742 if (section
->_cooked_size
!= 0)
2743 size
= section
->_cooked_size
;
2745 size
= section
->_raw_size
;
2746 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
2749 elf_section_data (section
)->tdata
= (PTR
) c
;
2752 memcpy (c
+ offset
, location
, count
);
2755 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
2759 /* Work over a section just before writing it out. This routine is
2760 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2761 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2765 _bfd_mips_elf_section_processing (abfd
, hdr
)
2767 Elf_Internal_Shdr
*hdr
;
2769 if (hdr
->bfd_section
!= NULL
)
2771 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
2773 if (strcmp (name
, ".sdata") == 0)
2775 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2776 hdr
->sh_type
= SHT_PROGBITS
;
2778 else if (strcmp (name
, ".sbss") == 0)
2780 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2781 hdr
->sh_type
= SHT_NOBITS
;
2783 else if (strcmp (name
, ".lit8") == 0
2784 || strcmp (name
, ".lit4") == 0)
2786 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2787 hdr
->sh_type
= SHT_PROGBITS
;
2789 else if (strcmp (name
, ".compact_rel") == 0)
2792 hdr
->sh_type
= SHT_PROGBITS
;
2794 else if (strcmp (name
, ".rtproc") == 0)
2796 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
2798 unsigned int adjust
;
2800 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
2802 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
2810 /* Work over a section just before writing it out. We update the GP
2811 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2812 on the value we are using. */
2815 mips_elf32_section_processing (abfd
, hdr
)
2817 Elf32_Internal_Shdr
*hdr
;
2819 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2823 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2824 BFD_ASSERT (hdr
->contents
== NULL
);
2827 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2830 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2831 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2835 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2836 && hdr
->bfd_section
!= NULL
2837 && elf_section_data (hdr
->bfd_section
) != NULL
2838 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2840 bfd_byte
*contents
, *l
, *lend
;
2842 /* We stored the section contents in the elf_section_data tdata
2843 field in the set_section_contents routine. We save the
2844 section contents so that we don't have to read them again.
2845 At this point we know that elf_gp is set, so we can look
2846 through the section contents to see if there is an
2847 ODK_REGINFO structure. */
2849 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2851 lend
= contents
+ hdr
->sh_size
;
2852 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2854 Elf_Internal_Options intopt
;
2856 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2858 if (intopt
.kind
== ODK_REGINFO
)
2865 + sizeof (Elf_External_Options
)
2866 + (sizeof (Elf32_External_RegInfo
) - 4)),
2869 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
2870 if (bfd_write (buf
, 1, 4, abfd
) != 4)
2877 return _bfd_mips_elf_section_processing (abfd
, hdr
);
2880 /* MIPS ELF uses two common sections. One is the usual one, and the
2881 other is for small objects. All the small objects are kept
2882 together, and then referenced via the gp pointer, which yields
2883 faster assembler code. This is what we use for the small common
2884 section. This approach is copied from ecoff.c. */
2885 static asection mips_elf_scom_section
;
2886 static asymbol mips_elf_scom_symbol
;
2887 static asymbol
*mips_elf_scom_symbol_ptr
;
2889 /* MIPS ELF also uses an acommon section, which represents an
2890 allocated common symbol which may be overridden by a
2891 definition in a shared library. */
2892 static asection mips_elf_acom_section
;
2893 static asymbol mips_elf_acom_symbol
;
2894 static asymbol
*mips_elf_acom_symbol_ptr
;
2896 /* The Irix 5 support uses two virtual sections, which represent
2897 text/data symbols defined in dynamic objects. */
2898 static asection mips_elf_text_section
;
2899 static asection
*mips_elf_text_section_ptr
;
2900 static asymbol mips_elf_text_symbol
;
2901 static asymbol
*mips_elf_text_symbol_ptr
;
2903 static asection mips_elf_data_section
;
2904 static asection
*mips_elf_data_section_ptr
;
2905 static asymbol mips_elf_data_symbol
;
2906 static asymbol
*mips_elf_data_symbol_ptr
;
2908 /* Handle the special MIPS section numbers that a symbol may use.
2909 This is used for both the 32-bit and the 64-bit ABI. */
2912 _bfd_mips_elf_symbol_processing (abfd
, asym
)
2916 elf_symbol_type
*elfsym
;
2918 elfsym
= (elf_symbol_type
*) asym
;
2919 switch (elfsym
->internal_elf_sym
.st_shndx
)
2921 case SHN_MIPS_ACOMMON
:
2922 /* This section is used in a dynamically linked executable file.
2923 It is an allocated common section. The dynamic linker can
2924 either resolve these symbols to something in a shared
2925 library, or it can just leave them here. For our purposes,
2926 we can consider these symbols to be in a new section. */
2927 if (mips_elf_acom_section
.name
== NULL
)
2929 /* Initialize the acommon section. */
2930 mips_elf_acom_section
.name
= ".acommon";
2931 mips_elf_acom_section
.flags
= SEC_ALLOC
;
2932 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
2933 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
2934 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
2935 mips_elf_acom_symbol
.name
= ".acommon";
2936 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
2937 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
2938 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
2940 asym
->section
= &mips_elf_acom_section
;
2944 /* Common symbols less than the GP size are automatically
2945 treated as SHN_MIPS_SCOMMON symbols. */
2946 if (asym
->value
> elf_gp_size (abfd
))
2949 case SHN_MIPS_SCOMMON
:
2950 if (mips_elf_scom_section
.name
== NULL
)
2952 /* Initialize the small common section. */
2953 mips_elf_scom_section
.name
= ".scommon";
2954 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
2955 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
2956 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
2957 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
2958 mips_elf_scom_symbol
.name
= ".scommon";
2959 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2960 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
2961 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
2963 asym
->section
= &mips_elf_scom_section
;
2964 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2967 case SHN_MIPS_SUNDEFINED
:
2968 asym
->section
= bfd_und_section_ptr
;
2971 #if 0 /* for SGI_COMPAT */
2973 asym
->section
= mips_elf_text_section_ptr
;
2977 asym
->section
= mips_elf_data_section_ptr
;
2983 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
2987 mips_elf_additional_program_headers (abfd
)
2995 if (! SGI_COMPAT (abfd
))
2998 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2999 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3001 /* We need a PT_MIPS_REGINFO segment. */
3005 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3006 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3008 /* We need a PT_MIPS_RTPROC segment. */
3015 /* Modify the segment map for an Irix 5 executable. */
3018 mips_elf_modify_segment_map (abfd
)
3022 struct elf_segment_map
*m
, **pm
;
3024 if (! SGI_COMPAT (abfd
))
3027 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
3029 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3030 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3032 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3033 if (m
->p_type
== PT_MIPS_REGINFO
)
3037 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3041 m
->p_type
= PT_MIPS_REGINFO
;
3045 /* We want to put it after the PHDR and INTERP segments. */
3046 pm
= &elf_tdata (abfd
)->segment_map
;
3048 && ((*pm
)->p_type
== PT_PHDR
3049 || (*pm
)->p_type
== PT_INTERP
))
3057 /* If there are .dynamic and .mdebug sections, we make a room for
3058 the RTPROC header. FIXME: Rewrite without section names. */
3059 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
3060 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3061 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3063 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3064 if (m
->p_type
== PT_MIPS_RTPROC
)
3068 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3072 m
->p_type
= PT_MIPS_RTPROC
;
3074 s
= bfd_get_section_by_name (abfd
, ".rtproc");
3079 m
->p_flags_valid
= 1;
3087 /* We want to put it after the DYNAMIC segment. */
3088 pm
= &elf_tdata (abfd
)->segment_map
;
3089 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
3099 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
3100 .dynsym, and .hash sections, and everything in between. */
3101 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
3102 if ((*pm
)->p_type
== PT_DYNAMIC
)
3107 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
3109 static const char *sec_names
[] =
3110 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
3113 struct elf_segment_map
*n
;
3117 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
3119 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
3120 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3126 sz
= s
->_cooked_size
;
3129 if (high
< s
->vma
+ sz
)
3135 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3136 if ((s
->flags
& SEC_LOAD
) != 0
3139 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3143 n
= ((struct elf_segment_map
*)
3144 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
3151 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3153 if ((s
->flags
& SEC_LOAD
) != 0
3156 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3170 /* The structure of the runtime procedure descriptor created by the
3171 loader for use by the static exception system. */
3173 typedef struct runtime_pdr
{
3174 bfd_vma adr
; /* memory address of start of procedure */
3175 long regmask
; /* save register mask */
3176 long regoffset
; /* save register offset */
3177 long fregmask
; /* save floating point register mask */
3178 long fregoffset
; /* save floating point register offset */
3179 long frameoffset
; /* frame size */
3180 short framereg
; /* frame pointer register */
3181 short pcreg
; /* offset or reg of return pc */
3182 long irpss
; /* index into the runtime string table */
3184 struct exception_info
*exception_info
;/* pointer to exception array */
3186 #define cbRPDR sizeof(RPDR)
3187 #define rpdNil ((pRPDR) 0)
3189 /* Swap RPDR (runtime procedure table entry) for output. */
3191 static void ecoff_swap_rpdr_out
3192 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
3195 ecoff_swap_rpdr_out (abfd
, in
, ex
)
3198 struct rpdr_ext
*ex
;
3200 /* ecoff_put_off was defined in ecoffswap.h. */
3201 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
3202 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
3203 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
3204 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
3205 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
3206 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
3208 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
3209 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
3211 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
3213 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
3217 /* Read ECOFF debugging information from a .mdebug section into a
3218 ecoff_debug_info structure. */
3221 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
3224 struct ecoff_debug_info
*debug
;
3227 const struct ecoff_debug_swap
*swap
;
3228 char *ext_hdr
= NULL
;
3230 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3232 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
3233 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
3236 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
3237 swap
->external_hdr_size
)
3241 symhdr
= &debug
->symbolic_header
;
3242 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
3244 /* The symbolic header contains absolute file offsets and sizes to
3246 #define READ(ptr, offset, count, size, type) \
3247 if (symhdr->count == 0) \
3248 debug->ptr = NULL; \
3251 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
3252 if (debug->ptr == NULL) \
3253 goto error_return; \
3254 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3255 || (bfd_read (debug->ptr, size, symhdr->count, \
3256 abfd) != size * symhdr->count)) \
3257 goto error_return; \
3260 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
3261 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
3262 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
3263 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
3264 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
3265 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
3267 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
3268 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
3269 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
3270 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
3271 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
3275 debug
->adjust
= NULL
;
3280 if (ext_hdr
!= NULL
)
3282 if (debug
->line
!= NULL
)
3284 if (debug
->external_dnr
!= NULL
)
3285 free (debug
->external_dnr
);
3286 if (debug
->external_pdr
!= NULL
)
3287 free (debug
->external_pdr
);
3288 if (debug
->external_sym
!= NULL
)
3289 free (debug
->external_sym
);
3290 if (debug
->external_opt
!= NULL
)
3291 free (debug
->external_opt
);
3292 if (debug
->external_aux
!= NULL
)
3293 free (debug
->external_aux
);
3294 if (debug
->ss
!= NULL
)
3296 if (debug
->ssext
!= NULL
)
3297 free (debug
->ssext
);
3298 if (debug
->external_fdr
!= NULL
)
3299 free (debug
->external_fdr
);
3300 if (debug
->external_rfd
!= NULL
)
3301 free (debug
->external_rfd
);
3302 if (debug
->external_ext
!= NULL
)
3303 free (debug
->external_ext
);
3307 /* MIPS ELF local labels start with '$', not 'L'. */
3311 mips_elf_is_local_label_name (abfd
, name
)
3318 /* On Irix 6, the labels go back to starting with '.', so we accept
3319 the generic ELF local label syntax as well. */
3320 return _bfd_elf_is_local_label_name (abfd
, name
);
3323 /* MIPS ELF uses a special find_nearest_line routine in order the
3324 handle the ECOFF debugging information. */
3326 struct mips_elf_find_line
3328 struct ecoff_debug_info d
;
3329 struct ecoff_find_line i
;
3333 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
3334 functionname_ptr
, line_ptr
)
3339 const char **filename_ptr
;
3340 const char **functionname_ptr
;
3341 unsigned int *line_ptr
;
3345 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3346 filename_ptr
, functionname_ptr
,
3350 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
3354 struct mips_elf_find_line
*fi
;
3355 const struct ecoff_debug_swap
* const swap
=
3356 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3358 /* If we are called during a link, mips_elf_final_link may have
3359 cleared the SEC_HAS_CONTENTS field. We force it back on here
3360 if appropriate (which it normally will be). */
3361 origflags
= msec
->flags
;
3362 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
3363 msec
->flags
|= SEC_HAS_CONTENTS
;
3365 fi
= elf_tdata (abfd
)->find_line_info
;
3368 bfd_size_type external_fdr_size
;
3371 struct fdr
*fdr_ptr
;
3373 fi
= ((struct mips_elf_find_line
*)
3374 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
3377 msec
->flags
= origflags
;
3381 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
3383 msec
->flags
= origflags
;
3387 /* Swap in the FDR information. */
3388 fi
->d
.fdr
= ((struct fdr
*)
3390 (fi
->d
.symbolic_header
.ifdMax
*
3391 sizeof (struct fdr
))));
3392 if (fi
->d
.fdr
== NULL
)
3394 msec
->flags
= origflags
;
3397 external_fdr_size
= swap
->external_fdr_size
;
3398 fdr_ptr
= fi
->d
.fdr
;
3399 fraw_src
= (char *) fi
->d
.external_fdr
;
3400 fraw_end
= (fraw_src
3401 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
3402 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
3403 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
3405 elf_tdata (abfd
)->find_line_info
= fi
;
3407 /* Note that we don't bother to ever free this information.
3408 find_nearest_line is either called all the time, as in
3409 objdump -l, so the information should be saved, or it is
3410 rarely called, as in ld error messages, so the memory
3411 wasted is unimportant. Still, it would probably be a
3412 good idea for free_cached_info to throw it away. */
3415 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
3416 &fi
->i
, filename_ptr
, functionname_ptr
,
3419 msec
->flags
= origflags
;
3423 msec
->flags
= origflags
;
3426 /* Fall back on the generic ELF find_nearest_line routine. */
3428 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
3429 filename_ptr
, functionname_ptr
,
3433 /* The mips16 compiler uses a couple of special sections to handle
3434 floating point arguments.
3436 Section names that look like .mips16.fn.FNNAME contain stubs that
3437 copy floating point arguments from the fp regs to the gp regs and
3438 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3439 call should be redirected to the stub instead. If no 32 bit
3440 function calls FNNAME, the stub should be discarded. We need to
3441 consider any reference to the function, not just a call, because
3442 if the address of the function is taken we will need the stub,
3443 since the address might be passed to a 32 bit function.
3445 Section names that look like .mips16.call.FNNAME contain stubs
3446 that copy floating point arguments from the gp regs to the fp
3447 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3448 then any 16 bit function that calls FNNAME should be redirected
3449 to the stub instead. If FNNAME is not a 32 bit function, the
3450 stub should be discarded.
3452 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3453 which call FNNAME and then copy the return value from the fp regs
3454 to the gp regs. These stubs store the return value in $18 while
3455 calling FNNAME; any function which might call one of these stubs
3456 must arrange to save $18 around the call. (This case is not
3457 needed for 32 bit functions that call 16 bit functions, because
3458 16 bit functions always return floating point values in both
3461 Note that in all cases FNNAME might be defined statically.
3462 Therefore, FNNAME is not used literally. Instead, the relocation
3463 information will indicate which symbol the section is for.
3465 We record any stubs that we find in the symbol table. */
3467 #define FN_STUB ".mips16.fn."
3468 #define CALL_STUB ".mips16.call."
3469 #define CALL_FP_STUB ".mips16.call.fp."
3471 /* The MIPS ELF linker needs additional information for each symbol in
3472 the global hash table. */
3474 struct mips_elf_link_hash_entry
3476 struct elf_link_hash_entry root
;
3478 /* External symbol information. */
3481 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
3482 unsigned int mips_32_relocs
;
3484 /* If there is a stub that 32 bit functions should use to call this
3485 16 bit function, this points to the section containing the stub. */
3488 /* Whether we need the fn_stub; this is set if this symbol appears
3489 in any relocs other than a 16 bit call. */
3490 boolean need_fn_stub
;
3492 /* If there is a stub that 16 bit functions should use to call this
3493 32 bit function, this points to the section containing the stub. */
3494 asection
*call_stub
;
3496 /* This is like the call_stub field, but it is used if the function
3497 being called returns a floating point value. */
3498 asection
*call_fp_stub
;
3501 /* MIPS ELF linker hash table. */
3503 struct mips_elf_link_hash_table
3505 struct elf_link_hash_table root
;
3506 /* String section indices for the dynamic section symbols. */
3507 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
3508 /* The number of .rtproc entries. */
3509 bfd_size_type procedure_count
;
3510 /* The size of the .compact_rel section (if SGI_COMPAT). */
3511 bfd_size_type compact_rel_size
;
3512 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3513 entry is set to the address of __rld_obj_head as in Irix 5. */
3514 boolean use_rld_obj_head
;
3515 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3517 /* This is set if we see any mips16 stub sections. */
3518 boolean mips16_stubs_seen
;
3521 /* Look up an entry in a MIPS ELF linker hash table. */
3523 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3524 ((struct mips_elf_link_hash_entry *) \
3525 elf_link_hash_lookup (&(table)->root, (string), (create), \
3528 /* Traverse a MIPS ELF linker hash table. */
3530 #define mips_elf_link_hash_traverse(table, func, info) \
3531 (elf_link_hash_traverse \
3533 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3536 /* Get the MIPS ELF linker hash table from a link_info structure. */
3538 #define mips_elf_hash_table(p) \
3539 ((struct mips_elf_link_hash_table *) ((p)->hash))
3541 static boolean mips_elf_output_extsym
3542 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3544 /* Create an entry in a MIPS ELF linker hash table. */
3546 static struct bfd_hash_entry
*
3547 mips_elf_link_hash_newfunc (entry
, table
, string
)
3548 struct bfd_hash_entry
*entry
;
3549 struct bfd_hash_table
*table
;
3552 struct mips_elf_link_hash_entry
*ret
=
3553 (struct mips_elf_link_hash_entry
*) entry
;
3555 /* Allocate the structure if it has not already been allocated by a
3557 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3558 ret
= ((struct mips_elf_link_hash_entry
*)
3559 bfd_hash_allocate (table
,
3560 sizeof (struct mips_elf_link_hash_entry
)));
3561 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3562 return (struct bfd_hash_entry
*) ret
;
3564 /* Call the allocation method of the superclass. */
3565 ret
= ((struct mips_elf_link_hash_entry
*)
3566 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3568 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3570 /* Set local fields. */
3571 memset (&ret
->esym
, 0, sizeof (EXTR
));
3572 /* We use -2 as a marker to indicate that the information has
3573 not been set. -1 means there is no associated ifd. */
3575 ret
->mips_32_relocs
= 0;
3576 ret
->fn_stub
= NULL
;
3577 ret
->need_fn_stub
= false;
3578 ret
->call_stub
= NULL
;
3579 ret
->call_fp_stub
= NULL
;
3582 return (struct bfd_hash_entry
*) ret
;
3585 /* Create a MIPS ELF linker hash table. */
3587 static struct bfd_link_hash_table
*
3588 mips_elf_link_hash_table_create (abfd
)
3591 struct mips_elf_link_hash_table
*ret
;
3594 ret
= ((struct mips_elf_link_hash_table
*)
3595 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
3596 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
3599 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3600 mips_elf_link_hash_newfunc
))
3602 bfd_release (abfd
, ret
);
3606 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
3607 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
3608 ret
->procedure_count
= 0;
3609 ret
->compact_rel_size
= 0;
3610 ret
->use_rld_obj_head
= false;
3612 ret
->mips16_stubs_seen
= false;
3614 return &ret
->root
.root
;
3617 /* Hook called by the linker routine which adds symbols from an object
3618 file. We must handle the special MIPS section numbers here. */
3622 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3624 struct bfd_link_info
*info
;
3625 const Elf_Internal_Sym
*sym
;
3631 if (SGI_COMPAT (abfd
)
3632 && (abfd
->flags
& DYNAMIC
) != 0
3633 && strcmp (*namep
, "_rld_new_interface") == 0)
3635 /* Skip Irix 5 rld entry name. */
3640 switch (sym
->st_shndx
)
3643 /* Common symbols less than the GP size are automatically
3644 treated as SHN_MIPS_SCOMMON symbols. */
3645 if (sym
->st_size
> elf_gp_size (abfd
))
3648 case SHN_MIPS_SCOMMON
:
3649 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3650 (*secp
)->flags
|= SEC_IS_COMMON
;
3651 *valp
= sym
->st_size
;
3655 /* This section is used in a shared object. */
3656 if (mips_elf_text_section_ptr
== NULL
)
3658 /* Initialize the section. */
3659 mips_elf_text_section
.name
= ".text";
3660 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
3661 mips_elf_text_section
.output_section
= NULL
;
3662 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
3663 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
3664 mips_elf_text_symbol
.name
= ".text";
3665 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
3666 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
3667 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
3668 mips_elf_text_section_ptr
= &mips_elf_text_section
;
3670 /* This code used to do *secp = bfd_und_section_ptr if
3671 info->shared. I don't know why, and that doesn't make sense,
3672 so I took it out. */
3673 *secp
= mips_elf_text_section_ptr
;
3676 case SHN_MIPS_ACOMMON
:
3677 /* Fall through. XXX Can we treat this as allocated data? */
3679 /* This section is used in a shared object. */
3680 if (mips_elf_data_section_ptr
== NULL
)
3682 /* Initialize the section. */
3683 mips_elf_data_section
.name
= ".data";
3684 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
3685 mips_elf_data_section
.output_section
= NULL
;
3686 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
3687 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
3688 mips_elf_data_symbol
.name
= ".data";
3689 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
3690 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
3691 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
3692 mips_elf_data_section_ptr
= &mips_elf_data_section
;
3694 /* This code used to do *secp = bfd_und_section_ptr if
3695 info->shared. I don't know why, and that doesn't make sense,
3696 so I took it out. */
3697 *secp
= mips_elf_data_section_ptr
;
3700 case SHN_MIPS_SUNDEFINED
:
3701 *secp
= bfd_und_section_ptr
;
3705 if (SGI_COMPAT (abfd
)
3707 && info
->hash
->creator
== abfd
->xvec
3708 && strcmp (*namep
, "__rld_obj_head") == 0)
3710 struct elf_link_hash_entry
*h
;
3712 /* Mark __rld_obj_head as dynamic. */
3714 if (! (_bfd_generic_link_add_one_symbol
3715 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3716 (bfd_vma
) *valp
, (const char *) NULL
, false,
3717 get_elf_backend_data (abfd
)->collect
,
3718 (struct bfd_link_hash_entry
**) &h
)))
3720 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
3721 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3722 h
->type
= STT_OBJECT
;
3724 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3727 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3730 /* If this is a mips16 text symbol, add 1 to the value to make it
3731 odd. This will cause something like .word SYM to come up with
3732 the right value when it is loaded into the PC. */
3733 if (sym
->st_other
== STO_MIPS16
)
3739 /* Structure used to pass information to mips_elf_output_extsym. */
3744 struct bfd_link_info
*info
;
3745 struct ecoff_debug_info
*debug
;
3746 const struct ecoff_debug_swap
*swap
;
3750 /* This routine is used to write out ECOFF debugging external symbol
3751 information. It is called via mips_elf_link_hash_traverse. The
3752 ECOFF external symbol information must match the ELF external
3753 symbol information. Unfortunately, at this point we don't know
3754 whether a symbol is required by reloc information, so the two
3755 tables may wind up being different. We must sort out the external
3756 symbol information before we can set the final size of the .mdebug
3757 section, and we must set the size of the .mdebug section before we
3758 can relocate any sections, and we can't know which symbols are
3759 required by relocation until we relocate the sections.
3760 Fortunately, it is relatively unlikely that any symbol will be
3761 stripped but required by a reloc. In particular, it can not happen
3762 when generating a final executable. */
3765 mips_elf_output_extsym (h
, data
)
3766 struct mips_elf_link_hash_entry
*h
;
3769 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
3771 asection
*sec
, *output_section
;
3773 if (h
->root
.indx
== -2)
3775 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3776 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
3777 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3778 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
3780 else if (einfo
->info
->strip
== strip_all
3781 || (einfo
->info
->strip
== strip_some
3782 && bfd_hash_lookup (einfo
->info
->keep_hash
,
3783 h
->root
.root
.root
.string
,
3784 false, false) == NULL
))
3792 if (h
->esym
.ifd
== -2)
3795 h
->esym
.cobol_main
= 0;
3796 h
->esym
.weakext
= 0;
3797 h
->esym
.reserved
= 0;
3798 h
->esym
.ifd
= ifdNil
;
3799 h
->esym
.asym
.value
= 0;
3800 h
->esym
.asym
.st
= stGlobal
;
3802 if (SGI_COMPAT (einfo
->abfd
)
3803 && (h
->root
.root
.type
== bfd_link_hash_undefined
3804 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
3808 /* Use undefined class. Also, set class and type for some
3810 name
= h
->root
.root
.root
.string
;
3811 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
3812 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
3814 h
->esym
.asym
.sc
= scData
;
3815 h
->esym
.asym
.st
= stLabel
;
3816 h
->esym
.asym
.value
= 0;
3818 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
3820 h
->esym
.asym
.sc
= scAbs
;
3821 h
->esym
.asym
.st
= stLabel
;
3822 h
->esym
.asym
.value
=
3823 mips_elf_hash_table (einfo
->info
)->procedure_count
;
3825 else if (strcmp (name
, "_gp_disp") == 0)
3827 h
->esym
.asym
.sc
= scAbs
;
3828 h
->esym
.asym
.st
= stLabel
;
3829 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
3832 h
->esym
.asym
.sc
= scUndefined
;
3834 else if (h
->root
.root
.type
!= bfd_link_hash_defined
3835 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
3836 h
->esym
.asym
.sc
= scAbs
;
3841 sec
= h
->root
.root
.u
.def
.section
;
3842 output_section
= sec
->output_section
;
3844 /* When making a shared library and symbol h is the one from
3845 the another shared library, OUTPUT_SECTION may be null. */
3846 if (output_section
== NULL
)
3847 h
->esym
.asym
.sc
= scUndefined
;
3850 name
= bfd_section_name (output_section
->owner
, output_section
);
3852 if (strcmp (name
, ".text") == 0)
3853 h
->esym
.asym
.sc
= scText
;
3854 else if (strcmp (name
, ".data") == 0)
3855 h
->esym
.asym
.sc
= scData
;
3856 else if (strcmp (name
, ".sdata") == 0)
3857 h
->esym
.asym
.sc
= scSData
;
3858 else if (strcmp (name
, ".rodata") == 0
3859 || strcmp (name
, ".rdata") == 0)
3860 h
->esym
.asym
.sc
= scRData
;
3861 else if (strcmp (name
, ".bss") == 0)
3862 h
->esym
.asym
.sc
= scBss
;
3863 else if (strcmp (name
, ".sbss") == 0)
3864 h
->esym
.asym
.sc
= scSBss
;
3865 else if (strcmp (name
, ".init") == 0)
3866 h
->esym
.asym
.sc
= scInit
;
3867 else if (strcmp (name
, ".fini") == 0)
3868 h
->esym
.asym
.sc
= scFini
;
3870 h
->esym
.asym
.sc
= scAbs
;
3874 h
->esym
.asym
.reserved
= 0;
3875 h
->esym
.asym
.index
= indexNil
;
3878 if (h
->root
.root
.type
== bfd_link_hash_common
)
3879 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
3880 else if (h
->root
.root
.type
== bfd_link_hash_defined
3881 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3883 if (h
->esym
.asym
.sc
== scCommon
)
3884 h
->esym
.asym
.sc
= scBss
;
3885 else if (h
->esym
.asym
.sc
== scSCommon
)
3886 h
->esym
.asym
.sc
= scSBss
;
3888 sec
= h
->root
.root
.u
.def
.section
;
3889 output_section
= sec
->output_section
;
3890 if (output_section
!= NULL
)
3891 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
3892 + sec
->output_offset
3893 + output_section
->vma
);
3895 h
->esym
.asym
.value
= 0;
3897 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3899 /* Set type and value for a symbol with a function stub. */
3900 h
->esym
.asym
.st
= stProc
;
3901 sec
= h
->root
.root
.u
.def
.section
;
3903 h
->esym
.asym
.value
= 0;
3906 output_section
= sec
->output_section
;
3907 if (output_section
!= NULL
)
3908 h
->esym
.asym
.value
= (h
->root
.plt
.offset
3909 + sec
->output_offset
3910 + output_section
->vma
);
3912 h
->esym
.asym
.value
= 0;
3919 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
3920 h
->root
.root
.root
.string
,
3923 einfo
->failed
= true;
3930 /* Create a runtime procedure table from the .mdebug section. */
3933 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
3936 struct bfd_link_info
*info
;
3938 struct ecoff_debug_info
*debug
;
3940 const struct ecoff_debug_swap
*swap
;
3941 HDRR
*hdr
= &debug
->symbolic_header
;
3943 struct rpdr_ext
*erp
;
3945 struct pdr_ext
*epdr
;
3946 struct sym_ext
*esym
;
3949 unsigned long size
, count
;
3950 unsigned long sindex
;
3954 const char *no_name_func
= _("static procedure (no name)");
3962 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3964 sindex
= strlen (no_name_func
) + 1;
3965 count
= hdr
->ipdMax
;
3968 size
= swap
->external_pdr_size
;
3970 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
3974 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
3977 size
= sizeof (RPDR
);
3978 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
3982 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
3986 count
= hdr
->isymMax
;
3987 size
= swap
->external_sym_size
;
3988 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
3992 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
3995 count
= hdr
->issMax
;
3996 ss
= (char *) bfd_malloc (count
);
3999 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
4002 count
= hdr
->ipdMax
;
4003 for (i
= 0; i
< count
; i
++, rp
++)
4005 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
4006 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
4007 rp
->adr
= sym
.value
;
4008 rp
->regmask
= pdr
.regmask
;
4009 rp
->regoffset
= pdr
.regoffset
;
4010 rp
->fregmask
= pdr
.fregmask
;
4011 rp
->fregoffset
= pdr
.fregoffset
;
4012 rp
->frameoffset
= pdr
.frameoffset
;
4013 rp
->framereg
= pdr
.framereg
;
4014 rp
->pcreg
= pdr
.pcreg
;
4016 sv
[i
] = ss
+ sym
.iss
;
4017 sindex
+= strlen (sv
[i
]) + 1;
4021 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
4022 size
= BFD_ALIGN (size
, 16);
4023 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
4026 mips_elf_hash_table (info
)->procedure_count
= 0;
4030 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
4032 erp
= (struct rpdr_ext
*) rtproc
;
4033 memset (erp
, 0, sizeof (struct rpdr_ext
));
4035 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
4036 strcpy (str
, no_name_func
);
4037 str
+= strlen (no_name_func
) + 1;
4038 for (i
= 0; i
< count
; i
++)
4040 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
4041 strcpy (str
, sv
[i
]);
4042 str
+= strlen (sv
[i
]) + 1;
4044 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
4046 /* Set the size and contents of .rtproc section. */
4047 s
->_raw_size
= size
;
4048 s
->contents
= (bfd_byte
*) rtproc
;
4050 /* Skip this section later on (I don't think this currently
4051 matters, but someday it might). */
4052 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
4081 /* A comparison routine used to sort .gptab entries. */
4084 gptab_compare (p1
, p2
)
4088 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
4089 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
4091 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
4094 /* We need to use a special link routine to handle the .reginfo and
4095 the .mdebug sections. We need to merge all instances of these
4096 sections together, not write them all out sequentially. */
4099 mips_elf_final_link (abfd
, info
)
4101 struct bfd_link_info
*info
;
4105 struct bfd_link_order
*p
;
4106 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
4107 asection
*rtproc_sec
;
4108 Elf32_RegInfo reginfo
;
4109 struct ecoff_debug_info debug
;
4110 const struct ecoff_debug_swap
*swap
4111 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4112 HDRR
*symhdr
= &debug
.symbolic_header
;
4113 PTR mdebug_handle
= NULL
;
4115 /* Drop the .options section, since it has special semantics which I
4116 haven't bothered to figure out. */
4117 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
4119 if (strcmp ((*secpp
)->name
, ".options") == 0)
4121 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
4122 if (p
->type
== bfd_indirect_link_order
)
4123 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
4124 (*secpp
)->link_order_head
= NULL
;
4125 *secpp
= (*secpp
)->next
;
4126 --abfd
->section_count
;
4131 /* Get a value for the GP register. */
4132 if (elf_gp (abfd
) == 0)
4134 struct bfd_link_hash_entry
*h
;
4136 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4137 if (h
!= (struct bfd_link_hash_entry
*) NULL
4138 && h
->type
== bfd_link_hash_defined
)
4139 elf_gp (abfd
) = (h
->u
.def
.value
4140 + h
->u
.def
.section
->output_section
->vma
4141 + h
->u
.def
.section
->output_offset
);
4142 else if (info
->relocateable
)
4146 /* Make up a value. */
4148 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4151 && (strcmp (o
->name
, ".sbss") == 0
4152 || strcmp (o
->name
, ".sdata") == 0
4153 || strcmp (o
->name
, ".lit4") == 0
4154 || strcmp (o
->name
, ".lit8") == 0))
4157 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
4161 /* If the relocate_section function needs to do a reloc
4162 involving the GP value, it should make a reloc_dangerous
4163 callback to warn that GP is not defined. */
4167 /* Go through the sections and collect the .reginfo and .mdebug
4171 gptab_data_sec
= NULL
;
4172 gptab_bss_sec
= NULL
;
4173 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4175 if (strcmp (o
->name
, ".reginfo") == 0)
4177 memset (®info
, 0, sizeof reginfo
);
4179 /* We have found the .reginfo section in the output file.
4180 Look through all the link_orders comprising it and merge
4181 the information together. */
4182 for (p
= o
->link_order_head
;
4183 p
!= (struct bfd_link_order
*) NULL
;
4186 asection
*input_section
;
4188 Elf32_External_RegInfo ext
;
4191 if (p
->type
!= bfd_indirect_link_order
)
4193 if (p
->type
== bfd_fill_link_order
)
4198 input_section
= p
->u
.indirect
.section
;
4199 input_bfd
= input_section
->owner
;
4201 /* The linker emulation code has probably clobbered the
4202 size to be zero bytes. */
4203 if (input_section
->_raw_size
== 0)
4204 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4206 if (! bfd_get_section_contents (input_bfd
, input_section
,
4212 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
4214 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
4215 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
4216 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
4217 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
4218 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
4220 /* ri_gp_value is set by the function
4221 mips_elf32_section_processing when the section is
4222 finally written out. */
4224 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4225 elf_link_input_bfd ignores this section. */
4226 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4229 /* Force the section size to the value we want. */
4230 o
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4232 /* Skip this section later on (I don't think this currently
4233 matters, but someday it might). */
4234 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4239 if (strcmp (o
->name
, ".mdebug") == 0)
4241 struct extsym_info einfo
;
4243 /* We have found the .mdebug section in the output file.
4244 Look through all the link_orders comprising it and merge
4245 the information together. */
4246 symhdr
->magic
= swap
->sym_magic
;
4247 /* FIXME: What should the version stamp be? */
4249 symhdr
->ilineMax
= 0;
4253 symhdr
->isymMax
= 0;
4254 symhdr
->ioptMax
= 0;
4255 symhdr
->iauxMax
= 0;
4257 symhdr
->issExtMax
= 0;
4260 symhdr
->iextMax
= 0;
4262 /* We accumulate the debugging information itself in the
4263 debug_info structure. */
4265 debug
.external_dnr
= NULL
;
4266 debug
.external_pdr
= NULL
;
4267 debug
.external_sym
= NULL
;
4268 debug
.external_opt
= NULL
;
4269 debug
.external_aux
= NULL
;
4271 debug
.ssext
= debug
.ssext_end
= NULL
;
4272 debug
.external_fdr
= NULL
;
4273 debug
.external_rfd
= NULL
;
4274 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4276 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4277 if (mdebug_handle
== (PTR
) NULL
)
4280 if (SGI_COMPAT (abfd
))
4286 static const char * const name
[] =
4287 { ".text", ".init", ".fini", ".data",
4288 ".rodata", ".sdata", ".sbss", ".bss" };
4289 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
4290 scRData
, scSData
, scSBss
, scBss
};
4293 esym
.cobol_main
= 0;
4297 esym
.asym
.iss
= issNil
;
4298 esym
.asym
.st
= stLocal
;
4299 esym
.asym
.reserved
= 0;
4300 esym
.asym
.index
= indexNil
;
4302 for (i
= 0; i
< 8; i
++)
4304 esym
.asym
.sc
= sc
[i
];
4305 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4308 esym
.asym
.value
= s
->vma
;
4309 last
= s
->vma
+ s
->_raw_size
;
4312 esym
.asym
.value
= last
;
4314 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4320 for (p
= o
->link_order_head
;
4321 p
!= (struct bfd_link_order
*) NULL
;
4324 asection
*input_section
;
4326 const struct ecoff_debug_swap
*input_swap
;
4327 struct ecoff_debug_info input_debug
;
4331 if (p
->type
!= bfd_indirect_link_order
)
4333 if (p
->type
== bfd_fill_link_order
)
4338 input_section
= p
->u
.indirect
.section
;
4339 input_bfd
= input_section
->owner
;
4341 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4342 || (get_elf_backend_data (input_bfd
)
4343 ->elf_backend_ecoff_debug_swap
) == NULL
)
4345 /* I don't know what a non MIPS ELF bfd would be
4346 doing with a .mdebug section, but I don't really
4347 want to deal with it. */
4351 input_swap
= (get_elf_backend_data (input_bfd
)
4352 ->elf_backend_ecoff_debug_swap
);
4354 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
4356 /* The ECOFF linking code expects that we have already
4357 read in the debugging information and set up an
4358 ecoff_debug_info structure, so we do that now. */
4359 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
4363 if (! (bfd_ecoff_debug_accumulate
4364 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
4365 &input_debug
, input_swap
, info
)))
4368 /* Loop through the external symbols. For each one with
4369 interesting information, try to find the symbol in
4370 the linker global hash table and save the information
4371 for the output external symbols. */
4372 eraw_src
= input_debug
.external_ext
;
4373 eraw_end
= (eraw_src
4374 + (input_debug
.symbolic_header
.iextMax
4375 * input_swap
->external_ext_size
));
4377 eraw_src
< eraw_end
;
4378 eraw_src
+= input_swap
->external_ext_size
)
4382 struct mips_elf_link_hash_entry
*h
;
4384 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4385 if (ext
.asym
.sc
== scNil
4386 || ext
.asym
.sc
== scUndefined
4387 || ext
.asym
.sc
== scSUndefined
)
4390 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4391 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
4392 name
, false, false, true);
4393 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4399 < input_debug
.symbolic_header
.ifdMax
);
4400 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4406 /* Free up the information we just read. */
4407 free (input_debug
.line
);
4408 free (input_debug
.external_dnr
);
4409 free (input_debug
.external_pdr
);
4410 free (input_debug
.external_sym
);
4411 free (input_debug
.external_opt
);
4412 free (input_debug
.external_aux
);
4413 free (input_debug
.ss
);
4414 free (input_debug
.ssext
);
4415 free (input_debug
.external_fdr
);
4416 free (input_debug
.external_rfd
);
4417 free (input_debug
.external_ext
);
4419 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4420 elf_link_input_bfd ignores this section. */
4421 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4424 if (SGI_COMPAT (abfd
) && info
->shared
)
4426 /* Create .rtproc section. */
4427 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4428 if (rtproc_sec
== NULL
)
4430 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4431 | SEC_LINKER_CREATED
| SEC_READONLY
);
4433 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4434 if (rtproc_sec
== NULL
4435 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4436 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
4440 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
4441 info
, rtproc_sec
, &debug
))
4445 /* Build the external symbol information. */
4448 einfo
.debug
= &debug
;
4450 einfo
.failed
= false;
4451 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4452 mips_elf_output_extsym
,
4457 /* Set the size of the .mdebug section. */
4458 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4460 /* Skip this section later on (I don't think this currently
4461 matters, but someday it might). */
4462 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4467 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4469 const char *subname
;
4472 Elf32_External_gptab
*ext_tab
;
4475 /* The .gptab.sdata and .gptab.sbss sections hold
4476 information describing how the small data area would
4477 change depending upon the -G switch. These sections
4478 not used in executables files. */
4479 if (! info
->relocateable
)
4483 for (p
= o
->link_order_head
;
4484 p
!= (struct bfd_link_order
*) NULL
;
4487 asection
*input_section
;
4489 if (p
->type
!= bfd_indirect_link_order
)
4491 if (p
->type
== bfd_fill_link_order
)
4496 input_section
= p
->u
.indirect
.section
;
4498 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4499 elf_link_input_bfd ignores this section. */
4500 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4503 /* Skip this section later on (I don't think this
4504 currently matters, but someday it might). */
4505 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4507 /* Really remove the section. */
4508 for (secpp
= &abfd
->sections
;
4510 secpp
= &(*secpp
)->next
)
4512 *secpp
= (*secpp
)->next
;
4513 --abfd
->section_count
;
4518 /* There is one gptab for initialized data, and one for
4519 uninitialized data. */
4520 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4522 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4526 (*_bfd_error_handler
)
4527 (_("%s: illegal section name `%s'"),
4528 bfd_get_filename (abfd
), o
->name
);
4529 bfd_set_error (bfd_error_nonrepresentable_section
);
4533 /* The linker script always combines .gptab.data and
4534 .gptab.sdata into .gptab.sdata, and likewise for
4535 .gptab.bss and .gptab.sbss. It is possible that there is
4536 no .sdata or .sbss section in the output file, in which
4537 case we must change the name of the output section. */
4538 subname
= o
->name
+ sizeof ".gptab" - 1;
4539 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4541 if (o
== gptab_data_sec
)
4542 o
->name
= ".gptab.data";
4544 o
->name
= ".gptab.bss";
4545 subname
= o
->name
+ sizeof ".gptab" - 1;
4546 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4549 /* Set up the first entry. */
4551 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
4554 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4555 tab
[0].gt_header
.gt_unused
= 0;
4557 /* Combine the input sections. */
4558 for (p
= o
->link_order_head
;
4559 p
!= (struct bfd_link_order
*) NULL
;
4562 asection
*input_section
;
4566 bfd_size_type gpentry
;
4568 if (p
->type
!= bfd_indirect_link_order
)
4570 if (p
->type
== bfd_fill_link_order
)
4575 input_section
= p
->u
.indirect
.section
;
4576 input_bfd
= input_section
->owner
;
4578 /* Combine the gptab entries for this input section one
4579 by one. We know that the input gptab entries are
4580 sorted by ascending -G value. */
4581 size
= bfd_section_size (input_bfd
, input_section
);
4583 for (gpentry
= sizeof (Elf32_External_gptab
);
4585 gpentry
+= sizeof (Elf32_External_gptab
))
4587 Elf32_External_gptab ext_gptab
;
4588 Elf32_gptab int_gptab
;
4594 if (! (bfd_get_section_contents
4595 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4596 gpentry
, sizeof (Elf32_External_gptab
))))
4602 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
4604 val
= int_gptab
.gt_entry
.gt_g_value
;
4605 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4608 for (look
= 1; look
< c
; look
++)
4610 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4611 tab
[look
].gt_entry
.gt_bytes
+= add
;
4613 if (tab
[look
].gt_entry
.gt_g_value
== val
)
4619 Elf32_gptab
*new_tab
;
4622 /* We need a new table entry. */
4623 new_tab
= ((Elf32_gptab
*)
4624 bfd_realloc ((PTR
) tab
,
4625 (c
+ 1) * sizeof (Elf32_gptab
)));
4626 if (new_tab
== NULL
)
4632 tab
[c
].gt_entry
.gt_g_value
= val
;
4633 tab
[c
].gt_entry
.gt_bytes
= add
;
4635 /* Merge in the size for the next smallest -G
4636 value, since that will be implied by this new
4639 for (look
= 1; look
< c
; look
++)
4641 if (tab
[look
].gt_entry
.gt_g_value
< val
4643 || (tab
[look
].gt_entry
.gt_g_value
4644 > tab
[max
].gt_entry
.gt_g_value
)))
4648 tab
[c
].gt_entry
.gt_bytes
+=
4649 tab
[max
].gt_entry
.gt_bytes
;
4654 last
= int_gptab
.gt_entry
.gt_bytes
;
4657 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4658 elf_link_input_bfd ignores this section. */
4659 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4662 /* The table must be sorted by -G value. */
4664 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
4666 /* Swap out the table. */
4667 ext_tab
= ((Elf32_External_gptab
*)
4668 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
4669 if (ext_tab
== NULL
)
4675 for (i
= 0; i
< c
; i
++)
4676 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
4679 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
4680 o
->contents
= (bfd_byte
*) ext_tab
;
4682 /* Skip this section later on (I don't think this currently
4683 matters, but someday it might). */
4684 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4688 /* Invoke the regular ELF backend linker to do all the work. */
4689 if (! bfd_elf32_bfd_final_link (abfd
, info
))
4692 /* Now write out the computed sections. */
4694 if (reginfo_sec
!= (asection
*) NULL
)
4696 Elf32_External_RegInfo ext
;
4698 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
4699 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4700 (file_ptr
) 0, sizeof ext
))
4704 if (mdebug_sec
!= (asection
*) NULL
)
4706 BFD_ASSERT (abfd
->output_has_begun
);
4707 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4709 mdebug_sec
->filepos
))
4712 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4715 if (gptab_data_sec
!= (asection
*) NULL
)
4717 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4718 gptab_data_sec
->contents
,
4720 gptab_data_sec
->_raw_size
))
4724 if (gptab_bss_sec
!= (asection
*) NULL
)
4726 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4727 gptab_bss_sec
->contents
,
4729 gptab_bss_sec
->_raw_size
))
4733 if (SGI_COMPAT (abfd
))
4735 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4736 if (rtproc_sec
!= NULL
)
4738 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
4739 rtproc_sec
->contents
,
4741 rtproc_sec
->_raw_size
))
4749 /* Handle a MIPS ELF HI16 reloc. */
4752 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
4754 Elf_Internal_Rela
*relhi
;
4755 Elf_Internal_Rela
*rello
;
4762 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4764 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4767 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4769 if ((addlo
& 0x8000) != 0)
4771 if ((addend
& 0x8000) != 0)
4774 bfd_put_32 (input_bfd
,
4775 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
4776 contents
+ relhi
->r_offset
);
4779 /* Handle a MIPS ELF local GOT16 reloc. */
4782 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
4787 Elf_Internal_Rela
*relhi
;
4788 Elf_Internal_Rela
*rello
;
4792 unsigned int assigned_gotno
;
4798 bfd_byte
*got_contents
;
4799 struct mips_got_info
*g
;
4801 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4803 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4806 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4808 if ((addlo
& 0x8000) != 0)
4810 if ((addend
& 0x8000) != 0)
4813 /* Get a got entry representing requested hipage. */
4814 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4815 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4816 BFD_ASSERT (g
!= NULL
);
4818 assigned_gotno
= g
->assigned_gotno
;
4819 got_contents
= sgot
->contents
;
4820 hipage
= addend
& 0xffff0000;
4822 for (i
= MIPS_RESERVED_GOTNO
; i
< assigned_gotno
; i
++)
4824 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
4825 if (hipage
== (address
& 0xffff0000))
4829 if (i
== assigned_gotno
)
4831 if (assigned_gotno
>= g
->local_gotno
)
4833 (*_bfd_error_handler
)
4834 (_("more got entries are needed for hipage relocations"));
4835 bfd_set_error (bfd_error_bad_value
);
4839 bfd_put_32 (input_bfd
, hipage
, got_contents
+ assigned_gotno
* 4);
4840 ++g
->assigned_gotno
;
4843 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
4844 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
4845 contents
+ relhi
->r_offset
);
4850 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
4853 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
4855 Elf_Internal_Rela
*rel
;
4861 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4862 bfd_put_32 (input_bfd
,
4863 (insn
& 0xffff0000) | (offset
& 0xffff),
4864 contents
+ rel
->r_offset
);
4867 /* Relocate a MIPS ELF section. */
4870 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4871 contents
, relocs
, local_syms
, local_sections
)
4873 struct bfd_link_info
*info
;
4875 asection
*input_section
;
4877 Elf_Internal_Rela
*relocs
;
4878 Elf_Internal_Sym
*local_syms
;
4879 asection
**local_sections
;
4881 Elf_Internal_Shdr
*symtab_hdr
;
4884 asection
*sgot
, *sreloc
, *scpt
;
4887 Elf_Internal_Rela
*rel
;
4888 Elf_Internal_Rela
*relend
;
4889 struct mips_got_info
*g
;
4891 dynobj
= elf_hash_table (info
)->dynobj
;
4892 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4896 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
4899 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
4902 if (elf_bad_symtab (input_bfd
))
4904 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
4909 locsymcount
= symtab_hdr
->sh_info
;
4910 extsymoff
= symtab_hdr
->sh_info
;
4913 gp
= _bfd_get_gp_value (output_bfd
);
4916 relend
= relocs
+ input_section
->reloc_count
;
4917 for (; rel
< relend
; rel
++)
4920 reloc_howto_type
*howto
;
4921 unsigned long r_symndx
;
4923 struct elf_link_hash_entry
*h
;
4925 Elf_Internal_Sym
*sym
;
4926 struct mips_elf_link_hash_entry
*mh
;
4928 bfd_reloc_status_type r
;
4930 r_type
= ELF32_R_TYPE (rel
->r_info
);
4931 if (r_type
== R_MIPS_GNU_VTINHERIT
4932 || r_type
== R_MIPS_GNU_VTENTRY
)
4934 if ((r_type
< 0 || r_type
>= (int) R_MIPS_max
)
4935 /* start-sanitize-sky */
4936 && r_type
!= R_MIPS_DVP_11_PCREL
4937 && r_type
!= R_MIPS_DVP_27_S4
4938 && r_type
!= R_MIPS_DVP_11_S4
4939 && r_type
!= R_MIPS_DVP_U15_S3
4940 /* end-sanitize-sky */
4941 && r_type
!= R_MIPS16_26
4942 && r_type
!= R_MIPS16_GPREL
)
4944 bfd_set_error (bfd_error_bad_value
);
4947 if (r_type
== R_MIPS16_26
)
4948 howto
= &elf_mips16_jump_howto
;
4949 else if (r_type
== R_MIPS16_GPREL
)
4950 howto
= &elf_mips16_gprel_howto
;
4951 /* start-sanitize-sky */
4952 else if (r_type
== R_MIPS_DVP_11_PCREL
)
4953 howto
= &elf_mips_dvp_11_pcrel_howto
;
4954 else if (r_type
== R_MIPS_DVP_27_S4
)
4955 howto
= &elf_mips_dvp_27_s4_howto
;
4956 else if (r_type
== R_MIPS_DVP_11_S4
)
4957 howto
= &elf_mips_dvp_11_s4_howto
;
4958 else if (r_type
== R_MIPS_DVP_U15_S3
)
4959 howto
= &elf_mips_dvp_u15_s3_howto
;
4960 /* end-sanitize-sky */
4962 howto
= elf_mips_howto_table
+ r_type
;
4965 && (r_type
== R_MIPS_CALL16
4966 || r_type
== R_MIPS_GOT16
4967 || r_type
== R_MIPS_CALL_HI16
4968 || r_type
== R_MIPS_CALL_LO16
4969 || r_type
== R_MIPS_GOT_HI16
4970 || r_type
== R_MIPS_GOT_LO16
))
4972 /* We need the .got section. */
4975 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4976 BFD_ASSERT (sgot
!= NULL
);
4977 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4978 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4979 BFD_ASSERT (g
!= NULL
);
4983 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4985 /* Mix in the change in GP address for a GP relative reloc. */
4986 if (r_type
!= R_MIPS_GPREL16
4987 && r_type
!= R_MIPS_LITERAL
4988 && r_type
!= R_MIPS_GPREL32
4989 && r_type
!= R_MIPS16_GPREL
)
4995 if (! ((*info
->callbacks
->reloc_dangerous
)
4997 _("GP relative relocation when GP not defined"),
4998 input_bfd
, input_section
,
5001 /* Only give the error once per link. */
5003 _bfd_set_gp_value (output_bfd
, gp
);
5006 if (r_symndx
< extsymoff
5007 || (elf_bad_symtab (input_bfd
)
5008 && local_sections
[r_symndx
] != NULL
))
5010 /* This is a relocation against a section. The current
5011 addend in the instruction is the difference between
5012 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
5013 must change this to be the difference between the
5014 final definition (which will end up in RELOCATION)
5015 and the GP value of OUTPUT_BFD (which is in GP). */
5016 addend
= elf_gp (input_bfd
) - gp
;
5018 else if (! info
->relocateable
)
5020 /* We are doing a final link. The current addend in the
5021 instruction is simply the desired offset into the
5022 symbol (normally zero). We want the instruction to
5023 hold the difference between the final definition of
5024 the symbol (which will end up in RELOCATION) and the
5025 GP value of OUTPUT_BFD (which is in GP). */
5030 /* We are generating relocateable output, and we aren't
5031 going to define this symbol, so we just leave the
5032 instruction alone. */
5040 if (info
->relocateable
)
5042 /* This is a relocateable link. We don't have to change
5043 anything, unless the reloc is against a section symbol,
5044 in which case we have to adjust according to where the
5045 section symbol winds up in the output section. */
5046 if (r_symndx
>= locsymcount
5047 || (elf_bad_symtab (input_bfd
)
5048 && local_sections
[r_symndx
] == NULL
))
5052 sym
= local_syms
+ r_symndx
;
5053 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5057 sec
= local_sections
[r_symndx
];
5059 /* It would be logical to add sym->st_value here,
5060 but Irix 5 sometimes generates a garbage symbol
5062 addend
+= sec
->output_offset
;
5064 /* If this is HI16 or GOT16 with an associated LO16,
5065 adjust the addend accordingly. Otherwise, just
5067 if (r_type
== R_MIPS_64
&& bfd_big_endian (input_bfd
))
5068 r
= _bfd_relocate_contents (howto
, input_bfd
,
5070 contents
+ rel
->r_offset
+ 4);
5071 else if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
5072 r
= _bfd_relocate_contents (howto
, input_bfd
,
5074 contents
+ rel
->r_offset
);
5077 Elf_Internal_Rela
*lorel
;
5079 /* As a GNU extension, permit an arbitrary
5080 number of R_MIPS_HI16 relocs before the
5081 R_MIPS_LO16 reloc. This permits gcc to emit
5082 the HI and LO relocs itself. */
5083 if (r_type
== R_MIPS_GOT16
)
5087 for (lorel
= rel
+ 1;
5089 && (ELF32_R_TYPE (lorel
->r_info
)
5095 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5097 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5102 r
= _bfd_relocate_contents (howto
, input_bfd
,
5104 contents
+ rel
->r_offset
);
5113 boolean undefined_error
;
5115 /* This is a final link. */
5116 undefined_error
= false;
5118 if (r_symndx
< extsymoff
5119 || (elf_bad_symtab (input_bfd
)
5120 && local_sections
[r_symndx
] != NULL
))
5123 sym
= local_syms
+ r_symndx
;
5124 sec
= local_sections
[r_symndx
];
5125 relocation
= (sec
->output_section
->vma
5126 + sec
->output_offset
);
5128 /* It would be logical to always add sym->st_value here,
5129 but Irix 5 sometimes generates a garbage symbol
5131 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5132 relocation
+= sym
->st_value
;
5134 /* mips16 text labels should be treated as odd. */
5135 if (sym
->st_other
== STO_MIPS16
)
5143 indx
= r_symndx
- extsymoff
;
5144 h
= elf_sym_hashes (input_bfd
)[indx
];
5145 while (h
->root
.type
== bfd_link_hash_indirect
5146 || h
->root
.type
== bfd_link_hash_warning
)
5147 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5148 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
5152 if (! ((*info
->callbacks
->reloc_dangerous
)
5154 _("_gp_disp used when GP not defined"),
5155 input_bfd
, input_section
,
5158 /* Only give the error once per link. */
5160 _bfd_set_gp_value (output_bfd
, gp
);
5165 sec
= input_section
;
5166 if (sec
->output_section
!= NULL
)
5169 + sec
->output_section
->vma
5170 + sec
->output_offset
));
5172 relocation
= gp
- rel
->r_offset
;
5173 if (r_type
== R_MIPS_LO16
)
5177 else if (h
->root
.type
== bfd_link_hash_defined
5178 || h
->root
.type
== bfd_link_hash_defweak
)
5180 sec
= h
->root
.u
.def
.section
;
5181 if (sec
->output_section
== NULL
)
5184 relocation
= (h
->root
.u
.def
.value
5185 + sec
->output_section
->vma
5186 + sec
->output_offset
);
5188 else if (h
->root
.type
== bfd_link_hash_undefweak
)
5190 else if (info
->shared
&& ! info
->symbolic
)
5192 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
5194 /* If this is a dynamic link, we should have created
5195 a _DYNAMIC_LINK symbol in
5196 mips_elf_create_dynamic_sections. Otherwise, we
5197 should define the symbol with a value of 0.
5198 FIXME: It should probably get into the symbol
5199 table somehow as well. */
5200 BFD_ASSERT (! info
->shared
);
5201 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
5202 ".dynamic") == NULL
);
5207 if (! ((*info
->callbacks
->undefined_symbol
)
5208 (info
, h
->root
.root
.string
, input_bfd
,
5209 input_section
, rel
->r_offset
)))
5211 undefined_error
= true;
5216 mh
= (struct mips_elf_link_hash_entry
*) h
;
5219 else if (sym
!= NULL
)
5220 other
= sym
->st_other
;
5224 /* If this function has an fn_stub, then it is a mips16
5225 function which needs a stub if it is called by a 32 bit
5226 function. If this reloc is anything other than a 16 bit
5227 call, redirect the reloc to the stub. We don't redirect
5228 relocs from other stub functions. */
5229 if (r_type
!= R_MIPS16_26
5231 && mh
->fn_stub
!= NULL
)
5233 && elf_tdata (input_bfd
)->local_stubs
!= NULL
5234 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
5235 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5236 FN_STUB
, sizeof FN_STUB
- 1) != 0
5237 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5238 CALL_STUB
, sizeof CALL_STUB
- 1) != 0
5239 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5240 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) != 0)
5244 BFD_ASSERT (mh
->need_fn_stub
);
5245 relocation
= (mh
->fn_stub
->output_section
->vma
5246 + mh
->fn_stub
->output_offset
);
5252 fn_stub
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
5253 relocation
= (fn_stub
->output_section
->vma
5254 + fn_stub
->output_offset
);
5257 /* RELOCATION now points to 32 bit code. */
5261 /* If this function has a call_stub, then it is called by a
5262 mips16 function; the call needs to go through a stub if
5263 this function is a 32 bit function. If this reloc is a
5264 16 bit call, and the symbol is not a 16 bit function,
5265 then redirect the reloc to the stub. Note that we don't
5266 need to worry about calling the function through a
5267 function pointer; such calls are handled by routing
5268 through a special mips16 routine. We don't have to check
5269 whether this call is from a stub; it can't be, because a
5270 stub contains 32 bit code, and hence can not have a 16
5272 if (r_type
== R_MIPS16_26
5274 && (mh
->call_stub
!= NULL
|| mh
->call_fp_stub
!= NULL
)
5275 && other
!= STO_MIPS16
)
5279 /* If both call_stub and call_fp_stub are defined, we
5280 can figure out which one to use by seeing which one
5281 appears in the input file. */
5282 if (mh
->call_stub
!= NULL
&& mh
->call_fp_stub
!= NULL
)
5287 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
5289 if (strncmp (bfd_get_section_name (input_bfd
, o
),
5290 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5292 stub
= mh
->call_fp_stub
;
5297 stub
= mh
->call_stub
;
5299 else if (mh
->call_stub
!= NULL
)
5300 stub
= mh
->call_stub
;
5302 stub
= mh
->call_fp_stub
;
5304 BFD_ASSERT (stub
->_raw_size
> 0);
5305 relocation
= stub
->output_section
->vma
+ stub
->output_offset
;
5308 if (r_type
== R_MIPS_HI16
)
5310 Elf_Internal_Rela
*lorel
;
5312 /* As a GNU extension, permit an arbitrary number of
5313 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
5314 This permits gcc to emit the HI and LO relocs itself. */
5315 for (lorel
= rel
+ 1;
5317 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
5321 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5323 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5324 contents
, relocation
+ addend
);
5328 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5329 contents
, rel
->r_offset
,
5330 relocation
, addend
);
5332 else if (r_type
== R_MIPS_GOT16
&& local
)
5334 /* GOT16 must also have an associated LO16 in the local
5335 case. In this case, the addend is extracted and the
5336 section in which the referenced object is determined.
5337 Then the final address of the object is computed and
5338 the GOT entry for the hipage (an aligned 64kb chunk)
5339 is added to .got section if needed. The offset field
5340 of the GOT16-relocated instruction is replaced by the
5341 index of this GOT entry for the hipage. */
5342 if ((rel
+ 1) < relend
5343 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
5345 if (! mips_elf_relocate_got_local (output_bfd
, input_bfd
,
5348 relocation
+ addend
))
5353 r
= bfd_reloc_outofrange
;
5355 else if (r_type
== R_MIPS_CALL16
5356 || r_type
== R_MIPS_GOT16
5357 || r_type
== R_MIPS_CALL_LO16
5358 || r_type
== R_MIPS_GOT_LO16
)
5362 /* This symbol must be registered as a global symbol
5363 having the corresponding got entry. */
5364 BFD_ASSERT (h
->got
.offset
!= (bfd_vma
) -1);
5366 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5367 BFD_ASSERT (g
->local_gotno
<= offset
5368 && offset
< sgot
->_raw_size
);
5369 bfd_put_32 (output_bfd
, relocation
+ addend
,
5370 sgot
->contents
+ offset
);
5371 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5373 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
5377 else if (r_type
== R_MIPS_CALL_HI16
5378 || r_type
== R_MIPS_GOT_HI16
)
5382 /* This must be a global symbol with a got entry. The
5383 next reloc must be the corresponding LO16 reloc. */
5384 BFD_ASSERT (h
!= NULL
&& h
->got
.offset
!= (bfd_vma
) -1);
5385 BFD_ASSERT ((rel
+ 1) < relend
);
5386 BFD_ASSERT ((int) ELF32_R_TYPE ((rel
+ 1)->r_info
)
5387 == (r_type
== R_MIPS_CALL_HI16
5388 ? (int) R_MIPS_CALL_LO16
5389 : (int) R_MIPS_GOT_LO16
));
5391 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5392 BFD_ASSERT (g
->local_gotno
<= offset
5393 && offset
< sgot
->_raw_size
);
5394 bfd_put_32 (output_bfd
, relocation
+ addend
,
5395 sgot
->contents
+ offset
);
5396 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5398 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
5402 else if (r_type
== R_MIPS_REL32
5403 || r_type
== R_MIPS_32
)
5405 Elf_Internal_Rel outrel
;
5406 Elf32_crinfo cptrel
;
5410 || (elf_hash_table (info
)->dynamic_sections_created
5412 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
5414 && (input_section
->flags
& SEC_ALLOC
) != 0)
5418 /* When generating a shared object, these
5419 relocations are copied into the output file to be
5420 resolved at run time. */
5423 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5424 BFD_ASSERT (sreloc
!= NULL
);
5429 if (elf_section_data (input_section
)->stab_info
== NULL
)
5430 outrel
.r_offset
= rel
->r_offset
;
5435 off
= (_bfd_stab_section_offset
5436 (output_bfd
, &elf_hash_table (info
)->stab_info
,
5438 &elf_section_data (input_section
)->stab_info
,
5440 if (off
== (bfd_vma
) -1)
5442 outrel
.r_offset
= off
;
5445 outrel
.r_offset
+= (input_section
->output_section
->vma
5446 + input_section
->output_offset
);
5448 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5451 memset (&outrel
, 0, sizeof outrel
);
5453 && (! info
->symbolic
5454 || (h
->elf_link_hash_flags
5455 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5457 BFD_ASSERT (h
->dynindx
!= -1);
5458 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
5459 sec
= input_section
;
5466 sec
= local_sections
[r_symndx
];
5469 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
5471 == bfd_link_hash_defweak
));
5472 sec
= h
->root
.u
.def
.section
;
5474 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5476 else if (sec
== NULL
|| sec
->owner
== NULL
)
5478 bfd_set_error (bfd_error_bad_value
);
5485 osec
= sec
->output_section
;
5486 indx
= elf_section_data (osec
)->dynindx
;
5491 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
5492 addend
+= relocation
;
5496 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
5498 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
5499 (((Elf32_External_Rel
*)
5501 + sreloc
->reloc_count
));
5502 ++sreloc
->reloc_count
;
5504 if (! skip
&& SGI_COMPAT (output_bfd
))
5509 /* Make an entry of compact relocation info. */
5510 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5511 cptrel
.vaddr
= (rel
->r_offset
5512 + input_section
->output_section
->vma
5513 + input_section
->output_offset
);
5514 if (r_type
== R_MIPS_REL32
)
5515 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5517 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5518 mips_elf_set_cr_dist2to (cptrel
, 0);
5519 cptrel
.konst
= addend
;
5521 cr
= (scpt
->contents
5522 + sizeof (Elf32_External_compact_rel
));
5523 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5524 ((Elf32_External_crinfo
*) cr
5525 + scpt
->reloc_count
));
5526 ++scpt
->reloc_count
;
5529 /* This reloc will be computed at runtime, so
5530 there's no need to do anything now. */
5534 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5535 contents
, rel
->r_offset
,
5536 relocation
, addend
);
5538 else if (r_type
== R_MIPS_64
)
5543 /* Do a 32 bit relocation, and sign extend to 64 bits. */
5544 addr
= rel
->r_offset
;
5545 if (bfd_big_endian (input_bfd
))
5547 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5548 contents
, addr
, relocation
,
5550 val
= bfd_get_32 (input_bfd
, contents
+ addr
);
5551 if ((val
& 0x80000000) != 0)
5555 addr
= rel
->r_offset
;
5556 if (bfd_little_endian (input_bfd
))
5558 bfd_put_32 (input_bfd
, val
, contents
+ addr
);
5560 else if (r_type
== R_MIPS_26
&& other
== STO_MIPS16
)
5564 /* This is a jump to a mips16 routine from a mips32
5565 routine. We need to change jal into jalx. */
5566 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5567 if (((insn
>> 26) & 0x3f) != 0x3
5568 && ((insn
>> 26) & 0x3f) != 0x1d)
5570 (*_bfd_error_handler
)
5571 (_("%s: %s+0x%lx: jump to mips16 routine which is not jal"),
5572 bfd_get_filename (input_bfd
),
5573 input_section
->name
,
5574 (unsigned long) rel
->r_offset
);
5575 bfd_set_error (bfd_error_bad_value
);
5578 insn
= (insn
& 0x3ffffff) | (0x1d << 26);
5579 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5580 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5581 contents
, rel
->r_offset
,
5582 relocation
, addend
);
5584 else if (r_type
== R_MIPS16_26
)
5586 /* It's easiest to do the normal relocation, and then
5587 dig out the instruction and swap the first word the
5588 way the mips16 expects it. If this is little endian,
5589 though, we need to swap the two words first, and then
5590 swap them back again later, so that the address looks
5593 if (bfd_little_endian (input_bfd
))
5597 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5598 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5599 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5602 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5603 contents
, rel
->r_offset
,
5604 relocation
, addend
);
5605 if (r
== bfd_reloc_ok
)
5609 if (bfd_little_endian (input_bfd
))
5611 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5612 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5613 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5616 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5617 insn
= ((insn
& 0xfc00)
5618 | ((insn
& 0x1f) << 5)
5619 | ((insn
& 0x3e0) >> 5));
5620 /* If this is a jump to a 32 bit routine, then make
5622 if (other
!= STO_MIPS16
)
5624 bfd_put_16 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5627 else if (r_type
== R_MIPS16_GPREL
)
5629 unsigned short extend
, insn
;
5631 unsigned long final
;
5633 /* Extract the addend into buf, run the regular reloc,
5634 and stuff the resulting value back into the
5636 if (rel
->r_offset
> input_section
->_raw_size
)
5637 r
= bfd_reloc_outofrange
;
5640 extend
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5641 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 2);
5642 bfd_put_32 (input_bfd
,
5643 (((extend
& 0x1f) << 11)
5647 r
= _bfd_final_link_relocate (howto
, input_bfd
,
5649 (bfd_vma
) 0, relocation
,
5651 final
= bfd_get_32 (input_bfd
, buf
);
5652 bfd_put_16 (input_bfd
,
5654 | ((final
>> 11) & 0x1f)
5656 contents
+ rel
->r_offset
);
5657 bfd_put_16 (input_bfd
,
5660 contents
+ rel
->r_offset
+ 2);
5663 /* start-sanitize-sky */
5664 else if (r_type
== R_MIPS_DVP_U15_S3
)
5666 if (rel
->r_offset
> input_section
->_raw_size
)
5667 r
= bfd_reloc_outofrange
;
5672 relocation
+= rel
->r_addend
;
5675 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5676 relocation
+= ((x
& (0xf << 21)) >> 10) + (x
& 0x7ff);
5677 x
&= ~ ((0xf << 21) | 0x7ff);
5678 x
|= (((relocation
& 0x7800) << 10)
5679 | (relocation
& 0x7ff));
5680 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
5682 if (relocation
& ~ (bfd_vma
) 0x7fff)
5683 r
= bfd_reloc_overflow
;
5688 /* end-sanitize-sky */
5690 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5691 contents
, rel
->r_offset
,
5692 relocation
, addend
);
5694 /* The jal instruction can only jump to an address which is
5695 divisible by 4, and it can only jump to an address with
5696 the same upper 4 bits as the PC. */
5697 if (r
== bfd_reloc_ok
5698 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
))
5703 if (other
== STO_MIPS16
)
5704 addr
&= ~ (bfd_vma
) 1;
5707 || ((addr
& 0xf0000000)
5708 != ((input_section
->output_section
->vma
5709 + input_section
->output_offset
5712 r
= bfd_reloc_overflow
;
5715 /* Don't bother to report a relocation overflow for a call
5716 to a weak undefined symbol with a value of zero. This
5719 even if we aren't in range to call address zero. */
5720 if (r
== bfd_reloc_overflow
5721 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
)
5722 && relocation
+ addend
== 0
5724 && h
->root
.type
== bfd_link_hash_undefweak
)
5727 /* If we've already issued an error for an undefined symbol,
5728 don't issue another useless error. */
5730 && (r
== bfd_reloc_undefined
|| r
== bfd_reloc_overflow
))
5733 if (SGI_COMPAT (abfd
)
5735 && (input_section
->flags
& SEC_ALLOC
) != 0)
5737 Elf32_crinfo cptrel
;
5740 /* Make an entry of compact relocation info. */
5741 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5742 cptrel
.vaddr
= (rel
->r_offset
5743 + input_section
->output_section
->vma
5744 + input_section
->output_offset
);
5749 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
5750 /* XXX How should we set dist2to in this case. */
5751 mips_elf_set_cr_dist2to (cptrel
, 8);
5752 cptrel
.konst
= addend
+ relocation
;
5753 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5754 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5755 ((Elf32_External_crinfo
*) cr
5756 + scpt
->reloc_count
));
5757 ++scpt
->reloc_count
;
5760 case R_MIPS_GPREL16
:
5761 case R_MIPS_LITERAL
:
5762 case R_MIPS_GPREL32
:
5763 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
5764 cptrel
.konst
= gp
- cptrel
.vaddr
;
5765 mips_elf_set_cr_dist2to (cptrel
, 4);
5766 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5767 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5768 ((Elf32_External_crinfo
*) cr
5769 + scpt
->reloc_count
));
5770 ++scpt
->reloc_count
;
5779 if (r
!= bfd_reloc_ok
)
5784 case bfd_reloc_outofrange
:
5786 case bfd_reloc_overflow
:
5791 name
= h
->root
.root
.string
;
5794 name
= bfd_elf_string_from_elf_section (input_bfd
,
5795 symtab_hdr
->sh_link
,
5800 name
= bfd_section_name (input_bfd
, sec
);
5802 if (! ((*info
->callbacks
->reloc_overflow
)
5803 (info
, name
, howto
->name
, (bfd_vma
) 0,
5804 input_bfd
, input_section
, rel
->r_offset
)))
5815 /* This hook function is called before the linker writes out a global
5816 symbol. We mark symbols as small common if appropriate. This is
5817 also where we undo the increment of the value for a mips16 symbol. */
5821 mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
5823 struct bfd_link_info
*info
;
5825 Elf_Internal_Sym
*sym
;
5826 asection
*input_sec
;
5828 /* If we see a common symbol, which implies a relocatable link, then
5829 if a symbol was small common in an input file, mark it as small
5830 common in the output file. */
5831 if (sym
->st_shndx
== SHN_COMMON
5832 && strcmp (input_sec
->name
, ".scommon") == 0)
5833 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
5835 if (sym
->st_other
== STO_MIPS16
5836 && (sym
->st_value
& 1) != 0)
5842 /* Functions for the dynamic linker. */
5844 /* The name of the dynamic interpreter. This is put in the .interp
5847 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
5849 /* Create dynamic sections when linking against a dynamic object. */
5852 mips_elf_create_dynamic_sections (abfd
, info
)
5854 struct bfd_link_info
*info
;
5856 struct elf_link_hash_entry
*h
;
5858 register asection
*s
;
5859 const char * const *namep
;
5861 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5862 | SEC_LINKER_CREATED
| SEC_READONLY
);
5864 /* Mips ABI requests the .dynamic section to be read only. */
5865 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5868 if (! bfd_set_section_flags (abfd
, s
, flags
))
5872 /* We need to create .got section. */
5873 if (! mips_elf_create_got_section (abfd
, info
))
5876 /* Create .stub section. */
5877 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
5879 s
= bfd_make_section (abfd
, ".stub");
5881 || ! bfd_set_section_flags (abfd
, s
, flags
)
5882 || ! bfd_set_section_alignment (abfd
, s
, 2))
5886 if (SGI_COMPAT (abfd
)
5888 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
5890 s
= bfd_make_section (abfd
, ".rld_map");
5892 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
5893 || ! bfd_set_section_alignment (abfd
, s
, 2))
5897 if (SGI_COMPAT (abfd
))
5899 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
5902 if (! (_bfd_generic_link_add_one_symbol
5903 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
5904 (bfd_vma
) 0, (const char *) NULL
, false,
5905 get_elf_backend_data (abfd
)->collect
,
5906 (struct bfd_link_hash_entry
**) &h
)))
5908 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5909 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5910 h
->type
= STT_SECTION
;
5912 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5916 /* We need to create a .compact_rel section. */
5917 if (! mips_elf_create_compact_rel_section (abfd
, info
))
5920 /* Change aligments of some sections. */
5921 s
= bfd_get_section_by_name (abfd
, ".hash");
5923 bfd_set_section_alignment (abfd
, s
, 4);
5924 s
= bfd_get_section_by_name (abfd
, ".dynsym");
5926 bfd_set_section_alignment (abfd
, s
, 4);
5927 s
= bfd_get_section_by_name (abfd
, ".dynstr");
5929 bfd_set_section_alignment (abfd
, s
, 4);
5930 s
= bfd_get_section_by_name (abfd
, ".reginfo");
5932 bfd_set_section_alignment (abfd
, s
, 4);
5933 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5935 bfd_set_section_alignment (abfd
, s
, 4);
5941 if (! (_bfd_generic_link_add_one_symbol
5942 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
5943 (bfd_vma
) 0, (const char *) NULL
, false,
5944 get_elf_backend_data (abfd
)->collect
,
5945 (struct bfd_link_hash_entry
**) &h
)))
5947 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5948 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5949 h
->type
= STT_SECTION
;
5951 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5954 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
5956 /* __rld_map is a four byte word located in the .data section
5957 and is filled in by the rtld to contain a pointer to
5958 the _r_debug structure. Its symbol value will be set in
5959 mips_elf_finish_dynamic_symbol. */
5960 s
= bfd_get_section_by_name (abfd
, ".rld_map");
5961 BFD_ASSERT (s
!= NULL
);
5964 if (! (_bfd_generic_link_add_one_symbol
5965 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
5966 (bfd_vma
) 0, (const char *) NULL
, false,
5967 get_elf_backend_data (abfd
)->collect
,
5968 (struct bfd_link_hash_entry
**) &h
)))
5970 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5971 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5972 h
->type
= STT_OBJECT
;
5974 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5982 /* Create the .compact_rel section. */
5985 mips_elf_create_compact_rel_section (abfd
, info
)
5987 struct bfd_link_info
*info
;
5990 register asection
*s
;
5992 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
5994 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
5997 s
= bfd_make_section (abfd
, ".compact_rel");
5999 || ! bfd_set_section_flags (abfd
, s
, flags
)
6000 || ! bfd_set_section_alignment (abfd
, s
, 2))
6003 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
6009 /* Create the .got section to hold the global offset table. */
6012 mips_elf_create_got_section (abfd
, info
)
6014 struct bfd_link_info
*info
;
6017 register asection
*s
;
6018 struct elf_link_hash_entry
*h
;
6019 struct mips_got_info
*g
;
6021 /* This function may be called more than once. */
6022 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
6025 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6026 | SEC_LINKER_CREATED
);
6028 s
= bfd_make_section (abfd
, ".got");
6030 || ! bfd_set_section_flags (abfd
, s
, flags
)
6031 || ! bfd_set_section_alignment (abfd
, s
, 4))
6034 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
6035 linker script because we don't want to define the symbol if we
6036 are not creating a global offset table. */
6038 if (! (_bfd_generic_link_add_one_symbol
6039 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
6040 (bfd_vma
) 0, (const char *) NULL
, false,
6041 get_elf_backend_data (abfd
)->collect
,
6042 (struct bfd_link_hash_entry
**) &h
)))
6044 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6045 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6046 h
->type
= STT_OBJECT
;
6049 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6052 /* The first several global offset table entries are reserved. */
6053 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
6055 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
6056 sizeof (struct mips_got_info
));
6059 g
->global_gotsym
= 0;
6060 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
6061 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
6062 if (elf_section_data (s
) == NULL
)
6065 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
6066 if (elf_section_data (s
) == NULL
)
6069 elf_section_data (s
)->tdata
= (PTR
) g
;
6074 /* Look through the relocs for a section during the first phase, and
6075 allocate space in the global offset table. */
6078 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
6080 struct bfd_link_info
*info
;
6082 const Elf_Internal_Rela
*relocs
;
6086 Elf_Internal_Shdr
*symtab_hdr
;
6087 struct elf_link_hash_entry
**sym_hashes
;
6088 struct mips_got_info
*g
;
6090 const Elf_Internal_Rela
*rel
;
6091 const Elf_Internal_Rela
*rel_end
;
6095 if (info
->relocateable
)
6098 dynobj
= elf_hash_table (info
)->dynobj
;
6099 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6100 sym_hashes
= elf_sym_hashes (abfd
);
6101 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
6103 /* Check for the mips16 stub sections. */
6105 name
= bfd_get_section_name (abfd
, sec
);
6106 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
6108 unsigned long r_symndx
;
6110 /* Look at the relocation information to figure out which symbol
6113 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6115 if (r_symndx
< extsymoff
6116 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6120 /* This stub is for a local symbol. This stub will only be
6121 needed if there is some relocation in this BFD, other
6122 than a 16 bit function call, which refers to this symbol. */
6123 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6125 Elf_Internal_Rela
*sec_relocs
;
6126 const Elf_Internal_Rela
*r
, *rend
;
6128 /* We can ignore stub sections when looking for relocs. */
6129 if ((o
->flags
& SEC_RELOC
) == 0
6130 || o
->reloc_count
== 0
6131 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
6132 sizeof FN_STUB
- 1) == 0
6133 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
6134 sizeof CALL_STUB
- 1) == 0
6135 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
6136 sizeof CALL_FP_STUB
- 1) == 0)
6139 sec_relocs
= (_bfd_elf32_link_read_relocs
6140 (abfd
, o
, (PTR
) NULL
,
6141 (Elf_Internal_Rela
*) NULL
,
6142 info
->keep_memory
));
6143 if (sec_relocs
== NULL
)
6146 rend
= sec_relocs
+ o
->reloc_count
;
6147 for (r
= sec_relocs
; r
< rend
; r
++)
6148 if (ELF32_R_SYM (r
->r_info
) == r_symndx
6149 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
6152 if (! info
->keep_memory
)
6161 /* There is no non-call reloc for this stub, so we do
6162 not need it. Since this function is called before
6163 the linker maps input sections to output sections, we
6164 can easily discard it by setting the SEC_EXCLUDE
6166 sec
->flags
|= SEC_EXCLUDE
;
6170 /* Record this stub in an array of local symbol stubs for
6172 if (elf_tdata (abfd
)->local_stubs
== NULL
)
6174 unsigned long symcount
;
6177 if (elf_bad_symtab (abfd
))
6178 symcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
6180 symcount
= symtab_hdr
->sh_info
;
6181 n
= (asection
**) bfd_zalloc (abfd
,
6182 symcount
* sizeof (asection
*));
6185 elf_tdata (abfd
)->local_stubs
= n
;
6188 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
6190 /* We don't need to set mips16_stubs_seen in this case.
6191 That flag is used to see whether we need to look through
6192 the global symbol table for stubs. We don't need to set
6193 it here, because we just have a local stub. */
6197 struct mips_elf_link_hash_entry
*h
;
6199 h
= ((struct mips_elf_link_hash_entry
*)
6200 sym_hashes
[r_symndx
- extsymoff
]);
6202 /* H is the symbol this stub is for. */
6205 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6208 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
6209 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6211 unsigned long r_symndx
;
6212 struct mips_elf_link_hash_entry
*h
;
6215 /* Look at the relocation information to figure out which symbol
6218 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6220 if (r_symndx
< extsymoff
6221 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6223 /* This stub was actually built for a static symbol defined
6224 in the same file. We assume that all static symbols in
6225 mips16 code are themselves mips16, so we can simply
6226 discard this stub. Since this function is called before
6227 the linker maps input sections to output sections, we can
6228 easily discard it by setting the SEC_EXCLUDE flag. */
6229 sec
->flags
|= SEC_EXCLUDE
;
6233 h
= ((struct mips_elf_link_hash_entry
*)
6234 sym_hashes
[r_symndx
- extsymoff
]);
6236 /* H is the symbol this stub is for. */
6238 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6239 loc
= &h
->call_fp_stub
;
6241 loc
= &h
->call_stub
;
6243 /* If we already have an appropriate stub for this function, we
6244 don't need another one, so we can discard this one. Since
6245 this function is called before the linker maps input sections
6246 to output sections, we can easily discard it by setting the
6247 SEC_EXCLUDE flag. We can also discard this section if we
6248 happen to already know that this is a mips16 function; it is
6249 not necessary to check this here, as it is checked later, but
6250 it is slightly faster to check now. */
6251 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
6253 sec
->flags
|= SEC_EXCLUDE
;
6258 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6268 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6273 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6274 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6275 BFD_ASSERT (g
!= NULL
);
6281 rel_end
= relocs
+ sec
->reloc_count
;
6282 for (rel
= relocs
; rel
< rel_end
; rel
++)
6284 unsigned long r_symndx
;
6285 struct elf_link_hash_entry
*h
;
6287 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6289 if (r_symndx
< extsymoff
)
6293 h
= sym_hashes
[r_symndx
- extsymoff
];
6295 /* This may be an indirect symbol created because of a version. */
6298 while (h
->root
.type
== bfd_link_hash_indirect
)
6299 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6303 /* Some relocs require a global offset table. */
6304 if (dynobj
== NULL
|| sgot
== NULL
)
6306 switch (ELF32_R_TYPE (rel
->r_info
))
6310 case R_MIPS_CALL_HI16
:
6311 case R_MIPS_CALL_LO16
:
6312 case R_MIPS_GOT_HI16
:
6313 case R_MIPS_GOT_LO16
:
6315 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6316 if (! mips_elf_create_got_section (dynobj
, info
))
6318 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6319 BFD_ASSERT (sgot
!= NULL
);
6320 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6321 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6322 BFD_ASSERT (g
!= NULL
);
6328 && (info
->shared
|| h
!= NULL
)
6329 && (sec
->flags
& SEC_ALLOC
) != 0)
6330 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6338 switch (ELF32_R_TYPE (rel
->r_info
))
6341 case R_MIPS_CALL_HI16
:
6342 case R_MIPS_CALL_LO16
:
6343 /* This symbol requires a global offset table entry. */
6347 (*_bfd_error_handler
)
6348 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
6349 bfd_get_filename (abfd
), (unsigned long) rel
->r_offset
);
6350 bfd_set_error (bfd_error_bad_value
);
6354 /* Make sure this symbol is output as a dynamic symbol. */
6355 if (h
->dynindx
== -1)
6357 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6361 if (h
->got
.offset
!= (bfd_vma
) -1)
6363 /* We have already allocated space in the .got. */
6367 /* Note the index of the first global got symbol in .dynsym. */
6368 if (g
->global_gotsym
== 0
6369 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6370 g
->global_gotsym
= h
->dynindx
;
6372 /* Make this symbol to have the corresponding got entry. */
6375 /* We need a stub, not a plt entry for the undefined
6376 function. But we record it as if it needs plt. See
6377 elf_adjust_dynamic_symbol in elflink.h. */
6378 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6384 case R_MIPS_GOT_HI16
:
6385 case R_MIPS_GOT_LO16
:
6386 /* This symbol requires a global offset table entry. */
6390 /* Make sure this symbol is output as a dynamic symbol. */
6391 if (h
->dynindx
== -1)
6393 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6397 if (h
->got
.offset
!= (bfd_vma
) -1)
6399 /* We have already allocated space in the .got. */
6402 /* Note the index of the first global got symbol in
6404 if (g
->global_gotsym
== 0
6405 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6406 g
->global_gotsym
= h
->dynindx
;
6408 /* Make this symbol to be the global got symbol. */
6416 if ((info
->shared
|| h
!= NULL
)
6417 && (sec
->flags
& SEC_ALLOC
) != 0)
6421 const char *name
= ".rel.dyn";
6423 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6426 sreloc
= bfd_make_section (dynobj
, name
);
6428 || ! bfd_set_section_flags (dynobj
, sreloc
,
6433 | SEC_LINKER_CREATED
6435 || ! bfd_set_section_alignment (dynobj
, sreloc
,
6442 /* When creating a shared object, we must copy these
6443 reloc types into the output file as R_MIPS_REL32
6444 relocs. We make room for this reloc in the
6445 .rel.dyn reloc section */
6446 if (sreloc
->_raw_size
== 0)
6448 /* Add a null element. */
6449 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6450 ++sreloc
->reloc_count
;
6452 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6456 struct mips_elf_link_hash_entry
*hmips
;
6458 /* We only need to copy this reloc if the symbol is
6459 defined in a dynamic object. */
6460 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6461 ++hmips
->mips_32_relocs
;
6465 if (SGI_COMPAT (abfd
))
6466 mips_elf_hash_table (info
)->compact_rel_size
+=
6467 sizeof (Elf32_External_crinfo
);
6472 case R_MIPS_GPREL16
:
6473 case R_MIPS_LITERAL
:
6474 case R_MIPS_GPREL32
:
6475 if (SGI_COMPAT (abfd
))
6476 mips_elf_hash_table (info
)->compact_rel_size
+=
6477 sizeof (Elf32_External_crinfo
);
6480 /* This relocation describes the C++ object vtable hierarchy.
6481 Reconstruct it for later use during GC. */
6482 case R_MIPS_GNU_VTINHERIT
:
6483 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6487 /* This relocation describes which C++ vtable entries are actually
6488 used. Record for later use during GC. */
6489 case R_MIPS_GNU_VTENTRY
:
6490 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
6498 /* If this reloc is not a 16 bit call, and it has a global
6499 symbol, then we will need the fn_stub if there is one.
6500 References from a stub section do not count. */
6502 && ELF32_R_TYPE (rel
->r_info
) != R_MIPS16_26
6503 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
6504 sizeof FN_STUB
- 1) != 0
6505 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
6506 sizeof CALL_STUB
- 1) != 0
6507 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
6508 sizeof CALL_FP_STUB
- 1) != 0)
6510 struct mips_elf_link_hash_entry
*mh
;
6512 mh
= (struct mips_elf_link_hash_entry
*) h
;
6513 mh
->need_fn_stub
= true;
6520 /* Return the section that should be marked against GC for a given
6524 mips_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
6526 struct bfd_link_info
*info
;
6527 Elf_Internal_Rela
*rel
;
6528 struct elf_link_hash_entry
*h
;
6529 Elf_Internal_Sym
*sym
;
6531 /* ??? Do mips16 stub sections need to be handled special? */
6535 switch (ELF32_R_TYPE (rel
->r_info
))
6537 case R_MIPS_GNU_VTINHERIT
:
6538 case R_MIPS_GNU_VTENTRY
:
6542 switch (h
->root
.type
)
6544 case bfd_link_hash_defined
:
6545 case bfd_link_hash_defweak
:
6546 return h
->root
.u
.def
.section
;
6548 case bfd_link_hash_common
:
6549 return h
->root
.u
.c
.p
->section
;
6555 if (!(elf_bad_symtab (abfd
)
6556 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
6557 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
6558 && sym
->st_shndx
!= SHN_COMMON
))
6560 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
6567 /* Update the got entry reference counts for the section being removed. */
6570 mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
6572 struct bfd_link_info
*info
;
6574 const Elf_Internal_Rela
*relocs
;
6577 Elf_Internal_Shdr
*symtab_hdr
;
6578 struct elf_link_hash_entry
**sym_hashes
;
6579 bfd_signed_vma
*local_got_refcounts
;
6580 const Elf_Internal_Rela
*rel
, *relend
;
6581 unsigned long r_symndx
;
6582 struct elf_link_hash_entry
*h
;
6584 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6585 sym_hashes
= elf_sym_hashes (abfd
);
6586 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6588 relend
= relocs
+ sec
->reloc_count
;
6589 for (rel
= relocs
; rel
< relend
; rel
++)
6590 switch (ELF32_R_TYPE (rel
->r_info
))
6594 case R_MIPS_CALL_HI16
:
6595 case R_MIPS_CALL_LO16
:
6596 case R_MIPS_GOT_HI16
:
6597 case R_MIPS_GOT_LO16
:
6598 /* ??? It would seem that the existing MIPS code does no sort
6599 of reference counting or whatnot on its GOT and PLT entries,
6600 so it is not possible to garbage collect them at this time. */
6612 /* Adjust a symbol defined by a dynamic object and referenced by a
6613 regular object. The current definition is in some section of the
6614 dynamic object, but we're not including those sections. We have to
6615 change the definition to something the rest of the link can
6619 mips_elf_adjust_dynamic_symbol (info
, h
)
6620 struct bfd_link_info
*info
;
6621 struct elf_link_hash_entry
*h
;
6624 struct mips_elf_link_hash_entry
*hmips
;
6627 dynobj
= elf_hash_table (info
)->dynobj
;
6629 /* Make sure we know what is going on here. */
6630 BFD_ASSERT (dynobj
!= NULL
6631 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
6632 || h
->weakdef
!= NULL
6633 || ((h
->elf_link_hash_flags
6634 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
6635 && (h
->elf_link_hash_flags
6636 & ELF_LINK_HASH_REF_REGULAR
) != 0
6637 && (h
->elf_link_hash_flags
6638 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
6640 /* If this symbol is defined in a dynamic object, we need to copy
6641 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
6643 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6644 if (! info
->relocateable
6645 && hmips
->mips_32_relocs
!= 0
6646 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6648 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6649 BFD_ASSERT (s
!= NULL
);
6651 if (s
->_raw_size
== 0)
6653 /* Make room for a null element. */
6654 s
->_raw_size
+= sizeof (Elf32_External_Rel
);
6657 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
6660 /* For a function, create a stub, if needed. */
6661 if (h
->type
== STT_FUNC
6662 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
6664 if (! elf_hash_table (info
)->dynamic_sections_created
)
6667 /* If this symbol is not defined in a regular file, then set
6668 the symbol to the stub location. This is required to make
6669 function pointers compare as equal between the normal
6670 executable and the shared library. */
6671 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6673 /* We need .stub section. */
6674 s
= bfd_get_section_by_name (dynobj
, ".stub");
6675 BFD_ASSERT (s
!= NULL
);
6677 h
->root
.u
.def
.section
= s
;
6678 h
->root
.u
.def
.value
= s
->_raw_size
;
6680 /* XXX Write this stub address somewhere. */
6681 h
->plt
.offset
= s
->_raw_size
;
6683 /* Make room for this stub code. */
6684 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6686 /* The last half word of the stub will be filled with the index
6687 of this symbol in .dynsym section. */
6692 /* If this is a weak symbol, and there is a real definition, the
6693 processor independent code will have arranged for us to see the
6694 real definition first, and we can just use the same value. */
6695 if (h
->weakdef
!= NULL
)
6697 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
6698 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
6699 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
6700 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
6704 /* This is a reference to a symbol defined by a dynamic object which
6705 is not a function. */
6710 /* This function is called after all the input files have been read,
6711 and the input sections have been assigned to output sections. We
6712 check for any mips16 stub sections that we can discard. */
6714 static boolean mips_elf_check_mips16_stubs
6715 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
6718 mips_elf_always_size_sections (output_bfd
, info
)
6720 struct bfd_link_info
*info
;
6722 if (info
->relocateable
6723 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
6726 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
6727 mips_elf_check_mips16_stubs
,
6733 /* Check the mips16 stubs for a particular symbol, and see if we can
6738 mips_elf_check_mips16_stubs (h
, data
)
6739 struct mips_elf_link_hash_entry
*h
;
6742 if (h
->fn_stub
!= NULL
6743 && ! h
->need_fn_stub
)
6745 /* We don't need the fn_stub; the only references to this symbol
6746 are 16 bit calls. Clobber the size to 0 to prevent it from
6747 being included in the link. */
6748 h
->fn_stub
->_raw_size
= 0;
6749 h
->fn_stub
->_cooked_size
= 0;
6750 h
->fn_stub
->flags
&= ~ SEC_RELOC
;
6751 h
->fn_stub
->reloc_count
= 0;
6752 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
6755 if (h
->call_stub
!= NULL
6756 && h
->root
.other
== STO_MIPS16
)
6758 /* We don't need the call_stub; this is a 16 bit function, so
6759 calls from other 16 bit functions are OK. Clobber the size
6760 to 0 to prevent it from being included in the link. */
6761 h
->call_stub
->_raw_size
= 0;
6762 h
->call_stub
->_cooked_size
= 0;
6763 h
->call_stub
->flags
&= ~ SEC_RELOC
;
6764 h
->call_stub
->reloc_count
= 0;
6765 h
->call_stub
->flags
|= SEC_EXCLUDE
;
6768 if (h
->call_fp_stub
!= NULL
6769 && h
->root
.other
== STO_MIPS16
)
6771 /* We don't need the call_stub; this is a 16 bit function, so
6772 calls from other 16 bit functions are OK. Clobber the size
6773 to 0 to prevent it from being included in the link. */
6774 h
->call_fp_stub
->_raw_size
= 0;
6775 h
->call_fp_stub
->_cooked_size
= 0;
6776 h
->call_fp_stub
->flags
&= ~ SEC_RELOC
;
6777 h
->call_fp_stub
->reloc_count
= 0;
6778 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
6784 /* Set the sizes of the dynamic sections. */
6787 mips_elf_size_dynamic_sections (output_bfd
, info
)
6789 struct bfd_link_info
*info
;
6795 struct mips_got_info
*g
;
6797 dynobj
= elf_hash_table (info
)->dynobj
;
6798 BFD_ASSERT (dynobj
!= NULL
);
6800 if (elf_hash_table (info
)->dynamic_sections_created
)
6802 /* Set the contents of the .interp section to the interpreter. */
6805 s
= bfd_get_section_by_name (dynobj
, ".interp");
6806 BFD_ASSERT (s
!= NULL
);
6807 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
6808 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
6812 /* Recompute the size of .got for local entires (reserved and
6813 hipages) if needed. To estimate it, get the upper bound of total
6814 size of loadable sections. */
6815 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6819 bfd_size_type loadable_size
= 0;
6820 bfd_size_type local_gotno
;
6823 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6824 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6825 BFD_ASSERT (g
!= NULL
);
6827 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
6828 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
6830 if ((s
->flags
& SEC_ALLOC
) == 0)
6832 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
6835 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
6837 /* Assume there are two loadable segments consisting of
6838 contiguous sections. Is 5 enough? */
6839 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
6840 g
->local_gotno
= local_gotno
;
6841 sgot
->_raw_size
+= local_gotno
* 4;
6844 /* The check_relocs and adjust_dynamic_symbol entry points have
6845 determined the sizes of the various dynamic sections. Allocate
6848 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
6853 /* It's OK to base decisions on the section name, because none
6854 of the dynobj section names depend upon the input files. */
6855 name
= bfd_get_section_name (dynobj
, s
);
6857 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
6862 if (strncmp (name
, ".rel", 4) == 0)
6864 if (s
->_raw_size
== 0)
6866 /* We only strip the section if the output section name
6867 has the same name. Otherwise, there might be several
6868 input sections for this output section. FIXME: This
6869 code is probably not needed these days anyhow, since
6870 the linker now does not create empty output sections. */
6871 if (s
->output_section
!= NULL
6873 bfd_get_section_name (s
->output_section
->owner
,
6874 s
->output_section
)) == 0)
6879 const char *outname
;
6882 /* If this relocation section applies to a read only
6883 section, then we probably need a DT_TEXTREL entry.
6884 If the relocation section is .rel.dyn, we always
6885 assert a DT_TEXTREL entry rather than testing whether
6886 there exists a relocation to a read only section or
6888 outname
= bfd_get_section_name (output_bfd
,
6890 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
6892 && (target
->flags
& SEC_READONLY
) != 0
6893 && (target
->flags
& SEC_ALLOC
) != 0)
6894 || strcmp (outname
, ".rel.dyn") == 0)
6897 /* We use the reloc_count field as a counter if we need
6898 to copy relocs into the output file. */
6899 if (strcmp (name
, ".rel.dyn") != 0)
6903 else if (strncmp (name
, ".got", 4) == 0)
6907 BFD_ASSERT (elf_section_data (s
) != NULL
);
6908 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
6909 BFD_ASSERT (g
!= NULL
);
6911 /* Fix the size of .got section for the correspondence of
6912 global symbols and got entries. This adds some useless
6913 got entries. Is this required by ABI really? */
6914 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
6915 s
->_raw_size
+= i
* 4;
6917 else if (strncmp (name
, ".stub", 5) == 0)
6919 /* Irix rld assumes that the function stub isn't at the end
6920 of .text section. So put a dummy. XXX */
6921 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6923 else if (! info
->shared
6924 && ! mips_elf_hash_table (info
)->use_rld_obj_head
6925 && strncmp (name
, ".rld_map", 8) == 0)
6927 /* We add a room for __rld_map. It will be filled in by the
6928 rtld to contain a pointer to the _r_debug structure. */
6931 else if (SGI_COMPAT (output_bfd
)
6932 && strncmp (name
, ".compact_rel", 12) == 0)
6933 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
6934 else if (strncmp (name
, ".init", 5) != 0)
6936 /* It's not one of our sections, so don't allocate space. */
6944 for (spp
= &s
->output_section
->owner
->sections
;
6945 *spp
!= s
->output_section
;
6946 spp
= &(*spp
)->next
)
6948 *spp
= s
->output_section
->next
;
6949 --s
->output_section
->owner
->section_count
;
6954 /* Allocate memory for the section contents. */
6955 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
6956 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
6958 bfd_set_error (bfd_error_no_memory
);
6961 memset (s
->contents
, 0, s
->_raw_size
);
6964 if (elf_hash_table (info
)->dynamic_sections_created
)
6966 /* Add some entries to the .dynamic section. We fill in the
6967 values later, in elf_mips_finish_dynamic_sections, but we
6968 must add the entries now so that we get the correct size for
6969 the .dynamic section. The DT_DEBUG entry is filled in by the
6970 dynamic linker and used by the debugger. */
6973 if (SGI_COMPAT (output_bfd
))
6975 /* SGI object has the equivalence of DT_DEBUG in the
6976 DT_MIPS_RLD_MAP entry. */
6977 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
6981 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
6987 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
6991 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
6994 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
6996 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
6999 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
7002 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
7006 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
7009 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
7012 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
7014 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
7017 s
= bfd_get_section_by_name (dynobj
, ".liblist");
7018 BFD_ASSERT (s
!= NULL
);
7020 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
7024 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
7027 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
7031 /* Time stamps in executable files are a bad idea. */
7032 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
7037 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
7042 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
7046 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
7049 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
7052 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
7055 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
7058 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
7061 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
7064 #if 0 /* (SGI_COMPAT) */
7065 if (! bfd_get_section_by_name (dynobj
, ".init"))
7066 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
7069 if (! bfd_get_section_by_name (dynobj
, ".fini"))
7070 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
7075 /* If we use dynamic linking, we generate a section symbol for each
7076 output section. These are local symbols, which means that they
7077 must come first in the dynamic symbol table.
7078 That means we must increment the dynamic symbol index of every
7079 other dynamic symbol. */
7081 const char * const *namep
;
7083 bfd_size_type strindex
;
7084 struct bfd_strtab_hash
*dynstr
;
7085 struct mips_got_info
*g
;
7088 if (elf_hash_table (info
)->dynamic_sections_created
)
7090 if (SGI_COMPAT (output_bfd
))
7092 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
7093 elf_link_hash_traverse (elf_hash_table (info
),
7094 mips_elf_adjust_dynindx
,
7096 elf_hash_table (info
)->dynsymcount
+= c
;
7098 dynstr
= elf_hash_table (info
)->dynstr
;
7099 BFD_ASSERT (dynstr
!= NULL
);
7101 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
7105 s
= bfd_get_section_by_name (output_bfd
, *namep
);
7107 elf_section_data (s
)->dynindx
= i
;
7109 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
7110 if (strindex
== (bfd_size_type
) -1)
7113 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
7118 c
= bfd_count_sections (output_bfd
);
7119 elf_link_hash_traverse (elf_hash_table (info
),
7120 mips_elf_adjust_dynindx
,
7122 elf_hash_table (info
)->dynsymcount
+= c
;
7124 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
7126 elf_section_data (s
)->dynindx
= i
;
7127 /* These symbols will have no names, so we don't need to
7128 fiddle with dynstr_index. */
7135 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7136 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7137 BFD_ASSERT (g
!= NULL
);
7139 /* If there are no global got symbols, fake the last symbol so
7141 if (g
->global_gotsym
)
7142 g
->global_gotsym
+= c
;
7144 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
7151 /* Increment the index of a dynamic symbol by a given amount. Called
7152 via elf_link_hash_traverse. */
7155 mips_elf_adjust_dynindx (h
, cparg
)
7156 struct elf_link_hash_entry
*h
;
7159 unsigned int *cp
= (unsigned int *) cparg
;
7161 if (h
->dynindx
!= -1)
7166 /* Finish up dynamic symbol handling. We set the contents of various
7167 dynamic sections here. */
7170 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
7172 struct bfd_link_info
*info
;
7173 struct elf_link_hash_entry
*h
;
7174 Elf_Internal_Sym
*sym
;
7179 struct mips_got_info
*g
;
7182 dynobj
= elf_hash_table (info
)->dynobj
;
7183 gval
= sym
->st_value
;
7185 if (h
->plt
.offset
!= (bfd_vma
) -1)
7189 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
7191 /* This symbol has a stub. Set it up. */
7193 BFD_ASSERT (h
->dynindx
!= -1);
7195 s
= bfd_get_section_by_name (dynobj
, ".stub");
7196 BFD_ASSERT (s
!= NULL
);
7198 /* Fill the stub. */
7200 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
7202 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
7205 /* FIXME: Can h->dynindex be more than 64K? */
7206 if (h
->dynindx
& 0xffff0000)
7209 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
7211 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
7213 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
7214 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
7216 /* Mark the symbol as undefined. plt.offset != -1 occurs
7217 only for the referenced symbol. */
7218 sym
->st_shndx
= SHN_UNDEF
;
7220 /* The run-time linker uses the st_value field of the symbol
7221 to reset the global offset table entry for this external
7222 to its stub address when unlinking a shared object. */
7223 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
7224 sym
->st_value
= gval
;
7227 BFD_ASSERT (h
->dynindx
!= -1);
7229 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7230 BFD_ASSERT (sgot
!= NULL
);
7231 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7232 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7233 BFD_ASSERT (g
!= NULL
);
7235 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
7237 bfd_size_type offset
;
7239 /* This symbol has an entry in the global offset table. Set its
7240 value to the corresponding got entry, if needed. */
7241 if (h
->got
.offset
== (bfd_vma
) -1)
7243 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
7244 BFD_ASSERT (g
->local_gotno
* 4 <= offset
7245 && offset
< sgot
->_raw_size
);
7246 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
7250 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7251 name
= h
->root
.root
.string
;
7252 if (strcmp (name
, "_DYNAMIC") == 0
7253 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
7254 sym
->st_shndx
= SHN_ABS
;
7255 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
7257 sym
->st_shndx
= SHN_ABS
;
7258 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7261 else if (SGI_COMPAT (output_bfd
))
7263 if (strcmp (name
, "_gp_disp") == 0)
7265 sym
->st_shndx
= SHN_ABS
;
7266 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7267 sym
->st_value
= elf_gp (output_bfd
);
7269 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
7270 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
7272 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7273 sym
->st_other
= STO_PROTECTED
;
7275 sym
->st_shndx
= SHN_MIPS_DATA
;
7277 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
7279 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7280 sym
->st_other
= STO_PROTECTED
;
7281 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
7282 sym
->st_shndx
= SHN_ABS
;
7284 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
7286 if (h
->type
== STT_FUNC
)
7287 sym
->st_shndx
= SHN_MIPS_TEXT
;
7288 else if (h
->type
== STT_OBJECT
)
7289 sym
->st_shndx
= SHN_MIPS_DATA
;
7293 if (SGI_COMPAT (output_bfd
)
7296 if (! mips_elf_hash_table (info
)->use_rld_obj_head
7297 && strcmp (name
, "__rld_map") == 0)
7299 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7300 BFD_ASSERT (s
!= NULL
);
7301 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
7302 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
7303 if (mips_elf_hash_table (info
)->rld_value
== 0)
7304 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7306 else if (mips_elf_hash_table (info
)->use_rld_obj_head
7307 && strcmp (name
, "__rld_obj_head") == 0)
7309 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7310 BFD_ASSERT (s
!= NULL
);
7311 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7315 /* If this is a mips16 symbol, force the value to be even. */
7316 if (sym
->st_other
== STO_MIPS16
7317 && (sym
->st_value
& 1) != 0)
7323 /* Finish up the dynamic sections. */
7326 mips_elf_finish_dynamic_sections (output_bfd
, info
)
7328 struct bfd_link_info
*info
;
7333 struct mips_got_info
*g
;
7335 dynobj
= elf_hash_table (info
)->dynobj
;
7337 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
7339 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7344 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7345 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7346 BFD_ASSERT (g
!= NULL
);
7349 if (elf_hash_table (info
)->dynamic_sections_created
)
7351 Elf32_External_Dyn
*dyncon
, *dynconend
;
7353 BFD_ASSERT (sdyn
!= NULL
);
7354 BFD_ASSERT (g
!= NULL
);
7356 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7357 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
7358 for (; dyncon
< dynconend
; dyncon
++)
7360 Elf_Internal_Dyn dyn
;
7365 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
7373 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7374 BFD_ASSERT (s
!= NULL
);
7375 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
7376 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7380 /* Rewrite DT_STRSZ. */
7382 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
7383 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7389 case DT_MIPS_CONFLICT
:
7392 case DT_MIPS_LIBLIST
:
7395 s
= bfd_get_section_by_name (output_bfd
, name
);
7396 BFD_ASSERT (s
!= NULL
);
7397 dyn
.d_un
.d_ptr
= s
->vma
;
7398 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7401 case DT_MIPS_RLD_VERSION
:
7402 dyn
.d_un
.d_val
= 1; /* XXX */
7403 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7407 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
7408 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7411 case DT_MIPS_CONFLICTNO
:
7413 elemsize
= sizeof (Elf32_Conflict
);
7416 case DT_MIPS_LIBLISTNO
:
7418 elemsize
= sizeof (Elf32_Lib
);
7420 s
= bfd_get_section_by_name (output_bfd
, name
);
7423 if (s
->_cooked_size
!= 0)
7424 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7426 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7431 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7434 case DT_MIPS_TIME_STAMP
:
7435 time ((time_t *) &dyn
.d_un
.d_val
);
7436 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7439 case DT_MIPS_ICHECKSUM
:
7443 case DT_MIPS_IVERSION
:
7447 case DT_MIPS_BASE_ADDRESS
:
7448 s
= output_bfd
->sections
;
7449 BFD_ASSERT (s
!= NULL
);
7450 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
7451 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7454 case DT_MIPS_LOCAL_GOTNO
:
7455 dyn
.d_un
.d_val
= g
->local_gotno
;
7456 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7459 case DT_MIPS_SYMTABNO
:
7461 elemsize
= sizeof (Elf32_External_Sym
);
7462 s
= bfd_get_section_by_name (output_bfd
, name
);
7463 BFD_ASSERT (s
!= NULL
);
7465 if (s
->_cooked_size
!= 0)
7466 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7468 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7469 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7472 case DT_MIPS_UNREFEXTNO
:
7474 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
7475 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7478 case DT_MIPS_GOTSYM
:
7479 dyn
.d_un
.d_val
= g
->global_gotsym
;
7480 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7483 case DT_MIPS_HIPAGENO
:
7484 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
7485 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7488 case DT_MIPS_RLD_MAP
:
7489 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
7490 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7497 /* The first entry of the global offset table will be filled at
7498 runtime. The second entry will be used by some runtime loaders.
7499 This isn't the case of Irix rld. */
7500 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
7502 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
7503 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
7507 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
7514 Elf_Internal_Sym sym
;
7517 const char * const * namep
= mips_elf_dynsym_sec_names
;
7518 Elf32_compact_rel cpt
;
7520 /* Set up the section symbols for the output sections. SGI sets
7521 the STT_NOTYPE attribute for these symbols. Should we do so? */
7523 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
7524 if (sdynsym
!= NULL
)
7526 if (SGI_COMPAT (output_bfd
))
7530 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7536 while ((name
= *namep
++) != NULL
)
7538 s
= bfd_get_section_by_name (output_bfd
, name
);
7541 sym
.st_value
= s
->vma
;
7542 dindx
= elf_section_data (s
)->dynindx
;
7543 last
= s
->vma
+ s
->_raw_size
;
7547 sym
.st_value
= last
;
7551 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
7556 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
7558 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7559 (((Elf32_External_Sym
*)
7564 /* Set the sh_info field of the output .dynsym section to
7565 the index of the first global symbol. */
7566 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7567 SIZEOF_MIPS_DYNSYM_SECNAMES
;
7573 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
7576 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
7580 sym
.st_value
= s
->vma
;
7582 indx
= elf_section_data (s
)->this_idx
;
7583 BFD_ASSERT (indx
> 0);
7584 sym
.st_shndx
= indx
;
7586 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7587 (((Elf32_External_Sym
*)
7589 + elf_section_data (s
)->dynindx
));
7592 /* Set the sh_info field of the output .dynsym section to
7593 the index of the first global symbol. */
7594 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7595 bfd_count_sections (output_bfd
) + 1;
7599 if (SGI_COMPAT (output_bfd
))
7601 /* Write .compact_rel section out. */
7602 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
7606 cpt
.num
= s
->reloc_count
;
7608 cpt
.offset
= (s
->output_section
->filepos
7609 + sizeof (Elf32_External_compact_rel
));
7612 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
7613 ((Elf32_External_compact_rel
*)
7616 /* Clean up a dummy stub function entry in .text. */
7617 s
= bfd_get_section_by_name (dynobj
, ".stub");
7620 file_ptr dummy_offset
;
7622 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
7623 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
7624 memset (s
->contents
+ dummy_offset
, 0,
7625 MIPS_FUNCTION_STUB_SIZE
);
7630 /* Clean up a first relocation in .rel.dyn. */
7631 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7632 if (s
!= NULL
&& s
->_raw_size
> 0)
7633 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
7639 /* This is almost identical to bfd_generic_get_... except that some
7640 MIPS relocations need to be handled specially. Sigh. */
7643 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
7644 relocateable
, symbols
)
7646 struct bfd_link_info
*link_info
;
7647 struct bfd_link_order
*link_order
;
7649 boolean relocateable
;
7652 /* Get enough memory to hold the stuff */
7653 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
7654 asection
*input_section
= link_order
->u
.indirect
.section
;
7656 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
7657 arelent
**reloc_vector
= NULL
;
7663 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
7664 if (reloc_vector
== NULL
&& reloc_size
!= 0)
7667 /* read in the section */
7668 if (!bfd_get_section_contents (input_bfd
,
7672 input_section
->_raw_size
))
7675 /* We're not relaxing the section, so just copy the size info */
7676 input_section
->_cooked_size
= input_section
->_raw_size
;
7677 input_section
->reloc_done
= true;
7679 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
7683 if (reloc_count
< 0)
7686 if (reloc_count
> 0)
7691 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
7694 struct bfd_hash_entry
*h
;
7695 struct bfd_link_hash_entry
*lh
;
7696 /* Skip all this stuff if we aren't mixing formats. */
7697 if (abfd
&& input_bfd
7698 && abfd
->xvec
== input_bfd
->xvec
)
7702 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
7703 lh
= (struct bfd_link_hash_entry
*) h
;
7710 case bfd_link_hash_undefined
:
7711 case bfd_link_hash_undefweak
:
7712 case bfd_link_hash_common
:
7715 case bfd_link_hash_defined
:
7716 case bfd_link_hash_defweak
:
7718 gp
= lh
->u
.def
.value
;
7720 case bfd_link_hash_indirect
:
7721 case bfd_link_hash_warning
:
7723 /* @@FIXME ignoring warning for now */
7725 case bfd_link_hash_new
:
7734 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
7737 char *error_message
= (char *) NULL
;
7738 bfd_reloc_status_type r
;
7740 /* Specific to MIPS: Deal with relocation types that require
7741 knowing the gp of the output bfd. */
7742 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
7743 if (bfd_is_abs_section (sym
->section
) && abfd
)
7745 /* The special_function wouldn't get called anyways. */
7749 /* The gp isn't there; let the special function code
7750 fall over on its own. */
7752 else if ((*parent
)->howto
->special_function
7753 == _bfd_mips_elf_gprel16_reloc
)
7755 /* bypass special_function call */
7756 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
7757 relocateable
, (PTR
) data
, gp
);
7758 goto skip_bfd_perform_relocation
;
7760 /* end mips specific stuff */
7762 r
= bfd_perform_relocation (input_bfd
,
7766 relocateable
? abfd
: (bfd
*) NULL
,
7768 skip_bfd_perform_relocation
:
7772 asection
*os
= input_section
->output_section
;
7774 /* A partial link, so keep the relocs */
7775 os
->orelocation
[os
->reloc_count
] = *parent
;
7779 if (r
!= bfd_reloc_ok
)
7783 case bfd_reloc_undefined
:
7784 if (!((*link_info
->callbacks
->undefined_symbol
)
7785 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7786 input_bfd
, input_section
, (*parent
)->address
)))
7789 case bfd_reloc_dangerous
:
7790 BFD_ASSERT (error_message
!= (char *) NULL
);
7791 if (!((*link_info
->callbacks
->reloc_dangerous
)
7792 (link_info
, error_message
, input_bfd
, input_section
,
7793 (*parent
)->address
)))
7796 case bfd_reloc_overflow
:
7797 if (!((*link_info
->callbacks
->reloc_overflow
)
7798 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7799 (*parent
)->howto
->name
, (*parent
)->addend
,
7800 input_bfd
, input_section
, (*parent
)->address
)))
7803 case bfd_reloc_outofrange
:
7812 if (reloc_vector
!= NULL
)
7813 free (reloc_vector
);
7817 if (reloc_vector
!= NULL
)
7818 free (reloc_vector
);
7821 #define bfd_elf32_bfd_get_relocated_section_contents \
7822 elf32_mips_get_relocated_section_contents
7824 /* ECOFF swapping routines. These are used when dealing with the
7825 .mdebug section, which is in the ECOFF debugging format. */
7826 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
7828 /* Symbol table magic number. */
7830 /* Alignment of debugging information. E.g., 4. */
7832 /* Sizes of external symbolic information. */
7833 sizeof (struct hdr_ext
),
7834 sizeof (struct dnr_ext
),
7835 sizeof (struct pdr_ext
),
7836 sizeof (struct sym_ext
),
7837 sizeof (struct opt_ext
),
7838 sizeof (struct fdr_ext
),
7839 sizeof (struct rfd_ext
),
7840 sizeof (struct ext_ext
),
7841 /* Functions to swap in external symbolic data. */
7850 _bfd_ecoff_swap_tir_in
,
7851 _bfd_ecoff_swap_rndx_in
,
7852 /* Functions to swap out external symbolic data. */
7861 _bfd_ecoff_swap_tir_out
,
7862 _bfd_ecoff_swap_rndx_out
,
7863 /* Function to read in symbolic data. */
7864 _bfd_mips_elf_read_ecoff_info
7867 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
7868 #define TARGET_LITTLE_NAME "elf32-littlemips"
7869 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
7870 #define TARGET_BIG_NAME "elf32-bigmips"
7871 #define ELF_ARCH bfd_arch_mips
7872 #define ELF_MACHINE_CODE EM_MIPS
7874 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
7875 a value of 0x1000, and we are compatible. */
7876 #define ELF_MAXPAGESIZE 0x1000
7878 #define elf_backend_collect true
7879 #define elf_backend_type_change_ok true
7880 #define elf_backend_can_gc_sections true
7881 #define elf_info_to_howto 0
7882 #define elf_info_to_howto_rel mips_info_to_howto_rel
7883 #define elf_backend_sym_is_global mips_elf_sym_is_global
7884 #define elf_backend_object_p mips_elf32_object_p
7885 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
7886 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
7887 #define elf_backend_section_from_bfd_section \
7888 _bfd_mips_elf_section_from_bfd_section
7889 #define elf_backend_section_processing mips_elf32_section_processing
7890 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
7891 #define elf_backend_additional_program_headers \
7892 mips_elf_additional_program_headers
7893 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
7894 #define elf_backend_final_write_processing \
7895 _bfd_mips_elf_final_write_processing
7896 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
7898 #define bfd_elf32_bfd_is_local_label_name \
7899 mips_elf_is_local_label_name
7900 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
7901 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
7902 #define bfd_elf32_bfd_link_hash_table_create \
7903 mips_elf_link_hash_table_create
7904 #define bfd_elf32_bfd_final_link mips_elf_final_link
7905 #define bfd_elf32_bfd_copy_private_bfd_data \
7906 _bfd_mips_elf_copy_private_bfd_data
7907 #define bfd_elf32_bfd_merge_private_bfd_data \
7908 _bfd_mips_elf_merge_private_bfd_data
7909 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
7910 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
7911 #define elf_backend_create_dynamic_sections \
7912 mips_elf_create_dynamic_sections
7913 #define elf_backend_check_relocs mips_elf_check_relocs
7914 #define elf_backend_adjust_dynamic_symbol \
7915 mips_elf_adjust_dynamic_symbol
7916 #define elf_backend_always_size_sections \
7917 mips_elf_always_size_sections
7918 #define elf_backend_size_dynamic_sections \
7919 mips_elf_size_dynamic_sections
7920 #define elf_backend_relocate_section mips_elf_relocate_section
7921 #define elf_backend_link_output_symbol_hook \
7922 mips_elf_link_output_symbol_hook
7923 #define elf_backend_finish_dynamic_symbol \
7924 mips_elf_finish_dynamic_symbol
7925 #define elf_backend_finish_dynamic_sections \
7926 mips_elf_finish_dynamic_sections
7927 #define elf_backend_gc_mark_hook mips_elf_gc_mark_hook
7928 #define elf_backend_gc_sweep_hook mips_elf_gc_sweep_hook
7930 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
7931 #define elf_backend_plt_header_size 0
7933 #include "elf32-target.h"