1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 94, 95, 96, 97, 1998 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 INLINE
int elf_mips_mach
PARAMS ((flagword
));
63 static INLINE
char* elf_mips_abi_name
PARAMS ((flagword
));
64 static boolean mips_elf32_section_from_shdr
65 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, char *));
66 static boolean mips_elf32_section_processing
67 PARAMS ((bfd
*, Elf32_Internal_Shdr
*));
68 static boolean mips_elf_is_local_label_name
69 PARAMS ((bfd
*, const char *));
70 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
71 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
72 static struct bfd_link_hash_table
*mips_elf_link_hash_table_create
74 static int gptab_compare
PARAMS ((const void *, const void *));
75 static boolean mips_elf_final_link
76 PARAMS ((bfd
*, struct bfd_link_info
*));
77 static void mips_elf_relocate_hi16
78 PARAMS ((bfd
*, Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_byte
*,
80 static boolean mips_elf_relocate_got_local
81 PARAMS ((bfd
*, bfd
*, asection
*, Elf_Internal_Rela
*,
82 Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
83 static void mips_elf_relocate_global_got
84 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
85 static bfd_reloc_status_type mips16_jump_reloc
86 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
87 static bfd_reloc_status_type mips16_gprel_reloc
88 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
89 /* start-sanitize-sky */
90 static bfd_reloc_status_type dvp_u15_s3_reloc
91 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
92 /* end-sanitize-sky */
93 static boolean mips_elf_adjust_dynindx
94 PARAMS ((struct elf_link_hash_entry
*, PTR
));
95 static boolean mips_elf_relocate_section
96 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
97 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
98 static boolean mips_elf_link_output_symbol_hook
99 PARAMS ((bfd
*, struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
101 static boolean mips_elf_create_dynamic_sections
102 PARAMS ((bfd
*, struct bfd_link_info
*));
103 static boolean mips_elf_create_compact_rel_section
104 PARAMS ((bfd
*, struct bfd_link_info
*));
105 static boolean mips_elf_create_got_section
106 PARAMS ((bfd
*, struct bfd_link_info
*));
107 static boolean mips_elf_check_relocs
108 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
109 const Elf_Internal_Rela
*));
110 static boolean mips_elf_adjust_dynamic_symbol
111 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
112 static boolean mips_elf_always_size_sections
113 PARAMS ((bfd
*, struct bfd_link_info
*));
114 static boolean mips_elf_size_dynamic_sections
115 PARAMS ((bfd
*, struct bfd_link_info
*));
116 static boolean mips_elf_finish_dynamic_symbol
117 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
118 Elf_Internal_Sym
*));
119 static boolean mips_elf_finish_dynamic_sections
120 PARAMS ((bfd
*, struct bfd_link_info
*));
121 static boolean mips_elf_add_symbol_hook
122 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
123 const char **, flagword
*, asection
**, bfd_vma
*));
124 static bfd_reloc_status_type mips_elf_final_gp
125 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
126 static bfd_byte
*elf32_mips_get_relocated_section_contents
127 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
128 bfd_byte
*, boolean
, asymbol
**));
130 /* This is true for Irix 5 executables, false for normal MIPS ELF ABI
131 executables. FIXME: At the moment, we default to always generating
132 Irix 5 executables. */
134 #define SGI_COMPAT(abfd) (1)
136 /* This structure is used to hold .got information when linking. It
137 is stored in the tdata field of the bfd_elf_section_data structure. */
141 /* The symbol index of the first global .got symbol. */
142 unsigned long global_gotsym
;
143 /* The number of local .got entries. */
144 unsigned int local_gotno
;
145 /* The number of local .got entries we have used. */
146 unsigned int assigned_gotno
;
149 /* The number of local .got entries we reserve. */
150 #define MIPS_RESERVED_GOTNO (2)
152 /* Instructions which appear in a stub. For some reason the stub is
153 slightly different on an SGI system. */
154 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
155 #define STUB_LW(abfd) \
157 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
158 : 0x8f998000) /* lw t9,0x8000(gp) */
159 #define STUB_MOVE 0x03e07825 /* move t7,ra */
160 #define STUB_JALR 0x0320f809 /* jal t9 */
161 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
162 #define MIPS_FUNCTION_STUB_SIZE (16)
165 /* We no longer try to identify particular sections for the .dynsym
166 section. When we do, we wind up crashing if there are other random
167 sections with relocations. */
169 /* Names of sections which appear in the .dynsym section in an Irix 5
172 static const char * const mips_elf_dynsym_sec_names
[] =
185 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
186 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
188 /* The number of entries in mips_elf_dynsym_sec_names which go in the
191 #define MIPS_TEXT_DYNSYM_SECNO (3)
195 /* The names of the runtime procedure table symbols used on Irix 5. */
197 static const char * const mips_elf_dynsym_rtproc_names
[] =
200 "_procedure_string_table",
201 "_procedure_table_size",
205 /* These structures are used to generate the .compact_rel section on
210 unsigned long id1
; /* Always one? */
211 unsigned long num
; /* Number of compact relocation entries. */
212 unsigned long id2
; /* Always two? */
213 unsigned long offset
; /* The file offset of the first relocation. */
214 unsigned long reserved0
; /* Zero? */
215 unsigned long reserved1
; /* Zero? */
224 bfd_byte reserved0
[4];
225 bfd_byte reserved1
[4];
226 } Elf32_External_compact_rel
;
230 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
231 unsigned int rtype
: 4; /* Relocation types. See below. */
232 unsigned int dist2to
: 8;
233 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
234 unsigned long konst
; /* KONST field. See below. */
235 unsigned long vaddr
; /* VADDR to be relocated. */
240 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
241 unsigned int rtype
: 4; /* Relocation types. See below. */
242 unsigned int dist2to
: 8;
243 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
244 unsigned long konst
; /* KONST field. See below. */
252 } Elf32_External_crinfo
;
258 } Elf32_External_crinfo2
;
260 /* These are the constants used to swap the bitfields in a crinfo. */
262 #define CRINFO_CTYPE (0x1)
263 #define CRINFO_CTYPE_SH (31)
264 #define CRINFO_RTYPE (0xf)
265 #define CRINFO_RTYPE_SH (27)
266 #define CRINFO_DIST2TO (0xff)
267 #define CRINFO_DIST2TO_SH (19)
268 #define CRINFO_RELVADDR (0x7ffff)
269 #define CRINFO_RELVADDR_SH (0)
271 /* A compact relocation info has long (3 words) or short (2 words)
272 formats. A short format doesn't have VADDR field and relvaddr
273 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
274 #define CRF_MIPS_LONG 1
275 #define CRF_MIPS_SHORT 0
277 /* There are 4 types of compact relocation at least. The value KONST
278 has different meaning for each type:
281 CT_MIPS_REL32 Address in data
282 CT_MIPS_WORD Address in word (XXX)
283 CT_MIPS_GPHI_LO GP - vaddr
284 CT_MIPS_JMPAD Address to jump
287 #define CRT_MIPS_REL32 0xa
288 #define CRT_MIPS_WORD 0xb
289 #define CRT_MIPS_GPHI_LO 0xc
290 #define CRT_MIPS_JMPAD 0xd
292 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
293 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
294 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
295 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
297 static void bfd_elf32_swap_compact_rel_out
298 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
299 static void bfd_elf32_swap_crinfo_out
300 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
302 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
304 static reloc_howto_type elf_mips_howto_table
[] =
307 HOWTO (R_MIPS_NONE
, /* type */
309 0, /* size (0 = byte, 1 = short, 2 = long) */
311 false, /* pc_relative */
313 complain_overflow_dont
, /* complain_on_overflow */
314 bfd_elf_generic_reloc
, /* special_function */
315 "R_MIPS_NONE", /* name */
316 false, /* partial_inplace */
319 false), /* pcrel_offset */
321 /* 16 bit relocation. */
322 HOWTO (R_MIPS_16
, /* type */
324 1, /* size (0 = byte, 1 = short, 2 = long) */
326 false, /* pc_relative */
328 complain_overflow_bitfield
, /* complain_on_overflow */
329 bfd_elf_generic_reloc
, /* special_function */
330 "R_MIPS_16", /* name */
331 true, /* partial_inplace */
332 0xffff, /* src_mask */
333 0xffff, /* dst_mask */
334 false), /* pcrel_offset */
336 /* 32 bit relocation. */
337 HOWTO (R_MIPS_32
, /* type */
339 2, /* size (0 = byte, 1 = short, 2 = long) */
341 false, /* pc_relative */
343 complain_overflow_bitfield
, /* complain_on_overflow */
344 bfd_elf_generic_reloc
, /* special_function */
345 "R_MIPS_32", /* name */
346 true, /* partial_inplace */
347 0xffffffff, /* src_mask */
348 0xffffffff, /* dst_mask */
349 false), /* pcrel_offset */
351 /* 32 bit symbol relative relocation. */
352 HOWTO (R_MIPS_REL32
, /* type */
354 2, /* size (0 = byte, 1 = short, 2 = long) */
356 false, /* pc_relative */
358 complain_overflow_bitfield
, /* complain_on_overflow */
359 bfd_elf_generic_reloc
, /* special_function */
360 "R_MIPS_REL32", /* name */
361 true, /* partial_inplace */
362 0xffffffff, /* src_mask */
363 0xffffffff, /* dst_mask */
364 false), /* pcrel_offset */
366 /* 26 bit branch address. */
367 HOWTO (R_MIPS_26
, /* type */
369 2, /* size (0 = byte, 1 = short, 2 = long) */
371 false, /* pc_relative */
373 complain_overflow_dont
, /* complain_on_overflow */
374 /* This needs complex overflow
375 detection, because the upper four
376 bits must match the PC. */
377 bfd_elf_generic_reloc
, /* special_function */
378 "R_MIPS_26", /* name */
379 true, /* partial_inplace */
380 0x3ffffff, /* src_mask */
381 0x3ffffff, /* dst_mask */
382 false), /* pcrel_offset */
384 /* High 16 bits of symbol value. */
385 HOWTO (R_MIPS_HI16
, /* type */
387 2, /* size (0 = byte, 1 = short, 2 = long) */
389 false, /* pc_relative */
391 complain_overflow_dont
, /* complain_on_overflow */
392 _bfd_mips_elf_hi16_reloc
, /* special_function */
393 "R_MIPS_HI16", /* name */
394 true, /* partial_inplace */
395 0xffff, /* src_mask */
396 0xffff, /* dst_mask */
397 false), /* pcrel_offset */
399 /* Low 16 bits of symbol value. */
400 HOWTO (R_MIPS_LO16
, /* type */
402 2, /* size (0 = byte, 1 = short, 2 = long) */
404 false, /* pc_relative */
406 complain_overflow_dont
, /* complain_on_overflow */
407 _bfd_mips_elf_lo16_reloc
, /* special_function */
408 "R_MIPS_LO16", /* name */
409 true, /* partial_inplace */
410 0xffff, /* src_mask */
411 0xffff, /* dst_mask */
412 false), /* pcrel_offset */
414 /* GP relative reference. */
415 HOWTO (R_MIPS_GPREL16
, /* type */
417 2, /* size (0 = byte, 1 = short, 2 = long) */
419 false, /* pc_relative */
421 complain_overflow_signed
, /* complain_on_overflow */
422 _bfd_mips_elf_gprel16_reloc
, /* special_function */
423 "R_MIPS_GPREL16", /* name */
424 true, /* partial_inplace */
425 0xffff, /* src_mask */
426 0xffff, /* dst_mask */
427 false), /* pcrel_offset */
429 /* Reference to literal section. */
430 HOWTO (R_MIPS_LITERAL
, /* type */
432 2, /* size (0 = byte, 1 = short, 2 = long) */
434 false, /* pc_relative */
436 complain_overflow_signed
, /* complain_on_overflow */
437 _bfd_mips_elf_gprel16_reloc
, /* special_function */
438 "R_MIPS_LITERAL", /* name */
439 true, /* partial_inplace */
440 0xffff, /* src_mask */
441 0xffff, /* dst_mask */
442 false), /* pcrel_offset */
444 /* Reference to global offset table. */
445 HOWTO (R_MIPS_GOT16
, /* type */
447 2, /* size (0 = byte, 1 = short, 2 = long) */
449 false, /* pc_relative */
451 complain_overflow_signed
, /* complain_on_overflow */
452 _bfd_mips_elf_got16_reloc
, /* special_function */
453 "R_MIPS_GOT16", /* name */
454 false, /* partial_inplace */
456 0xffff, /* dst_mask */
457 false), /* pcrel_offset */
459 /* 16 bit PC relative reference. */
460 HOWTO (R_MIPS_PC16
, /* type */
462 2, /* size (0 = byte, 1 = short, 2 = long) */
464 true, /* pc_relative */
466 complain_overflow_signed
, /* complain_on_overflow */
467 bfd_elf_generic_reloc
, /* special_function */
468 "R_MIPS_PC16", /* name */
469 true, /* partial_inplace */
470 0xffff, /* src_mask */
471 0xffff, /* dst_mask */
472 false), /* pcrel_offset */
474 /* 16 bit call through global offset table. */
475 /* FIXME: This is not handled correctly. */
476 HOWTO (R_MIPS_CALL16
, /* type */
478 2, /* size (0 = byte, 1 = short, 2 = long) */
480 false, /* pc_relative */
482 complain_overflow_signed
, /* complain_on_overflow */
483 bfd_elf_generic_reloc
, /* special_function */
484 "R_MIPS_CALL16", /* name */
485 false, /* partial_inplace */
487 0xffff, /* dst_mask */
488 false), /* pcrel_offset */
490 /* 32 bit GP relative reference. */
491 HOWTO (R_MIPS_GPREL32
, /* type */
493 2, /* size (0 = byte, 1 = short, 2 = long) */
495 false, /* pc_relative */
497 complain_overflow_bitfield
, /* complain_on_overflow */
498 _bfd_mips_elf_gprel32_reloc
, /* special_function */
499 "R_MIPS_GPREL32", /* name */
500 true, /* partial_inplace */
501 0xffffffff, /* src_mask */
502 0xffffffff, /* dst_mask */
503 false), /* pcrel_offset */
505 /* The remaining relocs are defined on Irix 5, although they are
506 not defined by the ABI. */
511 /* A 5 bit shift field. */
512 HOWTO (R_MIPS_SHIFT5
, /* type */
514 2, /* size (0 = byte, 1 = short, 2 = long) */
516 false, /* pc_relative */
518 complain_overflow_bitfield
, /* complain_on_overflow */
519 bfd_elf_generic_reloc
, /* special_function */
520 "R_MIPS_SHIFT5", /* name */
521 true, /* partial_inplace */
522 0x000007c0, /* src_mask */
523 0x000007c0, /* dst_mask */
524 false), /* pcrel_offset */
526 /* A 6 bit shift field. */
527 /* FIXME: This is not handled correctly; a special function is
528 needed to put the most significant bit in the right place. */
529 HOWTO (R_MIPS_SHIFT6
, /* type */
531 2, /* size (0 = byte, 1 = short, 2 = long) */
533 false, /* pc_relative */
535 complain_overflow_bitfield
, /* complain_on_overflow */
536 bfd_elf_generic_reloc
, /* special_function */
537 "R_MIPS_SHIFT6", /* name */
538 true, /* partial_inplace */
539 0x000007c4, /* src_mask */
540 0x000007c4, /* dst_mask */
541 false), /* pcrel_offset */
543 /* A 64 bit relocation. This is used in 32 bit ELF when addresses
544 are 64 bits long; the upper 32 bits are simply a sign extension.
545 The fields of the howto should be the same as for R_MIPS_32,
546 other than the type, name, and special_function. */
547 HOWTO (R_MIPS_64
, /* type */
549 2, /* size (0 = byte, 1 = short, 2 = long) */
551 false, /* pc_relative */
553 complain_overflow_bitfield
, /* complain_on_overflow */
554 mips32_64bit_reloc
, /* special_function */
555 "R_MIPS_64", /* name */
556 true, /* partial_inplace */
557 0xffffffff, /* src_mask */
558 0xffffffff, /* dst_mask */
559 false), /* pcrel_offset */
561 /* Displacement in the global offset table. */
562 /* FIXME: Not handled correctly. */
563 HOWTO (R_MIPS_GOT_DISP
, /* type */
565 2, /* size (0 = byte, 1 = short, 2 = long) */
567 false, /* pc_relative */
569 complain_overflow_bitfield
, /* complain_on_overflow */
570 bfd_elf_generic_reloc
, /* special_function */
571 "R_MIPS_GOT_DISP", /* name */
572 true, /* partial_inplace */
573 0x0000ffff, /* src_mask */
574 0x0000ffff, /* dst_mask */
575 false), /* pcrel_offset */
577 /* Displacement to page pointer in the global offset table. */
578 /* FIXME: Not handled correctly. */
579 HOWTO (R_MIPS_GOT_PAGE
, /* type */
581 2, /* size (0 = byte, 1 = short, 2 = long) */
583 false, /* pc_relative */
585 complain_overflow_bitfield
, /* complain_on_overflow */
586 bfd_elf_generic_reloc
, /* special_function */
587 "R_MIPS_GOT_PAGE", /* name */
588 true, /* partial_inplace */
589 0x0000ffff, /* src_mask */
590 0x0000ffff, /* dst_mask */
591 false), /* pcrel_offset */
593 /* Offset from page pointer in the global offset table. */
594 /* FIXME: Not handled correctly. */
595 HOWTO (R_MIPS_GOT_OFST
, /* type */
597 2, /* size (0 = byte, 1 = short, 2 = long) */
599 false, /* pc_relative */
601 complain_overflow_bitfield
, /* complain_on_overflow */
602 bfd_elf_generic_reloc
, /* special_function */
603 "R_MIPS_GOT_OFST", /* name */
604 true, /* partial_inplace */
605 0x0000ffff, /* src_mask */
606 0x0000ffff, /* dst_mask */
607 false), /* pcrel_offset */
609 /* High 16 bits of displacement in global offset table. */
610 /* FIXME: Not handled correctly. */
611 HOWTO (R_MIPS_GOT_HI16
, /* type */
613 2, /* size (0 = byte, 1 = short, 2 = long) */
615 false, /* pc_relative */
617 complain_overflow_dont
, /* complain_on_overflow */
618 bfd_elf_generic_reloc
, /* special_function */
619 "R_MIPS_GOT_HI16", /* name */
620 true, /* partial_inplace */
621 0x0000ffff, /* src_mask */
622 0x0000ffff, /* dst_mask */
623 false), /* pcrel_offset */
625 /* Low 16 bits of displacement in global offset table. */
626 /* FIXME: Not handled correctly. */
627 HOWTO (R_MIPS_GOT_LO16
, /* type */
629 2, /* size (0 = byte, 1 = short, 2 = long) */
631 false, /* pc_relative */
633 complain_overflow_dont
, /* complain_on_overflow */
634 bfd_elf_generic_reloc
, /* special_function */
635 "R_MIPS_GOT_LO16", /* name */
636 true, /* partial_inplace */
637 0x0000ffff, /* src_mask */
638 0x0000ffff, /* dst_mask */
639 false), /* pcrel_offset */
641 /* 64 bit subtraction. Presumably not used in 32 bit ELF. */
644 /* Used to cause the linker to insert and delete instructions? */
649 /* Get the higher values of a 64 bit addend. Presumably not used in
654 /* High 16 bits of displacement in global offset table. */
655 /* FIXME: Not handled correctly. */
656 HOWTO (R_MIPS_CALL_HI16
, /* type */
658 2, /* size (0 = byte, 1 = short, 2 = long) */
660 false, /* pc_relative */
662 complain_overflow_dont
, /* complain_on_overflow */
663 bfd_elf_generic_reloc
, /* special_function */
664 "R_MIPS_CALL_HI16", /* name */
665 true, /* partial_inplace */
666 0x0000ffff, /* src_mask */
667 0x0000ffff, /* dst_mask */
668 false), /* pcrel_offset */
670 /* Low 16 bits of displacement in global offset table. */
671 /* FIXME: Not handled correctly. */
672 HOWTO (R_MIPS_CALL_LO16
, /* type */
674 2, /* size (0 = byte, 1 = short, 2 = long) */
676 false, /* pc_relative */
678 complain_overflow_dont
, /* complain_on_overflow */
679 bfd_elf_generic_reloc
, /* special_function */
680 "R_MIPS_CALL_LO16", /* name */
681 true, /* partial_inplace */
682 0x0000ffff, /* src_mask */
683 0x0000ffff, /* dst_mask */
684 false), /* pcrel_offset */
688 { R_MIPS_ADD_IMMEDIATE
},
693 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
694 is a hack to make the linker think that we need 64 bit values. */
695 static reloc_howto_type elf_mips_ctor64_howto
=
696 HOWTO (R_MIPS_64
, /* type */
698 4, /* size (0 = byte, 1 = short, 2 = long) */
700 false, /* pc_relative */
702 complain_overflow_signed
, /* complain_on_overflow */
703 mips32_64bit_reloc
, /* special_function */
704 "R_MIPS_64", /* name */
705 true, /* partial_inplace */
706 0xffffffff, /* src_mask */
707 0xffffffff, /* dst_mask */
708 false); /* pcrel_offset */
710 /* The reloc used for the mips16 jump instruction. */
711 static reloc_howto_type elf_mips16_jump_howto
=
712 HOWTO (R_MIPS16_26
, /* type */
714 2, /* size (0 = byte, 1 = short, 2 = long) */
716 false, /* pc_relative */
718 complain_overflow_dont
, /* complain_on_overflow */
719 /* This needs complex overflow
720 detection, because the upper four
721 bits must match the PC. */
722 mips16_jump_reloc
, /* special_function */
723 "R_MIPS16_26", /* name */
724 true, /* partial_inplace */
725 0x3ffffff, /* src_mask */
726 0x3ffffff, /* dst_mask */
727 false); /* pcrel_offset */
729 /* The reloc used for the mips16 gprel instruction. The src_mask and
730 dsk_mask for this howto do not reflect the actual instruction, in
731 which the value is not contiguous; the masks are for the
732 convenience of the relocate_section routine. */
733 static reloc_howto_type elf_mips16_gprel_howto
=
734 HOWTO (R_MIPS16_GPREL
, /* type */
736 2, /* size (0 = byte, 1 = short, 2 = long) */
738 false, /* pc_relative */
740 complain_overflow_signed
, /* complain_on_overflow */
741 mips16_gprel_reloc
, /* special_function */
742 "R_MIPS16_GPREL", /* name */
743 true, /* partial_inplace */
744 0xffff, /* src_mask */
745 0xffff, /* dst_mask */
746 false); /* pcrel_offset */
748 /* start-sanitize-r5900 */
749 static reloc_howto_type elf_mips15_s3_howto
=
750 HOWTO (R_MIPS15_S3
, /* type */
752 2, /* size (0 = byte, 1 = short, 2 = long) */
754 false, /* pc_relative */
756 complain_overflow_bitfield
, /* complain_on_overflow */
757 bfd_elf_generic_reloc
, /* special_function */
758 "R_MIPS15_S3", /* name */
759 true, /* partial_inplace */
760 0x001fffc0, /* src_mask */
761 0x001fffc0, /* dst_mask */
762 false); /* pcrel_offset */
764 /* end-sanitize-r5900 */
765 /* start-sanitize-sky */
767 Note that partial_inplace and pcrel_offset are backwards from the
768 mips port. This is intentional as it seems more reasonable. */
769 static reloc_howto_type elf_mips_dvp_11_pcrel_howto
=
770 HOWTO (R_MIPS_DVP_11_PCREL
, /* type */
772 2, /* size (0 = byte, 1 = short, 2 = long) */
774 true, /* pc_relative */
776 complain_overflow_signed
, /* complain_on_overflow */
777 bfd_elf_generic_reloc
, /* special_function */
778 "R_MIPS_DVP_11_PCREL", /* name */
779 false, /* partial_inplace */
780 0x7ff, /* src_mask */
781 0x7ff, /* dst_mask */
782 true); /* pcrel_offset */
783 static reloc_howto_type elf_mips_dvp_27_s4_howto
=
784 HOWTO (R_MIPS_DVP_27_S4
, /* type */
786 2, /* size (0 = byte, 1 = short, 2 = long) */
788 false, /* pc_relative */
790 complain_overflow_unsigned
, /* complain_on_overflow */
791 bfd_elf_generic_reloc
, /* special_function */
792 "R_MIPS_DVP_27_S4", /* name */
793 false, /* partial_inplace */
794 0x7ffffff0, /* src_mask */
795 0x7ffffff0, /* dst_mask */
796 false); /* pcrel_offset */
797 static reloc_howto_type elf_mips_dvp_11_s4_howto
=
798 HOWTO (R_MIPS_DVP_11_S4
, /* type */
800 2, /* size (0 = byte, 1 = short, 2 = long) */
802 false, /* pc_relative */
804 complain_overflow_signed
, /* complain_on_overflow */
805 bfd_elf_generic_reloc
, /* special_function */
806 "R_MIPS_DVP_11_S4", /* name */
807 false, /* partial_inplace */
808 0x03ff, /* src_mask */
809 0x03ff, /* dst_mask */
810 false); /* pcrel_offset */
811 static reloc_howto_type elf_mips_dvp_u15_s3_howto
=
812 HOWTO (R_MIPS_DVP_U15_S3
, /* type */
814 2, /* size (0 = byte, 1 = short, 2 = long) */
816 false, /* pc_relative */
818 complain_overflow_unsigned
, /* complain_on_overflow */
819 dvp_u15_s3_reloc
, /* special_function */
820 "R_MIPS_DVP_U15_S3", /* name */
821 false, /* partial_inplace */
822 0xf03ff, /* src_mask */
823 0xf03ff, /* dst_mask */
824 false); /* pcrel_offset */
825 /* end-sanitize-sky */
827 /* GNU extension to record C++ vtable hierarchy */
828 static reloc_howto_type elf_mips_gnu_vtinherit_howto
=
829 HOWTO (R_MIPS_GNU_VTINHERIT
, /* type */
831 2, /* size (0 = byte, 1 = short, 2 = long) */
833 false, /* pc_relative */
835 complain_overflow_dont
, /* complain_on_overflow */
836 NULL
, /* special_function */
837 "R_MIPS_GNU_VTINHERIT", /* name */
838 false, /* partial_inplace */
841 false); /* pcrel_offset */
843 /* GNU extension to record C++ vtable member usage */
844 static reloc_howto_type elf_mips_gnu_vtentry_howto
=
845 HOWTO (R_MIPS_GNU_VTENTRY
, /* type */
847 2, /* size (0 = byte, 1 = short, 2 = long) */
849 false, /* pc_relative */
851 complain_overflow_dont
, /* complain_on_overflow */
852 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
853 "R_MIPS_GNU_VTENTRY", /* name */
854 false, /* partial_inplace */
857 false); /* pcrel_offset */
859 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
860 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
861 the HI16. Here we just save the information we need; we do the
862 actual relocation when we see the LO16. MIPS ELF requires that the
863 LO16 immediately follow the HI16. As a GNU extension, we permit an
864 arbitrary number of HI16 relocs to be associated with a single LO16
865 reloc. This extension permits gcc to output the HI and LO relocs
870 struct mips_hi16
*next
;
875 /* FIXME: This should not be a static variable. */
877 static struct mips_hi16
*mips_hi16_list
;
879 bfd_reloc_status_type
880 _bfd_mips_elf_hi16_reloc (abfd
,
888 arelent
*reloc_entry
;
891 asection
*input_section
;
893 char **error_message
;
895 bfd_reloc_status_type ret
;
899 /* If we're relocating, and this an external symbol, we don't want
900 to change anything. */
901 if (output_bfd
!= (bfd
*) NULL
902 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
903 && reloc_entry
->addend
== 0)
905 reloc_entry
->address
+= input_section
->output_offset
;
911 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
913 boolean relocateable
;
916 if (ret
== bfd_reloc_undefined
)
919 if (output_bfd
!= NULL
)
923 relocateable
= false;
924 output_bfd
= symbol
->section
->output_section
->owner
;
927 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
929 if (ret
!= bfd_reloc_ok
)
932 relocation
= gp
- reloc_entry
->address
;
936 if (bfd_is_und_section (symbol
->section
)
937 && output_bfd
== (bfd
*) NULL
)
938 ret
= bfd_reloc_undefined
;
940 if (bfd_is_com_section (symbol
->section
))
943 relocation
= symbol
->value
;
946 relocation
+= symbol
->section
->output_section
->vma
;
947 relocation
+= symbol
->section
->output_offset
;
948 relocation
+= reloc_entry
->addend
;
950 if (reloc_entry
->address
> input_section
->_cooked_size
)
951 return bfd_reloc_outofrange
;
953 /* Save the information, and let LO16 do the actual relocation. */
954 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
956 return bfd_reloc_outofrange
;
957 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
958 n
->addend
= relocation
;
959 n
->next
= mips_hi16_list
;
962 if (output_bfd
!= (bfd
*) NULL
)
963 reloc_entry
->address
+= input_section
->output_offset
;
968 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
969 inplace relocation; this function exists in order to do the
970 R_MIPS_HI16 relocation described above. */
972 bfd_reloc_status_type
973 _bfd_mips_elf_lo16_reloc (abfd
,
981 arelent
*reloc_entry
;
984 asection
*input_section
;
986 char **error_message
;
988 arelent gp_disp_relent
;
990 if (mips_hi16_list
!= NULL
)
1000 struct mips_hi16
*next
;
1002 /* Do the HI16 relocation. Note that we actually don't need
1003 to know anything about the LO16 itself, except where to
1004 find the low 16 bits of the addend needed by the LO16. */
1005 insn
= bfd_get_32 (abfd
, l
->addr
);
1006 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
1008 val
= ((insn
& 0xffff) << 16) + vallo
;
1011 /* The low order 16 bits are always treated as a signed
1012 value. Therefore, a negative value in the low order bits
1013 requires an adjustment in the high order bits. We need
1014 to make this adjustment in two ways: once for the bits we
1015 took from the data, and once for the bits we are putting
1016 back in to the data. */
1017 if ((vallo
& 0x8000) != 0)
1019 if ((val
& 0x8000) != 0)
1022 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
1023 bfd_put_32 (abfd
, insn
, l
->addr
);
1025 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1027 gp_disp_relent
= *reloc_entry
;
1028 reloc_entry
= &gp_disp_relent
;
1029 reloc_entry
->addend
= l
->addend
;
1037 mips_hi16_list
= NULL
;
1039 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1041 bfd_reloc_status_type ret
;
1042 bfd_vma gp
, relocation
;
1044 /* FIXME: Does this case ever occur? */
1046 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
1047 if (ret
!= bfd_reloc_ok
)
1050 relocation
= gp
- reloc_entry
->address
;
1051 relocation
+= symbol
->section
->output_section
->vma
;
1052 relocation
+= symbol
->section
->output_offset
;
1053 relocation
+= reloc_entry
->addend
;
1055 if (reloc_entry
->address
> input_section
->_cooked_size
)
1056 return bfd_reloc_outofrange
;
1058 gp_disp_relent
= *reloc_entry
;
1059 reloc_entry
= &gp_disp_relent
;
1060 reloc_entry
->addend
= relocation
- 4;
1063 /* Now do the LO16 reloc in the usual way. */
1064 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1065 input_section
, output_bfd
, error_message
);
1068 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1069 table used for PIC code. If the symbol is an external symbol, the
1070 instruction is modified to contain the offset of the appropriate
1071 entry in the global offset table. If the symbol is a section
1072 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1073 addends are combined to form the real addend against the section
1074 symbol; the GOT16 is modified to contain the offset of an entry in
1075 the global offset table, and the LO16 is modified to offset it
1076 appropriately. Thus an offset larger than 16 bits requires a
1077 modified value in the global offset table.
1079 This implementation suffices for the assembler, but the linker does
1080 not yet know how to create global offset tables. */
1082 bfd_reloc_status_type
1083 _bfd_mips_elf_got16_reloc (abfd
,
1091 arelent
*reloc_entry
;
1094 asection
*input_section
;
1096 char **error_message
;
1098 /* If we're relocating, and this an external symbol, we don't want
1099 to change anything. */
1100 if (output_bfd
!= (bfd
*) NULL
1101 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1102 && reloc_entry
->addend
== 0)
1104 reloc_entry
->address
+= input_section
->output_offset
;
1105 return bfd_reloc_ok
;
1108 /* If we're relocating, and this is a local symbol, we can handle it
1110 if (output_bfd
!= (bfd
*) NULL
1111 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1112 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1113 input_section
, output_bfd
, error_message
);
1118 /* We have to figure out the gp value, so that we can adjust the
1119 symbol value correctly. We look up the symbol _gp in the output
1120 BFD. If we can't find it, we're stuck. We cache it in the ELF
1121 target data. We don't need to adjust the symbol value for an
1122 external symbol if we are producing relocateable output. */
1124 static bfd_reloc_status_type
1125 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1128 boolean relocateable
;
1129 char **error_message
;
1132 if (bfd_is_und_section (symbol
->section
)
1136 return bfd_reloc_undefined
;
1139 *pgp
= _bfd_get_gp_value (output_bfd
);
1142 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1146 /* Make up a value. */
1147 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1148 _bfd_set_gp_value (output_bfd
, *pgp
);
1156 count
= bfd_get_symcount (output_bfd
);
1157 sym
= bfd_get_outsymbols (output_bfd
);
1159 if (sym
== (asymbol
**) NULL
)
1163 for (i
= 0; i
< count
; i
++, sym
++)
1165 register CONST
char *name
;
1167 name
= bfd_asymbol_name (*sym
);
1168 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1170 *pgp
= bfd_asymbol_value (*sym
);
1171 _bfd_set_gp_value (output_bfd
, *pgp
);
1179 /* Only get the error once. */
1181 _bfd_set_gp_value (output_bfd
, *pgp
);
1183 (char *) _("GP relative relocation when _gp not defined");
1184 return bfd_reloc_dangerous
;
1189 return bfd_reloc_ok
;
1192 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1193 become the offset from the gp register. This function also handles
1194 R_MIPS_LITERAL relocations, although those can be handled more
1195 cleverly because the entries in the .lit8 and .lit4 sections can be
1198 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1199 arelent
*, asection
*,
1200 boolean
, PTR
, bfd_vma
));
1202 bfd_reloc_status_type
1203 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1204 output_bfd
, error_message
)
1206 arelent
*reloc_entry
;
1209 asection
*input_section
;
1211 char **error_message
;
1213 boolean relocateable
;
1214 bfd_reloc_status_type ret
;
1217 /* If we're relocating, and this is an external symbol with no
1218 addend, we don't want to change anything. We will only have an
1219 addend if this is a newly created reloc, not read from an ELF
1221 if (output_bfd
!= (bfd
*) NULL
1222 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1223 && reloc_entry
->addend
== 0)
1225 reloc_entry
->address
+= input_section
->output_offset
;
1226 return bfd_reloc_ok
;
1229 if (output_bfd
!= (bfd
*) NULL
)
1230 relocateable
= true;
1233 relocateable
= false;
1234 output_bfd
= symbol
->section
->output_section
->owner
;
1237 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1239 if (ret
!= bfd_reloc_ok
)
1242 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1243 relocateable
, data
, gp
);
1246 static bfd_reloc_status_type
1247 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1251 arelent
*reloc_entry
;
1252 asection
*input_section
;
1253 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 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1274 /* Set val to the offset into the section or symbol. */
1275 if (reloc_entry
->howto
->src_mask
== 0)
1277 /* This case occurs with the 64-bit MIPS ELF ABI. */
1278 val
= reloc_entry
->addend
;
1282 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1287 /* Adjust val for the final section location and GP value. If we
1288 are producing relocateable output, we don't want to do this for
1289 an external symbol. */
1291 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1292 val
+= relocation
- gp
;
1294 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1295 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1298 reloc_entry
->address
+= input_section
->output_offset
;
1300 /* Make sure it fit in 16 bits. */
1301 if (val
>= 0x8000 && val
< 0xffff8000)
1302 return bfd_reloc_overflow
;
1304 return bfd_reloc_ok
;
1307 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1308 from the gp register? XXX */
1310 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1311 arelent
*, asection
*,
1312 boolean
, PTR
, bfd_vma
));
1314 bfd_reloc_status_type
1315 _bfd_mips_elf_gprel32_reloc (abfd
,
1323 arelent
*reloc_entry
;
1326 asection
*input_section
;
1328 char **error_message
;
1330 boolean relocateable
;
1331 bfd_reloc_status_type ret
;
1334 /* If we're relocating, and this is an external symbol with no
1335 addend, we don't want to change anything. We will only have an
1336 addend if this is a newly created reloc, not read from an ELF
1338 if (output_bfd
!= (bfd
*) NULL
1339 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1340 && reloc_entry
->addend
== 0)
1342 *error_message
= (char *)
1343 _("32bits gp relative relocation occurs for an external symbol");
1344 return bfd_reloc_outofrange
;
1347 if (output_bfd
!= (bfd
*) NULL
)
1349 relocateable
= true;
1350 gp
= _bfd_get_gp_value (output_bfd
);
1354 relocateable
= false;
1355 output_bfd
= symbol
->section
->output_section
->owner
;
1357 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1358 error_message
, &gp
);
1359 if (ret
!= bfd_reloc_ok
)
1363 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1364 relocateable
, data
, gp
);
1367 static bfd_reloc_status_type
1368 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1372 arelent
*reloc_entry
;
1373 asection
*input_section
;
1374 boolean relocateable
;
1381 if (bfd_is_com_section (symbol
->section
))
1384 relocation
= symbol
->value
;
1386 relocation
+= symbol
->section
->output_section
->vma
;
1387 relocation
+= symbol
->section
->output_offset
;
1389 if (reloc_entry
->address
> input_section
->_cooked_size
)
1390 return bfd_reloc_outofrange
;
1392 if (reloc_entry
->howto
->src_mask
== 0)
1394 /* This case arises with the 64-bit MIPS ELF ABI. */
1398 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1400 /* Set val to the offset into the section or symbol. */
1401 val
+= reloc_entry
->addend
;
1403 /* Adjust val for the final section location and GP value. If we
1404 are producing relocateable output, we don't want to do this for
1405 an external symbol. */
1407 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1408 val
+= relocation
- gp
;
1410 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1413 reloc_entry
->address
+= input_section
->output_offset
;
1415 return bfd_reloc_ok
;
1418 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1419 generated when addreses are 64 bits. The upper 32 bits are a simle
1422 static bfd_reloc_status_type
1423 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1424 output_bfd
, error_message
)
1426 arelent
*reloc_entry
;
1429 asection
*input_section
;
1431 char **error_message
;
1433 bfd_reloc_status_type r
;
1438 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1439 input_section
, output_bfd
, error_message
);
1440 if (r
!= bfd_reloc_continue
)
1443 /* Do a normal 32 bit relocation on the lower 32 bits. */
1444 reloc32
= *reloc_entry
;
1445 if (bfd_big_endian (abfd
))
1446 reloc32
.address
+= 4;
1447 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1448 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1449 output_bfd
, error_message
);
1451 /* Sign extend into the upper 32 bits. */
1452 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1453 if ((val
& 0x80000000) != 0)
1457 addr
= reloc_entry
->address
;
1458 if (bfd_little_endian (abfd
))
1460 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1465 /* Handle a mips16 jump. */
1467 static bfd_reloc_status_type
1468 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1469 output_bfd
, error_message
)
1471 arelent
*reloc_entry
;
1474 asection
*input_section
;
1476 char **error_message
;
1478 if (output_bfd
!= (bfd
*) NULL
1479 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1480 && reloc_entry
->addend
== 0)
1482 reloc_entry
->address
+= input_section
->output_offset
;
1483 return bfd_reloc_ok
;
1488 static boolean warned
;
1491 (*_bfd_error_handler
)
1492 (_("Linking mips16 objects into %s format is not supported"),
1493 bfd_get_target (input_section
->output_section
->owner
));
1497 return bfd_reloc_undefined
;
1500 /* Handle a mips16 GP relative reloc. */
1502 static bfd_reloc_status_type
1503 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1504 output_bfd
, error_message
)
1506 arelent
*reloc_entry
;
1509 asection
*input_section
;
1511 char **error_message
;
1513 boolean relocateable
;
1514 bfd_reloc_status_type ret
;
1516 unsigned short extend
, insn
;
1517 unsigned long final
;
1519 /* If we're relocating, and this is an external symbol with no
1520 addend, we don't want to change anything. We will only have an
1521 addend if this is a newly created reloc, not read from an ELF
1523 if (output_bfd
!= NULL
1524 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1525 && reloc_entry
->addend
== 0)
1527 reloc_entry
->address
+= input_section
->output_offset
;
1528 return bfd_reloc_ok
;
1531 if (output_bfd
!= NULL
)
1532 relocateable
= true;
1535 relocateable
= false;
1536 output_bfd
= symbol
->section
->output_section
->owner
;
1539 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1541 if (ret
!= bfd_reloc_ok
)
1544 if (reloc_entry
->address
> input_section
->_cooked_size
)
1545 return bfd_reloc_outofrange
;
1547 /* Pick up the mips16 extend instruction and the real instruction. */
1548 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1549 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1551 /* Stuff the current addend back as a 32 bit value, do the usual
1552 relocation, and then clean up. */
1554 (((extend
& 0x1f) << 11)
1557 (bfd_byte
*) data
+ reloc_entry
->address
);
1559 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1560 relocateable
, data
, gp
);
1562 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1565 | ((final
>> 11) & 0x1f)
1567 (bfd_byte
*) data
+ reloc_entry
->address
);
1571 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1576 /* start-sanitize-sky */
1577 /* Handle a dvp R_MIPS_DVP_U15_S3 reloc.
1578 This is needed because the bits aren't contiguous. */
1580 static bfd_reloc_status_type
1581 dvp_u15_s3_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1582 output_bfd
, error_message
)
1584 arelent
*reloc_entry
;
1587 asection
*input_section
;
1589 char **error_message
;
1594 /* If we're relocating, and this is an external symbol with no
1595 addend, we don't want to change anything. We will only have an
1596 addend if this is a newly created reloc, not read from an ELF
1597 file. See bfd_elf_generic_reloc. */
1598 if (output_bfd
!= NULL
1599 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1600 /* partial_inplace is false, so this test always succeeds,
1601 but for clarity and consistency with bfd_elf_generic_reloc
1602 this is left as is. */
1603 && (! reloc_entry
->howto
->partial_inplace
1604 || reloc_entry
->addend
== 0))
1606 reloc_entry
->address
+= input_section
->output_offset
;
1607 return bfd_reloc_ok
;
1610 if (reloc_entry
->address
> input_section
->_cooked_size
)
1611 return bfd_reloc_outofrange
;
1613 relocation
= (symbol
->value
1614 + symbol
->section
->output_section
->vma
1615 + symbol
->section
->output_offset
);
1616 relocation
+= reloc_entry
->addend
;
1619 x
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1620 x
|= (((relocation
& 0x7800) << 10)
1621 | (relocation
& 0x7ff));
1622 bfd_put_32 (abfd
, x
, (bfd_byte
*) data
+ reloc_entry
->address
);
1624 if (relocation
& ~(bfd_vma
) 0x7fff)
1625 return bfd_reloc_overflow
;
1626 return bfd_reloc_ok
;
1629 /* end-sanitize-sky */
1630 /* Return the ISA for a MIPS e_flags value. */
1633 elf_mips_isa (flags
)
1636 switch (flags
& EF_MIPS_ARCH
)
1650 /* Return the MACH for a MIPS e_flags value. */
1653 elf_mips_mach (flags
)
1656 switch (flags
& EF_MIPS_MACH
)
1658 case E_MIPS_MACH_3900
:
1659 return bfd_mach_mips3900
;
1661 case E_MIPS_MACH_4010
:
1662 return bfd_mach_mips4010
;
1664 case E_MIPS_MACH_4100
:
1665 return bfd_mach_mips4100
;
1666 /* start-sanitize-vr4xxx */
1668 case E_MIPS_MACH_4121
:
1669 return bfd_mach_mips4121
;
1670 /* end-sanitize-vr4xxx */
1671 /* start-sanitize-vr4320 */
1673 case E_MIPS_MACH_4320
:
1674 return bfd_mach_mips4320
;
1675 /* end-sanitize-vr4320 */
1677 case E_MIPS_MACH_4650
:
1678 return bfd_mach_mips4650
;
1679 /* start-sanitize-tx49 */
1681 case E_MIPS_MACH_4900
:
1682 return bfd_mach_mips4900
;
1683 /* end-sanitize-tx49 */
1684 /* start-sanitize-cygnus */
1686 case E_MIPS_MACH_5400
:
1687 return bfd_mach_mips5400
;
1688 /* end-sanitize-cygnus */
1689 /* start-sanitize-r5900 */
1691 case E_MIPS_MACH_5900
:
1692 return bfd_mach_mips5900
;
1693 /* end-sanitize-r5900 */
1696 switch (flags
& EF_MIPS_ARCH
)
1700 return bfd_mach_mips3000
;
1704 return bfd_mach_mips6000
;
1708 return bfd_mach_mips4000
;
1712 return bfd_mach_mips8000
;
1720 /* Return printable name for ABI from flagword. */
1723 elf_mips_abi_name (flags
)
1726 switch (flags
& EF_MIPS_ABI
)
1730 case E_MIPS_ABI_O32
:
1732 case E_MIPS_ABI_O64
:
1734 case E_MIPS_ABI_EABI32
:
1736 case E_MIPS_ABI_EABI64
:
1739 return "unknown abi";
1743 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1745 struct elf_reloc_map
{
1746 bfd_reloc_code_real_type bfd_reloc_val
;
1747 enum elf_mips_reloc_type elf_reloc_val
;
1750 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1752 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1753 { BFD_RELOC_16
, R_MIPS_16
},
1754 { BFD_RELOC_32
, R_MIPS_32
},
1755 { BFD_RELOC_64
, R_MIPS_64
},
1756 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1757 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1758 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1759 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1760 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1761 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1762 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1763 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1764 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1765 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1766 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1767 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1768 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
}
1771 /* Given a BFD reloc type, return a howto structure. */
1773 static reloc_howto_type
*
1774 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1776 bfd_reloc_code_real_type code
;
1780 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1782 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1783 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1789 bfd_set_error (bfd_error_bad_value
);
1792 case BFD_RELOC_CTOR
:
1793 /* We need to handle BFD_RELOC_CTOR specially.
1794 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1795 size of addresses on this architecture. */
1796 if (bfd_arch_bits_per_address (abfd
) == 32)
1797 return &elf_mips_howto_table
[(int) R_MIPS_32
];
1799 return &elf_mips_ctor64_howto
;
1801 case BFD_RELOC_MIPS16_JMP
:
1802 return &elf_mips16_jump_howto
;
1803 case BFD_RELOC_MIPS16_GPREL
:
1804 return &elf_mips16_gprel_howto
;
1805 /* start-sanitize-r5900 */
1806 case BFD_RELOC_MIPS15_S3
:
1807 return &elf_mips15_s3_howto
;
1808 /* end-sanitize-r5900 */
1809 /* start-sanitize-sky */
1810 case BFD_RELOC_MIPS_DVP_11_PCREL
:
1811 return &elf_mips_dvp_11_pcrel_howto
;
1812 case BFD_RELOC_MIPS_DVP_27_S4
:
1813 return &elf_mips_dvp_27_s4_howto
;
1814 case BFD_RELOC_MIPS_DVP_11_S4
:
1815 return &elf_mips_dvp_11_s4_howto
;
1816 case BFD_RELOC_MIPS_DVP_U15_S3
:
1817 return &elf_mips_dvp_u15_s3_howto
;
1818 /* end-sanitize-sky */
1819 case BFD_RELOC_VTABLE_INHERIT
:
1820 return &elf_mips_gnu_vtinherit_howto
;
1821 case BFD_RELOC_VTABLE_ENTRY
:
1822 return &elf_mips_gnu_vtentry_howto
;
1826 /* Given a MIPS reloc type, fill in an arelent structure. */
1829 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1832 Elf32_Internal_Rel
*dst
;
1834 unsigned int r_type
;
1836 r_type
= ELF32_R_TYPE (dst
->r_info
);
1840 cache_ptr
->howto
= &elf_mips16_jump_howto
;
1842 case R_MIPS16_GPREL
:
1843 cache_ptr
->howto
= &elf_mips16_gprel_howto
;
1845 /* start-sanitize-r5900 */
1847 cache_ptr
->howto
= &elf_mips15_s3_howto
;
1849 /* end-sanitize-r5900 */
1850 /* start-sanitize-sky */
1851 case R_MIPS_DVP_11_PCREL
:
1852 cache_ptr
->howto
= &elf_mips_dvp_11_pcrel_howto
;
1854 case R_MIPS_DVP_27_S4
:
1855 cache_ptr
->howto
= &elf_mips_dvp_27_s4_howto
;
1857 case R_MIPS_DVP_11_S4
:
1858 cache_ptr
->howto
= &elf_mips_dvp_11_s4_howto
;
1860 case R_MIPS_DVP_U15_S3
:
1861 cache_ptr
->howto
= &elf_mips_dvp_u15_s3_howto
;
1863 /* end-sanitize-sky */
1864 case R_MIPS_GNU_VTINHERIT
:
1865 cache_ptr
->howto
= &elf_mips_gnu_vtinherit_howto
;
1867 case R_MIPS_GNU_VTENTRY
:
1868 cache_ptr
->howto
= &elf_mips_gnu_vtentry_howto
;
1872 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1873 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1877 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1878 value for the object file. We get the addend now, rather than
1879 when we do the relocation, because the symbol manipulations done
1880 by the linker may cause us to lose track of the input BFD. */
1881 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1882 && (r_type
== (unsigned int) R_MIPS_GPREL16
1883 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1884 cache_ptr
->addend
= elf_gp (abfd
);
1887 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1888 routines swap this structure in and out. They are used outside of
1889 BFD, so they are globally visible. */
1892 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1894 const Elf32_External_RegInfo
*ex
;
1897 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1898 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1899 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1900 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1901 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1902 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1906 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1908 const Elf32_RegInfo
*in
;
1909 Elf32_External_RegInfo
*ex
;
1911 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1912 (bfd_byte
*) ex
->ri_gprmask
);
1913 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1914 (bfd_byte
*) ex
->ri_cprmask
[0]);
1915 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1916 (bfd_byte
*) ex
->ri_cprmask
[1]);
1917 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1918 (bfd_byte
*) ex
->ri_cprmask
[2]);
1919 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1920 (bfd_byte
*) ex
->ri_cprmask
[3]);
1921 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1922 (bfd_byte
*) ex
->ri_gp_value
);
1925 /* In the 64 bit ABI, the .MIPS.options section holds register
1926 information in an Elf64_Reginfo structure. These routines swap
1927 them in and out. They are globally visible because they are used
1928 outside of BFD. These routines are here so that gas can call them
1929 without worrying about whether the 64 bit ABI has been included. */
1932 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1934 const Elf64_External_RegInfo
*ex
;
1935 Elf64_Internal_RegInfo
*in
;
1937 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1938 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
1939 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1940 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1941 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1942 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1943 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1947 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1949 const Elf64_Internal_RegInfo
*in
;
1950 Elf64_External_RegInfo
*ex
;
1952 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1953 (bfd_byte
*) ex
->ri_gprmask
);
1954 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
1955 (bfd_byte
*) ex
->ri_pad
);
1956 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1957 (bfd_byte
*) ex
->ri_cprmask
[0]);
1958 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1959 (bfd_byte
*) ex
->ri_cprmask
[1]);
1960 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1961 (bfd_byte
*) ex
->ri_cprmask
[2]);
1962 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1963 (bfd_byte
*) ex
->ri_cprmask
[3]);
1964 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1965 (bfd_byte
*) ex
->ri_gp_value
);
1968 /* Swap an entry in a .gptab section. Note that these routines rely
1969 on the equivalence of the two elements of the union. */
1972 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1974 const Elf32_External_gptab
*ex
;
1977 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1978 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1982 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1984 const Elf32_gptab
*in
;
1985 Elf32_External_gptab
*ex
;
1987 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1988 ex
->gt_entry
.gt_g_value
);
1989 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1990 ex
->gt_entry
.gt_bytes
);
1994 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1996 const Elf32_compact_rel
*in
;
1997 Elf32_External_compact_rel
*ex
;
1999 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
2000 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
2001 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
2002 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
2003 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
2004 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
2008 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
2010 const Elf32_crinfo
*in
;
2011 Elf32_External_crinfo
*ex
;
2015 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
2016 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
2017 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
2018 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
2019 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
2020 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
2021 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
2024 /* Swap in an options header. */
2027 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
2029 const Elf_External_Options
*ex
;
2030 Elf_Internal_Options
*in
;
2032 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
2033 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
2034 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
2035 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
2038 /* Swap out an options header. */
2041 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
2043 const Elf_Internal_Options
*in
;
2044 Elf_External_Options
*ex
;
2046 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
2047 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
2048 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
2049 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
2052 /* Determine whether a symbol is global for the purposes of splitting
2053 the symbol table into global symbols and local symbols. At least
2054 on Irix 5, this split must be between section symbols and all other
2055 symbols. On most ELF targets the split is between static symbols
2056 and externally visible symbols. */
2060 mips_elf_sym_is_global (abfd
, sym
)
2064 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
2067 /* Set the right machine number for a MIPS ELF file. This is used for
2068 both the 32-bit and the 64-bit ABI. */
2071 _bfd_mips_elf_object_p (abfd
)
2074 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
,
2075 elf_mips_mach (elf_elfheader (abfd
)->e_flags
));
2079 /* Set the right machine number for a 32-bit MIPS ELF file. */
2082 mips_elf32_object_p (abfd
)
2085 /* Irix 5 is broken. Object file symbol tables are not always
2086 sorted correctly such that local symbols precede global symbols,
2087 and the sh_info field in the symbol table is not always right. */
2088 elf_bad_symtab (abfd
) = true;
2090 return _bfd_mips_elf_object_p (abfd
);
2093 /* The final processing done just before writing out a MIPS ELF object
2094 file. This gets the MIPS architecture right based on the machine
2095 number. This is used by both the 32-bit and the 64-bit ABI. */
2099 _bfd_mips_elf_final_write_processing (abfd
, linker
)
2105 Elf_Internal_Shdr
**hdrpp
;
2109 switch (bfd_get_mach (abfd
))
2112 case bfd_mach_mips3000
:
2113 val
= E_MIPS_ARCH_1
;
2116 case bfd_mach_mips3900
:
2117 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
2120 case bfd_mach_mips6000
:
2121 val
= E_MIPS_ARCH_2
;
2124 case bfd_mach_mips4000
:
2125 case bfd_mach_mips4300
:
2126 val
= E_MIPS_ARCH_3
;
2129 case bfd_mach_mips4010
:
2130 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
2133 case bfd_mach_mips4100
:
2134 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
2136 /* start-sanitize-vr4xxx */
2138 case bfd_mach_mips4121
:
2139 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4121
;
2141 /* end-sanitize-vr4xxx */
2142 /* start-sanitize-vr4320 */
2144 case bfd_mach_mips4320
:
2145 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4320
;
2147 /* end-sanitize-vr4320 */
2149 case bfd_mach_mips4650
:
2150 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
2152 /* start-sanitize-tx49 */
2154 case bfd_mach_mips4900
:
2155 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4900
;
2157 /* end-sanitize-tx49 */
2158 /* start-sanitize-cygnus */
2160 case bfd_mach_mips5400
:
2161 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_5400
;
2163 /* end-sanitize-cygnus */
2164 /* start-sanitize-r5900 */
2166 case bfd_mach_mips5900
:
2167 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_5900
;
2169 /* end-sanitize-r5900 */
2171 case bfd_mach_mips8000
:
2172 val
= E_MIPS_ARCH_4
;
2176 elf_elfheader (abfd
)->e_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2177 elf_elfheader (abfd
)->e_flags
|= val
;
2179 /* Set the sh_info field for .gptab sections and other appropriate
2180 info for each special section. */
2181 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
2182 i
< elf_elfheader (abfd
)->e_shnum
;
2185 switch ((*hdrpp
)->sh_type
)
2187 case SHT_MIPS_LIBLIST
:
2188 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
2190 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2193 case SHT_MIPS_GPTAB
:
2194 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2195 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2196 BFD_ASSERT (name
!= NULL
2197 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
2198 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
2199 BFD_ASSERT (sec
!= NULL
);
2200 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2203 case SHT_MIPS_CONTENT
:
2204 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2205 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2206 BFD_ASSERT (name
!= NULL
2207 && strncmp (name
, ".MIPS.content",
2208 sizeof ".MIPS.content" - 1) == 0);
2209 sec
= bfd_get_section_by_name (abfd
,
2210 name
+ sizeof ".MIPS.content" - 1);
2211 BFD_ASSERT (sec
!= NULL
);
2212 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2215 case SHT_MIPS_SYMBOL_LIB
:
2216 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
2218 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2219 sec
= bfd_get_section_by_name (abfd
, ".liblist");
2221 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2224 case SHT_MIPS_EVENTS
:
2225 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2226 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2227 BFD_ASSERT (name
!= NULL
);
2228 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
2229 sec
= bfd_get_section_by_name (abfd
,
2230 name
+ sizeof ".MIPS.events" - 1);
2233 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
2234 sizeof ".MIPS.post_rel" - 1) == 0);
2235 sec
= bfd_get_section_by_name (abfd
,
2237 + sizeof ".MIPS.post_rel" - 1));
2239 BFD_ASSERT (sec
!= NULL
);
2240 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2243 /* start-sanitize-sky */
2244 case SHT_DVP_OVERLAY_TABLE
:
2245 /* ??? This may not be technically necessary, just going with
2247 sec
= bfd_get_section_by_name (abfd
, SHNAME_DVP_OVERLAY_STRTAB
);
2249 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2251 /* end-sanitize-sky */
2256 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
2259 _bfd_mips_elf_set_private_flags (abfd
, flags
)
2263 BFD_ASSERT (!elf_flags_init (abfd
)
2264 || elf_elfheader (abfd
)->e_flags
== flags
);
2266 elf_elfheader (abfd
)->e_flags
= flags
;
2267 elf_flags_init (abfd
) = true;
2271 /* Copy backend specific data from one object module to another */
2274 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
2278 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2279 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2282 BFD_ASSERT (!elf_flags_init (obfd
)
2283 || (elf_elfheader (obfd
)->e_flags
2284 == elf_elfheader (ibfd
)->e_flags
));
2286 elf_gp (obfd
) = elf_gp (ibfd
);
2287 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
2288 elf_flags_init (obfd
) = true;
2292 /* Merge backend specific data from an object file to the output
2293 object file when linking. */
2296 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
2304 /* Check if we have the same endianess */
2305 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2306 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2310 if (bfd_big_endian (ibfd
))
2311 msg
= _("%s: compiled for a big endian system and target is little endian");
2313 msg
= _("%s: compiled for a little endian system and target is big endian");
2315 (*_bfd_error_handler
) (msg
, bfd_get_filename (ibfd
));
2317 bfd_set_error (bfd_error_wrong_format
);
2321 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2322 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2325 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2326 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
2327 old_flags
= elf_elfheader (obfd
)->e_flags
;
2329 if (! elf_flags_init (obfd
))
2331 elf_flags_init (obfd
) = true;
2332 elf_elfheader (obfd
)->e_flags
= new_flags
;
2334 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2335 && bfd_get_arch_info (obfd
)->the_default
)
2337 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
2338 bfd_get_mach (ibfd
)))
2345 /* Check flag compatibility. */
2347 new_flags
&= ~EF_MIPS_NOREORDER
;
2348 old_flags
&= ~EF_MIPS_NOREORDER
;
2350 if (new_flags
== old_flags
)
2355 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
2357 new_flags
&= ~EF_MIPS_PIC
;
2358 old_flags
&= ~EF_MIPS_PIC
;
2359 (*_bfd_error_handler
)
2360 (_("%s: linking PIC files with non-PIC files"),
2361 bfd_get_filename (ibfd
));
2365 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
2367 new_flags
&= ~EF_MIPS_CPIC
;
2368 old_flags
&= ~EF_MIPS_CPIC
;
2369 (*_bfd_error_handler
)
2370 (_("%s: linking abicalls files with non-abicalls files"),
2371 bfd_get_filename (ibfd
));
2375 /* Compare the ISA's. */
2376 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
2377 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
2379 /* If either has no machine specified, just compare the general isa's. */
2380 if ( !(new_flags
& EF_MIPS_MACH
) || !(old_flags
& EF_MIPS_MACH
))
2382 int new_isa
, old_isa
;
2384 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
2385 and -mips4 code. They will normally use the same data sizes and
2386 calling conventions. */
2388 new_isa
= elf_mips_isa (new_flags
);
2389 old_isa
= elf_mips_isa (old_flags
);
2390 if ((new_isa
== 1 || new_isa
== 2)
2391 ? (old_isa
!= 1 && old_isa
!= 2)
2392 : (old_isa
== 1 || old_isa
== 2))
2394 (*_bfd_error_handler
)
2395 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
2396 bfd_get_filename (ibfd
), new_isa
, old_isa
);
2403 (*_bfd_error_handler
)
2404 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
2405 bfd_get_filename (ibfd
),
2406 elf_mips_mach (new_flags
),
2407 elf_mips_mach (old_flags
));
2411 new_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2412 old_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2416 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
))
2418 /* Only error if both are set (to different values). */
2419 if ((new_flags
& EF_MIPS_ABI
)
2420 && (old_flags
& EF_MIPS_ABI
))
2422 (*_bfd_error_handler
)
2423 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
2424 bfd_get_filename (ibfd
),
2425 elf_mips_abi_name (new_flags
),
2426 elf_mips_abi_name (old_flags
));
2429 new_flags
&= ~EF_MIPS_ABI
;
2430 old_flags
&= ~EF_MIPS_ABI
;
2433 /* Warn about any other mismatches */
2434 if (new_flags
!= old_flags
)
2436 (*_bfd_error_handler
)
2437 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2438 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
2439 (unsigned long) old_flags
);
2445 bfd_set_error (bfd_error_bad_value
);
2452 /* Handle a MIPS specific section when reading an object file. This
2453 is called when elfcode.h finds a section with an unknown type.
2454 This routine supports both the 32-bit and 64-bit ELF ABI.
2456 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2460 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
2462 Elf_Internal_Shdr
*hdr
;
2465 /* There ought to be a place to keep ELF backend specific flags, but
2466 at the moment there isn't one. We just keep track of the
2467 sections by their name, instead. Fortunately, the ABI gives
2468 suggested names for all the MIPS specific sections, so we will
2469 probably get away with this. */
2470 switch (hdr
->sh_type
)
2472 case SHT_MIPS_LIBLIST
:
2473 if (strcmp (name
, ".liblist") != 0)
2477 if (strcmp (name
, ".msym") != 0)
2480 case SHT_MIPS_CONFLICT
:
2481 if (strcmp (name
, ".conflict") != 0)
2484 case SHT_MIPS_GPTAB
:
2485 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
2488 case SHT_MIPS_UCODE
:
2489 if (strcmp (name
, ".ucode") != 0)
2492 case SHT_MIPS_DEBUG
:
2493 if (strcmp (name
, ".mdebug") != 0)
2496 case SHT_MIPS_REGINFO
:
2497 if (strcmp (name
, ".reginfo") != 0
2498 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
2501 case SHT_MIPS_IFACE
:
2502 if (strcmp (name
, ".MIPS.interfaces") != 0)
2505 case SHT_MIPS_CONTENT
:
2506 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2509 case SHT_MIPS_OPTIONS
:
2510 if (strcmp (name
, ".options") != 0
2511 && strcmp (name
, ".MIPS.options") != 0)
2514 case SHT_MIPS_DWARF
:
2515 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2518 case SHT_MIPS_SYMBOL_LIB
:
2519 if (strcmp (name
, ".MIPS.symlib") != 0)
2522 case SHT_MIPS_EVENTS
:
2523 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2524 && strncmp (name
, ".MIPS.post_rel",
2525 sizeof ".MIPS.post_rel" - 1) != 0)
2528 /* start-sanitize-sky */
2529 case SHT_DVP_OVERLAY_TABLE
:
2530 if (strcmp (name
, SHNAME_DVP_OVERLAY_TABLE
) !=0)
2533 case SHT_DVP_OVERLAY
:
2534 if (strncmp (name
, SHNAME_DVP_OVERLAY_PREFIX
,
2535 sizeof (SHNAME_DVP_OVERLAY_PREFIX
) - 1) !=0)
2538 /* end-sanitize-sky */
2543 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2546 if (hdr
->sh_type
== SHT_MIPS_DEBUG
)
2548 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
2549 (bfd_get_section_flags (abfd
,
2558 /* Handle a 32-bit MIPS ELF specific section. */
2561 mips_elf32_section_from_shdr (abfd
, hdr
, name
)
2563 Elf_Internal_Shdr
*hdr
;
2566 if (! _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
))
2569 /* FIXME: We should record sh_info for a .gptab section. */
2571 /* For a .reginfo section, set the gp value in the tdata information
2572 from the contents of this section. We need the gp value while
2573 processing relocs, so we just get it now. The .reginfo section
2574 is not used in the 64-bit MIPS ELF ABI. */
2575 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2577 Elf32_External_RegInfo ext
;
2580 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
2581 (file_ptr
) 0, sizeof ext
))
2583 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
2584 elf_gp (abfd
) = s
.ri_gp_value
;
2587 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2588 set the gp value based on what we find. We may see both
2589 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2590 they should agree. */
2591 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
2593 bfd_byte
*contents
, *l
, *lend
;
2595 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
2596 if (contents
== NULL
)
2598 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
2599 (file_ptr
) 0, hdr
->sh_size
))
2605 lend
= contents
+ hdr
->sh_size
;
2606 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2608 Elf_Internal_Options intopt
;
2610 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2612 if (intopt
.kind
== ODK_REGINFO
)
2614 Elf32_RegInfo intreg
;
2616 bfd_mips_elf32_swap_reginfo_in
2618 ((Elf32_External_RegInfo
*)
2619 (l
+ sizeof (Elf_External_Options
))),
2621 elf_gp (abfd
) = intreg
.ri_gp_value
;
2631 /* Set the correct type for a MIPS ELF section. We do this by the
2632 section name, which is a hack, but ought to work. This routine is
2633 used by both the 32-bit and the 64-bit ABI. */
2636 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
2638 Elf32_Internal_Shdr
*hdr
;
2641 register const char *name
;
2643 name
= bfd_get_section_name (abfd
, sec
);
2645 if (strcmp (name
, ".liblist") == 0)
2647 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
2648 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
2649 /* The sh_link field is set in final_write_processing. */
2651 else if (strcmp (name
, ".msym") == 0)
2653 hdr
->sh_type
= SHT_MIPS_MSYM
;
2654 hdr
->sh_entsize
= 8;
2655 /* FIXME: Set the sh_info field. */
2657 else if (strcmp (name
, ".conflict") == 0)
2658 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
2659 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2661 hdr
->sh_type
= SHT_MIPS_GPTAB
;
2662 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
2663 /* The sh_info field is set in final_write_processing. */
2665 else if (strcmp (name
, ".ucode") == 0)
2666 hdr
->sh_type
= SHT_MIPS_UCODE
;
2667 else if (strcmp (name
, ".mdebug") == 0)
2669 hdr
->sh_type
= SHT_MIPS_DEBUG
;
2670 /* In a shared object on Irix 5.3, the .mdebug section has an
2671 entsize of 0. FIXME: Does this matter? */
2672 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2673 hdr
->sh_entsize
= 0;
2675 hdr
->sh_entsize
= 1;
2677 else if (strcmp (name
, ".reginfo") == 0)
2679 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2680 /* In a shared object on Irix 5.3, the .reginfo section has an
2681 entsize of 0x18. FIXME: Does this matter? */
2682 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2683 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2685 hdr
->sh_entsize
= 1;
2687 /* Force the section size to the correct value, even if the
2688 linker thinks it is larger. The link routine below will only
2689 write out this much data for .reginfo. */
2690 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf32_External_RegInfo
);
2692 else if (SGI_COMPAT (abfd
)
2693 && (strcmp (name
, ".hash") == 0
2694 || strcmp (name
, ".dynamic") == 0
2695 || strcmp (name
, ".dynstr") == 0))
2697 hdr
->sh_entsize
= 0;
2699 /* This isn't how the Irix 6 linker behaves. */
2700 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2703 else if (strcmp (name
, ".got") == 0
2704 || strcmp (name
, ".sdata") == 0
2705 || strcmp (name
, ".sbss") == 0
2706 || strcmp (name
, ".lit4") == 0
2707 || strcmp (name
, ".lit8") == 0)
2708 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2709 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2711 hdr
->sh_type
= SHT_MIPS_IFACE
;
2712 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2714 else if (strcmp (name
, ".MIPS.content") == 0)
2716 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2717 /* The sh_info field is set in final_write_processing. */
2719 else if (strcmp (name
, ".options") == 0
2720 || strcmp (name
, ".MIPS.options") == 0)
2722 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2723 hdr
->sh_entsize
= 1;
2724 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2726 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2727 hdr
->sh_type
= SHT_MIPS_DWARF
;
2728 else if (strcmp (name
, ".MIPS.symlib") == 0)
2730 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2731 /* The sh_link and sh_info fields are set in
2732 final_write_processing. */
2734 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2735 || strncmp (name
, ".MIPS.post_rel",
2736 sizeof ".MIPS.post_rel" - 1) == 0)
2738 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2739 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2740 /* The sh_link field is set in final_write_processing. */
2742 /* start-sanitize-sky */
2743 else if (strcmp (name
, SHNAME_DVP_OVERLAY_TABLE
) == 0)
2745 hdr
->sh_type
= SHT_DVP_OVERLAY_TABLE
;
2746 hdr
->sh_entsize
= sizeof (Elf32_Dvp_External_Overlay
);
2747 /* The sh_link field is set in final_write_processing. */
2749 else if (strcmp (name
, SHNAME_DVP_OVERLAY_STRTAB
) == 0)
2750 hdr
->sh_type
= SHT_STRTAB
;
2751 else if (strncmp (name
, SHNAME_DVP_OVERLAY_PREFIX
,
2752 sizeof (SHNAME_DVP_OVERLAY_PREFIX
) - 1) == 0)
2753 hdr
->sh_type
= SHT_DVP_OVERLAY
;
2754 /* end-sanitize-sky */
2759 /* Given a BFD section, try to locate the corresponding ELF section
2760 index. This is used by both the 32-bit and the 64-bit ABI.
2761 Actually, it's not clear to me that the 64-bit ABI supports these,
2762 but for non-PIC objects we will certainly want support for at least
2763 the .scommon section. */
2766 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2768 Elf32_Internal_Shdr
*hdr
;
2772 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2774 *retval
= SHN_MIPS_SCOMMON
;
2777 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2779 *retval
= SHN_MIPS_ACOMMON
;
2785 /* When are writing out the .options or .MIPS.options section,
2786 remember the bytes we are writing out, so that we can install the
2787 GP value in the section_processing routine. */
2790 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2795 bfd_size_type count
;
2797 if (strcmp (section
->name
, ".options") == 0
2798 || strcmp (section
->name
, ".MIPS.options") == 0)
2802 if (elf_section_data (section
) == NULL
)
2804 section
->used_by_bfd
=
2805 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
2806 if (elf_section_data (section
) == NULL
)
2809 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
2814 if (section
->_cooked_size
!= 0)
2815 size
= section
->_cooked_size
;
2817 size
= section
->_raw_size
;
2818 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
2821 elf_section_data (section
)->tdata
= (PTR
) c
;
2824 memcpy (c
+ offset
, location
, count
);
2827 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
2831 /* Work over a section just before writing it out. This routine is
2832 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2833 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2837 _bfd_mips_elf_section_processing (abfd
, hdr
)
2839 Elf_Internal_Shdr
*hdr
;
2841 if (hdr
->bfd_section
!= NULL
)
2843 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
2845 if (strcmp (name
, ".sdata") == 0)
2847 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2848 hdr
->sh_type
= SHT_PROGBITS
;
2850 else if (strcmp (name
, ".sbss") == 0)
2852 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2853 hdr
->sh_type
= SHT_NOBITS
;
2855 else if (strcmp (name
, ".lit8") == 0
2856 || strcmp (name
, ".lit4") == 0)
2858 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2859 hdr
->sh_type
= SHT_PROGBITS
;
2861 else if (strcmp (name
, ".compact_rel") == 0)
2864 hdr
->sh_type
= SHT_PROGBITS
;
2866 else if (strcmp (name
, ".rtproc") == 0)
2868 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
2870 unsigned int adjust
;
2872 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
2874 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
2882 /* Work over a section just before writing it out. We update the GP
2883 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2884 on the value we are using. */
2887 mips_elf32_section_processing (abfd
, hdr
)
2889 Elf32_Internal_Shdr
*hdr
;
2891 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2895 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2896 BFD_ASSERT (hdr
->contents
== NULL
);
2899 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2902 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2903 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2907 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2908 && hdr
->bfd_section
!= NULL
2909 && elf_section_data (hdr
->bfd_section
) != NULL
2910 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2912 bfd_byte
*contents
, *l
, *lend
;
2914 /* We stored the section contents in the elf_section_data tdata
2915 field in the set_section_contents routine. We save the
2916 section contents so that we don't have to read them again.
2917 At this point we know that elf_gp is set, so we can look
2918 through the section contents to see if there is an
2919 ODK_REGINFO structure. */
2921 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2923 lend
= contents
+ hdr
->sh_size
;
2924 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2926 Elf_Internal_Options intopt
;
2928 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2930 if (intopt
.kind
== ODK_REGINFO
)
2937 + sizeof (Elf_External_Options
)
2938 + (sizeof (Elf32_External_RegInfo
) - 4)),
2941 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
2942 if (bfd_write (buf
, 1, 4, abfd
) != 4)
2949 return _bfd_mips_elf_section_processing (abfd
, hdr
);
2952 /* MIPS ELF uses two common sections. One is the usual one, and the
2953 other is for small objects. All the small objects are kept
2954 together, and then referenced via the gp pointer, which yields
2955 faster assembler code. This is what we use for the small common
2956 section. This approach is copied from ecoff.c. */
2957 static asection mips_elf_scom_section
;
2958 static asymbol mips_elf_scom_symbol
;
2959 static asymbol
*mips_elf_scom_symbol_ptr
;
2961 /* MIPS ELF also uses an acommon section, which represents an
2962 allocated common symbol which may be overridden by a
2963 definition in a shared library. */
2964 static asection mips_elf_acom_section
;
2965 static asymbol mips_elf_acom_symbol
;
2966 static asymbol
*mips_elf_acom_symbol_ptr
;
2968 /* The Irix 5 support uses two virtual sections, which represent
2969 text/data symbols defined in dynamic objects. */
2970 static asection mips_elf_text_section
;
2971 static asection
*mips_elf_text_section_ptr
;
2972 static asymbol mips_elf_text_symbol
;
2973 static asymbol
*mips_elf_text_symbol_ptr
;
2975 static asection mips_elf_data_section
;
2976 static asection
*mips_elf_data_section_ptr
;
2977 static asymbol mips_elf_data_symbol
;
2978 static asymbol
*mips_elf_data_symbol_ptr
;
2980 /* Handle the special MIPS section numbers that a symbol may use.
2981 This is used for both the 32-bit and the 64-bit ABI. */
2984 _bfd_mips_elf_symbol_processing (abfd
, asym
)
2988 elf_symbol_type
*elfsym
;
2990 elfsym
= (elf_symbol_type
*) asym
;
2991 switch (elfsym
->internal_elf_sym
.st_shndx
)
2993 case SHN_MIPS_ACOMMON
:
2994 /* This section is used in a dynamically linked executable file.
2995 It is an allocated common section. The dynamic linker can
2996 either resolve these symbols to something in a shared
2997 library, or it can just leave them here. For our purposes,
2998 we can consider these symbols to be in a new section. */
2999 if (mips_elf_acom_section
.name
== NULL
)
3001 /* Initialize the acommon section. */
3002 mips_elf_acom_section
.name
= ".acommon";
3003 mips_elf_acom_section
.flags
= SEC_ALLOC
;
3004 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
3005 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
3006 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
3007 mips_elf_acom_symbol
.name
= ".acommon";
3008 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
3009 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
3010 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
3012 asym
->section
= &mips_elf_acom_section
;
3016 /* Common symbols less than the GP size are automatically
3017 treated as SHN_MIPS_SCOMMON symbols. */
3018 if (asym
->value
> elf_gp_size (abfd
))
3021 case SHN_MIPS_SCOMMON
:
3022 if (mips_elf_scom_section
.name
== NULL
)
3024 /* Initialize the small common section. */
3025 mips_elf_scom_section
.name
= ".scommon";
3026 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
3027 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
3028 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
3029 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
3030 mips_elf_scom_symbol
.name
= ".scommon";
3031 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
3032 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
3033 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
3035 asym
->section
= &mips_elf_scom_section
;
3036 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
3039 case SHN_MIPS_SUNDEFINED
:
3040 asym
->section
= bfd_und_section_ptr
;
3043 #if 0 /* for SGI_COMPAT */
3045 asym
->section
= mips_elf_text_section_ptr
;
3049 asym
->section
= mips_elf_data_section_ptr
;
3055 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
3059 mips_elf_additional_program_headers (abfd
)
3067 if (! SGI_COMPAT (abfd
))
3070 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3071 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3073 /* We need a PT_MIPS_REGINFO segment. */
3077 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3078 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3080 /* We need a PT_MIPS_RTPROC segment. */
3087 /* Modify the segment map for an Irix 5 executable. */
3090 mips_elf_modify_segment_map (abfd
)
3094 struct elf_segment_map
*m
, **pm
;
3096 if (! SGI_COMPAT (abfd
))
3099 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
3101 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3102 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3104 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3105 if (m
->p_type
== PT_MIPS_REGINFO
)
3109 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3113 m
->p_type
= PT_MIPS_REGINFO
;
3117 /* We want to put it after the PHDR and INTERP segments. */
3118 pm
= &elf_tdata (abfd
)->segment_map
;
3120 && ((*pm
)->p_type
== PT_PHDR
3121 || (*pm
)->p_type
== PT_INTERP
))
3129 /* If there are .dynamic and .mdebug sections, we make a room for
3130 the RTPROC header. FIXME: Rewrite without section names. */
3131 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
3132 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3133 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3135 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3136 if (m
->p_type
== PT_MIPS_RTPROC
)
3140 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3144 m
->p_type
= PT_MIPS_RTPROC
;
3146 s
= bfd_get_section_by_name (abfd
, ".rtproc");
3151 m
->p_flags_valid
= 1;
3159 /* We want to put it after the DYNAMIC segment. */
3160 pm
= &elf_tdata (abfd
)->segment_map
;
3161 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
3171 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
3172 .dynsym, and .hash sections, and everything in between. */
3173 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
3174 if ((*pm
)->p_type
== PT_DYNAMIC
)
3179 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
3181 static const char *sec_names
[] =
3182 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
3185 struct elf_segment_map
*n
;
3189 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
3191 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
3192 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3198 sz
= s
->_cooked_size
;
3201 if (high
< s
->vma
+ sz
)
3207 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3208 if ((s
->flags
& SEC_LOAD
) != 0
3211 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3215 n
= ((struct elf_segment_map
*)
3216 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
3223 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3225 if ((s
->flags
& SEC_LOAD
) != 0
3228 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3242 /* The structure of the runtime procedure descriptor created by the
3243 loader for use by the static exception system. */
3245 typedef struct runtime_pdr
{
3246 bfd_vma adr
; /* memory address of start of procedure */
3247 long regmask
; /* save register mask */
3248 long regoffset
; /* save register offset */
3249 long fregmask
; /* save floating point register mask */
3250 long fregoffset
; /* save floating point register offset */
3251 long frameoffset
; /* frame size */
3252 short framereg
; /* frame pointer register */
3253 short pcreg
; /* offset or reg of return pc */
3254 long irpss
; /* index into the runtime string table */
3256 struct exception_info
*exception_info
;/* pointer to exception array */
3258 #define cbRPDR sizeof(RPDR)
3259 #define rpdNil ((pRPDR) 0)
3261 /* Swap RPDR (runtime procedure table entry) for output. */
3263 static void ecoff_swap_rpdr_out
3264 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
3267 ecoff_swap_rpdr_out (abfd
, in
, ex
)
3270 struct rpdr_ext
*ex
;
3272 /* ecoff_put_off was defined in ecoffswap.h. */
3273 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
3274 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
3275 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
3276 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
3277 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
3278 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
3280 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
3281 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
3283 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
3285 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
3289 /* Read ECOFF debugging information from a .mdebug section into a
3290 ecoff_debug_info structure. */
3293 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
3296 struct ecoff_debug_info
*debug
;
3299 const struct ecoff_debug_swap
*swap
;
3300 char *ext_hdr
= NULL
;
3302 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3304 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
3305 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
3308 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
3309 swap
->external_hdr_size
)
3313 symhdr
= &debug
->symbolic_header
;
3314 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
3316 /* The symbolic header contains absolute file offsets and sizes to
3318 #define READ(ptr, offset, count, size, type) \
3319 if (symhdr->count == 0) \
3320 debug->ptr = NULL; \
3323 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
3324 if (debug->ptr == NULL) \
3325 goto error_return; \
3326 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3327 || (bfd_read (debug->ptr, size, symhdr->count, \
3328 abfd) != size * symhdr->count)) \
3329 goto error_return; \
3332 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
3333 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
3334 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
3335 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
3336 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
3337 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
3339 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
3340 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
3341 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
3342 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
3343 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
3347 debug
->adjust
= NULL
;
3352 if (ext_hdr
!= NULL
)
3354 if (debug
->line
!= NULL
)
3356 if (debug
->external_dnr
!= NULL
)
3357 free (debug
->external_dnr
);
3358 if (debug
->external_pdr
!= NULL
)
3359 free (debug
->external_pdr
);
3360 if (debug
->external_sym
!= NULL
)
3361 free (debug
->external_sym
);
3362 if (debug
->external_opt
!= NULL
)
3363 free (debug
->external_opt
);
3364 if (debug
->external_aux
!= NULL
)
3365 free (debug
->external_aux
);
3366 if (debug
->ss
!= NULL
)
3368 if (debug
->ssext
!= NULL
)
3369 free (debug
->ssext
);
3370 if (debug
->external_fdr
!= NULL
)
3371 free (debug
->external_fdr
);
3372 if (debug
->external_rfd
!= NULL
)
3373 free (debug
->external_rfd
);
3374 if (debug
->external_ext
!= NULL
)
3375 free (debug
->external_ext
);
3379 /* MIPS ELF local labels start with '$', not 'L'. */
3383 mips_elf_is_local_label_name (abfd
, name
)
3390 /* On Irix 6, the labels go back to starting with '.', so we accept
3391 the generic ELF local label syntax as well. */
3392 return _bfd_elf_is_local_label_name (abfd
, name
);
3395 /* MIPS ELF uses a special find_nearest_line routine in order the
3396 handle the ECOFF debugging information. */
3398 struct mips_elf_find_line
3400 struct ecoff_debug_info d
;
3401 struct ecoff_find_line i
;
3405 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
3406 functionname_ptr
, line_ptr
)
3411 const char **filename_ptr
;
3412 const char **functionname_ptr
;
3413 unsigned int *line_ptr
;
3417 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
3418 filename_ptr
, functionname_ptr
,
3422 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3423 filename_ptr
, functionname_ptr
,
3427 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
3431 struct mips_elf_find_line
*fi
;
3432 const struct ecoff_debug_swap
* const swap
=
3433 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3435 /* If we are called during a link, mips_elf_final_link may have
3436 cleared the SEC_HAS_CONTENTS field. We force it back on here
3437 if appropriate (which it normally will be). */
3438 origflags
= msec
->flags
;
3439 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
3440 msec
->flags
|= SEC_HAS_CONTENTS
;
3442 fi
= elf_tdata (abfd
)->find_line_info
;
3445 bfd_size_type external_fdr_size
;
3448 struct fdr
*fdr_ptr
;
3450 fi
= ((struct mips_elf_find_line
*)
3451 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
3454 msec
->flags
= origflags
;
3458 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
3460 msec
->flags
= origflags
;
3464 /* Swap in the FDR information. */
3465 fi
->d
.fdr
= ((struct fdr
*)
3467 (fi
->d
.symbolic_header
.ifdMax
*
3468 sizeof (struct fdr
))));
3469 if (fi
->d
.fdr
== NULL
)
3471 msec
->flags
= origflags
;
3474 external_fdr_size
= swap
->external_fdr_size
;
3475 fdr_ptr
= fi
->d
.fdr
;
3476 fraw_src
= (char *) fi
->d
.external_fdr
;
3477 fraw_end
= (fraw_src
3478 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
3479 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
3480 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
3482 elf_tdata (abfd
)->find_line_info
= fi
;
3484 /* Note that we don't bother to ever free this information.
3485 find_nearest_line is either called all the time, as in
3486 objdump -l, so the information should be saved, or it is
3487 rarely called, as in ld error messages, so the memory
3488 wasted is unimportant. Still, it would probably be a
3489 good idea for free_cached_info to throw it away. */
3492 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
3493 &fi
->i
, filename_ptr
, functionname_ptr
,
3496 msec
->flags
= origflags
;
3500 msec
->flags
= origflags
;
3503 /* Fall back on the generic ELF find_nearest_line routine. */
3505 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
3506 filename_ptr
, functionname_ptr
,
3510 /* The mips16 compiler uses a couple of special sections to handle
3511 floating point arguments.
3513 Section names that look like .mips16.fn.FNNAME contain stubs that
3514 copy floating point arguments from the fp regs to the gp regs and
3515 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3516 call should be redirected to the stub instead. If no 32 bit
3517 function calls FNNAME, the stub should be discarded. We need to
3518 consider any reference to the function, not just a call, because
3519 if the address of the function is taken we will need the stub,
3520 since the address might be passed to a 32 bit function.
3522 Section names that look like .mips16.call.FNNAME contain stubs
3523 that copy floating point arguments from the gp regs to the fp
3524 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3525 then any 16 bit function that calls FNNAME should be redirected
3526 to the stub instead. If FNNAME is not a 32 bit function, the
3527 stub should be discarded.
3529 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3530 which call FNNAME and then copy the return value from the fp regs
3531 to the gp regs. These stubs store the return value in $18 while
3532 calling FNNAME; any function which might call one of these stubs
3533 must arrange to save $18 around the call. (This case is not
3534 needed for 32 bit functions that call 16 bit functions, because
3535 16 bit functions always return floating point values in both
3538 Note that in all cases FNNAME might be defined statically.
3539 Therefore, FNNAME is not used literally. Instead, the relocation
3540 information will indicate which symbol the section is for.
3542 We record any stubs that we find in the symbol table. */
3544 #define FN_STUB ".mips16.fn."
3545 #define CALL_STUB ".mips16.call."
3546 #define CALL_FP_STUB ".mips16.call.fp."
3548 /* The MIPS ELF linker needs additional information for each symbol in
3549 the global hash table. */
3551 struct mips_elf_link_hash_entry
3553 struct elf_link_hash_entry root
;
3555 /* External symbol information. */
3558 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
3559 unsigned int mips_32_relocs
;
3561 /* If there is a stub that 32 bit functions should use to call this
3562 16 bit function, this points to the section containing the stub. */
3565 /* Whether we need the fn_stub; this is set if this symbol appears
3566 in any relocs other than a 16 bit call. */
3567 boolean need_fn_stub
;
3569 /* If there is a stub that 16 bit functions should use to call this
3570 32 bit function, this points to the section containing the stub. */
3571 asection
*call_stub
;
3573 /* This is like the call_stub field, but it is used if the function
3574 being called returns a floating point value. */
3575 asection
*call_fp_stub
;
3578 /* MIPS ELF linker hash table. */
3580 struct mips_elf_link_hash_table
3582 struct elf_link_hash_table root
;
3584 /* We no longer use this. */
3585 /* String section indices for the dynamic section symbols. */
3586 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
3588 /* The number of .rtproc entries. */
3589 bfd_size_type procedure_count
;
3590 /* The size of the .compact_rel section (if SGI_COMPAT). */
3591 bfd_size_type compact_rel_size
;
3592 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3593 entry is set to the address of __rld_obj_head as in Irix 5. */
3594 boolean use_rld_obj_head
;
3595 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3597 /* This is set if we see any mips16 stub sections. */
3598 boolean mips16_stubs_seen
;
3601 /* Look up an entry in a MIPS ELF linker hash table. */
3603 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3604 ((struct mips_elf_link_hash_entry *) \
3605 elf_link_hash_lookup (&(table)->root, (string), (create), \
3608 /* Traverse a MIPS ELF linker hash table. */
3610 #define mips_elf_link_hash_traverse(table, func, info) \
3611 (elf_link_hash_traverse \
3613 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3616 /* Get the MIPS ELF linker hash table from a link_info structure. */
3618 #define mips_elf_hash_table(p) \
3619 ((struct mips_elf_link_hash_table *) ((p)->hash))
3621 static boolean mips_elf_output_extsym
3622 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3624 /* Create an entry in a MIPS ELF linker hash table. */
3626 static struct bfd_hash_entry
*
3627 mips_elf_link_hash_newfunc (entry
, table
, string
)
3628 struct bfd_hash_entry
*entry
;
3629 struct bfd_hash_table
*table
;
3632 struct mips_elf_link_hash_entry
*ret
=
3633 (struct mips_elf_link_hash_entry
*) entry
;
3635 /* Allocate the structure if it has not already been allocated by a
3637 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3638 ret
= ((struct mips_elf_link_hash_entry
*)
3639 bfd_hash_allocate (table
,
3640 sizeof (struct mips_elf_link_hash_entry
)));
3641 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3642 return (struct bfd_hash_entry
*) ret
;
3644 /* Call the allocation method of the superclass. */
3645 ret
= ((struct mips_elf_link_hash_entry
*)
3646 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3648 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3650 /* Set local fields. */
3651 memset (&ret
->esym
, 0, sizeof (EXTR
));
3652 /* We use -2 as a marker to indicate that the information has
3653 not been set. -1 means there is no associated ifd. */
3655 ret
->mips_32_relocs
= 0;
3656 ret
->fn_stub
= NULL
;
3657 ret
->need_fn_stub
= false;
3658 ret
->call_stub
= NULL
;
3659 ret
->call_fp_stub
= NULL
;
3662 return (struct bfd_hash_entry
*) ret
;
3665 /* Create a MIPS ELF linker hash table. */
3667 static struct bfd_link_hash_table
*
3668 mips_elf_link_hash_table_create (abfd
)
3671 struct mips_elf_link_hash_table
*ret
;
3673 ret
= ((struct mips_elf_link_hash_table
*)
3674 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
3675 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
3678 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3679 mips_elf_link_hash_newfunc
))
3681 bfd_release (abfd
, ret
);
3686 /* We no longer use this. */
3687 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
3688 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
3690 ret
->procedure_count
= 0;
3691 ret
->compact_rel_size
= 0;
3692 ret
->use_rld_obj_head
= false;
3694 ret
->mips16_stubs_seen
= false;
3696 return &ret
->root
.root
;
3699 /* Hook called by the linker routine which adds symbols from an object
3700 file. We must handle the special MIPS section numbers here. */
3704 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3706 struct bfd_link_info
*info
;
3707 const Elf_Internal_Sym
*sym
;
3713 if (SGI_COMPAT (abfd
)
3714 && (abfd
->flags
& DYNAMIC
) != 0
3715 && strcmp (*namep
, "_rld_new_interface") == 0)
3717 /* Skip Irix 5 rld entry name. */
3722 switch (sym
->st_shndx
)
3725 /* Common symbols less than the GP size are automatically
3726 treated as SHN_MIPS_SCOMMON symbols. */
3727 if (sym
->st_size
> elf_gp_size (abfd
))
3730 case SHN_MIPS_SCOMMON
:
3731 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3732 (*secp
)->flags
|= SEC_IS_COMMON
;
3733 *valp
= sym
->st_size
;
3737 /* This section is used in a shared object. */
3738 if (mips_elf_text_section_ptr
== NULL
)
3740 /* Initialize the section. */
3741 mips_elf_text_section
.name
= ".text";
3742 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
3743 mips_elf_text_section
.output_section
= NULL
;
3744 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
3745 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
3746 mips_elf_text_symbol
.name
= ".text";
3747 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
3748 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
3749 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
3750 mips_elf_text_section_ptr
= &mips_elf_text_section
;
3752 /* This code used to do *secp = bfd_und_section_ptr if
3753 info->shared. I don't know why, and that doesn't make sense,
3754 so I took it out. */
3755 *secp
= mips_elf_text_section_ptr
;
3758 case SHN_MIPS_ACOMMON
:
3759 /* Fall through. XXX Can we treat this as allocated data? */
3761 /* This section is used in a shared object. */
3762 if (mips_elf_data_section_ptr
== NULL
)
3764 /* Initialize the section. */
3765 mips_elf_data_section
.name
= ".data";
3766 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
3767 mips_elf_data_section
.output_section
= NULL
;
3768 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
3769 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
3770 mips_elf_data_symbol
.name
= ".data";
3771 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
3772 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
3773 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
3774 mips_elf_data_section_ptr
= &mips_elf_data_section
;
3776 /* This code used to do *secp = bfd_und_section_ptr if
3777 info->shared. I don't know why, and that doesn't make sense,
3778 so I took it out. */
3779 *secp
= mips_elf_data_section_ptr
;
3782 case SHN_MIPS_SUNDEFINED
:
3783 *secp
= bfd_und_section_ptr
;
3787 if (SGI_COMPAT (abfd
)
3789 && info
->hash
->creator
== abfd
->xvec
3790 && strcmp (*namep
, "__rld_obj_head") == 0)
3792 struct elf_link_hash_entry
*h
;
3794 /* Mark __rld_obj_head as dynamic. */
3796 if (! (_bfd_generic_link_add_one_symbol
3797 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3798 (bfd_vma
) *valp
, (const char *) NULL
, false,
3799 get_elf_backend_data (abfd
)->collect
,
3800 (struct bfd_link_hash_entry
**) &h
)))
3802 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
3803 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3804 h
->type
= STT_OBJECT
;
3806 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3809 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3812 /* If this is a mips16 text symbol, add 1 to the value to make it
3813 odd. This will cause something like .word SYM to come up with
3814 the right value when it is loaded into the PC. */
3815 if (sym
->st_other
== STO_MIPS16
)
3821 /* Structure used to pass information to mips_elf_output_extsym. */
3826 struct bfd_link_info
*info
;
3827 struct ecoff_debug_info
*debug
;
3828 const struct ecoff_debug_swap
*swap
;
3832 /* This routine is used to write out ECOFF debugging external symbol
3833 information. It is called via mips_elf_link_hash_traverse. The
3834 ECOFF external symbol information must match the ELF external
3835 symbol information. Unfortunately, at this point we don't know
3836 whether a symbol is required by reloc information, so the two
3837 tables may wind up being different. We must sort out the external
3838 symbol information before we can set the final size of the .mdebug
3839 section, and we must set the size of the .mdebug section before we
3840 can relocate any sections, and we can't know which symbols are
3841 required by relocation until we relocate the sections.
3842 Fortunately, it is relatively unlikely that any symbol will be
3843 stripped but required by a reloc. In particular, it can not happen
3844 when generating a final executable. */
3847 mips_elf_output_extsym (h
, data
)
3848 struct mips_elf_link_hash_entry
*h
;
3851 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
3853 asection
*sec
, *output_section
;
3855 if (h
->root
.indx
== -2)
3857 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3858 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
3859 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3860 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
3862 else if (einfo
->info
->strip
== strip_all
3863 || (einfo
->info
->strip
== strip_some
3864 && bfd_hash_lookup (einfo
->info
->keep_hash
,
3865 h
->root
.root
.root
.string
,
3866 false, false) == NULL
))
3874 if (h
->esym
.ifd
== -2)
3877 h
->esym
.cobol_main
= 0;
3878 h
->esym
.weakext
= 0;
3879 h
->esym
.reserved
= 0;
3880 h
->esym
.ifd
= ifdNil
;
3881 h
->esym
.asym
.value
= 0;
3882 h
->esym
.asym
.st
= stGlobal
;
3884 if (SGI_COMPAT (einfo
->abfd
)
3885 && (h
->root
.root
.type
== bfd_link_hash_undefined
3886 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
3890 /* Use undefined class. Also, set class and type for some
3892 name
= h
->root
.root
.root
.string
;
3893 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
3894 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
3896 h
->esym
.asym
.sc
= scData
;
3897 h
->esym
.asym
.st
= stLabel
;
3898 h
->esym
.asym
.value
= 0;
3900 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
3902 h
->esym
.asym
.sc
= scAbs
;
3903 h
->esym
.asym
.st
= stLabel
;
3904 h
->esym
.asym
.value
=
3905 mips_elf_hash_table (einfo
->info
)->procedure_count
;
3907 else if (strcmp (name
, "_gp_disp") == 0)
3909 h
->esym
.asym
.sc
= scAbs
;
3910 h
->esym
.asym
.st
= stLabel
;
3911 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
3914 h
->esym
.asym
.sc
= scUndefined
;
3916 else if (h
->root
.root
.type
!= bfd_link_hash_defined
3917 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
3918 h
->esym
.asym
.sc
= scAbs
;
3923 sec
= h
->root
.root
.u
.def
.section
;
3924 output_section
= sec
->output_section
;
3926 /* When making a shared library and symbol h is the one from
3927 the another shared library, OUTPUT_SECTION may be null. */
3928 if (output_section
== NULL
)
3929 h
->esym
.asym
.sc
= scUndefined
;
3932 name
= bfd_section_name (output_section
->owner
, output_section
);
3934 if (strcmp (name
, ".text") == 0)
3935 h
->esym
.asym
.sc
= scText
;
3936 else if (strcmp (name
, ".data") == 0)
3937 h
->esym
.asym
.sc
= scData
;
3938 else if (strcmp (name
, ".sdata") == 0)
3939 h
->esym
.asym
.sc
= scSData
;
3940 else if (strcmp (name
, ".rodata") == 0
3941 || strcmp (name
, ".rdata") == 0)
3942 h
->esym
.asym
.sc
= scRData
;
3943 else if (strcmp (name
, ".bss") == 0)
3944 h
->esym
.asym
.sc
= scBss
;
3945 else if (strcmp (name
, ".sbss") == 0)
3946 h
->esym
.asym
.sc
= scSBss
;
3947 else if (strcmp (name
, ".init") == 0)
3948 h
->esym
.asym
.sc
= scInit
;
3949 else if (strcmp (name
, ".fini") == 0)
3950 h
->esym
.asym
.sc
= scFini
;
3952 h
->esym
.asym
.sc
= scAbs
;
3956 h
->esym
.asym
.reserved
= 0;
3957 h
->esym
.asym
.index
= indexNil
;
3960 if (h
->root
.root
.type
== bfd_link_hash_common
)
3961 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
3962 else if (h
->root
.root
.type
== bfd_link_hash_defined
3963 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3965 if (h
->esym
.asym
.sc
== scCommon
)
3966 h
->esym
.asym
.sc
= scBss
;
3967 else if (h
->esym
.asym
.sc
== scSCommon
)
3968 h
->esym
.asym
.sc
= scSBss
;
3970 sec
= h
->root
.root
.u
.def
.section
;
3971 output_section
= sec
->output_section
;
3972 if (output_section
!= NULL
)
3973 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
3974 + sec
->output_offset
3975 + output_section
->vma
);
3977 h
->esym
.asym
.value
= 0;
3979 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3981 /* Set type and value for a symbol with a function stub. */
3982 h
->esym
.asym
.st
= stProc
;
3983 sec
= h
->root
.root
.u
.def
.section
;
3985 h
->esym
.asym
.value
= 0;
3988 output_section
= sec
->output_section
;
3989 if (output_section
!= NULL
)
3990 h
->esym
.asym
.value
= (h
->root
.plt
.offset
3991 + sec
->output_offset
3992 + output_section
->vma
);
3994 h
->esym
.asym
.value
= 0;
4001 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
4002 h
->root
.root
.root
.string
,
4005 einfo
->failed
= true;
4012 /* Create a runtime procedure table from the .mdebug section. */
4015 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
4018 struct bfd_link_info
*info
;
4020 struct ecoff_debug_info
*debug
;
4022 const struct ecoff_debug_swap
*swap
;
4023 HDRR
*hdr
= &debug
->symbolic_header
;
4025 struct rpdr_ext
*erp
;
4027 struct pdr_ext
*epdr
;
4028 struct sym_ext
*esym
;
4031 unsigned long size
, count
;
4032 unsigned long sindex
;
4036 const char *no_name_func
= _("static procedure (no name)");
4044 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4046 sindex
= strlen (no_name_func
) + 1;
4047 count
= hdr
->ipdMax
;
4050 size
= swap
->external_pdr_size
;
4052 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
4056 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
4059 size
= sizeof (RPDR
);
4060 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
4064 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
4068 count
= hdr
->isymMax
;
4069 size
= swap
->external_sym_size
;
4070 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
4074 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
4077 count
= hdr
->issMax
;
4078 ss
= (char *) bfd_malloc (count
);
4081 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
4084 count
= hdr
->ipdMax
;
4085 for (i
= 0; i
< count
; i
++, rp
++)
4087 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
4088 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
4089 rp
->adr
= sym
.value
;
4090 rp
->regmask
= pdr
.regmask
;
4091 rp
->regoffset
= pdr
.regoffset
;
4092 rp
->fregmask
= pdr
.fregmask
;
4093 rp
->fregoffset
= pdr
.fregoffset
;
4094 rp
->frameoffset
= pdr
.frameoffset
;
4095 rp
->framereg
= pdr
.framereg
;
4096 rp
->pcreg
= pdr
.pcreg
;
4098 sv
[i
] = ss
+ sym
.iss
;
4099 sindex
+= strlen (sv
[i
]) + 1;
4103 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
4104 size
= BFD_ALIGN (size
, 16);
4105 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
4108 mips_elf_hash_table (info
)->procedure_count
= 0;
4112 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
4114 erp
= (struct rpdr_ext
*) rtproc
;
4115 memset (erp
, 0, sizeof (struct rpdr_ext
));
4117 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
4118 strcpy (str
, no_name_func
);
4119 str
+= strlen (no_name_func
) + 1;
4120 for (i
= 0; i
< count
; i
++)
4122 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
4123 strcpy (str
, sv
[i
]);
4124 str
+= strlen (sv
[i
]) + 1;
4126 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
4128 /* Set the size and contents of .rtproc section. */
4129 s
->_raw_size
= size
;
4130 s
->contents
= (bfd_byte
*) rtproc
;
4132 /* Skip this section later on (I don't think this currently
4133 matters, but someday it might). */
4134 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
4163 /* A comparison routine used to sort .gptab entries. */
4166 gptab_compare (p1
, p2
)
4170 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
4171 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
4173 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
4176 /* We need to use a special link routine to handle the .reginfo and
4177 the .mdebug sections. We need to merge all instances of these
4178 sections together, not write them all out sequentially. */
4181 mips_elf_final_link (abfd
, info
)
4183 struct bfd_link_info
*info
;
4187 struct bfd_link_order
*p
;
4188 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
4189 asection
*rtproc_sec
;
4190 Elf32_RegInfo reginfo
;
4191 struct ecoff_debug_info debug
;
4192 const struct ecoff_debug_swap
*swap
4193 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4194 HDRR
*symhdr
= &debug
.symbolic_header
;
4195 PTR mdebug_handle
= NULL
;
4197 /* Drop the .options section, since it has special semantics which I
4198 haven't bothered to figure out. */
4199 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
4201 if (strcmp ((*secpp
)->name
, ".options") == 0)
4203 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
4204 if (p
->type
== bfd_indirect_link_order
)
4205 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
4206 (*secpp
)->link_order_head
= NULL
;
4207 *secpp
= (*secpp
)->next
;
4208 --abfd
->section_count
;
4213 /* Get a value for the GP register. */
4214 if (elf_gp (abfd
) == 0)
4216 struct bfd_link_hash_entry
*h
;
4218 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4219 if (h
!= (struct bfd_link_hash_entry
*) NULL
4220 && h
->type
== bfd_link_hash_defined
)
4221 elf_gp (abfd
) = (h
->u
.def
.value
4222 + h
->u
.def
.section
->output_section
->vma
4223 + h
->u
.def
.section
->output_offset
);
4224 else if (info
->relocateable
)
4228 /* Make up a value. */
4230 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4233 && (strcmp (o
->name
, ".sbss") == 0
4234 || strcmp (o
->name
, ".sdata") == 0
4235 || strcmp (o
->name
, ".lit4") == 0
4236 || strcmp (o
->name
, ".lit8") == 0))
4239 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
4243 /* If the relocate_section function needs to do a reloc
4244 involving the GP value, it should make a reloc_dangerous
4245 callback to warn that GP is not defined. */
4249 /* Go through the sections and collect the .reginfo and .mdebug
4253 gptab_data_sec
= NULL
;
4254 gptab_bss_sec
= NULL
;
4255 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4257 if (strcmp (o
->name
, ".reginfo") == 0)
4259 memset (®info
, 0, sizeof reginfo
);
4261 /* We have found the .reginfo section in the output file.
4262 Look through all the link_orders comprising it and merge
4263 the information together. */
4264 for (p
= o
->link_order_head
;
4265 p
!= (struct bfd_link_order
*) NULL
;
4268 asection
*input_section
;
4270 Elf32_External_RegInfo ext
;
4273 if (p
->type
!= bfd_indirect_link_order
)
4275 if (p
->type
== bfd_fill_link_order
)
4280 input_section
= p
->u
.indirect
.section
;
4281 input_bfd
= input_section
->owner
;
4283 /* The linker emulation code has probably clobbered the
4284 size to be zero bytes. */
4285 if (input_section
->_raw_size
== 0)
4286 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4288 if (! bfd_get_section_contents (input_bfd
, input_section
,
4294 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
4296 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
4297 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
4298 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
4299 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
4300 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
4302 /* ri_gp_value is set by the function
4303 mips_elf32_section_processing when the section is
4304 finally written out. */
4306 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4307 elf_link_input_bfd ignores this section. */
4308 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4311 /* Force the section size to the value we want. */
4312 o
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4314 /* Skip this section later on (I don't think this currently
4315 matters, but someday it might). */
4316 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4321 if (strcmp (o
->name
, ".mdebug") == 0)
4323 struct extsym_info einfo
;
4325 /* We have found the .mdebug section in the output file.
4326 Look through all the link_orders comprising it and merge
4327 the information together. */
4328 symhdr
->magic
= swap
->sym_magic
;
4329 /* FIXME: What should the version stamp be? */
4331 symhdr
->ilineMax
= 0;
4335 symhdr
->isymMax
= 0;
4336 symhdr
->ioptMax
= 0;
4337 symhdr
->iauxMax
= 0;
4339 symhdr
->issExtMax
= 0;
4342 symhdr
->iextMax
= 0;
4344 /* We accumulate the debugging information itself in the
4345 debug_info structure. */
4347 debug
.external_dnr
= NULL
;
4348 debug
.external_pdr
= NULL
;
4349 debug
.external_sym
= NULL
;
4350 debug
.external_opt
= NULL
;
4351 debug
.external_aux
= NULL
;
4353 debug
.ssext
= debug
.ssext_end
= NULL
;
4354 debug
.external_fdr
= NULL
;
4355 debug
.external_rfd
= NULL
;
4356 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4358 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4359 if (mdebug_handle
== (PTR
) NULL
)
4362 if (SGI_COMPAT (abfd
))
4368 static const char * const name
[] =
4369 { ".text", ".init", ".fini", ".data",
4370 ".rodata", ".sdata", ".sbss", ".bss" };
4371 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
4372 scRData
, scSData
, scSBss
, scBss
};
4375 esym
.cobol_main
= 0;
4379 esym
.asym
.iss
= issNil
;
4380 esym
.asym
.st
= stLocal
;
4381 esym
.asym
.reserved
= 0;
4382 esym
.asym
.index
= indexNil
;
4384 for (i
= 0; i
< 8; i
++)
4386 esym
.asym
.sc
= sc
[i
];
4387 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4390 esym
.asym
.value
= s
->vma
;
4391 last
= s
->vma
+ s
->_raw_size
;
4394 esym
.asym
.value
= last
;
4396 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4402 for (p
= o
->link_order_head
;
4403 p
!= (struct bfd_link_order
*) NULL
;
4406 asection
*input_section
;
4408 const struct ecoff_debug_swap
*input_swap
;
4409 struct ecoff_debug_info input_debug
;
4413 if (p
->type
!= bfd_indirect_link_order
)
4415 if (p
->type
== bfd_fill_link_order
)
4420 input_section
= p
->u
.indirect
.section
;
4421 input_bfd
= input_section
->owner
;
4423 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4424 || (get_elf_backend_data (input_bfd
)
4425 ->elf_backend_ecoff_debug_swap
) == NULL
)
4427 /* I don't know what a non MIPS ELF bfd would be
4428 doing with a .mdebug section, but I don't really
4429 want to deal with it. */
4433 input_swap
= (get_elf_backend_data (input_bfd
)
4434 ->elf_backend_ecoff_debug_swap
);
4436 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
4438 /* The ECOFF linking code expects that we have already
4439 read in the debugging information and set up an
4440 ecoff_debug_info structure, so we do that now. */
4441 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
4445 if (! (bfd_ecoff_debug_accumulate
4446 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
4447 &input_debug
, input_swap
, info
)))
4450 /* Loop through the external symbols. For each one with
4451 interesting information, try to find the symbol in
4452 the linker global hash table and save the information
4453 for the output external symbols. */
4454 eraw_src
= input_debug
.external_ext
;
4455 eraw_end
= (eraw_src
4456 + (input_debug
.symbolic_header
.iextMax
4457 * input_swap
->external_ext_size
));
4459 eraw_src
< eraw_end
;
4460 eraw_src
+= input_swap
->external_ext_size
)
4464 struct mips_elf_link_hash_entry
*h
;
4466 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4467 if (ext
.asym
.sc
== scNil
4468 || ext
.asym
.sc
== scUndefined
4469 || ext
.asym
.sc
== scSUndefined
)
4472 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4473 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
4474 name
, false, false, true);
4475 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4481 < input_debug
.symbolic_header
.ifdMax
);
4482 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4488 /* Free up the information we just read. */
4489 free (input_debug
.line
);
4490 free (input_debug
.external_dnr
);
4491 free (input_debug
.external_pdr
);
4492 free (input_debug
.external_sym
);
4493 free (input_debug
.external_opt
);
4494 free (input_debug
.external_aux
);
4495 free (input_debug
.ss
);
4496 free (input_debug
.ssext
);
4497 free (input_debug
.external_fdr
);
4498 free (input_debug
.external_rfd
);
4499 free (input_debug
.external_ext
);
4501 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4502 elf_link_input_bfd ignores this section. */
4503 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4506 if (SGI_COMPAT (abfd
) && info
->shared
)
4508 /* Create .rtproc section. */
4509 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4510 if (rtproc_sec
== NULL
)
4512 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4513 | SEC_LINKER_CREATED
| SEC_READONLY
);
4515 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4516 if (rtproc_sec
== NULL
4517 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4518 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
4522 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
4523 info
, rtproc_sec
, &debug
))
4527 /* Build the external symbol information. */
4530 einfo
.debug
= &debug
;
4532 einfo
.failed
= false;
4533 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4534 mips_elf_output_extsym
,
4539 /* Set the size of the .mdebug section. */
4540 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4542 /* Skip this section later on (I don't think this currently
4543 matters, but someday it might). */
4544 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4549 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4551 const char *subname
;
4554 Elf32_External_gptab
*ext_tab
;
4557 /* The .gptab.sdata and .gptab.sbss sections hold
4558 information describing how the small data area would
4559 change depending upon the -G switch. These sections
4560 not used in executables files. */
4561 if (! info
->relocateable
)
4565 for (p
= o
->link_order_head
;
4566 p
!= (struct bfd_link_order
*) NULL
;
4569 asection
*input_section
;
4571 if (p
->type
!= bfd_indirect_link_order
)
4573 if (p
->type
== bfd_fill_link_order
)
4578 input_section
= p
->u
.indirect
.section
;
4580 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4581 elf_link_input_bfd ignores this section. */
4582 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4585 /* Skip this section later on (I don't think this
4586 currently matters, but someday it might). */
4587 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4589 /* Really remove the section. */
4590 for (secpp
= &abfd
->sections
;
4592 secpp
= &(*secpp
)->next
)
4594 *secpp
= (*secpp
)->next
;
4595 --abfd
->section_count
;
4600 /* There is one gptab for initialized data, and one for
4601 uninitialized data. */
4602 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4604 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4608 (*_bfd_error_handler
)
4609 (_("%s: illegal section name `%s'"),
4610 bfd_get_filename (abfd
), o
->name
);
4611 bfd_set_error (bfd_error_nonrepresentable_section
);
4615 /* The linker script always combines .gptab.data and
4616 .gptab.sdata into .gptab.sdata, and likewise for
4617 .gptab.bss and .gptab.sbss. It is possible that there is
4618 no .sdata or .sbss section in the output file, in which
4619 case we must change the name of the output section. */
4620 subname
= o
->name
+ sizeof ".gptab" - 1;
4621 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4623 if (o
== gptab_data_sec
)
4624 o
->name
= ".gptab.data";
4626 o
->name
= ".gptab.bss";
4627 subname
= o
->name
+ sizeof ".gptab" - 1;
4628 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4631 /* Set up the first entry. */
4633 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
4636 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4637 tab
[0].gt_header
.gt_unused
= 0;
4639 /* Combine the input sections. */
4640 for (p
= o
->link_order_head
;
4641 p
!= (struct bfd_link_order
*) NULL
;
4644 asection
*input_section
;
4648 bfd_size_type gpentry
;
4650 if (p
->type
!= bfd_indirect_link_order
)
4652 if (p
->type
== bfd_fill_link_order
)
4657 input_section
= p
->u
.indirect
.section
;
4658 input_bfd
= input_section
->owner
;
4660 /* Combine the gptab entries for this input section one
4661 by one. We know that the input gptab entries are
4662 sorted by ascending -G value. */
4663 size
= bfd_section_size (input_bfd
, input_section
);
4665 for (gpentry
= sizeof (Elf32_External_gptab
);
4667 gpentry
+= sizeof (Elf32_External_gptab
))
4669 Elf32_External_gptab ext_gptab
;
4670 Elf32_gptab int_gptab
;
4676 if (! (bfd_get_section_contents
4677 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4678 gpentry
, sizeof (Elf32_External_gptab
))))
4684 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
4686 val
= int_gptab
.gt_entry
.gt_g_value
;
4687 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4690 for (look
= 1; look
< c
; look
++)
4692 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4693 tab
[look
].gt_entry
.gt_bytes
+= add
;
4695 if (tab
[look
].gt_entry
.gt_g_value
== val
)
4701 Elf32_gptab
*new_tab
;
4704 /* We need a new table entry. */
4705 new_tab
= ((Elf32_gptab
*)
4706 bfd_realloc ((PTR
) tab
,
4707 (c
+ 1) * sizeof (Elf32_gptab
)));
4708 if (new_tab
== NULL
)
4714 tab
[c
].gt_entry
.gt_g_value
= val
;
4715 tab
[c
].gt_entry
.gt_bytes
= add
;
4717 /* Merge in the size for the next smallest -G
4718 value, since that will be implied by this new
4721 for (look
= 1; look
< c
; look
++)
4723 if (tab
[look
].gt_entry
.gt_g_value
< val
4725 || (tab
[look
].gt_entry
.gt_g_value
4726 > tab
[max
].gt_entry
.gt_g_value
)))
4730 tab
[c
].gt_entry
.gt_bytes
+=
4731 tab
[max
].gt_entry
.gt_bytes
;
4736 last
= int_gptab
.gt_entry
.gt_bytes
;
4739 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4740 elf_link_input_bfd ignores this section. */
4741 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4744 /* The table must be sorted by -G value. */
4746 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
4748 /* Swap out the table. */
4749 ext_tab
= ((Elf32_External_gptab
*)
4750 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
4751 if (ext_tab
== NULL
)
4757 for (i
= 0; i
< c
; i
++)
4758 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
4761 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
4762 o
->contents
= (bfd_byte
*) ext_tab
;
4764 /* Skip this section later on (I don't think this currently
4765 matters, but someday it might). */
4766 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4770 /* Invoke the regular ELF backend linker to do all the work. */
4771 if (! bfd_elf32_bfd_final_link (abfd
, info
))
4774 /* Now write out the computed sections. */
4776 if (reginfo_sec
!= (asection
*) NULL
)
4778 Elf32_External_RegInfo ext
;
4780 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
4781 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4782 (file_ptr
) 0, sizeof ext
))
4786 if (mdebug_sec
!= (asection
*) NULL
)
4788 BFD_ASSERT (abfd
->output_has_begun
);
4789 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4791 mdebug_sec
->filepos
))
4794 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4797 if (gptab_data_sec
!= (asection
*) NULL
)
4799 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4800 gptab_data_sec
->contents
,
4802 gptab_data_sec
->_raw_size
))
4806 if (gptab_bss_sec
!= (asection
*) NULL
)
4808 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4809 gptab_bss_sec
->contents
,
4811 gptab_bss_sec
->_raw_size
))
4815 if (SGI_COMPAT (abfd
))
4817 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4818 if (rtproc_sec
!= NULL
)
4820 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
4821 rtproc_sec
->contents
,
4823 rtproc_sec
->_raw_size
))
4831 /* Handle a MIPS ELF HI16 reloc. */
4834 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
4836 Elf_Internal_Rela
*relhi
;
4837 Elf_Internal_Rela
*rello
;
4844 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4846 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4849 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4851 if ((addlo
& 0x8000) != 0)
4853 if ((addend
& 0x8000) != 0)
4856 bfd_put_32 (input_bfd
,
4857 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
4858 contents
+ relhi
->r_offset
);
4861 /* Handle a MIPS ELF local GOT16 reloc. */
4864 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
4869 Elf_Internal_Rela
*relhi
;
4870 Elf_Internal_Rela
*rello
;
4874 unsigned int assigned_gotno
;
4880 bfd_byte
*got_contents
;
4881 struct mips_got_info
*g
;
4883 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4885 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4888 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4890 if ((addlo
& 0x8000) != 0)
4892 if ((addend
& 0x8000) != 0)
4895 /* Get a got entry representing requested hipage. */
4896 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4897 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4898 BFD_ASSERT (g
!= NULL
);
4900 assigned_gotno
= g
->assigned_gotno
;
4901 got_contents
= sgot
->contents
;
4902 hipage
= addend
& 0xffff0000;
4904 for (i
= MIPS_RESERVED_GOTNO
; i
< assigned_gotno
; i
++)
4906 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
4907 if (hipage
== (address
& 0xffff0000))
4911 if (i
== assigned_gotno
)
4913 if (assigned_gotno
>= g
->local_gotno
)
4915 (*_bfd_error_handler
)
4916 (_("more got entries are needed for hipage relocations"));
4917 bfd_set_error (bfd_error_bad_value
);
4921 bfd_put_32 (input_bfd
, hipage
, got_contents
+ assigned_gotno
* 4);
4922 ++g
->assigned_gotno
;
4925 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
4926 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
4927 contents
+ relhi
->r_offset
);
4932 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
4935 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
4937 Elf_Internal_Rela
*rel
;
4943 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4944 bfd_put_32 (input_bfd
,
4945 (insn
& 0xffff0000) | (offset
& 0xffff),
4946 contents
+ rel
->r_offset
);
4949 /* Relocate a MIPS ELF section. */
4952 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4953 contents
, relocs
, local_syms
, local_sections
)
4955 struct bfd_link_info
*info
;
4957 asection
*input_section
;
4959 Elf_Internal_Rela
*relocs
;
4960 Elf_Internal_Sym
*local_syms
;
4961 asection
**local_sections
;
4963 Elf_Internal_Shdr
*symtab_hdr
;
4966 asection
*sgot
, *sreloc
, *scpt
;
4969 Elf_Internal_Rela
*rel
;
4970 Elf_Internal_Rela
*relend
;
4971 struct mips_got_info
*g
;
4973 dynobj
= elf_hash_table (info
)->dynobj
;
4974 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4978 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
4981 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
4984 if (elf_bad_symtab (input_bfd
))
4986 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
4991 locsymcount
= symtab_hdr
->sh_info
;
4992 extsymoff
= symtab_hdr
->sh_info
;
4995 gp
= _bfd_get_gp_value (output_bfd
);
4998 relend
= relocs
+ input_section
->reloc_count
;
4999 for (; rel
< relend
; rel
++)
5002 reloc_howto_type
*howto
;
5003 unsigned long r_symndx
;
5005 struct elf_link_hash_entry
*h
;
5007 Elf_Internal_Sym
*sym
;
5008 struct mips_elf_link_hash_entry
*mh
;
5010 bfd_reloc_status_type r
;
5012 r_type
= ELF32_R_TYPE (rel
->r_info
);
5013 if (r_type
== R_MIPS_GNU_VTINHERIT
5014 || r_type
== R_MIPS_GNU_VTENTRY
)
5016 if ((r_type
< 0 || r_type
>= (int) R_MIPS_max
)
5017 /* start-sanitize-r5900 */
5018 && r_type
!= R_MIPS15_S3
5019 /* end-sanitize-r5900 */
5020 /* start-sanitize-sky */
5021 && r_type
!= R_MIPS_DVP_11_PCREL
5022 && r_type
!= R_MIPS_DVP_27_S4
5023 && r_type
!= R_MIPS_DVP_11_S4
5024 && r_type
!= R_MIPS_DVP_U15_S3
5025 /* end-sanitize-sky */
5026 && r_type
!= R_MIPS16_26
5027 && r_type
!= R_MIPS16_GPREL
)
5029 bfd_set_error (bfd_error_bad_value
);
5032 if (r_type
== R_MIPS16_26
)
5033 howto
= &elf_mips16_jump_howto
;
5034 else if (r_type
== R_MIPS16_GPREL
)
5035 howto
= &elf_mips16_gprel_howto
;
5036 /* start-sanitize-r5900 */
5037 else if (r_type
== R_MIPS15_S3
)
5038 howto
= &elf_mips15_s3_howto
;
5039 /* end-sanitize-r5900 */
5040 /* start-sanitize-sky */
5041 else if (r_type
== R_MIPS_DVP_11_PCREL
)
5042 howto
= &elf_mips_dvp_11_pcrel_howto
;
5043 else if (r_type
== R_MIPS_DVP_27_S4
)
5044 howto
= &elf_mips_dvp_27_s4_howto
;
5045 else if (r_type
== R_MIPS_DVP_11_S4
)
5046 howto
= &elf_mips_dvp_11_s4_howto
;
5047 else if (r_type
== R_MIPS_DVP_U15_S3
)
5048 howto
= &elf_mips_dvp_u15_s3_howto
;
5049 /* end-sanitize-sky */
5051 howto
= elf_mips_howto_table
+ r_type
;
5054 && (r_type
== R_MIPS_CALL16
5055 || r_type
== R_MIPS_GOT16
5056 || r_type
== R_MIPS_CALL_HI16
5057 || r_type
== R_MIPS_CALL_LO16
5058 || r_type
== R_MIPS_GOT_HI16
5059 || r_type
== R_MIPS_GOT_LO16
))
5061 /* We need the .got section. */
5064 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5065 BFD_ASSERT (sgot
!= NULL
);
5066 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5067 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5068 BFD_ASSERT (g
!= NULL
);
5072 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5074 /* Mix in the change in GP address for a GP relative reloc. */
5075 if (r_type
!= R_MIPS_GPREL16
5076 && r_type
!= R_MIPS_LITERAL
5077 && r_type
!= R_MIPS_GPREL32
5078 && r_type
!= R_MIPS16_GPREL
)
5084 if (! ((*info
->callbacks
->reloc_dangerous
)
5086 _("GP relative relocation when GP not defined"),
5087 input_bfd
, input_section
,
5090 /* Only give the error once per link. */
5092 _bfd_set_gp_value (output_bfd
, gp
);
5095 if (r_symndx
< extsymoff
5096 || (elf_bad_symtab (input_bfd
)
5097 && local_sections
[r_symndx
] != NULL
))
5099 /* This is a relocation against a section. The current
5100 addend in the instruction is the difference between
5101 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
5102 must change this to be the difference between the
5103 final definition (which will end up in RELOCATION)
5104 and the GP value of OUTPUT_BFD (which is in GP). */
5105 addend
= elf_gp (input_bfd
) - gp
;
5107 else if (! info
->relocateable
)
5109 /* We are doing a final link. The current addend in the
5110 instruction is simply the desired offset into the
5111 symbol (normally zero). We want the instruction to
5112 hold the difference between the final definition of
5113 the symbol (which will end up in RELOCATION) and the
5114 GP value of OUTPUT_BFD (which is in GP). */
5119 /* We are generating relocateable output, and we aren't
5120 going to define this symbol, so we just leave the
5121 instruction alone. */
5129 if (info
->relocateable
)
5131 /* This is a relocateable link. We don't have to change
5132 anything, unless the reloc is against a section symbol,
5133 in which case we have to adjust according to where the
5134 section symbol winds up in the output section. */
5135 if (r_symndx
>= locsymcount
5136 || (elf_bad_symtab (input_bfd
)
5137 && local_sections
[r_symndx
] == NULL
))
5141 sym
= local_syms
+ r_symndx
;
5142 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5146 sec
= local_sections
[r_symndx
];
5148 /* It would be logical to add sym->st_value here,
5149 but Irix 5 sometimes generates a garbage symbol
5151 addend
+= sec
->output_offset
;
5153 /* If this is HI16 or GOT16 with an associated LO16,
5154 adjust the addend accordingly. Otherwise, just
5156 if (r_type
== R_MIPS_64
&& bfd_big_endian (input_bfd
))
5157 r
= _bfd_relocate_contents (howto
, input_bfd
,
5159 contents
+ rel
->r_offset
+ 4);
5160 else if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
5161 r
= _bfd_relocate_contents (howto
, input_bfd
,
5163 contents
+ rel
->r_offset
);
5166 Elf_Internal_Rela
*lorel
;
5168 /* As a GNU extension, permit an arbitrary
5169 number of R_MIPS_HI16 relocs before the
5170 R_MIPS_LO16 reloc. This permits gcc to emit
5171 the HI and LO relocs itself. */
5172 if (r_type
== R_MIPS_GOT16
)
5176 for (lorel
= rel
+ 1;
5178 && (ELF32_R_TYPE (lorel
->r_info
)
5184 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5186 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5191 r
= _bfd_relocate_contents (howto
, input_bfd
,
5193 contents
+ rel
->r_offset
);
5202 boolean undefined_error
;
5204 /* This is a final link. */
5205 undefined_error
= false;
5207 if (r_symndx
< extsymoff
5208 || (elf_bad_symtab (input_bfd
)
5209 && local_sections
[r_symndx
] != NULL
))
5212 sym
= local_syms
+ r_symndx
;
5213 sec
= local_sections
[r_symndx
];
5214 relocation
= (sec
->output_section
->vma
5215 + sec
->output_offset
);
5217 /* It would be logical to always add sym->st_value here,
5218 but Irix 5 sometimes generates a garbage symbol
5220 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5221 relocation
+= sym
->st_value
;
5223 /* mips16 text labels should be treated as odd. */
5224 if (sym
->st_other
== STO_MIPS16
)
5232 indx
= r_symndx
- extsymoff
;
5233 h
= elf_sym_hashes (input_bfd
)[indx
];
5234 while (h
->root
.type
== bfd_link_hash_indirect
5235 || h
->root
.type
== bfd_link_hash_warning
)
5236 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5237 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
5241 if (! ((*info
->callbacks
->reloc_dangerous
)
5243 _("_gp_disp used when GP not defined"),
5244 input_bfd
, input_section
,
5247 /* Only give the error once per link. */
5249 _bfd_set_gp_value (output_bfd
, gp
);
5254 sec
= input_section
;
5255 if (sec
->output_section
!= NULL
)
5258 + sec
->output_section
->vma
5259 + sec
->output_offset
));
5261 relocation
= gp
- rel
->r_offset
;
5262 if (r_type
== R_MIPS_LO16
)
5266 else if (h
->root
.type
== bfd_link_hash_defined
5267 || h
->root
.type
== bfd_link_hash_defweak
)
5269 sec
= h
->root
.u
.def
.section
;
5270 if (sec
->output_section
== NULL
)
5273 relocation
= (h
->root
.u
.def
.value
5274 + sec
->output_section
->vma
5275 + sec
->output_offset
);
5277 else if (h
->root
.type
== bfd_link_hash_undefweak
)
5279 else if (info
->shared
&& ! info
->symbolic
)
5281 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
5283 /* If this is a dynamic link, we should have created
5284 a _DYNAMIC_LINK symbol in
5285 mips_elf_create_dynamic_sections. Otherwise, we
5286 should define the symbol with a value of 0.
5287 FIXME: It should probably get into the symbol
5288 table somehow as well. */
5289 BFD_ASSERT (! info
->shared
);
5290 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
5291 ".dynamic") == NULL
);
5296 if (! ((*info
->callbacks
->undefined_symbol
)
5297 (info
, h
->root
.root
.string
, input_bfd
,
5298 input_section
, rel
->r_offset
)))
5300 undefined_error
= true;
5305 mh
= (struct mips_elf_link_hash_entry
*) h
;
5308 else if (sym
!= NULL
)
5309 other
= sym
->st_other
;
5313 /* If this function has an fn_stub, then it is a mips16
5314 function which needs a stub if it is called by a 32 bit
5315 function. If this reloc is anything other than a 16 bit
5316 call, redirect the reloc to the stub. We don't redirect
5317 relocs from other stub functions. */
5318 if (r_type
!= R_MIPS16_26
5320 && mh
->fn_stub
!= NULL
)
5322 && elf_tdata (input_bfd
)->local_stubs
!= NULL
5323 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
5324 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5325 FN_STUB
, sizeof FN_STUB
- 1) != 0
5326 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5327 CALL_STUB
, sizeof CALL_STUB
- 1) != 0
5328 && strncmp (bfd_get_section_name (input_bfd
, input_section
),
5329 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) != 0)
5333 BFD_ASSERT (mh
->need_fn_stub
);
5334 relocation
= (mh
->fn_stub
->output_section
->vma
5335 + mh
->fn_stub
->output_offset
);
5341 fn_stub
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
5342 relocation
= (fn_stub
->output_section
->vma
5343 + fn_stub
->output_offset
);
5346 /* RELOCATION now points to 32 bit code. */
5350 /* If this function has a call_stub, then it is called by a
5351 mips16 function; the call needs to go through a stub if
5352 this function is a 32 bit function. If this reloc is a
5353 16 bit call, and the symbol is not a 16 bit function,
5354 then redirect the reloc to the stub. Note that we don't
5355 need to worry about calling the function through a
5356 function pointer; such calls are handled by routing
5357 through a special mips16 routine. We don't have to check
5358 whether this call is from a stub; it can't be, because a
5359 stub contains 32 bit code, and hence can not have a 16
5361 if (r_type
== R_MIPS16_26
5363 && (mh
->call_stub
!= NULL
|| mh
->call_fp_stub
!= NULL
)
5364 && other
!= STO_MIPS16
)
5368 /* If both call_stub and call_fp_stub are defined, we
5369 can figure out which one to use by seeing which one
5370 appears in the input file. */
5371 if (mh
->call_stub
!= NULL
&& mh
->call_fp_stub
!= NULL
)
5376 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
5378 if (strncmp (bfd_get_section_name (input_bfd
, o
),
5379 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5381 stub
= mh
->call_fp_stub
;
5386 stub
= mh
->call_stub
;
5388 else if (mh
->call_stub
!= NULL
)
5389 stub
= mh
->call_stub
;
5391 stub
= mh
->call_fp_stub
;
5393 BFD_ASSERT (stub
->_raw_size
> 0);
5394 relocation
= stub
->output_section
->vma
+ stub
->output_offset
;
5397 if (r_type
== R_MIPS_HI16
)
5399 Elf_Internal_Rela
*lorel
;
5401 /* As a GNU extension, permit an arbitrary number of
5402 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
5403 This permits gcc to emit the HI and LO relocs itself. */
5404 for (lorel
= rel
+ 1;
5406 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
5410 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
5412 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
5413 contents
, relocation
+ addend
);
5417 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5418 contents
, rel
->r_offset
,
5419 relocation
, addend
);
5421 else if (r_type
== R_MIPS_GOT16
&& local
)
5423 /* GOT16 must also have an associated LO16 in the local
5424 case. In this case, the addend is extracted and the
5425 section in which the referenced object is determined.
5426 Then the final address of the object is computed and
5427 the GOT entry for the hipage (an aligned 64kb chunk)
5428 is added to .got section if needed. The offset field
5429 of the GOT16-relocated instruction is replaced by the
5430 index of this GOT entry for the hipage. */
5431 if ((rel
+ 1) < relend
5432 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
5434 if (! mips_elf_relocate_got_local (output_bfd
, input_bfd
,
5437 relocation
+ addend
))
5442 r
= bfd_reloc_outofrange
;
5444 else if (r_type
== R_MIPS_CALL16
5445 || r_type
== R_MIPS_GOT16
5446 || r_type
== R_MIPS_CALL_LO16
5447 || r_type
== R_MIPS_GOT_LO16
)
5451 /* This symbol must be registered as a global symbol
5452 having the corresponding got entry. */
5453 BFD_ASSERT (h
->got
.offset
!= (bfd_vma
) -1);
5455 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5456 BFD_ASSERT (g
->local_gotno
<= offset
5457 && offset
< sgot
->_raw_size
);
5458 bfd_put_32 (output_bfd
, relocation
+ addend
,
5459 sgot
->contents
+ offset
);
5460 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5462 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
5466 else if (r_type
== R_MIPS_CALL_HI16
5467 || r_type
== R_MIPS_GOT_HI16
)
5471 /* This must be a global symbol with a got entry. The
5472 next reloc must be the corresponding LO16 reloc. */
5473 BFD_ASSERT (h
!= NULL
&& h
->got
.offset
!= (bfd_vma
) -1);
5474 BFD_ASSERT ((rel
+ 1) < relend
);
5475 BFD_ASSERT ((int) ELF32_R_TYPE ((rel
+ 1)->r_info
)
5476 == (r_type
== R_MIPS_CALL_HI16
5477 ? (int) R_MIPS_CALL_LO16
5478 : (int) R_MIPS_GOT_LO16
));
5480 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5481 BFD_ASSERT (g
->local_gotno
<= offset
5482 && offset
< sgot
->_raw_size
);
5483 bfd_put_32 (output_bfd
, relocation
+ addend
,
5484 sgot
->contents
+ offset
);
5485 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
5487 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
5491 else if (r_type
== R_MIPS_REL32
5492 || r_type
== R_MIPS_32
)
5494 Elf_Internal_Rel outrel
;
5495 Elf32_crinfo cptrel
;
5499 || (elf_hash_table (info
)->dynamic_sections_created
5501 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
5503 && (input_section
->flags
& SEC_ALLOC
) != 0)
5507 /* When generating a shared object, these
5508 relocations are copied into the output file to be
5509 resolved at run time. */
5512 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5513 BFD_ASSERT (sreloc
!= NULL
);
5518 if (elf_section_data (input_section
)->stab_info
== NULL
)
5519 outrel
.r_offset
= rel
->r_offset
;
5524 off
= (_bfd_stab_section_offset
5525 (output_bfd
, &elf_hash_table (info
)->stab_info
,
5527 &elf_section_data (input_section
)->stab_info
,
5529 if (off
== (bfd_vma
) -1)
5531 outrel
.r_offset
= off
;
5534 outrel
.r_offset
+= (input_section
->output_section
->vma
5535 + input_section
->output_offset
);
5537 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5540 memset (&outrel
, 0, sizeof outrel
);
5542 && (! info
->symbolic
5543 || (h
->elf_link_hash_flags
5544 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5546 BFD_ASSERT (h
->dynindx
!= -1);
5547 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
5548 sec
= input_section
;
5555 sec
= local_sections
[r_symndx
];
5558 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
5560 == bfd_link_hash_defweak
));
5561 sec
= h
->root
.u
.def
.section
;
5563 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5565 else if (sec
== NULL
|| sec
->owner
== NULL
)
5567 bfd_set_error (bfd_error_bad_value
);
5574 osec
= sec
->output_section
;
5575 indx
= elf_section_data (osec
)->dynindx
;
5580 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
5581 addend
+= relocation
;
5585 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
5587 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
5588 (((Elf32_External_Rel
*)
5590 + sreloc
->reloc_count
));
5591 ++sreloc
->reloc_count
;
5593 if (! skip
&& SGI_COMPAT (output_bfd
))
5598 /* Make an entry of compact relocation info. */
5599 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5600 cptrel
.vaddr
= (rel
->r_offset
5601 + input_section
->output_section
->vma
5602 + input_section
->output_offset
);
5603 if (r_type
== R_MIPS_REL32
)
5604 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5606 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5607 mips_elf_set_cr_dist2to (cptrel
, 0);
5608 cptrel
.konst
= addend
;
5610 cr
= (scpt
->contents
5611 + sizeof (Elf32_External_compact_rel
));
5612 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5613 ((Elf32_External_crinfo
*) cr
5614 + scpt
->reloc_count
));
5615 ++scpt
->reloc_count
;
5618 /* This reloc will be computed at runtime, so
5619 there's no need to do anything now. */
5623 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5624 contents
, rel
->r_offset
,
5625 relocation
, addend
);
5627 else if (r_type
== R_MIPS_64
)
5632 /* Do a 32 bit relocation, and sign extend to 64 bits. */
5633 addr
= rel
->r_offset
;
5634 if (bfd_big_endian (input_bfd
))
5636 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5637 contents
, addr
, relocation
,
5639 val
= bfd_get_32 (input_bfd
, contents
+ addr
);
5640 if ((val
& 0x80000000) != 0)
5644 addr
= rel
->r_offset
;
5645 if (bfd_little_endian (input_bfd
))
5647 bfd_put_32 (input_bfd
, val
, contents
+ addr
);
5649 else if (r_type
== R_MIPS_26
&& other
== STO_MIPS16
)
5653 /* This is a jump to a mips16 routine from a mips32
5654 routine. We need to change jal into jalx. */
5655 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5656 if (((insn
>> 26) & 0x3f) != 0x3
5657 && ((insn
>> 26) & 0x3f) != 0x1d)
5659 (*_bfd_error_handler
)
5660 (_("%s: %s+0x%lx: jump to mips16 routine which is not jal"),
5661 bfd_get_filename (input_bfd
),
5662 input_section
->name
,
5663 (unsigned long) rel
->r_offset
);
5664 bfd_set_error (bfd_error_bad_value
);
5667 insn
= (insn
& 0x3ffffff) | (0x1d << 26);
5668 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5669 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5670 contents
, rel
->r_offset
,
5671 relocation
, addend
);
5673 else if (r_type
== R_MIPS16_26
)
5675 /* It's easiest to do the normal relocation, and then
5676 dig out the instruction and swap the first word the
5677 way the mips16 expects it. If this is little endian,
5678 though, we need to swap the two words first, and then
5679 swap them back again later, so that the address looks
5682 if (bfd_little_endian (input_bfd
))
5686 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5687 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5688 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5691 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5692 contents
, rel
->r_offset
,
5693 relocation
, addend
);
5694 if (r
== bfd_reloc_ok
)
5698 if (bfd_little_endian (input_bfd
))
5700 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5701 insn
= ((insn
>> 16) & 0xffff) | ((insn
& 0xffff) << 16);
5702 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5705 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5706 insn
= ((insn
& 0xfc00)
5707 | ((insn
& 0x1f) << 5)
5708 | ((insn
& 0x3e0) >> 5));
5709 /* If this is a jump to a 32 bit routine, then make
5711 if (other
!= STO_MIPS16
)
5713 bfd_put_16 (input_bfd
, insn
, contents
+ rel
->r_offset
);
5716 else if (r_type
== R_MIPS16_GPREL
)
5718 unsigned short extend
, insn
;
5720 unsigned long final
;
5722 /* Extract the addend into buf, run the regular reloc,
5723 and stuff the resulting value back into the
5725 if (rel
->r_offset
> input_section
->_raw_size
)
5726 r
= bfd_reloc_outofrange
;
5729 extend
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
5730 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 2);
5731 bfd_put_32 (input_bfd
,
5732 (((extend
& 0x1f) << 11)
5736 r
= _bfd_final_link_relocate (howto
, input_bfd
,
5738 (bfd_vma
) 0, relocation
,
5740 final
= bfd_get_32 (input_bfd
, buf
);
5741 bfd_put_16 (input_bfd
,
5743 | ((final
>> 11) & 0x1f)
5745 contents
+ rel
->r_offset
);
5746 bfd_put_16 (input_bfd
,
5749 contents
+ rel
->r_offset
+ 2);
5752 /* start-sanitize-sky */
5753 else if (r_type
== R_MIPS_DVP_U15_S3
)
5755 if (rel
->r_offset
> input_section
->_raw_size
)
5756 r
= bfd_reloc_outofrange
;
5761 relocation
+= rel
->r_addend
;
5764 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5765 relocation
+= ((x
& (0xf << 21)) >> 10) + (x
& 0x7ff);
5766 x
&= ~ ((0xf << 21) | 0x7ff);
5767 x
|= (((relocation
& 0x7800) << 10)
5768 | (relocation
& 0x7ff));
5769 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
5771 if (relocation
& ~ (bfd_vma
) 0x7fff)
5772 r
= bfd_reloc_overflow
;
5777 /* end-sanitize-sky */
5779 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5780 contents
, rel
->r_offset
,
5781 relocation
, addend
);
5783 /* The jal instruction can only jump to an address which is
5784 divisible by 4, and it can only jump to an address with
5785 the same upper 4 bits as the PC. */
5786 if (r
== bfd_reloc_ok
5787 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
))
5792 if (other
== STO_MIPS16
)
5793 addr
&= ~ (bfd_vma
) 1;
5796 || ((addr
& 0xf0000000)
5797 != ((input_section
->output_section
->vma
5798 + input_section
->output_offset
5801 r
= bfd_reloc_overflow
;
5804 /* Don't bother to report a relocation overflow for a call
5805 to a weak undefined symbol with a value of zero. This
5808 even if we aren't in range to call address zero. */
5809 if (r
== bfd_reloc_overflow
5810 && (r_type
== R_MIPS16_26
|| r_type
== R_MIPS_26
)
5811 && relocation
+ addend
== 0
5813 && h
->root
.type
== bfd_link_hash_undefweak
)
5816 /* If we've already issued an error for an undefined symbol,
5817 don't issue another useless error. */
5819 && (r
== bfd_reloc_undefined
|| r
== bfd_reloc_overflow
))
5822 if (SGI_COMPAT (abfd
)
5824 && (input_section
->flags
& SEC_ALLOC
) != 0)
5826 Elf32_crinfo cptrel
;
5829 /* Make an entry of compact relocation info. */
5830 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5831 cptrel
.vaddr
= (rel
->r_offset
5832 + input_section
->output_section
->vma
5833 + input_section
->output_offset
);
5838 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
5839 /* XXX How should we set dist2to in this case. */
5840 mips_elf_set_cr_dist2to (cptrel
, 8);
5841 cptrel
.konst
= addend
+ relocation
;
5842 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5843 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5844 ((Elf32_External_crinfo
*) cr
5845 + scpt
->reloc_count
));
5846 ++scpt
->reloc_count
;
5849 case R_MIPS_GPREL16
:
5850 case R_MIPS_LITERAL
:
5851 case R_MIPS_GPREL32
:
5852 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
5853 cptrel
.konst
= gp
- cptrel
.vaddr
;
5854 mips_elf_set_cr_dist2to (cptrel
, 4);
5855 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
5856 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5857 ((Elf32_External_crinfo
*) cr
5858 + scpt
->reloc_count
));
5859 ++scpt
->reloc_count
;
5868 if (r
!= bfd_reloc_ok
)
5873 case bfd_reloc_outofrange
:
5875 case bfd_reloc_overflow
:
5880 name
= h
->root
.root
.string
;
5883 name
= bfd_elf_string_from_elf_section (input_bfd
,
5884 symtab_hdr
->sh_link
,
5889 name
= bfd_section_name (input_bfd
, sec
);
5891 if (! ((*info
->callbacks
->reloc_overflow
)
5892 (info
, name
, howto
->name
, (bfd_vma
) 0,
5893 input_bfd
, input_section
, rel
->r_offset
)))
5904 /* This hook function is called before the linker writes out a global
5905 symbol. We mark symbols as small common if appropriate. This is
5906 also where we undo the increment of the value for a mips16 symbol. */
5910 mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
5912 struct bfd_link_info
*info
;
5914 Elf_Internal_Sym
*sym
;
5915 asection
*input_sec
;
5917 /* If we see a common symbol, which implies a relocatable link, then
5918 if a symbol was small common in an input file, mark it as small
5919 common in the output file. */
5920 if (sym
->st_shndx
== SHN_COMMON
5921 && strcmp (input_sec
->name
, ".scommon") == 0)
5922 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
5924 if (sym
->st_other
== STO_MIPS16
5925 && (sym
->st_value
& 1) != 0)
5931 /* Functions for the dynamic linker. */
5933 /* The name of the dynamic interpreter. This is put in the .interp
5936 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
5938 /* Create dynamic sections when linking against a dynamic object. */
5941 mips_elf_create_dynamic_sections (abfd
, info
)
5943 struct bfd_link_info
*info
;
5945 struct elf_link_hash_entry
*h
;
5947 register asection
*s
;
5948 const char * const *namep
;
5950 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5951 | SEC_LINKER_CREATED
| SEC_READONLY
);
5953 /* Mips ABI requests the .dynamic section to be read only. */
5954 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5957 if (! bfd_set_section_flags (abfd
, s
, flags
))
5961 /* We need to create .got section. */
5962 if (! mips_elf_create_got_section (abfd
, info
))
5965 /* Create .stub section. */
5966 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
5968 s
= bfd_make_section (abfd
, ".stub");
5970 || ! bfd_set_section_flags (abfd
, s
, flags
)
5971 || ! bfd_set_section_alignment (abfd
, s
, 2))
5975 if (SGI_COMPAT (abfd
)
5977 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
5979 s
= bfd_make_section (abfd
, ".rld_map");
5981 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
5982 || ! bfd_set_section_alignment (abfd
, s
, 2))
5986 if (SGI_COMPAT (abfd
))
5988 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
5991 if (! (_bfd_generic_link_add_one_symbol
5992 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
5993 (bfd_vma
) 0, (const char *) NULL
, false,
5994 get_elf_backend_data (abfd
)->collect
,
5995 (struct bfd_link_hash_entry
**) &h
)))
5997 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5998 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5999 h
->type
= STT_SECTION
;
6001 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6005 /* We need to create a .compact_rel section. */
6006 if (! mips_elf_create_compact_rel_section (abfd
, info
))
6009 /* Change aligments of some sections. */
6010 s
= bfd_get_section_by_name (abfd
, ".hash");
6012 bfd_set_section_alignment (abfd
, s
, 4);
6013 s
= bfd_get_section_by_name (abfd
, ".dynsym");
6015 bfd_set_section_alignment (abfd
, s
, 4);
6016 s
= bfd_get_section_by_name (abfd
, ".dynstr");
6018 bfd_set_section_alignment (abfd
, s
, 4);
6019 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6021 bfd_set_section_alignment (abfd
, s
, 4);
6022 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6024 bfd_set_section_alignment (abfd
, s
, 4);
6030 if (! (_bfd_generic_link_add_one_symbol
6031 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
6032 (bfd_vma
) 0, (const char *) NULL
, false,
6033 get_elf_backend_data (abfd
)->collect
,
6034 (struct bfd_link_hash_entry
**) &h
)))
6036 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6037 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6038 h
->type
= STT_SECTION
;
6040 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6043 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
6045 /* __rld_map is a four byte word located in the .data section
6046 and is filled in by the rtld to contain a pointer to
6047 the _r_debug structure. Its symbol value will be set in
6048 mips_elf_finish_dynamic_symbol. */
6049 s
= bfd_get_section_by_name (abfd
, ".rld_map");
6050 BFD_ASSERT (s
!= NULL
);
6053 if (! (_bfd_generic_link_add_one_symbol
6054 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
6055 (bfd_vma
) 0, (const char *) NULL
, false,
6056 get_elf_backend_data (abfd
)->collect
,
6057 (struct bfd_link_hash_entry
**) &h
)))
6059 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6060 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6061 h
->type
= STT_OBJECT
;
6063 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6071 /* Create the .compact_rel section. */
6074 mips_elf_create_compact_rel_section (abfd
, info
)
6076 struct bfd_link_info
*info
;
6079 register asection
*s
;
6081 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
6083 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
6086 s
= bfd_make_section (abfd
, ".compact_rel");
6088 || ! bfd_set_section_flags (abfd
, s
, flags
)
6089 || ! bfd_set_section_alignment (abfd
, s
, 2))
6092 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
6098 /* Create the .got section to hold the global offset table. */
6101 mips_elf_create_got_section (abfd
, info
)
6103 struct bfd_link_info
*info
;
6106 register asection
*s
;
6107 struct elf_link_hash_entry
*h
;
6108 struct mips_got_info
*g
;
6110 /* This function may be called more than once. */
6111 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
6114 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6115 | SEC_LINKER_CREATED
);
6117 s
= bfd_make_section (abfd
, ".got");
6119 || ! bfd_set_section_flags (abfd
, s
, flags
)
6120 || ! bfd_set_section_alignment (abfd
, s
, 4))
6123 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
6124 linker script because we don't want to define the symbol if we
6125 are not creating a global offset table. */
6127 if (! (_bfd_generic_link_add_one_symbol
6128 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
6129 (bfd_vma
) 0, (const char *) NULL
, false,
6130 get_elf_backend_data (abfd
)->collect
,
6131 (struct bfd_link_hash_entry
**) &h
)))
6133 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6134 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6135 h
->type
= STT_OBJECT
;
6138 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6141 /* The first several global offset table entries are reserved. */
6142 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
6144 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
6145 sizeof (struct mips_got_info
));
6148 g
->global_gotsym
= 0;
6149 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
6150 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
6151 if (elf_section_data (s
) == NULL
)
6154 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
6155 if (elf_section_data (s
) == NULL
)
6158 elf_section_data (s
)->tdata
= (PTR
) g
;
6163 /* Look through the relocs for a section during the first phase, and
6164 allocate space in the global offset table. */
6167 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
6169 struct bfd_link_info
*info
;
6171 const Elf_Internal_Rela
*relocs
;
6175 Elf_Internal_Shdr
*symtab_hdr
;
6176 struct elf_link_hash_entry
**sym_hashes
;
6177 struct mips_got_info
*g
;
6179 const Elf_Internal_Rela
*rel
;
6180 const Elf_Internal_Rela
*rel_end
;
6184 if (info
->relocateable
)
6187 dynobj
= elf_hash_table (info
)->dynobj
;
6188 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6189 sym_hashes
= elf_sym_hashes (abfd
);
6190 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
6192 /* Check for the mips16 stub sections. */
6194 name
= bfd_get_section_name (abfd
, sec
);
6195 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
6197 unsigned long r_symndx
;
6199 /* Look at the relocation information to figure out which symbol
6202 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6204 if (r_symndx
< extsymoff
6205 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6209 /* This stub is for a local symbol. This stub will only be
6210 needed if there is some relocation in this BFD, other
6211 than a 16 bit function call, which refers to this symbol. */
6212 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6214 Elf_Internal_Rela
*sec_relocs
;
6215 const Elf_Internal_Rela
*r
, *rend
;
6217 /* We can ignore stub sections when looking for relocs. */
6218 if ((o
->flags
& SEC_RELOC
) == 0
6219 || o
->reloc_count
== 0
6220 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
6221 sizeof FN_STUB
- 1) == 0
6222 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
6223 sizeof CALL_STUB
- 1) == 0
6224 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
6225 sizeof CALL_FP_STUB
- 1) == 0)
6228 sec_relocs
= (_bfd_elf32_link_read_relocs
6229 (abfd
, o
, (PTR
) NULL
,
6230 (Elf_Internal_Rela
*) NULL
,
6231 info
->keep_memory
));
6232 if (sec_relocs
== NULL
)
6235 rend
= sec_relocs
+ o
->reloc_count
;
6236 for (r
= sec_relocs
; r
< rend
; r
++)
6237 if (ELF32_R_SYM (r
->r_info
) == r_symndx
6238 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
6241 if (! info
->keep_memory
)
6250 /* There is no non-call reloc for this stub, so we do
6251 not need it. Since this function is called before
6252 the linker maps input sections to output sections, we
6253 can easily discard it by setting the SEC_EXCLUDE
6255 sec
->flags
|= SEC_EXCLUDE
;
6259 /* Record this stub in an array of local symbol stubs for
6261 if (elf_tdata (abfd
)->local_stubs
== NULL
)
6263 unsigned long symcount
;
6266 if (elf_bad_symtab (abfd
))
6267 symcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
6269 symcount
= symtab_hdr
->sh_info
;
6270 n
= (asection
**) bfd_zalloc (abfd
,
6271 symcount
* sizeof (asection
*));
6274 elf_tdata (abfd
)->local_stubs
= n
;
6277 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
6279 /* We don't need to set mips16_stubs_seen in this case.
6280 That flag is used to see whether we need to look through
6281 the global symbol table for stubs. We don't need to set
6282 it here, because we just have a local stub. */
6286 struct mips_elf_link_hash_entry
*h
;
6288 h
= ((struct mips_elf_link_hash_entry
*)
6289 sym_hashes
[r_symndx
- extsymoff
]);
6291 /* H is the symbol this stub is for. */
6294 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6297 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
6298 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6300 unsigned long r_symndx
;
6301 struct mips_elf_link_hash_entry
*h
;
6304 /* Look at the relocation information to figure out which symbol
6307 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6309 if (r_symndx
< extsymoff
6310 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6312 /* This stub was actually built for a static symbol defined
6313 in the same file. We assume that all static symbols in
6314 mips16 code are themselves mips16, so we can simply
6315 discard this stub. Since this function is called before
6316 the linker maps input sections to output sections, we can
6317 easily discard it by setting the SEC_EXCLUDE flag. */
6318 sec
->flags
|= SEC_EXCLUDE
;
6322 h
= ((struct mips_elf_link_hash_entry
*)
6323 sym_hashes
[r_symndx
- extsymoff
]);
6325 /* H is the symbol this stub is for. */
6327 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6328 loc
= &h
->call_fp_stub
;
6330 loc
= &h
->call_stub
;
6332 /* If we already have an appropriate stub for this function, we
6333 don't need another one, so we can discard this one. Since
6334 this function is called before the linker maps input sections
6335 to output sections, we can easily discard it by setting the
6336 SEC_EXCLUDE flag. We can also discard this section if we
6337 happen to already know that this is a mips16 function; it is
6338 not necessary to check this here, as it is checked later, but
6339 it is slightly faster to check now. */
6340 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
6342 sec
->flags
|= SEC_EXCLUDE
;
6347 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6357 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6362 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6363 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6364 BFD_ASSERT (g
!= NULL
);
6370 rel_end
= relocs
+ sec
->reloc_count
;
6371 for (rel
= relocs
; rel
< rel_end
; rel
++)
6373 unsigned long r_symndx
;
6374 struct elf_link_hash_entry
*h
;
6376 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6378 if (r_symndx
< extsymoff
)
6382 h
= sym_hashes
[r_symndx
- extsymoff
];
6384 /* This may be an indirect symbol created because of a version. */
6387 while (h
->root
.type
== bfd_link_hash_indirect
)
6388 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6392 /* Some relocs require a global offset table. */
6393 if (dynobj
== NULL
|| sgot
== NULL
)
6395 switch (ELF32_R_TYPE (rel
->r_info
))
6399 case R_MIPS_CALL_HI16
:
6400 case R_MIPS_CALL_LO16
:
6401 case R_MIPS_GOT_HI16
:
6402 case R_MIPS_GOT_LO16
:
6404 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6405 if (! mips_elf_create_got_section (dynobj
, info
))
6407 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6408 BFD_ASSERT (sgot
!= NULL
);
6409 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6410 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6411 BFD_ASSERT (g
!= NULL
);
6417 && (info
->shared
|| h
!= NULL
)
6418 && (sec
->flags
& SEC_ALLOC
) != 0)
6419 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6427 switch (ELF32_R_TYPE (rel
->r_info
))
6430 case R_MIPS_CALL_HI16
:
6431 case R_MIPS_CALL_LO16
:
6432 /* This symbol requires a global offset table entry. */
6436 (*_bfd_error_handler
)
6437 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
6438 bfd_get_filename (abfd
), (unsigned long) rel
->r_offset
);
6439 bfd_set_error (bfd_error_bad_value
);
6443 /* Make sure this symbol is output as a dynamic symbol. */
6444 if (h
->dynindx
== -1)
6446 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6450 if (h
->got
.offset
!= (bfd_vma
) -1)
6452 /* We have already allocated space in the .got. */
6456 /* Note the index of the first global got symbol in .dynsym. */
6457 if (g
->global_gotsym
== 0
6458 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6459 g
->global_gotsym
= h
->dynindx
;
6461 /* Make this symbol to have the corresponding got entry. */
6464 /* We need a stub, not a plt entry for the undefined
6465 function. But we record it as if it needs plt. See
6466 elf_adjust_dynamic_symbol in elflink.h. */
6467 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6473 case R_MIPS_GOT_HI16
:
6474 case R_MIPS_GOT_LO16
:
6475 /* This symbol requires a global offset table entry. */
6479 /* Make sure this symbol is output as a dynamic symbol. */
6480 if (h
->dynindx
== -1)
6482 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6486 if (h
->got
.offset
!= (bfd_vma
) -1)
6488 /* We have already allocated space in the .got. */
6491 /* Note the index of the first global got symbol in
6493 if (g
->global_gotsym
== 0
6494 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
6495 g
->global_gotsym
= h
->dynindx
;
6497 /* Make this symbol to be the global got symbol. */
6505 if ((info
->shared
|| h
!= NULL
)
6506 && (sec
->flags
& SEC_ALLOC
) != 0)
6510 const char *name
= ".rel.dyn";
6512 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6515 sreloc
= bfd_make_section (dynobj
, name
);
6517 || ! bfd_set_section_flags (dynobj
, sreloc
,
6522 | SEC_LINKER_CREATED
6524 || ! bfd_set_section_alignment (dynobj
, sreloc
,
6531 /* When creating a shared object, we must copy these
6532 reloc types into the output file as R_MIPS_REL32
6533 relocs. We make room for this reloc in the
6534 .rel.dyn reloc section */
6535 if (sreloc
->_raw_size
== 0)
6537 /* Add a null element. */
6538 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6539 ++sreloc
->reloc_count
;
6541 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6545 struct mips_elf_link_hash_entry
*hmips
;
6547 /* We only need to copy this reloc if the symbol is
6548 defined in a dynamic object. */
6549 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6550 ++hmips
->mips_32_relocs
;
6554 if (SGI_COMPAT (abfd
))
6555 mips_elf_hash_table (info
)->compact_rel_size
+=
6556 sizeof (Elf32_External_crinfo
);
6561 case R_MIPS_GPREL16
:
6562 case R_MIPS_LITERAL
:
6563 case R_MIPS_GPREL32
:
6564 if (SGI_COMPAT (abfd
))
6565 mips_elf_hash_table (info
)->compact_rel_size
+=
6566 sizeof (Elf32_External_crinfo
);
6569 /* This relocation describes the C++ object vtable hierarchy.
6570 Reconstruct it for later use during GC. */
6571 case R_MIPS_GNU_VTINHERIT
:
6572 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6576 /* This relocation describes which C++ vtable entries are actually
6577 used. Record for later use during GC. */
6578 case R_MIPS_GNU_VTENTRY
:
6579 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
6587 /* If this reloc is not a 16 bit call, and it has a global
6588 symbol, then we will need the fn_stub if there is one.
6589 References from a stub section do not count. */
6591 && ELF32_R_TYPE (rel
->r_info
) != R_MIPS16_26
6592 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
6593 sizeof FN_STUB
- 1) != 0
6594 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
6595 sizeof CALL_STUB
- 1) != 0
6596 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
6597 sizeof CALL_FP_STUB
- 1) != 0)
6599 struct mips_elf_link_hash_entry
*mh
;
6601 mh
= (struct mips_elf_link_hash_entry
*) h
;
6602 mh
->need_fn_stub
= true;
6609 /* Return the section that should be marked against GC for a given
6613 mips_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
6615 struct bfd_link_info
*info
;
6616 Elf_Internal_Rela
*rel
;
6617 struct elf_link_hash_entry
*h
;
6618 Elf_Internal_Sym
*sym
;
6620 /* ??? Do mips16 stub sections need to be handled special? */
6624 switch (ELF32_R_TYPE (rel
->r_info
))
6626 case R_MIPS_GNU_VTINHERIT
:
6627 case R_MIPS_GNU_VTENTRY
:
6631 switch (h
->root
.type
)
6633 case bfd_link_hash_defined
:
6634 case bfd_link_hash_defweak
:
6635 return h
->root
.u
.def
.section
;
6637 case bfd_link_hash_common
:
6638 return h
->root
.u
.c
.p
->section
;
6647 if (!(elf_bad_symtab (abfd
)
6648 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
6649 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
6650 && sym
->st_shndx
!= SHN_COMMON
))
6652 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
6659 /* Update the got entry reference counts for the section being removed. */
6662 mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
6664 struct bfd_link_info
*info
;
6666 const Elf_Internal_Rela
*relocs
;
6669 Elf_Internal_Shdr
*symtab_hdr
;
6670 struct elf_link_hash_entry
**sym_hashes
;
6671 bfd_signed_vma
*local_got_refcounts
;
6672 const Elf_Internal_Rela
*rel
, *relend
;
6673 unsigned long r_symndx
;
6674 struct elf_link_hash_entry
*h
;
6676 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6677 sym_hashes
= elf_sym_hashes (abfd
);
6678 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6680 relend
= relocs
+ sec
->reloc_count
;
6681 for (rel
= relocs
; rel
< relend
; rel
++)
6682 switch (ELF32_R_TYPE (rel
->r_info
))
6686 case R_MIPS_CALL_HI16
:
6687 case R_MIPS_CALL_LO16
:
6688 case R_MIPS_GOT_HI16
:
6689 case R_MIPS_GOT_LO16
:
6690 /* ??? It would seem that the existing MIPS code does no sort
6691 of reference counting or whatnot on its GOT and PLT entries,
6692 so it is not possible to garbage collect them at this time. */
6704 /* Adjust a symbol defined by a dynamic object and referenced by a
6705 regular object. The current definition is in some section of the
6706 dynamic object, but we're not including those sections. We have to
6707 change the definition to something the rest of the link can
6711 mips_elf_adjust_dynamic_symbol (info
, h
)
6712 struct bfd_link_info
*info
;
6713 struct elf_link_hash_entry
*h
;
6716 struct mips_elf_link_hash_entry
*hmips
;
6719 dynobj
= elf_hash_table (info
)->dynobj
;
6721 /* Make sure we know what is going on here. */
6722 BFD_ASSERT (dynobj
!= NULL
6723 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
6724 || h
->weakdef
!= NULL
6725 || ((h
->elf_link_hash_flags
6726 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
6727 && (h
->elf_link_hash_flags
6728 & ELF_LINK_HASH_REF_REGULAR
) != 0
6729 && (h
->elf_link_hash_flags
6730 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
6732 /* If this symbol is defined in a dynamic object, we need to copy
6733 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
6735 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6736 if (! info
->relocateable
6737 && hmips
->mips_32_relocs
!= 0
6738 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6740 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6741 BFD_ASSERT (s
!= NULL
);
6743 if (s
->_raw_size
== 0)
6745 /* Make room for a null element. */
6746 s
->_raw_size
+= sizeof (Elf32_External_Rel
);
6749 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
6752 /* For a function, create a stub, if needed. */
6753 if (h
->type
== STT_FUNC
6754 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
6756 if (! elf_hash_table (info
)->dynamic_sections_created
)
6759 /* If this symbol is not defined in a regular file, then set
6760 the symbol to the stub location. This is required to make
6761 function pointers compare as equal between the normal
6762 executable and the shared library. */
6763 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6765 /* We need .stub section. */
6766 s
= bfd_get_section_by_name (dynobj
, ".stub");
6767 BFD_ASSERT (s
!= NULL
);
6769 h
->root
.u
.def
.section
= s
;
6770 h
->root
.u
.def
.value
= s
->_raw_size
;
6772 /* XXX Write this stub address somewhere. */
6773 h
->plt
.offset
= s
->_raw_size
;
6775 /* Make room for this stub code. */
6776 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
6778 /* The last half word of the stub will be filled with the index
6779 of this symbol in .dynsym section. */
6784 /* If this is a weak symbol, and there is a real definition, the
6785 processor independent code will have arranged for us to see the
6786 real definition first, and we can just use the same value. */
6787 if (h
->weakdef
!= NULL
)
6789 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
6790 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
6791 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
6792 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
6796 /* This is a reference to a symbol defined by a dynamic object which
6797 is not a function. */
6802 /* This function is called after all the input files have been read,
6803 and the input sections have been assigned to output sections. We
6804 check for any mips16 stub sections that we can discard. */
6806 static boolean mips_elf_check_mips16_stubs
6807 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
6810 mips_elf_always_size_sections (output_bfd
, info
)
6812 struct bfd_link_info
*info
;
6814 if (info
->relocateable
6815 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
6818 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
6819 mips_elf_check_mips16_stubs
,
6825 /* Check the mips16 stubs for a particular symbol, and see if we can
6830 mips_elf_check_mips16_stubs (h
, data
)
6831 struct mips_elf_link_hash_entry
*h
;
6834 if (h
->fn_stub
!= NULL
6835 && ! h
->need_fn_stub
)
6837 /* We don't need the fn_stub; the only references to this symbol
6838 are 16 bit calls. Clobber the size to 0 to prevent it from
6839 being included in the link. */
6840 h
->fn_stub
->_raw_size
= 0;
6841 h
->fn_stub
->_cooked_size
= 0;
6842 h
->fn_stub
->flags
&= ~ SEC_RELOC
;
6843 h
->fn_stub
->reloc_count
= 0;
6844 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
6847 if (h
->call_stub
!= NULL
6848 && h
->root
.other
== STO_MIPS16
)
6850 /* We don't need the call_stub; this is a 16 bit function, so
6851 calls from other 16 bit functions are OK. Clobber the size
6852 to 0 to prevent it from being included in the link. */
6853 h
->call_stub
->_raw_size
= 0;
6854 h
->call_stub
->_cooked_size
= 0;
6855 h
->call_stub
->flags
&= ~ SEC_RELOC
;
6856 h
->call_stub
->reloc_count
= 0;
6857 h
->call_stub
->flags
|= SEC_EXCLUDE
;
6860 if (h
->call_fp_stub
!= NULL
6861 && h
->root
.other
== STO_MIPS16
)
6863 /* We don't need the call_stub; this is a 16 bit function, so
6864 calls from other 16 bit functions are OK. Clobber the size
6865 to 0 to prevent it from being included in the link. */
6866 h
->call_fp_stub
->_raw_size
= 0;
6867 h
->call_fp_stub
->_cooked_size
= 0;
6868 h
->call_fp_stub
->flags
&= ~ SEC_RELOC
;
6869 h
->call_fp_stub
->reloc_count
= 0;
6870 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
6876 /* Set the sizes of the dynamic sections. */
6879 mips_elf_size_dynamic_sections (output_bfd
, info
)
6881 struct bfd_link_info
*info
;
6887 struct mips_got_info
*g
;
6889 dynobj
= elf_hash_table (info
)->dynobj
;
6890 BFD_ASSERT (dynobj
!= NULL
);
6892 if (elf_hash_table (info
)->dynamic_sections_created
)
6894 /* Set the contents of the .interp section to the interpreter. */
6897 s
= bfd_get_section_by_name (dynobj
, ".interp");
6898 BFD_ASSERT (s
!= NULL
);
6899 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
6900 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
6904 /* Recompute the size of .got for local entires (reserved and
6905 hipages) if needed. To estimate it, get the upper bound of total
6906 size of loadable sections. */
6907 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6911 bfd_size_type loadable_size
= 0;
6912 bfd_size_type local_gotno
;
6915 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6916 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6917 BFD_ASSERT (g
!= NULL
);
6919 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
6920 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
6922 if ((s
->flags
& SEC_ALLOC
) == 0)
6924 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
6927 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
6929 /* Assume there are two loadable segments consisting of
6930 contiguous sections. Is 5 enough? */
6931 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
6932 g
->local_gotno
= local_gotno
;
6933 sgot
->_raw_size
+= local_gotno
* 4;
6936 /* The check_relocs and adjust_dynamic_symbol entry points have
6937 determined the sizes of the various dynamic sections. Allocate
6940 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
6945 /* It's OK to base decisions on the section name, because none
6946 of the dynobj section names depend upon the input files. */
6947 name
= bfd_get_section_name (dynobj
, s
);
6949 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
6954 if (strncmp (name
, ".rel", 4) == 0)
6956 if (s
->_raw_size
== 0)
6958 /* We only strip the section if the output section name
6959 has the same name. Otherwise, there might be several
6960 input sections for this output section. FIXME: This
6961 code is probably not needed these days anyhow, since
6962 the linker now does not create empty output sections. */
6963 if (s
->output_section
!= NULL
6965 bfd_get_section_name (s
->output_section
->owner
,
6966 s
->output_section
)) == 0)
6971 const char *outname
;
6974 /* If this relocation section applies to a read only
6975 section, then we probably need a DT_TEXTREL entry.
6976 If the relocation section is .rel.dyn, we always
6977 assert a DT_TEXTREL entry rather than testing whether
6978 there exists a relocation to a read only section or
6980 outname
= bfd_get_section_name (output_bfd
,
6982 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
6984 && (target
->flags
& SEC_READONLY
) != 0
6985 && (target
->flags
& SEC_ALLOC
) != 0)
6986 || strcmp (outname
, ".rel.dyn") == 0)
6989 /* We use the reloc_count field as a counter if we need
6990 to copy relocs into the output file. */
6991 if (strcmp (name
, ".rel.dyn") != 0)
6995 else if (strncmp (name
, ".got", 4) == 0)
6999 BFD_ASSERT (elf_section_data (s
) != NULL
);
7000 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
7001 BFD_ASSERT (g
!= NULL
);
7003 /* Fix the size of .got section for the correspondence of
7004 global symbols and got entries. This adds some useless
7005 got entries. Is this required by ABI really? */
7006 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
7007 s
->_raw_size
+= i
* 4;
7009 else if (strncmp (name
, ".stub", 5) == 0)
7011 /* Irix rld assumes that the function stub isn't at the end
7012 of .text section. So put a dummy. XXX */
7013 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
7015 else if (! info
->shared
7016 && ! mips_elf_hash_table (info
)->use_rld_obj_head
7017 && strncmp (name
, ".rld_map", 8) == 0)
7019 /* We add a room for __rld_map. It will be filled in by the
7020 rtld to contain a pointer to the _r_debug structure. */
7023 else if (SGI_COMPAT (output_bfd
)
7024 && strncmp (name
, ".compact_rel", 12) == 0)
7025 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
7026 else if (strncmp (name
, ".init", 5) != 0)
7028 /* It's not one of our sections, so don't allocate space. */
7036 for (spp
= &s
->output_section
->owner
->sections
;
7037 *spp
!= s
->output_section
;
7038 spp
= &(*spp
)->next
)
7040 *spp
= s
->output_section
->next
;
7041 --s
->output_section
->owner
->section_count
;
7046 /* Allocate memory for the section contents. */
7047 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
7048 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
7050 bfd_set_error (bfd_error_no_memory
);
7053 memset (s
->contents
, 0, s
->_raw_size
);
7056 if (elf_hash_table (info
)->dynamic_sections_created
)
7058 /* Add some entries to the .dynamic section. We fill in the
7059 values later, in elf_mips_finish_dynamic_sections, but we
7060 must add the entries now so that we get the correct size for
7061 the .dynamic section. The DT_DEBUG entry is filled in by the
7062 dynamic linker and used by the debugger. */
7065 if (SGI_COMPAT (output_bfd
))
7067 /* SGI object has the equivalence of DT_DEBUG in the
7068 DT_MIPS_RLD_MAP entry. */
7069 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
7073 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
7079 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
7083 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
7086 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
7088 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
7091 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
7094 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
7098 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
7101 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
7104 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
7106 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
7109 s
= bfd_get_section_by_name (dynobj
, ".liblist");
7110 BFD_ASSERT (s
!= NULL
);
7112 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
7116 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
7119 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
7123 /* Time stamps in executable files are a bad idea. */
7124 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
7129 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
7134 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
7138 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
7141 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
7144 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
7147 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
7150 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
7153 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
7156 #if 0 /* (SGI_COMPAT) */
7157 if (! bfd_get_section_by_name (dynobj
, ".init"))
7158 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
7161 if (! bfd_get_section_by_name (dynobj
, ".fini"))
7162 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
7167 /* If we use dynamic linking, we generate a section symbol for each
7168 output section. These are local symbols, which means that they
7169 must come first in the dynamic symbol table.
7170 That means we must increment the dynamic symbol index of every
7171 other dynamic symbol. */
7174 struct mips_got_info
*g
;
7177 if (elf_hash_table (info
)->dynamic_sections_created
)
7180 /* We no longer try to restrict the set of sections which get
7181 dynamic symbol table entries, since it fails if we have
7182 other random sections which need dynamic relocations. */
7183 const char * const *namep
;
7184 bfd_size_type strindex
;
7185 struct bfd_strtab_hash
*dynstr
;
7187 if (SGI_COMPAT (output_bfd
))
7189 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
7190 elf_link_hash_traverse (elf_hash_table (info
),
7191 mips_elf_adjust_dynindx
,
7193 elf_hash_table (info
)->dynsymcount
+= c
;
7195 dynstr
= elf_hash_table (info
)->dynstr
;
7196 BFD_ASSERT (dynstr
!= NULL
);
7198 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
7202 s
= bfd_get_section_by_name (output_bfd
, *namep
);
7204 elf_section_data (s
)->dynindx
= i
;
7206 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
7207 if (strindex
== (bfd_size_type
) -1)
7210 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
7216 c
= bfd_count_sections (output_bfd
);
7217 elf_link_hash_traverse (elf_hash_table (info
),
7218 mips_elf_adjust_dynindx
,
7220 elf_hash_table (info
)->dynsymcount
+= c
;
7222 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
7224 elf_section_data (s
)->dynindx
= i
;
7225 /* These symbols will have no names, so we don't need to
7226 fiddle with dynstr_index. */
7233 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7234 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7235 BFD_ASSERT (g
!= NULL
);
7237 /* If there are no global got symbols, fake the last symbol so
7239 if (g
->global_gotsym
)
7240 g
->global_gotsym
+= c
;
7242 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
7249 /* Increment the index of a dynamic symbol by a given amount. Called
7250 via elf_link_hash_traverse. */
7253 mips_elf_adjust_dynindx (h
, cparg
)
7254 struct elf_link_hash_entry
*h
;
7257 unsigned int *cp
= (unsigned int *) cparg
;
7259 if (h
->dynindx
!= -1)
7264 /* Finish up dynamic symbol handling. We set the contents of various
7265 dynamic sections here. */
7268 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
7270 struct bfd_link_info
*info
;
7271 struct elf_link_hash_entry
*h
;
7272 Elf_Internal_Sym
*sym
;
7277 struct mips_got_info
*g
;
7280 dynobj
= elf_hash_table (info
)->dynobj
;
7281 gval
= sym
->st_value
;
7283 if (h
->plt
.offset
!= (bfd_vma
) -1)
7287 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
7289 /* This symbol has a stub. Set it up. */
7291 BFD_ASSERT (h
->dynindx
!= -1);
7293 s
= bfd_get_section_by_name (dynobj
, ".stub");
7294 BFD_ASSERT (s
!= NULL
);
7296 /* Fill the stub. */
7298 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
7300 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
7303 /* FIXME: Can h->dynindex be more than 64K? */
7304 if (h
->dynindx
& 0xffff0000)
7307 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
7309 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
7311 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
7312 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
7314 /* Mark the symbol as undefined. plt.offset != -1 occurs
7315 only for the referenced symbol. */
7316 sym
->st_shndx
= SHN_UNDEF
;
7318 /* The run-time linker uses the st_value field of the symbol
7319 to reset the global offset table entry for this external
7320 to its stub address when unlinking a shared object. */
7321 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
7322 sym
->st_value
= gval
;
7325 BFD_ASSERT (h
->dynindx
!= -1);
7327 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7328 BFD_ASSERT (sgot
!= NULL
);
7329 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7330 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7331 BFD_ASSERT (g
!= NULL
);
7333 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
7335 bfd_size_type offset
;
7337 /* This symbol has an entry in the global offset table. Set its
7338 value to the corresponding got entry, if needed. */
7339 if (h
->got
.offset
== (bfd_vma
) -1)
7341 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
7342 BFD_ASSERT (g
->local_gotno
* 4 <= offset
7343 && offset
< sgot
->_raw_size
);
7344 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
7348 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7349 name
= h
->root
.root
.string
;
7350 if (strcmp (name
, "_DYNAMIC") == 0
7351 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
7352 sym
->st_shndx
= SHN_ABS
;
7353 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
7355 sym
->st_shndx
= SHN_ABS
;
7356 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7359 else if (SGI_COMPAT (output_bfd
))
7361 if (strcmp (name
, "_gp_disp") == 0)
7363 sym
->st_shndx
= SHN_ABS
;
7364 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7365 sym
->st_value
= elf_gp (output_bfd
);
7367 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
7368 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
7370 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7371 sym
->st_other
= STO_PROTECTED
;
7373 sym
->st_shndx
= SHN_MIPS_DATA
;
7375 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
7377 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7378 sym
->st_other
= STO_PROTECTED
;
7379 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
7380 sym
->st_shndx
= SHN_ABS
;
7382 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
7384 if (h
->type
== STT_FUNC
)
7385 sym
->st_shndx
= SHN_MIPS_TEXT
;
7386 else if (h
->type
== STT_OBJECT
)
7387 sym
->st_shndx
= SHN_MIPS_DATA
;
7391 if (SGI_COMPAT (output_bfd
)
7394 if (! mips_elf_hash_table (info
)->use_rld_obj_head
7395 && strcmp (name
, "__rld_map") == 0)
7397 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7398 BFD_ASSERT (s
!= NULL
);
7399 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
7400 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
7401 if (mips_elf_hash_table (info
)->rld_value
== 0)
7402 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7404 else if (mips_elf_hash_table (info
)->use_rld_obj_head
7405 && strcmp (name
, "__rld_obj_head") == 0)
7407 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7408 BFD_ASSERT (s
!= NULL
);
7409 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7413 /* If this is a mips16 symbol, force the value to be even. */
7414 if (sym
->st_other
== STO_MIPS16
7415 && (sym
->st_value
& 1) != 0)
7421 /* Finish up the dynamic sections. */
7424 mips_elf_finish_dynamic_sections (output_bfd
, info
)
7426 struct bfd_link_info
*info
;
7431 struct mips_got_info
*g
;
7433 dynobj
= elf_hash_table (info
)->dynobj
;
7435 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
7437 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7442 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7443 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7444 BFD_ASSERT (g
!= NULL
);
7447 if (elf_hash_table (info
)->dynamic_sections_created
)
7449 Elf32_External_Dyn
*dyncon
, *dynconend
;
7451 BFD_ASSERT (sdyn
!= NULL
);
7452 BFD_ASSERT (g
!= NULL
);
7454 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7455 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
7456 for (; dyncon
< dynconend
; dyncon
++)
7458 Elf_Internal_Dyn dyn
;
7463 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
7471 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7472 BFD_ASSERT (s
!= NULL
);
7473 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
7474 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7478 /* Rewrite DT_STRSZ. */
7480 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
7481 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7487 case DT_MIPS_CONFLICT
:
7490 case DT_MIPS_LIBLIST
:
7493 s
= bfd_get_section_by_name (output_bfd
, name
);
7494 BFD_ASSERT (s
!= NULL
);
7495 dyn
.d_un
.d_ptr
= s
->vma
;
7496 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7499 case DT_MIPS_RLD_VERSION
:
7500 dyn
.d_un
.d_val
= 1; /* XXX */
7501 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7505 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
7506 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7509 case DT_MIPS_CONFLICTNO
:
7511 elemsize
= sizeof (Elf32_Conflict
);
7514 case DT_MIPS_LIBLISTNO
:
7516 elemsize
= sizeof (Elf32_Lib
);
7518 s
= bfd_get_section_by_name (output_bfd
, name
);
7521 if (s
->_cooked_size
!= 0)
7522 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7524 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7529 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7532 case DT_MIPS_TIME_STAMP
:
7533 time ((time_t *) &dyn
.d_un
.d_val
);
7534 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7537 case DT_MIPS_ICHECKSUM
:
7541 case DT_MIPS_IVERSION
:
7545 case DT_MIPS_BASE_ADDRESS
:
7546 s
= output_bfd
->sections
;
7547 BFD_ASSERT (s
!= NULL
);
7548 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
7549 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7552 case DT_MIPS_LOCAL_GOTNO
:
7553 dyn
.d_un
.d_val
= g
->local_gotno
;
7554 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7557 case DT_MIPS_SYMTABNO
:
7559 elemsize
= sizeof (Elf32_External_Sym
);
7560 s
= bfd_get_section_by_name (output_bfd
, name
);
7561 BFD_ASSERT (s
!= NULL
);
7563 if (s
->_cooked_size
!= 0)
7564 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7566 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7567 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7570 case DT_MIPS_UNREFEXTNO
:
7572 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
7574 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
);
7576 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7579 case DT_MIPS_GOTSYM
:
7580 dyn
.d_un
.d_val
= g
->global_gotsym
;
7581 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7584 case DT_MIPS_HIPAGENO
:
7585 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
7586 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7589 case DT_MIPS_RLD_MAP
:
7590 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
7591 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7598 /* The first entry of the global offset table will be filled at
7599 runtime. The second entry will be used by some runtime loaders.
7600 This isn't the case of Irix rld. */
7601 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
7603 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
7604 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
7608 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
7613 Elf_Internal_Sym sym
;
7614 Elf32_compact_rel cpt
;
7616 /* Set up the section symbols for the output sections. SGI sets
7617 the STT_NOTYPE attribute for these symbols. Should we do so? */
7619 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
7620 if (sdynsym
!= NULL
)
7624 const char * const * namep
= mips_elf_dynsym_sec_names
;
7629 /* We no longer try to restrict the set of sections which get
7630 dynamic symbol table entries, since it fails if we have
7631 other random sections which need dynamic relocations. */
7632 if (SGI_COMPAT (output_bfd
))
7636 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7642 while ((name
= *namep
++) != NULL
)
7644 s
= bfd_get_section_by_name (output_bfd
, name
);
7647 sym
.st_value
= s
->vma
;
7648 dindx
= elf_section_data (s
)->dynindx
;
7649 last
= s
->vma
+ s
->_raw_size
;
7653 sym
.st_value
= last
;
7657 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
7662 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
7664 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7665 (((Elf32_External_Sym
*)
7670 /* Set the sh_info field of the output .dynsym section to
7671 the index of the first global symbol. */
7672 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7673 SIZEOF_MIPS_DYNSYM_SECNAMES
;
7680 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
7683 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
7687 sym
.st_value
= s
->vma
;
7689 indx
= elf_section_data (s
)->this_idx
;
7690 BFD_ASSERT (indx
> 0);
7691 sym
.st_shndx
= indx
;
7693 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
7694 (((Elf32_External_Sym
*)
7696 + elf_section_data (s
)->dynindx
));
7699 /* Set the sh_info field of the output .dynsym section to
7700 the index of the first global symbol. */
7701 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
7702 bfd_count_sections (output_bfd
) + 1;
7706 if (SGI_COMPAT (output_bfd
))
7708 /* Write .compact_rel section out. */
7709 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
7713 cpt
.num
= s
->reloc_count
;
7715 cpt
.offset
= (s
->output_section
->filepos
7716 + sizeof (Elf32_External_compact_rel
));
7719 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
7720 ((Elf32_External_compact_rel
*)
7723 /* Clean up a dummy stub function entry in .text. */
7724 s
= bfd_get_section_by_name (dynobj
, ".stub");
7727 file_ptr dummy_offset
;
7729 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
7730 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
7731 memset (s
->contents
+ dummy_offset
, 0,
7732 MIPS_FUNCTION_STUB_SIZE
);
7737 /* Clean up a first relocation in .rel.dyn. */
7738 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7739 if (s
!= NULL
&& s
->_raw_size
> 0)
7740 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
7746 /* This is almost identical to bfd_generic_get_... except that some
7747 MIPS relocations need to be handled specially. Sigh. */
7750 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
7751 relocateable
, symbols
)
7753 struct bfd_link_info
*link_info
;
7754 struct bfd_link_order
*link_order
;
7756 boolean relocateable
;
7759 /* Get enough memory to hold the stuff */
7760 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
7761 asection
*input_section
= link_order
->u
.indirect
.section
;
7763 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
7764 arelent
**reloc_vector
= NULL
;
7770 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
7771 if (reloc_vector
== NULL
&& reloc_size
!= 0)
7774 /* read in the section */
7775 if (!bfd_get_section_contents (input_bfd
,
7779 input_section
->_raw_size
))
7782 /* We're not relaxing the section, so just copy the size info */
7783 input_section
->_cooked_size
= input_section
->_raw_size
;
7784 input_section
->reloc_done
= true;
7786 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
7790 if (reloc_count
< 0)
7793 if (reloc_count
> 0)
7798 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
7801 struct bfd_hash_entry
*h
;
7802 struct bfd_link_hash_entry
*lh
;
7803 /* Skip all this stuff if we aren't mixing formats. */
7804 if (abfd
&& input_bfd
7805 && abfd
->xvec
== input_bfd
->xvec
)
7809 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
7810 lh
= (struct bfd_link_hash_entry
*) h
;
7817 case bfd_link_hash_undefined
:
7818 case bfd_link_hash_undefweak
:
7819 case bfd_link_hash_common
:
7822 case bfd_link_hash_defined
:
7823 case bfd_link_hash_defweak
:
7825 gp
= lh
->u
.def
.value
;
7827 case bfd_link_hash_indirect
:
7828 case bfd_link_hash_warning
:
7830 /* @@FIXME ignoring warning for now */
7832 case bfd_link_hash_new
:
7841 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
7844 char *error_message
= (char *) NULL
;
7845 bfd_reloc_status_type r
;
7847 /* Specific to MIPS: Deal with relocation types that require
7848 knowing the gp of the output bfd. */
7849 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
7850 if (bfd_is_abs_section (sym
->section
) && abfd
)
7852 /* The special_function wouldn't get called anyways. */
7856 /* The gp isn't there; let the special function code
7857 fall over on its own. */
7859 else if ((*parent
)->howto
->special_function
7860 == _bfd_mips_elf_gprel16_reloc
)
7862 /* bypass special_function call */
7863 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
7864 relocateable
, (PTR
) data
, gp
);
7865 goto skip_bfd_perform_relocation
;
7867 /* end mips specific stuff */
7869 r
= bfd_perform_relocation (input_bfd
,
7873 relocateable
? abfd
: (bfd
*) NULL
,
7875 skip_bfd_perform_relocation
:
7879 asection
*os
= input_section
->output_section
;
7881 /* A partial link, so keep the relocs */
7882 os
->orelocation
[os
->reloc_count
] = *parent
;
7886 if (r
!= bfd_reloc_ok
)
7890 case bfd_reloc_undefined
:
7891 if (!((*link_info
->callbacks
->undefined_symbol
)
7892 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7893 input_bfd
, input_section
, (*parent
)->address
)))
7896 case bfd_reloc_dangerous
:
7897 BFD_ASSERT (error_message
!= (char *) NULL
);
7898 if (!((*link_info
->callbacks
->reloc_dangerous
)
7899 (link_info
, error_message
, input_bfd
, input_section
,
7900 (*parent
)->address
)))
7903 case bfd_reloc_overflow
:
7904 if (!((*link_info
->callbacks
->reloc_overflow
)
7905 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7906 (*parent
)->howto
->name
, (*parent
)->addend
,
7907 input_bfd
, input_section
, (*parent
)->address
)))
7910 case bfd_reloc_outofrange
:
7919 if (reloc_vector
!= NULL
)
7920 free (reloc_vector
);
7924 if (reloc_vector
!= NULL
)
7925 free (reloc_vector
);
7928 #define bfd_elf32_bfd_get_relocated_section_contents \
7929 elf32_mips_get_relocated_section_contents
7931 /* ECOFF swapping routines. These are used when dealing with the
7932 .mdebug section, which is in the ECOFF debugging format. */
7933 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
7935 /* Symbol table magic number. */
7937 /* Alignment of debugging information. E.g., 4. */
7939 /* Sizes of external symbolic information. */
7940 sizeof (struct hdr_ext
),
7941 sizeof (struct dnr_ext
),
7942 sizeof (struct pdr_ext
),
7943 sizeof (struct sym_ext
),
7944 sizeof (struct opt_ext
),
7945 sizeof (struct fdr_ext
),
7946 sizeof (struct rfd_ext
),
7947 sizeof (struct ext_ext
),
7948 /* Functions to swap in external symbolic data. */
7957 _bfd_ecoff_swap_tir_in
,
7958 _bfd_ecoff_swap_rndx_in
,
7959 /* Functions to swap out external symbolic data. */
7968 _bfd_ecoff_swap_tir_out
,
7969 _bfd_ecoff_swap_rndx_out
,
7970 /* Function to read in symbolic data. */
7971 _bfd_mips_elf_read_ecoff_info
7974 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
7975 #define TARGET_LITTLE_NAME "elf32-littlemips"
7976 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
7977 #define TARGET_BIG_NAME "elf32-bigmips"
7978 #define ELF_ARCH bfd_arch_mips
7979 #define ELF_MACHINE_CODE EM_MIPS
7981 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
7982 a value of 0x1000, and we are compatible. */
7983 #define ELF_MAXPAGESIZE 0x1000
7985 #define elf_backend_collect true
7986 #define elf_backend_type_change_ok true
7987 #define elf_backend_can_gc_sections true
7988 #define elf_info_to_howto 0
7989 #define elf_info_to_howto_rel mips_info_to_howto_rel
7990 #define elf_backend_sym_is_global mips_elf_sym_is_global
7991 #define elf_backend_object_p mips_elf32_object_p
7992 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
7993 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
7994 #define elf_backend_section_from_bfd_section \
7995 _bfd_mips_elf_section_from_bfd_section
7996 #define elf_backend_section_processing mips_elf32_section_processing
7997 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
7998 #define elf_backend_additional_program_headers \
7999 mips_elf_additional_program_headers
8000 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
8001 #define elf_backend_final_write_processing \
8002 _bfd_mips_elf_final_write_processing
8003 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
8005 #define bfd_elf32_bfd_is_local_label_name \
8006 mips_elf_is_local_label_name
8007 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
8008 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
8009 #define bfd_elf32_bfd_link_hash_table_create \
8010 mips_elf_link_hash_table_create
8011 #define bfd_elf32_bfd_final_link mips_elf_final_link
8012 #define bfd_elf32_bfd_copy_private_bfd_data \
8013 _bfd_mips_elf_copy_private_bfd_data
8014 #define bfd_elf32_bfd_merge_private_bfd_data \
8015 _bfd_mips_elf_merge_private_bfd_data
8016 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
8017 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
8018 #define elf_backend_create_dynamic_sections \
8019 mips_elf_create_dynamic_sections
8020 #define elf_backend_check_relocs mips_elf_check_relocs
8021 #define elf_backend_adjust_dynamic_symbol \
8022 mips_elf_adjust_dynamic_symbol
8023 #define elf_backend_always_size_sections \
8024 mips_elf_always_size_sections
8025 #define elf_backend_size_dynamic_sections \
8026 mips_elf_size_dynamic_sections
8027 #define elf_backend_relocate_section mips_elf_relocate_section
8028 #define elf_backend_link_output_symbol_hook \
8029 mips_elf_link_output_symbol_hook
8030 #define elf_backend_finish_dynamic_symbol \
8031 mips_elf_finish_dynamic_symbol
8032 #define elf_backend_finish_dynamic_sections \
8033 mips_elf_finish_dynamic_sections
8034 #define elf_backend_gc_mark_hook mips_elf_gc_mark_hook
8035 #define elf_backend_gc_sweep_hook mips_elf_gc_sweep_hook
8037 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
8038 #define elf_backend_plt_header_size 0
8040 #include "elf32-target.h"