1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 Most of the information added by Ian Lance Taylor, Cygnus Support,
7 N32/64 ABI support added by Mark Mitchell, CodeSourcery, LLC.
8 <mark@codesourcery.com>
9 Traditional MIPS targets support added by Koundinya.K, Dansk Data
10 Elektronik & Operations Research Group. <kk@ddeorg.soft.net>
12 This file is part of BFD, the Binary File Descriptor library.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 /* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
29 different MIPS ELF from other targets. This matters when linking.
30 This file supports both, switching at runtime. */
40 /* Get the ECOFF swapping routines. */
42 #include "coff/symconst.h"
43 #include "coff/internal.h"
44 #include "coff/ecoff.h"
45 #include "coff/mips.h"
46 #define ECOFF_SIGNED_32
47 #include "ecoffswap.h"
49 /* This structure is used to hold .got information when linking. It
50 is stored in the tdata field of the bfd_elf_section_data structure. */
54 /* The global symbol in the GOT with the lowest index in the dynamic
56 struct elf_link_hash_entry
*global_gotsym
;
57 /* The number of global .got entries. */
58 unsigned int global_gotno
;
59 /* The number of local .got entries. */
60 unsigned int local_gotno
;
61 /* The number of local .got entries we have used. */
62 unsigned int assigned_gotno
;
65 /* The MIPS ELF linker needs additional information for each symbol in
66 the global hash table. */
68 struct mips_elf_link_hash_entry
70 struct elf_link_hash_entry root
;
72 /* External symbol information. */
75 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
77 unsigned int possibly_dynamic_relocs
;
79 /* If the R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 reloc is against
80 a readonly section. */
81 boolean readonly_reloc
;
83 /* The index of the first dynamic relocation (in the .rel.dyn
84 section) against this symbol. */
85 unsigned int min_dyn_reloc_index
;
87 /* We must not create a stub for a symbol that has relocations
88 related to taking the function's address, i.e. any but
89 R_MIPS_CALL*16 ones -- see "MIPS ABI Supplement, 3rd Edition",
93 /* If there is a stub that 32 bit functions should use to call this
94 16 bit function, this points to the section containing the stub. */
97 /* Whether we need the fn_stub; this is set if this symbol appears
98 in any relocs other than a 16 bit call. */
101 /* If there is a stub that 16 bit functions should use to call this
102 32 bit function, this points to the section containing the stub. */
105 /* This is like the call_stub field, but it is used if the function
106 being called returns a floating point value. */
107 asection
*call_fp_stub
;
110 static bfd_reloc_status_type mips32_64bit_reloc
111 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
112 static reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
113 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
114 static reloc_howto_type
*mips_rtype_to_howto
115 PARAMS ((unsigned int));
116 static void mips_info_to_howto_rel
117 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
118 static void mips_info_to_howto_rela
119 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rela
*));
120 static void bfd_mips_elf32_swap_gptab_in
121 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
122 static void bfd_mips_elf32_swap_gptab_out
123 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
125 static void bfd_mips_elf_swap_msym_in
126 PARAMS ((bfd
*, const Elf32_External_Msym
*, Elf32_Internal_Msym
*));
128 static void bfd_mips_elf_swap_msym_out
129 PARAMS ((bfd
*, const Elf32_Internal_Msym
*, Elf32_External_Msym
*));
130 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
131 static boolean mips_elf_create_procedure_table
132 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
133 struct ecoff_debug_info
*));
134 static INLINE
int elf_mips_isa
PARAMS ((flagword
));
135 static INLINE
unsigned long elf_mips_mach
PARAMS ((flagword
));
136 static INLINE
char* elf_mips_abi_name
PARAMS ((bfd
*));
137 static boolean mips_elf_is_local_label_name
138 PARAMS ((bfd
*, const char *));
139 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
140 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
141 static int gptab_compare
PARAMS ((const void *, const void *));
142 static bfd_reloc_status_type mips16_jump_reloc
143 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
144 static bfd_reloc_status_type mips16_gprel_reloc
145 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
146 static boolean mips_elf_create_compact_rel_section
147 PARAMS ((bfd
*, struct bfd_link_info
*));
148 static boolean mips_elf_create_got_section
149 PARAMS ((bfd
*, struct bfd_link_info
*));
150 static bfd_reloc_status_type mips_elf_final_gp
151 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
152 static bfd_byte
*elf32_mips_get_relocated_section_contents
153 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
154 bfd_byte
*, boolean
, asymbol
**));
155 static asection
*mips_elf_create_msym_section
157 static void mips_elf_irix6_finish_dynamic_symbol
158 PARAMS ((bfd
*, const char *, Elf_Internal_Sym
*));
159 static bfd_vma mips_elf_sign_extend
PARAMS ((bfd_vma
, int));
160 static boolean mips_elf_overflow_p
PARAMS ((bfd_vma
, int));
161 static bfd_vma mips_elf_high
PARAMS ((bfd_vma
));
162 static bfd_vma mips_elf_higher
PARAMS ((bfd_vma
));
163 static bfd_vma mips_elf_highest
PARAMS ((bfd_vma
));
164 static bfd_vma mips_elf_global_got_index
165 PARAMS ((bfd
*, struct elf_link_hash_entry
*));
166 static bfd_vma mips_elf_local_got_index
167 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
));
168 static bfd_vma mips_elf_got_offset_from_index
169 PARAMS ((bfd
*, bfd
*, bfd_vma
));
170 static boolean mips_elf_record_global_got_symbol
171 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*,
172 struct mips_got_info
*));
173 static bfd_vma mips_elf_got_page
174 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
, bfd_vma
*));
175 static const Elf_Internal_Rela
*mips_elf_next_relocation
176 PARAMS ((unsigned int, const Elf_Internal_Rela
*,
177 const Elf_Internal_Rela
*));
178 static bfd_reloc_status_type mips_elf_calculate_relocation
179 PARAMS ((bfd
*, bfd
*, asection
*, struct bfd_link_info
*,
180 const Elf_Internal_Rela
*, bfd_vma
, reloc_howto_type
*,
181 Elf_Internal_Sym
*, asection
**, bfd_vma
*, const char **,
183 static bfd_vma mips_elf_obtain_contents
184 PARAMS ((reloc_howto_type
*, const Elf_Internal_Rela
*, bfd
*, bfd_byte
*));
185 static boolean mips_elf_perform_relocation
186 PARAMS ((struct bfd_link_info
*, reloc_howto_type
*,
187 const Elf_Internal_Rela
*, bfd_vma
,
188 bfd
*, asection
*, bfd_byte
*, boolean
));
189 static boolean mips_elf_assign_gp
PARAMS ((bfd
*, bfd_vma
*));
190 static boolean mips_elf_sort_hash_table_f
191 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
192 static boolean mips_elf_sort_hash_table
193 PARAMS ((struct bfd_link_info
*, unsigned long));
194 static asection
* mips_elf_got_section
PARAMS ((bfd
*));
195 static struct mips_got_info
*mips_elf_got_info
196 PARAMS ((bfd
*, asection
**));
197 static boolean mips_elf_local_relocation_p
198 PARAMS ((bfd
*, const Elf_Internal_Rela
*, asection
**, boolean
));
199 static bfd_vma mips_elf_create_local_got_entry
200 PARAMS ((bfd
*, struct mips_got_info
*, asection
*, bfd_vma
));
201 static bfd_vma mips_elf_got16_entry
202 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
, boolean
));
203 static boolean mips_elf_create_dynamic_relocation
204 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
205 struct mips_elf_link_hash_entry
*, asection
*,
206 bfd_vma
, bfd_vma
*, asection
*));
207 static void mips_elf_allocate_dynamic_relocations
208 PARAMS ((bfd
*, unsigned int));
209 static boolean mips_elf_stub_section_p
210 PARAMS ((bfd
*, asection
*));
211 static int sort_dynamic_relocs
212 PARAMS ((const void *, const void *));
213 static void _bfd_mips_elf_hide_symbol
214 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
215 static void _bfd_mips_elf_copy_indirect_symbol
216 PARAMS ((struct elf_link_hash_entry
*,
217 struct elf_link_hash_entry
*));
218 static boolean _bfd_elf32_mips_grok_prstatus
219 PARAMS ((bfd
*, Elf_Internal_Note
*));
220 static boolean _bfd_elf32_mips_grok_psinfo
221 PARAMS ((bfd
*, Elf_Internal_Note
*));
222 static boolean _bfd_elf32_mips_discard_info
223 PARAMS ((bfd
*, struct elf_reloc_cookie
*, struct bfd_link_info
*));
224 static boolean _bfd_elf32_mips_ignore_discarded_relocs
225 PARAMS ((asection
*));
226 static boolean _bfd_elf32_mips_write_section
227 PARAMS ((bfd
*, asection
*, bfd_byte
*));
229 extern const bfd_target bfd_elf32_tradbigmips_vec
;
230 extern const bfd_target bfd_elf32_tradlittlemips_vec
;
232 extern const bfd_target bfd_elf64_tradbigmips_vec
;
233 extern const bfd_target bfd_elf64_tradlittlemips_vec
;
236 /* The level of IRIX compatibility we're striving for. */
244 /* This will be used when we sort the dynamic relocation records. */
245 static bfd
*reldyn_sorting_bfd
;
247 /* Nonzero if ABFD is using the N32 ABI. */
249 #define ABI_N32_P(abfd) \
250 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
252 /* Nonzero if ABFD is using the 64-bit ABI. */
253 #define ABI_64_P(abfd) \
254 ((elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS64) != 0)
256 /* Depending on the target vector we generate some version of Irix
257 executables or "normal" MIPS ELF ABI executables. */
259 #define IRIX_COMPAT(abfd) \
260 (((abfd->xvec == &bfd_elf64_tradbigmips_vec) || \
261 (abfd->xvec == &bfd_elf64_tradlittlemips_vec) || \
262 (abfd->xvec == &bfd_elf32_tradbigmips_vec) || \
263 (abfd->xvec == &bfd_elf32_tradlittlemips_vec)) ? ict_none : \
264 ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5))
266 #define IRIX_COMPAT(abfd) \
267 (((abfd->xvec == &bfd_elf32_tradbigmips_vec) || \
268 (abfd->xvec == &bfd_elf32_tradlittlemips_vec)) ? ict_none : \
269 ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5))
272 #define NEWABI_P(abfd) (ABI_N32_P(abfd) || ABI_64_P(abfd))
274 /* Whether we are trying to be compatible with IRIX at all. */
275 #define SGI_COMPAT(abfd) \
276 (IRIX_COMPAT (abfd) != ict_none)
278 /* The name of the msym section. */
279 #define MIPS_ELF_MSYM_SECTION_NAME(abfd) ".msym"
281 /* The name of the srdata section. */
282 #define MIPS_ELF_SRDATA_SECTION_NAME(abfd) ".srdata"
284 /* The name of the options section. */
285 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
286 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.options" : ".options")
288 /* The name of the stub section. */
289 #define MIPS_ELF_STUB_SECTION_NAME(abfd) \
290 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.stubs" : ".stub")
292 /* The name of the dynamic relocation section. */
293 #define MIPS_ELF_REL_DYN_SECTION_NAME(abfd) ".rel.dyn"
295 /* The size of an external REL relocation. */
296 #define MIPS_ELF_REL_SIZE(abfd) \
297 (get_elf_backend_data (abfd)->s->sizeof_rel)
299 /* The size of an external dynamic table entry. */
300 #define MIPS_ELF_DYN_SIZE(abfd) \
301 (get_elf_backend_data (abfd)->s->sizeof_dyn)
303 /* The size of a GOT entry. */
304 #define MIPS_ELF_GOT_SIZE(abfd) \
305 (get_elf_backend_data (abfd)->s->arch_size / 8)
307 /* The size of a symbol-table entry. */
308 #define MIPS_ELF_SYM_SIZE(abfd) \
309 (get_elf_backend_data (abfd)->s->sizeof_sym)
311 /* The default alignment for sections, as a power of two. */
312 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
313 (get_elf_backend_data (abfd)->s->file_align == 8 ? 3 : 2)
315 /* Get word-sized data. */
316 #define MIPS_ELF_GET_WORD(abfd, ptr) \
317 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
319 /* Put out word-sized data. */
320 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
322 ? bfd_put_64 (abfd, val, ptr) \
323 : bfd_put_32 (abfd, val, ptr))
325 /* Add a dynamic symbol table-entry. */
327 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
328 (ABI_64_P (elf_hash_table (info)->dynobj) \
329 ? bfd_elf64_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val) \
330 : bfd_elf32_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
332 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
333 (ABI_64_P (elf_hash_table (info)->dynobj) \
334 ? (boolean) (abort (), false) \
335 : bfd_elf32_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
338 /* The number of local .got entries we reserve. */
339 #define MIPS_RESERVED_GOTNO (2)
341 /* Instructions which appear in a stub. For some reason the stub is
342 slightly different on an SGI system. */
343 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
344 #define STUB_LW(abfd) \
347 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
348 : 0x8f998010) /* lw t9,0x8010(gp) */ \
349 : 0x8f998010) /* lw t9,0x8000(gp) */
350 #define STUB_MOVE(abfd) \
351 (SGI_COMPAT (abfd) ? 0x03e07825 : 0x03e07821) /* move t7,ra */
352 #define STUB_JALR 0x0320f809 /* jal t9 */
353 #define STUB_LI16(abfd) \
354 (SGI_COMPAT (abfd) ? 0x34180000 : 0x24180000) /* ori t8,zero,0 */
355 #define MIPS_FUNCTION_STUB_SIZE (16)
358 /* We no longer try to identify particular sections for the .dynsym
359 section. When we do, we wind up crashing if there are other random
360 sections with relocations. */
362 /* Names of sections which appear in the .dynsym section in an Irix 5
365 static const char * const mips_elf_dynsym_sec_names
[] =
378 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
379 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
381 /* The number of entries in mips_elf_dynsym_sec_names which go in the
384 #define MIPS_TEXT_DYNSYM_SECNO (3)
388 /* The names of the runtime procedure table symbols used on Irix 5. */
390 static const char * const mips_elf_dynsym_rtproc_names
[] =
393 "_procedure_string_table",
394 "_procedure_table_size",
398 /* These structures are used to generate the .compact_rel section on
403 unsigned long id1
; /* Always one? */
404 unsigned long num
; /* Number of compact relocation entries. */
405 unsigned long id2
; /* Always two? */
406 unsigned long offset
; /* The file offset of the first relocation. */
407 unsigned long reserved0
; /* Zero? */
408 unsigned long reserved1
; /* Zero? */
417 bfd_byte reserved0
[4];
418 bfd_byte reserved1
[4];
419 } Elf32_External_compact_rel
;
423 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
424 unsigned int rtype
: 4; /* Relocation types. See below. */
425 unsigned int dist2to
: 8;
426 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
427 unsigned long konst
; /* KONST field. See below. */
428 unsigned long vaddr
; /* VADDR to be relocated. */
433 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
434 unsigned int rtype
: 4; /* Relocation types. See below. */
435 unsigned int dist2to
: 8;
436 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
437 unsigned long konst
; /* KONST field. See below. */
445 } Elf32_External_crinfo
;
451 } Elf32_External_crinfo2
;
453 /* These are the constants used to swap the bitfields in a crinfo. */
455 #define CRINFO_CTYPE (0x1)
456 #define CRINFO_CTYPE_SH (31)
457 #define CRINFO_RTYPE (0xf)
458 #define CRINFO_RTYPE_SH (27)
459 #define CRINFO_DIST2TO (0xff)
460 #define CRINFO_DIST2TO_SH (19)
461 #define CRINFO_RELVADDR (0x7ffff)
462 #define CRINFO_RELVADDR_SH (0)
464 /* A compact relocation info has long (3 words) or short (2 words)
465 formats. A short format doesn't have VADDR field and relvaddr
466 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
467 #define CRF_MIPS_LONG 1
468 #define CRF_MIPS_SHORT 0
470 /* There are 4 types of compact relocation at least. The value KONST
471 has different meaning for each type:
474 CT_MIPS_REL32 Address in data
475 CT_MIPS_WORD Address in word (XXX)
476 CT_MIPS_GPHI_LO GP - vaddr
477 CT_MIPS_JMPAD Address to jump
480 #define CRT_MIPS_REL32 0xa
481 #define CRT_MIPS_WORD 0xb
482 #define CRT_MIPS_GPHI_LO 0xc
483 #define CRT_MIPS_JMPAD 0xd
485 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
486 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
487 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
488 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
490 static void bfd_elf32_swap_compact_rel_out
491 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
492 static void bfd_elf32_swap_crinfo_out
493 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
495 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
496 from smaller values. Start with zero, widen, *then* decrement. */
497 #define MINUS_ONE (((bfd_vma)0) - 1)
499 /* The relocation table used for SHT_REL sections. */
501 static reloc_howto_type elf_mips_howto_table_rel
[] =
504 HOWTO (R_MIPS_NONE
, /* type */
506 0, /* size (0 = byte, 1 = short, 2 = long) */
508 false, /* pc_relative */
510 complain_overflow_dont
, /* complain_on_overflow */
511 bfd_elf_generic_reloc
, /* special_function */
512 "R_MIPS_NONE", /* name */
513 false, /* partial_inplace */
516 false), /* pcrel_offset */
518 /* 16 bit relocation. */
519 HOWTO (R_MIPS_16
, /* type */
521 2, /* size (0 = byte, 1 = short, 2 = long) */
523 false, /* pc_relative */
525 complain_overflow_signed
, /* complain_on_overflow */
526 bfd_elf_generic_reloc
, /* special_function */
527 "R_MIPS_16", /* name */
528 true, /* partial_inplace */
529 0x0000ffff, /* src_mask */
530 0x0000ffff, /* dst_mask */
531 false), /* pcrel_offset */
533 /* 32 bit relocation. */
534 HOWTO (R_MIPS_32
, /* type */
536 2, /* size (0 = byte, 1 = short, 2 = long) */
538 false, /* pc_relative */
540 complain_overflow_dont
, /* complain_on_overflow */
541 bfd_elf_generic_reloc
, /* special_function */
542 "R_MIPS_32", /* name */
543 true, /* partial_inplace */
544 0xffffffff, /* src_mask */
545 0xffffffff, /* dst_mask */
546 false), /* pcrel_offset */
548 /* 32 bit symbol relative relocation. */
549 HOWTO (R_MIPS_REL32
, /* type */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
553 false, /* pc_relative */
555 complain_overflow_dont
, /* complain_on_overflow */
556 bfd_elf_generic_reloc
, /* special_function */
557 "R_MIPS_REL32", /* name */
558 true, /* partial_inplace */
559 0xffffffff, /* src_mask */
560 0xffffffff, /* dst_mask */
561 false), /* pcrel_offset */
563 /* 26 bit jump address. */
564 HOWTO (R_MIPS_26
, /* type */
566 2, /* size (0 = byte, 1 = short, 2 = long) */
568 false, /* pc_relative */
570 complain_overflow_dont
, /* complain_on_overflow */
571 /* This needs complex overflow
572 detection, because the upper four
573 bits must match the PC + 4. */
574 bfd_elf_generic_reloc
, /* special_function */
575 "R_MIPS_26", /* name */
576 true, /* partial_inplace */
577 0x03ffffff, /* src_mask */
578 0x03ffffff, /* dst_mask */
579 false), /* pcrel_offset */
581 /* High 16 bits of symbol value. */
582 HOWTO (R_MIPS_HI16
, /* type */
584 2, /* size (0 = byte, 1 = short, 2 = long) */
586 false, /* pc_relative */
588 complain_overflow_dont
, /* complain_on_overflow */
589 _bfd_mips_elf_hi16_reloc
, /* special_function */
590 "R_MIPS_HI16", /* name */
591 true, /* partial_inplace */
592 0x0000ffff, /* src_mask */
593 0x0000ffff, /* dst_mask */
594 false), /* pcrel_offset */
596 /* Low 16 bits of symbol value. */
597 HOWTO (R_MIPS_LO16
, /* type */
599 2, /* size (0 = byte, 1 = short, 2 = long) */
601 false, /* pc_relative */
603 complain_overflow_dont
, /* complain_on_overflow */
604 _bfd_mips_elf_lo16_reloc
, /* special_function */
605 "R_MIPS_LO16", /* name */
606 true, /* partial_inplace */
607 0x0000ffff, /* src_mask */
608 0x0000ffff, /* dst_mask */
609 false), /* pcrel_offset */
611 /* GP relative reference. */
612 HOWTO (R_MIPS_GPREL16
, /* type */
614 2, /* size (0 = byte, 1 = short, 2 = long) */
616 false, /* pc_relative */
618 complain_overflow_signed
, /* complain_on_overflow */
619 _bfd_mips_elf_gprel16_reloc
, /* special_function */
620 "R_MIPS_GPREL16", /* name */
621 true, /* partial_inplace */
622 0x0000ffff, /* src_mask */
623 0x0000ffff, /* dst_mask */
624 false), /* pcrel_offset */
626 /* Reference to literal section. */
627 HOWTO (R_MIPS_LITERAL
, /* type */
629 2, /* size (0 = byte, 1 = short, 2 = long) */
631 false, /* pc_relative */
633 complain_overflow_signed
, /* complain_on_overflow */
634 _bfd_mips_elf_gprel16_reloc
, /* special_function */
635 "R_MIPS_LITERAL", /* name */
636 true, /* partial_inplace */
637 0x0000ffff, /* src_mask */
638 0x0000ffff, /* dst_mask */
639 false), /* pcrel_offset */
641 /* Reference to global offset table. */
642 HOWTO (R_MIPS_GOT16
, /* type */
644 2, /* size (0 = byte, 1 = short, 2 = long) */
646 false, /* pc_relative */
648 complain_overflow_signed
, /* complain_on_overflow */
649 _bfd_mips_elf_got16_reloc
, /* special_function */
650 "R_MIPS_GOT16", /* name */
651 true, /* partial_inplace */
652 0x0000ffff, /* src_mask */
653 0x0000ffff, /* dst_mask */
654 false), /* pcrel_offset */
656 /* 16 bit PC relative reference. */
657 HOWTO (R_MIPS_PC16
, /* type */
659 2, /* size (0 = byte, 1 = short, 2 = long) */
661 true, /* pc_relative */
663 complain_overflow_signed
, /* complain_on_overflow */
664 bfd_elf_generic_reloc
, /* special_function */
665 "R_MIPS_PC16", /* name */
666 true, /* partial_inplace */
667 0x0000ffff, /* src_mask */
668 0x0000ffff, /* dst_mask */
669 true), /* pcrel_offset */
671 /* 16 bit call through global offset table. */
672 HOWTO (R_MIPS_CALL16
, /* type */
674 2, /* size (0 = byte, 1 = short, 2 = long) */
676 false, /* pc_relative */
678 complain_overflow_signed
, /* complain_on_overflow */
679 bfd_elf_generic_reloc
, /* special_function */
680 "R_MIPS_CALL16", /* name */
681 true, /* partial_inplace */
682 0x0000ffff, /* src_mask */
683 0x0000ffff, /* dst_mask */
684 false), /* pcrel_offset */
686 /* 32 bit GP relative reference. */
687 HOWTO (R_MIPS_GPREL32
, /* type */
689 2, /* size (0 = byte, 1 = short, 2 = long) */
691 false, /* pc_relative */
693 complain_overflow_dont
, /* complain_on_overflow */
694 _bfd_mips_elf_gprel32_reloc
, /* special_function */
695 "R_MIPS_GPREL32", /* name */
696 true, /* partial_inplace */
697 0xffffffff, /* src_mask */
698 0xffffffff, /* dst_mask */
699 false), /* pcrel_offset */
701 /* The remaining relocs are defined on Irix 5, although they are
702 not defined by the ABI. */
707 /* A 5 bit shift field. */
708 HOWTO (R_MIPS_SHIFT5
, /* type */
710 2, /* size (0 = byte, 1 = short, 2 = long) */
712 false, /* pc_relative */
714 complain_overflow_bitfield
, /* complain_on_overflow */
715 bfd_elf_generic_reloc
, /* special_function */
716 "R_MIPS_SHIFT5", /* name */
717 true, /* partial_inplace */
718 0x000007c0, /* src_mask */
719 0x000007c0, /* dst_mask */
720 false), /* pcrel_offset */
722 /* A 6 bit shift field. */
723 /* FIXME: This is not handled correctly; a special function is
724 needed to put the most significant bit in the right place. */
725 HOWTO (R_MIPS_SHIFT6
, /* type */
727 2, /* size (0 = byte, 1 = short, 2 = long) */
729 false, /* pc_relative */
731 complain_overflow_bitfield
, /* complain_on_overflow */
732 bfd_elf_generic_reloc
, /* special_function */
733 "R_MIPS_SHIFT6", /* name */
734 true, /* partial_inplace */
735 0x000007c4, /* src_mask */
736 0x000007c4, /* dst_mask */
737 false), /* pcrel_offset */
739 /* A 64 bit relocation. */
740 HOWTO (R_MIPS_64
, /* type */
742 4, /* size (0 = byte, 1 = short, 2 = long) */
744 false, /* pc_relative */
746 complain_overflow_dont
, /* complain_on_overflow */
747 mips32_64bit_reloc
, /* special_function */
748 "R_MIPS_64", /* name */
749 true, /* partial_inplace */
750 MINUS_ONE
, /* src_mask */
751 MINUS_ONE
, /* dst_mask */
752 false), /* pcrel_offset */
754 /* Displacement in the global offset table. */
755 HOWTO (R_MIPS_GOT_DISP
, /* type */
757 2, /* size (0 = byte, 1 = short, 2 = long) */
759 false, /* pc_relative */
761 complain_overflow_signed
, /* complain_on_overflow */
762 bfd_elf_generic_reloc
, /* special_function */
763 "R_MIPS_GOT_DISP", /* name */
764 true, /* partial_inplace */
765 0x0000ffff, /* src_mask */
766 0x0000ffff, /* dst_mask */
767 false), /* pcrel_offset */
769 /* Displacement to page pointer in the global offset table. */
770 HOWTO (R_MIPS_GOT_PAGE
, /* type */
772 2, /* size (0 = byte, 1 = short, 2 = long) */
774 false, /* pc_relative */
776 complain_overflow_signed
, /* complain_on_overflow */
777 bfd_elf_generic_reloc
, /* special_function */
778 "R_MIPS_GOT_PAGE", /* name */
779 true, /* partial_inplace */
780 0x0000ffff, /* src_mask */
781 0x0000ffff, /* dst_mask */
782 false), /* pcrel_offset */
784 /* Offset from page pointer in the global offset table. */
785 HOWTO (R_MIPS_GOT_OFST
, /* type */
787 2, /* size (0 = byte, 1 = short, 2 = long) */
789 false, /* pc_relative */
791 complain_overflow_signed
, /* complain_on_overflow */
792 bfd_elf_generic_reloc
, /* special_function */
793 "R_MIPS_GOT_OFST", /* name */
794 true, /* partial_inplace */
795 0x0000ffff, /* src_mask */
796 0x0000ffff, /* dst_mask */
797 false), /* pcrel_offset */
799 /* High 16 bits of displacement in global offset table. */
800 HOWTO (R_MIPS_GOT_HI16
, /* type */
802 2, /* size (0 = byte, 1 = short, 2 = long) */
804 false, /* pc_relative */
806 complain_overflow_dont
, /* complain_on_overflow */
807 bfd_elf_generic_reloc
, /* special_function */
808 "R_MIPS_GOT_HI16", /* name */
809 true, /* partial_inplace */
810 0x0000ffff, /* src_mask */
811 0x0000ffff, /* dst_mask */
812 false), /* pcrel_offset */
814 /* Low 16 bits of displacement in global offset table. */
815 HOWTO (R_MIPS_GOT_LO16
, /* type */
817 2, /* size (0 = byte, 1 = short, 2 = long) */
819 false, /* pc_relative */
821 complain_overflow_dont
, /* complain_on_overflow */
822 bfd_elf_generic_reloc
, /* special_function */
823 "R_MIPS_GOT_LO16", /* name */
824 true, /* partial_inplace */
825 0x0000ffff, /* src_mask */
826 0x0000ffff, /* dst_mask */
827 false), /* pcrel_offset */
829 /* 64 bit subtraction. Used in the N32 ABI. */
830 HOWTO (R_MIPS_SUB
, /* type */
832 4, /* size (0 = byte, 1 = short, 2 = long) */
834 false, /* pc_relative */
836 complain_overflow_dont
, /* complain_on_overflow */
837 bfd_elf_generic_reloc
, /* special_function */
838 "R_MIPS_SUB", /* name */
839 true, /* partial_inplace */
840 MINUS_ONE
, /* src_mask */
841 MINUS_ONE
, /* dst_mask */
842 false), /* pcrel_offset */
844 /* Used to cause the linker to insert and delete instructions? */
845 EMPTY_HOWTO (R_MIPS_INSERT_A
),
846 EMPTY_HOWTO (R_MIPS_INSERT_B
),
847 EMPTY_HOWTO (R_MIPS_DELETE
),
849 /* Get the higher value of a 64 bit addend. */
850 HOWTO (R_MIPS_HIGHER
, /* type */
852 2, /* size (0 = byte, 1 = short, 2 = long) */
854 false, /* pc_relative */
856 complain_overflow_dont
, /* complain_on_overflow */
857 bfd_elf_generic_reloc
, /* special_function */
858 "R_MIPS_HIGHER", /* name */
859 true, /* partial_inplace */
860 0x0000ffff, /* src_mask */
861 0x0000ffff, /* dst_mask */
862 false), /* pcrel_offset */
864 /* Get the highest value of a 64 bit addend. */
865 HOWTO (R_MIPS_HIGHEST
, /* type */
867 2, /* size (0 = byte, 1 = short, 2 = long) */
869 false, /* pc_relative */
871 complain_overflow_dont
, /* complain_on_overflow */
872 bfd_elf_generic_reloc
, /* special_function */
873 "R_MIPS_HIGHEST", /* name */
874 true, /* partial_inplace */
875 0x0000ffff, /* src_mask */
876 0x0000ffff, /* dst_mask */
877 false), /* pcrel_offset */
879 /* High 16 bits of displacement in global offset table. */
880 HOWTO (R_MIPS_CALL_HI16
, /* type */
882 2, /* size (0 = byte, 1 = short, 2 = long) */
884 false, /* pc_relative */
886 complain_overflow_dont
, /* complain_on_overflow */
887 bfd_elf_generic_reloc
, /* special_function */
888 "R_MIPS_CALL_HI16", /* name */
889 true, /* partial_inplace */
890 0x0000ffff, /* src_mask */
891 0x0000ffff, /* dst_mask */
892 false), /* pcrel_offset */
894 /* Low 16 bits of displacement in global offset table. */
895 HOWTO (R_MIPS_CALL_LO16
, /* type */
897 2, /* size (0 = byte, 1 = short, 2 = long) */
899 false, /* pc_relative */
901 complain_overflow_dont
, /* complain_on_overflow */
902 bfd_elf_generic_reloc
, /* special_function */
903 "R_MIPS_CALL_LO16", /* name */
904 true, /* partial_inplace */
905 0x0000ffff, /* src_mask */
906 0x0000ffff, /* dst_mask */
907 false), /* pcrel_offset */
909 /* Section displacement. */
910 HOWTO (R_MIPS_SCN_DISP
, /* type */
912 2, /* size (0 = byte, 1 = short, 2 = long) */
914 false, /* pc_relative */
916 complain_overflow_dont
, /* complain_on_overflow */
917 bfd_elf_generic_reloc
, /* special_function */
918 "R_MIPS_SCN_DISP", /* name */
919 true, /* partial_inplace */
920 0xffffffff, /* src_mask */
921 0xffffffff, /* dst_mask */
922 false), /* pcrel_offset */
924 EMPTY_HOWTO (R_MIPS_REL16
),
925 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE
),
926 EMPTY_HOWTO (R_MIPS_PJUMP
),
927 EMPTY_HOWTO (R_MIPS_RELGOT
),
929 /* Protected jump conversion. This is an optimization hint. No
930 relocation is required for correctness. */
931 HOWTO (R_MIPS_JALR
, /* type */
933 2, /* size (0 = byte, 1 = short, 2 = long) */
935 false, /* pc_relative */
937 complain_overflow_dont
, /* complain_on_overflow */
938 bfd_elf_generic_reloc
, /* special_function */
939 "R_MIPS_JALR", /* name */
940 false, /* partial_inplace */
941 0x00000000, /* src_mask */
942 0x00000000, /* dst_mask */
943 false), /* pcrel_offset */
946 /* The relocation table used for SHT_RELA sections. */
948 static reloc_howto_type elf_mips_howto_table_rela
[] =
951 HOWTO (R_MIPS_NONE
, /* type */
953 0, /* size (0 = byte, 1 = short, 2 = long) */
955 false, /* pc_relative */
957 complain_overflow_dont
, /* complain_on_overflow */
958 bfd_elf_generic_reloc
, /* special_function */
959 "R_MIPS_NONE", /* name */
960 false, /* partial_inplace */
963 false), /* pcrel_offset */
965 /* 16 bit relocation. */
966 HOWTO (R_MIPS_16
, /* type */
968 2, /* size (0 = byte, 1 = short, 2 = long) */
970 false, /* pc_relative */
972 complain_overflow_signed
, /* complain_on_overflow */
973 bfd_elf_generic_reloc
, /* special_function */
974 "R_MIPS_16", /* name */
975 false, /* partial_inplace */
977 0x0000, /* dst_mask */
978 false), /* pcrel_offset */
980 /* 32 bit relocation. */
981 HOWTO (R_MIPS_32
, /* type */
983 2, /* size (0 = byte, 1 = short, 2 = long) */
985 false, /* pc_relative */
987 complain_overflow_dont
, /* complain_on_overflow */
988 bfd_elf_generic_reloc
, /* special_function */
989 "R_MIPS_32", /* name */
990 false, /* partial_inplace */
992 0xffffffff, /* dst_mask */
993 false), /* pcrel_offset */
995 /* 32 bit symbol relative relocation. */
996 HOWTO (R_MIPS_REL32
, /* type */
998 2, /* size (0 = byte, 1 = short, 2 = long) */
1000 false, /* pc_relative */
1002 complain_overflow_dont
, /* complain_on_overflow */
1003 bfd_elf_generic_reloc
, /* special_function */
1004 "R_MIPS_REL32", /* name */
1005 false, /* partial_inplace */
1007 0xffffffff, /* dst_mask */
1008 false), /* pcrel_offset */
1010 /* 26 bit jump address. */
1011 HOWTO (R_MIPS_26
, /* type */
1013 2, /* size (0 = byte, 1 = short, 2 = long) */
1015 false, /* pc_relative */
1017 complain_overflow_dont
, /* complain_on_overflow */
1018 /* This needs complex overflow
1019 detection, because the upper 36
1020 bits must match the PC + 4. */
1021 bfd_elf_generic_reloc
, /* special_function */
1022 "R_MIPS_26", /* name */
1023 false, /* partial_inplace */
1025 0x03ffffff, /* dst_mask */
1026 false), /* pcrel_offset */
1028 /* R_MIPS_HI16 and R_MIPS_LO16 are unsupported for 64 bit REL. */
1029 /* High 16 bits of symbol value. */
1030 HOWTO (R_MIPS_HI16
, /* type */
1032 2, /* size (0 = byte, 1 = short, 2 = long) */
1034 false, /* pc_relative */
1036 complain_overflow_dont
, /* complain_on_overflow */
1037 bfd_elf_generic_reloc
, /* special_function */
1038 "R_MIPS_HI16", /* name */
1039 false, /* partial_inplace */
1041 0x0000ffff, /* dst_mask */
1042 false), /* pcrel_offset */
1044 /* Low 16 bits of symbol value. */
1045 HOWTO (R_MIPS_LO16
, /* type */
1047 2, /* size (0 = byte, 1 = short, 2 = long) */
1049 false, /* pc_relative */
1051 complain_overflow_dont
, /* complain_on_overflow */
1052 bfd_elf_generic_reloc
, /* special_function */
1053 "R_MIPS_LO16", /* name */
1054 false, /* partial_inplace */
1056 0x0000ffff, /* dst_mask */
1057 false), /* pcrel_offset */
1059 /* GP relative reference. */
1060 HOWTO (R_MIPS_GPREL16
, /* type */
1062 2, /* size (0 = byte, 1 = short, 2 = long) */
1064 false, /* pc_relative */
1066 complain_overflow_signed
, /* complain_on_overflow */
1067 _bfd_mips_elf_gprel16_reloc
, /* special_function */
1068 "R_MIPS_GPREL16", /* name */
1069 false, /* partial_inplace */
1071 0x0000ffff, /* dst_mask */
1072 false), /* pcrel_offset */
1074 /* Reference to literal section. */
1075 HOWTO (R_MIPS_LITERAL
, /* type */
1077 2, /* size (0 = byte, 1 = short, 2 = long) */
1079 false, /* pc_relative */
1081 complain_overflow_signed
, /* complain_on_overflow */
1082 _bfd_mips_elf_gprel16_reloc
, /* special_function */
1083 "R_MIPS_LITERAL", /* name */
1084 false, /* partial_inplace */
1086 0x0000ffff, /* dst_mask */
1087 false), /* pcrel_offset */
1089 /* Reference to global offset table. */
1090 /* FIXME: This is not handled correctly. */
1091 HOWTO (R_MIPS_GOT16
, /* type */
1093 2, /* size (0 = byte, 1 = short, 2 = long) */
1095 false, /* pc_relative */
1097 complain_overflow_signed
, /* complain_on_overflow */
1098 bfd_elf_generic_reloc
, /* special_function */
1099 "R_MIPS_GOT16", /* name */
1100 false, /* partial_inplace */
1102 0x0000ffff, /* dst_mask */
1103 false), /* pcrel_offset */
1105 /* 16 bit PC relative reference. */
1106 HOWTO (R_MIPS_PC16
, /* type */
1108 2, /* size (0 = byte, 1 = short, 2 = long) */
1110 true, /* pc_relative */
1112 complain_overflow_signed
, /* complain_on_overflow */
1113 bfd_elf_generic_reloc
, /* special_function */
1114 "R_MIPS_PC16", /* name */
1115 false, /* partial_inplace */
1117 0x0000ffff, /* dst_mask */
1118 true), /* pcrel_offset */
1120 /* 16 bit call through global offset table. */
1121 /* FIXME: This is not handled correctly. */
1122 HOWTO (R_MIPS_CALL16
, /* type */
1124 2, /* size (0 = byte, 1 = short, 2 = long) */
1126 false, /* pc_relative */
1128 complain_overflow_signed
, /* complain_on_overflow */
1129 bfd_elf_generic_reloc
, /* special_function */
1130 "R_MIPS_CALL16", /* name */
1131 false, /* partial_inplace */
1133 0x0000ffff, /* dst_mask */
1134 false), /* pcrel_offset */
1136 /* 32 bit GP relative reference. */
1137 HOWTO (R_MIPS_GPREL32
, /* type */
1139 2, /* size (0 = byte, 1 = short, 2 = long) */
1141 false, /* pc_relative */
1143 complain_overflow_dont
, /* complain_on_overflow */
1144 _bfd_mips_elf_gprel32_reloc
, /* special_function */
1145 "R_MIPS_GPREL32", /* name */
1146 false, /* partial_inplace */
1148 0xffffffff, /* dst_mask */
1149 false), /* pcrel_offset */
1155 /* A 5 bit shift field. */
1156 HOWTO (R_MIPS_SHIFT5
, /* type */
1158 2, /* size (0 = byte, 1 = short, 2 = long) */
1160 false, /* pc_relative */
1162 complain_overflow_bitfield
, /* complain_on_overflow */
1163 bfd_elf_generic_reloc
, /* special_function */
1164 "R_MIPS_SHIFT5", /* name */
1165 false, /* partial_inplace */
1167 0x000007c0, /* dst_mask */
1168 false), /* pcrel_offset */
1170 /* A 6 bit shift field. */
1171 /* FIXME: Not handled correctly. */
1172 HOWTO (R_MIPS_SHIFT6
, /* type */
1174 2, /* size (0 = byte, 1 = short, 2 = long) */
1176 false, /* pc_relative */
1178 complain_overflow_bitfield
, /* complain_on_overflow */
1179 bfd_elf_generic_reloc
, /* special_function */
1180 "R_MIPS_SHIFT6", /* name */
1181 false, /* partial_inplace */
1183 0x000007c4, /* dst_mask */
1184 false), /* pcrel_offset */
1186 /* 64 bit relocation. */
1187 HOWTO (R_MIPS_64
, /* type */
1189 4, /* size (0 = byte, 1 = short, 2 = long) */
1191 false, /* pc_relative */
1193 complain_overflow_dont
, /* complain_on_overflow */
1194 bfd_elf_generic_reloc
, /* special_function */
1195 "R_MIPS_64", /* name */
1196 false, /* partial_inplace */
1198 MINUS_ONE
, /* dst_mask */
1199 false), /* pcrel_offset */
1201 /* Displacement in the global offset table. */
1202 /* FIXME: Not handled correctly. */
1203 HOWTO (R_MIPS_GOT_DISP
, /* type */
1205 2, /* size (0 = byte, 1 = short, 2 = long) */
1207 false, /* pc_relative */
1209 complain_overflow_signed
, /* complain_on_overflow */
1210 bfd_elf_generic_reloc
, /* special_function */
1211 "R_MIPS_GOT_DISP", /* name */
1212 false, /* partial_inplace */
1214 0x0000ffff, /* dst_mask */
1215 false), /* pcrel_offset */
1217 /* Displacement to page pointer in the global offset table. */
1218 /* FIXME: Not handled correctly. */
1219 HOWTO (R_MIPS_GOT_PAGE
, /* type */
1221 2, /* size (0 = byte, 1 = short, 2 = long) */
1223 false, /* pc_relative */
1225 complain_overflow_signed
, /* complain_on_overflow */
1226 bfd_elf_generic_reloc
, /* special_function */
1227 "R_MIPS_GOT_PAGE", /* name */
1228 false, /* partial_inplace */
1230 0x0000ffff, /* dst_mask */
1231 false), /* pcrel_offset */
1233 /* Offset from page pointer in the global offset table. */
1234 /* FIXME: Not handled correctly. */
1235 HOWTO (R_MIPS_GOT_OFST
, /* type */
1237 2, /* size (0 = byte, 1 = short, 2 = long) */
1239 false, /* pc_relative */
1241 complain_overflow_signed
, /* complain_on_overflow */
1242 bfd_elf_generic_reloc
, /* special_function */
1243 "R_MIPS_GOT_OFST", /* name */
1244 false, /* partial_inplace */
1246 0x0000ffff, /* dst_mask */
1247 false), /* pcrel_offset */
1249 /* High 16 bits of displacement in global offset table. */
1250 /* FIXME: Not handled correctly. */
1251 HOWTO (R_MIPS_GOT_HI16
, /* type */
1253 2, /* size (0 = byte, 1 = short, 2 = long) */
1255 false, /* pc_relative */
1257 complain_overflow_dont
, /* complain_on_overflow */
1258 bfd_elf_generic_reloc
, /* special_function */
1259 "R_MIPS_GOT_HI16", /* name */
1260 false, /* partial_inplace */
1262 0x0000ffff, /* dst_mask */
1263 false), /* pcrel_offset */
1265 /* Low 16 bits of displacement in global offset table. */
1266 /* FIXME: Not handled correctly. */
1267 HOWTO (R_MIPS_GOT_LO16
, /* type */
1269 2, /* size (0 = byte, 1 = short, 2 = long) */
1271 false, /* pc_relative */
1273 complain_overflow_dont
, /* complain_on_overflow */
1274 bfd_elf_generic_reloc
, /* special_function */
1275 "R_MIPS_GOT_LO16", /* name */
1276 false, /* partial_inplace */
1278 0x0000ffff, /* dst_mask */
1279 false), /* pcrel_offset */
1281 /* 64 bit substraction. */
1282 /* FIXME: Not handled correctly. */
1283 HOWTO (R_MIPS_SUB
, /* type */
1285 4, /* size (0 = byte, 1 = short, 2 = long) */
1287 false, /* pc_relative */
1289 complain_overflow_dont
, /* complain_on_overflow */
1290 bfd_elf_generic_reloc
, /* special_function */
1291 "R_MIPS_SUB", /* name */
1292 false, /* partial_inplace */
1294 MINUS_ONE
, /* dst_mask */
1295 false), /* pcrel_offset */
1297 /* Insert the addend as an instruction. */
1298 /* FIXME: Not handled correctly. */
1299 HOWTO (R_MIPS_INSERT_A
, /* type */
1301 2, /* size (0 = byte, 1 = short, 2 = long) */
1303 false, /* pc_relative */
1305 complain_overflow_dont
, /* complain_on_overflow */
1306 bfd_elf_generic_reloc
, /* special_function */
1307 "R_MIPS_INSERT_A", /* name */
1308 false, /* partial_inplace */
1310 0xffffffff, /* dst_mask */
1311 false), /* pcrel_offset */
1313 /* Insert the addend as an instruction, and change all relocations
1314 to refer to the old instruction at the address. */
1315 /* FIXME: Not handled correctly. */
1316 HOWTO (R_MIPS_INSERT_B
, /* type */
1318 2, /* size (0 = byte, 1 = short, 2 = long) */
1320 false, /* pc_relative */
1322 complain_overflow_dont
, /* complain_on_overflow */
1323 bfd_elf_generic_reloc
, /* special_function */
1324 "R_MIPS_INSERT_B", /* name */
1325 false, /* partial_inplace */
1327 0xffffffff, /* dst_mask */
1328 false), /* pcrel_offset */
1330 /* Delete a 32 bit instruction. */
1331 /* FIXME: Not handled correctly. */
1332 HOWTO (R_MIPS_DELETE
, /* type */
1334 2, /* size (0 = byte, 1 = short, 2 = long) */
1336 false, /* pc_relative */
1338 complain_overflow_dont
, /* complain_on_overflow */
1339 bfd_elf_generic_reloc
, /* special_function */
1340 "R_MIPS_DELETE", /* name */
1341 false, /* partial_inplace */
1343 0xffffffff, /* dst_mask */
1344 false), /* pcrel_offset */
1346 /* Get the higher value of a 64 bit addend. */
1347 HOWTO (R_MIPS_HIGHER
, /* type */
1349 2, /* size (0 = byte, 1 = short, 2 = long) */
1351 false, /* pc_relative */
1353 complain_overflow_dont
, /* complain_on_overflow */
1354 bfd_elf_generic_reloc
, /* special_function */
1355 "R_MIPS_HIGHER", /* name */
1356 false, /* partial_inplace */
1358 0x0000ffff, /* dst_mask */
1359 false), /* pcrel_offset */
1361 /* Get the highest value of a 64 bit addend. */
1362 HOWTO (R_MIPS_HIGHEST
, /* type */
1364 2, /* size (0 = byte, 1 = short, 2 = long) */
1366 false, /* pc_relative */
1368 complain_overflow_dont
, /* complain_on_overflow */
1369 bfd_elf_generic_reloc
, /* special_function */
1370 "R_MIPS_HIGHEST", /* name */
1371 false, /* partial_inplace */
1373 0x0000ffff, /* dst_mask */
1374 false), /* pcrel_offset */
1376 /* High 16 bits of displacement in global offset table. */
1377 /* FIXME: Not handled correctly. */
1378 HOWTO (R_MIPS_CALL_HI16
, /* type */
1380 2, /* size (0 = byte, 1 = short, 2 = long) */
1382 false, /* pc_relative */
1384 complain_overflow_dont
, /* complain_on_overflow */
1385 bfd_elf_generic_reloc
, /* special_function */
1386 "R_MIPS_CALL_HI16", /* name */
1387 false, /* partial_inplace */
1389 0x0000ffff, /* dst_mask */
1390 false), /* pcrel_offset */
1392 /* Low 16 bits of displacement in global offset table. */
1393 /* FIXME: Not handled correctly. */
1394 HOWTO (R_MIPS_CALL_LO16
, /* type */
1396 2, /* size (0 = byte, 1 = short, 2 = long) */
1398 false, /* pc_relative */
1400 complain_overflow_dont
, /* complain_on_overflow */
1401 bfd_elf_generic_reloc
, /* special_function */
1402 "R_MIPS_CALL_LO16", /* name */
1403 false, /* partial_inplace */
1405 0x0000ffff, /* dst_mask */
1406 false), /* pcrel_offset */
1408 /* Section displacement, used by an associated event location section. */
1409 /* FIXME: Not handled correctly. */
1410 HOWTO (R_MIPS_SCN_DISP
, /* type */
1412 2, /* size (0 = byte, 1 = short, 2 = long) */
1414 false, /* pc_relative */
1416 complain_overflow_dont
, /* complain_on_overflow */
1417 bfd_elf_generic_reloc
, /* special_function */
1418 "R_MIPS_SCN_DISP", /* name */
1419 false, /* partial_inplace */
1421 0xffffffff, /* dst_mask */
1422 false), /* pcrel_offset */
1424 HOWTO (R_MIPS_REL16
, /* type */
1426 1, /* size (0 = byte, 1 = short, 2 = long) */
1428 false, /* pc_relative */
1430 complain_overflow_signed
, /* complain_on_overflow */
1431 bfd_elf_generic_reloc
, /* special_function */
1432 "R_MIPS_REL16", /* name */
1433 false, /* partial_inplace */
1435 0xffff, /* dst_mask */
1436 false), /* pcrel_offset */
1438 /* These two are obsolete. */
1439 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE
),
1440 EMPTY_HOWTO (R_MIPS_PJUMP
),
1442 /* Similiar to R_MIPS_REL32, but used for relocations in a GOT section.
1443 It must be used for multigot GOT's (and only there). */
1444 HOWTO (R_MIPS_RELGOT
, /* type */
1446 2, /* size (0 = byte, 1 = short, 2 = long) */
1448 false, /* pc_relative */
1450 complain_overflow_dont
, /* complain_on_overflow */
1451 bfd_elf_generic_reloc
, /* special_function */
1452 "R_MIPS_RELGOT", /* name */
1453 false, /* partial_inplace */
1455 0xffffffff, /* dst_mask */
1456 false), /* pcrel_offset */
1458 /* Protected jump conversion. This is an optimization hint. No
1459 relocation is required for correctness. */
1460 HOWTO (R_MIPS_JALR
, /* type */
1462 2, /* size (0 = byte, 1 = short, 2 = long) */
1464 false, /* pc_relative */
1466 complain_overflow_dont
, /* complain_on_overflow */
1467 bfd_elf_generic_reloc
, /* special_function */
1468 "R_MIPS_JALR", /* name */
1469 false, /* partial_inplace */
1471 0xffffffff, /* dst_mask */
1472 false), /* pcrel_offset */
1475 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
1476 is a hack to make the linker think that we need 64 bit values. */
1477 static reloc_howto_type elf_mips_ctor64_howto
=
1478 HOWTO (R_MIPS_64
, /* type */
1480 4, /* size (0 = byte, 1 = short, 2 = long) */
1482 false, /* pc_relative */
1484 complain_overflow_signed
, /* complain_on_overflow */
1485 mips32_64bit_reloc
, /* special_function */
1486 "R_MIPS_64", /* name */
1487 true, /* partial_inplace */
1488 0xffffffff, /* src_mask */
1489 0xffffffff, /* dst_mask */
1490 false); /* pcrel_offset */
1492 /* The reloc used for the mips16 jump instruction. */
1493 static reloc_howto_type elf_mips16_jump_howto
=
1494 HOWTO (R_MIPS16_26
, /* type */
1496 2, /* size (0 = byte, 1 = short, 2 = long) */
1498 false, /* pc_relative */
1500 complain_overflow_dont
, /* complain_on_overflow */
1501 /* This needs complex overflow
1502 detection, because the upper four
1503 bits must match the PC. */
1504 mips16_jump_reloc
, /* special_function */
1505 "R_MIPS16_26", /* name */
1506 true, /* partial_inplace */
1507 0x3ffffff, /* src_mask */
1508 0x3ffffff, /* dst_mask */
1509 false); /* pcrel_offset */
1511 /* The reloc used for the mips16 gprel instruction. */
1512 static reloc_howto_type elf_mips16_gprel_howto
=
1513 HOWTO (R_MIPS16_GPREL
, /* type */
1515 2, /* size (0 = byte, 1 = short, 2 = long) */
1517 false, /* pc_relative */
1519 complain_overflow_signed
, /* complain_on_overflow */
1520 mips16_gprel_reloc
, /* special_function */
1521 "R_MIPS16_GPREL", /* name */
1522 true, /* partial_inplace */
1523 0x07ff001f, /* src_mask */
1524 0x07ff001f, /* dst_mask */
1525 false); /* pcrel_offset */
1527 /* GNU extensions for embedded-pic. */
1528 /* High 16 bits of symbol value, pc-relative. */
1529 static reloc_howto_type elf_mips_gnu_rel_hi16
=
1530 HOWTO (R_MIPS_GNU_REL_HI16
, /* type */
1532 2, /* size (0 = byte, 1 = short, 2 = long) */
1534 true, /* pc_relative */
1536 complain_overflow_dont
, /* complain_on_overflow */
1537 _bfd_mips_elf_hi16_reloc
, /* special_function */
1538 "R_MIPS_GNU_REL_HI16", /* name */
1539 true, /* partial_inplace */
1540 0xffff, /* src_mask */
1541 0xffff, /* dst_mask */
1542 true); /* pcrel_offset */
1544 /* Low 16 bits of symbol value, pc-relative. */
1545 static reloc_howto_type elf_mips_gnu_rel_lo16
=
1546 HOWTO (R_MIPS_GNU_REL_LO16
, /* type */
1548 2, /* size (0 = byte, 1 = short, 2 = long) */
1550 true, /* pc_relative */
1552 complain_overflow_dont
, /* complain_on_overflow */
1553 _bfd_mips_elf_lo16_reloc
, /* special_function */
1554 "R_MIPS_GNU_REL_LO16", /* name */
1555 true, /* partial_inplace */
1556 0xffff, /* src_mask */
1557 0xffff, /* dst_mask */
1558 true); /* pcrel_offset */
1560 /* 16 bit offset for pc-relative branches. */
1561 static reloc_howto_type elf_mips_gnu_rel16_s2
=
1562 HOWTO (R_MIPS_GNU_REL16_S2
, /* type */
1564 2, /* size (0 = byte, 1 = short, 2 = long) */
1566 true, /* pc_relative */
1568 complain_overflow_signed
, /* complain_on_overflow */
1569 bfd_elf_generic_reloc
, /* special_function */
1570 "R_MIPS_GNU_REL16_S2", /* name */
1571 true, /* partial_inplace */
1572 0xffff, /* src_mask */
1573 0xffff, /* dst_mask */
1574 true); /* pcrel_offset */
1576 /* 64 bit pc-relative. */
1577 static reloc_howto_type elf_mips_gnu_pcrel64
=
1578 HOWTO (R_MIPS_PC64
, /* type */
1580 4, /* size (0 = byte, 1 = short, 2 = long) */
1582 true, /* pc_relative */
1584 complain_overflow_signed
, /* complain_on_overflow */
1585 bfd_elf_generic_reloc
, /* special_function */
1586 "R_MIPS_PC64", /* name */
1587 true, /* partial_inplace */
1588 MINUS_ONE
, /* src_mask */
1589 MINUS_ONE
, /* dst_mask */
1590 true); /* pcrel_offset */
1592 /* 32 bit pc-relative. */
1593 static reloc_howto_type elf_mips_gnu_pcrel32
=
1594 HOWTO (R_MIPS_PC32
, /* type */
1596 2, /* size (0 = byte, 1 = short, 2 = long) */
1598 true, /* pc_relative */
1600 complain_overflow_signed
, /* complain_on_overflow */
1601 bfd_elf_generic_reloc
, /* special_function */
1602 "R_MIPS_PC32", /* name */
1603 true, /* partial_inplace */
1604 0xffffffff, /* src_mask */
1605 0xffffffff, /* dst_mask */
1606 true); /* pcrel_offset */
1608 /* GNU extension to record C++ vtable hierarchy */
1609 static reloc_howto_type elf_mips_gnu_vtinherit_howto
=
1610 HOWTO (R_MIPS_GNU_VTINHERIT
, /* type */
1612 2, /* size (0 = byte, 1 = short, 2 = long) */
1614 false, /* pc_relative */
1616 complain_overflow_dont
, /* complain_on_overflow */
1617 NULL
, /* special_function */
1618 "R_MIPS_GNU_VTINHERIT", /* name */
1619 false, /* partial_inplace */
1622 false); /* pcrel_offset */
1624 /* GNU extension to record C++ vtable member usage */
1625 static reloc_howto_type elf_mips_gnu_vtentry_howto
=
1626 HOWTO (R_MIPS_GNU_VTENTRY
, /* type */
1628 2, /* size (0 = byte, 1 = short, 2 = long) */
1630 false, /* pc_relative */
1632 complain_overflow_dont
, /* complain_on_overflow */
1633 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
1634 "R_MIPS_GNU_VTENTRY", /* name */
1635 false, /* partial_inplace */
1638 false); /* pcrel_offset */
1640 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
1641 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
1642 the HI16. Here we just save the information we need; we do the
1643 actual relocation when we see the LO16. MIPS ELF requires that the
1644 LO16 immediately follow the HI16. As a GNU extension, we permit an
1645 arbitrary number of HI16 relocs to be associated with a single LO16
1646 reloc. This extension permits gcc to output the HI and LO relocs
1651 struct mips_hi16
*next
;
1656 /* FIXME: This should not be a static variable. */
1658 static struct mips_hi16
*mips_hi16_list
;
1660 bfd_reloc_status_type
1661 _bfd_mips_elf_hi16_reloc (abfd
,
1668 bfd
*abfd ATTRIBUTE_UNUSED
;
1669 arelent
*reloc_entry
;
1672 asection
*input_section
;
1674 char **error_message
;
1676 bfd_reloc_status_type ret
;
1678 struct mips_hi16
*n
;
1680 /* If we're relocating, and this an external symbol, we don't want
1681 to change anything. */
1682 if (output_bfd
!= (bfd
*) NULL
1683 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1684 && reloc_entry
->addend
== 0)
1686 reloc_entry
->address
+= input_section
->output_offset
;
1687 return bfd_reloc_ok
;
1692 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1694 boolean relocateable
;
1697 if (ret
== bfd_reloc_undefined
)
1700 if (output_bfd
!= NULL
)
1701 relocateable
= true;
1704 relocateable
= false;
1705 output_bfd
= symbol
->section
->output_section
->owner
;
1708 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1709 error_message
, &gp
);
1710 if (ret
!= bfd_reloc_ok
)
1713 relocation
= gp
- reloc_entry
->address
;
1717 if (bfd_is_und_section (symbol
->section
)
1718 && output_bfd
== (bfd
*) NULL
)
1719 ret
= bfd_reloc_undefined
;
1721 if (bfd_is_com_section (symbol
->section
))
1724 relocation
= symbol
->value
;
1727 relocation
+= symbol
->section
->output_section
->vma
;
1728 relocation
+= symbol
->section
->output_offset
;
1729 relocation
+= reloc_entry
->addend
;
1730 if (reloc_entry
->howto
->pc_relative
)
1731 relocation
-= reloc_entry
->address
;
1733 if (reloc_entry
->address
> input_section
->_cooked_size
)
1734 return bfd_reloc_outofrange
;
1736 /* Save the information, and let LO16 do the actual relocation. */
1737 n
= (struct mips_hi16
*) bfd_malloc ((bfd_size_type
) sizeof *n
);
1739 return bfd_reloc_outofrange
;
1740 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
1741 n
->addend
= relocation
;
1742 n
->next
= mips_hi16_list
;
1745 if (output_bfd
!= (bfd
*) NULL
)
1746 reloc_entry
->address
+= input_section
->output_offset
;
1751 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
1752 inplace relocation; this function exists in order to do the
1753 R_MIPS_HI16 relocation described above. */
1755 bfd_reloc_status_type
1756 _bfd_mips_elf_lo16_reloc (abfd
,
1764 arelent
*reloc_entry
;
1767 asection
*input_section
;
1769 char **error_message
;
1771 arelent gp_disp_relent
;
1773 if (mips_hi16_list
!= NULL
)
1775 struct mips_hi16
*l
;
1782 unsigned long vallo
;
1783 struct mips_hi16
*next
;
1785 /* Do the HI16 relocation. Note that we actually don't need
1786 to know anything about the LO16 itself, except where to
1787 find the low 16 bits of the addend needed by the LO16. */
1788 insn
= bfd_get_32 (abfd
, l
->addr
);
1789 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
1791 val
= ((insn
& 0xffff) << 16) + vallo
;
1794 /* The low order 16 bits are always treated as a signed
1795 value. Therefore, a negative value in the low order bits
1796 requires an adjustment in the high order bits. We need
1797 to make this adjustment in two ways: once for the bits we
1798 took from the data, and once for the bits we are putting
1799 back in to the data. */
1800 if ((vallo
& 0x8000) != 0)
1802 if ((val
& 0x8000) != 0)
1805 insn
= (insn
&~ (bfd_vma
) 0xffff) | ((val
>> 16) & 0xffff);
1806 bfd_put_32 (abfd
, (bfd_vma
) insn
, l
->addr
);
1808 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1810 gp_disp_relent
= *reloc_entry
;
1811 reloc_entry
= &gp_disp_relent
;
1812 reloc_entry
->addend
= l
->addend
;
1820 mips_hi16_list
= NULL
;
1822 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1824 bfd_reloc_status_type ret
;
1825 bfd_vma gp
, relocation
;
1827 /* FIXME: Does this case ever occur? */
1829 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
1830 if (ret
!= bfd_reloc_ok
)
1833 relocation
= gp
- reloc_entry
->address
;
1834 relocation
+= symbol
->section
->output_section
->vma
;
1835 relocation
+= symbol
->section
->output_offset
;
1836 relocation
+= reloc_entry
->addend
;
1838 if (reloc_entry
->address
> input_section
->_cooked_size
)
1839 return bfd_reloc_outofrange
;
1841 gp_disp_relent
= *reloc_entry
;
1842 reloc_entry
= &gp_disp_relent
;
1843 reloc_entry
->addend
= relocation
- 4;
1846 /* Now do the LO16 reloc in the usual way. */
1847 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1848 input_section
, output_bfd
, error_message
);
1851 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1852 table used for PIC code. If the symbol is an external symbol, the
1853 instruction is modified to contain the offset of the appropriate
1854 entry in the global offset table. If the symbol is a section
1855 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1856 addends are combined to form the real addend against the section
1857 symbol; the GOT16 is modified to contain the offset of an entry in
1858 the global offset table, and the LO16 is modified to offset it
1859 appropriately. Thus an offset larger than 16 bits requires a
1860 modified value in the global offset table.
1862 This implementation suffices for the assembler, but the linker does
1863 not yet know how to create global offset tables. */
1865 bfd_reloc_status_type
1866 _bfd_mips_elf_got16_reloc (abfd
,
1874 arelent
*reloc_entry
;
1877 asection
*input_section
;
1879 char **error_message
;
1881 /* If we're relocating, and this an external symbol, we don't want
1882 to change anything. */
1883 if (output_bfd
!= (bfd
*) NULL
1884 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1885 && reloc_entry
->addend
== 0)
1887 reloc_entry
->address
+= input_section
->output_offset
;
1888 return bfd_reloc_ok
;
1891 /* If we're relocating, and this is a local symbol, we can handle it
1893 if (output_bfd
!= (bfd
*) NULL
1894 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1895 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1896 input_section
, output_bfd
, error_message
);
1901 /* Set the GP value for OUTPUT_BFD. Returns false if this is a
1902 dangerous relocation. */
1905 mips_elf_assign_gp (output_bfd
, pgp
)
1913 /* If we've already figured out what GP will be, just return it. */
1914 *pgp
= _bfd_get_gp_value (output_bfd
);
1918 count
= bfd_get_symcount (output_bfd
);
1919 sym
= bfd_get_outsymbols (output_bfd
);
1921 /* The linker script will have created a symbol named `_gp' with the
1922 appropriate value. */
1923 if (sym
== (asymbol
**) NULL
)
1927 for (i
= 0; i
< count
; i
++, sym
++)
1929 register const char *name
;
1931 name
= bfd_asymbol_name (*sym
);
1932 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1934 *pgp
= bfd_asymbol_value (*sym
);
1935 _bfd_set_gp_value (output_bfd
, *pgp
);
1943 /* Only get the error once. */
1945 _bfd_set_gp_value (output_bfd
, *pgp
);
1952 /* We have to figure out the gp value, so that we can adjust the
1953 symbol value correctly. We look up the symbol _gp in the output
1954 BFD. If we can't find it, we're stuck. We cache it in the ELF
1955 target data. We don't need to adjust the symbol value for an
1956 external symbol if we are producing relocateable output. */
1958 static bfd_reloc_status_type
1959 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1962 boolean relocateable
;
1963 char **error_message
;
1966 if (bfd_is_und_section (symbol
->section
)
1970 return bfd_reloc_undefined
;
1973 *pgp
= _bfd_get_gp_value (output_bfd
);
1976 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1980 /* Make up a value. */
1981 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1982 _bfd_set_gp_value (output_bfd
, *pgp
);
1984 else if (!mips_elf_assign_gp (output_bfd
, pgp
))
1987 (char *) _("GP relative relocation when _gp not defined");
1988 return bfd_reloc_dangerous
;
1992 return bfd_reloc_ok
;
1995 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1996 become the offset from the gp register. This function also handles
1997 R_MIPS_LITERAL relocations, although those can be handled more
1998 cleverly because the entries in the .lit8 and .lit4 sections can be
2001 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
2002 arelent
*, asection
*,
2003 boolean
, PTR
, bfd_vma
));
2005 bfd_reloc_status_type
2006 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
2007 output_bfd
, error_message
)
2009 arelent
*reloc_entry
;
2012 asection
*input_section
;
2014 char **error_message
;
2016 boolean relocateable
;
2017 bfd_reloc_status_type ret
;
2020 /* If we're relocating, and this is an external symbol with no
2021 addend, we don't want to change anything. We will only have an
2022 addend if this is a newly created reloc, not read from an ELF
2024 if (output_bfd
!= (bfd
*) NULL
2025 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
2026 && reloc_entry
->addend
== 0)
2028 reloc_entry
->address
+= input_section
->output_offset
;
2029 return bfd_reloc_ok
;
2032 if (output_bfd
!= (bfd
*) NULL
)
2033 relocateable
= true;
2036 relocateable
= false;
2037 output_bfd
= symbol
->section
->output_section
->owner
;
2040 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
2042 if (ret
!= bfd_reloc_ok
)
2045 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
2046 relocateable
, data
, gp
);
2049 static bfd_reloc_status_type
2050 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
2054 arelent
*reloc_entry
;
2055 asection
*input_section
;
2056 boolean relocateable
;
2064 if (bfd_is_com_section (symbol
->section
))
2067 relocation
= symbol
->value
;
2069 relocation
+= symbol
->section
->output_section
->vma
;
2070 relocation
+= symbol
->section
->output_offset
;
2072 if (reloc_entry
->address
> input_section
->_cooked_size
)
2073 return bfd_reloc_outofrange
;
2075 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
2077 /* Set val to the offset into the section or symbol. */
2078 if (reloc_entry
->howto
->src_mask
== 0)
2080 /* This case occurs with the 64-bit MIPS ELF ABI. */
2081 val
= reloc_entry
->addend
;
2085 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
2090 /* Adjust val for the final section location and GP value. If we
2091 are producing relocateable output, we don't want to do this for
2092 an external symbol. */
2094 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
2095 val
+= relocation
- gp
;
2097 insn
= (insn
& ~0xffff) | (val
& 0xffff);
2098 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
2101 reloc_entry
->address
+= input_section
->output_offset
;
2103 /* Make sure it fit in 16 bits. */
2104 if ((long) val
>= 0x8000 || (long) val
< -0x8000)
2105 return bfd_reloc_overflow
;
2107 return bfd_reloc_ok
;
2110 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
2111 from the gp register? XXX */
2113 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
2114 arelent
*, asection
*,
2115 boolean
, PTR
, bfd_vma
));
2117 bfd_reloc_status_type
2118 _bfd_mips_elf_gprel32_reloc (abfd
,
2126 arelent
*reloc_entry
;
2129 asection
*input_section
;
2131 char **error_message
;
2133 boolean relocateable
;
2134 bfd_reloc_status_type ret
;
2137 /* If we're relocating, and this is an external symbol with no
2138 addend, we don't want to change anything. We will only have an
2139 addend if this is a newly created reloc, not read from an ELF
2141 if (output_bfd
!= (bfd
*) NULL
2142 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
2143 && reloc_entry
->addend
== 0)
2145 *error_message
= (char *)
2146 _("32bits gp relative relocation occurs for an external symbol");
2147 return bfd_reloc_outofrange
;
2150 if (output_bfd
!= (bfd
*) NULL
)
2152 relocateable
= true;
2153 gp
= _bfd_get_gp_value (output_bfd
);
2157 relocateable
= false;
2158 output_bfd
= symbol
->section
->output_section
->owner
;
2160 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
2161 error_message
, &gp
);
2162 if (ret
!= bfd_reloc_ok
)
2166 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
2167 relocateable
, data
, gp
);
2170 static bfd_reloc_status_type
2171 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
2175 arelent
*reloc_entry
;
2176 asection
*input_section
;
2177 boolean relocateable
;
2184 if (bfd_is_com_section (symbol
->section
))
2187 relocation
= symbol
->value
;
2189 relocation
+= symbol
->section
->output_section
->vma
;
2190 relocation
+= symbol
->section
->output_offset
;
2192 if (reloc_entry
->address
> input_section
->_cooked_size
)
2193 return bfd_reloc_outofrange
;
2195 if (reloc_entry
->howto
->src_mask
== 0)
2197 /* This case arises with the 64-bit MIPS ELF ABI. */
2201 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
2203 /* Set val to the offset into the section or symbol. */
2204 val
+= reloc_entry
->addend
;
2206 /* Adjust val for the final section location and GP value. If we
2207 are producing relocateable output, we don't want to do this for
2208 an external symbol. */
2210 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
2211 val
+= relocation
- gp
;
2213 bfd_put_32 (abfd
, (bfd_vma
) val
, (bfd_byte
*) data
+ reloc_entry
->address
);
2216 reloc_entry
->address
+= input_section
->output_offset
;
2218 return bfd_reloc_ok
;
2221 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
2222 generated when addresses are 64 bits. The upper 32 bits are a simple
2225 static bfd_reloc_status_type
2226 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
2227 output_bfd
, error_message
)
2229 arelent
*reloc_entry
;
2232 asection
*input_section
;
2234 char **error_message
;
2236 bfd_reloc_status_type r
;
2241 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2242 input_section
, output_bfd
, error_message
);
2243 if (r
!= bfd_reloc_continue
)
2246 /* Do a normal 32 bit relocation on the lower 32 bits. */
2247 reloc32
= *reloc_entry
;
2248 if (bfd_big_endian (abfd
))
2249 reloc32
.address
+= 4;
2250 reloc32
.howto
= &elf_mips_howto_table_rel
[R_MIPS_32
];
2251 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
2252 output_bfd
, error_message
);
2254 /* Sign extend into the upper 32 bits. */
2255 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
2256 if ((val
& 0x80000000) != 0)
2260 addr
= reloc_entry
->address
;
2261 if (bfd_little_endian (abfd
))
2263 bfd_put_32 (abfd
, (bfd_vma
) val
, (bfd_byte
*) data
+ addr
);
2268 /* Handle a mips16 jump. */
2270 static bfd_reloc_status_type
2271 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
2272 output_bfd
, error_message
)
2273 bfd
*abfd ATTRIBUTE_UNUSED
;
2274 arelent
*reloc_entry
;
2276 PTR data ATTRIBUTE_UNUSED
;
2277 asection
*input_section
;
2279 char **error_message ATTRIBUTE_UNUSED
;
2281 if (output_bfd
!= (bfd
*) NULL
2282 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
2283 && reloc_entry
->addend
== 0)
2285 reloc_entry
->address
+= input_section
->output_offset
;
2286 return bfd_reloc_ok
;
2291 static boolean warned
;
2294 (*_bfd_error_handler
)
2295 (_("Linking mips16 objects into %s format is not supported"),
2296 bfd_get_target (input_section
->output_section
->owner
));
2300 return bfd_reloc_undefined
;
2303 /* Handle a mips16 GP relative reloc. */
2305 static bfd_reloc_status_type
2306 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
2307 output_bfd
, error_message
)
2309 arelent
*reloc_entry
;
2312 asection
*input_section
;
2314 char **error_message
;
2316 boolean relocateable
;
2317 bfd_reloc_status_type ret
;
2319 unsigned short extend
, insn
;
2320 unsigned long final
;
2322 /* If we're relocating, and this is an external symbol with no
2323 addend, we don't want to change anything. We will only have an
2324 addend if this is a newly created reloc, not read from an ELF
2326 if (output_bfd
!= NULL
2327 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
2328 && reloc_entry
->addend
== 0)
2330 reloc_entry
->address
+= input_section
->output_offset
;
2331 return bfd_reloc_ok
;
2334 if (output_bfd
!= NULL
)
2335 relocateable
= true;
2338 relocateable
= false;
2339 output_bfd
= symbol
->section
->output_section
->owner
;
2342 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
2344 if (ret
!= bfd_reloc_ok
)
2347 if (reloc_entry
->address
> input_section
->_cooked_size
)
2348 return bfd_reloc_outofrange
;
2350 /* Pick up the mips16 extend instruction and the real instruction. */
2351 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
2352 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
2354 /* Stuff the current addend back as a 32 bit value, do the usual
2355 relocation, and then clean up. */
2357 (bfd_vma
) (((extend
& 0x1f) << 11)
2360 (bfd_byte
*) data
+ reloc_entry
->address
);
2362 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
2363 relocateable
, data
, gp
);
2365 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
2367 (bfd_vma
) ((extend
& 0xf800)
2368 | ((final
>> 11) & 0x1f)
2370 (bfd_byte
*) data
+ reloc_entry
->address
);
2372 (bfd_vma
) ((insn
& 0xffe0)
2374 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
2379 /* Return the ISA for a MIPS e_flags value. */
2382 elf_mips_isa (flags
)
2385 switch (flags
& EF_MIPS_ARCH
)
2397 case E_MIPS_ARCH_32
:
2399 case E_MIPS_ARCH_64
:
2405 /* Return the MACH for a MIPS e_flags value. */
2407 static INLINE
unsigned long
2408 elf_mips_mach (flags
)
2411 switch (flags
& EF_MIPS_MACH
)
2413 case E_MIPS_MACH_3900
:
2414 return bfd_mach_mips3900
;
2416 case E_MIPS_MACH_4010
:
2417 return bfd_mach_mips4010
;
2419 case E_MIPS_MACH_4100
:
2420 return bfd_mach_mips4100
;
2422 case E_MIPS_MACH_4111
:
2423 return bfd_mach_mips4111
;
2425 case E_MIPS_MACH_4650
:
2426 return bfd_mach_mips4650
;
2428 case E_MIPS_MACH_SB1
:
2429 return bfd_mach_mips_sb1
;
2432 switch (flags
& EF_MIPS_ARCH
)
2436 return bfd_mach_mips3000
;
2440 return bfd_mach_mips6000
;
2444 return bfd_mach_mips4000
;
2448 return bfd_mach_mips8000
;
2452 return bfd_mach_mips5
;
2455 case E_MIPS_ARCH_32
:
2456 return bfd_mach_mipsisa32
;
2459 case E_MIPS_ARCH_64
:
2460 return bfd_mach_mipsisa64
;
2468 /* Return printable name for ABI. */
2470 static INLINE
char *
2471 elf_mips_abi_name (abfd
)
2476 flags
= elf_elfheader (abfd
)->e_flags
;
2477 switch (flags
& EF_MIPS_ABI
)
2480 if (ABI_N32_P (abfd
))
2482 else if (ABI_64_P (abfd
))
2486 case E_MIPS_ABI_O32
:
2488 case E_MIPS_ABI_O64
:
2490 case E_MIPS_ABI_EABI32
:
2492 case E_MIPS_ABI_EABI64
:
2495 return "unknown abi";
2499 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
2501 struct elf_reloc_map
{
2502 bfd_reloc_code_real_type bfd_reloc_val
;
2503 enum elf_mips_reloc_type elf_reloc_val
;
2506 static const struct elf_reloc_map mips_reloc_map
[] =
2508 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
2509 { BFD_RELOC_16
, R_MIPS_16
},
2510 { BFD_RELOC_32
, R_MIPS_32
},
2511 { BFD_RELOC_64
, R_MIPS_64
},
2512 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
2513 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
2514 { BFD_RELOC_LO16
, R_MIPS_LO16
},
2515 { BFD_RELOC_GPREL16
, R_MIPS_GPREL16
},
2516 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
2517 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
2518 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
2519 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
2520 { BFD_RELOC_GPREL32
, R_MIPS_GPREL32
},
2521 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
2522 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
2523 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
2524 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
},
2525 { BFD_RELOC_MIPS_SUB
, R_MIPS_SUB
},
2526 { BFD_RELOC_MIPS_GOT_PAGE
, R_MIPS_GOT_PAGE
},
2527 { BFD_RELOC_MIPS_GOT_OFST
, R_MIPS_GOT_OFST
},
2528 { BFD_RELOC_MIPS_GOT_DISP
, R_MIPS_GOT_DISP
}
2531 /* Given a BFD reloc type, return a howto structure. */
2533 static reloc_howto_type
*
2534 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
2536 bfd_reloc_code_real_type code
;
2540 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
2542 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
2543 return &elf_mips_howto_table_rel
[(int) mips_reloc_map
[i
].elf_reloc_val
];
2549 bfd_set_error (bfd_error_bad_value
);
2552 case BFD_RELOC_CTOR
:
2553 /* We need to handle BFD_RELOC_CTOR specially.
2554 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
2555 size of addresses on this architecture. */
2556 if (bfd_arch_bits_per_address (abfd
) == 32)
2557 return &elf_mips_howto_table_rel
[(int) R_MIPS_32
];
2559 return &elf_mips_ctor64_howto
;
2561 case BFD_RELOC_MIPS16_JMP
:
2562 return &elf_mips16_jump_howto
;
2563 case BFD_RELOC_MIPS16_GPREL
:
2564 return &elf_mips16_gprel_howto
;
2565 case BFD_RELOC_VTABLE_INHERIT
:
2566 return &elf_mips_gnu_vtinherit_howto
;
2567 case BFD_RELOC_VTABLE_ENTRY
:
2568 return &elf_mips_gnu_vtentry_howto
;
2569 case BFD_RELOC_PCREL_HI16_S
:
2570 return &elf_mips_gnu_rel_hi16
;
2571 case BFD_RELOC_PCREL_LO16
:
2572 return &elf_mips_gnu_rel_lo16
;
2573 case BFD_RELOC_16_PCREL_S2
:
2574 return &elf_mips_gnu_rel16_s2
;
2575 case BFD_RELOC_64_PCREL
:
2576 return &elf_mips_gnu_pcrel64
;
2577 case BFD_RELOC_32_PCREL
:
2578 return &elf_mips_gnu_pcrel32
;
2582 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
2584 static reloc_howto_type
*
2585 mips_rtype_to_howto (r_type
)
2586 unsigned int r_type
;
2591 return &elf_mips16_jump_howto
;
2593 case R_MIPS16_GPREL
:
2594 return &elf_mips16_gprel_howto
;
2596 case R_MIPS_GNU_VTINHERIT
:
2597 return &elf_mips_gnu_vtinherit_howto
;
2599 case R_MIPS_GNU_VTENTRY
:
2600 return &elf_mips_gnu_vtentry_howto
;
2602 case R_MIPS_GNU_REL_HI16
:
2603 return &elf_mips_gnu_rel_hi16
;
2605 case R_MIPS_GNU_REL_LO16
:
2606 return &elf_mips_gnu_rel_lo16
;
2608 case R_MIPS_GNU_REL16_S2
:
2609 return &elf_mips_gnu_rel16_s2
;
2612 return &elf_mips_gnu_pcrel64
;
2615 return &elf_mips_gnu_pcrel32
;
2619 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
2620 return &elf_mips_howto_table_rel
[r_type
];
2625 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
2628 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
2631 Elf32_Internal_Rel
*dst
;
2633 unsigned int r_type
;
2635 r_type
= ELF32_R_TYPE (dst
->r_info
);
2636 cache_ptr
->howto
= mips_rtype_to_howto (r_type
);
2638 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
2639 value for the object file. We get the addend now, rather than
2640 when we do the relocation, because the symbol manipulations done
2641 by the linker may cause us to lose track of the input BFD. */
2642 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
2643 && (r_type
== (unsigned int) R_MIPS_GPREL16
2644 || r_type
== (unsigned int) R_MIPS_LITERAL
))
2645 cache_ptr
->addend
= elf_gp (abfd
);
2648 /* Given a MIPS Elf32_Internal_Rela, fill in an arelent structure. */
2651 mips_info_to_howto_rela (abfd
, cache_ptr
, dst
)
2654 Elf32_Internal_Rela
*dst
;
2656 /* Since an Elf32_Internal_Rel is an initial prefix of an
2657 Elf32_Internal_Rela, we can just use mips_info_to_howto_rel
2659 mips_info_to_howto_rel (abfd
, cache_ptr
, (Elf32_Internal_Rel
*) dst
);
2661 /* If we ever need to do any extra processing with dst->r_addend
2662 (the field omitted in an Elf32_Internal_Rel) we can do it here. */
2665 /* A .reginfo section holds a single Elf32_RegInfo structure. These
2666 routines swap this structure in and out. They are used outside of
2667 BFD, so they are globally visible. */
2670 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
2672 const Elf32_External_RegInfo
*ex
;
2675 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
2676 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
2677 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
2678 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
2679 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
2680 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
2684 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
2686 const Elf32_RegInfo
*in
;
2687 Elf32_External_RegInfo
*ex
;
2689 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
2690 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
2691 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
2692 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
2693 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
2694 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
2697 /* In the 64 bit ABI, the .MIPS.options section holds register
2698 information in an Elf64_Reginfo structure. These routines swap
2699 them in and out. They are globally visible because they are used
2700 outside of BFD. These routines are here so that gas can call them
2701 without worrying about whether the 64 bit ABI has been included. */
2704 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
2706 const Elf64_External_RegInfo
*ex
;
2707 Elf64_Internal_RegInfo
*in
;
2709 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
2710 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
2711 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
2712 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
2713 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
2714 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
2715 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
2719 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
2721 const Elf64_Internal_RegInfo
*in
;
2722 Elf64_External_RegInfo
*ex
;
2724 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
2725 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
2726 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
2727 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
2728 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
2729 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
2730 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
2733 /* Swap an entry in a .gptab section. Note that these routines rely
2734 on the equivalence of the two elements of the union. */
2737 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
2739 const Elf32_External_gptab
*ex
;
2742 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
2743 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
2747 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
2749 const Elf32_gptab
*in
;
2750 Elf32_External_gptab
*ex
;
2752 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
2753 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
2757 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
2759 const Elf32_compact_rel
*in
;
2760 Elf32_External_compact_rel
*ex
;
2762 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
2763 H_PUT_32 (abfd
, in
->num
, ex
->num
);
2764 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
2765 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
2766 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
2767 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
2771 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
2773 const Elf32_crinfo
*in
;
2774 Elf32_External_crinfo
*ex
;
2778 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
2779 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
2780 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
2781 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
2782 H_PUT_32 (abfd
, l
, ex
->info
);
2783 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
2784 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
2787 /* Swap in an options header. */
2790 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
2792 const Elf_External_Options
*ex
;
2793 Elf_Internal_Options
*in
;
2795 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
2796 in
->size
= H_GET_8 (abfd
, ex
->size
);
2797 in
->section
= H_GET_16 (abfd
, ex
->section
);
2798 in
->info
= H_GET_32 (abfd
, ex
->info
);
2801 /* Swap out an options header. */
2804 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
2806 const Elf_Internal_Options
*in
;
2807 Elf_External_Options
*ex
;
2809 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
2810 H_PUT_8 (abfd
, in
->size
, ex
->size
);
2811 H_PUT_16 (abfd
, in
->section
, ex
->section
);
2812 H_PUT_32 (abfd
, in
->info
, ex
->info
);
2815 /* Swap in an MSYM entry. */
2818 bfd_mips_elf_swap_msym_in (abfd
, ex
, in
)
2820 const Elf32_External_Msym
*ex
;
2821 Elf32_Internal_Msym
*in
;
2823 in
->ms_hash_value
= H_GET_32 (abfd
, ex
->ms_hash_value
);
2824 in
->ms_info
= H_GET_32 (abfd
, ex
->ms_info
);
2827 /* Swap out an MSYM entry. */
2830 bfd_mips_elf_swap_msym_out (abfd
, in
, ex
)
2832 const Elf32_Internal_Msym
*in
;
2833 Elf32_External_Msym
*ex
;
2835 H_PUT_32 (abfd
, in
->ms_hash_value
, ex
->ms_hash_value
);
2836 H_PUT_32 (abfd
, in
->ms_info
, ex
->ms_info
);
2839 /* Determine whether a symbol is global for the purposes of splitting
2840 the symbol table into global symbols and local symbols. At least
2841 on Irix 5, this split must be between section symbols and all other
2842 symbols. On most ELF targets the split is between static symbols
2843 and externally visible symbols. */
2846 mips_elf_sym_is_global (abfd
, sym
)
2847 bfd
*abfd ATTRIBUTE_UNUSED
;
2850 if (SGI_COMPAT (abfd
))
2851 return (sym
->flags
& BSF_SECTION_SYM
) == 0;
2853 return ((sym
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
2854 || bfd_is_und_section (bfd_get_section (sym
))
2855 || bfd_is_com_section (bfd_get_section (sym
)));
2858 /* Set the right machine number for a MIPS ELF file. This is used for
2859 both the 32-bit and the 64-bit ABI. */
2862 _bfd_mips_elf_object_p (abfd
)
2865 /* Irix 5 and 6 are broken. Object file symbol tables are not always
2866 sorted correctly such that local symbols precede global symbols,
2867 and the sh_info field in the symbol table is not always right. */
2868 if (SGI_COMPAT(abfd
))
2869 elf_bad_symtab (abfd
) = true;
2871 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
,
2872 elf_mips_mach (elf_elfheader (abfd
)->e_flags
));
2876 /* The final processing done just before writing out a MIPS ELF object
2877 file. This gets the MIPS architecture right based on the machine
2878 number. This is used by both the 32-bit and the 64-bit ABI. */
2881 _bfd_mips_elf_final_write_processing (abfd
, linker
)
2883 boolean linker ATTRIBUTE_UNUSED
;
2887 Elf_Internal_Shdr
**hdrpp
;
2891 switch (bfd_get_mach (abfd
))
2894 case bfd_mach_mips3000
:
2895 val
= E_MIPS_ARCH_1
;
2898 case bfd_mach_mips3900
:
2899 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
2902 case bfd_mach_mips6000
:
2903 val
= E_MIPS_ARCH_2
;
2906 case bfd_mach_mips4000
:
2907 case bfd_mach_mips4300
:
2908 case bfd_mach_mips4400
:
2909 case bfd_mach_mips4600
:
2910 val
= E_MIPS_ARCH_3
;
2913 case bfd_mach_mips4010
:
2914 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
2917 case bfd_mach_mips4100
:
2918 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
2921 case bfd_mach_mips4111
:
2922 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
2925 case bfd_mach_mips4650
:
2926 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
2929 case bfd_mach_mips5000
:
2930 case bfd_mach_mips8000
:
2931 case bfd_mach_mips10000
:
2932 case bfd_mach_mips12000
:
2933 val
= E_MIPS_ARCH_4
;
2936 case bfd_mach_mips5
:
2937 val
= E_MIPS_ARCH_5
;
2940 case bfd_mach_mips_sb1
:
2941 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
2944 case bfd_mach_mipsisa32
:
2945 val
= E_MIPS_ARCH_32
;
2948 case bfd_mach_mipsisa64
:
2949 val
= E_MIPS_ARCH_64
;
2952 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
2953 elf_elfheader (abfd
)->e_flags
|= val
;
2955 /* Set the sh_info field for .gptab sections and other appropriate
2956 info for each special section. */
2957 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
2958 i
< elf_numsections (abfd
);
2961 switch ((*hdrpp
)->sh_type
)
2964 case SHT_MIPS_LIBLIST
:
2965 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
2967 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2970 case SHT_MIPS_GPTAB
:
2971 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2972 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2973 BFD_ASSERT (name
!= NULL
2974 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
2975 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
2976 BFD_ASSERT (sec
!= NULL
);
2977 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2980 case SHT_MIPS_CONTENT
:
2981 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2982 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2983 BFD_ASSERT (name
!= NULL
2984 && strncmp (name
, ".MIPS.content",
2985 sizeof ".MIPS.content" - 1) == 0);
2986 sec
= bfd_get_section_by_name (abfd
,
2987 name
+ sizeof ".MIPS.content" - 1);
2988 BFD_ASSERT (sec
!= NULL
);
2989 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2992 case SHT_MIPS_SYMBOL_LIB
:
2993 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
2995 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2996 sec
= bfd_get_section_by_name (abfd
, ".liblist");
2998 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
3001 case SHT_MIPS_EVENTS
:
3002 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
3003 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
3004 BFD_ASSERT (name
!= NULL
);
3005 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
3006 sec
= bfd_get_section_by_name (abfd
,
3007 name
+ sizeof ".MIPS.events" - 1);
3010 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
3011 sizeof ".MIPS.post_rel" - 1) == 0);
3012 sec
= bfd_get_section_by_name (abfd
,
3014 + sizeof ".MIPS.post_rel" - 1));
3016 BFD_ASSERT (sec
!= NULL
);
3017 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
3024 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
3027 _bfd_mips_elf_set_private_flags (abfd
, flags
)
3031 BFD_ASSERT (!elf_flags_init (abfd
)
3032 || elf_elfheader (abfd
)->e_flags
== flags
);
3034 elf_elfheader (abfd
)->e_flags
= flags
;
3035 elf_flags_init (abfd
) = true;
3039 /* Merge backend specific data from an object file to the output
3040 object file when linking. */
3043 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
3050 boolean null_input_bfd
= true;
3053 /* Check if we have the same endianess */
3054 if (_bfd_generic_verify_endian_match (ibfd
, obfd
) == false)
3057 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
3058 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
3061 new_flags
= elf_elfheader (ibfd
)->e_flags
;
3062 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
3063 old_flags
= elf_elfheader (obfd
)->e_flags
;
3065 if (! elf_flags_init (obfd
))
3067 elf_flags_init (obfd
) = true;
3068 elf_elfheader (obfd
)->e_flags
= new_flags
;
3069 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
3070 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
3072 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
3073 && bfd_get_arch_info (obfd
)->the_default
)
3075 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
3076 bfd_get_mach (ibfd
)))
3083 /* Check flag compatibility. */
3085 new_flags
&= ~EF_MIPS_NOREORDER
;
3086 old_flags
&= ~EF_MIPS_NOREORDER
;
3088 if (new_flags
== old_flags
)
3091 /* Check to see if the input BFD actually contains any sections.
3092 If not, its flags may not have been initialised either, but it cannot
3093 actually cause any incompatibility. */
3094 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
3096 /* Ignore synthetic sections and empty .text, .data and .bss sections
3097 which are automatically generated by gas. */
3098 if (strcmp (sec
->name
, ".reginfo")
3099 && strcmp (sec
->name
, ".mdebug")
3100 && ((!strcmp (sec
->name
, ".text")
3101 || !strcmp (sec
->name
, ".data")
3102 || !strcmp (sec
->name
, ".bss"))
3103 && sec
->_raw_size
!= 0))
3105 null_input_bfd
= false;
3114 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
3116 new_flags
&= ~EF_MIPS_PIC
;
3117 old_flags
&= ~EF_MIPS_PIC
;
3118 (*_bfd_error_handler
)
3119 (_("%s: linking PIC files with non-PIC files"),
3120 bfd_archive_filename (ibfd
));
3124 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
3126 new_flags
&= ~EF_MIPS_CPIC
;
3127 old_flags
&= ~EF_MIPS_CPIC
;
3128 (*_bfd_error_handler
)
3129 (_("%s: linking abicalls files with non-abicalls files"),
3130 bfd_archive_filename (ibfd
));
3134 /* Compare the ISA's. */
3135 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
3136 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
3138 int new_mach
= new_flags
& EF_MIPS_MACH
;
3139 int old_mach
= old_flags
& EF_MIPS_MACH
;
3140 int new_isa
= elf_mips_isa (new_flags
);
3141 int old_isa
= elf_mips_isa (old_flags
);
3143 /* If either has no machine specified, just compare the general isa's.
3144 Some combinations of machines are ok, if the isa's match. */
3147 || new_mach
== old_mach
3150 /* Don't warn about mixing code using 32-bit ISAs, or mixing code
3151 using 64-bit ISAs. They will normally use the same data sizes
3152 and calling conventions. */
3154 if (( (new_isa
== 1 || new_isa
== 2 || new_isa
== 32)
3155 ^ (old_isa
== 1 || old_isa
== 2 || old_isa
== 32)) != 0)
3157 (*_bfd_error_handler
)
3158 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
3159 bfd_archive_filename (ibfd
), new_isa
, old_isa
);
3166 (*_bfd_error_handler
)
3167 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
3168 bfd_archive_filename (ibfd
),
3169 elf_mips_mach (new_flags
),
3170 elf_mips_mach (old_flags
));
3174 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
3175 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
3178 /* Compare ABI's. The 64-bit ABI does not use EF_MIPS_ABI. But, it
3179 does set EI_CLASS differently from any 32-bit ABI. */
3180 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
3181 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
3182 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
3184 /* Only error if both are set (to different values). */
3185 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
3186 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
3187 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
3189 (*_bfd_error_handler
)
3190 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
3191 bfd_archive_filename (ibfd
),
3192 elf_mips_abi_name (ibfd
),
3193 elf_mips_abi_name (obfd
));
3196 new_flags
&= ~EF_MIPS_ABI
;
3197 old_flags
&= ~EF_MIPS_ABI
;
3200 /* Warn about any other mismatches */
3201 if (new_flags
!= old_flags
)
3203 (*_bfd_error_handler
)
3204 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
3205 bfd_archive_filename (ibfd
), (unsigned long) new_flags
,
3206 (unsigned long) old_flags
);
3212 bfd_set_error (bfd_error_bad_value
);
3220 _bfd_mips_elf_print_private_bfd_data (abfd
, ptr
)
3224 FILE *file
= (FILE *) ptr
;
3226 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
3228 /* Print normal ELF private data. */
3229 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
3231 /* xgettext:c-format */
3232 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
3234 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
3235 fprintf (file
, _(" [abi=O32]"));
3236 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
3237 fprintf (file
, _(" [abi=O64]"));
3238 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
3239 fprintf (file
, _(" [abi=EABI32]"));
3240 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
3241 fprintf (file
, _(" [abi=EABI64]"));
3242 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
3243 fprintf (file
, _(" [abi unknown]"));
3244 else if (ABI_N32_P (abfd
))
3245 fprintf (file
, _(" [abi=N32]"));
3246 else if (ABI_64_P (abfd
))
3247 fprintf (file
, _(" [abi=64]"));
3249 fprintf (file
, _(" [no abi set]"));
3251 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
3252 fprintf (file
, _(" [mips1]"));
3253 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
3254 fprintf (file
, _(" [mips2]"));
3255 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
3256 fprintf (file
, _(" [mips3]"));
3257 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
3258 fprintf (file
, _(" [mips4]"));
3259 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
3260 fprintf (file
, _ (" [mips5]"));
3261 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
3262 fprintf (file
, _ (" [mips32]"));
3263 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
3264 fprintf (file
, _ (" [mips64]"));
3266 fprintf (file
, _(" [unknown ISA]"));
3268 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
3269 fprintf (file
, _(" [32bitmode]"));
3271 fprintf (file
, _(" [not 32bitmode]"));
3278 /* Handle a MIPS specific section when reading an object file. This
3279 is called when elfcode.h finds a section with an unknown type.
3280 This routine supports both the 32-bit and 64-bit ELF ABI.
3282 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
3286 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
3288 Elf_Internal_Shdr
*hdr
;
3293 /* There ought to be a place to keep ELF backend specific flags, but
3294 at the moment there isn't one. We just keep track of the
3295 sections by their name, instead. Fortunately, the ABI gives
3296 suggested names for all the MIPS specific sections, so we will
3297 probably get away with this. */
3298 switch (hdr
->sh_type
)
3300 case SHT_MIPS_LIBLIST
:
3301 if (strcmp (name
, ".liblist") != 0)
3305 if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) != 0)
3308 case SHT_MIPS_CONFLICT
:
3309 if (strcmp (name
, ".conflict") != 0)
3312 case SHT_MIPS_GPTAB
:
3313 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
3316 case SHT_MIPS_UCODE
:
3317 if (strcmp (name
, ".ucode") != 0)
3320 case SHT_MIPS_DEBUG
:
3321 if (strcmp (name
, ".mdebug") != 0)
3323 flags
= SEC_DEBUGGING
;
3325 case SHT_MIPS_REGINFO
:
3326 if (strcmp (name
, ".reginfo") != 0
3327 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
3329 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
3331 case SHT_MIPS_IFACE
:
3332 if (strcmp (name
, ".MIPS.interfaces") != 0)
3335 case SHT_MIPS_CONTENT
:
3336 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
3339 case SHT_MIPS_OPTIONS
:
3340 if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) != 0)
3343 case SHT_MIPS_DWARF
:
3344 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
3347 case SHT_MIPS_SYMBOL_LIB
:
3348 if (strcmp (name
, ".MIPS.symlib") != 0)
3351 case SHT_MIPS_EVENTS
:
3352 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
3353 && strncmp (name
, ".MIPS.post_rel",
3354 sizeof ".MIPS.post_rel" - 1) != 0)
3361 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
3366 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
3367 (bfd_get_section_flags (abfd
,
3373 /* FIXME: We should record sh_info for a .gptab section. */
3375 /* For a .reginfo section, set the gp value in the tdata information
3376 from the contents of this section. We need the gp value while
3377 processing relocs, so we just get it now. The .reginfo section
3378 is not used in the 64-bit MIPS ELF ABI. */
3379 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
3381 Elf32_External_RegInfo ext
;
3384 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
3386 (bfd_size_type
) sizeof ext
))
3388 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
3389 elf_gp (abfd
) = s
.ri_gp_value
;
3392 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
3393 set the gp value based on what we find. We may see both
3394 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
3395 they should agree. */
3396 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
3398 bfd_byte
*contents
, *l
, *lend
;
3400 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
3401 if (contents
== NULL
)
3403 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
3404 (file_ptr
) 0, hdr
->sh_size
))
3410 lend
= contents
+ hdr
->sh_size
;
3411 while (l
+ sizeof (Elf_External_Options
) <= lend
)
3413 Elf_Internal_Options intopt
;
3415 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
3417 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
3419 Elf64_Internal_RegInfo intreg
;
3421 bfd_mips_elf64_swap_reginfo_in
3423 ((Elf64_External_RegInfo
*)
3424 (l
+ sizeof (Elf_External_Options
))),
3426 elf_gp (abfd
) = intreg
.ri_gp_value
;
3428 else if (intopt
.kind
== ODK_REGINFO
)
3430 Elf32_RegInfo intreg
;
3432 bfd_mips_elf32_swap_reginfo_in
3434 ((Elf32_External_RegInfo
*)
3435 (l
+ sizeof (Elf_External_Options
))),
3437 elf_gp (abfd
) = intreg
.ri_gp_value
;
3447 /* Set the correct type for a MIPS ELF section. We do this by the
3448 section name, which is a hack, but ought to work. This routine is
3449 used by both the 32-bit and the 64-bit ABI. */
3452 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
3454 Elf32_Internal_Shdr
*hdr
;
3457 register const char *name
;
3459 name
= bfd_get_section_name (abfd
, sec
);
3461 if (strcmp (name
, ".liblist") == 0)
3463 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
3464 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
3465 /* The sh_link field is set in final_write_processing. */
3467 else if (strcmp (name
, ".conflict") == 0)
3468 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
3469 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
3471 hdr
->sh_type
= SHT_MIPS_GPTAB
;
3472 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
3473 /* The sh_info field is set in final_write_processing. */
3475 else if (strcmp (name
, ".ucode") == 0)
3476 hdr
->sh_type
= SHT_MIPS_UCODE
;
3477 else if (strcmp (name
, ".mdebug") == 0)
3479 hdr
->sh_type
= SHT_MIPS_DEBUG
;
3480 /* In a shared object on Irix 5.3, the .mdebug section has an
3481 entsize of 0. FIXME: Does this matter? */
3482 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
3483 hdr
->sh_entsize
= 0;
3485 hdr
->sh_entsize
= 1;
3487 else if (strcmp (name
, ".reginfo") == 0)
3489 hdr
->sh_type
= SHT_MIPS_REGINFO
;
3490 /* In a shared object on Irix 5.3, the .reginfo section has an
3491 entsize of 0x18. FIXME: Does this matter? */
3492 if (SGI_COMPAT (abfd
))
3494 if ((abfd
->flags
& DYNAMIC
) != 0)
3495 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
3497 hdr
->sh_entsize
= 1;
3500 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
3502 else if (SGI_COMPAT (abfd
)
3503 && (strcmp (name
, ".hash") == 0
3504 || strcmp (name
, ".dynamic") == 0
3505 || strcmp (name
, ".dynstr") == 0))
3507 if (SGI_COMPAT (abfd
))
3508 hdr
->sh_entsize
= 0;
3510 /* This isn't how the Irix 6 linker behaves. */
3511 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
3514 else if (strcmp (name
, ".got") == 0
3515 || strcmp (name
, MIPS_ELF_SRDATA_SECTION_NAME (abfd
)) == 0
3516 || strcmp (name
, ".sdata") == 0
3517 || strcmp (name
, ".sbss") == 0
3518 || strcmp (name
, ".lit4") == 0
3519 || strcmp (name
, ".lit8") == 0)
3520 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
3521 else if (strcmp (name
, ".MIPS.interfaces") == 0)
3523 hdr
->sh_type
= SHT_MIPS_IFACE
;
3524 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3526 else if (strncmp (name
, ".MIPS.content", strlen (".MIPS.content")) == 0)
3528 hdr
->sh_type
= SHT_MIPS_CONTENT
;
3529 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3530 /* The sh_info field is set in final_write_processing. */
3532 else if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
3534 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
3535 hdr
->sh_entsize
= 1;
3536 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3538 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
3539 hdr
->sh_type
= SHT_MIPS_DWARF
;
3540 else if (strcmp (name
, ".MIPS.symlib") == 0)
3542 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
3543 /* The sh_link and sh_info fields are set in
3544 final_write_processing. */
3546 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
3547 || strncmp (name
, ".MIPS.post_rel",
3548 sizeof ".MIPS.post_rel" - 1) == 0)
3550 hdr
->sh_type
= SHT_MIPS_EVENTS
;
3551 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3552 /* The sh_link field is set in final_write_processing. */
3554 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) == 0)
3556 hdr
->sh_type
= SHT_MIPS_MSYM
;
3557 hdr
->sh_flags
|= SHF_ALLOC
;
3558 hdr
->sh_entsize
= 8;
3561 /* The generic elf_fake_sections will set up REL_HDR using the
3562 default kind of relocations. But, we may actually need both
3563 kinds of relocations, so we set up the second header here. */
3564 if ((sec
->flags
& SEC_RELOC
) != 0)
3566 struct bfd_elf_section_data
*esd
;
3567 bfd_size_type amt
= sizeof (Elf_Internal_Shdr
);
3569 esd
= elf_section_data (sec
);
3570 BFD_ASSERT (esd
->rel_hdr2
== NULL
);
3571 esd
->rel_hdr2
= (Elf_Internal_Shdr
*) bfd_zalloc (abfd
, amt
);
3574 _bfd_elf_init_reloc_shdr (abfd
, esd
->rel_hdr2
, sec
,
3575 !elf_section_data (sec
)->use_rela_p
);
3581 /* Given a BFD section, try to locate the corresponding ELF section
3582 index. This is used by both the 32-bit and the 64-bit ABI.
3583 Actually, it's not clear to me that the 64-bit ABI supports these,
3584 but for non-PIC objects we will certainly want support for at least
3585 the .scommon section. */
3588 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
3589 bfd
*abfd ATTRIBUTE_UNUSED
;
3590 Elf_Internal_Shdr
*hdr ATTRIBUTE_UNUSED
;
3594 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
3596 *retval
= SHN_MIPS_SCOMMON
;
3599 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
3601 *retval
= SHN_MIPS_ACOMMON
;
3607 /* When are writing out the .options or .MIPS.options section,
3608 remember the bytes we are writing out, so that we can install the
3609 GP value in the section_processing routine. */
3612 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
3617 bfd_size_type count
;
3619 if (strcmp (section
->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
3623 if (elf_section_data (section
) == NULL
)
3625 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
3626 section
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
3627 if (elf_section_data (section
) == NULL
)
3630 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
3635 if (section
->_cooked_size
!= 0)
3636 size
= section
->_cooked_size
;
3638 size
= section
->_raw_size
;
3639 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
3642 elf_section_data (section
)->tdata
= (PTR
) c
;
3645 memcpy (c
+ offset
, location
, (size_t) count
);
3648 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
3652 /* Work over a section just before writing it out. This routine is
3653 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
3654 sections that need the SHF_MIPS_GPREL flag by name; there has to be
3658 _bfd_mips_elf_section_processing (abfd
, hdr
)
3660 Elf_Internal_Shdr
*hdr
;
3662 if (hdr
->sh_type
== SHT_MIPS_REGINFO
3663 && hdr
->sh_size
> 0)
3667 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
3668 BFD_ASSERT (hdr
->contents
== NULL
);
3671 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
3674 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
3675 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
3679 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
3680 && hdr
->bfd_section
!= NULL
3681 && elf_section_data (hdr
->bfd_section
) != NULL
3682 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
3684 bfd_byte
*contents
, *l
, *lend
;
3686 /* We stored the section contents in the elf_section_data tdata
3687 field in the set_section_contents routine. We save the
3688 section contents so that we don't have to read them again.
3689 At this point we know that elf_gp is set, so we can look
3690 through the section contents to see if there is an
3691 ODK_REGINFO structure. */
3693 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
3695 lend
= contents
+ hdr
->sh_size
;
3696 while (l
+ sizeof (Elf_External_Options
) <= lend
)
3698 Elf_Internal_Options intopt
;
3700 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
3702 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
3709 + sizeof (Elf_External_Options
)
3710 + (sizeof (Elf64_External_RegInfo
) - 8)),
3713 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
3714 if (bfd_bwrite (buf
, (bfd_size_type
) 8, abfd
) != 8)
3717 else if (intopt
.kind
== ODK_REGINFO
)
3724 + sizeof (Elf_External_Options
)
3725 + (sizeof (Elf32_External_RegInfo
) - 4)),
3728 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
3729 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
3736 if (hdr
->bfd_section
!= NULL
)
3738 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
3740 if (strcmp (name
, ".sdata") == 0
3741 || strcmp (name
, ".lit8") == 0
3742 || strcmp (name
, ".lit4") == 0)
3744 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3745 hdr
->sh_type
= SHT_PROGBITS
;
3747 else if (strcmp (name
, ".sbss") == 0)
3749 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3750 hdr
->sh_type
= SHT_NOBITS
;
3752 else if (strcmp (name
, MIPS_ELF_SRDATA_SECTION_NAME (abfd
)) == 0)
3754 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
3755 hdr
->sh_type
= SHT_PROGBITS
;
3757 else if (strcmp (name
, ".compact_rel") == 0)
3760 hdr
->sh_type
= SHT_PROGBITS
;
3762 else if (strcmp (name
, ".rtproc") == 0)
3764 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
3766 unsigned int adjust
;
3768 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
3770 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
3778 /* MIPS ELF uses two common sections. One is the usual one, and the
3779 other is for small objects. All the small objects are kept
3780 together, and then referenced via the gp pointer, which yields
3781 faster assembler code. This is what we use for the small common
3782 section. This approach is copied from ecoff.c. */
3783 static asection mips_elf_scom_section
;
3784 static asymbol mips_elf_scom_symbol
;
3785 static asymbol
*mips_elf_scom_symbol_ptr
;
3787 /* MIPS ELF also uses an acommon section, which represents an
3788 allocated common symbol which may be overridden by a
3789 definition in a shared library. */
3790 static asection mips_elf_acom_section
;
3791 static asymbol mips_elf_acom_symbol
;
3792 static asymbol
*mips_elf_acom_symbol_ptr
;
3794 /* Handle the special MIPS section numbers that a symbol may use.
3795 This is used for both the 32-bit and the 64-bit ABI. */
3798 _bfd_mips_elf_symbol_processing (abfd
, asym
)
3802 elf_symbol_type
*elfsym
;
3804 elfsym
= (elf_symbol_type
*) asym
;
3805 switch (elfsym
->internal_elf_sym
.st_shndx
)
3807 case SHN_MIPS_ACOMMON
:
3808 /* This section is used in a dynamically linked executable file.
3809 It is an allocated common section. The dynamic linker can
3810 either resolve these symbols to something in a shared
3811 library, or it can just leave them here. For our purposes,
3812 we can consider these symbols to be in a new section. */
3813 if (mips_elf_acom_section
.name
== NULL
)
3815 /* Initialize the acommon section. */
3816 mips_elf_acom_section
.name
= ".acommon";
3817 mips_elf_acom_section
.flags
= SEC_ALLOC
;
3818 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
3819 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
3820 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
3821 mips_elf_acom_symbol
.name
= ".acommon";
3822 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
3823 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
3824 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
3826 asym
->section
= &mips_elf_acom_section
;
3830 /* Common symbols less than the GP size are automatically
3831 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
3832 if (asym
->value
> elf_gp_size (abfd
)
3833 || IRIX_COMPAT (abfd
) == ict_irix6
)
3836 case SHN_MIPS_SCOMMON
:
3837 if (mips_elf_scom_section
.name
== NULL
)
3839 /* Initialize the small common section. */
3840 mips_elf_scom_section
.name
= ".scommon";
3841 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
3842 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
3843 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
3844 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
3845 mips_elf_scom_symbol
.name
= ".scommon";
3846 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
3847 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
3848 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
3850 asym
->section
= &mips_elf_scom_section
;
3851 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
3854 case SHN_MIPS_SUNDEFINED
:
3855 asym
->section
= bfd_und_section_ptr
;
3858 #if 0 /* for SGI_COMPAT */
3860 asym
->section
= mips_elf_text_section_ptr
;
3864 asym
->section
= mips_elf_data_section_ptr
;
3870 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
3874 _bfd_mips_elf_additional_program_headers (abfd
)
3880 /* See if we need a PT_MIPS_REGINFO segment. */
3881 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3882 if (s
&& (s
->flags
& SEC_LOAD
))
3885 /* See if we need a PT_MIPS_OPTIONS segment. */
3886 if (IRIX_COMPAT (abfd
) == ict_irix6
3887 && bfd_get_section_by_name (abfd
,
3888 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
3891 /* See if we need a PT_MIPS_RTPROC segment. */
3892 if (IRIX_COMPAT (abfd
) == ict_irix5
3893 && bfd_get_section_by_name (abfd
, ".dynamic")
3894 && bfd_get_section_by_name (abfd
, ".mdebug"))
3900 /* Modify the segment map for an Irix 5 executable. */
3903 _bfd_mips_elf_modify_segment_map (abfd
)
3907 struct elf_segment_map
*m
, **pm
;
3910 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
3912 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3913 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3915 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3916 if (m
->p_type
== PT_MIPS_REGINFO
)
3921 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
3925 m
->p_type
= PT_MIPS_REGINFO
;
3929 /* We want to put it after the PHDR and INTERP segments. */
3930 pm
= &elf_tdata (abfd
)->segment_map
;
3932 && ((*pm
)->p_type
== PT_PHDR
3933 || (*pm
)->p_type
== PT_INTERP
))
3941 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
3942 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
3943 PT_OPTIONS segement immediately following the program header
3945 if (IRIX_COMPAT (abfd
) == ict_irix6
)
3947 for (s
= abfd
->sections
; s
; s
= s
->next
)
3948 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
3953 struct elf_segment_map
*options_segment
;
3955 /* Usually, there's a program header table. But, sometimes
3956 there's not (like when running the `ld' testsuite). So,
3957 if there's no program header table, we just put the
3958 options segement at the end. */
3959 for (pm
= &elf_tdata (abfd
)->segment_map
;
3962 if ((*pm
)->p_type
== PT_PHDR
)
3965 amt
= sizeof (struct elf_segment_map
);
3966 options_segment
= bfd_zalloc (abfd
, amt
);
3967 options_segment
->next
= *pm
;
3968 options_segment
->p_type
= PT_MIPS_OPTIONS
;
3969 options_segment
->p_flags
= PF_R
;
3970 options_segment
->p_flags_valid
= true;
3971 options_segment
->count
= 1;
3972 options_segment
->sections
[0] = s
;
3973 *pm
= options_segment
;
3978 if (IRIX_COMPAT (abfd
) == ict_irix5
)
3980 /* If there are .dynamic and .mdebug sections, we make a room
3981 for the RTPROC header. FIXME: Rewrite without section names. */
3982 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
3983 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3984 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3986 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3987 if (m
->p_type
== PT_MIPS_RTPROC
)
3992 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
3996 m
->p_type
= PT_MIPS_RTPROC
;
3998 s
= bfd_get_section_by_name (abfd
, ".rtproc");
4003 m
->p_flags_valid
= 1;
4011 /* We want to put it after the DYNAMIC segment. */
4012 pm
= &elf_tdata (abfd
)->segment_map
;
4013 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
4023 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic,
4024 .dynstr, .dynsym, and .hash sections, and everything in
4026 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
;
4028 if ((*pm
)->p_type
== PT_DYNAMIC
)
4031 if (m
!= NULL
&& IRIX_COMPAT (abfd
) == ict_none
)
4033 /* For a normal mips executable the permissions for the PT_DYNAMIC
4034 segment are read, write and execute. We do that here since
4035 the code in elf.c sets only the read permission. This matters
4036 sometimes for the dynamic linker. */
4037 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
4039 m
->p_flags
= PF_R
| PF_W
| PF_X
;
4040 m
->p_flags_valid
= 1;
4044 && m
->count
== 1 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
4046 static const char *sec_names
[] =
4048 ".dynamic", ".dynstr", ".dynsym", ".hash"
4052 struct elf_segment_map
*n
;
4056 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
4058 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
4059 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
4065 sz
= s
->_cooked_size
;
4068 if (high
< s
->vma
+ sz
)
4074 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
4075 if ((s
->flags
& SEC_LOAD
) != 0
4078 + (s
->_cooked_size
!=
4079 0 ? s
->_cooked_size
: s
->_raw_size
)) <= high
))
4082 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
4083 n
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
4090 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
4092 if ((s
->flags
& SEC_LOAD
) != 0
4095 + (s
->_cooked_size
!= 0 ?
4096 s
->_cooked_size
: s
->_raw_size
)) <= high
))
4110 /* The structure of the runtime procedure descriptor created by the
4111 loader for use by the static exception system. */
4113 typedef struct runtime_pdr
{
4114 bfd_vma adr
; /* memory address of start of procedure */
4115 long regmask
; /* save register mask */
4116 long regoffset
; /* save register offset */
4117 long fregmask
; /* save floating point register mask */
4118 long fregoffset
; /* save floating point register offset */
4119 long frameoffset
; /* frame size */
4120 short framereg
; /* frame pointer register */
4121 short pcreg
; /* offset or reg of return pc */
4122 long irpss
; /* index into the runtime string table */
4124 struct exception_info
*exception_info
;/* pointer to exception array */
4126 #define cbRPDR sizeof (RPDR)
4127 #define rpdNil ((pRPDR) 0)
4129 /* Swap RPDR (runtime procedure table entry) for output. */
4131 static void ecoff_swap_rpdr_out
4132 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
4135 ecoff_swap_rpdr_out (abfd
, in
, ex
)
4138 struct rpdr_ext
*ex
;
4140 /* ECOFF_PUT_OFF was defined in ecoffswap.h. */
4141 ECOFF_PUT_OFF (abfd
, in
->adr
, ex
->p_adr
);
4142 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
4143 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
4144 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
4145 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
4146 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
4148 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
4149 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
4151 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
4153 ECOFF_PUT_OFF (abfd
, in
->exception_info
, ex
->p_exception_info
);
4157 /* Read ECOFF debugging information from a .mdebug section into a
4158 ecoff_debug_info structure. */
4161 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
4164 struct ecoff_debug_info
*debug
;
4167 const struct ecoff_debug_swap
*swap
;
4168 char *ext_hdr
= NULL
;
4170 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4171 memset (debug
, 0, sizeof (*debug
));
4173 ext_hdr
= (char *) bfd_malloc (swap
->external_hdr_size
);
4174 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
4177 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
4178 swap
->external_hdr_size
)
4182 symhdr
= &debug
->symbolic_header
;
4183 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
4185 /* The symbolic header contains absolute file offsets and sizes to
4187 #define READ(ptr, offset, count, size, type) \
4188 if (symhdr->count == 0) \
4189 debug->ptr = NULL; \
4192 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
4193 debug->ptr = (type) bfd_malloc (amt); \
4194 if (debug->ptr == NULL) \
4195 goto error_return; \
4196 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
4197 || bfd_bread (debug->ptr, amt, abfd) != amt) \
4198 goto error_return; \
4201 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
4202 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4203 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4204 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4205 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4206 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4208 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4209 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
4210 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4211 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4212 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
4216 debug
->adjust
= NULL
;
4221 if (ext_hdr
!= NULL
)
4223 if (debug
->line
!= NULL
)
4225 if (debug
->external_dnr
!= NULL
)
4226 free (debug
->external_dnr
);
4227 if (debug
->external_pdr
!= NULL
)
4228 free (debug
->external_pdr
);
4229 if (debug
->external_sym
!= NULL
)
4230 free (debug
->external_sym
);
4231 if (debug
->external_opt
!= NULL
)
4232 free (debug
->external_opt
);
4233 if (debug
->external_aux
!= NULL
)
4234 free (debug
->external_aux
);
4235 if (debug
->ss
!= NULL
)
4237 if (debug
->ssext
!= NULL
)
4238 free (debug
->ssext
);
4239 if (debug
->external_fdr
!= NULL
)
4240 free (debug
->external_fdr
);
4241 if (debug
->external_rfd
!= NULL
)
4242 free (debug
->external_rfd
);
4243 if (debug
->external_ext
!= NULL
)
4244 free (debug
->external_ext
);
4248 /* MIPS ELF local labels start with '$', not 'L'. */
4251 mips_elf_is_local_label_name (abfd
, name
)
4258 /* On Irix 6, the labels go back to starting with '.', so we accept
4259 the generic ELF local label syntax as well. */
4260 return _bfd_elf_is_local_label_name (abfd
, name
);
4263 /* MIPS ELF uses a special find_nearest_line routine in order the
4264 handle the ECOFF debugging information. */
4266 struct mips_elf_find_line
4268 struct ecoff_debug_info d
;
4269 struct ecoff_find_line i
;
4273 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
4274 functionname_ptr
, line_ptr
)
4279 const char **filename_ptr
;
4280 const char **functionname_ptr
;
4281 unsigned int *line_ptr
;
4285 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
4286 filename_ptr
, functionname_ptr
,
4290 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
4291 filename_ptr
, functionname_ptr
,
4293 (unsigned) (ABI_64_P (abfd
) ? 8 : 0),
4294 &elf_tdata (abfd
)->dwarf2_find_line_info
))
4297 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
4301 struct mips_elf_find_line
*fi
;
4302 const struct ecoff_debug_swap
* const swap
=
4303 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4305 /* If we are called during a link, mips_elf_final_link may have
4306 cleared the SEC_HAS_CONTENTS field. We force it back on here
4307 if appropriate (which it normally will be). */
4308 origflags
= msec
->flags
;
4309 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
4310 msec
->flags
|= SEC_HAS_CONTENTS
;
4312 fi
= elf_tdata (abfd
)->find_line_info
;
4315 bfd_size_type external_fdr_size
;
4318 struct fdr
*fdr_ptr
;
4319 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
4321 fi
= (struct mips_elf_find_line
*) bfd_zalloc (abfd
, amt
);
4324 msec
->flags
= origflags
;
4328 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
4330 msec
->flags
= origflags
;
4334 /* Swap in the FDR information. */
4335 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
4336 fi
->d
.fdr
= (struct fdr
*) bfd_alloc (abfd
, amt
);
4337 if (fi
->d
.fdr
== NULL
)
4339 msec
->flags
= origflags
;
4342 external_fdr_size
= swap
->external_fdr_size
;
4343 fdr_ptr
= fi
->d
.fdr
;
4344 fraw_src
= (char *) fi
->d
.external_fdr
;
4345 fraw_end
= (fraw_src
4346 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
4347 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
4348 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
4350 elf_tdata (abfd
)->find_line_info
= fi
;
4352 /* Note that we don't bother to ever free this information.
4353 find_nearest_line is either called all the time, as in
4354 objdump -l, so the information should be saved, or it is
4355 rarely called, as in ld error messages, so the memory
4356 wasted is unimportant. Still, it would probably be a
4357 good idea for free_cached_info to throw it away. */
4360 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
4361 &fi
->i
, filename_ptr
, functionname_ptr
,
4364 msec
->flags
= origflags
;
4368 msec
->flags
= origflags
;
4371 /* Fall back on the generic ELF find_nearest_line routine. */
4373 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
4374 filename_ptr
, functionname_ptr
,
4378 /* The mips16 compiler uses a couple of special sections to handle
4379 floating point arguments.
4381 Section names that look like .mips16.fn.FNNAME contain stubs that
4382 copy floating point arguments from the fp regs to the gp regs and
4383 then jump to FNNAME. If any 32 bit function calls FNNAME, the
4384 call should be redirected to the stub instead. If no 32 bit
4385 function calls FNNAME, the stub should be discarded. We need to
4386 consider any reference to the function, not just a call, because
4387 if the address of the function is taken we will need the stub,
4388 since the address might be passed to a 32 bit function.
4390 Section names that look like .mips16.call.FNNAME contain stubs
4391 that copy floating point arguments from the gp regs to the fp
4392 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
4393 then any 16 bit function that calls FNNAME should be redirected
4394 to the stub instead. If FNNAME is not a 32 bit function, the
4395 stub should be discarded.
4397 .mips16.call.fp.FNNAME sections are similar, but contain stubs
4398 which call FNNAME and then copy the return value from the fp regs
4399 to the gp regs. These stubs store the return value in $18 while
4400 calling FNNAME; any function which might call one of these stubs
4401 must arrange to save $18 around the call. (This case is not
4402 needed for 32 bit functions that call 16 bit functions, because
4403 16 bit functions always return floating point values in both
4406 Note that in all cases FNNAME might be defined statically.
4407 Therefore, FNNAME is not used literally. Instead, the relocation
4408 information will indicate which symbol the section is for.
4410 We record any stubs that we find in the symbol table. */
4412 #define FN_STUB ".mips16.fn."
4413 #define CALL_STUB ".mips16.call."
4414 #define CALL_FP_STUB ".mips16.call.fp."
4416 /* MIPS ELF linker hash table. */
4418 struct mips_elf_link_hash_table
4420 struct elf_link_hash_table root
;
4422 /* We no longer use this. */
4423 /* String section indices for the dynamic section symbols. */
4424 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
4426 /* The number of .rtproc entries. */
4427 bfd_size_type procedure_count
;
4428 /* The size of the .compact_rel section (if SGI_COMPAT). */
4429 bfd_size_type compact_rel_size
;
4430 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
4431 entry is set to the address of __rld_obj_head as in Irix 5. */
4432 boolean use_rld_obj_head
;
4433 /* This is the value of the __rld_map or __rld_obj_head symbol. */
4435 /* This is set if we see any mips16 stub sections. */
4436 boolean mips16_stubs_seen
;
4439 /* Look up an entry in a MIPS ELF linker hash table. */
4441 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
4442 ((struct mips_elf_link_hash_entry *) \
4443 elf_link_hash_lookup (&(table)->root, (string), (create), \
4446 /* Traverse a MIPS ELF linker hash table. */
4448 #define mips_elf_link_hash_traverse(table, func, info) \
4449 (elf_link_hash_traverse \
4451 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
4454 /* Get the MIPS ELF linker hash table from a link_info structure. */
4456 #define mips_elf_hash_table(p) \
4457 ((struct mips_elf_link_hash_table *) ((p)->hash))
4459 static boolean mips_elf_output_extsym
4460 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
4462 /* Create an entry in a MIPS ELF linker hash table. */
4464 static struct bfd_hash_entry
*
4465 mips_elf_link_hash_newfunc (entry
, table
, string
)
4466 struct bfd_hash_entry
*entry
;
4467 struct bfd_hash_table
*table
;
4470 struct mips_elf_link_hash_entry
*ret
=
4471 (struct mips_elf_link_hash_entry
*) entry
;
4473 /* Allocate the structure if it has not already been allocated by a
4475 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
4476 ret
= ((struct mips_elf_link_hash_entry
*)
4477 bfd_hash_allocate (table
,
4478 sizeof (struct mips_elf_link_hash_entry
)));
4479 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
4480 return (struct bfd_hash_entry
*) ret
;
4482 /* Call the allocation method of the superclass. */
4483 ret
= ((struct mips_elf_link_hash_entry
*)
4484 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
4486 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
4488 /* Set local fields. */
4489 memset (&ret
->esym
, 0, sizeof (EXTR
));
4490 /* We use -2 as a marker to indicate that the information has
4491 not been set. -1 means there is no associated ifd. */
4493 ret
->possibly_dynamic_relocs
= 0;
4494 ret
->readonly_reloc
= false;
4495 ret
->min_dyn_reloc_index
= 0;
4496 ret
->no_fn_stub
= false;
4497 ret
->fn_stub
= NULL
;
4498 ret
->need_fn_stub
= false;
4499 ret
->call_stub
= NULL
;
4500 ret
->call_fp_stub
= NULL
;
4503 return (struct bfd_hash_entry
*) ret
;
4507 _bfd_mips_elf_hide_symbol (info
, entry
)
4508 struct bfd_link_info
*info
;
4509 struct elf_link_hash_entry
*entry
;
4513 struct mips_got_info
*g
;
4514 struct mips_elf_link_hash_entry
*h
;
4515 h
= (struct mips_elf_link_hash_entry
*) entry
;
4516 dynobj
= elf_hash_table (info
)->dynobj
;
4517 got
= bfd_get_section_by_name (dynobj
, ".got");
4518 g
= (struct mips_got_info
*) elf_section_data (got
)->tdata
;
4520 h
->root
.elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4521 h
->root
.plt
.offset
= (bfd_vma
) -1;
4522 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
4523 h
->root
.dynindx
= -1;
4525 /* FIXME: Do we allocate too much GOT space here? */
4527 got
->_raw_size
+= MIPS_ELF_GOT_SIZE (dynobj
);
4530 /* Create a MIPS ELF linker hash table. */
4532 struct bfd_link_hash_table
*
4533 _bfd_mips_elf_link_hash_table_create (abfd
)
4536 struct mips_elf_link_hash_table
*ret
;
4537 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
4539 ret
= (struct mips_elf_link_hash_table
*) bfd_alloc (abfd
, amt
);
4540 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
4543 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
4544 mips_elf_link_hash_newfunc
))
4546 bfd_release (abfd
, ret
);
4551 /* We no longer use this. */
4552 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
4553 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
4555 ret
->procedure_count
= 0;
4556 ret
->compact_rel_size
= 0;
4557 ret
->use_rld_obj_head
= false;
4559 ret
->mips16_stubs_seen
= false;
4561 return &ret
->root
.root
;
4564 /* Hook called by the linker routine which adds symbols from an object
4565 file. We must handle the special MIPS section numbers here. */
4568 _bfd_mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
4570 struct bfd_link_info
*info
;
4571 const Elf_Internal_Sym
*sym
;
4573 flagword
*flagsp ATTRIBUTE_UNUSED
;
4577 if (SGI_COMPAT (abfd
)
4578 && (abfd
->flags
& DYNAMIC
) != 0
4579 && strcmp (*namep
, "_rld_new_interface") == 0)
4581 /* Skip Irix 5 rld entry name. */
4586 switch (sym
->st_shndx
)
4589 /* Common symbols less than the GP size are automatically
4590 treated as SHN_MIPS_SCOMMON symbols. */
4591 if (sym
->st_size
> elf_gp_size (abfd
)
4592 || IRIX_COMPAT (abfd
) == ict_irix6
)
4595 case SHN_MIPS_SCOMMON
:
4596 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
4597 (*secp
)->flags
|= SEC_IS_COMMON
;
4598 *valp
= sym
->st_size
;
4602 /* This section is used in a shared object. */
4603 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
4605 asymbol
*elf_text_symbol
;
4606 asection
*elf_text_section
;
4607 bfd_size_type amt
= sizeof (asection
);
4609 elf_text_section
= bfd_zalloc (abfd
, amt
);
4610 if (elf_text_section
== NULL
)
4613 amt
= sizeof (asymbol
);
4614 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
4615 if (elf_text_symbol
== NULL
)
4618 /* Initialize the section. */
4620 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
4621 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
4623 elf_text_section
->symbol
= elf_text_symbol
;
4624 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
4626 elf_text_section
->name
= ".text";
4627 elf_text_section
->flags
= SEC_NO_FLAGS
;
4628 elf_text_section
->output_section
= NULL
;
4629 elf_text_section
->owner
= abfd
;
4630 elf_text_symbol
->name
= ".text";
4631 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
4632 elf_text_symbol
->section
= elf_text_section
;
4634 /* This code used to do *secp = bfd_und_section_ptr if
4635 info->shared. I don't know why, and that doesn't make sense,
4636 so I took it out. */
4637 *secp
= elf_tdata (abfd
)->elf_text_section
;
4640 case SHN_MIPS_ACOMMON
:
4641 /* Fall through. XXX Can we treat this as allocated data? */
4643 /* This section is used in a shared object. */
4644 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
4646 asymbol
*elf_data_symbol
;
4647 asection
*elf_data_section
;
4648 bfd_size_type amt
= sizeof (asection
);
4650 elf_data_section
= bfd_zalloc (abfd
, amt
);
4651 if (elf_data_section
== NULL
)
4654 amt
= sizeof (asymbol
);
4655 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
4656 if (elf_data_symbol
== NULL
)
4659 /* Initialize the section. */
4661 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
4662 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
4664 elf_data_section
->symbol
= elf_data_symbol
;
4665 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
4667 elf_data_section
->name
= ".data";
4668 elf_data_section
->flags
= SEC_NO_FLAGS
;
4669 elf_data_section
->output_section
= NULL
;
4670 elf_data_section
->owner
= abfd
;
4671 elf_data_symbol
->name
= ".data";
4672 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
4673 elf_data_symbol
->section
= elf_data_section
;
4675 /* This code used to do *secp = bfd_und_section_ptr if
4676 info->shared. I don't know why, and that doesn't make sense,
4677 so I took it out. */
4678 *secp
= elf_tdata (abfd
)->elf_data_section
;
4681 case SHN_MIPS_SUNDEFINED
:
4682 *secp
= bfd_und_section_ptr
;
4686 if (SGI_COMPAT (abfd
)
4688 && info
->hash
->creator
== abfd
->xvec
4689 && strcmp (*namep
, "__rld_obj_head") == 0)
4691 struct elf_link_hash_entry
*h
;
4693 /* Mark __rld_obj_head as dynamic. */
4695 if (! (_bfd_generic_link_add_one_symbol
4696 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
4697 (bfd_vma
) *valp
, (const char *) NULL
, false,
4698 get_elf_backend_data (abfd
)->collect
,
4699 (struct bfd_link_hash_entry
**) &h
)))
4701 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
4702 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4703 h
->type
= STT_OBJECT
;
4705 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4708 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
4711 /* If this is a mips16 text symbol, add 1 to the value to make it
4712 odd. This will cause something like .word SYM to come up with
4713 the right value when it is loaded into the PC. */
4714 if (sym
->st_other
== STO_MIPS16
)
4720 /* Structure used to pass information to mips_elf_output_extsym. */
4725 struct bfd_link_info
*info
;
4726 struct ecoff_debug_info
*debug
;
4727 const struct ecoff_debug_swap
*swap
;
4731 /* This routine is used to write out ECOFF debugging external symbol
4732 information. It is called via mips_elf_link_hash_traverse. The
4733 ECOFF external symbol information must match the ELF external
4734 symbol information. Unfortunately, at this point we don't know
4735 whether a symbol is required by reloc information, so the two
4736 tables may wind up being different. We must sort out the external
4737 symbol information before we can set the final size of the .mdebug
4738 section, and we must set the size of the .mdebug section before we
4739 can relocate any sections, and we can't know which symbols are
4740 required by relocation until we relocate the sections.
4741 Fortunately, it is relatively unlikely that any symbol will be
4742 stripped but required by a reloc. In particular, it can not happen
4743 when generating a final executable. */
4746 mips_elf_output_extsym (h
, data
)
4747 struct mips_elf_link_hash_entry
*h
;
4750 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
4752 asection
*sec
, *output_section
;
4754 if (h
->root
.indx
== -2)
4756 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4757 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
4758 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
4759 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
4761 else if (einfo
->info
->strip
== strip_all
4762 || (einfo
->info
->strip
== strip_some
4763 && bfd_hash_lookup (einfo
->info
->keep_hash
,
4764 h
->root
.root
.root
.string
,
4765 false, false) == NULL
))
4773 if (h
->esym
.ifd
== -2)
4776 h
->esym
.cobol_main
= 0;
4777 h
->esym
.weakext
= 0;
4778 h
->esym
.reserved
= 0;
4779 h
->esym
.ifd
= ifdNil
;
4780 h
->esym
.asym
.value
= 0;
4781 h
->esym
.asym
.st
= stGlobal
;
4783 if (h
->root
.root
.type
== bfd_link_hash_undefined
4784 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
4788 /* Use undefined class. Also, set class and type for some
4790 name
= h
->root
.root
.root
.string
;
4791 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
4792 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
4794 h
->esym
.asym
.sc
= scData
;
4795 h
->esym
.asym
.st
= stLabel
;
4796 h
->esym
.asym
.value
= 0;
4798 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
4800 h
->esym
.asym
.sc
= scAbs
;
4801 h
->esym
.asym
.st
= stLabel
;
4802 h
->esym
.asym
.value
=
4803 mips_elf_hash_table (einfo
->info
)->procedure_count
;
4805 else if (strcmp (name
, "_gp_disp") == 0)
4807 h
->esym
.asym
.sc
= scAbs
;
4808 h
->esym
.asym
.st
= stLabel
;
4809 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
4812 h
->esym
.asym
.sc
= scUndefined
;
4814 else if (h
->root
.root
.type
!= bfd_link_hash_defined
4815 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
4816 h
->esym
.asym
.sc
= scAbs
;
4821 sec
= h
->root
.root
.u
.def
.section
;
4822 output_section
= sec
->output_section
;
4824 /* When making a shared library and symbol h is the one from
4825 the another shared library, OUTPUT_SECTION may be null. */
4826 if (output_section
== NULL
)
4827 h
->esym
.asym
.sc
= scUndefined
;
4830 name
= bfd_section_name (output_section
->owner
, output_section
);
4832 if (strcmp (name
, ".text") == 0)
4833 h
->esym
.asym
.sc
= scText
;
4834 else if (strcmp (name
, ".data") == 0)
4835 h
->esym
.asym
.sc
= scData
;
4836 else if (strcmp (name
, ".sdata") == 0)
4837 h
->esym
.asym
.sc
= scSData
;
4838 else if (strcmp (name
, ".rodata") == 0
4839 || strcmp (name
, ".rdata") == 0)
4840 h
->esym
.asym
.sc
= scRData
;
4841 else if (strcmp (name
, ".bss") == 0)
4842 h
->esym
.asym
.sc
= scBss
;
4843 else if (strcmp (name
, ".sbss") == 0)
4844 h
->esym
.asym
.sc
= scSBss
;
4845 else if (strcmp (name
, ".init") == 0)
4846 h
->esym
.asym
.sc
= scInit
;
4847 else if (strcmp (name
, ".fini") == 0)
4848 h
->esym
.asym
.sc
= scFini
;
4850 h
->esym
.asym
.sc
= scAbs
;
4854 h
->esym
.asym
.reserved
= 0;
4855 h
->esym
.asym
.index
= indexNil
;
4858 if (h
->root
.root
.type
== bfd_link_hash_common
)
4859 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
4860 else if (h
->root
.root
.type
== bfd_link_hash_defined
4861 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4863 if (h
->esym
.asym
.sc
== scCommon
)
4864 h
->esym
.asym
.sc
= scBss
;
4865 else if (h
->esym
.asym
.sc
== scSCommon
)
4866 h
->esym
.asym
.sc
= scSBss
;
4868 sec
= h
->root
.root
.u
.def
.section
;
4869 output_section
= sec
->output_section
;
4870 if (output_section
!= NULL
)
4871 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
4872 + sec
->output_offset
4873 + output_section
->vma
);
4875 h
->esym
.asym
.value
= 0;
4877 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4879 struct mips_elf_link_hash_entry
*hd
= h
;
4880 boolean no_fn_stub
= h
->no_fn_stub
;
4882 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
4884 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
4885 no_fn_stub
= no_fn_stub
|| hd
->no_fn_stub
;
4890 /* Set type and value for a symbol with a function stub. */
4891 h
->esym
.asym
.st
= stProc
;
4892 sec
= hd
->root
.root
.u
.def
.section
;
4894 h
->esym
.asym
.value
= 0;
4897 output_section
= sec
->output_section
;
4898 if (output_section
!= NULL
)
4899 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
4900 + sec
->output_offset
4901 + output_section
->vma
);
4903 h
->esym
.asym
.value
= 0;
4911 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
4912 h
->root
.root
.root
.string
,
4915 einfo
->failed
= true;
4922 /* Create a runtime procedure table from the .mdebug section. */
4925 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
4928 struct bfd_link_info
*info
;
4930 struct ecoff_debug_info
*debug
;
4932 const struct ecoff_debug_swap
*swap
;
4933 HDRR
*hdr
= &debug
->symbolic_header
;
4935 struct rpdr_ext
*erp
;
4937 struct pdr_ext
*epdr
;
4938 struct sym_ext
*esym
;
4942 bfd_size_type count
;
4943 unsigned long sindex
;
4947 const char *no_name_func
= _("static procedure (no name)");
4955 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4957 sindex
= strlen (no_name_func
) + 1;
4958 count
= hdr
->ipdMax
;
4961 size
= swap
->external_pdr_size
;
4963 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
4967 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
4970 size
= sizeof (RPDR
);
4971 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
4975 size
= sizeof (char *);
4976 sv
= (char **) bfd_malloc (size
* count
);
4980 count
= hdr
->isymMax
;
4981 size
= swap
->external_sym_size
;
4982 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
4986 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
4989 count
= hdr
->issMax
;
4990 ss
= (char *) bfd_malloc (count
);
4993 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
4996 count
= hdr
->ipdMax
;
4997 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
4999 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
5000 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
5001 rp
->adr
= sym
.value
;
5002 rp
->regmask
= pdr
.regmask
;
5003 rp
->regoffset
= pdr
.regoffset
;
5004 rp
->fregmask
= pdr
.fregmask
;
5005 rp
->fregoffset
= pdr
.fregoffset
;
5006 rp
->frameoffset
= pdr
.frameoffset
;
5007 rp
->framereg
= pdr
.framereg
;
5008 rp
->pcreg
= pdr
.pcreg
;
5010 sv
[i
] = ss
+ sym
.iss
;
5011 sindex
+= strlen (sv
[i
]) + 1;
5015 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
5016 size
= BFD_ALIGN (size
, 16);
5017 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
5020 mips_elf_hash_table (info
)->procedure_count
= 0;
5024 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
5026 erp
= (struct rpdr_ext
*) rtproc
;
5027 memset (erp
, 0, sizeof (struct rpdr_ext
));
5029 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
5030 strcpy (str
, no_name_func
);
5031 str
+= strlen (no_name_func
) + 1;
5032 for (i
= 0; i
< count
; i
++)
5034 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
5035 strcpy (str
, sv
[i
]);
5036 str
+= strlen (sv
[i
]) + 1;
5038 ECOFF_PUT_OFF (abfd
, -1, (erp
+ count
)->p_adr
);
5040 /* Set the size and contents of .rtproc section. */
5041 s
->_raw_size
= size
;
5042 s
->contents
= (bfd_byte
*) rtproc
;
5044 /* Skip this section later on (I don't think this currently
5045 matters, but someday it might). */
5046 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
5075 /* A comparison routine used to sort .gptab entries. */
5078 gptab_compare (p1
, p2
)
5082 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
5083 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
5085 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
5088 /* We need to use a special link routine to handle the .reginfo and
5089 the .mdebug sections. We need to merge all instances of these
5090 sections together, not write them all out sequentially. */
5093 _bfd_mips_elf_final_link (abfd
, info
)
5095 struct bfd_link_info
*info
;
5099 struct bfd_link_order
*p
;
5100 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
5101 asection
*rtproc_sec
;
5102 Elf32_RegInfo reginfo
;
5103 struct ecoff_debug_info debug
;
5104 const struct ecoff_debug_swap
*swap
5105 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
5106 HDRR
*symhdr
= &debug
.symbolic_header
;
5107 PTR mdebug_handle
= NULL
;
5113 static const char * const secname
[] =
5115 ".text", ".init", ".fini", ".data",
5116 ".rodata", ".sdata", ".sbss", ".bss"
5118 static const int sc
[] =
5120 scText
, scInit
, scFini
, scData
,
5121 scRData
, scSData
, scSBss
, scBss
5124 /* If all the things we linked together were PIC, but we're
5125 producing an executable (rather than a shared object), then the
5126 resulting file is CPIC (i.e., it calls PIC code.) */
5128 && !info
->relocateable
5129 && elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
5131 elf_elfheader (abfd
)->e_flags
&= ~EF_MIPS_PIC
;
5132 elf_elfheader (abfd
)->e_flags
|= EF_MIPS_CPIC
;
5135 /* We'd carefully arranged the dynamic symbol indices, and then the
5136 generic size_dynamic_sections renumbered them out from under us.
5137 Rather than trying somehow to prevent the renumbering, just do
5139 if (elf_hash_table (info
)->dynamic_sections_created
)
5143 struct mips_got_info
*g
;
5145 /* When we resort, we must tell mips_elf_sort_hash_table what
5146 the lowest index it may use is. That's the number of section
5147 symbols we're going to add. The generic ELF linker only
5148 adds these symbols when building a shared object. Note that
5149 we count the sections after (possibly) removing the .options
5151 if (!mips_elf_sort_hash_table (info
, (info
->shared
5152 ? bfd_count_sections (abfd
) + 1
5156 /* Make sure we didn't grow the global .got region. */
5157 dynobj
= elf_hash_table (info
)->dynobj
;
5158 got
= bfd_get_section_by_name (dynobj
, ".got");
5159 g
= (struct mips_got_info
*) elf_section_data (got
)->tdata
;
5161 if (g
->global_gotsym
!= NULL
)
5162 BFD_ASSERT ((elf_hash_table (info
)->dynsymcount
5163 - g
->global_gotsym
->dynindx
)
5164 <= g
->global_gotno
);
5167 /* On IRIX5, we omit the .options section. On IRIX6, however, we
5168 include it, even though we don't process it quite right. (Some
5169 entries are supposed to be merged.) Empirically, we seem to be
5170 better off including it then not. */
5171 if (IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
5172 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
5174 if (strcmp ((*secpp
)->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
5176 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
5177 if (p
->type
== bfd_indirect_link_order
)
5178 p
->u
.indirect
.section
->flags
&= ~SEC_HAS_CONTENTS
;
5179 (*secpp
)->link_order_head
= NULL
;
5180 *secpp
= (*secpp
)->next
;
5181 --abfd
->section_count
;
5187 /* Get a value for the GP register. */
5188 if (elf_gp (abfd
) == 0)
5190 struct bfd_link_hash_entry
*h
;
5192 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
5193 if (h
!= (struct bfd_link_hash_entry
*) NULL
5194 && h
->type
== bfd_link_hash_defined
)
5195 elf_gp (abfd
) = (h
->u
.def
.value
5196 + h
->u
.def
.section
->output_section
->vma
5197 + h
->u
.def
.section
->output_offset
);
5198 else if (info
->relocateable
)
5202 /* Find the GP-relative section with the lowest offset. */
5204 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
5206 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
5209 /* And calculate GP relative to that. */
5210 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
5214 /* If the relocate_section function needs to do a reloc
5215 involving the GP value, it should make a reloc_dangerous
5216 callback to warn that GP is not defined. */
5220 /* Go through the sections and collect the .reginfo and .mdebug
5224 gptab_data_sec
= NULL
;
5225 gptab_bss_sec
= NULL
;
5226 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
5228 if (strcmp (o
->name
, ".reginfo") == 0)
5230 memset (®info
, 0, sizeof reginfo
);
5232 /* We have found the .reginfo section in the output file.
5233 Look through all the link_orders comprising it and merge
5234 the information together. */
5235 for (p
= o
->link_order_head
;
5236 p
!= (struct bfd_link_order
*) NULL
;
5239 asection
*input_section
;
5241 Elf32_External_RegInfo ext
;
5244 if (p
->type
!= bfd_indirect_link_order
)
5246 if (p
->type
== bfd_fill_link_order
)
5251 input_section
= p
->u
.indirect
.section
;
5252 input_bfd
= input_section
->owner
;
5254 /* The linker emulation code has probably clobbered the
5255 size to be zero bytes. */
5256 if (input_section
->_raw_size
== 0)
5257 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
5259 if (! bfd_get_section_contents (input_bfd
, input_section
,
5262 (bfd_size_type
) sizeof ext
))
5265 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
5267 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
5268 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
5269 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
5270 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
5271 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
5273 /* ri_gp_value is set by the function
5274 mips_elf32_section_processing when the section is
5275 finally written out. */
5277 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5278 elf_link_input_bfd ignores this section. */
5279 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
5282 /* Size has been set in mips_elf_always_size_sections */
5283 BFD_ASSERT(o
->_raw_size
== sizeof (Elf32_External_RegInfo
));
5285 /* Skip this section later on (I don't think this currently
5286 matters, but someday it might). */
5287 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
5292 if (strcmp (o
->name
, ".mdebug") == 0)
5294 struct extsym_info einfo
;
5297 /* We have found the .mdebug section in the output file.
5298 Look through all the link_orders comprising it and merge
5299 the information together. */
5300 symhdr
->magic
= swap
->sym_magic
;
5301 /* FIXME: What should the version stamp be? */
5303 symhdr
->ilineMax
= 0;
5307 symhdr
->isymMax
= 0;
5308 symhdr
->ioptMax
= 0;
5309 symhdr
->iauxMax
= 0;
5311 symhdr
->issExtMax
= 0;
5314 symhdr
->iextMax
= 0;
5316 /* We accumulate the debugging information itself in the
5317 debug_info structure. */
5319 debug
.external_dnr
= NULL
;
5320 debug
.external_pdr
= NULL
;
5321 debug
.external_sym
= NULL
;
5322 debug
.external_opt
= NULL
;
5323 debug
.external_aux
= NULL
;
5325 debug
.ssext
= debug
.ssext_end
= NULL
;
5326 debug
.external_fdr
= NULL
;
5327 debug
.external_rfd
= NULL
;
5328 debug
.external_ext
= debug
.external_ext_end
= NULL
;
5330 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
5331 if (mdebug_handle
== (PTR
) NULL
)
5335 esym
.cobol_main
= 0;
5339 esym
.asym
.iss
= issNil
;
5340 esym
.asym
.st
= stLocal
;
5341 esym
.asym
.reserved
= 0;
5342 esym
.asym
.index
= indexNil
;
5344 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
5346 esym
.asym
.sc
= sc
[i
];
5347 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
5350 esym
.asym
.value
= s
->vma
;
5351 last
= s
->vma
+ s
->_raw_size
;
5354 esym
.asym
.value
= last
;
5355 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
5360 for (p
= o
->link_order_head
;
5361 p
!= (struct bfd_link_order
*) NULL
;
5364 asection
*input_section
;
5366 const struct ecoff_debug_swap
*input_swap
;
5367 struct ecoff_debug_info input_debug
;
5371 if (p
->type
!= bfd_indirect_link_order
)
5373 if (p
->type
== bfd_fill_link_order
)
5378 input_section
= p
->u
.indirect
.section
;
5379 input_bfd
= input_section
->owner
;
5381 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
5382 || (get_elf_backend_data (input_bfd
)
5383 ->elf_backend_ecoff_debug_swap
) == NULL
)
5385 /* I don't know what a non MIPS ELF bfd would be
5386 doing with a .mdebug section, but I don't really
5387 want to deal with it. */
5391 input_swap
= (get_elf_backend_data (input_bfd
)
5392 ->elf_backend_ecoff_debug_swap
);
5394 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
5396 /* The ECOFF linking code expects that we have already
5397 read in the debugging information and set up an
5398 ecoff_debug_info structure, so we do that now. */
5399 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
5403 if (! (bfd_ecoff_debug_accumulate
5404 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
5405 &input_debug
, input_swap
, info
)))
5408 /* Loop through the external symbols. For each one with
5409 interesting information, try to find the symbol in
5410 the linker global hash table and save the information
5411 for the output external symbols. */
5412 eraw_src
= input_debug
.external_ext
;
5413 eraw_end
= (eraw_src
5414 + (input_debug
.symbolic_header
.iextMax
5415 * input_swap
->external_ext_size
));
5417 eraw_src
< eraw_end
;
5418 eraw_src
+= input_swap
->external_ext_size
)
5422 struct mips_elf_link_hash_entry
*h
;
5424 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
5425 if (ext
.asym
.sc
== scNil
5426 || ext
.asym
.sc
== scUndefined
5427 || ext
.asym
.sc
== scSUndefined
)
5430 name
= input_debug
.ssext
+ ext
.asym
.iss
;
5431 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
5432 name
, false, false, true);
5433 if (h
== NULL
|| h
->esym
.ifd
!= -2)
5439 < input_debug
.symbolic_header
.ifdMax
);
5440 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
5446 /* Free up the information we just read. */
5447 free (input_debug
.line
);
5448 free (input_debug
.external_dnr
);
5449 free (input_debug
.external_pdr
);
5450 free (input_debug
.external_sym
);
5451 free (input_debug
.external_opt
);
5452 free (input_debug
.external_aux
);
5453 free (input_debug
.ss
);
5454 free (input_debug
.ssext
);
5455 free (input_debug
.external_fdr
);
5456 free (input_debug
.external_rfd
);
5457 free (input_debug
.external_ext
);
5459 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5460 elf_link_input_bfd ignores this section. */
5461 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
5464 if (SGI_COMPAT (abfd
) && info
->shared
)
5466 /* Create .rtproc section. */
5467 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
5468 if (rtproc_sec
== NULL
)
5470 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5471 | SEC_LINKER_CREATED
| SEC_READONLY
);
5473 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
5474 if (rtproc_sec
== NULL
5475 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
5476 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
5480 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
5481 info
, rtproc_sec
, &debug
))
5485 /* Build the external symbol information. */
5488 einfo
.debug
= &debug
;
5490 einfo
.failed
= false;
5491 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
5492 mips_elf_output_extsym
,
5497 /* Set the size of the .mdebug section. */
5498 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
5500 /* Skip this section later on (I don't think this currently
5501 matters, but someday it might). */
5502 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
5507 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
5509 const char *subname
;
5512 Elf32_External_gptab
*ext_tab
;
5515 /* The .gptab.sdata and .gptab.sbss sections hold
5516 information describing how the small data area would
5517 change depending upon the -G switch. These sections
5518 not used in executables files. */
5519 if (! info
->relocateable
)
5521 for (p
= o
->link_order_head
;
5522 p
!= (struct bfd_link_order
*) NULL
;
5525 asection
*input_section
;
5527 if (p
->type
!= bfd_indirect_link_order
)
5529 if (p
->type
== bfd_fill_link_order
)
5534 input_section
= p
->u
.indirect
.section
;
5536 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5537 elf_link_input_bfd ignores this section. */
5538 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
5541 /* Skip this section later on (I don't think this
5542 currently matters, but someday it might). */
5543 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
5545 /* Really remove the section. */
5546 for (secpp
= &abfd
->sections
;
5548 secpp
= &(*secpp
)->next
)
5550 *secpp
= (*secpp
)->next
;
5551 --abfd
->section_count
;
5556 /* There is one gptab for initialized data, and one for
5557 uninitialized data. */
5558 if (strcmp (o
->name
, ".gptab.sdata") == 0)
5560 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
5564 (*_bfd_error_handler
)
5565 (_("%s: illegal section name `%s'"),
5566 bfd_get_filename (abfd
), o
->name
);
5567 bfd_set_error (bfd_error_nonrepresentable_section
);
5571 /* The linker script always combines .gptab.data and
5572 .gptab.sdata into .gptab.sdata, and likewise for
5573 .gptab.bss and .gptab.sbss. It is possible that there is
5574 no .sdata or .sbss section in the output file, in which
5575 case we must change the name of the output section. */
5576 subname
= o
->name
+ sizeof ".gptab" - 1;
5577 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
5579 if (o
== gptab_data_sec
)
5580 o
->name
= ".gptab.data";
5582 o
->name
= ".gptab.bss";
5583 subname
= o
->name
+ sizeof ".gptab" - 1;
5584 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
5587 /* Set up the first entry. */
5589 amt
= c
* sizeof (Elf32_gptab
);
5590 tab
= (Elf32_gptab
*) bfd_malloc (amt
);
5593 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
5594 tab
[0].gt_header
.gt_unused
= 0;
5596 /* Combine the input sections. */
5597 for (p
= o
->link_order_head
;
5598 p
!= (struct bfd_link_order
*) NULL
;
5601 asection
*input_section
;
5605 bfd_size_type gpentry
;
5607 if (p
->type
!= bfd_indirect_link_order
)
5609 if (p
->type
== bfd_fill_link_order
)
5614 input_section
= p
->u
.indirect
.section
;
5615 input_bfd
= input_section
->owner
;
5617 /* Combine the gptab entries for this input section one
5618 by one. We know that the input gptab entries are
5619 sorted by ascending -G value. */
5620 size
= bfd_section_size (input_bfd
, input_section
);
5622 for (gpentry
= sizeof (Elf32_External_gptab
);
5624 gpentry
+= sizeof (Elf32_External_gptab
))
5626 Elf32_External_gptab ext_gptab
;
5627 Elf32_gptab int_gptab
;
5633 if (! (bfd_get_section_contents
5634 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
5636 (bfd_size_type
) sizeof (Elf32_External_gptab
))))
5642 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
5644 val
= int_gptab
.gt_entry
.gt_g_value
;
5645 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
5648 for (look
= 1; look
< c
; look
++)
5650 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
5651 tab
[look
].gt_entry
.gt_bytes
+= add
;
5653 if (tab
[look
].gt_entry
.gt_g_value
== val
)
5659 Elf32_gptab
*new_tab
;
5662 /* We need a new table entry. */
5663 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
5664 new_tab
= (Elf32_gptab
*) bfd_realloc ((PTR
) tab
, amt
);
5665 if (new_tab
== NULL
)
5671 tab
[c
].gt_entry
.gt_g_value
= val
;
5672 tab
[c
].gt_entry
.gt_bytes
= add
;
5674 /* Merge in the size for the next smallest -G
5675 value, since that will be implied by this new
5678 for (look
= 1; look
< c
; look
++)
5680 if (tab
[look
].gt_entry
.gt_g_value
< val
5682 || (tab
[look
].gt_entry
.gt_g_value
5683 > tab
[max
].gt_entry
.gt_g_value
)))
5687 tab
[c
].gt_entry
.gt_bytes
+=
5688 tab
[max
].gt_entry
.gt_bytes
;
5693 last
= int_gptab
.gt_entry
.gt_bytes
;
5696 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5697 elf_link_input_bfd ignores this section. */
5698 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
5701 /* The table must be sorted by -G value. */
5703 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
5705 /* Swap out the table. */
5706 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
5707 ext_tab
= (Elf32_External_gptab
*) bfd_alloc (abfd
, amt
);
5708 if (ext_tab
== NULL
)
5714 for (j
= 0; j
< c
; j
++)
5715 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
5718 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
5719 o
->contents
= (bfd_byte
*) ext_tab
;
5721 /* Skip this section later on (I don't think this currently
5722 matters, but someday it might). */
5723 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
5727 /* Invoke the regular ELF backend linker to do all the work. */
5728 if (ABI_64_P (abfd
))
5731 if (!bfd_elf64_bfd_final_link (abfd
, info
))
5738 else if (!bfd_elf32_bfd_final_link (abfd
, info
))
5741 /* Now write out the computed sections. */
5743 if (reginfo_sec
!= (asection
*) NULL
)
5745 Elf32_External_RegInfo ext
;
5747 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
5748 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
5749 (file_ptr
) 0, (bfd_size_type
) sizeof ext
))
5753 if (mdebug_sec
!= (asection
*) NULL
)
5755 BFD_ASSERT (abfd
->output_has_begun
);
5756 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
5758 mdebug_sec
->filepos
))
5761 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
5764 if (gptab_data_sec
!= (asection
*) NULL
)
5766 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
5767 gptab_data_sec
->contents
,
5769 gptab_data_sec
->_raw_size
))
5773 if (gptab_bss_sec
!= (asection
*) NULL
)
5775 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
5776 gptab_bss_sec
->contents
,
5778 gptab_bss_sec
->_raw_size
))
5782 if (SGI_COMPAT (abfd
))
5784 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
5785 if (rtproc_sec
!= NULL
)
5787 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
5788 rtproc_sec
->contents
,
5790 rtproc_sec
->_raw_size
))
5798 /* This function is called via qsort() to sort the dynamic relocation
5799 entries by increasing r_symndx value. */
5802 sort_dynamic_relocs (arg1
, arg2
)
5806 const Elf32_External_Rel
*ext_reloc1
= (const Elf32_External_Rel
*) arg1
;
5807 const Elf32_External_Rel
*ext_reloc2
= (const Elf32_External_Rel
*) arg2
;
5809 Elf_Internal_Rel int_reloc1
;
5810 Elf_Internal_Rel int_reloc2
;
5812 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, ext_reloc1
, &int_reloc1
);
5813 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, ext_reloc2
, &int_reloc2
);
5815 return (ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
));
5818 /* Returns the GOT section for ABFD. */
5821 mips_elf_got_section (abfd
)
5824 return bfd_get_section_by_name (abfd
, ".got");
5827 /* Returns the GOT information associated with the link indicated by
5828 INFO. If SGOTP is non-NULL, it is filled in with the GOT
5831 static struct mips_got_info
*
5832 mips_elf_got_info (abfd
, sgotp
)
5837 struct mips_got_info
*g
;
5839 sgot
= mips_elf_got_section (abfd
);
5840 BFD_ASSERT (sgot
!= NULL
);
5841 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5842 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5843 BFD_ASSERT (g
!= NULL
);
5850 /* Return whether a relocation is against a local symbol. */
5853 mips_elf_local_relocation_p (input_bfd
, relocation
, local_sections
,
5856 const Elf_Internal_Rela
*relocation
;
5857 asection
**local_sections
;
5858 boolean check_forced
;
5860 unsigned long r_symndx
;
5861 Elf_Internal_Shdr
*symtab_hdr
;
5862 struct mips_elf_link_hash_entry
*h
;
5865 r_symndx
= ELF32_R_SYM (relocation
->r_info
);
5866 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5867 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
5869 if (r_symndx
< extsymoff
)
5871 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
5876 /* Look up the hash table to check whether the symbol
5877 was forced local. */
5878 h
= (struct mips_elf_link_hash_entry
*)
5879 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
5880 /* Find the real hash-table entry for this symbol. */
5881 while (h
->root
.root
.type
== bfd_link_hash_indirect
5882 || h
->root
.root
.type
== bfd_link_hash_warning
)
5883 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
5884 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
5891 /* Sign-extend VALUE, which has the indicated number of BITS. */
5894 mips_elf_sign_extend (value
, bits
)
5898 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
5899 /* VALUE is negative. */
5900 value
|= ((bfd_vma
) - 1) << bits
;
5905 /* Return non-zero if the indicated VALUE has overflowed the maximum
5906 range expressable by a signed number with the indicated number of
5910 mips_elf_overflow_p (value
, bits
)
5914 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
5916 if (svalue
> (1 << (bits
- 1)) - 1)
5917 /* The value is too big. */
5919 else if (svalue
< -(1 << (bits
- 1)))
5920 /* The value is too small. */
5927 /* Calculate the %high function. */
5930 mips_elf_high (value
)
5933 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
5936 /* Calculate the %higher function. */
5939 mips_elf_higher (value
)
5940 bfd_vma value ATTRIBUTE_UNUSED
;
5943 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
5946 return (bfd_vma
) -1;
5950 /* Calculate the %highest function. */
5953 mips_elf_highest (value
)
5954 bfd_vma value ATTRIBUTE_UNUSED
;
5957 return ((value
+ (bfd_vma
) 0x800080008000) >> 48) & 0xffff;
5960 return (bfd_vma
) -1;
5964 /* Returns the GOT index for the global symbol indicated by H. */
5967 mips_elf_global_got_index (abfd
, h
)
5969 struct elf_link_hash_entry
*h
;
5973 struct mips_got_info
*g
;
5975 g
= mips_elf_got_info (abfd
, &sgot
);
5977 /* Once we determine the global GOT entry with the lowest dynamic
5978 symbol table index, we must put all dynamic symbols with greater
5979 indices into the GOT. That makes it easy to calculate the GOT
5981 BFD_ASSERT (h
->dynindx
>= g
->global_gotsym
->dynindx
);
5982 index
= ((h
->dynindx
- g
->global_gotsym
->dynindx
+ g
->local_gotno
)
5983 * MIPS_ELF_GOT_SIZE (abfd
));
5984 BFD_ASSERT (index
< sgot
->_raw_size
);
5989 /* Returns the offset for the entry at the INDEXth position
5993 mips_elf_got_offset_from_index (dynobj
, output_bfd
, index
)
6001 sgot
= mips_elf_got_section (dynobj
);
6002 gp
= _bfd_get_gp_value (output_bfd
);
6003 return (sgot
->output_section
->vma
+ sgot
->output_offset
+ index
-
6007 /* If H is a symbol that needs a global GOT entry, but has a dynamic
6008 symbol table index lower than any we've seen to date, record it for
6012 mips_elf_record_global_got_symbol (h
, info
, g
)
6013 struct elf_link_hash_entry
*h
;
6014 struct bfd_link_info
*info
;
6015 struct mips_got_info
*g ATTRIBUTE_UNUSED
;
6017 /* A global symbol in the GOT must also be in the dynamic symbol
6019 if (h
->dynindx
== -1
6020 && !bfd_elf32_link_record_dynamic_symbol (info
, h
))
6023 /* If we've already marked this entry as needing GOT space, we don't
6024 need to do it again. */
6025 if (h
->got
.offset
!= (bfd_vma
) -1)
6028 /* By setting this to a value other than -1, we are indicating that
6029 there needs to be a GOT entry for H. Avoid using zero, as the
6030 generic ELF copy_indirect_symbol tests for <= 0. */
6036 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
6037 the dynamic symbols. */
6039 struct mips_elf_hash_sort_data
6041 /* The symbol in the global GOT with the lowest dynamic symbol table
6043 struct elf_link_hash_entry
*low
;
6044 /* The least dynamic symbol table index corresponding to a symbol
6045 with a GOT entry. */
6046 long min_got_dynindx
;
6047 /* The greatest dynamic symbol table index not corresponding to a
6048 symbol without a GOT entry. */
6049 long max_non_got_dynindx
;
6052 /* If H needs a GOT entry, assign it the highest available dynamic
6053 index. Otherwise, assign it the lowest available dynamic
6057 mips_elf_sort_hash_table_f (h
, data
)
6058 struct mips_elf_link_hash_entry
*h
;
6061 struct mips_elf_hash_sort_data
*hsd
6062 = (struct mips_elf_hash_sort_data
*) data
;
6064 /* Symbols without dynamic symbol table entries aren't interesting
6066 if (h
->root
.dynindx
== -1)
6069 if (h
->root
.got
.offset
!= 1)
6070 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
6073 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
6074 hsd
->low
= (struct elf_link_hash_entry
*) h
;
6080 /* Sort the dynamic symbol table so that symbols that need GOT entries
6081 appear towards the end. This reduces the amount of GOT space
6082 required. MAX_LOCAL is used to set the number of local symbols
6083 known to be in the dynamic symbol table. During
6084 mips_elf_size_dynamic_sections, this value is 1. Afterward, the
6085 section symbols are added and the count is higher. */
6088 mips_elf_sort_hash_table (info
, max_local
)
6089 struct bfd_link_info
*info
;
6090 unsigned long max_local
;
6092 struct mips_elf_hash_sort_data hsd
;
6093 struct mips_got_info
*g
;
6096 dynobj
= elf_hash_table (info
)->dynobj
;
6099 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
;
6100 hsd
.max_non_got_dynindx
= max_local
;
6101 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
6102 elf_hash_table (info
)),
6103 mips_elf_sort_hash_table_f
,
6106 /* There should have been enough room in the symbol table to
6107 accomodate both the GOT and non-GOT symbols. */
6108 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
6110 /* Now we know which dynamic symbol has the lowest dynamic symbol
6111 table index in the GOT. */
6112 g
= mips_elf_got_info (dynobj
, NULL
);
6113 g
->global_gotsym
= hsd
.low
;
6118 /* Create a local GOT entry for VALUE. Return the index of the entry,
6119 or -1 if it could not be created. */
6122 mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
)
6124 struct mips_got_info
*g
;
6128 if (g
->assigned_gotno
>= g
->local_gotno
)
6130 /* We didn't allocate enough space in the GOT. */
6131 (*_bfd_error_handler
)
6132 (_("not enough GOT space for local GOT entries"));
6133 bfd_set_error (bfd_error_bad_value
);
6134 return (bfd_vma
) -1;
6137 MIPS_ELF_PUT_WORD (abfd
, value
,
6139 + MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
));
6140 return MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
6143 /* Returns the GOT offset at which the indicated address can be found.
6144 If there is not yet a GOT entry for this value, create one. Returns
6145 -1 if no satisfactory GOT offset can be found. */
6148 mips_elf_local_got_index (abfd
, info
, value
)
6150 struct bfd_link_info
*info
;
6154 struct mips_got_info
*g
;
6157 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
6159 /* Look to see if we already have an appropriate entry. */
6160 for (entry
= (sgot
->contents
6161 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
6162 entry
!= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
6163 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
6165 bfd_vma address
= MIPS_ELF_GET_WORD (abfd
, entry
);
6166 if (address
== value
)
6167 return entry
- sgot
->contents
;
6170 return mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
6173 /* Find a GOT entry that is within 32KB of the VALUE. These entries
6174 are supposed to be placed at small offsets in the GOT, i.e.,
6175 within 32KB of GP. Return the index into the GOT for this page,
6176 and store the offset from this entry to the desired address in
6177 OFFSETP, if it is non-NULL. */
6180 mips_elf_got_page (abfd
, info
, value
, offsetp
)
6182 struct bfd_link_info
*info
;
6187 struct mips_got_info
*g
;
6189 bfd_byte
*last_entry
;
6193 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
6195 /* Look to see if we aleady have an appropriate entry. */
6196 last_entry
= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
6197 for (entry
= (sgot
->contents
6198 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
6199 entry
!= last_entry
;
6200 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
6202 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
6204 if (!mips_elf_overflow_p (value
- address
, 16))
6206 /* This entry will serve as the page pointer. We can add a
6207 16-bit number to it to get the actual address. */
6208 index
= entry
- sgot
->contents
;
6213 /* If we didn't have an appropriate entry, we create one now. */
6214 if (entry
== last_entry
)
6215 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
6219 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
6220 *offsetp
= value
- address
;
6226 /* Find a GOT entry whose higher-order 16 bits are the same as those
6227 for value. Return the index into the GOT for this entry. */
6230 mips_elf_got16_entry (abfd
, info
, value
, external
)
6232 struct bfd_link_info
*info
;
6237 struct mips_got_info
*g
;
6239 bfd_byte
*last_entry
;
6245 /* Although the ABI says that it is "the high-order 16 bits" that we
6246 want, it is really the %high value. The complete value is
6247 calculated with a `addiu' of a LO16 relocation, just as with a
6249 value
= mips_elf_high (value
) << 16;
6252 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
6254 /* Look to see if we already have an appropriate entry. */
6255 last_entry
= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
6256 for (entry
= (sgot
->contents
6257 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
6258 entry
!= last_entry
;
6259 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
6261 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
6262 if (address
== value
)
6264 /* This entry has the right high-order 16 bits, and the low-order
6265 16 bits are set to zero. */
6266 index
= entry
- sgot
->contents
;
6271 /* If we didn't have an appropriate entry, we create one now. */
6272 if (entry
== last_entry
)
6273 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
6278 /* Returns the first relocation of type r_type found, beginning with
6279 RELOCATION. RELEND is one-past-the-end of the relocation table. */
6281 static const Elf_Internal_Rela
*
6282 mips_elf_next_relocation (r_type
, relocation
, relend
)
6283 unsigned int r_type
;
6284 const Elf_Internal_Rela
*relocation
;
6285 const Elf_Internal_Rela
*relend
;
6287 /* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be
6288 immediately following. However, for the IRIX6 ABI, the next
6289 relocation may be a composed relocation consisting of several
6290 relocations for the same address. In that case, the R_MIPS_LO16
6291 relocation may occur as one of these. We permit a similar
6292 extension in general, as that is useful for GCC. */
6293 while (relocation
< relend
)
6295 if (ELF32_R_TYPE (relocation
->r_info
) == r_type
)
6301 /* We didn't find it. */
6302 bfd_set_error (bfd_error_bad_value
);
6306 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
6307 is the original relocation, which is now being transformed into a
6308 dynamic relocation. The ADDENDP is adjusted if necessary; the
6309 caller should store the result in place of the original addend. */
6312 mips_elf_create_dynamic_relocation (output_bfd
, info
, rel
, h
, sec
,
6313 symbol
, addendp
, input_section
)
6315 struct bfd_link_info
*info
;
6316 const Elf_Internal_Rela
*rel
;
6317 struct mips_elf_link_hash_entry
*h
;
6321 asection
*input_section
;
6323 Elf_Internal_Rel outrel
;
6329 r_type
= ELF32_R_TYPE (rel
->r_info
);
6330 dynobj
= elf_hash_table (info
)->dynobj
;
6332 = bfd_get_section_by_name (dynobj
,
6333 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd
));
6334 BFD_ASSERT (sreloc
!= NULL
);
6335 BFD_ASSERT (sreloc
->contents
!= NULL
);
6336 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
6337 < sreloc
->_raw_size
);
6341 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
->r_offset
);
6342 if (outrel
.r_offset
== (bfd_vma
) -1)
6345 /* If we've decided to skip this relocation, just output an empty
6346 record. Note that R_MIPS_NONE == 0, so that this call to memset
6347 is a way of setting R_TYPE to R_MIPS_NONE. */
6349 memset (&outrel
, 0, sizeof (outrel
));
6353 bfd_vma section_offset
;
6355 /* We must now calculate the dynamic symbol table index to use
6356 in the relocation. */
6358 && (! info
->symbolic
|| (h
->root
.elf_link_hash_flags
6359 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
6361 indx
= h
->root
.dynindx
;
6362 /* h->root.dynindx may be -1 if this symbol was marked to
6369 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
6371 else if (sec
== NULL
|| sec
->owner
== NULL
)
6373 bfd_set_error (bfd_error_bad_value
);
6378 indx
= elf_section_data (sec
->output_section
)->dynindx
;
6383 /* Figure out how far the target of the relocation is from
6384 the beginning of its section. */
6385 section_offset
= symbol
- sec
->output_section
->vma
;
6386 /* The relocation we're building is section-relative.
6387 Therefore, the original addend must be adjusted by the
6389 *addendp
+= section_offset
;
6390 /* Now, the relocation is just against the section. */
6391 symbol
= sec
->output_section
->vma
;
6394 /* If the relocation was previously an absolute relocation and
6395 this symbol will not be referred to by the relocation, we must
6396 adjust it by the value we give it in the dynamic symbol table.
6397 Otherwise leave the job up to the dynamic linker. */
6398 if (!indx
&& r_type
!= R_MIPS_REL32
)
6401 /* The relocation is always an REL32 relocation because we don't
6402 know where the shared library will wind up at load-time. */
6403 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
6405 /* Adjust the output offset of the relocation to reference the
6406 correct location in the output file. */
6407 outrel
.r_offset
+= (input_section
->output_section
->vma
6408 + input_section
->output_offset
);
6411 /* Put the relocation back out. We have to use the special
6412 relocation outputter in the 64-bit case since the 64-bit
6413 relocation format is non-standard. */
6414 if (ABI_64_P (output_bfd
))
6416 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
6417 (output_bfd
, &outrel
,
6419 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
6422 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
6423 (((Elf32_External_Rel
*)
6425 + sreloc
->reloc_count
));
6427 /* Record the index of the first relocation referencing H. This
6428 information is later emitted in the .msym section. */
6430 && (h
->min_dyn_reloc_index
== 0
6431 || sreloc
->reloc_count
< h
->min_dyn_reloc_index
))
6432 h
->min_dyn_reloc_index
= sreloc
->reloc_count
;
6434 /* We've now added another relocation. */
6435 ++sreloc
->reloc_count
;
6437 /* Make sure the output section is writable. The dynamic linker
6438 will be writing to it. */
6439 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
6442 /* On IRIX5, make an entry of compact relocation info. */
6443 if (! skip
&& IRIX_COMPAT (output_bfd
) == ict_irix5
)
6445 asection
*scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
6450 Elf32_crinfo cptrel
;
6452 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
6453 cptrel
.vaddr
= (rel
->r_offset
6454 + input_section
->output_section
->vma
6455 + input_section
->output_offset
);
6456 if (r_type
== R_MIPS_REL32
)
6457 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
6459 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
6460 mips_elf_set_cr_dist2to (cptrel
, 0);
6461 cptrel
.konst
= *addendp
;
6463 cr
= (scpt
->contents
6464 + sizeof (Elf32_External_compact_rel
));
6465 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
6466 ((Elf32_External_crinfo
*) cr
6467 + scpt
->reloc_count
));
6468 ++scpt
->reloc_count
;
6475 /* Calculate the value produced by the RELOCATION (which comes from
6476 the INPUT_BFD). The ADDEND is the addend to use for this
6477 RELOCATION; RELOCATION->R_ADDEND is ignored.
6479 The result of the relocation calculation is stored in VALUEP.
6480 REQUIRE_JALXP indicates whether or not the opcode used with this
6481 relocation must be JALX.
6483 This function returns bfd_reloc_continue if the caller need take no
6484 further action regarding this relocation, bfd_reloc_notsupported if
6485 something goes dramatically wrong, bfd_reloc_overflow if an
6486 overflow occurs, and bfd_reloc_ok to indicate success. */
6488 static bfd_reloc_status_type
6489 mips_elf_calculate_relocation (abfd
,
6503 asection
*input_section
;
6504 struct bfd_link_info
*info
;
6505 const Elf_Internal_Rela
*relocation
;
6507 reloc_howto_type
*howto
;
6508 Elf_Internal_Sym
*local_syms
;
6509 asection
**local_sections
;
6512 boolean
*require_jalxp
;
6514 /* The eventual value we will return. */
6516 /* The address of the symbol against which the relocation is
6519 /* The final GP value to be used for the relocatable, executable, or
6520 shared object file being produced. */
6521 bfd_vma gp
= (bfd_vma
) - 1;
6522 /* The place (section offset or address) of the storage unit being
6525 /* The value of GP used to create the relocatable object. */
6526 bfd_vma gp0
= (bfd_vma
) - 1;
6527 /* The offset into the global offset table at which the address of
6528 the relocation entry symbol, adjusted by the addend, resides
6529 during execution. */
6530 bfd_vma g
= (bfd_vma
) - 1;
6531 /* The section in which the symbol referenced by the relocation is
6533 asection
*sec
= NULL
;
6534 struct mips_elf_link_hash_entry
*h
= NULL
;
6535 /* True if the symbol referred to by this relocation is a local
6538 /* True if the symbol referred to by this relocation is "_gp_disp". */
6539 boolean gp_disp_p
= false;
6540 Elf_Internal_Shdr
*symtab_hdr
;
6542 unsigned long r_symndx
;
6544 /* True if overflow occurred during the calculation of the
6545 relocation value. */
6546 boolean overflowed_p
;
6547 /* True if this relocation refers to a MIPS16 function. */
6548 boolean target_is_16_bit_code_p
= false;
6550 /* Parse the relocation. */
6551 r_symndx
= ELF32_R_SYM (relocation
->r_info
);
6552 r_type
= ELF32_R_TYPE (relocation
->r_info
);
6553 p
= (input_section
->output_section
->vma
6554 + input_section
->output_offset
6555 + relocation
->r_offset
);
6557 /* Assume that there will be no overflow. */
6558 overflowed_p
= false;
6560 /* Figure out whether or not the symbol is local, and get the offset
6561 used in the array of hash table entries. */
6562 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
6563 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
6564 local_sections
, false);
6565 if (! elf_bad_symtab (input_bfd
))
6566 extsymoff
= symtab_hdr
->sh_info
;
6569 /* The symbol table does not follow the rule that local symbols
6570 must come before globals. */
6574 /* Figure out the value of the symbol. */
6577 Elf_Internal_Sym
*sym
;
6579 sym
= local_syms
+ r_symndx
;
6580 sec
= local_sections
[r_symndx
];
6582 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
6583 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
6584 symbol
+= sym
->st_value
;
6586 /* MIPS16 text labels should be treated as odd. */
6587 if (sym
->st_other
== STO_MIPS16
)
6590 /* Record the name of this symbol, for our caller. */
6591 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
6592 symtab_hdr
->sh_link
,
6595 *namep
= bfd_section_name (input_bfd
, sec
);
6597 target_is_16_bit_code_p
= (sym
->st_other
== STO_MIPS16
);
6601 /* For global symbols we look up the symbol in the hash-table. */
6602 h
= ((struct mips_elf_link_hash_entry
*)
6603 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
6604 /* Find the real hash-table entry for this symbol. */
6605 while (h
->root
.root
.type
== bfd_link_hash_indirect
6606 || h
->root
.root
.type
== bfd_link_hash_warning
)
6607 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
6609 /* Record the name of this symbol, for our caller. */
6610 *namep
= h
->root
.root
.root
.string
;
6612 /* See if this is the special _gp_disp symbol. Note that such a
6613 symbol must always be a global symbol. */
6614 if (strcmp (h
->root
.root
.root
.string
, "_gp_disp") == 0)
6616 /* Relocations against _gp_disp are permitted only with
6617 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
6618 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_LO16
)
6619 return bfd_reloc_notsupported
;
6623 /* If this symbol is defined, calculate its address. Note that
6624 _gp_disp is a magic symbol, always implicitly defined by the
6625 linker, so it's inappropriate to check to see whether or not
6627 else if ((h
->root
.root
.type
== bfd_link_hash_defined
6628 || h
->root
.root
.type
== bfd_link_hash_defweak
)
6629 && h
->root
.root
.u
.def
.section
)
6631 sec
= h
->root
.root
.u
.def
.section
;
6632 if (sec
->output_section
)
6633 symbol
= (h
->root
.root
.u
.def
.value
6634 + sec
->output_section
->vma
6635 + sec
->output_offset
);
6637 symbol
= h
->root
.root
.u
.def
.value
;
6639 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
6640 /* We allow relocations against undefined weak symbols, giving
6641 it the value zero, so that you can undefined weak functions
6642 and check to see if they exist by looking at their
6645 else if (info
->shared
6646 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
6647 && !info
->no_undefined
6648 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
6650 else if (strcmp (h
->root
.root
.root
.string
, "_DYNAMIC_LINK") == 0 ||
6651 strcmp (h
->root
.root
.root
.string
, "_DYNAMIC_LINKING") == 0)
6653 /* If this is a dynamic link, we should have created a
6654 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
6655 in in mips_elf_create_dynamic_sections.
6656 Otherwise, we should define the symbol with a value of 0.
6657 FIXME: It should probably get into the symbol table
6659 BFD_ASSERT (! info
->shared
);
6660 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
6665 if (! ((*info
->callbacks
->undefined_symbol
)
6666 (info
, h
->root
.root
.root
.string
, input_bfd
,
6667 input_section
, relocation
->r_offset
,
6668 (!info
->shared
|| info
->no_undefined
6669 || ELF_ST_VISIBILITY (h
->root
.other
)))))
6670 return bfd_reloc_undefined
;
6674 target_is_16_bit_code_p
= (h
->root
.other
== STO_MIPS16
);
6677 /* If this is a 32-bit call to a 16-bit function with a stub, we
6678 need to redirect the call to the stub, unless we're already *in*
6680 if (r_type
!= R_MIPS16_26
&& !info
->relocateable
6681 && ((h
!= NULL
&& h
->fn_stub
!= NULL
)
6682 || (local_p
&& elf_tdata (input_bfd
)->local_stubs
!= NULL
6683 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
6684 && !mips_elf_stub_section_p (input_bfd
, input_section
))
6686 /* This is a 32-bit call to a 16-bit function. We should
6687 have already noticed that we were going to need the
6690 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
6693 BFD_ASSERT (h
->need_fn_stub
);
6697 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
6699 /* If this is a 16-bit call to a 32-bit function with a stub, we
6700 need to redirect the call to the stub. */
6701 else if (r_type
== R_MIPS16_26
&& !info
->relocateable
6703 && (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
)
6704 && !target_is_16_bit_code_p
)
6706 /* If both call_stub and call_fp_stub are defined, we can figure
6707 out which one to use by seeing which one appears in the input
6709 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
6714 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
6716 if (strncmp (bfd_get_section_name (input_bfd
, o
),
6717 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6719 sec
= h
->call_fp_stub
;
6726 else if (h
->call_stub
!= NULL
)
6729 sec
= h
->call_fp_stub
;
6731 BFD_ASSERT (sec
->_raw_size
> 0);
6732 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
6735 /* Calls from 16-bit code to 32-bit code and vice versa require the
6736 special jalx instruction. */
6737 *require_jalxp
= (!info
->relocateable
6738 && ((r_type
== R_MIPS16_26
) != target_is_16_bit_code_p
));
6740 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
6741 local_sections
, true);
6743 /* If we haven't already determined the GOT offset, or the GP value,
6744 and we're going to need it, get it now. */
6749 case R_MIPS_GOT_DISP
:
6750 case R_MIPS_GOT_HI16
:
6751 case R_MIPS_CALL_HI16
:
6752 case R_MIPS_GOT_LO16
:
6753 case R_MIPS_CALL_LO16
:
6754 /* Find the index into the GOT where this value is located. */
6757 BFD_ASSERT (addend
== 0);
6758 g
= mips_elf_global_got_index
6759 (elf_hash_table (info
)->dynobj
,
6760 (struct elf_link_hash_entry
*) h
);
6761 if (! elf_hash_table(info
)->dynamic_sections_created
6763 && (info
->symbolic
|| h
->root
.dynindx
== -1)
6764 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
6766 /* This is a static link or a -Bsymbolic link. The
6767 symbol is defined locally, or was forced to be local.
6768 We must initialize this entry in the GOT. */
6769 asection
*sgot
= mips_elf_got_section(elf_hash_table
6771 MIPS_ELF_PUT_WORD (elf_hash_table (info
)->dynobj
,
6772 symbol
+ addend
, sgot
->contents
+ g
);
6775 else if (r_type
== R_MIPS_GOT16
|| r_type
== R_MIPS_CALL16
)
6776 /* There's no need to create a local GOT entry here; the
6777 calculation for a local GOT16 entry does not involve G. */
6781 g
= mips_elf_local_got_index (abfd
, info
, symbol
+ addend
);
6782 if (g
== (bfd_vma
) -1)
6786 /* Convert GOT indices to actual offsets. */
6787 g
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
6793 case R_MIPS_GPREL16
:
6794 case R_MIPS_GPREL32
:
6795 case R_MIPS_LITERAL
:
6796 gp0
= _bfd_get_gp_value (input_bfd
);
6797 gp
= _bfd_get_gp_value (abfd
);
6804 /* Figure out what kind of relocation is being performed. */
6808 return bfd_reloc_continue
;
6811 value
= symbol
+ mips_elf_sign_extend (addend
, 16);
6812 overflowed_p
= mips_elf_overflow_p (value
, 16);
6819 || (elf_hash_table (info
)->dynamic_sections_created
6821 && ((h
->root
.elf_link_hash_flags
6822 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0)
6823 && ((h
->root
.elf_link_hash_flags
6824 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
6826 && (input_section
->flags
& SEC_ALLOC
) != 0)
6828 /* If we're creating a shared library, or this relocation is
6829 against a symbol in a shared library, then we can't know
6830 where the symbol will end up. So, we create a relocation
6831 record in the output, and leave the job up to the dynamic
6834 if (!mips_elf_create_dynamic_relocation (abfd
,
6846 if (r_type
!= R_MIPS_REL32
)
6847 value
= symbol
+ addend
;
6851 value
&= howto
->dst_mask
;
6856 case R_MIPS_GNU_REL_LO16
:
6857 value
= symbol
+ addend
- p
;
6858 value
&= howto
->dst_mask
;
6861 case R_MIPS_GNU_REL16_S2
:
6862 value
= symbol
+ mips_elf_sign_extend (addend
<< 2, 18) - p
;
6863 overflowed_p
= mips_elf_overflow_p (value
, 18);
6864 value
= (value
>> 2) & howto
->dst_mask
;
6867 case R_MIPS_GNU_REL_HI16
:
6868 value
= mips_elf_high (addend
+ symbol
- p
);
6869 value
&= howto
->dst_mask
;
6873 /* The calculation for R_MIPS16_26 is just the same as for an
6874 R_MIPS_26. It's only the storage of the relocated field into
6875 the output file that's different. That's handled in
6876 mips_elf_perform_relocation. So, we just fall through to the
6877 R_MIPS_26 case here. */
6880 value
= (((addend
<< 2) | ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
6882 value
= (mips_elf_sign_extend (addend
<< 2, 28) + symbol
) >> 2;
6883 value
&= howto
->dst_mask
;
6889 value
= mips_elf_high (addend
+ symbol
);
6890 value
&= howto
->dst_mask
;
6894 value
= mips_elf_high (addend
+ gp
- p
);
6895 overflowed_p
= mips_elf_overflow_p (value
, 16);
6901 value
= (symbol
+ addend
) & howto
->dst_mask
;
6904 value
= addend
+ gp
- p
+ 4;
6905 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
6906 for overflow. But, on, say, Irix 5, relocations against
6907 _gp_disp are normally generated from the .cpload
6908 pseudo-op. It generates code that normally looks like
6911 lui $gp,%hi(_gp_disp)
6912 addiu $gp,$gp,%lo(_gp_disp)
6915 Here $t9 holds the address of the function being called,
6916 as required by the MIPS ELF ABI. The R_MIPS_LO16
6917 relocation can easily overflow in this situation, but the
6918 R_MIPS_HI16 relocation will handle the overflow.
6919 Therefore, we consider this a bug in the MIPS ABI, and do
6920 not check for overflow here. */
6924 case R_MIPS_LITERAL
:
6925 /* Because we don't merge literal sections, we can handle this
6926 just like R_MIPS_GPREL16. In the long run, we should merge
6927 shared literals, and then we will need to additional work
6932 case R_MIPS16_GPREL
:
6933 /* The R_MIPS16_GPREL performs the same calculation as
6934 R_MIPS_GPREL16, but stores the relocated bits in a different
6935 order. We don't need to do anything special here; the
6936 differences are handled in mips_elf_perform_relocation. */
6937 case R_MIPS_GPREL16
:
6939 value
= mips_elf_sign_extend (addend
, 16) + symbol
+ gp0
- gp
;
6941 value
= mips_elf_sign_extend (addend
, 16) + symbol
- gp
;
6942 overflowed_p
= mips_elf_overflow_p (value
, 16);
6951 /* The special case is when the symbol is forced to be local. We
6952 need the full address in the GOT since no R_MIPS_LO16 relocation
6954 forced
= ! mips_elf_local_relocation_p (input_bfd
, relocation
,
6955 local_sections
, false);
6956 value
= mips_elf_got16_entry (abfd
, info
, symbol
+ addend
, forced
);
6957 if (value
== (bfd_vma
) -1)
6960 = mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
6963 overflowed_p
= mips_elf_overflow_p (value
, 16);
6969 case R_MIPS_GOT_DISP
:
6971 overflowed_p
= mips_elf_overflow_p (value
, 16);
6974 case R_MIPS_GPREL32
:
6975 value
= (addend
+ symbol
+ gp0
- gp
) & howto
->dst_mask
;
6979 value
= mips_elf_sign_extend (addend
, 16) + symbol
- p
;
6980 overflowed_p
= mips_elf_overflow_p (value
, 16);
6981 value
= (bfd_vma
) ((bfd_signed_vma
) value
/ 4);
6984 case R_MIPS_GOT_HI16
:
6985 case R_MIPS_CALL_HI16
:
6986 /* We're allowed to handle these two relocations identically.
6987 The dynamic linker is allowed to handle the CALL relocations
6988 differently by creating a lazy evaluation stub. */
6990 value
= mips_elf_high (value
);
6991 value
&= howto
->dst_mask
;
6994 case R_MIPS_GOT_LO16
:
6995 case R_MIPS_CALL_LO16
:
6996 value
= g
& howto
->dst_mask
;
6999 case R_MIPS_GOT_PAGE
:
7000 value
= mips_elf_got_page (abfd
, info
, symbol
+ addend
, NULL
);
7001 if (value
== (bfd_vma
) -1)
7003 value
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
7006 overflowed_p
= mips_elf_overflow_p (value
, 16);
7009 case R_MIPS_GOT_OFST
:
7010 mips_elf_got_page (abfd
, info
, symbol
+ addend
, &value
);
7011 overflowed_p
= mips_elf_overflow_p (value
, 16);
7015 value
= symbol
- addend
;
7016 value
&= howto
->dst_mask
;
7020 value
= mips_elf_higher (addend
+ symbol
);
7021 value
&= howto
->dst_mask
;
7024 case R_MIPS_HIGHEST
:
7025 value
= mips_elf_highest (addend
+ symbol
);
7026 value
&= howto
->dst_mask
;
7029 case R_MIPS_SCN_DISP
:
7030 value
= symbol
+ addend
- sec
->output_offset
;
7031 value
&= howto
->dst_mask
;
7036 /* Both of these may be ignored. R_MIPS_JALR is an optimization
7037 hint; we could improve performance by honoring that hint. */
7038 return bfd_reloc_continue
;
7040 case R_MIPS_GNU_VTINHERIT
:
7041 case R_MIPS_GNU_VTENTRY
:
7042 /* We don't do anything with these at present. */
7043 return bfd_reloc_continue
;
7046 /* An unrecognized relocation type. */
7047 return bfd_reloc_notsupported
;
7050 /* Store the VALUE for our caller. */
7052 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
7055 /* Obtain the field relocated by RELOCATION. */
7058 mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
)
7059 reloc_howto_type
*howto
;
7060 const Elf_Internal_Rela
*relocation
;
7065 bfd_byte
*location
= contents
+ relocation
->r_offset
;
7067 /* Obtain the bytes. */
7068 x
= bfd_get (((bfd_vma
)(8 * bfd_get_reloc_size (howto
))), input_bfd
, location
);
7070 if ((ELF32_R_TYPE (relocation
->r_info
) == R_MIPS16_26
7071 || ELF32_R_TYPE (relocation
->r_info
) == R_MIPS16_GPREL
)
7072 && bfd_little_endian (input_bfd
))
7073 /* The two 16-bit words will be reversed on a little-endian
7074 system. See mips_elf_perform_relocation for more details. */
7075 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
7080 /* It has been determined that the result of the RELOCATION is the
7081 VALUE. Use HOWTO to place VALUE into the output file at the
7082 appropriate position. The SECTION is the section to which the
7083 relocation applies. If REQUIRE_JALX is true, then the opcode used
7084 for the relocation must be either JAL or JALX, and it is
7085 unconditionally converted to JALX.
7087 Returns false if anything goes wrong. */
7090 mips_elf_perform_relocation (info
, howto
, relocation
, value
,
7091 input_bfd
, input_section
,
7092 contents
, require_jalx
)
7093 struct bfd_link_info
*info
;
7094 reloc_howto_type
*howto
;
7095 const Elf_Internal_Rela
*relocation
;
7098 asection
*input_section
;
7100 boolean require_jalx
;
7104 int r_type
= ELF32_R_TYPE (relocation
->r_info
);
7106 /* Figure out where the relocation is occurring. */
7107 location
= contents
+ relocation
->r_offset
;
7109 /* Obtain the current value. */
7110 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
7112 /* Clear the field we are setting. */
7113 x
&= ~howto
->dst_mask
;
7115 /* If this is the R_MIPS16_26 relocation, we must store the
7116 value in a funny way. */
7117 if (r_type
== R_MIPS16_26
)
7119 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
7120 Most mips16 instructions are 16 bits, but these instructions
7123 The format of these instructions is:
7125 +--------------+--------------------------------+
7126 ! JALX ! X! Imm 20:16 ! Imm 25:21 !
7127 +--------------+--------------------------------+
7129 +-----------------------------------------------+
7131 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
7132 Note that the immediate value in the first word is swapped.
7134 When producing a relocateable object file, R_MIPS16_26 is
7135 handled mostly like R_MIPS_26. In particular, the addend is
7136 stored as a straight 26-bit value in a 32-bit instruction.
7137 (gas makes life simpler for itself by never adjusting a
7138 R_MIPS16_26 reloc to be against a section, so the addend is
7139 always zero). However, the 32 bit instruction is stored as 2
7140 16-bit values, rather than a single 32-bit value. In a
7141 big-endian file, the result is the same; in a little-endian
7142 file, the two 16-bit halves of the 32 bit value are swapped.
7143 This is so that a disassembler can recognize the jal
7146 When doing a final link, R_MIPS16_26 is treated as a 32 bit
7147 instruction stored as two 16-bit values. The addend A is the
7148 contents of the targ26 field. The calculation is the same as
7149 R_MIPS_26. When storing the calculated value, reorder the
7150 immediate value as shown above, and don't forget to store the
7151 value as two 16-bit values.
7153 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
7157 +--------+----------------------+
7161 +--------+----------------------+
7164 +----------+------+-------------+
7168 +----------+--------------------+
7169 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
7170 ((sub1 << 16) | sub2)).
7172 When producing a relocateable object file, the calculation is
7173 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
7174 When producing a fully linked file, the calculation is
7175 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
7176 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff) */
7178 if (!info
->relocateable
)
7179 /* Shuffle the bits according to the formula above. */
7180 value
= (((value
& 0x1f0000) << 5)
7181 | ((value
& 0x3e00000) >> 5)
7182 | (value
& 0xffff));
7184 else if (r_type
== R_MIPS16_GPREL
)
7186 /* R_MIPS16_GPREL is used for GP-relative addressing in mips16
7187 mode. A typical instruction will have a format like this:
7189 +--------------+--------------------------------+
7190 ! EXTEND ! Imm 10:5 ! Imm 15:11 !
7191 +--------------+--------------------------------+
7192 ! Major ! rx ! ry ! Imm 4:0 !
7193 +--------------+--------------------------------+
7195 EXTEND is the five bit value 11110. Major is the instruction
7198 This is handled exactly like R_MIPS_GPREL16, except that the
7199 addend is retrieved and stored as shown in this diagram; that
7200 is, the Imm fields above replace the V-rel16 field.
7202 All we need to do here is shuffle the bits appropriately. As
7203 above, the two 16-bit halves must be swapped on a
7204 little-endian system. */
7205 value
= (((value
& 0x7e0) << 16)
7206 | ((value
& 0xf800) << 5)
7210 /* Set the field. */
7211 x
|= (value
& howto
->dst_mask
);
7213 /* If required, turn JAL into JALX. */
7217 bfd_vma opcode
= x
>> 26;
7218 bfd_vma jalx_opcode
;
7220 /* Check to see if the opcode is already JAL or JALX. */
7221 if (r_type
== R_MIPS16_26
)
7223 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
7228 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
7232 /* If the opcode is not JAL or JALX, there's a problem. */
7235 (*_bfd_error_handler
)
7236 (_("%s: %s+0x%lx: jump to stub routine which is not jal"),
7237 bfd_archive_filename (input_bfd
),
7238 input_section
->name
,
7239 (unsigned long) relocation
->r_offset
);
7240 bfd_set_error (bfd_error_bad_value
);
7244 /* Make this the JALX opcode. */
7245 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
7248 /* Swap the high- and low-order 16 bits on little-endian systems
7249 when doing a MIPS16 relocation. */
7250 if ((r_type
== R_MIPS16_GPREL
|| r_type
== R_MIPS16_26
)
7251 && bfd_little_endian (input_bfd
))
7252 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
7254 /* Put the value into the output. */
7255 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
7259 /* Returns true if SECTION is a MIPS16 stub section. */
7262 mips_elf_stub_section_p (abfd
, section
)
7263 bfd
*abfd ATTRIBUTE_UNUSED
;
7266 const char *name
= bfd_get_section_name (abfd
, section
);
7268 return (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0
7269 || strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
7270 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0);
7273 /* Relocate a MIPS ELF section. */
7276 _bfd_mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
7277 contents
, relocs
, local_syms
, local_sections
)
7279 struct bfd_link_info
*info
;
7281 asection
*input_section
;
7283 Elf_Internal_Rela
*relocs
;
7284 Elf_Internal_Sym
*local_syms
;
7285 asection
**local_sections
;
7287 Elf_Internal_Rela
*rel
;
7288 const Elf_Internal_Rela
*relend
;
7290 boolean use_saved_addend_p
= false;
7291 struct elf_backend_data
*bed
;
7293 bed
= get_elf_backend_data (output_bfd
);
7294 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
7295 for (rel
= relocs
; rel
< relend
; ++rel
)
7299 reloc_howto_type
*howto
;
7300 boolean require_jalx
;
7301 /* True if the relocation is a RELA relocation, rather than a
7303 boolean rela_relocation_p
= true;
7304 unsigned int r_type
= ELF32_R_TYPE (rel
->r_info
);
7305 const char * msg
= (const char *) NULL
;
7307 /* Find the relocation howto for this relocation. */
7308 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
))
7310 /* Some 32-bit code uses R_MIPS_64. In particular, people use
7311 64-bit code, but make sure all their addresses are in the
7312 lowermost or uppermost 32-bit section of the 64-bit address
7313 space. Thus, when they use an R_MIPS_64 they mean what is
7314 usually meant by R_MIPS_32, with the exception that the
7315 stored value is sign-extended to 64 bits. */
7316 howto
= elf_mips_howto_table_rel
+ R_MIPS_32
;
7318 /* On big-endian systems, we need to lie about the position
7320 if (bfd_big_endian (input_bfd
))
7324 howto
= mips_rtype_to_howto (r_type
);
7326 if (!use_saved_addend_p
)
7328 Elf_Internal_Shdr
*rel_hdr
;
7330 /* If these relocations were originally of the REL variety,
7331 we must pull the addend out of the field that will be
7332 relocated. Otherwise, we simply use the contents of the
7333 RELA relocation. To determine which flavor or relocation
7334 this is, we depend on the fact that the INPUT_SECTION's
7335 REL_HDR is read before its REL_HDR2. */
7336 rel_hdr
= &elf_section_data (input_section
)->rel_hdr
;
7337 if ((size_t) (rel
- relocs
)
7338 >= (NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
))
7339 rel_hdr
= elf_section_data (input_section
)->rel_hdr2
;
7340 if (rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (input_bfd
))
7342 /* Note that this is a REL relocation. */
7343 rela_relocation_p
= false;
7345 /* Get the addend, which is stored in the input file. */
7346 addend
= mips_elf_obtain_contents (howto
,
7350 addend
&= howto
->src_mask
;
7352 /* For some kinds of relocations, the ADDEND is a
7353 combination of the addend stored in two different
7355 if (r_type
== R_MIPS_HI16
7356 || r_type
== R_MIPS_GNU_REL_HI16
7357 || (r_type
== R_MIPS_GOT16
7358 && mips_elf_local_relocation_p (input_bfd
, rel
,
7359 local_sections
, false)))
7362 const Elf_Internal_Rela
*lo16_relocation
;
7363 reloc_howto_type
*lo16_howto
;
7366 /* The combined value is the sum of the HI16 addend,
7367 left-shifted by sixteen bits, and the LO16
7368 addend, sign extended. (Usually, the code does
7369 a `lui' of the HI16 value, and then an `addiu' of
7372 Scan ahead to find a matching LO16 relocation. */
7373 if (r_type
== R_MIPS_GNU_REL_HI16
)
7374 lo
= R_MIPS_GNU_REL_LO16
;
7378 = mips_elf_next_relocation (lo
, rel
, relend
);
7379 if (lo16_relocation
== NULL
)
7382 /* Obtain the addend kept there. */
7383 lo16_howto
= mips_rtype_to_howto (lo
);
7384 l
= mips_elf_obtain_contents (lo16_howto
,
7386 input_bfd
, contents
);
7387 l
&= lo16_howto
->src_mask
;
7388 l
= mips_elf_sign_extend (l
, 16);
7392 /* Compute the combined addend. */
7395 else if (r_type
== R_MIPS16_GPREL
)
7397 /* The addend is scrambled in the object file. See
7398 mips_elf_perform_relocation for details on the
7400 addend
= (((addend
& 0x1f0000) >> 5)
7401 | ((addend
& 0x7e00000) >> 16)
7406 addend
= rel
->r_addend
;
7409 if (info
->relocateable
)
7411 Elf_Internal_Sym
*sym
;
7412 unsigned long r_symndx
;
7414 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
)
7415 && bfd_big_endian (input_bfd
))
7418 /* Since we're just relocating, all we need to do is copy
7419 the relocations back out to the object file, unless
7420 they're against a section symbol, in which case we need
7421 to adjust by the section offset, or unless they're GP
7422 relative in which case we need to adjust by the amount
7423 that we're adjusting GP in this relocateable object. */
7425 if (!mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
,
7427 /* There's nothing to do for non-local relocations. */
7430 if (r_type
== R_MIPS16_GPREL
7431 || r_type
== R_MIPS_GPREL16
7432 || r_type
== R_MIPS_GPREL32
7433 || r_type
== R_MIPS_LITERAL
)
7434 addend
-= (_bfd_get_gp_value (output_bfd
)
7435 - _bfd_get_gp_value (input_bfd
));
7436 else if (r_type
== R_MIPS_26
|| r_type
== R_MIPS16_26
7437 || r_type
== R_MIPS_GNU_REL16_S2
)
7438 /* The addend is stored without its two least
7439 significant bits (which are always zero.) In a
7440 non-relocateable link, calculate_relocation will do
7441 this shift; here, we must do it ourselves. */
7444 r_symndx
= ELF32_R_SYM (rel
->r_info
);
7445 sym
= local_syms
+ r_symndx
;
7446 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
7447 /* Adjust the addend appropriately. */
7448 addend
+= local_sections
[r_symndx
]->output_offset
;
7450 /* If the relocation is for a R_MIPS_HI16 or R_MIPS_GOT16,
7451 then we only want to write out the high-order 16 bits.
7452 The subsequent R_MIPS_LO16 will handle the low-order bits. */
7453 if (r_type
== R_MIPS_HI16
|| r_type
== R_MIPS_GOT16
7454 || r_type
== R_MIPS_GNU_REL_HI16
)
7455 addend
= mips_elf_high (addend
);
7456 /* If the relocation is for an R_MIPS_26 relocation, then
7457 the two low-order bits are not stored in the object file;
7458 they are implicitly zero. */
7459 else if (r_type
== R_MIPS_26
|| r_type
== R_MIPS16_26
7460 || r_type
== R_MIPS_GNU_REL16_S2
)
7463 if (rela_relocation_p
)
7464 /* If this is a RELA relocation, just update the addend.
7465 We have to cast away constness for REL. */
7466 rel
->r_addend
= addend
;
7469 /* Otherwise, we have to write the value back out. Note
7470 that we use the source mask, rather than the
7471 destination mask because the place to which we are
7472 writing will be source of the addend in the final
7474 addend
&= howto
->src_mask
;
7476 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
))
7477 /* See the comment above about using R_MIPS_64 in the 32-bit
7478 ABI. Here, we need to update the addend. It would be
7479 possible to get away with just using the R_MIPS_32 reloc
7480 but for endianness. */
7486 if (addend
& ((bfd_vma
) 1 << 31))
7488 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
7495 /* If we don't know that we have a 64-bit type,
7496 do two separate stores. */
7497 if (bfd_big_endian (input_bfd
))
7499 /* Store the sign-bits (which are most significant)
7501 low_bits
= sign_bits
;
7507 high_bits
= sign_bits
;
7509 bfd_put_32 (input_bfd
, low_bits
,
7510 contents
+ rel
->r_offset
);
7511 bfd_put_32 (input_bfd
, high_bits
,
7512 contents
+ rel
->r_offset
+ 4);
7516 if (!mips_elf_perform_relocation (info
, howto
, rel
, addend
,
7517 input_bfd
, input_section
,
7522 /* Go on to the next relocation. */
7526 /* In the N32 and 64-bit ABIs there may be multiple consecutive
7527 relocations for the same offset. In that case we are
7528 supposed to treat the output of each relocation as the addend
7530 if (rel
+ 1 < relend
7531 && rel
->r_offset
== rel
[1].r_offset
7532 && ELF32_R_TYPE (rel
[1].r_info
) != R_MIPS_NONE
)
7533 use_saved_addend_p
= true;
7535 use_saved_addend_p
= false;
7537 /* Figure out what value we are supposed to relocate. */
7538 switch (mips_elf_calculate_relocation (output_bfd
,
7551 case bfd_reloc_continue
:
7552 /* There's nothing to do. */
7555 case bfd_reloc_undefined
:
7556 /* mips_elf_calculate_relocation already called the
7557 undefined_symbol callback. There's no real point in
7558 trying to perform the relocation at this point, so we
7559 just skip ahead to the next relocation. */
7562 case bfd_reloc_notsupported
:
7563 msg
= _("internal error: unsupported relocation error");
7564 info
->callbacks
->warning
7565 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
7568 case bfd_reloc_overflow
:
7569 if (use_saved_addend_p
)
7570 /* Ignore overflow until we reach the last relocation for
7571 a given location. */
7575 BFD_ASSERT (name
!= NULL
);
7576 if (! ((*info
->callbacks
->reloc_overflow
)
7577 (info
, name
, howto
->name
, (bfd_vma
) 0,
7578 input_bfd
, input_section
, rel
->r_offset
)))
7591 /* If we've got another relocation for the address, keep going
7592 until we reach the last one. */
7593 if (use_saved_addend_p
)
7599 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
))
7600 /* See the comment above about using R_MIPS_64 in the 32-bit
7601 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
7602 that calculated the right value. Now, however, we
7603 sign-extend the 32-bit result to 64-bits, and store it as a
7604 64-bit value. We are especially generous here in that we
7605 go to extreme lengths to support this usage on systems with
7606 only a 32-bit VMA. */
7612 if (value
& ((bfd_vma
) 1 << 31))
7614 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
7621 /* If we don't know that we have a 64-bit type,
7622 do two separate stores. */
7623 if (bfd_big_endian (input_bfd
))
7625 /* Undo what we did above. */
7627 /* Store the sign-bits (which are most significant)
7629 low_bits
= sign_bits
;
7635 high_bits
= sign_bits
;
7637 bfd_put_32 (input_bfd
, low_bits
,
7638 contents
+ rel
->r_offset
);
7639 bfd_put_32 (input_bfd
, high_bits
,
7640 contents
+ rel
->r_offset
+ 4);
7644 /* Actually perform the relocation. */
7645 if (!mips_elf_perform_relocation (info
, howto
, rel
, value
, input_bfd
,
7646 input_section
, contents
,
7654 /* This hook function is called before the linker writes out a global
7655 symbol. We mark symbols as small common if appropriate. This is
7656 also where we undo the increment of the value for a mips16 symbol. */
7659 _bfd_mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
7660 bfd
*abfd ATTRIBUTE_UNUSED
;
7661 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
7662 const char *name ATTRIBUTE_UNUSED
;
7663 Elf_Internal_Sym
*sym
;
7664 asection
*input_sec
;
7666 /* If we see a common symbol, which implies a relocatable link, then
7667 if a symbol was small common in an input file, mark it as small
7668 common in the output file. */
7669 if (sym
->st_shndx
== SHN_COMMON
7670 && strcmp (input_sec
->name
, ".scommon") == 0)
7671 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
7673 if (sym
->st_other
== STO_MIPS16
7674 && (sym
->st_value
& 1) != 0)
7680 /* Functions for the dynamic linker. */
7682 /* The name of the dynamic interpreter. This is put in the .interp
7685 #define ELF_DYNAMIC_INTERPRETER(abfd) \
7686 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
7687 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
7688 : "/usr/lib/libc.so.1")
7690 /* Create dynamic sections when linking against a dynamic object. */
7693 _bfd_mips_elf_create_dynamic_sections (abfd
, info
)
7695 struct bfd_link_info
*info
;
7697 struct elf_link_hash_entry
*h
;
7699 register asection
*s
;
7700 const char * const *namep
;
7702 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7703 | SEC_LINKER_CREATED
| SEC_READONLY
);
7705 /* Mips ABI requests the .dynamic section to be read only. */
7706 s
= bfd_get_section_by_name (abfd
, ".dynamic");
7709 if (! bfd_set_section_flags (abfd
, s
, flags
))
7713 /* We need to create .got section. */
7714 if (! mips_elf_create_got_section (abfd
, info
))
7717 /* Create the .msym section on IRIX6. It is used by the dynamic
7718 linker to speed up dynamic relocations, and to avoid computing
7719 the ELF hash for symbols. */
7720 if (IRIX_COMPAT (abfd
) == ict_irix6
7721 && !mips_elf_create_msym_section (abfd
))
7724 /* Create .stub section. */
7725 if (bfd_get_section_by_name (abfd
,
7726 MIPS_ELF_STUB_SECTION_NAME (abfd
)) == NULL
)
7728 s
= bfd_make_section (abfd
, MIPS_ELF_STUB_SECTION_NAME (abfd
));
7730 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_CODE
)
7731 || ! bfd_set_section_alignment (abfd
, s
,
7732 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7736 if ((IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
7738 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
7740 s
= bfd_make_section (abfd
, ".rld_map");
7742 || ! bfd_set_section_flags (abfd
, s
, flags
&~ (flagword
) SEC_READONLY
)
7743 || ! bfd_set_section_alignment (abfd
, s
,
7744 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7748 /* On IRIX5, we adjust add some additional symbols and change the
7749 alignments of several sections. There is no ABI documentation
7750 indicating that this is necessary on IRIX6, nor any evidence that
7751 the linker takes such action. */
7752 if (IRIX_COMPAT (abfd
) == ict_irix5
)
7754 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
7757 if (! (_bfd_generic_link_add_one_symbol
7758 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
7759 (bfd_vma
) 0, (const char *) NULL
, false,
7760 get_elf_backend_data (abfd
)->collect
,
7761 (struct bfd_link_hash_entry
**) &h
)))
7763 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
7764 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7765 h
->type
= STT_SECTION
;
7767 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7771 /* We need to create a .compact_rel section. */
7772 if (SGI_COMPAT (abfd
))
7774 if (!mips_elf_create_compact_rel_section (abfd
, info
))
7778 /* Change aligments of some sections. */
7779 s
= bfd_get_section_by_name (abfd
, ".hash");
7781 bfd_set_section_alignment (abfd
, s
, 4);
7782 s
= bfd_get_section_by_name (abfd
, ".dynsym");
7784 bfd_set_section_alignment (abfd
, s
, 4);
7785 s
= bfd_get_section_by_name (abfd
, ".dynstr");
7787 bfd_set_section_alignment (abfd
, s
, 4);
7788 s
= bfd_get_section_by_name (abfd
, ".reginfo");
7790 bfd_set_section_alignment (abfd
, s
, 4);
7791 s
= bfd_get_section_by_name (abfd
, ".dynamic");
7793 bfd_set_section_alignment (abfd
, s
, 4);
7799 if (SGI_COMPAT (abfd
))
7801 if (!(_bfd_generic_link_add_one_symbol
7802 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
7803 (bfd_vma
) 0, (const char *) NULL
, false,
7804 get_elf_backend_data (abfd
)->collect
,
7805 (struct bfd_link_hash_entry
**) &h
)))
7810 /* For normal mips it is _DYNAMIC_LINKING. */
7811 if (!(_bfd_generic_link_add_one_symbol
7812 (info
, abfd
, "_DYNAMIC_LINKING", BSF_GLOBAL
,
7813 bfd_abs_section_ptr
, (bfd_vma
) 0, (const char *) NULL
, false,
7814 get_elf_backend_data (abfd
)->collect
,
7815 (struct bfd_link_hash_entry
**) &h
)))
7818 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
7819 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7820 h
->type
= STT_SECTION
;
7822 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7825 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
7827 /* __rld_map is a four byte word located in the .data section
7828 and is filled in by the rtld to contain a pointer to
7829 the _r_debug structure. Its symbol value will be set in
7830 mips_elf_finish_dynamic_symbol. */
7831 s
= bfd_get_section_by_name (abfd
, ".rld_map");
7832 BFD_ASSERT (s
!= NULL
);
7835 if (SGI_COMPAT (abfd
))
7837 if (!(_bfd_generic_link_add_one_symbol
7838 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
7839 (bfd_vma
) 0, (const char *) NULL
, false,
7840 get_elf_backend_data (abfd
)->collect
,
7841 (struct bfd_link_hash_entry
**) &h
)))
7846 /* For normal mips the symbol is __RLD_MAP. */
7847 if (!(_bfd_generic_link_add_one_symbol
7848 (info
, abfd
, "__RLD_MAP", BSF_GLOBAL
, s
,
7849 (bfd_vma
) 0, (const char *) NULL
, false,
7850 get_elf_backend_data (abfd
)->collect
,
7851 (struct bfd_link_hash_entry
**) &h
)))
7854 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
7855 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7856 h
->type
= STT_OBJECT
;
7858 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7866 /* Create the .compact_rel section. */
7869 mips_elf_create_compact_rel_section (abfd
, info
)
7871 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
7874 register asection
*s
;
7876 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
7878 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
7881 s
= bfd_make_section (abfd
, ".compact_rel");
7883 || ! bfd_set_section_flags (abfd
, s
, flags
)
7884 || ! bfd_set_section_alignment (abfd
, s
,
7885 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7888 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
7894 /* Create the .got section to hold the global offset table. */
7897 mips_elf_create_got_section (abfd
, info
)
7899 struct bfd_link_info
*info
;
7902 register asection
*s
;
7903 struct elf_link_hash_entry
*h
;
7904 struct mips_got_info
*g
;
7907 /* This function may be called more than once. */
7908 if (mips_elf_got_section (abfd
))
7911 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7912 | SEC_LINKER_CREATED
);
7914 s
= bfd_make_section (abfd
, ".got");
7916 || ! bfd_set_section_flags (abfd
, s
, flags
)
7917 || ! bfd_set_section_alignment (abfd
, s
, 4))
7920 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
7921 linker script because we don't want to define the symbol if we
7922 are not creating a global offset table. */
7924 if (! (_bfd_generic_link_add_one_symbol
7925 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
7926 (bfd_vma
) 0, (const char *) NULL
, false,
7927 get_elf_backend_data (abfd
)->collect
,
7928 (struct bfd_link_hash_entry
**) &h
)))
7930 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
7931 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7932 h
->type
= STT_OBJECT
;
7935 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7938 /* The first several global offset table entries are reserved. */
7939 s
->_raw_size
= MIPS_RESERVED_GOTNO
* MIPS_ELF_GOT_SIZE (abfd
);
7941 amt
= sizeof (struct mips_got_info
);
7942 g
= (struct mips_got_info
*) bfd_alloc (abfd
, amt
);
7945 g
->global_gotsym
= NULL
;
7946 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
7947 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
7948 if (elf_section_data (s
) == NULL
)
7950 amt
= sizeof (struct bfd_elf_section_data
);
7951 s
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
7952 if (elf_section_data (s
) == NULL
)
7955 elf_section_data (s
)->tdata
= (PTR
) g
;
7956 elf_section_data (s
)->this_hdr
.sh_flags
7957 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
7962 /* Returns the .msym section for ABFD, creating it if it does not
7963 already exist. Returns NULL to indicate error. */
7966 mips_elf_create_msym_section (abfd
)
7971 s
= bfd_get_section_by_name (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
7974 s
= bfd_make_section (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
7976 || !bfd_set_section_flags (abfd
, s
,
7980 | SEC_LINKER_CREATED
7982 || !bfd_set_section_alignment (abfd
, s
,
7983 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7990 /* Add room for N relocations to the .rel.dyn section in ABFD. */
7993 mips_elf_allocate_dynamic_relocations (abfd
, n
)
7999 s
= bfd_get_section_by_name (abfd
, MIPS_ELF_REL_DYN_SECTION_NAME (abfd
));
8000 BFD_ASSERT (s
!= NULL
);
8002 if (s
->_raw_size
== 0)
8004 /* Make room for a null element. */
8005 s
->_raw_size
+= MIPS_ELF_REL_SIZE (abfd
);
8008 s
->_raw_size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
8011 /* Look through the relocs for a section during the first phase, and
8012 allocate space in the global offset table. */
8015 _bfd_mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
8017 struct bfd_link_info
*info
;
8019 const Elf_Internal_Rela
*relocs
;
8023 Elf_Internal_Shdr
*symtab_hdr
;
8024 struct elf_link_hash_entry
**sym_hashes
;
8025 struct mips_got_info
*g
;
8027 const Elf_Internal_Rela
*rel
;
8028 const Elf_Internal_Rela
*rel_end
;
8031 struct elf_backend_data
*bed
;
8033 if (info
->relocateable
)
8036 dynobj
= elf_hash_table (info
)->dynobj
;
8037 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
8038 sym_hashes
= elf_sym_hashes (abfd
);
8039 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
8041 /* Check for the mips16 stub sections. */
8043 name
= bfd_get_section_name (abfd
, sec
);
8044 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
8046 unsigned long r_symndx
;
8048 /* Look at the relocation information to figure out which symbol
8051 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
8053 if (r_symndx
< extsymoff
8054 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
8058 /* This stub is for a local symbol. This stub will only be
8059 needed if there is some relocation in this BFD, other
8060 than a 16 bit function call, which refers to this symbol. */
8061 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
8063 Elf_Internal_Rela
*sec_relocs
;
8064 const Elf_Internal_Rela
*r
, *rend
;
8066 /* We can ignore stub sections when looking for relocs. */
8067 if ((o
->flags
& SEC_RELOC
) == 0
8068 || o
->reloc_count
== 0
8069 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
8070 sizeof FN_STUB
- 1) == 0
8071 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
8072 sizeof CALL_STUB
- 1) == 0
8073 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
8074 sizeof CALL_FP_STUB
- 1) == 0)
8077 sec_relocs
= (_bfd_elf32_link_read_relocs
8078 (abfd
, o
, (PTR
) NULL
,
8079 (Elf_Internal_Rela
*) NULL
,
8080 info
->keep_memory
));
8081 if (sec_relocs
== NULL
)
8084 rend
= sec_relocs
+ o
->reloc_count
;
8085 for (r
= sec_relocs
; r
< rend
; r
++)
8086 if (ELF32_R_SYM (r
->r_info
) == r_symndx
8087 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
8090 if (! info
->keep_memory
)
8099 /* There is no non-call reloc for this stub, so we do
8100 not need it. Since this function is called before
8101 the linker maps input sections to output sections, we
8102 can easily discard it by setting the SEC_EXCLUDE
8104 sec
->flags
|= SEC_EXCLUDE
;
8108 /* Record this stub in an array of local symbol stubs for
8110 if (elf_tdata (abfd
)->local_stubs
== NULL
)
8112 unsigned long symcount
;
8116 if (elf_bad_symtab (abfd
))
8117 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
8119 symcount
= symtab_hdr
->sh_info
;
8120 amt
= symcount
* sizeof (asection
*);
8121 n
= (asection
**) bfd_zalloc (abfd
, amt
);
8124 elf_tdata (abfd
)->local_stubs
= n
;
8127 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
8129 /* We don't need to set mips16_stubs_seen in this case.
8130 That flag is used to see whether we need to look through
8131 the global symbol table for stubs. We don't need to set
8132 it here, because we just have a local stub. */
8136 struct mips_elf_link_hash_entry
*h
;
8138 h
= ((struct mips_elf_link_hash_entry
*)
8139 sym_hashes
[r_symndx
- extsymoff
]);
8141 /* H is the symbol this stub is for. */
8144 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
8147 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
8148 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
8150 unsigned long r_symndx
;
8151 struct mips_elf_link_hash_entry
*h
;
8154 /* Look at the relocation information to figure out which symbol
8157 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
8159 if (r_symndx
< extsymoff
8160 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
8162 /* This stub was actually built for a static symbol defined
8163 in the same file. We assume that all static symbols in
8164 mips16 code are themselves mips16, so we can simply
8165 discard this stub. Since this function is called before
8166 the linker maps input sections to output sections, we can
8167 easily discard it by setting the SEC_EXCLUDE flag. */
8168 sec
->flags
|= SEC_EXCLUDE
;
8172 h
= ((struct mips_elf_link_hash_entry
*)
8173 sym_hashes
[r_symndx
- extsymoff
]);
8175 /* H is the symbol this stub is for. */
8177 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
8178 loc
= &h
->call_fp_stub
;
8180 loc
= &h
->call_stub
;
8182 /* If we already have an appropriate stub for this function, we
8183 don't need another one, so we can discard this one. Since
8184 this function is called before the linker maps input sections
8185 to output sections, we can easily discard it by setting the
8186 SEC_EXCLUDE flag. We can also discard this section if we
8187 happen to already know that this is a mips16 function; it is
8188 not necessary to check this here, as it is checked later, but
8189 it is slightly faster to check now. */
8190 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
8192 sec
->flags
|= SEC_EXCLUDE
;
8197 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
8207 sgot
= mips_elf_got_section (dynobj
);
8212 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
8213 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
8214 BFD_ASSERT (g
!= NULL
);
8219 bed
= get_elf_backend_data (abfd
);
8220 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
8221 for (rel
= relocs
; rel
< rel_end
; ++rel
)
8223 unsigned long r_symndx
;
8224 unsigned int r_type
;
8225 struct elf_link_hash_entry
*h
;
8227 r_symndx
= ELF32_R_SYM (rel
->r_info
);
8228 r_type
= ELF32_R_TYPE (rel
->r_info
);
8230 if (r_symndx
< extsymoff
)
8232 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
8234 (*_bfd_error_handler
)
8235 (_("%s: Malformed reloc detected for section %s"),
8236 bfd_archive_filename (abfd
), name
);
8237 bfd_set_error (bfd_error_bad_value
);
8242 h
= sym_hashes
[r_symndx
- extsymoff
];
8244 /* This may be an indirect symbol created because of a version. */
8247 while (h
->root
.type
== bfd_link_hash_indirect
)
8248 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8252 /* Some relocs require a global offset table. */
8253 if (dynobj
== NULL
|| sgot
== NULL
)
8259 case R_MIPS_CALL_HI16
:
8260 case R_MIPS_CALL_LO16
:
8261 case R_MIPS_GOT_HI16
:
8262 case R_MIPS_GOT_LO16
:
8263 case R_MIPS_GOT_PAGE
:
8264 case R_MIPS_GOT_OFST
:
8265 case R_MIPS_GOT_DISP
:
8267 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
8268 if (! mips_elf_create_got_section (dynobj
, info
))
8270 g
= mips_elf_got_info (dynobj
, &sgot
);
8277 && (info
->shared
|| h
!= NULL
)
8278 && (sec
->flags
& SEC_ALLOC
) != 0)
8279 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
8287 if (!h
&& (r_type
== R_MIPS_CALL_LO16
8288 || r_type
== R_MIPS_GOT_LO16
8289 || r_type
== R_MIPS_GOT_DISP
))
8291 /* We may need a local GOT entry for this relocation. We
8292 don't count R_MIPS_GOT_PAGE because we can estimate the
8293 maximum number of pages needed by looking at the size of
8294 the segment. Similar comments apply to R_MIPS_GOT16 and
8295 R_MIPS_CALL16. We don't count R_MIPS_GOT_HI16, or
8296 R_MIPS_CALL_HI16 because these are always followed by an
8297 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16.
8299 This estimation is very conservative since we can merge
8300 duplicate entries in the GOT. In order to be less
8301 conservative, we could actually build the GOT here,
8302 rather than in relocate_section. */
8304 sgot
->_raw_size
+= MIPS_ELF_GOT_SIZE (dynobj
);
8312 (*_bfd_error_handler
)
8313 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
8314 bfd_archive_filename (abfd
), (unsigned long) rel
->r_offset
);
8315 bfd_set_error (bfd_error_bad_value
);
8320 case R_MIPS_CALL_HI16
:
8321 case R_MIPS_CALL_LO16
:
8324 /* This symbol requires a global offset table entry. */
8325 if (!mips_elf_record_global_got_symbol (h
, info
, g
))
8328 /* We need a stub, not a plt entry for the undefined
8329 function. But we record it as if it needs plt. See
8330 elf_adjust_dynamic_symbol in elflink.h. */
8331 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
8337 case R_MIPS_GOT_HI16
:
8338 case R_MIPS_GOT_LO16
:
8339 case R_MIPS_GOT_DISP
:
8340 /* This symbol requires a global offset table entry. */
8341 if (h
&& !mips_elf_record_global_got_symbol (h
, info
, g
))
8348 if ((info
->shared
|| h
!= NULL
)
8349 && (sec
->flags
& SEC_ALLOC
) != 0)
8353 const char *dname
= MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
);
8355 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
8358 sreloc
= bfd_make_section (dynobj
, dname
);
8360 || ! bfd_set_section_flags (dynobj
, sreloc
,
8365 | SEC_LINKER_CREATED
8367 || ! bfd_set_section_alignment (dynobj
, sreloc
,
8372 #define MIPS_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
8375 /* When creating a shared object, we must copy these
8376 reloc types into the output file as R_MIPS_REL32
8377 relocs. We make room for this reloc in the
8378 .rel.dyn reloc section. */
8379 mips_elf_allocate_dynamic_relocations (dynobj
, 1);
8380 if ((sec
->flags
& MIPS_READONLY_SECTION
)
8381 == MIPS_READONLY_SECTION
)
8382 /* We tell the dynamic linker that there are
8383 relocations against the text segment. */
8384 info
->flags
|= DF_TEXTREL
;
8388 struct mips_elf_link_hash_entry
*hmips
;
8390 /* We only need to copy this reloc if the symbol is
8391 defined in a dynamic object. */
8392 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8393 ++hmips
->possibly_dynamic_relocs
;
8394 if ((sec
->flags
& MIPS_READONLY_SECTION
)
8395 == MIPS_READONLY_SECTION
)
8396 /* We need it to tell the dynamic linker if there
8397 are relocations against the text segment. */
8398 hmips
->readonly_reloc
= true;
8401 /* Even though we don't directly need a GOT entry for
8402 this symbol, a symbol must have a dynamic symbol
8403 table index greater that DT_MIPS_GOTSYM if there are
8404 dynamic relocations against it. */
8406 && !mips_elf_record_global_got_symbol (h
, info
, g
))
8410 if (SGI_COMPAT (abfd
))
8411 mips_elf_hash_table (info
)->compact_rel_size
+=
8412 sizeof (Elf32_External_crinfo
);
8416 case R_MIPS_GPREL16
:
8417 case R_MIPS_LITERAL
:
8418 case R_MIPS_GPREL32
:
8419 if (SGI_COMPAT (abfd
))
8420 mips_elf_hash_table (info
)->compact_rel_size
+=
8421 sizeof (Elf32_External_crinfo
);
8424 /* This relocation describes the C++ object vtable hierarchy.
8425 Reconstruct it for later use during GC. */
8426 case R_MIPS_GNU_VTINHERIT
:
8427 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
8431 /* This relocation describes which C++ vtable entries are actually
8432 used. Record for later use during GC. */
8433 case R_MIPS_GNU_VTENTRY
:
8434 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
8442 /* We must not create a stub for a symbol that has relocations
8443 related to taking the function's address. */
8449 struct mips_elf_link_hash_entry
*mh
;
8451 mh
= (struct mips_elf_link_hash_entry
*) h
;
8452 mh
->no_fn_stub
= true;
8456 case R_MIPS_CALL_HI16
:
8457 case R_MIPS_CALL_LO16
:
8461 /* If this reloc is not a 16 bit call, and it has a global
8462 symbol, then we will need the fn_stub if there is one.
8463 References from a stub section do not count. */
8465 && r_type
!= R_MIPS16_26
8466 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
8467 sizeof FN_STUB
- 1) != 0
8468 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
8469 sizeof CALL_STUB
- 1) != 0
8470 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
8471 sizeof CALL_FP_STUB
- 1) != 0)
8473 struct mips_elf_link_hash_entry
*mh
;
8475 mh
= (struct mips_elf_link_hash_entry
*) h
;
8476 mh
->need_fn_stub
= true;
8483 /* Return the section that should be marked against GC for a given
8487 _bfd_mips_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
8489 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
8490 Elf_Internal_Rela
*rel
;
8491 struct elf_link_hash_entry
*h
;
8492 Elf_Internal_Sym
*sym
;
8494 /* ??? Do mips16 stub sections need to be handled special? */
8498 switch (ELF32_R_TYPE (rel
->r_info
))
8500 case R_MIPS_GNU_VTINHERIT
:
8501 case R_MIPS_GNU_VTENTRY
:
8505 switch (h
->root
.type
)
8507 case bfd_link_hash_defined
:
8508 case bfd_link_hash_defweak
:
8509 return h
->root
.u
.def
.section
;
8511 case bfd_link_hash_common
:
8512 return h
->root
.u
.c
.p
->section
;
8521 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
8527 /* Update the got entry reference counts for the section being removed. */
8530 _bfd_mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
8531 bfd
*abfd ATTRIBUTE_UNUSED
;
8532 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
8533 asection
*sec ATTRIBUTE_UNUSED
;
8534 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
8537 Elf_Internal_Shdr
*symtab_hdr
;
8538 struct elf_link_hash_entry
**sym_hashes
;
8539 bfd_signed_vma
*local_got_refcounts
;
8540 const Elf_Internal_Rela
*rel
, *relend
;
8541 unsigned long r_symndx
;
8542 struct elf_link_hash_entry
*h
;
8544 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
8545 sym_hashes
= elf_sym_hashes (abfd
);
8546 local_got_refcounts
= elf_local_got_refcounts (abfd
);
8548 relend
= relocs
+ sec
->reloc_count
;
8549 for (rel
= relocs
; rel
< relend
; rel
++)
8550 switch (ELF32_R_TYPE (rel
->r_info
))
8554 case R_MIPS_CALL_HI16
:
8555 case R_MIPS_CALL_LO16
:
8556 case R_MIPS_GOT_HI16
:
8557 case R_MIPS_GOT_LO16
:
8558 /* ??? It would seem that the existing MIPS code does no sort
8559 of reference counting or whatnot on its GOT and PLT entries,
8560 so it is not possible to garbage collect them at this time. */
8571 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
8572 hiding the old indirect symbol. Process additional relocation
8573 information. Also called for weakdefs, in which case we just let
8574 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
8577 _bfd_mips_elf_copy_indirect_symbol (dir
, ind
)
8578 struct elf_link_hash_entry
*dir
, *ind
;
8580 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
8582 _bfd_elf_link_hash_copy_indirect (dir
, ind
);
8584 if (ind
->root
.type
!= bfd_link_hash_indirect
)
8587 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
8588 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
8589 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
8590 if (indmips
->readonly_reloc
)
8591 dirmips
->readonly_reloc
= true;
8592 if (dirmips
->min_dyn_reloc_index
== 0
8593 || (indmips
->min_dyn_reloc_index
!= 0
8594 && indmips
->min_dyn_reloc_index
< dirmips
->min_dyn_reloc_index
))
8595 dirmips
->min_dyn_reloc_index
= indmips
->min_dyn_reloc_index
;
8596 if (indmips
->no_fn_stub
)
8597 dirmips
->no_fn_stub
= true;
8600 /* Adjust a symbol defined by a dynamic object and referenced by a
8601 regular object. The current definition is in some section of the
8602 dynamic object, but we're not including those sections. We have to
8603 change the definition to something the rest of the link can
8607 _bfd_mips_elf_adjust_dynamic_symbol (info
, h
)
8608 struct bfd_link_info
*info
;
8609 struct elf_link_hash_entry
*h
;
8612 struct mips_elf_link_hash_entry
*hmips
;
8615 dynobj
= elf_hash_table (info
)->dynobj
;
8617 /* Make sure we know what is going on here. */
8618 BFD_ASSERT (dynobj
!= NULL
8619 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
8620 || h
->weakdef
!= NULL
8621 || ((h
->elf_link_hash_flags
8622 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
8623 && (h
->elf_link_hash_flags
8624 & ELF_LINK_HASH_REF_REGULAR
) != 0
8625 && (h
->elf_link_hash_flags
8626 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
8628 /* If this symbol is defined in a dynamic object, we need to copy
8629 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
8631 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8632 if (! info
->relocateable
8633 && hmips
->possibly_dynamic_relocs
!= 0
8634 && (h
->root
.type
== bfd_link_hash_defweak
8635 || (h
->elf_link_hash_flags
8636 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
8638 mips_elf_allocate_dynamic_relocations (dynobj
,
8639 hmips
->possibly_dynamic_relocs
);
8640 if (hmips
->readonly_reloc
)
8641 /* We tell the dynamic linker that there are relocations
8642 against the text segment. */
8643 info
->flags
|= DF_TEXTREL
;
8646 /* For a function, create a stub, if allowed. */
8647 if (! hmips
->no_fn_stub
8648 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
8650 if (! elf_hash_table (info
)->dynamic_sections_created
)
8653 /* If this symbol is not defined in a regular file, then set
8654 the symbol to the stub location. This is required to make
8655 function pointers compare as equal between the normal
8656 executable and the shared library. */
8657 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
8659 /* We need .stub section. */
8660 s
= bfd_get_section_by_name (dynobj
,
8661 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
8662 BFD_ASSERT (s
!= NULL
);
8664 h
->root
.u
.def
.section
= s
;
8665 h
->root
.u
.def
.value
= s
->_raw_size
;
8667 /* XXX Write this stub address somewhere. */
8668 h
->plt
.offset
= s
->_raw_size
;
8670 /* Make room for this stub code. */
8671 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
8673 /* The last half word of the stub will be filled with the index
8674 of this symbol in .dynsym section. */
8678 else if ((h
->type
== STT_FUNC
)
8679 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) == 0)
8681 /* This will set the entry for this symbol in the GOT to 0, and
8682 the dynamic linker will take care of this. */
8683 h
->root
.u
.def
.value
= 0;
8687 /* If this is a weak symbol, and there is a real definition, the
8688 processor independent code will have arranged for us to see the
8689 real definition first, and we can just use the same value. */
8690 if (h
->weakdef
!= NULL
)
8692 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
8693 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
8694 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
8695 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
8699 /* This is a reference to a symbol defined by a dynamic object which
8700 is not a function. */
8705 /* This function is called after all the input files have been read,
8706 and the input sections have been assigned to output sections. We
8707 check for any mips16 stub sections that we can discard. */
8709 static boolean mips_elf_check_mips16_stubs
8710 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
8713 _bfd_mips_elf_always_size_sections (output_bfd
, info
)
8715 struct bfd_link_info
*info
;
8719 /* The .reginfo section has a fixed size. */
8720 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
8722 bfd_set_section_size (output_bfd
, ri
,
8723 (bfd_size_type
) sizeof (Elf32_External_RegInfo
));
8725 if (info
->relocateable
8726 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
8729 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
8730 mips_elf_check_mips16_stubs
,
8736 /* Check the mips16 stubs for a particular symbol, and see if we can
8740 mips_elf_check_mips16_stubs (h
, data
)
8741 struct mips_elf_link_hash_entry
*h
;
8742 PTR data ATTRIBUTE_UNUSED
;
8744 if (h
->fn_stub
!= NULL
8745 && ! h
->need_fn_stub
)
8747 /* We don't need the fn_stub; the only references to this symbol
8748 are 16 bit calls. Clobber the size to 0 to prevent it from
8749 being included in the link. */
8750 h
->fn_stub
->_raw_size
= 0;
8751 h
->fn_stub
->_cooked_size
= 0;
8752 h
->fn_stub
->flags
&= ~SEC_RELOC
;
8753 h
->fn_stub
->reloc_count
= 0;
8754 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
8757 if (h
->call_stub
!= NULL
8758 && h
->root
.other
== STO_MIPS16
)
8760 /* We don't need the call_stub; this is a 16 bit function, so
8761 calls from other 16 bit functions are OK. Clobber the size
8762 to 0 to prevent it from being included in the link. */
8763 h
->call_stub
->_raw_size
= 0;
8764 h
->call_stub
->_cooked_size
= 0;
8765 h
->call_stub
->flags
&= ~SEC_RELOC
;
8766 h
->call_stub
->reloc_count
= 0;
8767 h
->call_stub
->flags
|= SEC_EXCLUDE
;
8770 if (h
->call_fp_stub
!= NULL
8771 && h
->root
.other
== STO_MIPS16
)
8773 /* We don't need the call_stub; this is a 16 bit function, so
8774 calls from other 16 bit functions are OK. Clobber the size
8775 to 0 to prevent it from being included in the link. */
8776 h
->call_fp_stub
->_raw_size
= 0;
8777 h
->call_fp_stub
->_cooked_size
= 0;
8778 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
8779 h
->call_fp_stub
->reloc_count
= 0;
8780 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
8786 /* Set the sizes of the dynamic sections. */
8789 _bfd_mips_elf_size_dynamic_sections (output_bfd
, info
)
8791 struct bfd_link_info
*info
;
8796 struct mips_got_info
*g
= NULL
;
8798 dynobj
= elf_hash_table (info
)->dynobj
;
8799 BFD_ASSERT (dynobj
!= NULL
);
8801 if (elf_hash_table (info
)->dynamic_sections_created
)
8803 /* Set the contents of the .interp section to the interpreter. */
8806 s
= bfd_get_section_by_name (dynobj
, ".interp");
8807 BFD_ASSERT (s
!= NULL
);
8809 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
8811 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
8815 /* The check_relocs and adjust_dynamic_symbol entry points have
8816 determined the sizes of the various dynamic sections. Allocate
8819 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8824 /* It's OK to base decisions on the section name, because none
8825 of the dynobj section names depend upon the input files. */
8826 name
= bfd_get_section_name (dynobj
, s
);
8828 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8833 if (strncmp (name
, ".rel", 4) == 0)
8835 if (s
->_raw_size
== 0)
8837 /* We only strip the section if the output section name
8838 has the same name. Otherwise, there might be several
8839 input sections for this output section. FIXME: This
8840 code is probably not needed these days anyhow, since
8841 the linker now does not create empty output sections. */
8842 if (s
->output_section
!= NULL
8844 bfd_get_section_name (s
->output_section
->owner
,
8845 s
->output_section
)) == 0)
8850 const char *outname
;
8853 /* If this relocation section applies to a read only
8854 section, then we probably need a DT_TEXTREL entry.
8855 If the relocation section is .rel.dyn, we always
8856 assert a DT_TEXTREL entry rather than testing whether
8857 there exists a relocation to a read only section or
8859 outname
= bfd_get_section_name (output_bfd
,
8861 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
8863 && (target
->flags
& SEC_READONLY
) != 0
8864 && (target
->flags
& SEC_ALLOC
) != 0)
8866 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd
)) == 0)
8869 /* We use the reloc_count field as a counter if we need
8870 to copy relocs into the output file. */
8872 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd
)) != 0)
8876 else if (strncmp (name
, ".got", 4) == 0)
8879 bfd_size_type loadable_size
= 0;
8880 bfd_size_type local_gotno
;
8883 BFD_ASSERT (elf_section_data (s
) != NULL
);
8884 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
8885 BFD_ASSERT (g
!= NULL
);
8887 /* Calculate the total loadable size of the output. That
8888 will give us the maximum number of GOT_PAGE entries
8890 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
8892 asection
*subsection
;
8894 for (subsection
= sub
->sections
;
8896 subsection
= subsection
->next
)
8898 if ((subsection
->flags
& SEC_ALLOC
) == 0)
8900 loadable_size
+= ((subsection
->_raw_size
+ 0xf)
8901 &~ (bfd_size_type
) 0xf);
8904 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
8906 /* Assume there are two loadable segments consisting of
8907 contiguous sections. Is 5 enough? */
8908 local_gotno
= (loadable_size
>> 16) + 5;
8909 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
8910 /* It's possible we will need GOT_PAGE entries as well as
8911 GOT16 entries. Often, these will be able to share GOT
8912 entries, but not always. */
8915 g
->local_gotno
+= local_gotno
;
8916 s
->_raw_size
+= local_gotno
* MIPS_ELF_GOT_SIZE (dynobj
);
8918 /* There has to be a global GOT entry for every symbol with
8919 a dynamic symbol table index of DT_MIPS_GOTSYM or
8920 higher. Therefore, it make sense to put those symbols
8921 that need GOT entries at the end of the symbol table. We
8923 if (!mips_elf_sort_hash_table (info
, 1))
8926 if (g
->global_gotsym
!= NULL
)
8927 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
8929 /* If there are no global symbols, or none requiring
8930 relocations, then GLOBAL_GOTSYM will be NULL. */
8932 g
->global_gotno
= i
;
8933 s
->_raw_size
+= i
* MIPS_ELF_GOT_SIZE (dynobj
);
8935 else if (strcmp (name
, MIPS_ELF_STUB_SECTION_NAME (output_bfd
)) == 0)
8937 /* Irix rld assumes that the function stub isn't at the end
8938 of .text section. So put a dummy. XXX */
8939 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
8941 else if (! info
->shared
8942 && ! mips_elf_hash_table (info
)->use_rld_obj_head
8943 && strncmp (name
, ".rld_map", 8) == 0)
8945 /* We add a room for __rld_map. It will be filled in by the
8946 rtld to contain a pointer to the _r_debug structure. */
8949 else if (SGI_COMPAT (output_bfd
)
8950 && strncmp (name
, ".compact_rel", 12) == 0)
8951 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
8952 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
))
8954 s
->_raw_size
= (sizeof (Elf32_External_Msym
)
8955 * (elf_hash_table (info
)->dynsymcount
8956 + bfd_count_sections (output_bfd
)));
8957 else if (strncmp (name
, ".init", 5) != 0)
8959 /* It's not one of our sections, so don't allocate space. */
8965 _bfd_strip_section_from_output (info
, s
);
8969 /* Allocate memory for the section contents. */
8970 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
8971 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
8973 bfd_set_error (bfd_error_no_memory
);
8978 if (elf_hash_table (info
)->dynamic_sections_created
)
8980 /* Add some entries to the .dynamic section. We fill in the
8981 values later, in elf_mips_finish_dynamic_sections, but we
8982 must add the entries now so that we get the correct size for
8983 the .dynamic section. The DT_DEBUG entry is filled in by the
8984 dynamic linker and used by the debugger. */
8987 /* SGI object has the equivalence of DT_DEBUG in the
8988 DT_MIPS_RLD_MAP entry. */
8989 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
8991 if (!SGI_COMPAT (output_bfd
))
8993 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
8999 /* Shared libraries on traditional mips have DT_DEBUG. */
9000 if (!SGI_COMPAT (output_bfd
))
9002 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
9007 if (reltext
&& SGI_COMPAT (output_bfd
))
9008 info
->flags
|= DF_TEXTREL
;
9010 if ((info
->flags
& DF_TEXTREL
) != 0)
9012 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
9016 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
9019 if (bfd_get_section_by_name (dynobj
,
9020 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
)))
9022 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
9025 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
9028 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
9032 if (SGI_COMPAT (output_bfd
))
9034 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICTNO
, 0))
9038 if (SGI_COMPAT (output_bfd
))
9040 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLISTNO
, 0))
9044 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
9046 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICT
, 0))
9049 s
= bfd_get_section_by_name (dynobj
, ".liblist");
9050 BFD_ASSERT (s
!= NULL
);
9052 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLIST
, 0))
9056 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
9059 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
9063 /* Time stamps in executable files are a bad idea. */
9064 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_TIME_STAMP
, 0))
9069 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_ICHECKSUM
, 0))
9074 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_IVERSION
, 0))
9078 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
9081 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
9084 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
9087 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
9090 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
9093 if (IRIX_COMPAT (dynobj
) == ict_irix5
9094 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
9097 if (IRIX_COMPAT (dynobj
) == ict_irix6
9098 && (bfd_get_section_by_name
9099 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
9100 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
9103 if (bfd_get_section_by_name (dynobj
,
9104 MIPS_ELF_MSYM_SECTION_NAME (dynobj
))
9105 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_MSYM
, 0))
9112 /* If NAME is one of the special IRIX6 symbols defined by the linker,
9113 adjust it appropriately now. */
9116 mips_elf_irix6_finish_dynamic_symbol (abfd
, name
, sym
)
9117 bfd
*abfd ATTRIBUTE_UNUSED
;
9119 Elf_Internal_Sym
*sym
;
9121 /* The linker script takes care of providing names and values for
9122 these, but we must place them into the right sections. */
9123 static const char* const text_section_symbols
[] = {
9126 "__dso_displacement",
9128 "__program_header_table",
9132 static const char* const data_section_symbols
[] = {
9140 const char* const *p
;
9143 for (i
= 0; i
< 2; ++i
)
9144 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
9147 if (strcmp (*p
, name
) == 0)
9149 /* All of these symbols are given type STT_SECTION by the
9151 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9153 /* The IRIX linker puts these symbols in special sections. */
9155 sym
->st_shndx
= SHN_MIPS_TEXT
;
9157 sym
->st_shndx
= SHN_MIPS_DATA
;
9163 /* Finish up dynamic symbol handling. We set the contents of various
9164 dynamic sections here. */
9167 _bfd_mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
9169 struct bfd_link_info
*info
;
9170 struct elf_link_hash_entry
*h
;
9171 Elf_Internal_Sym
*sym
;
9177 struct mips_got_info
*g
;
9179 struct mips_elf_link_hash_entry
*mh
;
9181 dynobj
= elf_hash_table (info
)->dynobj
;
9182 gval
= sym
->st_value
;
9183 mh
= (struct mips_elf_link_hash_entry
*) h
;
9185 if (h
->plt
.offset
!= (bfd_vma
) -1)
9189 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
9191 /* This symbol has a stub. Set it up. */
9193 BFD_ASSERT (h
->dynindx
!= -1);
9195 s
= bfd_get_section_by_name (dynobj
,
9196 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
9197 BFD_ASSERT (s
!= NULL
);
9199 /* Fill the stub. */
9201 bfd_put_32 (output_bfd
, (bfd_vma
) STUB_LW (output_bfd
), p
);
9203 bfd_put_32 (output_bfd
, (bfd_vma
) STUB_MOVE (output_bfd
), p
);
9206 /* FIXME: Can h->dynindex be more than 64K? */
9207 if (h
->dynindx
& 0xffff0000)
9210 bfd_put_32 (output_bfd
, (bfd_vma
) STUB_JALR
, p
);
9212 bfd_put_32 (output_bfd
, (bfd_vma
) STUB_LI16 (output_bfd
) + h
->dynindx
, p
);
9214 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
9215 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
9217 /* Mark the symbol as undefined. plt.offset != -1 occurs
9218 only for the referenced symbol. */
9219 sym
->st_shndx
= SHN_UNDEF
;
9221 /* The run-time linker uses the st_value field of the symbol
9222 to reset the global offset table entry for this external
9223 to its stub address when unlinking a shared object. */
9224 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
9225 sym
->st_value
= gval
;
9228 BFD_ASSERT (h
->dynindx
!= -1
9229 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0);
9231 sgot
= mips_elf_got_section (dynobj
);
9232 BFD_ASSERT (sgot
!= NULL
);
9233 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
9234 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
9235 BFD_ASSERT (g
!= NULL
);
9237 /* Run through the global symbol table, creating GOT entries for all
9238 the symbols that need them. */
9239 if (g
->global_gotsym
!= NULL
9240 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
9246 value
= sym
->st_value
;
9249 /* For an entity defined in a shared object, this will be
9250 NULL. (For functions in shared objects for
9251 which we have created stubs, ST_VALUE will be non-NULL.
9252 That's because such the functions are now no longer defined
9253 in a shared object.) */
9255 if (info
->shared
&& h
->root
.type
== bfd_link_hash_undefined
)
9258 value
= h
->root
.u
.def
.value
;
9260 offset
= mips_elf_global_got_index (dynobj
, h
);
9261 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
9264 /* Create a .msym entry, if appropriate. */
9265 smsym
= bfd_get_section_by_name (dynobj
,
9266 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
9269 Elf32_Internal_Msym msym
;
9271 msym
.ms_hash_value
= bfd_elf_hash (h
->root
.root
.string
);
9272 /* It is undocumented what the `1' indicates, but IRIX6 uses
9274 msym
.ms_info
= ELF32_MS_INFO (mh
->min_dyn_reloc_index
, 1);
9275 bfd_mips_elf_swap_msym_out
9277 ((Elf32_External_Msym
*) smsym
->contents
) + h
->dynindx
);
9280 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
9281 name
= h
->root
.root
.string
;
9282 if (strcmp (name
, "_DYNAMIC") == 0
9283 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
9284 sym
->st_shndx
= SHN_ABS
;
9285 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
9286 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
9288 sym
->st_shndx
= SHN_ABS
;
9289 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9292 else if (strcmp (name
, "_gp_disp") == 0)
9294 sym
->st_shndx
= SHN_ABS
;
9295 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9296 sym
->st_value
= elf_gp (output_bfd
);
9298 else if (SGI_COMPAT (output_bfd
))
9300 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
9301 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
9303 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9304 sym
->st_other
= STO_PROTECTED
;
9306 sym
->st_shndx
= SHN_MIPS_DATA
;
9308 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
9310 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9311 sym
->st_other
= STO_PROTECTED
;
9312 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
9313 sym
->st_shndx
= SHN_ABS
;
9315 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
9317 if (h
->type
== STT_FUNC
)
9318 sym
->st_shndx
= SHN_MIPS_TEXT
;
9319 else if (h
->type
== STT_OBJECT
)
9320 sym
->st_shndx
= SHN_MIPS_DATA
;
9324 /* Handle the IRIX6-specific symbols. */
9325 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
9326 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
9330 if (! mips_elf_hash_table (info
)->use_rld_obj_head
9331 && (strcmp (name
, "__rld_map") == 0
9332 || strcmp (name
, "__RLD_MAP") == 0))
9334 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
9335 BFD_ASSERT (s
!= NULL
);
9336 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
9337 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
9338 if (mips_elf_hash_table (info
)->rld_value
== 0)
9339 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
9341 else if (mips_elf_hash_table (info
)->use_rld_obj_head
9342 && strcmp (name
, "__rld_obj_head") == 0)
9344 /* IRIX6 does not use a .rld_map section. */
9345 if (IRIX_COMPAT (output_bfd
) == ict_irix5
9346 || IRIX_COMPAT (output_bfd
) == ict_none
)
9347 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
9349 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
9353 /* If this is a mips16 symbol, force the value to be even. */
9354 if (sym
->st_other
== STO_MIPS16
9355 && (sym
->st_value
& 1) != 0)
9361 /* Finish up the dynamic sections. */
9364 _bfd_mips_elf_finish_dynamic_sections (output_bfd
, info
)
9366 struct bfd_link_info
*info
;
9371 struct mips_got_info
*g
;
9373 dynobj
= elf_hash_table (info
)->dynobj
;
9375 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
9377 sgot
= mips_elf_got_section (dynobj
);
9382 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
9383 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
9384 BFD_ASSERT (g
!= NULL
);
9387 if (elf_hash_table (info
)->dynamic_sections_created
)
9391 BFD_ASSERT (sdyn
!= NULL
);
9392 BFD_ASSERT (g
!= NULL
);
9394 for (b
= sdyn
->contents
;
9395 b
< sdyn
->contents
+ sdyn
->_raw_size
;
9396 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
9398 Elf_Internal_Dyn dyn
;
9404 /* Read in the current dynamic entry. */
9405 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
9407 /* Assume that we're going to modify it and write it out. */
9413 s
= (bfd_get_section_by_name
9415 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
)));
9416 BFD_ASSERT (s
!= NULL
);
9417 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
9421 /* Rewrite DT_STRSZ. */
9423 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
9429 case DT_MIPS_CONFLICT
:
9432 case DT_MIPS_LIBLIST
:
9435 s
= bfd_get_section_by_name (output_bfd
, name
);
9436 BFD_ASSERT (s
!= NULL
);
9437 dyn
.d_un
.d_ptr
= s
->vma
;
9440 case DT_MIPS_RLD_VERSION
:
9441 dyn
.d_un
.d_val
= 1; /* XXX */
9445 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
9448 case DT_MIPS_CONFLICTNO
:
9450 elemsize
= sizeof (Elf32_Conflict
);
9453 case DT_MIPS_LIBLISTNO
:
9455 elemsize
= sizeof (Elf32_Lib
);
9457 s
= bfd_get_section_by_name (output_bfd
, name
);
9460 if (s
->_cooked_size
!= 0)
9461 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
9463 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
9469 case DT_MIPS_TIME_STAMP
:
9470 time ((time_t *) &dyn
.d_un
.d_val
);
9473 case DT_MIPS_ICHECKSUM
:
9478 case DT_MIPS_IVERSION
:
9483 case DT_MIPS_BASE_ADDRESS
:
9484 s
= output_bfd
->sections
;
9485 BFD_ASSERT (s
!= NULL
);
9486 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
9489 case DT_MIPS_LOCAL_GOTNO
:
9490 dyn
.d_un
.d_val
= g
->local_gotno
;
9493 case DT_MIPS_UNREFEXTNO
:
9494 /* The index into the dynamic symbol table which is the
9495 entry of the first external symbol that is not
9496 referenced within the same object. */
9497 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
9500 case DT_MIPS_GOTSYM
:
9501 if (g
->global_gotsym
)
9503 dyn
.d_un
.d_val
= g
->global_gotsym
->dynindx
;
9506 /* In case if we don't have global got symbols we default
9507 to setting DT_MIPS_GOTSYM to the same value as
9508 DT_MIPS_SYMTABNO, so we just fall through. */
9510 case DT_MIPS_SYMTABNO
:
9512 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
9513 s
= bfd_get_section_by_name (output_bfd
, name
);
9514 BFD_ASSERT (s
!= NULL
);
9516 if (s
->_cooked_size
!= 0)
9517 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
9519 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
9522 case DT_MIPS_HIPAGENO
:
9523 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
9526 case DT_MIPS_RLD_MAP
:
9527 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
9530 case DT_MIPS_OPTIONS
:
9531 s
= (bfd_get_section_by_name
9532 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
9533 dyn
.d_un
.d_ptr
= s
->vma
;
9537 s
= (bfd_get_section_by_name
9538 (output_bfd
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
)));
9539 dyn
.d_un
.d_ptr
= s
->vma
;
9548 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
9553 /* The first entry of the global offset table will be filled at
9554 runtime. The second entry will be used by some runtime loaders.
9555 This isn't the case of Irix rld. */
9556 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
9558 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
9559 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0x80000000,
9560 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
9564 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
9565 = MIPS_ELF_GOT_SIZE (output_bfd
);
9570 Elf32_compact_rel cpt
;
9572 /* ??? The section symbols for the output sections were set up in
9573 _bfd_elf_final_link. SGI sets the STT_NOTYPE attribute for these
9574 symbols. Should we do so? */
9576 smsym
= bfd_get_section_by_name (dynobj
,
9577 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
9580 Elf32_Internal_Msym msym
;
9582 msym
.ms_hash_value
= 0;
9583 msym
.ms_info
= ELF32_MS_INFO (0, 1);
9585 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
9587 long dynindx
= elf_section_data (s
)->dynindx
;
9589 bfd_mips_elf_swap_msym_out
9591 (((Elf32_External_Msym
*) smsym
->contents
)
9596 if (SGI_COMPAT (output_bfd
))
9598 /* Write .compact_rel section out. */
9599 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
9603 cpt
.num
= s
->reloc_count
;
9605 cpt
.offset
= (s
->output_section
->filepos
9606 + sizeof (Elf32_External_compact_rel
));
9609 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
9610 ((Elf32_External_compact_rel
*)
9613 /* Clean up a dummy stub function entry in .text. */
9614 s
= bfd_get_section_by_name (dynobj
,
9615 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
9618 file_ptr dummy_offset
;
9620 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
9621 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
9622 memset (s
->contents
+ dummy_offset
, 0,
9623 MIPS_FUNCTION_STUB_SIZE
);
9628 /* We need to sort the entries of the dynamic relocation section. */
9630 if (!ABI_64_P (output_bfd
))
9634 reldyn
= bfd_get_section_by_name (dynobj
,
9635 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
));
9636 if (reldyn
!= NULL
&& reldyn
->reloc_count
> 2)
9638 reldyn_sorting_bfd
= output_bfd
;
9639 qsort ((Elf32_External_Rel
*) reldyn
->contents
+ 1,
9640 (size_t) reldyn
->reloc_count
- 1,
9641 sizeof (Elf32_External_Rel
), sort_dynamic_relocs
);
9645 /* Clean up a first relocation in .rel.dyn. */
9646 s
= bfd_get_section_by_name (dynobj
,
9647 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
));
9648 if (s
!= NULL
&& s
->_raw_size
> 0)
9649 memset (s
->contents
, 0, MIPS_ELF_REL_SIZE (dynobj
));
9655 /* Support for core dump NOTE sections */
9657 _bfd_elf32_mips_grok_prstatus (abfd
, note
)
9659 Elf_Internal_Note
*note
;
9662 unsigned int raw_size
;
9664 switch (note
->descsz
)
9669 case 256: /* Linux/MIPS */
9671 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
9674 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
9683 /* Make a ".reg/999" section. */
9684 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
9685 raw_size
, note
->descpos
+ offset
);
9689 _bfd_elf32_mips_grok_psinfo (abfd
, note
)
9691 Elf_Internal_Note
*note
;
9693 switch (note
->descsz
)
9698 case 128: /* Linux/MIPS elf_prpsinfo */
9699 elf_tdata (abfd
)->core_program
9700 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
9701 elf_tdata (abfd
)->core_command
9702 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
9705 /* Note that for some reason, a spurious space is tacked
9706 onto the end of the args in some (at least one anyway)
9707 implementations, so strip it off if it exists. */
9710 char *command
= elf_tdata (abfd
)->core_command
;
9711 int n
= strlen (command
);
9713 if (0 < n
&& command
[n
- 1] == ' ')
9714 command
[n
- 1] = '\0';
9723 _bfd_elf32_mips_discard_info (abfd
, cookie
, info
)
9725 struct elf_reloc_cookie
*cookie
;
9726 struct bfd_link_info
*info
;
9729 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
9730 boolean ret
= false;
9731 unsigned char *tdata
;
9734 o
= bfd_get_section_by_name (abfd
, ".pdr");
9737 if (o
->_raw_size
== 0)
9739 if (o
->_raw_size
% PDR_SIZE
!= 0)
9741 if (o
->output_section
!= NULL
9742 && bfd_is_abs_section (o
->output_section
))
9745 tdata
= bfd_zmalloc (o
->_raw_size
/ PDR_SIZE
);
9749 cookie
->rels
= _bfd_elf32_link_read_relocs (abfd
, o
, (PTR
) NULL
,
9750 (Elf_Internal_Rela
*) NULL
,
9758 cookie
->rel
= cookie
->rels
;
9760 cookie
->rels
+ o
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
9762 for (i
= 0, skip
= 0; i
< o
->_raw_size
; i
++)
9764 if (_bfd_elf32_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
9773 elf_section_data (o
)->tdata
= tdata
;
9774 o
->_cooked_size
= o
->_raw_size
- skip
* PDR_SIZE
;
9780 if (! info
->keep_memory
)
9781 free (cookie
->rels
);
9787 _bfd_elf32_mips_ignore_discarded_relocs (sec
)
9790 if (strcmp (sec
->name
, ".pdr") == 0)
9796 _bfd_elf32_mips_write_section (output_bfd
, sec
, contents
)
9801 bfd_byte
*to
, *from
, *end
;
9804 if (strcmp (sec
->name
, ".pdr") != 0)
9807 if (elf_section_data (sec
)->tdata
== NULL
)
9811 end
= contents
+ sec
->_raw_size
;
9812 for (from
= contents
, i
= 0;
9814 from
+= PDR_SIZE
, i
++)
9816 if (((unsigned char *)elf_section_data (sec
)->tdata
)[i
] == 1)
9819 memcpy (to
, from
, PDR_SIZE
);
9822 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
9823 (file_ptr
) sec
->output_offset
,
9828 /* This is almost identical to bfd_generic_get_... except that some
9829 MIPS relocations need to be handled specially. Sigh. */
9832 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
9833 relocateable
, symbols
)
9835 struct bfd_link_info
*link_info
;
9836 struct bfd_link_order
*link_order
;
9838 boolean relocateable
;
9841 /* Get enough memory to hold the stuff */
9842 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
9843 asection
*input_section
= link_order
->u
.indirect
.section
;
9845 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
9846 arelent
**reloc_vector
= NULL
;
9852 reloc_vector
= (arelent
**) bfd_malloc ((bfd_size_type
) reloc_size
);
9853 if (reloc_vector
== NULL
&& reloc_size
!= 0)
9856 /* read in the section */
9857 if (!bfd_get_section_contents (input_bfd
,
9861 input_section
->_raw_size
))
9864 /* We're not relaxing the section, so just copy the size info */
9865 input_section
->_cooked_size
= input_section
->_raw_size
;
9866 input_section
->reloc_done
= true;
9868 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
9872 if (reloc_count
< 0)
9875 if (reloc_count
> 0)
9880 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
9883 struct bfd_hash_entry
*h
;
9884 struct bfd_link_hash_entry
*lh
;
9885 /* Skip all this stuff if we aren't mixing formats. */
9886 if (abfd
&& input_bfd
9887 && abfd
->xvec
== input_bfd
->xvec
)
9891 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
9892 lh
= (struct bfd_link_hash_entry
*) h
;
9899 case bfd_link_hash_undefined
:
9900 case bfd_link_hash_undefweak
:
9901 case bfd_link_hash_common
:
9904 case bfd_link_hash_defined
:
9905 case bfd_link_hash_defweak
:
9907 gp
= lh
->u
.def
.value
;
9909 case bfd_link_hash_indirect
:
9910 case bfd_link_hash_warning
:
9912 /* @@FIXME ignoring warning for now */
9914 case bfd_link_hash_new
:
9923 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
9926 char *error_message
= (char *) NULL
;
9927 bfd_reloc_status_type r
;
9929 /* Specific to MIPS: Deal with relocation types that require
9930 knowing the gp of the output bfd. */
9931 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
9932 if (bfd_is_abs_section (sym
->section
) && abfd
)
9934 /* The special_function wouldn't get called anyways. */
9938 /* The gp isn't there; let the special function code
9939 fall over on its own. */
9941 else if ((*parent
)->howto
->special_function
9942 == _bfd_mips_elf_gprel16_reloc
)
9944 /* bypass special_function call */
9945 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
9946 relocateable
, (PTR
) data
, gp
);
9947 goto skip_bfd_perform_relocation
;
9949 /* end mips specific stuff */
9951 r
= bfd_perform_relocation (input_bfd
,
9955 relocateable
? abfd
: (bfd
*) NULL
,
9957 skip_bfd_perform_relocation
:
9961 asection
*os
= input_section
->output_section
;
9963 /* A partial link, so keep the relocs */
9964 os
->orelocation
[os
->reloc_count
] = *parent
;
9968 if (r
!= bfd_reloc_ok
)
9972 case bfd_reloc_undefined
:
9973 if (!((*link_info
->callbacks
->undefined_symbol
)
9974 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
9975 input_bfd
, input_section
, (*parent
)->address
,
9979 case bfd_reloc_dangerous
:
9980 BFD_ASSERT (error_message
!= (char *) NULL
);
9981 if (!((*link_info
->callbacks
->reloc_dangerous
)
9982 (link_info
, error_message
, input_bfd
, input_section
,
9983 (*parent
)->address
)))
9986 case bfd_reloc_overflow
:
9987 if (!((*link_info
->callbacks
->reloc_overflow
)
9988 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
9989 (*parent
)->howto
->name
, (*parent
)->addend
,
9990 input_bfd
, input_section
, (*parent
)->address
)))
9993 case bfd_reloc_outofrange
:
10002 if (reloc_vector
!= NULL
)
10003 free (reloc_vector
);
10007 if (reloc_vector
!= NULL
)
10008 free (reloc_vector
);
10012 #define bfd_elf32_bfd_get_relocated_section_contents \
10013 elf32_mips_get_relocated_section_contents
10015 /* ECOFF swapping routines. These are used when dealing with the
10016 .mdebug section, which is in the ECOFF debugging format. */
10017 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
= {
10018 /* Symbol table magic number. */
10020 /* Alignment of debugging information. E.g., 4. */
10022 /* Sizes of external symbolic information. */
10023 sizeof (struct hdr_ext
),
10024 sizeof (struct dnr_ext
),
10025 sizeof (struct pdr_ext
),
10026 sizeof (struct sym_ext
),
10027 sizeof (struct opt_ext
),
10028 sizeof (struct fdr_ext
),
10029 sizeof (struct rfd_ext
),
10030 sizeof (struct ext_ext
),
10031 /* Functions to swap in external symbolic data. */
10040 _bfd_ecoff_swap_tir_in
,
10041 _bfd_ecoff_swap_rndx_in
,
10042 /* Functions to swap out external symbolic data. */
10043 ecoff_swap_hdr_out
,
10044 ecoff_swap_dnr_out
,
10045 ecoff_swap_pdr_out
,
10046 ecoff_swap_sym_out
,
10047 ecoff_swap_opt_out
,
10048 ecoff_swap_fdr_out
,
10049 ecoff_swap_rfd_out
,
10050 ecoff_swap_ext_out
,
10051 _bfd_ecoff_swap_tir_out
,
10052 _bfd_ecoff_swap_rndx_out
,
10053 /* Function to read in symbolic data. */
10054 _bfd_mips_elf_read_ecoff_info
10057 #define ELF_ARCH bfd_arch_mips
10058 #define ELF_MACHINE_CODE EM_MIPS
10060 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
10061 a value of 0x1000, and we are compatible. */
10062 #define ELF_MAXPAGESIZE 0x1000
10064 #define elf_backend_collect true
10065 #define elf_backend_type_change_ok true
10066 #define elf_backend_can_gc_sections true
10067 #define elf_info_to_howto mips_info_to_howto_rela
10068 #define elf_info_to_howto_rel mips_info_to_howto_rel
10069 #define elf_backend_sym_is_global mips_elf_sym_is_global
10070 #define elf_backend_object_p _bfd_mips_elf_object_p
10071 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
10072 #define elf_backend_section_processing _bfd_mips_elf_section_processing
10073 #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
10074 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
10075 #define elf_backend_section_from_bfd_section \
10076 _bfd_mips_elf_section_from_bfd_section
10077 #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
10078 #define elf_backend_link_output_symbol_hook \
10079 _bfd_mips_elf_link_output_symbol_hook
10080 #define elf_backend_create_dynamic_sections \
10081 _bfd_mips_elf_create_dynamic_sections
10082 #define elf_backend_check_relocs _bfd_mips_elf_check_relocs
10083 #define elf_backend_adjust_dynamic_symbol \
10084 _bfd_mips_elf_adjust_dynamic_symbol
10085 #define elf_backend_always_size_sections \
10086 _bfd_mips_elf_always_size_sections
10087 #define elf_backend_size_dynamic_sections \
10088 _bfd_mips_elf_size_dynamic_sections
10089 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section
10090 #define elf_backend_finish_dynamic_symbol \
10091 _bfd_mips_elf_finish_dynamic_symbol
10092 #define elf_backend_finish_dynamic_sections \
10093 _bfd_mips_elf_finish_dynamic_sections
10094 #define elf_backend_final_write_processing \
10095 _bfd_mips_elf_final_write_processing
10096 #define elf_backend_additional_program_headers \
10097 _bfd_mips_elf_additional_program_headers
10098 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
10099 #define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
10100 #define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
10101 #define elf_backend_copy_indirect_symbol \
10102 _bfd_mips_elf_copy_indirect_symbol
10103 #define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
10104 #define elf_backend_grok_prstatus _bfd_elf32_mips_grok_prstatus
10105 #define elf_backend_grok_psinfo _bfd_elf32_mips_grok_psinfo
10106 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
10108 #define elf_backend_got_header_size (4 * MIPS_RESERVED_GOTNO)
10109 #define elf_backend_plt_header_size 0
10110 #define elf_backend_may_use_rel_p 1
10111 #define elf_backend_may_use_rela_p 0
10112 #define elf_backend_default_use_rela_p 0
10113 #define elf_backend_sign_extend_vma true
10115 #define elf_backend_discard_info _bfd_elf32_mips_discard_info
10116 #define elf_backend_ignore_discarded_relocs \
10117 _bfd_elf32_mips_ignore_discarded_relocs
10118 #define elf_backend_write_section _bfd_elf32_mips_write_section
10120 #define bfd_elf32_bfd_is_local_label_name \
10121 mips_elf_is_local_label_name
10122 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
10123 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
10124 #define bfd_elf32_bfd_link_hash_table_create \
10125 _bfd_mips_elf_link_hash_table_create
10126 #define bfd_elf32_bfd_final_link _bfd_mips_elf_final_link
10127 #define bfd_elf32_bfd_merge_private_bfd_data \
10128 _bfd_mips_elf_merge_private_bfd_data
10129 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
10130 #define bfd_elf32_bfd_print_private_bfd_data \
10131 _bfd_mips_elf_print_private_bfd_data
10133 /* Support for SGI-ish mips targets. */
10134 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
10135 #define TARGET_LITTLE_NAME "elf32-littlemips"
10136 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
10137 #define TARGET_BIG_NAME "elf32-bigmips"
10139 #include "elf32-target.h"
10141 /* Support for traditional mips targets. */
10142 #define INCLUDED_TARGET_FILE /* More a type of flag. */
10144 #undef TARGET_LITTLE_SYM
10145 #undef TARGET_LITTLE_NAME
10146 #undef TARGET_BIG_SYM
10147 #undef TARGET_BIG_NAME
10149 #define TARGET_LITTLE_SYM bfd_elf32_tradlittlemips_vec
10150 #define TARGET_LITTLE_NAME "elf32-tradlittlemips"
10151 #define TARGET_BIG_SYM bfd_elf32_tradbigmips_vec
10152 #define TARGET_BIG_NAME "elf32-tradbigmips"
10154 /* Include the target file again for this target */
10155 #include "elf32-target.h"