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 false); /* 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 && r_type
!= R_MIPS16_26
4633 && r_type
!= R_MIPS16_GPREL
)
4635 bfd_set_error (bfd_error_bad_value
);
4638 if (r_type
== R_MIPS16_26
)
4639 howto
= &elf_mips16_jump_howto
;
4640 else if (r_type
== R_MIPS16_GPREL
)
4641 howto
= &elf_mips16_gprel_howto
;
4643 howto
= elf_mips_howto_table
+ r_type
;
4646 && (r_type
== R_MIPS_CALL16
4647 || r_type
== R_MIPS_GOT16
4648 || r_type
== R_MIPS_CALL_HI16
4649 || r_type
== R_MIPS_CALL_LO16
4650 || r_type
== R_MIPS_GOT_HI16
4651 || r_type
== R_MIPS_GOT_LO16
))
4653 /* We need the .got section. */
4656 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4657 BFD_ASSERT (sgot
!= NULL
);
4658 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4659 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4660 BFD_ASSERT (g
!= NULL
);
4664 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4666 /* Mix in the change in GP address for a GP relative reloc. */
4667 if (r_type
!= R_MIPS_GPREL16
4668 && r_type
!= R_MIPS_LITERAL
4669 && r_type
!= R_MIPS_GPREL32
4670 && r_type
!= R_MIPS16_GPREL
)
4676 if (! ((*info
->callbacks
->reloc_dangerous
)
4678 "GP relative relocation when GP not defined",
4679 input_bfd
, input_section
,
4682 /* Only give the error once per link. */
4684 _bfd_set_gp_value (output_bfd
, gp
);
4687 if (r_symndx
< extsymoff
4688 || (elf_bad_symtab (input_bfd
)
4689 && local_sections
[r_symndx
] != NULL
))
4691 /* This is a relocation against a section. The current
4692 addend in the instruction is the difference between
4693 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
4694 must change this to be the difference between the
4695 final definition (which will end up in RELOCATION)
4696 and the GP value of OUTPUT_BFD (which is in GP). */
4697 addend
= elf_gp (input_bfd
) - gp
;
4699 else if (! info
->relocateable
)
4701 /* We are doing a final link. The current addend in the
4702 instruction is simply the desired offset into the
4703 symbol (normally zero). We want the instruction to
4704 hold the difference between the final definition of
4705 the symbol (which will end up in RELOCATION) and the
4706 GP value of OUTPUT_BFD (which is in GP). */
4711 /* We are generating relocateable output, and we aren't
4712 going to define this symbol, so we just leave the
4713 instruction alone. */
4721 if (info
->relocateable
)
4723 /* This is a relocateable link. We don't have to change
4724 anything, unless the reloc is against a section symbol,
4725 in which case we have to adjust according to where the
4726 section symbol winds up in the output section. */
4727 if (r_symndx
>= locsymcount
4728 || (elf_bad_symtab (input_bfd
)
4729 && local_sections
[r_symndx
] == NULL
))
4733 sym
= local_syms
+ r_symndx
;
4734 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4738 sec
= local_sections
[r_symndx
];
4740 /* It would be logical to add sym->st_value here,
4741 but Irix 5 sometimes generates a garbage symbol
4743 addend
+= sec
->output_offset
;
4745 /* If this is HI16 or GOT16 with an associated LO16,
4746 adjust the addend accordingly. Otherwise, just
4748 if (r_type
== R_MIPS_64
&& bfd_big_endian (input_bfd
))
4749 r
= _bfd_relocate_contents (howto
, input_bfd
,
4751 contents
+ rel
->r_offset
+ 4);
4752 else if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
4753 r
= _bfd_relocate_contents (howto
, input_bfd
,
4755 contents
+ rel
->r_offset
);
4758 Elf_Internal_Rela
*lorel
;
4760 /* As a GNU extension, permit an arbitrary
4761 number of R_MIPS_HI16 relocs before the
4762 R_MIPS_LO16 reloc. This permits gcc to emit
4763 the HI and LO relocs itself. */
4764 if (r_type
== R_MIPS_GOT16
)
4768 for (lorel
= rel
+ 1;
4770 && (ELF32_R_TYPE (lorel
->r_info
)
4776 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
4778 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
4783 r
= _bfd_relocate_contents (howto
, input_bfd
,
4785 contents
+ rel
->r_offset
);
4795 /* This is a final link. */
4797 if (r_symndx
< extsymoff
4798 || (elf_bad_symtab (input_bfd
)
4799 && local_sections
[r_symndx
] != NULL
))
4802 sym
= local_syms
+ r_symndx
;
4803 sec
= local_sections
[r_symndx
];
4804 relocation
= (sec
->output_section
->vma
4805 + sec
->output_offset
);
4807 /* It would be logical to always add sym->st_value here,
4808 but Irix 5 sometimes generates a garbage symbol
4810 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4811 relocation
+= sym
->st_value
;
4813 /* mips16 text labels should be treated as odd. */
4814 if (sym
->st_other
== STO_MIPS16
)
4822 indx
= r_symndx
- extsymoff
;
4823 h
= elf_sym_hashes (input_bfd
)[indx
];
4824 while (h
->root
.type
== bfd_link_hash_indirect
4825 || h
->root
.type
== bfd_link_hash_warning
)
4826 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4827 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
4831 if (! ((*info
->callbacks
->reloc_dangerous
)
4833 "_gp_disp used when GP not defined",
4834 input_bfd
, input_section
,
4837 /* Only give the error once per link. */
4839 _bfd_set_gp_value (output_bfd
, gp
);
4844 sec
= input_section
;
4845 if (sec
->output_section
!= NULL
)
4848 + sec
->output_section
->vma
4849 + sec
->output_offset
));
4851 relocation
= gp
- rel
->r_offset
;
4852 if (r_type
== R_MIPS_LO16
)
4856 else if (h
->root
.type
== bfd_link_hash_defined
4857 || h
->root
.type
== bfd_link_hash_defweak
)
4859 sec
= h
->root
.u
.def
.section
;
4860 if (sec
->output_section
== NULL
)
4863 relocation
= (h
->root
.u
.def
.value
4864 + sec
->output_section
->vma
4865 + sec
->output_offset
);
4867 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4869 else if (info
->shared
&& ! info
->symbolic
)
4871 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
4873 /* If this is a dynamic link, we should have created
4874 a _DYNAMIC_LINK symbol in
4875 mips_elf_create_dynamic_sections. Otherwise, we
4876 should define the symbol with a value of 0.
4877 FIXME: It should probably get into the symbol
4878 table somehow as well. */
4879 BFD_ASSERT (! info
->shared
);
4880 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
4881 ".dynamic") == NULL
);
4886 if (! ((*info
->callbacks
->undefined_symbol
)
4887 (info
, h
->root
.root
.string
, input_bfd
,
4888 input_section
, rel
->r_offset
)))
4894 mh
= (struct mips_elf_link_hash_entry
*) h
;
4897 else if (sym
!= NULL
)
4898 other
= sym
->st_other
;
4902 /* If this function has an fn_stub, then it is a mips16
4903 function which needs a stub if it is called by a 32 bit
4904 function. If this reloc is anything other than a 16 bit
4905 call, redirect the reloc to the stub. We don't redirect
4906 relocs from other stub functions. */
4907 if (r_type
!= R_MIPS16_26
4909 && mh
->fn_stub
!= NULL
)
4911 && elf_tdata (input_bfd
)->local_stubs
!= NULL
4912 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
4913 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
4914 FN_STUB
, sizeof FN_STUB
- 1) != 0
4915 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
4916 CALL_STUB
, sizeof CALL_STUB
- 1) != 0
4917 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
4918 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) != 0)
4922 BFD_ASSERT (mh
->need_fn_stub
);
4923 relocation
= (mh
->fn_stub
->output_section
->vma
4924 + mh
->fn_stub
->output_offset
);
4930 fn_stub
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
4931 relocation
= (fn_stub
->output_section
->vma
4932 + fn_stub
->output_offset
);
4935 /* RELOCATION now points to 32 bit code. */
4939 /* If this function has a call_stub, then it is called by a
4940 mips16 function; the call needs to go through a stub if
4941 this function is a 32 bit function. If this reloc is a
4942 16 bit call, and the symbol is not a 16 bit function,
4943 then redirect the reloc to the stub. Note that we don't
4944 need to worry about calling the function through a
4945 function pointer; such calls are handled by routing
4946 through a special mips16 routine. We don't have to check
4947 whether this call is from a stub; it can't be, because a
4948 stub contains 32 bit code, and hence can not have a 16
4950 if (r_type
== R_MIPS16_26
4952 && (mh
->call_stub
!= NULL
|| mh
->call_fp_stub
!= NULL
)
4953 && other
!= STO_MIPS16
)
4957 /* If both call_stub and call_fp_stub are defined, we
4958 can figure out which one to use by seeing which one
4959 appears in the input file. */
4960 if (mh
->call_stub
!= NULL
&& mh
->call_fp_stub
!= NULL
)
4965 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
4967 if (strncmp (bfd_get_section_name (input_bfd
, o
),
4968 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
4970 stub
= mh
->call_fp_stub
;
4975 stub
= mh
->call_stub
;
4977 else if (mh
->call_stub
!= NULL
)
4978 stub
= mh
->call_stub
;
4980 stub
= mh
->call_fp_stub
;
4982 BFD_ASSERT (stub
->_raw_size
> 0);
4983 relocation
= stub
->output_section
->vma
+ stub
->output_offset
;
4986 if (r_type
== R_MIPS_HI16
)
4988 Elf_Internal_Rela
*lorel
;
4990 /* As a GNU extension, permit an arbitrary number of
4991 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
4992 This permits gcc to emit the HI and LO relocs itself. */
4993 for (lorel
= rel
+ 1;
4995 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
4999 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5001 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5002 contents
, relocation
+ addend
);
5006 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5007 contents
, rel
->r_offset
,
5008 relocation
, addend
);
5010 else if (r_type
== R_MIPS_GOT16
&& local
)
5012 /* GOT16 must also have an associated LO16 in the local
5013 case. In this case, the addend is extracted and the
5014 section in which the referenced object is determined.
5015 Then the final address of the object is computed and
5016 the GOT entry for the hipage (an aligned 64kb chunk)
5017 is added to .got section if needed. The offset field
5018 of the GOT16-relocated instruction is replaced by the
5019 index of this GOT entry for the hipage. */
5020 if ((rel
+ 1) < relend
5021 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
5023 if (! mips_elf_relocate_got_local (output_bfd
, input_bfd
,
5026 relocation
+ addend
))
5031 r
= bfd_reloc_outofrange
;
5033 else if (r_type
== R_MIPS_CALL16
5034 || r_type
== R_MIPS_GOT16
5035 || r_type
== R_MIPS_CALL_LO16
5036 || r_type
== R_MIPS_GOT_LO16
)
5040 /* This symbol must be registered as a global symbol
5041 having the corresponding got entry. */
5042 BFD_ASSERT (h
->got_offset
!= (bfd_vma
) -1);
5044 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5045 BFD_ASSERT (g
->local_gotno
<= offset
5046 && offset
< sgot
->_raw_size
);
5047 bfd_put_32 (output_bfd
, relocation
+ addend
,
5048 sgot
->contents
+ offset
);
5049 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5051 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
5055 else if (r_type
== R_MIPS_CALL_HI16
5056 || r_type
== R_MIPS_GOT_HI16
)
5060 /* This must be a global symbol with a got entry. The
5061 next reloc must be the corresponding LO16 reloc. */
5062 BFD_ASSERT (h
!= NULL
&& h
->got_offset
!= (bfd_vma
) -1);
5063 BFD_ASSERT ((rel
+ 1) < relend
);
5064 BFD_ASSERT (ELF32_R_TYPE ((rel
+ 1)->r_info
)
5065 == (r_type
== R_MIPS_CALL_HI16
5067 : R_MIPS_GOT_LO16
));
5069 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5070 BFD_ASSERT (g
->local_gotno
<= offset
5071 && offset
< sgot
->_raw_size
);
5072 bfd_put_32 (output_bfd
, relocation
+ addend
,
5073 sgot
->contents
+ offset
);
5074 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5076 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
5080 else if (r_type
== R_MIPS_REL32
5081 || r_type
== R_MIPS_32
)
5083 Elf_Internal_Rel outrel
;
5084 Elf32_crinfo cptrel
;
5088 || (elf_hash_table (info
)->dynamic_sections_created
5090 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
5092 && (input_section
->flags
& SEC_ALLOC
) != 0)
5096 /* When generating a shared object, these
5097 relocations are copied into the output file to be
5098 resolved at run time. */
5101 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5102 BFD_ASSERT (sreloc
!= NULL
);
5107 if (elf_section_data (input_section
)->stab_info
== NULL
)
5108 outrel
.r_offset
= rel
->r_offset
;
5113 off
= (_bfd_stab_section_offset
5114 (output_bfd
, &elf_hash_table (info
)->stab_info
,
5116 &elf_section_data (input_section
)->stab_info
,
5118 if (off
== (bfd_vma
) -1)
5120 outrel
.r_offset
= off
;
5123 outrel
.r_offset
+= (input_section
->output_section
->vma
5124 + input_section
->output_offset
);
5126 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5129 memset (&outrel
, 0, sizeof outrel
);
5131 && (! info
->symbolic
5132 || (h
->elf_link_hash_flags
5133 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5135 BFD_ASSERT (h
->dynindx
!= -1);
5136 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
5137 sec
= input_section
;
5144 sec
= local_sections
[r_symndx
];
5147 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
5149 == bfd_link_hash_defweak
));
5150 sec
= h
->root
.u
.def
.section
;
5152 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5154 else if (sec
== NULL
|| sec
->owner
== NULL
)
5156 bfd_set_error (bfd_error_bad_value
);
5163 osec
= sec
->output_section
;
5164 indx
= elf_section_data (osec
)->dynindx
;
5169 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
5170 addend
+= relocation
;
5174 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
5176 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
5177 (((Elf32_External_Rel
*)
5179 + sreloc
->reloc_count
));
5180 ++sreloc
->reloc_count
;
5182 if (! skip
&& SGI_COMPAT (output_bfd
))
5187 /* Make an entry of compact relocation info. */
5188 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5189 cptrel
.vaddr
= (rel
->r_offset
5190 + input_section
->output_section
->vma
5191 + input_section
->output_offset
);
5192 if (r_type
== R_MIPS_REL32
)
5193 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5195 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5196 mips_elf_set_cr_dist2to (cptrel
, 0);
5197 cptrel
.konst
= addend
;
5199 cr
= (scpt
->contents
5200 + sizeof (Elf32_External_compact_rel
));
5201 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5202 ((Elf32_External_crinfo
*) cr
5203 + scpt
->reloc_count
));
5204 ++scpt
->reloc_count
;
5207 /* This reloc will be computed at runtime, so
5208 there's no need to do anything now. */
5212 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5213 contents
, rel
->r_offset
,
5214 relocation
, addend
);
5216 else if (r_type
== R_MIPS_64
)
5221 /* Do a 32 bit relocation, and sign extend to 64 bits. */
5222 addr
= rel
->r_offset
;
5223 if (bfd_big_endian (input_bfd
))
5225 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5226 contents
, addr
, relocation
,
5228 val
= bfd_get_32 (input_bfd
, contents
+ addr
);
5229 if ((val
& 0x80000000) != 0)
5233 addr
= rel
->r_offset
;
5234 if (bfd_little_endian (input_bfd
))
5236 bfd_put_32 (input_bfd
, val
, contents
+ addr
);
5238 else if (r_type
== R_MIPS_26
&& other
== STO_MIPS16
)
5242 /* This is a jump to a mips16 routine from a mips32
5243 routine. We need to change jal into jalx. */
5244 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5245 if (((insn
>> 26) & 0x3f) != 0x3
5246 && ((insn
>> 26) & 0x3f) != 0x1d)
5248 (*_bfd_error_handler
)
5249 ("%s: %s+0x%lx: jump to mips16 routine which is not jal",
5250 bfd_get_filename (input_bfd
),
5251 input_section
->name
,
5252 (unsigned long) rel
->r_offset
);
5253 bfd_set_error (bfd_error_bad_value
);
5256 insn
= (insn
& 0x3ffffff) | (0x1d << 26);
5257 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5258 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5259 contents
, rel
->r_offset
,
5260 relocation
, addend
);
5262 else if (r_type
== R_MIPS16_26
)
5264 /* It's easiest to do the normal relocation, and then
5265 dig out the instruction and swap the first word the
5266 way the mips16 expects it. If this is little endian,
5267 though, we need to swap the two words first, and then
5268 swap them back again later, so that the address looks
5271 if (bfd_little_endian (input_bfd
))
5275 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5276 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5277 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5280 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5281 contents
, rel
->r_offset
,
5282 relocation
, addend
);
5283 if (r
== bfd_reloc_ok
)
5287 if (bfd_little_endian (input_bfd
))
5289 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5290 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5291 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5294 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5295 insn
= ((insn
& 0xfc00)
5296 | ((insn
& 0x1f) << 5)
5297 | ((insn
& 0x3e0) >> 5));
5298 /* If this is a jump to a 32 bit routine, then make
5300 if (other
!= STO_MIPS16
)
5302 bfd_put_16 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5305 else if (r_type
== R_MIPS16_GPREL
)
5307 unsigned short extend
, insn
;
5309 unsigned long final
;
5311 /* Extract the addend into buf, run the regular reloc,
5312 and stuff the resulting value back into the
5314 if (rel
->r_offset
> input_section
->_raw_size
)
5315 r
= bfd_reloc_outofrange
;
5318 extend
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5319 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 2);
5320 bfd_put_32 (input_bfd
,
5321 (((extend
& 0x1f) << 11)
5325 r
= _bfd_final_link_relocate (howto
, input_bfd
,
5327 (bfd_vma
) 0, relocation
,
5329 final
= bfd_get_32 (input_bfd
, buf
);
5330 bfd_put_16 (input_bfd
,
5332 | ((final
>> 11) & 0x1f)
5334 contents
+ rel
->r_offset
);
5335 bfd_put_16 (input_bfd
,
5338 contents
+ rel
->r_offset
+ 2);
5342 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5343 contents
, rel
->r_offset
,
5344 relocation
, addend
);
5346 /* The jal instruction can only jump to an address which is
5347 divisible by 4, and it can only jump to an address with
5348 the same upper 4 bits as the PC. */
5349 if (r
== bfd_reloc_ok
5350 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
))
5355 if (other
== STO_MIPS16
)
5356 addr
&= ~ (bfd_vma
) 1;
5359 || ((addr
& 0xf0000000)
5360 != ((input_section
->output_section
->vma
5361 + input_section
->output_offset
5364 r
= bfd_reloc_overflow
;
5367 if (SGI_COMPAT (abfd
)
5369 && (input_section
->flags
& SEC_ALLOC
) != 0)
5371 Elf32_crinfo cptrel
;
5374 /* Make an entry of compact relocation info. */
5375 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5376 cptrel
.vaddr
= (rel
->r_offset
5377 + input_section
->output_section
->vma
5378 + input_section
->output_offset
);
5383 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
5384 /* XXX How should we set dist2to in this case. */
5385 mips_elf_set_cr_dist2to (cptrel
, 8);
5386 cptrel
.konst
= addend
+ relocation
;
5387 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5388 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5389 ((Elf32_External_crinfo
*) cr
5390 + scpt
->reloc_count
));
5391 ++scpt
->reloc_count
;
5394 case R_MIPS_GPREL16
:
5395 case R_MIPS_LITERAL
:
5396 case R_MIPS_GPREL32
:
5397 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
5398 cptrel
.konst
= gp
- cptrel
.vaddr
;
5399 mips_elf_set_cr_dist2to (cptrel
, 4);
5400 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5401 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5402 ((Elf32_External_crinfo
*) cr
5403 + scpt
->reloc_count
));
5404 ++scpt
->reloc_count
;
5413 if (r
!= bfd_reloc_ok
)
5418 case bfd_reloc_outofrange
:
5420 case bfd_reloc_overflow
:
5425 name
= h
->root
.root
.string
;
5428 name
= bfd_elf_string_from_elf_section (input_bfd
,
5429 symtab_hdr
->sh_link
,
5434 name
= bfd_section_name (input_bfd
, sec
);
5436 if (! ((*info
->callbacks
->reloc_overflow
)
5437 (info
, name
, howto
->name
, (bfd_vma
) 0,
5438 input_bfd
, input_section
, rel
->r_offset
)))
5449 /* This hook function is called before the linker writes out a global
5450 symbol. We mark symbols as small common if appropriate. This is
5451 also where we undo the increment of the value for a mips16 symbol. */
5455 mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
5457 struct bfd_link_info
*info
;
5459 Elf_Internal_Sym
*sym
;
5460 asection
*input_sec
;
5462 /* If we see a common symbol, which implies a relocatable link, then
5463 if a symbol was small common in an input file, mark it as small
5464 common in the output file. */
5465 if (sym
->st_shndx
== SHN_COMMON
5466 && strcmp (input_sec
->name
, ".scommon") == 0)
5467 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
5469 if (sym
->st_other
== STO_MIPS16
5470 && (sym
->st_value
& 1) != 0)
5476 /* Functions for the dynamic linker. */
5478 /* The name of the dynamic interpreter. This is put in the .interp
5481 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
5483 /* Create dynamic sections when linking against a dynamic object. */
5486 mips_elf_create_dynamic_sections (abfd
, info
)
5488 struct bfd_link_info
*info
;
5490 struct elf_link_hash_entry
*h
;
5492 register asection
*s
;
5493 const char * const *namep
;
5495 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5496 | SEC_LINKER_CREATED
| SEC_READONLY
);
5498 /* Mips ABI requests the .dynamic section to be read only. */
5499 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5502 if (! bfd_set_section_flags (abfd
, s
, flags
))
5506 /* We need to create .got section. */
5507 if (! mips_elf_create_got_section (abfd
, info
))
5510 /* Create .stub section. */
5511 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
5513 s
= bfd_make_section (abfd
, ".stub");
5515 || ! bfd_set_section_flags (abfd
, s
, flags
)
5516 || ! bfd_set_section_alignment (abfd
, s
, 2))
5520 if (SGI_COMPAT (abfd
)
5522 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
5524 s
= bfd_make_section (abfd
, ".rld_map");
5526 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
5527 || ! bfd_set_section_alignment (abfd
, s
, 2))
5531 if (SGI_COMPAT (abfd
))
5533 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
5536 if (! (_bfd_generic_link_add_one_symbol
5537 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
5538 (bfd_vma
) 0, (const char *) NULL
, false,
5539 get_elf_backend_data (abfd
)->collect
,
5540 (struct bfd_link_hash_entry
**) &h
)))
5542 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5543 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5544 h
->type
= STT_SECTION
;
5546 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5550 /* We need to create a .compact_rel section. */
5551 if (! mips_elf_create_compact_rel_section (abfd
, info
))
5554 /* Change aligments of some sections. */
5555 s
= bfd_get_section_by_name (abfd
, ".hash");
5557 bfd_set_section_alignment (abfd
, s
, 4);
5558 s
= bfd_get_section_by_name (abfd
, ".dynsym");
5560 bfd_set_section_alignment (abfd
, s
, 4);
5561 s
= bfd_get_section_by_name (abfd
, ".dynstr");
5563 bfd_set_section_alignment (abfd
, s
, 4);
5564 s
= bfd_get_section_by_name (abfd
, ".reginfo");
5566 bfd_set_section_alignment (abfd
, s
, 4);
5567 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5569 bfd_set_section_alignment (abfd
, s
, 4);
5575 if (! (_bfd_generic_link_add_one_symbol
5576 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
5577 (bfd_vma
) 0, (const char *) NULL
, false,
5578 get_elf_backend_data (abfd
)->collect
,
5579 (struct bfd_link_hash_entry
**) &h
)))
5581 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5582 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5583 h
->type
= STT_SECTION
;
5585 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5588 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
5590 /* __rld_map is a four byte word located in the .data section
5591 and is filled in by the rtld to contain a pointer to
5592 the _r_debug structure. Its symbol value will be set in
5593 mips_elf_finish_dynamic_symbol. */
5594 s
= bfd_get_section_by_name (abfd
, ".rld_map");
5595 BFD_ASSERT (s
!= NULL
);
5598 if (! (_bfd_generic_link_add_one_symbol
5599 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
5600 (bfd_vma
) 0, (const char *) NULL
, false,
5601 get_elf_backend_data (abfd
)->collect
,
5602 (struct bfd_link_hash_entry
**) &h
)))
5604 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5605 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5606 h
->type
= STT_OBJECT
;
5608 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5616 /* Create the .compact_rel section. */
5619 mips_elf_create_compact_rel_section (abfd
, info
)
5621 struct bfd_link_info
*info
;
5624 register asection
*s
;
5626 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
5628 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
5631 s
= bfd_make_section (abfd
, ".compact_rel");
5633 || ! bfd_set_section_flags (abfd
, s
, flags
)
5634 || ! bfd_set_section_alignment (abfd
, s
, 2))
5637 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
5643 /* Create the .got section to hold the global offset table. */
5646 mips_elf_create_got_section (abfd
, info
)
5648 struct bfd_link_info
*info
;
5651 register asection
*s
;
5652 struct elf_link_hash_entry
*h
;
5653 struct mips_got_info
*g
;
5655 /* This function may be called more than once. */
5656 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
5659 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5660 | SEC_LINKER_CREATED
);
5662 s
= bfd_make_section (abfd
, ".got");
5664 || ! bfd_set_section_flags (abfd
, s
, flags
)
5665 || ! bfd_set_section_alignment (abfd
, s
, 4))
5668 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
5669 linker script because we don't want to define the symbol if we
5670 are not creating a global offset table. */
5672 if (! (_bfd_generic_link_add_one_symbol
5673 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
5674 (bfd_vma
) 0, (const char *) NULL
, false,
5675 get_elf_backend_data (abfd
)->collect
,
5676 (struct bfd_link_hash_entry
**) &h
)))
5678 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5679 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5680 h
->type
= STT_OBJECT
;
5683 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5686 /* The first several global offset table entries are reserved. */
5687 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
5689 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
5690 sizeof (struct mips_got_info
));
5693 g
->global_gotsym
= 0;
5694 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
5695 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
5696 if (elf_section_data (s
) == NULL
)
5699 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
5700 if (elf_section_data (s
) == NULL
)
5703 elf_section_data (s
)->tdata
= (PTR
) g
;
5708 /* Look through the relocs for a section during the first phase, and
5709 allocate space in the global offset table. */
5712 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
5714 struct bfd_link_info
*info
;
5716 const Elf_Internal_Rela
*relocs
;
5720 Elf_Internal_Shdr
*symtab_hdr
;
5721 struct elf_link_hash_entry
**sym_hashes
;
5722 struct mips_got_info
*g
;
5724 const Elf_Internal_Rela
*rel
;
5725 const Elf_Internal_Rela
*rel_end
;
5729 if (info
->relocateable
)
5732 dynobj
= elf_hash_table (info
)->dynobj
;
5733 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5734 sym_hashes
= elf_sym_hashes (abfd
);
5735 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
5737 /* Check for the mips16 stub sections. */
5739 name
= bfd_get_section_name (abfd
, sec
);
5740 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
5742 unsigned long r_symndx
;
5744 /* Look at the relocation information to figure out which symbol
5747 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
5749 if (r_symndx
< extsymoff
5750 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
5754 /* This stub is for a local symbol. This stub will only be
5755 needed if there is some relocation in this BFD, other
5756 than a 16 bit function call, which refers to this symbol. */
5757 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5759 Elf_Internal_Rela
*sec_relocs
;
5760 const Elf_Internal_Rela
*r
, *rend
;
5762 /* We can ignore stub sections when looking for relocs. */
5763 if ((o
->flags
& SEC_RELOC
) == 0
5764 || o
->reloc_count
== 0
5765 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
5766 sizeof FN_STUB
- 1) == 0
5767 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
5768 sizeof CALL_STUB
- 1) == 0
5769 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
5770 sizeof CALL_FP_STUB
- 1) == 0)
5773 sec_relocs
= (_bfd_elf32_link_read_relocs
5774 (abfd
, o
, (PTR
) NULL
,
5775 (Elf_Internal_Rela
*) NULL
,
5776 info
->keep_memory
));
5777 if (sec_relocs
== NULL
)
5780 rend
= sec_relocs
+ o
->reloc_count
;
5781 for (r
= sec_relocs
; r
< rend
; r
++)
5782 if (ELF32_R_SYM (r
->r_info
) == r_symndx
5783 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
5786 if (! info
->keep_memory
)
5795 /* There is no non-call reloc for this stub, so we do
5796 not need it. Since this function is called before
5797 the linker maps input sections to output sections, we
5798 can easily discard it by setting the SEC_EXCLUDE
5800 sec
->flags
|= SEC_EXCLUDE
;
5804 /* Record this stub in an array of local symbol stubs for
5806 if (elf_tdata (abfd
)->local_stubs
== NULL
)
5808 unsigned long symcount
;
5811 if (elf_bad_symtab (abfd
))
5812 symcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
5814 symcount
= symtab_hdr
->sh_info
;
5815 n
= (asection
**) bfd_zalloc (abfd
,
5816 symcount
* sizeof (asection
*));
5819 elf_tdata (abfd
)->local_stubs
= n
;
5822 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
5824 /* We don't need to set mips16_stubs_seen in this case.
5825 That flag is used to see whether we need to look through
5826 the global symbol table for stubs. We don't need to set
5827 it here, because we just have a local stub. */
5831 struct mips_elf_link_hash_entry
*h
;
5833 h
= ((struct mips_elf_link_hash_entry
*)
5834 sym_hashes
[r_symndx
- extsymoff
]);
5836 /* H is the symbol this stub is for. */
5839 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
5842 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
5843 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5845 unsigned long r_symndx
;
5846 struct mips_elf_link_hash_entry
*h
;
5849 /* Look at the relocation information to figure out which symbol
5852 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
5854 if (r_symndx
< extsymoff
5855 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
5857 /* This stub was actually built for a static symbol defined
5858 in the same file. We assume that all static symbols in
5859 mips16 code are themselves mips16, so we can simply
5860 discard this stub. Since this function is called before
5861 the linker maps input sections to output sections, we can
5862 easily discard it by setting the SEC_EXCLUDE flag. */
5863 sec
->flags
|= SEC_EXCLUDE
;
5867 h
= ((struct mips_elf_link_hash_entry
*)
5868 sym_hashes
[r_symndx
- extsymoff
]);
5870 /* H is the symbol this stub is for. */
5872 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5873 loc
= &h
->call_fp_stub
;
5875 loc
= &h
->call_stub
;
5877 /* If we already have an appropriate stub for this function, we
5878 don't need another one, so we can discard this one. Since
5879 this function is called before the linker maps input sections
5880 to output sections, we can easily discard it by setting the
5881 SEC_EXCLUDE flag. We can also discard this section if we
5882 happen to already know that this is a mips16 function; it is
5883 not necessary to check this here, as it is checked later, but
5884 it is slightly faster to check now. */
5885 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
5887 sec
->flags
|= SEC_EXCLUDE
;
5892 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
5902 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5907 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5908 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5909 BFD_ASSERT (g
!= NULL
);
5915 rel_end
= relocs
+ sec
->reloc_count
;
5916 for (rel
= relocs
; rel
< rel_end
; rel
++)
5918 unsigned long r_symndx
;
5919 struct elf_link_hash_entry
*h
;
5921 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5923 if (r_symndx
< extsymoff
)
5927 h
= sym_hashes
[r_symndx
- extsymoff
];
5929 /* This may be an indirect symbol created because of a version. */
5932 while (h
->root
.type
== bfd_link_hash_indirect
)
5933 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5937 /* Some relocs require a global offset table. */
5938 if (dynobj
== NULL
|| sgot
== NULL
)
5940 switch (ELF32_R_TYPE (rel
->r_info
))
5944 case R_MIPS_CALL_HI16
:
5945 case R_MIPS_CALL_LO16
:
5946 case R_MIPS_GOT_HI16
:
5947 case R_MIPS_GOT_LO16
:
5949 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
5950 if (! mips_elf_create_got_section (dynobj
, info
))
5952 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5953 BFD_ASSERT (sgot
!= NULL
);
5954 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5955 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5956 BFD_ASSERT (g
!= NULL
);
5962 && (info
->shared
|| h
!= NULL
)
5963 && (sec
->flags
& SEC_ALLOC
) != 0)
5964 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
5972 switch (ELF32_R_TYPE (rel
->r_info
))
5975 case R_MIPS_CALL_HI16
:
5976 case R_MIPS_CALL_LO16
:
5977 /* This symbol requires a global offset table entry. */
5981 (*_bfd_error_handler
)
5982 ("%s: CALL16 reloc at 0x%lx not against global symbol",
5983 bfd_get_filename (abfd
), (unsigned long) rel
->r_offset
);
5984 bfd_set_error (bfd_error_bad_value
);
5988 /* Make sure this symbol is output as a dynamic symbol. */
5989 if (h
->dynindx
== -1)
5991 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5995 if (h
->got_offset
!= (bfd_vma
) -1)
5997 /* We have already allocated space in the .got. */
6001 /* Note the index of the first global got symbol in .dynsym. */
6002 if (g
->global_gotsym
== 0
6003 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6004 g
->global_gotsym
= h
->dynindx
;
6006 /* Make this symbol to have the corresponding got entry. */
6009 /* We need a stub, not a plt entry for the undefined
6010 function. But we record it as if it needs plt. See
6011 elf_adjust_dynamic_symbol in elflink.h. */
6012 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6018 case R_MIPS_GOT_HI16
:
6019 case R_MIPS_GOT_LO16
:
6020 /* This symbol requires a global offset table entry. */
6024 /* Make sure this symbol is output as a dynamic symbol. */
6025 if (h
->dynindx
== -1)
6027 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6031 if (h
->got_offset
!= (bfd_vma
) -1)
6033 /* We have already allocated space in the .got. */
6036 /* Note the index of the first global got symbol in
6038 if (g
->global_gotsym
== 0
6039 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6040 g
->global_gotsym
= h
->dynindx
;
6042 /* Make this symbol to be the global got symbol. */
6050 if ((info
->shared
|| h
!= NULL
)
6051 && (sec
->flags
& SEC_ALLOC
) != 0)
6055 const char *name
= ".rel.dyn";
6057 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6060 sreloc
= bfd_make_section (dynobj
, name
);
6062 || ! bfd_set_section_flags (dynobj
, sreloc
,
6067 | SEC_LINKER_CREATED
6069 || ! bfd_set_section_alignment (dynobj
, sreloc
,
6076 /* When creating a shared object, we must copy these
6077 reloc types into the output file as R_MIPS_REL32
6078 relocs. We make room for this reloc in the
6079 .rel.dyn reloc section */
6080 if (sreloc
->_raw_size
== 0)
6082 /* Add a null element. */
6083 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6084 ++sreloc
->reloc_count
;
6086 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6090 struct mips_elf_link_hash_entry
*hmips
;
6092 /* We only need to copy this reloc if the symbol is
6093 defined in a dynamic object. */
6094 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6095 ++hmips
->mips_32_relocs
;
6099 if (SGI_COMPAT (abfd
))
6100 mips_elf_hash_table (info
)->compact_rel_size
+=
6101 sizeof (Elf32_External_crinfo
);
6106 case R_MIPS_GPREL16
:
6107 case R_MIPS_LITERAL
:
6108 case R_MIPS_GPREL32
:
6109 if (SGI_COMPAT (abfd
))
6110 mips_elf_hash_table (info
)->compact_rel_size
+=
6111 sizeof (Elf32_External_crinfo
);
6118 /* If this reloc is not a 16 bit call, and it has a global
6119 symbol, then we will need the fn_stub if there is one.
6120 References from a stub section do not count. */
6122 && ELF32_R_TYPE (rel
->r_info
) != R_MIPS16_26
6123 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
6124 sizeof FN_STUB
- 1) != 0
6125 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
6126 sizeof CALL_STUB
- 1) != 0
6127 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
6128 sizeof CALL_FP_STUB
- 1) != 0)
6130 struct mips_elf_link_hash_entry
*mh
;
6132 mh
= (struct mips_elf_link_hash_entry
*) h
;
6133 mh
->need_fn_stub
= true;
6140 /* Adjust a symbol defined by a dynamic object and referenced by a
6141 regular object. The current definition is in some section of the
6142 dynamic object, but we're not including those sections. We have to
6143 change the definition to something the rest of the link can
6147 mips_elf_adjust_dynamic_symbol (info
, h
)
6148 struct bfd_link_info
*info
;
6149 struct elf_link_hash_entry
*h
;
6152 struct mips_elf_link_hash_entry
*hmips
;
6155 dynobj
= elf_hash_table (info
)->dynobj
;
6157 /* Make sure we know what is going on here. */
6158 BFD_ASSERT (dynobj
!= NULL
6159 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
6160 || h
->weakdef
!= NULL
6161 || ((h
->elf_link_hash_flags
6162 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
6163 && (h
->elf_link_hash_flags
6164 & ELF_LINK_HASH_REF_REGULAR
) != 0
6165 && (h
->elf_link_hash_flags
6166 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
6168 /* If this symbol is defined in a dynamic object, we need to copy
6169 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
6171 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6172 if (! info
->relocateable
6173 && hmips
->mips_32_relocs
!= 0
6174 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6176 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6177 BFD_ASSERT (s
!= NULL
);
6179 if (s
->_raw_size
== 0)
6181 /* Make room for a null element. */
6182 s
->_raw_size
+= sizeof (Elf32_External_Rel
);
6185 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
6188 /* For a function, create a stub, if needed. */
6189 if (h
->type
== STT_FUNC
6190 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
6192 if (! elf_hash_table (info
)->dynamic_sections_created
)
6195 /* If this symbol is not defined in a regular file, then set
6196 the symbol to the stub location. This is required to make
6197 function pointers compare as equal between the normal
6198 executable and the shared library. */
6199 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6201 /* We need .stub section. */
6202 s
= bfd_get_section_by_name (dynobj
, ".stub");
6203 BFD_ASSERT (s
!= NULL
);
6205 h
->root
.u
.def
.section
= s
;
6206 h
->root
.u
.def
.value
= s
->_raw_size
;
6208 /* XXX Write this stub address somewhere. */
6209 h
->plt_offset
= s
->_raw_size
;
6211 /* Make room for this stub code. */
6212 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6214 /* The last half word of the stub will be filled with the index
6215 of this symbol in .dynsym section. */
6220 /* If this is a weak symbol, and there is a real definition, the
6221 processor independent code will have arranged for us to see the
6222 real definition first, and we can just use the same value. */
6223 if (h
->weakdef
!= NULL
)
6225 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
6226 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
6227 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
6228 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
6232 /* This is a reference to a symbol defined by a dynamic object which
6233 is not a function. */
6238 /* This function is called after all the input files have been read,
6239 and the input sections have been assigned to output sections. We
6240 check for any mips16 stub sections that we can discard. */
6242 static boolean mips_elf_check_mips16_stubs
6243 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
6246 mips_elf_always_size_sections (output_bfd
, info
)
6248 struct bfd_link_info
*info
;
6250 if (info
->relocateable
6251 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
6254 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
6255 mips_elf_check_mips16_stubs
,
6261 /* Check the mips16 stubs for a particular symbol, and see if we can
6266 mips_elf_check_mips16_stubs (h
, data
)
6267 struct mips_elf_link_hash_entry
*h
;
6270 if (h
->fn_stub
!= NULL
6271 && ! h
->need_fn_stub
)
6273 /* We don't need the fn_stub; the only references to this symbol
6274 are 16 bit calls. Clobber the size to 0 to prevent it from
6275 being included in the link. */
6276 h
->fn_stub
->_raw_size
= 0;
6277 h
->fn_stub
->_cooked_size
= 0;
6278 h
->fn_stub
->flags
&= ~ SEC_RELOC
;
6279 h
->fn_stub
->reloc_count
= 0;
6280 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
6283 if (h
->call_stub
!= NULL
6284 && h
->root
.other
== STO_MIPS16
)
6286 /* We don't need the call_stub; this is a 16 bit function, so
6287 calls from other 16 bit functions are OK. Clobber the size
6288 to 0 to prevent it from being included in the link. */
6289 h
->call_stub
->_raw_size
= 0;
6290 h
->call_stub
->_cooked_size
= 0;
6291 h
->call_stub
->flags
&= ~ SEC_RELOC
;
6292 h
->call_stub
->reloc_count
= 0;
6293 h
->call_stub
->flags
|= SEC_EXCLUDE
;
6296 if (h
->call_fp_stub
!= NULL
6297 && h
->root
.other
== STO_MIPS16
)
6299 /* We don't need the call_stub; this is a 16 bit function, so
6300 calls from other 16 bit functions are OK. Clobber the size
6301 to 0 to prevent it from being included in the link. */
6302 h
->call_fp_stub
->_raw_size
= 0;
6303 h
->call_fp_stub
->_cooked_size
= 0;
6304 h
->call_fp_stub
->flags
&= ~ SEC_RELOC
;
6305 h
->call_fp_stub
->reloc_count
= 0;
6306 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
6312 /* Set the sizes of the dynamic sections. */
6315 mips_elf_size_dynamic_sections (output_bfd
, info
)
6317 struct bfd_link_info
*info
;
6323 struct mips_got_info
*g
;
6325 dynobj
= elf_hash_table (info
)->dynobj
;
6326 BFD_ASSERT (dynobj
!= NULL
);
6328 if (elf_hash_table (info
)->dynamic_sections_created
)
6330 /* Set the contents of the .interp section to the interpreter. */
6333 s
= bfd_get_section_by_name (dynobj
, ".interp");
6334 BFD_ASSERT (s
!= NULL
);
6335 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
6336 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
6340 /* Recompute the size of .got for local entires (reserved and
6341 hipages) if needed. To estimate it, get the upper bound of total
6342 size of loadable sections. */
6343 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6347 bfd_size_type loadable_size
= 0;
6348 bfd_size_type local_gotno
;
6351 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6352 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6353 BFD_ASSERT (g
!= NULL
);
6355 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
6356 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
6358 if ((s
->flags
& SEC_ALLOC
) == 0)
6360 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
6363 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
6365 /* Assume there are two loadable segments consisting of
6366 contiguous sections. Is 5 enough? */
6367 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
6368 g
->local_gotno
= local_gotno
;
6369 sgot
->_raw_size
+= local_gotno
* 4;
6372 /* The check_relocs and adjust_dynamic_symbol entry points have
6373 determined the sizes of the various dynamic sections. Allocate
6376 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
6381 /* It's OK to base decisions on the section name, because none
6382 of the dynobj section names depend upon the input files. */
6383 name
= bfd_get_section_name (dynobj
, s
);
6385 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
6390 if (strncmp (name
, ".rel", 4) == 0)
6392 if (s
->_raw_size
== 0)
6396 const char *outname
;
6399 /* If this relocation section applies to a read only
6400 section, then we probably need a DT_TEXTREL entry.
6401 If the relocation section is .rel.dyn, we always
6402 assert a DT_TEXTREL entry rather than testing whether
6403 there exists a relocation to a read only section or
6405 outname
= bfd_get_section_name (output_bfd
,
6407 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
6409 && (target
->flags
& SEC_READONLY
) != 0
6410 && (target
->flags
& SEC_ALLOC
) != 0)
6411 || strcmp (outname
, ".rel.dyn") == 0)
6414 /* We use the reloc_count field as a counter if we need
6415 to copy relocs into the output file. */
6416 if (strcmp (name
, ".rel.dyn") != 0)
6420 else if (strncmp (name
, ".got", 4) == 0)
6424 BFD_ASSERT (elf_section_data (s
) != NULL
);
6425 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
6426 BFD_ASSERT (g
!= NULL
);
6428 /* Fix the size of .got section for the correspondence of
6429 global symbols and got entries. This adds some useless
6430 got entries. Is this required by ABI really? */
6431 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
6432 s
->_raw_size
+= i
* 4;
6434 else if (strncmp (name
, ".stub", 5) == 0)
6436 /* Irix rld assumes that the function stub isn't at the end
6437 of .text section. So put a dummy. XXX */
6438 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6440 else if (! info
->shared
6441 && ! mips_elf_hash_table (info
)->use_rld_obj_head
6442 && strncmp (name
, ".rld_map", 8) == 0)
6444 /* We add a room for __rld_map. It will be filled in by the
6445 rtld to contain a pointer to the _r_debug structure. */
6448 else if (SGI_COMPAT (output_bfd
)
6449 && strncmp (name
, ".compact_rel", 12) == 0)
6450 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
6451 else if (strncmp (name
, ".init", 5) != 0)
6453 /* It's not one of our sections, so don't allocate space. */
6461 for (spp
= &s
->output_section
->owner
->sections
;
6462 *spp
!= s
->output_section
;
6463 spp
= &(*spp
)->next
)
6465 *spp
= s
->output_section
->next
;
6466 --s
->output_section
->owner
->section_count
;
6471 /* Allocate memory for the section contents. */
6472 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
6473 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
6475 bfd_set_error (bfd_error_no_memory
);
6478 memset (s
->contents
, 0, s
->_raw_size
);
6481 if (elf_hash_table (info
)->dynamic_sections_created
)
6483 /* Add some entries to the .dynamic section. We fill in the
6484 values later, in elf_mips_finish_dynamic_sections, but we
6485 must add the entries now so that we get the correct size for
6486 the .dynamic section. The DT_DEBUG entry is filled in by the
6487 dynamic linker and used by the debugger. */
6490 if (SGI_COMPAT (output_bfd
))
6492 /* SGI object has the equivalence of DT_DEBUG in the
6493 DT_MIPS_RLD_MAP entry. */
6494 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
6498 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
6504 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
6508 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
6511 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
6513 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
6516 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
6519 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
6523 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
6526 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
6529 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
6531 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
6534 s
= bfd_get_section_by_name (dynobj
, ".liblist");
6535 BFD_ASSERT (s
!= NULL
);
6537 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
6541 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
6544 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
6548 /* Time stamps in executable files are a bad idea. */
6549 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
6554 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
6559 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
6563 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
6566 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
6569 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
6572 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
6575 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
6578 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
6581 #if 0 /* (SGI_COMPAT) */
6582 if (! bfd_get_section_by_name (dynobj
, ".init"))
6583 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
6586 if (! bfd_get_section_by_name (dynobj
, ".fini"))
6587 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
6592 /* If we use dynamic linking, we generate a section symbol for each
6593 output section. These are local symbols, which means that they
6594 must come first in the dynamic symbol table.
6595 That means we must increment the dynamic symbol index of every
6596 other dynamic symbol. */
6598 const char * const *namep
;
6600 bfd_size_type strindex
;
6601 struct bfd_strtab_hash
*dynstr
;
6602 struct mips_got_info
*g
;
6605 if (elf_hash_table (info
)->dynamic_sections_created
)
6607 if (SGI_COMPAT (output_bfd
))
6609 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
6610 elf_link_hash_traverse (elf_hash_table (info
),
6611 mips_elf_adjust_dynindx
,
6613 elf_hash_table (info
)->dynsymcount
+= c
;
6615 dynstr
= elf_hash_table (info
)->dynstr
;
6616 BFD_ASSERT (dynstr
!= NULL
);
6618 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
6622 s
= bfd_get_section_by_name (output_bfd
, *namep
);
6624 elf_section_data (s
)->dynindx
= i
;
6626 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
6627 if (strindex
== (bfd_size_type
) -1)
6630 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
6635 c
= bfd_count_sections (output_bfd
);
6636 elf_link_hash_traverse (elf_hash_table (info
),
6637 mips_elf_adjust_dynindx
,
6639 elf_hash_table (info
)->dynsymcount
+= c
;
6641 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
6643 elf_section_data (s
)->dynindx
= i
;
6644 /* These symbols will have no names, so we don't need to
6645 fiddle with dynstr_index. */
6652 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6653 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6654 BFD_ASSERT (g
!= NULL
);
6656 /* If there are no global got symbols, fake the last symbol so
6658 if (g
->global_gotsym
)
6659 g
->global_gotsym
+= c
;
6661 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
6668 /* Increment the index of a dynamic symbol by a given amount. Called
6669 via elf_link_hash_traverse. */
6672 mips_elf_adjust_dynindx (h
, cparg
)
6673 struct elf_link_hash_entry
*h
;
6676 unsigned int *cp
= (unsigned int *) cparg
;
6678 if (h
->dynindx
!= -1)
6683 /* Finish up dynamic symbol handling. We set the contents of various
6684 dynamic sections here. */
6687 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
6689 struct bfd_link_info
*info
;
6690 struct elf_link_hash_entry
*h
;
6691 Elf_Internal_Sym
*sym
;
6696 struct mips_got_info
*g
;
6699 dynobj
= elf_hash_table (info
)->dynobj
;
6700 gval
= sym
->st_value
;
6702 if (h
->plt_offset
!= (bfd_vma
) -1)
6706 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
6708 /* This symbol has a stub. Set it up. */
6710 BFD_ASSERT (h
->dynindx
!= -1);
6712 s
= bfd_get_section_by_name (dynobj
, ".stub");
6713 BFD_ASSERT (s
!= NULL
);
6715 /* Fill the stub. */
6717 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
6719 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
6722 /* FIXME: Can h->dynindex be more than 64K? */
6723 if (h
->dynindx
& 0xffff0000)
6726 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
6728 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
6730 BFD_ASSERT (h
->plt_offset
<= s
->_raw_size
);
6731 memcpy (s
->contents
+ h
->plt_offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
6733 /* Mark the symbol as undefined. plt_offset != -1 occurs
6734 only for the referenced symbol. */
6735 sym
->st_shndx
= SHN_UNDEF
;
6737 /* The run-time linker uses the st_value field of the symbol
6738 to reset the global offset table entry for this external
6739 to its stub address when unlinking a shared object. */
6740 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt_offset
;
6741 sym
->st_value
= gval
;
6744 BFD_ASSERT (h
->dynindx
!= -1);
6746 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6747 BFD_ASSERT (sgot
!= NULL
);
6748 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6749 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6750 BFD_ASSERT (g
!= NULL
);
6752 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
6754 bfd_size_type offset
;
6756 /* This symbol has an entry in the global offset table. Set its
6757 value to the corresponding got entry, if needed. */
6758 if (h
->got_offset
== (bfd_vma
) -1)
6760 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
6761 BFD_ASSERT (g
->local_gotno
* 4 <= offset
6762 && offset
< sgot
->_raw_size
);
6763 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
6767 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
6768 name
= h
->root
.root
.string
;
6769 if (strcmp (name
, "_DYNAMIC") == 0
6770 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
6771 sym
->st_shndx
= SHN_ABS
;
6772 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
6774 sym
->st_shndx
= SHN_ABS
;
6775 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6778 else if (SGI_COMPAT (output_bfd
))
6780 if (strcmp (name
, "_gp_disp") == 0)
6782 sym
->st_shndx
= SHN_ABS
;
6783 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6784 sym
->st_value
= elf_gp (output_bfd
);
6786 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
6787 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
6789 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6790 sym
->st_other
= STO_PROTECTED
;
6792 sym
->st_shndx
= SHN_MIPS_DATA
;
6794 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
6796 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6797 sym
->st_other
= STO_PROTECTED
;
6798 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
6799 sym
->st_shndx
= SHN_ABS
;
6801 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
6803 if (h
->type
== STT_FUNC
)
6804 sym
->st_shndx
= SHN_MIPS_TEXT
;
6805 else if (h
->type
== STT_OBJECT
)
6806 sym
->st_shndx
= SHN_MIPS_DATA
;
6810 if (SGI_COMPAT (output_bfd
)
6813 if (! mips_elf_hash_table (info
)->use_rld_obj_head
6814 && strcmp (name
, "__rld_map") == 0)
6816 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
6817 BFD_ASSERT (s
!= NULL
);
6818 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
6819 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
6820 if (mips_elf_hash_table (info
)->rld_value
== 0)
6821 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
6823 else if (mips_elf_hash_table (info
)->use_rld_obj_head
6824 && strcmp (name
, "__rld_obj_head") == 0)
6826 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
6827 BFD_ASSERT (s
!= NULL
);
6828 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
6832 /* If this is a mips16 symbol, force the value to be even. */
6833 if (sym
->st_other
== STO_MIPS16
6834 && (sym
->st_value
& 1) != 0)
6840 /* Finish up the dynamic sections. */
6843 mips_elf_finish_dynamic_sections (output_bfd
, info
)
6845 struct bfd_link_info
*info
;
6850 struct mips_got_info
*g
;
6852 dynobj
= elf_hash_table (info
)->dynobj
;
6854 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
6856 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6861 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6862 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6863 BFD_ASSERT (g
!= NULL
);
6866 if (elf_hash_table (info
)->dynamic_sections_created
)
6868 Elf32_External_Dyn
*dyncon
, *dynconend
;
6870 BFD_ASSERT (sdyn
!= NULL
);
6871 BFD_ASSERT (g
!= NULL
);
6873 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
6874 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
6875 for (; dyncon
< dynconend
; dyncon
++)
6877 Elf_Internal_Dyn dyn
;
6882 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
6890 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6891 BFD_ASSERT (s
!= NULL
);
6892 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
6893 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6897 /* Rewrite DT_STRSZ. */
6899 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
6900 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6906 case DT_MIPS_CONFLICT
:
6909 case DT_MIPS_LIBLIST
:
6912 s
= bfd_get_section_by_name (output_bfd
, name
);
6913 BFD_ASSERT (s
!= NULL
);
6914 dyn
.d_un
.d_ptr
= s
->vma
;
6915 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6918 case DT_MIPS_RLD_VERSION
:
6919 dyn
.d_un
.d_val
= 1; /* XXX */
6920 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6924 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
6925 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6928 case DT_MIPS_CONFLICTNO
:
6930 elemsize
= sizeof (Elf32_Conflict
);
6933 case DT_MIPS_LIBLISTNO
:
6935 elemsize
= sizeof (Elf32_Lib
);
6937 s
= bfd_get_section_by_name (output_bfd
, name
);
6940 if (s
->_cooked_size
!= 0)
6941 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
6943 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
6948 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6951 case DT_MIPS_TIME_STAMP
:
6952 time ((time_t *) &dyn
.d_un
.d_val
);
6953 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6956 case DT_MIPS_ICHECKSUM
:
6960 case DT_MIPS_IVERSION
:
6964 case DT_MIPS_BASE_ADDRESS
:
6965 s
= output_bfd
->sections
;
6966 BFD_ASSERT (s
!= NULL
);
6967 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
6968 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6971 case DT_MIPS_LOCAL_GOTNO
:
6972 dyn
.d_un
.d_val
= g
->local_gotno
;
6973 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6976 case DT_MIPS_SYMTABNO
:
6978 elemsize
= sizeof (Elf32_External_Sym
);
6979 s
= bfd_get_section_by_name (output_bfd
, name
);
6980 BFD_ASSERT (s
!= NULL
);
6982 if (s
->_cooked_size
!= 0)
6983 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
6985 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
6986 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6989 case DT_MIPS_UNREFEXTNO
:
6991 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
6992 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6995 case DT_MIPS_GOTSYM
:
6996 dyn
.d_un
.d_val
= g
->global_gotsym
;
6997 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7000 case DT_MIPS_HIPAGENO
:
7001 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
7002 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7005 case DT_MIPS_RLD_MAP
:
7006 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
7007 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7014 /* The first entry of the global offset table will be filled at
7015 runtime. The second entry will be used by some runtime loaders.
7016 This isn't the case of Irix rld. */
7017 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
7019 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
7020 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
7024 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
7031 Elf_Internal_Sym sym
;
7034 const char * const * namep
= mips_elf_dynsym_sec_names
;
7035 Elf32_compact_rel cpt
;
7037 /* Set up the section symbols for the output sections. SGI sets
7038 the STT_NOTYPE attribute for these symbols. Should we do so? */
7040 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
7041 if (sdynsym
!= NULL
)
7043 if (SGI_COMPAT (output_bfd
))
7047 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7051 while ((name
= *namep
++) != NULL
)
7053 s
= bfd_get_section_by_name (output_bfd
, name
);
7056 sym
.st_value
= s
->vma
;
7057 dindx
= elf_section_data (s
)->dynindx
;
7058 last
= s
->vma
+ s
->_raw_size
;
7062 sym
.st_value
= last
;
7066 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
7071 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
7073 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7074 (((Elf32_External_Sym
*)
7079 /* Set the sh_info field of the output .dynsym section to
7080 the index of the first global symbol. */
7081 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7082 SIZEOF_MIPS_DYNSYM_SECNAMES
;
7088 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
7091 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
7095 sym
.st_value
= s
->vma
;
7097 indx
= elf_section_data (s
)->this_idx
;
7098 BFD_ASSERT (indx
> 0);
7099 sym
.st_shndx
= indx
;
7101 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7102 (((Elf32_External_Sym
*)
7104 + elf_section_data (s
)->dynindx
));
7107 /* Set the sh_info field of the output .dynsym section to
7108 the index of the first global symbol. */
7109 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7110 bfd_count_sections (output_bfd
) + 1;
7114 if (SGI_COMPAT (output_bfd
))
7116 /* Write .compact_rel section out. */
7117 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
7121 cpt
.num
= s
->reloc_count
;
7123 cpt
.offset
= (s
->output_section
->filepos
7124 + sizeof (Elf32_External_compact_rel
));
7127 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
7128 ((Elf32_External_compact_rel
*)
7131 /* Clean up a dummy stub function entry in .text. */
7132 s
= bfd_get_section_by_name (dynobj
, ".stub");
7135 file_ptr dummy_offset
;
7137 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
7138 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
7139 memset (s
->contents
+ dummy_offset
, 0,
7140 MIPS_FUNCTION_STUB_SIZE
);
7145 /* Clean up a first relocation in .rel.dyn. */
7146 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7147 if (s
!= NULL
&& s
->_raw_size
> 0)
7148 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
7154 /* This is almost identical to bfd_generic_get_... except that some
7155 MIPS relocations need to be handled specially. Sigh. */
7158 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
7159 relocateable
, symbols
)
7161 struct bfd_link_info
*link_info
;
7162 struct bfd_link_order
*link_order
;
7164 boolean relocateable
;
7167 /* Get enough memory to hold the stuff */
7168 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
7169 asection
*input_section
= link_order
->u
.indirect
.section
;
7171 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
7172 arelent
**reloc_vector
= NULL
;
7178 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
7179 if (reloc_vector
== NULL
&& reloc_size
!= 0)
7182 /* read in the section */
7183 if (!bfd_get_section_contents (input_bfd
,
7187 input_section
->_raw_size
))
7190 /* We're not relaxing the section, so just copy the size info */
7191 input_section
->_cooked_size
= input_section
->_raw_size
;
7192 input_section
->reloc_done
= true;
7194 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
7198 if (reloc_count
< 0)
7201 if (reloc_count
> 0)
7206 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
7209 struct bfd_hash_entry
*h
;
7210 struct bfd_link_hash_entry
*lh
;
7211 /* Skip all this stuff if we aren't mixing formats. */
7212 if (abfd
&& input_bfd
7213 && abfd
->xvec
== input_bfd
->xvec
)
7217 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
7218 lh
= (struct bfd_link_hash_entry
*) h
;
7225 case bfd_link_hash_undefined
:
7226 case bfd_link_hash_undefweak
:
7227 case bfd_link_hash_common
:
7230 case bfd_link_hash_defined
:
7231 case bfd_link_hash_defweak
:
7233 gp
= lh
->u
.def
.value
;
7235 case bfd_link_hash_indirect
:
7236 case bfd_link_hash_warning
:
7238 /* @@FIXME ignoring warning for now */
7240 case bfd_link_hash_new
:
7249 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
7252 char *error_message
= (char *) NULL
;
7253 bfd_reloc_status_type r
;
7255 /* Specific to MIPS: Deal with relocation types that require
7256 knowing the gp of the output bfd. */
7257 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
7258 if (bfd_is_abs_section (sym
->section
) && abfd
)
7260 /* The special_function wouldn't get called anyways. */
7264 /* The gp isn't there; let the special function code
7265 fall over on its own. */
7267 else if ((*parent
)->howto
->special_function
7268 == _bfd_mips_elf_gprel16_reloc
)
7270 /* bypass special_function call */
7271 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
7272 relocateable
, (PTR
) data
, gp
);
7273 goto skip_bfd_perform_relocation
;
7275 /* end mips specific stuff */
7277 r
= bfd_perform_relocation (input_bfd
,
7281 relocateable
? abfd
: (bfd
*) NULL
,
7283 skip_bfd_perform_relocation
:
7287 asection
*os
= input_section
->output_section
;
7289 /* A partial link, so keep the relocs */
7290 os
->orelocation
[os
->reloc_count
] = *parent
;
7294 if (r
!= bfd_reloc_ok
)
7298 case bfd_reloc_undefined
:
7299 if (!((*link_info
->callbacks
->undefined_symbol
)
7300 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7301 input_bfd
, input_section
, (*parent
)->address
)))
7304 case bfd_reloc_dangerous
:
7305 BFD_ASSERT (error_message
!= (char *) NULL
);
7306 if (!((*link_info
->callbacks
->reloc_dangerous
)
7307 (link_info
, error_message
, input_bfd
, input_section
,
7308 (*parent
)->address
)))
7311 case bfd_reloc_overflow
:
7312 if (!((*link_info
->callbacks
->reloc_overflow
)
7313 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7314 (*parent
)->howto
->name
, (*parent
)->addend
,
7315 input_bfd
, input_section
, (*parent
)->address
)))
7318 case bfd_reloc_outofrange
:
7327 if (reloc_vector
!= NULL
)
7328 free (reloc_vector
);
7332 if (reloc_vector
!= NULL
)
7333 free (reloc_vector
);
7336 #define bfd_elf32_bfd_get_relocated_section_contents \
7337 elf32_mips_get_relocated_section_contents
7339 /* ECOFF swapping routines. These are used when dealing with the
7340 .mdebug section, which is in the ECOFF debugging format. */
7341 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
7343 /* Symbol table magic number. */
7345 /* Alignment of debugging information. E.g., 4. */
7347 /* Sizes of external symbolic information. */
7348 sizeof (struct hdr_ext
),
7349 sizeof (struct dnr_ext
),
7350 sizeof (struct pdr_ext
),
7351 sizeof (struct sym_ext
),
7352 sizeof (struct opt_ext
),
7353 sizeof (struct fdr_ext
),
7354 sizeof (struct rfd_ext
),
7355 sizeof (struct ext_ext
),
7356 /* Functions to swap in external symbolic data. */
7365 _bfd_ecoff_swap_tir_in
,
7366 _bfd_ecoff_swap_rndx_in
,
7367 /* Functions to swap out external symbolic data. */
7376 _bfd_ecoff_swap_tir_out
,
7377 _bfd_ecoff_swap_rndx_out
,
7378 /* Function to read in symbolic data. */
7379 _bfd_mips_elf_read_ecoff_info
7382 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
7383 #define TARGET_LITTLE_NAME "elf32-littlemips"
7384 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
7385 #define TARGET_BIG_NAME "elf32-bigmips"
7386 #define ELF_ARCH bfd_arch_mips
7387 #define ELF_MACHINE_CODE EM_MIPS
7389 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
7390 a value of 0x1000, and we are compatible. */
7391 #define ELF_MAXPAGESIZE 0x1000
7393 #define elf_backend_collect true
7394 #define elf_backend_type_change_ok true
7395 #define elf_info_to_howto 0
7396 #define elf_info_to_howto_rel mips_info_to_howto_rel
7397 #define elf_backend_sym_is_global mips_elf_sym_is_global
7398 #define elf_backend_object_p mips_elf32_object_p
7399 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
7400 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
7401 #define elf_backend_section_from_bfd_section \
7402 _bfd_mips_elf_section_from_bfd_section
7403 #define elf_backend_section_processing mips_elf32_section_processing
7404 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
7405 #define elf_backend_additional_program_headers \
7406 mips_elf_additional_program_headers
7407 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
7408 #define elf_backend_final_write_processing \
7409 _bfd_mips_elf_final_write_processing
7410 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
7412 #define bfd_elf32_bfd_is_local_label_name \
7413 mips_elf_is_local_label_name
7414 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
7415 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
7416 #define bfd_elf32_bfd_link_hash_table_create \
7417 mips_elf_link_hash_table_create
7418 #define bfd_elf32_bfd_final_link mips_elf_final_link
7419 #define bfd_elf32_bfd_copy_private_bfd_data \
7420 _bfd_mips_elf_copy_private_bfd_data
7421 #define bfd_elf32_bfd_merge_private_bfd_data \
7422 _bfd_mips_elf_merge_private_bfd_data
7423 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
7424 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
7425 #define elf_backend_create_dynamic_sections \
7426 mips_elf_create_dynamic_sections
7427 #define elf_backend_check_relocs mips_elf_check_relocs
7428 #define elf_backend_adjust_dynamic_symbol \
7429 mips_elf_adjust_dynamic_symbol
7430 #define elf_backend_always_size_sections \
7431 mips_elf_always_size_sections
7432 #define elf_backend_size_dynamic_sections \
7433 mips_elf_size_dynamic_sections
7434 #define elf_backend_relocate_section mips_elf_relocate_section
7435 #define elf_backend_link_output_symbol_hook \
7436 mips_elf_link_output_symbol_hook
7437 #define elf_backend_finish_dynamic_symbol \
7438 mips_elf_finish_dynamic_symbol
7439 #define elf_backend_finish_dynamic_sections \
7440 mips_elf_finish_dynamic_sections
7442 #include "elf32-target.h"