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
67 PARAMS ((bfd
*, asymbol
*));
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 void 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 boolean mips_elf_adjust_dynindx
86 PARAMS ((struct elf_link_hash_entry
*, PTR
));
87 static boolean mips_elf_relocate_section
88 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
89 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
90 static boolean mips_elf_link_output_symbol_hook
91 PARAMS ((bfd
*, struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
93 static boolean mips_elf_create_dynamic_sections
94 PARAMS ((bfd
*, struct bfd_link_info
*));
95 static boolean mips_elf_create_compact_rel_section
96 PARAMS ((bfd
*, struct bfd_link_info
*));
97 static boolean mips_elf_create_got_section
98 PARAMS ((bfd
*, struct bfd_link_info
*));
99 static boolean mips_elf_check_relocs
100 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
101 const Elf_Internal_Rela
*));
102 static boolean mips_elf_adjust_dynamic_symbol
103 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
104 static boolean mips_elf_always_size_sections
105 PARAMS ((bfd
*, struct bfd_link_info
*));
106 static boolean mips_elf_size_dynamic_sections
107 PARAMS ((bfd
*, struct bfd_link_info
*));
108 static boolean mips_elf_finish_dynamic_symbol
109 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
110 Elf_Internal_Sym
*));
111 static boolean mips_elf_finish_dynamic_sections
112 PARAMS ((bfd
*, struct bfd_link_info
*));
113 static boolean mips_elf_add_symbol_hook
114 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
115 const char **, flagword
*, asection
**, bfd_vma
*));
116 static bfd_reloc_status_type mips_elf_final_gp
117 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
118 static bfd_byte
*elf32_mips_get_relocated_section_contents
119 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
120 bfd_byte
*, boolean
, asymbol
**));
122 /* This is true for Irix 5 executables, false for normal MIPS ELF ABI
123 executables. FIXME: At the moment, we default to always generating
124 Irix 5 executables. */
126 #define SGI_COMPAT(abfd) (1)
128 /* This structure is used to hold .got information when linking. It
129 is stored in the tdata field of the bfd_elf_section_data structure. */
133 /* The symbol index of the first global .got symbol. */
134 unsigned long global_gotsym
;
135 /* The number of local .got entries. */
136 unsigned int local_gotno
;
139 /* The number of local .got entries we reserve. */
140 #define MIPS_RESERVED_GOTNO (2)
142 /* Instructions which appear in a stub. For some reason the stub is
143 slightly different on an SGI system. */
144 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
145 #define STUB_LW(abfd) \
147 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
148 : 0x8f998000) /* lw t9,0x8000(gp) */
149 #define STUB_MOVE 0x03e07825 /* move t7,ra */
150 #define STUB_JALR 0x0320f809 /* jal t9 */
151 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
152 #define MIPS_FUNCTION_STUB_SIZE (16)
154 /* Names of sections which appear in the .dynsym section in an Irix 5
157 static const char * const mips_elf_dynsym_sec_names
[] =
170 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
171 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
173 /* The number of entries in mips_elf_dynsym_sec_names which go in the
176 #define MIPS_TEXT_DYNSYM_SECNO (3)
178 /* The names of the runtime procedure table symbols used on Irix 5. */
180 static const char * const mips_elf_dynsym_rtproc_names
[] =
183 "_procedure_string_table",
184 "_procedure_table_size",
188 /* These structures are used to generate the .compact_rel section on
193 unsigned long id1
; /* Always one? */
194 unsigned long num
; /* Number of compact relocation entries. */
195 unsigned long id2
; /* Always two? */
196 unsigned long offset
; /* The file offset of the first relocation. */
197 unsigned long reserved0
; /* Zero? */
198 unsigned long reserved1
; /* Zero? */
207 bfd_byte reserved0
[4];
208 bfd_byte reserved1
[4];
209 } Elf32_External_compact_rel
;
213 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
214 unsigned int rtype
: 4; /* Relocation types. See below. */
215 unsigned int dist2to
: 8;
216 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
217 unsigned long konst
; /* KONST field. See below. */
218 unsigned long vaddr
; /* VADDR to be relocated. */
223 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
224 unsigned int rtype
: 4; /* Relocation types. See below. */
225 unsigned int dist2to
: 8;
226 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
227 unsigned long konst
; /* KONST field. See below. */
235 } Elf32_External_crinfo
;
241 } Elf32_External_crinfo2
;
243 /* These are the constants used to swap the bitfields in a crinfo. */
245 #define CRINFO_CTYPE (0x1)
246 #define CRINFO_CTYPE_SH (31)
247 #define CRINFO_RTYPE (0xf)
248 #define CRINFO_RTYPE_SH (27)
249 #define CRINFO_DIST2TO (0xff)
250 #define CRINFO_DIST2TO_SH (19)
251 #define CRINFO_RELVADDR (0x7ffff)
252 #define CRINFO_RELVADDR_SH (0)
254 /* A compact relocation info has long (3 words) or short (2 words)
255 formats. A short format doesn't have VADDR field and relvaddr
256 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
257 #define CRF_MIPS_LONG 1
258 #define CRF_MIPS_SHORT 0
260 /* There are 4 types of compact relocation at least. The value KONST
261 has different meaning for each type:
264 CT_MIPS_REL32 Address in data
265 CT_MIPS_WORD Address in word (XXX)
266 CT_MIPS_GPHI_LO GP - vaddr
267 CT_MIPS_JMPAD Address to jump
270 #define CRT_MIPS_REL32 0xa
271 #define CRT_MIPS_WORD 0xb
272 #define CRT_MIPS_GPHI_LO 0xc
273 #define CRT_MIPS_JMPAD 0xd
275 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
276 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
277 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
278 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
280 static void bfd_elf32_swap_compact_rel_out
281 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
282 static void bfd_elf32_swap_crinfo_out
283 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
285 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
290 R_MIPS_16
, R_MIPS_32
,
291 R_MIPS_REL32
, R_MIPS_26
,
292 R_MIPS_HI16
, R_MIPS_LO16
,
293 R_MIPS_GPREL16
, R_MIPS_LITERAL
,
294 R_MIPS_GOT16
, R_MIPS_PC16
,
295 R_MIPS_CALL16
, R_MIPS_GPREL32
,
296 /* The remaining relocs are defined on Irix, although they are not
297 in the MIPS ELF ABI. */
298 R_MIPS_UNUSED1
, R_MIPS_UNUSED2
,
300 R_MIPS_SHIFT5
, R_MIPS_SHIFT6
,
301 R_MIPS_64
, R_MIPS_GOT_DISP
,
302 R_MIPS_GOT_PAGE
, R_MIPS_GOT_OFST
,
303 R_MIPS_GOT_HI16
, R_MIPS_GOT_LO16
,
304 R_MIPS_SUB
, R_MIPS_INSERT_A
,
305 R_MIPS_INSERT_B
, R_MIPS_DELETE
,
306 R_MIPS_HIGHER
, R_MIPS_HIGHEST
,
307 R_MIPS_CALL_HI16
, R_MIPS_CALL_LO16
,
309 /* This reloc is used for the mips16. */
313 static reloc_howto_type elf_mips_howto_table
[] =
316 HOWTO (R_MIPS_NONE
, /* type */
318 0, /* size (0 = byte, 1 = short, 2 = long) */
320 false, /* pc_relative */
322 complain_overflow_dont
, /* complain_on_overflow */
323 bfd_elf_generic_reloc
, /* special_function */
324 "R_MIPS_NONE", /* name */
325 false, /* partial_inplace */
328 false), /* pcrel_offset */
330 /* 16 bit relocation. */
331 HOWTO (R_MIPS_16
, /* type */
333 1, /* size (0 = byte, 1 = short, 2 = long) */
335 false, /* pc_relative */
337 complain_overflow_bitfield
, /* complain_on_overflow */
338 bfd_elf_generic_reloc
, /* special_function */
339 "R_MIPS_16", /* name */
340 true, /* partial_inplace */
341 0xffff, /* src_mask */
342 0xffff, /* dst_mask */
343 false), /* pcrel_offset */
345 /* 32 bit relocation. */
346 HOWTO (R_MIPS_32
, /* type */
348 2, /* size (0 = byte, 1 = short, 2 = long) */
350 false, /* pc_relative */
352 complain_overflow_bitfield
, /* complain_on_overflow */
353 bfd_elf_generic_reloc
, /* special_function */
354 "R_MIPS_32", /* name */
355 true, /* partial_inplace */
356 0xffffffff, /* src_mask */
357 0xffffffff, /* dst_mask */
358 false), /* pcrel_offset */
360 /* 32 bit symbol relative relocation. */
361 HOWTO (R_MIPS_REL32
, /* type */
363 2, /* size (0 = byte, 1 = short, 2 = long) */
365 false, /* pc_relative */
367 complain_overflow_bitfield
, /* complain_on_overflow */
368 bfd_elf_generic_reloc
, /* special_function */
369 "R_MIPS_REL32", /* name */
370 true, /* partial_inplace */
371 0xffffffff, /* src_mask */
372 0xffffffff, /* dst_mask */
373 false), /* pcrel_offset */
375 /* 26 bit branch address. */
376 HOWTO (R_MIPS_26
, /* type */
378 2, /* size (0 = byte, 1 = short, 2 = long) */
380 false, /* pc_relative */
382 complain_overflow_dont
, /* complain_on_overflow */
383 /* This needs complex overflow
384 detection, because the upper four
385 bits must match the PC. */
386 bfd_elf_generic_reloc
, /* special_function */
387 "R_MIPS_26", /* name */
388 true, /* partial_inplace */
389 0x3ffffff, /* src_mask */
390 0x3ffffff, /* dst_mask */
391 false), /* pcrel_offset */
393 /* High 16 bits of symbol value. */
394 HOWTO (R_MIPS_HI16
, /* type */
396 2, /* size (0 = byte, 1 = short, 2 = long) */
398 false, /* pc_relative */
400 complain_overflow_dont
, /* complain_on_overflow */
401 _bfd_mips_elf_hi16_reloc
, /* special_function */
402 "R_MIPS_HI16", /* name */
403 true, /* partial_inplace */
404 0xffff, /* src_mask */
405 0xffff, /* dst_mask */
406 false), /* pcrel_offset */
408 /* Low 16 bits of symbol value. */
409 HOWTO (R_MIPS_LO16
, /* type */
411 2, /* size (0 = byte, 1 = short, 2 = long) */
413 false, /* pc_relative */
415 complain_overflow_dont
, /* complain_on_overflow */
416 _bfd_mips_elf_lo16_reloc
, /* special_function */
417 "R_MIPS_LO16", /* name */
418 true, /* partial_inplace */
419 0xffff, /* src_mask */
420 0xffff, /* dst_mask */
421 false), /* pcrel_offset */
423 /* GP relative reference. */
424 HOWTO (R_MIPS_GPREL16
, /* type */
426 2, /* size (0 = byte, 1 = short, 2 = long) */
428 false, /* pc_relative */
430 complain_overflow_signed
, /* complain_on_overflow */
431 _bfd_mips_elf_gprel16_reloc
, /* special_function */
432 "R_MIPS_GPREL16", /* name */
433 true, /* partial_inplace */
434 0xffff, /* src_mask */
435 0xffff, /* dst_mask */
436 false), /* pcrel_offset */
438 /* Reference to literal section. */
439 HOWTO (R_MIPS_LITERAL
, /* type */
441 2, /* size (0 = byte, 1 = short, 2 = long) */
443 false, /* pc_relative */
445 complain_overflow_signed
, /* complain_on_overflow */
446 _bfd_mips_elf_gprel16_reloc
, /* special_function */
447 "R_MIPS_LITERAL", /* name */
448 true, /* partial_inplace */
449 0xffff, /* src_mask */
450 0xffff, /* dst_mask */
451 false), /* pcrel_offset */
453 /* Reference to global offset table. */
454 HOWTO (R_MIPS_GOT16
, /* type */
456 2, /* size (0 = byte, 1 = short, 2 = long) */
458 false, /* pc_relative */
460 complain_overflow_signed
, /* complain_on_overflow */
461 _bfd_mips_elf_got16_reloc
, /* special_function */
462 "R_MIPS_GOT16", /* name */
463 false, /* partial_inplace */
465 0xffff, /* dst_mask */
466 false), /* pcrel_offset */
468 /* 16 bit PC relative reference. */
469 HOWTO (R_MIPS_PC16
, /* type */
471 2, /* size (0 = byte, 1 = short, 2 = long) */
473 true, /* pc_relative */
475 complain_overflow_signed
, /* complain_on_overflow */
476 bfd_elf_generic_reloc
, /* special_function */
477 "R_MIPS_PC16", /* name */
478 true, /* partial_inplace */
479 0xffff, /* src_mask */
480 0xffff, /* dst_mask */
481 false), /* pcrel_offset */
483 /* 16 bit call through global offset table. */
484 /* FIXME: This is not handled correctly. */
485 HOWTO (R_MIPS_CALL16
, /* type */
487 2, /* size (0 = byte, 1 = short, 2 = long) */
489 false, /* pc_relative */
491 complain_overflow_signed
, /* complain_on_overflow */
492 bfd_elf_generic_reloc
, /* special_function */
493 "R_MIPS_CALL16", /* name */
494 false, /* partial_inplace */
496 0xffff, /* dst_mask */
497 false), /* pcrel_offset */
499 /* 32 bit GP relative reference. */
500 HOWTO (R_MIPS_GPREL32
, /* type */
502 2, /* size (0 = byte, 1 = short, 2 = long) */
504 false, /* pc_relative */
506 complain_overflow_bitfield
, /* complain_on_overflow */
507 _bfd_mips_elf_gprel32_reloc
, /* special_function */
508 "R_MIPS_GPREL32", /* name */
509 true, /* partial_inplace */
510 0xffffffff, /* src_mask */
511 0xffffffff, /* dst_mask */
512 false), /* pcrel_offset */
514 /* The remaining relocs are defined on Irix 5, although they are
515 not defined by the ABI. */
520 /* A 5 bit shift field. */
521 HOWTO (R_MIPS_SHIFT5
, /* type */
523 2, /* size (0 = byte, 1 = short, 2 = long) */
525 false, /* pc_relative */
527 complain_overflow_bitfield
, /* complain_on_overflow */
528 bfd_elf_generic_reloc
, /* special_function */
529 "R_MIPS_SHIFT5", /* name */
530 true, /* partial_inplace */
531 0x000007c0, /* src_mask */
532 0x000007c0, /* dst_mask */
533 false), /* pcrel_offset */
535 /* A 6 bit shift field. */
536 /* FIXME: This is not handled correctly; a special function is
537 needed to put the most significant bit in the right place. */
538 HOWTO (R_MIPS_SHIFT6
, /* type */
540 2, /* size (0 = byte, 1 = short, 2 = long) */
542 false, /* pc_relative */
544 complain_overflow_bitfield
, /* complain_on_overflow */
545 bfd_elf_generic_reloc
, /* special_function */
546 "R_MIPS_SHIFT6", /* name */
547 true, /* partial_inplace */
548 0x000007c4, /* src_mask */
549 0x000007c4, /* dst_mask */
550 false), /* pcrel_offset */
552 /* A 64 bit relocation. This is used in 32 bit ELF when addresses
553 are 64 bits long; the upper 32 bits are simply a sign extension.
554 The fields of the howto should be the same as for R_MIPS_32,
555 other than the type, name, and special_function. */
556 HOWTO (R_MIPS_64
, /* type */
558 2, /* size (0 = byte, 1 = short, 2 = long) */
560 false, /* pc_relative */
562 complain_overflow_bitfield
, /* complain_on_overflow */
563 mips32_64bit_reloc
, /* special_function */
564 "R_MIPS_64", /* name */
565 true, /* partial_inplace */
566 0xffffffff, /* src_mask */
567 0xffffffff, /* dst_mask */
568 false), /* pcrel_offset */
570 /* Displacement in the global offset table. */
571 /* FIXME: Not handled correctly. */
572 HOWTO (R_MIPS_GOT_DISP
, /* type */
574 2, /* size (0 = byte, 1 = short, 2 = long) */
576 false, /* pc_relative */
578 complain_overflow_bitfield
, /* complain_on_overflow */
579 bfd_elf_generic_reloc
, /* special_function */
580 "R_MIPS_GOT_DISP", /* name */
581 true, /* partial_inplace */
582 0x0000ffff, /* src_mask */
583 0x0000ffff, /* dst_mask */
584 false), /* pcrel_offset */
586 /* Displacement to page pointer in the global offset table. */
587 /* FIXME: Not handled correctly. */
588 HOWTO (R_MIPS_GOT_PAGE
, /* type */
590 2, /* size (0 = byte, 1 = short, 2 = long) */
592 false, /* pc_relative */
594 complain_overflow_bitfield
, /* complain_on_overflow */
595 bfd_elf_generic_reloc
, /* special_function */
596 "R_MIPS_GOT_PAGE", /* name */
597 true, /* partial_inplace */
598 0x0000ffff, /* src_mask */
599 0x0000ffff, /* dst_mask */
600 false), /* pcrel_offset */
602 /* Offset from page pointer in the global offset table. */
603 /* FIXME: Not handled correctly. */
604 HOWTO (R_MIPS_GOT_OFST
, /* type */
606 2, /* size (0 = byte, 1 = short, 2 = long) */
608 false, /* pc_relative */
610 complain_overflow_bitfield
, /* complain_on_overflow */
611 bfd_elf_generic_reloc
, /* special_function */
612 "R_MIPS_GOT_OFST", /* name */
613 true, /* partial_inplace */
614 0x0000ffff, /* src_mask */
615 0x0000ffff, /* dst_mask */
616 false), /* pcrel_offset */
618 /* High 16 bits of displacement in global offset table. */
619 /* FIXME: Not handled correctly. */
620 HOWTO (R_MIPS_GOT_HI16
, /* type */
622 2, /* size (0 = byte, 1 = short, 2 = long) */
624 false, /* pc_relative */
626 complain_overflow_dont
, /* complain_on_overflow */
627 bfd_elf_generic_reloc
, /* special_function */
628 "R_MIPS_GOT_HI16", /* name */
629 true, /* partial_inplace */
630 0x0000ffff, /* src_mask */
631 0x0000ffff, /* dst_mask */
632 false), /* pcrel_offset */
634 /* Low 16 bits of displacement in global offset table. */
635 /* FIXME: Not handled correctly. */
636 HOWTO (R_MIPS_GOT_LO16
, /* type */
638 2, /* size (0 = byte, 1 = short, 2 = long) */
640 false, /* pc_relative */
642 complain_overflow_dont
, /* complain_on_overflow */
643 bfd_elf_generic_reloc
, /* special_function */
644 "R_MIPS_GOT_LO16", /* name */
645 true, /* partial_inplace */
646 0x0000ffff, /* src_mask */
647 0x0000ffff, /* dst_mask */
648 false), /* pcrel_offset */
650 /* 64 bit subtraction. Presumably not used in 32 bit ELF. */
653 /* Used to cause the linker to insert and delete instructions? */
658 /* Get the higher values of a 64 bit addend. Presumably not used in
663 /* High 16 bits of displacement in global offset table. */
664 /* FIXME: Not handled correctly. */
665 HOWTO (R_MIPS_CALL_HI16
, /* type */
667 2, /* size (0 = byte, 1 = short, 2 = long) */
669 false, /* pc_relative */
671 complain_overflow_dont
, /* complain_on_overflow */
672 bfd_elf_generic_reloc
, /* special_function */
673 "R_MIPS_CALL_HI16", /* name */
674 true, /* partial_inplace */
675 0x0000ffff, /* src_mask */
676 0x0000ffff, /* dst_mask */
677 false), /* pcrel_offset */
679 /* Low 16 bits of displacement in global offset table. */
680 /* FIXME: Not handled correctly. */
681 HOWTO (R_MIPS_CALL_LO16
, /* type */
683 2, /* size (0 = byte, 1 = short, 2 = long) */
685 false, /* pc_relative */
687 complain_overflow_dont
, /* complain_on_overflow */
688 bfd_elf_generic_reloc
, /* special_function */
689 "R_MIPS_CALL_LO16", /* name */
690 true, /* partial_inplace */
691 0x0000ffff, /* src_mask */
692 0x0000ffff, /* dst_mask */
693 false) /* pcrel_offset */
696 /* The reloc used for the mips16 jump instruction. */
697 static reloc_howto_type elf_mips16_jump_howto
=
698 HOWTO (R_MIPS16_26
, /* type */
700 2, /* size (0 = byte, 1 = short, 2 = long) */
702 false, /* pc_relative */
704 complain_overflow_dont
, /* complain_on_overflow */
705 /* This needs complex overflow
706 detection, because the upper four
707 bits must match the PC. */
708 mips16_jump_reloc
, /* special_function */
709 "R_MIPS16_26", /* name */
710 true, /* partial_inplace */
711 0x3ffffff, /* src_mask */
712 0x3ffffff, /* dst_mask */
713 false); /* pcrel_offset */
715 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
716 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
717 the HI16. Here we just save the information we need; we do the
718 actual relocation when we see the LO16. MIPS ELF requires that the
719 LO16 immediately follow the HI16. As a GNU extension, we permit an
720 arbitrary number of HI16 relocs to be associated with a single LO16
721 reloc. This extension permits gcc to output the HI and LO relocs
726 struct mips_hi16
*next
;
731 /* FIXME: This should not be a static variable. */
733 static struct mips_hi16
*mips_hi16_list
;
735 bfd_reloc_status_type
736 _bfd_mips_elf_hi16_reloc (abfd
,
744 arelent
*reloc_entry
;
747 asection
*input_section
;
749 char **error_message
;
751 bfd_reloc_status_type ret
;
755 /* If we're relocating, and this an external symbol, we don't want
756 to change anything. */
757 if (output_bfd
!= (bfd
*) NULL
758 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
759 && reloc_entry
->addend
== 0)
761 reloc_entry
->address
+= input_section
->output_offset
;
767 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
769 boolean relocateable
;
772 if (ret
== bfd_reloc_undefined
)
775 if (output_bfd
!= NULL
)
779 relocateable
= false;
780 output_bfd
= symbol
->section
->output_section
->owner
;
783 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
785 if (ret
!= bfd_reloc_ok
)
788 relocation
= gp
- reloc_entry
->address
;
792 if (bfd_is_und_section (symbol
->section
)
793 && output_bfd
== (bfd
*) NULL
)
794 ret
= bfd_reloc_undefined
;
796 if (bfd_is_com_section (symbol
->section
))
799 relocation
= symbol
->value
;
802 relocation
+= symbol
->section
->output_section
->vma
;
803 relocation
+= symbol
->section
->output_offset
;
804 relocation
+= reloc_entry
->addend
;
806 if (reloc_entry
->address
> input_section
->_cooked_size
)
807 return bfd_reloc_outofrange
;
809 /* Save the information, and let LO16 do the actual relocation. */
810 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
812 return bfd_reloc_outofrange
;
813 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
814 n
->addend
= relocation
;
815 n
->next
= mips_hi16_list
;
818 if (output_bfd
!= (bfd
*) NULL
)
819 reloc_entry
->address
+= input_section
->output_offset
;
824 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
825 inplace relocation; this function exists in order to do the
826 R_MIPS_HI16 relocation described above. */
828 bfd_reloc_status_type
829 _bfd_mips_elf_lo16_reloc (abfd
,
837 arelent
*reloc_entry
;
840 asection
*input_section
;
842 char **error_message
;
844 arelent gp_disp_relent
;
846 if (mips_hi16_list
!= NULL
)
856 struct mips_hi16
*next
;
858 /* Do the HI16 relocation. Note that we actually don't need
859 to know anything about the LO16 itself, except where to
860 find the low 16 bits of the addend needed by the LO16. */
861 insn
= bfd_get_32 (abfd
, l
->addr
);
862 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
864 val
= ((insn
& 0xffff) << 16) + vallo
;
867 /* The low order 16 bits are always treated as a signed
868 value. Therefore, a negative value in the low order bits
869 requires an adjustment in the high order bits. We need
870 to make this adjustment in two ways: once for the bits we
871 took from the data, and once for the bits we are putting
872 back in to the data. */
873 if ((vallo
& 0x8000) != 0)
875 if ((val
& 0x8000) != 0)
878 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
879 bfd_put_32 (abfd
, insn
, l
->addr
);
881 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
883 gp_disp_relent
= *reloc_entry
;
884 reloc_entry
= &gp_disp_relent
;
885 reloc_entry
->addend
= l
->addend
;
893 mips_hi16_list
= NULL
;
895 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
897 bfd_reloc_status_type ret
;
898 bfd_vma gp
, relocation
;
900 /* FIXME: Does this case ever occur? */
902 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
903 if (ret
!= bfd_reloc_ok
)
906 relocation
= gp
- reloc_entry
->address
;
907 relocation
+= symbol
->section
->output_section
->vma
;
908 relocation
+= symbol
->section
->output_offset
;
909 relocation
+= reloc_entry
->addend
;
911 if (reloc_entry
->address
> input_section
->_cooked_size
)
912 return bfd_reloc_outofrange
;
914 gp_disp_relent
= *reloc_entry
;
915 reloc_entry
= &gp_disp_relent
;
916 reloc_entry
->addend
= relocation
- 4;
919 /* Now do the LO16 reloc in the usual way. */
920 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
921 input_section
, output_bfd
, error_message
);
924 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
925 table used for PIC code. If the symbol is an external symbol, the
926 instruction is modified to contain the offset of the appropriate
927 entry in the global offset table. If the symbol is a section
928 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
929 addends are combined to form the real addend against the section
930 symbol; the GOT16 is modified to contain the offset of an entry in
931 the global offset table, and the LO16 is modified to offset it
932 appropriately. Thus an offset larger than 16 bits requires a
933 modified value in the global offset table.
935 This implementation suffices for the assembler, but the linker does
936 not yet know how to create global offset tables. */
938 bfd_reloc_status_type
939 _bfd_mips_elf_got16_reloc (abfd
,
947 arelent
*reloc_entry
;
950 asection
*input_section
;
952 char **error_message
;
954 /* If we're relocating, and this an external symbol, we don't want
955 to change anything. */
956 if (output_bfd
!= (bfd
*) NULL
957 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
958 && reloc_entry
->addend
== 0)
960 reloc_entry
->address
+= input_section
->output_offset
;
964 /* If we're relocating, and this is a local symbol, we can handle it
966 if (output_bfd
!= (bfd
*) NULL
967 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
968 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
969 input_section
, output_bfd
, error_message
);
974 /* We have to figure out the gp value, so that we can adjust the
975 symbol value correctly. We look up the symbol _gp in the output
976 BFD. If we can't find it, we're stuck. We cache it in the ELF
977 target data. We don't need to adjust the symbol value for an
978 external symbol if we are producing relocateable output. */
980 static bfd_reloc_status_type
981 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
984 boolean relocateable
;
985 char **error_message
;
988 if (bfd_is_und_section (symbol
->section
)
992 return bfd_reloc_undefined
;
995 *pgp
= _bfd_get_gp_value (output_bfd
);
998 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1002 /* Make up a value. */
1003 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1004 _bfd_set_gp_value (output_bfd
, *pgp
);
1012 count
= bfd_get_symcount (output_bfd
);
1013 sym
= bfd_get_outsymbols (output_bfd
);
1015 if (sym
== (asymbol
**) NULL
)
1019 for (i
= 0; i
< count
; i
++, sym
++)
1021 register CONST
char *name
;
1023 name
= bfd_asymbol_name (*sym
);
1024 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1026 *pgp
= bfd_asymbol_value (*sym
);
1027 _bfd_set_gp_value (output_bfd
, *pgp
);
1035 /* Only get the error once. */
1037 _bfd_set_gp_value (output_bfd
, *pgp
);
1039 (char *) "GP relative relocation when _gp not defined";
1040 return bfd_reloc_dangerous
;
1045 return bfd_reloc_ok
;
1048 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1049 become the offset from the gp register. This function also handles
1050 R_MIPS_LITERAL relocations, although those can be handled more
1051 cleverly because the entries in the .lit8 and .lit4 sections can be
1054 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1055 arelent
*, asection
*,
1056 boolean
, PTR
, bfd_vma
));
1058 bfd_reloc_status_type
1059 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1060 output_bfd
, error_message
)
1062 arelent
*reloc_entry
;
1065 asection
*input_section
;
1067 char **error_message
;
1069 boolean relocateable
;
1070 bfd_reloc_status_type ret
;
1073 /* If we're relocating, and this is an external symbol with no
1074 addend, we don't want to change anything. We will only have an
1075 addend if this is a newly created reloc, not read from an ELF
1077 if (output_bfd
!= (bfd
*) NULL
1078 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1079 && reloc_entry
->addend
== 0)
1081 reloc_entry
->address
+= input_section
->output_offset
;
1082 return bfd_reloc_ok
;
1085 if (output_bfd
!= (bfd
*) NULL
)
1086 relocateable
= true;
1089 relocateable
= false;
1090 output_bfd
= symbol
->section
->output_section
->owner
;
1093 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1095 if (ret
!= bfd_reloc_ok
)
1098 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1099 relocateable
, data
, gp
);
1102 static bfd_reloc_status_type
1103 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1107 arelent
*reloc_entry
;
1108 asection
*input_section
;
1109 boolean relocateable
;
1117 if (bfd_is_com_section (symbol
->section
))
1120 relocation
= symbol
->value
;
1122 relocation
+= symbol
->section
->output_section
->vma
;
1123 relocation
+= symbol
->section
->output_offset
;
1125 if (reloc_entry
->address
> input_section
->_cooked_size
)
1126 return bfd_reloc_outofrange
;
1128 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1130 /* Set val to the offset into the section or symbol. */
1131 if (reloc_entry
->howto
->src_mask
== 0)
1133 /* This case occurs with the 64-bit MIPS ELF ABI. */
1134 val
= reloc_entry
->addend
;
1138 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1143 /* Adjust val for the final section location and GP value. If we
1144 are producing relocateable output, we don't want to do this for
1145 an external symbol. */
1147 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1148 val
+= relocation
- gp
;
1150 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1151 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1154 reloc_entry
->address
+= input_section
->output_offset
;
1156 /* Make sure it fit in 16 bits. */
1157 if (val
>= 0x8000 && val
< 0xffff8000)
1158 return bfd_reloc_overflow
;
1160 return bfd_reloc_ok
;
1163 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1164 from the gp register? XXX */
1166 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1167 arelent
*, asection
*,
1168 boolean
, PTR
, bfd_vma
));
1170 bfd_reloc_status_type
1171 _bfd_mips_elf_gprel32_reloc (abfd
,
1179 arelent
*reloc_entry
;
1182 asection
*input_section
;
1184 char **error_message
;
1186 boolean relocateable
;
1187 bfd_reloc_status_type ret
;
1190 /* If we're relocating, and this is an external symbol with no
1191 addend, we don't want to change anything. We will only have an
1192 addend if this is a newly created reloc, not read from an ELF
1194 if (output_bfd
!= (bfd
*) NULL
1195 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1196 && reloc_entry
->addend
== 0)
1198 *error_message
= (char *)
1199 "32bits gp relative relocation occurs for an external symbol";
1200 return bfd_reloc_outofrange
;
1203 if (output_bfd
!= (bfd
*) NULL
)
1205 relocateable
= true;
1206 gp
= _bfd_get_gp_value (output_bfd
);
1210 relocateable
= false;
1211 output_bfd
= symbol
->section
->output_section
->owner
;
1213 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1214 error_message
, &gp
);
1215 if (ret
!= bfd_reloc_ok
)
1219 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1220 relocateable
, data
, gp
);
1223 static bfd_reloc_status_type
1224 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1228 arelent
*reloc_entry
;
1229 asection
*input_section
;
1230 boolean relocateable
;
1237 if (bfd_is_com_section (symbol
->section
))
1240 relocation
= symbol
->value
;
1242 relocation
+= symbol
->section
->output_section
->vma
;
1243 relocation
+= symbol
->section
->output_offset
;
1245 if (reloc_entry
->address
> input_section
->_cooked_size
)
1246 return bfd_reloc_outofrange
;
1248 if (reloc_entry
->howto
->src_mask
== 0)
1250 /* This case arises with the 64-bit MIPS ELF ABI. */
1254 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1256 /* Set val to the offset into the section or symbol. */
1257 val
+= reloc_entry
->addend
;
1259 /* Adjust val for the final section location and GP value. If we
1260 are producing relocateable output, we don't want to do this for
1261 an external symbol. */
1263 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1264 val
+= relocation
- gp
;
1266 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1269 reloc_entry
->address
+= input_section
->output_offset
;
1271 return bfd_reloc_ok
;
1274 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1275 generated when addreses are 64 bits. The upper 32 bits are a simle
1278 static bfd_reloc_status_type
1279 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1280 output_bfd
, error_message
)
1282 arelent
*reloc_entry
;
1285 asection
*input_section
;
1287 char **error_message
;
1289 bfd_reloc_status_type r
;
1294 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1295 input_section
, output_bfd
, error_message
);
1296 if (r
!= bfd_reloc_continue
)
1299 /* Do a normal 32 bit relocation on the lower 32 bits. */
1300 reloc32
= *reloc_entry
;
1301 if (bfd_big_endian (abfd
))
1302 reloc32
.address
+= 4;
1303 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1304 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1305 output_bfd
, error_message
);
1307 /* Sign extend into the upper 32 bits. */
1308 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1309 if ((val
& 0x80000000) != 0)
1313 addr
= reloc_entry
->address
;
1314 if (bfd_little_endian (abfd
))
1316 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1321 /* Handle a mips16 jump. */
1323 static bfd_reloc_status_type
1324 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1325 output_bfd
, error_message
)
1327 arelent
*reloc_entry
;
1330 asection
*input_section
;
1332 char **error_message
;
1334 if (output_bfd
!= (bfd
*) NULL
1335 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1336 && reloc_entry
->addend
== 0)
1338 reloc_entry
->address
+= input_section
->output_offset
;
1339 return bfd_reloc_ok
;
1346 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1348 struct elf_reloc_map
{
1349 bfd_reloc_code_real_type bfd_reloc_val
;
1350 enum reloc_type elf_reloc_val
;
1353 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1355 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1356 { BFD_RELOC_16
, R_MIPS_16
},
1357 { BFD_RELOC_32
, R_MIPS_32
},
1358 { BFD_RELOC_CTOR
, R_MIPS_32
},
1359 { BFD_RELOC_64
, R_MIPS_64
},
1360 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1361 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1362 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1363 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1364 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1365 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1366 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1367 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1368 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1369 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1370 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1371 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1372 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
}
1375 /* Given a BFD reloc type, return a howto structure. */
1377 static reloc_howto_type
*
1378 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1380 bfd_reloc_code_real_type code
;
1384 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1386 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1387 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1390 /* Special handling for the MIPS16 jump, since it is a made up reloc
1391 type with a large value. */
1392 if (code
== BFD_RELOC_MIPS16_JMP
)
1393 return &elf_mips16_jump_howto
;
1398 /* Given a MIPS reloc type, fill in an arelent structure. */
1401 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1404 Elf32_Internal_Rel
*dst
;
1406 unsigned int r_type
;
1408 r_type
= ELF32_R_TYPE (dst
->r_info
);
1409 if (r_type
== R_MIPS16_26
)
1410 cache_ptr
->howto
= &elf_mips16_jump_howto
;
1413 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1414 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1417 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1418 value for the object file. We get the addend now, rather than
1419 when we do the relocation, because the symbol manipulations done
1420 by the linker may cause us to lose track of the input BFD. */
1421 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1422 && (r_type
== (unsigned int) R_MIPS_GPREL16
1423 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1424 cache_ptr
->addend
= elf_gp (abfd
);
1427 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1428 routines swap this structure in and out. They are used outside of
1429 BFD, so they are globally visible. */
1432 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1434 const Elf32_External_RegInfo
*ex
;
1437 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1438 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1439 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1440 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1441 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1442 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1446 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1448 const Elf32_RegInfo
*in
;
1449 Elf32_External_RegInfo
*ex
;
1451 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1452 (bfd_byte
*) ex
->ri_gprmask
);
1453 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1454 (bfd_byte
*) ex
->ri_cprmask
[0]);
1455 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1456 (bfd_byte
*) ex
->ri_cprmask
[1]);
1457 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1458 (bfd_byte
*) ex
->ri_cprmask
[2]);
1459 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1460 (bfd_byte
*) ex
->ri_cprmask
[3]);
1461 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1462 (bfd_byte
*) ex
->ri_gp_value
);
1465 /* In the 64 bit ABI, the .MIPS.options section holds register
1466 information in an Elf64_Reginfo structure. These routines swap
1467 them in and out. They are globally visible because they are used
1468 outside of BFD. These routines are here so that gas can call them
1469 without worrying about whether the 64 bit ABI has been included. */
1472 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1474 const Elf64_External_RegInfo
*ex
;
1475 Elf64_Internal_RegInfo
*in
;
1477 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1478 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
1479 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1480 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1481 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1482 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1483 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1487 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1489 const Elf64_Internal_RegInfo
*in
;
1490 Elf64_External_RegInfo
*ex
;
1492 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1493 (bfd_byte
*) ex
->ri_gprmask
);
1494 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
1495 (bfd_byte
*) ex
->ri_pad
);
1496 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1497 (bfd_byte
*) ex
->ri_cprmask
[0]);
1498 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1499 (bfd_byte
*) ex
->ri_cprmask
[1]);
1500 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1501 (bfd_byte
*) ex
->ri_cprmask
[2]);
1502 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1503 (bfd_byte
*) ex
->ri_cprmask
[3]);
1504 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1505 (bfd_byte
*) ex
->ri_gp_value
);
1508 /* Swap an entry in a .gptab section. Note that these routines rely
1509 on the equivalence of the two elements of the union. */
1512 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1514 const Elf32_External_gptab
*ex
;
1517 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1518 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1522 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1524 const Elf32_gptab
*in
;
1525 Elf32_External_gptab
*ex
;
1527 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1528 ex
->gt_entry
.gt_g_value
);
1529 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1530 ex
->gt_entry
.gt_bytes
);
1534 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1536 const Elf32_compact_rel
*in
;
1537 Elf32_External_compact_rel
*ex
;
1539 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
1540 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
1541 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
1542 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
1543 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
1544 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
1548 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1550 const Elf32_crinfo
*in
;
1551 Elf32_External_crinfo
*ex
;
1555 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1556 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1557 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1558 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1559 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
1560 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
1561 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
1564 /* Swap in an options header. */
1567 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1569 const Elf_External_Options
*ex
;
1570 Elf_Internal_Options
*in
;
1572 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
1573 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
1574 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
1575 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
1578 /* Swap out an options header. */
1581 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
1583 const Elf_Internal_Options
*in
;
1584 Elf_External_Options
*ex
;
1586 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
1587 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
1588 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
1589 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
1592 /* Determine whether a symbol is global for the purposes of splitting
1593 the symbol table into global symbols and local symbols. At least
1594 on Irix 5, this split must be between section symbols and all other
1595 symbols. On most ELF targets the split is between static symbols
1596 and externally visible symbols. */
1600 mips_elf_sym_is_global (abfd
, sym
)
1604 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
1607 /* Set the right machine number for a MIPS ELF file. This is used for
1608 both the 32-bit and the 64-bit ABI. */
1611 _bfd_mips_elf_object_p (abfd
)
1614 switch (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
)
1618 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 3000);
1622 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 6000);
1626 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 4000);
1630 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 8000);
1637 /* Set the right machine number for a 32-bit MIPS ELF file. */
1640 mips_elf32_object_p (abfd
)
1643 /* Irix 5 is broken. Object file symbol tables are not always
1644 sorted correctly such that local symbols precede global symbols,
1645 and the sh_info field in the symbol table is not always right. */
1646 elf_bad_symtab (abfd
) = true;
1648 return _bfd_mips_elf_object_p (abfd
);
1651 /* The final processing done just before writing out a MIPS ELF object
1652 file. This gets the MIPS architecture right based on the machine
1653 number. This is used by both the 32-bit and the 64-bit ABI. */
1657 _bfd_mips_elf_final_write_processing (abfd
, linker
)
1663 Elf_Internal_Shdr
**hdrpp
;
1667 switch (bfd_get_mach (abfd
))
1670 val
= E_MIPS_ARCH_1
;
1674 val
= E_MIPS_ARCH_2
;
1678 val
= E_MIPS_ARCH_3
;
1682 val
= E_MIPS_ARCH_4
;
1690 elf_elfheader (abfd
)->e_flags
&=~ EF_MIPS_ARCH
;
1691 elf_elfheader (abfd
)->e_flags
|= val
;
1693 /* Set the sh_info field for .gptab sections. */
1694 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
1695 i
< elf_elfheader (abfd
)->e_shnum
;
1698 switch ((*hdrpp
)->sh_type
)
1700 case SHT_MIPS_LIBLIST
:
1701 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
1703 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
1706 case SHT_MIPS_GPTAB
:
1707 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1708 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1709 BFD_ASSERT (name
!= NULL
1710 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
1711 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
1712 BFD_ASSERT (sec
!= NULL
);
1713 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1716 case SHT_MIPS_CONTENT
:
1717 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1718 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1719 BFD_ASSERT (name
!= NULL
1720 && strncmp (name
, ".MIPS.content",
1721 sizeof ".MIPS.content" - 1) == 0);
1722 sec
= bfd_get_section_by_name (abfd
,
1723 name
+ sizeof ".MIPS.content" - 1);
1724 BFD_ASSERT (sec
!= NULL
);
1725 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1728 case SHT_MIPS_SYMBOL_LIB
:
1729 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
1731 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
1732 sec
= bfd_get_section_by_name (abfd
, ".liblist");
1734 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1737 case SHT_MIPS_EVENTS
:
1738 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1739 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1740 BFD_ASSERT (name
!= NULL
);
1741 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
1742 sec
= bfd_get_section_by_name (abfd
,
1743 name
+ sizeof ".MIPS.events" - 1);
1746 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
1747 sizeof ".MIPS.post_rel" - 1) == 0);
1748 sec
= bfd_get_section_by_name (abfd
,
1750 + sizeof ".MIPS.post_rel" - 1));
1752 BFD_ASSERT (sec
!= NULL
);
1753 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
1759 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
1762 _bfd_mips_elf_set_private_flags (abfd
, flags
)
1766 BFD_ASSERT (!elf_flags_init (abfd
)
1767 || elf_elfheader (abfd
)->e_flags
== flags
);
1769 elf_elfheader (abfd
)->e_flags
= flags
;
1770 elf_flags_init (abfd
) = true;
1774 /* Copy backend specific data from one object module to another */
1777 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
1781 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1782 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1785 BFD_ASSERT (!elf_flags_init (obfd
)
1786 || (elf_elfheader (obfd
)->e_flags
1787 == elf_elfheader (ibfd
)->e_flags
));
1789 elf_gp (obfd
) = elf_gp (ibfd
);
1790 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1791 elf_flags_init (obfd
) = true;
1795 /* Return the ISA for a MIPS e_flags value. */
1798 elf_mips_isa (flags
)
1801 switch (flags
& EF_MIPS_ARCH
)
1815 /* Merge backend specific data from an object file to the output
1816 object file when linking. */
1819 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
1827 /* Check if we have the same endianess */
1828 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1829 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1831 (*_bfd_error_handler
)
1832 ("%s: compiled for a %s endian system and target is %s endian",
1833 bfd_get_filename (ibfd
),
1834 bfd_big_endian (ibfd
) ? "big" : "little",
1835 bfd_big_endian (obfd
) ? "big" : "little");
1837 bfd_set_error (bfd_error_wrong_format
);
1841 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1842 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1845 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1846 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
1847 old_flags
= elf_elfheader (obfd
)->e_flags
;
1849 if (! elf_flags_init (obfd
))
1851 elf_flags_init (obfd
) = true;
1852 elf_elfheader (obfd
)->e_flags
= new_flags
;
1854 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
1855 && bfd_get_arch_info (obfd
)->the_default
)
1857 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
1858 bfd_get_mach (ibfd
)))
1865 /* Check flag compatibility. */
1867 new_flags
&= ~EF_MIPS_NOREORDER
;
1868 old_flags
&= ~EF_MIPS_NOREORDER
;
1870 if (new_flags
== old_flags
)
1875 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
1877 new_flags
&= ~EF_MIPS_PIC
;
1878 old_flags
&= ~EF_MIPS_PIC
;
1879 (*_bfd_error_handler
)
1880 ("%s: linking PIC files with non-PIC files",
1881 bfd_get_filename (ibfd
));
1885 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
1887 new_flags
&= ~EF_MIPS_CPIC
;
1888 old_flags
&= ~EF_MIPS_CPIC
;
1889 (*_bfd_error_handler
)
1890 ("%s: linking abicalls files with non-abicalls files",
1891 bfd_get_filename (ibfd
));
1895 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
1896 and -mips4 code. They will normally use the same data sizes and
1897 calling conventions. */
1898 if ((new_flags
& EF_MIPS_ARCH
) != (old_flags
& EF_MIPS_ARCH
))
1900 int new_isa
, old_isa
;
1902 new_isa
= elf_mips_isa (new_flags
);
1903 old_isa
= elf_mips_isa (old_flags
);
1904 if ((new_isa
== 1 || new_isa
== 2)
1905 ? (old_isa
!= 1 && old_isa
!= 2)
1906 : (old_isa
== 1 || old_isa
== 2))
1908 (*_bfd_error_handler
)
1909 ("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)",
1910 bfd_get_filename (ibfd
), new_isa
, old_isa
);
1914 new_flags
&= ~ EF_MIPS_ARCH
;
1915 old_flags
&= ~ EF_MIPS_ARCH
;
1918 /* Warn about any other mismatches */
1919 if (new_flags
!= old_flags
)
1921 (*_bfd_error_handler
)
1922 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1923 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
1924 (unsigned long) old_flags
);
1930 bfd_set_error (bfd_error_bad_value
);
1937 /* Handle a MIPS specific section when reading an object file. This
1938 is called when elfcode.h finds a section with an unknown type.
1939 This routine supports both the 32-bit and 64-bit ELF ABI.
1941 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
1945 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
1947 Elf_Internal_Shdr
*hdr
;
1950 /* There ought to be a place to keep ELF backend specific flags, but
1951 at the moment there isn't one. We just keep track of the
1952 sections by their name, instead. Fortunately, the ABI gives
1953 suggested names for all the MIPS specific sections, so we will
1954 probably get away with this. */
1955 switch (hdr
->sh_type
)
1957 case SHT_MIPS_LIBLIST
:
1958 if (strcmp (name
, ".liblist") != 0)
1962 if (strcmp (name
, ".msym") != 0)
1965 case SHT_MIPS_CONFLICT
:
1966 if (strcmp (name
, ".conflict") != 0)
1969 case SHT_MIPS_GPTAB
:
1970 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
1973 case SHT_MIPS_UCODE
:
1974 if (strcmp (name
, ".ucode") != 0)
1977 case SHT_MIPS_DEBUG
:
1978 if (strcmp (name
, ".mdebug") != 0)
1981 case SHT_MIPS_REGINFO
:
1982 if (strcmp (name
, ".reginfo") != 0
1983 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
1986 case SHT_MIPS_IFACE
:
1987 if (strcmp (name
, ".MIPS.interfaces") != 0)
1990 case SHT_MIPS_CONTENT
:
1991 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
1994 case SHT_MIPS_OPTIONS
:
1995 if (strcmp (name
, ".options") != 0
1996 && strcmp (name
, ".MIPS.options") != 0)
1999 case SHT_MIPS_DWARF
:
2000 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2003 case SHT_MIPS_SYMBOL_LIB
:
2004 if (strcmp (name
, ".MIPS.symlib") != 0)
2007 case SHT_MIPS_EVENTS
:
2008 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2009 && strncmp (name
, ".MIPS.post_rel",
2010 sizeof ".MIPS.post_rel" - 1) != 0)
2017 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2020 if (hdr
->sh_type
== SHT_MIPS_DEBUG
)
2022 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
2023 (bfd_get_section_flags (abfd
,
2032 /* Handle a 32-bit MIPS ELF specific section. */
2035 mips_elf32_section_from_shdr (abfd
, hdr
, name
)
2037 Elf_Internal_Shdr
*hdr
;
2040 if (! _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
))
2043 /* FIXME: We should record sh_info for a .gptab section. */
2045 /* For a .reginfo section, set the gp value in the tdata information
2046 from the contents of this section. We need the gp value while
2047 processing relocs, so we just get it now. The .reginfo section
2048 is not used in the 64-bit MIPS ELF ABI. */
2049 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2051 Elf32_External_RegInfo ext
;
2054 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
2055 (file_ptr
) 0, sizeof ext
))
2057 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
2058 elf_gp (abfd
) = s
.ri_gp_value
;
2061 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2062 set the gp value based on what we find. We may see both
2063 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2064 they should agree. */
2065 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
2067 bfd_byte
*contents
, *l
, *lend
;
2069 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
2070 if (contents
== NULL
)
2072 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
2073 (file_ptr
) 0, hdr
->sh_size
))
2079 lend
= contents
+ hdr
->sh_size
;
2080 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2082 Elf_Internal_Options intopt
;
2084 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2086 if (intopt
.kind
== ODK_REGINFO
)
2088 Elf32_RegInfo intreg
;
2090 bfd_mips_elf32_swap_reginfo_in
2092 ((Elf32_External_RegInfo
*)
2093 (l
+ sizeof (Elf_External_Options
))),
2095 elf_gp (abfd
) = intreg
.ri_gp_value
;
2105 /* Set the correct type for a MIPS ELF section. We do this by the
2106 section name, which is a hack, but ought to work. This routine is
2107 used by both the 32-bit and the 64-bit ABI. */
2110 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
2112 Elf32_Internal_Shdr
*hdr
;
2115 register const char *name
;
2117 name
= bfd_get_section_name (abfd
, sec
);
2119 if (strcmp (name
, ".liblist") == 0)
2121 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
2122 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
2123 /* The sh_link field is set in final_write_processing. */
2125 else if (strcmp (name
, ".msym") == 0)
2127 hdr
->sh_type
= SHT_MIPS_MSYM
;
2128 hdr
->sh_entsize
= 8;
2129 /* FIXME: Set the sh_info field. */
2131 else if (strcmp (name
, ".conflict") == 0)
2132 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
2133 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2135 hdr
->sh_type
= SHT_MIPS_GPTAB
;
2136 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
2137 /* The sh_info field is set in final_write_processing. */
2139 else if (strcmp (name
, ".ucode") == 0)
2140 hdr
->sh_type
= SHT_MIPS_UCODE
;
2141 else if (strcmp (name
, ".mdebug") == 0)
2143 hdr
->sh_type
= SHT_MIPS_DEBUG
;
2144 /* In a shared object on Irix 5.3, the .mdebug section has an
2145 entsize of 0. FIXME: Does this matter? */
2146 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2147 hdr
->sh_entsize
= 0;
2149 hdr
->sh_entsize
= 1;
2151 else if (strcmp (name
, ".reginfo") == 0)
2153 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2154 /* In a shared object on Irix 5.3, the .reginfo section has an
2155 entsize of 0x18. FIXME: Does this matter? */
2156 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2157 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2159 hdr
->sh_entsize
= 1;
2161 /* Force the section size to the correct value, even if the
2162 linker thinks it is larger. The link routine below will only
2163 write out this much data for .reginfo. */
2164 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf32_External_RegInfo
);
2166 else if (SGI_COMPAT (abfd
)
2167 && (strcmp (name
, ".hash") == 0
2168 || strcmp (name
, ".dynamic") == 0
2169 || strcmp (name
, ".dynstr") == 0))
2171 hdr
->sh_entsize
= 0;
2172 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2174 else if (strcmp (name
, ".got") == 0
2175 || strcmp (name
, ".sdata") == 0
2176 || strcmp (name
, ".sbss") == 0
2177 || strcmp (name
, ".lit4") == 0
2178 || strcmp (name
, ".lit8") == 0)
2179 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2180 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2182 hdr
->sh_type
= SHT_MIPS_IFACE
;
2183 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2185 else if (strcmp (name
, ".MIPS.content") == 0)
2187 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2188 /* The sh_info field is set in final_write_processing. */
2190 else if (strcmp (name
, ".options") == 0
2191 || strcmp (name
, ".MIPS.options") == 0)
2193 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2194 hdr
->sh_entsize
= 1;
2195 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2197 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2198 hdr
->sh_type
= SHT_MIPS_DWARF
;
2199 else if (strcmp (name
, ".MIPS.symlib") == 0)
2201 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2202 /* The sh_link and sh_info fields are set in
2203 final_write_processing. */
2205 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2206 || strncmp (name
, ".MIPS.post_rel",
2207 sizeof ".MIPS.post_rel" - 1) == 0)
2209 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2210 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2211 /* The sh_link field is set in final_write_processing. */
2217 /* Given a BFD section, try to locate the corresponding ELF section
2218 index. This is used by both the 32-bit and the 64-bit ABI.
2219 Actually, it's not clear to me that the 64-bit ABI supports these,
2220 but for non-PIC objects we will certainly want support for at least
2221 the .scommon section. */
2224 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2226 Elf32_Internal_Shdr
*hdr
;
2230 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2232 *retval
= SHN_MIPS_SCOMMON
;
2235 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2237 *retval
= SHN_MIPS_ACOMMON
;
2243 /* When are writing out the .options or .MIPS.options section,
2244 remember the bytes we are writing out, so that we can install the
2245 GP value in the section_processing routine. */
2248 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2253 bfd_size_type count
;
2255 if (strcmp (section
->name
, ".options") == 0
2256 || strcmp (section
->name
, ".MIPS.options") == 0)
2260 if (elf_section_data (section
) == NULL
)
2262 section
->used_by_bfd
=
2263 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
2264 if (elf_section_data (section
) == NULL
)
2267 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
2272 if (section
->_cooked_size
!= 0)
2273 size
= section
->_cooked_size
;
2275 size
= section
->_raw_size
;
2276 c
= (PTR
) bfd_zalloc (abfd
, size
);
2279 elf_section_data (section
)->tdata
= (PTR
) c
;
2282 memcpy (c
+ offset
, location
, count
);
2285 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
2289 /* Work over a section just before writing it out. This routine is
2290 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2291 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2295 _bfd_mips_elf_section_processing (abfd
, hdr
)
2297 Elf_Internal_Shdr
*hdr
;
2299 if (hdr
->bfd_section
!= NULL
)
2301 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
2303 if (strcmp (name
, ".sdata") == 0)
2305 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2306 hdr
->sh_type
= SHT_PROGBITS
;
2308 else if (strcmp (name
, ".sbss") == 0)
2310 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2311 hdr
->sh_type
= SHT_NOBITS
;
2313 else if (strcmp (name
, ".lit8") == 0
2314 || strcmp (name
, ".lit4") == 0)
2316 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2317 hdr
->sh_type
= SHT_PROGBITS
;
2319 else if (strcmp (name
, ".compact_rel") == 0)
2322 hdr
->sh_type
= SHT_PROGBITS
;
2324 else if (strcmp (name
, ".rtproc") == 0)
2326 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
2328 unsigned int adjust
;
2330 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
2332 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
2340 /* Work over a section just before writing it out. We update the GP
2341 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2342 on the value we are using. */
2345 mips_elf32_section_processing (abfd
, hdr
)
2347 Elf32_Internal_Shdr
*hdr
;
2349 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2353 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2354 BFD_ASSERT (hdr
->contents
== NULL
);
2357 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2360 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2361 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2365 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2366 && hdr
->bfd_section
!= NULL
2367 && elf_section_data (hdr
->bfd_section
) != NULL
2368 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2370 bfd_byte
*contents
, *l
, *lend
;
2372 /* We stored the section contents in the elf_section_data tdata
2373 field in the set_section_contents routine. We save the
2374 section contents so that we don't have to read them again.
2375 At this point we know that elf_gp is set, so we can look
2376 through the section contents to see if there is an
2377 ODK_REGINFO structure. */
2379 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2381 lend
= contents
+ hdr
->sh_size
;
2382 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2384 Elf_Internal_Options intopt
;
2386 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2388 if (intopt
.kind
== ODK_REGINFO
)
2395 + sizeof (Elf_External_Options
)
2396 + (sizeof (Elf32_External_RegInfo
) - 4)),
2399 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
2400 if (bfd_write (buf
, 1, 4, abfd
) != 4)
2407 return _bfd_mips_elf_section_processing (abfd
, hdr
);
2410 /* MIPS ELF uses two common sections. One is the usual one, and the
2411 other is for small objects. All the small objects are kept
2412 together, and then referenced via the gp pointer, which yields
2413 faster assembler code. This is what we use for the small common
2414 section. This approach is copied from ecoff.c. */
2415 static asection mips_elf_scom_section
;
2416 static asymbol mips_elf_scom_symbol
;
2417 static asymbol
*mips_elf_scom_symbol_ptr
;
2419 /* MIPS ELF also uses an acommon section, which represents an
2420 allocated common symbol which may be overridden by a
2421 definition in a shared library. */
2422 static asection mips_elf_acom_section
;
2423 static asymbol mips_elf_acom_symbol
;
2424 static asymbol
*mips_elf_acom_symbol_ptr
;
2426 /* The Irix 5 support uses two virtual sections, which represent
2427 text/data symbols defined in dynamic objects. */
2428 static asection mips_elf_text_section
;
2429 static asection
*mips_elf_text_section_ptr
;
2430 static asymbol mips_elf_text_symbol
;
2431 static asymbol
*mips_elf_text_symbol_ptr
;
2433 static asection mips_elf_data_section
;
2434 static asection
*mips_elf_data_section_ptr
;
2435 static asymbol mips_elf_data_symbol
;
2436 static asymbol
*mips_elf_data_symbol_ptr
;
2438 /* Handle the special MIPS section numbers that a symbol may use.
2439 This is used for both the 32-bit and the 64-bit ABI. */
2442 _bfd_mips_elf_symbol_processing (abfd
, asym
)
2446 elf_symbol_type
*elfsym
;
2448 elfsym
= (elf_symbol_type
*) asym
;
2449 switch (elfsym
->internal_elf_sym
.st_shndx
)
2451 case SHN_MIPS_ACOMMON
:
2452 /* This section is used in a dynamically linked executable file.
2453 It is an allocated common section. The dynamic linker can
2454 either resolve these symbols to something in a shared
2455 library, or it can just leave them here. For our purposes,
2456 we can consider these symbols to be in a new section. */
2457 if (mips_elf_acom_section
.name
== NULL
)
2459 /* Initialize the acommon section. */
2460 mips_elf_acom_section
.name
= ".acommon";
2461 mips_elf_acom_section
.flags
= SEC_ALLOC
;
2462 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
2463 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
2464 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
2465 mips_elf_acom_symbol
.name
= ".acommon";
2466 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
2467 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
2468 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
2470 asym
->section
= &mips_elf_acom_section
;
2474 /* Common symbols less than the GP size are automatically
2475 treated as SHN_MIPS_SCOMMON symbols. */
2476 if (asym
->value
> elf_gp_size (abfd
))
2479 case SHN_MIPS_SCOMMON
:
2480 if (mips_elf_scom_section
.name
== NULL
)
2482 /* Initialize the small common section. */
2483 mips_elf_scom_section
.name
= ".scommon";
2484 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
2485 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
2486 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
2487 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
2488 mips_elf_scom_symbol
.name
= ".scommon";
2489 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2490 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
2491 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
2493 asym
->section
= &mips_elf_scom_section
;
2494 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2497 case SHN_MIPS_SUNDEFINED
:
2498 asym
->section
= bfd_und_section_ptr
;
2501 #if 0 /* for SGI_COMPAT */
2503 asym
->section
= mips_elf_text_section_ptr
;
2507 asym
->section
= mips_elf_data_section_ptr
;
2513 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
2517 mips_elf_additional_program_headers (abfd
)
2525 if (! SGI_COMPAT (abfd
))
2528 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2529 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2531 /* We need a PT_MIPS_REGINFO segment. */
2535 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2536 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2538 /* We need a PT_MIPS_RTPROC segment. */
2545 /* Modify the segment map for an Irix 5 executable. */
2548 mips_elf_modify_segment_map (abfd
)
2552 struct elf_segment_map
*m
, **pm
;
2554 if (! SGI_COMPAT (abfd
))
2557 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
2559 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2560 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2562 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2563 if (m
->p_type
== PT_MIPS_REGINFO
)
2567 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2571 m
->p_type
= PT_MIPS_REGINFO
;
2575 /* We want to put it after the PHDR and INTERP segments. */
2576 pm
= &elf_tdata (abfd
)->segment_map
;
2578 && ((*pm
)->p_type
== PT_PHDR
2579 || (*pm
)->p_type
== PT_INTERP
))
2587 /* If there are .dynamic and .mdebug sections, we make a room for
2588 the RTPROC header. FIXME: Rewrite without section names. */
2589 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
2590 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2591 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2593 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2594 if (m
->p_type
== PT_MIPS_RTPROC
)
2598 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2602 m
->p_type
= PT_MIPS_RTPROC
;
2604 s
= bfd_get_section_by_name (abfd
, ".rtproc");
2609 m
->p_flags_valid
= 1;
2617 /* We want to put it after the DYNAMIC segment. */
2618 pm
= &elf_tdata (abfd
)->segment_map
;
2619 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
2629 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
2630 .dynsym, and .hash sections, and everything in between. */
2631 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
2632 if ((*pm
)->p_type
== PT_DYNAMIC
)
2637 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
2639 static const char *sec_names
[] =
2640 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
2643 struct elf_segment_map
*n
;
2647 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
2649 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
2650 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2656 sz
= s
->_cooked_size
;
2659 if (high
< s
->vma
+ sz
)
2665 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2666 if ((s
->flags
& SEC_LOAD
) != 0
2669 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2673 n
= ((struct elf_segment_map
*)
2674 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
2681 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2683 if ((s
->flags
& SEC_LOAD
) != 0
2686 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2700 /* The structure of the runtime procedure descriptor created by the
2701 loader for use by the static exception system. */
2703 typedef struct runtime_pdr
{
2704 bfd_vma adr
; /* memory address of start of procedure */
2705 long regmask
; /* save register mask */
2706 long regoffset
; /* save register offset */
2707 long fregmask
; /* save floating point register mask */
2708 long fregoffset
; /* save floating point register offset */
2709 long frameoffset
; /* frame size */
2710 short framereg
; /* frame pointer register */
2711 short pcreg
; /* offset or reg of return pc */
2712 long irpss
; /* index into the runtime string table */
2714 struct exception_info
*exception_info
;/* pointer to exception array */
2716 #define cbRPDR sizeof(RPDR)
2717 #define rpdNil ((pRPDR) 0)
2719 /* Swap RPDR (runtime procedure table entry) for output. */
2721 static void ecoff_swap_rpdr_out
2722 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
2725 ecoff_swap_rpdr_out (abfd
, in
, ex
)
2728 struct rpdr_ext
*ex
;
2730 /* ecoff_put_off was defined in ecoffswap.h. */
2731 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
2732 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
2733 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
2734 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
2735 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
2736 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
2738 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
2739 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
2741 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
2743 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
2747 /* Read ECOFF debugging information from a .mdebug section into a
2748 ecoff_debug_info structure. */
2751 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
2754 struct ecoff_debug_info
*debug
;
2757 const struct ecoff_debug_swap
*swap
;
2758 char *ext_hdr
= NULL
;
2760 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2762 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
2763 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
2766 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
2767 swap
->external_hdr_size
)
2771 symhdr
= &debug
->symbolic_header
;
2772 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
2774 /* The symbolic header contains absolute file offsets and sizes to
2776 #define READ(ptr, offset, count, size, type) \
2777 if (symhdr->count == 0) \
2778 debug->ptr = NULL; \
2781 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
2782 if (debug->ptr == NULL) \
2783 goto error_return; \
2784 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
2785 || (bfd_read (debug->ptr, size, symhdr->count, \
2786 abfd) != size * symhdr->count)) \
2787 goto error_return; \
2790 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
2791 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
2792 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
2793 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
2794 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
2795 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
2797 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
2798 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
2799 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
2800 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
2801 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
2805 debug
->adjust
= NULL
;
2810 if (ext_hdr
!= NULL
)
2812 if (debug
->line
!= NULL
)
2814 if (debug
->external_dnr
!= NULL
)
2815 free (debug
->external_dnr
);
2816 if (debug
->external_pdr
!= NULL
)
2817 free (debug
->external_pdr
);
2818 if (debug
->external_sym
!= NULL
)
2819 free (debug
->external_sym
);
2820 if (debug
->external_opt
!= NULL
)
2821 free (debug
->external_opt
);
2822 if (debug
->external_aux
!= NULL
)
2823 free (debug
->external_aux
);
2824 if (debug
->ss
!= NULL
)
2826 if (debug
->ssext
!= NULL
)
2827 free (debug
->ssext
);
2828 if (debug
->external_fdr
!= NULL
)
2829 free (debug
->external_fdr
);
2830 if (debug
->external_rfd
!= NULL
)
2831 free (debug
->external_rfd
);
2832 if (debug
->external_ext
!= NULL
)
2833 free (debug
->external_ext
);
2837 /* MIPS ELF local labels start with '$', not 'L'. */
2841 mips_elf_is_local_label (abfd
, symbol
)
2845 return symbol
->name
[0] == '$';
2848 /* MIPS ELF uses a special find_nearest_line routine in order the
2849 handle the ECOFF debugging information. */
2851 struct mips_elf_find_line
2853 struct ecoff_debug_info d
;
2854 struct ecoff_find_line i
;
2858 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
2859 functionname_ptr
, line_ptr
)
2864 const char **filename_ptr
;
2865 const char **functionname_ptr
;
2866 unsigned int *line_ptr
;
2870 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
2874 struct mips_elf_find_line
*fi
;
2875 const struct ecoff_debug_swap
* const swap
=
2876 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2878 /* If we are called during a link, mips_elf_final_link may have
2879 cleared the SEC_HAS_CONTENTS field. We force it back on here
2880 if appropriate (which it normally will be). */
2881 origflags
= msec
->flags
;
2882 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
2883 msec
->flags
|= SEC_HAS_CONTENTS
;
2885 fi
= elf_tdata (abfd
)->find_line_info
;
2888 bfd_size_type external_fdr_size
;
2891 struct fdr
*fdr_ptr
;
2893 fi
= ((struct mips_elf_find_line
*)
2894 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
2897 msec
->flags
= origflags
;
2901 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
2903 msec
->flags
= origflags
;
2907 /* Swap in the FDR information. */
2908 fi
->d
.fdr
= ((struct fdr
*)
2910 (fi
->d
.symbolic_header
.ifdMax
*
2911 sizeof (struct fdr
))));
2912 if (fi
->d
.fdr
== NULL
)
2914 msec
->flags
= origflags
;
2917 external_fdr_size
= swap
->external_fdr_size
;
2918 fdr_ptr
= fi
->d
.fdr
;
2919 fraw_src
= (char *) fi
->d
.external_fdr
;
2920 fraw_end
= (fraw_src
2921 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
2922 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
2923 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
2925 elf_tdata (abfd
)->find_line_info
= fi
;
2927 /* Note that we don't bother to ever free this information.
2928 find_nearest_line is either called all the time, as in
2929 objdump -l, so the information should be saved, or it is
2930 rarely called, as in ld error messages, so the memory
2931 wasted is unimportant. Still, it would probably be a
2932 good idea for free_cached_info to throw it away. */
2935 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
2936 &fi
->i
, filename_ptr
, functionname_ptr
,
2939 msec
->flags
= origflags
;
2943 msec
->flags
= origflags
;
2946 /* Fall back on the generic ELF find_nearest_line routine. */
2948 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
2949 filename_ptr
, functionname_ptr
,
2953 /* The mips16 compiler uses a couple of special sections to handle
2954 floating point arguments.
2956 Section names that look like .mips16.fn.FNNAME contain stubs that
2957 copy floating point arguments from the fp regs to the gp regs and
2958 then jump to FNNAME. If any 32 bit function calls FNNAME, the
2959 call should be redirected to the stub instead. If no 32 bit
2960 function calls FNNAME, the stub should be discarded. We need to
2961 consider any reference to the function, not just a call, because
2962 if the address of the function is taken we will need the stub,
2963 since the address might be passed to a 32 bit function.
2965 Section names that look like .mips16.call.FNNAME contain stubs
2966 that copy floating point arguments from the gp regs to the fp
2967 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
2968 then any 16 bit function that calls FNNAME should be redirected
2969 to the stub instead. If FNNAME is not a 32 bit function, the
2970 stub should be discarded.
2972 .mips16.call.fp.FNNAME sections are similar, but contain stubs
2973 which call FNNAME and then copy the return value from the fp regs
2974 to the gp regs. These stubs store the return value in $18 while
2975 calling FNNAME; any function which might call one of these stubs
2976 must arrange to save $18 around the call. (This case is not
2977 needed for 32 bit functions that call 16 bit functions, because
2978 16 bit functions always return floating point values in both
2981 Note that in all cases FNNAME might be defined statically.
2982 Therefore, FNNAME is not used literally. Instead, the relocation
2983 information will indicate which symbol the section is for.
2985 We record any stubs that we find in the symbol table. */
2987 #define FN_STUB ".mips16.fn."
2988 #define CALL_STUB ".mips16.call."
2989 #define CALL_FP_STUB ".mips16.call.fp."
2991 /* The MIPS ELF linker needs additional information for each symbol in
2992 the global hash table. */
2994 struct mips_elf_link_hash_entry
2996 struct elf_link_hash_entry root
;
2998 /* External symbol information. */
3001 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
3002 unsigned int mips_32_relocs
;
3004 /* If there is a stub that 32 bit functions should use to call this
3005 16 bit function, this points to the section containing the stub. */
3008 /* Whether we need the fn_stub; this is set if this symbol appears
3009 in any relocs other than a 16 bit call. */
3010 boolean need_fn_stub
;
3012 /* If there is a stub that 16 bit functions should use to call this
3013 32 bit function, this points to the section containing the stub. */
3014 asection
*call_stub
;
3016 /* This is like the call_stub field, but it is used if the function
3017 being called returns a floating point value. */
3018 asection
*call_fp_stub
;
3021 /* MIPS ELF linker hash table. */
3023 struct mips_elf_link_hash_table
3025 struct elf_link_hash_table root
;
3026 /* String section indices for the dynamic section symbols. */
3027 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
3028 /* The number of .rtproc entries. */
3029 bfd_size_type procedure_count
;
3030 /* The size of the .compact_rel section (if SGI_COMPAT). */
3031 bfd_size_type compact_rel_size
;
3032 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3033 entry is set to the address of __rld_obj_head as in Irix 5. */
3034 boolean use_rld_obj_head
;
3035 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3037 /* This is set if we see any mips16 stub sections. */
3038 boolean mips16_stubs_seen
;
3041 /* Look up an entry in a MIPS ELF linker hash table. */
3043 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3044 ((struct mips_elf_link_hash_entry *) \
3045 elf_link_hash_lookup (&(table)->root, (string), (create), \
3048 /* Traverse a MIPS ELF linker hash table. */
3050 #define mips_elf_link_hash_traverse(table, func, info) \
3051 (elf_link_hash_traverse \
3053 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3056 /* Get the MIPS ELF linker hash table from a link_info structure. */
3058 #define mips_elf_hash_table(p) \
3059 ((struct mips_elf_link_hash_table *) ((p)->hash))
3061 static boolean mips_elf_output_extsym
3062 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3064 /* Create an entry in a MIPS ELF linker hash table. */
3066 static struct bfd_hash_entry
*
3067 mips_elf_link_hash_newfunc (entry
, table
, string
)
3068 struct bfd_hash_entry
*entry
;
3069 struct bfd_hash_table
*table
;
3072 struct mips_elf_link_hash_entry
*ret
=
3073 (struct mips_elf_link_hash_entry
*) entry
;
3075 /* Allocate the structure if it has not already been allocated by a
3077 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3078 ret
= ((struct mips_elf_link_hash_entry
*)
3079 bfd_hash_allocate (table
,
3080 sizeof (struct mips_elf_link_hash_entry
)));
3081 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3082 return (struct bfd_hash_entry
*) ret
;
3084 /* Call the allocation method of the superclass. */
3085 ret
= ((struct mips_elf_link_hash_entry
*)
3086 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3088 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3090 /* Set local fields. */
3091 memset (&ret
->esym
, 0, sizeof (EXTR
));
3092 /* We use -2 as a marker to indicate that the information has
3093 not been set. -1 means there is no associated ifd. */
3095 ret
->mips_32_relocs
= 0;
3096 ret
->fn_stub
= NULL
;
3097 ret
->need_fn_stub
= false;
3098 ret
->call_stub
= NULL
;
3099 ret
->call_fp_stub
= NULL
;
3102 return (struct bfd_hash_entry
*) ret
;
3105 /* Create a MIPS ELF linker hash table. */
3107 static struct bfd_link_hash_table
*
3108 mips_elf_link_hash_table_create (abfd
)
3111 struct mips_elf_link_hash_table
*ret
;
3114 ret
= ((struct mips_elf_link_hash_table
*)
3115 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
3116 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
3119 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3120 mips_elf_link_hash_newfunc
))
3122 bfd_release (abfd
, ret
);
3126 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
3127 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
3128 ret
->procedure_count
= 0;
3129 ret
->compact_rel_size
= 0;
3130 ret
->use_rld_obj_head
= false;
3132 ret
->mips16_stubs_seen
= false;
3134 return &ret
->root
.root
;
3137 /* Hook called by the linker routine which adds symbols from an object
3138 file. We must handle the special MIPS section numbers here. */
3142 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3144 struct bfd_link_info
*info
;
3145 const Elf_Internal_Sym
*sym
;
3151 if (SGI_COMPAT (abfd
)
3152 && (abfd
->flags
& DYNAMIC
) != 0
3153 && strcmp (*namep
, "_rld_new_interface") == 0)
3155 /* Skip Irix 5 rld entry name. */
3160 switch (sym
->st_shndx
)
3163 /* Common symbols less than the GP size are automatically
3164 treated as SHN_MIPS_SCOMMON symbols. */
3165 if (sym
->st_size
> elf_gp_size (abfd
))
3168 case SHN_MIPS_SCOMMON
:
3169 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3170 (*secp
)->flags
|= SEC_IS_COMMON
;
3171 *valp
= sym
->st_size
;
3175 /* This section is used in a shared object. */
3176 if (mips_elf_text_section_ptr
== NULL
)
3178 /* Initialize the section. */
3179 mips_elf_text_section
.name
= ".text";
3180 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
3181 mips_elf_text_section
.output_section
= NULL
;
3182 mips_elf_text_section
.owner
= abfd
;
3183 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
3184 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
3185 mips_elf_text_symbol
.name
= ".text";
3186 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
3187 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
3188 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
3189 mips_elf_text_section_ptr
= &mips_elf_text_section
;
3192 *secp
= bfd_und_section_ptr
;
3194 *secp
= mips_elf_text_section_ptr
;
3197 case SHN_MIPS_ACOMMON
:
3198 /* Fall through. XXX Can we treat this as allocated data? */
3200 /* This section is used in a shared object. */
3201 if (mips_elf_data_section_ptr
== NULL
)
3203 /* Initialize the section. */
3204 mips_elf_data_section
.name
= ".data";
3205 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
3206 mips_elf_data_section
.output_section
= NULL
;
3207 mips_elf_data_section
.owner
= abfd
;
3208 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
3209 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
3210 mips_elf_data_symbol
.name
= ".data";
3211 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
3212 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
3213 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
3214 mips_elf_data_section_ptr
= &mips_elf_data_section
;
3217 *secp
= bfd_und_section_ptr
;
3219 *secp
= mips_elf_data_section_ptr
;
3222 case SHN_MIPS_SUNDEFINED
:
3223 *secp
= bfd_und_section_ptr
;
3227 if (SGI_COMPAT (abfd
)
3229 && info
->hash
->creator
== abfd
->xvec
3230 && strcmp (*namep
, "__rld_obj_head") == 0)
3232 struct elf_link_hash_entry
*h
;
3234 /* Mark __rld_obj_head as dynamic. */
3236 if (! (_bfd_generic_link_add_one_symbol
3237 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3238 (bfd_vma
) *valp
, (const char *) NULL
, false,
3239 get_elf_backend_data (abfd
)->collect
,
3240 (struct bfd_link_hash_entry
**) &h
)))
3242 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
3243 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3244 h
->type
= STT_OBJECT
;
3246 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3249 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3252 /* If this is a mips16 text symbol, add 1 to the value to make it
3253 odd. This will cause something like .word SYM to come up with
3254 the right value when it is loaded into the PC. */
3255 if (sym
->st_other
== STO_MIPS16
)
3261 /* Structure used to pass information to mips_elf_output_extsym. */
3266 struct bfd_link_info
*info
;
3267 struct ecoff_debug_info
*debug
;
3268 const struct ecoff_debug_swap
*swap
;
3272 /* This routine is used to write out ECOFF debugging external symbol
3273 information. It is called via mips_elf_link_hash_traverse. The
3274 ECOFF external symbol information must match the ELF external
3275 symbol information. Unfortunately, at this point we don't know
3276 whether a symbol is required by reloc information, so the two
3277 tables may wind up being different. We must sort out the external
3278 symbol information before we can set the final size of the .mdebug
3279 section, and we must set the size of the .mdebug section before we
3280 can relocate any sections, and we can't know which symbols are
3281 required by relocation until we relocate the sections.
3282 Fortunately, it is relatively unlikely that any symbol will be
3283 stripped but required by a reloc. In particular, it can not happen
3284 when generating a final executable. */
3287 mips_elf_output_extsym (h
, data
)
3288 struct mips_elf_link_hash_entry
*h
;
3291 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
3293 asection
*sec
, *output_section
;
3295 if (h
->root
.indx
== -2)
3297 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3298 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
3299 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3300 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
3302 else if (einfo
->info
->strip
== strip_all
3303 || (einfo
->info
->strip
== strip_some
3304 && bfd_hash_lookup (einfo
->info
->keep_hash
,
3305 h
->root
.root
.root
.string
,
3306 false, false) == NULL
))
3314 if (h
->esym
.ifd
== -2)
3317 h
->esym
.cobol_main
= 0;
3318 h
->esym
.weakext
= 0;
3319 h
->esym
.reserved
= 0;
3320 h
->esym
.ifd
= ifdNil
;
3321 h
->esym
.asym
.value
= 0;
3322 h
->esym
.asym
.st
= stGlobal
;
3324 if (SGI_COMPAT (einfo
->abfd
)
3325 && (h
->root
.root
.type
== bfd_link_hash_undefined
3326 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
3330 /* Use undefined class. Also, set class and type for some
3332 name
= h
->root
.root
.root
.string
;
3333 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
3334 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
3336 h
->esym
.asym
.sc
= scData
;
3337 h
->esym
.asym
.st
= stLabel
;
3338 h
->esym
.asym
.value
= 0;
3340 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
3342 h
->esym
.asym
.sc
= scAbs
;
3343 h
->esym
.asym
.st
= stLabel
;
3344 h
->esym
.asym
.value
=
3345 mips_elf_hash_table (einfo
->info
)->procedure_count
;
3347 else if (strcmp (name
, "_gp_disp") == 0)
3349 h
->esym
.asym
.sc
= scAbs
;
3350 h
->esym
.asym
.st
= stLabel
;
3351 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
3354 h
->esym
.asym
.sc
= scUndefined
;
3356 else if (h
->root
.root
.type
!= bfd_link_hash_defined
3357 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
3358 h
->esym
.asym
.sc
= scAbs
;
3363 sec
= h
->root
.root
.u
.def
.section
;
3364 output_section
= sec
->output_section
;
3366 /* When making a shared library and symbol h is the one from
3367 the another shared library, OUTPUT_SECTION may be null. */
3368 if (output_section
== NULL
)
3369 h
->esym
.asym
.sc
= scUndefined
;
3372 name
= bfd_section_name (output_section
->owner
, output_section
);
3374 if (strcmp (name
, ".text") == 0)
3375 h
->esym
.asym
.sc
= scText
;
3376 else if (strcmp (name
, ".data") == 0)
3377 h
->esym
.asym
.sc
= scData
;
3378 else if (strcmp (name
, ".sdata") == 0)
3379 h
->esym
.asym
.sc
= scSData
;
3380 else if (strcmp (name
, ".rodata") == 0
3381 || strcmp (name
, ".rdata") == 0)
3382 h
->esym
.asym
.sc
= scRData
;
3383 else if (strcmp (name
, ".bss") == 0)
3384 h
->esym
.asym
.sc
= scBss
;
3385 else if (strcmp (name
, ".sbss") == 0)
3386 h
->esym
.asym
.sc
= scSBss
;
3387 else if (strcmp (name
, ".init") == 0)
3388 h
->esym
.asym
.sc
= scInit
;
3389 else if (strcmp (name
, ".fini") == 0)
3390 h
->esym
.asym
.sc
= scFini
;
3392 h
->esym
.asym
.sc
= scAbs
;
3396 h
->esym
.asym
.reserved
= 0;
3397 h
->esym
.asym
.index
= indexNil
;
3400 if (h
->root
.root
.type
== bfd_link_hash_common
)
3401 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
3402 else if (h
->root
.root
.type
== bfd_link_hash_defined
3403 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3405 if (h
->esym
.asym
.sc
== scCommon
)
3406 h
->esym
.asym
.sc
= scBss
;
3407 else if (h
->esym
.asym
.sc
== scSCommon
)
3408 h
->esym
.asym
.sc
= scSBss
;
3410 sec
= h
->root
.root
.u
.def
.section
;
3411 output_section
= sec
->output_section
;
3412 if (output_section
!= NULL
)
3413 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
3414 + sec
->output_offset
3415 + output_section
->vma
);
3417 h
->esym
.asym
.value
= 0;
3419 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3421 /* Set type and value for a symbol with a function stub. */
3422 h
->esym
.asym
.st
= stProc
;
3423 sec
= h
->root
.root
.u
.def
.section
;
3425 h
->esym
.asym
.value
= 0;
3428 output_section
= sec
->output_section
;
3429 if (output_section
!= NULL
)
3430 h
->esym
.asym
.value
= (h
->root
.plt_offset
3431 + sec
->output_offset
3432 + output_section
->vma
);
3434 h
->esym
.asym
.value
= 0;
3441 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
3442 h
->root
.root
.root
.string
,
3445 einfo
->failed
= true;
3452 /* Create a runtime procedure table from the .mdebug section. */
3455 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
3458 struct bfd_link_info
*info
;
3460 struct ecoff_debug_info
*debug
;
3462 const struct ecoff_debug_swap
*swap
;
3463 HDRR
*hdr
= &debug
->symbolic_header
;
3465 struct rpdr_ext
*erp
;
3467 struct pdr_ext
*epdr
;
3468 struct sym_ext
*esym
;
3471 unsigned long size
, count
;
3472 unsigned long sindex
;
3476 const char *no_name_func
= "static procedure (no name)";
3484 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3486 sindex
= strlen (no_name_func
) + 1;
3487 count
= hdr
->ipdMax
;
3490 size
= swap
->external_pdr_size
;
3492 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
3496 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
3499 size
= sizeof (RPDR
);
3500 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
3504 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
3508 count
= hdr
->isymMax
;
3509 size
= swap
->external_sym_size
;
3510 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
3514 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
3517 count
= hdr
->issMax
;
3518 ss
= (char *) bfd_malloc (count
);
3521 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
3524 count
= hdr
->ipdMax
;
3525 for (i
= 0; i
< count
; i
++, rp
++)
3527 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
3528 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
3529 rp
->adr
= sym
.value
;
3530 rp
->regmask
= pdr
.regmask
;
3531 rp
->regoffset
= pdr
.regoffset
;
3532 rp
->fregmask
= pdr
.fregmask
;
3533 rp
->fregoffset
= pdr
.fregoffset
;
3534 rp
->frameoffset
= pdr
.frameoffset
;
3535 rp
->framereg
= pdr
.framereg
;
3536 rp
->pcreg
= pdr
.pcreg
;
3538 sv
[i
] = ss
+ sym
.iss
;
3539 sindex
+= strlen (sv
[i
]) + 1;
3543 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
3544 size
= BFD_ALIGN (size
, 16);
3545 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
3548 mips_elf_hash_table (info
)->procedure_count
= 0;
3552 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
3554 erp
= (struct rpdr_ext
*) rtproc
;
3555 memset (erp
, 0, sizeof (struct rpdr_ext
));
3557 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
3558 strcpy (str
, no_name_func
);
3559 str
+= strlen (no_name_func
) + 1;
3560 for (i
= 0; i
< count
; i
++)
3562 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
3563 strcpy (str
, sv
[i
]);
3564 str
+= strlen (sv
[i
]) + 1;
3566 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
3568 /* Set the size and contents of .rtproc section. */
3569 s
->_raw_size
= size
;
3570 s
->contents
= rtproc
;
3572 /* Skip this section later on (I don't think this currently
3573 matters, but someday it might). */
3574 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
3603 /* A comparison routine used to sort .gptab entries. */
3606 gptab_compare (p1
, p2
)
3610 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
3611 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
3613 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
3616 /* We need to use a special link routine to handle the .reginfo and
3617 the .mdebug sections. We need to merge all instances of these
3618 sections together, not write them all out sequentially. */
3621 mips_elf_final_link (abfd
, info
)
3623 struct bfd_link_info
*info
;
3627 struct bfd_link_order
*p
;
3628 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
3629 asection
*rtproc_sec
;
3630 Elf32_RegInfo reginfo
;
3631 struct ecoff_debug_info debug
;
3632 const struct ecoff_debug_swap
*swap
3633 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3634 HDRR
*symhdr
= &debug
.symbolic_header
;
3635 PTR mdebug_handle
= NULL
;
3637 /* Drop the .options section, since it has special semantics which I
3638 haven't bothered to figure out. */
3639 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
3641 if (strcmp ((*secpp
)->name
, ".options") == 0)
3643 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
3644 if (p
->type
== bfd_indirect_link_order
)
3645 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
3646 (*secpp
)->link_order_head
= NULL
;
3647 *secpp
= (*secpp
)->next
;
3648 --abfd
->section_count
;
3653 /* Get a value for the GP register. */
3654 if (elf_gp (abfd
) == 0)
3656 struct bfd_link_hash_entry
*h
;
3658 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
3659 if (h
!= (struct bfd_link_hash_entry
*) NULL
3660 && h
->type
== bfd_link_hash_defined
)
3661 elf_gp (abfd
) = (h
->u
.def
.value
3662 + h
->u
.def
.section
->output_section
->vma
3663 + h
->u
.def
.section
->output_offset
);
3664 else if (info
->relocateable
)
3668 /* Make up a value. */
3670 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3673 && (strcmp (o
->name
, ".sbss") == 0
3674 || strcmp (o
->name
, ".sdata") == 0
3675 || strcmp (o
->name
, ".lit4") == 0
3676 || strcmp (o
->name
, ".lit8") == 0))
3679 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
3683 /* If the relocate_section function needs to do a reloc
3684 involving the GP value, it should make a reloc_dangerous
3685 callback to warn that GP is not defined. */
3689 /* Go through the sections and collect the .reginfo and .mdebug
3693 gptab_data_sec
= NULL
;
3694 gptab_bss_sec
= NULL
;
3695 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3697 if (strcmp (o
->name
, ".reginfo") == 0)
3699 memset (®info
, 0, sizeof reginfo
);
3701 /* We have found the .reginfo section in the output file.
3702 Look through all the link_orders comprising it and merge
3703 the information together. */
3704 for (p
= o
->link_order_head
;
3705 p
!= (struct bfd_link_order
*) NULL
;
3708 asection
*input_section
;
3710 Elf32_External_RegInfo ext
;
3713 if (p
->type
!= bfd_indirect_link_order
)
3715 if (p
->type
== bfd_fill_link_order
)
3720 input_section
= p
->u
.indirect
.section
;
3721 input_bfd
= input_section
->owner
;
3723 /* The linker emulation code has probably clobbered the
3724 size to be zero bytes. */
3725 if (input_section
->_raw_size
== 0)
3726 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3728 if (! bfd_get_section_contents (input_bfd
, input_section
,
3734 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
3736 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
3737 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
3738 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
3739 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
3740 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
3742 /* ri_gp_value is set by the function
3743 mips_elf32_section_processing when the section is
3744 finally written out. */
3746 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3747 elf_link_input_bfd ignores this section. */
3748 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3751 /* Force the section size to the value we want. */
3752 o
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3754 /* Skip this section later on (I don't think this currently
3755 matters, but someday it might). */
3756 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3761 if (strcmp (o
->name
, ".mdebug") == 0)
3763 struct extsym_info einfo
;
3765 /* We have found the .mdebug section in the output file.
3766 Look through all the link_orders comprising it and merge
3767 the information together. */
3768 symhdr
->magic
= swap
->sym_magic
;
3769 /* FIXME: What should the version stamp be? */
3771 symhdr
->ilineMax
= 0;
3775 symhdr
->isymMax
= 0;
3776 symhdr
->ioptMax
= 0;
3777 symhdr
->iauxMax
= 0;
3779 symhdr
->issExtMax
= 0;
3782 symhdr
->iextMax
= 0;
3784 /* We accumulate the debugging information itself in the
3785 debug_info structure. */
3787 debug
.external_dnr
= NULL
;
3788 debug
.external_pdr
= NULL
;
3789 debug
.external_sym
= NULL
;
3790 debug
.external_opt
= NULL
;
3791 debug
.external_aux
= NULL
;
3793 debug
.ssext
= debug
.ssext_end
= NULL
;
3794 debug
.external_fdr
= NULL
;
3795 debug
.external_rfd
= NULL
;
3796 debug
.external_ext
= debug
.external_ext_end
= NULL
;
3798 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
3799 if (mdebug_handle
== (PTR
) NULL
)
3802 if (SGI_COMPAT (abfd
))
3808 static const char * const name
[] =
3809 { ".text", ".init", ".fini", ".data",
3810 ".rodata", ".sdata", ".sbss", ".bss" };
3811 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
3812 scRData
, scSData
, scSBss
, scBss
};
3815 esym
.cobol_main
= 0;
3819 esym
.asym
.iss
= issNil
;
3820 esym
.asym
.st
= stLocal
;
3821 esym
.asym
.reserved
= 0;
3822 esym
.asym
.index
= indexNil
;
3823 for (i
= 0; i
< 8; i
++)
3825 esym
.asym
.sc
= sc
[i
];
3826 s
= bfd_get_section_by_name (abfd
, name
[i
]);
3829 esym
.asym
.value
= s
->vma
;
3830 last
= s
->vma
+ s
->_raw_size
;
3833 esym
.asym
.value
= last
;
3835 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
3841 for (p
= o
->link_order_head
;
3842 p
!= (struct bfd_link_order
*) NULL
;
3845 asection
*input_section
;
3847 const struct ecoff_debug_swap
*input_swap
;
3848 struct ecoff_debug_info input_debug
;
3852 if (p
->type
!= bfd_indirect_link_order
)
3854 if (p
->type
== bfd_fill_link_order
)
3859 input_section
= p
->u
.indirect
.section
;
3860 input_bfd
= input_section
->owner
;
3862 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
3863 || (get_elf_backend_data (input_bfd
)
3864 ->elf_backend_ecoff_debug_swap
) == NULL
)
3866 /* I don't know what a non MIPS ELF bfd would be
3867 doing with a .mdebug section, but I don't really
3868 want to deal with it. */
3872 input_swap
= (get_elf_backend_data (input_bfd
)
3873 ->elf_backend_ecoff_debug_swap
);
3875 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
3877 /* The ECOFF linking code expects that we have already
3878 read in the debugging information and set up an
3879 ecoff_debug_info structure, so we do that now. */
3880 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
3884 if (! (bfd_ecoff_debug_accumulate
3885 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
3886 &input_debug
, input_swap
, info
)))
3889 /* Loop through the external symbols. For each one with
3890 interesting information, try to find the symbol in
3891 the linker global hash table and save the information
3892 for the output external symbols. */
3893 eraw_src
= input_debug
.external_ext
;
3894 eraw_end
= (eraw_src
3895 + (input_debug
.symbolic_header
.iextMax
3896 * input_swap
->external_ext_size
));
3898 eraw_src
< eraw_end
;
3899 eraw_src
+= input_swap
->external_ext_size
)
3903 struct mips_elf_link_hash_entry
*h
;
3905 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
3906 if (ext
.asym
.sc
== scNil
3907 || ext
.asym
.sc
== scUndefined
3908 || ext
.asym
.sc
== scSUndefined
)
3911 name
= input_debug
.ssext
+ ext
.asym
.iss
;
3912 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
3913 name
, false, false, true);
3914 if (h
== NULL
|| h
->esym
.ifd
!= -2)
3920 < input_debug
.symbolic_header
.ifdMax
);
3921 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
3927 /* Free up the information we just read. */
3928 free (input_debug
.line
);
3929 free (input_debug
.external_dnr
);
3930 free (input_debug
.external_pdr
);
3931 free (input_debug
.external_sym
);
3932 free (input_debug
.external_opt
);
3933 free (input_debug
.external_aux
);
3934 free (input_debug
.ss
);
3935 free (input_debug
.ssext
);
3936 free (input_debug
.external_fdr
);
3937 free (input_debug
.external_rfd
);
3938 free (input_debug
.external_ext
);
3940 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3941 elf_link_input_bfd ignores this section. */
3942 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3945 if (SGI_COMPAT (abfd
) && info
->shared
)
3947 /* Create .rtproc section. */
3948 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
3949 if (rtproc_sec
== NULL
)
3951 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3952 | SEC_LINKER_CREATED
| SEC_READONLY
);
3954 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
3955 if (rtproc_sec
== NULL
3956 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
3957 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 12))
3961 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
3962 info
, rtproc_sec
, &debug
))
3966 /* Build the external symbol information. */
3969 einfo
.debug
= &debug
;
3971 einfo
.failed
= false;
3972 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
3973 mips_elf_output_extsym
,
3978 /* Set the size of the .mdebug section. */
3979 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
3981 /* Skip this section later on (I don't think this currently
3982 matters, but someday it might). */
3983 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3988 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
3990 const char *subname
;
3993 Elf32_External_gptab
*ext_tab
;
3996 /* The .gptab.sdata and .gptab.sbss sections hold
3997 information describing how the small data area would
3998 change depending upon the -G switch. These sections
3999 not used in executables files. */
4000 if (! info
->relocateable
)
4004 for (p
= o
->link_order_head
;
4005 p
!= (struct bfd_link_order
*) NULL
;
4008 asection
*input_section
;
4010 if (p
->type
!= bfd_indirect_link_order
)
4012 if (p
->type
== bfd_fill_link_order
)
4017 input_section
= p
->u
.indirect
.section
;
4019 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4020 elf_link_input_bfd ignores this section. */
4021 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4024 /* Skip this section later on (I don't think this
4025 currently matters, but someday it might). */
4026 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4028 /* Really remove the section. */
4029 for (secpp
= &abfd
->sections
;
4031 secpp
= &(*secpp
)->next
)
4033 *secpp
= (*secpp
)->next
;
4034 --abfd
->section_count
;
4039 /* There is one gptab for initialized data, and one for
4040 uninitialized data. */
4041 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4043 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4047 (*_bfd_error_handler
)
4048 ("%s: illegal section name `%s'",
4049 bfd_get_filename (abfd
), o
->name
);
4050 bfd_set_error (bfd_error_nonrepresentable_section
);
4054 /* The linker script always combines .gptab.data and
4055 .gptab.sdata into .gptab.sdata, and likewise for
4056 .gptab.bss and .gptab.sbss. It is possible that there is
4057 no .sdata or .sbss section in the output file, in which
4058 case we must change the name of the output section. */
4059 subname
= o
->name
+ sizeof ".gptab" - 1;
4060 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4062 if (o
== gptab_data_sec
)
4063 o
->name
= ".gptab.data";
4065 o
->name
= ".gptab.bss";
4066 subname
= o
->name
+ sizeof ".gptab" - 1;
4067 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4070 /* Set up the first entry. */
4072 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
4075 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4076 tab
[0].gt_header
.gt_unused
= 0;
4078 /* Combine the input sections. */
4079 for (p
= o
->link_order_head
;
4080 p
!= (struct bfd_link_order
*) NULL
;
4083 asection
*input_section
;
4087 bfd_size_type gpentry
;
4089 if (p
->type
!= bfd_indirect_link_order
)
4091 if (p
->type
== bfd_fill_link_order
)
4096 input_section
= p
->u
.indirect
.section
;
4097 input_bfd
= input_section
->owner
;
4099 /* Combine the gptab entries for this input section one
4100 by one. We know that the input gptab entries are
4101 sorted by ascending -G value. */
4102 size
= bfd_section_size (input_bfd
, input_section
);
4104 for (gpentry
= sizeof (Elf32_External_gptab
);
4106 gpentry
+= sizeof (Elf32_External_gptab
))
4108 Elf32_External_gptab ext_gptab
;
4109 Elf32_gptab int_gptab
;
4115 if (! (bfd_get_section_contents
4116 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4117 gpentry
, sizeof (Elf32_External_gptab
))))
4123 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
4125 val
= int_gptab
.gt_entry
.gt_g_value
;
4126 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4129 for (look
= 1; look
< c
; look
++)
4131 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4132 tab
[look
].gt_entry
.gt_bytes
+= add
;
4134 if (tab
[look
].gt_entry
.gt_g_value
== val
)
4140 Elf32_gptab
*new_tab
;
4143 /* We need a new table entry. */
4144 new_tab
= ((Elf32_gptab
*)
4145 bfd_realloc ((PTR
) tab
,
4146 (c
+ 1) * sizeof (Elf32_gptab
)));
4147 if (new_tab
== NULL
)
4153 tab
[c
].gt_entry
.gt_g_value
= val
;
4154 tab
[c
].gt_entry
.gt_bytes
= add
;
4156 /* Merge in the size for the next smallest -G
4157 value, since that will be implied by this new
4160 for (look
= 1; look
< c
; look
++)
4162 if (tab
[look
].gt_entry
.gt_g_value
< val
4164 || (tab
[look
].gt_entry
.gt_g_value
4165 > tab
[max
].gt_entry
.gt_g_value
)))
4169 tab
[c
].gt_entry
.gt_bytes
+=
4170 tab
[max
].gt_entry
.gt_bytes
;
4175 last
= int_gptab
.gt_entry
.gt_bytes
;
4178 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4179 elf_link_input_bfd ignores this section. */
4180 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4183 /* The table must be sorted by -G value. */
4185 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
4187 /* Swap out the table. */
4188 ext_tab
= ((Elf32_External_gptab
*)
4189 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
4190 if (ext_tab
== NULL
)
4196 for (i
= 0; i
< c
; i
++)
4197 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
4200 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
4201 o
->contents
= (bfd_byte
*) ext_tab
;
4203 /* Skip this section later on (I don't think this currently
4204 matters, but someday it might). */
4205 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4209 /* Invoke the regular ELF backend linker to do all the work. */
4210 if (! bfd_elf32_bfd_final_link (abfd
, info
))
4213 /* Now write out the computed sections. */
4215 if (reginfo_sec
!= (asection
*) NULL
)
4217 Elf32_External_RegInfo ext
;
4219 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
4220 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4221 (file_ptr
) 0, sizeof ext
))
4225 if (mdebug_sec
!= (asection
*) NULL
)
4227 BFD_ASSERT (abfd
->output_has_begun
);
4228 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4230 mdebug_sec
->filepos
))
4233 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4236 if (gptab_data_sec
!= (asection
*) NULL
)
4238 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4239 gptab_data_sec
->contents
,
4241 gptab_data_sec
->_raw_size
))
4245 if (gptab_bss_sec
!= (asection
*) NULL
)
4247 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4248 gptab_bss_sec
->contents
,
4250 gptab_bss_sec
->_raw_size
))
4254 if (SGI_COMPAT (abfd
))
4256 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4257 if (rtproc_sec
!= NULL
)
4259 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
4260 rtproc_sec
->contents
,
4262 rtproc_sec
->_raw_size
))
4270 /* Handle a MIPS ELF HI16 reloc. */
4273 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
4275 Elf_Internal_Rela
*relhi
;
4276 Elf_Internal_Rela
*rello
;
4283 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4285 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4288 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4290 if ((addlo
& 0x8000) != 0)
4292 if ((addend
& 0x8000) != 0)
4295 bfd_put_32 (input_bfd
,
4296 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
4297 contents
+ relhi
->r_offset
);
4300 /* Handle a MIPS ELF local GOT16 reloc. */
4303 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
4308 Elf_Internal_Rela
*relhi
;
4309 Elf_Internal_Rela
*rello
;
4319 bfd_byte
*got_contents
;
4320 struct mips_got_info
*g
;
4322 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4324 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4327 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4329 if ((addlo
& 0x8000) != 0)
4331 if ((addend
& 0x8000) != 0)
4334 /* Get a got entry representing requested hipage. */
4335 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4336 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4337 BFD_ASSERT (g
!= NULL
);
4339 local_gotno
= g
->local_gotno
;
4340 got_contents
= sgot
->contents
;
4341 hipage
= addend
& 0xffff0000;
4343 for (i
= MIPS_RESERVED_GOTNO
; i
< local_gotno
; i
++)
4345 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
4346 if (hipage
== (address
& 0xffff0000))
4348 if (address
== (bfd_vma
) 0)
4350 bfd_put_32 (input_bfd
, hipage
, got_contents
+ i
* 4);
4355 BFD_ASSERT (i
< local_gotno
);
4357 if (i
== local_gotno
)
4358 (*_bfd_error_handler
)
4359 ("ELF MIPS linker: more got entries are needed for hipage: %x",
4363 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
4364 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
4365 contents
+ relhi
->r_offset
);
4368 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
4371 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
4373 Elf_Internal_Rela
*rel
;
4379 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4380 bfd_put_32 (input_bfd
,
4381 (insn
& 0xffff0000) | (offset
& 0xffff),
4382 contents
+ rel
->r_offset
);
4385 /* Relocate a MIPS ELF section. */
4388 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4389 contents
, relocs
, local_syms
, local_sections
)
4391 struct bfd_link_info
*info
;
4393 asection
*input_section
;
4395 Elf_Internal_Rela
*relocs
;
4396 Elf_Internal_Sym
*local_syms
;
4397 asection
**local_sections
;
4399 Elf_Internal_Shdr
*symtab_hdr
;
4402 asection
*sgot
, *sreloc
, *scpt
;
4405 Elf_Internal_Rela
*rel
;
4406 Elf_Internal_Rela
*relend
;
4407 struct mips_got_info
*g
;
4409 dynobj
= elf_hash_table (info
)->dynobj
;
4410 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4414 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
4417 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
4420 if (elf_bad_symtab (input_bfd
))
4422 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
4427 locsymcount
= symtab_hdr
->sh_info
;
4428 extsymoff
= symtab_hdr
->sh_info
;
4431 gp
= _bfd_get_gp_value (output_bfd
);
4434 relend
= relocs
+ input_section
->reloc_count
;
4435 for (; rel
< relend
; rel
++)
4438 reloc_howto_type
*howto
;
4439 unsigned long r_symndx
;
4441 struct elf_link_hash_entry
*h
;
4443 Elf_Internal_Sym
*sym
;
4444 struct mips_elf_link_hash_entry
*mh
;
4446 bfd_reloc_status_type r
;
4448 r_type
= ELF32_R_TYPE (rel
->r_info
);
4449 if ((r_type
< 0 || r_type
>= (int) R_MIPS_max
) && r_type
!= R_MIPS16_26
)
4451 bfd_set_error (bfd_error_bad_value
);
4454 if (r_type
!= R_MIPS16_26
)
4455 howto
= elf_mips_howto_table
+ r_type
;
4457 howto
= &elf_mips16_jump_howto
;
4460 && (r_type
== R_MIPS_CALL16
4461 || r_type
== R_MIPS_GOT16
4462 || r_type
== R_MIPS_CALL_HI16
4463 || r_type
== R_MIPS_CALL_LO16
4464 || r_type
== R_MIPS_GOT_HI16
4465 || r_type
== R_MIPS_GOT_LO16
))
4467 /* We need the .got section. */
4470 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4471 BFD_ASSERT (sgot
!= NULL
);
4472 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4473 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4474 BFD_ASSERT (g
!= NULL
);
4478 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4480 /* Mix in the change in GP address for a GP relative reloc. */
4481 if (r_type
!= R_MIPS_GPREL16
4482 && r_type
!= R_MIPS_LITERAL
4483 && r_type
!= R_MIPS_GPREL32
)
4489 if (! ((*info
->callbacks
->reloc_dangerous
)
4491 "GP relative relocation when GP not defined",
4492 input_bfd
, input_section
,
4495 /* Only give the error once per link. */
4497 _bfd_set_gp_value (output_bfd
, gp
);
4500 if (r_symndx
< extsymoff
4501 || (elf_bad_symtab (input_bfd
)
4502 && local_sections
[r_symndx
] != NULL
))
4504 /* This is a relocation against a section. The current
4505 addend in the instruction is the difference between
4506 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
4507 must change this to be the difference between the
4508 final definition (which will end up in RELOCATION)
4509 and the GP value of OUTPUT_BFD (which is in GP). */
4510 addend
= elf_gp (input_bfd
) - gp
;
4512 else if (! info
->relocateable
)
4514 /* We are doing a final link. The current addend in the
4515 instruction is simply the desired offset into the
4516 symbol (normally zero). We want the instruction to
4517 hold the difference between the final definition of
4518 the symbol (which will end up in RELOCATION) and the
4519 GP value of OUTPUT_BFD (which is in GP). */
4524 /* We are generating relocateable output, and we aren't
4525 going to define this symbol, so we just leave the
4526 instruction alone. */
4534 if (info
->relocateable
)
4536 /* This is a relocateable link. We don't have to change
4537 anything, unless the reloc is against a section symbol,
4538 in which case we have to adjust according to where the
4539 section symbol winds up in the output section. */
4540 if (r_symndx
>= locsymcount
4541 || (elf_bad_symtab (input_bfd
)
4542 && local_sections
[r_symndx
] == NULL
))
4546 sym
= local_syms
+ r_symndx
;
4547 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4551 sec
= local_sections
[r_symndx
];
4553 /* It would be logical to add sym->st_value here,
4554 but Irix 5 sometimes generates a garbage symbol
4556 addend
+= sec
->output_offset
;
4558 /* If this is HI16 or GOT16 with an associated LO16,
4559 adjust the addend accordingly. Otherwise, just
4561 if (r_type
== R_MIPS_64
&& bfd_big_endian (input_bfd
))
4562 r
= _bfd_relocate_contents (howto
, input_bfd
,
4564 contents
+ rel
->r_offset
+ 4);
4565 else if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
4566 r
= _bfd_relocate_contents (howto
, input_bfd
,
4568 contents
+ rel
->r_offset
);
4571 Elf_Internal_Rela
*lorel
;
4573 /* As a GNU extension, permit an arbitrary
4574 number of R_MIPS_HI16 relocs before the
4575 R_MIPS_LO16 reloc. This permits gcc to emit
4576 the HI and LO relocs itself. */
4577 if (r_type
== R_MIPS_GOT16
)
4581 for (lorel
= rel
+ 1;
4583 && (ELF32_R_TYPE (lorel
->r_info
)
4589 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
4591 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
4596 r
= _bfd_relocate_contents (howto
, input_bfd
,
4598 contents
+ rel
->r_offset
);
4608 /* This is a final link. */
4610 if (r_symndx
< extsymoff
4611 || (elf_bad_symtab (input_bfd
)
4612 && local_sections
[r_symndx
] != NULL
))
4615 sym
= local_syms
+ r_symndx
;
4616 sec
= local_sections
[r_symndx
];
4617 relocation
= (sec
->output_section
->vma
4618 + sec
->output_offset
);
4620 /* It would be logical to always add sym->st_value here,
4621 but Irix 5 sometimes generates a garbage symbol
4623 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4624 relocation
+= sym
->st_value
;
4626 /* mips16 text labels should be treated as odd. */
4627 if (sym
->st_other
== STO_MIPS16
)
4635 indx
= r_symndx
- extsymoff
;
4636 h
= elf_sym_hashes (input_bfd
)[indx
];
4637 while (h
->root
.type
== bfd_link_hash_indirect
4638 || h
->root
.type
== bfd_link_hash_warning
)
4639 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4640 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
4644 if (! ((*info
->callbacks
->reloc_dangerous
)
4646 "_gp_disp used when GP not defined",
4647 input_bfd
, input_section
,
4650 /* Only give the error once per link. */
4652 _bfd_set_gp_value (output_bfd
, gp
);
4657 sec
= input_section
;
4658 if (sec
->output_section
!= NULL
)
4661 + sec
->output_section
->vma
4662 + sec
->output_offset
));
4664 relocation
= gp
- rel
->r_offset
;
4665 if (r_type
== R_MIPS_LO16
)
4669 else if (h
->root
.type
== bfd_link_hash_defined
4670 || h
->root
.type
== bfd_link_hash_defweak
)
4672 sec
= h
->root
.u
.def
.section
;
4673 if (sec
->output_section
== NULL
)
4676 relocation
= (h
->root
.u
.def
.value
4677 + sec
->output_section
->vma
4678 + sec
->output_offset
);
4680 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4682 else if (info
->shared
&& ! info
->symbolic
)
4684 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
4686 /* If this is a dynamic link, we should have created
4687 a _DYNAMIC_LINK symbol in
4688 mips_elf_create_dynamic_sections. Otherwise, we
4689 should define the symbol with a value of 0.
4690 FIXME: It should probably get into the symbol
4691 table somehow as well. */
4692 BFD_ASSERT (! info
->shared
);
4693 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
4694 ".dynamic") == NULL
);
4699 if (! ((*info
->callbacks
->undefined_symbol
)
4700 (info
, h
->root
.root
.string
, input_bfd
,
4701 input_section
, rel
->r_offset
)))
4707 mh
= (struct mips_elf_link_hash_entry
*) h
;
4710 else if (sym
!= NULL
)
4711 other
= sym
->st_other
;
4715 /* If this function has an fn_stub, then it is a mips16
4716 function which needs a stub if it is called by a 32 bit
4717 function. If this reloc is anything other than a 16 bit
4718 call, redirect the reloc to the stub. We don't redirect
4719 relocs from other stub functions. */
4720 if (r_type
!= R_MIPS16_26
4722 && mh
->fn_stub
!= NULL
)
4724 && elf_tdata (input_bfd
)->local_stubs
!= NULL
4725 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
4726 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
4727 FN_STUB
, sizeof FN_STUB
- 1) != 0
4728 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
4729 CALL_STUB
, sizeof CALL_STUB
- 1) != 0
4730 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
4731 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) != 0)
4735 BFD_ASSERT (mh
->need_fn_stub
);
4736 relocation
= (mh
->fn_stub
->output_section
->vma
4737 + mh
->fn_stub
->output_offset
);
4743 fn_stub
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
4744 relocation
= (fn_stub
->output_section
->vma
4745 + fn_stub
->output_offset
);
4748 /* RELOCATION now points to 32 bit code. */
4752 /* If this function has a call_stub, then it is called by a
4753 mips16 function; the call needs to go through a stub if
4754 this function is a 32 bit function. If this reloc is a
4755 16 bit call, and the symbol is not a 16 bit function,
4756 then redirect the reloc to the stub. Note that we don't
4757 need to worry about calling the function through a
4758 function pointer; such calls are handled by routing
4759 through a special mips16 routine. We don't have to check
4760 whether this call is from a stub; it can't be, because a
4761 stub contains 32 bit code, and hence can not have a 16
4763 if (r_type
== R_MIPS16_26
4765 && (mh
->call_stub
!= NULL
|| mh
->call_fp_stub
!= NULL
)
4766 && other
!= STO_MIPS16
)
4770 /* If both call_stub and call_fp_stub are defined, we
4771 can figure out which one to use by seeing which one
4772 appears in the input file. */
4773 if (mh
->call_stub
!= NULL
&& mh
->call_fp_stub
!= NULL
)
4778 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
4780 if (strncmp (bfd_get_section_name (input_bfd
, o
),
4781 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
4783 stub
= mh
->call_fp_stub
;
4788 stub
= mh
->call_stub
;
4790 else if (mh
->call_stub
!= NULL
)
4791 stub
= mh
->call_stub
;
4793 stub
= mh
->call_fp_stub
;
4795 BFD_ASSERT (stub
->_raw_size
> 0);
4796 relocation
= stub
->output_section
->vma
+ stub
->output_offset
;
4799 if (r_type
== R_MIPS_HI16
)
4801 Elf_Internal_Rela
*lorel
;
4803 /* As a GNU extension, permit an arbitrary number of
4804 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
4805 This permits gcc to emit the HI and LO relocs itself. */
4806 for (lorel
= rel
+ 1;
4808 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
4812 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
4814 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
4815 contents
, relocation
+ addend
);
4819 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4820 contents
, rel
->r_offset
,
4821 relocation
, addend
);
4823 else if (r_type
== R_MIPS_GOT16
&& local
)
4825 /* GOT16 must also have an associated LO16 in the local
4826 case. In this case, the addend is extracted and the
4827 section in which the referenced object is determined.
4828 Then the final address of the object is computed and
4829 the GOT entry for the hipage (an aligned 64kb chunk)
4830 is added to .got section if needed. The offset field
4831 of the GOT16-relocated instruction is replaced by the
4832 index of this GOT entry for the hipage. */
4833 if ((rel
+ 1) < relend
4834 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
4836 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
,
4839 relocation
+ addend
);
4843 r
= bfd_reloc_outofrange
;
4845 else if (r_type
== R_MIPS_CALL16
4846 || r_type
== R_MIPS_GOT16
4847 || r_type
== R_MIPS_CALL_LO16
4848 || r_type
== R_MIPS_GOT_LO16
)
4852 /* This symbol must be registered as a global symbol
4853 having the corresponding got entry. */
4854 BFD_ASSERT (h
->got_offset
!= (bfd_vma
) -1);
4856 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
4857 BFD_ASSERT (g
->local_gotno
<= offset
4858 && offset
< sgot
->_raw_size
);
4859 bfd_put_32 (output_bfd
, relocation
+ addend
,
4860 sgot
->contents
+ offset
);
4861 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
4863 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
4867 else if (r_type
== R_MIPS_CALL_HI16
4868 || r_type
== R_MIPS_GOT_HI16
)
4872 /* This must be a global symbol with a got entry. The
4873 next reloc must be the corresponding LO16 reloc. */
4874 BFD_ASSERT (h
!= NULL
&& h
->got_offset
!= (bfd_vma
) -1);
4875 BFD_ASSERT ((rel
+ 1) < relend
);
4876 BFD_ASSERT (ELF32_R_TYPE ((rel
+ 1)->r_info
)
4877 == (r_type
== R_MIPS_CALL_HI16
4879 : R_MIPS_GOT_LO16
));
4881 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
4882 BFD_ASSERT (g
->local_gotno
<= offset
4883 && offset
< sgot
->_raw_size
);
4884 bfd_put_32 (output_bfd
, relocation
+ addend
,
4885 sgot
->contents
+ offset
);
4886 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
4888 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
4892 else if (r_type
== R_MIPS_REL32
4893 || r_type
== R_MIPS_32
)
4895 Elf_Internal_Rel outrel
;
4896 Elf32_crinfo cptrel
;
4900 || (elf_hash_table (info
)->dynamic_sections_created
4902 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
4904 && (input_section
->flags
& SEC_ALLOC
) != 0)
4906 /* When generating a shared object, these
4907 relocations are copied into the output file to be
4908 resolved at run time. */
4911 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
4912 BFD_ASSERT (sreloc
!= NULL
);
4915 outrel
.r_offset
= (rel
->r_offset
4916 + input_section
->output_section
->vma
4917 + input_section
->output_offset
);
4919 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4922 && (! info
->symbolic
4923 || (h
->elf_link_hash_flags
4924 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4926 BFD_ASSERT (h
->dynindx
!= -1);
4927 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
4928 sec
= input_section
;
4935 sec
= local_sections
[r_symndx
];
4938 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
4940 == bfd_link_hash_defweak
));
4941 sec
= h
->root
.u
.def
.section
;
4943 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
4945 else if (sec
== NULL
|| sec
->owner
== NULL
)
4947 bfd_set_error (bfd_error_bad_value
);
4954 osec
= sec
->output_section
;
4955 indx
= elf_section_data (osec
)->dynindx
;
4960 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
4961 addend
+= relocation
;
4964 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
4965 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
4966 (((Elf32_External_Rel
*)
4968 + sreloc
->reloc_count
));
4969 ++sreloc
->reloc_count
;
4971 if (SGI_COMPAT (output_bfd
))
4976 /* Make an entry of compact relocation info. */
4977 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
4978 cptrel
.vaddr
= (rel
->r_offset
4979 + input_section
->output_section
->vma
4980 + input_section
->output_offset
);
4981 if (r_type
== R_MIPS_REL32
)
4982 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
4984 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
4985 mips_elf_set_cr_dist2to (cptrel
, 0);
4986 cptrel
.konst
= addend
;
4988 cr
= (scpt
->contents
4989 + sizeof (Elf32_External_compact_rel
));
4990 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4991 ((Elf32_External_crinfo
*) cr
4992 + scpt
->reloc_count
));
4993 ++scpt
->reloc_count
;
4996 /* This reloc will be computed at runtime, so
4997 there's no need to do anything now. */
5001 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5002 contents
, rel
->r_offset
,
5003 relocation
, addend
);
5005 else if (r_type
== R_MIPS_64
)
5010 /* Do a 32 bit relocation, and sign extend to 64 bits. */
5011 addr
= rel
->r_offset
;
5012 if (bfd_big_endian (input_bfd
))
5014 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5015 contents
, addr
, relocation
,
5017 val
= bfd_get_32 (input_bfd
, contents
+ addr
);
5018 if ((val
& 0x80000000) != 0)
5022 addr
= rel
->r_offset
;
5023 if (bfd_little_endian (input_bfd
))
5025 bfd_put_32 (input_bfd
, val
, contents
+ addr
);
5027 else if (r_type
== R_MIPS_26
&& other
== STO_MIPS16
)
5031 /* This is a jump to a mips16 routine from a mips32
5032 routine. We need to change jal into jalx. */
5033 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5034 if (((insn
>> 26) & 0x3f) != 0x3
5035 && ((insn
>> 26) & 0x3f) != 0x1d)
5037 (*_bfd_error_handler
)
5038 ("%s: %s+0x%lx: jump to mips16 routine which is not jal",
5039 bfd_get_filename (input_bfd
),
5040 input_section
->name
,
5041 (unsigned long) rel
->r_offset
);
5042 bfd_set_error (bfd_error_bad_value
);
5045 insn
= (insn
& 0x3ffffff) | (0x1d << 26);
5046 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5047 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5048 contents
, rel
->r_offset
,
5049 relocation
, addend
);
5051 else if (r_type
== R_MIPS16_26
)
5053 /* It's easiest to do the normal relocation, and then
5054 dig out the instruction and swap the first word the
5055 way the mips16 expects it. */
5056 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5057 contents
, rel
->r_offset
,
5058 relocation
, addend
);
5059 if (r
== bfd_reloc_ok
)
5063 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5064 insn
= ((insn
& 0xfc00)
5065 | ((insn
& 0x1f) << 5)
5066 | ((insn
& 0x3e0) >> 5));
5067 /* If this is a jump to a 32 bit routine, then make
5069 if (other
!= STO_MIPS16
)
5071 bfd_put_16 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5075 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5076 contents
, rel
->r_offset
,
5077 relocation
, addend
);
5079 if (SGI_COMPAT (abfd
)
5081 && (input_section
->flags
& SEC_ALLOC
) != 0)
5083 Elf32_crinfo cptrel
;
5086 /* Make an entry of compact relocation info. */
5087 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5088 cptrel
.vaddr
= (rel
->r_offset
5089 + input_section
->output_section
->vma
5090 + input_section
->output_offset
);
5095 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
5096 /* XXX How should we set dist2to in this case. */
5097 mips_elf_set_cr_dist2to (cptrel
, 8);
5098 cptrel
.konst
= addend
+ relocation
;
5099 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5100 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5101 ((Elf32_External_crinfo
*) cr
5102 + scpt
->reloc_count
));
5103 ++scpt
->reloc_count
;
5106 case R_MIPS_GPREL16
:
5107 case R_MIPS_LITERAL
:
5108 case R_MIPS_GPREL32
:
5109 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
5110 cptrel
.konst
= gp
- cptrel
.vaddr
;
5111 mips_elf_set_cr_dist2to (cptrel
, 4);
5112 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5113 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5114 ((Elf32_External_crinfo
*) cr
5115 + scpt
->reloc_count
));
5116 ++scpt
->reloc_count
;
5125 if (r
!= bfd_reloc_ok
)
5130 case bfd_reloc_outofrange
:
5132 case bfd_reloc_overflow
:
5137 name
= h
->root
.root
.string
;
5140 name
= bfd_elf_string_from_elf_section (input_bfd
,
5141 symtab_hdr
->sh_link
,
5146 name
= bfd_section_name (input_bfd
, sec
);
5148 if (! ((*info
->callbacks
->reloc_overflow
)
5149 (info
, name
, howto
->name
, (bfd_vma
) 0,
5150 input_bfd
, input_section
, rel
->r_offset
)))
5161 /* This hook function is called before the linker writes out a global
5162 symbol. This is where we undo the increment of the value for a
5167 mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
5169 struct bfd_link_info
*info
;
5171 Elf_Internal_Sym
*sym
;
5172 asection
*input_sec
;
5174 if (sym
->st_other
== STO_MIPS16
5175 && (sym
->st_value
& 1) != 0)
5180 /* Functions for the dynamic linker. */
5182 /* The name of the dynamic interpreter. This is put in the .interp
5185 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
5187 /* Create dynamic sections when linking against a dynamic object. */
5190 mips_elf_create_dynamic_sections (abfd
, info
)
5192 struct bfd_link_info
*info
;
5194 struct elf_link_hash_entry
*h
;
5196 register asection
*s
;
5197 const char * const *namep
;
5199 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5200 | SEC_LINKER_CREATED
| SEC_READONLY
);
5202 /* Mips ABI requests the .dynamic section to be read only. */
5203 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5206 if (! bfd_set_section_flags (abfd
, s
, flags
))
5210 /* We need to create .got section. */
5211 if (! mips_elf_create_got_section (abfd
, info
))
5214 /* Create .stub section. */
5215 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
5217 s
= bfd_make_section (abfd
, ".stub");
5219 || ! bfd_set_section_flags (abfd
, s
, flags
)
5220 || ! bfd_set_section_alignment (abfd
, s
, 2))
5224 if (SGI_COMPAT (abfd
)
5226 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
5228 s
= bfd_make_section (abfd
, ".rld_map");
5230 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
5231 || ! bfd_set_section_alignment (abfd
, s
, 2))
5235 if (SGI_COMPAT (abfd
))
5237 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
5240 if (! (_bfd_generic_link_add_one_symbol
5241 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
5242 (bfd_vma
) 0, (const char *) NULL
, false,
5243 get_elf_backend_data (abfd
)->collect
,
5244 (struct bfd_link_hash_entry
**) &h
)))
5246 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5247 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5248 h
->type
= STT_SECTION
;
5250 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5254 /* We need to create a .compact_rel section. */
5255 if (! mips_elf_create_compact_rel_section (abfd
, info
))
5258 /* Change aligments of some sections. */
5259 s
= bfd_get_section_by_name (abfd
, ".hash");
5261 bfd_set_section_alignment (abfd
, s
, 4);
5262 s
= bfd_get_section_by_name (abfd
, ".dynsym");
5264 bfd_set_section_alignment (abfd
, s
, 4);
5265 s
= bfd_get_section_by_name (abfd
, ".dynstr");
5267 bfd_set_section_alignment (abfd
, s
, 4);
5268 s
= bfd_get_section_by_name (abfd
, ".reginfo");
5270 bfd_set_section_alignment (abfd
, s
, 4);
5271 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5273 bfd_set_section_alignment (abfd
, s
, 4);
5279 if (! (_bfd_generic_link_add_one_symbol
5280 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
5281 (bfd_vma
) 0, (const char *) NULL
, false,
5282 get_elf_backend_data (abfd
)->collect
,
5283 (struct bfd_link_hash_entry
**) &h
)))
5285 h
->elf_link_hash_flags
^=~ ELF_LINK_NON_ELF
;
5286 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5287 h
->type
= STT_SECTION
;
5289 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5292 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
5294 /* __rld_map is a four byte word located in the .data section
5295 and is filled in by the rtld to contain a pointer to
5296 the _r_debug structure. Its symbol value will be set in
5297 mips_elf_finish_dynamic_symbol. */
5298 s
= bfd_get_section_by_name (abfd
, ".rld_map");
5299 BFD_ASSERT (s
!= NULL
);
5302 if (! (_bfd_generic_link_add_one_symbol
5303 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
5304 (bfd_vma
) 0, (const char *) NULL
, false,
5305 get_elf_backend_data (abfd
)->collect
,
5306 (struct bfd_link_hash_entry
**) &h
)))
5308 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5309 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5310 h
->type
= STT_OBJECT
;
5312 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5320 /* Create the .compact_rel section. */
5323 mips_elf_create_compact_rel_section (abfd
, info
)
5325 struct bfd_link_info
*info
;
5328 register asection
*s
;
5330 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
5332 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
5335 s
= bfd_make_section (abfd
, ".compact_rel");
5337 || ! bfd_set_section_flags (abfd
, s
, flags
)
5338 || ! bfd_set_section_alignment (abfd
, s
, 2))
5341 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
5347 /* Create the .got section to hold the global offset table. */
5350 mips_elf_create_got_section (abfd
, info
)
5352 struct bfd_link_info
*info
;
5355 register asection
*s
;
5356 struct elf_link_hash_entry
*h
;
5357 struct mips_got_info
*g
;
5359 /* This function may be called more than once. */
5360 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
5363 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5364 | SEC_LINKER_CREATED
);
5366 s
= bfd_make_section (abfd
, ".got");
5368 || ! bfd_set_section_flags (abfd
, s
, flags
)
5369 || ! bfd_set_section_alignment (abfd
, s
, 4))
5372 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
5373 linker script because we don't want to define the symbol if we
5374 are not creating a global offset table. */
5376 if (! (_bfd_generic_link_add_one_symbol
5377 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
5378 (bfd_vma
) 0, (const char *) NULL
, false,
5379 get_elf_backend_data (abfd
)->collect
,
5380 (struct bfd_link_hash_entry
**) &h
)))
5382 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5383 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5384 h
->type
= STT_OBJECT
;
5387 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5390 /* The first several global offset table entries are reserved. */
5391 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
5393 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
5394 sizeof (struct mips_got_info
));
5397 g
->global_gotsym
= 0;
5398 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
5399 if (elf_section_data (s
) == NULL
)
5402 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
5403 if (elf_section_data (s
) == NULL
)
5406 elf_section_data (s
)->tdata
= (PTR
) g
;
5411 /* Look through the relocs for a section during the first phase, and
5412 allocate space in the global offset table. */
5415 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
5417 struct bfd_link_info
*info
;
5419 const Elf_Internal_Rela
*relocs
;
5423 Elf_Internal_Shdr
*symtab_hdr
;
5424 struct elf_link_hash_entry
**sym_hashes
;
5425 struct mips_got_info
*g
;
5427 const Elf_Internal_Rela
*rel
;
5428 const Elf_Internal_Rela
*rel_end
;
5432 if (info
->relocateable
)
5435 dynobj
= elf_hash_table (info
)->dynobj
;
5436 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5437 sym_hashes
= elf_sym_hashes (abfd
);
5438 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
5440 /* Check for the mips16 stub sections. */
5442 name
= bfd_get_section_name (abfd
, sec
);
5443 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
5445 unsigned long r_symndx
;
5447 /* Look at the relocation information to figure out which symbol
5450 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
5452 if (r_symndx
< extsymoff
5453 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
5457 /* This stub is for a local symbol. This stub will only be
5458 needed if there is some relocation in this BFD, other
5459 than a 16 bit function call, which refers to this symbol. */
5460 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5462 Elf_Internal_Rela
*sec_relocs
;
5463 const Elf_Internal_Rela
*r
, *rend
;
5465 /* We can ignore stub sections when looking for relocs. */
5466 if ((o
->flags
& SEC_RELOC
) == 0
5467 || o
->reloc_count
== 0
5468 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
5469 sizeof FN_STUB
- 1) == 0
5470 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
5471 sizeof CALL_STUB
- 1) == 0
5472 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
5473 sizeof CALL_FP_STUB
- 1) == 0)
5476 sec_relocs
= (_bfd_elf32_link_read_relocs
5477 (abfd
, o
, (PTR
) NULL
,
5478 (Elf_Internal_Rela
*) NULL
,
5479 info
->keep_memory
));
5480 if (sec_relocs
== NULL
)
5483 rend
= sec_relocs
+ o
->reloc_count
;
5484 for (r
= sec_relocs
; r
< rend
; r
++)
5485 if (ELF32_R_SYM (r
->r_info
) == r_symndx
5486 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
5489 if (! info
->keep_memory
)
5498 /* There is no non-call reloc for this stub, so we do
5499 not need it. Since this function is called before
5500 the linker maps input sections to output sections, we
5501 can easily discard it by setting the SEC_EXCLUDE
5503 sec
->flags
|= SEC_EXCLUDE
;
5507 /* Record this stub in an array of local symbol stubs for
5509 if (elf_tdata (abfd
)->local_stubs
== NULL
)
5511 unsigned long symcount
;
5514 if (elf_bad_symtab (abfd
))
5515 symcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
5517 symcount
= symtab_hdr
->sh_info
;
5518 n
= (asection
**) bfd_zalloc (abfd
,
5519 symcount
* sizeof (asection
*));
5522 elf_tdata (abfd
)->local_stubs
= n
;
5525 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
5527 /* We don't need to set mips16_stubs_seen in this case.
5528 That flag is used to see whether we need to look through
5529 the global symbol table for stubs. We don't need to set
5530 it here, because we just have a local stub. */
5534 struct mips_elf_link_hash_entry
*h
;
5536 h
= ((struct mips_elf_link_hash_entry
*)
5537 sym_hashes
[r_symndx
- extsymoff
]);
5539 /* H is the symbol this stub is for. */
5542 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
5545 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
5546 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5548 unsigned long r_symndx
;
5549 struct mips_elf_link_hash_entry
*h
;
5552 /* Look at the relocation information to figure out which symbol
5555 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
5557 if (r_symndx
< extsymoff
5558 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
5560 /* This stub was actually built for a static symbol defined
5561 in the same file. We assume that all static symbols in
5562 mips16 code are themselves mips16, so we can simply
5563 discard this stub. Since this function is called before
5564 the linker maps input sections to output sections, we can
5565 easily discard it by setting the SEC_EXCLUDE flag. */
5566 sec
->flags
|= SEC_EXCLUDE
;
5570 h
= ((struct mips_elf_link_hash_entry
*)
5571 sym_hashes
[r_symndx
- extsymoff
]);
5573 /* H is the symbol this stub is for. */
5575 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5576 loc
= &h
->call_fp_stub
;
5578 loc
= &h
->call_stub
;
5580 /* If we already have an appropriate stub for this function, we
5581 don't need another one, so we can discard this one. Since
5582 this function is called before the linker maps input sections
5583 to output sections, we can easily discard it by setting the
5584 SEC_EXCLUDE flag. We can also discard this section if we
5585 happen to already know that this is a mips16 function; it is
5586 not necessary to check this here, as it is checked later, but
5587 it is slightly faster to check now. */
5588 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
5590 sec
->flags
|= SEC_EXCLUDE
;
5595 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
5605 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5610 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5611 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5612 BFD_ASSERT (g
!= NULL
);
5618 rel_end
= relocs
+ sec
->reloc_count
;
5619 for (rel
= relocs
; rel
< rel_end
; rel
++)
5621 unsigned long r_symndx
;
5622 struct elf_link_hash_entry
*h
;
5624 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5626 if (r_symndx
< extsymoff
)
5629 h
= sym_hashes
[r_symndx
- extsymoff
];
5631 /* Some relocs require a global offset table. */
5632 if (dynobj
== NULL
|| sgot
== NULL
)
5634 switch (ELF32_R_TYPE (rel
->r_info
))
5638 case R_MIPS_CALL_HI16
:
5639 case R_MIPS_CALL_LO16
:
5640 case R_MIPS_GOT_HI16
:
5641 case R_MIPS_GOT_LO16
:
5643 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
5644 if (! mips_elf_create_got_section (dynobj
, info
))
5646 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5647 BFD_ASSERT (sgot
!= NULL
);
5648 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5649 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5650 BFD_ASSERT (g
!= NULL
);
5656 && (info
->shared
|| h
!= NULL
)
5657 && (sec
->flags
& SEC_ALLOC
) != 0)
5658 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
5666 switch (ELF32_R_TYPE (rel
->r_info
))
5669 case R_MIPS_CALL_HI16
:
5670 case R_MIPS_CALL_LO16
:
5671 /* This symbol requires a global offset table entry. */
5673 BFD_ASSERT (h
!= NULL
);
5675 /* Make sure this symbol is output as a dynamic symbol. */
5676 if (h
->dynindx
== -1)
5678 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5682 if (h
->got_offset
!= (bfd_vma
) -1)
5684 /* We have already allocated space in the .got. */
5688 /* Note the index of the first global got symbol in .dynsym. */
5689 if (g
->global_gotsym
== 0
5690 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
5691 g
->global_gotsym
= h
->dynindx
;
5693 /* Make this symbol to have the corresponding got entry. */
5696 /* We need a stub, not a plt entry for the undefined
5697 function. But we record it as if it needs plt. See
5698 elf_adjust_dynamic_symbol in elflink.h. */
5699 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
5705 case R_MIPS_GOT_HI16
:
5706 case R_MIPS_GOT_LO16
:
5707 /* This symbol requires a global offset table entry. */
5711 /* Make sure this symbol is output as a dynamic symbol. */
5712 if (h
->dynindx
== -1)
5714 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5718 if (h
->got_offset
!= (bfd_vma
) -1)
5720 /* We have already allocated space in the .got. */
5723 /* Note the index of the first global got symbol in
5725 if (g
->global_gotsym
== 0
5726 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
5727 g
->global_gotsym
= h
->dynindx
;
5729 /* Make this symbol to be the global got symbol. */
5737 if ((info
->shared
|| h
!= NULL
)
5738 && (sec
->flags
& SEC_ALLOC
) != 0)
5742 const char *name
= ".rel.dyn";
5744 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5747 sreloc
= bfd_make_section (dynobj
, name
);
5749 || ! bfd_set_section_flags (dynobj
, sreloc
,
5754 | SEC_LINKER_CREATED
5756 || ! bfd_set_section_alignment (dynobj
, sreloc
,
5763 /* When creating a shared object, we must copy these
5764 reloc types into the output file as R_MIPS_REL32
5765 relocs. We make room for this reloc in the
5766 .rel.dyn reloc section */
5767 if (sreloc
->_raw_size
== 0)
5769 /* Add a null element. */
5770 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
5771 ++sreloc
->reloc_count
;
5773 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
5777 struct mips_elf_link_hash_entry
*hmips
;
5779 /* We only need to copy this reloc if the symbol is
5780 defined in a dynamic object. */
5781 hmips
= (struct mips_elf_link_hash_entry
*) h
;
5782 ++hmips
->mips_32_relocs
;
5786 if (SGI_COMPAT (abfd
))
5787 mips_elf_hash_table (info
)->compact_rel_size
+=
5788 sizeof (Elf32_External_crinfo
);
5793 case R_MIPS_GPREL16
:
5794 case R_MIPS_LITERAL
:
5795 case R_MIPS_GPREL32
:
5796 if (SGI_COMPAT (abfd
))
5797 mips_elf_hash_table (info
)->compact_rel_size
+=
5798 sizeof (Elf32_External_crinfo
);
5805 /* If this reloc is not a 16 bit call, and it has a global
5806 symbol, then we will need the fn_stub if there is one.
5807 References from a stub section do not count. */
5809 && ELF32_R_TYPE (rel
->r_info
) != R_MIPS16_26
5810 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
5811 sizeof FN_STUB
- 1) != 0
5812 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
5813 sizeof CALL_STUB
- 1) != 0
5814 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
5815 sizeof CALL_FP_STUB
- 1) != 0)
5817 struct mips_elf_link_hash_entry
*mh
;
5819 mh
= (struct mips_elf_link_hash_entry
*) h
;
5820 mh
->need_fn_stub
= true;
5827 /* Adjust a symbol defined by a dynamic object and referenced by a
5828 regular object. The current definition is in some section of the
5829 dynamic object, but we're not including those sections. We have to
5830 change the definition to something the rest of the link can
5834 mips_elf_adjust_dynamic_symbol (info
, h
)
5835 struct bfd_link_info
*info
;
5836 struct elf_link_hash_entry
*h
;
5839 struct mips_elf_link_hash_entry
*hmips
;
5842 dynobj
= elf_hash_table (info
)->dynobj
;
5844 /* Make sure we know what is going on here. */
5845 BFD_ASSERT (dynobj
!= NULL
5846 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
5847 || h
->weakdef
!= NULL
5848 || ((h
->elf_link_hash_flags
5849 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5850 && (h
->elf_link_hash_flags
5851 & ELF_LINK_HASH_REF_REGULAR
) != 0
5852 && (h
->elf_link_hash_flags
5853 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
5855 /* If this symbol is defined in a dynamic object, we need to copy
5856 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
5858 hmips
= (struct mips_elf_link_hash_entry
*) h
;
5859 if (! info
->relocateable
5860 && hmips
->mips_32_relocs
!= 0
5861 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5863 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5864 BFD_ASSERT (s
!= NULL
);
5866 if (s
->_raw_size
== 0)
5868 /* Make room for a null element. */
5869 s
->_raw_size
+= sizeof (Elf32_External_Rel
);
5872 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
5875 /* For a function, create a stub, if needed. */
5876 if (h
->type
== STT_FUNC
5877 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
5879 if (! elf_hash_table (info
)->dynamic_sections_created
)
5882 /* If this symbol is not defined in a regular file, then set
5883 the symbol to the stub location. This is required to make
5884 function pointers compare as equal between the normal
5885 executable and the shared library. */
5886 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5888 /* We need .stub section. */
5889 s
= bfd_get_section_by_name (dynobj
, ".stub");
5890 BFD_ASSERT (s
!= NULL
);
5892 h
->root
.u
.def
.section
= s
;
5893 h
->root
.u
.def
.value
= s
->_raw_size
;
5895 /* XXX Write this stub address somewhere. */
5896 h
->plt_offset
= s
->_raw_size
;
5898 /* Make room for this stub code. */
5899 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
5901 /* The last half word of the stub will be filled with the index
5902 of this symbol in .dynsym section. */
5907 /* If this is a weak symbol, and there is a real definition, the
5908 processor independent code will have arranged for us to see the
5909 real definition first, and we can just use the same value. */
5910 if (h
->weakdef
!= NULL
)
5912 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
5913 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
5914 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
5915 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
5919 /* This is a reference to a symbol defined by a dynamic object which
5920 is not a function. */
5925 /* This function is called after all the input files have been read,
5926 and the input sections have been assigned to output sections. We
5927 check for any mips16 stub sections that we can discard. */
5929 static boolean mips_elf_check_mips16_stubs
5930 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
5933 mips_elf_always_size_sections (output_bfd
, info
)
5935 struct bfd_link_info
*info
;
5937 if (info
->relocateable
5938 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
5941 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
5942 mips_elf_check_mips16_stubs
,
5948 /* Check the mips16 stubs for a particular symbol, and see if we can
5953 mips_elf_check_mips16_stubs (h
, data
)
5954 struct mips_elf_link_hash_entry
*h
;
5957 if (h
->fn_stub
!= NULL
5958 && ! h
->need_fn_stub
)
5960 /* We don't need the fn_stub; the only references to this symbol
5961 are 16 bit calls. Clobber the size to 0 to prevent it from
5962 being included in the link. */
5963 h
->fn_stub
->_raw_size
= 0;
5964 h
->fn_stub
->_cooked_size
= 0;
5965 h
->fn_stub
->flags
&= ~ SEC_RELOC
;
5966 h
->fn_stub
->reloc_count
= 0;
5967 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
5970 if (h
->call_stub
!= NULL
5971 && h
->root
.other
== STO_MIPS16
)
5973 /* We don't need the call_stub; this is a 16 bit function, so
5974 calls from other 16 bit functions are OK. Clobber the size
5975 to 0 to prevent it from being included in the link. */
5976 h
->call_stub
->_raw_size
= 0;
5977 h
->call_stub
->_cooked_size
= 0;
5978 h
->call_stub
->flags
&= ~ SEC_RELOC
;
5979 h
->call_stub
->reloc_count
= 0;
5980 h
->call_stub
->flags
|= SEC_EXCLUDE
;
5983 if (h
->call_fp_stub
!= NULL
5984 && h
->root
.other
== STO_MIPS16
)
5986 /* We don't need the call_stub; this is a 16 bit function, so
5987 calls from other 16 bit functions are OK. Clobber the size
5988 to 0 to prevent it from being included in the link. */
5989 h
->call_fp_stub
->_raw_size
= 0;
5990 h
->call_fp_stub
->_cooked_size
= 0;
5991 h
->call_fp_stub
->flags
&= ~ SEC_RELOC
;
5992 h
->call_fp_stub
->reloc_count
= 0;
5993 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
5999 /* Set the sizes of the dynamic sections. */
6002 mips_elf_size_dynamic_sections (output_bfd
, info
)
6004 struct bfd_link_info
*info
;
6010 struct mips_got_info
*g
;
6012 dynobj
= elf_hash_table (info
)->dynobj
;
6013 BFD_ASSERT (dynobj
!= NULL
);
6015 if (elf_hash_table (info
)->dynamic_sections_created
)
6017 /* Set the contents of the .interp section to the interpreter. */
6020 s
= bfd_get_section_by_name (dynobj
, ".interp");
6021 BFD_ASSERT (s
!= NULL
);
6022 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
6023 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
6027 /* Recompute the size of .got for local entires (reserved and
6028 hipages) if needed. To estimate it, get the upper bound of total
6029 size of loadable sections. */
6030 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6034 bfd_size_type loadable_size
= 0;
6035 bfd_size_type local_gotno
;
6038 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6039 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6040 BFD_ASSERT (g
!= NULL
);
6042 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
6043 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
6045 if ((s
->flags
& SEC_ALLOC
) == 0)
6047 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
6050 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
6052 /* Assume there are two loadable segments consisting of
6053 contiguous sections. Is 5 enough? */
6054 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
6055 g
->local_gotno
= local_gotno
;
6056 sgot
->_raw_size
+= local_gotno
* 4;
6059 /* The check_relocs and adjust_dynamic_symbol entry points have
6060 determined the sizes of the various dynamic sections. Allocate
6063 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
6068 /* It's OK to base decisions on the section name, because none
6069 of the dynobj section names depend upon the input files. */
6070 name
= bfd_get_section_name (dynobj
, s
);
6072 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
6077 if (strncmp (name
, ".rel", 4) == 0)
6079 if (s
->_raw_size
== 0)
6083 const char *outname
;
6086 /* If this relocation section applies to a read only
6087 section, then we probably need a DT_TEXTREL entry.
6088 If the relocation section is .rel.dyn, we always
6089 assert a DT_TEXTREL entry rather than testing whether
6090 there exists a relocation to a read only section or
6092 outname
= bfd_get_section_name (output_bfd
,
6094 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
6095 if ((target
!= NULL
&& (target
->flags
& SEC_READONLY
) != 0)
6096 || strcmp (outname
, ".rel.dyn") == 0)
6099 /* We use the reloc_count field as a counter if we need
6100 to copy relocs into the output file. */
6101 if (strcmp (name
, ".rel.dyn") != 0)
6105 else if (strncmp (name
, ".got", 4) == 0)
6109 BFD_ASSERT (elf_section_data (s
) != NULL
);
6110 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
6111 BFD_ASSERT (g
!= NULL
);
6113 /* Fix the size of .got section for the correspondence of
6114 global symbols and got entries. This adds some useless
6115 got entries. Is this required by ABI really? */
6116 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
6117 s
->_raw_size
+= i
* 4;
6119 else if (strncmp (name
, ".stub", 5) == 0)
6121 /* Irix rld assumes that the function stub isn't at the end
6122 of .text section. So put a dummy. XXX */
6123 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6125 else if (! info
->shared
6126 && ! mips_elf_hash_table (info
)->use_rld_obj_head
6127 && strncmp (name
, ".rld_map", 8) == 0)
6129 /* We add a room for __rld_map. It will be filled in by the
6130 rtld to contain a pointer to the _r_debug structure. */
6133 else if (SGI_COMPAT (output_bfd
)
6134 && strncmp (name
, ".compact_rel", 12) == 0)
6135 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
6136 else if (strncmp (name
, ".init", 5) != 0)
6138 /* It's not one of our sections, so don't allocate space. */
6146 for (spp
= &s
->output_section
->owner
->sections
;
6147 *spp
!= s
->output_section
;
6148 spp
= &(*spp
)->next
)
6150 *spp
= s
->output_section
->next
;
6151 --s
->output_section
->owner
->section_count
;
6156 /* Allocate memory for the section contents. */
6157 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
6158 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
6160 bfd_set_error (bfd_error_no_memory
);
6163 memset (s
->contents
, 0, s
->_raw_size
);
6166 if (elf_hash_table (info
)->dynamic_sections_created
)
6168 /* Add some entries to the .dynamic section. We fill in the
6169 values later, in elf_mips_finish_dynamic_sections, but we
6170 must add the entries now so that we get the correct size for
6171 the .dynamic section. The DT_DEBUG entry is filled in by the
6172 dynamic linker and used by the debugger. */
6175 if (SGI_COMPAT (output_bfd
))
6177 /* SGI object has the equivalence of DT_DEBUG in the
6178 DT_MIPS_RLD_MAP entry. */
6179 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
6183 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
6189 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
6193 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
6196 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
6198 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
6201 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
6204 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
6208 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
6211 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
6214 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
6216 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
6219 s
= bfd_get_section_by_name (dynobj
, ".liblist");
6220 BFD_ASSERT (s
!= NULL
);
6222 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
6226 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
6229 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
6233 /* Time stamps in executable files are a bad idea. */
6234 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
6239 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
6244 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
6248 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
6251 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
6254 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
6257 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
6260 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
6263 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
6266 #if 0 /* (SGI_COMPAT) */
6267 if (! bfd_get_section_by_name (dynobj
, ".init"))
6268 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
6271 if (! bfd_get_section_by_name (dynobj
, ".fini"))
6272 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
6277 /* If we use dynamic linking, we generate a section symbol for each
6278 output section. These are local symbols, which means that they
6279 must come first in the dynamic symbol table.
6280 That means we must increment the dynamic symbol index of every
6281 other dynamic symbol. */
6283 const char * const *namep
;
6285 bfd_size_type strindex
;
6286 struct bfd_strtab_hash
*dynstr
;
6287 struct mips_got_info
*g
;
6290 if (elf_hash_table (info
)->dynamic_sections_created
)
6292 if (SGI_COMPAT (output_bfd
))
6294 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
6295 elf_link_hash_traverse (elf_hash_table (info
),
6296 mips_elf_adjust_dynindx
,
6298 elf_hash_table (info
)->dynsymcount
+= c
;
6300 dynstr
= elf_hash_table (info
)->dynstr
;
6301 BFD_ASSERT (dynstr
!= NULL
);
6303 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
6307 s
= bfd_get_section_by_name (output_bfd
, *namep
);
6309 elf_section_data (s
)->dynindx
= i
;
6311 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
6312 if (strindex
== (bfd_size_type
) -1)
6315 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
6320 c
= bfd_count_sections (output_bfd
);
6321 elf_link_hash_traverse (elf_hash_table (info
),
6322 mips_elf_adjust_dynindx
,
6324 elf_hash_table (info
)->dynsymcount
+= c
;
6326 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
6328 elf_section_data (s
)->dynindx
= i
;
6329 /* These symbols will have no names, so we don't need to
6330 fiddle with dynstr_index. */
6337 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6338 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6339 BFD_ASSERT (g
!= NULL
);
6341 /* If there are no global got symbols, fake the last symbol so
6343 if (g
->global_gotsym
)
6344 g
->global_gotsym
+= c
;
6346 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
6353 /* Increment the index of a dynamic symbol by a given amount. Called
6354 via elf_link_hash_traverse. */
6357 mips_elf_adjust_dynindx (h
, cparg
)
6358 struct elf_link_hash_entry
*h
;
6361 unsigned int *cp
= (unsigned int *) cparg
;
6363 if (h
->dynindx
!= -1)
6368 /* Finish up dynamic symbol handling. We set the contents of various
6369 dynamic sections here. */
6372 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
6374 struct bfd_link_info
*info
;
6375 struct elf_link_hash_entry
*h
;
6376 Elf_Internal_Sym
*sym
;
6381 struct mips_got_info
*g
;
6384 dynobj
= elf_hash_table (info
)->dynobj
;
6385 gval
= sym
->st_value
;
6387 if (h
->plt_offset
!= (bfd_vma
) -1)
6391 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
6393 /* This symbol has a stub. Set it up. */
6395 BFD_ASSERT (h
->dynindx
!= -1);
6397 s
= bfd_get_section_by_name (dynobj
, ".stub");
6398 BFD_ASSERT (s
!= NULL
);
6400 /* Fill the stub. */
6402 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
6404 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
6407 /* FIXME: Can h->dynindex be more than 64K? */
6408 if (h
->dynindx
& 0xffff0000)
6411 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
6413 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
6415 BFD_ASSERT (h
->plt_offset
<= s
->_raw_size
);
6416 memcpy (s
->contents
+ h
->plt_offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
6418 /* Mark the symbol as undefined. plt_offset != -1 occurs
6419 only for the referenced symbol. */
6420 sym
->st_shndx
= SHN_UNDEF
;
6422 /* The run-time linker uses the st_value field of the symbol
6423 to reset the global offset table entry for this external
6424 to its stub address when unlinking a shared object. */
6425 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt_offset
;
6426 sym
->st_value
= gval
;
6429 BFD_ASSERT (h
->dynindx
!= -1);
6431 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6432 BFD_ASSERT (sgot
!= NULL
);
6433 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6434 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6435 BFD_ASSERT (g
!= NULL
);
6437 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
6439 bfd_size_type offset
;
6441 /* This symbol has an entry in the global offset table. Set its
6442 value to the corresponding got entry, if needed. */
6443 if (h
->got_offset
== (bfd_vma
) -1)
6445 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
6446 BFD_ASSERT (g
->local_gotno
* 4 <= offset
6447 && offset
< sgot
->_raw_size
);
6448 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
6452 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
6453 name
= h
->root
.root
.string
;
6454 if (strcmp (name
, "_DYNAMIC") == 0
6455 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
6456 sym
->st_shndx
= SHN_ABS
;
6457 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
6459 sym
->st_shndx
= SHN_ABS
;
6460 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6463 else if (SGI_COMPAT (output_bfd
))
6465 if (strcmp (name
, "_gp_disp") == 0)
6467 sym
->st_shndx
= SHN_ABS
;
6468 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6469 sym
->st_value
= elf_gp (output_bfd
);
6471 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
6472 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
6474 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6475 sym
->st_other
= STO_PROTECTED
;
6477 sym
->st_shndx
= SHN_MIPS_DATA
;
6479 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
6481 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6482 sym
->st_other
= STO_PROTECTED
;
6483 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
6484 sym
->st_shndx
= SHN_ABS
;
6486 else if (sym
->st_shndx
!= SHN_UNDEF
)
6488 if (h
->type
== STT_FUNC
)
6489 sym
->st_shndx
= SHN_MIPS_TEXT
;
6490 else if (h
->type
== STT_OBJECT
)
6491 sym
->st_shndx
= SHN_MIPS_DATA
;
6495 if (SGI_COMPAT (output_bfd
)
6498 if (! mips_elf_hash_table (info
)->use_rld_obj_head
6499 && strcmp (name
, "__rld_map") == 0)
6501 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
6502 BFD_ASSERT (s
!= NULL
);
6503 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
6504 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
6505 if (mips_elf_hash_table (info
)->rld_value
== 0)
6506 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
6508 else if (mips_elf_hash_table (info
)->use_rld_obj_head
6509 && strcmp (name
, "__rld_obj_head") == 0)
6511 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
6512 BFD_ASSERT (s
!= NULL
);
6513 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
6517 /* If this is a mips16 symbol, force the value to be even. */
6518 if (sym
->st_other
== STO_MIPS16
6519 && (sym
->st_value
& 1) != 0)
6525 /* Finish up the dynamic sections. */
6528 mips_elf_finish_dynamic_sections (output_bfd
, info
)
6530 struct bfd_link_info
*info
;
6535 struct mips_got_info
*g
;
6537 dynobj
= elf_hash_table (info
)->dynobj
;
6539 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
6541 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6546 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6547 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6548 BFD_ASSERT (g
!= NULL
);
6551 if (elf_hash_table (info
)->dynamic_sections_created
)
6553 Elf32_External_Dyn
*dyncon
, *dynconend
;
6555 BFD_ASSERT (sdyn
!= NULL
);
6556 BFD_ASSERT (g
!= NULL
);
6558 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
6559 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
6560 for (; dyncon
< dynconend
; dyncon
++)
6562 Elf_Internal_Dyn dyn
;
6567 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
6575 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6576 BFD_ASSERT (s
!= NULL
);
6577 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
6578 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6582 /* Rewrite DT_STRSZ. */
6584 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
6585 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6591 case DT_MIPS_CONFLICT
:
6594 case DT_MIPS_LIBLIST
:
6597 s
= bfd_get_section_by_name (output_bfd
, name
);
6598 BFD_ASSERT (s
!= NULL
);
6599 dyn
.d_un
.d_ptr
= s
->vma
;
6600 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6603 case DT_MIPS_RLD_VERSION
:
6604 dyn
.d_un
.d_val
= 1; /* XXX */
6605 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6609 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
6610 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6613 case DT_MIPS_CONFLICTNO
:
6615 elemsize
= sizeof (Elf32_Conflict
);
6618 case DT_MIPS_LIBLISTNO
:
6620 elemsize
= sizeof (Elf32_Lib
);
6622 s
= bfd_get_section_by_name (output_bfd
, name
);
6625 if (s
->_cooked_size
!= 0)
6626 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
6628 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
6633 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6636 case DT_MIPS_TIME_STAMP
:
6637 time ((time_t *) &dyn
.d_un
.d_val
);
6638 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6641 case DT_MIPS_ICHECKSUM
:
6645 case DT_MIPS_IVERSION
:
6649 case DT_MIPS_BASE_ADDRESS
:
6650 s
= output_bfd
->sections
;
6651 BFD_ASSERT (s
!= NULL
);
6652 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
6653 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6656 case DT_MIPS_LOCAL_GOTNO
:
6657 dyn
.d_un
.d_val
= g
->local_gotno
;
6658 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6661 case DT_MIPS_SYMTABNO
:
6663 elemsize
= sizeof (Elf32_External_Sym
);
6664 s
= bfd_get_section_by_name (output_bfd
, name
);
6665 BFD_ASSERT (s
!= NULL
);
6667 if (s
->_cooked_size
!= 0)
6668 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
6670 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
6671 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6674 case DT_MIPS_UNREFEXTNO
:
6676 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
6677 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6680 case DT_MIPS_GOTSYM
:
6681 dyn
.d_un
.d_val
= g
->global_gotsym
;
6682 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6685 case DT_MIPS_HIPAGENO
:
6686 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
6687 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6690 case DT_MIPS_RLD_MAP
:
6691 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
6692 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6699 /* The first entry of the global offset table will be filled at
6700 runtime. The second entry will be used by some runtime loaders.
6701 This isn't the case of Irix rld. */
6702 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
6704 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
6705 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
6709 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
6716 Elf_Internal_Sym sym
;
6719 const char * const * namep
= mips_elf_dynsym_sec_names
;
6720 Elf32_compact_rel cpt
;
6722 /* Set up the section symbols for the output sections. SGI sets
6723 the STT_NOTYPE attribute for these symbols. Should we do so? */
6725 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
6726 if (sdynsym
!= NULL
)
6728 if (SGI_COMPAT (output_bfd
))
6732 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
6736 while ((name
= *namep
++) != NULL
)
6738 s
= bfd_get_section_by_name (output_bfd
, name
);
6741 sym
.st_value
= s
->vma
;
6742 dindx
= elf_section_data (s
)->dynindx
;
6743 last
= s
->vma
+ s
->_raw_size
;
6747 sym
.st_value
= last
;
6751 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
6756 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
6758 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
6759 (((Elf32_External_Sym
*)
6764 /* Set the sh_info field of the output .dynsym section to
6765 the index of the first global symbol. */
6766 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
6767 SIZEOF_MIPS_DYNSYM_SECNAMES
;
6773 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
6776 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
6780 sym
.st_value
= s
->vma
;
6782 indx
= elf_section_data (s
)->this_idx
;
6783 BFD_ASSERT (indx
> 0);
6784 sym
.st_shndx
= indx
;
6786 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
6787 (((Elf32_External_Sym
*)
6789 + elf_section_data (s
)->dynindx
));
6792 /* Set the sh_info field of the output .dynsym section to
6793 the index of the first global symbol. */
6794 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
6795 bfd_count_sections (output_bfd
) + 1;
6799 if (SGI_COMPAT (output_bfd
))
6801 /* Write .compact_rel section out. */
6802 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
6806 cpt
.num
= s
->reloc_count
;
6808 cpt
.offset
= (s
->output_section
->filepos
6809 + sizeof (Elf32_External_compact_rel
));
6812 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
6813 ((Elf32_External_compact_rel
*)
6816 /* Clean up a dummy stub function entry in .text. */
6817 s
= bfd_get_section_by_name (dynobj
, ".stub");
6820 file_ptr dummy_offset
;
6822 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
6823 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
6824 memset (s
->contents
+ dummy_offset
, 0,
6825 MIPS_FUNCTION_STUB_SIZE
);
6830 /* Clean up a first relocation in .rel.dyn. */
6831 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6832 if (s
!= NULL
&& s
->_raw_size
> 0)
6833 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
6839 /* This is almost identical to bfd_generic_get_... except that some
6840 MIPS relocations need to be handled specially. Sigh. */
6843 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
6844 relocateable
, symbols
)
6846 struct bfd_link_info
*link_info
;
6847 struct bfd_link_order
*link_order
;
6849 boolean relocateable
;
6852 /* Get enough memory to hold the stuff */
6853 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
6854 asection
*input_section
= link_order
->u
.indirect
.section
;
6856 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
6857 arelent
**reloc_vector
= NULL
;
6863 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
6864 if (reloc_vector
== NULL
&& reloc_size
!= 0)
6867 /* read in the section */
6868 if (!bfd_get_section_contents (input_bfd
,
6872 input_section
->_raw_size
))
6875 /* We're not relaxing the section, so just copy the size info */
6876 input_section
->_cooked_size
= input_section
->_raw_size
;
6877 input_section
->reloc_done
= true;
6879 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
6883 if (reloc_count
< 0)
6886 if (reloc_count
> 0)
6891 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
6894 struct bfd_hash_entry
*h
;
6895 struct bfd_link_hash_entry
*lh
;
6896 /* Skip all this stuff if we aren't mixing formats. */
6897 if (abfd
&& input_bfd
6898 && abfd
->xvec
== input_bfd
->xvec
)
6902 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
6903 lh
= (struct bfd_link_hash_entry
*) h
;
6910 case bfd_link_hash_undefined
:
6911 case bfd_link_hash_undefweak
:
6912 case bfd_link_hash_common
:
6915 case bfd_link_hash_defined
:
6916 case bfd_link_hash_defweak
:
6918 gp
= lh
->u
.def
.value
;
6920 case bfd_link_hash_indirect
:
6921 case bfd_link_hash_warning
:
6923 /* @@FIXME ignoring warning for now */
6925 case bfd_link_hash_new
:
6934 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
6937 char *error_message
= (char *) NULL
;
6938 bfd_reloc_status_type r
;
6940 /* Specific to MIPS: Deal with relocation types that require
6941 knowing the gp of the output bfd. */
6942 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
6943 if (bfd_is_abs_section (sym
->section
) && abfd
)
6945 /* The special_function wouldn't get called anyways. */
6949 /* The gp isn't there; let the special function code
6950 fall over on its own. */
6952 else if ((*parent
)->howto
->special_function
6953 == _bfd_mips_elf_gprel16_reloc
)
6955 /* bypass special_function call */
6956 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
6957 relocateable
, (PTR
) data
, gp
);
6958 goto skip_bfd_perform_relocation
;
6960 /* end mips specific stuff */
6962 r
= bfd_perform_relocation (input_bfd
,
6966 relocateable
? abfd
: (bfd
*) NULL
,
6968 skip_bfd_perform_relocation
:
6972 asection
*os
= input_section
->output_section
;
6974 /* A partial link, so keep the relocs */
6975 os
->orelocation
[os
->reloc_count
] = *parent
;
6979 if (r
!= bfd_reloc_ok
)
6983 case bfd_reloc_undefined
:
6984 if (!((*link_info
->callbacks
->undefined_symbol
)
6985 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
6986 input_bfd
, input_section
, (*parent
)->address
)))
6989 case bfd_reloc_dangerous
:
6990 BFD_ASSERT (error_message
!= (char *) NULL
);
6991 if (!((*link_info
->callbacks
->reloc_dangerous
)
6992 (link_info
, error_message
, input_bfd
, input_section
,
6993 (*parent
)->address
)))
6996 case bfd_reloc_overflow
:
6997 if (!((*link_info
->callbacks
->reloc_overflow
)
6998 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
6999 (*parent
)->howto
->name
, (*parent
)->addend
,
7000 input_bfd
, input_section
, (*parent
)->address
)))
7003 case bfd_reloc_outofrange
:
7012 if (reloc_vector
!= NULL
)
7013 free (reloc_vector
);
7017 if (reloc_vector
!= NULL
)
7018 free (reloc_vector
);
7021 #define bfd_elf32_bfd_get_relocated_section_contents \
7022 elf32_mips_get_relocated_section_contents
7024 /* ECOFF swapping routines. These are used when dealing with the
7025 .mdebug section, which is in the ECOFF debugging format. */
7026 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
7028 /* Symbol table magic number. */
7030 /* Alignment of debugging information. E.g., 4. */
7032 /* Sizes of external symbolic information. */
7033 sizeof (struct hdr_ext
),
7034 sizeof (struct dnr_ext
),
7035 sizeof (struct pdr_ext
),
7036 sizeof (struct sym_ext
),
7037 sizeof (struct opt_ext
),
7038 sizeof (struct fdr_ext
),
7039 sizeof (struct rfd_ext
),
7040 sizeof (struct ext_ext
),
7041 /* Functions to swap in external symbolic data. */
7050 _bfd_ecoff_swap_tir_in
,
7051 _bfd_ecoff_swap_rndx_in
,
7052 /* Functions to swap out external symbolic data. */
7061 _bfd_ecoff_swap_tir_out
,
7062 _bfd_ecoff_swap_rndx_out
,
7063 /* Function to read in symbolic data. */
7064 _bfd_mips_elf_read_ecoff_info
7067 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
7068 #define TARGET_LITTLE_NAME "elf32-littlemips"
7069 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
7070 #define TARGET_BIG_NAME "elf32-bigmips"
7071 #define ELF_ARCH bfd_arch_mips
7072 #define ELF_MACHINE_CODE EM_MIPS
7074 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
7075 a value of 0x1000, and we are compatible. */
7076 #define ELF_MAXPAGESIZE 0x1000
7078 #define elf_backend_collect true
7079 #define elf_backend_type_change_ok true
7080 #define elf_info_to_howto 0
7081 #define elf_info_to_howto_rel mips_info_to_howto_rel
7082 #define elf_backend_sym_is_global mips_elf_sym_is_global
7083 #define elf_backend_object_p mips_elf32_object_p
7084 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
7085 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
7086 #define elf_backend_section_from_bfd_section \
7087 _bfd_mips_elf_section_from_bfd_section
7088 #define elf_backend_section_processing mips_elf32_section_processing
7089 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
7090 #define elf_backend_additional_program_headers \
7091 mips_elf_additional_program_headers
7092 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
7093 #define elf_backend_final_write_processing \
7094 _bfd_mips_elf_final_write_processing
7095 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
7097 #define bfd_elf32_bfd_is_local_label mips_elf_is_local_label
7098 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
7099 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
7100 #define bfd_elf32_bfd_link_hash_table_create \
7101 mips_elf_link_hash_table_create
7102 #define bfd_elf32_bfd_final_link mips_elf_final_link
7103 #define bfd_elf32_bfd_copy_private_bfd_data \
7104 _bfd_mips_elf_copy_private_bfd_data
7105 #define bfd_elf32_bfd_merge_private_bfd_data \
7106 _bfd_mips_elf_merge_private_bfd_data
7107 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
7108 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
7109 #define elf_backend_create_dynamic_sections \
7110 mips_elf_create_dynamic_sections
7111 #define elf_backend_check_relocs mips_elf_check_relocs
7112 #define elf_backend_adjust_dynamic_symbol \
7113 mips_elf_adjust_dynamic_symbol
7114 #define elf_backend_always_size_sections \
7115 mips_elf_always_size_sections
7116 #define elf_backend_size_dynamic_sections \
7117 mips_elf_size_dynamic_sections
7118 #define elf_backend_relocate_section mips_elf_relocate_section
7119 #define elf_backend_link_output_symbol_hook \
7120 mips_elf_link_output_symbol_hook
7121 #define elf_backend_finish_dynamic_symbol \
7122 mips_elf_finish_dynamic_symbol
7123 #define elf_backend_finish_dynamic_sections \
7124 mips_elf_finish_dynamic_sections
7126 #include "elf32-target.h"