1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 94, 95, 96, 97, 98, 1999 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 /* This structure is used to hold .got information when linking. It
45 is stored in the tdata field of the bfd_elf_section_data structure. */
49 /* The global symbol in the GOT with the lowest index in the dynamic
51 struct elf_link_hash_entry
*global_gotsym
;
52 /* The number of local .got entries. */
53 unsigned int local_gotno
;
54 /* The number of local .got entries we have used. */
55 unsigned int assigned_gotno
;
58 /* The MIPS ELF linker needs additional information for each symbol in
59 the global hash table. */
61 struct mips_elf_link_hash_entry
63 struct elf_link_hash_entry root
;
65 /* External symbol information. */
68 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
69 unsigned int mips_32_relocs
;
71 /* The index of the first dynamic relocation (in the .rel.dyn
72 section) against this symbol. */
73 unsigned int min_dyn_reloc_index
;
75 /* If there is a stub that 32 bit functions should use to call this
76 16 bit function, this points to the section containing the stub. */
79 /* Whether we need the fn_stub; this is set if this symbol appears
80 in any relocs other than a 16 bit call. */
83 /* If there is a stub that 16 bit functions should use to call this
84 32 bit function, this points to the section containing the stub. */
87 /* This is like the call_stub field, but it is used if the function
88 being called returns a floating point value. */
89 asection
*call_fp_stub
;
92 static bfd_reloc_status_type mips32_64bit_reloc
93 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
94 static reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
95 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
96 static void mips_info_to_howto_rel
97 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
98 static void mips_info_to_howto_rela
99 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rela
*));
100 static void bfd_mips_elf32_swap_gptab_in
101 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
102 static void bfd_mips_elf32_swap_gptab_out
103 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
104 static void bfd_mips_elf_swap_msym_in
105 PARAMS ((bfd
*, const Elf32_External_Msym
*, Elf32_Internal_Msym
*));
106 static void bfd_mips_elf_swap_msym_out
107 PARAMS ((bfd
*, const Elf32_Internal_Msym
*, Elf32_External_Msym
*));
108 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
109 static boolean mips_elf32_object_p
PARAMS ((bfd
*));
110 static boolean mips_elf_create_procedure_table
111 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
112 struct ecoff_debug_info
*));
113 static int mips_elf_additional_program_headers
PARAMS ((bfd
*));
114 static boolean mips_elf_modify_segment_map
PARAMS ((bfd
*));
115 static INLINE
int elf_mips_isa
PARAMS ((flagword
));
116 static INLINE
int elf_mips_mach
PARAMS ((flagword
));
117 static INLINE
char* elf_mips_abi_name
PARAMS ((flagword
));
118 static boolean mips_elf32_section_from_shdr
119 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, char *));
120 static boolean mips_elf32_section_processing
121 PARAMS ((bfd
*, Elf32_Internal_Shdr
*));
122 static boolean mips_elf_is_local_label_name
123 PARAMS ((bfd
*, const char *));
124 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
125 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
126 static struct bfd_link_hash_table
*mips_elf_link_hash_table_create
128 static int gptab_compare
PARAMS ((const void *, const void *));
129 static boolean mips_elf_final_link
130 PARAMS ((bfd
*, struct bfd_link_info
*));
131 static void mips_elf_relocate_hi16
132 PARAMS ((bfd
*, Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_byte
*,
134 static boolean mips_elf_relocate_got_local
135 PARAMS ((bfd
*, bfd
*, asection
*, Elf_Internal_Rela
*,
136 Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
137 static void mips_elf_relocate_global_got
138 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
139 static bfd_reloc_status_type mips16_jump_reloc
140 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
141 static bfd_reloc_status_type mips16_gprel_reloc
142 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
143 static boolean mips_elf_relocate_section
144 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
145 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
146 static boolean mips_elf_link_output_symbol_hook
147 PARAMS ((bfd
*, struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
149 static boolean mips_elf_create_dynamic_sections
150 PARAMS ((bfd
*, struct bfd_link_info
*));
151 static boolean mips_elf_create_compact_rel_section
152 PARAMS ((bfd
*, struct bfd_link_info
*));
153 static boolean mips_elf_create_got_section
154 PARAMS ((bfd
*, struct bfd_link_info
*));
155 static boolean mips_elf_check_relocs
156 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
157 const Elf_Internal_Rela
*));
158 static boolean mips_elf_adjust_dynamic_symbol
159 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
160 static boolean mips_elf_always_size_sections
161 PARAMS ((bfd
*, struct bfd_link_info
*));
162 static boolean mips_elf_size_dynamic_sections
163 PARAMS ((bfd
*, struct bfd_link_info
*));
164 static boolean mips_elf_finish_dynamic_symbol
165 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
166 Elf_Internal_Sym
*));
167 static boolean mips_elf_finish_dynamic_sections
168 PARAMS ((bfd
*, struct bfd_link_info
*));
169 static boolean mips_elf_add_symbol_hook
170 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
171 const char **, flagword
*, asection
**, bfd_vma
*));
172 static bfd_reloc_status_type mips_elf_final_gp
173 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
174 static bfd_byte
*elf32_mips_get_relocated_section_contents
175 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
176 bfd_byte
*, boolean
, asymbol
**));
177 static asection
*mips_elf_create_msym_section
179 static void mips_elf_irix6_finish_dynamic_symbol
180 PARAMS ((bfd
*, const char *, Elf_Internal_Sym
*));
181 static bfd_vma mips_elf_sign_extend
PARAMS ((bfd_vma
, int));
182 static boolean mips_elf_overflow_p
PARAMS ((bfd_vma
, int));
183 static bfd_vma mips_elf_high
PARAMS ((bfd_vma
));
184 static bfd_vma mips_elf_higher
PARAMS ((bfd_vma
));
185 static bfd_vma mips_elf_highest
PARAMS ((bfd_vma
));
186 static bfd_vma mips_elf_global_got_index
187 PARAMS ((bfd
*, struct elf_link_hash_entry
*));
188 static bfd_vma mips_elf_local_got_index
189 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
));
190 static bfd_vma mips_elf_got_offset_from_index
191 PARAMS ((bfd
*, bfd
*, bfd_vma
));
192 static boolean mips_elf_record_global_got_symbol
193 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*,
194 struct mips_got_info
*));
195 static bfd_vma mips_elf_got_page
196 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
, bfd_vma
*));
197 static boolean mips_elf_next_lo16_addend
198 PARAMS ((Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_vma
*));
199 static bfd_reloc_status_type mips_elf_calculate_relocation
200 PARAMS ((bfd
*, bfd
*, asection
*, struct bfd_link_info
*,
201 Elf_Internal_Rela
*, bfd_vma
, reloc_howto_type
*,
202 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**,
203 bfd_vma
*, const char **));
204 static bfd_vma mips_elf_obtain_contents
205 PARAMS ((reloc_howto_type
*, Elf_Internal_Rela
*, bfd
*, bfd_byte
*));
206 static void mips_elf_perform_relocation
207 PARAMS ((reloc_howto_type
*, Elf_Internal_Rela
*, bfd_vma
,
209 static boolean mips_elf_assign_gp
PARAMS ((bfd
*, bfd_vma
*));
210 static boolean mips_elf_sort_hash_table_f
211 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
212 static boolean mips_elf_sort_hash_table
213 PARAMS ((struct bfd_link_info
*));
214 static asection
* mips_elf_got_section
PARAMS ((bfd
*));
215 static struct mips_got_info
*mips_elf_got_info
216 PARAMS ((bfd
*, asection
**));
217 static bfd_vma mips_elf_create_local_got_entry
218 PARAMS ((bfd
*, struct mips_got_info
*, asection
*, bfd_vma
));
219 static bfd_vma mips_elf_got16_entry
220 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
));
221 static unsigned int mips_elf_create_dynamic_relocation
222 PARAMS ((bfd
*, struct bfd_link_info
*, Elf32_Internal_Rela
*,
223 long, bfd_vma
, asection
*));
225 /* The level of IRIX compatibility we're striving for. */
233 /* Nonzero if ABFD is using the N32 ABI. */
235 #define ABI_N32_P(abfd) \
236 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
238 /* Nonzero if ABFD is using the 64-bit ABI. FIXME: This is never
240 #define ABI_64_P(abfd) \
241 ((elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS64) != 0)
243 /* What version of Irix we are trying to be compatible with. FIXME:
244 At the moment, we never generate "normal" MIPS ELF ABI executables;
245 we always use some version of Irix. */
247 #define IRIX_COMPAT(abfd) \
248 ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5)
250 /* Whether we are trying to be compatible with IRIX at all. */
252 #define SGI_COMPAT(abfd) \
253 (IRIX_COMPAT (abfd) != ict_none)
255 /* The name of the msym section. */
256 #define MIPS_ELF_MSYM_SECTION_NAME(abfd) ".msym"
258 /* The name of the srdata section. */
259 #define MIPS_ELF_SRDATA_SECTION_NAME(abfd) ".srdata"
261 /* The name of the options section. */
262 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
263 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.options" : ".options")
265 /* The name of the stub section. */
266 #define MIPS_ELF_STUB_SECTION_NAME(abfd) \
267 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.stubs" : ".stub")
269 /* The number of local .got entries we reserve. */
270 #define MIPS_RESERVED_GOTNO (2)
272 /* Instructions which appear in a stub. For some reason the stub is
273 slightly different on an SGI system. */
274 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
275 #define STUB_LW(abfd) \
277 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
278 : 0x8f998000) /* lw t9,0x8000(gp) */
279 #define STUB_MOVE 0x03e07825 /* move t7,ra */
280 #define STUB_JALR 0x0320f809 /* jal t9 */
281 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
282 #define MIPS_FUNCTION_STUB_SIZE (16)
285 /* We no longer try to identify particular sections for the .dynsym
286 section. When we do, we wind up crashing if there are other random
287 sections with relocations. */
289 /* Names of sections which appear in the .dynsym section in an Irix 5
292 static const char * const mips_elf_dynsym_sec_names
[] =
305 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
306 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
308 /* The number of entries in mips_elf_dynsym_sec_names which go in the
311 #define MIPS_TEXT_DYNSYM_SECNO (3)
315 /* The names of the runtime procedure table symbols used on Irix 5. */
317 static const char * const mips_elf_dynsym_rtproc_names
[] =
320 "_procedure_string_table",
321 "_procedure_table_size",
325 /* These structures are used to generate the .compact_rel section on
330 unsigned long id1
; /* Always one? */
331 unsigned long num
; /* Number of compact relocation entries. */
332 unsigned long id2
; /* Always two? */
333 unsigned long offset
; /* The file offset of the first relocation. */
334 unsigned long reserved0
; /* Zero? */
335 unsigned long reserved1
; /* Zero? */
344 bfd_byte reserved0
[4];
345 bfd_byte reserved1
[4];
346 } Elf32_External_compact_rel
;
350 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
351 unsigned int rtype
: 4; /* Relocation types. See below. */
352 unsigned int dist2to
: 8;
353 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
354 unsigned long konst
; /* KONST field. See below. */
355 unsigned long vaddr
; /* VADDR to be relocated. */
360 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
361 unsigned int rtype
: 4; /* Relocation types. See below. */
362 unsigned int dist2to
: 8;
363 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
364 unsigned long konst
; /* KONST field. See below. */
372 } Elf32_External_crinfo
;
378 } Elf32_External_crinfo2
;
380 /* These are the constants used to swap the bitfields in a crinfo. */
382 #define CRINFO_CTYPE (0x1)
383 #define CRINFO_CTYPE_SH (31)
384 #define CRINFO_RTYPE (0xf)
385 #define CRINFO_RTYPE_SH (27)
386 #define CRINFO_DIST2TO (0xff)
387 #define CRINFO_DIST2TO_SH (19)
388 #define CRINFO_RELVADDR (0x7ffff)
389 #define CRINFO_RELVADDR_SH (0)
391 /* A compact relocation info has long (3 words) or short (2 words)
392 formats. A short format doesn't have VADDR field and relvaddr
393 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
394 #define CRF_MIPS_LONG 1
395 #define CRF_MIPS_SHORT 0
397 /* There are 4 types of compact relocation at least. The value KONST
398 has different meaning for each type:
401 CT_MIPS_REL32 Address in data
402 CT_MIPS_WORD Address in word (XXX)
403 CT_MIPS_GPHI_LO GP - vaddr
404 CT_MIPS_JMPAD Address to jump
407 #define CRT_MIPS_REL32 0xa
408 #define CRT_MIPS_WORD 0xb
409 #define CRT_MIPS_GPHI_LO 0xc
410 #define CRT_MIPS_JMPAD 0xd
412 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
413 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
414 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
415 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
417 static void bfd_elf32_swap_compact_rel_out
418 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
419 static void bfd_elf32_swap_crinfo_out
420 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
422 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
424 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
425 from smaller values. Start with zero, widen, *then* decrement. */
426 #define MINUS_ONE (((bfd_vma)0) - 1)
428 static reloc_howto_type elf_mips_howto_table
[] =
431 HOWTO (R_MIPS_NONE
, /* type */
433 0, /* size (0 = byte, 1 = short, 2 = long) */
435 false, /* pc_relative */
437 complain_overflow_dont
, /* complain_on_overflow */
438 bfd_elf_generic_reloc
, /* special_function */
439 "R_MIPS_NONE", /* name */
440 false, /* partial_inplace */
443 false), /* pcrel_offset */
445 /* 16 bit relocation. */
446 HOWTO (R_MIPS_16
, /* type */
448 1, /* size (0 = byte, 1 = short, 2 = long) */
450 false, /* pc_relative */
452 complain_overflow_bitfield
, /* complain_on_overflow */
453 bfd_elf_generic_reloc
, /* special_function */
454 "R_MIPS_16", /* name */
455 true, /* partial_inplace */
456 0xffff, /* src_mask */
457 0xffff, /* dst_mask */
458 false), /* pcrel_offset */
460 /* 32 bit relocation. */
461 HOWTO (R_MIPS_32
, /* type */
463 2, /* size (0 = byte, 1 = short, 2 = long) */
465 false, /* pc_relative */
467 complain_overflow_bitfield
, /* complain_on_overflow */
468 bfd_elf_generic_reloc
, /* special_function */
469 "R_MIPS_32", /* name */
470 true, /* partial_inplace */
471 0xffffffff, /* src_mask */
472 0xffffffff, /* dst_mask */
473 false), /* pcrel_offset */
475 /* 32 bit symbol relative relocation. */
476 HOWTO (R_MIPS_REL32
, /* type */
478 2, /* size (0 = byte, 1 = short, 2 = long) */
480 false, /* pc_relative */
482 complain_overflow_bitfield
, /* complain_on_overflow */
483 bfd_elf_generic_reloc
, /* special_function */
484 "R_MIPS_REL32", /* name */
485 true, /* partial_inplace */
486 0xffffffff, /* src_mask */
487 0xffffffff, /* dst_mask */
488 false), /* pcrel_offset */
490 /* 26 bit branch address. */
491 HOWTO (R_MIPS_26
, /* type */
493 2, /* size (0 = byte, 1 = short, 2 = long) */
495 false, /* pc_relative */
497 complain_overflow_dont
, /* complain_on_overflow */
498 /* This needs complex overflow
499 detection, because the upper four
500 bits must match the PC. */
501 bfd_elf_generic_reloc
, /* special_function */
502 "R_MIPS_26", /* name */
503 true, /* partial_inplace */
504 0x3ffffff, /* src_mask */
505 0x3ffffff, /* dst_mask */
506 false), /* pcrel_offset */
508 /* High 16 bits of symbol value. */
509 HOWTO (R_MIPS_HI16
, /* type */
511 2, /* size (0 = byte, 1 = short, 2 = long) */
513 false, /* pc_relative */
515 complain_overflow_dont
, /* complain_on_overflow */
516 _bfd_mips_elf_hi16_reloc
, /* special_function */
517 "R_MIPS_HI16", /* name */
518 true, /* partial_inplace */
519 0xffff, /* src_mask */
520 0xffff, /* dst_mask */
521 false), /* pcrel_offset */
523 /* Low 16 bits of symbol value. */
524 HOWTO (R_MIPS_LO16
, /* type */
526 2, /* size (0 = byte, 1 = short, 2 = long) */
528 false, /* pc_relative */
530 complain_overflow_dont
, /* complain_on_overflow */
531 _bfd_mips_elf_lo16_reloc
, /* special_function */
532 "R_MIPS_LO16", /* name */
533 true, /* partial_inplace */
534 0xffff, /* src_mask */
535 0xffff, /* dst_mask */
536 false), /* pcrel_offset */
538 /* GP relative reference. */
539 HOWTO (R_MIPS_GPREL16
, /* type */
541 2, /* size (0 = byte, 1 = short, 2 = long) */
543 false, /* pc_relative */
545 complain_overflow_signed
, /* complain_on_overflow */
546 _bfd_mips_elf_gprel16_reloc
, /* special_function */
547 "R_MIPS_GPREL16", /* name */
548 true, /* partial_inplace */
549 0xffff, /* src_mask */
550 0xffff, /* dst_mask */
551 false), /* pcrel_offset */
553 /* Reference to literal section. */
554 HOWTO (R_MIPS_LITERAL
, /* type */
556 2, /* size (0 = byte, 1 = short, 2 = long) */
558 false, /* pc_relative */
560 complain_overflow_signed
, /* complain_on_overflow */
561 _bfd_mips_elf_gprel16_reloc
, /* special_function */
562 "R_MIPS_LITERAL", /* name */
563 true, /* partial_inplace */
564 0xffff, /* src_mask */
565 0xffff, /* dst_mask */
566 false), /* pcrel_offset */
568 /* Reference to global offset table. */
569 HOWTO (R_MIPS_GOT16
, /* type */
571 2, /* size (0 = byte, 1 = short, 2 = long) */
573 false, /* pc_relative */
575 complain_overflow_signed
, /* complain_on_overflow */
576 _bfd_mips_elf_got16_reloc
, /* special_function */
577 "R_MIPS_GOT16", /* name */
578 false, /* partial_inplace */
580 0xffff, /* dst_mask */
581 false), /* pcrel_offset */
583 /* 16 bit PC relative reference. */
584 HOWTO (R_MIPS_PC16
, /* type */
586 2, /* size (0 = byte, 1 = short, 2 = long) */
588 true, /* pc_relative */
590 complain_overflow_signed
, /* complain_on_overflow */
591 bfd_elf_generic_reloc
, /* special_function */
592 "R_MIPS_PC16", /* name */
593 true, /* partial_inplace */
594 0xffff, /* src_mask */
595 0xffff, /* dst_mask */
596 false), /* pcrel_offset */
598 /* 16 bit call through global offset table. */
599 HOWTO (R_MIPS_CALL16
, /* type */
601 2, /* size (0 = byte, 1 = short, 2 = long) */
603 false, /* pc_relative */
605 complain_overflow_signed
, /* complain_on_overflow */
606 bfd_elf_generic_reloc
, /* special_function */
607 "R_MIPS_CALL16", /* name */
608 false, /* partial_inplace */
610 0xffff, /* dst_mask */
611 false), /* pcrel_offset */
613 /* 32 bit GP relative reference. */
614 HOWTO (R_MIPS_GPREL32
, /* type */
616 2, /* size (0 = byte, 1 = short, 2 = long) */
618 false, /* pc_relative */
620 complain_overflow_bitfield
, /* complain_on_overflow */
621 _bfd_mips_elf_gprel32_reloc
, /* special_function */
622 "R_MIPS_GPREL32", /* name */
623 true, /* partial_inplace */
624 0xffffffff, /* src_mask */
625 0xffffffff, /* dst_mask */
626 false), /* pcrel_offset */
628 /* The remaining relocs are defined on Irix 5, although they are
629 not defined by the ABI. */
634 /* A 5 bit shift field. */
635 HOWTO (R_MIPS_SHIFT5
, /* type */
637 2, /* size (0 = byte, 1 = short, 2 = long) */
639 false, /* pc_relative */
641 complain_overflow_bitfield
, /* complain_on_overflow */
642 bfd_elf_generic_reloc
, /* special_function */
643 "R_MIPS_SHIFT5", /* name */
644 true, /* partial_inplace */
645 0x000007c0, /* src_mask */
646 0x000007c0, /* dst_mask */
647 false), /* pcrel_offset */
649 /* A 6 bit shift field. */
650 /* FIXME: This is not handled correctly; a special function is
651 needed to put the most significant bit in the right place. */
652 HOWTO (R_MIPS_SHIFT6
, /* type */
654 2, /* size (0 = byte, 1 = short, 2 = long) */
656 false, /* pc_relative */
658 complain_overflow_bitfield
, /* complain_on_overflow */
659 bfd_elf_generic_reloc
, /* special_function */
660 "R_MIPS_SHIFT6", /* name */
661 true, /* partial_inplace */
662 0x000007c4, /* src_mask */
663 0x000007c4, /* dst_mask */
664 false), /* pcrel_offset */
666 /* A 64 bit relocation. This is used in 32 bit ELF when addresses
667 are 64 bits long; the upper 32 bits are simply a sign extension.
668 The fields of the howto should be the same as for R_MIPS_32,
669 other than the type, name, and special_function. */
670 HOWTO (R_MIPS_64
, /* type */
672 2, /* size (0 = byte, 1 = short, 2 = long) */
674 false, /* pc_relative */
676 complain_overflow_bitfield
, /* complain_on_overflow */
677 mips32_64bit_reloc
, /* special_function */
678 "R_MIPS_64", /* name */
679 true, /* partial_inplace */
680 0xffffffff, /* src_mask */
681 0xffffffff, /* dst_mask */
682 false), /* pcrel_offset */
684 /* Displacement in the global offset table. */
685 HOWTO (R_MIPS_GOT_DISP
, /* type */
687 2, /* size (0 = byte, 1 = short, 2 = long) */
689 false, /* pc_relative */
691 complain_overflow_bitfield
, /* complain_on_overflow */
692 bfd_elf_generic_reloc
, /* special_function */
693 "R_MIPS_GOT_DISP", /* name */
694 true, /* partial_inplace */
695 0x0000ffff, /* src_mask */
696 0x0000ffff, /* dst_mask */
697 false), /* pcrel_offset */
699 /* Displacement to page pointer in the global offset table. */
700 HOWTO (R_MIPS_GOT_PAGE
, /* type */
702 2, /* size (0 = byte, 1 = short, 2 = long) */
704 false, /* pc_relative */
706 complain_overflow_bitfield
, /* complain_on_overflow */
707 bfd_elf_generic_reloc
, /* special_function */
708 "R_MIPS_GOT_PAGE", /* name */
709 true, /* partial_inplace */
710 0x0000ffff, /* src_mask */
711 0x0000ffff, /* dst_mask */
712 false), /* pcrel_offset */
714 /* Offset from page pointer in the global offset table. */
715 HOWTO (R_MIPS_GOT_OFST
, /* type */
717 2, /* size (0 = byte, 1 = short, 2 = long) */
719 false, /* pc_relative */
721 complain_overflow_bitfield
, /* complain_on_overflow */
722 bfd_elf_generic_reloc
, /* special_function */
723 "R_MIPS_GOT_OFST", /* name */
724 true, /* partial_inplace */
725 0x0000ffff, /* src_mask */
726 0x0000ffff, /* dst_mask */
727 false), /* pcrel_offset */
729 /* High 16 bits of displacement in global offset table. */
730 HOWTO (R_MIPS_GOT_HI16
, /* type */
732 2, /* size (0 = byte, 1 = short, 2 = long) */
734 false, /* pc_relative */
736 complain_overflow_dont
, /* complain_on_overflow */
737 bfd_elf_generic_reloc
, /* special_function */
738 "R_MIPS_GOT_HI16", /* name */
739 true, /* partial_inplace */
740 0x0000ffff, /* src_mask */
741 0x0000ffff, /* dst_mask */
742 false), /* pcrel_offset */
744 /* Low 16 bits of displacement in global offset table. */
745 HOWTO (R_MIPS_GOT_LO16
, /* type */
747 2, /* size (0 = byte, 1 = short, 2 = long) */
749 false, /* pc_relative */
751 complain_overflow_dont
, /* complain_on_overflow */
752 bfd_elf_generic_reloc
, /* special_function */
753 "R_MIPS_GOT_LO16", /* name */
754 true, /* partial_inplace */
755 0x0000ffff, /* src_mask */
756 0x0000ffff, /* dst_mask */
757 false), /* pcrel_offset */
759 /* 64 bit subtraction. Used in the N32 ABI. */
760 HOWTO (R_MIPS_SUB
, /* type */
762 4, /* size (0 = byte, 1 = short, 2 = long) */
764 false, /* pc_relative */
766 complain_overflow_bitfield
, /* complain_on_overflow */
767 bfd_elf_generic_reloc
, /* special_function */
768 "R_MIPS_SUB", /* name */
769 true, /* partial_inplace */
770 MINUS_ONE
, /* src_mask */
771 MINUS_ONE
, /* dst_mask */
772 false), /* pcrel_offset */
774 /* Used to cause the linker to insert and delete instructions? */
779 /* Get the higher values of a 64 bit addend. Presumably not used in
784 /* High 16 bits of displacement in global offset table. */
785 HOWTO (R_MIPS_CALL_HI16
, /* type */
787 2, /* size (0 = byte, 1 = short, 2 = long) */
789 false, /* pc_relative */
791 complain_overflow_dont
, /* complain_on_overflow */
792 bfd_elf_generic_reloc
, /* special_function */
793 "R_MIPS_CALL_HI16", /* name */
794 true, /* partial_inplace */
795 0x0000ffff, /* src_mask */
796 0x0000ffff, /* dst_mask */
797 false), /* pcrel_offset */
799 /* Low 16 bits of displacement in global offset table. */
800 HOWTO (R_MIPS_CALL_LO16
, /* type */
802 2, /* size (0 = byte, 1 = short, 2 = long) */
804 false, /* pc_relative */
806 complain_overflow_dont
, /* complain_on_overflow */
807 bfd_elf_generic_reloc
, /* special_function */
808 "R_MIPS_CALL_LO16", /* name */
809 true, /* partial_inplace */
810 0x0000ffff, /* src_mask */
811 0x0000ffff, /* dst_mask */
812 false), /* pcrel_offset */
814 /* Section displacement. */
815 HOWTO (R_MIPS_SCN_DISP
, /* type */
817 2, /* size (0 = byte, 1 = short, 2 = long) */
819 false, /* pc_relative */
821 complain_overflow_dont
, /* complain_on_overflow */
822 bfd_elf_generic_reloc
, /* special_function */
823 "R_MIPS_SCN_DISP", /* name */
824 false, /* partial_inplace */
825 0xffffffff, /* src_mask */
826 0xffffffff, /* dst_mask */
827 false), /* pcrel_offset */
830 { R_MIPS_ADD_IMMEDIATE
},
834 /* Protected jump conversion. This is an optimization hint. No
835 relocation is required for correctness. */
836 HOWTO (R_MIPS_JALR
, /* type */
838 0, /* size (0 = byte, 1 = short, 2 = long) */
840 false, /* pc_relative */
842 complain_overflow_dont
, /* complain_on_overflow */
843 bfd_elf_generic_reloc
, /* special_function */
844 "R_MIPS_JALR", /* name */
845 false, /* partial_inplace */
846 0x00000000, /* src_mask */
847 0x00000000, /* dst_mask */
848 false), /* pcrel_offset */
851 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
852 is a hack to make the linker think that we need 64 bit values. */
853 static reloc_howto_type elf_mips_ctor64_howto
=
854 HOWTO (R_MIPS_64
, /* type */
856 4, /* size (0 = byte, 1 = short, 2 = long) */
858 false, /* pc_relative */
860 complain_overflow_signed
, /* complain_on_overflow */
861 mips32_64bit_reloc
, /* special_function */
862 "R_MIPS_64", /* name */
863 true, /* partial_inplace */
864 0xffffffff, /* src_mask */
865 0xffffffff, /* dst_mask */
866 false); /* pcrel_offset */
868 /* The reloc used for the mips16 jump instruction. */
869 static reloc_howto_type elf_mips16_jump_howto
=
870 HOWTO (R_MIPS16_26
, /* type */
872 2, /* size (0 = byte, 1 = short, 2 = long) */
874 false, /* pc_relative */
876 complain_overflow_dont
, /* complain_on_overflow */
877 /* This needs complex overflow
878 detection, because the upper four
879 bits must match the PC. */
880 mips16_jump_reloc
, /* special_function */
881 "R_MIPS16_26", /* name */
882 true, /* partial_inplace */
883 0x3ffffff, /* src_mask */
884 0x3ffffff, /* dst_mask */
885 false); /* pcrel_offset */
887 /* The reloc used for the mips16 gprel instruction. The src_mask and
888 dsk_mask for this howto do not reflect the actual instruction, in
889 which the value is not contiguous; the masks are for the
890 convenience of the relocate_section routine. */
891 static reloc_howto_type elf_mips16_gprel_howto
=
892 HOWTO (R_MIPS16_GPREL
, /* type */
894 2, /* size (0 = byte, 1 = short, 2 = long) */
896 false, /* pc_relative */
898 complain_overflow_signed
, /* complain_on_overflow */
899 mips16_gprel_reloc
, /* special_function */
900 "R_MIPS16_GPREL", /* name */
901 true, /* partial_inplace */
902 0xffff, /* src_mask */
903 0xffff, /* dst_mask */
904 false); /* pcrel_offset */
907 /* GNU extension to record C++ vtable hierarchy */
908 static reloc_howto_type elf_mips_gnu_vtinherit_howto
=
909 HOWTO (R_MIPS_GNU_VTINHERIT
, /* type */
911 2, /* size (0 = byte, 1 = short, 2 = long) */
913 false, /* pc_relative */
915 complain_overflow_dont
, /* complain_on_overflow */
916 NULL
, /* special_function */
917 "R_MIPS_GNU_VTINHERIT", /* name */
918 false, /* partial_inplace */
921 false); /* pcrel_offset */
923 /* GNU extension to record C++ vtable member usage */
924 static reloc_howto_type elf_mips_gnu_vtentry_howto
=
925 HOWTO (R_MIPS_GNU_VTENTRY
, /* type */
927 2, /* size (0 = byte, 1 = short, 2 = long) */
929 false, /* pc_relative */
931 complain_overflow_dont
, /* complain_on_overflow */
932 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
933 "R_MIPS_GNU_VTENTRY", /* name */
934 false, /* partial_inplace */
937 false); /* pcrel_offset */
939 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
940 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
941 the HI16. Here we just save the information we need; we do the
942 actual relocation when we see the LO16. MIPS ELF requires that the
943 LO16 immediately follow the HI16. As a GNU extension, we permit an
944 arbitrary number of HI16 relocs to be associated with a single LO16
945 reloc. This extension permits gcc to output the HI and LO relocs
950 struct mips_hi16
*next
;
955 /* FIXME: This should not be a static variable. */
957 static struct mips_hi16
*mips_hi16_list
;
959 bfd_reloc_status_type
960 _bfd_mips_elf_hi16_reloc (abfd
,
968 arelent
*reloc_entry
;
971 asection
*input_section
;
973 char **error_message
;
975 bfd_reloc_status_type ret
;
979 /* If we're relocating, and this an external symbol, we don't want
980 to change anything. */
981 if (output_bfd
!= (bfd
*) NULL
982 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
983 && reloc_entry
->addend
== 0)
985 reloc_entry
->address
+= input_section
->output_offset
;
991 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
993 boolean relocateable
;
996 if (ret
== bfd_reloc_undefined
)
999 if (output_bfd
!= NULL
)
1000 relocateable
= true;
1003 relocateable
= false;
1004 output_bfd
= symbol
->section
->output_section
->owner
;
1007 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1008 error_message
, &gp
);
1009 if (ret
!= bfd_reloc_ok
)
1012 relocation
= gp
- reloc_entry
->address
;
1016 if (bfd_is_und_section (symbol
->section
)
1017 && output_bfd
== (bfd
*) NULL
)
1018 ret
= bfd_reloc_undefined
;
1020 if (bfd_is_com_section (symbol
->section
))
1023 relocation
= symbol
->value
;
1026 relocation
+= symbol
->section
->output_section
->vma
;
1027 relocation
+= symbol
->section
->output_offset
;
1028 relocation
+= reloc_entry
->addend
;
1030 if (reloc_entry
->address
> input_section
->_cooked_size
)
1031 return bfd_reloc_outofrange
;
1033 /* Save the information, and let LO16 do the actual relocation. */
1034 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
1036 return bfd_reloc_outofrange
;
1037 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
1038 n
->addend
= relocation
;
1039 n
->next
= mips_hi16_list
;
1042 if (output_bfd
!= (bfd
*) NULL
)
1043 reloc_entry
->address
+= input_section
->output_offset
;
1048 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
1049 inplace relocation; this function exists in order to do the
1050 R_MIPS_HI16 relocation described above. */
1052 bfd_reloc_status_type
1053 _bfd_mips_elf_lo16_reloc (abfd
,
1061 arelent
*reloc_entry
;
1064 asection
*input_section
;
1066 char **error_message
;
1068 arelent gp_disp_relent
;
1070 if (mips_hi16_list
!= NULL
)
1072 struct mips_hi16
*l
;
1079 unsigned long vallo
;
1080 struct mips_hi16
*next
;
1082 /* Do the HI16 relocation. Note that we actually don't need
1083 to know anything about the LO16 itself, except where to
1084 find the low 16 bits of the addend needed by the LO16. */
1085 insn
= bfd_get_32 (abfd
, l
->addr
);
1086 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
1088 val
= ((insn
& 0xffff) << 16) + vallo
;
1091 /* The low order 16 bits are always treated as a signed
1092 value. Therefore, a negative value in the low order bits
1093 requires an adjustment in the high order bits. We need
1094 to make this adjustment in two ways: once for the bits we
1095 took from the data, and once for the bits we are putting
1096 back in to the data. */
1097 if ((vallo
& 0x8000) != 0)
1099 if ((val
& 0x8000) != 0)
1102 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
1103 bfd_put_32 (abfd
, insn
, l
->addr
);
1105 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1107 gp_disp_relent
= *reloc_entry
;
1108 reloc_entry
= &gp_disp_relent
;
1109 reloc_entry
->addend
= l
->addend
;
1117 mips_hi16_list
= NULL
;
1119 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1121 bfd_reloc_status_type ret
;
1122 bfd_vma gp
, relocation
;
1124 /* FIXME: Does this case ever occur? */
1126 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
1127 if (ret
!= bfd_reloc_ok
)
1130 relocation
= gp
- reloc_entry
->address
;
1131 relocation
+= symbol
->section
->output_section
->vma
;
1132 relocation
+= symbol
->section
->output_offset
;
1133 relocation
+= reloc_entry
->addend
;
1135 if (reloc_entry
->address
> input_section
->_cooked_size
)
1136 return bfd_reloc_outofrange
;
1138 gp_disp_relent
= *reloc_entry
;
1139 reloc_entry
= &gp_disp_relent
;
1140 reloc_entry
->addend
= relocation
- 4;
1143 /* Now do the LO16 reloc in the usual way. */
1144 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1145 input_section
, output_bfd
, error_message
);
1148 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1149 table used for PIC code. If the symbol is an external symbol, the
1150 instruction is modified to contain the offset of the appropriate
1151 entry in the global offset table. If the symbol is a section
1152 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1153 addends are combined to form the real addend against the section
1154 symbol; the GOT16 is modified to contain the offset of an entry in
1155 the global offset table, and the LO16 is modified to offset it
1156 appropriately. Thus an offset larger than 16 bits requires a
1157 modified value in the global offset table.
1159 This implementation suffices for the assembler, but the linker does
1160 not yet know how to create global offset tables. */
1162 bfd_reloc_status_type
1163 _bfd_mips_elf_got16_reloc (abfd
,
1171 arelent
*reloc_entry
;
1174 asection
*input_section
;
1176 char **error_message
;
1178 /* If we're relocating, and this an external symbol, we don't want
1179 to change anything. */
1180 if (output_bfd
!= (bfd
*) NULL
1181 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1182 && reloc_entry
->addend
== 0)
1184 reloc_entry
->address
+= input_section
->output_offset
;
1185 return bfd_reloc_ok
;
1188 /* If we're relocating, and this is a local symbol, we can handle it
1190 if (output_bfd
!= (bfd
*) NULL
1191 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1192 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1193 input_section
, output_bfd
, error_message
);
1198 /* Set the GP value for OUTPUT_BFD. Returns false if this is a
1199 dangerous relocation. */
1202 mips_elf_assign_gp (output_bfd
, pgp
)
1210 /* If we've already figured out what GP will be, just return it. */
1211 *pgp
= _bfd_get_gp_value (output_bfd
);
1215 count
= bfd_get_symcount (output_bfd
);
1216 sym
= bfd_get_outsymbols (output_bfd
);
1218 /* The linker script will have created a symbol named `_gp' with the
1219 appropriate value. */
1220 if (sym
== (asymbol
**) NULL
)
1224 for (i
= 0; i
< count
; i
++, sym
++)
1226 register CONST
char *name
;
1228 name
= bfd_asymbol_name (*sym
);
1229 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1231 *pgp
= bfd_asymbol_value (*sym
);
1232 _bfd_set_gp_value (output_bfd
, *pgp
);
1240 /* Only get the error once. */
1242 _bfd_set_gp_value (output_bfd
, *pgp
);
1249 /* We have to figure out the gp value, so that we can adjust the
1250 symbol value correctly. We look up the symbol _gp in the output
1251 BFD. If we can't find it, we're stuck. We cache it in the ELF
1252 target data. We don't need to adjust the symbol value for an
1253 external symbol if we are producing relocateable output. */
1255 static bfd_reloc_status_type
1256 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1259 boolean relocateable
;
1260 char **error_message
;
1263 if (bfd_is_und_section (symbol
->section
)
1267 return bfd_reloc_undefined
;
1270 *pgp
= _bfd_get_gp_value (output_bfd
);
1273 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1277 /* Make up a value. */
1278 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1279 _bfd_set_gp_value (output_bfd
, *pgp
);
1281 else if (!mips_elf_assign_gp (output_bfd
, pgp
))
1284 (char *) _("GP relative relocation when _gp not defined");
1285 return bfd_reloc_dangerous
;
1289 return bfd_reloc_ok
;
1292 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1293 become the offset from the gp register. This function also handles
1294 R_MIPS_LITERAL relocations, although those can be handled more
1295 cleverly because the entries in the .lit8 and .lit4 sections can be
1298 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1299 arelent
*, asection
*,
1300 boolean
, PTR
, bfd_vma
));
1302 bfd_reloc_status_type
1303 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1304 output_bfd
, error_message
)
1306 arelent
*reloc_entry
;
1309 asection
*input_section
;
1311 char **error_message
;
1313 boolean relocateable
;
1314 bfd_reloc_status_type ret
;
1317 /* If we're relocating, and this is an external symbol with no
1318 addend, we don't want to change anything. We will only have an
1319 addend if this is a newly created reloc, not read from an ELF
1321 if (output_bfd
!= (bfd
*) NULL
1322 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1323 && reloc_entry
->addend
== 0)
1325 reloc_entry
->address
+= input_section
->output_offset
;
1326 return bfd_reloc_ok
;
1329 if (output_bfd
!= (bfd
*) NULL
)
1330 relocateable
= true;
1333 relocateable
= false;
1334 output_bfd
= symbol
->section
->output_section
->owner
;
1337 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1339 if (ret
!= bfd_reloc_ok
)
1342 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1343 relocateable
, data
, gp
);
1346 static bfd_reloc_status_type
1347 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1351 arelent
*reloc_entry
;
1352 asection
*input_section
;
1353 boolean relocateable
;
1361 if (bfd_is_com_section (symbol
->section
))
1364 relocation
= symbol
->value
;
1366 relocation
+= symbol
->section
->output_section
->vma
;
1367 relocation
+= symbol
->section
->output_offset
;
1369 if (reloc_entry
->address
> input_section
->_cooked_size
)
1370 return bfd_reloc_outofrange
;
1372 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1374 /* Set val to the offset into the section or symbol. */
1375 if (reloc_entry
->howto
->src_mask
== 0)
1377 /* This case occurs with the 64-bit MIPS ELF ABI. */
1378 val
= reloc_entry
->addend
;
1382 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1387 /* Adjust val for the final section location and GP value. If we
1388 are producing relocateable output, we don't want to do this for
1389 an external symbol. */
1391 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1392 val
+= relocation
- gp
;
1394 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1395 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1398 reloc_entry
->address
+= input_section
->output_offset
;
1400 /* Make sure it fit in 16 bits. */
1401 if (val
>= 0x8000 && val
< 0xffff8000)
1402 return bfd_reloc_overflow
;
1404 return bfd_reloc_ok
;
1407 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1408 from the gp register? XXX */
1410 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1411 arelent
*, asection
*,
1412 boolean
, PTR
, bfd_vma
));
1414 bfd_reloc_status_type
1415 _bfd_mips_elf_gprel32_reloc (abfd
,
1423 arelent
*reloc_entry
;
1426 asection
*input_section
;
1428 char **error_message
;
1430 boolean relocateable
;
1431 bfd_reloc_status_type ret
;
1434 /* If we're relocating, and this is an external symbol with no
1435 addend, we don't want to change anything. We will only have an
1436 addend if this is a newly created reloc, not read from an ELF
1438 if (output_bfd
!= (bfd
*) NULL
1439 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1440 && reloc_entry
->addend
== 0)
1442 *error_message
= (char *)
1443 _("32bits gp relative relocation occurs for an external symbol");
1444 return bfd_reloc_outofrange
;
1447 if (output_bfd
!= (bfd
*) NULL
)
1449 relocateable
= true;
1450 gp
= _bfd_get_gp_value (output_bfd
);
1454 relocateable
= false;
1455 output_bfd
= symbol
->section
->output_section
->owner
;
1457 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1458 error_message
, &gp
);
1459 if (ret
!= bfd_reloc_ok
)
1463 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1464 relocateable
, data
, gp
);
1467 static bfd_reloc_status_type
1468 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1472 arelent
*reloc_entry
;
1473 asection
*input_section
;
1474 boolean relocateable
;
1481 if (bfd_is_com_section (symbol
->section
))
1484 relocation
= symbol
->value
;
1486 relocation
+= symbol
->section
->output_section
->vma
;
1487 relocation
+= symbol
->section
->output_offset
;
1489 if (reloc_entry
->address
> input_section
->_cooked_size
)
1490 return bfd_reloc_outofrange
;
1492 if (reloc_entry
->howto
->src_mask
== 0)
1494 /* This case arises with the 64-bit MIPS ELF ABI. */
1498 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1500 /* Set val to the offset into the section or symbol. */
1501 val
+= reloc_entry
->addend
;
1503 /* Adjust val for the final section location and GP value. If we
1504 are producing relocateable output, we don't want to do this for
1505 an external symbol. */
1507 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1508 val
+= relocation
- gp
;
1510 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1513 reloc_entry
->address
+= input_section
->output_offset
;
1515 return bfd_reloc_ok
;
1518 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1519 generated when addreses are 64 bits. The upper 32 bits are a simle
1522 static bfd_reloc_status_type
1523 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1524 output_bfd
, error_message
)
1526 arelent
*reloc_entry
;
1529 asection
*input_section
;
1531 char **error_message
;
1533 bfd_reloc_status_type r
;
1538 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1539 input_section
, output_bfd
, error_message
);
1540 if (r
!= bfd_reloc_continue
)
1543 /* Do a normal 32 bit relocation on the lower 32 bits. */
1544 reloc32
= *reloc_entry
;
1545 if (bfd_big_endian (abfd
))
1546 reloc32
.address
+= 4;
1547 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1548 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1549 output_bfd
, error_message
);
1551 /* Sign extend into the upper 32 bits. */
1552 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1553 if ((val
& 0x80000000) != 0)
1557 addr
= reloc_entry
->address
;
1558 if (bfd_little_endian (abfd
))
1560 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1565 /* Handle a mips16 jump. */
1567 static bfd_reloc_status_type
1568 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1569 output_bfd
, error_message
)
1571 arelent
*reloc_entry
;
1574 asection
*input_section
;
1576 char **error_message
;
1578 if (output_bfd
!= (bfd
*) NULL
1579 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1580 && reloc_entry
->addend
== 0)
1582 reloc_entry
->address
+= input_section
->output_offset
;
1583 return bfd_reloc_ok
;
1588 static boolean warned
;
1591 (*_bfd_error_handler
)
1592 (_("Linking mips16 objects into %s format is not supported"),
1593 bfd_get_target (input_section
->output_section
->owner
));
1597 return bfd_reloc_undefined
;
1600 /* Handle a mips16 GP relative reloc. */
1602 static bfd_reloc_status_type
1603 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1604 output_bfd
, error_message
)
1606 arelent
*reloc_entry
;
1609 asection
*input_section
;
1611 char **error_message
;
1613 boolean relocateable
;
1614 bfd_reloc_status_type ret
;
1616 unsigned short extend
, insn
;
1617 unsigned long final
;
1619 /* If we're relocating, and this is an external symbol with no
1620 addend, we don't want to change anything. We will only have an
1621 addend if this is a newly created reloc, not read from an ELF
1623 if (output_bfd
!= NULL
1624 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1625 && reloc_entry
->addend
== 0)
1627 reloc_entry
->address
+= input_section
->output_offset
;
1628 return bfd_reloc_ok
;
1631 if (output_bfd
!= NULL
)
1632 relocateable
= true;
1635 relocateable
= false;
1636 output_bfd
= symbol
->section
->output_section
->owner
;
1639 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1641 if (ret
!= bfd_reloc_ok
)
1644 if (reloc_entry
->address
> input_section
->_cooked_size
)
1645 return bfd_reloc_outofrange
;
1647 /* Pick up the mips16 extend instruction and the real instruction. */
1648 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1649 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1651 /* Stuff the current addend back as a 32 bit value, do the usual
1652 relocation, and then clean up. */
1654 (((extend
& 0x1f) << 11)
1657 (bfd_byte
*) data
+ reloc_entry
->address
);
1659 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1660 relocateable
, data
, gp
);
1662 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1665 | ((final
>> 11) & 0x1f)
1667 (bfd_byte
*) data
+ reloc_entry
->address
);
1671 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1676 /* Return the ISA for a MIPS e_flags value. */
1679 elf_mips_isa (flags
)
1682 switch (flags
& EF_MIPS_ARCH
)
1696 /* Return the MACH for a MIPS e_flags value. */
1699 elf_mips_mach (flags
)
1702 switch (flags
& EF_MIPS_MACH
)
1704 case E_MIPS_MACH_3900
:
1705 return bfd_mach_mips3900
;
1707 case E_MIPS_MACH_4010
:
1708 return bfd_mach_mips4010
;
1710 case E_MIPS_MACH_4100
:
1711 return bfd_mach_mips4100
;
1713 case E_MIPS_MACH_4111
:
1714 return bfd_mach_mips4111
;
1716 case E_MIPS_MACH_4650
:
1717 return bfd_mach_mips4650
;
1720 switch (flags
& EF_MIPS_ARCH
)
1724 return bfd_mach_mips3000
;
1728 return bfd_mach_mips6000
;
1732 return bfd_mach_mips4000
;
1736 return bfd_mach_mips8000
;
1744 /* Return printable name for ABI from flagword. */
1747 elf_mips_abi_name (flags
)
1750 switch (flags
& EF_MIPS_ABI
)
1754 case E_MIPS_ABI_O32
:
1756 case E_MIPS_ABI_O64
:
1758 case E_MIPS_ABI_EABI32
:
1760 case E_MIPS_ABI_EABI64
:
1763 return "unknown abi";
1767 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1769 struct elf_reloc_map
{
1770 bfd_reloc_code_real_type bfd_reloc_val
;
1771 enum elf_mips_reloc_type elf_reloc_val
;
1774 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1776 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1777 { BFD_RELOC_16
, R_MIPS_16
},
1778 { BFD_RELOC_32
, R_MIPS_32
},
1779 { BFD_RELOC_64
, R_MIPS_64
},
1780 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1781 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1782 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1783 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1784 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1785 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1786 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1787 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1788 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1789 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1790 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1791 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1792 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
},
1793 { BFD_RELOC_MIPS_SUB
, R_MIPS_SUB
},
1794 { BFD_RELOC_MIPS_GOT_PAGE
, R_MIPS_GOT_PAGE
},
1795 { BFD_RELOC_MIPS_GOT_OFST
, R_MIPS_GOT_OFST
},
1796 { BFD_RELOC_MIPS_GOT_DISP
, R_MIPS_GOT_DISP
}
1799 /* Given a BFD reloc type, return a howto structure. */
1801 static reloc_howto_type
*
1802 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1804 bfd_reloc_code_real_type code
;
1808 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1810 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1811 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1817 bfd_set_error (bfd_error_bad_value
);
1820 case BFD_RELOC_CTOR
:
1821 /* We need to handle BFD_RELOC_CTOR specially.
1822 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1823 size of addresses on this architecture. */
1824 if (bfd_arch_bits_per_address (abfd
) == 32)
1825 return &elf_mips_howto_table
[(int) R_MIPS_32
];
1827 return &elf_mips_ctor64_howto
;
1829 case BFD_RELOC_MIPS16_JMP
:
1830 return &elf_mips16_jump_howto
;
1831 case BFD_RELOC_MIPS16_GPREL
:
1832 return &elf_mips16_gprel_howto
;
1833 case BFD_RELOC_VTABLE_INHERIT
:
1834 return &elf_mips_gnu_vtinherit_howto
;
1835 case BFD_RELOC_VTABLE_ENTRY
:
1836 return &elf_mips_gnu_vtentry_howto
;
1840 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
1843 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1846 Elf32_Internal_Rel
*dst
;
1848 unsigned int r_type
;
1850 r_type
= ELF32_R_TYPE (dst
->r_info
);
1854 cache_ptr
->howto
= &elf_mips16_jump_howto
;
1856 case R_MIPS16_GPREL
:
1857 cache_ptr
->howto
= &elf_mips16_gprel_howto
;
1859 case R_MIPS_GNU_VTINHERIT
:
1860 cache_ptr
->howto
= &elf_mips_gnu_vtinherit_howto
;
1862 case R_MIPS_GNU_VTENTRY
:
1863 cache_ptr
->howto
= &elf_mips_gnu_vtentry_howto
;
1867 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1868 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1872 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1873 value for the object file. We get the addend now, rather than
1874 when we do the relocation, because the symbol manipulations done
1875 by the linker may cause us to lose track of the input BFD. */
1876 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1877 && (r_type
== (unsigned int) R_MIPS_GPREL16
1878 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1879 cache_ptr
->addend
= elf_gp (abfd
);
1882 /* Given a MIPS Elf32_Internal_Rela, fill in an arelent structure. */
1885 mips_info_to_howto_rela (abfd
, cache_ptr
, dst
)
1888 Elf32_Internal_Rela
*dst
;
1890 /* Since an Elf32_Internal_Rel is an initial prefix of an
1891 Elf32_Internal_Rela, we can just use mips_info_to_howto_rel
1893 mips_info_to_howto_rel (abfd
, cache_ptr
, (Elf32_Internal_Rel
*) dst
);
1895 /* If we ever need to do any extra processing with dst->r_addend
1896 (the field omitted in an Elf32_Internal_Rel) we can do it here. */
1899 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1900 routines swap this structure in and out. They are used outside of
1901 BFD, so they are globally visible. */
1904 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1906 const Elf32_External_RegInfo
*ex
;
1909 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1910 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1911 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1912 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1913 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1914 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1918 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1920 const Elf32_RegInfo
*in
;
1921 Elf32_External_RegInfo
*ex
;
1923 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1924 (bfd_byte
*) ex
->ri_gprmask
);
1925 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1926 (bfd_byte
*) ex
->ri_cprmask
[0]);
1927 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1928 (bfd_byte
*) ex
->ri_cprmask
[1]);
1929 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1930 (bfd_byte
*) ex
->ri_cprmask
[2]);
1931 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1932 (bfd_byte
*) ex
->ri_cprmask
[3]);
1933 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1934 (bfd_byte
*) ex
->ri_gp_value
);
1937 /* In the 64 bit ABI, the .MIPS.options section holds register
1938 information in an Elf64_Reginfo structure. These routines swap
1939 them in and out. They are globally visible because they are used
1940 outside of BFD. These routines are here so that gas can call them
1941 without worrying about whether the 64 bit ABI has been included. */
1944 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1946 const Elf64_External_RegInfo
*ex
;
1947 Elf64_Internal_RegInfo
*in
;
1949 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1950 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
1951 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1952 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1953 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1954 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1955 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1959 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1961 const Elf64_Internal_RegInfo
*in
;
1962 Elf64_External_RegInfo
*ex
;
1964 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1965 (bfd_byte
*) ex
->ri_gprmask
);
1966 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
1967 (bfd_byte
*) ex
->ri_pad
);
1968 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1969 (bfd_byte
*) ex
->ri_cprmask
[0]);
1970 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1971 (bfd_byte
*) ex
->ri_cprmask
[1]);
1972 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1973 (bfd_byte
*) ex
->ri_cprmask
[2]);
1974 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1975 (bfd_byte
*) ex
->ri_cprmask
[3]);
1976 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1977 (bfd_byte
*) ex
->ri_gp_value
);
1980 /* Swap an entry in a .gptab section. Note that these routines rely
1981 on the equivalence of the two elements of the union. */
1984 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1986 const Elf32_External_gptab
*ex
;
1989 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1990 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1994 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1996 const Elf32_gptab
*in
;
1997 Elf32_External_gptab
*ex
;
1999 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
2000 ex
->gt_entry
.gt_g_value
);
2001 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
2002 ex
->gt_entry
.gt_bytes
);
2006 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
2008 const Elf32_compact_rel
*in
;
2009 Elf32_External_compact_rel
*ex
;
2011 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
2012 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
2013 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
2014 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
2015 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
2016 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
2020 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
2022 const Elf32_crinfo
*in
;
2023 Elf32_External_crinfo
*ex
;
2027 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
2028 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
2029 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
2030 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
2031 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
2032 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
2033 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
2036 /* Swap in an options header. */
2039 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
2041 const Elf_External_Options
*ex
;
2042 Elf_Internal_Options
*in
;
2044 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
2045 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
2046 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
2047 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
2050 /* Swap out an options header. */
2053 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
2055 const Elf_Internal_Options
*in
;
2056 Elf_External_Options
*ex
;
2058 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
2059 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
2060 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
2061 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
2064 /* Swap in an MSYM entry. */
2067 bfd_mips_elf_swap_msym_in (abfd
, ex
, in
)
2069 const Elf32_External_Msym
*ex
;
2070 Elf32_Internal_Msym
*in
;
2072 in
->ms_hash_value
= bfd_h_get_32 (abfd
, ex
->ms_hash_value
);
2073 in
->ms_info
= bfd_h_get_32 (abfd
, ex
->ms_info
);
2076 /* Swap out an MSYM entry. */
2079 bfd_mips_elf_swap_msym_out (abfd
, in
, ex
)
2081 const Elf32_Internal_Msym
*in
;
2082 Elf32_External_Msym
*ex
;
2084 bfd_h_put_32 (abfd
, in
->ms_hash_value
, ex
->ms_hash_value
);
2085 bfd_h_put_32 (abfd
, in
->ms_info
, ex
->ms_info
);
2089 /* Determine whether a symbol is global for the purposes of splitting
2090 the symbol table into global symbols and local symbols. At least
2091 on Irix 5, this split must be between section symbols and all other
2092 symbols. On most ELF targets the split is between static symbols
2093 and externally visible symbols. */
2097 mips_elf_sym_is_global (abfd
, sym
)
2101 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
2104 /* Set the right machine number for a MIPS ELF file. This is used for
2105 both the 32-bit and the 64-bit ABI. */
2108 _bfd_mips_elf_object_p (abfd
)
2111 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
,
2112 elf_mips_mach (elf_elfheader (abfd
)->e_flags
));
2116 /* Set the right machine number for a 32-bit MIPS ELF file. */
2119 mips_elf32_object_p (abfd
)
2122 /* Irix 5 is broken. Object file symbol tables are not always
2123 sorted correctly such that local symbols precede global symbols,
2124 and the sh_info field in the symbol table is not always right. */
2125 elf_bad_symtab (abfd
) = true;
2127 return _bfd_mips_elf_object_p (abfd
);
2130 /* The final processing done just before writing out a MIPS ELF object
2131 file. This gets the MIPS architecture right based on the machine
2132 number. This is used by both the 32-bit and the 64-bit ABI. */
2136 _bfd_mips_elf_final_write_processing (abfd
, linker
)
2142 Elf_Internal_Shdr
**hdrpp
;
2146 switch (bfd_get_mach (abfd
))
2149 case bfd_mach_mips3000
:
2150 val
= E_MIPS_ARCH_1
;
2153 case bfd_mach_mips3900
:
2154 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
2157 case bfd_mach_mips6000
:
2158 val
= E_MIPS_ARCH_2
;
2161 case bfd_mach_mips4000
:
2162 case bfd_mach_mips4300
:
2163 val
= E_MIPS_ARCH_3
;
2166 case bfd_mach_mips4010
:
2167 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
2170 case bfd_mach_mips4100
:
2171 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
2174 case bfd_mach_mips4111
:
2175 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
2178 case bfd_mach_mips4650
:
2179 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
2182 case bfd_mach_mips8000
:
2183 val
= E_MIPS_ARCH_4
;
2187 elf_elfheader (abfd
)->e_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2188 elf_elfheader (abfd
)->e_flags
|= val
;
2190 /* Set the sh_info field for .gptab sections and other appropriate
2191 info for each special section. */
2192 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
2193 i
< elf_elfheader (abfd
)->e_shnum
;
2196 switch ((*hdrpp
)->sh_type
)
2199 case SHT_MIPS_LIBLIST
:
2200 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
2202 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2205 case SHT_MIPS_GPTAB
:
2206 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2207 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2208 BFD_ASSERT (name
!= NULL
2209 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
2210 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
2211 BFD_ASSERT (sec
!= NULL
);
2212 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2215 case SHT_MIPS_CONTENT
:
2216 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2217 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2218 BFD_ASSERT (name
!= NULL
2219 && strncmp (name
, ".MIPS.content",
2220 sizeof ".MIPS.content" - 1) == 0);
2221 sec
= bfd_get_section_by_name (abfd
,
2222 name
+ sizeof ".MIPS.content" - 1);
2223 BFD_ASSERT (sec
!= NULL
);
2224 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2227 case SHT_MIPS_SYMBOL_LIB
:
2228 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
2230 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2231 sec
= bfd_get_section_by_name (abfd
, ".liblist");
2233 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2236 case SHT_MIPS_EVENTS
:
2237 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2238 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2239 BFD_ASSERT (name
!= NULL
);
2240 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
2241 sec
= bfd_get_section_by_name (abfd
,
2242 name
+ sizeof ".MIPS.events" - 1);
2245 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
2246 sizeof ".MIPS.post_rel" - 1) == 0);
2247 sec
= bfd_get_section_by_name (abfd
,
2249 + sizeof ".MIPS.post_rel" - 1));
2251 BFD_ASSERT (sec
!= NULL
);
2252 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2259 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
2262 _bfd_mips_elf_set_private_flags (abfd
, flags
)
2266 BFD_ASSERT (!elf_flags_init (abfd
)
2267 || elf_elfheader (abfd
)->e_flags
== flags
);
2269 elf_elfheader (abfd
)->e_flags
= flags
;
2270 elf_flags_init (abfd
) = true;
2274 /* Copy backend specific data from one object module to another */
2277 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
2281 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2282 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2285 BFD_ASSERT (!elf_flags_init (obfd
)
2286 || (elf_elfheader (obfd
)->e_flags
2287 == elf_elfheader (ibfd
)->e_flags
));
2289 elf_gp (obfd
) = elf_gp (ibfd
);
2290 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
2291 elf_flags_init (obfd
) = true;
2295 /* Merge backend specific data from an object file to the output
2296 object file when linking. */
2299 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
2307 /* Check if we have the same endianess */
2308 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2309 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2313 if (bfd_big_endian (ibfd
))
2314 msg
= _("%s: compiled for a big endian system and target is little endian");
2316 msg
= _("%s: compiled for a little endian system and target is big endian");
2318 (*_bfd_error_handler
) (msg
, bfd_get_filename (ibfd
));
2320 bfd_set_error (bfd_error_wrong_format
);
2324 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2325 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2328 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2329 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
2330 old_flags
= elf_elfheader (obfd
)->e_flags
;
2332 if (! elf_flags_init (obfd
))
2334 elf_flags_init (obfd
) = true;
2335 elf_elfheader (obfd
)->e_flags
= new_flags
;
2337 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2338 && bfd_get_arch_info (obfd
)->the_default
)
2340 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
2341 bfd_get_mach (ibfd
)))
2348 /* Check flag compatibility. */
2350 new_flags
&= ~EF_MIPS_NOREORDER
;
2351 old_flags
&= ~EF_MIPS_NOREORDER
;
2353 if (new_flags
== old_flags
)
2358 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
2360 new_flags
&= ~EF_MIPS_PIC
;
2361 old_flags
&= ~EF_MIPS_PIC
;
2362 (*_bfd_error_handler
)
2363 (_("%s: linking PIC files with non-PIC files"),
2364 bfd_get_filename (ibfd
));
2368 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
2370 new_flags
&= ~EF_MIPS_CPIC
;
2371 old_flags
&= ~EF_MIPS_CPIC
;
2372 (*_bfd_error_handler
)
2373 (_("%s: linking abicalls files with non-abicalls files"),
2374 bfd_get_filename (ibfd
));
2378 /* Compare the ISA's. */
2379 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
2380 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
2382 int new_mach
= new_flags
& EF_MIPS_MACH
;
2383 int old_mach
= old_flags
& EF_MIPS_MACH
;
2384 int new_isa
= elf_mips_isa (new_flags
);
2385 int old_isa
= elf_mips_isa (old_flags
);
2387 /* If either has no machine specified, just compare the general isa's.
2388 Some combinations of machines are ok, if the isa's match. */
2391 || new_mach
== old_mach
2394 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
2395 and -mips4 code. They will normally use the same data sizes and
2396 calling conventions. */
2398 if ((new_isa
== 1 || new_isa
== 2)
2399 ? (old_isa
!= 1 && old_isa
!= 2)
2400 : (old_isa
== 1 || old_isa
== 2))
2402 (*_bfd_error_handler
)
2403 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
2404 bfd_get_filename (ibfd
), new_isa
, old_isa
);
2411 (*_bfd_error_handler
)
2412 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
2413 bfd_get_filename (ibfd
),
2414 elf_mips_mach (new_flags
),
2415 elf_mips_mach (old_flags
));
2419 new_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2420 old_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2424 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
))
2426 /* Only error if both are set (to different values). */
2427 if ((new_flags
& EF_MIPS_ABI
)
2428 && (old_flags
& EF_MIPS_ABI
))
2430 (*_bfd_error_handler
)
2431 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
2432 bfd_get_filename (ibfd
),
2433 elf_mips_abi_name (new_flags
),
2434 elf_mips_abi_name (old_flags
));
2437 new_flags
&= ~EF_MIPS_ABI
;
2438 old_flags
&= ~EF_MIPS_ABI
;
2441 /* Warn about any other mismatches */
2442 if (new_flags
!= old_flags
)
2444 (*_bfd_error_handler
)
2445 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2446 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
2447 (unsigned long) old_flags
);
2453 bfd_set_error (bfd_error_bad_value
);
2461 _bfd_mips_elf_print_private_bfd_data (abfd
, ptr
)
2465 FILE *file
= (FILE *) ptr
;
2467 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
2469 /* Print normal ELF private data. */
2470 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
2472 /* xgettext:c-format */
2473 fprintf (file
, _ ("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
2475 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
2476 fprintf (file
, _ (" [abi=O32]"));
2477 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
2478 fprintf (file
, _ (" [abi=O64]"));
2479 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
2480 fprintf (file
, _ (" [abi=EABI32]"));
2481 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
2482 fprintf (file
, _ (" [abi=EABI64]"));
2483 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
2484 fprintf (file
, _ (" [abi unknown]"));
2485 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI2
))
2486 fprintf (file
, _ (" [abi=N32]"));
2488 fprintf (file
, _ (" [no abi set]"));
2490 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
2491 fprintf (file
, _ (" [mips1]"));
2492 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
2493 fprintf (file
, _ (" [mips2]"));
2494 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
2495 fprintf (file
, _ (" [mips3]"));
2496 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
2497 fprintf (file
, _ (" [mips4]"));
2499 fprintf (file
, _ (" [unknown ISA]"));
2501 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
2502 fprintf (file
, _ (" [32bitmode]"));
2504 fprintf (file
, _ (" [not 32bitmode]"));
2511 /* Handle a MIPS specific section when reading an object file. This
2512 is called when elfcode.h finds a section with an unknown type.
2513 This routine supports both the 32-bit and 64-bit ELF ABI.
2515 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2519 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
2521 Elf_Internal_Shdr
*hdr
;
2526 /* There ought to be a place to keep ELF backend specific flags, but
2527 at the moment there isn't one. We just keep track of the
2528 sections by their name, instead. Fortunately, the ABI gives
2529 suggested names for all the MIPS specific sections, so we will
2530 probably get away with this. */
2531 switch (hdr
->sh_type
)
2533 case SHT_MIPS_LIBLIST
:
2534 if (strcmp (name
, ".liblist") != 0)
2538 if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) != 0)
2541 case SHT_MIPS_CONFLICT
:
2542 if (strcmp (name
, ".conflict") != 0)
2545 case SHT_MIPS_GPTAB
:
2546 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
2549 case SHT_MIPS_UCODE
:
2550 if (strcmp (name
, ".ucode") != 0)
2553 case SHT_MIPS_DEBUG
:
2554 if (strcmp (name
, ".mdebug") != 0)
2556 flags
= SEC_DEBUGGING
;
2558 case SHT_MIPS_REGINFO
:
2559 if (strcmp (name
, ".reginfo") != 0
2560 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
2562 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
2564 case SHT_MIPS_IFACE
:
2565 if (strcmp (name
, ".MIPS.interfaces") != 0)
2568 case SHT_MIPS_CONTENT
:
2569 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2572 case SHT_MIPS_OPTIONS
:
2573 if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) != 0)
2576 case SHT_MIPS_DWARF
:
2577 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2580 case SHT_MIPS_SYMBOL_LIB
:
2581 if (strcmp (name
, ".MIPS.symlib") != 0)
2584 case SHT_MIPS_EVENTS
:
2585 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2586 && strncmp (name
, ".MIPS.post_rel",
2587 sizeof ".MIPS.post_rel" - 1) != 0)
2594 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2599 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
2600 (bfd_get_section_flags (abfd
,
2609 /* Handle a 32-bit MIPS ELF specific section. */
2612 mips_elf32_section_from_shdr (abfd
, hdr
, name
)
2614 Elf_Internal_Shdr
*hdr
;
2617 if (! _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
))
2620 /* FIXME: We should record sh_info for a .gptab section. */
2622 /* For a .reginfo section, set the gp value in the tdata information
2623 from the contents of this section. We need the gp value while
2624 processing relocs, so we just get it now. The .reginfo section
2625 is not used in the 64-bit MIPS ELF ABI. */
2626 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2628 Elf32_External_RegInfo ext
;
2631 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
2632 (file_ptr
) 0, sizeof ext
))
2634 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
2635 elf_gp (abfd
) = s
.ri_gp_value
;
2638 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2639 set the gp value based on what we find. We may see both
2640 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2641 they should agree. */
2642 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
2644 bfd_byte
*contents
, *l
, *lend
;
2646 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
2647 if (contents
== NULL
)
2649 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
2650 (file_ptr
) 0, hdr
->sh_size
))
2656 lend
= contents
+ hdr
->sh_size
;
2657 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2659 Elf_Internal_Options intopt
;
2661 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2663 if (intopt
.kind
== ODK_REGINFO
)
2665 Elf32_RegInfo intreg
;
2667 bfd_mips_elf32_swap_reginfo_in
2669 ((Elf32_External_RegInfo
*)
2670 (l
+ sizeof (Elf_External_Options
))),
2672 elf_gp (abfd
) = intreg
.ri_gp_value
;
2682 /* Set the correct type for a MIPS ELF section. We do this by the
2683 section name, which is a hack, but ought to work. This routine is
2684 used by both the 32-bit and the 64-bit ABI. */
2687 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
2689 Elf32_Internal_Shdr
*hdr
;
2692 register const char *name
;
2694 name
= bfd_get_section_name (abfd
, sec
);
2696 if (strcmp (name
, ".liblist") == 0)
2698 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
2699 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
2700 /* The sh_link field is set in final_write_processing. */
2702 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) == 0)
2704 hdr
->sh_type
= SHT_MIPS_MSYM
;
2705 hdr
->sh_entsize
= 8;
2706 /* FIXME: Set the sh_info field. */
2708 else if (strcmp (name
, ".conflict") == 0)
2709 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
2710 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2712 hdr
->sh_type
= SHT_MIPS_GPTAB
;
2713 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
2714 /* The sh_info field is set in final_write_processing. */
2716 else if (strcmp (name
, ".ucode") == 0)
2717 hdr
->sh_type
= SHT_MIPS_UCODE
;
2718 else if (strcmp (name
, ".mdebug") == 0)
2720 hdr
->sh_type
= SHT_MIPS_DEBUG
;
2721 /* In a shared object on Irix 5.3, the .mdebug section has an
2722 entsize of 0. FIXME: Does this matter? */
2723 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2724 hdr
->sh_entsize
= 0;
2726 hdr
->sh_entsize
= 1;
2728 else if (strcmp (name
, ".reginfo") == 0)
2730 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2731 /* In a shared object on Irix 5.3, the .reginfo section has an
2732 entsize of 0x18. FIXME: Does this matter? */
2733 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2734 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2736 hdr
->sh_entsize
= 1;
2738 else if (SGI_COMPAT (abfd
)
2739 && (strcmp (name
, ".hash") == 0
2740 || strcmp (name
, ".dynamic") == 0
2741 || strcmp (name
, ".dynstr") == 0))
2743 hdr
->sh_entsize
= 0;
2745 /* This isn't how the Irix 6 linker behaves. */
2746 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2749 else if (strcmp (name
, ".got") == 0
2750 || strcmp (name
, MIPS_ELF_SRDATA_SECTION_NAME (abfd
)) == 0
2751 || strcmp (name
, ".sdata") == 0
2752 || strcmp (name
, ".sbss") == 0
2753 || strcmp (name
, ".lit4") == 0
2754 || strcmp (name
, ".lit8") == 0)
2755 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2756 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2758 hdr
->sh_type
= SHT_MIPS_IFACE
;
2759 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2761 else if (strncmp (name
, ".MIPS.content", strlen (".MIPS.content")) == 0)
2763 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2764 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2765 /* The sh_info field is set in final_write_processing. */
2767 else if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
2769 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2770 hdr
->sh_entsize
= 1;
2771 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2773 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2774 hdr
->sh_type
= SHT_MIPS_DWARF
;
2775 else if (strcmp (name
, ".MIPS.symlib") == 0)
2777 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2778 /* The sh_link and sh_info fields are set in
2779 final_write_processing. */
2781 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2782 || strncmp (name
, ".MIPS.post_rel",
2783 sizeof ".MIPS.post_rel" - 1) == 0)
2785 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2786 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2787 /* The sh_link field is set in final_write_processing. */
2789 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) == 0)
2791 hdr
->sh_type
= SHT_MIPS_MSYM
;
2792 hdr
->sh_flags
|= SHF_ALLOC
;
2793 hdr
->sh_entsize
= 8;
2796 /* The generic elf_fake_sections will set up REL_HDR using the
2797 default kind of relocations. But, we may actually need both
2798 kinds of relocations, so we set up the second header here. */
2799 if ((sec
->flags
& SEC_RELOC
) != 0)
2801 struct bfd_elf_section_data
*esd
;
2803 esd
= elf_section_data (sec
);
2804 BFD_ASSERT (esd
->rel_hdr2
== NULL
);
2806 = (Elf_Internal_Shdr
*) bfd_zalloc (abfd
, sizeof (Elf_Internal_Shdr
));
2809 _bfd_elf_init_reloc_shdr (abfd
, esd
->rel_hdr2
, sec
,
2810 !elf_section_data (sec
)->use_rela_p
);
2816 /* Given a BFD section, try to locate the corresponding ELF section
2817 index. This is used by both the 32-bit and the 64-bit ABI.
2818 Actually, it's not clear to me that the 64-bit ABI supports these,
2819 but for non-PIC objects we will certainly want support for at least
2820 the .scommon section. */
2823 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2825 Elf32_Internal_Shdr
*hdr
;
2829 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2831 *retval
= SHN_MIPS_SCOMMON
;
2834 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2836 *retval
= SHN_MIPS_ACOMMON
;
2842 /* When are writing out the .options or .MIPS.options section,
2843 remember the bytes we are writing out, so that we can install the
2844 GP value in the section_processing routine. */
2847 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2852 bfd_size_type count
;
2854 if (strcmp (section
->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
2858 if (elf_section_data (section
) == NULL
)
2860 section
->used_by_bfd
=
2861 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
2862 if (elf_section_data (section
) == NULL
)
2865 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
2870 if (section
->_cooked_size
!= 0)
2871 size
= section
->_cooked_size
;
2873 size
= section
->_raw_size
;
2874 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
2877 elf_section_data (section
)->tdata
= (PTR
) c
;
2880 memcpy (c
+ offset
, location
, count
);
2883 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
2887 /* Work over a section just before writing it out. This routine is
2888 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2889 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2893 _bfd_mips_elf_section_processing (abfd
, hdr
)
2895 Elf_Internal_Shdr
*hdr
;
2897 if (hdr
->bfd_section
!= NULL
)
2899 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
2901 if (strcmp (name
, ".sdata") == 0
2902 || strcmp (name
, ".lit8") == 0
2903 || strcmp (name
, ".lit4") == 0)
2905 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2906 hdr
->sh_type
= SHT_PROGBITS
;
2908 else if (strcmp (name
, ".sbss") == 0)
2910 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2911 hdr
->sh_type
= SHT_NOBITS
;
2913 else if (strcmp (name
, MIPS_ELF_SRDATA_SECTION_NAME (abfd
)) == 0)
2915 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
2916 hdr
->sh_type
= SHT_PROGBITS
;
2918 else if (strcmp (name
, ".compact_rel") == 0)
2921 hdr
->sh_type
= SHT_PROGBITS
;
2923 else if (strcmp (name
, ".rtproc") == 0)
2925 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
2927 unsigned int adjust
;
2929 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
2931 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
2939 /* Work over a section just before writing it out. We update the GP
2940 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2941 on the value we are using. */
2944 mips_elf32_section_processing (abfd
, hdr
)
2946 Elf32_Internal_Shdr
*hdr
;
2948 if (hdr
->sh_type
== SHT_MIPS_REGINFO
2949 && hdr
->sh_size
> 0)
2953 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2954 BFD_ASSERT (hdr
->contents
== NULL
);
2957 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2960 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2961 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2965 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2966 && hdr
->bfd_section
!= NULL
2967 && elf_section_data (hdr
->bfd_section
) != NULL
2968 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2970 bfd_byte
*contents
, *l
, *lend
;
2972 /* We stored the section contents in the elf_section_data tdata
2973 field in the set_section_contents routine. We save the
2974 section contents so that we don't have to read them again.
2975 At this point we know that elf_gp is set, so we can look
2976 through the section contents to see if there is an
2977 ODK_REGINFO structure. */
2979 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2981 lend
= contents
+ hdr
->sh_size
;
2982 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2984 Elf_Internal_Options intopt
;
2986 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2988 if (intopt
.kind
== ODK_REGINFO
)
2995 + sizeof (Elf_External_Options
)
2996 + (sizeof (Elf32_External_RegInfo
) - 4)),
2999 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
3000 if (bfd_write (buf
, 1, 4, abfd
) != 4)
3007 return _bfd_mips_elf_section_processing (abfd
, hdr
);
3010 /* MIPS ELF uses two common sections. One is the usual one, and the
3011 other is for small objects. All the small objects are kept
3012 together, and then referenced via the gp pointer, which yields
3013 faster assembler code. This is what we use for the small common
3014 section. This approach is copied from ecoff.c. */
3015 static asection mips_elf_scom_section
;
3016 static asymbol mips_elf_scom_symbol
;
3017 static asymbol
*mips_elf_scom_symbol_ptr
;
3019 /* MIPS ELF also uses an acommon section, which represents an
3020 allocated common symbol which may be overridden by a
3021 definition in a shared library. */
3022 static asection mips_elf_acom_section
;
3023 static asymbol mips_elf_acom_symbol
;
3024 static asymbol
*mips_elf_acom_symbol_ptr
;
3026 /* The Irix 5 support uses two virtual sections, which represent
3027 text/data symbols defined in dynamic objects. */
3028 static asection mips_elf_text_section
;
3029 static asection
*mips_elf_text_section_ptr
;
3030 static asymbol mips_elf_text_symbol
;
3031 static asymbol
*mips_elf_text_symbol_ptr
;
3033 static asection mips_elf_data_section
;
3034 static asection
*mips_elf_data_section_ptr
;
3035 static asymbol mips_elf_data_symbol
;
3036 static asymbol
*mips_elf_data_symbol_ptr
;
3038 /* Handle the special MIPS section numbers that a symbol may use.
3039 This is used for both the 32-bit and the 64-bit ABI. */
3042 _bfd_mips_elf_symbol_processing (abfd
, asym
)
3046 elf_symbol_type
*elfsym
;
3048 elfsym
= (elf_symbol_type
*) asym
;
3049 switch (elfsym
->internal_elf_sym
.st_shndx
)
3051 case SHN_MIPS_ACOMMON
:
3052 /* This section is used in a dynamically linked executable file.
3053 It is an allocated common section. The dynamic linker can
3054 either resolve these symbols to something in a shared
3055 library, or it can just leave them here. For our purposes,
3056 we can consider these symbols to be in a new section. */
3057 if (mips_elf_acom_section
.name
== NULL
)
3059 /* Initialize the acommon section. */
3060 mips_elf_acom_section
.name
= ".acommon";
3061 mips_elf_acom_section
.flags
= SEC_ALLOC
;
3062 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
3063 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
3064 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
3065 mips_elf_acom_symbol
.name
= ".acommon";
3066 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
3067 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
3068 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
3070 asym
->section
= &mips_elf_acom_section
;
3074 /* Common symbols less than the GP size are automatically
3075 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
3076 if (asym
->value
> elf_gp_size (abfd
)
3077 || IRIX_COMPAT (abfd
) == ict_irix6
)
3080 case SHN_MIPS_SCOMMON
:
3081 if (mips_elf_scom_section
.name
== NULL
)
3083 /* Initialize the small common section. */
3084 mips_elf_scom_section
.name
= ".scommon";
3085 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
3086 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
3087 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
3088 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
3089 mips_elf_scom_symbol
.name
= ".scommon";
3090 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
3091 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
3092 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
3094 asym
->section
= &mips_elf_scom_section
;
3095 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
3098 case SHN_MIPS_SUNDEFINED
:
3099 asym
->section
= bfd_und_section_ptr
;
3102 #if 0 /* for SGI_COMPAT */
3104 asym
->section
= mips_elf_text_section_ptr
;
3108 asym
->section
= mips_elf_data_section_ptr
;
3114 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
3118 mips_elf_additional_program_headers (abfd
)
3124 if (!SGI_COMPAT (abfd
))
3127 /* See if we need a PT_MIPS_REGINFO segment. */
3128 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3129 if (s
&& (s
->flags
& SEC_LOAD
))
3132 /* See if we need a PT_MIPS_OPTIONS segment. */
3133 if (IRIX_COMPAT (abfd
) == ict_irix6
3134 && bfd_get_section_by_name (abfd
,
3135 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
3138 /* See if we need a PT_MIPS_RTPROC segment. */
3139 if (IRIX_COMPAT (abfd
) == ict_irix5
3140 && bfd_get_section_by_name (abfd
, ".dynamic")
3141 && bfd_get_section_by_name (abfd
, ".mdebug"))
3147 /* Modify the segment map for an Irix 5 executable. */
3150 mips_elf_modify_segment_map (abfd
)
3154 struct elf_segment_map
*m
, **pm
;
3156 if (! SGI_COMPAT (abfd
))
3159 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
3161 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3162 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3164 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3165 if (m
->p_type
== PT_MIPS_REGINFO
)
3169 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3173 m
->p_type
= PT_MIPS_REGINFO
;
3177 /* We want to put it after the PHDR and INTERP segments. */
3178 pm
= &elf_tdata (abfd
)->segment_map
;
3180 && ((*pm
)->p_type
== PT_PHDR
3181 || (*pm
)->p_type
== PT_INTERP
))
3189 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
3190 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
3191 PT_OPTIONS segement immediately following the program header
3193 if (IRIX_COMPAT (abfd
) == ict_irix6
)
3197 for (s
= abfd
->sections
; s
; s
= s
->next
)
3198 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
3203 struct elf_segment_map
*options_segment
;
3205 for (m
= elf_tdata (abfd
)->segment_map
; m
; m
= m
->next
)
3206 if (m
->p_type
== PT_PHDR
)
3209 /* There should always be a program header table. */
3213 options_segment
= bfd_zalloc (abfd
,
3214 sizeof (struct elf_segment_map
));
3215 options_segment
->next
= m
->next
;
3216 options_segment
->p_type
= PT_MIPS_OPTIONS
;
3217 options_segment
->p_flags
= PF_R
;
3218 options_segment
->p_flags_valid
= true;
3219 options_segment
->count
= 1;
3220 options_segment
->sections
[0] = s
;
3221 m
->next
= options_segment
;
3226 /* If there are .dynamic and .mdebug sections, we make a room
3227 for the RTPROC header. FIXME: Rewrite without section names. */
3228 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
3229 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3230 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3232 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3233 if (m
->p_type
== PT_MIPS_RTPROC
)
3237 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3241 m
->p_type
= PT_MIPS_RTPROC
;
3243 s
= bfd_get_section_by_name (abfd
, ".rtproc");
3248 m
->p_flags_valid
= 1;
3256 /* We want to put it after the DYNAMIC segment. */
3257 pm
= &elf_tdata (abfd
)->segment_map
;
3258 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
3268 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic,
3269 .dynstr, .dynsym, and .hash sections, and everything in
3271 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
3272 if ((*pm
)->p_type
== PT_DYNAMIC
)
3277 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
3279 static const char *sec_names
[] =
3280 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
3283 struct elf_segment_map
*n
;
3287 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
3289 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
3290 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3296 sz
= s
->_cooked_size
;
3299 if (high
< s
->vma
+ sz
)
3305 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3306 if ((s
->flags
& SEC_LOAD
) != 0
3309 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3313 n
= ((struct elf_segment_map
*)
3314 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
3321 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3323 if ((s
->flags
& SEC_LOAD
) != 0
3326 + (s
->_cooked_size
!= 0 ?
3327 s
->_cooked_size
: s
->_raw_size
))
3342 /* The structure of the runtime procedure descriptor created by the
3343 loader for use by the static exception system. */
3345 typedef struct runtime_pdr
{
3346 bfd_vma adr
; /* memory address of start of procedure */
3347 long regmask
; /* save register mask */
3348 long regoffset
; /* save register offset */
3349 long fregmask
; /* save floating point register mask */
3350 long fregoffset
; /* save floating point register offset */
3351 long frameoffset
; /* frame size */
3352 short framereg
; /* frame pointer register */
3353 short pcreg
; /* offset or reg of return pc */
3354 long irpss
; /* index into the runtime string table */
3356 struct exception_info
*exception_info
;/* pointer to exception array */
3358 #define cbRPDR sizeof(RPDR)
3359 #define rpdNil ((pRPDR) 0)
3361 /* Swap RPDR (runtime procedure table entry) for output. */
3363 static void ecoff_swap_rpdr_out
3364 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
3367 ecoff_swap_rpdr_out (abfd
, in
, ex
)
3370 struct rpdr_ext
*ex
;
3372 /* ecoff_put_off was defined in ecoffswap.h. */
3373 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
3374 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
3375 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
3376 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
3377 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
3378 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
3380 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
3381 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
3383 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
3385 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
3389 /* Read ECOFF debugging information from a .mdebug section into a
3390 ecoff_debug_info structure. */
3393 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
3396 struct ecoff_debug_info
*debug
;
3399 const struct ecoff_debug_swap
*swap
;
3400 char *ext_hdr
= NULL
;
3402 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3403 memset (debug
, 0, sizeof(*debug
));
3405 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
3406 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
3409 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
3410 swap
->external_hdr_size
)
3414 symhdr
= &debug
->symbolic_header
;
3415 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
3417 /* The symbolic header contains absolute file offsets and sizes to
3419 #define READ(ptr, offset, count, size, type) \
3420 if (symhdr->count == 0) \
3421 debug->ptr = NULL; \
3424 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
3425 if (debug->ptr == NULL) \
3426 goto error_return; \
3427 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3428 || (bfd_read (debug->ptr, size, symhdr->count, \
3429 abfd) != size * symhdr->count)) \
3430 goto error_return; \
3433 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
3434 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
3435 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
3436 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
3437 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
3438 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
3440 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
3441 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
3442 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
3443 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
3444 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
3448 debug
->adjust
= NULL
;
3453 if (ext_hdr
!= NULL
)
3455 if (debug
->line
!= NULL
)
3457 if (debug
->external_dnr
!= NULL
)
3458 free (debug
->external_dnr
);
3459 if (debug
->external_pdr
!= NULL
)
3460 free (debug
->external_pdr
);
3461 if (debug
->external_sym
!= NULL
)
3462 free (debug
->external_sym
);
3463 if (debug
->external_opt
!= NULL
)
3464 free (debug
->external_opt
);
3465 if (debug
->external_aux
!= NULL
)
3466 free (debug
->external_aux
);
3467 if (debug
->ss
!= NULL
)
3469 if (debug
->ssext
!= NULL
)
3470 free (debug
->ssext
);
3471 if (debug
->external_fdr
!= NULL
)
3472 free (debug
->external_fdr
);
3473 if (debug
->external_rfd
!= NULL
)
3474 free (debug
->external_rfd
);
3475 if (debug
->external_ext
!= NULL
)
3476 free (debug
->external_ext
);
3480 /* MIPS ELF local labels start with '$', not 'L'. */
3484 mips_elf_is_local_label_name (abfd
, name
)
3491 /* On Irix 6, the labels go back to starting with '.', so we accept
3492 the generic ELF local label syntax as well. */
3493 return _bfd_elf_is_local_label_name (abfd
, name
);
3496 /* MIPS ELF uses a special find_nearest_line routine in order the
3497 handle the ECOFF debugging information. */
3499 struct mips_elf_find_line
3501 struct ecoff_debug_info d
;
3502 struct ecoff_find_line i
;
3506 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
3507 functionname_ptr
, line_ptr
)
3512 const char **filename_ptr
;
3513 const char **functionname_ptr
;
3514 unsigned int *line_ptr
;
3518 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
3519 filename_ptr
, functionname_ptr
,
3523 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3524 filename_ptr
, functionname_ptr
,
3526 ABI_64_P (abfd
) ? 8 : 0))
3529 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
3533 struct mips_elf_find_line
*fi
;
3534 const struct ecoff_debug_swap
* const swap
=
3535 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3537 /* If we are called during a link, mips_elf_final_link may have
3538 cleared the SEC_HAS_CONTENTS field. We force it back on here
3539 if appropriate (which it normally will be). */
3540 origflags
= msec
->flags
;
3541 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
3542 msec
->flags
|= SEC_HAS_CONTENTS
;
3544 fi
= elf_tdata (abfd
)->find_line_info
;
3547 bfd_size_type external_fdr_size
;
3550 struct fdr
*fdr_ptr
;
3552 fi
= ((struct mips_elf_find_line
*)
3553 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
3556 msec
->flags
= origflags
;
3560 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
3562 msec
->flags
= origflags
;
3566 /* Swap in the FDR information. */
3567 fi
->d
.fdr
= ((struct fdr
*)
3569 (fi
->d
.symbolic_header
.ifdMax
*
3570 sizeof (struct fdr
))));
3571 if (fi
->d
.fdr
== NULL
)
3573 msec
->flags
= origflags
;
3576 external_fdr_size
= swap
->external_fdr_size
;
3577 fdr_ptr
= fi
->d
.fdr
;
3578 fraw_src
= (char *) fi
->d
.external_fdr
;
3579 fraw_end
= (fraw_src
3580 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
3581 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
3582 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
3584 elf_tdata (abfd
)->find_line_info
= fi
;
3586 /* Note that we don't bother to ever free this information.
3587 find_nearest_line is either called all the time, as in
3588 objdump -l, so the information should be saved, or it is
3589 rarely called, as in ld error messages, so the memory
3590 wasted is unimportant. Still, it would probably be a
3591 good idea for free_cached_info to throw it away. */
3594 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
3595 &fi
->i
, filename_ptr
, functionname_ptr
,
3598 msec
->flags
= origflags
;
3602 msec
->flags
= origflags
;
3605 /* Fall back on the generic ELF find_nearest_line routine. */
3607 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
3608 filename_ptr
, functionname_ptr
,
3612 /* The mips16 compiler uses a couple of special sections to handle
3613 floating point arguments.
3615 Section names that look like .mips16.fn.FNNAME contain stubs that
3616 copy floating point arguments from the fp regs to the gp regs and
3617 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3618 call should be redirected to the stub instead. If no 32 bit
3619 function calls FNNAME, the stub should be discarded. We need to
3620 consider any reference to the function, not just a call, because
3621 if the address of the function is taken we will need the stub,
3622 since the address might be passed to a 32 bit function.
3624 Section names that look like .mips16.call.FNNAME contain stubs
3625 that copy floating point arguments from the gp regs to the fp
3626 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3627 then any 16 bit function that calls FNNAME should be redirected
3628 to the stub instead. If FNNAME is not a 32 bit function, the
3629 stub should be discarded.
3631 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3632 which call FNNAME and then copy the return value from the fp regs
3633 to the gp regs. These stubs store the return value in $18 while
3634 calling FNNAME; any function which might call one of these stubs
3635 must arrange to save $18 around the call. (This case is not
3636 needed for 32 bit functions that call 16 bit functions, because
3637 16 bit functions always return floating point values in both
3640 Note that in all cases FNNAME might be defined statically.
3641 Therefore, FNNAME is not used literally. Instead, the relocation
3642 information will indicate which symbol the section is for.
3644 We record any stubs that we find in the symbol table. */
3646 #define FN_STUB ".mips16.fn."
3647 #define CALL_STUB ".mips16.call."
3648 #define CALL_FP_STUB ".mips16.call.fp."
3650 /* MIPS ELF linker hash table. */
3652 struct mips_elf_link_hash_table
3654 struct elf_link_hash_table root
;
3656 /* We no longer use this. */
3657 /* String section indices for the dynamic section symbols. */
3658 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
3660 /* The number of .rtproc entries. */
3661 bfd_size_type procedure_count
;
3662 /* The size of the .compact_rel section (if SGI_COMPAT). */
3663 bfd_size_type compact_rel_size
;
3664 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3665 entry is set to the address of __rld_obj_head as in Irix 5. */
3666 boolean use_rld_obj_head
;
3667 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3669 /* This is set if we see any mips16 stub sections. */
3670 boolean mips16_stubs_seen
;
3673 /* Look up an entry in a MIPS ELF linker hash table. */
3675 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3676 ((struct mips_elf_link_hash_entry *) \
3677 elf_link_hash_lookup (&(table)->root, (string), (create), \
3680 /* Traverse a MIPS ELF linker hash table. */
3682 #define mips_elf_link_hash_traverse(table, func, info) \
3683 (elf_link_hash_traverse \
3685 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3688 /* Get the MIPS ELF linker hash table from a link_info structure. */
3690 #define mips_elf_hash_table(p) \
3691 ((struct mips_elf_link_hash_table *) ((p)->hash))
3693 static boolean mips_elf_output_extsym
3694 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3696 /* Create an entry in a MIPS ELF linker hash table. */
3698 static struct bfd_hash_entry
*
3699 mips_elf_link_hash_newfunc (entry
, table
, string
)
3700 struct bfd_hash_entry
*entry
;
3701 struct bfd_hash_table
*table
;
3704 struct mips_elf_link_hash_entry
*ret
=
3705 (struct mips_elf_link_hash_entry
*) entry
;
3707 /* Allocate the structure if it has not already been allocated by a
3709 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3710 ret
= ((struct mips_elf_link_hash_entry
*)
3711 bfd_hash_allocate (table
,
3712 sizeof (struct mips_elf_link_hash_entry
)));
3713 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3714 return (struct bfd_hash_entry
*) ret
;
3716 /* Call the allocation method of the superclass. */
3717 ret
= ((struct mips_elf_link_hash_entry
*)
3718 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3720 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3722 /* Set local fields. */
3723 memset (&ret
->esym
, 0, sizeof (EXTR
));
3724 /* We use -2 as a marker to indicate that the information has
3725 not been set. -1 means there is no associated ifd. */
3727 ret
->mips_32_relocs
= 0;
3728 ret
->min_dyn_reloc_index
= 0;
3729 ret
->fn_stub
= NULL
;
3730 ret
->need_fn_stub
= false;
3731 ret
->call_stub
= NULL
;
3732 ret
->call_fp_stub
= NULL
;
3735 return (struct bfd_hash_entry
*) ret
;
3738 /* Create a MIPS ELF linker hash table. */
3740 static struct bfd_link_hash_table
*
3741 mips_elf_link_hash_table_create (abfd
)
3744 struct mips_elf_link_hash_table
*ret
;
3746 ret
= ((struct mips_elf_link_hash_table
*)
3747 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
3748 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
3751 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3752 mips_elf_link_hash_newfunc
))
3754 bfd_release (abfd
, ret
);
3759 /* We no longer use this. */
3760 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
3761 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
3763 ret
->procedure_count
= 0;
3764 ret
->compact_rel_size
= 0;
3765 ret
->use_rld_obj_head
= false;
3767 ret
->mips16_stubs_seen
= false;
3769 return &ret
->root
.root
;
3772 /* Hook called by the linker routine which adds symbols from an object
3773 file. We must handle the special MIPS section numbers here. */
3777 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3779 struct bfd_link_info
*info
;
3780 const Elf_Internal_Sym
*sym
;
3786 if (SGI_COMPAT (abfd
)
3787 && (abfd
->flags
& DYNAMIC
) != 0
3788 && strcmp (*namep
, "_rld_new_interface") == 0)
3790 /* Skip Irix 5 rld entry name. */
3795 switch (sym
->st_shndx
)
3798 /* Common symbols less than the GP size are automatically
3799 treated as SHN_MIPS_SCOMMON symbols. */
3800 if (sym
->st_size
> elf_gp_size (abfd
)
3801 || IRIX_COMPAT (abfd
) == ict_irix6
)
3804 case SHN_MIPS_SCOMMON
:
3805 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3806 (*secp
)->flags
|= SEC_IS_COMMON
;
3807 *valp
= sym
->st_size
;
3811 /* This section is used in a shared object. */
3812 if (mips_elf_text_section_ptr
== NULL
)
3814 /* Initialize the section. */
3815 mips_elf_text_section
.name
= ".text";
3816 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
3817 mips_elf_text_section
.output_section
= NULL
;
3818 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
3819 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
3820 mips_elf_text_symbol
.name
= ".text";
3821 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
3822 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
3823 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
3824 mips_elf_text_section_ptr
= &mips_elf_text_section
;
3826 /* This code used to do *secp = bfd_und_section_ptr if
3827 info->shared. I don't know why, and that doesn't make sense,
3828 so I took it out. */
3829 *secp
= mips_elf_text_section_ptr
;
3832 case SHN_MIPS_ACOMMON
:
3833 /* Fall through. XXX Can we treat this as allocated data? */
3835 /* This section is used in a shared object. */
3836 if (mips_elf_data_section_ptr
== NULL
)
3838 /* Initialize the section. */
3839 mips_elf_data_section
.name
= ".data";
3840 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
3841 mips_elf_data_section
.output_section
= NULL
;
3842 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
3843 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
3844 mips_elf_data_symbol
.name
= ".data";
3845 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
3846 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
3847 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
3848 mips_elf_data_section_ptr
= &mips_elf_data_section
;
3850 /* This code used to do *secp = bfd_und_section_ptr if
3851 info->shared. I don't know why, and that doesn't make sense,
3852 so I took it out. */
3853 *secp
= mips_elf_data_section_ptr
;
3856 case SHN_MIPS_SUNDEFINED
:
3857 *secp
= bfd_und_section_ptr
;
3861 if (SGI_COMPAT (abfd
)
3863 && info
->hash
->creator
== abfd
->xvec
3864 && strcmp (*namep
, "__rld_obj_head") == 0)
3866 struct elf_link_hash_entry
*h
;
3868 /* Mark __rld_obj_head as dynamic. */
3870 if (! (_bfd_generic_link_add_one_symbol
3871 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3872 (bfd_vma
) *valp
, (const char *) NULL
, false,
3873 get_elf_backend_data (abfd
)->collect
,
3874 (struct bfd_link_hash_entry
**) &h
)))
3876 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
3877 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3878 h
->type
= STT_OBJECT
;
3880 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3883 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3886 /* If this is a mips16 text symbol, add 1 to the value to make it
3887 odd. This will cause something like .word SYM to come up with
3888 the right value when it is loaded into the PC. */
3889 if (sym
->st_other
== STO_MIPS16
)
3895 /* Structure used to pass information to mips_elf_output_extsym. */
3900 struct bfd_link_info
*info
;
3901 struct ecoff_debug_info
*debug
;
3902 const struct ecoff_debug_swap
*swap
;
3906 /* This routine is used to write out ECOFF debugging external symbol
3907 information. It is called via mips_elf_link_hash_traverse. The
3908 ECOFF external symbol information must match the ELF external
3909 symbol information. Unfortunately, at this point we don't know
3910 whether a symbol is required by reloc information, so the two
3911 tables may wind up being different. We must sort out the external
3912 symbol information before we can set the final size of the .mdebug
3913 section, and we must set the size of the .mdebug section before we
3914 can relocate any sections, and we can't know which symbols are
3915 required by relocation until we relocate the sections.
3916 Fortunately, it is relatively unlikely that any symbol will be
3917 stripped but required by a reloc. In particular, it can not happen
3918 when generating a final executable. */
3921 mips_elf_output_extsym (h
, data
)
3922 struct mips_elf_link_hash_entry
*h
;
3925 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
3927 asection
*sec
, *output_section
;
3929 if (h
->root
.indx
== -2)
3931 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3932 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
3933 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3934 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
3936 else if (einfo
->info
->strip
== strip_all
3937 || (einfo
->info
->strip
== strip_some
3938 && bfd_hash_lookup (einfo
->info
->keep_hash
,
3939 h
->root
.root
.root
.string
,
3940 false, false) == NULL
))
3948 if (h
->esym
.ifd
== -2)
3951 h
->esym
.cobol_main
= 0;
3952 h
->esym
.weakext
= 0;
3953 h
->esym
.reserved
= 0;
3954 h
->esym
.ifd
= ifdNil
;
3955 h
->esym
.asym
.value
= 0;
3956 h
->esym
.asym
.st
= stGlobal
;
3958 if (SGI_COMPAT (einfo
->abfd
)
3959 && (h
->root
.root
.type
== bfd_link_hash_undefined
3960 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
3964 /* Use undefined class. Also, set class and type for some
3966 name
= h
->root
.root
.root
.string
;
3967 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
3968 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
3970 h
->esym
.asym
.sc
= scData
;
3971 h
->esym
.asym
.st
= stLabel
;
3972 h
->esym
.asym
.value
= 0;
3974 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
3976 h
->esym
.asym
.sc
= scAbs
;
3977 h
->esym
.asym
.st
= stLabel
;
3978 h
->esym
.asym
.value
=
3979 mips_elf_hash_table (einfo
->info
)->procedure_count
;
3981 else if (strcmp (name
, "_gp_disp") == 0)
3983 h
->esym
.asym
.sc
= scAbs
;
3984 h
->esym
.asym
.st
= stLabel
;
3985 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
3988 h
->esym
.asym
.sc
= scUndefined
;
3990 else if (h
->root
.root
.type
!= bfd_link_hash_defined
3991 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
3992 h
->esym
.asym
.sc
= scAbs
;
3997 sec
= h
->root
.root
.u
.def
.section
;
3998 output_section
= sec
->output_section
;
4000 /* When making a shared library and symbol h is the one from
4001 the another shared library, OUTPUT_SECTION may be null. */
4002 if (output_section
== NULL
)
4003 h
->esym
.asym
.sc
= scUndefined
;
4006 name
= bfd_section_name (output_section
->owner
, output_section
);
4008 if (strcmp (name
, ".text") == 0)
4009 h
->esym
.asym
.sc
= scText
;
4010 else if (strcmp (name
, ".data") == 0)
4011 h
->esym
.asym
.sc
= scData
;
4012 else if (strcmp (name
, ".sdata") == 0)
4013 h
->esym
.asym
.sc
= scSData
;
4014 else if (strcmp (name
, ".rodata") == 0
4015 || strcmp (name
, ".rdata") == 0)
4016 h
->esym
.asym
.sc
= scRData
;
4017 else if (strcmp (name
, ".bss") == 0)
4018 h
->esym
.asym
.sc
= scBss
;
4019 else if (strcmp (name
, ".sbss") == 0)
4020 h
->esym
.asym
.sc
= scSBss
;
4021 else if (strcmp (name
, ".init") == 0)
4022 h
->esym
.asym
.sc
= scInit
;
4023 else if (strcmp (name
, ".fini") == 0)
4024 h
->esym
.asym
.sc
= scFini
;
4026 h
->esym
.asym
.sc
= scAbs
;
4030 h
->esym
.asym
.reserved
= 0;
4031 h
->esym
.asym
.index
= indexNil
;
4034 if (h
->root
.root
.type
== bfd_link_hash_common
)
4035 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
4036 else if (h
->root
.root
.type
== bfd_link_hash_defined
4037 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4039 if (h
->esym
.asym
.sc
== scCommon
)
4040 h
->esym
.asym
.sc
= scBss
;
4041 else if (h
->esym
.asym
.sc
== scSCommon
)
4042 h
->esym
.asym
.sc
= scSBss
;
4044 sec
= h
->root
.root
.u
.def
.section
;
4045 output_section
= sec
->output_section
;
4046 if (output_section
!= NULL
)
4047 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
4048 + sec
->output_offset
4049 + output_section
->vma
);
4051 h
->esym
.asym
.value
= 0;
4053 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4055 /* Set type and value for a symbol with a function stub. */
4056 h
->esym
.asym
.st
= stProc
;
4057 sec
= h
->root
.root
.u
.def
.section
;
4059 h
->esym
.asym
.value
= 0;
4062 output_section
= sec
->output_section
;
4063 if (output_section
!= NULL
)
4064 h
->esym
.asym
.value
= (h
->root
.plt
.offset
4065 + sec
->output_offset
4066 + output_section
->vma
);
4068 h
->esym
.asym
.value
= 0;
4075 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
4076 h
->root
.root
.root
.string
,
4079 einfo
->failed
= true;
4086 /* Create a runtime procedure table from the .mdebug section. */
4089 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
4092 struct bfd_link_info
*info
;
4094 struct ecoff_debug_info
*debug
;
4096 const struct ecoff_debug_swap
*swap
;
4097 HDRR
*hdr
= &debug
->symbolic_header
;
4099 struct rpdr_ext
*erp
;
4101 struct pdr_ext
*epdr
;
4102 struct sym_ext
*esym
;
4105 unsigned long size
, count
;
4106 unsigned long sindex
;
4110 const char *no_name_func
= _("static procedure (no name)");
4118 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4120 sindex
= strlen (no_name_func
) + 1;
4121 count
= hdr
->ipdMax
;
4124 size
= swap
->external_pdr_size
;
4126 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
4130 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
4133 size
= sizeof (RPDR
);
4134 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
4138 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
4142 count
= hdr
->isymMax
;
4143 size
= swap
->external_sym_size
;
4144 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
4148 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
4151 count
= hdr
->issMax
;
4152 ss
= (char *) bfd_malloc (count
);
4155 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
4158 count
= hdr
->ipdMax
;
4159 for (i
= 0; i
< count
; i
++, rp
++)
4161 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
4162 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
4163 rp
->adr
= sym
.value
;
4164 rp
->regmask
= pdr
.regmask
;
4165 rp
->regoffset
= pdr
.regoffset
;
4166 rp
->fregmask
= pdr
.fregmask
;
4167 rp
->fregoffset
= pdr
.fregoffset
;
4168 rp
->frameoffset
= pdr
.frameoffset
;
4169 rp
->framereg
= pdr
.framereg
;
4170 rp
->pcreg
= pdr
.pcreg
;
4172 sv
[i
] = ss
+ sym
.iss
;
4173 sindex
+= strlen (sv
[i
]) + 1;
4177 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
4178 size
= BFD_ALIGN (size
, 16);
4179 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
4182 mips_elf_hash_table (info
)->procedure_count
= 0;
4186 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
4188 erp
= (struct rpdr_ext
*) rtproc
;
4189 memset (erp
, 0, sizeof (struct rpdr_ext
));
4191 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
4192 strcpy (str
, no_name_func
);
4193 str
+= strlen (no_name_func
) + 1;
4194 for (i
= 0; i
< count
; i
++)
4196 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
4197 strcpy (str
, sv
[i
]);
4198 str
+= strlen (sv
[i
]) + 1;
4200 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
4202 /* Set the size and contents of .rtproc section. */
4203 s
->_raw_size
= size
;
4204 s
->contents
= (bfd_byte
*) rtproc
;
4206 /* Skip this section later on (I don't think this currently
4207 matters, but someday it might). */
4208 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
4237 /* A comparison routine used to sort .gptab entries. */
4240 gptab_compare (p1
, p2
)
4244 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
4245 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
4247 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
4250 /* We need to use a special link routine to handle the .reginfo and
4251 the .mdebug sections. We need to merge all instances of these
4252 sections together, not write them all out sequentially. */
4255 mips_elf_final_link (abfd
, info
)
4257 struct bfd_link_info
*info
;
4261 struct bfd_link_order
*p
;
4262 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
4263 asection
*rtproc_sec
;
4264 Elf32_RegInfo reginfo
;
4265 struct ecoff_debug_info debug
;
4266 const struct ecoff_debug_swap
*swap
4267 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4268 HDRR
*symhdr
= &debug
.symbolic_header
;
4269 PTR mdebug_handle
= NULL
;
4271 /* If all the things we linked together were PIC, but we're
4272 producing an executable (rather than a shared object), then the
4273 resulting file is CPIC (i.e., it calls PIC code.) */
4275 && !info
->relocateable
4276 && elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
4278 elf_elfheader (abfd
)->e_flags
&= ~EF_MIPS_PIC
;
4279 elf_elfheader (abfd
)->e_flags
|= EF_MIPS_CPIC
;
4282 /* On IRIX5, we omit the .options section. On IRIX6, however, we
4283 include it, even though we don't process it quite right. (Some
4284 entries are supposed to be merged.) Empirically, we seem to be
4285 better off including it then not. */
4286 if (IRIX_COMPAT (abfd
) == ict_irix5
)
4287 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
4289 if (strcmp ((*secpp
)->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
4291 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
4292 if (p
->type
== bfd_indirect_link_order
)
4293 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
4294 (*secpp
)->link_order_head
= NULL
;
4295 *secpp
= (*secpp
)->next
;
4296 --abfd
->section_count
;
4302 /* Get a value for the GP register. */
4303 if (elf_gp (abfd
) == 0)
4305 struct bfd_link_hash_entry
*h
;
4307 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4308 if (h
!= (struct bfd_link_hash_entry
*) NULL
4309 && h
->type
== bfd_link_hash_defined
)
4310 elf_gp (abfd
) = (h
->u
.def
.value
4311 + h
->u
.def
.section
->output_section
->vma
4312 + h
->u
.def
.section
->output_offset
);
4313 else if (info
->relocateable
)
4317 /* Find the GP-relative section with the lowest offset. */
4319 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4321 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
4324 /* And calculate GP relative to that. */
4325 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
4329 /* If the relocate_section function needs to do a reloc
4330 involving the GP value, it should make a reloc_dangerous
4331 callback to warn that GP is not defined. */
4335 /* Go through the sections and collect the .reginfo and .mdebug
4339 gptab_data_sec
= NULL
;
4340 gptab_bss_sec
= NULL
;
4341 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4343 if (strcmp (o
->name
, ".reginfo") == 0)
4345 memset (®info
, 0, sizeof reginfo
);
4347 /* We have found the .reginfo section in the output file.
4348 Look through all the link_orders comprising it and merge
4349 the information together. */
4350 for (p
= o
->link_order_head
;
4351 p
!= (struct bfd_link_order
*) NULL
;
4354 asection
*input_section
;
4356 Elf32_External_RegInfo ext
;
4359 if (p
->type
!= bfd_indirect_link_order
)
4361 if (p
->type
== bfd_fill_link_order
)
4366 input_section
= p
->u
.indirect
.section
;
4367 input_bfd
= input_section
->owner
;
4369 /* The linker emulation code has probably clobbered the
4370 size to be zero bytes. */
4371 if (input_section
->_raw_size
== 0)
4372 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4374 if (! bfd_get_section_contents (input_bfd
, input_section
,
4380 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
4382 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
4383 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
4384 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
4385 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
4386 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
4388 /* ri_gp_value is set by the function
4389 mips_elf32_section_processing when the section is
4390 finally written out. */
4392 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4393 elf_link_input_bfd ignores this section. */
4394 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4397 /* Size has been set in mips_elf_always_size_sections */
4398 BFD_ASSERT(o
->_raw_size
== sizeof (Elf32_External_RegInfo
));
4400 /* Skip this section later on (I don't think this currently
4401 matters, but someday it might). */
4402 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4407 if (strcmp (o
->name
, ".mdebug") == 0)
4409 struct extsym_info einfo
;
4411 /* We have found the .mdebug section in the output file.
4412 Look through all the link_orders comprising it and merge
4413 the information together. */
4414 symhdr
->magic
= swap
->sym_magic
;
4415 /* FIXME: What should the version stamp be? */
4417 symhdr
->ilineMax
= 0;
4421 symhdr
->isymMax
= 0;
4422 symhdr
->ioptMax
= 0;
4423 symhdr
->iauxMax
= 0;
4425 symhdr
->issExtMax
= 0;
4428 symhdr
->iextMax
= 0;
4430 /* We accumulate the debugging information itself in the
4431 debug_info structure. */
4433 debug
.external_dnr
= NULL
;
4434 debug
.external_pdr
= NULL
;
4435 debug
.external_sym
= NULL
;
4436 debug
.external_opt
= NULL
;
4437 debug
.external_aux
= NULL
;
4439 debug
.ssext
= debug
.ssext_end
= NULL
;
4440 debug
.external_fdr
= NULL
;
4441 debug
.external_rfd
= NULL
;
4442 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4444 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4445 if (mdebug_handle
== (PTR
) NULL
)
4448 if (SGI_COMPAT (abfd
))
4454 static const char * const name
[] =
4455 { ".text", ".init", ".fini", ".data",
4456 ".rodata", ".sdata", ".sbss", ".bss" };
4457 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
4458 scRData
, scSData
, scSBss
, scBss
};
4461 esym
.cobol_main
= 0;
4465 esym
.asym
.iss
= issNil
;
4466 esym
.asym
.st
= stLocal
;
4467 esym
.asym
.reserved
= 0;
4468 esym
.asym
.index
= indexNil
;
4470 for (i
= 0; i
< 8; i
++)
4472 esym
.asym
.sc
= sc
[i
];
4473 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4476 esym
.asym
.value
= s
->vma
;
4477 last
= s
->vma
+ s
->_raw_size
;
4480 esym
.asym
.value
= last
;
4482 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4488 for (p
= o
->link_order_head
;
4489 p
!= (struct bfd_link_order
*) NULL
;
4492 asection
*input_section
;
4494 const struct ecoff_debug_swap
*input_swap
;
4495 struct ecoff_debug_info input_debug
;
4499 if (p
->type
!= bfd_indirect_link_order
)
4501 if (p
->type
== bfd_fill_link_order
)
4506 input_section
= p
->u
.indirect
.section
;
4507 input_bfd
= input_section
->owner
;
4509 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4510 || (get_elf_backend_data (input_bfd
)
4511 ->elf_backend_ecoff_debug_swap
) == NULL
)
4513 /* I don't know what a non MIPS ELF bfd would be
4514 doing with a .mdebug section, but I don't really
4515 want to deal with it. */
4519 input_swap
= (get_elf_backend_data (input_bfd
)
4520 ->elf_backend_ecoff_debug_swap
);
4522 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
4524 /* The ECOFF linking code expects that we have already
4525 read in the debugging information and set up an
4526 ecoff_debug_info structure, so we do that now. */
4527 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
4531 if (! (bfd_ecoff_debug_accumulate
4532 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
4533 &input_debug
, input_swap
, info
)))
4536 /* Loop through the external symbols. For each one with
4537 interesting information, try to find the symbol in
4538 the linker global hash table and save the information
4539 for the output external symbols. */
4540 eraw_src
= input_debug
.external_ext
;
4541 eraw_end
= (eraw_src
4542 + (input_debug
.symbolic_header
.iextMax
4543 * input_swap
->external_ext_size
));
4545 eraw_src
< eraw_end
;
4546 eraw_src
+= input_swap
->external_ext_size
)
4550 struct mips_elf_link_hash_entry
*h
;
4552 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4553 if (ext
.asym
.sc
== scNil
4554 || ext
.asym
.sc
== scUndefined
4555 || ext
.asym
.sc
== scSUndefined
)
4558 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4559 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
4560 name
, false, false, true);
4561 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4567 < input_debug
.symbolic_header
.ifdMax
);
4568 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4574 /* Free up the information we just read. */
4575 free (input_debug
.line
);
4576 free (input_debug
.external_dnr
);
4577 free (input_debug
.external_pdr
);
4578 free (input_debug
.external_sym
);
4579 free (input_debug
.external_opt
);
4580 free (input_debug
.external_aux
);
4581 free (input_debug
.ss
);
4582 free (input_debug
.ssext
);
4583 free (input_debug
.external_fdr
);
4584 free (input_debug
.external_rfd
);
4585 free (input_debug
.external_ext
);
4587 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4588 elf_link_input_bfd ignores this section. */
4589 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4592 if (SGI_COMPAT (abfd
) && info
->shared
)
4594 /* Create .rtproc section. */
4595 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4596 if (rtproc_sec
== NULL
)
4598 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4599 | SEC_LINKER_CREATED
| SEC_READONLY
);
4601 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4602 if (rtproc_sec
== NULL
4603 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4604 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
4608 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
4609 info
, rtproc_sec
, &debug
))
4613 /* Build the external symbol information. */
4616 einfo
.debug
= &debug
;
4618 einfo
.failed
= false;
4619 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4620 mips_elf_output_extsym
,
4625 /* Set the size of the .mdebug section. */
4626 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4628 /* Skip this section later on (I don't think this currently
4629 matters, but someday it might). */
4630 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4635 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4637 const char *subname
;
4640 Elf32_External_gptab
*ext_tab
;
4643 /* The .gptab.sdata and .gptab.sbss sections hold
4644 information describing how the small data area would
4645 change depending upon the -G switch. These sections
4646 not used in executables files. */
4647 if (! info
->relocateable
)
4651 for (p
= o
->link_order_head
;
4652 p
!= (struct bfd_link_order
*) NULL
;
4655 asection
*input_section
;
4657 if (p
->type
!= bfd_indirect_link_order
)
4659 if (p
->type
== bfd_fill_link_order
)
4664 input_section
= p
->u
.indirect
.section
;
4666 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4667 elf_link_input_bfd ignores this section. */
4668 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4671 /* Skip this section later on (I don't think this
4672 currently matters, but someday it might). */
4673 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4675 /* Really remove the section. */
4676 for (secpp
= &abfd
->sections
;
4678 secpp
= &(*secpp
)->next
)
4680 *secpp
= (*secpp
)->next
;
4681 --abfd
->section_count
;
4686 /* There is one gptab for initialized data, and one for
4687 uninitialized data. */
4688 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4690 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4694 (*_bfd_error_handler
)
4695 (_("%s: illegal section name `%s'"),
4696 bfd_get_filename (abfd
), o
->name
);
4697 bfd_set_error (bfd_error_nonrepresentable_section
);
4701 /* The linker script always combines .gptab.data and
4702 .gptab.sdata into .gptab.sdata, and likewise for
4703 .gptab.bss and .gptab.sbss. It is possible that there is
4704 no .sdata or .sbss section in the output file, in which
4705 case we must change the name of the output section. */
4706 subname
= o
->name
+ sizeof ".gptab" - 1;
4707 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4709 if (o
== gptab_data_sec
)
4710 o
->name
= ".gptab.data";
4712 o
->name
= ".gptab.bss";
4713 subname
= o
->name
+ sizeof ".gptab" - 1;
4714 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4717 /* Set up the first entry. */
4719 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
4722 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4723 tab
[0].gt_header
.gt_unused
= 0;
4725 /* Combine the input sections. */
4726 for (p
= o
->link_order_head
;
4727 p
!= (struct bfd_link_order
*) NULL
;
4730 asection
*input_section
;
4734 bfd_size_type gpentry
;
4736 if (p
->type
!= bfd_indirect_link_order
)
4738 if (p
->type
== bfd_fill_link_order
)
4743 input_section
= p
->u
.indirect
.section
;
4744 input_bfd
= input_section
->owner
;
4746 /* Combine the gptab entries for this input section one
4747 by one. We know that the input gptab entries are
4748 sorted by ascending -G value. */
4749 size
= bfd_section_size (input_bfd
, input_section
);
4751 for (gpentry
= sizeof (Elf32_External_gptab
);
4753 gpentry
+= sizeof (Elf32_External_gptab
))
4755 Elf32_External_gptab ext_gptab
;
4756 Elf32_gptab int_gptab
;
4762 if (! (bfd_get_section_contents
4763 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4764 gpentry
, sizeof (Elf32_External_gptab
))))
4770 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
4772 val
= int_gptab
.gt_entry
.gt_g_value
;
4773 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4776 for (look
= 1; look
< c
; look
++)
4778 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4779 tab
[look
].gt_entry
.gt_bytes
+= add
;
4781 if (tab
[look
].gt_entry
.gt_g_value
== val
)
4787 Elf32_gptab
*new_tab
;
4790 /* We need a new table entry. */
4791 new_tab
= ((Elf32_gptab
*)
4792 bfd_realloc ((PTR
) tab
,
4793 (c
+ 1) * sizeof (Elf32_gptab
)));
4794 if (new_tab
== NULL
)
4800 tab
[c
].gt_entry
.gt_g_value
= val
;
4801 tab
[c
].gt_entry
.gt_bytes
= add
;
4803 /* Merge in the size for the next smallest -G
4804 value, since that will be implied by this new
4807 for (look
= 1; look
< c
; look
++)
4809 if (tab
[look
].gt_entry
.gt_g_value
< val
4811 || (tab
[look
].gt_entry
.gt_g_value
4812 > tab
[max
].gt_entry
.gt_g_value
)))
4816 tab
[c
].gt_entry
.gt_bytes
+=
4817 tab
[max
].gt_entry
.gt_bytes
;
4822 last
= int_gptab
.gt_entry
.gt_bytes
;
4825 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4826 elf_link_input_bfd ignores this section. */
4827 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4830 /* The table must be sorted by -G value. */
4832 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
4834 /* Swap out the table. */
4835 ext_tab
= ((Elf32_External_gptab
*)
4836 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
4837 if (ext_tab
== NULL
)
4843 for (i
= 0; i
< c
; i
++)
4844 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
4847 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
4848 o
->contents
= (bfd_byte
*) ext_tab
;
4850 /* Skip this section later on (I don't think this currently
4851 matters, but someday it might). */
4852 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4856 /* Invoke the regular ELF backend linker to do all the work. */
4857 if (! bfd_elf32_bfd_final_link (abfd
, info
))
4860 /* Now write out the computed sections. */
4862 if (reginfo_sec
!= (asection
*) NULL
)
4864 Elf32_External_RegInfo ext
;
4866 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
4867 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4868 (file_ptr
) 0, sizeof ext
))
4872 if (mdebug_sec
!= (asection
*) NULL
)
4874 BFD_ASSERT (abfd
->output_has_begun
);
4875 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4877 mdebug_sec
->filepos
))
4880 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4883 if (gptab_data_sec
!= (asection
*) NULL
)
4885 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4886 gptab_data_sec
->contents
,
4888 gptab_data_sec
->_raw_size
))
4892 if (gptab_bss_sec
!= (asection
*) NULL
)
4894 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4895 gptab_bss_sec
->contents
,
4897 gptab_bss_sec
->_raw_size
))
4901 if (SGI_COMPAT (abfd
))
4903 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4904 if (rtproc_sec
!= NULL
)
4906 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
4907 rtproc_sec
->contents
,
4909 rtproc_sec
->_raw_size
))
4917 /* Handle a MIPS ELF HI16 reloc. */
4920 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
4922 Elf_Internal_Rela
*relhi
;
4923 Elf_Internal_Rela
*rello
;
4930 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4932 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4935 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4937 if ((addlo
& 0x8000) != 0)
4939 if ((addend
& 0x8000) != 0)
4942 bfd_put_32 (input_bfd
,
4943 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
4944 contents
+ relhi
->r_offset
);
4947 /* Handle a MIPS ELF local GOT16 reloc. */
4950 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
4955 Elf_Internal_Rela
*relhi
;
4956 Elf_Internal_Rela
*rello
;
4960 unsigned int assigned_gotno
;
4966 bfd_byte
*got_contents
;
4967 struct mips_got_info
*g
;
4969 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4971 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4974 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4976 if ((addlo
& 0x8000) != 0)
4978 if ((addend
& 0x8000) != 0)
4981 /* Get a got entry representing requested hipage. */
4982 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4983 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4984 BFD_ASSERT (g
!= NULL
);
4986 assigned_gotno
= g
->assigned_gotno
;
4987 got_contents
= sgot
->contents
;
4988 hipage
= addend
& 0xffff0000;
4990 for (i
= MIPS_RESERVED_GOTNO
; i
< assigned_gotno
; i
++)
4992 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
4993 if (hipage
== (address
& 0xffff0000))
4997 if (i
== assigned_gotno
)
4999 if (assigned_gotno
>= g
->local_gotno
)
5001 (*_bfd_error_handler
)
5002 (_("more got entries are needed for hipage relocations"));
5003 bfd_set_error (bfd_error_bad_value
);
5007 bfd_put_32 (input_bfd
, hipage
, got_contents
+ assigned_gotno
* 4);
5008 ++g
->assigned_gotno
;
5011 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
5012 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
5013 contents
+ relhi
->r_offset
);
5018 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
5021 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
5023 Elf_Internal_Rela
*rel
;
5029 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5030 bfd_put_32 (input_bfd
,
5031 (insn
& 0xffff0000) | (offset
& 0xffff),
5032 contents
+ rel
->r_offset
);
5035 /* Returns the GOT section for ABFD. */
5038 mips_elf_got_section (abfd
)
5041 return bfd_get_section_by_name (abfd
, ".got");
5044 /* Returns the GOT information associated with the link indicated by
5045 INFO. If SGOTP is non-NULL, it is filled in with the GOT
5048 static struct mips_got_info
*
5049 mips_elf_got_info (abfd
, sgotp
)
5054 struct mips_got_info
*g
;
5056 sgot
= mips_elf_got_section (abfd
);
5057 BFD_ASSERT (sgot
!= NULL
);
5058 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5059 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5060 BFD_ASSERT (g
!= NULL
);
5067 /* Sign-extend VALUE, which has the indicated number of BITS. */
5070 mips_elf_sign_extend (value
, bits
)
5074 if (value
& (1 << (bits
- 1)))
5075 /* VALUE is negative. */
5076 value
|= ((bfd_vma
) - 1) << bits
;
5081 /* Return non-zero if the indicated VALUE has overflowed the maximum
5082 range expressable by a signed number with the indicated number of
5086 mips_elf_overflow_p (value
, bits
)
5090 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
5092 if (svalue
> (1 << (bits
- 1)) - 1)
5093 /* The value is too big. */
5095 else if (svalue
< -(1 << (bits
- 1)))
5096 /* The value is too small. */
5103 /* Calculate the %high function. */
5106 mips_elf_high (value
)
5109 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
5112 /* Calculate the %higher function. */
5115 mips_elf_higher (value
)
5119 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
5122 return (bfd_vma
) -1;
5126 /* Calculate the %highest function. */
5129 mips_elf_highest (value
)
5133 return ((value
+ (bfd_vma
) 0x800080008000) > 48) & 0xffff;
5136 return (bfd_vma
) -1;
5140 /* Returns the GOT index for the global symbol indicated by H. */
5143 mips_elf_global_got_index (abfd
, h
)
5145 struct elf_link_hash_entry
*h
;
5149 struct mips_got_info
*g
;
5151 g
= mips_elf_got_info (abfd
, &sgot
);
5153 /* Once we determine the global GOT entry with the lowest dynamic
5154 symbol table index, we must put all dynamic symbols with greater
5155 indices into the GOT. That makes it easy to calculate the GOT
5157 BFD_ASSERT (h
->dynindx
>= g
->global_gotsym
->dynindx
);
5158 index
= (h
->dynindx
- g
->global_gotsym
->dynindx
+ g
->local_gotno
) * 4;
5159 BFD_ASSERT (index
< sgot
->_raw_size
);
5164 /* Returns the offset for the entry at the INDEXth position
5168 mips_elf_got_offset_from_index (dynobj
, output_bfd
, index
)
5175 char *error_message
;
5177 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5178 gp
= _bfd_get_gp_value (output_bfd
);
5179 return (sgot
->output_section
->vma
+ sgot
->output_offset
+ index
-
5183 /* If H is a symbol that needs a global GOT entry, but has a dynamic
5184 symbol table index lower than any we've seen to date, record it for
5188 mips_elf_record_global_got_symbol (h
, info
, g
)
5189 struct elf_link_hash_entry
*h
;
5190 struct bfd_link_info
*info
;
5191 struct mips_got_info
*g
;
5193 /* A global symbol in the GOT must also be in the dynamic symbol
5195 if (h
->dynindx
== -1
5196 && !bfd_elf32_link_record_dynamic_symbol (info
, h
))
5199 /* If we've already marked this entry as need GOT space, we don't
5200 need to do it again. */
5201 if (h
->got
.offset
!= (bfd_vma
) - 1)
5204 /* By setting this to a value other than -1, we are indicating that
5205 there needs to be a GOT entry for H. */
5211 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
5212 the dynamic symbols. */
5214 struct mips_elf_hash_sort_data
5216 /* The symbol in the global GOT with the lowest dynamic symbol table
5218 struct elf_link_hash_entry
*low
;
5219 /* The least dynamic symbol table index corresponding to a symbol
5220 with a GOT entry. */
5221 long min_got_dynindx
;
5222 /* The greatest dynamic symbol table index not corresponding to a
5223 symbol without a GOT entry. */
5224 long max_non_got_dynindx
;
5227 /* If H needs a GOT entry, assign it the highest available dynamic
5228 index. Otherwise, assign it the lowest available dynamic
5232 mips_elf_sort_hash_table_f (h
, data
)
5233 struct mips_elf_link_hash_entry
*h
;
5236 struct mips_elf_hash_sort_data
*hsd
5237 = (struct mips_elf_hash_sort_data
*) data
;
5239 /* Symbols without dynamic symbol table entries aren't interesting
5241 if (h
->root
.dynindx
== -1)
5244 if (h
->root
.got
.offset
!= 0)
5245 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
5248 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
5249 hsd
->low
= (struct elf_link_hash_entry
*) h
;
5255 /* Sort the dynamic symbol table so that symbols that need GOT entries
5256 appear towards the end. This reduces the amount of GOT space
5260 mips_elf_sort_hash_table (info
)
5261 struct bfd_link_info
*info
;
5263 struct mips_elf_hash_sort_data hsd
;
5264 struct mips_got_info
*g
;
5267 dynobj
= elf_hash_table (info
)->dynobj
;
5270 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
;
5271 hsd
.max_non_got_dynindx
= 1;
5272 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
5273 elf_hash_table (info
)),
5274 mips_elf_sort_hash_table_f
,
5277 /* There shoud have been enough room in the symbol table to
5278 accomodate both the GOT and non-GOT symbols. */
5279 BFD_ASSERT (hsd
.min_got_dynindx
== hsd
.max_non_got_dynindx
);
5281 /* Now we know which dynamic symbol has the lowest dynamic symbol
5282 table index in the GOT. */
5283 g
= mips_elf_got_info (dynobj
, NULL
);
5284 g
->global_gotsym
= hsd
.low
;
5289 /* Create a local GOT entry for VALUE. Return the index of the entry,
5290 or -1 if it could not be created. */
5293 mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
)
5295 struct mips_got_info
*g
;
5299 if (g
->assigned_gotno
>= g
->local_gotno
)
5301 /* We didn't allocate enough space in the GOT. */
5302 (*_bfd_error_handler
)
5303 (_("not enough GOT space for local GOT entries"));
5304 bfd_set_error (bfd_error_bad_value
);
5305 return (bfd_vma
) -1;
5308 bfd_put_32 (abfd
, value
, sgot
->contents
+ 4 * g
->assigned_gotno
);
5309 return 4 * g
->assigned_gotno
++;
5312 /* Returns the GOT offset at which the indicated address can be found.
5313 If there is not yet a GOT entry for this value, create one. Returns
5314 -1 if no satisfactory GOT offset can be found. */
5317 mips_elf_local_got_index (abfd
, info
, value
)
5319 struct bfd_link_info
*info
;
5323 struct mips_got_info
*g
;
5326 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
5328 /* Look to see if we already have an appropriate entry. */
5329 for (entry
= sgot
->contents
+ 4 * MIPS_RESERVED_GOTNO
;
5330 entry
!= sgot
->contents
+ 4 * g
->assigned_gotno
;
5333 bfd_vma address
= bfd_get_32 (abfd
, entry
);
5335 if (address
== value
)
5336 return entry
- sgot
->contents
;
5339 return mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
5342 /* Find a GOT entry that is within 32KB of the VALUE. These entries
5343 are supposed to be placed at small offsets in the GOT, i.e.,
5344 within 32KB of GP. Return the index into the GOT for this page,
5345 and store the offset from this entry to the desired address in
5346 OFFSETP, if it is non-NULL. */
5349 mips_elf_got_page (abfd
, info
, value
, offsetp
)
5351 struct bfd_link_info
*info
;
5356 struct mips_got_info
*g
;
5358 bfd_byte
*last_entry
;
5362 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
5364 /* Look to see if we aleady have an appropriate entry. */
5365 last_entry
= sgot
->contents
+ 4 * g
->assigned_gotno
;
5366 for (entry
= sgot
->contents
+ 4 * MIPS_RESERVED_GOTNO
;
5367 entry
!= last_entry
;
5370 address
= bfd_get_32 (abfd
, entry
);
5371 if (!mips_elf_overflow_p (value
- address
, 16))
5373 /* This entry will serve as the page pointer. We can add a
5374 16-bit number to it to get the actual address. */
5375 index
= entry
- sgot
->contents
;
5380 /* If we didn't have an appropriate entry, we create one now. */
5381 if (entry
== last_entry
)
5382 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
5386 address
= bfd_get_32 (abfd
, entry
);
5387 *offsetp
= value
- address
;
5393 /* Find a GOT entry whose higher-order 16 bits are the same as those
5394 for value. Return the index into the GOT for this entry. */
5397 mips_elf_got16_entry (abfd
, info
, value
)
5399 struct bfd_link_info
*info
;
5403 struct mips_got_info
*g
;
5405 bfd_byte
*last_entry
;
5409 value
&= 0xffff0000;
5410 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
5412 /* Look to see if we already have an appropriate entry. */
5413 last_entry
= sgot
->contents
+ 4 * g
->assigned_gotno
;
5414 for (entry
= sgot
->contents
+ 4 * MIPS_RESERVED_GOTNO
;
5415 entry
!= last_entry
;
5418 address
= bfd_get_32 (abfd
, entry
);
5419 if (address
& 0xffff0000 == value
)
5421 /* This entry has the right high-order 16 bits. */
5422 index
= 4 * (entry
- sgot
->contents
);
5427 /* If we didn't have an appropriate entry, we create one now. */
5428 if (entry
== last_entry
)
5429 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
5434 /* Sets *ADDENDP to the addend for the first R_MIPS_LO16 relocation
5435 found, beginning with RELOCATION. RELEND is one-past-the-end of
5436 the relocation table. */
5439 mips_elf_next_lo16_addend (relocation
, relend
, addendp
)
5440 Elf_Internal_Rela
*relocation
;
5441 Elf_Internal_Rela
*relend
;
5444 /* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be
5445 immediately following. However, for the IRIX6 ABI, the next
5446 relocation may be a composed relocation consisting of several
5447 relocations for the same address. In that case, the R_MIPS_LO16
5448 relo!scation may occur as one of these. We permit a similar
5449 extension in general, as that is useful for GCC. */
5450 while (relocation
< relend
)
5452 if (ELF32_R_TYPE (relocation
->r_info
) == R_MIPS_LO16
)
5454 *addendp
= relocation
->r_addend
;
5461 /* We didn't find it. */
5465 /* Create a rel.dyn relocation for the dynamic linker to resolve. The
5466 relocatin is against the symbol with the dynamic symbol table index
5467 DYNINDX. REL is the original relocation, which is now being made
5471 mips_elf_create_dynamic_relocation (output_bfd
, info
, rel
, dynindx
,
5472 addend
, input_section
)
5474 struct bfd_link_info
*info
;
5475 Elf_Internal_Rela
*rel
;
5478 asection
*input_section
;
5480 Elf_Internal_Rel outrel
;
5486 r_type
= ELF32_R_TYPE (rel
->r_info
);
5487 dynobj
= elf_hash_table (info
)->dynobj
;
5488 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5489 BFD_ASSERT (sreloc
!= NULL
);
5493 /* The symbol for the relocation is the same as it was for the
5494 original relocation. */
5495 outrel
.r_info
= ELF32_R_INFO (dynindx
, R_MIPS_REL32
);
5497 /* The offset for the dynamic relocation is the same as for the
5498 original relocation, adjusted by the offset at which the original
5499 section is output. */
5500 if (elf_section_data (input_section
)->stab_info
== NULL
)
5501 outrel
.r_offset
= rel
->r_offset
;
5506 off
= (_bfd_stab_section_offset
5507 (output_bfd
, &elf_hash_table (info
)->stab_info
,
5509 &elf_section_data (input_section
)->stab_info
,
5511 if (off
== (bfd_vma
) -1)
5513 outrel
.r_offset
= off
;
5515 outrel
.r_offset
+= (input_section
->output_section
->vma
5516 + input_section
->output_offset
);
5518 /* If we've decided to skip this relocation, just output an emtpy
5521 memset (&outrel
, 0, sizeof (outrel
));
5523 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
5524 (((Elf32_External_Rel
*)
5526 + sreloc
->reloc_count
));
5527 ++sreloc
->reloc_count
;
5529 /* Make sure the output section is writable. The dynamic linker
5530 will be writing to it. */
5531 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
5534 /* On IRIX5, make an entry of compact relocation info. */
5535 if (! skip
&& IRIX_COMPAT (output_bfd
) == ict_irix5
)
5537 asection
* scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5542 Elf32_crinfo cptrel
;
5544 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5545 cptrel
.vaddr
= (rel
->r_offset
5546 + input_section
->output_section
->vma
5547 + input_section
->output_offset
);
5548 if (r_type
== R_MIPS_REL32
)
5549 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5551 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5552 mips_elf_set_cr_dist2to (cptrel
, 0);
5553 cptrel
.konst
= addend
;
5555 cr
= (scpt
->contents
5556 + sizeof (Elf32_External_compact_rel
));
5557 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5558 ((Elf32_External_crinfo
*) cr
5559 + scpt
->reloc_count
));
5560 ++scpt
->reloc_count
;
5564 return sreloc
->reloc_count
- 1;
5567 /* Calculate the value produced by the RELOCATION (which comes from
5568 the INPUT_BFD). The ADDEND is the addend to use for this
5569 RELOCATION; RELOCATION->R_ADDEND is ignored.
5571 The result of the relocation calculation is stored in VALUEP.
5573 This function returns bfd_reloc_continue if the caller need take no
5574 further action regarding this relocation, bfd_reloc_notsupported if
5575 something goes dramatically wrong, bfd_reloc_overflow if an
5576 overflow occurs, and bfd_reloc_ok to indicate success. */
5578 static bfd_reloc_status_type
5579 mips_elf_calculate_relocation (abfd
,
5593 asection
*input_section
;
5594 struct bfd_link_info
*info
;
5595 Elf_Internal_Rela
*relocation
;
5597 reloc_howto_type
*howto
;
5598 Elf_Internal_Rela
*relend
;
5599 Elf_Internal_Sym
*local_syms
;
5600 asection
**local_sections
;
5604 /* The eventual value we will return. */
5606 /* The address of the symbol against which the relocation is
5609 /* The final GP value to be used for the relocatable, executable, or
5610 shared object file being produced. */
5611 bfd_vma gp
= (bfd_vma
) - 1;
5612 /* The place (section offset or address) of the storage unit being
5615 /* The value of GP used to create the relocatable object. */
5616 bfd_vma gp0
= (bfd_vma
) - 1;
5617 /* The offset into the global offset table at which the address of
5618 the relocation entry symbol, adjusted by the addend, resides
5619 during execution. */
5620 bfd_vma g
= (bfd_vma
) - 1;
5621 /* The section in which the symbol referenced by the relocation is
5623 asection
*sec
= NULL
;
5624 struct mips_elf_link_hash_entry
* h
= NULL
;
5625 unsigned long r_symndx
;
5627 boolean gp_disp_p
= false;
5628 Elf_Internal_Shdr
*symtab_hdr
;
5631 boolean overflowed_p
;
5633 /* Parse the relocation. */
5634 r_symndx
= ELF32_R_SYM (relocation
->r_info
);
5635 r_type
= ELF32_R_TYPE (relocation
->r_info
);
5636 p
= (input_section
->output_section
->vma
5637 + input_section
->output_offset
5638 + relocation
->r_offset
);
5640 /* Assume that there will be no overflow. */
5641 overflowed_p
= false;
5643 /* Figure out whether or not the symbol is local. */
5644 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5645 if (elf_bad_symtab (input_bfd
))
5647 /* The symbol table does not follow the rule that local symbols
5648 must come before globals. */
5650 local_p
= local_sections
[r_symndx
] != NULL
;
5654 extsymoff
= symtab_hdr
->sh_info
;
5655 local_p
= r_symndx
< extsymoff
;
5658 /* Figure out the value of the symbol. */
5661 Elf_Internal_Sym
*sym
;
5663 sym
= local_syms
+ r_symndx
;
5664 sec
= local_sections
[r_symndx
];
5666 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
5667 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5668 symbol
+= sym
->st_value
;
5670 /* MIPS16 text labels should be treated as odd. */
5671 if (sym
->st_other
== STO_MIPS16
)
5674 /* Record the name of this symbol, for our caller. */
5675 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
5676 symtab_hdr
->sh_link
,
5679 *namep
= bfd_section_name (input_bfd
, sec
);
5683 /* For global symbols we look up the symbol in the hash-table. */
5684 h
= ((struct mips_elf_link_hash_entry
*)
5685 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
5686 /* Find the real hash-table entry for this symbol. */
5687 while (h
->root
.type
== bfd_link_hash_indirect
5688 || h
->root
.type
== bfd_link_hash_warning
)
5689 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
5691 /* Record the name of this symbol, for our caller. */
5692 *namep
= h
->root
.root
.root
.string
;
5694 /* See if this is the special _gp_disp symbol. Note that such a
5695 symbol must always be a global symbol. */
5696 if (strcmp (h
->root
.root
.root
.string
, "_gp_disp") == 0)
5698 /* Relocations against _gp_disp are permitted only with
5699 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
5700 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_LO16
)
5701 return bfd_reloc_notsupported
;
5706 /* If this symbol is defined, calculate its address. */
5707 if ((h
->root
.root
.type
== bfd_link_hash_defined
5708 || h
->root
.root
.type
== bfd_link_hash_defweak
)
5709 && h
->root
.root
.u
.def
.section
)
5711 sec
= h
->root
.root
.u
.def
.section
;
5712 if (sec
->output_section
)
5713 symbol
= (h
->root
.root
.u
.def
.value
5714 + sec
->output_section
->vma
5715 + sec
->output_offset
);
5717 symbol
= h
->root
.root
.u
.def
.value
;
5721 (*info
->callbacks
->undefined_symbol
)
5722 (info
, h
->root
.root
.root
.string
, input_bfd
,
5723 input_section
, relocation
->r_offset
);
5724 return bfd_reloc_undefined
;
5728 /* If we haven't already determined the GOT offset, or the GP value,
5729 and we're going to need it, get it now. */
5733 case R_MIPS_GOT_DISP
:
5734 case R_MIPS_GOT_HI16
:
5735 case R_MIPS_CALL_HI16
:
5736 case R_MIPS_GOT_LO16
:
5737 case R_MIPS_CALL_LO16
:
5738 /* Find the index into the GOT where this value is located. */
5741 BFD_ASSERT (addend
== 0);
5742 g
= mips_elf_global_got_index
5743 (elf_hash_table (info
)->dynobj
,
5744 (struct elf_link_hash_entry
*) h
);
5748 g
= mips_elf_local_got_index (abfd
, info
, symbol
+ addend
);
5749 if (g
== (bfd_vma
) -1)
5753 /* Convert GOT indices to actual offsets. */
5754 g
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
5760 case R_MIPS_GPREL16
:
5761 case R_MIPS_GPREL32
:
5762 gp0
= _bfd_get_gp_value (input_bfd
);
5763 gp
= _bfd_get_gp_value (abfd
);
5770 /* Figure out what kind of relocation is being performed. */
5774 return bfd_reloc_continue
;
5777 value
= symbol
+ mips_elf_sign_extend (addend
, 16);
5778 overflowed_p
= mips_elf_overflow_p (value
, 16);
5783 /* If we're creating a shared library, or this relocation is
5784 against a symbol in a shared library, then we can't know
5785 where the symbol will end up. So, we create a relocation
5786 record in the output, and leave the job up to the dynamic
5788 if (info
->shared
|| !sec
->output_section
)
5790 unsigned int reloc_index
;
5792 BFD_ASSERT (h
!= NULL
);
5794 = mips_elf_create_dynamic_relocation (abfd
,
5800 if (h
->min_dyn_reloc_index
== 0
5801 || reloc_index
< h
->min_dyn_reloc_index
)
5802 h
->min_dyn_reloc_index
= reloc_index
;
5803 value
= symbol
+ addend
;
5807 if (r_type
== R_MIPS_32
)
5808 value
= symbol
+ addend
;
5812 value
&= howto
->dst_mask
;
5817 value
= (((addend
<< 2) | (p
& 0xf0000000)) + symbol
) >> 2;
5819 value
= (mips_elf_sign_extend (addend
<< 2, 28) + symbol
) >> 2;
5820 value
&= howto
->dst_mask
;
5826 value
= mips_elf_high (addend
+ symbol
);
5827 value
&= howto
->dst_mask
;
5831 value
= mips_elf_high (addend
+ gp
- p
);
5832 overflowed_p
= mips_elf_overflow_p (value
, 16);
5838 value
= (symbol
+ addend
) & howto
->dst_mask
;
5841 value
= addend
+ gp
- p
+ 4;
5842 overflowed_p
= mips_elf_overflow_p (value
, 16);
5846 case R_MIPS_LITERAL
:
5847 /* Because we don't merge literal sections, we can handle this
5848 just like R_MIPS_GPREL16. In the long run, we should merge
5849 shared literals, and then we will need to additional work
5854 case R_MIPS_GPREL16
:
5856 value
= mips_elf_sign_extend (addend
, 16) + symbol
+ gp0
- gp
;
5858 value
= mips_elf_sign_extend (addend
, 16) + symbol
- gp
;
5859 overflowed_p
= mips_elf_overflow_p (value
, 16);
5865 value
= mips_elf_got16_entry (abfd
, info
, symbol
+ addend
);
5866 if (value
== (bfd_vma
) -1)
5869 = mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
5872 overflowed_p
= mips_elf_overflow_p (value
, 16);
5879 case R_MIPS_GOT_DISP
:
5881 overflowed_p
= mips_elf_overflow_p (value
, 16);
5884 case R_MIPS_GPREL32
:
5885 value
= (addend
+ symbol
+ gp0
- gp
) & howto
->dst_mask
;
5889 value
= mips_elf_sign_extend (addend
, 16) + symbol
- p
;
5890 overflowed_p
= mips_elf_overflow_p (value
, 16);
5893 case R_MIPS_GOT_HI16
:
5894 case R_MIPS_CALL_HI16
:
5895 /* We're allowed to handle these two relocations identically.
5896 The dynamic linker is allowed to handle the CALL relocations
5897 differently by creating a lazy evaluation stub. */
5899 value
= mips_elf_high (value
);
5900 value
&= howto
->dst_mask
;
5903 case R_MIPS_GOT_LO16
:
5904 case R_MIPS_CALL_LO16
:
5905 value
= g
& howto
->dst_mask
;
5909 value
= (symbol
+ addend
) & howto
->dst_mask
;
5912 case R_MIPS_GOT_PAGE
:
5913 value
= mips_elf_got_page (abfd
, info
, symbol
+ addend
, NULL
);
5914 if (value
== (bfd_vma
) -1)
5916 value
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
5919 overflowed_p
= mips_elf_overflow_p (value
, 16);
5922 case R_MIPS_GOT_OFST
:
5923 mips_elf_got_page (abfd
, info
, symbol
+ addend
, &value
);
5924 overflowed_p
= mips_elf_overflow_p (value
, 16);
5928 value
= symbol
- addend
;
5929 value
&= howto
->dst_mask
;
5933 value
= mips_elf_higher (addend
+ symbol
);
5934 value
&= howto
->dst_mask
;
5937 case R_MIPS_HIGHEST
:
5938 value
= mips_elf_highest (addend
+ symbol
);
5939 value
&= howto
->dst_mask
;
5942 case R_MIPS_SCN_DISP
:
5943 value
= symbol
+ addend
- sec
->output_offset
;
5944 value
&= howto
->dst_mask
;
5949 /* Both of these may be ignored. R_MIPS_JALR is an optimization
5950 hint; we could improve performance by honoring that hint. */
5951 return bfd_reloc_continue
;
5953 case R_MIPS_GNU_VTINHERIT
:
5954 case R_MIPS_GNU_VTENTRY
:
5955 /* We don't do anything with these at present. */
5956 return bfd_reloc_continue
;
5959 case R_MIPS16_GPREL
:
5960 /* These relocations, used for MIPS16, are not clearly
5961 documented anywhere. What do they do? */
5962 return bfd_reloc_notsupported
;
5965 /* An unrecognized relocation type. */
5966 return bfd_reloc_notsupported
;
5969 /* Store the VALUE for our caller. */
5971 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
5974 /* Obtain the field relocated by RELOCATION. */
5977 mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
)
5978 reloc_howto_type
*howto
;
5979 Elf_Internal_Rela
*relocation
;
5984 bfd_byte
*location
= contents
+ relocation
->r_offset
;
5986 switch (bfd_get_reloc_size (howto
))
5993 x
= bfd_get_8 (input_bfd
, location
);
5997 x
= bfd_get_16 (input_bfd
, location
);
6001 x
= bfd_get_32 (input_bfd
, location
);
6006 x
= bfd_get_64 (input_bfd
, location
);
6020 /* It has been determined that the result of the RELOCATION is the
6021 VALUE. Use HOWTO to place VALUE into the output file at the
6022 appropriate position. The SECTION is the section to which the
6025 Returns false if anything goes wrong. */
6028 mips_elf_perform_relocation (howto
, relocation
, value
, input_bfd
, contents
)
6029 reloc_howto_type
*howto
;
6030 Elf_Internal_Rela
*relocation
;
6036 bfd_byte
*location
= contents
+ relocation
->r_offset
;
6038 /* Obtain the current value. */
6039 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
6041 /* Clear the field we are setting. */
6042 x
&= ~howto
->dst_mask
;
6044 /* Set the field. */
6045 x
|= (value
& howto
->dst_mask
);
6047 /* Put the value into the output. */
6048 switch (bfd_get_reloc_size (howto
))
6055 bfd_put_8 (input_bfd
, x
, location
);
6059 bfd_put_16 (input_bfd
, x
, location
);
6063 bfd_put_32 (input_bfd
, x
, location
);
6068 bfd_put_64 (input_bfd
, x
, location
);
6080 /* Relocate a MIPS ELF section. */
6083 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
6084 contents
, relocs
, local_syms
, local_sections
)
6086 struct bfd_link_info
*info
;
6088 asection
*input_section
;
6090 Elf_Internal_Rela
*relocs
;
6091 Elf_Internal_Sym
*local_syms
;
6092 asection
**local_sections
;
6094 Elf_Internal_Shdr
*symtab_hdr
;
6097 asection
*sgot
, *sreloc
, *scpt
;
6100 Elf_Internal_Rela
*rel
;
6101 Elf_Internal_Rela
*relend
;
6102 struct mips_got_info
*g
;
6104 bfd_vma last_hi16_addend
;
6105 boolean next_relocation_for_same_address_p
= false;
6106 boolean use_saved_addend_p
= false;
6107 boolean last_hi16_addend_valid_p
= false;
6109 dynobj
= elf_hash_table (info
)->dynobj
;
6110 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
6114 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
6117 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
6120 if (elf_bad_symtab (input_bfd
))
6122 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
6127 locsymcount
= symtab_hdr
->sh_info
;
6128 extsymoff
= symtab_hdr
->sh_info
;
6131 gp
= _bfd_get_gp_value (output_bfd
);
6132 relend
= relocs
+ input_section
->reloc_count
;
6134 for (rel
= relocs
; rel
< relend
; ++rel
)
6139 reloc_howto_type
*howto
;
6141 /* Find the relocation howto for this relocation. */
6142 howto
= elf_mips_howto_table
+ ELF32_R_TYPE (rel
->r_info
);
6144 if (!use_saved_addend_p
)
6146 Elf_Internal_Shdr
*rel_hdr
;
6148 /* If these relocations were originally of the REL variety,
6149 we must pull the addend out of the field that will be
6150 relocated. Otherwise, we simply use the contents of the
6151 RELA relocation. To determine which flavor or relocation
6152 this is, we depend on the fact that the INPUT_SECTION's
6153 REL_HDR is read before its REL_HDR2. */
6154 rel_hdr
= &elf_section_data (input_section
)->rel_hdr
;
6155 if (rel
- relocs
>= rel_hdr
->sh_size
/ rel_hdr
->sh_entsize
)
6156 rel_hdr
= elf_section_data (input_section
)->rel_hdr2
;
6157 if (rel_hdr
->sh_entsize
== sizeof (Elf32_External_Rel
))
6159 int r_type
= ELF32_R_TYPE (rel
->r_info
);
6161 addend
= mips_elf_obtain_contents (howto
,
6165 addend
&= howto
->src_mask
;
6167 /* For some kinds of relocations, the ADDEND is a
6168 combination of the addend stored in two different
6170 if (r_type
== R_MIPS_HI16
|| r_type
== R_MIPS_GOT16
)
6172 /* Scan ahead to find a matching R_MIPS_LO16
6176 if (!mips_elf_next_lo16_addend (rel
, relend
, &l
))
6179 /* Save the high-order bit for later. When we
6180 encounter the R_MIPS_LO16 relocation we will need
6183 last_hi16_addend
= addend
;
6184 last_hi16_addend_valid_p
= true;
6186 /* Compute the combined addend. */
6189 else if (r_type
== R_MIPS_LO16
)
6191 /* Used the saved HI16 addend. */
6192 if (!last_hi16_addend_valid_p
)
6194 addend
|= last_hi16_addend
;
6198 addend
= rel
->r_addend
;
6201 /* In the N32 and 64-bit ABIs there may be multiple consecutive
6202 relocations for the same offset. In that case we are
6203 supposed to treat the output of each relocation as the addend
6205 if (rel
+ 1 < relend
&& rel
->r_offset
== (rel
+ 1)->r_offset
)
6206 use_saved_addend_p
= true;
6208 use_saved_addend_p
= false;
6210 /* Figure out what value we are supposed to relocate. */
6211 switch (mips_elf_calculate_relocation (output_bfd
,
6224 case bfd_reloc_continue
:
6225 /* There's nothing to do. */
6228 case bfd_reloc_undefined
:
6231 case bfd_reloc_notsupported
:
6235 case bfd_reloc_overflow
:
6236 if (use_saved_addend_p
)
6237 /* Ignore overflow until we reach the last relocation for
6238 a given location. */
6241 || ! ((*info
->callbacks
->reloc_overflow
)
6242 (info
, name
, howto
->name
, (bfd_vma
) 0,
6243 input_bfd
, input_section
, rel
->r_offset
)))
6256 /* If we've got another relocation for the address, keep going
6257 until we reach the last one. */
6258 if (use_saved_addend_p
)
6264 /* Actually perform the relocation. */
6265 mips_elf_perform_relocation (howto
, rel
, value
, input_bfd
,
6272 /* This hook function is called before the linker writes out a global
6273 symbol. We mark symbols as small common if appropriate. This is
6274 also where we undo the increment of the value for a mips16 symbol. */
6278 mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
6280 struct bfd_link_info
*info
;
6282 Elf_Internal_Sym
*sym
;
6283 asection
*input_sec
;
6285 /* If we see a common symbol, which implies a relocatable link, then
6286 if a symbol was small common in an input file, mark it as small
6287 common in the output file. */
6288 if (sym
->st_shndx
== SHN_COMMON
6289 && strcmp (input_sec
->name
, ".scommon") == 0)
6290 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
6292 if (sym
->st_other
== STO_MIPS16
6293 && (sym
->st_value
& 1) != 0)
6299 /* Functions for the dynamic linker. */
6301 /* The name of the dynamic interpreter. This is put in the .interp
6304 #define ELF_DYNAMIC_INTERPRETER(abfd) \
6305 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" : "/usr/lib/libc.so.1")
6307 /* Create dynamic sections when linking against a dynamic object. */
6310 mips_elf_create_dynamic_sections (abfd
, info
)
6312 struct bfd_link_info
*info
;
6314 struct elf_link_hash_entry
*h
;
6316 register asection
*s
;
6317 const char * const *namep
;
6319 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6320 | SEC_LINKER_CREATED
| SEC_READONLY
);
6322 /* Mips ABI requests the .dynamic section to be read only. */
6323 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6326 if (! bfd_set_section_flags (abfd
, s
, flags
))
6330 /* We need to create .got section. */
6331 if (! mips_elf_create_got_section (abfd
, info
))
6334 /* Create the .msym section on IRIX6. It is used by the dynamic
6335 linker to speed up dynamic relocations, and to avoid computing
6336 the ELF hash for symbols. */
6337 if (IRIX_COMPAT (abfd
) == ict_irix6
6338 && !mips_elf_create_msym_section (abfd
))
6341 /* Create .stub section. */
6342 if (bfd_get_section_by_name (abfd
,
6343 MIPS_ELF_STUB_SECTION_NAME (abfd
)) == NULL
)
6345 s
= bfd_make_section (abfd
, MIPS_ELF_STUB_SECTION_NAME (abfd
));
6347 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_CODE
)
6348 || ! bfd_set_section_alignment (abfd
, s
, 2))
6352 if (IRIX_COMPAT (abfd
) == ict_irix5
6354 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
6356 s
= bfd_make_section (abfd
, ".rld_map");
6358 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
6359 || ! bfd_set_section_alignment (abfd
, s
, 2))
6363 /* On IRIX5, we adjust add some additional symbols and change the
6364 alignments of several sections. There is no ABI documentation
6365 indicating that this is necessary on IRIX6, nor any evidence that
6366 the linker takes such action. */
6367 if (IRIX_COMPAT (abfd
) == ict_irix5
)
6369 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
6372 if (! (_bfd_generic_link_add_one_symbol
6373 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
6374 (bfd_vma
) 0, (const char *) NULL
, false,
6375 get_elf_backend_data (abfd
)->collect
,
6376 (struct bfd_link_hash_entry
**) &h
)))
6378 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6379 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6380 h
->type
= STT_SECTION
;
6382 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6386 /* We need to create a .compact_rel section. */
6387 if (! mips_elf_create_compact_rel_section (abfd
, info
))
6390 /* Change aligments of some sections. */
6391 s
= bfd_get_section_by_name (abfd
, ".hash");
6393 bfd_set_section_alignment (abfd
, s
, 4);
6394 s
= bfd_get_section_by_name (abfd
, ".dynsym");
6396 bfd_set_section_alignment (abfd
, s
, 4);
6397 s
= bfd_get_section_by_name (abfd
, ".dynstr");
6399 bfd_set_section_alignment (abfd
, s
, 4);
6400 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6402 bfd_set_section_alignment (abfd
, s
, 4);
6403 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6405 bfd_set_section_alignment (abfd
, s
, 4);
6411 if (! (_bfd_generic_link_add_one_symbol
6412 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
6413 (bfd_vma
) 0, (const char *) NULL
, false,
6414 get_elf_backend_data (abfd
)->collect
,
6415 (struct bfd_link_hash_entry
**) &h
)))
6417 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6418 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6419 h
->type
= STT_SECTION
;
6421 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6424 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
6426 /* __rld_map is a four byte word located in the .data section
6427 and is filled in by the rtld to contain a pointer to
6428 the _r_debug structure. Its symbol value will be set in
6429 mips_elf_finish_dynamic_symbol. */
6430 s
= bfd_get_section_by_name (abfd
, ".rld_map");
6431 BFD_ASSERT (s
!= NULL
);
6434 if (! (_bfd_generic_link_add_one_symbol
6435 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
6436 (bfd_vma
) 0, (const char *) NULL
, false,
6437 get_elf_backend_data (abfd
)->collect
,
6438 (struct bfd_link_hash_entry
**) &h
)))
6440 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6441 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6442 h
->type
= STT_OBJECT
;
6444 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6452 /* Create the .compact_rel section. */
6455 mips_elf_create_compact_rel_section (abfd
, info
)
6457 struct bfd_link_info
*info
;
6460 register asection
*s
;
6462 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
6464 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
6467 s
= bfd_make_section (abfd
, ".compact_rel");
6469 || ! bfd_set_section_flags (abfd
, s
, flags
)
6470 || ! bfd_set_section_alignment (abfd
, s
, 2))
6473 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
6479 /* Create the .got section to hold the global offset table. */
6482 mips_elf_create_got_section (abfd
, info
)
6484 struct bfd_link_info
*info
;
6487 register asection
*s
;
6488 struct elf_link_hash_entry
*h
;
6489 struct mips_got_info
*g
;
6491 /* This function may be called more than once. */
6492 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
6495 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6496 | SEC_LINKER_CREATED
);
6498 s
= bfd_make_section (abfd
, ".got");
6500 || ! bfd_set_section_flags (abfd
, s
, flags
)
6501 || ! bfd_set_section_alignment (abfd
, s
, 4))
6504 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
6505 linker script because we don't want to define the symbol if we
6506 are not creating a global offset table. */
6508 if (! (_bfd_generic_link_add_one_symbol
6509 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
6510 (bfd_vma
) 0, (const char *) NULL
, false,
6511 get_elf_backend_data (abfd
)->collect
,
6512 (struct bfd_link_hash_entry
**) &h
)))
6514 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6515 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6516 h
->type
= STT_OBJECT
;
6519 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6522 /* The first several global offset table entries are reserved. */
6523 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
6525 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
6526 sizeof (struct mips_got_info
));
6529 g
->global_gotsym
= NULL
;
6530 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
6531 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
6532 if (elf_section_data (s
) == NULL
)
6535 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
6536 if (elf_section_data (s
) == NULL
)
6539 elf_section_data (s
)->tdata
= (PTR
) g
;
6540 elf_section_data (s
)->this_hdr
.sh_flags
6541 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
6546 /* Returns the .msym section for ABFD, creating it if it does not
6547 already exist. Returns NULL to indicate error. */
6550 mips_elf_create_msym_section (abfd
)
6555 s
= bfd_get_section_by_name (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
6558 s
= bfd_make_section (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
6560 || !bfd_set_section_flags (abfd
, s
,
6564 | SEC_LINKER_CREATED
6566 || !bfd_set_section_alignment (abfd
, s
, 2))
6573 /* Look through the relocs for a section during the first phase, and
6574 allocate space in the global offset table. */
6577 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
6579 struct bfd_link_info
*info
;
6581 const Elf_Internal_Rela
*relocs
;
6585 Elf_Internal_Shdr
*symtab_hdr
;
6586 struct elf_link_hash_entry
**sym_hashes
;
6587 struct mips_got_info
*g
;
6589 const Elf_Internal_Rela
*rel
;
6590 const Elf_Internal_Rela
*rel_end
;
6594 if (info
->relocateable
)
6597 dynobj
= elf_hash_table (info
)->dynobj
;
6598 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6599 sym_hashes
= elf_sym_hashes (abfd
);
6600 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
6602 /* Check for the mips16 stub sections. */
6604 name
= bfd_get_section_name (abfd
, sec
);
6605 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
6607 unsigned long r_symndx
;
6609 /* Look at the relocation information to figure out which symbol
6612 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6614 if (r_symndx
< extsymoff
6615 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6619 /* This stub is for a local symbol. This stub will only be
6620 needed if there is some relocation in this BFD, other
6621 than a 16 bit function call, which refers to this symbol. */
6622 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6624 Elf_Internal_Rela
*sec_relocs
;
6625 const Elf_Internal_Rela
*r
, *rend
;
6627 /* We can ignore stub sections when looking for relocs. */
6628 if ((o
->flags
& SEC_RELOC
) == 0
6629 || o
->reloc_count
== 0
6630 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
6631 sizeof FN_STUB
- 1) == 0
6632 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
6633 sizeof CALL_STUB
- 1) == 0
6634 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
6635 sizeof CALL_FP_STUB
- 1) == 0)
6638 sec_relocs
= (_bfd_elf32_link_read_relocs
6639 (abfd
, o
, (PTR
) NULL
,
6640 (Elf_Internal_Rela
*) NULL
,
6641 info
->keep_memory
));
6642 if (sec_relocs
== NULL
)
6645 rend
= sec_relocs
+ o
->reloc_count
;
6646 for (r
= sec_relocs
; r
< rend
; r
++)
6647 if (ELF32_R_SYM (r
->r_info
) == r_symndx
6648 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
6651 if (! info
->keep_memory
)
6660 /* There is no non-call reloc for this stub, so we do
6661 not need it. Since this function is called before
6662 the linker maps input sections to output sections, we
6663 can easily discard it by setting the SEC_EXCLUDE
6665 sec
->flags
|= SEC_EXCLUDE
;
6669 /* Record this stub in an array of local symbol stubs for
6671 if (elf_tdata (abfd
)->local_stubs
== NULL
)
6673 unsigned long symcount
;
6676 if (elf_bad_symtab (abfd
))
6677 symcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
6679 symcount
= symtab_hdr
->sh_info
;
6680 n
= (asection
**) bfd_zalloc (abfd
,
6681 symcount
* sizeof (asection
*));
6684 elf_tdata (abfd
)->local_stubs
= n
;
6687 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
6689 /* We don't need to set mips16_stubs_seen in this case.
6690 That flag is used to see whether we need to look through
6691 the global symbol table for stubs. We don't need to set
6692 it here, because we just have a local stub. */
6696 struct mips_elf_link_hash_entry
*h
;
6698 h
= ((struct mips_elf_link_hash_entry
*)
6699 sym_hashes
[r_symndx
- extsymoff
]);
6701 /* H is the symbol this stub is for. */
6704 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6707 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
6708 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6710 unsigned long r_symndx
;
6711 struct mips_elf_link_hash_entry
*h
;
6714 /* Look at the relocation information to figure out which symbol
6717 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6719 if (r_symndx
< extsymoff
6720 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6722 /* This stub was actually built for a static symbol defined
6723 in the same file. We assume that all static symbols in
6724 mips16 code are themselves mips16, so we can simply
6725 discard this stub. Since this function is called before
6726 the linker maps input sections to output sections, we can
6727 easily discard it by setting the SEC_EXCLUDE flag. */
6728 sec
->flags
|= SEC_EXCLUDE
;
6732 h
= ((struct mips_elf_link_hash_entry
*)
6733 sym_hashes
[r_symndx
- extsymoff
]);
6735 /* H is the symbol this stub is for. */
6737 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6738 loc
= &h
->call_fp_stub
;
6740 loc
= &h
->call_stub
;
6742 /* If we already have an appropriate stub for this function, we
6743 don't need another one, so we can discard this one. Since
6744 this function is called before the linker maps input sections
6745 to output sections, we can easily discard it by setting the
6746 SEC_EXCLUDE flag. We can also discard this section if we
6747 happen to already know that this is a mips16 function; it is
6748 not necessary to check this here, as it is checked later, but
6749 it is slightly faster to check now. */
6750 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
6752 sec
->flags
|= SEC_EXCLUDE
;
6757 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6767 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6772 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6773 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6774 BFD_ASSERT (g
!= NULL
);
6780 rel_end
= relocs
+ sec
->reloc_count
;
6781 for (rel
= relocs
; rel
< rel_end
; rel
++)
6783 unsigned long r_symndx
;
6785 struct elf_link_hash_entry
*h
;
6787 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6788 r_type
= ELF32_R_TYPE (rel
->r_info
);
6790 if (r_symndx
< extsymoff
)
6794 h
= sym_hashes
[r_symndx
- extsymoff
];
6796 /* This may be an indirect symbol created because of a version. */
6799 while (h
->root
.type
== bfd_link_hash_indirect
)
6800 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6804 /* Some relocs require a global offset table. */
6805 if (dynobj
== NULL
|| sgot
== NULL
)
6811 case R_MIPS_CALL_HI16
:
6812 case R_MIPS_CALL_LO16
:
6813 case R_MIPS_GOT_HI16
:
6814 case R_MIPS_GOT_LO16
:
6816 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6817 if (! mips_elf_create_got_section (dynobj
, info
))
6819 g
= mips_elf_got_info (dynobj
, &sgot
);
6825 && (info
->shared
|| h
!= NULL
)
6826 && (sec
->flags
& SEC_ALLOC
) != 0)
6827 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6835 if (!h
&& (r_type
== R_MIPS_CALL_LO16
6836 || r_type
== R_MIPS_GOT_LO16
6837 || r_type
== R_MIPS_GOT_DISP
))
6839 /* We may need a local GOT entry for this relocation. We
6840 don't count R_MIPS_HI16 or R_MIPS_GOT16 relocations
6841 because they are always followed by a R_MIPS_LO16
6842 relocation for the value. We don't R_MIPS_GOT_PAGE
6843 because we can estimate the maximum number of pages
6844 needed by looking at the size of the segment.
6846 This estimation is very conservative since we can merge
6847 duplicate entries in the GOT. In order to be less
6848 conservative, we could actually build the GOT here,
6849 rather than in relocate_section. */
6851 sgot
->_raw_size
+= 4;
6859 (*_bfd_error_handler
)
6860 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
6861 bfd_get_filename (abfd
), (unsigned long) rel
->r_offset
);
6862 bfd_set_error (bfd_error_bad_value
);
6867 case R_MIPS_CALL_HI16
:
6868 case R_MIPS_CALL_LO16
:
6869 /* This symbol requires a global offset table entry. */
6870 if (!mips_elf_record_global_got_symbol (h
, info
, g
))
6873 /* We need a stub, not a plt entry for the undefined
6874 function. But we record it as if it needs plt. See
6875 elf_adjust_dynamic_symbol in elflink.h. */
6876 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6882 case R_MIPS_GOT_HI16
:
6883 case R_MIPS_GOT_LO16
:
6884 case R_MIPS_GOT_DISP
:
6885 /* This symbol requires a global offset table entry. */
6886 if (h
&& !mips_elf_record_global_got_symbol (h
, info
, g
))
6892 if ((info
->shared
|| h
!= NULL
)
6893 && (sec
->flags
& SEC_ALLOC
) != 0)
6897 const char *name
= ".rel.dyn";
6899 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6902 sreloc
= bfd_make_section (dynobj
, name
);
6904 || ! bfd_set_section_flags (dynobj
, sreloc
,
6909 | SEC_LINKER_CREATED
6911 || ! bfd_set_section_alignment (dynobj
, sreloc
,
6918 /* When creating a shared object, we must copy these
6919 reloc types into the output file as R_MIPS_REL32
6920 relocs. We make room for this reloc in the
6921 .rel.dyn reloc section */
6922 if (sreloc
->_raw_size
== 0)
6924 /* Add a null element. */
6925 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6926 ++sreloc
->reloc_count
;
6928 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6932 struct mips_elf_link_hash_entry
*hmips
;
6934 /* We only need to copy this reloc if the symbol is
6935 defined in a dynamic object. */
6936 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6937 ++hmips
->mips_32_relocs
;
6940 /* Even though we don't directly need a GOT entry for
6941 this symbol, a symbol must have a dynamic symbol
6942 table index greater that DT_GOTSYM if there are
6943 dynamic relocations against it. */
6944 if (!mips_elf_record_global_got_symbol (h
, info
, g
))
6948 if (SGI_COMPAT (abfd
))
6949 mips_elf_hash_table (info
)->compact_rel_size
+=
6950 sizeof (Elf32_External_crinfo
);
6955 case R_MIPS_GPREL16
:
6956 case R_MIPS_LITERAL
:
6957 case R_MIPS_GPREL32
:
6958 if (SGI_COMPAT (abfd
))
6959 mips_elf_hash_table (info
)->compact_rel_size
+=
6960 sizeof (Elf32_External_crinfo
);
6963 /* This relocation describes the C++ object vtable hierarchy.
6964 Reconstruct it for later use during GC. */
6965 case R_MIPS_GNU_VTINHERIT
:
6966 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6970 /* This relocation describes which C++ vtable entries are actually
6971 used. Record for later use during GC. */
6972 case R_MIPS_GNU_VTENTRY
:
6973 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
6981 /* If this reloc is not a 16 bit call, and it has a global
6982 symbol, then we will need the fn_stub if there is one.
6983 References from a stub section do not count. */
6985 && r_type
!= R_MIPS16_26
6986 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
6987 sizeof FN_STUB
- 1) != 0
6988 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
6989 sizeof CALL_STUB
- 1) != 0
6990 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
6991 sizeof CALL_FP_STUB
- 1) != 0)
6993 struct mips_elf_link_hash_entry
*mh
;
6995 mh
= (struct mips_elf_link_hash_entry
*) h
;
6996 mh
->need_fn_stub
= true;
7003 /* Return the section that should be marked against GC for a given
7007 mips_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
7009 struct bfd_link_info
*info
;
7010 Elf_Internal_Rela
*rel
;
7011 struct elf_link_hash_entry
*h
;
7012 Elf_Internal_Sym
*sym
;
7014 /* ??? Do mips16 stub sections need to be handled special? */
7018 switch (ELF32_R_TYPE (rel
->r_info
))
7020 case R_MIPS_GNU_VTINHERIT
:
7021 case R_MIPS_GNU_VTENTRY
:
7025 switch (h
->root
.type
)
7027 case bfd_link_hash_defined
:
7028 case bfd_link_hash_defweak
:
7029 return h
->root
.u
.def
.section
;
7031 case bfd_link_hash_common
:
7032 return h
->root
.u
.c
.p
->section
;
7041 if (!(elf_bad_symtab (abfd
)
7042 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
7043 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
7044 && sym
->st_shndx
!= SHN_COMMON
))
7046 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
7053 /* Update the got entry reference counts for the section being removed. */
7056 mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
7058 struct bfd_link_info
*info
;
7060 const Elf_Internal_Rela
*relocs
;
7063 Elf_Internal_Shdr
*symtab_hdr
;
7064 struct elf_link_hash_entry
**sym_hashes
;
7065 bfd_signed_vma
*local_got_refcounts
;
7066 const Elf_Internal_Rela
*rel
, *relend
;
7067 unsigned long r_symndx
;
7068 struct elf_link_hash_entry
*h
;
7070 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7071 sym_hashes
= elf_sym_hashes (abfd
);
7072 local_got_refcounts
= elf_local_got_refcounts (abfd
);
7074 relend
= relocs
+ sec
->reloc_count
;
7075 for (rel
= relocs
; rel
< relend
; rel
++)
7076 switch (ELF32_R_TYPE (rel
->r_info
))
7080 case R_MIPS_CALL_HI16
:
7081 case R_MIPS_CALL_LO16
:
7082 case R_MIPS_GOT_HI16
:
7083 case R_MIPS_GOT_LO16
:
7084 /* ??? It would seem that the existing MIPS code does no sort
7085 of reference counting or whatnot on its GOT and PLT entries,
7086 so it is not possible to garbage collect them at this time. */
7098 /* Adjust a symbol defined by a dynamic object and referenced by a
7099 regular object. The current definition is in some section of the
7100 dynamic object, but we're not including those sections. We have to
7101 change the definition to something the rest of the link can
7105 mips_elf_adjust_dynamic_symbol (info
, h
)
7106 struct bfd_link_info
*info
;
7107 struct elf_link_hash_entry
*h
;
7110 struct mips_elf_link_hash_entry
*hmips
;
7113 dynobj
= elf_hash_table (info
)->dynobj
;
7115 /* Make sure we know what is going on here. */
7116 BFD_ASSERT (dynobj
!= NULL
7117 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
7118 || h
->weakdef
!= NULL
7119 || ((h
->elf_link_hash_flags
7120 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
7121 && (h
->elf_link_hash_flags
7122 & ELF_LINK_HASH_REF_REGULAR
) != 0
7123 && (h
->elf_link_hash_flags
7124 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
7126 /* If this symbol is defined in a dynamic object, we need to copy
7127 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
7129 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7130 if (! info
->relocateable
7131 && hmips
->mips_32_relocs
!= 0
7132 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
7134 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7135 BFD_ASSERT (s
!= NULL
);
7137 if (s
->_raw_size
== 0)
7139 /* Make room for a null element. */
7140 s
->_raw_size
+= sizeof (Elf32_External_Rel
);
7143 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
7146 /* For a function, create a stub, if needed. */
7147 if (h
->type
== STT_FUNC
7148 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
7150 if (! elf_hash_table (info
)->dynamic_sections_created
)
7153 /* If this symbol is not defined in a regular file, then set
7154 the symbol to the stub location. This is required to make
7155 function pointers compare as equal between the normal
7156 executable and the shared library. */
7157 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
7159 /* We need .stub section. */
7160 s
= bfd_get_section_by_name (dynobj
,
7161 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
7162 BFD_ASSERT (s
!= NULL
);
7164 h
->root
.u
.def
.section
= s
;
7165 h
->root
.u
.def
.value
= s
->_raw_size
;
7167 /* XXX Write this stub address somewhere. */
7168 h
->plt
.offset
= s
->_raw_size
;
7170 /* Make room for this stub code. */
7171 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
7173 /* The last half word of the stub will be filled with the index
7174 of this symbol in .dynsym section. */
7179 /* If this is a weak symbol, and there is a real definition, the
7180 processor independent code will have arranged for us to see the
7181 real definition first, and we can just use the same value. */
7182 if (h
->weakdef
!= NULL
)
7184 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
7185 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
7186 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
7187 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
7191 /* This is a reference to a symbol defined by a dynamic object which
7192 is not a function. */
7197 /* This function is called after all the input files have been read,
7198 and the input sections have been assigned to output sections. We
7199 check for any mips16 stub sections that we can discard. */
7201 static boolean mips_elf_check_mips16_stubs
7202 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
7205 mips_elf_always_size_sections (output_bfd
, info
)
7207 struct bfd_link_info
*info
;
7211 /* The .reginfo section has a fixed size. */
7212 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
7214 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
7216 if (info
->relocateable
7217 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
7220 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
7221 mips_elf_check_mips16_stubs
,
7227 /* Check the mips16 stubs for a particular symbol, and see if we can
7232 mips_elf_check_mips16_stubs (h
, data
)
7233 struct mips_elf_link_hash_entry
*h
;
7236 if (h
->fn_stub
!= NULL
7237 && ! h
->need_fn_stub
)
7239 /* We don't need the fn_stub; the only references to this symbol
7240 are 16 bit calls. Clobber the size to 0 to prevent it from
7241 being included in the link. */
7242 h
->fn_stub
->_raw_size
= 0;
7243 h
->fn_stub
->_cooked_size
= 0;
7244 h
->fn_stub
->flags
&= ~ SEC_RELOC
;
7245 h
->fn_stub
->reloc_count
= 0;
7246 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
7249 if (h
->call_stub
!= NULL
7250 && h
->root
.other
== STO_MIPS16
)
7252 /* We don't need the call_stub; this is a 16 bit function, so
7253 calls from other 16 bit functions are OK. Clobber the size
7254 to 0 to prevent it from being included in the link. */
7255 h
->call_stub
->_raw_size
= 0;
7256 h
->call_stub
->_cooked_size
= 0;
7257 h
->call_stub
->flags
&= ~ SEC_RELOC
;
7258 h
->call_stub
->reloc_count
= 0;
7259 h
->call_stub
->flags
|= SEC_EXCLUDE
;
7262 if (h
->call_fp_stub
!= NULL
7263 && h
->root
.other
== STO_MIPS16
)
7265 /* We don't need the call_stub; this is a 16 bit function, so
7266 calls from other 16 bit functions are OK. Clobber the size
7267 to 0 to prevent it from being included in the link. */
7268 h
->call_fp_stub
->_raw_size
= 0;
7269 h
->call_fp_stub
->_cooked_size
= 0;
7270 h
->call_fp_stub
->flags
&= ~ SEC_RELOC
;
7271 h
->call_fp_stub
->reloc_count
= 0;
7272 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
7278 /* Set the sizes of the dynamic sections. */
7281 mips_elf_size_dynamic_sections (output_bfd
, info
)
7283 struct bfd_link_info
*info
;
7288 struct mips_got_info
*g
;
7290 dynobj
= elf_hash_table (info
)->dynobj
;
7291 BFD_ASSERT (dynobj
!= NULL
);
7293 if (elf_hash_table (info
)->dynamic_sections_created
)
7295 /* Set the contents of the .interp section to the interpreter. */
7298 s
= bfd_get_section_by_name (dynobj
, ".interp");
7299 BFD_ASSERT (s
!= NULL
);
7301 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
7303 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
7307 /* The check_relocs and adjust_dynamic_symbol entry points have
7308 determined the sizes of the various dynamic sections. Allocate
7311 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
7316 /* It's OK to base decisions on the section name, because none
7317 of the dynobj section names depend upon the input files. */
7318 name
= bfd_get_section_name (dynobj
, s
);
7320 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
7325 if (strncmp (name
, ".rel", 4) == 0)
7327 if (s
->_raw_size
== 0)
7329 /* We only strip the section if the output section name
7330 has the same name. Otherwise, there might be several
7331 input sections for this output section. FIXME: This
7332 code is probably not needed these days anyhow, since
7333 the linker now does not create empty output sections. */
7334 if (s
->output_section
!= NULL
7336 bfd_get_section_name (s
->output_section
->owner
,
7337 s
->output_section
)) == 0)
7342 const char *outname
;
7345 /* If this relocation section applies to a read only
7346 section, then we probably need a DT_TEXTREL entry.
7347 If the relocation section is .rel.dyn, we always
7348 assert a DT_TEXTREL entry rather than testing whether
7349 there exists a relocation to a read only section or
7351 outname
= bfd_get_section_name (output_bfd
,
7353 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
7355 && (target
->flags
& SEC_READONLY
) != 0
7356 && (target
->flags
& SEC_ALLOC
) != 0)
7357 || strcmp (outname
, ".rel.dyn") == 0)
7360 /* We use the reloc_count field as a counter if we need
7361 to copy relocs into the output file. */
7362 if (strcmp (name
, ".rel.dyn") != 0)
7366 else if (strncmp (name
, ".got", 4) == 0)
7369 bfd_size_type loadable_size
= 0;
7370 bfd_size_type local_gotno
;
7373 BFD_ASSERT (elf_section_data (s
) != NULL
);
7374 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
7375 BFD_ASSERT (g
!= NULL
);
7377 /* Calculate the total loadable size of the output. That
7378 will give us the maximum number of GOT_PAGE entries
7380 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
7382 asection
*subsection
;
7384 for (subsection
= sub
->sections
;
7386 subsection
= subsection
->next
)
7388 if ((subsection
->flags
& SEC_ALLOC
) == 0)
7390 loadable_size
+= (subsection
->_raw_size
+ 0xf) & ~0xf;
7393 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
7395 /* Assume there are two loadable segments consisting of
7396 contiguous sections. Is 5 enough? */
7397 local_gotno
= (loadable_size
>> 16) + 5;
7398 g
->local_gotno
+= local_gotno
;
7399 s
->_raw_size
+= local_gotno
* 4;
7401 /* There has to be a global GOT entry for every symbol with
7402 a dynamic symbol table index of DT_MIPS_GOTSYM or
7403 higher. Therefore, it make sense to put those symbols
7404 that need GOT entries at the end of the symbol table. We
7406 if (!mips_elf_sort_hash_table (info
))
7409 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
7410 s
->_raw_size
+= i
* 4;
7412 else if (strcmp (name
, MIPS_ELF_STUB_SECTION_NAME (output_bfd
)) == 0)
7414 /* Irix rld assumes that the function stub isn't at the end
7415 of .text section. So put a dummy. XXX */
7416 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
7418 else if (! info
->shared
7419 && ! mips_elf_hash_table (info
)->use_rld_obj_head
7420 && strncmp (name
, ".rld_map", 8) == 0)
7422 /* We add a room for __rld_map. It will be filled in by the
7423 rtld to contain a pointer to the _r_debug structure. */
7426 else if (SGI_COMPAT (output_bfd
)
7427 && strncmp (name
, ".compact_rel", 12) == 0)
7428 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
7429 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
))
7431 s
->_raw_size
= (sizeof (Elf32_External_Msym
)
7432 * (elf_hash_table (info
)->dynsymcount
7433 + bfd_count_sections (output_bfd
)));
7434 else if (strncmp (name
, ".init", 5) != 0)
7436 /* It's not one of our sections, so don't allocate space. */
7442 _bfd_strip_section_from_output (s
);
7446 /* Allocate memory for the section contents. */
7447 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
7448 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
7450 bfd_set_error (bfd_error_no_memory
);
7455 if (elf_hash_table (info
)->dynamic_sections_created
)
7457 /* Add some entries to the .dynamic section. We fill in the
7458 values later, in elf_mips_finish_dynamic_sections, but we
7459 must add the entries now so that we get the correct size for
7460 the .dynamic section. The DT_DEBUG entry is filled in by the
7461 dynamic linker and used by the debugger. */
7464 if (SGI_COMPAT (output_bfd
))
7466 /* SGI object has the equivalence of DT_DEBUG in the
7467 DT_MIPS_RLD_MAP entry. */
7468 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
7472 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
7478 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
7482 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
7485 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
7487 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
7490 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
7493 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
7497 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
7500 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
7503 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
7505 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
7508 s
= bfd_get_section_by_name (dynobj
, ".liblist");
7509 BFD_ASSERT (s
!= NULL
);
7511 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
7515 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
7518 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
7522 /* Time stamps in executable files are a bad idea. */
7523 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
7528 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
7533 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
7537 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
7540 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
7543 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
7546 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
7549 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
7552 if (IRIX_COMPAT (dynobj
) == ict_irix5
7553 && ! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
7556 if (IRIX_COMPAT (dynobj
) == ict_irix6
7557 && (bfd_get_section_by_name
7558 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
7559 && !bfd_elf32_add_dynamic_entry (info
, DT_MIPS_OPTIONS
, 0))
7562 if (bfd_get_section_by_name (dynobj
,
7563 MIPS_ELF_MSYM_SECTION_NAME (dynobj
))
7564 && !bfd_elf32_add_dynamic_entry (info
, DT_MIPS_MSYM
, 0))
7568 /* If we use dynamic linking, we generate a section symbol for each
7569 output section. These are local symbols, which means that they
7570 must come first in the dynamic symbol table.
7571 That means we must increment the dynamic symbol index of every
7572 other dynamic symbol. */
7575 struct mips_got_info
*g
;
7578 if (elf_hash_table (info
)->dynamic_sections_created
)
7581 /* We no longer try to restrict the set of sections which get
7582 dynamic symbol table entries, since it fails if we have
7583 other random sections which need dynamic relocations. */
7584 const char * const *namep
;
7585 bfd_size_type strindex
;
7586 struct bfd_strtab_hash
*dynstr
;
7588 if (SGI_COMPAT (output_bfd
))
7590 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
7591 elf_link_hash_traverse (elf_hash_table (info
),
7592 mips_elf_adjust_dynindx
,
7594 elf_hash_table (info
)->dynsymcount
+= c
;
7596 dynstr
= elf_hash_table (info
)->dynstr
;
7597 BFD_ASSERT (dynstr
!= NULL
);
7599 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
7603 s
= bfd_get_section_by_name (output_bfd
, *namep
);
7605 elf_section_data (s
)->dynindx
= i
;
7607 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
7608 if (strindex
== (bfd_size_type
) -1)
7611 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
7617 c
= bfd_count_sections (output_bfd
);
7618 elf_link_hash_traverse (elf_hash_table (info
),
7619 _bfd_elf_link_adjust_dynindx
,
7621 elf_hash_table (info
)->dynsymcount
+= c
;
7623 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
7625 elf_section_data (s
)->dynindx
= i
;
7626 /* These symbols will have no names, so we don't need to
7627 fiddle with dynstr_index. */
7636 /* If NAME is one of the special IRIX6 symbols defined by the linker,
7637 adjust it appropriately now. */
7640 mips_elf_irix6_finish_dynamic_symbol (abfd
, name
, sym
)
7643 Elf_Internal_Sym
*sym
;
7645 /* The linker script takes care of providing names and values for
7646 these, but we must place them into the right sections. */
7647 static const char* const text_section_symbols
[] = {
7650 "__dso_displacement",
7652 "__program_header_table",
7656 static const char* const data_section_symbols
[] = {
7664 const char* const *p
;
7667 for (i
= 0; i
< 2; ++i
)
7668 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
7671 if (strcmp (*p
, name
) == 0)
7673 /* All of these symbols are given type STT_SECTION by the
7675 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7677 /* The IRIX linker puts these symbols in special sections. */
7679 sym
->st_shndx
= SHN_MIPS_TEXT
;
7681 sym
->st_shndx
= SHN_MIPS_DATA
;
7687 /* Finish up dynamic symbol handling. We set the contents of various
7688 dynamic sections here. */
7691 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
7693 struct bfd_link_info
*info
;
7694 struct elf_link_hash_entry
*h
;
7695 Elf_Internal_Sym
*sym
;
7701 struct mips_got_info
*g
;
7703 struct mips_elf_link_hash_entry
*mh
;
7705 dynobj
= elf_hash_table (info
)->dynobj
;
7706 gval
= sym
->st_value
;
7707 mh
= (struct mips_elf_link_hash_entry
*) h
;
7709 if (h
->plt
.offset
!= (bfd_vma
) -1)
7713 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
7715 /* This symbol has a stub. Set it up. */
7717 BFD_ASSERT (h
->dynindx
!= -1);
7719 s
= bfd_get_section_by_name (dynobj
,
7720 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
7721 BFD_ASSERT (s
!= NULL
);
7723 /* Fill the stub. */
7725 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
7727 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
7730 /* FIXME: Can h->dynindex be more than 64K? */
7731 if (h
->dynindx
& 0xffff0000)
7734 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
7736 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
7738 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
7739 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
7741 /* Mark the symbol as undefined. plt.offset != -1 occurs
7742 only for the referenced symbol. */
7743 sym
->st_shndx
= SHN_UNDEF
;
7745 /* The run-time linker uses the st_value field of the symbol
7746 to reset the global offset table entry for this external
7747 to its stub address when unlinking a shared object. */
7748 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
7749 sym
->st_value
= gval
;
7752 BFD_ASSERT (h
->dynindx
!= -1);
7754 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7755 BFD_ASSERT (sgot
!= NULL
);
7756 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7757 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7758 BFD_ASSERT (g
!= NULL
);
7760 /* Run through the global symbol table, creating GOT entries for all
7761 the symbols that need them. */
7762 if (h
->dynindx
>= g
->global_gotsym
->dynindx
)
7768 value
= sym
->st_value
;
7770 /* For an entity defined in a shared object, this will be
7771 NULL. (For functions in shared objects for
7772 which we have created stubs, ST_VALUE will be non-NULL.
7773 That's because such the functions are now no longer defined
7774 in a shared object.) */
7775 value
= h
->root
.u
.def
.value
;
7777 offset
= mips_elf_global_got_index (dynobj
, h
);
7778 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ offset
);
7781 /* Create a .msym entry, if appropriate. */
7782 smsym
= bfd_get_section_by_name (dynobj
,
7783 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
7786 Elf32_Internal_Msym msym
;
7788 msym
.ms_hash_value
= bfd_elf_hash (h
->root
.root
.string
);
7789 /* It is undocumented what the `1' indicates, but IRIX6 uses
7791 msym
.ms_info
= ELF32_MS_INFO (mh
->min_dyn_reloc_index
, 1);
7792 bfd_mips_elf_swap_msym_out
7794 ((Elf32_External_Msym
*) smsym
->contents
) + h
->dynindx
);
7797 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7798 name
= h
->root
.root
.string
;
7799 if (strcmp (name
, "_DYNAMIC") == 0
7800 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
7801 sym
->st_shndx
= SHN_ABS
;
7802 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
7804 sym
->st_shndx
= SHN_ABS
;
7805 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7808 else if (SGI_COMPAT (output_bfd
))
7810 if (strcmp (name
, "_gp_disp") == 0)
7812 sym
->st_shndx
= SHN_ABS
;
7813 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7814 sym
->st_value
= elf_gp (output_bfd
);
7816 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
7817 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
7819 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7820 sym
->st_other
= STO_PROTECTED
;
7822 sym
->st_shndx
= SHN_MIPS_DATA
;
7824 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
7826 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7827 sym
->st_other
= STO_PROTECTED
;
7828 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
7829 sym
->st_shndx
= SHN_ABS
;
7831 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
7833 if (h
->type
== STT_FUNC
)
7834 sym
->st_shndx
= SHN_MIPS_TEXT
;
7835 else if (h
->type
== STT_OBJECT
)
7836 sym
->st_shndx
= SHN_MIPS_DATA
;
7840 /* Handle the IRIX6-specific symbols. */
7841 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
7842 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
7844 if (SGI_COMPAT (output_bfd
)
7847 if (! mips_elf_hash_table (info
)->use_rld_obj_head
7848 && strcmp (name
, "__rld_map") == 0)
7850 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7851 BFD_ASSERT (s
!= NULL
);
7852 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
7853 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
7854 if (mips_elf_hash_table (info
)->rld_value
== 0)
7855 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7857 else if (mips_elf_hash_table (info
)->use_rld_obj_head
7858 && strcmp (name
, "__rld_obj_head") == 0)
7860 /* IRIX6 does not use a .rld_map section. */
7861 if (IRIX_COMPAT (output_bfd
) == ict_irix5
)
7862 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
7864 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7868 /* If this is a mips16 symbol, force the value to be even. */
7869 if (sym
->st_other
== STO_MIPS16
7870 && (sym
->st_value
& 1) != 0)
7876 /* Finish up the dynamic sections. */
7879 mips_elf_finish_dynamic_sections (output_bfd
, info
)
7881 struct bfd_link_info
*info
;
7886 struct mips_got_info
*g
;
7888 dynobj
= elf_hash_table (info
)->dynobj
;
7890 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
7892 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7897 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7898 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7899 BFD_ASSERT (g
!= NULL
);
7902 if (elf_hash_table (info
)->dynamic_sections_created
)
7904 Elf32_External_Dyn
*dyncon
, *dynconend
;
7906 BFD_ASSERT (sdyn
!= NULL
);
7907 BFD_ASSERT (g
!= NULL
);
7909 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7910 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
7911 for (; dyncon
< dynconend
; dyncon
++)
7913 Elf_Internal_Dyn dyn
;
7918 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
7926 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7927 BFD_ASSERT (s
!= NULL
);
7928 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
7929 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7933 /* Rewrite DT_STRSZ. */
7935 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
7936 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7942 case DT_MIPS_CONFLICT
:
7945 case DT_MIPS_LIBLIST
:
7948 s
= bfd_get_section_by_name (output_bfd
, name
);
7949 BFD_ASSERT (s
!= NULL
);
7950 dyn
.d_un
.d_ptr
= s
->vma
;
7951 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7954 case DT_MIPS_RLD_VERSION
:
7955 dyn
.d_un
.d_val
= 1; /* XXX */
7956 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7960 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
7961 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7964 case DT_MIPS_CONFLICTNO
:
7966 elemsize
= sizeof (Elf32_Conflict
);
7969 case DT_MIPS_LIBLISTNO
:
7971 elemsize
= sizeof (Elf32_Lib
);
7973 s
= bfd_get_section_by_name (output_bfd
, name
);
7976 if (s
->_cooked_size
!= 0)
7977 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7979 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7984 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7987 case DT_MIPS_TIME_STAMP
:
7988 time ((time_t *) &dyn
.d_un
.d_val
);
7989 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7992 case DT_MIPS_ICHECKSUM
:
7996 case DT_MIPS_IVERSION
:
8000 case DT_MIPS_BASE_ADDRESS
:
8001 s
= output_bfd
->sections
;
8002 BFD_ASSERT (s
!= NULL
);
8003 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
8004 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8007 case DT_MIPS_LOCAL_GOTNO
:
8008 dyn
.d_un
.d_val
= g
->local_gotno
;
8009 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8012 case DT_MIPS_SYMTABNO
:
8014 elemsize
= sizeof (Elf32_External_Sym
);
8015 s
= bfd_get_section_by_name (output_bfd
, name
);
8016 BFD_ASSERT (s
!= NULL
);
8018 if (s
->_cooked_size
!= 0)
8019 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
8021 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
8022 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8025 case DT_MIPS_UNREFEXTNO
:
8026 /* The index into the dynamic symbol table which is the
8027 entry of the first external symbol that is not
8028 referenced within the same object. */
8029 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
8030 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8033 case DT_MIPS_GOTSYM
:
8034 dyn
.d_un
.d_val
= g
->global_gotsym
->dynindx
;
8035 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8038 case DT_MIPS_HIPAGENO
:
8039 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
8040 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8043 case DT_MIPS_RLD_MAP
:
8044 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
8045 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8048 case DT_MIPS_OPTIONS
:
8049 s
= (bfd_get_section_by_name
8050 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
8051 dyn
.d_un
.d_ptr
= s
->vma
;
8052 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8056 s
= (bfd_get_section_by_name
8057 (output_bfd
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
)));
8058 dyn
.d_un
.d_ptr
= s
->vma
;
8059 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8065 /* The first entry of the global offset table will be filled at
8066 runtime. The second entry will be used by some runtime loaders.
8067 This isn't the case of Irix rld. */
8068 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
8070 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
8071 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
8075 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
8081 Elf_Internal_Sym sym
;
8082 Elf32_compact_rel cpt
;
8084 /* Set up the section symbols for the output sections. SGI sets
8085 the STT_NOTYPE attribute for these symbols. Should we do so? */
8087 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
8088 smsym
= bfd_get_section_by_name (dynobj
,
8089 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
8090 if (sdynsym
!= NULL
)
8094 const char * const * namep
= mips_elf_dynsym_sec_names
;
8099 /* We no longer try to restrict the set of sections which get
8100 dynamic symbol table entries, since it fails if we have
8101 other random sections which need dynamic relocations. */
8102 if (SGI_COMPAT (output_bfd
))
8106 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
8112 while ((name
= *namep
++) != NULL
)
8114 s
= bfd_get_section_by_name (output_bfd
, name
);
8117 sym
.st_value
= s
->vma
;
8118 dindx
= elf_section_data (s
)->dynindx
;
8119 last
= s
->vma
+ s
->_raw_size
;
8123 sym
.st_value
= last
;
8127 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
8132 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
8134 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
8135 (((Elf32_External_Sym
*)
8140 /* Set the sh_info field of the output .dynsym section to
8141 the index of the first global symbol. */
8142 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
8143 SIZEOF_MIPS_DYNSYM_SECNAMES
;
8148 Elf32_Internal_Msym msym
;
8152 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
8155 msym
.ms_hash_value
= 0;
8156 msym
.ms_info
= ELF32_MS_INFO (0, 1);
8158 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
8163 sym
.st_value
= s
->vma
;
8165 indx
= elf_section_data (s
)->this_idx
;
8166 BFD_ASSERT (indx
> 0);
8167 sym
.st_shndx
= indx
;
8169 dynindx
= elf_section_data (s
)->dynindx
;
8171 bfd_elf32_swap_symbol_out
8173 (((Elf32_External_Sym
*) sdynsym
->contents
)
8177 bfd_mips_elf_swap_msym_out
8179 (((Elf32_External_Msym
*) smsym
->contents
)
8183 /* Set the sh_info field of the output .dynsym section to
8184 the index of the first global symbol. */
8185 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
8186 bfd_count_sections (output_bfd
) + 1;
8190 if (SGI_COMPAT (output_bfd
))
8192 /* Write .compact_rel section out. */
8193 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
8197 cpt
.num
= s
->reloc_count
;
8199 cpt
.offset
= (s
->output_section
->filepos
8200 + sizeof (Elf32_External_compact_rel
));
8203 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
8204 ((Elf32_External_compact_rel
*)
8207 /* Clean up a dummy stub function entry in .text. */
8208 s
= bfd_get_section_by_name (dynobj
,
8209 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
8212 file_ptr dummy_offset
;
8214 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
8215 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
8216 memset (s
->contents
+ dummy_offset
, 0,
8217 MIPS_FUNCTION_STUB_SIZE
);
8222 /* Clean up a first relocation in .rel.dyn. */
8223 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
8224 if (s
!= NULL
&& s
->_raw_size
> 0)
8225 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
8231 /* This is almost identical to bfd_generic_get_... except that some
8232 MIPS relocations need to be handled specially. Sigh. */
8235 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
8236 relocateable
, symbols
)
8238 struct bfd_link_info
*link_info
;
8239 struct bfd_link_order
*link_order
;
8241 boolean relocateable
;
8244 /* Get enough memory to hold the stuff */
8245 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
8246 asection
*input_section
= link_order
->u
.indirect
.section
;
8248 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
8249 arelent
**reloc_vector
= NULL
;
8255 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
8256 if (reloc_vector
== NULL
&& reloc_size
!= 0)
8259 /* read in the section */
8260 if (!bfd_get_section_contents (input_bfd
,
8264 input_section
->_raw_size
))
8267 /* We're not relaxing the section, so just copy the size info */
8268 input_section
->_cooked_size
= input_section
->_raw_size
;
8269 input_section
->reloc_done
= true;
8271 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
8275 if (reloc_count
< 0)
8278 if (reloc_count
> 0)
8283 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
8286 struct bfd_hash_entry
*h
;
8287 struct bfd_link_hash_entry
*lh
;
8288 /* Skip all this stuff if we aren't mixing formats. */
8289 if (abfd
&& input_bfd
8290 && abfd
->xvec
== input_bfd
->xvec
)
8294 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
8295 lh
= (struct bfd_link_hash_entry
*) h
;
8302 case bfd_link_hash_undefined
:
8303 case bfd_link_hash_undefweak
:
8304 case bfd_link_hash_common
:
8307 case bfd_link_hash_defined
:
8308 case bfd_link_hash_defweak
:
8310 gp
= lh
->u
.def
.value
;
8312 case bfd_link_hash_indirect
:
8313 case bfd_link_hash_warning
:
8315 /* @@FIXME ignoring warning for now */
8317 case bfd_link_hash_new
:
8326 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
8329 char *error_message
= (char *) NULL
;
8330 bfd_reloc_status_type r
;
8332 /* Specific to MIPS: Deal with relocation types that require
8333 knowing the gp of the output bfd. */
8334 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
8335 if (bfd_is_abs_section (sym
->section
) && abfd
)
8337 /* The special_function wouldn't get called anyways. */
8341 /* The gp isn't there; let the special function code
8342 fall over on its own. */
8344 else if ((*parent
)->howto
->special_function
8345 == _bfd_mips_elf_gprel16_reloc
)
8347 /* bypass special_function call */
8348 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
8349 relocateable
, (PTR
) data
, gp
);
8350 goto skip_bfd_perform_relocation
;
8352 /* end mips specific stuff */
8354 r
= bfd_perform_relocation (input_bfd
,
8358 relocateable
? abfd
: (bfd
*) NULL
,
8360 skip_bfd_perform_relocation
:
8364 asection
*os
= input_section
->output_section
;
8366 /* A partial link, so keep the relocs */
8367 os
->orelocation
[os
->reloc_count
] = *parent
;
8371 if (r
!= bfd_reloc_ok
)
8375 case bfd_reloc_undefined
:
8376 if (!((*link_info
->callbacks
->undefined_symbol
)
8377 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
8378 input_bfd
, input_section
, (*parent
)->address
)))
8381 case bfd_reloc_dangerous
:
8382 BFD_ASSERT (error_message
!= (char *) NULL
);
8383 if (!((*link_info
->callbacks
->reloc_dangerous
)
8384 (link_info
, error_message
, input_bfd
, input_section
,
8385 (*parent
)->address
)))
8388 case bfd_reloc_overflow
:
8389 if (!((*link_info
->callbacks
->reloc_overflow
)
8390 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
8391 (*parent
)->howto
->name
, (*parent
)->addend
,
8392 input_bfd
, input_section
, (*parent
)->address
)))
8395 case bfd_reloc_outofrange
:
8404 if (reloc_vector
!= NULL
)
8405 free (reloc_vector
);
8409 if (reloc_vector
!= NULL
)
8410 free (reloc_vector
);
8413 #define bfd_elf32_bfd_get_relocated_section_contents \
8414 elf32_mips_get_relocated_section_contents
8416 /* ECOFF swapping routines. These are used when dealing with the
8417 .mdebug section, which is in the ECOFF debugging format. */
8418 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
8420 /* Symbol table magic number. */
8422 /* Alignment of debugging information. E.g., 4. */
8424 /* Sizes of external symbolic information. */
8425 sizeof (struct hdr_ext
),
8426 sizeof (struct dnr_ext
),
8427 sizeof (struct pdr_ext
),
8428 sizeof (struct sym_ext
),
8429 sizeof (struct opt_ext
),
8430 sizeof (struct fdr_ext
),
8431 sizeof (struct rfd_ext
),
8432 sizeof (struct ext_ext
),
8433 /* Functions to swap in external symbolic data. */
8442 _bfd_ecoff_swap_tir_in
,
8443 _bfd_ecoff_swap_rndx_in
,
8444 /* Functions to swap out external symbolic data. */
8453 _bfd_ecoff_swap_tir_out
,
8454 _bfd_ecoff_swap_rndx_out
,
8455 /* Function to read in symbolic data. */
8456 _bfd_mips_elf_read_ecoff_info
8459 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
8460 #define TARGET_LITTLE_NAME "elf32-littlemips"
8461 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
8462 #define TARGET_BIG_NAME "elf32-bigmips"
8463 #define ELF_ARCH bfd_arch_mips
8464 #define ELF_MACHINE_CODE EM_MIPS
8466 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
8467 a value of 0x1000, and we are compatible. */
8468 #define ELF_MAXPAGESIZE 0x1000
8470 #define elf_backend_collect true
8471 #define elf_backend_type_change_ok true
8472 #define elf_backend_can_gc_sections true
8473 #define elf_info_to_howto mips_info_to_howto_rela
8474 #define elf_info_to_howto_rel mips_info_to_howto_rel
8475 #define elf_backend_sym_is_global mips_elf_sym_is_global
8476 #define elf_backend_object_p mips_elf32_object_p
8477 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
8478 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
8479 #define elf_backend_section_from_bfd_section \
8480 _bfd_mips_elf_section_from_bfd_section
8481 #define elf_backend_section_processing mips_elf32_section_processing
8482 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
8483 #define elf_backend_additional_program_headers \
8484 mips_elf_additional_program_headers
8485 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
8486 #define elf_backend_final_write_processing \
8487 _bfd_mips_elf_final_write_processing
8488 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
8490 #define bfd_elf32_bfd_is_local_label_name \
8491 mips_elf_is_local_label_name
8492 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
8493 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
8494 #define bfd_elf32_bfd_link_hash_table_create \
8495 mips_elf_link_hash_table_create
8496 #define bfd_elf32_bfd_final_link mips_elf_final_link
8497 #define bfd_elf32_bfd_copy_private_bfd_data \
8498 _bfd_mips_elf_copy_private_bfd_data
8499 #define bfd_elf32_bfd_merge_private_bfd_data \
8500 _bfd_mips_elf_merge_private_bfd_data
8501 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
8502 #define bfd_elf32_bfd_print_private_bfd_data \
8503 _bfd_mips_elf_print_private_bfd_data
8504 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
8505 #define elf_backend_create_dynamic_sections \
8506 mips_elf_create_dynamic_sections
8507 #define elf_backend_check_relocs mips_elf_check_relocs
8508 #define elf_backend_adjust_dynamic_symbol \
8509 mips_elf_adjust_dynamic_symbol
8510 #define elf_backend_always_size_sections \
8511 mips_elf_always_size_sections
8512 #define elf_backend_size_dynamic_sections \
8513 mips_elf_size_dynamic_sections
8514 #define elf_backend_relocate_section mips_elf_relocate_section
8515 #define elf_backend_link_output_symbol_hook \
8516 mips_elf_link_output_symbol_hook
8517 #define elf_backend_finish_dynamic_symbol \
8518 mips_elf_finish_dynamic_symbol
8519 #define elf_backend_finish_dynamic_sections \
8520 mips_elf_finish_dynamic_sections
8521 #define elf_backend_gc_mark_hook mips_elf_gc_mark_hook
8522 #define elf_backend_gc_sweep_hook mips_elf_gc_sweep_hook
8524 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
8525 #define elf_backend_plt_header_size 0
8527 #include "elf32-target.h"