1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
4 Most of the information added by Ian Lance Taylor, Cygnus Support,
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 /* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
24 different MIPS ELF from other targets. This matters when linking.
25 This file supports both, switching at runtime. */
35 /* Get the ECOFF swapping routines. */
37 #include "coff/symconst.h"
38 #include "coff/internal.h"
39 #include "coff/ecoff.h"
40 #include "coff/mips.h"
42 #include "ecoffswap.h"
44 static bfd_reloc_status_type mips32_64bit_reloc
45 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
46 static reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
47 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
48 static void mips_info_to_howto_rel
49 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
50 static void bfd_mips_elf32_swap_gptab_in
51 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
52 static void bfd_mips_elf32_swap_gptab_out
53 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
54 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
55 static boolean mips_elf32_object_p
PARAMS ((bfd
*));
56 static boolean mips_elf_create_procedure_table
57 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
58 struct ecoff_debug_info
*));
59 static int mips_elf_additional_program_headers
PARAMS ((bfd
*));
60 static boolean mips_elf_modify_segment_map
PARAMS ((bfd
*));
61 static INLINE
int elf_mips_isa
PARAMS ((flagword
));
62 static INLINE
int elf_mips_mach
PARAMS ((flagword
));
63 static boolean mips_elf32_section_from_shdr
64 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, char *));
65 static boolean mips_elf32_section_processing
66 PARAMS ((bfd
*, Elf32_Internal_Shdr
*));
67 static boolean mips_elf_is_local_label_name
68 PARAMS ((bfd
*, const char *));
69 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
70 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
71 static struct bfd_link_hash_table
*mips_elf_link_hash_table_create
73 static int gptab_compare
PARAMS ((const void *, const void *));
74 static boolean mips_elf_final_link
75 PARAMS ((bfd
*, struct bfd_link_info
*));
76 static void mips_elf_relocate_hi16
77 PARAMS ((bfd
*, Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_byte
*,
79 static boolean mips_elf_relocate_got_local
80 PARAMS ((bfd
*, bfd
*, asection
*, Elf_Internal_Rela
*,
81 Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
82 static void mips_elf_relocate_global_got
83 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
84 static bfd_reloc_status_type mips16_jump_reloc
85 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
86 static bfd_reloc_status_type mips16_gprel_reloc
87 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
88 /* start-sanitize-sky */
89 static bfd_reloc_status_type dvp_u15_s3_reloc
90 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
91 /* end-sanitize-sky */
92 static boolean mips_elf_adjust_dynindx
93 PARAMS ((struct elf_link_hash_entry
*, PTR
));
94 static boolean mips_elf_relocate_section
95 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
96 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
97 static boolean mips_elf_link_output_symbol_hook
98 PARAMS ((bfd
*, struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
100 static boolean mips_elf_create_dynamic_sections
101 PARAMS ((bfd
*, struct bfd_link_info
*));
102 static boolean mips_elf_create_compact_rel_section
103 PARAMS ((bfd
*, struct bfd_link_info
*));
104 static boolean mips_elf_create_got_section
105 PARAMS ((bfd
*, struct bfd_link_info
*));
106 static boolean mips_elf_check_relocs
107 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
108 const Elf_Internal_Rela
*));
109 static boolean mips_elf_adjust_dynamic_symbol
110 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
111 static boolean mips_elf_always_size_sections
112 PARAMS ((bfd
*, struct bfd_link_info
*));
113 static boolean mips_elf_size_dynamic_sections
114 PARAMS ((bfd
*, struct bfd_link_info
*));
115 static boolean mips_elf_finish_dynamic_symbol
116 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
117 Elf_Internal_Sym
*));
118 static boolean mips_elf_finish_dynamic_sections
119 PARAMS ((bfd
*, struct bfd_link_info
*));
120 static boolean mips_elf_add_symbol_hook
121 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
122 const char **, flagword
*, asection
**, bfd_vma
*));
123 static bfd_reloc_status_type mips_elf_final_gp
124 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
125 static bfd_byte
*elf32_mips_get_relocated_section_contents
126 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
127 bfd_byte
*, boolean
, asymbol
**));
129 /* This is true for Irix 5 executables, false for normal MIPS ELF ABI
130 executables. FIXME: At the moment, we default to always generating
131 Irix 5 executables. */
133 #define SGI_COMPAT(abfd) (1)
135 /* This structure is used to hold .got information when linking. It
136 is stored in the tdata field of the bfd_elf_section_data structure. */
140 /* The symbol index of the first global .got symbol. */
141 unsigned long global_gotsym
;
142 /* The number of local .got entries. */
143 unsigned int local_gotno
;
144 /* The number of local .got entries we have used. */
145 unsigned int assigned_gotno
;
148 /* The number of local .got entries we reserve. */
149 #define MIPS_RESERVED_GOTNO (2)
151 /* Instructions which appear in a stub. For some reason the stub is
152 slightly different on an SGI system. */
153 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
154 #define STUB_LW(abfd) \
156 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
157 : 0x8f998000) /* lw t9,0x8000(gp) */
158 #define STUB_MOVE 0x03e07825 /* move t7,ra */
159 #define STUB_JALR 0x0320f809 /* jal t9 */
160 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
161 #define MIPS_FUNCTION_STUB_SIZE (16)
163 /* Names of sections which appear in the .dynsym section in an Irix 5
166 static const char * const mips_elf_dynsym_sec_names
[] =
179 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
180 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
182 /* The number of entries in mips_elf_dynsym_sec_names which go in the
185 #define MIPS_TEXT_DYNSYM_SECNO (3)
187 /* The names of the runtime procedure table symbols used on Irix 5. */
189 static const char * const mips_elf_dynsym_rtproc_names
[] =
192 "_procedure_string_table",
193 "_procedure_table_size",
197 /* These structures are used to generate the .compact_rel section on
202 unsigned long id1
; /* Always one? */
203 unsigned long num
; /* Number of compact relocation entries. */
204 unsigned long id2
; /* Always two? */
205 unsigned long offset
; /* The file offset of the first relocation. */
206 unsigned long reserved0
; /* Zero? */
207 unsigned long reserved1
; /* Zero? */
216 bfd_byte reserved0
[4];
217 bfd_byte reserved1
[4];
218 } Elf32_External_compact_rel
;
222 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
223 unsigned int rtype
: 4; /* Relocation types. See below. */
224 unsigned int dist2to
: 8;
225 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
226 unsigned long konst
; /* KONST field. See below. */
227 unsigned long vaddr
; /* VADDR to be relocated. */
232 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
233 unsigned int rtype
: 4; /* Relocation types. See below. */
234 unsigned int dist2to
: 8;
235 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
236 unsigned long konst
; /* KONST field. See below. */
244 } Elf32_External_crinfo
;
250 } Elf32_External_crinfo2
;
252 /* These are the constants used to swap the bitfields in a crinfo. */
254 #define CRINFO_CTYPE (0x1)
255 #define CRINFO_CTYPE_SH (31)
256 #define CRINFO_RTYPE (0xf)
257 #define CRINFO_RTYPE_SH (27)
258 #define CRINFO_DIST2TO (0xff)
259 #define CRINFO_DIST2TO_SH (19)
260 #define CRINFO_RELVADDR (0x7ffff)
261 #define CRINFO_RELVADDR_SH (0)
263 /* A compact relocation info has long (3 words) or short (2 words)
264 formats. A short format doesn't have VADDR field and relvaddr
265 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
266 #define CRF_MIPS_LONG 1
267 #define CRF_MIPS_SHORT 0
269 /* There are 4 types of compact relocation at least. The value KONST
270 has different meaning for each type:
273 CT_MIPS_REL32 Address in data
274 CT_MIPS_WORD Address in word (XXX)
275 CT_MIPS_GPHI_LO GP - vaddr
276 CT_MIPS_JMPAD Address to jump
279 #define CRT_MIPS_REL32 0xa
280 #define CRT_MIPS_WORD 0xb
281 #define CRT_MIPS_GPHI_LO 0xc
282 #define CRT_MIPS_JMPAD 0xd
284 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
285 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
286 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
287 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
289 static void bfd_elf32_swap_compact_rel_out
290 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
291 static void bfd_elf32_swap_crinfo_out
292 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
294 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
296 static reloc_howto_type elf_mips_howto_table
[] =
299 HOWTO (R_MIPS_NONE
, /* type */
301 0, /* size (0 = byte, 1 = short, 2 = long) */
303 false, /* pc_relative */
305 complain_overflow_dont
, /* complain_on_overflow */
306 bfd_elf_generic_reloc
, /* special_function */
307 "R_MIPS_NONE", /* name */
308 false, /* partial_inplace */
311 false), /* pcrel_offset */
313 /* 16 bit relocation. */
314 HOWTO (R_MIPS_16
, /* type */
316 1, /* size (0 = byte, 1 = short, 2 = long) */
318 false, /* pc_relative */
320 complain_overflow_bitfield
, /* complain_on_overflow */
321 bfd_elf_generic_reloc
, /* special_function */
322 "R_MIPS_16", /* name */
323 true, /* partial_inplace */
324 0xffff, /* src_mask */
325 0xffff, /* dst_mask */
326 false), /* pcrel_offset */
328 /* 32 bit relocation. */
329 HOWTO (R_MIPS_32
, /* type */
331 2, /* size (0 = byte, 1 = short, 2 = long) */
333 false, /* pc_relative */
335 complain_overflow_bitfield
, /* complain_on_overflow */
336 bfd_elf_generic_reloc
, /* special_function */
337 "R_MIPS_32", /* name */
338 true, /* partial_inplace */
339 0xffffffff, /* src_mask */
340 0xffffffff, /* dst_mask */
341 false), /* pcrel_offset */
343 /* 32 bit symbol relative relocation. */
344 HOWTO (R_MIPS_REL32
, /* type */
346 2, /* size (0 = byte, 1 = short, 2 = long) */
348 false, /* pc_relative */
350 complain_overflow_bitfield
, /* complain_on_overflow */
351 bfd_elf_generic_reloc
, /* special_function */
352 "R_MIPS_REL32", /* name */
353 true, /* partial_inplace */
354 0xffffffff, /* src_mask */
355 0xffffffff, /* dst_mask */
356 false), /* pcrel_offset */
358 /* 26 bit branch address. */
359 HOWTO (R_MIPS_26
, /* type */
361 2, /* size (0 = byte, 1 = short, 2 = long) */
363 false, /* pc_relative */
365 complain_overflow_dont
, /* complain_on_overflow */
366 /* This needs complex overflow
367 detection, because the upper four
368 bits must match the PC. */
369 bfd_elf_generic_reloc
, /* special_function */
370 "R_MIPS_26", /* name */
371 true, /* partial_inplace */
372 0x3ffffff, /* src_mask */
373 0x3ffffff, /* dst_mask */
374 false), /* pcrel_offset */
376 /* High 16 bits of symbol value. */
377 HOWTO (R_MIPS_HI16
, /* type */
379 2, /* size (0 = byte, 1 = short, 2 = long) */
381 false, /* pc_relative */
383 complain_overflow_dont
, /* complain_on_overflow */
384 _bfd_mips_elf_hi16_reloc
, /* special_function */
385 "R_MIPS_HI16", /* name */
386 true, /* partial_inplace */
387 0xffff, /* src_mask */
388 0xffff, /* dst_mask */
389 false), /* pcrel_offset */
391 /* Low 16 bits of symbol value. */
392 HOWTO (R_MIPS_LO16
, /* type */
394 2, /* size (0 = byte, 1 = short, 2 = long) */
396 false, /* pc_relative */
398 complain_overflow_dont
, /* complain_on_overflow */
399 _bfd_mips_elf_lo16_reloc
, /* special_function */
400 "R_MIPS_LO16", /* name */
401 true, /* partial_inplace */
402 0xffff, /* src_mask */
403 0xffff, /* dst_mask */
404 false), /* pcrel_offset */
406 /* GP relative reference. */
407 HOWTO (R_MIPS_GPREL16
, /* type */
409 2, /* size (0 = byte, 1 = short, 2 = long) */
411 false, /* pc_relative */
413 complain_overflow_signed
, /* complain_on_overflow */
414 _bfd_mips_elf_gprel16_reloc
, /* special_function */
415 "R_MIPS_GPREL16", /* name */
416 true, /* partial_inplace */
417 0xffff, /* src_mask */
418 0xffff, /* dst_mask */
419 false), /* pcrel_offset */
421 /* Reference to literal section. */
422 HOWTO (R_MIPS_LITERAL
, /* type */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
426 false, /* pc_relative */
428 complain_overflow_signed
, /* complain_on_overflow */
429 _bfd_mips_elf_gprel16_reloc
, /* special_function */
430 "R_MIPS_LITERAL", /* name */
431 true, /* partial_inplace */
432 0xffff, /* src_mask */
433 0xffff, /* dst_mask */
434 false), /* pcrel_offset */
436 /* Reference to global offset table. */
437 HOWTO (R_MIPS_GOT16
, /* type */
439 2, /* size (0 = byte, 1 = short, 2 = long) */
441 false, /* pc_relative */
443 complain_overflow_signed
, /* complain_on_overflow */
444 _bfd_mips_elf_got16_reloc
, /* special_function */
445 "R_MIPS_GOT16", /* name */
446 false, /* partial_inplace */
448 0xffff, /* dst_mask */
449 false), /* pcrel_offset */
451 /* 16 bit PC relative reference. */
452 HOWTO (R_MIPS_PC16
, /* type */
454 2, /* size (0 = byte, 1 = short, 2 = long) */
456 true, /* pc_relative */
458 complain_overflow_signed
, /* complain_on_overflow */
459 bfd_elf_generic_reloc
, /* special_function */
460 "R_MIPS_PC16", /* name */
461 true, /* partial_inplace */
462 0xffff, /* src_mask */
463 0xffff, /* dst_mask */
464 false), /* pcrel_offset */
466 /* 16 bit call through global offset table. */
467 /* FIXME: This is not handled correctly. */
468 HOWTO (R_MIPS_CALL16
, /* type */
470 2, /* size (0 = byte, 1 = short, 2 = long) */
472 false, /* pc_relative */
474 complain_overflow_signed
, /* complain_on_overflow */
475 bfd_elf_generic_reloc
, /* special_function */
476 "R_MIPS_CALL16", /* name */
477 false, /* partial_inplace */
479 0xffff, /* dst_mask */
480 false), /* pcrel_offset */
482 /* 32 bit GP relative reference. */
483 HOWTO (R_MIPS_GPREL32
, /* type */
485 2, /* size (0 = byte, 1 = short, 2 = long) */
487 false, /* pc_relative */
489 complain_overflow_bitfield
, /* complain_on_overflow */
490 _bfd_mips_elf_gprel32_reloc
, /* special_function */
491 "R_MIPS_GPREL32", /* name */
492 true, /* partial_inplace */
493 0xffffffff, /* src_mask */
494 0xffffffff, /* dst_mask */
495 false), /* pcrel_offset */
497 /* The remaining relocs are defined on Irix 5, although they are
498 not defined by the ABI. */
503 /* A 5 bit shift field. */
504 HOWTO (R_MIPS_SHIFT5
, /* type */
506 2, /* size (0 = byte, 1 = short, 2 = long) */
508 false, /* pc_relative */
510 complain_overflow_bitfield
, /* complain_on_overflow */
511 bfd_elf_generic_reloc
, /* special_function */
512 "R_MIPS_SHIFT5", /* name */
513 true, /* partial_inplace */
514 0x000007c0, /* src_mask */
515 0x000007c0, /* dst_mask */
516 false), /* pcrel_offset */
518 /* A 6 bit shift field. */
519 /* FIXME: This is not handled correctly; a special function is
520 needed to put the most significant bit in the right place. */
521 HOWTO (R_MIPS_SHIFT6
, /* type */
523 2, /* size (0 = byte, 1 = short, 2 = long) */
525 false, /* pc_relative */
527 complain_overflow_bitfield
, /* complain_on_overflow */
528 bfd_elf_generic_reloc
, /* special_function */
529 "R_MIPS_SHIFT6", /* name */
530 true, /* partial_inplace */
531 0x000007c4, /* src_mask */
532 0x000007c4, /* dst_mask */
533 false), /* pcrel_offset */
535 /* A 64 bit relocation. This is used in 32 bit ELF when addresses
536 are 64 bits long; the upper 32 bits are simply a sign extension.
537 The fields of the howto should be the same as for R_MIPS_32,
538 other than the type, name, and special_function. */
539 HOWTO (R_MIPS_64
, /* type */
541 2, /* size (0 = byte, 1 = short, 2 = long) */
543 false, /* pc_relative */
545 complain_overflow_bitfield
, /* complain_on_overflow */
546 mips32_64bit_reloc
, /* special_function */
547 "R_MIPS_64", /* name */
548 true, /* partial_inplace */
549 0xffffffff, /* src_mask */
550 0xffffffff, /* dst_mask */
551 false), /* pcrel_offset */
553 /* Displacement in the global offset table. */
554 /* FIXME: Not handled correctly. */
555 HOWTO (R_MIPS_GOT_DISP
, /* type */
557 2, /* size (0 = byte, 1 = short, 2 = long) */
559 false, /* pc_relative */
561 complain_overflow_bitfield
, /* complain_on_overflow */
562 bfd_elf_generic_reloc
, /* special_function */
563 "R_MIPS_GOT_DISP", /* name */
564 true, /* partial_inplace */
565 0x0000ffff, /* src_mask */
566 0x0000ffff, /* dst_mask */
567 false), /* pcrel_offset */
569 /* Displacement to page pointer in the global offset table. */
570 /* FIXME: Not handled correctly. */
571 HOWTO (R_MIPS_GOT_PAGE
, /* type */
573 2, /* size (0 = byte, 1 = short, 2 = long) */
575 false, /* pc_relative */
577 complain_overflow_bitfield
, /* complain_on_overflow */
578 bfd_elf_generic_reloc
, /* special_function */
579 "R_MIPS_GOT_PAGE", /* name */
580 true, /* partial_inplace */
581 0x0000ffff, /* src_mask */
582 0x0000ffff, /* dst_mask */
583 false), /* pcrel_offset */
585 /* Offset from page pointer in the global offset table. */
586 /* FIXME: Not handled correctly. */
587 HOWTO (R_MIPS_GOT_OFST
, /* type */
589 2, /* size (0 = byte, 1 = short, 2 = long) */
591 false, /* pc_relative */
593 complain_overflow_bitfield
, /* complain_on_overflow */
594 bfd_elf_generic_reloc
, /* special_function */
595 "R_MIPS_GOT_OFST", /* name */
596 true, /* partial_inplace */
597 0x0000ffff, /* src_mask */
598 0x0000ffff, /* dst_mask */
599 false), /* pcrel_offset */
601 /* High 16 bits of displacement in global offset table. */
602 /* FIXME: Not handled correctly. */
603 HOWTO (R_MIPS_GOT_HI16
, /* type */
605 2, /* size (0 = byte, 1 = short, 2 = long) */
607 false, /* pc_relative */
609 complain_overflow_dont
, /* complain_on_overflow */
610 bfd_elf_generic_reloc
, /* special_function */
611 "R_MIPS_GOT_HI16", /* name */
612 true, /* partial_inplace */
613 0x0000ffff, /* src_mask */
614 0x0000ffff, /* dst_mask */
615 false), /* pcrel_offset */
617 /* Low 16 bits of displacement in global offset table. */
618 /* FIXME: Not handled correctly. */
619 HOWTO (R_MIPS_GOT_LO16
, /* type */
621 2, /* size (0 = byte, 1 = short, 2 = long) */
623 false, /* pc_relative */
625 complain_overflow_dont
, /* complain_on_overflow */
626 bfd_elf_generic_reloc
, /* special_function */
627 "R_MIPS_GOT_LO16", /* name */
628 true, /* partial_inplace */
629 0x0000ffff, /* src_mask */
630 0x0000ffff, /* dst_mask */
631 false), /* pcrel_offset */
633 /* 64 bit subtraction. Presumably not used in 32 bit ELF. */
636 /* Used to cause the linker to insert and delete instructions? */
641 /* Get the higher values of a 64 bit addend. Presumably not used in
646 /* High 16 bits of displacement in global offset table. */
647 /* FIXME: Not handled correctly. */
648 HOWTO (R_MIPS_CALL_HI16
, /* type */
650 2, /* size (0 = byte, 1 = short, 2 = long) */
652 false, /* pc_relative */
654 complain_overflow_dont
, /* complain_on_overflow */
655 bfd_elf_generic_reloc
, /* special_function */
656 "R_MIPS_CALL_HI16", /* name */
657 true, /* partial_inplace */
658 0x0000ffff, /* src_mask */
659 0x0000ffff, /* dst_mask */
660 false), /* pcrel_offset */
662 /* Low 16 bits of displacement in global offset table. */
663 /* FIXME: Not handled correctly. */
664 HOWTO (R_MIPS_CALL_LO16
, /* type */
666 2, /* size (0 = byte, 1 = short, 2 = long) */
668 false, /* pc_relative */
670 complain_overflow_dont
, /* complain_on_overflow */
671 bfd_elf_generic_reloc
, /* special_function */
672 "R_MIPS_CALL_LO16", /* name */
673 true, /* partial_inplace */
674 0x0000ffff, /* src_mask */
675 0x0000ffff, /* dst_mask */
676 false), /* pcrel_offset */
678 /* start-sanitize-r5900 */
679 HOWTO (R_MIPS15_S3
, /* type */
681 2, /* size (0 = byte, 1 = short, 2 = long) */
683 false, /* pc_relative */
685 complain_overflow_bitfield
, /* complain_on_overflow */
686 bfd_elf_generic_reloc
, /* special_function */
687 "R_MIPS15_S3", /* name */
688 true, /* partial_inplace */
689 0x001fffc0, /* src_mask */
690 0x001fffc0, /* dst_mask */
691 false) /* pcrel_offset */
692 /* end-sanitize-r5900 */
696 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
697 is a hack to make the linker think that we need 64 bit values. */
698 static reloc_howto_type elf_mips_ctor64_howto
=
699 HOWTO (R_MIPS_64
, /* type */
701 4, /* size (0 = byte, 1 = short, 2 = long) */
703 false, /* pc_relative */
705 complain_overflow_signed
, /* complain_on_overflow */
706 mips32_64bit_reloc
, /* special_function */
707 "R_MIPS_64", /* name */
708 true, /* partial_inplace */
709 0xffffffff, /* src_mask */
710 0xffffffff, /* dst_mask */
711 false); /* pcrel_offset */
713 /* The reloc used for the mips16 jump instruction. */
714 static reloc_howto_type elf_mips16_jump_howto
=
715 HOWTO (R_MIPS16_26
, /* type */
717 2, /* size (0 = byte, 1 = short, 2 = long) */
719 false, /* pc_relative */
721 complain_overflow_dont
, /* complain_on_overflow */
722 /* This needs complex overflow
723 detection, because the upper four
724 bits must match the PC. */
725 mips16_jump_reloc
, /* special_function */
726 "R_MIPS16_26", /* name */
727 true, /* partial_inplace */
728 0x3ffffff, /* src_mask */
729 0x3ffffff, /* dst_mask */
730 false); /* pcrel_offset */
732 /* The reloc used for the mips16 gprel instruction. The src_mask and
733 dsk_mask for this howto do not reflect the actual instruction, in
734 which the value is not contiguous; the masks are for the
735 convenience of the relocate_section routine. */
736 static reloc_howto_type elf_mips16_gprel_howto
=
737 HOWTO (R_MIPS16_GPREL
, /* type */
739 2, /* size (0 = byte, 1 = short, 2 = long) */
741 false, /* pc_relative */
743 complain_overflow_signed
, /* complain_on_overflow */
744 mips16_gprel_reloc
, /* special_function */
745 "R_MIPS16_GPREL", /* name */
746 true, /* partial_inplace */
747 0xffff, /* src_mask */
748 0xffff, /* dst_mask */
749 false); /* pcrel_offset */
751 /* start-sanitize-sky */
753 Note that partial_inplace and pcrel_offset are backwards from the
754 mips port. This is intentional as it seems more reasonable. */
755 static reloc_howto_type elf_mips_dvp_11_pcrel_howto
=
756 HOWTO (R_MIPS_DVP_11_PCREL
, /* type */
758 2, /* size (0 = byte, 1 = short, 2 = long) */
760 true, /* pc_relative */
762 complain_overflow_signed
, /* complain_on_overflow */
763 bfd_elf_generic_reloc
, /* special_function */
764 "R_MIPS_DVP_11_PCREL", /* name */
765 false, /* partial_inplace */
766 0x7ff, /* src_mask */
767 0x7ff, /* dst_mask */
768 true); /* pcrel_offset */
769 static reloc_howto_type elf_mips_dvp_27_s4_howto
=
770 HOWTO (R_MIPS_DVP_27_S4
, /* type */
772 2, /* size (0 = byte, 1 = short, 2 = long) */
774 false, /* pc_relative */
776 complain_overflow_unsigned
, /* complain_on_overflow */
777 bfd_elf_generic_reloc
, /* special_function */
778 "R_MIPS_DVP_27_S4", /* name */
779 false, /* partial_inplace */
780 0x7ffffff0, /* src_mask */
781 0x7ffffff0, /* dst_mask */
782 false); /* pcrel_offset */
783 static reloc_howto_type elf_mips_dvp_11_s4_howto
=
784 HOWTO (R_MIPS_DVP_11_S4
, /* type */
786 2, /* size (0 = byte, 1 = short, 2 = long) */
788 false, /* pc_relative */
790 complain_overflow_signed
, /* complain_on_overflow */
791 bfd_elf_generic_reloc
, /* special_function */
792 "R_MIPS_DVP_11_S4", /* name */
793 false, /* partial_inplace */
794 0x03ff, /* src_mask */
795 0x03ff, /* dst_mask */
796 false); /* pcrel_offset */
797 static reloc_howto_type elf_mips_dvp_u15_s3_howto
=
798 HOWTO (R_MIPS_DVP_U15_S3
, /* type */
800 2, /* size (0 = byte, 1 = short, 2 = long) */
802 false, /* pc_relative */
804 complain_overflow_unsigned
, /* complain_on_overflow */
805 dvp_u15_s3_reloc
, /* special_function */
806 "R_MIPS_DVP_U15_S3", /* name */
807 false, /* partial_inplace */
808 0xf03ff, /* src_mask */
809 0xf03ff, /* dst_mask */
810 false); /* pcrel_offset */
811 /* end-sanitize-sky */
813 /* GNU extension to record C++ vtable hierarchy */
814 static reloc_howto_type elf_mips_gnu_vtinherit_howto
=
815 HOWTO (R_MIPS_GNU_VTINHERIT
, /* type */
817 2, /* size (0 = byte, 1 = short, 2 = long) */
819 false, /* pc_relative */
821 complain_overflow_dont
, /* complain_on_overflow */
822 NULL
, /* special_function */
823 "R_MIPS_GNU_VTINHERIT", /* name */
824 false, /* partial_inplace */
827 false); /* pcrel_offset */
829 /* GNU extension to record C++ vtable member usage */
830 static reloc_howto_type elf_mips_gnu_vtentry_howto
=
831 HOWTO (R_MIPS_GNU_VTENTRY
, /* type */
833 2, /* size (0 = byte, 1 = short, 2 = long) */
835 false, /* pc_relative */
837 complain_overflow_dont
, /* complain_on_overflow */
838 NULL
, /* special_function */
839 "R_MIPS_GNU_VTENTRY", /* name */
840 false, /* partial_inplace */
843 false); /* pcrel_offset */
845 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
846 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
847 the HI16. Here we just save the information we need; we do the
848 actual relocation when we see the LO16. MIPS ELF requires that the
849 LO16 immediately follow the HI16. As a GNU extension, we permit an
850 arbitrary number of HI16 relocs to be associated with a single LO16
851 reloc. This extension permits gcc to output the HI and LO relocs
856 struct mips_hi16
*next
;
861 /* FIXME: This should not be a static variable. */
863 static struct mips_hi16
*mips_hi16_list
;
865 bfd_reloc_status_type
866 _bfd_mips_elf_hi16_reloc (abfd
,
874 arelent
*reloc_entry
;
877 asection
*input_section
;
879 char **error_message
;
881 bfd_reloc_status_type ret
;
885 /* If we're relocating, and this an external symbol, we don't want
886 to change anything. */
887 if (output_bfd
!= (bfd
*) NULL
888 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
889 && reloc_entry
->addend
== 0)
891 reloc_entry
->address
+= input_section
->output_offset
;
897 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
899 boolean relocateable
;
902 if (ret
== bfd_reloc_undefined
)
905 if (output_bfd
!= NULL
)
909 relocateable
= false;
910 output_bfd
= symbol
->section
->output_section
->owner
;
913 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
915 if (ret
!= bfd_reloc_ok
)
918 relocation
= gp
- reloc_entry
->address
;
922 if (bfd_is_und_section (symbol
->section
)
923 && output_bfd
== (bfd
*) NULL
)
924 ret
= bfd_reloc_undefined
;
926 if (bfd_is_com_section (symbol
->section
))
929 relocation
= symbol
->value
;
932 relocation
+= symbol
->section
->output_section
->vma
;
933 relocation
+= symbol
->section
->output_offset
;
934 relocation
+= reloc_entry
->addend
;
936 if (reloc_entry
->address
> input_section
->_cooked_size
)
937 return bfd_reloc_outofrange
;
939 /* Save the information, and let LO16 do the actual relocation. */
940 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
942 return bfd_reloc_outofrange
;
943 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
944 n
->addend
= relocation
;
945 n
->next
= mips_hi16_list
;
948 if (output_bfd
!= (bfd
*) NULL
)
949 reloc_entry
->address
+= input_section
->output_offset
;
954 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
955 inplace relocation; this function exists in order to do the
956 R_MIPS_HI16 relocation described above. */
958 bfd_reloc_status_type
959 _bfd_mips_elf_lo16_reloc (abfd
,
967 arelent
*reloc_entry
;
970 asection
*input_section
;
972 char **error_message
;
974 arelent gp_disp_relent
;
976 if (mips_hi16_list
!= NULL
)
986 struct mips_hi16
*next
;
988 /* Do the HI16 relocation. Note that we actually don't need
989 to know anything about the LO16 itself, except where to
990 find the low 16 bits of the addend needed by the LO16. */
991 insn
= bfd_get_32 (abfd
, l
->addr
);
992 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
994 val
= ((insn
& 0xffff) << 16) + vallo
;
997 /* The low order 16 bits are always treated as a signed
998 value. Therefore, a negative value in the low order bits
999 requires an adjustment in the high order bits. We need
1000 to make this adjustment in two ways: once for the bits we
1001 took from the data, and once for the bits we are putting
1002 back in to the data. */
1003 if ((vallo
& 0x8000) != 0)
1005 if ((val
& 0x8000) != 0)
1008 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
1009 bfd_put_32 (abfd
, insn
, l
->addr
);
1011 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1013 gp_disp_relent
= *reloc_entry
;
1014 reloc_entry
= &gp_disp_relent
;
1015 reloc_entry
->addend
= l
->addend
;
1023 mips_hi16_list
= NULL
;
1025 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1027 bfd_reloc_status_type ret
;
1028 bfd_vma gp
, relocation
;
1030 /* FIXME: Does this case ever occur? */
1032 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
1033 if (ret
!= bfd_reloc_ok
)
1036 relocation
= gp
- reloc_entry
->address
;
1037 relocation
+= symbol
->section
->output_section
->vma
;
1038 relocation
+= symbol
->section
->output_offset
;
1039 relocation
+= reloc_entry
->addend
;
1041 if (reloc_entry
->address
> input_section
->_cooked_size
)
1042 return bfd_reloc_outofrange
;
1044 gp_disp_relent
= *reloc_entry
;
1045 reloc_entry
= &gp_disp_relent
;
1046 reloc_entry
->addend
= relocation
- 4;
1049 /* Now do the LO16 reloc in the usual way. */
1050 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1051 input_section
, output_bfd
, error_message
);
1054 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1055 table used for PIC code. If the symbol is an external symbol, the
1056 instruction is modified to contain the offset of the appropriate
1057 entry in the global offset table. If the symbol is a section
1058 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1059 addends are combined to form the real addend against the section
1060 symbol; the GOT16 is modified to contain the offset of an entry in
1061 the global offset table, and the LO16 is modified to offset it
1062 appropriately. Thus an offset larger than 16 bits requires a
1063 modified value in the global offset table.
1065 This implementation suffices for the assembler, but the linker does
1066 not yet know how to create global offset tables. */
1068 bfd_reloc_status_type
1069 _bfd_mips_elf_got16_reloc (abfd
,
1077 arelent
*reloc_entry
;
1080 asection
*input_section
;
1082 char **error_message
;
1084 /* If we're relocating, and this an external symbol, we don't want
1085 to change anything. */
1086 if (output_bfd
!= (bfd
*) NULL
1087 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1088 && reloc_entry
->addend
== 0)
1090 reloc_entry
->address
+= input_section
->output_offset
;
1091 return bfd_reloc_ok
;
1094 /* If we're relocating, and this is a local symbol, we can handle it
1096 if (output_bfd
!= (bfd
*) NULL
1097 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1098 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1099 input_section
, output_bfd
, error_message
);
1104 /* We have to figure out the gp value, so that we can adjust the
1105 symbol value correctly. We look up the symbol _gp in the output
1106 BFD. If we can't find it, we're stuck. We cache it in the ELF
1107 target data. We don't need to adjust the symbol value for an
1108 external symbol if we are producing relocateable output. */
1110 static bfd_reloc_status_type
1111 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1114 boolean relocateable
;
1115 char **error_message
;
1118 if (bfd_is_und_section (symbol
->section
)
1122 return bfd_reloc_undefined
;
1125 *pgp
= _bfd_get_gp_value (output_bfd
);
1128 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1132 /* Make up a value. */
1133 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1134 _bfd_set_gp_value (output_bfd
, *pgp
);
1142 count
= bfd_get_symcount (output_bfd
);
1143 sym
= bfd_get_outsymbols (output_bfd
);
1145 if (sym
== (asymbol
**) NULL
)
1149 for (i
= 0; i
< count
; i
++, sym
++)
1151 register CONST
char *name
;
1153 name
= bfd_asymbol_name (*sym
);
1154 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1156 *pgp
= bfd_asymbol_value (*sym
);
1157 _bfd_set_gp_value (output_bfd
, *pgp
);
1165 /* Only get the error once. */
1167 _bfd_set_gp_value (output_bfd
, *pgp
);
1169 (char *) _("GP relative relocation when _gp not defined");
1170 return bfd_reloc_dangerous
;
1175 return bfd_reloc_ok
;
1178 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1179 become the offset from the gp register. This function also handles
1180 R_MIPS_LITERAL relocations, although those can be handled more
1181 cleverly because the entries in the .lit8 and .lit4 sections can be
1184 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1185 arelent
*, asection
*,
1186 boolean
, PTR
, bfd_vma
));
1188 bfd_reloc_status_type
1189 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1190 output_bfd
, error_message
)
1192 arelent
*reloc_entry
;
1195 asection
*input_section
;
1197 char **error_message
;
1199 boolean relocateable
;
1200 bfd_reloc_status_type ret
;
1203 /* If we're relocating, and this is an external symbol with no
1204 addend, we don't want to change anything. We will only have an
1205 addend if this is a newly created reloc, not read from an ELF
1207 if (output_bfd
!= (bfd
*) NULL
1208 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1209 && reloc_entry
->addend
== 0)
1211 reloc_entry
->address
+= input_section
->output_offset
;
1212 return bfd_reloc_ok
;
1215 if (output_bfd
!= (bfd
*) NULL
)
1216 relocateable
= true;
1219 relocateable
= false;
1220 output_bfd
= symbol
->section
->output_section
->owner
;
1223 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1225 if (ret
!= bfd_reloc_ok
)
1228 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1229 relocateable
, data
, gp
);
1232 static bfd_reloc_status_type
1233 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1237 arelent
*reloc_entry
;
1238 asection
*input_section
;
1239 boolean relocateable
;
1247 if (bfd_is_com_section (symbol
->section
))
1250 relocation
= symbol
->value
;
1252 relocation
+= symbol
->section
->output_section
->vma
;
1253 relocation
+= symbol
->section
->output_offset
;
1255 if (reloc_entry
->address
> input_section
->_cooked_size
)
1256 return bfd_reloc_outofrange
;
1258 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1260 /* Set val to the offset into the section or symbol. */
1261 if (reloc_entry
->howto
->src_mask
== 0)
1263 /* This case occurs with the 64-bit MIPS ELF ABI. */
1264 val
= reloc_entry
->addend
;
1268 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1273 /* Adjust val for the final section location and GP value. If we
1274 are producing relocateable output, we don't want to do this for
1275 an external symbol. */
1277 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1278 val
+= relocation
- gp
;
1280 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1281 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1284 reloc_entry
->address
+= input_section
->output_offset
;
1286 /* Make sure it fit in 16 bits. */
1287 if (val
>= 0x8000 && val
< 0xffff8000)
1288 return bfd_reloc_overflow
;
1290 return bfd_reloc_ok
;
1293 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1294 from the gp register? XXX */
1296 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1297 arelent
*, asection
*,
1298 boolean
, PTR
, bfd_vma
));
1300 bfd_reloc_status_type
1301 _bfd_mips_elf_gprel32_reloc (abfd
,
1309 arelent
*reloc_entry
;
1312 asection
*input_section
;
1314 char **error_message
;
1316 boolean relocateable
;
1317 bfd_reloc_status_type ret
;
1320 /* If we're relocating, and this is an external symbol with no
1321 addend, we don't want to change anything. We will only have an
1322 addend if this is a newly created reloc, not read from an ELF
1324 if (output_bfd
!= (bfd
*) NULL
1325 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1326 && reloc_entry
->addend
== 0)
1328 *error_message
= (char *)
1329 _("32bits gp relative relocation occurs for an external symbol");
1330 return bfd_reloc_outofrange
;
1333 if (output_bfd
!= (bfd
*) NULL
)
1335 relocateable
= true;
1336 gp
= _bfd_get_gp_value (output_bfd
);
1340 relocateable
= false;
1341 output_bfd
= symbol
->section
->output_section
->owner
;
1343 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1344 error_message
, &gp
);
1345 if (ret
!= bfd_reloc_ok
)
1349 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1350 relocateable
, data
, gp
);
1353 static bfd_reloc_status_type
1354 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1358 arelent
*reloc_entry
;
1359 asection
*input_section
;
1360 boolean relocateable
;
1367 if (bfd_is_com_section (symbol
->section
))
1370 relocation
= symbol
->value
;
1372 relocation
+= symbol
->section
->output_section
->vma
;
1373 relocation
+= symbol
->section
->output_offset
;
1375 if (reloc_entry
->address
> input_section
->_cooked_size
)
1376 return bfd_reloc_outofrange
;
1378 if (reloc_entry
->howto
->src_mask
== 0)
1380 /* This case arises with the 64-bit MIPS ELF ABI. */
1384 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1386 /* Set val to the offset into the section or symbol. */
1387 val
+= reloc_entry
->addend
;
1389 /* Adjust val for the final section location and GP value. If we
1390 are producing relocateable output, we don't want to do this for
1391 an external symbol. */
1393 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1394 val
+= relocation
- gp
;
1396 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1399 reloc_entry
->address
+= input_section
->output_offset
;
1401 return bfd_reloc_ok
;
1404 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1405 generated when addreses are 64 bits. The upper 32 bits are a simle
1408 static bfd_reloc_status_type
1409 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1410 output_bfd
, error_message
)
1412 arelent
*reloc_entry
;
1415 asection
*input_section
;
1417 char **error_message
;
1419 bfd_reloc_status_type r
;
1424 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1425 input_section
, output_bfd
, error_message
);
1426 if (r
!= bfd_reloc_continue
)
1429 /* Do a normal 32 bit relocation on the lower 32 bits. */
1430 reloc32
= *reloc_entry
;
1431 if (bfd_big_endian (abfd
))
1432 reloc32
.address
+= 4;
1433 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1434 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1435 output_bfd
, error_message
);
1437 /* Sign extend into the upper 32 bits. */
1438 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1439 if ((val
& 0x80000000) != 0)
1443 addr
= reloc_entry
->address
;
1444 if (bfd_little_endian (abfd
))
1446 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1451 /* Handle a mips16 jump. */
1453 static bfd_reloc_status_type
1454 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1455 output_bfd
, error_message
)
1457 arelent
*reloc_entry
;
1460 asection
*input_section
;
1462 char **error_message
;
1464 if (output_bfd
!= (bfd
*) NULL
1465 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1466 && reloc_entry
->addend
== 0)
1468 reloc_entry
->address
+= input_section
->output_offset
;
1469 return bfd_reloc_ok
;
1474 static boolean warned
;
1477 (*_bfd_error_handler
)
1478 (_("Linking mips16 objects into %s format is not supported"),
1479 bfd_get_target (input_section
->output_section
->owner
));
1483 return bfd_reloc_undefined
;
1486 /* Handle a mips16 GP relative reloc. */
1488 static bfd_reloc_status_type
1489 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1490 output_bfd
, error_message
)
1492 arelent
*reloc_entry
;
1495 asection
*input_section
;
1497 char **error_message
;
1499 boolean relocateable
;
1500 bfd_reloc_status_type ret
;
1502 unsigned short extend
, insn
;
1503 unsigned long final
;
1505 /* If we're relocating, and this is an external symbol with no
1506 addend, we don't want to change anything. We will only have an
1507 addend if this is a newly created reloc, not read from an ELF
1509 if (output_bfd
!= NULL
1510 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1511 && reloc_entry
->addend
== 0)
1513 reloc_entry
->address
+= input_section
->output_offset
;
1514 return bfd_reloc_ok
;
1517 if (output_bfd
!= NULL
)
1518 relocateable
= true;
1521 relocateable
= false;
1522 output_bfd
= symbol
->section
->output_section
->owner
;
1525 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1527 if (ret
!= bfd_reloc_ok
)
1530 if (reloc_entry
->address
> input_section
->_cooked_size
)
1531 return bfd_reloc_outofrange
;
1533 /* Pick up the mips16 extend instruction and the real instruction. */
1534 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1535 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1537 /* Stuff the current addend back as a 32 bit value, do the usual
1538 relocation, and then clean up. */
1540 (((extend
& 0x1f) << 11)
1543 (bfd_byte
*) data
+ reloc_entry
->address
);
1545 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1546 relocateable
, data
, gp
);
1548 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1551 | ((final
>> 11) & 0x1f)
1553 (bfd_byte
*) data
+ reloc_entry
->address
);
1557 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1562 /* start-sanitize-sky */
1563 /* Handle a dvp R_MIPS_DVP_U15_S3 reloc.
1564 This is needed because the bits aren't contiguous. */
1566 static bfd_reloc_status_type
1567 dvp_u15_s3_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1568 output_bfd
, error_message
)
1570 arelent
*reloc_entry
;
1573 asection
*input_section
;
1575 char **error_message
;
1577 boolean relocateable
;
1578 bfd_reloc_status_type ret
;
1582 /* If we're relocating, and this is an external symbol with no
1583 addend, we don't want to change anything. We will only have an
1584 addend if this is a newly created reloc, not read from an ELF
1585 file. See bfd_elf_generic_reloc. */
1586 if (output_bfd
!= NULL
1587 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1588 /* partial_inplace is false, so this test always succeeds,
1589 but for clarity and consistency with bfd_elf_generic_reloc
1590 this is left as is. */
1591 && (! reloc_entry
->howto
->partial_inplace
1592 || reloc_entry
->addend
== 0))
1594 reloc_entry
->address
+= input_section
->output_offset
;
1595 return bfd_reloc_ok
;
1598 if (reloc_entry
->address
> input_section
->_cooked_size
)
1599 return bfd_reloc_outofrange
;
1601 relocation
= (symbol
->value
1602 + symbol
->section
->output_section
->vma
1603 + symbol
->section
->output_offset
);
1604 relocation
+= reloc_entry
->addend
;
1607 x
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1608 x
|= (((relocation
& 0x7800) << 10)
1609 | (relocation
& 0x7ff));
1610 bfd_put_32 (abfd
, x
, (bfd_byte
*) data
+ reloc_entry
->address
);
1612 if (relocation
& ~(bfd_vma
) 0x7fff)
1613 return bfd_reloc_overflow
;
1614 return bfd_reloc_ok
;
1617 /* end-sanitize-sky */
1618 /* Return the ISA for a MIPS e_flags value. */
1621 elf_mips_isa (flags
)
1624 switch (flags
& EF_MIPS_ARCH
)
1638 /* Return the MACH for a MIPS e_flags value. */
1641 elf_mips_mach (flags
)
1644 switch (flags
& EF_MIPS_MACH
)
1646 case E_MIPS_MACH_3900
:
1647 return bfd_mach_mips3900
;
1649 case E_MIPS_MACH_4010
:
1650 return bfd_mach_mips4010
;
1652 case E_MIPS_MACH_4100
:
1653 return bfd_mach_mips4100
;
1654 /* start-sanitize-vr4320 */
1656 case E_MIPS_MACH_4320
:
1657 return bfd_mach_mips4320
;
1658 /* end-sanitize-vr4320 */
1660 case E_MIPS_MACH_4650
:
1661 return bfd_mach_mips4650
;
1662 /* start-sanitize-tx49 */
1664 case E_MIPS_MACH_4900
:
1665 return bfd_mach_mips4900
;
1666 /* end-sanitize-tx49 */
1667 /* start-sanitize-vr5400 */
1669 case E_MIPS_MACH_5400
:
1670 return bfd_mach_mips5400
;
1671 /* end-sanitize-vr5400 */
1672 /* start-sanitize-r5900 */
1674 case E_MIPS_MACH_5900
:
1675 return bfd_mach_mips5900
;
1676 /* end-sanitize-r5900 */
1679 switch (flags
& EF_MIPS_ARCH
)
1683 return bfd_mach_mips3000
;
1687 return bfd_mach_mips6000
;
1691 return bfd_mach_mips4000
;
1695 return bfd_mach_mips8000
;
1703 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1705 struct elf_reloc_map
{
1706 bfd_reloc_code_real_type bfd_reloc_val
;
1707 enum elf_mips_reloc_type elf_reloc_val
;
1710 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1712 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1713 { BFD_RELOC_16
, R_MIPS_16
},
1714 { BFD_RELOC_32
, R_MIPS_32
},
1715 { BFD_RELOC_64
, R_MIPS_64
},
1716 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1717 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1718 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1719 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1720 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1721 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1722 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1723 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1724 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1725 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1726 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1727 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1728 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
},
1729 /* start-sanitize-r5900 */
1730 { BFD_RELOC_MIPS15_S3
, R_MIPS15_S3
},
1731 /* end-sanitize-r5900 */
1734 /* Given a BFD reloc type, return a howto structure. */
1736 static reloc_howto_type
*
1737 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1739 bfd_reloc_code_real_type code
;
1743 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1745 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1746 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1751 case BFD_RELOC_CTOR
:
1752 /* We need to handle BFD_RELOC_CTOR specially.
1753 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1754 size of addresses on this architecture. */
1755 if (bfd_arch_bits_per_address (abfd
) == 32)
1756 return &elf_mips_howto_table
[(int) R_MIPS_32
];
1758 return &elf_mips_ctor64_howto
;
1760 case BFD_RELOC_MIPS16_JMP
:
1761 return &elf_mips16_jump_howto
;
1762 case BFD_RELOC_MIPS16_GPREL
:
1763 return &elf_mips16_gprel_howto
;
1764 /* start-sanitize-sky */
1765 case BFD_RELOC_MIPS_DVP_11_PCREL
:
1766 return &elf_mips_dvp_11_pcrel_howto
;
1767 case BFD_RELOC_MIPS_DVP_27_S4
:
1768 return &elf_mips_dvp_27_s4_howto
;
1769 case BFD_RELOC_MIPS_DVP_11_S4
:
1770 return &elf_mips_dvp_11_s4_howto
;
1771 case BFD_RELOC_MIPS_DVP_U15_S3
:
1772 return &elf_mips_dvp_u15_s3_howto
;
1773 /* end-sanitize-sky */
1774 case BFD_RELOC_VTABLE_INHERIT
:
1775 return &elf_mips_gnu_vtinherit_howto
;
1776 case BFD_RELOC_VTABLE_ENTRY
:
1777 return &elf_mips_gnu_vtentry_howto
;
1783 /* Given a MIPS reloc type, fill in an arelent structure. */
1786 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1789 Elf32_Internal_Rel
*dst
;
1791 unsigned int r_type
;
1793 r_type
= ELF32_R_TYPE (dst
->r_info
);
1797 cache_ptr
->howto
= &elf_mips16_jump_howto
;
1799 case R_MIPS16_GPREL
:
1800 cache_ptr
->howto
= &elf_mips16_gprel_howto
;
1802 /* start-sanitize-sky */
1803 case R_MIPS_DVP_11_PCREL
:
1804 cache_ptr
->howto
= &elf_mips_dvp_11_pcrel_howto
;
1806 case R_MIPS_DVP_27_S4
:
1807 cache_ptr
->howto
= &elf_mips_dvp_27_s4_howto
;
1809 case R_MIPS_DVP_11_S4
:
1810 cache_ptr
->howto
= &elf_mips_dvp_11_s4_howto
;
1812 case R_MIPS_DVP_U15_S3
:
1813 cache_ptr
->howto
= &elf_mips_dvp_u15_s3_howto
;
1815 /* end-sanitize-sky */
1816 case R_MIPS_GNU_VTINHERIT
:
1817 cache_ptr
->howto
= &elf_mips_gnu_vtinherit_howto
;
1819 case R_MIPS_GNU_VTENTRY
:
1820 cache_ptr
->howto
= &elf_mips_gnu_vtentry_howto
;
1824 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1825 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1829 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1830 value for the object file. We get the addend now, rather than
1831 when we do the relocation, because the symbol manipulations done
1832 by the linker may cause us to lose track of the input BFD. */
1833 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1834 && (r_type
== (unsigned int) R_MIPS_GPREL16
1835 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1836 cache_ptr
->addend
= elf_gp (abfd
);
1839 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1840 routines swap this structure in and out. They are used outside of
1841 BFD, so they are globally visible. */
1844 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1846 const Elf32_External_RegInfo
*ex
;
1849 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1850 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1851 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1852 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1853 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1854 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1858 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1860 const Elf32_RegInfo
*in
;
1861 Elf32_External_RegInfo
*ex
;
1863 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1864 (bfd_byte
*) ex
->ri_gprmask
);
1865 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1866 (bfd_byte
*) ex
->ri_cprmask
[0]);
1867 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1868 (bfd_byte
*) ex
->ri_cprmask
[1]);
1869 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1870 (bfd_byte
*) ex
->ri_cprmask
[2]);
1871 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1872 (bfd_byte
*) ex
->ri_cprmask
[3]);
1873 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1874 (bfd_byte
*) ex
->ri_gp_value
);
1877 /* In the 64 bit ABI, the .MIPS.options section holds register
1878 information in an Elf64_Reginfo structure. These routines swap
1879 them in and out. They are globally visible because they are used
1880 outside of BFD. These routines are here so that gas can call them
1881 without worrying about whether the 64 bit ABI has been included. */
1884 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1886 const Elf64_External_RegInfo
*ex
;
1887 Elf64_Internal_RegInfo
*in
;
1889 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1890 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
1891 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1892 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1893 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1894 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1895 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1899 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1901 const Elf64_Internal_RegInfo
*in
;
1902 Elf64_External_RegInfo
*ex
;
1904 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1905 (bfd_byte
*) ex
->ri_gprmask
);
1906 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
1907 (bfd_byte
*) ex
->ri_pad
);
1908 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1909 (bfd_byte
*) ex
->ri_cprmask
[0]);
1910 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1911 (bfd_byte
*) ex
->ri_cprmask
[1]);
1912 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1913 (bfd_byte
*) ex
->ri_cprmask
[2]);
1914 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1915 (bfd_byte
*) ex
->ri_cprmask
[3]);
1916 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1917 (bfd_byte
*) ex
->ri_gp_value
);
1920 /* Swap an entry in a .gptab section. Note that these routines rely
1921 on the equivalence of the two elements of the union. */
1924 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1926 const Elf32_External_gptab
*ex
;
1929 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1930 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1934 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1936 const Elf32_gptab
*in
;
1937 Elf32_External_gptab
*ex
;
1939 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1940 ex
->gt_entry
.gt_g_value
);
1941 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1942 ex
->gt_entry
.gt_bytes
);
1946 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1948 const Elf32_compact_rel
*in
;
1949 Elf32_External_compact_rel
*ex
;
1951 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
1952 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
1953 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
1954 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
1955 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
1956 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
1960 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1962 const Elf32_crinfo
*in
;
1963 Elf32_External_crinfo
*ex
;
1967 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1968 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1969 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1970 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1971 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
1972 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
1973 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
1976 /* Swap in an options header. */
1979 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1981 const Elf_External_Options
*ex
;
1982 Elf_Internal_Options
*in
;
1984 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
1985 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
1986 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
1987 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
1990 /* Swap out an options header. */
1993 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
1995 const Elf_Internal_Options
*in
;
1996 Elf_External_Options
*ex
;
1998 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
1999 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
2000 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
2001 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
2004 /* Determine whether a symbol is global for the purposes of splitting
2005 the symbol table into global symbols and local symbols. At least
2006 on Irix 5, this split must be between section symbols and all other
2007 symbols. On most ELF targets the split is between static symbols
2008 and externally visible symbols. */
2012 mips_elf_sym_is_global (abfd
, sym
)
2016 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
2019 /* Set the right machine number for a MIPS ELF file. This is used for
2020 both the 32-bit and the 64-bit ABI. */
2023 _bfd_mips_elf_object_p (abfd
)
2026 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
,
2027 elf_mips_mach (elf_elfheader (abfd
)->e_flags
));
2031 /* Set the right machine number for a 32-bit MIPS ELF file. */
2034 mips_elf32_object_p (abfd
)
2037 /* Irix 5 is broken. Object file symbol tables are not always
2038 sorted correctly such that local symbols precede global symbols,
2039 and the sh_info field in the symbol table is not always right. */
2040 elf_bad_symtab (abfd
) = true;
2042 return _bfd_mips_elf_object_p (abfd
);
2045 /* The final processing done just before writing out a MIPS ELF object
2046 file. This gets the MIPS architecture right based on the machine
2047 number. This is used by both the 32-bit and the 64-bit ABI. */
2051 _bfd_mips_elf_final_write_processing (abfd
, linker
)
2057 Elf_Internal_Shdr
**hdrpp
;
2061 switch (bfd_get_mach (abfd
))
2064 case bfd_mach_mips3000
:
2065 val
= E_MIPS_ARCH_1
;
2068 case bfd_mach_mips3900
:
2069 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
2072 case bfd_mach_mips6000
:
2073 val
= E_MIPS_ARCH_2
;
2076 case bfd_mach_mips4000
:
2077 val
= E_MIPS_ARCH_3
;
2080 case bfd_mach_mips4010
:
2081 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
2084 case bfd_mach_mips4100
:
2085 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
2087 /* start-sanitize-vr4320 */
2089 case bfd_mach_mips4320
:
2090 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4320
;
2092 /* end-sanitize-vr4320 */
2094 case bfd_mach_mips4650
:
2095 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
2097 /* start-sanitize-tx49 */
2099 case bfd_mach_mips4900
:
2100 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4900
;
2102 /* end-sanitize-tx49 */
2103 /* start-sanitize-vr5400 */
2105 case bfd_mach_mips5400
:
2106 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_5400
;
2108 /* end-sanitize-vr5400 */
2109 /* start-sanitize-r5900 */
2111 case bfd_mach_mips5900
:
2112 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_5900
;
2114 /* end-sanitize-r5900 */
2116 case bfd_mach_mips8000
:
2117 val
= E_MIPS_ARCH_4
;
2121 elf_elfheader (abfd
)->e_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2122 elf_elfheader (abfd
)->e_flags
|= val
;
2124 /* Set the sh_info field for .gptab sections and other appropriate
2125 info for each special section. */
2126 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
2127 i
< elf_elfheader (abfd
)->e_shnum
;
2130 switch ((*hdrpp
)->sh_type
)
2132 case SHT_MIPS_LIBLIST
:
2133 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
2135 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2138 case SHT_MIPS_GPTAB
:
2139 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2140 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2141 BFD_ASSERT (name
!= NULL
2142 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
2143 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
2144 BFD_ASSERT (sec
!= NULL
);
2145 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2148 case SHT_MIPS_CONTENT
:
2149 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2150 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2151 BFD_ASSERT (name
!= NULL
2152 && strncmp (name
, ".MIPS.content",
2153 sizeof ".MIPS.content" - 1) == 0);
2154 sec
= bfd_get_section_by_name (abfd
,
2155 name
+ sizeof ".MIPS.content" - 1);
2156 BFD_ASSERT (sec
!= NULL
);
2157 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2160 case SHT_MIPS_SYMBOL_LIB
:
2161 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
2163 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2164 sec
= bfd_get_section_by_name (abfd
, ".liblist");
2166 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2169 case SHT_MIPS_EVENTS
:
2170 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2171 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2172 BFD_ASSERT (name
!= NULL
);
2173 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
2174 sec
= bfd_get_section_by_name (abfd
,
2175 name
+ sizeof ".MIPS.events" - 1);
2178 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
2179 sizeof ".MIPS.post_rel" - 1) == 0);
2180 sec
= bfd_get_section_by_name (abfd
,
2182 + sizeof ".MIPS.post_rel" - 1));
2184 BFD_ASSERT (sec
!= NULL
);
2185 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2188 /* start-sanitize-sky */
2189 case SHT_DVP_OVERLAY_TABLE
:
2190 /* ??? This may not be technically necessary, just going with
2192 sec
= bfd_get_section_by_name (abfd
, SHNAME_DVP_OVERLAY_STRTAB
);
2194 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2196 /* end-sanitize-sky */
2201 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
2204 _bfd_mips_elf_set_private_flags (abfd
, flags
)
2208 BFD_ASSERT (!elf_flags_init (abfd
)
2209 || elf_elfheader (abfd
)->e_flags
== flags
);
2211 elf_elfheader (abfd
)->e_flags
= flags
;
2212 elf_flags_init (abfd
) = true;
2216 /* Copy backend specific data from one object module to another */
2219 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
2223 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2224 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2227 BFD_ASSERT (!elf_flags_init (obfd
)
2228 || (elf_elfheader (obfd
)->e_flags
2229 == elf_elfheader (ibfd
)->e_flags
));
2231 elf_gp (obfd
) = elf_gp (ibfd
);
2232 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
2233 elf_flags_init (obfd
) = true;
2237 /* Merge backend specific data from an object file to the output
2238 object file when linking. */
2241 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
2249 /* Check if we have the same endianess */
2250 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2251 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2255 if (bfd_big_endian (ibfd
))
2256 msg
= _("%s: compiled for a big endian system and target is little endian");
2258 msg
= _("%s: compiled for a little endian system and target is big endian");
2260 (*_bfd_error_handler
) (msg
, bfd_get_filename (ibfd
));
2262 bfd_set_error (bfd_error_wrong_format
);
2266 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2267 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2270 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2271 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
2272 old_flags
= elf_elfheader (obfd
)->e_flags
;
2274 if (! elf_flags_init (obfd
))
2276 elf_flags_init (obfd
) = true;
2277 elf_elfheader (obfd
)->e_flags
= new_flags
;
2279 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2280 && bfd_get_arch_info (obfd
)->the_default
)
2282 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
2283 bfd_get_mach (ibfd
)))
2290 /* Check flag compatibility. */
2292 new_flags
&= ~EF_MIPS_NOREORDER
;
2293 old_flags
&= ~EF_MIPS_NOREORDER
;
2295 if (new_flags
== old_flags
)
2300 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
2302 new_flags
&= ~EF_MIPS_PIC
;
2303 old_flags
&= ~EF_MIPS_PIC
;
2304 (*_bfd_error_handler
)
2305 (_("%s: linking PIC files with non-PIC files"),
2306 bfd_get_filename (ibfd
));
2310 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
2312 new_flags
&= ~EF_MIPS_CPIC
;
2313 old_flags
&= ~EF_MIPS_CPIC
;
2314 (*_bfd_error_handler
)
2315 (_("%s: linking abicalls files with non-abicalls files"),
2316 bfd_get_filename (ibfd
));
2320 /* Compare the ISA's. */
2321 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
2322 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
2324 /* If either has no machine specified, just compare the general isa's. */
2325 if ( !(new_flags
& EF_MIPS_MACH
) || !(old_flags
& EF_MIPS_MACH
))
2327 int new_isa
, old_isa
;
2329 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
2330 and -mips4 code. They will normally use the same data sizes and
2331 calling conventions. */
2333 new_isa
= elf_mips_isa (new_flags
);
2334 old_isa
= elf_mips_isa (old_flags
);
2335 if ((new_isa
== 1 || new_isa
== 2)
2336 ? (old_isa
!= 1 && old_isa
!= 2)
2337 : (old_isa
== 1 || old_isa
== 2))
2339 (*_bfd_error_handler
)
2340 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
2341 bfd_get_filename (ibfd
), new_isa
, old_isa
);
2348 (*_bfd_error_handler
)
2349 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
2350 bfd_get_filename (ibfd
),
2351 elf_mips_mach (new_flags
),
2352 elf_mips_mach (old_flags
));
2356 new_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2357 old_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2360 /* Warn about any other mismatches */
2361 if (new_flags
!= old_flags
)
2363 (*_bfd_error_handler
)
2364 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2365 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
2366 (unsigned long) old_flags
);
2372 bfd_set_error (bfd_error_bad_value
);
2379 /* Handle a MIPS specific section when reading an object file. This
2380 is called when elfcode.h finds a section with an unknown type.
2381 This routine supports both the 32-bit and 64-bit ELF ABI.
2383 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2387 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
2389 Elf_Internal_Shdr
*hdr
;
2392 /* There ought to be a place to keep ELF backend specific flags, but
2393 at the moment there isn't one. We just keep track of the
2394 sections by their name, instead. Fortunately, the ABI gives
2395 suggested names for all the MIPS specific sections, so we will
2396 probably get away with this. */
2397 switch (hdr
->sh_type
)
2399 case SHT_MIPS_LIBLIST
:
2400 if (strcmp (name
, _(".liblist")) != 0)
2404 if (strcmp (name
, ".msym") != 0)
2407 case SHT_MIPS_CONFLICT
:
2408 if (strcmp (name
, ".conflict") != 0)
2411 case SHT_MIPS_GPTAB
:
2412 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
2415 case SHT_MIPS_UCODE
:
2416 if (strcmp (name
, ".ucode") != 0)
2419 case SHT_MIPS_DEBUG
:
2420 if (strcmp (name
, ".mdebug") != 0)
2423 case SHT_MIPS_REGINFO
:
2424 if (strcmp (name
, ".reginfo") != 0
2425 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
2428 case SHT_MIPS_IFACE
:
2429 if (strcmp (name
, ".MIPS.interfaces") != 0)
2432 case SHT_MIPS_CONTENT
:
2433 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2436 case SHT_MIPS_OPTIONS
:
2437 if (strcmp (name
, ".options") != 0
2438 && strcmp (name
, ".MIPS.options") != 0)
2441 case SHT_MIPS_DWARF
:
2442 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2445 case SHT_MIPS_SYMBOL_LIB
:
2446 if (strcmp (name
, ".MIPS.symlib") != 0)
2449 case SHT_MIPS_EVENTS
:
2450 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2451 && strncmp (name
, ".MIPS.post_rel",
2452 sizeof ".MIPS.post_rel" - 1) != 0)
2455 /* start-sanitize-sky */
2456 case SHT_DVP_OVERLAY_TABLE
:
2457 if (strcmp (name
, SHNAME_DVP_OVERLAY_TABLE
) !=0)
2460 case SHT_DVP_OVERLAY
:
2461 if (strncmp (name
, SHNAME_DVP_OVERLAY_PREFIX
,
2462 sizeof (SHNAME_DVP_OVERLAY_PREFIX
) - 1) !=0)
2465 /* end-sanitize-sky */
2470 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2473 if (hdr
->sh_type
== SHT_MIPS_DEBUG
)
2475 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
2476 (bfd_get_section_flags (abfd
,
2485 /* Handle a 32-bit MIPS ELF specific section. */
2488 mips_elf32_section_from_shdr (abfd
, hdr
, name
)
2490 Elf_Internal_Shdr
*hdr
;
2493 if (! _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
))
2496 /* FIXME: We should record sh_info for a .gptab section. */
2498 /* For a .reginfo section, set the gp value in the tdata information
2499 from the contents of this section. We need the gp value while
2500 processing relocs, so we just get it now. The .reginfo section
2501 is not used in the 64-bit MIPS ELF ABI. */
2502 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2504 Elf32_External_RegInfo ext
;
2507 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
2508 (file_ptr
) 0, sizeof ext
))
2510 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
2511 elf_gp (abfd
) = s
.ri_gp_value
;
2514 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2515 set the gp value based on what we find. We may see both
2516 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2517 they should agree. */
2518 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
2520 bfd_byte
*contents
, *l
, *lend
;
2522 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
2523 if (contents
== NULL
)
2525 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
2526 (file_ptr
) 0, hdr
->sh_size
))
2532 lend
= contents
+ hdr
->sh_size
;
2533 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2535 Elf_Internal_Options intopt
;
2537 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2539 if (intopt
.kind
== ODK_REGINFO
)
2541 Elf32_RegInfo intreg
;
2543 bfd_mips_elf32_swap_reginfo_in
2545 ((Elf32_External_RegInfo
*)
2546 (l
+ sizeof (Elf_External_Options
))),
2548 elf_gp (abfd
) = intreg
.ri_gp_value
;
2558 /* Set the correct type for a MIPS ELF section. We do this by the
2559 section name, which is a hack, but ought to work. This routine is
2560 used by both the 32-bit and the 64-bit ABI. */
2563 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
2565 Elf32_Internal_Shdr
*hdr
;
2568 register const char *name
;
2570 name
= bfd_get_section_name (abfd
, sec
);
2572 if (strcmp (name
, ".liblist") == 0)
2574 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
2575 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
2576 /* The sh_link field is set in final_write_processing. */
2578 else if (strcmp (name
, ".msym") == 0)
2580 hdr
->sh_type
= SHT_MIPS_MSYM
;
2581 hdr
->sh_entsize
= 8;
2582 /* FIXME: Set the sh_info field. */
2584 else if (strcmp (name
, ".conflict") == 0)
2585 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
2586 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2588 hdr
->sh_type
= SHT_MIPS_GPTAB
;
2589 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
2590 /* The sh_info field is set in final_write_processing. */
2592 else if (strcmp (name
, ".ucode") == 0)
2593 hdr
->sh_type
= SHT_MIPS_UCODE
;
2594 else if (strcmp (name
, ".mdebug") == 0)
2596 hdr
->sh_type
= SHT_MIPS_DEBUG
;
2597 /* In a shared object on Irix 5.3, the .mdebug section has an
2598 entsize of 0. FIXME: Does this matter? */
2599 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2600 hdr
->sh_entsize
= 0;
2602 hdr
->sh_entsize
= 1;
2604 else if (strcmp (name
, ".reginfo") == 0)
2606 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2607 /* In a shared object on Irix 5.3, the .reginfo section has an
2608 entsize of 0x18. FIXME: Does this matter? */
2609 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2610 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2612 hdr
->sh_entsize
= 1;
2614 /* Force the section size to the correct value, even if the
2615 linker thinks it is larger. The link routine below will only
2616 write out this much data for .reginfo. */
2617 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf32_External_RegInfo
);
2619 else if (SGI_COMPAT (abfd
)
2620 && (strcmp (name
, ".hash") == 0
2621 || strcmp (name
, ".dynamic") == 0
2622 || strcmp (name
, ".dynstr") == 0))
2624 hdr
->sh_entsize
= 0;
2625 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2627 else if (strcmp (name
, ".got") == 0
2628 || strcmp (name
, ".sdata") == 0
2629 || strcmp (name
, ".sbss") == 0
2630 || strcmp (name
, ".lit4") == 0
2631 || strcmp (name
, ".lit8") == 0)
2632 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2633 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2635 hdr
->sh_type
= SHT_MIPS_IFACE
;
2636 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2638 else if (strcmp (name
, ".MIPS.content") == 0)
2640 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2641 /* The sh_info field is set in final_write_processing. */
2643 else if (strcmp (name
, ".options") == 0
2644 || strcmp (name
, ".MIPS.options") == 0)
2646 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2647 hdr
->sh_entsize
= 1;
2648 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2650 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2651 hdr
->sh_type
= SHT_MIPS_DWARF
;
2652 else if (strcmp (name
, ".MIPS.symlib") == 0)
2654 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2655 /* The sh_link and sh_info fields are set in
2656 final_write_processing. */
2658 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2659 || strncmp (name
, ".MIPS.post_rel",
2660 sizeof ".MIPS.post_rel" - 1) == 0)
2662 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2663 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2664 /* The sh_link field is set in final_write_processing. */
2666 /* start-sanitize-sky */
2667 else if (strcmp (name
, SHNAME_DVP_OVERLAY_TABLE
) == 0)
2669 hdr
->sh_type
= SHT_DVP_OVERLAY_TABLE
;
2670 hdr
->sh_entsize
= sizeof (Elf32_Dvp_External_Overlay
);
2671 /* The sh_link field is set in final_write_processing. */
2673 else if (strcmp (name
, SHNAME_DVP_OVERLAY_STRTAB
) == 0)
2674 hdr
->sh_type
= SHT_STRTAB
;
2675 else if (strncmp (name
, SHNAME_DVP_OVERLAY_PREFIX
,
2676 sizeof (SHNAME_DVP_OVERLAY_PREFIX
) - 1) == 0)
2677 hdr
->sh_type
= SHT_DVP_OVERLAY
;
2678 /* end-sanitize-sky */
2683 /* Given a BFD section, try to locate the corresponding ELF section
2684 index. This is used by both the 32-bit and the 64-bit ABI.
2685 Actually, it's not clear to me that the 64-bit ABI supports these,
2686 but for non-PIC objects we will certainly want support for at least
2687 the .scommon section. */
2690 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2692 Elf32_Internal_Shdr
*hdr
;
2696 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2698 *retval
= SHN_MIPS_SCOMMON
;
2701 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2703 *retval
= SHN_MIPS_ACOMMON
;
2709 /* When are writing out the .options or .MIPS.options section,
2710 remember the bytes we are writing out, so that we can install the
2711 GP value in the section_processing routine. */
2714 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2719 bfd_size_type count
;
2721 if (strcmp (section
->name
, ".options") == 0
2722 || strcmp (section
->name
, ".MIPS.options") == 0)
2726 if (elf_section_data (section
) == NULL
)
2728 section
->used_by_bfd
=
2729 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
2730 if (elf_section_data (section
) == NULL
)
2733 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
2738 if (section
->_cooked_size
!= 0)
2739 size
= section
->_cooked_size
;
2741 size
= section
->_raw_size
;
2742 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
2745 elf_section_data (section
)->tdata
= (PTR
) c
;
2748 memcpy (c
+ offset
, location
, count
);
2751 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
2755 /* Work over a section just before writing it out. This routine is
2756 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2757 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2761 _bfd_mips_elf_section_processing (abfd
, hdr
)
2763 Elf_Internal_Shdr
*hdr
;
2765 if (hdr
->bfd_section
!= NULL
)
2767 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
2769 if (strcmp (name
, ".sdata") == 0)
2771 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2772 hdr
->sh_type
= SHT_PROGBITS
;
2774 else if (strcmp (name
, ".sbss") == 0)
2776 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2777 hdr
->sh_type
= SHT_NOBITS
;
2779 else if (strcmp (name
, ".lit8") == 0
2780 || strcmp (name
, ".lit4") == 0)
2782 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2783 hdr
->sh_type
= SHT_PROGBITS
;
2785 else if (strcmp (name
, ".compact_rel") == 0)
2788 hdr
->sh_type
= SHT_PROGBITS
;
2790 else if (strcmp (name
, ".rtproc") == 0)
2792 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
2794 unsigned int adjust
;
2796 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
2798 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
2806 /* Work over a section just before writing it out. We update the GP
2807 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2808 on the value we are using. */
2811 mips_elf32_section_processing (abfd
, hdr
)
2813 Elf32_Internal_Shdr
*hdr
;
2815 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2819 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2820 BFD_ASSERT (hdr
->contents
== NULL
);
2823 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2826 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2827 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2831 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2832 && hdr
->bfd_section
!= NULL
2833 && elf_section_data (hdr
->bfd_section
) != NULL
2834 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2836 bfd_byte
*contents
, *l
, *lend
;
2838 /* We stored the section contents in the elf_section_data tdata
2839 field in the set_section_contents routine. We save the
2840 section contents so that we don't have to read them again.
2841 At this point we know that elf_gp is set, so we can look
2842 through the section contents to see if there is an
2843 ODK_REGINFO structure. */
2845 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2847 lend
= contents
+ hdr
->sh_size
;
2848 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2850 Elf_Internal_Options intopt
;
2852 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2854 if (intopt
.kind
== ODK_REGINFO
)
2861 + sizeof (Elf_External_Options
)
2862 + (sizeof (Elf32_External_RegInfo
) - 4)),
2865 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
2866 if (bfd_write (buf
, 1, 4, abfd
) != 4)
2873 return _bfd_mips_elf_section_processing (abfd
, hdr
);
2876 /* MIPS ELF uses two common sections. One is the usual one, and the
2877 other is for small objects. All the small objects are kept
2878 together, and then referenced via the gp pointer, which yields
2879 faster assembler code. This is what we use for the small common
2880 section. This approach is copied from ecoff.c. */
2881 static asection mips_elf_scom_section
;
2882 static asymbol mips_elf_scom_symbol
;
2883 static asymbol
*mips_elf_scom_symbol_ptr
;
2885 /* MIPS ELF also uses an acommon section, which represents an
2886 allocated common symbol which may be overridden by a
2887 definition in a shared library. */
2888 static asection mips_elf_acom_section
;
2889 static asymbol mips_elf_acom_symbol
;
2890 static asymbol
*mips_elf_acom_symbol_ptr
;
2892 /* The Irix 5 support uses two virtual sections, which represent
2893 text/data symbols defined in dynamic objects. */
2894 static asection mips_elf_text_section
;
2895 static asection
*mips_elf_text_section_ptr
;
2896 static asymbol mips_elf_text_symbol
;
2897 static asymbol
*mips_elf_text_symbol_ptr
;
2899 static asection mips_elf_data_section
;
2900 static asection
*mips_elf_data_section_ptr
;
2901 static asymbol mips_elf_data_symbol
;
2902 static asymbol
*mips_elf_data_symbol_ptr
;
2904 /* Handle the special MIPS section numbers that a symbol may use.
2905 This is used for both the 32-bit and the 64-bit ABI. */
2908 _bfd_mips_elf_symbol_processing (abfd
, asym
)
2912 elf_symbol_type
*elfsym
;
2914 elfsym
= (elf_symbol_type
*) asym
;
2915 switch (elfsym
->internal_elf_sym
.st_shndx
)
2917 case SHN_MIPS_ACOMMON
:
2918 /* This section is used in a dynamically linked executable file.
2919 It is an allocated common section. The dynamic linker can
2920 either resolve these symbols to something in a shared
2921 library, or it can just leave them here. For our purposes,
2922 we can consider these symbols to be in a new section. */
2923 if (mips_elf_acom_section
.name
== NULL
)
2925 /* Initialize the acommon section. */
2926 mips_elf_acom_section
.name
= ".acommon";
2927 mips_elf_acom_section
.flags
= SEC_ALLOC
;
2928 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
2929 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
2930 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
2931 mips_elf_acom_symbol
.name
= ".acommon";
2932 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
2933 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
2934 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
2936 asym
->section
= &mips_elf_acom_section
;
2940 /* Common symbols less than the GP size are automatically
2941 treated as SHN_MIPS_SCOMMON symbols. */
2942 if (asym
->value
> elf_gp_size (abfd
))
2945 case SHN_MIPS_SCOMMON
:
2946 if (mips_elf_scom_section
.name
== NULL
)
2948 /* Initialize the small common section. */
2949 mips_elf_scom_section
.name
= ".scommon";
2950 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
2951 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
2952 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
2953 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
2954 mips_elf_scom_symbol
.name
= ".scommon";
2955 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2956 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
2957 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
2959 asym
->section
= &mips_elf_scom_section
;
2960 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2963 case SHN_MIPS_SUNDEFINED
:
2964 asym
->section
= bfd_und_section_ptr
;
2967 #if 0 /* for SGI_COMPAT */
2969 asym
->section
= mips_elf_text_section_ptr
;
2973 asym
->section
= mips_elf_data_section_ptr
;
2979 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
2983 mips_elf_additional_program_headers (abfd
)
2991 if (! SGI_COMPAT (abfd
))
2994 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2995 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2997 /* We need a PT_MIPS_REGINFO segment. */
3001 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3002 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3004 /* We need a PT_MIPS_RTPROC segment. */
3011 /* Modify the segment map for an Irix 5 executable. */
3014 mips_elf_modify_segment_map (abfd
)
3018 struct elf_segment_map
*m
, **pm
;
3020 if (! SGI_COMPAT (abfd
))
3023 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
3025 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3026 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3028 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3029 if (m
->p_type
== PT_MIPS_REGINFO
)
3033 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3037 m
->p_type
= PT_MIPS_REGINFO
;
3041 /* We want to put it after the PHDR and INTERP segments. */
3042 pm
= &elf_tdata (abfd
)->segment_map
;
3044 && ((*pm
)->p_type
== PT_PHDR
3045 || (*pm
)->p_type
== PT_INTERP
))
3053 /* If there are .dynamic and .mdebug sections, we make a room for
3054 the RTPROC header. FIXME: Rewrite without section names. */
3055 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
3056 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3057 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3059 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3060 if (m
->p_type
== PT_MIPS_RTPROC
)
3064 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3068 m
->p_type
= PT_MIPS_RTPROC
;
3070 s
= bfd_get_section_by_name (abfd
, ".rtproc");
3075 m
->p_flags_valid
= 1;
3083 /* We want to put it after the DYNAMIC segment. */
3084 pm
= &elf_tdata (abfd
)->segment_map
;
3085 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
3095 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
3096 .dynsym, and .hash sections, and everything in between. */
3097 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
3098 if ((*pm
)->p_type
== PT_DYNAMIC
)
3103 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
3105 static const char *sec_names
[] =
3106 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
3109 struct elf_segment_map
*n
;
3113 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
3115 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
3116 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3122 sz
= s
->_cooked_size
;
3125 if (high
< s
->vma
+ sz
)
3131 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3132 if ((s
->flags
& SEC_LOAD
) != 0
3135 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3139 n
= ((struct elf_segment_map
*)
3140 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
3147 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3149 if ((s
->flags
& SEC_LOAD
) != 0
3152 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3166 /* The structure of the runtime procedure descriptor created by the
3167 loader for use by the static exception system. */
3169 typedef struct runtime_pdr
{
3170 bfd_vma adr
; /* memory address of start of procedure */
3171 long regmask
; /* save register mask */
3172 long regoffset
; /* save register offset */
3173 long fregmask
; /* save floating point register mask */
3174 long fregoffset
; /* save floating point register offset */
3175 long frameoffset
; /* frame size */
3176 short framereg
; /* frame pointer register */
3177 short pcreg
; /* offset or reg of return pc */
3178 long irpss
; /* index into the runtime string table */
3180 struct exception_info
*exception_info
;/* pointer to exception array */
3182 #define cbRPDR sizeof(RPDR)
3183 #define rpdNil ((pRPDR) 0)
3185 /* Swap RPDR (runtime procedure table entry) for output. */
3187 static void ecoff_swap_rpdr_out
3188 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
3191 ecoff_swap_rpdr_out (abfd
, in
, ex
)
3194 struct rpdr_ext
*ex
;
3196 /* ecoff_put_off was defined in ecoffswap.h. */
3197 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
3198 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
3199 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
3200 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
3201 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
3202 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
3204 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
3205 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
3207 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
3209 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
3213 /* Read ECOFF debugging information from a .mdebug section into a
3214 ecoff_debug_info structure. */
3217 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
3220 struct ecoff_debug_info
*debug
;
3223 const struct ecoff_debug_swap
*swap
;
3224 char *ext_hdr
= NULL
;
3226 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3228 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
3229 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
3232 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
3233 swap
->external_hdr_size
)
3237 symhdr
= &debug
->symbolic_header
;
3238 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
3240 /* The symbolic header contains absolute file offsets and sizes to
3242 #define READ(ptr, offset, count, size, type) \
3243 if (symhdr->count == 0) \
3244 debug->ptr = NULL; \
3247 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
3248 if (debug->ptr == NULL) \
3249 goto error_return; \
3250 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3251 || (bfd_read (debug->ptr, size, symhdr->count, \
3252 abfd) != size * symhdr->count)) \
3253 goto error_return; \
3256 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
3257 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
3258 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
3259 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
3260 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
3261 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
3263 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
3264 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
3265 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
3266 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
3267 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
3271 debug
->adjust
= NULL
;
3276 if (ext_hdr
!= NULL
)
3278 if (debug
->line
!= NULL
)
3280 if (debug
->external_dnr
!= NULL
)
3281 free (debug
->external_dnr
);
3282 if (debug
->external_pdr
!= NULL
)
3283 free (debug
->external_pdr
);
3284 if (debug
->external_sym
!= NULL
)
3285 free (debug
->external_sym
);
3286 if (debug
->external_opt
!= NULL
)
3287 free (debug
->external_opt
);
3288 if (debug
->external_aux
!= NULL
)
3289 free (debug
->external_aux
);
3290 if (debug
->ss
!= NULL
)
3292 if (debug
->ssext
!= NULL
)
3293 free (debug
->ssext
);
3294 if (debug
->external_fdr
!= NULL
)
3295 free (debug
->external_fdr
);
3296 if (debug
->external_rfd
!= NULL
)
3297 free (debug
->external_rfd
);
3298 if (debug
->external_ext
!= NULL
)
3299 free (debug
->external_ext
);
3303 /* MIPS ELF local labels start with '$', not 'L'. */
3307 mips_elf_is_local_label_name (abfd
, name
)
3314 /* On Irix 6, the labels go back to starting with '.', so we accept
3315 the generic ELF local label syntax as well. */
3316 return _bfd_elf_is_local_label_name (abfd
, name
);
3319 /* MIPS ELF uses a special find_nearest_line routine in order the
3320 handle the ECOFF debugging information. */
3322 struct mips_elf_find_line
3324 struct ecoff_debug_info d
;
3325 struct ecoff_find_line i
;
3329 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
3330 functionname_ptr
, line_ptr
)
3335 const char **filename_ptr
;
3336 const char **functionname_ptr
;
3337 unsigned int *line_ptr
;
3341 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3342 filename_ptr
, functionname_ptr
,
3346 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
3350 struct mips_elf_find_line
*fi
;
3351 const struct ecoff_debug_swap
* const swap
=
3352 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3354 /* If we are called during a link, mips_elf_final_link may have
3355 cleared the SEC_HAS_CONTENTS field. We force it back on here
3356 if appropriate (which it normally will be). */
3357 origflags
= msec
->flags
;
3358 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
3359 msec
->flags
|= SEC_HAS_CONTENTS
;
3361 fi
= elf_tdata (abfd
)->find_line_info
;
3364 bfd_size_type external_fdr_size
;
3367 struct fdr
*fdr_ptr
;
3369 fi
= ((struct mips_elf_find_line
*)
3370 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
3373 msec
->flags
= origflags
;
3377 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
3379 msec
->flags
= origflags
;
3383 /* Swap in the FDR information. */
3384 fi
->d
.fdr
= ((struct fdr
*)
3386 (fi
->d
.symbolic_header
.ifdMax
*
3387 sizeof (struct fdr
))));
3388 if (fi
->d
.fdr
== NULL
)
3390 msec
->flags
= origflags
;
3393 external_fdr_size
= swap
->external_fdr_size
;
3394 fdr_ptr
= fi
->d
.fdr
;
3395 fraw_src
= (char *) fi
->d
.external_fdr
;
3396 fraw_end
= (fraw_src
3397 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
3398 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
3399 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
3401 elf_tdata (abfd
)->find_line_info
= fi
;
3403 /* Note that we don't bother to ever free this information.
3404 find_nearest_line is either called all the time, as in
3405 objdump -l, so the information should be saved, or it is
3406 rarely called, as in ld error messages, so the memory
3407 wasted is unimportant. Still, it would probably be a
3408 good idea for free_cached_info to throw it away. */
3411 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
3412 &fi
->i
, filename_ptr
, functionname_ptr
,
3415 msec
->flags
= origflags
;
3419 msec
->flags
= origflags
;
3422 /* Fall back on the generic ELF find_nearest_line routine. */
3424 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
3425 filename_ptr
, functionname_ptr
,
3429 /* The mips16 compiler uses a couple of special sections to handle
3430 floating point arguments.
3432 Section names that look like .mips16.fn.FNNAME contain stubs that
3433 copy floating point arguments from the fp regs to the gp regs and
3434 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3435 call should be redirected to the stub instead. If no 32 bit
3436 function calls FNNAME, the stub should be discarded. We need to
3437 consider any reference to the function, not just a call, because
3438 if the address of the function is taken we will need the stub,
3439 since the address might be passed to a 32 bit function.
3441 Section names that look like .mips16.call.FNNAME contain stubs
3442 that copy floating point arguments from the gp regs to the fp
3443 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3444 then any 16 bit function that calls FNNAME should be redirected
3445 to the stub instead. If FNNAME is not a 32 bit function, the
3446 stub should be discarded.
3448 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3449 which call FNNAME and then copy the return value from the fp regs
3450 to the gp regs. These stubs store the return value in $18 while
3451 calling FNNAME; any function which might call one of these stubs
3452 must arrange to save $18 around the call. (This case is not
3453 needed for 32 bit functions that call 16 bit functions, because
3454 16 bit functions always return floating point values in both
3457 Note that in all cases FNNAME might be defined statically.
3458 Therefore, FNNAME is not used literally. Instead, the relocation
3459 information will indicate which symbol the section is for.
3461 We record any stubs that we find in the symbol table. */
3463 #define FN_STUB ".mips16.fn."
3464 #define CALL_STUB ".mips16.call."
3465 #define CALL_FP_STUB ".mips16.call.fp."
3467 /* The MIPS ELF linker needs additional information for each symbol in
3468 the global hash table. */
3470 struct mips_elf_link_hash_entry
3472 struct elf_link_hash_entry root
;
3474 /* External symbol information. */
3477 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
3478 unsigned int mips_32_relocs
;
3480 /* If there is a stub that 32 bit functions should use to call this
3481 16 bit function, this points to the section containing the stub. */
3484 /* Whether we need the fn_stub; this is set if this symbol appears
3485 in any relocs other than a 16 bit call. */
3486 boolean need_fn_stub
;
3488 /* If there is a stub that 16 bit functions should use to call this
3489 32 bit function, this points to the section containing the stub. */
3490 asection
*call_stub
;
3492 /* This is like the call_stub field, but it is used if the function
3493 being called returns a floating point value. */
3494 asection
*call_fp_stub
;
3497 /* MIPS ELF linker hash table. */
3499 struct mips_elf_link_hash_table
3501 struct elf_link_hash_table root
;
3502 /* String section indices for the dynamic section symbols. */
3503 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
3504 /* The number of .rtproc entries. */
3505 bfd_size_type procedure_count
;
3506 /* The size of the .compact_rel section (if SGI_COMPAT). */
3507 bfd_size_type compact_rel_size
;
3508 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3509 entry is set to the address of __rld_obj_head as in Irix 5. */
3510 boolean use_rld_obj_head
;
3511 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3513 /* This is set if we see any mips16 stub sections. */
3514 boolean mips16_stubs_seen
;
3517 /* Look up an entry in a MIPS ELF linker hash table. */
3519 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3520 ((struct mips_elf_link_hash_entry *) \
3521 elf_link_hash_lookup (&(table)->root, (string), (create), \
3524 /* Traverse a MIPS ELF linker hash table. */
3526 #define mips_elf_link_hash_traverse(table, func, info) \
3527 (elf_link_hash_traverse \
3529 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3532 /* Get the MIPS ELF linker hash table from a link_info structure. */
3534 #define mips_elf_hash_table(p) \
3535 ((struct mips_elf_link_hash_table *) ((p)->hash))
3537 static boolean mips_elf_output_extsym
3538 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3540 /* Create an entry in a MIPS ELF linker hash table. */
3542 static struct bfd_hash_entry
*
3543 mips_elf_link_hash_newfunc (entry
, table
, string
)
3544 struct bfd_hash_entry
*entry
;
3545 struct bfd_hash_table
*table
;
3548 struct mips_elf_link_hash_entry
*ret
=
3549 (struct mips_elf_link_hash_entry
*) entry
;
3551 /* Allocate the structure if it has not already been allocated by a
3553 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3554 ret
= ((struct mips_elf_link_hash_entry
*)
3555 bfd_hash_allocate (table
,
3556 sizeof (struct mips_elf_link_hash_entry
)));
3557 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3558 return (struct bfd_hash_entry
*) ret
;
3560 /* Call the allocation method of the superclass. */
3561 ret
= ((struct mips_elf_link_hash_entry
*)
3562 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3564 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3566 /* Set local fields. */
3567 memset (&ret
->esym
, 0, sizeof (EXTR
));
3568 /* We use -2 as a marker to indicate that the information has
3569 not been set. -1 means there is no associated ifd. */
3571 ret
->mips_32_relocs
= 0;
3572 ret
->fn_stub
= NULL
;
3573 ret
->need_fn_stub
= false;
3574 ret
->call_stub
= NULL
;
3575 ret
->call_fp_stub
= NULL
;
3578 return (struct bfd_hash_entry
*) ret
;
3581 /* Create a MIPS ELF linker hash table. */
3583 static struct bfd_link_hash_table
*
3584 mips_elf_link_hash_table_create (abfd
)
3587 struct mips_elf_link_hash_table
*ret
;
3590 ret
= ((struct mips_elf_link_hash_table
*)
3591 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
3592 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
3595 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3596 mips_elf_link_hash_newfunc
))
3598 bfd_release (abfd
, ret
);
3602 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
3603 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
3604 ret
->procedure_count
= 0;
3605 ret
->compact_rel_size
= 0;
3606 ret
->use_rld_obj_head
= false;
3608 ret
->mips16_stubs_seen
= false;
3610 return &ret
->root
.root
;
3613 /* Hook called by the linker routine which adds symbols from an object
3614 file. We must handle the special MIPS section numbers here. */
3618 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3620 struct bfd_link_info
*info
;
3621 const Elf_Internal_Sym
*sym
;
3627 if (SGI_COMPAT (abfd
)
3628 && (abfd
->flags
& DYNAMIC
) != 0
3629 && strcmp (*namep
, "_rld_new_interface") == 0)
3631 /* Skip Irix 5 rld entry name. */
3636 switch (sym
->st_shndx
)
3639 /* Common symbols less than the GP size are automatically
3640 treated as SHN_MIPS_SCOMMON symbols. */
3641 if (sym
->st_size
> elf_gp_size (abfd
))
3644 case SHN_MIPS_SCOMMON
:
3645 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3646 (*secp
)->flags
|= SEC_IS_COMMON
;
3647 *valp
= sym
->st_size
;
3651 /* This section is used in a shared object. */
3652 if (mips_elf_text_section_ptr
== NULL
)
3654 /* Initialize the section. */
3655 mips_elf_text_section
.name
= ".text";
3656 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
3657 mips_elf_text_section
.output_section
= NULL
;
3658 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
3659 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
3660 mips_elf_text_symbol
.name
= ".text";
3661 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
3662 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
3663 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
3664 mips_elf_text_section_ptr
= &mips_elf_text_section
;
3666 /* This code used to do *secp = bfd_und_section_ptr if
3667 info->shared. I don't know why, and that doesn't make sense,
3668 so I took it out. */
3669 *secp
= mips_elf_text_section_ptr
;
3672 case SHN_MIPS_ACOMMON
:
3673 /* Fall through. XXX Can we treat this as allocated data? */
3675 /* This section is used in a shared object. */
3676 if (mips_elf_data_section_ptr
== NULL
)
3678 /* Initialize the section. */
3679 mips_elf_data_section
.name
= ".data";
3680 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
3681 mips_elf_data_section
.output_section
= NULL
;
3682 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
3683 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
3684 mips_elf_data_symbol
.name
= ".data";
3685 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
3686 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
3687 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
3688 mips_elf_data_section_ptr
= &mips_elf_data_section
;
3690 /* This code used to do *secp = bfd_und_section_ptr if
3691 info->shared. I don't know why, and that doesn't make sense,
3692 so I took it out. */
3693 *secp
= mips_elf_data_section_ptr
;
3696 case SHN_MIPS_SUNDEFINED
:
3697 *secp
= bfd_und_section_ptr
;
3701 if (SGI_COMPAT (abfd
)
3703 && info
->hash
->creator
== abfd
->xvec
3704 && strcmp (*namep
, "__rld_obj_head") == 0)
3706 struct elf_link_hash_entry
*h
;
3708 /* Mark __rld_obj_head as dynamic. */
3710 if (! (_bfd_generic_link_add_one_symbol
3711 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3712 (bfd_vma
) *valp
, (const char *) NULL
, false,
3713 get_elf_backend_data (abfd
)->collect
,
3714 (struct bfd_link_hash_entry
**) &h
)))
3716 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
3717 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3718 h
->type
= STT_OBJECT
;
3720 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3723 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3726 /* If this is a mips16 text symbol, add 1 to the value to make it
3727 odd. This will cause something like .word SYM to come up with
3728 the right value when it is loaded into the PC. */
3729 if (sym
->st_other
== STO_MIPS16
)
3735 /* Structure used to pass information to mips_elf_output_extsym. */
3740 struct bfd_link_info
*info
;
3741 struct ecoff_debug_info
*debug
;
3742 const struct ecoff_debug_swap
*swap
;
3746 /* This routine is used to write out ECOFF debugging external symbol
3747 information. It is called via mips_elf_link_hash_traverse. The
3748 ECOFF external symbol information must match the ELF external
3749 symbol information. Unfortunately, at this point we don't know
3750 whether a symbol is required by reloc information, so the two
3751 tables may wind up being different. We must sort out the external
3752 symbol information before we can set the final size of the .mdebug
3753 section, and we must set the size of the .mdebug section before we
3754 can relocate any sections, and we can't know which symbols are
3755 required by relocation until we relocate the sections.
3756 Fortunately, it is relatively unlikely that any symbol will be
3757 stripped but required by a reloc. In particular, it can not happen
3758 when generating a final executable. */
3761 mips_elf_output_extsym (h
, data
)
3762 struct mips_elf_link_hash_entry
*h
;
3765 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
3767 asection
*sec
, *output_section
;
3769 if (h
->root
.indx
== -2)
3771 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3772 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
3773 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3774 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
3776 else if (einfo
->info
->strip
== strip_all
3777 || (einfo
->info
->strip
== strip_some
3778 && bfd_hash_lookup (einfo
->info
->keep_hash
,
3779 h
->root
.root
.root
.string
,
3780 false, false) == NULL
))
3788 if (h
->esym
.ifd
== -2)
3791 h
->esym
.cobol_main
= 0;
3792 h
->esym
.weakext
= 0;
3793 h
->esym
.reserved
= 0;
3794 h
->esym
.ifd
= ifdNil
;
3795 h
->esym
.asym
.value
= 0;
3796 h
->esym
.asym
.st
= stGlobal
;
3798 if (SGI_COMPAT (einfo
->abfd
)
3799 && (h
->root
.root
.type
== bfd_link_hash_undefined
3800 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
3804 /* Use undefined class. Also, set class and type for some
3806 name
= h
->root
.root
.root
.string
;
3807 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
3808 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
3810 h
->esym
.asym
.sc
= scData
;
3811 h
->esym
.asym
.st
= stLabel
;
3812 h
->esym
.asym
.value
= 0;
3814 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
3816 h
->esym
.asym
.sc
= scAbs
;
3817 h
->esym
.asym
.st
= stLabel
;
3818 h
->esym
.asym
.value
=
3819 mips_elf_hash_table (einfo
->info
)->procedure_count
;
3821 else if (strcmp (name
, "_gp_disp") == 0)
3823 h
->esym
.asym
.sc
= scAbs
;
3824 h
->esym
.asym
.st
= stLabel
;
3825 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
3828 h
->esym
.asym
.sc
= scUndefined
;
3830 else if (h
->root
.root
.type
!= bfd_link_hash_defined
3831 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
3832 h
->esym
.asym
.sc
= scAbs
;
3837 sec
= h
->root
.root
.u
.def
.section
;
3838 output_section
= sec
->output_section
;
3840 /* When making a shared library and symbol h is the one from
3841 the another shared library, OUTPUT_SECTION may be null. */
3842 if (output_section
== NULL
)
3843 h
->esym
.asym
.sc
= scUndefined
;
3846 name
= bfd_section_name (output_section
->owner
, output_section
);
3848 if (strcmp (name
, ".text") == 0)
3849 h
->esym
.asym
.sc
= scText
;
3850 else if (strcmp (name
, ".data") == 0)
3851 h
->esym
.asym
.sc
= scData
;
3852 else if (strcmp (name
, ".sdata") == 0)
3853 h
->esym
.asym
.sc
= scSData
;
3854 else if (strcmp (name
, ".rodata") == 0
3855 || strcmp (name
, ".rdata") == 0)
3856 h
->esym
.asym
.sc
= scRData
;
3857 else if (strcmp (name
, ".bss") == 0)
3858 h
->esym
.asym
.sc
= scBss
;
3859 else if (strcmp (name
, ".sbss") == 0)
3860 h
->esym
.asym
.sc
= scSBss
;
3861 else if (strcmp (name
, ".init") == 0)
3862 h
->esym
.asym
.sc
= scInit
;
3863 else if (strcmp (name
, ".fini") == 0)
3864 h
->esym
.asym
.sc
= scFini
;
3866 h
->esym
.asym
.sc
= scAbs
;
3870 h
->esym
.asym
.reserved
= 0;
3871 h
->esym
.asym
.index
= indexNil
;
3874 if (h
->root
.root
.type
== bfd_link_hash_common
)
3875 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
3876 else if (h
->root
.root
.type
== bfd_link_hash_defined
3877 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3879 if (h
->esym
.asym
.sc
== scCommon
)
3880 h
->esym
.asym
.sc
= scBss
;
3881 else if (h
->esym
.asym
.sc
== scSCommon
)
3882 h
->esym
.asym
.sc
= scSBss
;
3884 sec
= h
->root
.root
.u
.def
.section
;
3885 output_section
= sec
->output_section
;
3886 if (output_section
!= NULL
)
3887 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
3888 + sec
->output_offset
3889 + output_section
->vma
);
3891 h
->esym
.asym
.value
= 0;
3893 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3895 /* Set type and value for a symbol with a function stub. */
3896 h
->esym
.asym
.st
= stProc
;
3897 sec
= h
->root
.root
.u
.def
.section
;
3899 h
->esym
.asym
.value
= 0;
3902 output_section
= sec
->output_section
;
3903 if (output_section
!= NULL
)
3904 h
->esym
.asym
.value
= (h
->root
.plt
.offset
3905 + sec
->output_offset
3906 + output_section
->vma
);
3908 h
->esym
.asym
.value
= 0;
3915 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
3916 h
->root
.root
.root
.string
,
3919 einfo
->failed
= true;
3926 /* Create a runtime procedure table from the .mdebug section. */
3929 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
3932 struct bfd_link_info
*info
;
3934 struct ecoff_debug_info
*debug
;
3936 const struct ecoff_debug_swap
*swap
;
3937 HDRR
*hdr
= &debug
->symbolic_header
;
3939 struct rpdr_ext
*erp
;
3941 struct pdr_ext
*epdr
;
3942 struct sym_ext
*esym
;
3945 unsigned long size
, count
;
3946 unsigned long sindex
;
3950 const char *no_name_func
= _("static procedure (no name)");
3958 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3960 sindex
= strlen (no_name_func
) + 1;
3961 count
= hdr
->ipdMax
;
3964 size
= swap
->external_pdr_size
;
3966 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
3970 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
3973 size
= sizeof (RPDR
);
3974 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
3978 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
3982 count
= hdr
->isymMax
;
3983 size
= swap
->external_sym_size
;
3984 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
3988 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
3991 count
= hdr
->issMax
;
3992 ss
= (char *) bfd_malloc (count
);
3995 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
3998 count
= hdr
->ipdMax
;
3999 for (i
= 0; i
< count
; i
++, rp
++)
4001 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
4002 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
4003 rp
->adr
= sym
.value
;
4004 rp
->regmask
= pdr
.regmask
;
4005 rp
->regoffset
= pdr
.regoffset
;
4006 rp
->fregmask
= pdr
.fregmask
;
4007 rp
->fregoffset
= pdr
.fregoffset
;
4008 rp
->frameoffset
= pdr
.frameoffset
;
4009 rp
->framereg
= pdr
.framereg
;
4010 rp
->pcreg
= pdr
.pcreg
;
4012 sv
[i
] = ss
+ sym
.iss
;
4013 sindex
+= strlen (sv
[i
]) + 1;
4017 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
4018 size
= BFD_ALIGN (size
, 16);
4019 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
4022 mips_elf_hash_table (info
)->procedure_count
= 0;
4026 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
4028 erp
= (struct rpdr_ext
*) rtproc
;
4029 memset (erp
, 0, sizeof (struct rpdr_ext
));
4031 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
4032 strcpy (str
, no_name_func
);
4033 str
+= strlen (no_name_func
) + 1;
4034 for (i
= 0; i
< count
; i
++)
4036 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
4037 strcpy (str
, sv
[i
]);
4038 str
+= strlen (sv
[i
]) + 1;
4040 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
4042 /* Set the size and contents of .rtproc section. */
4043 s
->_raw_size
= size
;
4044 s
->contents
= (bfd_byte
*) rtproc
;
4046 /* Skip this section later on (I don't think this currently
4047 matters, but someday it might). */
4048 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
4077 /* A comparison routine used to sort .gptab entries. */
4080 gptab_compare (p1
, p2
)
4084 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
4085 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
4087 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
4090 /* We need to use a special link routine to handle the .reginfo and
4091 the .mdebug sections. We need to merge all instances of these
4092 sections together, not write them all out sequentially. */
4095 mips_elf_final_link (abfd
, info
)
4097 struct bfd_link_info
*info
;
4101 struct bfd_link_order
*p
;
4102 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
4103 asection
*rtproc_sec
;
4104 Elf32_RegInfo reginfo
;
4105 struct ecoff_debug_info debug
;
4106 const struct ecoff_debug_swap
*swap
4107 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4108 HDRR
*symhdr
= &debug
.symbolic_header
;
4109 PTR mdebug_handle
= NULL
;
4111 /* Drop the .options section, since it has special semantics which I
4112 haven't bothered to figure out. */
4113 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
4115 if (strcmp ((*secpp
)->name
, ".options") == 0)
4117 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
4118 if (p
->type
== bfd_indirect_link_order
)
4119 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
4120 (*secpp
)->link_order_head
= NULL
;
4121 *secpp
= (*secpp
)->next
;
4122 --abfd
->section_count
;
4127 /* Get a value for the GP register. */
4128 if (elf_gp (abfd
) == 0)
4130 struct bfd_link_hash_entry
*h
;
4132 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4133 if (h
!= (struct bfd_link_hash_entry
*) NULL
4134 && h
->type
== bfd_link_hash_defined
)
4135 elf_gp (abfd
) = (h
->u
.def
.value
4136 + h
->u
.def
.section
->output_section
->vma
4137 + h
->u
.def
.section
->output_offset
);
4138 else if (info
->relocateable
)
4142 /* Make up a value. */
4144 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4147 && (strcmp (o
->name
, ".sbss") == 0
4148 || strcmp (o
->name
, ".sdata") == 0
4149 || strcmp (o
->name
, ".lit4") == 0
4150 || strcmp (o
->name
, ".lit8") == 0))
4153 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
4157 /* If the relocate_section function needs to do a reloc
4158 involving the GP value, it should make a reloc_dangerous
4159 callback to warn that GP is not defined. */
4163 /* Go through the sections and collect the .reginfo and .mdebug
4167 gptab_data_sec
= NULL
;
4168 gptab_bss_sec
= NULL
;
4169 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4171 if (strcmp (o
->name
, ".reginfo") == 0)
4173 memset (®info
, 0, sizeof reginfo
);
4175 /* We have found the .reginfo section in the output file.
4176 Look through all the link_orders comprising it and merge
4177 the information together. */
4178 for (p
= o
->link_order_head
;
4179 p
!= (struct bfd_link_order
*) NULL
;
4182 asection
*input_section
;
4184 Elf32_External_RegInfo ext
;
4187 if (p
->type
!= bfd_indirect_link_order
)
4189 if (p
->type
== bfd_fill_link_order
)
4194 input_section
= p
->u
.indirect
.section
;
4195 input_bfd
= input_section
->owner
;
4197 /* The linker emulation code has probably clobbered the
4198 size to be zero bytes. */
4199 if (input_section
->_raw_size
== 0)
4200 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4202 if (! bfd_get_section_contents (input_bfd
, input_section
,
4208 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
4210 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
4211 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
4212 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
4213 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
4214 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
4216 /* ri_gp_value is set by the function
4217 mips_elf32_section_processing when the section is
4218 finally written out. */
4220 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4221 elf_link_input_bfd ignores this section. */
4222 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4225 /* Force the section size to the value we want. */
4226 o
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4228 /* Skip this section later on (I don't think this currently
4229 matters, but someday it might). */
4230 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4235 if (strcmp (o
->name
, ".mdebug") == 0)
4237 struct extsym_info einfo
;
4239 /* We have found the .mdebug section in the output file.
4240 Look through all the link_orders comprising it and merge
4241 the information together. */
4242 symhdr
->magic
= swap
->sym_magic
;
4243 /* FIXME: What should the version stamp be? */
4245 symhdr
->ilineMax
= 0;
4249 symhdr
->isymMax
= 0;
4250 symhdr
->ioptMax
= 0;
4251 symhdr
->iauxMax
= 0;
4253 symhdr
->issExtMax
= 0;
4256 symhdr
->iextMax
= 0;
4258 /* We accumulate the debugging information itself in the
4259 debug_info structure. */
4261 debug
.external_dnr
= NULL
;
4262 debug
.external_pdr
= NULL
;
4263 debug
.external_sym
= NULL
;
4264 debug
.external_opt
= NULL
;
4265 debug
.external_aux
= NULL
;
4267 debug
.ssext
= debug
.ssext_end
= NULL
;
4268 debug
.external_fdr
= NULL
;
4269 debug
.external_rfd
= NULL
;
4270 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4272 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4273 if (mdebug_handle
== (PTR
) NULL
)
4276 if (SGI_COMPAT (abfd
))
4282 static const char * const name
[] =
4283 { ".text", ".init", ".fini", ".data",
4284 ".rodata", ".sdata", ".sbss", ".bss" };
4285 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
4286 scRData
, scSData
, scSBss
, scBss
};
4289 esym
.cobol_main
= 0;
4293 esym
.asym
.iss
= issNil
;
4294 esym
.asym
.st
= stLocal
;
4295 esym
.asym
.reserved
= 0;
4296 esym
.asym
.index
= indexNil
;
4298 for (i
= 0; i
< 8; i
++)
4300 esym
.asym
.sc
= sc
[i
];
4301 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4304 esym
.asym
.value
= s
->vma
;
4305 last
= s
->vma
+ s
->_raw_size
;
4308 esym
.asym
.value
= last
;
4310 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4316 for (p
= o
->link_order_head
;
4317 p
!= (struct bfd_link_order
*) NULL
;
4320 asection
*input_section
;
4322 const struct ecoff_debug_swap
*input_swap
;
4323 struct ecoff_debug_info input_debug
;
4327 if (p
->type
!= bfd_indirect_link_order
)
4329 if (p
->type
== bfd_fill_link_order
)
4334 input_section
= p
->u
.indirect
.section
;
4335 input_bfd
= input_section
->owner
;
4337 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4338 || (get_elf_backend_data (input_bfd
)
4339 ->elf_backend_ecoff_debug_swap
) == NULL
)
4341 /* I don't know what a non MIPS ELF bfd would be
4342 doing with a .mdebug section, but I don't really
4343 want to deal with it. */
4347 input_swap
= (get_elf_backend_data (input_bfd
)
4348 ->elf_backend_ecoff_debug_swap
);
4350 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
4352 /* The ECOFF linking code expects that we have already
4353 read in the debugging information and set up an
4354 ecoff_debug_info structure, so we do that now. */
4355 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
4359 if (! (bfd_ecoff_debug_accumulate
4360 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
4361 &input_debug
, input_swap
, info
)))
4364 /* Loop through the external symbols. For each one with
4365 interesting information, try to find the symbol in
4366 the linker global hash table and save the information
4367 for the output external symbols. */
4368 eraw_src
= input_debug
.external_ext
;
4369 eraw_end
= (eraw_src
4370 + (input_debug
.symbolic_header
.iextMax
4371 * input_swap
->external_ext_size
));
4373 eraw_src
< eraw_end
;
4374 eraw_src
+= input_swap
->external_ext_size
)
4378 struct mips_elf_link_hash_entry
*h
;
4380 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4381 if (ext
.asym
.sc
== scNil
4382 || ext
.asym
.sc
== scUndefined
4383 || ext
.asym
.sc
== scSUndefined
)
4386 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4387 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
4388 name
, false, false, true);
4389 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4395 < input_debug
.symbolic_header
.ifdMax
);
4396 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4402 /* Free up the information we just read. */
4403 free (input_debug
.line
);
4404 free (input_debug
.external_dnr
);
4405 free (input_debug
.external_pdr
);
4406 free (input_debug
.external_sym
);
4407 free (input_debug
.external_opt
);
4408 free (input_debug
.external_aux
);
4409 free (input_debug
.ss
);
4410 free (input_debug
.ssext
);
4411 free (input_debug
.external_fdr
);
4412 free (input_debug
.external_rfd
);
4413 free (input_debug
.external_ext
);
4415 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4416 elf_link_input_bfd ignores this section. */
4417 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4420 if (SGI_COMPAT (abfd
) && info
->shared
)
4422 /* Create .rtproc section. */
4423 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4424 if (rtproc_sec
== NULL
)
4426 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4427 | SEC_LINKER_CREATED
| SEC_READONLY
);
4429 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4430 if (rtproc_sec
== NULL
4431 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4432 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
4436 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
4437 info
, rtproc_sec
, &debug
))
4441 /* Build the external symbol information. */
4444 einfo
.debug
= &debug
;
4446 einfo
.failed
= false;
4447 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4448 mips_elf_output_extsym
,
4453 /* Set the size of the .mdebug section. */
4454 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4456 /* Skip this section later on (I don't think this currently
4457 matters, but someday it might). */
4458 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4463 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4465 const char *subname
;
4468 Elf32_External_gptab
*ext_tab
;
4471 /* The .gptab.sdata and .gptab.sbss sections hold
4472 information describing how the small data area would
4473 change depending upon the -G switch. These sections
4474 not used in executables files. */
4475 if (! info
->relocateable
)
4479 for (p
= o
->link_order_head
;
4480 p
!= (struct bfd_link_order
*) NULL
;
4483 asection
*input_section
;
4485 if (p
->type
!= bfd_indirect_link_order
)
4487 if (p
->type
== bfd_fill_link_order
)
4492 input_section
= p
->u
.indirect
.section
;
4494 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4495 elf_link_input_bfd ignores this section. */
4496 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4499 /* Skip this section later on (I don't think this
4500 currently matters, but someday it might). */
4501 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4503 /* Really remove the section. */
4504 for (secpp
= &abfd
->sections
;
4506 secpp
= &(*secpp
)->next
)
4508 *secpp
= (*secpp
)->next
;
4509 --abfd
->section_count
;
4514 /* There is one gptab for initialized data, and one for
4515 uninitialized data. */
4516 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4518 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4522 (*_bfd_error_handler
)
4523 (_("%s: illegal section name `%s'"),
4524 bfd_get_filename (abfd
), o
->name
);
4525 bfd_set_error (bfd_error_nonrepresentable_section
);
4529 /* The linker script always combines .gptab.data and
4530 .gptab.sdata into .gptab.sdata, and likewise for
4531 .gptab.bss and .gptab.sbss. It is possible that there is
4532 no .sdata or .sbss section in the output file, in which
4533 case we must change the name of the output section. */
4534 subname
= o
->name
+ sizeof ".gptab" - 1;
4535 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4537 if (o
== gptab_data_sec
)
4538 o
->name
= ".gptab.data";
4540 o
->name
= ".gptab.bss";
4541 subname
= o
->name
+ sizeof ".gptab" - 1;
4542 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4545 /* Set up the first entry. */
4547 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
4550 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4551 tab
[0].gt_header
.gt_unused
= 0;
4553 /* Combine the input sections. */
4554 for (p
= o
->link_order_head
;
4555 p
!= (struct bfd_link_order
*) NULL
;
4558 asection
*input_section
;
4562 bfd_size_type gpentry
;
4564 if (p
->type
!= bfd_indirect_link_order
)
4566 if (p
->type
== bfd_fill_link_order
)
4571 input_section
= p
->u
.indirect
.section
;
4572 input_bfd
= input_section
->owner
;
4574 /* Combine the gptab entries for this input section one
4575 by one. We know that the input gptab entries are
4576 sorted by ascending -G value. */
4577 size
= bfd_section_size (input_bfd
, input_section
);
4579 for (gpentry
= sizeof (Elf32_External_gptab
);
4581 gpentry
+= sizeof (Elf32_External_gptab
))
4583 Elf32_External_gptab ext_gptab
;
4584 Elf32_gptab int_gptab
;
4590 if (! (bfd_get_section_contents
4591 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4592 gpentry
, sizeof (Elf32_External_gptab
))))
4598 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
4600 val
= int_gptab
.gt_entry
.gt_g_value
;
4601 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4604 for (look
= 1; look
< c
; look
++)
4606 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4607 tab
[look
].gt_entry
.gt_bytes
+= add
;
4609 if (tab
[look
].gt_entry
.gt_g_value
== val
)
4615 Elf32_gptab
*new_tab
;
4618 /* We need a new table entry. */
4619 new_tab
= ((Elf32_gptab
*)
4620 bfd_realloc ((PTR
) tab
,
4621 (c
+ 1) * sizeof (Elf32_gptab
)));
4622 if (new_tab
== NULL
)
4628 tab
[c
].gt_entry
.gt_g_value
= val
;
4629 tab
[c
].gt_entry
.gt_bytes
= add
;
4631 /* Merge in the size for the next smallest -G
4632 value, since that will be implied by this new
4635 for (look
= 1; look
< c
; look
++)
4637 if (tab
[look
].gt_entry
.gt_g_value
< val
4639 || (tab
[look
].gt_entry
.gt_g_value
4640 > tab
[max
].gt_entry
.gt_g_value
)))
4644 tab
[c
].gt_entry
.gt_bytes
+=
4645 tab
[max
].gt_entry
.gt_bytes
;
4650 last
= int_gptab
.gt_entry
.gt_bytes
;
4653 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4654 elf_link_input_bfd ignores this section. */
4655 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4658 /* The table must be sorted by -G value. */
4660 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
4662 /* Swap out the table. */
4663 ext_tab
= ((Elf32_External_gptab
*)
4664 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
4665 if (ext_tab
== NULL
)
4671 for (i
= 0; i
< c
; i
++)
4672 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
4675 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
4676 o
->contents
= (bfd_byte
*) ext_tab
;
4678 /* Skip this section later on (I don't think this currently
4679 matters, but someday it might). */
4680 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4684 /* Invoke the regular ELF backend linker to do all the work. */
4685 if (! bfd_elf32_bfd_final_link (abfd
, info
))
4688 /* Now write out the computed sections. */
4690 if (reginfo_sec
!= (asection
*) NULL
)
4692 Elf32_External_RegInfo ext
;
4694 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
4695 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4696 (file_ptr
) 0, sizeof ext
))
4700 if (mdebug_sec
!= (asection
*) NULL
)
4702 BFD_ASSERT (abfd
->output_has_begun
);
4703 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4705 mdebug_sec
->filepos
))
4708 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4711 if (gptab_data_sec
!= (asection
*) NULL
)
4713 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4714 gptab_data_sec
->contents
,
4716 gptab_data_sec
->_raw_size
))
4720 if (gptab_bss_sec
!= (asection
*) NULL
)
4722 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4723 gptab_bss_sec
->contents
,
4725 gptab_bss_sec
->_raw_size
))
4729 if (SGI_COMPAT (abfd
))
4731 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4732 if (rtproc_sec
!= NULL
)
4734 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
4735 rtproc_sec
->contents
,
4737 rtproc_sec
->_raw_size
))
4745 /* Handle a MIPS ELF HI16 reloc. */
4748 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
4750 Elf_Internal_Rela
*relhi
;
4751 Elf_Internal_Rela
*rello
;
4758 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4760 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4763 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4765 if ((addlo
& 0x8000) != 0)
4767 if ((addend
& 0x8000) != 0)
4770 bfd_put_32 (input_bfd
,
4771 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
4772 contents
+ relhi
->r_offset
);
4775 /* Handle a MIPS ELF local GOT16 reloc. */
4778 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
4783 Elf_Internal_Rela
*relhi
;
4784 Elf_Internal_Rela
*rello
;
4788 unsigned int assigned_gotno
;
4794 bfd_byte
*got_contents
;
4795 struct mips_got_info
*g
;
4797 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4799 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4802 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4804 if ((addlo
& 0x8000) != 0)
4806 if ((addend
& 0x8000) != 0)
4809 /* Get a got entry representing requested hipage. */
4810 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4811 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4812 BFD_ASSERT (g
!= NULL
);
4814 assigned_gotno
= g
->assigned_gotno
;
4815 got_contents
= sgot
->contents
;
4816 hipage
= addend
& 0xffff0000;
4818 for (i
= MIPS_RESERVED_GOTNO
; i
< assigned_gotno
; i
++)
4820 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
4821 if (hipage
== (address
& 0xffff0000))
4825 if (i
== assigned_gotno
)
4827 if (assigned_gotno
>= g
->local_gotno
)
4829 (*_bfd_error_handler
)
4830 (_("more got entries are needed for hipage relocations"));
4831 bfd_set_error (bfd_error_bad_value
);
4835 bfd_put_32 (input_bfd
, hipage
, got_contents
+ assigned_gotno
* 4);
4836 ++g
->assigned_gotno
;
4839 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
4840 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
4841 contents
+ relhi
->r_offset
);
4846 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
4849 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
4851 Elf_Internal_Rela
*rel
;
4857 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4858 bfd_put_32 (input_bfd
,
4859 (insn
& 0xffff0000) | (offset
& 0xffff),
4860 contents
+ rel
->r_offset
);
4863 /* Relocate a MIPS ELF section. */
4866 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4867 contents
, relocs
, local_syms
, local_sections
)
4869 struct bfd_link_info
*info
;
4871 asection
*input_section
;
4873 Elf_Internal_Rela
*relocs
;
4874 Elf_Internal_Sym
*local_syms
;
4875 asection
**local_sections
;
4877 Elf_Internal_Shdr
*symtab_hdr
;
4880 asection
*sgot
, *sreloc
, *scpt
;
4883 Elf_Internal_Rela
*rel
;
4884 Elf_Internal_Rela
*relend
;
4885 struct mips_got_info
*g
;
4887 dynobj
= elf_hash_table (info
)->dynobj
;
4888 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4892 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
4895 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
4898 if (elf_bad_symtab (input_bfd
))
4900 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
4905 locsymcount
= symtab_hdr
->sh_info
;
4906 extsymoff
= symtab_hdr
->sh_info
;
4909 gp
= _bfd_get_gp_value (output_bfd
);
4912 relend
= relocs
+ input_section
->reloc_count
;
4913 for (; rel
< relend
; rel
++)
4916 reloc_howto_type
*howto
;
4917 unsigned long r_symndx
;
4919 struct elf_link_hash_entry
*h
;
4921 Elf_Internal_Sym
*sym
;
4922 struct mips_elf_link_hash_entry
*mh
;
4924 bfd_reloc_status_type r
;
4926 r_type
= ELF32_R_TYPE (rel
->r_info
);
4927 if (r_type
== R_MIPS_GNU_VTINHERIT
4928 || r_type
== R_MIPS_GNU_VTENTRY
)
4930 if ((r_type
< 0 || r_type
>= (int) R_MIPS_max
)
4931 /* start-sanitize-sky */
4932 && r_type
!= R_MIPS_DVP_11_PCREL
4933 && r_type
!= R_MIPS_DVP_27_S4
4934 && r_type
!= R_MIPS_DVP_11_S4
4935 && r_type
!= R_MIPS_DVP_U15_S3
4936 /* end-sanitize-sky */
4937 && r_type
!= R_MIPS16_26
4938 && r_type
!= R_MIPS16_GPREL
)
4940 bfd_set_error (bfd_error_bad_value
);
4943 if (r_type
== R_MIPS16_26
)
4944 howto
= &elf_mips16_jump_howto
;
4945 else if (r_type
== R_MIPS16_GPREL
)
4946 howto
= &elf_mips16_gprel_howto
;
4947 /* start-sanitize-sky */
4948 else if (r_type
== R_MIPS_DVP_11_PCREL
)
4949 howto
= &elf_mips_dvp_11_pcrel_howto
;
4950 else if (r_type
== R_MIPS_DVP_27_S4
)
4951 howto
= &elf_mips_dvp_27_s4_howto
;
4952 else if (r_type
== R_MIPS_DVP_11_S4
)
4953 howto
= &elf_mips_dvp_11_s4_howto
;
4954 else if (r_type
== R_MIPS_DVP_U15_S3
)
4955 howto
= &elf_mips_dvp_u15_s3_howto
;
4956 /* end-sanitize-sky */
4958 howto
= elf_mips_howto_table
+ r_type
;
4961 && (r_type
== R_MIPS_CALL16
4962 || r_type
== R_MIPS_GOT16
4963 || r_type
== R_MIPS_CALL_HI16
4964 || r_type
== R_MIPS_CALL_LO16
4965 || r_type
== R_MIPS_GOT_HI16
4966 || r_type
== R_MIPS_GOT_LO16
))
4968 /* We need the .got section. */
4971 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4972 BFD_ASSERT (sgot
!= NULL
);
4973 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4974 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4975 BFD_ASSERT (g
!= NULL
);
4979 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4981 /* Mix in the change in GP address for a GP relative reloc. */
4982 if (r_type
!= R_MIPS_GPREL16
4983 && r_type
!= R_MIPS_LITERAL
4984 && r_type
!= R_MIPS_GPREL32
4985 && r_type
!= R_MIPS16_GPREL
)
4991 if (! ((*info
->callbacks
->reloc_dangerous
)
4993 _("GP relative relocation when GP not defined"),
4994 input_bfd
, input_section
,
4997 /* Only give the error once per link. */
4999 _bfd_set_gp_value (output_bfd
, gp
);
5002 if (r_symndx
< extsymoff
5003 || (elf_bad_symtab (input_bfd
)
5004 && local_sections
[r_symndx
] != NULL
))
5006 /* This is a relocation against a section. The current
5007 addend in the instruction is the difference between
5008 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
5009 must change this to be the difference between the
5010 final definition (which will end up in RELOCATION)
5011 and the GP value of OUTPUT_BFD (which is in GP). */
5012 addend
= elf_gp (input_bfd
) - gp
;
5014 else if (! info
->relocateable
)
5016 /* We are doing a final link. The current addend in the
5017 instruction is simply the desired offset into the
5018 symbol (normally zero). We want the instruction to
5019 hold the difference between the final definition of
5020 the symbol (which will end up in RELOCATION) and the
5021 GP value of OUTPUT_BFD (which is in GP). */
5026 /* We are generating relocateable output, and we aren't
5027 going to define this symbol, so we just leave the
5028 instruction alone. */
5036 if (info
->relocateable
)
5038 /* This is a relocateable link. We don't have to change
5039 anything, unless the reloc is against a section symbol,
5040 in which case we have to adjust according to where the
5041 section symbol winds up in the output section. */
5042 if (r_symndx
>= locsymcount
5043 || (elf_bad_symtab (input_bfd
)
5044 && local_sections
[r_symndx
] == NULL
))
5048 sym
= local_syms
+ r_symndx
;
5049 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5053 sec
= local_sections
[r_symndx
];
5055 /* It would be logical to add sym->st_value here,
5056 but Irix 5 sometimes generates a garbage symbol
5058 addend
+= sec
->output_offset
;
5060 /* If this is HI16 or GOT16 with an associated LO16,
5061 adjust the addend accordingly. Otherwise, just
5063 if (r_type
== R_MIPS_64
&& bfd_big_endian (input_bfd
))
5064 r
= _bfd_relocate_contents (howto
, input_bfd
,
5066 contents
+ rel
->r_offset
+ 4);
5067 else if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
5068 r
= _bfd_relocate_contents (howto
, input_bfd
,
5070 contents
+ rel
->r_offset
);
5073 Elf_Internal_Rela
*lorel
;
5075 /* As a GNU extension, permit an arbitrary
5076 number of R_MIPS_HI16 relocs before the
5077 R_MIPS_LO16 reloc. This permits gcc to emit
5078 the HI and LO relocs itself. */
5079 if (r_type
== R_MIPS_GOT16
)
5083 for (lorel
= rel
+ 1;
5085 && (ELF32_R_TYPE (lorel
->r_info
)
5091 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5093 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5098 r
= _bfd_relocate_contents (howto
, input_bfd
,
5100 contents
+ rel
->r_offset
);
5109 boolean undefined_error
;
5111 /* This is a final link. */
5112 undefined_error
= false;
5114 if (r_symndx
< extsymoff
5115 || (elf_bad_symtab (input_bfd
)
5116 && local_sections
[r_symndx
] != NULL
))
5119 sym
= local_syms
+ r_symndx
;
5120 sec
= local_sections
[r_symndx
];
5121 relocation
= (sec
->output_section
->vma
5122 + sec
->output_offset
);
5124 /* It would be logical to always add sym->st_value here,
5125 but Irix 5 sometimes generates a garbage symbol
5127 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5128 relocation
+= sym
->st_value
;
5130 /* mips16 text labels should be treated as odd. */
5131 if (sym
->st_other
== STO_MIPS16
)
5139 indx
= r_symndx
- extsymoff
;
5140 h
= elf_sym_hashes (input_bfd
)[indx
];
5141 while (h
->root
.type
== bfd_link_hash_indirect
5142 || h
->root
.type
== bfd_link_hash_warning
)
5143 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5144 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
5148 if (! ((*info
->callbacks
->reloc_dangerous
)
5150 _("_gp_disp used when GP not defined"),
5151 input_bfd
, input_section
,
5154 /* Only give the error once per link. */
5156 _bfd_set_gp_value (output_bfd
, gp
);
5161 sec
= input_section
;
5162 if (sec
->output_section
!= NULL
)
5165 + sec
->output_section
->vma
5166 + sec
->output_offset
));
5168 relocation
= gp
- rel
->r_offset
;
5169 if (r_type
== R_MIPS_LO16
)
5173 else if (h
->root
.type
== bfd_link_hash_defined
5174 || h
->root
.type
== bfd_link_hash_defweak
)
5176 sec
= h
->root
.u
.def
.section
;
5177 if (sec
->output_section
== NULL
)
5180 relocation
= (h
->root
.u
.def
.value
5181 + sec
->output_section
->vma
5182 + sec
->output_offset
);
5184 else if (h
->root
.type
== bfd_link_hash_undefweak
)
5186 else if (info
->shared
&& ! info
->symbolic
)
5188 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
5190 /* If this is a dynamic link, we should have created
5191 a _DYNAMIC_LINK symbol in
5192 mips_elf_create_dynamic_sections. Otherwise, we
5193 should define the symbol with a value of 0.
5194 FIXME: It should probably get into the symbol
5195 table somehow as well. */
5196 BFD_ASSERT (! info
->shared
);
5197 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
5198 ".dynamic") == NULL
);
5203 if (! ((*info
->callbacks
->undefined_symbol
)
5204 (info
, h
->root
.root
.string
, input_bfd
,
5205 input_section
, rel
->r_offset
)))
5207 undefined_error
= true;
5212 mh
= (struct mips_elf_link_hash_entry
*) h
;
5215 else if (sym
!= NULL
)
5216 other
= sym
->st_other
;
5220 /* If this function has an fn_stub, then it is a mips16
5221 function which needs a stub if it is called by a 32 bit
5222 function. If this reloc is anything other than a 16 bit
5223 call, redirect the reloc to the stub. We don't redirect
5224 relocs from other stub functions. */
5225 if (r_type
!= R_MIPS16_26
5227 && mh
->fn_stub
!= NULL
)
5229 && elf_tdata (input_bfd
)->local_stubs
!= NULL
5230 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
5231 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5232 FN_STUB
, sizeof FN_STUB
- 1) != 0
5233 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5234 CALL_STUB
, sizeof CALL_STUB
- 1) != 0
5235 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5236 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) != 0)
5240 BFD_ASSERT (mh
->need_fn_stub
);
5241 relocation
= (mh
->fn_stub
->output_section
->vma
5242 + mh
->fn_stub
->output_offset
);
5248 fn_stub
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
5249 relocation
= (fn_stub
->output_section
->vma
5250 + fn_stub
->output_offset
);
5253 /* RELOCATION now points to 32 bit code. */
5257 /* If this function has a call_stub, then it is called by a
5258 mips16 function; the call needs to go through a stub if
5259 this function is a 32 bit function. If this reloc is a
5260 16 bit call, and the symbol is not a 16 bit function,
5261 then redirect the reloc to the stub. Note that we don't
5262 need to worry about calling the function through a
5263 function pointer; such calls are handled by routing
5264 through a special mips16 routine. We don't have to check
5265 whether this call is from a stub; it can't be, because a
5266 stub contains 32 bit code, and hence can not have a 16
5268 if (r_type
== R_MIPS16_26
5270 && (mh
->call_stub
!= NULL
|| mh
->call_fp_stub
!= NULL
)
5271 && other
!= STO_MIPS16
)
5275 /* If both call_stub and call_fp_stub are defined, we
5276 can figure out which one to use by seeing which one
5277 appears in the input file. */
5278 if (mh
->call_stub
!= NULL
&& mh
->call_fp_stub
!= NULL
)
5283 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
5285 if (strncmp (bfd_get_section_name (input_bfd
, o
),
5286 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5288 stub
= mh
->call_fp_stub
;
5293 stub
= mh
->call_stub
;
5295 else if (mh
->call_stub
!= NULL
)
5296 stub
= mh
->call_stub
;
5298 stub
= mh
->call_fp_stub
;
5300 BFD_ASSERT (stub
->_raw_size
> 0);
5301 relocation
= stub
->output_section
->vma
+ stub
->output_offset
;
5304 if (r_type
== R_MIPS_HI16
)
5306 Elf_Internal_Rela
*lorel
;
5308 /* As a GNU extension, permit an arbitrary number of
5309 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
5310 This permits gcc to emit the HI and LO relocs itself. */
5311 for (lorel
= rel
+ 1;
5313 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
5317 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5319 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5320 contents
, relocation
+ addend
);
5324 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5325 contents
, rel
->r_offset
,
5326 relocation
, addend
);
5328 else if (r_type
== R_MIPS_GOT16
&& local
)
5330 /* GOT16 must also have an associated LO16 in the local
5331 case. In this case, the addend is extracted and the
5332 section in which the referenced object is determined.
5333 Then the final address of the object is computed and
5334 the GOT entry for the hipage (an aligned 64kb chunk)
5335 is added to .got section if needed. The offset field
5336 of the GOT16-relocated instruction is replaced by the
5337 index of this GOT entry for the hipage. */
5338 if ((rel
+ 1) < relend
5339 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
5341 if (! mips_elf_relocate_got_local (output_bfd
, input_bfd
,
5344 relocation
+ addend
))
5349 r
= bfd_reloc_outofrange
;
5351 else if (r_type
== R_MIPS_CALL16
5352 || r_type
== R_MIPS_GOT16
5353 || r_type
== R_MIPS_CALL_LO16
5354 || r_type
== R_MIPS_GOT_LO16
)
5358 /* This symbol must be registered as a global symbol
5359 having the corresponding got entry. */
5360 BFD_ASSERT (h
->got
.offset
!= (bfd_vma
) -1);
5362 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5363 BFD_ASSERT (g
->local_gotno
<= offset
5364 && offset
< sgot
->_raw_size
);
5365 bfd_put_32 (output_bfd
, relocation
+ addend
,
5366 sgot
->contents
+ offset
);
5367 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5369 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
5373 else if (r_type
== R_MIPS_CALL_HI16
5374 || r_type
== R_MIPS_GOT_HI16
)
5378 /* This must be a global symbol with a got entry. The
5379 next reloc must be the corresponding LO16 reloc. */
5380 BFD_ASSERT (h
!= NULL
&& h
->got
.offset
!= (bfd_vma
) -1);
5381 BFD_ASSERT ((rel
+ 1) < relend
);
5382 BFD_ASSERT ((int) ELF32_R_TYPE ((rel
+ 1)->r_info
)
5383 == (r_type
== R_MIPS_CALL_HI16
5384 ? (int) R_MIPS_CALL_LO16
5385 : (int) R_MIPS_GOT_LO16
));
5387 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5388 BFD_ASSERT (g
->local_gotno
<= offset
5389 && offset
< sgot
->_raw_size
);
5390 bfd_put_32 (output_bfd
, relocation
+ addend
,
5391 sgot
->contents
+ offset
);
5392 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5394 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
5398 else if (r_type
== R_MIPS_REL32
5399 || r_type
== R_MIPS_32
)
5401 Elf_Internal_Rel outrel
;
5402 Elf32_crinfo cptrel
;
5406 || (elf_hash_table (info
)->dynamic_sections_created
5408 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
5410 && (input_section
->flags
& SEC_ALLOC
) != 0)
5414 /* When generating a shared object, these
5415 relocations are copied into the output file to be
5416 resolved at run time. */
5419 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5420 BFD_ASSERT (sreloc
!= NULL
);
5425 if (elf_section_data (input_section
)->stab_info
== NULL
)
5426 outrel
.r_offset
= rel
->r_offset
;
5431 off
= (_bfd_stab_section_offset
5432 (output_bfd
, &elf_hash_table (info
)->stab_info
,
5434 &elf_section_data (input_section
)->stab_info
,
5436 if (off
== (bfd_vma
) -1)
5438 outrel
.r_offset
= off
;
5441 outrel
.r_offset
+= (input_section
->output_section
->vma
5442 + input_section
->output_offset
);
5444 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5447 memset (&outrel
, 0, sizeof outrel
);
5449 && (! info
->symbolic
5450 || (h
->elf_link_hash_flags
5451 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5453 BFD_ASSERT (h
->dynindx
!= -1);
5454 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
5455 sec
= input_section
;
5462 sec
= local_sections
[r_symndx
];
5465 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
5467 == bfd_link_hash_defweak
));
5468 sec
= h
->root
.u
.def
.section
;
5470 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5472 else if (sec
== NULL
|| sec
->owner
== NULL
)
5474 bfd_set_error (bfd_error_bad_value
);
5481 osec
= sec
->output_section
;
5482 indx
= elf_section_data (osec
)->dynindx
;
5487 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
5488 addend
+= relocation
;
5492 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
5494 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
5495 (((Elf32_External_Rel
*)
5497 + sreloc
->reloc_count
));
5498 ++sreloc
->reloc_count
;
5500 if (! skip
&& SGI_COMPAT (output_bfd
))
5505 /* Make an entry of compact relocation info. */
5506 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5507 cptrel
.vaddr
= (rel
->r_offset
5508 + input_section
->output_section
->vma
5509 + input_section
->output_offset
);
5510 if (r_type
== R_MIPS_REL32
)
5511 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5513 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5514 mips_elf_set_cr_dist2to (cptrel
, 0);
5515 cptrel
.konst
= addend
;
5517 cr
= (scpt
->contents
5518 + sizeof (Elf32_External_compact_rel
));
5519 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5520 ((Elf32_External_crinfo
*) cr
5521 + scpt
->reloc_count
));
5522 ++scpt
->reloc_count
;
5525 /* This reloc will be computed at runtime, so
5526 there's no need to do anything now. */
5530 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5531 contents
, rel
->r_offset
,
5532 relocation
, addend
);
5534 else if (r_type
== R_MIPS_64
)
5539 /* Do a 32 bit relocation, and sign extend to 64 bits. */
5540 addr
= rel
->r_offset
;
5541 if (bfd_big_endian (input_bfd
))
5543 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5544 contents
, addr
, relocation
,
5546 val
= bfd_get_32 (input_bfd
, contents
+ addr
);
5547 if ((val
& 0x80000000) != 0)
5551 addr
= rel
->r_offset
;
5552 if (bfd_little_endian (input_bfd
))
5554 bfd_put_32 (input_bfd
, val
, contents
+ addr
);
5556 else if (r_type
== R_MIPS_26
&& other
== STO_MIPS16
)
5560 /* This is a jump to a mips16 routine from a mips32
5561 routine. We need to change jal into jalx. */
5562 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5563 if (((insn
>> 26) & 0x3f) != 0x3
5564 && ((insn
>> 26) & 0x3f) != 0x1d)
5566 (*_bfd_error_handler
)
5567 (_("%s: %s+0x%lx: jump to mips16 routine which is not jal"),
5568 bfd_get_filename (input_bfd
),
5569 input_section
->name
,
5570 (unsigned long) rel
->r_offset
);
5571 bfd_set_error (bfd_error_bad_value
);
5574 insn
= (insn
& 0x3ffffff) | (0x1d << 26);
5575 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5576 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5577 contents
, rel
->r_offset
,
5578 relocation
, addend
);
5580 else if (r_type
== R_MIPS16_26
)
5582 /* It's easiest to do the normal relocation, and then
5583 dig out the instruction and swap the first word the
5584 way the mips16 expects it. If this is little endian,
5585 though, we need to swap the two words first, and then
5586 swap them back again later, so that the address looks
5589 if (bfd_little_endian (input_bfd
))
5593 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5594 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5595 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5598 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5599 contents
, rel
->r_offset
,
5600 relocation
, addend
);
5601 if (r
== bfd_reloc_ok
)
5605 if (bfd_little_endian (input_bfd
))
5607 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5608 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5609 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5612 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5613 insn
= ((insn
& 0xfc00)
5614 | ((insn
& 0x1f) << 5)
5615 | ((insn
& 0x3e0) >> 5));
5616 /* If this is a jump to a 32 bit routine, then make
5618 if (other
!= STO_MIPS16
)
5620 bfd_put_16 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5623 else if (r_type
== R_MIPS16_GPREL
)
5625 unsigned short extend
, insn
;
5627 unsigned long final
;
5629 /* Extract the addend into buf, run the regular reloc,
5630 and stuff the resulting value back into the
5632 if (rel
->r_offset
> input_section
->_raw_size
)
5633 r
= bfd_reloc_outofrange
;
5636 extend
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5637 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 2);
5638 bfd_put_32 (input_bfd
,
5639 (((extend
& 0x1f) << 11)
5643 r
= _bfd_final_link_relocate (howto
, input_bfd
,
5645 (bfd_vma
) 0, relocation
,
5647 final
= bfd_get_32 (input_bfd
, buf
);
5648 bfd_put_16 (input_bfd
,
5650 | ((final
>> 11) & 0x1f)
5652 contents
+ rel
->r_offset
);
5653 bfd_put_16 (input_bfd
,
5656 contents
+ rel
->r_offset
+ 2);
5659 /* start-sanitize-sky */
5660 else if (r_type
== R_MIPS_DVP_U15_S3
)
5662 if (rel
->r_offset
> input_section
->_raw_size
)
5663 r
= bfd_reloc_outofrange
;
5668 relocation
+= rel
->r_addend
;
5671 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5672 relocation
+= ((x
& (0xf << 21)) >> 10) + (x
& 0x7ff);
5673 x
&= ~ ((0xf << 21) | 0x7ff);
5674 x
|= (((relocation
& 0x7800) << 10)
5675 | (relocation
& 0x7ff));
5676 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
5678 if (relocation
& ~ (bfd_vma
) 0x7fff)
5679 r
= bfd_reloc_overflow
;
5684 /* end-sanitize-sky */
5686 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5687 contents
, rel
->r_offset
,
5688 relocation
, addend
);
5690 /* The jal instruction can only jump to an address which is
5691 divisible by 4, and it can only jump to an address with
5692 the same upper 4 bits as the PC. */
5693 if (r
== bfd_reloc_ok
5694 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
))
5699 if (other
== STO_MIPS16
)
5700 addr
&= ~ (bfd_vma
) 1;
5703 || ((addr
& 0xf0000000)
5704 != ((input_section
->output_section
->vma
5705 + input_section
->output_offset
5708 r
= bfd_reloc_overflow
;
5711 /* Don't bother to report a relocation overflow for a call
5712 to a weak undefined symbol with a value of zero. This
5715 even if we aren't in range to call address zero. */
5716 if (r
== bfd_reloc_overflow
5717 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
)
5718 && relocation
+ addend
== 0
5720 && h
->root
.type
== bfd_link_hash_undefweak
)
5723 /* If we've already issued an error for an undefined symbol,
5724 don't issue another useless error. */
5726 && (r
== bfd_reloc_undefined
|| r
== bfd_reloc_overflow
))
5729 if (SGI_COMPAT (abfd
)
5731 && (input_section
->flags
& SEC_ALLOC
) != 0)
5733 Elf32_crinfo cptrel
;
5736 /* Make an entry of compact relocation info. */
5737 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5738 cptrel
.vaddr
= (rel
->r_offset
5739 + input_section
->output_section
->vma
5740 + input_section
->output_offset
);
5745 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
5746 /* XXX How should we set dist2to in this case. */
5747 mips_elf_set_cr_dist2to (cptrel
, 8);
5748 cptrel
.konst
= addend
+ relocation
;
5749 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5750 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5751 ((Elf32_External_crinfo
*) cr
5752 + scpt
->reloc_count
));
5753 ++scpt
->reloc_count
;
5756 case R_MIPS_GPREL16
:
5757 case R_MIPS_LITERAL
:
5758 case R_MIPS_GPREL32
:
5759 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
5760 cptrel
.konst
= gp
- cptrel
.vaddr
;
5761 mips_elf_set_cr_dist2to (cptrel
, 4);
5762 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5763 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5764 ((Elf32_External_crinfo
*) cr
5765 + scpt
->reloc_count
));
5766 ++scpt
->reloc_count
;
5775 if (r
!= bfd_reloc_ok
)
5780 case bfd_reloc_outofrange
:
5782 case bfd_reloc_overflow
:
5787 name
= h
->root
.root
.string
;
5790 name
= bfd_elf_string_from_elf_section (input_bfd
,
5791 symtab_hdr
->sh_link
,
5796 name
= bfd_section_name (input_bfd
, sec
);
5798 if (! ((*info
->callbacks
->reloc_overflow
)
5799 (info
, name
, howto
->name
, (bfd_vma
) 0,
5800 input_bfd
, input_section
, rel
->r_offset
)))
5811 /* This hook function is called before the linker writes out a global
5812 symbol. We mark symbols as small common if appropriate. This is
5813 also where we undo the increment of the value for a mips16 symbol. */
5817 mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
5819 struct bfd_link_info
*info
;
5821 Elf_Internal_Sym
*sym
;
5822 asection
*input_sec
;
5824 /* If we see a common symbol, which implies a relocatable link, then
5825 if a symbol was small common in an input file, mark it as small
5826 common in the output file. */
5827 if (sym
->st_shndx
== SHN_COMMON
5828 && strcmp (input_sec
->name
, ".scommon") == 0)
5829 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
5831 if (sym
->st_other
== STO_MIPS16
5832 && (sym
->st_value
& 1) != 0)
5838 /* Functions for the dynamic linker. */
5840 /* The name of the dynamic interpreter. This is put in the .interp
5843 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
5845 /* Create dynamic sections when linking against a dynamic object. */
5848 mips_elf_create_dynamic_sections (abfd
, info
)
5850 struct bfd_link_info
*info
;
5852 struct elf_link_hash_entry
*h
;
5854 register asection
*s
;
5855 const char * const *namep
;
5857 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5858 | SEC_LINKER_CREATED
| SEC_READONLY
);
5860 /* Mips ABI requests the .dynamic section to be read only. */
5861 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5864 if (! bfd_set_section_flags (abfd
, s
, flags
))
5868 /* We need to create .got section. */
5869 if (! mips_elf_create_got_section (abfd
, info
))
5872 /* Create .stub section. */
5873 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
5875 s
= bfd_make_section (abfd
, ".stub");
5877 || ! bfd_set_section_flags (abfd
, s
, flags
)
5878 || ! bfd_set_section_alignment (abfd
, s
, 2))
5882 if (SGI_COMPAT (abfd
)
5884 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
5886 s
= bfd_make_section (abfd
, ".rld_map");
5888 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
5889 || ! bfd_set_section_alignment (abfd
, s
, 2))
5893 if (SGI_COMPAT (abfd
))
5895 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
5898 if (! (_bfd_generic_link_add_one_symbol
5899 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
5900 (bfd_vma
) 0, (const char *) NULL
, false,
5901 get_elf_backend_data (abfd
)->collect
,
5902 (struct bfd_link_hash_entry
**) &h
)))
5904 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5905 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5906 h
->type
= STT_SECTION
;
5908 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5912 /* We need to create a .compact_rel section. */
5913 if (! mips_elf_create_compact_rel_section (abfd
, info
))
5916 /* Change aligments of some sections. */
5917 s
= bfd_get_section_by_name (abfd
, ".hash");
5919 bfd_set_section_alignment (abfd
, s
, 4);
5920 s
= bfd_get_section_by_name (abfd
, ".dynsym");
5922 bfd_set_section_alignment (abfd
, s
, 4);
5923 s
= bfd_get_section_by_name (abfd
, ".dynstr");
5925 bfd_set_section_alignment (abfd
, s
, 4);
5926 s
= bfd_get_section_by_name (abfd
, ".reginfo");
5928 bfd_set_section_alignment (abfd
, s
, 4);
5929 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5931 bfd_set_section_alignment (abfd
, s
, 4);
5937 if (! (_bfd_generic_link_add_one_symbol
5938 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
5939 (bfd_vma
) 0, (const char *) NULL
, false,
5940 get_elf_backend_data (abfd
)->collect
,
5941 (struct bfd_link_hash_entry
**) &h
)))
5943 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5944 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5945 h
->type
= STT_SECTION
;
5947 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5950 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
5952 /* __rld_map is a four byte word located in the .data section
5953 and is filled in by the rtld to contain a pointer to
5954 the _r_debug structure. Its symbol value will be set in
5955 mips_elf_finish_dynamic_symbol. */
5956 s
= bfd_get_section_by_name (abfd
, ".rld_map");
5957 BFD_ASSERT (s
!= NULL
);
5960 if (! (_bfd_generic_link_add_one_symbol
5961 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
5962 (bfd_vma
) 0, (const char *) NULL
, false,
5963 get_elf_backend_data (abfd
)->collect
,
5964 (struct bfd_link_hash_entry
**) &h
)))
5966 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5967 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5968 h
->type
= STT_OBJECT
;
5970 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5978 /* Create the .compact_rel section. */
5981 mips_elf_create_compact_rel_section (abfd
, info
)
5983 struct bfd_link_info
*info
;
5986 register asection
*s
;
5988 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
5990 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
5993 s
= bfd_make_section (abfd
, ".compact_rel");
5995 || ! bfd_set_section_flags (abfd
, s
, flags
)
5996 || ! bfd_set_section_alignment (abfd
, s
, 2))
5999 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
6005 /* Create the .got section to hold the global offset table. */
6008 mips_elf_create_got_section (abfd
, info
)
6010 struct bfd_link_info
*info
;
6013 register asection
*s
;
6014 struct elf_link_hash_entry
*h
;
6015 struct mips_got_info
*g
;
6017 /* This function may be called more than once. */
6018 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
6021 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6022 | SEC_LINKER_CREATED
);
6024 s
= bfd_make_section (abfd
, ".got");
6026 || ! bfd_set_section_flags (abfd
, s
, flags
)
6027 || ! bfd_set_section_alignment (abfd
, s
, 4))
6030 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
6031 linker script because we don't want to define the symbol if we
6032 are not creating a global offset table. */
6034 if (! (_bfd_generic_link_add_one_symbol
6035 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
6036 (bfd_vma
) 0, (const char *) NULL
, false,
6037 get_elf_backend_data (abfd
)->collect
,
6038 (struct bfd_link_hash_entry
**) &h
)))
6040 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6041 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6042 h
->type
= STT_OBJECT
;
6045 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6048 /* The first several global offset table entries are reserved. */
6049 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
6051 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
6052 sizeof (struct mips_got_info
));
6055 g
->global_gotsym
= 0;
6056 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
6057 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
6058 if (elf_section_data (s
) == NULL
)
6061 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
6062 if (elf_section_data (s
) == NULL
)
6065 elf_section_data (s
)->tdata
= (PTR
) g
;
6070 /* Look through the relocs for a section during the first phase, and
6071 allocate space in the global offset table. */
6074 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
6076 struct bfd_link_info
*info
;
6078 const Elf_Internal_Rela
*relocs
;
6082 Elf_Internal_Shdr
*symtab_hdr
;
6083 struct elf_link_hash_entry
**sym_hashes
;
6084 struct mips_got_info
*g
;
6086 const Elf_Internal_Rela
*rel
;
6087 const Elf_Internal_Rela
*rel_end
;
6091 if (info
->relocateable
)
6094 dynobj
= elf_hash_table (info
)->dynobj
;
6095 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6096 sym_hashes
= elf_sym_hashes (abfd
);
6097 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
6099 /* Check for the mips16 stub sections. */
6101 name
= bfd_get_section_name (abfd
, sec
);
6102 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
6104 unsigned long r_symndx
;
6106 /* Look at the relocation information to figure out which symbol
6109 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6111 if (r_symndx
< extsymoff
6112 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6116 /* This stub is for a local symbol. This stub will only be
6117 needed if there is some relocation in this BFD, other
6118 than a 16 bit function call, which refers to this symbol. */
6119 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6121 Elf_Internal_Rela
*sec_relocs
;
6122 const Elf_Internal_Rela
*r
, *rend
;
6124 /* We can ignore stub sections when looking for relocs. */
6125 if ((o
->flags
& SEC_RELOC
) == 0
6126 || o
->reloc_count
== 0
6127 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
6128 sizeof FN_STUB
- 1) == 0
6129 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
6130 sizeof CALL_STUB
- 1) == 0
6131 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
6132 sizeof CALL_FP_STUB
- 1) == 0)
6135 sec_relocs
= (_bfd_elf32_link_read_relocs
6136 (abfd
, o
, (PTR
) NULL
,
6137 (Elf_Internal_Rela
*) NULL
,
6138 info
->keep_memory
));
6139 if (sec_relocs
== NULL
)
6142 rend
= sec_relocs
+ o
->reloc_count
;
6143 for (r
= sec_relocs
; r
< rend
; r
++)
6144 if (ELF32_R_SYM (r
->r_info
) == r_symndx
6145 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
6148 if (! info
->keep_memory
)
6157 /* There is no non-call reloc for this stub, so we do
6158 not need it. Since this function is called before
6159 the linker maps input sections to output sections, we
6160 can easily discard it by setting the SEC_EXCLUDE
6162 sec
->flags
|= SEC_EXCLUDE
;
6166 /* Record this stub in an array of local symbol stubs for
6168 if (elf_tdata (abfd
)->local_stubs
== NULL
)
6170 unsigned long symcount
;
6173 if (elf_bad_symtab (abfd
))
6174 symcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
6176 symcount
= symtab_hdr
->sh_info
;
6177 n
= (asection
**) bfd_zalloc (abfd
,
6178 symcount
* sizeof (asection
*));
6181 elf_tdata (abfd
)->local_stubs
= n
;
6184 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
6186 /* We don't need to set mips16_stubs_seen in this case.
6187 That flag is used to see whether we need to look through
6188 the global symbol table for stubs. We don't need to set
6189 it here, because we just have a local stub. */
6193 struct mips_elf_link_hash_entry
*h
;
6195 h
= ((struct mips_elf_link_hash_entry
*)
6196 sym_hashes
[r_symndx
- extsymoff
]);
6198 /* H is the symbol this stub is for. */
6201 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6204 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
6205 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6207 unsigned long r_symndx
;
6208 struct mips_elf_link_hash_entry
*h
;
6211 /* Look at the relocation information to figure out which symbol
6214 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6216 if (r_symndx
< extsymoff
6217 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6219 /* This stub was actually built for a static symbol defined
6220 in the same file. We assume that all static symbols in
6221 mips16 code are themselves mips16, so we can simply
6222 discard this stub. Since this function is called before
6223 the linker maps input sections to output sections, we can
6224 easily discard it by setting the SEC_EXCLUDE flag. */
6225 sec
->flags
|= SEC_EXCLUDE
;
6229 h
= ((struct mips_elf_link_hash_entry
*)
6230 sym_hashes
[r_symndx
- extsymoff
]);
6232 /* H is the symbol this stub is for. */
6234 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6235 loc
= &h
->call_fp_stub
;
6237 loc
= &h
->call_stub
;
6239 /* If we already have an appropriate stub for this function, we
6240 don't need another one, so we can discard this one. Since
6241 this function is called before the linker maps input sections
6242 to output sections, we can easily discard it by setting the
6243 SEC_EXCLUDE flag. We can also discard this section if we
6244 happen to already know that this is a mips16 function; it is
6245 not necessary to check this here, as it is checked later, but
6246 it is slightly faster to check now. */
6247 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
6249 sec
->flags
|= SEC_EXCLUDE
;
6254 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6264 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6269 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6270 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6271 BFD_ASSERT (g
!= NULL
);
6277 rel_end
= relocs
+ sec
->reloc_count
;
6278 for (rel
= relocs
; rel
< rel_end
; rel
++)
6280 unsigned long r_symndx
;
6281 struct elf_link_hash_entry
*h
;
6283 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6285 if (r_symndx
< extsymoff
)
6289 h
= sym_hashes
[r_symndx
- extsymoff
];
6291 /* This may be an indirect symbol created because of a version. */
6294 while (h
->root
.type
== bfd_link_hash_indirect
)
6295 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6299 /* Some relocs require a global offset table. */
6300 if (dynobj
== NULL
|| sgot
== NULL
)
6302 switch (ELF32_R_TYPE (rel
->r_info
))
6306 case R_MIPS_CALL_HI16
:
6307 case R_MIPS_CALL_LO16
:
6308 case R_MIPS_GOT_HI16
:
6309 case R_MIPS_GOT_LO16
:
6311 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6312 if (! mips_elf_create_got_section (dynobj
, info
))
6314 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6315 BFD_ASSERT (sgot
!= NULL
);
6316 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6317 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6318 BFD_ASSERT (g
!= NULL
);
6324 && (info
->shared
|| h
!= NULL
)
6325 && (sec
->flags
& SEC_ALLOC
) != 0)
6326 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6334 switch (ELF32_R_TYPE (rel
->r_info
))
6337 case R_MIPS_CALL_HI16
:
6338 case R_MIPS_CALL_LO16
:
6339 /* This symbol requires a global offset table entry. */
6343 (*_bfd_error_handler
)
6344 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
6345 bfd_get_filename (abfd
), (unsigned long) rel
->r_offset
);
6346 bfd_set_error (bfd_error_bad_value
);
6350 /* Make sure this symbol is output as a dynamic symbol. */
6351 if (h
->dynindx
== -1)
6353 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6357 if (h
->got
.offset
!= (bfd_vma
) -1)
6359 /* We have already allocated space in the .got. */
6363 /* Note the index of the first global got symbol in .dynsym. */
6364 if (g
->global_gotsym
== 0
6365 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6366 g
->global_gotsym
= h
->dynindx
;
6368 /* Make this symbol to have the corresponding got entry. */
6371 /* We need a stub, not a plt entry for the undefined
6372 function. But we record it as if it needs plt. See
6373 elf_adjust_dynamic_symbol in elflink.h. */
6374 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6380 case R_MIPS_GOT_HI16
:
6381 case R_MIPS_GOT_LO16
:
6382 /* This symbol requires a global offset table entry. */
6386 /* Make sure this symbol is output as a dynamic symbol. */
6387 if (h
->dynindx
== -1)
6389 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6393 if (h
->got
.offset
!= (bfd_vma
) -1)
6395 /* We have already allocated space in the .got. */
6398 /* Note the index of the first global got symbol in
6400 if (g
->global_gotsym
== 0
6401 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6402 g
->global_gotsym
= h
->dynindx
;
6404 /* Make this symbol to be the global got symbol. */
6412 if ((info
->shared
|| h
!= NULL
)
6413 && (sec
->flags
& SEC_ALLOC
) != 0)
6417 const char *name
= ".rel.dyn";
6419 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6422 sreloc
= bfd_make_section (dynobj
, name
);
6424 || ! bfd_set_section_flags (dynobj
, sreloc
,
6429 | SEC_LINKER_CREATED
6431 || ! bfd_set_section_alignment (dynobj
, sreloc
,
6438 /* When creating a shared object, we must copy these
6439 reloc types into the output file as R_MIPS_REL32
6440 relocs. We make room for this reloc in the
6441 .rel.dyn reloc section */
6442 if (sreloc
->_raw_size
== 0)
6444 /* Add a null element. */
6445 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6446 ++sreloc
->reloc_count
;
6448 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6452 struct mips_elf_link_hash_entry
*hmips
;
6454 /* We only need to copy this reloc if the symbol is
6455 defined in a dynamic object. */
6456 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6457 ++hmips
->mips_32_relocs
;
6461 if (SGI_COMPAT (abfd
))
6462 mips_elf_hash_table (info
)->compact_rel_size
+=
6463 sizeof (Elf32_External_crinfo
);
6468 case R_MIPS_GPREL16
:
6469 case R_MIPS_LITERAL
:
6470 case R_MIPS_GPREL32
:
6471 if (SGI_COMPAT (abfd
))
6472 mips_elf_hash_table (info
)->compact_rel_size
+=
6473 sizeof (Elf32_External_crinfo
);
6476 /* This relocation describes the C++ object vtable hierarchy.
6477 Reconstruct it for later use during GC. */
6478 case R_MIPS_GNU_VTINHERIT
:
6479 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6483 /* This relocation describes which C++ vtable entries are actually
6484 used. Record for later use during GC. */
6485 case R_MIPS_GNU_VTENTRY
:
6486 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
6494 /* If this reloc is not a 16 bit call, and it has a global
6495 symbol, then we will need the fn_stub if there is one.
6496 References from a stub section do not count. */
6498 && ELF32_R_TYPE (rel
->r_info
) != R_MIPS16_26
6499 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
6500 sizeof FN_STUB
- 1) != 0
6501 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
6502 sizeof CALL_STUB
- 1) != 0
6503 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
6504 sizeof CALL_FP_STUB
- 1) != 0)
6506 struct mips_elf_link_hash_entry
*mh
;
6508 mh
= (struct mips_elf_link_hash_entry
*) h
;
6509 mh
->need_fn_stub
= true;
6516 /* Return the section that should be marked against GC for a given
6520 mips_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
6522 struct bfd_link_info
*info
;
6523 Elf_Internal_Rela
*rel
;
6524 struct elf_link_hash_entry
*h
;
6525 Elf_Internal_Sym
*sym
;
6527 /* ??? Do mips16 stub sections need to be handled special? */
6531 switch (ELF32_R_TYPE (rel
->r_info
))
6533 case R_MIPS_GNU_VTINHERIT
:
6534 case R_MIPS_GNU_VTENTRY
:
6538 switch (h
->root
.type
)
6540 case bfd_link_hash_defined
:
6541 case bfd_link_hash_defweak
:
6542 return h
->root
.u
.def
.section
;
6544 case bfd_link_hash_common
:
6545 return h
->root
.u
.c
.p
->section
;
6551 if (!(elf_bad_symtab (abfd
)
6552 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
6553 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
6554 && sym
->st_shndx
!= SHN_COMMON
))
6556 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
6563 /* Update the got entry reference counts for the section being removed. */
6566 mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
6568 struct bfd_link_info
*info
;
6570 const Elf_Internal_Rela
*relocs
;
6573 Elf_Internal_Shdr
*symtab_hdr
;
6574 struct elf_link_hash_entry
**sym_hashes
;
6575 bfd_signed_vma
*local_got_refcounts
;
6576 const Elf_Internal_Rela
*rel
, *relend
;
6577 unsigned long r_symndx
;
6578 struct elf_link_hash_entry
*h
;
6580 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6581 sym_hashes
= elf_sym_hashes (abfd
);
6582 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6584 relend
= relocs
+ sec
->reloc_count
;
6585 for (rel
= relocs
; rel
< relend
; rel
++)
6586 switch (ELF32_R_TYPE (rel
->r_info
))
6590 case R_MIPS_CALL_HI16
:
6591 case R_MIPS_CALL_LO16
:
6592 case R_MIPS_GOT_HI16
:
6593 case R_MIPS_GOT_LO16
:
6594 /* ??? It would seem that the existing MIPS code does no sort
6595 of reference counting or whatnot on its GOT and PLT entries,
6596 so it is not possible to garbage collect them at this time. */
6608 /* Adjust a symbol defined by a dynamic object and referenced by a
6609 regular object. The current definition is in some section of the
6610 dynamic object, but we're not including those sections. We have to
6611 change the definition to something the rest of the link can
6615 mips_elf_adjust_dynamic_symbol (info
, h
)
6616 struct bfd_link_info
*info
;
6617 struct elf_link_hash_entry
*h
;
6620 struct mips_elf_link_hash_entry
*hmips
;
6623 dynobj
= elf_hash_table (info
)->dynobj
;
6625 /* Make sure we know what is going on here. */
6626 BFD_ASSERT (dynobj
!= NULL
6627 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
6628 || h
->weakdef
!= NULL
6629 || ((h
->elf_link_hash_flags
6630 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
6631 && (h
->elf_link_hash_flags
6632 & ELF_LINK_HASH_REF_REGULAR
) != 0
6633 && (h
->elf_link_hash_flags
6634 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
6636 /* If this symbol is defined in a dynamic object, we need to copy
6637 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
6639 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6640 if (! info
->relocateable
6641 && hmips
->mips_32_relocs
!= 0
6642 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6644 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6645 BFD_ASSERT (s
!= NULL
);
6647 if (s
->_raw_size
== 0)
6649 /* Make room for a null element. */
6650 s
->_raw_size
+= sizeof (Elf32_External_Rel
);
6653 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
6656 /* For a function, create a stub, if needed. */
6657 if (h
->type
== STT_FUNC
6658 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
6660 if (! elf_hash_table (info
)->dynamic_sections_created
)
6663 /* If this symbol is not defined in a regular file, then set
6664 the symbol to the stub location. This is required to make
6665 function pointers compare as equal between the normal
6666 executable and the shared library. */
6667 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6669 /* We need .stub section. */
6670 s
= bfd_get_section_by_name (dynobj
, ".stub");
6671 BFD_ASSERT (s
!= NULL
);
6673 h
->root
.u
.def
.section
= s
;
6674 h
->root
.u
.def
.value
= s
->_raw_size
;
6676 /* XXX Write this stub address somewhere. */
6677 h
->plt
.offset
= s
->_raw_size
;
6679 /* Make room for this stub code. */
6680 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6682 /* The last half word of the stub will be filled with the index
6683 of this symbol in .dynsym section. */
6688 /* If this is a weak symbol, and there is a real definition, the
6689 processor independent code will have arranged for us to see the
6690 real definition first, and we can just use the same value. */
6691 if (h
->weakdef
!= NULL
)
6693 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
6694 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
6695 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
6696 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
6700 /* This is a reference to a symbol defined by a dynamic object which
6701 is not a function. */
6706 /* This function is called after all the input files have been read,
6707 and the input sections have been assigned to output sections. We
6708 check for any mips16 stub sections that we can discard. */
6710 static boolean mips_elf_check_mips16_stubs
6711 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
6714 mips_elf_always_size_sections (output_bfd
, info
)
6716 struct bfd_link_info
*info
;
6718 if (info
->relocateable
6719 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
6722 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
6723 mips_elf_check_mips16_stubs
,
6729 /* Check the mips16 stubs for a particular symbol, and see if we can
6734 mips_elf_check_mips16_stubs (h
, data
)
6735 struct mips_elf_link_hash_entry
*h
;
6738 if (h
->fn_stub
!= NULL
6739 && ! h
->need_fn_stub
)
6741 /* We don't need the fn_stub; the only references to this symbol
6742 are 16 bit calls. Clobber the size to 0 to prevent it from
6743 being included in the link. */
6744 h
->fn_stub
->_raw_size
= 0;
6745 h
->fn_stub
->_cooked_size
= 0;
6746 h
->fn_stub
->flags
&= ~ SEC_RELOC
;
6747 h
->fn_stub
->reloc_count
= 0;
6748 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
6751 if (h
->call_stub
!= NULL
6752 && h
->root
.other
== STO_MIPS16
)
6754 /* We don't need the call_stub; this is a 16 bit function, so
6755 calls from other 16 bit functions are OK. Clobber the size
6756 to 0 to prevent it from being included in the link. */
6757 h
->call_stub
->_raw_size
= 0;
6758 h
->call_stub
->_cooked_size
= 0;
6759 h
->call_stub
->flags
&= ~ SEC_RELOC
;
6760 h
->call_stub
->reloc_count
= 0;
6761 h
->call_stub
->flags
|= SEC_EXCLUDE
;
6764 if (h
->call_fp_stub
!= NULL
6765 && h
->root
.other
== STO_MIPS16
)
6767 /* We don't need the call_stub; this is a 16 bit function, so
6768 calls from other 16 bit functions are OK. Clobber the size
6769 to 0 to prevent it from being included in the link. */
6770 h
->call_fp_stub
->_raw_size
= 0;
6771 h
->call_fp_stub
->_cooked_size
= 0;
6772 h
->call_fp_stub
->flags
&= ~ SEC_RELOC
;
6773 h
->call_fp_stub
->reloc_count
= 0;
6774 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
6780 /* Set the sizes of the dynamic sections. */
6783 mips_elf_size_dynamic_sections (output_bfd
, info
)
6785 struct bfd_link_info
*info
;
6791 struct mips_got_info
*g
;
6793 dynobj
= elf_hash_table (info
)->dynobj
;
6794 BFD_ASSERT (dynobj
!= NULL
);
6796 if (elf_hash_table (info
)->dynamic_sections_created
)
6798 /* Set the contents of the .interp section to the interpreter. */
6801 s
= bfd_get_section_by_name (dynobj
, ".interp");
6802 BFD_ASSERT (s
!= NULL
);
6803 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
6804 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
6808 /* Recompute the size of .got for local entires (reserved and
6809 hipages) if needed. To estimate it, get the upper bound of total
6810 size of loadable sections. */
6811 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6815 bfd_size_type loadable_size
= 0;
6816 bfd_size_type local_gotno
;
6819 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6820 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6821 BFD_ASSERT (g
!= NULL
);
6823 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
6824 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
6826 if ((s
->flags
& SEC_ALLOC
) == 0)
6828 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
6831 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
6833 /* Assume there are two loadable segments consisting of
6834 contiguous sections. Is 5 enough? */
6835 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
6836 g
->local_gotno
= local_gotno
;
6837 sgot
->_raw_size
+= local_gotno
* 4;
6840 /* The check_relocs and adjust_dynamic_symbol entry points have
6841 determined the sizes of the various dynamic sections. Allocate
6844 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
6849 /* It's OK to base decisions on the section name, because none
6850 of the dynobj section names depend upon the input files. */
6851 name
= bfd_get_section_name (dynobj
, s
);
6853 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
6858 if (strncmp (name
, ".rel", 4) == 0)
6860 if (s
->_raw_size
== 0)
6862 /* We only strip the section if the output section name
6863 has the same name. Otherwise, there might be several
6864 input sections for this output section. FIXME: This
6865 code is probably not needed these days anyhow, since
6866 the linker now does not create empty output sections. */
6867 if (s
->output_section
!= NULL
6869 bfd_get_section_name (s
->output_section
->owner
,
6870 s
->output_section
)) == 0)
6875 const char *outname
;
6878 /* If this relocation section applies to a read only
6879 section, then we probably need a DT_TEXTREL entry.
6880 If the relocation section is .rel.dyn, we always
6881 assert a DT_TEXTREL entry rather than testing whether
6882 there exists a relocation to a read only section or
6884 outname
= bfd_get_section_name (output_bfd
,
6886 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
6888 && (target
->flags
& SEC_READONLY
) != 0
6889 && (target
->flags
& SEC_ALLOC
) != 0)
6890 || strcmp (outname
, ".rel.dyn") == 0)
6893 /* We use the reloc_count field as a counter if we need
6894 to copy relocs into the output file. */
6895 if (strcmp (name
, ".rel.dyn") != 0)
6899 else if (strncmp (name
, ".got", 4) == 0)
6903 BFD_ASSERT (elf_section_data (s
) != NULL
);
6904 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
6905 BFD_ASSERT (g
!= NULL
);
6907 /* Fix the size of .got section for the correspondence of
6908 global symbols and got entries. This adds some useless
6909 got entries. Is this required by ABI really? */
6910 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
6911 s
->_raw_size
+= i
* 4;
6913 else if (strncmp (name
, ".stub", 5) == 0)
6915 /* Irix rld assumes that the function stub isn't at the end
6916 of .text section. So put a dummy. XXX */
6917 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6919 else if (! info
->shared
6920 && ! mips_elf_hash_table (info
)->use_rld_obj_head
6921 && strncmp (name
, ".rld_map", 8) == 0)
6923 /* We add a room for __rld_map. It will be filled in by the
6924 rtld to contain a pointer to the _r_debug structure. */
6927 else if (SGI_COMPAT (output_bfd
)
6928 && strncmp (name
, ".compact_rel", 12) == 0)
6929 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
6930 else if (strncmp (name
, ".init", 5) != 0)
6932 /* It's not one of our sections, so don't allocate space. */
6940 for (spp
= &s
->output_section
->owner
->sections
;
6941 *spp
!= s
->output_section
;
6942 spp
= &(*spp
)->next
)
6944 *spp
= s
->output_section
->next
;
6945 --s
->output_section
->owner
->section_count
;
6950 /* Allocate memory for the section contents. */
6951 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
6952 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
6954 bfd_set_error (bfd_error_no_memory
);
6957 memset (s
->contents
, 0, s
->_raw_size
);
6960 if (elf_hash_table (info
)->dynamic_sections_created
)
6962 /* Add some entries to the .dynamic section. We fill in the
6963 values later, in elf_mips_finish_dynamic_sections, but we
6964 must add the entries now so that we get the correct size for
6965 the .dynamic section. The DT_DEBUG entry is filled in by the
6966 dynamic linker and used by the debugger. */
6969 if (SGI_COMPAT (output_bfd
))
6971 /* SGI object has the equivalence of DT_DEBUG in the
6972 DT_MIPS_RLD_MAP entry. */
6973 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
6977 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
6983 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
6987 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
6990 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
6992 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
6995 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
6998 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
7002 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
7005 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
7008 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
7010 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
7013 s
= bfd_get_section_by_name (dynobj
, ".liblist");
7014 BFD_ASSERT (s
!= NULL
);
7016 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
7020 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
7023 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
7027 /* Time stamps in executable files are a bad idea. */
7028 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
7033 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
7038 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
7042 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
7045 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
7048 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
7051 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
7054 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
7057 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
7060 #if 0 /* (SGI_COMPAT) */
7061 if (! bfd_get_section_by_name (dynobj
, ".init"))
7062 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
7065 if (! bfd_get_section_by_name (dynobj
, ".fini"))
7066 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
7071 /* If we use dynamic linking, we generate a section symbol for each
7072 output section. These are local symbols, which means that they
7073 must come first in the dynamic symbol table.
7074 That means we must increment the dynamic symbol index of every
7075 other dynamic symbol. */
7077 const char * const *namep
;
7079 bfd_size_type strindex
;
7080 struct bfd_strtab_hash
*dynstr
;
7081 struct mips_got_info
*g
;
7084 if (elf_hash_table (info
)->dynamic_sections_created
)
7086 if (SGI_COMPAT (output_bfd
))
7088 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
7089 elf_link_hash_traverse (elf_hash_table (info
),
7090 mips_elf_adjust_dynindx
,
7092 elf_hash_table (info
)->dynsymcount
+= c
;
7094 dynstr
= elf_hash_table (info
)->dynstr
;
7095 BFD_ASSERT (dynstr
!= NULL
);
7097 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
7101 s
= bfd_get_section_by_name (output_bfd
, *namep
);
7103 elf_section_data (s
)->dynindx
= i
;
7105 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
7106 if (strindex
== (bfd_size_type
) -1)
7109 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
7114 c
= bfd_count_sections (output_bfd
);
7115 elf_link_hash_traverse (elf_hash_table (info
),
7116 mips_elf_adjust_dynindx
,
7118 elf_hash_table (info
)->dynsymcount
+= c
;
7120 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
7122 elf_section_data (s
)->dynindx
= i
;
7123 /* These symbols will have no names, so we don't need to
7124 fiddle with dynstr_index. */
7131 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7132 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7133 BFD_ASSERT (g
!= NULL
);
7135 /* If there are no global got symbols, fake the last symbol so
7137 if (g
->global_gotsym
)
7138 g
->global_gotsym
+= c
;
7140 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
7147 /* Increment the index of a dynamic symbol by a given amount. Called
7148 via elf_link_hash_traverse. */
7151 mips_elf_adjust_dynindx (h
, cparg
)
7152 struct elf_link_hash_entry
*h
;
7155 unsigned int *cp
= (unsigned int *) cparg
;
7157 if (h
->dynindx
!= -1)
7162 /* Finish up dynamic symbol handling. We set the contents of various
7163 dynamic sections here. */
7166 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
7168 struct bfd_link_info
*info
;
7169 struct elf_link_hash_entry
*h
;
7170 Elf_Internal_Sym
*sym
;
7175 struct mips_got_info
*g
;
7178 dynobj
= elf_hash_table (info
)->dynobj
;
7179 gval
= sym
->st_value
;
7181 if (h
->plt
.offset
!= (bfd_vma
) -1)
7185 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
7187 /* This symbol has a stub. Set it up. */
7189 BFD_ASSERT (h
->dynindx
!= -1);
7191 s
= bfd_get_section_by_name (dynobj
, ".stub");
7192 BFD_ASSERT (s
!= NULL
);
7194 /* Fill the stub. */
7196 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
7198 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
7201 /* FIXME: Can h->dynindex be more than 64K? */
7202 if (h
->dynindx
& 0xffff0000)
7205 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
7207 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
7209 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
7210 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
7212 /* Mark the symbol as undefined. plt.offset != -1 occurs
7213 only for the referenced symbol. */
7214 sym
->st_shndx
= SHN_UNDEF
;
7216 /* The run-time linker uses the st_value field of the symbol
7217 to reset the global offset table entry for this external
7218 to its stub address when unlinking a shared object. */
7219 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
7220 sym
->st_value
= gval
;
7223 BFD_ASSERT (h
->dynindx
!= -1);
7225 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7226 BFD_ASSERT (sgot
!= NULL
);
7227 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7228 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7229 BFD_ASSERT (g
!= NULL
);
7231 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
7233 bfd_size_type offset
;
7235 /* This symbol has an entry in the global offset table. Set its
7236 value to the corresponding got entry, if needed. */
7237 if (h
->got
.offset
== (bfd_vma
) -1)
7239 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
7240 BFD_ASSERT (g
->local_gotno
* 4 <= offset
7241 && offset
< sgot
->_raw_size
);
7242 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
7246 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7247 name
= h
->root
.root
.string
;
7248 if (strcmp (name
, "_DYNAMIC") == 0
7249 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
7250 sym
->st_shndx
= SHN_ABS
;
7251 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
7253 sym
->st_shndx
= SHN_ABS
;
7254 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7257 else if (SGI_COMPAT (output_bfd
))
7259 if (strcmp (name
, "_gp_disp") == 0)
7261 sym
->st_shndx
= SHN_ABS
;
7262 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7263 sym
->st_value
= elf_gp (output_bfd
);
7265 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
7266 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
7268 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7269 sym
->st_other
= STO_PROTECTED
;
7271 sym
->st_shndx
= SHN_MIPS_DATA
;
7273 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
7275 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7276 sym
->st_other
= STO_PROTECTED
;
7277 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
7278 sym
->st_shndx
= SHN_ABS
;
7280 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
7282 if (h
->type
== STT_FUNC
)
7283 sym
->st_shndx
= SHN_MIPS_TEXT
;
7284 else if (h
->type
== STT_OBJECT
)
7285 sym
->st_shndx
= SHN_MIPS_DATA
;
7289 if (SGI_COMPAT (output_bfd
)
7292 if (! mips_elf_hash_table (info
)->use_rld_obj_head
7293 && strcmp (name
, "__rld_map") == 0)
7295 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7296 BFD_ASSERT (s
!= NULL
);
7297 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
7298 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
7299 if (mips_elf_hash_table (info
)->rld_value
== 0)
7300 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7302 else if (mips_elf_hash_table (info
)->use_rld_obj_head
7303 && strcmp (name
, "__rld_obj_head") == 0)
7305 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7306 BFD_ASSERT (s
!= NULL
);
7307 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7311 /* If this is a mips16 symbol, force the value to be even. */
7312 if (sym
->st_other
== STO_MIPS16
7313 && (sym
->st_value
& 1) != 0)
7319 /* Finish up the dynamic sections. */
7322 mips_elf_finish_dynamic_sections (output_bfd
, info
)
7324 struct bfd_link_info
*info
;
7329 struct mips_got_info
*g
;
7331 dynobj
= elf_hash_table (info
)->dynobj
;
7333 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
7335 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7340 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7341 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7342 BFD_ASSERT (g
!= NULL
);
7345 if (elf_hash_table (info
)->dynamic_sections_created
)
7347 Elf32_External_Dyn
*dyncon
, *dynconend
;
7349 BFD_ASSERT (sdyn
!= NULL
);
7350 BFD_ASSERT (g
!= NULL
);
7352 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7353 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
7354 for (; dyncon
< dynconend
; dyncon
++)
7356 Elf_Internal_Dyn dyn
;
7361 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
7369 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7370 BFD_ASSERT (s
!= NULL
);
7371 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
7372 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7376 /* Rewrite DT_STRSZ. */
7378 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
7379 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7385 case DT_MIPS_CONFLICT
:
7388 case DT_MIPS_LIBLIST
:
7391 s
= bfd_get_section_by_name (output_bfd
, name
);
7392 BFD_ASSERT (s
!= NULL
);
7393 dyn
.d_un
.d_ptr
= s
->vma
;
7394 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7397 case DT_MIPS_RLD_VERSION
:
7398 dyn
.d_un
.d_val
= 1; /* XXX */
7399 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7403 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
7404 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7407 case DT_MIPS_CONFLICTNO
:
7409 elemsize
= sizeof (Elf32_Conflict
);
7412 case DT_MIPS_LIBLISTNO
:
7414 elemsize
= sizeof (Elf32_Lib
);
7416 s
= bfd_get_section_by_name (output_bfd
, name
);
7419 if (s
->_cooked_size
!= 0)
7420 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7422 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7427 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7430 case DT_MIPS_TIME_STAMP
:
7431 time ((time_t *) &dyn
.d_un
.d_val
);
7432 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7435 case DT_MIPS_ICHECKSUM
:
7439 case DT_MIPS_IVERSION
:
7443 case DT_MIPS_BASE_ADDRESS
:
7444 s
= output_bfd
->sections
;
7445 BFD_ASSERT (s
!= NULL
);
7446 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
7447 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7450 case DT_MIPS_LOCAL_GOTNO
:
7451 dyn
.d_un
.d_val
= g
->local_gotno
;
7452 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7455 case DT_MIPS_SYMTABNO
:
7457 elemsize
= sizeof (Elf32_External_Sym
);
7458 s
= bfd_get_section_by_name (output_bfd
, name
);
7459 BFD_ASSERT (s
!= NULL
);
7461 if (s
->_cooked_size
!= 0)
7462 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7464 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7465 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7468 case DT_MIPS_UNREFEXTNO
:
7470 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
7471 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7474 case DT_MIPS_GOTSYM
:
7475 dyn
.d_un
.d_val
= g
->global_gotsym
;
7476 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7479 case DT_MIPS_HIPAGENO
:
7480 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
7481 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7484 case DT_MIPS_RLD_MAP
:
7485 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
7486 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7493 /* The first entry of the global offset table will be filled at
7494 runtime. The second entry will be used by some runtime loaders.
7495 This isn't the case of Irix rld. */
7496 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
7498 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
7499 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
7503 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
7510 Elf_Internal_Sym sym
;
7513 const char * const * namep
= mips_elf_dynsym_sec_names
;
7514 Elf32_compact_rel cpt
;
7516 /* Set up the section symbols for the output sections. SGI sets
7517 the STT_NOTYPE attribute for these symbols. Should we do so? */
7519 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
7520 if (sdynsym
!= NULL
)
7522 if (SGI_COMPAT (output_bfd
))
7526 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7532 while ((name
= *namep
++) != NULL
)
7534 s
= bfd_get_section_by_name (output_bfd
, name
);
7537 sym
.st_value
= s
->vma
;
7538 dindx
= elf_section_data (s
)->dynindx
;
7539 last
= s
->vma
+ s
->_raw_size
;
7543 sym
.st_value
= last
;
7547 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
7552 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
7554 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7555 (((Elf32_External_Sym
*)
7560 /* Set the sh_info field of the output .dynsym section to
7561 the index of the first global symbol. */
7562 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7563 SIZEOF_MIPS_DYNSYM_SECNAMES
;
7569 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
7572 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
7576 sym
.st_value
= s
->vma
;
7578 indx
= elf_section_data (s
)->this_idx
;
7579 BFD_ASSERT (indx
> 0);
7580 sym
.st_shndx
= indx
;
7582 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7583 (((Elf32_External_Sym
*)
7585 + elf_section_data (s
)->dynindx
));
7588 /* Set the sh_info field of the output .dynsym section to
7589 the index of the first global symbol. */
7590 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7591 bfd_count_sections (output_bfd
) + 1;
7595 if (SGI_COMPAT (output_bfd
))
7597 /* Write .compact_rel section out. */
7598 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
7602 cpt
.num
= s
->reloc_count
;
7604 cpt
.offset
= (s
->output_section
->filepos
7605 + sizeof (Elf32_External_compact_rel
));
7608 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
7609 ((Elf32_External_compact_rel
*)
7612 /* Clean up a dummy stub function entry in .text. */
7613 s
= bfd_get_section_by_name (dynobj
, ".stub");
7616 file_ptr dummy_offset
;
7618 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
7619 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
7620 memset (s
->contents
+ dummy_offset
, 0,
7621 MIPS_FUNCTION_STUB_SIZE
);
7626 /* Clean up a first relocation in .rel.dyn. */
7627 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7628 if (s
!= NULL
&& s
->_raw_size
> 0)
7629 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
7635 /* This is almost identical to bfd_generic_get_... except that some
7636 MIPS relocations need to be handled specially. Sigh. */
7639 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
7640 relocateable
, symbols
)
7642 struct bfd_link_info
*link_info
;
7643 struct bfd_link_order
*link_order
;
7645 boolean relocateable
;
7648 /* Get enough memory to hold the stuff */
7649 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
7650 asection
*input_section
= link_order
->u
.indirect
.section
;
7652 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
7653 arelent
**reloc_vector
= NULL
;
7659 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
7660 if (reloc_vector
== NULL
&& reloc_size
!= 0)
7663 /* read in the section */
7664 if (!bfd_get_section_contents (input_bfd
,
7668 input_section
->_raw_size
))
7671 /* We're not relaxing the section, so just copy the size info */
7672 input_section
->_cooked_size
= input_section
->_raw_size
;
7673 input_section
->reloc_done
= true;
7675 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
7679 if (reloc_count
< 0)
7682 if (reloc_count
> 0)
7687 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
7690 struct bfd_hash_entry
*h
;
7691 struct bfd_link_hash_entry
*lh
;
7692 /* Skip all this stuff if we aren't mixing formats. */
7693 if (abfd
&& input_bfd
7694 && abfd
->xvec
== input_bfd
->xvec
)
7698 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
7699 lh
= (struct bfd_link_hash_entry
*) h
;
7706 case bfd_link_hash_undefined
:
7707 case bfd_link_hash_undefweak
:
7708 case bfd_link_hash_common
:
7711 case bfd_link_hash_defined
:
7712 case bfd_link_hash_defweak
:
7714 gp
= lh
->u
.def
.value
;
7716 case bfd_link_hash_indirect
:
7717 case bfd_link_hash_warning
:
7719 /* @@FIXME ignoring warning for now */
7721 case bfd_link_hash_new
:
7730 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
7733 char *error_message
= (char *) NULL
;
7734 bfd_reloc_status_type r
;
7736 /* Specific to MIPS: Deal with relocation types that require
7737 knowing the gp of the output bfd. */
7738 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
7739 if (bfd_is_abs_section (sym
->section
) && abfd
)
7741 /* The special_function wouldn't get called anyways. */
7745 /* The gp isn't there; let the special function code
7746 fall over on its own. */
7748 else if ((*parent
)->howto
->special_function
7749 == _bfd_mips_elf_gprel16_reloc
)
7751 /* bypass special_function call */
7752 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
7753 relocateable
, (PTR
) data
, gp
);
7754 goto skip_bfd_perform_relocation
;
7756 /* end mips specific stuff */
7758 r
= bfd_perform_relocation (input_bfd
,
7762 relocateable
? abfd
: (bfd
*) NULL
,
7764 skip_bfd_perform_relocation
:
7768 asection
*os
= input_section
->output_section
;
7770 /* A partial link, so keep the relocs */
7771 os
->orelocation
[os
->reloc_count
] = *parent
;
7775 if (r
!= bfd_reloc_ok
)
7779 case bfd_reloc_undefined
:
7780 if (!((*link_info
->callbacks
->undefined_symbol
)
7781 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7782 input_bfd
, input_section
, (*parent
)->address
)))
7785 case bfd_reloc_dangerous
:
7786 BFD_ASSERT (error_message
!= (char *) NULL
);
7787 if (!((*link_info
->callbacks
->reloc_dangerous
)
7788 (link_info
, error_message
, input_bfd
, input_section
,
7789 (*parent
)->address
)))
7792 case bfd_reloc_overflow
:
7793 if (!((*link_info
->callbacks
->reloc_overflow
)
7794 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7795 (*parent
)->howto
->name
, (*parent
)->addend
,
7796 input_bfd
, input_section
, (*parent
)->address
)))
7799 case bfd_reloc_outofrange
:
7808 if (reloc_vector
!= NULL
)
7809 free (reloc_vector
);
7813 if (reloc_vector
!= NULL
)
7814 free (reloc_vector
);
7817 #define bfd_elf32_bfd_get_relocated_section_contents \
7818 elf32_mips_get_relocated_section_contents
7820 /* ECOFF swapping routines. These are used when dealing with the
7821 .mdebug section, which is in the ECOFF debugging format. */
7822 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
7824 /* Symbol table magic number. */
7826 /* Alignment of debugging information. E.g., 4. */
7828 /* Sizes of external symbolic information. */
7829 sizeof (struct hdr_ext
),
7830 sizeof (struct dnr_ext
),
7831 sizeof (struct pdr_ext
),
7832 sizeof (struct sym_ext
),
7833 sizeof (struct opt_ext
),
7834 sizeof (struct fdr_ext
),
7835 sizeof (struct rfd_ext
),
7836 sizeof (struct ext_ext
),
7837 /* Functions to swap in external symbolic data. */
7846 _bfd_ecoff_swap_tir_in
,
7847 _bfd_ecoff_swap_rndx_in
,
7848 /* Functions to swap out external symbolic data. */
7857 _bfd_ecoff_swap_tir_out
,
7858 _bfd_ecoff_swap_rndx_out
,
7859 /* Function to read in symbolic data. */
7860 _bfd_mips_elf_read_ecoff_info
7863 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
7864 #define TARGET_LITTLE_NAME "elf32-littlemips"
7865 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
7866 #define TARGET_BIG_NAME "elf32-bigmips"
7867 #define ELF_ARCH bfd_arch_mips
7868 #define ELF_MACHINE_CODE EM_MIPS
7870 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
7871 a value of 0x1000, and we are compatible. */
7872 #define ELF_MAXPAGESIZE 0x1000
7874 #define elf_backend_collect true
7875 #define elf_backend_type_change_ok true
7876 #define elf_backend_can_gc_sections true
7877 #define elf_info_to_howto 0
7878 #define elf_info_to_howto_rel mips_info_to_howto_rel
7879 #define elf_backend_sym_is_global mips_elf_sym_is_global
7880 #define elf_backend_object_p mips_elf32_object_p
7881 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
7882 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
7883 #define elf_backend_section_from_bfd_section \
7884 _bfd_mips_elf_section_from_bfd_section
7885 #define elf_backend_section_processing mips_elf32_section_processing
7886 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
7887 #define elf_backend_additional_program_headers \
7888 mips_elf_additional_program_headers
7889 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
7890 #define elf_backend_final_write_processing \
7891 _bfd_mips_elf_final_write_processing
7892 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
7894 #define bfd_elf32_bfd_is_local_label_name \
7895 mips_elf_is_local_label_name
7896 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
7897 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
7898 #define bfd_elf32_bfd_link_hash_table_create \
7899 mips_elf_link_hash_table_create
7900 #define bfd_elf32_bfd_final_link mips_elf_final_link
7901 #define bfd_elf32_bfd_copy_private_bfd_data \
7902 _bfd_mips_elf_copy_private_bfd_data
7903 #define bfd_elf32_bfd_merge_private_bfd_data \
7904 _bfd_mips_elf_merge_private_bfd_data
7905 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
7906 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
7907 #define elf_backend_create_dynamic_sections \
7908 mips_elf_create_dynamic_sections
7909 #define elf_backend_check_relocs mips_elf_check_relocs
7910 #define elf_backend_adjust_dynamic_symbol \
7911 mips_elf_adjust_dynamic_symbol
7912 #define elf_backend_always_size_sections \
7913 mips_elf_always_size_sections
7914 #define elf_backend_size_dynamic_sections \
7915 mips_elf_size_dynamic_sections
7916 #define elf_backend_relocate_section mips_elf_relocate_section
7917 #define elf_backend_link_output_symbol_hook \
7918 mips_elf_link_output_symbol_hook
7919 #define elf_backend_finish_dynamic_symbol \
7920 mips_elf_finish_dynamic_symbol
7921 #define elf_backend_finish_dynamic_sections \
7922 mips_elf_finish_dynamic_sections
7923 #define elf_backend_gc_mark_hook mips_elf_gc_mark_hook
7924 #define elf_backend_gc_sweep_hook mips_elf_gc_sweep_hook
7926 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
7927 #define elf_backend_plt_header_size 0
7929 #include "elf32-target.h"