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 boolean mips_elf_relocate_got_local
79 PARAMS ((bfd
*, bfd
*, asection
*, Elf_Internal_Rela
*,
80 Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
81 static void mips_elf_relocate_global_got
82 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
83 static bfd_reloc_status_type mips16_jump_reloc
84 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
85 static bfd_reloc_status_type mips16_gprel_reloc
86 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
87 static boolean mips_elf_adjust_dynindx
88 PARAMS ((struct elf_link_hash_entry
*, PTR
));
89 static boolean mips_elf_relocate_section
90 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
91 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
92 static boolean mips_elf_link_output_symbol_hook
93 PARAMS ((bfd
*, struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
95 static boolean mips_elf_create_dynamic_sections
96 PARAMS ((bfd
*, struct bfd_link_info
*));
97 static boolean mips_elf_create_compact_rel_section
98 PARAMS ((bfd
*, struct bfd_link_info
*));
99 static boolean mips_elf_create_got_section
100 PARAMS ((bfd
*, struct bfd_link_info
*));
101 static boolean mips_elf_check_relocs
102 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
103 const Elf_Internal_Rela
*));
104 static boolean mips_elf_adjust_dynamic_symbol
105 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
106 static boolean mips_elf_always_size_sections
107 PARAMS ((bfd
*, struct bfd_link_info
*));
108 static boolean mips_elf_size_dynamic_sections
109 PARAMS ((bfd
*, struct bfd_link_info
*));
110 static boolean mips_elf_finish_dynamic_symbol
111 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
112 Elf_Internal_Sym
*));
113 static boolean mips_elf_finish_dynamic_sections
114 PARAMS ((bfd
*, struct bfd_link_info
*));
115 static boolean mips_elf_add_symbol_hook
116 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
117 const char **, flagword
*, asection
**, bfd_vma
*));
118 static bfd_reloc_status_type mips_elf_final_gp
119 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
120 static bfd_byte
*elf32_mips_get_relocated_section_contents
121 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
122 bfd_byte
*, boolean
, asymbol
**));
124 /* This is true for Irix 5 executables, false for normal MIPS ELF ABI
125 executables. FIXME: At the moment, we default to always generating
126 Irix 5 executables. */
128 #define SGI_COMPAT(abfd) (1)
130 /* This structure is used to hold .got information when linking. It
131 is stored in the tdata field of the bfd_elf_section_data structure. */
135 /* The symbol index of the first global .got symbol. */
136 unsigned long global_gotsym
;
137 /* The number of local .got entries. */
138 unsigned int local_gotno
;
139 /* The number of local .got entries we have used. */
140 unsigned int assigned_gotno
;
143 /* The number of local .got entries we reserve. */
144 #define MIPS_RESERVED_GOTNO (2)
146 /* Instructions which appear in a stub. For some reason the stub is
147 slightly different on an SGI system. */
148 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
149 #define STUB_LW(abfd) \
151 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
152 : 0x8f998000) /* lw t9,0x8000(gp) */
153 #define STUB_MOVE 0x03e07825 /* move t7,ra */
154 #define STUB_JALR 0x0320f809 /* jal t9 */
155 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
156 #define MIPS_FUNCTION_STUB_SIZE (16)
158 /* Names of sections which appear in the .dynsym section in an Irix 5
161 static const char * const mips_elf_dynsym_sec_names
[] =
174 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
175 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
177 /* The number of entries in mips_elf_dynsym_sec_names which go in the
180 #define MIPS_TEXT_DYNSYM_SECNO (3)
182 /* The names of the runtime procedure table symbols used on Irix 5. */
184 static const char * const mips_elf_dynsym_rtproc_names
[] =
187 "_procedure_string_table",
188 "_procedure_table_size",
192 /* These structures are used to generate the .compact_rel section on
197 unsigned long id1
; /* Always one? */
198 unsigned long num
; /* Number of compact relocation entries. */
199 unsigned long id2
; /* Always two? */
200 unsigned long offset
; /* The file offset of the first relocation. */
201 unsigned long reserved0
; /* Zero? */
202 unsigned long reserved1
; /* Zero? */
211 bfd_byte reserved0
[4];
212 bfd_byte reserved1
[4];
213 } Elf32_External_compact_rel
;
217 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
218 unsigned int rtype
: 4; /* Relocation types. See below. */
219 unsigned int dist2to
: 8;
220 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
221 unsigned long konst
; /* KONST field. See below. */
222 unsigned long vaddr
; /* VADDR to be relocated. */
227 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
228 unsigned int rtype
: 4; /* Relocation types. See below. */
229 unsigned int dist2to
: 8;
230 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
231 unsigned long konst
; /* KONST field. See below. */
239 } Elf32_External_crinfo
;
245 } Elf32_External_crinfo2
;
247 /* These are the constants used to swap the bitfields in a crinfo. */
249 #define CRINFO_CTYPE (0x1)
250 #define CRINFO_CTYPE_SH (31)
251 #define CRINFO_RTYPE (0xf)
252 #define CRINFO_RTYPE_SH (27)
253 #define CRINFO_DIST2TO (0xff)
254 #define CRINFO_DIST2TO_SH (19)
255 #define CRINFO_RELVADDR (0x7ffff)
256 #define CRINFO_RELVADDR_SH (0)
258 /* A compact relocation info has long (3 words) or short (2 words)
259 formats. A short format doesn't have VADDR field and relvaddr
260 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
261 #define CRF_MIPS_LONG 1
262 #define CRF_MIPS_SHORT 0
264 /* There are 4 types of compact relocation at least. The value KONST
265 has different meaning for each type:
268 CT_MIPS_REL32 Address in data
269 CT_MIPS_WORD Address in word (XXX)
270 CT_MIPS_GPHI_LO GP - vaddr
271 CT_MIPS_JMPAD Address to jump
274 #define CRT_MIPS_REL32 0xa
275 #define CRT_MIPS_WORD 0xb
276 #define CRT_MIPS_GPHI_LO 0xc
277 #define CRT_MIPS_JMPAD 0xd
279 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
280 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
281 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
282 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
284 static void bfd_elf32_swap_compact_rel_out
285 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
286 static void bfd_elf32_swap_crinfo_out
287 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
289 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
294 R_MIPS_16
, R_MIPS_32
,
295 R_MIPS_REL32
, R_MIPS_26
,
296 R_MIPS_HI16
, R_MIPS_LO16
,
297 R_MIPS_GPREL16
, R_MIPS_LITERAL
,
298 R_MIPS_GOT16
, R_MIPS_PC16
,
299 R_MIPS_CALL16
, R_MIPS_GPREL32
,
300 /* The remaining relocs are defined on Irix, although they are not
301 in the MIPS ELF ABI. */
302 R_MIPS_UNUSED1
, R_MIPS_UNUSED2
,
304 R_MIPS_SHIFT5
, R_MIPS_SHIFT6
,
305 R_MIPS_64
, R_MIPS_GOT_DISP
,
306 R_MIPS_GOT_PAGE
, R_MIPS_GOT_OFST
,
307 R_MIPS_GOT_HI16
, R_MIPS_GOT_LO16
,
308 R_MIPS_SUB
, R_MIPS_INSERT_A
,
309 R_MIPS_INSERT_B
, R_MIPS_DELETE
,
310 R_MIPS_HIGHER
, R_MIPS_HIGHEST
,
311 R_MIPS_CALL_HI16
, R_MIPS_CALL_LO16
,
313 /* These relocs are used for the mips16. */
318 static reloc_howto_type elf_mips_howto_table
[] =
321 HOWTO (R_MIPS_NONE
, /* type */
323 0, /* size (0 = byte, 1 = short, 2 = long) */
325 false, /* pc_relative */
327 complain_overflow_dont
, /* complain_on_overflow */
328 bfd_elf_generic_reloc
, /* special_function */
329 "R_MIPS_NONE", /* name */
330 false, /* partial_inplace */
333 false), /* pcrel_offset */
335 /* 16 bit relocation. */
336 HOWTO (R_MIPS_16
, /* type */
338 1, /* size (0 = byte, 1 = short, 2 = long) */
340 false, /* pc_relative */
342 complain_overflow_bitfield
, /* complain_on_overflow */
343 bfd_elf_generic_reloc
, /* special_function */
344 "R_MIPS_16", /* name */
345 true, /* partial_inplace */
346 0xffff, /* src_mask */
347 0xffff, /* dst_mask */
348 false), /* pcrel_offset */
350 /* 32 bit relocation. */
351 HOWTO (R_MIPS_32
, /* type */
353 2, /* size (0 = byte, 1 = short, 2 = long) */
355 false, /* pc_relative */
357 complain_overflow_bitfield
, /* complain_on_overflow */
358 bfd_elf_generic_reloc
, /* special_function */
359 "R_MIPS_32", /* name */
360 true, /* partial_inplace */
361 0xffffffff, /* src_mask */
362 0xffffffff, /* dst_mask */
363 false), /* pcrel_offset */
365 /* 32 bit symbol relative relocation. */
366 HOWTO (R_MIPS_REL32
, /* type */
368 2, /* size (0 = byte, 1 = short, 2 = long) */
370 false, /* pc_relative */
372 complain_overflow_bitfield
, /* complain_on_overflow */
373 bfd_elf_generic_reloc
, /* special_function */
374 "R_MIPS_REL32", /* name */
375 true, /* partial_inplace */
376 0xffffffff, /* src_mask */
377 0xffffffff, /* dst_mask */
378 false), /* pcrel_offset */
380 /* 26 bit branch address. */
381 HOWTO (R_MIPS_26
, /* type */
383 2, /* size (0 = byte, 1 = short, 2 = long) */
385 false, /* pc_relative */
387 complain_overflow_dont
, /* complain_on_overflow */
388 /* This needs complex overflow
389 detection, because the upper four
390 bits must match the PC. */
391 bfd_elf_generic_reloc
, /* special_function */
392 "R_MIPS_26", /* name */
393 true, /* partial_inplace */
394 0x3ffffff, /* src_mask */
395 0x3ffffff, /* dst_mask */
396 false), /* pcrel_offset */
398 /* High 16 bits of symbol value. */
399 HOWTO (R_MIPS_HI16
, /* type */
401 2, /* size (0 = byte, 1 = short, 2 = long) */
403 false, /* pc_relative */
405 complain_overflow_dont
, /* complain_on_overflow */
406 _bfd_mips_elf_hi16_reloc
, /* special_function */
407 "R_MIPS_HI16", /* name */
408 true, /* partial_inplace */
409 0xffff, /* src_mask */
410 0xffff, /* dst_mask */
411 false), /* pcrel_offset */
413 /* Low 16 bits of symbol value. */
414 HOWTO (R_MIPS_LO16
, /* type */
416 2, /* size (0 = byte, 1 = short, 2 = long) */
418 false, /* pc_relative */
420 complain_overflow_dont
, /* complain_on_overflow */
421 _bfd_mips_elf_lo16_reloc
, /* special_function */
422 "R_MIPS_LO16", /* name */
423 true, /* partial_inplace */
424 0xffff, /* src_mask */
425 0xffff, /* dst_mask */
426 false), /* pcrel_offset */
428 /* GP relative reference. */
429 HOWTO (R_MIPS_GPREL16
, /* type */
431 2, /* size (0 = byte, 1 = short, 2 = long) */
433 false, /* pc_relative */
435 complain_overflow_signed
, /* complain_on_overflow */
436 _bfd_mips_elf_gprel16_reloc
, /* special_function */
437 "R_MIPS_GPREL16", /* name */
438 true, /* partial_inplace */
439 0xffff, /* src_mask */
440 0xffff, /* dst_mask */
441 false), /* pcrel_offset */
443 /* Reference to literal section. */
444 HOWTO (R_MIPS_LITERAL
, /* type */
446 2, /* size (0 = byte, 1 = short, 2 = long) */
448 false, /* pc_relative */
450 complain_overflow_signed
, /* complain_on_overflow */
451 _bfd_mips_elf_gprel16_reloc
, /* special_function */
452 "R_MIPS_LITERAL", /* name */
453 true, /* partial_inplace */
454 0xffff, /* src_mask */
455 0xffff, /* dst_mask */
456 false), /* pcrel_offset */
458 /* Reference to global offset table. */
459 HOWTO (R_MIPS_GOT16
, /* type */
461 2, /* size (0 = byte, 1 = short, 2 = long) */
463 false, /* pc_relative */
465 complain_overflow_signed
, /* complain_on_overflow */
466 _bfd_mips_elf_got16_reloc
, /* special_function */
467 "R_MIPS_GOT16", /* name */
468 false, /* partial_inplace */
470 0xffff, /* dst_mask */
471 false), /* pcrel_offset */
473 /* 16 bit PC relative reference. */
474 HOWTO (R_MIPS_PC16
, /* type */
476 2, /* size (0 = byte, 1 = short, 2 = long) */
478 true, /* pc_relative */
480 complain_overflow_signed
, /* complain_on_overflow */
481 bfd_elf_generic_reloc
, /* special_function */
482 "R_MIPS_PC16", /* name */
483 true, /* partial_inplace */
484 0xffff, /* src_mask */
485 0xffff, /* dst_mask */
486 false), /* pcrel_offset */
488 /* 16 bit call through global offset table. */
489 /* FIXME: This is not handled correctly. */
490 HOWTO (R_MIPS_CALL16
, /* type */
492 2, /* size (0 = byte, 1 = short, 2 = long) */
494 false, /* pc_relative */
496 complain_overflow_signed
, /* complain_on_overflow */
497 bfd_elf_generic_reloc
, /* special_function */
498 "R_MIPS_CALL16", /* name */
499 false, /* partial_inplace */
501 0xffff, /* dst_mask */
502 false), /* pcrel_offset */
504 /* 32 bit GP relative reference. */
505 HOWTO (R_MIPS_GPREL32
, /* type */
507 2, /* size (0 = byte, 1 = short, 2 = long) */
509 false, /* pc_relative */
511 complain_overflow_bitfield
, /* complain_on_overflow */
512 _bfd_mips_elf_gprel32_reloc
, /* special_function */
513 "R_MIPS_GPREL32", /* name */
514 true, /* partial_inplace */
515 0xffffffff, /* src_mask */
516 0xffffffff, /* dst_mask */
517 false), /* pcrel_offset */
519 /* The remaining relocs are defined on Irix 5, although they are
520 not defined by the ABI. */
525 /* A 5 bit shift field. */
526 HOWTO (R_MIPS_SHIFT5
, /* type */
528 2, /* size (0 = byte, 1 = short, 2 = long) */
530 false, /* pc_relative */
532 complain_overflow_bitfield
, /* complain_on_overflow */
533 bfd_elf_generic_reloc
, /* special_function */
534 "R_MIPS_SHIFT5", /* name */
535 true, /* partial_inplace */
536 0x000007c0, /* src_mask */
537 0x000007c0, /* dst_mask */
538 false), /* pcrel_offset */
540 /* A 6 bit shift field. */
541 /* FIXME: This is not handled correctly; a special function is
542 needed to put the most significant bit in the right place. */
543 HOWTO (R_MIPS_SHIFT6
, /* type */
545 2, /* size (0 = byte, 1 = short, 2 = long) */
547 false, /* pc_relative */
549 complain_overflow_bitfield
, /* complain_on_overflow */
550 bfd_elf_generic_reloc
, /* special_function */
551 "R_MIPS_SHIFT6", /* name */
552 true, /* partial_inplace */
553 0x000007c4, /* src_mask */
554 0x000007c4, /* dst_mask */
555 false), /* pcrel_offset */
557 /* A 64 bit relocation. This is used in 32 bit ELF when addresses
558 are 64 bits long; the upper 32 bits are simply a sign extension.
559 The fields of the howto should be the same as for R_MIPS_32,
560 other than the type, name, and special_function. */
561 HOWTO (R_MIPS_64
, /* type */
563 2, /* size (0 = byte, 1 = short, 2 = long) */
565 false, /* pc_relative */
567 complain_overflow_bitfield
, /* complain_on_overflow */
568 mips32_64bit_reloc
, /* special_function */
569 "R_MIPS_64", /* name */
570 true, /* partial_inplace */
571 0xffffffff, /* src_mask */
572 0xffffffff, /* dst_mask */
573 false), /* pcrel_offset */
575 /* Displacement in the global offset table. */
576 /* FIXME: Not handled correctly. */
577 HOWTO (R_MIPS_GOT_DISP
, /* type */
579 2, /* size (0 = byte, 1 = short, 2 = long) */
581 false, /* pc_relative */
583 complain_overflow_bitfield
, /* complain_on_overflow */
584 bfd_elf_generic_reloc
, /* special_function */
585 "R_MIPS_GOT_DISP", /* name */
586 true, /* partial_inplace */
587 0x0000ffff, /* src_mask */
588 0x0000ffff, /* dst_mask */
589 false), /* pcrel_offset */
591 /* Displacement to page pointer in the global offset table. */
592 /* FIXME: Not handled correctly. */
593 HOWTO (R_MIPS_GOT_PAGE
, /* type */
595 2, /* size (0 = byte, 1 = short, 2 = long) */
597 false, /* pc_relative */
599 complain_overflow_bitfield
, /* complain_on_overflow */
600 bfd_elf_generic_reloc
, /* special_function */
601 "R_MIPS_GOT_PAGE", /* name */
602 true, /* partial_inplace */
603 0x0000ffff, /* src_mask */
604 0x0000ffff, /* dst_mask */
605 false), /* pcrel_offset */
607 /* Offset from page pointer in the global offset table. */
608 /* FIXME: Not handled correctly. */
609 HOWTO (R_MIPS_GOT_OFST
, /* type */
611 2, /* size (0 = byte, 1 = short, 2 = long) */
613 false, /* pc_relative */
615 complain_overflow_bitfield
, /* complain_on_overflow */
616 bfd_elf_generic_reloc
, /* special_function */
617 "R_MIPS_GOT_OFST", /* name */
618 true, /* partial_inplace */
619 0x0000ffff, /* src_mask */
620 0x0000ffff, /* dst_mask */
621 false), /* pcrel_offset */
623 /* High 16 bits of displacement in global offset table. */
624 /* FIXME: Not handled correctly. */
625 HOWTO (R_MIPS_GOT_HI16
, /* type */
627 2, /* size (0 = byte, 1 = short, 2 = long) */
629 false, /* pc_relative */
631 complain_overflow_dont
, /* complain_on_overflow */
632 bfd_elf_generic_reloc
, /* special_function */
633 "R_MIPS_GOT_HI16", /* name */
634 true, /* partial_inplace */
635 0x0000ffff, /* src_mask */
636 0x0000ffff, /* dst_mask */
637 false), /* pcrel_offset */
639 /* Low 16 bits of displacement in global offset table. */
640 /* FIXME: Not handled correctly. */
641 HOWTO (R_MIPS_GOT_LO16
, /* type */
643 2, /* size (0 = byte, 1 = short, 2 = long) */
645 false, /* pc_relative */
647 complain_overflow_dont
, /* complain_on_overflow */
648 bfd_elf_generic_reloc
, /* special_function */
649 "R_MIPS_GOT_LO16", /* name */
650 true, /* partial_inplace */
651 0x0000ffff, /* src_mask */
652 0x0000ffff, /* dst_mask */
653 false), /* pcrel_offset */
655 /* 64 bit subtraction. Presumably not used in 32 bit ELF. */
658 /* Used to cause the linker to insert and delete instructions? */
663 /* Get the higher values of a 64 bit addend. Presumably not used in
668 /* High 16 bits of displacement in global offset table. */
669 /* FIXME: Not handled correctly. */
670 HOWTO (R_MIPS_CALL_HI16
, /* type */
672 2, /* size (0 = byte, 1 = short, 2 = long) */
674 false, /* pc_relative */
676 complain_overflow_dont
, /* complain_on_overflow */
677 bfd_elf_generic_reloc
, /* special_function */
678 "R_MIPS_CALL_HI16", /* name */
679 true, /* partial_inplace */
680 0x0000ffff, /* src_mask */
681 0x0000ffff, /* dst_mask */
682 false), /* pcrel_offset */
684 /* Low 16 bits of displacement in global offset table. */
685 /* FIXME: Not handled correctly. */
686 HOWTO (R_MIPS_CALL_LO16
, /* type */
688 2, /* size (0 = byte, 1 = short, 2 = long) */
690 false, /* pc_relative */
692 complain_overflow_dont
, /* complain_on_overflow */
693 bfd_elf_generic_reloc
, /* special_function */
694 "R_MIPS_CALL_LO16", /* name */
695 true, /* partial_inplace */
696 0x0000ffff, /* src_mask */
697 0x0000ffff, /* dst_mask */
698 false) /* pcrel_offset */
701 /* The reloc used for the mips16 jump instruction. */
702 static reloc_howto_type elf_mips16_jump_howto
=
703 HOWTO (R_MIPS16_26
, /* type */
705 2, /* size (0 = byte, 1 = short, 2 = long) */
707 false, /* pc_relative */
709 complain_overflow_dont
, /* complain_on_overflow */
710 /* This needs complex overflow
711 detection, because the upper four
712 bits must match the PC. */
713 mips16_jump_reloc
, /* special_function */
714 "R_MIPS16_26", /* name */
715 true, /* partial_inplace */
716 0x3ffffff, /* src_mask */
717 0x3ffffff, /* dst_mask */
718 false); /* pcrel_offset */
720 /* The reloc used for the mips16 gprel instruction. The src_mask and
721 dsk_mask for this howto do not reflect the actual instruction, in
722 which the value is not contiguous; the masks are for the
723 convenience of the relocate_section routine. */
724 static reloc_howto_type elf_mips16_gprel_howto
=
725 HOWTO (R_MIPS16_GPREL
, /* type */
727 2, /* size (0 = byte, 1 = short, 2 = long) */
729 false, /* pc_relative */
731 complain_overflow_signed
, /* complain_on_overflow */
732 mips16_gprel_reloc
, /* special_function */
733 "R_MIPS16_GPREL", /* name */
734 true, /* partial_inplace */
735 0xffff, /* src_mask */
736 0xffff, /* dst_mask */
737 false); /* pcrel_offset */
739 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
740 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
741 the HI16. Here we just save the information we need; we do the
742 actual relocation when we see the LO16. MIPS ELF requires that the
743 LO16 immediately follow the HI16. As a GNU extension, we permit an
744 arbitrary number of HI16 relocs to be associated with a single LO16
745 reloc. This extension permits gcc to output the HI and LO relocs
750 struct mips_hi16
*next
;
755 /* FIXME: This should not be a static variable. */
757 static struct mips_hi16
*mips_hi16_list
;
759 bfd_reloc_status_type
760 _bfd_mips_elf_hi16_reloc (abfd
,
768 arelent
*reloc_entry
;
771 asection
*input_section
;
773 char **error_message
;
775 bfd_reloc_status_type ret
;
779 /* If we're relocating, and this an external symbol, we don't want
780 to change anything. */
781 if (output_bfd
!= (bfd
*) NULL
782 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
783 && reloc_entry
->addend
== 0)
785 reloc_entry
->address
+= input_section
->output_offset
;
791 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
793 boolean relocateable
;
796 if (ret
== bfd_reloc_undefined
)
799 if (output_bfd
!= NULL
)
803 relocateable
= false;
804 output_bfd
= symbol
->section
->output_section
->owner
;
807 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
809 if (ret
!= bfd_reloc_ok
)
812 relocation
= gp
- reloc_entry
->address
;
816 if (bfd_is_und_section (symbol
->section
)
817 && output_bfd
== (bfd
*) NULL
)
818 ret
= bfd_reloc_undefined
;
820 if (bfd_is_com_section (symbol
->section
))
823 relocation
= symbol
->value
;
826 relocation
+= symbol
->section
->output_section
->vma
;
827 relocation
+= symbol
->section
->output_offset
;
828 relocation
+= reloc_entry
->addend
;
830 if (reloc_entry
->address
> input_section
->_cooked_size
)
831 return bfd_reloc_outofrange
;
833 /* Save the information, and let LO16 do the actual relocation. */
834 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
836 return bfd_reloc_outofrange
;
837 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
838 n
->addend
= relocation
;
839 n
->next
= mips_hi16_list
;
842 if (output_bfd
!= (bfd
*) NULL
)
843 reloc_entry
->address
+= input_section
->output_offset
;
848 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
849 inplace relocation; this function exists in order to do the
850 R_MIPS_HI16 relocation described above. */
852 bfd_reloc_status_type
853 _bfd_mips_elf_lo16_reloc (abfd
,
861 arelent
*reloc_entry
;
864 asection
*input_section
;
866 char **error_message
;
868 arelent gp_disp_relent
;
870 if (mips_hi16_list
!= NULL
)
880 struct mips_hi16
*next
;
882 /* Do the HI16 relocation. Note that we actually don't need
883 to know anything about the LO16 itself, except where to
884 find the low 16 bits of the addend needed by the LO16. */
885 insn
= bfd_get_32 (abfd
, l
->addr
);
886 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
888 val
= ((insn
& 0xffff) << 16) + vallo
;
891 /* The low order 16 bits are always treated as a signed
892 value. Therefore, a negative value in the low order bits
893 requires an adjustment in the high order bits. We need
894 to make this adjustment in two ways: once for the bits we
895 took from the data, and once for the bits we are putting
896 back in to the data. */
897 if ((vallo
& 0x8000) != 0)
899 if ((val
& 0x8000) != 0)
902 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
903 bfd_put_32 (abfd
, insn
, l
->addr
);
905 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
907 gp_disp_relent
= *reloc_entry
;
908 reloc_entry
= &gp_disp_relent
;
909 reloc_entry
->addend
= l
->addend
;
917 mips_hi16_list
= NULL
;
919 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
921 bfd_reloc_status_type ret
;
922 bfd_vma gp
, relocation
;
924 /* FIXME: Does this case ever occur? */
926 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
927 if (ret
!= bfd_reloc_ok
)
930 relocation
= gp
- reloc_entry
->address
;
931 relocation
+= symbol
->section
->output_section
->vma
;
932 relocation
+= symbol
->section
->output_offset
;
933 relocation
+= reloc_entry
->addend
;
935 if (reloc_entry
->address
> input_section
->_cooked_size
)
936 return bfd_reloc_outofrange
;
938 gp_disp_relent
= *reloc_entry
;
939 reloc_entry
= &gp_disp_relent
;
940 reloc_entry
->addend
= relocation
- 4;
943 /* Now do the LO16 reloc in the usual way. */
944 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
945 input_section
, output_bfd
, error_message
);
948 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
949 table used for PIC code. If the symbol is an external symbol, the
950 instruction is modified to contain the offset of the appropriate
951 entry in the global offset table. If the symbol is a section
952 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
953 addends are combined to form the real addend against the section
954 symbol; the GOT16 is modified to contain the offset of an entry in
955 the global offset table, and the LO16 is modified to offset it
956 appropriately. Thus an offset larger than 16 bits requires a
957 modified value in the global offset table.
959 This implementation suffices for the assembler, but the linker does
960 not yet know how to create global offset tables. */
962 bfd_reloc_status_type
963 _bfd_mips_elf_got16_reloc (abfd
,
971 arelent
*reloc_entry
;
974 asection
*input_section
;
976 char **error_message
;
978 /* If we're relocating, and this an external symbol, we don't want
979 to change anything. */
980 if (output_bfd
!= (bfd
*) NULL
981 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
982 && reloc_entry
->addend
== 0)
984 reloc_entry
->address
+= input_section
->output_offset
;
988 /* If we're relocating, and this is a local symbol, we can handle it
990 if (output_bfd
!= (bfd
*) NULL
991 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
992 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
993 input_section
, output_bfd
, error_message
);
998 /* We have to figure out the gp value, so that we can adjust the
999 symbol value correctly. We look up the symbol _gp in the output
1000 BFD. If we can't find it, we're stuck. We cache it in the ELF
1001 target data. We don't need to adjust the symbol value for an
1002 external symbol if we are producing relocateable output. */
1004 static bfd_reloc_status_type
1005 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1008 boolean relocateable
;
1009 char **error_message
;
1012 if (bfd_is_und_section (symbol
->section
)
1016 return bfd_reloc_undefined
;
1019 *pgp
= _bfd_get_gp_value (output_bfd
);
1022 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1026 /* Make up a value. */
1027 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1028 _bfd_set_gp_value (output_bfd
, *pgp
);
1036 count
= bfd_get_symcount (output_bfd
);
1037 sym
= bfd_get_outsymbols (output_bfd
);
1039 if (sym
== (asymbol
**) NULL
)
1043 for (i
= 0; i
< count
; i
++, sym
++)
1045 register CONST
char *name
;
1047 name
= bfd_asymbol_name (*sym
);
1048 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1050 *pgp
= bfd_asymbol_value (*sym
);
1051 _bfd_set_gp_value (output_bfd
, *pgp
);
1059 /* Only get the error once. */
1061 _bfd_set_gp_value (output_bfd
, *pgp
);
1063 (char *) "GP relative relocation when _gp not defined";
1064 return bfd_reloc_dangerous
;
1069 return bfd_reloc_ok
;
1072 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1073 become the offset from the gp register. This function also handles
1074 R_MIPS_LITERAL relocations, although those can be handled more
1075 cleverly because the entries in the .lit8 and .lit4 sections can be
1078 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1079 arelent
*, asection
*,
1080 boolean
, PTR
, bfd_vma
));
1082 bfd_reloc_status_type
1083 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1084 output_bfd
, error_message
)
1086 arelent
*reloc_entry
;
1089 asection
*input_section
;
1091 char **error_message
;
1093 boolean relocateable
;
1094 bfd_reloc_status_type ret
;
1097 /* If we're relocating, and this is an external symbol with no
1098 addend, we don't want to change anything. We will only have an
1099 addend if this is a newly created reloc, not read from an ELF
1101 if (output_bfd
!= (bfd
*) NULL
1102 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1103 && reloc_entry
->addend
== 0)
1105 reloc_entry
->address
+= input_section
->output_offset
;
1106 return bfd_reloc_ok
;
1109 if (output_bfd
!= (bfd
*) NULL
)
1110 relocateable
= true;
1113 relocateable
= false;
1114 output_bfd
= symbol
->section
->output_section
->owner
;
1117 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1119 if (ret
!= bfd_reloc_ok
)
1122 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1123 relocateable
, data
, gp
);
1126 static bfd_reloc_status_type
1127 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1131 arelent
*reloc_entry
;
1132 asection
*input_section
;
1133 boolean relocateable
;
1141 if (bfd_is_com_section (symbol
->section
))
1144 relocation
= symbol
->value
;
1146 relocation
+= symbol
->section
->output_section
->vma
;
1147 relocation
+= symbol
->section
->output_offset
;
1149 if (reloc_entry
->address
> input_section
->_cooked_size
)
1150 return bfd_reloc_outofrange
;
1152 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1154 /* Set val to the offset into the section or symbol. */
1155 if (reloc_entry
->howto
->src_mask
== 0)
1157 /* This case occurs with the 64-bit MIPS ELF ABI. */
1158 val
= reloc_entry
->addend
;
1162 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1167 /* Adjust val for the final section location and GP value. If we
1168 are producing relocateable output, we don't want to do this for
1169 an external symbol. */
1171 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1172 val
+= relocation
- gp
;
1174 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1175 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1178 reloc_entry
->address
+= input_section
->output_offset
;
1180 /* Make sure it fit in 16 bits. */
1181 if (val
>= 0x8000 && val
< 0xffff8000)
1182 return bfd_reloc_overflow
;
1184 return bfd_reloc_ok
;
1187 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1188 from the gp register? XXX */
1190 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1191 arelent
*, asection
*,
1192 boolean
, PTR
, bfd_vma
));
1194 bfd_reloc_status_type
1195 _bfd_mips_elf_gprel32_reloc (abfd
,
1203 arelent
*reloc_entry
;
1206 asection
*input_section
;
1208 char **error_message
;
1210 boolean relocateable
;
1211 bfd_reloc_status_type ret
;
1214 /* If we're relocating, and this is an external symbol with no
1215 addend, we don't want to change anything. We will only have an
1216 addend if this is a newly created reloc, not read from an ELF
1218 if (output_bfd
!= (bfd
*) NULL
1219 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1220 && reloc_entry
->addend
== 0)
1222 *error_message
= (char *)
1223 "32bits gp relative relocation occurs for an external symbol";
1224 return bfd_reloc_outofrange
;
1227 if (output_bfd
!= (bfd
*) NULL
)
1229 relocateable
= true;
1230 gp
= _bfd_get_gp_value (output_bfd
);
1234 relocateable
= false;
1235 output_bfd
= symbol
->section
->output_section
->owner
;
1237 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1238 error_message
, &gp
);
1239 if (ret
!= bfd_reloc_ok
)
1243 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1244 relocateable
, data
, gp
);
1247 static bfd_reloc_status_type
1248 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1252 arelent
*reloc_entry
;
1253 asection
*input_section
;
1254 boolean relocateable
;
1261 if (bfd_is_com_section (symbol
->section
))
1264 relocation
= symbol
->value
;
1266 relocation
+= symbol
->section
->output_section
->vma
;
1267 relocation
+= symbol
->section
->output_offset
;
1269 if (reloc_entry
->address
> input_section
->_cooked_size
)
1270 return bfd_reloc_outofrange
;
1272 if (reloc_entry
->howto
->src_mask
== 0)
1274 /* This case arises with the 64-bit MIPS ELF ABI. */
1278 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1280 /* Set val to the offset into the section or symbol. */
1281 val
+= reloc_entry
->addend
;
1283 /* Adjust val for the final section location and GP value. If we
1284 are producing relocateable output, we don't want to do this for
1285 an external symbol. */
1287 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1288 val
+= relocation
- gp
;
1290 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1293 reloc_entry
->address
+= input_section
->output_offset
;
1295 return bfd_reloc_ok
;
1298 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1299 generated when addreses are 64 bits. The upper 32 bits are a simle
1302 static bfd_reloc_status_type
1303 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1304 output_bfd
, error_message
)
1306 arelent
*reloc_entry
;
1309 asection
*input_section
;
1311 char **error_message
;
1313 bfd_reloc_status_type r
;
1318 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1319 input_section
, output_bfd
, error_message
);
1320 if (r
!= bfd_reloc_continue
)
1323 /* Do a normal 32 bit relocation on the lower 32 bits. */
1324 reloc32
= *reloc_entry
;
1325 if (bfd_big_endian (abfd
))
1326 reloc32
.address
+= 4;
1327 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1328 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1329 output_bfd
, error_message
);
1331 /* Sign extend into the upper 32 bits. */
1332 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1333 if ((val
& 0x80000000) != 0)
1337 addr
= reloc_entry
->address
;
1338 if (bfd_little_endian (abfd
))
1340 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1345 /* Handle a mips16 jump. */
1347 static bfd_reloc_status_type
1348 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1349 output_bfd
, error_message
)
1351 arelent
*reloc_entry
;
1354 asection
*input_section
;
1356 char **error_message
;
1358 if (output_bfd
!= (bfd
*) NULL
1359 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1360 && reloc_entry
->addend
== 0)
1362 reloc_entry
->address
+= input_section
->output_offset
;
1363 return bfd_reloc_ok
;
1370 /* Handle a mips16 GP relative reloc. */
1372 static bfd_reloc_status_type
1373 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1374 output_bfd
, error_message
)
1376 arelent
*reloc_entry
;
1379 asection
*input_section
;
1381 char **error_message
;
1383 boolean relocateable
;
1384 bfd_reloc_status_type ret
;
1386 unsigned short extend
, insn
;
1387 unsigned long final
;
1389 /* If we're relocating, and this is an external symbol with no
1390 addend, we don't want to change anything. We will only have an
1391 addend if this is a newly created reloc, not read from an ELF
1393 if (output_bfd
!= NULL
1394 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1395 && reloc_entry
->addend
== 0)
1397 reloc_entry
->address
+= input_section
->output_offset
;
1398 return bfd_reloc_ok
;
1401 if (output_bfd
!= NULL
)
1402 relocateable
= true;
1405 relocateable
= false;
1406 output_bfd
= symbol
->section
->output_section
->owner
;
1409 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1411 if (ret
!= bfd_reloc_ok
)
1414 if (reloc_entry
->address
> input_section
->_cooked_size
)
1415 return bfd_reloc_outofrange
;
1417 /* Pick up the mips16 extend instruction and the real instruction. */
1418 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1419 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1421 /* Stuff the current addend back as a 32 bit value, do the usual
1422 relocation, and then clean up. */
1424 (((extend
& 0x1f) << 11)
1427 (bfd_byte
*) data
+ reloc_entry
->address
);
1429 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1430 relocateable
, data
, gp
);
1432 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1435 | ((final
>> 11) & 0x1f)
1437 (bfd_byte
*) data
+ reloc_entry
->address
);
1441 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1446 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1448 struct elf_reloc_map
{
1449 bfd_reloc_code_real_type bfd_reloc_val
;
1450 enum reloc_type elf_reloc_val
;
1453 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1455 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1456 { BFD_RELOC_16
, R_MIPS_16
},
1457 { BFD_RELOC_32
, R_MIPS_32
},
1458 { BFD_RELOC_CTOR
, R_MIPS_32
},
1459 { BFD_RELOC_64
, R_MIPS_64
},
1460 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1461 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1462 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1463 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1464 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1465 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1466 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1467 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1468 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1469 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1470 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1471 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1472 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
}
1475 /* Given a BFD reloc type, return a howto structure. */
1477 static reloc_howto_type
*
1478 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1480 bfd_reloc_code_real_type code
;
1484 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1486 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1487 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1490 /* Special handling for the MIPS16 relocs, since they are made up
1491 reloc types with a large value. */
1492 if (code
== BFD_RELOC_MIPS16_JMP
)
1493 return &elf_mips16_jump_howto
;
1494 else if (code
== BFD_RELOC_MIPS16_GPREL
)
1495 return &elf_mips16_gprel_howto
;
1500 /* Given a MIPS reloc type, fill in an arelent structure. */
1503 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1506 Elf32_Internal_Rel
*dst
;
1508 unsigned int r_type
;
1510 r_type
= ELF32_R_TYPE (dst
->r_info
);
1511 if (r_type
== R_MIPS16_26
)
1512 cache_ptr
->howto
= &elf_mips16_jump_howto
;
1513 else if (r_type
== R_MIPS16_GPREL
)
1514 cache_ptr
->howto
= &elf_mips16_gprel_howto
;
1517 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1518 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1521 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1522 value for the object file. We get the addend now, rather than
1523 when we do the relocation, because the symbol manipulations done
1524 by the linker may cause us to lose track of the input BFD. */
1525 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1526 && (r_type
== (unsigned int) R_MIPS_GPREL16
1527 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1528 cache_ptr
->addend
= elf_gp (abfd
);
1531 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1532 routines swap this structure in and out. They are used outside of
1533 BFD, so they are globally visible. */
1536 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1538 const Elf32_External_RegInfo
*ex
;
1541 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1542 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1543 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1544 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1545 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1546 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1550 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1552 const Elf32_RegInfo
*in
;
1553 Elf32_External_RegInfo
*ex
;
1555 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1556 (bfd_byte
*) ex
->ri_gprmask
);
1557 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1558 (bfd_byte
*) ex
->ri_cprmask
[0]);
1559 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1560 (bfd_byte
*) ex
->ri_cprmask
[1]);
1561 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1562 (bfd_byte
*) ex
->ri_cprmask
[2]);
1563 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1564 (bfd_byte
*) ex
->ri_cprmask
[3]);
1565 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1566 (bfd_byte
*) ex
->ri_gp_value
);
1569 /* In the 64 bit ABI, the .MIPS.options section holds register
1570 information in an Elf64_Reginfo structure. These routines swap
1571 them in and out. They are globally visible because they are used
1572 outside of BFD. These routines are here so that gas can call them
1573 without worrying about whether the 64 bit ABI has been included. */
1576 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1578 const Elf64_External_RegInfo
*ex
;
1579 Elf64_Internal_RegInfo
*in
;
1581 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1582 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
1583 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1584 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1585 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1586 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1587 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1591 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1593 const Elf64_Internal_RegInfo
*in
;
1594 Elf64_External_RegInfo
*ex
;
1596 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1597 (bfd_byte
*) ex
->ri_gprmask
);
1598 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
1599 (bfd_byte
*) ex
->ri_pad
);
1600 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1601 (bfd_byte
*) ex
->ri_cprmask
[0]);
1602 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1603 (bfd_byte
*) ex
->ri_cprmask
[1]);
1604 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1605 (bfd_byte
*) ex
->ri_cprmask
[2]);
1606 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1607 (bfd_byte
*) ex
->ri_cprmask
[3]);
1608 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1609 (bfd_byte
*) ex
->ri_gp_value
);
1612 /* Swap an entry in a .gptab section. Note that these routines rely
1613 on the equivalence of the two elements of the union. */
1616 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1618 const Elf32_External_gptab
*ex
;
1621 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1622 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1626 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1628 const Elf32_gptab
*in
;
1629 Elf32_External_gptab
*ex
;
1631 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1632 ex
->gt_entry
.gt_g_value
);
1633 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1634 ex
->gt_entry
.gt_bytes
);
1638 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1640 const Elf32_compact_rel
*in
;
1641 Elf32_External_compact_rel
*ex
;
1643 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
1644 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
1645 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
1646 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
1647 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
1648 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
1652 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1654 const Elf32_crinfo
*in
;
1655 Elf32_External_crinfo
*ex
;
1659 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1660 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1661 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1662 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1663 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
1664 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
1665 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
1668 /* Swap in an options header. */
1671 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1673 const Elf_External_Options
*ex
;
1674 Elf_Internal_Options
*in
;
1676 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
1677 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
1678 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
1679 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
1682 /* Swap out an options header. */
1685 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
1687 const Elf_Internal_Options
*in
;
1688 Elf_External_Options
*ex
;
1690 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
1691 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
1692 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
1693 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
1696 /* Determine whether a symbol is global for the purposes of splitting
1697 the symbol table into global symbols and local symbols. At least
1698 on Irix 5, this split must be between section symbols and all other
1699 symbols. On most ELF targets the split is between static symbols
1700 and externally visible symbols. */
1704 mips_elf_sym_is_global (abfd
, sym
)
1708 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
1711 /* Set the right machine number for a MIPS ELF file. This is used for
1712 both the 32-bit and the 64-bit ABI. */
1715 _bfd_mips_elf_object_p (abfd
)
1718 switch (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
)
1722 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 3000);
1726 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 6000);
1730 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 4000);
1734 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 8000);
1741 /* Set the right machine number for a 32-bit MIPS ELF file. */
1744 mips_elf32_object_p (abfd
)
1747 /* Irix 5 is broken. Object file symbol tables are not always
1748 sorted correctly such that local symbols precede global symbols,
1749 and the sh_info field in the symbol table is not always right. */
1750 elf_bad_symtab (abfd
) = true;
1752 return _bfd_mips_elf_object_p (abfd
);
1755 /* The final processing done just before writing out a MIPS ELF object
1756 file. This gets the MIPS architecture right based on the machine
1757 number. This is used by both the 32-bit and the 64-bit ABI. */
1761 _bfd_mips_elf_final_write_processing (abfd
, linker
)
1767 Elf_Internal_Shdr
**hdrpp
;
1771 switch (bfd_get_mach (abfd
))
1774 val
= E_MIPS_ARCH_1
;
1778 val
= E_MIPS_ARCH_2
;
1782 val
= E_MIPS_ARCH_3
;
1786 val
= E_MIPS_ARCH_4
;
1794 elf_elfheader (abfd
)->e_flags
&=~ EF_MIPS_ARCH
;
1795 elf_elfheader (abfd
)->e_flags
|= val
;
1797 /* Set the sh_info field for .gptab sections. */
1798 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
1799 i
< elf_elfheader (abfd
)->e_shnum
;
1802 switch ((*hdrpp
)->sh_type
)
1804 case SHT_MIPS_LIBLIST
:
1805 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
1807 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
1810 case SHT_MIPS_GPTAB
:
1811 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1812 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1813 BFD_ASSERT (name
!= NULL
1814 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
1815 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
1816 BFD_ASSERT (sec
!= NULL
);
1817 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1820 case SHT_MIPS_CONTENT
:
1821 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1822 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1823 BFD_ASSERT (name
!= NULL
1824 && strncmp (name
, ".MIPS.content",
1825 sizeof ".MIPS.content" - 1) == 0);
1826 sec
= bfd_get_section_by_name (abfd
,
1827 name
+ sizeof ".MIPS.content" - 1);
1828 BFD_ASSERT (sec
!= NULL
);
1829 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1832 case SHT_MIPS_SYMBOL_LIB
:
1833 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
1835 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
1836 sec
= bfd_get_section_by_name (abfd
, ".liblist");
1838 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1841 case SHT_MIPS_EVENTS
:
1842 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1843 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1844 BFD_ASSERT (name
!= NULL
);
1845 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
1846 sec
= bfd_get_section_by_name (abfd
,
1847 name
+ sizeof ".MIPS.events" - 1);
1850 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
1851 sizeof ".MIPS.post_rel" - 1) == 0);
1852 sec
= bfd_get_section_by_name (abfd
,
1854 + sizeof ".MIPS.post_rel" - 1));
1856 BFD_ASSERT (sec
!= NULL
);
1857 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
1863 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
1866 _bfd_mips_elf_set_private_flags (abfd
, flags
)
1870 BFD_ASSERT (!elf_flags_init (abfd
)
1871 || elf_elfheader (abfd
)->e_flags
== flags
);
1873 elf_elfheader (abfd
)->e_flags
= flags
;
1874 elf_flags_init (abfd
) = true;
1878 /* Copy backend specific data from one object module to another */
1881 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
1885 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1886 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1889 BFD_ASSERT (!elf_flags_init (obfd
)
1890 || (elf_elfheader (obfd
)->e_flags
1891 == elf_elfheader (ibfd
)->e_flags
));
1893 elf_gp (obfd
) = elf_gp (ibfd
);
1894 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1895 elf_flags_init (obfd
) = true;
1899 /* Return the ISA for a MIPS e_flags value. */
1902 elf_mips_isa (flags
)
1905 switch (flags
& EF_MIPS_ARCH
)
1919 /* Merge backend specific data from an object file to the output
1920 object file when linking. */
1923 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
1931 /* Check if we have the same endianess */
1932 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1933 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1935 (*_bfd_error_handler
)
1936 ("%s: compiled for a %s endian system and target is %s endian",
1937 bfd_get_filename (ibfd
),
1938 bfd_big_endian (ibfd
) ? "big" : "little",
1939 bfd_big_endian (obfd
) ? "big" : "little");
1941 bfd_set_error (bfd_error_wrong_format
);
1945 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1946 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1949 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1950 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
1951 old_flags
= elf_elfheader (obfd
)->e_flags
;
1953 if (! elf_flags_init (obfd
))
1955 elf_flags_init (obfd
) = true;
1956 elf_elfheader (obfd
)->e_flags
= new_flags
;
1958 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
1959 && bfd_get_arch_info (obfd
)->the_default
)
1961 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
1962 bfd_get_mach (ibfd
)))
1969 /* Check flag compatibility. */
1971 new_flags
&= ~EF_MIPS_NOREORDER
;
1972 old_flags
&= ~EF_MIPS_NOREORDER
;
1974 if (new_flags
== old_flags
)
1979 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
1981 new_flags
&= ~EF_MIPS_PIC
;
1982 old_flags
&= ~EF_MIPS_PIC
;
1983 (*_bfd_error_handler
)
1984 ("%s: linking PIC files with non-PIC files",
1985 bfd_get_filename (ibfd
));
1989 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
1991 new_flags
&= ~EF_MIPS_CPIC
;
1992 old_flags
&= ~EF_MIPS_CPIC
;
1993 (*_bfd_error_handler
)
1994 ("%s: linking abicalls files with non-abicalls files",
1995 bfd_get_filename (ibfd
));
1999 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
2000 and -mips4 code. They will normally use the same data sizes and
2001 calling conventions. */
2002 if ((new_flags
& EF_MIPS_ARCH
) != (old_flags
& EF_MIPS_ARCH
))
2004 int new_isa
, old_isa
;
2006 new_isa
= elf_mips_isa (new_flags
);
2007 old_isa
= elf_mips_isa (old_flags
);
2008 if ((new_isa
== 1 || new_isa
== 2)
2009 ? (old_isa
!= 1 && old_isa
!= 2)
2010 : (old_isa
== 1 || old_isa
== 2))
2012 (*_bfd_error_handler
)
2013 ("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)",
2014 bfd_get_filename (ibfd
), new_isa
, old_isa
);
2018 new_flags
&= ~ EF_MIPS_ARCH
;
2019 old_flags
&= ~ EF_MIPS_ARCH
;
2022 /* Warn about any other mismatches */
2023 if (new_flags
!= old_flags
)
2025 (*_bfd_error_handler
)
2026 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
2027 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
2028 (unsigned long) old_flags
);
2034 bfd_set_error (bfd_error_bad_value
);
2041 /* Handle a MIPS specific section when reading an object file. This
2042 is called when elfcode.h finds a section with an unknown type.
2043 This routine supports both the 32-bit and 64-bit ELF ABI.
2045 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2049 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
2051 Elf_Internal_Shdr
*hdr
;
2054 /* There ought to be a place to keep ELF backend specific flags, but
2055 at the moment there isn't one. We just keep track of the
2056 sections by their name, instead. Fortunately, the ABI gives
2057 suggested names for all the MIPS specific sections, so we will
2058 probably get away with this. */
2059 switch (hdr
->sh_type
)
2061 case SHT_MIPS_LIBLIST
:
2062 if (strcmp (name
, ".liblist") != 0)
2066 if (strcmp (name
, ".msym") != 0)
2069 case SHT_MIPS_CONFLICT
:
2070 if (strcmp (name
, ".conflict") != 0)
2073 case SHT_MIPS_GPTAB
:
2074 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
2077 case SHT_MIPS_UCODE
:
2078 if (strcmp (name
, ".ucode") != 0)
2081 case SHT_MIPS_DEBUG
:
2082 if (strcmp (name
, ".mdebug") != 0)
2085 case SHT_MIPS_REGINFO
:
2086 if (strcmp (name
, ".reginfo") != 0
2087 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
2090 case SHT_MIPS_IFACE
:
2091 if (strcmp (name
, ".MIPS.interfaces") != 0)
2094 case SHT_MIPS_CONTENT
:
2095 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2098 case SHT_MIPS_OPTIONS
:
2099 if (strcmp (name
, ".options") != 0
2100 && strcmp (name
, ".MIPS.options") != 0)
2103 case SHT_MIPS_DWARF
:
2104 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2107 case SHT_MIPS_SYMBOL_LIB
:
2108 if (strcmp (name
, ".MIPS.symlib") != 0)
2111 case SHT_MIPS_EVENTS
:
2112 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2113 && strncmp (name
, ".MIPS.post_rel",
2114 sizeof ".MIPS.post_rel" - 1) != 0)
2121 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2124 if (hdr
->sh_type
== SHT_MIPS_DEBUG
)
2126 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
2127 (bfd_get_section_flags (abfd
,
2136 /* Handle a 32-bit MIPS ELF specific section. */
2139 mips_elf32_section_from_shdr (abfd
, hdr
, name
)
2141 Elf_Internal_Shdr
*hdr
;
2144 if (! _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
))
2147 /* FIXME: We should record sh_info for a .gptab section. */
2149 /* For a .reginfo section, set the gp value in the tdata information
2150 from the contents of this section. We need the gp value while
2151 processing relocs, so we just get it now. The .reginfo section
2152 is not used in the 64-bit MIPS ELF ABI. */
2153 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2155 Elf32_External_RegInfo ext
;
2158 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
2159 (file_ptr
) 0, sizeof ext
))
2161 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
2162 elf_gp (abfd
) = s
.ri_gp_value
;
2165 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2166 set the gp value based on what we find. We may see both
2167 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2168 they should agree. */
2169 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
2171 bfd_byte
*contents
, *l
, *lend
;
2173 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
2174 if (contents
== NULL
)
2176 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
2177 (file_ptr
) 0, hdr
->sh_size
))
2183 lend
= contents
+ hdr
->sh_size
;
2184 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2186 Elf_Internal_Options intopt
;
2188 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2190 if (intopt
.kind
== ODK_REGINFO
)
2192 Elf32_RegInfo intreg
;
2194 bfd_mips_elf32_swap_reginfo_in
2196 ((Elf32_External_RegInfo
*)
2197 (l
+ sizeof (Elf_External_Options
))),
2199 elf_gp (abfd
) = intreg
.ri_gp_value
;
2209 /* Set the correct type for a MIPS ELF section. We do this by the
2210 section name, which is a hack, but ought to work. This routine is
2211 used by both the 32-bit and the 64-bit ABI. */
2214 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
2216 Elf32_Internal_Shdr
*hdr
;
2219 register const char *name
;
2221 name
= bfd_get_section_name (abfd
, sec
);
2223 if (strcmp (name
, ".liblist") == 0)
2225 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
2226 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
2227 /* The sh_link field is set in final_write_processing. */
2229 else if (strcmp (name
, ".msym") == 0)
2231 hdr
->sh_type
= SHT_MIPS_MSYM
;
2232 hdr
->sh_entsize
= 8;
2233 /* FIXME: Set the sh_info field. */
2235 else if (strcmp (name
, ".conflict") == 0)
2236 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
2237 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2239 hdr
->sh_type
= SHT_MIPS_GPTAB
;
2240 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
2241 /* The sh_info field is set in final_write_processing. */
2243 else if (strcmp (name
, ".ucode") == 0)
2244 hdr
->sh_type
= SHT_MIPS_UCODE
;
2245 else if (strcmp (name
, ".mdebug") == 0)
2247 hdr
->sh_type
= SHT_MIPS_DEBUG
;
2248 /* In a shared object on Irix 5.3, the .mdebug section has an
2249 entsize of 0. FIXME: Does this matter? */
2250 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2251 hdr
->sh_entsize
= 0;
2253 hdr
->sh_entsize
= 1;
2255 else if (strcmp (name
, ".reginfo") == 0)
2257 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2258 /* In a shared object on Irix 5.3, the .reginfo section has an
2259 entsize of 0x18. FIXME: Does this matter? */
2260 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2261 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2263 hdr
->sh_entsize
= 1;
2265 /* Force the section size to the correct value, even if the
2266 linker thinks it is larger. The link routine below will only
2267 write out this much data for .reginfo. */
2268 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf32_External_RegInfo
);
2270 else if (SGI_COMPAT (abfd
)
2271 && (strcmp (name
, ".hash") == 0
2272 || strcmp (name
, ".dynamic") == 0
2273 || strcmp (name
, ".dynstr") == 0))
2275 hdr
->sh_entsize
= 0;
2276 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2278 else if (strcmp (name
, ".got") == 0
2279 || strcmp (name
, ".sdata") == 0
2280 || strcmp (name
, ".sbss") == 0
2281 || strcmp (name
, ".lit4") == 0
2282 || strcmp (name
, ".lit8") == 0)
2283 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2284 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2286 hdr
->sh_type
= SHT_MIPS_IFACE
;
2287 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2289 else if (strcmp (name
, ".MIPS.content") == 0)
2291 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2292 /* The sh_info field is set in final_write_processing. */
2294 else if (strcmp (name
, ".options") == 0
2295 || strcmp (name
, ".MIPS.options") == 0)
2297 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2298 hdr
->sh_entsize
= 1;
2299 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2301 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2302 hdr
->sh_type
= SHT_MIPS_DWARF
;
2303 else if (strcmp (name
, ".MIPS.symlib") == 0)
2305 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2306 /* The sh_link and sh_info fields are set in
2307 final_write_processing. */
2309 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2310 || strncmp (name
, ".MIPS.post_rel",
2311 sizeof ".MIPS.post_rel" - 1) == 0)
2313 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2314 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2315 /* The sh_link field is set in final_write_processing. */
2321 /* Given a BFD section, try to locate the corresponding ELF section
2322 index. This is used by both the 32-bit and the 64-bit ABI.
2323 Actually, it's not clear to me that the 64-bit ABI supports these,
2324 but for non-PIC objects we will certainly want support for at least
2325 the .scommon section. */
2328 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2330 Elf32_Internal_Shdr
*hdr
;
2334 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2336 *retval
= SHN_MIPS_SCOMMON
;
2339 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2341 *retval
= SHN_MIPS_ACOMMON
;
2347 /* When are writing out the .options or .MIPS.options section,
2348 remember the bytes we are writing out, so that we can install the
2349 GP value in the section_processing routine. */
2352 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2357 bfd_size_type count
;
2359 if (strcmp (section
->name
, ".options") == 0
2360 || strcmp (section
->name
, ".MIPS.options") == 0)
2364 if (elf_section_data (section
) == NULL
)
2366 section
->used_by_bfd
=
2367 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
2368 if (elf_section_data (section
) == NULL
)
2371 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
2376 if (section
->_cooked_size
!= 0)
2377 size
= section
->_cooked_size
;
2379 size
= section
->_raw_size
;
2380 c
= (PTR
) bfd_zalloc (abfd
, size
);
2383 elf_section_data (section
)->tdata
= (PTR
) c
;
2386 memcpy (c
+ offset
, location
, count
);
2389 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
2393 /* Work over a section just before writing it out. This routine is
2394 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2395 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2399 _bfd_mips_elf_section_processing (abfd
, hdr
)
2401 Elf_Internal_Shdr
*hdr
;
2403 if (hdr
->bfd_section
!= NULL
)
2405 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
2407 if (strcmp (name
, ".sdata") == 0)
2409 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2410 hdr
->sh_type
= SHT_PROGBITS
;
2412 else if (strcmp (name
, ".sbss") == 0)
2414 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2415 hdr
->sh_type
= SHT_NOBITS
;
2417 else if (strcmp (name
, ".lit8") == 0
2418 || strcmp (name
, ".lit4") == 0)
2420 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2421 hdr
->sh_type
= SHT_PROGBITS
;
2423 else if (strcmp (name
, ".compact_rel") == 0)
2426 hdr
->sh_type
= SHT_PROGBITS
;
2428 else if (strcmp (name
, ".rtproc") == 0)
2430 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
2432 unsigned int adjust
;
2434 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
2436 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
2444 /* Work over a section just before writing it out. We update the GP
2445 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2446 on the value we are using. */
2449 mips_elf32_section_processing (abfd
, hdr
)
2451 Elf32_Internal_Shdr
*hdr
;
2453 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2457 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2458 BFD_ASSERT (hdr
->contents
== NULL
);
2461 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2464 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2465 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2469 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2470 && hdr
->bfd_section
!= NULL
2471 && elf_section_data (hdr
->bfd_section
) != NULL
2472 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2474 bfd_byte
*contents
, *l
, *lend
;
2476 /* We stored the section contents in the elf_section_data tdata
2477 field in the set_section_contents routine. We save the
2478 section contents so that we don't have to read them again.
2479 At this point we know that elf_gp is set, so we can look
2480 through the section contents to see if there is an
2481 ODK_REGINFO structure. */
2483 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2485 lend
= contents
+ hdr
->sh_size
;
2486 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2488 Elf_Internal_Options intopt
;
2490 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2492 if (intopt
.kind
== ODK_REGINFO
)
2499 + sizeof (Elf_External_Options
)
2500 + (sizeof (Elf32_External_RegInfo
) - 4)),
2503 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
2504 if (bfd_write (buf
, 1, 4, abfd
) != 4)
2511 return _bfd_mips_elf_section_processing (abfd
, hdr
);
2514 /* MIPS ELF uses two common sections. One is the usual one, and the
2515 other is for small objects. All the small objects are kept
2516 together, and then referenced via the gp pointer, which yields
2517 faster assembler code. This is what we use for the small common
2518 section. This approach is copied from ecoff.c. */
2519 static asection mips_elf_scom_section
;
2520 static asymbol mips_elf_scom_symbol
;
2521 static asymbol
*mips_elf_scom_symbol_ptr
;
2523 /* MIPS ELF also uses an acommon section, which represents an
2524 allocated common symbol which may be overridden by a
2525 definition in a shared library. */
2526 static asection mips_elf_acom_section
;
2527 static asymbol mips_elf_acom_symbol
;
2528 static asymbol
*mips_elf_acom_symbol_ptr
;
2530 /* The Irix 5 support uses two virtual sections, which represent
2531 text/data symbols defined in dynamic objects. */
2532 static asection mips_elf_text_section
;
2533 static asection
*mips_elf_text_section_ptr
;
2534 static asymbol mips_elf_text_symbol
;
2535 static asymbol
*mips_elf_text_symbol_ptr
;
2537 static asection mips_elf_data_section
;
2538 static asection
*mips_elf_data_section_ptr
;
2539 static asymbol mips_elf_data_symbol
;
2540 static asymbol
*mips_elf_data_symbol_ptr
;
2542 /* Handle the special MIPS section numbers that a symbol may use.
2543 This is used for both the 32-bit and the 64-bit ABI. */
2546 _bfd_mips_elf_symbol_processing (abfd
, asym
)
2550 elf_symbol_type
*elfsym
;
2552 elfsym
= (elf_symbol_type
*) asym
;
2553 switch (elfsym
->internal_elf_sym
.st_shndx
)
2555 case SHN_MIPS_ACOMMON
:
2556 /* This section is used in a dynamically linked executable file.
2557 It is an allocated common section. The dynamic linker can
2558 either resolve these symbols to something in a shared
2559 library, or it can just leave them here. For our purposes,
2560 we can consider these symbols to be in a new section. */
2561 if (mips_elf_acom_section
.name
== NULL
)
2563 /* Initialize the acommon section. */
2564 mips_elf_acom_section
.name
= ".acommon";
2565 mips_elf_acom_section
.flags
= SEC_ALLOC
;
2566 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
2567 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
2568 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
2569 mips_elf_acom_symbol
.name
= ".acommon";
2570 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
2571 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
2572 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
2574 asym
->section
= &mips_elf_acom_section
;
2578 /* Common symbols less than the GP size are automatically
2579 treated as SHN_MIPS_SCOMMON symbols. */
2580 if (asym
->value
> elf_gp_size (abfd
))
2583 case SHN_MIPS_SCOMMON
:
2584 if (mips_elf_scom_section
.name
== NULL
)
2586 /* Initialize the small common section. */
2587 mips_elf_scom_section
.name
= ".scommon";
2588 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
2589 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
2590 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
2591 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
2592 mips_elf_scom_symbol
.name
= ".scommon";
2593 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2594 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
2595 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
2597 asym
->section
= &mips_elf_scom_section
;
2598 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2601 case SHN_MIPS_SUNDEFINED
:
2602 asym
->section
= bfd_und_section_ptr
;
2605 #if 0 /* for SGI_COMPAT */
2607 asym
->section
= mips_elf_text_section_ptr
;
2611 asym
->section
= mips_elf_data_section_ptr
;
2617 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
2621 mips_elf_additional_program_headers (abfd
)
2629 if (! SGI_COMPAT (abfd
))
2632 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2633 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2635 /* We need a PT_MIPS_REGINFO segment. */
2639 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2640 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2642 /* We need a PT_MIPS_RTPROC segment. */
2649 /* Modify the segment map for an Irix 5 executable. */
2652 mips_elf_modify_segment_map (abfd
)
2656 struct elf_segment_map
*m
, **pm
;
2658 if (! SGI_COMPAT (abfd
))
2661 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
2663 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2664 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2666 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2667 if (m
->p_type
== PT_MIPS_REGINFO
)
2671 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2675 m
->p_type
= PT_MIPS_REGINFO
;
2679 /* We want to put it after the PHDR and INTERP segments. */
2680 pm
= &elf_tdata (abfd
)->segment_map
;
2682 && ((*pm
)->p_type
== PT_PHDR
2683 || (*pm
)->p_type
== PT_INTERP
))
2691 /* If there are .dynamic and .mdebug sections, we make a room for
2692 the RTPROC header. FIXME: Rewrite without section names. */
2693 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
2694 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2695 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2697 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2698 if (m
->p_type
== PT_MIPS_RTPROC
)
2702 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2706 m
->p_type
= PT_MIPS_RTPROC
;
2708 s
= bfd_get_section_by_name (abfd
, ".rtproc");
2713 m
->p_flags_valid
= 1;
2721 /* We want to put it after the DYNAMIC segment. */
2722 pm
= &elf_tdata (abfd
)->segment_map
;
2723 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
2733 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
2734 .dynsym, and .hash sections, and everything in between. */
2735 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
2736 if ((*pm
)->p_type
== PT_DYNAMIC
)
2741 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
2743 static const char *sec_names
[] =
2744 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
2747 struct elf_segment_map
*n
;
2751 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
2753 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
2754 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2760 sz
= s
->_cooked_size
;
2763 if (high
< s
->vma
+ sz
)
2769 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2770 if ((s
->flags
& SEC_LOAD
) != 0
2773 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2777 n
= ((struct elf_segment_map
*)
2778 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
2785 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2787 if ((s
->flags
& SEC_LOAD
) != 0
2790 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2804 /* The structure of the runtime procedure descriptor created by the
2805 loader for use by the static exception system. */
2807 typedef struct runtime_pdr
{
2808 bfd_vma adr
; /* memory address of start of procedure */
2809 long regmask
; /* save register mask */
2810 long regoffset
; /* save register offset */
2811 long fregmask
; /* save floating point register mask */
2812 long fregoffset
; /* save floating point register offset */
2813 long frameoffset
; /* frame size */
2814 short framereg
; /* frame pointer register */
2815 short pcreg
; /* offset or reg of return pc */
2816 long irpss
; /* index into the runtime string table */
2818 struct exception_info
*exception_info
;/* pointer to exception array */
2820 #define cbRPDR sizeof(RPDR)
2821 #define rpdNil ((pRPDR) 0)
2823 /* Swap RPDR (runtime procedure table entry) for output. */
2825 static void ecoff_swap_rpdr_out
2826 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
2829 ecoff_swap_rpdr_out (abfd
, in
, ex
)
2832 struct rpdr_ext
*ex
;
2834 /* ecoff_put_off was defined in ecoffswap.h. */
2835 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
2836 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
2837 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
2838 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
2839 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
2840 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
2842 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
2843 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
2845 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
2847 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
2851 /* Read ECOFF debugging information from a .mdebug section into a
2852 ecoff_debug_info structure. */
2855 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
2858 struct ecoff_debug_info
*debug
;
2861 const struct ecoff_debug_swap
*swap
;
2862 char *ext_hdr
= NULL
;
2864 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2866 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
2867 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
2870 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
2871 swap
->external_hdr_size
)
2875 symhdr
= &debug
->symbolic_header
;
2876 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
2878 /* The symbolic header contains absolute file offsets and sizes to
2880 #define READ(ptr, offset, count, size, type) \
2881 if (symhdr->count == 0) \
2882 debug->ptr = NULL; \
2885 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
2886 if (debug->ptr == NULL) \
2887 goto error_return; \
2888 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
2889 || (bfd_read (debug->ptr, size, symhdr->count, \
2890 abfd) != size * symhdr->count)) \
2891 goto error_return; \
2894 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
2895 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
2896 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
2897 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
2898 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
2899 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
2901 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
2902 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
2903 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
2904 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
2905 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
2909 debug
->adjust
= NULL
;
2914 if (ext_hdr
!= NULL
)
2916 if (debug
->line
!= NULL
)
2918 if (debug
->external_dnr
!= NULL
)
2919 free (debug
->external_dnr
);
2920 if (debug
->external_pdr
!= NULL
)
2921 free (debug
->external_pdr
);
2922 if (debug
->external_sym
!= NULL
)
2923 free (debug
->external_sym
);
2924 if (debug
->external_opt
!= NULL
)
2925 free (debug
->external_opt
);
2926 if (debug
->external_aux
!= NULL
)
2927 free (debug
->external_aux
);
2928 if (debug
->ss
!= NULL
)
2930 if (debug
->ssext
!= NULL
)
2931 free (debug
->ssext
);
2932 if (debug
->external_fdr
!= NULL
)
2933 free (debug
->external_fdr
);
2934 if (debug
->external_rfd
!= NULL
)
2935 free (debug
->external_rfd
);
2936 if (debug
->external_ext
!= NULL
)
2937 free (debug
->external_ext
);
2941 /* MIPS ELF local labels start with '$', not 'L'. */
2945 mips_elf_is_local_label (abfd
, symbol
)
2949 return symbol
->name
[0] == '$';
2952 /* MIPS ELF uses a special find_nearest_line routine in order the
2953 handle the ECOFF debugging information. */
2955 struct mips_elf_find_line
2957 struct ecoff_debug_info d
;
2958 struct ecoff_find_line i
;
2962 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
2963 functionname_ptr
, line_ptr
)
2968 const char **filename_ptr
;
2969 const char **functionname_ptr
;
2970 unsigned int *line_ptr
;
2974 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
2978 struct mips_elf_find_line
*fi
;
2979 const struct ecoff_debug_swap
* const swap
=
2980 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2982 /* If we are called during a link, mips_elf_final_link may have
2983 cleared the SEC_HAS_CONTENTS field. We force it back on here
2984 if appropriate (which it normally will be). */
2985 origflags
= msec
->flags
;
2986 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
2987 msec
->flags
|= SEC_HAS_CONTENTS
;
2989 fi
= elf_tdata (abfd
)->find_line_info
;
2992 bfd_size_type external_fdr_size
;
2995 struct fdr
*fdr_ptr
;
2997 fi
= ((struct mips_elf_find_line
*)
2998 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
3001 msec
->flags
= origflags
;
3005 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
3007 msec
->flags
= origflags
;
3011 /* Swap in the FDR information. */
3012 fi
->d
.fdr
= ((struct fdr
*)
3014 (fi
->d
.symbolic_header
.ifdMax
*
3015 sizeof (struct fdr
))));
3016 if (fi
->d
.fdr
== NULL
)
3018 msec
->flags
= origflags
;
3021 external_fdr_size
= swap
->external_fdr_size
;
3022 fdr_ptr
= fi
->d
.fdr
;
3023 fraw_src
= (char *) fi
->d
.external_fdr
;
3024 fraw_end
= (fraw_src
3025 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
3026 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
3027 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
3029 elf_tdata (abfd
)->find_line_info
= fi
;
3031 /* Note that we don't bother to ever free this information.
3032 find_nearest_line is either called all the time, as in
3033 objdump -l, so the information should be saved, or it is
3034 rarely called, as in ld error messages, so the memory
3035 wasted is unimportant. Still, it would probably be a
3036 good idea for free_cached_info to throw it away. */
3039 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
3040 &fi
->i
, filename_ptr
, functionname_ptr
,
3043 msec
->flags
= origflags
;
3047 msec
->flags
= origflags
;
3050 /* Fall back on the generic ELF find_nearest_line routine. */
3052 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
3053 filename_ptr
, functionname_ptr
,
3057 /* The mips16 compiler uses a couple of special sections to handle
3058 floating point arguments.
3060 Section names that look like .mips16.fn.FNNAME contain stubs that
3061 copy floating point arguments from the fp regs to the gp regs and
3062 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3063 call should be redirected to the stub instead. If no 32 bit
3064 function calls FNNAME, the stub should be discarded. We need to
3065 consider any reference to the function, not just a call, because
3066 if the address of the function is taken we will need the stub,
3067 since the address might be passed to a 32 bit function.
3069 Section names that look like .mips16.call.FNNAME contain stubs
3070 that copy floating point arguments from the gp regs to the fp
3071 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3072 then any 16 bit function that calls FNNAME should be redirected
3073 to the stub instead. If FNNAME is not a 32 bit function, the
3074 stub should be discarded.
3076 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3077 which call FNNAME and then copy the return value from the fp regs
3078 to the gp regs. These stubs store the return value in $18 while
3079 calling FNNAME; any function which might call one of these stubs
3080 must arrange to save $18 around the call. (This case is not
3081 needed for 32 bit functions that call 16 bit functions, because
3082 16 bit functions always return floating point values in both
3085 Note that in all cases FNNAME might be defined statically.
3086 Therefore, FNNAME is not used literally. Instead, the relocation
3087 information will indicate which symbol the section is for.
3089 We record any stubs that we find in the symbol table. */
3091 #define FN_STUB ".mips16.fn."
3092 #define CALL_STUB ".mips16.call."
3093 #define CALL_FP_STUB ".mips16.call.fp."
3095 /* The MIPS ELF linker needs additional information for each symbol in
3096 the global hash table. */
3098 struct mips_elf_link_hash_entry
3100 struct elf_link_hash_entry root
;
3102 /* External symbol information. */
3105 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
3106 unsigned int mips_32_relocs
;
3108 /* If there is a stub that 32 bit functions should use to call this
3109 16 bit function, this points to the section containing the stub. */
3112 /* Whether we need the fn_stub; this is set if this symbol appears
3113 in any relocs other than a 16 bit call. */
3114 boolean need_fn_stub
;
3116 /* If there is a stub that 16 bit functions should use to call this
3117 32 bit function, this points to the section containing the stub. */
3118 asection
*call_stub
;
3120 /* This is like the call_stub field, but it is used if the function
3121 being called returns a floating point value. */
3122 asection
*call_fp_stub
;
3125 /* MIPS ELF linker hash table. */
3127 struct mips_elf_link_hash_table
3129 struct elf_link_hash_table root
;
3130 /* String section indices for the dynamic section symbols. */
3131 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
3132 /* The number of .rtproc entries. */
3133 bfd_size_type procedure_count
;
3134 /* The size of the .compact_rel section (if SGI_COMPAT). */
3135 bfd_size_type compact_rel_size
;
3136 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3137 entry is set to the address of __rld_obj_head as in Irix 5. */
3138 boolean use_rld_obj_head
;
3139 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3141 /* This is set if we see any mips16 stub sections. */
3142 boolean mips16_stubs_seen
;
3145 /* Look up an entry in a MIPS ELF linker hash table. */
3147 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3148 ((struct mips_elf_link_hash_entry *) \
3149 elf_link_hash_lookup (&(table)->root, (string), (create), \
3152 /* Traverse a MIPS ELF linker hash table. */
3154 #define mips_elf_link_hash_traverse(table, func, info) \
3155 (elf_link_hash_traverse \
3157 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3160 /* Get the MIPS ELF linker hash table from a link_info structure. */
3162 #define mips_elf_hash_table(p) \
3163 ((struct mips_elf_link_hash_table *) ((p)->hash))
3165 static boolean mips_elf_output_extsym
3166 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3168 /* Create an entry in a MIPS ELF linker hash table. */
3170 static struct bfd_hash_entry
*
3171 mips_elf_link_hash_newfunc (entry
, table
, string
)
3172 struct bfd_hash_entry
*entry
;
3173 struct bfd_hash_table
*table
;
3176 struct mips_elf_link_hash_entry
*ret
=
3177 (struct mips_elf_link_hash_entry
*) entry
;
3179 /* Allocate the structure if it has not already been allocated by a
3181 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3182 ret
= ((struct mips_elf_link_hash_entry
*)
3183 bfd_hash_allocate (table
,
3184 sizeof (struct mips_elf_link_hash_entry
)));
3185 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3186 return (struct bfd_hash_entry
*) ret
;
3188 /* Call the allocation method of the superclass. */
3189 ret
= ((struct mips_elf_link_hash_entry
*)
3190 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3192 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3194 /* Set local fields. */
3195 memset (&ret
->esym
, 0, sizeof (EXTR
));
3196 /* We use -2 as a marker to indicate that the information has
3197 not been set. -1 means there is no associated ifd. */
3199 ret
->mips_32_relocs
= 0;
3200 ret
->fn_stub
= NULL
;
3201 ret
->need_fn_stub
= false;
3202 ret
->call_stub
= NULL
;
3203 ret
->call_fp_stub
= NULL
;
3206 return (struct bfd_hash_entry
*) ret
;
3209 /* Create a MIPS ELF linker hash table. */
3211 static struct bfd_link_hash_table
*
3212 mips_elf_link_hash_table_create (abfd
)
3215 struct mips_elf_link_hash_table
*ret
;
3218 ret
= ((struct mips_elf_link_hash_table
*)
3219 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
3220 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
3223 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3224 mips_elf_link_hash_newfunc
))
3226 bfd_release (abfd
, ret
);
3230 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
3231 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
3232 ret
->procedure_count
= 0;
3233 ret
->compact_rel_size
= 0;
3234 ret
->use_rld_obj_head
= false;
3236 ret
->mips16_stubs_seen
= false;
3238 return &ret
->root
.root
;
3241 /* Hook called by the linker routine which adds symbols from an object
3242 file. We must handle the special MIPS section numbers here. */
3246 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3248 struct bfd_link_info
*info
;
3249 const Elf_Internal_Sym
*sym
;
3255 if (SGI_COMPAT (abfd
)
3256 && (abfd
->flags
& DYNAMIC
) != 0
3257 && strcmp (*namep
, "_rld_new_interface") == 0)
3259 /* Skip Irix 5 rld entry name. */
3264 switch (sym
->st_shndx
)
3267 /* Common symbols less than the GP size are automatically
3268 treated as SHN_MIPS_SCOMMON symbols. */
3269 if (sym
->st_size
> elf_gp_size (abfd
))
3272 case SHN_MIPS_SCOMMON
:
3273 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3274 (*secp
)->flags
|= SEC_IS_COMMON
;
3275 *valp
= sym
->st_size
;
3279 /* This section is used in a shared object. */
3280 if (mips_elf_text_section_ptr
== NULL
)
3282 /* Initialize the section. */
3283 mips_elf_text_section
.name
= ".text";
3284 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
3285 mips_elf_text_section
.output_section
= NULL
;
3286 mips_elf_text_section
.owner
= abfd
;
3287 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
3288 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
3289 mips_elf_text_symbol
.name
= ".text";
3290 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
3291 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
3292 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
3293 mips_elf_text_section_ptr
= &mips_elf_text_section
;
3296 *secp
= bfd_und_section_ptr
;
3298 *secp
= mips_elf_text_section_ptr
;
3301 case SHN_MIPS_ACOMMON
:
3302 /* Fall through. XXX Can we treat this as allocated data? */
3304 /* This section is used in a shared object. */
3305 if (mips_elf_data_section_ptr
== NULL
)
3307 /* Initialize the section. */
3308 mips_elf_data_section
.name
= ".data";
3309 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
3310 mips_elf_data_section
.output_section
= NULL
;
3311 mips_elf_data_section
.owner
= abfd
;
3312 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
3313 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
3314 mips_elf_data_symbol
.name
= ".data";
3315 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
3316 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
3317 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
3318 mips_elf_data_section_ptr
= &mips_elf_data_section
;
3321 *secp
= bfd_und_section_ptr
;
3323 *secp
= mips_elf_data_section_ptr
;
3326 case SHN_MIPS_SUNDEFINED
:
3327 *secp
= bfd_und_section_ptr
;
3331 if (SGI_COMPAT (abfd
)
3333 && info
->hash
->creator
== abfd
->xvec
3334 && strcmp (*namep
, "__rld_obj_head") == 0)
3336 struct elf_link_hash_entry
*h
;
3338 /* Mark __rld_obj_head as dynamic. */
3340 if (! (_bfd_generic_link_add_one_symbol
3341 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3342 (bfd_vma
) *valp
, (const char *) NULL
, false,
3343 get_elf_backend_data (abfd
)->collect
,
3344 (struct bfd_link_hash_entry
**) &h
)))
3346 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
3347 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3348 h
->type
= STT_OBJECT
;
3350 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3353 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3356 /* If this is a mips16 text symbol, add 1 to the value to make it
3357 odd. This will cause something like .word SYM to come up with
3358 the right value when it is loaded into the PC. */
3359 if (sym
->st_other
== STO_MIPS16
)
3365 /* Structure used to pass information to mips_elf_output_extsym. */
3370 struct bfd_link_info
*info
;
3371 struct ecoff_debug_info
*debug
;
3372 const struct ecoff_debug_swap
*swap
;
3376 /* This routine is used to write out ECOFF debugging external symbol
3377 information. It is called via mips_elf_link_hash_traverse. The
3378 ECOFF external symbol information must match the ELF external
3379 symbol information. Unfortunately, at this point we don't know
3380 whether a symbol is required by reloc information, so the two
3381 tables may wind up being different. We must sort out the external
3382 symbol information before we can set the final size of the .mdebug
3383 section, and we must set the size of the .mdebug section before we
3384 can relocate any sections, and we can't know which symbols are
3385 required by relocation until we relocate the sections.
3386 Fortunately, it is relatively unlikely that any symbol will be
3387 stripped but required by a reloc. In particular, it can not happen
3388 when generating a final executable. */
3391 mips_elf_output_extsym (h
, data
)
3392 struct mips_elf_link_hash_entry
*h
;
3395 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
3397 asection
*sec
, *output_section
;
3399 if (h
->root
.indx
== -2)
3401 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3402 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
3403 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3404 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
3406 else if (einfo
->info
->strip
== strip_all
3407 || (einfo
->info
->strip
== strip_some
3408 && bfd_hash_lookup (einfo
->info
->keep_hash
,
3409 h
->root
.root
.root
.string
,
3410 false, false) == NULL
))
3418 if (h
->esym
.ifd
== -2)
3421 h
->esym
.cobol_main
= 0;
3422 h
->esym
.weakext
= 0;
3423 h
->esym
.reserved
= 0;
3424 h
->esym
.ifd
= ifdNil
;
3425 h
->esym
.asym
.value
= 0;
3426 h
->esym
.asym
.st
= stGlobal
;
3428 if (SGI_COMPAT (einfo
->abfd
)
3429 && (h
->root
.root
.type
== bfd_link_hash_undefined
3430 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
3434 /* Use undefined class. Also, set class and type for some
3436 name
= h
->root
.root
.root
.string
;
3437 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
3438 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
3440 h
->esym
.asym
.sc
= scData
;
3441 h
->esym
.asym
.st
= stLabel
;
3442 h
->esym
.asym
.value
= 0;
3444 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
3446 h
->esym
.asym
.sc
= scAbs
;
3447 h
->esym
.asym
.st
= stLabel
;
3448 h
->esym
.asym
.value
=
3449 mips_elf_hash_table (einfo
->info
)->procedure_count
;
3451 else if (strcmp (name
, "_gp_disp") == 0)
3453 h
->esym
.asym
.sc
= scAbs
;
3454 h
->esym
.asym
.st
= stLabel
;
3455 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
3458 h
->esym
.asym
.sc
= scUndefined
;
3460 else if (h
->root
.root
.type
!= bfd_link_hash_defined
3461 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
3462 h
->esym
.asym
.sc
= scAbs
;
3467 sec
= h
->root
.root
.u
.def
.section
;
3468 output_section
= sec
->output_section
;
3470 /* When making a shared library and symbol h is the one from
3471 the another shared library, OUTPUT_SECTION may be null. */
3472 if (output_section
== NULL
)
3473 h
->esym
.asym
.sc
= scUndefined
;
3476 name
= bfd_section_name (output_section
->owner
, output_section
);
3478 if (strcmp (name
, ".text") == 0)
3479 h
->esym
.asym
.sc
= scText
;
3480 else if (strcmp (name
, ".data") == 0)
3481 h
->esym
.asym
.sc
= scData
;
3482 else if (strcmp (name
, ".sdata") == 0)
3483 h
->esym
.asym
.sc
= scSData
;
3484 else if (strcmp (name
, ".rodata") == 0
3485 || strcmp (name
, ".rdata") == 0)
3486 h
->esym
.asym
.sc
= scRData
;
3487 else if (strcmp (name
, ".bss") == 0)
3488 h
->esym
.asym
.sc
= scBss
;
3489 else if (strcmp (name
, ".sbss") == 0)
3490 h
->esym
.asym
.sc
= scSBss
;
3491 else if (strcmp (name
, ".init") == 0)
3492 h
->esym
.asym
.sc
= scInit
;
3493 else if (strcmp (name
, ".fini") == 0)
3494 h
->esym
.asym
.sc
= scFini
;
3496 h
->esym
.asym
.sc
= scAbs
;
3500 h
->esym
.asym
.reserved
= 0;
3501 h
->esym
.asym
.index
= indexNil
;
3504 if (h
->root
.root
.type
== bfd_link_hash_common
)
3505 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
3506 else if (h
->root
.root
.type
== bfd_link_hash_defined
3507 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3509 if (h
->esym
.asym
.sc
== scCommon
)
3510 h
->esym
.asym
.sc
= scBss
;
3511 else if (h
->esym
.asym
.sc
== scSCommon
)
3512 h
->esym
.asym
.sc
= scSBss
;
3514 sec
= h
->root
.root
.u
.def
.section
;
3515 output_section
= sec
->output_section
;
3516 if (output_section
!= NULL
)
3517 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
3518 + sec
->output_offset
3519 + output_section
->vma
);
3521 h
->esym
.asym
.value
= 0;
3523 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3525 /* Set type and value for a symbol with a function stub. */
3526 h
->esym
.asym
.st
= stProc
;
3527 sec
= h
->root
.root
.u
.def
.section
;
3529 h
->esym
.asym
.value
= 0;
3532 output_section
= sec
->output_section
;
3533 if (output_section
!= NULL
)
3534 h
->esym
.asym
.value
= (h
->root
.plt_offset
3535 + sec
->output_offset
3536 + output_section
->vma
);
3538 h
->esym
.asym
.value
= 0;
3545 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
3546 h
->root
.root
.root
.string
,
3549 einfo
->failed
= true;
3556 /* Create a runtime procedure table from the .mdebug section. */
3559 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
3562 struct bfd_link_info
*info
;
3564 struct ecoff_debug_info
*debug
;
3566 const struct ecoff_debug_swap
*swap
;
3567 HDRR
*hdr
= &debug
->symbolic_header
;
3569 struct rpdr_ext
*erp
;
3571 struct pdr_ext
*epdr
;
3572 struct sym_ext
*esym
;
3575 unsigned long size
, count
;
3576 unsigned long sindex
;
3580 const char *no_name_func
= "static procedure (no name)";
3588 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3590 sindex
= strlen (no_name_func
) + 1;
3591 count
= hdr
->ipdMax
;
3594 size
= swap
->external_pdr_size
;
3596 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
3600 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
3603 size
= sizeof (RPDR
);
3604 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
3608 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
3612 count
= hdr
->isymMax
;
3613 size
= swap
->external_sym_size
;
3614 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
3618 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
3621 count
= hdr
->issMax
;
3622 ss
= (char *) bfd_malloc (count
);
3625 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
3628 count
= hdr
->ipdMax
;
3629 for (i
= 0; i
< count
; i
++, rp
++)
3631 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
3632 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
3633 rp
->adr
= sym
.value
;
3634 rp
->regmask
= pdr
.regmask
;
3635 rp
->regoffset
= pdr
.regoffset
;
3636 rp
->fregmask
= pdr
.fregmask
;
3637 rp
->fregoffset
= pdr
.fregoffset
;
3638 rp
->frameoffset
= pdr
.frameoffset
;
3639 rp
->framereg
= pdr
.framereg
;
3640 rp
->pcreg
= pdr
.pcreg
;
3642 sv
[i
] = ss
+ sym
.iss
;
3643 sindex
+= strlen (sv
[i
]) + 1;
3647 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
3648 size
= BFD_ALIGN (size
, 16);
3649 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
3652 mips_elf_hash_table (info
)->procedure_count
= 0;
3656 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
3658 erp
= (struct rpdr_ext
*) rtproc
;
3659 memset (erp
, 0, sizeof (struct rpdr_ext
));
3661 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
3662 strcpy (str
, no_name_func
);
3663 str
+= strlen (no_name_func
) + 1;
3664 for (i
= 0; i
< count
; i
++)
3666 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
3667 strcpy (str
, sv
[i
]);
3668 str
+= strlen (sv
[i
]) + 1;
3670 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
3672 /* Set the size and contents of .rtproc section. */
3673 s
->_raw_size
= size
;
3674 s
->contents
= rtproc
;
3676 /* Skip this section later on (I don't think this currently
3677 matters, but someday it might). */
3678 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
3707 /* A comparison routine used to sort .gptab entries. */
3710 gptab_compare (p1
, p2
)
3714 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
3715 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
3717 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
3720 /* We need to use a special link routine to handle the .reginfo and
3721 the .mdebug sections. We need to merge all instances of these
3722 sections together, not write them all out sequentially. */
3725 mips_elf_final_link (abfd
, info
)
3727 struct bfd_link_info
*info
;
3731 struct bfd_link_order
*p
;
3732 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
3733 asection
*rtproc_sec
;
3734 Elf32_RegInfo reginfo
;
3735 struct ecoff_debug_info debug
;
3736 const struct ecoff_debug_swap
*swap
3737 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3738 HDRR
*symhdr
= &debug
.symbolic_header
;
3739 PTR mdebug_handle
= NULL
;
3741 /* Drop the .options section, since it has special semantics which I
3742 haven't bothered to figure out. */
3743 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
3745 if (strcmp ((*secpp
)->name
, ".options") == 0)
3747 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
3748 if (p
->type
== bfd_indirect_link_order
)
3749 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
3750 (*secpp
)->link_order_head
= NULL
;
3751 *secpp
= (*secpp
)->next
;
3752 --abfd
->section_count
;
3757 /* Get a value for the GP register. */
3758 if (elf_gp (abfd
) == 0)
3760 struct bfd_link_hash_entry
*h
;
3762 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
3763 if (h
!= (struct bfd_link_hash_entry
*) NULL
3764 && h
->type
== bfd_link_hash_defined
)
3765 elf_gp (abfd
) = (h
->u
.def
.value
3766 + h
->u
.def
.section
->output_section
->vma
3767 + h
->u
.def
.section
->output_offset
);
3768 else if (info
->relocateable
)
3772 /* Make up a value. */
3774 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3777 && (strcmp (o
->name
, ".sbss") == 0
3778 || strcmp (o
->name
, ".sdata") == 0
3779 || strcmp (o
->name
, ".lit4") == 0
3780 || strcmp (o
->name
, ".lit8") == 0))
3783 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
3787 /* If the relocate_section function needs to do a reloc
3788 involving the GP value, it should make a reloc_dangerous
3789 callback to warn that GP is not defined. */
3793 /* Go through the sections and collect the .reginfo and .mdebug
3797 gptab_data_sec
= NULL
;
3798 gptab_bss_sec
= NULL
;
3799 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3801 if (strcmp (o
->name
, ".reginfo") == 0)
3803 memset (®info
, 0, sizeof reginfo
);
3805 /* We have found the .reginfo section in the output file.
3806 Look through all the link_orders comprising it and merge
3807 the information together. */
3808 for (p
= o
->link_order_head
;
3809 p
!= (struct bfd_link_order
*) NULL
;
3812 asection
*input_section
;
3814 Elf32_External_RegInfo ext
;
3817 if (p
->type
!= bfd_indirect_link_order
)
3819 if (p
->type
== bfd_fill_link_order
)
3824 input_section
= p
->u
.indirect
.section
;
3825 input_bfd
= input_section
->owner
;
3827 /* The linker emulation code has probably clobbered the
3828 size to be zero bytes. */
3829 if (input_section
->_raw_size
== 0)
3830 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3832 if (! bfd_get_section_contents (input_bfd
, input_section
,
3838 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
3840 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
3841 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
3842 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
3843 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
3844 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
3846 /* ri_gp_value is set by the function
3847 mips_elf32_section_processing when the section is
3848 finally written out. */
3850 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3851 elf_link_input_bfd ignores this section. */
3852 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3855 /* Force the section size to the value we want. */
3856 o
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3858 /* Skip this section later on (I don't think this currently
3859 matters, but someday it might). */
3860 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3865 if (strcmp (o
->name
, ".mdebug") == 0)
3867 struct extsym_info einfo
;
3869 /* We have found the .mdebug section in the output file.
3870 Look through all the link_orders comprising it and merge
3871 the information together. */
3872 symhdr
->magic
= swap
->sym_magic
;
3873 /* FIXME: What should the version stamp be? */
3875 symhdr
->ilineMax
= 0;
3879 symhdr
->isymMax
= 0;
3880 symhdr
->ioptMax
= 0;
3881 symhdr
->iauxMax
= 0;
3883 symhdr
->issExtMax
= 0;
3886 symhdr
->iextMax
= 0;
3888 /* We accumulate the debugging information itself in the
3889 debug_info structure. */
3891 debug
.external_dnr
= NULL
;
3892 debug
.external_pdr
= NULL
;
3893 debug
.external_sym
= NULL
;
3894 debug
.external_opt
= NULL
;
3895 debug
.external_aux
= NULL
;
3897 debug
.ssext
= debug
.ssext_end
= NULL
;
3898 debug
.external_fdr
= NULL
;
3899 debug
.external_rfd
= NULL
;
3900 debug
.external_ext
= debug
.external_ext_end
= NULL
;
3902 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
3903 if (mdebug_handle
== (PTR
) NULL
)
3906 if (SGI_COMPAT (abfd
))
3912 static const char * const name
[] =
3913 { ".text", ".init", ".fini", ".data",
3914 ".rodata", ".sdata", ".sbss", ".bss" };
3915 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
3916 scRData
, scSData
, scSBss
, scBss
};
3919 esym
.cobol_main
= 0;
3923 esym
.asym
.iss
= issNil
;
3924 esym
.asym
.st
= stLocal
;
3925 esym
.asym
.reserved
= 0;
3926 esym
.asym
.index
= indexNil
;
3927 for (i
= 0; i
< 8; i
++)
3929 esym
.asym
.sc
= sc
[i
];
3930 s
= bfd_get_section_by_name (abfd
, name
[i
]);
3933 esym
.asym
.value
= s
->vma
;
3934 last
= s
->vma
+ s
->_raw_size
;
3937 esym
.asym
.value
= last
;
3939 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
3945 for (p
= o
->link_order_head
;
3946 p
!= (struct bfd_link_order
*) NULL
;
3949 asection
*input_section
;
3951 const struct ecoff_debug_swap
*input_swap
;
3952 struct ecoff_debug_info input_debug
;
3956 if (p
->type
!= bfd_indirect_link_order
)
3958 if (p
->type
== bfd_fill_link_order
)
3963 input_section
= p
->u
.indirect
.section
;
3964 input_bfd
= input_section
->owner
;
3966 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
3967 || (get_elf_backend_data (input_bfd
)
3968 ->elf_backend_ecoff_debug_swap
) == NULL
)
3970 /* I don't know what a non MIPS ELF bfd would be
3971 doing with a .mdebug section, but I don't really
3972 want to deal with it. */
3976 input_swap
= (get_elf_backend_data (input_bfd
)
3977 ->elf_backend_ecoff_debug_swap
);
3979 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
3981 /* The ECOFF linking code expects that we have already
3982 read in the debugging information and set up an
3983 ecoff_debug_info structure, so we do that now. */
3984 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
3988 if (! (bfd_ecoff_debug_accumulate
3989 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
3990 &input_debug
, input_swap
, info
)))
3993 /* Loop through the external symbols. For each one with
3994 interesting information, try to find the symbol in
3995 the linker global hash table and save the information
3996 for the output external symbols. */
3997 eraw_src
= input_debug
.external_ext
;
3998 eraw_end
= (eraw_src
3999 + (input_debug
.symbolic_header
.iextMax
4000 * input_swap
->external_ext_size
));
4002 eraw_src
< eraw_end
;
4003 eraw_src
+= input_swap
->external_ext_size
)
4007 struct mips_elf_link_hash_entry
*h
;
4009 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4010 if (ext
.asym
.sc
== scNil
4011 || ext
.asym
.sc
== scUndefined
4012 || ext
.asym
.sc
== scSUndefined
)
4015 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4016 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
4017 name
, false, false, true);
4018 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4024 < input_debug
.symbolic_header
.ifdMax
);
4025 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4031 /* Free up the information we just read. */
4032 free (input_debug
.line
);
4033 free (input_debug
.external_dnr
);
4034 free (input_debug
.external_pdr
);
4035 free (input_debug
.external_sym
);
4036 free (input_debug
.external_opt
);
4037 free (input_debug
.external_aux
);
4038 free (input_debug
.ss
);
4039 free (input_debug
.ssext
);
4040 free (input_debug
.external_fdr
);
4041 free (input_debug
.external_rfd
);
4042 free (input_debug
.external_ext
);
4044 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4045 elf_link_input_bfd ignores this section. */
4046 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4049 if (SGI_COMPAT (abfd
) && info
->shared
)
4051 /* Create .rtproc section. */
4052 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4053 if (rtproc_sec
== NULL
)
4055 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4056 | SEC_LINKER_CREATED
| SEC_READONLY
);
4058 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4059 if (rtproc_sec
== NULL
4060 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4061 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 12))
4065 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
4066 info
, rtproc_sec
, &debug
))
4070 /* Build the external symbol information. */
4073 einfo
.debug
= &debug
;
4075 einfo
.failed
= false;
4076 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4077 mips_elf_output_extsym
,
4082 /* Set the size of the .mdebug section. */
4083 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4085 /* Skip this section later on (I don't think this currently
4086 matters, but someday it might). */
4087 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4092 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4094 const char *subname
;
4097 Elf32_External_gptab
*ext_tab
;
4100 /* The .gptab.sdata and .gptab.sbss sections hold
4101 information describing how the small data area would
4102 change depending upon the -G switch. These sections
4103 not used in executables files. */
4104 if (! info
->relocateable
)
4108 for (p
= o
->link_order_head
;
4109 p
!= (struct bfd_link_order
*) NULL
;
4112 asection
*input_section
;
4114 if (p
->type
!= bfd_indirect_link_order
)
4116 if (p
->type
== bfd_fill_link_order
)
4121 input_section
= p
->u
.indirect
.section
;
4123 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4124 elf_link_input_bfd ignores this section. */
4125 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4128 /* Skip this section later on (I don't think this
4129 currently matters, but someday it might). */
4130 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4132 /* Really remove the section. */
4133 for (secpp
= &abfd
->sections
;
4135 secpp
= &(*secpp
)->next
)
4137 *secpp
= (*secpp
)->next
;
4138 --abfd
->section_count
;
4143 /* There is one gptab for initialized data, and one for
4144 uninitialized data. */
4145 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4147 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4151 (*_bfd_error_handler
)
4152 ("%s: illegal section name `%s'",
4153 bfd_get_filename (abfd
), o
->name
);
4154 bfd_set_error (bfd_error_nonrepresentable_section
);
4158 /* The linker script always combines .gptab.data and
4159 .gptab.sdata into .gptab.sdata, and likewise for
4160 .gptab.bss and .gptab.sbss. It is possible that there is
4161 no .sdata or .sbss section in the output file, in which
4162 case we must change the name of the output section. */
4163 subname
= o
->name
+ sizeof ".gptab" - 1;
4164 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4166 if (o
== gptab_data_sec
)
4167 o
->name
= ".gptab.data";
4169 o
->name
= ".gptab.bss";
4170 subname
= o
->name
+ sizeof ".gptab" - 1;
4171 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4174 /* Set up the first entry. */
4176 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
4179 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4180 tab
[0].gt_header
.gt_unused
= 0;
4182 /* Combine the input sections. */
4183 for (p
= o
->link_order_head
;
4184 p
!= (struct bfd_link_order
*) NULL
;
4187 asection
*input_section
;
4191 bfd_size_type gpentry
;
4193 if (p
->type
!= bfd_indirect_link_order
)
4195 if (p
->type
== bfd_fill_link_order
)
4200 input_section
= p
->u
.indirect
.section
;
4201 input_bfd
= input_section
->owner
;
4203 /* Combine the gptab entries for this input section one
4204 by one. We know that the input gptab entries are
4205 sorted by ascending -G value. */
4206 size
= bfd_section_size (input_bfd
, input_section
);
4208 for (gpentry
= sizeof (Elf32_External_gptab
);
4210 gpentry
+= sizeof (Elf32_External_gptab
))
4212 Elf32_External_gptab ext_gptab
;
4213 Elf32_gptab int_gptab
;
4219 if (! (bfd_get_section_contents
4220 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4221 gpentry
, sizeof (Elf32_External_gptab
))))
4227 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
4229 val
= int_gptab
.gt_entry
.gt_g_value
;
4230 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4233 for (look
= 1; look
< c
; look
++)
4235 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4236 tab
[look
].gt_entry
.gt_bytes
+= add
;
4238 if (tab
[look
].gt_entry
.gt_g_value
== val
)
4244 Elf32_gptab
*new_tab
;
4247 /* We need a new table entry. */
4248 new_tab
= ((Elf32_gptab
*)
4249 bfd_realloc ((PTR
) tab
,
4250 (c
+ 1) * sizeof (Elf32_gptab
)));
4251 if (new_tab
== NULL
)
4257 tab
[c
].gt_entry
.gt_g_value
= val
;
4258 tab
[c
].gt_entry
.gt_bytes
= add
;
4260 /* Merge in the size for the next smallest -G
4261 value, since that will be implied by this new
4264 for (look
= 1; look
< c
; look
++)
4266 if (tab
[look
].gt_entry
.gt_g_value
< val
4268 || (tab
[look
].gt_entry
.gt_g_value
4269 > tab
[max
].gt_entry
.gt_g_value
)))
4273 tab
[c
].gt_entry
.gt_bytes
+=
4274 tab
[max
].gt_entry
.gt_bytes
;
4279 last
= int_gptab
.gt_entry
.gt_bytes
;
4282 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4283 elf_link_input_bfd ignores this section. */
4284 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4287 /* The table must be sorted by -G value. */
4289 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
4291 /* Swap out the table. */
4292 ext_tab
= ((Elf32_External_gptab
*)
4293 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
4294 if (ext_tab
== NULL
)
4300 for (i
= 0; i
< c
; i
++)
4301 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
4304 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
4305 o
->contents
= (bfd_byte
*) ext_tab
;
4307 /* Skip this section later on (I don't think this currently
4308 matters, but someday it might). */
4309 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4313 /* Invoke the regular ELF backend linker to do all the work. */
4314 if (! bfd_elf32_bfd_final_link (abfd
, info
))
4317 /* Now write out the computed sections. */
4319 if (reginfo_sec
!= (asection
*) NULL
)
4321 Elf32_External_RegInfo ext
;
4323 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
4324 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4325 (file_ptr
) 0, sizeof ext
))
4329 if (mdebug_sec
!= (asection
*) NULL
)
4331 BFD_ASSERT (abfd
->output_has_begun
);
4332 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4334 mdebug_sec
->filepos
))
4337 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4340 if (gptab_data_sec
!= (asection
*) NULL
)
4342 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4343 gptab_data_sec
->contents
,
4345 gptab_data_sec
->_raw_size
))
4349 if (gptab_bss_sec
!= (asection
*) NULL
)
4351 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4352 gptab_bss_sec
->contents
,
4354 gptab_bss_sec
->_raw_size
))
4358 if (SGI_COMPAT (abfd
))
4360 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4361 if (rtproc_sec
!= NULL
)
4363 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
4364 rtproc_sec
->contents
,
4366 rtproc_sec
->_raw_size
))
4374 /* Handle a MIPS ELF HI16 reloc. */
4377 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
4379 Elf_Internal_Rela
*relhi
;
4380 Elf_Internal_Rela
*rello
;
4387 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4389 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4392 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4394 if ((addlo
& 0x8000) != 0)
4396 if ((addend
& 0x8000) != 0)
4399 bfd_put_32 (input_bfd
,
4400 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
4401 contents
+ relhi
->r_offset
);
4404 /* Handle a MIPS ELF local GOT16 reloc. */
4407 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
4412 Elf_Internal_Rela
*relhi
;
4413 Elf_Internal_Rela
*rello
;
4417 unsigned int assigned_gotno
;
4423 bfd_byte
*got_contents
;
4424 struct mips_got_info
*g
;
4426 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4428 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4431 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4433 if ((addlo
& 0x8000) != 0)
4435 if ((addend
& 0x8000) != 0)
4438 /* Get a got entry representing requested hipage. */
4439 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4440 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4441 BFD_ASSERT (g
!= NULL
);
4443 assigned_gotno
= g
->assigned_gotno
;
4444 got_contents
= sgot
->contents
;
4445 hipage
= addend
& 0xffff0000;
4447 for (i
= MIPS_RESERVED_GOTNO
; i
< assigned_gotno
; i
++)
4449 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
4450 if (hipage
== (address
& 0xffff0000))
4454 if (i
== assigned_gotno
)
4456 if (assigned_gotno
>= g
->local_gotno
)
4458 (*_bfd_error_handler
)
4459 ("more got entries are needed for hipage relocations");
4460 bfd_set_error (bfd_error_bad_value
);
4464 bfd_put_32 (input_bfd
, hipage
, got_contents
+ assigned_gotno
* 4);
4465 ++g
->assigned_gotno
;
4468 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
4469 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
4470 contents
+ relhi
->r_offset
);
4475 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
4478 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
4480 Elf_Internal_Rela
*rel
;
4486 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4487 bfd_put_32 (input_bfd
,
4488 (insn
& 0xffff0000) | (offset
& 0xffff),
4489 contents
+ rel
->r_offset
);
4492 /* Relocate a MIPS ELF section. */
4495 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4496 contents
, relocs
, local_syms
, local_sections
)
4498 struct bfd_link_info
*info
;
4500 asection
*input_section
;
4502 Elf_Internal_Rela
*relocs
;
4503 Elf_Internal_Sym
*local_syms
;
4504 asection
**local_sections
;
4506 Elf_Internal_Shdr
*symtab_hdr
;
4509 asection
*sgot
, *sreloc
, *scpt
;
4512 Elf_Internal_Rela
*rel
;
4513 Elf_Internal_Rela
*relend
;
4514 struct mips_got_info
*g
;
4516 dynobj
= elf_hash_table (info
)->dynobj
;
4517 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4521 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
4524 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
4527 if (elf_bad_symtab (input_bfd
))
4529 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
4534 locsymcount
= symtab_hdr
->sh_info
;
4535 extsymoff
= symtab_hdr
->sh_info
;
4538 gp
= _bfd_get_gp_value (output_bfd
);
4541 relend
= relocs
+ input_section
->reloc_count
;
4542 for (; rel
< relend
; rel
++)
4545 reloc_howto_type
*howto
;
4546 unsigned long r_symndx
;
4548 struct elf_link_hash_entry
*h
;
4550 Elf_Internal_Sym
*sym
;
4551 struct mips_elf_link_hash_entry
*mh
;
4553 bfd_reloc_status_type r
;
4555 r_type
= ELF32_R_TYPE (rel
->r_info
);
4556 if ((r_type
< 0 || r_type
>= (int) R_MIPS_max
)
4557 && r_type
!= R_MIPS16_26
4558 && r_type
!= R_MIPS16_GPREL
)
4560 bfd_set_error (bfd_error_bad_value
);
4563 if (r_type
== R_MIPS16_26
)
4564 howto
= &elf_mips16_jump_howto
;
4565 else if (r_type
== R_MIPS16_GPREL
)
4566 howto
= &elf_mips16_gprel_howto
;
4568 howto
= elf_mips_howto_table
+ r_type
;
4571 && (r_type
== R_MIPS_CALL16
4572 || r_type
== R_MIPS_GOT16
4573 || r_type
== R_MIPS_CALL_HI16
4574 || r_type
== R_MIPS_CALL_LO16
4575 || r_type
== R_MIPS_GOT_HI16
4576 || r_type
== R_MIPS_GOT_LO16
))
4578 /* We need the .got section. */
4581 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4582 BFD_ASSERT (sgot
!= NULL
);
4583 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4584 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4585 BFD_ASSERT (g
!= NULL
);
4589 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4591 /* Mix in the change in GP address for a GP relative reloc. */
4592 if (r_type
!= R_MIPS_GPREL16
4593 && r_type
!= R_MIPS_LITERAL
4594 && r_type
!= R_MIPS_GPREL32
4595 && r_type
!= R_MIPS16_GPREL
)
4601 if (! ((*info
->callbacks
->reloc_dangerous
)
4603 "GP relative relocation when GP not defined",
4604 input_bfd
, input_section
,
4607 /* Only give the error once per link. */
4609 _bfd_set_gp_value (output_bfd
, gp
);
4612 if (r_symndx
< extsymoff
4613 || (elf_bad_symtab (input_bfd
)
4614 && local_sections
[r_symndx
] != NULL
))
4616 /* This is a relocation against a section. The current
4617 addend in the instruction is the difference between
4618 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
4619 must change this to be the difference between the
4620 final definition (which will end up in RELOCATION)
4621 and the GP value of OUTPUT_BFD (which is in GP). */
4622 addend
= elf_gp (input_bfd
) - gp
;
4624 else if (! info
->relocateable
)
4626 /* We are doing a final link. The current addend in the
4627 instruction is simply the desired offset into the
4628 symbol (normally zero). We want the instruction to
4629 hold the difference between the final definition of
4630 the symbol (which will end up in RELOCATION) and the
4631 GP value of OUTPUT_BFD (which is in GP). */
4636 /* We are generating relocateable output, and we aren't
4637 going to define this symbol, so we just leave the
4638 instruction alone. */
4646 if (info
->relocateable
)
4648 /* This is a relocateable link. We don't have to change
4649 anything, unless the reloc is against a section symbol,
4650 in which case we have to adjust according to where the
4651 section symbol winds up in the output section. */
4652 if (r_symndx
>= locsymcount
4653 || (elf_bad_symtab (input_bfd
)
4654 && local_sections
[r_symndx
] == NULL
))
4658 sym
= local_syms
+ r_symndx
;
4659 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4663 sec
= local_sections
[r_symndx
];
4665 /* It would be logical to add sym->st_value here,
4666 but Irix 5 sometimes generates a garbage symbol
4668 addend
+= sec
->output_offset
;
4670 /* If this is HI16 or GOT16 with an associated LO16,
4671 adjust the addend accordingly. Otherwise, just
4673 if (r_type
== R_MIPS_64
&& bfd_big_endian (input_bfd
))
4674 r
= _bfd_relocate_contents (howto
, input_bfd
,
4676 contents
+ rel
->r_offset
+ 4);
4677 else if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
4678 r
= _bfd_relocate_contents (howto
, input_bfd
,
4680 contents
+ rel
->r_offset
);
4683 Elf_Internal_Rela
*lorel
;
4685 /* As a GNU extension, permit an arbitrary
4686 number of R_MIPS_HI16 relocs before the
4687 R_MIPS_LO16 reloc. This permits gcc to emit
4688 the HI and LO relocs itself. */
4689 if (r_type
== R_MIPS_GOT16
)
4693 for (lorel
= rel
+ 1;
4695 && (ELF32_R_TYPE (lorel
->r_info
)
4701 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
4703 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
4708 r
= _bfd_relocate_contents (howto
, input_bfd
,
4710 contents
+ rel
->r_offset
);
4720 /* This is a final link. */
4722 if (r_symndx
< extsymoff
4723 || (elf_bad_symtab (input_bfd
)
4724 && local_sections
[r_symndx
] != NULL
))
4727 sym
= local_syms
+ r_symndx
;
4728 sec
= local_sections
[r_symndx
];
4729 relocation
= (sec
->output_section
->vma
4730 + sec
->output_offset
);
4732 /* It would be logical to always add sym->st_value here,
4733 but Irix 5 sometimes generates a garbage symbol
4735 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4736 relocation
+= sym
->st_value
;
4738 /* mips16 text labels should be treated as odd. */
4739 if (sym
->st_other
== STO_MIPS16
)
4747 indx
= r_symndx
- extsymoff
;
4748 h
= elf_sym_hashes (input_bfd
)[indx
];
4749 while (h
->root
.type
== bfd_link_hash_indirect
4750 || h
->root
.type
== bfd_link_hash_warning
)
4751 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4752 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
4756 if (! ((*info
->callbacks
->reloc_dangerous
)
4758 "_gp_disp used when GP not defined",
4759 input_bfd
, input_section
,
4762 /* Only give the error once per link. */
4764 _bfd_set_gp_value (output_bfd
, gp
);
4769 sec
= input_section
;
4770 if (sec
->output_section
!= NULL
)
4773 + sec
->output_section
->vma
4774 + sec
->output_offset
));
4776 relocation
= gp
- rel
->r_offset
;
4777 if (r_type
== R_MIPS_LO16
)
4781 else if (h
->root
.type
== bfd_link_hash_defined
4782 || h
->root
.type
== bfd_link_hash_defweak
)
4784 sec
= h
->root
.u
.def
.section
;
4785 if (sec
->output_section
== NULL
)
4788 relocation
= (h
->root
.u
.def
.value
4789 + sec
->output_section
->vma
4790 + sec
->output_offset
);
4792 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4794 else if (info
->shared
&& ! info
->symbolic
)
4796 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
4798 /* If this is a dynamic link, we should have created
4799 a _DYNAMIC_LINK symbol in
4800 mips_elf_create_dynamic_sections. Otherwise, we
4801 should define the symbol with a value of 0.
4802 FIXME: It should probably get into the symbol
4803 table somehow as well. */
4804 BFD_ASSERT (! info
->shared
);
4805 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
4806 ".dynamic") == NULL
);
4811 if (! ((*info
->callbacks
->undefined_symbol
)
4812 (info
, h
->root
.root
.string
, input_bfd
,
4813 input_section
, rel
->r_offset
)))
4819 mh
= (struct mips_elf_link_hash_entry
*) h
;
4822 else if (sym
!= NULL
)
4823 other
= sym
->st_other
;
4827 /* If this function has an fn_stub, then it is a mips16
4828 function which needs a stub if it is called by a 32 bit
4829 function. If this reloc is anything other than a 16 bit
4830 call, redirect the reloc to the stub. We don't redirect
4831 relocs from other stub functions. */
4832 if (r_type
!= R_MIPS16_26
4834 && mh
->fn_stub
!= NULL
)
4836 && elf_tdata (input_bfd
)->local_stubs
!= NULL
4837 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
4838 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
4839 FN_STUB
, sizeof FN_STUB
- 1) != 0
4840 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
4841 CALL_STUB
, sizeof CALL_STUB
- 1) != 0
4842 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
4843 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) != 0)
4847 BFD_ASSERT (mh
->need_fn_stub
);
4848 relocation
= (mh
->fn_stub
->output_section
->vma
4849 + mh
->fn_stub
->output_offset
);
4855 fn_stub
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
4856 relocation
= (fn_stub
->output_section
->vma
4857 + fn_stub
->output_offset
);
4860 /* RELOCATION now points to 32 bit code. */
4864 /* If this function has a call_stub, then it is called by a
4865 mips16 function; the call needs to go through a stub if
4866 this function is a 32 bit function. If this reloc is a
4867 16 bit call, and the symbol is not a 16 bit function,
4868 then redirect the reloc to the stub. Note that we don't
4869 need to worry about calling the function through a
4870 function pointer; such calls are handled by routing
4871 through a special mips16 routine. We don't have to check
4872 whether this call is from a stub; it can't be, because a
4873 stub contains 32 bit code, and hence can not have a 16
4875 if (r_type
== R_MIPS16_26
4877 && (mh
->call_stub
!= NULL
|| mh
->call_fp_stub
!= NULL
)
4878 && other
!= STO_MIPS16
)
4882 /* If both call_stub and call_fp_stub are defined, we
4883 can figure out which one to use by seeing which one
4884 appears in the input file. */
4885 if (mh
->call_stub
!= NULL
&& mh
->call_fp_stub
!= NULL
)
4890 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
4892 if (strncmp (bfd_get_section_name (input_bfd
, o
),
4893 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
4895 stub
= mh
->call_fp_stub
;
4900 stub
= mh
->call_stub
;
4902 else if (mh
->call_stub
!= NULL
)
4903 stub
= mh
->call_stub
;
4905 stub
= mh
->call_fp_stub
;
4907 BFD_ASSERT (stub
->_raw_size
> 0);
4908 relocation
= stub
->output_section
->vma
+ stub
->output_offset
;
4911 if (r_type
== R_MIPS_HI16
)
4913 Elf_Internal_Rela
*lorel
;
4915 /* As a GNU extension, permit an arbitrary number of
4916 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
4917 This permits gcc to emit the HI and LO relocs itself. */
4918 for (lorel
= rel
+ 1;
4920 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
4924 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
4926 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
4927 contents
, relocation
+ addend
);
4931 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4932 contents
, rel
->r_offset
,
4933 relocation
, addend
);
4935 else if (r_type
== R_MIPS_GOT16
&& local
)
4937 /* GOT16 must also have an associated LO16 in the local
4938 case. In this case, the addend is extracted and the
4939 section in which the referenced object is determined.
4940 Then the final address of the object is computed and
4941 the GOT entry for the hipage (an aligned 64kb chunk)
4942 is added to .got section if needed. The offset field
4943 of the GOT16-relocated instruction is replaced by the
4944 index of this GOT entry for the hipage. */
4945 if ((rel
+ 1) < relend
4946 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
4948 if (! mips_elf_relocate_got_local (output_bfd
, input_bfd
,
4951 relocation
+ addend
))
4956 r
= bfd_reloc_outofrange
;
4958 else if (r_type
== R_MIPS_CALL16
4959 || r_type
== R_MIPS_GOT16
4960 || r_type
== R_MIPS_CALL_LO16
4961 || r_type
== R_MIPS_GOT_LO16
)
4965 /* This symbol must be registered as a global symbol
4966 having the corresponding got entry. */
4967 BFD_ASSERT (h
->got_offset
!= (bfd_vma
) -1);
4969 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
4970 BFD_ASSERT (g
->local_gotno
<= offset
4971 && offset
< sgot
->_raw_size
);
4972 bfd_put_32 (output_bfd
, relocation
+ addend
,
4973 sgot
->contents
+ offset
);
4974 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
4976 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
4980 else if (r_type
== R_MIPS_CALL_HI16
4981 || r_type
== R_MIPS_GOT_HI16
)
4985 /* This must be a global symbol with a got entry. The
4986 next reloc must be the corresponding LO16 reloc. */
4987 BFD_ASSERT (h
!= NULL
&& h
->got_offset
!= (bfd_vma
) -1);
4988 BFD_ASSERT ((rel
+ 1) < relend
);
4989 BFD_ASSERT (ELF32_R_TYPE ((rel
+ 1)->r_info
)
4990 == (r_type
== R_MIPS_CALL_HI16
4992 : R_MIPS_GOT_LO16
));
4994 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
4995 BFD_ASSERT (g
->local_gotno
<= offset
4996 && offset
< sgot
->_raw_size
);
4997 bfd_put_32 (output_bfd
, relocation
+ addend
,
4998 sgot
->contents
+ offset
);
4999 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5001 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
5005 else if (r_type
== R_MIPS_REL32
5006 || r_type
== R_MIPS_32
)
5008 Elf_Internal_Rel outrel
;
5009 Elf32_crinfo cptrel
;
5013 || (elf_hash_table (info
)->dynamic_sections_created
5015 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
5017 && (input_section
->flags
& SEC_ALLOC
) != 0)
5019 /* When generating a shared object, these
5020 relocations are copied into the output file to be
5021 resolved at run time. */
5024 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5025 BFD_ASSERT (sreloc
!= NULL
);
5028 outrel
.r_offset
= (rel
->r_offset
5029 + input_section
->output_section
->vma
5030 + input_section
->output_offset
);
5032 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5035 && (! info
->symbolic
5036 || (h
->elf_link_hash_flags
5037 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5039 BFD_ASSERT (h
->dynindx
!= -1);
5040 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
5041 sec
= input_section
;
5048 sec
= local_sections
[r_symndx
];
5051 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
5053 == bfd_link_hash_defweak
));
5054 sec
= h
->root
.u
.def
.section
;
5056 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5058 else if (sec
== NULL
|| sec
->owner
== NULL
)
5060 bfd_set_error (bfd_error_bad_value
);
5067 osec
= sec
->output_section
;
5068 indx
= elf_section_data (osec
)->dynindx
;
5073 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
5074 addend
+= relocation
;
5077 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
5078 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
5079 (((Elf32_External_Rel
*)
5081 + sreloc
->reloc_count
));
5082 ++sreloc
->reloc_count
;
5084 if (SGI_COMPAT (output_bfd
))
5089 /* Make an entry of compact relocation info. */
5090 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5091 cptrel
.vaddr
= (rel
->r_offset
5092 + input_section
->output_section
->vma
5093 + input_section
->output_offset
);
5094 if (r_type
== R_MIPS_REL32
)
5095 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5097 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5098 mips_elf_set_cr_dist2to (cptrel
, 0);
5099 cptrel
.konst
= addend
;
5101 cr
= (scpt
->contents
5102 + sizeof (Elf32_External_compact_rel
));
5103 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5104 ((Elf32_External_crinfo
*) cr
5105 + scpt
->reloc_count
));
5106 ++scpt
->reloc_count
;
5109 /* This reloc will be computed at runtime, so
5110 there's no need to do anything now. */
5114 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5115 contents
, rel
->r_offset
,
5116 relocation
, addend
);
5118 else if (r_type
== R_MIPS_64
)
5123 /* Do a 32 bit relocation, and sign extend to 64 bits. */
5124 addr
= rel
->r_offset
;
5125 if (bfd_big_endian (input_bfd
))
5127 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5128 contents
, addr
, relocation
,
5130 val
= bfd_get_32 (input_bfd
, contents
+ addr
);
5131 if ((val
& 0x80000000) != 0)
5135 addr
= rel
->r_offset
;
5136 if (bfd_little_endian (input_bfd
))
5138 bfd_put_32 (input_bfd
, val
, contents
+ addr
);
5140 else if (r_type
== R_MIPS_26
&& other
== STO_MIPS16
)
5144 /* This is a jump to a mips16 routine from a mips32
5145 routine. We need to change jal into jalx. */
5146 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5147 if (((insn
>> 26) & 0x3f) != 0x3
5148 && ((insn
>> 26) & 0x3f) != 0x1d)
5150 (*_bfd_error_handler
)
5151 ("%s: %s+0x%lx: jump to mips16 routine which is not jal",
5152 bfd_get_filename (input_bfd
),
5153 input_section
->name
,
5154 (unsigned long) rel
->r_offset
);
5155 bfd_set_error (bfd_error_bad_value
);
5158 insn
= (insn
& 0x3ffffff) | (0x1d << 26);
5159 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5160 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5161 contents
, rel
->r_offset
,
5162 relocation
, addend
);
5164 else if (r_type
== R_MIPS16_26
)
5166 /* It's easiest to do the normal relocation, and then
5167 dig out the instruction and swap the first word the
5168 way the mips16 expects it. */
5169 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5170 contents
, rel
->r_offset
,
5171 relocation
, addend
);
5172 if (r
== bfd_reloc_ok
)
5176 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5177 insn
= ((insn
& 0xfc00)
5178 | ((insn
& 0x1f) << 5)
5179 | ((insn
& 0x3e0) >> 5));
5180 /* If this is a jump to a 32 bit routine, then make
5182 if (other
!= STO_MIPS16
)
5184 bfd_put_16 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5187 else if (r_type
== R_MIPS16_GPREL
)
5189 unsigned short extend
, insn
;
5191 unsigned long final
;
5193 /* Extract the addend into buf, run the regular reloc,
5194 and stuff the resulting value back into the
5196 if (rel
->r_offset
> input_section
->_raw_size
)
5197 r
= bfd_reloc_outofrange
;
5200 extend
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5201 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 2);
5202 bfd_put_32 (input_bfd
,
5203 (((extend
& 0x1f) << 11)
5207 r
= _bfd_final_link_relocate (howto
, input_bfd
,
5209 (bfd_vma
) 0, relocation
,
5211 final
= bfd_get_32 (input_bfd
, buf
);
5212 bfd_put_16 (input_bfd
,
5214 | ((final
>> 11) & 0x1f)
5216 contents
+ rel
->r_offset
);
5217 bfd_put_16 (input_bfd
,
5220 contents
+ rel
->r_offset
+ 2);
5224 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5225 contents
, rel
->r_offset
,
5226 relocation
, addend
);
5228 /* The jal instruction can only jump to an address which is
5229 divisible by 4, and it can only jump to an address with
5230 the same upper 4 bits as the PC. */
5231 if (r
== bfd_reloc_ok
5232 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
))
5237 if (other
== STO_MIPS16
)
5238 addr
&= ~ (bfd_vma
) 1;
5241 || ((addr
& 0xf0000000)
5242 != ((input_section
->output_section
->vma
5243 + input_section
->output_offset
5246 r
= bfd_reloc_overflow
;
5249 if (SGI_COMPAT (abfd
)
5251 && (input_section
->flags
& SEC_ALLOC
) != 0)
5253 Elf32_crinfo cptrel
;
5256 /* Make an entry of compact relocation info. */
5257 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5258 cptrel
.vaddr
= (rel
->r_offset
5259 + input_section
->output_section
->vma
5260 + input_section
->output_offset
);
5265 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
5266 /* XXX How should we set dist2to in this case. */
5267 mips_elf_set_cr_dist2to (cptrel
, 8);
5268 cptrel
.konst
= addend
+ relocation
;
5269 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5270 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5271 ((Elf32_External_crinfo
*) cr
5272 + scpt
->reloc_count
));
5273 ++scpt
->reloc_count
;
5276 case R_MIPS_GPREL16
:
5277 case R_MIPS_LITERAL
:
5278 case R_MIPS_GPREL32
:
5279 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
5280 cptrel
.konst
= gp
- cptrel
.vaddr
;
5281 mips_elf_set_cr_dist2to (cptrel
, 4);
5282 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5283 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5284 ((Elf32_External_crinfo
*) cr
5285 + scpt
->reloc_count
));
5286 ++scpt
->reloc_count
;
5295 if (r
!= bfd_reloc_ok
)
5300 case bfd_reloc_outofrange
:
5302 case bfd_reloc_overflow
:
5307 name
= h
->root
.root
.string
;
5310 name
= bfd_elf_string_from_elf_section (input_bfd
,
5311 symtab_hdr
->sh_link
,
5316 name
= bfd_section_name (input_bfd
, sec
);
5318 if (! ((*info
->callbacks
->reloc_overflow
)
5319 (info
, name
, howto
->name
, (bfd_vma
) 0,
5320 input_bfd
, input_section
, rel
->r_offset
)))
5331 /* This hook function is called before the linker writes out a global
5332 symbol. This is where we undo the increment of the value for a
5337 mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
5339 struct bfd_link_info
*info
;
5341 Elf_Internal_Sym
*sym
;
5342 asection
*input_sec
;
5344 if (sym
->st_other
== STO_MIPS16
5345 && (sym
->st_value
& 1) != 0)
5350 /* Functions for the dynamic linker. */
5352 /* The name of the dynamic interpreter. This is put in the .interp
5355 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
5357 /* Create dynamic sections when linking against a dynamic object. */
5360 mips_elf_create_dynamic_sections (abfd
, info
)
5362 struct bfd_link_info
*info
;
5364 struct elf_link_hash_entry
*h
;
5366 register asection
*s
;
5367 const char * const *namep
;
5369 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5370 | SEC_LINKER_CREATED
| SEC_READONLY
);
5372 /* Mips ABI requests the .dynamic section to be read only. */
5373 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5376 if (! bfd_set_section_flags (abfd
, s
, flags
))
5380 /* We need to create .got section. */
5381 if (! mips_elf_create_got_section (abfd
, info
))
5384 /* Create .stub section. */
5385 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
5387 s
= bfd_make_section (abfd
, ".stub");
5389 || ! bfd_set_section_flags (abfd
, s
, flags
)
5390 || ! bfd_set_section_alignment (abfd
, s
, 2))
5394 if (SGI_COMPAT (abfd
)
5396 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
5398 s
= bfd_make_section (abfd
, ".rld_map");
5400 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
5401 || ! bfd_set_section_alignment (abfd
, s
, 2))
5405 if (SGI_COMPAT (abfd
))
5407 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
5410 if (! (_bfd_generic_link_add_one_symbol
5411 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
5412 (bfd_vma
) 0, (const char *) NULL
, false,
5413 get_elf_backend_data (abfd
)->collect
,
5414 (struct bfd_link_hash_entry
**) &h
)))
5416 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5417 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5418 h
->type
= STT_SECTION
;
5420 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5424 /* We need to create a .compact_rel section. */
5425 if (! mips_elf_create_compact_rel_section (abfd
, info
))
5428 /* Change aligments of some sections. */
5429 s
= bfd_get_section_by_name (abfd
, ".hash");
5431 bfd_set_section_alignment (abfd
, s
, 4);
5432 s
= bfd_get_section_by_name (abfd
, ".dynsym");
5434 bfd_set_section_alignment (abfd
, s
, 4);
5435 s
= bfd_get_section_by_name (abfd
, ".dynstr");
5437 bfd_set_section_alignment (abfd
, s
, 4);
5438 s
= bfd_get_section_by_name (abfd
, ".reginfo");
5440 bfd_set_section_alignment (abfd
, s
, 4);
5441 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5443 bfd_set_section_alignment (abfd
, s
, 4);
5449 if (! (_bfd_generic_link_add_one_symbol
5450 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
5451 (bfd_vma
) 0, (const char *) NULL
, false,
5452 get_elf_backend_data (abfd
)->collect
,
5453 (struct bfd_link_hash_entry
**) &h
)))
5455 h
->elf_link_hash_flags
^=~ ELF_LINK_NON_ELF
;
5456 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5457 h
->type
= STT_SECTION
;
5459 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5462 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
5464 /* __rld_map is a four byte word located in the .data section
5465 and is filled in by the rtld to contain a pointer to
5466 the _r_debug structure. Its symbol value will be set in
5467 mips_elf_finish_dynamic_symbol. */
5468 s
= bfd_get_section_by_name (abfd
, ".rld_map");
5469 BFD_ASSERT (s
!= NULL
);
5472 if (! (_bfd_generic_link_add_one_symbol
5473 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
5474 (bfd_vma
) 0, (const char *) NULL
, false,
5475 get_elf_backend_data (abfd
)->collect
,
5476 (struct bfd_link_hash_entry
**) &h
)))
5478 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5479 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5480 h
->type
= STT_OBJECT
;
5482 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5490 /* Create the .compact_rel section. */
5493 mips_elf_create_compact_rel_section (abfd
, info
)
5495 struct bfd_link_info
*info
;
5498 register asection
*s
;
5500 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
5502 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
5505 s
= bfd_make_section (abfd
, ".compact_rel");
5507 || ! bfd_set_section_flags (abfd
, s
, flags
)
5508 || ! bfd_set_section_alignment (abfd
, s
, 2))
5511 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
5517 /* Create the .got section to hold the global offset table. */
5520 mips_elf_create_got_section (abfd
, info
)
5522 struct bfd_link_info
*info
;
5525 register asection
*s
;
5526 struct elf_link_hash_entry
*h
;
5527 struct mips_got_info
*g
;
5529 /* This function may be called more than once. */
5530 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
5533 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5534 | SEC_LINKER_CREATED
);
5536 s
= bfd_make_section (abfd
, ".got");
5538 || ! bfd_set_section_flags (abfd
, s
, flags
)
5539 || ! bfd_set_section_alignment (abfd
, s
, 4))
5542 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
5543 linker script because we don't want to define the symbol if we
5544 are not creating a global offset table. */
5546 if (! (_bfd_generic_link_add_one_symbol
5547 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
5548 (bfd_vma
) 0, (const char *) NULL
, false,
5549 get_elf_backend_data (abfd
)->collect
,
5550 (struct bfd_link_hash_entry
**) &h
)))
5552 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5553 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5554 h
->type
= STT_OBJECT
;
5557 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5560 /* The first several global offset table entries are reserved. */
5561 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
5563 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
5564 sizeof (struct mips_got_info
));
5567 g
->global_gotsym
= 0;
5568 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
5569 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
5570 if (elf_section_data (s
) == NULL
)
5573 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
5574 if (elf_section_data (s
) == NULL
)
5577 elf_section_data (s
)->tdata
= (PTR
) g
;
5582 /* Look through the relocs for a section during the first phase, and
5583 allocate space in the global offset table. */
5586 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
5588 struct bfd_link_info
*info
;
5590 const Elf_Internal_Rela
*relocs
;
5594 Elf_Internal_Shdr
*symtab_hdr
;
5595 struct elf_link_hash_entry
**sym_hashes
;
5596 struct mips_got_info
*g
;
5598 const Elf_Internal_Rela
*rel
;
5599 const Elf_Internal_Rela
*rel_end
;
5603 if (info
->relocateable
)
5606 dynobj
= elf_hash_table (info
)->dynobj
;
5607 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5608 sym_hashes
= elf_sym_hashes (abfd
);
5609 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
5611 /* Check for the mips16 stub sections. */
5613 name
= bfd_get_section_name (abfd
, sec
);
5614 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
5616 unsigned long r_symndx
;
5618 /* Look at the relocation information to figure out which symbol
5621 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
5623 if (r_symndx
< extsymoff
5624 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
5628 /* This stub is for a local symbol. This stub will only be
5629 needed if there is some relocation in this BFD, other
5630 than a 16 bit function call, which refers to this symbol. */
5631 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5633 Elf_Internal_Rela
*sec_relocs
;
5634 const Elf_Internal_Rela
*r
, *rend
;
5636 /* We can ignore stub sections when looking for relocs. */
5637 if ((o
->flags
& SEC_RELOC
) == 0
5638 || o
->reloc_count
== 0
5639 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
5640 sizeof FN_STUB
- 1) == 0
5641 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
5642 sizeof CALL_STUB
- 1) == 0
5643 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
5644 sizeof CALL_FP_STUB
- 1) == 0)
5647 sec_relocs
= (_bfd_elf32_link_read_relocs
5648 (abfd
, o
, (PTR
) NULL
,
5649 (Elf_Internal_Rela
*) NULL
,
5650 info
->keep_memory
));
5651 if (sec_relocs
== NULL
)
5654 rend
= sec_relocs
+ o
->reloc_count
;
5655 for (r
= sec_relocs
; r
< rend
; r
++)
5656 if (ELF32_R_SYM (r
->r_info
) == r_symndx
5657 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
5660 if (! info
->keep_memory
)
5669 /* There is no non-call reloc for this stub, so we do
5670 not need it. Since this function is called before
5671 the linker maps input sections to output sections, we
5672 can easily discard it by setting the SEC_EXCLUDE
5674 sec
->flags
|= SEC_EXCLUDE
;
5678 /* Record this stub in an array of local symbol stubs for
5680 if (elf_tdata (abfd
)->local_stubs
== NULL
)
5682 unsigned long symcount
;
5685 if (elf_bad_symtab (abfd
))
5686 symcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
5688 symcount
= symtab_hdr
->sh_info
;
5689 n
= (asection
**) bfd_zalloc (abfd
,
5690 symcount
* sizeof (asection
*));
5693 elf_tdata (abfd
)->local_stubs
= n
;
5696 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
5698 /* We don't need to set mips16_stubs_seen in this case.
5699 That flag is used to see whether we need to look through
5700 the global symbol table for stubs. We don't need to set
5701 it here, because we just have a local stub. */
5705 struct mips_elf_link_hash_entry
*h
;
5707 h
= ((struct mips_elf_link_hash_entry
*)
5708 sym_hashes
[r_symndx
- extsymoff
]);
5710 /* H is the symbol this stub is for. */
5713 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
5716 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
5717 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5719 unsigned long r_symndx
;
5720 struct mips_elf_link_hash_entry
*h
;
5723 /* Look at the relocation information to figure out which symbol
5726 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
5728 if (r_symndx
< extsymoff
5729 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
5731 /* This stub was actually built for a static symbol defined
5732 in the same file. We assume that all static symbols in
5733 mips16 code are themselves mips16, so we can simply
5734 discard this stub. Since this function is called before
5735 the linker maps input sections to output sections, we can
5736 easily discard it by setting the SEC_EXCLUDE flag. */
5737 sec
->flags
|= SEC_EXCLUDE
;
5741 h
= ((struct mips_elf_link_hash_entry
*)
5742 sym_hashes
[r_symndx
- extsymoff
]);
5744 /* H is the symbol this stub is for. */
5746 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5747 loc
= &h
->call_fp_stub
;
5749 loc
= &h
->call_stub
;
5751 /* If we already have an appropriate stub for this function, we
5752 don't need another one, so we can discard this one. Since
5753 this function is called before the linker maps input sections
5754 to output sections, we can easily discard it by setting the
5755 SEC_EXCLUDE flag. We can also discard this section if we
5756 happen to already know that this is a mips16 function; it is
5757 not necessary to check this here, as it is checked later, but
5758 it is slightly faster to check now. */
5759 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
5761 sec
->flags
|= SEC_EXCLUDE
;
5766 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
5776 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5781 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5782 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5783 BFD_ASSERT (g
!= NULL
);
5789 rel_end
= relocs
+ sec
->reloc_count
;
5790 for (rel
= relocs
; rel
< rel_end
; rel
++)
5792 unsigned long r_symndx
;
5793 struct elf_link_hash_entry
*h
;
5795 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5797 if (r_symndx
< extsymoff
)
5800 h
= sym_hashes
[r_symndx
- extsymoff
];
5802 /* Some relocs require a global offset table. */
5803 if (dynobj
== NULL
|| sgot
== NULL
)
5805 switch (ELF32_R_TYPE (rel
->r_info
))
5809 case R_MIPS_CALL_HI16
:
5810 case R_MIPS_CALL_LO16
:
5811 case R_MIPS_GOT_HI16
:
5812 case R_MIPS_GOT_LO16
:
5814 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
5815 if (! mips_elf_create_got_section (dynobj
, info
))
5817 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5818 BFD_ASSERT (sgot
!= NULL
);
5819 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5820 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5821 BFD_ASSERT (g
!= NULL
);
5827 && (info
->shared
|| h
!= NULL
)
5828 && (sec
->flags
& SEC_ALLOC
) != 0)
5829 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
5837 switch (ELF32_R_TYPE (rel
->r_info
))
5840 case R_MIPS_CALL_HI16
:
5841 case R_MIPS_CALL_LO16
:
5842 /* This symbol requires a global offset table entry. */
5844 BFD_ASSERT (h
!= NULL
);
5846 /* Make sure this symbol is output as a dynamic symbol. */
5847 if (h
->dynindx
== -1)
5849 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5853 if (h
->got_offset
!= (bfd_vma
) -1)
5855 /* We have already allocated space in the .got. */
5859 /* Note the index of the first global got symbol in .dynsym. */
5860 if (g
->global_gotsym
== 0
5861 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
5862 g
->global_gotsym
= h
->dynindx
;
5864 /* Make this symbol to have the corresponding got entry. */
5867 /* We need a stub, not a plt entry for the undefined
5868 function. But we record it as if it needs plt. See
5869 elf_adjust_dynamic_symbol in elflink.h. */
5870 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
5876 case R_MIPS_GOT_HI16
:
5877 case R_MIPS_GOT_LO16
:
5878 /* This symbol requires a global offset table entry. */
5882 /* Make sure this symbol is output as a dynamic symbol. */
5883 if (h
->dynindx
== -1)
5885 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5889 if (h
->got_offset
!= (bfd_vma
) -1)
5891 /* We have already allocated space in the .got. */
5894 /* Note the index of the first global got symbol in
5896 if (g
->global_gotsym
== 0
5897 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
5898 g
->global_gotsym
= h
->dynindx
;
5900 /* Make this symbol to be the global got symbol. */
5908 if ((info
->shared
|| h
!= NULL
)
5909 && (sec
->flags
& SEC_ALLOC
) != 0)
5913 const char *name
= ".rel.dyn";
5915 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5918 sreloc
= bfd_make_section (dynobj
, name
);
5920 || ! bfd_set_section_flags (dynobj
, sreloc
,
5925 | SEC_LINKER_CREATED
5927 || ! bfd_set_section_alignment (dynobj
, sreloc
,
5934 /* When creating a shared object, we must copy these
5935 reloc types into the output file as R_MIPS_REL32
5936 relocs. We make room for this reloc in the
5937 .rel.dyn reloc section */
5938 if (sreloc
->_raw_size
== 0)
5940 /* Add a null element. */
5941 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
5942 ++sreloc
->reloc_count
;
5944 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
5948 struct mips_elf_link_hash_entry
*hmips
;
5950 /* We only need to copy this reloc if the symbol is
5951 defined in a dynamic object. */
5952 hmips
= (struct mips_elf_link_hash_entry
*) h
;
5953 ++hmips
->mips_32_relocs
;
5957 if (SGI_COMPAT (abfd
))
5958 mips_elf_hash_table (info
)->compact_rel_size
+=
5959 sizeof (Elf32_External_crinfo
);
5964 case R_MIPS_GPREL16
:
5965 case R_MIPS_LITERAL
:
5966 case R_MIPS_GPREL32
:
5967 if (SGI_COMPAT (abfd
))
5968 mips_elf_hash_table (info
)->compact_rel_size
+=
5969 sizeof (Elf32_External_crinfo
);
5976 /* If this reloc is not a 16 bit call, and it has a global
5977 symbol, then we will need the fn_stub if there is one.
5978 References from a stub section do not count. */
5980 && ELF32_R_TYPE (rel
->r_info
) != R_MIPS16_26
5981 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
5982 sizeof FN_STUB
- 1) != 0
5983 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
5984 sizeof CALL_STUB
- 1) != 0
5985 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
5986 sizeof CALL_FP_STUB
- 1) != 0)
5988 struct mips_elf_link_hash_entry
*mh
;
5990 mh
= (struct mips_elf_link_hash_entry
*) h
;
5991 mh
->need_fn_stub
= true;
5998 /* Adjust a symbol defined by a dynamic object and referenced by a
5999 regular object. The current definition is in some section of the
6000 dynamic object, but we're not including those sections. We have to
6001 change the definition to something the rest of the link can
6005 mips_elf_adjust_dynamic_symbol (info
, h
)
6006 struct bfd_link_info
*info
;
6007 struct elf_link_hash_entry
*h
;
6010 struct mips_elf_link_hash_entry
*hmips
;
6013 dynobj
= elf_hash_table (info
)->dynobj
;
6015 /* Make sure we know what is going on here. */
6016 BFD_ASSERT (dynobj
!= NULL
6017 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
6018 || h
->weakdef
!= NULL
6019 || ((h
->elf_link_hash_flags
6020 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
6021 && (h
->elf_link_hash_flags
6022 & ELF_LINK_HASH_REF_REGULAR
) != 0
6023 && (h
->elf_link_hash_flags
6024 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
6026 /* If this symbol is defined in a dynamic object, we need to copy
6027 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
6029 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6030 if (! info
->relocateable
6031 && hmips
->mips_32_relocs
!= 0
6032 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6034 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6035 BFD_ASSERT (s
!= NULL
);
6037 if (s
->_raw_size
== 0)
6039 /* Make room for a null element. */
6040 s
->_raw_size
+= sizeof (Elf32_External_Rel
);
6043 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
6046 /* For a function, create a stub, if needed. */
6047 if (h
->type
== STT_FUNC
6048 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
6050 if (! elf_hash_table (info
)->dynamic_sections_created
)
6053 /* If this symbol is not defined in a regular file, then set
6054 the symbol to the stub location. This is required to make
6055 function pointers compare as equal between the normal
6056 executable and the shared library. */
6057 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6059 /* We need .stub section. */
6060 s
= bfd_get_section_by_name (dynobj
, ".stub");
6061 BFD_ASSERT (s
!= NULL
);
6063 h
->root
.u
.def
.section
= s
;
6064 h
->root
.u
.def
.value
= s
->_raw_size
;
6066 /* XXX Write this stub address somewhere. */
6067 h
->plt_offset
= s
->_raw_size
;
6069 /* Make room for this stub code. */
6070 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6072 /* The last half word of the stub will be filled with the index
6073 of this symbol in .dynsym section. */
6078 /* If this is a weak symbol, and there is a real definition, the
6079 processor independent code will have arranged for us to see the
6080 real definition first, and we can just use the same value. */
6081 if (h
->weakdef
!= NULL
)
6083 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
6084 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
6085 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
6086 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
6090 /* This is a reference to a symbol defined by a dynamic object which
6091 is not a function. */
6096 /* This function is called after all the input files have been read,
6097 and the input sections have been assigned to output sections. We
6098 check for any mips16 stub sections that we can discard. */
6100 static boolean mips_elf_check_mips16_stubs
6101 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
6104 mips_elf_always_size_sections (output_bfd
, info
)
6106 struct bfd_link_info
*info
;
6108 if (info
->relocateable
6109 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
6112 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
6113 mips_elf_check_mips16_stubs
,
6119 /* Check the mips16 stubs for a particular symbol, and see if we can
6124 mips_elf_check_mips16_stubs (h
, data
)
6125 struct mips_elf_link_hash_entry
*h
;
6128 if (h
->fn_stub
!= NULL
6129 && ! h
->need_fn_stub
)
6131 /* We don't need the fn_stub; the only references to this symbol
6132 are 16 bit calls. Clobber the size to 0 to prevent it from
6133 being included in the link. */
6134 h
->fn_stub
->_raw_size
= 0;
6135 h
->fn_stub
->_cooked_size
= 0;
6136 h
->fn_stub
->flags
&= ~ SEC_RELOC
;
6137 h
->fn_stub
->reloc_count
= 0;
6138 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
6141 if (h
->call_stub
!= NULL
6142 && h
->root
.other
== STO_MIPS16
)
6144 /* We don't need the call_stub; this is a 16 bit function, so
6145 calls from other 16 bit functions are OK. Clobber the size
6146 to 0 to prevent it from being included in the link. */
6147 h
->call_stub
->_raw_size
= 0;
6148 h
->call_stub
->_cooked_size
= 0;
6149 h
->call_stub
->flags
&= ~ SEC_RELOC
;
6150 h
->call_stub
->reloc_count
= 0;
6151 h
->call_stub
->flags
|= SEC_EXCLUDE
;
6154 if (h
->call_fp_stub
!= NULL
6155 && h
->root
.other
== STO_MIPS16
)
6157 /* We don't need the call_stub; this is a 16 bit function, so
6158 calls from other 16 bit functions are OK. Clobber the size
6159 to 0 to prevent it from being included in the link. */
6160 h
->call_fp_stub
->_raw_size
= 0;
6161 h
->call_fp_stub
->_cooked_size
= 0;
6162 h
->call_fp_stub
->flags
&= ~ SEC_RELOC
;
6163 h
->call_fp_stub
->reloc_count
= 0;
6164 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
6170 /* Set the sizes of the dynamic sections. */
6173 mips_elf_size_dynamic_sections (output_bfd
, info
)
6175 struct bfd_link_info
*info
;
6181 struct mips_got_info
*g
;
6183 dynobj
= elf_hash_table (info
)->dynobj
;
6184 BFD_ASSERT (dynobj
!= NULL
);
6186 if (elf_hash_table (info
)->dynamic_sections_created
)
6188 /* Set the contents of the .interp section to the interpreter. */
6191 s
= bfd_get_section_by_name (dynobj
, ".interp");
6192 BFD_ASSERT (s
!= NULL
);
6193 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
6194 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
6198 /* Recompute the size of .got for local entires (reserved and
6199 hipages) if needed. To estimate it, get the upper bound of total
6200 size of loadable sections. */
6201 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6205 bfd_size_type loadable_size
= 0;
6206 bfd_size_type local_gotno
;
6209 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6210 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6211 BFD_ASSERT (g
!= NULL
);
6213 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
6214 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
6216 if ((s
->flags
& SEC_ALLOC
) == 0)
6218 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
6221 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
6223 /* Assume there are two loadable segments consisting of
6224 contiguous sections. Is 5 enough? */
6225 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
6226 g
->local_gotno
= local_gotno
;
6227 sgot
->_raw_size
+= local_gotno
* 4;
6230 /* The check_relocs and adjust_dynamic_symbol entry points have
6231 determined the sizes of the various dynamic sections. Allocate
6234 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
6239 /* It's OK to base decisions on the section name, because none
6240 of the dynobj section names depend upon the input files. */
6241 name
= bfd_get_section_name (dynobj
, s
);
6243 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
6248 if (strncmp (name
, ".rel", 4) == 0)
6250 if (s
->_raw_size
== 0)
6254 const char *outname
;
6257 /* If this relocation section applies to a read only
6258 section, then we probably need a DT_TEXTREL entry.
6259 If the relocation section is .rel.dyn, we always
6260 assert a DT_TEXTREL entry rather than testing whether
6261 there exists a relocation to a read only section or
6263 outname
= bfd_get_section_name (output_bfd
,
6265 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
6266 if ((target
!= NULL
&& (target
->flags
& SEC_READONLY
) != 0)
6267 || strcmp (outname
, ".rel.dyn") == 0)
6270 /* We use the reloc_count field as a counter if we need
6271 to copy relocs into the output file. */
6272 if (strcmp (name
, ".rel.dyn") != 0)
6276 else if (strncmp (name
, ".got", 4) == 0)
6280 BFD_ASSERT (elf_section_data (s
) != NULL
);
6281 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
6282 BFD_ASSERT (g
!= NULL
);
6284 /* Fix the size of .got section for the correspondence of
6285 global symbols and got entries. This adds some useless
6286 got entries. Is this required by ABI really? */
6287 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
6288 s
->_raw_size
+= i
* 4;
6290 else if (strncmp (name
, ".stub", 5) == 0)
6292 /* Irix rld assumes that the function stub isn't at the end
6293 of .text section. So put a dummy. XXX */
6294 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6296 else if (! info
->shared
6297 && ! mips_elf_hash_table (info
)->use_rld_obj_head
6298 && strncmp (name
, ".rld_map", 8) == 0)
6300 /* We add a room for __rld_map. It will be filled in by the
6301 rtld to contain a pointer to the _r_debug structure. */
6304 else if (SGI_COMPAT (output_bfd
)
6305 && strncmp (name
, ".compact_rel", 12) == 0)
6306 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
6307 else if (strncmp (name
, ".init", 5) != 0)
6309 /* It's not one of our sections, so don't allocate space. */
6317 for (spp
= &s
->output_section
->owner
->sections
;
6318 *spp
!= s
->output_section
;
6319 spp
= &(*spp
)->next
)
6321 *spp
= s
->output_section
->next
;
6322 --s
->output_section
->owner
->section_count
;
6327 /* Allocate memory for the section contents. */
6328 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
6329 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
6331 bfd_set_error (bfd_error_no_memory
);
6334 memset (s
->contents
, 0, s
->_raw_size
);
6337 if (elf_hash_table (info
)->dynamic_sections_created
)
6339 /* Add some entries to the .dynamic section. We fill in the
6340 values later, in elf_mips_finish_dynamic_sections, but we
6341 must add the entries now so that we get the correct size for
6342 the .dynamic section. The DT_DEBUG entry is filled in by the
6343 dynamic linker and used by the debugger. */
6346 if (SGI_COMPAT (output_bfd
))
6348 /* SGI object has the equivalence of DT_DEBUG in the
6349 DT_MIPS_RLD_MAP entry. */
6350 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
6354 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
6360 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
6364 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
6367 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
6369 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
6372 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
6375 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
6379 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
6382 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
6385 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
6387 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
6390 s
= bfd_get_section_by_name (dynobj
, ".liblist");
6391 BFD_ASSERT (s
!= NULL
);
6393 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
6397 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
6400 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
6404 /* Time stamps in executable files are a bad idea. */
6405 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
6410 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
6415 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
6419 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
6422 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
6425 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
6428 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
6431 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
6434 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
6437 #if 0 /* (SGI_COMPAT) */
6438 if (! bfd_get_section_by_name (dynobj
, ".init"))
6439 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
6442 if (! bfd_get_section_by_name (dynobj
, ".fini"))
6443 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
6448 /* If we use dynamic linking, we generate a section symbol for each
6449 output section. These are local symbols, which means that they
6450 must come first in the dynamic symbol table.
6451 That means we must increment the dynamic symbol index of every
6452 other dynamic symbol. */
6454 const char * const *namep
;
6456 bfd_size_type strindex
;
6457 struct bfd_strtab_hash
*dynstr
;
6458 struct mips_got_info
*g
;
6461 if (elf_hash_table (info
)->dynamic_sections_created
)
6463 if (SGI_COMPAT (output_bfd
))
6465 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
6466 elf_link_hash_traverse (elf_hash_table (info
),
6467 mips_elf_adjust_dynindx
,
6469 elf_hash_table (info
)->dynsymcount
+= c
;
6471 dynstr
= elf_hash_table (info
)->dynstr
;
6472 BFD_ASSERT (dynstr
!= NULL
);
6474 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
6478 s
= bfd_get_section_by_name (output_bfd
, *namep
);
6480 elf_section_data (s
)->dynindx
= i
;
6482 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
6483 if (strindex
== (bfd_size_type
) -1)
6486 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
6491 c
= bfd_count_sections (output_bfd
);
6492 elf_link_hash_traverse (elf_hash_table (info
),
6493 mips_elf_adjust_dynindx
,
6495 elf_hash_table (info
)->dynsymcount
+= c
;
6497 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
6499 elf_section_data (s
)->dynindx
= i
;
6500 /* These symbols will have no names, so we don't need to
6501 fiddle with dynstr_index. */
6508 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6509 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6510 BFD_ASSERT (g
!= NULL
);
6512 /* If there are no global got symbols, fake the last symbol so
6514 if (g
->global_gotsym
)
6515 g
->global_gotsym
+= c
;
6517 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
6524 /* Increment the index of a dynamic symbol by a given amount. Called
6525 via elf_link_hash_traverse. */
6528 mips_elf_adjust_dynindx (h
, cparg
)
6529 struct elf_link_hash_entry
*h
;
6532 unsigned int *cp
= (unsigned int *) cparg
;
6534 if (h
->dynindx
!= -1)
6539 /* Finish up dynamic symbol handling. We set the contents of various
6540 dynamic sections here. */
6543 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
6545 struct bfd_link_info
*info
;
6546 struct elf_link_hash_entry
*h
;
6547 Elf_Internal_Sym
*sym
;
6552 struct mips_got_info
*g
;
6555 dynobj
= elf_hash_table (info
)->dynobj
;
6556 gval
= sym
->st_value
;
6558 if (h
->plt_offset
!= (bfd_vma
) -1)
6562 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
6564 /* This symbol has a stub. Set it up. */
6566 BFD_ASSERT (h
->dynindx
!= -1);
6568 s
= bfd_get_section_by_name (dynobj
, ".stub");
6569 BFD_ASSERT (s
!= NULL
);
6571 /* Fill the stub. */
6573 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
6575 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
6578 /* FIXME: Can h->dynindex be more than 64K? */
6579 if (h
->dynindx
& 0xffff0000)
6582 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
6584 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
6586 BFD_ASSERT (h
->plt_offset
<= s
->_raw_size
);
6587 memcpy (s
->contents
+ h
->plt_offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
6589 /* Mark the symbol as undefined. plt_offset != -1 occurs
6590 only for the referenced symbol. */
6591 sym
->st_shndx
= SHN_UNDEF
;
6593 /* The run-time linker uses the st_value field of the symbol
6594 to reset the global offset table entry for this external
6595 to its stub address when unlinking a shared object. */
6596 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt_offset
;
6597 sym
->st_value
= gval
;
6600 BFD_ASSERT (h
->dynindx
!= -1);
6602 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6603 BFD_ASSERT (sgot
!= NULL
);
6604 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6605 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6606 BFD_ASSERT (g
!= NULL
);
6608 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
6610 bfd_size_type offset
;
6612 /* This symbol has an entry in the global offset table. Set its
6613 value to the corresponding got entry, if needed. */
6614 if (h
->got_offset
== (bfd_vma
) -1)
6616 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
6617 BFD_ASSERT (g
->local_gotno
* 4 <= offset
6618 && offset
< sgot
->_raw_size
);
6619 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
6623 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
6624 name
= h
->root
.root
.string
;
6625 if (strcmp (name
, "_DYNAMIC") == 0
6626 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
6627 sym
->st_shndx
= SHN_ABS
;
6628 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
6630 sym
->st_shndx
= SHN_ABS
;
6631 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6634 else if (SGI_COMPAT (output_bfd
))
6636 if (strcmp (name
, "_gp_disp") == 0)
6638 sym
->st_shndx
= SHN_ABS
;
6639 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6640 sym
->st_value
= elf_gp (output_bfd
);
6642 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
6643 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
6645 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6646 sym
->st_other
= STO_PROTECTED
;
6648 sym
->st_shndx
= SHN_MIPS_DATA
;
6650 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
6652 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6653 sym
->st_other
= STO_PROTECTED
;
6654 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
6655 sym
->st_shndx
= SHN_ABS
;
6657 else if (sym
->st_shndx
!= SHN_UNDEF
)
6659 if (h
->type
== STT_FUNC
)
6660 sym
->st_shndx
= SHN_MIPS_TEXT
;
6661 else if (h
->type
== STT_OBJECT
)
6662 sym
->st_shndx
= SHN_MIPS_DATA
;
6666 if (SGI_COMPAT (output_bfd
)
6669 if (! mips_elf_hash_table (info
)->use_rld_obj_head
6670 && strcmp (name
, "__rld_map") == 0)
6672 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
6673 BFD_ASSERT (s
!= NULL
);
6674 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
6675 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
6676 if (mips_elf_hash_table (info
)->rld_value
== 0)
6677 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
6679 else if (mips_elf_hash_table (info
)->use_rld_obj_head
6680 && strcmp (name
, "__rld_obj_head") == 0)
6682 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
6683 BFD_ASSERT (s
!= NULL
);
6684 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
6688 /* If this is a mips16 symbol, force the value to be even. */
6689 if (sym
->st_other
== STO_MIPS16
6690 && (sym
->st_value
& 1) != 0)
6696 /* Finish up the dynamic sections. */
6699 mips_elf_finish_dynamic_sections (output_bfd
, info
)
6701 struct bfd_link_info
*info
;
6706 struct mips_got_info
*g
;
6708 dynobj
= elf_hash_table (info
)->dynobj
;
6710 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
6712 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6717 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6718 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6719 BFD_ASSERT (g
!= NULL
);
6722 if (elf_hash_table (info
)->dynamic_sections_created
)
6724 Elf32_External_Dyn
*dyncon
, *dynconend
;
6726 BFD_ASSERT (sdyn
!= NULL
);
6727 BFD_ASSERT (g
!= NULL
);
6729 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
6730 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
6731 for (; dyncon
< dynconend
; dyncon
++)
6733 Elf_Internal_Dyn dyn
;
6738 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
6746 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6747 BFD_ASSERT (s
!= NULL
);
6748 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
6749 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6753 /* Rewrite DT_STRSZ. */
6755 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
6756 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6762 case DT_MIPS_CONFLICT
:
6765 case DT_MIPS_LIBLIST
:
6768 s
= bfd_get_section_by_name (output_bfd
, name
);
6769 BFD_ASSERT (s
!= NULL
);
6770 dyn
.d_un
.d_ptr
= s
->vma
;
6771 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6774 case DT_MIPS_RLD_VERSION
:
6775 dyn
.d_un
.d_val
= 1; /* XXX */
6776 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6780 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
6781 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6784 case DT_MIPS_CONFLICTNO
:
6786 elemsize
= sizeof (Elf32_Conflict
);
6789 case DT_MIPS_LIBLISTNO
:
6791 elemsize
= sizeof (Elf32_Lib
);
6793 s
= bfd_get_section_by_name (output_bfd
, name
);
6796 if (s
->_cooked_size
!= 0)
6797 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
6799 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
6804 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6807 case DT_MIPS_TIME_STAMP
:
6808 time ((time_t *) &dyn
.d_un
.d_val
);
6809 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6812 case DT_MIPS_ICHECKSUM
:
6816 case DT_MIPS_IVERSION
:
6820 case DT_MIPS_BASE_ADDRESS
:
6821 s
= output_bfd
->sections
;
6822 BFD_ASSERT (s
!= NULL
);
6823 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
6824 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6827 case DT_MIPS_LOCAL_GOTNO
:
6828 dyn
.d_un
.d_val
= g
->local_gotno
;
6829 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6832 case DT_MIPS_SYMTABNO
:
6834 elemsize
= sizeof (Elf32_External_Sym
);
6835 s
= bfd_get_section_by_name (output_bfd
, name
);
6836 BFD_ASSERT (s
!= NULL
);
6838 if (s
->_cooked_size
!= 0)
6839 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
6841 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
6842 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6845 case DT_MIPS_UNREFEXTNO
:
6847 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
6848 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6851 case DT_MIPS_GOTSYM
:
6852 dyn
.d_un
.d_val
= g
->global_gotsym
;
6853 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6856 case DT_MIPS_HIPAGENO
:
6857 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
6858 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6861 case DT_MIPS_RLD_MAP
:
6862 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
6863 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6870 /* The first entry of the global offset table will be filled at
6871 runtime. The second entry will be used by some runtime loaders.
6872 This isn't the case of Irix rld. */
6873 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
6875 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
6876 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
6880 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
6887 Elf_Internal_Sym sym
;
6890 const char * const * namep
= mips_elf_dynsym_sec_names
;
6891 Elf32_compact_rel cpt
;
6893 /* Set up the section symbols for the output sections. SGI sets
6894 the STT_NOTYPE attribute for these symbols. Should we do so? */
6896 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
6897 if (sdynsym
!= NULL
)
6899 if (SGI_COMPAT (output_bfd
))
6903 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
6907 while ((name
= *namep
++) != NULL
)
6909 s
= bfd_get_section_by_name (output_bfd
, name
);
6912 sym
.st_value
= s
->vma
;
6913 dindx
= elf_section_data (s
)->dynindx
;
6914 last
= s
->vma
+ s
->_raw_size
;
6918 sym
.st_value
= last
;
6922 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
6927 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
6929 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
6930 (((Elf32_External_Sym
*)
6935 /* Set the sh_info field of the output .dynsym section to
6936 the index of the first global symbol. */
6937 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
6938 SIZEOF_MIPS_DYNSYM_SECNAMES
;
6944 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
6947 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
6951 sym
.st_value
= s
->vma
;
6953 indx
= elf_section_data (s
)->this_idx
;
6954 BFD_ASSERT (indx
> 0);
6955 sym
.st_shndx
= indx
;
6957 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
6958 (((Elf32_External_Sym
*)
6960 + elf_section_data (s
)->dynindx
));
6963 /* Set the sh_info field of the output .dynsym section to
6964 the index of the first global symbol. */
6965 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
6966 bfd_count_sections (output_bfd
) + 1;
6970 if (SGI_COMPAT (output_bfd
))
6972 /* Write .compact_rel section out. */
6973 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
6977 cpt
.num
= s
->reloc_count
;
6979 cpt
.offset
= (s
->output_section
->filepos
6980 + sizeof (Elf32_External_compact_rel
));
6983 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
6984 ((Elf32_External_compact_rel
*)
6987 /* Clean up a dummy stub function entry in .text. */
6988 s
= bfd_get_section_by_name (dynobj
, ".stub");
6991 file_ptr dummy_offset
;
6993 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
6994 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
6995 memset (s
->contents
+ dummy_offset
, 0,
6996 MIPS_FUNCTION_STUB_SIZE
);
7001 /* Clean up a first relocation in .rel.dyn. */
7002 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7003 if (s
!= NULL
&& s
->_raw_size
> 0)
7004 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
7010 /* This is almost identical to bfd_generic_get_... except that some
7011 MIPS relocations need to be handled specially. Sigh. */
7014 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
7015 relocateable
, symbols
)
7017 struct bfd_link_info
*link_info
;
7018 struct bfd_link_order
*link_order
;
7020 boolean relocateable
;
7023 /* Get enough memory to hold the stuff */
7024 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
7025 asection
*input_section
= link_order
->u
.indirect
.section
;
7027 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
7028 arelent
**reloc_vector
= NULL
;
7034 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
7035 if (reloc_vector
== NULL
&& reloc_size
!= 0)
7038 /* read in the section */
7039 if (!bfd_get_section_contents (input_bfd
,
7043 input_section
->_raw_size
))
7046 /* We're not relaxing the section, so just copy the size info */
7047 input_section
->_cooked_size
= input_section
->_raw_size
;
7048 input_section
->reloc_done
= true;
7050 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
7054 if (reloc_count
< 0)
7057 if (reloc_count
> 0)
7062 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
7065 struct bfd_hash_entry
*h
;
7066 struct bfd_link_hash_entry
*lh
;
7067 /* Skip all this stuff if we aren't mixing formats. */
7068 if (abfd
&& input_bfd
7069 && abfd
->xvec
== input_bfd
->xvec
)
7073 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
7074 lh
= (struct bfd_link_hash_entry
*) h
;
7081 case bfd_link_hash_undefined
:
7082 case bfd_link_hash_undefweak
:
7083 case bfd_link_hash_common
:
7086 case bfd_link_hash_defined
:
7087 case bfd_link_hash_defweak
:
7089 gp
= lh
->u
.def
.value
;
7091 case bfd_link_hash_indirect
:
7092 case bfd_link_hash_warning
:
7094 /* @@FIXME ignoring warning for now */
7096 case bfd_link_hash_new
:
7105 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
7108 char *error_message
= (char *) NULL
;
7109 bfd_reloc_status_type r
;
7111 /* Specific to MIPS: Deal with relocation types that require
7112 knowing the gp of the output bfd. */
7113 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
7114 if (bfd_is_abs_section (sym
->section
) && abfd
)
7116 /* The special_function wouldn't get called anyways. */
7120 /* The gp isn't there; let the special function code
7121 fall over on its own. */
7123 else if ((*parent
)->howto
->special_function
7124 == _bfd_mips_elf_gprel16_reloc
)
7126 /* bypass special_function call */
7127 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
7128 relocateable
, (PTR
) data
, gp
);
7129 goto skip_bfd_perform_relocation
;
7131 /* end mips specific stuff */
7133 r
= bfd_perform_relocation (input_bfd
,
7137 relocateable
? abfd
: (bfd
*) NULL
,
7139 skip_bfd_perform_relocation
:
7143 asection
*os
= input_section
->output_section
;
7145 /* A partial link, so keep the relocs */
7146 os
->orelocation
[os
->reloc_count
] = *parent
;
7150 if (r
!= bfd_reloc_ok
)
7154 case bfd_reloc_undefined
:
7155 if (!((*link_info
->callbacks
->undefined_symbol
)
7156 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7157 input_bfd
, input_section
, (*parent
)->address
)))
7160 case bfd_reloc_dangerous
:
7161 BFD_ASSERT (error_message
!= (char *) NULL
);
7162 if (!((*link_info
->callbacks
->reloc_dangerous
)
7163 (link_info
, error_message
, input_bfd
, input_section
,
7164 (*parent
)->address
)))
7167 case bfd_reloc_overflow
:
7168 if (!((*link_info
->callbacks
->reloc_overflow
)
7169 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7170 (*parent
)->howto
->name
, (*parent
)->addend
,
7171 input_bfd
, input_section
, (*parent
)->address
)))
7174 case bfd_reloc_outofrange
:
7183 if (reloc_vector
!= NULL
)
7184 free (reloc_vector
);
7188 if (reloc_vector
!= NULL
)
7189 free (reloc_vector
);
7192 #define bfd_elf32_bfd_get_relocated_section_contents \
7193 elf32_mips_get_relocated_section_contents
7195 /* ECOFF swapping routines. These are used when dealing with the
7196 .mdebug section, which is in the ECOFF debugging format. */
7197 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
7199 /* Symbol table magic number. */
7201 /* Alignment of debugging information. E.g., 4. */
7203 /* Sizes of external symbolic information. */
7204 sizeof (struct hdr_ext
),
7205 sizeof (struct dnr_ext
),
7206 sizeof (struct pdr_ext
),
7207 sizeof (struct sym_ext
),
7208 sizeof (struct opt_ext
),
7209 sizeof (struct fdr_ext
),
7210 sizeof (struct rfd_ext
),
7211 sizeof (struct ext_ext
),
7212 /* Functions to swap in external symbolic data. */
7221 _bfd_ecoff_swap_tir_in
,
7222 _bfd_ecoff_swap_rndx_in
,
7223 /* Functions to swap out external symbolic data. */
7232 _bfd_ecoff_swap_tir_out
,
7233 _bfd_ecoff_swap_rndx_out
,
7234 /* Function to read in symbolic data. */
7235 _bfd_mips_elf_read_ecoff_info
7238 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
7239 #define TARGET_LITTLE_NAME "elf32-littlemips"
7240 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
7241 #define TARGET_BIG_NAME "elf32-bigmips"
7242 #define ELF_ARCH bfd_arch_mips
7243 #define ELF_MACHINE_CODE EM_MIPS
7245 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
7246 a value of 0x1000, and we are compatible. */
7247 #define ELF_MAXPAGESIZE 0x1000
7249 #define elf_backend_collect true
7250 #define elf_backend_type_change_ok true
7251 #define elf_info_to_howto 0
7252 #define elf_info_to_howto_rel mips_info_to_howto_rel
7253 #define elf_backend_sym_is_global mips_elf_sym_is_global
7254 #define elf_backend_object_p mips_elf32_object_p
7255 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
7256 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
7257 #define elf_backend_section_from_bfd_section \
7258 _bfd_mips_elf_section_from_bfd_section
7259 #define elf_backend_section_processing mips_elf32_section_processing
7260 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
7261 #define elf_backend_additional_program_headers \
7262 mips_elf_additional_program_headers
7263 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
7264 #define elf_backend_final_write_processing \
7265 _bfd_mips_elf_final_write_processing
7266 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
7268 #define bfd_elf32_bfd_is_local_label mips_elf_is_local_label
7269 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
7270 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
7271 #define bfd_elf32_bfd_link_hash_table_create \
7272 mips_elf_link_hash_table_create
7273 #define bfd_elf32_bfd_final_link mips_elf_final_link
7274 #define bfd_elf32_bfd_copy_private_bfd_data \
7275 _bfd_mips_elf_copy_private_bfd_data
7276 #define bfd_elf32_bfd_merge_private_bfd_data \
7277 _bfd_mips_elf_merge_private_bfd_data
7278 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
7279 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
7280 #define elf_backend_create_dynamic_sections \
7281 mips_elf_create_dynamic_sections
7282 #define elf_backend_check_relocs mips_elf_check_relocs
7283 #define elf_backend_adjust_dynamic_symbol \
7284 mips_elf_adjust_dynamic_symbol
7285 #define elf_backend_always_size_sections \
7286 mips_elf_always_size_sections
7287 #define elf_backend_size_dynamic_sections \
7288 mips_elf_size_dynamic_sections
7289 #define elf_backend_relocate_section mips_elf_relocate_section
7290 #define elf_backend_link_output_symbol_hook \
7291 mips_elf_link_output_symbol_hook
7292 #define elf_backend_finish_dynamic_symbol \
7293 mips_elf_finish_dynamic_symbol
7294 #define elf_backend_finish_dynamic_sections \
7295 mips_elf_finish_dynamic_sections
7297 #include "elf32-target.h"