1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 94, 95, 96, 97, 98, 99, 2000
3 Free Software Foundation, Inc.
5 Most of the information added by Ian Lance Taylor, Cygnus Support,
7 N32/64 ABI support added by Mark Mitchell, CodeSourcery, LLC.
8 <mark@codesourcery.com>
9 Traditional MIPS targets support added by Koundinya.K, Dansk Data
10 Elektronik & Operations Research Group. <kk@ddeorg.soft.net>
12 This file is part of BFD, the Binary File Descriptor library.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 /* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
29 different MIPS ELF from other targets. This matters when linking.
30 This file supports both, switching at runtime. */
40 /* Get the ECOFF swapping routines. */
42 #include "coff/symconst.h"
43 #include "coff/internal.h"
44 #include "coff/ecoff.h"
45 #include "coff/mips.h"
46 #define ECOFF_SIGNED_32
47 #include "ecoffswap.h"
49 /* This structure is used to hold .got information when linking. It
50 is stored in the tdata field of the bfd_elf_section_data structure. */
52 struct mips_got_info {
53 /* The global symbol in the GOT with the lowest index in the dynamic
55 struct elf_link_hash_entry *global_gotsym;
56 /* The number of global .got entries. */
57 unsigned int global_gotno;
58 /* The number of local .got entries. */
59 unsigned int local_gotno;
60 /* The number of local .got entries we have used. */
61 unsigned int assigned_gotno;
64 /* The MIPS ELF linker needs additional information for each symbol in
65 the global hash table. */
67 struct mips_elf_link_hash_entry {
68 struct elf_link_hash_entry root;
70 /* External symbol information. */
73 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
75 unsigned int possibly_dynamic_relocs;
77 /* The index of the first dynamic relocation (in the .rel.dyn
78 section) against this symbol. */
79 unsigned int min_dyn_reloc_index;
81 /* If there is a stub that 32 bit functions should use to call this
82 16 bit function, this points to the section containing the stub. */
85 /* Whether we need the fn_stub; this is set if this symbol appears
86 in any relocs other than a 16 bit call. */
89 /* If there is a stub that 16 bit functions should use to call this
90 32 bit function, this points to the section containing the stub. */
93 /* This is like the call_stub field, but it is used if the function
94 being called returns a floating point value. */
95 asection *call_fp_stub;
98 static bfd_reloc_status_type mips32_64bit_reloc
99 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
100 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
101 PARAMS ((bfd *, bfd_reloc_code_real_type));
102 static reloc_howto_type *mips_rtype_to_howto
103 PARAMS ((unsigned int));
104 static void mips_info_to_howto_rel
105 PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
106 static void mips_info_to_howto_rela
107 PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
108 static void bfd_mips_elf32_swap_gptab_in
109 PARAMS ((bfd *, const Elf32_External_gptab *, Elf32_gptab *));
110 static void bfd_mips_elf32_swap_gptab_out
111 PARAMS ((bfd *, const Elf32_gptab *, Elf32_External_gptab *));
113 static void bfd_mips_elf_swap_msym_in
114 PARAMS ((bfd *, const Elf32_External_Msym *, Elf32_Internal_Msym *));
116 static void bfd_mips_elf_swap_msym_out
117 PARAMS ((bfd *, const Elf32_Internal_Msym *, Elf32_External_Msym *));
118 static boolean mips_elf_sym_is_global PARAMS ((bfd *, asymbol *));
119 static boolean mips_elf_create_procedure_table
120 PARAMS ((PTR, bfd *, struct bfd_link_info *, asection *,
121 struct ecoff_debug_info *));
122 static INLINE int elf_mips_isa PARAMS ((flagword));
123 static INLINE int elf_mips_mach PARAMS ((flagword));
124 static INLINE char* elf_mips_abi_name PARAMS ((bfd *));
125 static boolean mips_elf_is_local_label_name
126 PARAMS ((bfd *, const char *));
127 static struct bfd_hash_entry *mips_elf_link_hash_newfunc
128 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
129 static int gptab_compare PARAMS ((const void *, const void *));
130 static bfd_reloc_status_type mips16_jump_reloc
131 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
132 static bfd_reloc_status_type mips16_gprel_reloc
133 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
134 static boolean mips_elf_create_compact_rel_section
135 PARAMS ((bfd *, struct bfd_link_info *));
136 static boolean mips_elf_create_got_section
137 PARAMS ((bfd *, struct bfd_link_info *));
138 static bfd_reloc_status_type mips_elf_final_gp
139 PARAMS ((bfd *, asymbol *, boolean, char **, bfd_vma *));
140 static bfd_byte *elf32_mips_get_relocated_section_contents
141 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
142 bfd_byte *, boolean, asymbol **));
143 static asection *mips_elf_create_msym_section
145 static void mips_elf_irix6_finish_dynamic_symbol
146 PARAMS ((bfd *, const char *, Elf_Internal_Sym *));
147 static bfd_vma mips_elf_sign_extend PARAMS ((bfd_vma, int));
148 static boolean mips_elf_overflow_p PARAMS ((bfd_vma, int));
149 static bfd_vma mips_elf_high PARAMS ((bfd_vma));
150 static bfd_vma mips_elf_higher PARAMS ((bfd_vma));
151 static bfd_vma mips_elf_highest PARAMS ((bfd_vma));
152 static bfd_vma mips_elf_global_got_index
153 PARAMS ((bfd *, struct elf_link_hash_entry *));
154 static bfd_vma mips_elf_local_got_index
155 PARAMS ((bfd *, struct bfd_link_info *, bfd_vma));
156 static bfd_vma mips_elf_got_offset_from_index
157 PARAMS ((bfd *, bfd *, bfd_vma));
158 static boolean mips_elf_record_global_got_symbol
159 PARAMS ((struct elf_link_hash_entry *, struct bfd_link_info *,
160 struct mips_got_info *));
161 static bfd_vma mips_elf_got_page
162 PARAMS ((bfd *, struct bfd_link_info *, bfd_vma, bfd_vma *));
163 static const Elf_Internal_Rela *mips_elf_next_relocation
164 PARAMS ((unsigned int, const Elf_Internal_Rela *,
165 const Elf_Internal_Rela *));
166 static bfd_reloc_status_type mips_elf_calculate_relocation
167 PARAMS ((bfd *, bfd *, asection *, struct bfd_link_info *,
168 const Elf_Internal_Rela *, bfd_vma, reloc_howto_type *,
169 Elf_Internal_Sym *, asection **, bfd_vma *, const char **,
171 static bfd_vma mips_elf_obtain_contents
172 PARAMS ((reloc_howto_type *, const Elf_Internal_Rela *, bfd *, bfd_byte *));
173 static boolean mips_elf_perform_relocation
174 PARAMS ((struct bfd_link_info *, reloc_howto_type *,
175 const Elf_Internal_Rela *, bfd_vma,
176 bfd *, asection *, bfd_byte *, boolean));
177 static boolean mips_elf_assign_gp PARAMS ((bfd *, bfd_vma *));
178 static boolean mips_elf_sort_hash_table_f
179 PARAMS ((struct mips_elf_link_hash_entry *, PTR));
180 static boolean mips_elf_sort_hash_table
181 PARAMS ((struct bfd_link_info *, unsigned long));
182 static asection * mips_elf_got_section PARAMS ((bfd *));
183 static struct mips_got_info *mips_elf_got_info
184 PARAMS ((bfd *, asection **));
185 static boolean mips_elf_local_relocation_p
186 PARAMS ((bfd *, const Elf_Internal_Rela *, asection **, boolean));
187 static bfd_vma mips_elf_create_local_got_entry
188 PARAMS ((bfd *, struct mips_got_info *, asection *, bfd_vma));
189 static bfd_vma mips_elf_got16_entry
190 PARAMS ((bfd *, struct bfd_link_info *, bfd_vma, boolean));
191 static boolean mips_elf_create_dynamic_relocation
192 PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Rela *,
193 struct mips_elf_link_hash_entry *, asection *,
194 bfd_vma, bfd_vma *, asection *, boolean local_p));
195 static void mips_elf_allocate_dynamic_relocations
196 PARAMS ((bfd *, unsigned int));
197 static boolean mips_elf_stub_section_p
198 PARAMS ((bfd *, asection *));
199 static int sort_dynamic_relocs
200 PARAMS ((const void *, const void *));
202 extern const bfd_target bfd_elf32_tradbigmips_vec;
204 /* The level of IRIX compatibility we're striving for. */
212 /* This will be used when we sort the dynamic relocation records. */
213 static bfd *reldyn_sorting_bfd;
215 /* Nonzero if ABFD is using the N32 ABI. */
217 #define ABI_N32_P(abfd) \
218 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
220 /* Nonzero if ABFD is using the 64-bit ABI. FIXME: This is never
222 #define ABI_64_P(abfd) \
223 ((elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS64) != 0)
225 /* Depending on the target vector we generate some version of Irix
226 executables or "normal" MIPS ELF ABI executables. */
228 #define IRIX_COMPAT(abfd) \
229 (abfd->xvec == &bfd_elf32_tradbigmips_vec ? ict_none : \
230 ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5))
232 /* Whether we are trying to be compatible with IRIX at all. */
234 #define SGI_COMPAT(abfd) \
235 (IRIX_COMPAT (abfd) != ict_none)
237 /* The name of the msym section. */
238 #define MIPS_ELF_MSYM_SECTION_NAME(abfd) ".msym"
240 /* The name of the srdata section. */
241 #define MIPS_ELF_SRDATA_SECTION_NAME(abfd) ".srdata"
243 /* The name of the options section. */
244 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
245 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.options" : ".options")
247 /* The name of the stub section. */
248 #define MIPS_ELF_STUB_SECTION_NAME(abfd) \
249 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.stubs" : ".stub")
251 /* The name of the dynamic relocation section. */
252 #define MIPS_ELF_REL_DYN_SECTION_NAME(abfd) ".rel.dyn"
254 /* The size of an external REL relocation. */
255 #define MIPS_ELF_REL_SIZE(abfd) \
256 (get_elf_backend_data (abfd)->s->sizeof_rel)
258 /* The size of an external dynamic table entry. */
259 #define MIPS_ELF_DYN_SIZE(abfd) \
260 (get_elf_backend_data (abfd)->s->sizeof_dyn)
262 /* The size of a GOT entry. */
263 #define MIPS_ELF_GOT_SIZE(abfd) \
264 (get_elf_backend_data (abfd)->s->arch_size / 8)
266 /* The size of a symbol-table entry. */
267 #define MIPS_ELF_SYM_SIZE(abfd) \
268 (get_elf_backend_data (abfd)->s->sizeof_sym)
270 /* The default alignment for sections, as a power of two. */
271 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
272 (get_elf_backend_data (abfd)->s->file_align == 8 ? 3 : 2)
274 /* Get word-sized data. */
275 #define MIPS_ELF_GET_WORD(abfd, ptr) \
276 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
278 /* Put out word-sized data. */
279 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
281 ? bfd_put_64 (abfd, val, ptr) \
282 : bfd_put_32 (abfd, val, ptr))
284 /* Add a dynamic symbol table-entry. */
286 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
287 (ABI_64_P (elf_hash_table (info)->dynobj) \
288 ? bfd_elf64_add_dynamic_entry (info, tag, val) \
289 : bfd_elf32_add_dynamic_entry (info, tag, val))
291 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
292 (ABI_64_P (elf_hash_table (info)->dynobj) \
293 ? (abort (), false) \
294 : bfd_elf32_add_dynamic_entry (info, tag, val))
297 /* The number of local .got entries we reserve. */
298 #define MIPS_RESERVED_GOTNO (2)
300 /* Instructions which appear in a stub. For some reason the stub is
301 slightly different on an SGI system. */
302 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
303 #define STUB_LW(abfd) \
306 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
307 : 0x8f998010) /* lw t9,0x8010(gp) */ \
308 : 0x8f998010) /* lw t9,0x8000(gp) */
309 #define STUB_MOVE(abfd) \
310 (SGI_COMPAT (abfd) ? 0x03e07825 : 0x03e07821) /* move t7,ra */
311 #define STUB_JALR 0x0320f809 /* jal t9 */
312 #define STUB_LI16(abfd) \
313 (SGI_COMPAT (abfd) ? 0x34180000 : 0x24180000) /* ori t8,zero,0 */
314 #define MIPS_FUNCTION_STUB_SIZE (16)
317 /* We no longer try to identify particular sections for the .dynsym
318 section. When we do, we wind up crashing if there are other random
319 sections with relocations. */
321 /* Names of sections which appear in the .dynsym section in an Irix 5
324 static const char * const mips_elf_dynsym_sec_names[] = {
336 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
337 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
339 /* The number of entries in mips_elf_dynsym_sec_names which go in the
342 #define MIPS_TEXT_DYNSYM_SECNO (3)
346 /* The names of the runtime procedure table symbols used on Irix 5. */
348 static const char * const mips_elf_dynsym_rtproc_names[] = {
350 "_procedure_string_table",
351 "_procedure_table_size",
355 /* These structures are used to generate the .compact_rel section on
359 unsigned long id1; /* Always one? */
360 unsigned long num; /* Number of compact relocation entries. */
361 unsigned long id2; /* Always two? */
362 unsigned long offset; /* The file offset of the first relocation. */
363 unsigned long reserved0; /* Zero? */
364 unsigned long reserved1; /* Zero? */
372 bfd_byte reserved0[4];
373 bfd_byte reserved1[4];
374 } Elf32_External_compact_rel;
377 unsigned int ctype : 1; /* 1: long 0: short format. See below. */
378 unsigned int rtype : 4; /* Relocation types. See below. */
379 unsigned int dist2to : 8;
380 unsigned int relvaddr : 19; /* (VADDR - vaddr of the previous entry)/ 4 */
381 unsigned long konst; /* KONST field. See below. */
382 unsigned long vaddr; /* VADDR to be relocated. */
386 unsigned int ctype : 1; /* 1: long 0: short format. See below. */
387 unsigned int rtype : 4; /* Relocation types. See below. */
388 unsigned int dist2to : 8;
389 unsigned int relvaddr : 19; /* (VADDR - vaddr of the previous entry)/ 4 */
390 unsigned long konst; /* KONST field. See below. */
397 } Elf32_External_crinfo;
402 } Elf32_External_crinfo2;
404 /* These are the constants used to swap the bitfields in a crinfo. */
406 #define CRINFO_CTYPE (0x1)
407 #define CRINFO_CTYPE_SH (31)
408 #define CRINFO_RTYPE (0xf)
409 #define CRINFO_RTYPE_SH (27)
410 #define CRINFO_DIST2TO (0xff)
411 #define CRINFO_DIST2TO_SH (19)
412 #define CRINFO_RELVADDR (0x7ffff)
413 #define CRINFO_RELVADDR_SH (0)
415 /* A compact relocation info has long (3 words) or short (2 words)
416 formats. A short format doesn't have VADDR field and relvaddr
417 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
418 #define CRF_MIPS_LONG 1
419 #define CRF_MIPS_SHORT 0
421 /* There are 4 types of compact relocation at least. The value KONST
422 has different meaning for each type:
425 CT_MIPS_REL32 Address in data
426 CT_MIPS_WORD Address in word (XXX)
427 CT_MIPS_GPHI_LO GP - vaddr
428 CT_MIPS_JMPAD Address to jump
431 #define CRT_MIPS_REL32 0xa
432 #define CRT_MIPS_WORD 0xb
433 #define CRT_MIPS_GPHI_LO 0xc
434 #define CRT_MIPS_JMPAD 0xd
436 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
437 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
438 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
439 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
441 static void bfd_elf32_swap_compact_rel_out
442 PARAMS ((bfd *, const Elf32_compact_rel *, Elf32_External_compact_rel *));
443 static void bfd_elf32_swap_crinfo_out
444 PARAMS ((bfd *, const Elf32_crinfo *, Elf32_External_crinfo *));
446 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
448 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
449 from smaller values. Start with zero, widen, *then* decrement. */
450 #define MINUS_ONE (((bfd_vma)0) - 1)
452 static reloc_howto_type elf_mips_howto_table[] = {
454 HOWTO (R_MIPS_NONE, /* type */
456 0, /* size (0 = byte, 1 = short, 2 = long) */
458 false, /* pc_relative */
460 complain_overflow_dont, /* complain_on_overflow */
461 bfd_elf_generic_reloc, /* special_function */
462 "R_MIPS_NONE", /* name */
463 false, /* partial_inplace */
466 false), /* pcrel_offset */
468 /* 16 bit relocation. */
469 HOWTO (R_MIPS_16, /* type */
471 1, /* size (0 = byte, 1 = short, 2 = long) */
473 false, /* pc_relative */
475 complain_overflow_bitfield, /* complain_on_overflow */
476 bfd_elf_generic_reloc, /* special_function */
477 "R_MIPS_16", /* name */
478 true, /* partial_inplace */
479 0xffff, /* src_mask */
480 0xffff, /* dst_mask */
481 false), /* pcrel_offset */
483 /* 32 bit relocation. */
484 HOWTO (R_MIPS_32, /* type */
486 2, /* size (0 = byte, 1 = short, 2 = long) */
488 false, /* pc_relative */
490 complain_overflow_bitfield, /* complain_on_overflow */
491 bfd_elf_generic_reloc, /* special_function */
492 "R_MIPS_32", /* name */
493 true, /* partial_inplace */
494 0xffffffff, /* src_mask */
495 0xffffffff, /* dst_mask */
496 false), /* pcrel_offset */
498 /* 32 bit symbol relative relocation. */
499 HOWTO (R_MIPS_REL32, /* type */
501 2, /* size (0 = byte, 1 = short, 2 = long) */
503 false, /* pc_relative */
505 complain_overflow_bitfield, /* complain_on_overflow */
506 bfd_elf_generic_reloc, /* special_function */
507 "R_MIPS_REL32", /* name */
508 true, /* partial_inplace */
509 0xffffffff, /* src_mask */
510 0xffffffff, /* dst_mask */
511 false), /* pcrel_offset */
513 /* 26 bit branch address. */
514 HOWTO (R_MIPS_26, /* type */
516 2, /* size (0 = byte, 1 = short, 2 = long) */
518 false, /* pc_relative */
520 complain_overflow_dont, /* complain_on_overflow */
521 /* This needs complex overflow
522 detection, because the upper four
523 bits must match the PC. */
524 bfd_elf_generic_reloc, /* special_function */
525 "R_MIPS_26", /* name */
526 true, /* partial_inplace */
527 0x3ffffff, /* src_mask */
528 0x3ffffff, /* dst_mask */
529 false), /* pcrel_offset */
531 /* High 16 bits of symbol value. */
532 HOWTO (R_MIPS_HI16, /* type */
534 2, /* size (0 = byte, 1 = short, 2 = long) */
536 false, /* pc_relative */
538 complain_overflow_dont, /* complain_on_overflow */
539 _bfd_mips_elf_hi16_reloc, /* special_function */
540 "R_MIPS_HI16", /* name */
541 true, /* partial_inplace */
542 0xffff, /* src_mask */
543 0xffff, /* dst_mask */
544 false), /* pcrel_offset */
546 /* Low 16 bits of symbol value. */
547 HOWTO (R_MIPS_LO16, /* type */
549 2, /* size (0 = byte, 1 = short, 2 = long) */
551 false, /* pc_relative */
553 complain_overflow_dont, /* complain_on_overflow */
554 _bfd_mips_elf_lo16_reloc, /* special_function */
555 "R_MIPS_LO16", /* name */
556 true, /* partial_inplace */
557 0xffff, /* src_mask */
558 0xffff, /* dst_mask */
559 false), /* pcrel_offset */
561 /* GP relative reference. */
562 HOWTO (R_MIPS_GPREL16, /* type */
564 2, /* size (0 = byte, 1 = short, 2 = long) */
566 false, /* pc_relative */
568 complain_overflow_signed, /* complain_on_overflow */
569 _bfd_mips_elf_gprel16_reloc, /* special_function */
570 "R_MIPS_GPREL16", /* name */
571 true, /* partial_inplace */
572 0xffff, /* src_mask */
573 0xffff, /* dst_mask */
574 false), /* pcrel_offset */
576 /* Reference to literal section. */
577 HOWTO (R_MIPS_LITERAL, /* type */
579 2, /* size (0 = byte, 1 = short, 2 = long) */
581 false, /* pc_relative */
583 complain_overflow_signed, /* complain_on_overflow */
584 _bfd_mips_elf_gprel16_reloc, /* special_function */
585 "R_MIPS_LITERAL", /* name */
586 true, /* partial_inplace */
587 0xffff, /* src_mask */
588 0xffff, /* dst_mask */
589 false), /* pcrel_offset */
591 /* Reference to global offset table. */
592 HOWTO (R_MIPS_GOT16, /* type */
594 2, /* size (0 = byte, 1 = short, 2 = long) */
596 false, /* pc_relative */
598 complain_overflow_signed, /* complain_on_overflow */
599 _bfd_mips_elf_got16_reloc, /* special_function */
600 "R_MIPS_GOT16", /* name */
601 false, /* partial_inplace */
602 0xffff, /* src_mask */
603 0xffff, /* dst_mask */
604 false), /* pcrel_offset */
606 /* 16 bit PC relative reference. */
607 HOWTO (R_MIPS_PC16, /* type */
609 2, /* size (0 = byte, 1 = short, 2 = long) */
611 true, /* pc_relative */
613 complain_overflow_signed, /* complain_on_overflow */
614 bfd_elf_generic_reloc, /* special_function */
615 "R_MIPS_PC16", /* name */
616 true, /* partial_inplace */
617 0xffff, /* src_mask */
618 0xffff, /* dst_mask */
619 true), /* pcrel_offset */
621 /* 16 bit call through global offset table. */
622 HOWTO (R_MIPS_CALL16, /* type */
624 2, /* size (0 = byte, 1 = short, 2 = long) */
626 false, /* pc_relative */
628 complain_overflow_signed, /* complain_on_overflow */
629 bfd_elf_generic_reloc, /* special_function */
630 "R_MIPS_CALL16", /* name */
631 false, /* partial_inplace */
632 0xffff, /* src_mask */
633 0xffff, /* dst_mask */
634 false), /* pcrel_offset */
636 /* 32 bit GP relative reference. */
637 HOWTO (R_MIPS_GPREL32, /* type */
639 2, /* size (0 = byte, 1 = short, 2 = long) */
641 false, /* pc_relative */
643 complain_overflow_bitfield, /* complain_on_overflow */
644 _bfd_mips_elf_gprel32_reloc, /* special_function */
645 "R_MIPS_GPREL32", /* name */
646 true, /* partial_inplace */
647 0xffffffff, /* src_mask */
648 0xffffffff, /* dst_mask */
649 false), /* pcrel_offset */
651 /* The remaining relocs are defined on Irix 5, although they are
652 not defined by the ABI. */
657 /* A 5 bit shift field. */
658 HOWTO (R_MIPS_SHIFT5, /* type */
660 2, /* size (0 = byte, 1 = short, 2 = long) */
662 false, /* pc_relative */
664 complain_overflow_bitfield, /* complain_on_overflow */
665 bfd_elf_generic_reloc, /* special_function */
666 "R_MIPS_SHIFT5", /* name */
667 true, /* partial_inplace */
668 0x000007c0, /* src_mask */
669 0x000007c0, /* dst_mask */
670 false), /* pcrel_offset */
672 /* A 6 bit shift field. */
673 /* FIXME: This is not handled correctly; a special function is
674 needed to put the most significant bit in the right place. */
675 HOWTO (R_MIPS_SHIFT6, /* type */
677 2, /* size (0 = byte, 1 = short, 2 = long) */
679 false, /* pc_relative */
681 complain_overflow_bitfield, /* complain_on_overflow */
682 bfd_elf_generic_reloc, /* special_function */
683 "R_MIPS_SHIFT6", /* name */
684 true, /* partial_inplace */
685 0x000007c4, /* src_mask */
686 0x000007c4, /* dst_mask */
687 false), /* pcrel_offset */
689 /* A 64 bit relocation. */
690 HOWTO (R_MIPS_64, /* type */
692 4, /* size (0 = byte, 1 = short, 2 = long) */
694 false, /* pc_relative */
696 complain_overflow_bitfield, /* complain_on_overflow */
697 mips32_64bit_reloc, /* special_function */
698 "R_MIPS_64", /* name */
699 true, /* partial_inplace */
700 MINUS_ONE, /* src_mask */
701 MINUS_ONE, /* dst_mask */
702 false), /* pcrel_offset */
704 /* Displacement in the global offset table. */
705 HOWTO (R_MIPS_GOT_DISP, /* type */
707 2, /* size (0 = byte, 1 = short, 2 = long) */
709 false, /* pc_relative */
711 complain_overflow_bitfield, /* complain_on_overflow */
712 bfd_elf_generic_reloc, /* special_function */
713 "R_MIPS_GOT_DISP", /* name */
714 true, /* partial_inplace */
715 0x0000ffff, /* src_mask */
716 0x0000ffff, /* dst_mask */
717 false), /* pcrel_offset */
719 /* Displacement to page pointer in the global offset table. */
720 HOWTO (R_MIPS_GOT_PAGE, /* type */
722 2, /* size (0 = byte, 1 = short, 2 = long) */
724 false, /* pc_relative */
726 complain_overflow_bitfield, /* complain_on_overflow */
727 bfd_elf_generic_reloc, /* special_function */
728 "R_MIPS_GOT_PAGE", /* name */
729 true, /* partial_inplace */
730 0x0000ffff, /* src_mask */
731 0x0000ffff, /* dst_mask */
732 false), /* pcrel_offset */
734 /* Offset from page pointer in the global offset table. */
735 HOWTO (R_MIPS_GOT_OFST, /* type */
737 2, /* size (0 = byte, 1 = short, 2 = long) */
739 false, /* pc_relative */
741 complain_overflow_bitfield, /* complain_on_overflow */
742 bfd_elf_generic_reloc, /* special_function */
743 "R_MIPS_GOT_OFST", /* name */
744 true, /* partial_inplace */
745 0x0000ffff, /* src_mask */
746 0x0000ffff, /* dst_mask */
747 false), /* pcrel_offset */
749 /* High 16 bits of displacement in global offset table. */
750 HOWTO (R_MIPS_GOT_HI16, /* type */
752 2, /* size (0 = byte, 1 = short, 2 = long) */
754 false, /* pc_relative */
756 complain_overflow_dont, /* complain_on_overflow */
757 bfd_elf_generic_reloc, /* special_function */
758 "R_MIPS_GOT_HI16", /* name */
759 true, /* partial_inplace */
760 0x0000ffff, /* src_mask */
761 0x0000ffff, /* dst_mask */
762 false), /* pcrel_offset */
764 /* Low 16 bits of displacement in global offset table. */
765 HOWTO (R_MIPS_GOT_LO16, /* type */
767 2, /* size (0 = byte, 1 = short, 2 = long) */
769 false, /* pc_relative */
771 complain_overflow_dont, /* complain_on_overflow */
772 bfd_elf_generic_reloc, /* special_function */
773 "R_MIPS_GOT_LO16", /* name */
774 true, /* partial_inplace */
775 0x0000ffff, /* src_mask */
776 0x0000ffff, /* dst_mask */
777 false), /* pcrel_offset */
779 /* 64 bit subtraction. Used in the N32 ABI. */
780 HOWTO (R_MIPS_SUB, /* type */
782 4, /* size (0 = byte, 1 = short, 2 = long) */
784 false, /* pc_relative */
786 complain_overflow_bitfield, /* complain_on_overflow */
787 bfd_elf_generic_reloc, /* special_function */
788 "R_MIPS_SUB", /* name */
789 true, /* partial_inplace */
790 MINUS_ONE, /* src_mask */
791 MINUS_ONE, /* dst_mask */
792 false), /* pcrel_offset */
794 /* Used to cause the linker to insert and delete instructions? */
795 EMPTY_HOWTO (R_MIPS_INSERT_A),
796 EMPTY_HOWTO (R_MIPS_INSERT_B),
797 EMPTY_HOWTO (R_MIPS_DELETE),
799 /* Get the higher value of a 64 bit addend. */
800 HOWTO (R_MIPS_HIGHER, /* 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_HIGHER", /* name */
809 true, /* partial_inplace */
811 0xffff, /* dst_mask */
812 false), /* pcrel_offset */
814 /* Get the highest value of a 64 bit addend. */
815 HOWTO (R_MIPS_HIGHEST, /* 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_HIGHEST", /* name */
824 true, /* partial_inplace */
826 0xffff, /* dst_mask */
827 false), /* pcrel_offset */
829 /* High 16 bits of displacement in global offset table. */
830 HOWTO (R_MIPS_CALL_HI16, /* type */
832 2, /* size (0 = byte, 1 = short, 2 = long) */
834 false, /* pc_relative */
836 complain_overflow_dont, /* complain_on_overflow */
837 bfd_elf_generic_reloc, /* special_function */
838 "R_MIPS_CALL_HI16", /* name */
839 true, /* partial_inplace */
840 0x0000ffff, /* src_mask */
841 0x0000ffff, /* dst_mask */
842 false), /* pcrel_offset */
844 /* Low 16 bits of displacement in global offset table. */
845 HOWTO (R_MIPS_CALL_LO16, /* type */
847 2, /* size (0 = byte, 1 = short, 2 = long) */
849 false, /* pc_relative */
851 complain_overflow_dont, /* complain_on_overflow */
852 bfd_elf_generic_reloc, /* special_function */
853 "R_MIPS_CALL_LO16", /* name */
854 true, /* partial_inplace */
855 0x0000ffff, /* src_mask */
856 0x0000ffff, /* dst_mask */
857 false), /* pcrel_offset */
859 /* Section displacement. */
860 HOWTO (R_MIPS_SCN_DISP, /* type */
862 2, /* size (0 = byte, 1 = short, 2 = long) */
864 false, /* pc_relative */
866 complain_overflow_dont, /* complain_on_overflow */
867 bfd_elf_generic_reloc, /* special_function */
868 "R_MIPS_SCN_DISP", /* name */
869 false, /* partial_inplace */
870 0xffffffff, /* src_mask */
871 0xffffffff, /* dst_mask */
872 false), /* pcrel_offset */
874 EMPTY_HOWTO (R_MIPS_REL16),
875 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
876 EMPTY_HOWTO (R_MIPS_PJUMP),
877 EMPTY_HOWTO (R_MIPS_RELGOT),
879 /* Protected jump conversion. This is an optimization hint. No
880 relocation is required for correctness. */
881 HOWTO (R_MIPS_JALR, /* type */
883 0, /* size (0 = byte, 1 = short, 2 = long) */
885 false, /* pc_relative */
887 complain_overflow_dont, /* complain_on_overflow */
888 bfd_elf_generic_reloc, /* special_function */
889 "R_MIPS_JALR", /* name */
890 false, /* partial_inplace */
891 0x00000000, /* src_mask */
892 0x00000000, /* dst_mask */
893 false), /* pcrel_offset */
896 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
897 is a hack to make the linker think that we need 64 bit values. */
898 static reloc_howto_type elf_mips_ctor64_howto =
899 HOWTO (R_MIPS_64, /* type */
901 4, /* size (0 = byte, 1 = short, 2 = long) */
903 false, /* pc_relative */
905 complain_overflow_signed, /* complain_on_overflow */
906 mips32_64bit_reloc, /* special_function */
907 "R_MIPS_64", /* name */
908 true, /* partial_inplace */
909 0xffffffff, /* src_mask */
910 0xffffffff, /* dst_mask */
911 false); /* pcrel_offset */
913 /* The reloc used for the mips16 jump instruction. */
914 static reloc_howto_type elf_mips16_jump_howto =
915 HOWTO (R_MIPS16_26, /* type */
917 2, /* size (0 = byte, 1 = short, 2 = long) */
919 false, /* pc_relative */
921 complain_overflow_dont, /* complain_on_overflow */
922 /* This needs complex overflow
923 detection, because the upper four
924 bits must match the PC. */
925 mips16_jump_reloc, /* special_function */
926 "R_MIPS16_26", /* name */
927 true, /* partial_inplace */
928 0x3ffffff, /* src_mask */
929 0x3ffffff, /* dst_mask */
930 false); /* pcrel_offset */
932 /* The reloc used for the mips16 gprel instruction. */
933 static reloc_howto_type elf_mips16_gprel_howto =
934 HOWTO (R_MIPS16_GPREL, /* type */
936 2, /* size (0 = byte, 1 = short, 2 = long) */
938 false, /* pc_relative */
940 complain_overflow_signed, /* complain_on_overflow */
941 mips16_gprel_reloc, /* special_function */
942 "R_MIPS16_GPREL", /* name */
943 true, /* partial_inplace */
944 0x07ff001f, /* src_mask */
945 0x07ff001f, /* dst_mask */
946 false); /* pcrel_offset */
948 /* GNU extensions for embedded-pic. */
949 /* High 16 bits of symbol value, pc-relative. */
950 static reloc_howto_type elf_mips_gnu_rel_hi16 =
951 HOWTO (R_MIPS_GNU_REL_HI16, /* type */
953 2, /* size (0 = byte, 1 = short, 2 = long) */
955 true, /* pc_relative */
957 complain_overflow_dont, /* complain_on_overflow */
958 _bfd_mips_elf_hi16_reloc, /* special_function */
959 "R_MIPS_GNU_REL_HI16", /* name */
960 true, /* partial_inplace */
961 0xffff, /* src_mask */
962 0xffff, /* dst_mask */
963 true); /* pcrel_offset */
965 /* Low 16 bits of symbol value, pc-relative. */
966 static reloc_howto_type elf_mips_gnu_rel_lo16 =
967 HOWTO (R_MIPS_GNU_REL_LO16, /* type */
969 2, /* size (0 = byte, 1 = short, 2 = long) */
971 true, /* pc_relative */
973 complain_overflow_dont, /* complain_on_overflow */
974 _bfd_mips_elf_lo16_reloc, /* special_function */
975 "R_MIPS_GNU_REL_LO16", /* name */
976 true, /* partial_inplace */
977 0xffff, /* src_mask */
978 0xffff, /* dst_mask */
979 true); /* pcrel_offset */
981 /* 16 bit offset for pc-relative branches. */
982 static reloc_howto_type elf_mips_gnu_rel16_s2 =
983 HOWTO (R_MIPS_GNU_REL16_S2, /* type */
985 2, /* size (0 = byte, 1 = short, 2 = long) */
987 true, /* pc_relative */
989 complain_overflow_signed, /* complain_on_overflow */
990 bfd_elf_generic_reloc, /* special_function */
991 "R_MIPS_GNU_REL16_S2", /* name */
992 true, /* partial_inplace */
993 0xffff, /* src_mask */
994 0xffff, /* dst_mask */
995 true); /* pcrel_offset */
997 /* 64 bit pc-relative. */
998 static reloc_howto_type elf_mips_gnu_pcrel64 =
999 HOWTO (R_MIPS_PC64, /* type */
1001 4, /* size (0 = byte, 1 = short, 2 = long) */
1003 true, /* pc_relative */
1005 complain_overflow_signed, /* complain_on_overflow */
1006 bfd_elf_generic_reloc, /* special_function */
1007 "R_MIPS_PC64", /* name */
1008 true, /* partial_inplace */
1009 MINUS_ONE, /* src_mask */
1010 MINUS_ONE, /* dst_mask */
1011 true); /* pcrel_offset */
1013 /* 32 bit pc-relative. */
1014 static reloc_howto_type elf_mips_gnu_pcrel32 =
1015 HOWTO (R_MIPS_PC32, /* type */
1017 2, /* size (0 = byte, 1 = short, 2 = long) */
1019 true, /* pc_relative */
1021 complain_overflow_signed, /* complain_on_overflow */
1022 bfd_elf_generic_reloc, /* special_function */
1023 "R_MIPS_PC32", /* name */
1024 true, /* partial_inplace */
1025 0xffffffff, /* src_mask */
1026 0xffffffff, /* dst_mask */
1027 true); /* pcrel_offset */
1029 /* GNU extension to record C++ vtable hierarchy */
1030 static reloc_howto_type elf_mips_gnu_vtinherit_howto =
1031 HOWTO (R_MIPS_GNU_VTINHERIT, /* type */
1033 2, /* size (0 = byte, 1 = short, 2 = long) */
1035 false, /* pc_relative */
1037 complain_overflow_dont, /* complain_on_overflow */
1038 NULL, /* special_function */
1039 "R_MIPS_GNU_VTINHERIT", /* name */
1040 false, /* partial_inplace */
1043 false); /* pcrel_offset */
1045 /* GNU extension to record C++ vtable member usage */
1046 static reloc_howto_type elf_mips_gnu_vtentry_howto =
1047 HOWTO (R_MIPS_GNU_VTENTRY, /* type */
1049 2, /* size (0 = byte, 1 = short, 2 = long) */
1051 false, /* pc_relative */
1053 complain_overflow_dont, /* complain_on_overflow */
1054 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1055 "R_MIPS_GNU_VTENTRY", /* name */
1056 false, /* partial_inplace */
1059 false); /* pcrel_offset */
1061 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
1062 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
1063 the HI16. Here we just save the information we need; we do the
1064 actual relocation when we see the LO16. MIPS ELF requires that the
1065 LO16 immediately follow the HI16. As a GNU extension, we permit an
1066 arbitrary number of HI16 relocs to be associated with a single LO16
1067 reloc. This extension permits gcc to output the HI and LO relocs
1071 struct mips_hi16 *next;
1076 /* FIXME: This should not be a static variable. */
1078 static struct mips_hi16 *mips_hi16_list;
1080 bfd_reloc_status_type
1081 _bfd_mips_elf_hi16_reloc (abfd,
1088 bfd *abfd ATTRIBUTE_UNUSED;
1089 arelent *reloc_entry;
1092 asection *input_section;
1094 char **error_message;
1096 bfd_reloc_status_type ret;
1098 struct mips_hi16 *n;
1100 /* If we're relocating, and this an external symbol, we don't want
1101 to change anything. */
1102 if (output_bfd != (bfd *) NULL
1103 && (symbol->flags & BSF_SECTION_SYM) == 0
1104 && reloc_entry->addend == 0)
1106 reloc_entry->address += input_section->output_offset;
1107 return bfd_reloc_ok;
1112 if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
1114 boolean relocateable;
1117 if (ret == bfd_reloc_undefined)
1120 if (output_bfd != NULL)
1121 relocateable = true;
1124 relocateable = false;
1125 output_bfd = symbol->section->output_section->owner;
1128 ret = mips_elf_final_gp (output_bfd, symbol, relocateable,
1129 error_message, &gp);
1130 if (ret != bfd_reloc_ok)
1133 relocation = gp - reloc_entry->address;
1137 if (bfd_is_und_section (symbol->section)
1138 && output_bfd == (bfd *) NULL)
1139 ret = bfd_reloc_undefined;
1141 if (bfd_is_com_section (symbol->section))
1144 relocation = symbol->value;
1147 relocation += symbol->section->output_section->vma;
1148 relocation += symbol->section->output_offset;
1149 relocation += reloc_entry->addend;
1151 if (reloc_entry->address > input_section->_cooked_size)
1152 return bfd_reloc_outofrange;
1154 /* Save the information, and let LO16 do the actual relocation. */
1155 n = (struct mips_hi16 *) bfd_malloc (sizeof *n);
1157 return bfd_reloc_outofrange;
1158 n->addr = (bfd_byte *) data + reloc_entry->address;
1159 n->addend = relocation;
1160 n->next = mips_hi16_list;
1163 if (output_bfd != (bfd *) NULL)
1164 reloc_entry->address += input_section->output_offset;
1169 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
1170 inplace relocation; this function exists in order to do the
1171 R_MIPS_HI16 relocation described above. */
1173 bfd_reloc_status_type
1174 _bfd_mips_elf_lo16_reloc (abfd,
1182 arelent *reloc_entry;
1185 asection *input_section;
1187 char **error_message;
1189 arelent gp_disp_relent;
1191 if (mips_hi16_list != NULL)
1193 struct mips_hi16 *l;
1200 unsigned long vallo;
1201 struct mips_hi16 *next;
1203 /* Do the HI16 relocation. Note that we actually don't need
1204 to know anything about the LO16 itself, except where to
1205 find the low 16 bits of the addend needed by the LO16. */
1206 insn = bfd_get_32 (abfd, l->addr);
1207 vallo = (bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address)
1209 val = ((insn & 0xffff) << 16) + vallo;
1212 /* The low order 16 bits are always treated as a signed
1213 value. Therefore, a negative value in the low order bits
1214 requires an adjustment in the high order bits. We need
1215 to make this adjustment in two ways: once for the bits we
1216 took from the data, and once for the bits we are putting
1217 back in to the data. */
1218 if ((vallo & 0x8000) != 0)
1220 if ((val & 0x8000) != 0)
1223 insn = (insn & ~0xffff) | ((val >> 16) & 0xffff);
1224 bfd_put_32 (abfd, insn, l->addr);
1226 if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
1228 gp_disp_relent = *reloc_entry;
1229 reloc_entry = &gp_disp_relent;
1230 reloc_entry->addend = l->addend;
1238 mips_hi16_list = NULL;
1240 else if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
1242 bfd_reloc_status_type ret;
1243 bfd_vma gp, relocation;
1245 /* FIXME: Does this case ever occur? */
1247 ret = mips_elf_final_gp (output_bfd, symbol, true, error_message, &gp);
1248 if (ret != bfd_reloc_ok)
1251 relocation = gp - reloc_entry->address;
1252 relocation += symbol->section->output_section->vma;
1253 relocation += symbol->section->output_offset;
1254 relocation += reloc_entry->addend;
1256 if (reloc_entry->address > input_section->_cooked_size)
1257 return bfd_reloc_outofrange;
1259 gp_disp_relent = *reloc_entry;
1260 reloc_entry = &gp_disp_relent;
1261 reloc_entry->addend = relocation - 4;
1264 /* Now do the LO16 reloc in the usual way. */
1265 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1266 input_section, output_bfd, error_message);
1269 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1270 table used for PIC code. If the symbol is an external symbol, the
1271 instruction is modified to contain the offset of the appropriate
1272 entry in the global offset table. If the symbol is a section
1273 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1274 addends are combined to form the real addend against the section
1275 symbol; the GOT16 is modified to contain the offset of an entry in
1276 the global offset table, and the LO16 is modified to offset it
1277 appropriately. Thus an offset larger than 16 bits requires a
1278 modified value in the global offset table.
1280 This implementation suffices for the assembler, but the linker does
1281 not yet know how to create global offset tables. */
1283 bfd_reloc_status_type
1284 _bfd_mips_elf_got16_reloc (abfd,
1292 arelent *reloc_entry;
1295 asection *input_section;
1297 char **error_message;
1299 /* If we're relocating, and this an external symbol, we don't want
1300 to change anything. */
1301 if (output_bfd != (bfd *) NULL
1302 && (symbol->flags & BSF_SECTION_SYM) == 0
1303 && reloc_entry->addend == 0)
1305 reloc_entry->address += input_section->output_offset;
1306 return bfd_reloc_ok;
1309 /* If we're relocating, and this is a local symbol, we can handle it
1311 if (output_bfd != (bfd *) NULL
1312 && (symbol->flags & BSF_SECTION_SYM) != 0)
1313 return _bfd_mips_elf_hi16_reloc (abfd, reloc_entry, symbol, data,
1314 input_section, output_bfd, error_message);
1319 /* Set the GP value for OUTPUT_BFD. Returns false if this is a
1320 dangerous relocation. */
1323 mips_elf_assign_gp (output_bfd, pgp)
1331 /* If we've already figured out what GP will be, just return it. */
1332 *pgp = _bfd_get_gp_value (output_bfd);
1336 count = bfd_get_symcount (output_bfd);
1337 sym = bfd_get_outsymbols (output_bfd);
1339 /* The linker script will have created a symbol named `_gp' with the
1340 appropriate value. */
1341 if (sym == (asymbol **) NULL)
1345 for (i = 0; i < count; i++, sym++)
1347 register CONST char *name;
1349 name = bfd_asymbol_name (*sym);
1350 if (*name == '_' && strcmp (name, "_gp") == 0)
1352 *pgp = bfd_asymbol_value (*sym);
1353 _bfd_set_gp_value (output_bfd, *pgp);
1361 /* Only get the error once. */
1363 _bfd_set_gp_value (output_bfd, *pgp);
1370 /* We have to figure out the gp value, so that we can adjust the
1371 symbol value correctly. We look up the symbol _gp in the output
1372 BFD. If we can't find it, we're stuck. We cache it in the ELF
1373 target data. We don't need to adjust the symbol value for an
1374 external symbol if we are producing relocateable output. */
1376 static bfd_reloc_status_type
1377 mips_elf_final_gp (output_bfd, symbol, relocateable, error_message, pgp)
1380 boolean relocateable;
1381 char **error_message;
1384 if (bfd_is_und_section (symbol->section)
1388 return bfd_reloc_undefined;
1391 *pgp = _bfd_get_gp_value (output_bfd);
1394 || (symbol->flags & BSF_SECTION_SYM) != 0))
1398 /* Make up a value. */
1399 *pgp = symbol->section->output_section->vma + 0x4000;
1400 _bfd_set_gp_value (output_bfd, *pgp);
1402 else if (!mips_elf_assign_gp (output_bfd, pgp))
1405 (char *) _("GP relative relocation when _gp not defined");
1406 return bfd_reloc_dangerous;
1410 return bfd_reloc_ok;
1413 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1414 become the offset from the gp register. This function also handles
1415 R_MIPS_LITERAL relocations, although those can be handled more
1416 cleverly because the entries in the .lit8 and .lit4 sections can be
1419 static bfd_reloc_status_type gprel16_with_gp PARAMS ((bfd *, asymbol *,
1420 arelent *, asection *,
1421 boolean, PTR, bfd_vma));
1423 bfd_reloc_status_type
1424 _bfd_mips_elf_gprel16_reloc (abfd, reloc_entry, symbol, data, input_section,
1425 output_bfd, error_message)
1427 arelent *reloc_entry;
1430 asection *input_section;
1432 char **error_message;
1434 boolean relocateable;
1435 bfd_reloc_status_type ret;
1438 /* If we're relocating, and this is an external symbol with no
1439 addend, we don't want to change anything. We will only have an
1440 addend if this is a newly created reloc, not read from an ELF
1442 if (output_bfd != (bfd *) NULL
1443 && (symbol->flags & BSF_SECTION_SYM) == 0
1444 && reloc_entry->addend == 0)
1446 reloc_entry->address += input_section->output_offset;
1447 return bfd_reloc_ok;
1450 if (output_bfd != (bfd *) NULL)
1451 relocateable = true;
1454 relocateable = false;
1455 output_bfd = symbol->section->output_section->owner;
1458 ret = mips_elf_final_gp (output_bfd, symbol, relocateable, error_message,
1460 if (ret != bfd_reloc_ok)
1463 return gprel16_with_gp (abfd, symbol, reloc_entry, input_section,
1464 relocateable, data, gp);
1467 static bfd_reloc_status_type
1468 gprel16_with_gp (abfd, symbol, reloc_entry, input_section, relocateable, data,
1472 arelent *reloc_entry;
1473 asection *input_section;
1474 boolean relocateable;
1482 if (bfd_is_com_section (symbol->section))
1485 relocation = symbol->value;
1487 relocation += symbol->section->output_section->vma;
1488 relocation += symbol->section->output_offset;
1490 if (reloc_entry->address > input_section->_cooked_size)
1491 return bfd_reloc_outofrange;
1493 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1495 /* Set val to the offset into the section or symbol. */
1496 if (reloc_entry->howto->src_mask == 0)
1498 /* This case occurs with the 64-bit MIPS ELF ABI. */
1499 val = reloc_entry->addend;
1503 val = ((insn & 0xffff) + reloc_entry->addend) & 0xffff;
1508 /* Adjust val for the final section location and GP value. If we
1509 are producing relocateable output, we don't want to do this for
1510 an external symbol. */
1512 || (symbol->flags & BSF_SECTION_SYM) != 0)
1513 val += relocation - gp;
1515 insn = (insn & ~0xffff) | (val & 0xffff);
1516 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
1519 reloc_entry->address += input_section->output_offset;
1521 /* Make sure it fit in 16 bits. */
1522 if ((long) val >= 0x8000 || (long) val < -0x8000)
1523 return bfd_reloc_overflow;
1525 return bfd_reloc_ok;
1528 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1529 from the gp register? XXX */
1531 static bfd_reloc_status_type gprel32_with_gp PARAMS ((bfd *, asymbol *,
1532 arelent *, asection *,
1533 boolean, PTR, bfd_vma));
1535 bfd_reloc_status_type
1536 _bfd_mips_elf_gprel32_reloc (abfd,
1544 arelent *reloc_entry;
1547 asection *input_section;
1549 char **error_message;
1551 boolean relocateable;
1552 bfd_reloc_status_type ret;
1555 /* If we're relocating, and this is an external symbol with no
1556 addend, we don't want to change anything. We will only have an
1557 addend if this is a newly created reloc, not read from an ELF
1559 if (output_bfd != (bfd *) NULL
1560 && (symbol->flags & BSF_SECTION_SYM) == 0
1561 && reloc_entry->addend == 0)
1563 *error_message = (char *)
1564 _("32bits gp relative relocation occurs for an external symbol");
1565 return bfd_reloc_outofrange;
1568 if (output_bfd != (bfd *) NULL)
1570 relocateable = true;
1571 gp = _bfd_get_gp_value (output_bfd);
1575 relocateable = false;
1576 output_bfd = symbol->section->output_section->owner;
1578 ret = mips_elf_final_gp (output_bfd, symbol, relocateable,
1579 error_message, &gp);
1580 if (ret != bfd_reloc_ok)
1584 return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
1585 relocateable, data, gp);
1588 static bfd_reloc_status_type
1589 gprel32_with_gp (abfd, symbol, reloc_entry, input_section, relocateable, data,
1593 arelent *reloc_entry;
1594 asection *input_section;
1595 boolean relocateable;
1602 if (bfd_is_com_section (symbol->section))
1605 relocation = symbol->value;
1607 relocation += symbol->section->output_section->vma;
1608 relocation += symbol->section->output_offset;
1610 if (reloc_entry->address > input_section->_cooked_size)
1611 return bfd_reloc_outofrange;
1613 if (reloc_entry->howto->src_mask == 0)
1615 /* This case arises with the 64-bit MIPS ELF ABI. */
1619 val = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1621 /* Set val to the offset into the section or symbol. */
1622 val += reloc_entry->addend;
1624 /* Adjust val for the final section location and GP value. If we
1625 are producing relocateable output, we don't want to do this for
1626 an external symbol. */
1628 || (symbol->flags & BSF_SECTION_SYM) != 0)
1629 val += relocation - gp;
1631 bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);
1634 reloc_entry->address += input_section->output_offset;
1636 return bfd_reloc_ok;
1639 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1640 generated when addreses are 64 bits. The upper 32 bits are a simle
1643 static bfd_reloc_status_type
1644 mips32_64bit_reloc (abfd, reloc_entry, symbol, data, input_section,
1645 output_bfd, error_message)
1647 arelent *reloc_entry;
1650 asection *input_section;
1652 char **error_message;
1654 bfd_reloc_status_type r;
1659 r = bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1660 input_section, output_bfd, error_message);
1661 if (r != bfd_reloc_continue)
1664 /* Do a normal 32 bit relocation on the lower 32 bits. */
1665 reloc32 = *reloc_entry;
1666 if (bfd_big_endian (abfd))
1667 reloc32.address += 4;
1668 reloc32.howto = &elf_mips_howto_table[R_MIPS_32];
1669 r = bfd_perform_relocation (abfd, &reloc32, data, input_section,
1670 output_bfd, error_message);
1672 /* Sign extend into the upper 32 bits. */
1673 val = bfd_get_32 (abfd, (bfd_byte *) data + reloc32.address);
1674 if ((val & 0x80000000) != 0)
1678 addr = reloc_entry->address;
1679 if (bfd_little_endian (abfd))
1681 bfd_put_32 (abfd, val, (bfd_byte *) data + addr);
1686 /* Handle a mips16 jump. */
1688 static bfd_reloc_status_type
1689 mips16_jump_reloc (abfd, reloc_entry, symbol, data, input_section,
1690 output_bfd, error_message)
1691 bfd *abfd ATTRIBUTE_UNUSED;
1692 arelent *reloc_entry;
1694 PTR data ATTRIBUTE_UNUSED;
1695 asection *input_section;
1697 char **error_message ATTRIBUTE_UNUSED;
1699 if (output_bfd != (bfd *) NULL
1700 && (symbol->flags & BSF_SECTION_SYM) == 0
1701 && reloc_entry->addend == 0)
1703 reloc_entry->address += input_section->output_offset;
1704 return bfd_reloc_ok;
1709 static boolean warned;
1712 (*_bfd_error_handler)
1713 (_("Linking mips16 objects into %s format is not supported"),
1714 bfd_get_target (input_section->output_section->owner));
1718 return bfd_reloc_undefined;
1721 /* Handle a mips16 GP relative reloc. */
1723 static bfd_reloc_status_type
1724 mips16_gprel_reloc (abfd, reloc_entry, symbol, data, input_section,
1725 output_bfd, error_message)
1727 arelent *reloc_entry;
1730 asection *input_section;
1732 char **error_message;
1734 boolean relocateable;
1735 bfd_reloc_status_type ret;
1737 unsigned short extend, insn;
1738 unsigned long final;
1740 /* If we're relocating, and this is an external symbol with no
1741 addend, we don't want to change anything. We will only have an
1742 addend if this is a newly created reloc, not read from an ELF
1744 if (output_bfd != NULL
1745 && (symbol->flags & BSF_SECTION_SYM) == 0
1746 && reloc_entry->addend == 0)
1748 reloc_entry->address += input_section->output_offset;
1749 return bfd_reloc_ok;
1752 if (output_bfd != NULL)
1753 relocateable = true;
1756 relocateable = false;
1757 output_bfd = symbol->section->output_section->owner;
1760 ret = mips_elf_final_gp (output_bfd, symbol, relocateable, error_message,
1762 if (ret != bfd_reloc_ok)
1765 if (reloc_entry->address > input_section->_cooked_size)
1766 return bfd_reloc_outofrange;
1768 /* Pick up the mips16 extend instruction and the real instruction. */
1769 extend = bfd_get_16 (abfd, (bfd_byte *) data + reloc_entry->address);
1770 insn = bfd_get_16 (abfd, (bfd_byte *) data + reloc_entry->address + 2);
1772 /* Stuff the current addend back as a 32 bit value, do the usual
1773 relocation, and then clean up. */
1775 (((extend & 0x1f) << 11)
1778 (bfd_byte *) data + reloc_entry->address);
1780 ret = gprel16_with_gp (abfd, symbol, reloc_entry, input_section,
1781 relocateable, data, gp);
1783 final = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1786 | ((final >> 11) & 0x1f)
1788 (bfd_byte *) data + reloc_entry->address);
1792 (bfd_byte *) data + reloc_entry->address + 2);
1797 /* Return the ISA for a MIPS e_flags value. */
1800 elf_mips_isa (flags)
1803 switch (flags & EF_MIPS_ARCH)
1815 case E_MIPS_ARCH_32:
1817 case E_MIPS_ARCH_64:
1823 /* Return the MACH for a MIPS e_flags value. */
1826 elf_mips_mach (flags)
1829 switch (flags & EF_MIPS_MACH)
1831 case E_MIPS_MACH_3900:
1832 return bfd_mach_mips3900;
1834 case E_MIPS_MACH_4010:
1835 return bfd_mach_mips4010;
1837 case E_MIPS_MACH_4100:
1838 return bfd_mach_mips4100;
1840 case E_MIPS_MACH_4111:
1841 return bfd_mach_mips4111;
1843 case E_MIPS_MACH_4650:
1844 return bfd_mach_mips4650;
1846 case E_MIPS_MACH_MIPS32_4K:
1847 return bfd_mach_mips32_4k;
1849 case E_MIPS_MACH_SB1:
1850 return bfd_mach_mips_sb1;
1853 switch (flags & EF_MIPS_ARCH)
1857 return bfd_mach_mips3000;
1861 return bfd_mach_mips6000;
1865 return bfd_mach_mips4000;
1869 return bfd_mach_mips8000;
1873 return bfd_mach_mips5;
1876 case E_MIPS_ARCH_32:
1877 return bfd_mach_mips32;
1880 case E_MIPS_ARCH_64:
1881 return bfd_mach_mips64;
1889 /* Return printable name for ABI. */
1891 static INLINE char *
1892 elf_mips_abi_name (abfd)
1897 if (ABI_N32_P (abfd))
1899 else if (ABI_64_P (abfd))
1902 flags = elf_elfheader (abfd)->e_flags;
1903 switch (flags & EF_MIPS_ABI)
1907 case E_MIPS_ABI_O32:
1909 case E_MIPS_ABI_O64:
1911 case E_MIPS_ABI_EABI32:
1913 case E_MIPS_ABI_EABI64:
1916 return "unknown abi";
1920 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1922 struct elf_reloc_map {
1923 bfd_reloc_code_real_type bfd_reloc_val;
1924 enum elf_mips_reloc_type elf_reloc_val;
1927 static CONST struct elf_reloc_map mips_reloc_map[] = {
1928 { BFD_RELOC_NONE, R_MIPS_NONE, },
1929 { BFD_RELOC_16, R_MIPS_16 },
1930 { BFD_RELOC_32, R_MIPS_32 },
1931 { BFD_RELOC_64, R_MIPS_64 },
1932 { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
1933 { BFD_RELOC_HI16_S, R_MIPS_HI16 },
1934 { BFD_RELOC_LO16, R_MIPS_LO16 },
1935 { BFD_RELOC_MIPS_GPREL, R_MIPS_GPREL16 },
1936 { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
1937 { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
1938 { BFD_RELOC_16_PCREL, R_MIPS_PC16 },
1939 { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
1940 { BFD_RELOC_MIPS_GPREL32, R_MIPS_GPREL32 },
1941 { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
1942 { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 },
1943 { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 },
1944 { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 },
1945 { BFD_RELOC_MIPS_SUB, R_MIPS_SUB },
1946 { BFD_RELOC_MIPS_GOT_PAGE, R_MIPS_GOT_PAGE },
1947 { BFD_RELOC_MIPS_GOT_OFST, R_MIPS_GOT_OFST },
1948 { BFD_RELOC_MIPS_GOT_DISP, R_MIPS_GOT_DISP }
1951 /* Given a BFD reloc type, return a howto structure. */
1953 static reloc_howto_type *
1954 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
1956 bfd_reloc_code_real_type code;
1960 for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map); i++)
1962 if (mips_reloc_map[i].bfd_reloc_val == code)
1963 return &elf_mips_howto_table[(int) mips_reloc_map[i].elf_reloc_val];
1969 bfd_set_error (bfd_error_bad_value);
1972 case BFD_RELOC_CTOR:
1973 /* We need to handle BFD_RELOC_CTOR specially.
1974 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1975 size of addresses on this architecture. */
1976 if (bfd_arch_bits_per_address (abfd) == 32)
1977 return &elf_mips_howto_table[(int) R_MIPS_32];
1979 return &elf_mips_ctor64_howto;
1981 case BFD_RELOC_MIPS16_JMP:
1982 return &elf_mips16_jump_howto;
1983 case BFD_RELOC_MIPS16_GPREL:
1984 return &elf_mips16_gprel_howto;
1985 case BFD_RELOC_VTABLE_INHERIT:
1986 return &elf_mips_gnu_vtinherit_howto;
1987 case BFD_RELOC_VTABLE_ENTRY:
1988 return &elf_mips_gnu_vtentry_howto;
1989 case BFD_RELOC_PCREL_HI16_S:
1990 return &elf_mips_gnu_rel_hi16;
1991 case BFD_RELOC_PCREL_LO16:
1992 return &elf_mips_gnu_rel_lo16;
1993 case BFD_RELOC_16_PCREL_S2:
1994 return &elf_mips_gnu_rel16_s2;
1995 case BFD_RELOC_64_PCREL:
1996 return &elf_mips_gnu_pcrel64;
1997 case BFD_RELOC_32_PCREL:
1998 return &elf_mips_gnu_pcrel32;
2002 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
2004 static reloc_howto_type *
2005 mips_rtype_to_howto (r_type)
2006 unsigned int r_type;
2011 return &elf_mips16_jump_howto;
2013 case R_MIPS16_GPREL:
2014 return &elf_mips16_gprel_howto;
2016 case R_MIPS_GNU_VTINHERIT:
2017 return &elf_mips_gnu_vtinherit_howto;
2019 case R_MIPS_GNU_VTENTRY:
2020 return &elf_mips_gnu_vtentry_howto;
2022 case R_MIPS_GNU_REL_HI16:
2023 return &elf_mips_gnu_rel_hi16;
2025 case R_MIPS_GNU_REL_LO16:
2026 return &elf_mips_gnu_rel_lo16;
2028 case R_MIPS_GNU_REL16_S2:
2029 return &elf_mips_gnu_rel16_s2;
2032 return &elf_mips_gnu_pcrel64;
2035 return &elf_mips_gnu_pcrel32;
2039 BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
2040 return &elf_mips_howto_table[r_type];
2045 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
2048 mips_info_to_howto_rel (abfd, cache_ptr, dst)
2051 Elf32_Internal_Rel *dst;
2053 unsigned int r_type;
2055 r_type = ELF32_R_TYPE (dst->r_info);
2056 cache_ptr->howto = mips_rtype_to_howto (r_type);
2058 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
2059 value for the object file. We get the addend now, rather than
2060 when we do the relocation, because the symbol manipulations done
2061 by the linker may cause us to lose track of the input BFD. */
2062 if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
2063 && (r_type == (unsigned int) R_MIPS_GPREL16
2064 || r_type == (unsigned int) R_MIPS_LITERAL))
2065 cache_ptr->addend = elf_gp (abfd);
2068 /* Given a MIPS Elf32_Internal_Rela, fill in an arelent structure. */
2071 mips_info_to_howto_rela (abfd, cache_ptr, dst)
2074 Elf32_Internal_Rela *dst;
2076 /* Since an Elf32_Internal_Rel is an initial prefix of an
2077 Elf32_Internal_Rela, we can just use mips_info_to_howto_rel
2079 mips_info_to_howto_rel (abfd, cache_ptr, (Elf32_Internal_Rel *) dst);
2081 /* If we ever need to do any extra processing with dst->r_addend
2082 (the field omitted in an Elf32_Internal_Rel) we can do it here. */
2085 /* A .reginfo section holds a single Elf32_RegInfo structure. These
2086 routines swap this structure in and out. They are used outside of
2087 BFD, so they are globally visible. */
2090 bfd_mips_elf32_swap_reginfo_in (abfd, ex, in)
2092 const Elf32_External_RegInfo *ex;
2095 in->ri_gprmask = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_gprmask);
2096 in->ri_cprmask[0] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[0]);
2097 in->ri_cprmask[1] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[1]);
2098 in->ri_cprmask[2] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[2]);
2099 in->ri_cprmask[3] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[3]);
2100 in->ri_gp_value = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_gp_value);
2104 bfd_mips_elf32_swap_reginfo_out (abfd, in, ex)
2106 const Elf32_RegInfo *in;
2107 Elf32_External_RegInfo *ex;
2109 bfd_h_put_32 (abfd, (bfd_vma) in->ri_gprmask,
2110 (bfd_byte *) ex->ri_gprmask);
2111 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[0],
2112 (bfd_byte *) ex->ri_cprmask[0]);
2113 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[1],
2114 (bfd_byte *) ex->ri_cprmask[1]);
2115 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[2],
2116 (bfd_byte *) ex->ri_cprmask[2]);
2117 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[3],
2118 (bfd_byte *) ex->ri_cprmask[3]);
2119 bfd_h_put_32 (abfd, (bfd_vma) in->ri_gp_value,
2120 (bfd_byte *) ex->ri_gp_value);
2123 /* In the 64 bit ABI, the .MIPS.options section holds register
2124 information in an Elf64_Reginfo structure. These routines swap
2125 them in and out. They are globally visible because they are used
2126 outside of BFD. These routines are here so that gas can call them
2127 without worrying about whether the 64 bit ABI has been included. */
2130 bfd_mips_elf64_swap_reginfo_in (abfd, ex, in)
2132 const Elf64_External_RegInfo *ex;
2133 Elf64_Internal_RegInfo *in;
2135 in->ri_gprmask = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_gprmask);
2136 in->ri_pad = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_pad);
2137 in->ri_cprmask[0] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[0]);
2138 in->ri_cprmask[1] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[1]);
2139 in->ri_cprmask[2] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[2]);
2140 in->ri_cprmask[3] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[3]);
2141 in->ri_gp_value = bfd_h_get_64 (abfd, (bfd_byte *) ex->ri_gp_value);
2145 bfd_mips_elf64_swap_reginfo_out (abfd, in, ex)
2147 const Elf64_Internal_RegInfo *in;
2148 Elf64_External_RegInfo *ex;
2150 bfd_h_put_32 (abfd, (bfd_vma) in->ri_gprmask,
2151 (bfd_byte *) ex->ri_gprmask);
2152 bfd_h_put_32 (abfd, (bfd_vma) in->ri_pad,
2153 (bfd_byte *) ex->ri_pad);
2154 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[0],
2155 (bfd_byte *) ex->ri_cprmask[0]);
2156 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[1],
2157 (bfd_byte *) ex->ri_cprmask[1]);
2158 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[2],
2159 (bfd_byte *) ex->ri_cprmask[2]);
2160 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[3],
2161 (bfd_byte *) ex->ri_cprmask[3]);
2162 bfd_h_put_64 (abfd, (bfd_vma) in->ri_gp_value,
2163 (bfd_byte *) ex->ri_gp_value);
2166 /* Swap an entry in a .gptab section. Note that these routines rely
2167 on the equivalence of the two elements of the union. */
2170 bfd_mips_elf32_swap_gptab_in (abfd, ex, in)
2172 const Elf32_External_gptab *ex;
2175 in->gt_entry.gt_g_value = bfd_h_get_32 (abfd, ex->gt_entry.gt_g_value);
2176 in->gt_entry.gt_bytes = bfd_h_get_32 (abfd, ex->gt_entry.gt_bytes);
2180 bfd_mips_elf32_swap_gptab_out (abfd, in, ex)
2182 const Elf32_gptab *in;
2183 Elf32_External_gptab *ex;
2185 bfd_h_put_32 (abfd, (bfd_vma) in->gt_entry.gt_g_value,
2186 ex->gt_entry.gt_g_value);
2187 bfd_h_put_32 (abfd, (bfd_vma) in->gt_entry.gt_bytes,
2188 ex->gt_entry.gt_bytes);
2192 bfd_elf32_swap_compact_rel_out (abfd, in, ex)
2194 const Elf32_compact_rel *in;
2195 Elf32_External_compact_rel *ex;
2197 bfd_h_put_32 (abfd, (bfd_vma) in->id1, ex->id1);
2198 bfd_h_put_32 (abfd, (bfd_vma) in->num, ex->num);
2199 bfd_h_put_32 (abfd, (bfd_vma) in->id2, ex->id2);
2200 bfd_h_put_32 (abfd, (bfd_vma) in->offset, ex->offset);
2201 bfd_h_put_32 (abfd, (bfd_vma) in->reserved0, ex->reserved0);
2202 bfd_h_put_32 (abfd, (bfd_vma) in->reserved1, ex->reserved1);
2206 bfd_elf32_swap_crinfo_out (abfd, in, ex)
2208 const Elf32_crinfo *in;
2209 Elf32_External_crinfo *ex;
2213 l = (((in->ctype & CRINFO_CTYPE) << CRINFO_CTYPE_SH)
2214 | ((in->rtype & CRINFO_RTYPE) << CRINFO_RTYPE_SH)
2215 | ((in->dist2to & CRINFO_DIST2TO) << CRINFO_DIST2TO_SH)
2216 | ((in->relvaddr & CRINFO_RELVADDR) << CRINFO_RELVADDR_SH));
2217 bfd_h_put_32 (abfd, (bfd_vma) l, ex->info);
2218 bfd_h_put_32 (abfd, (bfd_vma) in->konst, ex->konst);
2219 bfd_h_put_32 (abfd, (bfd_vma) in->vaddr, ex->vaddr);
2222 /* Swap in an options header. */
2225 bfd_mips_elf_swap_options_in (abfd, ex, in)
2227 const Elf_External_Options *ex;
2228 Elf_Internal_Options *in;
2230 in->kind = bfd_h_get_8 (abfd, ex->kind);
2231 in->size = bfd_h_get_8 (abfd, ex->size);
2232 in->section = bfd_h_get_16 (abfd, ex->section);
2233 in->info = bfd_h_get_32 (abfd, ex->info);
2236 /* Swap out an options header. */
2239 bfd_mips_elf_swap_options_out (abfd, in, ex)
2241 const Elf_Internal_Options *in;
2242 Elf_External_Options *ex;
2244 bfd_h_put_8 (abfd, in->kind, ex->kind);
2245 bfd_h_put_8 (abfd, in->size, ex->size);
2246 bfd_h_put_16 (abfd, in->section, ex->section);
2247 bfd_h_put_32 (abfd, in->info, ex->info);
2250 /* Swap in an MSYM entry. */
2253 bfd_mips_elf_swap_msym_in (abfd, ex, in)
2255 const Elf32_External_Msym *ex;
2256 Elf32_Internal_Msym *in;
2258 in->ms_hash_value = bfd_h_get_32 (abfd, ex->ms_hash_value);
2259 in->ms_info = bfd_h_get_32 (abfd, ex->ms_info);
2262 /* Swap out an MSYM entry. */
2265 bfd_mips_elf_swap_msym_out (abfd, in, ex)
2267 const Elf32_Internal_Msym *in;
2268 Elf32_External_Msym *ex;
2270 bfd_h_put_32 (abfd, in->ms_hash_value, ex->ms_hash_value);
2271 bfd_h_put_32 (abfd, in->ms_info, ex->ms_info);
2274 /* Determine whether a symbol is global for the purposes of splitting
2275 the symbol table into global symbols and local symbols. At least
2276 on Irix 5, this split must be between section symbols and all other
2277 symbols. On most ELF targets the split is between static symbols
2278 and externally visible symbols. */
2281 mips_elf_sym_is_global (abfd, sym)
2282 bfd *abfd ATTRIBUTE_UNUSED;
2285 return (sym->flags & BSF_SECTION_SYM) == 0 ? true : false;
2288 /* Set the right machine number for a MIPS ELF file. This is used for
2289 both the 32-bit and the 64-bit ABI. */
2292 _bfd_mips_elf_object_p (abfd)
2295 /* Irix 5 and 6 is broken. Object file symbol tables are not always
2296 sorted correctly such that local symbols precede global symbols,
2297 and the sh_info field in the symbol table is not always right. */
2298 elf_bad_symtab (abfd) = true;
2300 bfd_default_set_arch_mach (abfd, bfd_arch_mips,
2301 elf_mips_mach (elf_elfheader (abfd)->e_flags));
2305 /* The final processing done just before writing out a MIPS ELF object
2306 file. This gets the MIPS architecture right based on the machine
2307 number. This is used by both the 32-bit and the 64-bit ABI. */
2310 _bfd_mips_elf_final_write_processing (abfd, linker)
2312 boolean linker ATTRIBUTE_UNUSED;
2316 Elf_Internal_Shdr **hdrpp;
2320 switch (bfd_get_mach (abfd))
2323 case bfd_mach_mips3000:
2324 val = E_MIPS_ARCH_1;
2327 case bfd_mach_mips3900:
2328 val = E_MIPS_ARCH_1 | E_MIPS_MACH_3900;
2331 case bfd_mach_mips6000:
2332 val = E_MIPS_ARCH_2;
2335 case bfd_mach_mips4000:
2336 case bfd_mach_mips4300:
2337 val = E_MIPS_ARCH_3;
2340 case bfd_mach_mips4010:
2341 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4010;
2344 case bfd_mach_mips4100:
2345 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4100;
2348 case bfd_mach_mips4111:
2349 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4111;
2352 case bfd_mach_mips4650:
2353 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4650;
2356 case bfd_mach_mips8000:
2357 val = E_MIPS_ARCH_4;
2360 case bfd_mach_mips32:
2361 val = E_MIPS_ARCH_32;
2364 case bfd_mach_mips32_4k:
2365 val = E_MIPS_ARCH_32 | E_MIPS_MACH_MIPS32_4K;
2368 case bfd_mach_mips5:
2369 val = E_MIPS_ARCH_5;
2372 case bfd_mach_mips64:
2373 val = E_MIPS_ARCH_64;
2376 case bfd_mach_mips_sb1:
2377 val = E_MIPS_ARCH_64 | E_MIPS_MACH_SB1;
2381 elf_elfheader (abfd)->e_flags &= ~(EF_MIPS_ARCH | EF_MIPS_MACH);
2382 elf_elfheader (abfd)->e_flags |= val;
2384 /* Set the sh_info field for .gptab sections and other appropriate
2385 info for each special section. */
2386 for (i = 1, hdrpp = elf_elfsections (abfd) + 1;
2387 i < elf_elfheader (abfd)->e_shnum;
2390 switch ((*hdrpp)->sh_type)
2393 case SHT_MIPS_LIBLIST:
2394 sec = bfd_get_section_by_name (abfd, ".dynstr");
2396 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx;
2399 case SHT_MIPS_GPTAB:
2400 BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
2401 name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section);
2402 BFD_ASSERT (name != NULL
2403 && strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0);
2404 sec = bfd_get_section_by_name (abfd, name + sizeof ".gptab" - 1);
2405 BFD_ASSERT (sec != NULL);
2406 (*hdrpp)->sh_info = elf_section_data (sec)->this_idx;
2409 case SHT_MIPS_CONTENT:
2410 BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
2411 name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section);
2412 BFD_ASSERT (name != NULL
2413 && strncmp (name, ".MIPS.content",
2414 sizeof ".MIPS.content" - 1) == 0);
2415 sec = bfd_get_section_by_name (abfd,
2416 name + sizeof ".MIPS.content" - 1);
2417 BFD_ASSERT (sec != NULL);
2418 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx;
2421 case SHT_MIPS_SYMBOL_LIB:
2422 sec = bfd_get_section_by_name (abfd, ".dynsym");
2424 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx;
2425 sec = bfd_get_section_by_name (abfd, ".liblist");
2427 (*hdrpp)->sh_info = elf_section_data (sec)->this_idx;
2430 case SHT_MIPS_EVENTS:
2431 BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
2432 name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section);
2433 BFD_ASSERT (name != NULL);
2434 if (strncmp (name, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
2435 sec = bfd_get_section_by_name (abfd,
2436 name + sizeof ".MIPS.events" - 1);
2439 BFD_ASSERT (strncmp (name, ".MIPS.post_rel",
2440 sizeof ".MIPS.post_rel" - 1) == 0);
2441 sec = bfd_get_section_by_name (abfd,
2443 + sizeof ".MIPS.post_rel" - 1));
2445 BFD_ASSERT (sec != NULL);
2446 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx;
2453 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
2456 _bfd_mips_elf_set_private_flags (abfd, flags)
2460 BFD_ASSERT (!elf_flags_init (abfd)
2461 || elf_elfheader (abfd)->e_flags == flags);
2463 elf_elfheader (abfd)->e_flags = flags;
2464 elf_flags_init (abfd) = true;
2468 /* Copy backend specific data from one object module to another */
2471 _bfd_mips_elf_copy_private_bfd_data (ibfd, obfd)
2475 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
2476 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
2479 BFD_ASSERT (!elf_flags_init (obfd)
2480 || (elf_elfheader (obfd)->e_flags
2481 == elf_elfheader (ibfd)->e_flags));
2483 elf_gp (obfd) = elf_gp (ibfd);
2484 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
2485 elf_flags_init (obfd) = true;
2489 /* Merge backend specific data from an object file to the output
2490 object file when linking. */
2493 _bfd_mips_elf_merge_private_bfd_data (ibfd, obfd)
2500 boolean null_input_bfd = true;
2503 /* Check if we have the same endianess */
2504 if (_bfd_generic_verify_endian_match (ibfd, obfd) == false)
2507 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
2508 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
2511 new_flags = elf_elfheader (ibfd)->e_flags;
2512 elf_elfheader (obfd)->e_flags |= new_flags & EF_MIPS_NOREORDER;
2513 old_flags = elf_elfheader (obfd)->e_flags;
2515 if (! elf_flags_init (obfd))
2517 elf_flags_init (obfd) = true;
2518 elf_elfheader (obfd)->e_flags = new_flags;
2519 elf_elfheader (obfd)->e_ident[EI_CLASS]
2520 = elf_elfheader (ibfd)->e_ident[EI_CLASS];
2522 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
2523 && bfd_get_arch_info (obfd)->the_default)
2525 if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
2526 bfd_get_mach (ibfd)))
2533 /* Check flag compatibility. */
2535 new_flags &= ~EF_MIPS_NOREORDER;
2536 old_flags &= ~EF_MIPS_NOREORDER;
2538 if (new_flags == old_flags)
2541 /* Check to see if the input BFD actually contains any sections.
2542 If not, its flags may not have been initialised either, but it cannot
2543 actually cause any incompatibility. */
2544 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
2546 /* Ignore synthetic sections and empty .text, .data and .bss sections
2547 which are automatically generated by gas. */
2548 if (strcmp (sec->name, ".reginfo")
2549 && strcmp (sec->name, ".mdebug")
2550 && ((!strcmp (sec->name, ".text")
2551 || !strcmp (sec->name, ".data")
2552 || !strcmp (sec->name, ".bss"))
2553 && sec->_raw_size != 0))
2555 null_input_bfd = false;
2564 if ((new_flags & EF_MIPS_PIC) != (old_flags & EF_MIPS_PIC))
2566 new_flags &= ~EF_MIPS_PIC;
2567 old_flags &= ~EF_MIPS_PIC;
2568 (*_bfd_error_handler)
2569 (_("%s: linking PIC files with non-PIC files"),
2570 bfd_get_filename (ibfd));
2574 if ((new_flags & EF_MIPS_CPIC) != (old_flags & EF_MIPS_CPIC))
2576 new_flags &= ~EF_MIPS_CPIC;
2577 old_flags &= ~EF_MIPS_CPIC;
2578 (*_bfd_error_handler)
2579 (_("%s: linking abicalls files with non-abicalls files"),
2580 bfd_get_filename (ibfd));
2584 /* Compare the ISA's. */
2585 if ((new_flags & (EF_MIPS_ARCH | EF_MIPS_MACH))
2586 != (old_flags & (EF_MIPS_ARCH | EF_MIPS_MACH)))
2588 int new_mach = new_flags & EF_MIPS_MACH;
2589 int old_mach = old_flags & EF_MIPS_MACH;
2590 int new_isa = elf_mips_isa (new_flags);
2591 int old_isa = elf_mips_isa (old_flags);
2593 /* If either has no machine specified, just compare the general isa's.
2594 Some combinations of machines are ok, if the isa's match. */
2597 || new_mach == old_mach
2600 /* Don't warn about mixing code using 32-bit ISAs, or mixing code
2601 using 64-bit ISAs. They will normally use the same data sizes
2602 and calling conventions. */
2604 if (( (new_isa == 1 || new_isa == 2 || new_isa == 32)
2605 ^ (old_isa == 1 || old_isa == 2 || old_isa == 32)) != 0)
2607 (*_bfd_error_handler)
2608 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
2609 bfd_get_filename (ibfd), new_isa, old_isa);
2616 (*_bfd_error_handler)
2617 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
2618 bfd_get_filename (ibfd),
2619 elf_mips_mach (new_flags),
2620 elf_mips_mach (old_flags));
2624 new_flags &= ~(EF_MIPS_ARCH | EF_MIPS_MACH);
2625 old_flags &= ~(EF_MIPS_ARCH | EF_MIPS_MACH);
2628 /* Compare ABI's. The 64-bit ABI does not use EF_MIPS_ABI. But, it
2629 does set EI_CLASS differently from any 32-bit ABI. */
2630 if ((new_flags & EF_MIPS_ABI) != (old_flags & EF_MIPS_ABI)
2631 || (elf_elfheader (ibfd)->e_ident[EI_CLASS]
2632 != elf_elfheader (obfd)->e_ident[EI_CLASS]))
2634 /* Only error if both are set (to different values). */
2635 if (((new_flags & EF_MIPS_ABI) && (old_flags & EF_MIPS_ABI))
2636 || (elf_elfheader (ibfd)->e_ident[EI_CLASS]
2637 != elf_elfheader (obfd)->e_ident[EI_CLASS]))
2639 (*_bfd_error_handler)
2640 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
2641 bfd_get_filename (ibfd),
2642 elf_mips_abi_name (ibfd),
2643 elf_mips_abi_name (obfd));
2646 new_flags &= ~EF_MIPS_ABI;
2647 old_flags &= ~EF_MIPS_ABI;
2650 /* Warn about any other mismatches */
2651 if (new_flags != old_flags)
2653 (*_bfd_error_handler)
2654 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2655 bfd_get_filename (ibfd), (unsigned long) new_flags,
2656 (unsigned long) old_flags);
2662 bfd_set_error (bfd_error_bad_value);
2670 _bfd_mips_elf_print_private_bfd_data (abfd, ptr)
2674 FILE *file = (FILE *) ptr;
2676 BFD_ASSERT (abfd != NULL && ptr != NULL);
2678 /* Print normal ELF private data. */
2679 _bfd_elf_print_private_bfd_data (abfd, ptr);
2681 /* xgettext:c-format */
2682 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
2684 if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_O32)
2685 fprintf (file, _(" [abi=O32]"));
2686 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_O64)
2687 fprintf (file, _(" [abi=O64]"));
2688 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI32)
2689 fprintf (file, _(" [abi=EABI32]"));
2690 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64)
2691 fprintf (file, _(" [abi=EABI64]"));
2692 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI))
2693 fprintf (file, _(" [abi unknown]"));
2694 else if (ABI_N32_P (abfd))
2695 fprintf (file, _(" [abi=N32]"));
2696 else if (ABI_64_P (abfd))
2697 fprintf (file, _(" [abi=64]"));
2699 fprintf (file, _(" [no abi set]"));
2701 if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1)
2702 fprintf (file, _(" [mips1]"));
2703 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2)
2704 fprintf (file, _(" [mips2]"));
2705 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3)
2706 fprintf (file, _(" [mips3]"));
2707 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4)
2708 fprintf (file, _(" [mips4]"));
2709 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_5)
2710 fprintf (file, _ (" [mips5]"));
2711 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_32)
2712 fprintf (file, _ (" [mips32]"));
2713 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_64)
2714 fprintf (file, _ (" [mips64]"));
2716 fprintf (file, _(" [unknown ISA]"));
2718 if (elf_elfheader (abfd)->e_flags & EF_MIPS_32BITMODE)
2719 fprintf (file, _(" [32bitmode]"));
2721 fprintf (file, _(" [not 32bitmode]"));
2728 /* Handle a MIPS specific section when reading an object file. This
2729 is called when elfcode.h finds a section with an unknown type.
2730 This routine supports both the 32-bit and 64-bit ELF ABI.
2732 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2736 _bfd_mips_elf_section_from_shdr (abfd, hdr, name)
2738 Elf_Internal_Shdr *hdr;
2743 /* There ought to be a place to keep ELF backend specific flags, but
2744 at the moment there isn't one. We just keep track of the
2745 sections by their name, instead. Fortunately, the ABI gives
2746 suggested names for all the MIPS specific sections, so we will
2747 probably get away with this. */
2748 switch (hdr->sh_type)
2750 case SHT_MIPS_LIBLIST:
2751 if (strcmp (name, ".liblist") != 0)
2755 if (strcmp (name, MIPS_ELF_MSYM_SECTION_NAME (abfd)) != 0)
2758 case SHT_MIPS_CONFLICT:
2759 if (strcmp (name, ".conflict") != 0)
2762 case SHT_MIPS_GPTAB:
2763 if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) != 0)
2766 case SHT_MIPS_UCODE:
2767 if (strcmp (name, ".ucode") != 0)
2770 case SHT_MIPS_DEBUG:
2771 if (strcmp (name, ".mdebug") != 0)
2773 flags = SEC_DEBUGGING;
2775 case SHT_MIPS_REGINFO:
2776 if (strcmp (name, ".reginfo") != 0
2777 || hdr->sh_size != sizeof (Elf32_External_RegInfo))
2779 flags = (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_SIZE);
2781 case SHT_MIPS_IFACE:
2782 if (strcmp (name, ".MIPS.interfaces") != 0)
2785 case SHT_MIPS_CONTENT:
2786 if (strncmp (name, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2789 case SHT_MIPS_OPTIONS:
2790 if (strcmp (name, MIPS_ELF_OPTIONS_SECTION_NAME (abfd)) != 0)
2793 case SHT_MIPS_DWARF:
2794 if (strncmp (name, ".debug_", sizeof ".debug_" - 1) != 0)
2797 case SHT_MIPS_SYMBOL_LIB:
2798 if (strcmp (name, ".MIPS.symlib") != 0)
2801 case SHT_MIPS_EVENTS:
2802 if (strncmp (name, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2803 && strncmp (name, ".MIPS.post_rel",
2804 sizeof ".MIPS.post_rel" - 1) != 0)
2811 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
2816 if (! bfd_set_section_flags (abfd, hdr->bfd_section,
2817 (bfd_get_section_flags (abfd,
2823 /* FIXME: We should record sh_info for a .gptab section. */
2825 /* For a .reginfo section, set the gp value in the tdata information
2826 from the contents of this section. We need the gp value while
2827 processing relocs, so we just get it now. The .reginfo section
2828 is not used in the 64-bit MIPS ELF ABI. */
2829 if (hdr->sh_type == SHT_MIPS_REGINFO)
2831 Elf32_External_RegInfo ext;
2834 if (! bfd_get_section_contents (abfd, hdr->bfd_section, (PTR) &ext,
2835 (file_ptr) 0, sizeof ext))
2837 bfd_mips_elf32_swap_reginfo_in (abfd, &ext, &s);
2838 elf_gp (abfd) = s.ri_gp_value;
2841 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2842 set the gp value based on what we find. We may see both
2843 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2844 they should agree. */
2845 if (hdr->sh_type == SHT_MIPS_OPTIONS)
2847 bfd_byte *contents, *l, *lend;
2849 contents = (bfd_byte *) bfd_malloc (hdr->sh_size);
2850 if (contents == NULL)
2852 if (! bfd_get_section_contents (abfd, hdr->bfd_section, contents,
2853 (file_ptr) 0, hdr->sh_size))
2859 lend = contents + hdr->sh_size;
2860 while (l + sizeof (Elf_External_Options) <= lend)
2862 Elf_Internal_Options intopt;
2864 bfd_mips_elf_swap_options_in (abfd, (Elf_External_Options *) l,
2866 if (ABI_64_P (abfd) && intopt.kind == ODK_REGINFO)
2868 Elf64_Internal_RegInfo intreg;
2870 bfd_mips_elf64_swap_reginfo_in
2872 ((Elf64_External_RegInfo *)
2873 (l + sizeof (Elf_External_Options))),
2875 elf_gp (abfd) = intreg.ri_gp_value;
2877 else if (intopt.kind == ODK_REGINFO)
2879 Elf32_RegInfo intreg;
2881 bfd_mips_elf32_swap_reginfo_in
2883 ((Elf32_External_RegInfo *)
2884 (l + sizeof (Elf_External_Options))),
2886 elf_gp (abfd) = intreg.ri_gp_value;
2896 /* Set the correct type for a MIPS ELF section. We do this by the
2897 section name, which is a hack, but ought to work. This routine is
2898 used by both the 32-bit and the 64-bit ABI. */
2901 _bfd_mips_elf_fake_sections (abfd, hdr, sec)
2903 Elf32_Internal_Shdr *hdr;
2906 register const char *name;
2908 name = bfd_get_section_name (abfd, sec);
2910 if (strcmp (name, ".liblist") == 0)
2912 hdr->sh_type = SHT_MIPS_LIBLIST;
2913 hdr->sh_info = sec->_raw_size / sizeof (Elf32_Lib);
2914 /* The sh_link field is set in final_write_processing. */
2916 else if (strcmp (name, ".conflict") == 0)
2917 hdr->sh_type = SHT_MIPS_CONFLICT;
2918 else if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0)
2920 hdr->sh_type = SHT_MIPS_GPTAB;
2921 hdr->sh_entsize = sizeof (Elf32_External_gptab);
2922 /* The sh_info field is set in final_write_processing. */
2924 else if (strcmp (name, ".ucode") == 0)
2925 hdr->sh_type = SHT_MIPS_UCODE;
2926 else if (strcmp (name, ".mdebug") == 0)
2928 hdr->sh_type = SHT_MIPS_DEBUG;
2929 /* In a shared object on Irix 5.3, the .mdebug section has an
2930 entsize of 0. FIXME: Does this matter? */
2931 if (SGI_COMPAT (abfd) && (abfd->flags & DYNAMIC) != 0)
2932 hdr->sh_entsize = 0;
2934 hdr->sh_entsize = 1;
2936 else if (strcmp (name, ".reginfo") == 0)
2938 hdr->sh_type = SHT_MIPS_REGINFO;
2939 /* In a shared object on Irix 5.3, the .reginfo section has an
2940 entsize of 0x18. FIXME: Does this matter? */
2941 if (SGI_COMPAT (abfd))
2943 if ((abfd->flags & DYNAMIC) != 0)
2944 hdr->sh_entsize = sizeof (Elf32_External_RegInfo);
2946 hdr->sh_entsize = 1;
2949 hdr->sh_entsize = sizeof (Elf32_External_RegInfo);
2951 else if (SGI_COMPAT (abfd)
2952 && (strcmp (name, ".hash") == 0
2953 || strcmp (name, ".dynamic") == 0
2954 || strcmp (name, ".dynstr") == 0))
2956 if (SGI_COMPAT (abfd))
2957 hdr->sh_entsize = 0;
2959 /* This isn't how the Irix 6 linker behaves. */
2960 hdr->sh_info = SIZEOF_MIPS_DYNSYM_SECNAMES;
2963 else if (strcmp (name, ".got") == 0
2964 || strcmp (name, MIPS_ELF_SRDATA_SECTION_NAME (abfd)) == 0
2965 || strcmp (name, ".sdata") == 0
2966 || strcmp (name, ".sbss") == 0
2967 || strcmp (name, ".lit4") == 0
2968 || strcmp (name, ".lit8") == 0)
2969 hdr->sh_flags |= SHF_MIPS_GPREL;
2970 else if (strcmp (name, ".MIPS.interfaces") == 0)
2972 hdr->sh_type = SHT_MIPS_IFACE;
2973 hdr->sh_flags |= SHF_MIPS_NOSTRIP;
2975 else if (strncmp (name, ".MIPS.content", strlen (".MIPS.content")) == 0)
2977 hdr->sh_type = SHT_MIPS_CONTENT;
2978 hdr->sh_flags |= SHF_MIPS_NOSTRIP;
2979 /* The sh_info field is set in final_write_processing. */
2981 else if (strcmp (name, MIPS_ELF_OPTIONS_SECTION_NAME (abfd)) == 0)
2983 hdr->sh_type = SHT_MIPS_OPTIONS;
2984 hdr->sh_entsize = 1;
2985 hdr->sh_flags |= SHF_MIPS_NOSTRIP;
2987 else if (strncmp (name, ".debug_", sizeof ".debug_" - 1) == 0)
2988 hdr->sh_type = SHT_MIPS_DWARF;
2989 else if (strcmp (name, ".MIPS.symlib") == 0)
2991 hdr->sh_type = SHT_MIPS_SYMBOL_LIB;
2992 /* The sh_link and sh_info fields are set in
2993 final_write_processing. */
2995 else if (strncmp (name, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2996 || strncmp (name, ".MIPS.post_rel",
2997 sizeof ".MIPS.post_rel" - 1) == 0)
2999 hdr->sh_type = SHT_MIPS_EVENTS;
3000 hdr->sh_flags |= SHF_MIPS_NOSTRIP;
3001 /* The sh_link field is set in final_write_processing. */
3003 else if (strcmp (name, MIPS_ELF_MSYM_SECTION_NAME (abfd)) == 0)
3005 hdr->sh_type = SHT_MIPS_MSYM;
3006 hdr->sh_flags |= SHF_ALLOC;
3007 hdr->sh_entsize = 8;
3010 /* The generic elf_fake_sections will set up REL_HDR using the
3011 default kind of relocations. But, we may actually need both
3012 kinds of relocations, so we set up the second header here. */
3013 if ((sec->flags & SEC_RELOC) != 0)
3015 struct bfd_elf_section_data *esd;
3017 esd = elf_section_data (sec);
3018 BFD_ASSERT (esd->rel_hdr2 == NULL);
3020 = (Elf_Internal_Shdr *) bfd_zalloc (abfd, sizeof (Elf_Internal_Shdr));
3023 _bfd_elf_init_reloc_shdr (abfd, esd->rel_hdr2, sec,
3024 !elf_section_data (sec)->use_rela_p);
3030 /* Given a BFD section, try to locate the corresponding ELF section
3031 index. This is used by both the 32-bit and the 64-bit ABI.
3032 Actually, it's not clear to me that the 64-bit ABI supports these,
3033 but for non-PIC objects we will certainly want support for at least
3034 the .scommon section. */
3037 _bfd_mips_elf_section_from_bfd_section (abfd, hdr, sec, retval)
3038 bfd *abfd ATTRIBUTE_UNUSED;
3039 Elf32_Internal_Shdr *hdr ATTRIBUTE_UNUSED;
3043 if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)
3045 *retval = SHN_MIPS_SCOMMON;
3048 if (strcmp (bfd_get_section_name (abfd, sec), ".acommon") == 0)
3050 *retval = SHN_MIPS_ACOMMON;
3056 /* When are writing out the .options or .MIPS.options section,
3057 remember the bytes we are writing out, so that we can install the
3058 GP value in the section_processing routine. */
3061 _bfd_mips_elf_set_section_contents (abfd, section, location, offset, count)
3066 bfd_size_type count;
3068 if (strcmp (section->name, MIPS_ELF_OPTIONS_SECTION_NAME (abfd)) == 0)
3072 if (elf_section_data (section) == NULL)
3074 section->used_by_bfd =
3075 (PTR) bfd_zalloc (abfd, sizeof (struct bfd_elf_section_data));
3076 if (elf_section_data (section) == NULL)
3079 c = (bfd_byte *) elf_section_data (section)->tdata;
3084 if (section->_cooked_size != 0)
3085 size = section->_cooked_size;
3087 size = section->_raw_size;
3088 c = (bfd_byte *) bfd_zalloc (abfd, size);
3091 elf_section_data (section)->tdata = (PTR) c;
3094 memcpy (c + offset, location, count);
3097 return _bfd_elf_set_section_contents (abfd, section, location, offset,
3101 /* Work over a section just before writing it out. This routine is
3102 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
3103 sections that need the SHF_MIPS_GPREL flag by name; there has to be
3107 _bfd_mips_elf_section_processing (abfd, hdr)
3109 Elf_Internal_Shdr *hdr;
3111 if (hdr->sh_type == SHT_MIPS_REGINFO
3112 && hdr->sh_size > 0)
3116 BFD_ASSERT (hdr->sh_size == sizeof (Elf32_External_RegInfo));
3117 BFD_ASSERT (hdr->contents == NULL);
3120 hdr->sh_offset + sizeof (Elf32_External_RegInfo) - 4,
3123 bfd_h_put_32 (abfd, (bfd_vma) elf_gp (abfd), buf);
3124 if (bfd_write (buf, (bfd_size_type) 1, (bfd_size_type) 4, abfd) != 4)
3128 if (hdr->sh_type == SHT_MIPS_OPTIONS
3129 && hdr->bfd_section != NULL
3130 && elf_section_data (hdr->bfd_section) != NULL
3131 && elf_section_data (hdr->bfd_section)->tdata != NULL)
3133 bfd_byte *contents, *l, *lend;
3135 /* We stored the section contents in the elf_section_data tdata
3136 field in the set_section_contents routine. We save the
3137 section contents so that we don't have to read them again.
3138 At this point we know that elf_gp is set, so we can look
3139 through the section contents to see if there is an
3140 ODK_REGINFO structure. */
3142 contents = (bfd_byte *) elf_section_data (hdr->bfd_section)->tdata;
3144 lend = contents + hdr->sh_size;
3145 while (l + sizeof (Elf_External_Options) <= lend)
3147 Elf_Internal_Options intopt;
3149 bfd_mips_elf_swap_options_in (abfd, (Elf_External_Options *) l,
3151 if (ABI_64_P (abfd) && intopt.kind == ODK_REGINFO)
3158 + sizeof (Elf_External_Options)
3159 + (sizeof (Elf64_External_RegInfo) - 8)),
3162 bfd_h_put_64 (abfd, elf_gp (abfd), buf);
3163 if (bfd_write (buf, 1, 8, abfd) != 8)
3166 else if (intopt.kind == ODK_REGINFO)
3173 + sizeof (Elf_External_Options)
3174 + (sizeof (Elf32_External_RegInfo) - 4)),
3177 bfd_h_put_32 (abfd, elf_gp (abfd), buf);
3178 if (bfd_write (buf, 1, 4, abfd) != 4)
3185 if (hdr->bfd_section != NULL)
3187 const char *name = bfd_get_section_name (abfd, hdr->bfd_section);
3189 if (strcmp (name, ".sdata") == 0
3190 || strcmp (name, ".lit8") == 0
3191 || strcmp (name, ".lit4") == 0)
3193 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
3194 hdr->sh_type = SHT_PROGBITS;
3196 else if (strcmp (name, ".sbss") == 0)
3198 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
3199 hdr->sh_type = SHT_NOBITS;
3201 else if (strcmp (name, MIPS_ELF_SRDATA_SECTION_NAME (abfd)) == 0)
3203 hdr->sh_flags |= SHF_ALLOC | SHF_MIPS_GPREL;
3204 hdr->sh_type = SHT_PROGBITS;
3206 else if (strcmp (name, ".compact_rel") == 0)
3209 hdr->sh_type = SHT_PROGBITS;
3211 else if (strcmp (name, ".rtproc") == 0)
3213 if (hdr->sh_addralign != 0 && hdr->sh_entsize == 0)
3215 unsigned int adjust;
3217 adjust = hdr->sh_size % hdr->sh_addralign;
3219 hdr->sh_size += hdr->sh_addralign - adjust;
3227 /* MIPS ELF uses two common sections. One is the usual one, and the
3228 other is for small objects. All the small objects are kept
3229 together, and then referenced via the gp pointer, which yields
3230 faster assembler code. This is what we use for the small common
3231 section. This approach is copied from ecoff.c. */
3232 static asection mips_elf_scom_section;
3233 static asymbol mips_elf_scom_symbol;
3234 static asymbol *mips_elf_scom_symbol_ptr;
3236 /* MIPS ELF also uses an acommon section, which represents an
3237 allocated common symbol which may be overridden by a
3238 definition in a shared library. */
3239 static asection mips_elf_acom_section;
3240 static asymbol mips_elf_acom_symbol;
3241 static asymbol *mips_elf_acom_symbol_ptr;
3243 /* Handle the special MIPS section numbers that a symbol may use.
3244 This is used for both the 32-bit and the 64-bit ABI. */
3247 _bfd_mips_elf_symbol_processing (abfd, asym)
3251 elf_symbol_type *elfsym;
3253 elfsym = (elf_symbol_type *) asym;
3254 switch (elfsym->internal_elf_sym.st_shndx)
3256 case SHN_MIPS_ACOMMON:
3257 /* This section is used in a dynamically linked executable file.
3258 It is an allocated common section. The dynamic linker can
3259 either resolve these symbols to something in a shared
3260 library, or it can just leave them here. For our purposes,
3261 we can consider these symbols to be in a new section. */
3262 if (mips_elf_acom_section.name == NULL)
3264 /* Initialize the acommon section. */
3265 mips_elf_acom_section.name = ".acommon";
3266 mips_elf_acom_section.flags = SEC_ALLOC;
3267 mips_elf_acom_section.output_section = &mips_elf_acom_section;
3268 mips_elf_acom_section.symbol = &mips_elf_acom_symbol;
3269 mips_elf_acom_section.symbol_ptr_ptr = &mips_elf_acom_symbol_ptr;
3270 mips_elf_acom_symbol.name = ".acommon";
3271 mips_elf_acom_symbol.flags = BSF_SECTION_SYM;
3272 mips_elf_acom_symbol.section = &mips_elf_acom_section;
3273 mips_elf_acom_symbol_ptr = &mips_elf_acom_symbol;
3275 asym->section = &mips_elf_acom_section;
3279 /* Common symbols less than the GP size are automatically
3280 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
3281 if (asym->value > elf_gp_size (abfd)
3282 || IRIX_COMPAT (abfd) == ict_irix6)
3285 case SHN_MIPS_SCOMMON:
3286 if (mips_elf_scom_section.name == NULL)
3288 /* Initialize the small common section. */
3289 mips_elf_scom_section.name = ".scommon";
3290 mips_elf_scom_section.flags = SEC_IS_COMMON;
3291 mips_elf_scom_section.output_section = &mips_elf_scom_section;
3292 mips_elf_scom_section.symbol = &mips_elf_scom_symbol;
3293 mips_elf_scom_section.symbol_ptr_ptr = &mips_elf_scom_symbol_ptr;
3294 mips_elf_scom_symbol.name = ".scommon";
3295 mips_elf_scom_symbol.flags = BSF_SECTION_SYM;
3296 mips_elf_scom_symbol.section = &mips_elf_scom_section;
3297 mips_elf_scom_symbol_ptr = &mips_elf_scom_symbol;
3299 asym->section = &mips_elf_scom_section;
3300 asym->value = elfsym->internal_elf_sym.st_size;
3303 case SHN_MIPS_SUNDEFINED:
3304 asym->section = bfd_und_section_ptr;
3307 #if 0 /* for SGI_COMPAT */
3309 asym->section = mips_elf_text_section_ptr;
3313 asym->section = mips_elf_data_section_ptr;
3319 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
3323 _bfd_mips_elf_additional_program_headers (abfd)
3329 /* See if we need a PT_MIPS_REGINFO segment. */
3330 s = bfd_get_section_by_name (abfd, ".reginfo");
3331 if (s && (s->flags & SEC_LOAD))
3334 /* See if we need a PT_MIPS_OPTIONS segment. */
3335 if (IRIX_COMPAT (abfd) == ict_irix6
3336 && bfd_get_section_by_name (abfd,
3337 MIPS_ELF_OPTIONS_SECTION_NAME (abfd)))
3340 /* See if we need a PT_MIPS_RTPROC segment. */
3341 if (IRIX_COMPAT (abfd) == ict_irix5
3342 && bfd_get_section_by_name (abfd, ".dynamic")
3343 && bfd_get_section_by_name (abfd, ".mdebug"))
3349 /* Modify the segment map for an Irix 5 executable. */
3352 _bfd_mips_elf_modify_segment_map (abfd)
3356 struct elf_segment_map *m, **pm;
3358 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
3360 s = bfd_get_section_by_name (abfd, ".reginfo");
3361 if (s != NULL && (s->flags & SEC_LOAD) != 0)
3363 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
3364 if (m->p_type == PT_MIPS_REGINFO)
3368 m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m);
3372 m->p_type = PT_MIPS_REGINFO;
3376 /* We want to put it after the PHDR and INTERP segments. */
3377 pm = &elf_tdata (abfd)->segment_map;
3379 && ((*pm)->p_type == PT_PHDR
3380 || (*pm)->p_type == PT_INTERP))
3388 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
3389 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
3390 PT_OPTIONS segement immediately following the program header
3392 if (IRIX_COMPAT (abfd) == ict_irix6)
3396 for (s = abfd->sections; s; s = s->next)
3397 if (elf_section_data (s)->this_hdr.sh_type == SHT_MIPS_OPTIONS)
3402 struct elf_segment_map *options_segment;
3404 /* Usually, there's a program header table. But, sometimes
3405 there's not (like when running the `ld' testsuite). So,
3406 if there's no program header table, we just put the
3407 options segement at the end. */
3408 for (pm = &elf_tdata (abfd)->segment_map;
3411 if ((*pm)->p_type == PT_PHDR)
3414 options_segment = bfd_zalloc (abfd,
3415 sizeof (struct elf_segment_map));
3416 options_segment->next = *pm;
3417 options_segment->p_type = PT_MIPS_OPTIONS;
3418 options_segment->p_flags = PF_R;
3419 options_segment->p_flags_valid = true;
3420 options_segment->count = 1;
3421 options_segment->sections[0] = s;
3422 *pm = options_segment;
3427 if (IRIX_COMPAT (abfd) == ict_irix5)
3429 /* If there are .dynamic and .mdebug sections, we make a room
3430 for the RTPROC header. FIXME: Rewrite without section names. */
3431 if (bfd_get_section_by_name (abfd, ".interp") == NULL
3432 && bfd_get_section_by_name (abfd, ".dynamic") != NULL
3433 && bfd_get_section_by_name (abfd, ".mdebug") != NULL)
3435 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
3436 if (m->p_type == PT_MIPS_RTPROC)
3440 m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m);
3444 m->p_type = PT_MIPS_RTPROC;
3446 s = bfd_get_section_by_name (abfd, ".rtproc");
3451 m->p_flags_valid = 1;
3459 /* We want to put it after the DYNAMIC segment. */
3460 pm = &elf_tdata (abfd)->segment_map;
3461 while (*pm != NULL && (*pm)->p_type != PT_DYNAMIC)
3471 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic,
3472 .dynstr, .dynsym, and .hash sections, and everything in
3474 for (pm = &elf_tdata (abfd)->segment_map; *pm != NULL;
3476 if ((*pm)->p_type == PT_DYNAMIC)
3479 if (IRIX_COMPAT (abfd) == ict_none)
3481 /* For a normal mips executable the permissions for the PT_DYNAMIC
3482 segment are read, write and execute. We do that here since
3483 the code in elf.c sets only the read permission. This matters
3484 sometimes for the dynamic linker. */
3485 if (bfd_get_section_by_name (abfd, ".dynamic") != NULL)
3487 m->p_flags = PF_R | PF_W | PF_X;
3488 m->p_flags_valid = 1;
3492 && m->count == 1 && strcmp (m->sections[0]->name, ".dynamic") == 0)
3494 static const char *sec_names[] = {
3495 ".dynamic", ".dynstr", ".dynsym", ".hash"
3499 struct elf_segment_map *n;
3503 for (i = 0; i < sizeof sec_names / sizeof sec_names[0]; i++)
3505 s = bfd_get_section_by_name (abfd, sec_names[i]);
3506 if (s != NULL && (s->flags & SEC_LOAD) != 0)
3512 sz = s->_cooked_size;
3515 if (high < s->vma + sz)
3521 for (s = abfd->sections; s != NULL; s = s->next)
3522 if ((s->flags & SEC_LOAD) != 0
3525 + (s->_cooked_size !=
3526 0 ? s->_cooked_size : s->_raw_size)) <= high))
3529 n = ((struct elf_segment_map *)
3530 bfd_zalloc (abfd, sizeof *n + (c - 1) * sizeof (asection *)));
3537 for (s = abfd->sections; s != NULL; s = s->next)
3539 if ((s->flags & SEC_LOAD) != 0
3542 + (s->_cooked_size != 0 ?
3543 s->_cooked_size : s->_raw_size)) <= high))
3557 /* The structure of the runtime procedure descriptor created by the
3558 loader for use by the static exception system. */
3560 typedef struct runtime_pdr {
3561 bfd_vma adr; /* memory address of start of procedure */
3562 long regmask; /* save register mask */
3563 long regoffset; /* save register offset */
3564 long fregmask; /* save floating point register mask */
3565 long fregoffset; /* save floating point register offset */
3566 long frameoffset; /* frame size */
3567 short framereg; /* frame pointer register */
3568 short pcreg; /* offset or reg of return pc */
3569 long irpss; /* index into the runtime string table */
3571 struct exception_info *exception_info;/* pointer to exception array */
3573 #define cbRPDR sizeof (RPDR)
3574 #define rpdNil ((pRPDR) 0)
3576 /* Swap RPDR (runtime procedure table entry) for output. */
3578 static void ecoff_swap_rpdr_out
3579 PARAMS ((bfd *, const RPDR *, struct rpdr_ext *));
3582 ecoff_swap_rpdr_out (abfd, in, ex)
3585 struct rpdr_ext *ex;
3587 /* ecoff_put_off was defined in ecoffswap.h. */
3588 ecoff_put_off (abfd, in->adr, (bfd_byte *) ex->p_adr);
3589 bfd_h_put_32 (abfd, in->regmask, (bfd_byte *) ex->p_regmask);
3590 bfd_h_put_32 (abfd, in->regoffset, (bfd_byte *) ex->p_regoffset);
3591 bfd_h_put_32 (abfd, in->fregmask, (bfd_byte *) ex->p_fregmask);
3592 bfd_h_put_32 (abfd, in->fregoffset, (bfd_byte *) ex->p_fregoffset);
3593 bfd_h_put_32 (abfd, in->frameoffset, (bfd_byte *) ex->p_frameoffset);
3595 bfd_h_put_16 (abfd, in->framereg, (bfd_byte *) ex->p_framereg);
3596 bfd_h_put_16 (abfd, in->pcreg, (bfd_byte *) ex->p_pcreg);
3598 bfd_h_put_32 (abfd, in->irpss, (bfd_byte *) ex->p_irpss);
3600 ecoff_put_off (abfd, in->exception_info, (bfd_byte *) ex->p_exception_info);
3604 /* Read ECOFF debugging information from a .mdebug section into a
3605 ecoff_debug_info structure. */
3608 _bfd_mips_elf_read_ecoff_info (abfd, section, debug)
3611 struct ecoff_debug_info *debug;
3614 const struct ecoff_debug_swap *swap;
3615 char *ext_hdr = NULL;
3617 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
3618 memset (debug, 0, sizeof (*debug));
3620 ext_hdr = (char *) bfd_malloc ((size_t) swap->external_hdr_size);
3621 if (ext_hdr == NULL && swap->external_hdr_size != 0)
3624 if (bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0,
3625 swap->external_hdr_size)
3629 symhdr = &debug->symbolic_header;
3630 (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr);
3632 /* The symbolic header contains absolute file offsets and sizes to
3634 #define READ(ptr, offset, count, size, type) \
3635 if (symhdr->count == 0) \
3636 debug->ptr = NULL; \
3639 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
3640 if (debug->ptr == NULL) \
3641 goto error_return; \
3642 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3643 || (bfd_read (debug->ptr, size, symhdr->count, \
3644 abfd) != size * symhdr->count)) \
3645 goto error_return; \
3648 READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *);
3649 READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR);
3650 READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR);
3651 READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR);
3652 READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR);
3653 READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext),
3655 READ (ss, cbSsOffset, issMax, sizeof (char), char *);
3656 READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *);
3657 READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR);
3658 READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR);
3659 READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR);
3663 debug->adjust = NULL;
3668 if (ext_hdr != NULL)
3670 if (debug->line != NULL)
3672 if (debug->external_dnr != NULL)
3673 free (debug->external_dnr);
3674 if (debug->external_pdr != NULL)
3675 free (debug->external_pdr);
3676 if (debug->external_sym != NULL)
3677 free (debug->external_sym);
3678 if (debug->external_opt != NULL)
3679 free (debug->external_opt);
3680 if (debug->external_aux != NULL)
3681 free (debug->external_aux);
3682 if (debug->ss != NULL)
3684 if (debug->ssext != NULL)
3685 free (debug->ssext);
3686 if (debug->external_fdr != NULL)
3687 free (debug->external_fdr);
3688 if (debug->external_rfd != NULL)
3689 free (debug->external_rfd);
3690 if (debug->external_ext != NULL)
3691 free (debug->external_ext);
3695 /* MIPS ELF local labels start with '$', not 'L'. */
3698 mips_elf_is_local_label_name (abfd, name)
3705 /* On Irix 6, the labels go back to starting with '.', so we accept
3706 the generic ELF local label syntax as well. */
3707 return _bfd_elf_is_local_label_name (abfd, name);
3710 /* MIPS ELF uses a special find_nearest_line routine in order the
3711 handle the ECOFF debugging information. */
3713 struct mips_elf_find_line {
3714 struct ecoff_debug_info d;
3715 struct ecoff_find_line i;
3719 _bfd_mips_elf_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
3720 functionname_ptr, line_ptr)
3725 const char **filename_ptr;
3726 const char **functionname_ptr;
3727 unsigned int *line_ptr;
3731 if (_bfd_dwarf1_find_nearest_line (abfd, section, symbols, offset,
3732 filename_ptr, functionname_ptr,
3736 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
3737 filename_ptr, functionname_ptr,
3739 ABI_64_P (abfd) ? 8 : 0, NULL))
3742 msec = bfd_get_section_by_name (abfd, ".mdebug");
3746 struct mips_elf_find_line *fi;
3747 const struct ecoff_debug_swap * const swap =
3748 get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
3750 /* If we are called during a link, mips_elf_final_link may have
3751 cleared the SEC_HAS_CONTENTS field. We force it back on here
3752 if appropriate (which it normally will be). */
3753 origflags = msec->flags;
3754 if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS)
3755 msec->flags |= SEC_HAS_CONTENTS;
3757 fi = elf_tdata (abfd)->find_line_info;
3760 bfd_size_type external_fdr_size;
3763 struct fdr *fdr_ptr;
3765 fi = ((struct mips_elf_find_line *)
3766 bfd_zalloc (abfd, sizeof (struct mips_elf_find_line)));
3769 msec->flags = origflags;
3773 if (! _bfd_mips_elf_read_ecoff_info (abfd, msec, &fi->d))
3775 msec->flags = origflags;
3779 /* Swap in the FDR information. */
3780 fi->d.fdr = ((struct fdr *)
3782 (fi->d.symbolic_header.ifdMax *
3783 sizeof (struct fdr))));
3784 if (fi->d.fdr == NULL)
3786 msec->flags = origflags;
3789 external_fdr_size = swap->external_fdr_size;
3790 fdr_ptr = fi->d.fdr;
3791 fraw_src = (char *) fi->d.external_fdr;
3792 fraw_end = (fraw_src
3793 + fi->d.symbolic_header.ifdMax * external_fdr_size);
3794 for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
3795 (*swap->swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr);
3797 elf_tdata (abfd)->find_line_info = fi;
3799 /* Note that we don't bother to ever free this information.
3800 find_nearest_line is either called all the time, as in
3801 objdump -l, so the information should be saved, or it is
3802 rarely called, as in ld error messages, so the memory
3803 wasted is unimportant. Still, it would probably be a
3804 good idea for free_cached_info to throw it away. */
3807 if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap,
3808 &fi->i, filename_ptr, functionname_ptr,
3811 msec->flags = origflags;
3815 msec->flags = origflags;
3818 /* Fall back on the generic ELF find_nearest_line routine. */
3820 return _bfd_elf_find_nearest_line (abfd, section, symbols, offset,
3821 filename_ptr, functionname_ptr,
3825 /* The mips16 compiler uses a couple of special sections to handle
3826 floating point arguments.
3828 Section names that look like .mips16.fn.FNNAME contain stubs that
3829 copy floating point arguments from the fp regs to the gp regs and
3830 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3831 call should be redirected to the stub instead. If no 32 bit
3832 function calls FNNAME, the stub should be discarded. We need to
3833 consider any reference to the function, not just a call, because
3834 if the address of the function is taken we will need the stub,
3835 since the address might be passed to a 32 bit function.
3837 Section names that look like .mips16.call.FNNAME contain stubs
3838 that copy floating point arguments from the gp regs to the fp
3839 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3840 then any 16 bit function that calls FNNAME should be redirected
3841 to the stub instead. If FNNAME is not a 32 bit function, the
3842 stub should be discarded.
3844 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3845 which call FNNAME and then copy the return value from the fp regs
3846 to the gp regs. These stubs store the return value in $18 while
3847 calling FNNAME; any function which might call one of these stubs
3848 must arrange to save $18 around the call. (This case is not
3849 needed for 32 bit functions that call 16 bit functions, because
3850 16 bit functions always return floating point values in both
3853 Note that in all cases FNNAME might be defined statically.
3854 Therefore, FNNAME is not used literally. Instead, the relocation
3855 information will indicate which symbol the section is for.
3857 We record any stubs that we find in the symbol table. */
3859 #define FN_STUB ".mips16.fn."
3860 #define CALL_STUB ".mips16.call."
3861 #define CALL_FP_STUB ".mips16.call.fp."
3863 /* MIPS ELF linker hash table. */
3865 struct mips_elf_link_hash_table {
3866 struct elf_link_hash_table root;
3868 /* We no longer use this. */
3869 /* String section indices for the dynamic section symbols. */
3870 bfd_size_type dynsym_sec_strindex[SIZEOF_MIPS_DYNSYM_SECNAMES];
3872 /* The number of .rtproc entries. */
3873 bfd_size_type procedure_count;
3874 /* The size of the .compact_rel section (if SGI_COMPAT). */
3875 bfd_size_type compact_rel_size;
3876 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3877 entry is set to the address of __rld_obj_head as in Irix 5. */
3878 boolean use_rld_obj_head;
3879 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3881 /* This is set if we see any mips16 stub sections. */
3882 boolean mips16_stubs_seen;
3885 /* Look up an entry in a MIPS ELF linker hash table. */
3887 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3888 ((struct mips_elf_link_hash_entry *) \
3889 elf_link_hash_lookup (&(table)->root, (string), (create), \
3892 /* Traverse a MIPS ELF linker hash table. */
3894 #define mips_elf_link_hash_traverse(table, func, info) \
3895 (elf_link_hash_traverse \
3897 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3900 /* Get the MIPS ELF linker hash table from a link_info structure. */
3902 #define mips_elf_hash_table(p) \
3903 ((struct mips_elf_link_hash_table *) ((p)->hash))
3905 static boolean mips_elf_output_extsym
3906 PARAMS ((struct mips_elf_link_hash_entry *, PTR));
3908 /* Create an entry in a MIPS ELF linker hash table. */
3910 static struct bfd_hash_entry *
3911 mips_elf_link_hash_newfunc (entry, table, string)
3912 struct bfd_hash_entry *entry;
3913 struct bfd_hash_table *table;
3916 struct mips_elf_link_hash_entry *ret =
3917 (struct mips_elf_link_hash_entry *) entry;
3919 /* Allocate the structure if it has not already been allocated by a
3921 if (ret == (struct mips_elf_link_hash_entry *) NULL)
3922 ret = ((struct mips_elf_link_hash_entry *)
3923 bfd_hash_allocate (table,
3924 sizeof (struct mips_elf_link_hash_entry)));
3925 if (ret == (struct mips_elf_link_hash_entry *) NULL)
3926 return (struct bfd_hash_entry *) ret;
3928 /* Call the allocation method of the superclass. */
3929 ret = ((struct mips_elf_link_hash_entry *)
3930 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
3932 if (ret != (struct mips_elf_link_hash_entry *) NULL)
3934 /* Set local fields. */
3935 memset (&ret->esym, 0, sizeof (EXTR));
3936 /* We use -2 as a marker to indicate that the information has
3937 not been set. -1 means there is no associated ifd. */
3939 ret->possibly_dynamic_relocs = 0;
3940 ret->min_dyn_reloc_index = 0;
3941 ret->fn_stub = NULL;
3942 ret->need_fn_stub = false;
3943 ret->call_stub = NULL;
3944 ret->call_fp_stub = NULL;
3947 return (struct bfd_hash_entry *) ret;
3951 _bfd_mips_elf_hide_symbol (info, h)
3952 struct bfd_link_info *info;
3953 struct mips_elf_link_hash_entry *h;
3957 struct mips_got_info *g;
3958 dynobj = elf_hash_table (info)->dynobj;
3959 got = bfd_get_section_by_name (dynobj, ".got");
3960 g = (struct mips_got_info *) elf_section_data (got)->tdata;
3962 h->root.elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3963 h->root.plt.offset = (bfd_vma) -1;
3964 h->root.dynindx = -1;
3966 /* FIXME: Do we allocate too much GOT space here? */
3968 got->_raw_size += MIPS_ELF_GOT_SIZE (dynobj);
3971 /* Create a MIPS ELF linker hash table. */
3973 struct bfd_link_hash_table *
3974 _bfd_mips_elf_link_hash_table_create (abfd)
3977 struct mips_elf_link_hash_table *ret;
3979 ret = ((struct mips_elf_link_hash_table *)
3980 bfd_alloc (abfd, sizeof (struct mips_elf_link_hash_table)));
3981 if (ret == (struct mips_elf_link_hash_table *) NULL)
3984 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
3985 mips_elf_link_hash_newfunc))
3987 bfd_release (abfd, ret);
3992 /* We no longer use this. */
3993 for (i = 0; i < SIZEOF_MIPS_DYNSYM_SECNAMES; i++)
3994 ret->dynsym_sec_strindex[i] = (bfd_size_type) -1;
3996 ret->procedure_count = 0;
3997 ret->compact_rel_size = 0;
3998 ret->use_rld_obj_head = false;
4000 ret->mips16_stubs_seen = false;
4002 return &ret->root.root;
4005 /* Hook called by the linker routine which adds symbols from an object
4006 file. We must handle the special MIPS section numbers here. */
4009 _bfd_mips_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
4011 struct bfd_link_info *info;
4012 const Elf_Internal_Sym *sym;
4014 flagword *flagsp ATTRIBUTE_UNUSED;
4018 if (SGI_COMPAT (abfd)
4019 && (abfd->flags & DYNAMIC) != 0
4020 && strcmp (*namep, "_rld_new_interface") == 0)
4022 /* Skip Irix 5 rld entry name. */
4027 switch (sym->st_shndx)
4030 /* Common symbols less than the GP size are automatically
4031 treated as SHN_MIPS_SCOMMON symbols. */
4032 if (sym->st_size > elf_gp_size (abfd)
4033 || IRIX_COMPAT (abfd) == ict_irix6)
4036 case SHN_MIPS_SCOMMON:
4037 *secp = bfd_make_section_old_way (abfd, ".scommon");
4038 (*secp)->flags |= SEC_IS_COMMON;
4039 *valp = sym->st_size;
4043 /* This section is used in a shared object. */
4044 if (elf_tdata (abfd)->elf_text_section == NULL)
4046 asymbol *elf_text_symbol;
4047 asection *elf_text_section;
4049 elf_text_section = bfd_zalloc (abfd, sizeof (asection));
4050 if (elf_text_section == NULL)
4053 elf_text_symbol = bfd_zalloc (abfd, sizeof (asymbol));
4054 if (elf_text_symbol == NULL)
4057 /* Initialize the section. */
4059 elf_tdata (abfd)->elf_text_section = elf_text_section;
4060 elf_tdata (abfd)->elf_text_symbol = elf_text_symbol;
4062 elf_text_section->symbol = elf_text_symbol;
4063 elf_text_section->symbol_ptr_ptr = &elf_tdata (abfd)->elf_text_symbol;
4065 elf_text_section->name = ".text";
4066 elf_text_section->flags = SEC_NO_FLAGS;
4067 elf_text_section->output_section = NULL;
4068 elf_text_section->owner = abfd;
4069 elf_text_symbol->name = ".text";
4070 elf_text_symbol->flags = BSF_SECTION_SYM | BSF_DYNAMIC;
4071 elf_text_symbol->section = elf_text_section;
4073 /* This code used to do *secp = bfd_und_section_ptr if
4074 info->shared. I don't know why, and that doesn't make sense,
4075 so I took it out. */
4076 *secp = elf_tdata (abfd)->elf_text_section;
4079 case SHN_MIPS_ACOMMON:
4080 /* Fall through. XXX Can we treat this as allocated data? */
4082 /* This section is used in a shared object. */
4083 if (elf_tdata (abfd)->elf_data_section == NULL)
4085 asymbol *elf_data_symbol;
4086 asection *elf_data_section;
4088 elf_data_section = bfd_zalloc (abfd, sizeof (asection));
4089 if (elf_data_section == NULL)
4092 elf_data_symbol = bfd_zalloc (abfd, sizeof (asymbol));
4093 if (elf_data_symbol == NULL)
4096 /* Initialize the section. */
4098 elf_tdata (abfd)->elf_data_section = elf_data_section;
4099 elf_tdata (abfd)->elf_data_symbol = elf_data_symbol;
4101 elf_data_section->symbol = elf_data_symbol;
4102 elf_data_section->symbol_ptr_ptr = &elf_tdata (abfd)->elf_data_symbol;
4104 elf_data_section->name = ".data";
4105 elf_data_section->flags = SEC_NO_FLAGS;
4106 elf_data_section->output_section = NULL;
4107 elf_data_section->owner = abfd;
4108 elf_data_symbol->name = ".data";
4109 elf_data_symbol->flags = BSF_SECTION_SYM | BSF_DYNAMIC;
4110 elf_data_symbol->section = elf_data_section;
4112 /* This code used to do *secp = bfd_und_section_ptr if
4113 info->shared. I don't know why, and that doesn't make sense,
4114 so I took it out. */
4115 *secp = elf_tdata (abfd)->elf_data_section;
4118 case SHN_MIPS_SUNDEFINED:
4119 *secp = bfd_und_section_ptr;
4123 if (SGI_COMPAT (abfd)
4125 && info->hash->creator == abfd->xvec
4126 && strcmp (*namep, "__rld_obj_head") == 0)
4128 struct elf_link_hash_entry *h;
4130 /* Mark __rld_obj_head as dynamic. */
4132 if (! (_bfd_generic_link_add_one_symbol
4133 (info, abfd, *namep, BSF_GLOBAL, *secp,
4134 (bfd_vma) *valp, (const char *) NULL, false,
4135 get_elf_backend_data (abfd)->collect,
4136 (struct bfd_link_hash_entry **) &h)))
4138 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
4139 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
4140 h->type = STT_OBJECT;
4142 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
4145 mips_elf_hash_table (info)->use_rld_obj_head = true;
4148 /* If this is a mips16 text symbol, add 1 to the value to make it
4149 odd. This will cause something like .word SYM to come up with
4150 the right value when it is loaded into the PC. */
4151 if (sym->st_other == STO_MIPS16)
4157 /* Structure used to pass information to mips_elf_output_extsym. */
4159 struct extsym_info {
4161 struct bfd_link_info *info;
4162 struct ecoff_debug_info *debug;
4163 const struct ecoff_debug_swap *swap;
4167 /* This routine is used to write out ECOFF debugging external symbol
4168 information. It is called via mips_elf_link_hash_traverse. The
4169 ECOFF external symbol information must match the ELF external
4170 symbol information. Unfortunately, at this point we don't know
4171 whether a symbol is required by reloc information, so the two
4172 tables may wind up being different. We must sort out the external
4173 symbol information before we can set the final size of the .mdebug
4174 section, and we must set the size of the .mdebug section before we
4175 can relocate any sections, and we can't know which symbols are
4176 required by relocation until we relocate the sections.
4177 Fortunately, it is relatively unlikely that any symbol will be
4178 stripped but required by a reloc. In particular, it can not happen
4179 when generating a final executable. */
4182 mips_elf_output_extsym (h, data)
4183 struct mips_elf_link_hash_entry *h;
4186 struct extsym_info *einfo = (struct extsym_info *) data;
4188 asection *sec, *output_section;
4190 if (h->root.indx == -2)
4192 else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
4193 || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)
4194 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
4195 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
4197 else if (einfo->info->strip == strip_all
4198 || (einfo->info->strip == strip_some
4199 && bfd_hash_lookup (einfo->info->keep_hash,
4200 h->root.root.root.string,
4201 false, false) == NULL))
4209 if (h->esym.ifd == -2)
4212 h->esym.cobol_main = 0;
4213 h->esym.weakext = 0;
4214 h->esym.reserved = 0;
4215 h->esym.ifd = ifdNil;
4216 h->esym.asym.value = 0;
4217 h->esym.asym.st = stGlobal;
4219 if (h->root.root.type == bfd_link_hash_undefined
4220 || h->root.root.type == bfd_link_hash_undefweak)
4224 /* Use undefined class. Also, set class and type for some
4226 name = h->root.root.root.string;
4227 if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0
4228 || strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0)
4230 h->esym.asym.sc = scData;
4231 h->esym.asym.st = stLabel;
4232 h->esym.asym.value = 0;
4234 else if (strcmp (name, mips_elf_dynsym_rtproc_names[2]) == 0)
4236 h->esym.asym.sc = scAbs;
4237 h->esym.asym.st = stLabel;
4238 h->esym.asym.value =
4239 mips_elf_hash_table (einfo->info)->procedure_count;
4241 else if (strcmp (name, "_gp_disp") == 0)
4243 h->esym.asym.sc = scAbs;
4244 h->esym.asym.st = stLabel;
4245 h->esym.asym.value = elf_gp (einfo->abfd);
4248 h->esym.asym.sc = scUndefined;
4250 else if (h->root.root.type != bfd_link_hash_defined
4251 && h->root.root.type != bfd_link_hash_defweak)
4252 h->esym.asym.sc = scAbs;
4257 sec = h->root.root.u.def.section;
4258 output_section = sec->output_section;
4260 /* When making a shared library and symbol h is the one from
4261 the another shared library, OUTPUT_SECTION may be null. */
4262 if (output_section == NULL)
4263 h->esym.asym.sc = scUndefined;
4266 name = bfd_section_name (output_section->owner, output_section);
4268 if (strcmp (name, ".text") == 0)
4269 h->esym.asym.sc = scText;
4270 else if (strcmp (name, ".data") == 0)
4271 h->esym.asym.sc = scData;
4272 else if (strcmp (name, ".sdata") == 0)
4273 h->esym.asym.sc = scSData;
4274 else if (strcmp (name, ".rodata") == 0
4275 || strcmp (name, ".rdata") == 0)
4276 h->esym.asym.sc = scRData;
4277 else if (strcmp (name, ".bss") == 0)
4278 h->esym.asym.sc = scBss;
4279 else if (strcmp (name, ".sbss") == 0)
4280 h->esym.asym.sc = scSBss;
4281 else if (strcmp (name, ".init") == 0)
4282 h->esym.asym.sc = scInit;
4283 else if (strcmp (name, ".fini") == 0)
4284 h->esym.asym.sc = scFini;
4286 h->esym.asym.sc = scAbs;
4290 h->esym.asym.reserved = 0;
4291 h->esym.asym.index = indexNil;
4294 if (h->root.root.type == bfd_link_hash_common)
4295 h->esym.asym.value = h->root.root.u.c.size;
4296 else if (h->root.root.type == bfd_link_hash_defined
4297 || h->root.root.type == bfd_link_hash_defweak)
4299 if (h->esym.asym.sc == scCommon)
4300 h->esym.asym.sc = scBss;
4301 else if (h->esym.asym.sc == scSCommon)
4302 h->esym.asym.sc = scSBss;
4304 sec = h->root.root.u.def.section;
4305 output_section = sec->output_section;
4306 if (output_section != NULL)
4307 h->esym.asym.value = (h->root.root.u.def.value
4308 + sec->output_offset
4309 + output_section->vma);
4311 h->esym.asym.value = 0;
4313 else if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
4315 /* Set type and value for a symbol with a function stub. */
4316 h->esym.asym.st = stProc;
4317 sec = h->root.root.u.def.section;
4319 h->esym.asym.value = 0;
4322 output_section = sec->output_section;
4323 if (output_section != NULL)
4324 h->esym.asym.value = (h->root.plt.offset
4325 + sec->output_offset
4326 + output_section->vma);
4328 h->esym.asym.value = 0;
4335 if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap,
4336 h->root.root.root.string,
4339 einfo->failed = true;
4346 /* Create a runtime procedure table from the .mdebug section. */
4349 mips_elf_create_procedure_table (handle, abfd, info, s, debug)
4352 struct bfd_link_info *info;
4354 struct ecoff_debug_info *debug;
4356 const struct ecoff_debug_swap *swap;
4357 HDRR *hdr = &debug->symbolic_header;
4359 struct rpdr_ext *erp;
4361 struct pdr_ext *epdr;
4362 struct sym_ext *esym;
4365 unsigned long size, count;
4366 unsigned long sindex;
4370 const char *no_name_func = _("static procedure (no name)");
4378 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
4380 sindex = strlen (no_name_func) + 1;
4381 count = hdr->ipdMax;
4384 size = swap->external_pdr_size;
4386 epdr = (struct pdr_ext *) bfd_malloc (size * count);
4390 if (! _bfd_ecoff_get_accumulated_pdr (handle, (PTR) epdr))
4393 size = sizeof (RPDR);
4394 rp = rpdr = (RPDR *) bfd_malloc (size * count);
4398 sv = (char **) bfd_malloc (sizeof (char *) * count);
4402 count = hdr->isymMax;
4403 size = swap->external_sym_size;
4404 esym = (struct sym_ext *) bfd_malloc (size * count);
4408 if (! _bfd_ecoff_get_accumulated_sym (handle, (PTR) esym))
4411 count = hdr->issMax;
4412 ss = (char *) bfd_malloc (count);
4415 if (! _bfd_ecoff_get_accumulated_ss (handle, (PTR) ss))
4418 count = hdr->ipdMax;
4419 for (i = 0; i < count; i++, rp++)
4421 (*swap->swap_pdr_in) (abfd, (PTR) (epdr + i), &pdr);
4422 (*swap->swap_sym_in) (abfd, (PTR) &esym[pdr.isym], &sym);
4423 rp->adr = sym.value;
4424 rp->regmask = pdr.regmask;
4425 rp->regoffset = pdr.regoffset;
4426 rp->fregmask = pdr.fregmask;
4427 rp->fregoffset = pdr.fregoffset;
4428 rp->frameoffset = pdr.frameoffset;
4429 rp->framereg = pdr.framereg;
4430 rp->pcreg = pdr.pcreg;
4432 sv[i] = ss + sym.iss;
4433 sindex += strlen (sv[i]) + 1;
4437 size = sizeof (struct rpdr_ext) * (count + 2) + sindex;
4438 size = BFD_ALIGN (size, 16);
4439 rtproc = (PTR) bfd_alloc (abfd, size);
4442 mips_elf_hash_table (info)->procedure_count = 0;
4446 mips_elf_hash_table (info)->procedure_count = count + 2;
4448 erp = (struct rpdr_ext *) rtproc;
4449 memset (erp, 0, sizeof (struct rpdr_ext));
4451 str = (char *) rtproc + sizeof (struct rpdr_ext) * (count + 2);
4452 strcpy (str, no_name_func);
4453 str += strlen (no_name_func) + 1;
4454 for (i = 0; i < count; i++)
4456 ecoff_swap_rpdr_out (abfd, rpdr + i, erp + i);
4457 strcpy (str, sv[i]);
4458 str += strlen (sv[i]) + 1;
4460 ecoff_put_off (abfd, (bfd_vma) -1, (bfd_byte *) (erp + count)->p_adr);
4462 /* Set the size and contents of .rtproc section. */
4463 s->_raw_size = size;
4464 s->contents = (bfd_byte *) rtproc;
4466 /* Skip this section later on (I don't think this currently
4467 matters, but someday it might). */
4468 s->link_order_head = (struct bfd_link_order *) NULL;
4497 /* A comparison routine used to sort .gptab entries. */
4500 gptab_compare (p1, p2)
4504 const Elf32_gptab *a1 = (const Elf32_gptab *) p1;
4505 const Elf32_gptab *a2 = (const Elf32_gptab *) p2;
4507 return a1->gt_entry.gt_g_value - a2->gt_entry.gt_g_value;
4510 /* We need to use a special link routine to handle the .reginfo and
4511 the .mdebug sections. We need to merge all instances of these
4512 sections together, not write them all out sequentially. */
4515 _bfd_mips_elf_final_link (abfd, info)
4517 struct bfd_link_info *info;
4521 struct bfd_link_order *p;
4522 asection *reginfo_sec, *mdebug_sec, *gptab_data_sec, *gptab_bss_sec;
4523 asection *rtproc_sec;
4524 Elf32_RegInfo reginfo;
4525 struct ecoff_debug_info debug;
4526 const struct ecoff_debug_swap *swap
4527 = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
4528 HDRR *symhdr = &debug.symbolic_header;
4529 PTR mdebug_handle = NULL;
4534 static const char * const name[] = {
4535 ".text", ".init", ".fini", ".data",
4536 ".rodata", ".sdata", ".sbss", ".bss"
4538 static const int sc[] = {
4539 scText, scInit, scFini, scData,
4540 scRData, scSData, scSBss, scBss
4543 /* If all the things we linked together were PIC, but we're
4544 producing an executable (rather than a shared object), then the
4545 resulting file is CPIC (i.e., it calls PIC code.) */
4547 && !info->relocateable
4548 && elf_elfheader (abfd)->e_flags & EF_MIPS_PIC)
4550 elf_elfheader (abfd)->e_flags &= ~EF_MIPS_PIC;
4551 elf_elfheader (abfd)->e_flags |= EF_MIPS_CPIC;
4554 /* We'd carefully arranged the dynamic symbol indices, and then the
4555 generic size_dynamic_sections renumbered them out from under us.
4556 Rather than trying somehow to prevent the renumbering, just do
4558 if (elf_hash_table (info)->dynamic_sections_created)
4562 struct mips_got_info *g;
4564 /* When we resort, we must tell mips_elf_sort_hash_table what
4565 the lowest index it may use is. That's the number of section
4566 symbols we're going to add. The generic ELF linker only
4567 adds these symbols when building a shared object. Note that
4568 we count the sections after (possibly) removing the .options
4570 if (!mips_elf_sort_hash_table (info, (info->shared
4571 ? bfd_count_sections (abfd) + 1
4575 /* Make sure we didn't grow the global .got region. */
4576 dynobj = elf_hash_table (info)->dynobj;
4577 got = bfd_get_section_by_name (dynobj, ".got");
4578 g = (struct mips_got_info *) elf_section_data (got)->tdata;
4580 if (g->global_gotsym != NULL)
4581 BFD_ASSERT ((elf_hash_table (info)->dynsymcount
4582 - g->global_gotsym->dynindx)
4583 <= g->global_gotno);
4586 /* On IRIX5, we omit the .options section. On IRIX6, however, we
4587 include it, even though we don't process it quite right. (Some
4588 entries are supposed to be merged.) Empirically, we seem to be
4589 better off including it then not. */
4590 if (IRIX_COMPAT (abfd) == ict_irix5 || IRIX_COMPAT (abfd) == ict_none)
4591 for (secpp = &abfd->sections; *secpp != NULL; secpp = &(*secpp)->next)
4593 if (strcmp ((*secpp)->name, MIPS_ELF_OPTIONS_SECTION_NAME (abfd)) == 0)
4595 for (p = (*secpp)->link_order_head; p != NULL; p = p->next)
4596 if (p->type == bfd_indirect_link_order)
4597 p->u.indirect.section->flags &= ~SEC_HAS_CONTENTS;
4598 (*secpp)->link_order_head = NULL;
4599 *secpp = (*secpp)->next;
4600 --abfd->section_count;
4606 /* Get a value for the GP register. */
4607 if (elf_gp (abfd) == 0)
4609 struct bfd_link_hash_entry *h;
4611 h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true);
4612 if (h != (struct bfd_link_hash_entry *) NULL
4613 && h->type == bfd_link_hash_defined)
4614 elf_gp (abfd) = (h->u.def.value
4615 + h->u.def.section->output_section->vma
4616 + h->u.def.section->output_offset);
4617 else if (info->relocateable)
4621 /* Find the GP-relative section with the lowest offset. */
4623 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
4625 && (elf_section_data (o)->this_hdr.sh_flags & SHF_MIPS_GPREL))
4628 /* And calculate GP relative to that. */
4629 elf_gp (abfd) = lo + ELF_MIPS_GP_OFFSET (abfd);
4633 /* If the relocate_section function needs to do a reloc
4634 involving the GP value, it should make a reloc_dangerous
4635 callback to warn that GP is not defined. */
4639 /* Go through the sections and collect the .reginfo and .mdebug
4643 gptab_data_sec = NULL;
4644 gptab_bss_sec = NULL;
4645 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
4647 if (strcmp (o->name, ".reginfo") == 0)
4649 memset (®info, 0, sizeof reginfo);
4651 /* We have found the .reginfo section in the output file.
4652 Look through all the link_orders comprising it and merge
4653 the information together. */
4654 for (p = o->link_order_head;
4655 p != (struct bfd_link_order *) NULL;
4658 asection *input_section;
4660 Elf32_External_RegInfo ext;
4663 if (p->type != bfd_indirect_link_order)
4665 if (p->type == bfd_fill_link_order)
4670 input_section = p->u.indirect.section;
4671 input_bfd = input_section->owner;
4673 /* The linker emulation code has probably clobbered the
4674 size to be zero bytes. */
4675 if (input_section->_raw_size == 0)
4676 input_section->_raw_size = sizeof (Elf32_External_RegInfo);
4678 if (! bfd_get_section_contents (input_bfd, input_section,
4684 bfd_mips_elf32_swap_reginfo_in (input_bfd, &ext, &sub);
4686 reginfo.ri_gprmask |= sub.ri_gprmask;
4687 reginfo.ri_cprmask[0] |= sub.ri_cprmask[0];
4688 reginfo.ri_cprmask[1] |= sub.ri_cprmask[1];
4689 reginfo.ri_cprmask[2] |= sub.ri_cprmask[2];
4690 reginfo.ri_cprmask[3] |= sub.ri_cprmask[3];
4692 /* ri_gp_value is set by the function
4693 mips_elf32_section_processing when the section is
4694 finally written out. */
4696 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4697 elf_link_input_bfd ignores this section. */
4698 input_section->flags &= ~SEC_HAS_CONTENTS;
4701 /* Size has been set in mips_elf_always_size_sections */
4702 BFD_ASSERT(o->_raw_size == sizeof (Elf32_External_RegInfo));
4704 /* Skip this section later on (I don't think this currently
4705 matters, but someday it might). */
4706 o->link_order_head = (struct bfd_link_order *) NULL;
4711 if (strcmp (o->name, ".mdebug") == 0)
4713 struct extsym_info einfo;
4715 /* We have found the .mdebug section in the output file.
4716 Look through all the link_orders comprising it and merge
4717 the information together. */
4718 symhdr->magic = swap->sym_magic;
4719 /* FIXME: What should the version stamp be? */
4721 symhdr->ilineMax = 0;
4725 symhdr->isymMax = 0;
4726 symhdr->ioptMax = 0;
4727 symhdr->iauxMax = 0;
4729 symhdr->issExtMax = 0;
4732 symhdr->iextMax = 0;
4734 /* We accumulate the debugging information itself in the
4735 debug_info structure. */
4737 debug.external_dnr = NULL;
4738 debug.external_pdr = NULL;
4739 debug.external_sym = NULL;
4740 debug.external_opt = NULL;
4741 debug.external_aux = NULL;
4743 debug.ssext = debug.ssext_end = NULL;
4744 debug.external_fdr = NULL;
4745 debug.external_rfd = NULL;
4746 debug.external_ext = debug.external_ext_end = NULL;
4748 mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info);
4749 if (mdebug_handle == (PTR) NULL)
4753 esym.cobol_main = 0;
4757 esym.asym.iss = issNil;
4758 esym.asym.st = stLocal;
4759 esym.asym.reserved = 0;
4760 esym.asym.index = indexNil;
4762 for (i = 0; i < 8; i++)
4764 esym.asym.sc = sc[i];
4765 s = bfd_get_section_by_name (abfd, name[i]);
4768 esym.asym.value = s->vma;
4769 last = s->vma + s->_raw_size;
4772 esym.asym.value = last;
4773 if (!bfd_ecoff_debug_one_external (abfd, &debug, swap,
4778 for (p = o->link_order_head;
4779 p != (struct bfd_link_order *) NULL;
4782 asection *input_section;
4784 const struct ecoff_debug_swap *input_swap;
4785 struct ecoff_debug_info input_debug;
4789 if (p->type != bfd_indirect_link_order)
4791 if (p->type == bfd_fill_link_order)
4796 input_section = p->u.indirect.section;
4797 input_bfd = input_section->owner;
4799 if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour
4800 || (get_elf_backend_data (input_bfd)
4801 ->elf_backend_ecoff_debug_swap) == NULL)
4803 /* I don't know what a non MIPS ELF bfd would be
4804 doing with a .mdebug section, but I don't really
4805 want to deal with it. */
4809 input_swap = (get_elf_backend_data (input_bfd)
4810 ->elf_backend_ecoff_debug_swap);
4812 BFD_ASSERT (p->size == input_section->_raw_size);
4814 /* The ECOFF linking code expects that we have already
4815 read in the debugging information and set up an
4816 ecoff_debug_info structure, so we do that now. */
4817 if (! _bfd_mips_elf_read_ecoff_info (input_bfd, input_section,
4821 if (! (bfd_ecoff_debug_accumulate
4822 (mdebug_handle, abfd, &debug, swap, input_bfd,
4823 &input_debug, input_swap, info)))
4826 /* Loop through the external symbols. For each one with
4827 interesting information, try to find the symbol in
4828 the linker global hash table and save the information
4829 for the output external symbols. */
4830 eraw_src = input_debug.external_ext;
4831 eraw_end = (eraw_src
4832 + (input_debug.symbolic_header.iextMax
4833 * input_swap->external_ext_size));
4835 eraw_src < eraw_end;
4836 eraw_src += input_swap->external_ext_size)
4840 struct mips_elf_link_hash_entry *h;
4842 (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext);
4843 if (ext.asym.sc == scNil
4844 || ext.asym.sc == scUndefined
4845 || ext.asym.sc == scSUndefined)
4848 name = input_debug.ssext + ext.asym.iss;
4849 h = mips_elf_link_hash_lookup (mips_elf_hash_table (info),
4850 name, false, false, true);
4851 if (h == NULL || h->esym.ifd != -2)
4857 < input_debug.symbolic_header.ifdMax);
4858 ext.ifd = input_debug.ifdmap[ext.ifd];
4864 /* Free up the information we just read. */
4865 free (input_debug.line);
4866 free (input_debug.external_dnr);
4867 free (input_debug.external_pdr);
4868 free (input_debug.external_sym);
4869 free (input_debug.external_opt);
4870 free (input_debug.external_aux);
4871 free (input_debug.ss);
4872 free (input_debug.ssext);
4873 free (input_debug.external_fdr);
4874 free (input_debug.external_rfd);
4875 free (input_debug.external_ext);
4877 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4878 elf_link_input_bfd ignores this section. */
4879 input_section->flags &= ~SEC_HAS_CONTENTS;
4882 if (SGI_COMPAT (abfd) && info->shared)
4884 /* Create .rtproc section. */
4885 rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc");
4886 if (rtproc_sec == NULL)
4888 flagword flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY
4889 | SEC_LINKER_CREATED | SEC_READONLY);
4891 rtproc_sec = bfd_make_section (abfd, ".rtproc");
4892 if (rtproc_sec == NULL
4893 || ! bfd_set_section_flags (abfd, rtproc_sec, flags)
4894 || ! bfd_set_section_alignment (abfd, rtproc_sec, 4))
4898 if (! mips_elf_create_procedure_table (mdebug_handle, abfd,
4899 info, rtproc_sec, &debug))
4903 /* Build the external symbol information. */
4906 einfo.debug = &debug;
4908 einfo.failed = false;
4909 mips_elf_link_hash_traverse (mips_elf_hash_table (info),
4910 mips_elf_output_extsym,
4915 /* Set the size of the .mdebug section. */
4916 o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap);
4918 /* Skip this section later on (I don't think this currently
4919 matters, but someday it might). */
4920 o->link_order_head = (struct bfd_link_order *) NULL;
4925 if (strncmp (o->name, ".gptab.", sizeof ".gptab." - 1) == 0)
4927 const char *subname;
4930 Elf32_External_gptab *ext_tab;
4933 /* The .gptab.sdata and .gptab.sbss sections hold
4934 information describing how the small data area would
4935 change depending upon the -G switch. These sections
4936 not used in executables files. */
4937 if (! info->relocateable)
4941 for (p = o->link_order_head;
4942 p != (struct bfd_link_order *) NULL;
4945 asection *input_section;
4947 if (p->type != bfd_indirect_link_order)
4949 if (p->type == bfd_fill_link_order)
4954 input_section = p->u.indirect.section;
4956 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4957 elf_link_input_bfd ignores this section. */
4958 input_section->flags &= ~SEC_HAS_CONTENTS;
4961 /* Skip this section later on (I don't think this
4962 currently matters, but someday it might). */
4963 o->link_order_head = (struct bfd_link_order *) NULL;
4965 /* Really remove the section. */
4966 for (secpp = &abfd->sections;
4968 secpp = &(*secpp)->next)
4970 *secpp = (*secpp)->next;
4971 --abfd->section_count;
4976 /* There is one gptab for initialized data, and one for
4977 uninitialized data. */
4978 if (strcmp (o->name, ".gptab.sdata") == 0)
4980 else if (strcmp (o->name, ".gptab.sbss") == 0)
4984 (*_bfd_error_handler)
4985 (_("%s: illegal section name `%s'"),
4986 bfd_get_filename (abfd), o->name);
4987 bfd_set_error (bfd_error_nonrepresentable_section);
4991 /* The linker script always combines .gptab.data and
4992 .gptab.sdata into .gptab.sdata, and likewise for
4993 .gptab.bss and .gptab.sbss. It is possible that there is
4994 no .sdata or .sbss section in the output file, in which
4995 case we must change the name of the output section. */
4996 subname = o->name + sizeof ".gptab" - 1;
4997 if (bfd_get_section_by_name (abfd, subname) == NULL)
4999 if (o == gptab_data_sec)
5000 o->name = ".gptab.data";
5002 o->name = ".gptab.bss";
5003 subname = o->name + sizeof ".gptab" - 1;
5004 BFD_ASSERT (bfd_get_section_by_name (abfd, subname) != NULL);
5007 /* Set up the first entry. */
5009 tab = (Elf32_gptab *) bfd_malloc (c * sizeof (Elf32_gptab));
5012 tab[0].gt_header.gt_current_g_value = elf_gp_size (abfd);
5013 tab[0].gt_header.gt_unused = 0;
5015 /* Combine the input sections. */
5016 for (p = o->link_order_head;
5017 p != (struct bfd_link_order *) NULL;
5020 asection *input_section;
5024 bfd_size_type gpentry;
5026 if (p->type != bfd_indirect_link_order)
5028 if (p->type == bfd_fill_link_order)
5033 input_section = p->u.indirect.section;
5034 input_bfd = input_section->owner;
5036 /* Combine the gptab entries for this input section one
5037 by one. We know that the input gptab entries are
5038 sorted by ascending -G value. */
5039 size = bfd_section_size (input_bfd, input_section);
5041 for (gpentry = sizeof (Elf32_External_gptab);
5043 gpentry += sizeof (Elf32_External_gptab))
5045 Elf32_External_gptab ext_gptab;
5046 Elf32_gptab int_gptab;
5052 if (! (bfd_get_section_contents
5053 (input_bfd, input_section, (PTR) &ext_gptab,
5054 gpentry, sizeof (Elf32_External_gptab))))
5060 bfd_mips_elf32_swap_gptab_in (input_bfd, &ext_gptab,
5062 val = int_gptab.gt_entry.gt_g_value;
5063 add = int_gptab.gt_entry.gt_bytes - last;
5066 for (look = 1; look < c; look++)
5068 if (tab[look].gt_entry.gt_g_value >= val)
5069 tab[look].gt_entry.gt_bytes += add;
5071 if (tab[look].gt_entry.gt_g_value == val)
5077 Elf32_gptab *new_tab;
5080 /* We need a new table entry. */
5081 new_tab = ((Elf32_gptab *)
5082 bfd_realloc ((PTR) tab,
5083 (c + 1) * sizeof (Elf32_gptab)));
5084 if (new_tab == NULL)
5090 tab[c].gt_entry.gt_g_value = val;
5091 tab[c].gt_entry.gt_bytes = add;
5093 /* Merge in the size for the next smallest -G
5094 value, since that will be implied by this new
5097 for (look = 1; look < c; look++)
5099 if (tab[look].gt_entry.gt_g_value < val
5101 || (tab[look].gt_entry.gt_g_value
5102 > tab[max].gt_entry.gt_g_value)))
5106 tab[c].gt_entry.gt_bytes +=
5107 tab[max].gt_entry.gt_bytes;
5112 last = int_gptab.gt_entry.gt_bytes;
5115 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5116 elf_link_input_bfd ignores this section. */
5117 input_section->flags &= ~SEC_HAS_CONTENTS;
5120 /* The table must be sorted by -G value. */
5122 qsort (tab + 1, c - 1, sizeof (tab[0]), gptab_compare);
5124 /* Swap out the table. */
5125 ext_tab = ((Elf32_External_gptab *)
5126 bfd_alloc (abfd, c * sizeof (Elf32_External_gptab)));
5127 if (ext_tab == NULL)
5133 for (i = 0; i < c; i++)
5134 bfd_mips_elf32_swap_gptab_out (abfd, tab + i, ext_tab + i);
5137 o->_raw_size = c * sizeof (Elf32_External_gptab);
5138 o->contents = (bfd_byte *) ext_tab;
5140 /* Skip this section later on (I don't think this currently
5141 matters, but someday it might). */
5142 o->link_order_head = (struct bfd_link_order *) NULL;
5146 /* Invoke the regular ELF backend linker to do all the work. */
5147 if (ABI_64_P (abfd))
5150 if (!bfd_elf64_bfd_final_link (abfd, info))
5157 else if (!bfd_elf32_bfd_final_link (abfd, info))
5160 /* Now write out the computed sections. */
5162 if (reginfo_sec != (asection *) NULL)
5164 Elf32_External_RegInfo ext;
5166 bfd_mips_elf32_swap_reginfo_out (abfd, ®info, &ext);
5167 if (! bfd_set_section_contents (abfd, reginfo_sec, (PTR) &ext,
5168 (file_ptr) 0, sizeof ext))
5172 if (mdebug_sec != (asection *) NULL)
5174 BFD_ASSERT (abfd->output_has_begun);
5175 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug,
5177 mdebug_sec->filepos))
5180 bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info);
5183 if (gptab_data_sec != (asection *) NULL)
5185 if (! bfd_set_section_contents (abfd, gptab_data_sec,
5186 gptab_data_sec->contents,
5188 gptab_data_sec->_raw_size))
5192 if (gptab_bss_sec != (asection *) NULL)
5194 if (! bfd_set_section_contents (abfd, gptab_bss_sec,
5195 gptab_bss_sec->contents,
5197 gptab_bss_sec->_raw_size))
5201 if (SGI_COMPAT (abfd))
5203 rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc");
5204 if (rtproc_sec != NULL)
5206 if (! bfd_set_section_contents (abfd, rtproc_sec,
5207 rtproc_sec->contents,
5209 rtproc_sec->_raw_size))
5217 /* This function is called via qsort() to sort the dynamic relocation
5218 entries by increasing r_symndx value. */
5221 sort_dynamic_relocs (arg1, arg2)
5225 const Elf32_External_Rel *ext_reloc1 = (const Elf32_External_Rel *) arg1;
5226 const Elf32_External_Rel *ext_reloc2 = (const Elf32_External_Rel *) arg2;
5228 Elf_Internal_Rel int_reloc1;
5229 Elf_Internal_Rel int_reloc2;
5231 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd, ext_reloc1, &int_reloc1);
5232 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd, ext_reloc2, &int_reloc2);
5234 return (ELF32_R_SYM (int_reloc1.r_info) - ELF32_R_SYM (int_reloc2.r_info));
5237 /* Returns the GOT section for ABFD. */
5240 mips_elf_got_section (abfd)
5243 return bfd_get_section_by_name (abfd, ".got");
5246 /* Returns the GOT information associated with the link indicated by
5247 INFO. If SGOTP is non-NULL, it is filled in with the GOT
5250 static struct mips_got_info *
5251 mips_elf_got_info (abfd, sgotp)
5256 struct mips_got_info *g;
5258 sgot = mips_elf_got_section (abfd);
5259 BFD_ASSERT (sgot != NULL);
5260 BFD_ASSERT (elf_section_data (sgot) != NULL);
5261 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
5262 BFD_ASSERT (g != NULL);
5269 /* Return whether a relocation is against a local symbol. */
5272 mips_elf_local_relocation_p (input_bfd, relocation, local_sections,
5275 const Elf_Internal_Rela *relocation;
5276 asection **local_sections;
5277 boolean check_forced;
5279 unsigned long r_symndx;
5280 Elf_Internal_Shdr *symtab_hdr;
5281 struct mips_elf_link_hash_entry *h;
5284 r_symndx = ELF32_R_SYM (relocation->r_info);
5285 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5286 extsymoff = (elf_bad_symtab (input_bfd)) ? 0 : symtab_hdr->sh_info;
5288 if (r_symndx < extsymoff)
5290 if (elf_bad_symtab (input_bfd) && local_sections[r_symndx] != NULL)
5295 /* Look up the hash table to check whether the symbol
5296 was forced local. */
5297 h = (struct mips_elf_link_hash_entry *)
5298 elf_sym_hashes (input_bfd) [r_symndx - extsymoff];
5299 /* Find the real hash-table entry for this symbol. */
5300 while (h->root.root.type == bfd_link_hash_indirect
5301 || h->root.root.type == bfd_link_hash_warning)
5302 h = (struct mips_elf_link_hash_entry *) h->root.root.u.i.link;
5303 if ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)
5310 /* Sign-extend VALUE, which has the indicated number of BITS. */
5313 mips_elf_sign_extend (value, bits)
5317 if (value & ((bfd_vma) 1 << (bits - 1)))
5318 /* VALUE is negative. */
5319 value |= ((bfd_vma) - 1) << bits;
5324 /* Return non-zero if the indicated VALUE has overflowed the maximum
5325 range expressable by a signed number with the indicated number of
5329 mips_elf_overflow_p (value, bits)
5333 bfd_signed_vma svalue = (bfd_signed_vma) value;
5335 if (svalue > (1 << (bits - 1)) - 1)
5336 /* The value is too big. */
5338 else if (svalue < -(1 << (bits - 1)))
5339 /* The value is too small. */
5346 /* Calculate the %high function. */
5349 mips_elf_high (value)
5352 return ((value + (bfd_vma) 0x8000) >> 16) & 0xffff;
5355 /* Calculate the %higher function. */
5358 mips_elf_higher (value)
5359 bfd_vma value ATTRIBUTE_UNUSED;
5362 return ((value + (bfd_vma) 0x80008000) >> 32) & 0xffff;
5365 return (bfd_vma) -1;
5369 /* Calculate the %highest function. */
5372 mips_elf_highest (value)
5373 bfd_vma value ATTRIBUTE_UNUSED;
5376 return ((value + (bfd_vma) 0x800080008000) >> 48) & 0xffff;
5379 return (bfd_vma) -1;
5383 /* Returns the GOT index for the global symbol indicated by H. */
5386 mips_elf_global_got_index (abfd, h)
5388 struct elf_link_hash_entry *h;
5392 struct mips_got_info *g;
5394 g = mips_elf_got_info (abfd, &sgot);
5396 /* Once we determine the global GOT entry with the lowest dynamic
5397 symbol table index, we must put all dynamic symbols with greater
5398 indices into the GOT. That makes it easy to calculate the GOT
5400 BFD_ASSERT (h->dynindx >= g->global_gotsym->dynindx);
5401 index = ((h->dynindx - g->global_gotsym->dynindx + g->local_gotno)
5402 * MIPS_ELF_GOT_SIZE (abfd));
5403 BFD_ASSERT (index < sgot->_raw_size);
5408 /* Returns the offset for the entry at the INDEXth position
5412 mips_elf_got_offset_from_index (dynobj, output_bfd, index)
5420 sgot = mips_elf_got_section (dynobj);
5421 gp = _bfd_get_gp_value (output_bfd);
5422 return (sgot->output_section->vma + sgot->output_offset + index -
5426 /* If H is a symbol that needs a global GOT entry, but has a dynamic
5427 symbol table index lower than any we've seen to date, record it for
5431 mips_elf_record_global_got_symbol (h, info, g)
5432 struct elf_link_hash_entry *h;
5433 struct bfd_link_info *info;
5434 struct mips_got_info *g ATTRIBUTE_UNUSED;
5436 /* A global symbol in the GOT must also be in the dynamic symbol
5438 if (h->dynindx == -1
5439 && !bfd_elf32_link_record_dynamic_symbol (info, h))
5442 /* If we've already marked this entry as need GOT space, we don't
5443 need to do it again. */
5444 if (h->got.offset != (bfd_vma) - 1)
5447 /* By setting this to a value other than -1, we are indicating that
5448 there needs to be a GOT entry for H. */
5454 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
5455 the dynamic symbols. */
5457 struct mips_elf_hash_sort_data {
5458 /* The symbol in the global GOT with the lowest dynamic symbol table
5460 struct elf_link_hash_entry *low;
5461 /* The least dynamic symbol table index corresponding to a symbol
5462 with a GOT entry. */
5463 long min_got_dynindx;
5464 /* The greatest dynamic symbol table index not corresponding to a
5465 symbol without a GOT entry. */
5466 long max_non_got_dynindx;
5469 /* If H needs a GOT entry, assign it the highest available dynamic
5470 index. Otherwise, assign it the lowest available dynamic
5474 mips_elf_sort_hash_table_f (h, data)
5475 struct mips_elf_link_hash_entry *h;
5478 struct mips_elf_hash_sort_data *hsd
5479 = (struct mips_elf_hash_sort_data *) data;
5481 /* Symbols without dynamic symbol table entries aren't interesting
5483 if (h->root.dynindx == -1)
5486 if (h->root.got.offset != 0)
5487 h->root.dynindx = hsd->max_non_got_dynindx++;
5490 h->root.dynindx = --hsd->min_got_dynindx;
5491 hsd->low = (struct elf_link_hash_entry *) h;
5497 /* Sort the dynamic symbol table so that symbols that need GOT entries
5498 appear towards the end. This reduces the amount of GOT space
5499 required. MAX_LOCAL is used to set the number of local symbols
5500 known to be in the dynamic symbol table. During
5501 mips_elf_size_dynamic_sections, this value is 1. Afterward, the
5502 section symbols are added and the count is higher. */
5505 mips_elf_sort_hash_table (info, max_local)
5506 struct bfd_link_info *info;
5507 unsigned long max_local;
5509 struct mips_elf_hash_sort_data hsd;
5510 struct mips_got_info *g;
5513 dynobj = elf_hash_table (info)->dynobj;
5516 hsd.min_got_dynindx = elf_hash_table (info)->dynsymcount;
5517 hsd.max_non_got_dynindx = max_local;
5518 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table *)
5519 elf_hash_table (info)),
5520 mips_elf_sort_hash_table_f,
5523 /* There shoud have been enough room in the symbol table to
5524 accomodate both the GOT and non-GOT symbols. */
5525 BFD_ASSERT (hsd.max_non_got_dynindx <= hsd.min_got_dynindx);
5527 /* Now we know which dynamic symbol has the lowest dynamic symbol
5528 table index in the GOT. */
5529 g = mips_elf_got_info (dynobj, NULL);
5530 g->global_gotsym = hsd.low;
5535 /* Create a local GOT entry for VALUE. Return the index of the entry,
5536 or -1 if it could not be created. */
5539 mips_elf_create_local_got_entry (abfd, g, sgot, value)
5541 struct mips_got_info *g;
5545 if (g->assigned_gotno >= g->local_gotno)
5547 /* We didn't allocate enough space in the GOT. */
5548 (*_bfd_error_handler)
5549 (_("not enough GOT space for local GOT entries"));
5550 bfd_set_error (bfd_error_bad_value);
5551 return (bfd_vma) -1;
5554 MIPS_ELF_PUT_WORD (abfd, value,
5556 + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno));
5557 return MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno++;
5560 /* Returns the GOT offset at which the indicated address can be found.
5561 If there is not yet a GOT entry for this value, create one. Returns
5562 -1 if no satisfactory GOT offset can be found. */
5565 mips_elf_local_got_index (abfd, info, value)
5567 struct bfd_link_info *info;
5571 struct mips_got_info *g;
5574 g = mips_elf_got_info (elf_hash_table (info)->dynobj, &sgot);
5576 /* Look to see if we already have an appropriate entry. */
5577 for (entry = (sgot->contents
5578 + MIPS_ELF_GOT_SIZE (abfd) * MIPS_RESERVED_GOTNO);
5579 entry != sgot->contents + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno;
5580 entry += MIPS_ELF_GOT_SIZE (abfd))
5582 bfd_vma address = MIPS_ELF_GET_WORD (abfd, entry);
5583 if (address == value)
5584 return entry - sgot->contents;
5587 return mips_elf_create_local_got_entry (abfd, g, sgot, value);
5590 /* Find a GOT entry that is within 32KB of the VALUE. These entries
5591 are supposed to be placed at small offsets in the GOT, i.e.,
5592 within 32KB of GP. Return the index into the GOT for this page,
5593 and store the offset from this entry to the desired address in
5594 OFFSETP, if it is non-NULL. */
5597 mips_elf_got_page (abfd, info, value, offsetp)
5599 struct bfd_link_info *info;
5604 struct mips_got_info *g;
5606 bfd_byte *last_entry;
5610 g = mips_elf_got_info (elf_hash_table (info)->dynobj, &sgot);
5612 /* Look to see if we aleady have an appropriate entry. */
5613 last_entry = sgot->contents + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno;
5614 for (entry = (sgot->contents
5615 + MIPS_ELF_GOT_SIZE (abfd) * MIPS_RESERVED_GOTNO);
5616 entry != last_entry;
5617 entry += MIPS_ELF_GOT_SIZE (abfd))
5619 address = MIPS_ELF_GET_WORD (abfd, entry);
5621 if (!mips_elf_overflow_p (value - address, 16))
5623 /* This entry will serve as the page pointer. We can add a
5624 16-bit number to it to get the actual address. */
5625 index = entry - sgot->contents;
5630 /* If we didn't have an appropriate entry, we create one now. */
5631 if (entry == last_entry)
5632 index = mips_elf_create_local_got_entry (abfd, g, sgot, value);
5636 address = MIPS_ELF_GET_WORD (abfd, entry);
5637 *offsetp = value - address;
5643 /* Find a GOT entry whose higher-order 16 bits are the same as those
5644 for value. Return the index into the GOT for this entry. */
5647 mips_elf_got16_entry (abfd, info, value, external)
5649 struct bfd_link_info *info;
5654 struct mips_got_info *g;
5656 bfd_byte *last_entry;
5662 /* Although the ABI says that it is "the high-order 16 bits" that we
5663 want, it is really the %high value. The complete value is
5664 calculated with a `addiu' of a LO16 relocation, just as with a
5666 value = mips_elf_high (value) << 16;
5669 g = mips_elf_got_info (elf_hash_table (info)->dynobj, &sgot);
5671 /* Look to see if we already have an appropriate entry. */
5672 last_entry = sgot->contents + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno;
5673 for (entry = (sgot->contents
5674 + MIPS_ELF_GOT_SIZE (abfd) * MIPS_RESERVED_GOTNO);
5675 entry != last_entry;
5676 entry += MIPS_ELF_GOT_SIZE (abfd))
5678 address = MIPS_ELF_GET_WORD (abfd, entry);
5679 if (address == value)
5681 /* This entry has the right high-order 16 bits, and the low-order
5682 16 bits are set to zero. */
5683 index = entry - sgot->contents;
5688 /* If we didn't have an appropriate entry, we create one now. */
5689 if (entry == last_entry)
5690 index = mips_elf_create_local_got_entry (abfd, g, sgot, value);
5695 /* Returns the first relocation of type r_type found, beginning with
5696 RELOCATION. RELEND is one-past-the-end of the relocation table. */
5698 static const Elf_Internal_Rela *
5699 mips_elf_next_relocation (r_type, relocation, relend)
5700 unsigned int r_type;
5701 const Elf_Internal_Rela *relocation;
5702 const Elf_Internal_Rela *relend;
5704 /* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be
5705 immediately following. However, for the IRIX6 ABI, the next
5706 relocation may be a composed relocation consisting of several
5707 relocations for the same address. In that case, the R_MIPS_LO16
5708 relocation may occur as one of these. We permit a similar
5709 extension in general, as that is useful for GCC. */
5710 while (relocation < relend)
5712 if (ELF32_R_TYPE (relocation->r_info) == r_type)
5718 /* We didn't find it. */
5719 bfd_set_error (bfd_error_bad_value);
5723 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
5724 is the original relocation, which is now being transformed into a
5725 dynamic relocation. The ADDENDP is adjusted if necessary; the
5726 caller should store the result in place of the original addend. */
5729 mips_elf_create_dynamic_relocation (output_bfd, info, rel, h, sec,
5730 symbol, addendp, input_section, local_p)
5732 struct bfd_link_info *info;
5733 const Elf_Internal_Rela *rel;
5734 struct mips_elf_link_hash_entry *h;
5738 asection *input_section;
5741 Elf_Internal_Rel outrel;
5747 r_type = ELF32_R_TYPE (rel->r_info);
5748 dynobj = elf_hash_table (info)->dynobj;
5750 = bfd_get_section_by_name (dynobj,
5751 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd));
5752 BFD_ASSERT (sreloc != NULL);
5753 BFD_ASSERT (sreloc->contents != NULL);
5757 /* We begin by assuming that the offset for the dynamic relocation
5758 is the same as for the original relocation. We'll adjust this
5759 later to reflect the correct output offsets. */
5760 if (elf_section_data (input_section)->stab_info == NULL)
5761 outrel.r_offset = rel->r_offset;
5764 /* Except that in a stab section things are more complex.
5765 Because we compress stab information, the offset given in the
5766 relocation may not be the one we want; we must let the stabs
5767 machinery tell us the offset. */
5769 = (_bfd_stab_section_offset
5770 (output_bfd, &elf_hash_table (info)->stab_info,
5772 &elf_section_data (input_section)->stab_info,
5774 /* If we didn't need the relocation at all, this value will be
5776 if (outrel.r_offset == (bfd_vma) -1)
5780 /* If we've decided to skip this relocation, just output an empty
5781 record. Note that R_MIPS_NONE == 0, so that this call to memset
5782 is a way of setting R_TYPE to R_MIPS_NONE. */
5784 memset (&outrel, 0, sizeof (outrel));
5788 bfd_vma section_offset;
5790 /* We must now calculate the dynamic symbol table index to use
5791 in the relocation. */
5793 && (! info->symbolic || (h->root.elf_link_hash_flags
5794 & ELF_LINK_HASH_DEF_REGULAR) == 0))
5796 indx = h->root.dynindx;
5797 /* h->root.dynindx may be -1 if this symbol was marked to
5804 if (sec != NULL && bfd_is_abs_section (sec))
5806 else if (sec == NULL || sec->owner == NULL)
5808 bfd_set_error (bfd_error_bad_value);
5813 indx = elf_section_data (sec->output_section)->dynindx;
5818 /* Figure out how far the target of the relocation is from
5819 the beginning of its section. */
5820 section_offset = symbol - sec->output_section->vma;
5821 /* The relocation we're building is section-relative.
5822 Therefore, the original addend must be adjusted by the
5824 *addendp += symbol - sec->output_section->vma;
5825 /* Now, the relocation is just against the section. */
5826 symbol = sec->output_section->vma;
5829 /* If the relocation is against a local symbol was previously an
5830 absolute relocation, we must adjust it by the value we give
5831 it in the dynamic symbol table. */
5832 if (local_p && r_type != R_MIPS_REL32)
5835 /* The relocation is always an REL32 relocation because we don't
5836 know where the shared library will wind up at load-time. */
5837 outrel.r_info = ELF32_R_INFO (indx, R_MIPS_REL32);
5839 /* Adjust the output offset of the relocation to reference the
5840 correct location in the output file. */
5841 outrel.r_offset += (input_section->output_section->vma
5842 + input_section->output_offset);
5845 /* Put the relocation back out. We have to use the special
5846 relocation outputter in the 64-bit case since the 64-bit
5847 relocation format is non-standard. */
5848 if (ABI_64_P (output_bfd))
5850 (*get_elf_backend_data (output_bfd)->s->swap_reloc_out)
5851 (output_bfd, &outrel,
5853 + sreloc->reloc_count * sizeof (Elf64_Mips_External_Rel)));
5856 bfd_elf32_swap_reloc_out (output_bfd, &outrel,
5857 (((Elf32_External_Rel *)
5859 + sreloc->reloc_count));
5861 /* Record the index of the first relocation referencing H. This
5862 information is later emitted in the .msym section. */
5864 && (h->min_dyn_reloc_index == 0
5865 || sreloc->reloc_count < h->min_dyn_reloc_index))
5866 h->min_dyn_reloc_index = sreloc->reloc_count;
5868 /* We've now added another relocation. */
5869 ++sreloc->reloc_count;
5871 /* Make sure the output section is writable. The dynamic linker
5872 will be writing to it. */
5873 elf_section_data (input_section->output_section)->this_hdr.sh_flags
5876 /* On IRIX5, make an entry of compact relocation info. */
5877 if (! skip && IRIX_COMPAT (output_bfd) == ict_irix5)
5879 asection *scpt = bfd_get_section_by_name (dynobj, ".compact_rel");
5884 Elf32_crinfo cptrel;
5886 mips_elf_set_cr_format (cptrel, CRF_MIPS_LONG);
5887 cptrel.vaddr = (rel->r_offset
5888 + input_section->output_section->vma
5889 + input_section->output_offset);
5890 if (r_type == R_MIPS_REL32)
5891 mips_elf_set_cr_type (cptrel, CRT_MIPS_REL32);
5893 mips_elf_set_cr_type (cptrel, CRT_MIPS_WORD);
5894 mips_elf_set_cr_dist2to (cptrel, 0);
5895 cptrel.konst = *addendp;
5897 cr = (scpt->contents
5898 + sizeof (Elf32_External_compact_rel));
5899 bfd_elf32_swap_crinfo_out (output_bfd, &cptrel,
5900 ((Elf32_External_crinfo *) cr
5901 + scpt->reloc_count));
5902 ++scpt->reloc_count;
5909 /* Calculate the value produced by the RELOCATION (which comes from
5910 the INPUT_BFD). The ADDEND is the addend to use for this
5911 RELOCATION; RELOCATION->R_ADDEND is ignored.
5913 The result of the relocation calculation is stored in VALUEP.
5914 REQUIRE_JALXP indicates whether or not the opcode used with this
5915 relocation must be JALX.
5917 This function returns bfd_reloc_continue if the caller need take no
5918 further action regarding this relocation, bfd_reloc_notsupported if
5919 something goes dramatically wrong, bfd_reloc_overflow if an
5920 overflow occurs, and bfd_reloc_ok to indicate success. */
5922 static bfd_reloc_status_type
5923 mips_elf_calculate_relocation (abfd,
5937 asection *input_section;
5938 struct bfd_link_info *info;
5939 const Elf_Internal_Rela *relocation;
5941 reloc_howto_type *howto;
5942 Elf_Internal_Sym *local_syms;
5943 asection **local_sections;
5946 boolean *require_jalxp;
5948 /* The eventual value we will return. */
5950 /* The address of the symbol against which the relocation is
5953 /* The final GP value to be used for the relocatable, executable, or
5954 shared object file being produced. */
5955 bfd_vma gp = (bfd_vma) - 1;
5956 /* The place (section offset or address) of the storage unit being
5959 /* The value of GP used to create the relocatable object. */
5960 bfd_vma gp0 = (bfd_vma) - 1;
5961 /* The offset into the global offset table at which the address of
5962 the relocation entry symbol, adjusted by the addend, resides
5963 during execution. */
5964 bfd_vma g = (bfd_vma) - 1;
5965 /* The section in which the symbol referenced by the relocation is
5967 asection *sec = NULL;
5968 struct mips_elf_link_hash_entry *h = NULL;
5969 /* True if the symbol referred to by this relocation is a local
5972 /* True if the symbol referred to by this relocation is "_gp_disp". */
5973 boolean gp_disp_p = false;
5974 Elf_Internal_Shdr *symtab_hdr;
5976 unsigned long r_symndx;
5978 /* True if overflow occurred during the calculation of the
5979 relocation value. */
5980 boolean overflowed_p;
5981 /* True if this relocation refers to a MIPS16 function. */
5982 boolean target_is_16_bit_code_p = false;
5984 /* Parse the relocation. */
5985 r_symndx = ELF32_R_SYM (relocation->r_info);
5986 r_type = ELF32_R_TYPE (relocation->r_info);
5987 p = (input_section->output_section->vma
5988 + input_section->output_offset
5989 + relocation->r_offset);
5991 /* Assume that there will be no overflow. */
5992 overflowed_p = false;
5994 /* Figure out whether or not the symbol is local, and get the offset
5995 used in the array of hash table entries. */
5996 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5997 local_p = mips_elf_local_relocation_p (input_bfd, relocation,
5998 local_sections, false);
5999 if (! elf_bad_symtab (input_bfd))
6000 extsymoff = symtab_hdr->sh_info;
6003 /* The symbol table does not follow the rule that local symbols
6004 must come before globals. */
6008 /* Figure out the value of the symbol. */
6011 Elf_Internal_Sym *sym;
6013 sym = local_syms + r_symndx;
6014 sec = local_sections[r_symndx];
6016 symbol = sec->output_section->vma + sec->output_offset;
6017 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
6018 symbol += sym->st_value;
6020 /* MIPS16 text labels should be treated as odd. */
6021 if (sym->st_other == STO_MIPS16)
6024 /* Record the name of this symbol, for our caller. */
6025 *namep = bfd_elf_string_from_elf_section (input_bfd,
6026 symtab_hdr->sh_link,
6029 *namep = bfd_section_name (input_bfd, sec);
6031 target_is_16_bit_code_p = (sym->st_other == STO_MIPS16);
6035 /* For global symbols we look up the symbol in the hash-table. */
6036 h = ((struct mips_elf_link_hash_entry *)
6037 elf_sym_hashes (input_bfd) [r_symndx - extsymoff]);
6038 /* Find the real hash-table entry for this symbol. */
6039 while (h->root.root.type == bfd_link_hash_indirect
6040 || h->root.root.type == bfd_link_hash_warning)
6041 h = (struct mips_elf_link_hash_entry *) h->root.root.u.i.link;
6043 /* Record the name of this symbol, for our caller. */
6044 *namep = h->root.root.root.string;
6046 /* See if this is the special _gp_disp symbol. Note that such a
6047 symbol must always be a global symbol. */
6048 if (strcmp (h->root.root.root.string, "_gp_disp") == 0)
6050 /* Relocations against _gp_disp are permitted only with
6051 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
6052 if (r_type != R_MIPS_HI16 && r_type != R_MIPS_LO16)
6053 return bfd_reloc_notsupported;
6057 /* If this symbol is defined, calculate its address. Note that
6058 _gp_disp is a magic symbol, always implicitly defined by the
6059 linker, so it's inappropriate to check to see whether or not
6061 else if ((h->root.root.type == bfd_link_hash_defined
6062 || h->root.root.type == bfd_link_hash_defweak)
6063 && h->root.root.u.def.section)
6065 sec = h->root.root.u.def.section;
6066 if (sec->output_section)
6067 symbol = (h->root.root.u.def.value
6068 + sec->output_section->vma
6069 + sec->output_offset);
6071 symbol = h->root.root.u.def.value;
6073 else if (h->root.root.type == bfd_link_hash_undefweak)
6074 /* We allow relocations against undefined weak symbols, giving
6075 it the value zero, so that you can undefined weak functions
6076 and check to see if they exist by looking at their
6079 else if (info->shared && !info->symbolic && !info->no_undefined
6080 && ELF_ST_VISIBILITY (h->root.other) == STV_DEFAULT)
6082 else if (strcmp (h->root.root.root.string, "_DYNAMIC_LINK") == 0 ||
6083 strcmp (h->root.root.root.string, "_DYNAMIC_LINKING") == 0)
6085 /* If this is a dynamic link, we should have created a
6086 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
6087 in in mips_elf_create_dynamic_sections.
6088 Otherwise, we should define the symbol with a value of 0.
6089 FIXME: It should probably get into the symbol table
6091 BFD_ASSERT (! info->shared);
6092 BFD_ASSERT (bfd_get_section_by_name (abfd, ".dynamic") == NULL);
6097 if (! ((*info->callbacks->undefined_symbol)
6098 (info, h->root.root.root.string, input_bfd,
6099 input_section, relocation->r_offset,
6100 (!info->shared || info->no_undefined
6101 || ELF_ST_VISIBILITY (h->root.other)))))
6102 return bfd_reloc_undefined;
6106 target_is_16_bit_code_p = (h->root.other == STO_MIPS16);
6109 /* If this is a 32-bit call to a 16-bit function with a stub, we
6110 need to redirect the call to the stub, unless we're already *in*
6112 if (r_type != R_MIPS16_26 && !info->relocateable
6113 && ((h != NULL && h->fn_stub != NULL)
6114 || (local_p && elf_tdata (input_bfd)->local_stubs != NULL
6115 && elf_tdata (input_bfd)->local_stubs[r_symndx] != NULL))
6116 && !mips_elf_stub_section_p (input_bfd, input_section))
6118 /* This is a 32-bit call to a 16-bit function. We should
6119 have already noticed that we were going to need the
6122 sec = elf_tdata (input_bfd)->local_stubs[r_symndx];
6125 BFD_ASSERT (h->need_fn_stub);
6129 symbol = sec->output_section->vma + sec->output_offset;
6131 /* If this is a 16-bit call to a 32-bit function with a stub, we
6132 need to redirect the call to the stub. */
6133 else if (r_type == R_MIPS16_26 && !info->relocateable
6135 && (h->call_stub != NULL || h->call_fp_stub != NULL)
6136 && !target_is_16_bit_code_p)
6138 /* If both call_stub and call_fp_stub are defined, we can figure
6139 out which one to use by seeing which one appears in the input
6141 if (h->call_stub != NULL && h->call_fp_stub != NULL)
6146 for (o = input_bfd->sections; o != NULL; o = o->next)
6148 if (strncmp (bfd_get_section_name (input_bfd, o),
6149 CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0)
6151 sec = h->call_fp_stub;
6158 else if (h->call_stub != NULL)
6161 sec = h->call_fp_stub;
6163 BFD_ASSERT (sec->_raw_size > 0);
6164 symbol = sec->output_section->vma + sec->output_offset;
6167 /* Calls from 16-bit code to 32-bit code and vice versa require the
6168 special jalx instruction. */
6169 *require_jalxp = (!info->relocateable
6170 && ((r_type == R_MIPS16_26) != target_is_16_bit_code_p));
6172 local_p = mips_elf_local_relocation_p (input_bfd, relocation,
6173 local_sections, true);
6175 /* If we haven't already determined the GOT offset, or the GP value,
6176 and we're going to need it, get it now. */
6181 case R_MIPS_GOT_DISP:
6182 case R_MIPS_GOT_HI16:
6183 case R_MIPS_CALL_HI16:
6184 case R_MIPS_GOT_LO16:
6185 case R_MIPS_CALL_LO16:
6186 /* Find the index into the GOT where this value is located. */
6189 BFD_ASSERT (addend == 0);
6190 g = mips_elf_global_got_index
6191 (elf_hash_table (info)->dynobj,
6192 (struct elf_link_hash_entry *) h);
6193 if (! elf_hash_table(info)->dynamic_sections_created
6195 && (info->symbolic || h->root.dynindx == -1)
6196 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
6198 /* This is a static link or a -Bsymbolic link. The
6199 symbol is defined locally, or was forced to be local.
6200 We must initialize this entry in the GOT. */
6201 asection *sgot = mips_elf_got_section(elf_hash_table
6203 MIPS_ELF_PUT_WORD (elf_hash_table (info)->dynobj,
6204 symbol + addend, sgot->contents + g);
6207 else if (r_type == R_MIPS_GOT16)
6208 /* There's no need to create a local GOT entry here; the
6209 calculation for a local GOT16 entry does not involve G. */
6213 g = mips_elf_local_got_index (abfd, info, symbol + addend);
6214 if (g == (bfd_vma) -1)
6218 /* Convert GOT indices to actual offsets. */
6219 g = mips_elf_got_offset_from_index (elf_hash_table (info)->dynobj,
6225 case R_MIPS_GPREL16:
6226 case R_MIPS_GPREL32:
6227 case R_MIPS_LITERAL:
6228 gp0 = _bfd_get_gp_value (input_bfd);
6229 gp = _bfd_get_gp_value (abfd);
6236 /* Figure out what kind of relocation is being performed. */
6240 return bfd_reloc_continue;
6243 value = symbol + mips_elf_sign_extend (addend, 16);
6244 overflowed_p = mips_elf_overflow_p (value, 16);
6251 || (elf_hash_table (info)->dynamic_sections_created
6253 && ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)
6255 && (input_section->flags & SEC_ALLOC) != 0)
6257 /* If we're creating a shared library, or this relocation is
6258 against a symbol in a shared library, then we can't know
6259 where the symbol will end up. So, we create a relocation
6260 record in the output, and leave the job up to the dynamic
6263 if (!mips_elf_create_dynamic_relocation (abfd,
6270 input_section, local_p))
6275 if (r_type != R_MIPS_REL32)
6276 value = symbol + addend;
6280 value &= howto->dst_mask;
6285 case R_MIPS_GNU_REL_LO16:
6286 value = symbol + addend - p;
6287 value &= howto->dst_mask;
6290 case R_MIPS_GNU_REL16_S2:
6291 value = symbol + mips_elf_sign_extend (addend << 2, 18) - p;
6292 overflowed_p = mips_elf_overflow_p (value, 18);
6293 value = (value >> 2) & howto->dst_mask;
6296 case R_MIPS_GNU_REL_HI16:
6297 value = mips_elf_high (addend + symbol - p);
6298 value &= howto->dst_mask;
6302 /* The calculation for R_MIPS_26 is just the same as for an
6303 R_MIPS_26. It's only the storage of the relocated field into
6304 the output file that's different. That's handled in
6305 mips_elf_perform_relocation. So, we just fall through to the
6306 R_MIPS_26 case here. */
6309 value = (((addend << 2) | (p & 0xf0000000)) + symbol) >> 2;
6311 value = (mips_elf_sign_extend (addend << 2, 28) + symbol) >> 2;
6312 value &= howto->dst_mask;
6318 value = mips_elf_high (addend + symbol);
6319 value &= howto->dst_mask;
6323 value = mips_elf_high (addend + gp - p);
6324 overflowed_p = mips_elf_overflow_p (value, 16);
6330 value = (symbol + addend) & howto->dst_mask;
6333 value = addend + gp - p + 4;
6334 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
6335 for overflow. But, on, say, Irix 5, relocations against
6336 _gp_disp are normally generated from the .cpload
6337 pseudo-op. It generates code that normally looks like
6340 lui $gp,%hi(_gp_disp)
6341 addiu $gp,$gp,%lo(_gp_disp)
6344 Here $t9 holds the address of the function being called,
6345 as required by the MIPS ELF ABI. The R_MIPS_LO16
6346 relocation can easily overflow in this situation, but the
6347 R_MIPS_HI16 relocation will handle the overflow.
6348 Therefore, we consider this a bug in the MIPS ABI, and do
6349 not check for overflow here. */
6353 case R_MIPS_LITERAL:
6354 /* Because we don't merge literal sections, we can handle this
6355 just like R_MIPS_GPREL16. In the long run, we should merge
6356 shared literals, and then we will need to additional work
6361 case R_MIPS16_GPREL:
6362 /* The R_MIPS16_GPREL performs the same calculation as
6363 R_MIPS_GPREL16, but stores the relocated bits in a different
6364 order. We don't need to do anything special here; the
6365 differences are handled in mips_elf_perform_relocation. */
6366 case R_MIPS_GPREL16:
6368 value = mips_elf_sign_extend (addend, 16) + symbol + gp0 - gp;
6370 value = mips_elf_sign_extend (addend, 16) + symbol - gp;
6371 overflowed_p = mips_elf_overflow_p (value, 16);
6379 /* The special case is when the symbol is forced to be local. We
6380 need the full address in the GOT since no R_MIPS_LO16 relocation
6382 forced = ! mips_elf_local_relocation_p (input_bfd, relocation,
6383 local_sections, false);
6384 value = mips_elf_got16_entry (abfd, info, symbol + addend, forced);
6385 if (value == (bfd_vma) -1)
6388 = mips_elf_got_offset_from_index (elf_hash_table (info)->dynobj,
6391 overflowed_p = mips_elf_overflow_p (value, 16);
6398 case R_MIPS_GOT_DISP:
6400 overflowed_p = mips_elf_overflow_p (value, 16);
6403 case R_MIPS_GPREL32:
6404 value = (addend + symbol + gp0 - gp) & howto->dst_mask;
6408 value = mips_elf_sign_extend (addend, 16) + symbol - p;
6409 value = (bfd_vma) ((bfd_signed_vma) value / 4);
6410 overflowed_p = mips_elf_overflow_p (value, 16);
6413 case R_MIPS_GOT_HI16:
6414 case R_MIPS_CALL_HI16:
6415 /* We're allowed to handle these two relocations identically.
6416 The dynamic linker is allowed to handle the CALL relocations
6417 differently by creating a lazy evaluation stub. */
6419 value = mips_elf_high (value);
6420 value &= howto->dst_mask;
6423 case R_MIPS_GOT_LO16:
6424 case R_MIPS_CALL_LO16:
6425 value = g & howto->dst_mask;
6428 case R_MIPS_GOT_PAGE:
6429 value = mips_elf_got_page (abfd, info, symbol + addend, NULL);
6430 if (value == (bfd_vma) -1)
6432 value = mips_elf_got_offset_from_index (elf_hash_table (info)->dynobj,
6435 overflowed_p = mips_elf_overflow_p (value, 16);
6438 case R_MIPS_GOT_OFST:
6439 mips_elf_got_page (abfd, info, symbol + addend, &value);
6440 overflowed_p = mips_elf_overflow_p (value, 16);
6444 value = symbol - addend;
6445 value &= howto->dst_mask;
6449 value = mips_elf_higher (addend + symbol);
6450 value &= howto->dst_mask;
6453 case R_MIPS_HIGHEST:
6454 value = mips_elf_highest (addend + symbol);
6455 value &= howto->dst_mask;
6458 case R_MIPS_SCN_DISP:
6459 value = symbol + addend - sec->output_offset;
6460 value &= howto->dst_mask;
6465 /* Both of these may be ignored. R_MIPS_JALR is an optimization
6466 hint; we could improve performance by honoring that hint. */
6467 return bfd_reloc_continue;
6469 case R_MIPS_GNU_VTINHERIT:
6470 case R_MIPS_GNU_VTENTRY:
6471 /* We don't do anything with these at present. */
6472 return bfd_reloc_continue;
6475 /* An unrecognized relocation type. */
6476 return bfd_reloc_notsupported;
6479 /* Store the VALUE for our caller. */
6481 return overflowed_p ? bfd_reloc_overflow : bfd_reloc_ok;
6484 /* Obtain the field relocated by RELOCATION. */
6487 mips_elf_obtain_contents (howto, relocation, input_bfd, contents)
6488 reloc_howto_type *howto;
6489 const Elf_Internal_Rela *relocation;
6494 bfd_byte *location = contents + relocation->r_offset;
6496 /* Obtain the bytes. */
6497 x = bfd_get (8 * bfd_get_reloc_size (howto), input_bfd, location);
6499 if ((ELF32_R_TYPE (relocation->r_info) == R_MIPS16_26
6500 || ELF32_R_TYPE (relocation->r_info) == R_MIPS16_GPREL)
6501 && bfd_little_endian (input_bfd))
6502 /* The two 16-bit words will be reversed on a little-endian
6503 system. See mips_elf_perform_relocation for more details. */
6504 x = (((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16));
6509 /* It has been determined that the result of the RELOCATION is the
6510 VALUE. Use HOWTO to place VALUE into the output file at the
6511 appropriate position. The SECTION is the section to which the
6512 relocation applies. If REQUIRE_JALX is true, then the opcode used
6513 for the relocation must be either JAL or JALX, and it is
6514 unconditionally converted to JALX.
6516 Returns false if anything goes wrong. */
6519 mips_elf_perform_relocation (info, howto, relocation, value,
6520 input_bfd, input_section,
6521 contents, require_jalx)
6522 struct bfd_link_info *info;
6523 reloc_howto_type *howto;
6524 const Elf_Internal_Rela *relocation;
6527 asection *input_section;
6529 boolean require_jalx;
6533 int r_type = ELF32_R_TYPE (relocation->r_info);
6535 /* Figure out where the relocation is occurring. */
6536 location = contents + relocation->r_offset;
6538 /* Obtain the current value. */
6539 x = mips_elf_obtain_contents (howto, relocation, input_bfd, contents);
6541 /* Clear the field we are setting. */
6542 x &= ~howto->dst_mask;
6544 /* If this is the R_MIPS16_26 relocation, we must store the
6545 value in a funny way. */
6546 if (r_type == R_MIPS16_26)
6548 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
6549 Most mips16 instructions are 16 bits, but these instructions
6552 The format of these instructions is:
6554 +--------------+--------------------------------+
6555 ! JALX ! X! Imm 20:16 ! Imm 25:21 !
6556 +--------------+--------------------------------+
6558 +-----------------------------------------------+
6560 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
6561 Note that the immediate value in the first word is swapped.
6563 When producing a relocateable object file, R_MIPS16_26 is
6564 handled mostly like R_MIPS_26. In particular, the addend is
6565 stored as a straight 26-bit value in a 32-bit instruction.
6566 (gas makes life simpler for itself by never adjusting a
6567 R_MIPS16_26 reloc to be against a section, so the addend is
6568 always zero). However, the 32 bit instruction is stored as 2
6569 16-bit values, rather than a single 32-bit value. In a
6570 big-endian file, the result is the same; in a little-endian
6571 file, the two 16-bit halves of the 32 bit value are swapped.
6572 This is so that a disassembler can recognize the jal
6575 When doing a final link, R_MIPS16_26 is treated as a 32 bit
6576 instruction stored as two 16-bit values. The addend A is the
6577 contents of the targ26 field. The calculation is the same as
6578 R_MIPS_26. When storing the calculated value, reorder the
6579 immediate value as shown above, and don't forget to store the
6580 value as two 16-bit values.
6582 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
6586 +--------+----------------------+
6590 +--------+----------------------+
6593 +----------+------+-------------+
6597 +----------+--------------------+
6598 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
6599 ((sub1 << 16) | sub2)).
6601 When producing a relocateable object file, the calculation is
6602 (((A < 2) | (P & 0xf0000000) + S) >> 2)
6603 When producing a fully linked file, the calculation is
6604 let R = (((A < 2) | (P & 0xf0000000) + S) >> 2)
6605 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff) */
6607 if (!info->relocateable)
6608 /* Shuffle the bits according to the formula above. */
6609 value = (((value & 0x1f0000) << 5)
6610 | ((value & 0x3e00000) >> 5)
6611 | (value & 0xffff));
6614 else if (r_type == R_MIPS16_GPREL)
6616 /* R_MIPS16_GPREL is used for GP-relative addressing in mips16
6617 mode. A typical instruction will have a format like this:
6619 +--------------+--------------------------------+
6620 ! EXTEND ! Imm 10:5 ! Imm 15:11 !
6621 +--------------+--------------------------------+
6622 ! Major ! rx ! ry ! Imm 4:0 !
6623 +--------------+--------------------------------+
6625 EXTEND is the five bit value 11110. Major is the instruction
6628 This is handled exactly like R_MIPS_GPREL16, except that the
6629 addend is retrieved and stored as shown in this diagram; that
6630 is, the Imm fields above replace the V-rel16 field.
6632 All we need to do here is shuffle the bits appropriately. As
6633 above, the two 16-bit halves must be swapped on a
6634 little-endian system. */
6635 value = (((value & 0x7e0) << 16)
6636 | ((value & 0xf800) << 5)
6640 /* Set the field. */
6641 x |= (value & howto->dst_mask);
6643 /* If required, turn JAL into JALX. */
6647 bfd_vma opcode = x >> 26;
6648 bfd_vma jalx_opcode;
6650 /* Check to see if the opcode is already JAL or JALX. */
6651 if (r_type == R_MIPS16_26)
6653 ok = ((opcode == 0x6) || (opcode == 0x7));
6658 ok = ((opcode == 0x3) || (opcode == 0x1d));
6662 /* If the opcode is not JAL or JALX, there's a problem. */
6665 (*_bfd_error_handler)
6666 (_("%s: %s+0x%lx: jump to stub routine which is not jal"),
6667 bfd_get_filename (input_bfd),
6668 input_section->name,
6669 (unsigned long) relocation->r_offset);
6670 bfd_set_error (bfd_error_bad_value);
6674 /* Make this the JALX opcode. */
6675 x = (x & ~(0x3f << 26)) | (jalx_opcode << 26);
6678 /* Swap the high- and low-order 16 bits on little-endian systems
6679 when doing a MIPS16 relocation. */
6680 if ((r_type == R_MIPS16_GPREL || r_type == R_MIPS16_26)
6681 && bfd_little_endian (input_bfd))
6682 x = (((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16));
6684 /* Put the value into the output. */
6685 bfd_put (8 * bfd_get_reloc_size (howto), input_bfd, x, location);
6689 /* Returns true if SECTION is a MIPS16 stub section. */
6692 mips_elf_stub_section_p (abfd, section)
6693 bfd *abfd ATTRIBUTE_UNUSED;
6696 const char *name = bfd_get_section_name (abfd, section);
6698 return (strncmp (name, FN_STUB, sizeof FN_STUB - 1) == 0
6699 || strncmp (name, CALL_STUB, sizeof CALL_STUB - 1) == 0
6700 || strncmp (name, CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0);
6703 /* Relocate a MIPS ELF section. */
6706 _bfd_mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
6707 contents, relocs, local_syms, local_sections)
6709 struct bfd_link_info *info;
6711 asection *input_section;
6713 Elf_Internal_Rela *relocs;
6714 Elf_Internal_Sym *local_syms;
6715 asection **local_sections;
6717 Elf_Internal_Rela *rel;
6718 const Elf_Internal_Rela *relend;
6720 boolean use_saved_addend_p = false;
6721 struct elf_backend_data *bed;
6723 bed = get_elf_backend_data (output_bfd);
6724 relend = relocs + input_section->reloc_count * bed->s->int_rels_per_ext_rel;
6725 for (rel = relocs; rel < relend; ++rel)
6729 reloc_howto_type *howto;
6730 boolean require_jalx;
6731 /* True if the relocation is a RELA relocation, rather than a
6733 boolean rela_relocation_p = true;
6734 int r_type = ELF32_R_TYPE (rel->r_info);
6736 /* Find the relocation howto for this relocation. */
6737 if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd))
6739 /* Some 32-bit code uses R_MIPS_64. In particular, people use
6740 64-bit code, but make sure all their addresses are in the
6741 lowermost or uppermost 32-bit section of the 64-bit address
6742 space. Thus, when they use an R_MIPS_64 they mean what is
6743 usually meant by R_MIPS_32, with the exception that the
6744 stored value is sign-extended to 64 bits. */
6745 howto = elf_mips_howto_table + R_MIPS_32;
6747 /* On big-endian systems, we need to lie about the position
6749 if (bfd_big_endian (input_bfd))
6753 howto = mips_rtype_to_howto (r_type);
6755 if (!use_saved_addend_p)
6757 Elf_Internal_Shdr *rel_hdr;
6759 /* If these relocations were originally of the REL variety,
6760 we must pull the addend out of the field that will be
6761 relocated. Otherwise, we simply use the contents of the
6762 RELA relocation. To determine which flavor or relocation
6763 this is, we depend on the fact that the INPUT_SECTION's
6764 REL_HDR is read before its REL_HDR2. */
6765 rel_hdr = &elf_section_data (input_section)->rel_hdr;
6766 if ((size_t) (rel - relocs)
6767 >= (rel_hdr->sh_size / rel_hdr->sh_entsize
6768 * bed->s->int_rels_per_ext_rel))
6769 rel_hdr = elf_section_data (input_section)->rel_hdr2;
6770 if (rel_hdr->sh_entsize == MIPS_ELF_REL_SIZE (input_bfd))
6772 /* Note that this is a REL relocation. */
6773 rela_relocation_p = false;
6775 /* Get the addend, which is stored in the input file. */
6776 addend = mips_elf_obtain_contents (howto,
6780 addend &= howto->src_mask;
6782 /* For some kinds of relocations, the ADDEND is a
6783 combination of the addend stored in two different
6785 if (r_type == R_MIPS_HI16
6786 || r_type == R_MIPS_GNU_REL_HI16
6787 || (r_type == R_MIPS_GOT16
6788 && mips_elf_local_relocation_p (input_bfd, rel,
6789 local_sections, false)))
6792 const Elf_Internal_Rela *lo16_relocation;
6793 reloc_howto_type *lo16_howto;
6796 /* The combined value is the sum of the HI16 addend,
6797 left-shifted by sixteen bits, and the LO16
6798 addend, sign extended. (Usually, the code does
6799 a `lui' of the HI16 value, and then an `addiu' of
6802 Scan ahead to find a matching LO16 relocation. */
6803 if (r_type == R_MIPS_GNU_REL_HI16)
6804 lo = R_MIPS_GNU_REL_LO16;
6808 = mips_elf_next_relocation (lo, rel, relend);
6809 if (lo16_relocation == NULL)
6812 /* Obtain the addend kept there. */
6813 lo16_howto = mips_rtype_to_howto (lo);
6814 l = mips_elf_obtain_contents (lo16_howto,
6816 input_bfd, contents);
6817 l &= lo16_howto->src_mask;
6818 l = mips_elf_sign_extend (l, 16);
6822 /* Compute the combined addend. */
6825 else if (r_type == R_MIPS16_GPREL)
6827 /* The addend is scrambled in the object file. See
6828 mips_elf_perform_relocation for details on the
6830 addend = (((addend & 0x1f0000) >> 5)
6831 | ((addend & 0x7e00000) >> 16)
6836 addend = rel->r_addend;
6839 if (info->relocateable)
6841 Elf_Internal_Sym *sym;
6842 unsigned long r_symndx;
6844 if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd)
6845 && bfd_big_endian (input_bfd))
6848 /* Since we're just relocating, all we need to do is copy
6849 the relocations back out to the object file, unless
6850 they're against a section symbol, in which case we need
6851 to adjust by the section offset, or unless they're GP
6852 relative in which case we need to adjust by the amount
6853 that we're adjusting GP in this relocateable object. */
6855 if (!mips_elf_local_relocation_p (input_bfd, rel, local_sections,
6857 /* There's nothing to do for non-local relocations. */
6860 if (r_type == R_MIPS16_GPREL
6861 || r_type == R_MIPS_GPREL16
6862 || r_type == R_MIPS_GPREL32
6863 || r_type == R_MIPS_LITERAL)
6864 addend -= (_bfd_get_gp_value (output_bfd)
6865 - _bfd_get_gp_value (input_bfd));
6866 else if (r_type == R_MIPS_26 || r_type == R_MIPS16_26
6867 || r_type == R_MIPS_GNU_REL16_S2)
6868 /* The addend is stored without its two least
6869 significant bits (which are always zero.) In a
6870 non-relocateable link, calculate_relocation will do
6871 this shift; here, we must do it ourselves. */
6874 r_symndx = ELF32_R_SYM (rel->r_info);
6875 sym = local_syms + r_symndx;
6876 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
6877 /* Adjust the addend appropriately. */
6878 addend += local_sections[r_symndx]->output_offset;
6880 /* If the relocation is for a R_MIPS_HI16 or R_MIPS_GOT16,
6881 then we only want to write out the high-order 16 bits.
6882 The subsequent R_MIPS_LO16 will handle the low-order bits. */
6883 if (r_type == R_MIPS_HI16 || r_type == R_MIPS_GOT16
6884 || r_type == R_MIPS_GNU_REL_HI16)
6885 addend = mips_elf_high (addend);
6886 /* If the relocation is for an R_MIPS_26 relocation, then
6887 the two low-order bits are not stored in the object file;
6888 they are implicitly zero. */
6889 else if (r_type == R_MIPS_26 || r_type == R_MIPS16_26
6890 || r_type == R_MIPS_GNU_REL16_S2)
6893 if (rela_relocation_p)
6894 /* If this is a RELA relocation, just update the addend.
6895 We have to cast away constness for REL. */
6896 rel->r_addend = addend;
6899 /* Otherwise, we have to write the value back out. Note
6900 that we use the source mask, rather than the
6901 destination mask because the place to which we are
6902 writing will be source of the addend in the final
6904 addend &= howto->src_mask;
6906 if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd))
6907 /* See the comment above about using R_MIPS_64 in the 32-bit
6908 ABI. Here, we need to update the addend. It would be
6909 possible to get away with just using the R_MIPS_32 reloc
6910 but for endianness. */
6916 if (addend & ((bfd_vma) 1 << 31))
6917 sign_bits = ((bfd_vma) 1 << 32) - 1;
6921 /* If we don't know that we have a 64-bit type,
6922 do two separate stores. */
6923 if (bfd_big_endian (input_bfd))
6925 /* Store the sign-bits (which are most significant)
6927 low_bits = sign_bits;
6933 high_bits = sign_bits;
6935 bfd_put_32 (input_bfd, low_bits,
6936 contents + rel->r_offset);
6937 bfd_put_32 (input_bfd, high_bits,
6938 contents + rel->r_offset + 4);
6942 if (!mips_elf_perform_relocation (info, howto, rel, addend,
6943 input_bfd, input_section,
6948 /* Go on to the next relocation. */
6952 /* In the N32 and 64-bit ABIs there may be multiple consecutive
6953 relocations for the same offset. In that case we are
6954 supposed to treat the output of each relocation as the addend
6956 if (rel + 1 < relend
6957 && rel->r_offset == rel[1].r_offset
6958 && ELF32_R_TYPE (rel[1].r_info) != R_MIPS_NONE)
6959 use_saved_addend_p = true;
6961 use_saved_addend_p = false;
6963 /* Figure out what value we are supposed to relocate. */
6964 switch (mips_elf_calculate_relocation (output_bfd,
6977 case bfd_reloc_continue:
6978 /* There's nothing to do. */
6981 case bfd_reloc_undefined:
6982 /* mips_elf_calculate_relocation already called the
6983 undefined_symbol callback. There's no real point in
6984 trying to perform the relocation at this point, so we
6985 just skip ahead to the next relocation. */
6988 case bfd_reloc_notsupported:
6992 case bfd_reloc_overflow:
6993 if (use_saved_addend_p)
6994 /* Ignore overflow until we reach the last relocation for
6995 a given location. */
6999 BFD_ASSERT (name != NULL);
7000 if (! ((*info->callbacks->reloc_overflow)
7001 (info, name, howto->name, (bfd_vma) 0,
7002 input_bfd, input_section, rel->r_offset)))
7015 /* If we've got another relocation for the address, keep going
7016 until we reach the last one. */
7017 if (use_saved_addend_p)
7023 if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd))
7024 /* See the comment above about using R_MIPS_64 in the 32-bit
7025 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
7026 that calculated the right value. Now, however, we
7027 sign-extend the 32-bit result to 64-bits, and store it as a
7028 64-bit value. We are especially generous here in that we
7029 go to extreme lengths to support this usage on systems with
7030 only a 32-bit VMA. */
7036 if (value & ((bfd_vma) 1 << 31))
7037 sign_bits = ((bfd_vma) 1 << 32) - 1;
7041 /* If we don't know that we have a 64-bit type,
7042 do two separate stores. */
7043 if (bfd_big_endian (input_bfd))
7045 /* Undo what we did above. */
7047 /* Store the sign-bits (which are most significant)
7049 low_bits = sign_bits;
7055 high_bits = sign_bits;
7057 bfd_put_32 (input_bfd, low_bits,
7058 contents + rel->r_offset);
7059 bfd_put_32 (input_bfd, high_bits,
7060 contents + rel->r_offset + 4);
7064 /* Actually perform the relocation. */
7065 if (!mips_elf_perform_relocation (info, howto, rel, value, input_bfd,
7066 input_section, contents,
7074 /* This hook function is called before the linker writes out a global
7075 symbol. We mark symbols as small common if appropriate. This is
7076 also where we undo the increment of the value for a mips16 symbol. */
7079 _bfd_mips_elf_link_output_symbol_hook (abfd, info, name, sym, input_sec)
7080 bfd *abfd ATTRIBUTE_UNUSED;
7081 struct bfd_link_info *info ATTRIBUTE_UNUSED;
7082 const char *name ATTRIBUTE_UNUSED;
7083 Elf_Internal_Sym *sym;
7084 asection *input_sec;
7086 /* If we see a common symbol, which implies a relocatable link, then
7087 if a symbol was small common in an input file, mark it as small
7088 common in the output file. */
7089 if (sym->st_shndx == SHN_COMMON
7090 && strcmp (input_sec->name, ".scommon") == 0)
7091 sym->st_shndx = SHN_MIPS_SCOMMON;
7093 if (sym->st_other == STO_MIPS16
7094 && (sym->st_value & 1) != 0)
7100 /* Functions for the dynamic linker. */
7102 /* The name of the dynamic interpreter. This is put in the .interp
7105 #define ELF_DYNAMIC_INTERPRETER(abfd) \
7106 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
7107 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
7108 : "/usr/lib/libc.so.1")
7110 /* Create dynamic sections when linking against a dynamic object. */
7113 _bfd_mips_elf_create_dynamic_sections (abfd, info)
7115 struct bfd_link_info *info;
7117 struct elf_link_hash_entry *h;
7119 register asection *s;
7120 const char * const *namep;
7122 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
7123 | SEC_LINKER_CREATED | SEC_READONLY);
7125 /* Mips ABI requests the .dynamic section to be read only. */
7126 s = bfd_get_section_by_name (abfd, ".dynamic");
7129 if (! bfd_set_section_flags (abfd, s, flags))
7133 /* We need to create .got section. */
7134 if (! mips_elf_create_got_section (abfd, info))
7137 /* Create the .msym section on IRIX6. It is used by the dynamic
7138 linker to speed up dynamic relocations, and to avoid computing
7139 the ELF hash for symbols. */
7140 if (IRIX_COMPAT (abfd) == ict_irix6
7141 && !mips_elf_create_msym_section (abfd))
7144 /* Create .stub section. */
7145 if (bfd_get_section_by_name (abfd,
7146 MIPS_ELF_STUB_SECTION_NAME (abfd)) == NULL)
7148 s = bfd_make_section (abfd, MIPS_ELF_STUB_SECTION_NAME (abfd));
7150 || ! bfd_set_section_flags (abfd, s, flags | SEC_CODE)
7151 || ! bfd_set_section_alignment (abfd, s,
7152 MIPS_ELF_LOG_FILE_ALIGN (abfd)))
7156 if ((IRIX_COMPAT (abfd) == ict_irix5 || IRIX_COMPAT (abfd) == ict_none)
7158 && bfd_get_section_by_name (abfd, ".rld_map") == NULL)
7160 s = bfd_make_section (abfd, ".rld_map");
7162 || ! bfd_set_section_flags (abfd, s, flags & ~SEC_READONLY)
7163 || ! bfd_set_section_alignment (abfd, s,
7164 MIPS_ELF_LOG_FILE_ALIGN (abfd)))
7168 /* On IRIX5, we adjust add some additional symbols and change the
7169 alignments of several sections. There is no ABI documentation
7170 indicating that this is necessary on IRIX6, nor any evidence that
7171 the linker takes such action. */
7172 if (IRIX_COMPAT (abfd) == ict_irix5)
7174 for (namep = mips_elf_dynsym_rtproc_names; *namep != NULL; namep++)
7177 if (! (_bfd_generic_link_add_one_symbol
7178 (info, abfd, *namep, BSF_GLOBAL, bfd_und_section_ptr,
7179 (bfd_vma) 0, (const char *) NULL, false,
7180 get_elf_backend_data (abfd)->collect,
7181 (struct bfd_link_hash_entry **) &h)))
7183 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
7184 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
7185 h->type = STT_SECTION;
7187 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
7191 /* We need to create a .compact_rel section. */
7192 if (SGI_COMPAT (abfd))
7194 if (!mips_elf_create_compact_rel_section (abfd, info))
7198 /* Change aligments of some sections. */
7199 s = bfd_get_section_by_name (abfd, ".hash");
7201 bfd_set_section_alignment (abfd, s, 4);
7202 s = bfd_get_section_by_name (abfd, ".dynsym");
7204 bfd_set_section_alignment (abfd, s, 4);
7205 s = bfd_get_section_by_name (abfd, ".dynstr");
7207 bfd_set_section_alignment (abfd, s, 4);
7208 s = bfd_get_section_by_name (abfd, ".reginfo");
7210 bfd_set_section_alignment (abfd, s, 4);
7211 s = bfd_get_section_by_name (abfd, ".dynamic");
7213 bfd_set_section_alignment (abfd, s, 4);
7219 if (SGI_COMPAT (abfd))
7221 if (!(_bfd_generic_link_add_one_symbol
7222 (info, abfd, "_DYNAMIC_LINK", BSF_GLOBAL, bfd_abs_section_ptr,
7223 (bfd_vma) 0, (const char *) NULL, false,
7224 get_elf_backend_data (abfd)->collect,
7225 (struct bfd_link_hash_entry **) &h)))
7230 /* For normal mips it is _DYNAMIC_LINKING. */
7231 if (!(_bfd_generic_link_add_one_symbol
7232 (info, abfd, "_DYNAMIC_LINKING", BSF_GLOBAL,
7233 bfd_abs_section_ptr, (bfd_vma) 0, (const char *) NULL, false,
7234 get_elf_backend_data (abfd)->collect,
7235 (struct bfd_link_hash_entry **) &h)))
7238 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
7239 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
7240 h->type = STT_SECTION;
7242 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
7245 if (! mips_elf_hash_table (info)->use_rld_obj_head)
7247 /* __rld_map is a four byte word located in the .data section
7248 and is filled in by the rtld to contain a pointer to
7249 the _r_debug structure. Its symbol value will be set in
7250 mips_elf_finish_dynamic_symbol. */
7251 s = bfd_get_section_by_name (abfd, ".rld_map");
7252 BFD_ASSERT (s != NULL);
7255 if (SGI_COMPAT (abfd))
7257 if (!(_bfd_generic_link_add_one_symbol
7258 (info, abfd, "__rld_map", BSF_GLOBAL, s,
7259 (bfd_vma) 0, (const char *) NULL, false,
7260 get_elf_backend_data (abfd)->collect,
7261 (struct bfd_link_hash_entry **) &h)))
7266 /* For normal mips the symbol is __RLD_MAP. */
7267 if (!(_bfd_generic_link_add_one_symbol
7268 (info, abfd, "__RLD_MAP", BSF_GLOBAL, s,
7269 (bfd_vma) 0, (const char *) NULL, false,
7270 get_elf_backend_data (abfd)->collect,
7271 (struct bfd_link_hash_entry **) &h)))
7274 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
7275 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
7276 h->type = STT_OBJECT;
7278 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
7286 /* Create the .compact_rel section. */
7289 mips_elf_create_compact_rel_section (abfd, info)
7291 struct bfd_link_info *info ATTRIBUTE_UNUSED;
7294 register asection *s;
7296 if (bfd_get_section_by_name (abfd, ".compact_rel") == NULL)
7298 flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED
7301 s = bfd_make_section (abfd, ".compact_rel");
7303 || ! bfd_set_section_flags (abfd, s, flags)
7304 || ! bfd_set_section_alignment (abfd, s,
7305 MIPS_ELF_LOG_FILE_ALIGN (abfd)))
7308 s->_raw_size = sizeof (Elf32_External_compact_rel);
7314 /* Create the .got section to hold the global offset table. */
7317 mips_elf_create_got_section (abfd, info)
7319 struct bfd_link_info *info;
7322 register asection *s;
7323 struct elf_link_hash_entry *h;
7324 struct mips_got_info *g;
7326 /* This function may be called more than once. */
7327 if (mips_elf_got_section (abfd))
7330 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
7331 | SEC_LINKER_CREATED);
7333 s = bfd_make_section (abfd, ".got");
7335 || ! bfd_set_section_flags (abfd, s, flags)
7336 || ! bfd_set_section_alignment (abfd, s, 4))
7339 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
7340 linker script because we don't want to define the symbol if we
7341 are not creating a global offset table. */
7343 if (! (_bfd_generic_link_add_one_symbol
7344 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
7345 (bfd_vma) 0, (const char *) NULL, false,
7346 get_elf_backend_data (abfd)->collect,
7347 (struct bfd_link_hash_entry **) &h)))
7349 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
7350 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
7351 h->type = STT_OBJECT;
7354 && ! bfd_elf32_link_record_dynamic_symbol (info, h))
7357 /* The first several global offset table entries are reserved. */
7358 s->_raw_size = MIPS_RESERVED_GOTNO * MIPS_ELF_GOT_SIZE (abfd);
7360 g = (struct mips_got_info *) bfd_alloc (abfd,
7361 sizeof (struct mips_got_info));
7364 g->global_gotsym = NULL;
7365 g->local_gotno = MIPS_RESERVED_GOTNO;
7366 g->assigned_gotno = MIPS_RESERVED_GOTNO;
7367 if (elf_section_data (s) == NULL)
7370 (PTR) bfd_zalloc (abfd, sizeof (struct bfd_elf_section_data));
7371 if (elf_section_data (s) == NULL)
7374 elf_section_data (s)->tdata = (PTR) g;
7375 elf_section_data (s)->this_hdr.sh_flags
7376 |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
7381 /* Returns the .msym section for ABFD, creating it if it does not
7382 already exist. Returns NULL to indicate error. */
7385 mips_elf_create_msym_section (abfd)
7390 s = bfd_get_section_by_name (abfd, MIPS_ELF_MSYM_SECTION_NAME (abfd));
7393 s = bfd_make_section (abfd, MIPS_ELF_MSYM_SECTION_NAME (abfd));
7395 || !bfd_set_section_flags (abfd, s,
7399 | SEC_LINKER_CREATED
7401 || !bfd_set_section_alignment (abfd, s,
7402 MIPS_ELF_LOG_FILE_ALIGN (abfd)))
7409 /* Add room for N relocations to the .rel.dyn section in ABFD. */
7412 mips_elf_allocate_dynamic_relocations (abfd, n)
7418 s = bfd_get_section_by_name (abfd, MIPS_ELF_REL_DYN_SECTION_NAME (abfd));
7419 BFD_ASSERT (s != NULL);
7421 if (s->_raw_size == 0)
7423 /* Make room for a null element. */
7424 s->_raw_size += MIPS_ELF_REL_SIZE (abfd);
7427 s->_raw_size += n * MIPS_ELF_REL_SIZE (abfd);
7430 /* Look through the relocs for a section during the first phase, and
7431 allocate space in the global offset table. */
7434 _bfd_mips_elf_check_relocs (abfd, info, sec, relocs)
7436 struct bfd_link_info *info;
7438 const Elf_Internal_Rela *relocs;
7442 Elf_Internal_Shdr *symtab_hdr;
7443 struct elf_link_hash_entry **sym_hashes;
7444 struct mips_got_info *g;
7446 const Elf_Internal_Rela *rel;
7447 const Elf_Internal_Rela *rel_end;
7450 struct elf_backend_data *bed;
7452 if (info->relocateable)
7455 dynobj = elf_hash_table (info)->dynobj;
7456 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
7457 sym_hashes = elf_sym_hashes (abfd);
7458 extsymoff = (elf_bad_symtab (abfd)) ? 0 : symtab_hdr->sh_info;
7460 /* Check for the mips16 stub sections. */
7462 name = bfd_get_section_name (abfd, sec);
7463 if (strncmp (name, FN_STUB, sizeof FN_STUB - 1) == 0)
7465 unsigned long r_symndx;
7467 /* Look at the relocation information to figure out which symbol
7470 r_symndx = ELF32_R_SYM (relocs->r_info);
7472 if (r_symndx < extsymoff
7473 || sym_hashes[r_symndx - extsymoff] == NULL)
7477 /* This stub is for a local symbol. This stub will only be
7478 needed if there is some relocation in this BFD, other
7479 than a 16 bit function call, which refers to this symbol. */
7480 for (o = abfd->sections; o != NULL; o = o->next)
7482 Elf_Internal_Rela *sec_relocs;
7483 const Elf_Internal_Rela *r, *rend;
7485 /* We can ignore stub sections when looking for relocs. */
7486 if ((o->flags & SEC_RELOC) == 0
7487 || o->reloc_count == 0
7488 || strncmp (bfd_get_section_name (abfd, o), FN_STUB,
7489 sizeof FN_STUB - 1) == 0
7490 || strncmp (bfd_get_section_name (abfd, o), CALL_STUB,
7491 sizeof CALL_STUB - 1) == 0
7492 || strncmp (bfd_get_section_name (abfd, o), CALL_FP_STUB,
7493 sizeof CALL_FP_STUB - 1) == 0)
7496 sec_relocs = (_bfd_elf32_link_read_relocs
7497 (abfd, o, (PTR) NULL,
7498 (Elf_Internal_Rela *) NULL,
7499 info->keep_memory));
7500 if (sec_relocs == NULL)
7503 rend = sec_relocs + o->reloc_count;
7504 for (r = sec_relocs; r < rend; r++)
7505 if (ELF32_R_SYM (r->r_info) == r_symndx
7506 && ELF32_R_TYPE (r->r_info) != R_MIPS16_26)
7509 if (! info->keep_memory)
7518 /* There is no non-call reloc for this stub, so we do
7519 not need it. Since this function is called before
7520 the linker maps input sections to output sections, we
7521 can easily discard it by setting the SEC_EXCLUDE
7523 sec->flags |= SEC_EXCLUDE;
7527 /* Record this stub in an array of local symbol stubs for
7529 if (elf_tdata (abfd)->local_stubs == NULL)
7531 unsigned long symcount;
7534 if (elf_bad_symtab (abfd))
7535 symcount = symtab_hdr->sh_size / symtab_hdr->sh_entsize;
7537 symcount = symtab_hdr->sh_info;
7538 n = (asection **) bfd_zalloc (abfd,
7539 symcount * sizeof (asection *));
7542 elf_tdata (abfd)->local_stubs = n;
7545 elf_tdata (abfd)->local_stubs[r_symndx] = sec;
7547 /* We don't need to set mips16_stubs_seen in this case.
7548 That flag is used to see whether we need to look through
7549 the global symbol table for stubs. We don't need to set
7550 it here, because we just have a local stub. */
7554 struct mips_elf_link_hash_entry *h;
7556 h = ((struct mips_elf_link_hash_entry *)
7557 sym_hashes[r_symndx - extsymoff]);
7559 /* H is the symbol this stub is for. */
7562 mips_elf_hash_table (info)->mips16_stubs_seen = true;
7565 else if (strncmp (name, CALL_STUB, sizeof CALL_STUB - 1) == 0
7566 || strncmp (name, CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0)
7568 unsigned long r_symndx;
7569 struct mips_elf_link_hash_entry *h;
7572 /* Look at the relocation information to figure out which symbol
7575 r_symndx = ELF32_R_SYM (relocs->r_info);
7577 if (r_symndx < extsymoff
7578 || sym_hashes[r_symndx - extsymoff] == NULL)
7580 /* This stub was actually built for a static symbol defined
7581 in the same file. We assume that all static symbols in
7582 mips16 code are themselves mips16, so we can simply
7583 discard this stub. Since this function is called before
7584 the linker maps input sections to output sections, we can
7585 easily discard it by setting the SEC_EXCLUDE flag. */
7586 sec->flags |= SEC_EXCLUDE;
7590 h = ((struct mips_elf_link_hash_entry *)
7591 sym_hashes[r_symndx - extsymoff]);
7593 /* H is the symbol this stub is for. */
7595 if (strncmp (name, CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0)
7596 loc = &h->call_fp_stub;
7598 loc = &h->call_stub;
7600 /* If we already have an appropriate stub for this function, we
7601 don't need another one, so we can discard this one. Since
7602 this function is called before the linker maps input sections
7603 to output sections, we can easily discard it by setting the
7604 SEC_EXCLUDE flag. We can also discard this section if we
7605 happen to already know that this is a mips16 function; it is
7606 not necessary to check this here, as it is checked later, but
7607 it is slightly faster to check now. */
7608 if (*loc != NULL || h->root.other == STO_MIPS16)
7610 sec->flags |= SEC_EXCLUDE;
7615 mips_elf_hash_table (info)->mips16_stubs_seen = true;
7625 sgot = mips_elf_got_section (dynobj);
7630 BFD_ASSERT (elf_section_data (sgot) != NULL);
7631 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
7632 BFD_ASSERT (g != NULL);
7637 bed = get_elf_backend_data (abfd);
7638 rel_end = relocs + sec->reloc_count * bed->s->int_rels_per_ext_rel;
7639 for (rel = relocs; rel < rel_end; ++rel)
7641 unsigned long r_symndx;
7643 struct elf_link_hash_entry *h;
7645 r_symndx = ELF32_R_SYM (rel->r_info);
7646 r_type = ELF32_R_TYPE (rel->r_info);
7648 if (r_symndx < extsymoff)
7650 else if (r_symndx >= extsymoff + (symtab_hdr->sh_size / symtab_hdr->sh_entsize))
7652 (*_bfd_error_handler)
7653 (_("Malformed reloc detected for section %s"), name);
7654 bfd_set_error (bfd_error_bad_value);
7659 h = sym_hashes[r_symndx - extsymoff];
7661 /* This may be an indirect symbol created because of a version. */
7664 while (h->root.type == bfd_link_hash_indirect)
7665 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7669 /* Some relocs require a global offset table. */
7670 if (dynobj == NULL || sgot == NULL)
7676 case R_MIPS_CALL_HI16:
7677 case R_MIPS_CALL_LO16:
7678 case R_MIPS_GOT_HI16:
7679 case R_MIPS_GOT_LO16:
7680 case R_MIPS_GOT_PAGE:
7681 case R_MIPS_GOT_OFST:
7682 case R_MIPS_GOT_DISP:
7684 elf_hash_table (info)->dynobj = dynobj = abfd;
7685 if (! mips_elf_create_got_section (dynobj, info))
7687 g = mips_elf_got_info (dynobj, &sgot);
7694 && (info->shared || h != NULL)
7695 && (sec->flags & SEC_ALLOC) != 0)
7696 elf_hash_table (info)->dynobj = dynobj = abfd;
7704 if (!h && (r_type == R_MIPS_CALL_LO16
7705 || r_type == R_MIPS_GOT_LO16
7706 || r_type == R_MIPS_GOT_DISP))
7708 /* We may need a local GOT entry for this relocation. We
7709 don't count R_MIPS_GOT_PAGE because we can estimate the
7710 maximum number of pages needed by looking at the size of
7711 the segment. Similar comments apply to R_MIPS_GOT16. We
7712 don't count R_MIPS_GOT_HI16, or R_MIPS_CALL_HI16 because
7713 these are always followed by an R_MIPS_GOT_LO16 or
7716 This estimation is very conservative since we can merge
7717 duplicate entries in the GOT. In order to be less
7718 conservative, we could actually build the GOT here,
7719 rather than in relocate_section. */
7721 sgot->_raw_size += MIPS_ELF_GOT_SIZE (dynobj);
7729 (*_bfd_error_handler)
7730 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
7731 bfd_get_filename (abfd), (unsigned long) rel->r_offset);
7732 bfd_set_error (bfd_error_bad_value);
7737 case R_MIPS_CALL_HI16:
7738 case R_MIPS_CALL_LO16:
7741 /* This symbol requires a global offset table entry. */
7742 if (!mips_elf_record_global_got_symbol (h, info, g))
7745 /* We need a stub, not a plt entry for the undefined
7746 function. But we record it as if it needs plt. See
7747 elf_adjust_dynamic_symbol in elflink.h. */
7748 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
7754 case R_MIPS_GOT_HI16:
7755 case R_MIPS_GOT_LO16:
7756 case R_MIPS_GOT_DISP:
7757 /* This symbol requires a global offset table entry. */
7758 if (h && !mips_elf_record_global_got_symbol (h, info, g))
7765 if ((info->shared || h != NULL)
7766 && (sec->flags & SEC_ALLOC) != 0)
7770 const char *name = MIPS_ELF_REL_DYN_SECTION_NAME (dynobj);
7772 sreloc = bfd_get_section_by_name (dynobj, name);
7775 sreloc = bfd_make_section (dynobj, name);
7777 || ! bfd_set_section_flags (dynobj, sreloc,
7782 | SEC_LINKER_CREATED
7784 || ! bfd_set_section_alignment (dynobj, sreloc,
7790 /* When creating a shared object, we must copy these
7791 reloc types into the output file as R_MIPS_REL32
7792 relocs. We make room for this reloc in the
7793 .rel.dyn reloc section. */
7794 mips_elf_allocate_dynamic_relocations (dynobj, 1);
7797 struct mips_elf_link_hash_entry *hmips;
7799 /* We only need to copy this reloc if the symbol is
7800 defined in a dynamic object. */
7801 hmips = (struct mips_elf_link_hash_entry *) h;
7802 ++hmips->possibly_dynamic_relocs;
7805 /* Even though we don't directly need a GOT entry for
7806 this symbol, a symbol must have a dynamic symbol
7807 table index greater that DT_MIPS_GOTSYM if there are
7808 dynamic relocations against it. */
7810 && !mips_elf_record_global_got_symbol (h, info, g))
7814 if (SGI_COMPAT (abfd))
7815 mips_elf_hash_table (info)->compact_rel_size +=
7816 sizeof (Elf32_External_crinfo);
7820 case R_MIPS_GPREL16:
7821 case R_MIPS_LITERAL:
7822 case R_MIPS_GPREL32:
7823 if (SGI_COMPAT (abfd))
7824 mips_elf_hash_table (info)->compact_rel_size +=
7825 sizeof (Elf32_External_crinfo);
7828 /* This relocation describes the C++ object vtable hierarchy.
7829 Reconstruct it for later use during GC. */
7830 case R_MIPS_GNU_VTINHERIT:
7831 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
7835 /* This relocation describes which C++ vtable entries are actually
7836 used. Record for later use during GC. */
7837 case R_MIPS_GNU_VTENTRY:
7838 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_offset))
7846 /* If this reloc is not a 16 bit call, and it has a global
7847 symbol, then we will need the fn_stub if there is one.
7848 References from a stub section do not count. */
7850 && r_type != R_MIPS16_26
7851 && strncmp (bfd_get_section_name (abfd, sec), FN_STUB,
7852 sizeof FN_STUB - 1) != 0
7853 && strncmp (bfd_get_section_name (abfd, sec), CALL_STUB,
7854 sizeof CALL_STUB - 1) != 0
7855 && strncmp (bfd_get_section_name (abfd, sec), CALL_FP_STUB,
7856 sizeof CALL_FP_STUB - 1) != 0)
7858 struct mips_elf_link_hash_entry *mh;
7860 mh = (struct mips_elf_link_hash_entry *) h;
7861 mh->need_fn_stub = true;
7868 /* Return the section that should be marked against GC for a given
7872 _bfd_mips_elf_gc_mark_hook (abfd, info, rel, h, sym)
7874 struct bfd_link_info *info ATTRIBUTE_UNUSED;
7875 Elf_Internal_Rela *rel;
7876 struct elf_link_hash_entry *h;
7877 Elf_Internal_Sym *sym;
7879 /* ??? Do mips16 stub sections need to be handled special? */
7883 switch (ELF32_R_TYPE (rel->r_info))
7885 case R_MIPS_GNU_VTINHERIT:
7886 case R_MIPS_GNU_VTENTRY:
7890 switch (h->root.type)
7892 case bfd_link_hash_defined:
7893 case bfd_link_hash_defweak:
7894 return h->root.u.def.section;
7896 case bfd_link_hash_common:
7897 return h->root.u.c.p->section;
7906 if (!(elf_bad_symtab (abfd)
7907 && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
7908 && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
7909 && sym->st_shndx != SHN_COMMON))
7911 return bfd_section_from_elf_index (abfd, sym->st_shndx);
7918 /* Update the got entry reference counts for the section being removed. */
7921 _bfd_mips_elf_gc_sweep_hook (abfd, info, sec, relocs)
7922 bfd *abfd ATTRIBUTE_UNUSED;
7923 struct bfd_link_info *info ATTRIBUTE_UNUSED;
7924 asection *sec ATTRIBUTE_UNUSED;
7925 const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
7928 Elf_Internal_Shdr *symtab_hdr;
7929 struct elf_link_hash_entry **sym_hashes;
7930 bfd_signed_vma *local_got_refcounts;
7931 const Elf_Internal_Rela *rel, *relend;
7932 unsigned long r_symndx;
7933 struct elf_link_hash_entry *h;
7935 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
7936 sym_hashes = elf_sym_hashes (abfd);
7937 local_got_refcounts = elf_local_got_refcounts (abfd);
7939 relend = relocs + sec->reloc_count;
7940 for (rel = relocs; rel < relend; rel++)
7941 switch (ELF32_R_TYPE (rel->r_info))
7945 case R_MIPS_CALL_HI16:
7946 case R_MIPS_CALL_LO16:
7947 case R_MIPS_GOT_HI16:
7948 case R_MIPS_GOT_LO16:
7949 /* ??? It would seem that the existing MIPS code does no sort
7950 of reference counting or whatnot on its GOT and PLT entries,
7951 so it is not possible to garbage collect them at this time. */
7962 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
7963 hiding the old indirect symbol. Process additional relocation
7967 _bfd_mips_elf_copy_indirect_symbol (dir, ind)
7968 struct elf_link_hash_entry *dir, *ind;
7970 struct mips_elf_link_hash_entry *dirmips, *indmips;
7972 _bfd_elf_link_hash_copy_indirect (dir, ind);
7974 dirmips = (struct mips_elf_link_hash_entry *) dir;
7975 indmips = (struct mips_elf_link_hash_entry *) ind;
7976 dirmips->possibly_dynamic_relocs += indmips->possibly_dynamic_relocs;
7977 if (dirmips->min_dyn_reloc_index == 0
7978 || (indmips->min_dyn_reloc_index != 0
7979 && indmips->min_dyn_reloc_index < dirmips->min_dyn_reloc_index))
7980 dirmips->min_dyn_reloc_index = indmips->min_dyn_reloc_index;
7983 /* Adjust a symbol defined by a dynamic object and referenced by a
7984 regular object. The current definition is in some section of the
7985 dynamic object, but we're not including those sections. We have to
7986 change the definition to something the rest of the link can
7990 _bfd_mips_elf_adjust_dynamic_symbol (info, h)
7991 struct bfd_link_info *info;
7992 struct elf_link_hash_entry *h;
7995 struct mips_elf_link_hash_entry *hmips;
7998 dynobj = elf_hash_table (info)->dynobj;
8000 /* Make sure we know what is going on here. */
8001 BFD_ASSERT (dynobj != NULL
8002 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
8003 || h->weakdef != NULL
8004 || ((h->elf_link_hash_flags
8005 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
8006 && (h->elf_link_hash_flags
8007 & ELF_LINK_HASH_REF_REGULAR) != 0
8008 && (h->elf_link_hash_flags
8009 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
8011 /* If this symbol is defined in a dynamic object, we need to copy
8012 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
8014 hmips = (struct mips_elf_link_hash_entry *) h;
8015 if (! info->relocateable
8016 && hmips->possibly_dynamic_relocs != 0
8017 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
8018 mips_elf_allocate_dynamic_relocations (dynobj,
8019 hmips->possibly_dynamic_relocs);
8021 /* For a function, create a stub, if needed. */
8022 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
8024 if (! elf_hash_table (info)->dynamic_sections_created)
8027 /* If this symbol is not defined in a regular file, then set
8028 the symbol to the stub location. This is required to make
8029 function pointers compare as equal between the normal
8030 executable and the shared library. */
8031 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
8033 /* We need .stub section. */
8034 s = bfd_get_section_by_name (dynobj,
8035 MIPS_ELF_STUB_SECTION_NAME (dynobj));
8036 BFD_ASSERT (s != NULL);
8038 h->root.u.def.section = s;
8039 h->root.u.def.value = s->_raw_size;
8041 /* XXX Write this stub address somewhere. */
8042 h->plt.offset = s->_raw_size;
8044 /* Make room for this stub code. */
8045 s->_raw_size += MIPS_FUNCTION_STUB_SIZE;
8047 /* The last half word of the stub will be filled with the index
8048 of this symbol in .dynsym section. */
8052 else if ((h->type == STT_FUNC)
8053 && (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) == 0)
8055 /* This will set the entry for this symbol in the GOT to 0, and
8056 the dynamic linker will take care of this. */
8057 h->root.u.def.value = 0;
8061 /* If this is a weak symbol, and there is a real definition, the
8062 processor independent code will have arranged for us to see the
8063 real definition first, and we can just use the same value. */
8064 if (h->weakdef != NULL)
8066 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
8067 || h->weakdef->root.type == bfd_link_hash_defweak);
8068 h->root.u.def.section = h->weakdef->root.u.def.section;
8069 h->root.u.def.value = h->weakdef->root.u.def.value;
8073 /* This is a reference to a symbol defined by a dynamic object which
8074 is not a function. */
8079 /* This function is called after all the input files have been read,
8080 and the input sections have been assigned to output sections. We
8081 check for any mips16 stub sections that we can discard. */
8083 static boolean mips_elf_check_mips16_stubs
8084 PARAMS ((struct mips_elf_link_hash_entry *, PTR));
8087 _bfd_mips_elf_always_size_sections (output_bfd, info)
8089 struct bfd_link_info *info;
8093 /* The .reginfo section has a fixed size. */
8094 ri = bfd_get_section_by_name (output_bfd, ".reginfo");
8096 bfd_set_section_size (output_bfd, ri, sizeof (Elf32_External_RegInfo));
8098 if (info->relocateable
8099 || ! mips_elf_hash_table (info)->mips16_stubs_seen)
8102 mips_elf_link_hash_traverse (mips_elf_hash_table (info),
8103 mips_elf_check_mips16_stubs,
8109 /* Check the mips16 stubs for a particular symbol, and see if we can
8113 mips_elf_check_mips16_stubs (h, data)
8114 struct mips_elf_link_hash_entry *h;
8115 PTR data ATTRIBUTE_UNUSED;
8117 if (h->fn_stub != NULL
8118 && ! h->need_fn_stub)
8120 /* We don't need the fn_stub; the only references to this symbol
8121 are 16 bit calls. Clobber the size to 0 to prevent it from
8122 being included in the link. */
8123 h->fn_stub->_raw_size = 0;
8124 h->fn_stub->_cooked_size = 0;
8125 h->fn_stub->flags &= ~SEC_RELOC;
8126 h->fn_stub->reloc_count = 0;
8127 h->fn_stub->flags |= SEC_EXCLUDE;
8130 if (h->call_stub != NULL
8131 && h->root.other == STO_MIPS16)
8133 /* We don't need the call_stub; this is a 16 bit function, so
8134 calls from other 16 bit functions are OK. Clobber the size
8135 to 0 to prevent it from being included in the link. */
8136 h->call_stub->_raw_size = 0;
8137 h->call_stub->_cooked_size = 0;
8138 h->call_stub->flags &= ~SEC_RELOC;
8139 h->call_stub->reloc_count = 0;
8140 h->call_stub->flags |= SEC_EXCLUDE;
8143 if (h->call_fp_stub != NULL
8144 && h->root.other == STO_MIPS16)
8146 /* We don't need the call_stub; this is a 16 bit function, so
8147 calls from other 16 bit functions are OK. Clobber the size
8148 to 0 to prevent it from being included in the link. */
8149 h->call_fp_stub->_raw_size = 0;
8150 h->call_fp_stub->_cooked_size = 0;
8151 h->call_fp_stub->flags &= ~SEC_RELOC;
8152 h->call_fp_stub->reloc_count = 0;
8153 h->call_fp_stub->flags |= SEC_EXCLUDE;
8159 /* Set the sizes of the dynamic sections. */
8162 _bfd_mips_elf_size_dynamic_sections (output_bfd, info)
8164 struct bfd_link_info *info;
8169 struct mips_got_info *g = NULL;
8171 dynobj = elf_hash_table (info)->dynobj;
8172 BFD_ASSERT (dynobj != NULL);
8174 if (elf_hash_table (info)->dynamic_sections_created)
8176 /* Set the contents of the .interp section to the interpreter. */
8179 s = bfd_get_section_by_name (dynobj, ".interp");
8180 BFD_ASSERT (s != NULL);
8182 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd)) + 1;
8184 = (bfd_byte *) ELF_DYNAMIC_INTERPRETER (output_bfd);
8188 /* The check_relocs and adjust_dynamic_symbol entry points have
8189 determined the sizes of the various dynamic sections. Allocate
8192 for (s = dynobj->sections; s != NULL; s = s->next)
8197 /* It's OK to base decisions on the section name, because none
8198 of the dynobj section names depend upon the input files. */
8199 name = bfd_get_section_name (dynobj, s);
8201 if ((s->flags & SEC_LINKER_CREATED) == 0)
8206 if (strncmp (name, ".rel", 4) == 0)
8208 if (s->_raw_size == 0)
8210 /* We only strip the section if the output section name
8211 has the same name. Otherwise, there might be several
8212 input sections for this output section. FIXME: This
8213 code is probably not needed these days anyhow, since
8214 the linker now does not create empty output sections. */
8215 if (s->output_section != NULL
8217 bfd_get_section_name (s->output_section->owner,
8218 s->output_section)) == 0)
8223 const char *outname;
8226 /* If this relocation section applies to a read only
8227 section, then we probably need a DT_TEXTREL entry.
8228 If the relocation section is .rel.dyn, we always
8229 assert a DT_TEXTREL entry rather than testing whether
8230 there exists a relocation to a read only section or
8232 outname = bfd_get_section_name (output_bfd,
8234 target = bfd_get_section_by_name (output_bfd, outname + 4);
8236 && (target->flags & SEC_READONLY) != 0
8237 && (target->flags & SEC_ALLOC) != 0)
8239 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd)) == 0)
8242 /* We use the reloc_count field as a counter if we need
8243 to copy relocs into the output file. */
8245 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd)) != 0)
8249 else if (strncmp (name, ".got", 4) == 0)
8252 bfd_size_type loadable_size = 0;
8253 bfd_size_type local_gotno;
8256 BFD_ASSERT (elf_section_data (s) != NULL);
8257 g = (struct mips_got_info *) elf_section_data (s)->tdata;
8258 BFD_ASSERT (g != NULL);
8260 /* Calculate the total loadable size of the output. That
8261 will give us the maximum number of GOT_PAGE entries
8263 for (sub = info->input_bfds; sub; sub = sub->link_next)
8265 asection *subsection;
8267 for (subsection = sub->sections;
8269 subsection = subsection->next)
8271 if ((subsection->flags & SEC_ALLOC) == 0)
8273 loadable_size += (subsection->_raw_size + 0xf) & ~0xf;
8276 loadable_size += MIPS_FUNCTION_STUB_SIZE;
8278 /* Assume there are two loadable segments consisting of
8279 contiguous sections. Is 5 enough? */
8280 local_gotno = (loadable_size >> 16) + 5;
8281 if (IRIX_COMPAT (output_bfd) == ict_irix6)
8282 /* It's possible we will need GOT_PAGE entries as well as
8283 GOT16 entries. Often, these will be able to share GOT
8284 entries, but not always. */
8287 g->local_gotno += local_gotno;
8288 s->_raw_size += local_gotno * MIPS_ELF_GOT_SIZE (dynobj);
8290 /* There has to be a global GOT entry for every symbol with
8291 a dynamic symbol table index of DT_MIPS_GOTSYM or
8292 higher. Therefore, it make sense to put those symbols
8293 that need GOT entries at the end of the symbol table. We
8295 if (!mips_elf_sort_hash_table (info, 1))
8298 if (g->global_gotsym != NULL)
8299 i = elf_hash_table (info)->dynsymcount - g->global_gotsym->dynindx;
8301 /* If there are no global symbols, or none requiring
8302 relocations, then GLOBAL_GOTSYM will be NULL. */
8304 g->global_gotno = i;
8305 s->_raw_size += i * MIPS_ELF_GOT_SIZE (dynobj);
8307 else if (strcmp (name, MIPS_ELF_STUB_SECTION_NAME (output_bfd)) == 0)
8309 /* Irix rld assumes that the function stub isn't at the end
8310 of .text section. So put a dummy. XXX */
8311 s->_raw_size += MIPS_FUNCTION_STUB_SIZE;
8313 else if (! info->shared
8314 && ! mips_elf_hash_table (info)->use_rld_obj_head
8315 && strncmp (name, ".rld_map", 8) == 0)
8317 /* We add a room for __rld_map. It will be filled in by the
8318 rtld to contain a pointer to the _r_debug structure. */
8321 else if (SGI_COMPAT (output_bfd)
8322 && strncmp (name, ".compact_rel", 12) == 0)
8323 s->_raw_size += mips_elf_hash_table (info)->compact_rel_size;
8324 else if (strcmp (name, MIPS_ELF_MSYM_SECTION_NAME (output_bfd))
8326 s->_raw_size = (sizeof (Elf32_External_Msym)
8327 * (elf_hash_table (info)->dynsymcount
8328 + bfd_count_sections (output_bfd)));
8329 else if (strncmp (name, ".init", 5) != 0)
8331 /* It's not one of our sections, so don't allocate space. */
8337 _bfd_strip_section_from_output (info, s);
8341 /* Allocate memory for the section contents. */
8342 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
8343 if (s->contents == NULL && s->_raw_size != 0)
8345 bfd_set_error (bfd_error_no_memory);
8350 if (elf_hash_table (info)->dynamic_sections_created)
8352 /* Add some entries to the .dynamic section. We fill in the
8353 values later, in elf_mips_finish_dynamic_sections, but we
8354 must add the entries now so that we get the correct size for
8355 the .dynamic section. The DT_DEBUG entry is filled in by the
8356 dynamic linker and used by the debugger. */
8359 /* SGI object has the equivalence of DT_DEBUG in the
8360 DT_MIPS_RLD_MAP entry. */
8361 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_RLD_MAP, 0))
8363 if (!SGI_COMPAT (output_bfd))
8365 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_DEBUG, 0))
8371 /* Shared libraries on traditional mips have DT_DEBUG. */
8372 if (!SGI_COMPAT (output_bfd))
8374 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_DEBUG, 0))
8378 if (reltext && SGI_COMPAT (output_bfd))
8380 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_TEXTREL, 0))
8382 info->flags |= DF_TEXTREL;
8385 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_PLTGOT, 0))
8388 if (bfd_get_section_by_name (dynobj,
8389 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj)))
8391 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_REL, 0))
8394 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_RELSZ, 0))
8397 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_RELENT, 0))
8401 if (SGI_COMPAT (output_bfd))
8403 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_CONFLICTNO, 0))
8407 if (SGI_COMPAT (output_bfd))
8409 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_LIBLISTNO, 0))
8413 if (bfd_get_section_by_name (dynobj, ".conflict") != NULL)
8415 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_CONFLICT, 0))
8418 s = bfd_get_section_by_name (dynobj, ".liblist");
8419 BFD_ASSERT (s != NULL);
8421 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_LIBLIST, 0))
8425 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_RLD_VERSION, 0))
8428 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_FLAGS, 0))
8432 /* Time stamps in executable files are a bad idea. */
8433 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_TIME_STAMP, 0))
8438 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_ICHECKSUM, 0))
8443 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_IVERSION, 0))
8447 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_BASE_ADDRESS, 0))
8450 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_LOCAL_GOTNO, 0))
8453 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_SYMTABNO, 0))
8456 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_UNREFEXTNO, 0))
8459 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_GOTSYM, 0))
8462 if (IRIX_COMPAT (dynobj) == ict_irix5
8463 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_HIPAGENO, 0))
8466 if (IRIX_COMPAT (dynobj) == ict_irix6
8467 && (bfd_get_section_by_name
8468 (dynobj, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj)))
8469 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_OPTIONS, 0))
8472 if (bfd_get_section_by_name (dynobj,
8473 MIPS_ELF_MSYM_SECTION_NAME (dynobj))
8474 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_MSYM, 0))
8481 /* If NAME is one of the special IRIX6 symbols defined by the linker,
8482 adjust it appropriately now. */
8485 mips_elf_irix6_finish_dynamic_symbol (abfd, name, sym)
8486 bfd *abfd ATTRIBUTE_UNUSED;
8488 Elf_Internal_Sym *sym;
8490 /* The linker script takes care of providing names and values for
8491 these, but we must place them into the right sections. */
8492 static const char* const text_section_symbols[] = {
8495 "__dso_displacement",
8497 "__program_header_table",
8501 static const char* const data_section_symbols[] = {
8509 const char* const *p;
8512 for (i = 0; i < 2; ++i)
8513 for (p = (i == 0) ? text_section_symbols : data_section_symbols;
8516 if (strcmp (*p, name) == 0)
8518 /* All of these symbols are given type STT_SECTION by the
8520 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
8522 /* The IRIX linker puts these symbols in special sections. */
8524 sym->st_shndx = SHN_MIPS_TEXT;
8526 sym->st_shndx = SHN_MIPS_DATA;
8532 /* Finish up dynamic symbol handling. We set the contents of various
8533 dynamic sections here. */
8536 _bfd_mips_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
8538 struct bfd_link_info *info;
8539 struct elf_link_hash_entry *h;
8540 Elf_Internal_Sym *sym;
8546 struct mips_got_info *g;
8548 struct mips_elf_link_hash_entry *mh;
8550 dynobj = elf_hash_table (info)->dynobj;
8551 gval = sym->st_value;
8552 mh = (struct mips_elf_link_hash_entry *) h;
8554 if (h->plt.offset != (bfd_vma) -1)
8558 bfd_byte stub[MIPS_FUNCTION_STUB_SIZE];
8560 /* This symbol has a stub. Set it up. */
8562 BFD_ASSERT (h->dynindx != -1);
8564 s = bfd_get_section_by_name (dynobj,
8565 MIPS_ELF_STUB_SECTION_NAME (dynobj));
8566 BFD_ASSERT (s != NULL);
8568 /* Fill the stub. */
8570 bfd_put_32 (output_bfd, STUB_LW (output_bfd), p);
8572 bfd_put_32 (output_bfd, STUB_MOVE (output_bfd), p);
8575 /* FIXME: Can h->dynindex be more than 64K? */
8576 if (h->dynindx & 0xffff0000)
8579 bfd_put_32 (output_bfd, STUB_JALR, p);
8581 bfd_put_32 (output_bfd, STUB_LI16 (output_bfd) + h->dynindx, p);
8583 BFD_ASSERT (h->plt.offset <= s->_raw_size);
8584 memcpy (s->contents + h->plt.offset, stub, MIPS_FUNCTION_STUB_SIZE);
8586 /* Mark the symbol as undefined. plt.offset != -1 occurs
8587 only for the referenced symbol. */
8588 sym->st_shndx = SHN_UNDEF;
8590 /* The run-time linker uses the st_value field of the symbol
8591 to reset the global offset table entry for this external
8592 to its stub address when unlinking a shared object. */
8593 gval = s->output_section->vma + s->output_offset + h->plt.offset;
8594 sym->st_value = gval;
8597 BFD_ASSERT (h->dynindx != -1
8598 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0);
8600 sgot = mips_elf_got_section (dynobj);
8601 BFD_ASSERT (sgot != NULL);
8602 BFD_ASSERT (elf_section_data (sgot) != NULL);
8603 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
8604 BFD_ASSERT (g != NULL);
8606 /* Run through the global symbol table, creating GOT entries for all
8607 the symbols that need them. */
8608 if (g->global_gotsym != NULL
8609 && h->dynindx >= g->global_gotsym->dynindx)
8615 value = sym->st_value;
8618 /* For an entity defined in a shared object, this will be
8619 NULL. (For functions in shared objects for
8620 which we have created stubs, ST_VALUE will be non-NULL.
8621 That's because such the functions are now no longer defined
8622 in a shared object.) */
8624 if (info->shared && h->root.type == bfd_link_hash_undefined)
8627 value = h->root.u.def.value;
8629 offset = mips_elf_global_got_index (dynobj, h);
8630 MIPS_ELF_PUT_WORD (output_bfd, value, sgot->contents + offset);
8633 /* Create a .msym entry, if appropriate. */
8634 smsym = bfd_get_section_by_name (dynobj,
8635 MIPS_ELF_MSYM_SECTION_NAME (dynobj));
8638 Elf32_Internal_Msym msym;
8640 msym.ms_hash_value = bfd_elf_hash (h->root.root.string);
8641 /* It is undocumented what the `1' indicates, but IRIX6 uses
8643 msym.ms_info = ELF32_MS_INFO (mh->min_dyn_reloc_index, 1);
8644 bfd_mips_elf_swap_msym_out
8646 ((Elf32_External_Msym *) smsym->contents) + h->dynindx);
8649 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
8650 name = h->root.root.string;
8651 if (strcmp (name, "_DYNAMIC") == 0
8652 || strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
8653 sym->st_shndx = SHN_ABS;
8654 else if (strcmp (name, "_DYNAMIC_LINK") == 0
8655 || strcmp (name, "_DYNAMIC_LINKING") == 0)
8657 sym->st_shndx = SHN_ABS;
8658 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
8661 else if (strcmp (name, "_gp_disp") == 0)
8663 sym->st_shndx = SHN_ABS;
8664 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
8665 sym->st_value = elf_gp (output_bfd);
8667 else if (SGI_COMPAT (output_bfd))
8669 if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0
8670 || strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0)
8672 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
8673 sym->st_other = STO_PROTECTED;
8675 sym->st_shndx = SHN_MIPS_DATA;
8677 else if (strcmp (name, mips_elf_dynsym_rtproc_names[2]) == 0)
8679 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
8680 sym->st_other = STO_PROTECTED;
8681 sym->st_value = mips_elf_hash_table (info)->procedure_count;
8682 sym->st_shndx = SHN_ABS;
8684 else if (sym->st_shndx != SHN_UNDEF && sym->st_shndx != SHN_ABS)
8686 if (h->type == STT_FUNC)
8687 sym->st_shndx = SHN_MIPS_TEXT;
8688 else if (h->type == STT_OBJECT)
8689 sym->st_shndx = SHN_MIPS_DATA;
8693 /* Handle the IRIX6-specific symbols. */
8694 if (IRIX_COMPAT (output_bfd) == ict_irix6)
8695 mips_elf_irix6_finish_dynamic_symbol (output_bfd, name, sym);
8699 if (! mips_elf_hash_table (info)->use_rld_obj_head
8700 && (strcmp (name, "__rld_map") == 0
8701 || strcmp (name, "__RLD_MAP") == 0))
8703 asection *s = bfd_get_section_by_name (dynobj, ".rld_map");
8704 BFD_ASSERT (s != NULL);
8705 sym->st_value = s->output_section->vma + s->output_offset;
8706 bfd_put_32 (output_bfd, (bfd_vma) 0, s->contents);
8707 if (mips_elf_hash_table (info)->rld_value == 0)
8708 mips_elf_hash_table (info)->rld_value = sym->st_value;
8710 else if (mips_elf_hash_table (info)->use_rld_obj_head
8711 && strcmp (name, "__rld_obj_head") == 0)
8713 /* IRIX6 does not use a .rld_map section. */
8714 if (IRIX_COMPAT (output_bfd) == ict_irix5
8715 || IRIX_COMPAT (output_bfd) == ict_none)
8716 BFD_ASSERT (bfd_get_section_by_name (dynobj, ".rld_map")
8718 mips_elf_hash_table (info)->rld_value = sym->st_value;
8722 /* If this is a mips16 symbol, force the value to be even. */
8723 if (sym->st_other == STO_MIPS16
8724 && (sym->st_value & 1) != 0)
8730 /* Finish up the dynamic sections. */
8733 _bfd_mips_elf_finish_dynamic_sections (output_bfd, info)
8735 struct bfd_link_info *info;
8740 struct mips_got_info *g;
8742 dynobj = elf_hash_table (info)->dynobj;
8744 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
8746 sgot = mips_elf_got_section (dynobj);
8751 BFD_ASSERT (elf_section_data (sgot) != NULL);
8752 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
8753 BFD_ASSERT (g != NULL);
8756 if (elf_hash_table (info)->dynamic_sections_created)
8760 BFD_ASSERT (sdyn != NULL);
8761 BFD_ASSERT (g != NULL);
8763 for (b = sdyn->contents;
8764 b < sdyn->contents + sdyn->_raw_size;
8765 b += MIPS_ELF_DYN_SIZE (dynobj))
8767 Elf_Internal_Dyn dyn;
8773 /* Read in the current dynamic entry. */
8774 (*get_elf_backend_data (dynobj)->s->swap_dyn_in) (dynobj, b, &dyn);
8776 /* Assume that we're going to modify it and write it out. */
8782 s = (bfd_get_section_by_name
8784 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj)));
8785 BFD_ASSERT (s != NULL);
8786 dyn.d_un.d_val = MIPS_ELF_REL_SIZE (dynobj);
8790 /* Rewrite DT_STRSZ. */
8792 _bfd_stringtab_size (elf_hash_table (info)->dynstr);
8798 case DT_MIPS_CONFLICT:
8801 case DT_MIPS_LIBLIST:
8804 s = bfd_get_section_by_name (output_bfd, name);
8805 BFD_ASSERT (s != NULL);
8806 dyn.d_un.d_ptr = s->vma;
8809 case DT_MIPS_RLD_VERSION:
8810 dyn.d_un.d_val = 1; /* XXX */
8814 dyn.d_un.d_val = RHF_NOTPOT; /* XXX */
8817 case DT_MIPS_CONFLICTNO:
8819 elemsize = sizeof (Elf32_Conflict);
8822 case DT_MIPS_LIBLISTNO:
8824 elemsize = sizeof (Elf32_Lib);
8826 s = bfd_get_section_by_name (output_bfd, name);
8829 if (s->_cooked_size != 0)
8830 dyn.d_un.d_val = s->_cooked_size / elemsize;
8832 dyn.d_un.d_val = s->_raw_size / elemsize;
8838 case DT_MIPS_TIME_STAMP:
8839 time ((time_t *) &dyn.d_un.d_val);
8842 case DT_MIPS_ICHECKSUM:
8847 case DT_MIPS_IVERSION:
8852 case DT_MIPS_BASE_ADDRESS:
8853 s = output_bfd->sections;
8854 BFD_ASSERT (s != NULL);
8855 dyn.d_un.d_ptr = s->vma & ~(0xffff);
8858 case DT_MIPS_LOCAL_GOTNO:
8859 dyn.d_un.d_val = g->local_gotno;
8862 case DT_MIPS_UNREFEXTNO:
8863 /* The index into the dynamic symbol table which is the
8864 entry of the first external symbol that is not
8865 referenced within the same object. */
8866 dyn.d_un.d_val = bfd_count_sections (output_bfd) + 1;
8869 case DT_MIPS_GOTSYM:
8870 if (g->global_gotsym)
8872 dyn.d_un.d_val = g->global_gotsym->dynindx;
8875 /* In case if we don't have global got symbols we default
8876 to setting DT_MIPS_GOTSYM to the same value as
8877 DT_MIPS_SYMTABNO, so we just fall through. */
8879 case DT_MIPS_SYMTABNO:
8881 elemsize = MIPS_ELF_SYM_SIZE (output_bfd);
8882 s = bfd_get_section_by_name (output_bfd, name);
8883 BFD_ASSERT (s != NULL);
8885 if (s->_cooked_size != 0)
8886 dyn.d_un.d_val = s->_cooked_size / elemsize;
8888 dyn.d_un.d_val = s->_raw_size / elemsize;
8891 case DT_MIPS_HIPAGENO:
8892 dyn.d_un.d_val = g->local_gotno - MIPS_RESERVED_GOTNO;
8895 case DT_MIPS_RLD_MAP:
8896 dyn.d_un.d_ptr = mips_elf_hash_table (info)->rld_value;
8899 case DT_MIPS_OPTIONS:
8900 s = (bfd_get_section_by_name
8901 (output_bfd, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd)));
8902 dyn.d_un.d_ptr = s->vma;
8906 s = (bfd_get_section_by_name
8907 (output_bfd, MIPS_ELF_MSYM_SECTION_NAME (output_bfd)));
8908 dyn.d_un.d_ptr = s->vma;
8917 (*get_elf_backend_data (dynobj)->s->swap_dyn_out)
8922 /* The first entry of the global offset table will be filled at
8923 runtime. The second entry will be used by some runtime loaders.
8924 This isn't the case of Irix rld. */
8925 if (sgot != NULL && sgot->_raw_size > 0)
8927 MIPS_ELF_PUT_WORD (output_bfd, (bfd_vma) 0, sgot->contents);
8928 MIPS_ELF_PUT_WORD (output_bfd, (bfd_vma) 0x80000000,
8929 sgot->contents + MIPS_ELF_GOT_SIZE (output_bfd));
8933 elf_section_data (sgot->output_section)->this_hdr.sh_entsize
8934 = MIPS_ELF_GOT_SIZE (output_bfd);
8939 Elf32_compact_rel cpt;
8941 /* ??? The section symbols for the output sections were set up in
8942 _bfd_elf_final_link. SGI sets the STT_NOTYPE attribute for these
8943 symbols. Should we do so? */
8945 smsym = bfd_get_section_by_name (dynobj,
8946 MIPS_ELF_MSYM_SECTION_NAME (dynobj));
8949 Elf32_Internal_Msym msym;
8951 msym.ms_hash_value = 0;
8952 msym.ms_info = ELF32_MS_INFO (0, 1);
8954 for (s = output_bfd->sections; s != NULL; s = s->next)
8956 long dynindx = elf_section_data (s)->dynindx;
8958 bfd_mips_elf_swap_msym_out
8960 (((Elf32_External_Msym *) smsym->contents)
8965 if (SGI_COMPAT (output_bfd))
8967 /* Write .compact_rel section out. */
8968 s = bfd_get_section_by_name (dynobj, ".compact_rel");
8972 cpt.num = s->reloc_count;
8974 cpt.offset = (s->output_section->filepos
8975 + sizeof (Elf32_External_compact_rel));
8978 bfd_elf32_swap_compact_rel_out (output_bfd, &cpt,
8979 ((Elf32_External_compact_rel *)
8982 /* Clean up a dummy stub function entry in .text. */
8983 s = bfd_get_section_by_name (dynobj,
8984 MIPS_ELF_STUB_SECTION_NAME (dynobj));
8987 file_ptr dummy_offset;
8989 BFD_ASSERT (s->_raw_size >= MIPS_FUNCTION_STUB_SIZE);
8990 dummy_offset = s->_raw_size - MIPS_FUNCTION_STUB_SIZE;
8991 memset (s->contents + dummy_offset, 0,
8992 MIPS_FUNCTION_STUB_SIZE);
8997 /* We need to sort the entries of the dynamic relocation section. */
8999 if (!ABI_64_P (output_bfd))
9003 reldyn = bfd_get_section_by_name (dynobj,
9004 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj));
9005 if (reldyn != NULL && reldyn->reloc_count > 2)
9007 reldyn_sorting_bfd = output_bfd;
9008 qsort ((Elf32_External_Rel *) reldyn->contents + 1,
9009 (size_t) reldyn->reloc_count - 1,
9010 sizeof (Elf32_External_Rel), sort_dynamic_relocs);
9014 /* Clean up a first relocation in .rel.dyn. */
9015 s = bfd_get_section_by_name (dynobj,
9016 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj));
9017 if (s != NULL && s->_raw_size > 0)
9018 memset (s->contents, 0, MIPS_ELF_REL_SIZE (dynobj));
9024 /* This is almost identical to bfd_generic_get_... except that some
9025 MIPS relocations need to be handled specially. Sigh. */
9028 elf32_mips_get_relocated_section_contents (abfd, link_info, link_order, data,
9029 relocateable, symbols)
9031 struct bfd_link_info *link_info;
9032 struct bfd_link_order *link_order;
9034 boolean relocateable;
9037 /* Get enough memory to hold the stuff */
9038 bfd *input_bfd = link_order->u.indirect.section->owner;
9039 asection *input_section = link_order->u.indirect.section;
9041 long reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section);
9042 arelent **reloc_vector = NULL;
9048 reloc_vector = (arelent **) bfd_malloc (reloc_size);
9049 if (reloc_vector == NULL && reloc_size != 0)
9052 /* read in the section */
9053 if (!bfd_get_section_contents (input_bfd,
9057 input_section->_raw_size))
9060 /* We're not relaxing the section, so just copy the size info */
9061 input_section->_cooked_size = input_section->_raw_size;
9062 input_section->reloc_done = true;
9064 reloc_count = bfd_canonicalize_reloc (input_bfd,
9068 if (reloc_count < 0)
9071 if (reloc_count > 0)
9076 bfd_vma gp = 0x12345678; /* initialize just to shut gcc up */
9079 struct bfd_hash_entry *h;
9080 struct bfd_link_hash_entry *lh;
9081 /* Skip all this stuff if we aren't mixing formats. */
9082 if (abfd && input_bfd
9083 && abfd->xvec == input_bfd->xvec)
9087 h = bfd_hash_lookup (&link_info->hash->table, "_gp", false, false);
9088 lh = (struct bfd_link_hash_entry *) h;
9095 case bfd_link_hash_undefined:
9096 case bfd_link_hash_undefweak:
9097 case bfd_link_hash_common:
9100 case bfd_link_hash_defined:
9101 case bfd_link_hash_defweak:
9103 gp = lh->u.def.value;
9105 case bfd_link_hash_indirect:
9106 case bfd_link_hash_warning:
9108 /* @@FIXME ignoring warning for now */
9110 case bfd_link_hash_new:
9119 for (parent = reloc_vector; *parent != (arelent *) NULL;
9122 char *error_message = (char *) NULL;
9123 bfd_reloc_status_type r;
9125 /* Specific to MIPS: Deal with relocation types that require
9126 knowing the gp of the output bfd. */
9127 asymbol *sym = *(*parent)->sym_ptr_ptr;
9128 if (bfd_is_abs_section (sym->section) && abfd)
9130 /* The special_function wouldn't get called anyways. */
9134 /* The gp isn't there; let the special function code
9135 fall over on its own. */
9137 else if ((*parent)->howto->special_function
9138 == _bfd_mips_elf_gprel16_reloc)
9140 /* bypass special_function call */
9141 r = gprel16_with_gp (input_bfd, sym, *parent, input_section,
9142 relocateable, (PTR) data, gp);
9143 goto skip_bfd_perform_relocation;
9145 /* end mips specific stuff */
9147 r = bfd_perform_relocation (input_bfd,
9151 relocateable ? abfd : (bfd *) NULL,
9153 skip_bfd_perform_relocation:
9157 asection *os = input_section->output_section;
9159 /* A partial link, so keep the relocs */
9160 os->orelocation[os->reloc_count] = *parent;
9164 if (r != bfd_reloc_ok)
9168 case bfd_reloc_undefined:
9169 if (!((*link_info->callbacks->undefined_symbol)
9170 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
9171 input_bfd, input_section, (*parent)->address,
9175 case bfd_reloc_dangerous:
9176 BFD_ASSERT (error_message != (char *) NULL);
9177 if (!((*link_info->callbacks->reloc_dangerous)
9178 (link_info, error_message, input_bfd, input_section,
9179 (*parent)->address)))
9182 case bfd_reloc_overflow:
9183 if (!((*link_info->callbacks->reloc_overflow)
9184 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
9185 (*parent)->howto->name, (*parent)->addend,
9186 input_bfd, input_section, (*parent)->address)))
9189 case bfd_reloc_outofrange:
9198 if (reloc_vector != NULL)
9199 free (reloc_vector);
9203 if (reloc_vector != NULL)
9204 free (reloc_vector);
9208 #define bfd_elf32_bfd_get_relocated_section_contents \
9209 elf32_mips_get_relocated_section_contents
9211 /* ECOFF swapping routines. These are used when dealing with the
9212 .mdebug section, which is in the ECOFF debugging format. */
9213 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = {
9214 /* Symbol table magic number. */
9216 /* Alignment of debugging information. E.g., 4. */
9218 /* Sizes of external symbolic information. */
9219 sizeof (struct hdr_ext),
9220 sizeof (struct dnr_ext),
9221 sizeof (struct pdr_ext),
9222 sizeof (struct sym_ext),
9223 sizeof (struct opt_ext),
9224 sizeof (struct fdr_ext),
9225 sizeof (struct rfd_ext),
9226 sizeof (struct ext_ext),
9227 /* Functions to swap in external symbolic data. */
9236 _bfd_ecoff_swap_tir_in,
9237 _bfd_ecoff_swap_rndx_in,
9238 /* Functions to swap out external symbolic data. */
9247 _bfd_ecoff_swap_tir_out,
9248 _bfd_ecoff_swap_rndx_out,
9249 /* Function to read in symbolic data. */
9250 _bfd_mips_elf_read_ecoff_info
9253 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
9254 #define TARGET_LITTLE_NAME "elf32-littlemips"
9255 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
9256 #define TARGET_BIG_NAME "elf32-bigmips"
9257 #define ELF_ARCH bfd_arch_mips
9258 #define ELF_MACHINE_CODE EM_MIPS
9260 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
9261 a value of 0x1000, and we are compatible. */
9262 #define ELF_MAXPAGESIZE 0x1000
9264 #define elf_backend_collect true
9265 #define elf_backend_type_change_ok true
9266 #define elf_backend_can_gc_sections true
9267 #define elf_backend_sign_extend_vma true
9268 #define elf_info_to_howto mips_info_to_howto_rela
9269 #define elf_info_to_howto_rel mips_info_to_howto_rel
9270 #define elf_backend_sym_is_global mips_elf_sym_is_global
9271 #define elf_backend_object_p _bfd_mips_elf_object_p
9272 #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
9273 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
9274 #define elf_backend_section_from_bfd_section \
9275 _bfd_mips_elf_section_from_bfd_section
9276 #define elf_backend_section_processing _bfd_mips_elf_section_processing
9277 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
9278 #define elf_backend_additional_program_headers \
9279 _bfd_mips_elf_additional_program_headers
9280 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
9281 #define elf_backend_final_write_processing \
9282 _bfd_mips_elf_final_write_processing
9283 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
9284 #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
9285 #define elf_backend_create_dynamic_sections \
9286 _bfd_mips_elf_create_dynamic_sections
9287 #define elf_backend_check_relocs _bfd_mips_elf_check_relocs
9288 #define elf_backend_adjust_dynamic_symbol \
9289 _bfd_mips_elf_adjust_dynamic_symbol
9290 #define elf_backend_always_size_sections \
9291 _bfd_mips_elf_always_size_sections
9292 #define elf_backend_size_dynamic_sections \
9293 _bfd_mips_elf_size_dynamic_sections
9294 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section
9295 #define elf_backend_link_output_symbol_hook \
9296 _bfd_mips_elf_link_output_symbol_hook
9297 #define elf_backend_finish_dynamic_symbol \
9298 _bfd_mips_elf_finish_dynamic_symbol
9299 #define elf_backend_finish_dynamic_sections \
9300 _bfd_mips_elf_finish_dynamic_sections
9301 #define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
9302 #define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
9304 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
9305 #define elf_backend_plt_header_size 0
9307 #define elf_backend_copy_indirect_symbol \
9308 _bfd_mips_elf_copy_indirect_symbol
9310 #define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
9312 #define bfd_elf32_bfd_is_local_label_name \
9313 mips_elf_is_local_label_name
9314 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
9315 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
9316 #define bfd_elf32_bfd_link_hash_table_create \
9317 _bfd_mips_elf_link_hash_table_create
9318 #define bfd_elf32_bfd_final_link _bfd_mips_elf_final_link
9319 #define bfd_elf32_bfd_copy_private_bfd_data \
9320 _bfd_mips_elf_copy_private_bfd_data
9321 #define bfd_elf32_bfd_merge_private_bfd_data \
9322 _bfd_mips_elf_merge_private_bfd_data
9323 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
9324 #define bfd_elf32_bfd_print_private_bfd_data \
9325 _bfd_mips_elf_print_private_bfd_data
9326 #include "elf32-target.h"
9328 /* Support for traditional mips targets */
9330 #define INCLUDED_TARGET_FILE /* More a type of flag */
9332 #undef TARGET_LITTLE_SYM
9333 #undef TARGET_LITTLE_NAME
9334 #undef TARGET_BIG_SYM
9335 #undef TARGET_BIG_NAME
9337 #define TARGET_LITTLE_SYM bfd_elf32_tradlittlemips_vec
9338 #define TARGET_LITTLE_NAME "elf32-tradlittlemips"
9339 #define TARGET_BIG_SYM bfd_elf32_tradbigmips_vec
9340 #define TARGET_BIG_NAME "elf32-tradbigmips"
9342 /* Include the target file again for this target */
9343 #include "elf32-target.h"