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_size_dynamic_sections
105 PARAMS ((bfd
*, struct bfd_link_info
*));
106 static boolean mips_elf_finish_dynamic_symbol
107 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
108 Elf_Internal_Sym
*));
109 static boolean mips_elf_finish_dynamic_sections
110 PARAMS ((bfd
*, struct bfd_link_info
*));
111 static boolean mips_elf_add_symbol_hook
112 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
113 const char **, flagword
*, asection
**, bfd_vma
*));
114 static bfd_reloc_status_type mips_elf_final_gp
115 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
116 static bfd_byte
*elf32_mips_get_relocated_section_contents
117 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
118 bfd_byte
*, boolean
, asymbol
**));
120 /* This is true for Irix 5 executables, false for normal MIPS ELF ABI
121 executables. FIXME: At the moment, we default to always generating
122 Irix 5 executables. */
124 #define SGI_COMPAT(abfd) (1)
126 /* This structure is used to hold .got information when linking. It
127 is stored in the tdata field of the bfd_elf_section_data structure. */
131 /* The symbol index of the first global .got symbol. */
132 unsigned long global_gotsym
;
133 /* The number of local .got entries. */
134 unsigned int local_gotno
;
137 /* The number of local .got entries we reserve. */
138 #define MIPS_RESERVED_GOTNO (2)
140 /* Instructions which appear in a stub. For some reason the stub is
141 slightly different on an SGI system. */
142 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
143 #define STUB_LW(abfd) \
145 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
146 : 0x8f998000) /* lw t9,0x8000(gp) */
147 #define STUB_MOVE 0x03e07825 /* move t7,ra */
148 #define STUB_JALR 0x0320f809 /* jal t9 */
149 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
150 #define MIPS_FUNCTION_STUB_SIZE (16)
152 /* Names of sections which appear in the .dynsym section in an Irix 5
155 static const char * const mips_elf_dynsym_sec_names
[] =
168 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
169 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
171 /* The number of entries in mips_elf_dynsym_sec_names which go in the
174 #define MIPS_TEXT_DYNSYM_SECNO (3)
176 /* The names of the runtime procedure table symbols used on Irix 5. */
178 static const char * const mips_elf_dynsym_rtproc_names
[] =
181 "_procedure_string_table",
182 "_procedure_table_size",
186 /* These structures are used to generate the .compact_rel section on
191 unsigned long id1
; /* Always one? */
192 unsigned long num
; /* Number of compact relocation entries. */
193 unsigned long id2
; /* Always two? */
194 unsigned long offset
; /* The file offset of the first relocation. */
195 unsigned long reserved0
; /* Zero? */
196 unsigned long reserved1
; /* Zero? */
205 bfd_byte reserved0
[4];
206 bfd_byte reserved1
[4];
207 } Elf32_External_compact_rel
;
211 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
212 unsigned int rtype
: 4; /* Relocation types. See below. */
213 unsigned int dist2to
: 8;
214 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
215 unsigned long konst
; /* KONST field. See below. */
216 unsigned long vaddr
; /* VADDR to be relocated. */
221 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
222 unsigned int rtype
: 4; /* Relocation types. See below. */
223 unsigned int dist2to
: 8;
224 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
225 unsigned long konst
; /* KONST field. See below. */
233 } Elf32_External_crinfo
;
239 } Elf32_External_crinfo2
;
241 /* These are the constants used to swap the bitfields in a crinfo. */
243 #define CRINFO_CTYPE (0x1)
244 #define CRINFO_CTYPE_SH (31)
245 #define CRINFO_RTYPE (0xf)
246 #define CRINFO_RTYPE_SH (27)
247 #define CRINFO_DIST2TO (0xff)
248 #define CRINFO_DIST2TO_SH (19)
249 #define CRINFO_RELVADDR (0x7ffff)
250 #define CRINFO_RELVADDR_SH (0)
252 /* A compact relocation info has long (3 words) or short (2 words)
253 formats. A short format doesn't have VADDR field and relvaddr
254 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
255 #define CRF_MIPS_LONG 1
256 #define CRF_MIPS_SHORT 0
258 /* There are 4 types of compact relocation at least. The value KONST
259 has different meaning for each type:
262 CT_MIPS_REL32 Address in data
263 CT_MIPS_WORD Address in word (XXX)
264 CT_MIPS_GPHI_LO GP - vaddr
265 CT_MIPS_JMPAD Address to jump
268 #define CRT_MIPS_REL32 0xa
269 #define CRT_MIPS_WORD 0xb
270 #define CRT_MIPS_GPHI_LO 0xc
271 #define CRT_MIPS_JMPAD 0xd
273 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
274 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
275 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
276 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
278 static void bfd_elf32_swap_compact_rel_out
279 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
280 static void bfd_elf32_swap_crinfo_out
281 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
283 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
288 R_MIPS_16
, R_MIPS_32
,
289 R_MIPS_REL32
, R_MIPS_26
,
290 R_MIPS_HI16
, R_MIPS_LO16
,
291 R_MIPS_GPREL16
, R_MIPS_LITERAL
,
292 R_MIPS_GOT16
, R_MIPS_PC16
,
293 R_MIPS_CALL16
, R_MIPS_GPREL32
,
294 /* The remaining relocs are defined on Irix, although they are not
295 in the MIPS ELF ABI. */
296 R_MIPS_UNUSED1
, R_MIPS_UNUSED2
,
298 R_MIPS_SHIFT5
, R_MIPS_SHIFT6
,
299 R_MIPS_64
, R_MIPS_GOT_DISP
,
300 R_MIPS_GOT_PAGE
, R_MIPS_GOT_OFST
,
301 R_MIPS_GOT_HI16
, R_MIPS_GOT_LO16
,
302 R_MIPS_SUB
, R_MIPS_INSERT_A
,
303 R_MIPS_INSERT_B
, R_MIPS_DELETE
,
304 R_MIPS_HIGHER
, R_MIPS_HIGHEST
,
305 R_MIPS_CALL_HI16
, R_MIPS_CALL_LO16
,
307 /* This reloc is used for the mips16. */
311 static reloc_howto_type elf_mips_howto_table
[] =
314 HOWTO (R_MIPS_NONE
, /* type */
316 0, /* size (0 = byte, 1 = short, 2 = long) */
318 false, /* pc_relative */
320 complain_overflow_dont
, /* complain_on_overflow */
321 bfd_elf_generic_reloc
, /* special_function */
322 "R_MIPS_NONE", /* name */
323 false, /* partial_inplace */
326 false), /* pcrel_offset */
328 /* 16 bit relocation. */
329 HOWTO (R_MIPS_16
, /* type */
331 1, /* size (0 = byte, 1 = short, 2 = long) */
333 false, /* pc_relative */
335 complain_overflow_bitfield
, /* complain_on_overflow */
336 bfd_elf_generic_reloc
, /* special_function */
337 "R_MIPS_16", /* name */
338 true, /* partial_inplace */
339 0xffff, /* src_mask */
340 0xffff, /* dst_mask */
341 false), /* pcrel_offset */
343 /* 32 bit relocation. */
344 HOWTO (R_MIPS_32
, /* type */
346 2, /* size (0 = byte, 1 = short, 2 = long) */
348 false, /* pc_relative */
350 complain_overflow_bitfield
, /* complain_on_overflow */
351 bfd_elf_generic_reloc
, /* special_function */
352 "R_MIPS_32", /* name */
353 true, /* partial_inplace */
354 0xffffffff, /* src_mask */
355 0xffffffff, /* dst_mask */
356 false), /* pcrel_offset */
358 /* 32 bit symbol relative relocation. */
359 HOWTO (R_MIPS_REL32
, /* type */
361 2, /* size (0 = byte, 1 = short, 2 = long) */
363 false, /* pc_relative */
365 complain_overflow_bitfield
, /* complain_on_overflow */
366 bfd_elf_generic_reloc
, /* special_function */
367 "R_MIPS_REL32", /* name */
368 true, /* partial_inplace */
369 0xffffffff, /* src_mask */
370 0xffffffff, /* dst_mask */
371 false), /* pcrel_offset */
373 /* 26 bit branch address. */
374 HOWTO (R_MIPS_26
, /* type */
376 2, /* size (0 = byte, 1 = short, 2 = long) */
378 false, /* pc_relative */
380 complain_overflow_dont
, /* complain_on_overflow */
381 /* This needs complex overflow
382 detection, because the upper four
383 bits must match the PC. */
384 bfd_elf_generic_reloc
, /* special_function */
385 "R_MIPS_26", /* name */
386 true, /* partial_inplace */
387 0x3ffffff, /* src_mask */
388 0x3ffffff, /* dst_mask */
389 false), /* pcrel_offset */
391 /* High 16 bits of symbol value. */
392 HOWTO (R_MIPS_HI16
, /* type */
394 2, /* size (0 = byte, 1 = short, 2 = long) */
396 false, /* pc_relative */
398 complain_overflow_dont
, /* complain_on_overflow */
399 _bfd_mips_elf_hi16_reloc
, /* special_function */
400 "R_MIPS_HI16", /* name */
401 true, /* partial_inplace */
402 0xffff, /* src_mask */
403 0xffff, /* dst_mask */
404 false), /* pcrel_offset */
406 /* Low 16 bits of symbol value. */
407 HOWTO (R_MIPS_LO16
, /* type */
409 2, /* size (0 = byte, 1 = short, 2 = long) */
411 false, /* pc_relative */
413 complain_overflow_dont
, /* complain_on_overflow */
414 _bfd_mips_elf_lo16_reloc
, /* special_function */
415 "R_MIPS_LO16", /* name */
416 true, /* partial_inplace */
417 0xffff, /* src_mask */
418 0xffff, /* dst_mask */
419 false), /* pcrel_offset */
421 /* GP relative reference. */
422 HOWTO (R_MIPS_GPREL16
, /* type */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
426 false, /* pc_relative */
428 complain_overflow_signed
, /* complain_on_overflow */
429 _bfd_mips_elf_gprel16_reloc
, /* special_function */
430 "R_MIPS_GPREL16", /* name */
431 true, /* partial_inplace */
432 0xffff, /* src_mask */
433 0xffff, /* dst_mask */
434 false), /* pcrel_offset */
436 /* Reference to literal section. */
437 HOWTO (R_MIPS_LITERAL
, /* type */
439 2, /* size (0 = byte, 1 = short, 2 = long) */
441 false, /* pc_relative */
443 complain_overflow_signed
, /* complain_on_overflow */
444 _bfd_mips_elf_gprel16_reloc
, /* special_function */
445 "R_MIPS_LITERAL", /* name */
446 true, /* partial_inplace */
447 0xffff, /* src_mask */
448 0xffff, /* dst_mask */
449 false), /* pcrel_offset */
451 /* Reference to global offset table. */
452 HOWTO (R_MIPS_GOT16
, /* type */
454 2, /* size (0 = byte, 1 = short, 2 = long) */
456 false, /* pc_relative */
458 complain_overflow_signed
, /* complain_on_overflow */
459 _bfd_mips_elf_got16_reloc
, /* special_function */
460 "R_MIPS_GOT16", /* name */
461 false, /* partial_inplace */
463 0xffff, /* dst_mask */
464 false), /* pcrel_offset */
466 /* 16 bit PC relative reference. */
467 HOWTO (R_MIPS_PC16
, /* type */
469 2, /* size (0 = byte, 1 = short, 2 = long) */
471 true, /* pc_relative */
473 complain_overflow_signed
, /* complain_on_overflow */
474 bfd_elf_generic_reloc
, /* special_function */
475 "R_MIPS_PC16", /* name */
476 true, /* partial_inplace */
477 0xffff, /* src_mask */
478 0xffff, /* dst_mask */
479 false), /* pcrel_offset */
481 /* 16 bit call through global offset table. */
482 /* FIXME: This is not handled correctly. */
483 HOWTO (R_MIPS_CALL16
, /* type */
485 2, /* size (0 = byte, 1 = short, 2 = long) */
487 false, /* pc_relative */
489 complain_overflow_signed
, /* complain_on_overflow */
490 bfd_elf_generic_reloc
, /* special_function */
491 "R_MIPS_CALL16", /* name */
492 false, /* partial_inplace */
494 0xffff, /* dst_mask */
495 false), /* pcrel_offset */
497 /* 32 bit GP relative reference. */
498 HOWTO (R_MIPS_GPREL32
, /* type */
500 2, /* size (0 = byte, 1 = short, 2 = long) */
502 false, /* pc_relative */
504 complain_overflow_bitfield
, /* complain_on_overflow */
505 _bfd_mips_elf_gprel32_reloc
, /* special_function */
506 "R_MIPS_GPREL32", /* name */
507 true, /* partial_inplace */
508 0xffffffff, /* src_mask */
509 0xffffffff, /* dst_mask */
510 false), /* pcrel_offset */
512 /* The remaining relocs are defined on Irix 5, although they are
513 not defined by the ABI. */
518 /* A 5 bit shift field. */
519 HOWTO (R_MIPS_SHIFT5
, /* type */
521 2, /* size (0 = byte, 1 = short, 2 = long) */
523 false, /* pc_relative */
525 complain_overflow_bitfield
, /* complain_on_overflow */
526 bfd_elf_generic_reloc
, /* special_function */
527 "R_MIPS_SHIFT5", /* name */
528 true, /* partial_inplace */
529 0x000007c0, /* src_mask */
530 0x000007c0, /* dst_mask */
531 false), /* pcrel_offset */
533 /* A 6 bit shift field. */
534 /* FIXME: This is not handled correctly; a special function is
535 needed to put the most significant bit in the right place. */
536 HOWTO (R_MIPS_SHIFT6
, /* type */
538 2, /* size (0 = byte, 1 = short, 2 = long) */
540 false, /* pc_relative */
542 complain_overflow_bitfield
, /* complain_on_overflow */
543 bfd_elf_generic_reloc
, /* special_function */
544 "R_MIPS_SHIFT6", /* name */
545 true, /* partial_inplace */
546 0x000007c4, /* src_mask */
547 0x000007c4, /* dst_mask */
548 false), /* pcrel_offset */
550 /* A 64 bit relocation. This is used in 32 bit ELF when addresses
551 are 64 bits long; the upper 32 bits are simply a sign extension.
552 The fields of the howto should be the same as for R_MIPS_32,
553 other than the type, name, and special_function. */
554 HOWTO (R_MIPS_64
, /* type */
556 2, /* size (0 = byte, 1 = short, 2 = long) */
558 false, /* pc_relative */
560 complain_overflow_bitfield
, /* complain_on_overflow */
561 mips32_64bit_reloc
, /* special_function */
562 "R_MIPS_64", /* name */
563 true, /* partial_inplace */
564 0xffffffff, /* src_mask */
565 0xffffffff, /* dst_mask */
566 false), /* pcrel_offset */
568 /* Displacement in the global offset table. */
569 /* FIXME: Not handled correctly. */
570 HOWTO (R_MIPS_GOT_DISP
, /* type */
572 2, /* size (0 = byte, 1 = short, 2 = long) */
574 false, /* pc_relative */
576 complain_overflow_bitfield
, /* complain_on_overflow */
577 bfd_elf_generic_reloc
, /* special_function */
578 "R_MIPS_GOT_DISP", /* name */
579 true, /* partial_inplace */
580 0x0000ffff, /* src_mask */
581 0x0000ffff, /* dst_mask */
582 false), /* pcrel_offset */
584 /* Displacement to page pointer in the global offset table. */
585 /* FIXME: Not handled correctly. */
586 HOWTO (R_MIPS_GOT_PAGE
, /* type */
588 2, /* size (0 = byte, 1 = short, 2 = long) */
590 false, /* pc_relative */
592 complain_overflow_bitfield
, /* complain_on_overflow */
593 bfd_elf_generic_reloc
, /* special_function */
594 "R_MIPS_GOT_PAGE", /* name */
595 true, /* partial_inplace */
596 0x0000ffff, /* src_mask */
597 0x0000ffff, /* dst_mask */
598 false), /* pcrel_offset */
600 /* Offset from page pointer in the global offset table. */
601 /* FIXME: Not handled correctly. */
602 HOWTO (R_MIPS_GOT_OFST
, /* type */
604 2, /* size (0 = byte, 1 = short, 2 = long) */
606 false, /* pc_relative */
608 complain_overflow_bitfield
, /* complain_on_overflow */
609 bfd_elf_generic_reloc
, /* special_function */
610 "R_MIPS_GOT_OFST", /* name */
611 true, /* partial_inplace */
612 0x0000ffff, /* src_mask */
613 0x0000ffff, /* dst_mask */
614 false), /* pcrel_offset */
616 /* High 16 bits of displacement in global offset table. */
617 /* FIXME: Not handled correctly. */
618 HOWTO (R_MIPS_GOT_HI16
, /* type */
620 2, /* size (0 = byte, 1 = short, 2 = long) */
622 false, /* pc_relative */
624 complain_overflow_dont
, /* complain_on_overflow */
625 bfd_elf_generic_reloc
, /* special_function */
626 "R_MIPS_GOT_HI16", /* name */
627 true, /* partial_inplace */
628 0x0000ffff, /* src_mask */
629 0x0000ffff, /* dst_mask */
630 false), /* pcrel_offset */
632 /* Low 16 bits of displacement in global offset table. */
633 /* FIXME: Not handled correctly. */
634 HOWTO (R_MIPS_GOT_LO16
, /* type */
636 2, /* size (0 = byte, 1 = short, 2 = long) */
638 false, /* pc_relative */
640 complain_overflow_dont
, /* complain_on_overflow */
641 bfd_elf_generic_reloc
, /* special_function */
642 "R_MIPS_GOT_LO16", /* name */
643 true, /* partial_inplace */
644 0x0000ffff, /* src_mask */
645 0x0000ffff, /* dst_mask */
646 false), /* pcrel_offset */
648 /* 64 bit subtraction. Presumably not used in 32 bit ELF. */
651 /* Used to cause the linker to insert and delete instructions? */
656 /* Get the higher values of a 64 bit addend. Presumably not used in
661 /* High 16 bits of displacement in global offset table. */
662 /* FIXME: Not handled correctly. */
663 HOWTO (R_MIPS_CALL_HI16
, /* type */
665 2, /* size (0 = byte, 1 = short, 2 = long) */
667 false, /* pc_relative */
669 complain_overflow_dont
, /* complain_on_overflow */
670 bfd_elf_generic_reloc
, /* special_function */
671 "R_MIPS_CALL_HI16", /* name */
672 true, /* partial_inplace */
673 0x0000ffff, /* src_mask */
674 0x0000ffff, /* dst_mask */
675 false), /* pcrel_offset */
677 /* Low 16 bits of displacement in global offset table. */
678 /* FIXME: Not handled correctly. */
679 HOWTO (R_MIPS_CALL_LO16
, /* type */
681 2, /* size (0 = byte, 1 = short, 2 = long) */
683 false, /* pc_relative */
685 complain_overflow_dont
, /* complain_on_overflow */
686 bfd_elf_generic_reloc
, /* special_function */
687 "R_MIPS_CALL_LO16", /* name */
688 true, /* partial_inplace */
689 0x0000ffff, /* src_mask */
690 0x0000ffff, /* dst_mask */
691 false) /* pcrel_offset */
694 /* The reloc used for the mips16 jump instruction. */
695 static reloc_howto_type elf_mips16_jump_howto
=
696 HOWTO (R_MIPS16_26
, /* type */
698 2, /* size (0 = byte, 1 = short, 2 = long) */
700 false, /* pc_relative */
702 complain_overflow_dont
, /* complain_on_overflow */
703 /* This needs complex overflow
704 detection, because the upper four
705 bits must match the PC. */
706 mips16_jump_reloc
, /* special_function */
707 "R_MIPS16_26", /* name */
708 true, /* partial_inplace */
709 0x3ffffff, /* src_mask */
710 0x3ffffff, /* dst_mask */
711 false); /* pcrel_offset */
713 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
714 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
715 the HI16. Here we just save the information we need; we do the
716 actual relocation when we see the LO16. MIPS ELF requires that the
717 LO16 immediately follow the HI16. As a GNU extension, we permit an
718 arbitrary number of HI16 relocs to be associated with a single LO16
719 reloc. This extension permits gcc to output the HI and LO relocs
724 struct mips_hi16
*next
;
729 /* FIXME: This should not be a static variable. */
731 static struct mips_hi16
*mips_hi16_list
;
733 bfd_reloc_status_type
734 _bfd_mips_elf_hi16_reloc (abfd
,
742 arelent
*reloc_entry
;
745 asection
*input_section
;
747 char **error_message
;
749 bfd_reloc_status_type ret
;
753 /* If we're relocating, and this an external symbol, we don't want
754 to change anything. */
755 if (output_bfd
!= (bfd
*) NULL
756 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
757 && reloc_entry
->addend
== 0)
759 reloc_entry
->address
+= input_section
->output_offset
;
765 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
767 boolean relocateable
;
770 if (ret
== bfd_reloc_undefined
)
773 if (output_bfd
!= NULL
)
777 relocateable
= false;
778 output_bfd
= symbol
->section
->output_section
->owner
;
781 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
783 if (ret
!= bfd_reloc_ok
)
786 relocation
= gp
- reloc_entry
->address
;
790 if (bfd_is_und_section (symbol
->section
)
791 && output_bfd
== (bfd
*) NULL
)
792 ret
= bfd_reloc_undefined
;
794 if (bfd_is_com_section (symbol
->section
))
797 relocation
= symbol
->value
;
800 relocation
+= symbol
->section
->output_section
->vma
;
801 relocation
+= symbol
->section
->output_offset
;
802 relocation
+= reloc_entry
->addend
;
804 if (reloc_entry
->address
> input_section
->_cooked_size
)
805 return bfd_reloc_outofrange
;
807 /* Save the information, and let LO16 do the actual relocation. */
808 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
810 return bfd_reloc_outofrange
;
811 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
812 n
->addend
= relocation
;
813 n
->next
= mips_hi16_list
;
816 if (output_bfd
!= (bfd
*) NULL
)
817 reloc_entry
->address
+= input_section
->output_offset
;
822 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
823 inplace relocation; this function exists in order to do the
824 R_MIPS_HI16 relocation described above. */
826 bfd_reloc_status_type
827 _bfd_mips_elf_lo16_reloc (abfd
,
835 arelent
*reloc_entry
;
838 asection
*input_section
;
840 char **error_message
;
842 arelent gp_disp_relent
;
844 if (mips_hi16_list
!= NULL
)
854 struct mips_hi16
*next
;
856 /* Do the HI16 relocation. Note that we actually don't need
857 to know anything about the LO16 itself, except where to
858 find the low 16 bits of the addend needed by the LO16. */
859 insn
= bfd_get_32 (abfd
, l
->addr
);
860 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
862 val
= ((insn
& 0xffff) << 16) + vallo
;
865 /* The low order 16 bits are always treated as a signed
866 value. Therefore, a negative value in the low order bits
867 requires an adjustment in the high order bits. We need
868 to make this adjustment in two ways: once for the bits we
869 took from the data, and once for the bits we are putting
870 back in to the data. */
871 if ((vallo
& 0x8000) != 0)
873 if ((val
& 0x8000) != 0)
876 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
877 bfd_put_32 (abfd
, insn
, l
->addr
);
879 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
881 gp_disp_relent
= *reloc_entry
;
882 reloc_entry
= &gp_disp_relent
;
883 reloc_entry
->addend
= l
->addend
;
891 mips_hi16_list
= NULL
;
893 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
895 bfd_reloc_status_type ret
;
896 bfd_vma gp
, relocation
;
898 /* FIXME: Does this case ever occur? */
900 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
901 if (ret
!= bfd_reloc_ok
)
904 relocation
= gp
- reloc_entry
->address
;
905 relocation
+= symbol
->section
->output_section
->vma
;
906 relocation
+= symbol
->section
->output_offset
;
907 relocation
+= reloc_entry
->addend
;
909 if (reloc_entry
->address
> input_section
->_cooked_size
)
910 return bfd_reloc_outofrange
;
912 gp_disp_relent
= *reloc_entry
;
913 reloc_entry
= &gp_disp_relent
;
914 reloc_entry
->addend
= relocation
- 4;
917 /* Now do the LO16 reloc in the usual way. */
918 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
919 input_section
, output_bfd
, error_message
);
922 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
923 table used for PIC code. If the symbol is an external symbol, the
924 instruction is modified to contain the offset of the appropriate
925 entry in the global offset table. If the symbol is a section
926 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
927 addends are combined to form the real addend against the section
928 symbol; the GOT16 is modified to contain the offset of an entry in
929 the global offset table, and the LO16 is modified to offset it
930 appropriately. Thus an offset larger than 16 bits requires a
931 modified value in the global offset table.
933 This implementation suffices for the assembler, but the linker does
934 not yet know how to create global offset tables. */
936 bfd_reloc_status_type
937 _bfd_mips_elf_got16_reloc (abfd
,
945 arelent
*reloc_entry
;
948 asection
*input_section
;
950 char **error_message
;
952 /* If we're relocating, and this an external symbol, we don't want
953 to change anything. */
954 if (output_bfd
!= (bfd
*) NULL
955 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
956 && reloc_entry
->addend
== 0)
958 reloc_entry
->address
+= input_section
->output_offset
;
962 /* If we're relocating, and this is a local symbol, we can handle it
964 if (output_bfd
!= (bfd
*) NULL
965 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
966 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
967 input_section
, output_bfd
, error_message
);
972 /* We have to figure out the gp value, so that we can adjust the
973 symbol value correctly. We look up the symbol _gp in the output
974 BFD. If we can't find it, we're stuck. We cache it in the ELF
975 target data. We don't need to adjust the symbol value for an
976 external symbol if we are producing relocateable output. */
978 static bfd_reloc_status_type
979 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
982 boolean relocateable
;
983 char **error_message
;
986 if (bfd_is_und_section (symbol
->section
)
990 return bfd_reloc_undefined
;
993 *pgp
= _bfd_get_gp_value (output_bfd
);
996 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1000 /* Make up a value. */
1001 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1002 _bfd_set_gp_value (output_bfd
, *pgp
);
1010 count
= bfd_get_symcount (output_bfd
);
1011 sym
= bfd_get_outsymbols (output_bfd
);
1013 if (sym
== (asymbol
**) NULL
)
1017 for (i
= 0; i
< count
; i
++, sym
++)
1019 register CONST
char *name
;
1021 name
= bfd_asymbol_name (*sym
);
1022 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1024 *pgp
= bfd_asymbol_value (*sym
);
1025 _bfd_set_gp_value (output_bfd
, *pgp
);
1033 /* Only get the error once. */
1035 _bfd_set_gp_value (output_bfd
, *pgp
);
1037 (char *) "GP relative relocation when _gp not defined";
1038 return bfd_reloc_dangerous
;
1043 return bfd_reloc_ok
;
1046 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1047 become the offset from the gp register. This function also handles
1048 R_MIPS_LITERAL relocations, although those can be handled more
1049 cleverly because the entries in the .lit8 and .lit4 sections can be
1052 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1053 arelent
*, asection
*,
1054 boolean
, PTR
, bfd_vma
));
1056 bfd_reloc_status_type
1057 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1058 output_bfd
, error_message
)
1060 arelent
*reloc_entry
;
1063 asection
*input_section
;
1065 char **error_message
;
1067 boolean relocateable
;
1068 bfd_reloc_status_type ret
;
1071 /* If we're relocating, and this is an external symbol with no
1072 addend, we don't want to change anything. We will only have an
1073 addend if this is a newly created reloc, not read from an ELF
1075 if (output_bfd
!= (bfd
*) NULL
1076 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1077 && reloc_entry
->addend
== 0)
1079 reloc_entry
->address
+= input_section
->output_offset
;
1080 return bfd_reloc_ok
;
1083 if (output_bfd
!= (bfd
*) NULL
)
1084 relocateable
= true;
1087 relocateable
= false;
1088 output_bfd
= symbol
->section
->output_section
->owner
;
1091 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1093 if (ret
!= bfd_reloc_ok
)
1096 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1097 relocateable
, data
, gp
);
1100 static bfd_reloc_status_type
1101 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1105 arelent
*reloc_entry
;
1106 asection
*input_section
;
1107 boolean relocateable
;
1115 if (bfd_is_com_section (symbol
->section
))
1118 relocation
= symbol
->value
;
1120 relocation
+= symbol
->section
->output_section
->vma
;
1121 relocation
+= symbol
->section
->output_offset
;
1123 if (reloc_entry
->address
> input_section
->_cooked_size
)
1124 return bfd_reloc_outofrange
;
1126 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1128 /* Set val to the offset into the section or symbol. */
1129 if (reloc_entry
->howto
->src_mask
== 0)
1131 /* This case occurs with the 64-bit MIPS ELF ABI. */
1132 val
= reloc_entry
->addend
;
1136 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1141 /* Adjust val for the final section location and GP value. If we
1142 are producing relocateable output, we don't want to do this for
1143 an external symbol. */
1145 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1146 val
+= relocation
- gp
;
1148 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1149 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1152 reloc_entry
->address
+= input_section
->output_offset
;
1154 /* Make sure it fit in 16 bits. */
1155 if (val
>= 0x8000 && val
< 0xffff8000)
1156 return bfd_reloc_overflow
;
1158 return bfd_reloc_ok
;
1161 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1162 from the gp register? XXX */
1164 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1165 arelent
*, asection
*,
1166 boolean
, PTR
, bfd_vma
));
1168 bfd_reloc_status_type
1169 _bfd_mips_elf_gprel32_reloc (abfd
,
1177 arelent
*reloc_entry
;
1180 asection
*input_section
;
1182 char **error_message
;
1184 boolean relocateable
;
1185 bfd_reloc_status_type ret
;
1188 /* If we're relocating, and this is an external symbol with no
1189 addend, we don't want to change anything. We will only have an
1190 addend if this is a newly created reloc, not read from an ELF
1192 if (output_bfd
!= (bfd
*) NULL
1193 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1194 && reloc_entry
->addend
== 0)
1196 *error_message
= (char *)
1197 "32bits gp relative relocation occurs for an external symbol";
1198 return bfd_reloc_outofrange
;
1201 if (output_bfd
!= (bfd
*) NULL
)
1203 relocateable
= true;
1204 gp
= _bfd_get_gp_value (output_bfd
);
1208 relocateable
= false;
1209 output_bfd
= symbol
->section
->output_section
->owner
;
1211 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1212 error_message
, &gp
);
1213 if (ret
!= bfd_reloc_ok
)
1217 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1218 relocateable
, data
, gp
);
1221 static bfd_reloc_status_type
1222 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1226 arelent
*reloc_entry
;
1227 asection
*input_section
;
1228 boolean relocateable
;
1235 if (bfd_is_com_section (symbol
->section
))
1238 relocation
= symbol
->value
;
1240 relocation
+= symbol
->section
->output_section
->vma
;
1241 relocation
+= symbol
->section
->output_offset
;
1243 if (reloc_entry
->address
> input_section
->_cooked_size
)
1244 return bfd_reloc_outofrange
;
1246 if (reloc_entry
->howto
->src_mask
== 0)
1248 /* This case arises with the 64-bit MIPS ELF ABI. */
1252 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1254 /* Set val to the offset into the section or symbol. */
1255 val
+= reloc_entry
->addend
;
1257 /* Adjust val for the final section location and GP value. If we
1258 are producing relocateable output, we don't want to do this for
1259 an external symbol. */
1261 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1262 val
+= relocation
- gp
;
1264 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1267 reloc_entry
->address
+= input_section
->output_offset
;
1269 return bfd_reloc_ok
;
1272 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1273 generated when addreses are 64 bits. The upper 32 bits are a simle
1276 static bfd_reloc_status_type
1277 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1278 output_bfd
, error_message
)
1280 arelent
*reloc_entry
;
1283 asection
*input_section
;
1285 char **error_message
;
1287 bfd_reloc_status_type r
;
1292 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1293 input_section
, output_bfd
, error_message
);
1294 if (r
!= bfd_reloc_continue
)
1297 /* Do a normal 32 bit relocation on the lower 32 bits. */
1298 reloc32
= *reloc_entry
;
1299 if (bfd_big_endian (abfd
))
1300 reloc32
.address
+= 4;
1301 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1302 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1303 output_bfd
, error_message
);
1305 /* Sign extend into the upper 32 bits. */
1306 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1307 if ((val
& 0x80000000) != 0)
1311 addr
= reloc_entry
->address
;
1312 if (bfd_little_endian (abfd
))
1314 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1319 /* Handle a mips16 jump. */
1321 static bfd_reloc_status_type
1322 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1323 output_bfd
, error_message
)
1325 arelent
*reloc_entry
;
1328 asection
*input_section
;
1330 char **error_message
;
1332 if (output_bfd
!= (bfd
*) NULL
1333 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1334 && reloc_entry
->addend
== 0)
1336 reloc_entry
->address
+= input_section
->output_offset
;
1337 return bfd_reloc_ok
;
1344 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1346 struct elf_reloc_map
{
1347 bfd_reloc_code_real_type bfd_reloc_val
;
1348 enum reloc_type elf_reloc_val
;
1351 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1353 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1354 { BFD_RELOC_16
, R_MIPS_16
},
1355 { BFD_RELOC_32
, R_MIPS_32
},
1356 { BFD_RELOC_CTOR
, R_MIPS_32
},
1357 { BFD_RELOC_64
, R_MIPS_64
},
1358 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1359 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1360 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1361 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1362 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1363 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1364 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1365 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1366 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1367 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1368 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1369 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1370 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
}
1373 /* Given a BFD reloc type, return a howto structure. */
1375 static reloc_howto_type
*
1376 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1378 bfd_reloc_code_real_type code
;
1382 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1384 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1385 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1388 /* Special handling for the MIPS16 jump, since it is a made up reloc
1389 type with a large value. */
1390 if (code
== BFD_RELOC_MIPS16_JMP
)
1391 return &elf_mips16_jump_howto
;
1396 /* Given a MIPS reloc type, fill in an arelent structure. */
1399 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1402 Elf32_Internal_Rel
*dst
;
1404 unsigned int r_type
;
1406 r_type
= ELF32_R_TYPE (dst
->r_info
);
1407 if (r_type
== R_MIPS16_26
)
1408 cache_ptr
->howto
= &elf_mips16_jump_howto
;
1411 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1412 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1415 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1416 value for the object file. We get the addend now, rather than
1417 when we do the relocation, because the symbol manipulations done
1418 by the linker may cause us to lose track of the input BFD. */
1419 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1420 && (r_type
== (unsigned int) R_MIPS_GPREL16
1421 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1422 cache_ptr
->addend
= elf_gp (abfd
);
1425 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1426 routines swap this structure in and out. They are used outside of
1427 BFD, so they are globally visible. */
1430 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1432 const Elf32_External_RegInfo
*ex
;
1435 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1436 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1437 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1438 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1439 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1440 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1444 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1446 const Elf32_RegInfo
*in
;
1447 Elf32_External_RegInfo
*ex
;
1449 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1450 (bfd_byte
*) ex
->ri_gprmask
);
1451 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1452 (bfd_byte
*) ex
->ri_cprmask
[0]);
1453 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1454 (bfd_byte
*) ex
->ri_cprmask
[1]);
1455 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1456 (bfd_byte
*) ex
->ri_cprmask
[2]);
1457 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1458 (bfd_byte
*) ex
->ri_cprmask
[3]);
1459 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1460 (bfd_byte
*) ex
->ri_gp_value
);
1463 /* In the 64 bit ABI, the .MIPS.options section holds register
1464 information in an Elf64_Reginfo structure. These routines swap
1465 them in and out. They are globally visible because they are used
1466 outside of BFD. These routines are here so that gas can call them
1467 without worrying about whether the 64 bit ABI has been included. */
1470 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1472 const Elf64_External_RegInfo
*ex
;
1473 Elf64_Internal_RegInfo
*in
;
1475 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1476 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
1477 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1478 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1479 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1480 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1481 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1485 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1487 const Elf64_Internal_RegInfo
*in
;
1488 Elf64_External_RegInfo
*ex
;
1490 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1491 (bfd_byte
*) ex
->ri_gprmask
);
1492 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
1493 (bfd_byte
*) ex
->ri_pad
);
1494 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1495 (bfd_byte
*) ex
->ri_cprmask
[0]);
1496 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1497 (bfd_byte
*) ex
->ri_cprmask
[1]);
1498 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1499 (bfd_byte
*) ex
->ri_cprmask
[2]);
1500 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1501 (bfd_byte
*) ex
->ri_cprmask
[3]);
1502 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1503 (bfd_byte
*) ex
->ri_gp_value
);
1506 /* Swap an entry in a .gptab section. Note that these routines rely
1507 on the equivalence of the two elements of the union. */
1510 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1512 const Elf32_External_gptab
*ex
;
1515 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1516 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1520 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1522 const Elf32_gptab
*in
;
1523 Elf32_External_gptab
*ex
;
1525 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1526 ex
->gt_entry
.gt_g_value
);
1527 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1528 ex
->gt_entry
.gt_bytes
);
1532 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1534 const Elf32_compact_rel
*in
;
1535 Elf32_External_compact_rel
*ex
;
1537 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
1538 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
1539 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
1540 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
1541 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
1542 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
1546 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1548 const Elf32_crinfo
*in
;
1549 Elf32_External_crinfo
*ex
;
1553 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1554 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1555 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1556 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1557 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
1558 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
1559 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
1562 /* Swap in an options header. */
1565 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1567 const Elf_External_Options
*ex
;
1568 Elf_Internal_Options
*in
;
1570 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
1571 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
1572 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
1573 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
1576 /* Swap out an options header. */
1579 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
1581 const Elf_Internal_Options
*in
;
1582 Elf_External_Options
*ex
;
1584 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
1585 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
1586 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
1587 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
1590 /* Determine whether a symbol is global for the purposes of splitting
1591 the symbol table into global symbols and local symbols. At least
1592 on Irix 5, this split must be between section symbols and all other
1593 symbols. On most ELF targets the split is between static symbols
1594 and externally visible symbols. */
1598 mips_elf_sym_is_global (abfd
, sym
)
1602 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
1605 /* Set the right machine number for a MIPS ELF file. This is used for
1606 both the 32-bit and the 64-bit ABI. */
1609 _bfd_mips_elf_object_p (abfd
)
1612 switch (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
)
1616 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 3000);
1620 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 6000);
1624 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 4000);
1628 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 8000);
1635 /* Set the right machine number for a 32-bit MIPS ELF file. */
1638 mips_elf32_object_p (abfd
)
1641 /* Irix 5 is broken. Object file symbol tables are not always
1642 sorted correctly such that local symbols precede global symbols,
1643 and the sh_info field in the symbol table is not always right. */
1644 elf_bad_symtab (abfd
) = true;
1646 return _bfd_mips_elf_object_p (abfd
);
1649 /* The final processing done just before writing out a MIPS ELF object
1650 file. This gets the MIPS architecture right based on the machine
1651 number. This is used by both the 32-bit and the 64-bit ABI. */
1655 _bfd_mips_elf_final_write_processing (abfd
, linker
)
1661 Elf_Internal_Shdr
**hdrpp
;
1665 switch (bfd_get_mach (abfd
))
1668 val
= E_MIPS_ARCH_1
;
1672 val
= E_MIPS_ARCH_2
;
1676 val
= E_MIPS_ARCH_3
;
1680 val
= E_MIPS_ARCH_4
;
1688 elf_elfheader (abfd
)->e_flags
&=~ EF_MIPS_ARCH
;
1689 elf_elfheader (abfd
)->e_flags
|= val
;
1691 /* Set the sh_info field for .gptab sections. */
1692 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
1693 i
< elf_elfheader (abfd
)->e_shnum
;
1696 switch ((*hdrpp
)->sh_type
)
1698 case SHT_MIPS_LIBLIST
:
1699 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
1701 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
1704 case SHT_MIPS_GPTAB
:
1705 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1706 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1707 BFD_ASSERT (name
!= NULL
1708 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
1709 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
1710 BFD_ASSERT (sec
!= NULL
);
1711 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1714 case SHT_MIPS_CONTENT
:
1715 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1716 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1717 BFD_ASSERT (name
!= NULL
1718 && strncmp (name
, ".MIPS.content",
1719 sizeof ".MIPS.content" - 1) == 0);
1720 sec
= bfd_get_section_by_name (abfd
,
1721 name
+ sizeof ".MIPS.content" - 1);
1722 BFD_ASSERT (sec
!= NULL
);
1723 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1726 case SHT_MIPS_SYMBOL_LIB
:
1727 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
1729 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
1730 sec
= bfd_get_section_by_name (abfd
, ".liblist");
1732 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1735 case SHT_MIPS_EVENTS
:
1736 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1737 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1738 BFD_ASSERT (name
!= NULL
);
1739 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
1740 sec
= bfd_get_section_by_name (abfd
,
1741 name
+ sizeof ".MIPS.events" - 1);
1744 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
1745 sizeof ".MIPS.post_rel" - 1) == 0);
1746 sec
= bfd_get_section_by_name (abfd
,
1748 + sizeof ".MIPS.post_rel" - 1));
1750 BFD_ASSERT (sec
!= NULL
);
1751 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
1757 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
1760 _bfd_mips_elf_set_private_flags (abfd
, flags
)
1764 BFD_ASSERT (!elf_flags_init (abfd
)
1765 || elf_elfheader (abfd
)->e_flags
== flags
);
1767 elf_elfheader (abfd
)->e_flags
= flags
;
1768 elf_flags_init (abfd
) = true;
1772 /* Copy backend specific data from one object module to another */
1775 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
1779 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1780 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1783 BFD_ASSERT (!elf_flags_init (obfd
)
1784 || (elf_elfheader (obfd
)->e_flags
1785 == elf_elfheader (ibfd
)->e_flags
));
1787 elf_gp (obfd
) = elf_gp (ibfd
);
1788 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1789 elf_flags_init (obfd
) = true;
1793 /* Return the ISA for a MIPS e_flags value. */
1796 elf_mips_isa (flags
)
1799 switch (flags
& EF_MIPS_ARCH
)
1813 /* Merge backend specific data from an object file to the output
1814 object file when linking. */
1817 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
1825 /* Check if we have the same endianess */
1826 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1827 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1829 (*_bfd_error_handler
)
1830 ("%s: compiled for a %s endian system and target is %s endian",
1831 bfd_get_filename (ibfd
),
1832 bfd_big_endian (ibfd
) ? "big" : "little",
1833 bfd_big_endian (obfd
) ? "big" : "little");
1835 bfd_set_error (bfd_error_wrong_format
);
1839 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1840 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1843 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1844 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
1845 old_flags
= elf_elfheader (obfd
)->e_flags
;
1847 if (! elf_flags_init (obfd
))
1849 elf_flags_init (obfd
) = true;
1850 elf_elfheader (obfd
)->e_flags
= new_flags
;
1852 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
1853 && bfd_get_arch_info (obfd
)->the_default
)
1855 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
1856 bfd_get_mach (ibfd
)))
1863 /* Check flag compatibility. */
1865 new_flags
&= ~EF_MIPS_NOREORDER
;
1866 old_flags
&= ~EF_MIPS_NOREORDER
;
1868 if (new_flags
== old_flags
)
1873 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
1875 new_flags
&= ~EF_MIPS_PIC
;
1876 old_flags
&= ~EF_MIPS_PIC
;
1877 (*_bfd_error_handler
)
1878 ("%s: linking PIC files with non-PIC files",
1879 bfd_get_filename (ibfd
));
1883 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
1885 new_flags
&= ~EF_MIPS_CPIC
;
1886 old_flags
&= ~EF_MIPS_CPIC
;
1887 (*_bfd_error_handler
)
1888 ("%s: linking abicalls files with non-abicalls files",
1889 bfd_get_filename (ibfd
));
1893 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
1894 and -mips4 code. They will normally use the same data sizes and
1895 calling conventions. */
1896 if ((new_flags
& EF_MIPS_ARCH
) != (old_flags
& EF_MIPS_ARCH
))
1898 int new_isa
, old_isa
;
1900 new_isa
= elf_mips_isa (new_flags
);
1901 old_isa
= elf_mips_isa (old_flags
);
1902 if ((new_isa
== 1 || new_isa
== 2)
1903 ? (old_isa
!= 1 && old_isa
!= 2)
1904 : (old_isa
== 1 || old_isa
== 2))
1906 (*_bfd_error_handler
)
1907 ("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)",
1908 bfd_get_filename (ibfd
), new_isa
, old_isa
);
1912 new_flags
&= ~ EF_MIPS_ARCH
;
1913 old_flags
&= ~ EF_MIPS_ARCH
;
1916 /* Warn about any other mismatches */
1917 if (new_flags
!= old_flags
)
1919 (*_bfd_error_handler
)
1920 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1921 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
1922 (unsigned long) old_flags
);
1928 bfd_set_error (bfd_error_bad_value
);
1935 /* Handle a MIPS specific section when reading an object file. This
1936 is called when elfcode.h finds a section with an unknown type.
1937 This routine supports both the 32-bit and 64-bit ELF ABI.
1939 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
1943 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
1945 Elf_Internal_Shdr
*hdr
;
1948 /* There ought to be a place to keep ELF backend specific flags, but
1949 at the moment there isn't one. We just keep track of the
1950 sections by their name, instead. Fortunately, the ABI gives
1951 suggested names for all the MIPS specific sections, so we will
1952 probably get away with this. */
1953 switch (hdr
->sh_type
)
1955 case SHT_MIPS_LIBLIST
:
1956 if (strcmp (name
, ".liblist") != 0)
1960 if (strcmp (name
, ".msym") != 0)
1963 case SHT_MIPS_CONFLICT
:
1964 if (strcmp (name
, ".conflict") != 0)
1967 case SHT_MIPS_GPTAB
:
1968 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
1971 case SHT_MIPS_UCODE
:
1972 if (strcmp (name
, ".ucode") != 0)
1975 case SHT_MIPS_DEBUG
:
1976 if (strcmp (name
, ".mdebug") != 0)
1979 case SHT_MIPS_REGINFO
:
1980 if (strcmp (name
, ".reginfo") != 0
1981 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
1984 case SHT_MIPS_IFACE
:
1985 if (strcmp (name
, ".MIPS.interfaces") != 0)
1988 case SHT_MIPS_CONTENT
:
1989 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
1992 case SHT_MIPS_OPTIONS
:
1993 if (strcmp (name
, ".options") != 0
1994 && strcmp (name
, ".MIPS.options") != 0)
1997 case SHT_MIPS_DWARF
:
1998 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2001 case SHT_MIPS_SYMBOL_LIB
:
2002 if (strcmp (name
, ".MIPS.symlib") != 0)
2005 case SHT_MIPS_EVENTS
:
2006 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2007 && strncmp (name
, ".MIPS.post_rel",
2008 sizeof ".MIPS.post_rel" - 1) != 0)
2015 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2018 if (hdr
->sh_type
== SHT_MIPS_DEBUG
)
2020 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
2021 (bfd_get_section_flags (abfd
,
2030 /* Handle a 32-bit MIPS ELF specific section. */
2033 mips_elf32_section_from_shdr (abfd
, hdr
, name
)
2035 Elf_Internal_Shdr
*hdr
;
2038 if (! _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
))
2041 /* FIXME: We should record sh_info for a .gptab section. */
2043 /* For a .reginfo section, set the gp value in the tdata information
2044 from the contents of this section. We need the gp value while
2045 processing relocs, so we just get it now. The .reginfo section
2046 is not used in the 64-bit MIPS ELF ABI. */
2047 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2049 Elf32_External_RegInfo ext
;
2052 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
2053 (file_ptr
) 0, sizeof ext
))
2055 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
2056 elf_gp (abfd
) = s
.ri_gp_value
;
2059 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2060 set the gp value based on what we find. We may see both
2061 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2062 they should agree. */
2063 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
2065 bfd_byte
*contents
, *l
, *lend
;
2067 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
2068 if (contents
== NULL
)
2070 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
2071 (file_ptr
) 0, hdr
->sh_size
))
2077 lend
= contents
+ hdr
->sh_size
;
2078 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2080 Elf_Internal_Options intopt
;
2082 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2084 if (intopt
.kind
== ODK_REGINFO
)
2086 Elf32_RegInfo intreg
;
2088 bfd_mips_elf32_swap_reginfo_in
2090 ((Elf32_External_RegInfo
*)
2091 (l
+ sizeof (Elf_External_Options
))),
2093 elf_gp (abfd
) = intreg
.ri_gp_value
;
2103 /* Set the correct type for a MIPS ELF section. We do this by the
2104 section name, which is a hack, but ought to work. This routine is
2105 used by both the 32-bit and the 64-bit ABI. */
2108 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
2110 Elf32_Internal_Shdr
*hdr
;
2113 register const char *name
;
2115 name
= bfd_get_section_name (abfd
, sec
);
2117 if (strcmp (name
, ".liblist") == 0)
2119 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
2120 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
2121 /* The sh_link field is set in final_write_processing. */
2123 else if (strcmp (name
, ".msym") == 0)
2125 hdr
->sh_type
= SHT_MIPS_MSYM
;
2126 hdr
->sh_entsize
= 8;
2127 /* FIXME: Set the sh_info field. */
2129 else if (strcmp (name
, ".conflict") == 0)
2130 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
2131 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2133 hdr
->sh_type
= SHT_MIPS_GPTAB
;
2134 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
2135 /* The sh_info field is set in final_write_processing. */
2137 else if (strcmp (name
, ".ucode") == 0)
2138 hdr
->sh_type
= SHT_MIPS_UCODE
;
2139 else if (strcmp (name
, ".mdebug") == 0)
2141 hdr
->sh_type
= SHT_MIPS_DEBUG
;
2142 /* In a shared object on Irix 5.3, the .mdebug section has an
2143 entsize of 0. FIXME: Does this matter? */
2144 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2145 hdr
->sh_entsize
= 0;
2147 hdr
->sh_entsize
= 1;
2149 else if (strcmp (name
, ".reginfo") == 0)
2151 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2152 /* In a shared object on Irix 5.3, the .reginfo section has an
2153 entsize of 0x18. FIXME: Does this matter? */
2154 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2155 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2157 hdr
->sh_entsize
= 1;
2159 /* Force the section size to the correct value, even if the
2160 linker thinks it is larger. The link routine below will only
2161 write out this much data for .reginfo. */
2162 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf32_External_RegInfo
);
2164 else if (SGI_COMPAT (abfd
)
2165 && (strcmp (name
, ".hash") == 0
2166 || strcmp (name
, ".dynamic") == 0
2167 || strcmp (name
, ".dynstr") == 0))
2169 hdr
->sh_entsize
= 0;
2170 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2172 else if (strcmp (name
, ".got") == 0
2173 || strcmp (name
, ".sdata") == 0
2174 || strcmp (name
, ".sbss") == 0
2175 || strcmp (name
, ".lit4") == 0
2176 || strcmp (name
, ".lit8") == 0)
2177 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2178 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2180 hdr
->sh_type
= SHT_MIPS_IFACE
;
2181 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2183 else if (strcmp (name
, ".MIPS.content") == 0)
2185 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2186 /* The sh_info field is set in final_write_processing. */
2188 else if (strcmp (name
, ".options") == 0
2189 || strcmp (name
, ".MIPS.options") == 0)
2191 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2192 hdr
->sh_entsize
= 1;
2193 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2195 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2196 hdr
->sh_type
= SHT_MIPS_DWARF
;
2197 else if (strcmp (name
, ".MIPS.symlib") == 0)
2199 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2200 /* The sh_link and sh_info fields are set in
2201 final_write_processing. */
2203 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2204 || strncmp (name
, ".MIPS.post_rel",
2205 sizeof ".MIPS.post_rel" - 1) == 0)
2207 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2208 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2209 /* The sh_link field is set in final_write_processing. */
2215 /* Given a BFD section, try to locate the corresponding ELF section
2216 index. This is used by both the 32-bit and the 64-bit ABI.
2217 Actually, it's not clear to me that the 64-bit ABI supports these,
2218 but for non-PIC objects we will certainly want support for at least
2219 the .scommon section. */
2222 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2224 Elf32_Internal_Shdr
*hdr
;
2228 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2230 *retval
= SHN_MIPS_SCOMMON
;
2233 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2235 *retval
= SHN_MIPS_ACOMMON
;
2241 /* When are writing out the .options or .MIPS.options section,
2242 remember the bytes we are writing out, so that we can install the
2243 GP value in the section_processing routine. */
2246 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2251 bfd_size_type count
;
2253 if (strcmp (section
->name
, ".options") == 0
2254 || strcmp (section
->name
, ".MIPS.options") == 0)
2258 if (elf_section_data (section
) == NULL
)
2260 section
->used_by_bfd
=
2261 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
2262 if (elf_section_data (section
) == NULL
)
2265 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
2270 if (section
->_cooked_size
!= 0)
2271 size
= section
->_cooked_size
;
2273 size
= section
->_raw_size
;
2274 c
= (PTR
) bfd_zalloc (abfd
, size
);
2277 elf_section_data (section
)->tdata
= (PTR
) c
;
2280 memcpy (c
+ offset
, location
, count
);
2283 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
2287 /* Work over a section just before writing it out. This routine is
2288 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2289 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2293 _bfd_mips_elf_section_processing (abfd
, hdr
)
2295 Elf_Internal_Shdr
*hdr
;
2297 if (hdr
->bfd_section
!= NULL
)
2299 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
2301 if (strcmp (name
, ".sdata") == 0)
2303 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2304 hdr
->sh_type
= SHT_PROGBITS
;
2306 else if (strcmp (name
, ".sbss") == 0)
2308 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2309 hdr
->sh_type
= SHT_NOBITS
;
2311 else if (strcmp (name
, ".lit8") == 0
2312 || strcmp (name
, ".lit4") == 0)
2314 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2315 hdr
->sh_type
= SHT_PROGBITS
;
2317 else if (strcmp (name
, ".compact_rel") == 0)
2320 hdr
->sh_type
= SHT_PROGBITS
;
2322 else if (strcmp (name
, ".rtproc") == 0)
2324 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
2326 unsigned int adjust
;
2328 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
2330 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
2338 /* Work over a section just before writing it out. We update the GP
2339 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2340 on the value we are using. */
2343 mips_elf32_section_processing (abfd
, hdr
)
2345 Elf32_Internal_Shdr
*hdr
;
2347 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2351 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2352 BFD_ASSERT (hdr
->contents
== NULL
);
2355 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2358 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2359 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2363 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2364 && hdr
->bfd_section
!= NULL
2365 && elf_section_data (hdr
->bfd_section
) != NULL
2366 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2368 bfd_byte
*contents
, *l
, *lend
;
2370 /* We stored the section contents in the elf_section_data tdata
2371 field in the set_section_contents routine. We save the
2372 section contents so that we don't have to read them again.
2373 At this point we know that elf_gp is set, so we can look
2374 through the section contents to see if there is an
2375 ODK_REGINFO structure. */
2377 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2379 lend
= contents
+ hdr
->sh_size
;
2380 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2382 Elf_Internal_Options intopt
;
2384 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2386 if (intopt
.kind
== ODK_REGINFO
)
2393 + sizeof (Elf_External_Options
)
2394 + (sizeof (Elf32_External_RegInfo
) - 4)),
2397 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
2398 if (bfd_write (buf
, 1, 4, abfd
) != 4)
2405 return _bfd_mips_elf_section_processing (abfd
, hdr
);
2408 /* MIPS ELF uses two common sections. One is the usual one, and the
2409 other is for small objects. All the small objects are kept
2410 together, and then referenced via the gp pointer, which yields
2411 faster assembler code. This is what we use for the small common
2412 section. This approach is copied from ecoff.c. */
2413 static asection mips_elf_scom_section
;
2414 static asymbol mips_elf_scom_symbol
;
2415 static asymbol
*mips_elf_scom_symbol_ptr
;
2417 /* MIPS ELF also uses an acommon section, which represents an
2418 allocated common symbol which may be overridden by a
2419 definition in a shared library. */
2420 static asection mips_elf_acom_section
;
2421 static asymbol mips_elf_acom_symbol
;
2422 static asymbol
*mips_elf_acom_symbol_ptr
;
2424 /* The Irix 5 support uses two virtual sections, which represent
2425 text/data symbols defined in dynamic objects. */
2426 static asection mips_elf_text_section
;
2427 static asection
*mips_elf_text_section_ptr
;
2428 static asymbol mips_elf_text_symbol
;
2429 static asymbol
*mips_elf_text_symbol_ptr
;
2431 static asection mips_elf_data_section
;
2432 static asection
*mips_elf_data_section_ptr
;
2433 static asymbol mips_elf_data_symbol
;
2434 static asymbol
*mips_elf_data_symbol_ptr
;
2436 /* Handle the special MIPS section numbers that a symbol may use.
2437 This is used for both the 32-bit and the 64-bit ABI. */
2440 _bfd_mips_elf_symbol_processing (abfd
, asym
)
2444 elf_symbol_type
*elfsym
;
2446 elfsym
= (elf_symbol_type
*) asym
;
2447 switch (elfsym
->internal_elf_sym
.st_shndx
)
2449 case SHN_MIPS_ACOMMON
:
2450 /* This section is used in a dynamically linked executable file.
2451 It is an allocated common section. The dynamic linker can
2452 either resolve these symbols to something in a shared
2453 library, or it can just leave them here. For our purposes,
2454 we can consider these symbols to be in a new section. */
2455 if (mips_elf_acom_section
.name
== NULL
)
2457 /* Initialize the acommon section. */
2458 mips_elf_acom_section
.name
= ".acommon";
2459 mips_elf_acom_section
.flags
= SEC_ALLOC
;
2460 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
2461 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
2462 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
2463 mips_elf_acom_symbol
.name
= ".acommon";
2464 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
2465 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
2466 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
2468 asym
->section
= &mips_elf_acom_section
;
2472 /* Common symbols less than the GP size are automatically
2473 treated as SHN_MIPS_SCOMMON symbols. */
2474 if (asym
->value
> elf_gp_size (abfd
))
2477 case SHN_MIPS_SCOMMON
:
2478 if (mips_elf_scom_section
.name
== NULL
)
2480 /* Initialize the small common section. */
2481 mips_elf_scom_section
.name
= ".scommon";
2482 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
2483 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
2484 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
2485 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
2486 mips_elf_scom_symbol
.name
= ".scommon";
2487 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2488 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
2489 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
2491 asym
->section
= &mips_elf_scom_section
;
2492 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2495 case SHN_MIPS_SUNDEFINED
:
2496 asym
->section
= bfd_und_section_ptr
;
2499 #if 0 /* for SGI_COMPAT */
2501 asym
->section
= mips_elf_text_section_ptr
;
2505 asym
->section
= mips_elf_data_section_ptr
;
2511 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
2515 mips_elf_additional_program_headers (abfd
)
2523 if (! SGI_COMPAT (abfd
))
2526 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2527 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2529 /* We need a PT_MIPS_REGINFO segment. */
2533 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2534 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2536 /* We need a PT_MIPS_RTPROC segment. */
2543 /* Modify the segment map for an Irix 5 executable. */
2546 mips_elf_modify_segment_map (abfd
)
2550 struct elf_segment_map
*m
, **pm
;
2552 if (! SGI_COMPAT (abfd
))
2555 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
2557 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2558 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2560 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2561 if (m
->p_type
== PT_MIPS_REGINFO
)
2565 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2569 m
->p_type
= PT_MIPS_REGINFO
;
2573 /* We want to put it after the PHDR and INTERP segments. */
2574 pm
= &elf_tdata (abfd
)->segment_map
;
2576 && ((*pm
)->p_type
== PT_PHDR
2577 || (*pm
)->p_type
== PT_INTERP
))
2585 /* If there are .dynamic and .mdebug sections, we make a room for
2586 the RTPROC header. FIXME: Rewrite without section names. */
2587 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
2588 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2589 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2591 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2592 if (m
->p_type
== PT_MIPS_RTPROC
)
2596 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2600 m
->p_type
= PT_MIPS_RTPROC
;
2602 s
= bfd_get_section_by_name (abfd
, ".rtproc");
2607 m
->p_flags_valid
= 1;
2615 /* We want to put it after the DYNAMIC segment. */
2616 pm
= &elf_tdata (abfd
)->segment_map
;
2617 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
2627 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
2628 .dynsym, and .hash sections, and everything in between. */
2629 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
2630 if ((*pm
)->p_type
== PT_DYNAMIC
)
2635 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
2637 static const char *sec_names
[] =
2638 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
2641 struct elf_segment_map
*n
;
2645 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
2647 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
2648 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2654 sz
= s
->_cooked_size
;
2657 if (high
< s
->vma
+ sz
)
2663 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2664 if ((s
->flags
& SEC_LOAD
) != 0
2667 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2671 n
= ((struct elf_segment_map
*)
2672 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
2679 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2681 if ((s
->flags
& SEC_LOAD
) != 0
2684 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2698 /* The structure of the runtime procedure descriptor created by the
2699 loader for use by the static exception system. */
2701 typedef struct runtime_pdr
{
2702 bfd_vma adr
; /* memory address of start of procedure */
2703 long regmask
; /* save register mask */
2704 long regoffset
; /* save register offset */
2705 long fregmask
; /* save floating point register mask */
2706 long fregoffset
; /* save floating point register offset */
2707 long frameoffset
; /* frame size */
2708 short framereg
; /* frame pointer register */
2709 short pcreg
; /* offset or reg of return pc */
2710 long irpss
; /* index into the runtime string table */
2712 struct exception_info
*exception_info
;/* pointer to exception array */
2714 #define cbRPDR sizeof(RPDR)
2715 #define rpdNil ((pRPDR) 0)
2717 /* Swap RPDR (runtime procedure table entry) for output. */
2719 static void ecoff_swap_rpdr_out
2720 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
2723 ecoff_swap_rpdr_out (abfd
, in
, ex
)
2726 struct rpdr_ext
*ex
;
2728 /* ecoff_put_off was defined in ecoffswap.h. */
2729 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
2730 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
2731 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
2732 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
2733 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
2734 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
2736 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
2737 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
2739 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
2741 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
2745 /* Read ECOFF debugging information from a .mdebug section into a
2746 ecoff_debug_info structure. */
2749 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
2752 struct ecoff_debug_info
*debug
;
2755 const struct ecoff_debug_swap
*swap
;
2756 char *ext_hdr
= NULL
;
2758 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2760 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
2761 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
2764 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
2765 swap
->external_hdr_size
)
2769 symhdr
= &debug
->symbolic_header
;
2770 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
2772 /* The symbolic header contains absolute file offsets and sizes to
2774 #define READ(ptr, offset, count, size, type) \
2775 if (symhdr->count == 0) \
2776 debug->ptr = NULL; \
2779 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
2780 if (debug->ptr == NULL) \
2781 goto error_return; \
2782 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
2783 || (bfd_read (debug->ptr, size, symhdr->count, \
2784 abfd) != size * symhdr->count)) \
2785 goto error_return; \
2788 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
2789 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
2790 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
2791 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
2792 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
2793 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
2795 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
2796 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
2797 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
2798 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
2799 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
2803 debug
->adjust
= NULL
;
2808 if (ext_hdr
!= NULL
)
2810 if (debug
->line
!= NULL
)
2812 if (debug
->external_dnr
!= NULL
)
2813 free (debug
->external_dnr
);
2814 if (debug
->external_pdr
!= NULL
)
2815 free (debug
->external_pdr
);
2816 if (debug
->external_sym
!= NULL
)
2817 free (debug
->external_sym
);
2818 if (debug
->external_opt
!= NULL
)
2819 free (debug
->external_opt
);
2820 if (debug
->external_aux
!= NULL
)
2821 free (debug
->external_aux
);
2822 if (debug
->ss
!= NULL
)
2824 if (debug
->ssext
!= NULL
)
2825 free (debug
->ssext
);
2826 if (debug
->external_fdr
!= NULL
)
2827 free (debug
->external_fdr
);
2828 if (debug
->external_rfd
!= NULL
)
2829 free (debug
->external_rfd
);
2830 if (debug
->external_ext
!= NULL
)
2831 free (debug
->external_ext
);
2835 /* MIPS ELF local labels start with '$', not 'L'. */
2839 mips_elf_is_local_label (abfd
, symbol
)
2843 return symbol
->name
[0] == '$';
2846 /* MIPS ELF uses a special find_nearest_line routine in order the
2847 handle the ECOFF debugging information. */
2849 struct mips_elf_find_line
2851 struct ecoff_debug_info d
;
2852 struct ecoff_find_line i
;
2856 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
2857 functionname_ptr
, line_ptr
)
2862 const char **filename_ptr
;
2863 const char **functionname_ptr
;
2864 unsigned int *line_ptr
;
2868 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
2872 struct mips_elf_find_line
*fi
;
2873 const struct ecoff_debug_swap
* const swap
=
2874 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2876 /* If we are called during a link, mips_elf_final_link may have
2877 cleared the SEC_HAS_CONTENTS field. We force it back on here
2878 if appropriate (which it normally will be). */
2879 origflags
= msec
->flags
;
2880 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
2881 msec
->flags
|= SEC_HAS_CONTENTS
;
2883 fi
= elf_tdata (abfd
)->find_line_info
;
2886 bfd_size_type external_fdr_size
;
2889 struct fdr
*fdr_ptr
;
2891 fi
= ((struct mips_elf_find_line
*)
2892 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
2895 msec
->flags
= origflags
;
2899 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
2901 msec
->flags
= origflags
;
2905 /* Swap in the FDR information. */
2906 fi
->d
.fdr
= ((struct fdr
*)
2908 (fi
->d
.symbolic_header
.ifdMax
*
2909 sizeof (struct fdr
))));
2910 if (fi
->d
.fdr
== NULL
)
2912 msec
->flags
= origflags
;
2915 external_fdr_size
= swap
->external_fdr_size
;
2916 fdr_ptr
= fi
->d
.fdr
;
2917 fraw_src
= (char *) fi
->d
.external_fdr
;
2918 fraw_end
= (fraw_src
2919 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
2920 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
2921 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
2923 elf_tdata (abfd
)->find_line_info
= fi
;
2925 /* Note that we don't bother to ever free this information.
2926 find_nearest_line is either called all the time, as in
2927 objdump -l, so the information should be saved, or it is
2928 rarely called, as in ld error messages, so the memory
2929 wasted is unimportant. Still, it would probably be a
2930 good idea for free_cached_info to throw it away. */
2933 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
2934 &fi
->i
, filename_ptr
, functionname_ptr
,
2937 msec
->flags
= origflags
;
2941 msec
->flags
= origflags
;
2944 /* Fall back on the generic ELF find_nearest_line routine. */
2946 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
2947 filename_ptr
, functionname_ptr
,
2951 /* The MIPS ELF linker needs additional information for each symbol in
2952 the global hash table. */
2954 struct mips_elf_link_hash_entry
2956 struct elf_link_hash_entry root
;
2958 /* External symbol information. */
2961 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
2962 unsigned int mips_32_relocs
;
2965 /* MIPS ELF linker hash table. */
2967 struct mips_elf_link_hash_table
2969 struct elf_link_hash_table root
;
2970 /* String section indices for the dynamic section symbols. */
2971 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
2972 /* The number of .rtproc entries. */
2973 bfd_size_type procedure_count
;
2974 /* The size of the .compact_rel section (if SGI_COMPAT). */
2975 bfd_size_type compact_rel_size
;
2976 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
2977 entry is set to the address of __rld_obj_head as in Irix 5. */
2978 boolean use_rld_obj_head
;
2979 /* This is the value of the __rld_map or __rld_obj_head symbol. */
2983 /* Look up an entry in a MIPS ELF linker hash table. */
2985 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
2986 ((struct mips_elf_link_hash_entry *) \
2987 elf_link_hash_lookup (&(table)->root, (string), (create), \
2990 /* Traverse a MIPS ELF linker hash table. */
2992 #define mips_elf_link_hash_traverse(table, func, info) \
2993 (elf_link_hash_traverse \
2995 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
2998 /* Get the MIPS ELF linker hash table from a link_info structure. */
3000 #define mips_elf_hash_table(p) \
3001 ((struct mips_elf_link_hash_table *) ((p)->hash))
3003 static boolean mips_elf_output_extsym
3004 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3006 /* Create an entry in a MIPS ELF linker hash table. */
3008 static struct bfd_hash_entry
*
3009 mips_elf_link_hash_newfunc (entry
, table
, string
)
3010 struct bfd_hash_entry
*entry
;
3011 struct bfd_hash_table
*table
;
3014 struct mips_elf_link_hash_entry
*ret
=
3015 (struct mips_elf_link_hash_entry
*) entry
;
3017 /* Allocate the structure if it has not already been allocated by a
3019 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3020 ret
= ((struct mips_elf_link_hash_entry
*)
3021 bfd_hash_allocate (table
,
3022 sizeof (struct mips_elf_link_hash_entry
)));
3023 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3024 return (struct bfd_hash_entry
*) ret
;
3026 /* Call the allocation method of the superclass. */
3027 ret
= ((struct mips_elf_link_hash_entry
*)
3028 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3030 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3032 /* Set local fields. */
3033 memset (&ret
->esym
, 0, sizeof (EXTR
));
3034 /* We use -2 as a marker to indicate that the information has
3035 not been set. -1 means there is no associated ifd. */
3037 ret
->mips_32_relocs
= 0;
3040 return (struct bfd_hash_entry
*) ret
;
3043 /* Create a MIPS ELF linker hash table. */
3045 static struct bfd_link_hash_table
*
3046 mips_elf_link_hash_table_create (abfd
)
3049 struct mips_elf_link_hash_table
*ret
;
3052 ret
= ((struct mips_elf_link_hash_table
*)
3053 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
3054 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
3057 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3058 mips_elf_link_hash_newfunc
))
3060 bfd_release (abfd
, ret
);
3064 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
3065 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
3066 ret
->procedure_count
= 0;
3067 ret
->compact_rel_size
= 0;
3068 ret
->use_rld_obj_head
= false;
3071 return &ret
->root
.root
;
3074 /* Hook called by the linker routine which adds symbols from an object
3075 file. We must handle the special MIPS section numbers here. */
3079 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3081 struct bfd_link_info
*info
;
3082 const Elf_Internal_Sym
*sym
;
3088 if (SGI_COMPAT (abfd
)
3089 && (abfd
->flags
& DYNAMIC
) != 0
3090 && strcmp (*namep
, "_rld_new_interface") == 0)
3092 /* Skip Irix 5 rld entry name. */
3097 switch (sym
->st_shndx
)
3100 /* Common symbols less than the GP size are automatically
3101 treated as SHN_MIPS_SCOMMON symbols. */
3102 if (sym
->st_size
> elf_gp_size (abfd
))
3105 case SHN_MIPS_SCOMMON
:
3106 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3107 (*secp
)->flags
|= SEC_IS_COMMON
;
3108 *valp
= sym
->st_size
;
3112 /* This section is used in a shared object. */
3113 if (mips_elf_text_section_ptr
== NULL
)
3115 /* Initialize the section. */
3116 mips_elf_text_section
.name
= ".text";
3117 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
3118 mips_elf_text_section
.output_section
= NULL
;
3119 mips_elf_text_section
.owner
= abfd
;
3120 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
3121 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
3122 mips_elf_text_symbol
.name
= ".text";
3123 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
3124 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
3125 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
3126 mips_elf_text_section_ptr
= &mips_elf_text_section
;
3129 *secp
= bfd_und_section_ptr
;
3131 *secp
= mips_elf_text_section_ptr
;
3134 case SHN_MIPS_ACOMMON
:
3135 /* Fall through. XXX Can we treat this as allocated data? */
3137 /* This section is used in a shared object. */
3138 if (mips_elf_data_section_ptr
== NULL
)
3140 /* Initialize the section. */
3141 mips_elf_data_section
.name
= ".data";
3142 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
3143 mips_elf_data_section
.output_section
= NULL
;
3144 mips_elf_data_section
.owner
= abfd
;
3145 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
3146 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
3147 mips_elf_data_symbol
.name
= ".data";
3148 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
3149 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
3150 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
3151 mips_elf_data_section_ptr
= &mips_elf_data_section
;
3154 *secp
= bfd_und_section_ptr
;
3156 *secp
= mips_elf_data_section_ptr
;
3159 case SHN_MIPS_SUNDEFINED
:
3160 *secp
= bfd_und_section_ptr
;
3164 if (SGI_COMPAT (abfd
)
3166 && info
->hash
->creator
== abfd
->xvec
3167 && strcmp (*namep
, "__rld_obj_head") == 0)
3169 struct elf_link_hash_entry
*h
;
3171 /* Mark __rld_obj_head as dynamic. */
3173 if (! (_bfd_generic_link_add_one_symbol
3174 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3175 (bfd_vma
) *valp
, (const char *) NULL
, false,
3176 get_elf_backend_data (abfd
)->collect
,
3177 (struct bfd_link_hash_entry
**) &h
)))
3179 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
3180 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3181 h
->type
= STT_OBJECT
;
3183 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3186 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3189 /* If this is a mips16 text symbol, add 1 to the value to make it
3190 odd. This will cause something like .word SYM to come up with
3191 the right value when it is loaded into the PC. */
3192 if (sym
->st_other
== STO_MIPS16
)
3198 /* Structure used to pass information to mips_elf_output_extsym. */
3203 struct bfd_link_info
*info
;
3204 struct ecoff_debug_info
*debug
;
3205 const struct ecoff_debug_swap
*swap
;
3209 /* This routine is used to write out ECOFF debugging external symbol
3210 information. It is called via mips_elf_link_hash_traverse. The
3211 ECOFF external symbol information must match the ELF external
3212 symbol information. Unfortunately, at this point we don't know
3213 whether a symbol is required by reloc information, so the two
3214 tables may wind up being different. We must sort out the external
3215 symbol information before we can set the final size of the .mdebug
3216 section, and we must set the size of the .mdebug section before we
3217 can relocate any sections, and we can't know which symbols are
3218 required by relocation until we relocate the sections.
3219 Fortunately, it is relatively unlikely that any symbol will be
3220 stripped but required by a reloc. In particular, it can not happen
3221 when generating a final executable. */
3224 mips_elf_output_extsym (h
, data
)
3225 struct mips_elf_link_hash_entry
*h
;
3228 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
3230 asection
*sec
, *output_section
;
3232 if (h
->root
.indx
== -2)
3234 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3235 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
3236 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3237 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
3239 else if (einfo
->info
->strip
== strip_all
3240 || (einfo
->info
->strip
== strip_some
3241 && bfd_hash_lookup (einfo
->info
->keep_hash
,
3242 h
->root
.root
.root
.string
,
3243 false, false) == NULL
))
3251 if (h
->esym
.ifd
== -2)
3254 h
->esym
.cobol_main
= 0;
3255 h
->esym
.weakext
= 0;
3256 h
->esym
.reserved
= 0;
3257 h
->esym
.ifd
= ifdNil
;
3258 h
->esym
.asym
.value
= 0;
3259 h
->esym
.asym
.st
= stGlobal
;
3261 if (SGI_COMPAT (einfo
->abfd
)
3262 && (h
->root
.root
.type
== bfd_link_hash_undefined
3263 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
3267 /* Use undefined class. Also, set class and type for some
3269 name
= h
->root
.root
.root
.string
;
3270 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
3271 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
3273 h
->esym
.asym
.sc
= scData
;
3274 h
->esym
.asym
.st
= stLabel
;
3275 h
->esym
.asym
.value
= 0;
3277 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
3279 h
->esym
.asym
.sc
= scAbs
;
3280 h
->esym
.asym
.st
= stLabel
;
3281 h
->esym
.asym
.value
=
3282 mips_elf_hash_table (einfo
->info
)->procedure_count
;
3284 else if (strcmp (name
, "_gp_disp") == 0)
3286 h
->esym
.asym
.sc
= scAbs
;
3287 h
->esym
.asym
.st
= stLabel
;
3288 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
3291 h
->esym
.asym
.sc
= scUndefined
;
3293 else if (h
->root
.root
.type
!= bfd_link_hash_defined
3294 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
3295 h
->esym
.asym
.sc
= scAbs
;
3300 sec
= h
->root
.root
.u
.def
.section
;
3301 output_section
= sec
->output_section
;
3303 /* When making a shared library and symbol h is the one from
3304 the another shared library, OUTPUT_SECTION may be null. */
3305 if (output_section
== NULL
)
3306 h
->esym
.asym
.sc
= scUndefined
;
3309 name
= bfd_section_name (output_section
->owner
, output_section
);
3311 if (strcmp (name
, ".text") == 0)
3312 h
->esym
.asym
.sc
= scText
;
3313 else if (strcmp (name
, ".data") == 0)
3314 h
->esym
.asym
.sc
= scData
;
3315 else if (strcmp (name
, ".sdata") == 0)
3316 h
->esym
.asym
.sc
= scSData
;
3317 else if (strcmp (name
, ".rodata") == 0
3318 || strcmp (name
, ".rdata") == 0)
3319 h
->esym
.asym
.sc
= scRData
;
3320 else if (strcmp (name
, ".bss") == 0)
3321 h
->esym
.asym
.sc
= scBss
;
3322 else if (strcmp (name
, ".sbss") == 0)
3323 h
->esym
.asym
.sc
= scSBss
;
3324 else if (strcmp (name
, ".init") == 0)
3325 h
->esym
.asym
.sc
= scInit
;
3326 else if (strcmp (name
, ".fini") == 0)
3327 h
->esym
.asym
.sc
= scFini
;
3329 h
->esym
.asym
.sc
= scAbs
;
3333 h
->esym
.asym
.reserved
= 0;
3334 h
->esym
.asym
.index
= indexNil
;
3337 if (h
->root
.root
.type
== bfd_link_hash_common
)
3338 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
3339 else if (h
->root
.root
.type
== bfd_link_hash_defined
3340 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3342 if (h
->esym
.asym
.sc
== scCommon
)
3343 h
->esym
.asym
.sc
= scBss
;
3344 else if (h
->esym
.asym
.sc
== scSCommon
)
3345 h
->esym
.asym
.sc
= scSBss
;
3347 sec
= h
->root
.root
.u
.def
.section
;
3348 output_section
= sec
->output_section
;
3349 if (output_section
!= NULL
)
3350 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
3351 + sec
->output_offset
3352 + output_section
->vma
);
3354 h
->esym
.asym
.value
= 0;
3356 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3358 /* Set type and value for a symbol with a function stub. */
3359 h
->esym
.asym
.st
= stProc
;
3360 sec
= h
->root
.root
.u
.def
.section
;
3362 h
->esym
.asym
.value
= 0;
3365 output_section
= sec
->output_section
;
3366 if (output_section
!= NULL
)
3367 h
->esym
.asym
.value
= (h
->root
.plt_offset
3368 + sec
->output_offset
3369 + output_section
->vma
);
3371 h
->esym
.asym
.value
= 0;
3378 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
3379 h
->root
.root
.root
.string
,
3382 einfo
->failed
= true;
3389 /* Create a runtime procedure table from the .mdebug section. */
3392 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
3395 struct bfd_link_info
*info
;
3397 struct ecoff_debug_info
*debug
;
3399 const struct ecoff_debug_swap
*swap
;
3400 HDRR
*hdr
= &debug
->symbolic_header
;
3402 struct rpdr_ext
*erp
;
3404 struct pdr_ext
*epdr
;
3405 struct sym_ext
*esym
;
3408 unsigned long size
, count
;
3409 unsigned long sindex
;
3413 const char *no_name_func
= "static procedure (no name)";
3421 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3423 sindex
= strlen (no_name_func
) + 1;
3424 count
= hdr
->ipdMax
;
3427 size
= swap
->external_pdr_size
;
3429 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
3433 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
3436 size
= sizeof (RPDR
);
3437 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
3441 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
3445 count
= hdr
->isymMax
;
3446 size
= swap
->external_sym_size
;
3447 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
3451 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
3454 count
= hdr
->issMax
;
3455 ss
= (char *) bfd_malloc (count
);
3458 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
3461 count
= hdr
->ipdMax
;
3462 for (i
= 0; i
< count
; i
++, rp
++)
3464 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
3465 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
3466 rp
->adr
= sym
.value
;
3467 rp
->regmask
= pdr
.regmask
;
3468 rp
->regoffset
= pdr
.regoffset
;
3469 rp
->fregmask
= pdr
.fregmask
;
3470 rp
->fregoffset
= pdr
.fregoffset
;
3471 rp
->frameoffset
= pdr
.frameoffset
;
3472 rp
->framereg
= pdr
.framereg
;
3473 rp
->pcreg
= pdr
.pcreg
;
3475 sv
[i
] = ss
+ sym
.iss
;
3476 sindex
+= strlen (sv
[i
]) + 1;
3480 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
3481 size
= BFD_ALIGN (size
, 16);
3482 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
3485 mips_elf_hash_table (info
)->procedure_count
= 0;
3489 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
3491 erp
= (struct rpdr_ext
*) rtproc
;
3492 memset (erp
, 0, sizeof (struct rpdr_ext
));
3494 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
3495 strcpy (str
, no_name_func
);
3496 str
+= strlen (no_name_func
) + 1;
3497 for (i
= 0; i
< count
; i
++)
3499 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
3500 strcpy (str
, sv
[i
]);
3501 str
+= strlen (sv
[i
]) + 1;
3503 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
3505 /* Set the size and contents of .rtproc section. */
3506 s
->_raw_size
= size
;
3507 s
->contents
= rtproc
;
3509 /* Skip this section later on (I don't think this currently
3510 matters, but someday it might). */
3511 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
3540 /* A comparison routine used to sort .gptab entries. */
3543 gptab_compare (p1
, p2
)
3547 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
3548 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
3550 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
3553 /* We need to use a special link routine to handle the .reginfo and
3554 the .mdebug sections. We need to merge all instances of these
3555 sections together, not write them all out sequentially. */
3558 mips_elf_final_link (abfd
, info
)
3560 struct bfd_link_info
*info
;
3564 struct bfd_link_order
*p
;
3565 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
3566 asection
*rtproc_sec
;
3567 Elf32_RegInfo reginfo
;
3568 struct ecoff_debug_info debug
;
3569 const struct ecoff_debug_swap
*swap
3570 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3571 HDRR
*symhdr
= &debug
.symbolic_header
;
3572 PTR mdebug_handle
= NULL
;
3574 /* Drop the .options section, since it has special semantics which I
3575 haven't bothered to figure out. */
3576 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
3578 if (strcmp ((*secpp
)->name
, ".options") == 0)
3580 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
3581 if (p
->type
== bfd_indirect_link_order
)
3582 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
3583 (*secpp
)->link_order_head
= NULL
;
3584 *secpp
= (*secpp
)->next
;
3585 --abfd
->section_count
;
3590 /* Get a value for the GP register. */
3591 if (elf_gp (abfd
) == 0)
3593 struct bfd_link_hash_entry
*h
;
3595 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
3596 if (h
!= (struct bfd_link_hash_entry
*) NULL
3597 && h
->type
== bfd_link_hash_defined
)
3598 elf_gp (abfd
) = (h
->u
.def
.value
3599 + h
->u
.def
.section
->output_section
->vma
3600 + h
->u
.def
.section
->output_offset
);
3601 else if (info
->relocateable
)
3605 /* Make up a value. */
3607 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3610 && (strcmp (o
->name
, ".sbss") == 0
3611 || strcmp (o
->name
, ".sdata") == 0
3612 || strcmp (o
->name
, ".lit4") == 0
3613 || strcmp (o
->name
, ".lit8") == 0))
3616 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
3620 /* If the relocate_section function needs to do a reloc
3621 involving the GP value, it should make a reloc_dangerous
3622 callback to warn that GP is not defined. */
3626 /* Go through the sections and collect the .reginfo and .mdebug
3630 gptab_data_sec
= NULL
;
3631 gptab_bss_sec
= NULL
;
3632 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3634 if (strcmp (o
->name
, ".reginfo") == 0)
3636 memset (®info
, 0, sizeof reginfo
);
3638 /* We have found the .reginfo section in the output file.
3639 Look through all the link_orders comprising it and merge
3640 the information together. */
3641 for (p
= o
->link_order_head
;
3642 p
!= (struct bfd_link_order
*) NULL
;
3645 asection
*input_section
;
3647 Elf32_External_RegInfo ext
;
3650 if (p
->type
!= bfd_indirect_link_order
)
3652 if (p
->type
== bfd_fill_link_order
)
3657 input_section
= p
->u
.indirect
.section
;
3658 input_bfd
= input_section
->owner
;
3660 /* The linker emulation code has probably clobbered the
3661 size to be zero bytes. */
3662 if (input_section
->_raw_size
== 0)
3663 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3665 if (! bfd_get_section_contents (input_bfd
, input_section
,
3671 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
3673 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
3674 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
3675 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
3676 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
3677 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
3679 /* ri_gp_value is set by the function
3680 mips_elf32_section_processing when the section is
3681 finally written out. */
3683 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3684 elf_link_input_bfd ignores this section. */
3685 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3688 /* Force the section size to the value we want. */
3689 o
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3691 /* Skip this section later on (I don't think this currently
3692 matters, but someday it might). */
3693 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3698 if (strcmp (o
->name
, ".mdebug") == 0)
3700 struct extsym_info einfo
;
3702 /* We have found the .mdebug section in the output file.
3703 Look through all the link_orders comprising it and merge
3704 the information together. */
3705 symhdr
->magic
= swap
->sym_magic
;
3706 /* FIXME: What should the version stamp be? */
3708 symhdr
->ilineMax
= 0;
3712 symhdr
->isymMax
= 0;
3713 symhdr
->ioptMax
= 0;
3714 symhdr
->iauxMax
= 0;
3716 symhdr
->issExtMax
= 0;
3719 symhdr
->iextMax
= 0;
3721 /* We accumulate the debugging information itself in the
3722 debug_info structure. */
3724 debug
.external_dnr
= NULL
;
3725 debug
.external_pdr
= NULL
;
3726 debug
.external_sym
= NULL
;
3727 debug
.external_opt
= NULL
;
3728 debug
.external_aux
= NULL
;
3730 debug
.ssext
= debug
.ssext_end
= NULL
;
3731 debug
.external_fdr
= NULL
;
3732 debug
.external_rfd
= NULL
;
3733 debug
.external_ext
= debug
.external_ext_end
= NULL
;
3735 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
3736 if (mdebug_handle
== (PTR
) NULL
)
3739 if (SGI_COMPAT (abfd
))
3745 static const char * const name
[] =
3746 { ".text", ".init", ".fini", ".data",
3747 ".rodata", ".sdata", ".sbss", ".bss" };
3748 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
3749 scRData
, scSData
, scSBss
, scBss
};
3752 esym
.cobol_main
= 0;
3756 esym
.asym
.iss
= issNil
;
3757 esym
.asym
.st
= stLocal
;
3758 esym
.asym
.reserved
= 0;
3759 esym
.asym
.index
= indexNil
;
3760 for (i
= 0; i
< 8; i
++)
3762 esym
.asym
.sc
= sc
[i
];
3763 s
= bfd_get_section_by_name (abfd
, name
[i
]);
3766 esym
.asym
.value
= s
->vma
;
3767 last
= s
->vma
+ s
->_raw_size
;
3770 esym
.asym
.value
= last
;
3772 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
3778 for (p
= o
->link_order_head
;
3779 p
!= (struct bfd_link_order
*) NULL
;
3782 asection
*input_section
;
3784 const struct ecoff_debug_swap
*input_swap
;
3785 struct ecoff_debug_info input_debug
;
3789 if (p
->type
!= bfd_indirect_link_order
)
3791 if (p
->type
== bfd_fill_link_order
)
3796 input_section
= p
->u
.indirect
.section
;
3797 input_bfd
= input_section
->owner
;
3799 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
3800 || (get_elf_backend_data (input_bfd
)
3801 ->elf_backend_ecoff_debug_swap
) == NULL
)
3803 /* I don't know what a non MIPS ELF bfd would be
3804 doing with a .mdebug section, but I don't really
3805 want to deal with it. */
3809 input_swap
= (get_elf_backend_data (input_bfd
)
3810 ->elf_backend_ecoff_debug_swap
);
3812 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
3814 /* The ECOFF linking code expects that we have already
3815 read in the debugging information and set up an
3816 ecoff_debug_info structure, so we do that now. */
3817 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
3821 if (! (bfd_ecoff_debug_accumulate
3822 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
3823 &input_debug
, input_swap
, info
)))
3826 /* Loop through the external symbols. For each one with
3827 interesting information, try to find the symbol in
3828 the linker global hash table and save the information
3829 for the output external symbols. */
3830 eraw_src
= input_debug
.external_ext
;
3831 eraw_end
= (eraw_src
3832 + (input_debug
.symbolic_header
.iextMax
3833 * input_swap
->external_ext_size
));
3835 eraw_src
< eraw_end
;
3836 eraw_src
+= input_swap
->external_ext_size
)
3840 struct mips_elf_link_hash_entry
*h
;
3842 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
3843 if (ext
.asym
.sc
== scNil
3844 || ext
.asym
.sc
== scUndefined
3845 || ext
.asym
.sc
== scSUndefined
)
3848 name
= input_debug
.ssext
+ ext
.asym
.iss
;
3849 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
3850 name
, false, false, true);
3851 if (h
== NULL
|| h
->esym
.ifd
!= -2)
3857 < input_debug
.symbolic_header
.ifdMax
);
3858 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
3864 /* Free up the information we just read. */
3865 free (input_debug
.line
);
3866 free (input_debug
.external_dnr
);
3867 free (input_debug
.external_pdr
);
3868 free (input_debug
.external_sym
);
3869 free (input_debug
.external_opt
);
3870 free (input_debug
.external_aux
);
3871 free (input_debug
.ss
);
3872 free (input_debug
.ssext
);
3873 free (input_debug
.external_fdr
);
3874 free (input_debug
.external_rfd
);
3875 free (input_debug
.external_ext
);
3877 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3878 elf_link_input_bfd ignores this section. */
3879 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3882 if (SGI_COMPAT (abfd
) && info
->shared
)
3884 /* Create .rtproc section. */
3885 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
3886 if (rtproc_sec
== NULL
)
3888 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3889 | SEC_LINKER_CREATED
| SEC_READONLY
);
3891 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
3892 if (rtproc_sec
== NULL
3893 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
3894 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 12))
3898 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
3899 info
, rtproc_sec
, &debug
))
3903 /* Build the external symbol information. */
3906 einfo
.debug
= &debug
;
3908 einfo
.failed
= false;
3909 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
3910 mips_elf_output_extsym
,
3915 /* Set the size of the .mdebug section. */
3916 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
3918 /* Skip this section later on (I don't think this currently
3919 matters, but someday it might). */
3920 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3925 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
3927 const char *subname
;
3930 Elf32_External_gptab
*ext_tab
;
3933 /* The .gptab.sdata and .gptab.sbss sections hold
3934 information describing how the small data area would
3935 change depending upon the -G switch. These sections
3936 not used in executables files. */
3937 if (! info
->relocateable
)
3941 for (p
= o
->link_order_head
;
3942 p
!= (struct bfd_link_order
*) NULL
;
3945 asection
*input_section
;
3947 if (p
->type
!= bfd_indirect_link_order
)
3949 if (p
->type
== bfd_fill_link_order
)
3954 input_section
= p
->u
.indirect
.section
;
3956 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3957 elf_link_input_bfd ignores this section. */
3958 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3961 /* Skip this section later on (I don't think this
3962 currently matters, but someday it might). */
3963 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3965 /* Really remove the section. */
3966 for (secpp
= &abfd
->sections
;
3968 secpp
= &(*secpp
)->next
)
3970 *secpp
= (*secpp
)->next
;
3971 --abfd
->section_count
;
3976 /* There is one gptab for initialized data, and one for
3977 uninitialized data. */
3978 if (strcmp (o
->name
, ".gptab.sdata") == 0)
3980 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
3984 (*_bfd_error_handler
)
3985 ("%s: illegal section name `%s'",
3986 bfd_get_filename (abfd
), o
->name
);
3987 bfd_set_error (bfd_error_nonrepresentable_section
);
3991 /* The linker script always combines .gptab.data and
3992 .gptab.sdata into .gptab.sdata, and likewise for
3993 .gptab.bss and .gptab.sbss. It is possible that there is
3994 no .sdata or .sbss section in the output file, in which
3995 case we must change the name of the output section. */
3996 subname
= o
->name
+ sizeof ".gptab" - 1;
3997 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
3999 if (o
== gptab_data_sec
)
4000 o
->name
= ".gptab.data";
4002 o
->name
= ".gptab.bss";
4003 subname
= o
->name
+ sizeof ".gptab" - 1;
4004 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4007 /* Set up the first entry. */
4009 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
4012 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4013 tab
[0].gt_header
.gt_unused
= 0;
4015 /* Combine the input sections. */
4016 for (p
= o
->link_order_head
;
4017 p
!= (struct bfd_link_order
*) NULL
;
4020 asection
*input_section
;
4024 bfd_size_type gpentry
;
4026 if (p
->type
!= bfd_indirect_link_order
)
4028 if (p
->type
== bfd_fill_link_order
)
4033 input_section
= p
->u
.indirect
.section
;
4034 input_bfd
= input_section
->owner
;
4036 /* Combine the gptab entries for this input section one
4037 by one. We know that the input gptab entries are
4038 sorted by ascending -G value. */
4039 size
= bfd_section_size (input_bfd
, input_section
);
4041 for (gpentry
= sizeof (Elf32_External_gptab
);
4043 gpentry
+= sizeof (Elf32_External_gptab
))
4045 Elf32_External_gptab ext_gptab
;
4046 Elf32_gptab int_gptab
;
4052 if (! (bfd_get_section_contents
4053 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4054 gpentry
, sizeof (Elf32_External_gptab
))))
4060 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
4062 val
= int_gptab
.gt_entry
.gt_g_value
;
4063 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4066 for (look
= 1; look
< c
; look
++)
4068 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4069 tab
[look
].gt_entry
.gt_bytes
+= add
;
4071 if (tab
[look
].gt_entry
.gt_g_value
== val
)
4077 Elf32_gptab
*new_tab
;
4080 /* We need a new table entry. */
4081 new_tab
= ((Elf32_gptab
*)
4082 bfd_realloc ((PTR
) tab
,
4083 (c
+ 1) * sizeof (Elf32_gptab
)));
4084 if (new_tab
== NULL
)
4090 tab
[c
].gt_entry
.gt_g_value
= val
;
4091 tab
[c
].gt_entry
.gt_bytes
= add
;
4093 /* Merge in the size for the next smallest -G
4094 value, since that will be implied by this new
4097 for (look
= 1; look
< c
; look
++)
4099 if (tab
[look
].gt_entry
.gt_g_value
< val
4101 || (tab
[look
].gt_entry
.gt_g_value
4102 > tab
[max
].gt_entry
.gt_g_value
)))
4106 tab
[c
].gt_entry
.gt_bytes
+=
4107 tab
[max
].gt_entry
.gt_bytes
;
4112 last
= int_gptab
.gt_entry
.gt_bytes
;
4115 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4116 elf_link_input_bfd ignores this section. */
4117 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4120 /* The table must be sorted by -G value. */
4122 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
4124 /* Swap out the table. */
4125 ext_tab
= ((Elf32_External_gptab
*)
4126 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
4127 if (ext_tab
== NULL
)
4133 for (i
= 0; i
< c
; i
++)
4134 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
4137 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
4138 o
->contents
= (bfd_byte
*) ext_tab
;
4140 /* Skip this section later on (I don't think this currently
4141 matters, but someday it might). */
4142 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4146 /* Invoke the regular ELF backend linker to do all the work. */
4147 if (! bfd_elf32_bfd_final_link (abfd
, info
))
4150 /* Now write out the computed sections. */
4152 if (reginfo_sec
!= (asection
*) NULL
)
4154 Elf32_External_RegInfo ext
;
4156 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
4157 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4158 (file_ptr
) 0, sizeof ext
))
4162 if (mdebug_sec
!= (asection
*) NULL
)
4164 BFD_ASSERT (abfd
->output_has_begun
);
4165 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4167 mdebug_sec
->filepos
))
4170 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4173 if (gptab_data_sec
!= (asection
*) NULL
)
4175 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4176 gptab_data_sec
->contents
,
4178 gptab_data_sec
->_raw_size
))
4182 if (gptab_bss_sec
!= (asection
*) NULL
)
4184 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4185 gptab_bss_sec
->contents
,
4187 gptab_bss_sec
->_raw_size
))
4191 if (SGI_COMPAT (abfd
))
4193 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4194 if (rtproc_sec
!= NULL
)
4196 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
4197 rtproc_sec
->contents
,
4199 rtproc_sec
->_raw_size
))
4207 /* Handle a MIPS ELF HI16 reloc. */
4210 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
4212 Elf_Internal_Rela
*relhi
;
4213 Elf_Internal_Rela
*rello
;
4220 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4222 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4225 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4227 if ((addlo
& 0x8000) != 0)
4229 if ((addend
& 0x8000) != 0)
4232 bfd_put_32 (input_bfd
,
4233 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
4234 contents
+ relhi
->r_offset
);
4237 /* Handle a MIPS ELF local GOT16 reloc. */
4240 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
4245 Elf_Internal_Rela
*relhi
;
4246 Elf_Internal_Rela
*rello
;
4256 bfd_byte
*got_contents
;
4257 struct mips_got_info
*g
;
4259 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4261 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4264 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4266 if ((addlo
& 0x8000) != 0)
4268 if ((addend
& 0x8000) != 0)
4271 /* Get a got entry representing requested hipage. */
4272 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4273 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4274 BFD_ASSERT (g
!= NULL
);
4276 local_gotno
= g
->local_gotno
;
4277 got_contents
= sgot
->contents
;
4278 hipage
= addend
& 0xffff0000;
4280 for (i
= MIPS_RESERVED_GOTNO
; i
< local_gotno
; i
++)
4282 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
4283 if (hipage
== (address
& 0xffff0000))
4285 if (address
== (bfd_vma
) 0)
4287 bfd_put_32 (input_bfd
, hipage
, got_contents
+ i
* 4);
4292 BFD_ASSERT (i
< local_gotno
);
4294 if (i
== local_gotno
)
4295 (*_bfd_error_handler
)
4296 ("ELF MIPS linker: more got entries are needed for hipage: %x",
4300 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
4301 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
4302 contents
+ relhi
->r_offset
);
4305 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
4308 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
4310 Elf_Internal_Rela
*rel
;
4316 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4317 bfd_put_32 (input_bfd
,
4318 (insn
& 0xffff0000) | (offset
& 0xffff),
4319 contents
+ rel
->r_offset
);
4322 /* Relocate a MIPS ELF section. */
4325 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4326 contents
, relocs
, local_syms
, local_sections
)
4328 struct bfd_link_info
*info
;
4330 asection
*input_section
;
4332 Elf_Internal_Rela
*relocs
;
4333 Elf_Internal_Sym
*local_syms
;
4334 asection
**local_sections
;
4336 Elf_Internal_Shdr
*symtab_hdr
;
4339 asection
*sgot
, *sreloc
, *scpt
;
4342 Elf_Internal_Rela
*rel
;
4343 Elf_Internal_Rela
*relend
;
4344 struct mips_got_info
*g
;
4346 dynobj
= elf_hash_table (info
)->dynobj
;
4347 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4351 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
4354 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
4357 if (elf_bad_symtab (input_bfd
))
4359 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
4364 locsymcount
= symtab_hdr
->sh_info
;
4365 extsymoff
= symtab_hdr
->sh_info
;
4368 gp
= _bfd_get_gp_value (output_bfd
);
4371 relend
= relocs
+ input_section
->reloc_count
;
4372 for (; rel
< relend
; rel
++)
4375 reloc_howto_type
*howto
;
4376 unsigned long r_symndx
;
4378 struct elf_link_hash_entry
*h
;
4380 Elf_Internal_Sym
*sym
;
4381 bfd_reloc_status_type r
;
4383 r_type
= ELF32_R_TYPE (rel
->r_info
);
4384 if ((r_type
< 0 || r_type
>= (int) R_MIPS_max
) && r_type
!= R_MIPS16_26
)
4386 bfd_set_error (bfd_error_bad_value
);
4389 if (r_type
!= R_MIPS16_26
)
4390 howto
= elf_mips_howto_table
+ r_type
;
4392 howto
= &elf_mips16_jump_howto
;
4395 && (r_type
== R_MIPS_CALL16
4396 || r_type
== R_MIPS_GOT16
4397 || r_type
== R_MIPS_CALL_HI16
4398 || r_type
== R_MIPS_CALL_LO16
4399 || r_type
== R_MIPS_GOT_HI16
4400 || r_type
== R_MIPS_GOT_LO16
))
4402 /* We need the .got section. */
4405 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4406 BFD_ASSERT (sgot
!= NULL
);
4407 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4408 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4409 BFD_ASSERT (g
!= NULL
);
4413 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4415 /* Mix in the change in GP address for a GP relative reloc. */
4416 if (r_type
!= R_MIPS_GPREL16
4417 && r_type
!= R_MIPS_LITERAL
4418 && r_type
!= R_MIPS_GPREL32
)
4424 if (! ((*info
->callbacks
->reloc_dangerous
)
4426 "GP relative relocation when GP not defined",
4427 input_bfd
, input_section
,
4430 /* Only give the error once per link. */
4432 _bfd_set_gp_value (output_bfd
, gp
);
4435 if (r_symndx
< extsymoff
4436 || (elf_bad_symtab (input_bfd
)
4437 && local_sections
[r_symndx
] != NULL
))
4439 /* This is a relocation against a section. The current
4440 addend in the instruction is the difference between
4441 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
4442 must change this to be the difference between the
4443 final definition (which will end up in RELOCATION)
4444 and the GP value of OUTPUT_BFD (which is in GP). */
4445 addend
= elf_gp (input_bfd
) - gp
;
4447 else if (! info
->relocateable
)
4449 /* We are doing a final link. The current addend in the
4450 instruction is simply the desired offset into the
4451 symbol (normally zero). We want the instruction to
4452 hold the difference between the final definition of
4453 the symbol (which will end up in RELOCATION) and the
4454 GP value of OUTPUT_BFD (which is in GP). */
4459 /* We are generating relocateable output, and we aren't
4460 going to define this symbol, so we just leave the
4461 instruction alone. */
4469 if (info
->relocateable
)
4471 /* This is a relocateable link. We don't have to change
4472 anything, unless the reloc is against a section symbol,
4473 in which case we have to adjust according to where the
4474 section symbol winds up in the output section. */
4475 if (r_symndx
>= locsymcount
4476 || (elf_bad_symtab (input_bfd
)
4477 && local_sections
[r_symndx
] == NULL
))
4481 sym
= local_syms
+ r_symndx
;
4482 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4486 sec
= local_sections
[r_symndx
];
4488 /* It would be logical to add sym->st_value here,
4489 but Irix 5 sometimes generates a garbage symbol
4491 addend
+= sec
->output_offset
;
4493 /* If this is HI16 or GOT16 with an associated LO16,
4494 adjust the addend accordingly. Otherwise, just
4496 if (r_type
== R_MIPS_64
&& bfd_big_endian (input_bfd
))
4497 r
= _bfd_relocate_contents (howto
, input_bfd
,
4499 contents
+ rel
->r_offset
+ 4);
4500 else if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
4501 r
= _bfd_relocate_contents (howto
, input_bfd
,
4503 contents
+ rel
->r_offset
);
4506 Elf_Internal_Rela
*lorel
;
4508 /* As a GNU extension, permit an arbitrary
4509 number of R_MIPS_HI16 relocs before the
4510 R_MIPS_LO16 reloc. This permits gcc to emit
4511 the HI and LO relocs itself. */
4512 if (r_type
== R_MIPS_GOT16
)
4516 for (lorel
= rel
+ 1;
4518 && (ELF32_R_TYPE (lorel
->r_info
)
4524 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
4526 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
4531 r
= _bfd_relocate_contents (howto
, input_bfd
,
4533 contents
+ rel
->r_offset
);
4543 /* This is a final link. */
4545 if (r_symndx
< extsymoff
4546 || (elf_bad_symtab (input_bfd
)
4547 && local_sections
[r_symndx
] != NULL
))
4550 sym
= local_syms
+ r_symndx
;
4551 sec
= local_sections
[r_symndx
];
4552 relocation
= (sec
->output_section
->vma
4553 + sec
->output_offset
);
4555 /* It would be logical to always add sym->st_value here,
4556 but Irix 5 sometimes generates a garbage symbol
4558 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4559 relocation
+= sym
->st_value
;
4561 /* mips16 text labels should be treated as odd. */
4562 if (sym
->st_other
== STO_MIPS16
)
4570 indx
= r_symndx
- extsymoff
;
4571 h
= elf_sym_hashes (input_bfd
)[indx
];
4572 while (h
->root
.type
== bfd_link_hash_indirect
4573 || h
->root
.type
== bfd_link_hash_warning
)
4574 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4575 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
4579 if (! ((*info
->callbacks
->reloc_dangerous
)
4581 "_gp_disp used when GP not defined",
4582 input_bfd
, input_section
,
4585 /* Only give the error once per link. */
4587 _bfd_set_gp_value (output_bfd
, gp
);
4592 sec
= input_section
;
4593 if (sec
->output_section
!= NULL
)
4596 + sec
->output_section
->vma
4597 + sec
->output_offset
));
4599 relocation
= gp
- rel
->r_offset
;
4600 if (r_type
== R_MIPS_LO16
)
4604 else if (h
->root
.type
== bfd_link_hash_defined
4605 || h
->root
.type
== bfd_link_hash_defweak
)
4607 sec
= h
->root
.u
.def
.section
;
4608 if (sec
->output_section
== NULL
)
4611 relocation
= (h
->root
.u
.def
.value
4612 + sec
->output_section
->vma
4613 + sec
->output_offset
);
4615 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4617 else if (info
->shared
&& ! info
->symbolic
)
4619 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
4621 /* If this is a dynamic link, we should have created
4622 a _DYNAMIC_LINK symbol in
4623 mips_elf_create_dynamic_sections. Otherwise, we
4624 should define the symbol with a value of 0.
4625 FIXME: It should probably get into the symbol
4626 table somehow as well. */
4627 BFD_ASSERT (! info
->shared
);
4628 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
4629 ".dynamic") == NULL
);
4634 if (! ((*info
->callbacks
->undefined_symbol
)
4635 (info
, h
->root
.root
.string
, input_bfd
,
4636 input_section
, rel
->r_offset
)))
4642 if (r_type
== R_MIPS_HI16
)
4644 Elf_Internal_Rela
*lorel
;
4646 /* As a GNU extension, permit an arbitrary number of
4647 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
4648 This permits gcc to emit the HI and LO relocs itself. */
4649 for (lorel
= rel
+ 1;
4651 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
4655 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
4657 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
4658 contents
, relocation
+ addend
);
4662 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4663 contents
, rel
->r_offset
,
4664 relocation
, addend
);
4666 else if (r_type
== R_MIPS_GOT16
&& local
)
4668 /* GOT16 must also have an associated LO16 in the local
4669 case. In this case, the addend is extracted and the
4670 section in which the referenced object is determined.
4671 Then the final address of the object is computed and
4672 the GOT entry for the hipage (an aligned 64kb chunk)
4673 is added to .got section if needed. The offset field
4674 of the GOT16-relocated instruction is replaced by the
4675 index of this GOT entry for the hipage. */
4676 if ((rel
+ 1) < relend
4677 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
4679 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
,
4682 relocation
+ addend
);
4686 r
= bfd_reloc_outofrange
;
4688 else if (r_type
== R_MIPS_CALL16
4689 || r_type
== R_MIPS_GOT16
4690 || r_type
== R_MIPS_CALL_LO16
4691 || r_type
== R_MIPS_GOT_LO16
)
4695 /* This symbol must be registered as a global symbol
4696 having the corresponding got entry. */
4697 BFD_ASSERT (h
->got_offset
!= (bfd_vma
) -1);
4699 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
4700 BFD_ASSERT (g
->local_gotno
<= offset
4701 && offset
< sgot
->_raw_size
);
4702 bfd_put_32 (output_bfd
, relocation
+ addend
,
4703 sgot
->contents
+ offset
);
4704 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
4706 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
4710 else if (r_type
== R_MIPS_CALL_HI16
4711 || r_type
== R_MIPS_GOT_HI16
)
4715 /* This must be a global symbol with a got entry. The
4716 next reloc must be the corresponding LO16 reloc. */
4717 BFD_ASSERT (h
!= NULL
&& h
->got_offset
!= (bfd_vma
) -1);
4718 BFD_ASSERT ((rel
+ 1) < relend
);
4719 BFD_ASSERT (ELF32_R_TYPE ((rel
+ 1)->r_info
)
4720 == (r_type
== R_MIPS_CALL_HI16
4722 : R_MIPS_GOT_LO16
));
4724 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
4725 BFD_ASSERT (g
->local_gotno
<= offset
4726 && offset
< sgot
->_raw_size
);
4727 bfd_put_32 (output_bfd
, relocation
+ addend
,
4728 sgot
->contents
+ offset
);
4729 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
4731 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
4735 else if (r_type
== R_MIPS_REL32
4736 || r_type
== R_MIPS_32
)
4738 Elf_Internal_Rel outrel
;
4739 Elf32_crinfo cptrel
;
4743 || (elf_hash_table (info
)->dynamic_sections_created
4745 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
4747 && (input_section
->flags
& SEC_ALLOC
) != 0)
4749 /* When generating a shared object, these
4750 relocations are copied into the output file to be
4751 resolved at run time. */
4754 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
4755 BFD_ASSERT (sreloc
!= NULL
);
4758 outrel
.r_offset
= (rel
->r_offset
4759 + input_section
->output_section
->vma
4760 + input_section
->output_offset
);
4762 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4765 && (! info
->symbolic
4766 || (h
->elf_link_hash_flags
4767 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4769 BFD_ASSERT (h
->dynindx
!= -1);
4770 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
4771 sec
= input_section
;
4778 sec
= local_sections
[r_symndx
];
4781 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
4783 == bfd_link_hash_defweak
));
4784 sec
= h
->root
.u
.def
.section
;
4786 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
4788 else if (sec
== NULL
|| sec
->owner
== NULL
)
4790 bfd_set_error (bfd_error_bad_value
);
4797 osec
= sec
->output_section
;
4798 indx
= elf_section_data (osec
)->dynindx
;
4803 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
4804 addend
+= relocation
;
4807 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
4808 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
4809 (((Elf32_External_Rel
*)
4811 + sreloc
->reloc_count
));
4812 ++sreloc
->reloc_count
;
4814 if (SGI_COMPAT (output_bfd
))
4819 /* Make an entry of compact relocation info. */
4820 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
4821 cptrel
.vaddr
= (rel
->r_offset
4822 + input_section
->output_section
->vma
4823 + input_section
->output_offset
);
4824 if (r_type
== R_MIPS_REL32
)
4825 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
4827 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
4828 mips_elf_set_cr_dist2to (cptrel
, 0);
4829 cptrel
.konst
= addend
;
4831 cr
= (scpt
->contents
4832 + sizeof (Elf32_External_compact_rel
));
4833 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4834 ((Elf32_External_crinfo
*) cr
4835 + scpt
->reloc_count
));
4836 ++scpt
->reloc_count
;
4839 /* This reloc will be computed at runtime, so
4840 there's no need to do anything now. */
4844 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4845 contents
, rel
->r_offset
,
4846 relocation
, addend
);
4848 else if (r_type
== R_MIPS_64
)
4853 /* Do a 32 bit relocation, and sign extend to 64 bits. */
4854 addr
= rel
->r_offset
;
4855 if (bfd_big_endian (input_bfd
))
4857 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4858 contents
, addr
, relocation
,
4860 val
= bfd_get_32 (input_bfd
, contents
+ addr
);
4861 if ((val
& 0x80000000) != 0)
4865 addr
= rel
->r_offset
;
4866 if (bfd_little_endian (input_bfd
))
4868 bfd_put_32 (input_bfd
, val
, contents
+ addr
);
4870 else if (r_type
== R_MIPS_26
4871 && ((h
!= NULL
&& h
->other
== STO_MIPS16
)
4872 || (sym
!= NULL
&& sym
->st_other
== STO_MIPS16
)))
4876 /* This is a jump to a mips16 routine from a mips32
4877 routine. We need to change jal into jalx. */
4878 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4879 if (((insn
>> 26) & 0x3f) != 0x3
4880 && ((insn
>> 26) & 0x3f) != 0x1d)
4882 (*_bfd_error_handler
)
4883 ("%s: %s+0x%lx: jump to mips16 routine which is not jal",
4884 bfd_get_filename (input_bfd
),
4885 input_section
->name
,
4886 (unsigned long) rel
->r_offset
);
4887 bfd_set_error (bfd_error_bad_value
);
4890 insn
= (insn
& 0x3ffffff) | (0x1d << 26);
4891 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
4892 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4893 contents
, rel
->r_offset
,
4894 relocation
, addend
);
4896 else if (r_type
== R_MIPS16_26
)
4898 /* It's easiest to do the normal relocation, and then
4899 dig out the instruction and swap the first word the
4900 way the mips16 expects it. */
4901 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4902 contents
, rel
->r_offset
,
4903 relocation
, addend
);
4904 if (r
== bfd_reloc_ok
)
4908 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
4909 insn
= ((insn
& 0xfc00)
4910 | ((insn
& 0x1f) << 5)
4911 | ((insn
& 0x3e0) >> 5));
4912 /* If this is a jump to a 32 bit routine, then make
4914 if ((h
!= NULL
&& h
->other
!= STO_MIPS16
)
4915 || (sym
!= NULL
&& sym
->st_other
!= STO_MIPS16
))
4917 bfd_put_16 (input_bfd
, insn
, contents
+ rel
->r_offset
);
4921 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4922 contents
, rel
->r_offset
,
4923 relocation
, addend
);
4925 if (SGI_COMPAT (abfd
)
4927 && (input_section
->flags
& SEC_ALLOC
) != 0)
4929 Elf32_crinfo cptrel
;
4932 /* Make an entry of compact relocation info. */
4933 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
4934 cptrel
.vaddr
= (rel
->r_offset
4935 + input_section
->output_section
->vma
4936 + input_section
->output_offset
);
4941 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
4942 /* XXX How should we set dist2to in this case. */
4943 mips_elf_set_cr_dist2to (cptrel
, 8);
4944 cptrel
.konst
= addend
+ relocation
;
4945 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
4946 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4947 ((Elf32_External_crinfo
*) cr
4948 + scpt
->reloc_count
));
4949 ++scpt
->reloc_count
;
4952 case R_MIPS_GPREL16
:
4953 case R_MIPS_LITERAL
:
4954 case R_MIPS_GPREL32
:
4955 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
4956 cptrel
.konst
= gp
- cptrel
.vaddr
;
4957 mips_elf_set_cr_dist2to (cptrel
, 4);
4958 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
4959 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4960 ((Elf32_External_crinfo
*) cr
4961 + scpt
->reloc_count
));
4962 ++scpt
->reloc_count
;
4971 if (r
!= bfd_reloc_ok
)
4976 case bfd_reloc_outofrange
:
4978 case bfd_reloc_overflow
:
4983 name
= h
->root
.root
.string
;
4986 name
= bfd_elf_string_from_elf_section (input_bfd
,
4987 symtab_hdr
->sh_link
,
4992 name
= bfd_section_name (input_bfd
, sec
);
4994 if (! ((*info
->callbacks
->reloc_overflow
)
4995 (info
, name
, howto
->name
, (bfd_vma
) 0,
4996 input_bfd
, input_section
, rel
->r_offset
)))
5007 /* This hook function is called before the linker writes out a global
5008 symbol. This is where we undo the increment of the value for a
5013 mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
5015 struct bfd_link_info
*info
;
5017 Elf_Internal_Sym
*sym
;
5018 asection
*input_sec
;
5020 if (sym
->st_other
== STO_MIPS16
5021 && (sym
->st_value
& 1) != 0)
5026 /* Functions for the dynamic linker. */
5028 /* The name of the dynamic interpreter. This is put in the .interp
5031 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
5033 /* Create dynamic sections when linking against a dynamic object. */
5036 mips_elf_create_dynamic_sections (abfd
, info
)
5038 struct bfd_link_info
*info
;
5040 struct elf_link_hash_entry
*h
;
5042 register asection
*s
;
5043 const char * const *namep
;
5045 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5046 | SEC_LINKER_CREATED
| SEC_READONLY
);
5048 /* Mips ABI requests the .dynamic section to be read only. */
5049 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5052 if (! bfd_set_section_flags (abfd
, s
, flags
))
5056 /* We need to create .got section. */
5057 if (! mips_elf_create_got_section (abfd
, info
))
5060 /* Create .stub section. */
5061 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
5063 s
= bfd_make_section (abfd
, ".stub");
5065 || ! bfd_set_section_flags (abfd
, s
, flags
)
5066 || ! bfd_set_section_alignment (abfd
, s
, 2))
5070 if (SGI_COMPAT (abfd
)
5072 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
5074 s
= bfd_make_section (abfd
, ".rld_map");
5076 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
5077 || ! bfd_set_section_alignment (abfd
, s
, 2))
5081 if (SGI_COMPAT (abfd
))
5083 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
5086 if (! (_bfd_generic_link_add_one_symbol
5087 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
5088 (bfd_vma
) 0, (const char *) NULL
, false,
5089 get_elf_backend_data (abfd
)->collect
,
5090 (struct bfd_link_hash_entry
**) &h
)))
5092 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5093 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5094 h
->type
= STT_SECTION
;
5096 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5100 /* We need to create a .compact_rel section. */
5101 if (! mips_elf_create_compact_rel_section (abfd
, info
))
5104 /* Change aligments of some sections. */
5105 s
= bfd_get_section_by_name (abfd
, ".hash");
5107 bfd_set_section_alignment (abfd
, s
, 4);
5108 s
= bfd_get_section_by_name (abfd
, ".dynsym");
5110 bfd_set_section_alignment (abfd
, s
, 4);
5111 s
= bfd_get_section_by_name (abfd
, ".dynstr");
5113 bfd_set_section_alignment (abfd
, s
, 4);
5114 s
= bfd_get_section_by_name (abfd
, ".reginfo");
5116 bfd_set_section_alignment (abfd
, s
, 4);
5117 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5119 bfd_set_section_alignment (abfd
, s
, 4);
5125 if (! (_bfd_generic_link_add_one_symbol
5126 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
5127 (bfd_vma
) 0, (const char *) NULL
, false,
5128 get_elf_backend_data (abfd
)->collect
,
5129 (struct bfd_link_hash_entry
**) &h
)))
5131 h
->elf_link_hash_flags
^=~ ELF_LINK_NON_ELF
;
5132 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5133 h
->type
= STT_SECTION
;
5135 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5138 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
5140 /* __rld_map is a four byte word located in the .data section
5141 and is filled in by the rtld to contain a pointer to
5142 the _r_debug structure. Its symbol value will be set in
5143 mips_elf_finish_dynamic_symbol. */
5144 s
= bfd_get_section_by_name (abfd
, ".rld_map");
5145 BFD_ASSERT (s
!= NULL
);
5148 if (! (_bfd_generic_link_add_one_symbol
5149 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
5150 (bfd_vma
) 0, (const char *) NULL
, false,
5151 get_elf_backend_data (abfd
)->collect
,
5152 (struct bfd_link_hash_entry
**) &h
)))
5154 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5155 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5156 h
->type
= STT_OBJECT
;
5158 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5166 /* Create the .compact_rel section. */
5169 mips_elf_create_compact_rel_section (abfd
, info
)
5171 struct bfd_link_info
*info
;
5174 register asection
*s
;
5176 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
5178 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
5181 s
= bfd_make_section (abfd
, ".compact_rel");
5183 || ! bfd_set_section_flags (abfd
, s
, flags
)
5184 || ! bfd_set_section_alignment (abfd
, s
, 2))
5187 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
5193 /* Create the .got section to hold the global offset table. */
5196 mips_elf_create_got_section (abfd
, info
)
5198 struct bfd_link_info
*info
;
5201 register asection
*s
;
5202 struct elf_link_hash_entry
*h
;
5203 struct mips_got_info
*g
;
5205 /* This function may be called more than once. */
5206 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
5209 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5210 | SEC_LINKER_CREATED
);
5212 s
= bfd_make_section (abfd
, ".got");
5214 || ! bfd_set_section_flags (abfd
, s
, flags
)
5215 || ! bfd_set_section_alignment (abfd
, s
, 4))
5218 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
5219 linker script because we don't want to define the symbol if we
5220 are not creating a global offset table. */
5222 if (! (_bfd_generic_link_add_one_symbol
5223 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
5224 (bfd_vma
) 0, (const char *) NULL
, false,
5225 get_elf_backend_data (abfd
)->collect
,
5226 (struct bfd_link_hash_entry
**) &h
)))
5228 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5229 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5230 h
->type
= STT_OBJECT
;
5233 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5236 /* The first several global offset table entries are reserved. */
5237 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
5239 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
5240 sizeof (struct mips_got_info
));
5243 g
->global_gotsym
= 0;
5244 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
5245 if (elf_section_data (s
) == NULL
)
5248 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
5249 if (elf_section_data (s
) == NULL
)
5252 elf_section_data (s
)->tdata
= (PTR
) g
;
5257 /* Look through the relocs for a section during the first phase, and
5258 allocate space in the global offset table. */
5261 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
5263 struct bfd_link_info
*info
;
5265 const Elf_Internal_Rela
*relocs
;
5268 Elf_Internal_Shdr
*symtab_hdr
;
5269 struct elf_link_hash_entry
**sym_hashes
;
5270 struct mips_got_info
*g
;
5272 const Elf_Internal_Rela
*rel
;
5273 const Elf_Internal_Rela
*rel_end
;
5277 if (info
->relocateable
)
5280 dynobj
= elf_hash_table (info
)->dynobj
;
5281 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5282 sym_hashes
= elf_sym_hashes (abfd
);
5283 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
5292 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5297 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5298 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5299 BFD_ASSERT (g
!= NULL
);
5305 rel_end
= relocs
+ sec
->reloc_count
;
5306 for (rel
= relocs
; rel
< rel_end
; rel
++)
5308 unsigned long r_symndx
;
5309 struct elf_link_hash_entry
*h
;
5311 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5313 if (r_symndx
< extsymoff
)
5316 h
= sym_hashes
[r_symndx
- extsymoff
];
5318 /* Some relocs require a global offset table. */
5319 if (dynobj
== NULL
|| sgot
== NULL
)
5321 switch (ELF32_R_TYPE (rel
->r_info
))
5325 case R_MIPS_CALL_HI16
:
5326 case R_MIPS_CALL_LO16
:
5327 case R_MIPS_GOT_HI16
:
5328 case R_MIPS_GOT_LO16
:
5330 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
5331 if (! mips_elf_create_got_section (dynobj
, info
))
5333 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5334 BFD_ASSERT (sgot
!= NULL
);
5335 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5336 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5337 BFD_ASSERT (g
!= NULL
);
5343 && (info
->shared
|| h
!= NULL
)
5344 && (sec
->flags
& SEC_ALLOC
) != 0)
5345 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
5353 switch (ELF32_R_TYPE (rel
->r_info
))
5356 case R_MIPS_CALL_HI16
:
5357 case R_MIPS_CALL_LO16
:
5358 /* This symbol requires a global offset table entry. */
5360 BFD_ASSERT (h
!= NULL
);
5362 /* Make sure this symbol is output as a dynamic symbol. */
5363 if (h
->dynindx
== -1)
5365 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5369 if (h
->got_offset
!= (bfd_vma
) -1)
5371 /* We have already allocated space in the .got. */
5375 /* Note the index of the first global got symbol in .dynsym. */
5376 if (g
->global_gotsym
== 0
5377 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
5378 g
->global_gotsym
= h
->dynindx
;
5380 /* Make this symbol to have the corresponding got entry. */
5383 /* We need a stub, not a plt entry for the undefined
5384 function. But we record it as if it needs plt. See
5385 elf_adjust_dynamic_symbol in elflink.h. */
5386 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
5392 case R_MIPS_GOT_HI16
:
5393 case R_MIPS_GOT_LO16
:
5394 /* This symbol requires a global offset table entry. */
5398 /* Make sure this symbol is output as a dynamic symbol. */
5399 if (h
->dynindx
== -1)
5401 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5405 if (h
->got_offset
!= (bfd_vma
) -1)
5407 /* We have already allocated space in the .got. */
5410 /* Note the index of the first global got symbol in
5412 if (g
->global_gotsym
== 0
5413 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
5414 g
->global_gotsym
= h
->dynindx
;
5416 /* Make this symbol to be the global got symbol. */
5424 if ((info
->shared
|| h
!= NULL
)
5425 && (sec
->flags
& SEC_ALLOC
) != 0)
5429 const char *name
= ".rel.dyn";
5431 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5434 sreloc
= bfd_make_section (dynobj
, name
);
5436 || ! bfd_set_section_flags (dynobj
, sreloc
,
5441 | SEC_LINKER_CREATED
5443 || ! bfd_set_section_alignment (dynobj
, sreloc
,
5450 /* When creating a shared object, we must copy these
5451 reloc types into the output file as R_MIPS_REL32
5452 relocs. We make room for this reloc in the
5453 .rel.dyn reloc section */
5454 if (sreloc
->_raw_size
== 0)
5456 /* Add a null element. */
5457 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
5458 ++sreloc
->reloc_count
;
5460 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
5464 struct mips_elf_link_hash_entry
*hmips
;
5466 /* We only need to copy this reloc if the symbol is
5467 defined in a dynamic object. */
5468 hmips
= (struct mips_elf_link_hash_entry
*) h
;
5469 ++hmips
->mips_32_relocs
;
5473 if (SGI_COMPAT (abfd
))
5474 mips_elf_hash_table (info
)->compact_rel_size
+=
5475 sizeof (Elf32_External_crinfo
);
5480 case R_MIPS_GPREL16
:
5481 case R_MIPS_LITERAL
:
5482 case R_MIPS_GPREL32
:
5483 if (SGI_COMPAT (abfd
))
5484 mips_elf_hash_table (info
)->compact_rel_size
+=
5485 sizeof (Elf32_External_crinfo
);
5496 /* Adjust a symbol defined by a dynamic object and referenced by a
5497 regular object. The current definition is in some section of the
5498 dynamic object, but we're not including those sections. We have to
5499 change the definition to something the rest of the link can
5503 mips_elf_adjust_dynamic_symbol (info
, h
)
5504 struct bfd_link_info
*info
;
5505 struct elf_link_hash_entry
*h
;
5508 struct mips_elf_link_hash_entry
*hmips
;
5511 dynobj
= elf_hash_table (info
)->dynobj
;
5513 /* Make sure we know what is going on here. */
5514 BFD_ASSERT (dynobj
!= NULL
5515 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
5516 || h
->weakdef
!= NULL
5517 || ((h
->elf_link_hash_flags
5518 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5519 && (h
->elf_link_hash_flags
5520 & ELF_LINK_HASH_REF_REGULAR
) != 0
5521 && (h
->elf_link_hash_flags
5522 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
5524 /* If this symbol is defined in a dynamic object, we need to copy
5525 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
5527 hmips
= (struct mips_elf_link_hash_entry
*) h
;
5528 if (! info
->relocateable
5529 && hmips
->mips_32_relocs
!= 0
5530 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5532 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5533 BFD_ASSERT (s
!= NULL
);
5535 if (s
->_raw_size
== 0)
5537 /* Make room for a null element. */
5538 s
->_raw_size
+= sizeof (Elf32_External_Rel
);
5541 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
5544 /* For a function, create a stub, if needed. */
5545 if (h
->type
== STT_FUNC
5546 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
5548 if (! elf_hash_table (info
)->dynamic_sections_created
)
5551 /* If this symbol is not defined in a regular file, then set
5552 the symbol to the stub location. This is required to make
5553 function pointers compare as equal between the normal
5554 executable and the shared library. */
5555 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5557 /* We need .stub section. */
5558 s
= bfd_get_section_by_name (dynobj
, ".stub");
5559 BFD_ASSERT (s
!= NULL
);
5561 h
->root
.u
.def
.section
= s
;
5562 h
->root
.u
.def
.value
= s
->_raw_size
;
5564 /* XXX Write this stub address somewhere. */
5565 h
->plt_offset
= s
->_raw_size
;
5567 /* Make room for this stub code. */
5568 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
5570 /* The last half word of the stub will be filled with the index
5571 of this symbol in .dynsym section. */
5576 /* If this is a weak symbol, and there is a real definition, the
5577 processor independent code will have arranged for us to see the
5578 real definition first, and we can just use the same value. */
5579 if (h
->weakdef
!= NULL
)
5581 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
5582 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
5583 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
5584 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
5588 /* This is a reference to a symbol defined by a dynamic object which
5589 is not a function. */
5594 /* Set the sizes of the dynamic sections. */
5597 mips_elf_size_dynamic_sections (output_bfd
, info
)
5599 struct bfd_link_info
*info
;
5605 struct mips_got_info
*g
;
5607 dynobj
= elf_hash_table (info
)->dynobj
;
5608 BFD_ASSERT (dynobj
!= NULL
);
5610 if (elf_hash_table (info
)->dynamic_sections_created
)
5612 /* Set the contents of the .interp section to the interpreter. */
5615 s
= bfd_get_section_by_name (dynobj
, ".interp");
5616 BFD_ASSERT (s
!= NULL
);
5617 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5618 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
5622 /* Recompute the size of .got for local entires (reserved and
5623 hipages) if needed. To estimate it, get the upper bound of total
5624 size of loadable sections. */
5625 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5629 bfd_size_type loadable_size
= 0;
5630 bfd_size_type local_gotno
;
5633 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5634 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5635 BFD_ASSERT (g
!= NULL
);
5637 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
5638 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
5640 if ((s
->flags
& SEC_ALLOC
) == 0)
5642 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
5645 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
5647 /* Assume there are two loadable segments consisting of
5648 contiguous sections. Is 5 enough? */
5649 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
5650 g
->local_gotno
= local_gotno
;
5651 sgot
->_raw_size
+= local_gotno
* 4;
5654 /* The check_relocs and adjust_dynamic_symbol entry points have
5655 determined the sizes of the various dynamic sections. Allocate
5658 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
5663 /* It's OK to base decisions on the section name, because none
5664 of the dynobj section names depend upon the input files. */
5665 name
= bfd_get_section_name (dynobj
, s
);
5667 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
5672 if (strncmp (name
, ".rel", 4) == 0)
5674 if (s
->_raw_size
== 0)
5678 const char *outname
;
5681 /* If this relocation section applies to a read only
5682 section, then we probably need a DT_TEXTREL entry.
5683 If the relocation section is .rel.dyn, we always
5684 assert a DT_TEXTREL entry rather than testing whether
5685 there exists a relocation to a read only section or
5687 outname
= bfd_get_section_name (output_bfd
,
5689 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
5690 if ((target
!= NULL
&& (target
->flags
& SEC_READONLY
) != 0)
5691 || strcmp (outname
, ".rel.dyn") == 0)
5694 /* We use the reloc_count field as a counter if we need
5695 to copy relocs into the output file. */
5696 if (strcmp (name
, ".rel.dyn") != 0)
5700 else if (strncmp (name
, ".got", 4) == 0)
5704 BFD_ASSERT (elf_section_data (s
) != NULL
);
5705 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
5706 BFD_ASSERT (g
!= NULL
);
5708 /* Fix the size of .got section for the correspondence of
5709 global symbols and got entries. This adds some useless
5710 got entries. Is this required by ABI really? */
5711 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
5712 s
->_raw_size
+= i
* 4;
5714 else if (strncmp (name
, ".stub", 5) == 0)
5716 /* Irix rld assumes that the function stub isn't at the end
5717 of .text section. So put a dummy. XXX */
5718 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
5720 else if (! info
->shared
5721 && ! mips_elf_hash_table (info
)->use_rld_obj_head
5722 && strncmp (name
, ".rld_map", 8) == 0)
5724 /* We add a room for __rld_map. It will be filled in by the
5725 rtld to contain a pointer to the _r_debug structure. */
5728 else if (SGI_COMPAT (output_bfd
)
5729 && strncmp (name
, ".compact_rel", 12) == 0)
5730 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
5731 else if (strncmp (name
, ".init", 5) != 0)
5733 /* It's not one of our sections, so don't allocate space. */
5741 for (spp
= &s
->output_section
->owner
->sections
;
5742 *spp
!= s
->output_section
;
5743 spp
= &(*spp
)->next
)
5745 *spp
= s
->output_section
->next
;
5746 --s
->output_section
->owner
->section_count
;
5751 /* Allocate memory for the section contents. */
5752 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
5753 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
5755 bfd_set_error (bfd_error_no_memory
);
5758 memset (s
->contents
, 0, s
->_raw_size
);
5761 if (elf_hash_table (info
)->dynamic_sections_created
)
5763 /* Add some entries to the .dynamic section. We fill in the
5764 values later, in elf_mips_finish_dynamic_sections, but we
5765 must add the entries now so that we get the correct size for
5766 the .dynamic section. The DT_DEBUG entry is filled in by the
5767 dynamic linker and used by the debugger. */
5770 if (SGI_COMPAT (output_bfd
))
5772 /* SGI object has the equivalence of DT_DEBUG in the
5773 DT_MIPS_RLD_MAP entry. */
5774 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
5778 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
5784 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
5788 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
5791 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
5793 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
5796 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
5799 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
5803 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
5806 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
5809 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
5811 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
5814 s
= bfd_get_section_by_name (dynobj
, ".liblist");
5815 BFD_ASSERT (s
!= NULL
);
5817 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
5821 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
5824 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
5828 /* Time stamps in executable files are a bad idea. */
5829 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
5834 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
5839 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
5843 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
5846 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
5849 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
5852 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
5855 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
5858 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
5861 #if 0 /* (SGI_COMPAT) */
5862 if (! bfd_get_section_by_name (dynobj
, ".init"))
5863 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
5866 if (! bfd_get_section_by_name (dynobj
, ".fini"))
5867 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
5872 /* If we use dynamic linking, we generate a section symbol for each
5873 output section. These are local symbols, which means that they
5874 must come first in the dynamic symbol table.
5875 That means we must increment the dynamic symbol index of every
5876 other dynamic symbol. */
5878 const char * const *namep
;
5880 bfd_size_type strindex
;
5881 struct bfd_strtab_hash
*dynstr
;
5882 struct mips_got_info
*g
;
5885 if (elf_hash_table (info
)->dynamic_sections_created
)
5887 if (SGI_COMPAT (output_bfd
))
5889 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
5890 elf_link_hash_traverse (elf_hash_table (info
),
5891 mips_elf_adjust_dynindx
,
5893 elf_hash_table (info
)->dynsymcount
+= c
;
5895 dynstr
= elf_hash_table (info
)->dynstr
;
5896 BFD_ASSERT (dynstr
!= NULL
);
5898 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
5902 s
= bfd_get_section_by_name (output_bfd
, *namep
);
5904 elf_section_data (s
)->dynindx
= i
;
5906 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
5907 if (strindex
== (bfd_size_type
) -1)
5910 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
5915 c
= bfd_count_sections (output_bfd
);
5916 elf_link_hash_traverse (elf_hash_table (info
),
5917 mips_elf_adjust_dynindx
,
5919 elf_hash_table (info
)->dynsymcount
+= c
;
5921 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
5923 elf_section_data (s
)->dynindx
= i
;
5924 /* These symbols will have no names, so we don't need to
5925 fiddle with dynstr_index. */
5932 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5933 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5934 BFD_ASSERT (g
!= NULL
);
5936 /* If there are no global got symbols, fake the last symbol so
5938 if (g
->global_gotsym
)
5939 g
->global_gotsym
+= c
;
5941 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
5948 /* Increment the index of a dynamic symbol by a given amount. Called
5949 via elf_link_hash_traverse. */
5952 mips_elf_adjust_dynindx (h
, cparg
)
5953 struct elf_link_hash_entry
*h
;
5956 unsigned int *cp
= (unsigned int *) cparg
;
5958 if (h
->dynindx
!= -1)
5963 /* Finish up dynamic symbol handling. We set the contents of various
5964 dynamic sections here. */
5967 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
5969 struct bfd_link_info
*info
;
5970 struct elf_link_hash_entry
*h
;
5971 Elf_Internal_Sym
*sym
;
5976 struct mips_got_info
*g
;
5979 dynobj
= elf_hash_table (info
)->dynobj
;
5980 gval
= sym
->st_value
;
5982 if (h
->plt_offset
!= (bfd_vma
) -1)
5986 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
5988 /* This symbol has a stub. Set it up. */
5990 BFD_ASSERT (h
->dynindx
!= -1);
5992 s
= bfd_get_section_by_name (dynobj
, ".stub");
5993 BFD_ASSERT (s
!= NULL
);
5995 /* Fill the stub. */
5997 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
5999 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
6002 /* FIXME: Can h->dynindex be more than 64K? */
6003 if (h
->dynindx
& 0xffff0000)
6006 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
6008 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
6010 BFD_ASSERT (h
->plt_offset
<= s
->_raw_size
);
6011 memcpy (s
->contents
+ h
->plt_offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
6013 /* Mark the symbol as undefined. plt_offset != -1 occurs
6014 only for the referenced symbol. */
6015 sym
->st_shndx
= SHN_UNDEF
;
6017 /* The run-time linker uses the st_value field of the symbol
6018 to reset the global offset table entry for this external
6019 to its stub address when unlinking a shared object. */
6020 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt_offset
;
6021 sym
->st_value
= gval
;
6024 BFD_ASSERT (h
->dynindx
!= -1);
6026 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6027 BFD_ASSERT (sgot
!= NULL
);
6028 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6029 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6030 BFD_ASSERT (g
!= NULL
);
6032 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
6034 bfd_size_type offset
;
6036 /* This symbol has an entry in the global offset table. Set its
6037 value to the corresponding got entry, if needed. */
6038 if (h
->got_offset
== (bfd_vma
) -1)
6040 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
6041 BFD_ASSERT (g
->local_gotno
* 4 <= offset
6042 && offset
< sgot
->_raw_size
);
6043 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
6047 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
6048 name
= h
->root
.root
.string
;
6049 if (strcmp (name
, "_DYNAMIC") == 0
6050 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
6051 sym
->st_shndx
= SHN_ABS
;
6052 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
6054 sym
->st_shndx
= SHN_ABS
;
6055 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6058 else if (SGI_COMPAT (output_bfd
))
6060 if (strcmp (name
, "_gp_disp") == 0)
6062 sym
->st_shndx
= SHN_ABS
;
6063 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6064 sym
->st_value
= elf_gp (output_bfd
);
6066 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
6067 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
6069 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6070 sym
->st_other
= STO_PROTECTED
;
6072 sym
->st_shndx
= SHN_MIPS_DATA
;
6074 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
6076 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6077 sym
->st_other
= STO_PROTECTED
;
6078 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
6079 sym
->st_shndx
= SHN_ABS
;
6081 else if (sym
->st_shndx
!= SHN_UNDEF
)
6083 if (h
->type
== STT_FUNC
)
6084 sym
->st_shndx
= SHN_MIPS_TEXT
;
6085 else if (h
->type
== STT_OBJECT
)
6086 sym
->st_shndx
= SHN_MIPS_DATA
;
6090 if (SGI_COMPAT (output_bfd
)
6093 if (! mips_elf_hash_table (info
)->use_rld_obj_head
6094 && strcmp (name
, "__rld_map") == 0)
6096 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
6097 BFD_ASSERT (s
!= NULL
);
6098 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
6099 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
6100 if (mips_elf_hash_table (info
)->rld_value
== 0)
6101 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
6103 else if (mips_elf_hash_table (info
)->use_rld_obj_head
6104 && strcmp (name
, "__rld_obj_head") == 0)
6106 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
6107 BFD_ASSERT (s
!= NULL
);
6108 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
6112 /* If this is a mips16 symbol, force the value to be even. */
6113 if (sym
->st_other
== STO_MIPS16
6114 && (sym
->st_value
& 1) != 0)
6120 /* Finish up the dynamic sections. */
6123 mips_elf_finish_dynamic_sections (output_bfd
, info
)
6125 struct bfd_link_info
*info
;
6130 struct mips_got_info
*g
;
6132 dynobj
= elf_hash_table (info
)->dynobj
;
6134 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
6136 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6141 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6142 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6143 BFD_ASSERT (g
!= NULL
);
6146 if (elf_hash_table (info
)->dynamic_sections_created
)
6148 Elf32_External_Dyn
*dyncon
, *dynconend
;
6150 BFD_ASSERT (sdyn
!= NULL
);
6151 BFD_ASSERT (g
!= NULL
);
6153 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
6154 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
6155 for (; dyncon
< dynconend
; dyncon
++)
6157 Elf_Internal_Dyn dyn
;
6162 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
6170 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6171 BFD_ASSERT (s
!= NULL
);
6172 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
6173 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6177 /* Rewrite DT_STRSZ. */
6179 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
6180 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6186 case DT_MIPS_CONFLICT
:
6189 case DT_MIPS_LIBLIST
:
6192 s
= bfd_get_section_by_name (output_bfd
, name
);
6193 BFD_ASSERT (s
!= NULL
);
6194 dyn
.d_un
.d_ptr
= s
->vma
;
6195 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6198 case DT_MIPS_RLD_VERSION
:
6199 dyn
.d_un
.d_val
= 1; /* XXX */
6200 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6204 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
6205 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6208 case DT_MIPS_CONFLICTNO
:
6210 elemsize
= sizeof (Elf32_Conflict
);
6213 case DT_MIPS_LIBLISTNO
:
6215 elemsize
= sizeof (Elf32_Lib
);
6217 s
= bfd_get_section_by_name (output_bfd
, name
);
6220 if (s
->_cooked_size
!= 0)
6221 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
6223 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
6228 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6231 case DT_MIPS_TIME_STAMP
:
6232 time ((time_t *) &dyn
.d_un
.d_val
);
6233 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6236 case DT_MIPS_ICHECKSUM
:
6240 case DT_MIPS_IVERSION
:
6244 case DT_MIPS_BASE_ADDRESS
:
6245 s
= output_bfd
->sections
;
6246 BFD_ASSERT (s
!= NULL
);
6247 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
6248 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6251 case DT_MIPS_LOCAL_GOTNO
:
6252 dyn
.d_un
.d_val
= g
->local_gotno
;
6253 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6256 case DT_MIPS_SYMTABNO
:
6258 elemsize
= sizeof (Elf32_External_Sym
);
6259 s
= bfd_get_section_by_name (output_bfd
, name
);
6260 BFD_ASSERT (s
!= NULL
);
6262 if (s
->_cooked_size
!= 0)
6263 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
6265 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
6266 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6269 case DT_MIPS_UNREFEXTNO
:
6271 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
6272 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6275 case DT_MIPS_GOTSYM
:
6276 dyn
.d_un
.d_val
= g
->global_gotsym
;
6277 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6280 case DT_MIPS_HIPAGENO
:
6281 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
6282 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6285 case DT_MIPS_RLD_MAP
:
6286 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
6287 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6294 /* The first entry of the global offset table will be filled at
6295 runtime. The second entry will be used by some runtime loaders.
6296 This isn't the case of Irix rld. */
6297 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
6299 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
6300 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
6304 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
6311 Elf_Internal_Sym sym
;
6314 const char * const * namep
= mips_elf_dynsym_sec_names
;
6315 Elf32_compact_rel cpt
;
6317 /* Set up the section symbols for the output sections. SGI sets
6318 the STT_NOTYPE attribute for these symbols. Should we do so? */
6320 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
6321 if (sdynsym
!= NULL
)
6323 if (SGI_COMPAT (output_bfd
))
6327 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
6331 while ((name
= *namep
++) != NULL
)
6333 s
= bfd_get_section_by_name (output_bfd
, name
);
6336 sym
.st_value
= s
->vma
;
6337 dindx
= elf_section_data (s
)->dynindx
;
6338 last
= s
->vma
+ s
->_raw_size
;
6342 sym
.st_value
= last
;
6346 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
6351 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
6353 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
6354 (((Elf32_External_Sym
*)
6359 /* Set the sh_info field of the output .dynsym section to
6360 the index of the first global symbol. */
6361 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
6362 SIZEOF_MIPS_DYNSYM_SECNAMES
;
6368 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
6371 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
6375 sym
.st_value
= s
->vma
;
6377 indx
= elf_section_data (s
)->this_idx
;
6378 BFD_ASSERT (indx
> 0);
6379 sym
.st_shndx
= indx
;
6381 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
6382 (((Elf32_External_Sym
*)
6384 + elf_section_data (s
)->dynindx
));
6387 /* Set the sh_info field of the output .dynsym section to
6388 the index of the first global symbol. */
6389 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
6390 bfd_count_sections (output_bfd
) + 1;
6394 if (SGI_COMPAT (output_bfd
))
6396 /* Write .compact_rel section out. */
6397 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
6401 cpt
.num
= s
->reloc_count
;
6403 cpt
.offset
= (s
->output_section
->filepos
6404 + sizeof (Elf32_External_compact_rel
));
6407 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
6408 ((Elf32_External_compact_rel
*)
6411 /* Clean up a dummy stub function entry in .text. */
6412 s
= bfd_get_section_by_name (dynobj
, ".stub");
6415 file_ptr dummy_offset
;
6417 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
6418 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
6419 memset (s
->contents
+ dummy_offset
, 0,
6420 MIPS_FUNCTION_STUB_SIZE
);
6425 /* Clean up a first relocation in .rel.dyn. */
6426 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6427 if (s
!= NULL
&& s
->_raw_size
> 0)
6428 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
6434 /* This is almost identical to bfd_generic_get_... except that some
6435 MIPS relocations need to be handled specially. Sigh. */
6438 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
6439 relocateable
, symbols
)
6441 struct bfd_link_info
*link_info
;
6442 struct bfd_link_order
*link_order
;
6444 boolean relocateable
;
6447 /* Get enough memory to hold the stuff */
6448 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
6449 asection
*input_section
= link_order
->u
.indirect
.section
;
6451 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
6452 arelent
**reloc_vector
= NULL
;
6458 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
6459 if (reloc_vector
== NULL
&& reloc_size
!= 0)
6462 /* read in the section */
6463 if (!bfd_get_section_contents (input_bfd
,
6467 input_section
->_raw_size
))
6470 /* We're not relaxing the section, so just copy the size info */
6471 input_section
->_cooked_size
= input_section
->_raw_size
;
6472 input_section
->reloc_done
= true;
6474 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
6478 if (reloc_count
< 0)
6481 if (reloc_count
> 0)
6486 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
6489 struct bfd_hash_entry
*h
;
6490 struct bfd_link_hash_entry
*lh
;
6491 /* Skip all this stuff if we aren't mixing formats. */
6492 if (abfd
&& input_bfd
6493 && abfd
->xvec
== input_bfd
->xvec
)
6497 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
6498 lh
= (struct bfd_link_hash_entry
*) h
;
6505 case bfd_link_hash_undefined
:
6506 case bfd_link_hash_undefweak
:
6507 case bfd_link_hash_common
:
6510 case bfd_link_hash_defined
:
6511 case bfd_link_hash_defweak
:
6513 gp
= lh
->u
.def
.value
;
6515 case bfd_link_hash_indirect
:
6516 case bfd_link_hash_warning
:
6518 /* @@FIXME ignoring warning for now */
6520 case bfd_link_hash_new
:
6529 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
6532 char *error_message
= (char *) NULL
;
6533 bfd_reloc_status_type r
;
6535 /* Specific to MIPS: Deal with relocation types that require
6536 knowing the gp of the output bfd. */
6537 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
6538 if (bfd_is_abs_section (sym
->section
) && abfd
)
6540 /* The special_function wouldn't get called anyways. */
6544 /* The gp isn't there; let the special function code
6545 fall over on its own. */
6547 else if ((*parent
)->howto
->special_function
6548 == _bfd_mips_elf_gprel16_reloc
)
6550 /* bypass special_function call */
6551 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
6552 relocateable
, (PTR
) data
, gp
);
6553 goto skip_bfd_perform_relocation
;
6555 /* end mips specific stuff */
6557 r
= bfd_perform_relocation (input_bfd
,
6561 relocateable
? abfd
: (bfd
*) NULL
,
6563 skip_bfd_perform_relocation
:
6567 asection
*os
= input_section
->output_section
;
6569 /* A partial link, so keep the relocs */
6570 os
->orelocation
[os
->reloc_count
] = *parent
;
6574 if (r
!= bfd_reloc_ok
)
6578 case bfd_reloc_undefined
:
6579 if (!((*link_info
->callbacks
->undefined_symbol
)
6580 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
6581 input_bfd
, input_section
, (*parent
)->address
)))
6584 case bfd_reloc_dangerous
:
6585 BFD_ASSERT (error_message
!= (char *) NULL
);
6586 if (!((*link_info
->callbacks
->reloc_dangerous
)
6587 (link_info
, error_message
, input_bfd
, input_section
,
6588 (*parent
)->address
)))
6591 case bfd_reloc_overflow
:
6592 if (!((*link_info
->callbacks
->reloc_overflow
)
6593 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
6594 (*parent
)->howto
->name
, (*parent
)->addend
,
6595 input_bfd
, input_section
, (*parent
)->address
)))
6598 case bfd_reloc_outofrange
:
6607 if (reloc_vector
!= NULL
)
6608 free (reloc_vector
);
6612 if (reloc_vector
!= NULL
)
6613 free (reloc_vector
);
6616 #define bfd_elf32_bfd_get_relocated_section_contents \
6617 elf32_mips_get_relocated_section_contents
6619 /* ECOFF swapping routines. These are used when dealing with the
6620 .mdebug section, which is in the ECOFF debugging format. */
6621 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
6623 /* Symbol table magic number. */
6625 /* Alignment of debugging information. E.g., 4. */
6627 /* Sizes of external symbolic information. */
6628 sizeof (struct hdr_ext
),
6629 sizeof (struct dnr_ext
),
6630 sizeof (struct pdr_ext
),
6631 sizeof (struct sym_ext
),
6632 sizeof (struct opt_ext
),
6633 sizeof (struct fdr_ext
),
6634 sizeof (struct rfd_ext
),
6635 sizeof (struct ext_ext
),
6636 /* Functions to swap in external symbolic data. */
6645 _bfd_ecoff_swap_tir_in
,
6646 _bfd_ecoff_swap_rndx_in
,
6647 /* Functions to swap out external symbolic data. */
6656 _bfd_ecoff_swap_tir_out
,
6657 _bfd_ecoff_swap_rndx_out
,
6658 /* Function to read in symbolic data. */
6659 _bfd_mips_elf_read_ecoff_info
6662 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
6663 #define TARGET_LITTLE_NAME "elf32-littlemips"
6664 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
6665 #define TARGET_BIG_NAME "elf32-bigmips"
6666 #define ELF_ARCH bfd_arch_mips
6667 #define ELF_MACHINE_CODE EM_MIPS
6669 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
6670 a value of 0x1000, and we are compatible. */
6671 #define ELF_MAXPAGESIZE 0x1000
6673 #define elf_backend_collect true
6674 #define elf_backend_type_change_ok true
6675 #define elf_info_to_howto 0
6676 #define elf_info_to_howto_rel mips_info_to_howto_rel
6677 #define elf_backend_sym_is_global mips_elf_sym_is_global
6678 #define elf_backend_object_p mips_elf32_object_p
6679 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
6680 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
6681 #define elf_backend_section_from_bfd_section \
6682 _bfd_mips_elf_section_from_bfd_section
6683 #define elf_backend_section_processing mips_elf32_section_processing
6684 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
6685 #define elf_backend_additional_program_headers \
6686 mips_elf_additional_program_headers
6687 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
6688 #define elf_backend_final_write_processing \
6689 _bfd_mips_elf_final_write_processing
6690 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
6692 #define bfd_elf32_bfd_is_local_label mips_elf_is_local_label
6693 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
6694 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
6695 #define bfd_elf32_bfd_link_hash_table_create \
6696 mips_elf_link_hash_table_create
6697 #define bfd_elf32_bfd_final_link mips_elf_final_link
6698 #define bfd_elf32_bfd_copy_private_bfd_data \
6699 _bfd_mips_elf_copy_private_bfd_data
6700 #define bfd_elf32_bfd_merge_private_bfd_data \
6701 _bfd_mips_elf_merge_private_bfd_data
6702 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
6703 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
6704 #define elf_backend_create_dynamic_sections \
6705 mips_elf_create_dynamic_sections
6706 #define elf_backend_check_relocs mips_elf_check_relocs
6707 #define elf_backend_adjust_dynamic_symbol \
6708 mips_elf_adjust_dynamic_symbol
6709 #define elf_backend_size_dynamic_sections \
6710 mips_elf_size_dynamic_sections
6711 #define elf_backend_relocate_section mips_elf_relocate_section
6712 #define elf_backend_link_output_symbol_hook \
6713 mips_elf_link_output_symbol_hook
6714 #define elf_backend_finish_dynamic_symbol \
6715 mips_elf_finish_dynamic_symbol
6716 #define elf_backend_finish_dynamic_sections \
6717 mips_elf_finish_dynamic_sections
6719 #include "elf32-target.h"