1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 94, 95, 96, 97, 98, 1999 Free Software Foundation, Inc.
4 Most of the information added by Ian Lance Taylor, Cygnus Support,
6 N32/64 ABI support added by Mark Mitchell, CodeSourcery, LLC.
7 <mark@codesourcery.com>
9 This file is part of BFD, the Binary File Descriptor library.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 /* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
26 different MIPS ELF from other targets. This matters when linking.
27 This file supports both, switching at runtime. */
37 /* Get the ECOFF swapping routines. */
39 #include "coff/symconst.h"
40 #include "coff/internal.h"
41 #include "coff/ecoff.h"
42 #include "coff/mips.h"
43 #define ECOFF_SIGNED_32
44 #include "ecoffswap.h"
46 /* This structure is used to hold .got information when linking. It
47 is stored in the tdata field of the bfd_elf_section_data structure. */
51 /* The global symbol in the GOT with the lowest index in the dynamic
53 struct elf_link_hash_entry
*global_gotsym
;
54 /* The number of global .got entries. */
55 unsigned int global_gotno
;
56 /* The number of local .got entries. */
57 unsigned int local_gotno
;
58 /* The number of local .got entries we have used. */
59 unsigned int assigned_gotno
;
62 /* The MIPS ELF linker needs additional information for each symbol in
63 the global hash table. */
65 struct mips_elf_link_hash_entry
67 struct elf_link_hash_entry root
;
69 /* External symbol information. */
72 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
74 unsigned int possibly_dynamic_relocs
;
76 /* The index of the first dynamic relocation (in the .rel.dyn
77 section) against this symbol. */
78 unsigned int min_dyn_reloc_index
;
80 /* If there is a stub that 32 bit functions should use to call this
81 16 bit function, this points to the section containing the stub. */
84 /* Whether we need the fn_stub; this is set if this symbol appears
85 in any relocs other than a 16 bit call. */
88 /* If there is a stub that 16 bit functions should use to call this
89 32 bit function, this points to the section containing the stub. */
92 /* This is like the call_stub field, but it is used if the function
93 being called returns a floating point value. */
94 asection
*call_fp_stub
;
97 static bfd_reloc_status_type mips32_64bit_reloc
98 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
99 static reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
100 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
101 static reloc_howto_type
*mips_rtype_to_howto
102 PARAMS ((unsigned int));
103 static void mips_info_to_howto_rel
104 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
105 static void mips_info_to_howto_rela
106 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rela
*));
107 static void bfd_mips_elf32_swap_gptab_in
108 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
109 static void bfd_mips_elf32_swap_gptab_out
110 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
112 static void bfd_mips_elf_swap_msym_in
113 PARAMS ((bfd
*, const Elf32_External_Msym
*, Elf32_Internal_Msym
*));
115 static void bfd_mips_elf_swap_msym_out
116 PARAMS ((bfd
*, const Elf32_Internal_Msym
*, Elf32_External_Msym
*));
117 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
118 static boolean mips_elf_create_procedure_table
119 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
120 struct ecoff_debug_info
*));
121 static INLINE
int elf_mips_isa
PARAMS ((flagword
));
122 static INLINE
int elf_mips_mach
PARAMS ((flagword
));
123 static INLINE
char* elf_mips_abi_name
PARAMS ((bfd
*));
124 static boolean mips_elf_is_local_label_name
125 PARAMS ((bfd
*, const char *));
126 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
127 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
128 static int gptab_compare
PARAMS ((const void *, const void *));
129 static bfd_reloc_status_type mips16_jump_reloc
130 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
131 static bfd_reloc_status_type mips16_gprel_reloc
132 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
133 static boolean mips_elf_create_compact_rel_section
134 PARAMS ((bfd
*, struct bfd_link_info
*));
135 static boolean mips_elf_create_got_section
136 PARAMS ((bfd
*, struct bfd_link_info
*));
137 static bfd_reloc_status_type mips_elf_final_gp
138 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
139 static bfd_byte
*elf32_mips_get_relocated_section_contents
140 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
141 bfd_byte
*, boolean
, asymbol
**));
142 static asection
*mips_elf_create_msym_section
144 static void mips_elf_irix6_finish_dynamic_symbol
145 PARAMS ((bfd
*, const char *, Elf_Internal_Sym
*));
146 static bfd_vma mips_elf_sign_extend
PARAMS ((bfd_vma
, int));
147 static boolean mips_elf_overflow_p
PARAMS ((bfd_vma
, int));
148 static bfd_vma mips_elf_high
PARAMS ((bfd_vma
));
149 static bfd_vma mips_elf_higher
PARAMS ((bfd_vma
));
150 static bfd_vma mips_elf_highest
PARAMS ((bfd_vma
));
151 static bfd_vma mips_elf_global_got_index
152 PARAMS ((bfd
*, struct elf_link_hash_entry
*));
153 static bfd_vma mips_elf_local_got_index
154 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
));
155 static bfd_vma mips_elf_got_offset_from_index
156 PARAMS ((bfd
*, bfd
*, bfd_vma
));
157 static boolean mips_elf_record_global_got_symbol
158 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*,
159 struct mips_got_info
*));
160 static bfd_vma mips_elf_got_page
161 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
, bfd_vma
*));
162 static const Elf_Internal_Rela
*mips_elf_next_relocation
163 PARAMS ((unsigned int, const Elf_Internal_Rela
*,
164 const Elf_Internal_Rela
*));
165 static bfd_reloc_status_type mips_elf_calculate_relocation
166 PARAMS ((bfd
*, bfd
*, asection
*, struct bfd_link_info
*,
167 const Elf_Internal_Rela
*, bfd_vma
, reloc_howto_type
*,
168 Elf_Internal_Sym
*, asection
**, bfd_vma
*, const char **,
170 static bfd_vma mips_elf_obtain_contents
171 PARAMS ((reloc_howto_type
*, const Elf_Internal_Rela
*, bfd
*, bfd_byte
*));
172 static boolean mips_elf_perform_relocation
173 PARAMS ((struct bfd_link_info
*, reloc_howto_type
*,
174 const Elf_Internal_Rela
*, bfd_vma
,
175 bfd
*, asection
*, bfd_byte
*, boolean
));
176 static boolean mips_elf_assign_gp
PARAMS ((bfd
*, bfd_vma
*));
177 static boolean mips_elf_sort_hash_table_f
178 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
179 static boolean mips_elf_sort_hash_table
180 PARAMS ((struct bfd_link_info
*, unsigned long));
181 static asection
* mips_elf_got_section
PARAMS ((bfd
*));
182 static struct mips_got_info
*mips_elf_got_info
183 PARAMS ((bfd
*, asection
**));
184 static boolean mips_elf_local_relocation_p
185 PARAMS ((bfd
*, const Elf_Internal_Rela
*, asection
**, boolean
));
186 static bfd_vma mips_elf_create_local_got_entry
187 PARAMS ((bfd
*, struct mips_got_info
*, asection
*, bfd_vma
));
188 static bfd_vma mips_elf_got16_entry
189 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
, boolean
));
190 static boolean mips_elf_create_dynamic_relocation
191 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
192 struct mips_elf_link_hash_entry
*, asection
*,
193 bfd_vma
, bfd_vma
*, asection
*));
194 static void mips_elf_allocate_dynamic_relocations
195 PARAMS ((bfd
*, unsigned int));
196 static boolean mips_elf_stub_section_p
197 PARAMS ((bfd
*, asection
*));
198 static int sort_dynamic_relocs
199 PARAMS ((const void *, const void *));
201 /* The level of IRIX compatibility we're striving for. */
209 /* This will be used when we sort the dynamic relocation records. */
210 static bfd
*reldyn_sorting_bfd
;
212 /* Nonzero if ABFD is using the N32 ABI. */
214 #define ABI_N32_P(abfd) \
215 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
217 /* Nonzero if ABFD is using the 64-bit ABI. FIXME: This is never
219 #define ABI_64_P(abfd) \
220 ((elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS64) != 0)
222 /* What version of Irix we are trying to be compatible with. FIXME:
223 At the moment, we never generate "normal" MIPS ELF ABI executables;
224 we always use some version of Irix. */
226 #define IRIX_COMPAT(abfd) \
227 ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5)
229 /* Whether we are trying to be compatible with IRIX at all. */
231 #define SGI_COMPAT(abfd) \
232 (IRIX_COMPAT (abfd) != ict_none)
234 /* The name of the msym section. */
235 #define MIPS_ELF_MSYM_SECTION_NAME(abfd) ".msym"
237 /* The name of the srdata section. */
238 #define MIPS_ELF_SRDATA_SECTION_NAME(abfd) ".srdata"
240 /* The name of the options section. */
241 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
242 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.options" : ".options")
244 /* The name of the stub section. */
245 #define MIPS_ELF_STUB_SECTION_NAME(abfd) \
246 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.stubs" : ".stub")
248 /* The name of the dynamic relocation section. */
249 #define MIPS_ELF_REL_DYN_SECTION_NAME(abfd) ".rel.dyn"
251 /* The size of an external REL relocation. */
252 #define MIPS_ELF_REL_SIZE(abfd) \
253 (get_elf_backend_data (abfd)->s->sizeof_rel)
255 /* The size of an external dynamic table entry. */
256 #define MIPS_ELF_DYN_SIZE(abfd) \
257 (get_elf_backend_data (abfd)->s->sizeof_dyn)
259 /* The size of a GOT entry. */
260 #define MIPS_ELF_GOT_SIZE(abfd) \
261 (get_elf_backend_data (abfd)->s->arch_size / 8)
263 /* The size of a symbol-table entry. */
264 #define MIPS_ELF_SYM_SIZE(abfd) \
265 (get_elf_backend_data (abfd)->s->sizeof_sym)
267 /* The default alignment for sections, as a power of two. */
268 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
269 (get_elf_backend_data (abfd)->s->file_align == 8 ? 3 : 2)
271 /* Get word-sized data. */
272 #define MIPS_ELF_GET_WORD(abfd, ptr) \
273 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
275 /* Put out word-sized data. */
276 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
278 ? bfd_put_64 (abfd, val, ptr) \
279 : bfd_put_32 (abfd, val, ptr))
281 /* Add a dynamic symbol table-entry. */
283 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
284 (ABI_64_P (elf_hash_table (info)->dynobj) \
285 ? bfd_elf64_add_dynamic_entry (info, tag, val) \
286 : bfd_elf32_add_dynamic_entry (info, tag, val))
288 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
289 (ABI_64_P (elf_hash_table (info)->dynobj) \
290 ? (abort (), false) \
291 : bfd_elf32_add_dynamic_entry (info, tag, val))
294 /* The number of local .got entries we reserve. */
295 #define MIPS_RESERVED_GOTNO (2)
297 /* Instructions which appear in a stub. For some reason the stub is
298 slightly different on an SGI system. */
299 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
300 #define STUB_LW(abfd) \
303 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
304 : 0x8f998010) /* lw t9,0x8010(gp) */ \
305 : 0x8f998000) /* lw t9,0x8000(gp) */
306 #define STUB_MOVE 0x03e07825 /* move t7,ra */
307 #define STUB_JALR 0x0320f809 /* jal t9 */
308 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
309 #define MIPS_FUNCTION_STUB_SIZE (16)
312 /* We no longer try to identify particular sections for the .dynsym
313 section. When we do, we wind up crashing if there are other random
314 sections with relocations. */
316 /* Names of sections which appear in the .dynsym section in an Irix 5
319 static const char * const mips_elf_dynsym_sec_names
[] =
332 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
333 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
335 /* The number of entries in mips_elf_dynsym_sec_names which go in the
338 #define MIPS_TEXT_DYNSYM_SECNO (3)
342 /* The names of the runtime procedure table symbols used on Irix 5. */
344 static const char * const mips_elf_dynsym_rtproc_names
[] =
347 "_procedure_string_table",
348 "_procedure_table_size",
352 /* These structures are used to generate the .compact_rel section on
357 unsigned long id1
; /* Always one? */
358 unsigned long num
; /* Number of compact relocation entries. */
359 unsigned long id2
; /* Always two? */
360 unsigned long offset
; /* The file offset of the first relocation. */
361 unsigned long reserved0
; /* Zero? */
362 unsigned long reserved1
; /* Zero? */
371 bfd_byte reserved0
[4];
372 bfd_byte reserved1
[4];
373 } Elf32_External_compact_rel
;
377 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
378 unsigned int rtype
: 4; /* Relocation types. See below. */
379 unsigned int dist2to
: 8;
380 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
381 unsigned long konst
; /* KONST field. See below. */
382 unsigned long vaddr
; /* VADDR to be relocated. */
387 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
388 unsigned int rtype
: 4; /* Relocation types. See below. */
389 unsigned int dist2to
: 8;
390 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
391 unsigned long konst
; /* KONST field. See below. */
399 } Elf32_External_crinfo
;
405 } Elf32_External_crinfo2
;
407 /* These are the constants used to swap the bitfields in a crinfo. */
409 #define CRINFO_CTYPE (0x1)
410 #define CRINFO_CTYPE_SH (31)
411 #define CRINFO_RTYPE (0xf)
412 #define CRINFO_RTYPE_SH (27)
413 #define CRINFO_DIST2TO (0xff)
414 #define CRINFO_DIST2TO_SH (19)
415 #define CRINFO_RELVADDR (0x7ffff)
416 #define CRINFO_RELVADDR_SH (0)
418 /* A compact relocation info has long (3 words) or short (2 words)
419 formats. A short format doesn't have VADDR field and relvaddr
420 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
421 #define CRF_MIPS_LONG 1
422 #define CRF_MIPS_SHORT 0
424 /* There are 4 types of compact relocation at least. The value KONST
425 has different meaning for each type:
428 CT_MIPS_REL32 Address in data
429 CT_MIPS_WORD Address in word (XXX)
430 CT_MIPS_GPHI_LO GP - vaddr
431 CT_MIPS_JMPAD Address to jump
434 #define CRT_MIPS_REL32 0xa
435 #define CRT_MIPS_WORD 0xb
436 #define CRT_MIPS_GPHI_LO 0xc
437 #define CRT_MIPS_JMPAD 0xd
439 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
440 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
441 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
442 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
444 static void bfd_elf32_swap_compact_rel_out
445 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
446 static void bfd_elf32_swap_crinfo_out
447 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
449 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
451 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
452 from smaller values. Start with zero, widen, *then* decrement. */
453 #define MINUS_ONE (((bfd_vma)0) - 1)
455 static reloc_howto_type elf_mips_howto_table
[] =
458 HOWTO (R_MIPS_NONE
, /* type */
460 0, /* size (0 = byte, 1 = short, 2 = long) */
462 false, /* pc_relative */
464 complain_overflow_dont
, /* complain_on_overflow */
465 bfd_elf_generic_reloc
, /* special_function */
466 "R_MIPS_NONE", /* name */
467 false, /* partial_inplace */
470 false), /* pcrel_offset */
472 /* 16 bit relocation. */
473 HOWTO (R_MIPS_16
, /* type */
475 1, /* size (0 = byte, 1 = short, 2 = long) */
477 false, /* pc_relative */
479 complain_overflow_bitfield
, /* complain_on_overflow */
480 bfd_elf_generic_reloc
, /* special_function */
481 "R_MIPS_16", /* name */
482 true, /* partial_inplace */
483 0xffff, /* src_mask */
484 0xffff, /* dst_mask */
485 false), /* pcrel_offset */
487 /* 32 bit relocation. */
488 HOWTO (R_MIPS_32
, /* type */
490 2, /* size (0 = byte, 1 = short, 2 = long) */
492 false, /* pc_relative */
494 complain_overflow_bitfield
, /* complain_on_overflow */
495 bfd_elf_generic_reloc
, /* special_function */
496 "R_MIPS_32", /* name */
497 true, /* partial_inplace */
498 0xffffffff, /* src_mask */
499 0xffffffff, /* dst_mask */
500 false), /* pcrel_offset */
502 /* 32 bit symbol relative relocation. */
503 HOWTO (R_MIPS_REL32
, /* type */
505 2, /* size (0 = byte, 1 = short, 2 = long) */
507 false, /* pc_relative */
509 complain_overflow_bitfield
, /* complain_on_overflow */
510 bfd_elf_generic_reloc
, /* special_function */
511 "R_MIPS_REL32", /* name */
512 true, /* partial_inplace */
513 0xffffffff, /* src_mask */
514 0xffffffff, /* dst_mask */
515 false), /* pcrel_offset */
517 /* 26 bit branch address. */
518 HOWTO (R_MIPS_26
, /* type */
520 2, /* size (0 = byte, 1 = short, 2 = long) */
522 false, /* pc_relative */
524 complain_overflow_dont
, /* complain_on_overflow */
525 /* This needs complex overflow
526 detection, because the upper four
527 bits must match the PC. */
528 bfd_elf_generic_reloc
, /* special_function */
529 "R_MIPS_26", /* name */
530 true, /* partial_inplace */
531 0x3ffffff, /* src_mask */
532 0x3ffffff, /* dst_mask */
533 false), /* pcrel_offset */
535 /* High 16 bits of symbol value. */
536 HOWTO (R_MIPS_HI16
, /* type */
538 2, /* size (0 = byte, 1 = short, 2 = long) */
540 false, /* pc_relative */
542 complain_overflow_dont
, /* complain_on_overflow */
543 _bfd_mips_elf_hi16_reloc
, /* special_function */
544 "R_MIPS_HI16", /* name */
545 true, /* partial_inplace */
546 0xffff, /* src_mask */
547 0xffff, /* dst_mask */
548 false), /* pcrel_offset */
550 /* Low 16 bits of symbol value. */
551 HOWTO (R_MIPS_LO16
, /* type */
553 2, /* size (0 = byte, 1 = short, 2 = long) */
555 false, /* pc_relative */
557 complain_overflow_dont
, /* complain_on_overflow */
558 _bfd_mips_elf_lo16_reloc
, /* special_function */
559 "R_MIPS_LO16", /* name */
560 true, /* partial_inplace */
561 0xffff, /* src_mask */
562 0xffff, /* dst_mask */
563 false), /* pcrel_offset */
565 /* GP relative reference. */
566 HOWTO (R_MIPS_GPREL16
, /* type */
568 2, /* size (0 = byte, 1 = short, 2 = long) */
570 false, /* pc_relative */
572 complain_overflow_signed
, /* complain_on_overflow */
573 _bfd_mips_elf_gprel16_reloc
, /* special_function */
574 "R_MIPS_GPREL16", /* name */
575 true, /* partial_inplace */
576 0xffff, /* src_mask */
577 0xffff, /* dst_mask */
578 false), /* pcrel_offset */
580 /* Reference to literal section. */
581 HOWTO (R_MIPS_LITERAL
, /* type */
583 2, /* size (0 = byte, 1 = short, 2 = long) */
585 false, /* pc_relative */
587 complain_overflow_signed
, /* complain_on_overflow */
588 _bfd_mips_elf_gprel16_reloc
, /* special_function */
589 "R_MIPS_LITERAL", /* name */
590 true, /* partial_inplace */
591 0xffff, /* src_mask */
592 0xffff, /* dst_mask */
593 false), /* pcrel_offset */
595 /* Reference to global offset table. */
596 HOWTO (R_MIPS_GOT16
, /* type */
598 2, /* size (0 = byte, 1 = short, 2 = long) */
600 false, /* pc_relative */
602 complain_overflow_signed
, /* complain_on_overflow */
603 _bfd_mips_elf_got16_reloc
, /* special_function */
604 "R_MIPS_GOT16", /* name */
605 false, /* partial_inplace */
606 0xffff, /* src_mask */
607 0xffff, /* dst_mask */
608 false), /* pcrel_offset */
610 /* 16 bit PC relative reference. */
611 HOWTO (R_MIPS_PC16
, /* type */
613 2, /* size (0 = byte, 1 = short, 2 = long) */
615 true, /* pc_relative */
617 complain_overflow_signed
, /* complain_on_overflow */
618 bfd_elf_generic_reloc
, /* special_function */
619 "R_MIPS_PC16", /* name */
620 true, /* partial_inplace */
621 0xffff, /* src_mask */
622 0xffff, /* dst_mask */
623 true), /* pcrel_offset */
625 /* 16 bit call through global offset table. */
626 HOWTO (R_MIPS_CALL16
, /* type */
628 2, /* size (0 = byte, 1 = short, 2 = long) */
630 false, /* pc_relative */
632 complain_overflow_signed
, /* complain_on_overflow */
633 bfd_elf_generic_reloc
, /* special_function */
634 "R_MIPS_CALL16", /* name */
635 false, /* partial_inplace */
636 0xffff, /* src_mask */
637 0xffff, /* dst_mask */
638 false), /* pcrel_offset */
640 /* 32 bit GP relative reference. */
641 HOWTO (R_MIPS_GPREL32
, /* type */
643 2, /* size (0 = byte, 1 = short, 2 = long) */
645 false, /* pc_relative */
647 complain_overflow_bitfield
, /* complain_on_overflow */
648 _bfd_mips_elf_gprel32_reloc
, /* special_function */
649 "R_MIPS_GPREL32", /* name */
650 true, /* partial_inplace */
651 0xffffffff, /* src_mask */
652 0xffffffff, /* dst_mask */
653 false), /* pcrel_offset */
655 /* The remaining relocs are defined on Irix 5, although they are
656 not defined by the ABI. */
661 /* A 5 bit shift field. */
662 HOWTO (R_MIPS_SHIFT5
, /* type */
664 2, /* size (0 = byte, 1 = short, 2 = long) */
666 false, /* pc_relative */
668 complain_overflow_bitfield
, /* complain_on_overflow */
669 bfd_elf_generic_reloc
, /* special_function */
670 "R_MIPS_SHIFT5", /* name */
671 true, /* partial_inplace */
672 0x000007c0, /* src_mask */
673 0x000007c0, /* dst_mask */
674 false), /* pcrel_offset */
676 /* A 6 bit shift field. */
677 /* FIXME: This is not handled correctly; a special function is
678 needed to put the most significant bit in the right place. */
679 HOWTO (R_MIPS_SHIFT6
, /* type */
681 2, /* size (0 = byte, 1 = short, 2 = long) */
683 false, /* pc_relative */
685 complain_overflow_bitfield
, /* complain_on_overflow */
686 bfd_elf_generic_reloc
, /* special_function */
687 "R_MIPS_SHIFT6", /* name */
688 true, /* partial_inplace */
689 0x000007c4, /* src_mask */
690 0x000007c4, /* dst_mask */
691 false), /* pcrel_offset */
693 /* A 64 bit relocation. */
694 HOWTO (R_MIPS_64
, /* type */
696 4, /* size (0 = byte, 1 = short, 2 = long) */
698 false, /* pc_relative */
700 complain_overflow_bitfield
, /* complain_on_overflow */
701 mips32_64bit_reloc
, /* special_function */
702 "R_MIPS_64", /* name */
703 true, /* partial_inplace */
704 MINUS_ONE
, /* src_mask */
705 MINUS_ONE
, /* dst_mask */
706 false), /* pcrel_offset */
708 /* Displacement in the global offset table. */
709 HOWTO (R_MIPS_GOT_DISP
, /* type */
711 2, /* size (0 = byte, 1 = short, 2 = long) */
713 false, /* pc_relative */
715 complain_overflow_bitfield
, /* complain_on_overflow */
716 bfd_elf_generic_reloc
, /* special_function */
717 "R_MIPS_GOT_DISP", /* name */
718 true, /* partial_inplace */
719 0x0000ffff, /* src_mask */
720 0x0000ffff, /* dst_mask */
721 false), /* pcrel_offset */
723 /* Displacement to page pointer in the global offset table. */
724 HOWTO (R_MIPS_GOT_PAGE
, /* type */
726 2, /* size (0 = byte, 1 = short, 2 = long) */
728 false, /* pc_relative */
730 complain_overflow_bitfield
, /* complain_on_overflow */
731 bfd_elf_generic_reloc
, /* special_function */
732 "R_MIPS_GOT_PAGE", /* name */
733 true, /* partial_inplace */
734 0x0000ffff, /* src_mask */
735 0x0000ffff, /* dst_mask */
736 false), /* pcrel_offset */
738 /* Offset from page pointer in the global offset table. */
739 HOWTO (R_MIPS_GOT_OFST
, /* type */
741 2, /* size (0 = byte, 1 = short, 2 = long) */
743 false, /* pc_relative */
745 complain_overflow_bitfield
, /* complain_on_overflow */
746 bfd_elf_generic_reloc
, /* special_function */
747 "R_MIPS_GOT_OFST", /* name */
748 true, /* partial_inplace */
749 0x0000ffff, /* src_mask */
750 0x0000ffff, /* dst_mask */
751 false), /* pcrel_offset */
753 /* High 16 bits of displacement in global offset table. */
754 HOWTO (R_MIPS_GOT_HI16
, /* type */
756 2, /* size (0 = byte, 1 = short, 2 = long) */
758 false, /* pc_relative */
760 complain_overflow_dont
, /* complain_on_overflow */
761 bfd_elf_generic_reloc
, /* special_function */
762 "R_MIPS_GOT_HI16", /* name */
763 true, /* partial_inplace */
764 0x0000ffff, /* src_mask */
765 0x0000ffff, /* dst_mask */
766 false), /* pcrel_offset */
768 /* Low 16 bits of displacement in global offset table. */
769 HOWTO (R_MIPS_GOT_LO16
, /* type */
771 2, /* size (0 = byte, 1 = short, 2 = long) */
773 false, /* pc_relative */
775 complain_overflow_dont
, /* complain_on_overflow */
776 bfd_elf_generic_reloc
, /* special_function */
777 "R_MIPS_GOT_LO16", /* name */
778 true, /* partial_inplace */
779 0x0000ffff, /* src_mask */
780 0x0000ffff, /* dst_mask */
781 false), /* pcrel_offset */
783 /* 64 bit subtraction. Used in the N32 ABI. */
784 HOWTO (R_MIPS_SUB
, /* type */
786 4, /* size (0 = byte, 1 = short, 2 = long) */
788 false, /* pc_relative */
790 complain_overflow_bitfield
, /* complain_on_overflow */
791 bfd_elf_generic_reloc
, /* special_function */
792 "R_MIPS_SUB", /* name */
793 true, /* partial_inplace */
794 MINUS_ONE
, /* src_mask */
795 MINUS_ONE
, /* dst_mask */
796 false), /* pcrel_offset */
798 /* Used to cause the linker to insert and delete instructions? */
799 EMPTY_HOWTO (R_MIPS_INSERT_A
),
800 EMPTY_HOWTO (R_MIPS_INSERT_B
),
801 EMPTY_HOWTO (R_MIPS_DELETE
),
803 /* Get the higher value of a 64 bit addend. */
804 HOWTO (R_MIPS_HIGHER
, /* type */
806 2, /* size (0 = byte, 1 = short, 2 = long) */
808 false, /* pc_relative */
810 complain_overflow_dont
, /* complain_on_overflow */
811 bfd_elf_generic_reloc
, /* special_function */
812 "R_MIPS_HIGHER", /* name */
813 true, /* partial_inplace */
815 0xffff, /* dst_mask */
816 false), /* pcrel_offset */
818 /* Get the highest value of a 64 bit addend. */
819 HOWTO (R_MIPS_HIGHEST
, /* type */
821 2, /* size (0 = byte, 1 = short, 2 = long) */
823 false, /* pc_relative */
825 complain_overflow_dont
, /* complain_on_overflow */
826 bfd_elf_generic_reloc
, /* special_function */
827 "R_MIPS_HIGHEST", /* name */
828 true, /* partial_inplace */
830 0xffff, /* dst_mask */
831 false), /* pcrel_offset */
833 /* High 16 bits of displacement in global offset table. */
834 HOWTO (R_MIPS_CALL_HI16
, /* type */
836 2, /* size (0 = byte, 1 = short, 2 = long) */
838 false, /* pc_relative */
840 complain_overflow_dont
, /* complain_on_overflow */
841 bfd_elf_generic_reloc
, /* special_function */
842 "R_MIPS_CALL_HI16", /* name */
843 true, /* partial_inplace */
844 0x0000ffff, /* src_mask */
845 0x0000ffff, /* dst_mask */
846 false), /* pcrel_offset */
848 /* Low 16 bits of displacement in global offset table. */
849 HOWTO (R_MIPS_CALL_LO16
, /* type */
851 2, /* size (0 = byte, 1 = short, 2 = long) */
853 false, /* pc_relative */
855 complain_overflow_dont
, /* complain_on_overflow */
856 bfd_elf_generic_reloc
, /* special_function */
857 "R_MIPS_CALL_LO16", /* name */
858 true, /* partial_inplace */
859 0x0000ffff, /* src_mask */
860 0x0000ffff, /* dst_mask */
861 false), /* pcrel_offset */
863 /* Section displacement. */
864 HOWTO (R_MIPS_SCN_DISP
, /* type */
866 2, /* size (0 = byte, 1 = short, 2 = long) */
868 false, /* pc_relative */
870 complain_overflow_dont
, /* complain_on_overflow */
871 bfd_elf_generic_reloc
, /* special_function */
872 "R_MIPS_SCN_DISP", /* name */
873 false, /* partial_inplace */
874 0xffffffff, /* src_mask */
875 0xffffffff, /* dst_mask */
876 false), /* pcrel_offset */
878 EMPTY_HOWTO (R_MIPS_REL16
),
879 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE
),
880 EMPTY_HOWTO (R_MIPS_PJUMP
),
881 EMPTY_HOWTO (R_MIPS_RELGOT
),
883 /* Protected jump conversion. This is an optimization hint. No
884 relocation is required for correctness. */
885 HOWTO (R_MIPS_JALR
, /* type */
887 0, /* size (0 = byte, 1 = short, 2 = long) */
889 false, /* pc_relative */
891 complain_overflow_dont
, /* complain_on_overflow */
892 bfd_elf_generic_reloc
, /* special_function */
893 "R_MIPS_JALR", /* name */
894 false, /* partial_inplace */
895 0x00000000, /* src_mask */
896 0x00000000, /* dst_mask */
897 false), /* pcrel_offset */
900 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
901 is a hack to make the linker think that we need 64 bit values. */
902 static reloc_howto_type elf_mips_ctor64_howto
=
903 HOWTO (R_MIPS_64
, /* type */
905 4, /* size (0 = byte, 1 = short, 2 = long) */
907 false, /* pc_relative */
909 complain_overflow_signed
, /* complain_on_overflow */
910 mips32_64bit_reloc
, /* special_function */
911 "R_MIPS_64", /* name */
912 true, /* partial_inplace */
913 0xffffffff, /* src_mask */
914 0xffffffff, /* dst_mask */
915 false); /* pcrel_offset */
917 /* The reloc used for the mips16 jump instruction. */
918 static reloc_howto_type elf_mips16_jump_howto
=
919 HOWTO (R_MIPS16_26
, /* type */
921 2, /* size (0 = byte, 1 = short, 2 = long) */
923 false, /* pc_relative */
925 complain_overflow_dont
, /* complain_on_overflow */
926 /* This needs complex overflow
927 detection, because the upper four
928 bits must match the PC. */
929 mips16_jump_reloc
, /* special_function */
930 "R_MIPS16_26", /* name */
931 true, /* partial_inplace */
932 0x3ffffff, /* src_mask */
933 0x3ffffff, /* dst_mask */
934 false); /* pcrel_offset */
936 /* The reloc used for the mips16 gprel instruction. */
937 static reloc_howto_type elf_mips16_gprel_howto
=
938 HOWTO (R_MIPS16_GPREL
, /* type */
940 2, /* size (0 = byte, 1 = short, 2 = long) */
942 false, /* pc_relative */
944 complain_overflow_signed
, /* complain_on_overflow */
945 mips16_gprel_reloc
, /* special_function */
946 "R_MIPS16_GPREL", /* name */
947 true, /* partial_inplace */
948 0x07ff001f, /* src_mask */
949 0x07ff001f, /* dst_mask */
950 false); /* pcrel_offset */
952 /* GNU extensions for embedded-pic. */
953 /* High 16 bits of symbol value, pc-relative. */
954 static reloc_howto_type elf_mips_gnu_rel_hi16
=
955 HOWTO (R_MIPS_GNU_REL_HI16
, /* type */
957 2, /* size (0 = byte, 1 = short, 2 = long) */
959 true, /* pc_relative */
961 complain_overflow_dont
, /* complain_on_overflow */
962 _bfd_mips_elf_hi16_reloc
, /* special_function */
963 "R_MIPS_GNU_REL_HI16", /* name */
964 true, /* partial_inplace */
965 0xffff, /* src_mask */
966 0xffff, /* dst_mask */
967 true); /* pcrel_offset */
969 /* Low 16 bits of symbol value, pc-relative. */
970 static reloc_howto_type elf_mips_gnu_rel_lo16
=
971 HOWTO (R_MIPS_GNU_REL_LO16
, /* type */
973 2, /* size (0 = byte, 1 = short, 2 = long) */
975 true, /* pc_relative */
977 complain_overflow_dont
, /* complain_on_overflow */
978 _bfd_mips_elf_lo16_reloc
, /* special_function */
979 "R_MIPS_GNU_REL_LO16", /* name */
980 true, /* partial_inplace */
981 0xffff, /* src_mask */
982 0xffff, /* dst_mask */
983 true); /* pcrel_offset */
985 /* 16 bit offset for pc-relative branches. */
986 static reloc_howto_type elf_mips_gnu_rel16_s2
=
987 HOWTO (R_MIPS_GNU_REL16_S2
, /* type */
989 2, /* size (0 = byte, 1 = short, 2 = long) */
991 true, /* pc_relative */
993 complain_overflow_signed
, /* complain_on_overflow */
994 bfd_elf_generic_reloc
, /* special_function */
995 "R_MIPS_GNU_REL16_S2", /* name */
996 true, /* partial_inplace */
997 0xffff, /* src_mask */
998 0xffff, /* dst_mask */
999 true); /* pcrel_offset */
1001 /* 64 bit pc-relative. */
1002 static reloc_howto_type elf_mips_gnu_pcrel64
=
1003 HOWTO (R_MIPS_PC64
, /* type */
1005 4, /* size (0 = byte, 1 = short, 2 = long) */
1007 true, /* pc_relative */
1009 complain_overflow_signed
, /* complain_on_overflow */
1010 bfd_elf_generic_reloc
, /* special_function */
1011 "R_MIPS_PC64", /* name */
1012 true, /* partial_inplace */
1013 MINUS_ONE
, /* src_mask */
1014 MINUS_ONE
, /* dst_mask */
1015 true); /* pcrel_offset */
1017 /* 32 bit pc-relative. */
1018 static reloc_howto_type elf_mips_gnu_pcrel32
=
1019 HOWTO (R_MIPS_PC32
, /* type */
1021 2, /* size (0 = byte, 1 = short, 2 = long) */
1023 true, /* pc_relative */
1025 complain_overflow_signed
, /* complain_on_overflow */
1026 bfd_elf_generic_reloc
, /* special_function */
1027 "R_MIPS_PC32", /* name */
1028 true, /* partial_inplace */
1029 0xffffffff, /* src_mask */
1030 0xffffffff, /* dst_mask */
1031 true); /* pcrel_offset */
1033 /* GNU extension to record C++ vtable hierarchy */
1034 static reloc_howto_type elf_mips_gnu_vtinherit_howto
=
1035 HOWTO (R_MIPS_GNU_VTINHERIT
, /* type */
1037 2, /* size (0 = byte, 1 = short, 2 = long) */
1039 false, /* pc_relative */
1041 complain_overflow_dont
, /* complain_on_overflow */
1042 NULL
, /* special_function */
1043 "R_MIPS_GNU_VTINHERIT", /* name */
1044 false, /* partial_inplace */
1047 false); /* pcrel_offset */
1049 /* GNU extension to record C++ vtable member usage */
1050 static reloc_howto_type elf_mips_gnu_vtentry_howto
=
1051 HOWTO (R_MIPS_GNU_VTENTRY
, /* type */
1053 2, /* size (0 = byte, 1 = short, 2 = long) */
1055 false, /* pc_relative */
1057 complain_overflow_dont
, /* complain_on_overflow */
1058 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
1059 "R_MIPS_GNU_VTENTRY", /* name */
1060 false, /* partial_inplace */
1063 false); /* pcrel_offset */
1065 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
1066 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
1067 the HI16. Here we just save the information we need; we do the
1068 actual relocation when we see the LO16. MIPS ELF requires that the
1069 LO16 immediately follow the HI16. As a GNU extension, we permit an
1070 arbitrary number of HI16 relocs to be associated with a single LO16
1071 reloc. This extension permits gcc to output the HI and LO relocs
1076 struct mips_hi16
*next
;
1081 /* FIXME: This should not be a static variable. */
1083 static struct mips_hi16
*mips_hi16_list
;
1085 bfd_reloc_status_type
1086 _bfd_mips_elf_hi16_reloc (abfd
,
1093 bfd
*abfd ATTRIBUTE_UNUSED
;
1094 arelent
*reloc_entry
;
1097 asection
*input_section
;
1099 char **error_message
;
1101 bfd_reloc_status_type ret
;
1103 struct mips_hi16
*n
;
1105 /* If we're relocating, and this an external symbol, we don't want
1106 to change anything. */
1107 if (output_bfd
!= (bfd
*) NULL
1108 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1109 && reloc_entry
->addend
== 0)
1111 reloc_entry
->address
+= input_section
->output_offset
;
1112 return bfd_reloc_ok
;
1117 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1119 boolean relocateable
;
1122 if (ret
== bfd_reloc_undefined
)
1125 if (output_bfd
!= NULL
)
1126 relocateable
= true;
1129 relocateable
= false;
1130 output_bfd
= symbol
->section
->output_section
->owner
;
1133 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1134 error_message
, &gp
);
1135 if (ret
!= bfd_reloc_ok
)
1138 relocation
= gp
- reloc_entry
->address
;
1142 if (bfd_is_und_section (symbol
->section
)
1143 && output_bfd
== (bfd
*) NULL
)
1144 ret
= bfd_reloc_undefined
;
1146 if (bfd_is_com_section (symbol
->section
))
1149 relocation
= symbol
->value
;
1152 relocation
+= symbol
->section
->output_section
->vma
;
1153 relocation
+= symbol
->section
->output_offset
;
1154 relocation
+= reloc_entry
->addend
;
1156 if (reloc_entry
->address
> input_section
->_cooked_size
)
1157 return bfd_reloc_outofrange
;
1159 /* Save the information, and let LO16 do the actual relocation. */
1160 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
1162 return bfd_reloc_outofrange
;
1163 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
1164 n
->addend
= relocation
;
1165 n
->next
= mips_hi16_list
;
1168 if (output_bfd
!= (bfd
*) NULL
)
1169 reloc_entry
->address
+= input_section
->output_offset
;
1174 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
1175 inplace relocation; this function exists in order to do the
1176 R_MIPS_HI16 relocation described above. */
1178 bfd_reloc_status_type
1179 _bfd_mips_elf_lo16_reloc (abfd
,
1187 arelent
*reloc_entry
;
1190 asection
*input_section
;
1192 char **error_message
;
1194 arelent gp_disp_relent
;
1196 if (mips_hi16_list
!= NULL
)
1198 struct mips_hi16
*l
;
1205 unsigned long vallo
;
1206 struct mips_hi16
*next
;
1208 /* Do the HI16 relocation. Note that we actually don't need
1209 to know anything about the LO16 itself, except where to
1210 find the low 16 bits of the addend needed by the LO16. */
1211 insn
= bfd_get_32 (abfd
, l
->addr
);
1212 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
1214 val
= ((insn
& 0xffff) << 16) + vallo
;
1217 /* The low order 16 bits are always treated as a signed
1218 value. Therefore, a negative value in the low order bits
1219 requires an adjustment in the high order bits. We need
1220 to make this adjustment in two ways: once for the bits we
1221 took from the data, and once for the bits we are putting
1222 back in to the data. */
1223 if ((vallo
& 0x8000) != 0)
1225 if ((val
& 0x8000) != 0)
1228 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
1229 bfd_put_32 (abfd
, insn
, l
->addr
);
1231 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1233 gp_disp_relent
= *reloc_entry
;
1234 reloc_entry
= &gp_disp_relent
;
1235 reloc_entry
->addend
= l
->addend
;
1243 mips_hi16_list
= NULL
;
1245 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1247 bfd_reloc_status_type ret
;
1248 bfd_vma gp
, relocation
;
1250 /* FIXME: Does this case ever occur? */
1252 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
1253 if (ret
!= bfd_reloc_ok
)
1256 relocation
= gp
- reloc_entry
->address
;
1257 relocation
+= symbol
->section
->output_section
->vma
;
1258 relocation
+= symbol
->section
->output_offset
;
1259 relocation
+= reloc_entry
->addend
;
1261 if (reloc_entry
->address
> input_section
->_cooked_size
)
1262 return bfd_reloc_outofrange
;
1264 gp_disp_relent
= *reloc_entry
;
1265 reloc_entry
= &gp_disp_relent
;
1266 reloc_entry
->addend
= relocation
- 4;
1269 /* Now do the LO16 reloc in the usual way. */
1270 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1271 input_section
, output_bfd
, error_message
);
1274 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1275 table used for PIC code. If the symbol is an external symbol, the
1276 instruction is modified to contain the offset of the appropriate
1277 entry in the global offset table. If the symbol is a section
1278 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1279 addends are combined to form the real addend against the section
1280 symbol; the GOT16 is modified to contain the offset of an entry in
1281 the global offset table, and the LO16 is modified to offset it
1282 appropriately. Thus an offset larger than 16 bits requires a
1283 modified value in the global offset table.
1285 This implementation suffices for the assembler, but the linker does
1286 not yet know how to create global offset tables. */
1288 bfd_reloc_status_type
1289 _bfd_mips_elf_got16_reloc (abfd
,
1297 arelent
*reloc_entry
;
1300 asection
*input_section
;
1302 char **error_message
;
1304 /* If we're relocating, and this an external symbol, we don't want
1305 to change anything. */
1306 if (output_bfd
!= (bfd
*) NULL
1307 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1308 && reloc_entry
->addend
== 0)
1310 reloc_entry
->address
+= input_section
->output_offset
;
1311 return bfd_reloc_ok
;
1314 /* If we're relocating, and this is a local symbol, we can handle it
1316 if (output_bfd
!= (bfd
*) NULL
1317 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1318 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1319 input_section
, output_bfd
, error_message
);
1324 /* Set the GP value for OUTPUT_BFD. Returns false if this is a
1325 dangerous relocation. */
1328 mips_elf_assign_gp (output_bfd
, pgp
)
1336 /* If we've already figured out what GP will be, just return it. */
1337 *pgp
= _bfd_get_gp_value (output_bfd
);
1341 count
= bfd_get_symcount (output_bfd
);
1342 sym
= bfd_get_outsymbols (output_bfd
);
1344 /* The linker script will have created a symbol named `_gp' with the
1345 appropriate value. */
1346 if (sym
== (asymbol
**) NULL
)
1350 for (i
= 0; i
< count
; i
++, sym
++)
1352 register CONST
char *name
;
1354 name
= bfd_asymbol_name (*sym
);
1355 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1357 *pgp
= bfd_asymbol_value (*sym
);
1358 _bfd_set_gp_value (output_bfd
, *pgp
);
1366 /* Only get the error once. */
1368 _bfd_set_gp_value (output_bfd
, *pgp
);
1375 /* We have to figure out the gp value, so that we can adjust the
1376 symbol value correctly. We look up the symbol _gp in the output
1377 BFD. If we can't find it, we're stuck. We cache it in the ELF
1378 target data. We don't need to adjust the symbol value for an
1379 external symbol if we are producing relocateable output. */
1381 static bfd_reloc_status_type
1382 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1385 boolean relocateable
;
1386 char **error_message
;
1389 if (bfd_is_und_section (symbol
->section
)
1393 return bfd_reloc_undefined
;
1396 *pgp
= _bfd_get_gp_value (output_bfd
);
1399 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1403 /* Make up a value. */
1404 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1405 _bfd_set_gp_value (output_bfd
, *pgp
);
1407 else if (!mips_elf_assign_gp (output_bfd
, pgp
))
1410 (char *) _("GP relative relocation when _gp not defined");
1411 return bfd_reloc_dangerous
;
1415 return bfd_reloc_ok
;
1418 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1419 become the offset from the gp register. This function also handles
1420 R_MIPS_LITERAL relocations, although those can be handled more
1421 cleverly because the entries in the .lit8 and .lit4 sections can be
1424 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1425 arelent
*, asection
*,
1426 boolean
, PTR
, bfd_vma
));
1428 bfd_reloc_status_type
1429 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1430 output_bfd
, error_message
)
1432 arelent
*reloc_entry
;
1435 asection
*input_section
;
1437 char **error_message
;
1439 boolean relocateable
;
1440 bfd_reloc_status_type ret
;
1443 /* If we're relocating, and this is an external symbol with no
1444 addend, we don't want to change anything. We will only have an
1445 addend if this is a newly created reloc, not read from an ELF
1447 if (output_bfd
!= (bfd
*) NULL
1448 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1449 && reloc_entry
->addend
== 0)
1451 reloc_entry
->address
+= input_section
->output_offset
;
1452 return bfd_reloc_ok
;
1455 if (output_bfd
!= (bfd
*) NULL
)
1456 relocateable
= true;
1459 relocateable
= false;
1460 output_bfd
= symbol
->section
->output_section
->owner
;
1463 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1465 if (ret
!= bfd_reloc_ok
)
1468 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1469 relocateable
, data
, gp
);
1472 static bfd_reloc_status_type
1473 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1477 arelent
*reloc_entry
;
1478 asection
*input_section
;
1479 boolean relocateable
;
1487 if (bfd_is_com_section (symbol
->section
))
1490 relocation
= symbol
->value
;
1492 relocation
+= symbol
->section
->output_section
->vma
;
1493 relocation
+= symbol
->section
->output_offset
;
1495 if (reloc_entry
->address
> input_section
->_cooked_size
)
1496 return bfd_reloc_outofrange
;
1498 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1500 /* Set val to the offset into the section or symbol. */
1501 if (reloc_entry
->howto
->src_mask
== 0)
1503 /* This case occurs with the 64-bit MIPS ELF ABI. */
1504 val
= reloc_entry
->addend
;
1508 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1513 /* Adjust val for the final section location and GP value. If we
1514 are producing relocateable output, we don't want to do this for
1515 an external symbol. */
1517 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1518 val
+= relocation
- gp
;
1520 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1521 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1524 reloc_entry
->address
+= input_section
->output_offset
;
1526 /* Make sure it fit in 16 bits. */
1527 if ((long) val
>= 0x8000 || (long) val
< -0x8000)
1528 return bfd_reloc_overflow
;
1530 return bfd_reloc_ok
;
1533 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1534 from the gp register? XXX */
1536 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1537 arelent
*, asection
*,
1538 boolean
, PTR
, bfd_vma
));
1540 bfd_reloc_status_type
1541 _bfd_mips_elf_gprel32_reloc (abfd
,
1549 arelent
*reloc_entry
;
1552 asection
*input_section
;
1554 char **error_message
;
1556 boolean relocateable
;
1557 bfd_reloc_status_type ret
;
1560 /* If we're relocating, and this is an external symbol with no
1561 addend, we don't want to change anything. We will only have an
1562 addend if this is a newly created reloc, not read from an ELF
1564 if (output_bfd
!= (bfd
*) NULL
1565 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1566 && reloc_entry
->addend
== 0)
1568 *error_message
= (char *)
1569 _("32bits gp relative relocation occurs for an external symbol");
1570 return bfd_reloc_outofrange
;
1573 if (output_bfd
!= (bfd
*) NULL
)
1575 relocateable
= true;
1576 gp
= _bfd_get_gp_value (output_bfd
);
1580 relocateable
= false;
1581 output_bfd
= symbol
->section
->output_section
->owner
;
1583 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1584 error_message
, &gp
);
1585 if (ret
!= bfd_reloc_ok
)
1589 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1590 relocateable
, data
, gp
);
1593 static bfd_reloc_status_type
1594 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1598 arelent
*reloc_entry
;
1599 asection
*input_section
;
1600 boolean relocateable
;
1607 if (bfd_is_com_section (symbol
->section
))
1610 relocation
= symbol
->value
;
1612 relocation
+= symbol
->section
->output_section
->vma
;
1613 relocation
+= symbol
->section
->output_offset
;
1615 if (reloc_entry
->address
> input_section
->_cooked_size
)
1616 return bfd_reloc_outofrange
;
1618 if (reloc_entry
->howto
->src_mask
== 0)
1620 /* This case arises with the 64-bit MIPS ELF ABI. */
1624 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1626 /* Set val to the offset into the section or symbol. */
1627 val
+= reloc_entry
->addend
;
1629 /* Adjust val for the final section location and GP value. If we
1630 are producing relocateable output, we don't want to do this for
1631 an external symbol. */
1633 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1634 val
+= relocation
- gp
;
1636 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1639 reloc_entry
->address
+= input_section
->output_offset
;
1641 return bfd_reloc_ok
;
1644 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1645 generated when addreses are 64 bits. The upper 32 bits are a simle
1648 static bfd_reloc_status_type
1649 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1650 output_bfd
, error_message
)
1652 arelent
*reloc_entry
;
1655 asection
*input_section
;
1657 char **error_message
;
1659 bfd_reloc_status_type r
;
1664 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1665 input_section
, output_bfd
, error_message
);
1666 if (r
!= bfd_reloc_continue
)
1669 /* Do a normal 32 bit relocation on the lower 32 bits. */
1670 reloc32
= *reloc_entry
;
1671 if (bfd_big_endian (abfd
))
1672 reloc32
.address
+= 4;
1673 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1674 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1675 output_bfd
, error_message
);
1677 /* Sign extend into the upper 32 bits. */
1678 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1679 if ((val
& 0x80000000) != 0)
1683 addr
= reloc_entry
->address
;
1684 if (bfd_little_endian (abfd
))
1686 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1691 /* Handle a mips16 jump. */
1693 static bfd_reloc_status_type
1694 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1695 output_bfd
, error_message
)
1696 bfd
*abfd ATTRIBUTE_UNUSED
;
1697 arelent
*reloc_entry
;
1699 PTR data ATTRIBUTE_UNUSED
;
1700 asection
*input_section
;
1702 char **error_message ATTRIBUTE_UNUSED
;
1704 if (output_bfd
!= (bfd
*) NULL
1705 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1706 && reloc_entry
->addend
== 0)
1708 reloc_entry
->address
+= input_section
->output_offset
;
1709 return bfd_reloc_ok
;
1714 static boolean warned
;
1717 (*_bfd_error_handler
)
1718 (_("Linking mips16 objects into %s format is not supported"),
1719 bfd_get_target (input_section
->output_section
->owner
));
1723 return bfd_reloc_undefined
;
1726 /* Handle a mips16 GP relative reloc. */
1728 static bfd_reloc_status_type
1729 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1730 output_bfd
, error_message
)
1732 arelent
*reloc_entry
;
1735 asection
*input_section
;
1737 char **error_message
;
1739 boolean relocateable
;
1740 bfd_reloc_status_type ret
;
1742 unsigned short extend
, insn
;
1743 unsigned long final
;
1745 /* If we're relocating, and this is an external symbol with no
1746 addend, we don't want to change anything. We will only have an
1747 addend if this is a newly created reloc, not read from an ELF
1749 if (output_bfd
!= NULL
1750 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1751 && reloc_entry
->addend
== 0)
1753 reloc_entry
->address
+= input_section
->output_offset
;
1754 return bfd_reloc_ok
;
1757 if (output_bfd
!= NULL
)
1758 relocateable
= true;
1761 relocateable
= false;
1762 output_bfd
= symbol
->section
->output_section
->owner
;
1765 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1767 if (ret
!= bfd_reloc_ok
)
1770 if (reloc_entry
->address
> input_section
->_cooked_size
)
1771 return bfd_reloc_outofrange
;
1773 /* Pick up the mips16 extend instruction and the real instruction. */
1774 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1775 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1777 /* Stuff the current addend back as a 32 bit value, do the usual
1778 relocation, and then clean up. */
1780 (((extend
& 0x1f) << 11)
1783 (bfd_byte
*) data
+ reloc_entry
->address
);
1785 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1786 relocateable
, data
, gp
);
1788 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1791 | ((final
>> 11) & 0x1f)
1793 (bfd_byte
*) data
+ reloc_entry
->address
);
1797 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1802 /* Return the ISA for a MIPS e_flags value. */
1805 elf_mips_isa (flags
)
1808 switch (flags
& EF_MIPS_ARCH
)
1822 /* Return the MACH for a MIPS e_flags value. */
1825 elf_mips_mach (flags
)
1828 switch (flags
& EF_MIPS_MACH
)
1830 case E_MIPS_MACH_3900
:
1831 return bfd_mach_mips3900
;
1833 case E_MIPS_MACH_4010
:
1834 return bfd_mach_mips4010
;
1836 case E_MIPS_MACH_4100
:
1837 return bfd_mach_mips4100
;
1839 case E_MIPS_MACH_4111
:
1840 return bfd_mach_mips4111
;
1842 case E_MIPS_MACH_4650
:
1843 return bfd_mach_mips4650
;
1846 switch (flags
& EF_MIPS_ARCH
)
1850 return bfd_mach_mips3000
;
1854 return bfd_mach_mips6000
;
1858 return bfd_mach_mips4000
;
1862 return bfd_mach_mips8000
;
1870 /* Return printable name for ABI. */
1873 elf_mips_abi_name (abfd
)
1878 if (ABI_N32_P (abfd
))
1880 else if (ABI_64_P (abfd
))
1883 flags
= elf_elfheader (abfd
)->e_flags
;
1884 switch (flags
& EF_MIPS_ABI
)
1888 case E_MIPS_ABI_O32
:
1890 case E_MIPS_ABI_O64
:
1892 case E_MIPS_ABI_EABI32
:
1894 case E_MIPS_ABI_EABI64
:
1897 return "unknown abi";
1901 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1903 struct elf_reloc_map
{
1904 bfd_reloc_code_real_type bfd_reloc_val
;
1905 enum elf_mips_reloc_type elf_reloc_val
;
1908 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1910 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1911 { BFD_RELOC_16
, R_MIPS_16
},
1912 { BFD_RELOC_32
, R_MIPS_32
},
1913 { BFD_RELOC_64
, R_MIPS_64
},
1914 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1915 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1916 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1917 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1918 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1919 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1920 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1921 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1922 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1923 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1924 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1925 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1926 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
},
1927 { BFD_RELOC_MIPS_SUB
, R_MIPS_SUB
},
1928 { BFD_RELOC_MIPS_GOT_PAGE
, R_MIPS_GOT_PAGE
},
1929 { BFD_RELOC_MIPS_GOT_OFST
, R_MIPS_GOT_OFST
},
1930 { BFD_RELOC_MIPS_GOT_DISP
, R_MIPS_GOT_DISP
}
1933 /* Given a BFD reloc type, return a howto structure. */
1935 static reloc_howto_type
*
1936 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1938 bfd_reloc_code_real_type code
;
1942 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1944 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1945 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1951 bfd_set_error (bfd_error_bad_value
);
1954 case BFD_RELOC_CTOR
:
1955 /* We need to handle BFD_RELOC_CTOR specially.
1956 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1957 size of addresses on this architecture. */
1958 if (bfd_arch_bits_per_address (abfd
) == 32)
1959 return &elf_mips_howto_table
[(int) R_MIPS_32
];
1961 return &elf_mips_ctor64_howto
;
1963 case BFD_RELOC_MIPS16_JMP
:
1964 return &elf_mips16_jump_howto
;
1965 case BFD_RELOC_MIPS16_GPREL
:
1966 return &elf_mips16_gprel_howto
;
1967 case BFD_RELOC_VTABLE_INHERIT
:
1968 return &elf_mips_gnu_vtinherit_howto
;
1969 case BFD_RELOC_VTABLE_ENTRY
:
1970 return &elf_mips_gnu_vtentry_howto
;
1971 case BFD_RELOC_PCREL_HI16_S
:
1972 return &elf_mips_gnu_rel_hi16
;
1973 case BFD_RELOC_PCREL_LO16
:
1974 return &elf_mips_gnu_rel_lo16
;
1975 case BFD_RELOC_16_PCREL_S2
:
1976 return &elf_mips_gnu_rel16_s2
;
1977 case BFD_RELOC_64_PCREL
:
1978 return &elf_mips_gnu_pcrel64
;
1979 case BFD_RELOC_32_PCREL
:
1980 return &elf_mips_gnu_pcrel32
;
1984 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
1986 static reloc_howto_type
*
1987 mips_rtype_to_howto (r_type
)
1988 unsigned int r_type
;
1993 return &elf_mips16_jump_howto
;
1995 case R_MIPS16_GPREL
:
1996 return &elf_mips16_gprel_howto
;
1998 case R_MIPS_GNU_VTINHERIT
:
1999 return &elf_mips_gnu_vtinherit_howto
;
2001 case R_MIPS_GNU_VTENTRY
:
2002 return &elf_mips_gnu_vtentry_howto
;
2004 case R_MIPS_GNU_REL_HI16
:
2005 return &elf_mips_gnu_rel_hi16
;
2007 case R_MIPS_GNU_REL_LO16
:
2008 return &elf_mips_gnu_rel_lo16
;
2010 case R_MIPS_GNU_REL16_S2
:
2011 return &elf_mips_gnu_rel16_s2
;
2014 return &elf_mips_gnu_pcrel64
;
2017 return &elf_mips_gnu_pcrel32
;
2021 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
2022 return &elf_mips_howto_table
[r_type
];
2027 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
2030 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
2033 Elf32_Internal_Rel
*dst
;
2035 unsigned int r_type
;
2037 r_type
= ELF32_R_TYPE (dst
->r_info
);
2038 cache_ptr
->howto
= mips_rtype_to_howto (r_type
);
2040 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
2041 value for the object file. We get the addend now, rather than
2042 when we do the relocation, because the symbol manipulations done
2043 by the linker may cause us to lose track of the input BFD. */
2044 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
2045 && (r_type
== (unsigned int) R_MIPS_GPREL16
2046 || r_type
== (unsigned int) R_MIPS_LITERAL
))
2047 cache_ptr
->addend
= elf_gp (abfd
);
2050 /* Given a MIPS Elf32_Internal_Rela, fill in an arelent structure. */
2053 mips_info_to_howto_rela (abfd
, cache_ptr
, dst
)
2056 Elf32_Internal_Rela
*dst
;
2058 /* Since an Elf32_Internal_Rel is an initial prefix of an
2059 Elf32_Internal_Rela, we can just use mips_info_to_howto_rel
2061 mips_info_to_howto_rel (abfd
, cache_ptr
, (Elf32_Internal_Rel
*) dst
);
2063 /* If we ever need to do any extra processing with dst->r_addend
2064 (the field omitted in an Elf32_Internal_Rel) we can do it here. */
2067 /* A .reginfo section holds a single Elf32_RegInfo structure. These
2068 routines swap this structure in and out. They are used outside of
2069 BFD, so they are globally visible. */
2072 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
2074 const Elf32_External_RegInfo
*ex
;
2077 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
2078 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
2079 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
2080 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
2081 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
2082 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
2086 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
2088 const Elf32_RegInfo
*in
;
2089 Elf32_External_RegInfo
*ex
;
2091 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
2092 (bfd_byte
*) ex
->ri_gprmask
);
2093 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
2094 (bfd_byte
*) ex
->ri_cprmask
[0]);
2095 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
2096 (bfd_byte
*) ex
->ri_cprmask
[1]);
2097 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
2098 (bfd_byte
*) ex
->ri_cprmask
[2]);
2099 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
2100 (bfd_byte
*) ex
->ri_cprmask
[3]);
2101 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
2102 (bfd_byte
*) ex
->ri_gp_value
);
2105 /* In the 64 bit ABI, the .MIPS.options section holds register
2106 information in an Elf64_Reginfo structure. These routines swap
2107 them in and out. They are globally visible because they are used
2108 outside of BFD. These routines are here so that gas can call them
2109 without worrying about whether the 64 bit ABI has been included. */
2112 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
2114 const Elf64_External_RegInfo
*ex
;
2115 Elf64_Internal_RegInfo
*in
;
2117 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
2118 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
2119 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
2120 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
2121 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
2122 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
2123 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
2127 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
2129 const Elf64_Internal_RegInfo
*in
;
2130 Elf64_External_RegInfo
*ex
;
2132 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
2133 (bfd_byte
*) ex
->ri_gprmask
);
2134 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
2135 (bfd_byte
*) ex
->ri_pad
);
2136 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
2137 (bfd_byte
*) ex
->ri_cprmask
[0]);
2138 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
2139 (bfd_byte
*) ex
->ri_cprmask
[1]);
2140 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
2141 (bfd_byte
*) ex
->ri_cprmask
[2]);
2142 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
2143 (bfd_byte
*) ex
->ri_cprmask
[3]);
2144 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
2145 (bfd_byte
*) ex
->ri_gp_value
);
2148 /* Swap an entry in a .gptab section. Note that these routines rely
2149 on the equivalence of the two elements of the union. */
2152 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
2154 const Elf32_External_gptab
*ex
;
2157 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
2158 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
2162 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
2164 const Elf32_gptab
*in
;
2165 Elf32_External_gptab
*ex
;
2167 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
2168 ex
->gt_entry
.gt_g_value
);
2169 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
2170 ex
->gt_entry
.gt_bytes
);
2174 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
2176 const Elf32_compact_rel
*in
;
2177 Elf32_External_compact_rel
*ex
;
2179 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
2180 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
2181 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
2182 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
2183 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
2184 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
2188 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
2190 const Elf32_crinfo
*in
;
2191 Elf32_External_crinfo
*ex
;
2195 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
2196 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
2197 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
2198 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
2199 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
2200 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
2201 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
2204 /* Swap in an options header. */
2207 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
2209 const Elf_External_Options
*ex
;
2210 Elf_Internal_Options
*in
;
2212 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
2213 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
2214 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
2215 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
2218 /* Swap out an options header. */
2221 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
2223 const Elf_Internal_Options
*in
;
2224 Elf_External_Options
*ex
;
2226 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
2227 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
2228 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
2229 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
2232 /* Swap in an MSYM entry. */
2235 bfd_mips_elf_swap_msym_in (abfd
, ex
, in
)
2237 const Elf32_External_Msym
*ex
;
2238 Elf32_Internal_Msym
*in
;
2240 in
->ms_hash_value
= bfd_h_get_32 (abfd
, ex
->ms_hash_value
);
2241 in
->ms_info
= bfd_h_get_32 (abfd
, ex
->ms_info
);
2244 /* Swap out an MSYM entry. */
2247 bfd_mips_elf_swap_msym_out (abfd
, in
, ex
)
2249 const Elf32_Internal_Msym
*in
;
2250 Elf32_External_Msym
*ex
;
2252 bfd_h_put_32 (abfd
, in
->ms_hash_value
, ex
->ms_hash_value
);
2253 bfd_h_put_32 (abfd
, in
->ms_info
, ex
->ms_info
);
2257 /* Determine whether a symbol is global for the purposes of splitting
2258 the symbol table into global symbols and local symbols. At least
2259 on Irix 5, this split must be between section symbols and all other
2260 symbols. On most ELF targets the split is between static symbols
2261 and externally visible symbols. */
2265 mips_elf_sym_is_global (abfd
, sym
)
2266 bfd
*abfd ATTRIBUTE_UNUSED
;
2269 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
2272 /* Set the right machine number for a MIPS ELF file. This is used for
2273 both the 32-bit and the 64-bit ABI. */
2276 _bfd_mips_elf_object_p (abfd
)
2279 /* Irix 5 and 6 is broken. Object file symbol tables are not always
2280 sorted correctly such that local symbols precede global symbols,
2281 and the sh_info field in the symbol table is not always right. */
2282 elf_bad_symtab (abfd
) = true;
2284 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
,
2285 elf_mips_mach (elf_elfheader (abfd
)->e_flags
));
2289 /* The final processing done just before writing out a MIPS ELF object
2290 file. This gets the MIPS architecture right based on the machine
2291 number. This is used by both the 32-bit and the 64-bit ABI. */
2295 _bfd_mips_elf_final_write_processing (abfd
, linker
)
2297 boolean linker ATTRIBUTE_UNUSED
;
2301 Elf_Internal_Shdr
**hdrpp
;
2305 switch (bfd_get_mach (abfd
))
2308 case bfd_mach_mips3000
:
2309 val
= E_MIPS_ARCH_1
;
2312 case bfd_mach_mips3900
:
2313 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
2316 case bfd_mach_mips6000
:
2317 val
= E_MIPS_ARCH_2
;
2320 case bfd_mach_mips4000
:
2321 case bfd_mach_mips4300
:
2322 val
= E_MIPS_ARCH_3
;
2325 case bfd_mach_mips4010
:
2326 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
2329 case bfd_mach_mips4100
:
2330 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
2333 case bfd_mach_mips4111
:
2334 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
2337 case bfd_mach_mips4650
:
2338 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
2341 case bfd_mach_mips8000
:
2342 val
= E_MIPS_ARCH_4
;
2346 elf_elfheader (abfd
)->e_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2347 elf_elfheader (abfd
)->e_flags
|= val
;
2349 /* Set the sh_info field for .gptab sections and other appropriate
2350 info for each special section. */
2351 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
2352 i
< elf_elfheader (abfd
)->e_shnum
;
2355 switch ((*hdrpp
)->sh_type
)
2358 case SHT_MIPS_LIBLIST
:
2359 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
2361 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2364 case SHT_MIPS_GPTAB
:
2365 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2366 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2367 BFD_ASSERT (name
!= NULL
2368 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
2369 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
2370 BFD_ASSERT (sec
!= NULL
);
2371 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2374 case SHT_MIPS_CONTENT
:
2375 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2376 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2377 BFD_ASSERT (name
!= NULL
2378 && strncmp (name
, ".MIPS.content",
2379 sizeof ".MIPS.content" - 1) == 0);
2380 sec
= bfd_get_section_by_name (abfd
,
2381 name
+ sizeof ".MIPS.content" - 1);
2382 BFD_ASSERT (sec
!= NULL
);
2383 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2386 case SHT_MIPS_SYMBOL_LIB
:
2387 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
2389 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2390 sec
= bfd_get_section_by_name (abfd
, ".liblist");
2392 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2395 case SHT_MIPS_EVENTS
:
2396 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2397 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2398 BFD_ASSERT (name
!= NULL
);
2399 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
2400 sec
= bfd_get_section_by_name (abfd
,
2401 name
+ sizeof ".MIPS.events" - 1);
2404 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
2405 sizeof ".MIPS.post_rel" - 1) == 0);
2406 sec
= bfd_get_section_by_name (abfd
,
2408 + sizeof ".MIPS.post_rel" - 1));
2410 BFD_ASSERT (sec
!= NULL
);
2411 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2418 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
2421 _bfd_mips_elf_set_private_flags (abfd
, flags
)
2425 BFD_ASSERT (!elf_flags_init (abfd
)
2426 || elf_elfheader (abfd
)->e_flags
== flags
);
2428 elf_elfheader (abfd
)->e_flags
= flags
;
2429 elf_flags_init (abfd
) = true;
2433 /* Copy backend specific data from one object module to another */
2436 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
2440 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2441 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2444 BFD_ASSERT (!elf_flags_init (obfd
)
2445 || (elf_elfheader (obfd
)->e_flags
2446 == elf_elfheader (ibfd
)->e_flags
));
2448 elf_gp (obfd
) = elf_gp (ibfd
);
2449 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
2450 elf_flags_init (obfd
) = true;
2454 /* Merge backend specific data from an object file to the output
2455 object file when linking. */
2458 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
2466 /* Check if we have the same endianess */
2467 if (_bfd_generic_verify_endian_match (ibfd
, obfd
) == false)
2470 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2471 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2474 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2475 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
2476 old_flags
= elf_elfheader (obfd
)->e_flags
;
2478 if (! elf_flags_init (obfd
))
2480 elf_flags_init (obfd
) = true;
2481 elf_elfheader (obfd
)->e_flags
= new_flags
;
2482 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
2483 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
2485 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2486 && bfd_get_arch_info (obfd
)->the_default
)
2488 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
2489 bfd_get_mach (ibfd
)))
2496 /* Check flag compatibility. */
2498 new_flags
&= ~EF_MIPS_NOREORDER
;
2499 old_flags
&= ~EF_MIPS_NOREORDER
;
2501 if (new_flags
== old_flags
)
2506 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
2508 new_flags
&= ~EF_MIPS_PIC
;
2509 old_flags
&= ~EF_MIPS_PIC
;
2510 (*_bfd_error_handler
)
2511 (_("%s: linking PIC files with non-PIC files"),
2512 bfd_get_filename (ibfd
));
2516 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
2518 new_flags
&= ~EF_MIPS_CPIC
;
2519 old_flags
&= ~EF_MIPS_CPIC
;
2520 (*_bfd_error_handler
)
2521 (_("%s: linking abicalls files with non-abicalls files"),
2522 bfd_get_filename (ibfd
));
2526 /* Compare the ISA's. */
2527 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
2528 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
2530 int new_mach
= new_flags
& EF_MIPS_MACH
;
2531 int old_mach
= old_flags
& EF_MIPS_MACH
;
2532 int new_isa
= elf_mips_isa (new_flags
);
2533 int old_isa
= elf_mips_isa (old_flags
);
2535 /* If either has no machine specified, just compare the general isa's.
2536 Some combinations of machines are ok, if the isa's match. */
2539 || new_mach
== old_mach
2542 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
2543 and -mips4 code. They will normally use the same data sizes and
2544 calling conventions. */
2546 if ((new_isa
== 1 || new_isa
== 2)
2547 ? (old_isa
!= 1 && old_isa
!= 2)
2548 : (old_isa
== 1 || old_isa
== 2))
2550 (*_bfd_error_handler
)
2551 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
2552 bfd_get_filename (ibfd
), new_isa
, old_isa
);
2559 (*_bfd_error_handler
)
2560 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
2561 bfd_get_filename (ibfd
),
2562 elf_mips_mach (new_flags
),
2563 elf_mips_mach (old_flags
));
2567 new_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2568 old_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2571 /* Compare ABI's. The 64-bit ABI does not use EF_MIPS_ABI. But, it
2572 does set EI_CLASS differently from any 32-bit ABI. */
2573 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
2574 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
2575 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
2577 /* Only error if both are set (to different values). */
2578 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
2579 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
2580 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
2582 (*_bfd_error_handler
)
2583 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
2584 bfd_get_filename (ibfd
),
2585 elf_mips_abi_name (ibfd
),
2586 elf_mips_abi_name (obfd
));
2589 new_flags
&= ~EF_MIPS_ABI
;
2590 old_flags
&= ~EF_MIPS_ABI
;
2593 /* Warn about any other mismatches */
2594 if (new_flags
!= old_flags
)
2596 (*_bfd_error_handler
)
2597 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2598 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
2599 (unsigned long) old_flags
);
2605 bfd_set_error (bfd_error_bad_value
);
2613 _bfd_mips_elf_print_private_bfd_data (abfd
, ptr
)
2617 FILE *file
= (FILE *) ptr
;
2619 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
2621 /* Print normal ELF private data. */
2622 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
2624 /* xgettext:c-format */
2625 fprintf (file
, _ ("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
2627 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
2628 fprintf (file
, _ (" [abi=O32]"));
2629 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
2630 fprintf (file
, _ (" [abi=O64]"));
2631 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
2632 fprintf (file
, _ (" [abi=EABI32]"));
2633 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
2634 fprintf (file
, _ (" [abi=EABI64]"));
2635 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
2636 fprintf (file
, _ (" [abi unknown]"));
2637 else if (ABI_N32_P (abfd
))
2638 fprintf (file
, _ (" [abi=N32]"));
2639 else if (ABI_64_P (abfd
))
2640 fprintf (file
, _ (" [abi=64]"));
2642 fprintf (file
, _ (" [no abi set]"));
2644 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
2645 fprintf (file
, _ (" [mips1]"));
2646 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
2647 fprintf (file
, _ (" [mips2]"));
2648 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
2649 fprintf (file
, _ (" [mips3]"));
2650 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
2651 fprintf (file
, _ (" [mips4]"));
2653 fprintf (file
, _ (" [unknown ISA]"));
2655 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
2656 fprintf (file
, _ (" [32bitmode]"));
2658 fprintf (file
, _ (" [not 32bitmode]"));
2665 /* Handle a MIPS specific section when reading an object file. This
2666 is called when elfcode.h finds a section with an unknown type.
2667 This routine supports both the 32-bit and 64-bit ELF ABI.
2669 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2673 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
2675 Elf_Internal_Shdr
*hdr
;
2680 /* There ought to be a place to keep ELF backend specific flags, but
2681 at the moment there isn't one. We just keep track of the
2682 sections by their name, instead. Fortunately, the ABI gives
2683 suggested names for all the MIPS specific sections, so we will
2684 probably get away with this. */
2685 switch (hdr
->sh_type
)
2687 case SHT_MIPS_LIBLIST
:
2688 if (strcmp (name
, ".liblist") != 0)
2692 if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) != 0)
2695 case SHT_MIPS_CONFLICT
:
2696 if (strcmp (name
, ".conflict") != 0)
2699 case SHT_MIPS_GPTAB
:
2700 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
2703 case SHT_MIPS_UCODE
:
2704 if (strcmp (name
, ".ucode") != 0)
2707 case SHT_MIPS_DEBUG
:
2708 if (strcmp (name
, ".mdebug") != 0)
2710 flags
= SEC_DEBUGGING
;
2712 case SHT_MIPS_REGINFO
:
2713 if (strcmp (name
, ".reginfo") != 0
2714 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
2716 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
2718 case SHT_MIPS_IFACE
:
2719 if (strcmp (name
, ".MIPS.interfaces") != 0)
2722 case SHT_MIPS_CONTENT
:
2723 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2726 case SHT_MIPS_OPTIONS
:
2727 if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) != 0)
2730 case SHT_MIPS_DWARF
:
2731 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2734 case SHT_MIPS_SYMBOL_LIB
:
2735 if (strcmp (name
, ".MIPS.symlib") != 0)
2738 case SHT_MIPS_EVENTS
:
2739 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2740 && strncmp (name
, ".MIPS.post_rel",
2741 sizeof ".MIPS.post_rel" - 1) != 0)
2748 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2753 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
2754 (bfd_get_section_flags (abfd
,
2760 /* FIXME: We should record sh_info for a .gptab section. */
2762 /* For a .reginfo section, set the gp value in the tdata information
2763 from the contents of this section. We need the gp value while
2764 processing relocs, so we just get it now. The .reginfo section
2765 is not used in the 64-bit MIPS ELF ABI. */
2766 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2768 Elf32_External_RegInfo ext
;
2771 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
2772 (file_ptr
) 0, sizeof ext
))
2774 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
2775 elf_gp (abfd
) = s
.ri_gp_value
;
2778 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2779 set the gp value based on what we find. We may see both
2780 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2781 they should agree. */
2782 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
2784 bfd_byte
*contents
, *l
, *lend
;
2786 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
2787 if (contents
== NULL
)
2789 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
2790 (file_ptr
) 0, hdr
->sh_size
))
2796 lend
= contents
+ hdr
->sh_size
;
2797 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2799 Elf_Internal_Options intopt
;
2801 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2803 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
2805 Elf64_Internal_RegInfo intreg
;
2807 bfd_mips_elf64_swap_reginfo_in
2809 ((Elf64_External_RegInfo
*)
2810 (l
+ sizeof (Elf_External_Options
))),
2812 elf_gp (abfd
) = intreg
.ri_gp_value
;
2814 else if (intopt
.kind
== ODK_REGINFO
)
2816 Elf32_RegInfo intreg
;
2818 bfd_mips_elf32_swap_reginfo_in
2820 ((Elf32_External_RegInfo
*)
2821 (l
+ sizeof (Elf_External_Options
))),
2823 elf_gp (abfd
) = intreg
.ri_gp_value
;
2833 /* Set the correct type for a MIPS ELF section. We do this by the
2834 section name, which is a hack, but ought to work. This routine is
2835 used by both the 32-bit and the 64-bit ABI. */
2838 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
2840 Elf32_Internal_Shdr
*hdr
;
2843 register const char *name
;
2845 name
= bfd_get_section_name (abfd
, sec
);
2847 if (strcmp (name
, ".liblist") == 0)
2849 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
2850 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
2851 /* The sh_link field is set in final_write_processing. */
2853 else if (strcmp (name
, ".conflict") == 0)
2854 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
2855 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2857 hdr
->sh_type
= SHT_MIPS_GPTAB
;
2858 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
2859 /* The sh_info field is set in final_write_processing. */
2861 else if (strcmp (name
, ".ucode") == 0)
2862 hdr
->sh_type
= SHT_MIPS_UCODE
;
2863 else if (strcmp (name
, ".mdebug") == 0)
2865 hdr
->sh_type
= SHT_MIPS_DEBUG
;
2866 /* In a shared object on Irix 5.3, the .mdebug section has an
2867 entsize of 0. FIXME: Does this matter? */
2868 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2869 hdr
->sh_entsize
= 0;
2871 hdr
->sh_entsize
= 1;
2873 else if (strcmp (name
, ".reginfo") == 0)
2875 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2876 /* In a shared object on Irix 5.3, the .reginfo section has an
2877 entsize of 0x18. FIXME: Does this matter? */
2878 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2879 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2881 hdr
->sh_entsize
= 1;
2883 else if (SGI_COMPAT (abfd
)
2884 && (strcmp (name
, ".hash") == 0
2885 || strcmp (name
, ".dynamic") == 0
2886 || strcmp (name
, ".dynstr") == 0))
2888 hdr
->sh_entsize
= 0;
2890 /* This isn't how the Irix 6 linker behaves. */
2891 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2894 else if (strcmp (name
, ".got") == 0
2895 || strcmp (name
, MIPS_ELF_SRDATA_SECTION_NAME (abfd
)) == 0
2896 || strcmp (name
, ".sdata") == 0
2897 || strcmp (name
, ".sbss") == 0
2898 || strcmp (name
, ".lit4") == 0
2899 || strcmp (name
, ".lit8") == 0)
2900 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2901 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2903 hdr
->sh_type
= SHT_MIPS_IFACE
;
2904 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2906 else if (strncmp (name
, ".MIPS.content", strlen (".MIPS.content")) == 0)
2908 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2909 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2910 /* The sh_info field is set in final_write_processing. */
2912 else if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
2914 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2915 hdr
->sh_entsize
= 1;
2916 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2918 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2919 hdr
->sh_type
= SHT_MIPS_DWARF
;
2920 else if (strcmp (name
, ".MIPS.symlib") == 0)
2922 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2923 /* The sh_link and sh_info fields are set in
2924 final_write_processing. */
2926 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2927 || strncmp (name
, ".MIPS.post_rel",
2928 sizeof ".MIPS.post_rel" - 1) == 0)
2930 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2931 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2932 /* The sh_link field is set in final_write_processing. */
2934 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) == 0)
2936 hdr
->sh_type
= SHT_MIPS_MSYM
;
2937 hdr
->sh_flags
|= SHF_ALLOC
;
2938 hdr
->sh_entsize
= 8;
2941 /* The generic elf_fake_sections will set up REL_HDR using the
2942 default kind of relocations. But, we may actually need both
2943 kinds of relocations, so we set up the second header here. */
2944 if ((sec
->flags
& SEC_RELOC
) != 0)
2946 struct bfd_elf_section_data
*esd
;
2948 esd
= elf_section_data (sec
);
2949 BFD_ASSERT (esd
->rel_hdr2
== NULL
);
2951 = (Elf_Internal_Shdr
*) bfd_zalloc (abfd
, sizeof (Elf_Internal_Shdr
));
2954 _bfd_elf_init_reloc_shdr (abfd
, esd
->rel_hdr2
, sec
,
2955 !elf_section_data (sec
)->use_rela_p
);
2961 /* Given a BFD section, try to locate the corresponding ELF section
2962 index. This is used by both the 32-bit and the 64-bit ABI.
2963 Actually, it's not clear to me that the 64-bit ABI supports these,
2964 but for non-PIC objects we will certainly want support for at least
2965 the .scommon section. */
2968 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2969 bfd
*abfd ATTRIBUTE_UNUSED
;
2970 Elf32_Internal_Shdr
*hdr ATTRIBUTE_UNUSED
;
2974 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2976 *retval
= SHN_MIPS_SCOMMON
;
2979 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2981 *retval
= SHN_MIPS_ACOMMON
;
2987 /* When are writing out the .options or .MIPS.options section,
2988 remember the bytes we are writing out, so that we can install the
2989 GP value in the section_processing routine. */
2992 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2997 bfd_size_type count
;
2999 if (strcmp (section
->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
3003 if (elf_section_data (section
) == NULL
)
3005 section
->used_by_bfd
=
3006 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
3007 if (elf_section_data (section
) == NULL
)
3010 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
3015 if (section
->_cooked_size
!= 0)
3016 size
= section
->_cooked_size
;
3018 size
= section
->_raw_size
;
3019 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
3022 elf_section_data (section
)->tdata
= (PTR
) c
;
3025 memcpy (c
+ offset
, location
, count
);
3028 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
3032 /* Work over a section just before writing it out. This routine is
3033 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
3034 sections that need the SHF_MIPS_GPREL flag by name; there has to be
3038 _bfd_mips_elf_section_processing (abfd
, hdr
)
3040 Elf_Internal_Shdr
*hdr
;
3042 if (hdr
->sh_type
== SHT_MIPS_REGINFO
3043 && hdr
->sh_size
> 0)
3047 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
3048 BFD_ASSERT (hdr
->contents
== NULL
);
3051 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
3054 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
3055 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
3059 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
3060 && hdr
->bfd_section
!= NULL
3061 && elf_section_data (hdr
->bfd_section
) != NULL
3062 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
3064 bfd_byte
*contents
, *l
, *lend
;
3066 /* We stored the section contents in the elf_section_data tdata
3067 field in the set_section_contents routine. We save the
3068 section contents so that we don't have to read them again.
3069 At this point we know that elf_gp is set, so we can look
3070 through the section contents to see if there is an
3071 ODK_REGINFO structure. */
3073 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
3075 lend
= contents
+ hdr
->sh_size
;
3076 while (l
+ sizeof (Elf_External_Options
) <= lend
)
3078 Elf_Internal_Options intopt
;
3080 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
3082 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
3089 + sizeof (Elf_External_Options
)
3090 + (sizeof (Elf64_External_RegInfo
) - 8)),
3093 bfd_h_put_64 (abfd
, elf_gp (abfd
), buf
);
3094 if (bfd_write (buf
, 1, 8, abfd
) != 8)
3097 else if (intopt
.kind
== ODK_REGINFO
)
3104 + sizeof (Elf_External_Options
)
3105 + (sizeof (Elf32_External_RegInfo
) - 4)),
3108 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
3109 if (bfd_write (buf
, 1, 4, abfd
) != 4)
3116 if (hdr
->bfd_section
!= NULL
)
3118 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
3120 if (strcmp (name
, ".sdata") == 0
3121 || strcmp (name
, ".lit8") == 0
3122 || strcmp (name
, ".lit4") == 0)
3124 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3125 hdr
->sh_type
= SHT_PROGBITS
;
3127 else if (strcmp (name
, ".sbss") == 0)
3129 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3130 hdr
->sh_type
= SHT_NOBITS
;
3132 else if (strcmp (name
, MIPS_ELF_SRDATA_SECTION_NAME (abfd
)) == 0)
3134 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
3135 hdr
->sh_type
= SHT_PROGBITS
;
3137 else if (strcmp (name
, ".compact_rel") == 0)
3140 hdr
->sh_type
= SHT_PROGBITS
;
3142 else if (strcmp (name
, ".rtproc") == 0)
3144 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
3146 unsigned int adjust
;
3148 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
3150 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
3159 /* MIPS ELF uses two common sections. One is the usual one, and the
3160 other is for small objects. All the small objects are kept
3161 together, and then referenced via the gp pointer, which yields
3162 faster assembler code. This is what we use for the small common
3163 section. This approach is copied from ecoff.c. */
3164 static asection mips_elf_scom_section
;
3165 static asymbol mips_elf_scom_symbol
;
3166 static asymbol
*mips_elf_scom_symbol_ptr
;
3168 /* MIPS ELF also uses an acommon section, which represents an
3169 allocated common symbol which may be overridden by a
3170 definition in a shared library. */
3171 static asection mips_elf_acom_section
;
3172 static asymbol mips_elf_acom_symbol
;
3173 static asymbol
*mips_elf_acom_symbol_ptr
;
3175 /* Handle the special MIPS section numbers that a symbol may use.
3176 This is used for both the 32-bit and the 64-bit ABI. */
3179 _bfd_mips_elf_symbol_processing (abfd
, asym
)
3183 elf_symbol_type
*elfsym
;
3185 elfsym
= (elf_symbol_type
*) asym
;
3186 switch (elfsym
->internal_elf_sym
.st_shndx
)
3188 case SHN_MIPS_ACOMMON
:
3189 /* This section is used in a dynamically linked executable file.
3190 It is an allocated common section. The dynamic linker can
3191 either resolve these symbols to something in a shared
3192 library, or it can just leave them here. For our purposes,
3193 we can consider these symbols to be in a new section. */
3194 if (mips_elf_acom_section
.name
== NULL
)
3196 /* Initialize the acommon section. */
3197 mips_elf_acom_section
.name
= ".acommon";
3198 mips_elf_acom_section
.flags
= SEC_ALLOC
;
3199 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
3200 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
3201 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
3202 mips_elf_acom_symbol
.name
= ".acommon";
3203 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
3204 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
3205 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
3207 asym
->section
= &mips_elf_acom_section
;
3211 /* Common symbols less than the GP size are automatically
3212 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
3213 if (asym
->value
> elf_gp_size (abfd
)
3214 || IRIX_COMPAT (abfd
) == ict_irix6
)
3217 case SHN_MIPS_SCOMMON
:
3218 if (mips_elf_scom_section
.name
== NULL
)
3220 /* Initialize the small common section. */
3221 mips_elf_scom_section
.name
= ".scommon";
3222 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
3223 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
3224 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
3225 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
3226 mips_elf_scom_symbol
.name
= ".scommon";
3227 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
3228 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
3229 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
3231 asym
->section
= &mips_elf_scom_section
;
3232 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
3235 case SHN_MIPS_SUNDEFINED
:
3236 asym
->section
= bfd_und_section_ptr
;
3239 #if 0 /* for SGI_COMPAT */
3241 asym
->section
= mips_elf_text_section_ptr
;
3245 asym
->section
= mips_elf_data_section_ptr
;
3251 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
3255 _bfd_mips_elf_additional_program_headers (abfd
)
3261 if (!SGI_COMPAT (abfd
))
3264 /* See if we need a PT_MIPS_REGINFO segment. */
3265 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3266 if (s
&& (s
->flags
& SEC_LOAD
))
3269 /* See if we need a PT_MIPS_OPTIONS segment. */
3270 if (IRIX_COMPAT (abfd
) == ict_irix6
3271 && bfd_get_section_by_name (abfd
,
3272 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
3275 /* See if we need a PT_MIPS_RTPROC segment. */
3276 if (IRIX_COMPAT (abfd
) == ict_irix5
3277 && bfd_get_section_by_name (abfd
, ".dynamic")
3278 && bfd_get_section_by_name (abfd
, ".mdebug"))
3284 /* Modify the segment map for an Irix 5 executable. */
3287 _bfd_mips_elf_modify_segment_map (abfd
)
3291 struct elf_segment_map
*m
, **pm
;
3293 if (! SGI_COMPAT (abfd
))
3296 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
3298 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3299 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3301 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3302 if (m
->p_type
== PT_MIPS_REGINFO
)
3306 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3310 m
->p_type
= PT_MIPS_REGINFO
;
3314 /* We want to put it after the PHDR and INTERP segments. */
3315 pm
= &elf_tdata (abfd
)->segment_map
;
3317 && ((*pm
)->p_type
== PT_PHDR
3318 || (*pm
)->p_type
== PT_INTERP
))
3326 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
3327 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
3328 PT_OPTIONS segement immediately following the program header
3330 if (IRIX_COMPAT (abfd
) == ict_irix6
)
3334 for (s
= abfd
->sections
; s
; s
= s
->next
)
3335 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
3340 struct elf_segment_map
*options_segment
;
3342 /* Usually, there's a program header table. But, sometimes
3343 there's not (like when running the `ld' testsuite). So,
3344 if there's no program header table, we just put the
3345 options segement at the end. */
3346 for (pm
= &elf_tdata (abfd
)->segment_map
;
3349 if ((*pm
)->p_type
== PT_PHDR
)
3352 options_segment
= bfd_zalloc (abfd
,
3353 sizeof (struct elf_segment_map
));
3354 options_segment
->next
= *pm
;
3355 options_segment
->p_type
= PT_MIPS_OPTIONS
;
3356 options_segment
->p_flags
= PF_R
;
3357 options_segment
->p_flags_valid
= true;
3358 options_segment
->count
= 1;
3359 options_segment
->sections
[0] = s
;
3360 *pm
= options_segment
;
3365 /* If there are .dynamic and .mdebug sections, we make a room
3366 for the RTPROC header. FIXME: Rewrite without section names. */
3367 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
3368 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3369 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3371 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3372 if (m
->p_type
== PT_MIPS_RTPROC
)
3376 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3380 m
->p_type
= PT_MIPS_RTPROC
;
3382 s
= bfd_get_section_by_name (abfd
, ".rtproc");
3387 m
->p_flags_valid
= 1;
3395 /* We want to put it after the DYNAMIC segment. */
3396 pm
= &elf_tdata (abfd
)->segment_map
;
3397 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
3407 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic,
3408 .dynstr, .dynsym, and .hash sections, and everything in
3410 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
3411 if ((*pm
)->p_type
== PT_DYNAMIC
)
3416 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
3418 static const char *sec_names
[] =
3419 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
3422 struct elf_segment_map
*n
;
3426 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
3428 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
3429 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3435 sz
= s
->_cooked_size
;
3438 if (high
< s
->vma
+ sz
)
3444 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3445 if ((s
->flags
& SEC_LOAD
) != 0
3448 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3452 n
= ((struct elf_segment_map
*)
3453 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
3460 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3462 if ((s
->flags
& SEC_LOAD
) != 0
3465 + (s
->_cooked_size
!= 0 ?
3466 s
->_cooked_size
: s
->_raw_size
))
3481 /* The structure of the runtime procedure descriptor created by the
3482 loader for use by the static exception system. */
3484 typedef struct runtime_pdr
{
3485 bfd_vma adr
; /* memory address of start of procedure */
3486 long regmask
; /* save register mask */
3487 long regoffset
; /* save register offset */
3488 long fregmask
; /* save floating point register mask */
3489 long fregoffset
; /* save floating point register offset */
3490 long frameoffset
; /* frame size */
3491 short framereg
; /* frame pointer register */
3492 short pcreg
; /* offset or reg of return pc */
3493 long irpss
; /* index into the runtime string table */
3495 struct exception_info
*exception_info
;/* pointer to exception array */
3497 #define cbRPDR sizeof(RPDR)
3498 #define rpdNil ((pRPDR) 0)
3500 /* Swap RPDR (runtime procedure table entry) for output. */
3502 static void ecoff_swap_rpdr_out
3503 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
3506 ecoff_swap_rpdr_out (abfd
, in
, ex
)
3509 struct rpdr_ext
*ex
;
3511 /* ecoff_put_off was defined in ecoffswap.h. */
3512 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
3513 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
3514 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
3515 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
3516 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
3517 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
3519 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
3520 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
3522 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
3524 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
3528 /* Read ECOFF debugging information from a .mdebug section into a
3529 ecoff_debug_info structure. */
3532 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
3535 struct ecoff_debug_info
*debug
;
3538 const struct ecoff_debug_swap
*swap
;
3539 char *ext_hdr
= NULL
;
3541 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3542 memset (debug
, 0, sizeof(*debug
));
3544 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
3545 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
3548 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
3549 swap
->external_hdr_size
)
3553 symhdr
= &debug
->symbolic_header
;
3554 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
3556 /* The symbolic header contains absolute file offsets and sizes to
3558 #define READ(ptr, offset, count, size, type) \
3559 if (symhdr->count == 0) \
3560 debug->ptr = NULL; \
3563 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
3564 if (debug->ptr == NULL) \
3565 goto error_return; \
3566 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3567 || (bfd_read (debug->ptr, size, symhdr->count, \
3568 abfd) != size * symhdr->count)) \
3569 goto error_return; \
3572 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
3573 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
3574 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
3575 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
3576 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
3577 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
3579 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
3580 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
3581 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
3582 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
3583 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
3587 debug
->adjust
= NULL
;
3592 if (ext_hdr
!= NULL
)
3594 if (debug
->line
!= NULL
)
3596 if (debug
->external_dnr
!= NULL
)
3597 free (debug
->external_dnr
);
3598 if (debug
->external_pdr
!= NULL
)
3599 free (debug
->external_pdr
);
3600 if (debug
->external_sym
!= NULL
)
3601 free (debug
->external_sym
);
3602 if (debug
->external_opt
!= NULL
)
3603 free (debug
->external_opt
);
3604 if (debug
->external_aux
!= NULL
)
3605 free (debug
->external_aux
);
3606 if (debug
->ss
!= NULL
)
3608 if (debug
->ssext
!= NULL
)
3609 free (debug
->ssext
);
3610 if (debug
->external_fdr
!= NULL
)
3611 free (debug
->external_fdr
);
3612 if (debug
->external_rfd
!= NULL
)
3613 free (debug
->external_rfd
);
3614 if (debug
->external_ext
!= NULL
)
3615 free (debug
->external_ext
);
3619 /* MIPS ELF local labels start with '$', not 'L'. */
3623 mips_elf_is_local_label_name (abfd
, name
)
3630 /* On Irix 6, the labels go back to starting with '.', so we accept
3631 the generic ELF local label syntax as well. */
3632 return _bfd_elf_is_local_label_name (abfd
, name
);
3635 /* MIPS ELF uses a special find_nearest_line routine in order the
3636 handle the ECOFF debugging information. */
3638 struct mips_elf_find_line
3640 struct ecoff_debug_info d
;
3641 struct ecoff_find_line i
;
3645 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
3646 functionname_ptr
, line_ptr
)
3651 const char **filename_ptr
;
3652 const char **functionname_ptr
;
3653 unsigned int *line_ptr
;
3657 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
3658 filename_ptr
, functionname_ptr
,
3662 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3663 filename_ptr
, functionname_ptr
,
3665 ABI_64_P (abfd
) ? 8 : 0))
3668 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
3672 struct mips_elf_find_line
*fi
;
3673 const struct ecoff_debug_swap
* const swap
=
3674 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3676 /* If we are called during a link, mips_elf_final_link may have
3677 cleared the SEC_HAS_CONTENTS field. We force it back on here
3678 if appropriate (which it normally will be). */
3679 origflags
= msec
->flags
;
3680 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
3681 msec
->flags
|= SEC_HAS_CONTENTS
;
3683 fi
= elf_tdata (abfd
)->find_line_info
;
3686 bfd_size_type external_fdr_size
;
3689 struct fdr
*fdr_ptr
;
3691 fi
= ((struct mips_elf_find_line
*)
3692 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
3695 msec
->flags
= origflags
;
3699 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
3701 msec
->flags
= origflags
;
3705 /* Swap in the FDR information. */
3706 fi
->d
.fdr
= ((struct fdr
*)
3708 (fi
->d
.symbolic_header
.ifdMax
*
3709 sizeof (struct fdr
))));
3710 if (fi
->d
.fdr
== NULL
)
3712 msec
->flags
= origflags
;
3715 external_fdr_size
= swap
->external_fdr_size
;
3716 fdr_ptr
= fi
->d
.fdr
;
3717 fraw_src
= (char *) fi
->d
.external_fdr
;
3718 fraw_end
= (fraw_src
3719 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
3720 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
3721 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
3723 elf_tdata (abfd
)->find_line_info
= fi
;
3725 /* Note that we don't bother to ever free this information.
3726 find_nearest_line is either called all the time, as in
3727 objdump -l, so the information should be saved, or it is
3728 rarely called, as in ld error messages, so the memory
3729 wasted is unimportant. Still, it would probably be a
3730 good idea for free_cached_info to throw it away. */
3733 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
3734 &fi
->i
, filename_ptr
, functionname_ptr
,
3737 msec
->flags
= origflags
;
3741 msec
->flags
= origflags
;
3744 /* Fall back on the generic ELF find_nearest_line routine. */
3746 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
3747 filename_ptr
, functionname_ptr
,
3751 /* The mips16 compiler uses a couple of special sections to handle
3752 floating point arguments.
3754 Section names that look like .mips16.fn.FNNAME contain stubs that
3755 copy floating point arguments from the fp regs to the gp regs and
3756 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3757 call should be redirected to the stub instead. If no 32 bit
3758 function calls FNNAME, the stub should be discarded. We need to
3759 consider any reference to the function, not just a call, because
3760 if the address of the function is taken we will need the stub,
3761 since the address might be passed to a 32 bit function.
3763 Section names that look like .mips16.call.FNNAME contain stubs
3764 that copy floating point arguments from the gp regs to the fp
3765 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3766 then any 16 bit function that calls FNNAME should be redirected
3767 to the stub instead. If FNNAME is not a 32 bit function, the
3768 stub should be discarded.
3770 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3771 which call FNNAME and then copy the return value from the fp regs
3772 to the gp regs. These stubs store the return value in $18 while
3773 calling FNNAME; any function which might call one of these stubs
3774 must arrange to save $18 around the call. (This case is not
3775 needed for 32 bit functions that call 16 bit functions, because
3776 16 bit functions always return floating point values in both
3779 Note that in all cases FNNAME might be defined statically.
3780 Therefore, FNNAME is not used literally. Instead, the relocation
3781 information will indicate which symbol the section is for.
3783 We record any stubs that we find in the symbol table. */
3785 #define FN_STUB ".mips16.fn."
3786 #define CALL_STUB ".mips16.call."
3787 #define CALL_FP_STUB ".mips16.call.fp."
3789 /* MIPS ELF linker hash table. */
3791 struct mips_elf_link_hash_table
3793 struct elf_link_hash_table root
;
3795 /* We no longer use this. */
3796 /* String section indices for the dynamic section symbols. */
3797 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
3799 /* The number of .rtproc entries. */
3800 bfd_size_type procedure_count
;
3801 /* The size of the .compact_rel section (if SGI_COMPAT). */
3802 bfd_size_type compact_rel_size
;
3803 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3804 entry is set to the address of __rld_obj_head as in Irix 5. */
3805 boolean use_rld_obj_head
;
3806 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3808 /* This is set if we see any mips16 stub sections. */
3809 boolean mips16_stubs_seen
;
3812 /* Look up an entry in a MIPS ELF linker hash table. */
3814 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3815 ((struct mips_elf_link_hash_entry *) \
3816 elf_link_hash_lookup (&(table)->root, (string), (create), \
3819 /* Traverse a MIPS ELF linker hash table. */
3821 #define mips_elf_link_hash_traverse(table, func, info) \
3822 (elf_link_hash_traverse \
3824 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3827 /* Get the MIPS ELF linker hash table from a link_info structure. */
3829 #define mips_elf_hash_table(p) \
3830 ((struct mips_elf_link_hash_table *) ((p)->hash))
3832 static boolean mips_elf_output_extsym
3833 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3835 /* Create an entry in a MIPS ELF linker hash table. */
3837 static struct bfd_hash_entry
*
3838 mips_elf_link_hash_newfunc (entry
, table
, string
)
3839 struct bfd_hash_entry
*entry
;
3840 struct bfd_hash_table
*table
;
3843 struct mips_elf_link_hash_entry
*ret
=
3844 (struct mips_elf_link_hash_entry
*) entry
;
3846 /* Allocate the structure if it has not already been allocated by a
3848 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3849 ret
= ((struct mips_elf_link_hash_entry
*)
3850 bfd_hash_allocate (table
,
3851 sizeof (struct mips_elf_link_hash_entry
)));
3852 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3853 return (struct bfd_hash_entry
*) ret
;
3855 /* Call the allocation method of the superclass. */
3856 ret
= ((struct mips_elf_link_hash_entry
*)
3857 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3859 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3861 /* Set local fields. */
3862 memset (&ret
->esym
, 0, sizeof (EXTR
));
3863 /* We use -2 as a marker to indicate that the information has
3864 not been set. -1 means there is no associated ifd. */
3866 ret
->possibly_dynamic_relocs
= 0;
3867 ret
->min_dyn_reloc_index
= 0;
3868 ret
->fn_stub
= NULL
;
3869 ret
->need_fn_stub
= false;
3870 ret
->call_stub
= NULL
;
3871 ret
->call_fp_stub
= NULL
;
3874 return (struct bfd_hash_entry
*) ret
;
3878 _bfd_mips_elf_hide_symbol(info
, h
)
3879 struct bfd_link_info
*info
;
3880 struct mips_elf_link_hash_entry
*h
;
3884 struct mips_got_info
*g
;
3885 dynobj
= elf_hash_table (info
)->dynobj
;
3886 got
= bfd_get_section_by_name (dynobj
, ".got");
3887 g
= (struct mips_got_info
*) elf_section_data (got
)->tdata
;
3889 h
->root
.elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3890 h
->root
.plt
.offset
= (bfd_vma
) -1;
3891 h
->root
.dynindx
= -1;
3893 /* FIXME: Do we allocate too much GOT space here? */
3895 got
->_raw_size
+= MIPS_ELF_GOT_SIZE (dynobj
);
3898 /* Create a MIPS ELF linker hash table. */
3900 struct bfd_link_hash_table
*
3901 _bfd_mips_elf_link_hash_table_create (abfd
)
3904 struct mips_elf_link_hash_table
*ret
;
3906 ret
= ((struct mips_elf_link_hash_table
*)
3907 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
3908 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
3911 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3912 mips_elf_link_hash_newfunc
))
3914 bfd_release (abfd
, ret
);
3919 /* We no longer use this. */
3920 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
3921 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
3923 ret
->procedure_count
= 0;
3924 ret
->compact_rel_size
= 0;
3925 ret
->use_rld_obj_head
= false;
3927 ret
->mips16_stubs_seen
= false;
3929 return &ret
->root
.root
;
3932 /* Hook called by the linker routine which adds symbols from an object
3933 file. We must handle the special MIPS section numbers here. */
3937 _bfd_mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3939 struct bfd_link_info
*info
;
3940 const Elf_Internal_Sym
*sym
;
3942 flagword
*flagsp ATTRIBUTE_UNUSED
;
3946 if (SGI_COMPAT (abfd
)
3947 && (abfd
->flags
& DYNAMIC
) != 0
3948 && strcmp (*namep
, "_rld_new_interface") == 0)
3950 /* Skip Irix 5 rld entry name. */
3955 switch (sym
->st_shndx
)
3958 /* Common symbols less than the GP size are automatically
3959 treated as SHN_MIPS_SCOMMON symbols. */
3960 if (sym
->st_size
> elf_gp_size (abfd
)
3961 || IRIX_COMPAT (abfd
) == ict_irix6
)
3964 case SHN_MIPS_SCOMMON
:
3965 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3966 (*secp
)->flags
|= SEC_IS_COMMON
;
3967 *valp
= sym
->st_size
;
3971 /* This section is used in a shared object. */
3972 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
3974 asymbol
*elf_text_symbol
;
3975 asection
*elf_text_section
;
3977 elf_text_section
= bfd_zalloc (abfd
, sizeof (asection
));
3978 if (elf_text_section
== NULL
)
3981 elf_text_symbol
= bfd_zalloc (abfd
, sizeof (asymbol
));
3982 if (elf_text_symbol
== NULL
)
3985 /* Initialize the section. */
3987 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
3988 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
3990 elf_text_section
->symbol
= elf_text_symbol
;
3991 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
3993 elf_text_section
->name
= ".text";
3994 elf_text_section
->flags
= SEC_NO_FLAGS
;
3995 elf_text_section
->output_section
= NULL
;
3996 elf_text_section
->owner
= abfd
;
3997 elf_text_symbol
->name
= ".text";
3998 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
3999 elf_text_symbol
->section
= elf_text_section
;
4001 /* This code used to do *secp = bfd_und_section_ptr if
4002 info->shared. I don't know why, and that doesn't make sense,
4003 so I took it out. */
4004 *secp
= elf_tdata (abfd
)->elf_text_section
;
4007 case SHN_MIPS_ACOMMON
:
4008 /* Fall through. XXX Can we treat this as allocated data? */
4010 /* This section is used in a shared object. */
4011 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
4013 asymbol
*elf_data_symbol
;
4014 asection
*elf_data_section
;
4016 elf_data_section
= bfd_zalloc (abfd
, sizeof (asection
));
4017 if (elf_data_section
== NULL
)
4020 elf_data_symbol
= bfd_zalloc (abfd
, sizeof (asymbol
));
4021 if (elf_data_symbol
== NULL
)
4024 /* Initialize the section. */
4026 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
4027 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
4029 elf_data_section
->symbol
= elf_data_symbol
;
4030 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
4032 elf_data_section
->name
= ".data";
4033 elf_data_section
->flags
= SEC_NO_FLAGS
;
4034 elf_data_section
->output_section
= NULL
;
4035 elf_data_section
->owner
= abfd
;
4036 elf_data_symbol
->name
= ".data";
4037 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
4038 elf_data_symbol
->section
= elf_data_section
;
4040 /* This code used to do *secp = bfd_und_section_ptr if
4041 info->shared. I don't know why, and that doesn't make sense,
4042 so I took it out. */
4043 *secp
= elf_tdata (abfd
)->elf_data_section
;
4046 case SHN_MIPS_SUNDEFINED
:
4047 *secp
= bfd_und_section_ptr
;
4051 if (SGI_COMPAT (abfd
)
4053 && info
->hash
->creator
== abfd
->xvec
4054 && strcmp (*namep
, "__rld_obj_head") == 0)
4056 struct elf_link_hash_entry
*h
;
4058 /* Mark __rld_obj_head as dynamic. */
4060 if (! (_bfd_generic_link_add_one_symbol
4061 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
4062 (bfd_vma
) *valp
, (const char *) NULL
, false,
4063 get_elf_backend_data (abfd
)->collect
,
4064 (struct bfd_link_hash_entry
**) &h
)))
4066 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
4067 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4068 h
->type
= STT_OBJECT
;
4070 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4073 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
4076 /* If this is a mips16 text symbol, add 1 to the value to make it
4077 odd. This will cause something like .word SYM to come up with
4078 the right value when it is loaded into the PC. */
4079 if (sym
->st_other
== STO_MIPS16
)
4085 /* Structure used to pass information to mips_elf_output_extsym. */
4090 struct bfd_link_info
*info
;
4091 struct ecoff_debug_info
*debug
;
4092 const struct ecoff_debug_swap
*swap
;
4096 /* This routine is used to write out ECOFF debugging external symbol
4097 information. It is called via mips_elf_link_hash_traverse. The
4098 ECOFF external symbol information must match the ELF external
4099 symbol information. Unfortunately, at this point we don't know
4100 whether a symbol is required by reloc information, so the two
4101 tables may wind up being different. We must sort out the external
4102 symbol information before we can set the final size of the .mdebug
4103 section, and we must set the size of the .mdebug section before we
4104 can relocate any sections, and we can't know which symbols are
4105 required by relocation until we relocate the sections.
4106 Fortunately, it is relatively unlikely that any symbol will be
4107 stripped but required by a reloc. In particular, it can not happen
4108 when generating a final executable. */
4111 mips_elf_output_extsym (h
, data
)
4112 struct mips_elf_link_hash_entry
*h
;
4115 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
4117 asection
*sec
, *output_section
;
4119 if (h
->root
.indx
== -2)
4121 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4122 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
4123 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
4124 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
4126 else if (einfo
->info
->strip
== strip_all
4127 || (einfo
->info
->strip
== strip_some
4128 && bfd_hash_lookup (einfo
->info
->keep_hash
,
4129 h
->root
.root
.root
.string
,
4130 false, false) == NULL
))
4138 if (h
->esym
.ifd
== -2)
4141 h
->esym
.cobol_main
= 0;
4142 h
->esym
.weakext
= 0;
4143 h
->esym
.reserved
= 0;
4144 h
->esym
.ifd
= ifdNil
;
4145 h
->esym
.asym
.value
= 0;
4146 h
->esym
.asym
.st
= stGlobal
;
4148 if (SGI_COMPAT (einfo
->abfd
)
4149 && (h
->root
.root
.type
== bfd_link_hash_undefined
4150 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
4154 /* Use undefined class. Also, set class and type for some
4156 name
= h
->root
.root
.root
.string
;
4157 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
4158 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
4160 h
->esym
.asym
.sc
= scData
;
4161 h
->esym
.asym
.st
= stLabel
;
4162 h
->esym
.asym
.value
= 0;
4164 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
4166 h
->esym
.asym
.sc
= scAbs
;
4167 h
->esym
.asym
.st
= stLabel
;
4168 h
->esym
.asym
.value
=
4169 mips_elf_hash_table (einfo
->info
)->procedure_count
;
4171 else if (strcmp (name
, "_gp_disp") == 0)
4173 h
->esym
.asym
.sc
= scAbs
;
4174 h
->esym
.asym
.st
= stLabel
;
4175 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
4178 h
->esym
.asym
.sc
= scUndefined
;
4180 else if (h
->root
.root
.type
!= bfd_link_hash_defined
4181 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
4182 h
->esym
.asym
.sc
= scAbs
;
4187 sec
= h
->root
.root
.u
.def
.section
;
4188 output_section
= sec
->output_section
;
4190 /* When making a shared library and symbol h is the one from
4191 the another shared library, OUTPUT_SECTION may be null. */
4192 if (output_section
== NULL
)
4193 h
->esym
.asym
.sc
= scUndefined
;
4196 name
= bfd_section_name (output_section
->owner
, output_section
);
4198 if (strcmp (name
, ".text") == 0)
4199 h
->esym
.asym
.sc
= scText
;
4200 else if (strcmp (name
, ".data") == 0)
4201 h
->esym
.asym
.sc
= scData
;
4202 else if (strcmp (name
, ".sdata") == 0)
4203 h
->esym
.asym
.sc
= scSData
;
4204 else if (strcmp (name
, ".rodata") == 0
4205 || strcmp (name
, ".rdata") == 0)
4206 h
->esym
.asym
.sc
= scRData
;
4207 else if (strcmp (name
, ".bss") == 0)
4208 h
->esym
.asym
.sc
= scBss
;
4209 else if (strcmp (name
, ".sbss") == 0)
4210 h
->esym
.asym
.sc
= scSBss
;
4211 else if (strcmp (name
, ".init") == 0)
4212 h
->esym
.asym
.sc
= scInit
;
4213 else if (strcmp (name
, ".fini") == 0)
4214 h
->esym
.asym
.sc
= scFini
;
4216 h
->esym
.asym
.sc
= scAbs
;
4220 h
->esym
.asym
.reserved
= 0;
4221 h
->esym
.asym
.index
= indexNil
;
4224 if (h
->root
.root
.type
== bfd_link_hash_common
)
4225 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
4226 else if (h
->root
.root
.type
== bfd_link_hash_defined
4227 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4229 if (h
->esym
.asym
.sc
== scCommon
)
4230 h
->esym
.asym
.sc
= scBss
;
4231 else if (h
->esym
.asym
.sc
== scSCommon
)
4232 h
->esym
.asym
.sc
= scSBss
;
4234 sec
= h
->root
.root
.u
.def
.section
;
4235 output_section
= sec
->output_section
;
4236 if (output_section
!= NULL
)
4237 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
4238 + sec
->output_offset
4239 + output_section
->vma
);
4241 h
->esym
.asym
.value
= 0;
4243 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4245 /* Set type and value for a symbol with a function stub. */
4246 h
->esym
.asym
.st
= stProc
;
4247 sec
= h
->root
.root
.u
.def
.section
;
4249 h
->esym
.asym
.value
= 0;
4252 output_section
= sec
->output_section
;
4253 if (output_section
!= NULL
)
4254 h
->esym
.asym
.value
= (h
->root
.plt
.offset
4255 + sec
->output_offset
4256 + output_section
->vma
);
4258 h
->esym
.asym
.value
= 0;
4265 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
4266 h
->root
.root
.root
.string
,
4269 einfo
->failed
= true;
4276 /* Create a runtime procedure table from the .mdebug section. */
4279 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
4282 struct bfd_link_info
*info
;
4284 struct ecoff_debug_info
*debug
;
4286 const struct ecoff_debug_swap
*swap
;
4287 HDRR
*hdr
= &debug
->symbolic_header
;
4289 struct rpdr_ext
*erp
;
4291 struct pdr_ext
*epdr
;
4292 struct sym_ext
*esym
;
4295 unsigned long size
, count
;
4296 unsigned long sindex
;
4300 const char *no_name_func
= _("static procedure (no name)");
4308 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4310 sindex
= strlen (no_name_func
) + 1;
4311 count
= hdr
->ipdMax
;
4314 size
= swap
->external_pdr_size
;
4316 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
4320 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
4323 size
= sizeof (RPDR
);
4324 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
4328 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
4332 count
= hdr
->isymMax
;
4333 size
= swap
->external_sym_size
;
4334 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
4338 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
4341 count
= hdr
->issMax
;
4342 ss
= (char *) bfd_malloc (count
);
4345 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
4348 count
= hdr
->ipdMax
;
4349 for (i
= 0; i
< count
; i
++, rp
++)
4351 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
4352 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
4353 rp
->adr
= sym
.value
;
4354 rp
->regmask
= pdr
.regmask
;
4355 rp
->regoffset
= pdr
.regoffset
;
4356 rp
->fregmask
= pdr
.fregmask
;
4357 rp
->fregoffset
= pdr
.fregoffset
;
4358 rp
->frameoffset
= pdr
.frameoffset
;
4359 rp
->framereg
= pdr
.framereg
;
4360 rp
->pcreg
= pdr
.pcreg
;
4362 sv
[i
] = ss
+ sym
.iss
;
4363 sindex
+= strlen (sv
[i
]) + 1;
4367 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
4368 size
= BFD_ALIGN (size
, 16);
4369 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
4372 mips_elf_hash_table (info
)->procedure_count
= 0;
4376 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
4378 erp
= (struct rpdr_ext
*) rtproc
;
4379 memset (erp
, 0, sizeof (struct rpdr_ext
));
4381 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
4382 strcpy (str
, no_name_func
);
4383 str
+= strlen (no_name_func
) + 1;
4384 for (i
= 0; i
< count
; i
++)
4386 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
4387 strcpy (str
, sv
[i
]);
4388 str
+= strlen (sv
[i
]) + 1;
4390 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
4392 /* Set the size and contents of .rtproc section. */
4393 s
->_raw_size
= size
;
4394 s
->contents
= (bfd_byte
*) rtproc
;
4396 /* Skip this section later on (I don't think this currently
4397 matters, but someday it might). */
4398 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
4427 /* A comparison routine used to sort .gptab entries. */
4430 gptab_compare (p1
, p2
)
4434 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
4435 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
4437 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
4440 /* We need to use a special link routine to handle the .reginfo and
4441 the .mdebug sections. We need to merge all instances of these
4442 sections together, not write them all out sequentially. */
4445 _bfd_mips_elf_final_link (abfd
, info
)
4447 struct bfd_link_info
*info
;
4451 struct bfd_link_order
*p
;
4452 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
4453 asection
*rtproc_sec
;
4454 Elf32_RegInfo reginfo
;
4455 struct ecoff_debug_info debug
;
4456 const struct ecoff_debug_swap
*swap
4457 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4458 HDRR
*symhdr
= &debug
.symbolic_header
;
4459 PTR mdebug_handle
= NULL
;
4461 /* If all the things we linked together were PIC, but we're
4462 producing an executable (rather than a shared object), then the
4463 resulting file is CPIC (i.e., it calls PIC code.) */
4465 && !info
->relocateable
4466 && elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
4468 elf_elfheader (abfd
)->e_flags
&= ~EF_MIPS_PIC
;
4469 elf_elfheader (abfd
)->e_flags
|= EF_MIPS_CPIC
;
4472 /* We'd carefully arranged the dynamic symbol indices, and then the
4473 generic size_dynamic_sections renumbered them out from under us.
4474 Rather than trying somehow to prevent the renumbering, just do
4476 if (elf_hash_table (info
)->dynamic_sections_created
)
4480 struct mips_got_info
*g
;
4482 /* When we resort, we must tell mips_elf_sort_hash_table what
4483 the lowest index it may use is. That's the number of section
4484 symbols we're going to add. The generic ELF linker only
4485 adds these symbols when building a shared object. Note that
4486 we count the sections after (possibly) removing the .options
4488 if (!mips_elf_sort_hash_table (info
, (info
->shared
4489 ? bfd_count_sections (abfd
) + 1
4493 /* Make sure we didn't grow the global .got region. */
4494 dynobj
= elf_hash_table (info
)->dynobj
;
4495 got
= bfd_get_section_by_name (dynobj
, ".got");
4496 g
= (struct mips_got_info
*) elf_section_data (got
)->tdata
;
4498 if (g
->global_gotsym
!= NULL
)
4499 BFD_ASSERT ((elf_hash_table (info
)->dynsymcount
4500 - g
->global_gotsym
->dynindx
)
4501 <= g
->global_gotno
);
4504 /* On IRIX5, we omit the .options section. On IRIX6, however, we
4505 include it, even though we don't process it quite right. (Some
4506 entries are supposed to be merged.) Empirically, we seem to be
4507 better off including it then not. */
4508 if (IRIX_COMPAT (abfd
) == ict_irix5
)
4509 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
4511 if (strcmp ((*secpp
)->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
4513 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
4514 if (p
->type
== bfd_indirect_link_order
)
4515 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
4516 (*secpp
)->link_order_head
= NULL
;
4517 *secpp
= (*secpp
)->next
;
4518 --abfd
->section_count
;
4524 /* Get a value for the GP register. */
4525 if (elf_gp (abfd
) == 0)
4527 struct bfd_link_hash_entry
*h
;
4529 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4530 if (h
!= (struct bfd_link_hash_entry
*) NULL
4531 && h
->type
== bfd_link_hash_defined
)
4532 elf_gp (abfd
) = (h
->u
.def
.value
4533 + h
->u
.def
.section
->output_section
->vma
4534 + h
->u
.def
.section
->output_offset
);
4535 else if (info
->relocateable
)
4539 /* Find the GP-relative section with the lowest offset. */
4541 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4543 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
4546 /* And calculate GP relative to that. */
4547 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
4551 /* If the relocate_section function needs to do a reloc
4552 involving the GP value, it should make a reloc_dangerous
4553 callback to warn that GP is not defined. */
4557 /* Go through the sections and collect the .reginfo and .mdebug
4561 gptab_data_sec
= NULL
;
4562 gptab_bss_sec
= NULL
;
4563 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4565 if (strcmp (o
->name
, ".reginfo") == 0)
4567 memset (®info
, 0, sizeof reginfo
);
4569 /* We have found the .reginfo section in the output file.
4570 Look through all the link_orders comprising it and merge
4571 the information together. */
4572 for (p
= o
->link_order_head
;
4573 p
!= (struct bfd_link_order
*) NULL
;
4576 asection
*input_section
;
4578 Elf32_External_RegInfo ext
;
4581 if (p
->type
!= bfd_indirect_link_order
)
4583 if (p
->type
== bfd_fill_link_order
)
4588 input_section
= p
->u
.indirect
.section
;
4589 input_bfd
= input_section
->owner
;
4591 /* The linker emulation code has probably clobbered the
4592 size to be zero bytes. */
4593 if (input_section
->_raw_size
== 0)
4594 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4596 if (! bfd_get_section_contents (input_bfd
, input_section
,
4602 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
4604 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
4605 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
4606 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
4607 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
4608 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
4610 /* ri_gp_value is set by the function
4611 mips_elf32_section_processing when the section is
4612 finally written out. */
4614 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4615 elf_link_input_bfd ignores this section. */
4616 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4619 /* Size has been set in mips_elf_always_size_sections */
4620 BFD_ASSERT(o
->_raw_size
== sizeof (Elf32_External_RegInfo
));
4622 /* Skip this section later on (I don't think this currently
4623 matters, but someday it might). */
4624 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4629 if (strcmp (o
->name
, ".mdebug") == 0)
4631 struct extsym_info einfo
;
4633 /* We have found the .mdebug section in the output file.
4634 Look through all the link_orders comprising it and merge
4635 the information together. */
4636 symhdr
->magic
= swap
->sym_magic
;
4637 /* FIXME: What should the version stamp be? */
4639 symhdr
->ilineMax
= 0;
4643 symhdr
->isymMax
= 0;
4644 symhdr
->ioptMax
= 0;
4645 symhdr
->iauxMax
= 0;
4647 symhdr
->issExtMax
= 0;
4650 symhdr
->iextMax
= 0;
4652 /* We accumulate the debugging information itself in the
4653 debug_info structure. */
4655 debug
.external_dnr
= NULL
;
4656 debug
.external_pdr
= NULL
;
4657 debug
.external_sym
= NULL
;
4658 debug
.external_opt
= NULL
;
4659 debug
.external_aux
= NULL
;
4661 debug
.ssext
= debug
.ssext_end
= NULL
;
4662 debug
.external_fdr
= NULL
;
4663 debug
.external_rfd
= NULL
;
4664 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4666 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4667 if (mdebug_handle
== (PTR
) NULL
)
4670 if (SGI_COMPAT (abfd
))
4676 static const char * const name
[] =
4677 { ".text", ".init", ".fini", ".data",
4678 ".rodata", ".sdata", ".sbss", ".bss" };
4679 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
4680 scRData
, scSData
, scSBss
, scBss
};
4683 esym
.cobol_main
= 0;
4687 esym
.asym
.iss
= issNil
;
4688 esym
.asym
.st
= stLocal
;
4689 esym
.asym
.reserved
= 0;
4690 esym
.asym
.index
= indexNil
;
4692 for (i
= 0; i
< 8; i
++)
4694 esym
.asym
.sc
= sc
[i
];
4695 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4698 esym
.asym
.value
= s
->vma
;
4699 last
= s
->vma
+ s
->_raw_size
;
4702 esym
.asym
.value
= last
;
4704 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4710 for (p
= o
->link_order_head
;
4711 p
!= (struct bfd_link_order
*) NULL
;
4714 asection
*input_section
;
4716 const struct ecoff_debug_swap
*input_swap
;
4717 struct ecoff_debug_info input_debug
;
4721 if (p
->type
!= bfd_indirect_link_order
)
4723 if (p
->type
== bfd_fill_link_order
)
4728 input_section
= p
->u
.indirect
.section
;
4729 input_bfd
= input_section
->owner
;
4731 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4732 || (get_elf_backend_data (input_bfd
)
4733 ->elf_backend_ecoff_debug_swap
) == NULL
)
4735 /* I don't know what a non MIPS ELF bfd would be
4736 doing with a .mdebug section, but I don't really
4737 want to deal with it. */
4741 input_swap
= (get_elf_backend_data (input_bfd
)
4742 ->elf_backend_ecoff_debug_swap
);
4744 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
4746 /* The ECOFF linking code expects that we have already
4747 read in the debugging information and set up an
4748 ecoff_debug_info structure, so we do that now. */
4749 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
4753 if (! (bfd_ecoff_debug_accumulate
4754 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
4755 &input_debug
, input_swap
, info
)))
4758 /* Loop through the external symbols. For each one with
4759 interesting information, try to find the symbol in
4760 the linker global hash table and save the information
4761 for the output external symbols. */
4762 eraw_src
= input_debug
.external_ext
;
4763 eraw_end
= (eraw_src
4764 + (input_debug
.symbolic_header
.iextMax
4765 * input_swap
->external_ext_size
));
4767 eraw_src
< eraw_end
;
4768 eraw_src
+= input_swap
->external_ext_size
)
4772 struct mips_elf_link_hash_entry
*h
;
4774 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4775 if (ext
.asym
.sc
== scNil
4776 || ext
.asym
.sc
== scUndefined
4777 || ext
.asym
.sc
== scSUndefined
)
4780 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4781 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
4782 name
, false, false, true);
4783 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4789 < input_debug
.symbolic_header
.ifdMax
);
4790 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4796 /* Free up the information we just read. */
4797 free (input_debug
.line
);
4798 free (input_debug
.external_dnr
);
4799 free (input_debug
.external_pdr
);
4800 free (input_debug
.external_sym
);
4801 free (input_debug
.external_opt
);
4802 free (input_debug
.external_aux
);
4803 free (input_debug
.ss
);
4804 free (input_debug
.ssext
);
4805 free (input_debug
.external_fdr
);
4806 free (input_debug
.external_rfd
);
4807 free (input_debug
.external_ext
);
4809 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4810 elf_link_input_bfd ignores this section. */
4811 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4814 if (SGI_COMPAT (abfd
) && info
->shared
)
4816 /* Create .rtproc section. */
4817 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4818 if (rtproc_sec
== NULL
)
4820 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4821 | SEC_LINKER_CREATED
| SEC_READONLY
);
4823 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4824 if (rtproc_sec
== NULL
4825 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4826 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
4830 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
4831 info
, rtproc_sec
, &debug
))
4835 /* Build the external symbol information. */
4838 einfo
.debug
= &debug
;
4840 einfo
.failed
= false;
4841 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4842 mips_elf_output_extsym
,
4847 /* Set the size of the .mdebug section. */
4848 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4850 /* Skip this section later on (I don't think this currently
4851 matters, but someday it might). */
4852 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4857 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4859 const char *subname
;
4862 Elf32_External_gptab
*ext_tab
;
4865 /* The .gptab.sdata and .gptab.sbss sections hold
4866 information describing how the small data area would
4867 change depending upon the -G switch. These sections
4868 not used in executables files. */
4869 if (! info
->relocateable
)
4873 for (p
= o
->link_order_head
;
4874 p
!= (struct bfd_link_order
*) NULL
;
4877 asection
*input_section
;
4879 if (p
->type
!= bfd_indirect_link_order
)
4881 if (p
->type
== bfd_fill_link_order
)
4886 input_section
= p
->u
.indirect
.section
;
4888 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4889 elf_link_input_bfd ignores this section. */
4890 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4893 /* Skip this section later on (I don't think this
4894 currently matters, but someday it might). */
4895 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4897 /* Really remove the section. */
4898 for (secpp
= &abfd
->sections
;
4900 secpp
= &(*secpp
)->next
)
4902 *secpp
= (*secpp
)->next
;
4903 --abfd
->section_count
;
4908 /* There is one gptab for initialized data, and one for
4909 uninitialized data. */
4910 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4912 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4916 (*_bfd_error_handler
)
4917 (_("%s: illegal section name `%s'"),
4918 bfd_get_filename (abfd
), o
->name
);
4919 bfd_set_error (bfd_error_nonrepresentable_section
);
4923 /* The linker script always combines .gptab.data and
4924 .gptab.sdata into .gptab.sdata, and likewise for
4925 .gptab.bss and .gptab.sbss. It is possible that there is
4926 no .sdata or .sbss section in the output file, in which
4927 case we must change the name of the output section. */
4928 subname
= o
->name
+ sizeof ".gptab" - 1;
4929 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4931 if (o
== gptab_data_sec
)
4932 o
->name
= ".gptab.data";
4934 o
->name
= ".gptab.bss";
4935 subname
= o
->name
+ sizeof ".gptab" - 1;
4936 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4939 /* Set up the first entry. */
4941 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
4944 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4945 tab
[0].gt_header
.gt_unused
= 0;
4947 /* Combine the input sections. */
4948 for (p
= o
->link_order_head
;
4949 p
!= (struct bfd_link_order
*) NULL
;
4952 asection
*input_section
;
4956 bfd_size_type gpentry
;
4958 if (p
->type
!= bfd_indirect_link_order
)
4960 if (p
->type
== bfd_fill_link_order
)
4965 input_section
= p
->u
.indirect
.section
;
4966 input_bfd
= input_section
->owner
;
4968 /* Combine the gptab entries for this input section one
4969 by one. We know that the input gptab entries are
4970 sorted by ascending -G value. */
4971 size
= bfd_section_size (input_bfd
, input_section
);
4973 for (gpentry
= sizeof (Elf32_External_gptab
);
4975 gpentry
+= sizeof (Elf32_External_gptab
))
4977 Elf32_External_gptab ext_gptab
;
4978 Elf32_gptab int_gptab
;
4984 if (! (bfd_get_section_contents
4985 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4986 gpentry
, sizeof (Elf32_External_gptab
))))
4992 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
4994 val
= int_gptab
.gt_entry
.gt_g_value
;
4995 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4998 for (look
= 1; look
< c
; look
++)
5000 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
5001 tab
[look
].gt_entry
.gt_bytes
+= add
;
5003 if (tab
[look
].gt_entry
.gt_g_value
== val
)
5009 Elf32_gptab
*new_tab
;
5012 /* We need a new table entry. */
5013 new_tab
= ((Elf32_gptab
*)
5014 bfd_realloc ((PTR
) tab
,
5015 (c
+ 1) * sizeof (Elf32_gptab
)));
5016 if (new_tab
== NULL
)
5022 tab
[c
].gt_entry
.gt_g_value
= val
;
5023 tab
[c
].gt_entry
.gt_bytes
= add
;
5025 /* Merge in the size for the next smallest -G
5026 value, since that will be implied by this new
5029 for (look
= 1; look
< c
; look
++)
5031 if (tab
[look
].gt_entry
.gt_g_value
< val
5033 || (tab
[look
].gt_entry
.gt_g_value
5034 > tab
[max
].gt_entry
.gt_g_value
)))
5038 tab
[c
].gt_entry
.gt_bytes
+=
5039 tab
[max
].gt_entry
.gt_bytes
;
5044 last
= int_gptab
.gt_entry
.gt_bytes
;
5047 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5048 elf_link_input_bfd ignores this section. */
5049 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
5052 /* The table must be sorted by -G value. */
5054 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
5056 /* Swap out the table. */
5057 ext_tab
= ((Elf32_External_gptab
*)
5058 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
5059 if (ext_tab
== NULL
)
5065 for (i
= 0; i
< c
; i
++)
5066 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
5069 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
5070 o
->contents
= (bfd_byte
*) ext_tab
;
5072 /* Skip this section later on (I don't think this currently
5073 matters, but someday it might). */
5074 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
5078 /* Invoke the regular ELF backend linker to do all the work. */
5079 if (ABI_64_P (abfd
))
5082 if (!bfd_elf64_bfd_final_link (abfd
, info
))
5089 else if (!bfd_elf32_bfd_final_link (abfd
, info
))
5092 /* Now write out the computed sections. */
5094 if (reginfo_sec
!= (asection
*) NULL
)
5096 Elf32_External_RegInfo ext
;
5098 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
5099 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
5100 (file_ptr
) 0, sizeof ext
))
5104 if (mdebug_sec
!= (asection
*) NULL
)
5106 BFD_ASSERT (abfd
->output_has_begun
);
5107 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
5109 mdebug_sec
->filepos
))
5112 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
5115 if (gptab_data_sec
!= (asection
*) NULL
)
5117 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
5118 gptab_data_sec
->contents
,
5120 gptab_data_sec
->_raw_size
))
5124 if (gptab_bss_sec
!= (asection
*) NULL
)
5126 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
5127 gptab_bss_sec
->contents
,
5129 gptab_bss_sec
->_raw_size
))
5133 if (SGI_COMPAT (abfd
))
5135 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
5136 if (rtproc_sec
!= NULL
)
5138 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
5139 rtproc_sec
->contents
,
5141 rtproc_sec
->_raw_size
))
5149 /* This function is called via qsort() to sort the dynamic relocation
5150 entries by increasing r_symndx value. */
5153 sort_dynamic_relocs (arg1
,arg2
)
5157 const Elf32_External_Rel
*ext_reloc1
= (const Elf32_External_Rel
*) arg1
;
5158 const Elf32_External_Rel
*ext_reloc2
= (const Elf32_External_Rel
*) arg2
;
5160 Elf_Internal_Rel int_reloc1
;
5161 Elf_Internal_Rel int_reloc2
;
5163 bfd_elf32_swap_reloc_in(reldyn_sorting_bfd
, ext_reloc1
, &int_reloc1
);
5164 bfd_elf32_swap_reloc_in(reldyn_sorting_bfd
, ext_reloc2
, &int_reloc2
);
5166 return (ELF32_R_SYM(int_reloc1
.r_info
) - ELF32_R_SYM(int_reloc2
.r_info
));
5169 /* Returns the GOT section for ABFD. */
5172 mips_elf_got_section (abfd
)
5175 return bfd_get_section_by_name (abfd
, ".got");
5178 /* Returns the GOT information associated with the link indicated by
5179 INFO. If SGOTP is non-NULL, it is filled in with the GOT
5182 static struct mips_got_info
*
5183 mips_elf_got_info (abfd
, sgotp
)
5188 struct mips_got_info
*g
;
5190 sgot
= mips_elf_got_section (abfd
);
5191 BFD_ASSERT (sgot
!= NULL
);
5192 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5193 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5194 BFD_ASSERT (g
!= NULL
);
5201 /* Return whether a relocation is against a local symbol. */
5204 mips_elf_local_relocation_p (input_bfd
, relocation
, local_sections
,
5207 const Elf_Internal_Rela
*relocation
;
5208 asection
**local_sections
;
5209 boolean check_forced
;
5211 unsigned long r_symndx
;
5212 Elf_Internal_Shdr
*symtab_hdr
;
5213 struct mips_elf_link_hash_entry
* h
;
5216 r_symndx
= ELF32_R_SYM (relocation
->r_info
);
5217 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5218 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
5220 if (r_symndx
< extsymoff
)
5222 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
5227 /* Look up the hash table to check whether the symbol
5228 was forced local. */
5229 h
= (struct mips_elf_link_hash_entry
*)
5230 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
5231 /* Find the real hash-table entry for this symbol. */
5232 while (h
->root
.root
.type
== bfd_link_hash_indirect
5233 || h
->root
.root
.type
== bfd_link_hash_warning
)
5234 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
5235 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
5242 /* Sign-extend VALUE, which has the indicated number of BITS. */
5245 mips_elf_sign_extend (value
, bits
)
5249 if (value
& ((bfd_vma
)1 << (bits
- 1)))
5250 /* VALUE is negative. */
5251 value
|= ((bfd_vma
) - 1) << bits
;
5256 /* Return non-zero if the indicated VALUE has overflowed the maximum
5257 range expressable by a signed number with the indicated number of
5261 mips_elf_overflow_p (value
, bits
)
5265 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
5267 if (svalue
> (1 << (bits
- 1)) - 1)
5268 /* The value is too big. */
5270 else if (svalue
< -(1 << (bits
- 1)))
5271 /* The value is too small. */
5278 /* Calculate the %high function. */
5281 mips_elf_high (value
)
5284 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
5287 /* Calculate the %higher function. */
5290 mips_elf_higher (value
)
5291 bfd_vma value ATTRIBUTE_UNUSED
;
5294 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
5297 return (bfd_vma
) -1;
5301 /* Calculate the %highest function. */
5304 mips_elf_highest (value
)
5305 bfd_vma value ATTRIBUTE_UNUSED
;
5308 return ((value
+ (bfd_vma
) 0x800080008000) >> 48) & 0xffff;
5311 return (bfd_vma
) -1;
5315 /* Returns the GOT index for the global symbol indicated by H. */
5318 mips_elf_global_got_index (abfd
, h
)
5320 struct elf_link_hash_entry
*h
;
5324 struct mips_got_info
*g
;
5326 g
= mips_elf_got_info (abfd
, &sgot
);
5328 /* Once we determine the global GOT entry with the lowest dynamic
5329 symbol table index, we must put all dynamic symbols with greater
5330 indices into the GOT. That makes it easy to calculate the GOT
5332 BFD_ASSERT (h
->dynindx
>= g
->global_gotsym
->dynindx
);
5333 index
= ((h
->dynindx
- g
->global_gotsym
->dynindx
+ g
->local_gotno
)
5334 * MIPS_ELF_GOT_SIZE (abfd
));
5335 BFD_ASSERT (index
< sgot
->_raw_size
);
5340 /* Returns the offset for the entry at the INDEXth position
5344 mips_elf_got_offset_from_index (dynobj
, output_bfd
, index
)
5352 sgot
= mips_elf_got_section (dynobj
);
5353 gp
= _bfd_get_gp_value (output_bfd
);
5354 return (sgot
->output_section
->vma
+ sgot
->output_offset
+ index
-
5358 /* If H is a symbol that needs a global GOT entry, but has a dynamic
5359 symbol table index lower than any we've seen to date, record it for
5363 mips_elf_record_global_got_symbol (h
, info
, g
)
5364 struct elf_link_hash_entry
*h
;
5365 struct bfd_link_info
*info
;
5366 struct mips_got_info
*g ATTRIBUTE_UNUSED
;
5368 /* A global symbol in the GOT must also be in the dynamic symbol
5370 if (h
->dynindx
== -1
5371 && !bfd_elf32_link_record_dynamic_symbol (info
, h
))
5374 /* If we've already marked this entry as need GOT space, we don't
5375 need to do it again. */
5376 if (h
->got
.offset
!= (bfd_vma
) - 1)
5379 /* By setting this to a value other than -1, we are indicating that
5380 there needs to be a GOT entry for H. */
5386 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
5387 the dynamic symbols. */
5389 struct mips_elf_hash_sort_data
5391 /* The symbol in the global GOT with the lowest dynamic symbol table
5393 struct elf_link_hash_entry
*low
;
5394 /* The least dynamic symbol table index corresponding to a symbol
5395 with a GOT entry. */
5396 long min_got_dynindx
;
5397 /* The greatest dynamic symbol table index not corresponding to a
5398 symbol without a GOT entry. */
5399 long max_non_got_dynindx
;
5402 /* If H needs a GOT entry, assign it the highest available dynamic
5403 index. Otherwise, assign it the lowest available dynamic
5407 mips_elf_sort_hash_table_f (h
, data
)
5408 struct mips_elf_link_hash_entry
*h
;
5411 struct mips_elf_hash_sort_data
*hsd
5412 = (struct mips_elf_hash_sort_data
*) data
;
5414 /* Symbols without dynamic symbol table entries aren't interesting
5416 if (h
->root
.dynindx
== -1)
5419 if (h
->root
.got
.offset
!= 0)
5420 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
5423 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
5424 hsd
->low
= (struct elf_link_hash_entry
*) h
;
5430 /* Sort the dynamic symbol table so that symbols that need GOT entries
5431 appear towards the end. This reduces the amount of GOT space
5432 required. MAX_LOCAL is used to set the number of local symbols
5433 known to be in the dynamic symbol table. During
5434 mips_elf_size_dynamic_sections, this value is 1. Afterward, the
5435 section symbols are added and the count is higher. */
5438 mips_elf_sort_hash_table (info
, max_local
)
5439 struct bfd_link_info
*info
;
5440 unsigned long max_local
;
5442 struct mips_elf_hash_sort_data hsd
;
5443 struct mips_got_info
*g
;
5446 dynobj
= elf_hash_table (info
)->dynobj
;
5449 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
;
5450 hsd
.max_non_got_dynindx
= max_local
;
5451 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
5452 elf_hash_table (info
)),
5453 mips_elf_sort_hash_table_f
,
5456 /* There shoud have been enough room in the symbol table to
5457 accomodate both the GOT and non-GOT symbols. */
5458 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
5460 /* Now we know which dynamic symbol has the lowest dynamic symbol
5461 table index in the GOT. */
5462 g
= mips_elf_got_info (dynobj
, NULL
);
5463 g
->global_gotsym
= hsd
.low
;
5468 /* Create a local GOT entry for VALUE. Return the index of the entry,
5469 or -1 if it could not be created. */
5472 mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
)
5474 struct mips_got_info
*g
;
5478 if (g
->assigned_gotno
>= g
->local_gotno
)
5480 /* We didn't allocate enough space in the GOT. */
5481 (*_bfd_error_handler
)
5482 (_("not enough GOT space for local GOT entries"));
5483 bfd_set_error (bfd_error_bad_value
);
5484 return (bfd_vma
) -1;
5487 MIPS_ELF_PUT_WORD (abfd
, value
,
5489 + MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
));
5490 return MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
5493 /* Returns the GOT offset at which the indicated address can be found.
5494 If there is not yet a GOT entry for this value, create one. Returns
5495 -1 if no satisfactory GOT offset can be found. */
5498 mips_elf_local_got_index (abfd
, info
, value
)
5500 struct bfd_link_info
*info
;
5504 struct mips_got_info
*g
;
5507 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
5509 /* Look to see if we already have an appropriate entry. */
5510 for (entry
= (sgot
->contents
5511 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
5512 entry
!= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
5513 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
5515 bfd_vma address
= MIPS_ELF_GET_WORD (abfd
, entry
);
5516 if (address
== value
)
5517 return entry
- sgot
->contents
;
5520 return mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
5523 /* Find a GOT entry that is within 32KB of the VALUE. These entries
5524 are supposed to be placed at small offsets in the GOT, i.e.,
5525 within 32KB of GP. Return the index into the GOT for this page,
5526 and store the offset from this entry to the desired address in
5527 OFFSETP, if it is non-NULL. */
5530 mips_elf_got_page (abfd
, info
, value
, offsetp
)
5532 struct bfd_link_info
*info
;
5537 struct mips_got_info
*g
;
5539 bfd_byte
*last_entry
;
5543 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
5545 /* Look to see if we aleady have an appropriate entry. */
5546 last_entry
= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
5547 for (entry
= (sgot
->contents
5548 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
5549 entry
!= last_entry
;
5550 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
5552 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
5554 if (!mips_elf_overflow_p (value
- address
, 16))
5556 /* This entry will serve as the page pointer. We can add a
5557 16-bit number to it to get the actual address. */
5558 index
= entry
- sgot
->contents
;
5563 /* If we didn't have an appropriate entry, we create one now. */
5564 if (entry
== last_entry
)
5565 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
5569 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
5570 *offsetp
= value
- address
;
5576 /* Find a GOT entry whose higher-order 16 bits are the same as those
5577 for value. Return the index into the GOT for this entry. */
5580 mips_elf_got16_entry (abfd
, info
, value
, external
)
5582 struct bfd_link_info
*info
;
5587 struct mips_got_info
*g
;
5589 bfd_byte
*last_entry
;
5595 /* Although the ABI says that it is "the high-order 16 bits" that we
5596 want, it is really the %high value. The complete value is
5597 calculated with a `addiu' of a LO16 relocation, just as with a
5599 value
= mips_elf_high (value
) << 16;
5602 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
5604 /* Look to see if we already have an appropriate entry. */
5605 last_entry
= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
5606 for (entry
= (sgot
->contents
5607 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
5608 entry
!= last_entry
;
5609 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
5611 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
5612 if (address
== value
)
5614 /* This entry has the right high-order 16 bits, and the low-order
5615 16 bits are set to zero. */
5616 index
= entry
- sgot
->contents
;
5621 /* If we didn't have an appropriate entry, we create one now. */
5622 if (entry
== last_entry
)
5623 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
5628 /* Returns the first relocation of type r_type found, beginning with
5629 RELOCATION. RELEND is one-past-the-end of the relocation table. */
5631 static const Elf_Internal_Rela
*
5632 mips_elf_next_relocation (r_type
, relocation
, relend
)
5633 unsigned int r_type
;
5634 const Elf_Internal_Rela
*relocation
;
5635 const Elf_Internal_Rela
*relend
;
5637 /* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be
5638 immediately following. However, for the IRIX6 ABI, the next
5639 relocation may be a composed relocation consisting of several
5640 relocations for the same address. In that case, the R_MIPS_LO16
5641 relocation may occur as one of these. We permit a similar
5642 extension in general, as that is useful for GCC. */
5643 while (relocation
< relend
)
5645 if (ELF32_R_TYPE (relocation
->r_info
) == r_type
)
5651 /* We didn't find it. */
5652 bfd_set_error (bfd_error_bad_value
);
5656 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
5657 is the original relocation, which is now being transformed into a
5658 dynamic relocation. The ADDENDP is adjusted if necessary; the
5659 caller should store the result in place of the original addend. */
5662 mips_elf_create_dynamic_relocation (output_bfd
, info
, rel
, h
, sec
,
5663 symbol
, addendp
, input_section
)
5665 struct bfd_link_info
*info
;
5666 const Elf_Internal_Rela
*rel
;
5667 struct mips_elf_link_hash_entry
*h
;
5671 asection
*input_section
;
5673 Elf_Internal_Rel outrel
;
5679 r_type
= ELF32_R_TYPE (rel
->r_info
);
5680 dynobj
= elf_hash_table (info
)->dynobj
;
5682 = bfd_get_section_by_name (dynobj
,
5683 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd
));
5684 BFD_ASSERT (sreloc
!= NULL
);
5685 BFD_ASSERT (sreloc
->contents
!= NULL
);
5689 /* We begin by assuming that the offset for the dynamic relocation
5690 is the same as for the original relocation. We'll adjust this
5691 later to reflect the correct output offsets. */
5692 if (elf_section_data (input_section
)->stab_info
== NULL
)
5693 outrel
.r_offset
= rel
->r_offset
;
5696 /* Except that in a stab section things are more complex.
5697 Because we compress stab information, the offset given in the
5698 relocation may not be the one we want; we must let the stabs
5699 machinery tell us the offset. */
5701 = (_bfd_stab_section_offset
5702 (output_bfd
, &elf_hash_table (info
)->stab_info
,
5704 &elf_section_data (input_section
)->stab_info
,
5706 /* If we didn't need the relocation at all, this value will be
5708 if (outrel
.r_offset
== (bfd_vma
) -1)
5712 /* If we've decided to skip this relocation, just output an empty
5713 record. Note that R_MIPS_NONE == 0, so that this call to memset
5714 is a way of setting R_TYPE to R_MIPS_NONE. */
5716 memset (&outrel
, 0, sizeof (outrel
));
5720 bfd_vma section_offset
;
5722 /* We must now calculate the dynamic symbol table index to use
5723 in the relocation. */
5725 && (! info
->symbolic
|| (h
->root
.elf_link_hash_flags
5726 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5728 indx
= h
->root
.dynindx
;
5729 /* h->root.dynindx may be -1 if this symbol was marked to
5736 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5738 else if (sec
== NULL
|| sec
->owner
== NULL
)
5740 bfd_set_error (bfd_error_bad_value
);
5745 indx
= elf_section_data (sec
->output_section
)->dynindx
;
5750 /* Figure out how far the target of the relocation is from
5751 the beginning of its section. */
5752 section_offset
= symbol
- sec
->output_section
->vma
;
5753 /* The relocation we're building is section-relative.
5754 Therefore, the original addend must be adjusted by the
5756 *addendp
+= symbol
- sec
->output_section
->vma
;
5757 /* Now, the relocation is just against the section. */
5758 symbol
= sec
->output_section
->vma
;
5761 /* If the relocation was previously an absolute relocation, we
5762 must adjust it by the value we give it in the dynamic symbol
5764 if (r_type
!= R_MIPS_REL32
)
5767 /* The relocation is always an REL32 relocation because we don't
5768 know where the shared library will wind up at load-time. */
5769 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
5771 /* Adjust the output offset of the relocation to reference the
5772 correct location in the output file. */
5773 outrel
.r_offset
+= (input_section
->output_section
->vma
5774 + input_section
->output_offset
);
5777 /* Put the relocation back out. We have to use the special
5778 relocation outputter in the 64-bit case since the 64-bit
5779 relocation format is non-standard. */
5780 if (ABI_64_P (output_bfd
))
5782 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
5783 (output_bfd
, &outrel
,
5785 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
5788 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
5789 (((Elf32_External_Rel
*)
5791 + sreloc
->reloc_count
));
5793 /* Record the index of the first relocation referencing H. This
5794 information is later emitted in the .msym section. */
5796 && (h
->min_dyn_reloc_index
== 0
5797 || sreloc
->reloc_count
< h
->min_dyn_reloc_index
))
5798 h
->min_dyn_reloc_index
= sreloc
->reloc_count
;
5800 /* We've now added another relocation. */
5801 ++sreloc
->reloc_count
;
5803 /* Make sure the output section is writable. The dynamic linker
5804 will be writing to it. */
5805 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
5808 /* On IRIX5, make an entry of compact relocation info. */
5809 if (! skip
&& IRIX_COMPAT (output_bfd
) == ict_irix5
)
5811 asection
* scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5816 Elf32_crinfo cptrel
;
5818 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5819 cptrel
.vaddr
= (rel
->r_offset
5820 + input_section
->output_section
->vma
5821 + input_section
->output_offset
);
5822 if (r_type
== R_MIPS_REL32
)
5823 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5825 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5826 mips_elf_set_cr_dist2to (cptrel
, 0);
5827 cptrel
.konst
= *addendp
;
5829 cr
= (scpt
->contents
5830 + sizeof (Elf32_External_compact_rel
));
5831 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5832 ((Elf32_External_crinfo
*) cr
5833 + scpt
->reloc_count
));
5834 ++scpt
->reloc_count
;
5841 /* Calculate the value produced by the RELOCATION (which comes from
5842 the INPUT_BFD). The ADDEND is the addend to use for this
5843 RELOCATION; RELOCATION->R_ADDEND is ignored.
5845 The result of the relocation calculation is stored in VALUEP.
5846 REQUIRE_JALXP indicates whether or not the opcode used with this
5847 relocation must be JALX.
5849 This function returns bfd_reloc_continue if the caller need take no
5850 further action regarding this relocation, bfd_reloc_notsupported if
5851 something goes dramatically wrong, bfd_reloc_overflow if an
5852 overflow occurs, and bfd_reloc_ok to indicate success. */
5854 static bfd_reloc_status_type
5855 mips_elf_calculate_relocation (abfd
,
5869 asection
*input_section
;
5870 struct bfd_link_info
*info
;
5871 const Elf_Internal_Rela
*relocation
;
5873 reloc_howto_type
*howto
;
5874 Elf_Internal_Sym
*local_syms
;
5875 asection
**local_sections
;
5878 boolean
*require_jalxp
;
5880 /* The eventual value we will return. */
5882 /* The address of the symbol against which the relocation is
5885 /* The final GP value to be used for the relocatable, executable, or
5886 shared object file being produced. */
5887 bfd_vma gp
= (bfd_vma
) - 1;
5888 /* The place (section offset or address) of the storage unit being
5891 /* The value of GP used to create the relocatable object. */
5892 bfd_vma gp0
= (bfd_vma
) - 1;
5893 /* The offset into the global offset table at which the address of
5894 the relocation entry symbol, adjusted by the addend, resides
5895 during execution. */
5896 bfd_vma g
= (bfd_vma
) - 1;
5897 /* The section in which the symbol referenced by the relocation is
5899 asection
*sec
= NULL
;
5900 struct mips_elf_link_hash_entry
* h
= NULL
;
5901 /* True if the symbol referred to by this relocation is a local
5904 /* True if the symbol referred to by this relocation is "_gp_disp". */
5905 boolean gp_disp_p
= false;
5906 Elf_Internal_Shdr
*symtab_hdr
;
5908 unsigned long r_symndx
;
5910 /* True if overflow occurred during the calculation of the
5911 relocation value. */
5912 boolean overflowed_p
;
5913 /* True if this relocation refers to a MIPS16 function. */
5914 boolean target_is_16_bit_code_p
= false;
5916 /* Parse the relocation. */
5917 r_symndx
= ELF32_R_SYM (relocation
->r_info
);
5918 r_type
= ELF32_R_TYPE (relocation
->r_info
);
5919 p
= (input_section
->output_section
->vma
5920 + input_section
->output_offset
5921 + relocation
->r_offset
);
5923 /* Assume that there will be no overflow. */
5924 overflowed_p
= false;
5926 /* Figure out whether or not the symbol is local, and get the offset
5927 used in the array of hash table entries. */
5928 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5929 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
5930 local_sections
, false);
5931 if (! elf_bad_symtab (input_bfd
))
5932 extsymoff
= symtab_hdr
->sh_info
;
5935 /* The symbol table does not follow the rule that local symbols
5936 must come before globals. */
5940 /* Figure out the value of the symbol. */
5943 Elf_Internal_Sym
*sym
;
5945 sym
= local_syms
+ r_symndx
;
5946 sec
= local_sections
[r_symndx
];
5948 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
5949 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5950 symbol
+= sym
->st_value
;
5952 /* MIPS16 text labels should be treated as odd. */
5953 if (sym
->st_other
== STO_MIPS16
)
5956 /* Record the name of this symbol, for our caller. */
5957 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
5958 symtab_hdr
->sh_link
,
5961 *namep
= bfd_section_name (input_bfd
, sec
);
5963 target_is_16_bit_code_p
= (sym
->st_other
== STO_MIPS16
);
5967 /* For global symbols we look up the symbol in the hash-table. */
5968 h
= ((struct mips_elf_link_hash_entry
*)
5969 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
5970 /* Find the real hash-table entry for this symbol. */
5971 while (h
->root
.root
.type
== bfd_link_hash_indirect
5972 || h
->root
.root
.type
== bfd_link_hash_warning
)
5973 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
5975 /* Record the name of this symbol, for our caller. */
5976 *namep
= h
->root
.root
.root
.string
;
5978 /* See if this is the special _gp_disp symbol. Note that such a
5979 symbol must always be a global symbol. */
5980 if (strcmp (h
->root
.root
.root
.string
, "_gp_disp") == 0)
5982 /* Relocations against _gp_disp are permitted only with
5983 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
5984 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_LO16
)
5985 return bfd_reloc_notsupported
;
5989 /* If this symbol is defined, calculate its address. Note that
5990 _gp_disp is a magic symbol, always implicitly defined by the
5991 linker, so it's inappropriate to check to see whether or not
5993 else if ((h
->root
.root
.type
== bfd_link_hash_defined
5994 || h
->root
.root
.type
== bfd_link_hash_defweak
)
5995 && h
->root
.root
.u
.def
.section
)
5997 sec
= h
->root
.root
.u
.def
.section
;
5998 if (sec
->output_section
)
5999 symbol
= (h
->root
.root
.u
.def
.value
6000 + sec
->output_section
->vma
6001 + sec
->output_offset
);
6003 symbol
= h
->root
.root
.u
.def
.value
;
6005 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
6006 /* We allow relocations against undefined weak symbols, giving
6007 it the value zero, so that you can undefined weak functions
6008 and check to see if they exist by looking at their
6011 else if (info
->shared
&& !info
->symbolic
&& !info
->no_undefined
6012 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
6014 else if (strcmp (h
->root
.root
.root
.string
, "_DYNAMIC_LINK") == 0)
6016 /* If this is a dynamic link, we should have created a
6017 _DYNAMIC_LINK symbol in mips_elf_create_dynamic_sections.
6018 Otherwise, we should define the symbol with a value of 0.
6019 FIXME: It should probably get into the symbol table
6021 BFD_ASSERT (! info
->shared
);
6022 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
6027 if (! ((*info
->callbacks
->undefined_symbol
)
6028 (info
, h
->root
.root
.root
.string
, input_bfd
,
6029 input_section
, relocation
->r_offset
,
6030 (!info
->shared
|| info
->no_undefined
6031 || ELF_ST_VISIBILITY (h
->root
.other
)))))
6032 return bfd_reloc_undefined
;
6036 target_is_16_bit_code_p
= (h
->root
.other
== STO_MIPS16
);
6039 /* If this is a 32-bit call to a 16-bit function with a stub, we
6040 need to redirect the call to the stub, unless we're already *in*
6042 if (r_type
!= R_MIPS16_26
&& !info
->relocateable
6043 && ((h
!= NULL
&& h
->fn_stub
!= NULL
)
6044 || (local_p
&& elf_tdata (input_bfd
)->local_stubs
!= NULL
6045 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
6046 && !mips_elf_stub_section_p (input_bfd
, input_section
))
6048 /* This is a 32-bit call to a 16-bit function. We should
6049 have already noticed that we were going to need the
6052 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
6055 BFD_ASSERT (h
->need_fn_stub
);
6059 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
6061 /* If this is a 16-bit call to a 32-bit function with a stub, we
6062 need to redirect the call to the stub. */
6063 else if (r_type
== R_MIPS16_26
&& !info
->relocateable
6065 && (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
)
6066 && !target_is_16_bit_code_p
)
6068 /* If both call_stub and call_fp_stub are defined, we can figure
6069 out which one to use by seeing which one appears in the input
6071 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
6076 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
6078 if (strncmp (bfd_get_section_name (input_bfd
, o
),
6079 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6081 sec
= h
->call_fp_stub
;
6088 else if (h
->call_stub
!= NULL
)
6091 sec
= h
->call_fp_stub
;
6093 BFD_ASSERT (sec
->_raw_size
> 0);
6094 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
6097 /* Calls from 16-bit code to 32-bit code and vice versa require the
6098 special jalx instruction. */
6099 *require_jalxp
= (!info
->relocateable
6100 && ((r_type
== R_MIPS16_26
) != target_is_16_bit_code_p
));
6102 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
6103 local_sections
, true);
6105 /* If we haven't already determined the GOT offset, or the GP value,
6106 and we're going to need it, get it now. */
6111 case R_MIPS_GOT_DISP
:
6112 case R_MIPS_GOT_HI16
:
6113 case R_MIPS_CALL_HI16
:
6114 case R_MIPS_GOT_LO16
:
6115 case R_MIPS_CALL_LO16
:
6116 /* Find the index into the GOT where this value is located. */
6119 BFD_ASSERT (addend
== 0);
6120 g
= mips_elf_global_got_index
6121 (elf_hash_table (info
)->dynobj
,
6122 (struct elf_link_hash_entry
*) h
);
6123 if (! elf_hash_table(info
)->dynamic_sections_created
6125 && (info
->symbolic
|| h
->root
.dynindx
== -1)
6126 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
6128 /* This is a static link or a -Bsymbolic link. The
6129 symbol is defined locally, or was forced to be local.
6130 We must initialize this entry in the GOT. */
6131 asection
*sgot
= mips_elf_got_section(elf_hash_table
6133 MIPS_ELF_PUT_WORD (elf_hash_table (info
)->dynobj
,
6134 symbol
+ addend
, sgot
->contents
+ g
);
6137 else if (r_type
== R_MIPS_GOT16
)
6138 /* There's no need to create a local GOT entry here; the
6139 calculation for a local GOT16 entry does not involve G. */
6143 g
= mips_elf_local_got_index (abfd
, info
, symbol
+ addend
);
6144 if (g
== (bfd_vma
) -1)
6148 /* Convert GOT indices to actual offsets. */
6149 g
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
6155 case R_MIPS_GPREL16
:
6156 case R_MIPS_GPREL32
:
6157 case R_MIPS_LITERAL
:
6158 gp0
= _bfd_get_gp_value (input_bfd
);
6159 gp
= _bfd_get_gp_value (abfd
);
6166 /* Figure out what kind of relocation is being performed. */
6170 return bfd_reloc_continue
;
6173 value
= symbol
+ mips_elf_sign_extend (addend
, 16);
6174 overflowed_p
= mips_elf_overflow_p (value
, 16);
6181 || (elf_hash_table (info
)->dynamic_sections_created
6183 && ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)
6185 && (input_section
->flags
& SEC_ALLOC
) != 0)
6187 /* If we're creating a shared library, or this relocation is
6188 against a symbol in a shared library, then we can't know
6189 where the symbol will end up. So, we create a relocation
6190 record in the output, and leave the job up to the dynamic
6193 if (!mips_elf_create_dynamic_relocation (abfd
,
6205 if (r_type
!= R_MIPS_REL32
)
6206 value
= symbol
+ addend
;
6210 value
&= howto
->dst_mask
;
6215 case R_MIPS_GNU_REL_LO16
:
6216 value
= symbol
+ addend
- p
;
6217 value
&= howto
->dst_mask
;
6220 case R_MIPS_GNU_REL16_S2
:
6221 value
= symbol
+ mips_elf_sign_extend (addend
<< 2, 18) - p
;
6222 overflowed_p
= mips_elf_overflow_p (value
, 18);
6223 value
= (value
>> 2) & howto
->dst_mask
;
6226 case R_MIPS_GNU_REL_HI16
:
6227 value
= mips_elf_high (addend
+ symbol
- p
);
6228 value
&= howto
->dst_mask
;
6232 /* The calculation for R_MIPS_26 is just the same as for an
6233 R_MIPS_26. It's only the storage of the relocated field into
6234 the output file that's different. That's handled in
6235 mips_elf_perform_relocation. So, we just fall through to the
6236 R_MIPS_26 case here. */
6239 value
= (((addend
<< 2) | (p
& 0xf0000000)) + symbol
) >> 2;
6241 value
= (mips_elf_sign_extend (addend
<< 2, 28) + symbol
) >> 2;
6242 value
&= howto
->dst_mask
;
6248 value
= mips_elf_high (addend
+ symbol
);
6249 value
&= howto
->dst_mask
;
6253 value
= mips_elf_high (addend
+ gp
- p
);
6254 overflowed_p
= mips_elf_overflow_p (value
, 16);
6260 value
= (symbol
+ addend
) & howto
->dst_mask
;
6263 value
= addend
+ gp
- p
+ 4;
6264 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
6265 for overflow. But, on, say, Irix 5, relocations against
6266 _gp_disp are normally generated from the .cpload
6267 pseudo-op. It generates code that normally looks like
6270 lui $gp,%hi(_gp_disp)
6271 addiu $gp,$gp,%lo(_gp_disp)
6274 Here $t9 holds the address of the function being called,
6275 as required by the MIPS ELF ABI. The R_MIPS_LO16
6276 relocation can easily overflow in this situation, but the
6277 R_MIPS_HI16 relocation will handle the overflow.
6278 Therefore, we consider this a bug in the MIPS ABI, and do
6279 not check for overflow here. */
6283 case R_MIPS_LITERAL
:
6284 /* Because we don't merge literal sections, we can handle this
6285 just like R_MIPS_GPREL16. In the long run, we should merge
6286 shared literals, and then we will need to additional work
6291 case R_MIPS16_GPREL
:
6292 /* The R_MIPS16_GPREL performs the same calculation as
6293 R_MIPS_GPREL16, but stores the relocated bits in a different
6294 order. We don't need to do anything special here; the
6295 differences are handled in mips_elf_perform_relocation. */
6296 case R_MIPS_GPREL16
:
6298 value
= mips_elf_sign_extend (addend
, 16) + symbol
+ gp0
- gp
;
6300 value
= mips_elf_sign_extend (addend
, 16) + symbol
- gp
;
6301 overflowed_p
= mips_elf_overflow_p (value
, 16);
6309 /* The special case is when the symbol is forced to be local. We
6310 need the full address in the GOT since no R_MIPS_LO16 relocation
6312 forced
= ! mips_elf_local_relocation_p (input_bfd
, relocation
,
6313 local_sections
, false);
6314 value
= mips_elf_got16_entry (abfd
, info
, symbol
+ addend
, forced
);
6315 if (value
== (bfd_vma
) -1)
6318 = mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
6321 overflowed_p
= mips_elf_overflow_p (value
, 16);
6328 case R_MIPS_GOT_DISP
:
6330 overflowed_p
= mips_elf_overflow_p (value
, 16);
6333 case R_MIPS_GPREL32
:
6334 value
= (addend
+ symbol
+ gp0
- gp
) & howto
->dst_mask
;
6338 value
= mips_elf_sign_extend (addend
, 16) + symbol
- p
;
6339 value
= (bfd_vma
) ((bfd_signed_vma
) value
/ 4);
6340 overflowed_p
= mips_elf_overflow_p (value
, 16);
6343 case R_MIPS_GOT_HI16
:
6344 case R_MIPS_CALL_HI16
:
6345 /* We're allowed to handle these two relocations identically.
6346 The dynamic linker is allowed to handle the CALL relocations
6347 differently by creating a lazy evaluation stub. */
6349 value
= mips_elf_high (value
);
6350 value
&= howto
->dst_mask
;
6353 case R_MIPS_GOT_LO16
:
6354 case R_MIPS_CALL_LO16
:
6355 value
= g
& howto
->dst_mask
;
6358 case R_MIPS_GOT_PAGE
:
6359 value
= mips_elf_got_page (abfd
, info
, symbol
+ addend
, NULL
);
6360 if (value
== (bfd_vma
) -1)
6362 value
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
6365 overflowed_p
= mips_elf_overflow_p (value
, 16);
6368 case R_MIPS_GOT_OFST
:
6369 mips_elf_got_page (abfd
, info
, symbol
+ addend
, &value
);
6370 overflowed_p
= mips_elf_overflow_p (value
, 16);
6374 value
= symbol
- addend
;
6375 value
&= howto
->dst_mask
;
6379 value
= mips_elf_higher (addend
+ symbol
);
6380 value
&= howto
->dst_mask
;
6383 case R_MIPS_HIGHEST
:
6384 value
= mips_elf_highest (addend
+ symbol
);
6385 value
&= howto
->dst_mask
;
6388 case R_MIPS_SCN_DISP
:
6389 value
= symbol
+ addend
- sec
->output_offset
;
6390 value
&= howto
->dst_mask
;
6395 /* Both of these may be ignored. R_MIPS_JALR is an optimization
6396 hint; we could improve performance by honoring that hint. */
6397 return bfd_reloc_continue
;
6399 case R_MIPS_GNU_VTINHERIT
:
6400 case R_MIPS_GNU_VTENTRY
:
6401 /* We don't do anything with these at present. */
6402 return bfd_reloc_continue
;
6405 /* An unrecognized relocation type. */
6406 return bfd_reloc_notsupported
;
6409 /* Store the VALUE for our caller. */
6411 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
6414 /* Obtain the field relocated by RELOCATION. */
6417 mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
)
6418 reloc_howto_type
*howto
;
6419 const Elf_Internal_Rela
*relocation
;
6424 bfd_byte
*location
= contents
+ relocation
->r_offset
;
6426 /* Obtain the bytes. */
6427 x
= bfd_get (8 * bfd_get_reloc_size (howto
), input_bfd
, location
);
6429 if ((ELF32_R_TYPE (relocation
->r_info
) == R_MIPS16_26
6430 || ELF32_R_TYPE (relocation
->r_info
) == R_MIPS16_GPREL
)
6431 && bfd_little_endian (input_bfd
))
6432 /* The two 16-bit words will be reversed on a little-endian
6433 system. See mips_elf_perform_relocation for more details. */
6434 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
6439 /* It has been determined that the result of the RELOCATION is the
6440 VALUE. Use HOWTO to place VALUE into the output file at the
6441 appropriate position. The SECTION is the section to which the
6442 relocation applies. If REQUIRE_JALX is true, then the opcode used
6443 for the relocation must be either JAL or JALX, and it is
6444 unconditionally converted to JALX.
6446 Returns false if anything goes wrong. */
6449 mips_elf_perform_relocation (info
, howto
, relocation
, value
,
6450 input_bfd
, input_section
,
6451 contents
, require_jalx
)
6452 struct bfd_link_info
*info
;
6453 reloc_howto_type
*howto
;
6454 const Elf_Internal_Rela
*relocation
;
6457 asection
*input_section
;
6459 boolean require_jalx
;
6463 int r_type
= ELF32_R_TYPE (relocation
->r_info
);
6465 /* Figure out where the relocation is occurring. */
6466 location
= contents
+ relocation
->r_offset
;
6468 /* Obtain the current value. */
6469 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
6471 /* Clear the field we are setting. */
6472 x
&= ~howto
->dst_mask
;
6474 /* If this is the R_MIPS16_26 relocation, we must store the
6475 value in a funny way. */
6476 if (r_type
== R_MIPS16_26
)
6478 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
6479 Most mips16 instructions are 16 bits, but these instructions
6482 The format of these instructions is:
6484 +--------------+--------------------------------+
6485 ! JALX ! X! Imm 20:16 ! Imm 25:21 !
6486 +--------------+--------------------------------+
6488 +-----------------------------------------------+
6490 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
6491 Note that the immediate value in the first word is swapped.
6493 When producing a relocateable object file, R_MIPS16_26 is
6494 handled mostly like R_MIPS_26. In particular, the addend is
6495 stored as a straight 26-bit value in a 32-bit instruction.
6496 (gas makes life simpler for itself by never adjusting a
6497 R_MIPS16_26 reloc to be against a section, so the addend is
6498 always zero). However, the 32 bit instruction is stored as 2
6499 16-bit values, rather than a single 32-bit value. In a
6500 big-endian file, the result is the same; in a little-endian
6501 file, the two 16-bit halves of the 32 bit value are swapped.
6502 This is so that a disassembler can recognize the jal
6505 When doing a final link, R_MIPS16_26 is treated as a 32 bit
6506 instruction stored as two 16-bit values. The addend A is the
6507 contents of the targ26 field. The calculation is the same as
6508 R_MIPS_26. When storing the calculated value, reorder the
6509 immediate value as shown above, and don't forget to store the
6510 value as two 16-bit values.
6512 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
6516 +--------+----------------------+
6520 +--------+----------------------+
6523 +----------+------+-------------+
6527 +----------+--------------------+
6528 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
6529 ((sub1 << 16) | sub2)).
6531 When producing a relocateable object file, the calculation is
6532 (((A < 2) | (P & 0xf0000000) + S) >> 2)
6533 When producing a fully linked file, the calculation is
6534 let R = (((A < 2) | (P & 0xf0000000) + S) >> 2)
6535 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff) */
6537 if (!info
->relocateable
)
6538 /* Shuffle the bits according to the formula above. */
6539 value
= (((value
& 0x1f0000) << 5)
6540 | ((value
& 0x3e00000) >> 5)
6541 | (value
& 0xffff));
6544 else if (r_type
== R_MIPS16_GPREL
)
6546 /* R_MIPS16_GPREL is used for GP-relative addressing in mips16
6547 mode. A typical instruction will have a format like this:
6549 +--------------+--------------------------------+
6550 ! EXTEND ! Imm 10:5 ! Imm 15:11 !
6551 +--------------+--------------------------------+
6552 ! Major ! rx ! ry ! Imm 4:0 !
6553 +--------------+--------------------------------+
6555 EXTEND is the five bit value 11110. Major is the instruction
6558 This is handled exactly like R_MIPS_GPREL16, except that the
6559 addend is retrieved and stored as shown in this diagram; that
6560 is, the Imm fields above replace the V-rel16 field.
6562 All we need to do here is shuffle the bits appropriately. As
6563 above, the two 16-bit halves must be swapped on a
6564 little-endian system. */
6565 value
= (((value
& 0x7e0) << 16)
6566 | ((value
& 0xf800) << 5)
6570 /* Set the field. */
6571 x
|= (value
& howto
->dst_mask
);
6573 /* If required, turn JAL into JALX. */
6577 bfd_vma opcode
= x
>> 26;
6578 bfd_vma jalx_opcode
;
6580 /* Check to see if the opcode is already JAL or JALX. */
6581 if (r_type
== R_MIPS16_26
)
6583 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
6588 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
6592 /* If the opcode is not JAL or JALX, there's a problem. */
6595 (*_bfd_error_handler
)
6596 (_("%s: %s+0x%lx: jump to stub routine which is not jal"),
6597 bfd_get_filename (input_bfd
),
6598 input_section
->name
,
6599 (unsigned long) relocation
->r_offset
);
6600 bfd_set_error (bfd_error_bad_value
);
6604 /* Make this the JALX opcode. */
6605 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
6608 /* Swap the high- and low-order 16 bits on little-endian systems
6609 when doing a MIPS16 relocation. */
6610 if ((r_type
== R_MIPS16_GPREL
|| r_type
== R_MIPS16_26
)
6611 && bfd_little_endian (input_bfd
))
6612 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
6614 /* Put the value into the output. */
6615 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
6619 /* Returns true if SECTION is a MIPS16 stub section. */
6622 mips_elf_stub_section_p (abfd
, section
)
6623 bfd
*abfd ATTRIBUTE_UNUSED
;
6626 const char *name
= bfd_get_section_name (abfd
, section
);
6628 return (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0
6629 || strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
6630 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0);
6633 /* Relocate a MIPS ELF section. */
6636 _bfd_mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
6637 contents
, relocs
, local_syms
, local_sections
)
6639 struct bfd_link_info
*info
;
6641 asection
*input_section
;
6643 Elf_Internal_Rela
*relocs
;
6644 Elf_Internal_Sym
*local_syms
;
6645 asection
**local_sections
;
6647 Elf_Internal_Rela
*rel
;
6648 const Elf_Internal_Rela
*relend
;
6650 boolean use_saved_addend_p
= false;
6651 struct elf_backend_data
*bed
;
6653 bed
= get_elf_backend_data (output_bfd
);
6654 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
6655 for (rel
= relocs
; rel
< relend
; ++rel
)
6659 reloc_howto_type
*howto
;
6660 boolean require_jalx
;
6661 /* True if the relocation is a RELA relocation, rather than a
6663 boolean rela_relocation_p
= true;
6664 int r_type
= ELF32_R_TYPE (rel
->r_info
);
6666 /* Find the relocation howto for this relocation. */
6667 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
))
6669 /* Some 32-bit code uses R_MIPS_64. In particular, people use
6670 64-bit code, but make sure all their addresses are in the
6671 lowermost or uppermost 32-bit section of the 64-bit address
6672 space. Thus, when they use an R_MIPS_64 they mean what is
6673 usually meant by R_MIPS_32, with the exception that the
6674 stored value is sign-extended to 64 bits. */
6675 howto
= elf_mips_howto_table
+ R_MIPS_32
;
6677 /* On big-endian systems, we need to lie about the position
6679 if (bfd_big_endian (input_bfd
))
6683 howto
= mips_rtype_to_howto (r_type
);
6685 if (!use_saved_addend_p
)
6687 Elf_Internal_Shdr
*rel_hdr
;
6689 /* If these relocations were originally of the REL variety,
6690 we must pull the addend out of the field that will be
6691 relocated. Otherwise, we simply use the contents of the
6692 RELA relocation. To determine which flavor or relocation
6693 this is, we depend on the fact that the INPUT_SECTION's
6694 REL_HDR is read before its REL_HDR2. */
6695 rel_hdr
= &elf_section_data (input_section
)->rel_hdr
;
6696 if ((size_t) (rel
- relocs
)
6697 >= (rel_hdr
->sh_size
/ rel_hdr
->sh_entsize
6698 * bed
->s
->int_rels_per_ext_rel
))
6699 rel_hdr
= elf_section_data (input_section
)->rel_hdr2
;
6700 if (rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (input_bfd
))
6702 /* Note that this is a REL relocation. */
6703 rela_relocation_p
= false;
6705 /* Get the addend, which is stored in the input file. */
6706 addend
= mips_elf_obtain_contents (howto
,
6710 addend
&= howto
->src_mask
;
6712 /* For some kinds of relocations, the ADDEND is a
6713 combination of the addend stored in two different
6715 if (r_type
== R_MIPS_HI16
6716 || r_type
== R_MIPS_GNU_REL_HI16
6717 || (r_type
== R_MIPS_GOT16
6718 && mips_elf_local_relocation_p (input_bfd
, rel
,
6719 local_sections
, false)))
6722 const Elf_Internal_Rela
*lo16_relocation
;
6723 reloc_howto_type
*lo16_howto
;
6726 /* The combined value is the sum of the HI16 addend,
6727 left-shifted by sixteen bits, and the LO16
6728 addend, sign extended. (Usually, the code does
6729 a `lui' of the HI16 value, and then an `addiu' of
6732 Scan ahead to find a matching LO16 relocation. */
6733 if (r_type
== R_MIPS_GNU_REL_HI16
)
6734 lo
= R_MIPS_GNU_REL_LO16
;
6738 = mips_elf_next_relocation (lo
, rel
, relend
);
6739 if (lo16_relocation
== NULL
)
6742 /* Obtain the addend kept there. */
6743 lo16_howto
= mips_rtype_to_howto (lo
);
6744 l
= mips_elf_obtain_contents (lo16_howto
,
6746 input_bfd
, contents
);
6747 l
&= lo16_howto
->src_mask
;
6748 l
= mips_elf_sign_extend (l
, 16);
6752 /* Compute the combined addend. */
6755 else if (r_type
== R_MIPS16_GPREL
)
6757 /* The addend is scrambled in the object file. See
6758 mips_elf_perform_relocation for details on the
6760 addend
= (((addend
& 0x1f0000) >> 5)
6761 | ((addend
& 0x7e00000) >> 16)
6766 addend
= rel
->r_addend
;
6769 if (info
->relocateable
)
6771 Elf_Internal_Sym
*sym
;
6772 unsigned long r_symndx
;
6774 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
)
6775 && bfd_big_endian (input_bfd
))
6778 /* Since we're just relocating, all we need to do is copy
6779 the relocations back out to the object file, unless
6780 they're against a section symbol, in which case we need
6781 to adjust by the section offset, or unless they're GP
6782 relative in which case we need to adjust by the amount
6783 that we're adjusting GP in this relocateable object. */
6785 if (!mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
,
6787 /* There's nothing to do for non-local relocations. */
6790 if (r_type
== R_MIPS16_GPREL
6791 || r_type
== R_MIPS_GPREL16
6792 || r_type
== R_MIPS_GPREL32
6793 || r_type
== R_MIPS_LITERAL
)
6794 addend
-= (_bfd_get_gp_value (output_bfd
)
6795 - _bfd_get_gp_value (input_bfd
));
6796 else if (r_type
== R_MIPS_26
|| r_type
== R_MIPS16_26
6797 || r_type
== R_MIPS_GNU_REL16_S2
)
6798 /* The addend is stored without its two least
6799 significant bits (which are always zero.) In a
6800 non-relocateable link, calculate_relocation will do
6801 this shift; here, we must do it ourselves. */
6804 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6805 sym
= local_syms
+ r_symndx
;
6806 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
6807 /* Adjust the addend appropriately. */
6808 addend
+= local_sections
[r_symndx
]->output_offset
;
6810 /* If the relocation is for a R_MIPS_HI16 or R_MIPS_GOT16,
6811 then we only want to write out the high-order 16 bits.
6812 The subsequent R_MIPS_LO16 will handle the low-order bits. */
6813 if (r_type
== R_MIPS_HI16
|| r_type
== R_MIPS_GOT16
6814 || r_type
== R_MIPS_GNU_REL_HI16
)
6815 addend
= mips_elf_high (addend
);
6816 /* If the relocation is for an R_MIPS_26 relocation, then
6817 the two low-order bits are not stored in the object file;
6818 they are implicitly zero. */
6819 else if (r_type
== R_MIPS_26
|| r_type
== R_MIPS16_26
6820 || r_type
== R_MIPS_GNU_REL16_S2
)
6823 if (rela_relocation_p
)
6824 /* If this is a RELA relocation, just update the addend.
6825 We have to cast away constness for REL. */
6826 rel
->r_addend
= addend
;
6829 /* Otherwise, we have to write the value back out. Note
6830 that we use the source mask, rather than the
6831 destination mask because the place to which we are
6832 writing will be source of the addend in the final
6834 addend
&= howto
->src_mask
;
6836 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
))
6837 /* See the comment above about using R_MIPS_64 in the 32-bit
6838 ABI. Here, we need to update the addend. It would be
6839 possible to get away with just using the R_MIPS_32 reloc
6840 but for endianness. */
6846 if (addend
& ((bfd_vma
) 1 << 31))
6847 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
6851 /* If we don't know that we have a 64-bit type,
6852 do two separate stores. */
6853 if (bfd_big_endian (input_bfd
))
6855 /* Store the sign-bits (which are most significant)
6857 low_bits
= sign_bits
;
6863 high_bits
= sign_bits
;
6865 bfd_put_32 (input_bfd
, low_bits
,
6866 contents
+ rel
->r_offset
);
6867 bfd_put_32 (input_bfd
, high_bits
,
6868 contents
+ rel
->r_offset
+ 4);
6872 if (!mips_elf_perform_relocation (info
, howto
, rel
, addend
,
6873 input_bfd
, input_section
,
6878 /* Go on to the next relocation. */
6882 /* In the N32 and 64-bit ABIs there may be multiple consecutive
6883 relocations for the same offset. In that case we are
6884 supposed to treat the output of each relocation as the addend
6886 if (rel
+ 1 < relend
6887 && rel
->r_offset
== rel
[1].r_offset
6888 && ELF32_R_TYPE (rel
[1].r_info
) != R_MIPS_NONE
)
6889 use_saved_addend_p
= true;
6891 use_saved_addend_p
= false;
6893 /* Figure out what value we are supposed to relocate. */
6894 switch (mips_elf_calculate_relocation (output_bfd
,
6907 case bfd_reloc_continue
:
6908 /* There's nothing to do. */
6911 case bfd_reloc_undefined
:
6912 /* mips_elf_calculate_relocation already called the
6913 undefined_symbol callback. There's no real point in
6914 trying to perform the relocation at this point, so we
6915 just skip ahead to the next relocation. */
6918 case bfd_reloc_notsupported
:
6922 case bfd_reloc_overflow
:
6923 if (use_saved_addend_p
)
6924 /* Ignore overflow until we reach the last relocation for
6925 a given location. */
6929 BFD_ASSERT (name
!= NULL
);
6930 if (! ((*info
->callbacks
->reloc_overflow
)
6931 (info
, name
, howto
->name
, (bfd_vma
) 0,
6932 input_bfd
, input_section
, rel
->r_offset
)))
6945 /* If we've got another relocation for the address, keep going
6946 until we reach the last one. */
6947 if (use_saved_addend_p
)
6953 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
))
6954 /* See the comment above about using R_MIPS_64 in the 32-bit
6955 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
6956 that calculated the right value. Now, however, we
6957 sign-extend the 32-bit result to 64-bits, and store it as a
6958 64-bit value. We are especially generous here in that we
6959 go to extreme lengths to support this usage on systems with
6960 only a 32-bit VMA. */
6966 if (value
& ((bfd_vma
) 1 << 31))
6967 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
6971 /* If we don't know that we have a 64-bit type,
6972 do two separate stores. */
6973 if (bfd_big_endian (input_bfd
))
6975 /* Undo what we did above. */
6977 /* Store the sign-bits (which are most significant)
6979 low_bits
= sign_bits
;
6985 high_bits
= sign_bits
;
6987 bfd_put_32 (input_bfd
, low_bits
,
6988 contents
+ rel
->r_offset
);
6989 bfd_put_32 (input_bfd
, high_bits
,
6990 contents
+ rel
->r_offset
+ 4);
6994 /* Actually perform the relocation. */
6995 if (!mips_elf_perform_relocation (info
, howto
, rel
, value
, input_bfd
,
6996 input_section
, contents
,
7004 /* This hook function is called before the linker writes out a global
7005 symbol. We mark symbols as small common if appropriate. This is
7006 also where we undo the increment of the value for a mips16 symbol. */
7010 _bfd_mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
7011 bfd
*abfd ATTRIBUTE_UNUSED
;
7012 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
7013 const char *name ATTRIBUTE_UNUSED
;
7014 Elf_Internal_Sym
*sym
;
7015 asection
*input_sec
;
7017 /* If we see a common symbol, which implies a relocatable link, then
7018 if a symbol was small common in an input file, mark it as small
7019 common in the output file. */
7020 if (sym
->st_shndx
== SHN_COMMON
7021 && strcmp (input_sec
->name
, ".scommon") == 0)
7022 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
7024 if (sym
->st_other
== STO_MIPS16
7025 && (sym
->st_value
& 1) != 0)
7031 /* Functions for the dynamic linker. */
7033 /* The name of the dynamic interpreter. This is put in the .interp
7036 #define ELF_DYNAMIC_INTERPRETER(abfd) \
7037 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
7038 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
7039 : "/usr/lib/libc.so.1")
7041 /* Create dynamic sections when linking against a dynamic object. */
7044 _bfd_mips_elf_create_dynamic_sections (abfd
, info
)
7046 struct bfd_link_info
*info
;
7048 struct elf_link_hash_entry
*h
;
7050 register asection
*s
;
7051 const char * const *namep
;
7053 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7054 | SEC_LINKER_CREATED
| SEC_READONLY
);
7056 /* Mips ABI requests the .dynamic section to be read only. */
7057 s
= bfd_get_section_by_name (abfd
, ".dynamic");
7060 if (! bfd_set_section_flags (abfd
, s
, flags
))
7064 /* We need to create .got section. */
7065 if (! mips_elf_create_got_section (abfd
, info
))
7068 /* Create the .msym section on IRIX6. It is used by the dynamic
7069 linker to speed up dynamic relocations, and to avoid computing
7070 the ELF hash for symbols. */
7071 if (IRIX_COMPAT (abfd
) == ict_irix6
7072 && !mips_elf_create_msym_section (abfd
))
7075 /* Create .stub section. */
7076 if (bfd_get_section_by_name (abfd
,
7077 MIPS_ELF_STUB_SECTION_NAME (abfd
)) == NULL
)
7079 s
= bfd_make_section (abfd
, MIPS_ELF_STUB_SECTION_NAME (abfd
));
7081 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_CODE
)
7082 || ! bfd_set_section_alignment (abfd
, s
,
7083 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7087 if (IRIX_COMPAT (abfd
) == ict_irix5
7089 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
7091 s
= bfd_make_section (abfd
, ".rld_map");
7093 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
7094 || ! bfd_set_section_alignment (abfd
, s
,
7095 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7099 /* On IRIX5, we adjust add some additional symbols and change the
7100 alignments of several sections. There is no ABI documentation
7101 indicating that this is necessary on IRIX6, nor any evidence that
7102 the linker takes such action. */
7103 if (IRIX_COMPAT (abfd
) == ict_irix5
)
7105 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
7108 if (! (_bfd_generic_link_add_one_symbol
7109 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
7110 (bfd_vma
) 0, (const char *) NULL
, false,
7111 get_elf_backend_data (abfd
)->collect
,
7112 (struct bfd_link_hash_entry
**) &h
)))
7114 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
7115 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7116 h
->type
= STT_SECTION
;
7118 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7122 /* We need to create a .compact_rel section. */
7123 if (! mips_elf_create_compact_rel_section (abfd
, info
))
7126 /* Change aligments of some sections. */
7127 s
= bfd_get_section_by_name (abfd
, ".hash");
7129 bfd_set_section_alignment (abfd
, s
, 4);
7130 s
= bfd_get_section_by_name (abfd
, ".dynsym");
7132 bfd_set_section_alignment (abfd
, s
, 4);
7133 s
= bfd_get_section_by_name (abfd
, ".dynstr");
7135 bfd_set_section_alignment (abfd
, s
, 4);
7136 s
= bfd_get_section_by_name (abfd
, ".reginfo");
7138 bfd_set_section_alignment (abfd
, s
, 4);
7139 s
= bfd_get_section_by_name (abfd
, ".dynamic");
7141 bfd_set_section_alignment (abfd
, s
, 4);
7147 if (! (_bfd_generic_link_add_one_symbol
7148 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
7149 (bfd_vma
) 0, (const char *) NULL
, false,
7150 get_elf_backend_data (abfd
)->collect
,
7151 (struct bfd_link_hash_entry
**) &h
)))
7153 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
7154 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7155 h
->type
= STT_SECTION
;
7157 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7160 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
7162 /* __rld_map is a four byte word located in the .data section
7163 and is filled in by the rtld to contain a pointer to
7164 the _r_debug structure. Its symbol value will be set in
7165 mips_elf_finish_dynamic_symbol. */
7166 s
= bfd_get_section_by_name (abfd
, ".rld_map");
7167 BFD_ASSERT (s
!= NULL
);
7170 if (! (_bfd_generic_link_add_one_symbol
7171 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
7172 (bfd_vma
) 0, (const char *) NULL
, false,
7173 get_elf_backend_data (abfd
)->collect
,
7174 (struct bfd_link_hash_entry
**) &h
)))
7176 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
7177 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7178 h
->type
= STT_OBJECT
;
7180 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7188 /* Create the .compact_rel section. */
7191 mips_elf_create_compact_rel_section (abfd
, info
)
7193 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
7196 register asection
*s
;
7198 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
7200 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
7203 s
= bfd_make_section (abfd
, ".compact_rel");
7205 || ! bfd_set_section_flags (abfd
, s
, flags
)
7206 || ! bfd_set_section_alignment (abfd
, s
,
7207 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7210 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
7216 /* Create the .got section to hold the global offset table. */
7219 mips_elf_create_got_section (abfd
, info
)
7221 struct bfd_link_info
*info
;
7224 register asection
*s
;
7225 struct elf_link_hash_entry
*h
;
7226 struct mips_got_info
*g
;
7228 /* This function may be called more than once. */
7229 if (mips_elf_got_section (abfd
))
7232 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7233 | SEC_LINKER_CREATED
);
7235 s
= bfd_make_section (abfd
, ".got");
7237 || ! bfd_set_section_flags (abfd
, s
, flags
)
7238 || ! bfd_set_section_alignment (abfd
, s
, 4))
7241 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
7242 linker script because we don't want to define the symbol if we
7243 are not creating a global offset table. */
7245 if (! (_bfd_generic_link_add_one_symbol
7246 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
7247 (bfd_vma
) 0, (const char *) NULL
, false,
7248 get_elf_backend_data (abfd
)->collect
,
7249 (struct bfd_link_hash_entry
**) &h
)))
7251 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
7252 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7253 h
->type
= STT_OBJECT
;
7256 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7259 /* The first several global offset table entries are reserved. */
7260 s
->_raw_size
= MIPS_RESERVED_GOTNO
* MIPS_ELF_GOT_SIZE (abfd
);
7262 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
7263 sizeof (struct mips_got_info
));
7266 g
->global_gotsym
= NULL
;
7267 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
7268 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
7269 if (elf_section_data (s
) == NULL
)
7272 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
7273 if (elf_section_data (s
) == NULL
)
7276 elf_section_data (s
)->tdata
= (PTR
) g
;
7277 elf_section_data (s
)->this_hdr
.sh_flags
7278 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
7283 /* Returns the .msym section for ABFD, creating it if it does not
7284 already exist. Returns NULL to indicate error. */
7287 mips_elf_create_msym_section (abfd
)
7292 s
= bfd_get_section_by_name (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
7295 s
= bfd_make_section (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
7297 || !bfd_set_section_flags (abfd
, s
,
7301 | SEC_LINKER_CREATED
7303 || !bfd_set_section_alignment (abfd
, s
,
7304 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7311 /* Add room for N relocations to the .rel.dyn section in ABFD. */
7314 mips_elf_allocate_dynamic_relocations (abfd
, n
)
7320 s
= bfd_get_section_by_name (abfd
, MIPS_ELF_REL_DYN_SECTION_NAME (abfd
));
7321 BFD_ASSERT (s
!= NULL
);
7323 if (s
->_raw_size
== 0)
7325 /* Make room for a null element. */
7326 s
->_raw_size
+= MIPS_ELF_REL_SIZE (abfd
);
7329 s
->_raw_size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
7332 /* Look through the relocs for a section during the first phase, and
7333 allocate space in the global offset table. */
7336 _bfd_mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
7338 struct bfd_link_info
*info
;
7340 const Elf_Internal_Rela
*relocs
;
7344 Elf_Internal_Shdr
*symtab_hdr
;
7345 struct elf_link_hash_entry
**sym_hashes
;
7346 struct mips_got_info
*g
;
7348 const Elf_Internal_Rela
*rel
;
7349 const Elf_Internal_Rela
*rel_end
;
7352 struct elf_backend_data
*bed
;
7354 if (info
->relocateable
)
7357 dynobj
= elf_hash_table (info
)->dynobj
;
7358 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7359 sym_hashes
= elf_sym_hashes (abfd
);
7360 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
7362 /* Check for the mips16 stub sections. */
7364 name
= bfd_get_section_name (abfd
, sec
);
7365 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
7367 unsigned long r_symndx
;
7369 /* Look at the relocation information to figure out which symbol
7372 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
7374 if (r_symndx
< extsymoff
7375 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
7379 /* This stub is for a local symbol. This stub will only be
7380 needed if there is some relocation in this BFD, other
7381 than a 16 bit function call, which refers to this symbol. */
7382 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
7384 Elf_Internal_Rela
*sec_relocs
;
7385 const Elf_Internal_Rela
*r
, *rend
;
7387 /* We can ignore stub sections when looking for relocs. */
7388 if ((o
->flags
& SEC_RELOC
) == 0
7389 || o
->reloc_count
== 0
7390 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
7391 sizeof FN_STUB
- 1) == 0
7392 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
7393 sizeof CALL_STUB
- 1) == 0
7394 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
7395 sizeof CALL_FP_STUB
- 1) == 0)
7398 sec_relocs
= (_bfd_elf32_link_read_relocs
7399 (abfd
, o
, (PTR
) NULL
,
7400 (Elf_Internal_Rela
*) NULL
,
7401 info
->keep_memory
));
7402 if (sec_relocs
== NULL
)
7405 rend
= sec_relocs
+ o
->reloc_count
;
7406 for (r
= sec_relocs
; r
< rend
; r
++)
7407 if (ELF32_R_SYM (r
->r_info
) == r_symndx
7408 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
7411 if (! info
->keep_memory
)
7420 /* There is no non-call reloc for this stub, so we do
7421 not need it. Since this function is called before
7422 the linker maps input sections to output sections, we
7423 can easily discard it by setting the SEC_EXCLUDE
7425 sec
->flags
|= SEC_EXCLUDE
;
7429 /* Record this stub in an array of local symbol stubs for
7431 if (elf_tdata (abfd
)->local_stubs
== NULL
)
7433 unsigned long symcount
;
7436 if (elf_bad_symtab (abfd
))
7437 symcount
= symtab_hdr
->sh_size
/ symtab_hdr
->sh_entsize
;
7439 symcount
= symtab_hdr
->sh_info
;
7440 n
= (asection
**) bfd_zalloc (abfd
,
7441 symcount
* sizeof (asection
*));
7444 elf_tdata (abfd
)->local_stubs
= n
;
7447 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
7449 /* We don't need to set mips16_stubs_seen in this case.
7450 That flag is used to see whether we need to look through
7451 the global symbol table for stubs. We don't need to set
7452 it here, because we just have a local stub. */
7456 struct mips_elf_link_hash_entry
*h
;
7458 h
= ((struct mips_elf_link_hash_entry
*)
7459 sym_hashes
[r_symndx
- extsymoff
]);
7461 /* H is the symbol this stub is for. */
7464 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
7467 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
7468 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
7470 unsigned long r_symndx
;
7471 struct mips_elf_link_hash_entry
*h
;
7474 /* Look at the relocation information to figure out which symbol
7477 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
7479 if (r_symndx
< extsymoff
7480 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
7482 /* This stub was actually built for a static symbol defined
7483 in the same file. We assume that all static symbols in
7484 mips16 code are themselves mips16, so we can simply
7485 discard this stub. Since this function is called before
7486 the linker maps input sections to output sections, we can
7487 easily discard it by setting the SEC_EXCLUDE flag. */
7488 sec
->flags
|= SEC_EXCLUDE
;
7492 h
= ((struct mips_elf_link_hash_entry
*)
7493 sym_hashes
[r_symndx
- extsymoff
]);
7495 /* H is the symbol this stub is for. */
7497 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
7498 loc
= &h
->call_fp_stub
;
7500 loc
= &h
->call_stub
;
7502 /* If we already have an appropriate stub for this function, we
7503 don't need another one, so we can discard this one. Since
7504 this function is called before the linker maps input sections
7505 to output sections, we can easily discard it by setting the
7506 SEC_EXCLUDE flag. We can also discard this section if we
7507 happen to already know that this is a mips16 function; it is
7508 not necessary to check this here, as it is checked later, but
7509 it is slightly faster to check now. */
7510 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
7512 sec
->flags
|= SEC_EXCLUDE
;
7517 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
7527 sgot
= mips_elf_got_section (dynobj
);
7532 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7533 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7534 BFD_ASSERT (g
!= NULL
);
7539 bed
= get_elf_backend_data (abfd
);
7540 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
7541 for (rel
= relocs
; rel
< rel_end
; ++rel
)
7543 unsigned long r_symndx
;
7545 struct elf_link_hash_entry
*h
;
7547 r_symndx
= ELF32_R_SYM (rel
->r_info
);
7548 r_type
= ELF32_R_TYPE (rel
->r_info
);
7550 if (r_symndx
< extsymoff
)
7554 h
= sym_hashes
[r_symndx
- extsymoff
];
7556 /* This may be an indirect symbol created because of a version. */
7559 while (h
->root
.type
== bfd_link_hash_indirect
)
7560 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7564 /* Some relocs require a global offset table. */
7565 if (dynobj
== NULL
|| sgot
== NULL
)
7571 case R_MIPS_CALL_HI16
:
7572 case R_MIPS_CALL_LO16
:
7573 case R_MIPS_GOT_HI16
:
7574 case R_MIPS_GOT_LO16
:
7575 case R_MIPS_GOT_PAGE
:
7576 case R_MIPS_GOT_OFST
:
7577 case R_MIPS_GOT_DISP
:
7579 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7580 if (! mips_elf_create_got_section (dynobj
, info
))
7582 g
= mips_elf_got_info (dynobj
, &sgot
);
7589 && (info
->shared
|| h
!= NULL
)
7590 && (sec
->flags
& SEC_ALLOC
) != 0)
7591 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7599 if (!h
&& (r_type
== R_MIPS_CALL_LO16
7600 || r_type
== R_MIPS_GOT_LO16
7601 || r_type
== R_MIPS_GOT_DISP
))
7603 /* We may need a local GOT entry for this relocation. We
7604 don't count R_MIPS_GOT_PAGE because we can estimate the
7605 maximum number of pages needed by looking at the size of
7606 the segment. Similar comments apply to R_MIPS_GOT16. We
7607 don't count R_MIPS_GOT_HI16, or R_MIPS_CALL_HI16 because
7608 these are always followed by an R_MIPS_GOT_LO16 or
7611 This estimation is very conservative since we can merge
7612 duplicate entries in the GOT. In order to be less
7613 conservative, we could actually build the GOT here,
7614 rather than in relocate_section. */
7616 sgot
->_raw_size
+= MIPS_ELF_GOT_SIZE (dynobj
);
7624 (*_bfd_error_handler
)
7625 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
7626 bfd_get_filename (abfd
), (unsigned long) rel
->r_offset
);
7627 bfd_set_error (bfd_error_bad_value
);
7632 case R_MIPS_CALL_HI16
:
7633 case R_MIPS_CALL_LO16
:
7636 /* This symbol requires a global offset table entry. */
7637 if (!mips_elf_record_global_got_symbol (h
, info
, g
))
7640 /* We need a stub, not a plt entry for the undefined
7641 function. But we record it as if it needs plt. See
7642 elf_adjust_dynamic_symbol in elflink.h. */
7643 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
7649 case R_MIPS_GOT_HI16
:
7650 case R_MIPS_GOT_LO16
:
7651 case R_MIPS_GOT_DISP
:
7652 /* This symbol requires a global offset table entry. */
7653 if (h
&& !mips_elf_record_global_got_symbol (h
, info
, g
))
7660 if ((info
->shared
|| h
!= NULL
)
7661 && (sec
->flags
& SEC_ALLOC
) != 0)
7665 const char *name
= MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
);
7667 sreloc
= bfd_get_section_by_name (dynobj
, name
);
7670 sreloc
= bfd_make_section (dynobj
, name
);
7672 || ! bfd_set_section_flags (dynobj
, sreloc
,
7677 | SEC_LINKER_CREATED
7679 || ! bfd_set_section_alignment (dynobj
, sreloc
,
7685 /* When creating a shared object, we must copy these
7686 reloc types into the output file as R_MIPS_REL32
7687 relocs. We make room for this reloc in the
7688 .rel.dyn reloc section. */
7689 mips_elf_allocate_dynamic_relocations (dynobj
, 1);
7692 struct mips_elf_link_hash_entry
*hmips
;
7694 /* We only need to copy this reloc if the symbol is
7695 defined in a dynamic object. */
7696 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7697 ++hmips
->possibly_dynamic_relocs
;
7700 /* Even though we don't directly need a GOT entry for
7701 this symbol, a symbol must have a dynamic symbol
7702 table index greater that DT_MIPS_GOTSYM if there are
7703 dynamic relocations against it. */
7705 && !mips_elf_record_global_got_symbol (h
, info
, g
))
7709 if (SGI_COMPAT (dynobj
))
7710 mips_elf_hash_table (info
)->compact_rel_size
+=
7711 sizeof (Elf32_External_crinfo
);
7715 case R_MIPS_GPREL16
:
7716 case R_MIPS_LITERAL
:
7717 case R_MIPS_GPREL32
:
7718 if (SGI_COMPAT (dynobj
))
7719 mips_elf_hash_table (info
)->compact_rel_size
+=
7720 sizeof (Elf32_External_crinfo
);
7723 /* This relocation describes the C++ object vtable hierarchy.
7724 Reconstruct it for later use during GC. */
7725 case R_MIPS_GNU_VTINHERIT
:
7726 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
7730 /* This relocation describes which C++ vtable entries are actually
7731 used. Record for later use during GC. */
7732 case R_MIPS_GNU_VTENTRY
:
7733 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
7741 /* If this reloc is not a 16 bit call, and it has a global
7742 symbol, then we will need the fn_stub if there is one.
7743 References from a stub section do not count. */
7745 && r_type
!= R_MIPS16_26
7746 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
7747 sizeof FN_STUB
- 1) != 0
7748 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
7749 sizeof CALL_STUB
- 1) != 0
7750 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
7751 sizeof CALL_FP_STUB
- 1) != 0)
7753 struct mips_elf_link_hash_entry
*mh
;
7755 mh
= (struct mips_elf_link_hash_entry
*) h
;
7756 mh
->need_fn_stub
= true;
7763 /* Return the section that should be marked against GC for a given
7767 _bfd_mips_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
7769 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
7770 Elf_Internal_Rela
*rel
;
7771 struct elf_link_hash_entry
*h
;
7772 Elf_Internal_Sym
*sym
;
7774 /* ??? Do mips16 stub sections need to be handled special? */
7778 switch (ELF32_R_TYPE (rel
->r_info
))
7780 case R_MIPS_GNU_VTINHERIT
:
7781 case R_MIPS_GNU_VTENTRY
:
7785 switch (h
->root
.type
)
7787 case bfd_link_hash_defined
:
7788 case bfd_link_hash_defweak
:
7789 return h
->root
.u
.def
.section
;
7791 case bfd_link_hash_common
:
7792 return h
->root
.u
.c
.p
->section
;
7801 if (!(elf_bad_symtab (abfd
)
7802 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
7803 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
7804 && sym
->st_shndx
!= SHN_COMMON
))
7806 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
7813 /* Update the got entry reference counts for the section being removed. */
7816 _bfd_mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
7817 bfd
*abfd ATTRIBUTE_UNUSED
;
7818 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
7819 asection
*sec ATTRIBUTE_UNUSED
;
7820 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
7823 Elf_Internal_Shdr
*symtab_hdr
;
7824 struct elf_link_hash_entry
**sym_hashes
;
7825 bfd_signed_vma
*local_got_refcounts
;
7826 const Elf_Internal_Rela
*rel
, *relend
;
7827 unsigned long r_symndx
;
7828 struct elf_link_hash_entry
*h
;
7830 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7831 sym_hashes
= elf_sym_hashes (abfd
);
7832 local_got_refcounts
= elf_local_got_refcounts (abfd
);
7834 relend
= relocs
+ sec
->reloc_count
;
7835 for (rel
= relocs
; rel
< relend
; rel
++)
7836 switch (ELF32_R_TYPE (rel
->r_info
))
7840 case R_MIPS_CALL_HI16
:
7841 case R_MIPS_CALL_LO16
:
7842 case R_MIPS_GOT_HI16
:
7843 case R_MIPS_GOT_LO16
:
7844 /* ??? It would seem that the existing MIPS code does no sort
7845 of reference counting or whatnot on its GOT and PLT entries,
7846 so it is not possible to garbage collect them at this time. */
7857 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
7858 hiding the old indirect symbol. Process additional relocation
7862 _bfd_mips_elf_copy_indirect_symbol (dir
, ind
)
7863 struct elf_link_hash_entry
*dir
, *ind
;
7865 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
7867 _bfd_elf_link_hash_copy_indirect (dir
, ind
);
7869 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
7870 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
7871 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
7872 if (dirmips
->min_dyn_reloc_index
== 0
7873 || (indmips
->min_dyn_reloc_index
!= 0
7874 && indmips
->min_dyn_reloc_index
< dirmips
->min_dyn_reloc_index
))
7875 dirmips
->min_dyn_reloc_index
= indmips
->min_dyn_reloc_index
;
7878 /* Adjust a symbol defined by a dynamic object and referenced by a
7879 regular object. The current definition is in some section of the
7880 dynamic object, but we're not including those sections. We have to
7881 change the definition to something the rest of the link can
7885 _bfd_mips_elf_adjust_dynamic_symbol (info
, h
)
7886 struct bfd_link_info
*info
;
7887 struct elf_link_hash_entry
*h
;
7890 struct mips_elf_link_hash_entry
*hmips
;
7893 dynobj
= elf_hash_table (info
)->dynobj
;
7895 /* Make sure we know what is going on here. */
7896 BFD_ASSERT (dynobj
!= NULL
7897 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
7898 || h
->weakdef
!= NULL
7899 || ((h
->elf_link_hash_flags
7900 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
7901 && (h
->elf_link_hash_flags
7902 & ELF_LINK_HASH_REF_REGULAR
) != 0
7903 && (h
->elf_link_hash_flags
7904 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
7906 /* If this symbol is defined in a dynamic object, we need to copy
7907 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
7909 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7910 if (! info
->relocateable
7911 && hmips
->possibly_dynamic_relocs
!= 0
7912 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
7913 mips_elf_allocate_dynamic_relocations (dynobj
,
7914 hmips
->possibly_dynamic_relocs
);
7916 /* For a function, create a stub, if needed. */
7917 if (h
->type
== STT_FUNC
7918 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
7920 if (! elf_hash_table (info
)->dynamic_sections_created
)
7923 /* If this symbol is not defined in a regular file, then set
7924 the symbol to the stub location. This is required to make
7925 function pointers compare as equal between the normal
7926 executable and the shared library. */
7927 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
7929 /* We need .stub section. */
7930 s
= bfd_get_section_by_name (dynobj
,
7931 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
7932 BFD_ASSERT (s
!= NULL
);
7934 h
->root
.u
.def
.section
= s
;
7935 h
->root
.u
.def
.value
= s
->_raw_size
;
7937 /* XXX Write this stub address somewhere. */
7938 h
->plt
.offset
= s
->_raw_size
;
7940 /* Make room for this stub code. */
7941 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
7943 /* The last half word of the stub will be filled with the index
7944 of this symbol in .dynsym section. */
7949 /* If this is a weak symbol, and there is a real definition, the
7950 processor independent code will have arranged for us to see the
7951 real definition first, and we can just use the same value. */
7952 if (h
->weakdef
!= NULL
)
7954 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
7955 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
7956 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
7957 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
7961 /* This is a reference to a symbol defined by a dynamic object which
7962 is not a function. */
7967 /* This function is called after all the input files have been read,
7968 and the input sections have been assigned to output sections. We
7969 check for any mips16 stub sections that we can discard. */
7971 static boolean mips_elf_check_mips16_stubs
7972 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
7975 _bfd_mips_elf_always_size_sections (output_bfd
, info
)
7977 struct bfd_link_info
*info
;
7981 /* The .reginfo section has a fixed size. */
7982 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
7984 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
7986 if (info
->relocateable
7987 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
7990 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
7991 mips_elf_check_mips16_stubs
,
7997 /* Check the mips16 stubs for a particular symbol, and see if we can
8002 mips_elf_check_mips16_stubs (h
, data
)
8003 struct mips_elf_link_hash_entry
*h
;
8004 PTR data ATTRIBUTE_UNUSED
;
8006 if (h
->fn_stub
!= NULL
8007 && ! h
->need_fn_stub
)
8009 /* We don't need the fn_stub; the only references to this symbol
8010 are 16 bit calls. Clobber the size to 0 to prevent it from
8011 being included in the link. */
8012 h
->fn_stub
->_raw_size
= 0;
8013 h
->fn_stub
->_cooked_size
= 0;
8014 h
->fn_stub
->flags
&= ~ SEC_RELOC
;
8015 h
->fn_stub
->reloc_count
= 0;
8016 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
8019 if (h
->call_stub
!= NULL
8020 && h
->root
.other
== STO_MIPS16
)
8022 /* We don't need the call_stub; this is a 16 bit function, so
8023 calls from other 16 bit functions are OK. Clobber the size
8024 to 0 to prevent it from being included in the link. */
8025 h
->call_stub
->_raw_size
= 0;
8026 h
->call_stub
->_cooked_size
= 0;
8027 h
->call_stub
->flags
&= ~ SEC_RELOC
;
8028 h
->call_stub
->reloc_count
= 0;
8029 h
->call_stub
->flags
|= SEC_EXCLUDE
;
8032 if (h
->call_fp_stub
!= NULL
8033 && h
->root
.other
== STO_MIPS16
)
8035 /* We don't need the call_stub; this is a 16 bit function, so
8036 calls from other 16 bit functions are OK. Clobber the size
8037 to 0 to prevent it from being included in the link. */
8038 h
->call_fp_stub
->_raw_size
= 0;
8039 h
->call_fp_stub
->_cooked_size
= 0;
8040 h
->call_fp_stub
->flags
&= ~ SEC_RELOC
;
8041 h
->call_fp_stub
->reloc_count
= 0;
8042 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
8048 /* Set the sizes of the dynamic sections. */
8051 _bfd_mips_elf_size_dynamic_sections (output_bfd
, info
)
8053 struct bfd_link_info
*info
;
8058 struct mips_got_info
*g
= NULL
;
8060 dynobj
= elf_hash_table (info
)->dynobj
;
8061 BFD_ASSERT (dynobj
!= NULL
);
8063 if (elf_hash_table (info
)->dynamic_sections_created
)
8065 /* Set the contents of the .interp section to the interpreter. */
8068 s
= bfd_get_section_by_name (dynobj
, ".interp");
8069 BFD_ASSERT (s
!= NULL
);
8071 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
8073 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
8077 /* The check_relocs and adjust_dynamic_symbol entry points have
8078 determined the sizes of the various dynamic sections. Allocate
8081 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8086 /* It's OK to base decisions on the section name, because none
8087 of the dynobj section names depend upon the input files. */
8088 name
= bfd_get_section_name (dynobj
, s
);
8090 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8095 if (strncmp (name
, ".rel", 4) == 0)
8097 if (s
->_raw_size
== 0)
8099 /* We only strip the section if the output section name
8100 has the same name. Otherwise, there might be several
8101 input sections for this output section. FIXME: This
8102 code is probably not needed these days anyhow, since
8103 the linker now does not create empty output sections. */
8104 if (s
->output_section
!= NULL
8106 bfd_get_section_name (s
->output_section
->owner
,
8107 s
->output_section
)) == 0)
8112 const char *outname
;
8115 /* If this relocation section applies to a read only
8116 section, then we probably need a DT_TEXTREL entry.
8117 If the relocation section is .rel.dyn, we always
8118 assert a DT_TEXTREL entry rather than testing whether
8119 there exists a relocation to a read only section or
8121 outname
= bfd_get_section_name (output_bfd
,
8123 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
8125 && (target
->flags
& SEC_READONLY
) != 0
8126 && (target
->flags
& SEC_ALLOC
) != 0)
8128 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd
)) == 0)
8131 /* We use the reloc_count field as a counter if we need
8132 to copy relocs into the output file. */
8134 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd
)) != 0)
8138 else if (strncmp (name
, ".got", 4) == 0)
8141 bfd_size_type loadable_size
= 0;
8142 bfd_size_type local_gotno
;
8145 BFD_ASSERT (elf_section_data (s
) != NULL
);
8146 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
8147 BFD_ASSERT (g
!= NULL
);
8149 /* Calculate the total loadable size of the output. That
8150 will give us the maximum number of GOT_PAGE entries
8152 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
8154 asection
*subsection
;
8156 for (subsection
= sub
->sections
;
8158 subsection
= subsection
->next
)
8160 if ((subsection
->flags
& SEC_ALLOC
) == 0)
8162 loadable_size
+= (subsection
->_raw_size
+ 0xf) & ~0xf;
8165 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
8167 /* Assume there are two loadable segments consisting of
8168 contiguous sections. Is 5 enough? */
8169 local_gotno
= (loadable_size
>> 16) + 5;
8170 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
8171 /* It's possible we will need GOT_PAGE entries as well as
8172 GOT16 entries. Often, these will be able to share GOT
8173 entries, but not always. */
8176 g
->local_gotno
+= local_gotno
;
8177 s
->_raw_size
+= local_gotno
* MIPS_ELF_GOT_SIZE (dynobj
);
8179 /* There has to be a global GOT entry for every symbol with
8180 a dynamic symbol table index of DT_MIPS_GOTSYM or
8181 higher. Therefore, it make sense to put those symbols
8182 that need GOT entries at the end of the symbol table. We
8184 if (!mips_elf_sort_hash_table (info
, 1))
8187 if (g
->global_gotsym
!= NULL
)
8188 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
8190 /* If there are no global symbols, or none requiring
8191 relocations, then GLOBAL_GOTSYM will be NULL. */
8193 g
->global_gotno
= i
;
8194 s
->_raw_size
+= i
* MIPS_ELF_GOT_SIZE (dynobj
);
8196 else if (strcmp (name
, MIPS_ELF_STUB_SECTION_NAME (output_bfd
)) == 0)
8198 /* Irix rld assumes that the function stub isn't at the end
8199 of .text section. So put a dummy. XXX */
8200 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
8202 else if (! info
->shared
8203 && ! mips_elf_hash_table (info
)->use_rld_obj_head
8204 && strncmp (name
, ".rld_map", 8) == 0)
8206 /* We add a room for __rld_map. It will be filled in by the
8207 rtld to contain a pointer to the _r_debug structure. */
8210 else if (SGI_COMPAT (output_bfd
)
8211 && strncmp (name
, ".compact_rel", 12) == 0)
8212 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
8213 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
))
8215 s
->_raw_size
= (sizeof (Elf32_External_Msym
)
8216 * (elf_hash_table (info
)->dynsymcount
8217 + bfd_count_sections (output_bfd
)));
8218 else if (strncmp (name
, ".init", 5) != 0)
8220 /* It's not one of our sections, so don't allocate space. */
8226 _bfd_strip_section_from_output (info
, s
);
8230 /* Allocate memory for the section contents. */
8231 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
8232 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
8234 bfd_set_error (bfd_error_no_memory
);
8239 if (elf_hash_table (info
)->dynamic_sections_created
)
8241 /* Add some entries to the .dynamic section. We fill in the
8242 values later, in elf_mips_finish_dynamic_sections, but we
8243 must add the entries now so that we get the correct size for
8244 the .dynamic section. The DT_DEBUG entry is filled in by the
8245 dynamic linker and used by the debugger. */
8248 if (SGI_COMPAT (output_bfd
))
8250 /* SGI object has the equivalence of DT_DEBUG in the
8251 DT_MIPS_RLD_MAP entry. */
8252 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
8256 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
8262 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
8266 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
8269 if (bfd_get_section_by_name (dynobj
,
8270 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
)))
8272 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
8275 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
8278 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
8282 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICTNO
, 0))
8285 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLISTNO
, 0))
8288 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
8290 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICT
, 0))
8293 s
= bfd_get_section_by_name (dynobj
, ".liblist");
8294 BFD_ASSERT (s
!= NULL
);
8296 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLIST
, 0))
8300 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
8303 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
8307 /* Time stamps in executable files are a bad idea. */
8308 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_TIME_STAMP
, 0))
8313 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_ICHECKSUM
, 0))
8318 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_IVERSION
, 0))
8322 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
8325 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
8328 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
8331 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
8334 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
8337 if (IRIX_COMPAT (dynobj
) == ict_irix5
8338 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
8341 if (IRIX_COMPAT (dynobj
) == ict_irix6
8342 && (bfd_get_section_by_name
8343 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
8344 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
8347 if (bfd_get_section_by_name (dynobj
,
8348 MIPS_ELF_MSYM_SECTION_NAME (dynobj
))
8349 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_MSYM
, 0))
8356 /* If NAME is one of the special IRIX6 symbols defined by the linker,
8357 adjust it appropriately now. */
8360 mips_elf_irix6_finish_dynamic_symbol (abfd
, name
, sym
)
8361 bfd
*abfd ATTRIBUTE_UNUSED
;
8363 Elf_Internal_Sym
*sym
;
8365 /* The linker script takes care of providing names and values for
8366 these, but we must place them into the right sections. */
8367 static const char* const text_section_symbols
[] = {
8370 "__dso_displacement",
8372 "__program_header_table",
8376 static const char* const data_section_symbols
[] = {
8384 const char* const *p
;
8387 for (i
= 0; i
< 2; ++i
)
8388 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
8391 if (strcmp (*p
, name
) == 0)
8393 /* All of these symbols are given type STT_SECTION by the
8395 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8397 /* The IRIX linker puts these symbols in special sections. */
8399 sym
->st_shndx
= SHN_MIPS_TEXT
;
8401 sym
->st_shndx
= SHN_MIPS_DATA
;
8407 /* Finish up dynamic symbol handling. We set the contents of various
8408 dynamic sections here. */
8411 _bfd_mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
8413 struct bfd_link_info
*info
;
8414 struct elf_link_hash_entry
*h
;
8415 Elf_Internal_Sym
*sym
;
8421 struct mips_got_info
*g
;
8423 struct mips_elf_link_hash_entry
*mh
;
8425 dynobj
= elf_hash_table (info
)->dynobj
;
8426 gval
= sym
->st_value
;
8427 mh
= (struct mips_elf_link_hash_entry
*) h
;
8429 if (h
->plt
.offset
!= (bfd_vma
) -1)
8433 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
8435 /* This symbol has a stub. Set it up. */
8437 BFD_ASSERT (h
->dynindx
!= -1);
8439 s
= bfd_get_section_by_name (dynobj
,
8440 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
8441 BFD_ASSERT (s
!= NULL
);
8443 /* Fill the stub. */
8445 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
8447 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
8450 /* FIXME: Can h->dynindex be more than 64K? */
8451 if (h
->dynindx
& 0xffff0000)
8454 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
8456 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
8458 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
8459 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
8461 /* Mark the symbol as undefined. plt.offset != -1 occurs
8462 only for the referenced symbol. */
8463 sym
->st_shndx
= SHN_UNDEF
;
8465 /* The run-time linker uses the st_value field of the symbol
8466 to reset the global offset table entry for this external
8467 to its stub address when unlinking a shared object. */
8468 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
8469 sym
->st_value
= gval
;
8472 BFD_ASSERT (h
->dynindx
!= -1
8473 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0);
8475 sgot
= mips_elf_got_section (dynobj
);
8476 BFD_ASSERT (sgot
!= NULL
);
8477 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
8478 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
8479 BFD_ASSERT (g
!= NULL
);
8481 /* Run through the global symbol table, creating GOT entries for all
8482 the symbols that need them. */
8483 if (g
->global_gotsym
!= NULL
8484 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
8490 value
= sym
->st_value
;
8492 /* For an entity defined in a shared object, this will be
8493 NULL. (For functions in shared objects for
8494 which we have created stubs, ST_VALUE will be non-NULL.
8495 That's because such the functions are now no longer defined
8496 in a shared object.) */
8497 value
= h
->root
.u
.def
.value
;
8499 offset
= mips_elf_global_got_index (dynobj
, h
);
8500 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
8503 /* Create a .msym entry, if appropriate. */
8504 smsym
= bfd_get_section_by_name (dynobj
,
8505 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
8508 Elf32_Internal_Msym msym
;
8510 msym
.ms_hash_value
= bfd_elf_hash (h
->root
.root
.string
);
8511 /* It is undocumented what the `1' indicates, but IRIX6 uses
8513 msym
.ms_info
= ELF32_MS_INFO (mh
->min_dyn_reloc_index
, 1);
8514 bfd_mips_elf_swap_msym_out
8516 ((Elf32_External_Msym
*) smsym
->contents
) + h
->dynindx
);
8519 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
8520 name
= h
->root
.root
.string
;
8521 if (strcmp (name
, "_DYNAMIC") == 0
8522 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
8523 sym
->st_shndx
= SHN_ABS
;
8524 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
8526 sym
->st_shndx
= SHN_ABS
;
8527 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8530 else if (SGI_COMPAT (output_bfd
))
8532 if (strcmp (name
, "_gp_disp") == 0)
8534 sym
->st_shndx
= SHN_ABS
;
8535 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8536 sym
->st_value
= elf_gp (output_bfd
);
8538 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
8539 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
8541 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8542 sym
->st_other
= STO_PROTECTED
;
8544 sym
->st_shndx
= SHN_MIPS_DATA
;
8546 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
8548 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8549 sym
->st_other
= STO_PROTECTED
;
8550 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
8551 sym
->st_shndx
= SHN_ABS
;
8553 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
8555 if (h
->type
== STT_FUNC
)
8556 sym
->st_shndx
= SHN_MIPS_TEXT
;
8557 else if (h
->type
== STT_OBJECT
)
8558 sym
->st_shndx
= SHN_MIPS_DATA
;
8562 /* Handle the IRIX6-specific symbols. */
8563 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
8564 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
8566 if (SGI_COMPAT (output_bfd
)
8569 if (! mips_elf_hash_table (info
)->use_rld_obj_head
8570 && strcmp (name
, "__rld_map") == 0)
8572 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
8573 BFD_ASSERT (s
!= NULL
);
8574 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
8575 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
8576 if (mips_elf_hash_table (info
)->rld_value
== 0)
8577 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
8579 else if (mips_elf_hash_table (info
)->use_rld_obj_head
8580 && strcmp (name
, "__rld_obj_head") == 0)
8582 /* IRIX6 does not use a .rld_map section. */
8583 if (IRIX_COMPAT (output_bfd
) == ict_irix5
)
8584 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
8586 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
8590 /* If this is a mips16 symbol, force the value to be even. */
8591 if (sym
->st_other
== STO_MIPS16
8592 && (sym
->st_value
& 1) != 0)
8598 /* Finish up the dynamic sections. */
8601 _bfd_mips_elf_finish_dynamic_sections (output_bfd
, info
)
8603 struct bfd_link_info
*info
;
8608 struct mips_got_info
*g
;
8610 dynobj
= elf_hash_table (info
)->dynobj
;
8612 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
8614 sgot
= mips_elf_got_section (dynobj
);
8619 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
8620 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
8621 BFD_ASSERT (g
!= NULL
);
8624 if (elf_hash_table (info
)->dynamic_sections_created
)
8628 BFD_ASSERT (sdyn
!= NULL
);
8629 BFD_ASSERT (g
!= NULL
);
8631 for (b
= sdyn
->contents
;
8632 b
< sdyn
->contents
+ sdyn
->_raw_size
;
8633 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
8635 Elf_Internal_Dyn dyn
;
8641 /* Read in the current dynamic entry. */
8642 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
8644 /* Assume that we're going to modify it and write it out. */
8650 s
= (bfd_get_section_by_name
8652 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
)));
8653 BFD_ASSERT (s
!= NULL
);
8654 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
8658 /* Rewrite DT_STRSZ. */
8660 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
8666 case DT_MIPS_CONFLICT
:
8669 case DT_MIPS_LIBLIST
:
8672 s
= bfd_get_section_by_name (output_bfd
, name
);
8673 BFD_ASSERT (s
!= NULL
);
8674 dyn
.d_un
.d_ptr
= s
->vma
;
8677 case DT_MIPS_RLD_VERSION
:
8678 dyn
.d_un
.d_val
= 1; /* XXX */
8682 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
8685 case DT_MIPS_CONFLICTNO
:
8687 elemsize
= sizeof (Elf32_Conflict
);
8690 case DT_MIPS_LIBLISTNO
:
8692 elemsize
= sizeof (Elf32_Lib
);
8694 s
= bfd_get_section_by_name (output_bfd
, name
);
8697 if (s
->_cooked_size
!= 0)
8698 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
8700 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
8706 case DT_MIPS_TIME_STAMP
:
8707 time ((time_t *) &dyn
.d_un
.d_val
);
8710 case DT_MIPS_ICHECKSUM
:
8715 case DT_MIPS_IVERSION
:
8720 case DT_MIPS_BASE_ADDRESS
:
8721 s
= output_bfd
->sections
;
8722 BFD_ASSERT (s
!= NULL
);
8723 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
8726 case DT_MIPS_LOCAL_GOTNO
:
8727 dyn
.d_un
.d_val
= g
->local_gotno
;
8730 case DT_MIPS_UNREFEXTNO
:
8731 /* The index into the dynamic symbol table which is the
8732 entry of the first external symbol that is not
8733 referenced within the same object. */
8734 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
8737 case DT_MIPS_GOTSYM
:
8738 if (g
->global_gotsym
)
8740 dyn
.d_un
.d_val
= g
->global_gotsym
->dynindx
;
8743 /* In case if we don't have global got symbols we default
8744 to setting DT_MIPS_GOTSYM to the same value as
8745 DT_MIPS_SYMTABNO, so we just fall through. */
8747 case DT_MIPS_SYMTABNO
:
8749 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
8750 s
= bfd_get_section_by_name (output_bfd
, name
);
8751 BFD_ASSERT (s
!= NULL
);
8753 if (s
->_cooked_size
!= 0)
8754 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
8756 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
8759 case DT_MIPS_HIPAGENO
:
8760 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
8763 case DT_MIPS_RLD_MAP
:
8764 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
8767 case DT_MIPS_OPTIONS
:
8768 s
= (bfd_get_section_by_name
8769 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
8770 dyn
.d_un
.d_ptr
= s
->vma
;
8774 s
= (bfd_get_section_by_name
8775 (output_bfd
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
)));
8776 dyn
.d_un
.d_ptr
= s
->vma
;
8785 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
8790 /* The first entry of the global offset table will be filled at
8791 runtime. The second entry will be used by some runtime loaders.
8792 This isn't the case of Irix rld. */
8793 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
8795 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
8796 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0x80000000,
8797 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
8801 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
8802 = MIPS_ELF_GOT_SIZE (output_bfd
);
8807 Elf32_compact_rel cpt
;
8809 /* ??? The section symbols for the output sections were set up in
8810 _bfd_elf_final_link. SGI sets the STT_NOTYPE attribute for these
8811 symbols. Should we do so? */
8813 smsym
= bfd_get_section_by_name (dynobj
,
8814 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
8817 Elf32_Internal_Msym msym
;
8819 msym
.ms_hash_value
= 0;
8820 msym
.ms_info
= ELF32_MS_INFO (0, 1);
8822 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
8824 long dynindx
= elf_section_data (s
)->dynindx
;
8826 bfd_mips_elf_swap_msym_out
8828 (((Elf32_External_Msym
*) smsym
->contents
)
8833 if (SGI_COMPAT (output_bfd
))
8835 /* Write .compact_rel section out. */
8836 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
8840 cpt
.num
= s
->reloc_count
;
8842 cpt
.offset
= (s
->output_section
->filepos
8843 + sizeof (Elf32_External_compact_rel
));
8846 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
8847 ((Elf32_External_compact_rel
*)
8850 /* Clean up a dummy stub function entry in .text. */
8851 s
= bfd_get_section_by_name (dynobj
,
8852 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
8855 file_ptr dummy_offset
;
8857 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
8858 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
8859 memset (s
->contents
+ dummy_offset
, 0,
8860 MIPS_FUNCTION_STUB_SIZE
);
8865 /* We need to sort the entries of the dynamic relocation section. */
8867 if (!ABI_64_P (output_bfd
))
8871 reldyn
= bfd_get_section_by_name (dynobj
,
8872 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
));
8873 if (reldyn
!= NULL
&& reldyn
->reloc_count
> 2)
8875 reldyn_sorting_bfd
= output_bfd
;
8876 qsort ((Elf32_External_Rel
*) reldyn
->contents
+ 1,
8877 (size_t) reldyn
->reloc_count
- 1,
8878 sizeof (Elf32_External_Rel
), sort_dynamic_relocs
);
8882 /* Clean up a first relocation in .rel.dyn. */
8883 s
= bfd_get_section_by_name (dynobj
,
8884 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
));
8885 if (s
!= NULL
&& s
->_raw_size
> 0)
8886 memset (s
->contents
, 0, MIPS_ELF_REL_SIZE (dynobj
));
8892 /* This is almost identical to bfd_generic_get_... except that some
8893 MIPS relocations need to be handled specially. Sigh. */
8896 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
8897 relocateable
, symbols
)
8899 struct bfd_link_info
*link_info
;
8900 struct bfd_link_order
*link_order
;
8902 boolean relocateable
;
8905 /* Get enough memory to hold the stuff */
8906 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
8907 asection
*input_section
= link_order
->u
.indirect
.section
;
8909 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
8910 arelent
**reloc_vector
= NULL
;
8916 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
8917 if (reloc_vector
== NULL
&& reloc_size
!= 0)
8920 /* read in the section */
8921 if (!bfd_get_section_contents (input_bfd
,
8925 input_section
->_raw_size
))
8928 /* We're not relaxing the section, so just copy the size info */
8929 input_section
->_cooked_size
= input_section
->_raw_size
;
8930 input_section
->reloc_done
= true;
8932 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
8936 if (reloc_count
< 0)
8939 if (reloc_count
> 0)
8944 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
8947 struct bfd_hash_entry
*h
;
8948 struct bfd_link_hash_entry
*lh
;
8949 /* Skip all this stuff if we aren't mixing formats. */
8950 if (abfd
&& input_bfd
8951 && abfd
->xvec
== input_bfd
->xvec
)
8955 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
8956 lh
= (struct bfd_link_hash_entry
*) h
;
8963 case bfd_link_hash_undefined
:
8964 case bfd_link_hash_undefweak
:
8965 case bfd_link_hash_common
:
8968 case bfd_link_hash_defined
:
8969 case bfd_link_hash_defweak
:
8971 gp
= lh
->u
.def
.value
;
8973 case bfd_link_hash_indirect
:
8974 case bfd_link_hash_warning
:
8976 /* @@FIXME ignoring warning for now */
8978 case bfd_link_hash_new
:
8987 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
8990 char *error_message
= (char *) NULL
;
8991 bfd_reloc_status_type r
;
8993 /* Specific to MIPS: Deal with relocation types that require
8994 knowing the gp of the output bfd. */
8995 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
8996 if (bfd_is_abs_section (sym
->section
) && abfd
)
8998 /* The special_function wouldn't get called anyways. */
9002 /* The gp isn't there; let the special function code
9003 fall over on its own. */
9005 else if ((*parent
)->howto
->special_function
9006 == _bfd_mips_elf_gprel16_reloc
)
9008 /* bypass special_function call */
9009 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
9010 relocateable
, (PTR
) data
, gp
);
9011 goto skip_bfd_perform_relocation
;
9013 /* end mips specific stuff */
9015 r
= bfd_perform_relocation (input_bfd
,
9019 relocateable
? abfd
: (bfd
*) NULL
,
9021 skip_bfd_perform_relocation
:
9025 asection
*os
= input_section
->output_section
;
9027 /* A partial link, so keep the relocs */
9028 os
->orelocation
[os
->reloc_count
] = *parent
;
9032 if (r
!= bfd_reloc_ok
)
9036 case bfd_reloc_undefined
:
9037 if (!((*link_info
->callbacks
->undefined_symbol
)
9038 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
9039 input_bfd
, input_section
, (*parent
)->address
,
9043 case bfd_reloc_dangerous
:
9044 BFD_ASSERT (error_message
!= (char *) NULL
);
9045 if (!((*link_info
->callbacks
->reloc_dangerous
)
9046 (link_info
, error_message
, input_bfd
, input_section
,
9047 (*parent
)->address
)))
9050 case bfd_reloc_overflow
:
9051 if (!((*link_info
->callbacks
->reloc_overflow
)
9052 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
9053 (*parent
)->howto
->name
, (*parent
)->addend
,
9054 input_bfd
, input_section
, (*parent
)->address
)))
9057 case bfd_reloc_outofrange
:
9066 if (reloc_vector
!= NULL
)
9067 free (reloc_vector
);
9071 if (reloc_vector
!= NULL
)
9072 free (reloc_vector
);
9075 #define bfd_elf32_bfd_get_relocated_section_contents \
9076 elf32_mips_get_relocated_section_contents
9078 /* ECOFF swapping routines. These are used when dealing with the
9079 .mdebug section, which is in the ECOFF debugging format. */
9080 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
9082 /* Symbol table magic number. */
9084 /* Alignment of debugging information. E.g., 4. */
9086 /* Sizes of external symbolic information. */
9087 sizeof (struct hdr_ext
),
9088 sizeof (struct dnr_ext
),
9089 sizeof (struct pdr_ext
),
9090 sizeof (struct sym_ext
),
9091 sizeof (struct opt_ext
),
9092 sizeof (struct fdr_ext
),
9093 sizeof (struct rfd_ext
),
9094 sizeof (struct ext_ext
),
9095 /* Functions to swap in external symbolic data. */
9104 _bfd_ecoff_swap_tir_in
,
9105 _bfd_ecoff_swap_rndx_in
,
9106 /* Functions to swap out external symbolic data. */
9115 _bfd_ecoff_swap_tir_out
,
9116 _bfd_ecoff_swap_rndx_out
,
9117 /* Function to read in symbolic data. */
9118 _bfd_mips_elf_read_ecoff_info
9121 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
9122 #define TARGET_LITTLE_NAME "elf32-littlemips"
9123 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
9124 #define TARGET_BIG_NAME "elf32-bigmips"
9125 #define ELF_ARCH bfd_arch_mips
9126 #define ELF_MACHINE_CODE EM_MIPS
9128 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
9129 a value of 0x1000, and we are compatible. */
9130 #define ELF_MAXPAGESIZE 0x1000
9132 #define elf_backend_collect true
9133 #define elf_backend_type_change_ok true
9134 #define elf_backend_can_gc_sections true
9135 #define elf_backend_sign_extend_vma true
9136 #define elf_info_to_howto mips_info_to_howto_rela
9137 #define elf_info_to_howto_rel mips_info_to_howto_rel
9138 #define elf_backend_sym_is_global mips_elf_sym_is_global
9139 #define elf_backend_object_p _bfd_mips_elf_object_p
9140 #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
9141 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
9142 #define elf_backend_section_from_bfd_section \
9143 _bfd_mips_elf_section_from_bfd_section
9144 #define elf_backend_section_processing _bfd_mips_elf_section_processing
9145 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
9146 #define elf_backend_additional_program_headers \
9147 _bfd_mips_elf_additional_program_headers
9148 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
9149 #define elf_backend_final_write_processing \
9150 _bfd_mips_elf_final_write_processing
9151 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
9152 #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
9153 #define elf_backend_create_dynamic_sections \
9154 _bfd_mips_elf_create_dynamic_sections
9155 #define elf_backend_check_relocs _bfd_mips_elf_check_relocs
9156 #define elf_backend_adjust_dynamic_symbol \
9157 _bfd_mips_elf_adjust_dynamic_symbol
9158 #define elf_backend_always_size_sections \
9159 _bfd_mips_elf_always_size_sections
9160 #define elf_backend_size_dynamic_sections \
9161 _bfd_mips_elf_size_dynamic_sections
9162 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section
9163 #define elf_backend_link_output_symbol_hook \
9164 _bfd_mips_elf_link_output_symbol_hook
9165 #define elf_backend_finish_dynamic_symbol \
9166 _bfd_mips_elf_finish_dynamic_symbol
9167 #define elf_backend_finish_dynamic_sections \
9168 _bfd_mips_elf_finish_dynamic_sections
9169 #define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
9170 #define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
9172 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
9173 #define elf_backend_plt_header_size 0
9175 #define elf_backend_copy_indirect_symbol \
9176 _bfd_mips_elf_copy_indirect_symbol
9178 #define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
9180 #define bfd_elf32_bfd_is_local_label_name \
9181 mips_elf_is_local_label_name
9182 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
9183 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
9184 #define bfd_elf32_bfd_link_hash_table_create \
9185 _bfd_mips_elf_link_hash_table_create
9186 #define bfd_elf32_bfd_final_link _bfd_mips_elf_final_link
9187 #define bfd_elf32_bfd_copy_private_bfd_data \
9188 _bfd_mips_elf_copy_private_bfd_data
9189 #define bfd_elf32_bfd_merge_private_bfd_data \
9190 _bfd_mips_elf_merge_private_bfd_data
9191 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
9192 #define bfd_elf32_bfd_print_private_bfd_data \
9193 _bfd_mips_elf_print_private_bfd_data
9194 #include "elf32-target.h"
9196 /* Support for traditional mips targets */
9198 #define INCLUDED_TARGET_FILE /* More a type of flag */
9200 #undef TARGET_LITTLE_SYM
9201 #undef TARGET_LITTLE_NAME
9202 #undef TARGET_BIG_SYM
9203 #undef TARGET_BIG_NAME
9205 #define TARGET_LITTLE_SYM bfd_elf32_tradlittlemips_vec
9206 #define TARGET_LITTLE_NAME "elf32-tradlittlemips"
9207 #define TARGET_BIG_SYM bfd_elf32_tradbigmips_vec
9208 #define TARGET_BIG_NAME "elf32-tradbigmips"
9210 /* Include the target file again for this target */
9211 #include "elf32-target.h"