1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
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;
109 /* Are we forced local? .*/
110 boolean forced_local;
113 static bfd_reloc_status_type mips32_64bit_reloc
114 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
115 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
116 PARAMS ((bfd *, bfd_reloc_code_real_type));
117 static reloc_howto_type *mips_rtype_to_howto
118 PARAMS ((unsigned int));
119 static void mips_info_to_howto_rel
120 PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
121 static void mips_info_to_howto_rela
122 PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
123 static void bfd_mips_elf32_swap_gptab_in
124 PARAMS ((bfd *, const Elf32_External_gptab *, Elf32_gptab *));
125 static void bfd_mips_elf32_swap_gptab_out
126 PARAMS ((bfd *, const Elf32_gptab *, Elf32_External_gptab *));
128 static void bfd_mips_elf_swap_msym_in
129 PARAMS ((bfd *, const Elf32_External_Msym *, Elf32_Internal_Msym *));
131 static void bfd_mips_elf_swap_msym_out
132 PARAMS ((bfd *, const Elf32_Internal_Msym *, Elf32_External_Msym *));
133 static boolean mips_elf_sym_is_global PARAMS ((bfd *, asymbol *));
134 static boolean mips_elf_create_procedure_table
135 PARAMS ((PTR, bfd *, struct bfd_link_info *, asection *,
136 struct ecoff_debug_info *));
137 static INLINE int elf_mips_isa PARAMS ((flagword));
138 static INLINE unsigned long elf_mips_mach PARAMS ((flagword));
139 static INLINE char* elf_mips_abi_name PARAMS ((bfd *));
140 static boolean mips_elf_is_local_label_name
141 PARAMS ((bfd *, const char *));
142 static struct bfd_hash_entry *mips_elf_link_hash_newfunc
143 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
144 static int gptab_compare PARAMS ((const void *, const void *));
145 static bfd_reloc_status_type mips16_jump_reloc
146 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
147 static bfd_reloc_status_type mips16_gprel_reloc
148 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
149 static boolean mips_elf_create_compact_rel_section
150 PARAMS ((bfd *, struct bfd_link_info *));
151 static boolean mips_elf_create_got_section
152 PARAMS ((bfd *, struct bfd_link_info *));
153 static bfd_reloc_status_type mips_elf_final_gp
154 PARAMS ((bfd *, asymbol *, boolean, char **, bfd_vma *));
155 static bfd_byte *elf32_mips_get_relocated_section_contents
156 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
157 bfd_byte *, boolean, asymbol **));
158 static asection *mips_elf_create_msym_section
160 static void mips_elf_irix6_finish_dynamic_symbol
161 PARAMS ((bfd *, const char *, Elf_Internal_Sym *));
162 static bfd_vma mips_elf_sign_extend PARAMS ((bfd_vma, int));
163 static boolean mips_elf_overflow_p PARAMS ((bfd_vma, int));
164 static bfd_vma mips_elf_high PARAMS ((bfd_vma));
165 static bfd_vma mips_elf_higher PARAMS ((bfd_vma));
166 static bfd_vma mips_elf_highest PARAMS ((bfd_vma));
167 static bfd_vma mips_elf_global_got_index
168 PARAMS ((bfd *, struct elf_link_hash_entry *));
169 static bfd_vma mips_elf_local_got_index
170 PARAMS ((bfd *, struct bfd_link_info *, bfd_vma));
171 static bfd_vma mips_elf_got_offset_from_index
172 PARAMS ((bfd *, bfd *, bfd_vma));
173 static boolean mips_elf_record_global_got_symbol
174 PARAMS ((struct elf_link_hash_entry *, struct bfd_link_info *,
175 struct mips_got_info *));
176 static bfd_vma mips_elf_got_page
177 PARAMS ((bfd *, struct bfd_link_info *, bfd_vma, bfd_vma *));
178 static const Elf_Internal_Rela *mips_elf_next_relocation
179 PARAMS ((unsigned int, const Elf_Internal_Rela *,
180 const Elf_Internal_Rela *));
181 static bfd_reloc_status_type mips_elf_calculate_relocation
182 PARAMS ((bfd *, bfd *, asection *, struct bfd_link_info *,
183 const Elf_Internal_Rela *, bfd_vma, reloc_howto_type *,
184 Elf_Internal_Sym *, asection **, bfd_vma *, const char **,
186 static bfd_vma mips_elf_obtain_contents
187 PARAMS ((reloc_howto_type *, const Elf_Internal_Rela *, bfd *, bfd_byte *));
188 static boolean mips_elf_perform_relocation
189 PARAMS ((struct bfd_link_info *, reloc_howto_type *,
190 const Elf_Internal_Rela *, bfd_vma,
191 bfd *, asection *, bfd_byte *, boolean));
192 static boolean mips_elf_assign_gp PARAMS ((bfd *, bfd_vma *));
193 static boolean mips_elf_sort_hash_table_f
194 PARAMS ((struct mips_elf_link_hash_entry *, PTR));
195 static boolean mips_elf_sort_hash_table
196 PARAMS ((struct bfd_link_info *, unsigned long));
197 static asection * mips_elf_got_section PARAMS ((bfd *));
198 static struct mips_got_info *mips_elf_got_info
199 PARAMS ((bfd *, asection **));
200 static boolean mips_elf_local_relocation_p
201 PARAMS ((bfd *, const Elf_Internal_Rela *, asection **, boolean));
202 static bfd_vma mips_elf_create_local_got_entry
203 PARAMS ((bfd *, struct mips_got_info *, asection *, bfd_vma));
204 static bfd_vma mips_elf_got16_entry
205 PARAMS ((bfd *, struct bfd_link_info *, bfd_vma, boolean));
206 static boolean mips_elf_create_dynamic_relocation
207 PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Rela *,
208 struct mips_elf_link_hash_entry *, asection *,
209 bfd_vma, bfd_vma *, asection *));
210 static void mips_elf_allocate_dynamic_relocations
211 PARAMS ((bfd *, unsigned int));
212 static boolean mips_elf_stub_section_p
213 PARAMS ((bfd *, asection *));
214 static int sort_dynamic_relocs
215 PARAMS ((const void *, const void *));
216 static void _bfd_mips_elf_hide_symbol
217 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, boolean));
218 static void _bfd_mips_elf_copy_indirect_symbol
219 PARAMS ((struct elf_link_hash_entry *,
220 struct elf_link_hash_entry *));
221 static boolean _bfd_elf32_mips_grok_prstatus
222 PARAMS ((bfd *, Elf_Internal_Note *));
223 static boolean _bfd_elf32_mips_grok_psinfo
224 PARAMS ((bfd *, Elf_Internal_Note *));
225 static boolean _bfd_elf32_mips_discard_info
226 PARAMS ((bfd *, struct elf_reloc_cookie *, struct bfd_link_info *));
227 static boolean _bfd_elf32_mips_ignore_discarded_relocs
228 PARAMS ((asection *));
229 static boolean _bfd_elf32_mips_write_section
230 PARAMS ((bfd *, asection *, bfd_byte *));
232 extern const bfd_target bfd_elf32_tradbigmips_vec;
233 extern const bfd_target bfd_elf32_tradlittlemips_vec;
235 extern const bfd_target bfd_elf64_tradbigmips_vec;
236 extern const bfd_target bfd_elf64_tradlittlemips_vec;
239 /* The level of IRIX compatibility we're striving for. */
247 /* This will be used when we sort the dynamic relocation records. */
248 static bfd *reldyn_sorting_bfd;
250 /* Nonzero if ABFD is using the N32 ABI. */
252 #define ABI_N32_P(abfd) \
253 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
255 /* Nonzero if ABFD is using the 64-bit ABI. */
256 #define ABI_64_P(abfd) \
257 ((elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS64) != 0)
259 /* Depending on the target vector we generate some version of Irix
260 executables or "normal" MIPS ELF ABI executables. */
262 #define IRIX_COMPAT(abfd) \
263 (((abfd->xvec == &bfd_elf64_tradbigmips_vec) || \
264 (abfd->xvec == &bfd_elf64_tradlittlemips_vec) || \
265 (abfd->xvec == &bfd_elf32_tradbigmips_vec) || \
266 (abfd->xvec == &bfd_elf32_tradlittlemips_vec)) ? ict_none : \
267 ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5))
269 #define IRIX_COMPAT(abfd) \
270 (((abfd->xvec == &bfd_elf32_tradbigmips_vec) || \
271 (abfd->xvec == &bfd_elf32_tradlittlemips_vec)) ? ict_none : \
272 ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5))
275 #define NEWABI_P(abfd) (ABI_N32_P(abfd) || ABI_64_P(abfd))
277 /* Whether we are trying to be compatible with IRIX at all. */
278 #define SGI_COMPAT(abfd) \
279 (IRIX_COMPAT (abfd) != ict_none)
281 /* The name of the msym section. */
282 #define MIPS_ELF_MSYM_SECTION_NAME(abfd) ".msym"
284 /* The name of the srdata section. */
285 #define MIPS_ELF_SRDATA_SECTION_NAME(abfd) ".srdata"
287 /* The name of the options section. */
288 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
289 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.options" : ".options")
291 /* The name of the stub section. */
292 #define MIPS_ELF_STUB_SECTION_NAME(abfd) \
293 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.stubs" : ".stub")
295 /* The name of the dynamic relocation section. */
296 #define MIPS_ELF_REL_DYN_SECTION_NAME(abfd) ".rel.dyn"
298 /* The size of an external REL relocation. */
299 #define MIPS_ELF_REL_SIZE(abfd) \
300 (get_elf_backend_data (abfd)->s->sizeof_rel)
302 /* The size of an external dynamic table entry. */
303 #define MIPS_ELF_DYN_SIZE(abfd) \
304 (get_elf_backend_data (abfd)->s->sizeof_dyn)
306 /* The size of a GOT entry. */
307 #define MIPS_ELF_GOT_SIZE(abfd) \
308 (get_elf_backend_data (abfd)->s->arch_size / 8)
310 /* The size of a symbol-table entry. */
311 #define MIPS_ELF_SYM_SIZE(abfd) \
312 (get_elf_backend_data (abfd)->s->sizeof_sym)
314 /* The default alignment for sections, as a power of two. */
315 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
316 (get_elf_backend_data (abfd)->s->file_align == 8 ? 3 : 2)
318 /* Get word-sized data. */
319 #define MIPS_ELF_GET_WORD(abfd, ptr) \
320 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
322 /* Put out word-sized data. */
323 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
325 ? bfd_put_64 (abfd, val, ptr) \
326 : bfd_put_32 (abfd, val, ptr))
328 /* Add a dynamic symbol table-entry. */
330 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
331 (ABI_64_P (elf_hash_table (info)->dynobj) \
332 ? bfd_elf64_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val) \
333 : bfd_elf32_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
335 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
336 (ABI_64_P (elf_hash_table (info)->dynobj) \
337 ? (boolean) (abort (), false) \
338 : bfd_elf32_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
341 /* The number of local .got entries we reserve. */
342 #define MIPS_RESERVED_GOTNO (2)
344 /* Instructions which appear in a stub. For some reason the stub is
345 slightly different on an SGI system. */
346 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
347 #define STUB_LW(abfd) \
350 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
351 : 0x8f998010) /* lw t9,0x8010(gp) */ \
352 : 0x8f998010) /* lw t9,0x8000(gp) */
353 #define STUB_MOVE(abfd) \
354 (SGI_COMPAT (abfd) ? 0x03e07825 : 0x03e07821) /* move t7,ra */
355 #define STUB_JALR 0x0320f809 /* jal t9 */
356 #define STUB_LI16(abfd) \
357 (SGI_COMPAT (abfd) ? 0x34180000 : 0x24180000) /* ori t8,zero,0 */
358 #define MIPS_FUNCTION_STUB_SIZE (16)
361 /* We no longer try to identify particular sections for the .dynsym
362 section. When we do, we wind up crashing if there are other random
363 sections with relocations. */
365 /* Names of sections which appear in the .dynsym section in an Irix 5
368 static const char * const mips_elf_dynsym_sec_names[] =
381 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
382 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
384 /* The number of entries in mips_elf_dynsym_sec_names which go in the
387 #define MIPS_TEXT_DYNSYM_SECNO (3)
391 /* The names of the runtime procedure table symbols used on Irix 5. */
393 static const char * const mips_elf_dynsym_rtproc_names[] =
396 "_procedure_string_table",
397 "_procedure_table_size",
401 /* These structures are used to generate the .compact_rel section on
406 unsigned long id1; /* Always one? */
407 unsigned long num; /* Number of compact relocation entries. */
408 unsigned long id2; /* Always two? */
409 unsigned long offset; /* The file offset of the first relocation. */
410 unsigned long reserved0; /* Zero? */
411 unsigned long reserved1; /* Zero? */
420 bfd_byte reserved0[4];
421 bfd_byte reserved1[4];
422 } Elf32_External_compact_rel;
426 unsigned int ctype : 1; /* 1: long 0: short format. See below. */
427 unsigned int rtype : 4; /* Relocation types. See below. */
428 unsigned int dist2to : 8;
429 unsigned int relvaddr : 19; /* (VADDR - vaddr of the previous entry)/ 4 */
430 unsigned long konst; /* KONST field. See below. */
431 unsigned long vaddr; /* VADDR to be relocated. */
436 unsigned int ctype : 1; /* 1: long 0: short format. See below. */
437 unsigned int rtype : 4; /* Relocation types. See below. */
438 unsigned int dist2to : 8;
439 unsigned int relvaddr : 19; /* (VADDR - vaddr of the previous entry)/ 4 */
440 unsigned long konst; /* KONST field. See below. */
448 } Elf32_External_crinfo;
454 } Elf32_External_crinfo2;
456 /* These are the constants used to swap the bitfields in a crinfo. */
458 #define CRINFO_CTYPE (0x1)
459 #define CRINFO_CTYPE_SH (31)
460 #define CRINFO_RTYPE (0xf)
461 #define CRINFO_RTYPE_SH (27)
462 #define CRINFO_DIST2TO (0xff)
463 #define CRINFO_DIST2TO_SH (19)
464 #define CRINFO_RELVADDR (0x7ffff)
465 #define CRINFO_RELVADDR_SH (0)
467 /* A compact relocation info has long (3 words) or short (2 words)
468 formats. A short format doesn't have VADDR field and relvaddr
469 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
470 #define CRF_MIPS_LONG 1
471 #define CRF_MIPS_SHORT 0
473 /* There are 4 types of compact relocation at least. The value KONST
474 has different meaning for each type:
477 CT_MIPS_REL32 Address in data
478 CT_MIPS_WORD Address in word (XXX)
479 CT_MIPS_GPHI_LO GP - vaddr
480 CT_MIPS_JMPAD Address to jump
483 #define CRT_MIPS_REL32 0xa
484 #define CRT_MIPS_WORD 0xb
485 #define CRT_MIPS_GPHI_LO 0xc
486 #define CRT_MIPS_JMPAD 0xd
488 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
489 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
490 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
491 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
493 static void bfd_elf32_swap_compact_rel_out
494 PARAMS ((bfd *, const Elf32_compact_rel *, Elf32_External_compact_rel *));
495 static void bfd_elf32_swap_crinfo_out
496 PARAMS ((bfd *, const Elf32_crinfo *, Elf32_External_crinfo *));
498 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
499 from smaller values. Start with zero, widen, *then* decrement. */
500 #define MINUS_ONE (((bfd_vma)0) - 1)
502 /* The relocation table used for SHT_REL sections. */
504 static reloc_howto_type elf_mips_howto_table_rel[] =
507 HOWTO (R_MIPS_NONE, /* type */
509 0, /* size (0 = byte, 1 = short, 2 = long) */
511 false, /* pc_relative */
513 complain_overflow_dont, /* complain_on_overflow */
514 bfd_elf_generic_reloc, /* special_function */
515 "R_MIPS_NONE", /* name */
516 false, /* partial_inplace */
519 false), /* pcrel_offset */
521 /* 16 bit relocation. */
522 HOWTO (R_MIPS_16, /* type */
524 2, /* size (0 = byte, 1 = short, 2 = long) */
526 false, /* pc_relative */
528 complain_overflow_signed, /* complain_on_overflow */
529 bfd_elf_generic_reloc, /* special_function */
530 "R_MIPS_16", /* name */
531 true, /* partial_inplace */
532 0x0000ffff, /* src_mask */
533 0x0000ffff, /* dst_mask */
534 false), /* pcrel_offset */
536 /* 32 bit relocation. */
537 HOWTO (R_MIPS_32, /* type */
539 2, /* size (0 = byte, 1 = short, 2 = long) */
541 false, /* pc_relative */
543 complain_overflow_dont, /* complain_on_overflow */
544 bfd_elf_generic_reloc, /* special_function */
545 "R_MIPS_32", /* name */
546 true, /* partial_inplace */
547 0xffffffff, /* src_mask */
548 0xffffffff, /* dst_mask */
549 false), /* pcrel_offset */
551 /* 32 bit symbol relative relocation. */
552 HOWTO (R_MIPS_REL32, /* type */
554 2, /* size (0 = byte, 1 = short, 2 = long) */
556 false, /* pc_relative */
558 complain_overflow_dont, /* complain_on_overflow */
559 bfd_elf_generic_reloc, /* special_function */
560 "R_MIPS_REL32", /* name */
561 true, /* partial_inplace */
562 0xffffffff, /* src_mask */
563 0xffffffff, /* dst_mask */
564 false), /* pcrel_offset */
566 /* 26 bit jump address. */
567 HOWTO (R_MIPS_26, /* type */
569 2, /* size (0 = byte, 1 = short, 2 = long) */
571 false, /* pc_relative */
573 complain_overflow_dont, /* complain_on_overflow */
574 /* This needs complex overflow
575 detection, because the upper four
576 bits must match the PC + 4. */
577 bfd_elf_generic_reloc, /* special_function */
578 "R_MIPS_26", /* name */
579 true, /* partial_inplace */
580 0x03ffffff, /* src_mask */
581 0x03ffffff, /* dst_mask */
582 false), /* pcrel_offset */
584 /* High 16 bits of symbol value. */
585 HOWTO (R_MIPS_HI16, /* type */
587 2, /* size (0 = byte, 1 = short, 2 = long) */
589 false, /* pc_relative */
591 complain_overflow_dont, /* complain_on_overflow */
592 _bfd_mips_elf_hi16_reloc, /* special_function */
593 "R_MIPS_HI16", /* name */
594 true, /* partial_inplace */
595 0x0000ffff, /* src_mask */
596 0x0000ffff, /* dst_mask */
597 false), /* pcrel_offset */
599 /* Low 16 bits of symbol value. */
600 HOWTO (R_MIPS_LO16, /* type */
602 2, /* size (0 = byte, 1 = short, 2 = long) */
604 false, /* pc_relative */
606 complain_overflow_dont, /* complain_on_overflow */
607 _bfd_mips_elf_lo16_reloc, /* special_function */
608 "R_MIPS_LO16", /* name */
609 true, /* partial_inplace */
610 0x0000ffff, /* src_mask */
611 0x0000ffff, /* dst_mask */
612 false), /* pcrel_offset */
614 /* GP relative reference. */
615 HOWTO (R_MIPS_GPREL16, /* type */
617 2, /* size (0 = byte, 1 = short, 2 = long) */
619 false, /* pc_relative */
621 complain_overflow_signed, /* complain_on_overflow */
622 _bfd_mips_elf_gprel16_reloc, /* special_function */
623 "R_MIPS_GPREL16", /* name */
624 true, /* partial_inplace */
625 0x0000ffff, /* src_mask */
626 0x0000ffff, /* dst_mask */
627 false), /* pcrel_offset */
629 /* Reference to literal section. */
630 HOWTO (R_MIPS_LITERAL, /* type */
632 2, /* size (0 = byte, 1 = short, 2 = long) */
634 false, /* pc_relative */
636 complain_overflow_signed, /* complain_on_overflow */
637 _bfd_mips_elf_gprel16_reloc, /* special_function */
638 "R_MIPS_LITERAL", /* name */
639 true, /* partial_inplace */
640 0x0000ffff, /* src_mask */
641 0x0000ffff, /* dst_mask */
642 false), /* pcrel_offset */
644 /* Reference to global offset table. */
645 HOWTO (R_MIPS_GOT16, /* type */
647 2, /* size (0 = byte, 1 = short, 2 = long) */
649 false, /* pc_relative */
651 complain_overflow_signed, /* complain_on_overflow */
652 _bfd_mips_elf_got16_reloc, /* special_function */
653 "R_MIPS_GOT16", /* name */
654 true, /* partial_inplace */
655 0x0000ffff, /* src_mask */
656 0x0000ffff, /* dst_mask */
657 false), /* pcrel_offset */
659 /* 16 bit PC relative reference. */
660 HOWTO (R_MIPS_PC16, /* type */
662 2, /* size (0 = byte, 1 = short, 2 = long) */
664 true, /* pc_relative */
666 complain_overflow_signed, /* complain_on_overflow */
667 bfd_elf_generic_reloc, /* special_function */
668 "R_MIPS_PC16", /* name */
669 true, /* partial_inplace */
670 0x0000ffff, /* src_mask */
671 0x0000ffff, /* dst_mask */
672 true), /* pcrel_offset */
674 /* 16 bit call through global offset table. */
675 HOWTO (R_MIPS_CALL16, /* type */
677 2, /* size (0 = byte, 1 = short, 2 = long) */
679 false, /* pc_relative */
681 complain_overflow_signed, /* complain_on_overflow */
682 bfd_elf_generic_reloc, /* special_function */
683 "R_MIPS_CALL16", /* name */
684 true, /* partial_inplace */
685 0x0000ffff, /* src_mask */
686 0x0000ffff, /* dst_mask */
687 false), /* pcrel_offset */
689 /* 32 bit GP relative reference. */
690 HOWTO (R_MIPS_GPREL32, /* type */
692 2, /* size (0 = byte, 1 = short, 2 = long) */
694 false, /* pc_relative */
696 complain_overflow_dont, /* complain_on_overflow */
697 _bfd_mips_elf_gprel32_reloc, /* special_function */
698 "R_MIPS_GPREL32", /* name */
699 true, /* partial_inplace */
700 0xffffffff, /* src_mask */
701 0xffffffff, /* dst_mask */
702 false), /* pcrel_offset */
704 /* The remaining relocs are defined on Irix 5, although they are
705 not defined by the ABI. */
710 /* A 5 bit shift field. */
711 HOWTO (R_MIPS_SHIFT5, /* type */
713 2, /* size (0 = byte, 1 = short, 2 = long) */
715 false, /* pc_relative */
717 complain_overflow_bitfield, /* complain_on_overflow */
718 bfd_elf_generic_reloc, /* special_function */
719 "R_MIPS_SHIFT5", /* name */
720 true, /* partial_inplace */
721 0x000007c0, /* src_mask */
722 0x000007c0, /* dst_mask */
723 false), /* pcrel_offset */
725 /* A 6 bit shift field. */
726 /* FIXME: This is not handled correctly; a special function is
727 needed to put the most significant bit in the right place. */
728 HOWTO (R_MIPS_SHIFT6, /* type */
730 2, /* size (0 = byte, 1 = short, 2 = long) */
732 false, /* pc_relative */
734 complain_overflow_bitfield, /* complain_on_overflow */
735 bfd_elf_generic_reloc, /* special_function */
736 "R_MIPS_SHIFT6", /* name */
737 true, /* partial_inplace */
738 0x000007c4, /* src_mask */
739 0x000007c4, /* dst_mask */
740 false), /* pcrel_offset */
742 /* A 64 bit relocation. */
743 HOWTO (R_MIPS_64, /* type */
745 4, /* size (0 = byte, 1 = short, 2 = long) */
747 false, /* pc_relative */
749 complain_overflow_dont, /* complain_on_overflow */
750 mips32_64bit_reloc, /* special_function */
751 "R_MIPS_64", /* name */
752 true, /* partial_inplace */
753 MINUS_ONE, /* src_mask */
754 MINUS_ONE, /* dst_mask */
755 false), /* pcrel_offset */
757 /* Displacement in the global offset table. */
758 HOWTO (R_MIPS_GOT_DISP, /* type */
760 2, /* size (0 = byte, 1 = short, 2 = long) */
762 false, /* pc_relative */
764 complain_overflow_signed, /* complain_on_overflow */
765 bfd_elf_generic_reloc, /* special_function */
766 "R_MIPS_GOT_DISP", /* name */
767 true, /* partial_inplace */
768 0x0000ffff, /* src_mask */
769 0x0000ffff, /* dst_mask */
770 false), /* pcrel_offset */
772 /* Displacement to page pointer in the global offset table. */
773 HOWTO (R_MIPS_GOT_PAGE, /* type */
775 2, /* size (0 = byte, 1 = short, 2 = long) */
777 false, /* pc_relative */
779 complain_overflow_signed, /* complain_on_overflow */
780 bfd_elf_generic_reloc, /* special_function */
781 "R_MIPS_GOT_PAGE", /* name */
782 true, /* partial_inplace */
783 0x0000ffff, /* src_mask */
784 0x0000ffff, /* dst_mask */
785 false), /* pcrel_offset */
787 /* Offset from page pointer in the global offset table. */
788 HOWTO (R_MIPS_GOT_OFST, /* type */
790 2, /* size (0 = byte, 1 = short, 2 = long) */
792 false, /* pc_relative */
794 complain_overflow_signed, /* complain_on_overflow */
795 bfd_elf_generic_reloc, /* special_function */
796 "R_MIPS_GOT_OFST", /* name */
797 true, /* partial_inplace */
798 0x0000ffff, /* src_mask */
799 0x0000ffff, /* dst_mask */
800 false), /* pcrel_offset */
802 /* High 16 bits of displacement in global offset table. */
803 HOWTO (R_MIPS_GOT_HI16, /* type */
805 2, /* size (0 = byte, 1 = short, 2 = long) */
807 false, /* pc_relative */
809 complain_overflow_dont, /* complain_on_overflow */
810 bfd_elf_generic_reloc, /* special_function */
811 "R_MIPS_GOT_HI16", /* name */
812 true, /* partial_inplace */
813 0x0000ffff, /* src_mask */
814 0x0000ffff, /* dst_mask */
815 false), /* pcrel_offset */
817 /* Low 16 bits of displacement in global offset table. */
818 HOWTO (R_MIPS_GOT_LO16, /* type */
820 2, /* size (0 = byte, 1 = short, 2 = long) */
822 false, /* pc_relative */
824 complain_overflow_dont, /* complain_on_overflow */
825 bfd_elf_generic_reloc, /* special_function */
826 "R_MIPS_GOT_LO16", /* name */
827 true, /* partial_inplace */
828 0x0000ffff, /* src_mask */
829 0x0000ffff, /* dst_mask */
830 false), /* pcrel_offset */
832 /* 64 bit subtraction. Used in the N32 ABI. */
833 HOWTO (R_MIPS_SUB, /* type */
835 4, /* size (0 = byte, 1 = short, 2 = long) */
837 false, /* pc_relative */
839 complain_overflow_dont, /* complain_on_overflow */
840 bfd_elf_generic_reloc, /* special_function */
841 "R_MIPS_SUB", /* name */
842 true, /* partial_inplace */
843 MINUS_ONE, /* src_mask */
844 MINUS_ONE, /* dst_mask */
845 false), /* pcrel_offset */
847 /* Used to cause the linker to insert and delete instructions? */
848 EMPTY_HOWTO (R_MIPS_INSERT_A),
849 EMPTY_HOWTO (R_MIPS_INSERT_B),
850 EMPTY_HOWTO (R_MIPS_DELETE),
852 /* Get the higher value of a 64 bit addend. */
853 HOWTO (R_MIPS_HIGHER, /* type */
855 2, /* size (0 = byte, 1 = short, 2 = long) */
857 false, /* pc_relative */
859 complain_overflow_dont, /* complain_on_overflow */
860 bfd_elf_generic_reloc, /* special_function */
861 "R_MIPS_HIGHER", /* name */
862 true, /* partial_inplace */
863 0x0000ffff, /* src_mask */
864 0x0000ffff, /* dst_mask */
865 false), /* pcrel_offset */
867 /* Get the highest value of a 64 bit addend. */
868 HOWTO (R_MIPS_HIGHEST, /* type */
870 2, /* size (0 = byte, 1 = short, 2 = long) */
872 false, /* pc_relative */
874 complain_overflow_dont, /* complain_on_overflow */
875 bfd_elf_generic_reloc, /* special_function */
876 "R_MIPS_HIGHEST", /* name */
877 true, /* partial_inplace */
878 0x0000ffff, /* src_mask */
879 0x0000ffff, /* dst_mask */
880 false), /* pcrel_offset */
882 /* High 16 bits of displacement in global offset table. */
883 HOWTO (R_MIPS_CALL_HI16, /* type */
885 2, /* size (0 = byte, 1 = short, 2 = long) */
887 false, /* pc_relative */
889 complain_overflow_dont, /* complain_on_overflow */
890 bfd_elf_generic_reloc, /* special_function */
891 "R_MIPS_CALL_HI16", /* name */
892 true, /* partial_inplace */
893 0x0000ffff, /* src_mask */
894 0x0000ffff, /* dst_mask */
895 false), /* pcrel_offset */
897 /* Low 16 bits of displacement in global offset table. */
898 HOWTO (R_MIPS_CALL_LO16, /* type */
900 2, /* size (0 = byte, 1 = short, 2 = long) */
902 false, /* pc_relative */
904 complain_overflow_dont, /* complain_on_overflow */
905 bfd_elf_generic_reloc, /* special_function */
906 "R_MIPS_CALL_LO16", /* name */
907 true, /* partial_inplace */
908 0x0000ffff, /* src_mask */
909 0x0000ffff, /* dst_mask */
910 false), /* pcrel_offset */
912 /* Section displacement. */
913 HOWTO (R_MIPS_SCN_DISP, /* type */
915 2, /* size (0 = byte, 1 = short, 2 = long) */
917 false, /* pc_relative */
919 complain_overflow_dont, /* complain_on_overflow */
920 bfd_elf_generic_reloc, /* special_function */
921 "R_MIPS_SCN_DISP", /* name */
922 true, /* partial_inplace */
923 0xffffffff, /* src_mask */
924 0xffffffff, /* dst_mask */
925 false), /* pcrel_offset */
927 EMPTY_HOWTO (R_MIPS_REL16),
928 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
929 EMPTY_HOWTO (R_MIPS_PJUMP),
930 EMPTY_HOWTO (R_MIPS_RELGOT),
932 /* Protected jump conversion. This is an optimization hint. No
933 relocation is required for correctness. */
934 HOWTO (R_MIPS_JALR, /* type */
936 2, /* size (0 = byte, 1 = short, 2 = long) */
938 false, /* pc_relative */
940 complain_overflow_dont, /* complain_on_overflow */
941 bfd_elf_generic_reloc, /* special_function */
942 "R_MIPS_JALR", /* name */
943 false, /* partial_inplace */
944 0x00000000, /* src_mask */
945 0x00000000, /* dst_mask */
946 false), /* pcrel_offset */
949 /* The relocation table used for SHT_RELA sections. */
951 static reloc_howto_type elf_mips_howto_table_rela[] =
954 HOWTO (R_MIPS_NONE, /* type */
956 0, /* size (0 = byte, 1 = short, 2 = long) */
958 false, /* pc_relative */
960 complain_overflow_dont, /* complain_on_overflow */
961 bfd_elf_generic_reloc, /* special_function */
962 "R_MIPS_NONE", /* name */
963 false, /* partial_inplace */
966 false), /* pcrel_offset */
968 /* 16 bit relocation. */
969 HOWTO (R_MIPS_16, /* type */
971 2, /* size (0 = byte, 1 = short, 2 = long) */
973 false, /* pc_relative */
975 complain_overflow_signed, /* complain_on_overflow */
976 bfd_elf_generic_reloc, /* special_function */
977 "R_MIPS_16", /* name */
978 false, /* partial_inplace */
980 0x0000, /* dst_mask */
981 false), /* pcrel_offset */
983 /* 32 bit relocation. */
984 HOWTO (R_MIPS_32, /* type */
986 2, /* size (0 = byte, 1 = short, 2 = long) */
988 false, /* pc_relative */
990 complain_overflow_dont, /* complain_on_overflow */
991 bfd_elf_generic_reloc, /* special_function */
992 "R_MIPS_32", /* name */
993 false, /* partial_inplace */
995 0xffffffff, /* dst_mask */
996 false), /* pcrel_offset */
998 /* 32 bit symbol relative relocation. */
999 HOWTO (R_MIPS_REL32, /* type */
1001 2, /* size (0 = byte, 1 = short, 2 = long) */
1003 false, /* pc_relative */
1005 complain_overflow_dont, /* complain_on_overflow */
1006 bfd_elf_generic_reloc, /* special_function */
1007 "R_MIPS_REL32", /* name */
1008 false, /* partial_inplace */
1010 0xffffffff, /* dst_mask */
1011 false), /* pcrel_offset */
1013 /* 26 bit jump address. */
1014 HOWTO (R_MIPS_26, /* type */
1016 2, /* size (0 = byte, 1 = short, 2 = long) */
1018 false, /* pc_relative */
1020 complain_overflow_dont, /* complain_on_overflow */
1021 /* This needs complex overflow
1022 detection, because the upper 36
1023 bits must match the PC + 4. */
1024 bfd_elf_generic_reloc, /* special_function */
1025 "R_MIPS_26", /* name */
1026 false, /* partial_inplace */
1028 0x03ffffff, /* dst_mask */
1029 false), /* pcrel_offset */
1031 /* R_MIPS_HI16 and R_MIPS_LO16 are unsupported for 64 bit REL. */
1032 /* High 16 bits of symbol value. */
1033 HOWTO (R_MIPS_HI16, /* type */
1035 2, /* size (0 = byte, 1 = short, 2 = long) */
1037 false, /* pc_relative */
1039 complain_overflow_dont, /* complain_on_overflow */
1040 bfd_elf_generic_reloc, /* special_function */
1041 "R_MIPS_HI16", /* name */
1042 false, /* partial_inplace */
1044 0x0000ffff, /* dst_mask */
1045 false), /* pcrel_offset */
1047 /* Low 16 bits of symbol value. */
1048 HOWTO (R_MIPS_LO16, /* type */
1050 2, /* size (0 = byte, 1 = short, 2 = long) */
1052 false, /* pc_relative */
1054 complain_overflow_dont, /* complain_on_overflow */
1055 bfd_elf_generic_reloc, /* special_function */
1056 "R_MIPS_LO16", /* name */
1057 false, /* partial_inplace */
1059 0x0000ffff, /* dst_mask */
1060 false), /* pcrel_offset */
1062 /* GP relative reference. */
1063 HOWTO (R_MIPS_GPREL16, /* type */
1065 2, /* size (0 = byte, 1 = short, 2 = long) */
1067 false, /* pc_relative */
1069 complain_overflow_signed, /* complain_on_overflow */
1070 _bfd_mips_elf_gprel16_reloc, /* special_function */
1071 "R_MIPS_GPREL16", /* name */
1072 false, /* partial_inplace */
1074 0x0000ffff, /* dst_mask */
1075 false), /* pcrel_offset */
1077 /* Reference to literal section. */
1078 HOWTO (R_MIPS_LITERAL, /* type */
1080 2, /* size (0 = byte, 1 = short, 2 = long) */
1082 false, /* pc_relative */
1084 complain_overflow_signed, /* complain_on_overflow */
1085 _bfd_mips_elf_gprel16_reloc, /* special_function */
1086 "R_MIPS_LITERAL", /* name */
1087 false, /* partial_inplace */
1089 0x0000ffff, /* dst_mask */
1090 false), /* pcrel_offset */
1092 /* Reference to global offset table. */
1093 /* FIXME: This is not handled correctly. */
1094 HOWTO (R_MIPS_GOT16, /* type */
1096 2, /* size (0 = byte, 1 = short, 2 = long) */
1098 false, /* pc_relative */
1100 complain_overflow_signed, /* complain_on_overflow */
1101 bfd_elf_generic_reloc, /* special_function */
1102 "R_MIPS_GOT16", /* name */
1103 false, /* partial_inplace */
1105 0x0000ffff, /* dst_mask */
1106 false), /* pcrel_offset */
1108 /* 16 bit PC relative reference. */
1109 HOWTO (R_MIPS_PC16, /* type */
1111 2, /* size (0 = byte, 1 = short, 2 = long) */
1113 true, /* pc_relative */
1115 complain_overflow_signed, /* complain_on_overflow */
1116 bfd_elf_generic_reloc, /* special_function */
1117 "R_MIPS_PC16", /* name */
1118 false, /* partial_inplace */
1120 0x0000ffff, /* dst_mask */
1121 true), /* pcrel_offset */
1123 /* 16 bit call through global offset table. */
1124 /* FIXME: This is not handled correctly. */
1125 HOWTO (R_MIPS_CALL16, /* type */
1127 2, /* size (0 = byte, 1 = short, 2 = long) */
1129 false, /* pc_relative */
1131 complain_overflow_signed, /* complain_on_overflow */
1132 bfd_elf_generic_reloc, /* special_function */
1133 "R_MIPS_CALL16", /* name */
1134 false, /* partial_inplace */
1136 0x0000ffff, /* dst_mask */
1137 false), /* pcrel_offset */
1139 /* 32 bit GP relative reference. */
1140 HOWTO (R_MIPS_GPREL32, /* type */
1142 2, /* size (0 = byte, 1 = short, 2 = long) */
1144 false, /* pc_relative */
1146 complain_overflow_dont, /* complain_on_overflow */
1147 _bfd_mips_elf_gprel32_reloc, /* special_function */
1148 "R_MIPS_GPREL32", /* name */
1149 false, /* partial_inplace */
1151 0xffffffff, /* dst_mask */
1152 false), /* pcrel_offset */
1158 /* A 5 bit shift field. */
1159 HOWTO (R_MIPS_SHIFT5, /* type */
1161 2, /* size (0 = byte, 1 = short, 2 = long) */
1163 false, /* pc_relative */
1165 complain_overflow_bitfield, /* complain_on_overflow */
1166 bfd_elf_generic_reloc, /* special_function */
1167 "R_MIPS_SHIFT5", /* name */
1168 false, /* partial_inplace */
1170 0x000007c0, /* dst_mask */
1171 false), /* pcrel_offset */
1173 /* A 6 bit shift field. */
1174 /* FIXME: Not handled correctly. */
1175 HOWTO (R_MIPS_SHIFT6, /* type */
1177 2, /* size (0 = byte, 1 = short, 2 = long) */
1179 false, /* pc_relative */
1181 complain_overflow_bitfield, /* complain_on_overflow */
1182 bfd_elf_generic_reloc, /* special_function */
1183 "R_MIPS_SHIFT6", /* name */
1184 false, /* partial_inplace */
1186 0x000007c4, /* dst_mask */
1187 false), /* pcrel_offset */
1189 /* 64 bit relocation. */
1190 HOWTO (R_MIPS_64, /* type */
1192 4, /* size (0 = byte, 1 = short, 2 = long) */
1194 false, /* pc_relative */
1196 complain_overflow_dont, /* complain_on_overflow */
1197 bfd_elf_generic_reloc, /* special_function */
1198 "R_MIPS_64", /* name */
1199 false, /* partial_inplace */
1201 MINUS_ONE, /* dst_mask */
1202 false), /* pcrel_offset */
1204 /* Displacement in the global offset table. */
1205 /* FIXME: Not handled correctly. */
1206 HOWTO (R_MIPS_GOT_DISP, /* type */
1208 2, /* size (0 = byte, 1 = short, 2 = long) */
1210 false, /* pc_relative */
1212 complain_overflow_signed, /* complain_on_overflow */
1213 bfd_elf_generic_reloc, /* special_function */
1214 "R_MIPS_GOT_DISP", /* name */
1215 false, /* partial_inplace */
1217 0x0000ffff, /* dst_mask */
1218 false), /* pcrel_offset */
1220 /* Displacement to page pointer in the global offset table. */
1221 /* FIXME: Not handled correctly. */
1222 HOWTO (R_MIPS_GOT_PAGE, /* type */
1224 2, /* size (0 = byte, 1 = short, 2 = long) */
1226 false, /* pc_relative */
1228 complain_overflow_signed, /* complain_on_overflow */
1229 bfd_elf_generic_reloc, /* special_function */
1230 "R_MIPS_GOT_PAGE", /* name */
1231 false, /* partial_inplace */
1233 0x0000ffff, /* dst_mask */
1234 false), /* pcrel_offset */
1236 /* Offset from page pointer in the global offset table. */
1237 /* FIXME: Not handled correctly. */
1238 HOWTO (R_MIPS_GOT_OFST, /* type */
1240 2, /* size (0 = byte, 1 = short, 2 = long) */
1242 false, /* pc_relative */
1244 complain_overflow_signed, /* complain_on_overflow */
1245 bfd_elf_generic_reloc, /* special_function */
1246 "R_MIPS_GOT_OFST", /* name */
1247 false, /* partial_inplace */
1249 0x0000ffff, /* dst_mask */
1250 false), /* pcrel_offset */
1252 /* High 16 bits of displacement in global offset table. */
1253 /* FIXME: Not handled correctly. */
1254 HOWTO (R_MIPS_GOT_HI16, /* type */
1256 2, /* size (0 = byte, 1 = short, 2 = long) */
1258 false, /* pc_relative */
1260 complain_overflow_dont, /* complain_on_overflow */
1261 bfd_elf_generic_reloc, /* special_function */
1262 "R_MIPS_GOT_HI16", /* name */
1263 false, /* partial_inplace */
1265 0x0000ffff, /* dst_mask */
1266 false), /* pcrel_offset */
1268 /* Low 16 bits of displacement in global offset table. */
1269 /* FIXME: Not handled correctly. */
1270 HOWTO (R_MIPS_GOT_LO16, /* type */
1272 2, /* size (0 = byte, 1 = short, 2 = long) */
1274 false, /* pc_relative */
1276 complain_overflow_dont, /* complain_on_overflow */
1277 bfd_elf_generic_reloc, /* special_function */
1278 "R_MIPS_GOT_LO16", /* name */
1279 false, /* partial_inplace */
1281 0x0000ffff, /* dst_mask */
1282 false), /* pcrel_offset */
1284 /* 64 bit substraction. */
1285 /* FIXME: Not handled correctly. */
1286 HOWTO (R_MIPS_SUB, /* type */
1288 4, /* size (0 = byte, 1 = short, 2 = long) */
1290 false, /* pc_relative */
1292 complain_overflow_dont, /* complain_on_overflow */
1293 bfd_elf_generic_reloc, /* special_function */
1294 "R_MIPS_SUB", /* name */
1295 false, /* partial_inplace */
1297 MINUS_ONE, /* dst_mask */
1298 false), /* pcrel_offset */
1300 /* Insert the addend as an instruction. */
1301 /* FIXME: Not handled correctly. */
1302 HOWTO (R_MIPS_INSERT_A, /* type */
1304 2, /* size (0 = byte, 1 = short, 2 = long) */
1306 false, /* pc_relative */
1308 complain_overflow_dont, /* complain_on_overflow */
1309 bfd_elf_generic_reloc, /* special_function */
1310 "R_MIPS_INSERT_A", /* name */
1311 false, /* partial_inplace */
1313 0xffffffff, /* dst_mask */
1314 false), /* pcrel_offset */
1316 /* Insert the addend as an instruction, and change all relocations
1317 to refer to the old instruction at the address. */
1318 /* FIXME: Not handled correctly. */
1319 HOWTO (R_MIPS_INSERT_B, /* type */
1321 2, /* size (0 = byte, 1 = short, 2 = long) */
1323 false, /* pc_relative */
1325 complain_overflow_dont, /* complain_on_overflow */
1326 bfd_elf_generic_reloc, /* special_function */
1327 "R_MIPS_INSERT_B", /* name */
1328 false, /* partial_inplace */
1330 0xffffffff, /* dst_mask */
1331 false), /* pcrel_offset */
1333 /* Delete a 32 bit instruction. */
1334 /* FIXME: Not handled correctly. */
1335 HOWTO (R_MIPS_DELETE, /* type */
1337 2, /* size (0 = byte, 1 = short, 2 = long) */
1339 false, /* pc_relative */
1341 complain_overflow_dont, /* complain_on_overflow */
1342 bfd_elf_generic_reloc, /* special_function */
1343 "R_MIPS_DELETE", /* name */
1344 false, /* partial_inplace */
1346 0xffffffff, /* dst_mask */
1347 false), /* pcrel_offset */
1349 /* Get the higher value of a 64 bit addend. */
1350 HOWTO (R_MIPS_HIGHER, /* type */
1352 2, /* size (0 = byte, 1 = short, 2 = long) */
1354 false, /* pc_relative */
1356 complain_overflow_dont, /* complain_on_overflow */
1357 bfd_elf_generic_reloc, /* special_function */
1358 "R_MIPS_HIGHER", /* name */
1359 false, /* partial_inplace */
1361 0x0000ffff, /* dst_mask */
1362 false), /* pcrel_offset */
1364 /* Get the highest value of a 64 bit addend. */
1365 HOWTO (R_MIPS_HIGHEST, /* type */
1367 2, /* size (0 = byte, 1 = short, 2 = long) */
1369 false, /* pc_relative */
1371 complain_overflow_dont, /* complain_on_overflow */
1372 bfd_elf_generic_reloc, /* special_function */
1373 "R_MIPS_HIGHEST", /* name */
1374 false, /* partial_inplace */
1376 0x0000ffff, /* dst_mask */
1377 false), /* pcrel_offset */
1379 /* High 16 bits of displacement in global offset table. */
1380 /* FIXME: Not handled correctly. */
1381 HOWTO (R_MIPS_CALL_HI16, /* type */
1383 2, /* size (0 = byte, 1 = short, 2 = long) */
1385 false, /* pc_relative */
1387 complain_overflow_dont, /* complain_on_overflow */
1388 bfd_elf_generic_reloc, /* special_function */
1389 "R_MIPS_CALL_HI16", /* name */
1390 false, /* partial_inplace */
1392 0x0000ffff, /* dst_mask */
1393 false), /* pcrel_offset */
1395 /* Low 16 bits of displacement in global offset table. */
1396 /* FIXME: Not handled correctly. */
1397 HOWTO (R_MIPS_CALL_LO16, /* type */
1399 2, /* size (0 = byte, 1 = short, 2 = long) */
1401 false, /* pc_relative */
1403 complain_overflow_dont, /* complain_on_overflow */
1404 bfd_elf_generic_reloc, /* special_function */
1405 "R_MIPS_CALL_LO16", /* name */
1406 false, /* partial_inplace */
1408 0x0000ffff, /* dst_mask */
1409 false), /* pcrel_offset */
1411 /* Section displacement, used by an associated event location section. */
1412 /* FIXME: Not handled correctly. */
1413 HOWTO (R_MIPS_SCN_DISP, /* type */
1415 2, /* size (0 = byte, 1 = short, 2 = long) */
1417 false, /* pc_relative */
1419 complain_overflow_dont, /* complain_on_overflow */
1420 bfd_elf_generic_reloc, /* special_function */
1421 "R_MIPS_SCN_DISP", /* name */
1422 false, /* partial_inplace */
1424 0xffffffff, /* dst_mask */
1425 false), /* pcrel_offset */
1427 HOWTO (R_MIPS_REL16, /* type */
1429 1, /* size (0 = byte, 1 = short, 2 = long) */
1431 false, /* pc_relative */
1433 complain_overflow_signed, /* complain_on_overflow */
1434 bfd_elf_generic_reloc, /* special_function */
1435 "R_MIPS_REL16", /* name */
1436 false, /* partial_inplace */
1438 0xffff, /* dst_mask */
1439 false), /* pcrel_offset */
1441 /* These two are obsolete. */
1442 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
1443 EMPTY_HOWTO (R_MIPS_PJUMP),
1445 /* Similiar to R_MIPS_REL32, but used for relocations in a GOT section.
1446 It must be used for multigot GOT's (and only there). */
1447 HOWTO (R_MIPS_RELGOT, /* type */
1449 2, /* size (0 = byte, 1 = short, 2 = long) */
1451 false, /* pc_relative */
1453 complain_overflow_dont, /* complain_on_overflow */
1454 bfd_elf_generic_reloc, /* special_function */
1455 "R_MIPS_RELGOT", /* name */
1456 false, /* partial_inplace */
1458 0xffffffff, /* dst_mask */
1459 false), /* pcrel_offset */
1461 /* Protected jump conversion. This is an optimization hint. No
1462 relocation is required for correctness. */
1463 HOWTO (R_MIPS_JALR, /* type */
1465 2, /* size (0 = byte, 1 = short, 2 = long) */
1467 false, /* pc_relative */
1469 complain_overflow_dont, /* complain_on_overflow */
1470 bfd_elf_generic_reloc, /* special_function */
1471 "R_MIPS_JALR", /* name */
1472 false, /* partial_inplace */
1474 0xffffffff, /* dst_mask */
1475 false), /* pcrel_offset */
1478 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
1479 is a hack to make the linker think that we need 64 bit values. */
1480 static reloc_howto_type elf_mips_ctor64_howto =
1481 HOWTO (R_MIPS_64, /* type */
1483 4, /* size (0 = byte, 1 = short, 2 = long) */
1485 false, /* pc_relative */
1487 complain_overflow_signed, /* complain_on_overflow */
1488 mips32_64bit_reloc, /* special_function */
1489 "R_MIPS_64", /* name */
1490 true, /* partial_inplace */
1491 0xffffffff, /* src_mask */
1492 0xffffffff, /* dst_mask */
1493 false); /* pcrel_offset */
1495 /* The reloc used for the mips16 jump instruction. */
1496 static reloc_howto_type elf_mips16_jump_howto =
1497 HOWTO (R_MIPS16_26, /* type */
1499 2, /* size (0 = byte, 1 = short, 2 = long) */
1501 false, /* pc_relative */
1503 complain_overflow_dont, /* complain_on_overflow */
1504 /* This needs complex overflow
1505 detection, because the upper four
1506 bits must match the PC. */
1507 mips16_jump_reloc, /* special_function */
1508 "R_MIPS16_26", /* name */
1509 true, /* partial_inplace */
1510 0x3ffffff, /* src_mask */
1511 0x3ffffff, /* dst_mask */
1512 false); /* pcrel_offset */
1514 /* The reloc used for the mips16 gprel instruction. */
1515 static reloc_howto_type elf_mips16_gprel_howto =
1516 HOWTO (R_MIPS16_GPREL, /* type */
1518 2, /* size (0 = byte, 1 = short, 2 = long) */
1520 false, /* pc_relative */
1522 complain_overflow_signed, /* complain_on_overflow */
1523 mips16_gprel_reloc, /* special_function */
1524 "R_MIPS16_GPREL", /* name */
1525 true, /* partial_inplace */
1526 0x07ff001f, /* src_mask */
1527 0x07ff001f, /* dst_mask */
1528 false); /* pcrel_offset */
1530 /* GNU extensions for embedded-pic. */
1531 /* High 16 bits of symbol value, pc-relative. */
1532 static reloc_howto_type elf_mips_gnu_rel_hi16 =
1533 HOWTO (R_MIPS_GNU_REL_HI16, /* type */
1535 2, /* size (0 = byte, 1 = short, 2 = long) */
1537 true, /* pc_relative */
1539 complain_overflow_dont, /* complain_on_overflow */
1540 _bfd_mips_elf_hi16_reloc, /* special_function */
1541 "R_MIPS_GNU_REL_HI16", /* name */
1542 true, /* partial_inplace */
1543 0xffff, /* src_mask */
1544 0xffff, /* dst_mask */
1545 true); /* pcrel_offset */
1547 /* Low 16 bits of symbol value, pc-relative. */
1548 static reloc_howto_type elf_mips_gnu_rel_lo16 =
1549 HOWTO (R_MIPS_GNU_REL_LO16, /* type */
1551 2, /* size (0 = byte, 1 = short, 2 = long) */
1553 true, /* pc_relative */
1555 complain_overflow_dont, /* complain_on_overflow */
1556 _bfd_mips_elf_lo16_reloc, /* special_function */
1557 "R_MIPS_GNU_REL_LO16", /* name */
1558 true, /* partial_inplace */
1559 0xffff, /* src_mask */
1560 0xffff, /* dst_mask */
1561 true); /* pcrel_offset */
1563 /* 16 bit offset for pc-relative branches. */
1564 static reloc_howto_type elf_mips_gnu_rel16_s2 =
1565 HOWTO (R_MIPS_GNU_REL16_S2, /* type */
1567 2, /* size (0 = byte, 1 = short, 2 = long) */
1569 true, /* pc_relative */
1571 complain_overflow_signed, /* complain_on_overflow */
1572 bfd_elf_generic_reloc, /* special_function */
1573 "R_MIPS_GNU_REL16_S2", /* name */
1574 true, /* partial_inplace */
1575 0xffff, /* src_mask */
1576 0xffff, /* dst_mask */
1577 true); /* pcrel_offset */
1579 /* 64 bit pc-relative. */
1580 static reloc_howto_type elf_mips_gnu_pcrel64 =
1581 HOWTO (R_MIPS_PC64, /* type */
1583 4, /* size (0 = byte, 1 = short, 2 = long) */
1585 true, /* pc_relative */
1587 complain_overflow_signed, /* complain_on_overflow */
1588 bfd_elf_generic_reloc, /* special_function */
1589 "R_MIPS_PC64", /* name */
1590 true, /* partial_inplace */
1591 MINUS_ONE, /* src_mask */
1592 MINUS_ONE, /* dst_mask */
1593 true); /* pcrel_offset */
1595 /* 32 bit pc-relative. */
1596 static reloc_howto_type elf_mips_gnu_pcrel32 =
1597 HOWTO (R_MIPS_PC32, /* type */
1599 2, /* size (0 = byte, 1 = short, 2 = long) */
1601 true, /* pc_relative */
1603 complain_overflow_signed, /* complain_on_overflow */
1604 bfd_elf_generic_reloc, /* special_function */
1605 "R_MIPS_PC32", /* name */
1606 true, /* partial_inplace */
1607 0xffffffff, /* src_mask */
1608 0xffffffff, /* dst_mask */
1609 true); /* pcrel_offset */
1611 /* GNU extension to record C++ vtable hierarchy */
1612 static reloc_howto_type elf_mips_gnu_vtinherit_howto =
1613 HOWTO (R_MIPS_GNU_VTINHERIT, /* type */
1615 2, /* size (0 = byte, 1 = short, 2 = long) */
1617 false, /* pc_relative */
1619 complain_overflow_dont, /* complain_on_overflow */
1620 NULL, /* special_function */
1621 "R_MIPS_GNU_VTINHERIT", /* name */
1622 false, /* partial_inplace */
1625 false); /* pcrel_offset */
1627 /* GNU extension to record C++ vtable member usage */
1628 static reloc_howto_type elf_mips_gnu_vtentry_howto =
1629 HOWTO (R_MIPS_GNU_VTENTRY, /* type */
1631 2, /* size (0 = byte, 1 = short, 2 = long) */
1633 false, /* pc_relative */
1635 complain_overflow_dont, /* complain_on_overflow */
1636 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1637 "R_MIPS_GNU_VTENTRY", /* name */
1638 false, /* partial_inplace */
1641 false); /* pcrel_offset */
1643 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
1644 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
1645 the HI16. Here we just save the information we need; we do the
1646 actual relocation when we see the LO16.
1648 MIPS ELF requires that the LO16 immediately follow the HI16. As a
1649 GNU extension, for non-pc-relative relocations, we permit an
1650 arbitrary number of HI16 relocs to be associated with a single LO16
1651 reloc. This extension permits gcc to output the HI and LO relocs
1654 This cannot be done for PC-relative relocations because both the HI16
1655 and LO16 parts of the relocations must be done relative to the LO16
1656 part, and there can be carry to or borrow from the HI16 part. */
1660 struct mips_hi16 *next;
1665 /* FIXME: This should not be a static variable. */
1667 static struct mips_hi16 *mips_hi16_list;
1669 bfd_reloc_status_type
1670 _bfd_mips_elf_hi16_reloc (abfd,
1677 bfd *abfd ATTRIBUTE_UNUSED;
1678 arelent *reloc_entry;
1681 asection *input_section;
1683 char **error_message;
1685 bfd_reloc_status_type ret;
1687 struct mips_hi16 *n;
1689 /* If we're relocating, and this an external symbol, we don't want
1690 to change anything. */
1691 if (output_bfd != (bfd *) NULL
1692 && (symbol->flags & BSF_SECTION_SYM) == 0
1693 && reloc_entry->addend == 0)
1695 reloc_entry->address += input_section->output_offset;
1696 return bfd_reloc_ok;
1701 if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
1703 boolean relocateable;
1706 if (ret == bfd_reloc_undefined)
1709 if (output_bfd != NULL)
1710 relocateable = true;
1713 relocateable = false;
1714 output_bfd = symbol->section->output_section->owner;
1717 ret = mips_elf_final_gp (output_bfd, symbol, relocateable,
1718 error_message, &gp);
1719 if (ret != bfd_reloc_ok)
1722 relocation = gp - reloc_entry->address;
1726 if (bfd_is_und_section (symbol->section)
1727 && output_bfd == (bfd *) NULL)
1728 ret = bfd_reloc_undefined;
1730 if (bfd_is_com_section (symbol->section))
1733 relocation = symbol->value;
1736 relocation += symbol->section->output_section->vma;
1737 relocation += symbol->section->output_offset;
1738 relocation += reloc_entry->addend;
1740 if (reloc_entry->address > input_section->_cooked_size)
1741 return bfd_reloc_outofrange;
1743 /* Save the information, and let LO16 do the actual relocation. */
1744 n = (struct mips_hi16 *) bfd_malloc ((bfd_size_type) sizeof *n);
1746 return bfd_reloc_outofrange;
1747 n->addr = (bfd_byte *) data + reloc_entry->address;
1748 n->addend = relocation;
1749 n->next = mips_hi16_list;
1752 if (output_bfd != (bfd *) NULL)
1753 reloc_entry->address += input_section->output_offset;
1758 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
1759 inplace relocation; this function exists in order to do the
1760 R_MIPS_HI16 relocation described above. */
1762 bfd_reloc_status_type
1763 _bfd_mips_elf_lo16_reloc (abfd,
1771 arelent *reloc_entry;
1774 asection *input_section;
1776 char **error_message;
1778 arelent gp_disp_relent;
1780 if (mips_hi16_list != NULL)
1782 struct mips_hi16 *l;
1789 unsigned long vallo;
1790 struct mips_hi16 *next;
1792 /* Do the HI16 relocation. Note that we actually don't need
1793 to know anything about the LO16 itself, except where to
1794 find the low 16 bits of the addend needed by the LO16. */
1795 insn = bfd_get_32 (abfd, l->addr);
1796 vallo = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1798 /* The low order 16 bits are always treated as a signed
1800 vallo = ((vallo & 0xffff) ^ 0x8000) - 0x8000;
1801 val = ((insn & 0xffff) << 16) + vallo;
1804 /* If PC-relative, we need to subtract out the address of the LO
1805 half of the HI/LO. (The actual relocation is relative
1806 to that instruction.) */
1807 if (reloc_entry->howto->pc_relative)
1808 val -= reloc_entry->address;
1810 /* At this point, "val" has the value of the combined HI/LO
1811 pair. If the low order 16 bits (which will be used for
1812 the LO16 insn) are negative, then we will need an
1813 adjustment for the high order 16 bits. */
1815 val = (val >> 16) & 0xffff;
1817 insn &= ~ (bfd_vma) 0xffff;
1819 bfd_put_32 (abfd, (bfd_vma) insn, l->addr);
1821 if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
1823 gp_disp_relent = *reloc_entry;
1824 reloc_entry = &gp_disp_relent;
1825 reloc_entry->addend = l->addend;
1833 mips_hi16_list = NULL;
1835 else if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
1837 bfd_reloc_status_type ret;
1838 bfd_vma gp, relocation;
1840 /* FIXME: Does this case ever occur? */
1842 ret = mips_elf_final_gp (output_bfd, symbol, true, error_message, &gp);
1843 if (ret != bfd_reloc_ok)
1846 relocation = gp - reloc_entry->address;
1847 relocation += symbol->section->output_section->vma;
1848 relocation += symbol->section->output_offset;
1849 relocation += reloc_entry->addend;
1851 if (reloc_entry->address > input_section->_cooked_size)
1852 return bfd_reloc_outofrange;
1854 gp_disp_relent = *reloc_entry;
1855 reloc_entry = &gp_disp_relent;
1856 reloc_entry->addend = relocation - 4;
1859 /* Now do the LO16 reloc in the usual way. */
1860 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1861 input_section, output_bfd, error_message);
1864 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1865 table used for PIC code. If the symbol is an external symbol, the
1866 instruction is modified to contain the offset of the appropriate
1867 entry in the global offset table. If the symbol is a section
1868 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1869 addends are combined to form the real addend against the section
1870 symbol; the GOT16 is modified to contain the offset of an entry in
1871 the global offset table, and the LO16 is modified to offset it
1872 appropriately. Thus an offset larger than 16 bits requires a
1873 modified value in the global offset table.
1875 This implementation suffices for the assembler, but the linker does
1876 not yet know how to create global offset tables. */
1878 bfd_reloc_status_type
1879 _bfd_mips_elf_got16_reloc (abfd,
1887 arelent *reloc_entry;
1890 asection *input_section;
1892 char **error_message;
1894 /* If we're relocating, and this an external symbol, we don't want
1895 to change anything. */
1896 if (output_bfd != (bfd *) NULL
1897 && (symbol->flags & BSF_SECTION_SYM) == 0
1898 && reloc_entry->addend == 0)
1900 reloc_entry->address += input_section->output_offset;
1901 return bfd_reloc_ok;
1904 /* If we're relocating, and this is a local symbol, we can handle it
1906 if (output_bfd != (bfd *) NULL
1907 && (symbol->flags & BSF_SECTION_SYM) != 0)
1908 return _bfd_mips_elf_hi16_reloc (abfd, reloc_entry, symbol, data,
1909 input_section, output_bfd, error_message);
1914 /* Set the GP value for OUTPUT_BFD. Returns false if this is a
1915 dangerous relocation. */
1918 mips_elf_assign_gp (output_bfd, pgp)
1926 /* If we've already figured out what GP will be, just return it. */
1927 *pgp = _bfd_get_gp_value (output_bfd);
1931 count = bfd_get_symcount (output_bfd);
1932 sym = bfd_get_outsymbols (output_bfd);
1934 /* The linker script will have created a symbol named `_gp' with the
1935 appropriate value. */
1936 if (sym == (asymbol **) NULL)
1940 for (i = 0; i < count; i++, sym++)
1942 register const char *name;
1944 name = bfd_asymbol_name (*sym);
1945 if (*name == '_' && strcmp (name, "_gp") == 0)
1947 *pgp = bfd_asymbol_value (*sym);
1948 _bfd_set_gp_value (output_bfd, *pgp);
1956 /* Only get the error once. */
1958 _bfd_set_gp_value (output_bfd, *pgp);
1965 /* We have to figure out the gp value, so that we can adjust the
1966 symbol value correctly. We look up the symbol _gp in the output
1967 BFD. If we can't find it, we're stuck. We cache it in the ELF
1968 target data. We don't need to adjust the symbol value for an
1969 external symbol if we are producing relocateable output. */
1971 static bfd_reloc_status_type
1972 mips_elf_final_gp (output_bfd, symbol, relocateable, error_message, pgp)
1975 boolean relocateable;
1976 char **error_message;
1979 if (bfd_is_und_section (symbol->section)
1983 return bfd_reloc_undefined;
1986 *pgp = _bfd_get_gp_value (output_bfd);
1989 || (symbol->flags & BSF_SECTION_SYM) != 0))
1993 /* Make up a value. */
1994 *pgp = symbol->section->output_section->vma + 0x4000;
1995 _bfd_set_gp_value (output_bfd, *pgp);
1997 else if (!mips_elf_assign_gp (output_bfd, pgp))
2000 (char *) _("GP relative relocation when _gp not defined");
2001 return bfd_reloc_dangerous;
2005 return bfd_reloc_ok;
2008 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
2009 become the offset from the gp register. This function also handles
2010 R_MIPS_LITERAL relocations, although those can be handled more
2011 cleverly because the entries in the .lit8 and .lit4 sections can be
2014 static bfd_reloc_status_type gprel16_with_gp PARAMS ((bfd *, asymbol *,
2015 arelent *, asection *,
2016 boolean, PTR, bfd_vma));
2018 bfd_reloc_status_type
2019 _bfd_mips_elf_gprel16_reloc (abfd, reloc_entry, symbol, data, input_section,
2020 output_bfd, error_message)
2022 arelent *reloc_entry;
2025 asection *input_section;
2027 char **error_message;
2029 boolean relocateable;
2030 bfd_reloc_status_type ret;
2033 /* If we're relocating, and this is an external symbol with no
2034 addend, we don't want to change anything. We will only have an
2035 addend if this is a newly created reloc, not read from an ELF
2037 if (output_bfd != (bfd *) NULL
2038 && (symbol->flags & BSF_SECTION_SYM) == 0
2039 && reloc_entry->addend == 0)
2041 reloc_entry->address += input_section->output_offset;
2042 return bfd_reloc_ok;
2045 if (output_bfd != (bfd *) NULL)
2046 relocateable = true;
2049 relocateable = false;
2050 output_bfd = symbol->section->output_section->owner;
2053 ret = mips_elf_final_gp (output_bfd, symbol, relocateable, error_message,
2055 if (ret != bfd_reloc_ok)
2058 return gprel16_with_gp (abfd, symbol, reloc_entry, input_section,
2059 relocateable, data, gp);
2062 static bfd_reloc_status_type
2063 gprel16_with_gp (abfd, symbol, reloc_entry, input_section, relocateable, data,
2067 arelent *reloc_entry;
2068 asection *input_section;
2069 boolean relocateable;
2077 if (bfd_is_com_section (symbol->section))
2080 relocation = symbol->value;
2082 relocation += symbol->section->output_section->vma;
2083 relocation += symbol->section->output_offset;
2085 if (reloc_entry->address > input_section->_cooked_size)
2086 return bfd_reloc_outofrange;
2088 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
2090 /* Set val to the offset into the section or symbol. */
2091 if (reloc_entry->howto->src_mask == 0)
2093 /* This case occurs with the 64-bit MIPS ELF ABI. */
2094 val = reloc_entry->addend;
2098 val = ((insn & 0xffff) + reloc_entry->addend) & 0xffff;
2103 /* Adjust val for the final section location and GP value. If we
2104 are producing relocateable output, we don't want to do this for
2105 an external symbol. */
2107 || (symbol->flags & BSF_SECTION_SYM) != 0)
2108 val += relocation - gp;
2110 insn = (insn & ~0xffff) | (val & 0xffff);
2111 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
2114 reloc_entry->address += input_section->output_offset;
2116 /* Make sure it fit in 16 bits. */
2117 if ((long) val >= 0x8000 || (long) val < -0x8000)
2118 return bfd_reloc_overflow;
2120 return bfd_reloc_ok;
2123 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
2124 from the gp register? XXX */
2126 static bfd_reloc_status_type gprel32_with_gp PARAMS ((bfd *, asymbol *,
2127 arelent *, asection *,
2128 boolean, PTR, bfd_vma));
2130 bfd_reloc_status_type
2131 _bfd_mips_elf_gprel32_reloc (abfd,
2139 arelent *reloc_entry;
2142 asection *input_section;
2144 char **error_message;
2146 boolean relocateable;
2147 bfd_reloc_status_type ret;
2150 /* If we're relocating, and this is an external symbol with no
2151 addend, we don't want to change anything. We will only have an
2152 addend if this is a newly created reloc, not read from an ELF
2154 if (output_bfd != (bfd *) NULL
2155 && (symbol->flags & BSF_SECTION_SYM) == 0
2156 && reloc_entry->addend == 0)
2158 *error_message = (char *)
2159 _("32bits gp relative relocation occurs for an external symbol");
2160 return bfd_reloc_outofrange;
2163 if (output_bfd != (bfd *) NULL)
2165 relocateable = true;
2166 gp = _bfd_get_gp_value (output_bfd);
2170 relocateable = false;
2171 output_bfd = symbol->section->output_section->owner;
2173 ret = mips_elf_final_gp (output_bfd, symbol, relocateable,
2174 error_message, &gp);
2175 if (ret != bfd_reloc_ok)
2179 return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
2180 relocateable, data, gp);
2183 static bfd_reloc_status_type
2184 gprel32_with_gp (abfd, symbol, reloc_entry, input_section, relocateable, data,
2188 arelent *reloc_entry;
2189 asection *input_section;
2190 boolean relocateable;
2197 if (bfd_is_com_section (symbol->section))
2200 relocation = symbol->value;
2202 relocation += symbol->section->output_section->vma;
2203 relocation += symbol->section->output_offset;
2205 if (reloc_entry->address > input_section->_cooked_size)
2206 return bfd_reloc_outofrange;
2208 if (reloc_entry->howto->src_mask == 0)
2210 /* This case arises with the 64-bit MIPS ELF ABI. */
2214 val = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
2216 /* Set val to the offset into the section or symbol. */
2217 val += reloc_entry->addend;
2219 /* Adjust val for the final section location and GP value. If we
2220 are producing relocateable output, we don't want to do this for
2221 an external symbol. */
2223 || (symbol->flags & BSF_SECTION_SYM) != 0)
2224 val += relocation - gp;
2226 bfd_put_32 (abfd, (bfd_vma) val, (bfd_byte *) data + reloc_entry->address);
2229 reloc_entry->address += input_section->output_offset;
2231 return bfd_reloc_ok;
2234 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
2235 generated when addresses are 64 bits. The upper 32 bits are a simple
2238 static bfd_reloc_status_type
2239 mips32_64bit_reloc (abfd, reloc_entry, symbol, data, input_section,
2240 output_bfd, error_message)
2242 arelent *reloc_entry;
2245 asection *input_section;
2247 char **error_message;
2249 bfd_reloc_status_type r;
2254 r = bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2255 input_section, output_bfd, error_message);
2256 if (r != bfd_reloc_continue)
2259 /* Do a normal 32 bit relocation on the lower 32 bits. */
2260 reloc32 = *reloc_entry;
2261 if (bfd_big_endian (abfd))
2262 reloc32.address += 4;
2263 reloc32.howto = &elf_mips_howto_table_rel[R_MIPS_32];
2264 r = bfd_perform_relocation (abfd, &reloc32, data, input_section,
2265 output_bfd, error_message);
2267 /* Sign extend into the upper 32 bits. */
2268 val = bfd_get_32 (abfd, (bfd_byte *) data + reloc32.address);
2269 if ((val & 0x80000000) != 0)
2273 addr = reloc_entry->address;
2274 if (bfd_little_endian (abfd))
2276 bfd_put_32 (abfd, (bfd_vma) val, (bfd_byte *) data + addr);
2281 /* Handle a mips16 jump. */
2283 static bfd_reloc_status_type
2284 mips16_jump_reloc (abfd, reloc_entry, symbol, data, input_section,
2285 output_bfd, error_message)
2286 bfd *abfd ATTRIBUTE_UNUSED;
2287 arelent *reloc_entry;
2289 PTR data ATTRIBUTE_UNUSED;
2290 asection *input_section;
2292 char **error_message ATTRIBUTE_UNUSED;
2294 if (output_bfd != (bfd *) NULL
2295 && (symbol->flags & BSF_SECTION_SYM) == 0
2296 && reloc_entry->addend == 0)
2298 reloc_entry->address += input_section->output_offset;
2299 return bfd_reloc_ok;
2304 static boolean warned;
2307 (*_bfd_error_handler)
2308 (_("Linking mips16 objects into %s format is not supported"),
2309 bfd_get_target (input_section->output_section->owner));
2313 return bfd_reloc_undefined;
2316 /* Handle a mips16 GP relative reloc. */
2318 static bfd_reloc_status_type
2319 mips16_gprel_reloc (abfd, reloc_entry, symbol, data, input_section,
2320 output_bfd, error_message)
2322 arelent *reloc_entry;
2325 asection *input_section;
2327 char **error_message;
2329 boolean relocateable;
2330 bfd_reloc_status_type ret;
2332 unsigned short extend, insn;
2333 unsigned long final;
2335 /* If we're relocating, and this is an external symbol with no
2336 addend, we don't want to change anything. We will only have an
2337 addend if this is a newly created reloc, not read from an ELF
2339 if (output_bfd != NULL
2340 && (symbol->flags & BSF_SECTION_SYM) == 0
2341 && reloc_entry->addend == 0)
2343 reloc_entry->address += input_section->output_offset;
2344 return bfd_reloc_ok;
2347 if (output_bfd != NULL)
2348 relocateable = true;
2351 relocateable = false;
2352 output_bfd = symbol->section->output_section->owner;
2355 ret = mips_elf_final_gp (output_bfd, symbol, relocateable, error_message,
2357 if (ret != bfd_reloc_ok)
2360 if (reloc_entry->address > input_section->_cooked_size)
2361 return bfd_reloc_outofrange;
2363 /* Pick up the mips16 extend instruction and the real instruction. */
2364 extend = bfd_get_16 (abfd, (bfd_byte *) data + reloc_entry->address);
2365 insn = bfd_get_16 (abfd, (bfd_byte *) data + reloc_entry->address + 2);
2367 /* Stuff the current addend back as a 32 bit value, do the usual
2368 relocation, and then clean up. */
2370 (bfd_vma) (((extend & 0x1f) << 11)
2373 (bfd_byte *) data + reloc_entry->address);
2375 ret = gprel16_with_gp (abfd, symbol, reloc_entry, input_section,
2376 relocateable, data, gp);
2378 final = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
2380 (bfd_vma) ((extend & 0xf800)
2381 | ((final >> 11) & 0x1f)
2383 (bfd_byte *) data + reloc_entry->address);
2385 (bfd_vma) ((insn & 0xffe0)
2387 (bfd_byte *) data + reloc_entry->address + 2);
2392 /* Return the ISA for a MIPS e_flags value. */
2395 elf_mips_isa (flags)
2398 switch (flags & EF_MIPS_ARCH)
2410 case E_MIPS_ARCH_32:
2412 case E_MIPS_ARCH_64:
2418 /* Return the MACH for a MIPS e_flags value. */
2420 static INLINE unsigned long
2421 elf_mips_mach (flags)
2424 switch (flags & EF_MIPS_MACH)
2426 case E_MIPS_MACH_3900:
2427 return bfd_mach_mips3900;
2429 case E_MIPS_MACH_4010:
2430 return bfd_mach_mips4010;
2432 case E_MIPS_MACH_4100:
2433 return bfd_mach_mips4100;
2435 case E_MIPS_MACH_4111:
2436 return bfd_mach_mips4111;
2438 case E_MIPS_MACH_4650:
2439 return bfd_mach_mips4650;
2441 case E_MIPS_MACH_SB1:
2442 return bfd_mach_mips_sb1;
2445 switch (flags & EF_MIPS_ARCH)
2449 return bfd_mach_mips3000;
2453 return bfd_mach_mips6000;
2457 return bfd_mach_mips4000;
2461 return bfd_mach_mips8000;
2465 return bfd_mach_mips5;
2468 case E_MIPS_ARCH_32:
2469 return bfd_mach_mipsisa32;
2472 case E_MIPS_ARCH_64:
2473 return bfd_mach_mipsisa64;
2481 /* Return printable name for ABI. */
2483 static INLINE char *
2484 elf_mips_abi_name (abfd)
2489 flags = elf_elfheader (abfd)->e_flags;
2490 switch (flags & EF_MIPS_ABI)
2493 if (ABI_N32_P (abfd))
2495 else if (ABI_64_P (abfd))
2499 case E_MIPS_ABI_O32:
2501 case E_MIPS_ABI_O64:
2503 case E_MIPS_ABI_EABI32:
2505 case E_MIPS_ABI_EABI64:
2508 return "unknown abi";
2512 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
2514 struct elf_reloc_map {
2515 bfd_reloc_code_real_type bfd_reloc_val;
2516 enum elf_mips_reloc_type elf_reloc_val;
2519 static const struct elf_reloc_map mips_reloc_map[] =
2521 { BFD_RELOC_NONE, R_MIPS_NONE, },
2522 { BFD_RELOC_16, R_MIPS_16 },
2523 { BFD_RELOC_32, R_MIPS_32 },
2524 { BFD_RELOC_64, R_MIPS_64 },
2525 { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
2526 { BFD_RELOC_HI16_S, R_MIPS_HI16 },
2527 { BFD_RELOC_LO16, R_MIPS_LO16 },
2528 { BFD_RELOC_GPREL16, R_MIPS_GPREL16 },
2529 { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
2530 { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
2531 { BFD_RELOC_16_PCREL, R_MIPS_PC16 },
2532 { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
2533 { BFD_RELOC_GPREL32, R_MIPS_GPREL32 },
2534 { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
2535 { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 },
2536 { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 },
2537 { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 },
2538 { BFD_RELOC_MIPS_SUB, R_MIPS_SUB },
2539 { BFD_RELOC_MIPS_GOT_PAGE, R_MIPS_GOT_PAGE },
2540 { BFD_RELOC_MIPS_GOT_OFST, R_MIPS_GOT_OFST },
2541 { BFD_RELOC_MIPS_GOT_DISP, R_MIPS_GOT_DISP }
2544 /* Given a BFD reloc type, return a howto structure. */
2546 static reloc_howto_type *
2547 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
2549 bfd_reloc_code_real_type code;
2553 for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map); i++)
2555 if (mips_reloc_map[i].bfd_reloc_val == code)
2556 return &elf_mips_howto_table_rel[(int) mips_reloc_map[i].elf_reloc_val];
2562 bfd_set_error (bfd_error_bad_value);
2565 case BFD_RELOC_CTOR:
2566 /* We need to handle BFD_RELOC_CTOR specially.
2567 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
2568 size of addresses on this architecture. */
2569 if (bfd_arch_bits_per_address (abfd) == 32)
2570 return &elf_mips_howto_table_rel[(int) R_MIPS_32];
2572 return &elf_mips_ctor64_howto;
2574 case BFD_RELOC_MIPS16_JMP:
2575 return &elf_mips16_jump_howto;
2576 case BFD_RELOC_MIPS16_GPREL:
2577 return &elf_mips16_gprel_howto;
2578 case BFD_RELOC_VTABLE_INHERIT:
2579 return &elf_mips_gnu_vtinherit_howto;
2580 case BFD_RELOC_VTABLE_ENTRY:
2581 return &elf_mips_gnu_vtentry_howto;
2582 case BFD_RELOC_PCREL_HI16_S:
2583 return &elf_mips_gnu_rel_hi16;
2584 case BFD_RELOC_PCREL_LO16:
2585 return &elf_mips_gnu_rel_lo16;
2586 case BFD_RELOC_16_PCREL_S2:
2587 return &elf_mips_gnu_rel16_s2;
2588 case BFD_RELOC_64_PCREL:
2589 return &elf_mips_gnu_pcrel64;
2590 case BFD_RELOC_32_PCREL:
2591 return &elf_mips_gnu_pcrel32;
2595 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
2597 static reloc_howto_type *
2598 mips_rtype_to_howto (r_type)
2599 unsigned int r_type;
2604 return &elf_mips16_jump_howto;
2606 case R_MIPS16_GPREL:
2607 return &elf_mips16_gprel_howto;
2609 case R_MIPS_GNU_VTINHERIT:
2610 return &elf_mips_gnu_vtinherit_howto;
2612 case R_MIPS_GNU_VTENTRY:
2613 return &elf_mips_gnu_vtentry_howto;
2615 case R_MIPS_GNU_REL_HI16:
2616 return &elf_mips_gnu_rel_hi16;
2618 case R_MIPS_GNU_REL_LO16:
2619 return &elf_mips_gnu_rel_lo16;
2621 case R_MIPS_GNU_REL16_S2:
2622 return &elf_mips_gnu_rel16_s2;
2625 return &elf_mips_gnu_pcrel64;
2628 return &elf_mips_gnu_pcrel32;
2632 BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
2633 return &elf_mips_howto_table_rel[r_type];
2638 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
2641 mips_info_to_howto_rel (abfd, cache_ptr, dst)
2644 Elf32_Internal_Rel *dst;
2646 unsigned int r_type;
2648 r_type = ELF32_R_TYPE (dst->r_info);
2649 cache_ptr->howto = mips_rtype_to_howto (r_type);
2651 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
2652 value for the object file. We get the addend now, rather than
2653 when we do the relocation, because the symbol manipulations done
2654 by the linker may cause us to lose track of the input BFD. */
2655 if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
2656 && (r_type == (unsigned int) R_MIPS_GPREL16
2657 || r_type == (unsigned int) R_MIPS_LITERAL))
2658 cache_ptr->addend = elf_gp (abfd);
2661 /* Given a MIPS Elf32_Internal_Rela, fill in an arelent structure. */
2664 mips_info_to_howto_rela (abfd, cache_ptr, dst)
2667 Elf32_Internal_Rela *dst;
2669 /* Since an Elf32_Internal_Rel is an initial prefix of an
2670 Elf32_Internal_Rela, we can just use mips_info_to_howto_rel
2672 mips_info_to_howto_rel (abfd, cache_ptr, (Elf32_Internal_Rel *) dst);
2674 /* If we ever need to do any extra processing with dst->r_addend
2675 (the field omitted in an Elf32_Internal_Rel) we can do it here. */
2678 /* A .reginfo section holds a single Elf32_RegInfo structure. These
2679 routines swap this structure in and out. They are used outside of
2680 BFD, so they are globally visible. */
2683 bfd_mips_elf32_swap_reginfo_in (abfd, ex, in)
2685 const Elf32_External_RegInfo *ex;
2688 in->ri_gprmask = H_GET_32 (abfd, ex->ri_gprmask);
2689 in->ri_cprmask[0] = H_GET_32 (abfd, ex->ri_cprmask[0]);
2690 in->ri_cprmask[1] = H_GET_32 (abfd, ex->ri_cprmask[1]);
2691 in->ri_cprmask[2] = H_GET_32 (abfd, ex->ri_cprmask[2]);
2692 in->ri_cprmask[3] = H_GET_32 (abfd, ex->ri_cprmask[3]);
2693 in->ri_gp_value = H_GET_32 (abfd, ex->ri_gp_value);
2697 bfd_mips_elf32_swap_reginfo_out (abfd, in, ex)
2699 const Elf32_RegInfo *in;
2700 Elf32_External_RegInfo *ex;
2702 H_PUT_32 (abfd, in->ri_gprmask, ex->ri_gprmask);
2703 H_PUT_32 (abfd, in->ri_cprmask[0], ex->ri_cprmask[0]);
2704 H_PUT_32 (abfd, in->ri_cprmask[1], ex->ri_cprmask[1]);
2705 H_PUT_32 (abfd, in->ri_cprmask[2], ex->ri_cprmask[2]);
2706 H_PUT_32 (abfd, in->ri_cprmask[3], ex->ri_cprmask[3]);
2707 H_PUT_32 (abfd, in->ri_gp_value, ex->ri_gp_value);
2710 /* In the 64 bit ABI, the .MIPS.options section holds register
2711 information in an Elf64_Reginfo structure. These routines swap
2712 them in and out. They are globally visible because they are used
2713 outside of BFD. These routines are here so that gas can call them
2714 without worrying about whether the 64 bit ABI has been included. */
2717 bfd_mips_elf64_swap_reginfo_in (abfd, ex, in)
2719 const Elf64_External_RegInfo *ex;
2720 Elf64_Internal_RegInfo *in;
2722 in->ri_gprmask = H_GET_32 (abfd, ex->ri_gprmask);
2723 in->ri_pad = H_GET_32 (abfd, ex->ri_pad);
2724 in->ri_cprmask[0] = H_GET_32 (abfd, ex->ri_cprmask[0]);
2725 in->ri_cprmask[1] = H_GET_32 (abfd, ex->ri_cprmask[1]);
2726 in->ri_cprmask[2] = H_GET_32 (abfd, ex->ri_cprmask[2]);
2727 in->ri_cprmask[3] = H_GET_32 (abfd, ex->ri_cprmask[3]);
2728 in->ri_gp_value = H_GET_64 (abfd, ex->ri_gp_value);
2732 bfd_mips_elf64_swap_reginfo_out (abfd, in, ex)
2734 const Elf64_Internal_RegInfo *in;
2735 Elf64_External_RegInfo *ex;
2737 H_PUT_32 (abfd, in->ri_gprmask, ex->ri_gprmask);
2738 H_PUT_32 (abfd, in->ri_pad, ex->ri_pad);
2739 H_PUT_32 (abfd, in->ri_cprmask[0], ex->ri_cprmask[0]);
2740 H_PUT_32 (abfd, in->ri_cprmask[1], ex->ri_cprmask[1]);
2741 H_PUT_32 (abfd, in->ri_cprmask[2], ex->ri_cprmask[2]);
2742 H_PUT_32 (abfd, in->ri_cprmask[3], ex->ri_cprmask[3]);
2743 H_PUT_64 (abfd, in->ri_gp_value, ex->ri_gp_value);
2746 /* Swap an entry in a .gptab section. Note that these routines rely
2747 on the equivalence of the two elements of the union. */
2750 bfd_mips_elf32_swap_gptab_in (abfd, ex, in)
2752 const Elf32_External_gptab *ex;
2755 in->gt_entry.gt_g_value = H_GET_32 (abfd, ex->gt_entry.gt_g_value);
2756 in->gt_entry.gt_bytes = H_GET_32 (abfd, ex->gt_entry.gt_bytes);
2760 bfd_mips_elf32_swap_gptab_out (abfd, in, ex)
2762 const Elf32_gptab *in;
2763 Elf32_External_gptab *ex;
2765 H_PUT_32 (abfd, in->gt_entry.gt_g_value, ex->gt_entry.gt_g_value);
2766 H_PUT_32 (abfd, in->gt_entry.gt_bytes, ex->gt_entry.gt_bytes);
2770 bfd_elf32_swap_compact_rel_out (abfd, in, ex)
2772 const Elf32_compact_rel *in;
2773 Elf32_External_compact_rel *ex;
2775 H_PUT_32 (abfd, in->id1, ex->id1);
2776 H_PUT_32 (abfd, in->num, ex->num);
2777 H_PUT_32 (abfd, in->id2, ex->id2);
2778 H_PUT_32 (abfd, in->offset, ex->offset);
2779 H_PUT_32 (abfd, in->reserved0, ex->reserved0);
2780 H_PUT_32 (abfd, in->reserved1, ex->reserved1);
2784 bfd_elf32_swap_crinfo_out (abfd, in, ex)
2786 const Elf32_crinfo *in;
2787 Elf32_External_crinfo *ex;
2791 l = (((in->ctype & CRINFO_CTYPE) << CRINFO_CTYPE_SH)
2792 | ((in->rtype & CRINFO_RTYPE) << CRINFO_RTYPE_SH)
2793 | ((in->dist2to & CRINFO_DIST2TO) << CRINFO_DIST2TO_SH)
2794 | ((in->relvaddr & CRINFO_RELVADDR) << CRINFO_RELVADDR_SH));
2795 H_PUT_32 (abfd, l, ex->info);
2796 H_PUT_32 (abfd, in->konst, ex->konst);
2797 H_PUT_32 (abfd, in->vaddr, ex->vaddr);
2800 /* Swap in an options header. */
2803 bfd_mips_elf_swap_options_in (abfd, ex, in)
2805 const Elf_External_Options *ex;
2806 Elf_Internal_Options *in;
2808 in->kind = H_GET_8 (abfd, ex->kind);
2809 in->size = H_GET_8 (abfd, ex->size);
2810 in->section = H_GET_16 (abfd, ex->section);
2811 in->info = H_GET_32 (abfd, ex->info);
2814 /* Swap out an options header. */
2817 bfd_mips_elf_swap_options_out (abfd, in, ex)
2819 const Elf_Internal_Options *in;
2820 Elf_External_Options *ex;
2822 H_PUT_8 (abfd, in->kind, ex->kind);
2823 H_PUT_8 (abfd, in->size, ex->size);
2824 H_PUT_16 (abfd, in->section, ex->section);
2825 H_PUT_32 (abfd, in->info, ex->info);
2828 /* Swap in an MSYM entry. */
2831 bfd_mips_elf_swap_msym_in (abfd, ex, in)
2833 const Elf32_External_Msym *ex;
2834 Elf32_Internal_Msym *in;
2836 in->ms_hash_value = H_GET_32 (abfd, ex->ms_hash_value);
2837 in->ms_info = H_GET_32 (abfd, ex->ms_info);
2840 /* Swap out an MSYM entry. */
2843 bfd_mips_elf_swap_msym_out (abfd, in, ex)
2845 const Elf32_Internal_Msym *in;
2846 Elf32_External_Msym *ex;
2848 H_PUT_32 (abfd, in->ms_hash_value, ex->ms_hash_value);
2849 H_PUT_32 (abfd, in->ms_info, ex->ms_info);
2852 /* Determine whether a symbol is global for the purposes of splitting
2853 the symbol table into global symbols and local symbols. At least
2854 on Irix 5, this split must be between section symbols and all other
2855 symbols. On most ELF targets the split is between static symbols
2856 and externally visible symbols. */
2859 mips_elf_sym_is_global (abfd, sym)
2860 bfd *abfd ATTRIBUTE_UNUSED;
2863 if (SGI_COMPAT (abfd))
2864 return (sym->flags & BSF_SECTION_SYM) == 0;
2866 return ((sym->flags & (BSF_GLOBAL | BSF_WEAK)) != 0
2867 || bfd_is_und_section (bfd_get_section (sym))
2868 || bfd_is_com_section (bfd_get_section (sym)));
2871 /* Set the right machine number for a MIPS ELF file. This is used for
2872 both the 32-bit and the 64-bit ABI. */
2875 _bfd_mips_elf_object_p (abfd)
2878 /* Irix 5 and 6 are broken. Object file symbol tables are not always
2879 sorted correctly such that local symbols precede global symbols,
2880 and the sh_info field in the symbol table is not always right. */
2881 if (SGI_COMPAT(abfd))
2882 elf_bad_symtab (abfd) = true;
2884 bfd_default_set_arch_mach (abfd, bfd_arch_mips,
2885 elf_mips_mach (elf_elfheader (abfd)->e_flags));
2889 /* The final processing done just before writing out a MIPS ELF object
2890 file. This gets the MIPS architecture right based on the machine
2891 number. This is used by both the 32-bit and the 64-bit ABI. */
2894 _bfd_mips_elf_final_write_processing (abfd, linker)
2896 boolean linker ATTRIBUTE_UNUSED;
2900 Elf_Internal_Shdr **hdrpp;
2904 switch (bfd_get_mach (abfd))
2907 case bfd_mach_mips3000:
2908 val = E_MIPS_ARCH_1;
2911 case bfd_mach_mips3900:
2912 val = E_MIPS_ARCH_1 | E_MIPS_MACH_3900;
2915 case bfd_mach_mips6000:
2916 val = E_MIPS_ARCH_2;
2919 case bfd_mach_mips4000:
2920 case bfd_mach_mips4300:
2921 case bfd_mach_mips4400:
2922 case bfd_mach_mips4600:
2923 val = E_MIPS_ARCH_3;
2926 case bfd_mach_mips4010:
2927 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4010;
2930 case bfd_mach_mips4100:
2931 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4100;
2934 case bfd_mach_mips4111:
2935 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4111;
2938 case bfd_mach_mips4650:
2939 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4650;
2942 case bfd_mach_mips5000:
2943 case bfd_mach_mips8000:
2944 case bfd_mach_mips10000:
2945 case bfd_mach_mips12000:
2946 val = E_MIPS_ARCH_4;
2949 case bfd_mach_mips5:
2950 val = E_MIPS_ARCH_5;
2953 case bfd_mach_mips_sb1:
2954 val = E_MIPS_ARCH_64 | E_MIPS_MACH_SB1;
2957 case bfd_mach_mipsisa32:
2958 val = E_MIPS_ARCH_32;
2961 case bfd_mach_mipsisa64:
2962 val = E_MIPS_ARCH_64;
2965 elf_elfheader (abfd)->e_flags &= ~(EF_MIPS_ARCH | EF_MIPS_MACH);
2966 elf_elfheader (abfd)->e_flags |= val;
2968 /* Set the sh_info field for .gptab sections and other appropriate
2969 info for each special section. */
2970 for (i = 1, hdrpp = elf_elfsections (abfd) + 1;
2971 i < elf_numsections (abfd);
2974 switch ((*hdrpp)->sh_type)
2977 case SHT_MIPS_LIBLIST:
2978 sec = bfd_get_section_by_name (abfd, ".dynstr");
2980 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx;
2983 case SHT_MIPS_GPTAB:
2984 BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
2985 name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section);
2986 BFD_ASSERT (name != NULL
2987 && strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0);
2988 sec = bfd_get_section_by_name (abfd, name + sizeof ".gptab" - 1);
2989 BFD_ASSERT (sec != NULL);
2990 (*hdrpp)->sh_info = elf_section_data (sec)->this_idx;
2993 case SHT_MIPS_CONTENT:
2994 BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
2995 name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section);
2996 BFD_ASSERT (name != NULL
2997 && strncmp (name, ".MIPS.content",
2998 sizeof ".MIPS.content" - 1) == 0);
2999 sec = bfd_get_section_by_name (abfd,
3000 name + sizeof ".MIPS.content" - 1);
3001 BFD_ASSERT (sec != NULL);
3002 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx;
3005 case SHT_MIPS_SYMBOL_LIB:
3006 sec = bfd_get_section_by_name (abfd, ".dynsym");
3008 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx;
3009 sec = bfd_get_section_by_name (abfd, ".liblist");
3011 (*hdrpp)->sh_info = elf_section_data (sec)->this_idx;
3014 case SHT_MIPS_EVENTS:
3015 BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
3016 name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section);
3017 BFD_ASSERT (name != NULL);
3018 if (strncmp (name, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
3019 sec = bfd_get_section_by_name (abfd,
3020 name + sizeof ".MIPS.events" - 1);
3023 BFD_ASSERT (strncmp (name, ".MIPS.post_rel",
3024 sizeof ".MIPS.post_rel" - 1) == 0);
3025 sec = bfd_get_section_by_name (abfd,
3027 + sizeof ".MIPS.post_rel" - 1));
3029 BFD_ASSERT (sec != NULL);
3030 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx;
3037 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
3040 _bfd_mips_elf_set_private_flags (abfd, flags)
3044 BFD_ASSERT (!elf_flags_init (abfd)
3045 || elf_elfheader (abfd)->e_flags == flags);
3047 elf_elfheader (abfd)->e_flags = flags;
3048 elf_flags_init (abfd) = true;
3052 /* Merge backend specific data from an object file to the output
3053 object file when linking. */
3056 _bfd_mips_elf_merge_private_bfd_data (ibfd, obfd)
3063 boolean null_input_bfd = true;
3066 /* Check if we have the same endianess */
3067 if (_bfd_generic_verify_endian_match (ibfd, obfd) == false)
3070 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
3071 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
3074 new_flags = elf_elfheader (ibfd)->e_flags;
3075 elf_elfheader (obfd)->e_flags |= new_flags & EF_MIPS_NOREORDER;
3076 old_flags = elf_elfheader (obfd)->e_flags;
3078 if (! elf_flags_init (obfd))
3080 elf_flags_init (obfd) = true;
3081 elf_elfheader (obfd)->e_flags = new_flags;
3082 elf_elfheader (obfd)->e_ident[EI_CLASS]
3083 = elf_elfheader (ibfd)->e_ident[EI_CLASS];
3085 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
3086 && bfd_get_arch_info (obfd)->the_default)
3088 if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
3089 bfd_get_mach (ibfd)))
3096 /* Check flag compatibility. */
3098 new_flags &= ~EF_MIPS_NOREORDER;
3099 old_flags &= ~EF_MIPS_NOREORDER;
3101 if (new_flags == old_flags)
3104 /* Check to see if the input BFD actually contains any sections.
3105 If not, its flags may not have been initialised either, but it cannot
3106 actually cause any incompatibility. */
3107 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
3109 /* Ignore synthetic sections and empty .text, .data and .bss sections
3110 which are automatically generated by gas. */
3111 if (strcmp (sec->name, ".reginfo")
3112 && strcmp (sec->name, ".mdebug")
3113 && ((!strcmp (sec->name, ".text")
3114 || !strcmp (sec->name, ".data")
3115 || !strcmp (sec->name, ".bss"))
3116 && sec->_raw_size != 0))
3118 null_input_bfd = false;
3127 if ((new_flags & EF_MIPS_PIC) != (old_flags & EF_MIPS_PIC))
3129 new_flags &= ~EF_MIPS_PIC;
3130 old_flags &= ~EF_MIPS_PIC;
3131 (*_bfd_error_handler)
3132 (_("%s: linking PIC files with non-PIC files"),
3133 bfd_archive_filename (ibfd));
3137 if ((new_flags & EF_MIPS_CPIC) != (old_flags & EF_MIPS_CPIC))
3139 new_flags &= ~EF_MIPS_CPIC;
3140 old_flags &= ~EF_MIPS_CPIC;
3141 (*_bfd_error_handler)
3142 (_("%s: linking abicalls files with non-abicalls files"),
3143 bfd_archive_filename (ibfd));
3147 /* Compare the ISA's. */
3148 if ((new_flags & (EF_MIPS_ARCH | EF_MIPS_MACH))
3149 != (old_flags & (EF_MIPS_ARCH | EF_MIPS_MACH)))
3151 int new_mach = new_flags & EF_MIPS_MACH;
3152 int old_mach = old_flags & EF_MIPS_MACH;
3153 int new_isa = elf_mips_isa (new_flags);
3154 int old_isa = elf_mips_isa (old_flags);
3156 /* If either has no machine specified, just compare the general isa's.
3157 Some combinations of machines are ok, if the isa's match. */
3160 || new_mach == old_mach
3163 /* Don't warn about mixing code using 32-bit ISAs, or mixing code
3164 using 64-bit ISAs. They will normally use the same data sizes
3165 and calling conventions. */
3167 if (( (new_isa == 1 || new_isa == 2 || new_isa == 32)
3168 ^ (old_isa == 1 || old_isa == 2 || old_isa == 32)) != 0)
3170 (*_bfd_error_handler)
3171 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
3172 bfd_archive_filename (ibfd), new_isa, old_isa);
3177 /* Do we need to update the mach field? */
3178 if (old_mach == 0 && new_mach != 0)
3179 elf_elfheader (obfd)->e_flags |= new_mach;
3181 /* Do we need to update the ISA field? */
3182 if (new_isa > old_isa)
3184 elf_elfheader (obfd)->e_flags &= ~EF_MIPS_ARCH;
3185 elf_elfheader (obfd)->e_flags
3186 |= new_flags & EF_MIPS_ARCH;
3192 (*_bfd_error_handler)
3193 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
3194 bfd_archive_filename (ibfd),
3195 elf_mips_mach (new_flags),
3196 elf_mips_mach (old_flags));
3200 new_flags &= ~(EF_MIPS_ARCH | EF_MIPS_MACH);
3201 old_flags &= ~(EF_MIPS_ARCH | EF_MIPS_MACH);
3204 /* Compare ABI's. The 64-bit ABI does not use EF_MIPS_ABI. But, it
3205 does set EI_CLASS differently from any 32-bit ABI. */
3206 if ((new_flags & EF_MIPS_ABI) != (old_flags & EF_MIPS_ABI)
3207 || (elf_elfheader (ibfd)->e_ident[EI_CLASS]
3208 != elf_elfheader (obfd)->e_ident[EI_CLASS]))
3210 /* Only error if both are set (to different values). */
3211 if (((new_flags & EF_MIPS_ABI) && (old_flags & EF_MIPS_ABI))
3212 || (elf_elfheader (ibfd)->e_ident[EI_CLASS]
3213 != elf_elfheader (obfd)->e_ident[EI_CLASS]))
3215 (*_bfd_error_handler)
3216 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
3217 bfd_archive_filename (ibfd),
3218 elf_mips_abi_name (ibfd),
3219 elf_mips_abi_name (obfd));
3222 new_flags &= ~EF_MIPS_ABI;
3223 old_flags &= ~EF_MIPS_ABI;
3226 /* Warn about any other mismatches */
3227 if (new_flags != old_flags)
3229 (*_bfd_error_handler)
3230 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
3231 bfd_archive_filename (ibfd), (unsigned long) new_flags,
3232 (unsigned long) old_flags);
3238 bfd_set_error (bfd_error_bad_value);
3246 _bfd_mips_elf_print_private_bfd_data (abfd, ptr)
3250 FILE *file = (FILE *) ptr;
3252 BFD_ASSERT (abfd != NULL && ptr != NULL);
3254 /* Print normal ELF private data. */
3255 _bfd_elf_print_private_bfd_data (abfd, ptr);
3257 /* xgettext:c-format */
3258 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
3260 if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_O32)
3261 fprintf (file, _(" [abi=O32]"));
3262 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_O64)
3263 fprintf (file, _(" [abi=O64]"));
3264 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI32)
3265 fprintf (file, _(" [abi=EABI32]"));
3266 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64)
3267 fprintf (file, _(" [abi=EABI64]"));
3268 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI))
3269 fprintf (file, _(" [abi unknown]"));
3270 else if (ABI_N32_P (abfd))
3271 fprintf (file, _(" [abi=N32]"));
3272 else if (ABI_64_P (abfd))
3273 fprintf (file, _(" [abi=64]"));
3275 fprintf (file, _(" [no abi set]"));
3277 if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1)
3278 fprintf (file, _(" [mips1]"));
3279 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2)
3280 fprintf (file, _(" [mips2]"));
3281 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3)
3282 fprintf (file, _(" [mips3]"));
3283 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4)
3284 fprintf (file, _(" [mips4]"));
3285 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_5)
3286 fprintf (file, _(" [mips5]"));
3287 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_32)
3288 fprintf (file, _(" [mips32]"));
3289 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_64)
3290 fprintf (file, _(" [mips64]"));
3292 fprintf (file, _(" [unknown ISA]"));
3294 if (elf_elfheader (abfd)->e_flags & EF_MIPS_32BITMODE)
3295 fprintf (file, _(" [32bitmode]"));
3297 fprintf (file, _(" [not 32bitmode]"));
3304 /* Handle a MIPS specific section when reading an object file. This
3305 is called when elfcode.h finds a section with an unknown type.
3306 This routine supports both the 32-bit and 64-bit ELF ABI.
3308 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
3312 _bfd_mips_elf_section_from_shdr (abfd, hdr, name)
3314 Elf_Internal_Shdr *hdr;
3319 /* There ought to be a place to keep ELF backend specific flags, but
3320 at the moment there isn't one. We just keep track of the
3321 sections by their name, instead. Fortunately, the ABI gives
3322 suggested names for all the MIPS specific sections, so we will
3323 probably get away with this. */
3324 switch (hdr->sh_type)
3326 case SHT_MIPS_LIBLIST:
3327 if (strcmp (name, ".liblist") != 0)
3331 if (strcmp (name, MIPS_ELF_MSYM_SECTION_NAME (abfd)) != 0)
3334 case SHT_MIPS_CONFLICT:
3335 if (strcmp (name, ".conflict") != 0)
3338 case SHT_MIPS_GPTAB:
3339 if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) != 0)
3342 case SHT_MIPS_UCODE:
3343 if (strcmp (name, ".ucode") != 0)
3346 case SHT_MIPS_DEBUG:
3347 if (strcmp (name, ".mdebug") != 0)
3349 flags = SEC_DEBUGGING;
3351 case SHT_MIPS_REGINFO:
3352 if (strcmp (name, ".reginfo") != 0
3353 || hdr->sh_size != sizeof (Elf32_External_RegInfo))
3355 flags = (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_SIZE);
3357 case SHT_MIPS_IFACE:
3358 if (strcmp (name, ".MIPS.interfaces") != 0)
3361 case SHT_MIPS_CONTENT:
3362 if (strncmp (name, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
3365 case SHT_MIPS_OPTIONS:
3366 if (strcmp (name, MIPS_ELF_OPTIONS_SECTION_NAME (abfd)) != 0)
3369 case SHT_MIPS_DWARF:
3370 if (strncmp (name, ".debug_", sizeof ".debug_" - 1) != 0)
3373 case SHT_MIPS_SYMBOL_LIB:
3374 if (strcmp (name, ".MIPS.symlib") != 0)
3377 case SHT_MIPS_EVENTS:
3378 if (strncmp (name, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
3379 && strncmp (name, ".MIPS.post_rel",
3380 sizeof ".MIPS.post_rel" - 1) != 0)
3387 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
3392 if (! bfd_set_section_flags (abfd, hdr->bfd_section,
3393 (bfd_get_section_flags (abfd,
3399 /* FIXME: We should record sh_info for a .gptab section. */
3401 /* For a .reginfo section, set the gp value in the tdata information
3402 from the contents of this section. We need the gp value while
3403 processing relocs, so we just get it now. The .reginfo section
3404 is not used in the 64-bit MIPS ELF ABI. */
3405 if (hdr->sh_type == SHT_MIPS_REGINFO)
3407 Elf32_External_RegInfo ext;
3410 if (! bfd_get_section_contents (abfd, hdr->bfd_section, (PTR) &ext,
3412 (bfd_size_type) sizeof ext))
3414 bfd_mips_elf32_swap_reginfo_in (abfd, &ext, &s);
3415 elf_gp (abfd) = s.ri_gp_value;
3418 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
3419 set the gp value based on what we find. We may see both
3420 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
3421 they should agree. */
3422 if (hdr->sh_type == SHT_MIPS_OPTIONS)
3424 bfd_byte *contents, *l, *lend;
3426 contents = (bfd_byte *) bfd_malloc (hdr->sh_size);
3427 if (contents == NULL)
3429 if (! bfd_get_section_contents (abfd, hdr->bfd_section, contents,
3430 (file_ptr) 0, hdr->sh_size))
3436 lend = contents + hdr->sh_size;
3437 while (l + sizeof (Elf_External_Options) <= lend)
3439 Elf_Internal_Options intopt;
3441 bfd_mips_elf_swap_options_in (abfd, (Elf_External_Options *) l,
3443 if (ABI_64_P (abfd) && intopt.kind == ODK_REGINFO)
3445 Elf64_Internal_RegInfo intreg;
3447 bfd_mips_elf64_swap_reginfo_in
3449 ((Elf64_External_RegInfo *)
3450 (l + sizeof (Elf_External_Options))),
3452 elf_gp (abfd) = intreg.ri_gp_value;
3454 else if (intopt.kind == ODK_REGINFO)
3456 Elf32_RegInfo intreg;
3458 bfd_mips_elf32_swap_reginfo_in
3460 ((Elf32_External_RegInfo *)
3461 (l + sizeof (Elf_External_Options))),
3463 elf_gp (abfd) = intreg.ri_gp_value;
3473 /* Set the correct type for a MIPS ELF section. We do this by the
3474 section name, which is a hack, but ought to work. This routine is
3475 used by both the 32-bit and the 64-bit ABI. */
3478 _bfd_mips_elf_fake_sections (abfd, hdr, sec)
3480 Elf32_Internal_Shdr *hdr;
3483 register const char *name;
3485 name = bfd_get_section_name (abfd, sec);
3487 if (strcmp (name, ".liblist") == 0)
3489 hdr->sh_type = SHT_MIPS_LIBLIST;
3490 hdr->sh_info = sec->_raw_size / sizeof (Elf32_Lib);
3491 /* The sh_link field is set in final_write_processing. */
3493 else if (strcmp (name, ".conflict") == 0)
3494 hdr->sh_type = SHT_MIPS_CONFLICT;
3495 else if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0)
3497 hdr->sh_type = SHT_MIPS_GPTAB;
3498 hdr->sh_entsize = sizeof (Elf32_External_gptab);
3499 /* The sh_info field is set in final_write_processing. */
3501 else if (strcmp (name, ".ucode") == 0)
3502 hdr->sh_type = SHT_MIPS_UCODE;
3503 else if (strcmp (name, ".mdebug") == 0)
3505 hdr->sh_type = SHT_MIPS_DEBUG;
3506 /* In a shared object on Irix 5.3, the .mdebug section has an
3507 entsize of 0. FIXME: Does this matter? */
3508 if (SGI_COMPAT (abfd) && (abfd->flags & DYNAMIC) != 0)
3509 hdr->sh_entsize = 0;
3511 hdr->sh_entsize = 1;
3513 else if (strcmp (name, ".reginfo") == 0)
3515 hdr->sh_type = SHT_MIPS_REGINFO;
3516 /* In a shared object on Irix 5.3, the .reginfo section has an
3517 entsize of 0x18. FIXME: Does this matter? */
3518 if (SGI_COMPAT (abfd))
3520 if ((abfd->flags & DYNAMIC) != 0)
3521 hdr->sh_entsize = sizeof (Elf32_External_RegInfo);
3523 hdr->sh_entsize = 1;
3526 hdr->sh_entsize = sizeof (Elf32_External_RegInfo);
3528 else if (SGI_COMPAT (abfd)
3529 && (strcmp (name, ".hash") == 0
3530 || strcmp (name, ".dynamic") == 0
3531 || strcmp (name, ".dynstr") == 0))
3533 if (SGI_COMPAT (abfd))
3534 hdr->sh_entsize = 0;
3536 /* This isn't how the Irix 6 linker behaves. */
3537 hdr->sh_info = SIZEOF_MIPS_DYNSYM_SECNAMES;
3540 else if (strcmp (name, ".got") == 0
3541 || strcmp (name, MIPS_ELF_SRDATA_SECTION_NAME (abfd)) == 0
3542 || strcmp (name, ".sdata") == 0
3543 || strcmp (name, ".sbss") == 0
3544 || strcmp (name, ".lit4") == 0
3545 || strcmp (name, ".lit8") == 0)
3546 hdr->sh_flags |= SHF_MIPS_GPREL;
3547 else if (strcmp (name, ".MIPS.interfaces") == 0)
3549 hdr->sh_type = SHT_MIPS_IFACE;
3550 hdr->sh_flags |= SHF_MIPS_NOSTRIP;
3552 else if (strncmp (name, ".MIPS.content", strlen (".MIPS.content")) == 0)
3554 hdr->sh_type = SHT_MIPS_CONTENT;
3555 hdr->sh_flags |= SHF_MIPS_NOSTRIP;
3556 /* The sh_info field is set in final_write_processing. */
3558 else if (strcmp (name, MIPS_ELF_OPTIONS_SECTION_NAME (abfd)) == 0)
3560 hdr->sh_type = SHT_MIPS_OPTIONS;
3561 hdr->sh_entsize = 1;
3562 hdr->sh_flags |= SHF_MIPS_NOSTRIP;
3564 else if (strncmp (name, ".debug_", sizeof ".debug_" - 1) == 0)
3565 hdr->sh_type = SHT_MIPS_DWARF;
3566 else if (strcmp (name, ".MIPS.symlib") == 0)
3568 hdr->sh_type = SHT_MIPS_SYMBOL_LIB;
3569 /* The sh_link and sh_info fields are set in
3570 final_write_processing. */
3572 else if (strncmp (name, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
3573 || strncmp (name, ".MIPS.post_rel",
3574 sizeof ".MIPS.post_rel" - 1) == 0)
3576 hdr->sh_type = SHT_MIPS_EVENTS;
3577 hdr->sh_flags |= SHF_MIPS_NOSTRIP;
3578 /* The sh_link field is set in final_write_processing. */
3580 else if (strcmp (name, MIPS_ELF_MSYM_SECTION_NAME (abfd)) == 0)
3582 hdr->sh_type = SHT_MIPS_MSYM;
3583 hdr->sh_flags |= SHF_ALLOC;
3584 hdr->sh_entsize = 8;
3587 /* The generic elf_fake_sections will set up REL_HDR using the
3588 default kind of relocations. But, we may actually need both
3589 kinds of relocations, so we set up the second header here.
3591 This is not necessary for the O32 ABI since that only uses Elf32_Rel
3592 relocations (cf. System V ABI, MIPS RISC Processor Supplement,
3593 3rd Edition, p. 4-17). It breaks the IRIX 5/6 32-bit ld, since one
3594 of the resulting empty .rela.<section> sections starts with
3595 sh_offset == object size, and ld doesn't allow that. While the check
3596 is arguably bogus for empty or SHT_NOBITS sections, it can easily be
3597 avoided by not emitting those useless sections in the first place. */
3598 if (IRIX_COMPAT (abfd) != ict_irix5 && (sec->flags & SEC_RELOC) != 0)
3600 struct bfd_elf_section_data *esd;
3601 bfd_size_type amt = sizeof (Elf_Internal_Shdr);
3603 esd = elf_section_data (sec);
3604 BFD_ASSERT (esd->rel_hdr2 == NULL);
3605 esd->rel_hdr2 = (Elf_Internal_Shdr *) bfd_zalloc (abfd, amt);
3608 _bfd_elf_init_reloc_shdr (abfd, esd->rel_hdr2, sec,
3609 !elf_section_data (sec)->use_rela_p);
3615 /* Given a BFD section, try to locate the corresponding ELF section
3616 index. This is used by both the 32-bit and the 64-bit ABI.
3617 Actually, it's not clear to me that the 64-bit ABI supports these,
3618 but for non-PIC objects we will certainly want support for at least
3619 the .scommon section. */
3622 _bfd_mips_elf_section_from_bfd_section (abfd, sec, retval)
3623 bfd *abfd ATTRIBUTE_UNUSED;
3627 if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)
3629 *retval = SHN_MIPS_SCOMMON;
3632 if (strcmp (bfd_get_section_name (abfd, sec), ".acommon") == 0)
3634 *retval = SHN_MIPS_ACOMMON;
3640 /* When are writing out the .options or .MIPS.options section,
3641 remember the bytes we are writing out, so that we can install the
3642 GP value in the section_processing routine. */
3645 _bfd_mips_elf_set_section_contents (abfd, section, location, offset, count)
3650 bfd_size_type count;
3652 if (strcmp (section->name, MIPS_ELF_OPTIONS_SECTION_NAME (abfd)) == 0)
3656 if (elf_section_data (section) == NULL)
3658 bfd_size_type amt = sizeof (struct bfd_elf_section_data);
3659 section->used_by_bfd = (PTR) bfd_zalloc (abfd, amt);
3660 if (elf_section_data (section) == NULL)
3663 c = (bfd_byte *) elf_section_data (section)->tdata;
3668 if (section->_cooked_size != 0)
3669 size = section->_cooked_size;
3671 size = section->_raw_size;
3672 c = (bfd_byte *) bfd_zalloc (abfd, size);
3675 elf_section_data (section)->tdata = (PTR) c;
3678 memcpy (c + offset, location, (size_t) count);
3681 return _bfd_elf_set_section_contents (abfd, section, location, offset,
3685 /* Work over a section just before writing it out. This routine is
3686 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
3687 sections that need the SHF_MIPS_GPREL flag by name; there has to be
3691 _bfd_mips_elf_section_processing (abfd, hdr)
3693 Elf_Internal_Shdr *hdr;
3695 if (hdr->sh_type == SHT_MIPS_REGINFO
3696 && hdr->sh_size > 0)
3700 BFD_ASSERT (hdr->sh_size == sizeof (Elf32_External_RegInfo));
3701 BFD_ASSERT (hdr->contents == NULL);
3704 hdr->sh_offset + sizeof (Elf32_External_RegInfo) - 4,
3707 H_PUT_32 (abfd, elf_gp (abfd), buf);
3708 if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
3712 if (hdr->sh_type == SHT_MIPS_OPTIONS
3713 && hdr->bfd_section != NULL
3714 && elf_section_data (hdr->bfd_section) != NULL
3715 && elf_section_data (hdr->bfd_section)->tdata != NULL)
3717 bfd_byte *contents, *l, *lend;
3719 /* We stored the section contents in the elf_section_data tdata
3720 field in the set_section_contents routine. We save the
3721 section contents so that we don't have to read them again.
3722 At this point we know that elf_gp is set, so we can look
3723 through the section contents to see if there is an
3724 ODK_REGINFO structure. */
3726 contents = (bfd_byte *) elf_section_data (hdr->bfd_section)->tdata;
3728 lend = contents + hdr->sh_size;
3729 while (l + sizeof (Elf_External_Options) <= lend)
3731 Elf_Internal_Options intopt;
3733 bfd_mips_elf_swap_options_in (abfd, (Elf_External_Options *) l,
3735 if (ABI_64_P (abfd) && intopt.kind == ODK_REGINFO)
3742 + sizeof (Elf_External_Options)
3743 + (sizeof (Elf64_External_RegInfo) - 8)),
3746 H_PUT_64 (abfd, elf_gp (abfd), buf);
3747 if (bfd_bwrite (buf, (bfd_size_type) 8, abfd) != 8)
3750 else if (intopt.kind == ODK_REGINFO)
3757 + sizeof (Elf_External_Options)
3758 + (sizeof (Elf32_External_RegInfo) - 4)),
3761 H_PUT_32 (abfd, elf_gp (abfd), buf);
3762 if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
3769 if (hdr->bfd_section != NULL)
3771 const char *name = bfd_get_section_name (abfd, hdr->bfd_section);
3773 if (strcmp (name, ".sdata") == 0
3774 || strcmp (name, ".lit8") == 0
3775 || strcmp (name, ".lit4") == 0)
3777 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
3778 hdr->sh_type = SHT_PROGBITS;
3780 else if (strcmp (name, ".sbss") == 0)
3782 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
3783 hdr->sh_type = SHT_NOBITS;
3785 else if (strcmp (name, MIPS_ELF_SRDATA_SECTION_NAME (abfd)) == 0)
3787 hdr->sh_flags |= SHF_ALLOC | SHF_MIPS_GPREL;
3788 hdr->sh_type = SHT_PROGBITS;
3790 else if (strcmp (name, ".compact_rel") == 0)
3793 hdr->sh_type = SHT_PROGBITS;
3795 else if (strcmp (name, ".rtproc") == 0)
3797 if (hdr->sh_addralign != 0 && hdr->sh_entsize == 0)
3799 unsigned int adjust;
3801 adjust = hdr->sh_size % hdr->sh_addralign;
3803 hdr->sh_size += hdr->sh_addralign - adjust;
3811 /* MIPS ELF uses two common sections. One is the usual one, and the
3812 other is for small objects. All the small objects are kept
3813 together, and then referenced via the gp pointer, which yields
3814 faster assembler code. This is what we use for the small common
3815 section. This approach is copied from ecoff.c. */
3816 static asection mips_elf_scom_section;
3817 static asymbol mips_elf_scom_symbol;
3818 static asymbol *mips_elf_scom_symbol_ptr;
3820 /* MIPS ELF also uses an acommon section, which represents an
3821 allocated common symbol which may be overridden by a
3822 definition in a shared library. */
3823 static asection mips_elf_acom_section;
3824 static asymbol mips_elf_acom_symbol;
3825 static asymbol *mips_elf_acom_symbol_ptr;
3827 /* Handle the special MIPS section numbers that a symbol may use.
3828 This is used for both the 32-bit and the 64-bit ABI. */
3831 _bfd_mips_elf_symbol_processing (abfd, asym)
3835 elf_symbol_type *elfsym;
3837 elfsym = (elf_symbol_type *) asym;
3838 switch (elfsym->internal_elf_sym.st_shndx)
3840 case SHN_MIPS_ACOMMON:
3841 /* This section is used in a dynamically linked executable file.
3842 It is an allocated common section. The dynamic linker can
3843 either resolve these symbols to something in a shared
3844 library, or it can just leave them here. For our purposes,
3845 we can consider these symbols to be in a new section. */
3846 if (mips_elf_acom_section.name == NULL)
3848 /* Initialize the acommon section. */
3849 mips_elf_acom_section.name = ".acommon";
3850 mips_elf_acom_section.flags = SEC_ALLOC;
3851 mips_elf_acom_section.output_section = &mips_elf_acom_section;
3852 mips_elf_acom_section.symbol = &mips_elf_acom_symbol;
3853 mips_elf_acom_section.symbol_ptr_ptr = &mips_elf_acom_symbol_ptr;
3854 mips_elf_acom_symbol.name = ".acommon";
3855 mips_elf_acom_symbol.flags = BSF_SECTION_SYM;
3856 mips_elf_acom_symbol.section = &mips_elf_acom_section;
3857 mips_elf_acom_symbol_ptr = &mips_elf_acom_symbol;
3859 asym->section = &mips_elf_acom_section;
3863 /* Common symbols less than the GP size are automatically
3864 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
3865 if (asym->value > elf_gp_size (abfd)
3866 || IRIX_COMPAT (abfd) == ict_irix6)
3869 case SHN_MIPS_SCOMMON:
3870 if (mips_elf_scom_section.name == NULL)
3872 /* Initialize the small common section. */
3873 mips_elf_scom_section.name = ".scommon";
3874 mips_elf_scom_section.flags = SEC_IS_COMMON;
3875 mips_elf_scom_section.output_section = &mips_elf_scom_section;
3876 mips_elf_scom_section.symbol = &mips_elf_scom_symbol;
3877 mips_elf_scom_section.symbol_ptr_ptr = &mips_elf_scom_symbol_ptr;
3878 mips_elf_scom_symbol.name = ".scommon";
3879 mips_elf_scom_symbol.flags = BSF_SECTION_SYM;
3880 mips_elf_scom_symbol.section = &mips_elf_scom_section;
3881 mips_elf_scom_symbol_ptr = &mips_elf_scom_symbol;
3883 asym->section = &mips_elf_scom_section;
3884 asym->value = elfsym->internal_elf_sym.st_size;
3887 case SHN_MIPS_SUNDEFINED:
3888 asym->section = bfd_und_section_ptr;
3891 #if 0 /* for SGI_COMPAT */
3893 asym->section = mips_elf_text_section_ptr;
3897 asym->section = mips_elf_data_section_ptr;
3903 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
3907 _bfd_mips_elf_additional_program_headers (abfd)
3913 /* See if we need a PT_MIPS_REGINFO segment. */
3914 s = bfd_get_section_by_name (abfd, ".reginfo");
3915 if (s && (s->flags & SEC_LOAD))
3918 /* See if we need a PT_MIPS_OPTIONS segment. */
3919 if (IRIX_COMPAT (abfd) == ict_irix6
3920 && bfd_get_section_by_name (abfd,
3921 MIPS_ELF_OPTIONS_SECTION_NAME (abfd)))
3924 /* See if we need a PT_MIPS_RTPROC segment. */
3925 if (IRIX_COMPAT (abfd) == ict_irix5
3926 && bfd_get_section_by_name (abfd, ".dynamic")
3927 && bfd_get_section_by_name (abfd, ".mdebug"))
3933 /* Modify the segment map for an Irix 5 executable. */
3936 _bfd_mips_elf_modify_segment_map (abfd)
3940 struct elf_segment_map *m, **pm;
3943 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
3945 s = bfd_get_section_by_name (abfd, ".reginfo");
3946 if (s != NULL && (s->flags & SEC_LOAD) != 0)
3948 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
3949 if (m->p_type == PT_MIPS_REGINFO)
3954 m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
3958 m->p_type = PT_MIPS_REGINFO;
3962 /* We want to put it after the PHDR and INTERP segments. */
3963 pm = &elf_tdata (abfd)->segment_map;
3965 && ((*pm)->p_type == PT_PHDR
3966 || (*pm)->p_type == PT_INTERP))
3974 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
3975 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
3976 PT_OPTIONS segement immediately following the program header
3978 if (IRIX_COMPAT (abfd) == ict_irix6)
3980 for (s = abfd->sections; s; s = s->next)
3981 if (elf_section_data (s)->this_hdr.sh_type == SHT_MIPS_OPTIONS)
3986 struct elf_segment_map *options_segment;
3988 /* Usually, there's a program header table. But, sometimes
3989 there's not (like when running the `ld' testsuite). So,
3990 if there's no program header table, we just put the
3991 options segement at the end. */
3992 for (pm = &elf_tdata (abfd)->segment_map;
3995 if ((*pm)->p_type == PT_PHDR)
3998 amt = sizeof (struct elf_segment_map);
3999 options_segment = bfd_zalloc (abfd, amt);
4000 options_segment->next = *pm;
4001 options_segment->p_type = PT_MIPS_OPTIONS;
4002 options_segment->p_flags = PF_R;
4003 options_segment->p_flags_valid = true;
4004 options_segment->count = 1;
4005 options_segment->sections[0] = s;
4006 *pm = options_segment;
4011 if (IRIX_COMPAT (abfd) == ict_irix5)
4013 /* If there are .dynamic and .mdebug sections, we make a room
4014 for the RTPROC header. FIXME: Rewrite without section names. */
4015 if (bfd_get_section_by_name (abfd, ".interp") == NULL
4016 && bfd_get_section_by_name (abfd, ".dynamic") != NULL
4017 && bfd_get_section_by_name (abfd, ".mdebug") != NULL)
4019 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
4020 if (m->p_type == PT_MIPS_RTPROC)
4025 m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
4029 m->p_type = PT_MIPS_RTPROC;
4031 s = bfd_get_section_by_name (abfd, ".rtproc");
4036 m->p_flags_valid = 1;
4044 /* We want to put it after the DYNAMIC segment. */
4045 pm = &elf_tdata (abfd)->segment_map;
4046 while (*pm != NULL && (*pm)->p_type != PT_DYNAMIC)
4056 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic,
4057 .dynstr, .dynsym, and .hash sections, and everything in
4059 for (pm = &elf_tdata (abfd)->segment_map; *pm != NULL;
4061 if ((*pm)->p_type == PT_DYNAMIC)
4064 if (m != NULL && IRIX_COMPAT (abfd) == ict_none)
4066 /* For a normal mips executable the permissions for the PT_DYNAMIC
4067 segment are read, write and execute. We do that here since
4068 the code in elf.c sets only the read permission. This matters
4069 sometimes for the dynamic linker. */
4070 if (bfd_get_section_by_name (abfd, ".dynamic") != NULL)
4072 m->p_flags = PF_R | PF_W | PF_X;
4073 m->p_flags_valid = 1;
4077 && m->count == 1 && strcmp (m->sections[0]->name, ".dynamic") == 0)
4079 static const char *sec_names[] =
4081 ".dynamic", ".dynstr", ".dynsym", ".hash"
4085 struct elf_segment_map *n;
4089 for (i = 0; i < sizeof sec_names / sizeof sec_names[0]; i++)
4091 s = bfd_get_section_by_name (abfd, sec_names[i]);
4092 if (s != NULL && (s->flags & SEC_LOAD) != 0)
4098 sz = s->_cooked_size;
4101 if (high < s->vma + sz)
4107 for (s = abfd->sections; s != NULL; s = s->next)
4108 if ((s->flags & SEC_LOAD) != 0
4111 + (s->_cooked_size !=
4112 0 ? s->_cooked_size : s->_raw_size)) <= high))
4115 amt = sizeof *n + (bfd_size_type) (c - 1) * sizeof (asection *);
4116 n = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
4123 for (s = abfd->sections; s != NULL; s = s->next)
4125 if ((s->flags & SEC_LOAD) != 0
4128 + (s->_cooked_size != 0 ?
4129 s->_cooked_size : s->_raw_size)) <= high))
4143 /* The structure of the runtime procedure descriptor created by the
4144 loader for use by the static exception system. */
4146 typedef struct runtime_pdr {
4147 bfd_vma adr; /* memory address of start of procedure */
4148 long regmask; /* save register mask */
4149 long regoffset; /* save register offset */
4150 long fregmask; /* save floating point register mask */
4151 long fregoffset; /* save floating point register offset */
4152 long frameoffset; /* frame size */
4153 short framereg; /* frame pointer register */
4154 short pcreg; /* offset or reg of return pc */
4155 long irpss; /* index into the runtime string table */
4157 struct exception_info *exception_info;/* pointer to exception array */
4159 #define cbRPDR sizeof (RPDR)
4160 #define rpdNil ((pRPDR) 0)
4162 /* Swap RPDR (runtime procedure table entry) for output. */
4164 static void ecoff_swap_rpdr_out
4165 PARAMS ((bfd *, const RPDR *, struct rpdr_ext *));
4168 ecoff_swap_rpdr_out (abfd, in, ex)
4171 struct rpdr_ext *ex;
4173 /* ECOFF_PUT_OFF was defined in ecoffswap.h. */
4174 ECOFF_PUT_OFF (abfd, in->adr, ex->p_adr);
4175 H_PUT_32 (abfd, in->regmask, ex->p_regmask);
4176 H_PUT_32 (abfd, in->regoffset, ex->p_regoffset);
4177 H_PUT_32 (abfd, in->fregmask, ex->p_fregmask);
4178 H_PUT_32 (abfd, in->fregoffset, ex->p_fregoffset);
4179 H_PUT_32 (abfd, in->frameoffset, ex->p_frameoffset);
4181 H_PUT_16 (abfd, in->framereg, ex->p_framereg);
4182 H_PUT_16 (abfd, in->pcreg, ex->p_pcreg);
4184 H_PUT_32 (abfd, in->irpss, ex->p_irpss);
4186 ECOFF_PUT_OFF (abfd, in->exception_info, ex->p_exception_info);
4190 /* Read ECOFF debugging information from a .mdebug section into a
4191 ecoff_debug_info structure. */
4194 _bfd_mips_elf_read_ecoff_info (abfd, section, debug)
4197 struct ecoff_debug_info *debug;
4200 const struct ecoff_debug_swap *swap;
4201 char *ext_hdr = NULL;
4203 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
4204 memset (debug, 0, sizeof (*debug));
4206 ext_hdr = (char *) bfd_malloc (swap->external_hdr_size);
4207 if (ext_hdr == NULL && swap->external_hdr_size != 0)
4210 if (bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0,
4211 swap->external_hdr_size)
4215 symhdr = &debug->symbolic_header;
4216 (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr);
4218 /* The symbolic header contains absolute file offsets and sizes to
4220 #define READ(ptr, offset, count, size, type) \
4221 if (symhdr->count == 0) \
4222 debug->ptr = NULL; \
4225 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
4226 debug->ptr = (type) bfd_malloc (amt); \
4227 if (debug->ptr == NULL) \
4228 goto error_return; \
4229 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
4230 || bfd_bread (debug->ptr, amt, abfd) != amt) \
4231 goto error_return; \
4234 READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *);
4235 READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR);
4236 READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR);
4237 READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR);
4238 READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR);
4239 READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext),
4241 READ (ss, cbSsOffset, issMax, sizeof (char), char *);
4242 READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *);
4243 READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR);
4244 READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR);
4245 READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR);
4249 debug->adjust = NULL;
4254 if (ext_hdr != NULL)
4256 if (debug->line != NULL)
4258 if (debug->external_dnr != NULL)
4259 free (debug->external_dnr);
4260 if (debug->external_pdr != NULL)
4261 free (debug->external_pdr);
4262 if (debug->external_sym != NULL)
4263 free (debug->external_sym);
4264 if (debug->external_opt != NULL)
4265 free (debug->external_opt);
4266 if (debug->external_aux != NULL)
4267 free (debug->external_aux);
4268 if (debug->ss != NULL)
4270 if (debug->ssext != NULL)
4271 free (debug->ssext);
4272 if (debug->external_fdr != NULL)
4273 free (debug->external_fdr);
4274 if (debug->external_rfd != NULL)
4275 free (debug->external_rfd);
4276 if (debug->external_ext != NULL)
4277 free (debug->external_ext);
4281 /* MIPS ELF local labels start with '$', not 'L'. */
4284 mips_elf_is_local_label_name (abfd, name)
4291 /* On Irix 6, the labels go back to starting with '.', so we accept
4292 the generic ELF local label syntax as well. */
4293 return _bfd_elf_is_local_label_name (abfd, name);
4296 /* MIPS ELF uses a special find_nearest_line routine in order the
4297 handle the ECOFF debugging information. */
4299 struct mips_elf_find_line
4301 struct ecoff_debug_info d;
4302 struct ecoff_find_line i;
4306 _bfd_mips_elf_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
4307 functionname_ptr, line_ptr)
4312 const char **filename_ptr;
4313 const char **functionname_ptr;
4314 unsigned int *line_ptr;
4318 if (_bfd_dwarf1_find_nearest_line (abfd, section, symbols, offset,
4319 filename_ptr, functionname_ptr,
4323 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
4324 filename_ptr, functionname_ptr,
4326 (unsigned) (ABI_64_P (abfd) ? 8 : 0),
4327 &elf_tdata (abfd)->dwarf2_find_line_info))
4330 msec = bfd_get_section_by_name (abfd, ".mdebug");
4334 struct mips_elf_find_line *fi;
4335 const struct ecoff_debug_swap * const swap =
4336 get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
4338 /* If we are called during a link, mips_elf_final_link may have
4339 cleared the SEC_HAS_CONTENTS field. We force it back on here
4340 if appropriate (which it normally will be). */
4341 origflags = msec->flags;
4342 if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS)
4343 msec->flags |= SEC_HAS_CONTENTS;
4345 fi = elf_tdata (abfd)->find_line_info;
4348 bfd_size_type external_fdr_size;
4351 struct fdr *fdr_ptr;
4352 bfd_size_type amt = sizeof (struct mips_elf_find_line);
4354 fi = (struct mips_elf_find_line *) bfd_zalloc (abfd, amt);
4357 msec->flags = origflags;
4361 if (! _bfd_mips_elf_read_ecoff_info (abfd, msec, &fi->d))
4363 msec->flags = origflags;
4367 /* Swap in the FDR information. */
4368 amt = fi->d.symbolic_header.ifdMax * sizeof (struct fdr);
4369 fi->d.fdr = (struct fdr *) bfd_alloc (abfd, amt);
4370 if (fi->d.fdr == NULL)
4372 msec->flags = origflags;
4375 external_fdr_size = swap->external_fdr_size;
4376 fdr_ptr = fi->d.fdr;
4377 fraw_src = (char *) fi->d.external_fdr;
4378 fraw_end = (fraw_src
4379 + fi->d.symbolic_header.ifdMax * external_fdr_size);
4380 for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
4381 (*swap->swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr);
4383 elf_tdata (abfd)->find_line_info = fi;
4385 /* Note that we don't bother to ever free this information.
4386 find_nearest_line is either called all the time, as in
4387 objdump -l, so the information should be saved, or it is
4388 rarely called, as in ld error messages, so the memory
4389 wasted is unimportant. Still, it would probably be a
4390 good idea for free_cached_info to throw it away. */
4393 if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap,
4394 &fi->i, filename_ptr, functionname_ptr,
4397 msec->flags = origflags;
4401 msec->flags = origflags;
4404 /* Fall back on the generic ELF find_nearest_line routine. */
4406 return _bfd_elf_find_nearest_line (abfd, section, symbols, offset,
4407 filename_ptr, functionname_ptr,
4411 /* The mips16 compiler uses a couple of special sections to handle
4412 floating point arguments.
4414 Section names that look like .mips16.fn.FNNAME contain stubs that
4415 copy floating point arguments from the fp regs to the gp regs and
4416 then jump to FNNAME. If any 32 bit function calls FNNAME, the
4417 call should be redirected to the stub instead. If no 32 bit
4418 function calls FNNAME, the stub should be discarded. We need to
4419 consider any reference to the function, not just a call, because
4420 if the address of the function is taken we will need the stub,
4421 since the address might be passed to a 32 bit function.
4423 Section names that look like .mips16.call.FNNAME contain stubs
4424 that copy floating point arguments from the gp regs to the fp
4425 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
4426 then any 16 bit function that calls FNNAME should be redirected
4427 to the stub instead. If FNNAME is not a 32 bit function, the
4428 stub should be discarded.
4430 .mips16.call.fp.FNNAME sections are similar, but contain stubs
4431 which call FNNAME and then copy the return value from the fp regs
4432 to the gp regs. These stubs store the return value in $18 while
4433 calling FNNAME; any function which might call one of these stubs
4434 must arrange to save $18 around the call. (This case is not
4435 needed for 32 bit functions that call 16 bit functions, because
4436 16 bit functions always return floating point values in both
4439 Note that in all cases FNNAME might be defined statically.
4440 Therefore, FNNAME is not used literally. Instead, the relocation
4441 information will indicate which symbol the section is for.
4443 We record any stubs that we find in the symbol table. */
4445 #define FN_STUB ".mips16.fn."
4446 #define CALL_STUB ".mips16.call."
4447 #define CALL_FP_STUB ".mips16.call.fp."
4449 /* MIPS ELF linker hash table. */
4451 struct mips_elf_link_hash_table
4453 struct elf_link_hash_table root;
4455 /* We no longer use this. */
4456 /* String section indices for the dynamic section symbols. */
4457 bfd_size_type dynsym_sec_strindex[SIZEOF_MIPS_DYNSYM_SECNAMES];
4459 /* The number of .rtproc entries. */
4460 bfd_size_type procedure_count;
4461 /* The size of the .compact_rel section (if SGI_COMPAT). */
4462 bfd_size_type compact_rel_size;
4463 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
4464 entry is set to the address of __rld_obj_head as in Irix 5. */
4465 boolean use_rld_obj_head;
4466 /* This is the value of the __rld_map or __rld_obj_head symbol. */
4468 /* This is set if we see any mips16 stub sections. */
4469 boolean mips16_stubs_seen;
4472 /* Look up an entry in a MIPS ELF linker hash table. */
4474 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
4475 ((struct mips_elf_link_hash_entry *) \
4476 elf_link_hash_lookup (&(table)->root, (string), (create), \
4479 /* Traverse a MIPS ELF linker hash table. */
4481 #define mips_elf_link_hash_traverse(table, func, info) \
4482 (elf_link_hash_traverse \
4484 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
4487 /* Get the MIPS ELF linker hash table from a link_info structure. */
4489 #define mips_elf_hash_table(p) \
4490 ((struct mips_elf_link_hash_table *) ((p)->hash))
4492 static boolean mips_elf_output_extsym
4493 PARAMS ((struct mips_elf_link_hash_entry *, PTR));
4495 /* Create an entry in a MIPS ELF linker hash table. */
4497 static struct bfd_hash_entry *
4498 mips_elf_link_hash_newfunc (entry, table, string)
4499 struct bfd_hash_entry *entry;
4500 struct bfd_hash_table *table;
4503 struct mips_elf_link_hash_entry *ret =
4504 (struct mips_elf_link_hash_entry *) entry;
4506 /* Allocate the structure if it has not already been allocated by a
4508 if (ret == (struct mips_elf_link_hash_entry *) NULL)
4509 ret = ((struct mips_elf_link_hash_entry *)
4510 bfd_hash_allocate (table,
4511 sizeof (struct mips_elf_link_hash_entry)));
4512 if (ret == (struct mips_elf_link_hash_entry *) NULL)
4513 return (struct bfd_hash_entry *) ret;
4515 /* Call the allocation method of the superclass. */
4516 ret = ((struct mips_elf_link_hash_entry *)
4517 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
4519 if (ret != (struct mips_elf_link_hash_entry *) NULL)
4521 /* Set local fields. */
4522 memset (&ret->esym, 0, sizeof (EXTR));
4523 /* We use -2 as a marker to indicate that the information has
4524 not been set. -1 means there is no associated ifd. */
4526 ret->possibly_dynamic_relocs = 0;
4527 ret->readonly_reloc = false;
4528 ret->min_dyn_reloc_index = 0;
4529 ret->no_fn_stub = false;
4530 ret->fn_stub = NULL;
4531 ret->need_fn_stub = false;
4532 ret->call_stub = NULL;
4533 ret->call_fp_stub = NULL;
4534 ret->forced_local = false;
4537 return (struct bfd_hash_entry *) ret;
4541 _bfd_mips_elf_hide_symbol (info, entry, force_local)
4542 struct bfd_link_info *info;
4543 struct elf_link_hash_entry *entry;
4544 boolean force_local;
4548 struct mips_got_info *g;
4549 struct mips_elf_link_hash_entry *h;
4551 h = (struct mips_elf_link_hash_entry *) entry;
4552 if (h->forced_local)
4554 h->forced_local = true;
4556 dynobj = elf_hash_table (info)->dynobj;
4557 got = bfd_get_section_by_name (dynobj, ".got");
4558 g = (struct mips_got_info *) elf_section_data (got)->tdata;
4560 _bfd_elf_link_hash_hide_symbol (info, &h->root, force_local);
4562 /* FIXME: Do we allocate too much GOT space here? */
4564 got->_raw_size += MIPS_ELF_GOT_SIZE (dynobj);
4567 /* Create a MIPS ELF linker hash table. */
4569 struct bfd_link_hash_table *
4570 _bfd_mips_elf_link_hash_table_create (abfd)
4573 struct mips_elf_link_hash_table *ret;
4574 bfd_size_type amt = sizeof (struct mips_elf_link_hash_table);
4576 ret = (struct mips_elf_link_hash_table *) bfd_alloc (abfd, amt);
4577 if (ret == (struct mips_elf_link_hash_table *) NULL)
4580 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
4581 mips_elf_link_hash_newfunc))
4583 bfd_release (abfd, ret);
4588 /* We no longer use this. */
4589 for (i = 0; i < SIZEOF_MIPS_DYNSYM_SECNAMES; i++)
4590 ret->dynsym_sec_strindex[i] = (bfd_size_type) -1;
4592 ret->procedure_count = 0;
4593 ret->compact_rel_size = 0;
4594 ret->use_rld_obj_head = false;
4596 ret->mips16_stubs_seen = false;
4598 return &ret->root.root;
4601 /* Hook called by the linker routine which adds symbols from an object
4602 file. We must handle the special MIPS section numbers here. */
4605 _bfd_mips_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
4607 struct bfd_link_info *info;
4608 const Elf_Internal_Sym *sym;
4610 flagword *flagsp ATTRIBUTE_UNUSED;
4614 if (SGI_COMPAT (abfd)
4615 && (abfd->flags & DYNAMIC) != 0
4616 && strcmp (*namep, "_rld_new_interface") == 0)
4618 /* Skip Irix 5 rld entry name. */
4623 switch (sym->st_shndx)
4626 /* Common symbols less than the GP size are automatically
4627 treated as SHN_MIPS_SCOMMON symbols. */
4628 if (sym->st_size > elf_gp_size (abfd)
4629 || IRIX_COMPAT (abfd) == ict_irix6)
4632 case SHN_MIPS_SCOMMON:
4633 *secp = bfd_make_section_old_way (abfd, ".scommon");
4634 (*secp)->flags |= SEC_IS_COMMON;
4635 *valp = sym->st_size;
4639 /* This section is used in a shared object. */
4640 if (elf_tdata (abfd)->elf_text_section == NULL)
4642 asymbol *elf_text_symbol;
4643 asection *elf_text_section;
4644 bfd_size_type amt = sizeof (asection);
4646 elf_text_section = bfd_zalloc (abfd, amt);
4647 if (elf_text_section == NULL)
4650 amt = sizeof (asymbol);
4651 elf_text_symbol = bfd_zalloc (abfd, amt);
4652 if (elf_text_symbol == NULL)
4655 /* Initialize the section. */
4657 elf_tdata (abfd)->elf_text_section = elf_text_section;
4658 elf_tdata (abfd)->elf_text_symbol = elf_text_symbol;
4660 elf_text_section->symbol = elf_text_symbol;
4661 elf_text_section->symbol_ptr_ptr = &elf_tdata (abfd)->elf_text_symbol;
4663 elf_text_section->name = ".text";
4664 elf_text_section->flags = SEC_NO_FLAGS;
4665 elf_text_section->output_section = NULL;
4666 elf_text_section->owner = abfd;
4667 elf_text_symbol->name = ".text";
4668 elf_text_symbol->flags = BSF_SECTION_SYM | BSF_DYNAMIC;
4669 elf_text_symbol->section = elf_text_section;
4671 /* This code used to do *secp = bfd_und_section_ptr if
4672 info->shared. I don't know why, and that doesn't make sense,
4673 so I took it out. */
4674 *secp = elf_tdata (abfd)->elf_text_section;
4677 case SHN_MIPS_ACOMMON:
4678 /* Fall through. XXX Can we treat this as allocated data? */
4680 /* This section is used in a shared object. */
4681 if (elf_tdata (abfd)->elf_data_section == NULL)
4683 asymbol *elf_data_symbol;
4684 asection *elf_data_section;
4685 bfd_size_type amt = sizeof (asection);
4687 elf_data_section = bfd_zalloc (abfd, amt);
4688 if (elf_data_section == NULL)
4691 amt = sizeof (asymbol);
4692 elf_data_symbol = bfd_zalloc (abfd, amt);
4693 if (elf_data_symbol == NULL)
4696 /* Initialize the section. */
4698 elf_tdata (abfd)->elf_data_section = elf_data_section;
4699 elf_tdata (abfd)->elf_data_symbol = elf_data_symbol;
4701 elf_data_section->symbol = elf_data_symbol;
4702 elf_data_section->symbol_ptr_ptr = &elf_tdata (abfd)->elf_data_symbol;
4704 elf_data_section->name = ".data";
4705 elf_data_section->flags = SEC_NO_FLAGS;
4706 elf_data_section->output_section = NULL;
4707 elf_data_section->owner = abfd;
4708 elf_data_symbol->name = ".data";
4709 elf_data_symbol->flags = BSF_SECTION_SYM | BSF_DYNAMIC;
4710 elf_data_symbol->section = elf_data_section;
4712 /* This code used to do *secp = bfd_und_section_ptr if
4713 info->shared. I don't know why, and that doesn't make sense,
4714 so I took it out. */
4715 *secp = elf_tdata (abfd)->elf_data_section;
4718 case SHN_MIPS_SUNDEFINED:
4719 *secp = bfd_und_section_ptr;
4723 if (SGI_COMPAT (abfd)
4725 && info->hash->creator == abfd->xvec
4726 && strcmp (*namep, "__rld_obj_head") == 0)
4728 struct elf_link_hash_entry *h;
4730 /* Mark __rld_obj_head as dynamic. */
4732 if (! (_bfd_generic_link_add_one_symbol
4733 (info, abfd, *namep, BSF_GLOBAL, *secp,
4734 (bfd_vma) *valp, (const char *) NULL, false,
4735 get_elf_backend_data (abfd)->collect,
4736 (struct bfd_link_hash_entry **) &h)))
4738 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
4739 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
4740 h->type = STT_OBJECT;
4742 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
4745 mips_elf_hash_table (info)->use_rld_obj_head = true;
4748 /* If this is a mips16 text symbol, add 1 to the value to make it
4749 odd. This will cause something like .word SYM to come up with
4750 the right value when it is loaded into the PC. */
4751 if (sym->st_other == STO_MIPS16)
4757 /* Structure used to pass information to mips_elf_output_extsym. */
4762 struct bfd_link_info *info;
4763 struct ecoff_debug_info *debug;
4764 const struct ecoff_debug_swap *swap;
4768 /* This routine is used to write out ECOFF debugging external symbol
4769 information. It is called via mips_elf_link_hash_traverse. The
4770 ECOFF external symbol information must match the ELF external
4771 symbol information. Unfortunately, at this point we don't know
4772 whether a symbol is required by reloc information, so the two
4773 tables may wind up being different. We must sort out the external
4774 symbol information before we can set the final size of the .mdebug
4775 section, and we must set the size of the .mdebug section before we
4776 can relocate any sections, and we can't know which symbols are
4777 required by relocation until we relocate the sections.
4778 Fortunately, it is relatively unlikely that any symbol will be
4779 stripped but required by a reloc. In particular, it can not happen
4780 when generating a final executable. */
4783 mips_elf_output_extsym (h, data)
4784 struct mips_elf_link_hash_entry *h;
4787 struct extsym_info *einfo = (struct extsym_info *) data;
4789 asection *sec, *output_section;
4791 if (h->root.root.type == bfd_link_hash_warning)
4792 h = (struct mips_elf_link_hash_entry *) h->root.root.u.i.link;
4794 if (h->root.indx == -2)
4796 else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
4797 || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)
4798 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
4799 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
4801 else if (einfo->info->strip == strip_all
4802 || (einfo->info->strip == strip_some
4803 && bfd_hash_lookup (einfo->info->keep_hash,
4804 h->root.root.root.string,
4805 false, false) == NULL))
4813 if (h->esym.ifd == -2)
4816 h->esym.cobol_main = 0;
4817 h->esym.weakext = 0;
4818 h->esym.reserved = 0;
4819 h->esym.ifd = ifdNil;
4820 h->esym.asym.value = 0;
4821 h->esym.asym.st = stGlobal;
4823 if (h->root.root.type == bfd_link_hash_undefined
4824 || h->root.root.type == bfd_link_hash_undefweak)
4828 /* Use undefined class. Also, set class and type for some
4830 name = h->root.root.root.string;
4831 if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0
4832 || strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0)
4834 h->esym.asym.sc = scData;
4835 h->esym.asym.st = stLabel;
4836 h->esym.asym.value = 0;
4838 else if (strcmp (name, mips_elf_dynsym_rtproc_names[2]) == 0)
4840 h->esym.asym.sc = scAbs;
4841 h->esym.asym.st = stLabel;
4842 h->esym.asym.value =
4843 mips_elf_hash_table (einfo->info)->procedure_count;
4845 else if (strcmp (name, "_gp_disp") == 0)
4847 h->esym.asym.sc = scAbs;
4848 h->esym.asym.st = stLabel;
4849 h->esym.asym.value = elf_gp (einfo->abfd);
4852 h->esym.asym.sc = scUndefined;
4854 else if (h->root.root.type != bfd_link_hash_defined
4855 && h->root.root.type != bfd_link_hash_defweak)
4856 h->esym.asym.sc = scAbs;
4861 sec = h->root.root.u.def.section;
4862 output_section = sec->output_section;
4864 /* When making a shared library and symbol h is the one from
4865 the another shared library, OUTPUT_SECTION may be null. */
4866 if (output_section == NULL)
4867 h->esym.asym.sc = scUndefined;
4870 name = bfd_section_name (output_section->owner, output_section);
4872 if (strcmp (name, ".text") == 0)
4873 h->esym.asym.sc = scText;
4874 else if (strcmp (name, ".data") == 0)
4875 h->esym.asym.sc = scData;
4876 else if (strcmp (name, ".sdata") == 0)
4877 h->esym.asym.sc = scSData;
4878 else if (strcmp (name, ".rodata") == 0
4879 || strcmp (name, ".rdata") == 0)
4880 h->esym.asym.sc = scRData;
4881 else if (strcmp (name, ".bss") == 0)
4882 h->esym.asym.sc = scBss;
4883 else if (strcmp (name, ".sbss") == 0)
4884 h->esym.asym.sc = scSBss;
4885 else if (strcmp (name, ".init") == 0)
4886 h->esym.asym.sc = scInit;
4887 else if (strcmp (name, ".fini") == 0)
4888 h->esym.asym.sc = scFini;
4890 h->esym.asym.sc = scAbs;
4894 h->esym.asym.reserved = 0;
4895 h->esym.asym.index = indexNil;
4898 if (h->root.root.type == bfd_link_hash_common)
4899 h->esym.asym.value = h->root.root.u.c.size;
4900 else if (h->root.root.type == bfd_link_hash_defined
4901 || h->root.root.type == bfd_link_hash_defweak)
4903 if (h->esym.asym.sc == scCommon)
4904 h->esym.asym.sc = scBss;
4905 else if (h->esym.asym.sc == scSCommon)
4906 h->esym.asym.sc = scSBss;
4908 sec = h->root.root.u.def.section;
4909 output_section = sec->output_section;
4910 if (output_section != NULL)
4911 h->esym.asym.value = (h->root.root.u.def.value
4912 + sec->output_offset
4913 + output_section->vma);
4915 h->esym.asym.value = 0;
4917 else if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
4919 struct mips_elf_link_hash_entry *hd = h;
4920 boolean no_fn_stub = h->no_fn_stub;
4922 while (hd->root.root.type == bfd_link_hash_indirect)
4924 hd = (struct mips_elf_link_hash_entry *)h->root.root.u.i.link;
4925 no_fn_stub = no_fn_stub || hd->no_fn_stub;
4930 /* Set type and value for a symbol with a function stub. */
4931 h->esym.asym.st = stProc;
4932 sec = hd->root.root.u.def.section;
4934 h->esym.asym.value = 0;
4937 output_section = sec->output_section;
4938 if (output_section != NULL)
4939 h->esym.asym.value = (hd->root.plt.offset
4940 + sec->output_offset
4941 + output_section->vma);
4943 h->esym.asym.value = 0;
4951 if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap,
4952 h->root.root.root.string,
4955 einfo->failed = true;
4962 /* Create a runtime procedure table from the .mdebug section. */
4965 mips_elf_create_procedure_table (handle, abfd, info, s, debug)
4968 struct bfd_link_info *info;
4970 struct ecoff_debug_info *debug;
4972 const struct ecoff_debug_swap *swap;
4973 HDRR *hdr = &debug->symbolic_header;
4975 struct rpdr_ext *erp;
4977 struct pdr_ext *epdr;
4978 struct sym_ext *esym;
4982 bfd_size_type count;
4983 unsigned long sindex;
4987 const char *no_name_func = _("static procedure (no name)");
4995 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
4997 sindex = strlen (no_name_func) + 1;
4998 count = hdr->ipdMax;
5001 size = swap->external_pdr_size;
5003 epdr = (struct pdr_ext *) bfd_malloc (size * count);
5007 if (! _bfd_ecoff_get_accumulated_pdr (handle, (PTR) epdr))
5010 size = sizeof (RPDR);
5011 rp = rpdr = (RPDR *) bfd_malloc (size * count);
5015 size = sizeof (char *);
5016 sv = (char **) bfd_malloc (size * count);
5020 count = hdr->isymMax;
5021 size = swap->external_sym_size;
5022 esym = (struct sym_ext *) bfd_malloc (size * count);
5026 if (! _bfd_ecoff_get_accumulated_sym (handle, (PTR) esym))
5029 count = hdr->issMax;
5030 ss = (char *) bfd_malloc (count);
5033 if (! _bfd_ecoff_get_accumulated_ss (handle, (PTR) ss))
5036 count = hdr->ipdMax;
5037 for (i = 0; i < (unsigned long) count; i++, rp++)
5039 (*swap->swap_pdr_in) (abfd, (PTR) (epdr + i), &pdr);
5040 (*swap->swap_sym_in) (abfd, (PTR) &esym[pdr.isym], &sym);
5041 rp->adr = sym.value;
5042 rp->regmask = pdr.regmask;
5043 rp->regoffset = pdr.regoffset;
5044 rp->fregmask = pdr.fregmask;
5045 rp->fregoffset = pdr.fregoffset;
5046 rp->frameoffset = pdr.frameoffset;
5047 rp->framereg = pdr.framereg;
5048 rp->pcreg = pdr.pcreg;
5050 sv[i] = ss + sym.iss;
5051 sindex += strlen (sv[i]) + 1;
5055 size = sizeof (struct rpdr_ext) * (count + 2) + sindex;
5056 size = BFD_ALIGN (size, 16);
5057 rtproc = (PTR) bfd_alloc (abfd, size);
5060 mips_elf_hash_table (info)->procedure_count = 0;
5064 mips_elf_hash_table (info)->procedure_count = count + 2;
5066 erp = (struct rpdr_ext *) rtproc;
5067 memset (erp, 0, sizeof (struct rpdr_ext));
5069 str = (char *) rtproc + sizeof (struct rpdr_ext) * (count + 2);
5070 strcpy (str, no_name_func);
5071 str += strlen (no_name_func) + 1;
5072 for (i = 0; i < count; i++)
5074 ecoff_swap_rpdr_out (abfd, rpdr + i, erp + i);
5075 strcpy (str, sv[i]);
5076 str += strlen (sv[i]) + 1;
5078 ECOFF_PUT_OFF (abfd, -1, (erp + count)->p_adr);
5080 /* Set the size and contents of .rtproc section. */
5081 s->_raw_size = size;
5082 s->contents = (bfd_byte *) rtproc;
5084 /* Skip this section later on (I don't think this currently
5085 matters, but someday it might). */
5086 s->link_order_head = (struct bfd_link_order *) NULL;
5115 /* A comparison routine used to sort .gptab entries. */
5118 gptab_compare (p1, p2)
5122 const Elf32_gptab *a1 = (const Elf32_gptab *) p1;
5123 const Elf32_gptab *a2 = (const Elf32_gptab *) p2;
5125 return a1->gt_entry.gt_g_value - a2->gt_entry.gt_g_value;
5128 /* We need to use a special link routine to handle the .reginfo and
5129 the .mdebug sections. We need to merge all instances of these
5130 sections together, not write them all out sequentially. */
5133 _bfd_mips_elf_final_link (abfd, info)
5135 struct bfd_link_info *info;
5139 struct bfd_link_order *p;
5140 asection *reginfo_sec, *mdebug_sec, *gptab_data_sec, *gptab_bss_sec;
5141 asection *rtproc_sec;
5142 Elf32_RegInfo reginfo;
5143 struct ecoff_debug_info debug;
5144 const struct ecoff_debug_swap *swap
5145 = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
5146 HDRR *symhdr = &debug.symbolic_header;
5147 PTR mdebug_handle = NULL;
5153 static const char * const secname[] =
5155 ".text", ".init", ".fini", ".data",
5156 ".rodata", ".sdata", ".sbss", ".bss"
5158 static const int sc[] =
5160 scText, scInit, scFini, scData,
5161 scRData, scSData, scSBss, scBss
5164 /* If all the things we linked together were PIC, but we're
5165 producing an executable (rather than a shared object), then the
5166 resulting file is CPIC (i.e., it calls PIC code.) */
5168 && !info->relocateable
5169 && elf_elfheader (abfd)->e_flags & EF_MIPS_PIC)
5171 elf_elfheader (abfd)->e_flags &= ~EF_MIPS_PIC;
5172 elf_elfheader (abfd)->e_flags |= EF_MIPS_CPIC;
5175 /* We'd carefully arranged the dynamic symbol indices, and then the
5176 generic size_dynamic_sections renumbered them out from under us.
5177 Rather than trying somehow to prevent the renumbering, just do
5179 if (elf_hash_table (info)->dynamic_sections_created)
5183 struct mips_got_info *g;
5185 /* When we resort, we must tell mips_elf_sort_hash_table what
5186 the lowest index it may use is. That's the number of section
5187 symbols we're going to add. The generic ELF linker only
5188 adds these symbols when building a shared object. Note that
5189 we count the sections after (possibly) removing the .options
5191 if (!mips_elf_sort_hash_table (info, (info->shared
5192 ? bfd_count_sections (abfd) + 1
5196 /* Make sure we didn't grow the global .got region. */
5197 dynobj = elf_hash_table (info)->dynobj;
5198 got = bfd_get_section_by_name (dynobj, ".got");
5199 g = (struct mips_got_info *) elf_section_data (got)->tdata;
5201 if (g->global_gotsym != NULL)
5202 BFD_ASSERT ((elf_hash_table (info)->dynsymcount
5203 - g->global_gotsym->dynindx)
5204 <= g->global_gotno);
5207 /* On IRIX5, we omit the .options section. On IRIX6, however, we
5208 include it, even though we don't process it quite right. (Some
5209 entries are supposed to be merged.) Empirically, we seem to be
5210 better off including it then not. */
5211 if (IRIX_COMPAT (abfd) == ict_irix5 || IRIX_COMPAT (abfd) == ict_none)
5212 for (secpp = &abfd->sections; *secpp != NULL; secpp = &(*secpp)->next)
5214 if (strcmp ((*secpp)->name, MIPS_ELF_OPTIONS_SECTION_NAME (abfd)) == 0)
5216 for (p = (*secpp)->link_order_head; p != NULL; p = p->next)
5217 if (p->type == bfd_indirect_link_order)
5218 p->u.indirect.section->flags &= ~SEC_HAS_CONTENTS;
5219 (*secpp)->link_order_head = NULL;
5220 bfd_section_list_remove (abfd, secpp);
5221 --abfd->section_count;
5227 /* Get a value for the GP register. */
5228 if (elf_gp (abfd) == 0)
5230 struct bfd_link_hash_entry *h;
5232 h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true);
5233 if (h != (struct bfd_link_hash_entry *) NULL
5234 && h->type == bfd_link_hash_defined)
5235 elf_gp (abfd) = (h->u.def.value
5236 + h->u.def.section->output_section->vma
5237 + h->u.def.section->output_offset);
5238 else if (info->relocateable)
5242 /* Find the GP-relative section with the lowest offset. */
5244 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
5246 && (elf_section_data (o)->this_hdr.sh_flags & SHF_MIPS_GPREL))
5249 /* And calculate GP relative to that. */
5250 elf_gp (abfd) = lo + ELF_MIPS_GP_OFFSET (abfd);
5254 /* If the relocate_section function needs to do a reloc
5255 involving the GP value, it should make a reloc_dangerous
5256 callback to warn that GP is not defined. */
5260 /* Go through the sections and collect the .reginfo and .mdebug
5264 gptab_data_sec = NULL;
5265 gptab_bss_sec = NULL;
5266 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
5268 if (strcmp (o->name, ".reginfo") == 0)
5270 memset (®info, 0, sizeof reginfo);
5272 /* We have found the .reginfo section in the output file.
5273 Look through all the link_orders comprising it and merge
5274 the information together. */
5275 for (p = o->link_order_head;
5276 p != (struct bfd_link_order *) NULL;
5279 asection *input_section;
5281 Elf32_External_RegInfo ext;
5284 if (p->type != bfd_indirect_link_order)
5286 if (p->type == bfd_fill_link_order)
5291 input_section = p->u.indirect.section;
5292 input_bfd = input_section->owner;
5294 /* The linker emulation code has probably clobbered the
5295 size to be zero bytes. */
5296 if (input_section->_raw_size == 0)
5297 input_section->_raw_size = sizeof (Elf32_External_RegInfo);
5299 if (! bfd_get_section_contents (input_bfd, input_section,
5302 (bfd_size_type) sizeof ext))
5305 bfd_mips_elf32_swap_reginfo_in (input_bfd, &ext, &sub);
5307 reginfo.ri_gprmask |= sub.ri_gprmask;
5308 reginfo.ri_cprmask[0] |= sub.ri_cprmask[0];
5309 reginfo.ri_cprmask[1] |= sub.ri_cprmask[1];
5310 reginfo.ri_cprmask[2] |= sub.ri_cprmask[2];
5311 reginfo.ri_cprmask[3] |= sub.ri_cprmask[3];
5313 /* ri_gp_value is set by the function
5314 mips_elf32_section_processing when the section is
5315 finally written out. */
5317 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5318 elf_link_input_bfd ignores this section. */
5319 input_section->flags &= ~SEC_HAS_CONTENTS;
5322 /* Size has been set in mips_elf_always_size_sections */
5323 BFD_ASSERT(o->_raw_size == sizeof (Elf32_External_RegInfo));
5325 /* Skip this section later on (I don't think this currently
5326 matters, but someday it might). */
5327 o->link_order_head = (struct bfd_link_order *) NULL;
5332 if (strcmp (o->name, ".mdebug") == 0)
5334 struct extsym_info einfo;
5337 /* We have found the .mdebug section in the output file.
5338 Look through all the link_orders comprising it and merge
5339 the information together. */
5340 symhdr->magic = swap->sym_magic;
5341 /* FIXME: What should the version stamp be? */
5343 symhdr->ilineMax = 0;
5347 symhdr->isymMax = 0;
5348 symhdr->ioptMax = 0;
5349 symhdr->iauxMax = 0;
5351 symhdr->issExtMax = 0;
5354 symhdr->iextMax = 0;
5356 /* We accumulate the debugging information itself in the
5357 debug_info structure. */
5359 debug.external_dnr = NULL;
5360 debug.external_pdr = NULL;
5361 debug.external_sym = NULL;
5362 debug.external_opt = NULL;
5363 debug.external_aux = NULL;
5365 debug.ssext = debug.ssext_end = NULL;
5366 debug.external_fdr = NULL;
5367 debug.external_rfd = NULL;
5368 debug.external_ext = debug.external_ext_end = NULL;
5370 mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info);
5371 if (mdebug_handle == (PTR) NULL)
5375 esym.cobol_main = 0;
5379 esym.asym.iss = issNil;
5380 esym.asym.st = stLocal;
5381 esym.asym.reserved = 0;
5382 esym.asym.index = indexNil;
5384 for (i = 0; i < sizeof (secname) / sizeof (secname[0]); i++)
5386 esym.asym.sc = sc[i];
5387 s = bfd_get_section_by_name (abfd, secname[i]);
5390 esym.asym.value = s->vma;
5391 last = s->vma + s->_raw_size;
5394 esym.asym.value = last;
5395 if (!bfd_ecoff_debug_one_external (abfd, &debug, swap,
5400 for (p = o->link_order_head;
5401 p != (struct bfd_link_order *) NULL;
5404 asection *input_section;
5406 const struct ecoff_debug_swap *input_swap;
5407 struct ecoff_debug_info input_debug;
5411 if (p->type != bfd_indirect_link_order)
5413 if (p->type == bfd_fill_link_order)
5418 input_section = p->u.indirect.section;
5419 input_bfd = input_section->owner;
5421 if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour
5422 || (get_elf_backend_data (input_bfd)
5423 ->elf_backend_ecoff_debug_swap) == NULL)
5425 /* I don't know what a non MIPS ELF bfd would be
5426 doing with a .mdebug section, but I don't really
5427 want to deal with it. */
5431 input_swap = (get_elf_backend_data (input_bfd)
5432 ->elf_backend_ecoff_debug_swap);
5434 BFD_ASSERT (p->size == input_section->_raw_size);
5436 /* The ECOFF linking code expects that we have already
5437 read in the debugging information and set up an
5438 ecoff_debug_info structure, so we do that now. */
5439 if (! _bfd_mips_elf_read_ecoff_info (input_bfd, input_section,
5443 if (! (bfd_ecoff_debug_accumulate
5444 (mdebug_handle, abfd, &debug, swap, input_bfd,
5445 &input_debug, input_swap, info)))
5448 /* Loop through the external symbols. For each one with
5449 interesting information, try to find the symbol in
5450 the linker global hash table and save the information
5451 for the output external symbols. */
5452 eraw_src = input_debug.external_ext;
5453 eraw_end = (eraw_src
5454 + (input_debug.symbolic_header.iextMax
5455 * input_swap->external_ext_size));
5457 eraw_src < eraw_end;
5458 eraw_src += input_swap->external_ext_size)
5462 struct mips_elf_link_hash_entry *h;
5464 (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext);
5465 if (ext.asym.sc == scNil
5466 || ext.asym.sc == scUndefined
5467 || ext.asym.sc == scSUndefined)
5470 name = input_debug.ssext + ext.asym.iss;
5471 h = mips_elf_link_hash_lookup (mips_elf_hash_table (info),
5472 name, false, false, true);
5473 if (h == NULL || h->esym.ifd != -2)
5479 < input_debug.symbolic_header.ifdMax);
5480 ext.ifd = input_debug.ifdmap[ext.ifd];
5486 /* Free up the information we just read. */
5487 free (input_debug.line);
5488 free (input_debug.external_dnr);
5489 free (input_debug.external_pdr);
5490 free (input_debug.external_sym);
5491 free (input_debug.external_opt);
5492 free (input_debug.external_aux);
5493 free (input_debug.ss);
5494 free (input_debug.ssext);
5495 free (input_debug.external_fdr);
5496 free (input_debug.external_rfd);
5497 free (input_debug.external_ext);
5499 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5500 elf_link_input_bfd ignores this section. */
5501 input_section->flags &= ~SEC_HAS_CONTENTS;
5504 if (SGI_COMPAT (abfd) && info->shared)
5506 /* Create .rtproc section. */
5507 rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc");
5508 if (rtproc_sec == NULL)
5510 flagword flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY
5511 | SEC_LINKER_CREATED | SEC_READONLY);
5513 rtproc_sec = bfd_make_section (abfd, ".rtproc");
5514 if (rtproc_sec == NULL
5515 || ! bfd_set_section_flags (abfd, rtproc_sec, flags)
5516 || ! bfd_set_section_alignment (abfd, rtproc_sec, 4))
5520 if (! mips_elf_create_procedure_table (mdebug_handle, abfd,
5521 info, rtproc_sec, &debug))
5525 /* Build the external symbol information. */
5528 einfo.debug = &debug;
5530 einfo.failed = false;
5531 mips_elf_link_hash_traverse (mips_elf_hash_table (info),
5532 mips_elf_output_extsym,
5537 /* Set the size of the .mdebug section. */
5538 o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap);
5540 /* Skip this section later on (I don't think this currently
5541 matters, but someday it might). */
5542 o->link_order_head = (struct bfd_link_order *) NULL;
5547 if (strncmp (o->name, ".gptab.", sizeof ".gptab." - 1) == 0)
5549 const char *subname;
5552 Elf32_External_gptab *ext_tab;
5555 /* The .gptab.sdata and .gptab.sbss sections hold
5556 information describing how the small data area would
5557 change depending upon the -G switch. These sections
5558 not used in executables files. */
5559 if (! info->relocateable)
5561 for (p = o->link_order_head;
5562 p != (struct bfd_link_order *) NULL;
5565 asection *input_section;
5567 if (p->type != bfd_indirect_link_order)
5569 if (p->type == bfd_fill_link_order)
5574 input_section = p->u.indirect.section;
5576 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5577 elf_link_input_bfd ignores this section. */
5578 input_section->flags &= ~SEC_HAS_CONTENTS;
5581 /* Skip this section later on (I don't think this
5582 currently matters, but someday it might). */
5583 o->link_order_head = (struct bfd_link_order *) NULL;
5585 /* Really remove the section. */
5586 for (secpp = &abfd->sections;
5588 secpp = &(*secpp)->next)
5590 bfd_section_list_remove (abfd, secpp);
5591 --abfd->section_count;
5596 /* There is one gptab for initialized data, and one for
5597 uninitialized data. */
5598 if (strcmp (o->name, ".gptab.sdata") == 0)
5600 else if (strcmp (o->name, ".gptab.sbss") == 0)
5604 (*_bfd_error_handler)
5605 (_("%s: illegal section name `%s'"),
5606 bfd_get_filename (abfd), o->name);
5607 bfd_set_error (bfd_error_nonrepresentable_section);
5611 /* The linker script always combines .gptab.data and
5612 .gptab.sdata into .gptab.sdata, and likewise for
5613 .gptab.bss and .gptab.sbss. It is possible that there is
5614 no .sdata or .sbss section in the output file, in which
5615 case we must change the name of the output section. */
5616 subname = o->name + sizeof ".gptab" - 1;
5617 if (bfd_get_section_by_name (abfd, subname) == NULL)
5619 if (o == gptab_data_sec)
5620 o->name = ".gptab.data";
5622 o->name = ".gptab.bss";
5623 subname = o->name + sizeof ".gptab" - 1;
5624 BFD_ASSERT (bfd_get_section_by_name (abfd, subname) != NULL);
5627 /* Set up the first entry. */
5629 amt = c * sizeof (Elf32_gptab);
5630 tab = (Elf32_gptab *) bfd_malloc (amt);
5633 tab[0].gt_header.gt_current_g_value = elf_gp_size (abfd);
5634 tab[0].gt_header.gt_unused = 0;
5636 /* Combine the input sections. */
5637 for (p = o->link_order_head;
5638 p != (struct bfd_link_order *) NULL;
5641 asection *input_section;
5645 bfd_size_type gpentry;
5647 if (p->type != bfd_indirect_link_order)
5649 if (p->type == bfd_fill_link_order)
5654 input_section = p->u.indirect.section;
5655 input_bfd = input_section->owner;
5657 /* Combine the gptab entries for this input section one
5658 by one. We know that the input gptab entries are
5659 sorted by ascending -G value. */
5660 size = bfd_section_size (input_bfd, input_section);
5662 for (gpentry = sizeof (Elf32_External_gptab);
5664 gpentry += sizeof (Elf32_External_gptab))
5666 Elf32_External_gptab ext_gptab;
5667 Elf32_gptab int_gptab;
5673 if (! (bfd_get_section_contents
5674 (input_bfd, input_section, (PTR) &ext_gptab,
5676 (bfd_size_type) sizeof (Elf32_External_gptab))))
5682 bfd_mips_elf32_swap_gptab_in (input_bfd, &ext_gptab,
5684 val = int_gptab.gt_entry.gt_g_value;
5685 add = int_gptab.gt_entry.gt_bytes - last;
5688 for (look = 1; look < c; look++)
5690 if (tab[look].gt_entry.gt_g_value >= val)
5691 tab[look].gt_entry.gt_bytes += add;
5693 if (tab[look].gt_entry.gt_g_value == val)
5699 Elf32_gptab *new_tab;
5702 /* We need a new table entry. */
5703 amt = (bfd_size_type) (c + 1) * sizeof (Elf32_gptab);
5704 new_tab = (Elf32_gptab *) bfd_realloc ((PTR) tab, amt);
5705 if (new_tab == NULL)
5711 tab[c].gt_entry.gt_g_value = val;
5712 tab[c].gt_entry.gt_bytes = add;
5714 /* Merge in the size for the next smallest -G
5715 value, since that will be implied by this new
5718 for (look = 1; look < c; look++)
5720 if (tab[look].gt_entry.gt_g_value < val
5722 || (tab[look].gt_entry.gt_g_value
5723 > tab[max].gt_entry.gt_g_value)))
5727 tab[c].gt_entry.gt_bytes +=
5728 tab[max].gt_entry.gt_bytes;
5733 last = int_gptab.gt_entry.gt_bytes;
5736 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5737 elf_link_input_bfd ignores this section. */
5738 input_section->flags &= ~SEC_HAS_CONTENTS;
5741 /* The table must be sorted by -G value. */
5743 qsort (tab + 1, c - 1, sizeof (tab[0]), gptab_compare);
5745 /* Swap out the table. */
5746 amt = (bfd_size_type) c * sizeof (Elf32_External_gptab);
5747 ext_tab = (Elf32_External_gptab *) bfd_alloc (abfd, amt);
5748 if (ext_tab == NULL)
5754 for (j = 0; j < c; j++)
5755 bfd_mips_elf32_swap_gptab_out (abfd, tab + j, ext_tab + j);
5758 o->_raw_size = c * sizeof (Elf32_External_gptab);
5759 o->contents = (bfd_byte *) ext_tab;
5761 /* Skip this section later on (I don't think this currently
5762 matters, but someday it might). */
5763 o->link_order_head = (struct bfd_link_order *) NULL;
5767 /* Invoke the regular ELF backend linker to do all the work. */
5768 if (ABI_64_P (abfd))
5771 if (!bfd_elf64_bfd_final_link (abfd, info))
5778 else if (!bfd_elf32_bfd_final_link (abfd, info))
5781 /* Now write out the computed sections. */
5783 if (reginfo_sec != (asection *) NULL)
5785 Elf32_External_RegInfo ext;
5787 bfd_mips_elf32_swap_reginfo_out (abfd, ®info, &ext);
5788 if (! bfd_set_section_contents (abfd, reginfo_sec, (PTR) &ext,
5789 (file_ptr) 0, (bfd_size_type) sizeof ext))
5793 if (mdebug_sec != (asection *) NULL)
5795 BFD_ASSERT (abfd->output_has_begun);
5796 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug,
5798 mdebug_sec->filepos))
5801 bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info);
5804 if (gptab_data_sec != (asection *) NULL)
5806 if (! bfd_set_section_contents (abfd, gptab_data_sec,
5807 gptab_data_sec->contents,
5809 gptab_data_sec->_raw_size))
5813 if (gptab_bss_sec != (asection *) NULL)
5815 if (! bfd_set_section_contents (abfd, gptab_bss_sec,
5816 gptab_bss_sec->contents,
5818 gptab_bss_sec->_raw_size))
5822 if (SGI_COMPAT (abfd))
5824 rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc");
5825 if (rtproc_sec != NULL)
5827 if (! bfd_set_section_contents (abfd, rtproc_sec,
5828 rtproc_sec->contents,
5830 rtproc_sec->_raw_size))
5838 /* This function is called via qsort() to sort the dynamic relocation
5839 entries by increasing r_symndx value. */
5842 sort_dynamic_relocs (arg1, arg2)
5846 const Elf32_External_Rel *ext_reloc1 = (const Elf32_External_Rel *) arg1;
5847 const Elf32_External_Rel *ext_reloc2 = (const Elf32_External_Rel *) arg2;
5849 Elf_Internal_Rel int_reloc1;
5850 Elf_Internal_Rel int_reloc2;
5852 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd, ext_reloc1, &int_reloc1);
5853 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd, ext_reloc2, &int_reloc2);
5855 return (ELF32_R_SYM (int_reloc1.r_info) - ELF32_R_SYM (int_reloc2.r_info));
5858 /* Returns the GOT section for ABFD. */
5861 mips_elf_got_section (abfd)
5864 return bfd_get_section_by_name (abfd, ".got");
5867 /* Returns the GOT information associated with the link indicated by
5868 INFO. If SGOTP is non-NULL, it is filled in with the GOT
5871 static struct mips_got_info *
5872 mips_elf_got_info (abfd, sgotp)
5877 struct mips_got_info *g;
5879 sgot = mips_elf_got_section (abfd);
5880 BFD_ASSERT (sgot != NULL);
5881 BFD_ASSERT (elf_section_data (sgot) != NULL);
5882 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
5883 BFD_ASSERT (g != NULL);
5890 /* Return whether a relocation is against a local symbol. */
5893 mips_elf_local_relocation_p (input_bfd, relocation, local_sections,
5896 const Elf_Internal_Rela *relocation;
5897 asection **local_sections;
5898 boolean check_forced;
5900 unsigned long r_symndx;
5901 Elf_Internal_Shdr *symtab_hdr;
5902 struct mips_elf_link_hash_entry *h;
5905 r_symndx = ELF32_R_SYM (relocation->r_info);
5906 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5907 extsymoff = (elf_bad_symtab (input_bfd)) ? 0 : symtab_hdr->sh_info;
5909 if (r_symndx < extsymoff)
5911 if (elf_bad_symtab (input_bfd) && local_sections[r_symndx] != NULL)
5916 /* Look up the hash table to check whether the symbol
5917 was forced local. */
5918 h = (struct mips_elf_link_hash_entry *)
5919 elf_sym_hashes (input_bfd) [r_symndx - extsymoff];
5920 /* Find the real hash-table entry for this symbol. */
5921 while (h->root.root.type == bfd_link_hash_indirect
5922 || h->root.root.type == bfd_link_hash_warning)
5923 h = (struct mips_elf_link_hash_entry *) h->root.root.u.i.link;
5924 if ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)
5931 /* Sign-extend VALUE, which has the indicated number of BITS. */
5934 mips_elf_sign_extend (value, bits)
5938 if (value & ((bfd_vma) 1 << (bits - 1)))
5939 /* VALUE is negative. */
5940 value |= ((bfd_vma) - 1) << bits;
5945 /* Return non-zero if the indicated VALUE has overflowed the maximum
5946 range expressable by a signed number with the indicated number of
5950 mips_elf_overflow_p (value, bits)
5954 bfd_signed_vma svalue = (bfd_signed_vma) value;
5956 if (svalue > (1 << (bits - 1)) - 1)
5957 /* The value is too big. */
5959 else if (svalue < -(1 << (bits - 1)))
5960 /* The value is too small. */
5967 /* Calculate the %high function. */
5970 mips_elf_high (value)
5973 return ((value + (bfd_vma) 0x8000) >> 16) & 0xffff;
5976 /* Calculate the %higher function. */
5979 mips_elf_higher (value)
5980 bfd_vma value ATTRIBUTE_UNUSED;
5983 return ((value + (bfd_vma) 0x80008000) >> 32) & 0xffff;
5986 return (bfd_vma) -1;
5990 /* Calculate the %highest function. */
5993 mips_elf_highest (value)
5994 bfd_vma value ATTRIBUTE_UNUSED;
5997 return ((value + (bfd_vma) 0x800080008000) >> 48) & 0xffff;
6000 return (bfd_vma) -1;
6004 /* Returns the GOT index for the global symbol indicated by H. */
6007 mips_elf_global_got_index (abfd, h)
6009 struct elf_link_hash_entry *h;
6013 struct mips_got_info *g;
6015 g = mips_elf_got_info (abfd, &sgot);
6017 /* Once we determine the global GOT entry with the lowest dynamic
6018 symbol table index, we must put all dynamic symbols with greater
6019 indices into the GOT. That makes it easy to calculate the GOT
6021 BFD_ASSERT (h->dynindx >= g->global_gotsym->dynindx);
6022 index = ((h->dynindx - g->global_gotsym->dynindx + g->local_gotno)
6023 * MIPS_ELF_GOT_SIZE (abfd));
6024 BFD_ASSERT (index < sgot->_raw_size);
6029 /* Returns the offset for the entry at the INDEXth position
6033 mips_elf_got_offset_from_index (dynobj, output_bfd, index)
6041 sgot = mips_elf_got_section (dynobj);
6042 gp = _bfd_get_gp_value (output_bfd);
6043 return (sgot->output_section->vma + sgot->output_offset + index -
6047 /* If H is a symbol that needs a global GOT entry, but has a dynamic
6048 symbol table index lower than any we've seen to date, record it for
6052 mips_elf_record_global_got_symbol (h, info, g)
6053 struct elf_link_hash_entry *h;
6054 struct bfd_link_info *info;
6055 struct mips_got_info *g ATTRIBUTE_UNUSED;
6057 /* A global symbol in the GOT must also be in the dynamic symbol
6059 if (h->dynindx == -1)
6061 switch (ELF_ST_VISIBILITY (h->other))
6065 _bfd_mips_elf_hide_symbol (info, h, true);
6068 if (!bfd_elf32_link_record_dynamic_symbol (info, h))
6072 /* If we've already marked this entry as needing GOT space, we don't
6073 need to do it again. */
6074 if (h->got.offset != (bfd_vma) -1)
6077 /* By setting this to a value other than -1, we are indicating that
6078 there needs to be a GOT entry for H. Avoid using zero, as the
6079 generic ELF copy_indirect_symbol tests for <= 0. */
6085 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
6086 the dynamic symbols. */
6088 struct mips_elf_hash_sort_data
6090 /* The symbol in the global GOT with the lowest dynamic symbol table
6092 struct elf_link_hash_entry *low;
6093 /* The least dynamic symbol table index corresponding to a symbol
6094 with a GOT entry. */
6095 long min_got_dynindx;
6096 /* The greatest dynamic symbol table index not corresponding to a
6097 symbol without a GOT entry. */
6098 long max_non_got_dynindx;
6101 /* If H needs a GOT entry, assign it the highest available dynamic
6102 index. Otherwise, assign it the lowest available dynamic
6106 mips_elf_sort_hash_table_f (h, data)
6107 struct mips_elf_link_hash_entry *h;
6110 struct mips_elf_hash_sort_data *hsd
6111 = (struct mips_elf_hash_sort_data *) data;
6113 if (h->root.root.type == bfd_link_hash_warning)
6114 h = (struct mips_elf_link_hash_entry *) h->root.root.u.i.link;
6116 /* Symbols without dynamic symbol table entries aren't interesting
6118 if (h->root.dynindx == -1)
6121 if (h->root.got.offset != 1)
6122 h->root.dynindx = hsd->max_non_got_dynindx++;
6125 h->root.dynindx = --hsd->min_got_dynindx;
6126 hsd->low = (struct elf_link_hash_entry *) h;
6132 /* Sort the dynamic symbol table so that symbols that need GOT entries
6133 appear towards the end. This reduces the amount of GOT space
6134 required. MAX_LOCAL is used to set the number of local symbols
6135 known to be in the dynamic symbol table. During
6136 mips_elf_size_dynamic_sections, this value is 1. Afterward, the
6137 section symbols are added and the count is higher. */
6140 mips_elf_sort_hash_table (info, max_local)
6141 struct bfd_link_info *info;
6142 unsigned long max_local;
6144 struct mips_elf_hash_sort_data hsd;
6145 struct mips_got_info *g;
6148 dynobj = elf_hash_table (info)->dynobj;
6151 hsd.min_got_dynindx = elf_hash_table (info)->dynsymcount;
6152 hsd.max_non_got_dynindx = max_local;
6153 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table *)
6154 elf_hash_table (info)),
6155 mips_elf_sort_hash_table_f,
6158 /* There should have been enough room in the symbol table to
6159 accomodate both the GOT and non-GOT symbols. */
6160 BFD_ASSERT (hsd.max_non_got_dynindx <= hsd.min_got_dynindx);
6162 /* Now we know which dynamic symbol has the lowest dynamic symbol
6163 table index in the GOT. */
6164 g = mips_elf_got_info (dynobj, NULL);
6165 g->global_gotsym = hsd.low;
6170 /* Create a local GOT entry for VALUE. Return the index of the entry,
6171 or -1 if it could not be created. */
6174 mips_elf_create_local_got_entry (abfd, g, sgot, value)
6176 struct mips_got_info *g;
6180 if (g->assigned_gotno >= g->local_gotno)
6182 /* We didn't allocate enough space in the GOT. */
6183 (*_bfd_error_handler)
6184 (_("not enough GOT space for local GOT entries"));
6185 bfd_set_error (bfd_error_bad_value);
6186 return (bfd_vma) -1;
6189 MIPS_ELF_PUT_WORD (abfd, value,
6191 + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno));
6192 return MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno++;
6195 /* Returns the GOT offset at which the indicated address can be found.
6196 If there is not yet a GOT entry for this value, create one. Returns
6197 -1 if no satisfactory GOT offset can be found. */
6200 mips_elf_local_got_index (abfd, info, value)
6202 struct bfd_link_info *info;
6206 struct mips_got_info *g;
6209 g = mips_elf_got_info (elf_hash_table (info)->dynobj, &sgot);
6211 /* Look to see if we already have an appropriate entry. */
6212 for (entry = (sgot->contents
6213 + MIPS_ELF_GOT_SIZE (abfd) * MIPS_RESERVED_GOTNO);
6214 entry != sgot->contents + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno;
6215 entry += MIPS_ELF_GOT_SIZE (abfd))
6217 bfd_vma address = MIPS_ELF_GET_WORD (abfd, entry);
6218 if (address == value)
6219 return entry - sgot->contents;
6222 return mips_elf_create_local_got_entry (abfd, g, sgot, value);
6225 /* Find a GOT entry that is within 32KB of the VALUE. These entries
6226 are supposed to be placed at small offsets in the GOT, i.e.,
6227 within 32KB of GP. Return the index into the GOT for this page,
6228 and store the offset from this entry to the desired address in
6229 OFFSETP, if it is non-NULL. */
6232 mips_elf_got_page (abfd, info, value, offsetp)
6234 struct bfd_link_info *info;
6239 struct mips_got_info *g;
6241 bfd_byte *last_entry;
6245 g = mips_elf_got_info (elf_hash_table (info)->dynobj, &sgot);
6247 /* Look to see if we aleady have an appropriate entry. */
6248 last_entry = sgot->contents + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno;
6249 for (entry = (sgot->contents
6250 + MIPS_ELF_GOT_SIZE (abfd) * MIPS_RESERVED_GOTNO);
6251 entry != last_entry;
6252 entry += MIPS_ELF_GOT_SIZE (abfd))
6254 address = MIPS_ELF_GET_WORD (abfd, entry);
6256 if (!mips_elf_overflow_p (value - address, 16))
6258 /* This entry will serve as the page pointer. We can add a
6259 16-bit number to it to get the actual address. */
6260 index = entry - sgot->contents;
6265 /* If we didn't have an appropriate entry, we create one now. */
6266 if (entry == last_entry)
6267 index = mips_elf_create_local_got_entry (abfd, g, sgot, value);
6271 address = MIPS_ELF_GET_WORD (abfd, entry);
6272 *offsetp = value - address;
6278 /* Find a GOT entry whose higher-order 16 bits are the same as those
6279 for value. Return the index into the GOT for this entry. */
6282 mips_elf_got16_entry (abfd, info, value, external)
6284 struct bfd_link_info *info;
6289 struct mips_got_info *g;
6291 bfd_byte *last_entry;
6297 /* Although the ABI says that it is "the high-order 16 bits" that we
6298 want, it is really the %high value. The complete value is
6299 calculated with a `addiu' of a LO16 relocation, just as with a
6301 value = mips_elf_high (value) << 16;
6304 g = mips_elf_got_info (elf_hash_table (info)->dynobj, &sgot);
6306 /* Look to see if we already have an appropriate entry. */
6307 last_entry = sgot->contents + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno;
6308 for (entry = (sgot->contents
6309 + MIPS_ELF_GOT_SIZE (abfd) * MIPS_RESERVED_GOTNO);
6310 entry != last_entry;
6311 entry += MIPS_ELF_GOT_SIZE (abfd))
6313 address = MIPS_ELF_GET_WORD (abfd, entry);
6314 if (address == value)
6316 /* This entry has the right high-order 16 bits, and the low-order
6317 16 bits are set to zero. */
6318 index = entry - sgot->contents;
6323 /* If we didn't have an appropriate entry, we create one now. */
6324 if (entry == last_entry)
6325 index = mips_elf_create_local_got_entry (abfd, g, sgot, value);
6330 /* Returns the first relocation of type r_type found, beginning with
6331 RELOCATION. RELEND is one-past-the-end of the relocation table. */
6333 static const Elf_Internal_Rela *
6334 mips_elf_next_relocation (r_type, relocation, relend)
6335 unsigned int r_type;
6336 const Elf_Internal_Rela *relocation;
6337 const Elf_Internal_Rela *relend;
6339 /* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be
6340 immediately following. However, for the IRIX6 ABI, the next
6341 relocation may be a composed relocation consisting of several
6342 relocations for the same address. In that case, the R_MIPS_LO16
6343 relocation may occur as one of these. We permit a similar
6344 extension in general, as that is useful for GCC. */
6345 while (relocation < relend)
6347 if (ELF32_R_TYPE (relocation->r_info) == r_type)
6353 /* We didn't find it. */
6354 bfd_set_error (bfd_error_bad_value);
6358 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
6359 is the original relocation, which is now being transformed into a
6360 dynamic relocation. The ADDENDP is adjusted if necessary; the
6361 caller should store the result in place of the original addend. */
6364 mips_elf_create_dynamic_relocation (output_bfd, info, rel, h, sec,
6365 symbol, addendp, input_section)
6367 struct bfd_link_info *info;
6368 const Elf_Internal_Rela *rel;
6369 struct mips_elf_link_hash_entry *h;
6373 asection *input_section;
6375 Elf_Internal_Rel outrel;
6381 r_type = ELF32_R_TYPE (rel->r_info);
6382 dynobj = elf_hash_table (info)->dynobj;
6384 = bfd_get_section_by_name (dynobj,
6385 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd));
6386 BFD_ASSERT (sreloc != NULL);
6387 BFD_ASSERT (sreloc->contents != NULL);
6388 BFD_ASSERT (sreloc->reloc_count * MIPS_ELF_REL_SIZE (output_bfd)
6389 < sreloc->_raw_size);
6393 _bfd_elf_section_offset (output_bfd, info, input_section, rel->r_offset);
6394 if (outrel.r_offset == (bfd_vma) -1)
6396 /* FIXME: For -2 runtime relocation needs to be skipped, but
6397 properly resolved statically and installed. */
6398 BFD_ASSERT (outrel.r_offset != (bfd_vma) -2);
6400 /* If we've decided to skip this relocation, just output an empty
6401 record. Note that R_MIPS_NONE == 0, so that this call to memset
6402 is a way of setting R_TYPE to R_MIPS_NONE. */
6404 memset (&outrel, 0, sizeof (outrel));
6408 bfd_vma section_offset;
6410 /* We must now calculate the dynamic symbol table index to use
6411 in the relocation. */
6413 && (! info->symbolic || (h->root.elf_link_hash_flags
6414 & ELF_LINK_HASH_DEF_REGULAR) == 0))
6416 indx = h->root.dynindx;
6417 /* h->root.dynindx may be -1 if this symbol was marked to
6424 if (sec != NULL && bfd_is_abs_section (sec))
6426 else if (sec == NULL || sec->owner == NULL)
6428 bfd_set_error (bfd_error_bad_value);
6433 indx = elf_section_data (sec->output_section)->dynindx;
6438 /* Figure out how far the target of the relocation is from
6439 the beginning of its section. */
6440 section_offset = symbol - sec->output_section->vma;
6441 /* The relocation we're building is section-relative.
6442 Therefore, the original addend must be adjusted by the
6444 *addendp += section_offset;
6445 /* Now, the relocation is just against the section. */
6446 symbol = sec->output_section->vma;
6449 /* If the relocation was previously an absolute relocation and
6450 this symbol will not be referred to by the relocation, we must
6451 adjust it by the value we give it in the dynamic symbol table.
6452 Otherwise leave the job up to the dynamic linker. */
6453 if (!indx && r_type != R_MIPS_REL32)
6456 /* The relocation is always an REL32 relocation because we don't
6457 know where the shared library will wind up at load-time. */
6458 outrel.r_info = ELF32_R_INFO (indx, R_MIPS_REL32);
6460 /* Adjust the output offset of the relocation to reference the
6461 correct location in the output file. */
6462 outrel.r_offset += (input_section->output_section->vma
6463 + input_section->output_offset);
6466 /* Put the relocation back out. We have to use the special
6467 relocation outputter in the 64-bit case since the 64-bit
6468 relocation format is non-standard. */
6469 if (ABI_64_P (output_bfd))
6471 (*get_elf_backend_data (output_bfd)->s->swap_reloc_out)
6472 (output_bfd, &outrel,
6474 + sreloc->reloc_count * sizeof (Elf64_Mips_External_Rel)));
6477 bfd_elf32_swap_reloc_out (output_bfd, &outrel,
6478 (((Elf32_External_Rel *)
6480 + sreloc->reloc_count));
6482 /* Record the index of the first relocation referencing H. This
6483 information is later emitted in the .msym section. */
6485 && (h->min_dyn_reloc_index == 0
6486 || sreloc->reloc_count < h->min_dyn_reloc_index))
6487 h->min_dyn_reloc_index = sreloc->reloc_count;
6489 /* We've now added another relocation. */
6490 ++sreloc->reloc_count;
6492 /* Make sure the output section is writable. The dynamic linker
6493 will be writing to it. */
6494 elf_section_data (input_section->output_section)->this_hdr.sh_flags
6497 /* On IRIX5, make an entry of compact relocation info. */
6498 if (! skip && IRIX_COMPAT (output_bfd) == ict_irix5)
6500 asection *scpt = bfd_get_section_by_name (dynobj, ".compact_rel");
6505 Elf32_crinfo cptrel;
6507 mips_elf_set_cr_format (cptrel, CRF_MIPS_LONG);
6508 cptrel.vaddr = (rel->r_offset
6509 + input_section->output_section->vma
6510 + input_section->output_offset);
6511 if (r_type == R_MIPS_REL32)
6512 mips_elf_set_cr_type (cptrel, CRT_MIPS_REL32);
6514 mips_elf_set_cr_type (cptrel, CRT_MIPS_WORD);
6515 mips_elf_set_cr_dist2to (cptrel, 0);
6516 cptrel.konst = *addendp;
6518 cr = (scpt->contents
6519 + sizeof (Elf32_External_compact_rel));
6520 bfd_elf32_swap_crinfo_out (output_bfd, &cptrel,
6521 ((Elf32_External_crinfo *) cr
6522 + scpt->reloc_count));
6523 ++scpt->reloc_count;
6530 /* Calculate the value produced by the RELOCATION (which comes from
6531 the INPUT_BFD). The ADDEND is the addend to use for this
6532 RELOCATION; RELOCATION->R_ADDEND is ignored.
6534 The result of the relocation calculation is stored in VALUEP.
6535 REQUIRE_JALXP indicates whether or not the opcode used with this
6536 relocation must be JALX.
6538 This function returns bfd_reloc_continue if the caller need take no
6539 further action regarding this relocation, bfd_reloc_notsupported if
6540 something goes dramatically wrong, bfd_reloc_overflow if an
6541 overflow occurs, and bfd_reloc_ok to indicate success. */
6543 static bfd_reloc_status_type
6544 mips_elf_calculate_relocation (abfd,
6558 asection *input_section;
6559 struct bfd_link_info *info;
6560 const Elf_Internal_Rela *relocation;
6562 reloc_howto_type *howto;
6563 Elf_Internal_Sym *local_syms;
6564 asection **local_sections;
6567 boolean *require_jalxp;
6569 /* The eventual value we will return. */
6571 /* The address of the symbol against which the relocation is
6574 /* The final GP value to be used for the relocatable, executable, or
6575 shared object file being produced. */
6576 bfd_vma gp = (bfd_vma) - 1;
6577 /* The place (section offset or address) of the storage unit being
6580 /* The value of GP used to create the relocatable object. */
6581 bfd_vma gp0 = (bfd_vma) - 1;
6582 /* The offset into the global offset table at which the address of
6583 the relocation entry symbol, adjusted by the addend, resides
6584 during execution. */
6585 bfd_vma g = (bfd_vma) - 1;
6586 /* The section in which the symbol referenced by the relocation is
6588 asection *sec = NULL;
6589 struct mips_elf_link_hash_entry *h = NULL;
6590 /* True if the symbol referred to by this relocation is a local
6593 /* True if the symbol referred to by this relocation is "_gp_disp". */
6594 boolean gp_disp_p = false;
6595 Elf_Internal_Shdr *symtab_hdr;
6597 unsigned long r_symndx;
6599 /* True if overflow occurred during the calculation of the
6600 relocation value. */
6601 boolean overflowed_p;
6602 /* True if this relocation refers to a MIPS16 function. */
6603 boolean target_is_16_bit_code_p = false;
6605 /* Parse the relocation. */
6606 r_symndx = ELF32_R_SYM (relocation->r_info);
6607 r_type = ELF32_R_TYPE (relocation->r_info);
6608 p = (input_section->output_section->vma
6609 + input_section->output_offset
6610 + relocation->r_offset);
6612 /* Assume that there will be no overflow. */
6613 overflowed_p = false;
6615 /* Figure out whether or not the symbol is local, and get the offset
6616 used in the array of hash table entries. */
6617 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
6618 local_p = mips_elf_local_relocation_p (input_bfd, relocation,
6619 local_sections, false);
6620 if (! elf_bad_symtab (input_bfd))
6621 extsymoff = symtab_hdr->sh_info;
6624 /* The symbol table does not follow the rule that local symbols
6625 must come before globals. */
6629 /* Figure out the value of the symbol. */
6632 Elf_Internal_Sym *sym;
6634 sym = local_syms + r_symndx;
6635 sec = local_sections[r_symndx];
6637 symbol = sec->output_section->vma + sec->output_offset;
6638 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
6639 symbol += sym->st_value;
6641 /* MIPS16 text labels should be treated as odd. */
6642 if (sym->st_other == STO_MIPS16)
6645 /* Record the name of this symbol, for our caller. */
6646 *namep = bfd_elf_string_from_elf_section (input_bfd,
6647 symtab_hdr->sh_link,
6650 *namep = bfd_section_name (input_bfd, sec);
6652 target_is_16_bit_code_p = (sym->st_other == STO_MIPS16);
6656 /* For global symbols we look up the symbol in the hash-table. */
6657 h = ((struct mips_elf_link_hash_entry *)
6658 elf_sym_hashes (input_bfd) [r_symndx - extsymoff]);
6659 /* Find the real hash-table entry for this symbol. */
6660 while (h->root.root.type == bfd_link_hash_indirect
6661 || h->root.root.type == bfd_link_hash_warning)
6662 h = (struct mips_elf_link_hash_entry *) h->root.root.u.i.link;
6664 /* Record the name of this symbol, for our caller. */
6665 *namep = h->root.root.root.string;
6667 /* See if this is the special _gp_disp symbol. Note that such a
6668 symbol must always be a global symbol. */
6669 if (strcmp (h->root.root.root.string, "_gp_disp") == 0)
6671 /* Relocations against _gp_disp are permitted only with
6672 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
6673 if (r_type != R_MIPS_HI16 && r_type != R_MIPS_LO16)
6674 return bfd_reloc_notsupported;
6678 /* If this symbol is defined, calculate its address. Note that
6679 _gp_disp is a magic symbol, always implicitly defined by the
6680 linker, so it's inappropriate to check to see whether or not
6682 else if ((h->root.root.type == bfd_link_hash_defined
6683 || h->root.root.type == bfd_link_hash_defweak)
6684 && h->root.root.u.def.section)
6686 sec = h->root.root.u.def.section;
6687 if (sec->output_section)
6688 symbol = (h->root.root.u.def.value
6689 + sec->output_section->vma
6690 + sec->output_offset);
6692 symbol = h->root.root.u.def.value;
6694 else if (h->root.root.type == bfd_link_hash_undefweak)
6695 /* We allow relocations against undefined weak symbols, giving
6696 it the value zero, so that you can undefined weak functions
6697 and check to see if they exist by looking at their
6700 else if (info->shared
6701 && (!info->symbolic || info->allow_shlib_undefined)
6702 && !info->no_undefined
6703 && ELF_ST_VISIBILITY (h->root.other) == STV_DEFAULT)
6705 else if (strcmp (h->root.root.root.string, "_DYNAMIC_LINK") == 0 ||
6706 strcmp (h->root.root.root.string, "_DYNAMIC_LINKING") == 0)
6708 /* If this is a dynamic link, we should have created a
6709 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
6710 in in mips_elf_create_dynamic_sections.
6711 Otherwise, we should define the symbol with a value of 0.
6712 FIXME: It should probably get into the symbol table
6714 BFD_ASSERT (! info->shared);
6715 BFD_ASSERT (bfd_get_section_by_name (abfd, ".dynamic") == NULL);
6720 if (! ((*info->callbacks->undefined_symbol)
6721 (info, h->root.root.root.string, input_bfd,
6722 input_section, relocation->r_offset,
6723 (!info->shared || info->no_undefined
6724 || ELF_ST_VISIBILITY (h->root.other)))))
6725 return bfd_reloc_undefined;
6729 target_is_16_bit_code_p = (h->root.other == STO_MIPS16);
6732 /* If this is a 32-bit call to a 16-bit function with a stub, we
6733 need to redirect the call to the stub, unless we're already *in*
6735 if (r_type != R_MIPS16_26 && !info->relocateable
6736 && ((h != NULL && h->fn_stub != NULL)
6737 || (local_p && elf_tdata (input_bfd)->local_stubs != NULL
6738 && elf_tdata (input_bfd)->local_stubs[r_symndx] != NULL))
6739 && !mips_elf_stub_section_p (input_bfd, input_section))
6741 /* This is a 32-bit call to a 16-bit function. We should
6742 have already noticed that we were going to need the
6745 sec = elf_tdata (input_bfd)->local_stubs[r_symndx];
6748 BFD_ASSERT (h->need_fn_stub);
6752 symbol = sec->output_section->vma + sec->output_offset;
6754 /* If this is a 16-bit call to a 32-bit function with a stub, we
6755 need to redirect the call to the stub. */
6756 else if (r_type == R_MIPS16_26 && !info->relocateable
6758 && (h->call_stub != NULL || h->call_fp_stub != NULL)
6759 && !target_is_16_bit_code_p)
6761 /* If both call_stub and call_fp_stub are defined, we can figure
6762 out which one to use by seeing which one appears in the input
6764 if (h->call_stub != NULL && h->call_fp_stub != NULL)
6769 for (o = input_bfd->sections; o != NULL; o = o->next)
6771 if (strncmp (bfd_get_section_name (input_bfd, o),
6772 CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0)
6774 sec = h->call_fp_stub;
6781 else if (h->call_stub != NULL)
6784 sec = h->call_fp_stub;
6786 BFD_ASSERT (sec->_raw_size > 0);
6787 symbol = sec->output_section->vma + sec->output_offset;
6790 /* Calls from 16-bit code to 32-bit code and vice versa require the
6791 special jalx instruction. */
6792 *require_jalxp = (!info->relocateable
6793 && (((r_type == R_MIPS16_26) && !target_is_16_bit_code_p)
6794 || ((r_type == R_MIPS_26) && target_is_16_bit_code_p)));
6796 local_p = mips_elf_local_relocation_p (input_bfd, relocation,
6797 local_sections, true);
6799 /* If we haven't already determined the GOT offset, or the GP value,
6800 and we're going to need it, get it now. */
6805 case R_MIPS_GOT_DISP:
6806 case R_MIPS_GOT_HI16:
6807 case R_MIPS_CALL_HI16:
6808 case R_MIPS_GOT_LO16:
6809 case R_MIPS_CALL_LO16:
6810 /* Find the index into the GOT where this value is located. */
6813 BFD_ASSERT (addend == 0);
6814 g = mips_elf_global_got_index
6815 (elf_hash_table (info)->dynobj,
6816 (struct elf_link_hash_entry *) h);
6817 if (! elf_hash_table(info)->dynamic_sections_created
6819 && (info->symbolic || h->root.dynindx == -1)
6820 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
6822 /* This is a static link or a -Bsymbolic link. The
6823 symbol is defined locally, or was forced to be local.
6824 We must initialize this entry in the GOT. */
6825 asection *sgot = mips_elf_got_section(elf_hash_table
6827 MIPS_ELF_PUT_WORD (elf_hash_table (info)->dynobj,
6828 symbol + addend, sgot->contents + g);
6831 else if (r_type == R_MIPS_GOT16 || r_type == R_MIPS_CALL16)
6832 /* There's no need to create a local GOT entry here; the
6833 calculation for a local GOT16 entry does not involve G. */
6837 g = mips_elf_local_got_index (abfd, info, symbol + addend);
6838 if (g == (bfd_vma) -1)
6839 return bfd_reloc_outofrange;
6842 /* Convert GOT indices to actual offsets. */
6843 g = mips_elf_got_offset_from_index (elf_hash_table (info)->dynobj,
6849 case R_MIPS16_GPREL:
6850 case R_MIPS_GPREL16:
6851 case R_MIPS_GPREL32:
6852 case R_MIPS_LITERAL:
6853 gp0 = _bfd_get_gp_value (input_bfd);
6854 gp = _bfd_get_gp_value (abfd);
6861 /* Figure out what kind of relocation is being performed. */
6865 return bfd_reloc_continue;
6868 value = symbol + mips_elf_sign_extend (addend, 16);
6869 overflowed_p = mips_elf_overflow_p (value, 16);
6876 || (elf_hash_table (info)->dynamic_sections_created
6878 && ((h->root.elf_link_hash_flags
6879 & ELF_LINK_HASH_DEF_DYNAMIC) != 0)
6880 && ((h->root.elf_link_hash_flags
6881 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
6883 && (input_section->flags & SEC_ALLOC) != 0)
6885 /* If we're creating a shared library, or this relocation is
6886 against a symbol in a shared library, then we can't know
6887 where the symbol will end up. So, we create a relocation
6888 record in the output, and leave the job up to the dynamic
6891 if (!mips_elf_create_dynamic_relocation (abfd,
6899 return bfd_reloc_undefined;
6903 if (r_type != R_MIPS_REL32)
6904 value = symbol + addend;
6908 value &= howto->dst_mask;
6913 case R_MIPS_GNU_REL_LO16:
6914 value = symbol + addend - p;
6915 value &= howto->dst_mask;
6918 case R_MIPS_GNU_REL16_S2:
6919 value = symbol + mips_elf_sign_extend (addend << 2, 18) - p;
6920 overflowed_p = mips_elf_overflow_p (value, 18);
6921 value = (value >> 2) & howto->dst_mask;
6924 case R_MIPS_GNU_REL_HI16:
6925 /* Instead of subtracting 'p' here, we should be subtracting the
6926 equivalent value for the LO part of the reloc, since the value
6927 here is relative to that address. Because that's not easy to do,
6928 we adjust 'addend' in _bfd_mips_elf_relocate_section(). See also
6929 the comment there for more information. */
6930 value = mips_elf_high (addend + symbol - p);
6931 value &= howto->dst_mask;
6935 /* The calculation for R_MIPS16_26 is just the same as for an
6936 R_MIPS_26. It's only the storage of the relocated field into
6937 the output file that's different. That's handled in
6938 mips_elf_perform_relocation. So, we just fall through to the
6939 R_MIPS_26 case here. */
6942 value = (((addend << 2) | ((p + 4) & 0xf0000000)) + symbol) >> 2;
6944 value = (mips_elf_sign_extend (addend << 2, 28) + symbol) >> 2;
6945 value &= howto->dst_mask;
6951 value = mips_elf_high (addend + symbol);
6952 value &= howto->dst_mask;
6956 value = mips_elf_high (addend + gp - p);
6957 overflowed_p = mips_elf_overflow_p (value, 16);
6963 value = (symbol + addend) & howto->dst_mask;
6966 value = addend + gp - p + 4;
6967 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
6968 for overflow. But, on, say, Irix 5, relocations against
6969 _gp_disp are normally generated from the .cpload
6970 pseudo-op. It generates code that normally looks like
6973 lui $gp,%hi(_gp_disp)
6974 addiu $gp,$gp,%lo(_gp_disp)
6977 Here $t9 holds the address of the function being called,
6978 as required by the MIPS ELF ABI. The R_MIPS_LO16
6979 relocation can easily overflow in this situation, but the
6980 R_MIPS_HI16 relocation will handle the overflow.
6981 Therefore, we consider this a bug in the MIPS ABI, and do
6982 not check for overflow here. */
6986 case R_MIPS_LITERAL:
6987 /* Because we don't merge literal sections, we can handle this
6988 just like R_MIPS_GPREL16. In the long run, we should merge
6989 shared literals, and then we will need to additional work
6994 case R_MIPS16_GPREL:
6995 /* The R_MIPS16_GPREL performs the same calculation as
6996 R_MIPS_GPREL16, but stores the relocated bits in a different
6997 order. We don't need to do anything special here; the
6998 differences are handled in mips_elf_perform_relocation. */
6999 case R_MIPS_GPREL16:
7001 value = mips_elf_sign_extend (addend, 16) + symbol + gp0 - gp;
7003 value = mips_elf_sign_extend (addend, 16) + symbol - gp;
7004 overflowed_p = mips_elf_overflow_p (value, 16);
7013 /* The special case is when the symbol is forced to be local. We
7014 need the full address in the GOT since no R_MIPS_LO16 relocation
7016 forced = ! mips_elf_local_relocation_p (input_bfd, relocation,
7017 local_sections, false);
7018 value = mips_elf_got16_entry (abfd, info, symbol + addend, forced);
7019 if (value == (bfd_vma) -1)
7020 return bfd_reloc_outofrange;
7022 = mips_elf_got_offset_from_index (elf_hash_table (info)->dynobj,
7025 overflowed_p = mips_elf_overflow_p (value, 16);
7031 case R_MIPS_GOT_DISP:
7033 overflowed_p = mips_elf_overflow_p (value, 16);
7036 case R_MIPS_GPREL32:
7037 value = (addend + symbol + gp0 - gp) & howto->dst_mask;
7041 value = mips_elf_sign_extend (addend, 16) + symbol - p;
7042 overflowed_p = mips_elf_overflow_p (value, 16);
7043 value = (bfd_vma) ((bfd_signed_vma) value / 4);
7046 case R_MIPS_GOT_HI16:
7047 case R_MIPS_CALL_HI16:
7048 /* We're allowed to handle these two relocations identically.
7049 The dynamic linker is allowed to handle the CALL relocations
7050 differently by creating a lazy evaluation stub. */
7052 value = mips_elf_high (value);
7053 value &= howto->dst_mask;
7056 case R_MIPS_GOT_LO16:
7057 case R_MIPS_CALL_LO16:
7058 value = g & howto->dst_mask;
7061 case R_MIPS_GOT_PAGE:
7062 value = mips_elf_got_page (abfd, info, symbol + addend, NULL);
7063 if (value == (bfd_vma) -1)
7064 return bfd_reloc_outofrange;
7065 value = mips_elf_got_offset_from_index (elf_hash_table (info)->dynobj,
7068 overflowed_p = mips_elf_overflow_p (value, 16);
7071 case R_MIPS_GOT_OFST:
7072 mips_elf_got_page (abfd, info, symbol + addend, &value);
7073 overflowed_p = mips_elf_overflow_p (value, 16);
7077 value = symbol - addend;
7078 value &= howto->dst_mask;
7082 value = mips_elf_higher (addend + symbol);
7083 value &= howto->dst_mask;
7086 case R_MIPS_HIGHEST:
7087 value = mips_elf_highest (addend + symbol);
7088 value &= howto->dst_mask;
7091 case R_MIPS_SCN_DISP:
7092 value = symbol + addend - sec->output_offset;
7093 value &= howto->dst_mask;
7098 /* Both of these may be ignored. R_MIPS_JALR is an optimization
7099 hint; we could improve performance by honoring that hint. */
7100 return bfd_reloc_continue;
7102 case R_MIPS_GNU_VTINHERIT:
7103 case R_MIPS_GNU_VTENTRY:
7104 /* We don't do anything with these at present. */
7105 return bfd_reloc_continue;
7108 /* An unrecognized relocation type. */
7109 return bfd_reloc_notsupported;
7112 /* Store the VALUE for our caller. */
7114 return overflowed_p ? bfd_reloc_overflow : bfd_reloc_ok;
7117 /* Obtain the field relocated by RELOCATION. */
7120 mips_elf_obtain_contents (howto, relocation, input_bfd, contents)
7121 reloc_howto_type *howto;
7122 const Elf_Internal_Rela *relocation;
7127 bfd_byte *location = contents + relocation->r_offset;
7129 /* Obtain the bytes. */
7130 x = bfd_get (((bfd_vma)(8 * bfd_get_reloc_size (howto))), input_bfd, location);
7132 if ((ELF32_R_TYPE (relocation->r_info) == R_MIPS16_26
7133 || ELF32_R_TYPE (relocation->r_info) == R_MIPS16_GPREL)
7134 && bfd_little_endian (input_bfd))
7135 /* The two 16-bit words will be reversed on a little-endian
7136 system. See mips_elf_perform_relocation for more details. */
7137 x = (((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16));
7142 /* It has been determined that the result of the RELOCATION is the
7143 VALUE. Use HOWTO to place VALUE into the output file at the
7144 appropriate position. The SECTION is the section to which the
7145 relocation applies. If REQUIRE_JALX is true, then the opcode used
7146 for the relocation must be either JAL or JALX, and it is
7147 unconditionally converted to JALX.
7149 Returns false if anything goes wrong. */
7152 mips_elf_perform_relocation (info, howto, relocation, value,
7153 input_bfd, input_section,
7154 contents, require_jalx)
7155 struct bfd_link_info *info;
7156 reloc_howto_type *howto;
7157 const Elf_Internal_Rela *relocation;
7160 asection *input_section;
7162 boolean require_jalx;
7166 int r_type = ELF32_R_TYPE (relocation->r_info);
7168 /* Figure out where the relocation is occurring. */
7169 location = contents + relocation->r_offset;
7171 /* Obtain the current value. */
7172 x = mips_elf_obtain_contents (howto, relocation, input_bfd, contents);
7174 /* Clear the field we are setting. */
7175 x &= ~howto->dst_mask;
7177 /* If this is the R_MIPS16_26 relocation, we must store the
7178 value in a funny way. */
7179 if (r_type == R_MIPS16_26)
7181 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
7182 Most mips16 instructions are 16 bits, but these instructions
7185 The format of these instructions is:
7187 +--------------+--------------------------------+
7188 ! JALX ! X! Imm 20:16 ! Imm 25:21 !
7189 +--------------+--------------------------------+
7191 +-----------------------------------------------+
7193 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
7194 Note that the immediate value in the first word is swapped.
7196 When producing a relocateable object file, R_MIPS16_26 is
7197 handled mostly like R_MIPS_26. In particular, the addend is
7198 stored as a straight 26-bit value in a 32-bit instruction.
7199 (gas makes life simpler for itself by never adjusting a
7200 R_MIPS16_26 reloc to be against a section, so the addend is
7201 always zero). However, the 32 bit instruction is stored as 2
7202 16-bit values, rather than a single 32-bit value. In a
7203 big-endian file, the result is the same; in a little-endian
7204 file, the two 16-bit halves of the 32 bit value are swapped.
7205 This is so that a disassembler can recognize the jal
7208 When doing a final link, R_MIPS16_26 is treated as a 32 bit
7209 instruction stored as two 16-bit values. The addend A is the
7210 contents of the targ26 field. The calculation is the same as
7211 R_MIPS_26. When storing the calculated value, reorder the
7212 immediate value as shown above, and don't forget to store the
7213 value as two 16-bit values.
7215 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
7219 +--------+----------------------+
7223 +--------+----------------------+
7226 +----------+------+-------------+
7230 +----------+--------------------+
7231 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
7232 ((sub1 << 16) | sub2)).
7234 When producing a relocateable object file, the calculation is
7235 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
7236 When producing a fully linked file, the calculation is
7237 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
7238 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff) */
7240 if (!info->relocateable)
7241 /* Shuffle the bits according to the formula above. */
7242 value = (((value & 0x1f0000) << 5)
7243 | ((value & 0x3e00000) >> 5)
7244 | (value & 0xffff));
7246 else if (r_type == R_MIPS16_GPREL)
7248 /* R_MIPS16_GPREL is used for GP-relative addressing in mips16
7249 mode. A typical instruction will have a format like this:
7251 +--------------+--------------------------------+
7252 ! EXTEND ! Imm 10:5 ! Imm 15:11 !
7253 +--------------+--------------------------------+
7254 ! Major ! rx ! ry ! Imm 4:0 !
7255 +--------------+--------------------------------+
7257 EXTEND is the five bit value 11110. Major is the instruction
7260 This is handled exactly like R_MIPS_GPREL16, except that the
7261 addend is retrieved and stored as shown in this diagram; that
7262 is, the Imm fields above replace the V-rel16 field.
7264 All we need to do here is shuffle the bits appropriately. As
7265 above, the two 16-bit halves must be swapped on a
7266 little-endian system. */
7267 value = (((value & 0x7e0) << 16)
7268 | ((value & 0xf800) << 5)
7272 /* Set the field. */
7273 x |= (value & howto->dst_mask);
7275 /* If required, turn JAL into JALX. */
7279 bfd_vma opcode = x >> 26;
7280 bfd_vma jalx_opcode;
7282 /* Check to see if the opcode is already JAL or JALX. */
7283 if (r_type == R_MIPS16_26)
7285 ok = ((opcode == 0x6) || (opcode == 0x7));
7290 ok = ((opcode == 0x3) || (opcode == 0x1d));
7294 /* If the opcode is not JAL or JALX, there's a problem. */
7297 (*_bfd_error_handler)
7298 (_("%s: %s+0x%lx: jump to stub routine which is not jal"),
7299 bfd_archive_filename (input_bfd),
7300 input_section->name,
7301 (unsigned long) relocation->r_offset);
7302 bfd_set_error (bfd_error_bad_value);
7306 /* Make this the JALX opcode. */
7307 x = (x & ~(0x3f << 26)) | (jalx_opcode << 26);
7310 /* Swap the high- and low-order 16 bits on little-endian systems
7311 when doing a MIPS16 relocation. */
7312 if ((r_type == R_MIPS16_GPREL || r_type == R_MIPS16_26)
7313 && bfd_little_endian (input_bfd))
7314 x = (((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16));
7316 /* Put the value into the output. */
7317 bfd_put (8 * bfd_get_reloc_size (howto), input_bfd, x, location);
7321 /* Returns true if SECTION is a MIPS16 stub section. */
7324 mips_elf_stub_section_p (abfd, section)
7325 bfd *abfd ATTRIBUTE_UNUSED;
7328 const char *name = bfd_get_section_name (abfd, section);
7330 return (strncmp (name, FN_STUB, sizeof FN_STUB - 1) == 0
7331 || strncmp (name, CALL_STUB, sizeof CALL_STUB - 1) == 0
7332 || strncmp (name, CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0);
7335 /* Relocate a MIPS ELF section. */
7338 _bfd_mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
7339 contents, relocs, local_syms, local_sections)
7341 struct bfd_link_info *info;
7343 asection *input_section;
7345 Elf_Internal_Rela *relocs;
7346 Elf_Internal_Sym *local_syms;
7347 asection **local_sections;
7349 Elf_Internal_Rela *rel;
7350 const Elf_Internal_Rela *relend;
7352 boolean use_saved_addend_p = false;
7353 struct elf_backend_data *bed;
7355 bed = get_elf_backend_data (output_bfd);
7356 relend = relocs + input_section->reloc_count * bed->s->int_rels_per_ext_rel;
7357 for (rel = relocs; rel < relend; ++rel)
7361 reloc_howto_type *howto;
7362 boolean require_jalx;
7363 /* True if the relocation is a RELA relocation, rather than a
7365 boolean rela_relocation_p = true;
7366 unsigned int r_type = ELF32_R_TYPE (rel->r_info);
7367 const char * msg = (const char *) NULL;
7369 /* Find the relocation howto for this relocation. */
7370 if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd))
7372 /* Some 32-bit code uses R_MIPS_64. In particular, people use
7373 64-bit code, but make sure all their addresses are in the
7374 lowermost or uppermost 32-bit section of the 64-bit address
7375 space. Thus, when they use an R_MIPS_64 they mean what is
7376 usually meant by R_MIPS_32, with the exception that the
7377 stored value is sign-extended to 64 bits. */
7378 howto = elf_mips_howto_table_rel + R_MIPS_32;
7380 /* On big-endian systems, we need to lie about the position
7382 if (bfd_big_endian (input_bfd))
7386 howto = mips_rtype_to_howto (r_type);
7388 if (!use_saved_addend_p)
7390 Elf_Internal_Shdr *rel_hdr;
7392 /* If these relocations were originally of the REL variety,
7393 we must pull the addend out of the field that will be
7394 relocated. Otherwise, we simply use the contents of the
7395 RELA relocation. To determine which flavor or relocation
7396 this is, we depend on the fact that the INPUT_SECTION's
7397 REL_HDR is read before its REL_HDR2. */
7398 rel_hdr = &elf_section_data (input_section)->rel_hdr;
7399 if ((size_t) (rel - relocs)
7400 >= (NUM_SHDR_ENTRIES (rel_hdr) * bed->s->int_rels_per_ext_rel))
7401 rel_hdr = elf_section_data (input_section)->rel_hdr2;
7402 if (rel_hdr->sh_entsize == MIPS_ELF_REL_SIZE (input_bfd))
7404 /* Note that this is a REL relocation. */
7405 rela_relocation_p = false;
7407 /* Get the addend, which is stored in the input file. */
7408 addend = mips_elf_obtain_contents (howto,
7412 addend &= howto->src_mask;
7414 /* For some kinds of relocations, the ADDEND is a
7415 combination of the addend stored in two different
7417 if (r_type == R_MIPS_HI16
7418 || r_type == R_MIPS_GNU_REL_HI16
7419 || (r_type == R_MIPS_GOT16
7420 && mips_elf_local_relocation_p (input_bfd, rel,
7421 local_sections, false)))
7424 const Elf_Internal_Rela *lo16_relocation;
7425 reloc_howto_type *lo16_howto;
7428 /* The combined value is the sum of the HI16 addend,
7429 left-shifted by sixteen bits, and the LO16
7430 addend, sign extended. (Usually, the code does
7431 a `lui' of the HI16 value, and then an `addiu' of
7434 Scan ahead to find a matching LO16 relocation. */
7435 if (r_type == R_MIPS_GNU_REL_HI16)
7436 lo = R_MIPS_GNU_REL_LO16;
7440 = mips_elf_next_relocation (lo, rel, relend);
7441 if (lo16_relocation == NULL)
7444 /* Obtain the addend kept there. */
7445 lo16_howto = mips_rtype_to_howto (lo);
7446 l = mips_elf_obtain_contents (lo16_howto,
7448 input_bfd, contents);
7449 l &= lo16_howto->src_mask;
7450 l = mips_elf_sign_extend (l, 16);
7454 /* Compute the combined addend. */
7457 /* If PC-relative, subtract the difference between the
7458 address of the LO part of the reloc and the address of
7459 the HI part. The relocation is relative to the LO
7460 part, but mips_elf_calculate_relocation() doesn't know
7461 it address or the difference from the HI part, so
7462 we subtract that difference here. See also the
7463 comment in mips_elf_calculate_relocation(). */
7464 if (r_type == R_MIPS_GNU_REL_HI16)
7465 addend -= (lo16_relocation->r_offset - rel->r_offset);
7467 else if (r_type == R_MIPS16_GPREL)
7469 /* The addend is scrambled in the object file. See
7470 mips_elf_perform_relocation for details on the
7472 addend = (((addend & 0x1f0000) >> 5)
7473 | ((addend & 0x7e00000) >> 16)
7478 addend = rel->r_addend;
7481 if (info->relocateable)
7483 Elf_Internal_Sym *sym;
7484 unsigned long r_symndx;
7486 if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd)
7487 && bfd_big_endian (input_bfd))
7490 /* Since we're just relocating, all we need to do is copy
7491 the relocations back out to the object file, unless
7492 they're against a section symbol, in which case we need
7493 to adjust by the section offset, or unless they're GP
7494 relative in which case we need to adjust by the amount
7495 that we're adjusting GP in this relocateable object. */
7497 if (!mips_elf_local_relocation_p (input_bfd, rel, local_sections,
7499 /* There's nothing to do for non-local relocations. */
7502 if (r_type == R_MIPS16_GPREL
7503 || r_type == R_MIPS_GPREL16
7504 || r_type == R_MIPS_GPREL32
7505 || r_type == R_MIPS_LITERAL)
7506 addend -= (_bfd_get_gp_value (output_bfd)
7507 - _bfd_get_gp_value (input_bfd));
7508 else if (r_type == R_MIPS_26 || r_type == R_MIPS16_26
7509 || r_type == R_MIPS_GNU_REL16_S2)
7510 /* The addend is stored without its two least
7511 significant bits (which are always zero.) In a
7512 non-relocateable link, calculate_relocation will do
7513 this shift; here, we must do it ourselves. */
7516 r_symndx = ELF32_R_SYM (rel->r_info);
7517 sym = local_syms + r_symndx;
7518 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
7519 /* Adjust the addend appropriately. */
7520 addend += local_sections[r_symndx]->output_offset;
7522 /* If the relocation is for a R_MIPS_HI16 or R_MIPS_GOT16,
7523 then we only want to write out the high-order 16 bits.
7524 The subsequent R_MIPS_LO16 will handle the low-order bits. */
7525 if (r_type == R_MIPS_HI16 || r_type == R_MIPS_GOT16
7526 || r_type == R_MIPS_GNU_REL_HI16)
7527 addend = mips_elf_high (addend);
7528 /* If the relocation is for an R_MIPS_26 relocation, then
7529 the two low-order bits are not stored in the object file;
7530 they are implicitly zero. */
7531 else if (r_type == R_MIPS_26 || r_type == R_MIPS16_26
7532 || r_type == R_MIPS_GNU_REL16_S2)
7535 if (rela_relocation_p)
7536 /* If this is a RELA relocation, just update the addend.
7537 We have to cast away constness for REL. */
7538 rel->r_addend = addend;
7541 /* Otherwise, we have to write the value back out. Note
7542 that we use the source mask, rather than the
7543 destination mask because the place to which we are
7544 writing will be source of the addend in the final
7546 addend &= howto->src_mask;
7548 if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd))
7549 /* See the comment above about using R_MIPS_64 in the 32-bit
7550 ABI. Here, we need to update the addend. It would be
7551 possible to get away with just using the R_MIPS_32 reloc
7552 but for endianness. */
7558 if (addend & ((bfd_vma) 1 << 31))
7560 sign_bits = ((bfd_vma) 1 << 32) - 1;
7567 /* If we don't know that we have a 64-bit type,
7568 do two separate stores. */
7569 if (bfd_big_endian (input_bfd))
7571 /* Store the sign-bits (which are most significant)
7573 low_bits = sign_bits;
7579 high_bits = sign_bits;
7581 bfd_put_32 (input_bfd, low_bits,
7582 contents + rel->r_offset);
7583 bfd_put_32 (input_bfd, high_bits,
7584 contents + rel->r_offset + 4);
7588 if (!mips_elf_perform_relocation (info, howto, rel, addend,
7589 input_bfd, input_section,
7594 /* Go on to the next relocation. */
7598 /* In the N32 and 64-bit ABIs there may be multiple consecutive
7599 relocations for the same offset. In that case we are
7600 supposed to treat the output of each relocation as the addend
7602 if (rel + 1 < relend
7603 && rel->r_offset == rel[1].r_offset
7604 && ELF32_R_TYPE (rel[1].r_info) != R_MIPS_NONE)
7605 use_saved_addend_p = true;
7607 use_saved_addend_p = false;
7609 /* Figure out what value we are supposed to relocate. */
7610 switch (mips_elf_calculate_relocation (output_bfd,
7623 case bfd_reloc_continue:
7624 /* There's nothing to do. */
7627 case bfd_reloc_undefined:
7628 /* mips_elf_calculate_relocation already called the
7629 undefined_symbol callback. There's no real point in
7630 trying to perform the relocation at this point, so we
7631 just skip ahead to the next relocation. */
7634 case bfd_reloc_notsupported:
7635 msg = _("internal error: unsupported relocation error");
7636 info->callbacks->warning
7637 (info, msg, name, input_bfd, input_section, rel->r_offset);
7640 case bfd_reloc_overflow:
7641 if (use_saved_addend_p)
7642 /* Ignore overflow until we reach the last relocation for
7643 a given location. */
7647 BFD_ASSERT (name != NULL);
7648 if (! ((*info->callbacks->reloc_overflow)
7649 (info, name, howto->name, (bfd_vma) 0,
7650 input_bfd, input_section, rel->r_offset)))
7663 /* If we've got another relocation for the address, keep going
7664 until we reach the last one. */
7665 if (use_saved_addend_p)
7671 if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd))
7672 /* See the comment above about using R_MIPS_64 in the 32-bit
7673 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
7674 that calculated the right value. Now, however, we
7675 sign-extend the 32-bit result to 64-bits, and store it as a
7676 64-bit value. We are especially generous here in that we
7677 go to extreme lengths to support this usage on systems with
7678 only a 32-bit VMA. */
7684 if (value & ((bfd_vma) 1 << 31))
7686 sign_bits = ((bfd_vma) 1 << 32) - 1;
7693 /* If we don't know that we have a 64-bit type,
7694 do two separate stores. */
7695 if (bfd_big_endian (input_bfd))
7697 /* Undo what we did above. */
7699 /* Store the sign-bits (which are most significant)
7701 low_bits = sign_bits;
7707 high_bits = sign_bits;
7709 bfd_put_32 (input_bfd, low_bits,
7710 contents + rel->r_offset);
7711 bfd_put_32 (input_bfd, high_bits,
7712 contents + rel->r_offset + 4);
7716 /* Actually perform the relocation. */
7717 if (!mips_elf_perform_relocation (info, howto, rel, value, input_bfd,
7718 input_section, contents,
7726 /* This hook function is called before the linker writes out a global
7727 symbol. We mark symbols as small common if appropriate. This is
7728 also where we undo the increment of the value for a mips16 symbol. */
7731 _bfd_mips_elf_link_output_symbol_hook (abfd, info, name, sym, input_sec)
7732 bfd *abfd ATTRIBUTE_UNUSED;
7733 struct bfd_link_info *info ATTRIBUTE_UNUSED;
7734 const char *name ATTRIBUTE_UNUSED;
7735 Elf_Internal_Sym *sym;
7736 asection *input_sec;
7738 /* If we see a common symbol, which implies a relocatable link, then
7739 if a symbol was small common in an input file, mark it as small
7740 common in the output file. */
7741 if (sym->st_shndx == SHN_COMMON
7742 && strcmp (input_sec->name, ".scommon") == 0)
7743 sym->st_shndx = SHN_MIPS_SCOMMON;
7745 if (sym->st_other == STO_MIPS16
7746 && (sym->st_value & 1) != 0)
7752 /* Functions for the dynamic linker. */
7754 /* The name of the dynamic interpreter. This is put in the .interp
7757 #define ELF_DYNAMIC_INTERPRETER(abfd) \
7758 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
7759 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
7760 : "/usr/lib/libc.so.1")
7762 /* Create dynamic sections when linking against a dynamic object. */
7765 _bfd_mips_elf_create_dynamic_sections (abfd, info)
7767 struct bfd_link_info *info;
7769 struct elf_link_hash_entry *h;
7771 register asection *s;
7772 const char * const *namep;
7774 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
7775 | SEC_LINKER_CREATED | SEC_READONLY);
7777 /* Mips ABI requests the .dynamic section to be read only. */
7778 s = bfd_get_section_by_name (abfd, ".dynamic");
7781 if (! bfd_set_section_flags (abfd, s, flags))
7785 /* We need to create .got section. */
7786 if (! mips_elf_create_got_section (abfd, info))
7789 /* Create the .msym section on IRIX6. It is used by the dynamic
7790 linker to speed up dynamic relocations, and to avoid computing
7791 the ELF hash for symbols. */
7792 if (IRIX_COMPAT (abfd) == ict_irix6
7793 && !mips_elf_create_msym_section (abfd))
7796 /* Create .stub section. */
7797 if (bfd_get_section_by_name (abfd,
7798 MIPS_ELF_STUB_SECTION_NAME (abfd)) == NULL)
7800 s = bfd_make_section (abfd, MIPS_ELF_STUB_SECTION_NAME (abfd));
7802 || ! bfd_set_section_flags (abfd, s, flags | SEC_CODE)
7803 || ! bfd_set_section_alignment (abfd, s,
7804 MIPS_ELF_LOG_FILE_ALIGN (abfd)))
7808 if ((IRIX_COMPAT (abfd) == ict_irix5 || IRIX_COMPAT (abfd) == ict_none)
7810 && bfd_get_section_by_name (abfd, ".rld_map") == NULL)
7812 s = bfd_make_section (abfd, ".rld_map");
7814 || ! bfd_set_section_flags (abfd, s, flags &~ (flagword) SEC_READONLY)
7815 || ! bfd_set_section_alignment (abfd, s,
7816 MIPS_ELF_LOG_FILE_ALIGN (abfd)))
7820 /* On IRIX5, we adjust add some additional symbols and change the
7821 alignments of several sections. There is no ABI documentation
7822 indicating that this is necessary on IRIX6, nor any evidence that
7823 the linker takes such action. */
7824 if (IRIX_COMPAT (abfd) == ict_irix5)
7826 for (namep = mips_elf_dynsym_rtproc_names; *namep != NULL; namep++)
7829 if (! (_bfd_generic_link_add_one_symbol
7830 (info, abfd, *namep, BSF_GLOBAL, bfd_und_section_ptr,
7831 (bfd_vma) 0, (const char *) NULL, false,
7832 get_elf_backend_data (abfd)->collect,
7833 (struct bfd_link_hash_entry **) &h)))
7835 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
7836 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
7837 h->type = STT_SECTION;
7839 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
7843 /* We need to create a .compact_rel section. */
7844 if (SGI_COMPAT (abfd))
7846 if (!mips_elf_create_compact_rel_section (abfd, info))
7850 /* Change aligments of some sections. */
7851 s = bfd_get_section_by_name (abfd, ".hash");
7853 bfd_set_section_alignment (abfd, s, 4);
7854 s = bfd_get_section_by_name (abfd, ".dynsym");
7856 bfd_set_section_alignment (abfd, s, 4);
7857 s = bfd_get_section_by_name (abfd, ".dynstr");
7859 bfd_set_section_alignment (abfd, s, 4);
7860 s = bfd_get_section_by_name (abfd, ".reginfo");
7862 bfd_set_section_alignment (abfd, s, 4);
7863 s = bfd_get_section_by_name (abfd, ".dynamic");
7865 bfd_set_section_alignment (abfd, s, 4);
7871 if (SGI_COMPAT (abfd))
7873 if (!(_bfd_generic_link_add_one_symbol
7874 (info, abfd, "_DYNAMIC_LINK", BSF_GLOBAL, bfd_abs_section_ptr,
7875 (bfd_vma) 0, (const char *) NULL, false,
7876 get_elf_backend_data (abfd)->collect,
7877 (struct bfd_link_hash_entry **) &h)))
7882 /* For normal mips it is _DYNAMIC_LINKING. */
7883 if (!(_bfd_generic_link_add_one_symbol
7884 (info, abfd, "_DYNAMIC_LINKING", BSF_GLOBAL,
7885 bfd_abs_section_ptr, (bfd_vma) 0, (const char *) NULL, false,
7886 get_elf_backend_data (abfd)->collect,
7887 (struct bfd_link_hash_entry **) &h)))
7890 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
7891 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
7892 h->type = STT_SECTION;
7894 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
7897 if (! mips_elf_hash_table (info)->use_rld_obj_head)
7899 /* __rld_map is a four byte word located in the .data section
7900 and is filled in by the rtld to contain a pointer to
7901 the _r_debug structure. Its symbol value will be set in
7902 mips_elf_finish_dynamic_symbol. */
7903 s = bfd_get_section_by_name (abfd, ".rld_map");
7904 BFD_ASSERT (s != NULL);
7907 if (SGI_COMPAT (abfd))
7909 if (!(_bfd_generic_link_add_one_symbol
7910 (info, abfd, "__rld_map", BSF_GLOBAL, s,
7911 (bfd_vma) 0, (const char *) NULL, false,
7912 get_elf_backend_data (abfd)->collect,
7913 (struct bfd_link_hash_entry **) &h)))
7918 /* For normal mips the symbol is __RLD_MAP. */
7919 if (!(_bfd_generic_link_add_one_symbol
7920 (info, abfd, "__RLD_MAP", BSF_GLOBAL, s,
7921 (bfd_vma) 0, (const char *) NULL, false,
7922 get_elf_backend_data (abfd)->collect,
7923 (struct bfd_link_hash_entry **) &h)))
7926 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
7927 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
7928 h->type = STT_OBJECT;
7930 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
7938 /* Create the .compact_rel section. */
7941 mips_elf_create_compact_rel_section (abfd, info)
7943 struct bfd_link_info *info ATTRIBUTE_UNUSED;
7946 register asection *s;
7948 if (bfd_get_section_by_name (abfd, ".compact_rel") == NULL)
7950 flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED
7953 s = bfd_make_section (abfd, ".compact_rel");
7955 || ! bfd_set_section_flags (abfd, s, flags)
7956 || ! bfd_set_section_alignment (abfd, s,
7957 MIPS_ELF_LOG_FILE_ALIGN (abfd)))
7960 s->_raw_size = sizeof (Elf32_External_compact_rel);
7966 /* Create the .got section to hold the global offset table. */
7969 mips_elf_create_got_section (abfd, info)
7971 struct bfd_link_info *info;
7974 register asection *s;
7975 struct elf_link_hash_entry *h;
7976 struct mips_got_info *g;
7979 /* This function may be called more than once. */
7980 if (mips_elf_got_section (abfd))
7983 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
7984 | SEC_LINKER_CREATED);
7986 s = bfd_make_section (abfd, ".got");
7988 || ! bfd_set_section_flags (abfd, s, flags)
7989 || ! bfd_set_section_alignment (abfd, s, 4))
7992 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
7993 linker script because we don't want to define the symbol if we
7994 are not creating a global offset table. */
7996 if (! (_bfd_generic_link_add_one_symbol
7997 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
7998 (bfd_vma) 0, (const char *) NULL, false,
7999 get_elf_backend_data (abfd)->collect,
8000 (struct bfd_link_hash_entry **) &h)))
8002 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
8003 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
8004 h->type = STT_OBJECT;
8007 && ! bfd_elf32_link_record_dynamic_symbol (info, h))
8010 /* The first several global offset table entries are reserved. */
8011 s->_raw_size = MIPS_RESERVED_GOTNO * MIPS_ELF_GOT_SIZE (abfd);
8013 amt = sizeof (struct mips_got_info);
8014 g = (struct mips_got_info *) bfd_alloc (abfd, amt);
8017 g->global_gotsym = NULL;
8018 g->local_gotno = MIPS_RESERVED_GOTNO;
8019 g->assigned_gotno = MIPS_RESERVED_GOTNO;
8020 if (elf_section_data (s) == NULL)
8022 amt = sizeof (struct bfd_elf_section_data);
8023 s->used_by_bfd = (PTR) bfd_zalloc (abfd, amt);
8024 if (elf_section_data (s) == NULL)
8027 elf_section_data (s)->tdata = (PTR) g;
8028 elf_section_data (s)->this_hdr.sh_flags
8029 |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
8034 /* Returns the .msym section for ABFD, creating it if it does not
8035 already exist. Returns NULL to indicate error. */
8038 mips_elf_create_msym_section (abfd)
8043 s = bfd_get_section_by_name (abfd, MIPS_ELF_MSYM_SECTION_NAME (abfd));
8046 s = bfd_make_section (abfd, MIPS_ELF_MSYM_SECTION_NAME (abfd));
8048 || !bfd_set_section_flags (abfd, s,
8052 | SEC_LINKER_CREATED
8054 || !bfd_set_section_alignment (abfd, s,
8055 MIPS_ELF_LOG_FILE_ALIGN (abfd)))
8062 /* Add room for N relocations to the .rel.dyn section in ABFD. */
8065 mips_elf_allocate_dynamic_relocations (abfd, n)
8071 s = bfd_get_section_by_name (abfd, MIPS_ELF_REL_DYN_SECTION_NAME (abfd));
8072 BFD_ASSERT (s != NULL);
8074 if (s->_raw_size == 0)
8076 /* Make room for a null element. */
8077 s->_raw_size += MIPS_ELF_REL_SIZE (abfd);
8080 s->_raw_size += n * MIPS_ELF_REL_SIZE (abfd);
8083 /* Look through the relocs for a section during the first phase, and
8084 allocate space in the global offset table. */
8087 _bfd_mips_elf_check_relocs (abfd, info, sec, relocs)
8089 struct bfd_link_info *info;
8091 const Elf_Internal_Rela *relocs;
8095 Elf_Internal_Shdr *symtab_hdr;
8096 struct elf_link_hash_entry **sym_hashes;
8097 struct mips_got_info *g;
8099 const Elf_Internal_Rela *rel;
8100 const Elf_Internal_Rela *rel_end;
8103 struct elf_backend_data *bed;
8105 if (info->relocateable)
8108 dynobj = elf_hash_table (info)->dynobj;
8109 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
8110 sym_hashes = elf_sym_hashes (abfd);
8111 extsymoff = (elf_bad_symtab (abfd)) ? 0 : symtab_hdr->sh_info;
8113 /* Check for the mips16 stub sections. */
8115 name = bfd_get_section_name (abfd, sec);
8116 if (strncmp (name, FN_STUB, sizeof FN_STUB - 1) == 0)
8118 unsigned long r_symndx;
8120 /* Look at the relocation information to figure out which symbol
8123 r_symndx = ELF32_R_SYM (relocs->r_info);
8125 if (r_symndx < extsymoff
8126 || sym_hashes[r_symndx - extsymoff] == NULL)
8130 /* This stub is for a local symbol. This stub will only be
8131 needed if there is some relocation in this BFD, other
8132 than a 16 bit function call, which refers to this symbol. */
8133 for (o = abfd->sections; o != NULL; o = o->next)
8135 Elf_Internal_Rela *sec_relocs;
8136 const Elf_Internal_Rela *r, *rend;
8138 /* We can ignore stub sections when looking for relocs. */
8139 if ((o->flags & SEC_RELOC) == 0
8140 || o->reloc_count == 0
8141 || strncmp (bfd_get_section_name (abfd, o), FN_STUB,
8142 sizeof FN_STUB - 1) == 0
8143 || strncmp (bfd_get_section_name (abfd, o), CALL_STUB,
8144 sizeof CALL_STUB - 1) == 0
8145 || strncmp (bfd_get_section_name (abfd, o), CALL_FP_STUB,
8146 sizeof CALL_FP_STUB - 1) == 0)
8149 sec_relocs = (_bfd_elf32_link_read_relocs
8150 (abfd, o, (PTR) NULL,
8151 (Elf_Internal_Rela *) NULL,
8152 info->keep_memory));
8153 if (sec_relocs == NULL)
8156 rend = sec_relocs + o->reloc_count;
8157 for (r = sec_relocs; r < rend; r++)
8158 if (ELF32_R_SYM (r->r_info) == r_symndx
8159 && ELF32_R_TYPE (r->r_info) != R_MIPS16_26)
8162 if (! info->keep_memory)
8171 /* There is no non-call reloc for this stub, so we do
8172 not need it. Since this function is called before
8173 the linker maps input sections to output sections, we
8174 can easily discard it by setting the SEC_EXCLUDE
8176 sec->flags |= SEC_EXCLUDE;
8180 /* Record this stub in an array of local symbol stubs for
8182 if (elf_tdata (abfd)->local_stubs == NULL)
8184 unsigned long symcount;
8188 if (elf_bad_symtab (abfd))
8189 symcount = NUM_SHDR_ENTRIES (symtab_hdr);
8191 symcount = symtab_hdr->sh_info;
8192 amt = symcount * sizeof (asection *);
8193 n = (asection **) bfd_zalloc (abfd, amt);
8196 elf_tdata (abfd)->local_stubs = n;
8199 elf_tdata (abfd)->local_stubs[r_symndx] = sec;
8201 /* We don't need to set mips16_stubs_seen in this case.
8202 That flag is used to see whether we need to look through
8203 the global symbol table for stubs. We don't need to set
8204 it here, because we just have a local stub. */
8208 struct mips_elf_link_hash_entry *h;
8210 h = ((struct mips_elf_link_hash_entry *)
8211 sym_hashes[r_symndx - extsymoff]);
8213 /* H is the symbol this stub is for. */
8216 mips_elf_hash_table (info)->mips16_stubs_seen = true;
8219 else if (strncmp (name, CALL_STUB, sizeof CALL_STUB - 1) == 0
8220 || strncmp (name, CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0)
8222 unsigned long r_symndx;
8223 struct mips_elf_link_hash_entry *h;
8226 /* Look at the relocation information to figure out which symbol
8229 r_symndx = ELF32_R_SYM (relocs->r_info);
8231 if (r_symndx < extsymoff
8232 || sym_hashes[r_symndx - extsymoff] == NULL)
8234 /* This stub was actually built for a static symbol defined
8235 in the same file. We assume that all static symbols in
8236 mips16 code are themselves mips16, so we can simply
8237 discard this stub. Since this function is called before
8238 the linker maps input sections to output sections, we can
8239 easily discard it by setting the SEC_EXCLUDE flag. */
8240 sec->flags |= SEC_EXCLUDE;
8244 h = ((struct mips_elf_link_hash_entry *)
8245 sym_hashes[r_symndx - extsymoff]);
8247 /* H is the symbol this stub is for. */
8249 if (strncmp (name, CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0)
8250 loc = &h->call_fp_stub;
8252 loc = &h->call_stub;
8254 /* If we already have an appropriate stub for this function, we
8255 don't need another one, so we can discard this one. Since
8256 this function is called before the linker maps input sections
8257 to output sections, we can easily discard it by setting the
8258 SEC_EXCLUDE flag. We can also discard this section if we
8259 happen to already know that this is a mips16 function; it is
8260 not necessary to check this here, as it is checked later, but
8261 it is slightly faster to check now. */
8262 if (*loc != NULL || h->root.other == STO_MIPS16)
8264 sec->flags |= SEC_EXCLUDE;
8269 mips_elf_hash_table (info)->mips16_stubs_seen = true;
8279 sgot = mips_elf_got_section (dynobj);
8284 BFD_ASSERT (elf_section_data (sgot) != NULL);
8285 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
8286 BFD_ASSERT (g != NULL);
8291 bed = get_elf_backend_data (abfd);
8292 rel_end = relocs + sec->reloc_count * bed->s->int_rels_per_ext_rel;
8293 for (rel = relocs; rel < rel_end; ++rel)
8295 unsigned long r_symndx;
8296 unsigned int r_type;
8297 struct elf_link_hash_entry *h;
8299 r_symndx = ELF32_R_SYM (rel->r_info);
8300 r_type = ELF32_R_TYPE (rel->r_info);
8302 if (r_symndx < extsymoff)
8304 else if (r_symndx >= extsymoff + NUM_SHDR_ENTRIES (symtab_hdr))
8306 (*_bfd_error_handler)
8307 (_("%s: Malformed reloc detected for section %s"),
8308 bfd_archive_filename (abfd), name);
8309 bfd_set_error (bfd_error_bad_value);
8314 h = sym_hashes[r_symndx - extsymoff];
8316 /* This may be an indirect symbol created because of a version. */
8319 while (h->root.type == bfd_link_hash_indirect)
8320 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8324 /* Some relocs require a global offset table. */
8325 if (dynobj == NULL || sgot == NULL)
8331 case R_MIPS_CALL_HI16:
8332 case R_MIPS_CALL_LO16:
8333 case R_MIPS_GOT_HI16:
8334 case R_MIPS_GOT_LO16:
8335 case R_MIPS_GOT_PAGE:
8336 case R_MIPS_GOT_OFST:
8337 case R_MIPS_GOT_DISP:
8339 elf_hash_table (info)->dynobj = dynobj = abfd;
8340 if (! mips_elf_create_got_section (dynobj, info))
8342 g = mips_elf_got_info (dynobj, &sgot);
8349 && (info->shared || h != NULL)
8350 && (sec->flags & SEC_ALLOC) != 0)
8351 elf_hash_table (info)->dynobj = dynobj = abfd;
8359 if (!h && (r_type == R_MIPS_CALL_LO16
8360 || r_type == R_MIPS_GOT_LO16
8361 || r_type == R_MIPS_GOT_DISP))
8363 /* We may need a local GOT entry for this relocation. We
8364 don't count R_MIPS_GOT_PAGE because we can estimate the
8365 maximum number of pages needed by looking at the size of
8366 the segment. Similar comments apply to R_MIPS_GOT16 and
8367 R_MIPS_CALL16. We don't count R_MIPS_GOT_HI16, or
8368 R_MIPS_CALL_HI16 because these are always followed by an
8369 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16.
8371 This estimation is very conservative since we can merge
8372 duplicate entries in the GOT. In order to be less
8373 conservative, we could actually build the GOT here,
8374 rather than in relocate_section. */
8376 sgot->_raw_size += MIPS_ELF_GOT_SIZE (dynobj);
8384 (*_bfd_error_handler)
8385 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
8386 bfd_archive_filename (abfd), (unsigned long) rel->r_offset);
8387 bfd_set_error (bfd_error_bad_value);
8392 case R_MIPS_CALL_HI16:
8393 case R_MIPS_CALL_LO16:
8396 /* This symbol requires a global offset table entry. */
8397 if (!mips_elf_record_global_got_symbol (h, info, g))
8400 /* We need a stub, not a plt entry for the undefined
8401 function. But we record it as if it needs plt. See
8402 elf_adjust_dynamic_symbol in elflink.h. */
8403 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
8409 case R_MIPS_GOT_HI16:
8410 case R_MIPS_GOT_LO16:
8411 case R_MIPS_GOT_DISP:
8412 /* This symbol requires a global offset table entry. */
8413 if (h && !mips_elf_record_global_got_symbol (h, info, g))
8420 if ((info->shared || h != NULL)
8421 && (sec->flags & SEC_ALLOC) != 0)
8425 const char *dname = MIPS_ELF_REL_DYN_SECTION_NAME (dynobj);
8427 sreloc = bfd_get_section_by_name (dynobj, dname);
8430 sreloc = bfd_make_section (dynobj, dname);
8432 || ! bfd_set_section_flags (dynobj, sreloc,
8437 | SEC_LINKER_CREATED
8439 || ! bfd_set_section_alignment (dynobj, sreloc,
8444 #define MIPS_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
8447 /* When creating a shared object, we must copy these
8448 reloc types into the output file as R_MIPS_REL32
8449 relocs. We make room for this reloc in the
8450 .rel.dyn reloc section. */
8451 mips_elf_allocate_dynamic_relocations (dynobj, 1);
8452 if ((sec->flags & MIPS_READONLY_SECTION)
8453 == MIPS_READONLY_SECTION)
8454 /* We tell the dynamic linker that there are
8455 relocations against the text segment. */
8456 info->flags |= DF_TEXTREL;
8460 struct mips_elf_link_hash_entry *hmips;
8462 /* We only need to copy this reloc if the symbol is
8463 defined in a dynamic object. */
8464 hmips = (struct mips_elf_link_hash_entry *) h;
8465 ++hmips->possibly_dynamic_relocs;
8466 if ((sec->flags & MIPS_READONLY_SECTION)
8467 == MIPS_READONLY_SECTION)
8468 /* We need it to tell the dynamic linker if there
8469 are relocations against the text segment. */
8470 hmips->readonly_reloc = true;
8473 /* Even though we don't directly need a GOT entry for
8474 this symbol, a symbol must have a dynamic symbol
8475 table index greater that DT_MIPS_GOTSYM if there are
8476 dynamic relocations against it. */
8478 && !mips_elf_record_global_got_symbol (h, info, g))
8482 if (SGI_COMPAT (abfd))
8483 mips_elf_hash_table (info)->compact_rel_size +=
8484 sizeof (Elf32_External_crinfo);
8488 case R_MIPS_GPREL16:
8489 case R_MIPS_LITERAL:
8490 case R_MIPS_GPREL32:
8491 if (SGI_COMPAT (abfd))
8492 mips_elf_hash_table (info)->compact_rel_size +=
8493 sizeof (Elf32_External_crinfo);
8496 /* This relocation describes the C++ object vtable hierarchy.
8497 Reconstruct it for later use during GC. */
8498 case R_MIPS_GNU_VTINHERIT:
8499 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
8503 /* This relocation describes which C++ vtable entries are actually
8504 used. Record for later use during GC. */
8505 case R_MIPS_GNU_VTENTRY:
8506 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_offset))
8514 /* We must not create a stub for a symbol that has relocations
8515 related to taking the function's address. */
8521 struct mips_elf_link_hash_entry *mh;
8523 mh = (struct mips_elf_link_hash_entry *) h;
8524 mh->no_fn_stub = true;
8528 case R_MIPS_CALL_HI16:
8529 case R_MIPS_CALL_LO16:
8533 /* If this reloc is not a 16 bit call, and it has a global
8534 symbol, then we will need the fn_stub if there is one.
8535 References from a stub section do not count. */
8537 && r_type != R_MIPS16_26
8538 && strncmp (bfd_get_section_name (abfd, sec), FN_STUB,
8539 sizeof FN_STUB - 1) != 0
8540 && strncmp (bfd_get_section_name (abfd, sec), CALL_STUB,
8541 sizeof CALL_STUB - 1) != 0
8542 && strncmp (bfd_get_section_name (abfd, sec), CALL_FP_STUB,
8543 sizeof CALL_FP_STUB - 1) != 0)
8545 struct mips_elf_link_hash_entry *mh;
8547 mh = (struct mips_elf_link_hash_entry *) h;
8548 mh->need_fn_stub = true;
8555 /* Return the section that should be marked against GC for a given
8559 _bfd_mips_elf_gc_mark_hook (abfd, info, rel, h, sym)
8561 struct bfd_link_info *info ATTRIBUTE_UNUSED;
8562 Elf_Internal_Rela *rel;
8563 struct elf_link_hash_entry *h;
8564 Elf_Internal_Sym *sym;
8566 /* ??? Do mips16 stub sections need to be handled special? */
8570 switch (ELF32_R_TYPE (rel->r_info))
8572 case R_MIPS_GNU_VTINHERIT:
8573 case R_MIPS_GNU_VTENTRY:
8577 switch (h->root.type)
8579 case bfd_link_hash_defined:
8580 case bfd_link_hash_defweak:
8581 return h->root.u.def.section;
8583 case bfd_link_hash_common:
8584 return h->root.u.c.p->section;
8593 return bfd_section_from_elf_index (abfd, sym->st_shndx);
8599 /* Update the got entry reference counts for the section being removed. */
8602 _bfd_mips_elf_gc_sweep_hook (abfd, info, sec, relocs)
8603 bfd *abfd ATTRIBUTE_UNUSED;
8604 struct bfd_link_info *info ATTRIBUTE_UNUSED;
8605 asection *sec ATTRIBUTE_UNUSED;
8606 const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
8609 Elf_Internal_Shdr *symtab_hdr;
8610 struct elf_link_hash_entry **sym_hashes;
8611 bfd_signed_vma *local_got_refcounts;
8612 const Elf_Internal_Rela *rel, *relend;
8613 unsigned long r_symndx;
8614 struct elf_link_hash_entry *h;
8616 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
8617 sym_hashes = elf_sym_hashes (abfd);
8618 local_got_refcounts = elf_local_got_refcounts (abfd);
8620 relend = relocs + sec->reloc_count;
8621 for (rel = relocs; rel < relend; rel++)
8622 switch (ELF32_R_TYPE (rel->r_info))
8626 case R_MIPS_CALL_HI16:
8627 case R_MIPS_CALL_LO16:
8628 case R_MIPS_GOT_HI16:
8629 case R_MIPS_GOT_LO16:
8630 /* ??? It would seem that the existing MIPS code does no sort
8631 of reference counting or whatnot on its GOT and PLT entries,
8632 so it is not possible to garbage collect them at this time. */
8643 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
8644 hiding the old indirect symbol. Process additional relocation
8645 information. Also called for weakdefs, in which case we just let
8646 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
8649 _bfd_mips_elf_copy_indirect_symbol (dir, ind)
8650 struct elf_link_hash_entry *dir, *ind;
8652 struct mips_elf_link_hash_entry *dirmips, *indmips;
8654 _bfd_elf_link_hash_copy_indirect (dir, ind);
8656 if (ind->root.type != bfd_link_hash_indirect)
8659 dirmips = (struct mips_elf_link_hash_entry *) dir;
8660 indmips = (struct mips_elf_link_hash_entry *) ind;
8661 dirmips->possibly_dynamic_relocs += indmips->possibly_dynamic_relocs;
8662 if (indmips->readonly_reloc)
8663 dirmips->readonly_reloc = true;
8664 if (dirmips->min_dyn_reloc_index == 0
8665 || (indmips->min_dyn_reloc_index != 0
8666 && indmips->min_dyn_reloc_index < dirmips->min_dyn_reloc_index))
8667 dirmips->min_dyn_reloc_index = indmips->min_dyn_reloc_index;
8668 if (indmips->no_fn_stub)
8669 dirmips->no_fn_stub = true;
8672 /* Adjust a symbol defined by a dynamic object and referenced by a
8673 regular object. The current definition is in some section of the
8674 dynamic object, but we're not including those sections. We have to
8675 change the definition to something the rest of the link can
8679 _bfd_mips_elf_adjust_dynamic_symbol (info, h)
8680 struct bfd_link_info *info;
8681 struct elf_link_hash_entry *h;
8684 struct mips_elf_link_hash_entry *hmips;
8687 dynobj = elf_hash_table (info)->dynobj;
8689 /* Make sure we know what is going on here. */
8690 BFD_ASSERT (dynobj != NULL
8691 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
8692 || h->weakdef != NULL
8693 || ((h->elf_link_hash_flags
8694 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
8695 && (h->elf_link_hash_flags
8696 & ELF_LINK_HASH_REF_REGULAR) != 0
8697 && (h->elf_link_hash_flags
8698 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
8700 /* If this symbol is defined in a dynamic object, we need to copy
8701 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
8703 hmips = (struct mips_elf_link_hash_entry *) h;
8704 if (! info->relocateable
8705 && hmips->possibly_dynamic_relocs != 0
8706 && (h->root.type == bfd_link_hash_defweak
8707 || (h->elf_link_hash_flags
8708 & ELF_LINK_HASH_DEF_REGULAR) == 0))
8710 mips_elf_allocate_dynamic_relocations (dynobj,
8711 hmips->possibly_dynamic_relocs);
8712 if (hmips->readonly_reloc)
8713 /* We tell the dynamic linker that there are relocations
8714 against the text segment. */
8715 info->flags |= DF_TEXTREL;
8718 /* For a function, create a stub, if allowed. */
8719 if (! hmips->no_fn_stub
8720 && (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
8722 if (! elf_hash_table (info)->dynamic_sections_created)
8725 /* If this symbol is not defined in a regular file, then set
8726 the symbol to the stub location. This is required to make
8727 function pointers compare as equal between the normal
8728 executable and the shared library. */
8729 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
8731 /* We need .stub section. */
8732 s = bfd_get_section_by_name (dynobj,
8733 MIPS_ELF_STUB_SECTION_NAME (dynobj));
8734 BFD_ASSERT (s != NULL);
8736 h->root.u.def.section = s;
8737 h->root.u.def.value = s->_raw_size;
8739 /* XXX Write this stub address somewhere. */
8740 h->plt.offset = s->_raw_size;
8742 /* Make room for this stub code. */
8743 s->_raw_size += MIPS_FUNCTION_STUB_SIZE;
8745 /* The last half word of the stub will be filled with the index
8746 of this symbol in .dynsym section. */
8750 else if ((h->type == STT_FUNC)
8751 && (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) == 0)
8753 /* This will set the entry for this symbol in the GOT to 0, and
8754 the dynamic linker will take care of this. */
8755 h->root.u.def.value = 0;
8759 /* If this is a weak symbol, and there is a real definition, the
8760 processor independent code will have arranged for us to see the
8761 real definition first, and we can just use the same value. */
8762 if (h->weakdef != NULL)
8764 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
8765 || h->weakdef->root.type == bfd_link_hash_defweak);
8766 h->root.u.def.section = h->weakdef->root.u.def.section;
8767 h->root.u.def.value = h->weakdef->root.u.def.value;
8771 /* This is a reference to a symbol defined by a dynamic object which
8772 is not a function. */
8777 /* This function is called after all the input files have been read,
8778 and the input sections have been assigned to output sections. We
8779 check for any mips16 stub sections that we can discard. */
8781 static boolean mips_elf_check_mips16_stubs
8782 PARAMS ((struct mips_elf_link_hash_entry *, PTR));
8785 _bfd_mips_elf_always_size_sections (output_bfd, info)
8787 struct bfd_link_info *info;
8791 /* The .reginfo section has a fixed size. */
8792 ri = bfd_get_section_by_name (output_bfd, ".reginfo");
8794 bfd_set_section_size (output_bfd, ri,
8795 (bfd_size_type) sizeof (Elf32_External_RegInfo));
8797 if (info->relocateable
8798 || ! mips_elf_hash_table (info)->mips16_stubs_seen)
8801 mips_elf_link_hash_traverse (mips_elf_hash_table (info),
8802 mips_elf_check_mips16_stubs,
8808 /* Check the mips16 stubs for a particular symbol, and see if we can
8812 mips_elf_check_mips16_stubs (h, data)
8813 struct mips_elf_link_hash_entry *h;
8814 PTR data ATTRIBUTE_UNUSED;
8816 if (h->root.root.type == bfd_link_hash_warning)
8817 h = (struct mips_elf_link_hash_entry *) h->root.root.u.i.link;
8819 if (h->fn_stub != NULL
8820 && ! h->need_fn_stub)
8822 /* We don't need the fn_stub; the only references to this symbol
8823 are 16 bit calls. Clobber the size to 0 to prevent it from
8824 being included in the link. */
8825 h->fn_stub->_raw_size = 0;
8826 h->fn_stub->_cooked_size = 0;
8827 h->fn_stub->flags &= ~SEC_RELOC;
8828 h->fn_stub->reloc_count = 0;
8829 h->fn_stub->flags |= SEC_EXCLUDE;
8832 if (h->call_stub != NULL
8833 && h->root.other == STO_MIPS16)
8835 /* We don't need the call_stub; this is a 16 bit function, so
8836 calls from other 16 bit functions are OK. Clobber the size
8837 to 0 to prevent it from being included in the link. */
8838 h->call_stub->_raw_size = 0;
8839 h->call_stub->_cooked_size = 0;
8840 h->call_stub->flags &= ~SEC_RELOC;
8841 h->call_stub->reloc_count = 0;
8842 h->call_stub->flags |= SEC_EXCLUDE;
8845 if (h->call_fp_stub != NULL
8846 && h->root.other == STO_MIPS16)
8848 /* We don't need the call_stub; this is a 16 bit function, so
8849 calls from other 16 bit functions are OK. Clobber the size
8850 to 0 to prevent it from being included in the link. */
8851 h->call_fp_stub->_raw_size = 0;
8852 h->call_fp_stub->_cooked_size = 0;
8853 h->call_fp_stub->flags &= ~SEC_RELOC;
8854 h->call_fp_stub->reloc_count = 0;
8855 h->call_fp_stub->flags |= SEC_EXCLUDE;
8861 /* Set the sizes of the dynamic sections. */
8864 _bfd_mips_elf_size_dynamic_sections (output_bfd, info)
8866 struct bfd_link_info *info;
8871 struct mips_got_info *g = NULL;
8873 dynobj = elf_hash_table (info)->dynobj;
8874 BFD_ASSERT (dynobj != NULL);
8876 if (elf_hash_table (info)->dynamic_sections_created)
8878 /* Set the contents of the .interp section to the interpreter. */
8881 s = bfd_get_section_by_name (dynobj, ".interp");
8882 BFD_ASSERT (s != NULL);
8884 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd)) + 1;
8886 = (bfd_byte *) ELF_DYNAMIC_INTERPRETER (output_bfd);
8890 /* The check_relocs and adjust_dynamic_symbol entry points have
8891 determined the sizes of the various dynamic sections. Allocate
8894 for (s = dynobj->sections; s != NULL; s = s->next)
8899 /* It's OK to base decisions on the section name, because none
8900 of the dynobj section names depend upon the input files. */
8901 name = bfd_get_section_name (dynobj, s);
8903 if ((s->flags & SEC_LINKER_CREATED) == 0)
8908 if (strncmp (name, ".rel", 4) == 0)
8910 if (s->_raw_size == 0)
8912 /* We only strip the section if the output section name
8913 has the same name. Otherwise, there might be several
8914 input sections for this output section. FIXME: This
8915 code is probably not needed these days anyhow, since
8916 the linker now does not create empty output sections. */
8917 if (s->output_section != NULL
8919 bfd_get_section_name (s->output_section->owner,
8920 s->output_section)) == 0)
8925 const char *outname;
8928 /* If this relocation section applies to a read only
8929 section, then we probably need a DT_TEXTREL entry.
8930 If the relocation section is .rel.dyn, we always
8931 assert a DT_TEXTREL entry rather than testing whether
8932 there exists a relocation to a read only section or
8934 outname = bfd_get_section_name (output_bfd,
8936 target = bfd_get_section_by_name (output_bfd, outname + 4);
8938 && (target->flags & SEC_READONLY) != 0
8939 && (target->flags & SEC_ALLOC) != 0)
8941 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd)) == 0)
8944 /* We use the reloc_count field as a counter if we need
8945 to copy relocs into the output file. */
8947 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd)) != 0)
8951 else if (strncmp (name, ".got", 4) == 0)
8954 bfd_size_type loadable_size = 0;
8955 bfd_size_type local_gotno;
8958 BFD_ASSERT (elf_section_data (s) != NULL);
8959 g = (struct mips_got_info *) elf_section_data (s)->tdata;
8960 BFD_ASSERT (g != NULL);
8962 /* Calculate the total loadable size of the output. That
8963 will give us the maximum number of GOT_PAGE entries
8965 for (sub = info->input_bfds; sub; sub = sub->link_next)
8967 asection *subsection;
8969 for (subsection = sub->sections;
8971 subsection = subsection->next)
8973 if ((subsection->flags & SEC_ALLOC) == 0)
8975 loadable_size += ((subsection->_raw_size + 0xf)
8976 &~ (bfd_size_type) 0xf);
8979 loadable_size += MIPS_FUNCTION_STUB_SIZE;
8981 /* Assume there are two loadable segments consisting of
8982 contiguous sections. Is 5 enough? */
8983 local_gotno = (loadable_size >> 16) + 5;
8984 if (IRIX_COMPAT (output_bfd) == ict_irix6)
8985 /* It's possible we will need GOT_PAGE entries as well as
8986 GOT16 entries. Often, these will be able to share GOT
8987 entries, but not always. */
8990 g->local_gotno += local_gotno;
8991 s->_raw_size += local_gotno * MIPS_ELF_GOT_SIZE (dynobj);
8993 /* There has to be a global GOT entry for every symbol with
8994 a dynamic symbol table index of DT_MIPS_GOTSYM or
8995 higher. Therefore, it make sense to put those symbols
8996 that need GOT entries at the end of the symbol table. We
8998 if (!mips_elf_sort_hash_table (info, 1))
9001 if (g->global_gotsym != NULL)
9002 i = elf_hash_table (info)->dynsymcount - g->global_gotsym->dynindx;
9004 /* If there are no global symbols, or none requiring
9005 relocations, then GLOBAL_GOTSYM will be NULL. */
9007 g->global_gotno = i;
9008 s->_raw_size += i * MIPS_ELF_GOT_SIZE (dynobj);
9010 else if (strcmp (name, MIPS_ELF_STUB_SECTION_NAME (output_bfd)) == 0)
9012 /* Irix rld assumes that the function stub isn't at the end
9013 of .text section. So put a dummy. XXX */
9014 s->_raw_size += MIPS_FUNCTION_STUB_SIZE;
9016 else if (! info->shared
9017 && ! mips_elf_hash_table (info)->use_rld_obj_head
9018 && strncmp (name, ".rld_map", 8) == 0)
9020 /* We add a room for __rld_map. It will be filled in by the
9021 rtld to contain a pointer to the _r_debug structure. */
9024 else if (SGI_COMPAT (output_bfd)
9025 && strncmp (name, ".compact_rel", 12) == 0)
9026 s->_raw_size += mips_elf_hash_table (info)->compact_rel_size;
9027 else if (strcmp (name, MIPS_ELF_MSYM_SECTION_NAME (output_bfd))
9029 s->_raw_size = (sizeof (Elf32_External_Msym)
9030 * (elf_hash_table (info)->dynsymcount
9031 + bfd_count_sections (output_bfd)));
9032 else if (strncmp (name, ".init", 5) != 0)
9034 /* It's not one of our sections, so don't allocate space. */
9040 _bfd_strip_section_from_output (info, s);
9044 /* Allocate memory for the section contents. */
9045 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
9046 if (s->contents == NULL && s->_raw_size != 0)
9048 bfd_set_error (bfd_error_no_memory);
9053 if (elf_hash_table (info)->dynamic_sections_created)
9055 /* Add some entries to the .dynamic section. We fill in the
9056 values later, in elf_mips_finish_dynamic_sections, but we
9057 must add the entries now so that we get the correct size for
9058 the .dynamic section. The DT_DEBUG entry is filled in by the
9059 dynamic linker and used by the debugger. */
9062 /* SGI object has the equivalence of DT_DEBUG in the
9063 DT_MIPS_RLD_MAP entry. */
9064 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_RLD_MAP, 0))
9066 if (!SGI_COMPAT (output_bfd))
9068 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_DEBUG, 0))
9074 /* Shared libraries on traditional mips have DT_DEBUG. */
9075 if (!SGI_COMPAT (output_bfd))
9077 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_DEBUG, 0))
9082 if (reltext && SGI_COMPAT (output_bfd))
9083 info->flags |= DF_TEXTREL;
9085 if ((info->flags & DF_TEXTREL) != 0)
9087 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_TEXTREL, 0))
9091 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_PLTGOT, 0))
9094 if (bfd_get_section_by_name (dynobj,
9095 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj)))
9097 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_REL, 0))
9100 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_RELSZ, 0))
9103 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_RELENT, 0))
9107 if (SGI_COMPAT (output_bfd))
9109 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_CONFLICTNO, 0))
9113 if (SGI_COMPAT (output_bfd))
9115 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_LIBLISTNO, 0))
9119 if (bfd_get_section_by_name (dynobj, ".conflict") != NULL)
9121 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_CONFLICT, 0))
9124 s = bfd_get_section_by_name (dynobj, ".liblist");
9125 BFD_ASSERT (s != NULL);
9127 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_LIBLIST, 0))
9131 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_RLD_VERSION, 0))
9134 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_FLAGS, 0))
9138 /* Time stamps in executable files are a bad idea. */
9139 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_TIME_STAMP, 0))
9144 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_ICHECKSUM, 0))
9149 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_IVERSION, 0))
9153 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_BASE_ADDRESS, 0))
9156 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_LOCAL_GOTNO, 0))
9159 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_SYMTABNO, 0))
9162 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_UNREFEXTNO, 0))
9165 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_GOTSYM, 0))
9168 if (IRIX_COMPAT (dynobj) == ict_irix5
9169 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_HIPAGENO, 0))
9172 if (IRIX_COMPAT (dynobj) == ict_irix6
9173 && (bfd_get_section_by_name
9174 (dynobj, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj)))
9175 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_OPTIONS, 0))
9178 if (bfd_get_section_by_name (dynobj,
9179 MIPS_ELF_MSYM_SECTION_NAME (dynobj))
9180 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_MSYM, 0))
9187 /* If NAME is one of the special IRIX6 symbols defined by the linker,
9188 adjust it appropriately now. */
9191 mips_elf_irix6_finish_dynamic_symbol (abfd, name, sym)
9192 bfd *abfd ATTRIBUTE_UNUSED;
9194 Elf_Internal_Sym *sym;
9196 /* The linker script takes care of providing names and values for
9197 these, but we must place them into the right sections. */
9198 static const char* const text_section_symbols[] = {
9201 "__dso_displacement",
9203 "__program_header_table",
9207 static const char* const data_section_symbols[] = {
9215 const char* const *p;
9218 for (i = 0; i < 2; ++i)
9219 for (p = (i == 0) ? text_section_symbols : data_section_symbols;
9222 if (strcmp (*p, name) == 0)
9224 /* All of these symbols are given type STT_SECTION by the
9226 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
9228 /* The IRIX linker puts these symbols in special sections. */
9230 sym->st_shndx = SHN_MIPS_TEXT;
9232 sym->st_shndx = SHN_MIPS_DATA;
9238 /* Finish up dynamic symbol handling. We set the contents of various
9239 dynamic sections here. */
9242 _bfd_mips_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
9244 struct bfd_link_info *info;
9245 struct elf_link_hash_entry *h;
9246 Elf_Internal_Sym *sym;
9252 struct mips_got_info *g;
9254 struct mips_elf_link_hash_entry *mh;
9256 dynobj = elf_hash_table (info)->dynobj;
9257 gval = sym->st_value;
9258 mh = (struct mips_elf_link_hash_entry *) h;
9260 if (h->plt.offset != (bfd_vma) -1)
9264 bfd_byte stub[MIPS_FUNCTION_STUB_SIZE];
9266 /* This symbol has a stub. Set it up. */
9268 BFD_ASSERT (h->dynindx != -1);
9270 s = bfd_get_section_by_name (dynobj,
9271 MIPS_ELF_STUB_SECTION_NAME (dynobj));
9272 BFD_ASSERT (s != NULL);
9274 /* Fill the stub. */
9276 bfd_put_32 (output_bfd, (bfd_vma) STUB_LW (output_bfd), p);
9278 bfd_put_32 (output_bfd, (bfd_vma) STUB_MOVE (output_bfd), p);
9281 /* FIXME: Can h->dynindex be more than 64K? */
9282 if (h->dynindx & 0xffff0000)
9285 bfd_put_32 (output_bfd, (bfd_vma) STUB_JALR, p);
9287 bfd_put_32 (output_bfd, (bfd_vma) STUB_LI16 (output_bfd) + h->dynindx, p);
9289 BFD_ASSERT (h->plt.offset <= s->_raw_size);
9290 memcpy (s->contents + h->plt.offset, stub, MIPS_FUNCTION_STUB_SIZE);
9292 /* Mark the symbol as undefined. plt.offset != -1 occurs
9293 only for the referenced symbol. */
9294 sym->st_shndx = SHN_UNDEF;
9296 /* The run-time linker uses the st_value field of the symbol
9297 to reset the global offset table entry for this external
9298 to its stub address when unlinking a shared object. */
9299 gval = s->output_section->vma + s->output_offset + h->plt.offset;
9300 sym->st_value = gval;
9303 BFD_ASSERT (h->dynindx != -1
9304 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0);
9306 sgot = mips_elf_got_section (dynobj);
9307 BFD_ASSERT (sgot != NULL);
9308 BFD_ASSERT (elf_section_data (sgot) != NULL);
9309 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
9310 BFD_ASSERT (g != NULL);
9312 /* Run through the global symbol table, creating GOT entries for all
9313 the symbols that need them. */
9314 if (g->global_gotsym != NULL
9315 && h->dynindx >= g->global_gotsym->dynindx)
9321 value = sym->st_value;
9324 /* For an entity defined in a shared object, this will be
9325 NULL. (For functions in shared objects for
9326 which we have created stubs, ST_VALUE will be non-NULL.
9327 That's because such the functions are now no longer defined
9328 in a shared object.) */
9330 if (info->shared && h->root.type == bfd_link_hash_undefined)
9333 value = h->root.u.def.value;
9335 offset = mips_elf_global_got_index (dynobj, h);
9336 MIPS_ELF_PUT_WORD (output_bfd, value, sgot->contents + offset);
9339 /* Create a .msym entry, if appropriate. */
9340 smsym = bfd_get_section_by_name (dynobj,
9341 MIPS_ELF_MSYM_SECTION_NAME (dynobj));
9344 Elf32_Internal_Msym msym;
9346 msym.ms_hash_value = bfd_elf_hash (h->root.root.string);
9347 /* It is undocumented what the `1' indicates, but IRIX6 uses
9349 msym.ms_info = ELF32_MS_INFO (mh->min_dyn_reloc_index, 1);
9350 bfd_mips_elf_swap_msym_out
9352 ((Elf32_External_Msym *) smsym->contents) + h->dynindx);
9355 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
9356 name = h->root.root.string;
9357 if (strcmp (name, "_DYNAMIC") == 0
9358 || strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
9359 sym->st_shndx = SHN_ABS;
9360 else if (strcmp (name, "_DYNAMIC_LINK") == 0
9361 || strcmp (name, "_DYNAMIC_LINKING") == 0)
9363 sym->st_shndx = SHN_ABS;
9364 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
9367 else if (strcmp (name, "_gp_disp") == 0)
9369 sym->st_shndx = SHN_ABS;
9370 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
9371 sym->st_value = elf_gp (output_bfd);
9373 else if (SGI_COMPAT (output_bfd))
9375 if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0
9376 || strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0)
9378 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
9379 sym->st_other = STO_PROTECTED;
9381 sym->st_shndx = SHN_MIPS_DATA;
9383 else if (strcmp (name, mips_elf_dynsym_rtproc_names[2]) == 0)
9385 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
9386 sym->st_other = STO_PROTECTED;
9387 sym->st_value = mips_elf_hash_table (info)->procedure_count;
9388 sym->st_shndx = SHN_ABS;
9390 else if (sym->st_shndx != SHN_UNDEF && sym->st_shndx != SHN_ABS)
9392 if (h->type == STT_FUNC)
9393 sym->st_shndx = SHN_MIPS_TEXT;
9394 else if (h->type == STT_OBJECT)
9395 sym->st_shndx = SHN_MIPS_DATA;
9399 /* Handle the IRIX6-specific symbols. */
9400 if (IRIX_COMPAT (output_bfd) == ict_irix6)
9401 mips_elf_irix6_finish_dynamic_symbol (output_bfd, name, sym);
9405 if (! mips_elf_hash_table (info)->use_rld_obj_head
9406 && (strcmp (name, "__rld_map") == 0
9407 || strcmp (name, "__RLD_MAP") == 0))
9409 asection *s = bfd_get_section_by_name (dynobj, ".rld_map");
9410 BFD_ASSERT (s != NULL);
9411 sym->st_value = s->output_section->vma + s->output_offset;
9412 bfd_put_32 (output_bfd, (bfd_vma) 0, s->contents);
9413 if (mips_elf_hash_table (info)->rld_value == 0)
9414 mips_elf_hash_table (info)->rld_value = sym->st_value;
9416 else if (mips_elf_hash_table (info)->use_rld_obj_head
9417 && strcmp (name, "__rld_obj_head") == 0)
9419 /* IRIX6 does not use a .rld_map section. */
9420 if (IRIX_COMPAT (output_bfd) == ict_irix5
9421 || IRIX_COMPAT (output_bfd) == ict_none)
9422 BFD_ASSERT (bfd_get_section_by_name (dynobj, ".rld_map")
9424 mips_elf_hash_table (info)->rld_value = sym->st_value;
9428 /* If this is a mips16 symbol, force the value to be even. */
9429 if (sym->st_other == STO_MIPS16
9430 && (sym->st_value & 1) != 0)
9436 /* Finish up the dynamic sections. */
9439 _bfd_mips_elf_finish_dynamic_sections (output_bfd, info)
9441 struct bfd_link_info *info;
9446 struct mips_got_info *g;
9448 dynobj = elf_hash_table (info)->dynobj;
9450 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
9452 sgot = mips_elf_got_section (dynobj);
9457 BFD_ASSERT (elf_section_data (sgot) != NULL);
9458 g = (struct mips_got_info *) elf_section_data (sgot)->tdata;
9459 BFD_ASSERT (g != NULL);
9462 if (elf_hash_table (info)->dynamic_sections_created)
9466 BFD_ASSERT (sdyn != NULL);
9467 BFD_ASSERT (g != NULL);
9469 for (b = sdyn->contents;
9470 b < sdyn->contents + sdyn->_raw_size;
9471 b += MIPS_ELF_DYN_SIZE (dynobj))
9473 Elf_Internal_Dyn dyn;
9479 /* Read in the current dynamic entry. */
9480 (*get_elf_backend_data (dynobj)->s->swap_dyn_in) (dynobj, b, &dyn);
9482 /* Assume that we're going to modify it and write it out. */
9488 s = (bfd_get_section_by_name
9490 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj)));
9491 BFD_ASSERT (s != NULL);
9492 dyn.d_un.d_val = MIPS_ELF_REL_SIZE (dynobj);
9496 /* Rewrite DT_STRSZ. */
9498 _bfd_elf_strtab_size (elf_hash_table (info)->dynstr);
9504 case DT_MIPS_CONFLICT:
9507 case DT_MIPS_LIBLIST:
9510 s = bfd_get_section_by_name (output_bfd, name);
9511 BFD_ASSERT (s != NULL);
9512 dyn.d_un.d_ptr = s->vma;
9515 case DT_MIPS_RLD_VERSION:
9516 dyn.d_un.d_val = 1; /* XXX */
9520 dyn.d_un.d_val = RHF_NOTPOT; /* XXX */
9523 case DT_MIPS_CONFLICTNO:
9525 elemsize = sizeof (Elf32_Conflict);
9528 case DT_MIPS_LIBLISTNO:
9530 elemsize = sizeof (Elf32_Lib);
9532 s = bfd_get_section_by_name (output_bfd, name);
9535 if (s->_cooked_size != 0)
9536 dyn.d_un.d_val = s->_cooked_size / elemsize;
9538 dyn.d_un.d_val = s->_raw_size / elemsize;
9544 case DT_MIPS_TIME_STAMP:
9545 time ((time_t *) &dyn.d_un.d_val);
9548 case DT_MIPS_ICHECKSUM:
9553 case DT_MIPS_IVERSION:
9558 case DT_MIPS_BASE_ADDRESS:
9559 s = output_bfd->sections;
9560 BFD_ASSERT (s != NULL);
9561 dyn.d_un.d_ptr = s->vma & ~(bfd_vma) 0xffff;
9564 case DT_MIPS_LOCAL_GOTNO:
9565 dyn.d_un.d_val = g->local_gotno;
9568 case DT_MIPS_UNREFEXTNO:
9569 /* The index into the dynamic symbol table which is the
9570 entry of the first external symbol that is not
9571 referenced within the same object. */
9572 dyn.d_un.d_val = bfd_count_sections (output_bfd) + 1;
9575 case DT_MIPS_GOTSYM:
9576 if (g->global_gotsym)
9578 dyn.d_un.d_val = g->global_gotsym->dynindx;
9581 /* In case if we don't have global got symbols we default
9582 to setting DT_MIPS_GOTSYM to the same value as
9583 DT_MIPS_SYMTABNO, so we just fall through. */
9585 case DT_MIPS_SYMTABNO:
9587 elemsize = MIPS_ELF_SYM_SIZE (output_bfd);
9588 s = bfd_get_section_by_name (output_bfd, name);
9589 BFD_ASSERT (s != NULL);
9591 if (s->_cooked_size != 0)
9592 dyn.d_un.d_val = s->_cooked_size / elemsize;
9594 dyn.d_un.d_val = s->_raw_size / elemsize;
9597 case DT_MIPS_HIPAGENO:
9598 dyn.d_un.d_val = g->local_gotno - MIPS_RESERVED_GOTNO;
9601 case DT_MIPS_RLD_MAP:
9602 dyn.d_un.d_ptr = mips_elf_hash_table (info)->rld_value;
9605 case DT_MIPS_OPTIONS:
9606 s = (bfd_get_section_by_name
9607 (output_bfd, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd)));
9608 dyn.d_un.d_ptr = s->vma;
9612 s = (bfd_get_section_by_name
9613 (output_bfd, MIPS_ELF_MSYM_SECTION_NAME (output_bfd)));
9614 dyn.d_un.d_ptr = s->vma;
9623 (*get_elf_backend_data (dynobj)->s->swap_dyn_out)
9628 /* The first entry of the global offset table will be filled at
9629 runtime. The second entry will be used by some runtime loaders.
9630 This isn't the case of Irix rld. */
9631 if (sgot != NULL && sgot->_raw_size > 0)
9633 MIPS_ELF_PUT_WORD (output_bfd, (bfd_vma) 0, sgot->contents);
9634 MIPS_ELF_PUT_WORD (output_bfd, (bfd_vma) 0x80000000,
9635 sgot->contents + MIPS_ELF_GOT_SIZE (output_bfd));
9639 elf_section_data (sgot->output_section)->this_hdr.sh_entsize
9640 = MIPS_ELF_GOT_SIZE (output_bfd);
9645 Elf32_compact_rel cpt;
9647 /* ??? The section symbols for the output sections were set up in
9648 _bfd_elf_final_link. SGI sets the STT_NOTYPE attribute for these
9649 symbols. Should we do so? */
9651 smsym = bfd_get_section_by_name (dynobj,
9652 MIPS_ELF_MSYM_SECTION_NAME (dynobj));
9655 Elf32_Internal_Msym msym;
9657 msym.ms_hash_value = 0;
9658 msym.ms_info = ELF32_MS_INFO (0, 1);
9660 for (s = output_bfd->sections; s != NULL; s = s->next)
9662 long dynindx = elf_section_data (s)->dynindx;
9664 bfd_mips_elf_swap_msym_out
9666 (((Elf32_External_Msym *) smsym->contents)
9671 if (SGI_COMPAT (output_bfd))
9673 /* Write .compact_rel section out. */
9674 s = bfd_get_section_by_name (dynobj, ".compact_rel");
9678 cpt.num = s->reloc_count;
9680 cpt.offset = (s->output_section->filepos
9681 + sizeof (Elf32_External_compact_rel));
9684 bfd_elf32_swap_compact_rel_out (output_bfd, &cpt,
9685 ((Elf32_External_compact_rel *)
9688 /* Clean up a dummy stub function entry in .text. */
9689 s = bfd_get_section_by_name (dynobj,
9690 MIPS_ELF_STUB_SECTION_NAME (dynobj));
9693 file_ptr dummy_offset;
9695 BFD_ASSERT (s->_raw_size >= MIPS_FUNCTION_STUB_SIZE);
9696 dummy_offset = s->_raw_size - MIPS_FUNCTION_STUB_SIZE;
9697 memset (s->contents + dummy_offset, 0,
9698 MIPS_FUNCTION_STUB_SIZE);
9703 /* We need to sort the entries of the dynamic relocation section. */
9705 if (!ABI_64_P (output_bfd))
9709 reldyn = bfd_get_section_by_name (dynobj,
9710 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj));
9711 if (reldyn != NULL && reldyn->reloc_count > 2)
9713 reldyn_sorting_bfd = output_bfd;
9714 qsort ((Elf32_External_Rel *) reldyn->contents + 1,
9715 (size_t) reldyn->reloc_count - 1,
9716 sizeof (Elf32_External_Rel), sort_dynamic_relocs);
9720 /* Clean up a first relocation in .rel.dyn. */
9721 s = bfd_get_section_by_name (dynobj,
9722 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj));
9723 if (s != NULL && s->_raw_size > 0)
9724 memset (s->contents, 0, MIPS_ELF_REL_SIZE (dynobj));
9730 /* Support for core dump NOTE sections */
9732 _bfd_elf32_mips_grok_prstatus (abfd, note)
9734 Elf_Internal_Note *note;
9737 unsigned int raw_size;
9739 switch (note->descsz)
9744 case 256: /* Linux/MIPS */
9746 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
9749 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
9758 /* Make a ".reg/999" section. */
9759 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
9760 raw_size, note->descpos + offset);
9764 _bfd_elf32_mips_grok_psinfo (abfd, note)
9766 Elf_Internal_Note *note;
9768 switch (note->descsz)
9773 case 128: /* Linux/MIPS elf_prpsinfo */
9774 elf_tdata (abfd)->core_program
9775 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
9776 elf_tdata (abfd)->core_command
9777 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
9780 /* Note that for some reason, a spurious space is tacked
9781 onto the end of the args in some (at least one anyway)
9782 implementations, so strip it off if it exists. */
9785 char *command = elf_tdata (abfd)->core_command;
9786 int n = strlen (command);
9788 if (0 < n && command[n - 1] == ' ')
9789 command[n - 1] = '\0';
9798 _bfd_elf32_mips_discard_info (abfd, cookie, info)
9800 struct elf_reloc_cookie *cookie;
9801 struct bfd_link_info *info;
9804 struct elf_backend_data *bed = get_elf_backend_data (abfd);
9805 boolean ret = false;
9806 unsigned char *tdata;
9809 o = bfd_get_section_by_name (abfd, ".pdr");
9812 if (o->_raw_size == 0)
9814 if (o->_raw_size % PDR_SIZE != 0)
9816 if (o->output_section != NULL
9817 && bfd_is_abs_section (o->output_section))
9820 tdata = bfd_zmalloc (o->_raw_size / PDR_SIZE);
9824 cookie->rels = _bfd_elf32_link_read_relocs (abfd, o, (PTR) NULL,
9825 (Elf_Internal_Rela *) NULL,
9833 cookie->rel = cookie->rels;
9835 cookie->rels + o->reloc_count * bed->s->int_rels_per_ext_rel;
9837 for (i = 0, skip = 0; i < o->_raw_size; i ++)
9839 if (_bfd_elf32_reloc_symbol_deleted_p (i * PDR_SIZE, cookie))
9848 elf_section_data (o)->tdata = tdata;
9849 o->_cooked_size = o->_raw_size - skip * PDR_SIZE;
9855 if (! info->keep_memory)
9856 free (cookie->rels);
9862 _bfd_elf32_mips_ignore_discarded_relocs (sec)
9865 if (strcmp (sec->name, ".pdr") == 0)
9871 _bfd_elf32_mips_write_section (output_bfd, sec, contents)
9876 bfd_byte *to, *from, *end;
9879 if (strcmp (sec->name, ".pdr") != 0)
9882 if (elf_section_data (sec)->tdata == NULL)
9886 end = contents + sec->_raw_size;
9887 for (from = contents, i = 0;
9889 from += PDR_SIZE, i++)
9891 if (((unsigned char *)elf_section_data (sec)->tdata)[i] == 1)
9894 memcpy (to, from, PDR_SIZE);
9897 bfd_set_section_contents (output_bfd, sec->output_section, contents,
9898 (file_ptr) sec->output_offset,
9903 /* Given a data section and an in-memory embedded reloc section, store
9904 relocation information into the embedded reloc section which can be
9905 used at runtime to relocate the data section. This is called by the
9906 linker when the --embedded-relocs switch is used. This is called
9907 after the add_symbols entry point has been called for all the
9908 objects, and before the final_link entry point is called. */
9911 bfd_mips_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
9913 struct bfd_link_info *info;
9918 Elf_Internal_Shdr *symtab_hdr;
9919 Elf_Internal_Shdr *shndx_hdr;
9920 Elf32_External_Sym *extsyms;
9921 Elf32_External_Sym *free_extsyms = NULL;
9922 Elf_External_Sym_Shndx *shndx_buf = NULL;
9923 Elf_Internal_Rela *internal_relocs;
9924 Elf_Internal_Rela *free_relocs = NULL;
9925 Elf_Internal_Rela *irel, *irelend;
9929 BFD_ASSERT (! info->relocateable);
9933 if (datasec->reloc_count == 0)
9936 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
9937 /* Read this BFD's symbols if we haven't done so already, or get the cached
9938 copy if it exists. */
9939 if (symtab_hdr->contents != NULL)
9940 extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
9943 /* Go get them off disk. */
9944 if (info->keep_memory)
9945 extsyms = ((Elf32_External_Sym *)
9946 bfd_alloc (abfd, symtab_hdr->sh_size));
9948 extsyms = ((Elf32_External_Sym *)
9949 bfd_malloc (symtab_hdr->sh_size));
9950 if (extsyms == NULL)
9952 if (! info->keep_memory)
9953 free_extsyms = extsyms;
9954 if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0
9955 || (bfd_bread (extsyms, symtab_hdr->sh_size, abfd)
9956 != symtab_hdr->sh_size))
9958 if (info->keep_memory)
9959 symtab_hdr->contents = (unsigned char *) extsyms;
9962 shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
9963 if (shndx_hdr->sh_size != 0)
9965 amt = symtab_hdr->sh_info * sizeof (Elf_External_Sym_Shndx);
9966 shndx_buf = (Elf_External_Sym_Shndx *) bfd_malloc (amt);
9967 if (shndx_buf == NULL)
9969 if (bfd_seek (abfd, shndx_hdr->sh_offset, SEEK_SET) != 0
9970 || bfd_bread ((PTR) shndx_buf, amt, abfd) != amt)
9974 /* Get a copy of the native relocations. */
9975 internal_relocs = (_bfd_elf32_link_read_relocs
9976 (abfd, datasec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
9977 info->keep_memory));
9978 if (internal_relocs == NULL)
9980 if (! info->keep_memory)
9981 free_relocs = internal_relocs;
9983 relsec->contents = (bfd_byte *) bfd_alloc (abfd, datasec->reloc_count * 12);
9984 if (relsec->contents == NULL)
9987 p = relsec->contents;
9989 irelend = internal_relocs + datasec->reloc_count;
9991 for (irel = internal_relocs; irel < irelend; irel++, p += 12)
9993 asection *targetsec;
9995 /* We are going to write a four byte longword into the runtime
9996 reloc section. The longword will be the address in the data
9997 section which must be relocated. It is followed by the name
9998 of the target section NUL-padded or truncated to 8
10001 /* We can only relocate absolute longword relocs at run time. */
10002 if ((ELF32_R_TYPE (irel->r_info) != (int) R_MIPS_32) &&
10003 (ELF32_R_TYPE (irel->r_info) != (int) R_MIPS_64))
10005 *errmsg = _("unsupported reloc type");
10006 bfd_set_error (bfd_error_bad_value);
10009 /* Get the target section referred to by the reloc. */
10010 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
10012 Elf32_External_Sym *esym;
10013 Elf_External_Sym_Shndx *shndx;
10014 Elf_Internal_Sym isym;
10016 /* A local symbol. */
10017 esym = extsyms + ELF32_R_SYM (irel->r_info);
10018 shndx = shndx_buf + (shndx_buf ? ELF32_R_SYM (irel->r_info) : 0);
10019 bfd_elf32_swap_symbol_in (abfd, esym, shndx, &isym);
10021 targetsec = bfd_section_from_elf_index (abfd, isym.st_shndx);
10025 unsigned long indx;
10026 struct elf_link_hash_entry *h;
10028 /* An external symbol. */
10029 indx = ELF32_R_SYM (irel->r_info);
10030 h = elf_sym_hashes (abfd)[indx];
10033 * For some reason, in certain programs, the symbol will
10034 * not be in the hash table. It seems to happen when you
10035 * declare a static table of pointers to const external structures.
10036 * In this case, the relocs are relative to data, not
10037 * text, so just treating it like an undefined link
10038 * should be sufficient.
10040 BFD_ASSERT(h != NULL);
10041 if (h->root.type == bfd_link_hash_defined
10042 || h->root.type == bfd_link_hash_defweak)
10043 targetsec = h->root.u.def.section;
10048 * Set the low bit of the relocation offset if it's a MIPS64 reloc.
10049 * Relocations will always be on (at least) 32-bit boundaries.
10052 bfd_put_32 (abfd, ((irel->r_offset + datasec->output_offset) +
10053 ((ELF32_R_TYPE (irel->r_info) == (int) R_MIPS_64) ? 1 : 0)),
10055 memset (p + 4, 0, 8);
10056 if (targetsec != NULL)
10057 strncpy (p + 4, targetsec->output_section->name, 8);
10060 if (shndx_buf != NULL)
10062 if (free_extsyms != NULL)
10063 free (free_extsyms);
10064 if (free_relocs != NULL)
10065 free (free_relocs);
10069 if (shndx_buf != NULL)
10071 if (free_extsyms != NULL)
10072 free (free_extsyms);
10073 if (free_relocs != NULL)
10074 free (free_relocs);
10078 /* This is almost identical to bfd_generic_get_... except that some
10079 MIPS relocations need to be handled specially. Sigh. */
10082 elf32_mips_get_relocated_section_contents (abfd, link_info, link_order, data,
10083 relocateable, symbols)
10085 struct bfd_link_info *link_info;
10086 struct bfd_link_order *link_order;
10088 boolean relocateable;
10091 /* Get enough memory to hold the stuff */
10092 bfd *input_bfd = link_order->u.indirect.section->owner;
10093 asection *input_section = link_order->u.indirect.section;
10095 long reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section);
10096 arelent **reloc_vector = NULL;
10099 if (reloc_size < 0)
10102 reloc_vector = (arelent **) bfd_malloc ((bfd_size_type) reloc_size);
10103 if (reloc_vector == NULL && reloc_size != 0)
10106 /* read in the section */
10107 if (!bfd_get_section_contents (input_bfd,
10111 input_section->_raw_size))
10114 /* We're not relaxing the section, so just copy the size info */
10115 input_section->_cooked_size = input_section->_raw_size;
10116 input_section->reloc_done = true;
10118 reloc_count = bfd_canonicalize_reloc (input_bfd,
10122 if (reloc_count < 0)
10125 if (reloc_count > 0)
10130 bfd_vma gp = 0x12345678; /* initialize just to shut gcc up */
10133 struct bfd_hash_entry *h;
10134 struct bfd_link_hash_entry *lh;
10135 /* Skip all this stuff if we aren't mixing formats. */
10136 if (abfd && input_bfd
10137 && abfd->xvec == input_bfd->xvec)
10141 h = bfd_hash_lookup (&link_info->hash->table, "_gp", false, false);
10142 lh = (struct bfd_link_hash_entry *) h;
10149 case bfd_link_hash_undefined:
10150 case bfd_link_hash_undefweak:
10151 case bfd_link_hash_common:
10154 case bfd_link_hash_defined:
10155 case bfd_link_hash_defweak:
10157 gp = lh->u.def.value;
10159 case bfd_link_hash_indirect:
10160 case bfd_link_hash_warning:
10162 /* @@FIXME ignoring warning for now */
10164 case bfd_link_hash_new:
10173 for (parent = reloc_vector; *parent != (arelent *) NULL;
10176 char *error_message = (char *) NULL;
10177 bfd_reloc_status_type r;
10179 /* Specific to MIPS: Deal with relocation types that require
10180 knowing the gp of the output bfd. */
10181 asymbol *sym = *(*parent)->sym_ptr_ptr;
10182 if (bfd_is_abs_section (sym->section) && abfd)
10184 /* The special_function wouldn't get called anyways. */
10186 else if (!gp_found)
10188 /* The gp isn't there; let the special function code
10189 fall over on its own. */
10191 else if ((*parent)->howto->special_function
10192 == _bfd_mips_elf_gprel16_reloc)
10194 /* bypass special_function call */
10195 r = gprel16_with_gp (input_bfd, sym, *parent, input_section,
10196 relocateable, (PTR) data, gp);
10197 goto skip_bfd_perform_relocation;
10199 /* end mips specific stuff */
10201 r = bfd_perform_relocation (input_bfd,
10205 relocateable ? abfd : (bfd *) NULL,
10207 skip_bfd_perform_relocation:
10211 asection *os = input_section->output_section;
10213 /* A partial link, so keep the relocs */
10214 os->orelocation[os->reloc_count] = *parent;
10218 if (r != bfd_reloc_ok)
10222 case bfd_reloc_undefined:
10223 if (!((*link_info->callbacks->undefined_symbol)
10224 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
10225 input_bfd, input_section, (*parent)->address,
10229 case bfd_reloc_dangerous:
10230 BFD_ASSERT (error_message != (char *) NULL);
10231 if (!((*link_info->callbacks->reloc_dangerous)
10232 (link_info, error_message, input_bfd, input_section,
10233 (*parent)->address)))
10236 case bfd_reloc_overflow:
10237 if (!((*link_info->callbacks->reloc_overflow)
10238 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
10239 (*parent)->howto->name, (*parent)->addend,
10240 input_bfd, input_section, (*parent)->address)))
10243 case bfd_reloc_outofrange:
10252 if (reloc_vector != NULL)
10253 free (reloc_vector);
10257 if (reloc_vector != NULL)
10258 free (reloc_vector);
10262 #define bfd_elf32_bfd_get_relocated_section_contents \
10263 elf32_mips_get_relocated_section_contents
10265 /* ECOFF swapping routines. These are used when dealing with the
10266 .mdebug section, which is in the ECOFF debugging format. */
10267 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = {
10268 /* Symbol table magic number. */
10270 /* Alignment of debugging information. E.g., 4. */
10272 /* Sizes of external symbolic information. */
10273 sizeof (struct hdr_ext),
10274 sizeof (struct dnr_ext),
10275 sizeof (struct pdr_ext),
10276 sizeof (struct sym_ext),
10277 sizeof (struct opt_ext),
10278 sizeof (struct fdr_ext),
10279 sizeof (struct rfd_ext),
10280 sizeof (struct ext_ext),
10281 /* Functions to swap in external symbolic data. */
10290 _bfd_ecoff_swap_tir_in,
10291 _bfd_ecoff_swap_rndx_in,
10292 /* Functions to swap out external symbolic data. */
10293 ecoff_swap_hdr_out,
10294 ecoff_swap_dnr_out,
10295 ecoff_swap_pdr_out,
10296 ecoff_swap_sym_out,
10297 ecoff_swap_opt_out,
10298 ecoff_swap_fdr_out,
10299 ecoff_swap_rfd_out,
10300 ecoff_swap_ext_out,
10301 _bfd_ecoff_swap_tir_out,
10302 _bfd_ecoff_swap_rndx_out,
10303 /* Function to read in symbolic data. */
10304 _bfd_mips_elf_read_ecoff_info
10307 #define ELF_ARCH bfd_arch_mips
10308 #define ELF_MACHINE_CODE EM_MIPS
10310 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
10311 a value of 0x1000, and we are compatible. */
10312 #define ELF_MAXPAGESIZE 0x1000
10314 #define elf_backend_collect true
10315 #define elf_backend_type_change_ok true
10316 #define elf_backend_can_gc_sections true
10317 #define elf_info_to_howto mips_info_to_howto_rela
10318 #define elf_info_to_howto_rel mips_info_to_howto_rel
10319 #define elf_backend_sym_is_global mips_elf_sym_is_global
10320 #define elf_backend_object_p _bfd_mips_elf_object_p
10321 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
10322 #define elf_backend_section_processing _bfd_mips_elf_section_processing
10323 #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
10324 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
10325 #define elf_backend_section_from_bfd_section \
10326 _bfd_mips_elf_section_from_bfd_section
10327 #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
10328 #define elf_backend_link_output_symbol_hook \
10329 _bfd_mips_elf_link_output_symbol_hook
10330 #define elf_backend_create_dynamic_sections \
10331 _bfd_mips_elf_create_dynamic_sections
10332 #define elf_backend_check_relocs _bfd_mips_elf_check_relocs
10333 #define elf_backend_adjust_dynamic_symbol \
10334 _bfd_mips_elf_adjust_dynamic_symbol
10335 #define elf_backend_always_size_sections \
10336 _bfd_mips_elf_always_size_sections
10337 #define elf_backend_size_dynamic_sections \
10338 _bfd_mips_elf_size_dynamic_sections
10339 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section
10340 #define elf_backend_finish_dynamic_symbol \
10341 _bfd_mips_elf_finish_dynamic_symbol
10342 #define elf_backend_finish_dynamic_sections \
10343 _bfd_mips_elf_finish_dynamic_sections
10344 #define elf_backend_final_write_processing \
10345 _bfd_mips_elf_final_write_processing
10346 #define elf_backend_additional_program_headers \
10347 _bfd_mips_elf_additional_program_headers
10348 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
10349 #define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
10350 #define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
10351 #define elf_backend_copy_indirect_symbol \
10352 _bfd_mips_elf_copy_indirect_symbol
10353 #define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
10354 #define elf_backend_grok_prstatus _bfd_elf32_mips_grok_prstatus
10355 #define elf_backend_grok_psinfo _bfd_elf32_mips_grok_psinfo
10356 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
10358 #define elf_backend_got_header_size (4 * MIPS_RESERVED_GOTNO)
10359 #define elf_backend_plt_header_size 0
10360 #define elf_backend_may_use_rel_p 1
10361 #define elf_backend_may_use_rela_p 0
10362 #define elf_backend_default_use_rela_p 0
10363 #define elf_backend_sign_extend_vma true
10365 #define elf_backend_discard_info _bfd_elf32_mips_discard_info
10366 #define elf_backend_ignore_discarded_relocs \
10367 _bfd_elf32_mips_ignore_discarded_relocs
10368 #define elf_backend_write_section _bfd_elf32_mips_write_section
10370 #define bfd_elf32_bfd_is_local_label_name \
10371 mips_elf_is_local_label_name
10372 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
10373 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
10374 #define bfd_elf32_bfd_link_hash_table_create \
10375 _bfd_mips_elf_link_hash_table_create
10376 #define bfd_elf32_bfd_final_link _bfd_mips_elf_final_link
10377 #define bfd_elf32_bfd_merge_private_bfd_data \
10378 _bfd_mips_elf_merge_private_bfd_data
10379 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
10380 #define bfd_elf32_bfd_print_private_bfd_data \
10381 _bfd_mips_elf_print_private_bfd_data
10383 /* Support for SGI-ish mips targets. */
10384 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
10385 #define TARGET_LITTLE_NAME "elf32-littlemips"
10386 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
10387 #define TARGET_BIG_NAME "elf32-bigmips"
10389 #include "elf32-target.h"
10391 /* Support for traditional mips targets. */
10392 #define INCLUDED_TARGET_FILE /* More a type of flag. */
10394 #undef TARGET_LITTLE_SYM
10395 #undef TARGET_LITTLE_NAME
10396 #undef TARGET_BIG_SYM
10397 #undef TARGET_BIG_NAME
10399 #define TARGET_LITTLE_SYM bfd_elf32_tradlittlemips_vec
10400 #define TARGET_LITTLE_NAME "elf32-tradlittlemips"
10401 #define TARGET_BIG_SYM bfd_elf32_tradbigmips_vec
10402 #define TARGET_BIG_NAME "elf32-tradbigmips"
10404 /* Include the target file again for this target */
10405 #include "elf32-target.h"