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 static boolean mips_elf_adjust_dynindx
89 PARAMS ((struct elf_link_hash_entry
*, PTR
));
90 static boolean mips_elf_relocate_section
91 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
92 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
93 static boolean mips_elf_link_output_symbol_hook
94 PARAMS ((bfd
*, struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
96 static boolean mips_elf_create_dynamic_sections
97 PARAMS ((bfd
*, struct bfd_link_info
*));
98 static boolean mips_elf_create_compact_rel_section
99 PARAMS ((bfd
*, struct bfd_link_info
*));
100 static boolean mips_elf_create_got_section
101 PARAMS ((bfd
*, struct bfd_link_info
*));
102 static boolean mips_elf_check_relocs
103 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
104 const Elf_Internal_Rela
*));
105 static boolean mips_elf_adjust_dynamic_symbol
106 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
107 static boolean mips_elf_always_size_sections
108 PARAMS ((bfd
*, struct bfd_link_info
*));
109 static boolean mips_elf_size_dynamic_sections
110 PARAMS ((bfd
*, struct bfd_link_info
*));
111 static boolean mips_elf_finish_dynamic_symbol
112 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
113 Elf_Internal_Sym
*));
114 static boolean mips_elf_finish_dynamic_sections
115 PARAMS ((bfd
*, struct bfd_link_info
*));
116 static boolean mips_elf_add_symbol_hook
117 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
118 const char **, flagword
*, asection
**, bfd_vma
*));
119 static bfd_reloc_status_type mips_elf_final_gp
120 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
121 static bfd_byte
*elf32_mips_get_relocated_section_contents
122 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
123 bfd_byte
*, boolean
, asymbol
**));
125 /* This is true for Irix 5 executables, false for normal MIPS ELF ABI
126 executables. FIXME: At the moment, we default to always generating
127 Irix 5 executables. */
129 #define SGI_COMPAT(abfd) (1)
131 /* This structure is used to hold .got information when linking. It
132 is stored in the tdata field of the bfd_elf_section_data structure. */
136 /* The symbol index of the first global .got symbol. */
137 unsigned long global_gotsym
;
138 /* The number of local .got entries. */
139 unsigned int local_gotno
;
140 /* The number of local .got entries we have used. */
141 unsigned int assigned_gotno
;
144 /* The number of local .got entries we reserve. */
145 #define MIPS_RESERVED_GOTNO (2)
147 /* Instructions which appear in a stub. For some reason the stub is
148 slightly different on an SGI system. */
149 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
150 #define STUB_LW(abfd) \
152 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
153 : 0x8f998000) /* lw t9,0x8000(gp) */
154 #define STUB_MOVE 0x03e07825 /* move t7,ra */
155 #define STUB_JALR 0x0320f809 /* jal t9 */
156 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
157 #define MIPS_FUNCTION_STUB_SIZE (16)
159 /* Names of sections which appear in the .dynsym section in an Irix 5
162 static const char * const mips_elf_dynsym_sec_names
[] =
175 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
176 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
178 /* The number of entries in mips_elf_dynsym_sec_names which go in the
181 #define MIPS_TEXT_DYNSYM_SECNO (3)
183 /* The names of the runtime procedure table symbols used on Irix 5. */
185 static const char * const mips_elf_dynsym_rtproc_names
[] =
188 "_procedure_string_table",
189 "_procedure_table_size",
193 /* These structures are used to generate the .compact_rel section on
198 unsigned long id1
; /* Always one? */
199 unsigned long num
; /* Number of compact relocation entries. */
200 unsigned long id2
; /* Always two? */
201 unsigned long offset
; /* The file offset of the first relocation. */
202 unsigned long reserved0
; /* Zero? */
203 unsigned long reserved1
; /* Zero? */
212 bfd_byte reserved0
[4];
213 bfd_byte reserved1
[4];
214 } Elf32_External_compact_rel
;
218 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
219 unsigned int rtype
: 4; /* Relocation types. See below. */
220 unsigned int dist2to
: 8;
221 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
222 unsigned long konst
; /* KONST field. See below. */
223 unsigned long vaddr
; /* VADDR to be relocated. */
228 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
229 unsigned int rtype
: 4; /* Relocation types. See below. */
230 unsigned int dist2to
: 8;
231 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
232 unsigned long konst
; /* KONST field. See below. */
240 } Elf32_External_crinfo
;
246 } Elf32_External_crinfo2
;
248 /* These are the constants used to swap the bitfields in a crinfo. */
250 #define CRINFO_CTYPE (0x1)
251 #define CRINFO_CTYPE_SH (31)
252 #define CRINFO_RTYPE (0xf)
253 #define CRINFO_RTYPE_SH (27)
254 #define CRINFO_DIST2TO (0xff)
255 #define CRINFO_DIST2TO_SH (19)
256 #define CRINFO_RELVADDR (0x7ffff)
257 #define CRINFO_RELVADDR_SH (0)
259 /* A compact relocation info has long (3 words) or short (2 words)
260 formats. A short format doesn't have VADDR field and relvaddr
261 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
262 #define CRF_MIPS_LONG 1
263 #define CRF_MIPS_SHORT 0
265 /* There are 4 types of compact relocation at least. The value KONST
266 has different meaning for each type:
269 CT_MIPS_REL32 Address in data
270 CT_MIPS_WORD Address in word (XXX)
271 CT_MIPS_GPHI_LO GP - vaddr
272 CT_MIPS_JMPAD Address to jump
275 #define CRT_MIPS_REL32 0xa
276 #define CRT_MIPS_WORD 0xb
277 #define CRT_MIPS_GPHI_LO 0xc
278 #define CRT_MIPS_JMPAD 0xd
280 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
281 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
282 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
283 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
285 static void bfd_elf32_swap_compact_rel_out
286 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
287 static void bfd_elf32_swap_crinfo_out
288 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
290 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
295 R_MIPS_16
, R_MIPS_32
,
296 R_MIPS_REL32
, R_MIPS_26
,
297 R_MIPS_HI16
, R_MIPS_LO16
,
298 R_MIPS_GPREL16
, R_MIPS_LITERAL
,
299 R_MIPS_GOT16
, R_MIPS_PC16
,
300 R_MIPS_CALL16
, R_MIPS_GPREL32
,
301 /* The remaining relocs are defined on Irix, although they are not
302 in the MIPS ELF ABI. */
303 R_MIPS_UNUSED1
, R_MIPS_UNUSED2
,
305 R_MIPS_SHIFT5
, R_MIPS_SHIFT6
,
306 R_MIPS_64
, R_MIPS_GOT_DISP
,
307 R_MIPS_GOT_PAGE
, R_MIPS_GOT_OFST
,
308 R_MIPS_GOT_HI16
, R_MIPS_GOT_LO16
,
309 R_MIPS_SUB
, R_MIPS_INSERT_A
,
310 R_MIPS_INSERT_B
, R_MIPS_DELETE
,
311 R_MIPS_HIGHER
, R_MIPS_HIGHEST
,
312 R_MIPS_CALL_HI16
, R_MIPS_CALL_LO16
,
313 /* start-sanitize-r5900 */
314 /* This is used by a mips co-processor instruction. */
316 /* end-sanitize-r5900 */
318 /* These relocs are used for the mips16. */
321 /* start-sanitize-sky */
322 /* These relocs are for the dvp. */
323 , R_MIPS_DVP_11_PCREL
= 120,
324 R_MIPS_DVP_27_S4
= 121
325 /* end-sanitize-sky */
328 static reloc_howto_type elf_mips_howto_table
[] =
331 HOWTO (R_MIPS_NONE
, /* type */
333 0, /* size (0 = byte, 1 = short, 2 = long) */
335 false, /* pc_relative */
337 complain_overflow_dont
, /* complain_on_overflow */
338 bfd_elf_generic_reloc
, /* special_function */
339 "R_MIPS_NONE", /* name */
340 false, /* partial_inplace */
343 false), /* pcrel_offset */
345 /* 16 bit relocation. */
346 HOWTO (R_MIPS_16
, /* type */
348 1, /* size (0 = byte, 1 = short, 2 = long) */
350 false, /* pc_relative */
352 complain_overflow_bitfield
, /* complain_on_overflow */
353 bfd_elf_generic_reloc
, /* special_function */
354 "R_MIPS_16", /* name */
355 true, /* partial_inplace */
356 0xffff, /* src_mask */
357 0xffff, /* dst_mask */
358 false), /* pcrel_offset */
360 /* 32 bit relocation. */
361 HOWTO (R_MIPS_32
, /* type */
363 2, /* size (0 = byte, 1 = short, 2 = long) */
365 false, /* pc_relative */
367 complain_overflow_bitfield
, /* complain_on_overflow */
368 bfd_elf_generic_reloc
, /* special_function */
369 "R_MIPS_32", /* name */
370 true, /* partial_inplace */
371 0xffffffff, /* src_mask */
372 0xffffffff, /* dst_mask */
373 false), /* pcrel_offset */
375 /* 32 bit symbol relative relocation. */
376 HOWTO (R_MIPS_REL32
, /* type */
378 2, /* size (0 = byte, 1 = short, 2 = long) */
380 false, /* pc_relative */
382 complain_overflow_bitfield
, /* complain_on_overflow */
383 bfd_elf_generic_reloc
, /* special_function */
384 "R_MIPS_REL32", /* name */
385 true, /* partial_inplace */
386 0xffffffff, /* src_mask */
387 0xffffffff, /* dst_mask */
388 false), /* pcrel_offset */
390 /* 26 bit branch address. */
391 HOWTO (R_MIPS_26
, /* type */
393 2, /* size (0 = byte, 1 = short, 2 = long) */
395 false, /* pc_relative */
397 complain_overflow_dont
, /* complain_on_overflow */
398 /* This needs complex overflow
399 detection, because the upper four
400 bits must match the PC. */
401 bfd_elf_generic_reloc
, /* special_function */
402 "R_MIPS_26", /* name */
403 true, /* partial_inplace */
404 0x3ffffff, /* src_mask */
405 0x3ffffff, /* dst_mask */
406 false), /* pcrel_offset */
408 /* High 16 bits of symbol value. */
409 HOWTO (R_MIPS_HI16
, /* type */
411 2, /* size (0 = byte, 1 = short, 2 = long) */
413 false, /* pc_relative */
415 complain_overflow_dont
, /* complain_on_overflow */
416 _bfd_mips_elf_hi16_reloc
, /* special_function */
417 "R_MIPS_HI16", /* name */
418 true, /* partial_inplace */
419 0xffff, /* src_mask */
420 0xffff, /* dst_mask */
421 false), /* pcrel_offset */
423 /* Low 16 bits of symbol value. */
424 HOWTO (R_MIPS_LO16
, /* type */
426 2, /* size (0 = byte, 1 = short, 2 = long) */
428 false, /* pc_relative */
430 complain_overflow_dont
, /* complain_on_overflow */
431 _bfd_mips_elf_lo16_reloc
, /* special_function */
432 "R_MIPS_LO16", /* name */
433 true, /* partial_inplace */
434 0xffff, /* src_mask */
435 0xffff, /* dst_mask */
436 false), /* pcrel_offset */
438 /* GP relative reference. */
439 HOWTO (R_MIPS_GPREL16
, /* type */
441 2, /* size (0 = byte, 1 = short, 2 = long) */
443 false, /* pc_relative */
445 complain_overflow_signed
, /* complain_on_overflow */
446 _bfd_mips_elf_gprel16_reloc
, /* special_function */
447 "R_MIPS_GPREL16", /* name */
448 true, /* partial_inplace */
449 0xffff, /* src_mask */
450 0xffff, /* dst_mask */
451 false), /* pcrel_offset */
453 /* Reference to literal section. */
454 HOWTO (R_MIPS_LITERAL
, /* type */
456 2, /* size (0 = byte, 1 = short, 2 = long) */
458 false, /* pc_relative */
460 complain_overflow_signed
, /* complain_on_overflow */
461 _bfd_mips_elf_gprel16_reloc
, /* special_function */
462 "R_MIPS_LITERAL", /* name */
463 true, /* partial_inplace */
464 0xffff, /* src_mask */
465 0xffff, /* dst_mask */
466 false), /* pcrel_offset */
468 /* Reference to global offset table. */
469 HOWTO (R_MIPS_GOT16
, /* type */
471 2, /* size (0 = byte, 1 = short, 2 = long) */
473 false, /* pc_relative */
475 complain_overflow_signed
, /* complain_on_overflow */
476 _bfd_mips_elf_got16_reloc
, /* special_function */
477 "R_MIPS_GOT16", /* name */
478 false, /* partial_inplace */
480 0xffff, /* dst_mask */
481 false), /* pcrel_offset */
483 /* 16 bit PC relative reference. */
484 HOWTO (R_MIPS_PC16
, /* type */
486 2, /* size (0 = byte, 1 = short, 2 = long) */
488 true, /* pc_relative */
490 complain_overflow_signed
, /* complain_on_overflow */
491 bfd_elf_generic_reloc
, /* special_function */
492 "R_MIPS_PC16", /* name */
493 true, /* partial_inplace */
494 0xffff, /* src_mask */
495 0xffff, /* dst_mask */
496 false), /* pcrel_offset */
498 /* 16 bit call through global offset table. */
499 /* FIXME: This is not handled correctly. */
500 HOWTO (R_MIPS_CALL16
, /* type */
502 2, /* size (0 = byte, 1 = short, 2 = long) */
504 false, /* pc_relative */
506 complain_overflow_signed
, /* complain_on_overflow */
507 bfd_elf_generic_reloc
, /* special_function */
508 "R_MIPS_CALL16", /* name */
509 false, /* partial_inplace */
511 0xffff, /* dst_mask */
512 false), /* pcrel_offset */
514 /* 32 bit GP relative reference. */
515 HOWTO (R_MIPS_GPREL32
, /* type */
517 2, /* size (0 = byte, 1 = short, 2 = long) */
519 false, /* pc_relative */
521 complain_overflow_bitfield
, /* complain_on_overflow */
522 _bfd_mips_elf_gprel32_reloc
, /* special_function */
523 "R_MIPS_GPREL32", /* name */
524 true, /* partial_inplace */
525 0xffffffff, /* src_mask */
526 0xffffffff, /* dst_mask */
527 false), /* pcrel_offset */
529 /* The remaining relocs are defined on Irix 5, although they are
530 not defined by the ABI. */
535 /* A 5 bit shift field. */
536 HOWTO (R_MIPS_SHIFT5
, /* type */
538 2, /* size (0 = byte, 1 = short, 2 = long) */
540 false, /* pc_relative */
542 complain_overflow_bitfield
, /* complain_on_overflow */
543 bfd_elf_generic_reloc
, /* special_function */
544 "R_MIPS_SHIFT5", /* name */
545 true, /* partial_inplace */
546 0x000007c0, /* src_mask */
547 0x000007c0, /* dst_mask */
548 false), /* pcrel_offset */
550 /* A 6 bit shift field. */
551 /* FIXME: This is not handled correctly; a special function is
552 needed to put the most significant bit in the right place. */
553 HOWTO (R_MIPS_SHIFT6
, /* type */
555 2, /* size (0 = byte, 1 = short, 2 = long) */
557 false, /* pc_relative */
559 complain_overflow_bitfield
, /* complain_on_overflow */
560 bfd_elf_generic_reloc
, /* special_function */
561 "R_MIPS_SHIFT6", /* name */
562 true, /* partial_inplace */
563 0x000007c4, /* src_mask */
564 0x000007c4, /* dst_mask */
565 false), /* pcrel_offset */
567 /* A 64 bit relocation. This is used in 32 bit ELF when addresses
568 are 64 bits long; the upper 32 bits are simply a sign extension.
569 The fields of the howto should be the same as for R_MIPS_32,
570 other than the type, name, and special_function. */
571 HOWTO (R_MIPS_64
, /* type */
573 2, /* size (0 = byte, 1 = short, 2 = long) */
575 false, /* pc_relative */
577 complain_overflow_bitfield
, /* complain_on_overflow */
578 mips32_64bit_reloc
, /* special_function */
579 "R_MIPS_64", /* name */
580 true, /* partial_inplace */
581 0xffffffff, /* src_mask */
582 0xffffffff, /* dst_mask */
583 false), /* pcrel_offset */
585 /* Displacement in the global offset table. */
586 /* FIXME: Not handled correctly. */
587 HOWTO (R_MIPS_GOT_DISP
, /* 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_DISP", /* name */
596 true, /* partial_inplace */
597 0x0000ffff, /* src_mask */
598 0x0000ffff, /* dst_mask */
599 false), /* pcrel_offset */
601 /* Displacement to page pointer in the global offset table. */
602 /* FIXME: Not handled correctly. */
603 HOWTO (R_MIPS_GOT_PAGE
, /* type */
605 2, /* size (0 = byte, 1 = short, 2 = long) */
607 false, /* pc_relative */
609 complain_overflow_bitfield
, /* complain_on_overflow */
610 bfd_elf_generic_reloc
, /* special_function */
611 "R_MIPS_GOT_PAGE", /* name */
612 true, /* partial_inplace */
613 0x0000ffff, /* src_mask */
614 0x0000ffff, /* dst_mask */
615 false), /* pcrel_offset */
617 /* Offset from page pointer in the global offset table. */
618 /* FIXME: Not handled correctly. */
619 HOWTO (R_MIPS_GOT_OFST
, /* type */
621 2, /* size (0 = byte, 1 = short, 2 = long) */
623 false, /* pc_relative */
625 complain_overflow_bitfield
, /* complain_on_overflow */
626 bfd_elf_generic_reloc
, /* special_function */
627 "R_MIPS_GOT_OFST", /* name */
628 true, /* partial_inplace */
629 0x0000ffff, /* src_mask */
630 0x0000ffff, /* dst_mask */
631 false), /* pcrel_offset */
633 /* High 16 bits of displacement in global offset table. */
634 /* FIXME: Not handled correctly. */
635 HOWTO (R_MIPS_GOT_HI16
, /* type */
637 2, /* size (0 = byte, 1 = short, 2 = long) */
639 false, /* pc_relative */
641 complain_overflow_dont
, /* complain_on_overflow */
642 bfd_elf_generic_reloc
, /* special_function */
643 "R_MIPS_GOT_HI16", /* name */
644 true, /* partial_inplace */
645 0x0000ffff, /* src_mask */
646 0x0000ffff, /* dst_mask */
647 false), /* pcrel_offset */
649 /* Low 16 bits of displacement in global offset table. */
650 /* FIXME: Not handled correctly. */
651 HOWTO (R_MIPS_GOT_LO16
, /* type */
653 2, /* size (0 = byte, 1 = short, 2 = long) */
655 false, /* pc_relative */
657 complain_overflow_dont
, /* complain_on_overflow */
658 bfd_elf_generic_reloc
, /* special_function */
659 "R_MIPS_GOT_LO16", /* name */
660 true, /* partial_inplace */
661 0x0000ffff, /* src_mask */
662 0x0000ffff, /* dst_mask */
663 false), /* pcrel_offset */
665 /* 64 bit subtraction. Presumably not used in 32 bit ELF. */
668 /* Used to cause the linker to insert and delete instructions? */
673 /* Get the higher values of a 64 bit addend. Presumably not used in
678 /* High 16 bits of displacement in global offset table. */
679 /* FIXME: Not handled correctly. */
680 HOWTO (R_MIPS_CALL_HI16
, /* type */
682 2, /* size (0 = byte, 1 = short, 2 = long) */
684 false, /* pc_relative */
686 complain_overflow_dont
, /* complain_on_overflow */
687 bfd_elf_generic_reloc
, /* special_function */
688 "R_MIPS_CALL_HI16", /* name */
689 true, /* partial_inplace */
690 0x0000ffff, /* src_mask */
691 0x0000ffff, /* dst_mask */
692 false), /* pcrel_offset */
694 /* Low 16 bits of displacement in global offset table. */
695 /* FIXME: Not handled correctly. */
696 HOWTO (R_MIPS_CALL_LO16
, /* type */
698 2, /* size (0 = byte, 1 = short, 2 = long) */
700 false, /* pc_relative */
702 complain_overflow_dont
, /* complain_on_overflow */
703 bfd_elf_generic_reloc
, /* special_function */
704 "R_MIPS_CALL_LO16", /* name */
705 true, /* partial_inplace */
706 0x0000ffff, /* src_mask */
707 0x0000ffff, /* dst_mask */
708 false), /* pcrel_offset */
710 /* start-sanitize-r5900 */
711 HOWTO (R_MIPS15_S3
, /* type */
713 2, /* size (0 = byte, 1 = short, 2 = long) */
715 false, /* pc_relative */
717 complain_overflow_bitfield
, /* complain_on_overflow */
718 bfd_elf_generic_reloc
, /* special_function */
719 "R_MIPS15_S3", /* name */
720 true, /* partial_inplace */
721 0x001fffc0, /* src_mask */
722 0x001fffc0, /* dst_mask */
723 false) /* pcrel_offset */
724 /* end-sanitize-r5900 */
728 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
729 is a hack to make the linker think that we need 64 bit values. */
730 static reloc_howto_type elf_mips_ctor64_howto
=
731 HOWTO (R_MIPS_64
, /* type */
733 4, /* size (0 = byte, 1 = short, 2 = long) */
735 false, /* pc_relative */
737 complain_overflow_signed
, /* complain_on_overflow */
738 mips32_64bit_reloc
, /* special_function */
739 "R_MIPS_64", /* name */
740 true, /* partial_inplace */
741 0xffffffff, /* src_mask */
742 0xffffffff, /* dst_mask */
743 false); /* pcrel_offset */
745 /* The reloc used for the mips16 jump instruction. */
746 static reloc_howto_type elf_mips16_jump_howto
=
747 HOWTO (R_MIPS16_26
, /* type */
749 2, /* size (0 = byte, 1 = short, 2 = long) */
751 false, /* pc_relative */
753 complain_overflow_dont
, /* complain_on_overflow */
754 /* This needs complex overflow
755 detection, because the upper four
756 bits must match the PC. */
757 mips16_jump_reloc
, /* special_function */
758 "R_MIPS16_26", /* name */
759 true, /* partial_inplace */
760 0x3ffffff, /* src_mask */
761 0x3ffffff, /* dst_mask */
762 false); /* pcrel_offset */
764 /* The reloc used for the mips16 gprel instruction. The src_mask and
765 dsk_mask for this howto do not reflect the actual instruction, in
766 which the value is not contiguous; the masks are for the
767 convenience of the relocate_section routine. */
768 static reloc_howto_type elf_mips16_gprel_howto
=
769 HOWTO (R_MIPS16_GPREL
, /* type */
771 2, /* size (0 = byte, 1 = short, 2 = long) */
773 false, /* pc_relative */
775 complain_overflow_signed
, /* complain_on_overflow */
776 mips16_gprel_reloc
, /* special_function */
777 "R_MIPS16_GPREL", /* name */
778 true, /* partial_inplace */
779 0xffff, /* src_mask */
780 0xffff, /* dst_mask */
781 false); /* pcrel_offset */
783 /* start-sanitize-sky */
785 Note that partial_inplace and pcrel_offset are backwards from the
786 mips port. This is intentional as it seems more reasonable. */
787 static reloc_howto_type elf_mips_dvp_11_pcrel_howto
=
788 HOWTO (R_MIPS_DVP_11_PCREL
, /* type */
790 2, /* size (0 = byte, 1 = short, 2 = long) */
792 true, /* pc_relative */
794 complain_overflow_signed
, /* complain_on_overflow */
795 bfd_elf_generic_reloc
, /* special_function */
796 "R_MIPS_DVP_11_PCREL", /* name */
797 false, /* partial_inplace */
798 0x7ff, /* src_mask */
799 0x7ff, /* dst_mask */
800 true); /* pcrel_offset */
801 static reloc_howto_type elf_mips_dvp_27_s4_howto
=
802 HOWTO (R_MIPS_DVP_27_S4
, /* type */
804 2, /* size (0 = byte, 1 = short, 2 = long) */
806 false, /* pc_relative */
808 complain_overflow_unsigned
, /* complain_on_overflow */
809 bfd_elf_generic_reloc
, /* special_function */
810 "R_MIPS_DVP_27_S4", /* name */
811 false, /* partial_inplace */
812 0x7ffffff0, /* src_mask */
813 0x7ffffff0, /* dst_mask */
814 false); /* pcrel_offset */
815 /* end-sanitize-sky */
817 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
818 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
819 the HI16. Here we just save the information we need; we do the
820 actual relocation when we see the LO16. MIPS ELF requires that the
821 LO16 immediately follow the HI16. As a GNU extension, we permit an
822 arbitrary number of HI16 relocs to be associated with a single LO16
823 reloc. This extension permits gcc to output the HI and LO relocs
828 struct mips_hi16
*next
;
833 /* FIXME: This should not be a static variable. */
835 static struct mips_hi16
*mips_hi16_list
;
837 bfd_reloc_status_type
838 _bfd_mips_elf_hi16_reloc (abfd
,
846 arelent
*reloc_entry
;
849 asection
*input_section
;
851 char **error_message
;
853 bfd_reloc_status_type ret
;
857 /* If we're relocating, and this an external symbol, we don't want
858 to change anything. */
859 if (output_bfd
!= (bfd
*) NULL
860 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
861 && reloc_entry
->addend
== 0)
863 reloc_entry
->address
+= input_section
->output_offset
;
869 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
871 boolean relocateable
;
874 if (ret
== bfd_reloc_undefined
)
877 if (output_bfd
!= NULL
)
881 relocateable
= false;
882 output_bfd
= symbol
->section
->output_section
->owner
;
885 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
887 if (ret
!= bfd_reloc_ok
)
890 relocation
= gp
- reloc_entry
->address
;
894 if (bfd_is_und_section (symbol
->section
)
895 && output_bfd
== (bfd
*) NULL
)
896 ret
= bfd_reloc_undefined
;
898 if (bfd_is_com_section (symbol
->section
))
901 relocation
= symbol
->value
;
904 relocation
+= symbol
->section
->output_section
->vma
;
905 relocation
+= symbol
->section
->output_offset
;
906 relocation
+= reloc_entry
->addend
;
908 if (reloc_entry
->address
> input_section
->_cooked_size
)
909 return bfd_reloc_outofrange
;
911 /* Save the information, and let LO16 do the actual relocation. */
912 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
914 return bfd_reloc_outofrange
;
915 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
916 n
->addend
= relocation
;
917 n
->next
= mips_hi16_list
;
920 if (output_bfd
!= (bfd
*) NULL
)
921 reloc_entry
->address
+= input_section
->output_offset
;
926 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
927 inplace relocation; this function exists in order to do the
928 R_MIPS_HI16 relocation described above. */
930 bfd_reloc_status_type
931 _bfd_mips_elf_lo16_reloc (abfd
,
939 arelent
*reloc_entry
;
942 asection
*input_section
;
944 char **error_message
;
946 arelent gp_disp_relent
;
948 if (mips_hi16_list
!= NULL
)
958 struct mips_hi16
*next
;
960 /* Do the HI16 relocation. Note that we actually don't need
961 to know anything about the LO16 itself, except where to
962 find the low 16 bits of the addend needed by the LO16. */
963 insn
= bfd_get_32 (abfd
, l
->addr
);
964 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
966 val
= ((insn
& 0xffff) << 16) + vallo
;
969 /* The low order 16 bits are always treated as a signed
970 value. Therefore, a negative value in the low order bits
971 requires an adjustment in the high order bits. We need
972 to make this adjustment in two ways: once for the bits we
973 took from the data, and once for the bits we are putting
974 back in to the data. */
975 if ((vallo
& 0x8000) != 0)
977 if ((val
& 0x8000) != 0)
980 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
981 bfd_put_32 (abfd
, insn
, l
->addr
);
983 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
985 gp_disp_relent
= *reloc_entry
;
986 reloc_entry
= &gp_disp_relent
;
987 reloc_entry
->addend
= l
->addend
;
995 mips_hi16_list
= NULL
;
997 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
999 bfd_reloc_status_type ret
;
1000 bfd_vma gp
, relocation
;
1002 /* FIXME: Does this case ever occur? */
1004 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
1005 if (ret
!= bfd_reloc_ok
)
1008 relocation
= gp
- reloc_entry
->address
;
1009 relocation
+= symbol
->section
->output_section
->vma
;
1010 relocation
+= symbol
->section
->output_offset
;
1011 relocation
+= reloc_entry
->addend
;
1013 if (reloc_entry
->address
> input_section
->_cooked_size
)
1014 return bfd_reloc_outofrange
;
1016 gp_disp_relent
= *reloc_entry
;
1017 reloc_entry
= &gp_disp_relent
;
1018 reloc_entry
->addend
= relocation
- 4;
1021 /* Now do the LO16 reloc in the usual way. */
1022 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1023 input_section
, output_bfd
, error_message
);
1026 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1027 table used for PIC code. If the symbol is an external symbol, the
1028 instruction is modified to contain the offset of the appropriate
1029 entry in the global offset table. If the symbol is a section
1030 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1031 addends are combined to form the real addend against the section
1032 symbol; the GOT16 is modified to contain the offset of an entry in
1033 the global offset table, and the LO16 is modified to offset it
1034 appropriately. Thus an offset larger than 16 bits requires a
1035 modified value in the global offset table.
1037 This implementation suffices for the assembler, but the linker does
1038 not yet know how to create global offset tables. */
1040 bfd_reloc_status_type
1041 _bfd_mips_elf_got16_reloc (abfd
,
1049 arelent
*reloc_entry
;
1052 asection
*input_section
;
1054 char **error_message
;
1056 /* If we're relocating, and this an external symbol, we don't want
1057 to change anything. */
1058 if (output_bfd
!= (bfd
*) NULL
1059 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1060 && reloc_entry
->addend
== 0)
1062 reloc_entry
->address
+= input_section
->output_offset
;
1063 return bfd_reloc_ok
;
1066 /* If we're relocating, and this is a local symbol, we can handle it
1068 if (output_bfd
!= (bfd
*) NULL
1069 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1070 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1071 input_section
, output_bfd
, error_message
);
1076 /* We have to figure out the gp value, so that we can adjust the
1077 symbol value correctly. We look up the symbol _gp in the output
1078 BFD. If we can't find it, we're stuck. We cache it in the ELF
1079 target data. We don't need to adjust the symbol value for an
1080 external symbol if we are producing relocateable output. */
1082 static bfd_reloc_status_type
1083 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1086 boolean relocateable
;
1087 char **error_message
;
1090 if (bfd_is_und_section (symbol
->section
)
1094 return bfd_reloc_undefined
;
1097 *pgp
= _bfd_get_gp_value (output_bfd
);
1100 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1104 /* Make up a value. */
1105 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1106 _bfd_set_gp_value (output_bfd
, *pgp
);
1114 count
= bfd_get_symcount (output_bfd
);
1115 sym
= bfd_get_outsymbols (output_bfd
);
1117 if (sym
== (asymbol
**) NULL
)
1121 for (i
= 0; i
< count
; i
++, sym
++)
1123 register CONST
char *name
;
1125 name
= bfd_asymbol_name (*sym
);
1126 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1128 *pgp
= bfd_asymbol_value (*sym
);
1129 _bfd_set_gp_value (output_bfd
, *pgp
);
1137 /* Only get the error once. */
1139 _bfd_set_gp_value (output_bfd
, *pgp
);
1141 (char *) _("GP relative relocation when _gp not defined");
1142 return bfd_reloc_dangerous
;
1147 return bfd_reloc_ok
;
1150 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1151 become the offset from the gp register. This function also handles
1152 R_MIPS_LITERAL relocations, although those can be handled more
1153 cleverly because the entries in the .lit8 and .lit4 sections can be
1156 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1157 arelent
*, asection
*,
1158 boolean
, PTR
, bfd_vma
));
1160 bfd_reloc_status_type
1161 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1162 output_bfd
, error_message
)
1164 arelent
*reloc_entry
;
1167 asection
*input_section
;
1169 char **error_message
;
1171 boolean relocateable
;
1172 bfd_reloc_status_type ret
;
1175 /* If we're relocating, and this is an external symbol with no
1176 addend, we don't want to change anything. We will only have an
1177 addend if this is a newly created reloc, not read from an ELF
1179 if (output_bfd
!= (bfd
*) NULL
1180 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1181 && reloc_entry
->addend
== 0)
1183 reloc_entry
->address
+= input_section
->output_offset
;
1184 return bfd_reloc_ok
;
1187 if (output_bfd
!= (bfd
*) NULL
)
1188 relocateable
= true;
1191 relocateable
= false;
1192 output_bfd
= symbol
->section
->output_section
->owner
;
1195 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1197 if (ret
!= bfd_reloc_ok
)
1200 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1201 relocateable
, data
, gp
);
1204 static bfd_reloc_status_type
1205 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1209 arelent
*reloc_entry
;
1210 asection
*input_section
;
1211 boolean relocateable
;
1219 if (bfd_is_com_section (symbol
->section
))
1222 relocation
= symbol
->value
;
1224 relocation
+= symbol
->section
->output_section
->vma
;
1225 relocation
+= symbol
->section
->output_offset
;
1227 if (reloc_entry
->address
> input_section
->_cooked_size
)
1228 return bfd_reloc_outofrange
;
1230 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1232 /* Set val to the offset into the section or symbol. */
1233 if (reloc_entry
->howto
->src_mask
== 0)
1235 /* This case occurs with the 64-bit MIPS ELF ABI. */
1236 val
= reloc_entry
->addend
;
1240 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1245 /* Adjust val for the final section location and GP value. If we
1246 are producing relocateable output, we don't want to do this for
1247 an external symbol. */
1249 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1250 val
+= relocation
- gp
;
1252 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1253 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1256 reloc_entry
->address
+= input_section
->output_offset
;
1258 /* Make sure it fit in 16 bits. */
1259 if (val
>= 0x8000 && val
< 0xffff8000)
1260 return bfd_reloc_overflow
;
1262 return bfd_reloc_ok
;
1265 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1266 from the gp register? XXX */
1268 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1269 arelent
*, asection
*,
1270 boolean
, PTR
, bfd_vma
));
1272 bfd_reloc_status_type
1273 _bfd_mips_elf_gprel32_reloc (abfd
,
1281 arelent
*reloc_entry
;
1284 asection
*input_section
;
1286 char **error_message
;
1288 boolean relocateable
;
1289 bfd_reloc_status_type ret
;
1292 /* If we're relocating, and this is an external symbol with no
1293 addend, we don't want to change anything. We will only have an
1294 addend if this is a newly created reloc, not read from an ELF
1296 if (output_bfd
!= (bfd
*) NULL
1297 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1298 && reloc_entry
->addend
== 0)
1300 *error_message
= (char *)
1301 _("32bits gp relative relocation occurs for an external symbol");
1302 return bfd_reloc_outofrange
;
1305 if (output_bfd
!= (bfd
*) NULL
)
1307 relocateable
= true;
1308 gp
= _bfd_get_gp_value (output_bfd
);
1312 relocateable
= false;
1313 output_bfd
= symbol
->section
->output_section
->owner
;
1315 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1316 error_message
, &gp
);
1317 if (ret
!= bfd_reloc_ok
)
1321 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1322 relocateable
, data
, gp
);
1325 static bfd_reloc_status_type
1326 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1330 arelent
*reloc_entry
;
1331 asection
*input_section
;
1332 boolean relocateable
;
1339 if (bfd_is_com_section (symbol
->section
))
1342 relocation
= symbol
->value
;
1344 relocation
+= symbol
->section
->output_section
->vma
;
1345 relocation
+= symbol
->section
->output_offset
;
1347 if (reloc_entry
->address
> input_section
->_cooked_size
)
1348 return bfd_reloc_outofrange
;
1350 if (reloc_entry
->howto
->src_mask
== 0)
1352 /* This case arises with the 64-bit MIPS ELF ABI. */
1356 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1358 /* Set val to the offset into the section or symbol. */
1359 val
+= reloc_entry
->addend
;
1361 /* Adjust val for the final section location and GP value. If we
1362 are producing relocateable output, we don't want to do this for
1363 an external symbol. */
1365 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1366 val
+= relocation
- gp
;
1368 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1371 reloc_entry
->address
+= input_section
->output_offset
;
1373 return bfd_reloc_ok
;
1376 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1377 generated when addreses are 64 bits. The upper 32 bits are a simle
1380 static bfd_reloc_status_type
1381 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1382 output_bfd
, error_message
)
1384 arelent
*reloc_entry
;
1387 asection
*input_section
;
1389 char **error_message
;
1391 bfd_reloc_status_type r
;
1396 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1397 input_section
, output_bfd
, error_message
);
1398 if (r
!= bfd_reloc_continue
)
1401 /* Do a normal 32 bit relocation on the lower 32 bits. */
1402 reloc32
= *reloc_entry
;
1403 if (bfd_big_endian (abfd
))
1404 reloc32
.address
+= 4;
1405 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1406 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1407 output_bfd
, error_message
);
1409 /* Sign extend into the upper 32 bits. */
1410 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1411 if ((val
& 0x80000000) != 0)
1415 addr
= reloc_entry
->address
;
1416 if (bfd_little_endian (abfd
))
1418 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1423 /* Handle a mips16 jump. */
1425 static bfd_reloc_status_type
1426 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1427 output_bfd
, error_message
)
1429 arelent
*reloc_entry
;
1432 asection
*input_section
;
1434 char **error_message
;
1436 if (output_bfd
!= (bfd
*) NULL
1437 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1438 && reloc_entry
->addend
== 0)
1440 reloc_entry
->address
+= input_section
->output_offset
;
1441 return bfd_reloc_ok
;
1446 static boolean warned
;
1449 (*_bfd_error_handler
)
1450 (_("Linking mips16 objects into %s format is not supported"),
1451 bfd_get_target (input_section
->output_section
->owner
));
1455 return bfd_reloc_undefined
;
1458 /* Handle a mips16 GP relative reloc. */
1460 static bfd_reloc_status_type
1461 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1462 output_bfd
, error_message
)
1464 arelent
*reloc_entry
;
1467 asection
*input_section
;
1469 char **error_message
;
1471 boolean relocateable
;
1472 bfd_reloc_status_type ret
;
1474 unsigned short extend
, insn
;
1475 unsigned long final
;
1477 /* If we're relocating, and this is an external symbol with no
1478 addend, we don't want to change anything. We will only have an
1479 addend if this is a newly created reloc, not read from an ELF
1481 if (output_bfd
!= NULL
1482 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1483 && reloc_entry
->addend
== 0)
1485 reloc_entry
->address
+= input_section
->output_offset
;
1486 return bfd_reloc_ok
;
1489 if (output_bfd
!= NULL
)
1490 relocateable
= true;
1493 relocateable
= false;
1494 output_bfd
= symbol
->section
->output_section
->owner
;
1497 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1499 if (ret
!= bfd_reloc_ok
)
1502 if (reloc_entry
->address
> input_section
->_cooked_size
)
1503 return bfd_reloc_outofrange
;
1505 /* Pick up the mips16 extend instruction and the real instruction. */
1506 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1507 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1509 /* Stuff the current addend back as a 32 bit value, do the usual
1510 relocation, and then clean up. */
1512 (((extend
& 0x1f) << 11)
1515 (bfd_byte
*) data
+ reloc_entry
->address
);
1517 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1518 relocateable
, data
, gp
);
1520 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1523 | ((final
>> 11) & 0x1f)
1525 (bfd_byte
*) data
+ reloc_entry
->address
);
1529 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1534 /* Return the ISA for a MIPS e_flags value. */
1537 elf_mips_isa (flags
)
1540 switch (flags
& EF_MIPS_ARCH
)
1554 /* Return the MACH for a MIPS e_flags value. */
1557 elf_mips_mach (flags
)
1560 switch (flags
& EF_MIPS_MACH
)
1562 case E_MIPS_MACH_3900
:
1563 return bfd_mach_mips3900
;
1565 case E_MIPS_MACH_4010
:
1566 return bfd_mach_mips4010
;
1568 case E_MIPS_MACH_4100
:
1569 return bfd_mach_mips4100
;
1570 /* start-sanitize-vr4320 */
1572 case E_MIPS_MACH_4320
:
1573 return bfd_mach_mips4320
;
1574 /* end-sanitize-vr4320 */
1576 case E_MIPS_MACH_4650
:
1577 return bfd_mach_mips4650
;
1578 /* start-sanitize-tx49 */
1580 case E_MIPS_MACH_4900
:
1581 return bfd_mach_mips4900
;
1582 /* end-sanitize-tx49 */
1583 /* start-sanitize-vr5400 */
1585 case E_MIPS_MACH_5400
:
1586 return bfd_mach_mips5400
;
1587 /* end-sanitize-vr5400 */
1588 /* start-sanitize-r5900 */
1590 case E_MIPS_MACH_5900
:
1591 return bfd_mach_mips5900
;
1592 /* end-sanitize-r5900 */
1595 switch (flags
& EF_MIPS_ARCH
)
1599 return bfd_mach_mips3000
;
1603 return bfd_mach_mips6000
;
1607 return bfd_mach_mips4000
;
1611 return bfd_mach_mips8000
;
1619 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1621 struct elf_reloc_map
{
1622 bfd_reloc_code_real_type bfd_reloc_val
;
1623 enum reloc_type elf_reloc_val
;
1626 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1628 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1629 { BFD_RELOC_16
, R_MIPS_16
},
1630 { BFD_RELOC_32
, R_MIPS_32
},
1631 { BFD_RELOC_64
, R_MIPS_64
},
1632 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1633 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1634 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1635 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1636 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1637 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1638 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1639 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1640 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1641 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1642 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1643 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1644 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
},
1645 /* start-sanitize-r5900 */
1646 { BFD_RELOC_MIPS15_S3
, R_MIPS15_S3
},
1647 /* end-sanitize-r5900 */
1650 /* Given a BFD reloc type, return a howto structure. */
1652 static reloc_howto_type
*
1653 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1655 bfd_reloc_code_real_type code
;
1659 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1661 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1662 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1665 /* We need to handle BFD_RELOC_CTOR specially.
1667 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1668 size of addresses on this architecture. */
1669 if (code
== BFD_RELOC_CTOR
)
1671 if (bfd_arch_bits_per_address (abfd
) == 32)
1672 return &elf_mips_howto_table
[(int) R_MIPS_32
];
1674 return &elf_mips_ctor64_howto
;
1677 /* Special handling for the MIPS16 relocs, since they are made up
1678 reloc types with a large value. */
1679 if (code
== BFD_RELOC_MIPS16_JMP
)
1680 return &elf_mips16_jump_howto
;
1681 else if (code
== BFD_RELOC_MIPS16_GPREL
)
1682 return &elf_mips16_gprel_howto
;
1683 /* start-sanitize-sky */
1684 else if (code
== BFD_RELOC_MIPS_DVP_11_PCREL
)
1685 return &elf_mips_dvp_11_pcrel_howto
;
1686 else if (code
== BFD_RELOC_MIPS_DVP_27_S4
)
1687 return &elf_mips_dvp_27_s4_howto
;
1688 /* end-sanitize-sky */
1693 /* Given a MIPS reloc type, fill in an arelent structure. */
1696 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1699 Elf32_Internal_Rel
*dst
;
1701 unsigned int r_type
;
1703 r_type
= ELF32_R_TYPE (dst
->r_info
);
1704 if (r_type
== R_MIPS16_26
)
1705 cache_ptr
->howto
= &elf_mips16_jump_howto
;
1706 else if (r_type
== R_MIPS16_GPREL
)
1707 cache_ptr
->howto
= &elf_mips16_gprel_howto
;
1708 /* start-sanitize-sky */
1709 else if (r_type
== R_MIPS_DVP_11_PCREL
)
1710 cache_ptr
->howto
= &elf_mips_dvp_11_pcrel_howto
;
1711 else if (r_type
== R_MIPS_DVP_27_S4
)
1712 cache_ptr
->howto
= &elf_mips_dvp_27_s4_howto
;
1713 /* end-sanitize-sky */
1716 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1717 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1720 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1721 value for the object file. We get the addend now, rather than
1722 when we do the relocation, because the symbol manipulations done
1723 by the linker may cause us to lose track of the input BFD. */
1724 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1725 && (r_type
== (unsigned int) R_MIPS_GPREL16
1726 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1727 cache_ptr
->addend
= elf_gp (abfd
);
1730 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1731 routines swap this structure in and out. They are used outside of
1732 BFD, so they are globally visible. */
1735 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1737 const Elf32_External_RegInfo
*ex
;
1740 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1741 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1742 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1743 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1744 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1745 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1749 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1751 const Elf32_RegInfo
*in
;
1752 Elf32_External_RegInfo
*ex
;
1754 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1755 (bfd_byte
*) ex
->ri_gprmask
);
1756 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1757 (bfd_byte
*) ex
->ri_cprmask
[0]);
1758 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1759 (bfd_byte
*) ex
->ri_cprmask
[1]);
1760 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1761 (bfd_byte
*) ex
->ri_cprmask
[2]);
1762 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1763 (bfd_byte
*) ex
->ri_cprmask
[3]);
1764 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1765 (bfd_byte
*) ex
->ri_gp_value
);
1768 /* In the 64 bit ABI, the .MIPS.options section holds register
1769 information in an Elf64_Reginfo structure. These routines swap
1770 them in and out. They are globally visible because they are used
1771 outside of BFD. These routines are here so that gas can call them
1772 without worrying about whether the 64 bit ABI has been included. */
1775 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1777 const Elf64_External_RegInfo
*ex
;
1778 Elf64_Internal_RegInfo
*in
;
1780 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1781 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
1782 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1783 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1784 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1785 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1786 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1790 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1792 const Elf64_Internal_RegInfo
*in
;
1793 Elf64_External_RegInfo
*ex
;
1795 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1796 (bfd_byte
*) ex
->ri_gprmask
);
1797 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
1798 (bfd_byte
*) ex
->ri_pad
);
1799 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1800 (bfd_byte
*) ex
->ri_cprmask
[0]);
1801 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1802 (bfd_byte
*) ex
->ri_cprmask
[1]);
1803 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1804 (bfd_byte
*) ex
->ri_cprmask
[2]);
1805 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1806 (bfd_byte
*) ex
->ri_cprmask
[3]);
1807 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1808 (bfd_byte
*) ex
->ri_gp_value
);
1811 /* Swap an entry in a .gptab section. Note that these routines rely
1812 on the equivalence of the two elements of the union. */
1815 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1817 const Elf32_External_gptab
*ex
;
1820 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1821 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1825 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1827 const Elf32_gptab
*in
;
1828 Elf32_External_gptab
*ex
;
1830 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1831 ex
->gt_entry
.gt_g_value
);
1832 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1833 ex
->gt_entry
.gt_bytes
);
1837 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1839 const Elf32_compact_rel
*in
;
1840 Elf32_External_compact_rel
*ex
;
1842 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
1843 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
1844 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
1845 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
1846 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
1847 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
1851 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1853 const Elf32_crinfo
*in
;
1854 Elf32_External_crinfo
*ex
;
1858 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1859 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1860 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1861 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1862 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
1863 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
1864 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
1867 /* Swap in an options header. */
1870 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1872 const Elf_External_Options
*ex
;
1873 Elf_Internal_Options
*in
;
1875 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
1876 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
1877 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
1878 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
1881 /* Swap out an options header. */
1884 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
1886 const Elf_Internal_Options
*in
;
1887 Elf_External_Options
*ex
;
1889 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
1890 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
1891 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
1892 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
1895 /* Determine whether a symbol is global for the purposes of splitting
1896 the symbol table into global symbols and local symbols. At least
1897 on Irix 5, this split must be between section symbols and all other
1898 symbols. On most ELF targets the split is between static symbols
1899 and externally visible symbols. */
1903 mips_elf_sym_is_global (abfd
, sym
)
1907 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
1910 /* Set the right machine number for a MIPS ELF file. This is used for
1911 both the 32-bit and the 64-bit ABI. */
1914 _bfd_mips_elf_object_p (abfd
)
1917 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
,
1918 elf_mips_mach (elf_elfheader (abfd
)->e_flags
));
1922 /* Set the right machine number for a 32-bit MIPS ELF file. */
1925 mips_elf32_object_p (abfd
)
1928 /* Irix 5 is broken. Object file symbol tables are not always
1929 sorted correctly such that local symbols precede global symbols,
1930 and the sh_info field in the symbol table is not always right. */
1931 elf_bad_symtab (abfd
) = true;
1933 return _bfd_mips_elf_object_p (abfd
);
1936 /* The final processing done just before writing out a MIPS ELF object
1937 file. This gets the MIPS architecture right based on the machine
1938 number. This is used by both the 32-bit and the 64-bit ABI. */
1942 _bfd_mips_elf_final_write_processing (abfd
, linker
)
1948 Elf_Internal_Shdr
**hdrpp
;
1952 switch (bfd_get_mach (abfd
))
1955 case bfd_mach_mips3000
:
1956 val
= E_MIPS_ARCH_1
;
1959 case bfd_mach_mips3900
:
1960 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
1963 case bfd_mach_mips6000
:
1964 val
= E_MIPS_ARCH_2
;
1967 case bfd_mach_mips4000
:
1968 val
= E_MIPS_ARCH_3
;
1971 case bfd_mach_mips4010
:
1972 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
1975 case bfd_mach_mips4100
:
1976 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
1978 /* start-sanitize-vr4320 */
1980 case bfd_mach_mips4320
:
1981 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4320
;
1983 /* end-sanitize-vr4320 */
1985 case bfd_mach_mips4650
:
1986 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
1988 /* start-sanitize-tx49 */
1990 case bfd_mach_mips4900
:
1991 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4900
;
1993 /* end-sanitize-tx49 */
1994 /* start-sanitize-vr5400 */
1996 case bfd_mach_mips5400
:
1997 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_5400
;
1999 /* end-sanitize-vr5400 */
2000 /* start-sanitize-r5900 */
2002 case bfd_mach_mips5900
:
2003 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_5900
;
2005 /* end-sanitize-r5900 */
2007 case bfd_mach_mips8000
:
2008 val
= E_MIPS_ARCH_4
;
2012 elf_elfheader (abfd
)->e_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2013 elf_elfheader (abfd
)->e_flags
|= val
;
2015 /* Set the sh_info field for .gptab sections and other appropriate
2016 info for each special section. */
2017 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
2018 i
< elf_elfheader (abfd
)->e_shnum
;
2021 switch ((*hdrpp
)->sh_type
)
2023 case SHT_MIPS_LIBLIST
:
2024 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
2026 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2029 case SHT_MIPS_GPTAB
:
2030 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2031 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2032 BFD_ASSERT (name
!= NULL
2033 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
2034 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
2035 BFD_ASSERT (sec
!= NULL
);
2036 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2039 case SHT_MIPS_CONTENT
:
2040 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2041 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2042 BFD_ASSERT (name
!= NULL
2043 && strncmp (name
, ".MIPS.content",
2044 sizeof ".MIPS.content" - 1) == 0);
2045 sec
= bfd_get_section_by_name (abfd
,
2046 name
+ sizeof ".MIPS.content" - 1);
2047 BFD_ASSERT (sec
!= NULL
);
2048 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2051 case SHT_MIPS_SYMBOL_LIB
:
2052 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
2054 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2055 sec
= bfd_get_section_by_name (abfd
, ".liblist");
2057 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2060 case SHT_MIPS_EVENTS
:
2061 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2062 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2063 BFD_ASSERT (name
!= NULL
);
2064 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
2065 sec
= bfd_get_section_by_name (abfd
,
2066 name
+ sizeof ".MIPS.events" - 1);
2069 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
2070 sizeof ".MIPS.post_rel" - 1) == 0);
2071 sec
= bfd_get_section_by_name (abfd
,
2073 + sizeof ".MIPS.post_rel" - 1));
2075 BFD_ASSERT (sec
!= NULL
);
2076 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2079 /* start-sanitize-sky */
2080 case SHT_DVP_OVERLAY_TABLE
:
2081 /* ??? This may not be technically necessary, just going with
2083 sec
= bfd_get_section_by_name (abfd
, SHNAME_DVP_OVERLAY_STRTAB
);
2085 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2087 /* end-sanitize-sky */
2092 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
2095 _bfd_mips_elf_set_private_flags (abfd
, flags
)
2099 BFD_ASSERT (!elf_flags_init (abfd
)
2100 || elf_elfheader (abfd
)->e_flags
== flags
);
2102 elf_elfheader (abfd
)->e_flags
= flags
;
2103 elf_flags_init (abfd
) = true;
2107 /* Copy backend specific data from one object module to another */
2110 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
2114 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2115 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2118 BFD_ASSERT (!elf_flags_init (obfd
)
2119 || (elf_elfheader (obfd
)->e_flags
2120 == elf_elfheader (ibfd
)->e_flags
));
2122 elf_gp (obfd
) = elf_gp (ibfd
);
2123 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
2124 elf_flags_init (obfd
) = true;
2128 /* Merge backend specific data from an object file to the output
2129 object file when linking. */
2132 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
2140 /* Check if we have the same endianess */
2141 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2142 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2146 if (bfd_big_endian (ibfd
))
2147 msg
= _("%s: compiled for a big endian system and target is little endian");
2149 msg
= _("%s: compiled for a little endian system and target is big endian");
2151 (*_bfd_error_handler
) (msg
, bfd_get_filename (ibfd
));
2153 bfd_set_error (bfd_error_wrong_format
);
2157 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2158 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2161 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2162 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
2163 old_flags
= elf_elfheader (obfd
)->e_flags
;
2165 if (! elf_flags_init (obfd
))
2167 elf_flags_init (obfd
) = true;
2168 elf_elfheader (obfd
)->e_flags
= new_flags
;
2170 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2171 && bfd_get_arch_info (obfd
)->the_default
)
2173 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
2174 bfd_get_mach (ibfd
)))
2181 /* Check flag compatibility. */
2183 new_flags
&= ~EF_MIPS_NOREORDER
;
2184 old_flags
&= ~EF_MIPS_NOREORDER
;
2186 if (new_flags
== old_flags
)
2191 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
2193 new_flags
&= ~EF_MIPS_PIC
;
2194 old_flags
&= ~EF_MIPS_PIC
;
2195 (*_bfd_error_handler
)
2196 (_("%s: linking PIC files with non-PIC files"),
2197 bfd_get_filename (ibfd
));
2201 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
2203 new_flags
&= ~EF_MIPS_CPIC
;
2204 old_flags
&= ~EF_MIPS_CPIC
;
2205 (*_bfd_error_handler
)
2206 (_("%s: linking abicalls files with non-abicalls files"),
2207 bfd_get_filename (ibfd
));
2211 /* Compare the ISA's. */
2212 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
2213 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
2215 /* If either has no machine specified, just compare the general isa's. */
2216 if ( !(new_flags
& EF_MIPS_MACH
) || !(old_flags
& EF_MIPS_MACH
))
2218 int new_isa
, old_isa
;
2220 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
2221 and -mips4 code. They will normally use the same data sizes and
2222 calling conventions. */
2224 new_isa
= elf_mips_isa (new_flags
);
2225 old_isa
= elf_mips_isa (old_flags
);
2226 if ((new_isa
== 1 || new_isa
== 2)
2227 ? (old_isa
!= 1 && old_isa
!= 2)
2228 : (old_isa
== 1 || old_isa
== 2))
2230 (*_bfd_error_handler
)
2231 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
2232 bfd_get_filename (ibfd
), new_isa
, old_isa
);
2239 (*_bfd_error_handler
)
2240 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
2241 bfd_get_filename (ibfd
),
2242 elf_mips_mach (new_flags
),
2243 elf_mips_mach (old_flags
));
2247 new_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2248 old_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2251 /* Warn about any other mismatches */
2252 if (new_flags
!= old_flags
)
2254 (*_bfd_error_handler
)
2255 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2256 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
2257 (unsigned long) old_flags
);
2263 bfd_set_error (bfd_error_bad_value
);
2270 /* Handle a MIPS specific section when reading an object file. This
2271 is called when elfcode.h finds a section with an unknown type.
2272 This routine supports both the 32-bit and 64-bit ELF ABI.
2274 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2278 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
2280 Elf_Internal_Shdr
*hdr
;
2283 /* There ought to be a place to keep ELF backend specific flags, but
2284 at the moment there isn't one. We just keep track of the
2285 sections by their name, instead. Fortunately, the ABI gives
2286 suggested names for all the MIPS specific sections, so we will
2287 probably get away with this. */
2288 switch (hdr
->sh_type
)
2290 case SHT_MIPS_LIBLIST
:
2291 if (strcmp (name
, _(".liblist")) != 0)
2295 if (strcmp (name
, ".msym") != 0)
2298 case SHT_MIPS_CONFLICT
:
2299 if (strcmp (name
, ".conflict") != 0)
2302 case SHT_MIPS_GPTAB
:
2303 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
2306 case SHT_MIPS_UCODE
:
2307 if (strcmp (name
, ".ucode") != 0)
2310 case SHT_MIPS_DEBUG
:
2311 if (strcmp (name
, ".mdebug") != 0)
2314 case SHT_MIPS_REGINFO
:
2315 if (strcmp (name
, ".reginfo") != 0
2316 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
2319 case SHT_MIPS_IFACE
:
2320 if (strcmp (name
, ".MIPS.interfaces") != 0)
2323 case SHT_MIPS_CONTENT
:
2324 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2327 case SHT_MIPS_OPTIONS
:
2328 if (strcmp (name
, ".options") != 0
2329 && strcmp (name
, ".MIPS.options") != 0)
2332 case SHT_MIPS_DWARF
:
2333 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2336 case SHT_MIPS_SYMBOL_LIB
:
2337 if (strcmp (name
, ".MIPS.symlib") != 0)
2340 case SHT_MIPS_EVENTS
:
2341 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2342 && strncmp (name
, ".MIPS.post_rel",
2343 sizeof ".MIPS.post_rel" - 1) != 0)
2346 /* start-sanitize-sky */
2347 case SHT_DVP_OVERLAY_TABLE
:
2348 if (strcmp (name
, SHNAME_DVP_OVERLAY_TABLE
) !=0)
2351 case SHT_DVP_OVERLAY
:
2352 if (strncmp (name
, SHNAME_DVP_OVERLAY_PREFIX
,
2353 sizeof (SHNAME_DVP_OVERLAY_PREFIX
) - 1) !=0)
2356 /* end-sanitize-sky */
2361 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2364 if (hdr
->sh_type
== SHT_MIPS_DEBUG
)
2366 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
2367 (bfd_get_section_flags (abfd
,
2376 /* Handle a 32-bit MIPS ELF specific section. */
2379 mips_elf32_section_from_shdr (abfd
, hdr
, name
)
2381 Elf_Internal_Shdr
*hdr
;
2384 if (! _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
))
2387 /* FIXME: We should record sh_info for a .gptab section. */
2389 /* For a .reginfo section, set the gp value in the tdata information
2390 from the contents of this section. We need the gp value while
2391 processing relocs, so we just get it now. The .reginfo section
2392 is not used in the 64-bit MIPS ELF ABI. */
2393 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2395 Elf32_External_RegInfo ext
;
2398 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
2399 (file_ptr
) 0, sizeof ext
))
2401 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
2402 elf_gp (abfd
) = s
.ri_gp_value
;
2405 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2406 set the gp value based on what we find. We may see both
2407 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2408 they should agree. */
2409 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
2411 bfd_byte
*contents
, *l
, *lend
;
2413 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
2414 if (contents
== NULL
)
2416 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
2417 (file_ptr
) 0, hdr
->sh_size
))
2423 lend
= contents
+ hdr
->sh_size
;
2424 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2426 Elf_Internal_Options intopt
;
2428 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2430 if (intopt
.kind
== ODK_REGINFO
)
2432 Elf32_RegInfo intreg
;
2434 bfd_mips_elf32_swap_reginfo_in
2436 ((Elf32_External_RegInfo
*)
2437 (l
+ sizeof (Elf_External_Options
))),
2439 elf_gp (abfd
) = intreg
.ri_gp_value
;
2449 /* Set the correct type for a MIPS ELF section. We do this by the
2450 section name, which is a hack, but ought to work. This routine is
2451 used by both the 32-bit and the 64-bit ABI. */
2454 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
2456 Elf32_Internal_Shdr
*hdr
;
2459 register const char *name
;
2461 name
= bfd_get_section_name (abfd
, sec
);
2463 if (strcmp (name
, ".liblist") == 0)
2465 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
2466 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
2467 /* The sh_link field is set in final_write_processing. */
2469 else if (strcmp (name
, ".msym") == 0)
2471 hdr
->sh_type
= SHT_MIPS_MSYM
;
2472 hdr
->sh_entsize
= 8;
2473 /* FIXME: Set the sh_info field. */
2475 else if (strcmp (name
, ".conflict") == 0)
2476 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
2477 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2479 hdr
->sh_type
= SHT_MIPS_GPTAB
;
2480 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
2481 /* The sh_info field is set in final_write_processing. */
2483 else if (strcmp (name
, ".ucode") == 0)
2484 hdr
->sh_type
= SHT_MIPS_UCODE
;
2485 else if (strcmp (name
, ".mdebug") == 0)
2487 hdr
->sh_type
= SHT_MIPS_DEBUG
;
2488 /* In a shared object on Irix 5.3, the .mdebug section has an
2489 entsize of 0. FIXME: Does this matter? */
2490 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2491 hdr
->sh_entsize
= 0;
2493 hdr
->sh_entsize
= 1;
2495 else if (strcmp (name
, ".reginfo") == 0)
2497 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2498 /* In a shared object on Irix 5.3, the .reginfo section has an
2499 entsize of 0x18. FIXME: Does this matter? */
2500 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2501 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2503 hdr
->sh_entsize
= 1;
2505 /* Force the section size to the correct value, even if the
2506 linker thinks it is larger. The link routine below will only
2507 write out this much data for .reginfo. */
2508 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf32_External_RegInfo
);
2510 else if (SGI_COMPAT (abfd
)
2511 && (strcmp (name
, ".hash") == 0
2512 || strcmp (name
, ".dynamic") == 0
2513 || strcmp (name
, ".dynstr") == 0))
2515 hdr
->sh_entsize
= 0;
2516 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2518 else if (strcmp (name
, ".got") == 0
2519 || strcmp (name
, ".sdata") == 0
2520 || strcmp (name
, ".sbss") == 0
2521 || strcmp (name
, ".lit4") == 0
2522 || strcmp (name
, ".lit8") == 0)
2523 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2524 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2526 hdr
->sh_type
= SHT_MIPS_IFACE
;
2527 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2529 else if (strcmp (name
, ".MIPS.content") == 0)
2531 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2532 /* The sh_info field is set in final_write_processing. */
2534 else if (strcmp (name
, ".options") == 0
2535 || strcmp (name
, ".MIPS.options") == 0)
2537 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2538 hdr
->sh_entsize
= 1;
2539 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2541 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2542 hdr
->sh_type
= SHT_MIPS_DWARF
;
2543 else if (strcmp (name
, ".MIPS.symlib") == 0)
2545 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2546 /* The sh_link and sh_info fields are set in
2547 final_write_processing. */
2549 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2550 || strncmp (name
, ".MIPS.post_rel",
2551 sizeof ".MIPS.post_rel" - 1) == 0)
2553 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2554 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2555 /* The sh_link field is set in final_write_processing. */
2557 /* start-sanitize-sky */
2558 else if (strcmp (name
, SHNAME_DVP_OVERLAY_TABLE
) == 0)
2560 hdr
->sh_type
= SHT_DVP_OVERLAY_TABLE
;
2561 hdr
->sh_entsize
= sizeof (Elf64_Dvp_External_Overlay
);
2562 /* The sh_link field is set in final_write_processing. */
2564 else if (strcmp (name
, SHNAME_DVP_OVERLAY_STRTAB
) == 0)
2565 hdr
->sh_type
= SHT_STRTAB
;
2566 else if (strncmp (name
, SHNAME_DVP_OVERLAY_PREFIX
,
2567 sizeof (SHNAME_DVP_OVERLAY_PREFIX
) - 1) == 0)
2568 hdr
->sh_type
= SHT_DVP_OVERLAY
;
2569 /* end-sanitize-sky */
2574 /* Given a BFD section, try to locate the corresponding ELF section
2575 index. This is used by both the 32-bit and the 64-bit ABI.
2576 Actually, it's not clear to me that the 64-bit ABI supports these,
2577 but for non-PIC objects we will certainly want support for at least
2578 the .scommon section. */
2581 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2583 Elf32_Internal_Shdr
*hdr
;
2587 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2589 *retval
= SHN_MIPS_SCOMMON
;
2592 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2594 *retval
= SHN_MIPS_ACOMMON
;
2600 /* When are writing out the .options or .MIPS.options section,
2601 remember the bytes we are writing out, so that we can install the
2602 GP value in the section_processing routine. */
2605 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2610 bfd_size_type count
;
2612 if (strcmp (section
->name
, ".options") == 0
2613 || strcmp (section
->name
, ".MIPS.options") == 0)
2617 if (elf_section_data (section
) == NULL
)
2619 section
->used_by_bfd
=
2620 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
2621 if (elf_section_data (section
) == NULL
)
2624 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
2629 if (section
->_cooked_size
!= 0)
2630 size
= section
->_cooked_size
;
2632 size
= section
->_raw_size
;
2633 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
2636 elf_section_data (section
)->tdata
= (PTR
) c
;
2639 memcpy (c
+ offset
, location
, count
);
2642 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
2646 /* Work over a section just before writing it out. This routine is
2647 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2648 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2652 _bfd_mips_elf_section_processing (abfd
, hdr
)
2654 Elf_Internal_Shdr
*hdr
;
2656 if (hdr
->bfd_section
!= NULL
)
2658 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
2660 if (strcmp (name
, ".sdata") == 0)
2662 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2663 hdr
->sh_type
= SHT_PROGBITS
;
2665 else if (strcmp (name
, ".sbss") == 0)
2667 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2668 hdr
->sh_type
= SHT_NOBITS
;
2670 else if (strcmp (name
, ".lit8") == 0
2671 || strcmp (name
, ".lit4") == 0)
2673 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2674 hdr
->sh_type
= SHT_PROGBITS
;
2676 else if (strcmp (name
, ".compact_rel") == 0)
2679 hdr
->sh_type
= SHT_PROGBITS
;
2681 else if (strcmp (name
, ".rtproc") == 0)
2683 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
2685 unsigned int adjust
;
2687 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
2689 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
2697 /* Work over a section just before writing it out. We update the GP
2698 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2699 on the value we are using. */
2702 mips_elf32_section_processing (abfd
, hdr
)
2704 Elf32_Internal_Shdr
*hdr
;
2706 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2710 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2711 BFD_ASSERT (hdr
->contents
== NULL
);
2714 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2717 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2718 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2722 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2723 && hdr
->bfd_section
!= NULL
2724 && elf_section_data (hdr
->bfd_section
) != NULL
2725 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2727 bfd_byte
*contents
, *l
, *lend
;
2729 /* We stored the section contents in the elf_section_data tdata
2730 field in the set_section_contents routine. We save the
2731 section contents so that we don't have to read them again.
2732 At this point we know that elf_gp is set, so we can look
2733 through the section contents to see if there is an
2734 ODK_REGINFO structure. */
2736 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2738 lend
= contents
+ hdr
->sh_size
;
2739 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2741 Elf_Internal_Options intopt
;
2743 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2745 if (intopt
.kind
== ODK_REGINFO
)
2752 + sizeof (Elf_External_Options
)
2753 + (sizeof (Elf32_External_RegInfo
) - 4)),
2756 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
2757 if (bfd_write (buf
, 1, 4, abfd
) != 4)
2764 return _bfd_mips_elf_section_processing (abfd
, hdr
);
2767 /* MIPS ELF uses two common sections. One is the usual one, and the
2768 other is for small objects. All the small objects are kept
2769 together, and then referenced via the gp pointer, which yields
2770 faster assembler code. This is what we use for the small common
2771 section. This approach is copied from ecoff.c. */
2772 static asection mips_elf_scom_section
;
2773 static asymbol mips_elf_scom_symbol
;
2774 static asymbol
*mips_elf_scom_symbol_ptr
;
2776 /* MIPS ELF also uses an acommon section, which represents an
2777 allocated common symbol which may be overridden by a
2778 definition in a shared library. */
2779 static asection mips_elf_acom_section
;
2780 static asymbol mips_elf_acom_symbol
;
2781 static asymbol
*mips_elf_acom_symbol_ptr
;
2783 /* The Irix 5 support uses two virtual sections, which represent
2784 text/data symbols defined in dynamic objects. */
2785 static asection mips_elf_text_section
;
2786 static asection
*mips_elf_text_section_ptr
;
2787 static asymbol mips_elf_text_symbol
;
2788 static asymbol
*mips_elf_text_symbol_ptr
;
2790 static asection mips_elf_data_section
;
2791 static asection
*mips_elf_data_section_ptr
;
2792 static asymbol mips_elf_data_symbol
;
2793 static asymbol
*mips_elf_data_symbol_ptr
;
2795 /* Handle the special MIPS section numbers that a symbol may use.
2796 This is used for both the 32-bit and the 64-bit ABI. */
2799 _bfd_mips_elf_symbol_processing (abfd
, asym
)
2803 elf_symbol_type
*elfsym
;
2805 elfsym
= (elf_symbol_type
*) asym
;
2806 switch (elfsym
->internal_elf_sym
.st_shndx
)
2808 case SHN_MIPS_ACOMMON
:
2809 /* This section is used in a dynamically linked executable file.
2810 It is an allocated common section. The dynamic linker can
2811 either resolve these symbols to something in a shared
2812 library, or it can just leave them here. For our purposes,
2813 we can consider these symbols to be in a new section. */
2814 if (mips_elf_acom_section
.name
== NULL
)
2816 /* Initialize the acommon section. */
2817 mips_elf_acom_section
.name
= ".acommon";
2818 mips_elf_acom_section
.flags
= SEC_ALLOC
;
2819 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
2820 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
2821 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
2822 mips_elf_acom_symbol
.name
= ".acommon";
2823 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
2824 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
2825 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
2827 asym
->section
= &mips_elf_acom_section
;
2831 /* Common symbols less than the GP size are automatically
2832 treated as SHN_MIPS_SCOMMON symbols. */
2833 if (asym
->value
> elf_gp_size (abfd
))
2836 case SHN_MIPS_SCOMMON
:
2837 if (mips_elf_scom_section
.name
== NULL
)
2839 /* Initialize the small common section. */
2840 mips_elf_scom_section
.name
= ".scommon";
2841 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
2842 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
2843 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
2844 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
2845 mips_elf_scom_symbol
.name
= ".scommon";
2846 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2847 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
2848 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
2850 asym
->section
= &mips_elf_scom_section
;
2851 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2854 case SHN_MIPS_SUNDEFINED
:
2855 asym
->section
= bfd_und_section_ptr
;
2858 #if 0 /* for SGI_COMPAT */
2860 asym
->section
= mips_elf_text_section_ptr
;
2864 asym
->section
= mips_elf_data_section_ptr
;
2870 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
2874 mips_elf_additional_program_headers (abfd
)
2882 if (! SGI_COMPAT (abfd
))
2885 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2886 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2888 /* We need a PT_MIPS_REGINFO segment. */
2892 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2893 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2895 /* We need a PT_MIPS_RTPROC segment. */
2902 /* Modify the segment map for an Irix 5 executable. */
2905 mips_elf_modify_segment_map (abfd
)
2909 struct elf_segment_map
*m
, **pm
;
2911 if (! SGI_COMPAT (abfd
))
2914 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
2916 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2917 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2919 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2920 if (m
->p_type
== PT_MIPS_REGINFO
)
2924 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2928 m
->p_type
= PT_MIPS_REGINFO
;
2932 /* We want to put it after the PHDR and INTERP segments. */
2933 pm
= &elf_tdata (abfd
)->segment_map
;
2935 && ((*pm
)->p_type
== PT_PHDR
2936 || (*pm
)->p_type
== PT_INTERP
))
2944 /* If there are .dynamic and .mdebug sections, we make a room for
2945 the RTPROC header. FIXME: Rewrite without section names. */
2946 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
2947 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2948 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2950 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2951 if (m
->p_type
== PT_MIPS_RTPROC
)
2955 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2959 m
->p_type
= PT_MIPS_RTPROC
;
2961 s
= bfd_get_section_by_name (abfd
, ".rtproc");
2966 m
->p_flags_valid
= 1;
2974 /* We want to put it after the DYNAMIC segment. */
2975 pm
= &elf_tdata (abfd
)->segment_map
;
2976 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
2986 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
2987 .dynsym, and .hash sections, and everything in between. */
2988 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
2989 if ((*pm
)->p_type
== PT_DYNAMIC
)
2994 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
2996 static const char *sec_names
[] =
2997 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
3000 struct elf_segment_map
*n
;
3004 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
3006 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
3007 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3013 sz
= s
->_cooked_size
;
3016 if (high
< s
->vma
+ sz
)
3022 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3023 if ((s
->flags
& SEC_LOAD
) != 0
3026 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3030 n
= ((struct elf_segment_map
*)
3031 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
3038 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3040 if ((s
->flags
& SEC_LOAD
) != 0
3043 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3057 /* The structure of the runtime procedure descriptor created by the
3058 loader for use by the static exception system. */
3060 typedef struct runtime_pdr
{
3061 bfd_vma adr
; /* memory address of start of procedure */
3062 long regmask
; /* save register mask */
3063 long regoffset
; /* save register offset */
3064 long fregmask
; /* save floating point register mask */
3065 long fregoffset
; /* save floating point register offset */
3066 long frameoffset
; /* frame size */
3067 short framereg
; /* frame pointer register */
3068 short pcreg
; /* offset or reg of return pc */
3069 long irpss
; /* index into the runtime string table */
3071 struct exception_info
*exception_info
;/* pointer to exception array */
3073 #define cbRPDR sizeof(RPDR)
3074 #define rpdNil ((pRPDR) 0)
3076 /* Swap RPDR (runtime procedure table entry) for output. */
3078 static void ecoff_swap_rpdr_out
3079 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
3082 ecoff_swap_rpdr_out (abfd
, in
, ex
)
3085 struct rpdr_ext
*ex
;
3087 /* ecoff_put_off was defined in ecoffswap.h. */
3088 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
3089 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
3090 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
3091 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
3092 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
3093 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
3095 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
3096 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
3098 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
3100 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
3104 /* Read ECOFF debugging information from a .mdebug section into a
3105 ecoff_debug_info structure. */
3108 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
3111 struct ecoff_debug_info
*debug
;
3114 const struct ecoff_debug_swap
*swap
;
3115 char *ext_hdr
= NULL
;
3117 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3119 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
3120 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
3123 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
3124 swap
->external_hdr_size
)
3128 symhdr
= &debug
->symbolic_header
;
3129 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
3131 /* The symbolic header contains absolute file offsets and sizes to
3133 #define READ(ptr, offset, count, size, type) \
3134 if (symhdr->count == 0) \
3135 debug->ptr = NULL; \
3138 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
3139 if (debug->ptr == NULL) \
3140 goto error_return; \
3141 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3142 || (bfd_read (debug->ptr, size, symhdr->count, \
3143 abfd) != size * symhdr->count)) \
3144 goto error_return; \
3147 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
3148 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
3149 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
3150 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
3151 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
3152 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
3154 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
3155 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
3156 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
3157 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
3158 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
3162 debug
->adjust
= NULL
;
3167 if (ext_hdr
!= NULL
)
3169 if (debug
->line
!= NULL
)
3171 if (debug
->external_dnr
!= NULL
)
3172 free (debug
->external_dnr
);
3173 if (debug
->external_pdr
!= NULL
)
3174 free (debug
->external_pdr
);
3175 if (debug
->external_sym
!= NULL
)
3176 free (debug
->external_sym
);
3177 if (debug
->external_opt
!= NULL
)
3178 free (debug
->external_opt
);
3179 if (debug
->external_aux
!= NULL
)
3180 free (debug
->external_aux
);
3181 if (debug
->ss
!= NULL
)
3183 if (debug
->ssext
!= NULL
)
3184 free (debug
->ssext
);
3185 if (debug
->external_fdr
!= NULL
)
3186 free (debug
->external_fdr
);
3187 if (debug
->external_rfd
!= NULL
)
3188 free (debug
->external_rfd
);
3189 if (debug
->external_ext
!= NULL
)
3190 free (debug
->external_ext
);
3194 /* MIPS ELF local labels start with '$', not 'L'. */
3198 mips_elf_is_local_label_name (abfd
, name
)
3205 /* On Irix 6, the labels go back to starting with '.', so we accept
3206 the generic ELF local label syntax as well. */
3207 return _bfd_elf_is_local_label_name (abfd
, name
);
3210 /* MIPS ELF uses a special find_nearest_line routine in order the
3211 handle the ECOFF debugging information. */
3213 struct mips_elf_find_line
3215 struct ecoff_debug_info d
;
3216 struct ecoff_find_line i
;
3220 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
3221 functionname_ptr
, line_ptr
)
3226 const char **filename_ptr
;
3227 const char **functionname_ptr
;
3228 unsigned int *line_ptr
;
3232 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3233 filename_ptr
, functionname_ptr
,
3237 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
3241 struct mips_elf_find_line
*fi
;
3242 const struct ecoff_debug_swap
* const swap
=
3243 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3245 /* If we are called during a link, mips_elf_final_link may have
3246 cleared the SEC_HAS_CONTENTS field. We force it back on here
3247 if appropriate (which it normally will be). */
3248 origflags
= msec
->flags
;
3249 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
3250 msec
->flags
|= SEC_HAS_CONTENTS
;
3252 fi
= elf_tdata (abfd
)->find_line_info
;
3255 bfd_size_type external_fdr_size
;
3258 struct fdr
*fdr_ptr
;
3260 fi
= ((struct mips_elf_find_line
*)
3261 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
3264 msec
->flags
= origflags
;
3268 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
3270 msec
->flags
= origflags
;
3274 /* Swap in the FDR information. */
3275 fi
->d
.fdr
= ((struct fdr
*)
3277 (fi
->d
.symbolic_header
.ifdMax
*
3278 sizeof (struct fdr
))));
3279 if (fi
->d
.fdr
== NULL
)
3281 msec
->flags
= origflags
;
3284 external_fdr_size
= swap
->external_fdr_size
;
3285 fdr_ptr
= fi
->d
.fdr
;
3286 fraw_src
= (char *) fi
->d
.external_fdr
;
3287 fraw_end
= (fraw_src
3288 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
3289 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
3290 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
3292 elf_tdata (abfd
)->find_line_info
= fi
;
3294 /* Note that we don't bother to ever free this information.
3295 find_nearest_line is either called all the time, as in
3296 objdump -l, so the information should be saved, or it is
3297 rarely called, as in ld error messages, so the memory
3298 wasted is unimportant. Still, it would probably be a
3299 good idea for free_cached_info to throw it away. */
3302 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
3303 &fi
->i
, filename_ptr
, functionname_ptr
,
3306 msec
->flags
= origflags
;
3310 msec
->flags
= origflags
;
3313 /* Fall back on the generic ELF find_nearest_line routine. */
3315 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
3316 filename_ptr
, functionname_ptr
,
3320 /* The mips16 compiler uses a couple of special sections to handle
3321 floating point arguments.
3323 Section names that look like .mips16.fn.FNNAME contain stubs that
3324 copy floating point arguments from the fp regs to the gp regs and
3325 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3326 call should be redirected to the stub instead. If no 32 bit
3327 function calls FNNAME, the stub should be discarded. We need to
3328 consider any reference to the function, not just a call, because
3329 if the address of the function is taken we will need the stub,
3330 since the address might be passed to a 32 bit function.
3332 Section names that look like .mips16.call.FNNAME contain stubs
3333 that copy floating point arguments from the gp regs to the fp
3334 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3335 then any 16 bit function that calls FNNAME should be redirected
3336 to the stub instead. If FNNAME is not a 32 bit function, the
3337 stub should be discarded.
3339 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3340 which call FNNAME and then copy the return value from the fp regs
3341 to the gp regs. These stubs store the return value in $18 while
3342 calling FNNAME; any function which might call one of these stubs
3343 must arrange to save $18 around the call. (This case is not
3344 needed for 32 bit functions that call 16 bit functions, because
3345 16 bit functions always return floating point values in both
3348 Note that in all cases FNNAME might be defined statically.
3349 Therefore, FNNAME is not used literally. Instead, the relocation
3350 information will indicate which symbol the section is for.
3352 We record any stubs that we find in the symbol table. */
3354 #define FN_STUB ".mips16.fn."
3355 #define CALL_STUB ".mips16.call."
3356 #define CALL_FP_STUB ".mips16.call.fp."
3358 /* The MIPS ELF linker needs additional information for each symbol in
3359 the global hash table. */
3361 struct mips_elf_link_hash_entry
3363 struct elf_link_hash_entry root
;
3365 /* External symbol information. */
3368 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
3369 unsigned int mips_32_relocs
;
3371 /* If there is a stub that 32 bit functions should use to call this
3372 16 bit function, this points to the section containing the stub. */
3375 /* Whether we need the fn_stub; this is set if this symbol appears
3376 in any relocs other than a 16 bit call. */
3377 boolean need_fn_stub
;
3379 /* If there is a stub that 16 bit functions should use to call this
3380 32 bit function, this points to the section containing the stub. */
3381 asection
*call_stub
;
3383 /* This is like the call_stub field, but it is used if the function
3384 being called returns a floating point value. */
3385 asection
*call_fp_stub
;
3388 /* MIPS ELF linker hash table. */
3390 struct mips_elf_link_hash_table
3392 struct elf_link_hash_table root
;
3393 /* String section indices for the dynamic section symbols. */
3394 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
3395 /* The number of .rtproc entries. */
3396 bfd_size_type procedure_count
;
3397 /* The size of the .compact_rel section (if SGI_COMPAT). */
3398 bfd_size_type compact_rel_size
;
3399 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3400 entry is set to the address of __rld_obj_head as in Irix 5. */
3401 boolean use_rld_obj_head
;
3402 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3404 /* This is set if we see any mips16 stub sections. */
3405 boolean mips16_stubs_seen
;
3408 /* Look up an entry in a MIPS ELF linker hash table. */
3410 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3411 ((struct mips_elf_link_hash_entry *) \
3412 elf_link_hash_lookup (&(table)->root, (string), (create), \
3415 /* Traverse a MIPS ELF linker hash table. */
3417 #define mips_elf_link_hash_traverse(table, func, info) \
3418 (elf_link_hash_traverse \
3420 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3423 /* Get the MIPS ELF linker hash table from a link_info structure. */
3425 #define mips_elf_hash_table(p) \
3426 ((struct mips_elf_link_hash_table *) ((p)->hash))
3428 static boolean mips_elf_output_extsym
3429 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3431 /* Create an entry in a MIPS ELF linker hash table. */
3433 static struct bfd_hash_entry
*
3434 mips_elf_link_hash_newfunc (entry
, table
, string
)
3435 struct bfd_hash_entry
*entry
;
3436 struct bfd_hash_table
*table
;
3439 struct mips_elf_link_hash_entry
*ret
=
3440 (struct mips_elf_link_hash_entry
*) entry
;
3442 /* Allocate the structure if it has not already been allocated by a
3444 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3445 ret
= ((struct mips_elf_link_hash_entry
*)
3446 bfd_hash_allocate (table
,
3447 sizeof (struct mips_elf_link_hash_entry
)));
3448 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3449 return (struct bfd_hash_entry
*) ret
;
3451 /* Call the allocation method of the superclass. */
3452 ret
= ((struct mips_elf_link_hash_entry
*)
3453 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3455 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3457 /* Set local fields. */
3458 memset (&ret
->esym
, 0, sizeof (EXTR
));
3459 /* We use -2 as a marker to indicate that the information has
3460 not been set. -1 means there is no associated ifd. */
3462 ret
->mips_32_relocs
= 0;
3463 ret
->fn_stub
= NULL
;
3464 ret
->need_fn_stub
= false;
3465 ret
->call_stub
= NULL
;
3466 ret
->call_fp_stub
= NULL
;
3469 return (struct bfd_hash_entry
*) ret
;
3472 /* Create a MIPS ELF linker hash table. */
3474 static struct bfd_link_hash_table
*
3475 mips_elf_link_hash_table_create (abfd
)
3478 struct mips_elf_link_hash_table
*ret
;
3481 ret
= ((struct mips_elf_link_hash_table
*)
3482 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
3483 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
3486 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3487 mips_elf_link_hash_newfunc
))
3489 bfd_release (abfd
, ret
);
3493 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
3494 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
3495 ret
->procedure_count
= 0;
3496 ret
->compact_rel_size
= 0;
3497 ret
->use_rld_obj_head
= false;
3499 ret
->mips16_stubs_seen
= false;
3501 return &ret
->root
.root
;
3504 /* Hook called by the linker routine which adds symbols from an object
3505 file. We must handle the special MIPS section numbers here. */
3509 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3511 struct bfd_link_info
*info
;
3512 const Elf_Internal_Sym
*sym
;
3518 if (SGI_COMPAT (abfd
)
3519 && (abfd
->flags
& DYNAMIC
) != 0
3520 && strcmp (*namep
, "_rld_new_interface") == 0)
3522 /* Skip Irix 5 rld entry name. */
3527 switch (sym
->st_shndx
)
3530 /* Common symbols less than the GP size are automatically
3531 treated as SHN_MIPS_SCOMMON symbols. */
3532 if (sym
->st_size
> elf_gp_size (abfd
))
3535 case SHN_MIPS_SCOMMON
:
3536 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3537 (*secp
)->flags
|= SEC_IS_COMMON
;
3538 *valp
= sym
->st_size
;
3542 /* This section is used in a shared object. */
3543 if (mips_elf_text_section_ptr
== NULL
)
3545 /* Initialize the section. */
3546 mips_elf_text_section
.name
= ".text";
3547 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
3548 mips_elf_text_section
.output_section
= NULL
;
3549 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
3550 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
3551 mips_elf_text_symbol
.name
= ".text";
3552 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
3553 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
3554 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
3555 mips_elf_text_section_ptr
= &mips_elf_text_section
;
3557 /* This code used to do *secp = bfd_und_section_ptr if
3558 info->shared. I don't know why, and that doesn't make sense,
3559 so I took it out. */
3560 *secp
= mips_elf_text_section_ptr
;
3563 case SHN_MIPS_ACOMMON
:
3564 /* Fall through. XXX Can we treat this as allocated data? */
3566 /* This section is used in a shared object. */
3567 if (mips_elf_data_section_ptr
== NULL
)
3569 /* Initialize the section. */
3570 mips_elf_data_section
.name
= ".data";
3571 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
3572 mips_elf_data_section
.output_section
= NULL
;
3573 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
3574 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
3575 mips_elf_data_symbol
.name
= ".data";
3576 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
3577 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
3578 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
3579 mips_elf_data_section_ptr
= &mips_elf_data_section
;
3581 /* This code used to do *secp = bfd_und_section_ptr if
3582 info->shared. I don't know why, and that doesn't make sense,
3583 so I took it out. */
3584 *secp
= mips_elf_data_section_ptr
;
3587 case SHN_MIPS_SUNDEFINED
:
3588 *secp
= bfd_und_section_ptr
;
3592 if (SGI_COMPAT (abfd
)
3594 && info
->hash
->creator
== abfd
->xvec
3595 && strcmp (*namep
, "__rld_obj_head") == 0)
3597 struct elf_link_hash_entry
*h
;
3599 /* Mark __rld_obj_head as dynamic. */
3601 if (! (_bfd_generic_link_add_one_symbol
3602 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3603 (bfd_vma
) *valp
, (const char *) NULL
, false,
3604 get_elf_backend_data (abfd
)->collect
,
3605 (struct bfd_link_hash_entry
**) &h
)))
3607 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
3608 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3609 h
->type
= STT_OBJECT
;
3611 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3614 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3617 /* If this is a mips16 text symbol, add 1 to the value to make it
3618 odd. This will cause something like .word SYM to come up with
3619 the right value when it is loaded into the PC. */
3620 if (sym
->st_other
== STO_MIPS16
)
3626 /* Structure used to pass information to mips_elf_output_extsym. */
3631 struct bfd_link_info
*info
;
3632 struct ecoff_debug_info
*debug
;
3633 const struct ecoff_debug_swap
*swap
;
3637 /* This routine is used to write out ECOFF debugging external symbol
3638 information. It is called via mips_elf_link_hash_traverse. The
3639 ECOFF external symbol information must match the ELF external
3640 symbol information. Unfortunately, at this point we don't know
3641 whether a symbol is required by reloc information, so the two
3642 tables may wind up being different. We must sort out the external
3643 symbol information before we can set the final size of the .mdebug
3644 section, and we must set the size of the .mdebug section before we
3645 can relocate any sections, and we can't know which symbols are
3646 required by relocation until we relocate the sections.
3647 Fortunately, it is relatively unlikely that any symbol will be
3648 stripped but required by a reloc. In particular, it can not happen
3649 when generating a final executable. */
3652 mips_elf_output_extsym (h
, data
)
3653 struct mips_elf_link_hash_entry
*h
;
3656 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
3658 asection
*sec
, *output_section
;
3660 if (h
->root
.indx
== -2)
3662 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3663 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
3664 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3665 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
3667 else if (einfo
->info
->strip
== strip_all
3668 || (einfo
->info
->strip
== strip_some
3669 && bfd_hash_lookup (einfo
->info
->keep_hash
,
3670 h
->root
.root
.root
.string
,
3671 false, false) == NULL
))
3679 if (h
->esym
.ifd
== -2)
3682 h
->esym
.cobol_main
= 0;
3683 h
->esym
.weakext
= 0;
3684 h
->esym
.reserved
= 0;
3685 h
->esym
.ifd
= ifdNil
;
3686 h
->esym
.asym
.value
= 0;
3687 h
->esym
.asym
.st
= stGlobal
;
3689 if (SGI_COMPAT (einfo
->abfd
)
3690 && (h
->root
.root
.type
== bfd_link_hash_undefined
3691 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
3695 /* Use undefined class. Also, set class and type for some
3697 name
= h
->root
.root
.root
.string
;
3698 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
3699 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
3701 h
->esym
.asym
.sc
= scData
;
3702 h
->esym
.asym
.st
= stLabel
;
3703 h
->esym
.asym
.value
= 0;
3705 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
3707 h
->esym
.asym
.sc
= scAbs
;
3708 h
->esym
.asym
.st
= stLabel
;
3709 h
->esym
.asym
.value
=
3710 mips_elf_hash_table (einfo
->info
)->procedure_count
;
3712 else if (strcmp (name
, "_gp_disp") == 0)
3714 h
->esym
.asym
.sc
= scAbs
;
3715 h
->esym
.asym
.st
= stLabel
;
3716 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
3719 h
->esym
.asym
.sc
= scUndefined
;
3721 else if (h
->root
.root
.type
!= bfd_link_hash_defined
3722 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
3723 h
->esym
.asym
.sc
= scAbs
;
3728 sec
= h
->root
.root
.u
.def
.section
;
3729 output_section
= sec
->output_section
;
3731 /* When making a shared library and symbol h is the one from
3732 the another shared library, OUTPUT_SECTION may be null. */
3733 if (output_section
== NULL
)
3734 h
->esym
.asym
.sc
= scUndefined
;
3737 name
= bfd_section_name (output_section
->owner
, output_section
);
3739 if (strcmp (name
, ".text") == 0)
3740 h
->esym
.asym
.sc
= scText
;
3741 else if (strcmp (name
, ".data") == 0)
3742 h
->esym
.asym
.sc
= scData
;
3743 else if (strcmp (name
, ".sdata") == 0)
3744 h
->esym
.asym
.sc
= scSData
;
3745 else if (strcmp (name
, ".rodata") == 0
3746 || strcmp (name
, ".rdata") == 0)
3747 h
->esym
.asym
.sc
= scRData
;
3748 else if (strcmp (name
, ".bss") == 0)
3749 h
->esym
.asym
.sc
= scBss
;
3750 else if (strcmp (name
, ".sbss") == 0)
3751 h
->esym
.asym
.sc
= scSBss
;
3752 else if (strcmp (name
, ".init") == 0)
3753 h
->esym
.asym
.sc
= scInit
;
3754 else if (strcmp (name
, ".fini") == 0)
3755 h
->esym
.asym
.sc
= scFini
;
3757 h
->esym
.asym
.sc
= scAbs
;
3761 h
->esym
.asym
.reserved
= 0;
3762 h
->esym
.asym
.index
= indexNil
;
3765 if (h
->root
.root
.type
== bfd_link_hash_common
)
3766 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
3767 else if (h
->root
.root
.type
== bfd_link_hash_defined
3768 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3770 if (h
->esym
.asym
.sc
== scCommon
)
3771 h
->esym
.asym
.sc
= scBss
;
3772 else if (h
->esym
.asym
.sc
== scSCommon
)
3773 h
->esym
.asym
.sc
= scSBss
;
3775 sec
= h
->root
.root
.u
.def
.section
;
3776 output_section
= sec
->output_section
;
3777 if (output_section
!= NULL
)
3778 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
3779 + sec
->output_offset
3780 + output_section
->vma
);
3782 h
->esym
.asym
.value
= 0;
3784 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3786 /* Set type and value for a symbol with a function stub. */
3787 h
->esym
.asym
.st
= stProc
;
3788 sec
= h
->root
.root
.u
.def
.section
;
3790 h
->esym
.asym
.value
= 0;
3793 output_section
= sec
->output_section
;
3794 if (output_section
!= NULL
)
3795 h
->esym
.asym
.value
= (h
->root
.plt_offset
3796 + sec
->output_offset
3797 + output_section
->vma
);
3799 h
->esym
.asym
.value
= 0;
3806 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
3807 h
->root
.root
.root
.string
,
3810 einfo
->failed
= true;
3817 /* Create a runtime procedure table from the .mdebug section. */
3820 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
3823 struct bfd_link_info
*info
;
3825 struct ecoff_debug_info
*debug
;
3827 const struct ecoff_debug_swap
*swap
;
3828 HDRR
*hdr
= &debug
->symbolic_header
;
3830 struct rpdr_ext
*erp
;
3832 struct pdr_ext
*epdr
;
3833 struct sym_ext
*esym
;
3836 unsigned long size
, count
;
3837 unsigned long sindex
;
3841 const char *no_name_func
= _("static procedure (no name)");
3849 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3851 sindex
= strlen (no_name_func
) + 1;
3852 count
= hdr
->ipdMax
;
3855 size
= swap
->external_pdr_size
;
3857 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
3861 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
3864 size
= sizeof (RPDR
);
3865 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
3869 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
3873 count
= hdr
->isymMax
;
3874 size
= swap
->external_sym_size
;
3875 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
3879 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
3882 count
= hdr
->issMax
;
3883 ss
= (char *) bfd_malloc (count
);
3886 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
3889 count
= hdr
->ipdMax
;
3890 for (i
= 0; i
< count
; i
++, rp
++)
3892 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
3893 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
3894 rp
->adr
= sym
.value
;
3895 rp
->regmask
= pdr
.regmask
;
3896 rp
->regoffset
= pdr
.regoffset
;
3897 rp
->fregmask
= pdr
.fregmask
;
3898 rp
->fregoffset
= pdr
.fregoffset
;
3899 rp
->frameoffset
= pdr
.frameoffset
;
3900 rp
->framereg
= pdr
.framereg
;
3901 rp
->pcreg
= pdr
.pcreg
;
3903 sv
[i
] = ss
+ sym
.iss
;
3904 sindex
+= strlen (sv
[i
]) + 1;
3908 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
3909 size
= BFD_ALIGN (size
, 16);
3910 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
3913 mips_elf_hash_table (info
)->procedure_count
= 0;
3917 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
3919 erp
= (struct rpdr_ext
*) rtproc
;
3920 memset (erp
, 0, sizeof (struct rpdr_ext
));
3922 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
3923 strcpy (str
, no_name_func
);
3924 str
+= strlen (no_name_func
) + 1;
3925 for (i
= 0; i
< count
; i
++)
3927 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
3928 strcpy (str
, sv
[i
]);
3929 str
+= strlen (sv
[i
]) + 1;
3931 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
3933 /* Set the size and contents of .rtproc section. */
3934 s
->_raw_size
= size
;
3935 s
->contents
= (bfd_byte
*) rtproc
;
3937 /* Skip this section later on (I don't think this currently
3938 matters, but someday it might). */
3939 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
3968 /* A comparison routine used to sort .gptab entries. */
3971 gptab_compare (p1
, p2
)
3975 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
3976 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
3978 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
3981 /* We need to use a special link routine to handle the .reginfo and
3982 the .mdebug sections. We need to merge all instances of these
3983 sections together, not write them all out sequentially. */
3986 mips_elf_final_link (abfd
, info
)
3988 struct bfd_link_info
*info
;
3992 struct bfd_link_order
*p
;
3993 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
3994 asection
*rtproc_sec
;
3995 Elf32_RegInfo reginfo
;
3996 struct ecoff_debug_info debug
;
3997 const struct ecoff_debug_swap
*swap
3998 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3999 HDRR
*symhdr
= &debug
.symbolic_header
;
4000 PTR mdebug_handle
= NULL
;
4002 /* Drop the .options section, since it has special semantics which I
4003 haven't bothered to figure out. */
4004 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
4006 if (strcmp ((*secpp
)->name
, ".options") == 0)
4008 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
4009 if (p
->type
== bfd_indirect_link_order
)
4010 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
4011 (*secpp
)->link_order_head
= NULL
;
4012 *secpp
= (*secpp
)->next
;
4013 --abfd
->section_count
;
4018 /* Get a value for the GP register. */
4019 if (elf_gp (abfd
) == 0)
4021 struct bfd_link_hash_entry
*h
;
4023 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4024 if (h
!= (struct bfd_link_hash_entry
*) NULL
4025 && h
->type
== bfd_link_hash_defined
)
4026 elf_gp (abfd
) = (h
->u
.def
.value
4027 + h
->u
.def
.section
->output_section
->vma
4028 + h
->u
.def
.section
->output_offset
);
4029 else if (info
->relocateable
)
4033 /* Make up a value. */
4035 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4038 && (strcmp (o
->name
, ".sbss") == 0
4039 || strcmp (o
->name
, ".sdata") == 0
4040 || strcmp (o
->name
, ".lit4") == 0
4041 || strcmp (o
->name
, ".lit8") == 0))
4044 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
4048 /* If the relocate_section function needs to do a reloc
4049 involving the GP value, it should make a reloc_dangerous
4050 callback to warn that GP is not defined. */
4054 /* Go through the sections and collect the .reginfo and .mdebug
4058 gptab_data_sec
= NULL
;
4059 gptab_bss_sec
= NULL
;
4060 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4062 if (strcmp (o
->name
, ".reginfo") == 0)
4064 memset (®info
, 0, sizeof reginfo
);
4066 /* We have found the .reginfo section in the output file.
4067 Look through all the link_orders comprising it and merge
4068 the information together. */
4069 for (p
= o
->link_order_head
;
4070 p
!= (struct bfd_link_order
*) NULL
;
4073 asection
*input_section
;
4075 Elf32_External_RegInfo ext
;
4078 if (p
->type
!= bfd_indirect_link_order
)
4080 if (p
->type
== bfd_fill_link_order
)
4085 input_section
= p
->u
.indirect
.section
;
4086 input_bfd
= input_section
->owner
;
4088 /* The linker emulation code has probably clobbered the
4089 size to be zero bytes. */
4090 if (input_section
->_raw_size
== 0)
4091 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4093 if (! bfd_get_section_contents (input_bfd
, input_section
,
4099 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
4101 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
4102 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
4103 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
4104 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
4105 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
4107 /* ri_gp_value is set by the function
4108 mips_elf32_section_processing when the section is
4109 finally written out. */
4111 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4112 elf_link_input_bfd ignores this section. */
4113 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4116 /* Force the section size to the value we want. */
4117 o
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4119 /* Skip this section later on (I don't think this currently
4120 matters, but someday it might). */
4121 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4126 if (strcmp (o
->name
, ".mdebug") == 0)
4128 struct extsym_info einfo
;
4130 /* We have found the .mdebug section in the output file.
4131 Look through all the link_orders comprising it and merge
4132 the information together. */
4133 symhdr
->magic
= swap
->sym_magic
;
4134 /* FIXME: What should the version stamp be? */
4136 symhdr
->ilineMax
= 0;
4140 symhdr
->isymMax
= 0;
4141 symhdr
->ioptMax
= 0;
4142 symhdr
->iauxMax
= 0;
4144 symhdr
->issExtMax
= 0;
4147 symhdr
->iextMax
= 0;
4149 /* We accumulate the debugging information itself in the
4150 debug_info structure. */
4152 debug
.external_dnr
= NULL
;
4153 debug
.external_pdr
= NULL
;
4154 debug
.external_sym
= NULL
;
4155 debug
.external_opt
= NULL
;
4156 debug
.external_aux
= NULL
;
4158 debug
.ssext
= debug
.ssext_end
= NULL
;
4159 debug
.external_fdr
= NULL
;
4160 debug
.external_rfd
= NULL
;
4161 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4163 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4164 if (mdebug_handle
== (PTR
) NULL
)
4167 if (SGI_COMPAT (abfd
))
4173 static const char * const name
[] =
4174 { ".text", ".init", ".fini", ".data",
4175 ".rodata", ".sdata", ".sbss", ".bss" };
4176 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
4177 scRData
, scSData
, scSBss
, scBss
};
4180 esym
.cobol_main
= 0;
4184 esym
.asym
.iss
= issNil
;
4185 esym
.asym
.st
= stLocal
;
4186 esym
.asym
.reserved
= 0;
4187 esym
.asym
.index
= indexNil
;
4189 for (i
= 0; i
< 8; i
++)
4191 esym
.asym
.sc
= sc
[i
];
4192 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4195 esym
.asym
.value
= s
->vma
;
4196 last
= s
->vma
+ s
->_raw_size
;
4199 esym
.asym
.value
= last
;
4201 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4207 for (p
= o
->link_order_head
;
4208 p
!= (struct bfd_link_order
*) NULL
;
4211 asection
*input_section
;
4213 const struct ecoff_debug_swap
*input_swap
;
4214 struct ecoff_debug_info input_debug
;
4218 if (p
->type
!= bfd_indirect_link_order
)
4220 if (p
->type
== bfd_fill_link_order
)
4225 input_section
= p
->u
.indirect
.section
;
4226 input_bfd
= input_section
->owner
;
4228 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4229 || (get_elf_backend_data (input_bfd
)
4230 ->elf_backend_ecoff_debug_swap
) == NULL
)
4232 /* I don't know what a non MIPS ELF bfd would be
4233 doing with a .mdebug section, but I don't really
4234 want to deal with it. */
4238 input_swap
= (get_elf_backend_data (input_bfd
)
4239 ->elf_backend_ecoff_debug_swap
);
4241 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
4243 /* The ECOFF linking code expects that we have already
4244 read in the debugging information and set up an
4245 ecoff_debug_info structure, so we do that now. */
4246 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
4250 if (! (bfd_ecoff_debug_accumulate
4251 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
4252 &input_debug
, input_swap
, info
)))
4255 /* Loop through the external symbols. For each one with
4256 interesting information, try to find the symbol in
4257 the linker global hash table and save the information
4258 for the output external symbols. */
4259 eraw_src
= input_debug
.external_ext
;
4260 eraw_end
= (eraw_src
4261 + (input_debug
.symbolic_header
.iextMax
4262 * input_swap
->external_ext_size
));
4264 eraw_src
< eraw_end
;
4265 eraw_src
+= input_swap
->external_ext_size
)
4269 struct mips_elf_link_hash_entry
*h
;
4271 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4272 if (ext
.asym
.sc
== scNil
4273 || ext
.asym
.sc
== scUndefined
4274 || ext
.asym
.sc
== scSUndefined
)
4277 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4278 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
4279 name
, false, false, true);
4280 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4286 < input_debug
.symbolic_header
.ifdMax
);
4287 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4293 /* Free up the information we just read. */
4294 free (input_debug
.line
);
4295 free (input_debug
.external_dnr
);
4296 free (input_debug
.external_pdr
);
4297 free (input_debug
.external_sym
);
4298 free (input_debug
.external_opt
);
4299 free (input_debug
.external_aux
);
4300 free (input_debug
.ss
);
4301 free (input_debug
.ssext
);
4302 free (input_debug
.external_fdr
);
4303 free (input_debug
.external_rfd
);
4304 free (input_debug
.external_ext
);
4306 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4307 elf_link_input_bfd ignores this section. */
4308 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4311 if (SGI_COMPAT (abfd
) && info
->shared
)
4313 /* Create .rtproc section. */
4314 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4315 if (rtproc_sec
== NULL
)
4317 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4318 | SEC_LINKER_CREATED
| SEC_READONLY
);
4320 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4321 if (rtproc_sec
== NULL
4322 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4323 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
4327 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
4328 info
, rtproc_sec
, &debug
))
4332 /* Build the external symbol information. */
4335 einfo
.debug
= &debug
;
4337 einfo
.failed
= false;
4338 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4339 mips_elf_output_extsym
,
4344 /* Set the size of the .mdebug section. */
4345 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4347 /* Skip this section later on (I don't think this currently
4348 matters, but someday it might). */
4349 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4354 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4356 const char *subname
;
4359 Elf32_External_gptab
*ext_tab
;
4362 /* The .gptab.sdata and .gptab.sbss sections hold
4363 information describing how the small data area would
4364 change depending upon the -G switch. These sections
4365 not used in executables files. */
4366 if (! info
->relocateable
)
4370 for (p
= o
->link_order_head
;
4371 p
!= (struct bfd_link_order
*) NULL
;
4374 asection
*input_section
;
4376 if (p
->type
!= bfd_indirect_link_order
)
4378 if (p
->type
== bfd_fill_link_order
)
4383 input_section
= p
->u
.indirect
.section
;
4385 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4386 elf_link_input_bfd ignores this section. */
4387 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4390 /* Skip this section later on (I don't think this
4391 currently matters, but someday it might). */
4392 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4394 /* Really remove the section. */
4395 for (secpp
= &abfd
->sections
;
4397 secpp
= &(*secpp
)->next
)
4399 *secpp
= (*secpp
)->next
;
4400 --abfd
->section_count
;
4405 /* There is one gptab for initialized data, and one for
4406 uninitialized data. */
4407 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4409 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4413 (*_bfd_error_handler
)
4414 (_("%s: illegal section name `%s'"),
4415 bfd_get_filename (abfd
), o
->name
);
4416 bfd_set_error (bfd_error_nonrepresentable_section
);
4420 /* The linker script always combines .gptab.data and
4421 .gptab.sdata into .gptab.sdata, and likewise for
4422 .gptab.bss and .gptab.sbss. It is possible that there is
4423 no .sdata or .sbss section in the output file, in which
4424 case we must change the name of the output section. */
4425 subname
= o
->name
+ sizeof ".gptab" - 1;
4426 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4428 if (o
== gptab_data_sec
)
4429 o
->name
= ".gptab.data";
4431 o
->name
= ".gptab.bss";
4432 subname
= o
->name
+ sizeof ".gptab" - 1;
4433 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4436 /* Set up the first entry. */
4438 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
4441 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4442 tab
[0].gt_header
.gt_unused
= 0;
4444 /* Combine the input sections. */
4445 for (p
= o
->link_order_head
;
4446 p
!= (struct bfd_link_order
*) NULL
;
4449 asection
*input_section
;
4453 bfd_size_type gpentry
;
4455 if (p
->type
!= bfd_indirect_link_order
)
4457 if (p
->type
== bfd_fill_link_order
)
4462 input_section
= p
->u
.indirect
.section
;
4463 input_bfd
= input_section
->owner
;
4465 /* Combine the gptab entries for this input section one
4466 by one. We know that the input gptab entries are
4467 sorted by ascending -G value. */
4468 size
= bfd_section_size (input_bfd
, input_section
);
4470 for (gpentry
= sizeof (Elf32_External_gptab
);
4472 gpentry
+= sizeof (Elf32_External_gptab
))
4474 Elf32_External_gptab ext_gptab
;
4475 Elf32_gptab int_gptab
;
4481 if (! (bfd_get_section_contents
4482 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4483 gpentry
, sizeof (Elf32_External_gptab
))))
4489 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
4491 val
= int_gptab
.gt_entry
.gt_g_value
;
4492 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4495 for (look
= 1; look
< c
; look
++)
4497 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4498 tab
[look
].gt_entry
.gt_bytes
+= add
;
4500 if (tab
[look
].gt_entry
.gt_g_value
== val
)
4506 Elf32_gptab
*new_tab
;
4509 /* We need a new table entry. */
4510 new_tab
= ((Elf32_gptab
*)
4511 bfd_realloc ((PTR
) tab
,
4512 (c
+ 1) * sizeof (Elf32_gptab
)));
4513 if (new_tab
== NULL
)
4519 tab
[c
].gt_entry
.gt_g_value
= val
;
4520 tab
[c
].gt_entry
.gt_bytes
= add
;
4522 /* Merge in the size for the next smallest -G
4523 value, since that will be implied by this new
4526 for (look
= 1; look
< c
; look
++)
4528 if (tab
[look
].gt_entry
.gt_g_value
< val
4530 || (tab
[look
].gt_entry
.gt_g_value
4531 > tab
[max
].gt_entry
.gt_g_value
)))
4535 tab
[c
].gt_entry
.gt_bytes
+=
4536 tab
[max
].gt_entry
.gt_bytes
;
4541 last
= int_gptab
.gt_entry
.gt_bytes
;
4544 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4545 elf_link_input_bfd ignores this section. */
4546 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4549 /* The table must be sorted by -G value. */
4551 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
4553 /* Swap out the table. */
4554 ext_tab
= ((Elf32_External_gptab
*)
4555 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
4556 if (ext_tab
== NULL
)
4562 for (i
= 0; i
< c
; i
++)
4563 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
4566 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
4567 o
->contents
= (bfd_byte
*) ext_tab
;
4569 /* Skip this section later on (I don't think this currently
4570 matters, but someday it might). */
4571 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4575 /* Invoke the regular ELF backend linker to do all the work. */
4576 if (! bfd_elf32_bfd_final_link (abfd
, info
))
4579 /* Now write out the computed sections. */
4581 if (reginfo_sec
!= (asection
*) NULL
)
4583 Elf32_External_RegInfo ext
;
4585 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
4586 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4587 (file_ptr
) 0, sizeof ext
))
4591 if (mdebug_sec
!= (asection
*) NULL
)
4593 BFD_ASSERT (abfd
->output_has_begun
);
4594 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4596 mdebug_sec
->filepos
))
4599 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4602 if (gptab_data_sec
!= (asection
*) NULL
)
4604 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4605 gptab_data_sec
->contents
,
4607 gptab_data_sec
->_raw_size
))
4611 if (gptab_bss_sec
!= (asection
*) NULL
)
4613 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4614 gptab_bss_sec
->contents
,
4616 gptab_bss_sec
->_raw_size
))
4620 if (SGI_COMPAT (abfd
))
4622 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4623 if (rtproc_sec
!= NULL
)
4625 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
4626 rtproc_sec
->contents
,
4628 rtproc_sec
->_raw_size
))
4636 /* Handle a MIPS ELF HI16 reloc. */
4639 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
4641 Elf_Internal_Rela
*relhi
;
4642 Elf_Internal_Rela
*rello
;
4649 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4651 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4654 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4656 if ((addlo
& 0x8000) != 0)
4658 if ((addend
& 0x8000) != 0)
4661 bfd_put_32 (input_bfd
,
4662 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
4663 contents
+ relhi
->r_offset
);
4666 /* Handle a MIPS ELF local GOT16 reloc. */
4669 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
4674 Elf_Internal_Rela
*relhi
;
4675 Elf_Internal_Rela
*rello
;
4679 unsigned int assigned_gotno
;
4685 bfd_byte
*got_contents
;
4686 struct mips_got_info
*g
;
4688 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4690 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4693 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4695 if ((addlo
& 0x8000) != 0)
4697 if ((addend
& 0x8000) != 0)
4700 /* Get a got entry representing requested hipage. */
4701 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4702 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4703 BFD_ASSERT (g
!= NULL
);
4705 assigned_gotno
= g
->assigned_gotno
;
4706 got_contents
= sgot
->contents
;
4707 hipage
= addend
& 0xffff0000;
4709 for (i
= MIPS_RESERVED_GOTNO
; i
< assigned_gotno
; i
++)
4711 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
4712 if (hipage
== (address
& 0xffff0000))
4716 if (i
== assigned_gotno
)
4718 if (assigned_gotno
>= g
->local_gotno
)
4720 (*_bfd_error_handler
)
4721 (_("more got entries are needed for hipage relocations"));
4722 bfd_set_error (bfd_error_bad_value
);
4726 bfd_put_32 (input_bfd
, hipage
, got_contents
+ assigned_gotno
* 4);
4727 ++g
->assigned_gotno
;
4730 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
4731 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
4732 contents
+ relhi
->r_offset
);
4737 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
4740 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
4742 Elf_Internal_Rela
*rel
;
4748 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4749 bfd_put_32 (input_bfd
,
4750 (insn
& 0xffff0000) | (offset
& 0xffff),
4751 contents
+ rel
->r_offset
);
4754 /* Relocate a MIPS ELF section. */
4757 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4758 contents
, relocs
, local_syms
, local_sections
)
4760 struct bfd_link_info
*info
;
4762 asection
*input_section
;
4764 Elf_Internal_Rela
*relocs
;
4765 Elf_Internal_Sym
*local_syms
;
4766 asection
**local_sections
;
4768 Elf_Internal_Shdr
*symtab_hdr
;
4771 asection
*sgot
, *sreloc
, *scpt
;
4774 Elf_Internal_Rela
*rel
;
4775 Elf_Internal_Rela
*relend
;
4776 struct mips_got_info
*g
;
4778 dynobj
= elf_hash_table (info
)->dynobj
;
4779 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4783 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
4786 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
4789 if (elf_bad_symtab (input_bfd
))
4791 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
4796 locsymcount
= symtab_hdr
->sh_info
;
4797 extsymoff
= symtab_hdr
->sh_info
;
4800 gp
= _bfd_get_gp_value (output_bfd
);
4803 relend
= relocs
+ input_section
->reloc_count
;
4804 for (; rel
< relend
; rel
++)
4807 reloc_howto_type
*howto
;
4808 unsigned long r_symndx
;
4810 struct elf_link_hash_entry
*h
;
4812 Elf_Internal_Sym
*sym
;
4813 struct mips_elf_link_hash_entry
*mh
;
4815 bfd_reloc_status_type r
;
4817 r_type
= ELF32_R_TYPE (rel
->r_info
);
4818 if ((r_type
< 0 || r_type
>= (int) R_MIPS_max
)
4819 /* start-sanitize-sky */
4820 && r_type
!= R_MIPS_DVP_11_PCREL
4821 && r_type
!= R_MIPS_DVP_27_S4
4822 /* end-sanitize-sky */
4823 && r_type
!= R_MIPS16_26
4824 && r_type
!= R_MIPS16_GPREL
)
4826 bfd_set_error (bfd_error_bad_value
);
4829 if (r_type
== R_MIPS16_26
)
4830 howto
= &elf_mips16_jump_howto
;
4831 else if (r_type
== R_MIPS16_GPREL
)
4832 howto
= &elf_mips16_gprel_howto
;
4833 /* start-sanitize-sky */
4834 else if (r_type
== R_MIPS_DVP_11_PCREL
)
4835 howto
= &elf_mips_dvp_11_pcrel_howto
;
4836 else if (r_type
== R_MIPS_DVP_27_S4
)
4837 howto
= &elf_mips_dvp_27_s4_howto
;
4838 /* end-sanitize-sky */
4840 howto
= elf_mips_howto_table
+ r_type
;
4843 && (r_type
== R_MIPS_CALL16
4844 || r_type
== R_MIPS_GOT16
4845 || r_type
== R_MIPS_CALL_HI16
4846 || r_type
== R_MIPS_CALL_LO16
4847 || r_type
== R_MIPS_GOT_HI16
4848 || r_type
== R_MIPS_GOT_LO16
))
4850 /* We need the .got section. */
4853 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4854 BFD_ASSERT (sgot
!= NULL
);
4855 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4856 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4857 BFD_ASSERT (g
!= NULL
);
4861 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4863 /* Mix in the change in GP address for a GP relative reloc. */
4864 if (r_type
!= R_MIPS_GPREL16
4865 && r_type
!= R_MIPS_LITERAL
4866 && r_type
!= R_MIPS_GPREL32
4867 && r_type
!= R_MIPS16_GPREL
)
4873 if (! ((*info
->callbacks
->reloc_dangerous
)
4875 _("GP relative relocation when GP not defined"),
4876 input_bfd
, input_section
,
4879 /* Only give the error once per link. */
4881 _bfd_set_gp_value (output_bfd
, gp
);
4884 if (r_symndx
< extsymoff
4885 || (elf_bad_symtab (input_bfd
)
4886 && local_sections
[r_symndx
] != NULL
))
4888 /* This is a relocation against a section. The current
4889 addend in the instruction is the difference between
4890 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
4891 must change this to be the difference between the
4892 final definition (which will end up in RELOCATION)
4893 and the GP value of OUTPUT_BFD (which is in GP). */
4894 addend
= elf_gp (input_bfd
) - gp
;
4896 else if (! info
->relocateable
)
4898 /* We are doing a final link. The current addend in the
4899 instruction is simply the desired offset into the
4900 symbol (normally zero). We want the instruction to
4901 hold the difference between the final definition of
4902 the symbol (which will end up in RELOCATION) and the
4903 GP value of OUTPUT_BFD (which is in GP). */
4908 /* We are generating relocateable output, and we aren't
4909 going to define this symbol, so we just leave the
4910 instruction alone. */
4918 if (info
->relocateable
)
4920 /* This is a relocateable link. We don't have to change
4921 anything, unless the reloc is against a section symbol,
4922 in which case we have to adjust according to where the
4923 section symbol winds up in the output section. */
4924 if (r_symndx
>= locsymcount
4925 || (elf_bad_symtab (input_bfd
)
4926 && local_sections
[r_symndx
] == NULL
))
4930 sym
= local_syms
+ r_symndx
;
4931 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4935 sec
= local_sections
[r_symndx
];
4937 /* It would be logical to add sym->st_value here,
4938 but Irix 5 sometimes generates a garbage symbol
4940 addend
+= sec
->output_offset
;
4942 /* If this is HI16 or GOT16 with an associated LO16,
4943 adjust the addend accordingly. Otherwise, just
4945 if (r_type
== R_MIPS_64
&& bfd_big_endian (input_bfd
))
4946 r
= _bfd_relocate_contents (howto
, input_bfd
,
4948 contents
+ rel
->r_offset
+ 4);
4949 else if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
4950 r
= _bfd_relocate_contents (howto
, input_bfd
,
4952 contents
+ rel
->r_offset
);
4955 Elf_Internal_Rela
*lorel
;
4957 /* As a GNU extension, permit an arbitrary
4958 number of R_MIPS_HI16 relocs before the
4959 R_MIPS_LO16 reloc. This permits gcc to emit
4960 the HI and LO relocs itself. */
4961 if (r_type
== R_MIPS_GOT16
)
4965 for (lorel
= rel
+ 1;
4967 && (ELF32_R_TYPE (lorel
->r_info
)
4973 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
4975 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
4980 r
= _bfd_relocate_contents (howto
, input_bfd
,
4982 contents
+ rel
->r_offset
);
4991 boolean undefined_error
;
4993 /* This is a final link. */
4994 undefined_error
= false;
4996 if (r_symndx
< extsymoff
4997 || (elf_bad_symtab (input_bfd
)
4998 && local_sections
[r_symndx
] != NULL
))
5001 sym
= local_syms
+ r_symndx
;
5002 sec
= local_sections
[r_symndx
];
5003 relocation
= (sec
->output_section
->vma
5004 + sec
->output_offset
);
5006 /* It would be logical to always add sym->st_value here,
5007 but Irix 5 sometimes generates a garbage symbol
5009 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5010 relocation
+= sym
->st_value
;
5012 /* mips16 text labels should be treated as odd. */
5013 if (sym
->st_other
== STO_MIPS16
)
5021 indx
= r_symndx
- extsymoff
;
5022 h
= elf_sym_hashes (input_bfd
)[indx
];
5023 while (h
->root
.type
== bfd_link_hash_indirect
5024 || h
->root
.type
== bfd_link_hash_warning
)
5025 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5026 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
5030 if (! ((*info
->callbacks
->reloc_dangerous
)
5032 _("_gp_disp used when GP not defined"),
5033 input_bfd
, input_section
,
5036 /* Only give the error once per link. */
5038 _bfd_set_gp_value (output_bfd
, gp
);
5043 sec
= input_section
;
5044 if (sec
->output_section
!= NULL
)
5047 + sec
->output_section
->vma
5048 + sec
->output_offset
));
5050 relocation
= gp
- rel
->r_offset
;
5051 if (r_type
== R_MIPS_LO16
)
5055 else if (h
->root
.type
== bfd_link_hash_defined
5056 || h
->root
.type
== bfd_link_hash_defweak
)
5058 sec
= h
->root
.u
.def
.section
;
5059 if (sec
->output_section
== NULL
)
5062 relocation
= (h
->root
.u
.def
.value
5063 + sec
->output_section
->vma
5064 + sec
->output_offset
);
5066 else if (h
->root
.type
== bfd_link_hash_undefweak
)
5068 else if (info
->shared
&& ! info
->symbolic
)
5070 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
5072 /* If this is a dynamic link, we should have created
5073 a _DYNAMIC_LINK symbol in
5074 mips_elf_create_dynamic_sections. Otherwise, we
5075 should define the symbol with a value of 0.
5076 FIXME: It should probably get into the symbol
5077 table somehow as well. */
5078 BFD_ASSERT (! info
->shared
);
5079 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
5080 ".dynamic") == NULL
);
5085 if (! ((*info
->callbacks
->undefined_symbol
)
5086 (info
, h
->root
.root
.string
, input_bfd
,
5087 input_section
, rel
->r_offset
)))
5089 undefined_error
= true;
5094 mh
= (struct mips_elf_link_hash_entry
*) h
;
5097 else if (sym
!= NULL
)
5098 other
= sym
->st_other
;
5102 /* If this function has an fn_stub, then it is a mips16
5103 function which needs a stub if it is called by a 32 bit
5104 function. If this reloc is anything other than a 16 bit
5105 call, redirect the reloc to the stub. We don't redirect
5106 relocs from other stub functions. */
5107 if (r_type
!= R_MIPS16_26
5109 && mh
->fn_stub
!= NULL
)
5111 && elf_tdata (input_bfd
)->local_stubs
!= NULL
5112 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
5113 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5114 FN_STUB
, sizeof FN_STUB
- 1) != 0
5115 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5116 CALL_STUB
, sizeof CALL_STUB
- 1) != 0
5117 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5118 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) != 0)
5122 BFD_ASSERT (mh
->need_fn_stub
);
5123 relocation
= (mh
->fn_stub
->output_section
->vma
5124 + mh
->fn_stub
->output_offset
);
5130 fn_stub
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
5131 relocation
= (fn_stub
->output_section
->vma
5132 + fn_stub
->output_offset
);
5135 /* RELOCATION now points to 32 bit code. */
5139 /* If this function has a call_stub, then it is called by a
5140 mips16 function; the call needs to go through a stub if
5141 this function is a 32 bit function. If this reloc is a
5142 16 bit call, and the symbol is not a 16 bit function,
5143 then redirect the reloc to the stub. Note that we don't
5144 need to worry about calling the function through a
5145 function pointer; such calls are handled by routing
5146 through a special mips16 routine. We don't have to check
5147 whether this call is from a stub; it can't be, because a
5148 stub contains 32 bit code, and hence can not have a 16
5150 if (r_type
== R_MIPS16_26
5152 && (mh
->call_stub
!= NULL
|| mh
->call_fp_stub
!= NULL
)
5153 && other
!= STO_MIPS16
)
5157 /* If both call_stub and call_fp_stub are defined, we
5158 can figure out which one to use by seeing which one
5159 appears in the input file. */
5160 if (mh
->call_stub
!= NULL
&& mh
->call_fp_stub
!= NULL
)
5165 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
5167 if (strncmp (bfd_get_section_name (input_bfd
, o
),
5168 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5170 stub
= mh
->call_fp_stub
;
5175 stub
= mh
->call_stub
;
5177 else if (mh
->call_stub
!= NULL
)
5178 stub
= mh
->call_stub
;
5180 stub
= mh
->call_fp_stub
;
5182 BFD_ASSERT (stub
->_raw_size
> 0);
5183 relocation
= stub
->output_section
->vma
+ stub
->output_offset
;
5186 if (r_type
== R_MIPS_HI16
)
5188 Elf_Internal_Rela
*lorel
;
5190 /* As a GNU extension, permit an arbitrary number of
5191 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
5192 This permits gcc to emit the HI and LO relocs itself. */
5193 for (lorel
= rel
+ 1;
5195 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
5199 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5201 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5202 contents
, relocation
+ addend
);
5206 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5207 contents
, rel
->r_offset
,
5208 relocation
, addend
);
5210 else if (r_type
== R_MIPS_GOT16
&& local
)
5212 /* GOT16 must also have an associated LO16 in the local
5213 case. In this case, the addend is extracted and the
5214 section in which the referenced object is determined.
5215 Then the final address of the object is computed and
5216 the GOT entry for the hipage (an aligned 64kb chunk)
5217 is added to .got section if needed. The offset field
5218 of the GOT16-relocated instruction is replaced by the
5219 index of this GOT entry for the hipage. */
5220 if ((rel
+ 1) < relend
5221 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
5223 if (! mips_elf_relocate_got_local (output_bfd
, input_bfd
,
5226 relocation
+ addend
))
5231 r
= bfd_reloc_outofrange
;
5233 else if (r_type
== R_MIPS_CALL16
5234 || r_type
== R_MIPS_GOT16
5235 || r_type
== R_MIPS_CALL_LO16
5236 || r_type
== R_MIPS_GOT_LO16
)
5240 /* This symbol must be registered as a global symbol
5241 having the corresponding got entry. */
5242 BFD_ASSERT (h
->got_offset
!= (bfd_vma
) -1);
5244 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5245 BFD_ASSERT (g
->local_gotno
<= offset
5246 && offset
< sgot
->_raw_size
);
5247 bfd_put_32 (output_bfd
, relocation
+ addend
,
5248 sgot
->contents
+ offset
);
5249 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5251 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
5255 else if (r_type
== R_MIPS_CALL_HI16
5256 || r_type
== R_MIPS_GOT_HI16
)
5260 /* This must be a global symbol with a got entry. The
5261 next reloc must be the corresponding LO16 reloc. */
5262 BFD_ASSERT (h
!= NULL
&& h
->got_offset
!= (bfd_vma
) -1);
5263 BFD_ASSERT ((rel
+ 1) < relend
);
5264 BFD_ASSERT ((int) ELF32_R_TYPE ((rel
+ 1)->r_info
)
5265 == (r_type
== R_MIPS_CALL_HI16
5266 ? (int) R_MIPS_CALL_LO16
5267 : (int) R_MIPS_GOT_LO16
));
5269 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5270 BFD_ASSERT (g
->local_gotno
<= offset
5271 && offset
< sgot
->_raw_size
);
5272 bfd_put_32 (output_bfd
, relocation
+ addend
,
5273 sgot
->contents
+ offset
);
5274 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5276 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
5280 else if (r_type
== R_MIPS_REL32
5281 || r_type
== R_MIPS_32
)
5283 Elf_Internal_Rel outrel
;
5284 Elf32_crinfo cptrel
;
5288 || (elf_hash_table (info
)->dynamic_sections_created
5290 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
5292 && (input_section
->flags
& SEC_ALLOC
) != 0)
5296 /* When generating a shared object, these
5297 relocations are copied into the output file to be
5298 resolved at run time. */
5301 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5302 BFD_ASSERT (sreloc
!= NULL
);
5307 if (elf_section_data (input_section
)->stab_info
== NULL
)
5308 outrel
.r_offset
= rel
->r_offset
;
5313 off
= (_bfd_stab_section_offset
5314 (output_bfd
, &elf_hash_table (info
)->stab_info
,
5316 &elf_section_data (input_section
)->stab_info
,
5318 if (off
== (bfd_vma
) -1)
5320 outrel
.r_offset
= off
;
5323 outrel
.r_offset
+= (input_section
->output_section
->vma
5324 + input_section
->output_offset
);
5326 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5329 memset (&outrel
, 0, sizeof outrel
);
5331 && (! info
->symbolic
5332 || (h
->elf_link_hash_flags
5333 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5335 BFD_ASSERT (h
->dynindx
!= -1);
5336 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
5337 sec
= input_section
;
5344 sec
= local_sections
[r_symndx
];
5347 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
5349 == bfd_link_hash_defweak
));
5350 sec
= h
->root
.u
.def
.section
;
5352 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5354 else if (sec
== NULL
|| sec
->owner
== NULL
)
5356 bfd_set_error (bfd_error_bad_value
);
5363 osec
= sec
->output_section
;
5364 indx
= elf_section_data (osec
)->dynindx
;
5369 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
5370 addend
+= relocation
;
5374 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
5376 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
5377 (((Elf32_External_Rel
*)
5379 + sreloc
->reloc_count
));
5380 ++sreloc
->reloc_count
;
5382 if (! skip
&& SGI_COMPAT (output_bfd
))
5387 /* Make an entry of compact relocation info. */
5388 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5389 cptrel
.vaddr
= (rel
->r_offset
5390 + input_section
->output_section
->vma
5391 + input_section
->output_offset
);
5392 if (r_type
== R_MIPS_REL32
)
5393 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5395 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5396 mips_elf_set_cr_dist2to (cptrel
, 0);
5397 cptrel
.konst
= addend
;
5399 cr
= (scpt
->contents
5400 + sizeof (Elf32_External_compact_rel
));
5401 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5402 ((Elf32_External_crinfo
*) cr
5403 + scpt
->reloc_count
));
5404 ++scpt
->reloc_count
;
5407 /* This reloc will be computed at runtime, so
5408 there's no need to do anything now. */
5412 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5413 contents
, rel
->r_offset
,
5414 relocation
, addend
);
5416 else if (r_type
== R_MIPS_64
)
5421 /* Do a 32 bit relocation, and sign extend to 64 bits. */
5422 addr
= rel
->r_offset
;
5423 if (bfd_big_endian (input_bfd
))
5425 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5426 contents
, addr
, relocation
,
5428 val
= bfd_get_32 (input_bfd
, contents
+ addr
);
5429 if ((val
& 0x80000000) != 0)
5433 addr
= rel
->r_offset
;
5434 if (bfd_little_endian (input_bfd
))
5436 bfd_put_32 (input_bfd
, val
, contents
+ addr
);
5438 else if (r_type
== R_MIPS_26
&& other
== STO_MIPS16
)
5442 /* This is a jump to a mips16 routine from a mips32
5443 routine. We need to change jal into jalx. */
5444 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5445 if (((insn
>> 26) & 0x3f) != 0x3
5446 && ((insn
>> 26) & 0x3f) != 0x1d)
5448 (*_bfd_error_handler
)
5449 (_("%s: %s+0x%lx: jump to mips16 routine which is not jal"),
5450 bfd_get_filename (input_bfd
),
5451 input_section
->name
,
5452 (unsigned long) rel
->r_offset
);
5453 bfd_set_error (bfd_error_bad_value
);
5456 insn
= (insn
& 0x3ffffff) | (0x1d << 26);
5457 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5458 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5459 contents
, rel
->r_offset
,
5460 relocation
, addend
);
5462 else if (r_type
== R_MIPS16_26
)
5464 /* It's easiest to do the normal relocation, and then
5465 dig out the instruction and swap the first word the
5466 way the mips16 expects it. If this is little endian,
5467 though, we need to swap the two words first, and then
5468 swap them back again later, so that the address looks
5471 if (bfd_little_endian (input_bfd
))
5475 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5476 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5477 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5480 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5481 contents
, rel
->r_offset
,
5482 relocation
, addend
);
5483 if (r
== bfd_reloc_ok
)
5487 if (bfd_little_endian (input_bfd
))
5489 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5490 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5491 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5494 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5495 insn
= ((insn
& 0xfc00)
5496 | ((insn
& 0x1f) << 5)
5497 | ((insn
& 0x3e0) >> 5));
5498 /* If this is a jump to a 32 bit routine, then make
5500 if (other
!= STO_MIPS16
)
5502 bfd_put_16 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5505 else if (r_type
== R_MIPS16_GPREL
)
5507 unsigned short extend
, insn
;
5509 unsigned long final
;
5511 /* Extract the addend into buf, run the regular reloc,
5512 and stuff the resulting value back into the
5514 if (rel
->r_offset
> input_section
->_raw_size
)
5515 r
= bfd_reloc_outofrange
;
5518 extend
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5519 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 2);
5520 bfd_put_32 (input_bfd
,
5521 (((extend
& 0x1f) << 11)
5525 r
= _bfd_final_link_relocate (howto
, input_bfd
,
5527 (bfd_vma
) 0, relocation
,
5529 final
= bfd_get_32 (input_bfd
, buf
);
5530 bfd_put_16 (input_bfd
,
5532 | ((final
>> 11) & 0x1f)
5534 contents
+ rel
->r_offset
);
5535 bfd_put_16 (input_bfd
,
5538 contents
+ rel
->r_offset
+ 2);
5542 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5543 contents
, rel
->r_offset
,
5544 relocation
, addend
);
5546 /* The jal instruction can only jump to an address which is
5547 divisible by 4, and it can only jump to an address with
5548 the same upper 4 bits as the PC. */
5549 if (r
== bfd_reloc_ok
5550 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
))
5555 if (other
== STO_MIPS16
)
5556 addr
&= ~ (bfd_vma
) 1;
5559 || ((addr
& 0xf0000000)
5560 != ((input_section
->output_section
->vma
5561 + input_section
->output_offset
5564 r
= bfd_reloc_overflow
;
5567 /* Don't bother to report a relocation overflow for a call
5568 to a weak undefined symbol with a value of zero. This
5571 even if we aren't in range to call address zero. */
5572 if (r
== bfd_reloc_overflow
5573 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
)
5574 && relocation
+ addend
== 0
5576 && h
->root
.type
== bfd_link_hash_undefweak
)
5579 /* If we've already issued an error for an undefined symbol,
5580 don't issue another useless error. */
5582 && (r
== bfd_reloc_undefined
|| r
== bfd_reloc_overflow
))
5585 if (SGI_COMPAT (abfd
)
5587 && (input_section
->flags
& SEC_ALLOC
) != 0)
5589 Elf32_crinfo cptrel
;
5592 /* Make an entry of compact relocation info. */
5593 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5594 cptrel
.vaddr
= (rel
->r_offset
5595 + input_section
->output_section
->vma
5596 + input_section
->output_offset
);
5601 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
5602 /* XXX How should we set dist2to in this case. */
5603 mips_elf_set_cr_dist2to (cptrel
, 8);
5604 cptrel
.konst
= addend
+ relocation
;
5605 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5606 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5607 ((Elf32_External_crinfo
*) cr
5608 + scpt
->reloc_count
));
5609 ++scpt
->reloc_count
;
5612 case R_MIPS_GPREL16
:
5613 case R_MIPS_LITERAL
:
5614 case R_MIPS_GPREL32
:
5615 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
5616 cptrel
.konst
= gp
- cptrel
.vaddr
;
5617 mips_elf_set_cr_dist2to (cptrel
, 4);
5618 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5619 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5620 ((Elf32_External_crinfo
*) cr
5621 + scpt
->reloc_count
));
5622 ++scpt
->reloc_count
;
5631 if (r
!= bfd_reloc_ok
)
5636 case bfd_reloc_outofrange
:
5638 case bfd_reloc_overflow
:
5643 name
= h
->root
.root
.string
;
5646 name
= bfd_elf_string_from_elf_section (input_bfd
,
5647 symtab_hdr
->sh_link
,
5652 name
= bfd_section_name (input_bfd
, sec
);
5654 if (! ((*info
->callbacks
->reloc_overflow
)
5655 (info
, name
, howto
->name
, (bfd_vma
) 0,
5656 input_bfd
, input_section
, rel
->r_offset
)))
5667 /* This hook function is called before the linker writes out a global
5668 symbol. We mark symbols as small common if appropriate. This is
5669 also where we undo the increment of the value for a mips16 symbol. */
5673 mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
5675 struct bfd_link_info
*info
;
5677 Elf_Internal_Sym
*sym
;
5678 asection
*input_sec
;
5680 /* If we see a common symbol, which implies a relocatable link, then
5681 if a symbol was small common in an input file, mark it as small
5682 common in the output file. */
5683 if (sym
->st_shndx
== SHN_COMMON
5684 && strcmp (input_sec
->name
, ".scommon") == 0)
5685 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
5687 if (sym
->st_other
== STO_MIPS16
5688 && (sym
->st_value
& 1) != 0)
5694 /* Functions for the dynamic linker. */
5696 /* The name of the dynamic interpreter. This is put in the .interp
5699 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
5701 /* Create dynamic sections when linking against a dynamic object. */
5704 mips_elf_create_dynamic_sections (abfd
, info
)
5706 struct bfd_link_info
*info
;
5708 struct elf_link_hash_entry
*h
;
5710 register asection
*s
;
5711 const char * const *namep
;
5713 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5714 | SEC_LINKER_CREATED
| SEC_READONLY
);
5716 /* Mips ABI requests the .dynamic section to be read only. */
5717 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5720 if (! bfd_set_section_flags (abfd
, s
, flags
))
5724 /* We need to create .got section. */
5725 if (! mips_elf_create_got_section (abfd
, info
))
5728 /* Create .stub section. */
5729 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
5731 s
= bfd_make_section (abfd
, ".stub");
5733 || ! bfd_set_section_flags (abfd
, s
, flags
)
5734 || ! bfd_set_section_alignment (abfd
, s
, 2))
5738 if (SGI_COMPAT (abfd
)
5740 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
5742 s
= bfd_make_section (abfd
, ".rld_map");
5744 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
5745 || ! bfd_set_section_alignment (abfd
, s
, 2))
5749 if (SGI_COMPAT (abfd
))
5751 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
5754 if (! (_bfd_generic_link_add_one_symbol
5755 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
5756 (bfd_vma
) 0, (const char *) NULL
, false,
5757 get_elf_backend_data (abfd
)->collect
,
5758 (struct bfd_link_hash_entry
**) &h
)))
5760 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5761 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5762 h
->type
= STT_SECTION
;
5764 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5768 /* We need to create a .compact_rel section. */
5769 if (! mips_elf_create_compact_rel_section (abfd
, info
))
5772 /* Change aligments of some sections. */
5773 s
= bfd_get_section_by_name (abfd
, ".hash");
5775 bfd_set_section_alignment (abfd
, s
, 4);
5776 s
= bfd_get_section_by_name (abfd
, ".dynsym");
5778 bfd_set_section_alignment (abfd
, s
, 4);
5779 s
= bfd_get_section_by_name (abfd
, ".dynstr");
5781 bfd_set_section_alignment (abfd
, s
, 4);
5782 s
= bfd_get_section_by_name (abfd
, ".reginfo");
5784 bfd_set_section_alignment (abfd
, s
, 4);
5785 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5787 bfd_set_section_alignment (abfd
, s
, 4);
5793 if (! (_bfd_generic_link_add_one_symbol
5794 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
5795 (bfd_vma
) 0, (const char *) NULL
, false,
5796 get_elf_backend_data (abfd
)->collect
,
5797 (struct bfd_link_hash_entry
**) &h
)))
5799 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5800 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5801 h
->type
= STT_SECTION
;
5803 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5806 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
5808 /* __rld_map is a four byte word located in the .data section
5809 and is filled in by the rtld to contain a pointer to
5810 the _r_debug structure. Its symbol value will be set in
5811 mips_elf_finish_dynamic_symbol. */
5812 s
= bfd_get_section_by_name (abfd
, ".rld_map");
5813 BFD_ASSERT (s
!= NULL
);
5816 if (! (_bfd_generic_link_add_one_symbol
5817 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
5818 (bfd_vma
) 0, (const char *) NULL
, false,
5819 get_elf_backend_data (abfd
)->collect
,
5820 (struct bfd_link_hash_entry
**) &h
)))
5822 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5823 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5824 h
->type
= STT_OBJECT
;
5826 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5834 /* Create the .compact_rel section. */
5837 mips_elf_create_compact_rel_section (abfd
, info
)
5839 struct bfd_link_info
*info
;
5842 register asection
*s
;
5844 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
5846 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
5849 s
= bfd_make_section (abfd
, ".compact_rel");
5851 || ! bfd_set_section_flags (abfd
, s
, flags
)
5852 || ! bfd_set_section_alignment (abfd
, s
, 2))
5855 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
5861 /* Create the .got section to hold the global offset table. */
5864 mips_elf_create_got_section (abfd
, info
)
5866 struct bfd_link_info
*info
;
5869 register asection
*s
;
5870 struct elf_link_hash_entry
*h
;
5871 struct mips_got_info
*g
;
5873 /* This function may be called more than once. */
5874 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
5877 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5878 | SEC_LINKER_CREATED
);
5880 s
= bfd_make_section (abfd
, ".got");
5882 || ! bfd_set_section_flags (abfd
, s
, flags
)
5883 || ! bfd_set_section_alignment (abfd
, s
, 4))
5886 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
5887 linker script because we don't want to define the symbol if we
5888 are not creating a global offset table. */
5890 if (! (_bfd_generic_link_add_one_symbol
5891 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
5892 (bfd_vma
) 0, (const char *) NULL
, false,
5893 get_elf_backend_data (abfd
)->collect
,
5894 (struct bfd_link_hash_entry
**) &h
)))
5896 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5897 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5898 h
->type
= STT_OBJECT
;
5901 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5904 /* The first several global offset table entries are reserved. */
5905 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
5907 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
5908 sizeof (struct mips_got_info
));
5911 g
->global_gotsym
= 0;
5912 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
5913 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
5914 if (elf_section_data (s
) == NULL
)
5917 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
5918 if (elf_section_data (s
) == NULL
)
5921 elf_section_data (s
)->tdata
= (PTR
) g
;
5926 /* Look through the relocs for a section during the first phase, and
5927 allocate space in the global offset table. */
5930 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
5932 struct bfd_link_info
*info
;
5934 const Elf_Internal_Rela
*relocs
;
5938 Elf_Internal_Shdr
*symtab_hdr
;
5939 struct elf_link_hash_entry
**sym_hashes
;
5940 struct mips_got_info
*g
;
5942 const Elf_Internal_Rela
*rel
;
5943 const Elf_Internal_Rela
*rel_end
;
5947 if (info
->relocateable
)
5950 dynobj
= elf_hash_table (info
)->dynobj
;
5951 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5952 sym_hashes
= elf_sym_hashes (abfd
);
5953 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
5955 /* Check for the mips16 stub sections. */
5957 name
= bfd_get_section_name (abfd
, sec
);
5958 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
5960 unsigned long r_symndx
;
5962 /* Look at the relocation information to figure out which symbol
5965 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
5967 if (r_symndx
< extsymoff
5968 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
5972 /* This stub is for a local symbol. This stub will only be
5973 needed if there is some relocation in this BFD, other
5974 than a 16 bit function call, which refers to this symbol. */
5975 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5977 Elf_Internal_Rela
*sec_relocs
;
5978 const Elf_Internal_Rela
*r
, *rend
;
5980 /* We can ignore stub sections when looking for relocs. */
5981 if ((o
->flags
& SEC_RELOC
) == 0
5982 || o
->reloc_count
== 0
5983 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
5984 sizeof FN_STUB
- 1) == 0
5985 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
5986 sizeof CALL_STUB
- 1) == 0
5987 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
5988 sizeof CALL_FP_STUB
- 1) == 0)
5991 sec_relocs
= (_bfd_elf32_link_read_relocs
5992 (abfd
, o
, (PTR
) NULL
,
5993 (Elf_Internal_Rela
*) NULL
,
5994 info
->keep_memory
));
5995 if (sec_relocs
== NULL
)
5998 rend
= sec_relocs
+ o
->reloc_count
;
5999 for (r
= sec_relocs
; r
< rend
; r
++)
6000 if (ELF32_R_SYM (r
->r_info
) == r_symndx
6001 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
6004 if (! info
->keep_memory
)
6013 /* There is no non-call reloc for this stub, so we do
6014 not need it. Since this function is called before
6015 the linker maps input sections to output sections, we
6016 can easily discard it by setting the SEC_EXCLUDE
6018 sec
->flags
|= SEC_EXCLUDE
;
6022 /* Record this stub in an array of local symbol stubs for
6024 if (elf_tdata (abfd
)->local_stubs
== NULL
)
6026 unsigned long symcount
;
6029 if (elf_bad_symtab (abfd
))
6030 symcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
6032 symcount
= symtab_hdr
->sh_info
;
6033 n
= (asection
**) bfd_zalloc (abfd
,
6034 symcount
* sizeof (asection
*));
6037 elf_tdata (abfd
)->local_stubs
= n
;
6040 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
6042 /* We don't need to set mips16_stubs_seen in this case.
6043 That flag is used to see whether we need to look through
6044 the global symbol table for stubs. We don't need to set
6045 it here, because we just have a local stub. */
6049 struct mips_elf_link_hash_entry
*h
;
6051 h
= ((struct mips_elf_link_hash_entry
*)
6052 sym_hashes
[r_symndx
- extsymoff
]);
6054 /* H is the symbol this stub is for. */
6057 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6060 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
6061 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6063 unsigned long r_symndx
;
6064 struct mips_elf_link_hash_entry
*h
;
6067 /* Look at the relocation information to figure out which symbol
6070 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6072 if (r_symndx
< extsymoff
6073 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6075 /* This stub was actually built for a static symbol defined
6076 in the same file. We assume that all static symbols in
6077 mips16 code are themselves mips16, so we can simply
6078 discard this stub. Since this function is called before
6079 the linker maps input sections to output sections, we can
6080 easily discard it by setting the SEC_EXCLUDE flag. */
6081 sec
->flags
|= SEC_EXCLUDE
;
6085 h
= ((struct mips_elf_link_hash_entry
*)
6086 sym_hashes
[r_symndx
- extsymoff
]);
6088 /* H is the symbol this stub is for. */
6090 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6091 loc
= &h
->call_fp_stub
;
6093 loc
= &h
->call_stub
;
6095 /* If we already have an appropriate stub for this function, we
6096 don't need another one, so we can discard this one. Since
6097 this function is called before the linker maps input sections
6098 to output sections, we can easily discard it by setting the
6099 SEC_EXCLUDE flag. We can also discard this section if we
6100 happen to already know that this is a mips16 function; it is
6101 not necessary to check this here, as it is checked later, but
6102 it is slightly faster to check now. */
6103 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
6105 sec
->flags
|= SEC_EXCLUDE
;
6110 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6120 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6125 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6126 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6127 BFD_ASSERT (g
!= NULL
);
6133 rel_end
= relocs
+ sec
->reloc_count
;
6134 for (rel
= relocs
; rel
< rel_end
; rel
++)
6136 unsigned long r_symndx
;
6137 struct elf_link_hash_entry
*h
;
6139 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6141 if (r_symndx
< extsymoff
)
6145 h
= sym_hashes
[r_symndx
- extsymoff
];
6147 /* This may be an indirect symbol created because of a version. */
6150 while (h
->root
.type
== bfd_link_hash_indirect
)
6151 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6155 /* Some relocs require a global offset table. */
6156 if (dynobj
== NULL
|| sgot
== NULL
)
6158 switch (ELF32_R_TYPE (rel
->r_info
))
6162 case R_MIPS_CALL_HI16
:
6163 case R_MIPS_CALL_LO16
:
6164 case R_MIPS_GOT_HI16
:
6165 case R_MIPS_GOT_LO16
:
6167 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6168 if (! mips_elf_create_got_section (dynobj
, info
))
6170 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6171 BFD_ASSERT (sgot
!= NULL
);
6172 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6173 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6174 BFD_ASSERT (g
!= NULL
);
6180 && (info
->shared
|| h
!= NULL
)
6181 && (sec
->flags
& SEC_ALLOC
) != 0)
6182 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6190 switch (ELF32_R_TYPE (rel
->r_info
))
6193 case R_MIPS_CALL_HI16
:
6194 case R_MIPS_CALL_LO16
:
6195 /* This symbol requires a global offset table entry. */
6199 (*_bfd_error_handler
)
6200 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
6201 bfd_get_filename (abfd
), (unsigned long) rel
->r_offset
);
6202 bfd_set_error (bfd_error_bad_value
);
6206 /* Make sure this symbol is output as a dynamic symbol. */
6207 if (h
->dynindx
== -1)
6209 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6213 if (h
->got_offset
!= (bfd_vma
) -1)
6215 /* We have already allocated space in the .got. */
6219 /* Note the index of the first global got symbol in .dynsym. */
6220 if (g
->global_gotsym
== 0
6221 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6222 g
->global_gotsym
= h
->dynindx
;
6224 /* Make this symbol to have the corresponding got entry. */
6227 /* We need a stub, not a plt entry for the undefined
6228 function. But we record it as if it needs plt. See
6229 elf_adjust_dynamic_symbol in elflink.h. */
6230 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6236 case R_MIPS_GOT_HI16
:
6237 case R_MIPS_GOT_LO16
:
6238 /* This symbol requires a global offset table entry. */
6242 /* Make sure this symbol is output as a dynamic symbol. */
6243 if (h
->dynindx
== -1)
6245 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6249 if (h
->got_offset
!= (bfd_vma
) -1)
6251 /* We have already allocated space in the .got. */
6254 /* Note the index of the first global got symbol in
6256 if (g
->global_gotsym
== 0
6257 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6258 g
->global_gotsym
= h
->dynindx
;
6260 /* Make this symbol to be the global got symbol. */
6268 if ((info
->shared
|| h
!= NULL
)
6269 && (sec
->flags
& SEC_ALLOC
) != 0)
6273 const char *name
= ".rel.dyn";
6275 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6278 sreloc
= bfd_make_section (dynobj
, name
);
6280 || ! bfd_set_section_flags (dynobj
, sreloc
,
6285 | SEC_LINKER_CREATED
6287 || ! bfd_set_section_alignment (dynobj
, sreloc
,
6294 /* When creating a shared object, we must copy these
6295 reloc types into the output file as R_MIPS_REL32
6296 relocs. We make room for this reloc in the
6297 .rel.dyn reloc section */
6298 if (sreloc
->_raw_size
== 0)
6300 /* Add a null element. */
6301 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6302 ++sreloc
->reloc_count
;
6304 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6308 struct mips_elf_link_hash_entry
*hmips
;
6310 /* We only need to copy this reloc if the symbol is
6311 defined in a dynamic object. */
6312 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6313 ++hmips
->mips_32_relocs
;
6317 if (SGI_COMPAT (abfd
))
6318 mips_elf_hash_table (info
)->compact_rel_size
+=
6319 sizeof (Elf32_External_crinfo
);
6324 case R_MIPS_GPREL16
:
6325 case R_MIPS_LITERAL
:
6326 case R_MIPS_GPREL32
:
6327 if (SGI_COMPAT (abfd
))
6328 mips_elf_hash_table (info
)->compact_rel_size
+=
6329 sizeof (Elf32_External_crinfo
);
6336 /* If this reloc is not a 16 bit call, and it has a global
6337 symbol, then we will need the fn_stub if there is one.
6338 References from a stub section do not count. */
6340 && ELF32_R_TYPE (rel
->r_info
) != R_MIPS16_26
6341 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
6342 sizeof FN_STUB
- 1) != 0
6343 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
6344 sizeof CALL_STUB
- 1) != 0
6345 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
6346 sizeof CALL_FP_STUB
- 1) != 0)
6348 struct mips_elf_link_hash_entry
*mh
;
6350 mh
= (struct mips_elf_link_hash_entry
*) h
;
6351 mh
->need_fn_stub
= true;
6358 /* Adjust a symbol defined by a dynamic object and referenced by a
6359 regular object. The current definition is in some section of the
6360 dynamic object, but we're not including those sections. We have to
6361 change the definition to something the rest of the link can
6365 mips_elf_adjust_dynamic_symbol (info
, h
)
6366 struct bfd_link_info
*info
;
6367 struct elf_link_hash_entry
*h
;
6370 struct mips_elf_link_hash_entry
*hmips
;
6373 dynobj
= elf_hash_table (info
)->dynobj
;
6375 /* Make sure we know what is going on here. */
6376 BFD_ASSERT (dynobj
!= NULL
6377 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
6378 || h
->weakdef
!= NULL
6379 || ((h
->elf_link_hash_flags
6380 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
6381 && (h
->elf_link_hash_flags
6382 & ELF_LINK_HASH_REF_REGULAR
) != 0
6383 && (h
->elf_link_hash_flags
6384 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
6386 /* If this symbol is defined in a dynamic object, we need to copy
6387 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
6389 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6390 if (! info
->relocateable
6391 && hmips
->mips_32_relocs
!= 0
6392 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6394 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6395 BFD_ASSERT (s
!= NULL
);
6397 if (s
->_raw_size
== 0)
6399 /* Make room for a null element. */
6400 s
->_raw_size
+= sizeof (Elf32_External_Rel
);
6403 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
6406 /* For a function, create a stub, if needed. */
6407 if (h
->type
== STT_FUNC
6408 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
6410 if (! elf_hash_table (info
)->dynamic_sections_created
)
6413 /* If this symbol is not defined in a regular file, then set
6414 the symbol to the stub location. This is required to make
6415 function pointers compare as equal between the normal
6416 executable and the shared library. */
6417 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6419 /* We need .stub section. */
6420 s
= bfd_get_section_by_name (dynobj
, ".stub");
6421 BFD_ASSERT (s
!= NULL
);
6423 h
->root
.u
.def
.section
= s
;
6424 h
->root
.u
.def
.value
= s
->_raw_size
;
6426 /* XXX Write this stub address somewhere. */
6427 h
->plt_offset
= s
->_raw_size
;
6429 /* Make room for this stub code. */
6430 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6432 /* The last half word of the stub will be filled with the index
6433 of this symbol in .dynsym section. */
6438 /* If this is a weak symbol, and there is a real definition, the
6439 processor independent code will have arranged for us to see the
6440 real definition first, and we can just use the same value. */
6441 if (h
->weakdef
!= NULL
)
6443 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
6444 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
6445 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
6446 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
6450 /* This is a reference to a symbol defined by a dynamic object which
6451 is not a function. */
6456 /* This function is called after all the input files have been read,
6457 and the input sections have been assigned to output sections. We
6458 check for any mips16 stub sections that we can discard. */
6460 static boolean mips_elf_check_mips16_stubs
6461 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
6464 mips_elf_always_size_sections (output_bfd
, info
)
6466 struct bfd_link_info
*info
;
6468 if (info
->relocateable
6469 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
6472 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
6473 mips_elf_check_mips16_stubs
,
6479 /* Check the mips16 stubs for a particular symbol, and see if we can
6484 mips_elf_check_mips16_stubs (h
, data
)
6485 struct mips_elf_link_hash_entry
*h
;
6488 if (h
->fn_stub
!= NULL
6489 && ! h
->need_fn_stub
)
6491 /* We don't need the fn_stub; the only references to this symbol
6492 are 16 bit calls. Clobber the size to 0 to prevent it from
6493 being included in the link. */
6494 h
->fn_stub
->_raw_size
= 0;
6495 h
->fn_stub
->_cooked_size
= 0;
6496 h
->fn_stub
->flags
&= ~ SEC_RELOC
;
6497 h
->fn_stub
->reloc_count
= 0;
6498 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
6501 if (h
->call_stub
!= NULL
6502 && h
->root
.other
== STO_MIPS16
)
6504 /* We don't need the call_stub; this is a 16 bit function, so
6505 calls from other 16 bit functions are OK. Clobber the size
6506 to 0 to prevent it from being included in the link. */
6507 h
->call_stub
->_raw_size
= 0;
6508 h
->call_stub
->_cooked_size
= 0;
6509 h
->call_stub
->flags
&= ~ SEC_RELOC
;
6510 h
->call_stub
->reloc_count
= 0;
6511 h
->call_stub
->flags
|= SEC_EXCLUDE
;
6514 if (h
->call_fp_stub
!= NULL
6515 && h
->root
.other
== STO_MIPS16
)
6517 /* We don't need the call_stub; this is a 16 bit function, so
6518 calls from other 16 bit functions are OK. Clobber the size
6519 to 0 to prevent it from being included in the link. */
6520 h
->call_fp_stub
->_raw_size
= 0;
6521 h
->call_fp_stub
->_cooked_size
= 0;
6522 h
->call_fp_stub
->flags
&= ~ SEC_RELOC
;
6523 h
->call_fp_stub
->reloc_count
= 0;
6524 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
6530 /* Set the sizes of the dynamic sections. */
6533 mips_elf_size_dynamic_sections (output_bfd
, info
)
6535 struct bfd_link_info
*info
;
6541 struct mips_got_info
*g
;
6543 dynobj
= elf_hash_table (info
)->dynobj
;
6544 BFD_ASSERT (dynobj
!= NULL
);
6546 if (elf_hash_table (info
)->dynamic_sections_created
)
6548 /* Set the contents of the .interp section to the interpreter. */
6551 s
= bfd_get_section_by_name (dynobj
, ".interp");
6552 BFD_ASSERT (s
!= NULL
);
6553 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
6554 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
6558 /* Recompute the size of .got for local entires (reserved and
6559 hipages) if needed. To estimate it, get the upper bound of total
6560 size of loadable sections. */
6561 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6565 bfd_size_type loadable_size
= 0;
6566 bfd_size_type local_gotno
;
6569 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6570 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6571 BFD_ASSERT (g
!= NULL
);
6573 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
6574 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
6576 if ((s
->flags
& SEC_ALLOC
) == 0)
6578 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
6581 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
6583 /* Assume there are two loadable segments consisting of
6584 contiguous sections. Is 5 enough? */
6585 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
6586 g
->local_gotno
= local_gotno
;
6587 sgot
->_raw_size
+= local_gotno
* 4;
6590 /* The check_relocs and adjust_dynamic_symbol entry points have
6591 determined the sizes of the various dynamic sections. Allocate
6594 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
6599 /* It's OK to base decisions on the section name, because none
6600 of the dynobj section names depend upon the input files. */
6601 name
= bfd_get_section_name (dynobj
, s
);
6603 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
6608 if (strncmp (name
, ".rel", 4) == 0)
6610 if (s
->_raw_size
== 0)
6614 const char *outname
;
6617 /* If this relocation section applies to a read only
6618 section, then we probably need a DT_TEXTREL entry.
6619 If the relocation section is .rel.dyn, we always
6620 assert a DT_TEXTREL entry rather than testing whether
6621 there exists a relocation to a read only section or
6623 outname
= bfd_get_section_name (output_bfd
,
6625 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
6627 && (target
->flags
& SEC_READONLY
) != 0
6628 && (target
->flags
& SEC_ALLOC
) != 0)
6629 || strcmp (outname
, ".rel.dyn") == 0)
6632 /* We use the reloc_count field as a counter if we need
6633 to copy relocs into the output file. */
6634 if (strcmp (name
, ".rel.dyn") != 0)
6638 else if (strncmp (name
, ".got", 4) == 0)
6642 BFD_ASSERT (elf_section_data (s
) != NULL
);
6643 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
6644 BFD_ASSERT (g
!= NULL
);
6646 /* Fix the size of .got section for the correspondence of
6647 global symbols and got entries. This adds some useless
6648 got entries. Is this required by ABI really? */
6649 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
6650 s
->_raw_size
+= i
* 4;
6652 else if (strncmp (name
, ".stub", 5) == 0)
6654 /* Irix rld assumes that the function stub isn't at the end
6655 of .text section. So put a dummy. XXX */
6656 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6658 else if (! info
->shared
6659 && ! mips_elf_hash_table (info
)->use_rld_obj_head
6660 && strncmp (name
, ".rld_map", 8) == 0)
6662 /* We add a room for __rld_map. It will be filled in by the
6663 rtld to contain a pointer to the _r_debug structure. */
6666 else if (SGI_COMPAT (output_bfd
)
6667 && strncmp (name
, ".compact_rel", 12) == 0)
6668 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
6669 else if (strncmp (name
, ".init", 5) != 0)
6671 /* It's not one of our sections, so don't allocate space. */
6679 for (spp
= &s
->output_section
->owner
->sections
;
6680 *spp
!= s
->output_section
;
6681 spp
= &(*spp
)->next
)
6683 *spp
= s
->output_section
->next
;
6684 --s
->output_section
->owner
->section_count
;
6689 /* Allocate memory for the section contents. */
6690 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
6691 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
6693 bfd_set_error (bfd_error_no_memory
);
6696 memset (s
->contents
, 0, s
->_raw_size
);
6699 if (elf_hash_table (info
)->dynamic_sections_created
)
6701 /* Add some entries to the .dynamic section. We fill in the
6702 values later, in elf_mips_finish_dynamic_sections, but we
6703 must add the entries now so that we get the correct size for
6704 the .dynamic section. The DT_DEBUG entry is filled in by the
6705 dynamic linker and used by the debugger. */
6708 if (SGI_COMPAT (output_bfd
))
6710 /* SGI object has the equivalence of DT_DEBUG in the
6711 DT_MIPS_RLD_MAP entry. */
6712 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
6716 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
6722 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
6726 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
6729 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
6731 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
6734 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
6737 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
6741 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
6744 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
6747 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
6749 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
6752 s
= bfd_get_section_by_name (dynobj
, ".liblist");
6753 BFD_ASSERT (s
!= NULL
);
6755 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
6759 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
6762 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
6766 /* Time stamps in executable files are a bad idea. */
6767 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
6772 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
6777 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
6781 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
6784 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
6787 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
6790 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
6793 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
6796 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
6799 #if 0 /* (SGI_COMPAT) */
6800 if (! bfd_get_section_by_name (dynobj
, ".init"))
6801 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
6804 if (! bfd_get_section_by_name (dynobj
, ".fini"))
6805 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
6810 /* If we use dynamic linking, we generate a section symbol for each
6811 output section. These are local symbols, which means that they
6812 must come first in the dynamic symbol table.
6813 That means we must increment the dynamic symbol index of every
6814 other dynamic symbol. */
6816 const char * const *namep
;
6818 bfd_size_type strindex
;
6819 struct bfd_strtab_hash
*dynstr
;
6820 struct mips_got_info
*g
;
6823 if (elf_hash_table (info
)->dynamic_sections_created
)
6825 if (SGI_COMPAT (output_bfd
))
6827 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
6828 elf_link_hash_traverse (elf_hash_table (info
),
6829 mips_elf_adjust_dynindx
,
6831 elf_hash_table (info
)->dynsymcount
+= c
;
6833 dynstr
= elf_hash_table (info
)->dynstr
;
6834 BFD_ASSERT (dynstr
!= NULL
);
6836 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
6840 s
= bfd_get_section_by_name (output_bfd
, *namep
);
6842 elf_section_data (s
)->dynindx
= i
;
6844 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
6845 if (strindex
== (bfd_size_type
) -1)
6848 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
6853 c
= bfd_count_sections (output_bfd
);
6854 elf_link_hash_traverse (elf_hash_table (info
),
6855 mips_elf_adjust_dynindx
,
6857 elf_hash_table (info
)->dynsymcount
+= c
;
6859 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
6861 elf_section_data (s
)->dynindx
= i
;
6862 /* These symbols will have no names, so we don't need to
6863 fiddle with dynstr_index. */
6870 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6871 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6872 BFD_ASSERT (g
!= NULL
);
6874 /* If there are no global got symbols, fake the last symbol so
6876 if (g
->global_gotsym
)
6877 g
->global_gotsym
+= c
;
6879 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
6886 /* Increment the index of a dynamic symbol by a given amount. Called
6887 via elf_link_hash_traverse. */
6890 mips_elf_adjust_dynindx (h
, cparg
)
6891 struct elf_link_hash_entry
*h
;
6894 unsigned int *cp
= (unsigned int *) cparg
;
6896 if (h
->dynindx
!= -1)
6901 /* Finish up dynamic symbol handling. We set the contents of various
6902 dynamic sections here. */
6905 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
6907 struct bfd_link_info
*info
;
6908 struct elf_link_hash_entry
*h
;
6909 Elf_Internal_Sym
*sym
;
6914 struct mips_got_info
*g
;
6917 dynobj
= elf_hash_table (info
)->dynobj
;
6918 gval
= sym
->st_value
;
6920 if (h
->plt_offset
!= (bfd_vma
) -1)
6924 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
6926 /* This symbol has a stub. Set it up. */
6928 BFD_ASSERT (h
->dynindx
!= -1);
6930 s
= bfd_get_section_by_name (dynobj
, ".stub");
6931 BFD_ASSERT (s
!= NULL
);
6933 /* Fill the stub. */
6935 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
6937 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
6940 /* FIXME: Can h->dynindex be more than 64K? */
6941 if (h
->dynindx
& 0xffff0000)
6944 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
6946 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
6948 BFD_ASSERT (h
->plt_offset
<= s
->_raw_size
);
6949 memcpy (s
->contents
+ h
->plt_offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
6951 /* Mark the symbol as undefined. plt_offset != -1 occurs
6952 only for the referenced symbol. */
6953 sym
->st_shndx
= SHN_UNDEF
;
6955 /* The run-time linker uses the st_value field of the symbol
6956 to reset the global offset table entry for this external
6957 to its stub address when unlinking a shared object. */
6958 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt_offset
;
6959 sym
->st_value
= gval
;
6962 BFD_ASSERT (h
->dynindx
!= -1);
6964 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6965 BFD_ASSERT (sgot
!= NULL
);
6966 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6967 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6968 BFD_ASSERT (g
!= NULL
);
6970 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
6972 bfd_size_type offset
;
6974 /* This symbol has an entry in the global offset table. Set its
6975 value to the corresponding got entry, if needed. */
6976 if (h
->got_offset
== (bfd_vma
) -1)
6978 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
6979 BFD_ASSERT (g
->local_gotno
* 4 <= offset
6980 && offset
< sgot
->_raw_size
);
6981 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
6985 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
6986 name
= h
->root
.root
.string
;
6987 if (strcmp (name
, "_DYNAMIC") == 0
6988 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
6989 sym
->st_shndx
= SHN_ABS
;
6990 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
6992 sym
->st_shndx
= SHN_ABS
;
6993 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6996 else if (SGI_COMPAT (output_bfd
))
6998 if (strcmp (name
, "_gp_disp") == 0)
7000 sym
->st_shndx
= SHN_ABS
;
7001 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7002 sym
->st_value
= elf_gp (output_bfd
);
7004 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
7005 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
7007 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7008 sym
->st_other
= STO_PROTECTED
;
7010 sym
->st_shndx
= SHN_MIPS_DATA
;
7012 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
7014 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7015 sym
->st_other
= STO_PROTECTED
;
7016 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
7017 sym
->st_shndx
= SHN_ABS
;
7019 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
7021 if (h
->type
== STT_FUNC
)
7022 sym
->st_shndx
= SHN_MIPS_TEXT
;
7023 else if (h
->type
== STT_OBJECT
)
7024 sym
->st_shndx
= SHN_MIPS_DATA
;
7028 if (SGI_COMPAT (output_bfd
)
7031 if (! mips_elf_hash_table (info
)->use_rld_obj_head
7032 && strcmp (name
, "__rld_map") == 0)
7034 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7035 BFD_ASSERT (s
!= NULL
);
7036 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
7037 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
7038 if (mips_elf_hash_table (info
)->rld_value
== 0)
7039 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7041 else if (mips_elf_hash_table (info
)->use_rld_obj_head
7042 && strcmp (name
, "__rld_obj_head") == 0)
7044 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7045 BFD_ASSERT (s
!= NULL
);
7046 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7050 /* If this is a mips16 symbol, force the value to be even. */
7051 if (sym
->st_other
== STO_MIPS16
7052 && (sym
->st_value
& 1) != 0)
7058 /* Finish up the dynamic sections. */
7061 mips_elf_finish_dynamic_sections (output_bfd
, info
)
7063 struct bfd_link_info
*info
;
7068 struct mips_got_info
*g
;
7070 dynobj
= elf_hash_table (info
)->dynobj
;
7072 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
7074 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7079 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7080 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7081 BFD_ASSERT (g
!= NULL
);
7084 if (elf_hash_table (info
)->dynamic_sections_created
)
7086 Elf32_External_Dyn
*dyncon
, *dynconend
;
7088 BFD_ASSERT (sdyn
!= NULL
);
7089 BFD_ASSERT (g
!= NULL
);
7091 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7092 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
7093 for (; dyncon
< dynconend
; dyncon
++)
7095 Elf_Internal_Dyn dyn
;
7100 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
7108 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7109 BFD_ASSERT (s
!= NULL
);
7110 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
7111 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7115 /* Rewrite DT_STRSZ. */
7117 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
7118 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7124 case DT_MIPS_CONFLICT
:
7127 case DT_MIPS_LIBLIST
:
7130 s
= bfd_get_section_by_name (output_bfd
, name
);
7131 BFD_ASSERT (s
!= NULL
);
7132 dyn
.d_un
.d_ptr
= s
->vma
;
7133 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7136 case DT_MIPS_RLD_VERSION
:
7137 dyn
.d_un
.d_val
= 1; /* XXX */
7138 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7142 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
7143 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7146 case DT_MIPS_CONFLICTNO
:
7148 elemsize
= sizeof (Elf32_Conflict
);
7151 case DT_MIPS_LIBLISTNO
:
7153 elemsize
= sizeof (Elf32_Lib
);
7155 s
= bfd_get_section_by_name (output_bfd
, name
);
7158 if (s
->_cooked_size
!= 0)
7159 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7161 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7166 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7169 case DT_MIPS_TIME_STAMP
:
7170 time ((time_t *) &dyn
.d_un
.d_val
);
7171 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7174 case DT_MIPS_ICHECKSUM
:
7178 case DT_MIPS_IVERSION
:
7182 case DT_MIPS_BASE_ADDRESS
:
7183 s
= output_bfd
->sections
;
7184 BFD_ASSERT (s
!= NULL
);
7185 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
7186 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7189 case DT_MIPS_LOCAL_GOTNO
:
7190 dyn
.d_un
.d_val
= g
->local_gotno
;
7191 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7194 case DT_MIPS_SYMTABNO
:
7196 elemsize
= sizeof (Elf32_External_Sym
);
7197 s
= bfd_get_section_by_name (output_bfd
, name
);
7198 BFD_ASSERT (s
!= NULL
);
7200 if (s
->_cooked_size
!= 0)
7201 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7203 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7204 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7207 case DT_MIPS_UNREFEXTNO
:
7209 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
7210 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7213 case DT_MIPS_GOTSYM
:
7214 dyn
.d_un
.d_val
= g
->global_gotsym
;
7215 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7218 case DT_MIPS_HIPAGENO
:
7219 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
7220 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7223 case DT_MIPS_RLD_MAP
:
7224 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
7225 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7232 /* The first entry of the global offset table will be filled at
7233 runtime. The second entry will be used by some runtime loaders.
7234 This isn't the case of Irix rld. */
7235 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
7237 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
7238 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
7242 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
7249 Elf_Internal_Sym sym
;
7252 const char * const * namep
= mips_elf_dynsym_sec_names
;
7253 Elf32_compact_rel cpt
;
7255 /* Set up the section symbols for the output sections. SGI sets
7256 the STT_NOTYPE attribute for these symbols. Should we do so? */
7258 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
7259 if (sdynsym
!= NULL
)
7261 if (SGI_COMPAT (output_bfd
))
7265 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7271 while ((name
= *namep
++) != NULL
)
7273 s
= bfd_get_section_by_name (output_bfd
, name
);
7276 sym
.st_value
= s
->vma
;
7277 dindx
= elf_section_data (s
)->dynindx
;
7278 last
= s
->vma
+ s
->_raw_size
;
7282 sym
.st_value
= last
;
7286 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
7291 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
7293 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7294 (((Elf32_External_Sym
*)
7299 /* Set the sh_info field of the output .dynsym section to
7300 the index of the first global symbol. */
7301 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7302 SIZEOF_MIPS_DYNSYM_SECNAMES
;
7308 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
7311 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
7315 sym
.st_value
= s
->vma
;
7317 indx
= elf_section_data (s
)->this_idx
;
7318 BFD_ASSERT (indx
> 0);
7319 sym
.st_shndx
= indx
;
7321 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7322 (((Elf32_External_Sym
*)
7324 + elf_section_data (s
)->dynindx
));
7327 /* Set the sh_info field of the output .dynsym section to
7328 the index of the first global symbol. */
7329 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7330 bfd_count_sections (output_bfd
) + 1;
7334 if (SGI_COMPAT (output_bfd
))
7336 /* Write .compact_rel section out. */
7337 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
7341 cpt
.num
= s
->reloc_count
;
7343 cpt
.offset
= (s
->output_section
->filepos
7344 + sizeof (Elf32_External_compact_rel
));
7347 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
7348 ((Elf32_External_compact_rel
*)
7351 /* Clean up a dummy stub function entry in .text. */
7352 s
= bfd_get_section_by_name (dynobj
, ".stub");
7355 file_ptr dummy_offset
;
7357 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
7358 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
7359 memset (s
->contents
+ dummy_offset
, 0,
7360 MIPS_FUNCTION_STUB_SIZE
);
7365 /* Clean up a first relocation in .rel.dyn. */
7366 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7367 if (s
!= NULL
&& s
->_raw_size
> 0)
7368 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
7374 /* This is almost identical to bfd_generic_get_... except that some
7375 MIPS relocations need to be handled specially. Sigh. */
7378 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
7379 relocateable
, symbols
)
7381 struct bfd_link_info
*link_info
;
7382 struct bfd_link_order
*link_order
;
7384 boolean relocateable
;
7387 /* Get enough memory to hold the stuff */
7388 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
7389 asection
*input_section
= link_order
->u
.indirect
.section
;
7391 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
7392 arelent
**reloc_vector
= NULL
;
7398 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
7399 if (reloc_vector
== NULL
&& reloc_size
!= 0)
7402 /* read in the section */
7403 if (!bfd_get_section_contents (input_bfd
,
7407 input_section
->_raw_size
))
7410 /* We're not relaxing the section, so just copy the size info */
7411 input_section
->_cooked_size
= input_section
->_raw_size
;
7412 input_section
->reloc_done
= true;
7414 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
7418 if (reloc_count
< 0)
7421 if (reloc_count
> 0)
7426 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
7429 struct bfd_hash_entry
*h
;
7430 struct bfd_link_hash_entry
*lh
;
7431 /* Skip all this stuff if we aren't mixing formats. */
7432 if (abfd
&& input_bfd
7433 && abfd
->xvec
== input_bfd
->xvec
)
7437 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
7438 lh
= (struct bfd_link_hash_entry
*) h
;
7445 case bfd_link_hash_undefined
:
7446 case bfd_link_hash_undefweak
:
7447 case bfd_link_hash_common
:
7450 case bfd_link_hash_defined
:
7451 case bfd_link_hash_defweak
:
7453 gp
= lh
->u
.def
.value
;
7455 case bfd_link_hash_indirect
:
7456 case bfd_link_hash_warning
:
7458 /* @@FIXME ignoring warning for now */
7460 case bfd_link_hash_new
:
7469 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
7472 char *error_message
= (char *) NULL
;
7473 bfd_reloc_status_type r
;
7475 /* Specific to MIPS: Deal with relocation types that require
7476 knowing the gp of the output bfd. */
7477 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
7478 if (bfd_is_abs_section (sym
->section
) && abfd
)
7480 /* The special_function wouldn't get called anyways. */
7484 /* The gp isn't there; let the special function code
7485 fall over on its own. */
7487 else if ((*parent
)->howto
->special_function
7488 == _bfd_mips_elf_gprel16_reloc
)
7490 /* bypass special_function call */
7491 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
7492 relocateable
, (PTR
) data
, gp
);
7493 goto skip_bfd_perform_relocation
;
7495 /* end mips specific stuff */
7497 r
= bfd_perform_relocation (input_bfd
,
7501 relocateable
? abfd
: (bfd
*) NULL
,
7503 skip_bfd_perform_relocation
:
7507 asection
*os
= input_section
->output_section
;
7509 /* A partial link, so keep the relocs */
7510 os
->orelocation
[os
->reloc_count
] = *parent
;
7514 if (r
!= bfd_reloc_ok
)
7518 case bfd_reloc_undefined
:
7519 if (!((*link_info
->callbacks
->undefined_symbol
)
7520 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7521 input_bfd
, input_section
, (*parent
)->address
)))
7524 case bfd_reloc_dangerous
:
7525 BFD_ASSERT (error_message
!= (char *) NULL
);
7526 if (!((*link_info
->callbacks
->reloc_dangerous
)
7527 (link_info
, error_message
, input_bfd
, input_section
,
7528 (*parent
)->address
)))
7531 case bfd_reloc_overflow
:
7532 if (!((*link_info
->callbacks
->reloc_overflow
)
7533 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7534 (*parent
)->howto
->name
, (*parent
)->addend
,
7535 input_bfd
, input_section
, (*parent
)->address
)))
7538 case bfd_reloc_outofrange
:
7547 if (reloc_vector
!= NULL
)
7548 free (reloc_vector
);
7552 if (reloc_vector
!= NULL
)
7553 free (reloc_vector
);
7556 #define bfd_elf32_bfd_get_relocated_section_contents \
7557 elf32_mips_get_relocated_section_contents
7559 /* ECOFF swapping routines. These are used when dealing with the
7560 .mdebug section, which is in the ECOFF debugging format. */
7561 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
7563 /* Symbol table magic number. */
7565 /* Alignment of debugging information. E.g., 4. */
7567 /* Sizes of external symbolic information. */
7568 sizeof (struct hdr_ext
),
7569 sizeof (struct dnr_ext
),
7570 sizeof (struct pdr_ext
),
7571 sizeof (struct sym_ext
),
7572 sizeof (struct opt_ext
),
7573 sizeof (struct fdr_ext
),
7574 sizeof (struct rfd_ext
),
7575 sizeof (struct ext_ext
),
7576 /* Functions to swap in external symbolic data. */
7585 _bfd_ecoff_swap_tir_in
,
7586 _bfd_ecoff_swap_rndx_in
,
7587 /* Functions to swap out external symbolic data. */
7596 _bfd_ecoff_swap_tir_out
,
7597 _bfd_ecoff_swap_rndx_out
,
7598 /* Function to read in symbolic data. */
7599 _bfd_mips_elf_read_ecoff_info
7602 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
7603 #define TARGET_LITTLE_NAME "elf32-littlemips"
7604 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
7605 #define TARGET_BIG_NAME "elf32-bigmips"
7606 #define ELF_ARCH bfd_arch_mips
7607 #define ELF_MACHINE_CODE EM_MIPS
7609 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
7610 a value of 0x1000, and we are compatible. */
7611 #define ELF_MAXPAGESIZE 0x1000
7613 #define elf_backend_collect true
7614 #define elf_backend_type_change_ok true
7615 #define elf_info_to_howto 0
7616 #define elf_info_to_howto_rel mips_info_to_howto_rel
7617 #define elf_backend_sym_is_global mips_elf_sym_is_global
7618 #define elf_backend_object_p mips_elf32_object_p
7619 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
7620 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
7621 #define elf_backend_section_from_bfd_section \
7622 _bfd_mips_elf_section_from_bfd_section
7623 #define elf_backend_section_processing mips_elf32_section_processing
7624 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
7625 #define elf_backend_additional_program_headers \
7626 mips_elf_additional_program_headers
7627 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
7628 #define elf_backend_final_write_processing \
7629 _bfd_mips_elf_final_write_processing
7630 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
7632 #define bfd_elf32_bfd_is_local_label_name \
7633 mips_elf_is_local_label_name
7634 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
7635 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
7636 #define bfd_elf32_bfd_link_hash_table_create \
7637 mips_elf_link_hash_table_create
7638 #define bfd_elf32_bfd_final_link mips_elf_final_link
7639 #define bfd_elf32_bfd_copy_private_bfd_data \
7640 _bfd_mips_elf_copy_private_bfd_data
7641 #define bfd_elf32_bfd_merge_private_bfd_data \
7642 _bfd_mips_elf_merge_private_bfd_data
7643 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
7644 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
7645 #define elf_backend_create_dynamic_sections \
7646 mips_elf_create_dynamic_sections
7647 #define elf_backend_check_relocs mips_elf_check_relocs
7648 #define elf_backend_adjust_dynamic_symbol \
7649 mips_elf_adjust_dynamic_symbol
7650 #define elf_backend_always_size_sections \
7651 mips_elf_always_size_sections
7652 #define elf_backend_size_dynamic_sections \
7653 mips_elf_size_dynamic_sections
7654 #define elf_backend_relocate_section mips_elf_relocate_section
7655 #define elf_backend_link_output_symbol_hook \
7656 mips_elf_link_output_symbol_hook
7657 #define elf_backend_finish_dynamic_symbol \
7658 mips_elf_finish_dynamic_symbol
7659 #define elf_backend_finish_dynamic_sections \
7660 mips_elf_finish_dynamic_sections
7662 #include "elf32-target.h"