1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996, 1997 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 boolean mips_elf32_section_from_shdr
63 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, char *));
64 static boolean mips_elf32_section_processing
65 PARAMS ((bfd
*, Elf32_Internal_Shdr
*));
66 static boolean mips_elf_is_local_label_name
67 PARAMS ((bfd
*, const char *));
68 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
69 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
70 static struct bfd_link_hash_table
*mips_elf_link_hash_table_create
72 static int gptab_compare
PARAMS ((const void *, const void *));
73 static boolean mips_elf_final_link
74 PARAMS ((bfd
*, struct bfd_link_info
*));
75 static void mips_elf_relocate_hi16
76 PARAMS ((bfd
*, Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_byte
*,
78 static boolean mips_elf_relocate_got_local
79 PARAMS ((bfd
*, bfd
*, asection
*, Elf_Internal_Rela
*,
80 Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
81 static void mips_elf_relocate_global_got
82 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
83 static bfd_reloc_status_type mips16_jump_reloc
84 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
85 static bfd_reloc_status_type mips16_gprel_reloc
86 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
87 static boolean mips_elf_adjust_dynindx
88 PARAMS ((struct elf_link_hash_entry
*, PTR
));
89 static boolean mips_elf_relocate_section
90 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
91 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
92 static boolean mips_elf_link_output_symbol_hook
93 PARAMS ((bfd
*, struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
95 static boolean mips_elf_create_dynamic_sections
96 PARAMS ((bfd
*, struct bfd_link_info
*));
97 static boolean mips_elf_create_compact_rel_section
98 PARAMS ((bfd
*, struct bfd_link_info
*));
99 static boolean mips_elf_create_got_section
100 PARAMS ((bfd
*, struct bfd_link_info
*));
101 static boolean mips_elf_check_relocs
102 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
103 const Elf_Internal_Rela
*));
104 static boolean mips_elf_adjust_dynamic_symbol
105 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
106 static boolean mips_elf_always_size_sections
107 PARAMS ((bfd
*, struct bfd_link_info
*));
108 static boolean mips_elf_size_dynamic_sections
109 PARAMS ((bfd
*, struct bfd_link_info
*));
110 static boolean mips_elf_finish_dynamic_symbol
111 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
112 Elf_Internal_Sym
*));
113 static boolean mips_elf_finish_dynamic_sections
114 PARAMS ((bfd
*, struct bfd_link_info
*));
115 static boolean mips_elf_add_symbol_hook
116 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
117 const char **, flagword
*, asection
**, bfd_vma
*));
118 static bfd_reloc_status_type mips_elf_final_gp
119 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
120 static bfd_byte
*elf32_mips_get_relocated_section_contents
121 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
122 bfd_byte
*, boolean
, asymbol
**));
124 /* This is true for Irix 5 executables, false for normal MIPS ELF ABI
125 executables. FIXME: At the moment, we default to always generating
126 Irix 5 executables. */
128 #define SGI_COMPAT(abfd) (1)
130 /* This structure is used to hold .got information when linking. It
131 is stored in the tdata field of the bfd_elf_section_data structure. */
135 /* The symbol index of the first global .got symbol. */
136 unsigned long global_gotsym
;
137 /* The number of local .got entries. */
138 unsigned int local_gotno
;
139 /* The number of local .got entries we have used. */
140 unsigned int assigned_gotno
;
143 /* The number of local .got entries we reserve. */
144 #define MIPS_RESERVED_GOTNO (2)
146 /* Instructions which appear in a stub. For some reason the stub is
147 slightly different on an SGI system. */
148 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
149 #define STUB_LW(abfd) \
151 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
152 : 0x8f998000) /* lw t9,0x8000(gp) */
153 #define STUB_MOVE 0x03e07825 /* move t7,ra */
154 #define STUB_JALR 0x0320f809 /* jal t9 */
155 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
156 #define MIPS_FUNCTION_STUB_SIZE (16)
158 /* Names of sections which appear in the .dynsym section in an Irix 5
161 static const char * const mips_elf_dynsym_sec_names
[] =
174 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
175 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
177 /* The number of entries in mips_elf_dynsym_sec_names which go in the
180 #define MIPS_TEXT_DYNSYM_SECNO (3)
182 /* The names of the runtime procedure table symbols used on Irix 5. */
184 static const char * const mips_elf_dynsym_rtproc_names
[] =
187 "_procedure_string_table",
188 "_procedure_table_size",
192 /* These structures are used to generate the .compact_rel section on
197 unsigned long id1
; /* Always one? */
198 unsigned long num
; /* Number of compact relocation entries. */
199 unsigned long id2
; /* Always two? */
200 unsigned long offset
; /* The file offset of the first relocation. */
201 unsigned long reserved0
; /* Zero? */
202 unsigned long reserved1
; /* Zero? */
211 bfd_byte reserved0
[4];
212 bfd_byte reserved1
[4];
213 } Elf32_External_compact_rel
;
217 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
218 unsigned int rtype
: 4; /* Relocation types. See below. */
219 unsigned int dist2to
: 8;
220 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
221 unsigned long konst
; /* KONST field. See below. */
222 unsigned long vaddr
; /* VADDR to be relocated. */
227 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
228 unsigned int rtype
: 4; /* Relocation types. See below. */
229 unsigned int dist2to
: 8;
230 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
231 unsigned long konst
; /* KONST field. See below. */
239 } Elf32_External_crinfo
;
245 } Elf32_External_crinfo2
;
247 /* These are the constants used to swap the bitfields in a crinfo. */
249 #define CRINFO_CTYPE (0x1)
250 #define CRINFO_CTYPE_SH (31)
251 #define CRINFO_RTYPE (0xf)
252 #define CRINFO_RTYPE_SH (27)
253 #define CRINFO_DIST2TO (0xff)
254 #define CRINFO_DIST2TO_SH (19)
255 #define CRINFO_RELVADDR (0x7ffff)
256 #define CRINFO_RELVADDR_SH (0)
258 /* A compact relocation info has long (3 words) or short (2 words)
259 formats. A short format doesn't have VADDR field and relvaddr
260 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
261 #define CRF_MIPS_LONG 1
262 #define CRF_MIPS_SHORT 0
264 /* There are 4 types of compact relocation at least. The value KONST
265 has different meaning for each type:
268 CT_MIPS_REL32 Address in data
269 CT_MIPS_WORD Address in word (XXX)
270 CT_MIPS_GPHI_LO GP - vaddr
271 CT_MIPS_JMPAD Address to jump
274 #define CRT_MIPS_REL32 0xa
275 #define CRT_MIPS_WORD 0xb
276 #define CRT_MIPS_GPHI_LO 0xc
277 #define CRT_MIPS_JMPAD 0xd
279 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
280 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
281 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
282 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
284 static void bfd_elf32_swap_compact_rel_out
285 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
286 static void bfd_elf32_swap_crinfo_out
287 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
289 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
294 R_MIPS_16
, R_MIPS_32
,
295 R_MIPS_REL32
, R_MIPS_26
,
296 R_MIPS_HI16
, R_MIPS_LO16
,
297 R_MIPS_GPREL16
, R_MIPS_LITERAL
,
298 R_MIPS_GOT16
, R_MIPS_PC16
,
299 R_MIPS_CALL16
, R_MIPS_GPREL32
,
300 /* The remaining relocs are defined on Irix, although they are not
301 in the MIPS ELF ABI. */
302 R_MIPS_UNUSED1
, R_MIPS_UNUSED2
,
304 R_MIPS_SHIFT5
, R_MIPS_SHIFT6
,
305 R_MIPS_64
, R_MIPS_GOT_DISP
,
306 R_MIPS_GOT_PAGE
, R_MIPS_GOT_OFST
,
307 R_MIPS_GOT_HI16
, R_MIPS_GOT_LO16
,
308 R_MIPS_SUB
, R_MIPS_INSERT_A
,
309 R_MIPS_INSERT_B
, R_MIPS_DELETE
,
310 R_MIPS_HIGHER
, R_MIPS_HIGHEST
,
311 R_MIPS_CALL_HI16
, R_MIPS_CALL_LO16
,
313 /* These relocs are used for the mips16. */
316 /* start-sanitize-sky */
317 /* These relocs are for the dvp. */
318 , R_MIPS_DVP_11_PCREL
= 120
319 /* end-sanitize-sky */
322 static reloc_howto_type elf_mips_howto_table
[] =
325 HOWTO (R_MIPS_NONE
, /* type */
327 0, /* size (0 = byte, 1 = short, 2 = long) */
329 false, /* pc_relative */
331 complain_overflow_dont
, /* complain_on_overflow */
332 bfd_elf_generic_reloc
, /* special_function */
333 "R_MIPS_NONE", /* name */
334 false, /* partial_inplace */
337 false), /* pcrel_offset */
339 /* 16 bit relocation. */
340 HOWTO (R_MIPS_16
, /* type */
342 1, /* size (0 = byte, 1 = short, 2 = long) */
344 false, /* pc_relative */
346 complain_overflow_bitfield
, /* complain_on_overflow */
347 bfd_elf_generic_reloc
, /* special_function */
348 "R_MIPS_16", /* name */
349 true, /* partial_inplace */
350 0xffff, /* src_mask */
351 0xffff, /* dst_mask */
352 false), /* pcrel_offset */
354 /* 32 bit relocation. */
355 HOWTO (R_MIPS_32
, /* type */
357 2, /* size (0 = byte, 1 = short, 2 = long) */
359 false, /* pc_relative */
361 complain_overflow_bitfield
, /* complain_on_overflow */
362 bfd_elf_generic_reloc
, /* special_function */
363 "R_MIPS_32", /* name */
364 true, /* partial_inplace */
365 0xffffffff, /* src_mask */
366 0xffffffff, /* dst_mask */
367 false), /* pcrel_offset */
369 /* 32 bit symbol relative relocation. */
370 HOWTO (R_MIPS_REL32
, /* type */
372 2, /* size (0 = byte, 1 = short, 2 = long) */
374 false, /* pc_relative */
376 complain_overflow_bitfield
, /* complain_on_overflow */
377 bfd_elf_generic_reloc
, /* special_function */
378 "R_MIPS_REL32", /* name */
379 true, /* partial_inplace */
380 0xffffffff, /* src_mask */
381 0xffffffff, /* dst_mask */
382 false), /* pcrel_offset */
384 /* 26 bit branch address. */
385 HOWTO (R_MIPS_26
, /* type */
387 2, /* size (0 = byte, 1 = short, 2 = long) */
389 false, /* pc_relative */
391 complain_overflow_dont
, /* complain_on_overflow */
392 /* This needs complex overflow
393 detection, because the upper four
394 bits must match the PC. */
395 bfd_elf_generic_reloc
, /* special_function */
396 "R_MIPS_26", /* name */
397 true, /* partial_inplace */
398 0x3ffffff, /* src_mask */
399 0x3ffffff, /* dst_mask */
400 false), /* pcrel_offset */
402 /* High 16 bits of symbol value. */
403 HOWTO (R_MIPS_HI16
, /* type */
405 2, /* size (0 = byte, 1 = short, 2 = long) */
407 false, /* pc_relative */
409 complain_overflow_dont
, /* complain_on_overflow */
410 _bfd_mips_elf_hi16_reloc
, /* special_function */
411 "R_MIPS_HI16", /* name */
412 true, /* partial_inplace */
413 0xffff, /* src_mask */
414 0xffff, /* dst_mask */
415 false), /* pcrel_offset */
417 /* Low 16 bits of symbol value. */
418 HOWTO (R_MIPS_LO16
, /* type */
420 2, /* size (0 = byte, 1 = short, 2 = long) */
422 false, /* pc_relative */
424 complain_overflow_dont
, /* complain_on_overflow */
425 _bfd_mips_elf_lo16_reloc
, /* special_function */
426 "R_MIPS_LO16", /* name */
427 true, /* partial_inplace */
428 0xffff, /* src_mask */
429 0xffff, /* dst_mask */
430 false), /* pcrel_offset */
432 /* GP relative reference. */
433 HOWTO (R_MIPS_GPREL16
, /* type */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
437 false, /* pc_relative */
439 complain_overflow_signed
, /* complain_on_overflow */
440 _bfd_mips_elf_gprel16_reloc
, /* special_function */
441 "R_MIPS_GPREL16", /* name */
442 true, /* partial_inplace */
443 0xffff, /* src_mask */
444 0xffff, /* dst_mask */
445 false), /* pcrel_offset */
447 /* Reference to literal section. */
448 HOWTO (R_MIPS_LITERAL
, /* type */
450 2, /* size (0 = byte, 1 = short, 2 = long) */
452 false, /* pc_relative */
454 complain_overflow_signed
, /* complain_on_overflow */
455 _bfd_mips_elf_gprel16_reloc
, /* special_function */
456 "R_MIPS_LITERAL", /* name */
457 true, /* partial_inplace */
458 0xffff, /* src_mask */
459 0xffff, /* dst_mask */
460 false), /* pcrel_offset */
462 /* Reference to global offset table. */
463 HOWTO (R_MIPS_GOT16
, /* type */
465 2, /* size (0 = byte, 1 = short, 2 = long) */
467 false, /* pc_relative */
469 complain_overflow_signed
, /* complain_on_overflow */
470 _bfd_mips_elf_got16_reloc
, /* special_function */
471 "R_MIPS_GOT16", /* name */
472 false, /* partial_inplace */
474 0xffff, /* dst_mask */
475 false), /* pcrel_offset */
477 /* 16 bit PC relative reference. */
478 HOWTO (R_MIPS_PC16
, /* type */
480 2, /* size (0 = byte, 1 = short, 2 = long) */
482 true, /* pc_relative */
484 complain_overflow_signed
, /* complain_on_overflow */
485 bfd_elf_generic_reloc
, /* special_function */
486 "R_MIPS_PC16", /* name */
487 true, /* partial_inplace */
488 0xffff, /* src_mask */
489 0xffff, /* dst_mask */
490 false), /* pcrel_offset */
492 /* 16 bit call through global offset table. */
493 /* FIXME: This is not handled correctly. */
494 HOWTO (R_MIPS_CALL16
, /* type */
496 2, /* size (0 = byte, 1 = short, 2 = long) */
498 false, /* pc_relative */
500 complain_overflow_signed
, /* complain_on_overflow */
501 bfd_elf_generic_reloc
, /* special_function */
502 "R_MIPS_CALL16", /* name */
503 false, /* partial_inplace */
505 0xffff, /* dst_mask */
506 false), /* pcrel_offset */
508 /* 32 bit GP relative reference. */
509 HOWTO (R_MIPS_GPREL32
, /* type */
511 2, /* size (0 = byte, 1 = short, 2 = long) */
513 false, /* pc_relative */
515 complain_overflow_bitfield
, /* complain_on_overflow */
516 _bfd_mips_elf_gprel32_reloc
, /* special_function */
517 "R_MIPS_GPREL32", /* name */
518 true, /* partial_inplace */
519 0xffffffff, /* src_mask */
520 0xffffffff, /* dst_mask */
521 false), /* pcrel_offset */
523 /* The remaining relocs are defined on Irix 5, although they are
524 not defined by the ABI. */
529 /* A 5 bit shift field. */
530 HOWTO (R_MIPS_SHIFT5
, /* type */
532 2, /* size (0 = byte, 1 = short, 2 = long) */
534 false, /* pc_relative */
536 complain_overflow_bitfield
, /* complain_on_overflow */
537 bfd_elf_generic_reloc
, /* special_function */
538 "R_MIPS_SHIFT5", /* name */
539 true, /* partial_inplace */
540 0x000007c0, /* src_mask */
541 0x000007c0, /* dst_mask */
542 false), /* pcrel_offset */
544 /* A 6 bit shift field. */
545 /* FIXME: This is not handled correctly; a special function is
546 needed to put the most significant bit in the right place. */
547 HOWTO (R_MIPS_SHIFT6
, /* type */
549 2, /* size (0 = byte, 1 = short, 2 = long) */
551 false, /* pc_relative */
553 complain_overflow_bitfield
, /* complain_on_overflow */
554 bfd_elf_generic_reloc
, /* special_function */
555 "R_MIPS_SHIFT6", /* name */
556 true, /* partial_inplace */
557 0x000007c4, /* src_mask */
558 0x000007c4, /* dst_mask */
559 false), /* pcrel_offset */
561 /* A 64 bit relocation. This is used in 32 bit ELF when addresses
562 are 64 bits long; the upper 32 bits are simply a sign extension.
563 The fields of the howto should be the same as for R_MIPS_32,
564 other than the type, name, and special_function. */
565 HOWTO (R_MIPS_64
, /* type */
567 2, /* size (0 = byte, 1 = short, 2 = long) */
569 false, /* pc_relative */
571 complain_overflow_bitfield
, /* complain_on_overflow */
572 mips32_64bit_reloc
, /* special_function */
573 "R_MIPS_64", /* name */
574 true, /* partial_inplace */
575 0xffffffff, /* src_mask */
576 0xffffffff, /* dst_mask */
577 false), /* pcrel_offset */
579 /* Displacement in the global offset table. */
580 /* FIXME: Not handled correctly. */
581 HOWTO (R_MIPS_GOT_DISP
, /* type */
583 2, /* size (0 = byte, 1 = short, 2 = long) */
585 false, /* pc_relative */
587 complain_overflow_bitfield
, /* complain_on_overflow */
588 bfd_elf_generic_reloc
, /* special_function */
589 "R_MIPS_GOT_DISP", /* name */
590 true, /* partial_inplace */
591 0x0000ffff, /* src_mask */
592 0x0000ffff, /* dst_mask */
593 false), /* pcrel_offset */
595 /* Displacement to page pointer in the global offset table. */
596 /* FIXME: Not handled correctly. */
597 HOWTO (R_MIPS_GOT_PAGE
, /* type */
599 2, /* size (0 = byte, 1 = short, 2 = long) */
601 false, /* pc_relative */
603 complain_overflow_bitfield
, /* complain_on_overflow */
604 bfd_elf_generic_reloc
, /* special_function */
605 "R_MIPS_GOT_PAGE", /* name */
606 true, /* partial_inplace */
607 0x0000ffff, /* src_mask */
608 0x0000ffff, /* dst_mask */
609 false), /* pcrel_offset */
611 /* Offset from page pointer in the global offset table. */
612 /* FIXME: Not handled correctly. */
613 HOWTO (R_MIPS_GOT_OFST
, /* type */
615 2, /* size (0 = byte, 1 = short, 2 = long) */
617 false, /* pc_relative */
619 complain_overflow_bitfield
, /* complain_on_overflow */
620 bfd_elf_generic_reloc
, /* special_function */
621 "R_MIPS_GOT_OFST", /* name */
622 true, /* partial_inplace */
623 0x0000ffff, /* src_mask */
624 0x0000ffff, /* dst_mask */
625 false), /* pcrel_offset */
627 /* High 16 bits of displacement in global offset table. */
628 /* FIXME: Not handled correctly. */
629 HOWTO (R_MIPS_GOT_HI16
, /* type */
631 2, /* size (0 = byte, 1 = short, 2 = long) */
633 false, /* pc_relative */
635 complain_overflow_dont
, /* complain_on_overflow */
636 bfd_elf_generic_reloc
, /* special_function */
637 "R_MIPS_GOT_HI16", /* name */
638 true, /* partial_inplace */
639 0x0000ffff, /* src_mask */
640 0x0000ffff, /* dst_mask */
641 false), /* pcrel_offset */
643 /* Low 16 bits of displacement in global offset table. */
644 /* FIXME: Not handled correctly. */
645 HOWTO (R_MIPS_GOT_LO16
, /* type */
647 2, /* size (0 = byte, 1 = short, 2 = long) */
649 false, /* pc_relative */
651 complain_overflow_dont
, /* complain_on_overflow */
652 bfd_elf_generic_reloc
, /* special_function */
653 "R_MIPS_GOT_LO16", /* name */
654 true, /* partial_inplace */
655 0x0000ffff, /* src_mask */
656 0x0000ffff, /* dst_mask */
657 false), /* pcrel_offset */
659 /* 64 bit subtraction. Presumably not used in 32 bit ELF. */
662 /* Used to cause the linker to insert and delete instructions? */
667 /* Get the higher values of a 64 bit addend. Presumably not used in
672 /* High 16 bits of displacement in global offset table. */
673 /* FIXME: Not handled correctly. */
674 HOWTO (R_MIPS_CALL_HI16
, /* type */
676 2, /* size (0 = byte, 1 = short, 2 = long) */
678 false, /* pc_relative */
680 complain_overflow_dont
, /* complain_on_overflow */
681 bfd_elf_generic_reloc
, /* special_function */
682 "R_MIPS_CALL_HI16", /* name */
683 true, /* partial_inplace */
684 0x0000ffff, /* src_mask */
685 0x0000ffff, /* dst_mask */
686 false), /* pcrel_offset */
688 /* Low 16 bits of displacement in global offset table. */
689 /* FIXME: Not handled correctly. */
690 HOWTO (R_MIPS_CALL_LO16
, /* type */
692 2, /* size (0 = byte, 1 = short, 2 = long) */
694 false, /* pc_relative */
696 complain_overflow_dont
, /* complain_on_overflow */
697 bfd_elf_generic_reloc
, /* special_function */
698 "R_MIPS_CALL_LO16", /* name */
699 true, /* partial_inplace */
700 0x0000ffff, /* src_mask */
701 0x0000ffff, /* dst_mask */
702 false) /* pcrel_offset */
705 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
706 is a hack to make the linker think that we need 64 bit values. */
707 static reloc_howto_type elf_mips_ctor64_howto
=
708 HOWTO (R_MIPS_64
, /* type */
710 4, /* size (0 = byte, 1 = short, 2 = long) */
712 false, /* pc_relative */
714 complain_overflow_signed
, /* complain_on_overflow */
715 mips32_64bit_reloc
, /* special_function */
716 "R_MIPS_64", /* name */
717 true, /* partial_inplace */
718 0xffffffff, /* src_mask */
719 0xffffffff, /* dst_mask */
720 false); /* pcrel_offset */
722 /* The reloc used for the mips16 jump instruction. */
723 static reloc_howto_type elf_mips16_jump_howto
=
724 HOWTO (R_MIPS16_26
, /* type */
726 2, /* size (0 = byte, 1 = short, 2 = long) */
728 false, /* pc_relative */
730 complain_overflow_dont
, /* complain_on_overflow */
731 /* This needs complex overflow
732 detection, because the upper four
733 bits must match the PC. */
734 mips16_jump_reloc
, /* special_function */
735 "R_MIPS16_26", /* name */
736 true, /* partial_inplace */
737 0x3ffffff, /* src_mask */
738 0x3ffffff, /* dst_mask */
739 false); /* pcrel_offset */
741 /* The reloc used for the mips16 gprel instruction. The src_mask and
742 dsk_mask for this howto do not reflect the actual instruction, in
743 which the value is not contiguous; the masks are for the
744 convenience of the relocate_section routine. */
745 static reloc_howto_type elf_mips16_gprel_howto
=
746 HOWTO (R_MIPS16_GPREL
, /* type */
748 2, /* size (0 = byte, 1 = short, 2 = long) */
750 false, /* pc_relative */
752 complain_overflow_signed
, /* complain_on_overflow */
753 mips16_gprel_reloc
, /* special_function */
754 "R_MIPS16_GPREL", /* name */
755 true, /* partial_inplace */
756 0xffff, /* src_mask */
757 0xffff, /* dst_mask */
758 false); /* pcrel_offset */
760 /* start-sanitize-sky */
761 /* DVP relocations. */
762 static reloc_howto_type elf_mips_dvp_11_pcrel_howto
=
763 HOWTO (R_MIPS_DVP_11_PCREL
, /* type */
765 2, /* size (0 = byte, 1 = short, 2 = long) */
767 true, /* pc_relative */
769 complain_overflow_signed
, /* complain_on_overflow */
770 bfd_elf_generic_reloc
, /* special_function */
771 "R_MIPS_DVP_11_PCREL", /* name */
772 true, /* partial_inplace */
773 0x7ff, /* src_mask */
774 0x7ff, /* dst_mask */
775 true); /* pcrel_offset */
776 /* end-sanitize-sky */
778 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
779 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
780 the HI16. Here we just save the information we need; we do the
781 actual relocation when we see the LO16. MIPS ELF requires that the
782 LO16 immediately follow the HI16. As a GNU extension, we permit an
783 arbitrary number of HI16 relocs to be associated with a single LO16
784 reloc. This extension permits gcc to output the HI and LO relocs
789 struct mips_hi16
*next
;
794 /* FIXME: This should not be a static variable. */
796 static struct mips_hi16
*mips_hi16_list
;
798 bfd_reloc_status_type
799 _bfd_mips_elf_hi16_reloc (abfd
,
807 arelent
*reloc_entry
;
810 asection
*input_section
;
812 char **error_message
;
814 bfd_reloc_status_type ret
;
818 /* If we're relocating, and this an external symbol, we don't want
819 to change anything. */
820 if (output_bfd
!= (bfd
*) NULL
821 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
822 && reloc_entry
->addend
== 0)
824 reloc_entry
->address
+= input_section
->output_offset
;
830 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
832 boolean relocateable
;
835 if (ret
== bfd_reloc_undefined
)
838 if (output_bfd
!= NULL
)
842 relocateable
= false;
843 output_bfd
= symbol
->section
->output_section
->owner
;
846 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
848 if (ret
!= bfd_reloc_ok
)
851 relocation
= gp
- reloc_entry
->address
;
855 if (bfd_is_und_section (symbol
->section
)
856 && output_bfd
== (bfd
*) NULL
)
857 ret
= bfd_reloc_undefined
;
859 if (bfd_is_com_section (symbol
->section
))
862 relocation
= symbol
->value
;
865 relocation
+= symbol
->section
->output_section
->vma
;
866 relocation
+= symbol
->section
->output_offset
;
867 relocation
+= reloc_entry
->addend
;
869 if (reloc_entry
->address
> input_section
->_cooked_size
)
870 return bfd_reloc_outofrange
;
872 /* Save the information, and let LO16 do the actual relocation. */
873 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
875 return bfd_reloc_outofrange
;
876 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
877 n
->addend
= relocation
;
878 n
->next
= mips_hi16_list
;
881 if (output_bfd
!= (bfd
*) NULL
)
882 reloc_entry
->address
+= input_section
->output_offset
;
887 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
888 inplace relocation; this function exists in order to do the
889 R_MIPS_HI16 relocation described above. */
891 bfd_reloc_status_type
892 _bfd_mips_elf_lo16_reloc (abfd
,
900 arelent
*reloc_entry
;
903 asection
*input_section
;
905 char **error_message
;
907 arelent gp_disp_relent
;
909 if (mips_hi16_list
!= NULL
)
919 struct mips_hi16
*next
;
921 /* Do the HI16 relocation. Note that we actually don't need
922 to know anything about the LO16 itself, except where to
923 find the low 16 bits of the addend needed by the LO16. */
924 insn
= bfd_get_32 (abfd
, l
->addr
);
925 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
927 val
= ((insn
& 0xffff) << 16) + vallo
;
930 /* The low order 16 bits are always treated as a signed
931 value. Therefore, a negative value in the low order bits
932 requires an adjustment in the high order bits. We need
933 to make this adjustment in two ways: once for the bits we
934 took from the data, and once for the bits we are putting
935 back in to the data. */
936 if ((vallo
& 0x8000) != 0)
938 if ((val
& 0x8000) != 0)
941 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
942 bfd_put_32 (abfd
, insn
, l
->addr
);
944 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
946 gp_disp_relent
= *reloc_entry
;
947 reloc_entry
= &gp_disp_relent
;
948 reloc_entry
->addend
= l
->addend
;
956 mips_hi16_list
= NULL
;
958 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
960 bfd_reloc_status_type ret
;
961 bfd_vma gp
, relocation
;
963 /* FIXME: Does this case ever occur? */
965 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
966 if (ret
!= bfd_reloc_ok
)
969 relocation
= gp
- reloc_entry
->address
;
970 relocation
+= symbol
->section
->output_section
->vma
;
971 relocation
+= symbol
->section
->output_offset
;
972 relocation
+= reloc_entry
->addend
;
974 if (reloc_entry
->address
> input_section
->_cooked_size
)
975 return bfd_reloc_outofrange
;
977 gp_disp_relent
= *reloc_entry
;
978 reloc_entry
= &gp_disp_relent
;
979 reloc_entry
->addend
= relocation
- 4;
982 /* Now do the LO16 reloc in the usual way. */
983 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
984 input_section
, output_bfd
, error_message
);
987 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
988 table used for PIC code. If the symbol is an external symbol, the
989 instruction is modified to contain the offset of the appropriate
990 entry in the global offset table. If the symbol is a section
991 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
992 addends are combined to form the real addend against the section
993 symbol; the GOT16 is modified to contain the offset of an entry in
994 the global offset table, and the LO16 is modified to offset it
995 appropriately. Thus an offset larger than 16 bits requires a
996 modified value in the global offset table.
998 This implementation suffices for the assembler, but the linker does
999 not yet know how to create global offset tables. */
1001 bfd_reloc_status_type
1002 _bfd_mips_elf_got16_reloc (abfd
,
1010 arelent
*reloc_entry
;
1013 asection
*input_section
;
1015 char **error_message
;
1017 /* If we're relocating, and this an external symbol, we don't want
1018 to change anything. */
1019 if (output_bfd
!= (bfd
*) NULL
1020 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1021 && reloc_entry
->addend
== 0)
1023 reloc_entry
->address
+= input_section
->output_offset
;
1024 return bfd_reloc_ok
;
1027 /* If we're relocating, and this is a local symbol, we can handle it
1029 if (output_bfd
!= (bfd
*) NULL
1030 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1031 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1032 input_section
, output_bfd
, error_message
);
1037 /* We have to figure out the gp value, so that we can adjust the
1038 symbol value correctly. We look up the symbol _gp in the output
1039 BFD. If we can't find it, we're stuck. We cache it in the ELF
1040 target data. We don't need to adjust the symbol value for an
1041 external symbol if we are producing relocateable output. */
1043 static bfd_reloc_status_type
1044 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1047 boolean relocateable
;
1048 char **error_message
;
1051 if (bfd_is_und_section (symbol
->section
)
1055 return bfd_reloc_undefined
;
1058 *pgp
= _bfd_get_gp_value (output_bfd
);
1061 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1065 /* Make up a value. */
1066 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1067 _bfd_set_gp_value (output_bfd
, *pgp
);
1075 count
= bfd_get_symcount (output_bfd
);
1076 sym
= bfd_get_outsymbols (output_bfd
);
1078 if (sym
== (asymbol
**) NULL
)
1082 for (i
= 0; i
< count
; i
++, sym
++)
1084 register CONST
char *name
;
1086 name
= bfd_asymbol_name (*sym
);
1087 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1089 *pgp
= bfd_asymbol_value (*sym
);
1090 _bfd_set_gp_value (output_bfd
, *pgp
);
1098 /* Only get the error once. */
1100 _bfd_set_gp_value (output_bfd
, *pgp
);
1102 (char *) "GP relative relocation when _gp not defined";
1103 return bfd_reloc_dangerous
;
1108 return bfd_reloc_ok
;
1111 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1112 become the offset from the gp register. This function also handles
1113 R_MIPS_LITERAL relocations, although those can be handled more
1114 cleverly because the entries in the .lit8 and .lit4 sections can be
1117 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1118 arelent
*, asection
*,
1119 boolean
, PTR
, bfd_vma
));
1121 bfd_reloc_status_type
1122 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1123 output_bfd
, error_message
)
1125 arelent
*reloc_entry
;
1128 asection
*input_section
;
1130 char **error_message
;
1132 boolean relocateable
;
1133 bfd_reloc_status_type ret
;
1136 /* If we're relocating, and this is an external symbol with no
1137 addend, we don't want to change anything. We will only have an
1138 addend if this is a newly created reloc, not read from an ELF
1140 if (output_bfd
!= (bfd
*) NULL
1141 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1142 && reloc_entry
->addend
== 0)
1144 reloc_entry
->address
+= input_section
->output_offset
;
1145 return bfd_reloc_ok
;
1148 if (output_bfd
!= (bfd
*) NULL
)
1149 relocateable
= true;
1152 relocateable
= false;
1153 output_bfd
= symbol
->section
->output_section
->owner
;
1156 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1158 if (ret
!= bfd_reloc_ok
)
1161 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1162 relocateable
, data
, gp
);
1165 static bfd_reloc_status_type
1166 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1170 arelent
*reloc_entry
;
1171 asection
*input_section
;
1172 boolean relocateable
;
1180 if (bfd_is_com_section (symbol
->section
))
1183 relocation
= symbol
->value
;
1185 relocation
+= symbol
->section
->output_section
->vma
;
1186 relocation
+= symbol
->section
->output_offset
;
1188 if (reloc_entry
->address
> input_section
->_cooked_size
)
1189 return bfd_reloc_outofrange
;
1191 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1193 /* Set val to the offset into the section or symbol. */
1194 if (reloc_entry
->howto
->src_mask
== 0)
1196 /* This case occurs with the 64-bit MIPS ELF ABI. */
1197 val
= reloc_entry
->addend
;
1201 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1206 /* Adjust val for the final section location and GP value. If we
1207 are producing relocateable output, we don't want to do this for
1208 an external symbol. */
1210 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1211 val
+= relocation
- gp
;
1213 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1214 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1217 reloc_entry
->address
+= input_section
->output_offset
;
1219 /* Make sure it fit in 16 bits. */
1220 if (val
>= 0x8000 && val
< 0xffff8000)
1221 return bfd_reloc_overflow
;
1223 return bfd_reloc_ok
;
1226 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1227 from the gp register? XXX */
1229 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1230 arelent
*, asection
*,
1231 boolean
, PTR
, bfd_vma
));
1233 bfd_reloc_status_type
1234 _bfd_mips_elf_gprel32_reloc (abfd
,
1242 arelent
*reloc_entry
;
1245 asection
*input_section
;
1247 char **error_message
;
1249 boolean relocateable
;
1250 bfd_reloc_status_type ret
;
1253 /* If we're relocating, and this is an external symbol with no
1254 addend, we don't want to change anything. We will only have an
1255 addend if this is a newly created reloc, not read from an ELF
1257 if (output_bfd
!= (bfd
*) NULL
1258 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1259 && reloc_entry
->addend
== 0)
1261 *error_message
= (char *)
1262 "32bits gp relative relocation occurs for an external symbol";
1263 return bfd_reloc_outofrange
;
1266 if (output_bfd
!= (bfd
*) NULL
)
1268 relocateable
= true;
1269 gp
= _bfd_get_gp_value (output_bfd
);
1273 relocateable
= false;
1274 output_bfd
= symbol
->section
->output_section
->owner
;
1276 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1277 error_message
, &gp
);
1278 if (ret
!= bfd_reloc_ok
)
1282 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1283 relocateable
, data
, gp
);
1286 static bfd_reloc_status_type
1287 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1291 arelent
*reloc_entry
;
1292 asection
*input_section
;
1293 boolean relocateable
;
1300 if (bfd_is_com_section (symbol
->section
))
1303 relocation
= symbol
->value
;
1305 relocation
+= symbol
->section
->output_section
->vma
;
1306 relocation
+= symbol
->section
->output_offset
;
1308 if (reloc_entry
->address
> input_section
->_cooked_size
)
1309 return bfd_reloc_outofrange
;
1311 if (reloc_entry
->howto
->src_mask
== 0)
1313 /* This case arises with the 64-bit MIPS ELF ABI. */
1317 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1319 /* Set val to the offset into the section or symbol. */
1320 val
+= reloc_entry
->addend
;
1322 /* Adjust val for the final section location and GP value. If we
1323 are producing relocateable output, we don't want to do this for
1324 an external symbol. */
1326 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1327 val
+= relocation
- gp
;
1329 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1332 reloc_entry
->address
+= input_section
->output_offset
;
1334 return bfd_reloc_ok
;
1337 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1338 generated when addreses are 64 bits. The upper 32 bits are a simle
1341 static bfd_reloc_status_type
1342 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1343 output_bfd
, error_message
)
1345 arelent
*reloc_entry
;
1348 asection
*input_section
;
1350 char **error_message
;
1352 bfd_reloc_status_type r
;
1357 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1358 input_section
, output_bfd
, error_message
);
1359 if (r
!= bfd_reloc_continue
)
1362 /* Do a normal 32 bit relocation on the lower 32 bits. */
1363 reloc32
= *reloc_entry
;
1364 if (bfd_big_endian (abfd
))
1365 reloc32
.address
+= 4;
1366 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1367 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1368 output_bfd
, error_message
);
1370 /* Sign extend into the upper 32 bits. */
1371 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1372 if ((val
& 0x80000000) != 0)
1376 addr
= reloc_entry
->address
;
1377 if (bfd_little_endian (abfd
))
1379 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1384 /* Handle a mips16 jump. */
1386 static bfd_reloc_status_type
1387 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1388 output_bfd
, error_message
)
1390 arelent
*reloc_entry
;
1393 asection
*input_section
;
1395 char **error_message
;
1397 if (output_bfd
!= (bfd
*) NULL
1398 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1399 && reloc_entry
->addend
== 0)
1401 reloc_entry
->address
+= input_section
->output_offset
;
1402 return bfd_reloc_ok
;
1407 static boolean warned
;
1410 (*_bfd_error_handler
)
1411 ("Linking mips16 objects into %s format is not supported",
1412 bfd_get_target (input_section
->output_section
->owner
));
1416 return bfd_reloc_undefined
;
1419 /* Handle a mips16 GP relative reloc. */
1421 static bfd_reloc_status_type
1422 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1423 output_bfd
, error_message
)
1425 arelent
*reloc_entry
;
1428 asection
*input_section
;
1430 char **error_message
;
1432 boolean relocateable
;
1433 bfd_reloc_status_type ret
;
1435 unsigned short extend
, insn
;
1436 unsigned long final
;
1438 /* If we're relocating, and this is an external symbol with no
1439 addend, we don't want to change anything. We will only have an
1440 addend if this is a newly created reloc, not read from an ELF
1442 if (output_bfd
!= NULL
1443 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1444 && reloc_entry
->addend
== 0)
1446 reloc_entry
->address
+= input_section
->output_offset
;
1447 return bfd_reloc_ok
;
1450 if (output_bfd
!= NULL
)
1451 relocateable
= true;
1454 relocateable
= false;
1455 output_bfd
= symbol
->section
->output_section
->owner
;
1458 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1460 if (ret
!= bfd_reloc_ok
)
1463 if (reloc_entry
->address
> input_section
->_cooked_size
)
1464 return bfd_reloc_outofrange
;
1466 /* Pick up the mips16 extend instruction and the real instruction. */
1467 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1468 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1470 /* Stuff the current addend back as a 32 bit value, do the usual
1471 relocation, and then clean up. */
1473 (((extend
& 0x1f) << 11)
1476 (bfd_byte
*) data
+ reloc_entry
->address
);
1478 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1479 relocateable
, data
, gp
);
1481 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1484 | ((final
>> 11) & 0x1f)
1486 (bfd_byte
*) data
+ reloc_entry
->address
);
1490 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1495 /* Return the ISA for a MIPS e_flags value. */
1498 elf_mips_isa (flags
)
1501 switch (flags
& EF_MIPS_ARCH
)
1515 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1517 struct elf_reloc_map
{
1518 bfd_reloc_code_real_type bfd_reloc_val
;
1519 enum reloc_type elf_reloc_val
;
1522 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1524 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1525 { BFD_RELOC_16
, R_MIPS_16
},
1526 { BFD_RELOC_32
, R_MIPS_32
},
1527 { BFD_RELOC_64
, R_MIPS_64
},
1528 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1529 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1530 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1531 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1532 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1533 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1534 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1535 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1536 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1537 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1538 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1539 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1540 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
}
1543 /* Given a BFD reloc type, return a howto structure. */
1545 static reloc_howto_type
*
1546 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1548 bfd_reloc_code_real_type code
;
1552 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1554 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1555 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1558 /* We need to handle BFD_RELOC_CTOR specially. If this is a mips3
1559 file, then we assume that we are using 64 bit addresses, and use
1560 R_MIPS_64. Otherwise, we use R_MIPS_32. */
1561 if (code
== BFD_RELOC_CTOR
)
1563 if (elf_mips_isa (elf_elfheader (abfd
)->e_flags
) < 3)
1564 return &elf_mips_howto_table
[(int) R_MIPS_32
];
1566 return &elf_mips_ctor64_howto
;
1569 /* Special handling for the MIPS16 relocs, since they are made up
1570 reloc types with a large value. */
1571 if (code
== BFD_RELOC_MIPS16_JMP
)
1572 return &elf_mips16_jump_howto
;
1573 else if (code
== BFD_RELOC_MIPS16_GPREL
)
1574 return &elf_mips16_gprel_howto
;
1575 /* start-sanitize-sky */
1576 else if (code
== BFD_RELOC_MIPS_DVP_11_PCREL
)
1577 return &elf_mips_dvp_11_pcrel_howto
;
1578 /* end-sanitize-sky */
1583 /* Given a MIPS reloc type, fill in an arelent structure. */
1586 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1589 Elf32_Internal_Rel
*dst
;
1591 unsigned int r_type
;
1593 r_type
= ELF32_R_TYPE (dst
->r_info
);
1594 if (r_type
== R_MIPS16_26
)
1595 cache_ptr
->howto
= &elf_mips16_jump_howto
;
1596 else if (r_type
== R_MIPS16_GPREL
)
1597 cache_ptr
->howto
= &elf_mips16_gprel_howto
;
1598 /* start-sanitize-sky */
1599 else if (r_type
== R_MIPS_DVP_11_PCREL
)
1600 cache_ptr
->howto
= &elf_mips_dvp_11_pcrel_howto
;
1601 /* end-sanitize-sky */
1604 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1605 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1608 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1609 value for the object file. We get the addend now, rather than
1610 when we do the relocation, because the symbol manipulations done
1611 by the linker may cause us to lose track of the input BFD. */
1612 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1613 && (r_type
== (unsigned int) R_MIPS_GPREL16
1614 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1615 cache_ptr
->addend
= elf_gp (abfd
);
1618 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1619 routines swap this structure in and out. They are used outside of
1620 BFD, so they are globally visible. */
1623 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1625 const Elf32_External_RegInfo
*ex
;
1628 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1629 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1630 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1631 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1632 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1633 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1637 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1639 const Elf32_RegInfo
*in
;
1640 Elf32_External_RegInfo
*ex
;
1642 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1643 (bfd_byte
*) ex
->ri_gprmask
);
1644 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1645 (bfd_byte
*) ex
->ri_cprmask
[0]);
1646 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1647 (bfd_byte
*) ex
->ri_cprmask
[1]);
1648 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1649 (bfd_byte
*) ex
->ri_cprmask
[2]);
1650 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1651 (bfd_byte
*) ex
->ri_cprmask
[3]);
1652 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1653 (bfd_byte
*) ex
->ri_gp_value
);
1656 /* In the 64 bit ABI, the .MIPS.options section holds register
1657 information in an Elf64_Reginfo structure. These routines swap
1658 them in and out. They are globally visible because they are used
1659 outside of BFD. These routines are here so that gas can call them
1660 without worrying about whether the 64 bit ABI has been included. */
1663 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1665 const Elf64_External_RegInfo
*ex
;
1666 Elf64_Internal_RegInfo
*in
;
1668 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1669 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
1670 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1671 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1672 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1673 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1674 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1678 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1680 const Elf64_Internal_RegInfo
*in
;
1681 Elf64_External_RegInfo
*ex
;
1683 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1684 (bfd_byte
*) ex
->ri_gprmask
);
1685 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
1686 (bfd_byte
*) ex
->ri_pad
);
1687 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1688 (bfd_byte
*) ex
->ri_cprmask
[0]);
1689 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1690 (bfd_byte
*) ex
->ri_cprmask
[1]);
1691 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1692 (bfd_byte
*) ex
->ri_cprmask
[2]);
1693 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1694 (bfd_byte
*) ex
->ri_cprmask
[3]);
1695 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1696 (bfd_byte
*) ex
->ri_gp_value
);
1699 /* Swap an entry in a .gptab section. Note that these routines rely
1700 on the equivalence of the two elements of the union. */
1703 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1705 const Elf32_External_gptab
*ex
;
1708 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1709 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1713 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1715 const Elf32_gptab
*in
;
1716 Elf32_External_gptab
*ex
;
1718 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1719 ex
->gt_entry
.gt_g_value
);
1720 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1721 ex
->gt_entry
.gt_bytes
);
1725 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1727 const Elf32_compact_rel
*in
;
1728 Elf32_External_compact_rel
*ex
;
1730 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
1731 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
1732 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
1733 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
1734 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
1735 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
1739 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1741 const Elf32_crinfo
*in
;
1742 Elf32_External_crinfo
*ex
;
1746 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1747 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1748 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1749 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1750 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
1751 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
1752 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
1755 /* Swap in an options header. */
1758 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1760 const Elf_External_Options
*ex
;
1761 Elf_Internal_Options
*in
;
1763 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
1764 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
1765 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
1766 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
1769 /* Swap out an options header. */
1772 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
1774 const Elf_Internal_Options
*in
;
1775 Elf_External_Options
*ex
;
1777 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
1778 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
1779 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
1780 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
1783 /* Determine whether a symbol is global for the purposes of splitting
1784 the symbol table into global symbols and local symbols. At least
1785 on Irix 5, this split must be between section symbols and all other
1786 symbols. On most ELF targets the split is between static symbols
1787 and externally visible symbols. */
1791 mips_elf_sym_is_global (abfd
, sym
)
1795 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
1798 /* Set the right machine number for a MIPS ELF file. This is used for
1799 both the 32-bit and the 64-bit ABI. */
1802 _bfd_mips_elf_object_p (abfd
)
1805 switch (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
)
1809 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 3000);
1813 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 6000);
1817 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 4000);
1821 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 8000);
1828 /* Set the right machine number for a 32-bit MIPS ELF file. */
1831 mips_elf32_object_p (abfd
)
1834 /* Irix 5 is broken. Object file symbol tables are not always
1835 sorted correctly such that local symbols precede global symbols,
1836 and the sh_info field in the symbol table is not always right. */
1837 elf_bad_symtab (abfd
) = true;
1839 return _bfd_mips_elf_object_p (abfd
);
1842 /* The final processing done just before writing out a MIPS ELF object
1843 file. This gets the MIPS architecture right based on the machine
1844 number. This is used by both the 32-bit and the 64-bit ABI. */
1848 _bfd_mips_elf_final_write_processing (abfd
, linker
)
1854 Elf_Internal_Shdr
**hdrpp
;
1858 switch (bfd_get_mach (abfd
))
1861 val
= E_MIPS_ARCH_1
;
1865 val
= E_MIPS_ARCH_2
;
1869 val
= E_MIPS_ARCH_3
;
1873 val
= E_MIPS_ARCH_4
;
1881 elf_elfheader (abfd
)->e_flags
&=~ EF_MIPS_ARCH
;
1882 elf_elfheader (abfd
)->e_flags
|= val
;
1884 /* Set the sh_info field for .gptab sections. */
1885 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
1886 i
< elf_elfheader (abfd
)->e_shnum
;
1889 switch ((*hdrpp
)->sh_type
)
1891 case SHT_MIPS_LIBLIST
:
1892 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
1894 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
1897 case SHT_MIPS_GPTAB
:
1898 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1899 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1900 BFD_ASSERT (name
!= NULL
1901 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
1902 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
1903 BFD_ASSERT (sec
!= NULL
);
1904 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1907 case SHT_MIPS_CONTENT
:
1908 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1909 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1910 BFD_ASSERT (name
!= NULL
1911 && strncmp (name
, ".MIPS.content",
1912 sizeof ".MIPS.content" - 1) == 0);
1913 sec
= bfd_get_section_by_name (abfd
,
1914 name
+ sizeof ".MIPS.content" - 1);
1915 BFD_ASSERT (sec
!= NULL
);
1916 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1919 case SHT_MIPS_SYMBOL_LIB
:
1920 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
1922 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
1923 sec
= bfd_get_section_by_name (abfd
, ".liblist");
1925 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1928 case SHT_MIPS_EVENTS
:
1929 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1930 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1931 BFD_ASSERT (name
!= NULL
);
1932 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
1933 sec
= bfd_get_section_by_name (abfd
,
1934 name
+ sizeof ".MIPS.events" - 1);
1937 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
1938 sizeof ".MIPS.post_rel" - 1) == 0);
1939 sec
= bfd_get_section_by_name (abfd
,
1941 + sizeof ".MIPS.post_rel" - 1));
1943 BFD_ASSERT (sec
!= NULL
);
1944 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
1950 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
1953 _bfd_mips_elf_set_private_flags (abfd
, flags
)
1957 BFD_ASSERT (!elf_flags_init (abfd
)
1958 || elf_elfheader (abfd
)->e_flags
== flags
);
1960 elf_elfheader (abfd
)->e_flags
= flags
;
1961 elf_flags_init (abfd
) = true;
1965 /* Copy backend specific data from one object module to another */
1968 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
1972 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1973 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1976 BFD_ASSERT (!elf_flags_init (obfd
)
1977 || (elf_elfheader (obfd
)->e_flags
1978 == elf_elfheader (ibfd
)->e_flags
));
1980 elf_gp (obfd
) = elf_gp (ibfd
);
1981 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1982 elf_flags_init (obfd
) = true;
1986 /* Merge backend specific data from an object file to the output
1987 object file when linking. */
1990 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
1998 /* Check if we have the same endianess */
1999 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2000 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2002 (*_bfd_error_handler
)
2003 ("%s: compiled for a %s endian system and target is %s endian",
2004 bfd_get_filename (ibfd
),
2005 bfd_big_endian (ibfd
) ? "big" : "little",
2006 bfd_big_endian (obfd
) ? "big" : "little");
2008 bfd_set_error (bfd_error_wrong_format
);
2012 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2013 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2016 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2017 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
2018 old_flags
= elf_elfheader (obfd
)->e_flags
;
2020 if (! elf_flags_init (obfd
))
2022 elf_flags_init (obfd
) = true;
2023 elf_elfheader (obfd
)->e_flags
= new_flags
;
2025 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2026 && bfd_get_arch_info (obfd
)->the_default
)
2028 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
2029 bfd_get_mach (ibfd
)))
2036 /* Check flag compatibility. */
2038 new_flags
&= ~EF_MIPS_NOREORDER
;
2039 old_flags
&= ~EF_MIPS_NOREORDER
;
2041 if (new_flags
== old_flags
)
2046 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
2048 new_flags
&= ~EF_MIPS_PIC
;
2049 old_flags
&= ~EF_MIPS_PIC
;
2050 (*_bfd_error_handler
)
2051 ("%s: linking PIC files with non-PIC files",
2052 bfd_get_filename (ibfd
));
2056 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
2058 new_flags
&= ~EF_MIPS_CPIC
;
2059 old_flags
&= ~EF_MIPS_CPIC
;
2060 (*_bfd_error_handler
)
2061 ("%s: linking abicalls files with non-abicalls files",
2062 bfd_get_filename (ibfd
));
2066 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
2067 and -mips4 code. They will normally use the same data sizes and
2068 calling conventions. */
2069 if ((new_flags
& EF_MIPS_ARCH
) != (old_flags
& EF_MIPS_ARCH
))
2071 int new_isa
, old_isa
;
2073 new_isa
= elf_mips_isa (new_flags
);
2074 old_isa
= elf_mips_isa (old_flags
);
2075 if ((new_isa
== 1 || new_isa
== 2)
2076 ? (old_isa
!= 1 && old_isa
!= 2)
2077 : (old_isa
== 1 || old_isa
== 2))
2079 (*_bfd_error_handler
)
2080 ("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)",
2081 bfd_get_filename (ibfd
), new_isa
, old_isa
);
2085 new_flags
&= ~ EF_MIPS_ARCH
;
2086 old_flags
&= ~ EF_MIPS_ARCH
;
2089 /* Warn about any other mismatches */
2090 if (new_flags
!= old_flags
)
2092 (*_bfd_error_handler
)
2093 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
2094 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
2095 (unsigned long) old_flags
);
2101 bfd_set_error (bfd_error_bad_value
);
2108 /* Handle a MIPS specific section when reading an object file. This
2109 is called when elfcode.h finds a section with an unknown type.
2110 This routine supports both the 32-bit and 64-bit ELF ABI.
2112 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2116 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
2118 Elf_Internal_Shdr
*hdr
;
2121 /* There ought to be a place to keep ELF backend specific flags, but
2122 at the moment there isn't one. We just keep track of the
2123 sections by their name, instead. Fortunately, the ABI gives
2124 suggested names for all the MIPS specific sections, so we will
2125 probably get away with this. */
2126 switch (hdr
->sh_type
)
2128 case SHT_MIPS_LIBLIST
:
2129 if (strcmp (name
, ".liblist") != 0)
2133 if (strcmp (name
, ".msym") != 0)
2136 case SHT_MIPS_CONFLICT
:
2137 if (strcmp (name
, ".conflict") != 0)
2140 case SHT_MIPS_GPTAB
:
2141 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
2144 case SHT_MIPS_UCODE
:
2145 if (strcmp (name
, ".ucode") != 0)
2148 case SHT_MIPS_DEBUG
:
2149 if (strcmp (name
, ".mdebug") != 0)
2152 case SHT_MIPS_REGINFO
:
2153 if (strcmp (name
, ".reginfo") != 0
2154 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
2157 case SHT_MIPS_IFACE
:
2158 if (strcmp (name
, ".MIPS.interfaces") != 0)
2161 case SHT_MIPS_CONTENT
:
2162 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2165 case SHT_MIPS_OPTIONS
:
2166 if (strcmp (name
, ".options") != 0
2167 && strcmp (name
, ".MIPS.options") != 0)
2170 case SHT_MIPS_DWARF
:
2171 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2174 case SHT_MIPS_SYMBOL_LIB
:
2175 if (strcmp (name
, ".MIPS.symlib") != 0)
2178 case SHT_MIPS_EVENTS
:
2179 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2180 && strncmp (name
, ".MIPS.post_rel",
2181 sizeof ".MIPS.post_rel" - 1) != 0)
2188 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2191 if (hdr
->sh_type
== SHT_MIPS_DEBUG
)
2193 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
2194 (bfd_get_section_flags (abfd
,
2203 /* Handle a 32-bit MIPS ELF specific section. */
2206 mips_elf32_section_from_shdr (abfd
, hdr
, name
)
2208 Elf_Internal_Shdr
*hdr
;
2211 if (! _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
))
2214 /* FIXME: We should record sh_info for a .gptab section. */
2216 /* For a .reginfo section, set the gp value in the tdata information
2217 from the contents of this section. We need the gp value while
2218 processing relocs, so we just get it now. The .reginfo section
2219 is not used in the 64-bit MIPS ELF ABI. */
2220 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2222 Elf32_External_RegInfo ext
;
2225 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
2226 (file_ptr
) 0, sizeof ext
))
2228 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
2229 elf_gp (abfd
) = s
.ri_gp_value
;
2232 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2233 set the gp value based on what we find. We may see both
2234 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2235 they should agree. */
2236 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
2238 bfd_byte
*contents
, *l
, *lend
;
2240 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
2241 if (contents
== NULL
)
2243 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
2244 (file_ptr
) 0, hdr
->sh_size
))
2250 lend
= contents
+ hdr
->sh_size
;
2251 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2253 Elf_Internal_Options intopt
;
2255 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2257 if (intopt
.kind
== ODK_REGINFO
)
2259 Elf32_RegInfo intreg
;
2261 bfd_mips_elf32_swap_reginfo_in
2263 ((Elf32_External_RegInfo
*)
2264 (l
+ sizeof (Elf_External_Options
))),
2266 elf_gp (abfd
) = intreg
.ri_gp_value
;
2276 /* Set the correct type for a MIPS ELF section. We do this by the
2277 section name, which is a hack, but ought to work. This routine is
2278 used by both the 32-bit and the 64-bit ABI. */
2281 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
2283 Elf32_Internal_Shdr
*hdr
;
2286 register const char *name
;
2288 name
= bfd_get_section_name (abfd
, sec
);
2290 if (strcmp (name
, ".liblist") == 0)
2292 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
2293 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
2294 /* The sh_link field is set in final_write_processing. */
2296 else if (strcmp (name
, ".msym") == 0)
2298 hdr
->sh_type
= SHT_MIPS_MSYM
;
2299 hdr
->sh_entsize
= 8;
2300 /* FIXME: Set the sh_info field. */
2302 else if (strcmp (name
, ".conflict") == 0)
2303 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
2304 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2306 hdr
->sh_type
= SHT_MIPS_GPTAB
;
2307 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
2308 /* The sh_info field is set in final_write_processing. */
2310 else if (strcmp (name
, ".ucode") == 0)
2311 hdr
->sh_type
= SHT_MIPS_UCODE
;
2312 else if (strcmp (name
, ".mdebug") == 0)
2314 hdr
->sh_type
= SHT_MIPS_DEBUG
;
2315 /* In a shared object on Irix 5.3, the .mdebug section has an
2316 entsize of 0. FIXME: Does this matter? */
2317 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2318 hdr
->sh_entsize
= 0;
2320 hdr
->sh_entsize
= 1;
2322 else if (strcmp (name
, ".reginfo") == 0)
2324 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2325 /* In a shared object on Irix 5.3, the .reginfo section has an
2326 entsize of 0x18. FIXME: Does this matter? */
2327 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2328 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2330 hdr
->sh_entsize
= 1;
2332 /* Force the section size to the correct value, even if the
2333 linker thinks it is larger. The link routine below will only
2334 write out this much data for .reginfo. */
2335 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf32_External_RegInfo
);
2337 else if (SGI_COMPAT (abfd
)
2338 && (strcmp (name
, ".hash") == 0
2339 || strcmp (name
, ".dynamic") == 0
2340 || strcmp (name
, ".dynstr") == 0))
2342 hdr
->sh_entsize
= 0;
2343 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2345 else if (strcmp (name
, ".got") == 0
2346 || strcmp (name
, ".sdata") == 0
2347 || strcmp (name
, ".sbss") == 0
2348 || strcmp (name
, ".lit4") == 0
2349 || strcmp (name
, ".lit8") == 0)
2350 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2351 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2353 hdr
->sh_type
= SHT_MIPS_IFACE
;
2354 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2356 else if (strcmp (name
, ".MIPS.content") == 0)
2358 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2359 /* The sh_info field is set in final_write_processing. */
2361 else if (strcmp (name
, ".options") == 0
2362 || strcmp (name
, ".MIPS.options") == 0)
2364 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2365 hdr
->sh_entsize
= 1;
2366 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2368 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2369 hdr
->sh_type
= SHT_MIPS_DWARF
;
2370 else if (strcmp (name
, ".MIPS.symlib") == 0)
2372 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2373 /* The sh_link and sh_info fields are set in
2374 final_write_processing. */
2376 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2377 || strncmp (name
, ".MIPS.post_rel",
2378 sizeof ".MIPS.post_rel" - 1) == 0)
2380 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2381 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2382 /* The sh_link field is set in final_write_processing. */
2388 /* Given a BFD section, try to locate the corresponding ELF section
2389 index. This is used by both the 32-bit and the 64-bit ABI.
2390 Actually, it's not clear to me that the 64-bit ABI supports these,
2391 but for non-PIC objects we will certainly want support for at least
2392 the .scommon section. */
2395 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2397 Elf32_Internal_Shdr
*hdr
;
2401 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2403 *retval
= SHN_MIPS_SCOMMON
;
2406 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2408 *retval
= SHN_MIPS_ACOMMON
;
2414 /* When are writing out the .options or .MIPS.options section,
2415 remember the bytes we are writing out, so that we can install the
2416 GP value in the section_processing routine. */
2419 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2424 bfd_size_type count
;
2426 if (strcmp (section
->name
, ".options") == 0
2427 || strcmp (section
->name
, ".MIPS.options") == 0)
2431 if (elf_section_data (section
) == NULL
)
2433 section
->used_by_bfd
=
2434 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
2435 if (elf_section_data (section
) == NULL
)
2438 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
2443 if (section
->_cooked_size
!= 0)
2444 size
= section
->_cooked_size
;
2446 size
= section
->_raw_size
;
2447 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
2450 elf_section_data (section
)->tdata
= (PTR
) c
;
2453 memcpy (c
+ offset
, location
, count
);
2456 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
2460 /* Work over a section just before writing it out. This routine is
2461 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2462 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2466 _bfd_mips_elf_section_processing (abfd
, hdr
)
2468 Elf_Internal_Shdr
*hdr
;
2470 if (hdr
->bfd_section
!= NULL
)
2472 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
2474 if (strcmp (name
, ".sdata") == 0)
2476 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2477 hdr
->sh_type
= SHT_PROGBITS
;
2479 else if (strcmp (name
, ".sbss") == 0)
2481 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2482 hdr
->sh_type
= SHT_NOBITS
;
2484 else if (strcmp (name
, ".lit8") == 0
2485 || strcmp (name
, ".lit4") == 0)
2487 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2488 hdr
->sh_type
= SHT_PROGBITS
;
2490 else if (strcmp (name
, ".compact_rel") == 0)
2493 hdr
->sh_type
= SHT_PROGBITS
;
2495 else if (strcmp (name
, ".rtproc") == 0)
2497 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
2499 unsigned int adjust
;
2501 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
2503 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
2511 /* Work over a section just before writing it out. We update the GP
2512 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2513 on the value we are using. */
2516 mips_elf32_section_processing (abfd
, hdr
)
2518 Elf32_Internal_Shdr
*hdr
;
2520 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2524 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2525 BFD_ASSERT (hdr
->contents
== NULL
);
2528 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2531 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2532 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2536 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2537 && hdr
->bfd_section
!= NULL
2538 && elf_section_data (hdr
->bfd_section
) != NULL
2539 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2541 bfd_byte
*contents
, *l
, *lend
;
2543 /* We stored the section contents in the elf_section_data tdata
2544 field in the set_section_contents routine. We save the
2545 section contents so that we don't have to read them again.
2546 At this point we know that elf_gp is set, so we can look
2547 through the section contents to see if there is an
2548 ODK_REGINFO structure. */
2550 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2552 lend
= contents
+ hdr
->sh_size
;
2553 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2555 Elf_Internal_Options intopt
;
2557 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2559 if (intopt
.kind
== ODK_REGINFO
)
2566 + sizeof (Elf_External_Options
)
2567 + (sizeof (Elf32_External_RegInfo
) - 4)),
2570 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
2571 if (bfd_write (buf
, 1, 4, abfd
) != 4)
2578 return _bfd_mips_elf_section_processing (abfd
, hdr
);
2581 /* MIPS ELF uses two common sections. One is the usual one, and the
2582 other is for small objects. All the small objects are kept
2583 together, and then referenced via the gp pointer, which yields
2584 faster assembler code. This is what we use for the small common
2585 section. This approach is copied from ecoff.c. */
2586 static asection mips_elf_scom_section
;
2587 static asymbol mips_elf_scom_symbol
;
2588 static asymbol
*mips_elf_scom_symbol_ptr
;
2590 /* MIPS ELF also uses an acommon section, which represents an
2591 allocated common symbol which may be overridden by a
2592 definition in a shared library. */
2593 static asection mips_elf_acom_section
;
2594 static asymbol mips_elf_acom_symbol
;
2595 static asymbol
*mips_elf_acom_symbol_ptr
;
2597 /* The Irix 5 support uses two virtual sections, which represent
2598 text/data symbols defined in dynamic objects. */
2599 static asection mips_elf_text_section
;
2600 static asection
*mips_elf_text_section_ptr
;
2601 static asymbol mips_elf_text_symbol
;
2602 static asymbol
*mips_elf_text_symbol_ptr
;
2604 static asection mips_elf_data_section
;
2605 static asection
*mips_elf_data_section_ptr
;
2606 static asymbol mips_elf_data_symbol
;
2607 static asymbol
*mips_elf_data_symbol_ptr
;
2609 /* Handle the special MIPS section numbers that a symbol may use.
2610 This is used for both the 32-bit and the 64-bit ABI. */
2613 _bfd_mips_elf_symbol_processing (abfd
, asym
)
2617 elf_symbol_type
*elfsym
;
2619 elfsym
= (elf_symbol_type
*) asym
;
2620 switch (elfsym
->internal_elf_sym
.st_shndx
)
2622 case SHN_MIPS_ACOMMON
:
2623 /* This section is used in a dynamically linked executable file.
2624 It is an allocated common section. The dynamic linker can
2625 either resolve these symbols to something in a shared
2626 library, or it can just leave them here. For our purposes,
2627 we can consider these symbols to be in a new section. */
2628 if (mips_elf_acom_section
.name
== NULL
)
2630 /* Initialize the acommon section. */
2631 mips_elf_acom_section
.name
= ".acommon";
2632 mips_elf_acom_section
.flags
= SEC_ALLOC
;
2633 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
2634 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
2635 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
2636 mips_elf_acom_symbol
.name
= ".acommon";
2637 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
2638 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
2639 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
2641 asym
->section
= &mips_elf_acom_section
;
2645 /* Common symbols less than the GP size are automatically
2646 treated as SHN_MIPS_SCOMMON symbols. */
2647 if (asym
->value
> elf_gp_size (abfd
))
2650 case SHN_MIPS_SCOMMON
:
2651 if (mips_elf_scom_section
.name
== NULL
)
2653 /* Initialize the small common section. */
2654 mips_elf_scom_section
.name
= ".scommon";
2655 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
2656 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
2657 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
2658 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
2659 mips_elf_scom_symbol
.name
= ".scommon";
2660 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2661 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
2662 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
2664 asym
->section
= &mips_elf_scom_section
;
2665 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2668 case SHN_MIPS_SUNDEFINED
:
2669 asym
->section
= bfd_und_section_ptr
;
2672 #if 0 /* for SGI_COMPAT */
2674 asym
->section
= mips_elf_text_section_ptr
;
2678 asym
->section
= mips_elf_data_section_ptr
;
2684 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
2688 mips_elf_additional_program_headers (abfd
)
2696 if (! SGI_COMPAT (abfd
))
2699 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2700 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2702 /* We need a PT_MIPS_REGINFO segment. */
2706 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2707 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2709 /* We need a PT_MIPS_RTPROC segment. */
2716 /* Modify the segment map for an Irix 5 executable. */
2719 mips_elf_modify_segment_map (abfd
)
2723 struct elf_segment_map
*m
, **pm
;
2725 if (! SGI_COMPAT (abfd
))
2728 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
2730 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2731 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2733 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2734 if (m
->p_type
== PT_MIPS_REGINFO
)
2738 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2742 m
->p_type
= PT_MIPS_REGINFO
;
2746 /* We want to put it after the PHDR and INTERP segments. */
2747 pm
= &elf_tdata (abfd
)->segment_map
;
2749 && ((*pm
)->p_type
== PT_PHDR
2750 || (*pm
)->p_type
== PT_INTERP
))
2758 /* If there are .dynamic and .mdebug sections, we make a room for
2759 the RTPROC header. FIXME: Rewrite without section names. */
2760 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
2761 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2762 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2764 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2765 if (m
->p_type
== PT_MIPS_RTPROC
)
2769 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2773 m
->p_type
= PT_MIPS_RTPROC
;
2775 s
= bfd_get_section_by_name (abfd
, ".rtproc");
2780 m
->p_flags_valid
= 1;
2788 /* We want to put it after the DYNAMIC segment. */
2789 pm
= &elf_tdata (abfd
)->segment_map
;
2790 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
2800 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
2801 .dynsym, and .hash sections, and everything in between. */
2802 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
2803 if ((*pm
)->p_type
== PT_DYNAMIC
)
2808 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
2810 static const char *sec_names
[] =
2811 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
2814 struct elf_segment_map
*n
;
2818 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
2820 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
2821 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2827 sz
= s
->_cooked_size
;
2830 if (high
< s
->vma
+ sz
)
2836 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2837 if ((s
->flags
& SEC_LOAD
) != 0
2840 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2844 n
= ((struct elf_segment_map
*)
2845 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
2852 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2854 if ((s
->flags
& SEC_LOAD
) != 0
2857 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2871 /* The structure of the runtime procedure descriptor created by the
2872 loader for use by the static exception system. */
2874 typedef struct runtime_pdr
{
2875 bfd_vma adr
; /* memory address of start of procedure */
2876 long regmask
; /* save register mask */
2877 long regoffset
; /* save register offset */
2878 long fregmask
; /* save floating point register mask */
2879 long fregoffset
; /* save floating point register offset */
2880 long frameoffset
; /* frame size */
2881 short framereg
; /* frame pointer register */
2882 short pcreg
; /* offset or reg of return pc */
2883 long irpss
; /* index into the runtime string table */
2885 struct exception_info
*exception_info
;/* pointer to exception array */
2887 #define cbRPDR sizeof(RPDR)
2888 #define rpdNil ((pRPDR) 0)
2890 /* Swap RPDR (runtime procedure table entry) for output. */
2892 static void ecoff_swap_rpdr_out
2893 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
2896 ecoff_swap_rpdr_out (abfd
, in
, ex
)
2899 struct rpdr_ext
*ex
;
2901 /* ecoff_put_off was defined in ecoffswap.h. */
2902 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
2903 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
2904 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
2905 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
2906 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
2907 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
2909 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
2910 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
2912 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
2914 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
2918 /* Read ECOFF debugging information from a .mdebug section into a
2919 ecoff_debug_info structure. */
2922 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
2925 struct ecoff_debug_info
*debug
;
2928 const struct ecoff_debug_swap
*swap
;
2929 char *ext_hdr
= NULL
;
2931 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2933 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
2934 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
2937 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
2938 swap
->external_hdr_size
)
2942 symhdr
= &debug
->symbolic_header
;
2943 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
2945 /* The symbolic header contains absolute file offsets and sizes to
2947 #define READ(ptr, offset, count, size, type) \
2948 if (symhdr->count == 0) \
2949 debug->ptr = NULL; \
2952 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
2953 if (debug->ptr == NULL) \
2954 goto error_return; \
2955 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
2956 || (bfd_read (debug->ptr, size, symhdr->count, \
2957 abfd) != size * symhdr->count)) \
2958 goto error_return; \
2961 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
2962 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
2963 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
2964 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
2965 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
2966 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
2968 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
2969 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
2970 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
2971 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
2972 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
2976 debug
->adjust
= NULL
;
2981 if (ext_hdr
!= NULL
)
2983 if (debug
->line
!= NULL
)
2985 if (debug
->external_dnr
!= NULL
)
2986 free (debug
->external_dnr
);
2987 if (debug
->external_pdr
!= NULL
)
2988 free (debug
->external_pdr
);
2989 if (debug
->external_sym
!= NULL
)
2990 free (debug
->external_sym
);
2991 if (debug
->external_opt
!= NULL
)
2992 free (debug
->external_opt
);
2993 if (debug
->external_aux
!= NULL
)
2994 free (debug
->external_aux
);
2995 if (debug
->ss
!= NULL
)
2997 if (debug
->ssext
!= NULL
)
2998 free (debug
->ssext
);
2999 if (debug
->external_fdr
!= NULL
)
3000 free (debug
->external_fdr
);
3001 if (debug
->external_rfd
!= NULL
)
3002 free (debug
->external_rfd
);
3003 if (debug
->external_ext
!= NULL
)
3004 free (debug
->external_ext
);
3008 /* MIPS ELF local labels start with '$', not 'L'. */
3012 mips_elf_is_local_label_name (abfd
, name
)
3019 /* On Irix 6, the labels go back to starting with '.', so we accept
3020 the generic ELF local label syntax as well. */
3021 return _bfd_elf_is_local_label_name (abfd
, name
);
3024 /* MIPS ELF uses a special find_nearest_line routine in order the
3025 handle the ECOFF debugging information. */
3027 struct mips_elf_find_line
3029 struct ecoff_debug_info d
;
3030 struct ecoff_find_line i
;
3034 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
3035 functionname_ptr
, line_ptr
)
3040 const char **filename_ptr
;
3041 const char **functionname_ptr
;
3042 unsigned int *line_ptr
;
3046 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3047 filename_ptr
, functionname_ptr
,
3051 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
3055 struct mips_elf_find_line
*fi
;
3056 const struct ecoff_debug_swap
* const swap
=
3057 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3059 /* If we are called during a link, mips_elf_final_link may have
3060 cleared the SEC_HAS_CONTENTS field. We force it back on here
3061 if appropriate (which it normally will be). */
3062 origflags
= msec
->flags
;
3063 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
3064 msec
->flags
|= SEC_HAS_CONTENTS
;
3066 fi
= elf_tdata (abfd
)->find_line_info
;
3069 bfd_size_type external_fdr_size
;
3072 struct fdr
*fdr_ptr
;
3074 fi
= ((struct mips_elf_find_line
*)
3075 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
3078 msec
->flags
= origflags
;
3082 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
3084 msec
->flags
= origflags
;
3088 /* Swap in the FDR information. */
3089 fi
->d
.fdr
= ((struct fdr
*)
3091 (fi
->d
.symbolic_header
.ifdMax
*
3092 sizeof (struct fdr
))));
3093 if (fi
->d
.fdr
== NULL
)
3095 msec
->flags
= origflags
;
3098 external_fdr_size
= swap
->external_fdr_size
;
3099 fdr_ptr
= fi
->d
.fdr
;
3100 fraw_src
= (char *) fi
->d
.external_fdr
;
3101 fraw_end
= (fraw_src
3102 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
3103 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
3104 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
3106 elf_tdata (abfd
)->find_line_info
= fi
;
3108 /* Note that we don't bother to ever free this information.
3109 find_nearest_line is either called all the time, as in
3110 objdump -l, so the information should be saved, or it is
3111 rarely called, as in ld error messages, so the memory
3112 wasted is unimportant. Still, it would probably be a
3113 good idea for free_cached_info to throw it away. */
3116 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
3117 &fi
->i
, filename_ptr
, functionname_ptr
,
3120 msec
->flags
= origflags
;
3124 msec
->flags
= origflags
;
3127 /* Fall back on the generic ELF find_nearest_line routine. */
3129 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
3130 filename_ptr
, functionname_ptr
,
3134 /* The mips16 compiler uses a couple of special sections to handle
3135 floating point arguments.
3137 Section names that look like .mips16.fn.FNNAME contain stubs that
3138 copy floating point arguments from the fp regs to the gp regs and
3139 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3140 call should be redirected to the stub instead. If no 32 bit
3141 function calls FNNAME, the stub should be discarded. We need to
3142 consider any reference to the function, not just a call, because
3143 if the address of the function is taken we will need the stub,
3144 since the address might be passed to a 32 bit function.
3146 Section names that look like .mips16.call.FNNAME contain stubs
3147 that copy floating point arguments from the gp regs to the fp
3148 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3149 then any 16 bit function that calls FNNAME should be redirected
3150 to the stub instead. If FNNAME is not a 32 bit function, the
3151 stub should be discarded.
3153 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3154 which call FNNAME and then copy the return value from the fp regs
3155 to the gp regs. These stubs store the return value in $18 while
3156 calling FNNAME; any function which might call one of these stubs
3157 must arrange to save $18 around the call. (This case is not
3158 needed for 32 bit functions that call 16 bit functions, because
3159 16 bit functions always return floating point values in both
3162 Note that in all cases FNNAME might be defined statically.
3163 Therefore, FNNAME is not used literally. Instead, the relocation
3164 information will indicate which symbol the section is for.
3166 We record any stubs that we find in the symbol table. */
3168 #define FN_STUB ".mips16.fn."
3169 #define CALL_STUB ".mips16.call."
3170 #define CALL_FP_STUB ".mips16.call.fp."
3172 /* The MIPS ELF linker needs additional information for each symbol in
3173 the global hash table. */
3175 struct mips_elf_link_hash_entry
3177 struct elf_link_hash_entry root
;
3179 /* External symbol information. */
3182 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
3183 unsigned int mips_32_relocs
;
3185 /* If there is a stub that 32 bit functions should use to call this
3186 16 bit function, this points to the section containing the stub. */
3189 /* Whether we need the fn_stub; this is set if this symbol appears
3190 in any relocs other than a 16 bit call. */
3191 boolean need_fn_stub
;
3193 /* If there is a stub that 16 bit functions should use to call this
3194 32 bit function, this points to the section containing the stub. */
3195 asection
*call_stub
;
3197 /* This is like the call_stub field, but it is used if the function
3198 being called returns a floating point value. */
3199 asection
*call_fp_stub
;
3202 /* MIPS ELF linker hash table. */
3204 struct mips_elf_link_hash_table
3206 struct elf_link_hash_table root
;
3207 /* String section indices for the dynamic section symbols. */
3208 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
3209 /* The number of .rtproc entries. */
3210 bfd_size_type procedure_count
;
3211 /* The size of the .compact_rel section (if SGI_COMPAT). */
3212 bfd_size_type compact_rel_size
;
3213 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3214 entry is set to the address of __rld_obj_head as in Irix 5. */
3215 boolean use_rld_obj_head
;
3216 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3218 /* This is set if we see any mips16 stub sections. */
3219 boolean mips16_stubs_seen
;
3222 /* Look up an entry in a MIPS ELF linker hash table. */
3224 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3225 ((struct mips_elf_link_hash_entry *) \
3226 elf_link_hash_lookup (&(table)->root, (string), (create), \
3229 /* Traverse a MIPS ELF linker hash table. */
3231 #define mips_elf_link_hash_traverse(table, func, info) \
3232 (elf_link_hash_traverse \
3234 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3237 /* Get the MIPS ELF linker hash table from a link_info structure. */
3239 #define mips_elf_hash_table(p) \
3240 ((struct mips_elf_link_hash_table *) ((p)->hash))
3242 static boolean mips_elf_output_extsym
3243 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3245 /* Create an entry in a MIPS ELF linker hash table. */
3247 static struct bfd_hash_entry
*
3248 mips_elf_link_hash_newfunc (entry
, table
, string
)
3249 struct bfd_hash_entry
*entry
;
3250 struct bfd_hash_table
*table
;
3253 struct mips_elf_link_hash_entry
*ret
=
3254 (struct mips_elf_link_hash_entry
*) entry
;
3256 /* Allocate the structure if it has not already been allocated by a
3258 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3259 ret
= ((struct mips_elf_link_hash_entry
*)
3260 bfd_hash_allocate (table
,
3261 sizeof (struct mips_elf_link_hash_entry
)));
3262 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3263 return (struct bfd_hash_entry
*) ret
;
3265 /* Call the allocation method of the superclass. */
3266 ret
= ((struct mips_elf_link_hash_entry
*)
3267 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3269 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3271 /* Set local fields. */
3272 memset (&ret
->esym
, 0, sizeof (EXTR
));
3273 /* We use -2 as a marker to indicate that the information has
3274 not been set. -1 means there is no associated ifd. */
3276 ret
->mips_32_relocs
= 0;
3277 ret
->fn_stub
= NULL
;
3278 ret
->need_fn_stub
= false;
3279 ret
->call_stub
= NULL
;
3280 ret
->call_fp_stub
= NULL
;
3283 return (struct bfd_hash_entry
*) ret
;
3286 /* Create a MIPS ELF linker hash table. */
3288 static struct bfd_link_hash_table
*
3289 mips_elf_link_hash_table_create (abfd
)
3292 struct mips_elf_link_hash_table
*ret
;
3295 ret
= ((struct mips_elf_link_hash_table
*)
3296 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
3297 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
3300 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3301 mips_elf_link_hash_newfunc
))
3303 bfd_release (abfd
, ret
);
3307 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
3308 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
3309 ret
->procedure_count
= 0;
3310 ret
->compact_rel_size
= 0;
3311 ret
->use_rld_obj_head
= false;
3313 ret
->mips16_stubs_seen
= false;
3315 return &ret
->root
.root
;
3318 /* Hook called by the linker routine which adds symbols from an object
3319 file. We must handle the special MIPS section numbers here. */
3323 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3325 struct bfd_link_info
*info
;
3326 const Elf_Internal_Sym
*sym
;
3332 if (SGI_COMPAT (abfd
)
3333 && (abfd
->flags
& DYNAMIC
) != 0
3334 && strcmp (*namep
, "_rld_new_interface") == 0)
3336 /* Skip Irix 5 rld entry name. */
3341 switch (sym
->st_shndx
)
3344 /* Common symbols less than the GP size are automatically
3345 treated as SHN_MIPS_SCOMMON symbols. */
3346 if (sym
->st_size
> elf_gp_size (abfd
))
3349 case SHN_MIPS_SCOMMON
:
3350 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3351 (*secp
)->flags
|= SEC_IS_COMMON
;
3352 *valp
= sym
->st_size
;
3356 /* This section is used in a shared object. */
3357 if (mips_elf_text_section_ptr
== NULL
)
3359 /* Initialize the section. */
3360 mips_elf_text_section
.name
= ".text";
3361 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
3362 mips_elf_text_section
.output_section
= NULL
;
3363 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
3364 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
3365 mips_elf_text_symbol
.name
= ".text";
3366 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
3367 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
3368 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
3369 mips_elf_text_section_ptr
= &mips_elf_text_section
;
3371 /* This code used to do *secp = bfd_und_section_ptr if
3372 info->shared. I don't know why, and that doesn't make sense,
3373 so I took it out. */
3374 *secp
= mips_elf_text_section_ptr
;
3377 case SHN_MIPS_ACOMMON
:
3378 /* Fall through. XXX Can we treat this as allocated data? */
3380 /* This section is used in a shared object. */
3381 if (mips_elf_data_section_ptr
== NULL
)
3383 /* Initialize the section. */
3384 mips_elf_data_section
.name
= ".data";
3385 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
3386 mips_elf_data_section
.output_section
= NULL
;
3387 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
3388 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
3389 mips_elf_data_symbol
.name
= ".data";
3390 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
3391 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
3392 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
3393 mips_elf_data_section_ptr
= &mips_elf_data_section
;
3395 /* This code used to do *secp = bfd_und_section_ptr if
3396 info->shared. I don't know why, and that doesn't make sense,
3397 so I took it out. */
3398 *secp
= mips_elf_data_section_ptr
;
3401 case SHN_MIPS_SUNDEFINED
:
3402 *secp
= bfd_und_section_ptr
;
3406 if (SGI_COMPAT (abfd
)
3408 && info
->hash
->creator
== abfd
->xvec
3409 && strcmp (*namep
, "__rld_obj_head") == 0)
3411 struct elf_link_hash_entry
*h
;
3413 /* Mark __rld_obj_head as dynamic. */
3415 if (! (_bfd_generic_link_add_one_symbol
3416 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3417 (bfd_vma
) *valp
, (const char *) NULL
, false,
3418 get_elf_backend_data (abfd
)->collect
,
3419 (struct bfd_link_hash_entry
**) &h
)))
3421 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
3422 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3423 h
->type
= STT_OBJECT
;
3425 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3428 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3431 /* If this is a mips16 text symbol, add 1 to the value to make it
3432 odd. This will cause something like .word SYM to come up with
3433 the right value when it is loaded into the PC. */
3434 if (sym
->st_other
== STO_MIPS16
)
3440 /* Structure used to pass information to mips_elf_output_extsym. */
3445 struct bfd_link_info
*info
;
3446 struct ecoff_debug_info
*debug
;
3447 const struct ecoff_debug_swap
*swap
;
3451 /* This routine is used to write out ECOFF debugging external symbol
3452 information. It is called via mips_elf_link_hash_traverse. The
3453 ECOFF external symbol information must match the ELF external
3454 symbol information. Unfortunately, at this point we don't know
3455 whether a symbol is required by reloc information, so the two
3456 tables may wind up being different. We must sort out the external
3457 symbol information before we can set the final size of the .mdebug
3458 section, and we must set the size of the .mdebug section before we
3459 can relocate any sections, and we can't know which symbols are
3460 required by relocation until we relocate the sections.
3461 Fortunately, it is relatively unlikely that any symbol will be
3462 stripped but required by a reloc. In particular, it can not happen
3463 when generating a final executable. */
3466 mips_elf_output_extsym (h
, data
)
3467 struct mips_elf_link_hash_entry
*h
;
3470 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
3472 asection
*sec
, *output_section
;
3474 if (h
->root
.indx
== -2)
3476 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3477 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
3478 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3479 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
3481 else if (einfo
->info
->strip
== strip_all
3482 || (einfo
->info
->strip
== strip_some
3483 && bfd_hash_lookup (einfo
->info
->keep_hash
,
3484 h
->root
.root
.root
.string
,
3485 false, false) == NULL
))
3493 if (h
->esym
.ifd
== -2)
3496 h
->esym
.cobol_main
= 0;
3497 h
->esym
.weakext
= 0;
3498 h
->esym
.reserved
= 0;
3499 h
->esym
.ifd
= ifdNil
;
3500 h
->esym
.asym
.value
= 0;
3501 h
->esym
.asym
.st
= stGlobal
;
3503 if (SGI_COMPAT (einfo
->abfd
)
3504 && (h
->root
.root
.type
== bfd_link_hash_undefined
3505 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
3509 /* Use undefined class. Also, set class and type for some
3511 name
= h
->root
.root
.root
.string
;
3512 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
3513 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
3515 h
->esym
.asym
.sc
= scData
;
3516 h
->esym
.asym
.st
= stLabel
;
3517 h
->esym
.asym
.value
= 0;
3519 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
3521 h
->esym
.asym
.sc
= scAbs
;
3522 h
->esym
.asym
.st
= stLabel
;
3523 h
->esym
.asym
.value
=
3524 mips_elf_hash_table (einfo
->info
)->procedure_count
;
3526 else if (strcmp (name
, "_gp_disp") == 0)
3528 h
->esym
.asym
.sc
= scAbs
;
3529 h
->esym
.asym
.st
= stLabel
;
3530 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
3533 h
->esym
.asym
.sc
= scUndefined
;
3535 else if (h
->root
.root
.type
!= bfd_link_hash_defined
3536 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
3537 h
->esym
.asym
.sc
= scAbs
;
3542 sec
= h
->root
.root
.u
.def
.section
;
3543 output_section
= sec
->output_section
;
3545 /* When making a shared library and symbol h is the one from
3546 the another shared library, OUTPUT_SECTION may be null. */
3547 if (output_section
== NULL
)
3548 h
->esym
.asym
.sc
= scUndefined
;
3551 name
= bfd_section_name (output_section
->owner
, output_section
);
3553 if (strcmp (name
, ".text") == 0)
3554 h
->esym
.asym
.sc
= scText
;
3555 else if (strcmp (name
, ".data") == 0)
3556 h
->esym
.asym
.sc
= scData
;
3557 else if (strcmp (name
, ".sdata") == 0)
3558 h
->esym
.asym
.sc
= scSData
;
3559 else if (strcmp (name
, ".rodata") == 0
3560 || strcmp (name
, ".rdata") == 0)
3561 h
->esym
.asym
.sc
= scRData
;
3562 else if (strcmp (name
, ".bss") == 0)
3563 h
->esym
.asym
.sc
= scBss
;
3564 else if (strcmp (name
, ".sbss") == 0)
3565 h
->esym
.asym
.sc
= scSBss
;
3566 else if (strcmp (name
, ".init") == 0)
3567 h
->esym
.asym
.sc
= scInit
;
3568 else if (strcmp (name
, ".fini") == 0)
3569 h
->esym
.asym
.sc
= scFini
;
3571 h
->esym
.asym
.sc
= scAbs
;
3575 h
->esym
.asym
.reserved
= 0;
3576 h
->esym
.asym
.index
= indexNil
;
3579 if (h
->root
.root
.type
== bfd_link_hash_common
)
3580 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
3581 else if (h
->root
.root
.type
== bfd_link_hash_defined
3582 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3584 if (h
->esym
.asym
.sc
== scCommon
)
3585 h
->esym
.asym
.sc
= scBss
;
3586 else if (h
->esym
.asym
.sc
== scSCommon
)
3587 h
->esym
.asym
.sc
= scSBss
;
3589 sec
= h
->root
.root
.u
.def
.section
;
3590 output_section
= sec
->output_section
;
3591 if (output_section
!= NULL
)
3592 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
3593 + sec
->output_offset
3594 + output_section
->vma
);
3596 h
->esym
.asym
.value
= 0;
3598 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3600 /* Set type and value for a symbol with a function stub. */
3601 h
->esym
.asym
.st
= stProc
;
3602 sec
= h
->root
.root
.u
.def
.section
;
3604 h
->esym
.asym
.value
= 0;
3607 output_section
= sec
->output_section
;
3608 if (output_section
!= NULL
)
3609 h
->esym
.asym
.value
= (h
->root
.plt_offset
3610 + sec
->output_offset
3611 + output_section
->vma
);
3613 h
->esym
.asym
.value
= 0;
3620 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
3621 h
->root
.root
.root
.string
,
3624 einfo
->failed
= true;
3631 /* Create a runtime procedure table from the .mdebug section. */
3634 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
3637 struct bfd_link_info
*info
;
3639 struct ecoff_debug_info
*debug
;
3641 const struct ecoff_debug_swap
*swap
;
3642 HDRR
*hdr
= &debug
->symbolic_header
;
3644 struct rpdr_ext
*erp
;
3646 struct pdr_ext
*epdr
;
3647 struct sym_ext
*esym
;
3650 unsigned long size
, count
;
3651 unsigned long sindex
;
3655 const char *no_name_func
= "static procedure (no name)";
3663 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3665 sindex
= strlen (no_name_func
) + 1;
3666 count
= hdr
->ipdMax
;
3669 size
= swap
->external_pdr_size
;
3671 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
3675 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
3678 size
= sizeof (RPDR
);
3679 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
3683 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
3687 count
= hdr
->isymMax
;
3688 size
= swap
->external_sym_size
;
3689 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
3693 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
3696 count
= hdr
->issMax
;
3697 ss
= (char *) bfd_malloc (count
);
3700 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
3703 count
= hdr
->ipdMax
;
3704 for (i
= 0; i
< count
; i
++, rp
++)
3706 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
3707 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
3708 rp
->adr
= sym
.value
;
3709 rp
->regmask
= pdr
.regmask
;
3710 rp
->regoffset
= pdr
.regoffset
;
3711 rp
->fregmask
= pdr
.fregmask
;
3712 rp
->fregoffset
= pdr
.fregoffset
;
3713 rp
->frameoffset
= pdr
.frameoffset
;
3714 rp
->framereg
= pdr
.framereg
;
3715 rp
->pcreg
= pdr
.pcreg
;
3717 sv
[i
] = ss
+ sym
.iss
;
3718 sindex
+= strlen (sv
[i
]) + 1;
3722 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
3723 size
= BFD_ALIGN (size
, 16);
3724 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
3727 mips_elf_hash_table (info
)->procedure_count
= 0;
3731 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
3733 erp
= (struct rpdr_ext
*) rtproc
;
3734 memset (erp
, 0, sizeof (struct rpdr_ext
));
3736 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
3737 strcpy (str
, no_name_func
);
3738 str
+= strlen (no_name_func
) + 1;
3739 for (i
= 0; i
< count
; i
++)
3741 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
3742 strcpy (str
, sv
[i
]);
3743 str
+= strlen (sv
[i
]) + 1;
3745 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
3747 /* Set the size and contents of .rtproc section. */
3748 s
->_raw_size
= size
;
3749 s
->contents
= (bfd_byte
*) rtproc
;
3751 /* Skip this section later on (I don't think this currently
3752 matters, but someday it might). */
3753 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
3782 /* A comparison routine used to sort .gptab entries. */
3785 gptab_compare (p1
, p2
)
3789 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
3790 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
3792 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
3795 /* We need to use a special link routine to handle the .reginfo and
3796 the .mdebug sections. We need to merge all instances of these
3797 sections together, not write them all out sequentially. */
3800 mips_elf_final_link (abfd
, info
)
3802 struct bfd_link_info
*info
;
3806 struct bfd_link_order
*p
;
3807 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
3808 asection
*rtproc_sec
;
3809 Elf32_RegInfo reginfo
;
3810 struct ecoff_debug_info debug
;
3811 const struct ecoff_debug_swap
*swap
3812 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3813 HDRR
*symhdr
= &debug
.symbolic_header
;
3814 PTR mdebug_handle
= NULL
;
3816 /* Drop the .options section, since it has special semantics which I
3817 haven't bothered to figure out. */
3818 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
3820 if (strcmp ((*secpp
)->name
, ".options") == 0)
3822 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
3823 if (p
->type
== bfd_indirect_link_order
)
3824 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
3825 (*secpp
)->link_order_head
= NULL
;
3826 *secpp
= (*secpp
)->next
;
3827 --abfd
->section_count
;
3832 /* Get a value for the GP register. */
3833 if (elf_gp (abfd
) == 0)
3835 struct bfd_link_hash_entry
*h
;
3837 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
3838 if (h
!= (struct bfd_link_hash_entry
*) NULL
3839 && h
->type
== bfd_link_hash_defined
)
3840 elf_gp (abfd
) = (h
->u
.def
.value
3841 + h
->u
.def
.section
->output_section
->vma
3842 + h
->u
.def
.section
->output_offset
);
3843 else if (info
->relocateable
)
3847 /* Make up a value. */
3849 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3852 && (strcmp (o
->name
, ".sbss") == 0
3853 || strcmp (o
->name
, ".sdata") == 0
3854 || strcmp (o
->name
, ".lit4") == 0
3855 || strcmp (o
->name
, ".lit8") == 0))
3858 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
3862 /* If the relocate_section function needs to do a reloc
3863 involving the GP value, it should make a reloc_dangerous
3864 callback to warn that GP is not defined. */
3868 /* Go through the sections and collect the .reginfo and .mdebug
3872 gptab_data_sec
= NULL
;
3873 gptab_bss_sec
= NULL
;
3874 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3876 if (strcmp (o
->name
, ".reginfo") == 0)
3878 memset (®info
, 0, sizeof reginfo
);
3880 /* We have found the .reginfo section in the output file.
3881 Look through all the link_orders comprising it and merge
3882 the information together. */
3883 for (p
= o
->link_order_head
;
3884 p
!= (struct bfd_link_order
*) NULL
;
3887 asection
*input_section
;
3889 Elf32_External_RegInfo ext
;
3892 if (p
->type
!= bfd_indirect_link_order
)
3894 if (p
->type
== bfd_fill_link_order
)
3899 input_section
= p
->u
.indirect
.section
;
3900 input_bfd
= input_section
->owner
;
3902 /* The linker emulation code has probably clobbered the
3903 size to be zero bytes. */
3904 if (input_section
->_raw_size
== 0)
3905 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3907 if (! bfd_get_section_contents (input_bfd
, input_section
,
3913 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
3915 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
3916 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
3917 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
3918 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
3919 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
3921 /* ri_gp_value is set by the function
3922 mips_elf32_section_processing when the section is
3923 finally written out. */
3925 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3926 elf_link_input_bfd ignores this section. */
3927 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3930 /* Force the section size to the value we want. */
3931 o
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3933 /* Skip this section later on (I don't think this currently
3934 matters, but someday it might). */
3935 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3940 if (strcmp (o
->name
, ".mdebug") == 0)
3942 struct extsym_info einfo
;
3944 /* We have found the .mdebug section in the output file.
3945 Look through all the link_orders comprising it and merge
3946 the information together. */
3947 symhdr
->magic
= swap
->sym_magic
;
3948 /* FIXME: What should the version stamp be? */
3950 symhdr
->ilineMax
= 0;
3954 symhdr
->isymMax
= 0;
3955 symhdr
->ioptMax
= 0;
3956 symhdr
->iauxMax
= 0;
3958 symhdr
->issExtMax
= 0;
3961 symhdr
->iextMax
= 0;
3963 /* We accumulate the debugging information itself in the
3964 debug_info structure. */
3966 debug
.external_dnr
= NULL
;
3967 debug
.external_pdr
= NULL
;
3968 debug
.external_sym
= NULL
;
3969 debug
.external_opt
= NULL
;
3970 debug
.external_aux
= NULL
;
3972 debug
.ssext
= debug
.ssext_end
= NULL
;
3973 debug
.external_fdr
= NULL
;
3974 debug
.external_rfd
= NULL
;
3975 debug
.external_ext
= debug
.external_ext_end
= NULL
;
3977 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
3978 if (mdebug_handle
== (PTR
) NULL
)
3981 if (SGI_COMPAT (abfd
))
3987 static const char * const name
[] =
3988 { ".text", ".init", ".fini", ".data",
3989 ".rodata", ".sdata", ".sbss", ".bss" };
3990 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
3991 scRData
, scSData
, scSBss
, scBss
};
3994 esym
.cobol_main
= 0;
3998 esym
.asym
.iss
= issNil
;
3999 esym
.asym
.st
= stLocal
;
4000 esym
.asym
.reserved
= 0;
4001 esym
.asym
.index
= indexNil
;
4002 for (i
= 0; i
< 8; i
++)
4004 esym
.asym
.sc
= sc
[i
];
4005 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4008 esym
.asym
.value
= s
->vma
;
4009 last
= s
->vma
+ s
->_raw_size
;
4012 esym
.asym
.value
= last
;
4014 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4020 for (p
= o
->link_order_head
;
4021 p
!= (struct bfd_link_order
*) NULL
;
4024 asection
*input_section
;
4026 const struct ecoff_debug_swap
*input_swap
;
4027 struct ecoff_debug_info input_debug
;
4031 if (p
->type
!= bfd_indirect_link_order
)
4033 if (p
->type
== bfd_fill_link_order
)
4038 input_section
= p
->u
.indirect
.section
;
4039 input_bfd
= input_section
->owner
;
4041 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4042 || (get_elf_backend_data (input_bfd
)
4043 ->elf_backend_ecoff_debug_swap
) == NULL
)
4045 /* I don't know what a non MIPS ELF bfd would be
4046 doing with a .mdebug section, but I don't really
4047 want to deal with it. */
4051 input_swap
= (get_elf_backend_data (input_bfd
)
4052 ->elf_backend_ecoff_debug_swap
);
4054 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
4056 /* The ECOFF linking code expects that we have already
4057 read in the debugging information and set up an
4058 ecoff_debug_info structure, so we do that now. */
4059 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
4063 if (! (bfd_ecoff_debug_accumulate
4064 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
4065 &input_debug
, input_swap
, info
)))
4068 /* Loop through the external symbols. For each one with
4069 interesting information, try to find the symbol in
4070 the linker global hash table and save the information
4071 for the output external symbols. */
4072 eraw_src
= input_debug
.external_ext
;
4073 eraw_end
= (eraw_src
4074 + (input_debug
.symbolic_header
.iextMax
4075 * input_swap
->external_ext_size
));
4077 eraw_src
< eraw_end
;
4078 eraw_src
+= input_swap
->external_ext_size
)
4082 struct mips_elf_link_hash_entry
*h
;
4084 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4085 if (ext
.asym
.sc
== scNil
4086 || ext
.asym
.sc
== scUndefined
4087 || ext
.asym
.sc
== scSUndefined
)
4090 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4091 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
4092 name
, false, false, true);
4093 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4099 < input_debug
.symbolic_header
.ifdMax
);
4100 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4106 /* Free up the information we just read. */
4107 free (input_debug
.line
);
4108 free (input_debug
.external_dnr
);
4109 free (input_debug
.external_pdr
);
4110 free (input_debug
.external_sym
);
4111 free (input_debug
.external_opt
);
4112 free (input_debug
.external_aux
);
4113 free (input_debug
.ss
);
4114 free (input_debug
.ssext
);
4115 free (input_debug
.external_fdr
);
4116 free (input_debug
.external_rfd
);
4117 free (input_debug
.external_ext
);
4119 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4120 elf_link_input_bfd ignores this section. */
4121 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4124 if (SGI_COMPAT (abfd
) && info
->shared
)
4126 /* Create .rtproc section. */
4127 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4128 if (rtproc_sec
== NULL
)
4130 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4131 | SEC_LINKER_CREATED
| SEC_READONLY
);
4133 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4134 if (rtproc_sec
== NULL
4135 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4136 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
4140 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
4141 info
, rtproc_sec
, &debug
))
4145 /* Build the external symbol information. */
4148 einfo
.debug
= &debug
;
4150 einfo
.failed
= false;
4151 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4152 mips_elf_output_extsym
,
4157 /* Set the size of the .mdebug section. */
4158 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4160 /* Skip this section later on (I don't think this currently
4161 matters, but someday it might). */
4162 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4167 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4169 const char *subname
;
4172 Elf32_External_gptab
*ext_tab
;
4175 /* The .gptab.sdata and .gptab.sbss sections hold
4176 information describing how the small data area would
4177 change depending upon the -G switch. These sections
4178 not used in executables files. */
4179 if (! info
->relocateable
)
4183 for (p
= o
->link_order_head
;
4184 p
!= (struct bfd_link_order
*) NULL
;
4187 asection
*input_section
;
4189 if (p
->type
!= bfd_indirect_link_order
)
4191 if (p
->type
== bfd_fill_link_order
)
4196 input_section
= p
->u
.indirect
.section
;
4198 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4199 elf_link_input_bfd ignores this section. */
4200 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4203 /* Skip this section later on (I don't think this
4204 currently matters, but someday it might). */
4205 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4207 /* Really remove the section. */
4208 for (secpp
= &abfd
->sections
;
4210 secpp
= &(*secpp
)->next
)
4212 *secpp
= (*secpp
)->next
;
4213 --abfd
->section_count
;
4218 /* There is one gptab for initialized data, and one for
4219 uninitialized data. */
4220 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4222 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4226 (*_bfd_error_handler
)
4227 ("%s: illegal section name `%s'",
4228 bfd_get_filename (abfd
), o
->name
);
4229 bfd_set_error (bfd_error_nonrepresentable_section
);
4233 /* The linker script always combines .gptab.data and
4234 .gptab.sdata into .gptab.sdata, and likewise for
4235 .gptab.bss and .gptab.sbss. It is possible that there is
4236 no .sdata or .sbss section in the output file, in which
4237 case we must change the name of the output section. */
4238 subname
= o
->name
+ sizeof ".gptab" - 1;
4239 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4241 if (o
== gptab_data_sec
)
4242 o
->name
= ".gptab.data";
4244 o
->name
= ".gptab.bss";
4245 subname
= o
->name
+ sizeof ".gptab" - 1;
4246 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4249 /* Set up the first entry. */
4251 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
4254 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4255 tab
[0].gt_header
.gt_unused
= 0;
4257 /* Combine the input sections. */
4258 for (p
= o
->link_order_head
;
4259 p
!= (struct bfd_link_order
*) NULL
;
4262 asection
*input_section
;
4266 bfd_size_type gpentry
;
4268 if (p
->type
!= bfd_indirect_link_order
)
4270 if (p
->type
== bfd_fill_link_order
)
4275 input_section
= p
->u
.indirect
.section
;
4276 input_bfd
= input_section
->owner
;
4278 /* Combine the gptab entries for this input section one
4279 by one. We know that the input gptab entries are
4280 sorted by ascending -G value. */
4281 size
= bfd_section_size (input_bfd
, input_section
);
4283 for (gpentry
= sizeof (Elf32_External_gptab
);
4285 gpentry
+= sizeof (Elf32_External_gptab
))
4287 Elf32_External_gptab ext_gptab
;
4288 Elf32_gptab int_gptab
;
4294 if (! (bfd_get_section_contents
4295 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4296 gpentry
, sizeof (Elf32_External_gptab
))))
4302 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
4304 val
= int_gptab
.gt_entry
.gt_g_value
;
4305 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4308 for (look
= 1; look
< c
; look
++)
4310 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4311 tab
[look
].gt_entry
.gt_bytes
+= add
;
4313 if (tab
[look
].gt_entry
.gt_g_value
== val
)
4319 Elf32_gptab
*new_tab
;
4322 /* We need a new table entry. */
4323 new_tab
= ((Elf32_gptab
*)
4324 bfd_realloc ((PTR
) tab
,
4325 (c
+ 1) * sizeof (Elf32_gptab
)));
4326 if (new_tab
== NULL
)
4332 tab
[c
].gt_entry
.gt_g_value
= val
;
4333 tab
[c
].gt_entry
.gt_bytes
= add
;
4335 /* Merge in the size for the next smallest -G
4336 value, since that will be implied by this new
4339 for (look
= 1; look
< c
; look
++)
4341 if (tab
[look
].gt_entry
.gt_g_value
< val
4343 || (tab
[look
].gt_entry
.gt_g_value
4344 > tab
[max
].gt_entry
.gt_g_value
)))
4348 tab
[c
].gt_entry
.gt_bytes
+=
4349 tab
[max
].gt_entry
.gt_bytes
;
4354 last
= int_gptab
.gt_entry
.gt_bytes
;
4357 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4358 elf_link_input_bfd ignores this section. */
4359 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4362 /* The table must be sorted by -G value. */
4364 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
4366 /* Swap out the table. */
4367 ext_tab
= ((Elf32_External_gptab
*)
4368 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
4369 if (ext_tab
== NULL
)
4375 for (i
= 0; i
< c
; i
++)
4376 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
4379 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
4380 o
->contents
= (bfd_byte
*) ext_tab
;
4382 /* Skip this section later on (I don't think this currently
4383 matters, but someday it might). */
4384 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4388 /* Invoke the regular ELF backend linker to do all the work. */
4389 if (! bfd_elf32_bfd_final_link (abfd
, info
))
4392 /* Now write out the computed sections. */
4394 if (reginfo_sec
!= (asection
*) NULL
)
4396 Elf32_External_RegInfo ext
;
4398 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
4399 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4400 (file_ptr
) 0, sizeof ext
))
4404 if (mdebug_sec
!= (asection
*) NULL
)
4406 BFD_ASSERT (abfd
->output_has_begun
);
4407 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4409 mdebug_sec
->filepos
))
4412 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4415 if (gptab_data_sec
!= (asection
*) NULL
)
4417 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4418 gptab_data_sec
->contents
,
4420 gptab_data_sec
->_raw_size
))
4424 if (gptab_bss_sec
!= (asection
*) NULL
)
4426 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4427 gptab_bss_sec
->contents
,
4429 gptab_bss_sec
->_raw_size
))
4433 if (SGI_COMPAT (abfd
))
4435 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4436 if (rtproc_sec
!= NULL
)
4438 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
4439 rtproc_sec
->contents
,
4441 rtproc_sec
->_raw_size
))
4449 /* Handle a MIPS ELF HI16 reloc. */
4452 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
4454 Elf_Internal_Rela
*relhi
;
4455 Elf_Internal_Rela
*rello
;
4462 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4464 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4467 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4469 if ((addlo
& 0x8000) != 0)
4471 if ((addend
& 0x8000) != 0)
4474 bfd_put_32 (input_bfd
,
4475 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
4476 contents
+ relhi
->r_offset
);
4479 /* Handle a MIPS ELF local GOT16 reloc. */
4482 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
4487 Elf_Internal_Rela
*relhi
;
4488 Elf_Internal_Rela
*rello
;
4492 unsigned int assigned_gotno
;
4498 bfd_byte
*got_contents
;
4499 struct mips_got_info
*g
;
4501 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4503 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4506 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4508 if ((addlo
& 0x8000) != 0)
4510 if ((addend
& 0x8000) != 0)
4513 /* Get a got entry representing requested hipage. */
4514 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4515 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4516 BFD_ASSERT (g
!= NULL
);
4518 assigned_gotno
= g
->assigned_gotno
;
4519 got_contents
= sgot
->contents
;
4520 hipage
= addend
& 0xffff0000;
4522 for (i
= MIPS_RESERVED_GOTNO
; i
< assigned_gotno
; i
++)
4524 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
4525 if (hipage
== (address
& 0xffff0000))
4529 if (i
== assigned_gotno
)
4531 if (assigned_gotno
>= g
->local_gotno
)
4533 (*_bfd_error_handler
)
4534 ("more got entries are needed for hipage relocations");
4535 bfd_set_error (bfd_error_bad_value
);
4539 bfd_put_32 (input_bfd
, hipage
, got_contents
+ assigned_gotno
* 4);
4540 ++g
->assigned_gotno
;
4543 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
4544 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
4545 contents
+ relhi
->r_offset
);
4550 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
4553 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
4555 Elf_Internal_Rela
*rel
;
4561 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4562 bfd_put_32 (input_bfd
,
4563 (insn
& 0xffff0000) | (offset
& 0xffff),
4564 contents
+ rel
->r_offset
);
4567 /* Relocate a MIPS ELF section. */
4570 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4571 contents
, relocs
, local_syms
, local_sections
)
4573 struct bfd_link_info
*info
;
4575 asection
*input_section
;
4577 Elf_Internal_Rela
*relocs
;
4578 Elf_Internal_Sym
*local_syms
;
4579 asection
**local_sections
;
4581 Elf_Internal_Shdr
*symtab_hdr
;
4584 asection
*sgot
, *sreloc
, *scpt
;
4587 Elf_Internal_Rela
*rel
;
4588 Elf_Internal_Rela
*relend
;
4589 struct mips_got_info
*g
;
4591 dynobj
= elf_hash_table (info
)->dynobj
;
4592 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4596 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
4599 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
4602 if (elf_bad_symtab (input_bfd
))
4604 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
4609 locsymcount
= symtab_hdr
->sh_info
;
4610 extsymoff
= symtab_hdr
->sh_info
;
4613 gp
= _bfd_get_gp_value (output_bfd
);
4616 relend
= relocs
+ input_section
->reloc_count
;
4617 for (; rel
< relend
; rel
++)
4620 reloc_howto_type
*howto
;
4621 unsigned long r_symndx
;
4623 struct elf_link_hash_entry
*h
;
4625 Elf_Internal_Sym
*sym
;
4626 struct mips_elf_link_hash_entry
*mh
;
4628 bfd_reloc_status_type r
;
4630 r_type
= ELF32_R_TYPE (rel
->r_info
);
4631 if ((r_type
< 0 || r_type
>= (int) R_MIPS_max
)
4632 /* start-sanitize-sky */
4633 && r_type
!= R_MIPS_DVP_11_PCREL
4634 /* end-sanitize-sky */
4635 && r_type
!= R_MIPS16_26
4636 && r_type
!= R_MIPS16_GPREL
)
4638 bfd_set_error (bfd_error_bad_value
);
4641 if (r_type
== R_MIPS16_26
)
4642 howto
= &elf_mips16_jump_howto
;
4643 else if (r_type
== R_MIPS16_GPREL
)
4644 howto
= &elf_mips16_gprel_howto
;
4645 /* start-sanitize-sky */
4646 else if (r_type
== R_MIPS_DVP_11_PCREL
)
4647 howto
= &elf_mips_dvp_11_pcrel_howto
;
4648 /* end-sanitize-sky */
4650 howto
= elf_mips_howto_table
+ r_type
;
4653 && (r_type
== R_MIPS_CALL16
4654 || r_type
== R_MIPS_GOT16
4655 || r_type
== R_MIPS_CALL_HI16
4656 || r_type
== R_MIPS_CALL_LO16
4657 || r_type
== R_MIPS_GOT_HI16
4658 || r_type
== R_MIPS_GOT_LO16
))
4660 /* We need the .got section. */
4663 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4664 BFD_ASSERT (sgot
!= NULL
);
4665 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4666 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4667 BFD_ASSERT (g
!= NULL
);
4671 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4673 /* Mix in the change in GP address for a GP relative reloc. */
4674 if (r_type
!= R_MIPS_GPREL16
4675 && r_type
!= R_MIPS_LITERAL
4676 && r_type
!= R_MIPS_GPREL32
4677 && r_type
!= R_MIPS16_GPREL
)
4683 if (! ((*info
->callbacks
->reloc_dangerous
)
4685 "GP relative relocation when GP not defined",
4686 input_bfd
, input_section
,
4689 /* Only give the error once per link. */
4691 _bfd_set_gp_value (output_bfd
, gp
);
4694 if (r_symndx
< extsymoff
4695 || (elf_bad_symtab (input_bfd
)
4696 && local_sections
[r_symndx
] != NULL
))
4698 /* This is a relocation against a section. The current
4699 addend in the instruction is the difference between
4700 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
4701 must change this to be the difference between the
4702 final definition (which will end up in RELOCATION)
4703 and the GP value of OUTPUT_BFD (which is in GP). */
4704 addend
= elf_gp (input_bfd
) - gp
;
4706 else if (! info
->relocateable
)
4708 /* We are doing a final link. The current addend in the
4709 instruction is simply the desired offset into the
4710 symbol (normally zero). We want the instruction to
4711 hold the difference between the final definition of
4712 the symbol (which will end up in RELOCATION) and the
4713 GP value of OUTPUT_BFD (which is in GP). */
4718 /* We are generating relocateable output, and we aren't
4719 going to define this symbol, so we just leave the
4720 instruction alone. */
4728 if (info
->relocateable
)
4730 /* This is a relocateable link. We don't have to change
4731 anything, unless the reloc is against a section symbol,
4732 in which case we have to adjust according to where the
4733 section symbol winds up in the output section. */
4734 if (r_symndx
>= locsymcount
4735 || (elf_bad_symtab (input_bfd
)
4736 && local_sections
[r_symndx
] == NULL
))
4740 sym
= local_syms
+ r_symndx
;
4741 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4745 sec
= local_sections
[r_symndx
];
4747 /* It would be logical to add sym->st_value here,
4748 but Irix 5 sometimes generates a garbage symbol
4750 addend
+= sec
->output_offset
;
4752 /* If this is HI16 or GOT16 with an associated LO16,
4753 adjust the addend accordingly. Otherwise, just
4755 if (r_type
== R_MIPS_64
&& bfd_big_endian (input_bfd
))
4756 r
= _bfd_relocate_contents (howto
, input_bfd
,
4758 contents
+ rel
->r_offset
+ 4);
4759 else if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
4760 r
= _bfd_relocate_contents (howto
, input_bfd
,
4762 contents
+ rel
->r_offset
);
4765 Elf_Internal_Rela
*lorel
;
4767 /* As a GNU extension, permit an arbitrary
4768 number of R_MIPS_HI16 relocs before the
4769 R_MIPS_LO16 reloc. This permits gcc to emit
4770 the HI and LO relocs itself. */
4771 if (r_type
== R_MIPS_GOT16
)
4775 for (lorel
= rel
+ 1;
4777 && (ELF32_R_TYPE (lorel
->r_info
)
4783 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
4785 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
4790 r
= _bfd_relocate_contents (howto
, input_bfd
,
4792 contents
+ rel
->r_offset
);
4802 /* This is a final link. */
4804 if (r_symndx
< extsymoff
4805 || (elf_bad_symtab (input_bfd
)
4806 && local_sections
[r_symndx
] != NULL
))
4809 sym
= local_syms
+ r_symndx
;
4810 sec
= local_sections
[r_symndx
];
4811 relocation
= (sec
->output_section
->vma
4812 + sec
->output_offset
);
4814 /* It would be logical to always add sym->st_value here,
4815 but Irix 5 sometimes generates a garbage symbol
4817 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4818 relocation
+= sym
->st_value
;
4820 /* mips16 text labels should be treated as odd. */
4821 if (sym
->st_other
== STO_MIPS16
)
4829 indx
= r_symndx
- extsymoff
;
4830 h
= elf_sym_hashes (input_bfd
)[indx
];
4831 while (h
->root
.type
== bfd_link_hash_indirect
4832 || h
->root
.type
== bfd_link_hash_warning
)
4833 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4834 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
4838 if (! ((*info
->callbacks
->reloc_dangerous
)
4840 "_gp_disp used when GP not defined",
4841 input_bfd
, input_section
,
4844 /* Only give the error once per link. */
4846 _bfd_set_gp_value (output_bfd
, gp
);
4851 sec
= input_section
;
4852 if (sec
->output_section
!= NULL
)
4855 + sec
->output_section
->vma
4856 + sec
->output_offset
));
4858 relocation
= gp
- rel
->r_offset
;
4859 if (r_type
== R_MIPS_LO16
)
4863 else if (h
->root
.type
== bfd_link_hash_defined
4864 || h
->root
.type
== bfd_link_hash_defweak
)
4866 sec
= h
->root
.u
.def
.section
;
4867 if (sec
->output_section
== NULL
)
4870 relocation
= (h
->root
.u
.def
.value
4871 + sec
->output_section
->vma
4872 + sec
->output_offset
);
4874 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4876 else if (info
->shared
&& ! info
->symbolic
)
4878 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
4880 /* If this is a dynamic link, we should have created
4881 a _DYNAMIC_LINK symbol in
4882 mips_elf_create_dynamic_sections. Otherwise, we
4883 should define the symbol with a value of 0.
4884 FIXME: It should probably get into the symbol
4885 table somehow as well. */
4886 BFD_ASSERT (! info
->shared
);
4887 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
4888 ".dynamic") == NULL
);
4893 if (! ((*info
->callbacks
->undefined_symbol
)
4894 (info
, h
->root
.root
.string
, input_bfd
,
4895 input_section
, rel
->r_offset
)))
4901 mh
= (struct mips_elf_link_hash_entry
*) h
;
4904 else if (sym
!= NULL
)
4905 other
= sym
->st_other
;
4909 /* If this function has an fn_stub, then it is a mips16
4910 function which needs a stub if it is called by a 32 bit
4911 function. If this reloc is anything other than a 16 bit
4912 call, redirect the reloc to the stub. We don't redirect
4913 relocs from other stub functions. */
4914 if (r_type
!= R_MIPS16_26
4916 && mh
->fn_stub
!= NULL
)
4918 && elf_tdata (input_bfd
)->local_stubs
!= NULL
4919 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
4920 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
4921 FN_STUB
, sizeof FN_STUB
- 1) != 0
4922 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
4923 CALL_STUB
, sizeof CALL_STUB
- 1) != 0
4924 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
4925 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) != 0)
4929 BFD_ASSERT (mh
->need_fn_stub
);
4930 relocation
= (mh
->fn_stub
->output_section
->vma
4931 + mh
->fn_stub
->output_offset
);
4937 fn_stub
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
4938 relocation
= (fn_stub
->output_section
->vma
4939 + fn_stub
->output_offset
);
4942 /* RELOCATION now points to 32 bit code. */
4946 /* If this function has a call_stub, then it is called by a
4947 mips16 function; the call needs to go through a stub if
4948 this function is a 32 bit function. If this reloc is a
4949 16 bit call, and the symbol is not a 16 bit function,
4950 then redirect the reloc to the stub. Note that we don't
4951 need to worry about calling the function through a
4952 function pointer; such calls are handled by routing
4953 through a special mips16 routine. We don't have to check
4954 whether this call is from a stub; it can't be, because a
4955 stub contains 32 bit code, and hence can not have a 16
4957 if (r_type
== R_MIPS16_26
4959 && (mh
->call_stub
!= NULL
|| mh
->call_fp_stub
!= NULL
)
4960 && other
!= STO_MIPS16
)
4964 /* If both call_stub and call_fp_stub are defined, we
4965 can figure out which one to use by seeing which one
4966 appears in the input file. */
4967 if (mh
->call_stub
!= NULL
&& mh
->call_fp_stub
!= NULL
)
4972 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
4974 if (strncmp (bfd_get_section_name (input_bfd
, o
),
4975 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
4977 stub
= mh
->call_fp_stub
;
4982 stub
= mh
->call_stub
;
4984 else if (mh
->call_stub
!= NULL
)
4985 stub
= mh
->call_stub
;
4987 stub
= mh
->call_fp_stub
;
4989 BFD_ASSERT (stub
->_raw_size
> 0);
4990 relocation
= stub
->output_section
->vma
+ stub
->output_offset
;
4993 if (r_type
== R_MIPS_HI16
)
4995 Elf_Internal_Rela
*lorel
;
4997 /* As a GNU extension, permit an arbitrary number of
4998 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
4999 This permits gcc to emit the HI and LO relocs itself. */
5000 for (lorel
= rel
+ 1;
5002 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
5006 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5008 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5009 contents
, relocation
+ addend
);
5013 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5014 contents
, rel
->r_offset
,
5015 relocation
, addend
);
5017 else if (r_type
== R_MIPS_GOT16
&& local
)
5019 /* GOT16 must also have an associated LO16 in the local
5020 case. In this case, the addend is extracted and the
5021 section in which the referenced object is determined.
5022 Then the final address of the object is computed and
5023 the GOT entry for the hipage (an aligned 64kb chunk)
5024 is added to .got section if needed. The offset field
5025 of the GOT16-relocated instruction is replaced by the
5026 index of this GOT entry for the hipage. */
5027 if ((rel
+ 1) < relend
5028 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
5030 if (! mips_elf_relocate_got_local (output_bfd
, input_bfd
,
5033 relocation
+ addend
))
5038 r
= bfd_reloc_outofrange
;
5040 else if (r_type
== R_MIPS_CALL16
5041 || r_type
== R_MIPS_GOT16
5042 || r_type
== R_MIPS_CALL_LO16
5043 || r_type
== R_MIPS_GOT_LO16
)
5047 /* This symbol must be registered as a global symbol
5048 having the corresponding got entry. */
5049 BFD_ASSERT (h
->got_offset
!= (bfd_vma
) -1);
5051 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5052 BFD_ASSERT (g
->local_gotno
<= offset
5053 && offset
< sgot
->_raw_size
);
5054 bfd_put_32 (output_bfd
, relocation
+ addend
,
5055 sgot
->contents
+ offset
);
5056 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5058 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
5062 else if (r_type
== R_MIPS_CALL_HI16
5063 || r_type
== R_MIPS_GOT_HI16
)
5067 /* This must be a global symbol with a got entry. The
5068 next reloc must be the corresponding LO16 reloc. */
5069 BFD_ASSERT (h
!= NULL
&& h
->got_offset
!= (bfd_vma
) -1);
5070 BFD_ASSERT ((rel
+ 1) < relend
);
5071 BFD_ASSERT (ELF32_R_TYPE ((rel
+ 1)->r_info
)
5072 == (r_type
== R_MIPS_CALL_HI16
5074 : R_MIPS_GOT_LO16
));
5076 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5077 BFD_ASSERT (g
->local_gotno
<= offset
5078 && offset
< sgot
->_raw_size
);
5079 bfd_put_32 (output_bfd
, relocation
+ addend
,
5080 sgot
->contents
+ offset
);
5081 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5083 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
5087 else if (r_type
== R_MIPS_REL32
5088 || r_type
== R_MIPS_32
)
5090 Elf_Internal_Rel outrel
;
5091 Elf32_crinfo cptrel
;
5095 || (elf_hash_table (info
)->dynamic_sections_created
5097 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
5099 && (input_section
->flags
& SEC_ALLOC
) != 0)
5103 /* When generating a shared object, these
5104 relocations are copied into the output file to be
5105 resolved at run time. */
5108 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5109 BFD_ASSERT (sreloc
!= NULL
);
5114 if (elf_section_data (input_section
)->stab_info
== NULL
)
5115 outrel
.r_offset
= rel
->r_offset
;
5120 off
= (_bfd_stab_section_offset
5121 (output_bfd
, &elf_hash_table (info
)->stab_info
,
5123 &elf_section_data (input_section
)->stab_info
,
5125 if (off
== (bfd_vma
) -1)
5127 outrel
.r_offset
= off
;
5130 outrel
.r_offset
+= (input_section
->output_section
->vma
5131 + input_section
->output_offset
);
5133 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5136 memset (&outrel
, 0, sizeof outrel
);
5138 && (! info
->symbolic
5139 || (h
->elf_link_hash_flags
5140 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5142 BFD_ASSERT (h
->dynindx
!= -1);
5143 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
5144 sec
= input_section
;
5151 sec
= local_sections
[r_symndx
];
5154 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
5156 == bfd_link_hash_defweak
));
5157 sec
= h
->root
.u
.def
.section
;
5159 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5161 else if (sec
== NULL
|| sec
->owner
== NULL
)
5163 bfd_set_error (bfd_error_bad_value
);
5170 osec
= sec
->output_section
;
5171 indx
= elf_section_data (osec
)->dynindx
;
5176 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
5177 addend
+= relocation
;
5181 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
5183 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
5184 (((Elf32_External_Rel
*)
5186 + sreloc
->reloc_count
));
5187 ++sreloc
->reloc_count
;
5189 if (! skip
&& SGI_COMPAT (output_bfd
))
5194 /* Make an entry of compact relocation info. */
5195 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5196 cptrel
.vaddr
= (rel
->r_offset
5197 + input_section
->output_section
->vma
5198 + input_section
->output_offset
);
5199 if (r_type
== R_MIPS_REL32
)
5200 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5202 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5203 mips_elf_set_cr_dist2to (cptrel
, 0);
5204 cptrel
.konst
= addend
;
5206 cr
= (scpt
->contents
5207 + sizeof (Elf32_External_compact_rel
));
5208 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5209 ((Elf32_External_crinfo
*) cr
5210 + scpt
->reloc_count
));
5211 ++scpt
->reloc_count
;
5214 /* This reloc will be computed at runtime, so
5215 there's no need to do anything now. */
5219 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5220 contents
, rel
->r_offset
,
5221 relocation
, addend
);
5223 else if (r_type
== R_MIPS_64
)
5228 /* Do a 32 bit relocation, and sign extend to 64 bits. */
5229 addr
= rel
->r_offset
;
5230 if (bfd_big_endian (input_bfd
))
5232 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5233 contents
, addr
, relocation
,
5235 val
= bfd_get_32 (input_bfd
, contents
+ addr
);
5236 if ((val
& 0x80000000) != 0)
5240 addr
= rel
->r_offset
;
5241 if (bfd_little_endian (input_bfd
))
5243 bfd_put_32 (input_bfd
, val
, contents
+ addr
);
5245 else if (r_type
== R_MIPS_26
&& other
== STO_MIPS16
)
5249 /* This is a jump to a mips16 routine from a mips32
5250 routine. We need to change jal into jalx. */
5251 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5252 if (((insn
>> 26) & 0x3f) != 0x3
5253 && ((insn
>> 26) & 0x3f) != 0x1d)
5255 (*_bfd_error_handler
)
5256 ("%s: %s+0x%lx: jump to mips16 routine which is not jal",
5257 bfd_get_filename (input_bfd
),
5258 input_section
->name
,
5259 (unsigned long) rel
->r_offset
);
5260 bfd_set_error (bfd_error_bad_value
);
5263 insn
= (insn
& 0x3ffffff) | (0x1d << 26);
5264 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5265 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5266 contents
, rel
->r_offset
,
5267 relocation
, addend
);
5269 else if (r_type
== R_MIPS16_26
)
5271 /* It's easiest to do the normal relocation, and then
5272 dig out the instruction and swap the first word the
5273 way the mips16 expects it. If this is little endian,
5274 though, we need to swap the two words first, and then
5275 swap them back again later, so that the address looks
5278 if (bfd_little_endian (input_bfd
))
5282 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5283 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5284 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5287 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5288 contents
, rel
->r_offset
,
5289 relocation
, addend
);
5290 if (r
== bfd_reloc_ok
)
5294 if (bfd_little_endian (input_bfd
))
5296 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5297 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5298 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5301 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5302 insn
= ((insn
& 0xfc00)
5303 | ((insn
& 0x1f) << 5)
5304 | ((insn
& 0x3e0) >> 5));
5305 /* If this is a jump to a 32 bit routine, then make
5307 if (other
!= STO_MIPS16
)
5309 bfd_put_16 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5312 else if (r_type
== R_MIPS16_GPREL
)
5314 unsigned short extend
, insn
;
5316 unsigned long final
;
5318 /* Extract the addend into buf, run the regular reloc,
5319 and stuff the resulting value back into the
5321 if (rel
->r_offset
> input_section
->_raw_size
)
5322 r
= bfd_reloc_outofrange
;
5325 extend
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5326 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 2);
5327 bfd_put_32 (input_bfd
,
5328 (((extend
& 0x1f) << 11)
5332 r
= _bfd_final_link_relocate (howto
, input_bfd
,
5334 (bfd_vma
) 0, relocation
,
5336 final
= bfd_get_32 (input_bfd
, buf
);
5337 bfd_put_16 (input_bfd
,
5339 | ((final
>> 11) & 0x1f)
5341 contents
+ rel
->r_offset
);
5342 bfd_put_16 (input_bfd
,
5345 contents
+ rel
->r_offset
+ 2);
5349 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5350 contents
, rel
->r_offset
,
5351 relocation
, addend
);
5353 /* The jal instruction can only jump to an address which is
5354 divisible by 4, and it can only jump to an address with
5355 the same upper 4 bits as the PC. */
5356 if (r
== bfd_reloc_ok
5357 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
))
5362 if (other
== STO_MIPS16
)
5363 addr
&= ~ (bfd_vma
) 1;
5366 || ((addr
& 0xf0000000)
5367 != ((input_section
->output_section
->vma
5368 + input_section
->output_offset
5371 r
= bfd_reloc_overflow
;
5374 if (SGI_COMPAT (abfd
)
5376 && (input_section
->flags
& SEC_ALLOC
) != 0)
5378 Elf32_crinfo cptrel
;
5381 /* Make an entry of compact relocation info. */
5382 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5383 cptrel
.vaddr
= (rel
->r_offset
5384 + input_section
->output_section
->vma
5385 + input_section
->output_offset
);
5390 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
5391 /* XXX How should we set dist2to in this case. */
5392 mips_elf_set_cr_dist2to (cptrel
, 8);
5393 cptrel
.konst
= addend
+ relocation
;
5394 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5395 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5396 ((Elf32_External_crinfo
*) cr
5397 + scpt
->reloc_count
));
5398 ++scpt
->reloc_count
;
5401 case R_MIPS_GPREL16
:
5402 case R_MIPS_LITERAL
:
5403 case R_MIPS_GPREL32
:
5404 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
5405 cptrel
.konst
= gp
- cptrel
.vaddr
;
5406 mips_elf_set_cr_dist2to (cptrel
, 4);
5407 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5408 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5409 ((Elf32_External_crinfo
*) cr
5410 + scpt
->reloc_count
));
5411 ++scpt
->reloc_count
;
5420 if (r
!= bfd_reloc_ok
)
5425 case bfd_reloc_outofrange
:
5427 case bfd_reloc_overflow
:
5432 name
= h
->root
.root
.string
;
5435 name
= bfd_elf_string_from_elf_section (input_bfd
,
5436 symtab_hdr
->sh_link
,
5441 name
= bfd_section_name (input_bfd
, sec
);
5443 if (! ((*info
->callbacks
->reloc_overflow
)
5444 (info
, name
, howto
->name
, (bfd_vma
) 0,
5445 input_bfd
, input_section
, rel
->r_offset
)))
5456 /* This hook function is called before the linker writes out a global
5457 symbol. We mark symbols as small common if appropriate. This is
5458 also where we undo the increment of the value for a mips16 symbol. */
5462 mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
5464 struct bfd_link_info
*info
;
5466 Elf_Internal_Sym
*sym
;
5467 asection
*input_sec
;
5469 /* If we see a common symbol, which implies a relocatable link, then
5470 if a symbol was small common in an input file, mark it as small
5471 common in the output file. */
5472 if (sym
->st_shndx
== SHN_COMMON
5473 && strcmp (input_sec
->name
, ".scommon") == 0)
5474 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
5476 if (sym
->st_other
== STO_MIPS16
5477 && (sym
->st_value
& 1) != 0)
5483 /* Functions for the dynamic linker. */
5485 /* The name of the dynamic interpreter. This is put in the .interp
5488 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
5490 /* Create dynamic sections when linking against a dynamic object. */
5493 mips_elf_create_dynamic_sections (abfd
, info
)
5495 struct bfd_link_info
*info
;
5497 struct elf_link_hash_entry
*h
;
5499 register asection
*s
;
5500 const char * const *namep
;
5502 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5503 | SEC_LINKER_CREATED
| SEC_READONLY
);
5505 /* Mips ABI requests the .dynamic section to be read only. */
5506 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5509 if (! bfd_set_section_flags (abfd
, s
, flags
))
5513 /* We need to create .got section. */
5514 if (! mips_elf_create_got_section (abfd
, info
))
5517 /* Create .stub section. */
5518 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
5520 s
= bfd_make_section (abfd
, ".stub");
5522 || ! bfd_set_section_flags (abfd
, s
, flags
)
5523 || ! bfd_set_section_alignment (abfd
, s
, 2))
5527 if (SGI_COMPAT (abfd
)
5529 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
5531 s
= bfd_make_section (abfd
, ".rld_map");
5533 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
5534 || ! bfd_set_section_alignment (abfd
, s
, 2))
5538 if (SGI_COMPAT (abfd
))
5540 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
5543 if (! (_bfd_generic_link_add_one_symbol
5544 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
5545 (bfd_vma
) 0, (const char *) NULL
, false,
5546 get_elf_backend_data (abfd
)->collect
,
5547 (struct bfd_link_hash_entry
**) &h
)))
5549 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5550 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5551 h
->type
= STT_SECTION
;
5553 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5557 /* We need to create a .compact_rel section. */
5558 if (! mips_elf_create_compact_rel_section (abfd
, info
))
5561 /* Change aligments of some sections. */
5562 s
= bfd_get_section_by_name (abfd
, ".hash");
5564 bfd_set_section_alignment (abfd
, s
, 4);
5565 s
= bfd_get_section_by_name (abfd
, ".dynsym");
5567 bfd_set_section_alignment (abfd
, s
, 4);
5568 s
= bfd_get_section_by_name (abfd
, ".dynstr");
5570 bfd_set_section_alignment (abfd
, s
, 4);
5571 s
= bfd_get_section_by_name (abfd
, ".reginfo");
5573 bfd_set_section_alignment (abfd
, s
, 4);
5574 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5576 bfd_set_section_alignment (abfd
, s
, 4);
5582 if (! (_bfd_generic_link_add_one_symbol
5583 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
5584 (bfd_vma
) 0, (const char *) NULL
, false,
5585 get_elf_backend_data (abfd
)->collect
,
5586 (struct bfd_link_hash_entry
**) &h
)))
5588 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5589 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5590 h
->type
= STT_SECTION
;
5592 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5595 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
5597 /* __rld_map is a four byte word located in the .data section
5598 and is filled in by the rtld to contain a pointer to
5599 the _r_debug structure. Its symbol value will be set in
5600 mips_elf_finish_dynamic_symbol. */
5601 s
= bfd_get_section_by_name (abfd
, ".rld_map");
5602 BFD_ASSERT (s
!= NULL
);
5605 if (! (_bfd_generic_link_add_one_symbol
5606 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
5607 (bfd_vma
) 0, (const char *) NULL
, false,
5608 get_elf_backend_data (abfd
)->collect
,
5609 (struct bfd_link_hash_entry
**) &h
)))
5611 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5612 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5613 h
->type
= STT_OBJECT
;
5615 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5623 /* Create the .compact_rel section. */
5626 mips_elf_create_compact_rel_section (abfd
, info
)
5628 struct bfd_link_info
*info
;
5631 register asection
*s
;
5633 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
5635 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
5638 s
= bfd_make_section (abfd
, ".compact_rel");
5640 || ! bfd_set_section_flags (abfd
, s
, flags
)
5641 || ! bfd_set_section_alignment (abfd
, s
, 2))
5644 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
5650 /* Create the .got section to hold the global offset table. */
5653 mips_elf_create_got_section (abfd
, info
)
5655 struct bfd_link_info
*info
;
5658 register asection
*s
;
5659 struct elf_link_hash_entry
*h
;
5660 struct mips_got_info
*g
;
5662 /* This function may be called more than once. */
5663 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
5666 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5667 | SEC_LINKER_CREATED
);
5669 s
= bfd_make_section (abfd
, ".got");
5671 || ! bfd_set_section_flags (abfd
, s
, flags
)
5672 || ! bfd_set_section_alignment (abfd
, s
, 4))
5675 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
5676 linker script because we don't want to define the symbol if we
5677 are not creating a global offset table. */
5679 if (! (_bfd_generic_link_add_one_symbol
5680 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
5681 (bfd_vma
) 0, (const char *) NULL
, false,
5682 get_elf_backend_data (abfd
)->collect
,
5683 (struct bfd_link_hash_entry
**) &h
)))
5685 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5686 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5687 h
->type
= STT_OBJECT
;
5690 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5693 /* The first several global offset table entries are reserved. */
5694 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
5696 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
5697 sizeof (struct mips_got_info
));
5700 g
->global_gotsym
= 0;
5701 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
5702 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
5703 if (elf_section_data (s
) == NULL
)
5706 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
5707 if (elf_section_data (s
) == NULL
)
5710 elf_section_data (s
)->tdata
= (PTR
) g
;
5715 /* Look through the relocs for a section during the first phase, and
5716 allocate space in the global offset table. */
5719 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
5721 struct bfd_link_info
*info
;
5723 const Elf_Internal_Rela
*relocs
;
5727 Elf_Internal_Shdr
*symtab_hdr
;
5728 struct elf_link_hash_entry
**sym_hashes
;
5729 struct mips_got_info
*g
;
5731 const Elf_Internal_Rela
*rel
;
5732 const Elf_Internal_Rela
*rel_end
;
5736 if (info
->relocateable
)
5739 dynobj
= elf_hash_table (info
)->dynobj
;
5740 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5741 sym_hashes
= elf_sym_hashes (abfd
);
5742 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
5744 /* Check for the mips16 stub sections. */
5746 name
= bfd_get_section_name (abfd
, sec
);
5747 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
5749 unsigned long r_symndx
;
5751 /* Look at the relocation information to figure out which symbol
5754 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
5756 if (r_symndx
< extsymoff
5757 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
5761 /* This stub is for a local symbol. This stub will only be
5762 needed if there is some relocation in this BFD, other
5763 than a 16 bit function call, which refers to this symbol. */
5764 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5766 Elf_Internal_Rela
*sec_relocs
;
5767 const Elf_Internal_Rela
*r
, *rend
;
5769 /* We can ignore stub sections when looking for relocs. */
5770 if ((o
->flags
& SEC_RELOC
) == 0
5771 || o
->reloc_count
== 0
5772 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
5773 sizeof FN_STUB
- 1) == 0
5774 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
5775 sizeof CALL_STUB
- 1) == 0
5776 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
5777 sizeof CALL_FP_STUB
- 1) == 0)
5780 sec_relocs
= (_bfd_elf32_link_read_relocs
5781 (abfd
, o
, (PTR
) NULL
,
5782 (Elf_Internal_Rela
*) NULL
,
5783 info
->keep_memory
));
5784 if (sec_relocs
== NULL
)
5787 rend
= sec_relocs
+ o
->reloc_count
;
5788 for (r
= sec_relocs
; r
< rend
; r
++)
5789 if (ELF32_R_SYM (r
->r_info
) == r_symndx
5790 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
5793 if (! info
->keep_memory
)
5802 /* There is no non-call reloc for this stub, so we do
5803 not need it. Since this function is called before
5804 the linker maps input sections to output sections, we
5805 can easily discard it by setting the SEC_EXCLUDE
5807 sec
->flags
|= SEC_EXCLUDE
;
5811 /* Record this stub in an array of local symbol stubs for
5813 if (elf_tdata (abfd
)->local_stubs
== NULL
)
5815 unsigned long symcount
;
5818 if (elf_bad_symtab (abfd
))
5819 symcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
5821 symcount
= symtab_hdr
->sh_info
;
5822 n
= (asection
**) bfd_zalloc (abfd
,
5823 symcount
* sizeof (asection
*));
5826 elf_tdata (abfd
)->local_stubs
= n
;
5829 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
5831 /* We don't need to set mips16_stubs_seen in this case.
5832 That flag is used to see whether we need to look through
5833 the global symbol table for stubs. We don't need to set
5834 it here, because we just have a local stub. */
5838 struct mips_elf_link_hash_entry
*h
;
5840 h
= ((struct mips_elf_link_hash_entry
*)
5841 sym_hashes
[r_symndx
- extsymoff
]);
5843 /* H is the symbol this stub is for. */
5846 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
5849 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
5850 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5852 unsigned long r_symndx
;
5853 struct mips_elf_link_hash_entry
*h
;
5856 /* Look at the relocation information to figure out which symbol
5859 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
5861 if (r_symndx
< extsymoff
5862 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
5864 /* This stub was actually built for a static symbol defined
5865 in the same file. We assume that all static symbols in
5866 mips16 code are themselves mips16, so we can simply
5867 discard this stub. Since this function is called before
5868 the linker maps input sections to output sections, we can
5869 easily discard it by setting the SEC_EXCLUDE flag. */
5870 sec
->flags
|= SEC_EXCLUDE
;
5874 h
= ((struct mips_elf_link_hash_entry
*)
5875 sym_hashes
[r_symndx
- extsymoff
]);
5877 /* H is the symbol this stub is for. */
5879 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5880 loc
= &h
->call_fp_stub
;
5882 loc
= &h
->call_stub
;
5884 /* If we already have an appropriate stub for this function, we
5885 don't need another one, so we can discard this one. Since
5886 this function is called before the linker maps input sections
5887 to output sections, we can easily discard it by setting the
5888 SEC_EXCLUDE flag. We can also discard this section if we
5889 happen to already know that this is a mips16 function; it is
5890 not necessary to check this here, as it is checked later, but
5891 it is slightly faster to check now. */
5892 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
5894 sec
->flags
|= SEC_EXCLUDE
;
5899 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
5909 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5914 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5915 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5916 BFD_ASSERT (g
!= NULL
);
5922 rel_end
= relocs
+ sec
->reloc_count
;
5923 for (rel
= relocs
; rel
< rel_end
; rel
++)
5925 unsigned long r_symndx
;
5926 struct elf_link_hash_entry
*h
;
5928 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5930 if (r_symndx
< extsymoff
)
5934 h
= sym_hashes
[r_symndx
- extsymoff
];
5936 /* This may be an indirect symbol created because of a version. */
5939 while (h
->root
.type
== bfd_link_hash_indirect
)
5940 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5944 /* Some relocs require a global offset table. */
5945 if (dynobj
== NULL
|| sgot
== NULL
)
5947 switch (ELF32_R_TYPE (rel
->r_info
))
5951 case R_MIPS_CALL_HI16
:
5952 case R_MIPS_CALL_LO16
:
5953 case R_MIPS_GOT_HI16
:
5954 case R_MIPS_GOT_LO16
:
5956 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
5957 if (! mips_elf_create_got_section (dynobj
, info
))
5959 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5960 BFD_ASSERT (sgot
!= NULL
);
5961 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5962 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5963 BFD_ASSERT (g
!= NULL
);
5969 && (info
->shared
|| h
!= NULL
)
5970 && (sec
->flags
& SEC_ALLOC
) != 0)
5971 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
5979 switch (ELF32_R_TYPE (rel
->r_info
))
5982 case R_MIPS_CALL_HI16
:
5983 case R_MIPS_CALL_LO16
:
5984 /* This symbol requires a global offset table entry. */
5988 (*_bfd_error_handler
)
5989 ("%s: CALL16 reloc at 0x%lx not against global symbol",
5990 bfd_get_filename (abfd
), (unsigned long) rel
->r_offset
);
5991 bfd_set_error (bfd_error_bad_value
);
5995 /* Make sure this symbol is output as a dynamic symbol. */
5996 if (h
->dynindx
== -1)
5998 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6002 if (h
->got_offset
!= (bfd_vma
) -1)
6004 /* We have already allocated space in the .got. */
6008 /* Note the index of the first global got symbol in .dynsym. */
6009 if (g
->global_gotsym
== 0
6010 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6011 g
->global_gotsym
= h
->dynindx
;
6013 /* Make this symbol to have the corresponding got entry. */
6016 /* We need a stub, not a plt entry for the undefined
6017 function. But we record it as if it needs plt. See
6018 elf_adjust_dynamic_symbol in elflink.h. */
6019 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6025 case R_MIPS_GOT_HI16
:
6026 case R_MIPS_GOT_LO16
:
6027 /* This symbol requires a global offset table entry. */
6031 /* Make sure this symbol is output as a dynamic symbol. */
6032 if (h
->dynindx
== -1)
6034 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6038 if (h
->got_offset
!= (bfd_vma
) -1)
6040 /* We have already allocated space in the .got. */
6043 /* Note the index of the first global got symbol in
6045 if (g
->global_gotsym
== 0
6046 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6047 g
->global_gotsym
= h
->dynindx
;
6049 /* Make this symbol to be the global got symbol. */
6057 if ((info
->shared
|| h
!= NULL
)
6058 && (sec
->flags
& SEC_ALLOC
) != 0)
6062 const char *name
= ".rel.dyn";
6064 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6067 sreloc
= bfd_make_section (dynobj
, name
);
6069 || ! bfd_set_section_flags (dynobj
, sreloc
,
6074 | SEC_LINKER_CREATED
6076 || ! bfd_set_section_alignment (dynobj
, sreloc
,
6083 /* When creating a shared object, we must copy these
6084 reloc types into the output file as R_MIPS_REL32
6085 relocs. We make room for this reloc in the
6086 .rel.dyn reloc section */
6087 if (sreloc
->_raw_size
== 0)
6089 /* Add a null element. */
6090 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6091 ++sreloc
->reloc_count
;
6093 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6097 struct mips_elf_link_hash_entry
*hmips
;
6099 /* We only need to copy this reloc if the symbol is
6100 defined in a dynamic object. */
6101 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6102 ++hmips
->mips_32_relocs
;
6106 if (SGI_COMPAT (abfd
))
6107 mips_elf_hash_table (info
)->compact_rel_size
+=
6108 sizeof (Elf32_External_crinfo
);
6113 case R_MIPS_GPREL16
:
6114 case R_MIPS_LITERAL
:
6115 case R_MIPS_GPREL32
:
6116 if (SGI_COMPAT (abfd
))
6117 mips_elf_hash_table (info
)->compact_rel_size
+=
6118 sizeof (Elf32_External_crinfo
);
6125 /* If this reloc is not a 16 bit call, and it has a global
6126 symbol, then we will need the fn_stub if there is one.
6127 References from a stub section do not count. */
6129 && ELF32_R_TYPE (rel
->r_info
) != R_MIPS16_26
6130 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
6131 sizeof FN_STUB
- 1) != 0
6132 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
6133 sizeof CALL_STUB
- 1) != 0
6134 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
6135 sizeof CALL_FP_STUB
- 1) != 0)
6137 struct mips_elf_link_hash_entry
*mh
;
6139 mh
= (struct mips_elf_link_hash_entry
*) h
;
6140 mh
->need_fn_stub
= true;
6147 /* Adjust a symbol defined by a dynamic object and referenced by a
6148 regular object. The current definition is in some section of the
6149 dynamic object, but we're not including those sections. We have to
6150 change the definition to something the rest of the link can
6154 mips_elf_adjust_dynamic_symbol (info
, h
)
6155 struct bfd_link_info
*info
;
6156 struct elf_link_hash_entry
*h
;
6159 struct mips_elf_link_hash_entry
*hmips
;
6162 dynobj
= elf_hash_table (info
)->dynobj
;
6164 /* Make sure we know what is going on here. */
6165 BFD_ASSERT (dynobj
!= NULL
6166 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
6167 || h
->weakdef
!= NULL
6168 || ((h
->elf_link_hash_flags
6169 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
6170 && (h
->elf_link_hash_flags
6171 & ELF_LINK_HASH_REF_REGULAR
) != 0
6172 && (h
->elf_link_hash_flags
6173 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
6175 /* If this symbol is defined in a dynamic object, we need to copy
6176 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
6178 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6179 if (! info
->relocateable
6180 && hmips
->mips_32_relocs
!= 0
6181 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6183 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6184 BFD_ASSERT (s
!= NULL
);
6186 if (s
->_raw_size
== 0)
6188 /* Make room for a null element. */
6189 s
->_raw_size
+= sizeof (Elf32_External_Rel
);
6192 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
6195 /* For a function, create a stub, if needed. */
6196 if (h
->type
== STT_FUNC
6197 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
6199 if (! elf_hash_table (info
)->dynamic_sections_created
)
6202 /* If this symbol is not defined in a regular file, then set
6203 the symbol to the stub location. This is required to make
6204 function pointers compare as equal between the normal
6205 executable and the shared library. */
6206 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6208 /* We need .stub section. */
6209 s
= bfd_get_section_by_name (dynobj
, ".stub");
6210 BFD_ASSERT (s
!= NULL
);
6212 h
->root
.u
.def
.section
= s
;
6213 h
->root
.u
.def
.value
= s
->_raw_size
;
6215 /* XXX Write this stub address somewhere. */
6216 h
->plt_offset
= s
->_raw_size
;
6218 /* Make room for this stub code. */
6219 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6221 /* The last half word of the stub will be filled with the index
6222 of this symbol in .dynsym section. */
6227 /* If this is a weak symbol, and there is a real definition, the
6228 processor independent code will have arranged for us to see the
6229 real definition first, and we can just use the same value. */
6230 if (h
->weakdef
!= NULL
)
6232 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
6233 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
6234 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
6235 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
6239 /* This is a reference to a symbol defined by a dynamic object which
6240 is not a function. */
6245 /* This function is called after all the input files have been read,
6246 and the input sections have been assigned to output sections. We
6247 check for any mips16 stub sections that we can discard. */
6249 static boolean mips_elf_check_mips16_stubs
6250 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
6253 mips_elf_always_size_sections (output_bfd
, info
)
6255 struct bfd_link_info
*info
;
6257 if (info
->relocateable
6258 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
6261 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
6262 mips_elf_check_mips16_stubs
,
6268 /* Check the mips16 stubs for a particular symbol, and see if we can
6273 mips_elf_check_mips16_stubs (h
, data
)
6274 struct mips_elf_link_hash_entry
*h
;
6277 if (h
->fn_stub
!= NULL
6278 && ! h
->need_fn_stub
)
6280 /* We don't need the fn_stub; the only references to this symbol
6281 are 16 bit calls. Clobber the size to 0 to prevent it from
6282 being included in the link. */
6283 h
->fn_stub
->_raw_size
= 0;
6284 h
->fn_stub
->_cooked_size
= 0;
6285 h
->fn_stub
->flags
&= ~ SEC_RELOC
;
6286 h
->fn_stub
->reloc_count
= 0;
6287 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
6290 if (h
->call_stub
!= NULL
6291 && h
->root
.other
== STO_MIPS16
)
6293 /* We don't need the call_stub; this is a 16 bit function, so
6294 calls from other 16 bit functions are OK. Clobber the size
6295 to 0 to prevent it from being included in the link. */
6296 h
->call_stub
->_raw_size
= 0;
6297 h
->call_stub
->_cooked_size
= 0;
6298 h
->call_stub
->flags
&= ~ SEC_RELOC
;
6299 h
->call_stub
->reloc_count
= 0;
6300 h
->call_stub
->flags
|= SEC_EXCLUDE
;
6303 if (h
->call_fp_stub
!= NULL
6304 && h
->root
.other
== STO_MIPS16
)
6306 /* We don't need the call_stub; this is a 16 bit function, so
6307 calls from other 16 bit functions are OK. Clobber the size
6308 to 0 to prevent it from being included in the link. */
6309 h
->call_fp_stub
->_raw_size
= 0;
6310 h
->call_fp_stub
->_cooked_size
= 0;
6311 h
->call_fp_stub
->flags
&= ~ SEC_RELOC
;
6312 h
->call_fp_stub
->reloc_count
= 0;
6313 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
6319 /* Set the sizes of the dynamic sections. */
6322 mips_elf_size_dynamic_sections (output_bfd
, info
)
6324 struct bfd_link_info
*info
;
6330 struct mips_got_info
*g
;
6332 dynobj
= elf_hash_table (info
)->dynobj
;
6333 BFD_ASSERT (dynobj
!= NULL
);
6335 if (elf_hash_table (info
)->dynamic_sections_created
)
6337 /* Set the contents of the .interp section to the interpreter. */
6340 s
= bfd_get_section_by_name (dynobj
, ".interp");
6341 BFD_ASSERT (s
!= NULL
);
6342 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
6343 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
6347 /* Recompute the size of .got for local entires (reserved and
6348 hipages) if needed. To estimate it, get the upper bound of total
6349 size of loadable sections. */
6350 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6354 bfd_size_type loadable_size
= 0;
6355 bfd_size_type local_gotno
;
6358 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6359 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6360 BFD_ASSERT (g
!= NULL
);
6362 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
6363 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
6365 if ((s
->flags
& SEC_ALLOC
) == 0)
6367 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
6370 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
6372 /* Assume there are two loadable segments consisting of
6373 contiguous sections. Is 5 enough? */
6374 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
6375 g
->local_gotno
= local_gotno
;
6376 sgot
->_raw_size
+= local_gotno
* 4;
6379 /* The check_relocs and adjust_dynamic_symbol entry points have
6380 determined the sizes of the various dynamic sections. Allocate
6383 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
6388 /* It's OK to base decisions on the section name, because none
6389 of the dynobj section names depend upon the input files. */
6390 name
= bfd_get_section_name (dynobj
, s
);
6392 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
6397 if (strncmp (name
, ".rel", 4) == 0)
6399 if (s
->_raw_size
== 0)
6403 const char *outname
;
6406 /* If this relocation section applies to a read only
6407 section, then we probably need a DT_TEXTREL entry.
6408 If the relocation section is .rel.dyn, we always
6409 assert a DT_TEXTREL entry rather than testing whether
6410 there exists a relocation to a read only section or
6412 outname
= bfd_get_section_name (output_bfd
,
6414 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
6416 && (target
->flags
& SEC_READONLY
) != 0
6417 && (target
->flags
& SEC_ALLOC
) != 0)
6418 || strcmp (outname
, ".rel.dyn") == 0)
6421 /* We use the reloc_count field as a counter if we need
6422 to copy relocs into the output file. */
6423 if (strcmp (name
, ".rel.dyn") != 0)
6427 else if (strncmp (name
, ".got", 4) == 0)
6431 BFD_ASSERT (elf_section_data (s
) != NULL
);
6432 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
6433 BFD_ASSERT (g
!= NULL
);
6435 /* Fix the size of .got section for the correspondence of
6436 global symbols and got entries. This adds some useless
6437 got entries. Is this required by ABI really? */
6438 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
6439 s
->_raw_size
+= i
* 4;
6441 else if (strncmp (name
, ".stub", 5) == 0)
6443 /* Irix rld assumes that the function stub isn't at the end
6444 of .text section. So put a dummy. XXX */
6445 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6447 else if (! info
->shared
6448 && ! mips_elf_hash_table (info
)->use_rld_obj_head
6449 && strncmp (name
, ".rld_map", 8) == 0)
6451 /* We add a room for __rld_map. It will be filled in by the
6452 rtld to contain a pointer to the _r_debug structure. */
6455 else if (SGI_COMPAT (output_bfd
)
6456 && strncmp (name
, ".compact_rel", 12) == 0)
6457 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
6458 else if (strncmp (name
, ".init", 5) != 0)
6460 /* It's not one of our sections, so don't allocate space. */
6468 for (spp
= &s
->output_section
->owner
->sections
;
6469 *spp
!= s
->output_section
;
6470 spp
= &(*spp
)->next
)
6472 *spp
= s
->output_section
->next
;
6473 --s
->output_section
->owner
->section_count
;
6478 /* Allocate memory for the section contents. */
6479 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
6480 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
6482 bfd_set_error (bfd_error_no_memory
);
6485 memset (s
->contents
, 0, s
->_raw_size
);
6488 if (elf_hash_table (info
)->dynamic_sections_created
)
6490 /* Add some entries to the .dynamic section. We fill in the
6491 values later, in elf_mips_finish_dynamic_sections, but we
6492 must add the entries now so that we get the correct size for
6493 the .dynamic section. The DT_DEBUG entry is filled in by the
6494 dynamic linker and used by the debugger. */
6497 if (SGI_COMPAT (output_bfd
))
6499 /* SGI object has the equivalence of DT_DEBUG in the
6500 DT_MIPS_RLD_MAP entry. */
6501 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
6505 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
6511 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
6515 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
6518 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
6520 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
6523 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
6526 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
6530 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
6533 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
6536 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
6538 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
6541 s
= bfd_get_section_by_name (dynobj
, ".liblist");
6542 BFD_ASSERT (s
!= NULL
);
6544 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
6548 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
6551 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
6555 /* Time stamps in executable files are a bad idea. */
6556 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
6561 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
6566 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
6570 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
6573 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
6576 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
6579 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
6582 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
6585 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
6588 #if 0 /* (SGI_COMPAT) */
6589 if (! bfd_get_section_by_name (dynobj
, ".init"))
6590 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
6593 if (! bfd_get_section_by_name (dynobj
, ".fini"))
6594 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
6599 /* If we use dynamic linking, we generate a section symbol for each
6600 output section. These are local symbols, which means that they
6601 must come first in the dynamic symbol table.
6602 That means we must increment the dynamic symbol index of every
6603 other dynamic symbol. */
6605 const char * const *namep
;
6607 bfd_size_type strindex
;
6608 struct bfd_strtab_hash
*dynstr
;
6609 struct mips_got_info
*g
;
6612 if (elf_hash_table (info
)->dynamic_sections_created
)
6614 if (SGI_COMPAT (output_bfd
))
6616 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
6617 elf_link_hash_traverse (elf_hash_table (info
),
6618 mips_elf_adjust_dynindx
,
6620 elf_hash_table (info
)->dynsymcount
+= c
;
6622 dynstr
= elf_hash_table (info
)->dynstr
;
6623 BFD_ASSERT (dynstr
!= NULL
);
6625 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
6629 s
= bfd_get_section_by_name (output_bfd
, *namep
);
6631 elf_section_data (s
)->dynindx
= i
;
6633 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
6634 if (strindex
== (bfd_size_type
) -1)
6637 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
6642 c
= bfd_count_sections (output_bfd
);
6643 elf_link_hash_traverse (elf_hash_table (info
),
6644 mips_elf_adjust_dynindx
,
6646 elf_hash_table (info
)->dynsymcount
+= c
;
6648 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
6650 elf_section_data (s
)->dynindx
= i
;
6651 /* These symbols will have no names, so we don't need to
6652 fiddle with dynstr_index. */
6659 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6660 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6661 BFD_ASSERT (g
!= NULL
);
6663 /* If there are no global got symbols, fake the last symbol so
6665 if (g
->global_gotsym
)
6666 g
->global_gotsym
+= c
;
6668 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
6675 /* Increment the index of a dynamic symbol by a given amount. Called
6676 via elf_link_hash_traverse. */
6679 mips_elf_adjust_dynindx (h
, cparg
)
6680 struct elf_link_hash_entry
*h
;
6683 unsigned int *cp
= (unsigned int *) cparg
;
6685 if (h
->dynindx
!= -1)
6690 /* Finish up dynamic symbol handling. We set the contents of various
6691 dynamic sections here. */
6694 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
6696 struct bfd_link_info
*info
;
6697 struct elf_link_hash_entry
*h
;
6698 Elf_Internal_Sym
*sym
;
6703 struct mips_got_info
*g
;
6706 dynobj
= elf_hash_table (info
)->dynobj
;
6707 gval
= sym
->st_value
;
6709 if (h
->plt_offset
!= (bfd_vma
) -1)
6713 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
6715 /* This symbol has a stub. Set it up. */
6717 BFD_ASSERT (h
->dynindx
!= -1);
6719 s
= bfd_get_section_by_name (dynobj
, ".stub");
6720 BFD_ASSERT (s
!= NULL
);
6722 /* Fill the stub. */
6724 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
6726 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
6729 /* FIXME: Can h->dynindex be more than 64K? */
6730 if (h
->dynindx
& 0xffff0000)
6733 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
6735 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
6737 BFD_ASSERT (h
->plt_offset
<= s
->_raw_size
);
6738 memcpy (s
->contents
+ h
->plt_offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
6740 /* Mark the symbol as undefined. plt_offset != -1 occurs
6741 only for the referenced symbol. */
6742 sym
->st_shndx
= SHN_UNDEF
;
6744 /* The run-time linker uses the st_value field of the symbol
6745 to reset the global offset table entry for this external
6746 to its stub address when unlinking a shared object. */
6747 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt_offset
;
6748 sym
->st_value
= gval
;
6751 BFD_ASSERT (h
->dynindx
!= -1);
6753 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6754 BFD_ASSERT (sgot
!= NULL
);
6755 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6756 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6757 BFD_ASSERT (g
!= NULL
);
6759 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
6761 bfd_size_type offset
;
6763 /* This symbol has an entry in the global offset table. Set its
6764 value to the corresponding got entry, if needed. */
6765 if (h
->got_offset
== (bfd_vma
) -1)
6767 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
6768 BFD_ASSERT (g
->local_gotno
* 4 <= offset
6769 && offset
< sgot
->_raw_size
);
6770 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
6774 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
6775 name
= h
->root
.root
.string
;
6776 if (strcmp (name
, "_DYNAMIC") == 0
6777 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
6778 sym
->st_shndx
= SHN_ABS
;
6779 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
6781 sym
->st_shndx
= SHN_ABS
;
6782 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6785 else if (SGI_COMPAT (output_bfd
))
6787 if (strcmp (name
, "_gp_disp") == 0)
6789 sym
->st_shndx
= SHN_ABS
;
6790 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6791 sym
->st_value
= elf_gp (output_bfd
);
6793 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
6794 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
6796 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6797 sym
->st_other
= STO_PROTECTED
;
6799 sym
->st_shndx
= SHN_MIPS_DATA
;
6801 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
6803 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6804 sym
->st_other
= STO_PROTECTED
;
6805 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
6806 sym
->st_shndx
= SHN_ABS
;
6808 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
6810 if (h
->type
== STT_FUNC
)
6811 sym
->st_shndx
= SHN_MIPS_TEXT
;
6812 else if (h
->type
== STT_OBJECT
)
6813 sym
->st_shndx
= SHN_MIPS_DATA
;
6817 if (SGI_COMPAT (output_bfd
)
6820 if (! mips_elf_hash_table (info
)->use_rld_obj_head
6821 && strcmp (name
, "__rld_map") == 0)
6823 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
6824 BFD_ASSERT (s
!= NULL
);
6825 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
6826 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
6827 if (mips_elf_hash_table (info
)->rld_value
== 0)
6828 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
6830 else if (mips_elf_hash_table (info
)->use_rld_obj_head
6831 && strcmp (name
, "__rld_obj_head") == 0)
6833 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
6834 BFD_ASSERT (s
!= NULL
);
6835 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
6839 /* If this is a mips16 symbol, force the value to be even. */
6840 if (sym
->st_other
== STO_MIPS16
6841 && (sym
->st_value
& 1) != 0)
6847 /* Finish up the dynamic sections. */
6850 mips_elf_finish_dynamic_sections (output_bfd
, info
)
6852 struct bfd_link_info
*info
;
6857 struct mips_got_info
*g
;
6859 dynobj
= elf_hash_table (info
)->dynobj
;
6861 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
6863 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6868 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6869 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6870 BFD_ASSERT (g
!= NULL
);
6873 if (elf_hash_table (info
)->dynamic_sections_created
)
6875 Elf32_External_Dyn
*dyncon
, *dynconend
;
6877 BFD_ASSERT (sdyn
!= NULL
);
6878 BFD_ASSERT (g
!= NULL
);
6880 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
6881 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
6882 for (; dyncon
< dynconend
; dyncon
++)
6884 Elf_Internal_Dyn dyn
;
6889 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
6897 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6898 BFD_ASSERT (s
!= NULL
);
6899 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
6900 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6904 /* Rewrite DT_STRSZ. */
6906 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
6907 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6913 case DT_MIPS_CONFLICT
:
6916 case DT_MIPS_LIBLIST
:
6919 s
= bfd_get_section_by_name (output_bfd
, name
);
6920 BFD_ASSERT (s
!= NULL
);
6921 dyn
.d_un
.d_ptr
= s
->vma
;
6922 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6925 case DT_MIPS_RLD_VERSION
:
6926 dyn
.d_un
.d_val
= 1; /* XXX */
6927 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6931 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
6932 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6935 case DT_MIPS_CONFLICTNO
:
6937 elemsize
= sizeof (Elf32_Conflict
);
6940 case DT_MIPS_LIBLISTNO
:
6942 elemsize
= sizeof (Elf32_Lib
);
6944 s
= bfd_get_section_by_name (output_bfd
, name
);
6947 if (s
->_cooked_size
!= 0)
6948 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
6950 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
6955 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6958 case DT_MIPS_TIME_STAMP
:
6959 time ((time_t *) &dyn
.d_un
.d_val
);
6960 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6963 case DT_MIPS_ICHECKSUM
:
6967 case DT_MIPS_IVERSION
:
6971 case DT_MIPS_BASE_ADDRESS
:
6972 s
= output_bfd
->sections
;
6973 BFD_ASSERT (s
!= NULL
);
6974 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
6975 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6978 case DT_MIPS_LOCAL_GOTNO
:
6979 dyn
.d_un
.d_val
= g
->local_gotno
;
6980 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6983 case DT_MIPS_SYMTABNO
:
6985 elemsize
= sizeof (Elf32_External_Sym
);
6986 s
= bfd_get_section_by_name (output_bfd
, name
);
6987 BFD_ASSERT (s
!= NULL
);
6989 if (s
->_cooked_size
!= 0)
6990 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
6992 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
6993 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6996 case DT_MIPS_UNREFEXTNO
:
6998 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
6999 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7002 case DT_MIPS_GOTSYM
:
7003 dyn
.d_un
.d_val
= g
->global_gotsym
;
7004 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7007 case DT_MIPS_HIPAGENO
:
7008 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
7009 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7012 case DT_MIPS_RLD_MAP
:
7013 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
7014 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7021 /* The first entry of the global offset table will be filled at
7022 runtime. The second entry will be used by some runtime loaders.
7023 This isn't the case of Irix rld. */
7024 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
7026 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
7027 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
7031 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
7038 Elf_Internal_Sym sym
;
7041 const char * const * namep
= mips_elf_dynsym_sec_names
;
7042 Elf32_compact_rel cpt
;
7044 /* Set up the section symbols for the output sections. SGI sets
7045 the STT_NOTYPE attribute for these symbols. Should we do so? */
7047 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
7048 if (sdynsym
!= NULL
)
7050 if (SGI_COMPAT (output_bfd
))
7054 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7058 while ((name
= *namep
++) != NULL
)
7060 s
= bfd_get_section_by_name (output_bfd
, name
);
7063 sym
.st_value
= s
->vma
;
7064 dindx
= elf_section_data (s
)->dynindx
;
7065 last
= s
->vma
+ s
->_raw_size
;
7069 sym
.st_value
= last
;
7073 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
7078 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
7080 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7081 (((Elf32_External_Sym
*)
7086 /* Set the sh_info field of the output .dynsym section to
7087 the index of the first global symbol. */
7088 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7089 SIZEOF_MIPS_DYNSYM_SECNAMES
;
7095 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
7098 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
7102 sym
.st_value
= s
->vma
;
7104 indx
= elf_section_data (s
)->this_idx
;
7105 BFD_ASSERT (indx
> 0);
7106 sym
.st_shndx
= indx
;
7108 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7109 (((Elf32_External_Sym
*)
7111 + elf_section_data (s
)->dynindx
));
7114 /* Set the sh_info field of the output .dynsym section to
7115 the index of the first global symbol. */
7116 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7117 bfd_count_sections (output_bfd
) + 1;
7121 if (SGI_COMPAT (output_bfd
))
7123 /* Write .compact_rel section out. */
7124 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
7128 cpt
.num
= s
->reloc_count
;
7130 cpt
.offset
= (s
->output_section
->filepos
7131 + sizeof (Elf32_External_compact_rel
));
7134 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
7135 ((Elf32_External_compact_rel
*)
7138 /* Clean up a dummy stub function entry in .text. */
7139 s
= bfd_get_section_by_name (dynobj
, ".stub");
7142 file_ptr dummy_offset
;
7144 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
7145 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
7146 memset (s
->contents
+ dummy_offset
, 0,
7147 MIPS_FUNCTION_STUB_SIZE
);
7152 /* Clean up a first relocation in .rel.dyn. */
7153 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7154 if (s
!= NULL
&& s
->_raw_size
> 0)
7155 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
7161 /* This is almost identical to bfd_generic_get_... except that some
7162 MIPS relocations need to be handled specially. Sigh. */
7165 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
7166 relocateable
, symbols
)
7168 struct bfd_link_info
*link_info
;
7169 struct bfd_link_order
*link_order
;
7171 boolean relocateable
;
7174 /* Get enough memory to hold the stuff */
7175 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
7176 asection
*input_section
= link_order
->u
.indirect
.section
;
7178 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
7179 arelent
**reloc_vector
= NULL
;
7185 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
7186 if (reloc_vector
== NULL
&& reloc_size
!= 0)
7189 /* read in the section */
7190 if (!bfd_get_section_contents (input_bfd
,
7194 input_section
->_raw_size
))
7197 /* We're not relaxing the section, so just copy the size info */
7198 input_section
->_cooked_size
= input_section
->_raw_size
;
7199 input_section
->reloc_done
= true;
7201 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
7205 if (reloc_count
< 0)
7208 if (reloc_count
> 0)
7213 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
7216 struct bfd_hash_entry
*h
;
7217 struct bfd_link_hash_entry
*lh
;
7218 /* Skip all this stuff if we aren't mixing formats. */
7219 if (abfd
&& input_bfd
7220 && abfd
->xvec
== input_bfd
->xvec
)
7224 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
7225 lh
= (struct bfd_link_hash_entry
*) h
;
7232 case bfd_link_hash_undefined
:
7233 case bfd_link_hash_undefweak
:
7234 case bfd_link_hash_common
:
7237 case bfd_link_hash_defined
:
7238 case bfd_link_hash_defweak
:
7240 gp
= lh
->u
.def
.value
;
7242 case bfd_link_hash_indirect
:
7243 case bfd_link_hash_warning
:
7245 /* @@FIXME ignoring warning for now */
7247 case bfd_link_hash_new
:
7256 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
7259 char *error_message
= (char *) NULL
;
7260 bfd_reloc_status_type r
;
7262 /* Specific to MIPS: Deal with relocation types that require
7263 knowing the gp of the output bfd. */
7264 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
7265 if (bfd_is_abs_section (sym
->section
) && abfd
)
7267 /* The special_function wouldn't get called anyways. */
7271 /* The gp isn't there; let the special function code
7272 fall over on its own. */
7274 else if ((*parent
)->howto
->special_function
7275 == _bfd_mips_elf_gprel16_reloc
)
7277 /* bypass special_function call */
7278 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
7279 relocateable
, (PTR
) data
, gp
);
7280 goto skip_bfd_perform_relocation
;
7282 /* end mips specific stuff */
7284 r
= bfd_perform_relocation (input_bfd
,
7288 relocateable
? abfd
: (bfd
*) NULL
,
7290 skip_bfd_perform_relocation
:
7294 asection
*os
= input_section
->output_section
;
7296 /* A partial link, so keep the relocs */
7297 os
->orelocation
[os
->reloc_count
] = *parent
;
7301 if (r
!= bfd_reloc_ok
)
7305 case bfd_reloc_undefined
:
7306 if (!((*link_info
->callbacks
->undefined_symbol
)
7307 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7308 input_bfd
, input_section
, (*parent
)->address
)))
7311 case bfd_reloc_dangerous
:
7312 BFD_ASSERT (error_message
!= (char *) NULL
);
7313 if (!((*link_info
->callbacks
->reloc_dangerous
)
7314 (link_info
, error_message
, input_bfd
, input_section
,
7315 (*parent
)->address
)))
7318 case bfd_reloc_overflow
:
7319 if (!((*link_info
->callbacks
->reloc_overflow
)
7320 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7321 (*parent
)->howto
->name
, (*parent
)->addend
,
7322 input_bfd
, input_section
, (*parent
)->address
)))
7325 case bfd_reloc_outofrange
:
7334 if (reloc_vector
!= NULL
)
7335 free (reloc_vector
);
7339 if (reloc_vector
!= NULL
)
7340 free (reloc_vector
);
7343 #define bfd_elf32_bfd_get_relocated_section_contents \
7344 elf32_mips_get_relocated_section_contents
7346 /* ECOFF swapping routines. These are used when dealing with the
7347 .mdebug section, which is in the ECOFF debugging format. */
7348 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
7350 /* Symbol table magic number. */
7352 /* Alignment of debugging information. E.g., 4. */
7354 /* Sizes of external symbolic information. */
7355 sizeof (struct hdr_ext
),
7356 sizeof (struct dnr_ext
),
7357 sizeof (struct pdr_ext
),
7358 sizeof (struct sym_ext
),
7359 sizeof (struct opt_ext
),
7360 sizeof (struct fdr_ext
),
7361 sizeof (struct rfd_ext
),
7362 sizeof (struct ext_ext
),
7363 /* Functions to swap in external symbolic data. */
7372 _bfd_ecoff_swap_tir_in
,
7373 _bfd_ecoff_swap_rndx_in
,
7374 /* Functions to swap out external symbolic data. */
7383 _bfd_ecoff_swap_tir_out
,
7384 _bfd_ecoff_swap_rndx_out
,
7385 /* Function to read in symbolic data. */
7386 _bfd_mips_elf_read_ecoff_info
7389 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
7390 #define TARGET_LITTLE_NAME "elf32-littlemips"
7391 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
7392 #define TARGET_BIG_NAME "elf32-bigmips"
7393 #define ELF_ARCH bfd_arch_mips
7394 #define ELF_MACHINE_CODE EM_MIPS
7396 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
7397 a value of 0x1000, and we are compatible. */
7398 #define ELF_MAXPAGESIZE 0x1000
7400 #define elf_backend_collect true
7401 #define elf_backend_type_change_ok true
7402 #define elf_info_to_howto 0
7403 #define elf_info_to_howto_rel mips_info_to_howto_rel
7404 #define elf_backend_sym_is_global mips_elf_sym_is_global
7405 #define elf_backend_object_p mips_elf32_object_p
7406 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
7407 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
7408 #define elf_backend_section_from_bfd_section \
7409 _bfd_mips_elf_section_from_bfd_section
7410 #define elf_backend_section_processing mips_elf32_section_processing
7411 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
7412 #define elf_backend_additional_program_headers \
7413 mips_elf_additional_program_headers
7414 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
7415 #define elf_backend_final_write_processing \
7416 _bfd_mips_elf_final_write_processing
7417 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
7419 #define bfd_elf32_bfd_is_local_label_name \
7420 mips_elf_is_local_label_name
7421 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
7422 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
7423 #define bfd_elf32_bfd_link_hash_table_create \
7424 mips_elf_link_hash_table_create
7425 #define bfd_elf32_bfd_final_link mips_elf_final_link
7426 #define bfd_elf32_bfd_copy_private_bfd_data \
7427 _bfd_mips_elf_copy_private_bfd_data
7428 #define bfd_elf32_bfd_merge_private_bfd_data \
7429 _bfd_mips_elf_merge_private_bfd_data
7430 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
7431 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
7432 #define elf_backend_create_dynamic_sections \
7433 mips_elf_create_dynamic_sections
7434 #define elf_backend_check_relocs mips_elf_check_relocs
7435 #define elf_backend_adjust_dynamic_symbol \
7436 mips_elf_adjust_dynamic_symbol
7437 #define elf_backend_always_size_sections \
7438 mips_elf_always_size_sections
7439 #define elf_backend_size_dynamic_sections \
7440 mips_elf_size_dynamic_sections
7441 #define elf_backend_relocate_section mips_elf_relocate_section
7442 #define elf_backend_link_output_symbol_hook \
7443 mips_elf_link_output_symbol_hook
7444 #define elf_backend_finish_dynamic_symbol \
7445 mips_elf_finish_dynamic_symbol
7446 #define elf_backend_finish_dynamic_sections \
7447 mips_elf_finish_dynamic_sections
7449 #include "elf32-target.h"