1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 Most of the information added by Ian Lance Taylor, Cygnus Support,
7 N32/64 ABI support added by Mark Mitchell, CodeSourcery, LLC.
8 <mark@codesourcery.com>
9 Traditional MIPS targets support added by Koundinya.K, Dansk Data
10 Elektronik & Operations Research Group. <kk@ddeorg.soft.net>
12 This file is part of BFD, the Binary File Descriptor library.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 /* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
29 different MIPS ELF from other targets. This matters when linking.
30 This file supports both, switching at runtime. */
40 /* Get the ECOFF swapping routines. */
42 #include "coff/symconst.h"
43 #include "coff/internal.h"
44 #include "coff/ecoff.h"
45 #include "coff/mips.h"
46 #define ECOFF_SIGNED_32
47 #include "ecoffswap.h"
49 /* This structure is used to hold .got information when linking. It
50 is stored in the tdata field of the bfd_elf_section_data structure. */
54 /* The global symbol in the GOT with the lowest index in the dynamic
56 struct elf_link_hash_entry
*global_gotsym
;
57 /* The number of global .got entries. */
58 unsigned int global_gotno
;
59 /* The number of local .got entries. */
60 unsigned int local_gotno
;
61 /* The number of local .got entries we have used. */
62 unsigned int assigned_gotno
;
65 /* The MIPS ELF linker needs additional information for each symbol in
66 the global hash table. */
68 struct mips_elf_link_hash_entry
70 struct elf_link_hash_entry root
;
72 /* External symbol information. */
75 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
77 unsigned int possibly_dynamic_relocs
;
79 /* If the R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 reloc is against
80 a readonly section. */
81 boolean readonly_reloc
;
83 /* The index of the first dynamic relocation (in the .rel.dyn
84 section) against this symbol. */
85 unsigned int min_dyn_reloc_index
;
87 /* We must not create a stub for a symbol that has relocations
88 related to taking the function's address, i.e. any but
89 R_MIPS_CALL*16 ones -- see "MIPS ABI Supplement, 3rd Edition",
93 /* If there is a stub that 32 bit functions should use to call this
94 16 bit function, this points to the section containing the stub. */
97 /* Whether we need the fn_stub; this is set if this symbol appears
98 in any relocs other than a 16 bit call. */
101 /* If there is a stub that 16 bit functions should use to call this
102 32 bit function, this points to the section containing the stub. */
105 /* This is like the call_stub field, but it is used if the function
106 being called returns a floating point value. */
107 asection
*call_fp_stub
;
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
*, boolean
));
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.
1645 MIPS ELF requires that the LO16 immediately follow the HI16. As a
1646 GNU extension, for non-pc-relative relocations, we permit an
1647 arbitrary number of HI16 relocs to be associated with a single LO16
1648 reloc. This extension permits gcc to output the HI and LO relocs
1651 This cannot be done for PC-relative relocations because both the HI16
1652 and LO16 parts of the relocations must be done relative to the LO16
1653 part, and there can be carry to or borrow from the HI16 part. */
1657 struct mips_hi16
*next
;
1662 /* FIXME: This should not be a static variable. */
1664 static struct mips_hi16
*mips_hi16_list
;
1666 bfd_reloc_status_type
1667 _bfd_mips_elf_hi16_reloc (abfd
,
1674 bfd
*abfd ATTRIBUTE_UNUSED
;
1675 arelent
*reloc_entry
;
1678 asection
*input_section
;
1680 char **error_message
;
1682 bfd_reloc_status_type ret
;
1684 struct mips_hi16
*n
;
1686 /* If we're relocating, and this an external symbol, we don't want
1687 to change anything. */
1688 if (output_bfd
!= (bfd
*) NULL
1689 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1690 && reloc_entry
->addend
== 0)
1692 reloc_entry
->address
+= input_section
->output_offset
;
1693 return bfd_reloc_ok
;
1698 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1700 boolean relocateable
;
1703 if (ret
== bfd_reloc_undefined
)
1706 if (output_bfd
!= NULL
)
1707 relocateable
= true;
1710 relocateable
= false;
1711 output_bfd
= symbol
->section
->output_section
->owner
;
1714 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1715 error_message
, &gp
);
1716 if (ret
!= bfd_reloc_ok
)
1719 relocation
= gp
- reloc_entry
->address
;
1723 if (bfd_is_und_section (symbol
->section
)
1724 && output_bfd
== (bfd
*) NULL
)
1725 ret
= bfd_reloc_undefined
;
1727 if (bfd_is_com_section (symbol
->section
))
1730 relocation
= symbol
->value
;
1733 relocation
+= symbol
->section
->output_section
->vma
;
1734 relocation
+= symbol
->section
->output_offset
;
1735 relocation
+= reloc_entry
->addend
;
1737 if (reloc_entry
->address
> input_section
->_cooked_size
)
1738 return bfd_reloc_outofrange
;
1740 /* Save the information, and let LO16 do the actual relocation. */
1741 n
= (struct mips_hi16
*) bfd_malloc ((bfd_size_type
) sizeof *n
);
1743 return bfd_reloc_outofrange
;
1744 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
1745 n
->addend
= relocation
;
1746 n
->next
= mips_hi16_list
;
1749 if (output_bfd
!= (bfd
*) NULL
)
1750 reloc_entry
->address
+= input_section
->output_offset
;
1755 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
1756 inplace relocation; this function exists in order to do the
1757 R_MIPS_HI16 relocation described above. */
1759 bfd_reloc_status_type
1760 _bfd_mips_elf_lo16_reloc (abfd
,
1768 arelent
*reloc_entry
;
1771 asection
*input_section
;
1773 char **error_message
;
1775 arelent gp_disp_relent
;
1777 if (mips_hi16_list
!= NULL
)
1779 struct mips_hi16
*l
;
1786 unsigned long vallo
;
1787 struct mips_hi16
*next
;
1789 /* Do the HI16 relocation. Note that we actually don't need
1790 to know anything about the LO16 itself, except where to
1791 find the low 16 bits of the addend needed by the LO16. */
1792 insn
= bfd_get_32 (abfd
, l
->addr
);
1793 vallo
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1795 /* The low order 16 bits are always treated as a signed
1797 vallo
= ((vallo
& 0xffff) ^ 0x8000) - 0x8000;
1798 val
= ((insn
& 0xffff) << 16) + vallo
;
1801 /* If PC-relative, we need to subtract out the address of the LO
1802 half of the HI/LO. (The actual relocation is relative
1803 to that instruction.) */
1804 if (reloc_entry
->howto
->pc_relative
)
1805 val
-= reloc_entry
->address
;
1807 /* At this point, "val" has the value of the combined HI/LO
1808 pair. If the low order 16 bits (which will be used for
1809 the LO16 insn) are negative, then we will need an
1810 adjustment for the high order 16 bits. */
1812 val
= (val
>> 16) & 0xffff;
1814 insn
&= ~ (bfd_vma
) 0xffff;
1816 bfd_put_32 (abfd
, (bfd_vma
) insn
, l
->addr
);
1818 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1820 gp_disp_relent
= *reloc_entry
;
1821 reloc_entry
= &gp_disp_relent
;
1822 reloc_entry
->addend
= l
->addend
;
1830 mips_hi16_list
= NULL
;
1832 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1834 bfd_reloc_status_type ret
;
1835 bfd_vma gp
, relocation
;
1837 /* FIXME: Does this case ever occur? */
1839 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
1840 if (ret
!= bfd_reloc_ok
)
1843 relocation
= gp
- reloc_entry
->address
;
1844 relocation
+= symbol
->section
->output_section
->vma
;
1845 relocation
+= symbol
->section
->output_offset
;
1846 relocation
+= reloc_entry
->addend
;
1848 if (reloc_entry
->address
> input_section
->_cooked_size
)
1849 return bfd_reloc_outofrange
;
1851 gp_disp_relent
= *reloc_entry
;
1852 reloc_entry
= &gp_disp_relent
;
1853 reloc_entry
->addend
= relocation
- 4;
1856 /* Now do the LO16 reloc in the usual way. */
1857 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1858 input_section
, output_bfd
, error_message
);
1861 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1862 table used for PIC code. If the symbol is an external symbol, the
1863 instruction is modified to contain the offset of the appropriate
1864 entry in the global offset table. If the symbol is a section
1865 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1866 addends are combined to form the real addend against the section
1867 symbol; the GOT16 is modified to contain the offset of an entry in
1868 the global offset table, and the LO16 is modified to offset it
1869 appropriately. Thus an offset larger than 16 bits requires a
1870 modified value in the global offset table.
1872 This implementation suffices for the assembler, but the linker does
1873 not yet know how to create global offset tables. */
1875 bfd_reloc_status_type
1876 _bfd_mips_elf_got16_reloc (abfd
,
1884 arelent
*reloc_entry
;
1887 asection
*input_section
;
1889 char **error_message
;
1891 /* If we're relocating, and this an external symbol, we don't want
1892 to change anything. */
1893 if (output_bfd
!= (bfd
*) NULL
1894 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1895 && reloc_entry
->addend
== 0)
1897 reloc_entry
->address
+= input_section
->output_offset
;
1898 return bfd_reloc_ok
;
1901 /* If we're relocating, and this is a local symbol, we can handle it
1903 if (output_bfd
!= (bfd
*) NULL
1904 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1905 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1906 input_section
, output_bfd
, error_message
);
1911 /* Set the GP value for OUTPUT_BFD. Returns false if this is a
1912 dangerous relocation. */
1915 mips_elf_assign_gp (output_bfd
, pgp
)
1923 /* If we've already figured out what GP will be, just return it. */
1924 *pgp
= _bfd_get_gp_value (output_bfd
);
1928 count
= bfd_get_symcount (output_bfd
);
1929 sym
= bfd_get_outsymbols (output_bfd
);
1931 /* The linker script will have created a symbol named `_gp' with the
1932 appropriate value. */
1933 if (sym
== (asymbol
**) NULL
)
1937 for (i
= 0; i
< count
; i
++, sym
++)
1939 register const char *name
;
1941 name
= bfd_asymbol_name (*sym
);
1942 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1944 *pgp
= bfd_asymbol_value (*sym
);
1945 _bfd_set_gp_value (output_bfd
, *pgp
);
1953 /* Only get the error once. */
1955 _bfd_set_gp_value (output_bfd
, *pgp
);
1962 /* We have to figure out the gp value, so that we can adjust the
1963 symbol value correctly. We look up the symbol _gp in the output
1964 BFD. If we can't find it, we're stuck. We cache it in the ELF
1965 target data. We don't need to adjust the symbol value for an
1966 external symbol if we are producing relocateable output. */
1968 static bfd_reloc_status_type
1969 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1972 boolean relocateable
;
1973 char **error_message
;
1976 if (bfd_is_und_section (symbol
->section
)
1980 return bfd_reloc_undefined
;
1983 *pgp
= _bfd_get_gp_value (output_bfd
);
1986 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1990 /* Make up a value. */
1991 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1992 _bfd_set_gp_value (output_bfd
, *pgp
);
1994 else if (!mips_elf_assign_gp (output_bfd
, pgp
))
1997 (char *) _("GP relative relocation when _gp not defined");
1998 return bfd_reloc_dangerous
;
2002 return bfd_reloc_ok
;
2005 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
2006 become the offset from the gp register. This function also handles
2007 R_MIPS_LITERAL relocations, although those can be handled more
2008 cleverly because the entries in the .lit8 and .lit4 sections can be
2011 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
2012 arelent
*, asection
*,
2013 boolean
, PTR
, bfd_vma
));
2015 bfd_reloc_status_type
2016 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
2017 output_bfd
, error_message
)
2019 arelent
*reloc_entry
;
2022 asection
*input_section
;
2024 char **error_message
;
2026 boolean relocateable
;
2027 bfd_reloc_status_type ret
;
2030 /* If we're relocating, and this is an external symbol with no
2031 addend, we don't want to change anything. We will only have an
2032 addend if this is a newly created reloc, not read from an ELF
2034 if (output_bfd
!= (bfd
*) NULL
2035 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
2036 && reloc_entry
->addend
== 0)
2038 reloc_entry
->address
+= input_section
->output_offset
;
2039 return bfd_reloc_ok
;
2042 if (output_bfd
!= (bfd
*) NULL
)
2043 relocateable
= true;
2046 relocateable
= false;
2047 output_bfd
= symbol
->section
->output_section
->owner
;
2050 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
2052 if (ret
!= bfd_reloc_ok
)
2055 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
2056 relocateable
, data
, gp
);
2059 static bfd_reloc_status_type
2060 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
2064 arelent
*reloc_entry
;
2065 asection
*input_section
;
2066 boolean relocateable
;
2074 if (bfd_is_com_section (symbol
->section
))
2077 relocation
= symbol
->value
;
2079 relocation
+= symbol
->section
->output_section
->vma
;
2080 relocation
+= symbol
->section
->output_offset
;
2082 if (reloc_entry
->address
> input_section
->_cooked_size
)
2083 return bfd_reloc_outofrange
;
2085 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
2087 /* Set val to the offset into the section or symbol. */
2088 if (reloc_entry
->howto
->src_mask
== 0)
2090 /* This case occurs with the 64-bit MIPS ELF ABI. */
2091 val
= reloc_entry
->addend
;
2095 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
2100 /* Adjust val for the final section location and GP value. If we
2101 are producing relocateable output, we don't want to do this for
2102 an external symbol. */
2104 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
2105 val
+= relocation
- gp
;
2107 insn
= (insn
& ~0xffff) | (val
& 0xffff);
2108 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
2111 reloc_entry
->address
+= input_section
->output_offset
;
2113 /* Make sure it fit in 16 bits. */
2114 if ((long) val
>= 0x8000 || (long) val
< -0x8000)
2115 return bfd_reloc_overflow
;
2117 return bfd_reloc_ok
;
2120 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
2121 from the gp register? XXX */
2123 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
2124 arelent
*, asection
*,
2125 boolean
, PTR
, bfd_vma
));
2127 bfd_reloc_status_type
2128 _bfd_mips_elf_gprel32_reloc (abfd
,
2136 arelent
*reloc_entry
;
2139 asection
*input_section
;
2141 char **error_message
;
2143 boolean relocateable
;
2144 bfd_reloc_status_type ret
;
2147 /* If we're relocating, and this is an external symbol with no
2148 addend, we don't want to change anything. We will only have an
2149 addend if this is a newly created reloc, not read from an ELF
2151 if (output_bfd
!= (bfd
*) NULL
2152 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
2153 && reloc_entry
->addend
== 0)
2155 *error_message
= (char *)
2156 _("32bits gp relative relocation occurs for an external symbol");
2157 return bfd_reloc_outofrange
;
2160 if (output_bfd
!= (bfd
*) NULL
)
2162 relocateable
= true;
2163 gp
= _bfd_get_gp_value (output_bfd
);
2167 relocateable
= false;
2168 output_bfd
= symbol
->section
->output_section
->owner
;
2170 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
2171 error_message
, &gp
);
2172 if (ret
!= bfd_reloc_ok
)
2176 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
2177 relocateable
, data
, gp
);
2180 static bfd_reloc_status_type
2181 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
2185 arelent
*reloc_entry
;
2186 asection
*input_section
;
2187 boolean relocateable
;
2194 if (bfd_is_com_section (symbol
->section
))
2197 relocation
= symbol
->value
;
2199 relocation
+= symbol
->section
->output_section
->vma
;
2200 relocation
+= symbol
->section
->output_offset
;
2202 if (reloc_entry
->address
> input_section
->_cooked_size
)
2203 return bfd_reloc_outofrange
;
2205 if (reloc_entry
->howto
->src_mask
== 0)
2207 /* This case arises with the 64-bit MIPS ELF ABI. */
2211 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
2213 /* Set val to the offset into the section or symbol. */
2214 val
+= reloc_entry
->addend
;
2216 /* Adjust val for the final section location and GP value. If we
2217 are producing relocateable output, we don't want to do this for
2218 an external symbol. */
2220 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
2221 val
+= relocation
- gp
;
2223 bfd_put_32 (abfd
, (bfd_vma
) val
, (bfd_byte
*) data
+ reloc_entry
->address
);
2226 reloc_entry
->address
+= input_section
->output_offset
;
2228 return bfd_reloc_ok
;
2231 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
2232 generated when addresses are 64 bits. The upper 32 bits are a simple
2235 static bfd_reloc_status_type
2236 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
2237 output_bfd
, error_message
)
2239 arelent
*reloc_entry
;
2242 asection
*input_section
;
2244 char **error_message
;
2246 bfd_reloc_status_type r
;
2251 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2252 input_section
, output_bfd
, error_message
);
2253 if (r
!= bfd_reloc_continue
)
2256 /* Do a normal 32 bit relocation on the lower 32 bits. */
2257 reloc32
= *reloc_entry
;
2258 if (bfd_big_endian (abfd
))
2259 reloc32
.address
+= 4;
2260 reloc32
.howto
= &elf_mips_howto_table_rel
[R_MIPS_32
];
2261 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
2262 output_bfd
, error_message
);
2264 /* Sign extend into the upper 32 bits. */
2265 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
2266 if ((val
& 0x80000000) != 0)
2270 addr
= reloc_entry
->address
;
2271 if (bfd_little_endian (abfd
))
2273 bfd_put_32 (abfd
, (bfd_vma
) val
, (bfd_byte
*) data
+ addr
);
2278 /* Handle a mips16 jump. */
2280 static bfd_reloc_status_type
2281 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
2282 output_bfd
, error_message
)
2283 bfd
*abfd ATTRIBUTE_UNUSED
;
2284 arelent
*reloc_entry
;
2286 PTR data ATTRIBUTE_UNUSED
;
2287 asection
*input_section
;
2289 char **error_message ATTRIBUTE_UNUSED
;
2291 if (output_bfd
!= (bfd
*) NULL
2292 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
2293 && reloc_entry
->addend
== 0)
2295 reloc_entry
->address
+= input_section
->output_offset
;
2296 return bfd_reloc_ok
;
2301 static boolean warned
;
2304 (*_bfd_error_handler
)
2305 (_("Linking mips16 objects into %s format is not supported"),
2306 bfd_get_target (input_section
->output_section
->owner
));
2310 return bfd_reloc_undefined
;
2313 /* Handle a mips16 GP relative reloc. */
2315 static bfd_reloc_status_type
2316 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
2317 output_bfd
, error_message
)
2319 arelent
*reloc_entry
;
2322 asection
*input_section
;
2324 char **error_message
;
2326 boolean relocateable
;
2327 bfd_reloc_status_type ret
;
2329 unsigned short extend
, insn
;
2330 unsigned long final
;
2332 /* If we're relocating, and this is an external symbol with no
2333 addend, we don't want to change anything. We will only have an
2334 addend if this is a newly created reloc, not read from an ELF
2336 if (output_bfd
!= NULL
2337 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
2338 && reloc_entry
->addend
== 0)
2340 reloc_entry
->address
+= input_section
->output_offset
;
2341 return bfd_reloc_ok
;
2344 if (output_bfd
!= NULL
)
2345 relocateable
= true;
2348 relocateable
= false;
2349 output_bfd
= symbol
->section
->output_section
->owner
;
2352 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
2354 if (ret
!= bfd_reloc_ok
)
2357 if (reloc_entry
->address
> input_section
->_cooked_size
)
2358 return bfd_reloc_outofrange
;
2360 /* Pick up the mips16 extend instruction and the real instruction. */
2361 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
2362 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
2364 /* Stuff the current addend back as a 32 bit value, do the usual
2365 relocation, and then clean up. */
2367 (bfd_vma
) (((extend
& 0x1f) << 11)
2370 (bfd_byte
*) data
+ reloc_entry
->address
);
2372 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
2373 relocateable
, data
, gp
);
2375 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
2377 (bfd_vma
) ((extend
& 0xf800)
2378 | ((final
>> 11) & 0x1f)
2380 (bfd_byte
*) data
+ reloc_entry
->address
);
2382 (bfd_vma
) ((insn
& 0xffe0)
2384 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
2389 /* Return the ISA for a MIPS e_flags value. */
2392 elf_mips_isa (flags
)
2395 switch (flags
& EF_MIPS_ARCH
)
2407 case E_MIPS_ARCH_32
:
2409 case E_MIPS_ARCH_64
:
2415 /* Return the MACH for a MIPS e_flags value. */
2417 static INLINE
unsigned long
2418 elf_mips_mach (flags
)
2421 switch (flags
& EF_MIPS_MACH
)
2423 case E_MIPS_MACH_3900
:
2424 return bfd_mach_mips3900
;
2426 case E_MIPS_MACH_4010
:
2427 return bfd_mach_mips4010
;
2429 case E_MIPS_MACH_4100
:
2430 return bfd_mach_mips4100
;
2432 case E_MIPS_MACH_4111
:
2433 return bfd_mach_mips4111
;
2435 case E_MIPS_MACH_4650
:
2436 return bfd_mach_mips4650
;
2438 case E_MIPS_MACH_SB1
:
2439 return bfd_mach_mips_sb1
;
2442 switch (flags
& EF_MIPS_ARCH
)
2446 return bfd_mach_mips3000
;
2450 return bfd_mach_mips6000
;
2454 return bfd_mach_mips4000
;
2458 return bfd_mach_mips8000
;
2462 return bfd_mach_mips5
;
2465 case E_MIPS_ARCH_32
:
2466 return bfd_mach_mipsisa32
;
2469 case E_MIPS_ARCH_64
:
2470 return bfd_mach_mipsisa64
;
2478 /* Return printable name for ABI. */
2480 static INLINE
char *
2481 elf_mips_abi_name (abfd
)
2486 flags
= elf_elfheader (abfd
)->e_flags
;
2487 switch (flags
& EF_MIPS_ABI
)
2490 if (ABI_N32_P (abfd
))
2492 else if (ABI_64_P (abfd
))
2496 case E_MIPS_ABI_O32
:
2498 case E_MIPS_ABI_O64
:
2500 case E_MIPS_ABI_EABI32
:
2502 case E_MIPS_ABI_EABI64
:
2505 return "unknown abi";
2509 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
2511 struct elf_reloc_map
{
2512 bfd_reloc_code_real_type bfd_reloc_val
;
2513 enum elf_mips_reloc_type elf_reloc_val
;
2516 static const struct elf_reloc_map mips_reloc_map
[] =
2518 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
2519 { BFD_RELOC_16
, R_MIPS_16
},
2520 { BFD_RELOC_32
, R_MIPS_32
},
2521 { BFD_RELOC_64
, R_MIPS_64
},
2522 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
2523 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
2524 { BFD_RELOC_LO16
, R_MIPS_LO16
},
2525 { BFD_RELOC_GPREL16
, R_MIPS_GPREL16
},
2526 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
2527 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
2528 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
2529 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
2530 { BFD_RELOC_GPREL32
, R_MIPS_GPREL32
},
2531 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
2532 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
2533 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
2534 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
},
2535 { BFD_RELOC_MIPS_SUB
, R_MIPS_SUB
},
2536 { BFD_RELOC_MIPS_GOT_PAGE
, R_MIPS_GOT_PAGE
},
2537 { BFD_RELOC_MIPS_GOT_OFST
, R_MIPS_GOT_OFST
},
2538 { BFD_RELOC_MIPS_GOT_DISP
, R_MIPS_GOT_DISP
}
2541 /* Given a BFD reloc type, return a howto structure. */
2543 static reloc_howto_type
*
2544 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
2546 bfd_reloc_code_real_type code
;
2550 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
2552 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
2553 return &elf_mips_howto_table_rel
[(int) mips_reloc_map
[i
].elf_reloc_val
];
2559 bfd_set_error (bfd_error_bad_value
);
2562 case BFD_RELOC_CTOR
:
2563 /* We need to handle BFD_RELOC_CTOR specially.
2564 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
2565 size of addresses on this architecture. */
2566 if (bfd_arch_bits_per_address (abfd
) == 32)
2567 return &elf_mips_howto_table_rel
[(int) R_MIPS_32
];
2569 return &elf_mips_ctor64_howto
;
2571 case BFD_RELOC_MIPS16_JMP
:
2572 return &elf_mips16_jump_howto
;
2573 case BFD_RELOC_MIPS16_GPREL
:
2574 return &elf_mips16_gprel_howto
;
2575 case BFD_RELOC_VTABLE_INHERIT
:
2576 return &elf_mips_gnu_vtinherit_howto
;
2577 case BFD_RELOC_VTABLE_ENTRY
:
2578 return &elf_mips_gnu_vtentry_howto
;
2579 case BFD_RELOC_PCREL_HI16_S
:
2580 return &elf_mips_gnu_rel_hi16
;
2581 case BFD_RELOC_PCREL_LO16
:
2582 return &elf_mips_gnu_rel_lo16
;
2583 case BFD_RELOC_16_PCREL_S2
:
2584 return &elf_mips_gnu_rel16_s2
;
2585 case BFD_RELOC_64_PCREL
:
2586 return &elf_mips_gnu_pcrel64
;
2587 case BFD_RELOC_32_PCREL
:
2588 return &elf_mips_gnu_pcrel32
;
2592 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
2594 static reloc_howto_type
*
2595 mips_rtype_to_howto (r_type
)
2596 unsigned int r_type
;
2601 return &elf_mips16_jump_howto
;
2603 case R_MIPS16_GPREL
:
2604 return &elf_mips16_gprel_howto
;
2606 case R_MIPS_GNU_VTINHERIT
:
2607 return &elf_mips_gnu_vtinherit_howto
;
2609 case R_MIPS_GNU_VTENTRY
:
2610 return &elf_mips_gnu_vtentry_howto
;
2612 case R_MIPS_GNU_REL_HI16
:
2613 return &elf_mips_gnu_rel_hi16
;
2615 case R_MIPS_GNU_REL_LO16
:
2616 return &elf_mips_gnu_rel_lo16
;
2618 case R_MIPS_GNU_REL16_S2
:
2619 return &elf_mips_gnu_rel16_s2
;
2622 return &elf_mips_gnu_pcrel64
;
2625 return &elf_mips_gnu_pcrel32
;
2629 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
2630 return &elf_mips_howto_table_rel
[r_type
];
2635 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
2638 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
2641 Elf32_Internal_Rel
*dst
;
2643 unsigned int r_type
;
2645 r_type
= ELF32_R_TYPE (dst
->r_info
);
2646 cache_ptr
->howto
= mips_rtype_to_howto (r_type
);
2648 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
2649 value for the object file. We get the addend now, rather than
2650 when we do the relocation, because the symbol manipulations done
2651 by the linker may cause us to lose track of the input BFD. */
2652 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
2653 && (r_type
== (unsigned int) R_MIPS_GPREL16
2654 || r_type
== (unsigned int) R_MIPS_LITERAL
))
2655 cache_ptr
->addend
= elf_gp (abfd
);
2658 /* Given a MIPS Elf32_Internal_Rela, fill in an arelent structure. */
2661 mips_info_to_howto_rela (abfd
, cache_ptr
, dst
)
2664 Elf32_Internal_Rela
*dst
;
2666 /* Since an Elf32_Internal_Rel is an initial prefix of an
2667 Elf32_Internal_Rela, we can just use mips_info_to_howto_rel
2669 mips_info_to_howto_rel (abfd
, cache_ptr
, (Elf32_Internal_Rel
*) dst
);
2671 /* If we ever need to do any extra processing with dst->r_addend
2672 (the field omitted in an Elf32_Internal_Rel) we can do it here. */
2675 /* A .reginfo section holds a single Elf32_RegInfo structure. These
2676 routines swap this structure in and out. They are used outside of
2677 BFD, so they are globally visible. */
2680 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
2682 const Elf32_External_RegInfo
*ex
;
2685 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
2686 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
2687 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
2688 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
2689 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
2690 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
2694 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
2696 const Elf32_RegInfo
*in
;
2697 Elf32_External_RegInfo
*ex
;
2699 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
2700 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
2701 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
2702 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
2703 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
2704 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
2707 /* In the 64 bit ABI, the .MIPS.options section holds register
2708 information in an Elf64_Reginfo structure. These routines swap
2709 them in and out. They are globally visible because they are used
2710 outside of BFD. These routines are here so that gas can call them
2711 without worrying about whether the 64 bit ABI has been included. */
2714 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
2716 const Elf64_External_RegInfo
*ex
;
2717 Elf64_Internal_RegInfo
*in
;
2719 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
2720 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
2721 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
2722 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
2723 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
2724 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
2725 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
2729 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
2731 const Elf64_Internal_RegInfo
*in
;
2732 Elf64_External_RegInfo
*ex
;
2734 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
2735 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
2736 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
2737 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
2738 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
2739 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
2740 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
2743 /* Swap an entry in a .gptab section. Note that these routines rely
2744 on the equivalence of the two elements of the union. */
2747 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
2749 const Elf32_External_gptab
*ex
;
2752 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
2753 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
2757 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
2759 const Elf32_gptab
*in
;
2760 Elf32_External_gptab
*ex
;
2762 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
2763 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
2767 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
2769 const Elf32_compact_rel
*in
;
2770 Elf32_External_compact_rel
*ex
;
2772 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
2773 H_PUT_32 (abfd
, in
->num
, ex
->num
);
2774 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
2775 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
2776 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
2777 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
2781 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
2783 const Elf32_crinfo
*in
;
2784 Elf32_External_crinfo
*ex
;
2788 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
2789 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
2790 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
2791 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
2792 H_PUT_32 (abfd
, l
, ex
->info
);
2793 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
2794 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
2797 /* Swap in an options header. */
2800 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
2802 const Elf_External_Options
*ex
;
2803 Elf_Internal_Options
*in
;
2805 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
2806 in
->size
= H_GET_8 (abfd
, ex
->size
);
2807 in
->section
= H_GET_16 (abfd
, ex
->section
);
2808 in
->info
= H_GET_32 (abfd
, ex
->info
);
2811 /* Swap out an options header. */
2814 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
2816 const Elf_Internal_Options
*in
;
2817 Elf_External_Options
*ex
;
2819 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
2820 H_PUT_8 (abfd
, in
->size
, ex
->size
);
2821 H_PUT_16 (abfd
, in
->section
, ex
->section
);
2822 H_PUT_32 (abfd
, in
->info
, ex
->info
);
2825 /* Swap in an MSYM entry. */
2828 bfd_mips_elf_swap_msym_in (abfd
, ex
, in
)
2830 const Elf32_External_Msym
*ex
;
2831 Elf32_Internal_Msym
*in
;
2833 in
->ms_hash_value
= H_GET_32 (abfd
, ex
->ms_hash_value
);
2834 in
->ms_info
= H_GET_32 (abfd
, ex
->ms_info
);
2837 /* Swap out an MSYM entry. */
2840 bfd_mips_elf_swap_msym_out (abfd
, in
, ex
)
2842 const Elf32_Internal_Msym
*in
;
2843 Elf32_External_Msym
*ex
;
2845 H_PUT_32 (abfd
, in
->ms_hash_value
, ex
->ms_hash_value
);
2846 H_PUT_32 (abfd
, in
->ms_info
, ex
->ms_info
);
2849 /* Determine whether a symbol is global for the purposes of splitting
2850 the symbol table into global symbols and local symbols. At least
2851 on Irix 5, this split must be between section symbols and all other
2852 symbols. On most ELF targets the split is between static symbols
2853 and externally visible symbols. */
2856 mips_elf_sym_is_global (abfd
, sym
)
2857 bfd
*abfd ATTRIBUTE_UNUSED
;
2860 if (SGI_COMPAT (abfd
))
2861 return (sym
->flags
& BSF_SECTION_SYM
) == 0;
2863 return ((sym
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
2864 || bfd_is_und_section (bfd_get_section (sym
))
2865 || bfd_is_com_section (bfd_get_section (sym
)));
2868 /* Set the right machine number for a MIPS ELF file. This is used for
2869 both the 32-bit and the 64-bit ABI. */
2872 _bfd_mips_elf_object_p (abfd
)
2875 /* Irix 5 and 6 are broken. Object file symbol tables are not always
2876 sorted correctly such that local symbols precede global symbols,
2877 and the sh_info field in the symbol table is not always right. */
2878 if (SGI_COMPAT(abfd
))
2879 elf_bad_symtab (abfd
) = true;
2881 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
,
2882 elf_mips_mach (elf_elfheader (abfd
)->e_flags
));
2886 /* The final processing done just before writing out a MIPS ELF object
2887 file. This gets the MIPS architecture right based on the machine
2888 number. This is used by both the 32-bit and the 64-bit ABI. */
2891 _bfd_mips_elf_final_write_processing (abfd
, linker
)
2893 boolean linker ATTRIBUTE_UNUSED
;
2897 Elf_Internal_Shdr
**hdrpp
;
2901 switch (bfd_get_mach (abfd
))
2904 case bfd_mach_mips3000
:
2905 val
= E_MIPS_ARCH_1
;
2908 case bfd_mach_mips3900
:
2909 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
2912 case bfd_mach_mips6000
:
2913 val
= E_MIPS_ARCH_2
;
2916 case bfd_mach_mips4000
:
2917 case bfd_mach_mips4300
:
2918 case bfd_mach_mips4400
:
2919 case bfd_mach_mips4600
:
2920 val
= E_MIPS_ARCH_3
;
2923 case bfd_mach_mips4010
:
2924 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
2927 case bfd_mach_mips4100
:
2928 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
2931 case bfd_mach_mips4111
:
2932 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
2935 case bfd_mach_mips4650
:
2936 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
2939 case bfd_mach_mips5000
:
2940 case bfd_mach_mips8000
:
2941 case bfd_mach_mips10000
:
2942 case bfd_mach_mips12000
:
2943 val
= E_MIPS_ARCH_4
;
2946 case bfd_mach_mips5
:
2947 val
= E_MIPS_ARCH_5
;
2950 case bfd_mach_mips_sb1
:
2951 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
2954 case bfd_mach_mipsisa32
:
2955 val
= E_MIPS_ARCH_32
;
2958 case bfd_mach_mipsisa64
:
2959 val
= E_MIPS_ARCH_64
;
2962 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
2963 elf_elfheader (abfd
)->e_flags
|= val
;
2965 /* Set the sh_info field for .gptab sections and other appropriate
2966 info for each special section. */
2967 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
2968 i
< elf_numsections (abfd
);
2971 switch ((*hdrpp
)->sh_type
)
2974 case SHT_MIPS_LIBLIST
:
2975 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
2977 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2980 case SHT_MIPS_GPTAB
:
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
, ".gptab.", sizeof ".gptab." - 1) == 0);
2985 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
2986 BFD_ASSERT (sec
!= NULL
);
2987 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2990 case SHT_MIPS_CONTENT
:
2991 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2992 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2993 BFD_ASSERT (name
!= NULL
2994 && strncmp (name
, ".MIPS.content",
2995 sizeof ".MIPS.content" - 1) == 0);
2996 sec
= bfd_get_section_by_name (abfd
,
2997 name
+ sizeof ".MIPS.content" - 1);
2998 BFD_ASSERT (sec
!= NULL
);
2999 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
3002 case SHT_MIPS_SYMBOL_LIB
:
3003 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
3005 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
3006 sec
= bfd_get_section_by_name (abfd
, ".liblist");
3008 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
3011 case SHT_MIPS_EVENTS
:
3012 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
3013 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
3014 BFD_ASSERT (name
!= NULL
);
3015 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
3016 sec
= bfd_get_section_by_name (abfd
,
3017 name
+ sizeof ".MIPS.events" - 1);
3020 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
3021 sizeof ".MIPS.post_rel" - 1) == 0);
3022 sec
= bfd_get_section_by_name (abfd
,
3024 + sizeof ".MIPS.post_rel" - 1));
3026 BFD_ASSERT (sec
!= NULL
);
3027 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
3034 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
3037 _bfd_mips_elf_set_private_flags (abfd
, flags
)
3041 BFD_ASSERT (!elf_flags_init (abfd
)
3042 || elf_elfheader (abfd
)->e_flags
== flags
);
3044 elf_elfheader (abfd
)->e_flags
= flags
;
3045 elf_flags_init (abfd
) = true;
3049 /* Merge backend specific data from an object file to the output
3050 object file when linking. */
3053 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
3060 boolean null_input_bfd
= true;
3063 /* Check if we have the same endianess */
3064 if (_bfd_generic_verify_endian_match (ibfd
, obfd
) == false)
3067 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
3068 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
3071 new_flags
= elf_elfheader (ibfd
)->e_flags
;
3072 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
3073 old_flags
= elf_elfheader (obfd
)->e_flags
;
3075 if (! elf_flags_init (obfd
))
3077 elf_flags_init (obfd
) = true;
3078 elf_elfheader (obfd
)->e_flags
= new_flags
;
3079 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
3080 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
3082 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
3083 && bfd_get_arch_info (obfd
)->the_default
)
3085 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
3086 bfd_get_mach (ibfd
)))
3093 /* Check flag compatibility. */
3095 new_flags
&= ~EF_MIPS_NOREORDER
;
3096 old_flags
&= ~EF_MIPS_NOREORDER
;
3098 if (new_flags
== old_flags
)
3101 /* Check to see if the input BFD actually contains any sections.
3102 If not, its flags may not have been initialised either, but it cannot
3103 actually cause any incompatibility. */
3104 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
3106 /* Ignore synthetic sections and empty .text, .data and .bss sections
3107 which are automatically generated by gas. */
3108 if (strcmp (sec
->name
, ".reginfo")
3109 && strcmp (sec
->name
, ".mdebug")
3110 && ((!strcmp (sec
->name
, ".text")
3111 || !strcmp (sec
->name
, ".data")
3112 || !strcmp (sec
->name
, ".bss"))
3113 && sec
->_raw_size
!= 0))
3115 null_input_bfd
= false;
3124 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
3126 new_flags
&= ~EF_MIPS_PIC
;
3127 old_flags
&= ~EF_MIPS_PIC
;
3128 (*_bfd_error_handler
)
3129 (_("%s: linking PIC files with non-PIC files"),
3130 bfd_archive_filename (ibfd
));
3134 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
3136 new_flags
&= ~EF_MIPS_CPIC
;
3137 old_flags
&= ~EF_MIPS_CPIC
;
3138 (*_bfd_error_handler
)
3139 (_("%s: linking abicalls files with non-abicalls files"),
3140 bfd_archive_filename (ibfd
));
3144 /* Compare the ISA's. */
3145 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
3146 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
3148 int new_mach
= new_flags
& EF_MIPS_MACH
;
3149 int old_mach
= old_flags
& EF_MIPS_MACH
;
3150 int new_isa
= elf_mips_isa (new_flags
);
3151 int old_isa
= elf_mips_isa (old_flags
);
3153 /* If either has no machine specified, just compare the general isa's.
3154 Some combinations of machines are ok, if the isa's match. */
3157 || new_mach
== old_mach
3160 /* Don't warn about mixing code using 32-bit ISAs, or mixing code
3161 using 64-bit ISAs. They will normally use the same data sizes
3162 and calling conventions. */
3164 if (( (new_isa
== 1 || new_isa
== 2 || new_isa
== 32)
3165 ^ (old_isa
== 1 || old_isa
== 2 || old_isa
== 32)) != 0)
3167 (*_bfd_error_handler
)
3168 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
3169 bfd_archive_filename (ibfd
), new_isa
, old_isa
);
3174 /* Do we need to update the mach field? */
3175 if (old_mach
== 0 && new_mach
!= 0)
3176 elf_elfheader (obfd
)->e_flags
|= new_mach
;
3178 /* Do we need to update the ISA field? */
3179 if (new_isa
> old_isa
)
3181 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_ARCH
;
3182 elf_elfheader (obfd
)->e_flags
3183 |= new_flags
& EF_MIPS_ARCH
;
3189 (*_bfd_error_handler
)
3190 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
3191 bfd_archive_filename (ibfd
),
3192 elf_mips_mach (new_flags
),
3193 elf_mips_mach (old_flags
));
3197 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
3198 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
3201 /* Compare ABI's. The 64-bit ABI does not use EF_MIPS_ABI. But, it
3202 does set EI_CLASS differently from any 32-bit ABI. */
3203 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
3204 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
3205 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
3207 /* Only error if both are set (to different values). */
3208 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
3209 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
3210 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
3212 (*_bfd_error_handler
)
3213 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
3214 bfd_archive_filename (ibfd
),
3215 elf_mips_abi_name (ibfd
),
3216 elf_mips_abi_name (obfd
));
3219 new_flags
&= ~EF_MIPS_ABI
;
3220 old_flags
&= ~EF_MIPS_ABI
;
3223 /* Warn about any other mismatches */
3224 if (new_flags
!= old_flags
)
3226 (*_bfd_error_handler
)
3227 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
3228 bfd_archive_filename (ibfd
), (unsigned long) new_flags
,
3229 (unsigned long) old_flags
);
3235 bfd_set_error (bfd_error_bad_value
);
3243 _bfd_mips_elf_print_private_bfd_data (abfd
, ptr
)
3247 FILE *file
= (FILE *) ptr
;
3249 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
3251 /* Print normal ELF private data. */
3252 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
3254 /* xgettext:c-format */
3255 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
3257 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
3258 fprintf (file
, _(" [abi=O32]"));
3259 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
3260 fprintf (file
, _(" [abi=O64]"));
3261 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
3262 fprintf (file
, _(" [abi=EABI32]"));
3263 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
3264 fprintf (file
, _(" [abi=EABI64]"));
3265 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
3266 fprintf (file
, _(" [abi unknown]"));
3267 else if (ABI_N32_P (abfd
))
3268 fprintf (file
, _(" [abi=N32]"));
3269 else if (ABI_64_P (abfd
))
3270 fprintf (file
, _(" [abi=64]"));
3272 fprintf (file
, _(" [no abi set]"));
3274 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
3275 fprintf (file
, _(" [mips1]"));
3276 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
3277 fprintf (file
, _(" [mips2]"));
3278 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
3279 fprintf (file
, _(" [mips3]"));
3280 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
3281 fprintf (file
, _(" [mips4]"));
3282 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
3283 fprintf (file
, _(" [mips5]"));
3284 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
3285 fprintf (file
, _(" [mips32]"));
3286 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
3287 fprintf (file
, _(" [mips64]"));
3289 fprintf (file
, _(" [unknown ISA]"));
3291 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
3292 fprintf (file
, _(" [32bitmode]"));
3294 fprintf (file
, _(" [not 32bitmode]"));
3301 /* Handle a MIPS specific section when reading an object file. This
3302 is called when elfcode.h finds a section with an unknown type.
3303 This routine supports both the 32-bit and 64-bit ELF ABI.
3305 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
3309 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
3311 Elf_Internal_Shdr
*hdr
;
3316 /* There ought to be a place to keep ELF backend specific flags, but
3317 at the moment there isn't one. We just keep track of the
3318 sections by their name, instead. Fortunately, the ABI gives
3319 suggested names for all the MIPS specific sections, so we will
3320 probably get away with this. */
3321 switch (hdr
->sh_type
)
3323 case SHT_MIPS_LIBLIST
:
3324 if (strcmp (name
, ".liblist") != 0)
3328 if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) != 0)
3331 case SHT_MIPS_CONFLICT
:
3332 if (strcmp (name
, ".conflict") != 0)
3335 case SHT_MIPS_GPTAB
:
3336 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
3339 case SHT_MIPS_UCODE
:
3340 if (strcmp (name
, ".ucode") != 0)
3343 case SHT_MIPS_DEBUG
:
3344 if (strcmp (name
, ".mdebug") != 0)
3346 flags
= SEC_DEBUGGING
;
3348 case SHT_MIPS_REGINFO
:
3349 if (strcmp (name
, ".reginfo") != 0
3350 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
3352 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
3354 case SHT_MIPS_IFACE
:
3355 if (strcmp (name
, ".MIPS.interfaces") != 0)
3358 case SHT_MIPS_CONTENT
:
3359 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
3362 case SHT_MIPS_OPTIONS
:
3363 if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) != 0)
3366 case SHT_MIPS_DWARF
:
3367 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
3370 case SHT_MIPS_SYMBOL_LIB
:
3371 if (strcmp (name
, ".MIPS.symlib") != 0)
3374 case SHT_MIPS_EVENTS
:
3375 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
3376 && strncmp (name
, ".MIPS.post_rel",
3377 sizeof ".MIPS.post_rel" - 1) != 0)
3384 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
3389 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
3390 (bfd_get_section_flags (abfd
,
3396 /* FIXME: We should record sh_info for a .gptab section. */
3398 /* For a .reginfo section, set the gp value in the tdata information
3399 from the contents of this section. We need the gp value while
3400 processing relocs, so we just get it now. The .reginfo section
3401 is not used in the 64-bit MIPS ELF ABI. */
3402 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
3404 Elf32_External_RegInfo ext
;
3407 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
3409 (bfd_size_type
) sizeof ext
))
3411 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
3412 elf_gp (abfd
) = s
.ri_gp_value
;
3415 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
3416 set the gp value based on what we find. We may see both
3417 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
3418 they should agree. */
3419 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
3421 bfd_byte
*contents
, *l
, *lend
;
3423 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
3424 if (contents
== NULL
)
3426 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
3427 (file_ptr
) 0, hdr
->sh_size
))
3433 lend
= contents
+ hdr
->sh_size
;
3434 while (l
+ sizeof (Elf_External_Options
) <= lend
)
3436 Elf_Internal_Options intopt
;
3438 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
3440 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
3442 Elf64_Internal_RegInfo intreg
;
3444 bfd_mips_elf64_swap_reginfo_in
3446 ((Elf64_External_RegInfo
*)
3447 (l
+ sizeof (Elf_External_Options
))),
3449 elf_gp (abfd
) = intreg
.ri_gp_value
;
3451 else if (intopt
.kind
== ODK_REGINFO
)
3453 Elf32_RegInfo intreg
;
3455 bfd_mips_elf32_swap_reginfo_in
3457 ((Elf32_External_RegInfo
*)
3458 (l
+ sizeof (Elf_External_Options
))),
3460 elf_gp (abfd
) = intreg
.ri_gp_value
;
3470 /* Set the correct type for a MIPS ELF section. We do this by the
3471 section name, which is a hack, but ought to work. This routine is
3472 used by both the 32-bit and the 64-bit ABI. */
3475 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
3477 Elf32_Internal_Shdr
*hdr
;
3480 register const char *name
;
3482 name
= bfd_get_section_name (abfd
, sec
);
3484 if (strcmp (name
, ".liblist") == 0)
3486 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
3487 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
3488 /* The sh_link field is set in final_write_processing. */
3490 else if (strcmp (name
, ".conflict") == 0)
3491 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
3492 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
3494 hdr
->sh_type
= SHT_MIPS_GPTAB
;
3495 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
3496 /* The sh_info field is set in final_write_processing. */
3498 else if (strcmp (name
, ".ucode") == 0)
3499 hdr
->sh_type
= SHT_MIPS_UCODE
;
3500 else if (strcmp (name
, ".mdebug") == 0)
3502 hdr
->sh_type
= SHT_MIPS_DEBUG
;
3503 /* In a shared object on Irix 5.3, the .mdebug section has an
3504 entsize of 0. FIXME: Does this matter? */
3505 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
3506 hdr
->sh_entsize
= 0;
3508 hdr
->sh_entsize
= 1;
3510 else if (strcmp (name
, ".reginfo") == 0)
3512 hdr
->sh_type
= SHT_MIPS_REGINFO
;
3513 /* In a shared object on Irix 5.3, the .reginfo section has an
3514 entsize of 0x18. FIXME: Does this matter? */
3515 if (SGI_COMPAT (abfd
))
3517 if ((abfd
->flags
& DYNAMIC
) != 0)
3518 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
3520 hdr
->sh_entsize
= 1;
3523 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
3525 else if (SGI_COMPAT (abfd
)
3526 && (strcmp (name
, ".hash") == 0
3527 || strcmp (name
, ".dynamic") == 0
3528 || strcmp (name
, ".dynstr") == 0))
3530 if (SGI_COMPAT (abfd
))
3531 hdr
->sh_entsize
= 0;
3533 /* This isn't how the Irix 6 linker behaves. */
3534 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
3537 else if (strcmp (name
, ".got") == 0
3538 || strcmp (name
, MIPS_ELF_SRDATA_SECTION_NAME (abfd
)) == 0
3539 || strcmp (name
, ".sdata") == 0
3540 || strcmp (name
, ".sbss") == 0
3541 || strcmp (name
, ".lit4") == 0
3542 || strcmp (name
, ".lit8") == 0)
3543 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
3544 else if (strcmp (name
, ".MIPS.interfaces") == 0)
3546 hdr
->sh_type
= SHT_MIPS_IFACE
;
3547 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3549 else if (strncmp (name
, ".MIPS.content", strlen (".MIPS.content")) == 0)
3551 hdr
->sh_type
= SHT_MIPS_CONTENT
;
3552 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3553 /* The sh_info field is set in final_write_processing. */
3555 else if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
3557 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
3558 hdr
->sh_entsize
= 1;
3559 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3561 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
3562 hdr
->sh_type
= SHT_MIPS_DWARF
;
3563 else if (strcmp (name
, ".MIPS.symlib") == 0)
3565 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
3566 /* The sh_link and sh_info fields are set in
3567 final_write_processing. */
3569 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
3570 || strncmp (name
, ".MIPS.post_rel",
3571 sizeof ".MIPS.post_rel" - 1) == 0)
3573 hdr
->sh_type
= SHT_MIPS_EVENTS
;
3574 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3575 /* The sh_link field is set in final_write_processing. */
3577 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) == 0)
3579 hdr
->sh_type
= SHT_MIPS_MSYM
;
3580 hdr
->sh_flags
|= SHF_ALLOC
;
3581 hdr
->sh_entsize
= 8;
3584 /* The generic elf_fake_sections will set up REL_HDR using the
3585 default kind of relocations. But, we may actually need both
3586 kinds of relocations, so we set up the second header here.
3588 This is not necessary for the O32 ABI since that only uses Elf32_Rel
3589 relocations (cf. System V ABI, MIPS RISC Processor Supplement,
3590 3rd Edition, p. 4-17). It breaks the IRIX 5/6 32-bit ld, since one
3591 of the resulting empty .rela.<section> sections starts with
3592 sh_offset == object size, and ld doesn't allow that. While the check
3593 is arguably bogus for empty or SHT_NOBITS sections, it can easily be
3594 avoided by not emitting those useless sections in the first place. */
3595 if (IRIX_COMPAT (abfd
) != ict_irix5
&& (sec
->flags
& SEC_RELOC
) != 0)
3597 struct bfd_elf_section_data
*esd
;
3598 bfd_size_type amt
= sizeof (Elf_Internal_Shdr
);
3600 esd
= elf_section_data (sec
);
3601 BFD_ASSERT (esd
->rel_hdr2
== NULL
);
3602 esd
->rel_hdr2
= (Elf_Internal_Shdr
*) bfd_zalloc (abfd
, amt
);
3605 _bfd_elf_init_reloc_shdr (abfd
, esd
->rel_hdr2
, sec
,
3606 !elf_section_data (sec
)->use_rela_p
);
3612 /* Given a BFD section, try to locate the corresponding ELF section
3613 index. This is used by both the 32-bit and the 64-bit ABI.
3614 Actually, it's not clear to me that the 64-bit ABI supports these,
3615 but for non-PIC objects we will certainly want support for at least
3616 the .scommon section. */
3619 _bfd_mips_elf_section_from_bfd_section (abfd
, sec
, retval
)
3620 bfd
*abfd ATTRIBUTE_UNUSED
;
3624 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
3626 *retval
= SHN_MIPS_SCOMMON
;
3629 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
3631 *retval
= SHN_MIPS_ACOMMON
;
3637 /* When are writing out the .options or .MIPS.options section,
3638 remember the bytes we are writing out, so that we can install the
3639 GP value in the section_processing routine. */
3642 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
3647 bfd_size_type count
;
3649 if (strcmp (section
->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
3653 if (elf_section_data (section
) == NULL
)
3655 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
3656 section
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
3657 if (elf_section_data (section
) == NULL
)
3660 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
3665 if (section
->_cooked_size
!= 0)
3666 size
= section
->_cooked_size
;
3668 size
= section
->_raw_size
;
3669 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
3672 elf_section_data (section
)->tdata
= (PTR
) c
;
3675 memcpy (c
+ offset
, location
, (size_t) count
);
3678 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
3682 /* Work over a section just before writing it out. This routine is
3683 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
3684 sections that need the SHF_MIPS_GPREL flag by name; there has to be
3688 _bfd_mips_elf_section_processing (abfd
, hdr
)
3690 Elf_Internal_Shdr
*hdr
;
3692 if (hdr
->sh_type
== SHT_MIPS_REGINFO
3693 && hdr
->sh_size
> 0)
3697 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
3698 BFD_ASSERT (hdr
->contents
== NULL
);
3701 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
3704 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
3705 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
3709 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
3710 && hdr
->bfd_section
!= NULL
3711 && elf_section_data (hdr
->bfd_section
) != NULL
3712 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
3714 bfd_byte
*contents
, *l
, *lend
;
3716 /* We stored the section contents in the elf_section_data tdata
3717 field in the set_section_contents routine. We save the
3718 section contents so that we don't have to read them again.
3719 At this point we know that elf_gp is set, so we can look
3720 through the section contents to see if there is an
3721 ODK_REGINFO structure. */
3723 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
3725 lend
= contents
+ hdr
->sh_size
;
3726 while (l
+ sizeof (Elf_External_Options
) <= lend
)
3728 Elf_Internal_Options intopt
;
3730 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
3732 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
3739 + sizeof (Elf_External_Options
)
3740 + (sizeof (Elf64_External_RegInfo
) - 8)),
3743 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
3744 if (bfd_bwrite (buf
, (bfd_size_type
) 8, abfd
) != 8)
3747 else if (intopt
.kind
== ODK_REGINFO
)
3754 + sizeof (Elf_External_Options
)
3755 + (sizeof (Elf32_External_RegInfo
) - 4)),
3758 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
3759 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
3766 if (hdr
->bfd_section
!= NULL
)
3768 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
3770 if (strcmp (name
, ".sdata") == 0
3771 || strcmp (name
, ".lit8") == 0
3772 || strcmp (name
, ".lit4") == 0)
3774 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3775 hdr
->sh_type
= SHT_PROGBITS
;
3777 else if (strcmp (name
, ".sbss") == 0)
3779 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3780 hdr
->sh_type
= SHT_NOBITS
;
3782 else if (strcmp (name
, MIPS_ELF_SRDATA_SECTION_NAME (abfd
)) == 0)
3784 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
3785 hdr
->sh_type
= SHT_PROGBITS
;
3787 else if (strcmp (name
, ".compact_rel") == 0)
3790 hdr
->sh_type
= SHT_PROGBITS
;
3792 else if (strcmp (name
, ".rtproc") == 0)
3794 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
3796 unsigned int adjust
;
3798 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
3800 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
3808 /* MIPS ELF uses two common sections. One is the usual one, and the
3809 other is for small objects. All the small objects are kept
3810 together, and then referenced via the gp pointer, which yields
3811 faster assembler code. This is what we use for the small common
3812 section. This approach is copied from ecoff.c. */
3813 static asection mips_elf_scom_section
;
3814 static asymbol mips_elf_scom_symbol
;
3815 static asymbol
*mips_elf_scom_symbol_ptr
;
3817 /* MIPS ELF also uses an acommon section, which represents an
3818 allocated common symbol which may be overridden by a
3819 definition in a shared library. */
3820 static asection mips_elf_acom_section
;
3821 static asymbol mips_elf_acom_symbol
;
3822 static asymbol
*mips_elf_acom_symbol_ptr
;
3824 /* Handle the special MIPS section numbers that a symbol may use.
3825 This is used for both the 32-bit and the 64-bit ABI. */
3828 _bfd_mips_elf_symbol_processing (abfd
, asym
)
3832 elf_symbol_type
*elfsym
;
3834 elfsym
= (elf_symbol_type
*) asym
;
3835 switch (elfsym
->internal_elf_sym
.st_shndx
)
3837 case SHN_MIPS_ACOMMON
:
3838 /* This section is used in a dynamically linked executable file.
3839 It is an allocated common section. The dynamic linker can
3840 either resolve these symbols to something in a shared
3841 library, or it can just leave them here. For our purposes,
3842 we can consider these symbols to be in a new section. */
3843 if (mips_elf_acom_section
.name
== NULL
)
3845 /* Initialize the acommon section. */
3846 mips_elf_acom_section
.name
= ".acommon";
3847 mips_elf_acom_section
.flags
= SEC_ALLOC
;
3848 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
3849 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
3850 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
3851 mips_elf_acom_symbol
.name
= ".acommon";
3852 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
3853 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
3854 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
3856 asym
->section
= &mips_elf_acom_section
;
3860 /* Common symbols less than the GP size are automatically
3861 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
3862 if (asym
->value
> elf_gp_size (abfd
)
3863 || IRIX_COMPAT (abfd
) == ict_irix6
)
3866 case SHN_MIPS_SCOMMON
:
3867 if (mips_elf_scom_section
.name
== NULL
)
3869 /* Initialize the small common section. */
3870 mips_elf_scom_section
.name
= ".scommon";
3871 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
3872 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
3873 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
3874 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
3875 mips_elf_scom_symbol
.name
= ".scommon";
3876 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
3877 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
3878 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
3880 asym
->section
= &mips_elf_scom_section
;
3881 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
3884 case SHN_MIPS_SUNDEFINED
:
3885 asym
->section
= bfd_und_section_ptr
;
3888 #if 0 /* for SGI_COMPAT */
3890 asym
->section
= mips_elf_text_section_ptr
;
3894 asym
->section
= mips_elf_data_section_ptr
;
3900 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
3904 _bfd_mips_elf_additional_program_headers (abfd
)
3910 /* See if we need a PT_MIPS_REGINFO segment. */
3911 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3912 if (s
&& (s
->flags
& SEC_LOAD
))
3915 /* See if we need a PT_MIPS_OPTIONS segment. */
3916 if (IRIX_COMPAT (abfd
) == ict_irix6
3917 && bfd_get_section_by_name (abfd
,
3918 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
3921 /* See if we need a PT_MIPS_RTPROC segment. */
3922 if (IRIX_COMPAT (abfd
) == ict_irix5
3923 && bfd_get_section_by_name (abfd
, ".dynamic")
3924 && bfd_get_section_by_name (abfd
, ".mdebug"))
3930 /* Modify the segment map for an Irix 5 executable. */
3933 _bfd_mips_elf_modify_segment_map (abfd
)
3937 struct elf_segment_map
*m
, **pm
;
3940 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
3942 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3943 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3945 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3946 if (m
->p_type
== PT_MIPS_REGINFO
)
3951 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
3955 m
->p_type
= PT_MIPS_REGINFO
;
3959 /* We want to put it after the PHDR and INTERP segments. */
3960 pm
= &elf_tdata (abfd
)->segment_map
;
3962 && ((*pm
)->p_type
== PT_PHDR
3963 || (*pm
)->p_type
== PT_INTERP
))
3971 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
3972 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
3973 PT_OPTIONS segement immediately following the program header
3975 if (IRIX_COMPAT (abfd
) == ict_irix6
)
3977 for (s
= abfd
->sections
; s
; s
= s
->next
)
3978 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
3983 struct elf_segment_map
*options_segment
;
3985 /* Usually, there's a program header table. But, sometimes
3986 there's not (like when running the `ld' testsuite). So,
3987 if there's no program header table, we just put the
3988 options segement at the end. */
3989 for (pm
= &elf_tdata (abfd
)->segment_map
;
3992 if ((*pm
)->p_type
== PT_PHDR
)
3995 amt
= sizeof (struct elf_segment_map
);
3996 options_segment
= bfd_zalloc (abfd
, amt
);
3997 options_segment
->next
= *pm
;
3998 options_segment
->p_type
= PT_MIPS_OPTIONS
;
3999 options_segment
->p_flags
= PF_R
;
4000 options_segment
->p_flags_valid
= true;
4001 options_segment
->count
= 1;
4002 options_segment
->sections
[0] = s
;
4003 *pm
= options_segment
;
4008 if (IRIX_COMPAT (abfd
) == ict_irix5
)
4010 /* If there are .dynamic and .mdebug sections, we make a room
4011 for the RTPROC header. FIXME: Rewrite without section names. */
4012 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
4013 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
4014 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
4016 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
4017 if (m
->p_type
== PT_MIPS_RTPROC
)
4022 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
4026 m
->p_type
= PT_MIPS_RTPROC
;
4028 s
= bfd_get_section_by_name (abfd
, ".rtproc");
4033 m
->p_flags_valid
= 1;
4041 /* We want to put it after the DYNAMIC segment. */
4042 pm
= &elf_tdata (abfd
)->segment_map
;
4043 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
4053 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic,
4054 .dynstr, .dynsym, and .hash sections, and everything in
4056 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
;
4058 if ((*pm
)->p_type
== PT_DYNAMIC
)
4061 if (m
!= NULL
&& IRIX_COMPAT (abfd
) == ict_none
)
4063 /* For a normal mips executable the permissions for the PT_DYNAMIC
4064 segment are read, write and execute. We do that here since
4065 the code in elf.c sets only the read permission. This matters
4066 sometimes for the dynamic linker. */
4067 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
4069 m
->p_flags
= PF_R
| PF_W
| PF_X
;
4070 m
->p_flags_valid
= 1;
4074 && m
->count
== 1 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
4076 static const char *sec_names
[] =
4078 ".dynamic", ".dynstr", ".dynsym", ".hash"
4082 struct elf_segment_map
*n
;
4086 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
4088 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
4089 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
4095 sz
= s
->_cooked_size
;
4098 if (high
< s
->vma
+ sz
)
4104 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
4105 if ((s
->flags
& SEC_LOAD
) != 0
4108 + (s
->_cooked_size
!=
4109 0 ? s
->_cooked_size
: s
->_raw_size
)) <= high
))
4112 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
4113 n
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
4120 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
4122 if ((s
->flags
& SEC_LOAD
) != 0
4125 + (s
->_cooked_size
!= 0 ?
4126 s
->_cooked_size
: s
->_raw_size
)) <= high
))
4140 /* The structure of the runtime procedure descriptor created by the
4141 loader for use by the static exception system. */
4143 typedef struct runtime_pdr
{
4144 bfd_vma adr
; /* memory address of start of procedure */
4145 long regmask
; /* save register mask */
4146 long regoffset
; /* save register offset */
4147 long fregmask
; /* save floating point register mask */
4148 long fregoffset
; /* save floating point register offset */
4149 long frameoffset
; /* frame size */
4150 short framereg
; /* frame pointer register */
4151 short pcreg
; /* offset or reg of return pc */
4152 long irpss
; /* index into the runtime string table */
4154 struct exception_info
*exception_info
;/* pointer to exception array */
4156 #define cbRPDR sizeof (RPDR)
4157 #define rpdNil ((pRPDR) 0)
4159 /* Swap RPDR (runtime procedure table entry) for output. */
4161 static void ecoff_swap_rpdr_out
4162 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
4165 ecoff_swap_rpdr_out (abfd
, in
, ex
)
4168 struct rpdr_ext
*ex
;
4170 /* ECOFF_PUT_OFF was defined in ecoffswap.h. */
4171 ECOFF_PUT_OFF (abfd
, in
->adr
, ex
->p_adr
);
4172 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
4173 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
4174 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
4175 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
4176 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
4178 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
4179 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
4181 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
4183 ECOFF_PUT_OFF (abfd
, in
->exception_info
, ex
->p_exception_info
);
4187 /* Read ECOFF debugging information from a .mdebug section into a
4188 ecoff_debug_info structure. */
4191 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
4194 struct ecoff_debug_info
*debug
;
4197 const struct ecoff_debug_swap
*swap
;
4198 char *ext_hdr
= NULL
;
4200 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4201 memset (debug
, 0, sizeof (*debug
));
4203 ext_hdr
= (char *) bfd_malloc (swap
->external_hdr_size
);
4204 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
4207 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
4208 swap
->external_hdr_size
)
4212 symhdr
= &debug
->symbolic_header
;
4213 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
4215 /* The symbolic header contains absolute file offsets and sizes to
4217 #define READ(ptr, offset, count, size, type) \
4218 if (symhdr->count == 0) \
4219 debug->ptr = NULL; \
4222 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
4223 debug->ptr = (type) bfd_malloc (amt); \
4224 if (debug->ptr == NULL) \
4225 goto error_return; \
4226 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
4227 || bfd_bread (debug->ptr, amt, abfd) != amt) \
4228 goto error_return; \
4231 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
4232 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4233 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4234 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4235 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4236 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4238 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4239 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
4240 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4241 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4242 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
4246 debug
->adjust
= NULL
;
4251 if (ext_hdr
!= NULL
)
4253 if (debug
->line
!= NULL
)
4255 if (debug
->external_dnr
!= NULL
)
4256 free (debug
->external_dnr
);
4257 if (debug
->external_pdr
!= NULL
)
4258 free (debug
->external_pdr
);
4259 if (debug
->external_sym
!= NULL
)
4260 free (debug
->external_sym
);
4261 if (debug
->external_opt
!= NULL
)
4262 free (debug
->external_opt
);
4263 if (debug
->external_aux
!= NULL
)
4264 free (debug
->external_aux
);
4265 if (debug
->ss
!= NULL
)
4267 if (debug
->ssext
!= NULL
)
4268 free (debug
->ssext
);
4269 if (debug
->external_fdr
!= NULL
)
4270 free (debug
->external_fdr
);
4271 if (debug
->external_rfd
!= NULL
)
4272 free (debug
->external_rfd
);
4273 if (debug
->external_ext
!= NULL
)
4274 free (debug
->external_ext
);
4278 /* MIPS ELF local labels start with '$', not 'L'. */
4281 mips_elf_is_local_label_name (abfd
, name
)
4288 /* On Irix 6, the labels go back to starting with '.', so we accept
4289 the generic ELF local label syntax as well. */
4290 return _bfd_elf_is_local_label_name (abfd
, name
);
4293 /* MIPS ELF uses a special find_nearest_line routine in order the
4294 handle the ECOFF debugging information. */
4296 struct mips_elf_find_line
4298 struct ecoff_debug_info d
;
4299 struct ecoff_find_line i
;
4303 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
4304 functionname_ptr
, line_ptr
)
4309 const char **filename_ptr
;
4310 const char **functionname_ptr
;
4311 unsigned int *line_ptr
;
4315 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
4316 filename_ptr
, functionname_ptr
,
4320 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
4321 filename_ptr
, functionname_ptr
,
4323 (unsigned) (ABI_64_P (abfd
) ? 8 : 0),
4324 &elf_tdata (abfd
)->dwarf2_find_line_info
))
4327 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
4331 struct mips_elf_find_line
*fi
;
4332 const struct ecoff_debug_swap
* const swap
=
4333 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4335 /* If we are called during a link, mips_elf_final_link may have
4336 cleared the SEC_HAS_CONTENTS field. We force it back on here
4337 if appropriate (which it normally will be). */
4338 origflags
= msec
->flags
;
4339 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
4340 msec
->flags
|= SEC_HAS_CONTENTS
;
4342 fi
= elf_tdata (abfd
)->find_line_info
;
4345 bfd_size_type external_fdr_size
;
4348 struct fdr
*fdr_ptr
;
4349 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
4351 fi
= (struct mips_elf_find_line
*) bfd_zalloc (abfd
, amt
);
4354 msec
->flags
= origflags
;
4358 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
4360 msec
->flags
= origflags
;
4364 /* Swap in the FDR information. */
4365 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
4366 fi
->d
.fdr
= (struct fdr
*) bfd_alloc (abfd
, amt
);
4367 if (fi
->d
.fdr
== NULL
)
4369 msec
->flags
= origflags
;
4372 external_fdr_size
= swap
->external_fdr_size
;
4373 fdr_ptr
= fi
->d
.fdr
;
4374 fraw_src
= (char *) fi
->d
.external_fdr
;
4375 fraw_end
= (fraw_src
4376 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
4377 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
4378 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
4380 elf_tdata (abfd
)->find_line_info
= fi
;
4382 /* Note that we don't bother to ever free this information.
4383 find_nearest_line is either called all the time, as in
4384 objdump -l, so the information should be saved, or it is
4385 rarely called, as in ld error messages, so the memory
4386 wasted is unimportant. Still, it would probably be a
4387 good idea for free_cached_info to throw it away. */
4390 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
4391 &fi
->i
, filename_ptr
, functionname_ptr
,
4394 msec
->flags
= origflags
;
4398 msec
->flags
= origflags
;
4401 /* Fall back on the generic ELF find_nearest_line routine. */
4403 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
4404 filename_ptr
, functionname_ptr
,
4408 /* The mips16 compiler uses a couple of special sections to handle
4409 floating point arguments.
4411 Section names that look like .mips16.fn.FNNAME contain stubs that
4412 copy floating point arguments from the fp regs to the gp regs and
4413 then jump to FNNAME. If any 32 bit function calls FNNAME, the
4414 call should be redirected to the stub instead. If no 32 bit
4415 function calls FNNAME, the stub should be discarded. We need to
4416 consider any reference to the function, not just a call, because
4417 if the address of the function is taken we will need the stub,
4418 since the address might be passed to a 32 bit function.
4420 Section names that look like .mips16.call.FNNAME contain stubs
4421 that copy floating point arguments from the gp regs to the fp
4422 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
4423 then any 16 bit function that calls FNNAME should be redirected
4424 to the stub instead. If FNNAME is not a 32 bit function, the
4425 stub should be discarded.
4427 .mips16.call.fp.FNNAME sections are similar, but contain stubs
4428 which call FNNAME and then copy the return value from the fp regs
4429 to the gp regs. These stubs store the return value in $18 while
4430 calling FNNAME; any function which might call one of these stubs
4431 must arrange to save $18 around the call. (This case is not
4432 needed for 32 bit functions that call 16 bit functions, because
4433 16 bit functions always return floating point values in both
4436 Note that in all cases FNNAME might be defined statically.
4437 Therefore, FNNAME is not used literally. Instead, the relocation
4438 information will indicate which symbol the section is for.
4440 We record any stubs that we find in the symbol table. */
4442 #define FN_STUB ".mips16.fn."
4443 #define CALL_STUB ".mips16.call."
4444 #define CALL_FP_STUB ".mips16.call.fp."
4446 /* MIPS ELF linker hash table. */
4448 struct mips_elf_link_hash_table
4450 struct elf_link_hash_table root
;
4452 /* We no longer use this. */
4453 /* String section indices for the dynamic section symbols. */
4454 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
4456 /* The number of .rtproc entries. */
4457 bfd_size_type procedure_count
;
4458 /* The size of the .compact_rel section (if SGI_COMPAT). */
4459 bfd_size_type compact_rel_size
;
4460 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
4461 entry is set to the address of __rld_obj_head as in Irix 5. */
4462 boolean use_rld_obj_head
;
4463 /* This is the value of the __rld_map or __rld_obj_head symbol. */
4465 /* This is set if we see any mips16 stub sections. */
4466 boolean mips16_stubs_seen
;
4469 /* Look up an entry in a MIPS ELF linker hash table. */
4471 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
4472 ((struct mips_elf_link_hash_entry *) \
4473 elf_link_hash_lookup (&(table)->root, (string), (create), \
4476 /* Traverse a MIPS ELF linker hash table. */
4478 #define mips_elf_link_hash_traverse(table, func, info) \
4479 (elf_link_hash_traverse \
4481 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
4484 /* Get the MIPS ELF linker hash table from a link_info structure. */
4486 #define mips_elf_hash_table(p) \
4487 ((struct mips_elf_link_hash_table *) ((p)->hash))
4489 static boolean mips_elf_output_extsym
4490 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
4492 /* Create an entry in a MIPS ELF linker hash table. */
4494 static struct bfd_hash_entry
*
4495 mips_elf_link_hash_newfunc (entry
, table
, string
)
4496 struct bfd_hash_entry
*entry
;
4497 struct bfd_hash_table
*table
;
4500 struct mips_elf_link_hash_entry
*ret
=
4501 (struct mips_elf_link_hash_entry
*) entry
;
4503 /* Allocate the structure if it has not already been allocated by a
4505 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
4506 ret
= ((struct mips_elf_link_hash_entry
*)
4507 bfd_hash_allocate (table
,
4508 sizeof (struct mips_elf_link_hash_entry
)));
4509 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
4510 return (struct bfd_hash_entry
*) ret
;
4512 /* Call the allocation method of the superclass. */
4513 ret
= ((struct mips_elf_link_hash_entry
*)
4514 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
4516 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
4518 /* Set local fields. */
4519 memset (&ret
->esym
, 0, sizeof (EXTR
));
4520 /* We use -2 as a marker to indicate that the information has
4521 not been set. -1 means there is no associated ifd. */
4523 ret
->possibly_dynamic_relocs
= 0;
4524 ret
->readonly_reloc
= false;
4525 ret
->min_dyn_reloc_index
= 0;
4526 ret
->no_fn_stub
= false;
4527 ret
->fn_stub
= NULL
;
4528 ret
->need_fn_stub
= false;
4529 ret
->call_stub
= NULL
;
4530 ret
->call_fp_stub
= NULL
;
4533 return (struct bfd_hash_entry
*) ret
;
4537 _bfd_mips_elf_hide_symbol (info
, entry
, force_local
)
4538 struct bfd_link_info
*info
;
4539 struct elf_link_hash_entry
*entry
;
4540 boolean force_local
;
4544 struct mips_got_info
*g
;
4545 struct mips_elf_link_hash_entry
*h
;
4546 h
= (struct mips_elf_link_hash_entry
*) entry
;
4547 dynobj
= elf_hash_table (info
)->dynobj
;
4548 got
= bfd_get_section_by_name (dynobj
, ".got");
4549 g
= (struct mips_got_info
*) elf_section_data (got
)->tdata
;
4551 _bfd_elf_link_hash_hide_symbol (info
, &h
->root
, force_local
);
4553 /* FIXME: Do we allocate too much GOT space here? */
4555 got
->_raw_size
+= MIPS_ELF_GOT_SIZE (dynobj
);
4558 /* Create a MIPS ELF linker hash table. */
4560 struct bfd_link_hash_table
*
4561 _bfd_mips_elf_link_hash_table_create (abfd
)
4564 struct mips_elf_link_hash_table
*ret
;
4565 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
4567 ret
= (struct mips_elf_link_hash_table
*) bfd_alloc (abfd
, amt
);
4568 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
4571 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
4572 mips_elf_link_hash_newfunc
))
4574 bfd_release (abfd
, ret
);
4579 /* We no longer use this. */
4580 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
4581 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
4583 ret
->procedure_count
= 0;
4584 ret
->compact_rel_size
= 0;
4585 ret
->use_rld_obj_head
= false;
4587 ret
->mips16_stubs_seen
= false;
4589 return &ret
->root
.root
;
4592 /* Hook called by the linker routine which adds symbols from an object
4593 file. We must handle the special MIPS section numbers here. */
4596 _bfd_mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
4598 struct bfd_link_info
*info
;
4599 const Elf_Internal_Sym
*sym
;
4601 flagword
*flagsp ATTRIBUTE_UNUSED
;
4605 if (SGI_COMPAT (abfd
)
4606 && (abfd
->flags
& DYNAMIC
) != 0
4607 && strcmp (*namep
, "_rld_new_interface") == 0)
4609 /* Skip Irix 5 rld entry name. */
4614 switch (sym
->st_shndx
)
4617 /* Common symbols less than the GP size are automatically
4618 treated as SHN_MIPS_SCOMMON symbols. */
4619 if (sym
->st_size
> elf_gp_size (abfd
)
4620 || IRIX_COMPAT (abfd
) == ict_irix6
)
4623 case SHN_MIPS_SCOMMON
:
4624 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
4625 (*secp
)->flags
|= SEC_IS_COMMON
;
4626 *valp
= sym
->st_size
;
4630 /* This section is used in a shared object. */
4631 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
4633 asymbol
*elf_text_symbol
;
4634 asection
*elf_text_section
;
4635 bfd_size_type amt
= sizeof (asection
);
4637 elf_text_section
= bfd_zalloc (abfd
, amt
);
4638 if (elf_text_section
== NULL
)
4641 amt
= sizeof (asymbol
);
4642 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
4643 if (elf_text_symbol
== NULL
)
4646 /* Initialize the section. */
4648 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
4649 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
4651 elf_text_section
->symbol
= elf_text_symbol
;
4652 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
4654 elf_text_section
->name
= ".text";
4655 elf_text_section
->flags
= SEC_NO_FLAGS
;
4656 elf_text_section
->output_section
= NULL
;
4657 elf_text_section
->owner
= abfd
;
4658 elf_text_symbol
->name
= ".text";
4659 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
4660 elf_text_symbol
->section
= elf_text_section
;
4662 /* This code used to do *secp = bfd_und_section_ptr if
4663 info->shared. I don't know why, and that doesn't make sense,
4664 so I took it out. */
4665 *secp
= elf_tdata (abfd
)->elf_text_section
;
4668 case SHN_MIPS_ACOMMON
:
4669 /* Fall through. XXX Can we treat this as allocated data? */
4671 /* This section is used in a shared object. */
4672 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
4674 asymbol
*elf_data_symbol
;
4675 asection
*elf_data_section
;
4676 bfd_size_type amt
= sizeof (asection
);
4678 elf_data_section
= bfd_zalloc (abfd
, amt
);
4679 if (elf_data_section
== NULL
)
4682 amt
= sizeof (asymbol
);
4683 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
4684 if (elf_data_symbol
== NULL
)
4687 /* Initialize the section. */
4689 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
4690 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
4692 elf_data_section
->symbol
= elf_data_symbol
;
4693 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
4695 elf_data_section
->name
= ".data";
4696 elf_data_section
->flags
= SEC_NO_FLAGS
;
4697 elf_data_section
->output_section
= NULL
;
4698 elf_data_section
->owner
= abfd
;
4699 elf_data_symbol
->name
= ".data";
4700 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
4701 elf_data_symbol
->section
= elf_data_section
;
4703 /* This code used to do *secp = bfd_und_section_ptr if
4704 info->shared. I don't know why, and that doesn't make sense,
4705 so I took it out. */
4706 *secp
= elf_tdata (abfd
)->elf_data_section
;
4709 case SHN_MIPS_SUNDEFINED
:
4710 *secp
= bfd_und_section_ptr
;
4714 if (SGI_COMPAT (abfd
)
4716 && info
->hash
->creator
== abfd
->xvec
4717 && strcmp (*namep
, "__rld_obj_head") == 0)
4719 struct elf_link_hash_entry
*h
;
4721 /* Mark __rld_obj_head as dynamic. */
4723 if (! (_bfd_generic_link_add_one_symbol
4724 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
4725 (bfd_vma
) *valp
, (const char *) NULL
, false,
4726 get_elf_backend_data (abfd
)->collect
,
4727 (struct bfd_link_hash_entry
**) &h
)))
4729 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
4730 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4731 h
->type
= STT_OBJECT
;
4733 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4736 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
4739 /* If this is a mips16 text symbol, add 1 to the value to make it
4740 odd. This will cause something like .word SYM to come up with
4741 the right value when it is loaded into the PC. */
4742 if (sym
->st_other
== STO_MIPS16
)
4748 /* Structure used to pass information to mips_elf_output_extsym. */
4753 struct bfd_link_info
*info
;
4754 struct ecoff_debug_info
*debug
;
4755 const struct ecoff_debug_swap
*swap
;
4759 /* This routine is used to write out ECOFF debugging external symbol
4760 information. It is called via mips_elf_link_hash_traverse. The
4761 ECOFF external symbol information must match the ELF external
4762 symbol information. Unfortunately, at this point we don't know
4763 whether a symbol is required by reloc information, so the two
4764 tables may wind up being different. We must sort out the external
4765 symbol information before we can set the final size of the .mdebug
4766 section, and we must set the size of the .mdebug section before we
4767 can relocate any sections, and we can't know which symbols are
4768 required by relocation until we relocate the sections.
4769 Fortunately, it is relatively unlikely that any symbol will be
4770 stripped but required by a reloc. In particular, it can not happen
4771 when generating a final executable. */
4774 mips_elf_output_extsym (h
, data
)
4775 struct mips_elf_link_hash_entry
*h
;
4778 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
4780 asection
*sec
, *output_section
;
4782 if (h
->root
.indx
== -2)
4784 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4785 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
4786 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
4787 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
4789 else if (einfo
->info
->strip
== strip_all
4790 || (einfo
->info
->strip
== strip_some
4791 && bfd_hash_lookup (einfo
->info
->keep_hash
,
4792 h
->root
.root
.root
.string
,
4793 false, false) == NULL
))
4801 if (h
->esym
.ifd
== -2)
4804 h
->esym
.cobol_main
= 0;
4805 h
->esym
.weakext
= 0;
4806 h
->esym
.reserved
= 0;
4807 h
->esym
.ifd
= ifdNil
;
4808 h
->esym
.asym
.value
= 0;
4809 h
->esym
.asym
.st
= stGlobal
;
4811 if (h
->root
.root
.type
== bfd_link_hash_undefined
4812 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
4816 /* Use undefined class. Also, set class and type for some
4818 name
= h
->root
.root
.root
.string
;
4819 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
4820 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
4822 h
->esym
.asym
.sc
= scData
;
4823 h
->esym
.asym
.st
= stLabel
;
4824 h
->esym
.asym
.value
= 0;
4826 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
4828 h
->esym
.asym
.sc
= scAbs
;
4829 h
->esym
.asym
.st
= stLabel
;
4830 h
->esym
.asym
.value
=
4831 mips_elf_hash_table (einfo
->info
)->procedure_count
;
4833 else if (strcmp (name
, "_gp_disp") == 0)
4835 h
->esym
.asym
.sc
= scAbs
;
4836 h
->esym
.asym
.st
= stLabel
;
4837 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
4840 h
->esym
.asym
.sc
= scUndefined
;
4842 else if (h
->root
.root
.type
!= bfd_link_hash_defined
4843 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
4844 h
->esym
.asym
.sc
= scAbs
;
4849 sec
= h
->root
.root
.u
.def
.section
;
4850 output_section
= sec
->output_section
;
4852 /* When making a shared library and symbol h is the one from
4853 the another shared library, OUTPUT_SECTION may be null. */
4854 if (output_section
== NULL
)
4855 h
->esym
.asym
.sc
= scUndefined
;
4858 name
= bfd_section_name (output_section
->owner
, output_section
);
4860 if (strcmp (name
, ".text") == 0)
4861 h
->esym
.asym
.sc
= scText
;
4862 else if (strcmp (name
, ".data") == 0)
4863 h
->esym
.asym
.sc
= scData
;
4864 else if (strcmp (name
, ".sdata") == 0)
4865 h
->esym
.asym
.sc
= scSData
;
4866 else if (strcmp (name
, ".rodata") == 0
4867 || strcmp (name
, ".rdata") == 0)
4868 h
->esym
.asym
.sc
= scRData
;
4869 else if (strcmp (name
, ".bss") == 0)
4870 h
->esym
.asym
.sc
= scBss
;
4871 else if (strcmp (name
, ".sbss") == 0)
4872 h
->esym
.asym
.sc
= scSBss
;
4873 else if (strcmp (name
, ".init") == 0)
4874 h
->esym
.asym
.sc
= scInit
;
4875 else if (strcmp (name
, ".fini") == 0)
4876 h
->esym
.asym
.sc
= scFini
;
4878 h
->esym
.asym
.sc
= scAbs
;
4882 h
->esym
.asym
.reserved
= 0;
4883 h
->esym
.asym
.index
= indexNil
;
4886 if (h
->root
.root
.type
== bfd_link_hash_common
)
4887 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
4888 else if (h
->root
.root
.type
== bfd_link_hash_defined
4889 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4891 if (h
->esym
.asym
.sc
== scCommon
)
4892 h
->esym
.asym
.sc
= scBss
;
4893 else if (h
->esym
.asym
.sc
== scSCommon
)
4894 h
->esym
.asym
.sc
= scSBss
;
4896 sec
= h
->root
.root
.u
.def
.section
;
4897 output_section
= sec
->output_section
;
4898 if (output_section
!= NULL
)
4899 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
4900 + sec
->output_offset
4901 + output_section
->vma
);
4903 h
->esym
.asym
.value
= 0;
4905 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4907 struct mips_elf_link_hash_entry
*hd
= h
;
4908 boolean no_fn_stub
= h
->no_fn_stub
;
4910 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
4912 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
4913 no_fn_stub
= no_fn_stub
|| hd
->no_fn_stub
;
4918 /* Set type and value for a symbol with a function stub. */
4919 h
->esym
.asym
.st
= stProc
;
4920 sec
= hd
->root
.root
.u
.def
.section
;
4922 h
->esym
.asym
.value
= 0;
4925 output_section
= sec
->output_section
;
4926 if (output_section
!= NULL
)
4927 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
4928 + sec
->output_offset
4929 + output_section
->vma
);
4931 h
->esym
.asym
.value
= 0;
4939 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
4940 h
->root
.root
.root
.string
,
4943 einfo
->failed
= true;
4950 /* Create a runtime procedure table from the .mdebug section. */
4953 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
4956 struct bfd_link_info
*info
;
4958 struct ecoff_debug_info
*debug
;
4960 const struct ecoff_debug_swap
*swap
;
4961 HDRR
*hdr
= &debug
->symbolic_header
;
4963 struct rpdr_ext
*erp
;
4965 struct pdr_ext
*epdr
;
4966 struct sym_ext
*esym
;
4970 bfd_size_type count
;
4971 unsigned long sindex
;
4975 const char *no_name_func
= _("static procedure (no name)");
4983 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4985 sindex
= strlen (no_name_func
) + 1;
4986 count
= hdr
->ipdMax
;
4989 size
= swap
->external_pdr_size
;
4991 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
4995 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
4998 size
= sizeof (RPDR
);
4999 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
5003 size
= sizeof (char *);
5004 sv
= (char **) bfd_malloc (size
* count
);
5008 count
= hdr
->isymMax
;
5009 size
= swap
->external_sym_size
;
5010 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
5014 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
5017 count
= hdr
->issMax
;
5018 ss
= (char *) bfd_malloc (count
);
5021 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
5024 count
= hdr
->ipdMax
;
5025 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
5027 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
5028 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
5029 rp
->adr
= sym
.value
;
5030 rp
->regmask
= pdr
.regmask
;
5031 rp
->regoffset
= pdr
.regoffset
;
5032 rp
->fregmask
= pdr
.fregmask
;
5033 rp
->fregoffset
= pdr
.fregoffset
;
5034 rp
->frameoffset
= pdr
.frameoffset
;
5035 rp
->framereg
= pdr
.framereg
;
5036 rp
->pcreg
= pdr
.pcreg
;
5038 sv
[i
] = ss
+ sym
.iss
;
5039 sindex
+= strlen (sv
[i
]) + 1;
5043 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
5044 size
= BFD_ALIGN (size
, 16);
5045 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
5048 mips_elf_hash_table (info
)->procedure_count
= 0;
5052 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
5054 erp
= (struct rpdr_ext
*) rtproc
;
5055 memset (erp
, 0, sizeof (struct rpdr_ext
));
5057 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
5058 strcpy (str
, no_name_func
);
5059 str
+= strlen (no_name_func
) + 1;
5060 for (i
= 0; i
< count
; i
++)
5062 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
5063 strcpy (str
, sv
[i
]);
5064 str
+= strlen (sv
[i
]) + 1;
5066 ECOFF_PUT_OFF (abfd
, -1, (erp
+ count
)->p_adr
);
5068 /* Set the size and contents of .rtproc section. */
5069 s
->_raw_size
= size
;
5070 s
->contents
= (bfd_byte
*) rtproc
;
5072 /* Skip this section later on (I don't think this currently
5073 matters, but someday it might). */
5074 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
5103 /* A comparison routine used to sort .gptab entries. */
5106 gptab_compare (p1
, p2
)
5110 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
5111 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
5113 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
5116 /* We need to use a special link routine to handle the .reginfo and
5117 the .mdebug sections. We need to merge all instances of these
5118 sections together, not write them all out sequentially. */
5121 _bfd_mips_elf_final_link (abfd
, info
)
5123 struct bfd_link_info
*info
;
5127 struct bfd_link_order
*p
;
5128 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
5129 asection
*rtproc_sec
;
5130 Elf32_RegInfo reginfo
;
5131 struct ecoff_debug_info debug
;
5132 const struct ecoff_debug_swap
*swap
5133 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
5134 HDRR
*symhdr
= &debug
.symbolic_header
;
5135 PTR mdebug_handle
= NULL
;
5141 static const char * const secname
[] =
5143 ".text", ".init", ".fini", ".data",
5144 ".rodata", ".sdata", ".sbss", ".bss"
5146 static const int sc
[] =
5148 scText
, scInit
, scFini
, scData
,
5149 scRData
, scSData
, scSBss
, scBss
5152 /* If all the things we linked together were PIC, but we're
5153 producing an executable (rather than a shared object), then the
5154 resulting file is CPIC (i.e., it calls PIC code.) */
5156 && !info
->relocateable
5157 && elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
5159 elf_elfheader (abfd
)->e_flags
&= ~EF_MIPS_PIC
;
5160 elf_elfheader (abfd
)->e_flags
|= EF_MIPS_CPIC
;
5163 /* We'd carefully arranged the dynamic symbol indices, and then the
5164 generic size_dynamic_sections renumbered them out from under us.
5165 Rather than trying somehow to prevent the renumbering, just do
5167 if (elf_hash_table (info
)->dynamic_sections_created
)
5171 struct mips_got_info
*g
;
5173 /* When we resort, we must tell mips_elf_sort_hash_table what
5174 the lowest index it may use is. That's the number of section
5175 symbols we're going to add. The generic ELF linker only
5176 adds these symbols when building a shared object. Note that
5177 we count the sections after (possibly) removing the .options
5179 if (!mips_elf_sort_hash_table (info
, (info
->shared
5180 ? bfd_count_sections (abfd
) + 1
5184 /* Make sure we didn't grow the global .got region. */
5185 dynobj
= elf_hash_table (info
)->dynobj
;
5186 got
= bfd_get_section_by_name (dynobj
, ".got");
5187 g
= (struct mips_got_info
*) elf_section_data (got
)->tdata
;
5189 if (g
->global_gotsym
!= NULL
)
5190 BFD_ASSERT ((elf_hash_table (info
)->dynsymcount
5191 - g
->global_gotsym
->dynindx
)
5192 <= g
->global_gotno
);
5195 /* On IRIX5, we omit the .options section. On IRIX6, however, we
5196 include it, even though we don't process it quite right. (Some
5197 entries are supposed to be merged.) Empirically, we seem to be
5198 better off including it then not. */
5199 if (IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
5200 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
5202 if (strcmp ((*secpp
)->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
5204 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
5205 if (p
->type
== bfd_indirect_link_order
)
5206 p
->u
.indirect
.section
->flags
&= ~SEC_HAS_CONTENTS
;
5207 (*secpp
)->link_order_head
= NULL
;
5208 bfd_section_list_remove (abfd
, secpp
);
5209 --abfd
->section_count
;
5215 /* Get a value for the GP register. */
5216 if (elf_gp (abfd
) == 0)
5218 struct bfd_link_hash_entry
*h
;
5220 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
5221 if (h
!= (struct bfd_link_hash_entry
*) NULL
5222 && h
->type
== bfd_link_hash_defined
)
5223 elf_gp (abfd
) = (h
->u
.def
.value
5224 + h
->u
.def
.section
->output_section
->vma
5225 + h
->u
.def
.section
->output_offset
);
5226 else if (info
->relocateable
)
5230 /* Find the GP-relative section with the lowest offset. */
5232 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
5234 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
5237 /* And calculate GP relative to that. */
5238 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
5242 /* If the relocate_section function needs to do a reloc
5243 involving the GP value, it should make a reloc_dangerous
5244 callback to warn that GP is not defined. */
5248 /* Go through the sections and collect the .reginfo and .mdebug
5252 gptab_data_sec
= NULL
;
5253 gptab_bss_sec
= NULL
;
5254 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
5256 if (strcmp (o
->name
, ".reginfo") == 0)
5258 memset (®info
, 0, sizeof reginfo
);
5260 /* We have found the .reginfo section in the output file.
5261 Look through all the link_orders comprising it and merge
5262 the information together. */
5263 for (p
= o
->link_order_head
;
5264 p
!= (struct bfd_link_order
*) NULL
;
5267 asection
*input_section
;
5269 Elf32_External_RegInfo ext
;
5272 if (p
->type
!= bfd_indirect_link_order
)
5274 if (p
->type
== bfd_data_link_order
)
5279 input_section
= p
->u
.indirect
.section
;
5280 input_bfd
= input_section
->owner
;
5282 /* The linker emulation code has probably clobbered the
5283 size to be zero bytes. */
5284 if (input_section
->_raw_size
== 0)
5285 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
5287 if (! bfd_get_section_contents (input_bfd
, input_section
,
5290 (bfd_size_type
) sizeof ext
))
5293 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
5295 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
5296 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
5297 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
5298 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
5299 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
5301 /* ri_gp_value is set by the function
5302 mips_elf32_section_processing when the section is
5303 finally written out. */
5305 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5306 elf_link_input_bfd ignores this section. */
5307 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
5310 /* Size has been set in mips_elf_always_size_sections */
5311 BFD_ASSERT(o
->_raw_size
== sizeof (Elf32_External_RegInfo
));
5313 /* Skip this section later on (I don't think this currently
5314 matters, but someday it might). */
5315 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
5320 if (strcmp (o
->name
, ".mdebug") == 0)
5322 struct extsym_info einfo
;
5325 /* We have found the .mdebug section in the output file.
5326 Look through all the link_orders comprising it and merge
5327 the information together. */
5328 symhdr
->magic
= swap
->sym_magic
;
5329 /* FIXME: What should the version stamp be? */
5331 symhdr
->ilineMax
= 0;
5335 symhdr
->isymMax
= 0;
5336 symhdr
->ioptMax
= 0;
5337 symhdr
->iauxMax
= 0;
5339 symhdr
->issExtMax
= 0;
5342 symhdr
->iextMax
= 0;
5344 /* We accumulate the debugging information itself in the
5345 debug_info structure. */
5347 debug
.external_dnr
= NULL
;
5348 debug
.external_pdr
= NULL
;
5349 debug
.external_sym
= NULL
;
5350 debug
.external_opt
= NULL
;
5351 debug
.external_aux
= NULL
;
5353 debug
.ssext
= debug
.ssext_end
= NULL
;
5354 debug
.external_fdr
= NULL
;
5355 debug
.external_rfd
= NULL
;
5356 debug
.external_ext
= debug
.external_ext_end
= NULL
;
5358 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
5359 if (mdebug_handle
== (PTR
) NULL
)
5363 esym
.cobol_main
= 0;
5367 esym
.asym
.iss
= issNil
;
5368 esym
.asym
.st
= stLocal
;
5369 esym
.asym
.reserved
= 0;
5370 esym
.asym
.index
= indexNil
;
5372 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
5374 esym
.asym
.sc
= sc
[i
];
5375 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
5378 esym
.asym
.value
= s
->vma
;
5379 last
= s
->vma
+ s
->_raw_size
;
5382 esym
.asym
.value
= last
;
5383 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
5388 for (p
= o
->link_order_head
;
5389 p
!= (struct bfd_link_order
*) NULL
;
5392 asection
*input_section
;
5394 const struct ecoff_debug_swap
*input_swap
;
5395 struct ecoff_debug_info input_debug
;
5399 if (p
->type
!= bfd_indirect_link_order
)
5401 if (p
->type
== bfd_data_link_order
)
5406 input_section
= p
->u
.indirect
.section
;
5407 input_bfd
= input_section
->owner
;
5409 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
5410 || (get_elf_backend_data (input_bfd
)
5411 ->elf_backend_ecoff_debug_swap
) == NULL
)
5413 /* I don't know what a non MIPS ELF bfd would be
5414 doing with a .mdebug section, but I don't really
5415 want to deal with it. */
5419 input_swap
= (get_elf_backend_data (input_bfd
)
5420 ->elf_backend_ecoff_debug_swap
);
5422 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
5424 /* The ECOFF linking code expects that we have already
5425 read in the debugging information and set up an
5426 ecoff_debug_info structure, so we do that now. */
5427 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
5431 if (! (bfd_ecoff_debug_accumulate
5432 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
5433 &input_debug
, input_swap
, info
)))
5436 /* Loop through the external symbols. For each one with
5437 interesting information, try to find the symbol in
5438 the linker global hash table and save the information
5439 for the output external symbols. */
5440 eraw_src
= input_debug
.external_ext
;
5441 eraw_end
= (eraw_src
5442 + (input_debug
.symbolic_header
.iextMax
5443 * input_swap
->external_ext_size
));
5445 eraw_src
< eraw_end
;
5446 eraw_src
+= input_swap
->external_ext_size
)
5450 struct mips_elf_link_hash_entry
*h
;
5452 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
5453 if (ext
.asym
.sc
== scNil
5454 || ext
.asym
.sc
== scUndefined
5455 || ext
.asym
.sc
== scSUndefined
)
5458 name
= input_debug
.ssext
+ ext
.asym
.iss
;
5459 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
5460 name
, false, false, true);
5461 if (h
== NULL
|| h
->esym
.ifd
!= -2)
5467 < input_debug
.symbolic_header
.ifdMax
);
5468 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
5474 /* Free up the information we just read. */
5475 free (input_debug
.line
);
5476 free (input_debug
.external_dnr
);
5477 free (input_debug
.external_pdr
);
5478 free (input_debug
.external_sym
);
5479 free (input_debug
.external_opt
);
5480 free (input_debug
.external_aux
);
5481 free (input_debug
.ss
);
5482 free (input_debug
.ssext
);
5483 free (input_debug
.external_fdr
);
5484 free (input_debug
.external_rfd
);
5485 free (input_debug
.external_ext
);
5487 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5488 elf_link_input_bfd ignores this section. */
5489 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
5492 if (SGI_COMPAT (abfd
) && info
->shared
)
5494 /* Create .rtproc section. */
5495 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
5496 if (rtproc_sec
== NULL
)
5498 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5499 | SEC_LINKER_CREATED
| SEC_READONLY
);
5501 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
5502 if (rtproc_sec
== NULL
5503 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
5504 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
5508 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
5509 info
, rtproc_sec
, &debug
))
5513 /* Build the external symbol information. */
5516 einfo
.debug
= &debug
;
5518 einfo
.failed
= false;
5519 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
5520 mips_elf_output_extsym
,
5525 /* Set the size of the .mdebug section. */
5526 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
5528 /* Skip this section later on (I don't think this currently
5529 matters, but someday it might). */
5530 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
5535 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
5537 const char *subname
;
5540 Elf32_External_gptab
*ext_tab
;
5543 /* The .gptab.sdata and .gptab.sbss sections hold
5544 information describing how the small data area would
5545 change depending upon the -G switch. These sections
5546 not used in executables files. */
5547 if (! info
->relocateable
)
5549 for (p
= o
->link_order_head
;
5550 p
!= (struct bfd_link_order
*) NULL
;
5553 asection
*input_section
;
5555 if (p
->type
!= bfd_indirect_link_order
)
5557 if (p
->type
== bfd_data_link_order
)
5562 input_section
= p
->u
.indirect
.section
;
5564 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5565 elf_link_input_bfd ignores this section. */
5566 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
5569 /* Skip this section later on (I don't think this
5570 currently matters, but someday it might). */
5571 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
5573 /* Really remove the section. */
5574 for (secpp
= &abfd
->sections
;
5576 secpp
= &(*secpp
)->next
)
5578 bfd_section_list_remove (abfd
, secpp
);
5579 --abfd
->section_count
;
5584 /* There is one gptab for initialized data, and one for
5585 uninitialized data. */
5586 if (strcmp (o
->name
, ".gptab.sdata") == 0)
5588 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
5592 (*_bfd_error_handler
)
5593 (_("%s: illegal section name `%s'"),
5594 bfd_get_filename (abfd
), o
->name
);
5595 bfd_set_error (bfd_error_nonrepresentable_section
);
5599 /* The linker script always combines .gptab.data and
5600 .gptab.sdata into .gptab.sdata, and likewise for
5601 .gptab.bss and .gptab.sbss. It is possible that there is
5602 no .sdata or .sbss section in the output file, in which
5603 case we must change the name of the output section. */
5604 subname
= o
->name
+ sizeof ".gptab" - 1;
5605 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
5607 if (o
== gptab_data_sec
)
5608 o
->name
= ".gptab.data";
5610 o
->name
= ".gptab.bss";
5611 subname
= o
->name
+ sizeof ".gptab" - 1;
5612 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
5615 /* Set up the first entry. */
5617 amt
= c
* sizeof (Elf32_gptab
);
5618 tab
= (Elf32_gptab
*) bfd_malloc (amt
);
5621 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
5622 tab
[0].gt_header
.gt_unused
= 0;
5624 /* Combine the input sections. */
5625 for (p
= o
->link_order_head
;
5626 p
!= (struct bfd_link_order
*) NULL
;
5629 asection
*input_section
;
5633 bfd_size_type gpentry
;
5635 if (p
->type
!= bfd_indirect_link_order
)
5637 if (p
->type
== bfd_data_link_order
)
5642 input_section
= p
->u
.indirect
.section
;
5643 input_bfd
= input_section
->owner
;
5645 /* Combine the gptab entries for this input section one
5646 by one. We know that the input gptab entries are
5647 sorted by ascending -G value. */
5648 size
= bfd_section_size (input_bfd
, input_section
);
5650 for (gpentry
= sizeof (Elf32_External_gptab
);
5652 gpentry
+= sizeof (Elf32_External_gptab
))
5654 Elf32_External_gptab ext_gptab
;
5655 Elf32_gptab int_gptab
;
5661 if (! (bfd_get_section_contents
5662 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
5664 (bfd_size_type
) sizeof (Elf32_External_gptab
))))
5670 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
5672 val
= int_gptab
.gt_entry
.gt_g_value
;
5673 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
5676 for (look
= 1; look
< c
; look
++)
5678 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
5679 tab
[look
].gt_entry
.gt_bytes
+= add
;
5681 if (tab
[look
].gt_entry
.gt_g_value
== val
)
5687 Elf32_gptab
*new_tab
;
5690 /* We need a new table entry. */
5691 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
5692 new_tab
= (Elf32_gptab
*) bfd_realloc ((PTR
) tab
, amt
);
5693 if (new_tab
== NULL
)
5699 tab
[c
].gt_entry
.gt_g_value
= val
;
5700 tab
[c
].gt_entry
.gt_bytes
= add
;
5702 /* Merge in the size for the next smallest -G
5703 value, since that will be implied by this new
5706 for (look
= 1; look
< c
; look
++)
5708 if (tab
[look
].gt_entry
.gt_g_value
< val
5710 || (tab
[look
].gt_entry
.gt_g_value
5711 > tab
[max
].gt_entry
.gt_g_value
)))
5715 tab
[c
].gt_entry
.gt_bytes
+=
5716 tab
[max
].gt_entry
.gt_bytes
;
5721 last
= int_gptab
.gt_entry
.gt_bytes
;
5724 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5725 elf_link_input_bfd ignores this section. */
5726 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
5729 /* The table must be sorted by -G value. */
5731 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
5733 /* Swap out the table. */
5734 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
5735 ext_tab
= (Elf32_External_gptab
*) bfd_alloc (abfd
, amt
);
5736 if (ext_tab
== NULL
)
5742 for (j
= 0; j
< c
; j
++)
5743 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
5746 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
5747 o
->contents
= (bfd_byte
*) ext_tab
;
5749 /* Skip this section later on (I don't think this currently
5750 matters, but someday it might). */
5751 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
5755 /* Invoke the regular ELF backend linker to do all the work. */
5756 if (ABI_64_P (abfd
))
5759 if (!bfd_elf64_bfd_final_link (abfd
, info
))
5766 else if (!bfd_elf32_bfd_final_link (abfd
, info
))
5769 /* Now write out the computed sections. */
5771 if (reginfo_sec
!= (asection
*) NULL
)
5773 Elf32_External_RegInfo ext
;
5775 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
5776 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
5777 (file_ptr
) 0, (bfd_size_type
) sizeof ext
))
5781 if (mdebug_sec
!= (asection
*) NULL
)
5783 BFD_ASSERT (abfd
->output_has_begun
);
5784 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
5786 mdebug_sec
->filepos
))
5789 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
5792 if (gptab_data_sec
!= (asection
*) NULL
)
5794 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
5795 gptab_data_sec
->contents
,
5797 gptab_data_sec
->_raw_size
))
5801 if (gptab_bss_sec
!= (asection
*) NULL
)
5803 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
5804 gptab_bss_sec
->contents
,
5806 gptab_bss_sec
->_raw_size
))
5810 if (SGI_COMPAT (abfd
))
5812 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
5813 if (rtproc_sec
!= NULL
)
5815 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
5816 rtproc_sec
->contents
,
5818 rtproc_sec
->_raw_size
))
5826 /* This function is called via qsort() to sort the dynamic relocation
5827 entries by increasing r_symndx value. */
5830 sort_dynamic_relocs (arg1
, arg2
)
5834 const Elf32_External_Rel
*ext_reloc1
= (const Elf32_External_Rel
*) arg1
;
5835 const Elf32_External_Rel
*ext_reloc2
= (const Elf32_External_Rel
*) arg2
;
5837 Elf_Internal_Rel int_reloc1
;
5838 Elf_Internal_Rel int_reloc2
;
5840 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, ext_reloc1
, &int_reloc1
);
5841 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, ext_reloc2
, &int_reloc2
);
5843 return (ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
));
5846 /* Returns the GOT section for ABFD. */
5849 mips_elf_got_section (abfd
)
5852 return bfd_get_section_by_name (abfd
, ".got");
5855 /* Returns the GOT information associated with the link indicated by
5856 INFO. If SGOTP is non-NULL, it is filled in with the GOT
5859 static struct mips_got_info
*
5860 mips_elf_got_info (abfd
, sgotp
)
5865 struct mips_got_info
*g
;
5867 sgot
= mips_elf_got_section (abfd
);
5868 BFD_ASSERT (sgot
!= NULL
);
5869 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5870 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5871 BFD_ASSERT (g
!= NULL
);
5878 /* Return whether a relocation is against a local symbol. */
5881 mips_elf_local_relocation_p (input_bfd
, relocation
, local_sections
,
5884 const Elf_Internal_Rela
*relocation
;
5885 asection
**local_sections
;
5886 boolean check_forced
;
5888 unsigned long r_symndx
;
5889 Elf_Internal_Shdr
*symtab_hdr
;
5890 struct mips_elf_link_hash_entry
*h
;
5893 r_symndx
= ELF32_R_SYM (relocation
->r_info
);
5894 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5895 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
5897 if (r_symndx
< extsymoff
)
5899 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
5904 /* Look up the hash table to check whether the symbol
5905 was forced local. */
5906 h
= (struct mips_elf_link_hash_entry
*)
5907 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
5908 /* Find the real hash-table entry for this symbol. */
5909 while (h
->root
.root
.type
== bfd_link_hash_indirect
5910 || h
->root
.root
.type
== bfd_link_hash_warning
)
5911 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
5912 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
5919 /* Sign-extend VALUE, which has the indicated number of BITS. */
5922 mips_elf_sign_extend (value
, bits
)
5926 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
5927 /* VALUE is negative. */
5928 value
|= ((bfd_vma
) - 1) << bits
;
5933 /* Return non-zero if the indicated VALUE has overflowed the maximum
5934 range expressable by a signed number with the indicated number of
5938 mips_elf_overflow_p (value
, bits
)
5942 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
5944 if (svalue
> (1 << (bits
- 1)) - 1)
5945 /* The value is too big. */
5947 else if (svalue
< -(1 << (bits
- 1)))
5948 /* The value is too small. */
5955 /* Calculate the %high function. */
5958 mips_elf_high (value
)
5961 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
5964 /* Calculate the %higher function. */
5967 mips_elf_higher (value
)
5968 bfd_vma value ATTRIBUTE_UNUSED
;
5971 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
5974 return (bfd_vma
) -1;
5978 /* Calculate the %highest function. */
5981 mips_elf_highest (value
)
5982 bfd_vma value ATTRIBUTE_UNUSED
;
5985 return ((value
+ (bfd_vma
) 0x800080008000) >> 48) & 0xffff;
5988 return (bfd_vma
) -1;
5992 /* Returns the GOT index for the global symbol indicated by H. */
5995 mips_elf_global_got_index (abfd
, h
)
5997 struct elf_link_hash_entry
*h
;
6001 struct mips_got_info
*g
;
6003 g
= mips_elf_got_info (abfd
, &sgot
);
6005 /* Once we determine the global GOT entry with the lowest dynamic
6006 symbol table index, we must put all dynamic symbols with greater
6007 indices into the GOT. That makes it easy to calculate the GOT
6009 BFD_ASSERT (h
->dynindx
>= g
->global_gotsym
->dynindx
);
6010 index
= ((h
->dynindx
- g
->global_gotsym
->dynindx
+ g
->local_gotno
)
6011 * MIPS_ELF_GOT_SIZE (abfd
));
6012 BFD_ASSERT (index
< sgot
->_raw_size
);
6017 /* Returns the offset for the entry at the INDEXth position
6021 mips_elf_got_offset_from_index (dynobj
, output_bfd
, index
)
6029 sgot
= mips_elf_got_section (dynobj
);
6030 gp
= _bfd_get_gp_value (output_bfd
);
6031 return (sgot
->output_section
->vma
+ sgot
->output_offset
+ index
-
6035 /* If H is a symbol that needs a global GOT entry, but has a dynamic
6036 symbol table index lower than any we've seen to date, record it for
6040 mips_elf_record_global_got_symbol (h
, info
, g
)
6041 struct elf_link_hash_entry
*h
;
6042 struct bfd_link_info
*info
;
6043 struct mips_got_info
*g ATTRIBUTE_UNUSED
;
6045 /* A global symbol in the GOT must also be in the dynamic symbol
6047 if (h
->dynindx
== -1
6048 && !bfd_elf32_link_record_dynamic_symbol (info
, h
))
6051 /* If we've already marked this entry as needing GOT space, we don't
6052 need to do it again. */
6053 if (h
->got
.offset
!= (bfd_vma
) -1)
6056 /* By setting this to a value other than -1, we are indicating that
6057 there needs to be a GOT entry for H. Avoid using zero, as the
6058 generic ELF copy_indirect_symbol tests for <= 0. */
6064 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
6065 the dynamic symbols. */
6067 struct mips_elf_hash_sort_data
6069 /* The symbol in the global GOT with the lowest dynamic symbol table
6071 struct elf_link_hash_entry
*low
;
6072 /* The least dynamic symbol table index corresponding to a symbol
6073 with a GOT entry. */
6074 long min_got_dynindx
;
6075 /* The greatest dynamic symbol table index not corresponding to a
6076 symbol without a GOT entry. */
6077 long max_non_got_dynindx
;
6080 /* If H needs a GOT entry, assign it the highest available dynamic
6081 index. Otherwise, assign it the lowest available dynamic
6085 mips_elf_sort_hash_table_f (h
, data
)
6086 struct mips_elf_link_hash_entry
*h
;
6089 struct mips_elf_hash_sort_data
*hsd
6090 = (struct mips_elf_hash_sort_data
*) data
;
6092 /* Symbols without dynamic symbol table entries aren't interesting
6094 if (h
->root
.dynindx
== -1)
6097 if (h
->root
.got
.offset
!= 1)
6098 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
6101 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
6102 hsd
->low
= (struct elf_link_hash_entry
*) h
;
6108 /* Sort the dynamic symbol table so that symbols that need GOT entries
6109 appear towards the end. This reduces the amount of GOT space
6110 required. MAX_LOCAL is used to set the number of local symbols
6111 known to be in the dynamic symbol table. During
6112 mips_elf_size_dynamic_sections, this value is 1. Afterward, the
6113 section symbols are added and the count is higher. */
6116 mips_elf_sort_hash_table (info
, max_local
)
6117 struct bfd_link_info
*info
;
6118 unsigned long max_local
;
6120 struct mips_elf_hash_sort_data hsd
;
6121 struct mips_got_info
*g
;
6124 dynobj
= elf_hash_table (info
)->dynobj
;
6127 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
;
6128 hsd
.max_non_got_dynindx
= max_local
;
6129 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
6130 elf_hash_table (info
)),
6131 mips_elf_sort_hash_table_f
,
6134 /* There should have been enough room in the symbol table to
6135 accomodate both the GOT and non-GOT symbols. */
6136 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
6138 /* Now we know which dynamic symbol has the lowest dynamic symbol
6139 table index in the GOT. */
6140 g
= mips_elf_got_info (dynobj
, NULL
);
6141 g
->global_gotsym
= hsd
.low
;
6146 /* Create a local GOT entry for VALUE. Return the index of the entry,
6147 or -1 if it could not be created. */
6150 mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
)
6152 struct mips_got_info
*g
;
6156 if (g
->assigned_gotno
>= g
->local_gotno
)
6158 /* We didn't allocate enough space in the GOT. */
6159 (*_bfd_error_handler
)
6160 (_("not enough GOT space for local GOT entries"));
6161 bfd_set_error (bfd_error_bad_value
);
6162 return (bfd_vma
) -1;
6165 MIPS_ELF_PUT_WORD (abfd
, value
,
6167 + MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
));
6168 return MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
6171 /* Returns the GOT offset at which the indicated address can be found.
6172 If there is not yet a GOT entry for this value, create one. Returns
6173 -1 if no satisfactory GOT offset can be found. */
6176 mips_elf_local_got_index (abfd
, info
, value
)
6178 struct bfd_link_info
*info
;
6182 struct mips_got_info
*g
;
6185 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
6187 /* Look to see if we already have an appropriate entry. */
6188 for (entry
= (sgot
->contents
6189 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
6190 entry
!= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
6191 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
6193 bfd_vma address
= MIPS_ELF_GET_WORD (abfd
, entry
);
6194 if (address
== value
)
6195 return entry
- sgot
->contents
;
6198 return mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
6201 /* Find a GOT entry that is within 32KB of the VALUE. These entries
6202 are supposed to be placed at small offsets in the GOT, i.e.,
6203 within 32KB of GP. Return the index into the GOT for this page,
6204 and store the offset from this entry to the desired address in
6205 OFFSETP, if it is non-NULL. */
6208 mips_elf_got_page (abfd
, info
, value
, offsetp
)
6210 struct bfd_link_info
*info
;
6215 struct mips_got_info
*g
;
6217 bfd_byte
*last_entry
;
6221 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
6223 /* Look to see if we aleady have an appropriate entry. */
6224 last_entry
= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
6225 for (entry
= (sgot
->contents
6226 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
6227 entry
!= last_entry
;
6228 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
6230 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
6232 if (!mips_elf_overflow_p (value
- address
, 16))
6234 /* This entry will serve as the page pointer. We can add a
6235 16-bit number to it to get the actual address. */
6236 index
= entry
- sgot
->contents
;
6241 /* If we didn't have an appropriate entry, we create one now. */
6242 if (entry
== last_entry
)
6243 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
6247 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
6248 *offsetp
= value
- address
;
6254 /* Find a GOT entry whose higher-order 16 bits are the same as those
6255 for value. Return the index into the GOT for this entry. */
6258 mips_elf_got16_entry (abfd
, info
, value
, external
)
6260 struct bfd_link_info
*info
;
6265 struct mips_got_info
*g
;
6267 bfd_byte
*last_entry
;
6273 /* Although the ABI says that it is "the high-order 16 bits" that we
6274 want, it is really the %high value. The complete value is
6275 calculated with a `addiu' of a LO16 relocation, just as with a
6277 value
= mips_elf_high (value
) << 16;
6280 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
6282 /* Look to see if we already have an appropriate entry. */
6283 last_entry
= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
6284 for (entry
= (sgot
->contents
6285 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
6286 entry
!= last_entry
;
6287 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
6289 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
6290 if (address
== value
)
6292 /* This entry has the right high-order 16 bits, and the low-order
6293 16 bits are set to zero. */
6294 index
= entry
- sgot
->contents
;
6299 /* If we didn't have an appropriate entry, we create one now. */
6300 if (entry
== last_entry
)
6301 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
6306 /* Returns the first relocation of type r_type found, beginning with
6307 RELOCATION. RELEND is one-past-the-end of the relocation table. */
6309 static const Elf_Internal_Rela
*
6310 mips_elf_next_relocation (r_type
, relocation
, relend
)
6311 unsigned int r_type
;
6312 const Elf_Internal_Rela
*relocation
;
6313 const Elf_Internal_Rela
*relend
;
6315 /* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be
6316 immediately following. However, for the IRIX6 ABI, the next
6317 relocation may be a composed relocation consisting of several
6318 relocations for the same address. In that case, the R_MIPS_LO16
6319 relocation may occur as one of these. We permit a similar
6320 extension in general, as that is useful for GCC. */
6321 while (relocation
< relend
)
6323 if (ELF32_R_TYPE (relocation
->r_info
) == r_type
)
6329 /* We didn't find it. */
6330 bfd_set_error (bfd_error_bad_value
);
6334 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
6335 is the original relocation, which is now being transformed into a
6336 dynamic relocation. The ADDENDP is adjusted if necessary; the
6337 caller should store the result in place of the original addend. */
6340 mips_elf_create_dynamic_relocation (output_bfd
, info
, rel
, h
, sec
,
6341 symbol
, addendp
, input_section
)
6343 struct bfd_link_info
*info
;
6344 const Elf_Internal_Rela
*rel
;
6345 struct mips_elf_link_hash_entry
*h
;
6349 asection
*input_section
;
6351 Elf_Internal_Rel outrel
;
6357 r_type
= ELF32_R_TYPE (rel
->r_info
);
6358 dynobj
= elf_hash_table (info
)->dynobj
;
6360 = bfd_get_section_by_name (dynobj
,
6361 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd
));
6362 BFD_ASSERT (sreloc
!= NULL
);
6363 BFD_ASSERT (sreloc
->contents
!= NULL
);
6364 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
6365 < sreloc
->_raw_size
);
6369 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
->r_offset
);
6370 if (outrel
.r_offset
== (bfd_vma
) -1)
6372 /* FIXME: For -2 runtime relocation needs to be skipped, but
6373 properly resolved statically and installed. */
6374 BFD_ASSERT (outrel
.r_offset
!= (bfd_vma
) -2);
6376 /* If we've decided to skip this relocation, just output an empty
6377 record. Note that R_MIPS_NONE == 0, so that this call to memset
6378 is a way of setting R_TYPE to R_MIPS_NONE. */
6380 memset (&outrel
, 0, sizeof (outrel
));
6384 bfd_vma section_offset
;
6386 /* We must now calculate the dynamic symbol table index to use
6387 in the relocation. */
6389 && (! info
->symbolic
|| (h
->root
.elf_link_hash_flags
6390 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
6392 indx
= h
->root
.dynindx
;
6393 /* h->root.dynindx may be -1 if this symbol was marked to
6400 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
6402 else if (sec
== NULL
|| sec
->owner
== NULL
)
6404 bfd_set_error (bfd_error_bad_value
);
6409 indx
= elf_section_data (sec
->output_section
)->dynindx
;
6414 /* Figure out how far the target of the relocation is from
6415 the beginning of its section. */
6416 section_offset
= symbol
- sec
->output_section
->vma
;
6417 /* The relocation we're building is section-relative.
6418 Therefore, the original addend must be adjusted by the
6420 *addendp
+= section_offset
;
6421 /* Now, the relocation is just against the section. */
6422 symbol
= sec
->output_section
->vma
;
6425 /* If the relocation was previously an absolute relocation and
6426 this symbol will not be referred to by the relocation, we must
6427 adjust it by the value we give it in the dynamic symbol table.
6428 Otherwise leave the job up to the dynamic linker. */
6429 if (!indx
&& r_type
!= R_MIPS_REL32
)
6432 /* The relocation is always an REL32 relocation because we don't
6433 know where the shared library will wind up at load-time. */
6434 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
6436 /* Adjust the output offset of the relocation to reference the
6437 correct location in the output file. */
6438 outrel
.r_offset
+= (input_section
->output_section
->vma
6439 + input_section
->output_offset
);
6442 /* Put the relocation back out. We have to use the special
6443 relocation outputter in the 64-bit case since the 64-bit
6444 relocation format is non-standard. */
6445 if (ABI_64_P (output_bfd
))
6447 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
6448 (output_bfd
, &outrel
,
6450 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
6453 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
6454 (((Elf32_External_Rel
*)
6456 + sreloc
->reloc_count
));
6458 /* Record the index of the first relocation referencing H. This
6459 information is later emitted in the .msym section. */
6461 && (h
->min_dyn_reloc_index
== 0
6462 || sreloc
->reloc_count
< h
->min_dyn_reloc_index
))
6463 h
->min_dyn_reloc_index
= sreloc
->reloc_count
;
6465 /* We've now added another relocation. */
6466 ++sreloc
->reloc_count
;
6468 /* Make sure the output section is writable. The dynamic linker
6469 will be writing to it. */
6470 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
6473 /* On IRIX5, make an entry of compact relocation info. */
6474 if (! skip
&& IRIX_COMPAT (output_bfd
) == ict_irix5
)
6476 asection
*scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
6481 Elf32_crinfo cptrel
;
6483 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
6484 cptrel
.vaddr
= (rel
->r_offset
6485 + input_section
->output_section
->vma
6486 + input_section
->output_offset
);
6487 if (r_type
== R_MIPS_REL32
)
6488 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
6490 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
6491 mips_elf_set_cr_dist2to (cptrel
, 0);
6492 cptrel
.konst
= *addendp
;
6494 cr
= (scpt
->contents
6495 + sizeof (Elf32_External_compact_rel
));
6496 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
6497 ((Elf32_External_crinfo
*) cr
6498 + scpt
->reloc_count
));
6499 ++scpt
->reloc_count
;
6506 /* Calculate the value produced by the RELOCATION (which comes from
6507 the INPUT_BFD). The ADDEND is the addend to use for this
6508 RELOCATION; RELOCATION->R_ADDEND is ignored.
6510 The result of the relocation calculation is stored in VALUEP.
6511 REQUIRE_JALXP indicates whether or not the opcode used with this
6512 relocation must be JALX.
6514 This function returns bfd_reloc_continue if the caller need take no
6515 further action regarding this relocation, bfd_reloc_notsupported if
6516 something goes dramatically wrong, bfd_reloc_overflow if an
6517 overflow occurs, and bfd_reloc_ok to indicate success. */
6519 static bfd_reloc_status_type
6520 mips_elf_calculate_relocation (abfd
,
6534 asection
*input_section
;
6535 struct bfd_link_info
*info
;
6536 const Elf_Internal_Rela
*relocation
;
6538 reloc_howto_type
*howto
;
6539 Elf_Internal_Sym
*local_syms
;
6540 asection
**local_sections
;
6543 boolean
*require_jalxp
;
6545 /* The eventual value we will return. */
6547 /* The address of the symbol against which the relocation is
6550 /* The final GP value to be used for the relocatable, executable, or
6551 shared object file being produced. */
6552 bfd_vma gp
= (bfd_vma
) - 1;
6553 /* The place (section offset or address) of the storage unit being
6556 /* The value of GP used to create the relocatable object. */
6557 bfd_vma gp0
= (bfd_vma
) - 1;
6558 /* The offset into the global offset table at which the address of
6559 the relocation entry symbol, adjusted by the addend, resides
6560 during execution. */
6561 bfd_vma g
= (bfd_vma
) - 1;
6562 /* The section in which the symbol referenced by the relocation is
6564 asection
*sec
= NULL
;
6565 struct mips_elf_link_hash_entry
*h
= NULL
;
6566 /* True if the symbol referred to by this relocation is a local
6569 /* True if the symbol referred to by this relocation is "_gp_disp". */
6570 boolean gp_disp_p
= false;
6571 Elf_Internal_Shdr
*symtab_hdr
;
6573 unsigned long r_symndx
;
6575 /* True if overflow occurred during the calculation of the
6576 relocation value. */
6577 boolean overflowed_p
;
6578 /* True if this relocation refers to a MIPS16 function. */
6579 boolean target_is_16_bit_code_p
= false;
6581 /* Parse the relocation. */
6582 r_symndx
= ELF32_R_SYM (relocation
->r_info
);
6583 r_type
= ELF32_R_TYPE (relocation
->r_info
);
6584 p
= (input_section
->output_section
->vma
6585 + input_section
->output_offset
6586 + relocation
->r_offset
);
6588 /* Assume that there will be no overflow. */
6589 overflowed_p
= false;
6591 /* Figure out whether or not the symbol is local, and get the offset
6592 used in the array of hash table entries. */
6593 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
6594 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
6595 local_sections
, false);
6596 if (! elf_bad_symtab (input_bfd
))
6597 extsymoff
= symtab_hdr
->sh_info
;
6600 /* The symbol table does not follow the rule that local symbols
6601 must come before globals. */
6605 /* Figure out the value of the symbol. */
6608 Elf_Internal_Sym
*sym
;
6610 sym
= local_syms
+ r_symndx
;
6611 sec
= local_sections
[r_symndx
];
6613 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
6614 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
6615 symbol
+= sym
->st_value
;
6617 /* MIPS16 text labels should be treated as odd. */
6618 if (sym
->st_other
== STO_MIPS16
)
6621 /* Record the name of this symbol, for our caller. */
6622 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
6623 symtab_hdr
->sh_link
,
6626 *namep
= bfd_section_name (input_bfd
, sec
);
6628 target_is_16_bit_code_p
= (sym
->st_other
== STO_MIPS16
);
6632 /* For global symbols we look up the symbol in the hash-table. */
6633 h
= ((struct mips_elf_link_hash_entry
*)
6634 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
6635 /* Find the real hash-table entry for this symbol. */
6636 while (h
->root
.root
.type
== bfd_link_hash_indirect
6637 || h
->root
.root
.type
== bfd_link_hash_warning
)
6638 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
6640 /* Record the name of this symbol, for our caller. */
6641 *namep
= h
->root
.root
.root
.string
;
6643 /* See if this is the special _gp_disp symbol. Note that such a
6644 symbol must always be a global symbol. */
6645 if (strcmp (h
->root
.root
.root
.string
, "_gp_disp") == 0)
6647 /* Relocations against _gp_disp are permitted only with
6648 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
6649 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_LO16
)
6650 return bfd_reloc_notsupported
;
6654 /* If this symbol is defined, calculate its address. Note that
6655 _gp_disp is a magic symbol, always implicitly defined by the
6656 linker, so it's inappropriate to check to see whether or not
6658 else if ((h
->root
.root
.type
== bfd_link_hash_defined
6659 || h
->root
.root
.type
== bfd_link_hash_defweak
)
6660 && h
->root
.root
.u
.def
.section
)
6662 sec
= h
->root
.root
.u
.def
.section
;
6663 if (sec
->output_section
)
6664 symbol
= (h
->root
.root
.u
.def
.value
6665 + sec
->output_section
->vma
6666 + sec
->output_offset
);
6668 symbol
= h
->root
.root
.u
.def
.value
;
6670 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
6671 /* We allow relocations against undefined weak symbols, giving
6672 it the value zero, so that you can undefined weak functions
6673 and check to see if they exist by looking at their
6676 else if (info
->shared
6677 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
6678 && !info
->no_undefined
6679 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
6681 else if (strcmp (h
->root
.root
.root
.string
, "_DYNAMIC_LINK") == 0 ||
6682 strcmp (h
->root
.root
.root
.string
, "_DYNAMIC_LINKING") == 0)
6684 /* If this is a dynamic link, we should have created a
6685 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
6686 in in mips_elf_create_dynamic_sections.
6687 Otherwise, we should define the symbol with a value of 0.
6688 FIXME: It should probably get into the symbol table
6690 BFD_ASSERT (! info
->shared
);
6691 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
6696 if (! ((*info
->callbacks
->undefined_symbol
)
6697 (info
, h
->root
.root
.root
.string
, input_bfd
,
6698 input_section
, relocation
->r_offset
,
6699 (!info
->shared
|| info
->no_undefined
6700 || ELF_ST_VISIBILITY (h
->root
.other
)))))
6701 return bfd_reloc_undefined
;
6705 target_is_16_bit_code_p
= (h
->root
.other
== STO_MIPS16
);
6708 /* If this is a 32-bit call to a 16-bit function with a stub, we
6709 need to redirect the call to the stub, unless we're already *in*
6711 if (r_type
!= R_MIPS16_26
&& !info
->relocateable
6712 && ((h
!= NULL
&& h
->fn_stub
!= NULL
)
6713 || (local_p
&& elf_tdata (input_bfd
)->local_stubs
!= NULL
6714 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
6715 && !mips_elf_stub_section_p (input_bfd
, input_section
))
6717 /* This is a 32-bit call to a 16-bit function. We should
6718 have already noticed that we were going to need the
6721 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
6724 BFD_ASSERT (h
->need_fn_stub
);
6728 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
6730 /* If this is a 16-bit call to a 32-bit function with a stub, we
6731 need to redirect the call to the stub. */
6732 else if (r_type
== R_MIPS16_26
&& !info
->relocateable
6734 && (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
)
6735 && !target_is_16_bit_code_p
)
6737 /* If both call_stub and call_fp_stub are defined, we can figure
6738 out which one to use by seeing which one appears in the input
6740 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
6745 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
6747 if (strncmp (bfd_get_section_name (input_bfd
, o
),
6748 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6750 sec
= h
->call_fp_stub
;
6757 else if (h
->call_stub
!= NULL
)
6760 sec
= h
->call_fp_stub
;
6762 BFD_ASSERT (sec
->_raw_size
> 0);
6763 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
6766 /* Calls from 16-bit code to 32-bit code and vice versa require the
6767 special jalx instruction. */
6768 *require_jalxp
= (!info
->relocateable
6769 && (((r_type
== R_MIPS16_26
) && !target_is_16_bit_code_p
)
6770 || ((r_type
== R_MIPS_26
) && target_is_16_bit_code_p
)));
6772 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
6773 local_sections
, true);
6775 /* If we haven't already determined the GOT offset, or the GP value,
6776 and we're going to need it, get it now. */
6781 case R_MIPS_GOT_DISP
:
6782 case R_MIPS_GOT_HI16
:
6783 case R_MIPS_CALL_HI16
:
6784 case R_MIPS_GOT_LO16
:
6785 case R_MIPS_CALL_LO16
:
6786 /* Find the index into the GOT where this value is located. */
6789 BFD_ASSERT (addend
== 0);
6790 g
= mips_elf_global_got_index
6791 (elf_hash_table (info
)->dynobj
,
6792 (struct elf_link_hash_entry
*) h
);
6793 if (! elf_hash_table(info
)->dynamic_sections_created
6795 && (info
->symbolic
|| h
->root
.dynindx
== -1)
6796 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
6798 /* This is a static link or a -Bsymbolic link. The
6799 symbol is defined locally, or was forced to be local.
6800 We must initialize this entry in the GOT. */
6801 asection
*sgot
= mips_elf_got_section(elf_hash_table
6803 MIPS_ELF_PUT_WORD (elf_hash_table (info
)->dynobj
,
6804 symbol
+ addend
, sgot
->contents
+ g
);
6807 else if (r_type
== R_MIPS_GOT16
|| r_type
== R_MIPS_CALL16
)
6808 /* There's no need to create a local GOT entry here; the
6809 calculation for a local GOT16 entry does not involve G. */
6813 g
= mips_elf_local_got_index (abfd
, info
, symbol
+ addend
);
6814 if (g
== (bfd_vma
) -1)
6815 return bfd_reloc_outofrange
;
6818 /* Convert GOT indices to actual offsets. */
6819 g
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
6825 case R_MIPS16_GPREL
:
6826 case R_MIPS_GPREL16
:
6827 case R_MIPS_GPREL32
:
6828 case R_MIPS_LITERAL
:
6829 gp0
= _bfd_get_gp_value (input_bfd
);
6830 gp
= _bfd_get_gp_value (abfd
);
6837 /* Figure out what kind of relocation is being performed. */
6841 return bfd_reloc_continue
;
6844 value
= symbol
+ mips_elf_sign_extend (addend
, 16);
6845 overflowed_p
= mips_elf_overflow_p (value
, 16);
6852 || (elf_hash_table (info
)->dynamic_sections_created
6854 && ((h
->root
.elf_link_hash_flags
6855 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0)
6856 && ((h
->root
.elf_link_hash_flags
6857 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
6859 && (input_section
->flags
& SEC_ALLOC
) != 0)
6861 /* If we're creating a shared library, or this relocation is
6862 against a symbol in a shared library, then we can't know
6863 where the symbol will end up. So, we create a relocation
6864 record in the output, and leave the job up to the dynamic
6867 if (!mips_elf_create_dynamic_relocation (abfd
,
6875 return bfd_reloc_undefined
;
6879 if (r_type
!= R_MIPS_REL32
)
6880 value
= symbol
+ addend
;
6884 value
&= howto
->dst_mask
;
6889 case R_MIPS_GNU_REL_LO16
:
6890 value
= symbol
+ addend
- p
;
6891 value
&= howto
->dst_mask
;
6894 case R_MIPS_GNU_REL16_S2
:
6895 value
= symbol
+ mips_elf_sign_extend (addend
<< 2, 18) - p
;
6896 overflowed_p
= mips_elf_overflow_p (value
, 18);
6897 value
= (value
>> 2) & howto
->dst_mask
;
6900 case R_MIPS_GNU_REL_HI16
:
6901 /* Instead of subtracting 'p' here, we should be subtracting the
6902 equivalent value for the LO part of the reloc, since the value
6903 here is relative to that address. Because that's not easy to do,
6904 we adjust 'addend' in _bfd_mips_elf_relocate_section(). See also
6905 the comment there for more information. */
6906 value
= mips_elf_high (addend
+ symbol
- p
);
6907 value
&= howto
->dst_mask
;
6911 /* The calculation for R_MIPS16_26 is just the same as for an
6912 R_MIPS_26. It's only the storage of the relocated field into
6913 the output file that's different. That's handled in
6914 mips_elf_perform_relocation. So, we just fall through to the
6915 R_MIPS_26 case here. */
6918 value
= (((addend
<< 2) | ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
6920 value
= (mips_elf_sign_extend (addend
<< 2, 28) + symbol
) >> 2;
6921 value
&= howto
->dst_mask
;
6927 value
= mips_elf_high (addend
+ symbol
);
6928 value
&= howto
->dst_mask
;
6932 value
= mips_elf_high (addend
+ gp
- p
);
6933 overflowed_p
= mips_elf_overflow_p (value
, 16);
6939 value
= (symbol
+ addend
) & howto
->dst_mask
;
6942 value
= addend
+ gp
- p
+ 4;
6943 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
6944 for overflow. But, on, say, Irix 5, relocations against
6945 _gp_disp are normally generated from the .cpload
6946 pseudo-op. It generates code that normally looks like
6949 lui $gp,%hi(_gp_disp)
6950 addiu $gp,$gp,%lo(_gp_disp)
6953 Here $t9 holds the address of the function being called,
6954 as required by the MIPS ELF ABI. The R_MIPS_LO16
6955 relocation can easily overflow in this situation, but the
6956 R_MIPS_HI16 relocation will handle the overflow.
6957 Therefore, we consider this a bug in the MIPS ABI, and do
6958 not check for overflow here. */
6962 case R_MIPS_LITERAL
:
6963 /* Because we don't merge literal sections, we can handle this
6964 just like R_MIPS_GPREL16. In the long run, we should merge
6965 shared literals, and then we will need to additional work
6970 case R_MIPS16_GPREL
:
6971 /* The R_MIPS16_GPREL performs the same calculation as
6972 R_MIPS_GPREL16, but stores the relocated bits in a different
6973 order. We don't need to do anything special here; the
6974 differences are handled in mips_elf_perform_relocation. */
6975 case R_MIPS_GPREL16
:
6977 value
= mips_elf_sign_extend (addend
, 16) + symbol
+ gp0
- gp
;
6979 value
= mips_elf_sign_extend (addend
, 16) + symbol
- gp
;
6980 overflowed_p
= mips_elf_overflow_p (value
, 16);
6989 /* The special case is when the symbol is forced to be local. We
6990 need the full address in the GOT since no R_MIPS_LO16 relocation
6992 forced
= ! mips_elf_local_relocation_p (input_bfd
, relocation
,
6993 local_sections
, false);
6994 value
= mips_elf_got16_entry (abfd
, info
, symbol
+ addend
, forced
);
6995 if (value
== (bfd_vma
) -1)
6996 return bfd_reloc_outofrange
;
6998 = mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
7001 overflowed_p
= mips_elf_overflow_p (value
, 16);
7007 case R_MIPS_GOT_DISP
:
7009 overflowed_p
= mips_elf_overflow_p (value
, 16);
7012 case R_MIPS_GPREL32
:
7013 value
= (addend
+ symbol
+ gp0
- gp
) & howto
->dst_mask
;
7017 value
= mips_elf_sign_extend (addend
, 16) + symbol
- p
;
7018 overflowed_p
= mips_elf_overflow_p (value
, 16);
7019 value
= (bfd_vma
) ((bfd_signed_vma
) value
/ 4);
7022 case R_MIPS_GOT_HI16
:
7023 case R_MIPS_CALL_HI16
:
7024 /* We're allowed to handle these two relocations identically.
7025 The dynamic linker is allowed to handle the CALL relocations
7026 differently by creating a lazy evaluation stub. */
7028 value
= mips_elf_high (value
);
7029 value
&= howto
->dst_mask
;
7032 case R_MIPS_GOT_LO16
:
7033 case R_MIPS_CALL_LO16
:
7034 value
= g
& howto
->dst_mask
;
7037 case R_MIPS_GOT_PAGE
:
7038 value
= mips_elf_got_page (abfd
, info
, symbol
+ addend
, NULL
);
7039 if (value
== (bfd_vma
) -1)
7040 return bfd_reloc_outofrange
;
7041 value
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
7044 overflowed_p
= mips_elf_overflow_p (value
, 16);
7047 case R_MIPS_GOT_OFST
:
7048 mips_elf_got_page (abfd
, info
, symbol
+ addend
, &value
);
7049 overflowed_p
= mips_elf_overflow_p (value
, 16);
7053 value
= symbol
- addend
;
7054 value
&= howto
->dst_mask
;
7058 value
= mips_elf_higher (addend
+ symbol
);
7059 value
&= howto
->dst_mask
;
7062 case R_MIPS_HIGHEST
:
7063 value
= mips_elf_highest (addend
+ symbol
);
7064 value
&= howto
->dst_mask
;
7067 case R_MIPS_SCN_DISP
:
7068 value
= symbol
+ addend
- sec
->output_offset
;
7069 value
&= howto
->dst_mask
;
7074 /* Both of these may be ignored. R_MIPS_JALR is an optimization
7075 hint; we could improve performance by honoring that hint. */
7076 return bfd_reloc_continue
;
7078 case R_MIPS_GNU_VTINHERIT
:
7079 case R_MIPS_GNU_VTENTRY
:
7080 /* We don't do anything with these at present. */
7081 return bfd_reloc_continue
;
7084 /* An unrecognized relocation type. */
7085 return bfd_reloc_notsupported
;
7088 /* Store the VALUE for our caller. */
7090 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
7093 /* Obtain the field relocated by RELOCATION. */
7096 mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
)
7097 reloc_howto_type
*howto
;
7098 const Elf_Internal_Rela
*relocation
;
7103 bfd_byte
*location
= contents
+ relocation
->r_offset
;
7105 /* Obtain the bytes. */
7106 x
= bfd_get (((bfd_vma
)(8 * bfd_get_reloc_size (howto
))), input_bfd
, location
);
7108 if ((ELF32_R_TYPE (relocation
->r_info
) == R_MIPS16_26
7109 || ELF32_R_TYPE (relocation
->r_info
) == R_MIPS16_GPREL
)
7110 && bfd_little_endian (input_bfd
))
7111 /* The two 16-bit words will be reversed on a little-endian
7112 system. See mips_elf_perform_relocation for more details. */
7113 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
7118 /* It has been determined that the result of the RELOCATION is the
7119 VALUE. Use HOWTO to place VALUE into the output file at the
7120 appropriate position. The SECTION is the section to which the
7121 relocation applies. If REQUIRE_JALX is true, then the opcode used
7122 for the relocation must be either JAL or JALX, and it is
7123 unconditionally converted to JALX.
7125 Returns false if anything goes wrong. */
7128 mips_elf_perform_relocation (info
, howto
, relocation
, value
,
7129 input_bfd
, input_section
,
7130 contents
, require_jalx
)
7131 struct bfd_link_info
*info
;
7132 reloc_howto_type
*howto
;
7133 const Elf_Internal_Rela
*relocation
;
7136 asection
*input_section
;
7138 boolean require_jalx
;
7142 int r_type
= ELF32_R_TYPE (relocation
->r_info
);
7144 /* Figure out where the relocation is occurring. */
7145 location
= contents
+ relocation
->r_offset
;
7147 /* Obtain the current value. */
7148 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
7150 /* Clear the field we are setting. */
7151 x
&= ~howto
->dst_mask
;
7153 /* If this is the R_MIPS16_26 relocation, we must store the
7154 value in a funny way. */
7155 if (r_type
== R_MIPS16_26
)
7157 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
7158 Most mips16 instructions are 16 bits, but these instructions
7161 The format of these instructions is:
7163 +--------------+--------------------------------+
7164 ! JALX ! X! Imm 20:16 ! Imm 25:21 !
7165 +--------------+--------------------------------+
7167 +-----------------------------------------------+
7169 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
7170 Note that the immediate value in the first word is swapped.
7172 When producing a relocateable object file, R_MIPS16_26 is
7173 handled mostly like R_MIPS_26. In particular, the addend is
7174 stored as a straight 26-bit value in a 32-bit instruction.
7175 (gas makes life simpler for itself by never adjusting a
7176 R_MIPS16_26 reloc to be against a section, so the addend is
7177 always zero). However, the 32 bit instruction is stored as 2
7178 16-bit values, rather than a single 32-bit value. In a
7179 big-endian file, the result is the same; in a little-endian
7180 file, the two 16-bit halves of the 32 bit value are swapped.
7181 This is so that a disassembler can recognize the jal
7184 When doing a final link, R_MIPS16_26 is treated as a 32 bit
7185 instruction stored as two 16-bit values. The addend A is the
7186 contents of the targ26 field. The calculation is the same as
7187 R_MIPS_26. When storing the calculated value, reorder the
7188 immediate value as shown above, and don't forget to store the
7189 value as two 16-bit values.
7191 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
7195 +--------+----------------------+
7199 +--------+----------------------+
7202 +----------+------+-------------+
7206 +----------+--------------------+
7207 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
7208 ((sub1 << 16) | sub2)).
7210 When producing a relocateable object file, the calculation is
7211 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
7212 When producing a fully linked file, the calculation is
7213 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
7214 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff) */
7216 if (!info
->relocateable
)
7217 /* Shuffle the bits according to the formula above. */
7218 value
= (((value
& 0x1f0000) << 5)
7219 | ((value
& 0x3e00000) >> 5)
7220 | (value
& 0xffff));
7222 else if (r_type
== R_MIPS16_GPREL
)
7224 /* R_MIPS16_GPREL is used for GP-relative addressing in mips16
7225 mode. A typical instruction will have a format like this:
7227 +--------------+--------------------------------+
7228 ! EXTEND ! Imm 10:5 ! Imm 15:11 !
7229 +--------------+--------------------------------+
7230 ! Major ! rx ! ry ! Imm 4:0 !
7231 +--------------+--------------------------------+
7233 EXTEND is the five bit value 11110. Major is the instruction
7236 This is handled exactly like R_MIPS_GPREL16, except that the
7237 addend is retrieved and stored as shown in this diagram; that
7238 is, the Imm fields above replace the V-rel16 field.
7240 All we need to do here is shuffle the bits appropriately. As
7241 above, the two 16-bit halves must be swapped on a
7242 little-endian system. */
7243 value
= (((value
& 0x7e0) << 16)
7244 | ((value
& 0xf800) << 5)
7248 /* Set the field. */
7249 x
|= (value
& howto
->dst_mask
);
7251 /* If required, turn JAL into JALX. */
7255 bfd_vma opcode
= x
>> 26;
7256 bfd_vma jalx_opcode
;
7258 /* Check to see if the opcode is already JAL or JALX. */
7259 if (r_type
== R_MIPS16_26
)
7261 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
7266 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
7270 /* If the opcode is not JAL or JALX, there's a problem. */
7273 (*_bfd_error_handler
)
7274 (_("%s: %s+0x%lx: jump to stub routine which is not jal"),
7275 bfd_archive_filename (input_bfd
),
7276 input_section
->name
,
7277 (unsigned long) relocation
->r_offset
);
7278 bfd_set_error (bfd_error_bad_value
);
7282 /* Make this the JALX opcode. */
7283 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
7286 /* Swap the high- and low-order 16 bits on little-endian systems
7287 when doing a MIPS16 relocation. */
7288 if ((r_type
== R_MIPS16_GPREL
|| r_type
== R_MIPS16_26
)
7289 && bfd_little_endian (input_bfd
))
7290 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
7292 /* Put the value into the output. */
7293 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
7297 /* Returns true if SECTION is a MIPS16 stub section. */
7300 mips_elf_stub_section_p (abfd
, section
)
7301 bfd
*abfd ATTRIBUTE_UNUSED
;
7304 const char *name
= bfd_get_section_name (abfd
, section
);
7306 return (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0
7307 || strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
7308 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0);
7311 /* Relocate a MIPS ELF section. */
7314 _bfd_mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
7315 contents
, relocs
, local_syms
, local_sections
)
7317 struct bfd_link_info
*info
;
7319 asection
*input_section
;
7321 Elf_Internal_Rela
*relocs
;
7322 Elf_Internal_Sym
*local_syms
;
7323 asection
**local_sections
;
7325 Elf_Internal_Rela
*rel
;
7326 const Elf_Internal_Rela
*relend
;
7328 boolean use_saved_addend_p
= false;
7329 struct elf_backend_data
*bed
;
7331 bed
= get_elf_backend_data (output_bfd
);
7332 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
7333 for (rel
= relocs
; rel
< relend
; ++rel
)
7337 reloc_howto_type
*howto
;
7338 boolean require_jalx
;
7339 /* True if the relocation is a RELA relocation, rather than a
7341 boolean rela_relocation_p
= true;
7342 unsigned int r_type
= ELF32_R_TYPE (rel
->r_info
);
7343 const char * msg
= (const char *) NULL
;
7345 /* Find the relocation howto for this relocation. */
7346 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
))
7348 /* Some 32-bit code uses R_MIPS_64. In particular, people use
7349 64-bit code, but make sure all their addresses are in the
7350 lowermost or uppermost 32-bit section of the 64-bit address
7351 space. Thus, when they use an R_MIPS_64 they mean what is
7352 usually meant by R_MIPS_32, with the exception that the
7353 stored value is sign-extended to 64 bits. */
7354 howto
= elf_mips_howto_table_rel
+ R_MIPS_32
;
7356 /* On big-endian systems, we need to lie about the position
7358 if (bfd_big_endian (input_bfd
))
7362 howto
= mips_rtype_to_howto (r_type
);
7364 if (!use_saved_addend_p
)
7366 Elf_Internal_Shdr
*rel_hdr
;
7368 /* If these relocations were originally of the REL variety,
7369 we must pull the addend out of the field that will be
7370 relocated. Otherwise, we simply use the contents of the
7371 RELA relocation. To determine which flavor or relocation
7372 this is, we depend on the fact that the INPUT_SECTION's
7373 REL_HDR is read before its REL_HDR2. */
7374 rel_hdr
= &elf_section_data (input_section
)->rel_hdr
;
7375 if ((size_t) (rel
- relocs
)
7376 >= (NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
))
7377 rel_hdr
= elf_section_data (input_section
)->rel_hdr2
;
7378 if (rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (input_bfd
))
7380 /* Note that this is a REL relocation. */
7381 rela_relocation_p
= false;
7383 /* Get the addend, which is stored in the input file. */
7384 addend
= mips_elf_obtain_contents (howto
,
7388 addend
&= howto
->src_mask
;
7390 /* For some kinds of relocations, the ADDEND is a
7391 combination of the addend stored in two different
7393 if (r_type
== R_MIPS_HI16
7394 || r_type
== R_MIPS_GNU_REL_HI16
7395 || (r_type
== R_MIPS_GOT16
7396 && mips_elf_local_relocation_p (input_bfd
, rel
,
7397 local_sections
, false)))
7400 const Elf_Internal_Rela
*lo16_relocation
;
7401 reloc_howto_type
*lo16_howto
;
7404 /* The combined value is the sum of the HI16 addend,
7405 left-shifted by sixteen bits, and the LO16
7406 addend, sign extended. (Usually, the code does
7407 a `lui' of the HI16 value, and then an `addiu' of
7410 Scan ahead to find a matching LO16 relocation. */
7411 if (r_type
== R_MIPS_GNU_REL_HI16
)
7412 lo
= R_MIPS_GNU_REL_LO16
;
7416 = mips_elf_next_relocation (lo
, rel
, relend
);
7417 if (lo16_relocation
== NULL
)
7420 /* Obtain the addend kept there. */
7421 lo16_howto
= mips_rtype_to_howto (lo
);
7422 l
= mips_elf_obtain_contents (lo16_howto
,
7424 input_bfd
, contents
);
7425 l
&= lo16_howto
->src_mask
;
7426 l
= mips_elf_sign_extend (l
, 16);
7430 /* Compute the combined addend. */
7433 /* If PC-relative, subtract the difference between the
7434 address of the LO part of the reloc and the address of
7435 the HI part. The relocation is relative to the LO
7436 part, but mips_elf_calculate_relocation() doesn't know
7437 it address or the difference from the HI part, so
7438 we subtract that difference here. See also the
7439 comment in mips_elf_calculate_relocation(). */
7440 if (r_type
== R_MIPS_GNU_REL_HI16
)
7441 addend
-= (lo16_relocation
->r_offset
- rel
->r_offset
);
7443 else if (r_type
== R_MIPS16_GPREL
)
7445 /* The addend is scrambled in the object file. See
7446 mips_elf_perform_relocation for details on the
7448 addend
= (((addend
& 0x1f0000) >> 5)
7449 | ((addend
& 0x7e00000) >> 16)
7454 addend
= rel
->r_addend
;
7457 if (info
->relocateable
)
7459 Elf_Internal_Sym
*sym
;
7460 unsigned long r_symndx
;
7462 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
)
7463 && bfd_big_endian (input_bfd
))
7466 /* Since we're just relocating, all we need to do is copy
7467 the relocations back out to the object file, unless
7468 they're against a section symbol, in which case we need
7469 to adjust by the section offset, or unless they're GP
7470 relative in which case we need to adjust by the amount
7471 that we're adjusting GP in this relocateable object. */
7473 if (!mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
,
7475 /* There's nothing to do for non-local relocations. */
7478 if (r_type
== R_MIPS16_GPREL
7479 || r_type
== R_MIPS_GPREL16
7480 || r_type
== R_MIPS_GPREL32
7481 || r_type
== R_MIPS_LITERAL
)
7482 addend
-= (_bfd_get_gp_value (output_bfd
)
7483 - _bfd_get_gp_value (input_bfd
));
7484 else if (r_type
== R_MIPS_26
|| r_type
== R_MIPS16_26
7485 || r_type
== R_MIPS_GNU_REL16_S2
)
7486 /* The addend is stored without its two least
7487 significant bits (which are always zero.) In a
7488 non-relocateable link, calculate_relocation will do
7489 this shift; here, we must do it ourselves. */
7492 r_symndx
= ELF32_R_SYM (rel
->r_info
);
7493 sym
= local_syms
+ r_symndx
;
7494 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
7495 /* Adjust the addend appropriately. */
7496 addend
+= local_sections
[r_symndx
]->output_offset
;
7498 /* If the relocation is for a R_MIPS_HI16 or R_MIPS_GOT16,
7499 then we only want to write out the high-order 16 bits.
7500 The subsequent R_MIPS_LO16 will handle the low-order bits. */
7501 if (r_type
== R_MIPS_HI16
|| r_type
== R_MIPS_GOT16
7502 || r_type
== R_MIPS_GNU_REL_HI16
)
7503 addend
= mips_elf_high (addend
);
7504 /* If the relocation is for an R_MIPS_26 relocation, then
7505 the two low-order bits are not stored in the object file;
7506 they are implicitly zero. */
7507 else if (r_type
== R_MIPS_26
|| r_type
== R_MIPS16_26
7508 || r_type
== R_MIPS_GNU_REL16_S2
)
7511 if (rela_relocation_p
)
7512 /* If this is a RELA relocation, just update the addend.
7513 We have to cast away constness for REL. */
7514 rel
->r_addend
= addend
;
7517 /* Otherwise, we have to write the value back out. Note
7518 that we use the source mask, rather than the
7519 destination mask because the place to which we are
7520 writing will be source of the addend in the final
7522 addend
&= howto
->src_mask
;
7524 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
))
7525 /* See the comment above about using R_MIPS_64 in the 32-bit
7526 ABI. Here, we need to update the addend. It would be
7527 possible to get away with just using the R_MIPS_32 reloc
7528 but for endianness. */
7534 if (addend
& ((bfd_vma
) 1 << 31))
7536 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
7543 /* If we don't know that we have a 64-bit type,
7544 do two separate stores. */
7545 if (bfd_big_endian (input_bfd
))
7547 /* Store the sign-bits (which are most significant)
7549 low_bits
= sign_bits
;
7555 high_bits
= sign_bits
;
7557 bfd_put_32 (input_bfd
, low_bits
,
7558 contents
+ rel
->r_offset
);
7559 bfd_put_32 (input_bfd
, high_bits
,
7560 contents
+ rel
->r_offset
+ 4);
7564 if (!mips_elf_perform_relocation (info
, howto
, rel
, addend
,
7565 input_bfd
, input_section
,
7570 /* Go on to the next relocation. */
7574 /* In the N32 and 64-bit ABIs there may be multiple consecutive
7575 relocations for the same offset. In that case we are
7576 supposed to treat the output of each relocation as the addend
7578 if (rel
+ 1 < relend
7579 && rel
->r_offset
== rel
[1].r_offset
7580 && ELF32_R_TYPE (rel
[1].r_info
) != R_MIPS_NONE
)
7581 use_saved_addend_p
= true;
7583 use_saved_addend_p
= false;
7585 /* Figure out what value we are supposed to relocate. */
7586 switch (mips_elf_calculate_relocation (output_bfd
,
7599 case bfd_reloc_continue
:
7600 /* There's nothing to do. */
7603 case bfd_reloc_undefined
:
7604 /* mips_elf_calculate_relocation already called the
7605 undefined_symbol callback. There's no real point in
7606 trying to perform the relocation at this point, so we
7607 just skip ahead to the next relocation. */
7610 case bfd_reloc_notsupported
:
7611 msg
= _("internal error: unsupported relocation error");
7612 info
->callbacks
->warning
7613 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
7616 case bfd_reloc_overflow
:
7617 if (use_saved_addend_p
)
7618 /* Ignore overflow until we reach the last relocation for
7619 a given location. */
7623 BFD_ASSERT (name
!= NULL
);
7624 if (! ((*info
->callbacks
->reloc_overflow
)
7625 (info
, name
, howto
->name
, (bfd_vma
) 0,
7626 input_bfd
, input_section
, rel
->r_offset
)))
7639 /* If we've got another relocation for the address, keep going
7640 until we reach the last one. */
7641 if (use_saved_addend_p
)
7647 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
))
7648 /* See the comment above about using R_MIPS_64 in the 32-bit
7649 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
7650 that calculated the right value. Now, however, we
7651 sign-extend the 32-bit result to 64-bits, and store it as a
7652 64-bit value. We are especially generous here in that we
7653 go to extreme lengths to support this usage on systems with
7654 only a 32-bit VMA. */
7660 if (value
& ((bfd_vma
) 1 << 31))
7662 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
7669 /* If we don't know that we have a 64-bit type,
7670 do two separate stores. */
7671 if (bfd_big_endian (input_bfd
))
7673 /* Undo what we did above. */
7675 /* Store the sign-bits (which are most significant)
7677 low_bits
= sign_bits
;
7683 high_bits
= sign_bits
;
7685 bfd_put_32 (input_bfd
, low_bits
,
7686 contents
+ rel
->r_offset
);
7687 bfd_put_32 (input_bfd
, high_bits
,
7688 contents
+ rel
->r_offset
+ 4);
7692 /* Actually perform the relocation. */
7693 if (!mips_elf_perform_relocation (info
, howto
, rel
, value
, input_bfd
,
7694 input_section
, contents
,
7702 /* This hook function is called before the linker writes out a global
7703 symbol. We mark symbols as small common if appropriate. This is
7704 also where we undo the increment of the value for a mips16 symbol. */
7707 _bfd_mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
7708 bfd
*abfd ATTRIBUTE_UNUSED
;
7709 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
7710 const char *name ATTRIBUTE_UNUSED
;
7711 Elf_Internal_Sym
*sym
;
7712 asection
*input_sec
;
7714 /* If we see a common symbol, which implies a relocatable link, then
7715 if a symbol was small common in an input file, mark it as small
7716 common in the output file. */
7717 if (sym
->st_shndx
== SHN_COMMON
7718 && strcmp (input_sec
->name
, ".scommon") == 0)
7719 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
7721 if (sym
->st_other
== STO_MIPS16
7722 && (sym
->st_value
& 1) != 0)
7728 /* Functions for the dynamic linker. */
7730 /* The name of the dynamic interpreter. This is put in the .interp
7733 #define ELF_DYNAMIC_INTERPRETER(abfd) \
7734 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
7735 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
7736 : "/usr/lib/libc.so.1")
7738 /* Create dynamic sections when linking against a dynamic object. */
7741 _bfd_mips_elf_create_dynamic_sections (abfd
, info
)
7743 struct bfd_link_info
*info
;
7745 struct elf_link_hash_entry
*h
;
7747 register asection
*s
;
7748 const char * const *namep
;
7750 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7751 | SEC_LINKER_CREATED
| SEC_READONLY
);
7753 /* Mips ABI requests the .dynamic section to be read only. */
7754 s
= bfd_get_section_by_name (abfd
, ".dynamic");
7757 if (! bfd_set_section_flags (abfd
, s
, flags
))
7761 /* We need to create .got section. */
7762 if (! mips_elf_create_got_section (abfd
, info
))
7765 /* Create the .msym section on IRIX6. It is used by the dynamic
7766 linker to speed up dynamic relocations, and to avoid computing
7767 the ELF hash for symbols. */
7768 if (IRIX_COMPAT (abfd
) == ict_irix6
7769 && !mips_elf_create_msym_section (abfd
))
7772 /* Create .stub section. */
7773 if (bfd_get_section_by_name (abfd
,
7774 MIPS_ELF_STUB_SECTION_NAME (abfd
)) == NULL
)
7776 s
= bfd_make_section (abfd
, MIPS_ELF_STUB_SECTION_NAME (abfd
));
7778 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_CODE
)
7779 || ! bfd_set_section_alignment (abfd
, s
,
7780 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7784 if ((IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
7786 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
7788 s
= bfd_make_section (abfd
, ".rld_map");
7790 || ! bfd_set_section_flags (abfd
, s
, flags
&~ (flagword
) SEC_READONLY
)
7791 || ! bfd_set_section_alignment (abfd
, s
,
7792 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7796 /* On IRIX5, we adjust add some additional symbols and change the
7797 alignments of several sections. There is no ABI documentation
7798 indicating that this is necessary on IRIX6, nor any evidence that
7799 the linker takes such action. */
7800 if (IRIX_COMPAT (abfd
) == ict_irix5
)
7802 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
7805 if (! (_bfd_generic_link_add_one_symbol
7806 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
7807 (bfd_vma
) 0, (const char *) NULL
, false,
7808 get_elf_backend_data (abfd
)->collect
,
7809 (struct bfd_link_hash_entry
**) &h
)))
7811 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
7812 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7813 h
->type
= STT_SECTION
;
7815 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7819 /* We need to create a .compact_rel section. */
7820 if (SGI_COMPAT (abfd
))
7822 if (!mips_elf_create_compact_rel_section (abfd
, info
))
7826 /* Change aligments of some sections. */
7827 s
= bfd_get_section_by_name (abfd
, ".hash");
7829 bfd_set_section_alignment (abfd
, s
, 4);
7830 s
= bfd_get_section_by_name (abfd
, ".dynsym");
7832 bfd_set_section_alignment (abfd
, s
, 4);
7833 s
= bfd_get_section_by_name (abfd
, ".dynstr");
7835 bfd_set_section_alignment (abfd
, s
, 4);
7836 s
= bfd_get_section_by_name (abfd
, ".reginfo");
7838 bfd_set_section_alignment (abfd
, s
, 4);
7839 s
= bfd_get_section_by_name (abfd
, ".dynamic");
7841 bfd_set_section_alignment (abfd
, s
, 4);
7847 if (SGI_COMPAT (abfd
))
7849 if (!(_bfd_generic_link_add_one_symbol
7850 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
7851 (bfd_vma
) 0, (const char *) NULL
, false,
7852 get_elf_backend_data (abfd
)->collect
,
7853 (struct bfd_link_hash_entry
**) &h
)))
7858 /* For normal mips it is _DYNAMIC_LINKING. */
7859 if (!(_bfd_generic_link_add_one_symbol
7860 (info
, abfd
, "_DYNAMIC_LINKING", BSF_GLOBAL
,
7861 bfd_abs_section_ptr
, (bfd_vma
) 0, (const char *) NULL
, false,
7862 get_elf_backend_data (abfd
)->collect
,
7863 (struct bfd_link_hash_entry
**) &h
)))
7866 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
7867 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7868 h
->type
= STT_SECTION
;
7870 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7873 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
7875 /* __rld_map is a four byte word located in the .data section
7876 and is filled in by the rtld to contain a pointer to
7877 the _r_debug structure. Its symbol value will be set in
7878 mips_elf_finish_dynamic_symbol. */
7879 s
= bfd_get_section_by_name (abfd
, ".rld_map");
7880 BFD_ASSERT (s
!= NULL
);
7883 if (SGI_COMPAT (abfd
))
7885 if (!(_bfd_generic_link_add_one_symbol
7886 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
7887 (bfd_vma
) 0, (const char *) NULL
, false,
7888 get_elf_backend_data (abfd
)->collect
,
7889 (struct bfd_link_hash_entry
**) &h
)))
7894 /* For normal mips the symbol is __RLD_MAP. */
7895 if (!(_bfd_generic_link_add_one_symbol
7896 (info
, abfd
, "__RLD_MAP", BSF_GLOBAL
, s
,
7897 (bfd_vma
) 0, (const char *) NULL
, false,
7898 get_elf_backend_data (abfd
)->collect
,
7899 (struct bfd_link_hash_entry
**) &h
)))
7902 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
7903 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7904 h
->type
= STT_OBJECT
;
7906 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7914 /* Create the .compact_rel section. */
7917 mips_elf_create_compact_rel_section (abfd
, info
)
7919 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
7922 register asection
*s
;
7924 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
7926 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
7929 s
= bfd_make_section (abfd
, ".compact_rel");
7931 || ! bfd_set_section_flags (abfd
, s
, flags
)
7932 || ! bfd_set_section_alignment (abfd
, s
,
7933 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7936 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
7942 /* Create the .got section to hold the global offset table. */
7945 mips_elf_create_got_section (abfd
, info
)
7947 struct bfd_link_info
*info
;
7950 register asection
*s
;
7951 struct elf_link_hash_entry
*h
;
7952 struct mips_got_info
*g
;
7955 /* This function may be called more than once. */
7956 if (mips_elf_got_section (abfd
))
7959 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7960 | SEC_LINKER_CREATED
);
7962 s
= bfd_make_section (abfd
, ".got");
7964 || ! bfd_set_section_flags (abfd
, s
, flags
)
7965 || ! bfd_set_section_alignment (abfd
, s
, 4))
7968 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
7969 linker script because we don't want to define the symbol if we
7970 are not creating a global offset table. */
7972 if (! (_bfd_generic_link_add_one_symbol
7973 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
7974 (bfd_vma
) 0, (const char *) NULL
, false,
7975 get_elf_backend_data (abfd
)->collect
,
7976 (struct bfd_link_hash_entry
**) &h
)))
7978 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
7979 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7980 h
->type
= STT_OBJECT
;
7983 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7986 /* The first several global offset table entries are reserved. */
7987 s
->_raw_size
= MIPS_RESERVED_GOTNO
* MIPS_ELF_GOT_SIZE (abfd
);
7989 amt
= sizeof (struct mips_got_info
);
7990 g
= (struct mips_got_info
*) bfd_alloc (abfd
, amt
);
7993 g
->global_gotsym
= NULL
;
7994 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
7995 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
7996 if (elf_section_data (s
) == NULL
)
7998 amt
= sizeof (struct bfd_elf_section_data
);
7999 s
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
8000 if (elf_section_data (s
) == NULL
)
8003 elf_section_data (s
)->tdata
= (PTR
) g
;
8004 elf_section_data (s
)->this_hdr
.sh_flags
8005 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
8010 /* Returns the .msym section for ABFD, creating it if it does not
8011 already exist. Returns NULL to indicate error. */
8014 mips_elf_create_msym_section (abfd
)
8019 s
= bfd_get_section_by_name (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
8022 s
= bfd_make_section (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
8024 || !bfd_set_section_flags (abfd
, s
,
8028 | SEC_LINKER_CREATED
8030 || !bfd_set_section_alignment (abfd
, s
,
8031 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
8038 /* Add room for N relocations to the .rel.dyn section in ABFD. */
8041 mips_elf_allocate_dynamic_relocations (abfd
, n
)
8047 s
= bfd_get_section_by_name (abfd
, MIPS_ELF_REL_DYN_SECTION_NAME (abfd
));
8048 BFD_ASSERT (s
!= NULL
);
8050 if (s
->_raw_size
== 0)
8052 /* Make room for a null element. */
8053 s
->_raw_size
+= MIPS_ELF_REL_SIZE (abfd
);
8056 s
->_raw_size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
8059 /* Look through the relocs for a section during the first phase, and
8060 allocate space in the global offset table. */
8063 _bfd_mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
8065 struct bfd_link_info
*info
;
8067 const Elf_Internal_Rela
*relocs
;
8071 Elf_Internal_Shdr
*symtab_hdr
;
8072 struct elf_link_hash_entry
**sym_hashes
;
8073 struct mips_got_info
*g
;
8075 const Elf_Internal_Rela
*rel
;
8076 const Elf_Internal_Rela
*rel_end
;
8079 struct elf_backend_data
*bed
;
8081 if (info
->relocateable
)
8084 dynobj
= elf_hash_table (info
)->dynobj
;
8085 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
8086 sym_hashes
= elf_sym_hashes (abfd
);
8087 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
8089 /* Check for the mips16 stub sections. */
8091 name
= bfd_get_section_name (abfd
, sec
);
8092 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
8094 unsigned long r_symndx
;
8096 /* Look at the relocation information to figure out which symbol
8099 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
8101 if (r_symndx
< extsymoff
8102 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
8106 /* This stub is for a local symbol. This stub will only be
8107 needed if there is some relocation in this BFD, other
8108 than a 16 bit function call, which refers to this symbol. */
8109 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
8111 Elf_Internal_Rela
*sec_relocs
;
8112 const Elf_Internal_Rela
*r
, *rend
;
8114 /* We can ignore stub sections when looking for relocs. */
8115 if ((o
->flags
& SEC_RELOC
) == 0
8116 || o
->reloc_count
== 0
8117 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
8118 sizeof FN_STUB
- 1) == 0
8119 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
8120 sizeof CALL_STUB
- 1) == 0
8121 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
8122 sizeof CALL_FP_STUB
- 1) == 0)
8125 sec_relocs
= (_bfd_elf32_link_read_relocs
8126 (abfd
, o
, (PTR
) NULL
,
8127 (Elf_Internal_Rela
*) NULL
,
8128 info
->keep_memory
));
8129 if (sec_relocs
== NULL
)
8132 rend
= sec_relocs
+ o
->reloc_count
;
8133 for (r
= sec_relocs
; r
< rend
; r
++)
8134 if (ELF32_R_SYM (r
->r_info
) == r_symndx
8135 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
8138 if (! info
->keep_memory
)
8147 /* There is no non-call reloc for this stub, so we do
8148 not need it. Since this function is called before
8149 the linker maps input sections to output sections, we
8150 can easily discard it by setting the SEC_EXCLUDE
8152 sec
->flags
|= SEC_EXCLUDE
;
8156 /* Record this stub in an array of local symbol stubs for
8158 if (elf_tdata (abfd
)->local_stubs
== NULL
)
8160 unsigned long symcount
;
8164 if (elf_bad_symtab (abfd
))
8165 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
8167 symcount
= symtab_hdr
->sh_info
;
8168 amt
= symcount
* sizeof (asection
*);
8169 n
= (asection
**) bfd_zalloc (abfd
, amt
);
8172 elf_tdata (abfd
)->local_stubs
= n
;
8175 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
8177 /* We don't need to set mips16_stubs_seen in this case.
8178 That flag is used to see whether we need to look through
8179 the global symbol table for stubs. We don't need to set
8180 it here, because we just have a local stub. */
8184 struct mips_elf_link_hash_entry
*h
;
8186 h
= ((struct mips_elf_link_hash_entry
*)
8187 sym_hashes
[r_symndx
- extsymoff
]);
8189 /* H is the symbol this stub is for. */
8192 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
8195 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
8196 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
8198 unsigned long r_symndx
;
8199 struct mips_elf_link_hash_entry
*h
;
8202 /* Look at the relocation information to figure out which symbol
8205 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
8207 if (r_symndx
< extsymoff
8208 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
8210 /* This stub was actually built for a static symbol defined
8211 in the same file. We assume that all static symbols in
8212 mips16 code are themselves mips16, so we can simply
8213 discard this stub. Since this function is called before
8214 the linker maps input sections to output sections, we can
8215 easily discard it by setting the SEC_EXCLUDE flag. */
8216 sec
->flags
|= SEC_EXCLUDE
;
8220 h
= ((struct mips_elf_link_hash_entry
*)
8221 sym_hashes
[r_symndx
- extsymoff
]);
8223 /* H is the symbol this stub is for. */
8225 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
8226 loc
= &h
->call_fp_stub
;
8228 loc
= &h
->call_stub
;
8230 /* If we already have an appropriate stub for this function, we
8231 don't need another one, so we can discard this one. Since
8232 this function is called before the linker maps input sections
8233 to output sections, we can easily discard it by setting the
8234 SEC_EXCLUDE flag. We can also discard this section if we
8235 happen to already know that this is a mips16 function; it is
8236 not necessary to check this here, as it is checked later, but
8237 it is slightly faster to check now. */
8238 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
8240 sec
->flags
|= SEC_EXCLUDE
;
8245 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
8255 sgot
= mips_elf_got_section (dynobj
);
8260 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
8261 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
8262 BFD_ASSERT (g
!= NULL
);
8267 bed
= get_elf_backend_data (abfd
);
8268 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
8269 for (rel
= relocs
; rel
< rel_end
; ++rel
)
8271 unsigned long r_symndx
;
8272 unsigned int r_type
;
8273 struct elf_link_hash_entry
*h
;
8275 r_symndx
= ELF32_R_SYM (rel
->r_info
);
8276 r_type
= ELF32_R_TYPE (rel
->r_info
);
8278 if (r_symndx
< extsymoff
)
8280 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
8282 (*_bfd_error_handler
)
8283 (_("%s: Malformed reloc detected for section %s"),
8284 bfd_archive_filename (abfd
), name
);
8285 bfd_set_error (bfd_error_bad_value
);
8290 h
= sym_hashes
[r_symndx
- extsymoff
];
8292 /* This may be an indirect symbol created because of a version. */
8295 while (h
->root
.type
== bfd_link_hash_indirect
)
8296 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8300 /* Some relocs require a global offset table. */
8301 if (dynobj
== NULL
|| sgot
== NULL
)
8307 case R_MIPS_CALL_HI16
:
8308 case R_MIPS_CALL_LO16
:
8309 case R_MIPS_GOT_HI16
:
8310 case R_MIPS_GOT_LO16
:
8311 case R_MIPS_GOT_PAGE
:
8312 case R_MIPS_GOT_OFST
:
8313 case R_MIPS_GOT_DISP
:
8315 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
8316 if (! mips_elf_create_got_section (dynobj
, info
))
8318 g
= mips_elf_got_info (dynobj
, &sgot
);
8325 && (info
->shared
|| h
!= NULL
)
8326 && (sec
->flags
& SEC_ALLOC
) != 0)
8327 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
8335 if (!h
&& (r_type
== R_MIPS_CALL_LO16
8336 || r_type
== R_MIPS_GOT_LO16
8337 || r_type
== R_MIPS_GOT_DISP
))
8339 /* We may need a local GOT entry for this relocation. We
8340 don't count R_MIPS_GOT_PAGE because we can estimate the
8341 maximum number of pages needed by looking at the size of
8342 the segment. Similar comments apply to R_MIPS_GOT16 and
8343 R_MIPS_CALL16. We don't count R_MIPS_GOT_HI16, or
8344 R_MIPS_CALL_HI16 because these are always followed by an
8345 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16.
8347 This estimation is very conservative since we can merge
8348 duplicate entries in the GOT. In order to be less
8349 conservative, we could actually build the GOT here,
8350 rather than in relocate_section. */
8352 sgot
->_raw_size
+= MIPS_ELF_GOT_SIZE (dynobj
);
8360 (*_bfd_error_handler
)
8361 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
8362 bfd_archive_filename (abfd
), (unsigned long) rel
->r_offset
);
8363 bfd_set_error (bfd_error_bad_value
);
8368 case R_MIPS_CALL_HI16
:
8369 case R_MIPS_CALL_LO16
:
8372 /* This symbol requires a global offset table entry. */
8373 if (!mips_elf_record_global_got_symbol (h
, info
, g
))
8376 /* We need a stub, not a plt entry for the undefined
8377 function. But we record it as if it needs plt. See
8378 elf_adjust_dynamic_symbol in elflink.h. */
8379 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
8385 case R_MIPS_GOT_HI16
:
8386 case R_MIPS_GOT_LO16
:
8387 case R_MIPS_GOT_DISP
:
8388 /* This symbol requires a global offset table entry. */
8389 if (h
&& !mips_elf_record_global_got_symbol (h
, info
, g
))
8396 if ((info
->shared
|| h
!= NULL
)
8397 && (sec
->flags
& SEC_ALLOC
) != 0)
8401 const char *dname
= MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
);
8403 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
8406 sreloc
= bfd_make_section (dynobj
, dname
);
8408 || ! bfd_set_section_flags (dynobj
, sreloc
,
8413 | SEC_LINKER_CREATED
8415 || ! bfd_set_section_alignment (dynobj
, sreloc
,
8420 #define MIPS_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
8423 /* When creating a shared object, we must copy these
8424 reloc types into the output file as R_MIPS_REL32
8425 relocs. We make room for this reloc in the
8426 .rel.dyn reloc section. */
8427 mips_elf_allocate_dynamic_relocations (dynobj
, 1);
8428 if ((sec
->flags
& MIPS_READONLY_SECTION
)
8429 == MIPS_READONLY_SECTION
)
8430 /* We tell the dynamic linker that there are
8431 relocations against the text segment. */
8432 info
->flags
|= DF_TEXTREL
;
8436 struct mips_elf_link_hash_entry
*hmips
;
8438 /* We only need to copy this reloc if the symbol is
8439 defined in a dynamic object. */
8440 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8441 ++hmips
->possibly_dynamic_relocs
;
8442 if ((sec
->flags
& MIPS_READONLY_SECTION
)
8443 == MIPS_READONLY_SECTION
)
8444 /* We need it to tell the dynamic linker if there
8445 are relocations against the text segment. */
8446 hmips
->readonly_reloc
= true;
8449 /* Even though we don't directly need a GOT entry for
8450 this symbol, a symbol must have a dynamic symbol
8451 table index greater that DT_MIPS_GOTSYM if there are
8452 dynamic relocations against it. */
8454 && !mips_elf_record_global_got_symbol (h
, info
, g
))
8458 if (SGI_COMPAT (abfd
))
8459 mips_elf_hash_table (info
)->compact_rel_size
+=
8460 sizeof (Elf32_External_crinfo
);
8464 case R_MIPS_GPREL16
:
8465 case R_MIPS_LITERAL
:
8466 case R_MIPS_GPREL32
:
8467 if (SGI_COMPAT (abfd
))
8468 mips_elf_hash_table (info
)->compact_rel_size
+=
8469 sizeof (Elf32_External_crinfo
);
8472 /* This relocation describes the C++ object vtable hierarchy.
8473 Reconstruct it for later use during GC. */
8474 case R_MIPS_GNU_VTINHERIT
:
8475 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
8479 /* This relocation describes which C++ vtable entries are actually
8480 used. Record for later use during GC. */
8481 case R_MIPS_GNU_VTENTRY
:
8482 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
8490 /* We must not create a stub for a symbol that has relocations
8491 related to taking the function's address. */
8497 struct mips_elf_link_hash_entry
*mh
;
8499 mh
= (struct mips_elf_link_hash_entry
*) h
;
8500 mh
->no_fn_stub
= true;
8504 case R_MIPS_CALL_HI16
:
8505 case R_MIPS_CALL_LO16
:
8509 /* If this reloc is not a 16 bit call, and it has a global
8510 symbol, then we will need the fn_stub if there is one.
8511 References from a stub section do not count. */
8513 && r_type
!= R_MIPS16_26
8514 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
8515 sizeof FN_STUB
- 1) != 0
8516 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
8517 sizeof CALL_STUB
- 1) != 0
8518 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
8519 sizeof CALL_FP_STUB
- 1) != 0)
8521 struct mips_elf_link_hash_entry
*mh
;
8523 mh
= (struct mips_elf_link_hash_entry
*) h
;
8524 mh
->need_fn_stub
= true;
8531 /* Return the section that should be marked against GC for a given
8535 _bfd_mips_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
8537 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
8538 Elf_Internal_Rela
*rel
;
8539 struct elf_link_hash_entry
*h
;
8540 Elf_Internal_Sym
*sym
;
8542 /* ??? Do mips16 stub sections need to be handled special? */
8546 switch (ELF32_R_TYPE (rel
->r_info
))
8548 case R_MIPS_GNU_VTINHERIT
:
8549 case R_MIPS_GNU_VTENTRY
:
8553 switch (h
->root
.type
)
8555 case bfd_link_hash_defined
:
8556 case bfd_link_hash_defweak
:
8557 return h
->root
.u
.def
.section
;
8559 case bfd_link_hash_common
:
8560 return h
->root
.u
.c
.p
->section
;
8569 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
8575 /* Update the got entry reference counts for the section being removed. */
8578 _bfd_mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
8579 bfd
*abfd ATTRIBUTE_UNUSED
;
8580 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
8581 asection
*sec ATTRIBUTE_UNUSED
;
8582 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
8585 Elf_Internal_Shdr
*symtab_hdr
;
8586 struct elf_link_hash_entry
**sym_hashes
;
8587 bfd_signed_vma
*local_got_refcounts
;
8588 const Elf_Internal_Rela
*rel
, *relend
;
8589 unsigned long r_symndx
;
8590 struct elf_link_hash_entry
*h
;
8592 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
8593 sym_hashes
= elf_sym_hashes (abfd
);
8594 local_got_refcounts
= elf_local_got_refcounts (abfd
);
8596 relend
= relocs
+ sec
->reloc_count
;
8597 for (rel
= relocs
; rel
< relend
; rel
++)
8598 switch (ELF32_R_TYPE (rel
->r_info
))
8602 case R_MIPS_CALL_HI16
:
8603 case R_MIPS_CALL_LO16
:
8604 case R_MIPS_GOT_HI16
:
8605 case R_MIPS_GOT_LO16
:
8606 /* ??? It would seem that the existing MIPS code does no sort
8607 of reference counting or whatnot on its GOT and PLT entries,
8608 so it is not possible to garbage collect them at this time. */
8619 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
8620 hiding the old indirect symbol. Process additional relocation
8621 information. Also called for weakdefs, in which case we just let
8622 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
8625 _bfd_mips_elf_copy_indirect_symbol (dir
, ind
)
8626 struct elf_link_hash_entry
*dir
, *ind
;
8628 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
8630 _bfd_elf_link_hash_copy_indirect (dir
, ind
);
8632 if (ind
->root
.type
!= bfd_link_hash_indirect
)
8635 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
8636 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
8637 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
8638 if (indmips
->readonly_reloc
)
8639 dirmips
->readonly_reloc
= true;
8640 if (dirmips
->min_dyn_reloc_index
== 0
8641 || (indmips
->min_dyn_reloc_index
!= 0
8642 && indmips
->min_dyn_reloc_index
< dirmips
->min_dyn_reloc_index
))
8643 dirmips
->min_dyn_reloc_index
= indmips
->min_dyn_reloc_index
;
8644 if (indmips
->no_fn_stub
)
8645 dirmips
->no_fn_stub
= true;
8648 /* Adjust a symbol defined by a dynamic object and referenced by a
8649 regular object. The current definition is in some section of the
8650 dynamic object, but we're not including those sections. We have to
8651 change the definition to something the rest of the link can
8655 _bfd_mips_elf_adjust_dynamic_symbol (info
, h
)
8656 struct bfd_link_info
*info
;
8657 struct elf_link_hash_entry
*h
;
8660 struct mips_elf_link_hash_entry
*hmips
;
8663 dynobj
= elf_hash_table (info
)->dynobj
;
8665 /* Make sure we know what is going on here. */
8666 BFD_ASSERT (dynobj
!= NULL
8667 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
8668 || h
->weakdef
!= NULL
8669 || ((h
->elf_link_hash_flags
8670 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
8671 && (h
->elf_link_hash_flags
8672 & ELF_LINK_HASH_REF_REGULAR
) != 0
8673 && (h
->elf_link_hash_flags
8674 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
8676 /* If this symbol is defined in a dynamic object, we need to copy
8677 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
8679 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8680 if (! info
->relocateable
8681 && hmips
->possibly_dynamic_relocs
!= 0
8682 && (h
->root
.type
== bfd_link_hash_defweak
8683 || (h
->elf_link_hash_flags
8684 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
8686 mips_elf_allocate_dynamic_relocations (dynobj
,
8687 hmips
->possibly_dynamic_relocs
);
8688 if (hmips
->readonly_reloc
)
8689 /* We tell the dynamic linker that there are relocations
8690 against the text segment. */
8691 info
->flags
|= DF_TEXTREL
;
8694 /* For a function, create a stub, if allowed. */
8695 if (! hmips
->no_fn_stub
8696 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
8698 if (! elf_hash_table (info
)->dynamic_sections_created
)
8701 /* If this symbol is not defined in a regular file, then set
8702 the symbol to the stub location. This is required to make
8703 function pointers compare as equal between the normal
8704 executable and the shared library. */
8705 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
8707 /* We need .stub section. */
8708 s
= bfd_get_section_by_name (dynobj
,
8709 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
8710 BFD_ASSERT (s
!= NULL
);
8712 h
->root
.u
.def
.section
= s
;
8713 h
->root
.u
.def
.value
= s
->_raw_size
;
8715 /* XXX Write this stub address somewhere. */
8716 h
->plt
.offset
= s
->_raw_size
;
8718 /* Make room for this stub code. */
8719 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
8721 /* The last half word of the stub will be filled with the index
8722 of this symbol in .dynsym section. */
8726 else if ((h
->type
== STT_FUNC
)
8727 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) == 0)
8729 /* This will set the entry for this symbol in the GOT to 0, and
8730 the dynamic linker will take care of this. */
8731 h
->root
.u
.def
.value
= 0;
8735 /* If this is a weak symbol, and there is a real definition, the
8736 processor independent code will have arranged for us to see the
8737 real definition first, and we can just use the same value. */
8738 if (h
->weakdef
!= NULL
)
8740 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
8741 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
8742 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
8743 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
8747 /* This is a reference to a symbol defined by a dynamic object which
8748 is not a function. */
8753 /* This function is called after all the input files have been read,
8754 and the input sections have been assigned to output sections. We
8755 check for any mips16 stub sections that we can discard. */
8757 static boolean mips_elf_check_mips16_stubs
8758 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
8761 _bfd_mips_elf_always_size_sections (output_bfd
, info
)
8763 struct bfd_link_info
*info
;
8767 /* The .reginfo section has a fixed size. */
8768 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
8770 bfd_set_section_size (output_bfd
, ri
,
8771 (bfd_size_type
) sizeof (Elf32_External_RegInfo
));
8773 if (info
->relocateable
8774 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
8777 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
8778 mips_elf_check_mips16_stubs
,
8784 /* Check the mips16 stubs for a particular symbol, and see if we can
8788 mips_elf_check_mips16_stubs (h
, data
)
8789 struct mips_elf_link_hash_entry
*h
;
8790 PTR data ATTRIBUTE_UNUSED
;
8792 if (h
->fn_stub
!= NULL
8793 && ! h
->need_fn_stub
)
8795 /* We don't need the fn_stub; the only references to this symbol
8796 are 16 bit calls. Clobber the size to 0 to prevent it from
8797 being included in the link. */
8798 h
->fn_stub
->_raw_size
= 0;
8799 h
->fn_stub
->_cooked_size
= 0;
8800 h
->fn_stub
->flags
&= ~SEC_RELOC
;
8801 h
->fn_stub
->reloc_count
= 0;
8802 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
8805 if (h
->call_stub
!= NULL
8806 && h
->root
.other
== STO_MIPS16
)
8808 /* We don't need the call_stub; this is a 16 bit function, so
8809 calls from other 16 bit functions are OK. Clobber the size
8810 to 0 to prevent it from being included in the link. */
8811 h
->call_stub
->_raw_size
= 0;
8812 h
->call_stub
->_cooked_size
= 0;
8813 h
->call_stub
->flags
&= ~SEC_RELOC
;
8814 h
->call_stub
->reloc_count
= 0;
8815 h
->call_stub
->flags
|= SEC_EXCLUDE
;
8818 if (h
->call_fp_stub
!= NULL
8819 && h
->root
.other
== STO_MIPS16
)
8821 /* We don't need the call_stub; this is a 16 bit function, so
8822 calls from other 16 bit functions are OK. Clobber the size
8823 to 0 to prevent it from being included in the link. */
8824 h
->call_fp_stub
->_raw_size
= 0;
8825 h
->call_fp_stub
->_cooked_size
= 0;
8826 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
8827 h
->call_fp_stub
->reloc_count
= 0;
8828 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
8834 /* Set the sizes of the dynamic sections. */
8837 _bfd_mips_elf_size_dynamic_sections (output_bfd
, info
)
8839 struct bfd_link_info
*info
;
8844 struct mips_got_info
*g
= NULL
;
8846 dynobj
= elf_hash_table (info
)->dynobj
;
8847 BFD_ASSERT (dynobj
!= NULL
);
8849 if (elf_hash_table (info
)->dynamic_sections_created
)
8851 /* Set the contents of the .interp section to the interpreter. */
8854 s
= bfd_get_section_by_name (dynobj
, ".interp");
8855 BFD_ASSERT (s
!= NULL
);
8857 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
8859 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
8863 /* The check_relocs and adjust_dynamic_symbol entry points have
8864 determined the sizes of the various dynamic sections. Allocate
8867 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8872 /* It's OK to base decisions on the section name, because none
8873 of the dynobj section names depend upon the input files. */
8874 name
= bfd_get_section_name (dynobj
, s
);
8876 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8881 if (strncmp (name
, ".rel", 4) == 0)
8883 if (s
->_raw_size
== 0)
8885 /* We only strip the section if the output section name
8886 has the same name. Otherwise, there might be several
8887 input sections for this output section. FIXME: This
8888 code is probably not needed these days anyhow, since
8889 the linker now does not create empty output sections. */
8890 if (s
->output_section
!= NULL
8892 bfd_get_section_name (s
->output_section
->owner
,
8893 s
->output_section
)) == 0)
8898 const char *outname
;
8901 /* If this relocation section applies to a read only
8902 section, then we probably need a DT_TEXTREL entry.
8903 If the relocation section is .rel.dyn, we always
8904 assert a DT_TEXTREL entry rather than testing whether
8905 there exists a relocation to a read only section or
8907 outname
= bfd_get_section_name (output_bfd
,
8909 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
8911 && (target
->flags
& SEC_READONLY
) != 0
8912 && (target
->flags
& SEC_ALLOC
) != 0)
8914 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd
)) == 0)
8917 /* We use the reloc_count field as a counter if we need
8918 to copy relocs into the output file. */
8920 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd
)) != 0)
8924 else if (strncmp (name
, ".got", 4) == 0)
8927 bfd_size_type loadable_size
= 0;
8928 bfd_size_type local_gotno
;
8931 BFD_ASSERT (elf_section_data (s
) != NULL
);
8932 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
8933 BFD_ASSERT (g
!= NULL
);
8935 /* Calculate the total loadable size of the output. That
8936 will give us the maximum number of GOT_PAGE entries
8938 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
8940 asection
*subsection
;
8942 for (subsection
= sub
->sections
;
8944 subsection
= subsection
->next
)
8946 if ((subsection
->flags
& SEC_ALLOC
) == 0)
8948 loadable_size
+= ((subsection
->_raw_size
+ 0xf)
8949 &~ (bfd_size_type
) 0xf);
8952 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
8954 /* Assume there are two loadable segments consisting of
8955 contiguous sections. Is 5 enough? */
8956 local_gotno
= (loadable_size
>> 16) + 5;
8957 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
8958 /* It's possible we will need GOT_PAGE entries as well as
8959 GOT16 entries. Often, these will be able to share GOT
8960 entries, but not always. */
8963 g
->local_gotno
+= local_gotno
;
8964 s
->_raw_size
+= local_gotno
* MIPS_ELF_GOT_SIZE (dynobj
);
8966 /* There has to be a global GOT entry for every symbol with
8967 a dynamic symbol table index of DT_MIPS_GOTSYM or
8968 higher. Therefore, it make sense to put those symbols
8969 that need GOT entries at the end of the symbol table. We
8971 if (!mips_elf_sort_hash_table (info
, 1))
8974 if (g
->global_gotsym
!= NULL
)
8975 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
8977 /* If there are no global symbols, or none requiring
8978 relocations, then GLOBAL_GOTSYM will be NULL. */
8980 g
->global_gotno
= i
;
8981 s
->_raw_size
+= i
* MIPS_ELF_GOT_SIZE (dynobj
);
8983 else if (strcmp (name
, MIPS_ELF_STUB_SECTION_NAME (output_bfd
)) == 0)
8985 /* Irix rld assumes that the function stub isn't at the end
8986 of .text section. So put a dummy. XXX */
8987 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
8989 else if (! info
->shared
8990 && ! mips_elf_hash_table (info
)->use_rld_obj_head
8991 && strncmp (name
, ".rld_map", 8) == 0)
8993 /* We add a room for __rld_map. It will be filled in by the
8994 rtld to contain a pointer to the _r_debug structure. */
8997 else if (SGI_COMPAT (output_bfd
)
8998 && strncmp (name
, ".compact_rel", 12) == 0)
8999 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
9000 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
))
9002 s
->_raw_size
= (sizeof (Elf32_External_Msym
)
9003 * (elf_hash_table (info
)->dynsymcount
9004 + bfd_count_sections (output_bfd
)));
9005 else if (strncmp (name
, ".init", 5) != 0)
9007 /* It's not one of our sections, so don't allocate space. */
9013 _bfd_strip_section_from_output (info
, s
);
9017 /* Allocate memory for the section contents. */
9018 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
9019 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
9021 bfd_set_error (bfd_error_no_memory
);
9026 if (elf_hash_table (info
)->dynamic_sections_created
)
9028 /* Add some entries to the .dynamic section. We fill in the
9029 values later, in elf_mips_finish_dynamic_sections, but we
9030 must add the entries now so that we get the correct size for
9031 the .dynamic section. The DT_DEBUG entry is filled in by the
9032 dynamic linker and used by the debugger. */
9035 /* SGI object has the equivalence of DT_DEBUG in the
9036 DT_MIPS_RLD_MAP entry. */
9037 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
9039 if (!SGI_COMPAT (output_bfd
))
9041 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
9047 /* Shared libraries on traditional mips have DT_DEBUG. */
9048 if (!SGI_COMPAT (output_bfd
))
9050 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
9055 if (reltext
&& SGI_COMPAT (output_bfd
))
9056 info
->flags
|= DF_TEXTREL
;
9058 if ((info
->flags
& DF_TEXTREL
) != 0)
9060 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
9064 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
9067 if (bfd_get_section_by_name (dynobj
,
9068 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
)))
9070 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
9073 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
9076 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
9080 if (SGI_COMPAT (output_bfd
))
9082 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICTNO
, 0))
9086 if (SGI_COMPAT (output_bfd
))
9088 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLISTNO
, 0))
9092 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
9094 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICT
, 0))
9097 s
= bfd_get_section_by_name (dynobj
, ".liblist");
9098 BFD_ASSERT (s
!= NULL
);
9100 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLIST
, 0))
9104 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
9107 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
9111 /* Time stamps in executable files are a bad idea. */
9112 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_TIME_STAMP
, 0))
9117 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_ICHECKSUM
, 0))
9122 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_IVERSION
, 0))
9126 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
9129 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
9132 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
9135 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
9138 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
9141 if (IRIX_COMPAT (dynobj
) == ict_irix5
9142 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
9145 if (IRIX_COMPAT (dynobj
) == ict_irix6
9146 && (bfd_get_section_by_name
9147 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
9148 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
9151 if (bfd_get_section_by_name (dynobj
,
9152 MIPS_ELF_MSYM_SECTION_NAME (dynobj
))
9153 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_MSYM
, 0))
9160 /* If NAME is one of the special IRIX6 symbols defined by the linker,
9161 adjust it appropriately now. */
9164 mips_elf_irix6_finish_dynamic_symbol (abfd
, name
, sym
)
9165 bfd
*abfd ATTRIBUTE_UNUSED
;
9167 Elf_Internal_Sym
*sym
;
9169 /* The linker script takes care of providing names and values for
9170 these, but we must place them into the right sections. */
9171 static const char* const text_section_symbols
[] = {
9174 "__dso_displacement",
9176 "__program_header_table",
9180 static const char* const data_section_symbols
[] = {
9188 const char* const *p
;
9191 for (i
= 0; i
< 2; ++i
)
9192 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
9195 if (strcmp (*p
, name
) == 0)
9197 /* All of these symbols are given type STT_SECTION by the
9199 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9201 /* The IRIX linker puts these symbols in special sections. */
9203 sym
->st_shndx
= SHN_MIPS_TEXT
;
9205 sym
->st_shndx
= SHN_MIPS_DATA
;
9211 /* Finish up dynamic symbol handling. We set the contents of various
9212 dynamic sections here. */
9215 _bfd_mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
9217 struct bfd_link_info
*info
;
9218 struct elf_link_hash_entry
*h
;
9219 Elf_Internal_Sym
*sym
;
9225 struct mips_got_info
*g
;
9227 struct mips_elf_link_hash_entry
*mh
;
9229 dynobj
= elf_hash_table (info
)->dynobj
;
9230 gval
= sym
->st_value
;
9231 mh
= (struct mips_elf_link_hash_entry
*) h
;
9233 if (h
->plt
.offset
!= (bfd_vma
) -1)
9237 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
9239 /* This symbol has a stub. Set it up. */
9241 BFD_ASSERT (h
->dynindx
!= -1);
9243 s
= bfd_get_section_by_name (dynobj
,
9244 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
9245 BFD_ASSERT (s
!= NULL
);
9247 /* Fill the stub. */
9249 bfd_put_32 (output_bfd
, (bfd_vma
) STUB_LW (output_bfd
), p
);
9251 bfd_put_32 (output_bfd
, (bfd_vma
) STUB_MOVE (output_bfd
), p
);
9254 /* FIXME: Can h->dynindex be more than 64K? */
9255 if (h
->dynindx
& 0xffff0000)
9258 bfd_put_32 (output_bfd
, (bfd_vma
) STUB_JALR
, p
);
9260 bfd_put_32 (output_bfd
, (bfd_vma
) STUB_LI16 (output_bfd
) + h
->dynindx
, p
);
9262 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
9263 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
9265 /* Mark the symbol as undefined. plt.offset != -1 occurs
9266 only for the referenced symbol. */
9267 sym
->st_shndx
= SHN_UNDEF
;
9269 /* The run-time linker uses the st_value field of the symbol
9270 to reset the global offset table entry for this external
9271 to its stub address when unlinking a shared object. */
9272 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
9273 sym
->st_value
= gval
;
9276 BFD_ASSERT (h
->dynindx
!= -1
9277 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0);
9279 sgot
= mips_elf_got_section (dynobj
);
9280 BFD_ASSERT (sgot
!= NULL
);
9281 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
9282 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
9283 BFD_ASSERT (g
!= NULL
);
9285 /* Run through the global symbol table, creating GOT entries for all
9286 the symbols that need them. */
9287 if (g
->global_gotsym
!= NULL
9288 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
9294 value
= sym
->st_value
;
9297 /* For an entity defined in a shared object, this will be
9298 NULL. (For functions in shared objects for
9299 which we have created stubs, ST_VALUE will be non-NULL.
9300 That's because such the functions are now no longer defined
9301 in a shared object.) */
9303 if (info
->shared
&& h
->root
.type
== bfd_link_hash_undefined
)
9306 value
= h
->root
.u
.def
.value
;
9308 offset
= mips_elf_global_got_index (dynobj
, h
);
9309 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
9312 /* Create a .msym entry, if appropriate. */
9313 smsym
= bfd_get_section_by_name (dynobj
,
9314 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
9317 Elf32_Internal_Msym msym
;
9319 msym
.ms_hash_value
= bfd_elf_hash (h
->root
.root
.string
);
9320 /* It is undocumented what the `1' indicates, but IRIX6 uses
9322 msym
.ms_info
= ELF32_MS_INFO (mh
->min_dyn_reloc_index
, 1);
9323 bfd_mips_elf_swap_msym_out
9325 ((Elf32_External_Msym
*) smsym
->contents
) + h
->dynindx
);
9328 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
9329 name
= h
->root
.root
.string
;
9330 if (strcmp (name
, "_DYNAMIC") == 0
9331 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
9332 sym
->st_shndx
= SHN_ABS
;
9333 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
9334 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
9336 sym
->st_shndx
= SHN_ABS
;
9337 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9340 else if (strcmp (name
, "_gp_disp") == 0)
9342 sym
->st_shndx
= SHN_ABS
;
9343 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9344 sym
->st_value
= elf_gp (output_bfd
);
9346 else if (SGI_COMPAT (output_bfd
))
9348 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
9349 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
9351 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9352 sym
->st_other
= STO_PROTECTED
;
9354 sym
->st_shndx
= SHN_MIPS_DATA
;
9356 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
9358 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9359 sym
->st_other
= STO_PROTECTED
;
9360 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
9361 sym
->st_shndx
= SHN_ABS
;
9363 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
9365 if (h
->type
== STT_FUNC
)
9366 sym
->st_shndx
= SHN_MIPS_TEXT
;
9367 else if (h
->type
== STT_OBJECT
)
9368 sym
->st_shndx
= SHN_MIPS_DATA
;
9372 /* Handle the IRIX6-specific symbols. */
9373 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
9374 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
9378 if (! mips_elf_hash_table (info
)->use_rld_obj_head
9379 && (strcmp (name
, "__rld_map") == 0
9380 || strcmp (name
, "__RLD_MAP") == 0))
9382 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
9383 BFD_ASSERT (s
!= NULL
);
9384 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
9385 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
9386 if (mips_elf_hash_table (info
)->rld_value
== 0)
9387 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
9389 else if (mips_elf_hash_table (info
)->use_rld_obj_head
9390 && strcmp (name
, "__rld_obj_head") == 0)
9392 /* IRIX6 does not use a .rld_map section. */
9393 if (IRIX_COMPAT (output_bfd
) == ict_irix5
9394 || IRIX_COMPAT (output_bfd
) == ict_none
)
9395 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
9397 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
9401 /* If this is a mips16 symbol, force the value to be even. */
9402 if (sym
->st_other
== STO_MIPS16
9403 && (sym
->st_value
& 1) != 0)
9409 /* Finish up the dynamic sections. */
9412 _bfd_mips_elf_finish_dynamic_sections (output_bfd
, info
)
9414 struct bfd_link_info
*info
;
9419 struct mips_got_info
*g
;
9421 dynobj
= elf_hash_table (info
)->dynobj
;
9423 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
9425 sgot
= mips_elf_got_section (dynobj
);
9430 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
9431 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
9432 BFD_ASSERT (g
!= NULL
);
9435 if (elf_hash_table (info
)->dynamic_sections_created
)
9439 BFD_ASSERT (sdyn
!= NULL
);
9440 BFD_ASSERT (g
!= NULL
);
9442 for (b
= sdyn
->contents
;
9443 b
< sdyn
->contents
+ sdyn
->_raw_size
;
9444 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
9446 Elf_Internal_Dyn dyn
;
9452 /* Read in the current dynamic entry. */
9453 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
9455 /* Assume that we're going to modify it and write it out. */
9461 s
= (bfd_get_section_by_name
9463 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
)));
9464 BFD_ASSERT (s
!= NULL
);
9465 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
9469 /* Rewrite DT_STRSZ. */
9471 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
9477 case DT_MIPS_CONFLICT
:
9480 case DT_MIPS_LIBLIST
:
9483 s
= bfd_get_section_by_name (output_bfd
, name
);
9484 BFD_ASSERT (s
!= NULL
);
9485 dyn
.d_un
.d_ptr
= s
->vma
;
9488 case DT_MIPS_RLD_VERSION
:
9489 dyn
.d_un
.d_val
= 1; /* XXX */
9493 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
9496 case DT_MIPS_CONFLICTNO
:
9498 elemsize
= sizeof (Elf32_Conflict
);
9501 case DT_MIPS_LIBLISTNO
:
9503 elemsize
= sizeof (Elf32_Lib
);
9505 s
= bfd_get_section_by_name (output_bfd
, name
);
9508 if (s
->_cooked_size
!= 0)
9509 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
9511 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
9517 case DT_MIPS_TIME_STAMP
:
9518 time ((time_t *) &dyn
.d_un
.d_val
);
9521 case DT_MIPS_ICHECKSUM
:
9526 case DT_MIPS_IVERSION
:
9531 case DT_MIPS_BASE_ADDRESS
:
9532 s
= output_bfd
->sections
;
9533 BFD_ASSERT (s
!= NULL
);
9534 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
9537 case DT_MIPS_LOCAL_GOTNO
:
9538 dyn
.d_un
.d_val
= g
->local_gotno
;
9541 case DT_MIPS_UNREFEXTNO
:
9542 /* The index into the dynamic symbol table which is the
9543 entry of the first external symbol that is not
9544 referenced within the same object. */
9545 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
9548 case DT_MIPS_GOTSYM
:
9549 if (g
->global_gotsym
)
9551 dyn
.d_un
.d_val
= g
->global_gotsym
->dynindx
;
9554 /* In case if we don't have global got symbols we default
9555 to setting DT_MIPS_GOTSYM to the same value as
9556 DT_MIPS_SYMTABNO, so we just fall through. */
9558 case DT_MIPS_SYMTABNO
:
9560 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
9561 s
= bfd_get_section_by_name (output_bfd
, name
);
9562 BFD_ASSERT (s
!= NULL
);
9564 if (s
->_cooked_size
!= 0)
9565 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
9567 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
9570 case DT_MIPS_HIPAGENO
:
9571 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
9574 case DT_MIPS_RLD_MAP
:
9575 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
9578 case DT_MIPS_OPTIONS
:
9579 s
= (bfd_get_section_by_name
9580 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
9581 dyn
.d_un
.d_ptr
= s
->vma
;
9585 s
= (bfd_get_section_by_name
9586 (output_bfd
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
)));
9587 dyn
.d_un
.d_ptr
= s
->vma
;
9596 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
9601 /* The first entry of the global offset table will be filled at
9602 runtime. The second entry will be used by some runtime loaders.
9603 This isn't the case of Irix rld. */
9604 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
9606 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
9607 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0x80000000,
9608 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
9612 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
9613 = MIPS_ELF_GOT_SIZE (output_bfd
);
9618 Elf32_compact_rel cpt
;
9620 /* ??? The section symbols for the output sections were set up in
9621 _bfd_elf_final_link. SGI sets the STT_NOTYPE attribute for these
9622 symbols. Should we do so? */
9624 smsym
= bfd_get_section_by_name (dynobj
,
9625 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
9628 Elf32_Internal_Msym msym
;
9630 msym
.ms_hash_value
= 0;
9631 msym
.ms_info
= ELF32_MS_INFO (0, 1);
9633 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
9635 long dynindx
= elf_section_data (s
)->dynindx
;
9637 bfd_mips_elf_swap_msym_out
9639 (((Elf32_External_Msym
*) smsym
->contents
)
9644 if (SGI_COMPAT (output_bfd
))
9646 /* Write .compact_rel section out. */
9647 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
9651 cpt
.num
= s
->reloc_count
;
9653 cpt
.offset
= (s
->output_section
->filepos
9654 + sizeof (Elf32_External_compact_rel
));
9657 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
9658 ((Elf32_External_compact_rel
*)
9661 /* Clean up a dummy stub function entry in .text. */
9662 s
= bfd_get_section_by_name (dynobj
,
9663 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
9666 file_ptr dummy_offset
;
9668 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
9669 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
9670 memset (s
->contents
+ dummy_offset
, 0,
9671 MIPS_FUNCTION_STUB_SIZE
);
9676 /* We need to sort the entries of the dynamic relocation section. */
9678 if (!ABI_64_P (output_bfd
))
9682 reldyn
= bfd_get_section_by_name (dynobj
,
9683 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
));
9684 if (reldyn
!= NULL
&& reldyn
->reloc_count
> 2)
9686 reldyn_sorting_bfd
= output_bfd
;
9687 qsort ((Elf32_External_Rel
*) reldyn
->contents
+ 1,
9688 (size_t) reldyn
->reloc_count
- 1,
9689 sizeof (Elf32_External_Rel
), sort_dynamic_relocs
);
9693 /* Clean up a first relocation in .rel.dyn. */
9694 s
= bfd_get_section_by_name (dynobj
,
9695 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
));
9696 if (s
!= NULL
&& s
->_raw_size
> 0)
9697 memset (s
->contents
, 0, MIPS_ELF_REL_SIZE (dynobj
));
9703 /* Support for core dump NOTE sections */
9705 _bfd_elf32_mips_grok_prstatus (abfd
, note
)
9707 Elf_Internal_Note
*note
;
9710 unsigned int raw_size
;
9712 switch (note
->descsz
)
9717 case 256: /* Linux/MIPS */
9719 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
9722 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
9731 /* Make a ".reg/999" section. */
9732 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
9733 raw_size
, note
->descpos
+ offset
);
9737 _bfd_elf32_mips_grok_psinfo (abfd
, note
)
9739 Elf_Internal_Note
*note
;
9741 switch (note
->descsz
)
9746 case 128: /* Linux/MIPS elf_prpsinfo */
9747 elf_tdata (abfd
)->core_program
9748 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
9749 elf_tdata (abfd
)->core_command
9750 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
9753 /* Note that for some reason, a spurious space is tacked
9754 onto the end of the args in some (at least one anyway)
9755 implementations, so strip it off if it exists. */
9758 char *command
= elf_tdata (abfd
)->core_command
;
9759 int n
= strlen (command
);
9761 if (0 < n
&& command
[n
- 1] == ' ')
9762 command
[n
- 1] = '\0';
9771 _bfd_elf32_mips_discard_info (abfd
, cookie
, info
)
9773 struct elf_reloc_cookie
*cookie
;
9774 struct bfd_link_info
*info
;
9777 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
9778 boolean ret
= false;
9779 unsigned char *tdata
;
9782 o
= bfd_get_section_by_name (abfd
, ".pdr");
9785 if (o
->_raw_size
== 0)
9787 if (o
->_raw_size
% PDR_SIZE
!= 0)
9789 if (o
->output_section
!= NULL
9790 && bfd_is_abs_section (o
->output_section
))
9793 tdata
= bfd_zmalloc (o
->_raw_size
/ PDR_SIZE
);
9797 cookie
->rels
= _bfd_elf32_link_read_relocs (abfd
, o
, (PTR
) NULL
,
9798 (Elf_Internal_Rela
*) NULL
,
9806 cookie
->rel
= cookie
->rels
;
9808 cookie
->rels
+ o
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
9810 for (i
= 0, skip
= 0; i
< o
->_raw_size
; i
++)
9812 if (_bfd_elf32_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
9821 elf_section_data (o
)->tdata
= tdata
;
9822 o
->_cooked_size
= o
->_raw_size
- skip
* PDR_SIZE
;
9828 if (! info
->keep_memory
)
9829 free (cookie
->rels
);
9835 _bfd_elf32_mips_ignore_discarded_relocs (sec
)
9838 if (strcmp (sec
->name
, ".pdr") == 0)
9844 _bfd_elf32_mips_write_section (output_bfd
, sec
, contents
)
9849 bfd_byte
*to
, *from
, *end
;
9852 if (strcmp (sec
->name
, ".pdr") != 0)
9855 if (elf_section_data (sec
)->tdata
== NULL
)
9859 end
= contents
+ sec
->_raw_size
;
9860 for (from
= contents
, i
= 0;
9862 from
+= PDR_SIZE
, i
++)
9864 if (((unsigned char *)elf_section_data (sec
)->tdata
)[i
] == 1)
9867 memcpy (to
, from
, PDR_SIZE
);
9870 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
9871 (file_ptr
) sec
->output_offset
,
9876 /* Given a data section and an in-memory embedded reloc section, store
9877 relocation information into the embedded reloc section which can be
9878 used at runtime to relocate the data section. This is called by the
9879 linker when the --embedded-relocs switch is used. This is called
9880 after the add_symbols entry point has been called for all the
9881 objects, and before the final_link entry point is called. */
9884 bfd_mips_elf32_create_embedded_relocs (abfd
, info
, datasec
, relsec
, errmsg
)
9886 struct bfd_link_info
*info
;
9891 Elf_Internal_Shdr
*symtab_hdr
;
9892 Elf_Internal_Shdr
*shndx_hdr
;
9893 Elf32_External_Sym
*extsyms
;
9894 Elf32_External_Sym
*free_extsyms
= NULL
;
9895 Elf_External_Sym_Shndx
*shndx_buf
= NULL
;
9896 Elf_Internal_Rela
*internal_relocs
;
9897 Elf_Internal_Rela
*free_relocs
= NULL
;
9898 Elf_Internal_Rela
*irel
, *irelend
;
9902 BFD_ASSERT (! info
->relocateable
);
9906 if (datasec
->reloc_count
== 0)
9909 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
9910 /* Read this BFD's symbols if we haven't done so already, or get the cached
9911 copy if it exists. */
9912 if (symtab_hdr
->contents
!= NULL
)
9913 extsyms
= (Elf32_External_Sym
*) symtab_hdr
->contents
;
9916 /* Go get them off disk. */
9917 if (info
->keep_memory
)
9918 extsyms
= ((Elf32_External_Sym
*)
9919 bfd_alloc (abfd
, symtab_hdr
->sh_size
));
9921 extsyms
= ((Elf32_External_Sym
*)
9922 bfd_malloc (symtab_hdr
->sh_size
));
9923 if (extsyms
== NULL
)
9925 if (! info
->keep_memory
)
9926 free_extsyms
= extsyms
;
9927 if (bfd_seek (abfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
9928 || (bfd_bread (extsyms
, symtab_hdr
->sh_size
, abfd
)
9929 != symtab_hdr
->sh_size
))
9931 if (info
->keep_memory
)
9932 symtab_hdr
->contents
= (unsigned char *) extsyms
;
9935 shndx_hdr
= &elf_tdata (abfd
)->symtab_shndx_hdr
;
9936 if (shndx_hdr
->sh_size
!= 0)
9938 amt
= symtab_hdr
->sh_info
* sizeof (Elf_External_Sym_Shndx
);
9939 shndx_buf
= (Elf_External_Sym_Shndx
*) bfd_malloc (amt
);
9940 if (shndx_buf
== NULL
)
9942 if (bfd_seek (abfd
, shndx_hdr
->sh_offset
, SEEK_SET
) != 0
9943 || bfd_bread ((PTR
) shndx_buf
, amt
, abfd
) != amt
)
9947 /* Get a copy of the native relocations. */
9948 internal_relocs
= (_bfd_elf32_link_read_relocs
9949 (abfd
, datasec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
9950 info
->keep_memory
));
9951 if (internal_relocs
== NULL
)
9953 if (! info
->keep_memory
)
9954 free_relocs
= internal_relocs
;
9956 relsec
->contents
= (bfd_byte
*) bfd_alloc (abfd
, datasec
->reloc_count
* 12);
9957 if (relsec
->contents
== NULL
)
9960 p
= relsec
->contents
;
9962 irelend
= internal_relocs
+ datasec
->reloc_count
;
9964 for (irel
= internal_relocs
; irel
< irelend
; irel
++, p
+= 12)
9966 asection
*targetsec
;
9968 /* We are going to write a four byte longword into the runtime
9969 reloc section. The longword will be the address in the data
9970 section which must be relocated. It is followed by the name
9971 of the target section NUL-padded or truncated to 8
9974 /* We can only relocate absolute longword relocs at run time. */
9975 if ((ELF32_R_TYPE (irel
->r_info
) != (int) R_MIPS_32
) &&
9976 (ELF32_R_TYPE (irel
->r_info
) != (int) R_MIPS_64
))
9978 *errmsg
= _("unsupported reloc type");
9979 bfd_set_error (bfd_error_bad_value
);
9982 /* Get the target section referred to by the reloc. */
9983 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
9985 Elf32_External_Sym
*esym
;
9986 Elf_External_Sym_Shndx
*shndx
;
9987 Elf_Internal_Sym isym
;
9989 /* A local symbol. */
9990 esym
= extsyms
+ ELF32_R_SYM (irel
->r_info
);
9991 shndx
= shndx_buf
+ (shndx_buf
? ELF32_R_SYM (irel
->r_info
) : 0);
9992 bfd_elf32_swap_symbol_in (abfd
, esym
, shndx
, &isym
);
9994 targetsec
= bfd_section_from_elf_index (abfd
, isym
.st_shndx
);
9999 struct elf_link_hash_entry
*h
;
10001 /* An external symbol. */
10002 indx
= ELF32_R_SYM (irel
->r_info
);
10003 h
= elf_sym_hashes (abfd
)[indx
];
10006 * For some reason, in certain programs, the symbol will
10007 * not be in the hash table. It seems to happen when you
10008 * declare a static table of pointers to const external structures.
10009 * In this case, the relocs are relative to data, not
10010 * text, so just treating it like an undefined link
10011 * should be sufficient.
10013 BFD_ASSERT(h
!= NULL
);
10014 if (h
->root
.type
== bfd_link_hash_defined
10015 || h
->root
.type
== bfd_link_hash_defweak
)
10016 targetsec
= h
->root
.u
.def
.section
;
10021 * Set the low bit of the relocation offset if it's a MIPS64 reloc.
10022 * Relocations will always be on (at least) 32-bit boundaries.
10025 bfd_put_32 (abfd
, ((irel
->r_offset
+ datasec
->output_offset
) +
10026 ((ELF32_R_TYPE (irel
->r_info
) == (int) R_MIPS_64
) ? 1 : 0)),
10028 memset (p
+ 4, 0, 8);
10029 if (targetsec
!= NULL
)
10030 strncpy (p
+ 4, targetsec
->output_section
->name
, 8);
10033 if (shndx_buf
!= NULL
)
10035 if (free_extsyms
!= NULL
)
10036 free (free_extsyms
);
10037 if (free_relocs
!= NULL
)
10038 free (free_relocs
);
10042 if (shndx_buf
!= NULL
)
10044 if (free_extsyms
!= NULL
)
10045 free (free_extsyms
);
10046 if (free_relocs
!= NULL
)
10047 free (free_relocs
);
10051 /* This is almost identical to bfd_generic_get_... except that some
10052 MIPS relocations need to be handled specially. Sigh. */
10055 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
10056 relocateable
, symbols
)
10058 struct bfd_link_info
*link_info
;
10059 struct bfd_link_order
*link_order
;
10061 boolean relocateable
;
10064 /* Get enough memory to hold the stuff */
10065 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
10066 asection
*input_section
= link_order
->u
.indirect
.section
;
10068 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
10069 arelent
**reloc_vector
= NULL
;
10072 if (reloc_size
< 0)
10075 reloc_vector
= (arelent
**) bfd_malloc ((bfd_size_type
) reloc_size
);
10076 if (reloc_vector
== NULL
&& reloc_size
!= 0)
10079 /* read in the section */
10080 if (!bfd_get_section_contents (input_bfd
,
10084 input_section
->_raw_size
))
10087 /* We're not relaxing the section, so just copy the size info */
10088 input_section
->_cooked_size
= input_section
->_raw_size
;
10089 input_section
->reloc_done
= true;
10091 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
10095 if (reloc_count
< 0)
10098 if (reloc_count
> 0)
10103 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
10106 struct bfd_hash_entry
*h
;
10107 struct bfd_link_hash_entry
*lh
;
10108 /* Skip all this stuff if we aren't mixing formats. */
10109 if (abfd
&& input_bfd
10110 && abfd
->xvec
== input_bfd
->xvec
)
10114 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
10115 lh
= (struct bfd_link_hash_entry
*) h
;
10122 case bfd_link_hash_undefined
:
10123 case bfd_link_hash_undefweak
:
10124 case bfd_link_hash_common
:
10127 case bfd_link_hash_defined
:
10128 case bfd_link_hash_defweak
:
10130 gp
= lh
->u
.def
.value
;
10132 case bfd_link_hash_indirect
:
10133 case bfd_link_hash_warning
:
10135 /* @@FIXME ignoring warning for now */
10137 case bfd_link_hash_new
:
10146 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
10149 char *error_message
= (char *) NULL
;
10150 bfd_reloc_status_type r
;
10152 /* Specific to MIPS: Deal with relocation types that require
10153 knowing the gp of the output bfd. */
10154 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
10155 if (bfd_is_abs_section (sym
->section
) && abfd
)
10157 /* The special_function wouldn't get called anyways. */
10159 else if (!gp_found
)
10161 /* The gp isn't there; let the special function code
10162 fall over on its own. */
10164 else if ((*parent
)->howto
->special_function
10165 == _bfd_mips_elf_gprel16_reloc
)
10167 /* bypass special_function call */
10168 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
10169 relocateable
, (PTR
) data
, gp
);
10170 goto skip_bfd_perform_relocation
;
10172 /* end mips specific stuff */
10174 r
= bfd_perform_relocation (input_bfd
,
10178 relocateable
? abfd
: (bfd
*) NULL
,
10180 skip_bfd_perform_relocation
:
10184 asection
*os
= input_section
->output_section
;
10186 /* A partial link, so keep the relocs */
10187 os
->orelocation
[os
->reloc_count
] = *parent
;
10191 if (r
!= bfd_reloc_ok
)
10195 case bfd_reloc_undefined
:
10196 if (!((*link_info
->callbacks
->undefined_symbol
)
10197 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
10198 input_bfd
, input_section
, (*parent
)->address
,
10202 case bfd_reloc_dangerous
:
10203 BFD_ASSERT (error_message
!= (char *) NULL
);
10204 if (!((*link_info
->callbacks
->reloc_dangerous
)
10205 (link_info
, error_message
, input_bfd
, input_section
,
10206 (*parent
)->address
)))
10209 case bfd_reloc_overflow
:
10210 if (!((*link_info
->callbacks
->reloc_overflow
)
10211 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
10212 (*parent
)->howto
->name
, (*parent
)->addend
,
10213 input_bfd
, input_section
, (*parent
)->address
)))
10216 case bfd_reloc_outofrange
:
10225 if (reloc_vector
!= NULL
)
10226 free (reloc_vector
);
10230 if (reloc_vector
!= NULL
)
10231 free (reloc_vector
);
10235 #define bfd_elf32_bfd_get_relocated_section_contents \
10236 elf32_mips_get_relocated_section_contents
10238 /* ECOFF swapping routines. These are used when dealing with the
10239 .mdebug section, which is in the ECOFF debugging format. */
10240 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
= {
10241 /* Symbol table magic number. */
10243 /* Alignment of debugging information. E.g., 4. */
10245 /* Sizes of external symbolic information. */
10246 sizeof (struct hdr_ext
),
10247 sizeof (struct dnr_ext
),
10248 sizeof (struct pdr_ext
),
10249 sizeof (struct sym_ext
),
10250 sizeof (struct opt_ext
),
10251 sizeof (struct fdr_ext
),
10252 sizeof (struct rfd_ext
),
10253 sizeof (struct ext_ext
),
10254 /* Functions to swap in external symbolic data. */
10263 _bfd_ecoff_swap_tir_in
,
10264 _bfd_ecoff_swap_rndx_in
,
10265 /* Functions to swap out external symbolic data. */
10266 ecoff_swap_hdr_out
,
10267 ecoff_swap_dnr_out
,
10268 ecoff_swap_pdr_out
,
10269 ecoff_swap_sym_out
,
10270 ecoff_swap_opt_out
,
10271 ecoff_swap_fdr_out
,
10272 ecoff_swap_rfd_out
,
10273 ecoff_swap_ext_out
,
10274 _bfd_ecoff_swap_tir_out
,
10275 _bfd_ecoff_swap_rndx_out
,
10276 /* Function to read in symbolic data. */
10277 _bfd_mips_elf_read_ecoff_info
10280 #define ELF_ARCH bfd_arch_mips
10281 #define ELF_MACHINE_CODE EM_MIPS
10283 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
10284 a value of 0x1000, and we are compatible. */
10285 #define ELF_MAXPAGESIZE 0x1000
10287 #define elf_backend_collect true
10288 #define elf_backend_type_change_ok true
10289 #define elf_backend_can_gc_sections true
10290 #define elf_info_to_howto mips_info_to_howto_rela
10291 #define elf_info_to_howto_rel mips_info_to_howto_rel
10292 #define elf_backend_sym_is_global mips_elf_sym_is_global
10293 #define elf_backend_object_p _bfd_mips_elf_object_p
10294 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
10295 #define elf_backend_section_processing _bfd_mips_elf_section_processing
10296 #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
10297 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
10298 #define elf_backend_section_from_bfd_section \
10299 _bfd_mips_elf_section_from_bfd_section
10300 #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
10301 #define elf_backend_link_output_symbol_hook \
10302 _bfd_mips_elf_link_output_symbol_hook
10303 #define elf_backend_create_dynamic_sections \
10304 _bfd_mips_elf_create_dynamic_sections
10305 #define elf_backend_check_relocs _bfd_mips_elf_check_relocs
10306 #define elf_backend_adjust_dynamic_symbol \
10307 _bfd_mips_elf_adjust_dynamic_symbol
10308 #define elf_backend_always_size_sections \
10309 _bfd_mips_elf_always_size_sections
10310 #define elf_backend_size_dynamic_sections \
10311 _bfd_mips_elf_size_dynamic_sections
10312 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section
10313 #define elf_backend_finish_dynamic_symbol \
10314 _bfd_mips_elf_finish_dynamic_symbol
10315 #define elf_backend_finish_dynamic_sections \
10316 _bfd_mips_elf_finish_dynamic_sections
10317 #define elf_backend_final_write_processing \
10318 _bfd_mips_elf_final_write_processing
10319 #define elf_backend_additional_program_headers \
10320 _bfd_mips_elf_additional_program_headers
10321 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
10322 #define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
10323 #define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
10324 #define elf_backend_copy_indirect_symbol \
10325 _bfd_mips_elf_copy_indirect_symbol
10326 #define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
10327 #define elf_backend_grok_prstatus _bfd_elf32_mips_grok_prstatus
10328 #define elf_backend_grok_psinfo _bfd_elf32_mips_grok_psinfo
10329 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
10331 #define elf_backend_got_header_size (4 * MIPS_RESERVED_GOTNO)
10332 #define elf_backend_plt_header_size 0
10333 #define elf_backend_may_use_rel_p 1
10334 #define elf_backend_may_use_rela_p 0
10335 #define elf_backend_default_use_rela_p 0
10336 #define elf_backend_sign_extend_vma true
10338 #define elf_backend_discard_info _bfd_elf32_mips_discard_info
10339 #define elf_backend_ignore_discarded_relocs \
10340 _bfd_elf32_mips_ignore_discarded_relocs
10341 #define elf_backend_write_section _bfd_elf32_mips_write_section
10343 #define bfd_elf32_bfd_is_local_label_name \
10344 mips_elf_is_local_label_name
10345 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
10346 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
10347 #define bfd_elf32_bfd_link_hash_table_create \
10348 _bfd_mips_elf_link_hash_table_create
10349 #define bfd_elf32_bfd_final_link _bfd_mips_elf_final_link
10350 #define bfd_elf32_bfd_merge_private_bfd_data \
10351 _bfd_mips_elf_merge_private_bfd_data
10352 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
10353 #define bfd_elf32_bfd_print_private_bfd_data \
10354 _bfd_mips_elf_print_private_bfd_data
10356 /* Support for SGI-ish mips targets. */
10357 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
10358 #define TARGET_LITTLE_NAME "elf32-littlemips"
10359 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
10360 #define TARGET_BIG_NAME "elf32-bigmips"
10362 #include "elf32-target.h"
10364 /* Support for traditional mips targets. */
10365 #define INCLUDED_TARGET_FILE /* More a type of flag. */
10367 #undef TARGET_LITTLE_SYM
10368 #undef TARGET_LITTLE_NAME
10369 #undef TARGET_BIG_SYM
10370 #undef TARGET_BIG_NAME
10372 #define TARGET_LITTLE_SYM bfd_elf32_tradlittlemips_vec
10373 #define TARGET_LITTLE_NAME "elf32-tradlittlemips"
10374 #define TARGET_BIG_SYM bfd_elf32_tradbigmips_vec
10375 #define TARGET_BIG_NAME "elf32-tradbigmips"
10377 /* Include the target file again for this target */
10378 #include "elf32-target.h"