1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996 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 reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
45 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
46 static void mips_info_to_howto_rel
47 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
48 static void bfd_mips_elf32_swap_gptab_in
49 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
50 static void bfd_mips_elf32_swap_gptab_out
51 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
52 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
53 static boolean mips_elf32_object_p
PARAMS ((bfd
*));
54 static boolean mips_elf_create_procedure_table
55 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
56 struct ecoff_debug_info
*));
57 static int mips_elf_additional_program_headers
PARAMS ((bfd
*));
58 static boolean mips_elf_modify_segment_map
PARAMS ((bfd
*));
59 static INLINE
int elf_mips_isa
PARAMS ((flagword
));
60 static boolean mips_elf32_section_from_shdr
61 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, char *));
62 static boolean mips_elf32_section_processing
63 PARAMS ((bfd
*, Elf32_Internal_Shdr
*));
64 static boolean mips_elf_is_local_label
65 PARAMS ((bfd
*, asymbol
*));
66 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
67 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
68 static struct bfd_link_hash_table
*mips_elf_link_hash_table_create
70 static int gptab_compare
PARAMS ((const void *, const void *));
71 static boolean mips_elf_final_link
72 PARAMS ((bfd
*, struct bfd_link_info
*));
73 static void mips_elf_relocate_hi16
74 PARAMS ((bfd
*, Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_byte
*,
76 static void mips_elf_relocate_got_local
77 PARAMS ((bfd
*, bfd
*, asection
*, Elf_Internal_Rela
*,
78 Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
79 static void mips_elf_relocate_global_got
80 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
81 static boolean mips_elf_adjust_dynindx
82 PARAMS ((struct elf_link_hash_entry
*, PTR
));
83 static boolean mips_elf_relocate_section
84 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
85 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
86 static boolean mips_elf_create_dynamic_sections
87 PARAMS ((bfd
*, struct bfd_link_info
*));
88 static boolean mips_elf_create_compact_rel_section
89 PARAMS ((bfd
*, struct bfd_link_info
*));
90 static boolean mips_elf_create_got_section
91 PARAMS ((bfd
*, struct bfd_link_info
*));
92 static boolean mips_elf_check_relocs
93 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
94 const Elf_Internal_Rela
*));
95 static boolean mips_elf_adjust_dynamic_symbol
96 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
97 static boolean mips_elf_size_dynamic_sections
98 PARAMS ((bfd
*, struct bfd_link_info
*));
99 static boolean mips_elf_finish_dynamic_symbol
100 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
101 Elf_Internal_Sym
*));
102 static boolean mips_elf_finish_dynamic_sections
103 PARAMS ((bfd
*, struct bfd_link_info
*));
104 static boolean mips_elf_add_symbol_hook
105 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
106 const char **, flagword
*, asection
**, bfd_vma
*));
107 static bfd_reloc_status_type mips_elf_final_gp
108 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
109 static bfd_byte
*elf32_mips_get_relocated_section_contents
110 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
111 bfd_byte
*, boolean
, asymbol
**));
113 /* This is true for Irix 5 executables, false for normal MIPS ELF ABI
114 executables. FIXME: At the moment, we default to always generating
115 Irix 5 executables. */
117 #define SGI_COMPAT(abfd) (1)
119 /* This structure is used to hold .got information when linking. It
120 is stored in the tdata field of the bfd_elf_section_data structure. */
124 /* The symbol index of the first global .got symbol. */
125 unsigned long global_gotsym
;
126 /* The number of local .got entries. */
127 unsigned int local_gotno
;
130 /* The number of local .got entries we reserve. */
131 #define MIPS_RESERVED_GOTNO (2)
133 /* Instructions which appear in a stub. For some reason the stub is
134 slightly different on an SGI system. */
135 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
136 #define STUB_LW(abfd) \
138 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
139 : 0x8f998000) /* lw t9,0x8000(gp) */
140 #define STUB_MOVE 0x03e07825 /* move t7,ra */
141 #define STUB_JALR 0x0320f809 /* jal t9 */
142 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
143 #define MIPS_FUNCTION_STUB_SIZE (16)
145 /* Names of sections which appear in the .dynsym section in an Irix 5
148 static const char * const mips_elf_dynsym_sec_names
[] =
161 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
162 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
164 /* The number of entries in mips_elf_dynsym_sec_names which go in the
167 #define MIPS_TEXT_DYNSYM_SECNO (3)
169 /* The names of the runtime procedure table symbols used on Irix 5. */
171 static const char * const mips_elf_dynsym_rtproc_names
[] =
174 "_procedure_string_table",
175 "_procedure_table_size",
179 /* These structures are used to generate the .compact_rel section on
184 unsigned long id1
; /* Always one? */
185 unsigned long num
; /* Number of compact relocation entries. */
186 unsigned long id2
; /* Always two? */
187 unsigned long offset
; /* The file offset of the first relocation. */
188 unsigned long reserved0
; /* Zero? */
189 unsigned long reserved1
; /* Zero? */
198 bfd_byte reserved0
[4];
199 bfd_byte reserved1
[4];
200 } Elf32_External_compact_rel
;
204 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
205 unsigned int rtype
: 4; /* Relocation types. See below. */
206 unsigned int dist2to
: 8;
207 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
208 unsigned long konst
; /* KONST field. See below. */
209 unsigned long vaddr
; /* VADDR to be relocated. */
214 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
215 unsigned int rtype
: 4; /* Relocation types. See below. */
216 unsigned int dist2to
: 8;
217 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
218 unsigned long konst
; /* KONST field. See below. */
226 } Elf32_External_crinfo
;
232 } Elf32_External_crinfo2
;
234 /* These are the constants used to swap the bitfields in a crinfo. */
236 #define CRINFO_CTYPE (0x1)
237 #define CRINFO_CTYPE_SH (31)
238 #define CRINFO_RTYPE (0xf)
239 #define CRINFO_RTYPE_SH (27)
240 #define CRINFO_DIST2TO (0xff)
241 #define CRINFO_DIST2TO_SH (19)
242 #define CRINFO_RELVADDR (0x7ffff)
243 #define CRINFO_RELVADDR_SH (0)
245 /* A compact relocation info has long (3 words) or short (2 words)
246 formats. A short format doesn't have VADDR field and relvaddr
247 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
248 #define CRF_MIPS_LONG 1
249 #define CRF_MIPS_SHORT 0
251 /* There are 4 types of compact relocation at least. The value KONST
252 has different meaning for each type:
255 CT_MIPS_REL32 Address in data
256 CT_MIPS_WORD Address in word (XXX)
257 CT_MIPS_GPHI_LO GP - vaddr
258 CT_MIPS_JMPAD Address to jump
261 #define CRT_MIPS_REL32 0xa
262 #define CRT_MIPS_WORD 0xb
263 #define CRT_MIPS_GPHI_LO 0xc
264 #define CRT_MIPS_JMPAD 0xd
266 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
267 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
268 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
269 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
271 static void bfd_elf32_swap_compact_rel_out
272 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
273 static void bfd_elf32_swap_crinfo_out
274 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
276 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
281 R_MIPS_16
, R_MIPS_32
,
282 R_MIPS_REL32
, R_MIPS_26
,
283 R_MIPS_HI16
, R_MIPS_LO16
,
284 R_MIPS_GPREL16
, R_MIPS_LITERAL
,
285 R_MIPS_GOT16
, R_MIPS_PC16
,
286 R_MIPS_CALL16
, R_MIPS_GPREL32
,
287 /* The remaining relocs are defined on Irix, although they are not
288 in the MIPS ELF ABI. */
289 R_MIPS_UNUSED1
, R_MIPS_UNUSED2
,
291 R_MIPS_SHIFT5
, R_MIPS_SHIFT6
,
292 R_MIPS_64
, R_MIPS_GOT_DISP
,
293 R_MIPS_GOT_PAGE
, R_MIPS_GOT_OFST
,
294 R_MIPS_GOT_HI16
, R_MIPS_GOT_LO16
,
295 R_MIPS_SUB
, R_MIPS_INSERT_A
,
296 R_MIPS_INSERT_B
, R_MIPS_DELETE
,
297 R_MIPS_HIGHER
, R_MIPS_HIGHEST
,
298 R_MIPS_CALL_HI16
, R_MIPS_CALL_LO16
,
302 static reloc_howto_type elf_mips_howto_table
[] =
305 HOWTO (R_MIPS_NONE
, /* type */
307 0, /* size (0 = byte, 1 = short, 2 = long) */
309 false, /* pc_relative */
311 complain_overflow_dont
, /* complain_on_overflow */
312 bfd_elf_generic_reloc
, /* special_function */
313 "R_MIPS_NONE", /* name */
314 false, /* partial_inplace */
317 false), /* pcrel_offset */
319 /* 16 bit relocation. */
320 HOWTO (R_MIPS_16
, /* type */
322 1, /* size (0 = byte, 1 = short, 2 = long) */
324 false, /* pc_relative */
326 complain_overflow_bitfield
, /* complain_on_overflow */
327 bfd_elf_generic_reloc
, /* special_function */
328 "R_MIPS_16", /* name */
329 true, /* partial_inplace */
330 0xffff, /* src_mask */
331 0xffff, /* dst_mask */
332 false), /* pcrel_offset */
334 /* 32 bit relocation. */
335 HOWTO (R_MIPS_32
, /* type */
337 2, /* size (0 = byte, 1 = short, 2 = long) */
339 false, /* pc_relative */
341 complain_overflow_bitfield
, /* complain_on_overflow */
342 bfd_elf_generic_reloc
, /* special_function */
343 "R_MIPS_32", /* name */
344 true, /* partial_inplace */
345 0xffffffff, /* src_mask */
346 0xffffffff, /* dst_mask */
347 false), /* pcrel_offset */
349 /* 32 bit symbol relative relocation. */
350 HOWTO (R_MIPS_REL32
, /* type */
352 2, /* size (0 = byte, 1 = short, 2 = long) */
354 false, /* pc_relative */
356 complain_overflow_bitfield
, /* complain_on_overflow */
357 bfd_elf_generic_reloc
, /* special_function */
358 "R_MIPS_REL32", /* name */
359 true, /* partial_inplace */
360 0xffffffff, /* src_mask */
361 0xffffffff, /* dst_mask */
362 false), /* pcrel_offset */
364 /* 26 bit branch address. */
365 HOWTO (R_MIPS_26
, /* type */
367 2, /* size (0 = byte, 1 = short, 2 = long) */
369 false, /* pc_relative */
371 complain_overflow_dont
, /* complain_on_overflow */
372 /* This needs complex overflow
373 detection, because the upper four
374 bits must match the PC. */
375 bfd_elf_generic_reloc
, /* special_function */
376 "R_MIPS_26", /* name */
377 true, /* partial_inplace */
378 0x3ffffff, /* src_mask */
379 0x3ffffff, /* dst_mask */
380 false), /* pcrel_offset */
382 /* High 16 bits of symbol value. */
383 HOWTO (R_MIPS_HI16
, /* type */
385 2, /* size (0 = byte, 1 = short, 2 = long) */
387 false, /* pc_relative */
389 complain_overflow_dont
, /* complain_on_overflow */
390 _bfd_mips_elf_hi16_reloc
, /* special_function */
391 "R_MIPS_HI16", /* name */
392 true, /* partial_inplace */
393 0xffff, /* src_mask */
394 0xffff, /* dst_mask */
395 false), /* pcrel_offset */
397 /* Low 16 bits of symbol value. */
398 HOWTO (R_MIPS_LO16
, /* type */
400 2, /* size (0 = byte, 1 = short, 2 = long) */
402 false, /* pc_relative */
404 complain_overflow_dont
, /* complain_on_overflow */
405 _bfd_mips_elf_lo16_reloc
, /* special_function */
406 "R_MIPS_LO16", /* name */
407 true, /* partial_inplace */
408 0xffff, /* src_mask */
409 0xffff, /* dst_mask */
410 false), /* pcrel_offset */
412 /* GP relative reference. */
413 HOWTO (R_MIPS_GPREL16
, /* type */
415 2, /* size (0 = byte, 1 = short, 2 = long) */
417 false, /* pc_relative */
419 complain_overflow_signed
, /* complain_on_overflow */
420 _bfd_mips_elf_gprel16_reloc
, /* special_function */
421 "R_MIPS_GPREL16", /* name */
422 true, /* partial_inplace */
423 0xffff, /* src_mask */
424 0xffff, /* dst_mask */
425 false), /* pcrel_offset */
427 /* Reference to literal section. */
428 HOWTO (R_MIPS_LITERAL
, /* type */
430 2, /* size (0 = byte, 1 = short, 2 = long) */
432 false, /* pc_relative */
434 complain_overflow_signed
, /* complain_on_overflow */
435 _bfd_mips_elf_gprel16_reloc
, /* special_function */
436 "R_MIPS_LITERAL", /* name */
437 true, /* partial_inplace */
438 0xffff, /* src_mask */
439 0xffff, /* dst_mask */
440 false), /* pcrel_offset */
442 /* Reference to global offset table. */
443 HOWTO (R_MIPS_GOT16
, /* type */
445 2, /* size (0 = byte, 1 = short, 2 = long) */
447 false, /* pc_relative */
449 complain_overflow_signed
, /* complain_on_overflow */
450 _bfd_mips_elf_got16_reloc
, /* special_function */
451 "R_MIPS_GOT16", /* name */
452 false, /* partial_inplace */
454 0xffff, /* dst_mask */
455 false), /* pcrel_offset */
457 /* 16 bit PC relative reference. */
458 HOWTO (R_MIPS_PC16
, /* type */
460 2, /* size (0 = byte, 1 = short, 2 = long) */
462 true, /* pc_relative */
464 complain_overflow_signed
, /* complain_on_overflow */
465 bfd_elf_generic_reloc
, /* special_function */
466 "R_MIPS_PC16", /* name */
467 true, /* partial_inplace */
468 0xffff, /* src_mask */
469 0xffff, /* dst_mask */
470 false), /* pcrel_offset */
472 /* 16 bit call through global offset table. */
473 /* FIXME: This is not handled correctly. */
474 HOWTO (R_MIPS_CALL16
, /* type */
476 2, /* size (0 = byte, 1 = short, 2 = long) */
478 false, /* pc_relative */
480 complain_overflow_signed
, /* complain_on_overflow */
481 bfd_elf_generic_reloc
, /* special_function */
482 "R_MIPS_CALL16", /* name */
483 false, /* partial_inplace */
485 0xffff, /* dst_mask */
486 false), /* pcrel_offset */
488 /* 32 bit GP relative reference. */
489 HOWTO (R_MIPS_GPREL32
, /* type */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
493 false, /* pc_relative */
495 complain_overflow_bitfield
, /* complain_on_overflow */
496 _bfd_mips_elf_gprel32_reloc
, /* special_function */
497 "R_MIPS_GPREL32", /* name */
498 true, /* partial_inplace */
499 0xffffffff, /* src_mask */
500 0xffffffff, /* dst_mask */
501 false), /* pcrel_offset */
503 /* The remaining relocs are defined on Irix 5, although they are
504 not defined by the ABI. */
509 /* A 5 bit shift field. */
510 HOWTO (R_MIPS_SHIFT5
, /* type */
512 2, /* size (0 = byte, 1 = short, 2 = long) */
514 false, /* pc_relative */
516 complain_overflow_bitfield
, /* complain_on_overflow */
517 bfd_elf_generic_reloc
, /* special_function */
518 "R_MIPS_SHIFT5", /* name */
519 true, /* partial_inplace */
520 0x000007c0, /* src_mask */
521 0x000007c0, /* dst_mask */
522 false), /* pcrel_offset */
524 /* A 6 bit shift field. */
525 /* FIXME: This is not handled correctly; a special function is
526 needed to put the most significant bit in the right place. */
527 HOWTO (R_MIPS_SHIFT6
, /* type */
529 2, /* size (0 = byte, 1 = short, 2 = long) */
531 false, /* pc_relative */
533 complain_overflow_bitfield
, /* complain_on_overflow */
534 bfd_elf_generic_reloc
, /* special_function */
535 "R_MIPS_SHIFT6", /* name */
536 true, /* partial_inplace */
537 0x000007c4, /* src_mask */
538 0x000007c4, /* dst_mask */
539 false), /* pcrel_offset */
541 /* A 64 bit relocation. Presumably not used in 32 bit ELF. */
544 /* Displacement in the global offset table. */
545 /* FIXME: Not handled correctly. */
546 HOWTO (R_MIPS_GOT_DISP
, /* type */
548 2, /* size (0 = byte, 1 = short, 2 = long) */
550 false, /* pc_relative */
552 complain_overflow_bitfield
, /* complain_on_overflow */
553 bfd_elf_generic_reloc
, /* special_function */
554 "R_MIPS_GOT_DISP", /* name */
555 true, /* partial_inplace */
556 0x0000ffff, /* src_mask */
557 0x0000ffff, /* dst_mask */
558 false), /* pcrel_offset */
560 /* Displacement to page pointer in the global offset table. */
561 /* FIXME: Not handled correctly. */
562 HOWTO (R_MIPS_GOT_PAGE
, /* type */
564 2, /* size (0 = byte, 1 = short, 2 = long) */
566 false, /* pc_relative */
568 complain_overflow_bitfield
, /* complain_on_overflow */
569 bfd_elf_generic_reloc
, /* special_function */
570 "R_MIPS_GOT_PAGE", /* name */
571 true, /* partial_inplace */
572 0x0000ffff, /* src_mask */
573 0x0000ffff, /* dst_mask */
574 false), /* pcrel_offset */
576 /* Offset from page pointer in the global offset table. */
577 /* FIXME: Not handled correctly. */
578 HOWTO (R_MIPS_GOT_OFST
, /* type */
580 2, /* size (0 = byte, 1 = short, 2 = long) */
582 false, /* pc_relative */
584 complain_overflow_bitfield
, /* complain_on_overflow */
585 bfd_elf_generic_reloc
, /* special_function */
586 "R_MIPS_GOT_OFST", /* name */
587 true, /* partial_inplace */
588 0x0000ffff, /* src_mask */
589 0x0000ffff, /* dst_mask */
590 false), /* pcrel_offset */
592 /* High 16 bits of displacement in global offset table. */
593 /* FIXME: Not handled correctly. */
594 HOWTO (R_MIPS_GOT_HI16
, /* type */
596 2, /* size (0 = byte, 1 = short, 2 = long) */
598 false, /* pc_relative */
600 complain_overflow_dont
, /* complain_on_overflow */
601 bfd_elf_generic_reloc
, /* special_function */
602 "R_MIPS_GOT_HI16", /* name */
603 true, /* partial_inplace */
604 0x0000ffff, /* src_mask */
605 0x0000ffff, /* dst_mask */
606 false), /* pcrel_offset */
608 /* Low 16 bits of displacement in global offset table. */
609 /* FIXME: Not handled correctly. */
610 HOWTO (R_MIPS_GOT_LO16
, /* type */
612 2, /* size (0 = byte, 1 = short, 2 = long) */
614 false, /* pc_relative */
616 complain_overflow_dont
, /* complain_on_overflow */
617 bfd_elf_generic_reloc
, /* special_function */
618 "R_MIPS_GOT_LO16", /* name */
619 true, /* partial_inplace */
620 0x0000ffff, /* src_mask */
621 0x0000ffff, /* dst_mask */
622 false), /* pcrel_offset */
624 /* 64 bit subtraction. Presumably not used in 32 bit ELF. */
627 /* Used to cause the linker to insert and delete instructions? */
632 /* Get the higher values of a 64 bit addend. Presumably not used in
637 /* High 16 bits of displacement in global offset table. */
638 /* FIXME: Not handled correctly. */
639 HOWTO (R_MIPS_CALL_HI16
, /* type */
641 2, /* size (0 = byte, 1 = short, 2 = long) */
643 false, /* pc_relative */
645 complain_overflow_dont
, /* complain_on_overflow */
646 bfd_elf_generic_reloc
, /* special_function */
647 "R_MIPS_CALL_HI16", /* name */
648 true, /* partial_inplace */
649 0x0000ffff, /* src_mask */
650 0x0000ffff, /* dst_mask */
651 false), /* pcrel_offset */
653 /* Low 16 bits of displacement in global offset table. */
654 /* FIXME: Not handled correctly. */
655 HOWTO (R_MIPS_CALL_LO16
, /* type */
657 2, /* size (0 = byte, 1 = short, 2 = long) */
659 false, /* pc_relative */
661 complain_overflow_dont
, /* complain_on_overflow */
662 bfd_elf_generic_reloc
, /* special_function */
663 "R_MIPS_CALL_LO16", /* name */
664 true, /* partial_inplace */
665 0x0000ffff, /* src_mask */
666 0x0000ffff, /* dst_mask */
667 false) /* pcrel_offset */
670 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
671 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
672 the HI16. Here we just save the information we need; we do the
673 actual relocation when we see the LO16. MIPS ELF requires that the
674 LO16 immediately follow the HI16. As a GNU extension, we permit an
675 arbitrary number of HI16 relocs to be associated with a single LO16
676 reloc. This extension permits gcc to output the HI and LO relocs
681 struct mips_hi16
*next
;
686 /* FIXME: This should not be a static variable. */
688 static struct mips_hi16
*mips_hi16_list
;
690 bfd_reloc_status_type
691 _bfd_mips_elf_hi16_reloc (abfd
,
699 arelent
*reloc_entry
;
702 asection
*input_section
;
704 char **error_message
;
706 bfd_reloc_status_type ret
;
710 /* If we're relocating, and this an external symbol, we don't want
711 to change anything. */
712 if (output_bfd
!= (bfd
*) NULL
713 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
714 && reloc_entry
->addend
== 0)
716 reloc_entry
->address
+= input_section
->output_offset
;
722 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
724 boolean relocateable
;
727 if (ret
== bfd_reloc_undefined
)
730 if (output_bfd
!= NULL
)
734 relocateable
= false;
735 output_bfd
= symbol
->section
->output_section
->owner
;
738 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
740 if (ret
!= bfd_reloc_ok
)
743 relocation
= gp
- reloc_entry
->address
;
747 if (bfd_is_und_section (symbol
->section
)
748 && output_bfd
== (bfd
*) NULL
)
749 ret
= bfd_reloc_undefined
;
751 if (bfd_is_com_section (symbol
->section
))
754 relocation
= symbol
->value
;
757 relocation
+= symbol
->section
->output_section
->vma
;
758 relocation
+= symbol
->section
->output_offset
;
759 relocation
+= reloc_entry
->addend
;
761 if (reloc_entry
->address
> input_section
->_cooked_size
)
762 return bfd_reloc_outofrange
;
764 /* Save the information, and let LO16 do the actual relocation. */
765 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
767 return bfd_reloc_outofrange
;
768 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
769 n
->addend
= relocation
;
770 n
->next
= mips_hi16_list
;
773 if (output_bfd
!= (bfd
*) NULL
)
774 reloc_entry
->address
+= input_section
->output_offset
;
779 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
780 inplace relocation; this function exists in order to do the
781 R_MIPS_HI16 relocation described above. */
783 bfd_reloc_status_type
784 _bfd_mips_elf_lo16_reloc (abfd
,
792 arelent
*reloc_entry
;
795 asection
*input_section
;
797 char **error_message
;
799 arelent gp_disp_relent
;
801 if (mips_hi16_list
!= NULL
)
811 struct mips_hi16
*next
;
813 /* Do the HI16 relocation. Note that we actually don't need
814 to know anything about the LO16 itself, except where to
815 find the low 16 bits of the addend needed by the LO16. */
816 insn
= bfd_get_32 (abfd
, l
->addr
);
817 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
819 val
= ((insn
& 0xffff) << 16) + vallo
;
822 /* The low order 16 bits are always treated as a signed
823 value. Therefore, a negative value in the low order bits
824 requires an adjustment in the high order bits. We need
825 to make this adjustment in two ways: once for the bits we
826 took from the data, and once for the bits we are putting
827 back in to the data. */
828 if ((vallo
& 0x8000) != 0)
830 if ((val
& 0x8000) != 0)
833 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
834 bfd_put_32 (abfd
, insn
, l
->addr
);
836 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
838 gp_disp_relent
= *reloc_entry
;
839 reloc_entry
= &gp_disp_relent
;
840 reloc_entry
->addend
= l
->addend
;
848 mips_hi16_list
= NULL
;
850 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
852 bfd_reloc_status_type ret
;
853 bfd_vma gp
, relocation
;
855 /* FIXME: Does this case ever occur? */
857 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
858 if (ret
!= bfd_reloc_ok
)
861 relocation
= gp
- reloc_entry
->address
;
862 relocation
+= symbol
->section
->output_section
->vma
;
863 relocation
+= symbol
->section
->output_offset
;
864 relocation
+= reloc_entry
->addend
;
866 if (reloc_entry
->address
> input_section
->_cooked_size
)
867 return bfd_reloc_outofrange
;
869 gp_disp_relent
= *reloc_entry
;
870 reloc_entry
= &gp_disp_relent
;
871 reloc_entry
->addend
= relocation
- 4;
874 /* Now do the LO16 reloc in the usual way. */
875 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
876 input_section
, output_bfd
, error_message
);
879 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
880 table used for PIC code. If the symbol is an external symbol, the
881 instruction is modified to contain the offset of the appropriate
882 entry in the global offset table. If the symbol is a section
883 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
884 addends are combined to form the real addend against the section
885 symbol; the GOT16 is modified to contain the offset of an entry in
886 the global offset table, and the LO16 is modified to offset it
887 appropriately. Thus an offset larger than 16 bits requires a
888 modified value in the global offset table.
890 This implementation suffices for the assembler, but the linker does
891 not yet know how to create global offset tables. */
893 bfd_reloc_status_type
894 _bfd_mips_elf_got16_reloc (abfd
,
902 arelent
*reloc_entry
;
905 asection
*input_section
;
907 char **error_message
;
909 /* If we're relocating, and this an external symbol, we don't want
910 to change anything. */
911 if (output_bfd
!= (bfd
*) NULL
912 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
913 && reloc_entry
->addend
== 0)
915 reloc_entry
->address
+= input_section
->output_offset
;
919 /* If we're relocating, and this is a local symbol, we can handle it
921 if (output_bfd
!= (bfd
*) NULL
922 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
923 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
924 input_section
, output_bfd
, error_message
);
929 /* We have to figure out the gp value, so that we can adjust the
930 symbol value correctly. We look up the symbol _gp in the output
931 BFD. If we can't find it, we're stuck. We cache it in the ELF
932 target data. We don't need to adjust the symbol value for an
933 external symbol if we are producing relocateable output. */
935 static bfd_reloc_status_type
936 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
939 boolean relocateable
;
940 char **error_message
;
943 if (bfd_is_und_section (symbol
->section
)
947 return bfd_reloc_undefined
;
950 *pgp
= _bfd_get_gp_value (output_bfd
);
953 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
957 /* Make up a value. */
958 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
959 _bfd_set_gp_value (output_bfd
, *pgp
);
967 count
= bfd_get_symcount (output_bfd
);
968 sym
= bfd_get_outsymbols (output_bfd
);
970 if (sym
== (asymbol
**) NULL
)
974 for (i
= 0; i
< count
; i
++, sym
++)
976 register CONST
char *name
;
978 name
= bfd_asymbol_name (*sym
);
979 if (*name
== '_' && strcmp (name
, "_gp") == 0)
981 *pgp
= bfd_asymbol_value (*sym
);
982 _bfd_set_gp_value (output_bfd
, *pgp
);
990 /* Only get the error once. */
992 _bfd_set_gp_value (output_bfd
, *pgp
);
994 (char *) "GP relative relocation when _gp not defined";
995 return bfd_reloc_dangerous
;
1000 return bfd_reloc_ok
;
1003 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1004 become the offset from the gp register. This function also handles
1005 R_MIPS_LITERAL relocations, although those can be handled more
1006 cleverly because the entries in the .lit8 and .lit4 sections can be
1009 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1010 arelent
*, asection
*,
1011 boolean
, PTR
, bfd_vma
));
1013 bfd_reloc_status_type
1014 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1015 output_bfd
, error_message
)
1017 arelent
*reloc_entry
;
1020 asection
*input_section
;
1022 char **error_message
;
1024 boolean relocateable
;
1025 bfd_reloc_status_type ret
;
1028 /* If we're relocating, and this is an external symbol with no
1029 addend, we don't want to change anything. We will only have an
1030 addend if this is a newly created reloc, not read from an ELF
1032 if (output_bfd
!= (bfd
*) NULL
1033 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1034 && reloc_entry
->addend
== 0)
1036 reloc_entry
->address
+= input_section
->output_offset
;
1037 return bfd_reloc_ok
;
1040 if (output_bfd
!= (bfd
*) NULL
)
1041 relocateable
= true;
1044 relocateable
= false;
1045 output_bfd
= symbol
->section
->output_section
->owner
;
1048 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1050 if (ret
!= bfd_reloc_ok
)
1053 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1054 relocateable
, data
, gp
);
1057 static bfd_reloc_status_type
1058 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1062 arelent
*reloc_entry
;
1063 asection
*input_section
;
1064 boolean relocateable
;
1072 if (bfd_is_com_section (symbol
->section
))
1075 relocation
= symbol
->value
;
1077 relocation
+= symbol
->section
->output_section
->vma
;
1078 relocation
+= symbol
->section
->output_offset
;
1080 if (reloc_entry
->address
> input_section
->_cooked_size
)
1081 return bfd_reloc_outofrange
;
1083 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1085 /* Set val to the offset into the section or symbol. */
1086 if (reloc_entry
->howto
->src_mask
== 0)
1088 /* This case occurs with the 64-bit MIPS ELF ABI. */
1089 val
= reloc_entry
->addend
;
1093 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1098 /* Adjust val for the final section location and GP value. If we
1099 are producing relocateable output, we don't want to do this for
1100 an external symbol. */
1102 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1103 val
+= relocation
- gp
;
1105 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1106 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1109 reloc_entry
->address
+= input_section
->output_offset
;
1111 /* Make sure it fit in 16 bits. */
1112 if (val
>= 0x8000 && val
< 0xffff8000)
1113 return bfd_reloc_overflow
;
1115 return bfd_reloc_ok
;
1118 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1119 from the gp register? XXX */
1121 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1122 arelent
*, asection
*,
1123 boolean
, PTR
, bfd_vma
));
1125 bfd_reloc_status_type
1126 _bfd_mips_elf_gprel32_reloc (abfd
,
1134 arelent
*reloc_entry
;
1137 asection
*input_section
;
1139 char **error_message
;
1141 boolean relocateable
;
1142 bfd_reloc_status_type ret
;
1145 /* If we're relocating, and this is an external symbol with no
1146 addend, we don't want to change anything. We will only have an
1147 addend if this is a newly created reloc, not read from an ELF
1149 if (output_bfd
!= (bfd
*) NULL
1150 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1151 && reloc_entry
->addend
== 0)
1153 *error_message
= (char *)
1154 "32bits gp relative relocation occurs for an external symbol";
1155 return bfd_reloc_outofrange
;
1158 if (output_bfd
!= (bfd
*) NULL
)
1160 relocateable
= true;
1161 gp
= _bfd_get_gp_value (output_bfd
);
1165 relocateable
= false;
1166 output_bfd
= symbol
->section
->output_section
->owner
;
1168 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1169 error_message
, &gp
);
1170 if (ret
!= bfd_reloc_ok
)
1174 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1175 relocateable
, data
, gp
);
1178 static bfd_reloc_status_type
1179 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1183 arelent
*reloc_entry
;
1184 asection
*input_section
;
1185 boolean relocateable
;
1192 if (bfd_is_com_section (symbol
->section
))
1195 relocation
= symbol
->value
;
1197 relocation
+= symbol
->section
->output_section
->vma
;
1198 relocation
+= symbol
->section
->output_offset
;
1200 if (reloc_entry
->address
> input_section
->_cooked_size
)
1201 return bfd_reloc_outofrange
;
1203 if (reloc_entry
->howto
->src_mask
== 0)
1205 /* This case arises with the 64-bit MIPS ELF ABI. */
1209 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1211 /* Set val to the offset into the section or symbol. */
1212 val
+= reloc_entry
->addend
;
1214 /* Adjust val for the final section location and GP value. If we
1215 are producing relocateable output, we don't want to do this for
1216 an external symbol. */
1218 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1219 val
+= relocation
- gp
;
1221 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1224 reloc_entry
->address
+= input_section
->output_offset
;
1226 return bfd_reloc_ok
;
1229 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1231 struct elf_reloc_map
{
1232 bfd_reloc_code_real_type bfd_reloc_val
;
1233 enum reloc_type elf_reloc_val
;
1236 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1238 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1239 { BFD_RELOC_16
, R_MIPS_16
},
1240 { BFD_RELOC_32
, R_MIPS_32
},
1241 { BFD_RELOC_CTOR
, R_MIPS_32
},
1242 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1243 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1244 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1245 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1246 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1247 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1248 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1249 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1250 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1251 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1252 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1253 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1254 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
}
1257 /* Given a BFD reloc type, return a howto structure. */
1259 static reloc_howto_type
*
1260 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1262 bfd_reloc_code_real_type code
;
1266 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1268 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1269 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1274 /* Given a MIPS reloc type, fill in an arelent structure. */
1277 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1280 Elf32_Internal_Rel
*dst
;
1282 unsigned int r_type
;
1284 r_type
= ELF32_R_TYPE (dst
->r_info
);
1285 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1286 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1288 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1289 value for the object file. We get the addend now, rather than
1290 when we do the relocation, because the symbol manipulations done
1291 by the linker may cause us to lose track of the input BFD. */
1292 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1293 && (r_type
== (unsigned int) R_MIPS_GPREL16
1294 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1295 cache_ptr
->addend
= elf_gp (abfd
);
1298 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1299 routines swap this structure in and out. They are used outside of
1300 BFD, so they are globally visible. */
1303 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1305 const Elf32_External_RegInfo
*ex
;
1308 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1309 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1310 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1311 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1312 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1313 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1317 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1319 const Elf32_RegInfo
*in
;
1320 Elf32_External_RegInfo
*ex
;
1322 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1323 (bfd_byte
*) ex
->ri_gprmask
);
1324 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1325 (bfd_byte
*) ex
->ri_cprmask
[0]);
1326 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1327 (bfd_byte
*) ex
->ri_cprmask
[1]);
1328 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1329 (bfd_byte
*) ex
->ri_cprmask
[2]);
1330 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1331 (bfd_byte
*) ex
->ri_cprmask
[3]);
1332 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1333 (bfd_byte
*) ex
->ri_gp_value
);
1336 /* In the 64 bit ABI, the .MIPS.options section holds register
1337 information in an Elf64_Reginfo structure. These routines swap
1338 them in and out. They are globally visible because they are used
1339 outside of BFD. These routines are here so that gas can call them
1340 without worrying about whether the 64 bit ABI has been included. */
1343 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1345 const Elf64_External_RegInfo
*ex
;
1346 Elf64_Internal_RegInfo
*in
;
1348 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1349 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
1350 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1351 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1352 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1353 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1354 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1358 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1360 const Elf64_Internal_RegInfo
*in
;
1361 Elf64_External_RegInfo
*ex
;
1363 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1364 (bfd_byte
*) ex
->ri_gprmask
);
1365 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
1366 (bfd_byte
*) ex
->ri_pad
);
1367 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1368 (bfd_byte
*) ex
->ri_cprmask
[0]);
1369 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1370 (bfd_byte
*) ex
->ri_cprmask
[1]);
1371 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1372 (bfd_byte
*) ex
->ri_cprmask
[2]);
1373 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1374 (bfd_byte
*) ex
->ri_cprmask
[3]);
1375 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1376 (bfd_byte
*) ex
->ri_gp_value
);
1379 /* Swap an entry in a .gptab section. Note that these routines rely
1380 on the equivalence of the two elements of the union. */
1383 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1385 const Elf32_External_gptab
*ex
;
1388 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1389 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1393 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1395 const Elf32_gptab
*in
;
1396 Elf32_External_gptab
*ex
;
1398 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1399 ex
->gt_entry
.gt_g_value
);
1400 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1401 ex
->gt_entry
.gt_bytes
);
1405 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1407 const Elf32_compact_rel
*in
;
1408 Elf32_External_compact_rel
*ex
;
1410 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
1411 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
1412 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
1413 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
1414 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
1415 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
1419 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1421 const Elf32_crinfo
*in
;
1422 Elf32_External_crinfo
*ex
;
1426 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1427 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1428 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1429 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1430 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
1431 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
1432 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
1435 /* Swap in an options header. */
1438 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1440 const Elf_External_Options
*ex
;
1441 Elf_Internal_Options
*in
;
1443 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
1444 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
1445 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
1446 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
1449 /* Swap out an options header. */
1452 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
1454 const Elf_Internal_Options
*in
;
1455 Elf_External_Options
*ex
;
1457 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
1458 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
1459 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
1460 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
1463 /* Determine whether a symbol is global for the purposes of splitting
1464 the symbol table into global symbols and local symbols. At least
1465 on Irix 5, this split must be between section symbols and all other
1466 symbols. On most ELF targets the split is between static symbols
1467 and externally visible symbols. */
1471 mips_elf_sym_is_global (abfd
, sym
)
1475 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
1478 /* Set the right machine number for a MIPS ELF file. This is used for
1479 both the 32-bit and the 64-bit ABI. */
1482 _bfd_mips_elf_object_p (abfd
)
1485 switch (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
)
1489 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 3000);
1493 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 6000);
1497 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 4000);
1501 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 8000);
1508 /* Set the right machine number for a 32-bit MIPS ELF file. */
1511 mips_elf32_object_p (abfd
)
1514 /* Irix 5 is broken. Object file symbol tables are not always
1515 sorted correctly such that local symbols precede global symbols,
1516 and the sh_info field in the symbol table is not always right. */
1517 elf_bad_symtab (abfd
) = true;
1519 return _bfd_mips_elf_object_p (abfd
);
1522 /* The final processing done just before writing out a MIPS ELF object
1523 file. This gets the MIPS architecture right based on the machine
1524 number. This is used by both the 32-bit and the 64-bit ABI. */
1528 _bfd_mips_elf_final_write_processing (abfd
, linker
)
1534 Elf_Internal_Shdr
**hdrpp
;
1538 switch (bfd_get_mach (abfd
))
1541 val
= E_MIPS_ARCH_1
;
1545 val
= E_MIPS_ARCH_2
;
1549 val
= E_MIPS_ARCH_3
;
1553 val
= E_MIPS_ARCH_4
;
1561 elf_elfheader (abfd
)->e_flags
&=~ EF_MIPS_ARCH
;
1562 elf_elfheader (abfd
)->e_flags
|= val
;
1564 /* Set the sh_info field for .gptab sections. */
1565 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
1566 i
< elf_elfheader (abfd
)->e_shnum
;
1569 switch ((*hdrpp
)->sh_type
)
1571 case SHT_MIPS_LIBLIST
:
1572 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
1574 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
1577 case SHT_MIPS_GPTAB
:
1578 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1579 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1580 BFD_ASSERT (name
!= NULL
1581 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
1582 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
1583 BFD_ASSERT (sec
!= NULL
);
1584 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1587 case SHT_MIPS_CONTENT
:
1588 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1589 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1590 BFD_ASSERT (name
!= NULL
1591 && strncmp (name
, ".MIPS.content",
1592 sizeof ".MIPS.content" - 1) == 0);
1593 sec
= bfd_get_section_by_name (abfd
,
1594 name
+ sizeof ".MIPS.content" - 1);
1595 BFD_ASSERT (sec
!= NULL
);
1596 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1599 case SHT_MIPS_SYMBOL_LIB
:
1600 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
1602 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
1603 sec
= bfd_get_section_by_name (abfd
, ".liblist");
1605 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1608 case SHT_MIPS_EVENTS
:
1609 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1610 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1611 BFD_ASSERT (name
!= NULL
);
1612 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
1613 sec
= bfd_get_section_by_name (abfd
,
1614 name
+ sizeof ".MIPS.events" - 1);
1617 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
1618 sizeof ".MIPS.post_rel" - 1) == 0);
1619 sec
= bfd_get_section_by_name (abfd
,
1621 + sizeof ".MIPS.post_rel" - 1));
1623 BFD_ASSERT (sec
!= NULL
);
1624 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
1630 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
1633 _bfd_mips_elf_set_private_flags (abfd
, flags
)
1637 BFD_ASSERT (!elf_flags_init (abfd
)
1638 || elf_elfheader (abfd
)->e_flags
== flags
);
1640 elf_elfheader (abfd
)->e_flags
= flags
;
1641 elf_flags_init (abfd
) = true;
1645 /* Copy backend specific data from one object module to another */
1648 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
1652 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1653 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1656 BFD_ASSERT (!elf_flags_init (obfd
)
1657 || (elf_elfheader (obfd
)->e_flags
1658 == elf_elfheader (ibfd
)->e_flags
));
1660 elf_gp (obfd
) = elf_gp (ibfd
);
1661 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1662 elf_flags_init (obfd
) = true;
1666 /* Return the ISA for a MIPS e_flags value. */
1669 elf_mips_isa (flags
)
1672 switch (flags
& EF_MIPS_ARCH
)
1686 /* Merge backend specific data from an object file to the output
1687 object file when linking. */
1690 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
1697 /* Check if we have the same endianess */
1698 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1699 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1701 (*_bfd_error_handler
)
1702 ("%s: compiled for a %s endian system and target is %s endian",
1703 bfd_get_filename (ibfd
),
1704 bfd_big_endian (ibfd
) ? "big" : "little",
1705 bfd_big_endian (obfd
) ? "big" : "little");
1707 bfd_set_error (bfd_error_wrong_format
);
1711 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1712 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1715 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1716 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
1717 old_flags
= elf_elfheader (obfd
)->e_flags
;
1719 if (!elf_flags_init (obfd
)) /* First call, no flags set */
1721 elf_flags_init (obfd
) = true;
1722 elf_elfheader (obfd
)->e_flags
= new_flags
;
1723 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
1724 && bfd_get_arch_info (obfd
)->the_default
)
1725 bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
1727 else if (((new_flags
^ old_flags
) & ~EF_MIPS_NOREORDER
)
1728 == 0) /* Compatible flags are ok */
1730 else /* Incompatible flags */
1732 /* Warn about -fPIC mismatch */
1733 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
1735 new_flags
&= ~EF_MIPS_PIC
;
1736 old_flags
&= ~EF_MIPS_PIC
;
1737 (*_bfd_error_handler
)
1738 ("%s: needs all files compiled with -fPIC",
1739 bfd_get_filename (ibfd
));
1742 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
1744 new_flags
&= ~EF_MIPS_CPIC
;
1745 old_flags
&= ~EF_MIPS_CPIC
;
1746 (*_bfd_error_handler
)
1747 ("%s: needs all files compiled with -mabicalls",
1748 bfd_get_filename (ibfd
));
1751 /* Don't warn about mixing -mips1 and -mips2 code, or mixing
1752 -mips3 and -mips4 code. They will normally use the same data
1753 sizes and calling conventions. */
1754 if ((new_flags
& EF_MIPS_ARCH
) != (old_flags
& EF_MIPS_ARCH
))
1756 int new_isa
, old_isa
;
1758 new_isa
= elf_mips_isa (new_flags
);
1759 old_isa
= elf_mips_isa (old_flags
);
1760 if ((new_isa
== 1 || new_isa
== 2)
1761 ? (old_isa
!= 1 && old_isa
!= 2)
1762 : (old_isa
== 1 || old_isa
== 2))
1763 (*_bfd_error_handler
)
1764 ("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)",
1765 bfd_get_filename (ibfd
), new_isa
, old_isa
);
1767 new_flags
&= ~ EF_MIPS_ARCH
;
1768 old_flags
&= ~ EF_MIPS_ARCH
;
1771 /* Warn about any other mismatches */
1772 if (new_flags
!= old_flags
)
1773 (*_bfd_error_handler
)
1774 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1775 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
1776 (unsigned long) old_flags
);
1778 bfd_set_error (bfd_error_bad_value
);
1785 /* Handle a MIPS specific section when reading an object file. This
1786 is called when elfcode.h finds a section with an unknown type.
1787 This routine supports both the 32-bit and 64-bit ELF ABI.
1789 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
1793 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
1795 Elf_Internal_Shdr
*hdr
;
1798 /* There ought to be a place to keep ELF backend specific flags, but
1799 at the moment there isn't one. We just keep track of the
1800 sections by their name, instead. Fortunately, the ABI gives
1801 suggested names for all the MIPS specific sections, so we will
1802 probably get away with this. */
1803 switch (hdr
->sh_type
)
1805 case SHT_MIPS_LIBLIST
:
1806 if (strcmp (name
, ".liblist") != 0)
1810 if (strcmp (name
, ".msym") != 0)
1813 case SHT_MIPS_CONFLICT
:
1814 if (strcmp (name
, ".conflict") != 0)
1817 case SHT_MIPS_GPTAB
:
1818 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
1821 case SHT_MIPS_UCODE
:
1822 if (strcmp (name
, ".ucode") != 0)
1825 case SHT_MIPS_DEBUG
:
1826 if (strcmp (name
, ".mdebug") != 0)
1829 case SHT_MIPS_REGINFO
:
1830 if (strcmp (name
, ".reginfo") != 0
1831 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
1834 case SHT_MIPS_IFACE
:
1835 if (strcmp (name
, ".MIPS.interfaces") != 0)
1838 case SHT_MIPS_CONTENT
:
1839 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
1842 case SHT_MIPS_OPTIONS
:
1843 if (strcmp (name
, ".options") != 0
1844 && strcmp (name
, ".MIPS.options") != 0)
1847 case SHT_MIPS_DWARF
:
1848 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
1851 case SHT_MIPS_SYMBOL_LIB
:
1852 if (strcmp (name
, ".MIPS.symlib") != 0)
1855 case SHT_MIPS_EVENTS
:
1856 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
1857 && strncmp (name
, ".MIPS.post_rel",
1858 sizeof ".MIPS.post_rel" - 1) != 0)
1865 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1868 if (hdr
->sh_type
== SHT_MIPS_DEBUG
)
1870 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
1871 (bfd_get_section_flags (abfd
,
1880 /* Handle a 32-bit MIPS ELF specific section. */
1883 mips_elf32_section_from_shdr (abfd
, hdr
, name
)
1885 Elf_Internal_Shdr
*hdr
;
1888 if (! _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
))
1891 /* FIXME: We should record sh_info for a .gptab section. */
1893 /* For a .reginfo section, set the gp value in the tdata information
1894 from the contents of this section. We need the gp value while
1895 processing relocs, so we just get it now. The .reginfo section
1896 is not used in the 64-bit MIPS ELF ABI. */
1897 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
1899 Elf32_External_RegInfo ext
;
1902 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
1903 (file_ptr
) 0, sizeof ext
))
1905 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
1906 elf_gp (abfd
) = s
.ri_gp_value
;
1909 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
1910 set the gp value based on what we find. We may see both
1911 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
1912 they should agree. */
1913 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
1915 bfd_byte
*contents
, *l
, *lend
;
1917 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
1918 if (contents
== NULL
)
1920 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
1921 (file_ptr
) 0, hdr
->sh_size
))
1927 lend
= contents
+ hdr
->sh_size
;
1928 while (l
+ sizeof (Elf_External_Options
) <= lend
)
1930 Elf_Internal_Options intopt
;
1932 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
1934 if (intopt
.kind
== ODK_REGINFO
)
1936 Elf32_RegInfo intreg
;
1938 bfd_mips_elf32_swap_reginfo_in
1940 ((Elf32_External_RegInfo
*)
1941 (l
+ sizeof (Elf_External_Options
))),
1943 elf_gp (abfd
) = intreg
.ri_gp_value
;
1953 /* Set the correct type for a MIPS ELF section. We do this by the
1954 section name, which is a hack, but ought to work. This routine is
1955 used by both the 32-bit and the 64-bit ABI. */
1958 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
1960 Elf32_Internal_Shdr
*hdr
;
1963 register const char *name
;
1965 name
= bfd_get_section_name (abfd
, sec
);
1967 if (strcmp (name
, ".liblist") == 0)
1969 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
1970 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
1971 /* The sh_link field is set in final_write_processing. */
1973 else if (strcmp (name
, ".msym") == 0)
1975 hdr
->sh_type
= SHT_MIPS_MSYM
;
1976 hdr
->sh_entsize
= 8;
1977 /* FIXME: Set the sh_info field. */
1979 else if (strcmp (name
, ".conflict") == 0)
1980 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
1981 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
1983 hdr
->sh_type
= SHT_MIPS_GPTAB
;
1984 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
1985 /* The sh_info field is set in final_write_processing. */
1987 else if (strcmp (name
, ".ucode") == 0)
1988 hdr
->sh_type
= SHT_MIPS_UCODE
;
1989 else if (strcmp (name
, ".mdebug") == 0)
1991 hdr
->sh_type
= SHT_MIPS_DEBUG
;
1992 /* In a shared object on Irix 5.3, the .mdebug section has an
1993 entsize of 0. FIXME: Does this matter? */
1994 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
1995 hdr
->sh_entsize
= 0;
1997 hdr
->sh_entsize
= 1;
1999 else if (strcmp (name
, ".reginfo") == 0)
2001 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2002 /* In a shared object on Irix 5.3, the .reginfo section has an
2003 entsize of 0x18. FIXME: Does this matter? */
2004 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2005 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2007 hdr
->sh_entsize
= 1;
2009 /* Force the section size to the correct value, even if the
2010 linker thinks it is larger. The link routine below will only
2011 write out this much data for .reginfo. */
2012 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf32_External_RegInfo
);
2014 else if (SGI_COMPAT (abfd
)
2015 && (strcmp (name
, ".hash") == 0
2016 || strcmp (name
, ".dynamic") == 0
2017 || strcmp (name
, ".dynstr") == 0))
2019 hdr
->sh_entsize
= 0;
2020 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2022 else if (strcmp (name
, ".got") == 0
2023 || strcmp (name
, ".sdata") == 0
2024 || strcmp (name
, ".sbss") == 0
2025 || strcmp (name
, ".lit4") == 0
2026 || strcmp (name
, ".lit8") == 0)
2027 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2028 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2030 hdr
->sh_type
= SHT_MIPS_IFACE
;
2031 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2033 else if (strcmp (name
, ".MIPS.content") == 0)
2035 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2036 /* The sh_info field is set in final_write_processing. */
2038 else if (strcmp (name
, ".options") == 0
2039 || strcmp (name
, ".MIPS.options") == 0)
2041 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2042 hdr
->sh_entsize
= 1;
2043 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2045 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2046 hdr
->sh_type
= SHT_MIPS_DWARF
;
2047 else if (strcmp (name
, ".MIPS.symlib") == 0)
2049 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2050 /* The sh_link and sh_info fields are set in
2051 final_write_processing. */
2053 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2054 || strncmp (name
, ".MIPS.post_rel",
2055 sizeof ".MIPS.post_rel" - 1) == 0)
2057 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2058 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2059 /* The sh_link field is set in final_write_processing. */
2065 /* Given a BFD section, try to locate the corresponding ELF section
2066 index. This is used by both the 32-bit and the 64-bit ABI.
2067 Actually, it's not clear to me that the 64-bit ABI supports these,
2068 but for non-PIC objects we will certainly want support for at least
2069 the .scommon section. */
2072 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2074 Elf32_Internal_Shdr
*hdr
;
2078 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2080 *retval
= SHN_MIPS_SCOMMON
;
2083 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2085 *retval
= SHN_MIPS_ACOMMON
;
2091 /* When are writing out the .options or .MIPS.options section,
2092 remember the bytes we are writing out, so that we can install the
2093 GP value in the section_processing routine. */
2096 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2101 bfd_size_type count
;
2103 if (strcmp (section
->name
, ".options") == 0
2104 || strcmp (section
->name
, ".MIPS.options") == 0)
2108 if (elf_section_data (section
) == NULL
)
2110 section
->used_by_bfd
=
2111 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
2112 if (elf_section_data (section
) == NULL
)
2115 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
2120 if (section
->_cooked_size
!= 0)
2121 size
= section
->_cooked_size
;
2123 size
= section
->_raw_size
;
2124 c
= (PTR
) bfd_zalloc (abfd
, size
);
2127 elf_section_data (section
)->tdata
= (PTR
) c
;
2130 memcpy (c
+ offset
, location
, count
);
2133 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
2137 /* Work over a section just before writing it out. This routine is
2138 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2139 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2143 _bfd_mips_elf_section_processing (abfd
, hdr
)
2145 Elf_Internal_Shdr
*hdr
;
2147 if (hdr
->bfd_section
!= NULL
)
2149 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
2151 if (strcmp (name
, ".sdata") == 0)
2153 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2154 hdr
->sh_type
= SHT_PROGBITS
;
2156 else if (strcmp (name
, ".sbss") == 0)
2158 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2159 hdr
->sh_type
= SHT_NOBITS
;
2161 else if (strcmp (name
, ".lit8") == 0
2162 || strcmp (name
, ".lit4") == 0)
2164 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2165 hdr
->sh_type
= SHT_PROGBITS
;
2167 else if (strcmp (name
, ".compact_rel") == 0)
2170 hdr
->sh_type
= SHT_PROGBITS
;
2172 else if (strcmp (name
, ".rtproc") == 0)
2174 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
2176 unsigned int adjust
;
2178 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
2180 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
2188 /* Work over a section just before writing it out. We update the GP
2189 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2190 on the value we are using. */
2193 mips_elf32_section_processing (abfd
, hdr
)
2195 Elf32_Internal_Shdr
*hdr
;
2197 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2201 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2202 BFD_ASSERT (hdr
->contents
== NULL
);
2205 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2208 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2209 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2213 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2214 && hdr
->bfd_section
!= NULL
2215 && elf_section_data (hdr
->bfd_section
) != NULL
2216 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2218 bfd_byte
*contents
, *l
, *lend
;
2220 /* We stored the section contents in the elf_section_data tdata
2221 field in the set_section_contents routine. We save the
2222 section contents so that we don't have to read them again.
2223 At this point we know that elf_gp is set, so we can look
2224 through the section contents to see if there is an
2225 ODK_REGINFO structure. */
2227 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2229 lend
= contents
+ hdr
->sh_size
;
2230 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2232 Elf_Internal_Options intopt
;
2234 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2236 if (intopt
.kind
== ODK_REGINFO
)
2243 + sizeof (Elf_External_Options
)
2244 + (sizeof (Elf32_External_RegInfo
) - 4)),
2247 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
2248 if (bfd_write (buf
, 1, 4, abfd
) != 4)
2255 return _bfd_mips_elf_section_processing (abfd
, hdr
);
2258 /* MIPS ELF uses two common sections. One is the usual one, and the
2259 other is for small objects. All the small objects are kept
2260 together, and then referenced via the gp pointer, which yields
2261 faster assembler code. This is what we use for the small common
2262 section. This approach is copied from ecoff.c. */
2263 static asection mips_elf_scom_section
;
2264 static asymbol mips_elf_scom_symbol
;
2265 static asymbol
*mips_elf_scom_symbol_ptr
;
2267 /* MIPS ELF also uses an acommon section, which represents an
2268 allocated common symbol which may be overridden by a
2269 definition in a shared library. */
2270 static asection mips_elf_acom_section
;
2271 static asymbol mips_elf_acom_symbol
;
2272 static asymbol
*mips_elf_acom_symbol_ptr
;
2274 /* The Irix 5 support uses two virtual sections, which represent
2275 text/data symbols defined in dynamic objects. */
2276 static asection mips_elf_text_section
;
2277 static asection
*mips_elf_text_section_ptr
;
2278 static asymbol mips_elf_text_symbol
;
2279 static asymbol
*mips_elf_text_symbol_ptr
;
2281 static asection mips_elf_data_section
;
2282 static asection
*mips_elf_data_section_ptr
;
2283 static asymbol mips_elf_data_symbol
;
2284 static asymbol
*mips_elf_data_symbol_ptr
;
2286 /* Handle the special MIPS section numbers that a symbol may use.
2287 This is used for both the 32-bit and the 64-bit ABI. */
2290 _bfd_mips_elf_symbol_processing (abfd
, asym
)
2294 elf_symbol_type
*elfsym
;
2296 elfsym
= (elf_symbol_type
*) asym
;
2297 switch (elfsym
->internal_elf_sym
.st_shndx
)
2299 case SHN_MIPS_ACOMMON
:
2300 /* This section is used in a dynamically linked executable file.
2301 It is an allocated common section. The dynamic linker can
2302 either resolve these symbols to something in a shared
2303 library, or it can just leave them here. For our purposes,
2304 we can consider these symbols to be in a new section. */
2305 if (mips_elf_acom_section
.name
== NULL
)
2307 /* Initialize the acommon section. */
2308 mips_elf_acom_section
.name
= ".acommon";
2309 mips_elf_acom_section
.flags
= SEC_ALLOC
;
2310 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
2311 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
2312 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
2313 mips_elf_acom_symbol
.name
= ".acommon";
2314 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
2315 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
2316 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
2318 asym
->section
= &mips_elf_acom_section
;
2322 /* Common symbols less than the GP size are automatically
2323 treated as SHN_MIPS_SCOMMON symbols. */
2324 if (asym
->value
> elf_gp_size (abfd
))
2327 case SHN_MIPS_SCOMMON
:
2328 if (mips_elf_scom_section
.name
== NULL
)
2330 /* Initialize the small common section. */
2331 mips_elf_scom_section
.name
= ".scommon";
2332 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
2333 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
2334 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
2335 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
2336 mips_elf_scom_symbol
.name
= ".scommon";
2337 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2338 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
2339 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
2341 asym
->section
= &mips_elf_scom_section
;
2342 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2345 case SHN_MIPS_SUNDEFINED
:
2346 asym
->section
= bfd_und_section_ptr
;
2349 #if 0 /* for SGI_COMPAT */
2351 asym
->section
= mips_elf_text_section_ptr
;
2355 asym
->section
= mips_elf_data_section_ptr
;
2361 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
2365 mips_elf_additional_program_headers (abfd
)
2373 if (! SGI_COMPAT (abfd
))
2376 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2377 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2379 /* We need a PT_MIPS_REGINFO segment. */
2383 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2384 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2386 /* We need a PT_MIPS_RTPROC segment. */
2393 /* Modify the segment map for an Irix 5 executable. */
2396 mips_elf_modify_segment_map (abfd
)
2400 struct elf_segment_map
*m
, **pm
;
2402 if (! SGI_COMPAT (abfd
))
2405 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
2407 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2408 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2410 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2411 if (m
->p_type
== PT_MIPS_REGINFO
)
2415 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2419 m
->p_type
= PT_MIPS_REGINFO
;
2423 /* We want to put it after the PHDR and INTERP segments. */
2424 pm
= &elf_tdata (abfd
)->segment_map
;
2426 && ((*pm
)->p_type
== PT_PHDR
2427 || (*pm
)->p_type
== PT_INTERP
))
2435 /* If there are .dynamic and .mdebug sections, we make a room for
2436 the RTPROC header. FIXME: Rewrite without section names. */
2437 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
2438 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2439 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2441 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2442 if (m
->p_type
== PT_MIPS_RTPROC
)
2446 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2450 m
->p_type
= PT_MIPS_RTPROC
;
2452 s
= bfd_get_section_by_name (abfd
, ".rtproc");
2457 m
->p_flags_valid
= 1;
2465 /* We want to put it after the DYNAMIC segment. */
2466 pm
= &elf_tdata (abfd
)->segment_map
;
2467 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
2477 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
2478 .dynsym, and .hash sections, and everything in between. */
2479 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
2480 if ((*pm
)->p_type
== PT_DYNAMIC
)
2485 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
2487 static const char *sec_names
[] =
2488 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
2491 struct elf_segment_map
*n
;
2495 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
2497 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
2498 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2504 sz
= s
->_cooked_size
;
2507 if (high
< s
->vma
+ sz
)
2513 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2514 if ((s
->flags
& SEC_LOAD
) != 0
2517 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2521 n
= ((struct elf_segment_map
*)
2522 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
2529 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2531 if ((s
->flags
& SEC_LOAD
) != 0
2534 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2548 /* The structure of the runtime procedure descriptor created by the
2549 loader for use by the static exception system. */
2551 typedef struct runtime_pdr
{
2552 bfd_vma adr
; /* memory address of start of procedure */
2553 long regmask
; /* save register mask */
2554 long regoffset
; /* save register offset */
2555 long fregmask
; /* save floating point register mask */
2556 long fregoffset
; /* save floating point register offset */
2557 long frameoffset
; /* frame size */
2558 short framereg
; /* frame pointer register */
2559 short pcreg
; /* offset or reg of return pc */
2560 long irpss
; /* index into the runtime string table */
2562 struct exception_info
*exception_info
;/* pointer to exception array */
2564 #define cbRPDR sizeof(RPDR)
2565 #define rpdNil ((pRPDR) 0)
2567 /* Swap RPDR (runtime procedure table entry) for output. */
2569 static void ecoff_swap_rpdr_out
2570 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
2573 ecoff_swap_rpdr_out (abfd
, in
, ex
)
2576 struct rpdr_ext
*ex
;
2578 /* ecoff_put_off was defined in ecoffswap.h. */
2579 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
2580 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
2581 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
2582 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
2583 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
2584 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
2586 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
2587 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
2589 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
2591 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
2595 /* Read ECOFF debugging information from a .mdebug section into a
2596 ecoff_debug_info structure. */
2599 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
2602 struct ecoff_debug_info
*debug
;
2605 const struct ecoff_debug_swap
*swap
;
2606 char *ext_hdr
= NULL
;
2608 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2610 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
2611 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
2614 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
2615 swap
->external_hdr_size
)
2619 symhdr
= &debug
->symbolic_header
;
2620 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
2622 /* The symbolic header contains absolute file offsets and sizes to
2624 #define READ(ptr, offset, count, size, type) \
2625 if (symhdr->count == 0) \
2626 debug->ptr = NULL; \
2629 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
2630 if (debug->ptr == NULL) \
2631 goto error_return; \
2632 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
2633 || (bfd_read (debug->ptr, size, symhdr->count, \
2634 abfd) != size * symhdr->count)) \
2635 goto error_return; \
2638 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
2639 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
2640 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
2641 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
2642 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
2643 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
2645 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
2646 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
2647 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
2648 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
2649 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
2653 debug
->adjust
= NULL
;
2658 if (ext_hdr
!= NULL
)
2660 if (debug
->line
!= NULL
)
2662 if (debug
->external_dnr
!= NULL
)
2663 free (debug
->external_dnr
);
2664 if (debug
->external_pdr
!= NULL
)
2665 free (debug
->external_pdr
);
2666 if (debug
->external_sym
!= NULL
)
2667 free (debug
->external_sym
);
2668 if (debug
->external_opt
!= NULL
)
2669 free (debug
->external_opt
);
2670 if (debug
->external_aux
!= NULL
)
2671 free (debug
->external_aux
);
2672 if (debug
->ss
!= NULL
)
2674 if (debug
->ssext
!= NULL
)
2675 free (debug
->ssext
);
2676 if (debug
->external_fdr
!= NULL
)
2677 free (debug
->external_fdr
);
2678 if (debug
->external_rfd
!= NULL
)
2679 free (debug
->external_rfd
);
2680 if (debug
->external_ext
!= NULL
)
2681 free (debug
->external_ext
);
2685 /* MIPS ELF local labels start with '$', not 'L'. */
2689 mips_elf_is_local_label (abfd
, symbol
)
2693 return symbol
->name
[0] == '$';
2696 /* MIPS ELF uses a special find_nearest_line routine in order the
2697 handle the ECOFF debugging information. */
2699 struct mips_elf_find_line
2701 struct ecoff_debug_info d
;
2702 struct ecoff_find_line i
;
2706 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
2707 functionname_ptr
, line_ptr
)
2712 const char **filename_ptr
;
2713 const char **functionname_ptr
;
2714 unsigned int *line_ptr
;
2718 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
2722 struct mips_elf_find_line
*fi
;
2723 const struct ecoff_debug_swap
* const swap
=
2724 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2726 /* If we are called during a link, mips_elf_final_link may have
2727 cleared the SEC_HAS_CONTENTS field. We force it back on here
2728 if appropriate (which it normally will be). */
2729 origflags
= msec
->flags
;
2730 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
2731 msec
->flags
|= SEC_HAS_CONTENTS
;
2733 fi
= elf_tdata (abfd
)->find_line_info
;
2736 bfd_size_type external_fdr_size
;
2739 struct fdr
*fdr_ptr
;
2741 fi
= ((struct mips_elf_find_line
*)
2742 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
2745 msec
->flags
= origflags
;
2749 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
2751 msec
->flags
= origflags
;
2755 /* Swap in the FDR information. */
2756 fi
->d
.fdr
= ((struct fdr
*)
2758 (fi
->d
.symbolic_header
.ifdMax
*
2759 sizeof (struct fdr
))));
2760 if (fi
->d
.fdr
== NULL
)
2762 msec
->flags
= origflags
;
2765 external_fdr_size
= swap
->external_fdr_size
;
2766 fdr_ptr
= fi
->d
.fdr
;
2767 fraw_src
= (char *) fi
->d
.external_fdr
;
2768 fraw_end
= (fraw_src
2769 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
2770 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
2771 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
2773 elf_tdata (abfd
)->find_line_info
= fi
;
2775 /* Note that we don't bother to ever free this information.
2776 find_nearest_line is either called all the time, as in
2777 objdump -l, so the information should be saved, or it is
2778 rarely called, as in ld error messages, so the memory
2779 wasted is unimportant. Still, it would probably be a
2780 good idea for free_cached_info to throw it away. */
2783 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
2784 &fi
->i
, filename_ptr
, functionname_ptr
,
2787 msec
->flags
= origflags
;
2791 msec
->flags
= origflags
;
2794 /* Fall back on the generic ELF find_nearest_line routine. */
2796 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
2797 filename_ptr
, functionname_ptr
,
2801 /* The MIPS ELF linker needs additional information for each symbol in
2802 the global hash table. */
2804 struct mips_elf_link_hash_entry
2806 struct elf_link_hash_entry root
;
2808 /* External symbol information. */
2811 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
2812 unsigned int mips_32_relocs
;
2815 /* MIPS ELF linker hash table. */
2817 struct mips_elf_link_hash_table
2819 struct elf_link_hash_table root
;
2820 /* String section indices for the dynamic section symbols. */
2821 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
2822 /* The number of .rtproc entries. */
2823 bfd_size_type procedure_count
;
2824 /* The size of the .compact_rel section (if SGI_COMPAT). */
2825 bfd_size_type compact_rel_size
;
2826 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
2827 entry is set to the address of __rld_obj_head as in Irix 5. */
2828 boolean use_rld_obj_head
;
2829 /* This is the value of the __rld_map or __rld_obj_head symbol. */
2833 /* Look up an entry in a MIPS ELF linker hash table. */
2835 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
2836 ((struct mips_elf_link_hash_entry *) \
2837 elf_link_hash_lookup (&(table)->root, (string), (create), \
2840 /* Traverse a MIPS ELF linker hash table. */
2842 #define mips_elf_link_hash_traverse(table, func, info) \
2843 (elf_link_hash_traverse \
2845 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
2848 /* Get the MIPS ELF linker hash table from a link_info structure. */
2850 #define mips_elf_hash_table(p) \
2851 ((struct mips_elf_link_hash_table *) ((p)->hash))
2853 static boolean mips_elf_output_extsym
2854 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
2856 /* Create an entry in a MIPS ELF linker hash table. */
2858 static struct bfd_hash_entry
*
2859 mips_elf_link_hash_newfunc (entry
, table
, string
)
2860 struct bfd_hash_entry
*entry
;
2861 struct bfd_hash_table
*table
;
2864 struct mips_elf_link_hash_entry
*ret
=
2865 (struct mips_elf_link_hash_entry
*) entry
;
2867 /* Allocate the structure if it has not already been allocated by a
2869 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
2870 ret
= ((struct mips_elf_link_hash_entry
*)
2871 bfd_hash_allocate (table
,
2872 sizeof (struct mips_elf_link_hash_entry
)));
2873 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
2874 return (struct bfd_hash_entry
*) ret
;
2876 /* Call the allocation method of the superclass. */
2877 ret
= ((struct mips_elf_link_hash_entry
*)
2878 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2880 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
2882 /* Set local fields. */
2883 memset (&ret
->esym
, 0, sizeof (EXTR
));
2884 /* We use -2 as a marker to indicate that the information has
2885 not been set. -1 means there is no associated ifd. */
2887 ret
->mips_32_relocs
= 0;
2890 return (struct bfd_hash_entry
*) ret
;
2893 /* Create a MIPS ELF linker hash table. */
2895 static struct bfd_link_hash_table
*
2896 mips_elf_link_hash_table_create (abfd
)
2899 struct mips_elf_link_hash_table
*ret
;
2902 ret
= ((struct mips_elf_link_hash_table
*)
2903 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
2904 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
2907 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
2908 mips_elf_link_hash_newfunc
))
2910 bfd_release (abfd
, ret
);
2914 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
2915 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
2916 ret
->procedure_count
= 0;
2917 ret
->compact_rel_size
= 0;
2918 ret
->use_rld_obj_head
= false;
2921 return &ret
->root
.root
;
2924 /* Hook called by the linker routine which adds symbols from an object
2925 file. We must handle the special MIPS section numbers here. */
2929 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2931 struct bfd_link_info
*info
;
2932 const Elf_Internal_Sym
*sym
;
2938 if (SGI_COMPAT (abfd
)
2939 && (abfd
->flags
& DYNAMIC
) != 0
2940 && strcmp (*namep
, "_rld_new_interface") == 0)
2942 /* Skip Irix 5 rld entry name. */
2947 switch (sym
->st_shndx
)
2950 /* Common symbols less than the GP size are automatically
2951 treated as SHN_MIPS_SCOMMON symbols. */
2952 if (sym
->st_size
> elf_gp_size (abfd
))
2955 case SHN_MIPS_SCOMMON
:
2956 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
2957 (*secp
)->flags
|= SEC_IS_COMMON
;
2958 *valp
= sym
->st_size
;
2962 /* This section is used in a shared object. */
2963 if (mips_elf_text_section_ptr
== NULL
)
2965 /* Initialize the section. */
2966 mips_elf_text_section
.name
= ".text";
2967 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
2968 mips_elf_text_section
.output_section
= NULL
;
2969 mips_elf_text_section
.owner
= abfd
;
2970 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
2971 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
2972 mips_elf_text_symbol
.name
= ".text";
2973 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
2974 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
2975 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
2976 mips_elf_text_section_ptr
= &mips_elf_text_section
;
2979 *secp
= bfd_und_section_ptr
;
2981 *secp
= mips_elf_text_section_ptr
;
2984 case SHN_MIPS_ACOMMON
:
2985 /* Fall through. XXX Can we treat this as allocated data? */
2987 /* This section is used in a shared object. */
2988 if (mips_elf_data_section_ptr
== NULL
)
2990 /* Initialize the section. */
2991 mips_elf_data_section
.name
= ".data";
2992 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
2993 mips_elf_data_section
.output_section
= NULL
;
2994 mips_elf_data_section
.owner
= abfd
;
2995 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
2996 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
2997 mips_elf_data_symbol
.name
= ".data";
2998 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
2999 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
3000 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
3001 mips_elf_data_section_ptr
= &mips_elf_data_section
;
3004 *secp
= bfd_und_section_ptr
;
3006 *secp
= mips_elf_data_section_ptr
;
3009 case SHN_MIPS_SUNDEFINED
:
3010 *secp
= bfd_und_section_ptr
;
3014 if (SGI_COMPAT (abfd
)
3016 && info
->hash
->creator
== abfd
->xvec
3017 && strcmp (*namep
, "__rld_obj_head") == 0)
3019 struct elf_link_hash_entry
*h
;
3021 /* Mark __rld_obj_head as dynamic. */
3023 if (! (_bfd_generic_link_add_one_symbol
3024 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3025 (bfd_vma
) *valp
, (const char *) NULL
, false,
3026 get_elf_backend_data (abfd
)->collect
,
3027 (struct bfd_link_hash_entry
**) &h
)))
3029 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
3030 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3031 h
->type
= STT_OBJECT
;
3033 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3036 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3042 /* Structure used to pass information to mips_elf_output_extsym. */
3047 struct bfd_link_info
*info
;
3048 struct ecoff_debug_info
*debug
;
3049 const struct ecoff_debug_swap
*swap
;
3053 /* This routine is used to write out ECOFF debugging external symbol
3054 information. It is called via mips_elf_link_hash_traverse. The
3055 ECOFF external symbol information must match the ELF external
3056 symbol information. Unfortunately, at this point we don't know
3057 whether a symbol is required by reloc information, so the two
3058 tables may wind up being different. We must sort out the external
3059 symbol information before we can set the final size of the .mdebug
3060 section, and we must set the size of the .mdebug section before we
3061 can relocate any sections, and we can't know which symbols are
3062 required by relocation until we relocate the sections.
3063 Fortunately, it is relatively unlikely that any symbol will be
3064 stripped but required by a reloc. In particular, it can not happen
3065 when generating a final executable. */
3068 mips_elf_output_extsym (h
, data
)
3069 struct mips_elf_link_hash_entry
*h
;
3072 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
3074 asection
*sec
, *output_section
;
3076 if (h
->root
.indx
== -2)
3078 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3079 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
3080 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3081 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
3083 else if (einfo
->info
->strip
== strip_all
3084 || (einfo
->info
->strip
== strip_some
3085 && bfd_hash_lookup (einfo
->info
->keep_hash
,
3086 h
->root
.root
.root
.string
,
3087 false, false) == NULL
))
3095 if (h
->esym
.ifd
== -2)
3098 h
->esym
.cobol_main
= 0;
3099 h
->esym
.weakext
= 0;
3100 h
->esym
.reserved
= 0;
3101 h
->esym
.ifd
= ifdNil
;
3102 h
->esym
.asym
.value
= 0;
3103 h
->esym
.asym
.st
= stGlobal
;
3105 if (SGI_COMPAT (einfo
->abfd
)
3106 && (h
->root
.root
.type
== bfd_link_hash_undefined
3107 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
3111 /* Use undefined class. Also, set class and type for some
3113 name
= h
->root
.root
.root
.string
;
3114 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
3115 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
3117 h
->esym
.asym
.sc
= scData
;
3118 h
->esym
.asym
.st
= stLabel
;
3119 h
->esym
.asym
.value
= 0;
3121 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
3123 h
->esym
.asym
.sc
= scAbs
;
3124 h
->esym
.asym
.st
= stLabel
;
3125 h
->esym
.asym
.value
=
3126 mips_elf_hash_table (einfo
->info
)->procedure_count
;
3128 else if (strcmp (name
, "_gp_disp") == 0)
3130 h
->esym
.asym
.sc
= scAbs
;
3131 h
->esym
.asym
.st
= stLabel
;
3132 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
3135 h
->esym
.asym
.sc
= scUndefined
;
3137 else if (h
->root
.root
.type
!= bfd_link_hash_defined
3138 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
3139 h
->esym
.asym
.sc
= scAbs
;
3144 sec
= h
->root
.root
.u
.def
.section
;
3145 output_section
= sec
->output_section
;
3147 /* When making a shared library and symbol h is the one from
3148 the another shared library, OUTPUT_SECTION may be null. */
3149 if (output_section
== NULL
)
3150 h
->esym
.asym
.sc
= scUndefined
;
3153 name
= bfd_section_name (output_section
->owner
, output_section
);
3155 if (strcmp (name
, ".text") == 0)
3156 h
->esym
.asym
.sc
= scText
;
3157 else if (strcmp (name
, ".data") == 0)
3158 h
->esym
.asym
.sc
= scData
;
3159 else if (strcmp (name
, ".sdata") == 0)
3160 h
->esym
.asym
.sc
= scSData
;
3161 else if (strcmp (name
, ".rodata") == 0
3162 || strcmp (name
, ".rdata") == 0)
3163 h
->esym
.asym
.sc
= scRData
;
3164 else if (strcmp (name
, ".bss") == 0)
3165 h
->esym
.asym
.sc
= scBss
;
3166 else if (strcmp (name
, ".sbss") == 0)
3167 h
->esym
.asym
.sc
= scSBss
;
3168 else if (strcmp (name
, ".init") == 0)
3169 h
->esym
.asym
.sc
= scInit
;
3170 else if (strcmp (name
, ".fini") == 0)
3171 h
->esym
.asym
.sc
= scFini
;
3173 h
->esym
.asym
.sc
= scAbs
;
3177 h
->esym
.asym
.reserved
= 0;
3178 h
->esym
.asym
.index
= indexNil
;
3181 if (h
->root
.root
.type
== bfd_link_hash_common
)
3182 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
3183 else if (h
->root
.root
.type
== bfd_link_hash_defined
3184 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3186 if (h
->esym
.asym
.sc
== scCommon
)
3187 h
->esym
.asym
.sc
= scBss
;
3188 else if (h
->esym
.asym
.sc
== scSCommon
)
3189 h
->esym
.asym
.sc
= scSBss
;
3191 sec
= h
->root
.root
.u
.def
.section
;
3192 output_section
= sec
->output_section
;
3193 if (output_section
!= NULL
)
3194 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
3195 + sec
->output_offset
3196 + output_section
->vma
);
3198 h
->esym
.asym
.value
= 0;
3200 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3202 /* Set type and value for a symbol with a function stub. */
3203 h
->esym
.asym
.st
= stProc
;
3204 sec
= h
->root
.root
.u
.def
.section
;
3206 h
->esym
.asym
.value
= 0;
3209 output_section
= sec
->output_section
;
3210 if (output_section
!= NULL
)
3211 h
->esym
.asym
.value
= (h
->root
.plt_offset
3212 + sec
->output_offset
3213 + output_section
->vma
);
3215 h
->esym
.asym
.value
= 0;
3222 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
3223 h
->root
.root
.root
.string
,
3226 einfo
->failed
= true;
3233 /* Create a runtime procedure table from the .mdebug section. */
3236 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
3239 struct bfd_link_info
*info
;
3241 struct ecoff_debug_info
*debug
;
3243 const struct ecoff_debug_swap
*swap
;
3244 HDRR
*hdr
= &debug
->symbolic_header
;
3246 struct rpdr_ext
*erp
;
3248 struct pdr_ext
*epdr
;
3249 struct sym_ext
*esym
;
3252 unsigned long size
, count
;
3253 unsigned long sindex
;
3257 const char *no_name_func
= "static procedure (no name)";
3265 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3267 sindex
= strlen (no_name_func
) + 1;
3268 count
= hdr
->ipdMax
;
3271 size
= swap
->external_pdr_size
;
3273 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
3277 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
3280 size
= sizeof (RPDR
);
3281 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
3285 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
3289 count
= hdr
->isymMax
;
3290 size
= swap
->external_sym_size
;
3291 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
3295 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
3298 count
= hdr
->issMax
;
3299 ss
= (char *) bfd_malloc (count
);
3302 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
3305 count
= hdr
->ipdMax
;
3306 for (i
= 0; i
< count
; i
++, rp
++)
3308 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
3309 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
3310 rp
->adr
= sym
.value
;
3311 rp
->regmask
= pdr
.regmask
;
3312 rp
->regoffset
= pdr
.regoffset
;
3313 rp
->fregmask
= pdr
.fregmask
;
3314 rp
->fregoffset
= pdr
.fregoffset
;
3315 rp
->frameoffset
= pdr
.frameoffset
;
3316 rp
->framereg
= pdr
.framereg
;
3317 rp
->pcreg
= pdr
.pcreg
;
3319 sv
[i
] = ss
+ sym
.iss
;
3320 sindex
+= strlen (sv
[i
]) + 1;
3324 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
3325 size
= BFD_ALIGN (size
, 16);
3326 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
3329 mips_elf_hash_table (info
)->procedure_count
= 0;
3333 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
3335 erp
= (struct rpdr_ext
*) rtproc
;
3336 memset (erp
, 0, sizeof (struct rpdr_ext
));
3338 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
3339 strcpy (str
, no_name_func
);
3340 str
+= strlen (no_name_func
) + 1;
3341 for (i
= 0; i
< count
; i
++)
3343 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
3344 strcpy (str
, sv
[i
]);
3345 str
+= strlen (sv
[i
]) + 1;
3347 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
3349 /* Set the size and contents of .rtproc section. */
3350 s
->_raw_size
= size
;
3351 s
->contents
= rtproc
;
3353 /* Skip this section later on (I don't think this currently
3354 matters, but someday it might). */
3355 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
3384 /* A comparison routine used to sort .gptab entries. */
3387 gptab_compare (p1
, p2
)
3391 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
3392 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
3394 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
3397 /* We need to use a special link routine to handle the .reginfo and
3398 the .mdebug sections. We need to merge all instances of these
3399 sections together, not write them all out sequentially. */
3402 mips_elf_final_link (abfd
, info
)
3404 struct bfd_link_info
*info
;
3408 struct bfd_link_order
*p
;
3409 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
3410 asection
*rtproc_sec
;
3411 Elf32_RegInfo reginfo
;
3412 struct ecoff_debug_info debug
;
3413 const struct ecoff_debug_swap
*swap
3414 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3415 HDRR
*symhdr
= &debug
.symbolic_header
;
3416 PTR mdebug_handle
= NULL
;
3418 /* Drop the .options section, since it has special semantics which I
3419 haven't bothered to figure out. */
3420 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
3422 if (strcmp ((*secpp
)->name
, ".options") == 0)
3424 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
3425 if (p
->type
== bfd_indirect_link_order
)
3426 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
3427 (*secpp
)->link_order_head
= NULL
;
3428 *secpp
= (*secpp
)->next
;
3429 --abfd
->section_count
;
3434 /* Get a value for the GP register. */
3435 if (elf_gp (abfd
) == 0)
3437 struct bfd_link_hash_entry
*h
;
3439 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
3440 if (h
!= (struct bfd_link_hash_entry
*) NULL
3441 && h
->type
== bfd_link_hash_defined
)
3442 elf_gp (abfd
) = (h
->u
.def
.value
3443 + h
->u
.def
.section
->output_section
->vma
3444 + h
->u
.def
.section
->output_offset
);
3445 else if (info
->relocateable
)
3449 /* Make up a value. */
3451 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3454 && (strcmp (o
->name
, ".sbss") == 0
3455 || strcmp (o
->name
, ".sdata") == 0
3456 || strcmp (o
->name
, ".lit4") == 0
3457 || strcmp (o
->name
, ".lit8") == 0))
3460 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
3464 /* If the relocate_section function needs to do a reloc
3465 involving the GP value, it should make a reloc_dangerous
3466 callback to warn that GP is not defined. */
3470 /* Go through the sections and collect the .reginfo and .mdebug
3474 gptab_data_sec
= NULL
;
3475 gptab_bss_sec
= NULL
;
3476 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3478 if (strcmp (o
->name
, ".reginfo") == 0)
3480 memset (®info
, 0, sizeof reginfo
);
3482 /* We have found the .reginfo section in the output file.
3483 Look through all the link_orders comprising it and merge
3484 the information together. */
3485 for (p
= o
->link_order_head
;
3486 p
!= (struct bfd_link_order
*) NULL
;
3489 asection
*input_section
;
3491 Elf32_External_RegInfo ext
;
3494 if (p
->type
!= bfd_indirect_link_order
)
3496 if (p
->type
== bfd_fill_link_order
)
3501 input_section
= p
->u
.indirect
.section
;
3502 input_bfd
= input_section
->owner
;
3504 /* The linker emulation code has probably clobbered the
3505 size to be zero bytes. */
3506 if (input_section
->_raw_size
== 0)
3507 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3509 if (! bfd_get_section_contents (input_bfd
, input_section
,
3515 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
3517 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
3518 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
3519 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
3520 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
3521 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
3523 /* ri_gp_value is set by the function
3524 mips_elf32_section_processing when the section is
3525 finally written out. */
3527 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3528 elf_link_input_bfd ignores this section. */
3529 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3532 /* Force the section size to the value we want. */
3533 o
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3535 /* Skip this section later on (I don't think this currently
3536 matters, but someday it might). */
3537 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3542 if (strcmp (o
->name
, ".mdebug") == 0)
3544 struct extsym_info einfo
;
3546 /* We have found the .mdebug section in the output file.
3547 Look through all the link_orders comprising it and merge
3548 the information together. */
3549 symhdr
->magic
= swap
->sym_magic
;
3550 /* FIXME: What should the version stamp be? */
3552 symhdr
->ilineMax
= 0;
3556 symhdr
->isymMax
= 0;
3557 symhdr
->ioptMax
= 0;
3558 symhdr
->iauxMax
= 0;
3560 symhdr
->issExtMax
= 0;
3563 symhdr
->iextMax
= 0;
3565 /* We accumulate the debugging information itself in the
3566 debug_info structure. */
3568 debug
.external_dnr
= NULL
;
3569 debug
.external_pdr
= NULL
;
3570 debug
.external_sym
= NULL
;
3571 debug
.external_opt
= NULL
;
3572 debug
.external_aux
= NULL
;
3574 debug
.ssext
= debug
.ssext_end
= NULL
;
3575 debug
.external_fdr
= NULL
;
3576 debug
.external_rfd
= NULL
;
3577 debug
.external_ext
= debug
.external_ext_end
= NULL
;
3579 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
3580 if (mdebug_handle
== (PTR
) NULL
)
3583 if (SGI_COMPAT (abfd
))
3589 static const char * const name
[] =
3590 { ".text", ".init", ".fini", ".data",
3591 ".rodata", ".sdata", ".sbss", ".bss" };
3592 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
3593 scRData
, scSData
, scSBss
, scBss
};
3596 esym
.cobol_main
= 0;
3600 esym
.asym
.iss
= issNil
;
3601 esym
.asym
.st
= stLocal
;
3602 esym
.asym
.reserved
= 0;
3603 esym
.asym
.index
= indexNil
;
3604 for (i
= 0; i
< 8; i
++)
3606 esym
.asym
.sc
= sc
[i
];
3607 s
= bfd_get_section_by_name (abfd
, name
[i
]);
3610 esym
.asym
.value
= s
->vma
;
3611 last
= s
->vma
+ s
->_raw_size
;
3614 esym
.asym
.value
= last
;
3616 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
3622 for (p
= o
->link_order_head
;
3623 p
!= (struct bfd_link_order
*) NULL
;
3626 asection
*input_section
;
3628 const struct ecoff_debug_swap
*input_swap
;
3629 struct ecoff_debug_info input_debug
;
3633 if (p
->type
!= bfd_indirect_link_order
)
3635 if (p
->type
== bfd_fill_link_order
)
3640 input_section
= p
->u
.indirect
.section
;
3641 input_bfd
= input_section
->owner
;
3643 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
3644 || (get_elf_backend_data (input_bfd
)
3645 ->elf_backend_ecoff_debug_swap
) == NULL
)
3647 /* I don't know what a non MIPS ELF bfd would be
3648 doing with a .mdebug section, but I don't really
3649 want to deal with it. */
3653 input_swap
= (get_elf_backend_data (input_bfd
)
3654 ->elf_backend_ecoff_debug_swap
);
3656 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
3658 /* The ECOFF linking code expects that we have already
3659 read in the debugging information and set up an
3660 ecoff_debug_info structure, so we do that now. */
3661 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
3665 if (! (bfd_ecoff_debug_accumulate
3666 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
3667 &input_debug
, input_swap
, info
)))
3670 /* Loop through the external symbols. For each one with
3671 interesting information, try to find the symbol in
3672 the linker global hash table and save the information
3673 for the output external symbols. */
3674 eraw_src
= input_debug
.external_ext
;
3675 eraw_end
= (eraw_src
3676 + (input_debug
.symbolic_header
.iextMax
3677 * input_swap
->external_ext_size
));
3679 eraw_src
< eraw_end
;
3680 eraw_src
+= input_swap
->external_ext_size
)
3684 struct mips_elf_link_hash_entry
*h
;
3686 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
3687 if (ext
.asym
.sc
== scNil
3688 || ext
.asym
.sc
== scUndefined
3689 || ext
.asym
.sc
== scSUndefined
)
3692 name
= input_debug
.ssext
+ ext
.asym
.iss
;
3693 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
3694 name
, false, false, true);
3695 if (h
== NULL
|| h
->esym
.ifd
!= -2)
3701 < input_debug
.symbolic_header
.ifdMax
);
3702 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
3708 /* Free up the information we just read. */
3709 free (input_debug
.line
);
3710 free (input_debug
.external_dnr
);
3711 free (input_debug
.external_pdr
);
3712 free (input_debug
.external_sym
);
3713 free (input_debug
.external_opt
);
3714 free (input_debug
.external_aux
);
3715 free (input_debug
.ss
);
3716 free (input_debug
.ssext
);
3717 free (input_debug
.external_fdr
);
3718 free (input_debug
.external_rfd
);
3719 free (input_debug
.external_ext
);
3721 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3722 elf_link_input_bfd ignores this section. */
3723 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3726 if (SGI_COMPAT (abfd
) && info
->shared
)
3728 /* Create .rtproc section. */
3729 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
3730 if (rtproc_sec
== NULL
)
3732 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3735 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
3736 if (rtproc_sec
== NULL
3737 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
3738 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 12))
3742 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
3743 info
, rtproc_sec
, &debug
))
3747 /* Build the external symbol information. */
3750 einfo
.debug
= &debug
;
3752 einfo
.failed
= false;
3753 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
3754 mips_elf_output_extsym
,
3759 /* Set the size of the .mdebug section. */
3760 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
3762 /* Skip this section later on (I don't think this currently
3763 matters, but someday it might). */
3764 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3769 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
3771 const char *subname
;
3774 Elf32_External_gptab
*ext_tab
;
3777 /* The .gptab.sdata and .gptab.sbss sections hold
3778 information describing how the small data area would
3779 change depending upon the -G switch. These sections
3780 not used in executables files. */
3781 if (! info
->relocateable
)
3785 for (p
= o
->link_order_head
;
3786 p
!= (struct bfd_link_order
*) NULL
;
3789 asection
*input_section
;
3791 if (p
->type
!= bfd_indirect_link_order
)
3793 if (p
->type
== bfd_fill_link_order
)
3798 input_section
= p
->u
.indirect
.section
;
3800 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3801 elf_link_input_bfd ignores this section. */
3802 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3805 /* Skip this section later on (I don't think this
3806 currently matters, but someday it might). */
3807 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3809 /* Really remove the section. */
3810 for (secpp
= &abfd
->sections
;
3812 secpp
= &(*secpp
)->next
)
3814 *secpp
= (*secpp
)->next
;
3815 --abfd
->section_count
;
3820 /* There is one gptab for initialized data, and one for
3821 uninitialized data. */
3822 if (strcmp (o
->name
, ".gptab.sdata") == 0)
3824 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
3828 (*_bfd_error_handler
)
3829 ("%s: illegal section name `%s'",
3830 bfd_get_filename (abfd
), o
->name
);
3831 bfd_set_error (bfd_error_nonrepresentable_section
);
3835 /* The linker script always combines .gptab.data and
3836 .gptab.sdata into .gptab.sdata, and likewise for
3837 .gptab.bss and .gptab.sbss. It is possible that there is
3838 no .sdata or .sbss section in the output file, in which
3839 case we must change the name of the output section. */
3840 subname
= o
->name
+ sizeof ".gptab" - 1;
3841 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
3843 if (o
== gptab_data_sec
)
3844 o
->name
= ".gptab.data";
3846 o
->name
= ".gptab.bss";
3847 subname
= o
->name
+ sizeof ".gptab" - 1;
3848 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
3851 /* Set up the first entry. */
3853 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
3856 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
3857 tab
[0].gt_header
.gt_unused
= 0;
3859 /* Combine the input sections. */
3860 for (p
= o
->link_order_head
;
3861 p
!= (struct bfd_link_order
*) NULL
;
3864 asection
*input_section
;
3868 bfd_size_type gpentry
;
3870 if (p
->type
!= bfd_indirect_link_order
)
3872 if (p
->type
== bfd_fill_link_order
)
3877 input_section
= p
->u
.indirect
.section
;
3878 input_bfd
= input_section
->owner
;
3880 /* Combine the gptab entries for this input section one
3881 by one. We know that the input gptab entries are
3882 sorted by ascending -G value. */
3883 size
= bfd_section_size (input_bfd
, input_section
);
3885 for (gpentry
= sizeof (Elf32_External_gptab
);
3887 gpentry
+= sizeof (Elf32_External_gptab
))
3889 Elf32_External_gptab ext_gptab
;
3890 Elf32_gptab int_gptab
;
3896 if (! (bfd_get_section_contents
3897 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
3898 gpentry
, sizeof (Elf32_External_gptab
))))
3904 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
3906 val
= int_gptab
.gt_entry
.gt_g_value
;
3907 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
3910 for (look
= 1; look
< c
; look
++)
3912 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
3913 tab
[look
].gt_entry
.gt_bytes
+= add
;
3915 if (tab
[look
].gt_entry
.gt_g_value
== val
)
3921 Elf32_gptab
*new_tab
;
3924 /* We need a new table entry. */
3925 new_tab
= ((Elf32_gptab
*)
3926 bfd_realloc ((PTR
) tab
,
3927 (c
+ 1) * sizeof (Elf32_gptab
)));
3928 if (new_tab
== NULL
)
3934 tab
[c
].gt_entry
.gt_g_value
= val
;
3935 tab
[c
].gt_entry
.gt_bytes
= add
;
3937 /* Merge in the size for the next smallest -G
3938 value, since that will be implied by this new
3941 for (look
= 1; look
< c
; look
++)
3943 if (tab
[look
].gt_entry
.gt_g_value
< val
3945 || (tab
[look
].gt_entry
.gt_g_value
3946 > tab
[max
].gt_entry
.gt_g_value
)))
3950 tab
[c
].gt_entry
.gt_bytes
+=
3951 tab
[max
].gt_entry
.gt_bytes
;
3956 last
= int_gptab
.gt_entry
.gt_bytes
;
3959 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3960 elf_link_input_bfd ignores this section. */
3961 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3964 /* The table must be sorted by -G value. */
3966 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
3968 /* Swap out the table. */
3969 ext_tab
= ((Elf32_External_gptab
*)
3970 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
3971 if (ext_tab
== NULL
)
3977 for (i
= 0; i
< c
; i
++)
3978 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
3981 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
3982 o
->contents
= (bfd_byte
*) ext_tab
;
3984 /* Skip this section later on (I don't think this currently
3985 matters, but someday it might). */
3986 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3990 /* Invoke the regular ELF backend linker to do all the work. */
3991 if (! bfd_elf32_bfd_final_link (abfd
, info
))
3994 /* Now write out the computed sections. */
3996 if (reginfo_sec
!= (asection
*) NULL
)
3998 Elf32_External_RegInfo ext
;
4000 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
4001 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4002 (file_ptr
) 0, sizeof ext
))
4006 if (mdebug_sec
!= (asection
*) NULL
)
4008 BFD_ASSERT (abfd
->output_has_begun
);
4009 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4011 mdebug_sec
->filepos
))
4014 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4017 if (gptab_data_sec
!= (asection
*) NULL
)
4019 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4020 gptab_data_sec
->contents
,
4022 gptab_data_sec
->_raw_size
))
4026 if (gptab_bss_sec
!= (asection
*) NULL
)
4028 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4029 gptab_bss_sec
->contents
,
4031 gptab_bss_sec
->_raw_size
))
4035 if (SGI_COMPAT (abfd
))
4037 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4038 if (rtproc_sec
!= NULL
)
4040 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
4041 rtproc_sec
->contents
,
4043 rtproc_sec
->_raw_size
))
4051 /* Handle a MIPS ELF HI16 reloc. */
4054 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
4056 Elf_Internal_Rela
*relhi
;
4057 Elf_Internal_Rela
*rello
;
4064 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4066 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4069 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4071 if ((addlo
& 0x8000) != 0)
4073 if ((addend
& 0x8000) != 0)
4076 bfd_put_32 (input_bfd
,
4077 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
4078 contents
+ relhi
->r_offset
);
4081 /* Handle a MIPS ELF local GOT16 reloc. */
4084 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
4089 Elf_Internal_Rela
*relhi
;
4090 Elf_Internal_Rela
*rello
;
4100 bfd_byte
*got_contents
;
4101 struct mips_got_info
*g
;
4103 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4105 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4108 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4110 if ((addlo
& 0x8000) != 0)
4112 if ((addend
& 0x8000) != 0)
4115 /* Get a got entry representing requested hipage. */
4116 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4117 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4118 BFD_ASSERT (g
!= NULL
);
4120 local_gotno
= g
->local_gotno
;
4121 got_contents
= sgot
->contents
;
4122 hipage
= addend
& 0xffff0000;
4124 for (i
= MIPS_RESERVED_GOTNO
; i
< local_gotno
; i
++)
4126 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
4127 if (hipage
== (address
& 0xffff0000))
4129 if (address
== (bfd_vma
) 0)
4131 bfd_put_32 (input_bfd
, hipage
, got_contents
+ i
* 4);
4136 BFD_ASSERT (i
< local_gotno
);
4138 if (i
== local_gotno
)
4139 (*_bfd_error_handler
)
4140 ("ELF MIPS linker: more got entries are needed for hipage: %x",
4144 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
4145 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
4146 contents
+ relhi
->r_offset
);
4149 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
4152 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
4154 Elf_Internal_Rela
*rel
;
4160 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4161 bfd_put_32 (input_bfd
,
4162 (insn
& 0xffff0000) | (offset
& 0xffff),
4163 contents
+ rel
->r_offset
);
4166 /* Relocate a MIPS ELF section. */
4169 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4170 contents
, relocs
, local_syms
, local_sections
)
4172 struct bfd_link_info
*info
;
4174 asection
*input_section
;
4176 Elf_Internal_Rela
*relocs
;
4177 Elf_Internal_Sym
*local_syms
;
4178 asection
**local_sections
;
4180 Elf_Internal_Shdr
*symtab_hdr
;
4183 asection
*sgot
, *sreloc
, *scpt
;
4186 Elf_Internal_Rela
*rel
;
4187 Elf_Internal_Rela
*relend
;
4188 struct mips_got_info
*g
;
4190 dynobj
= elf_hash_table (info
)->dynobj
;
4191 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4195 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
4198 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
4201 if (elf_bad_symtab (input_bfd
))
4203 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
4208 locsymcount
= symtab_hdr
->sh_info
;
4209 extsymoff
= symtab_hdr
->sh_info
;
4212 gp
= _bfd_get_gp_value (output_bfd
);
4215 relend
= relocs
+ input_section
->reloc_count
;
4216 for (; rel
< relend
; rel
++)
4219 reloc_howto_type
*howto
;
4220 unsigned long r_symndx
;
4222 struct elf_link_hash_entry
*h
;
4224 Elf_Internal_Sym
*sym
;
4225 bfd_reloc_status_type r
;
4227 r_type
= ELF32_R_TYPE (rel
->r_info
);
4228 if (r_type
< 0 || r_type
>= (int) R_MIPS_max
)
4230 bfd_set_error (bfd_error_bad_value
);
4233 howto
= elf_mips_howto_table
+ r_type
;
4236 && (r_type
== R_MIPS_CALL16
4237 || r_type
== R_MIPS_GOT16
4238 || r_type
== R_MIPS_CALL_HI16
4239 || r_type
== R_MIPS_CALL_LO16
4240 || r_type
== R_MIPS_GOT_HI16
4241 || r_type
== R_MIPS_GOT_LO16
))
4243 /* We need the .got section. */
4246 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4247 BFD_ASSERT (sgot
!= NULL
);
4248 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4249 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4250 BFD_ASSERT (g
!= NULL
);
4254 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4256 /* Mix in the change in GP address for a GP relative reloc. */
4257 if (r_type
!= R_MIPS_GPREL16
4258 && r_type
!= R_MIPS_LITERAL
4259 && r_type
!= R_MIPS_GPREL32
)
4265 if (! ((*info
->callbacks
->reloc_dangerous
)
4267 "GP relative relocation when GP not defined",
4268 input_bfd
, input_section
,
4271 /* Only give the error once per link. */
4273 _bfd_set_gp_value (output_bfd
, gp
);
4276 if (r_symndx
< extsymoff
4277 || (elf_bad_symtab (input_bfd
)
4278 && local_sections
[r_symndx
] != NULL
))
4280 /* This is a relocation against a section. The current
4281 addend in the instruction is the difference between
4282 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
4283 must change this to be the difference between the
4284 final definition (which will end up in RELOCATION)
4285 and the GP value of OUTPUT_BFD (which is in GP). */
4286 addend
= elf_gp (input_bfd
) - gp
;
4288 else if (! info
->relocateable
)
4290 /* We are doing a final link. The current addend in the
4291 instruction is simply the desired offset into the
4292 symbol (normally zero). We want the instruction to
4293 hold the difference between the final definition of
4294 the symbol (which will end up in RELOCATION) and the
4295 GP value of OUTPUT_BFD (which is in GP). */
4300 /* We are generating relocateable output, and we aren't
4301 going to define this symbol, so we just leave the
4302 instruction alone. */
4310 if (info
->relocateable
)
4312 /* This is a relocateable link. We don't have to change
4313 anything, unless the reloc is against a section symbol,
4314 in which case we have to adjust according to where the
4315 section symbol winds up in the output section. */
4316 if (r_symndx
>= locsymcount
4317 || (elf_bad_symtab (input_bfd
)
4318 && local_sections
[r_symndx
] == NULL
))
4322 sym
= local_syms
+ r_symndx
;
4323 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4327 sec
= local_sections
[r_symndx
];
4329 /* It would be logical to add sym->st_value here,
4330 but Irix 5 sometimes generates a garbage symbol
4332 addend
+= sec
->output_offset
;
4334 /* If this is HI16 or GOT16 with an associated LO16,
4335 adjust the addend accordingly. Otherwise, just
4337 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
4338 r
= _bfd_relocate_contents (howto
, input_bfd
,
4340 contents
+ rel
->r_offset
);
4343 Elf_Internal_Rela
*lorel
;
4345 /* As a GNU extension, permit an arbitrary
4346 number of R_MIPS_HI16 relocs before the
4347 R_MIPS_LO16 reloc. This permits gcc to emit
4348 the HI and LO relocs itself. */
4349 if (r_type
== R_MIPS_GOT16
)
4353 for (lorel
= rel
+ 1;
4355 && (ELF32_R_TYPE (lorel
->r_info
)
4361 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
4363 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
4368 r
= _bfd_relocate_contents (howto
, input_bfd
,
4370 contents
+ rel
->r_offset
);
4380 /* This is a final link. */
4382 if (r_symndx
< extsymoff
4383 || (elf_bad_symtab (input_bfd
)
4384 && local_sections
[r_symndx
] != NULL
))
4387 sym
= local_syms
+ r_symndx
;
4388 sec
= local_sections
[r_symndx
];
4389 relocation
= (sec
->output_section
->vma
4390 + sec
->output_offset
);
4392 /* It would be logical to always add sym->st_value here,
4393 but Irix 5 sometimes generates a garbage symbol
4395 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4396 relocation
+= sym
->st_value
;
4403 indx
= r_symndx
- extsymoff
;
4404 h
= elf_sym_hashes (input_bfd
)[indx
];
4405 while (h
->root
.type
== bfd_link_hash_indirect
4406 || h
->root
.type
== bfd_link_hash_warning
)
4407 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4408 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
4412 if (! ((*info
->callbacks
->reloc_dangerous
)
4414 "_gp_disp used when GP not defined",
4415 input_bfd
, input_section
,
4418 /* Only give the error once per link. */
4420 _bfd_set_gp_value (output_bfd
, gp
);
4425 sec
= input_section
;
4426 if (sec
->output_section
!= NULL
)
4429 + sec
->output_section
->vma
4430 + sec
->output_offset
));
4432 relocation
= gp
- rel
->r_offset
;
4433 if (r_type
== R_MIPS_LO16
)
4437 else if (h
->root
.type
== bfd_link_hash_defined
4438 || h
->root
.type
== bfd_link_hash_defweak
)
4440 sec
= h
->root
.u
.def
.section
;
4441 if (sec
->output_section
== NULL
)
4444 relocation
= (h
->root
.u
.def
.value
4445 + sec
->output_section
->vma
4446 + sec
->output_offset
);
4448 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4450 else if (info
->shared
&& ! info
->symbolic
)
4452 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
4454 /* If this is a dynamic link, we should have created
4455 a _DYNAMIC_LINK symbol in
4456 mips_elf_create_dynamic_sections. Otherwise, we
4457 should define the symbol with a value of 0.
4458 FIXME: It should probably get into the symbol
4459 table somehow as well. */
4460 BFD_ASSERT (! info
->shared
);
4461 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
4462 ".dynamic") == NULL
);
4467 if (! ((*info
->callbacks
->undefined_symbol
)
4468 (info
, h
->root
.root
.string
, input_bfd
,
4469 input_section
, rel
->r_offset
)))
4475 if (r_type
== R_MIPS_HI16
)
4477 Elf_Internal_Rela
*lorel
;
4479 /* As a GNU extension, permit an arbitrary number of
4480 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
4481 This permits gcc to emit the HI and LO relocs itself. */
4482 for (lorel
= rel
+ 1;
4484 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
4488 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
4490 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
4491 contents
, relocation
+ addend
);
4495 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4496 contents
, rel
->r_offset
,
4497 relocation
, addend
);
4499 else if (r_type
== R_MIPS_GOT16
&& local
)
4501 /* GOT16 must also have an associated LO16 in the local
4502 case. In this case, the addend is extracted and the
4503 section in which the referenced object is determined.
4504 Then the final address of the object is computed and
4505 the GOT entry for the hipage (an aligned 64kb chunk)
4506 is added to .got section if needed. The offset field
4507 of the GOT16-relocated instruction is replaced by the
4508 index of this GOT entry for the hipage. */
4509 if ((rel
+ 1) < relend
4510 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
4512 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
,
4515 relocation
+ addend
);
4519 r
= bfd_reloc_outofrange
;
4521 else if (r_type
== R_MIPS_CALL16
4522 || r_type
== R_MIPS_GOT16
4523 || r_type
== R_MIPS_CALL_LO16
4524 || r_type
== R_MIPS_GOT_LO16
)
4528 /* This symbol must be registered as a global symbol
4529 having the corresponding got entry. */
4530 BFD_ASSERT (h
->got_offset
!= (bfd_vma
) -1);
4532 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
4533 BFD_ASSERT (g
->local_gotno
<= offset
4534 && offset
< sgot
->_raw_size
);
4535 bfd_put_32 (output_bfd
, relocation
+ addend
,
4536 sgot
->contents
+ offset
);
4537 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
4539 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
4543 else if (r_type
== R_MIPS_CALL_HI16
4544 || r_type
== R_MIPS_GOT_HI16
)
4548 /* This must be a global symbol with a got entry. The
4549 next reloc must be the corresponding LO16 reloc. */
4550 BFD_ASSERT (h
!= NULL
&& h
->got_offset
!= (bfd_vma
) -1);
4551 BFD_ASSERT ((rel
+ 1) < relend
);
4552 BFD_ASSERT (ELF32_R_TYPE ((rel
+ 1)->r_info
)
4553 == (r_type
== R_MIPS_CALL_HI16
4555 : R_MIPS_GOT_LO16
));
4557 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
4558 BFD_ASSERT (g
->local_gotno
<= offset
4559 && offset
< sgot
->_raw_size
);
4560 bfd_put_32 (output_bfd
, relocation
+ addend
,
4561 sgot
->contents
+ offset
);
4562 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
4564 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
4568 else if (r_type
== R_MIPS_REL32
4569 || r_type
== R_MIPS_32
)
4571 Elf_Internal_Rel outrel
;
4572 Elf32_crinfo cptrel
;
4576 || (elf_hash_table (info
)->dynamic_sections_created
4578 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
4580 && (input_section
->flags
& SEC_ALLOC
) != 0)
4582 /* When generating a shared object, these
4583 relocations are copied into the output file to be
4584 resolved at run time. */
4587 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
4588 BFD_ASSERT (sreloc
!= NULL
);
4591 outrel
.r_offset
= (rel
->r_offset
4592 + input_section
->output_section
->vma
4593 + input_section
->output_offset
);
4595 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4598 && (! info
->symbolic
4599 || (h
->elf_link_hash_flags
4600 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4602 BFD_ASSERT (h
->dynindx
!= -1);
4603 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
4604 sec
= input_section
;
4611 sec
= local_sections
[r_symndx
];
4614 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
4616 == bfd_link_hash_defweak
));
4617 sec
= h
->root
.u
.def
.section
;
4619 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
4621 else if (sec
== NULL
|| sec
->owner
== NULL
)
4623 bfd_set_error (bfd_error_bad_value
);
4630 osec
= sec
->output_section
;
4631 indx
= elf_section_data (osec
)->dynindx
;
4636 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
4637 addend
+= relocation
;
4640 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
4641 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
4642 (((Elf32_External_Rel
*)
4644 + sreloc
->reloc_count
));
4645 ++sreloc
->reloc_count
;
4647 if (SGI_COMPAT (output_bfd
))
4652 /* Make an entry of compact relocation info. */
4653 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
4654 cptrel
.vaddr
= (rel
->r_offset
4655 + input_section
->output_section
->vma
4656 + input_section
->output_offset
);
4657 if (r_type
== R_MIPS_REL32
)
4658 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
4660 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
4661 mips_elf_set_cr_dist2to (cptrel
, 0);
4662 cptrel
.konst
= addend
;
4664 cr
= (scpt
->contents
4665 + sizeof (Elf32_External_compact_rel
));
4666 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4667 ((Elf32_External_crinfo
*) cr
4668 + scpt
->reloc_count
));
4669 ++scpt
->reloc_count
;
4672 /* This reloc will be computed at runtime, so
4673 there's no need to do anything now. */
4677 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4678 contents
, rel
->r_offset
,
4679 relocation
, addend
);
4682 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4683 contents
, rel
->r_offset
,
4684 relocation
, addend
);
4686 if (SGI_COMPAT (abfd
)
4688 && (input_section
->flags
& SEC_ALLOC
) != 0)
4690 Elf32_crinfo cptrel
;
4693 /* Make an entry of compact relocation info. */
4694 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
4695 cptrel
.vaddr
= (rel
->r_offset
4696 + input_section
->output_section
->vma
4697 + input_section
->output_offset
);
4702 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
4703 /* XXX How should we set dist2to in this case. */
4704 mips_elf_set_cr_dist2to (cptrel
, 8);
4705 cptrel
.konst
= addend
+ relocation
;
4706 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
4707 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4708 ((Elf32_External_crinfo
*) cr
4709 + scpt
->reloc_count
));
4710 ++scpt
->reloc_count
;
4713 case R_MIPS_GPREL16
:
4714 case R_MIPS_LITERAL
:
4715 case R_MIPS_GPREL32
:
4716 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
4717 cptrel
.konst
= gp
- cptrel
.vaddr
;
4718 mips_elf_set_cr_dist2to (cptrel
, 4);
4719 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
4720 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4721 ((Elf32_External_crinfo
*) cr
4722 + scpt
->reloc_count
));
4723 ++scpt
->reloc_count
;
4732 if (r
!= bfd_reloc_ok
)
4737 case bfd_reloc_outofrange
:
4739 case bfd_reloc_overflow
:
4744 name
= h
->root
.root
.string
;
4747 name
= bfd_elf_string_from_elf_section (input_bfd
,
4748 symtab_hdr
->sh_link
,
4753 name
= bfd_section_name (input_bfd
, sec
);
4755 if (! ((*info
->callbacks
->reloc_overflow
)
4756 (info
, name
, howto
->name
, (bfd_vma
) 0,
4757 input_bfd
, input_section
, rel
->r_offset
)))
4768 /* Functions for the dynamic linker. */
4770 /* The name of the dynamic interpreter. This is put in the .interp
4773 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
4775 /* Create dynamic sections when linking against a dynamic object. */
4778 mips_elf_create_dynamic_sections (abfd
, info
)
4780 struct bfd_link_info
*info
;
4782 struct elf_link_hash_entry
*h
;
4784 register asection
*s
;
4785 const char * const *namep
;
4787 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4790 /* Mips ABI requests the .dynamic section to be read only. */
4791 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4794 if (! bfd_set_section_flags (abfd
, s
, flags
))
4798 /* We need to create .got section. */
4799 if (! mips_elf_create_got_section (abfd
, info
))
4802 /* Create .stub section. */
4803 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
4805 s
= bfd_make_section (abfd
, ".stub");
4807 || ! bfd_set_section_flags (abfd
, s
, flags
)
4808 || ! bfd_set_section_alignment (abfd
, s
, 2))
4812 if (SGI_COMPAT (abfd
)
4814 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
4816 s
= bfd_make_section (abfd
, ".rld_map");
4818 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
4819 || ! bfd_set_section_alignment (abfd
, s
, 2))
4823 if (SGI_COMPAT (abfd
))
4825 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
4828 if (! (_bfd_generic_link_add_one_symbol
4829 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
4830 (bfd_vma
) 0, (const char *) NULL
, false,
4831 get_elf_backend_data (abfd
)->collect
,
4832 (struct bfd_link_hash_entry
**) &h
)))
4834 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
4835 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4836 h
->type
= STT_SECTION
;
4838 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4842 /* We need to create a .compact_rel section. */
4843 if (! mips_elf_create_compact_rel_section (abfd
, info
))
4846 /* Change aligments of some sections. */
4847 s
= bfd_get_section_by_name (abfd
, ".hash");
4849 bfd_set_section_alignment (abfd
, s
, 4);
4850 s
= bfd_get_section_by_name (abfd
, ".dynsym");
4852 bfd_set_section_alignment (abfd
, s
, 4);
4853 s
= bfd_get_section_by_name (abfd
, ".dynstr");
4855 bfd_set_section_alignment (abfd
, s
, 4);
4856 s
= bfd_get_section_by_name (abfd
, ".reginfo");
4858 bfd_set_section_alignment (abfd
, s
, 4);
4859 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4861 bfd_set_section_alignment (abfd
, s
, 4);
4867 if (! (_bfd_generic_link_add_one_symbol
4868 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
4869 (bfd_vma
) 0, (const char *) NULL
, false,
4870 get_elf_backend_data (abfd
)->collect
,
4871 (struct bfd_link_hash_entry
**) &h
)))
4873 h
->elf_link_hash_flags
^=~ ELF_LINK_NON_ELF
;
4874 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4875 h
->type
= STT_SECTION
;
4877 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4880 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
4882 /* __rld_map is a four byte word located in the .data section
4883 and is filled in by the rtld to contain a pointer to
4884 the _r_debug structure. Its symbol value will be set in
4885 mips_elf_finish_dynamic_symbol. */
4886 s
= bfd_get_section_by_name (abfd
, ".rld_map");
4887 BFD_ASSERT (s
!= NULL
);
4890 if (! (_bfd_generic_link_add_one_symbol
4891 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
4892 (bfd_vma
) 0, (const char *) NULL
, false,
4893 get_elf_backend_data (abfd
)->collect
,
4894 (struct bfd_link_hash_entry
**) &h
)))
4896 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
4897 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4898 h
->type
= STT_OBJECT
;
4900 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4908 /* Create the .compact_rel section. */
4911 mips_elf_create_compact_rel_section (abfd
, info
)
4913 struct bfd_link_info
*info
;
4916 register asection
*s
;
4918 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
4920 flags
= SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_READONLY
;
4922 s
= bfd_make_section (abfd
, ".compact_rel");
4924 || ! bfd_set_section_flags (abfd
, s
, flags
)
4925 || ! bfd_set_section_alignment (abfd
, s
, 2))
4928 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
4934 /* Create the .got section to hold the global offset table. */
4937 mips_elf_create_got_section (abfd
, info
)
4939 struct bfd_link_info
*info
;
4942 register asection
*s
;
4943 struct elf_link_hash_entry
*h
;
4944 struct mips_got_info
*g
;
4946 /* This function may be called more than once. */
4947 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
4950 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
4952 s
= bfd_make_section (abfd
, ".got");
4954 || ! bfd_set_section_flags (abfd
, s
, flags
)
4955 || ! bfd_set_section_alignment (abfd
, s
, 4))
4958 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
4959 linker script because we don't want to define the symbol if we
4960 are not creating a global offset table. */
4962 if (! (_bfd_generic_link_add_one_symbol
4963 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
4964 (bfd_vma
) 0, (const char *) NULL
, false,
4965 get_elf_backend_data (abfd
)->collect
,
4966 (struct bfd_link_hash_entry
**) &h
)))
4968 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
4969 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4970 h
->type
= STT_OBJECT
;
4973 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4976 /* The first several global offset table entries are reserved. */
4977 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
4979 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
4980 sizeof (struct mips_got_info
));
4983 g
->global_gotsym
= 0;
4984 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
4985 if (elf_section_data (s
) == NULL
)
4988 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
4989 if (elf_section_data (s
) == NULL
)
4992 elf_section_data (s
)->tdata
= (PTR
) g
;
4997 /* Look through the relocs for a section during the first phase, and
4998 allocate space in the global offset table. */
5001 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
5003 struct bfd_link_info
*info
;
5005 const Elf_Internal_Rela
*relocs
;
5008 Elf_Internal_Shdr
*symtab_hdr
;
5009 struct elf_link_hash_entry
**sym_hashes
;
5010 struct mips_got_info
*g
;
5012 const Elf_Internal_Rela
*rel
;
5013 const Elf_Internal_Rela
*rel_end
;
5017 if (info
->relocateable
)
5020 dynobj
= elf_hash_table (info
)->dynobj
;
5021 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5022 sym_hashes
= elf_sym_hashes (abfd
);
5023 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
5032 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5037 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5038 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5039 BFD_ASSERT (g
!= NULL
);
5045 rel_end
= relocs
+ sec
->reloc_count
;
5046 for (rel
= relocs
; rel
< rel_end
; rel
++)
5048 unsigned long r_symndx
;
5049 struct elf_link_hash_entry
*h
;
5051 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5053 if (r_symndx
< extsymoff
)
5056 h
= sym_hashes
[r_symndx
- extsymoff
];
5058 /* Some relocs require a global offset table. */
5059 if (dynobj
== NULL
|| sgot
== NULL
)
5061 switch (ELF32_R_TYPE (rel
->r_info
))
5065 case R_MIPS_CALL_HI16
:
5066 case R_MIPS_CALL_LO16
:
5067 case R_MIPS_GOT_HI16
:
5068 case R_MIPS_GOT_LO16
:
5070 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
5071 if (! mips_elf_create_got_section (dynobj
, info
))
5073 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5074 BFD_ASSERT (sgot
!= NULL
);
5075 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5076 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5077 BFD_ASSERT (g
!= NULL
);
5083 && (info
->shared
|| h
!= NULL
)
5084 && (sec
->flags
& SEC_ALLOC
) != 0)
5085 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
5093 switch (ELF32_R_TYPE (rel
->r_info
))
5096 case R_MIPS_CALL_HI16
:
5097 case R_MIPS_CALL_LO16
:
5098 /* This symbol requires a global offset table entry. */
5100 BFD_ASSERT (h
!= NULL
);
5102 /* Make sure this symbol is output as a dynamic symbol. */
5103 if (h
->dynindx
== -1)
5105 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5109 if (h
->got_offset
!= (bfd_vma
) -1)
5111 /* We have already allocated space in the .got. */
5115 /* Note the index of the first global got symbol in .dynsym. */
5116 if (g
->global_gotsym
== 0
5117 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
5118 g
->global_gotsym
= h
->dynindx
;
5120 /* Make this symbol to have the corresponding got entry. */
5123 /* We need a stub, not a plt entry for the undefined
5124 function. But we record it as if it needs plt. See
5125 elf_adjust_dynamic_symbol in elflink.h. */
5126 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
5132 case R_MIPS_GOT_HI16
:
5133 case R_MIPS_GOT_LO16
:
5134 /* This symbol requires a global offset table entry. */
5138 /* Make sure this symbol is output as a dynamic symbol. */
5139 if (h
->dynindx
== -1)
5141 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5145 if (h
->got_offset
!= (bfd_vma
) -1)
5147 /* We have already allocated space in the .got. */
5150 /* Note the index of the first global got symbol in
5152 if (g
->global_gotsym
== 0
5153 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
5154 g
->global_gotsym
= h
->dynindx
;
5156 /* Make this symbol to be the global got symbol. */
5164 if ((info
->shared
|| h
!= NULL
)
5165 && (sec
->flags
& SEC_ALLOC
) != 0)
5169 const char *name
= ".rel.dyn";
5171 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5174 sreloc
= bfd_make_section (dynobj
, name
);
5176 || ! bfd_set_section_flags (dynobj
, sreloc
,
5182 || ! bfd_set_section_alignment (dynobj
, sreloc
,
5189 /* When creating a shared object, we must copy these
5190 reloc types into the output file as R_MIPS_REL32
5191 relocs. We make room for this reloc in the
5192 .rel.dyn reloc section */
5193 if (sreloc
->_raw_size
== 0)
5195 /* Add a null element. */
5196 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
5197 ++sreloc
->reloc_count
;
5199 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
5203 struct mips_elf_link_hash_entry
*hmips
;
5205 /* We only need to copy this reloc if the symbol is
5206 defined in a dynamic object. */
5207 hmips
= (struct mips_elf_link_hash_entry
*) h
;
5208 ++hmips
->mips_32_relocs
;
5212 if (SGI_COMPAT (abfd
))
5213 mips_elf_hash_table (info
)->compact_rel_size
+=
5214 sizeof (Elf32_External_crinfo
);
5219 case R_MIPS_GPREL16
:
5220 case R_MIPS_LITERAL
:
5221 case R_MIPS_GPREL32
:
5222 if (SGI_COMPAT (abfd
))
5223 mips_elf_hash_table (info
)->compact_rel_size
+=
5224 sizeof (Elf32_External_crinfo
);
5235 /* Adjust a symbol defined by a dynamic object and referenced by a
5236 regular object. The current definition is in some section of the
5237 dynamic object, but we're not including those sections. We have to
5238 change the definition to something the rest of the link can
5242 mips_elf_adjust_dynamic_symbol (info
, h
)
5243 struct bfd_link_info
*info
;
5244 struct elf_link_hash_entry
*h
;
5247 struct mips_elf_link_hash_entry
*hmips
;
5250 dynobj
= elf_hash_table (info
)->dynobj
;
5252 /* Make sure we know what is going on here. */
5253 BFD_ASSERT (dynobj
!= NULL
5254 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
5255 || h
->weakdef
!= NULL
5256 || ((h
->elf_link_hash_flags
5257 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5258 && (h
->elf_link_hash_flags
5259 & ELF_LINK_HASH_REF_REGULAR
) != 0
5260 && (h
->elf_link_hash_flags
5261 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
5263 /* If this symbol is defined in a dynamic object, we need to copy
5264 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
5266 hmips
= (struct mips_elf_link_hash_entry
*) h
;
5267 if (! info
->relocateable
5268 && hmips
->mips_32_relocs
!= 0
5269 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5271 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5272 BFD_ASSERT (s
!= NULL
);
5274 if (s
->_raw_size
== 0)
5276 /* Make room for a null element. */
5277 s
->_raw_size
+= sizeof (Elf32_External_Rel
);
5280 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
5283 /* For a function, create a stub, if needed. */
5284 if (h
->type
== STT_FUNC
5285 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
5287 if (! elf_hash_table (info
)->dynamic_sections_created
)
5290 /* If this symbol is not defined in a regular file, then set
5291 the symbol to the stub location. This is required to make
5292 function pointers compare as equal between the normal
5293 executable and the shared library. */
5294 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5296 /* We need .stub section. */
5297 s
= bfd_get_section_by_name (dynobj
, ".stub");
5298 BFD_ASSERT (s
!= NULL
);
5300 h
->root
.u
.def
.section
= s
;
5301 h
->root
.u
.def
.value
= s
->_raw_size
;
5303 /* XXX Write this stub address somewhere. */
5304 h
->plt_offset
= s
->_raw_size
;
5306 /* Make room for this stub code. */
5307 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
5309 /* The last half word of the stub will be filled with the index
5310 of this symbol in .dynsym section. */
5315 /* If this is a weak symbol, and there is a real definition, the
5316 processor independent code will have arranged for us to see the
5317 real definition first, and we can just use the same value. */
5318 if (h
->weakdef
!= NULL
)
5320 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
5321 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
5322 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
5323 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
5327 /* This is a reference to a symbol defined by a dynamic object which
5328 is not a function. */
5333 /* Set the sizes of the dynamic sections. */
5336 mips_elf_size_dynamic_sections (output_bfd
, info
)
5338 struct bfd_link_info
*info
;
5344 struct mips_got_info
*g
;
5346 dynobj
= elf_hash_table (info
)->dynobj
;
5347 BFD_ASSERT (dynobj
!= NULL
);
5349 if (elf_hash_table (info
)->dynamic_sections_created
)
5351 /* Set the contents of the .interp section to the interpreter. */
5354 s
= bfd_get_section_by_name (dynobj
, ".interp");
5355 BFD_ASSERT (s
!= NULL
);
5356 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5357 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
5361 /* Recompute the size of .got for local entires (reserved and
5362 hipages) if needed. To estimate it, get the upper bound of total
5363 size of loadable sections. */
5364 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5368 bfd_size_type loadable_size
= 0;
5369 bfd_size_type local_gotno
;
5372 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5373 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5374 BFD_ASSERT (g
!= NULL
);
5376 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
5377 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
5379 if ((s
->flags
& SEC_ALLOC
) == 0)
5381 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
5384 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
5386 /* Assume there are two loadable segments consisting of
5387 contiguous sections. Is 5 enough? */
5388 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
5389 g
->local_gotno
= local_gotno
;
5390 sgot
->_raw_size
+= local_gotno
* 4;
5393 /* The check_relocs and adjust_dynamic_symbol entry points have
5394 determined the sizes of the various dynamic sections. Allocate
5397 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
5402 /* It's OK to base decisions on the section name, because none
5403 of the dynobj section names depend upon the input files. */
5404 name
= bfd_get_section_name (dynobj
, s
);
5406 if ((s
->flags
& SEC_IN_MEMORY
) == 0)
5411 if (strncmp (name
, ".rel", 4) == 0)
5413 if (s
->_raw_size
== 0)
5419 /* If this relocation section applies to a read only
5420 section, then we probably need a DT_TEXTREL entry.
5421 If the relocation section is .rel.dyn, we always
5422 assert a DT_TEXTREL entry rather than testing whether
5423 there exists a relocation to a read only section or
5425 target
= bfd_get_section_by_name (output_bfd
, name
+ 4);
5426 if ((target
!= NULL
&& (target
->flags
& SEC_READONLY
) != 0)
5427 || strcmp (name
, ".rel.dyn") == 0)
5430 /* We use the reloc_count field as a counter if we need
5431 to copy relocs into the output file. */
5432 if (strcmp (name
, ".rel.dyn") != 0)
5436 else if (strncmp (name
, ".got", 4) == 0)
5440 BFD_ASSERT (elf_section_data (s
) != NULL
);
5441 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
5442 BFD_ASSERT (g
!= NULL
);
5444 /* Fix the size of .got section for the correspondence of
5445 global symbols and got entries. This adds some useless
5446 got entries. Is this required by ABI really? */
5447 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
5448 s
->_raw_size
+= i
* 4;
5450 else if (strncmp (name
, ".stub", 5) == 0)
5452 /* Irix rld assumes that the function stub isn't at the end
5453 of .text section. So put a dummy. XXX */
5454 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
5456 else if (! info
->shared
5457 && ! mips_elf_hash_table (info
)->use_rld_obj_head
5458 && strncmp (name
, ".rld_map", 8) == 0)
5460 /* We add a room for __rld_map. It will be filled in by the
5461 rtld to contain a pointer to the _r_debug structure. */
5464 else if (SGI_COMPAT (output_bfd
)
5465 && strncmp (name
, ".compact_rel", 12) == 0)
5466 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
5467 else if (strncmp (name
, ".init", 5) != 0)
5469 /* It's not one of our sections, so don't allocate space. */
5477 for (spp
= &s
->output_section
->owner
->sections
;
5478 *spp
!= s
->output_section
;
5479 spp
= &(*spp
)->next
)
5481 *spp
= s
->output_section
->next
;
5482 --s
->output_section
->owner
->section_count
;
5487 /* Allocate memory for the section contents. */
5488 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
5489 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
5491 bfd_set_error (bfd_error_no_memory
);
5494 memset (s
->contents
, 0, s
->_raw_size
);
5497 if (elf_hash_table (info
)->dynamic_sections_created
)
5499 /* Add some entries to the .dynamic section. We fill in the
5500 values later, in elf_mips_finish_dynamic_sections, but we
5501 must add the entries now so that we get the correct size for
5502 the .dynamic section. The DT_DEBUG entry is filled in by the
5503 dynamic linker and used by the debugger. */
5506 if (SGI_COMPAT (output_bfd
))
5508 /* SGI object has the equivalence of DT_DEBUG in the
5509 DT_MIPS_RLD_MAP entry. */
5510 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
5514 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
5520 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
5524 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
5527 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
5529 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
5532 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
5535 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
5539 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
5542 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
5545 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
5547 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
5550 s
= bfd_get_section_by_name (dynobj
, ".liblist");
5551 BFD_ASSERT (s
!= NULL
);
5553 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
5557 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
5560 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
5564 /* Time stamps in executable files are a bad idea. */
5565 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
5570 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
5575 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
5579 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
5582 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
5585 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
5588 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
5591 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
5594 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
5597 #if 0 /* (SGI_COMPAT) */
5598 if (! bfd_get_section_by_name (dynobj
, ".init"))
5599 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
5602 if (! bfd_get_section_by_name (dynobj
, ".fini"))
5603 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
5608 /* If we use dynamic linking, we generate a section symbol for each
5609 output section. These are local symbols, which means that they
5610 must come first in the dynamic symbol table.
5611 That means we must increment the dynamic symbol index of every
5612 other dynamic symbol. */
5614 const char * const *namep
;
5616 bfd_size_type strindex
;
5617 struct bfd_strtab_hash
*dynstr
;
5618 struct mips_got_info
*g
;
5621 if (elf_hash_table (info
)->dynamic_sections_created
)
5623 if (SGI_COMPAT (output_bfd
))
5625 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
5626 elf_link_hash_traverse (elf_hash_table (info
),
5627 mips_elf_adjust_dynindx
,
5629 elf_hash_table (info
)->dynsymcount
+= c
;
5631 dynstr
= elf_hash_table (info
)->dynstr
;
5632 BFD_ASSERT (dynstr
!= NULL
);
5634 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
5638 s
= bfd_get_section_by_name (output_bfd
, *namep
);
5640 elf_section_data (s
)->dynindx
= i
;
5642 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
5643 if (strindex
== (bfd_size_type
) -1)
5646 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
5651 c
= bfd_count_sections (output_bfd
);
5652 elf_link_hash_traverse (elf_hash_table (info
),
5653 mips_elf_adjust_dynindx
,
5655 elf_hash_table (info
)->dynsymcount
+= c
;
5657 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
5659 elf_section_data (s
)->dynindx
= i
;
5660 /* These symbols will have no names, so we don't need to
5661 fiddle with dynstr_index. */
5668 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5669 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5670 BFD_ASSERT (g
!= NULL
);
5672 /* If there are no global got symbols, fake the last symbol so
5674 if (g
->global_gotsym
)
5675 g
->global_gotsym
+= c
;
5677 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
5684 /* Increment the index of a dynamic symbol by a given amount. Called
5685 via elf_link_hash_traverse. */
5688 mips_elf_adjust_dynindx (h
, cparg
)
5689 struct elf_link_hash_entry
*h
;
5692 unsigned int *cp
= (unsigned int *) cparg
;
5694 if (h
->dynindx
!= -1)
5699 /* Finish up dynamic symbol handling. We set the contents of various
5700 dynamic sections here. */
5703 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
5705 struct bfd_link_info
*info
;
5706 struct elf_link_hash_entry
*h
;
5707 Elf_Internal_Sym
*sym
;
5712 struct mips_got_info
*g
;
5715 dynobj
= elf_hash_table (info
)->dynobj
;
5716 gval
= sym
->st_value
;
5718 if (h
->plt_offset
!= (bfd_vma
) -1)
5722 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
5724 /* This symbol has a stub. Set it up. */
5726 BFD_ASSERT (h
->dynindx
!= -1);
5728 s
= bfd_get_section_by_name (dynobj
, ".stub");
5729 BFD_ASSERT (s
!= NULL
);
5731 /* Fill the stub. */
5733 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
5735 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
5738 /* FIXME: Can h->dynindex be more than 64K? */
5739 if (h
->dynindx
& 0xffff0000)
5742 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
5744 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
5746 BFD_ASSERT (h
->plt_offset
<= s
->_raw_size
);
5747 memcpy (s
->contents
+ h
->plt_offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
5749 /* Mark the symbol as undefined. plt_offset != -1 occurs
5750 only for the referenced symbol. */
5751 sym
->st_shndx
= SHN_UNDEF
;
5753 /* The run-time linker uses the st_value field of the symbol
5754 to reset the global offset table entry for this external
5755 to its stub address when unlinking a shared object. */
5756 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt_offset
;
5757 sym
->st_value
= gval
;
5760 BFD_ASSERT (h
->dynindx
!= -1);
5762 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5763 BFD_ASSERT (sgot
!= NULL
);
5764 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5765 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5766 BFD_ASSERT (g
!= NULL
);
5768 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
5770 bfd_size_type offset
;
5772 /* This symbol has an entry in the global offset table. Set its
5773 value to the corresponding got entry, if needed. */
5774 if (h
->got_offset
== (bfd_vma
) -1)
5776 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5777 BFD_ASSERT (g
->local_gotno
* 4 <= offset
5778 && offset
< sgot
->_raw_size
);
5779 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
5783 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
5784 name
= h
->root
.root
.string
;
5785 if (strcmp (name
, "_DYNAMIC") == 0
5786 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
5787 sym
->st_shndx
= SHN_ABS
;
5788 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
5790 sym
->st_shndx
= SHN_ABS
;
5791 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5794 else if (SGI_COMPAT (output_bfd
))
5796 if (strcmp (name
, "_gp_disp") == 0)
5798 sym
->st_shndx
= SHN_ABS
;
5799 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5800 sym
->st_value
= elf_gp (output_bfd
);
5802 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
5803 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
5805 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5806 sym
->st_other
= STO_PROTECTED
;
5808 sym
->st_shndx
= SHN_MIPS_DATA
;
5810 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
5812 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5813 sym
->st_other
= STO_PROTECTED
;
5814 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
5815 sym
->st_shndx
= SHN_ABS
;
5817 else if (sym
->st_shndx
!= SHN_UNDEF
)
5819 if (h
->type
== STT_FUNC
)
5820 sym
->st_shndx
= SHN_MIPS_TEXT
;
5821 else if (h
->type
== STT_OBJECT
)
5822 sym
->st_shndx
= SHN_MIPS_DATA
;
5826 if (SGI_COMPAT (output_bfd
)
5829 if (! mips_elf_hash_table (info
)->use_rld_obj_head
5830 && strcmp (name
, "__rld_map") == 0)
5832 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
5833 BFD_ASSERT (s
!= NULL
);
5834 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
5835 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
5836 if (mips_elf_hash_table (info
)->rld_value
== 0)
5837 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
5839 else if (mips_elf_hash_table (info
)->use_rld_obj_head
5840 && strcmp (name
, "__rld_obj_head") == 0)
5842 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
5843 BFD_ASSERT (s
!= NULL
);
5844 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
5851 /* Finish up the dynamic sections. */
5854 mips_elf_finish_dynamic_sections (output_bfd
, info
)
5856 struct bfd_link_info
*info
;
5861 struct mips_got_info
*g
;
5863 dynobj
= elf_hash_table (info
)->dynobj
;
5865 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5867 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5872 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5873 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5874 BFD_ASSERT (g
!= NULL
);
5877 if (elf_hash_table (info
)->dynamic_sections_created
)
5879 Elf32_External_Dyn
*dyncon
, *dynconend
;
5881 BFD_ASSERT (sdyn
!= NULL
);
5882 BFD_ASSERT (g
!= NULL
);
5884 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5885 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
5886 for (; dyncon
< dynconend
; dyncon
++)
5888 Elf_Internal_Dyn dyn
;
5893 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5901 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5902 BFD_ASSERT (s
!= NULL
);
5903 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
5904 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5908 /* Rewrite DT_STRSZ. */
5910 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
5911 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5917 case DT_MIPS_CONFLICT
:
5920 case DT_MIPS_LIBLIST
:
5923 s
= bfd_get_section_by_name (output_bfd
, name
);
5924 BFD_ASSERT (s
!= NULL
);
5925 dyn
.d_un
.d_ptr
= s
->vma
;
5926 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5929 case DT_MIPS_RLD_VERSION
:
5930 dyn
.d_un
.d_val
= 1; /* XXX */
5931 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5935 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
5936 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5939 case DT_MIPS_CONFLICTNO
:
5941 elemsize
= sizeof (Elf32_Conflict
);
5944 case DT_MIPS_LIBLISTNO
:
5946 elemsize
= sizeof (Elf32_Lib
);
5948 s
= bfd_get_section_by_name (output_bfd
, name
);
5951 if (s
->_cooked_size
!= 0)
5952 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5954 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5959 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5962 case DT_MIPS_TIME_STAMP
:
5963 time ((time_t *) &dyn
.d_un
.d_val
);
5964 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5967 case DT_MIPS_ICHECKSUM
:
5971 case DT_MIPS_IVERSION
:
5975 case DT_MIPS_BASE_ADDRESS
:
5976 s
= output_bfd
->sections
;
5977 BFD_ASSERT (s
!= NULL
);
5978 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
5979 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5982 case DT_MIPS_LOCAL_GOTNO
:
5983 dyn
.d_un
.d_val
= g
->local_gotno
;
5984 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5987 case DT_MIPS_SYMTABNO
:
5989 elemsize
= sizeof (Elf32_External_Sym
);
5990 s
= bfd_get_section_by_name (output_bfd
, name
);
5991 BFD_ASSERT (s
!= NULL
);
5993 if (s
->_cooked_size
!= 0)
5994 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5996 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5997 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6000 case DT_MIPS_UNREFEXTNO
:
6002 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
6003 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6006 case DT_MIPS_GOTSYM
:
6007 dyn
.d_un
.d_val
= g
->global_gotsym
;
6008 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6011 case DT_MIPS_HIPAGENO
:
6012 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
6013 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6016 case DT_MIPS_RLD_MAP
:
6017 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
6018 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6025 /* The first entry of the global offset table will be filled at
6026 runtime. The second entry will be used by some runtime loaders.
6027 This isn't the case of Irix rld. */
6028 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
6030 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
6031 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
6035 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
6042 Elf_Internal_Sym sym
;
6045 const char * const * namep
= mips_elf_dynsym_sec_names
;
6046 Elf32_compact_rel cpt
;
6048 /* Set up the section symbols for the output sections. SGI sets
6049 the STT_NOTYPE attribute for these symbols. Should we do so? */
6051 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
6052 if (sdynsym
!= NULL
)
6054 if (SGI_COMPAT (output_bfd
))
6058 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
6062 while ((name
= *namep
++) != NULL
)
6064 s
= bfd_get_section_by_name (output_bfd
, name
);
6067 sym
.st_value
= s
->vma
;
6068 dindx
= elf_section_data (s
)->dynindx
;
6069 last
= s
->vma
+ s
->_raw_size
;
6073 sym
.st_value
= last
;
6077 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
6082 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
6084 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
6085 (((Elf32_External_Sym
*)
6090 /* Set the sh_info field of the output .dynsym section to
6091 the index of the first global symbol. */
6092 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
6093 SIZEOF_MIPS_DYNSYM_SECNAMES
;
6099 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
6102 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
6106 sym
.st_value
= s
->vma
;
6108 indx
= elf_section_data (s
)->this_idx
;
6109 BFD_ASSERT (indx
> 0);
6110 sym
.st_shndx
= indx
;
6112 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
6113 (((Elf32_External_Sym
*)
6115 + elf_section_data (s
)->dynindx
));
6118 /* Set the sh_info field of the output .dynsym section to
6119 the index of the first global symbol. */
6120 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
6121 bfd_count_sections (output_bfd
) + 1;
6125 if (SGI_COMPAT (output_bfd
))
6127 /* Write .compact_rel section out. */
6128 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
6132 cpt
.num
= s
->reloc_count
;
6134 cpt
.offset
= (s
->output_section
->filepos
6135 + sizeof (Elf32_External_compact_rel
));
6138 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
6139 ((Elf32_External_compact_rel
*)
6142 /* Clean up a dummy stub function entry in .text. */
6143 s
= bfd_get_section_by_name (dynobj
, ".stub");
6146 file_ptr dummy_offset
;
6148 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
6149 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
6150 memset (s
->contents
+ dummy_offset
, 0,
6151 MIPS_FUNCTION_STUB_SIZE
);
6156 /* Clean up a first relocation in .rel.dyn. */
6157 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6158 if (s
!= NULL
&& s
->_raw_size
> 0)
6159 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
6165 /* This is almost identical to bfd_generic_get_... except that some
6166 MIPS relocations need to be handled specially. Sigh. */
6169 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
6170 relocateable
, symbols
)
6172 struct bfd_link_info
*link_info
;
6173 struct bfd_link_order
*link_order
;
6175 boolean relocateable
;
6178 /* Get enough memory to hold the stuff */
6179 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
6180 asection
*input_section
= link_order
->u
.indirect
.section
;
6182 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
6183 arelent
**reloc_vector
= NULL
;
6189 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
6190 if (reloc_vector
== NULL
&& reloc_size
!= 0)
6193 /* read in the section */
6194 if (!bfd_get_section_contents (input_bfd
,
6198 input_section
->_raw_size
))
6201 /* We're not relaxing the section, so just copy the size info */
6202 input_section
->_cooked_size
= input_section
->_raw_size
;
6203 input_section
->reloc_done
= true;
6205 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
6209 if (reloc_count
< 0)
6212 if (reloc_count
> 0)
6217 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
6220 struct bfd_hash_entry
*h
;
6221 struct bfd_link_hash_entry
*lh
;
6222 /* Skip all this stuff if we aren't mixing formats. */
6223 if (abfd
&& input_bfd
6224 && abfd
->xvec
== input_bfd
->xvec
)
6228 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
6229 lh
= (struct bfd_link_hash_entry
*) h
;
6236 case bfd_link_hash_undefined
:
6237 case bfd_link_hash_undefweak
:
6238 case bfd_link_hash_common
:
6241 case bfd_link_hash_defined
:
6242 case bfd_link_hash_defweak
:
6244 gp
= lh
->u
.def
.value
;
6246 case bfd_link_hash_indirect
:
6247 case bfd_link_hash_warning
:
6249 /* @@FIXME ignoring warning for now */
6251 case bfd_link_hash_new
:
6260 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
6263 char *error_message
= (char *) NULL
;
6264 bfd_reloc_status_type r
;
6266 /* Specific to MIPS: Deal with relocation types that require
6267 knowing the gp of the output bfd. */
6268 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
6269 if (bfd_is_abs_section (sym
->section
) && abfd
)
6271 /* The special_function wouldn't get called anyways. */
6275 /* The gp isn't there; let the special function code
6276 fall over on its own. */
6278 else if ((*parent
)->howto
->special_function
6279 == _bfd_mips_elf_gprel16_reloc
)
6281 /* bypass special_function call */
6282 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
6283 relocateable
, (PTR
) data
, gp
);
6284 goto skip_bfd_perform_relocation
;
6286 /* end mips specific stuff */
6288 r
= bfd_perform_relocation (input_bfd
,
6292 relocateable
? abfd
: (bfd
*) NULL
,
6294 skip_bfd_perform_relocation
:
6298 asection
*os
= input_section
->output_section
;
6300 /* A partial link, so keep the relocs */
6301 os
->orelocation
[os
->reloc_count
] = *parent
;
6305 if (r
!= bfd_reloc_ok
)
6309 case bfd_reloc_undefined
:
6310 if (!((*link_info
->callbacks
->undefined_symbol
)
6311 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
6312 input_bfd
, input_section
, (*parent
)->address
)))
6315 case bfd_reloc_dangerous
:
6316 BFD_ASSERT (error_message
!= (char *) NULL
);
6317 if (!((*link_info
->callbacks
->reloc_dangerous
)
6318 (link_info
, error_message
, input_bfd
, input_section
,
6319 (*parent
)->address
)))
6322 case bfd_reloc_overflow
:
6323 if (!((*link_info
->callbacks
->reloc_overflow
)
6324 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
6325 (*parent
)->howto
->name
, (*parent
)->addend
,
6326 input_bfd
, input_section
, (*parent
)->address
)))
6329 case bfd_reloc_outofrange
:
6338 if (reloc_vector
!= NULL
)
6339 free (reloc_vector
);
6343 if (reloc_vector
!= NULL
)
6344 free (reloc_vector
);
6347 #define bfd_elf32_bfd_get_relocated_section_contents \
6348 elf32_mips_get_relocated_section_contents
6350 /* ECOFF swapping routines. These are used when dealing with the
6351 .mdebug section, which is in the ECOFF debugging format. */
6352 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
6354 /* Symbol table magic number. */
6356 /* Alignment of debugging information. E.g., 4. */
6358 /* Sizes of external symbolic information. */
6359 sizeof (struct hdr_ext
),
6360 sizeof (struct dnr_ext
),
6361 sizeof (struct pdr_ext
),
6362 sizeof (struct sym_ext
),
6363 sizeof (struct opt_ext
),
6364 sizeof (struct fdr_ext
),
6365 sizeof (struct rfd_ext
),
6366 sizeof (struct ext_ext
),
6367 /* Functions to swap in external symbolic data. */
6376 _bfd_ecoff_swap_tir_in
,
6377 _bfd_ecoff_swap_rndx_in
,
6378 /* Functions to swap out external symbolic data. */
6387 _bfd_ecoff_swap_tir_out
,
6388 _bfd_ecoff_swap_rndx_out
,
6389 /* Function to read in symbolic data. */
6390 _bfd_mips_elf_read_ecoff_info
6393 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
6394 #define TARGET_LITTLE_NAME "elf32-littlemips"
6395 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
6396 #define TARGET_BIG_NAME "elf32-bigmips"
6397 #define ELF_ARCH bfd_arch_mips
6398 #define ELF_MACHINE_CODE EM_MIPS
6400 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
6401 a value of 0x1000, and we are compatible. */
6402 #define ELF_MAXPAGESIZE 0x1000
6404 #define elf_backend_collect true
6405 #define elf_backend_type_change_ok true
6406 #define elf_info_to_howto 0
6407 #define elf_info_to_howto_rel mips_info_to_howto_rel
6408 #define elf_backend_sym_is_global mips_elf_sym_is_global
6409 #define elf_backend_object_p mips_elf32_object_p
6410 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
6411 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
6412 #define elf_backend_section_from_bfd_section \
6413 _bfd_mips_elf_section_from_bfd_section
6414 #define elf_backend_section_processing mips_elf32_section_processing
6415 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
6416 #define elf_backend_additional_program_headers \
6417 mips_elf_additional_program_headers
6418 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
6419 #define elf_backend_final_write_processing \
6420 _bfd_mips_elf_final_write_processing
6421 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
6423 #define bfd_elf32_bfd_is_local_label mips_elf_is_local_label
6424 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
6425 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
6426 #define bfd_elf32_bfd_link_hash_table_create \
6427 mips_elf_link_hash_table_create
6428 #define bfd_elf32_bfd_final_link mips_elf_final_link
6429 #define bfd_elf32_bfd_copy_private_bfd_data \
6430 _bfd_mips_elf_copy_private_bfd_data
6431 #define bfd_elf32_bfd_merge_private_bfd_data \
6432 _bfd_mips_elf_merge_private_bfd_data
6433 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
6434 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
6435 #define elf_backend_create_dynamic_sections \
6436 mips_elf_create_dynamic_sections
6437 #define elf_backend_check_relocs mips_elf_check_relocs
6438 #define elf_backend_adjust_dynamic_symbol \
6439 mips_elf_adjust_dynamic_symbol
6440 #define elf_backend_size_dynamic_sections \
6441 mips_elf_size_dynamic_sections
6442 #define elf_backend_relocate_section mips_elf_relocate_section
6443 #define elf_backend_finish_dynamic_symbol \
6444 mips_elf_finish_dynamic_symbol
6445 #define elf_backend_finish_dynamic_sections \
6446 mips_elf_finish_dynamic_sections
6448 #include "elf32-target.h"