1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
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. */
54 /* The global symbol in the GOT with the lowest index in the dynamic
56 struct elf_link_hash_entry *global_gotsym;
57 /* The number of global .got entries. */
58 unsigned int global_gotno;
59 /* The number of local .got entries. */
60 unsigned int local_gotno;
61 /* The number of local .got entries we have used. */
62 unsigned int assigned_gotno;
65 /* The MIPS ELF linker needs additional information for each symbol in
66 the global hash table. */
68 struct mips_elf_link_hash_entry
70 struct elf_link_hash_entry root;
72 /* External symbol information. */
75 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
77 unsigned int possibly_dynamic_relocs;
79 /* If the R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 reloc is against
80 a readonly section. */
81 boolean readonly_reloc;
83 /* The index of the first dynamic relocation (in the .rel.dyn
84 section) against this symbol. */
85 unsigned int min_dyn_reloc_index;
87 /* We must not create a stub for a symbol that has relocations
88 related to taking the function's address, i.e. any but
89 R_MIPS_CALL*16 ones -- see "MIPS ABI Supplement, 3rd Edition",
93 /* If there is a stub that 32 bit functions should use to call this
94 16 bit function, this points to the section containing the stub. */
97 /* Whether we need the fn_stub; this is set if this symbol appears
98 in any relocs other than a 16 bit call. */
101 /* If there is a stub that 16 bit functions should use to call this
102 32 bit function, this points to the section containing the stub. */
105 /* This is like the call_stub field, but it is used if the function
106 being called returns a floating point value. */
107 asection *call_fp_stub;
110 static bfd_reloc_status_type mips32_64bit_reloc
111 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
112 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
113 PARAMS ((bfd *, bfd_reloc_code_real_type));
114 static reloc_howto_type *mips_rtype_to_howto
115 PARAMS ((unsigned int));
116 static void mips_info_to_howto_rel
117 PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
118 static void mips_info_to_howto_rela
119 PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
120 static void bfd_mips_elf32_swap_gptab_in
121 PARAMS ((bfd *, const Elf32_External_gptab *, Elf32_gptab *));
122 static void bfd_mips_elf32_swap_gptab_out
123 PARAMS ((bfd *, const Elf32_gptab *, Elf32_External_gptab *));
125 static void bfd_mips_elf_swap_msym_in
126 PARAMS ((bfd *, const Elf32_External_Msym *, Elf32_Internal_Msym *));
128 static void bfd_mips_elf_swap_msym_out
129 PARAMS ((bfd *, const Elf32_Internal_Msym *, Elf32_External_Msym *));
130 static boolean mips_elf_sym_is_global PARAMS ((bfd *, asymbol *));
131 static boolean mips_elf_create_procedure_table
132 PARAMS ((PTR, bfd *, struct bfd_link_info *, asection *,
133 struct ecoff_debug_info *));
134 static INLINE int elf_mips_isa PARAMS ((flagword));
135 static INLINE unsigned long elf_mips_mach PARAMS ((flagword));
136 static INLINE char* elf_mips_abi_name PARAMS ((bfd *));
137 static boolean mips_elf_is_local_label_name
138 PARAMS ((bfd *, const char *));
139 static struct bfd_hash_entry *mips_elf_link_hash_newfunc
140 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
141 static int gptab_compare PARAMS ((const void *, const void *));
142 static bfd_reloc_status_type mips16_jump_reloc
143 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
144 static bfd_reloc_status_type mips16_gprel_reloc
145 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
146 static boolean mips_elf_create_compact_rel_section
147 PARAMS ((bfd *, struct bfd_link_info *));
148 static boolean mips_elf_create_got_section
149 PARAMS ((bfd *, struct bfd_link_info *));
150 static bfd_reloc_status_type mips_elf_final_gp
151 PARAMS ((bfd *, asymbol *, boolean, char **, bfd_vma *));
152 static bfd_byte *elf32_mips_get_relocated_section_contents
153 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
154 bfd_byte *, boolean, asymbol **));
155 static asection *mips_elf_create_msym_section
157 static void mips_elf_irix6_finish_dynamic_symbol
158 PARAMS ((bfd *, const char *, Elf_Internal_Sym *));
159 static bfd_vma mips_elf_sign_extend PARAMS ((bfd_vma, int));
160 static boolean mips_elf_overflow_p PARAMS ((bfd_vma, int));
161 static bfd_vma mips_elf_high PARAMS ((bfd_vma));
162 static bfd_vma mips_elf_higher PARAMS ((bfd_vma));
163 static bfd_vma mips_elf_highest PARAMS ((bfd_vma));
164 static bfd_vma mips_elf_global_got_index
165 PARAMS ((bfd *, struct elf_link_hash_entry *));
166 static bfd_vma mips_elf_local_got_index
167 PARAMS ((bfd *, struct bfd_link_info *, bfd_vma));
168 static bfd_vma mips_elf_got_offset_from_index
169 PARAMS ((bfd *, bfd *, bfd_vma));
170 static boolean mips_elf_record_global_got_symbol
171 PARAMS ((struct elf_link_hash_entry *, struct bfd_link_info *,
172 struct mips_got_info *));
173 static bfd_vma mips_elf_got_page
174 PARAMS ((bfd *, struct bfd_link_info *, bfd_vma, bfd_vma *));
175 static const Elf_Internal_Rela *mips_elf_next_relocation
176 PARAMS ((unsigned int, const Elf_Internal_Rela *,
177 const Elf_Internal_Rela *));
178 static bfd_reloc_status_type mips_elf_calculate_relocation
179 PARAMS ((bfd *, bfd *, asection *, struct bfd_link_info *,
180 const Elf_Internal_Rela *, bfd_vma, reloc_howto_type *,
181 Elf_Internal_Sym *, asection **, bfd_vma *, const char **,
183 static bfd_vma mips_elf_obtain_contents
184 PARAMS ((reloc_howto_type *, const Elf_Internal_Rela *, bfd *, bfd_byte *));
185 static boolean mips_elf_perform_relocation
186 PARAMS ((struct bfd_link_info *, reloc_howto_type *,
187 const Elf_Internal_Rela *, bfd_vma,
188 bfd *, asection *, bfd_byte *, boolean));
189 static boolean mips_elf_assign_gp PARAMS ((bfd *, bfd_vma *));
190 static boolean mips_elf_sort_hash_table_f
191 PARAMS ((struct mips_elf_link_hash_entry *, PTR));
192 static boolean mips_elf_sort_hash_table
193 PARAMS ((struct bfd_link_info *, unsigned long));
194 static asection * mips_elf_got_section PARAMS ((bfd *));
195 static struct mips_got_info *mips_elf_got_info
196 PARAMS ((bfd *, asection **));
197 static boolean mips_elf_local_relocation_p
198 PARAMS ((bfd *, const Elf_Internal_Rela *, asection **, boolean));
199 static bfd_vma mips_elf_create_local_got_entry
200 PARAMS ((bfd *, struct mips_got_info *, asection *, bfd_vma));
201 static bfd_vma mips_elf_got16_entry
202 PARAMS ((bfd *, struct bfd_link_info *, bfd_vma, boolean));
203 static boolean mips_elf_create_dynamic_relocation
204 PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Rela *,
205 struct mips_elf_link_hash_entry *, asection *,
206 bfd_vma, bfd_vma *, asection *));
207 static void mips_elf_allocate_dynamic_relocations
208 PARAMS ((bfd *, unsigned int));
209 static boolean mips_elf_stub_section_p
210 PARAMS ((bfd *, asection *));
211 static int sort_dynamic_relocs
212 PARAMS ((const void *, const void *));
213 static void _bfd_mips_elf_hide_symbol
214 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
215 static void _bfd_mips_elf_copy_indirect_symbol
216 PARAMS ((struct elf_link_hash_entry *,
217 struct elf_link_hash_entry *));
218 static boolean _bfd_elf32_mips_grok_prstatus
219 PARAMS ((bfd *, Elf_Internal_Note *));
220 static boolean _bfd_elf32_mips_grok_psinfo
221 PARAMS ((bfd *, Elf_Internal_Note *));
222 static boolean _bfd_elf32_mips_discard_info
223 PARAMS ((bfd *, struct elf_reloc_cookie *, struct bfd_link_info *));
224 static boolean _bfd_elf32_mips_ignore_discarded_relocs
225 PARAMS ((asection *));
226 static boolean _bfd_elf32_mips_write_section
227 PARAMS ((bfd *, asection *, bfd_byte *));
229 extern const bfd_target bfd_elf32_tradbigmips_vec;
230 extern const bfd_target bfd_elf32_tradlittlemips_vec;
232 extern const bfd_target bfd_elf64_tradbigmips_vec;
233 extern const bfd_target bfd_elf64_tradlittlemips_vec;
236 /* The level of IRIX compatibility we're striving for. */
244 /* This will be used when we sort the dynamic relocation records. */
245 static bfd *reldyn_sorting_bfd;
247 /* Nonzero if ABFD is using the N32 ABI. */
249 #define ABI_N32_P(abfd) \
250 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
252 /* Nonzero if ABFD is using the 64-bit ABI. */
253 #define ABI_64_P(abfd) \
254 ((elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS64) != 0)
256 /* Depending on the target vector we generate some version of Irix
257 executables or "normal" MIPS ELF ABI executables. */
259 #define IRIX_COMPAT(abfd) \
260 (((abfd->xvec == &bfd_elf64_tradbigmips_vec) || \
261 (abfd->xvec == &bfd_elf64_tradlittlemips_vec) || \
262 (abfd->xvec == &bfd_elf32_tradbigmips_vec) || \
263 (abfd->xvec == &bfd_elf32_tradlittlemips_vec)) ? ict_none : \
264 ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5))
266 #define IRIX_COMPAT(abfd) \
267 (((abfd->xvec == &bfd_elf32_tradbigmips_vec) || \
268 (abfd->xvec == &bfd_elf32_tradlittlemips_vec)) ? ict_none : \
269 ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5))
272 /* Whether we are trying to be compatible with IRIX at all. */
273 #define SGI_COMPAT(abfd) \
274 (IRIX_COMPAT (abfd) != ict_none)
276 /* The name of the msym section. */
277 #define MIPS_ELF_MSYM_SECTION_NAME(abfd) ".msym"
279 /* The name of the srdata section. */
280 #define MIPS_ELF_SRDATA_SECTION_NAME(abfd) ".srdata"
282 /* The name of the options section. */
283 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
284 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.options" : ".options")
286 /* The name of the stub section. */
287 #define MIPS_ELF_STUB_SECTION_NAME(abfd) \
288 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.stubs" : ".stub")
290 /* The name of the dynamic relocation section. */
291 #define MIPS_ELF_REL_DYN_SECTION_NAME(abfd) ".rel.dyn"
293 /* The size of an external REL relocation. */
294 #define MIPS_ELF_REL_SIZE(abfd) \
295 (get_elf_backend_data (abfd)->s->sizeof_rel)
297 /* The size of an external dynamic table entry. */
298 #define MIPS_ELF_DYN_SIZE(abfd) \
299 (get_elf_backend_data (abfd)->s->sizeof_dyn)
301 /* The size of a GOT entry. */
302 #define MIPS_ELF_GOT_SIZE(abfd) \
303 (get_elf_backend_data (abfd)->s->arch_size / 8)
305 /* The size of a symbol-table entry. */
306 #define MIPS_ELF_SYM_SIZE(abfd) \
307 (get_elf_backend_data (abfd)->s->sizeof_sym)
309 /* The default alignment for sections, as a power of two. */
310 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
311 (get_elf_backend_data (abfd)->s->file_align == 8 ? 3 : 2)
313 /* Get word-sized data. */
314 #define MIPS_ELF_GET_WORD(abfd, ptr) \
315 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
317 /* Put out word-sized data. */
318 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
320 ? bfd_put_64 (abfd, val, ptr) \
321 : bfd_put_32 (abfd, val, ptr))
323 /* Add a dynamic symbol table-entry. */
325 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
326 (ABI_64_P (elf_hash_table (info)->dynobj) \
327 ? bfd_elf64_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val) \
328 : bfd_elf32_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
330 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
331 (ABI_64_P (elf_hash_table (info)->dynobj) \
332 ? (boolean) (abort (), false) \
333 : bfd_elf32_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
336 /* The number of local .got entries we reserve. */
337 #define MIPS_RESERVED_GOTNO (2)
339 /* Instructions which appear in a stub. For some reason the stub is
340 slightly different on an SGI system. */
341 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
342 #define STUB_LW(abfd) \
345 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
346 : 0x8f998010) /* lw t9,0x8010(gp) */ \
347 : 0x8f998010) /* lw t9,0x8000(gp) */
348 #define STUB_MOVE(abfd) \
349 (SGI_COMPAT (abfd) ? 0x03e07825 : 0x03e07821) /* move t7,ra */
350 #define STUB_JALR 0x0320f809 /* jal t9 */
351 #define STUB_LI16(abfd) \
352 (SGI_COMPAT (abfd) ? 0x34180000 : 0x24180000) /* ori t8,zero,0 */
353 #define MIPS_FUNCTION_STUB_SIZE (16)
356 /* We no longer try to identify particular sections for the .dynsym
357 section. When we do, we wind up crashing if there are other random
358 sections with relocations. */
360 /* Names of sections which appear in the .dynsym section in an Irix 5
363 static const char * const mips_elf_dynsym_sec_names[] =
376 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
377 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
379 /* The number of entries in mips_elf_dynsym_sec_names which go in the
382 #define MIPS_TEXT_DYNSYM_SECNO (3)
386 /* The names of the runtime procedure table symbols used on Irix 5. */
388 static const char * const mips_elf_dynsym_rtproc_names[] =
391 "_procedure_string_table",
392 "_procedure_table_size",
396 /* These structures are used to generate the .compact_rel section on
401 unsigned long id1; /* Always one? */
402 unsigned long num; /* Number of compact relocation entries. */
403 unsigned long id2; /* Always two? */
404 unsigned long offset; /* The file offset of the first relocation. */
405 unsigned long reserved0; /* Zero? */
406 unsigned long reserved1; /* Zero? */
415 bfd_byte reserved0[4];
416 bfd_byte reserved1[4];
417 } Elf32_External_compact_rel;
421 unsigned int ctype : 1; /* 1: long 0: short format. See below. */
422 unsigned int rtype : 4; /* Relocation types. See below. */
423 unsigned int dist2to : 8;
424 unsigned int relvaddr : 19; /* (VADDR - vaddr of the previous entry)/ 4 */
425 unsigned long konst; /* KONST field. See below. */
426 unsigned long vaddr; /* VADDR to be relocated. */
431 unsigned int ctype : 1; /* 1: long 0: short format. See below. */
432 unsigned int rtype : 4; /* Relocation types. See below. */
433 unsigned int dist2to : 8;
434 unsigned int relvaddr : 19; /* (VADDR - vaddr of the previous entry)/ 4 */
435 unsigned long konst; /* KONST field. See below. */
443 } Elf32_External_crinfo;
449 } Elf32_External_crinfo2;
451 /* These are the constants used to swap the bitfields in a crinfo. */
453 #define CRINFO_CTYPE (0x1)
454 #define CRINFO_CTYPE_SH (31)
455 #define CRINFO_RTYPE (0xf)
456 #define CRINFO_RTYPE_SH (27)
457 #define CRINFO_DIST2TO (0xff)
458 #define CRINFO_DIST2TO_SH (19)
459 #define CRINFO_RELVADDR (0x7ffff)
460 #define CRINFO_RELVADDR_SH (0)
462 /* A compact relocation info has long (3 words) or short (2 words)
463 formats. A short format doesn't have VADDR field and relvaddr
464 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
465 #define CRF_MIPS_LONG 1
466 #define CRF_MIPS_SHORT 0
468 /* There are 4 types of compact relocation at least. The value KONST
469 has different meaning for each type:
472 CT_MIPS_REL32 Address in data
473 CT_MIPS_WORD Address in word (XXX)
474 CT_MIPS_GPHI_LO GP - vaddr
475 CT_MIPS_JMPAD Address to jump
478 #define CRT_MIPS_REL32 0xa
479 #define CRT_MIPS_WORD 0xb
480 #define CRT_MIPS_GPHI_LO 0xc
481 #define CRT_MIPS_JMPAD 0xd
483 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
484 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
485 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
486 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
488 static void bfd_elf32_swap_compact_rel_out
489 PARAMS ((bfd *, const Elf32_compact_rel *, Elf32_External_compact_rel *));
490 static void bfd_elf32_swap_crinfo_out
491 PARAMS ((bfd *, const Elf32_crinfo *, Elf32_External_crinfo *));
493 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
495 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
496 from smaller values. Start with zero, widen, *then* decrement. */
497 #define MINUS_ONE (((bfd_vma)0) - 1)
499 static reloc_howto_type elf_mips_howto_table[] =
502 HOWTO (R_MIPS_NONE, /* type */
504 0, /* size (0 = byte, 1 = short, 2 = long) */
506 false, /* pc_relative */
508 complain_overflow_dont, /* complain_on_overflow */
509 bfd_elf_generic_reloc, /* special_function */
510 "R_MIPS_NONE", /* name */
511 false, /* partial_inplace */
514 false), /* pcrel_offset */
516 /* 16 bit relocation. */
517 HOWTO (R_MIPS_16, /* type */
519 1, /* size (0 = byte, 1 = short, 2 = long) */
521 false, /* pc_relative */
523 complain_overflow_bitfield, /* complain_on_overflow */
524 bfd_elf_generic_reloc, /* special_function */
525 "R_MIPS_16", /* name */
526 true, /* partial_inplace */
527 0xffff, /* src_mask */
528 0xffff, /* dst_mask */
529 false), /* pcrel_offset */
531 /* 32 bit relocation. */
532 HOWTO (R_MIPS_32, /* type */
534 2, /* size (0 = byte, 1 = short, 2 = long) */
536 false, /* pc_relative */
538 complain_overflow_dont, /* complain_on_overflow */
539 bfd_elf_generic_reloc, /* special_function */
540 "R_MIPS_32", /* name */
541 true, /* partial_inplace */
542 0xffffffff, /* src_mask */
543 0xffffffff, /* dst_mask */
544 false), /* pcrel_offset */
546 /* 32 bit symbol relative relocation. */
547 HOWTO (R_MIPS_REL32, /* type */
549 2, /* size (0 = byte, 1 = short, 2 = long) */
551 false, /* pc_relative */
553 complain_overflow_dont, /* complain_on_overflow */
554 bfd_elf_generic_reloc, /* special_function */
555 "R_MIPS_REL32", /* name */
556 true, /* partial_inplace */
557 0xffffffff, /* src_mask */
558 0xffffffff, /* dst_mask */
559 false), /* pcrel_offset */
561 /* 26 bit jump address. */
562 HOWTO (R_MIPS_26, /* type */
564 2, /* size (0 = byte, 1 = short, 2 = long) */
566 false, /* pc_relative */
568 complain_overflow_dont, /* complain_on_overflow */
569 /* This needs complex overflow
570 detection, because the upper four
571 bits must match the PC + 4. */
572 bfd_elf_generic_reloc, /* special_function */
573 "R_MIPS_26", /* name */
574 true, /* partial_inplace */
575 0x3ffffff, /* src_mask */
576 0x3ffffff, /* dst_mask */
577 false), /* pcrel_offset */
579 /* High 16 bits of symbol value. */
580 HOWTO (R_MIPS_HI16, /* type */
582 2, /* size (0 = byte, 1 = short, 2 = long) */
584 false, /* pc_relative */
586 complain_overflow_dont, /* complain_on_overflow */
587 _bfd_mips_elf_hi16_reloc, /* special_function */
588 "R_MIPS_HI16", /* name */
589 true, /* partial_inplace */
590 0xffff, /* src_mask */
591 0xffff, /* dst_mask */
592 false), /* pcrel_offset */
594 /* Low 16 bits of symbol value. */
595 HOWTO (R_MIPS_LO16, /* type */
597 2, /* size (0 = byte, 1 = short, 2 = long) */
599 false, /* pc_relative */
601 complain_overflow_dont, /* complain_on_overflow */
602 _bfd_mips_elf_lo16_reloc, /* special_function */
603 "R_MIPS_LO16", /* name */
604 true, /* partial_inplace */
605 0xffff, /* src_mask */
606 0xffff, /* dst_mask */
607 false), /* pcrel_offset */
609 /* GP relative reference. */
610 HOWTO (R_MIPS_GPREL16, /* type */
612 2, /* size (0 = byte, 1 = short, 2 = long) */
614 false, /* pc_relative */
616 complain_overflow_signed, /* complain_on_overflow */
617 _bfd_mips_elf_gprel16_reloc, /* special_function */
618 "R_MIPS_GPREL16", /* name */
619 true, /* partial_inplace */
620 0xffff, /* src_mask */
621 0xffff, /* dst_mask */
622 false), /* pcrel_offset */
624 /* Reference to literal section. */
625 HOWTO (R_MIPS_LITERAL, /* type */
627 2, /* size (0 = byte, 1 = short, 2 = long) */
629 false, /* pc_relative */
631 complain_overflow_signed, /* complain_on_overflow */
632 _bfd_mips_elf_gprel16_reloc, /* special_function */
633 "R_MIPS_LITERAL", /* name */
634 true, /* partial_inplace */
635 0xffff, /* src_mask */
636 0xffff, /* dst_mask */
637 false), /* pcrel_offset */
639 /* Reference to global offset table. */
640 HOWTO (R_MIPS_GOT16, /* type */
642 2, /* size (0 = byte, 1 = short, 2 = long) */
644 false, /* pc_relative */
646 complain_overflow_signed, /* complain_on_overflow */
647 _bfd_mips_elf_got16_reloc, /* special_function */
648 "R_MIPS_GOT16", /* name */
649 false, /* partial_inplace */
650 0xffff, /* src_mask */
651 0xffff, /* dst_mask */
652 false), /* pcrel_offset */
654 /* 16 bit PC relative reference. */
655 HOWTO (R_MIPS_PC16, /* type */
657 2, /* size (0 = byte, 1 = short, 2 = long) */
659 true, /* pc_relative */
661 complain_overflow_signed, /* complain_on_overflow */
662 bfd_elf_generic_reloc, /* special_function */
663 "R_MIPS_PC16", /* name */
664 true, /* partial_inplace */
665 0xffff, /* src_mask */
666 0xffff, /* dst_mask */
667 true), /* pcrel_offset */
669 /* 16 bit call through global offset table. */
670 HOWTO (R_MIPS_CALL16, /* type */
672 2, /* size (0 = byte, 1 = short, 2 = long) */
674 false, /* pc_relative */
676 complain_overflow_signed, /* complain_on_overflow */
677 bfd_elf_generic_reloc, /* special_function */
678 "R_MIPS_CALL16", /* name */
679 false, /* partial_inplace */
680 0xffff, /* src_mask */
681 0xffff, /* dst_mask */
682 false), /* pcrel_offset */
684 /* 32 bit GP relative reference. */
685 HOWTO (R_MIPS_GPREL32, /* type */
687 2, /* size (0 = byte, 1 = short, 2 = long) */
689 false, /* pc_relative */
691 complain_overflow_dont, /* complain_on_overflow */
692 _bfd_mips_elf_gprel32_reloc, /* special_function */
693 "R_MIPS_GPREL32", /* name */
694 true, /* partial_inplace */
695 0xffffffff, /* src_mask */
696 0xffffffff, /* dst_mask */
697 false), /* pcrel_offset */
699 /* The remaining relocs are defined on Irix 5, although they are
700 not defined by the ABI. */
705 /* A 5 bit shift field. */
706 HOWTO (R_MIPS_SHIFT5, /* type */
708 2, /* size (0 = byte, 1 = short, 2 = long) */
710 false, /* pc_relative */
712 complain_overflow_bitfield, /* complain_on_overflow */
713 bfd_elf_generic_reloc, /* special_function */
714 "R_MIPS_SHIFT5", /* name */
715 true, /* partial_inplace */
716 0x000007c0, /* src_mask */
717 0x000007c0, /* dst_mask */
718 false), /* pcrel_offset */
720 /* A 6 bit shift field. */
721 /* FIXME: This is not handled correctly; a special function is
722 needed to put the most significant bit in the right place. */
723 HOWTO (R_MIPS_SHIFT6, /* type */
725 2, /* size (0 = byte, 1 = short, 2 = long) */
727 false, /* pc_relative */
729 complain_overflow_bitfield, /* complain_on_overflow */
730 bfd_elf_generic_reloc, /* special_function */
731 "R_MIPS_SHIFT6", /* name */
732 true, /* partial_inplace */
733 0x000007c4, /* src_mask */
734 0x000007c4, /* dst_mask */
735 false), /* pcrel_offset */
737 /* A 64 bit relocation. */
738 HOWTO (R_MIPS_64, /* type */
740 4, /* size (0 = byte, 1 = short, 2 = long) */
742 false, /* pc_relative */
744 complain_overflow_dont, /* complain_on_overflow */
745 mips32_64bit_reloc, /* special_function */
746 "R_MIPS_64", /* name */
747 true, /* partial_inplace */
748 MINUS_ONE, /* src_mask */
749 MINUS_ONE, /* dst_mask */
750 false), /* pcrel_offset */
752 /* Displacement in the global offset table. */
753 HOWTO (R_MIPS_GOT_DISP, /* type */
755 2, /* size (0 = byte, 1 = short, 2 = long) */
757 false, /* pc_relative */
759 complain_overflow_signed, /* complain_on_overflow */
760 bfd_elf_generic_reloc, /* special_function */
761 "R_MIPS_GOT_DISP", /* name */
762 true, /* partial_inplace */
763 0x0000ffff, /* src_mask */
764 0x0000ffff, /* dst_mask */
765 false), /* pcrel_offset */
767 /* Displacement to page pointer in the global offset table. */
768 HOWTO (R_MIPS_GOT_PAGE, /* type */
770 2, /* size (0 = byte, 1 = short, 2 = long) */
772 false, /* pc_relative */
774 complain_overflow_signed, /* complain_on_overflow */
775 bfd_elf_generic_reloc, /* special_function */
776 "R_MIPS_GOT_PAGE", /* name */
777 true, /* partial_inplace */
778 0x0000ffff, /* src_mask */
779 0x0000ffff, /* dst_mask */
780 false), /* pcrel_offset */
782 /* Offset from page pointer in the global offset table. */
783 HOWTO (R_MIPS_GOT_OFST, /* type */
785 2, /* size (0 = byte, 1 = short, 2 = long) */
787 false, /* pc_relative */
789 complain_overflow_signed, /* complain_on_overflow */
790 bfd_elf_generic_reloc, /* special_function */
791 "R_MIPS_GOT_OFST", /* name */
792 true, /* partial_inplace */
793 0x0000ffff, /* src_mask */
794 0x0000ffff, /* dst_mask */
795 false), /* pcrel_offset */
797 /* High 16 bits of displacement in global offset table. */
798 HOWTO (R_MIPS_GOT_HI16, /* type */
800 2, /* size (0 = byte, 1 = short, 2 = long) */
802 false, /* pc_relative */
804 complain_overflow_dont, /* complain_on_overflow */
805 bfd_elf_generic_reloc, /* special_function */
806 "R_MIPS_GOT_HI16", /* name */
807 true, /* partial_inplace */
808 0x0000ffff, /* src_mask */
809 0x0000ffff, /* dst_mask */
810 false), /* pcrel_offset */
812 /* Low 16 bits of displacement in global offset table. */
813 HOWTO (R_MIPS_GOT_LO16, /* type */
815 2, /* size (0 = byte, 1 = short, 2 = long) */
817 false, /* pc_relative */
819 complain_overflow_dont, /* complain_on_overflow */
820 bfd_elf_generic_reloc, /* special_function */
821 "R_MIPS_GOT_LO16", /* name */
822 true, /* partial_inplace */
823 0x0000ffff, /* src_mask */
824 0x0000ffff, /* dst_mask */
825 false), /* pcrel_offset */
827 /* 64 bit subtraction. Used in the N32 ABI. */
828 HOWTO (R_MIPS_SUB, /* type */
830 4, /* size (0 = byte, 1 = short, 2 = long) */
832 false, /* pc_relative */
834 complain_overflow_dont, /* complain_on_overflow */
835 bfd_elf_generic_reloc, /* special_function */
836 "R_MIPS_SUB", /* name */
837 true, /* partial_inplace */
838 MINUS_ONE, /* src_mask */
839 MINUS_ONE, /* dst_mask */
840 false), /* pcrel_offset */
842 /* Used to cause the linker to insert and delete instructions? */
843 EMPTY_HOWTO (R_MIPS_INSERT_A),
844 EMPTY_HOWTO (R_MIPS_INSERT_B),
845 EMPTY_HOWTO (R_MIPS_DELETE),
847 /* Get the higher value of a 64 bit addend. */
848 HOWTO (R_MIPS_HIGHER, /* type */
850 2, /* size (0 = byte, 1 = short, 2 = long) */
852 false, /* pc_relative */
854 complain_overflow_dont, /* complain_on_overflow */
855 bfd_elf_generic_reloc, /* special_function */
856 "R_MIPS_HIGHER", /* name */
857 true, /* partial_inplace */
858 0xffff, /* src_mask */
859 0xffff, /* dst_mask */
860 false), /* pcrel_offset */
862 /* Get the highest value of a 64 bit addend. */
863 HOWTO (R_MIPS_HIGHEST, /* type */
865 2, /* size (0 = byte, 1 = short, 2 = long) */
867 false, /* pc_relative */
869 complain_overflow_dont, /* complain_on_overflow */
870 bfd_elf_generic_reloc, /* special_function */
871 "R_MIPS_HIGHEST", /* name */
872 true, /* partial_inplace */
873 0xffff, /* src_mask */
874 0xffff, /* dst_mask */
875 false), /* pcrel_offset */
877 /* High 16 bits of displacement in global offset table. */
878 HOWTO (R_MIPS_CALL_HI16, /* type */
880 2, /* size (0 = byte, 1 = short, 2 = long) */
882 false, /* pc_relative */
884 complain_overflow_dont, /* complain_on_overflow */
885 bfd_elf_generic_reloc, /* special_function */
886 "R_MIPS_CALL_HI16", /* name */
887 true, /* partial_inplace */
888 0x0000ffff, /* src_mask */
889 0x0000ffff, /* dst_mask */
890 false), /* pcrel_offset */
892 /* Low 16 bits of displacement in global offset table. */
893 HOWTO (R_MIPS_CALL_LO16, /* type */
895 2, /* size (0 = byte, 1 = short, 2 = long) */
897 false, /* pc_relative */
899 complain_overflow_dont, /* complain_on_overflow */
900 bfd_elf_generic_reloc, /* special_function */
901 "R_MIPS_CALL_LO16", /* name */
902 true, /* partial_inplace */
903 0x0000ffff, /* src_mask */
904 0x0000ffff, /* dst_mask */
905 false), /* pcrel_offset */
907 /* Section displacement. */
908 HOWTO (R_MIPS_SCN_DISP, /* type */
910 2, /* size (0 = byte, 1 = short, 2 = long) */
912 false, /* pc_relative */
914 complain_overflow_dont, /* complain_on_overflow */
915 bfd_elf_generic_reloc, /* special_function */
916 "R_MIPS_SCN_DISP", /* name */
917 true, /* partial_inplace */
918 0xffffffff, /* src_mask */
919 0xffffffff, /* dst_mask */
920 false), /* pcrel_offset */
922 EMPTY_HOWTO (R_MIPS_REL16),
923 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
924 EMPTY_HOWTO (R_MIPS_PJUMP),
925 EMPTY_HOWTO (R_MIPS_RELGOT),
927 /* Protected jump conversion. This is an optimization hint. No
928 relocation is required for correctness. */
929 HOWTO (R_MIPS_JALR, /* type */
931 0, /* size (0 = byte, 1 = short, 2 = long) */
933 false, /* pc_relative */
935 complain_overflow_dont, /* complain_on_overflow */
936 bfd_elf_generic_reloc, /* special_function */
937 "R_MIPS_JALR", /* name */
938 false, /* partial_inplace */
939 0x00000000, /* src_mask */
940 0x00000000, /* dst_mask */
941 false), /* pcrel_offset */
944 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
945 is a hack to make the linker think that we need 64 bit values. */
946 static reloc_howto_type elf_mips_ctor64_howto =
947 HOWTO (R_MIPS_64, /* type */
949 4, /* size (0 = byte, 1 = short, 2 = long) */
951 false, /* pc_relative */
953 complain_overflow_signed, /* complain_on_overflow */
954 mips32_64bit_reloc, /* special_function */
955 "R_MIPS_64", /* name */
956 true, /* partial_inplace */
957 0xffffffff, /* src_mask */
958 0xffffffff, /* dst_mask */
959 false); /* pcrel_offset */
961 /* The reloc used for the mips16 jump instruction. */
962 static reloc_howto_type elf_mips16_jump_howto =
963 HOWTO (R_MIPS16_26, /* type */
965 2, /* size (0 = byte, 1 = short, 2 = long) */
967 false, /* pc_relative */
969 complain_overflow_dont, /* complain_on_overflow */
970 /* This needs complex overflow
971 detection, because the upper four
972 bits must match the PC. */
973 mips16_jump_reloc, /* special_function */
974 "R_MIPS16_26", /* name */
975 true, /* partial_inplace */
976 0x3ffffff, /* src_mask */
977 0x3ffffff, /* dst_mask */
978 false); /* pcrel_offset */
980 /* The reloc used for the mips16 gprel instruction. */
981 static reloc_howto_type elf_mips16_gprel_howto =
982 HOWTO (R_MIPS16_GPREL, /* type */
984 2, /* size (0 = byte, 1 = short, 2 = long) */
986 false, /* pc_relative */
988 complain_overflow_signed, /* complain_on_overflow */
989 mips16_gprel_reloc, /* special_function */
990 "R_MIPS16_GPREL", /* name */
991 true, /* partial_inplace */
992 0x07ff001f, /* src_mask */
993 0x07ff001f, /* dst_mask */
994 false); /* pcrel_offset */
996 /* GNU extensions for embedded-pic. */
997 /* High 16 bits of symbol value, pc-relative. */
998 static reloc_howto_type elf_mips_gnu_rel_hi16 =
999 HOWTO (R_MIPS_GNU_REL_HI16, /* type */
1001 2, /* size (0 = byte, 1 = short, 2 = long) */
1003 true, /* pc_relative */
1005 complain_overflow_dont, /* complain_on_overflow */
1006 _bfd_mips_elf_hi16_reloc, /* special_function */
1007 "R_MIPS_GNU_REL_HI16", /* name */
1008 true, /* partial_inplace */
1009 0xffff, /* src_mask */
1010 0xffff, /* dst_mask */
1011 true); /* pcrel_offset */
1013 /* Low 16 bits of symbol value, pc-relative. */
1014 static reloc_howto_type elf_mips_gnu_rel_lo16 =
1015 HOWTO (R_MIPS_GNU_REL_LO16, /* type */
1017 2, /* size (0 = byte, 1 = short, 2 = long) */
1019 true, /* pc_relative */
1021 complain_overflow_dont, /* complain_on_overflow */
1022 _bfd_mips_elf_lo16_reloc, /* special_function */
1023 "R_MIPS_GNU_REL_LO16", /* name */
1024 true, /* partial_inplace */
1025 0xffff, /* src_mask */
1026 0xffff, /* dst_mask */
1027 true); /* pcrel_offset */
1029 /* 16 bit offset for pc-relative branches. */
1030 static reloc_howto_type elf_mips_gnu_rel16_s2 =
1031 HOWTO (R_MIPS_GNU_REL16_S2, /* type */
1033 2, /* size (0 = byte, 1 = short, 2 = long) */
1035 true, /* pc_relative */
1037 complain_overflow_signed, /* complain_on_overflow */
1038 bfd_elf_generic_reloc, /* special_function */
1039 "R_MIPS_GNU_REL16_S2", /* name */
1040 true, /* partial_inplace */
1041 0xffff, /* src_mask */
1042 0xffff, /* dst_mask */
1043 true); /* pcrel_offset */
1045 /* 64 bit pc-relative. */
1046 static reloc_howto_type elf_mips_gnu_pcrel64 =
1047 HOWTO (R_MIPS_PC64, /* type */
1049 4, /* size (0 = byte, 1 = short, 2 = long) */
1051 true, /* pc_relative */
1053 complain_overflow_signed, /* complain_on_overflow */
1054 bfd_elf_generic_reloc, /* special_function */
1055 "R_MIPS_PC64", /* name */
1056 true, /* partial_inplace */
1057 MINUS_ONE, /* src_mask */
1058 MINUS_ONE, /* dst_mask */
1059 true); /* pcrel_offset */
1061 /* 32 bit pc-relative. */
1062 static reloc_howto_type elf_mips_gnu_pcrel32 =
1063 HOWTO (R_MIPS_PC32, /* type */
1065 2, /* size (0 = byte, 1 = short, 2 = long) */
1067 true, /* pc_relative */
1069 complain_overflow_signed, /* complain_on_overflow */
1070 bfd_elf_generic_reloc, /* special_function */
1071 "R_MIPS_PC32", /* name */
1072 true, /* partial_inplace */
1073 0xffffffff, /* src_mask */
1074 0xffffffff, /* dst_mask */
1075 true); /* pcrel_offset */
1077 /* GNU extension to record C++ vtable hierarchy */
1078 static reloc_howto_type elf_mips_gnu_vtinherit_howto =
1079 HOWTO (R_MIPS_GNU_VTINHERIT, /* type */
1081 2, /* size (0 = byte, 1 = short, 2 = long) */
1083 false, /* pc_relative */
1085 complain_overflow_dont, /* complain_on_overflow */
1086 NULL, /* special_function */
1087 "R_MIPS_GNU_VTINHERIT", /* name */
1088 false, /* partial_inplace */
1091 false); /* pcrel_offset */
1093 /* GNU extension to record C++ vtable member usage */
1094 static reloc_howto_type elf_mips_gnu_vtentry_howto =
1095 HOWTO (R_MIPS_GNU_VTENTRY, /* type */
1097 2, /* size (0 = byte, 1 = short, 2 = long) */
1099 false, /* pc_relative */
1101 complain_overflow_dont, /* complain_on_overflow */
1102 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1103 "R_MIPS_GNU_VTENTRY", /* name */
1104 false, /* partial_inplace */
1107 false); /* pcrel_offset */
1109 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
1110 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
1111 the HI16. Here we just save the information we need; we do the
1112 actual relocation when we see the LO16. MIPS ELF requires that the
1113 LO16 immediately follow the HI16. As a GNU extension, we permit an
1114 arbitrary number of HI16 relocs to be associated with a single LO16
1115 reloc. This extension permits gcc to output the HI and LO relocs
1120 struct mips_hi16 *next;
1125 /* FIXME: This should not be a static variable. */
1127 static struct mips_hi16 *mips_hi16_list;
1129 bfd_reloc_status_type
1130 _bfd_mips_elf_hi16_reloc (abfd,
1137 bfd *abfd ATTRIBUTE_UNUSED;
1138 arelent *reloc_entry;
1141 asection *input_section;
1143 char **error_message;
1145 bfd_reloc_status_type ret;
1147 struct mips_hi16 *n;
1149 /* If we're relocating, and this an external symbol, we don't want
1150 to change anything. */
1151 if (output_bfd != (bfd *) NULL
1152 && (symbol->flags & BSF_SECTION_SYM) == 0
1153 && reloc_entry->addend == 0)
1155 reloc_entry->address += input_section->output_offset;
1156 return bfd_reloc_ok;
1161 if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
1163 boolean relocateable;
1166 if (ret == bfd_reloc_undefined)
1169 if (output_bfd != NULL)
1170 relocateable = true;
1173 relocateable = false;
1174 output_bfd = symbol->section->output_section->owner;
1177 ret = mips_elf_final_gp (output_bfd, symbol, relocateable,
1178 error_message, &gp);
1179 if (ret != bfd_reloc_ok)
1182 relocation = gp - reloc_entry->address;
1186 if (bfd_is_und_section (symbol->section)
1187 && output_bfd == (bfd *) NULL)
1188 ret = bfd_reloc_undefined;
1190 if (bfd_is_com_section (symbol->section))
1193 relocation = symbol->value;
1196 relocation += symbol->section->output_section->vma;
1197 relocation += symbol->section->output_offset;
1198 relocation += reloc_entry->addend;
1199 if (reloc_entry->howto->pc_relative)
1200 relocation -= reloc_entry->address;
1202 if (reloc_entry->address > input_section->_cooked_size)
1203 return bfd_reloc_outofrange;
1205 /* Save the information, and let LO16 do the actual relocation. */
1206 n = (struct mips_hi16 *) bfd_malloc ((bfd_size_type) sizeof *n);
1208 return bfd_reloc_outofrange;
1209 n->addr = (bfd_byte *) data + reloc_entry->address;
1210 n->addend = relocation;
1211 n->next = mips_hi16_list;
1214 if (output_bfd != (bfd *) NULL)
1215 reloc_entry->address += input_section->output_offset;
1220 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
1221 inplace relocation; this function exists in order to do the
1222 R_MIPS_HI16 relocation described above. */
1224 bfd_reloc_status_type
1225 _bfd_mips_elf_lo16_reloc (abfd,
1233 arelent *reloc_entry;
1236 asection *input_section;
1238 char **error_message;
1240 arelent gp_disp_relent;
1242 if (mips_hi16_list != NULL)
1244 struct mips_hi16 *l;
1251 unsigned long vallo;
1252 struct mips_hi16 *next;
1254 /* Do the HI16 relocation. Note that we actually don't need
1255 to know anything about the LO16 itself, except where to
1256 find the low 16 bits of the addend needed by the LO16. */
1257 insn = bfd_get_32 (abfd, l->addr);
1258 vallo = (bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address)
1260 val = ((insn & 0xffff) << 16) + vallo;
1263 /* The low order 16 bits are always treated as a signed
1264 value. Therefore, a negative value in the low order bits
1265 requires an adjustment in the high order bits. We need
1266 to make this adjustment in two ways: once for the bits we
1267 took from the data, and once for the bits we are putting
1268 back in to the data. */
1269 if ((vallo & 0x8000) != 0)
1271 if ((val & 0x8000) != 0)
1274 insn = (insn &~ (bfd_vma) 0xffff) | ((val >> 16) & 0xffff);
1275 bfd_put_32 (abfd, (bfd_vma) insn, l->addr);
1277 if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
1279 gp_disp_relent = *reloc_entry;
1280 reloc_entry = &gp_disp_relent;
1281 reloc_entry->addend = l->addend;
1289 mips_hi16_list = NULL;
1291 else if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
1293 bfd_reloc_status_type ret;
1294 bfd_vma gp, relocation;
1296 /* FIXME: Does this case ever occur? */
1298 ret = mips_elf_final_gp (output_bfd, symbol, true, error_message, &gp);
1299 if (ret != bfd_reloc_ok)
1302 relocation = gp - reloc_entry->address;
1303 relocation += symbol->section->output_section->vma;
1304 relocation += symbol->section->output_offset;
1305 relocation += reloc_entry->addend;
1307 if (reloc_entry->address > input_section->_cooked_size)
1308 return bfd_reloc_outofrange;
1310 gp_disp_relent = *reloc_entry;
1311 reloc_entry = &gp_disp_relent;
1312 reloc_entry->addend = relocation - 4;
1315 /* Now do the LO16 reloc in the usual way. */
1316 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1317 input_section, output_bfd, error_message);
1320 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1321 table used for PIC code. If the symbol is an external symbol, the
1322 instruction is modified to contain the offset of the appropriate
1323 entry in the global offset table. If the symbol is a section
1324 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1325 addends are combined to form the real addend against the section
1326 symbol; the GOT16 is modified to contain the offset of an entry in
1327 the global offset table, and the LO16 is modified to offset it
1328 appropriately. Thus an offset larger than 16 bits requires a
1329 modified value in the global offset table.
1331 This implementation suffices for the assembler, but the linker does
1332 not yet know how to create global offset tables. */
1334 bfd_reloc_status_type
1335 _bfd_mips_elf_got16_reloc (abfd,
1343 arelent *reloc_entry;
1346 asection *input_section;
1348 char **error_message;
1350 /* If we're relocating, and this an external symbol, we don't want
1351 to change anything. */
1352 if (output_bfd != (bfd *) NULL
1353 && (symbol->flags & BSF_SECTION_SYM) == 0
1354 && reloc_entry->addend == 0)
1356 reloc_entry->address += input_section->output_offset;
1357 return bfd_reloc_ok;
1360 /* If we're relocating, and this is a local symbol, we can handle it
1362 if (output_bfd != (bfd *) NULL
1363 && (symbol->flags & BSF_SECTION_SYM) != 0)
1364 return _bfd_mips_elf_hi16_reloc (abfd, reloc_entry, symbol, data,
1365 input_section, output_bfd, error_message);
1370 /* Set the GP value for OUTPUT_BFD. Returns false if this is a
1371 dangerous relocation. */
1374 mips_elf_assign_gp (output_bfd, pgp)
1382 /* If we've already figured out what GP will be, just return it. */
1383 *pgp = _bfd_get_gp_value (output_bfd);
1387 count = bfd_get_symcount (output_bfd);
1388 sym = bfd_get_outsymbols (output_bfd);
1390 /* The linker script will have created a symbol named `_gp' with the
1391 appropriate value. */
1392 if (sym == (asymbol **) NULL)
1396 for (i = 0; i < count; i++, sym++)
1398 register const char *name;
1400 name = bfd_asymbol_name (*sym);
1401 if (*name == '_' && strcmp (name, "_gp") == 0)
1403 *pgp = bfd_asymbol_value (*sym);
1404 _bfd_set_gp_value (output_bfd, *pgp);
1412 /* Only get the error once. */
1414 _bfd_set_gp_value (output_bfd, *pgp);
1421 /* We have to figure out the gp value, so that we can adjust the
1422 symbol value correctly. We look up the symbol _gp in the output
1423 BFD. If we can't find it, we're stuck. We cache it in the ELF
1424 target data. We don't need to adjust the symbol value for an
1425 external symbol if we are producing relocateable output. */
1427 static bfd_reloc_status_type
1428 mips_elf_final_gp (output_bfd, symbol, relocateable, error_message, pgp)
1431 boolean relocateable;
1432 char **error_message;
1435 if (bfd_is_und_section (symbol->section)
1439 return bfd_reloc_undefined;
1442 *pgp = _bfd_get_gp_value (output_bfd);
1445 || (symbol->flags & BSF_SECTION_SYM) != 0))
1449 /* Make up a value. */
1450 *pgp = symbol->section->output_section->vma + 0x4000;
1451 _bfd_set_gp_value (output_bfd, *pgp);
1453 else if (!mips_elf_assign_gp (output_bfd, pgp))
1456 (char *) _("GP relative relocation when _gp not defined");
1457 return bfd_reloc_dangerous;
1461 return bfd_reloc_ok;
1464 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1465 become the offset from the gp register. This function also handles
1466 R_MIPS_LITERAL relocations, although those can be handled more
1467 cleverly because the entries in the .lit8 and .lit4 sections can be
1470 static bfd_reloc_status_type gprel16_with_gp PARAMS ((bfd *, asymbol *,
1471 arelent *, asection *,
1472 boolean, PTR, bfd_vma));
1474 bfd_reloc_status_type
1475 _bfd_mips_elf_gprel16_reloc (abfd, reloc_entry, symbol, data, input_section,
1476 output_bfd, error_message)
1478 arelent *reloc_entry;
1481 asection *input_section;
1483 char **error_message;
1485 boolean relocateable;
1486 bfd_reloc_status_type ret;
1489 /* If we're relocating, and this is an external symbol with no
1490 addend, we don't want to change anything. We will only have an
1491 addend if this is a newly created reloc, not read from an ELF
1493 if (output_bfd != (bfd *) NULL
1494 && (symbol->flags & BSF_SECTION_SYM) == 0
1495 && reloc_entry->addend == 0)
1497 reloc_entry->address += input_section->output_offset;
1498 return bfd_reloc_ok;
1501 if (output_bfd != (bfd *) NULL)
1502 relocateable = true;
1505 relocateable = false;
1506 output_bfd = symbol->section->output_section->owner;
1509 ret = mips_elf_final_gp (output_bfd, symbol, relocateable, error_message,
1511 if (ret != bfd_reloc_ok)
1514 return gprel16_with_gp (abfd, symbol, reloc_entry, input_section,
1515 relocateable, data, gp);
1518 static bfd_reloc_status_type
1519 gprel16_with_gp (abfd, symbol, reloc_entry, input_section, relocateable, data,
1523 arelent *reloc_entry;
1524 asection *input_section;
1525 boolean relocateable;
1533 if (bfd_is_com_section (symbol->section))
1536 relocation = symbol->value;
1538 relocation += symbol->section->output_section->vma;
1539 relocation += symbol->section->output_offset;
1541 if (reloc_entry->address > input_section->_cooked_size)
1542 return bfd_reloc_outofrange;
1544 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1546 /* Set val to the offset into the section or symbol. */
1547 if (reloc_entry->howto->src_mask == 0)
1549 /* This case occurs with the 64-bit MIPS ELF ABI. */
1550 val = reloc_entry->addend;
1554 val = ((insn & 0xffff) + reloc_entry->addend) & 0xffff;
1559 /* Adjust val for the final section location and GP value. If we
1560 are producing relocateable output, we don't want to do this for
1561 an external symbol. */
1563 || (symbol->flags & BSF_SECTION_SYM) != 0)
1564 val += relocation - gp;
1566 insn = (insn &~ (bfd_vma) 0xffff) | (val & 0xffff);
1567 bfd_put_32 (abfd, (bfd_vma) insn, (bfd_byte *) data + reloc_entry->address);
1570 reloc_entry->address += input_section->output_offset;
1572 /* Make sure it fit in 16 bits. */
1573 if ((long) val >= 0x8000 || (long) val < -0x8000)
1574 return bfd_reloc_overflow;
1576 return bfd_reloc_ok;
1579 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1580 from the gp register? XXX */
1582 static bfd_reloc_status_type gprel32_with_gp PARAMS ((bfd *, asymbol *,
1583 arelent *, asection *,
1584 boolean, PTR, bfd_vma));
1586 bfd_reloc_status_type
1587 _bfd_mips_elf_gprel32_reloc (abfd,
1595 arelent *reloc_entry;
1598 asection *input_section;
1600 char **error_message;
1602 boolean relocateable;
1603 bfd_reloc_status_type ret;
1606 /* If we're relocating, and this is an external symbol with no
1607 addend, we don't want to change anything. We will only have an
1608 addend if this is a newly created reloc, not read from an ELF
1610 if (output_bfd != (bfd *) NULL
1611 && (symbol->flags & BSF_SECTION_SYM) == 0
1612 && reloc_entry->addend == 0)
1614 *error_message = (char *)
1615 _("32bits gp relative relocation occurs for an external symbol");
1616 return bfd_reloc_outofrange;
1619 if (output_bfd != (bfd *) NULL)
1621 relocateable = true;
1622 gp = _bfd_get_gp_value (output_bfd);
1626 relocateable = false;
1627 output_bfd = symbol->section->output_section->owner;
1629 ret = mips_elf_final_gp (output_bfd, symbol, relocateable,
1630 error_message, &gp);
1631 if (ret != bfd_reloc_ok)
1635 return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
1636 relocateable, data, gp);
1639 static bfd_reloc_status_type
1640 gprel32_with_gp (abfd, symbol, reloc_entry, input_section, relocateable, data,
1644 arelent *reloc_entry;
1645 asection *input_section;
1646 boolean relocateable;
1653 if (bfd_is_com_section (symbol->section))
1656 relocation = symbol->value;
1658 relocation += symbol->section->output_section->vma;
1659 relocation += symbol->section->output_offset;
1661 if (reloc_entry->address > input_section->_cooked_size)
1662 return bfd_reloc_outofrange;
1664 if (reloc_entry->howto->src_mask == 0)
1666 /* This case arises with the 64-bit MIPS ELF ABI. */
1670 val = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1672 /* Set val to the offset into the section or symbol. */
1673 val += reloc_entry->addend;
1675 /* Adjust val for the final section location and GP value. If we
1676 are producing relocateable output, we don't want to do this for
1677 an external symbol. */
1679 || (symbol->flags & BSF_SECTION_SYM) != 0)
1680 val += relocation - gp;
1682 bfd_put_32 (abfd, (bfd_vma) val, (bfd_byte *) data + reloc_entry->address);
1685 reloc_entry->address += input_section->output_offset;
1687 return bfd_reloc_ok;
1690 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1691 generated when addresses are 64 bits. The upper 32 bits are a simple
1694 static bfd_reloc_status_type
1695 mips32_64bit_reloc (abfd, reloc_entry, symbol, data, input_section,
1696 output_bfd, error_message)
1698 arelent *reloc_entry;
1701 asection *input_section;
1703 char **error_message;
1705 bfd_reloc_status_type r;
1710 r = bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1711 input_section, output_bfd, error_message);
1712 if (r != bfd_reloc_continue)
1715 /* Do a normal 32 bit relocation on the lower 32 bits. */
1716 reloc32 = *reloc_entry;
1717 if (bfd_big_endian (abfd))
1718 reloc32.address += 4;
1719 reloc32.howto = &elf_mips_howto_table[R_MIPS_32];
1720 r = bfd_perform_relocation (abfd, &reloc32, data, input_section,
1721 output_bfd, error_message);
1723 /* Sign extend into the upper 32 bits. */
1724 val = bfd_get_32 (abfd, (bfd_byte *) data + reloc32.address);
1725 if ((val & 0x80000000) != 0)
1729 addr = reloc_entry->address;
1730 if (bfd_little_endian (abfd))
1732 bfd_put_32 (abfd, (bfd_vma) val, (bfd_byte *) data + addr);
1737 /* Handle a mips16 jump. */
1739 static bfd_reloc_status_type
1740 mips16_jump_reloc (abfd, reloc_entry, symbol, data, input_section,
1741 output_bfd, error_message)
1742 bfd *abfd ATTRIBUTE_UNUSED;
1743 arelent *reloc_entry;
1745 PTR data ATTRIBUTE_UNUSED;
1746 asection *input_section;
1748 char **error_message ATTRIBUTE_UNUSED;
1750 if (output_bfd != (bfd *) NULL
1751 && (symbol->flags & BSF_SECTION_SYM) == 0
1752 && reloc_entry->addend == 0)
1754 reloc_entry->address += input_section->output_offset;
1755 return bfd_reloc_ok;
1760 static boolean warned;
1763 (*_bfd_error_handler)
1764 (_("Linking mips16 objects into %s format is not supported"),
1765 bfd_get_target (input_section->output_section->owner));
1769 return bfd_reloc_undefined;
1772 /* Handle a mips16 GP relative reloc. */
1774 static bfd_reloc_status_type
1775 mips16_gprel_reloc (abfd, reloc_entry, symbol, data, input_section,
1776 output_bfd, error_message)
1778 arelent *reloc_entry;
1781 asection *input_section;
1783 char **error_message;
1785 boolean relocateable;
1786 bfd_reloc_status_type ret;
1788 unsigned short extend, insn;
1789 unsigned long final;
1791 /* If we're relocating, and this is an external symbol with no
1792 addend, we don't want to change anything. We will only have an
1793 addend if this is a newly created reloc, not read from an ELF
1795 if (output_bfd != NULL
1796 && (symbol->flags & BSF_SECTION_SYM) == 0
1797 && reloc_entry->addend == 0)
1799 reloc_entry->address += input_section->output_offset;
1800 return bfd_reloc_ok;
1803 if (output_bfd != NULL)
1804 relocateable = true;
1807 relocateable = false;
1808 output_bfd = symbol->section->output_section->owner;
1811 ret = mips_elf_final_gp (output_bfd, symbol, relocateable, error_message,
1813 if (ret != bfd_reloc_ok)
1816 if (reloc_entry->address > input_section->_cooked_size)
1817 return bfd_reloc_outofrange;
1819 /* Pick up the mips16 extend instruction and the real instruction. */
1820 extend = bfd_get_16 (abfd, (bfd_byte *) data + reloc_entry->address);
1821 insn = bfd_get_16 (abfd, (bfd_byte *) data + reloc_entry->address + 2);
1823 /* Stuff the current addend back as a 32 bit value, do the usual
1824 relocation, and then clean up. */
1826 (bfd_vma) (((extend & 0x1f) << 11)
1829 (bfd_byte *) data + reloc_entry->address);
1831 ret = gprel16_with_gp (abfd, symbol, reloc_entry, input_section,
1832 relocateable, data, gp);
1834 final = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1836 (bfd_vma) ((extend & 0xf800)
1837 | ((final >> 11) & 0x1f)
1839 (bfd_byte *) data + reloc_entry->address);
1841 (bfd_vma) ((insn & 0xffe0)
1843 (bfd_byte *) data + reloc_entry->address + 2);
1848 /* Return the ISA for a MIPS e_flags value. */
1851 elf_mips_isa (flags)
1854 switch (flags & EF_MIPS_ARCH)
1866 case E_MIPS_ARCH_32:
1868 case E_MIPS_ARCH_64:
1874 /* Return the MACH for a MIPS e_flags value. */
1876 static INLINE unsigned long
1877 elf_mips_mach (flags)
1880 switch (flags & EF_MIPS_MACH)
1882 case E_MIPS_MACH_3900:
1883 return bfd_mach_mips3900;
1885 case E_MIPS_MACH_4010:
1886 return bfd_mach_mips4010;
1888 case E_MIPS_MACH_4100:
1889 return bfd_mach_mips4100;
1891 case E_MIPS_MACH_4111:
1892 return bfd_mach_mips4111;
1894 case E_MIPS_MACH_4650:
1895 return bfd_mach_mips4650;
1897 case E_MIPS_MACH_SB1:
1898 return bfd_mach_mips_sb1;
1901 switch (flags & EF_MIPS_ARCH)
1905 return bfd_mach_mips3000;
1909 return bfd_mach_mips6000;
1913 return bfd_mach_mips4000;
1917 return bfd_mach_mips8000;
1921 return bfd_mach_mips5;
1924 case E_MIPS_ARCH_32:
1925 return bfd_mach_mipsisa32;
1928 case E_MIPS_ARCH_64:
1929 return bfd_mach_mipsisa64;
1937 /* Return printable name for ABI. */
1939 static INLINE char *
1940 elf_mips_abi_name (abfd)
1945 flags = elf_elfheader (abfd)->e_flags;
1946 switch (flags & EF_MIPS_ABI)
1949 if (ABI_N32_P (abfd))
1951 else if (ABI_64_P (abfd))
1955 case E_MIPS_ABI_O32:
1957 case E_MIPS_ABI_O64:
1959 case E_MIPS_ABI_EABI32:
1961 case E_MIPS_ABI_EABI64:
1964 return "unknown abi";
1968 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1970 struct elf_reloc_map {
1971 bfd_reloc_code_real_type bfd_reloc_val;
1972 enum elf_mips_reloc_type elf_reloc_val;
1975 static const struct elf_reloc_map mips_reloc_map[] =
1977 { BFD_RELOC_NONE, R_MIPS_NONE, },
1978 { BFD_RELOC_16, R_MIPS_16 },
1979 { BFD_RELOC_32, R_MIPS_32 },
1980 { BFD_RELOC_64, R_MIPS_64 },
1981 { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
1982 { BFD_RELOC_HI16_S, R_MIPS_HI16 },
1983 { BFD_RELOC_LO16, R_MIPS_LO16 },
1984 { BFD_RELOC_GPREL16, R_MIPS_GPREL16 },
1985 { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
1986 { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
1987 { BFD_RELOC_16_PCREL, R_MIPS_PC16 },
1988 { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
1989 { BFD_RELOC_GPREL32, R_MIPS_GPREL32 },
1990 { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
1991 { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 },
1992 { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 },
1993 { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 },
1994 { BFD_RELOC_MIPS_SUB, R_MIPS_SUB },
1995 { BFD_RELOC_MIPS_GOT_PAGE, R_MIPS_GOT_PAGE },
1996 { BFD_RELOC_MIPS_GOT_OFST, R_MIPS_GOT_OFST },
1997 { BFD_RELOC_MIPS_GOT_DISP, R_MIPS_GOT_DISP }
2000 /* Given a BFD reloc type, return a howto structure. */
2002 static reloc_howto_type *
2003 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
2005 bfd_reloc_code_real_type code;
2009 for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map); i++)
2011 if (mips_reloc_map[i].bfd_reloc_val == code)
2012 return &elf_mips_howto_table[(int) mips_reloc_map[i].elf_reloc_val];
2018 bfd_set_error (bfd_error_bad_value);
2021 case BFD_RELOC_CTOR:
2022 /* We need to handle BFD_RELOC_CTOR specially.
2023 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
2024 size of addresses on this architecture. */
2025 if (bfd_arch_bits_per_address (abfd) == 32)
2026 return &elf_mips_howto_table[(int) R_MIPS_32];
2028 return &elf_mips_ctor64_howto;
2030 case BFD_RELOC_MIPS16_JMP:
2031 return &elf_mips16_jump_howto;
2032 case BFD_RELOC_MIPS16_GPREL:
2033 return &elf_mips16_gprel_howto;
2034 case BFD_RELOC_VTABLE_INHERIT:
2035 return &elf_mips_gnu_vtinherit_howto;
2036 case BFD_RELOC_VTABLE_ENTRY:
2037 return &elf_mips_gnu_vtentry_howto;
2038 case BFD_RELOC_PCREL_HI16_S:
2039 return &elf_mips_gnu_rel_hi16;
2040 case BFD_RELOC_PCREL_LO16:
2041 return &elf_mips_gnu_rel_lo16;
2042 case BFD_RELOC_16_PCREL_S2:
2043 return &elf_mips_gnu_rel16_s2;
2044 case BFD_RELOC_64_PCREL:
2045 return &elf_mips_gnu_pcrel64;
2046 case BFD_RELOC_32_PCREL:
2047 return &elf_mips_gnu_pcrel32;
2051 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
2053 static reloc_howto_type *
2054 mips_rtype_to_howto (r_type)
2055 unsigned int r_type;
2060 return &elf_mips16_jump_howto;
2062 case R_MIPS16_GPREL:
2063 return &elf_mips16_gprel_howto;
2065 case R_MIPS_GNU_VTINHERIT:
2066 return &elf_mips_gnu_vtinherit_howto;
2068 case R_MIPS_GNU_VTENTRY:
2069 return &elf_mips_gnu_vtentry_howto;
2071 case R_MIPS_GNU_REL_HI16:
2072 return &elf_mips_gnu_rel_hi16;
2074 case R_MIPS_GNU_REL_LO16:
2075 return &elf_mips_gnu_rel_lo16;
2077 case R_MIPS_GNU_REL16_S2:
2078 return &elf_mips_gnu_rel16_s2;
2081 return &elf_mips_gnu_pcrel64;
2084 return &elf_mips_gnu_pcrel32;
2088 BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
2089 return &elf_mips_howto_table[r_type];
2094 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
2097 mips_info_to_howto_rel (abfd, cache_ptr, dst)
2100 Elf32_Internal_Rel *dst;
2102 unsigned int r_type;
2104 r_type = ELF32_R_TYPE (dst->r_info);
2105 cache_ptr->howto = mips_rtype_to_howto (r_type);
2107 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
2108 value for the object file. We get the addend now, rather than
2109 when we do the relocation, because the symbol manipulations done
2110 by the linker may cause us to lose track of the input BFD. */
2111 if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
2112 && (r_type == (unsigned int) R_MIPS_GPREL16
2113 || r_type == (unsigned int) R_MIPS_LITERAL))
2114 cache_ptr->addend = elf_gp (abfd);
2117 /* Given a MIPS Elf32_Internal_Rela, fill in an arelent structure. */
2120 mips_info_to_howto_rela (abfd, cache_ptr, dst)
2123 Elf32_Internal_Rela *dst;
2125 /* Since an Elf32_Internal_Rel is an initial prefix of an
2126 Elf32_Internal_Rela, we can just use mips_info_to_howto_rel
2128 mips_info_to_howto_rel (abfd, cache_ptr, (Elf32_Internal_Rel *) dst);
2130 /* If we ever need to do any extra processing with dst->r_addend
2131 (the field omitted in an Elf32_Internal_Rel) we can do it here. */
2134 /* A .reginfo section holds a single Elf32_RegInfo structure. These
2135 routines swap this structure in and out. They are used outside of
2136 BFD, so they are globally visible. */
2139 bfd_mips_elf32_swap_reginfo_in (abfd, ex, in)
2141 const Elf32_External_RegInfo *ex;
2144 in->ri_gprmask = H_GET_32 (abfd, ex->ri_gprmask);
2145 in->ri_cprmask[0] = H_GET_32 (abfd, ex->ri_cprmask[0]);
2146 in->ri_cprmask[1] = H_GET_32 (abfd, ex->ri_cprmask[1]);
2147 in->ri_cprmask[2] = H_GET_32 (abfd, ex->ri_cprmask[2]);
2148 in->ri_cprmask[3] = H_GET_32 (abfd, ex->ri_cprmask[3]);
2149 in->ri_gp_value = H_GET_32 (abfd, ex->ri_gp_value);
2153 bfd_mips_elf32_swap_reginfo_out (abfd, in, ex)
2155 const Elf32_RegInfo *in;
2156 Elf32_External_RegInfo *ex;
2158 H_PUT_32 (abfd, in->ri_gprmask, ex->ri_gprmask);
2159 H_PUT_32 (abfd, in->ri_cprmask[0], ex->ri_cprmask[0]);
2160 H_PUT_32 (abfd, in->ri_cprmask[1], ex->ri_cprmask[1]);
2161 H_PUT_32 (abfd, in->ri_cprmask[2], ex->ri_cprmask[2]);
2162 H_PUT_32 (abfd, in->ri_cprmask[3], ex->ri_cprmask[3]);
2163 H_PUT_32 (abfd, in->ri_gp_value, ex->ri_gp_value);
2166 /* In the 64 bit ABI, the .MIPS.options section holds register
2167 information in an Elf64_Reginfo structure. These routines swap
2168 them in and out. They are globally visible because they are used
2169 outside of BFD. These routines are here so that gas can call them
2170 without worrying about whether the 64 bit ABI has been included. */
2173 bfd_mips_elf64_swap_reginfo_in (abfd, ex, in)
2175 const Elf64_External_RegInfo *ex;
2176 Elf64_Internal_RegInfo *in;
2178 in->ri_gprmask = H_GET_32 (abfd, ex->ri_gprmask);
2179 in->ri_pad = H_GET_32 (abfd, ex->ri_pad);
2180 in->ri_cprmask[0] = H_GET_32 (abfd, ex->ri_cprmask[0]);
2181 in->ri_cprmask[1] = H_GET_32 (abfd, ex->ri_cprmask[1]);
2182 in->ri_cprmask[2] = H_GET_32 (abfd, ex->ri_cprmask[2]);
2183 in->ri_cprmask[3] = H_GET_32 (abfd, ex->ri_cprmask[3]);
2184 in->ri_gp_value = H_GET_64 (abfd, ex->ri_gp_value);
2188 bfd_mips_elf64_swap_reginfo_out (abfd, in, ex)
2190 const Elf64_Internal_RegInfo *in;
2191 Elf64_External_RegInfo *ex;
2193 H_PUT_32 (abfd, in->ri_gprmask, ex->ri_gprmask);
2194 H_PUT_32 (abfd, in->ri_pad, ex->ri_pad);
2195 H_PUT_32 (abfd, in->ri_cprmask[0], ex->ri_cprmask[0]);
2196 H_PUT_32 (abfd, in->ri_cprmask[1], ex->ri_cprmask[1]);
2197 H_PUT_32 (abfd, in->ri_cprmask[2], ex->ri_cprmask[2]);
2198 H_PUT_32 (abfd, in->ri_cprmask[3], ex->ri_cprmask[3]);
2199 H_PUT_64 (abfd, in->ri_gp_value, ex->ri_gp_value);
2202 /* Swap an entry in a .gptab section. Note that these routines rely
2203 on the equivalence of the two elements of the union. */
2206 bfd_mips_elf32_swap_gptab_in (abfd, ex, in)
2208 const Elf32_External_gptab *ex;
2211 in->gt_entry.gt_g_value = H_GET_32 (abfd, ex->gt_entry.gt_g_value);
2212 in->gt_entry.gt_bytes = H_GET_32 (abfd, ex->gt_entry.gt_bytes);
2216 bfd_mips_elf32_swap_gptab_out (abfd, in, ex)
2218 const Elf32_gptab *in;
2219 Elf32_External_gptab *ex;
2221 H_PUT_32 (abfd, in->gt_entry.gt_g_value, ex->gt_entry.gt_g_value);
2222 H_PUT_32 (abfd, in->gt_entry.gt_bytes, ex->gt_entry.gt_bytes);
2226 bfd_elf32_swap_compact_rel_out (abfd, in, ex)
2228 const Elf32_compact_rel *in;
2229 Elf32_External_compact_rel *ex;
2231 H_PUT_32 (abfd, in->id1, ex->id1);
2232 H_PUT_32 (abfd, in->num, ex->num);
2233 H_PUT_32 (abfd, in->id2, ex->id2);
2234 H_PUT_32 (abfd, in->offset, ex->offset);
2235 H_PUT_32 (abfd, in->reserved0, ex->reserved0);
2236 H_PUT_32 (abfd, in->reserved1, ex->reserved1);
2240 bfd_elf32_swap_crinfo_out (abfd, in, ex)
2242 const Elf32_crinfo *in;
2243 Elf32_External_crinfo *ex;
2247 l = (((in->ctype & CRINFO_CTYPE) << CRINFO_CTYPE_SH)
2248 | ((in->rtype & CRINFO_RTYPE) << CRINFO_RTYPE_SH)
2249 | ((in->dist2to & CRINFO_DIST2TO) << CRINFO_DIST2TO_SH)
2250 | ((in->relvaddr & CRINFO_RELVADDR) << CRINFO_RELVADDR_SH));
2251 H_PUT_32 (abfd, l, ex->info);
2252 H_PUT_32 (abfd, in->konst, ex->konst);
2253 H_PUT_32 (abfd, in->vaddr, ex->vaddr);
2256 /* Swap in an options header. */
2259 bfd_mips_elf_swap_options_in (abfd, ex, in)
2261 const Elf_External_Options *ex;
2262 Elf_Internal_Options *in;
2264 in->kind = H_GET_8 (abfd, ex->kind);
2265 in->size = H_GET_8 (abfd, ex->size);
2266 in->section = H_GET_16 (abfd, ex->section);
2267 in->info = H_GET_32 (abfd, ex->info);
2270 /* Swap out an options header. */
2273 bfd_mips_elf_swap_options_out (abfd, in, ex)
2275 const Elf_Internal_Options *in;
2276 Elf_External_Options *ex;
2278 H_PUT_8 (abfd, in->kind, ex->kind);
2279 H_PUT_8 (abfd, in->size, ex->size);
2280 H_PUT_16 (abfd, in->section, ex->section);
2281 H_PUT_32 (abfd, in->info, ex->info);
2284 /* Swap in an MSYM entry. */
2287 bfd_mips_elf_swap_msym_in (abfd, ex, in)
2289 const Elf32_External_Msym *ex;
2290 Elf32_Internal_Msym *in;
2292 in->ms_hash_value = H_GET_32 (abfd, ex->ms_hash_value);
2293 in->ms_info = H_GET_32 (abfd, ex->ms_info);
2296 /* Swap out an MSYM entry. */
2299 bfd_mips_elf_swap_msym_out (abfd, in, ex)
2301 const Elf32_Internal_Msym *in;
2302 Elf32_External_Msym *ex;
2304 H_PUT_32 (abfd, in->ms_hash_value, ex->ms_hash_value);
2305 H_PUT_32 (abfd, in->ms_info, ex->ms_info);
2308 /* Determine whether a symbol is global for the purposes of splitting
2309 the symbol table into global symbols and local symbols. At least
2310 on Irix 5, this split must be between section symbols and all other
2311 symbols. On most ELF targets the split is between static symbols
2312 and externally visible symbols. */
2315 mips_elf_sym_is_global (abfd, sym)
2316 bfd *abfd ATTRIBUTE_UNUSED;
2319 if (SGI_COMPAT (abfd))
2320 return (sym->flags & BSF_SECTION_SYM) == 0;
2322 return ((sym->flags & (BSF_GLOBAL | BSF_WEAK)) != 0
2323 || bfd_is_und_section (bfd_get_section (sym))
2324 || bfd_is_com_section (bfd_get_section (sym)));
2327 /* Set the right machine number for a MIPS ELF file. This is used for
2328 both the 32-bit and the 64-bit ABI. */
2331 _bfd_mips_elf_object_p (abfd)
2334 /* Irix 5 and 6 is broken. Object file symbol tables are not always
2335 sorted correctly such that local symbols precede global symbols,
2336 and the sh_info field in the symbol table is not always right. */
2337 if (SGI_COMPAT(abfd))
2338 elf_bad_symtab (abfd) = true;
2340 bfd_default_set_arch_mach (abfd, bfd_arch_mips,
2341 elf_mips_mach (elf_elfheader (abfd)->e_flags));
2345 /* The final processing done just before writing out a MIPS ELF object
2346 file. This gets the MIPS architecture right based on the machine
2347 number. This is used by both the 32-bit and the 64-bit ABI. */
2350 _bfd_mips_elf_final_write_processing (abfd, linker)
2352 boolean linker ATTRIBUTE_UNUSED;
2356 Elf_Internal_Shdr **hdrpp;
2360 switch (bfd_get_mach (abfd))
2363 case bfd_mach_mips3000:
2364 val = E_MIPS_ARCH_1;
2367 case bfd_mach_mips3900:
2368 val = E_MIPS_ARCH_1 | E_MIPS_MACH_3900;
2371 case bfd_mach_mips6000:
2372 val = E_MIPS_ARCH_2;
2375 case bfd_mach_mips4000:
2376 case bfd_mach_mips4300:
2377 case bfd_mach_mips4400:
2378 case bfd_mach_mips4600:
2379 val = E_MIPS_ARCH_3;
2382 case bfd_mach_mips4010:
2383 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4010;
2386 case bfd_mach_mips4100:
2387 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4100;
2390 case bfd_mach_mips4111:
2391 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4111;
2394 case bfd_mach_mips4650:
2395 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4650;
2398 case bfd_mach_mips5000:
2399 case bfd_mach_mips8000:
2400 case bfd_mach_mips10000:
2401 case bfd_mach_mips12000:
2402 val = E_MIPS_ARCH_4;
2405 case bfd_mach_mips5:
2406 val = E_MIPS_ARCH_5;
2409 case bfd_mach_mips_sb1:
2410 val = E_MIPS_ARCH_64 | E_MIPS_MACH_SB1;
2413 case bfd_mach_mipsisa32:
2414 val = E_MIPS_ARCH_32;
2417 case bfd_mach_mipsisa64:
2418 val = E_MIPS_ARCH_64;
2421 elf_elfheader (abfd)->e_flags &= ~(EF_MIPS_ARCH | EF_MIPS_MACH);
2422 elf_elfheader (abfd)->e_flags |= val;
2424 /* Set the sh_info field for .gptab sections and other appropriate
2425 info for each special section. */
2426 for (i = 1, hdrpp = elf_elfsections (abfd) + 1;
2427 i < elf_elfheader (abfd)->e_shnum;
2430 switch ((*hdrpp)->sh_type)
2433 case SHT_MIPS_LIBLIST:
2434 sec = bfd_get_section_by_name (abfd, ".dynstr");
2436 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx;
2439 case SHT_MIPS_GPTAB:
2440 BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
2441 name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section);
2442 BFD_ASSERT (name != NULL
2443 && strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0);
2444 sec = bfd_get_section_by_name (abfd, name + sizeof ".gptab" - 1);
2445 BFD_ASSERT (sec != NULL);
2446 (*hdrpp)->sh_info = elf_section_data (sec)->this_idx;
2449 case SHT_MIPS_CONTENT:
2450 BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
2451 name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section);
2452 BFD_ASSERT (name != NULL
2453 && strncmp (name, ".MIPS.content",
2454 sizeof ".MIPS.content" - 1) == 0);
2455 sec = bfd_get_section_by_name (abfd,
2456 name + sizeof ".MIPS.content" - 1);
2457 BFD_ASSERT (sec != NULL);
2458 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx;
2461 case SHT_MIPS_SYMBOL_LIB:
2462 sec = bfd_get_section_by_name (abfd, ".dynsym");
2464 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx;
2465 sec = bfd_get_section_by_name (abfd, ".liblist");
2467 (*hdrpp)->sh_info = elf_section_data (sec)->this_idx;
2470 case SHT_MIPS_EVENTS:
2471 BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
2472 name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section);
2473 BFD_ASSERT (name != NULL);
2474 if (strncmp (name, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
2475 sec = bfd_get_section_by_name (abfd,
2476 name + sizeof ".MIPS.events" - 1);
2479 BFD_ASSERT (strncmp (name, ".MIPS.post_rel",
2480 sizeof ".MIPS.post_rel" - 1) == 0);
2481 sec = bfd_get_section_by_name (abfd,
2483 + sizeof ".MIPS.post_rel" - 1));
2485 BFD_ASSERT (sec != NULL);
2486 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx;
2493 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
2496 _bfd_mips_elf_set_private_flags (abfd, flags)
2500 BFD_ASSERT (!elf_flags_init (abfd)
2501 || elf_elfheader (abfd)->e_flags == flags);
2503 elf_elfheader (abfd)->e_flags = flags;
2504 elf_flags_init (abfd) = true;
2508 /* Copy backend specific data from one object module to another */
2511 _bfd_mips_elf_copy_private_bfd_data (ibfd, obfd)
2515 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
2516 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
2519 BFD_ASSERT (!elf_flags_init (obfd)
2520 || (elf_elfheader (obfd)->e_flags
2521 == elf_elfheader (ibfd)->e_flags));
2523 elf_gp (obfd) = elf_gp (ibfd);
2524 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
2525 elf_flags_init (obfd) = true;
2529 /* Merge backend specific data from an object file to the output
2530 object file when linking. */
2533 _bfd_mips_elf_merge_private_bfd_data (ibfd, obfd)
2540 boolean null_input_bfd = true;
2543 /* Check if we have the same endianess */
2544 if (_bfd_generic_verify_endian_match (ibfd, obfd) == false)
2547 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
2548 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
2551 new_flags = elf_elfheader (ibfd)->e_flags;
2552 elf_elfheader (obfd)->e_flags |= new_flags & EF_MIPS_NOREORDER;
2553 old_flags = elf_elfheader (obfd)->e_flags;
2555 if (! elf_flags_init (obfd))
2557 elf_flags_init (obfd) = true;
2558 elf_elfheader (obfd)->e_flags = new_flags;
2559 elf_elfheader (obfd)->e_ident[EI_CLASS]
2560 = elf_elfheader (ibfd)->e_ident[EI_CLASS];
2562 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
2563 && bfd_get_arch_info (obfd)->the_default)
2565 if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
2566 bfd_get_mach (ibfd)))
2573 /* Check flag compatibility. */
2575 new_flags &= ~EF_MIPS_NOREORDER;
2576 old_flags &= ~EF_MIPS_NOREORDER;
2578 if (new_flags == old_flags)
2581 /* Check to see if the input BFD actually contains any sections.
2582 If not, its flags may not have been initialised either, but it cannot
2583 actually cause any incompatibility. */
2584 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
2586 /* Ignore synthetic sections and empty .text, .data and .bss sections
2587 which are automatically generated by gas. */
2588 if (strcmp (sec->name, ".reginfo")
2589 && strcmp (sec->name, ".mdebug")
2590 && ((!strcmp (sec->name, ".text")
2591 || !strcmp (sec->name, ".data")
2592 || !strcmp (sec->name, ".bss"))
2593 && sec->_raw_size != 0))
2595 null_input_bfd = false;
2604 if ((new_flags & EF_MIPS_PIC) != (old_flags & EF_MIPS_PIC))
2606 new_flags &= ~EF_MIPS_PIC;
2607 old_flags &= ~EF_MIPS_PIC;
2608 (*_bfd_error_handler)
2609 (_("%s: linking PIC files with non-PIC files"),
2610 bfd_archive_filename (ibfd));
2614 if ((new_flags & EF_MIPS_CPIC) != (old_flags & EF_MIPS_CPIC))
2616 new_flags &= ~EF_MIPS_CPIC;
2617 old_flags &= ~EF_MIPS_CPIC;
2618 (*_bfd_error_handler)
2619 (_("%s: linking abicalls files with non-abicalls files"),
2620 bfd_archive_filename (ibfd));
2624 /* Compare the ISA's. */
2625 if ((new_flags & (EF_MIPS_ARCH | EF_MIPS_MACH))
2626 != (old_flags & (EF_MIPS_ARCH | EF_MIPS_MACH)))
2628 int new_mach = new_flags & EF_MIPS_MACH;
2629 int old_mach = old_flags & EF_MIPS_MACH;
2630 int new_isa = elf_mips_isa (new_flags);
2631 int old_isa = elf_mips_isa (old_flags);
2633 /* If either has no machine specified, just compare the general isa's.
2634 Some combinations of machines are ok, if the isa's match. */
2637 || new_mach == old_mach
2640 /* Don't warn about mixing code using 32-bit ISAs, or mixing code
2641 using 64-bit ISAs. They will normally use the same data sizes
2642 and calling conventions. */
2644 if (( (new_isa == 1 || new_isa == 2 || new_isa == 32)
2645 ^ (old_isa == 1 || old_isa == 2 || old_isa == 32)) != 0)
2647 (*_bfd_error_handler)
2648 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
2649 bfd_archive_filename (ibfd), new_isa, old_isa);
2656 (*_bfd_error_handler)
2657 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
2658 bfd_archive_filename (ibfd),
2659 elf_mips_mach (new_flags),
2660 elf_mips_mach (old_flags));
2664 new_flags &= ~(EF_MIPS_ARCH | EF_MIPS_MACH);
2665 old_flags &= ~(EF_MIPS_ARCH | EF_MIPS_MACH);
2668 /* Compare ABI's. The 64-bit ABI does not use EF_MIPS_ABI. But, it
2669 does set EI_CLASS differently from any 32-bit ABI. */
2670 if ((new_flags & EF_MIPS_ABI) != (old_flags & EF_MIPS_ABI)
2671 || (elf_elfheader (ibfd)->e_ident[EI_CLASS]
2672 != elf_elfheader (obfd)->e_ident[EI_CLASS]))
2674 /* Only error if both are set (to different values). */
2675 if (((new_flags & EF_MIPS_ABI) && (old_flags & EF_MIPS_ABI))
2676 || (elf_elfheader (ibfd)->e_ident[EI_CLASS]
2677 != elf_elfheader (obfd)->e_ident[EI_CLASS]))
2679 (*_bfd_error_handler)
2680 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
2681 bfd_archive_filename (ibfd),
2682 elf_mips_abi_name (ibfd),
2683 elf_mips_abi_name (obfd));
2686 new_flags &= ~EF_MIPS_ABI;
2687 old_flags &= ~EF_MIPS_ABI;
2690 /* Warn about any other mismatches */
2691 if (new_flags != old_flags)
2693 (*_bfd_error_handler)
2694 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2695 bfd_archive_filename (ibfd), (unsigned long) new_flags,
2696 (unsigned long) old_flags);
2702 bfd_set_error (bfd_error_bad_value);
2710 _bfd_mips_elf_print_private_bfd_data (abfd, ptr)
2714 FILE *file = (FILE *) ptr;
2716 BFD_ASSERT (abfd != NULL && ptr != NULL);
2718 /* Print normal ELF private data. */
2719 _bfd_elf_print_private_bfd_data (abfd, ptr);
2721 /* xgettext:c-format */
2722 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
2724 if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_O32)
2725 fprintf (file, _(" [abi=O32]"));
2726 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_O64)
2727 fprintf (file, _(" [abi=O64]"));
2728 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI32)
2729 fprintf (file, _(" [abi=EABI32]"));
2730 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64)
2731 fprintf (file, _(" [abi=EABI64]"));
2732 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI))
2733 fprintf (file, _(" [abi unknown]"));
2734 else if (ABI_N32_P (abfd))
2735 fprintf (file, _(" [abi=N32]"));
2736 else if (ABI_64_P (abfd))
2737 fprintf (file, _(" [abi=64]"));
2739 fprintf (file, _(" [no abi set]"));
2741 if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1)
2742 fprintf (file, _(" [mips1]"));
2743 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2)
2744 fprintf (file, _(" [mips2]"));
2745 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3)
2746 fprintf (file, _(" [mips3]"));
2747 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4)
2748 fprintf (file, _(" [mips4]"));
2749 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_5)
2750 fprintf (file, _ (" [mips5]"));
2751 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_32)
2752 fprintf (file, _ (" [mips32]"));
2753 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_64)
2754 fprintf (file, _ (" [mips64]"));
2756 fprintf (file, _(" [unknown ISA]"));
2758 if (elf_elfheader (abfd)->e_flags & EF_MIPS_32BITMODE)
2759 fprintf (file, _(" [32bitmode]"));
2761 fprintf (file, _(" [not 32bitmode]"));
2768 /* Handle a MIPS specific section when reading an object file. This
2769 is called when elfcode.h finds a section with an unknown type.
2770 This routine supports both the 32-bit and 64-bit ELF ABI.
2772 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2776 _bfd_mips_elf_section_from_shdr (abfd, hdr, name)
2778 Elf_Internal_Shdr *hdr;
2783 /* There ought to be a place to keep ELF backend specific flags, but
2784 at the moment there isn't one. We just keep track of the
2785 sections by their name, instead. Fortunately, the ABI gives
2786 suggested names for all the MIPS specific sections, so we will
2787 probably get away with this. */
2788 switch (hdr->sh_type)
2790 case SHT_MIPS_LIBLIST:
2791 if (strcmp (name, ".liblist") != 0)
2795 if (strcmp (name, MIPS_ELF_MSYM_SECTION_NAME (abfd)) != 0)
2798 case SHT_MIPS_CONFLICT:
2799 if (strcmp (name, ".conflict") != 0)
2802 case SHT_MIPS_GPTAB:
2803 if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) != 0)
2806 case SHT_MIPS_UCODE:
2807 if (strcmp (name, ".ucode") != 0)
2810 case SHT_MIPS_DEBUG:
2811 if (strcmp (name, ".mdebug") != 0)
2813 flags = SEC_DEBUGGING;
2815 case SHT_MIPS_REGINFO:
2816 if (strcmp (name, ".reginfo") != 0
2817 || hdr->sh_size != sizeof (Elf32_External_RegInfo))
2819 flags = (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_SIZE);
2821 case SHT_MIPS_IFACE:
2822 if (strcmp (name, ".MIPS.interfaces") != 0)
2825 case SHT_MIPS_CONTENT:
2826 if (strncmp (name, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2829 case SHT_MIPS_OPTIONS:
2830 if (strcmp (name, MIPS_ELF_OPTIONS_SECTION_NAME (abfd)) != 0)
2833 case SHT_MIPS_DWARF:
2834 if (strncmp (name, ".debug_", sizeof ".debug_" - 1) != 0)
2837 case SHT_MIPS_SYMBOL_LIB:
2838 if (strcmp (name, ".MIPS.symlib") != 0)
2841 case SHT_MIPS_EVENTS:
2842 if (strncmp (name, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2843 && strncmp (name, ".MIPS.post_rel",
2844 sizeof ".MIPS.post_rel" - 1) != 0)
2851 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
2856 if (! bfd_set_section_flags (abfd, hdr->bfd_section,
2857 (bfd_get_section_flags (abfd,
2863 /* FIXME: We should record sh_info for a .gptab section. */
2865 /* For a .reginfo section, set the gp value in the tdata information
2866 from the contents of this section. We need the gp value while
2867 processing relocs, so we just get it now. The .reginfo section
2868 is not used in the 64-bit MIPS ELF ABI. */
2869 if (hdr->sh_type == SHT_MIPS_REGINFO)
2871 Elf32_External_RegInfo ext;
2874 if (! bfd_get_section_contents (abfd, hdr->bfd_section, (PTR) &ext,
2876 (bfd_size_type) sizeof ext))
2878 bfd_mips_elf32_swap_reginfo_in (abfd, &ext, &s);
2879 elf_gp (abfd) = s.ri_gp_value;
2882 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2883 set the gp value based on what we find. We may see both
2884 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2885 they should agree. */
2886 if (hdr->sh_type == SHT_MIPS_OPTIONS)
2888 bfd_byte *contents, *l, *lend;
2890 contents = (bfd_byte *) bfd_malloc (hdr->sh_size);
2891 if (contents == NULL)
2893 if (! bfd_get_section_contents (abfd, hdr->bfd_section, contents,
2894 (file_ptr) 0, hdr->sh_size))
2900 lend = contents + hdr->sh_size;
2901 while (l + sizeof (Elf_External_Options) <= lend)
2903 Elf_Internal_Options intopt;
2905 bfd_mips_elf_swap_options_in (abfd, (Elf_External_Options *) l,
2907 if (ABI_64_P (abfd) && intopt.kind == ODK_REGINFO)
2909 Elf64_Internal_RegInfo intreg;
2911 bfd_mips_elf64_swap_reginfo_in
2913 ((Elf64_External_RegInfo *)
2914 (l + sizeof (Elf_External_Options))),
2916 elf_gp (abfd) = intreg.ri_gp_value;
2918 else if (intopt.kind == ODK_REGINFO)
2920 Elf32_RegInfo intreg;
2922 bfd_mips_elf32_swap_reginfo_in
2924 ((Elf32_External_RegInfo *)
2925 (l + sizeof (Elf_External_Options))),
2927 elf_gp (abfd) = intreg.ri_gp_value;
2937 /* Set the correct type for a MIPS ELF section. We do this by the
2938 section name, which is a hack, but ought to work. This routine is
2939 used by both the 32-bit and the 64-bit ABI. */
2942 _bfd_mips_elf_fake_sections (abfd, hdr, sec)
2944 Elf32_Internal_Shdr *hdr;
2947 register const char *name;
2949 name = bfd_get_section_name (abfd, sec);
2951 if (strcmp (name, ".liblist") == 0)
2953 hdr->sh_type = SHT_MIPS_LIBLIST;
2954 hdr->sh_info = sec->_raw_size / sizeof (Elf32_Lib);
2955 /* The sh_link field is set in final_write_processing. */
2957 else if (strcmp (name, ".conflict") == 0)
2958 hdr->sh_type = SHT_MIPS_CONFLICT;
2959 else if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0)
2961 hdr->sh_type = SHT_MIPS_GPTAB;
2962 hdr->sh_entsize = sizeof (Elf32_External_gptab);
2963 /* The sh_info field is set in final_write_processing. */
2965 else if (strcmp (name, ".ucode") == 0)
2966 hdr->sh_type = SHT_MIPS_UCODE;
2967 else if (strcmp (name, ".mdebug") == 0)
2969 hdr->sh_type = SHT_MIPS_DEBUG;
2970 /* In a shared object on Irix 5.3, the .mdebug section has an
2971 entsize of 0. FIXME: Does this matter? */
2972 if (SGI_COMPAT (abfd) && (abfd->flags & DYNAMIC) != 0)
2973 hdr->sh_entsize = 0;
2975 hdr->sh_entsize = 1;
2977 else if (strcmp (name, ".reginfo") == 0)
2979 hdr->sh_type = SHT_MIPS_REGINFO;
2980 /* In a shared object on Irix 5.3, the .reginfo section has an
2981 entsize of 0x18. FIXME: Does this matter? */
2982 if (SGI_COMPAT (abfd))
2984 if ((abfd->flags & DYNAMIC) != 0)
2985 hdr->sh_entsize = sizeof (Elf32_External_RegInfo);
2987 hdr->sh_entsize = 1;
2990 hdr->sh_entsize = sizeof (Elf32_External_RegInfo);
2992 else if (SGI_COMPAT (abfd)
2993 && (strcmp (name, ".hash") == 0
2994 || strcmp (name, ".dynamic") == 0
2995 || strcmp (name, ".dynstr") == 0))
2997 if (SGI_COMPAT (abfd))
2998 hdr->sh_entsize = 0;
3000 /* This isn't how the Irix 6 linker behaves. */
3001 hdr->sh_info = SIZEOF_MIPS_DYNSYM_SECNAMES;
3004 else if (strcmp (name, ".got") == 0
3005 || strcmp (name, MIPS_ELF_SRDATA_SECTION_NAME (abfd)) == 0
3006 || strcmp (name, ".sdata") == 0
3007 || strcmp (name, ".sbss") == 0
3008 || strcmp (name, ".lit4") == 0
3009 || strcmp (name, ".lit8") == 0)
3010 hdr->sh_flags |= SHF_MIPS_GPREL;
3011 else if (strcmp (name, ".MIPS.interfaces") == 0)
3013 hdr->sh_type = SHT_MIPS_IFACE;
3014 hdr->sh_flags |= SHF_MIPS_NOSTRIP;
3016 else if (strncmp (name, ".MIPS.content", strlen (".MIPS.content")) == 0)
3018 hdr->sh_type = SHT_MIPS_CONTENT;
3019 hdr->sh_flags |= SHF_MIPS_NOSTRIP;
3020 /* The sh_info field is set in final_write_processing. */
3022 else if (strcmp (name, MIPS_ELF_OPTIONS_SECTION_NAME (abfd)) == 0)
3024 hdr->sh_type = SHT_MIPS_OPTIONS;
3025 hdr->sh_entsize = 1;
3026 hdr->sh_flags |= SHF_MIPS_NOSTRIP;
3028 else if (strncmp (name, ".debug_", sizeof ".debug_" - 1) == 0)
3029 hdr->sh_type = SHT_MIPS_DWARF;
3030 else if (strcmp (name, ".MIPS.symlib") == 0)
3032 hdr->sh_type = SHT_MIPS_SYMBOL_LIB;
3033 /* The sh_link and sh_info fields are set in
3034 final_write_processing. */
3036 else if (strncmp (name, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
3037 || strncmp (name, ".MIPS.post_rel",
3038 sizeof ".MIPS.post_rel" - 1) == 0)
3040 hdr->sh_type = SHT_MIPS_EVENTS;
3041 hdr->sh_flags |= SHF_MIPS_NOSTRIP;
3042 /* The sh_link field is set in final_write_processing. */
3044 else if (strcmp (name, MIPS_ELF_MSYM_SECTION_NAME (abfd)) == 0)
3046 hdr->sh_type = SHT_MIPS_MSYM;
3047 hdr->sh_flags |= SHF_ALLOC;
3048 hdr->sh_entsize = 8;
3051 /* The generic elf_fake_sections will set up REL_HDR using the
3052 default kind of relocations. But, we may actually need both
3053 kinds of relocations, so we set up the second header here. */
3054 if ((sec->flags & SEC_RELOC) != 0)
3056 struct bfd_elf_section_data *esd;
3057 bfd_size_type amt = sizeof (Elf_Internal_Shdr);
3059 esd = elf_section_data (sec);
3060 BFD_ASSERT (esd->rel_hdr2 == NULL);
3061 esd->rel_hdr2 = (Elf_Internal_Shdr *) bfd_zalloc (abfd, amt);
3064 _bfd_elf_init_reloc_shdr (abfd, esd->rel_hdr2, sec,
3065 !elf_section_data (sec)->use_rela_p);
3071 /* Given a BFD section, try to locate the corresponding ELF section
3072 index. This is used by both the 32-bit and the 64-bit ABI.
3073 Actually, it's not clear to me that the 64-bit ABI supports these,
3074 but for non-PIC objects we will certainly want support for at least
3075 the .scommon section. */
3078 _bfd_mips_elf_section_from_bfd_section (abfd, hdr, sec, retval)
3079 bfd *abfd ATTRIBUTE_UNUSED;
3080 Elf_Internal_Shdr *hdr ATTRIBUTE_UNUSED;
3084 if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)
3086 *retval = SHN_MIPS_SCOMMON;
3089 if (strcmp (bfd_get_section_name (abfd, sec), ".acommon") == 0)
3091 *retval = SHN_MIPS_ACOMMON;
3097 /* When are writing out the .options or .MIPS.options section,
3098 remember the bytes we are writing out, so that we can install the
3099 GP value in the section_processing routine. */
3102 _bfd_mips_elf_set_section_contents (abfd, section, location, offset, count)
3107 bfd_size_type count;
3109 if (strcmp (section->name, MIPS_ELF_OPTIONS_SECTION_NAME (abfd)) == 0)
3113 if (elf_section_data (section) == NULL)
3115 bfd_size_type amt = sizeof (struct bfd_elf_section_data);
3116 section->used_by_bfd = (PTR) bfd_zalloc (abfd, amt);
3117 if (elf_section_data (section) == NULL)
3120 c = (bfd_byte *) elf_section_data (section)->tdata;
3125 if (section->_cooked_size != 0)
3126 size = section->_cooked_size;
3128 size = section->_raw_size;
3129 c = (bfd_byte *) bfd_zalloc (abfd, size);
3132 elf_section_data (section)->tdata = (PTR) c;
3135 memcpy (c + offset, location, (size_t) count);
3138 return _bfd_elf_set_section_contents (abfd, section, location, offset,
3142 /* Work over a section just before writing it out. This routine is
3143 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
3144 sections that need the SHF_MIPS_GPREL flag by name; there has to be
3148 _bfd_mips_elf_section_processing (abfd, hdr)
3150 Elf_Internal_Shdr *hdr;
3152 if (hdr->sh_type == SHT_MIPS_REGINFO
3153 && hdr->sh_size > 0)
3157 BFD_ASSERT (hdr->sh_size == sizeof (Elf32_External_RegInfo));
3158 BFD_ASSERT (hdr->contents == NULL);
3161 hdr->sh_offset + sizeof (Elf32_External_RegInfo) - 4,
3164 H_PUT_32 (abfd, elf_gp (abfd), buf);
3165 if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
3169 if (hdr->sh_type == SHT_MIPS_OPTIONS
3170 && hdr->bfd_section != NULL
3171 && elf_section_data (hdr->bfd_section) != NULL
3172 && elf_section_data (hdr->bfd_section)->tdata != NULL)
3174 bfd_byte *contents, *l, *lend;
3176 /* We stored the section contents in the elf_section_data tdata
3177 field in the set_section_contents routine. We save the
3178 section contents so that we don't have to read them again.
3179 At this point we know that elf_gp is set, so we can look
3180 through the section contents to see if there is an
3181 ODK_REGINFO structure. */
3183 contents = (bfd_byte *) elf_section_data (hdr->bfd_section)->tdata;
3185 lend = contents + hdr->sh_size;
3186 while (l + sizeof (Elf_External_Options) <= lend)
3188 Elf_Internal_Options intopt;
3190 bfd_mips_elf_swap_options_in (abfd, (Elf_External_Options *) l,
3192 if (ABI_64_P (abfd) && intopt.kind == ODK_REGINFO)
3199 + sizeof (Elf_External_Options)
3200 + (sizeof (Elf64_External_RegInfo) - 8)),
3203 H_PUT_64 (abfd, elf_gp (abfd), buf);
3204 if (bfd_bwrite (buf, (bfd_size_type) 8, abfd) != 8)
3207 else if (intopt.kind == ODK_REGINFO)
3214 + sizeof (Elf_External_Options)
3215 + (sizeof (Elf32_External_RegInfo) - 4)),
3218 H_PUT_32 (abfd, elf_gp (abfd), buf);
3219 if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
3226 if (hdr->bfd_section != NULL)
3228 const char *name = bfd_get_section_name (abfd, hdr->bfd_section);
3230 if (strcmp (name, ".sdata") == 0
3231 || strcmp (name, ".lit8") == 0
3232 || strcmp (name, ".lit4") == 0)
3234 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
3235 hdr->sh_type = SHT_PROGBITS;
3237 else if (strcmp (name, ".sbss") == 0)
3239 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
3240 hdr->sh_type = SHT_NOBITS;
3242 else if (strcmp (name, MIPS_ELF_SRDATA_SECTION_NAME (abfd)) == 0)
3244 hdr->sh_flags |= SHF_ALLOC | SHF_MIPS_GPREL;
3245 hdr->sh_type = SHT_PROGBITS;
3247 else if (strcmp (name, ".compact_rel") == 0)
3250 hdr->sh_type = SHT_PROGBITS;
3252 else if (strcmp (name, ".rtproc") == 0)
3254 if (hdr->sh_addralign != 0 && hdr->sh_entsize == 0)
3256 unsigned int adjust;
3258 adjust = hdr->sh_size % hdr->sh_addralign;
3260 hdr->sh_size += hdr->sh_addralign - adjust;
3268 /* MIPS ELF uses two common sections. One is the usual one, and the
3269 other is for small objects. All the small objects are kept
3270 together, and then referenced via the gp pointer, which yields
3271 faster assembler code. This is what we use for the small common
3272 section. This approach is copied from ecoff.c. */
3273 static asection mips_elf_scom_section;
3274 static asymbol mips_elf_scom_symbol;
3275 static asymbol *mips_elf_scom_symbol_ptr;
3277 /* MIPS ELF also uses an acommon section, which represents an
3278 allocated common symbol which may be overridden by a
3279 definition in a shared library. */
3280 static asection mips_elf_acom_section;
3281 static asymbol mips_elf_acom_symbol;
3282 static asymbol *mips_elf_acom_symbol_ptr;
3284 /* Handle the special MIPS section numbers that a symbol may use.
3285 This is used for both the 32-bit and the 64-bit ABI. */
3288 _bfd_mips_elf_symbol_processing (abfd, asym)
3292 elf_symbol_type *elfsym;
3294 elfsym = (elf_symbol_type *) asym;
3295 switch (elfsym->internal_elf_sym.st_shndx)
3297 case SHN_MIPS_ACOMMON:
3298 /* This section is used in a dynamically linked executable file.
3299 It is an allocated common section. The dynamic linker can
3300 either resolve these symbols to something in a shared
3301 library, or it can just leave them here. For our purposes,
3302 we can consider these symbols to be in a new section. */
3303 if (mips_elf_acom_section.name == NULL)
3305 /* Initialize the acommon section. */
3306 mips_elf_acom_section.name = ".acommon";
3307 mips_elf_acom_section.flags = SEC_ALLOC;
3308 mips_elf_acom_section.output_section = &mips_elf_acom_section;
3309 mips_elf_acom_section.symbol = &mips_elf_acom_symbol;
3310 mips_elf_acom_section.symbol_ptr_ptr = &mips_elf_acom_symbol_ptr;
3311 mips_elf_acom_symbol.name = ".acommon";
3312 mips_elf_acom_symbol.flags = BSF_SECTION_SYM;
3313 mips_elf_acom_symbol.section = &mips_elf_acom_section;
3314 mips_elf_acom_symbol_ptr = &mips_elf_acom_symbol;
3316 asym->section = &mips_elf_acom_section;
3320 /* Common symbols less than the GP size are automatically
3321 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
3322 if (asym->value > elf_gp_size (abfd)
3323 || IRIX_COMPAT (abfd) == ict_irix6)
3326 case SHN_MIPS_SCOMMON:
3327 if (mips_elf_scom_section.name == NULL)
3329 /* Initialize the small common section. */
3330 mips_elf_scom_section.name = ".scommon";
3331 mips_elf_scom_section.flags = SEC_IS_COMMON;
3332 mips_elf_scom_section.output_section = &mips_elf_scom_section;
3333 mips_elf_scom_section.symbol = &mips_elf_scom_symbol;
3334 mips_elf_scom_section.symbol_ptr_ptr = &mips_elf_scom_symbol_ptr;
3335 mips_elf_scom_symbol.name = ".scommon";
3336 mips_elf_scom_symbol.flags = BSF_SECTION_SYM;
3337 mips_elf_scom_symbol.section = &mips_elf_scom_section;
3338 mips_elf_scom_symbol_ptr = &mips_elf_scom_symbol;
3340 asym->section = &mips_elf_scom_section;
3341 asym->value = elfsym->internal_elf_sym.st_size;
3344 case SHN_MIPS_SUNDEFINED:
3345 asym->section = bfd_und_section_ptr;
3348 #if 0 /* for SGI_COMPAT */
3350 asym->section = mips_elf_text_section_ptr;
3354 asym->section = mips_elf_data_section_ptr;
3360 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
3364 _bfd_mips_elf_additional_program_headers (abfd)
3370 /* See if we need a PT_MIPS_REGINFO segment. */
3371 s = bfd_get_section_by_name (abfd, ".reginfo");
3372 if (s && (s->flags & SEC_LOAD))
3375 /* See if we need a PT_MIPS_OPTIONS segment. */
3376 if (IRIX_COMPAT (abfd) == ict_irix6
3377 && bfd_get_section_by_name (abfd,
3378 MIPS_ELF_OPTIONS_SECTION_NAME (abfd)))
3381 /* See if we need a PT_MIPS_RTPROC segment. */
3382 if (IRIX_COMPAT (abfd) == ict_irix5
3383 && bfd_get_section_by_name (abfd, ".dynamic")
3384 && bfd_get_section_by_name (abfd, ".mdebug"))
3390 /* Modify the segment map for an Irix 5 executable. */
3393 _bfd_mips_elf_modify_segment_map (abfd)
3397 struct elf_segment_map *m, **pm;
3400 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
3402 s = bfd_get_section_by_name (abfd, ".reginfo");
3403 if (s != NULL && (s->flags & SEC_LOAD) != 0)
3405 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
3406 if (m->p_type == PT_MIPS_REGINFO)
3411 m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
3415 m->p_type = PT_MIPS_REGINFO;
3419 /* We want to put it after the PHDR and INTERP segments. */
3420 pm = &elf_tdata (abfd)->segment_map;
3422 && ((*pm)->p_type == PT_PHDR
3423 || (*pm)->p_type == PT_INTERP))
3431 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
3432 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
3433 PT_OPTIONS segement immediately following the program header
3435 if (IRIX_COMPAT (abfd) == ict_irix6)
3437 for (s = abfd->sections; s; s = s->next)
3438 if (elf_section_data (s)->this_hdr.sh_type == SHT_MIPS_OPTIONS)
3443 struct elf_segment_map *options_segment;
3445 /* Usually, there's a program header table. But, sometimes
3446 there's not (like when running the `ld' testsuite). So,
3447 if there's no program header table, we just put the
3448 options segement at the end. */
3449 for (pm = &elf_tdata (abfd)->segment_map;
3452 if ((*pm)->p_type == PT_PHDR)
3455 amt = sizeof (struct elf_segment_map);
3456 options_segment = bfd_zalloc (abfd, amt);
3457 options_segment->next = *pm;
3458 options_segment->p_type = PT_MIPS_OPTIONS;
3459 options_segment->p_flags = PF_R;
3460 options_segment->p_flags_valid = true;
3461 options_segment->count = 1;
3462 options_segment->sections[0] = s;
3463 *pm = options_segment;
3468 if (IRIX_COMPAT (abfd) == ict_irix5)
3470 /* If there are .dynamic and .mdebug sections, we make a room
3471 for the RTPROC header. FIXME: Rewrite without section names. */
3472 if (bfd_get_section_by_name (abfd, ".interp") == NULL
3473 && bfd_get_section_by_name (abfd, ".dynamic") != NULL
3474 && bfd_get_section_by_name (abfd, ".mdebug") != NULL)
3476 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
3477 if (m->p_type == PT_MIPS_RTPROC)
3482 m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
3486 m->p_type = PT_MIPS_RTPROC;
3488 s = bfd_get_section_by_name (abfd, ".rtproc");
3493 m->p_flags_valid = 1;
3501 /* We want to put it after the DYNAMIC segment. */
3502 pm = &elf_tdata (abfd)->segment_map;
3503 while (*pm != NULL && (*pm)->p_type != PT_DYNAMIC)
3513 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic,
3514 .dynstr, .dynsym, and .hash sections, and everything in
3516 for (pm = &elf_tdata (abfd)->segment_map; *pm != NULL;
3518 if ((*pm)->p_type == PT_DYNAMIC)
3521 if (m != NULL && IRIX_COMPAT (abfd) == ict_none)
3523 /* For a normal mips executable the permissions for the PT_DYNAMIC
3524 segment are read, write and execute. We do that here since
3525 the code in elf.c sets only the read permission. This matters
3526 sometimes for the dynamic linker. */
3527 if (bfd_get_section_by_name (abfd, ".dynamic") != NULL)
3529 m->p_flags = PF_R | PF_W | PF_X;
3530 m->p_flags_valid = 1;
3534 && m->count == 1 && strcmp (m->sections[0]->name, ".dynamic") == 0)
3536 static const char *sec_names[] =
3538 ".dynamic", ".dynstr", ".dynsym", ".hash"
3542 struct elf_segment_map *n;
3546 for (i = 0; i < sizeof sec_names / sizeof sec_names[0]; i++)
3548 s = bfd_get_section_by_name (abfd, sec_names[i]);
3549 if (s != NULL && (s->flags & SEC_LOAD) != 0)
3555 sz = s->_cooked_size;
3558 if (high < s->vma + sz)
3564 for (s = abfd->sections; s != NULL; s = s->next)
3565 if ((s->flags & SEC_LOAD) != 0
3568 + (s->_cooked_size !=
3569 0 ? s->_cooked_size : s->_raw_size)) <= high))
3572 amt = sizeof *n + (bfd_size_type) (c - 1) * sizeof (asection *);
3573 n = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
3580 for (s = abfd->sections; s != NULL; s = s->next)
3582 if ((s->flags & SEC_LOAD) != 0
3585 + (s->_cooked_size != 0 ?
3586 s->_cooked_size : s->_raw_size)) <= high))
3600 /* The structure of the runtime procedure descriptor created by the
3601 loader for use by the static exception system. */
3603 typedef struct runtime_pdr {
3604 bfd_vma adr; /* memory address of start of procedure */
3605 long regmask; /* save register mask */
3606 long regoffset; /* save register offset */
3607 long fregmask; /* save floating point register mask */
3608 long fregoffset; /* save floating point register offset */
3609 long frameoffset; /* frame size */
3610 short framereg; /* frame pointer register */
3611 short pcreg; /* offset or reg of return pc */
3612 long irpss; /* index into the runtime string table */
3614 struct exception_info *exception_info;/* pointer to exception array */
3616 #define cbRPDR sizeof (RPDR)
3617 #define rpdNil ((pRPDR) 0)
3619 /* Swap RPDR (runtime procedure table entry) for output. */
3621 static void ecoff_swap_rpdr_out
3622 PARAMS ((bfd *, const RPDR *, struct rpdr_ext *));
3625 ecoff_swap_rpdr_out (abfd, in, ex)
3628 struct rpdr_ext *ex;
3630 /* ECOFF_PUT_OFF was defined in ecoffswap.h. */
3631 ECOFF_PUT_OFF (abfd, in->adr, ex->p_adr);
3632 H_PUT_32 (abfd, in->regmask, ex->p_regmask);
3633 H_PUT_32 (abfd, in->regoffset, ex->p_regoffset);
3634 H_PUT_32 (abfd, in->fregmask, ex->p_fregmask);
3635 H_PUT_32 (abfd, in->fregoffset, ex->p_fregoffset);
3636 H_PUT_32 (abfd, in->frameoffset, ex->p_frameoffset);
3638 H_PUT_16 (abfd, in->framereg, ex->p_framereg);
3639 H_PUT_16 (abfd, in->pcreg, ex->p_pcreg);
3641 H_PUT_32 (abfd, in->irpss, ex->p_irpss);
3643 ECOFF_PUT_OFF (abfd, in->exception_info, ex->p_exception_info);
3647 /* Read ECOFF debugging information from a .mdebug section into a
3648 ecoff_debug_info structure. */
3651 _bfd_mips_elf_read_ecoff_info (abfd, section, debug)
3654 struct ecoff_debug_info *debug;
3657 const struct ecoff_debug_swap *swap;
3658 char *ext_hdr = NULL;
3660 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
3661 memset (debug, 0, sizeof (*debug));
3663 ext_hdr = (char *) bfd_malloc (swap->external_hdr_size);
3664 if (ext_hdr == NULL && swap->external_hdr_size != 0)
3667 if (bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0,
3668 swap->external_hdr_size)
3672 symhdr = &debug->symbolic_header;
3673 (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr);
3675 /* The symbolic header contains absolute file offsets and sizes to
3677 #define READ(ptr, offset, count, size, type) \
3678 if (symhdr->count == 0) \
3679 debug->ptr = NULL; \
3682 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
3683 debug->ptr = (type) bfd_malloc (amt); \
3684 if (debug->ptr == NULL) \
3685 goto error_return; \
3686 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3687 || bfd_bread (debug->ptr, amt, abfd) != amt) \
3688 goto error_return; \
3691 READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *);
3692 READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR);
3693 READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR);
3694 READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR);
3695 READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR);
3696 READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext),
3698 READ (ss, cbSsOffset, issMax, sizeof (char), char *);
3699 READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *);
3700 READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR);
3701 READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR);
3702 READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR);
3706 debug->adjust = NULL;
3711 if (ext_hdr != NULL)
3713 if (debug->line != NULL)
3715 if (debug->external_dnr != NULL)
3716 free (debug->external_dnr);
3717 if (debug->external_pdr != NULL)
3718 free (debug->external_pdr);
3719 if (debug->external_sym != NULL)
3720 free (debug->external_sym);
3721 if (debug->external_opt != NULL)
3722 free (debug->external_opt);
3723 if (debug->external_aux != NULL)
3724 free (debug->external_aux);
3725 if (debug->ss != NULL)
3727 if (debug->ssext != NULL)
3728 free (debug->ssext);
3729 if (debug->external_fdr != NULL)
3730 free (debug->external_fdr);
3731 if (debug->external_rfd != NULL)
3732 free (debug->external_rfd);
3733 if (debug->external_ext != NULL)
3734 free (debug->external_ext);
3738 /* MIPS ELF local labels start with '$', not 'L'. */
3741 mips_elf_is_local_label_name (abfd, name)
3748 /* On Irix 6, the labels go back to starting with '.', so we accept
3749 the generic ELF local label syntax as well. */
3750 return _bfd_elf_is_local_label_name (abfd, name);
3753 /* MIPS ELF uses a special find_nearest_line routine in order the
3754 handle the ECOFF debugging information. */
3756 struct mips_elf_find_line
3758 struct ecoff_debug_info d;
3759 struct ecoff_find_line i;
3763 _bfd_mips_elf_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
3764 functionname_ptr, line_ptr)
3769 const char **filename_ptr;
3770 const char **functionname_ptr;
3771 unsigned int *line_ptr;
3775 if (_bfd_dwarf1_find_nearest_line (abfd, section, symbols, offset,
3776 filename_ptr, functionname_ptr,
3780 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
3781 filename_ptr, functionname_ptr,
3783 (unsigned) (ABI_64_P (abfd) ? 8 : 0),
3784 &elf_tdata (abfd)->dwarf2_find_line_info))
3787 msec = bfd_get_section_by_name (abfd, ".mdebug");
3791 struct mips_elf_find_line *fi;
3792 const struct ecoff_debug_swap * const swap =
3793 get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
3795 /* If we are called during a link, mips_elf_final_link may have
3796 cleared the SEC_HAS_CONTENTS field. We force it back on here
3797 if appropriate (which it normally will be). */
3798 origflags = msec->flags;
3799 if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS)
3800 msec->flags |= SEC_HAS_CONTENTS;
3802 fi = elf_tdata (abfd)->find_line_info;
3805 bfd_size_type external_fdr_size;
3808 struct fdr *fdr_ptr;
3809 bfd_size_type amt = sizeof (struct mips_elf_find_line);
3811 fi = (struct mips_elf_find_line *) bfd_zalloc (abfd, amt);
3814 msec->flags = origflags;
3818 if (! _bfd_mips_elf_read_ecoff_info (abfd, msec, &fi->d))
3820 msec->flags = origflags;
3824 /* Swap in the FDR information. */
3825 amt = fi->d.symbolic_header.ifdMax * sizeof (struct fdr);
3826 fi->d.fdr = (struct fdr *) bfd_alloc (abfd, amt);
3827 if (fi->d.fdr == NULL)
3829 msec->flags = origflags;
3832 external_fdr_size = swap->external_fdr_size;
3833 fdr_ptr = fi->d.fdr;
3834 fraw_src = (char *) fi->d.external_fdr;
3835 fraw_end = (fraw_src
3836 + fi->d.symbolic_header.ifdMax * external_fdr_size);
3837 for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
3838 (*swap->swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr);
3840 elf_tdata (abfd)->find_line_info = fi;
3842 /* Note that we don't bother to ever free this information.
3843 find_nearest_line is either called all the time, as in
3844 objdump -l, so the information should be saved, or it is
3845 rarely called, as in ld error messages, so the memory
3846 wasted is unimportant. Still, it would probably be a
3847 good idea for free_cached_info to throw it away. */
3850 if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap,
3851 &fi->i, filename_ptr, functionname_ptr,
3854 msec->flags = origflags;
3858 msec->flags = origflags;
3861 /* Fall back on the generic ELF find_nearest_line routine. */
3863 return _bfd_elf_find_nearest_line (abfd, section, symbols, offset,
3864 filename_ptr, functionname_ptr,
3868 /* The mips16 compiler uses a couple of special sections to handle
3869 floating point arguments.
3871 Section names that look like .mips16.fn.FNNAME contain stubs that
3872 copy floating point arguments from the fp regs to the gp regs and
3873 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3874 call should be redirected to the stub instead. If no 32 bit
3875 function calls FNNAME, the stub should be discarded. We need to
3876 consider any reference to the function, not just a call, because
3877 if the address of the function is taken we will need the stub,
3878 since the address might be passed to a 32 bit function.
3880 Section names that look like .mips16.call.FNNAME contain stubs
3881 that copy floating point arguments from the gp regs to the fp
3882 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3883 then any 16 bit function that calls FNNAME should be redirected
3884 to the stub instead. If FNNAME is not a 32 bit function, the
3885 stub should be discarded.
3887 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3888 which call FNNAME and then copy the return value from the fp regs
3889 to the gp regs. These stubs store the return value in $18 while
3890 calling FNNAME; any function which might call one of these stubs
3891 must arrange to save $18 around the call. (This case is not
3892 needed for 32 bit functions that call 16 bit functions, because
3893 16 bit functions always return floating point values in both
3896 Note that in all cases FNNAME might be defined statically.
3897 Therefore, FNNAME is not used literally. Instead, the relocation
3898 information will indicate which symbol the section is for.
3900 We record any stubs that we find in the symbol table. */
3902 #define FN_STUB ".mips16.fn."
3903 #define CALL_STUB ".mips16.call."
3904 #define CALL_FP_STUB ".mips16.call.fp."
3906 /* MIPS ELF linker hash table. */
3908 struct mips_elf_link_hash_table
3910 struct elf_link_hash_table root;
3912 /* We no longer use this. */
3913 /* String section indices for the dynamic section symbols. */
3914 bfd_size_type dynsym_sec_strindex[SIZEOF_MIPS_DYNSYM_SECNAMES];
3916 /* The number of .rtproc entries. */
3917 bfd_size_type procedure_count;
3918 /* The size of the .compact_rel section (if SGI_COMPAT). */
3919 bfd_size_type compact_rel_size;
3920 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3921 entry is set to the address of __rld_obj_head as in Irix 5. */
3922 boolean use_rld_obj_head;
3923 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3925 /* This is set if we see any mips16 stub sections. */
3926 boolean mips16_stubs_seen;
3929 /* Look up an entry in a MIPS ELF linker hash table. */
3931 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3932 ((struct mips_elf_link_hash_entry *) \
3933 elf_link_hash_lookup (&(table)->root, (string), (create), \
3936 /* Traverse a MIPS ELF linker hash table. */
3938 #define mips_elf_link_hash_traverse(table, func, info) \
3939 (elf_link_hash_traverse \
3941 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3944 /* Get the MIPS ELF linker hash table from a link_info structure. */
3946 #define mips_elf_hash_table(p) \
3947 ((struct mips_elf_link_hash_table *) ((p)->hash))
3949 static boolean mips_elf_output_extsym
3950 PARAMS ((struct mips_elf_link_hash_entry *, PTR));
3952 /* Create an entry in a MIPS ELF linker hash table. */
3954 static struct bfd_hash_entry *
3955 mips_elf_link_hash_newfunc (entry, table, string)
3956 struct bfd_hash_entry *entry;
3957 struct bfd_hash_table *table;
3960 struct mips_elf_link_hash_entry *ret =
3961 (struct mips_elf_link_hash_entry *) entry;
3963 /* Allocate the structure if it has not already been allocated by a
3965 if (ret == (struct mips_elf_link_hash_entry *) NULL)
3966 ret = ((struct mips_elf_link_hash_entry *)
3967 bfd_hash_allocate (table,
3968 sizeof (struct mips_elf_link_hash_entry)));
3969 if (ret == (struct mips_elf_link_hash_entry *) NULL)
3970 return (struct bfd_hash_entry *) ret;
3972 /* Call the allocation method of the superclass. */
3973 ret = ((struct mips_elf_link_hash_entry *)
3974 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
3976 if (ret != (struct mips_elf_link_hash_entry *) NULL)
3978 /* Set local fields. */
3979 memset (&ret->esym, 0, sizeof (EXTR));
3980 /* We use -2 as a marker to indicate that the information has
3981 not been set. -1 means there is no associated ifd. */
3983 ret->possibly_dynamic_relocs = 0;
3984 ret->readonly_reloc = false;
3985 ret->min_dyn_reloc_index = 0;
3986 ret->no_fn_stub = false;
3987 ret->fn_stub = NULL;
3988 ret->need_fn_stub = false;
3989 ret->call_stub = NULL;
3990 ret->call_fp_stub = NULL;
3993 return (struct bfd_hash_entry *) ret;
3997 _bfd_mips_elf_hide_symbol (info, entry)
3998 struct bfd_link_info *info;
3999 struct elf_link_hash_entry *entry;
4003 struct mips_got_info *g;
4004 struct mips_elf_link_hash_entry *h;
4005 h = (struct mips_elf_link_hash_entry *) entry;
4006 dynobj = elf_hash_table (info)->dynobj;
4007 got = bfd_get_section_by_name (dynobj, ".got");
4008 g = (struct mips_got_info *) elf_section_data (got)->tdata;
4010 h->root.elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
4011 h->root.plt.offset = (bfd_vma) -1;
4012 if ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)
4013 h->root.dynindx = -1;
4015 /* FIXME: Do we allocate too much GOT space here? */
4017 got->_raw_size += MIPS_ELF_GOT_SIZE (dynobj);
4020 /* Create a MIPS ELF linker hash table. */
4022 struct bfd_link_hash_table *
4023 _bfd_mips_elf_link_hash_table_create (abfd)
4026 struct mips_elf_link_hash_table *ret;
4027 bfd_size_type amt = sizeof (struct mips_elf_link_hash_table);
4029 ret = (struct mips_elf_link_hash_table *) bfd_alloc (abfd, amt);
4030 if (ret == (struct mips_elf_link_hash_table *) NULL)
4033 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
4034 mips_elf_link_hash_newfunc))
4036 bfd_release (abfd, ret);
4041 /* We no longer use this. */
4042 for (i = 0; i < SIZEOF_MIPS_DYNSYM_SECNAMES; i++)
4043 ret->dynsym_sec_strindex[i] = (bfd_size_type) -1;
4045 ret->procedure_count = 0;
4046 ret->compact_rel_size = 0;
4047 ret->use_rld_obj_head = false;
4049 ret->mips16_stubs_seen = false;
4051 return &ret->root.root;
4054 /* Hook called by the linker routine which adds symbols from an object
4055 file. We must handle the special MIPS section numbers here. */
4058 _bfd_mips_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
4060 struct bfd_link_info *info;
4061 const Elf_Internal_Sym *sym;
4063 flagword *flagsp ATTRIBUTE_UNUSED;
4067 if (SGI_COMPAT (abfd)
4068 && (abfd->flags & DYNAMIC) != 0
4069 && strcmp (*namep, "_rld_new_interface") == 0)
4071 /* Skip Irix 5 rld entry name. */
4076 switch (sym->st_shndx)
4079 /* Common symbols less than the GP size are automatically
4080 treated as SHN_MIPS_SCOMMON symbols. */
4081 if (sym->st_size > elf_gp_size (abfd)
4082 || IRIX_COMPAT (abfd) == ict_irix6)
4085 case SHN_MIPS_SCOMMON:
4086 *secp = bfd_make_section_old_way (abfd, ".scommon");
4087 (*secp)->flags |= SEC_IS_COMMON;
4088 *valp = sym->st_size;
4092 /* This section is used in a shared object. */
4093 if (elf_tdata (abfd)->elf_text_section == NULL)
4095 asymbol *elf_text_symbol;
4096 asection *elf_text_section;
4097 bfd_size_type amt = sizeof (asection);
4099 elf_text_section = bfd_zalloc (abfd, amt);
4100 if (elf_text_section == NULL)
4103 amt = sizeof (asymbol);
4104 elf_text_symbol = bfd_zalloc (abfd, amt);
4105 if (elf_text_symbol == NULL)
4108 /* Initialize the section. */
4110 elf_tdata (abfd)->elf_text_section = elf_text_section;
4111 elf_tdata (abfd)->elf_text_symbol = elf_text_symbol;
4113 elf_text_section->symbol = elf_text_symbol;
4114 elf_text_section->symbol_ptr_ptr = &elf_tdata (abfd)->elf_text_symbol;
4116 elf_text_section->name = ".text";
4117 elf_text_section->flags = SEC_NO_FLAGS;
4118 elf_text_section->output_section = NULL;
4119 elf_text_section->owner = abfd;
4120 elf_text_symbol->name = ".text";
4121 elf_text_symbol->flags = BSF_SECTION_SYM | BSF_DYNAMIC;
4122 elf_text_symbol->section = elf_text_section;
4124 /* This code used to do *secp = bfd_und_section_ptr if
4125 info->shared. I don't know why, and that doesn't make sense,
4126 so I took it out. */
4127 *secp = elf_tdata (abfd)->elf_text_section;
4130 case SHN_MIPS_ACOMMON:
4131 /* Fall through. XXX Can we treat this as allocated data? */
4133 /* This section is used in a shared object. */
4134 if (elf_tdata (abfd)->elf_data_section == NULL)
4136 asymbol *elf_data_symbol;
4137 asection *elf_data_section;
4138 bfd_size_type amt = sizeof (asection);
4140 elf_data_section = bfd_zalloc (abfd, amt);
4141 if (elf_data_section == NULL)
4144 amt = sizeof (asymbol);
4145 elf_data_symbol = bfd_zalloc (abfd, amt);
4146 if (elf_data_symbol == NULL)
4149 /* Initialize the section. */
4151 elf_tdata (abfd)->elf_data_section = elf_data_section;
4152 elf_tdata (abfd)->elf_data_symbol = elf_data_symbol;
4154 elf_data_section->symbol = elf_data_symbol;
4155 elf_data_section->symbol_ptr_ptr = &elf_tdata (abfd)->elf_data_symbol;
4157 elf_data_section->name = ".data";
4158 elf_data_section->flags = SEC_NO_FLAGS;
4159 elf_data_section->output_section = NULL;
4160 elf_data_section->owner = abfd;
4161 elf_data_symbol->name = ".data";
4162 elf_data_symbol->flags = BSF_SECTION_SYM | BSF_DYNAMIC;
4163 elf_data_symbol->section = elf_data_section;
4165 /* This code used to do *secp = bfd_und_section_ptr if
4166 info->shared. I don't know why, and that doesn't make sense,
4167 so I took it out. */
4168 *secp = elf_tdata (abfd)->elf_data_section;
4171 case SHN_MIPS_SUNDEFINED:
4172 *secp = bfd_und_section_ptr;
4176 if (SGI_COMPAT (abfd)
4178 && info->hash->creator == abfd->xvec
4179 && strcmp (*namep, "__rld_obj_head") == 0)
4181 struct elf_link_hash_entry *h;
4183 /* Mark __rld_obj_head as dynamic. */
4185 if (! (_bfd_generic_link_add_one_symbol
4186 (info, abfd, *namep, BSF_GLOBAL, *secp,
4187 (bfd_vma) *valp, (const char *) NULL, false,
4188 get_elf_backend_data (abfd)->collect,
4189 (struct bfd_link_hash_entry **) &h)))
4191 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
4192 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
4193 h->type = STT_OBJECT;
4195 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
4198 mips_elf_hash_table (info)->use_rld_obj_head = true;
4201 /* If this is a mips16 text symbol, add 1 to the value to make it
4202 odd. This will cause something like .word SYM to come up with
4203 the right value when it is loaded into the PC. */
4204 if (sym->st_other == STO_MIPS16)
4210 /* Structure used to pass information to mips_elf_output_extsym. */
4215 struct bfd_link_info *info;
4216 struct ecoff_debug_info *debug;
4217 const struct ecoff_debug_swap *swap;
4221 /* This routine is used to write out ECOFF debugging external symbol
4222 information. It is called via mips_elf_link_hash_traverse. The
4223 ECOFF external symbol information must match the ELF external
4224 symbol information. Unfortunately, at this point we don't know
4225 whether a symbol is required by reloc information, so the two
4226 tables may wind up being different. We must sort out the external
4227 symbol information before we can set the final size of the .mdebug
4228 section, and we must set the size of the .mdebug section before we
4229 can relocate any sections, and we can't know which symbols are
4230 required by relocation until we relocate the sections.
4231 Fortunately, it is relatively unlikely that any symbol will be
4232 stripped but required by a reloc. In particular, it can not happen
4233 when generating a final executable. */
4236 mips_elf_output_extsym (h, data)
4237 struct mips_elf_link_hash_entry *h;
4240 struct extsym_info *einfo = (struct extsym_info *) data;
4242 asection *sec, *output_section;
4244 if (h->root.indx == -2)
4246 else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
4247 || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)
4248 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
4249 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
4251 else if (einfo->info->strip == strip_all
4252 || (einfo->info->strip == strip_some
4253 && bfd_hash_lookup (einfo->info->keep_hash,
4254 h->root.root.root.string,
4255 false, false) == NULL))
4263 if (h->esym.ifd == -2)
4266 h->esym.cobol_main = 0;
4267 h->esym.weakext = 0;
4268 h->esym.reserved = 0;
4269 h->esym.ifd = ifdNil;
4270 h->esym.asym.value = 0;
4271 h->esym.asym.st = stGlobal;
4273 if (h->root.root.type == bfd_link_hash_undefined
4274 || h->root.root.type == bfd_link_hash_undefweak)
4278 /* Use undefined class. Also, set class and type for some
4280 name = h->root.root.root.string;
4281 if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0
4282 || strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0)
4284 h->esym.asym.sc = scData;
4285 h->esym.asym.st = stLabel;
4286 h->esym.asym.value = 0;
4288 else if (strcmp (name, mips_elf_dynsym_rtproc_names[2]) == 0)
4290 h->esym.asym.sc = scAbs;
4291 h->esym.asym.st = stLabel;
4292 h->esym.asym.value =
4293 mips_elf_hash_table (einfo->info)->procedure_count;
4295 else if (strcmp (name, "_gp_disp") == 0)
4297 h->esym.asym.sc = scAbs;
4298 h->esym.asym.st = stLabel;
4299 h->esym.asym.value = elf_gp (einfo->abfd);
4302 h->esym.asym.sc = scUndefined;
4304 else if (h->root.root.type != bfd_link_hash_defined
4305 && h->root.root.type != bfd_link_hash_defweak)
4306 h->esym.asym.sc = scAbs;
4311 sec = h->root.root.u.def.section;
4312 output_section = sec->output_section;
4314 /* When making a shared library and symbol h is the one from
4315 the another shared library, OUTPUT_SECTION may be null. */
4316 if (output_section == NULL)
4317 h->esym.asym.sc = scUndefined;
4320 name = bfd_section_name (output_section->owner, output_section);
4322 if (strcmp (name, ".text") == 0)
4323 h->esym.asym.sc = scText;
4324 else if (strcmp (name, ".data") == 0)
4325 h->esym.asym.sc = scData;
4326 else if (strcmp (name, ".sdata") == 0)
4327 h->esym.asym.sc = scSData;
4328 else if (strcmp (name, ".rodata") == 0
4329 || strcmp (name, ".rdata") == 0)
4330 h->esym.asym.sc = scRData;
4331 else if (strcmp (name, ".bss") == 0)
4332 h->esym.asym.sc = scBss;
4333 else if (strcmp (name, ".sbss") == 0)
4334 h->esym.asym.sc = scSBss;
4335 else if (strcmp (name, ".init") == 0)
4336 h->esym.asym.sc = scInit;
4337 else if (strcmp (name, ".fini") == 0)
4338 h->esym.asym.sc = scFini;
4340 h->esym.asym.sc = scAbs;
4344 h->esym.asym.reserved = 0;
4345 h->esym.asym.index = indexNil;
4348 if (h->root.root.type == bfd_link_hash_common)
4349 h->esym.asym.value = h->root.root.u.c.size;
4350 else if (h->root.root.type == bfd_link_hash_defined
4351 || h->root.root.type == bfd_link_hash_defweak)
4353 if (h->esym.asym.sc == scCommon)
4354 h->esym.asym.sc = scBss;
4355 else if (h->esym.asym.sc == scSCommon)
4356 h->esym.asym.sc = scSBss;
4358 sec = h->root.root.u.def.section;
4359 output_section = sec->output_section;
4360 if (output_section != NULL)
4361 h->esym.asym.value = (h->root.root.u.def.value
4362 + sec->output_offset
4363 + output_section->vma);
4365 h->esym.asym.value = 0;
4367 else if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
4369 struct mips_elf_link_hash_entry *hd = h;
4370 boolean no_fn_stub = h->no_fn_stub;
4372 while (hd->root.root.type == bfd_link_hash_indirect)
4374 hd = (struct mips_elf_link_hash_entry *)h->root.root.u.i.link;
4375 no_fn_stub = no_fn_stub || hd->no_fn_stub;
4380 /* Set type and value for a symbol with a function stub. */
4381 h->esym.asym.st = stProc;
4382 sec = hd->root.root.u.def.section;
4384 h->esym.asym.value = 0;
4387 output_section = sec->output_section;
4388 if (output_section != NULL)
4389 h->esym.asym.value = (hd->root.plt.offset
4390 + sec->output_offset
4391 + output_section->vma);
4393 h->esym.asym.value = 0;
4401 if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap,
4402 h->root.root.root.string,
4405 einfo->failed = true;
4412 /* Create a runtime procedure table from the .mdebug section. */
4415 mips_elf_create_procedure_table (handle, abfd, info, s, debug)
4418 struct bfd_link_info *info;
4420 struct ecoff_debug_info *debug;
4422 const struct ecoff_debug_swap *swap;
4423 HDRR *hdr = &debug->symbolic_header;
4425 struct rpdr_ext *erp;
4427 struct pdr_ext *epdr;
4428 struct sym_ext *esym;
4432 bfd_size_type count;
4433 unsigned long sindex;
4437 const char *no_name_func = _("static procedure (no name)");
4445 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
4447 sindex = strlen (no_name_func) + 1;
4448 count = hdr->ipdMax;
4451 size = swap->external_pdr_size;
4453 epdr = (struct pdr_ext *) bfd_malloc (size * count);
4457 if (! _bfd_ecoff_get_accumulated_pdr (handle, (PTR) epdr))
4460 size = sizeof (RPDR);
4461 rp = rpdr = (RPDR *) bfd_malloc (size * count);
4465 size = sizeof (char *);
4466 sv = (char **) bfd_malloc (size * count);
4470 count = hdr->isymMax;
4471 size = swap->external_sym_size;
4472 esym = (struct sym_ext *) bfd_malloc (size * count);
4476 if (! _bfd_ecoff_get_accumulated_sym (handle, (PTR) esym))
4479 count = hdr->issMax;
4480 ss = (char *) bfd_malloc (count);
4483 if (! _bfd_ecoff_get_accumulated_ss (handle, (PTR) ss))
4486 count = hdr->ipdMax;
4487 for (i = 0; i < (unsigned long) count; i++, rp++)
4489 (*swap->swap_pdr_in) (abfd, (PTR) (epdr + i), &pdr);
4490 (*swap->swap_sym_in) (abfd, (PTR) &esym[pdr.isym], &sym);
4491 rp->adr = sym.value;
4492 rp->regmask = pdr.regmask;
4493 rp->regoffset = pdr.regoffset;
4494 rp->fregmask = pdr.fregmask;
4495 rp->fregoffset = pdr.fregoffset;
4496 rp->frameoffset = pdr.frameoffset;
4497 rp->framereg = pdr.framereg;
4498 rp->pcreg = pdr.pcreg;
4500 sv[i] = ss + sym.iss;
4501 sindex += strlen (sv[i]) + 1;
4505 size = sizeof (struct rpdr_ext) * (count + 2) + sindex;
4506 size = BFD_ALIGN (size, 16);
4507 rtproc = (PTR) bfd_alloc (abfd, size);
4510 mips_elf_hash_table (info)->procedure_count = 0;
4514 mips_elf_hash_table (info)->procedure_count = count + 2;
4516 erp = (struct rpdr_ext *) rtproc;
4517 memset (erp, 0, sizeof (struct rpdr_ext));
4519 str = (char *) rtproc + sizeof (struct rpdr_ext) * (count + 2);
4520 strcpy (str, no_name_func);
4521 str += strlen (no_name_func) + 1;
4522 for (i = 0; i < count; i++)
4524 ecoff_swap_rpdr_out (abfd, rpdr + i, erp + i);
4525 strcpy (str, sv[i]);
4526 str += strlen (sv[i]) + 1;
4528 ECOFF_PUT_OFF (abfd, -1, (erp + count)->p_adr);
4530 /* Set the size and contents of .rtproc section. */
4531 s->_raw_size = size;
4532 s->contents = (bfd_byte *) rtproc;
4534 /* Skip this section later on (I don't think this currently
4535 matters, but someday it might). */
4536 s->link_order_head = (struct bfd_link_order *) NULL;
4565 /* A comparison routine used to sort .gptab entries. */
4568 gptab_compare (p1, p2)
4572 const Elf32_gptab *a1 = (const Elf32_gptab *) p1;
4573 const Elf32_gptab *a2 = (const Elf32_gptab *) p2;
4575 return a1->gt_entry.gt_g_value - a2->gt_entry.gt_g_value;
4578 /* We need to use a special link routine to handle the .reginfo and
4579 the .mdebug sections. We need to merge all instances of these
4580 sections together, not write them all out sequentially. */
4583 _bfd_mips_elf_final_link (abfd, info)
4585 struct bfd_link_info *info;
4589 struct bfd_link_order *p;
4590 asection *reginfo_sec, *mdebug_sec, *gptab_data_sec, *gptab_bss_sec;
4591 asection *rtproc_sec;
4592 Elf32_RegInfo reginfo;
4593 struct ecoff_debug_info debug;
4594 const struct ecoff_debug_swap *swap
4595 = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
4596 HDRR *symhdr = &debug.symbolic_header;
4597 PTR mdebug_handle = NULL;
4603 static const char * const secname[] =
4605 ".text", ".init", ".fini", ".data",
4606 ".rodata", ".sdata", ".sbss", ".bss"
4608 static const int sc[] =
4610 scText, scInit, scFini, scData,
4611 scRData, scSData, scSBss, scBss
4614 /* If all the things we linked together were PIC, but we're
4615 producing an executable (rather than a shared object), then the
4616 resulting file is CPIC (i.e., it calls PIC code.) */
4618 && !info->relocateable
4619 && elf_elfheader (abfd)->e_flags & EF_MIPS_PIC)
4621 elf_elfheader (abfd)->e_flags &= ~EF_MIPS_PIC;
4622 elf_elfheader (abfd)->e_flags |= EF_MIPS_CPIC;
4625 /* We'd carefully arranged the dynamic symbol indices, and then the
4626 generic size_dynamic_sections renumbered them out from under us.
4627 Rather than trying somehow to prevent the renumbering, just do
4629 if (elf_hash_table (info)->dynamic_sections_created)
4633 struct mips_got_info *g;
4635 /* When we resort, we must tell mips_elf_sort_hash_table what
4636 the lowest index it may use is. That's the number of section
4637 symbols we're going to add. The generic ELF linker only
4638 adds these symbols when building a shared object. Note that
4639 we count the sections after (possibly) removing the .options
4641 if (!mips_elf_sort_hash_table (info, (info->shared
4642 ? bfd_count_sections (abfd) + 1
4646 /* Make sure we didn't grow the global .got region. */
4647 dynobj = elf_hash_table (info)->dynobj;
4648 got = bfd_get_section_by_name (dynobj, ".got");
4649 g = (struct mips_got_info *) elf_section_data (got)->tdata;
4651 if (g->global_gotsym != NULL)
4652 BFD_ASSERT ((elf_hash_table (info)->dynsymcount
4653 - g->global_gotsym->dynindx)
4654 <= g->global_gotno);
4657 /* On IRIX5, we omit the .options section. On IRIX6, however, we
4658 include it, even though we don't process it quite right. (Some
4659 entries are supposed to be merged.) Empirically, we seem to be
4660 better off including it then not. */
4661 if (IRIX_COMPAT (abfd) == ict_irix5 || IRIX_COMPAT (abfd) == ict_none)
4662 for (secpp = &abfd->sections; *secpp != NULL; secpp = &(*secpp)->next)
4664 if (strcmp ((*secpp)->name, MIPS_ELF_OPTIONS_SECTION_NAME (abfd)) == 0)
4666 for (p = (*secpp)->link_order_head; p != NULL; p = p->next)
4667 if (p->type == bfd_indirect_link_order)
4668 p->u.indirect.section->flags &= ~SEC_HAS_CONTENTS;
4669 (*secpp)->link_order_head = NULL;
4670 *secpp = (*secpp)->next;
4671 --abfd->section_count;
4677 /* Get a value for the GP register. */
4678 if (elf_gp (abfd) == 0)
4680 struct bfd_link_hash_entry *h;
4682 h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true);
4683 if (h != (struct bfd_link_hash_entry *) NULL
4684 && h->type == bfd_link_hash_defined)
4685 elf_gp (abfd) = (h->u.def.value
4686 + h->u.def.section->output_section->vma
4687 + h->u.def.section->output_offset);
4688 else if (info->relocateable)
4692 /* Find the GP-relative section with the lowest offset. */
4694 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
4696 && (elf_section_data (o)->this_hdr.sh_flags & SHF_MIPS_GPREL))
4699 /* And calculate GP relative to that. */
4700 elf_gp (abfd) = lo + ELF_MIPS_GP_OFFSET (abfd);
4704 /* If the relocate_section function needs to do a reloc
4705 involving the GP value, it should make a reloc_dangerous
4706 callback to warn that GP is not defined. */
4710 /* Go through the sections and collect the .reginfo and .mdebug
4714 gptab_data_sec = NULL;
4715 gptab_bss_sec = NULL;
4716 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
4718 if (strcmp (o->name, ".reginfo") == 0)
4720 memset (®info, 0, sizeof reginfo);
4722 /* We have found the .reginfo section in the output file.
4723 Look through all the link_orders comprising it and merge
4724 the information together. */
4725 for (p = o->link_order_head;
4726 p != (struct bfd_link_order *) NULL;
4729 asection *input_section;
4731 Elf32_External_RegInfo ext;
4734 if (p->type != bfd_indirect_link_order)
4736 if (p->type == bfd_fill_link_order)
4741 input_section = p->u.indirect.section;
4742 input_bfd = input_section->owner;
4744 /* The linker emulation code has probably clobbered the
4745 size to be zero bytes. */
4746 if (input_section->_raw_size == 0)
4747 input_section->_raw_size = sizeof (Elf32_External_RegInfo);
4749 if (! bfd_get_section_contents (input_bfd, input_section,
4752 (bfd_size_type) sizeof ext))
4755 bfd_mips_elf32_swap_reginfo_in (input_bfd, &ext, &sub);
4757 reginfo.ri_gprmask |= sub.ri_gprmask;
4758 reginfo.ri_cprmask[0] |= sub.ri_cprmask[0];
4759 reginfo.ri_cprmask[1] |= sub.ri_cprmask[1];
4760 reginfo.ri_cprmask[2] |= sub.ri_cprmask[2];
4761 reginfo.ri_cprmask[3] |= sub.ri_cprmask[3];
4763 /* ri_gp_value is set by the function
4764 mips_elf32_section_processing when the section is
4765 finally written out. */
4767 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4768 elf_link_input_bfd ignores this section. */
4769 input_section->flags &= ~SEC_HAS_CONTENTS;
4772 /* Size has been set in mips_elf_always_size_sections */
4773 BFD_ASSERT(o->_raw_size == sizeof (Elf32_External_RegInfo));
4775 /* Skip this section later on (I don't think this currently
4776 matters, but someday it might). */
4777 o->link_order_head = (struct bfd_link_order *) NULL;
4782 if (strcmp (o->name, ".mdebug") == 0)
4784 struct extsym_info einfo;
4787 /* We have found the .mdebug section in the output file.
4788 Look through all the link_orders comprising it and merge
4789 the information together. */
4790 symhdr->magic = swap->sym_magic;
4791 /* FIXME: What should the version stamp be? */
4793 symhdr->ilineMax = 0;
4797 symhdr->isymMax = 0;
4798 symhdr->ioptMax = 0;
4799 symhdr->iauxMax = 0;
4801 symhdr->issExtMax = 0;
4804 symhdr->iextMax = 0;
4806 /* We accumulate the debugging information itself in the
4807 debug_info structure. */
4809 debug.external_dnr = NULL;
4810 debug.external_pdr = NULL;
4811 debug.external_sym = NULL;
4812 debug.external_opt = NULL;
4813 debug.external_aux = NULL;
4815 debug.ssext = debug.ssext_end = NULL;
4816 debug.external_fdr = NULL;
4817 debug.external_rfd = NULL;
4818 debug.external_ext = debug.external_ext_end = NULL;
4820 mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info);
4821 if (mdebug_handle == (PTR) NULL)
4825 esym.cobol_main = 0;
4829 esym.asym.iss = issNil;
4830 esym.asym.st = stLocal;
4831 esym.asym.reserved = 0;
4832 esym.asym.index = indexNil;
4834 for (i = 0; i < sizeof (secname) / sizeof (secname[0]); i++)
4836 esym.asym.sc = sc[i];
4837 s = bfd_get_section_by_name (abfd, secname[i]);
4840 esym.asym.value = s->vma;
4841 last = s->vma + s->_raw_size;
4844 esym.asym.value = last;
4845 if (!bfd_ecoff_debug_one_external (abfd, &debug, swap,
4850 for (p = o->link_order_head;
4851 p != (struct bfd_link_order *) NULL;
4854 asection *input_section;
4856 const struct ecoff_debug_swap *input_swap;
4857 struct ecoff_debug_info input_debug;
4861 if (p->type != bfd_indirect_link_order)
4863 if (p->type == bfd_fill_link_order)
4868 input_section = p->u.indirect.section;
4869 input_bfd = input_section->owner;
4871 if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour
4872 || (get_elf_backend_data (input_bfd)
4873 ->elf_backend_ecoff_debug_swap) == NULL)
4875 /* I don't know what a non MIPS ELF bfd would be
4876 doing with a .mdebug section, but I don't really
4877 want to deal with it. */
4881 input_swap = (get_elf_backend_data (input_bfd)
4882 ->elf_backend_ecoff_debug_swap);
4884 BFD_ASSERT (p->size == input_section->_raw_size);
4886 /* The ECOFF linking code expects that we have already
4887 read in the debugging information and set up an
4888 ecoff_debug_info structure, so we do that now. */
4889 if (! _bfd_mips_elf_read_ecoff_info (input_bfd, input_section,
4893 if (! (bfd_ecoff_debug_accumulate
4894 (mdebug_handle, abfd, &debug, swap, input_bfd,
4895 &input_debug, input_swap, info)))
4898 /* Loop through the external symbols. For each one with
4899 interesting information, try to find the symbol in
4900 the linker global hash table and save the information
4901 for the output external symbols. */
4902 eraw_src = input_debug.external_ext;
4903 eraw_end = (eraw_src
4904 + (input_debug.symbolic_header.iextMax
4905 * input_swap->external_ext_size));
4907 eraw_src < eraw_end;
4908 eraw_src += input_swap->external_ext_size)
4912 struct mips_elf_link_hash_entry *h;
4914 (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext);
4915 if (ext.asym.sc == scNil
4916 || ext.asym.sc == scUndefined
4917 || ext.asym.sc == scSUndefined)
4920 name = input_debug.ssext + ext.asym.iss;
4921 h = mips_elf_link_hash_lookup (mips_elf_hash_table (info),
4922 name, false, false, true);
4923 if (h == NULL || h->esym.ifd != -2)
4929 < input_debug.symbolic_header.ifdMax);
4930 ext.ifd = input_debug.ifdmap[ext.ifd];
4936 /* Free up the information we just read. */
4937 free (input_debug.line);
4938 free (input_debug.external_dnr);
4939 free (input_debug.external_pdr);
4940 free (input_debug.external_sym);
4941 free (input_debug.external_opt);
4942 free (input_debug.external_aux);
4943 free (input_debug.ss);
4944 free (input_debug.ssext);
4945 free (input_debug.external_fdr);
4946 free (input_debug.external_rfd);
4947 free (input_debug.external_ext);
4949 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4950 elf_link_input_bfd ignores this section. */
4951 input_section->flags &= ~SEC_HAS_CONTENTS;
4954 if (SGI_COMPAT (abfd) && info->shared)
4956 /* Create .rtproc section. */
4957 rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc");
4958 if (rtproc_sec == NULL)
4960 flagword flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY
4961 | SEC_LINKER_CREATED | SEC_READONLY);
4963 rtproc_sec = bfd_make_section (abfd, ".rtproc");
4964 if (rtproc_sec == NULL
4965 || ! bfd_set_section_flags (abfd, rtproc_sec, flags)
4966 || ! bfd_set_section_alignment (abfd, rtproc_sec, 4))
4970 if (! mips_elf_create_procedure_table (mdebug_handle, abfd,
4971 info, rtproc_sec, &debug))
4975 /* Build the external symbol information. */
4978 einfo.debug = &debug;
4980 einfo.failed = false;
4981 mips_elf_link_hash_traverse (mips_elf_hash_table (info),
4982 mips_elf_output_extsym,
4987 /* Set the size of the .mdebug section. */
4988 o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap);
4990 /* Skip this section later on (I don't think this currently
4991 matters, but someday it might). */
4992 o->link_order_head = (struct bfd_link_order *) NULL;
4997 if (strncmp (o->name, ".gptab.", sizeof ".gptab." - 1) == 0)
4999 const char *subname;
5002 Elf32_External_gptab *ext_tab;
5005 /* The .gptab.sdata and .gptab.sbss sections hold
5006 information describing how the small data area would
5007 change depending upon the -G switch. These sections
5008 not used in executables files. */
5009 if (! info->relocateable)
5011 for (p = o->link_order_head;
5012 p != (struct bfd_link_order *) NULL;
5015 asection *input_section;
5017 if (p->type != bfd_indirect_link_order)
5019 if (p->type == bfd_fill_link_order)
5024 input_section = p->u.indirect.section;
5026 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5027 elf_link_input_bfd ignores this section. */
5028 input_section->flags &= ~SEC_HAS_CONTENTS;
5031 /* Skip this section later on (I don't think this
5032 currently matters, but someday it might). */
5033 o->link_order_head = (struct bfd_link_order *) NULL;
5035 /* Really remove the section. */
5036 for (secpp = &abfd->sections;
5038 secpp = &(*secpp)->next)
5040 *secpp = (*secpp)->next;
5041 --abfd->section_count;
5046 /* There is one gptab for initialized data, and one for
5047 uninitialized data. */
5048 if (strcmp (o->name, ".gptab.sdata") == 0)
5050 else if (strcmp (o->name, ".gptab.sbss") == 0)
5054 (*_bfd_error_handler)
5055 (_("%s: illegal section name `%s'"),
5056 bfd_get_filename (abfd), o->name);
5057 bfd_set_error (bfd_error_nonrepresentable_section);
5061 /* The linker script always combines .gptab.data and
5062 .gptab.sdata into .gptab.sdata, and likewise for
5063 .gptab.bss and .gptab.sbss. It is possible that there is
5064 no .sdata or .sbss section in the output file, in which
5065 case we must change the name of the output section. */
5066 subname = o->name + sizeof ".gptab" - 1;
5067 if (bfd_get_section_by_name (abfd, subname) == NULL)
5069 if (o == gptab_data_sec)
5070 o->name = ".gptab.data";
5072 o->name = ".gptab.bss";
5073 subname = o->name + sizeof ".gptab" - 1;
5074 BFD_ASSERT (bfd_get_section_by_name (abfd, subname) != NULL);
5077 /* Set up the first entry. */
5079 amt = c * sizeof (Elf32_gptab);
5080 tab = (Elf32_gptab *) bfd_malloc (amt);
5083 tab[0].gt_header.gt_current_g_value = elf_gp_size (abfd);
5084 tab[0].gt_header.gt_unused = 0;
5086 /* Combine the input sections. */
5087 for (p = o->link_order_head;
5088 p != (struct bfd_link_order *) NULL;
5091 asection *input_section;
5095 bfd_size_type gpentry;
5097 if (p->type != bfd_indirect_link_order)
5099 if (p->type == bfd_fill_link_order)
5104 input_section = p->u.indirect.section;
5105 input_bfd = input_section->owner;
5107 /* Combine the gptab entries for this input section one
5108 by one. We know that the input gptab entries are
5109 sorted by ascending -G value. */
5110 size = bfd_section_size (input_bfd, input_section);
5112 for (gpentry = sizeof (Elf32_External_gptab);
5114 gpentry += sizeof (Elf32_External_gptab))
5116 Elf32_External_gptab ext_gptab;
5117 Elf32_gptab int_gptab;
5123 if (! (bfd_get_section_contents
5124 (input_bfd, input_section, (PTR) &ext_gptab,
5126 (bfd_size_type) sizeof (Elf32_External_gptab))))
5132 bfd_mips_elf32_swap_gptab_in (input_bfd, &ext_gptab,
5134 val = int_gptab.gt_entry.gt_g_value;
5135 add = int_gptab.gt_entry.gt_bytes - last;
5138 for (look = 1; look < c; look++)
5140 if (tab[look].gt_entry.gt_g_value >= val)
5141 tab[look].gt_entry.gt_bytes += add;
5143 if (tab[look].gt_entry.gt_g_value == val)
5149 Elf32_gptab *new_tab;
5152 /* We need a new table entry. */
5153 amt = (bfd_size_type) (c + 1) * sizeof (Elf32_gptab);
5154 new_tab = (Elf32_gptab *) bfd_realloc ((PTR) tab, amt);
5155 if (new_tab == NULL)
5161 tab[c].gt_entry.gt_g_value = val;
5162 tab[c].gt_entry.gt_bytes = add;
5164 /* Merge in the size for the next smallest -G
5165 value, since that will be implied by this new
5168 for (look = 1; look < c; look++)
5170 if (tab[look].gt_entry.gt_g_value < val
5172 || (tab[look].gt_entry.gt_g_value
5173 > tab[max].gt_entry.gt_g_value)))
5177 tab[c].gt_entry.gt_bytes +=
5178 tab[max].gt_entry.gt_bytes;
5183 last = int_gptab.gt_entry.gt_bytes;
5186 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5187 elf_link_input_bfd ignores this section. */
5188 input_section->flags &= ~SEC_HAS_CONTENTS;
5191 /* The table must be sorted by -G value. */
5193 qsort (tab + 1, c - 1, sizeof (tab[0]), gptab_compare);
5195 /* Swap out the table. */
5196 amt = (bfd_size_type) c * sizeof (Elf32_External_gptab);
5197 ext_tab = (Elf32_External_gptab *) bfd_alloc (abfd, amt);
5198 if (ext_tab == NULL)
5204 for (j = 0; j < c; j++)
5205 bfd_mips_elf32_swap_gptab_out (abfd, tab + j, ext_tab + j);
5208 o->_raw_size = c * sizeof (Elf32_External_gptab);
5209 o->contents = (bfd_byte *) ext_tab;
5211 /* Skip this section later on (I don't think this currently
5212 matters, but someday it might). */
5213 o->link_order_head = (struct bfd_link_order *) NULL;
5217 /* Invoke the regular ELF backend linker to do all the work. */
5218 if (ABI_64_P (abfd))
5221 if (!bfd_elf64_bfd_final_link (abfd, info))
5228 else if (!bfd_elf32_bfd_final_link (abfd, info))
5231 /* Now write out the computed sections. */
5233 if (reginfo_sec != (asection *) NULL)
5235 Elf32_External_RegInfo ext;
5237 bfd_mips_elf32_swap_reginfo_out (abfd, ®info, &ext);
5238 if (! bfd_set_section_contents (abfd, reginfo_sec, (PTR) &ext,
5239 (file_ptr) 0, (bfd_size_type) sizeof ext))
5243 if (mdebug_sec != (asection *) NULL)
5245 BFD_ASSERT (abfd->output_has_begun);
5246 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug,
5248 mdebug_sec->filepos))
5251 bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info);
5254 if (gptab_data_sec != (asection *) NULL)
5256 if (! bfd_set_section_contents (abfd, gptab_data_sec,
5257 gptab_data_sec->contents,
5259 gptab_data_sec->_raw_size))
5263 if (gptab_bss_sec != (asection *) NULL)
5265 if (! bfd_set_section_contents (abfd, gptab_bss_sec,
5266 gptab_bss_sec->contents,
5268 gptab_bss_sec->_raw_size))
5272 if (SGI_COMPAT (abfd))
5274 rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc");
5275 if (rtproc_sec != NULL)
5277 if (! bfd_set_section_contents (abfd, rtproc_sec,
5278 rtproc_sec->contents,
5280 rtproc_sec->_raw_size))
5288 /* This function is called via qsort() to sort the dynamic relocation
5289 entries by increasing r_symndx value. */
5292 sort_dynamic_relocs (arg1, arg2)
5296 const Elf32_External_Rel *ext_reloc1 = (const Elf32_External_Rel *) arg1;
5297 const Elf32_External_Rel *ext_reloc2 = (const Elf32_External_Rel *) arg2;
5299 Elf_Internal_Rel int_reloc1;
5300 Elf_Internal_Rel int_reloc2;
5302 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd, ext_reloc1, &int_reloc1);
5303 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd, ext_reloc2, &int_reloc2);
5305 return (ELF32_R_SYM (int_reloc1.r_info) - ELF32_R_SYM (int_reloc2.r_info));
5308 /* Returns the GOT section for ABFD. */
5311 mips_elf_got_section (abfd)
5314 return bfd_get_section_by_name (abfd, ".got");
5317 /* Returns the GOT information associated with the link indicated by
5318 INFO. If SGOTP is non-NULL, it is filled in with the GOT
5321 static struct mips_got_info *
5322 mips_elf_got_info (abfd, sgotp)
5327 struct mips_got_info *g;
5329 sgot = mips_elf_got_section (abfd);
5330 BFD_ASSERT (sgot != NULL);
5331 BFD_ASSERT (elf_section_data (sgot) != NULL);
5332 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
5333 BFD_ASSERT (g != NULL);
5340 /* Return whether a relocation is against a local symbol. */
5343 mips_elf_local_relocation_p (input_bfd, relocation, local_sections,
5346 const Elf_Internal_Rela *relocation;
5347 asection **local_sections;
5348 boolean check_forced;
5350 unsigned long r_symndx;
5351 Elf_Internal_Shdr *symtab_hdr;
5352 struct mips_elf_link_hash_entry *h;
5355 r_symndx = ELF32_R_SYM (relocation->r_info);
5356 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5357 extsymoff = (elf_bad_symtab (input_bfd)) ? 0 : symtab_hdr->sh_info;
5359 if (r_symndx < extsymoff)
5361 if (elf_bad_symtab (input_bfd) && local_sections[r_symndx] != NULL)
5366 /* Look up the hash table to check whether the symbol
5367 was forced local. */
5368 h = (struct mips_elf_link_hash_entry *)
5369 elf_sym_hashes (input_bfd) [r_symndx - extsymoff];
5370 /* Find the real hash-table entry for this symbol. */
5371 while (h->root.root.type == bfd_link_hash_indirect
5372 || h->root.root.type == bfd_link_hash_warning)
5373 h = (struct mips_elf_link_hash_entry *) h->root.root.u.i.link;
5374 if ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)
5381 /* Sign-extend VALUE, which has the indicated number of BITS. */
5384 mips_elf_sign_extend (value, bits)
5388 if (value & ((bfd_vma) 1 << (bits - 1)))
5389 /* VALUE is negative. */
5390 value |= ((bfd_vma) - 1) << bits;
5395 /* Return non-zero if the indicated VALUE has overflowed the maximum
5396 range expressable by a signed number with the indicated number of
5400 mips_elf_overflow_p (value, bits)
5404 bfd_signed_vma svalue = (bfd_signed_vma) value;
5406 if (svalue > (1 << (bits - 1)) - 1)
5407 /* The value is too big. */
5409 else if (svalue < -(1 << (bits - 1)))
5410 /* The value is too small. */
5417 /* Calculate the %high function. */
5420 mips_elf_high (value)
5423 return ((value + (bfd_vma) 0x8000) >> 16) & 0xffff;
5426 /* Calculate the %higher function. */
5429 mips_elf_higher (value)
5430 bfd_vma value ATTRIBUTE_UNUSED;
5433 return ((value + (bfd_vma) 0x80008000) >> 32) & 0xffff;
5436 return (bfd_vma) -1;
5440 /* Calculate the %highest function. */
5443 mips_elf_highest (value)
5444 bfd_vma value ATTRIBUTE_UNUSED;
5447 return ((value + (bfd_vma) 0x800080008000) >> 48) & 0xffff;
5450 return (bfd_vma) -1;
5454 /* Returns the GOT index for the global symbol indicated by H. */
5457 mips_elf_global_got_index (abfd, h)
5459 struct elf_link_hash_entry *h;
5463 struct mips_got_info *g;
5465 g = mips_elf_got_info (abfd, &sgot);
5467 /* Once we determine the global GOT entry with the lowest dynamic
5468 symbol table index, we must put all dynamic symbols with greater
5469 indices into the GOT. That makes it easy to calculate the GOT
5471 BFD_ASSERT (h->dynindx >= g->global_gotsym->dynindx);
5472 index = ((h->dynindx - g->global_gotsym->dynindx + g->local_gotno)
5473 * MIPS_ELF_GOT_SIZE (abfd));
5474 BFD_ASSERT (index < sgot->_raw_size);
5479 /* Returns the offset for the entry at the INDEXth position
5483 mips_elf_got_offset_from_index (dynobj, output_bfd, index)
5491 sgot = mips_elf_got_section (dynobj);
5492 gp = _bfd_get_gp_value (output_bfd);
5493 return (sgot->output_section->vma + sgot->output_offset + index -
5497 /* If H is a symbol that needs a global GOT entry, but has a dynamic
5498 symbol table index lower than any we've seen to date, record it for
5502 mips_elf_record_global_got_symbol (h, info, g)
5503 struct elf_link_hash_entry *h;
5504 struct bfd_link_info *info;
5505 struct mips_got_info *g ATTRIBUTE_UNUSED;
5507 /* A global symbol in the GOT must also be in the dynamic symbol
5509 if (h->dynindx == -1
5510 && !bfd_elf32_link_record_dynamic_symbol (info, h))
5513 /* If we've already marked this entry as needing GOT space, we don't
5514 need to do it again. */
5515 if (h->got.offset != (bfd_vma) -1)
5518 /* By setting this to a value other than -1, we are indicating that
5519 there needs to be a GOT entry for H. Avoid using zero, as the
5520 generic ELF copy_indirect_symbol tests for <= 0. */
5526 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
5527 the dynamic symbols. */
5529 struct mips_elf_hash_sort_data
5531 /* The symbol in the global GOT with the lowest dynamic symbol table
5533 struct elf_link_hash_entry *low;
5534 /* The least dynamic symbol table index corresponding to a symbol
5535 with a GOT entry. */
5536 long min_got_dynindx;
5537 /* The greatest dynamic symbol table index not corresponding to a
5538 symbol without a GOT entry. */
5539 long max_non_got_dynindx;
5542 /* If H needs a GOT entry, assign it the highest available dynamic
5543 index. Otherwise, assign it the lowest available dynamic
5547 mips_elf_sort_hash_table_f (h, data)
5548 struct mips_elf_link_hash_entry *h;
5551 struct mips_elf_hash_sort_data *hsd
5552 = (struct mips_elf_hash_sort_data *) data;
5554 /* Symbols without dynamic symbol table entries aren't interesting
5556 if (h->root.dynindx == -1)
5559 if (h->root.got.offset != 1)
5560 h->root.dynindx = hsd->max_non_got_dynindx++;
5563 h->root.dynindx = --hsd->min_got_dynindx;
5564 hsd->low = (struct elf_link_hash_entry *) h;
5570 /* Sort the dynamic symbol table so that symbols that need GOT entries
5571 appear towards the end. This reduces the amount of GOT space
5572 required. MAX_LOCAL is used to set the number of local symbols
5573 known to be in the dynamic symbol table. During
5574 mips_elf_size_dynamic_sections, this value is 1. Afterward, the
5575 section symbols are added and the count is higher. */
5578 mips_elf_sort_hash_table (info, max_local)
5579 struct bfd_link_info *info;
5580 unsigned long max_local;
5582 struct mips_elf_hash_sort_data hsd;
5583 struct mips_got_info *g;
5586 dynobj = elf_hash_table (info)->dynobj;
5589 hsd.min_got_dynindx = elf_hash_table (info)->dynsymcount;
5590 hsd.max_non_got_dynindx = max_local;
5591 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table *)
5592 elf_hash_table (info)),
5593 mips_elf_sort_hash_table_f,
5596 /* There should have been enough room in the symbol table to
5597 accomodate both the GOT and non-GOT symbols. */
5598 BFD_ASSERT (hsd.max_non_got_dynindx <= hsd.min_got_dynindx);
5600 /* Now we know which dynamic symbol has the lowest dynamic symbol
5601 table index in the GOT. */
5602 g = mips_elf_got_info (dynobj, NULL);
5603 g->global_gotsym = hsd.low;
5608 /* Create a local GOT entry for VALUE. Return the index of the entry,
5609 or -1 if it could not be created. */
5612 mips_elf_create_local_got_entry (abfd, g, sgot, value)
5614 struct mips_got_info *g;
5618 if (g->assigned_gotno >= g->local_gotno)
5620 /* We didn't allocate enough space in the GOT. */
5621 (*_bfd_error_handler)
5622 (_("not enough GOT space for local GOT entries"));
5623 bfd_set_error (bfd_error_bad_value);
5624 return (bfd_vma) -1;
5627 MIPS_ELF_PUT_WORD (abfd, value,
5629 + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno));
5630 return MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno++;
5633 /* Returns the GOT offset at which the indicated address can be found.
5634 If there is not yet a GOT entry for this value, create one. Returns
5635 -1 if no satisfactory GOT offset can be found. */
5638 mips_elf_local_got_index (abfd, info, value)
5640 struct bfd_link_info *info;
5644 struct mips_got_info *g;
5647 g = mips_elf_got_info (elf_hash_table (info)->dynobj, &sgot);
5649 /* Look to see if we already have an appropriate entry. */
5650 for (entry = (sgot->contents
5651 + MIPS_ELF_GOT_SIZE (abfd) * MIPS_RESERVED_GOTNO);
5652 entry != sgot->contents + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno;
5653 entry += MIPS_ELF_GOT_SIZE (abfd))
5655 bfd_vma address = MIPS_ELF_GET_WORD (abfd, entry);
5656 if (address == value)
5657 return entry - sgot->contents;
5660 return mips_elf_create_local_got_entry (abfd, g, sgot, value);
5663 /* Find a GOT entry that is within 32KB of the VALUE. These entries
5664 are supposed to be placed at small offsets in the GOT, i.e.,
5665 within 32KB of GP. Return the index into the GOT for this page,
5666 and store the offset from this entry to the desired address in
5667 OFFSETP, if it is non-NULL. */
5670 mips_elf_got_page (abfd, info, value, offsetp)
5672 struct bfd_link_info *info;
5677 struct mips_got_info *g;
5679 bfd_byte *last_entry;
5683 g = mips_elf_got_info (elf_hash_table (info)->dynobj, &sgot);
5685 /* Look to see if we aleady have an appropriate entry. */
5686 last_entry = sgot->contents + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno;
5687 for (entry = (sgot->contents
5688 + MIPS_ELF_GOT_SIZE (abfd) * MIPS_RESERVED_GOTNO);
5689 entry != last_entry;
5690 entry += MIPS_ELF_GOT_SIZE (abfd))
5692 address = MIPS_ELF_GET_WORD (abfd, entry);
5694 if (!mips_elf_overflow_p (value - address, 16))
5696 /* This entry will serve as the page pointer. We can add a
5697 16-bit number to it to get the actual address. */
5698 index = entry - sgot->contents;
5703 /* If we didn't have an appropriate entry, we create one now. */
5704 if (entry == last_entry)
5705 index = mips_elf_create_local_got_entry (abfd, g, sgot, value);
5709 address = MIPS_ELF_GET_WORD (abfd, entry);
5710 *offsetp = value - address;
5716 /* Find a GOT entry whose higher-order 16 bits are the same as those
5717 for value. Return the index into the GOT for this entry. */
5720 mips_elf_got16_entry (abfd, info, value, external)
5722 struct bfd_link_info *info;
5727 struct mips_got_info *g;
5729 bfd_byte *last_entry;
5735 /* Although the ABI says that it is "the high-order 16 bits" that we
5736 want, it is really the %high value. The complete value is
5737 calculated with a `addiu' of a LO16 relocation, just as with a
5739 value = mips_elf_high (value) << 16;
5742 g = mips_elf_got_info (elf_hash_table (info)->dynobj, &sgot);
5744 /* Look to see if we already have an appropriate entry. */
5745 last_entry = sgot->contents + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno;
5746 for (entry = (sgot->contents
5747 + MIPS_ELF_GOT_SIZE (abfd) * MIPS_RESERVED_GOTNO);
5748 entry != last_entry;
5749 entry += MIPS_ELF_GOT_SIZE (abfd))
5751 address = MIPS_ELF_GET_WORD (abfd, entry);
5752 if (address == value)
5754 /* This entry has the right high-order 16 bits, and the low-order
5755 16 bits are set to zero. */
5756 index = entry - sgot->contents;
5761 /* If we didn't have an appropriate entry, we create one now. */
5762 if (entry == last_entry)
5763 index = mips_elf_create_local_got_entry (abfd, g, sgot, value);
5768 /* Returns the first relocation of type r_type found, beginning with
5769 RELOCATION. RELEND is one-past-the-end of the relocation table. */
5771 static const Elf_Internal_Rela *
5772 mips_elf_next_relocation (r_type, relocation, relend)
5773 unsigned int r_type;
5774 const Elf_Internal_Rela *relocation;
5775 const Elf_Internal_Rela *relend;
5777 /* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be
5778 immediately following. However, for the IRIX6 ABI, the next
5779 relocation may be a composed relocation consisting of several
5780 relocations for the same address. In that case, the R_MIPS_LO16
5781 relocation may occur as one of these. We permit a similar
5782 extension in general, as that is useful for GCC. */
5783 while (relocation < relend)
5785 if (ELF32_R_TYPE (relocation->r_info) == r_type)
5791 /* We didn't find it. */
5792 bfd_set_error (bfd_error_bad_value);
5796 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
5797 is the original relocation, which is now being transformed into a
5798 dynamic relocation. The ADDENDP is adjusted if necessary; the
5799 caller should store the result in place of the original addend. */
5802 mips_elf_create_dynamic_relocation (output_bfd, info, rel, h, sec,
5803 symbol, addendp, input_section)
5805 struct bfd_link_info *info;
5806 const Elf_Internal_Rela *rel;
5807 struct mips_elf_link_hash_entry *h;
5811 asection *input_section;
5813 Elf_Internal_Rel outrel;
5819 r_type = ELF32_R_TYPE (rel->r_info);
5820 dynobj = elf_hash_table (info)->dynobj;
5822 = bfd_get_section_by_name (dynobj,
5823 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd));
5824 BFD_ASSERT (sreloc != NULL);
5825 BFD_ASSERT (sreloc->contents != NULL);
5826 BFD_ASSERT (sreloc->reloc_count * MIPS_ELF_REL_SIZE (output_bfd)
5827 < sreloc->_raw_size);
5831 /* We begin by assuming that the offset for the dynamic relocation
5832 is the same as for the original relocation. We'll adjust this
5833 later to reflect the correct output offsets. */
5834 if (elf_section_data (input_section)->stab_info == NULL)
5835 outrel.r_offset = rel->r_offset;
5838 /* Except that in a stab section things are more complex.
5839 Because we compress stab information, the offset given in the
5840 relocation may not be the one we want; we must let the stabs
5841 machinery tell us the offset. */
5843 = (_bfd_stab_section_offset
5844 (output_bfd, &elf_hash_table (info)->stab_info,
5846 &elf_section_data (input_section)->stab_info,
5848 /* If we didn't need the relocation at all, this value will be
5850 if (outrel.r_offset == (bfd_vma) -1)
5854 /* If we've decided to skip this relocation, just output an empty
5855 record. Note that R_MIPS_NONE == 0, so that this call to memset
5856 is a way of setting R_TYPE to R_MIPS_NONE. */
5858 memset (&outrel, 0, sizeof (outrel));
5862 bfd_vma section_offset;
5864 /* We must now calculate the dynamic symbol table index to use
5865 in the relocation. */
5867 && (! info->symbolic || (h->root.elf_link_hash_flags
5868 & ELF_LINK_HASH_DEF_REGULAR) == 0))
5870 indx = h->root.dynindx;
5871 /* h->root.dynindx may be -1 if this symbol was marked to
5878 if (sec != NULL && bfd_is_abs_section (sec))
5880 else if (sec == NULL || sec->owner == NULL)
5882 bfd_set_error (bfd_error_bad_value);
5887 indx = elf_section_data (sec->output_section)->dynindx;
5892 /* Figure out how far the target of the relocation is from
5893 the beginning of its section. */
5894 section_offset = symbol - sec->output_section->vma;
5895 /* The relocation we're building is section-relative.
5896 Therefore, the original addend must be adjusted by the
5898 *addendp += section_offset;
5899 /* Now, the relocation is just against the section. */
5900 symbol = sec->output_section->vma;
5903 /* If the relocation was previously an absolute relocation and
5904 this symbol will not be referred to by the relocation, we must
5905 adjust it by the value we give it in the dynamic symbol table.
5906 Otherwise leave the job up to the dynamic linker. */
5907 if (!indx && r_type != R_MIPS_REL32)
5910 /* The relocation is always an REL32 relocation because we don't
5911 know where the shared library will wind up at load-time. */
5912 outrel.r_info = ELF32_R_INFO (indx, R_MIPS_REL32);
5914 /* Adjust the output offset of the relocation to reference the
5915 correct location in the output file. */
5916 outrel.r_offset += (input_section->output_section->vma
5917 + input_section->output_offset);
5920 /* Put the relocation back out. We have to use the special
5921 relocation outputter in the 64-bit case since the 64-bit
5922 relocation format is non-standard. */
5923 if (ABI_64_P (output_bfd))
5925 (*get_elf_backend_data (output_bfd)->s->swap_reloc_out)
5926 (output_bfd, &outrel,
5928 + sreloc->reloc_count * sizeof (Elf64_Mips_External_Rel)));
5931 bfd_elf32_swap_reloc_out (output_bfd, &outrel,
5932 (((Elf32_External_Rel *)
5934 + sreloc->reloc_count));
5936 /* Record the index of the first relocation referencing H. This
5937 information is later emitted in the .msym section. */
5939 && (h->min_dyn_reloc_index == 0
5940 || sreloc->reloc_count < h->min_dyn_reloc_index))
5941 h->min_dyn_reloc_index = sreloc->reloc_count;
5943 /* We've now added another relocation. */
5944 ++sreloc->reloc_count;
5946 /* Make sure the output section is writable. The dynamic linker
5947 will be writing to it. */
5948 elf_section_data (input_section->output_section)->this_hdr.sh_flags
5951 /* On IRIX5, make an entry of compact relocation info. */
5952 if (! skip && IRIX_COMPAT (output_bfd) == ict_irix5)
5954 asection *scpt = bfd_get_section_by_name (dynobj, ".compact_rel");
5959 Elf32_crinfo cptrel;
5961 mips_elf_set_cr_format (cptrel, CRF_MIPS_LONG);
5962 cptrel.vaddr = (rel->r_offset
5963 + input_section->output_section->vma
5964 + input_section->output_offset);
5965 if (r_type == R_MIPS_REL32)
5966 mips_elf_set_cr_type (cptrel, CRT_MIPS_REL32);
5968 mips_elf_set_cr_type (cptrel, CRT_MIPS_WORD);
5969 mips_elf_set_cr_dist2to (cptrel, 0);
5970 cptrel.konst = *addendp;
5972 cr = (scpt->contents
5973 + sizeof (Elf32_External_compact_rel));
5974 bfd_elf32_swap_crinfo_out (output_bfd, &cptrel,
5975 ((Elf32_External_crinfo *) cr
5976 + scpt->reloc_count));
5977 ++scpt->reloc_count;
5984 /* Calculate the value produced by the RELOCATION (which comes from
5985 the INPUT_BFD). The ADDEND is the addend to use for this
5986 RELOCATION; RELOCATION->R_ADDEND is ignored.
5988 The result of the relocation calculation is stored in VALUEP.
5989 REQUIRE_JALXP indicates whether or not the opcode used with this
5990 relocation must be JALX.
5992 This function returns bfd_reloc_continue if the caller need take no
5993 further action regarding this relocation, bfd_reloc_notsupported if
5994 something goes dramatically wrong, bfd_reloc_overflow if an
5995 overflow occurs, and bfd_reloc_ok to indicate success. */
5997 static bfd_reloc_status_type
5998 mips_elf_calculate_relocation (abfd,
6012 asection *input_section;
6013 struct bfd_link_info *info;
6014 const Elf_Internal_Rela *relocation;
6016 reloc_howto_type *howto;
6017 Elf_Internal_Sym *local_syms;
6018 asection **local_sections;
6021 boolean *require_jalxp;
6023 /* The eventual value we will return. */
6025 /* The address of the symbol against which the relocation is
6028 /* The final GP value to be used for the relocatable, executable, or
6029 shared object file being produced. */
6030 bfd_vma gp = (bfd_vma) - 1;
6031 /* The place (section offset or address) of the storage unit being
6034 /* The value of GP used to create the relocatable object. */
6035 bfd_vma gp0 = (bfd_vma) - 1;
6036 /* The offset into the global offset table at which the address of
6037 the relocation entry symbol, adjusted by the addend, resides
6038 during execution. */
6039 bfd_vma g = (bfd_vma) - 1;
6040 /* The section in which the symbol referenced by the relocation is
6042 asection *sec = NULL;
6043 struct mips_elf_link_hash_entry *h = NULL;
6044 /* True if the symbol referred to by this relocation is a local
6047 /* True if the symbol referred to by this relocation is "_gp_disp". */
6048 boolean gp_disp_p = false;
6049 Elf_Internal_Shdr *symtab_hdr;
6051 unsigned long r_symndx;
6053 /* True if overflow occurred during the calculation of the
6054 relocation value. */
6055 boolean overflowed_p;
6056 /* True if this relocation refers to a MIPS16 function. */
6057 boolean target_is_16_bit_code_p = false;
6059 /* Parse the relocation. */
6060 r_symndx = ELF32_R_SYM (relocation->r_info);
6061 r_type = ELF32_R_TYPE (relocation->r_info);
6062 p = (input_section->output_section->vma
6063 + input_section->output_offset
6064 + relocation->r_offset);
6066 /* Assume that there will be no overflow. */
6067 overflowed_p = false;
6069 /* Figure out whether or not the symbol is local, and get the offset
6070 used in the array of hash table entries. */
6071 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
6072 local_p = mips_elf_local_relocation_p (input_bfd, relocation,
6073 local_sections, false);
6074 if (! elf_bad_symtab (input_bfd))
6075 extsymoff = symtab_hdr->sh_info;
6078 /* The symbol table does not follow the rule that local symbols
6079 must come before globals. */
6083 /* Figure out the value of the symbol. */
6086 Elf_Internal_Sym *sym;
6088 sym = local_syms + r_symndx;
6089 sec = local_sections[r_symndx];
6091 symbol = sec->output_section->vma + sec->output_offset;
6092 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
6093 symbol += sym->st_value;
6095 /* MIPS16 text labels should be treated as odd. */
6096 if (sym->st_other == STO_MIPS16)
6099 /* Record the name of this symbol, for our caller. */
6100 *namep = bfd_elf_string_from_elf_section (input_bfd,
6101 symtab_hdr->sh_link,
6104 *namep = bfd_section_name (input_bfd, sec);
6106 target_is_16_bit_code_p = (sym->st_other == STO_MIPS16);
6110 /* For global symbols we look up the symbol in the hash-table. */
6111 h = ((struct mips_elf_link_hash_entry *)
6112 elf_sym_hashes (input_bfd) [r_symndx - extsymoff]);
6113 /* Find the real hash-table entry for this symbol. */
6114 while (h->root.root.type == bfd_link_hash_indirect
6115 || h->root.root.type == bfd_link_hash_warning)
6116 h = (struct mips_elf_link_hash_entry *) h->root.root.u.i.link;
6118 /* Record the name of this symbol, for our caller. */
6119 *namep = h->root.root.root.string;
6121 /* See if this is the special _gp_disp symbol. Note that such a
6122 symbol must always be a global symbol. */
6123 if (strcmp (h->root.root.root.string, "_gp_disp") == 0)
6125 /* Relocations against _gp_disp are permitted only with
6126 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
6127 if (r_type != R_MIPS_HI16 && r_type != R_MIPS_LO16)
6128 return bfd_reloc_notsupported;
6132 /* If this symbol is defined, calculate its address. Note that
6133 _gp_disp is a magic symbol, always implicitly defined by the
6134 linker, so it's inappropriate to check to see whether or not
6136 else if ((h->root.root.type == bfd_link_hash_defined
6137 || h->root.root.type == bfd_link_hash_defweak)
6138 && h->root.root.u.def.section)
6140 sec = h->root.root.u.def.section;
6141 if (sec->output_section)
6142 symbol = (h->root.root.u.def.value
6143 + sec->output_section->vma
6144 + sec->output_offset);
6146 symbol = h->root.root.u.def.value;
6148 else if (h->root.root.type == bfd_link_hash_undefweak)
6149 /* We allow relocations against undefined weak symbols, giving
6150 it the value zero, so that you can undefined weak functions
6151 and check to see if they exist by looking at their
6154 else if (info->shared
6155 && (!info->symbolic || info->allow_shlib_undefined)
6156 && !info->no_undefined
6157 && ELF_ST_VISIBILITY (h->root.other) == STV_DEFAULT)
6159 else if (strcmp (h->root.root.root.string, "_DYNAMIC_LINK") == 0 ||
6160 strcmp (h->root.root.root.string, "_DYNAMIC_LINKING") == 0)
6162 /* If this is a dynamic link, we should have created a
6163 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
6164 in in mips_elf_create_dynamic_sections.
6165 Otherwise, we should define the symbol with a value of 0.
6166 FIXME: It should probably get into the symbol table
6168 BFD_ASSERT (! info->shared);
6169 BFD_ASSERT (bfd_get_section_by_name (abfd, ".dynamic") == NULL);
6174 if (! ((*info->callbacks->undefined_symbol)
6175 (info, h->root.root.root.string, input_bfd,
6176 input_section, relocation->r_offset,
6177 (!info->shared || info->no_undefined
6178 || ELF_ST_VISIBILITY (h->root.other)))))
6179 return bfd_reloc_undefined;
6183 target_is_16_bit_code_p = (h->root.other == STO_MIPS16);
6186 /* If this is a 32-bit call to a 16-bit function with a stub, we
6187 need to redirect the call to the stub, unless we're already *in*
6189 if (r_type != R_MIPS16_26 && !info->relocateable
6190 && ((h != NULL && h->fn_stub != NULL)
6191 || (local_p && elf_tdata (input_bfd)->local_stubs != NULL
6192 && elf_tdata (input_bfd)->local_stubs[r_symndx] != NULL))
6193 && !mips_elf_stub_section_p (input_bfd, input_section))
6195 /* This is a 32-bit call to a 16-bit function. We should
6196 have already noticed that we were going to need the
6199 sec = elf_tdata (input_bfd)->local_stubs[r_symndx];
6202 BFD_ASSERT (h->need_fn_stub);
6206 symbol = sec->output_section->vma + sec->output_offset;
6208 /* If this is a 16-bit call to a 32-bit function with a stub, we
6209 need to redirect the call to the stub. */
6210 else if (r_type == R_MIPS16_26 && !info->relocateable
6212 && (h->call_stub != NULL || h->call_fp_stub != NULL)
6213 && !target_is_16_bit_code_p)
6215 /* If both call_stub and call_fp_stub are defined, we can figure
6216 out which one to use by seeing which one appears in the input
6218 if (h->call_stub != NULL && h->call_fp_stub != NULL)
6223 for (o = input_bfd->sections; o != NULL; o = o->next)
6225 if (strncmp (bfd_get_section_name (input_bfd, o),
6226 CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0)
6228 sec = h->call_fp_stub;
6235 else if (h->call_stub != NULL)
6238 sec = h->call_fp_stub;
6240 BFD_ASSERT (sec->_raw_size > 0);
6241 symbol = sec->output_section->vma + sec->output_offset;
6244 /* Calls from 16-bit code to 32-bit code and vice versa require the
6245 special jalx instruction. */
6246 *require_jalxp = (!info->relocateable
6247 && ((r_type == R_MIPS16_26) != target_is_16_bit_code_p));
6249 local_p = mips_elf_local_relocation_p (input_bfd, relocation,
6250 local_sections, true);
6252 /* If we haven't already determined the GOT offset, or the GP value,
6253 and we're going to need it, get it now. */
6258 case R_MIPS_GOT_DISP:
6259 case R_MIPS_GOT_HI16:
6260 case R_MIPS_CALL_HI16:
6261 case R_MIPS_GOT_LO16:
6262 case R_MIPS_CALL_LO16:
6263 /* Find the index into the GOT where this value is located. */
6266 BFD_ASSERT (addend == 0);
6267 g = mips_elf_global_got_index
6268 (elf_hash_table (info)->dynobj,
6269 (struct elf_link_hash_entry *) h);
6270 if (! elf_hash_table(info)->dynamic_sections_created
6272 && (info->symbolic || h->root.dynindx == -1)
6273 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
6275 /* This is a static link or a -Bsymbolic link. The
6276 symbol is defined locally, or was forced to be local.
6277 We must initialize this entry in the GOT. */
6278 asection *sgot = mips_elf_got_section(elf_hash_table
6280 MIPS_ELF_PUT_WORD (elf_hash_table (info)->dynobj,
6281 symbol + addend, sgot->contents + g);
6284 else if (r_type == R_MIPS_GOT16 || r_type == R_MIPS_CALL16)
6285 /* There's no need to create a local GOT entry here; the
6286 calculation for a local GOT16 entry does not involve G. */
6290 g = mips_elf_local_got_index (abfd, info, symbol + addend);
6291 if (g == (bfd_vma) -1)
6295 /* Convert GOT indices to actual offsets. */
6296 g = mips_elf_got_offset_from_index (elf_hash_table (info)->dynobj,
6302 case R_MIPS_GPREL16:
6303 case R_MIPS_GPREL32:
6304 case R_MIPS_LITERAL:
6305 gp0 = _bfd_get_gp_value (input_bfd);
6306 gp = _bfd_get_gp_value (abfd);
6313 /* Figure out what kind of relocation is being performed. */
6317 return bfd_reloc_continue;
6320 value = symbol + mips_elf_sign_extend (addend, 16);
6321 overflowed_p = mips_elf_overflow_p (value, 16);
6328 || (elf_hash_table (info)->dynamic_sections_created
6330 && ((h->root.elf_link_hash_flags
6331 & ELF_LINK_HASH_DEF_DYNAMIC) != 0)
6332 && ((h->root.elf_link_hash_flags
6333 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
6335 && (input_section->flags & SEC_ALLOC) != 0)
6337 /* If we're creating a shared library, or this relocation is
6338 against a symbol in a shared library, then we can't know
6339 where the symbol will end up. So, we create a relocation
6340 record in the output, and leave the job up to the dynamic
6343 if (!mips_elf_create_dynamic_relocation (abfd,
6355 if (r_type != R_MIPS_REL32)
6356 value = symbol + addend;
6360 value &= howto->dst_mask;
6365 case R_MIPS_GNU_REL_LO16:
6366 value = symbol + addend - p;
6367 value &= howto->dst_mask;
6370 case R_MIPS_GNU_REL16_S2:
6371 value = symbol + mips_elf_sign_extend (addend << 2, 18) - p;
6372 overflowed_p = mips_elf_overflow_p (value, 18);
6373 value = (value >> 2) & howto->dst_mask;
6376 case R_MIPS_GNU_REL_HI16:
6377 value = mips_elf_high (addend + symbol - p);
6378 value &= howto->dst_mask;
6382 /* The calculation for R_MIPS16_26 is just the same as for an
6383 R_MIPS_26. It's only the storage of the relocated field into
6384 the output file that's different. That's handled in
6385 mips_elf_perform_relocation. So, we just fall through to the
6386 R_MIPS_26 case here. */
6389 value = (((addend << 2) | ((p + 4) & 0xf0000000)) + symbol) >> 2;
6391 value = (mips_elf_sign_extend (addend << 2, 28) + symbol) >> 2;
6392 value &= howto->dst_mask;
6398 value = mips_elf_high (addend + symbol);
6399 value &= howto->dst_mask;
6403 value = mips_elf_high (addend + gp - p);
6404 overflowed_p = mips_elf_overflow_p (value, 16);
6410 value = (symbol + addend) & howto->dst_mask;
6413 value = addend + gp - p + 4;
6414 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
6415 for overflow. But, on, say, Irix 5, relocations against
6416 _gp_disp are normally generated from the .cpload
6417 pseudo-op. It generates code that normally looks like
6420 lui $gp,%hi(_gp_disp)
6421 addiu $gp,$gp,%lo(_gp_disp)
6424 Here $t9 holds the address of the function being called,
6425 as required by the MIPS ELF ABI. The R_MIPS_LO16
6426 relocation can easily overflow in this situation, but the
6427 R_MIPS_HI16 relocation will handle the overflow.
6428 Therefore, we consider this a bug in the MIPS ABI, and do
6429 not check for overflow here. */
6433 case R_MIPS_LITERAL:
6434 /* Because we don't merge literal sections, we can handle this
6435 just like R_MIPS_GPREL16. In the long run, we should merge
6436 shared literals, and then we will need to additional work
6441 case R_MIPS16_GPREL:
6442 /* The R_MIPS16_GPREL performs the same calculation as
6443 R_MIPS_GPREL16, but stores the relocated bits in a different
6444 order. We don't need to do anything special here; the
6445 differences are handled in mips_elf_perform_relocation. */
6446 case R_MIPS_GPREL16:
6448 value = mips_elf_sign_extend (addend, 16) + symbol + gp0 - gp;
6450 value = mips_elf_sign_extend (addend, 16) + symbol - gp;
6451 overflowed_p = mips_elf_overflow_p (value, 16);
6460 /* The special case is when the symbol is forced to be local. We
6461 need the full address in the GOT since no R_MIPS_LO16 relocation
6463 forced = ! mips_elf_local_relocation_p (input_bfd, relocation,
6464 local_sections, false);
6465 value = mips_elf_got16_entry (abfd, info, symbol + addend, forced);
6466 if (value == (bfd_vma) -1)
6469 = mips_elf_got_offset_from_index (elf_hash_table (info)->dynobj,
6472 overflowed_p = mips_elf_overflow_p (value, 16);
6478 case R_MIPS_GOT_DISP:
6480 overflowed_p = mips_elf_overflow_p (value, 16);
6483 case R_MIPS_GPREL32:
6484 value = (addend + symbol + gp0 - gp) & howto->dst_mask;
6488 value = mips_elf_sign_extend (addend, 16) + symbol - p;
6489 overflowed_p = mips_elf_overflow_p (value, 16);
6490 value = (bfd_vma) ((bfd_signed_vma) value / 4);
6493 case R_MIPS_GOT_HI16:
6494 case R_MIPS_CALL_HI16:
6495 /* We're allowed to handle these two relocations identically.
6496 The dynamic linker is allowed to handle the CALL relocations
6497 differently by creating a lazy evaluation stub. */
6499 value = mips_elf_high (value);
6500 value &= howto->dst_mask;
6503 case R_MIPS_GOT_LO16:
6504 case R_MIPS_CALL_LO16:
6505 value = g & howto->dst_mask;
6508 case R_MIPS_GOT_PAGE:
6509 value = mips_elf_got_page (abfd, info, symbol + addend, NULL);
6510 if (value == (bfd_vma) -1)
6512 value = mips_elf_got_offset_from_index (elf_hash_table (info)->dynobj,
6515 overflowed_p = mips_elf_overflow_p (value, 16);
6518 case R_MIPS_GOT_OFST:
6519 mips_elf_got_page (abfd, info, symbol + addend, &value);
6520 overflowed_p = mips_elf_overflow_p (value, 16);
6524 value = symbol - addend;
6525 value &= howto->dst_mask;
6529 value = mips_elf_higher (addend + symbol);
6530 value &= howto->dst_mask;
6533 case R_MIPS_HIGHEST:
6534 value = mips_elf_highest (addend + symbol);
6535 value &= howto->dst_mask;
6538 case R_MIPS_SCN_DISP:
6539 value = symbol + addend - sec->output_offset;
6540 value &= howto->dst_mask;
6545 /* Both of these may be ignored. R_MIPS_JALR is an optimization
6546 hint; we could improve performance by honoring that hint. */
6547 return bfd_reloc_continue;
6549 case R_MIPS_GNU_VTINHERIT:
6550 case R_MIPS_GNU_VTENTRY:
6551 /* We don't do anything with these at present. */
6552 return bfd_reloc_continue;
6555 /* An unrecognized relocation type. */
6556 return bfd_reloc_notsupported;
6559 /* Store the VALUE for our caller. */
6561 return overflowed_p ? bfd_reloc_overflow : bfd_reloc_ok;
6564 /* Obtain the field relocated by RELOCATION. */
6567 mips_elf_obtain_contents (howto, relocation, input_bfd, contents)
6568 reloc_howto_type *howto;
6569 const Elf_Internal_Rela *relocation;
6574 bfd_byte *location = contents + relocation->r_offset;
6576 /* Obtain the bytes. */
6577 x = bfd_get (((bfd_vma)(8 * bfd_get_reloc_size (howto))), input_bfd, location);
6579 if ((ELF32_R_TYPE (relocation->r_info) == R_MIPS16_26
6580 || ELF32_R_TYPE (relocation->r_info) == R_MIPS16_GPREL)
6581 && bfd_little_endian (input_bfd))
6582 /* The two 16-bit words will be reversed on a little-endian
6583 system. See mips_elf_perform_relocation for more details. */
6584 x = (((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16));
6589 /* It has been determined that the result of the RELOCATION is the
6590 VALUE. Use HOWTO to place VALUE into the output file at the
6591 appropriate position. The SECTION is the section to which the
6592 relocation applies. If REQUIRE_JALX is true, then the opcode used
6593 for the relocation must be either JAL or JALX, and it is
6594 unconditionally converted to JALX.
6596 Returns false if anything goes wrong. */
6599 mips_elf_perform_relocation (info, howto, relocation, value,
6600 input_bfd, input_section,
6601 contents, require_jalx)
6602 struct bfd_link_info *info;
6603 reloc_howto_type *howto;
6604 const Elf_Internal_Rela *relocation;
6607 asection *input_section;
6609 boolean require_jalx;
6613 int r_type = ELF32_R_TYPE (relocation->r_info);
6615 /* Figure out where the relocation is occurring. */
6616 location = contents + relocation->r_offset;
6618 /* Obtain the current value. */
6619 x = mips_elf_obtain_contents (howto, relocation, input_bfd, contents);
6621 /* Clear the field we are setting. */
6622 x &= ~howto->dst_mask;
6624 /* If this is the R_MIPS16_26 relocation, we must store the
6625 value in a funny way. */
6626 if (r_type == R_MIPS16_26)
6628 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
6629 Most mips16 instructions are 16 bits, but these instructions
6632 The format of these instructions is:
6634 +--------------+--------------------------------+
6635 ! JALX ! X! Imm 20:16 ! Imm 25:21 !
6636 +--------------+--------------------------------+
6638 +-----------------------------------------------+
6640 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
6641 Note that the immediate value in the first word is swapped.
6643 When producing a relocateable object file, R_MIPS16_26 is
6644 handled mostly like R_MIPS_26. In particular, the addend is
6645 stored as a straight 26-bit value in a 32-bit instruction.
6646 (gas makes life simpler for itself by never adjusting a
6647 R_MIPS16_26 reloc to be against a section, so the addend is
6648 always zero). However, the 32 bit instruction is stored as 2
6649 16-bit values, rather than a single 32-bit value. In a
6650 big-endian file, the result is the same; in a little-endian
6651 file, the two 16-bit halves of the 32 bit value are swapped.
6652 This is so that a disassembler can recognize the jal
6655 When doing a final link, R_MIPS16_26 is treated as a 32 bit
6656 instruction stored as two 16-bit values. The addend A is the
6657 contents of the targ26 field. The calculation is the same as
6658 R_MIPS_26. When storing the calculated value, reorder the
6659 immediate value as shown above, and don't forget to store the
6660 value as two 16-bit values.
6662 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
6666 +--------+----------------------+
6670 +--------+----------------------+
6673 +----------+------+-------------+
6677 +----------+--------------------+
6678 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
6679 ((sub1 << 16) | sub2)).
6681 When producing a relocateable object file, the calculation is
6682 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
6683 When producing a fully linked file, the calculation is
6684 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
6685 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff) */
6687 if (!info->relocateable)
6688 /* Shuffle the bits according to the formula above. */
6689 value = (((value & 0x1f0000) << 5)
6690 | ((value & 0x3e00000) >> 5)
6691 | (value & 0xffff));
6693 else if (r_type == R_MIPS16_GPREL)
6695 /* R_MIPS16_GPREL is used for GP-relative addressing in mips16
6696 mode. A typical instruction will have a format like this:
6698 +--------------+--------------------------------+
6699 ! EXTEND ! Imm 10:5 ! Imm 15:11 !
6700 +--------------+--------------------------------+
6701 ! Major ! rx ! ry ! Imm 4:0 !
6702 +--------------+--------------------------------+
6704 EXTEND is the five bit value 11110. Major is the instruction
6707 This is handled exactly like R_MIPS_GPREL16, except that the
6708 addend is retrieved and stored as shown in this diagram; that
6709 is, the Imm fields above replace the V-rel16 field.
6711 All we need to do here is shuffle the bits appropriately. As
6712 above, the two 16-bit halves must be swapped on a
6713 little-endian system. */
6714 value = (((value & 0x7e0) << 16)
6715 | ((value & 0xf800) << 5)
6719 /* Set the field. */
6720 x |= (value & howto->dst_mask);
6722 /* If required, turn JAL into JALX. */
6726 bfd_vma opcode = x >> 26;
6727 bfd_vma jalx_opcode;
6729 /* Check to see if the opcode is already JAL or JALX. */
6730 if (r_type == R_MIPS16_26)
6732 ok = ((opcode == 0x6) || (opcode == 0x7));
6737 ok = ((opcode == 0x3) || (opcode == 0x1d));
6741 /* If the opcode is not JAL or JALX, there's a problem. */
6744 (*_bfd_error_handler)
6745 (_("%s: %s+0x%lx: jump to stub routine which is not jal"),
6746 bfd_archive_filename (input_bfd),
6747 input_section->name,
6748 (unsigned long) relocation->r_offset);
6749 bfd_set_error (bfd_error_bad_value);
6753 /* Make this the JALX opcode. */
6754 x = (x & ~(0x3f << 26)) | (jalx_opcode << 26);
6757 /* Swap the high- and low-order 16 bits on little-endian systems
6758 when doing a MIPS16 relocation. */
6759 if ((r_type == R_MIPS16_GPREL || r_type == R_MIPS16_26)
6760 && bfd_little_endian (input_bfd))
6761 x = (((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16));
6763 /* Put the value into the output. */
6764 bfd_put (8 * bfd_get_reloc_size (howto), input_bfd, x, location);
6768 /* Returns true if SECTION is a MIPS16 stub section. */
6771 mips_elf_stub_section_p (abfd, section)
6772 bfd *abfd ATTRIBUTE_UNUSED;
6775 const char *name = bfd_get_section_name (abfd, section);
6777 return (strncmp (name, FN_STUB, sizeof FN_STUB - 1) == 0
6778 || strncmp (name, CALL_STUB, sizeof CALL_STUB - 1) == 0
6779 || strncmp (name, CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0);
6782 /* Relocate a MIPS ELF section. */
6785 _bfd_mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
6786 contents, relocs, local_syms, local_sections)
6788 struct bfd_link_info *info;
6790 asection *input_section;
6792 Elf_Internal_Rela *relocs;
6793 Elf_Internal_Sym *local_syms;
6794 asection **local_sections;
6796 Elf_Internal_Rela *rel;
6797 const Elf_Internal_Rela *relend;
6799 boolean use_saved_addend_p = false;
6800 struct elf_backend_data *bed;
6802 bed = get_elf_backend_data (output_bfd);
6803 relend = relocs + input_section->reloc_count * bed->s->int_rels_per_ext_rel;
6804 for (rel = relocs; rel < relend; ++rel)
6808 reloc_howto_type *howto;
6809 boolean require_jalx;
6810 /* True if the relocation is a RELA relocation, rather than a
6812 boolean rela_relocation_p = true;
6813 unsigned int r_type = ELF32_R_TYPE (rel->r_info);
6814 const char * msg = (const char *) NULL;
6816 /* Find the relocation howto for this relocation. */
6817 if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd))
6819 /* Some 32-bit code uses R_MIPS_64. In particular, people use
6820 64-bit code, but make sure all their addresses are in the
6821 lowermost or uppermost 32-bit section of the 64-bit address
6822 space. Thus, when they use an R_MIPS_64 they mean what is
6823 usually meant by R_MIPS_32, with the exception that the
6824 stored value is sign-extended to 64 bits. */
6825 howto = elf_mips_howto_table + R_MIPS_32;
6827 /* On big-endian systems, we need to lie about the position
6829 if (bfd_big_endian (input_bfd))
6833 howto = mips_rtype_to_howto (r_type);
6835 if (!use_saved_addend_p)
6837 Elf_Internal_Shdr *rel_hdr;
6839 /* If these relocations were originally of the REL variety,
6840 we must pull the addend out of the field that will be
6841 relocated. Otherwise, we simply use the contents of the
6842 RELA relocation. To determine which flavor or relocation
6843 this is, we depend on the fact that the INPUT_SECTION's
6844 REL_HDR is read before its REL_HDR2. */
6845 rel_hdr = &elf_section_data (input_section)->rel_hdr;
6846 if ((size_t) (rel - relocs)
6847 >= (NUM_SHDR_ENTRIES (rel_hdr) * bed->s->int_rels_per_ext_rel))
6848 rel_hdr = elf_section_data (input_section)->rel_hdr2;
6849 if (rel_hdr->sh_entsize == MIPS_ELF_REL_SIZE (input_bfd))
6851 /* Note that this is a REL relocation. */
6852 rela_relocation_p = false;
6854 /* Get the addend, which is stored in the input file. */
6855 addend = mips_elf_obtain_contents (howto,
6859 addend &= howto->src_mask;
6861 /* For some kinds of relocations, the ADDEND is a
6862 combination of the addend stored in two different
6864 if (r_type == R_MIPS_HI16
6865 || r_type == R_MIPS_GNU_REL_HI16
6866 || (r_type == R_MIPS_GOT16
6867 && mips_elf_local_relocation_p (input_bfd, rel,
6868 local_sections, false)))
6871 const Elf_Internal_Rela *lo16_relocation;
6872 reloc_howto_type *lo16_howto;
6875 /* The combined value is the sum of the HI16 addend,
6876 left-shifted by sixteen bits, and the LO16
6877 addend, sign extended. (Usually, the code does
6878 a `lui' of the HI16 value, and then an `addiu' of
6881 Scan ahead to find a matching LO16 relocation. */
6882 if (r_type == R_MIPS_GNU_REL_HI16)
6883 lo = R_MIPS_GNU_REL_LO16;
6887 = mips_elf_next_relocation (lo, rel, relend);
6888 if (lo16_relocation == NULL)
6891 /* Obtain the addend kept there. */
6892 lo16_howto = mips_rtype_to_howto (lo);
6893 l = mips_elf_obtain_contents (lo16_howto,
6895 input_bfd, contents);
6896 l &= lo16_howto->src_mask;
6897 l = mips_elf_sign_extend (l, 16);
6901 /* Compute the combined addend. */
6904 else if (r_type == R_MIPS16_GPREL)
6906 /* The addend is scrambled in the object file. See
6907 mips_elf_perform_relocation for details on the
6909 addend = (((addend & 0x1f0000) >> 5)
6910 | ((addend & 0x7e00000) >> 16)
6915 addend = rel->r_addend;
6918 if (info->relocateable)
6920 Elf_Internal_Sym *sym;
6921 unsigned long r_symndx;
6923 if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd)
6924 && bfd_big_endian (input_bfd))
6927 /* Since we're just relocating, all we need to do is copy
6928 the relocations back out to the object file, unless
6929 they're against a section symbol, in which case we need
6930 to adjust by the section offset, or unless they're GP
6931 relative in which case we need to adjust by the amount
6932 that we're adjusting GP in this relocateable object. */
6934 if (!mips_elf_local_relocation_p (input_bfd, rel, local_sections,
6936 /* There's nothing to do for non-local relocations. */
6939 if (r_type == R_MIPS16_GPREL
6940 || r_type == R_MIPS_GPREL16
6941 || r_type == R_MIPS_GPREL32
6942 || r_type == R_MIPS_LITERAL)
6943 addend -= (_bfd_get_gp_value (output_bfd)
6944 - _bfd_get_gp_value (input_bfd));
6945 else if (r_type == R_MIPS_26 || r_type == R_MIPS16_26
6946 || r_type == R_MIPS_GNU_REL16_S2)
6947 /* The addend is stored without its two least
6948 significant bits (which are always zero.) In a
6949 non-relocateable link, calculate_relocation will do
6950 this shift; here, we must do it ourselves. */
6953 r_symndx = ELF32_R_SYM (rel->r_info);
6954 sym = local_syms + r_symndx;
6955 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
6956 /* Adjust the addend appropriately. */
6957 addend += local_sections[r_symndx]->output_offset;
6959 /* If the relocation is for a R_MIPS_HI16 or R_MIPS_GOT16,
6960 then we only want to write out the high-order 16 bits.
6961 The subsequent R_MIPS_LO16 will handle the low-order bits. */
6962 if (r_type == R_MIPS_HI16 || r_type == R_MIPS_GOT16
6963 || r_type == R_MIPS_GNU_REL_HI16)
6964 addend = mips_elf_high (addend);
6965 /* If the relocation is for an R_MIPS_26 relocation, then
6966 the two low-order bits are not stored in the object file;
6967 they are implicitly zero. */
6968 else if (r_type == R_MIPS_26 || r_type == R_MIPS16_26
6969 || r_type == R_MIPS_GNU_REL16_S2)
6972 if (rela_relocation_p)
6973 /* If this is a RELA relocation, just update the addend.
6974 We have to cast away constness for REL. */
6975 rel->r_addend = addend;
6978 /* Otherwise, we have to write the value back out. Note
6979 that we use the source mask, rather than the
6980 destination mask because the place to which we are
6981 writing will be source of the addend in the final
6983 addend &= howto->src_mask;
6985 if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd))
6986 /* See the comment above about using R_MIPS_64 in the 32-bit
6987 ABI. Here, we need to update the addend. It would be
6988 possible to get away with just using the R_MIPS_32 reloc
6989 but for endianness. */
6995 if (addend & ((bfd_vma) 1 << 31))
6997 sign_bits = ((bfd_vma) 1 << 32) - 1;
7004 /* If we don't know that we have a 64-bit type,
7005 do two separate stores. */
7006 if (bfd_big_endian (input_bfd))
7008 /* Store the sign-bits (which are most significant)
7010 low_bits = sign_bits;
7016 high_bits = sign_bits;
7018 bfd_put_32 (input_bfd, low_bits,
7019 contents + rel->r_offset);
7020 bfd_put_32 (input_bfd, high_bits,
7021 contents + rel->r_offset + 4);
7025 if (!mips_elf_perform_relocation (info, howto, rel, addend,
7026 input_bfd, input_section,
7031 /* Go on to the next relocation. */
7035 /* In the N32 and 64-bit ABIs there may be multiple consecutive
7036 relocations for the same offset. In that case we are
7037 supposed to treat the output of each relocation as the addend
7039 if (rel + 1 < relend
7040 && rel->r_offset == rel[1].r_offset
7041 && ELF32_R_TYPE (rel[1].r_info) != R_MIPS_NONE)
7042 use_saved_addend_p = true;
7044 use_saved_addend_p = false;
7046 /* Figure out what value we are supposed to relocate. */
7047 switch (mips_elf_calculate_relocation (output_bfd,
7060 case bfd_reloc_continue:
7061 /* There's nothing to do. */
7064 case bfd_reloc_undefined:
7065 /* mips_elf_calculate_relocation already called the
7066 undefined_symbol callback. There's no real point in
7067 trying to perform the relocation at this point, so we
7068 just skip ahead to the next relocation. */
7071 case bfd_reloc_notsupported:
7072 msg = _("internal error: unsupported relocation error");
7073 info->callbacks->warning
7074 (info, msg, name, input_bfd, input_section, rel->r_offset);
7077 case bfd_reloc_overflow:
7078 if (use_saved_addend_p)
7079 /* Ignore overflow until we reach the last relocation for
7080 a given location. */
7084 BFD_ASSERT (name != NULL);
7085 if (! ((*info->callbacks->reloc_overflow)
7086 (info, name, howto->name, (bfd_vma) 0,
7087 input_bfd, input_section, rel->r_offset)))
7100 /* If we've got another relocation for the address, keep going
7101 until we reach the last one. */
7102 if (use_saved_addend_p)
7108 if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd))
7109 /* See the comment above about using R_MIPS_64 in the 32-bit
7110 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
7111 that calculated the right value. Now, however, we
7112 sign-extend the 32-bit result to 64-bits, and store it as a
7113 64-bit value. We are especially generous here in that we
7114 go to extreme lengths to support this usage on systems with
7115 only a 32-bit VMA. */
7121 if (value & ((bfd_vma) 1 << 31))
7123 sign_bits = ((bfd_vma) 1 << 32) - 1;
7130 /* If we don't know that we have a 64-bit type,
7131 do two separate stores. */
7132 if (bfd_big_endian (input_bfd))
7134 /* Undo what we did above. */
7136 /* Store the sign-bits (which are most significant)
7138 low_bits = sign_bits;
7144 high_bits = sign_bits;
7146 bfd_put_32 (input_bfd, low_bits,
7147 contents + rel->r_offset);
7148 bfd_put_32 (input_bfd, high_bits,
7149 contents + rel->r_offset + 4);
7153 /* Actually perform the relocation. */
7154 if (!mips_elf_perform_relocation (info, howto, rel, value, input_bfd,
7155 input_section, contents,
7163 /* This hook function is called before the linker writes out a global
7164 symbol. We mark symbols as small common if appropriate. This is
7165 also where we undo the increment of the value for a mips16 symbol. */
7168 _bfd_mips_elf_link_output_symbol_hook (abfd, info, name, sym, input_sec)
7169 bfd *abfd ATTRIBUTE_UNUSED;
7170 struct bfd_link_info *info ATTRIBUTE_UNUSED;
7171 const char *name ATTRIBUTE_UNUSED;
7172 Elf_Internal_Sym *sym;
7173 asection *input_sec;
7175 /* If we see a common symbol, which implies a relocatable link, then
7176 if a symbol was small common in an input file, mark it as small
7177 common in the output file. */
7178 if (sym->st_shndx == SHN_COMMON
7179 && strcmp (input_sec->name, ".scommon") == 0)
7180 sym->st_shndx = SHN_MIPS_SCOMMON;
7182 if (sym->st_other == STO_MIPS16
7183 && (sym->st_value & 1) != 0)
7189 /* Functions for the dynamic linker. */
7191 /* The name of the dynamic interpreter. This is put in the .interp
7194 #define ELF_DYNAMIC_INTERPRETER(abfd) \
7195 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
7196 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
7197 : "/usr/lib/libc.so.1")
7199 /* Create dynamic sections when linking against a dynamic object. */
7202 _bfd_mips_elf_create_dynamic_sections (abfd, info)
7204 struct bfd_link_info *info;
7206 struct elf_link_hash_entry *h;
7208 register asection *s;
7209 const char * const *namep;
7211 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
7212 | SEC_LINKER_CREATED | SEC_READONLY);
7214 /* Mips ABI requests the .dynamic section to be read only. */
7215 s = bfd_get_section_by_name (abfd, ".dynamic");
7218 if (! bfd_set_section_flags (abfd, s, flags))
7222 /* We need to create .got section. */
7223 if (! mips_elf_create_got_section (abfd, info))
7226 /* Create the .msym section on IRIX6. It is used by the dynamic
7227 linker to speed up dynamic relocations, and to avoid computing
7228 the ELF hash for symbols. */
7229 if (IRIX_COMPAT (abfd) == ict_irix6
7230 && !mips_elf_create_msym_section (abfd))
7233 /* Create .stub section. */
7234 if (bfd_get_section_by_name (abfd,
7235 MIPS_ELF_STUB_SECTION_NAME (abfd)) == NULL)
7237 s = bfd_make_section (abfd, MIPS_ELF_STUB_SECTION_NAME (abfd));
7239 || ! bfd_set_section_flags (abfd, s, flags | SEC_CODE)
7240 || ! bfd_set_section_alignment (abfd, s,
7241 MIPS_ELF_LOG_FILE_ALIGN (abfd)))
7245 if ((IRIX_COMPAT (abfd) == ict_irix5 || IRIX_COMPAT (abfd) == ict_none)
7247 && bfd_get_section_by_name (abfd, ".rld_map") == NULL)
7249 s = bfd_make_section (abfd, ".rld_map");
7251 || ! bfd_set_section_flags (abfd, s, flags &~ (flagword) SEC_READONLY)
7252 || ! bfd_set_section_alignment (abfd, s,
7253 MIPS_ELF_LOG_FILE_ALIGN (abfd)))
7257 /* On IRIX5, we adjust add some additional symbols and change the
7258 alignments of several sections. There is no ABI documentation
7259 indicating that this is necessary on IRIX6, nor any evidence that
7260 the linker takes such action. */
7261 if (IRIX_COMPAT (abfd) == ict_irix5)
7263 for (namep = mips_elf_dynsym_rtproc_names; *namep != NULL; namep++)
7266 if (! (_bfd_generic_link_add_one_symbol
7267 (info, abfd, *namep, BSF_GLOBAL, bfd_und_section_ptr,
7268 (bfd_vma) 0, (const char *) NULL, false,
7269 get_elf_backend_data (abfd)->collect,
7270 (struct bfd_link_hash_entry **) &h)))
7272 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
7273 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
7274 h->type = STT_SECTION;
7276 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
7280 /* We need to create a .compact_rel section. */
7281 if (SGI_COMPAT (abfd))
7283 if (!mips_elf_create_compact_rel_section (abfd, info))
7287 /* Change aligments of some sections. */
7288 s = bfd_get_section_by_name (abfd, ".hash");
7290 bfd_set_section_alignment (abfd, s, 4);
7291 s = bfd_get_section_by_name (abfd, ".dynsym");
7293 bfd_set_section_alignment (abfd, s, 4);
7294 s = bfd_get_section_by_name (abfd, ".dynstr");
7296 bfd_set_section_alignment (abfd, s, 4);
7297 s = bfd_get_section_by_name (abfd, ".reginfo");
7299 bfd_set_section_alignment (abfd, s, 4);
7300 s = bfd_get_section_by_name (abfd, ".dynamic");
7302 bfd_set_section_alignment (abfd, s, 4);
7308 if (SGI_COMPAT (abfd))
7310 if (!(_bfd_generic_link_add_one_symbol
7311 (info, abfd, "_DYNAMIC_LINK", BSF_GLOBAL, bfd_abs_section_ptr,
7312 (bfd_vma) 0, (const char *) NULL, false,
7313 get_elf_backend_data (abfd)->collect,
7314 (struct bfd_link_hash_entry **) &h)))
7319 /* For normal mips it is _DYNAMIC_LINKING. */
7320 if (!(_bfd_generic_link_add_one_symbol
7321 (info, abfd, "_DYNAMIC_LINKING", BSF_GLOBAL,
7322 bfd_abs_section_ptr, (bfd_vma) 0, (const char *) NULL, false,
7323 get_elf_backend_data (abfd)->collect,
7324 (struct bfd_link_hash_entry **) &h)))
7327 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
7328 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
7329 h->type = STT_SECTION;
7331 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
7334 if (! mips_elf_hash_table (info)->use_rld_obj_head)
7336 /* __rld_map is a four byte word located in the .data section
7337 and is filled in by the rtld to contain a pointer to
7338 the _r_debug structure. Its symbol value will be set in
7339 mips_elf_finish_dynamic_symbol. */
7340 s = bfd_get_section_by_name (abfd, ".rld_map");
7341 BFD_ASSERT (s != NULL);
7344 if (SGI_COMPAT (abfd))
7346 if (!(_bfd_generic_link_add_one_symbol
7347 (info, abfd, "__rld_map", BSF_GLOBAL, s,
7348 (bfd_vma) 0, (const char *) NULL, false,
7349 get_elf_backend_data (abfd)->collect,
7350 (struct bfd_link_hash_entry **) &h)))
7355 /* For normal mips the symbol is __RLD_MAP. */
7356 if (!(_bfd_generic_link_add_one_symbol
7357 (info, abfd, "__RLD_MAP", BSF_GLOBAL, s,
7358 (bfd_vma) 0, (const char *) NULL, false,
7359 get_elf_backend_data (abfd)->collect,
7360 (struct bfd_link_hash_entry **) &h)))
7363 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
7364 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
7365 h->type = STT_OBJECT;
7367 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
7375 /* Create the .compact_rel section. */
7378 mips_elf_create_compact_rel_section (abfd, info)
7380 struct bfd_link_info *info ATTRIBUTE_UNUSED;
7383 register asection *s;
7385 if (bfd_get_section_by_name (abfd, ".compact_rel") == NULL)
7387 flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED
7390 s = bfd_make_section (abfd, ".compact_rel");
7392 || ! bfd_set_section_flags (abfd, s, flags)
7393 || ! bfd_set_section_alignment (abfd, s,
7394 MIPS_ELF_LOG_FILE_ALIGN (abfd)))
7397 s->_raw_size = sizeof (Elf32_External_compact_rel);
7403 /* Create the .got section to hold the global offset table. */
7406 mips_elf_create_got_section (abfd, info)
7408 struct bfd_link_info *info;
7411 register asection *s;
7412 struct elf_link_hash_entry *h;
7413 struct mips_got_info *g;
7416 /* This function may be called more than once. */
7417 if (mips_elf_got_section (abfd))
7420 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
7421 | SEC_LINKER_CREATED);
7423 s = bfd_make_section (abfd, ".got");
7425 || ! bfd_set_section_flags (abfd, s, flags)
7426 || ! bfd_set_section_alignment (abfd, s, 4))
7429 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
7430 linker script because we don't want to define the symbol if we
7431 are not creating a global offset table. */
7433 if (! (_bfd_generic_link_add_one_symbol
7434 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
7435 (bfd_vma) 0, (const char *) NULL, false,
7436 get_elf_backend_data (abfd)->collect,
7437 (struct bfd_link_hash_entry **) &h)))
7439 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
7440 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
7441 h->type = STT_OBJECT;
7444 && ! bfd_elf32_link_record_dynamic_symbol (info, h))
7447 /* The first several global offset table entries are reserved. */
7448 s->_raw_size = MIPS_RESERVED_GOTNO * MIPS_ELF_GOT_SIZE (abfd);
7450 amt = sizeof (struct mips_got_info);
7451 g = (struct mips_got_info *) bfd_alloc (abfd, amt);
7454 g->global_gotsym = NULL;
7455 g->local_gotno = MIPS_RESERVED_GOTNO;
7456 g->assigned_gotno = MIPS_RESERVED_GOTNO;
7457 if (elf_section_data (s) == NULL)
7459 amt = sizeof (struct bfd_elf_section_data);
7460 s->used_by_bfd = (PTR) bfd_zalloc (abfd, amt);
7461 if (elf_section_data (s) == NULL)
7464 elf_section_data (s)->tdata = (PTR) g;
7465 elf_section_data (s)->this_hdr.sh_flags
7466 |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
7471 /* Returns the .msym section for ABFD, creating it if it does not
7472 already exist. Returns NULL to indicate error. */
7475 mips_elf_create_msym_section (abfd)
7480 s = bfd_get_section_by_name (abfd, MIPS_ELF_MSYM_SECTION_NAME (abfd));
7483 s = bfd_make_section (abfd, MIPS_ELF_MSYM_SECTION_NAME (abfd));
7485 || !bfd_set_section_flags (abfd, s,
7489 | SEC_LINKER_CREATED
7491 || !bfd_set_section_alignment (abfd, s,
7492 MIPS_ELF_LOG_FILE_ALIGN (abfd)))
7499 /* Add room for N relocations to the .rel.dyn section in ABFD. */
7502 mips_elf_allocate_dynamic_relocations (abfd, n)
7508 s = bfd_get_section_by_name (abfd, MIPS_ELF_REL_DYN_SECTION_NAME (abfd));
7509 BFD_ASSERT (s != NULL);
7511 if (s->_raw_size == 0)
7513 /* Make room for a null element. */
7514 s->_raw_size += MIPS_ELF_REL_SIZE (abfd);
7517 s->_raw_size += n * MIPS_ELF_REL_SIZE (abfd);
7520 /* Look through the relocs for a section during the first phase, and
7521 allocate space in the global offset table. */
7524 _bfd_mips_elf_check_relocs (abfd, info, sec, relocs)
7526 struct bfd_link_info *info;
7528 const Elf_Internal_Rela *relocs;
7532 Elf_Internal_Shdr *symtab_hdr;
7533 struct elf_link_hash_entry **sym_hashes;
7534 struct mips_got_info *g;
7536 const Elf_Internal_Rela *rel;
7537 const Elf_Internal_Rela *rel_end;
7540 struct elf_backend_data *bed;
7542 if (info->relocateable)
7545 dynobj = elf_hash_table (info)->dynobj;
7546 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
7547 sym_hashes = elf_sym_hashes (abfd);
7548 extsymoff = (elf_bad_symtab (abfd)) ? 0 : symtab_hdr->sh_info;
7550 /* Check for the mips16 stub sections. */
7552 name = bfd_get_section_name (abfd, sec);
7553 if (strncmp (name, FN_STUB, sizeof FN_STUB - 1) == 0)
7555 unsigned long r_symndx;
7557 /* Look at the relocation information to figure out which symbol
7560 r_symndx = ELF32_R_SYM (relocs->r_info);
7562 if (r_symndx < extsymoff
7563 || sym_hashes[r_symndx - extsymoff] == NULL)
7567 /* This stub is for a local symbol. This stub will only be
7568 needed if there is some relocation in this BFD, other
7569 than a 16 bit function call, which refers to this symbol. */
7570 for (o = abfd->sections; o != NULL; o = o->next)
7572 Elf_Internal_Rela *sec_relocs;
7573 const Elf_Internal_Rela *r, *rend;
7575 /* We can ignore stub sections when looking for relocs. */
7576 if ((o->flags & SEC_RELOC) == 0
7577 || o->reloc_count == 0
7578 || strncmp (bfd_get_section_name (abfd, o), FN_STUB,
7579 sizeof FN_STUB - 1) == 0
7580 || strncmp (bfd_get_section_name (abfd, o), CALL_STUB,
7581 sizeof CALL_STUB - 1) == 0
7582 || strncmp (bfd_get_section_name (abfd, o), CALL_FP_STUB,
7583 sizeof CALL_FP_STUB - 1) == 0)
7586 sec_relocs = (_bfd_elf32_link_read_relocs
7587 (abfd, o, (PTR) NULL,
7588 (Elf_Internal_Rela *) NULL,
7589 info->keep_memory));
7590 if (sec_relocs == NULL)
7593 rend = sec_relocs + o->reloc_count;
7594 for (r = sec_relocs; r < rend; r++)
7595 if (ELF32_R_SYM (r->r_info) == r_symndx
7596 && ELF32_R_TYPE (r->r_info) != R_MIPS16_26)
7599 if (! info->keep_memory)
7608 /* There is no non-call reloc for this stub, so we do
7609 not need it. Since this function is called before
7610 the linker maps input sections to output sections, we
7611 can easily discard it by setting the SEC_EXCLUDE
7613 sec->flags |= SEC_EXCLUDE;
7617 /* Record this stub in an array of local symbol stubs for
7619 if (elf_tdata (abfd)->local_stubs == NULL)
7621 unsigned long symcount;
7625 if (elf_bad_symtab (abfd))
7626 symcount = NUM_SHDR_ENTRIES (symtab_hdr);
7628 symcount = symtab_hdr->sh_info;
7629 amt = symcount * sizeof (asection *);
7630 n = (asection **) bfd_zalloc (abfd, amt);
7633 elf_tdata (abfd)->local_stubs = n;
7636 elf_tdata (abfd)->local_stubs[r_symndx] = sec;
7638 /* We don't need to set mips16_stubs_seen in this case.
7639 That flag is used to see whether we need to look through
7640 the global symbol table for stubs. We don't need to set
7641 it here, because we just have a local stub. */
7645 struct mips_elf_link_hash_entry *h;
7647 h = ((struct mips_elf_link_hash_entry *)
7648 sym_hashes[r_symndx - extsymoff]);
7650 /* H is the symbol this stub is for. */
7653 mips_elf_hash_table (info)->mips16_stubs_seen = true;
7656 else if (strncmp (name, CALL_STUB, sizeof CALL_STUB - 1) == 0
7657 || strncmp (name, CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0)
7659 unsigned long r_symndx;
7660 struct mips_elf_link_hash_entry *h;
7663 /* Look at the relocation information to figure out which symbol
7666 r_symndx = ELF32_R_SYM (relocs->r_info);
7668 if (r_symndx < extsymoff
7669 || sym_hashes[r_symndx - extsymoff] == NULL)
7671 /* This stub was actually built for a static symbol defined
7672 in the same file. We assume that all static symbols in
7673 mips16 code are themselves mips16, so we can simply
7674 discard this stub. Since this function is called before
7675 the linker maps input sections to output sections, we can
7676 easily discard it by setting the SEC_EXCLUDE flag. */
7677 sec->flags |= SEC_EXCLUDE;
7681 h = ((struct mips_elf_link_hash_entry *)
7682 sym_hashes[r_symndx - extsymoff]);
7684 /* H is the symbol this stub is for. */
7686 if (strncmp (name, CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0)
7687 loc = &h->call_fp_stub;
7689 loc = &h->call_stub;
7691 /* If we already have an appropriate stub for this function, we
7692 don't need another one, so we can discard this one. Since
7693 this function is called before the linker maps input sections
7694 to output sections, we can easily discard it by setting the
7695 SEC_EXCLUDE flag. We can also discard this section if we
7696 happen to already know that this is a mips16 function; it is
7697 not necessary to check this here, as it is checked later, but
7698 it is slightly faster to check now. */
7699 if (*loc != NULL || h->root.other == STO_MIPS16)
7701 sec->flags |= SEC_EXCLUDE;
7706 mips_elf_hash_table (info)->mips16_stubs_seen = true;
7716 sgot = mips_elf_got_section (dynobj);
7721 BFD_ASSERT (elf_section_data (sgot) != NULL);
7722 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
7723 BFD_ASSERT (g != NULL);
7728 bed = get_elf_backend_data (abfd);
7729 rel_end = relocs + sec->reloc_count * bed->s->int_rels_per_ext_rel;
7730 for (rel = relocs; rel < rel_end; ++rel)
7732 unsigned long r_symndx;
7733 unsigned int r_type;
7734 struct elf_link_hash_entry *h;
7736 r_symndx = ELF32_R_SYM (rel->r_info);
7737 r_type = ELF32_R_TYPE (rel->r_info);
7739 if (r_symndx < extsymoff)
7741 else if (r_symndx >= extsymoff + NUM_SHDR_ENTRIES (symtab_hdr))
7743 (*_bfd_error_handler)
7744 (_("%s: Malformed reloc detected for section %s"),
7745 bfd_archive_filename (abfd), name);
7746 bfd_set_error (bfd_error_bad_value);
7751 h = sym_hashes[r_symndx - extsymoff];
7753 /* This may be an indirect symbol created because of a version. */
7756 while (h->root.type == bfd_link_hash_indirect)
7757 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7761 /* Some relocs require a global offset table. */
7762 if (dynobj == NULL || sgot == NULL)
7768 case R_MIPS_CALL_HI16:
7769 case R_MIPS_CALL_LO16:
7770 case R_MIPS_GOT_HI16:
7771 case R_MIPS_GOT_LO16:
7772 case R_MIPS_GOT_PAGE:
7773 case R_MIPS_GOT_OFST:
7774 case R_MIPS_GOT_DISP:
7776 elf_hash_table (info)->dynobj = dynobj = abfd;
7777 if (! mips_elf_create_got_section (dynobj, info))
7779 g = mips_elf_got_info (dynobj, &sgot);
7786 && (info->shared || h != NULL)
7787 && (sec->flags & SEC_ALLOC) != 0)
7788 elf_hash_table (info)->dynobj = dynobj = abfd;
7796 if (!h && (r_type == R_MIPS_CALL_LO16
7797 || r_type == R_MIPS_GOT_LO16
7798 || r_type == R_MIPS_GOT_DISP))
7800 /* We may need a local GOT entry for this relocation. We
7801 don't count R_MIPS_GOT_PAGE because we can estimate the
7802 maximum number of pages needed by looking at the size of
7803 the segment. Similar comments apply to R_MIPS_GOT16 and
7804 R_MIPS_CALL16. We don't count R_MIPS_GOT_HI16, or
7805 R_MIPS_CALL_HI16 because these are always followed by an
7806 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16.
7808 This estimation is very conservative since we can merge
7809 duplicate entries in the GOT. In order to be less
7810 conservative, we could actually build the GOT here,
7811 rather than in relocate_section. */
7813 sgot->_raw_size += MIPS_ELF_GOT_SIZE (dynobj);
7821 (*_bfd_error_handler)
7822 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
7823 bfd_archive_filename (abfd), (unsigned long) rel->r_offset);
7824 bfd_set_error (bfd_error_bad_value);
7829 case R_MIPS_CALL_HI16:
7830 case R_MIPS_CALL_LO16:
7833 /* This symbol requires a global offset table entry. */
7834 if (!mips_elf_record_global_got_symbol (h, info, g))
7837 /* We need a stub, not a plt entry for the undefined
7838 function. But we record it as if it needs plt. See
7839 elf_adjust_dynamic_symbol in elflink.h. */
7840 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
7846 case R_MIPS_GOT_HI16:
7847 case R_MIPS_GOT_LO16:
7848 case R_MIPS_GOT_DISP:
7849 /* This symbol requires a global offset table entry. */
7850 if (h && !mips_elf_record_global_got_symbol (h, info, g))
7857 if ((info->shared || h != NULL)
7858 && (sec->flags & SEC_ALLOC) != 0)
7862 const char *dname = MIPS_ELF_REL_DYN_SECTION_NAME (dynobj);
7864 sreloc = bfd_get_section_by_name (dynobj, dname);
7867 sreloc = bfd_make_section (dynobj, dname);
7869 || ! bfd_set_section_flags (dynobj, sreloc,
7874 | SEC_LINKER_CREATED
7876 || ! bfd_set_section_alignment (dynobj, sreloc,
7881 #define MIPS_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
7884 /* When creating a shared object, we must copy these
7885 reloc types into the output file as R_MIPS_REL32
7886 relocs. We make room for this reloc in the
7887 .rel.dyn reloc section. */
7888 mips_elf_allocate_dynamic_relocations (dynobj, 1);
7889 if ((sec->flags & MIPS_READONLY_SECTION)
7890 == MIPS_READONLY_SECTION)
7891 /* We tell the dynamic linker that there are
7892 relocations against the text segment. */
7893 info->flags |= DF_TEXTREL;
7897 struct mips_elf_link_hash_entry *hmips;
7899 /* We only need to copy this reloc if the symbol is
7900 defined in a dynamic object. */
7901 hmips = (struct mips_elf_link_hash_entry *) h;
7902 ++hmips->possibly_dynamic_relocs;
7903 if ((sec->flags & MIPS_READONLY_SECTION)
7904 == MIPS_READONLY_SECTION)
7905 /* We need it to tell the dynamic linker if there
7906 are relocations against the text segment. */
7907 hmips->readonly_reloc = true;
7910 /* Even though we don't directly need a GOT entry for
7911 this symbol, a symbol must have a dynamic symbol
7912 table index greater that DT_MIPS_GOTSYM if there are
7913 dynamic relocations against it. */
7915 && !mips_elf_record_global_got_symbol (h, info, g))
7919 if (SGI_COMPAT (abfd))
7920 mips_elf_hash_table (info)->compact_rel_size +=
7921 sizeof (Elf32_External_crinfo);
7925 case R_MIPS_GPREL16:
7926 case R_MIPS_LITERAL:
7927 case R_MIPS_GPREL32:
7928 if (SGI_COMPAT (abfd))
7929 mips_elf_hash_table (info)->compact_rel_size +=
7930 sizeof (Elf32_External_crinfo);
7933 /* This relocation describes the C++ object vtable hierarchy.
7934 Reconstruct it for later use during GC. */
7935 case R_MIPS_GNU_VTINHERIT:
7936 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
7940 /* This relocation describes which C++ vtable entries are actually
7941 used. Record for later use during GC. */
7942 case R_MIPS_GNU_VTENTRY:
7943 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_offset))
7951 /* We must not create a stub for a symbol that has relocations
7952 related to taking the function's address. */
7958 struct mips_elf_link_hash_entry *mh;
7960 mh = (struct mips_elf_link_hash_entry *) h;
7961 mh->no_fn_stub = true;
7965 case R_MIPS_CALL_HI16:
7966 case R_MIPS_CALL_LO16:
7970 /* If this reloc is not a 16 bit call, and it has a global
7971 symbol, then we will need the fn_stub if there is one.
7972 References from a stub section do not count. */
7974 && r_type != R_MIPS16_26
7975 && strncmp (bfd_get_section_name (abfd, sec), FN_STUB,
7976 sizeof FN_STUB - 1) != 0
7977 && strncmp (bfd_get_section_name (abfd, sec), CALL_STUB,
7978 sizeof CALL_STUB - 1) != 0
7979 && strncmp (bfd_get_section_name (abfd, sec), CALL_FP_STUB,
7980 sizeof CALL_FP_STUB - 1) != 0)
7982 struct mips_elf_link_hash_entry *mh;
7984 mh = (struct mips_elf_link_hash_entry *) h;
7985 mh->need_fn_stub = true;
7992 /* Return the section that should be marked against GC for a given
7996 _bfd_mips_elf_gc_mark_hook (abfd, info, rel, h, sym)
7998 struct bfd_link_info *info ATTRIBUTE_UNUSED;
7999 Elf_Internal_Rela *rel;
8000 struct elf_link_hash_entry *h;
8001 Elf_Internal_Sym *sym;
8003 /* ??? Do mips16 stub sections need to be handled special? */
8007 switch (ELF32_R_TYPE (rel->r_info))
8009 case R_MIPS_GNU_VTINHERIT:
8010 case R_MIPS_GNU_VTENTRY:
8014 switch (h->root.type)
8016 case bfd_link_hash_defined:
8017 case bfd_link_hash_defweak:
8018 return h->root.u.def.section;
8020 case bfd_link_hash_common:
8021 return h->root.u.c.p->section;
8030 if (!(elf_bad_symtab (abfd)
8031 && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
8032 && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
8033 && sym->st_shndx != SHN_COMMON))
8035 return bfd_section_from_elf_index (abfd, sym->st_shndx);
8042 /* Update the got entry reference counts for the section being removed. */
8045 _bfd_mips_elf_gc_sweep_hook (abfd, info, sec, relocs)
8046 bfd *abfd ATTRIBUTE_UNUSED;
8047 struct bfd_link_info *info ATTRIBUTE_UNUSED;
8048 asection *sec ATTRIBUTE_UNUSED;
8049 const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
8052 Elf_Internal_Shdr *symtab_hdr;
8053 struct elf_link_hash_entry **sym_hashes;
8054 bfd_signed_vma *local_got_refcounts;
8055 const Elf_Internal_Rela *rel, *relend;
8056 unsigned long r_symndx;
8057 struct elf_link_hash_entry *h;
8059 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
8060 sym_hashes = elf_sym_hashes (abfd);
8061 local_got_refcounts = elf_local_got_refcounts (abfd);
8063 relend = relocs + sec->reloc_count;
8064 for (rel = relocs; rel < relend; rel++)
8065 switch (ELF32_R_TYPE (rel->r_info))
8069 case R_MIPS_CALL_HI16:
8070 case R_MIPS_CALL_LO16:
8071 case R_MIPS_GOT_HI16:
8072 case R_MIPS_GOT_LO16:
8073 /* ??? It would seem that the existing MIPS code does no sort
8074 of reference counting or whatnot on its GOT and PLT entries,
8075 so it is not possible to garbage collect them at this time. */
8086 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
8087 hiding the old indirect symbol. Process additional relocation
8088 information. Also called for weakdefs, in which case we just let
8089 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
8092 _bfd_mips_elf_copy_indirect_symbol (dir, ind)
8093 struct elf_link_hash_entry *dir, *ind;
8095 struct mips_elf_link_hash_entry *dirmips, *indmips;
8097 _bfd_elf_link_hash_copy_indirect (dir, ind);
8099 if (ind->root.type != bfd_link_hash_indirect)
8102 dirmips = (struct mips_elf_link_hash_entry *) dir;
8103 indmips = (struct mips_elf_link_hash_entry *) ind;
8104 dirmips->possibly_dynamic_relocs += indmips->possibly_dynamic_relocs;
8105 if (indmips->readonly_reloc)
8106 dirmips->readonly_reloc = true;
8107 if (dirmips->min_dyn_reloc_index == 0
8108 || (indmips->min_dyn_reloc_index != 0
8109 && indmips->min_dyn_reloc_index < dirmips->min_dyn_reloc_index))
8110 dirmips->min_dyn_reloc_index = indmips->min_dyn_reloc_index;
8111 if (indmips->no_fn_stub)
8112 dirmips->no_fn_stub = true;
8115 /* Adjust a symbol defined by a dynamic object and referenced by a
8116 regular object. The current definition is in some section of the
8117 dynamic object, but we're not including those sections. We have to
8118 change the definition to something the rest of the link can
8122 _bfd_mips_elf_adjust_dynamic_symbol (info, h)
8123 struct bfd_link_info *info;
8124 struct elf_link_hash_entry *h;
8127 struct mips_elf_link_hash_entry *hmips;
8130 dynobj = elf_hash_table (info)->dynobj;
8132 /* Make sure we know what is going on here. */
8133 BFD_ASSERT (dynobj != NULL
8134 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
8135 || h->weakdef != NULL
8136 || ((h->elf_link_hash_flags
8137 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
8138 && (h->elf_link_hash_flags
8139 & ELF_LINK_HASH_REF_REGULAR) != 0
8140 && (h->elf_link_hash_flags
8141 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
8143 /* If this symbol is defined in a dynamic object, we need to copy
8144 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
8146 hmips = (struct mips_elf_link_hash_entry *) h;
8147 if (! info->relocateable
8148 && hmips->possibly_dynamic_relocs != 0
8149 && (h->root.type == bfd_link_hash_defweak
8150 || (h->elf_link_hash_flags
8151 & ELF_LINK_HASH_DEF_REGULAR) == 0))
8153 mips_elf_allocate_dynamic_relocations (dynobj,
8154 hmips->possibly_dynamic_relocs);
8155 if (hmips->readonly_reloc)
8156 /* We tell the dynamic linker that there are relocations
8157 against the text segment. */
8158 info->flags |= DF_TEXTREL;
8161 /* For a function, create a stub, if allowed. */
8162 if (! hmips->no_fn_stub
8163 && (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
8165 if (! elf_hash_table (info)->dynamic_sections_created)
8168 /* If this symbol is not defined in a regular file, then set
8169 the symbol to the stub location. This is required to make
8170 function pointers compare as equal between the normal
8171 executable and the shared library. */
8172 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
8174 /* We need .stub section. */
8175 s = bfd_get_section_by_name (dynobj,
8176 MIPS_ELF_STUB_SECTION_NAME (dynobj));
8177 BFD_ASSERT (s != NULL);
8179 h->root.u.def.section = s;
8180 h->root.u.def.value = s->_raw_size;
8182 /* XXX Write this stub address somewhere. */
8183 h->plt.offset = s->_raw_size;
8185 /* Make room for this stub code. */
8186 s->_raw_size += MIPS_FUNCTION_STUB_SIZE;
8188 /* The last half word of the stub will be filled with the index
8189 of this symbol in .dynsym section. */
8193 else if ((h->type == STT_FUNC)
8194 && (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) == 0)
8196 /* This will set the entry for this symbol in the GOT to 0, and
8197 the dynamic linker will take care of this. */
8198 h->root.u.def.value = 0;
8202 /* If this is a weak symbol, and there is a real definition, the
8203 processor independent code will have arranged for us to see the
8204 real definition first, and we can just use the same value. */
8205 if (h->weakdef != NULL)
8207 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
8208 || h->weakdef->root.type == bfd_link_hash_defweak);
8209 h->root.u.def.section = h->weakdef->root.u.def.section;
8210 h->root.u.def.value = h->weakdef->root.u.def.value;
8214 /* This is a reference to a symbol defined by a dynamic object which
8215 is not a function. */
8220 /* This function is called after all the input files have been read,
8221 and the input sections have been assigned to output sections. We
8222 check for any mips16 stub sections that we can discard. */
8224 static boolean mips_elf_check_mips16_stubs
8225 PARAMS ((struct mips_elf_link_hash_entry *, PTR));
8228 _bfd_mips_elf_always_size_sections (output_bfd, info)
8230 struct bfd_link_info *info;
8234 /* The .reginfo section has a fixed size. */
8235 ri = bfd_get_section_by_name (output_bfd, ".reginfo");
8237 bfd_set_section_size (output_bfd, ri,
8238 (bfd_size_type) sizeof (Elf32_External_RegInfo));
8240 if (info->relocateable
8241 || ! mips_elf_hash_table (info)->mips16_stubs_seen)
8244 mips_elf_link_hash_traverse (mips_elf_hash_table (info),
8245 mips_elf_check_mips16_stubs,
8251 /* Check the mips16 stubs for a particular symbol, and see if we can
8255 mips_elf_check_mips16_stubs (h, data)
8256 struct mips_elf_link_hash_entry *h;
8257 PTR data ATTRIBUTE_UNUSED;
8259 if (h->fn_stub != NULL
8260 && ! h->need_fn_stub)
8262 /* We don't need the fn_stub; the only references to this symbol
8263 are 16 bit calls. Clobber the size to 0 to prevent it from
8264 being included in the link. */
8265 h->fn_stub->_raw_size = 0;
8266 h->fn_stub->_cooked_size = 0;
8267 h->fn_stub->flags &= ~SEC_RELOC;
8268 h->fn_stub->reloc_count = 0;
8269 h->fn_stub->flags |= SEC_EXCLUDE;
8272 if (h->call_stub != NULL
8273 && h->root.other == STO_MIPS16)
8275 /* We don't need the call_stub; this is a 16 bit function, so
8276 calls from other 16 bit functions are OK. Clobber the size
8277 to 0 to prevent it from being included in the link. */
8278 h->call_stub->_raw_size = 0;
8279 h->call_stub->_cooked_size = 0;
8280 h->call_stub->flags &= ~SEC_RELOC;
8281 h->call_stub->reloc_count = 0;
8282 h->call_stub->flags |= SEC_EXCLUDE;
8285 if (h->call_fp_stub != NULL
8286 && h->root.other == STO_MIPS16)
8288 /* We don't need the call_stub; this is a 16 bit function, so
8289 calls from other 16 bit functions are OK. Clobber the size
8290 to 0 to prevent it from being included in the link. */
8291 h->call_fp_stub->_raw_size = 0;
8292 h->call_fp_stub->_cooked_size = 0;
8293 h->call_fp_stub->flags &= ~SEC_RELOC;
8294 h->call_fp_stub->reloc_count = 0;
8295 h->call_fp_stub->flags |= SEC_EXCLUDE;
8301 /* Set the sizes of the dynamic sections. */
8304 _bfd_mips_elf_size_dynamic_sections (output_bfd, info)
8306 struct bfd_link_info *info;
8311 struct mips_got_info *g = NULL;
8313 dynobj = elf_hash_table (info)->dynobj;
8314 BFD_ASSERT (dynobj != NULL);
8316 if (elf_hash_table (info)->dynamic_sections_created)
8318 /* Set the contents of the .interp section to the interpreter. */
8321 s = bfd_get_section_by_name (dynobj, ".interp");
8322 BFD_ASSERT (s != NULL);
8324 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd)) + 1;
8326 = (bfd_byte *) ELF_DYNAMIC_INTERPRETER (output_bfd);
8330 /* The check_relocs and adjust_dynamic_symbol entry points have
8331 determined the sizes of the various dynamic sections. Allocate
8334 for (s = dynobj->sections; s != NULL; s = s->next)
8339 /* It's OK to base decisions on the section name, because none
8340 of the dynobj section names depend upon the input files. */
8341 name = bfd_get_section_name (dynobj, s);
8343 if ((s->flags & SEC_LINKER_CREATED) == 0)
8348 if (strncmp (name, ".rel", 4) == 0)
8350 if (s->_raw_size == 0)
8352 /* We only strip the section if the output section name
8353 has the same name. Otherwise, there might be several
8354 input sections for this output section. FIXME: This
8355 code is probably not needed these days anyhow, since
8356 the linker now does not create empty output sections. */
8357 if (s->output_section != NULL
8359 bfd_get_section_name (s->output_section->owner,
8360 s->output_section)) == 0)
8365 const char *outname;
8368 /* If this relocation section applies to a read only
8369 section, then we probably need a DT_TEXTREL entry.
8370 If the relocation section is .rel.dyn, we always
8371 assert a DT_TEXTREL entry rather than testing whether
8372 there exists a relocation to a read only section or
8374 outname = bfd_get_section_name (output_bfd,
8376 target = bfd_get_section_by_name (output_bfd, outname + 4);
8378 && (target->flags & SEC_READONLY) != 0
8379 && (target->flags & SEC_ALLOC) != 0)
8381 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd)) == 0)
8384 /* We use the reloc_count field as a counter if we need
8385 to copy relocs into the output file. */
8387 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd)) != 0)
8391 else if (strncmp (name, ".got", 4) == 0)
8394 bfd_size_type loadable_size = 0;
8395 bfd_size_type local_gotno;
8398 BFD_ASSERT (elf_section_data (s) != NULL);
8399 g = (struct mips_got_info *) elf_section_data (s)->tdata;
8400 BFD_ASSERT (g != NULL);
8402 /* Calculate the total loadable size of the output. That
8403 will give us the maximum number of GOT_PAGE entries
8405 for (sub = info->input_bfds; sub; sub = sub->link_next)
8407 asection *subsection;
8409 for (subsection = sub->sections;
8411 subsection = subsection->next)
8413 if ((subsection->flags & SEC_ALLOC) == 0)
8415 loadable_size += ((subsection->_raw_size + 0xf)
8416 &~ (bfd_size_type) 0xf);
8419 loadable_size += MIPS_FUNCTION_STUB_SIZE;
8421 /* Assume there are two loadable segments consisting of
8422 contiguous sections. Is 5 enough? */
8423 local_gotno = (loadable_size >> 16) + 5;
8424 if (IRIX_COMPAT (output_bfd) == ict_irix6)
8425 /* It's possible we will need GOT_PAGE entries as well as
8426 GOT16 entries. Often, these will be able to share GOT
8427 entries, but not always. */
8430 g->local_gotno += local_gotno;
8431 s->_raw_size += local_gotno * MIPS_ELF_GOT_SIZE (dynobj);
8433 /* There has to be a global GOT entry for every symbol with
8434 a dynamic symbol table index of DT_MIPS_GOTSYM or
8435 higher. Therefore, it make sense to put those symbols
8436 that need GOT entries at the end of the symbol table. We
8438 if (!mips_elf_sort_hash_table (info, 1))
8441 if (g->global_gotsym != NULL)
8442 i = elf_hash_table (info)->dynsymcount - g->global_gotsym->dynindx;
8444 /* If there are no global symbols, or none requiring
8445 relocations, then GLOBAL_GOTSYM will be NULL. */
8447 g->global_gotno = i;
8448 s->_raw_size += i * MIPS_ELF_GOT_SIZE (dynobj);
8450 else if (strcmp (name, MIPS_ELF_STUB_SECTION_NAME (output_bfd)) == 0)
8452 /* Irix rld assumes that the function stub isn't at the end
8453 of .text section. So put a dummy. XXX */
8454 s->_raw_size += MIPS_FUNCTION_STUB_SIZE;
8456 else if (! info->shared
8457 && ! mips_elf_hash_table (info)->use_rld_obj_head
8458 && strncmp (name, ".rld_map", 8) == 0)
8460 /* We add a room for __rld_map. It will be filled in by the
8461 rtld to contain a pointer to the _r_debug structure. */
8464 else if (SGI_COMPAT (output_bfd)
8465 && strncmp (name, ".compact_rel", 12) == 0)
8466 s->_raw_size += mips_elf_hash_table (info)->compact_rel_size;
8467 else if (strcmp (name, MIPS_ELF_MSYM_SECTION_NAME (output_bfd))
8469 s->_raw_size = (sizeof (Elf32_External_Msym)
8470 * (elf_hash_table (info)->dynsymcount
8471 + bfd_count_sections (output_bfd)));
8472 else if (strncmp (name, ".init", 5) != 0)
8474 /* It's not one of our sections, so don't allocate space. */
8480 _bfd_strip_section_from_output (info, s);
8484 /* Allocate memory for the section contents. */
8485 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
8486 if (s->contents == NULL && s->_raw_size != 0)
8488 bfd_set_error (bfd_error_no_memory);
8493 if (elf_hash_table (info)->dynamic_sections_created)
8495 /* Add some entries to the .dynamic section. We fill in the
8496 values later, in elf_mips_finish_dynamic_sections, but we
8497 must add the entries now so that we get the correct size for
8498 the .dynamic section. The DT_DEBUG entry is filled in by the
8499 dynamic linker and used by the debugger. */
8502 /* SGI object has the equivalence of DT_DEBUG in the
8503 DT_MIPS_RLD_MAP entry. */
8504 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_RLD_MAP, 0))
8506 if (!SGI_COMPAT (output_bfd))
8508 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_DEBUG, 0))
8514 /* Shared libraries on traditional mips have DT_DEBUG. */
8515 if (!SGI_COMPAT (output_bfd))
8517 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_DEBUG, 0))
8522 if (reltext && SGI_COMPAT (output_bfd))
8523 info->flags |= DF_TEXTREL;
8525 if ((info->flags & DF_TEXTREL) != 0)
8527 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_TEXTREL, 0))
8531 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_PLTGOT, 0))
8534 if (bfd_get_section_by_name (dynobj,
8535 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj)))
8537 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_REL, 0))
8540 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_RELSZ, 0))
8543 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_RELENT, 0))
8547 if (SGI_COMPAT (output_bfd))
8549 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_CONFLICTNO, 0))
8553 if (SGI_COMPAT (output_bfd))
8555 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_LIBLISTNO, 0))
8559 if (bfd_get_section_by_name (dynobj, ".conflict") != NULL)
8561 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_CONFLICT, 0))
8564 s = bfd_get_section_by_name (dynobj, ".liblist");
8565 BFD_ASSERT (s != NULL);
8567 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_LIBLIST, 0))
8571 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_RLD_VERSION, 0))
8574 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_FLAGS, 0))
8578 /* Time stamps in executable files are a bad idea. */
8579 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_TIME_STAMP, 0))
8584 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_ICHECKSUM, 0))
8589 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_IVERSION, 0))
8593 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_BASE_ADDRESS, 0))
8596 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_LOCAL_GOTNO, 0))
8599 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_SYMTABNO, 0))
8602 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_UNREFEXTNO, 0))
8605 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_GOTSYM, 0))
8608 if (IRIX_COMPAT (dynobj) == ict_irix5
8609 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_HIPAGENO, 0))
8612 if (IRIX_COMPAT (dynobj) == ict_irix6
8613 && (bfd_get_section_by_name
8614 (dynobj, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj)))
8615 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_OPTIONS, 0))
8618 if (bfd_get_section_by_name (dynobj,
8619 MIPS_ELF_MSYM_SECTION_NAME (dynobj))
8620 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_MSYM, 0))
8627 /* If NAME is one of the special IRIX6 symbols defined by the linker,
8628 adjust it appropriately now. */
8631 mips_elf_irix6_finish_dynamic_symbol (abfd, name, sym)
8632 bfd *abfd ATTRIBUTE_UNUSED;
8634 Elf_Internal_Sym *sym;
8636 /* The linker script takes care of providing names and values for
8637 these, but we must place them into the right sections. */
8638 static const char* const text_section_symbols[] = {
8641 "__dso_displacement",
8643 "__program_header_table",
8647 static const char* const data_section_symbols[] = {
8655 const char* const *p;
8658 for (i = 0; i < 2; ++i)
8659 for (p = (i == 0) ? text_section_symbols : data_section_symbols;
8662 if (strcmp (*p, name) == 0)
8664 /* All of these symbols are given type STT_SECTION by the
8666 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
8668 /* The IRIX linker puts these symbols in special sections. */
8670 sym->st_shndx = SHN_MIPS_TEXT;
8672 sym->st_shndx = SHN_MIPS_DATA;
8678 /* Finish up dynamic symbol handling. We set the contents of various
8679 dynamic sections here. */
8682 _bfd_mips_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
8684 struct bfd_link_info *info;
8685 struct elf_link_hash_entry *h;
8686 Elf_Internal_Sym *sym;
8692 struct mips_got_info *g;
8694 struct mips_elf_link_hash_entry *mh;
8696 dynobj = elf_hash_table (info)->dynobj;
8697 gval = sym->st_value;
8698 mh = (struct mips_elf_link_hash_entry *) h;
8700 if (h->plt.offset != (bfd_vma) -1)
8704 bfd_byte stub[MIPS_FUNCTION_STUB_SIZE];
8706 /* This symbol has a stub. Set it up. */
8708 BFD_ASSERT (h->dynindx != -1);
8710 s = bfd_get_section_by_name (dynobj,
8711 MIPS_ELF_STUB_SECTION_NAME (dynobj));
8712 BFD_ASSERT (s != NULL);
8714 /* Fill the stub. */
8716 bfd_put_32 (output_bfd, (bfd_vma) STUB_LW (output_bfd), p);
8718 bfd_put_32 (output_bfd, (bfd_vma) STUB_MOVE (output_bfd), p);
8721 /* FIXME: Can h->dynindex be more than 64K? */
8722 if (h->dynindx & 0xffff0000)
8725 bfd_put_32 (output_bfd, (bfd_vma) STUB_JALR, p);
8727 bfd_put_32 (output_bfd, (bfd_vma) STUB_LI16 (output_bfd) + h->dynindx, p);
8729 BFD_ASSERT (h->plt.offset <= s->_raw_size);
8730 memcpy (s->contents + h->plt.offset, stub, MIPS_FUNCTION_STUB_SIZE);
8732 /* Mark the symbol as undefined. plt.offset != -1 occurs
8733 only for the referenced symbol. */
8734 sym->st_shndx = SHN_UNDEF;
8736 /* The run-time linker uses the st_value field of the symbol
8737 to reset the global offset table entry for this external
8738 to its stub address when unlinking a shared object. */
8739 gval = s->output_section->vma + s->output_offset + h->plt.offset;
8740 sym->st_value = gval;
8743 BFD_ASSERT (h->dynindx != -1
8744 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0);
8746 sgot = mips_elf_got_section (dynobj);
8747 BFD_ASSERT (sgot != NULL);
8748 BFD_ASSERT (elf_section_data (sgot) != NULL);
8749 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
8750 BFD_ASSERT (g != NULL);
8752 /* Run through the global symbol table, creating GOT entries for all
8753 the symbols that need them. */
8754 if (g->global_gotsym != NULL
8755 && h->dynindx >= g->global_gotsym->dynindx)
8761 value = sym->st_value;
8764 /* For an entity defined in a shared object, this will be
8765 NULL. (For functions in shared objects for
8766 which we have created stubs, ST_VALUE will be non-NULL.
8767 That's because such the functions are now no longer defined
8768 in a shared object.) */
8770 if (info->shared && h->root.type == bfd_link_hash_undefined)
8773 value = h->root.u.def.value;
8775 offset = mips_elf_global_got_index (dynobj, h);
8776 MIPS_ELF_PUT_WORD (output_bfd, value, sgot->contents + offset);
8779 /* Create a .msym entry, if appropriate. */
8780 smsym = bfd_get_section_by_name (dynobj,
8781 MIPS_ELF_MSYM_SECTION_NAME (dynobj));
8784 Elf32_Internal_Msym msym;
8786 msym.ms_hash_value = bfd_elf_hash (h->root.root.string);
8787 /* It is undocumented what the `1' indicates, but IRIX6 uses
8789 msym.ms_info = ELF32_MS_INFO (mh->min_dyn_reloc_index, 1);
8790 bfd_mips_elf_swap_msym_out
8792 ((Elf32_External_Msym *) smsym->contents) + h->dynindx);
8795 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
8796 name = h->root.root.string;
8797 if (strcmp (name, "_DYNAMIC") == 0
8798 || strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
8799 sym->st_shndx = SHN_ABS;
8800 else if (strcmp (name, "_DYNAMIC_LINK") == 0
8801 || strcmp (name, "_DYNAMIC_LINKING") == 0)
8803 sym->st_shndx = SHN_ABS;
8804 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
8807 else if (strcmp (name, "_gp_disp") == 0)
8809 sym->st_shndx = SHN_ABS;
8810 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
8811 sym->st_value = elf_gp (output_bfd);
8813 else if (SGI_COMPAT (output_bfd))
8815 if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0
8816 || strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0)
8818 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
8819 sym->st_other = STO_PROTECTED;
8821 sym->st_shndx = SHN_MIPS_DATA;
8823 else if (strcmp (name, mips_elf_dynsym_rtproc_names[2]) == 0)
8825 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
8826 sym->st_other = STO_PROTECTED;
8827 sym->st_value = mips_elf_hash_table (info)->procedure_count;
8828 sym->st_shndx = SHN_ABS;
8830 else if (sym->st_shndx != SHN_UNDEF && sym->st_shndx != SHN_ABS)
8832 if (h->type == STT_FUNC)
8833 sym->st_shndx = SHN_MIPS_TEXT;
8834 else if (h->type == STT_OBJECT)
8835 sym->st_shndx = SHN_MIPS_DATA;
8839 /* Handle the IRIX6-specific symbols. */
8840 if (IRIX_COMPAT (output_bfd) == ict_irix6)
8841 mips_elf_irix6_finish_dynamic_symbol (output_bfd, name, sym);
8845 if (! mips_elf_hash_table (info)->use_rld_obj_head
8846 && (strcmp (name, "__rld_map") == 0
8847 || strcmp (name, "__RLD_MAP") == 0))
8849 asection *s = bfd_get_section_by_name (dynobj, ".rld_map");
8850 BFD_ASSERT (s != NULL);
8851 sym->st_value = s->output_section->vma + s->output_offset;
8852 bfd_put_32 (output_bfd, (bfd_vma) 0, s->contents);
8853 if (mips_elf_hash_table (info)->rld_value == 0)
8854 mips_elf_hash_table (info)->rld_value = sym->st_value;
8856 else if (mips_elf_hash_table (info)->use_rld_obj_head
8857 && strcmp (name, "__rld_obj_head") == 0)
8859 /* IRIX6 does not use a .rld_map section. */
8860 if (IRIX_COMPAT (output_bfd) == ict_irix5
8861 || IRIX_COMPAT (output_bfd) == ict_none)
8862 BFD_ASSERT (bfd_get_section_by_name (dynobj, ".rld_map")
8864 mips_elf_hash_table (info)->rld_value = sym->st_value;
8868 /* If this is a mips16 symbol, force the value to be even. */
8869 if (sym->st_other == STO_MIPS16
8870 && (sym->st_value & 1) != 0)
8876 /* Finish up the dynamic sections. */
8879 _bfd_mips_elf_finish_dynamic_sections (output_bfd, info)
8881 struct bfd_link_info *info;
8886 struct mips_got_info *g;
8888 dynobj = elf_hash_table (info)->dynobj;
8890 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
8892 sgot = mips_elf_got_section (dynobj);
8897 BFD_ASSERT (elf_section_data (sgot) != NULL);
8898 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
8899 BFD_ASSERT (g != NULL);
8902 if (elf_hash_table (info)->dynamic_sections_created)
8906 BFD_ASSERT (sdyn != NULL);
8907 BFD_ASSERT (g != NULL);
8909 for (b = sdyn->contents;
8910 b < sdyn->contents + sdyn->_raw_size;
8911 b += MIPS_ELF_DYN_SIZE (dynobj))
8913 Elf_Internal_Dyn dyn;
8919 /* Read in the current dynamic entry. */
8920 (*get_elf_backend_data (dynobj)->s->swap_dyn_in) (dynobj, b, &dyn);
8922 /* Assume that we're going to modify it and write it out. */
8928 s = (bfd_get_section_by_name
8930 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj)));
8931 BFD_ASSERT (s != NULL);
8932 dyn.d_un.d_val = MIPS_ELF_REL_SIZE (dynobj);
8936 /* Rewrite DT_STRSZ. */
8938 _bfd_elf_strtab_size (elf_hash_table (info)->dynstr);
8944 case DT_MIPS_CONFLICT:
8947 case DT_MIPS_LIBLIST:
8950 s = bfd_get_section_by_name (output_bfd, name);
8951 BFD_ASSERT (s != NULL);
8952 dyn.d_un.d_ptr = s->vma;
8955 case DT_MIPS_RLD_VERSION:
8956 dyn.d_un.d_val = 1; /* XXX */
8960 dyn.d_un.d_val = RHF_NOTPOT; /* XXX */
8963 case DT_MIPS_CONFLICTNO:
8965 elemsize = sizeof (Elf32_Conflict);
8968 case DT_MIPS_LIBLISTNO:
8970 elemsize = sizeof (Elf32_Lib);
8972 s = bfd_get_section_by_name (output_bfd, name);
8975 if (s->_cooked_size != 0)
8976 dyn.d_un.d_val = s->_cooked_size / elemsize;
8978 dyn.d_un.d_val = s->_raw_size / elemsize;
8984 case DT_MIPS_TIME_STAMP:
8985 time ((time_t *) &dyn.d_un.d_val);
8988 case DT_MIPS_ICHECKSUM:
8993 case DT_MIPS_IVERSION:
8998 case DT_MIPS_BASE_ADDRESS:
8999 s = output_bfd->sections;
9000 BFD_ASSERT (s != NULL);
9001 dyn.d_un.d_ptr = s->vma & ~(bfd_vma) 0xffff;
9004 case DT_MIPS_LOCAL_GOTNO:
9005 dyn.d_un.d_val = g->local_gotno;
9008 case DT_MIPS_UNREFEXTNO:
9009 /* The index into the dynamic symbol table which is the
9010 entry of the first external symbol that is not
9011 referenced within the same object. */
9012 dyn.d_un.d_val = bfd_count_sections (output_bfd) + 1;
9015 case DT_MIPS_GOTSYM:
9016 if (g->global_gotsym)
9018 dyn.d_un.d_val = g->global_gotsym->dynindx;
9021 /* In case if we don't have global got symbols we default
9022 to setting DT_MIPS_GOTSYM to the same value as
9023 DT_MIPS_SYMTABNO, so we just fall through. */
9025 case DT_MIPS_SYMTABNO:
9027 elemsize = MIPS_ELF_SYM_SIZE (output_bfd);
9028 s = bfd_get_section_by_name (output_bfd, name);
9029 BFD_ASSERT (s != NULL);
9031 if (s->_cooked_size != 0)
9032 dyn.d_un.d_val = s->_cooked_size / elemsize;
9034 dyn.d_un.d_val = s->_raw_size / elemsize;
9037 case DT_MIPS_HIPAGENO:
9038 dyn.d_un.d_val = g->local_gotno - MIPS_RESERVED_GOTNO;
9041 case DT_MIPS_RLD_MAP:
9042 dyn.d_un.d_ptr = mips_elf_hash_table (info)->rld_value;
9045 case DT_MIPS_OPTIONS:
9046 s = (bfd_get_section_by_name
9047 (output_bfd, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd)));
9048 dyn.d_un.d_ptr = s->vma;
9052 s = (bfd_get_section_by_name
9053 (output_bfd, MIPS_ELF_MSYM_SECTION_NAME (output_bfd)));
9054 dyn.d_un.d_ptr = s->vma;
9063 (*get_elf_backend_data (dynobj)->s->swap_dyn_out)
9068 /* The first entry of the global offset table will be filled at
9069 runtime. The second entry will be used by some runtime loaders.
9070 This isn't the case of Irix rld. */
9071 if (sgot != NULL && sgot->_raw_size > 0)
9073 MIPS_ELF_PUT_WORD (output_bfd, (bfd_vma) 0, sgot->contents);
9074 MIPS_ELF_PUT_WORD (output_bfd, (bfd_vma) 0x80000000,
9075 sgot->contents + MIPS_ELF_GOT_SIZE (output_bfd));
9079 elf_section_data (sgot->output_section)->this_hdr.sh_entsize
9080 = MIPS_ELF_GOT_SIZE (output_bfd);
9085 Elf32_compact_rel cpt;
9087 /* ??? The section symbols for the output sections were set up in
9088 _bfd_elf_final_link. SGI sets the STT_NOTYPE attribute for these
9089 symbols. Should we do so? */
9091 smsym = bfd_get_section_by_name (dynobj,
9092 MIPS_ELF_MSYM_SECTION_NAME (dynobj));
9095 Elf32_Internal_Msym msym;
9097 msym.ms_hash_value = 0;
9098 msym.ms_info = ELF32_MS_INFO (0, 1);
9100 for (s = output_bfd->sections; s != NULL; s = s->next)
9102 long dynindx = elf_section_data (s)->dynindx;
9104 bfd_mips_elf_swap_msym_out
9106 (((Elf32_External_Msym *) smsym->contents)
9111 if (SGI_COMPAT (output_bfd))
9113 /* Write .compact_rel section out. */
9114 s = bfd_get_section_by_name (dynobj, ".compact_rel");
9118 cpt.num = s->reloc_count;
9120 cpt.offset = (s->output_section->filepos
9121 + sizeof (Elf32_External_compact_rel));
9124 bfd_elf32_swap_compact_rel_out (output_bfd, &cpt,
9125 ((Elf32_External_compact_rel *)
9128 /* Clean up a dummy stub function entry in .text. */
9129 s = bfd_get_section_by_name (dynobj,
9130 MIPS_ELF_STUB_SECTION_NAME (dynobj));
9133 file_ptr dummy_offset;
9135 BFD_ASSERT (s->_raw_size >= MIPS_FUNCTION_STUB_SIZE);
9136 dummy_offset = s->_raw_size - MIPS_FUNCTION_STUB_SIZE;
9137 memset (s->contents + dummy_offset, 0,
9138 MIPS_FUNCTION_STUB_SIZE);
9143 /* We need to sort the entries of the dynamic relocation section. */
9145 if (!ABI_64_P (output_bfd))
9149 reldyn = bfd_get_section_by_name (dynobj,
9150 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj));
9151 if (reldyn != NULL && reldyn->reloc_count > 2)
9153 reldyn_sorting_bfd = output_bfd;
9154 qsort ((Elf32_External_Rel *) reldyn->contents + 1,
9155 (size_t) reldyn->reloc_count - 1,
9156 sizeof (Elf32_External_Rel), sort_dynamic_relocs);
9160 /* Clean up a first relocation in .rel.dyn. */
9161 s = bfd_get_section_by_name (dynobj,
9162 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj));
9163 if (s != NULL && s->_raw_size > 0)
9164 memset (s->contents, 0, MIPS_ELF_REL_SIZE (dynobj));
9170 /* Support for core dump NOTE sections */
9172 _bfd_elf32_mips_grok_prstatus (abfd, note)
9174 Elf_Internal_Note *note;
9177 unsigned int raw_size;
9179 switch (note->descsz)
9184 case 256: /* Linux/MIPS */
9186 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
9189 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
9198 /* Make a ".reg/999" section. */
9199 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
9200 raw_size, note->descpos + offset);
9204 _bfd_elf32_mips_grok_psinfo (abfd, note)
9206 Elf_Internal_Note *note;
9208 switch (note->descsz)
9213 case 128: /* Linux/MIPS elf_prpsinfo */
9214 elf_tdata (abfd)->core_program
9215 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
9216 elf_tdata (abfd)->core_command
9217 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
9220 /* Note that for some reason, a spurious space is tacked
9221 onto the end of the args in some (at least one anyway)
9222 implementations, so strip it off if it exists. */
9225 char *command = elf_tdata (abfd)->core_command;
9226 int n = strlen (command);
9228 if (0 < n && command[n - 1] == ' ')
9229 command[n - 1] = '\0';
9238 _bfd_elf32_mips_discard_info (abfd, cookie, info)
9240 struct elf_reloc_cookie *cookie;
9241 struct bfd_link_info *info;
9244 struct elf_backend_data *bed = get_elf_backend_data (abfd);
9245 boolean ret = false;
9246 unsigned char *tdata;
9249 o = bfd_get_section_by_name (abfd, ".pdr");
9252 if (o->_raw_size == 0)
9254 if (o->_raw_size % PDR_SIZE != 0)
9256 if (o->output_section != NULL
9257 && bfd_is_abs_section (o->output_section))
9260 tdata = bfd_zmalloc (o->_raw_size / PDR_SIZE);
9264 cookie->rels = _bfd_elf32_link_read_relocs (abfd, o, (PTR) NULL,
9265 (Elf_Internal_Rela *) NULL,
9273 cookie->rel = cookie->rels;
9275 cookie->rels + o->reloc_count * bed->s->int_rels_per_ext_rel;
9277 for (i = 0, skip = 0; i < o->_raw_size; i ++)
9279 if (_bfd_elf32_reloc_symbol_deleted_p (i * PDR_SIZE, cookie))
9288 elf_section_data (o)->tdata = tdata;
9289 o->_cooked_size = o->_raw_size - skip * PDR_SIZE;
9295 if (! info->keep_memory)
9296 free (cookie->rels);
9302 _bfd_elf32_mips_ignore_discarded_relocs (sec)
9305 if (strcmp (sec->name, ".pdr") == 0)
9311 _bfd_elf32_mips_write_section (output_bfd, sec, contents)
9316 bfd_byte *to, *from, *end;
9319 if (strcmp (sec->name, ".pdr") != 0)
9322 if (elf_section_data (sec)->tdata == NULL)
9326 end = contents + sec->_raw_size;
9327 for (from = contents, i = 0;
9329 from += PDR_SIZE, i++)
9331 if (((unsigned char *)elf_section_data (sec)->tdata)[i] == 1)
9334 memcpy (to, from, PDR_SIZE);
9337 bfd_set_section_contents (output_bfd, sec->output_section, contents,
9338 (file_ptr) sec->output_offset,
9343 /* This is almost identical to bfd_generic_get_... except that some
9344 MIPS relocations need to be handled specially. Sigh. */
9347 elf32_mips_get_relocated_section_contents (abfd, link_info, link_order, data,
9348 relocateable, symbols)
9350 struct bfd_link_info *link_info;
9351 struct bfd_link_order *link_order;
9353 boolean relocateable;
9356 /* Get enough memory to hold the stuff */
9357 bfd *input_bfd = link_order->u.indirect.section->owner;
9358 asection *input_section = link_order->u.indirect.section;
9360 long reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section);
9361 arelent **reloc_vector = NULL;
9367 reloc_vector = (arelent **) bfd_malloc ((bfd_size_type) reloc_size);
9368 if (reloc_vector == NULL && reloc_size != 0)
9371 /* read in the section */
9372 if (!bfd_get_section_contents (input_bfd,
9376 input_section->_raw_size))
9379 /* We're not relaxing the section, so just copy the size info */
9380 input_section->_cooked_size = input_section->_raw_size;
9381 input_section->reloc_done = true;
9383 reloc_count = bfd_canonicalize_reloc (input_bfd,
9387 if (reloc_count < 0)
9390 if (reloc_count > 0)
9395 bfd_vma gp = 0x12345678; /* initialize just to shut gcc up */
9398 struct bfd_hash_entry *h;
9399 struct bfd_link_hash_entry *lh;
9400 /* Skip all this stuff if we aren't mixing formats. */
9401 if (abfd && input_bfd
9402 && abfd->xvec == input_bfd->xvec)
9406 h = bfd_hash_lookup (&link_info->hash->table, "_gp", false, false);
9407 lh = (struct bfd_link_hash_entry *) h;
9414 case bfd_link_hash_undefined:
9415 case bfd_link_hash_undefweak:
9416 case bfd_link_hash_common:
9419 case bfd_link_hash_defined:
9420 case bfd_link_hash_defweak:
9422 gp = lh->u.def.value;
9424 case bfd_link_hash_indirect:
9425 case bfd_link_hash_warning:
9427 /* @@FIXME ignoring warning for now */
9429 case bfd_link_hash_new:
9438 for (parent = reloc_vector; *parent != (arelent *) NULL;
9441 char *error_message = (char *) NULL;
9442 bfd_reloc_status_type r;
9444 /* Specific to MIPS: Deal with relocation types that require
9445 knowing the gp of the output bfd. */
9446 asymbol *sym = *(*parent)->sym_ptr_ptr;
9447 if (bfd_is_abs_section (sym->section) && abfd)
9449 /* The special_function wouldn't get called anyways. */
9453 /* The gp isn't there; let the special function code
9454 fall over on its own. */
9456 else if ((*parent)->howto->special_function
9457 == _bfd_mips_elf_gprel16_reloc)
9459 /* bypass special_function call */
9460 r = gprel16_with_gp (input_bfd, sym, *parent, input_section,
9461 relocateable, (PTR) data, gp);
9462 goto skip_bfd_perform_relocation;
9464 /* end mips specific stuff */
9466 r = bfd_perform_relocation (input_bfd,
9470 relocateable ? abfd : (bfd *) NULL,
9472 skip_bfd_perform_relocation:
9476 asection *os = input_section->output_section;
9478 /* A partial link, so keep the relocs */
9479 os->orelocation[os->reloc_count] = *parent;
9483 if (r != bfd_reloc_ok)
9487 case bfd_reloc_undefined:
9488 if (!((*link_info->callbacks->undefined_symbol)
9489 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
9490 input_bfd, input_section, (*parent)->address,
9494 case bfd_reloc_dangerous:
9495 BFD_ASSERT (error_message != (char *) NULL);
9496 if (!((*link_info->callbacks->reloc_dangerous)
9497 (link_info, error_message, input_bfd, input_section,
9498 (*parent)->address)))
9501 case bfd_reloc_overflow:
9502 if (!((*link_info->callbacks->reloc_overflow)
9503 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
9504 (*parent)->howto->name, (*parent)->addend,
9505 input_bfd, input_section, (*parent)->address)))
9508 case bfd_reloc_outofrange:
9517 if (reloc_vector != NULL)
9518 free (reloc_vector);
9522 if (reloc_vector != NULL)
9523 free (reloc_vector);
9527 #define bfd_elf32_bfd_get_relocated_section_contents \
9528 elf32_mips_get_relocated_section_contents
9530 /* ECOFF swapping routines. These are used when dealing with the
9531 .mdebug section, which is in the ECOFF debugging format. */
9532 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = {
9533 /* Symbol table magic number. */
9535 /* Alignment of debugging information. E.g., 4. */
9537 /* Sizes of external symbolic information. */
9538 sizeof (struct hdr_ext),
9539 sizeof (struct dnr_ext),
9540 sizeof (struct pdr_ext),
9541 sizeof (struct sym_ext),
9542 sizeof (struct opt_ext),
9543 sizeof (struct fdr_ext),
9544 sizeof (struct rfd_ext),
9545 sizeof (struct ext_ext),
9546 /* Functions to swap in external symbolic data. */
9555 _bfd_ecoff_swap_tir_in,
9556 _bfd_ecoff_swap_rndx_in,
9557 /* Functions to swap out external symbolic data. */
9566 _bfd_ecoff_swap_tir_out,
9567 _bfd_ecoff_swap_rndx_out,
9568 /* Function to read in symbolic data. */
9569 _bfd_mips_elf_read_ecoff_info
9572 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
9573 #define TARGET_LITTLE_NAME "elf32-littlemips"
9574 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
9575 #define TARGET_BIG_NAME "elf32-bigmips"
9576 #define ELF_ARCH bfd_arch_mips
9577 #define ELF_MACHINE_CODE EM_MIPS
9579 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
9580 a value of 0x1000, and we are compatible. */
9581 #define ELF_MAXPAGESIZE 0x1000
9583 #define elf_backend_collect true
9584 #define elf_backend_type_change_ok true
9585 #define elf_backend_can_gc_sections true
9586 #define elf_backend_sign_extend_vma true
9587 #define elf_info_to_howto mips_info_to_howto_rela
9588 #define elf_info_to_howto_rel mips_info_to_howto_rel
9589 #define elf_backend_sym_is_global mips_elf_sym_is_global
9590 #define elf_backend_object_p _bfd_mips_elf_object_p
9591 #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
9592 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
9593 #define elf_backend_section_from_bfd_section \
9594 _bfd_mips_elf_section_from_bfd_section
9595 #define elf_backend_section_processing _bfd_mips_elf_section_processing
9596 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
9597 #define elf_backend_additional_program_headers \
9598 _bfd_mips_elf_additional_program_headers
9599 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
9600 #define elf_backend_final_write_processing \
9601 _bfd_mips_elf_final_write_processing
9602 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
9603 #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
9604 #define elf_backend_create_dynamic_sections \
9605 _bfd_mips_elf_create_dynamic_sections
9606 #define elf_backend_check_relocs _bfd_mips_elf_check_relocs
9607 #define elf_backend_adjust_dynamic_symbol \
9608 _bfd_mips_elf_adjust_dynamic_symbol
9609 #define elf_backend_always_size_sections \
9610 _bfd_mips_elf_always_size_sections
9611 #define elf_backend_size_dynamic_sections \
9612 _bfd_mips_elf_size_dynamic_sections
9613 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section
9614 #define elf_backend_link_output_symbol_hook \
9615 _bfd_mips_elf_link_output_symbol_hook
9616 #define elf_backend_finish_dynamic_symbol \
9617 _bfd_mips_elf_finish_dynamic_symbol
9618 #define elf_backend_finish_dynamic_sections \
9619 _bfd_mips_elf_finish_dynamic_sections
9620 #define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
9621 #define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
9623 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
9624 #define elf_backend_plt_header_size 0
9626 #define elf_backend_copy_indirect_symbol \
9627 _bfd_mips_elf_copy_indirect_symbol
9629 #define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
9630 #define elf_backend_grok_prstatus _bfd_elf32_mips_grok_prstatus
9631 #define elf_backend_grok_psinfo _bfd_elf32_mips_grok_psinfo
9633 #define elf_backend_discard_info _bfd_elf32_mips_discard_info
9634 #define elf_backend_ignore_discarded_relocs \
9635 _bfd_elf32_mips_ignore_discarded_relocs
9636 #define elf_backend_write_section _bfd_elf32_mips_write_section
9638 #define bfd_elf32_bfd_is_local_label_name \
9639 mips_elf_is_local_label_name
9640 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
9641 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
9642 #define bfd_elf32_bfd_link_hash_table_create \
9643 _bfd_mips_elf_link_hash_table_create
9644 #define bfd_elf32_bfd_final_link _bfd_mips_elf_final_link
9645 #define bfd_elf32_bfd_copy_private_bfd_data \
9646 _bfd_mips_elf_copy_private_bfd_data
9647 #define bfd_elf32_bfd_merge_private_bfd_data \
9648 _bfd_mips_elf_merge_private_bfd_data
9649 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
9650 #define bfd_elf32_bfd_print_private_bfd_data \
9651 _bfd_mips_elf_print_private_bfd_data
9652 #include "elf32-target.h"
9654 /* Support for traditional mips targets */
9656 #define INCLUDED_TARGET_FILE /* More a type of flag */
9658 #undef TARGET_LITTLE_SYM
9659 #undef TARGET_LITTLE_NAME
9660 #undef TARGET_BIG_SYM
9661 #undef TARGET_BIG_NAME
9663 #define TARGET_LITTLE_SYM bfd_elf32_tradlittlemips_vec
9664 #define TARGET_LITTLE_NAME "elf32-tradlittlemips"
9665 #define TARGET_BIG_SYM bfd_elf32_tradbigmips_vec
9666 #define TARGET_BIG_NAME "elf32-tradbigmips"
9668 /* Include the target file again for this target */
9669 #include "elf32-target.h"