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"
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 local .got entries. */
55 unsigned int local_gotno
;
56 /* The number of local .got entries we have used. */
57 unsigned int assigned_gotno
;
60 /* The MIPS ELF linker needs additional information for each symbol in
61 the global hash table. */
63 struct mips_elf_link_hash_entry
65 struct elf_link_hash_entry root
;
67 /* External symbol information. */
70 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
71 unsigned int mips_32_relocs
;
73 /* The index of the first dynamic relocation (in the .rel.dyn
74 section) against this symbol. */
75 unsigned int min_dyn_reloc_index
;
77 /* If there is a stub that 32 bit functions should use to call this
78 16 bit function, this points to the section containing the stub. */
81 /* Whether we need the fn_stub; this is set if this symbol appears
82 in any relocs other than a 16 bit call. */
85 /* If there is a stub that 16 bit functions should use to call this
86 32 bit function, this points to the section containing the stub. */
89 /* This is like the call_stub field, but it is used if the function
90 being called returns a floating point value. */
91 asection
*call_fp_stub
;
94 static bfd_reloc_status_type mips32_64bit_reloc
95 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
96 static reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
97 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
98 static void mips_info_to_howto_rel
99 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
100 static void mips_info_to_howto_rela
101 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rela
*));
102 static void bfd_mips_elf32_swap_gptab_in
103 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
104 static void bfd_mips_elf32_swap_gptab_out
105 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
106 static void bfd_mips_elf_swap_msym_in
107 PARAMS ((bfd
*, const Elf32_External_Msym
*, Elf32_Internal_Msym
*));
108 static void bfd_mips_elf_swap_msym_out
109 PARAMS ((bfd
*, const Elf32_Internal_Msym
*, Elf32_External_Msym
*));
110 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
111 static boolean mips_elf_create_procedure_table
112 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
113 struct ecoff_debug_info
*));
114 static INLINE
int elf_mips_isa
PARAMS ((flagword
));
115 static INLINE
int elf_mips_mach
PARAMS ((flagword
));
116 static INLINE
char* elf_mips_abi_name
PARAMS ((bfd
*));
117 static boolean mips_elf_is_local_label_name
118 PARAMS ((bfd
*, const char *));
119 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
120 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
121 static struct bfd_link_hash_table
*mips_elf_link_hash_table_create
123 static int gptab_compare
PARAMS ((const void *, const void *));
124 static void mips_elf_relocate_hi16
125 PARAMS ((bfd
*, Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_byte
*,
127 static boolean mips_elf_relocate_got_local
128 PARAMS ((bfd
*, bfd
*, asection
*, Elf_Internal_Rela
*,
129 Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
130 static void mips_elf_relocate_global_got
131 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
132 static bfd_reloc_status_type mips16_jump_reloc
133 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
134 static bfd_reloc_status_type mips16_gprel_reloc
135 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
136 static boolean mips_elf_create_compact_rel_section
137 PARAMS ((bfd
*, struct bfd_link_info
*));
138 static boolean mips_elf_create_got_section
139 PARAMS ((bfd
*, struct bfd_link_info
*));
140 static bfd_reloc_status_type mips_elf_final_gp
141 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
142 static bfd_byte
*elf32_mips_get_relocated_section_contents
143 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
144 bfd_byte
*, boolean
, asymbol
**));
145 static asection
*mips_elf_create_msym_section
147 static void mips_elf_irix6_finish_dynamic_symbol
148 PARAMS ((bfd
*, const char *, Elf_Internal_Sym
*));
149 static bfd_vma mips_elf_sign_extend
PARAMS ((bfd_vma
, int));
150 static boolean mips_elf_overflow_p
PARAMS ((bfd_vma
, int));
151 static bfd_vma mips_elf_high
PARAMS ((bfd_vma
));
152 static bfd_vma mips_elf_higher
PARAMS ((bfd_vma
));
153 static bfd_vma mips_elf_highest
PARAMS ((bfd_vma
));
154 static bfd_vma mips_elf_global_got_index
155 PARAMS ((bfd
*, struct elf_link_hash_entry
*));
156 static bfd_vma mips_elf_local_got_index
157 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
));
158 static bfd_vma mips_elf_got_offset_from_index
159 PARAMS ((bfd
*, bfd
*, bfd_vma
));
160 static boolean mips_elf_record_global_got_symbol
161 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*,
162 struct mips_got_info
*));
163 static bfd_vma mips_elf_got_page
164 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
, bfd_vma
*));
165 static boolean mips_elf_next_lo16_addend
166 PARAMS ((const Elf_Internal_Rela
*, const Elf_Internal_Rela
*, bfd_vma
*));
167 static bfd_reloc_status_type mips_elf_calculate_relocation
168 PARAMS ((bfd
*, bfd
*, asection
*, struct bfd_link_info
*,
169 const Elf_Internal_Rela
*, bfd_vma
, reloc_howto_type
*,
170 Elf_Internal_Sym
*, asection
**, bfd_vma
*, const char **));
171 static bfd_vma mips_elf_obtain_contents
172 PARAMS ((reloc_howto_type
*, const Elf_Internal_Rela
*, bfd
*, bfd_byte
*));
173 static void mips_elf_perform_relocation
174 PARAMS ((reloc_howto_type
*, const Elf_Internal_Rela
*, bfd_vma
,
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
*));
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 bfd_vma mips_elf_create_local_got_entry
185 PARAMS ((bfd
*, struct mips_got_info
*, asection
*, bfd_vma
));
186 static bfd_vma mips_elf_got16_entry
187 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
));
188 static unsigned int mips_elf_create_dynamic_relocation
189 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
190 long, bfd_vma
, asection
*));
191 static void mips_elf_allocate_dynamic_relocations
192 PARAMS ((bfd
*, unsigned int));
194 /* The level of IRIX compatibility we're striving for. */
202 /* Nonzero if ABFD is using the N32 ABI. */
204 #define ABI_N32_P(abfd) \
205 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
207 /* Nonzero if ABFD is using the 64-bit ABI. FIXME: This is never
209 #define ABI_64_P(abfd) \
210 ((elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS64) != 0)
212 /* What version of Irix we are trying to be compatible with. FIXME:
213 At the moment, we never generate "normal" MIPS ELF ABI executables;
214 we always use some version of Irix. */
216 #define IRIX_COMPAT(abfd) \
217 ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5)
219 /* Whether we are trying to be compatible with IRIX at all. */
221 #define SGI_COMPAT(abfd) \
222 (IRIX_COMPAT (abfd) != ict_none)
224 /* The name of the msym section. */
225 #define MIPS_ELF_MSYM_SECTION_NAME(abfd) ".msym"
227 /* The name of the srdata section. */
228 #define MIPS_ELF_SRDATA_SECTION_NAME(abfd) ".srdata"
230 /* The name of the options section. */
231 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
232 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.options" : ".options")
234 /* The name of the stub section. */
235 #define MIPS_ELF_STUB_SECTION_NAME(abfd) \
236 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.stubs" : ".stub")
238 /* The name of the dynamic relocation section. */
239 #define MIPS_ELF_REL_DYN_SECTION_NAME(abfd) ".rel.dyn"
241 /* The size of an external REL relocation. */
242 #define MIPS_ELF_REL_SIZE(abfd) \
243 (get_elf_backend_data (abfd)->s->sizeof_rel)
245 /* The size of an external dynamic table entry. */
246 #define MIPS_ELF_DYN_SIZE(abfd) \
247 (get_elf_backend_data (abfd)->s->sizeof_dyn)
249 /* The size of a GOT entry. */
250 #define MIPS_ELF_GOT_SIZE(abfd) \
251 (get_elf_backend_data (abfd)->s->arch_size / 8)
253 /* The size of a symbol-table entry. */
254 #define MIPS_ELF_SYM_SIZE(abfd) \
255 (get_elf_backend_data (abfd)->s->sizeof_sym)
257 /* The default alignment for sections, as a power of two. */
258 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
259 (get_elf_backend_data (abfd)->s->file_align == 8 ? 3 : 2)
261 /* Get word-sized data. */
262 #define MIPS_ELF_GET_WORD(abfd, ptr) \
263 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
265 /* Put out word-sized data. */
266 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
268 ? bfd_put_64 (abfd, val, ptr) \
269 : bfd_put_32 (abfd, val, ptr))
271 /* Add a dynamic symbol table-entry. */
273 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
274 (ABI_64_P (elf_hash_table (info)->dynobj) \
275 ? bfd_elf64_add_dynamic_entry (info, tag, val) \
276 : bfd_elf32_add_dynamic_entry (info, tag, val))
278 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
279 (ABI_64_P (elf_hash_table (info)->dynobj) \
280 ? bfd_elf64_add_dynamic_entry (info, tag, val) \
284 /* The number of local .got entries we reserve. */
285 #define MIPS_RESERVED_GOTNO (2)
287 /* Instructions which appear in a stub. For some reason the stub is
288 slightly different on an SGI system. */
289 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
290 #define STUB_LW(abfd) \
293 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
294 : 0x8f998010) /* lw t9,0x8010(gp) */ \
295 : 0x8f998000) /* lw t9,0x8000(gp) */
296 #define STUB_MOVE 0x03e07825 /* move t7,ra */
297 #define STUB_JALR 0x0320f809 /* jal t9 */
298 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
299 #define MIPS_FUNCTION_STUB_SIZE (16)
302 /* We no longer try to identify particular sections for the .dynsym
303 section. When we do, we wind up crashing if there are other random
304 sections with relocations. */
306 /* Names of sections which appear in the .dynsym section in an Irix 5
309 static const char * const mips_elf_dynsym_sec_names
[] =
322 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
323 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
325 /* The number of entries in mips_elf_dynsym_sec_names which go in the
328 #define MIPS_TEXT_DYNSYM_SECNO (3)
332 /* The names of the runtime procedure table symbols used on Irix 5. */
334 static const char * const mips_elf_dynsym_rtproc_names
[] =
337 "_procedure_string_table",
338 "_procedure_table_size",
342 /* These structures are used to generate the .compact_rel section on
347 unsigned long id1
; /* Always one? */
348 unsigned long num
; /* Number of compact relocation entries. */
349 unsigned long id2
; /* Always two? */
350 unsigned long offset
; /* The file offset of the first relocation. */
351 unsigned long reserved0
; /* Zero? */
352 unsigned long reserved1
; /* Zero? */
361 bfd_byte reserved0
[4];
362 bfd_byte reserved1
[4];
363 } Elf32_External_compact_rel
;
367 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
368 unsigned int rtype
: 4; /* Relocation types. See below. */
369 unsigned int dist2to
: 8;
370 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
371 unsigned long konst
; /* KONST field. See below. */
372 unsigned long vaddr
; /* VADDR to be relocated. */
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. */
389 } Elf32_External_crinfo
;
395 } Elf32_External_crinfo2
;
397 /* These are the constants used to swap the bitfields in a crinfo. */
399 #define CRINFO_CTYPE (0x1)
400 #define CRINFO_CTYPE_SH (31)
401 #define CRINFO_RTYPE (0xf)
402 #define CRINFO_RTYPE_SH (27)
403 #define CRINFO_DIST2TO (0xff)
404 #define CRINFO_DIST2TO_SH (19)
405 #define CRINFO_RELVADDR (0x7ffff)
406 #define CRINFO_RELVADDR_SH (0)
408 /* A compact relocation info has long (3 words) or short (2 words)
409 formats. A short format doesn't have VADDR field and relvaddr
410 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
411 #define CRF_MIPS_LONG 1
412 #define CRF_MIPS_SHORT 0
414 /* There are 4 types of compact relocation at least. The value KONST
415 has different meaning for each type:
418 CT_MIPS_REL32 Address in data
419 CT_MIPS_WORD Address in word (XXX)
420 CT_MIPS_GPHI_LO GP - vaddr
421 CT_MIPS_JMPAD Address to jump
424 #define CRT_MIPS_REL32 0xa
425 #define CRT_MIPS_WORD 0xb
426 #define CRT_MIPS_GPHI_LO 0xc
427 #define CRT_MIPS_JMPAD 0xd
429 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
430 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
431 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
432 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
434 static void bfd_elf32_swap_compact_rel_out
435 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
436 static void bfd_elf32_swap_crinfo_out
437 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
439 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
441 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
442 from smaller values. Start with zero, widen, *then* decrement. */
443 #define MINUS_ONE (((bfd_vma)0) - 1)
445 static reloc_howto_type elf_mips_howto_table
[] =
448 HOWTO (R_MIPS_NONE
, /* type */
450 0, /* size (0 = byte, 1 = short, 2 = long) */
452 false, /* pc_relative */
454 complain_overflow_dont
, /* complain_on_overflow */
455 bfd_elf_generic_reloc
, /* special_function */
456 "R_MIPS_NONE", /* name */
457 false, /* partial_inplace */
460 false), /* pcrel_offset */
462 /* 16 bit relocation. */
463 HOWTO (R_MIPS_16
, /* type */
465 1, /* size (0 = byte, 1 = short, 2 = long) */
467 false, /* pc_relative */
469 complain_overflow_bitfield
, /* complain_on_overflow */
470 bfd_elf_generic_reloc
, /* special_function */
471 "R_MIPS_16", /* name */
472 true, /* partial_inplace */
473 0xffff, /* src_mask */
474 0xffff, /* dst_mask */
475 false), /* pcrel_offset */
477 /* 32 bit relocation. */
478 HOWTO (R_MIPS_32
, /* type */
480 2, /* size (0 = byte, 1 = short, 2 = long) */
482 false, /* pc_relative */
484 complain_overflow_bitfield
, /* complain_on_overflow */
485 bfd_elf_generic_reloc
, /* special_function */
486 "R_MIPS_32", /* name */
487 true, /* partial_inplace */
488 0xffffffff, /* src_mask */
489 0xffffffff, /* dst_mask */
490 false), /* pcrel_offset */
492 /* 32 bit symbol relative relocation. */
493 HOWTO (R_MIPS_REL32
, /* type */
495 2, /* size (0 = byte, 1 = short, 2 = long) */
497 false, /* pc_relative */
499 complain_overflow_bitfield
, /* complain_on_overflow */
500 bfd_elf_generic_reloc
, /* special_function */
501 "R_MIPS_REL32", /* name */
502 true, /* partial_inplace */
503 0xffffffff, /* src_mask */
504 0xffffffff, /* dst_mask */
505 false), /* pcrel_offset */
507 /* 26 bit branch address. */
508 HOWTO (R_MIPS_26
, /* type */
510 2, /* size (0 = byte, 1 = short, 2 = long) */
512 false, /* pc_relative */
514 complain_overflow_dont
, /* complain_on_overflow */
515 /* This needs complex overflow
516 detection, because the upper four
517 bits must match the PC. */
518 bfd_elf_generic_reloc
, /* special_function */
519 "R_MIPS_26", /* name */
520 true, /* partial_inplace */
521 0x3ffffff, /* src_mask */
522 0x3ffffff, /* dst_mask */
523 false), /* pcrel_offset */
525 /* High 16 bits of symbol value. */
526 HOWTO (R_MIPS_HI16
, /* type */
528 2, /* size (0 = byte, 1 = short, 2 = long) */
530 false, /* pc_relative */
532 complain_overflow_dont
, /* complain_on_overflow */
533 _bfd_mips_elf_hi16_reloc
, /* special_function */
534 "R_MIPS_HI16", /* name */
535 true, /* partial_inplace */
536 0xffff, /* src_mask */
537 0xffff, /* dst_mask */
538 false), /* pcrel_offset */
540 /* Low 16 bits of symbol value. */
541 HOWTO (R_MIPS_LO16
, /* type */
543 2, /* size (0 = byte, 1 = short, 2 = long) */
545 false, /* pc_relative */
547 complain_overflow_dont
, /* complain_on_overflow */
548 _bfd_mips_elf_lo16_reloc
, /* special_function */
549 "R_MIPS_LO16", /* name */
550 true, /* partial_inplace */
551 0xffff, /* src_mask */
552 0xffff, /* dst_mask */
553 false), /* pcrel_offset */
555 /* GP relative reference. */
556 HOWTO (R_MIPS_GPREL16
, /* type */
558 2, /* size (0 = byte, 1 = short, 2 = long) */
560 false, /* pc_relative */
562 complain_overflow_signed
, /* complain_on_overflow */
563 _bfd_mips_elf_gprel16_reloc
, /* special_function */
564 "R_MIPS_GPREL16", /* name */
565 true, /* partial_inplace */
566 0xffff, /* src_mask */
567 0xffff, /* dst_mask */
568 false), /* pcrel_offset */
570 /* Reference to literal section. */
571 HOWTO (R_MIPS_LITERAL
, /* type */
573 2, /* size (0 = byte, 1 = short, 2 = long) */
575 false, /* pc_relative */
577 complain_overflow_signed
, /* complain_on_overflow */
578 _bfd_mips_elf_gprel16_reloc
, /* special_function */
579 "R_MIPS_LITERAL", /* name */
580 true, /* partial_inplace */
581 0xffff, /* src_mask */
582 0xffff, /* dst_mask */
583 false), /* pcrel_offset */
585 /* Reference to global offset table. */
586 HOWTO (R_MIPS_GOT16
, /* type */
588 2, /* size (0 = byte, 1 = short, 2 = long) */
590 false, /* pc_relative */
592 complain_overflow_signed
, /* complain_on_overflow */
593 _bfd_mips_elf_got16_reloc
, /* special_function */
594 "R_MIPS_GOT16", /* name */
595 false, /* partial_inplace */
597 0xffff, /* dst_mask */
598 false), /* pcrel_offset */
600 /* 16 bit PC relative reference. */
601 HOWTO (R_MIPS_PC16
, /* type */
603 2, /* size (0 = byte, 1 = short, 2 = long) */
605 true, /* pc_relative */
607 complain_overflow_signed
, /* complain_on_overflow */
608 bfd_elf_generic_reloc
, /* special_function */
609 "R_MIPS_PC16", /* name */
610 true, /* partial_inplace */
611 0xffff, /* src_mask */
612 0xffff, /* dst_mask */
613 false), /* pcrel_offset */
615 /* 16 bit call through global offset table. */
616 HOWTO (R_MIPS_CALL16
, /* type */
618 2, /* size (0 = byte, 1 = short, 2 = long) */
620 false, /* pc_relative */
622 complain_overflow_signed
, /* complain_on_overflow */
623 bfd_elf_generic_reloc
, /* special_function */
624 "R_MIPS_CALL16", /* name */
625 false, /* partial_inplace */
627 0xffff, /* dst_mask */
628 false), /* pcrel_offset */
630 /* 32 bit GP relative reference. */
631 HOWTO (R_MIPS_GPREL32
, /* type */
633 2, /* size (0 = byte, 1 = short, 2 = long) */
635 false, /* pc_relative */
637 complain_overflow_bitfield
, /* complain_on_overflow */
638 _bfd_mips_elf_gprel32_reloc
, /* special_function */
639 "R_MIPS_GPREL32", /* name */
640 true, /* partial_inplace */
641 0xffffffff, /* src_mask */
642 0xffffffff, /* dst_mask */
643 false), /* pcrel_offset */
645 /* The remaining relocs are defined on Irix 5, although they are
646 not defined by the ABI. */
651 /* A 5 bit shift field. */
652 HOWTO (R_MIPS_SHIFT5
, /* type */
654 2, /* size (0 = byte, 1 = short, 2 = long) */
656 false, /* pc_relative */
658 complain_overflow_bitfield
, /* complain_on_overflow */
659 bfd_elf_generic_reloc
, /* special_function */
660 "R_MIPS_SHIFT5", /* name */
661 true, /* partial_inplace */
662 0x000007c0, /* src_mask */
663 0x000007c0, /* dst_mask */
664 false), /* pcrel_offset */
666 /* A 6 bit shift field. */
667 /* FIXME: This is not handled correctly; a special function is
668 needed to put the most significant bit in the right place. */
669 HOWTO (R_MIPS_SHIFT6
, /* type */
671 2, /* size (0 = byte, 1 = short, 2 = long) */
673 false, /* pc_relative */
675 complain_overflow_bitfield
, /* complain_on_overflow */
676 bfd_elf_generic_reloc
, /* special_function */
677 "R_MIPS_SHIFT6", /* name */
678 true, /* partial_inplace */
679 0x000007c4, /* src_mask */
680 0x000007c4, /* dst_mask */
681 false), /* pcrel_offset */
683 /* A 64 bit relocation. This is used in 32 bit ELF when addresses
684 are 64 bits long; the upper 32 bits are simply a sign extension.
685 The fields of the howto should be the same as for R_MIPS_32,
686 other than the type, name, and special_function. */
687 HOWTO (R_MIPS_64
, /* type */
689 2, /* size (0 = byte, 1 = short, 2 = long) */
691 false, /* pc_relative */
693 complain_overflow_bitfield
, /* complain_on_overflow */
694 mips32_64bit_reloc
, /* special_function */
695 "R_MIPS_64", /* name */
696 true, /* partial_inplace */
697 0xffffffff, /* src_mask */
698 0xffffffff, /* dst_mask */
699 false), /* pcrel_offset */
701 /* Displacement in the global offset table. */
702 HOWTO (R_MIPS_GOT_DISP
, /* type */
704 2, /* size (0 = byte, 1 = short, 2 = long) */
706 false, /* pc_relative */
708 complain_overflow_bitfield
, /* complain_on_overflow */
709 bfd_elf_generic_reloc
, /* special_function */
710 "R_MIPS_GOT_DISP", /* name */
711 true, /* partial_inplace */
712 0x0000ffff, /* src_mask */
713 0x0000ffff, /* dst_mask */
714 false), /* pcrel_offset */
716 /* Displacement to page pointer in the global offset table. */
717 HOWTO (R_MIPS_GOT_PAGE
, /* type */
719 2, /* size (0 = byte, 1 = short, 2 = long) */
721 false, /* pc_relative */
723 complain_overflow_bitfield
, /* complain_on_overflow */
724 bfd_elf_generic_reloc
, /* special_function */
725 "R_MIPS_GOT_PAGE", /* name */
726 true, /* partial_inplace */
727 0x0000ffff, /* src_mask */
728 0x0000ffff, /* dst_mask */
729 false), /* pcrel_offset */
731 /* Offset from page pointer in the global offset table. */
732 HOWTO (R_MIPS_GOT_OFST
, /* type */
734 2, /* size (0 = byte, 1 = short, 2 = long) */
736 false, /* pc_relative */
738 complain_overflow_bitfield
, /* complain_on_overflow */
739 bfd_elf_generic_reloc
, /* special_function */
740 "R_MIPS_GOT_OFST", /* name */
741 true, /* partial_inplace */
742 0x0000ffff, /* src_mask */
743 0x0000ffff, /* dst_mask */
744 false), /* pcrel_offset */
746 /* High 16 bits of displacement in global offset table. */
747 HOWTO (R_MIPS_GOT_HI16
, /* type */
749 2, /* size (0 = byte, 1 = short, 2 = long) */
751 false, /* pc_relative */
753 complain_overflow_dont
, /* complain_on_overflow */
754 bfd_elf_generic_reloc
, /* special_function */
755 "R_MIPS_GOT_HI16", /* name */
756 true, /* partial_inplace */
757 0x0000ffff, /* src_mask */
758 0x0000ffff, /* dst_mask */
759 false), /* pcrel_offset */
761 /* Low 16 bits of displacement in global offset table. */
762 HOWTO (R_MIPS_GOT_LO16
, /* type */
764 2, /* size (0 = byte, 1 = short, 2 = long) */
766 false, /* pc_relative */
768 complain_overflow_dont
, /* complain_on_overflow */
769 bfd_elf_generic_reloc
, /* special_function */
770 "R_MIPS_GOT_LO16", /* name */
771 true, /* partial_inplace */
772 0x0000ffff, /* src_mask */
773 0x0000ffff, /* dst_mask */
774 false), /* pcrel_offset */
776 /* 64 bit subtraction. Used in the N32 ABI. */
777 HOWTO (R_MIPS_SUB
, /* type */
779 4, /* size (0 = byte, 1 = short, 2 = long) */
781 false, /* pc_relative */
783 complain_overflow_bitfield
, /* complain_on_overflow */
784 bfd_elf_generic_reloc
, /* special_function */
785 "R_MIPS_SUB", /* name */
786 true, /* partial_inplace */
787 MINUS_ONE
, /* src_mask */
788 MINUS_ONE
, /* dst_mask */
789 false), /* pcrel_offset */
791 /* Used to cause the linker to insert and delete instructions? */
796 /* Get the higher value of a 64 bit addend. */
797 HOWTO (R_MIPS_HIGHER
, /* type */
799 2, /* size (0 = byte, 1 = short, 2 = long) */
801 false, /* pc_relative */
803 complain_overflow_dont
, /* complain_on_overflow */
804 bfd_elf_generic_reloc
, /* special_function */
805 "R_MIPS_HIGHER", /* name */
806 true, /* partial_inplace */
808 0xffff, /* dst_mask */
809 false), /* pcrel_offset */
811 /* Get the highest value of a 64 bit addend. */
812 HOWTO (R_MIPS_HIGHEST
, /* type */
814 2, /* size (0 = byte, 1 = short, 2 = long) */
816 false, /* pc_relative */
818 complain_overflow_dont
, /* complain_on_overflow */
819 bfd_elf_generic_reloc
, /* special_function */
820 "R_MIPS_HIGHEST", /* name */
821 true, /* partial_inplace */
823 0xffff, /* dst_mask */
824 false), /* pcrel_offset */
826 /* High 16 bits of displacement in global offset table. */
827 HOWTO (R_MIPS_CALL_HI16
, /* type */
829 2, /* size (0 = byte, 1 = short, 2 = long) */
831 false, /* pc_relative */
833 complain_overflow_dont
, /* complain_on_overflow */
834 bfd_elf_generic_reloc
, /* special_function */
835 "R_MIPS_CALL_HI16", /* name */
836 true, /* partial_inplace */
837 0x0000ffff, /* src_mask */
838 0x0000ffff, /* dst_mask */
839 false), /* pcrel_offset */
841 /* Low 16 bits of displacement in global offset table. */
842 HOWTO (R_MIPS_CALL_LO16
, /* type */
844 2, /* size (0 = byte, 1 = short, 2 = long) */
846 false, /* pc_relative */
848 complain_overflow_dont
, /* complain_on_overflow */
849 bfd_elf_generic_reloc
, /* special_function */
850 "R_MIPS_CALL_LO16", /* name */
851 true, /* partial_inplace */
852 0x0000ffff, /* src_mask */
853 0x0000ffff, /* dst_mask */
854 false), /* pcrel_offset */
856 /* Section displacement. */
857 HOWTO (R_MIPS_SCN_DISP
, /* type */
859 2, /* size (0 = byte, 1 = short, 2 = long) */
861 false, /* pc_relative */
863 complain_overflow_dont
, /* complain_on_overflow */
864 bfd_elf_generic_reloc
, /* special_function */
865 "R_MIPS_SCN_DISP", /* name */
866 false, /* partial_inplace */
867 0xffffffff, /* src_mask */
868 0xffffffff, /* dst_mask */
869 false), /* pcrel_offset */
872 { R_MIPS_ADD_IMMEDIATE
},
876 /* Protected jump conversion. This is an optimization hint. No
877 relocation is required for correctness. */
878 HOWTO (R_MIPS_JALR
, /* type */
880 0, /* size (0 = byte, 1 = short, 2 = long) */
882 false, /* pc_relative */
884 complain_overflow_dont
, /* complain_on_overflow */
885 bfd_elf_generic_reloc
, /* special_function */
886 "R_MIPS_JALR", /* name */
887 false, /* partial_inplace */
888 0x00000000, /* src_mask */
889 0x00000000, /* dst_mask */
890 false), /* pcrel_offset */
893 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
894 is a hack to make the linker think that we need 64 bit values. */
895 static reloc_howto_type elf_mips_ctor64_howto
=
896 HOWTO (R_MIPS_64
, /* type */
898 4, /* size (0 = byte, 1 = short, 2 = long) */
900 false, /* pc_relative */
902 complain_overflow_signed
, /* complain_on_overflow */
903 mips32_64bit_reloc
, /* special_function */
904 "R_MIPS_64", /* name */
905 true, /* partial_inplace */
906 0xffffffff, /* src_mask */
907 0xffffffff, /* dst_mask */
908 false); /* pcrel_offset */
910 /* The reloc used for the mips16 jump instruction. */
911 static reloc_howto_type elf_mips16_jump_howto
=
912 HOWTO (R_MIPS16_26
, /* type */
914 2, /* size (0 = byte, 1 = short, 2 = long) */
916 false, /* pc_relative */
918 complain_overflow_dont
, /* complain_on_overflow */
919 /* This needs complex overflow
920 detection, because the upper four
921 bits must match the PC. */
922 mips16_jump_reloc
, /* special_function */
923 "R_MIPS16_26", /* name */
924 true, /* partial_inplace */
925 0x3ffffff, /* src_mask */
926 0x3ffffff, /* dst_mask */
927 false); /* pcrel_offset */
929 /* The reloc used for the mips16 gprel instruction. The src_mask and
930 dsk_mask for this howto do not reflect the actual instruction, in
931 which the value is not contiguous; the masks are for the
932 convenience of the relocate_section routine. */
933 static reloc_howto_type elf_mips16_gprel_howto
=
934 HOWTO (R_MIPS16_GPREL
, /* type */
936 2, /* size (0 = byte, 1 = short, 2 = long) */
938 false, /* pc_relative */
940 complain_overflow_signed
, /* complain_on_overflow */
941 mips16_gprel_reloc
, /* special_function */
942 "R_MIPS16_GPREL", /* name */
943 true, /* partial_inplace */
944 0xffff, /* src_mask */
945 0xffff, /* dst_mask */
946 false); /* pcrel_offset */
949 /* GNU extension to record C++ vtable hierarchy */
950 static reloc_howto_type elf_mips_gnu_vtinherit_howto
=
951 HOWTO (R_MIPS_GNU_VTINHERIT
, /* type */
953 2, /* size (0 = byte, 1 = short, 2 = long) */
955 false, /* pc_relative */
957 complain_overflow_dont
, /* complain_on_overflow */
958 NULL
, /* special_function */
959 "R_MIPS_GNU_VTINHERIT", /* name */
960 false, /* partial_inplace */
963 false); /* pcrel_offset */
965 /* GNU extension to record C++ vtable member usage */
966 static reloc_howto_type elf_mips_gnu_vtentry_howto
=
967 HOWTO (R_MIPS_GNU_VTENTRY
, /* type */
969 2, /* size (0 = byte, 1 = short, 2 = long) */
971 false, /* pc_relative */
973 complain_overflow_dont
, /* complain_on_overflow */
974 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
975 "R_MIPS_GNU_VTENTRY", /* name */
976 false, /* partial_inplace */
979 false); /* pcrel_offset */
981 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
982 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
983 the HI16. Here we just save the information we need; we do the
984 actual relocation when we see the LO16. MIPS ELF requires that the
985 LO16 immediately follow the HI16. As a GNU extension, we permit an
986 arbitrary number of HI16 relocs to be associated with a single LO16
987 reloc. This extension permits gcc to output the HI and LO relocs
992 struct mips_hi16
*next
;
997 /* FIXME: This should not be a static variable. */
999 static struct mips_hi16
*mips_hi16_list
;
1001 bfd_reloc_status_type
1002 _bfd_mips_elf_hi16_reloc (abfd
,
1010 arelent
*reloc_entry
;
1013 asection
*input_section
;
1015 char **error_message
;
1017 bfd_reloc_status_type ret
;
1019 struct mips_hi16
*n
;
1021 /* If we're relocating, and this an external symbol, we don't want
1022 to change anything. */
1023 if (output_bfd
!= (bfd
*) NULL
1024 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1025 && reloc_entry
->addend
== 0)
1027 reloc_entry
->address
+= input_section
->output_offset
;
1028 return bfd_reloc_ok
;
1033 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1035 boolean relocateable
;
1038 if (ret
== bfd_reloc_undefined
)
1041 if (output_bfd
!= NULL
)
1042 relocateable
= true;
1045 relocateable
= false;
1046 output_bfd
= symbol
->section
->output_section
->owner
;
1049 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1050 error_message
, &gp
);
1051 if (ret
!= bfd_reloc_ok
)
1054 relocation
= gp
- reloc_entry
->address
;
1058 if (bfd_is_und_section (symbol
->section
)
1059 && output_bfd
== (bfd
*) NULL
)
1060 ret
= bfd_reloc_undefined
;
1062 if (bfd_is_com_section (symbol
->section
))
1065 relocation
= symbol
->value
;
1068 relocation
+= symbol
->section
->output_section
->vma
;
1069 relocation
+= symbol
->section
->output_offset
;
1070 relocation
+= reloc_entry
->addend
;
1072 if (reloc_entry
->address
> input_section
->_cooked_size
)
1073 return bfd_reloc_outofrange
;
1075 /* Save the information, and let LO16 do the actual relocation. */
1076 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
1078 return bfd_reloc_outofrange
;
1079 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
1080 n
->addend
= relocation
;
1081 n
->next
= mips_hi16_list
;
1084 if (output_bfd
!= (bfd
*) NULL
)
1085 reloc_entry
->address
+= input_section
->output_offset
;
1090 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
1091 inplace relocation; this function exists in order to do the
1092 R_MIPS_HI16 relocation described above. */
1094 bfd_reloc_status_type
1095 _bfd_mips_elf_lo16_reloc (abfd
,
1103 arelent
*reloc_entry
;
1106 asection
*input_section
;
1108 char **error_message
;
1110 arelent gp_disp_relent
;
1112 if (mips_hi16_list
!= NULL
)
1114 struct mips_hi16
*l
;
1121 unsigned long vallo
;
1122 struct mips_hi16
*next
;
1124 /* Do the HI16 relocation. Note that we actually don't need
1125 to know anything about the LO16 itself, except where to
1126 find the low 16 bits of the addend needed by the LO16. */
1127 insn
= bfd_get_32 (abfd
, l
->addr
);
1128 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
1130 val
= ((insn
& 0xffff) << 16) + vallo
;
1133 /* The low order 16 bits are always treated as a signed
1134 value. Therefore, a negative value in the low order bits
1135 requires an adjustment in the high order bits. We need
1136 to make this adjustment in two ways: once for the bits we
1137 took from the data, and once for the bits we are putting
1138 back in to the data. */
1139 if ((vallo
& 0x8000) != 0)
1141 if ((val
& 0x8000) != 0)
1144 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
1145 bfd_put_32 (abfd
, insn
, l
->addr
);
1147 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1149 gp_disp_relent
= *reloc_entry
;
1150 reloc_entry
= &gp_disp_relent
;
1151 reloc_entry
->addend
= l
->addend
;
1159 mips_hi16_list
= NULL
;
1161 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1163 bfd_reloc_status_type ret
;
1164 bfd_vma gp
, relocation
;
1166 /* FIXME: Does this case ever occur? */
1168 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
1169 if (ret
!= bfd_reloc_ok
)
1172 relocation
= gp
- reloc_entry
->address
;
1173 relocation
+= symbol
->section
->output_section
->vma
;
1174 relocation
+= symbol
->section
->output_offset
;
1175 relocation
+= reloc_entry
->addend
;
1177 if (reloc_entry
->address
> input_section
->_cooked_size
)
1178 return bfd_reloc_outofrange
;
1180 gp_disp_relent
= *reloc_entry
;
1181 reloc_entry
= &gp_disp_relent
;
1182 reloc_entry
->addend
= relocation
- 4;
1185 /* Now do the LO16 reloc in the usual way. */
1186 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1187 input_section
, output_bfd
, error_message
);
1190 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1191 table used for PIC code. If the symbol is an external symbol, the
1192 instruction is modified to contain the offset of the appropriate
1193 entry in the global offset table. If the symbol is a section
1194 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1195 addends are combined to form the real addend against the section
1196 symbol; the GOT16 is modified to contain the offset of an entry in
1197 the global offset table, and the LO16 is modified to offset it
1198 appropriately. Thus an offset larger than 16 bits requires a
1199 modified value in the global offset table.
1201 This implementation suffices for the assembler, but the linker does
1202 not yet know how to create global offset tables. */
1204 bfd_reloc_status_type
1205 _bfd_mips_elf_got16_reloc (abfd
,
1213 arelent
*reloc_entry
;
1216 asection
*input_section
;
1218 char **error_message
;
1220 /* If we're relocating, and this an external symbol, we don't want
1221 to change anything. */
1222 if (output_bfd
!= (bfd
*) NULL
1223 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1224 && reloc_entry
->addend
== 0)
1226 reloc_entry
->address
+= input_section
->output_offset
;
1227 return bfd_reloc_ok
;
1230 /* If we're relocating, and this is a local symbol, we can handle it
1232 if (output_bfd
!= (bfd
*) NULL
1233 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1234 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1235 input_section
, output_bfd
, error_message
);
1240 /* Set the GP value for OUTPUT_BFD. Returns false if this is a
1241 dangerous relocation. */
1244 mips_elf_assign_gp (output_bfd
, pgp
)
1252 /* If we've already figured out what GP will be, just return it. */
1253 *pgp
= _bfd_get_gp_value (output_bfd
);
1257 count
= bfd_get_symcount (output_bfd
);
1258 sym
= bfd_get_outsymbols (output_bfd
);
1260 /* The linker script will have created a symbol named `_gp' with the
1261 appropriate value. */
1262 if (sym
== (asymbol
**) NULL
)
1266 for (i
= 0; i
< count
; i
++, sym
++)
1268 register CONST
char *name
;
1270 name
= bfd_asymbol_name (*sym
);
1271 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1273 *pgp
= bfd_asymbol_value (*sym
);
1274 _bfd_set_gp_value (output_bfd
, *pgp
);
1282 /* Only get the error once. */
1284 _bfd_set_gp_value (output_bfd
, *pgp
);
1291 /* We have to figure out the gp value, so that we can adjust the
1292 symbol value correctly. We look up the symbol _gp in the output
1293 BFD. If we can't find it, we're stuck. We cache it in the ELF
1294 target data. We don't need to adjust the symbol value for an
1295 external symbol if we are producing relocateable output. */
1297 static bfd_reloc_status_type
1298 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1301 boolean relocateable
;
1302 char **error_message
;
1305 if (bfd_is_und_section (symbol
->section
)
1309 return bfd_reloc_undefined
;
1312 *pgp
= _bfd_get_gp_value (output_bfd
);
1315 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1319 /* Make up a value. */
1320 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1321 _bfd_set_gp_value (output_bfd
, *pgp
);
1323 else if (!mips_elf_assign_gp (output_bfd
, pgp
))
1326 (char *) _("GP relative relocation when _gp not defined");
1327 return bfd_reloc_dangerous
;
1331 return bfd_reloc_ok
;
1334 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1335 become the offset from the gp register. This function also handles
1336 R_MIPS_LITERAL relocations, although those can be handled more
1337 cleverly because the entries in the .lit8 and .lit4 sections can be
1340 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1341 arelent
*, asection
*,
1342 boolean
, PTR
, bfd_vma
));
1344 bfd_reloc_status_type
1345 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1346 output_bfd
, error_message
)
1348 arelent
*reloc_entry
;
1351 asection
*input_section
;
1353 char **error_message
;
1355 boolean relocateable
;
1356 bfd_reloc_status_type ret
;
1359 /* If we're relocating, and this is an external symbol with no
1360 addend, we don't want to change anything. We will only have an
1361 addend if this is a newly created reloc, not read from an ELF
1363 if (output_bfd
!= (bfd
*) NULL
1364 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1365 && reloc_entry
->addend
== 0)
1367 reloc_entry
->address
+= input_section
->output_offset
;
1368 return bfd_reloc_ok
;
1371 if (output_bfd
!= (bfd
*) NULL
)
1372 relocateable
= true;
1375 relocateable
= false;
1376 output_bfd
= symbol
->section
->output_section
->owner
;
1379 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1381 if (ret
!= bfd_reloc_ok
)
1384 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1385 relocateable
, data
, gp
);
1388 static bfd_reloc_status_type
1389 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1393 arelent
*reloc_entry
;
1394 asection
*input_section
;
1395 boolean relocateable
;
1403 if (bfd_is_com_section (symbol
->section
))
1406 relocation
= symbol
->value
;
1408 relocation
+= symbol
->section
->output_section
->vma
;
1409 relocation
+= symbol
->section
->output_offset
;
1411 if (reloc_entry
->address
> input_section
->_cooked_size
)
1412 return bfd_reloc_outofrange
;
1414 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1416 /* Set val to the offset into the section or symbol. */
1417 if (reloc_entry
->howto
->src_mask
== 0)
1419 /* This case occurs with the 64-bit MIPS ELF ABI. */
1420 val
= reloc_entry
->addend
;
1424 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1429 /* Adjust val for the final section location and GP value. If we
1430 are producing relocateable output, we don't want to do this for
1431 an external symbol. */
1433 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1434 val
+= relocation
- gp
;
1436 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1437 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1440 reloc_entry
->address
+= input_section
->output_offset
;
1442 /* Make sure it fit in 16 bits. */
1443 if (val
>= 0x8000 && val
< 0xffff8000)
1444 return bfd_reloc_overflow
;
1446 return bfd_reloc_ok
;
1449 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1450 from the gp register? XXX */
1452 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1453 arelent
*, asection
*,
1454 boolean
, PTR
, bfd_vma
));
1456 bfd_reloc_status_type
1457 _bfd_mips_elf_gprel32_reloc (abfd
,
1465 arelent
*reloc_entry
;
1468 asection
*input_section
;
1470 char **error_message
;
1472 boolean relocateable
;
1473 bfd_reloc_status_type ret
;
1476 /* If we're relocating, and this is an external symbol with no
1477 addend, we don't want to change anything. We will only have an
1478 addend if this is a newly created reloc, not read from an ELF
1480 if (output_bfd
!= (bfd
*) NULL
1481 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1482 && reloc_entry
->addend
== 0)
1484 *error_message
= (char *)
1485 _("32bits gp relative relocation occurs for an external symbol");
1486 return bfd_reloc_outofrange
;
1489 if (output_bfd
!= (bfd
*) NULL
)
1491 relocateable
= true;
1492 gp
= _bfd_get_gp_value (output_bfd
);
1496 relocateable
= false;
1497 output_bfd
= symbol
->section
->output_section
->owner
;
1499 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1500 error_message
, &gp
);
1501 if (ret
!= bfd_reloc_ok
)
1505 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1506 relocateable
, data
, gp
);
1509 static bfd_reloc_status_type
1510 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1514 arelent
*reloc_entry
;
1515 asection
*input_section
;
1516 boolean relocateable
;
1523 if (bfd_is_com_section (symbol
->section
))
1526 relocation
= symbol
->value
;
1528 relocation
+= symbol
->section
->output_section
->vma
;
1529 relocation
+= symbol
->section
->output_offset
;
1531 if (reloc_entry
->address
> input_section
->_cooked_size
)
1532 return bfd_reloc_outofrange
;
1534 if (reloc_entry
->howto
->src_mask
== 0)
1536 /* This case arises with the 64-bit MIPS ELF ABI. */
1540 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1542 /* Set val to the offset into the section or symbol. */
1543 val
+= reloc_entry
->addend
;
1545 /* Adjust val for the final section location and GP value. If we
1546 are producing relocateable output, we don't want to do this for
1547 an external symbol. */
1549 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1550 val
+= relocation
- gp
;
1552 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1555 reloc_entry
->address
+= input_section
->output_offset
;
1557 return bfd_reloc_ok
;
1560 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1561 generated when addreses are 64 bits. The upper 32 bits are a simle
1564 static bfd_reloc_status_type
1565 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1566 output_bfd
, error_message
)
1568 arelent
*reloc_entry
;
1571 asection
*input_section
;
1573 char **error_message
;
1575 bfd_reloc_status_type r
;
1580 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1581 input_section
, output_bfd
, error_message
);
1582 if (r
!= bfd_reloc_continue
)
1585 /* Do a normal 32 bit relocation on the lower 32 bits. */
1586 reloc32
= *reloc_entry
;
1587 if (bfd_big_endian (abfd
))
1588 reloc32
.address
+= 4;
1589 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1590 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1591 output_bfd
, error_message
);
1593 /* Sign extend into the upper 32 bits. */
1594 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1595 if ((val
& 0x80000000) != 0)
1599 addr
= reloc_entry
->address
;
1600 if (bfd_little_endian (abfd
))
1602 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1607 /* Handle a mips16 jump. */
1609 static bfd_reloc_status_type
1610 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1611 output_bfd
, error_message
)
1613 arelent
*reloc_entry
;
1616 asection
*input_section
;
1618 char **error_message
;
1620 if (output_bfd
!= (bfd
*) NULL
1621 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1622 && reloc_entry
->addend
== 0)
1624 reloc_entry
->address
+= input_section
->output_offset
;
1625 return bfd_reloc_ok
;
1630 static boolean warned
;
1633 (*_bfd_error_handler
)
1634 (_("Linking mips16 objects into %s format is not supported"),
1635 bfd_get_target (input_section
->output_section
->owner
));
1639 return bfd_reloc_undefined
;
1642 /* Handle a mips16 GP relative reloc. */
1644 static bfd_reloc_status_type
1645 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1646 output_bfd
, error_message
)
1648 arelent
*reloc_entry
;
1651 asection
*input_section
;
1653 char **error_message
;
1655 boolean relocateable
;
1656 bfd_reloc_status_type ret
;
1658 unsigned short extend
, insn
;
1659 unsigned long final
;
1661 /* If we're relocating, and this is an external symbol with no
1662 addend, we don't want to change anything. We will only have an
1663 addend if this is a newly created reloc, not read from an ELF
1665 if (output_bfd
!= NULL
1666 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1667 && reloc_entry
->addend
== 0)
1669 reloc_entry
->address
+= input_section
->output_offset
;
1670 return bfd_reloc_ok
;
1673 if (output_bfd
!= NULL
)
1674 relocateable
= true;
1677 relocateable
= false;
1678 output_bfd
= symbol
->section
->output_section
->owner
;
1681 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1683 if (ret
!= bfd_reloc_ok
)
1686 if (reloc_entry
->address
> input_section
->_cooked_size
)
1687 return bfd_reloc_outofrange
;
1689 /* Pick up the mips16 extend instruction and the real instruction. */
1690 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1691 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1693 /* Stuff the current addend back as a 32 bit value, do the usual
1694 relocation, and then clean up. */
1696 (((extend
& 0x1f) << 11)
1699 (bfd_byte
*) data
+ reloc_entry
->address
);
1701 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1702 relocateable
, data
, gp
);
1704 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1707 | ((final
>> 11) & 0x1f)
1709 (bfd_byte
*) data
+ reloc_entry
->address
);
1713 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1718 /* Return the ISA for a MIPS e_flags value. */
1721 elf_mips_isa (flags
)
1724 switch (flags
& EF_MIPS_ARCH
)
1738 /* Return the MACH for a MIPS e_flags value. */
1741 elf_mips_mach (flags
)
1744 switch (flags
& EF_MIPS_MACH
)
1746 case E_MIPS_MACH_3900
:
1747 return bfd_mach_mips3900
;
1749 case E_MIPS_MACH_4010
:
1750 return bfd_mach_mips4010
;
1752 case E_MIPS_MACH_4100
:
1753 return bfd_mach_mips4100
;
1755 case E_MIPS_MACH_4111
:
1756 return bfd_mach_mips4111
;
1758 case E_MIPS_MACH_4650
:
1759 return bfd_mach_mips4650
;
1762 switch (flags
& EF_MIPS_ARCH
)
1766 return bfd_mach_mips3000
;
1770 return bfd_mach_mips6000
;
1774 return bfd_mach_mips4000
;
1778 return bfd_mach_mips8000
;
1786 /* Return printable name for ABI. */
1789 elf_mips_abi_name (abfd
)
1794 if (ABI_N32_P (abfd
))
1796 else if (ABI_64_P (abfd
))
1799 flags
= elf_elfheader (abfd
)->e_flags
;
1800 switch (flags
& EF_MIPS_ABI
)
1804 case E_MIPS_ABI_O32
:
1806 case E_MIPS_ABI_O64
:
1808 case E_MIPS_ABI_EABI32
:
1810 case E_MIPS_ABI_EABI64
:
1813 return "unknown abi";
1817 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1819 struct elf_reloc_map
{
1820 bfd_reloc_code_real_type bfd_reloc_val
;
1821 enum elf_mips_reloc_type elf_reloc_val
;
1824 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1826 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1827 { BFD_RELOC_16
, R_MIPS_16
},
1828 { BFD_RELOC_32
, R_MIPS_32
},
1829 { BFD_RELOC_64
, R_MIPS_64
},
1830 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1831 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1832 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1833 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1834 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1835 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1836 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1837 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1838 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1839 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1840 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1841 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1842 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
},
1843 { BFD_RELOC_MIPS_SUB
, R_MIPS_SUB
},
1844 { BFD_RELOC_MIPS_GOT_PAGE
, R_MIPS_GOT_PAGE
},
1845 { BFD_RELOC_MIPS_GOT_OFST
, R_MIPS_GOT_OFST
},
1846 { BFD_RELOC_MIPS_GOT_DISP
, R_MIPS_GOT_DISP
}
1849 /* Given a BFD reloc type, return a howto structure. */
1851 static reloc_howto_type
*
1852 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1854 bfd_reloc_code_real_type code
;
1858 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1860 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1861 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1867 bfd_set_error (bfd_error_bad_value
);
1870 case BFD_RELOC_CTOR
:
1871 /* We need to handle BFD_RELOC_CTOR specially.
1872 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1873 size of addresses on this architecture. */
1874 if (bfd_arch_bits_per_address (abfd
) == 32)
1875 return &elf_mips_howto_table
[(int) R_MIPS_32
];
1877 return &elf_mips_ctor64_howto
;
1879 case BFD_RELOC_MIPS16_JMP
:
1880 return &elf_mips16_jump_howto
;
1881 case BFD_RELOC_MIPS16_GPREL
:
1882 return &elf_mips16_gprel_howto
;
1883 case BFD_RELOC_VTABLE_INHERIT
:
1884 return &elf_mips_gnu_vtinherit_howto
;
1885 case BFD_RELOC_VTABLE_ENTRY
:
1886 return &elf_mips_gnu_vtentry_howto
;
1890 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
1893 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1896 Elf32_Internal_Rel
*dst
;
1898 unsigned int r_type
;
1900 r_type
= ELF32_R_TYPE (dst
->r_info
);
1904 cache_ptr
->howto
= &elf_mips16_jump_howto
;
1906 case R_MIPS16_GPREL
:
1907 cache_ptr
->howto
= &elf_mips16_gprel_howto
;
1909 case R_MIPS_GNU_VTINHERIT
:
1910 cache_ptr
->howto
= &elf_mips_gnu_vtinherit_howto
;
1912 case R_MIPS_GNU_VTENTRY
:
1913 cache_ptr
->howto
= &elf_mips_gnu_vtentry_howto
;
1917 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1918 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1922 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1923 value for the object file. We get the addend now, rather than
1924 when we do the relocation, because the symbol manipulations done
1925 by the linker may cause us to lose track of the input BFD. */
1926 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1927 && (r_type
== (unsigned int) R_MIPS_GPREL16
1928 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1929 cache_ptr
->addend
= elf_gp (abfd
);
1932 /* Given a MIPS Elf32_Internal_Rela, fill in an arelent structure. */
1935 mips_info_to_howto_rela (abfd
, cache_ptr
, dst
)
1938 Elf32_Internal_Rela
*dst
;
1940 /* Since an Elf32_Internal_Rel is an initial prefix of an
1941 Elf32_Internal_Rela, we can just use mips_info_to_howto_rel
1943 mips_info_to_howto_rel (abfd
, cache_ptr
, (Elf32_Internal_Rel
*) dst
);
1945 /* If we ever need to do any extra processing with dst->r_addend
1946 (the field omitted in an Elf32_Internal_Rel) we can do it here. */
1949 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1950 routines swap this structure in and out. They are used outside of
1951 BFD, so they are globally visible. */
1954 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1956 const Elf32_External_RegInfo
*ex
;
1959 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1960 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1961 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1962 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1963 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1964 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1968 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1970 const Elf32_RegInfo
*in
;
1971 Elf32_External_RegInfo
*ex
;
1973 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1974 (bfd_byte
*) ex
->ri_gprmask
);
1975 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1976 (bfd_byte
*) ex
->ri_cprmask
[0]);
1977 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1978 (bfd_byte
*) ex
->ri_cprmask
[1]);
1979 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1980 (bfd_byte
*) ex
->ri_cprmask
[2]);
1981 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1982 (bfd_byte
*) ex
->ri_cprmask
[3]);
1983 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1984 (bfd_byte
*) ex
->ri_gp_value
);
1987 /* In the 64 bit ABI, the .MIPS.options section holds register
1988 information in an Elf64_Reginfo structure. These routines swap
1989 them in and out. They are globally visible because they are used
1990 outside of BFD. These routines are here so that gas can call them
1991 without worrying about whether the 64 bit ABI has been included. */
1994 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1996 const Elf64_External_RegInfo
*ex
;
1997 Elf64_Internal_RegInfo
*in
;
1999 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
2000 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
2001 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
2002 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
2003 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
2004 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
2005 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
2009 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
2011 const Elf64_Internal_RegInfo
*in
;
2012 Elf64_External_RegInfo
*ex
;
2014 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
2015 (bfd_byte
*) ex
->ri_gprmask
);
2016 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
2017 (bfd_byte
*) ex
->ri_pad
);
2018 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
2019 (bfd_byte
*) ex
->ri_cprmask
[0]);
2020 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
2021 (bfd_byte
*) ex
->ri_cprmask
[1]);
2022 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
2023 (bfd_byte
*) ex
->ri_cprmask
[2]);
2024 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
2025 (bfd_byte
*) ex
->ri_cprmask
[3]);
2026 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
2027 (bfd_byte
*) ex
->ri_gp_value
);
2030 /* Swap an entry in a .gptab section. Note that these routines rely
2031 on the equivalence of the two elements of the union. */
2034 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
2036 const Elf32_External_gptab
*ex
;
2039 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
2040 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
2044 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
2046 const Elf32_gptab
*in
;
2047 Elf32_External_gptab
*ex
;
2049 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
2050 ex
->gt_entry
.gt_g_value
);
2051 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
2052 ex
->gt_entry
.gt_bytes
);
2056 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
2058 const Elf32_compact_rel
*in
;
2059 Elf32_External_compact_rel
*ex
;
2061 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
2062 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
2063 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
2064 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
2065 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
2066 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
2070 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
2072 const Elf32_crinfo
*in
;
2073 Elf32_External_crinfo
*ex
;
2077 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
2078 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
2079 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
2080 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
2081 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
2082 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
2083 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
2086 /* Swap in an options header. */
2089 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
2091 const Elf_External_Options
*ex
;
2092 Elf_Internal_Options
*in
;
2094 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
2095 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
2096 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
2097 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
2100 /* Swap out an options header. */
2103 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
2105 const Elf_Internal_Options
*in
;
2106 Elf_External_Options
*ex
;
2108 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
2109 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
2110 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
2111 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
2114 /* Swap in an MSYM entry. */
2117 bfd_mips_elf_swap_msym_in (abfd
, ex
, in
)
2119 const Elf32_External_Msym
*ex
;
2120 Elf32_Internal_Msym
*in
;
2122 in
->ms_hash_value
= bfd_h_get_32 (abfd
, ex
->ms_hash_value
);
2123 in
->ms_info
= bfd_h_get_32 (abfd
, ex
->ms_info
);
2126 /* Swap out an MSYM entry. */
2129 bfd_mips_elf_swap_msym_out (abfd
, in
, ex
)
2131 const Elf32_Internal_Msym
*in
;
2132 Elf32_External_Msym
*ex
;
2134 bfd_h_put_32 (abfd
, in
->ms_hash_value
, ex
->ms_hash_value
);
2135 bfd_h_put_32 (abfd
, in
->ms_info
, ex
->ms_info
);
2139 /* Determine whether a symbol is global for the purposes of splitting
2140 the symbol table into global symbols and local symbols. At least
2141 on Irix 5, this split must be between section symbols and all other
2142 symbols. On most ELF targets the split is between static symbols
2143 and externally visible symbols. */
2147 mips_elf_sym_is_global (abfd
, sym
)
2151 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
2154 /* Set the right machine number for a MIPS ELF file. This is used for
2155 both the 32-bit and the 64-bit ABI. */
2158 _bfd_mips_elf_object_p (abfd
)
2161 /* Irix 5 and 6 is broken. Object file symbol tables are not always
2162 sorted correctly such that local symbols precede global symbols,
2163 and the sh_info field in the symbol table is not always right. */
2164 elf_bad_symtab (abfd
) = true;
2166 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
,
2167 elf_mips_mach (elf_elfheader (abfd
)->e_flags
));
2171 /* The final processing done just before writing out a MIPS ELF object
2172 file. This gets the MIPS architecture right based on the machine
2173 number. This is used by both the 32-bit and the 64-bit ABI. */
2177 _bfd_mips_elf_final_write_processing (abfd
, linker
)
2183 Elf_Internal_Shdr
**hdrpp
;
2187 switch (bfd_get_mach (abfd
))
2190 case bfd_mach_mips3000
:
2191 val
= E_MIPS_ARCH_1
;
2194 case bfd_mach_mips3900
:
2195 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
2198 case bfd_mach_mips6000
:
2199 val
= E_MIPS_ARCH_2
;
2202 case bfd_mach_mips4000
:
2203 case bfd_mach_mips4300
:
2204 val
= E_MIPS_ARCH_3
;
2207 case bfd_mach_mips4010
:
2208 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
2211 case bfd_mach_mips4100
:
2212 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
2215 case bfd_mach_mips4111
:
2216 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
2219 case bfd_mach_mips4650
:
2220 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
2223 case bfd_mach_mips8000
:
2224 val
= E_MIPS_ARCH_4
;
2228 elf_elfheader (abfd
)->e_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2229 elf_elfheader (abfd
)->e_flags
|= val
;
2231 /* Set the sh_info field for .gptab sections and other appropriate
2232 info for each special section. */
2233 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
2234 i
< elf_elfheader (abfd
)->e_shnum
;
2237 switch ((*hdrpp
)->sh_type
)
2240 case SHT_MIPS_LIBLIST
:
2241 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
2243 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2246 case SHT_MIPS_GPTAB
:
2247 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2248 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2249 BFD_ASSERT (name
!= NULL
2250 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
2251 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
2252 BFD_ASSERT (sec
!= NULL
);
2253 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2256 case SHT_MIPS_CONTENT
:
2257 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2258 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2259 BFD_ASSERT (name
!= NULL
2260 && strncmp (name
, ".MIPS.content",
2261 sizeof ".MIPS.content" - 1) == 0);
2262 sec
= bfd_get_section_by_name (abfd
,
2263 name
+ sizeof ".MIPS.content" - 1);
2264 BFD_ASSERT (sec
!= NULL
);
2265 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2268 case SHT_MIPS_SYMBOL_LIB
:
2269 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
2271 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2272 sec
= bfd_get_section_by_name (abfd
, ".liblist");
2274 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2277 case SHT_MIPS_EVENTS
:
2278 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2279 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2280 BFD_ASSERT (name
!= NULL
);
2281 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
2282 sec
= bfd_get_section_by_name (abfd
,
2283 name
+ sizeof ".MIPS.events" - 1);
2286 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
2287 sizeof ".MIPS.post_rel" - 1) == 0);
2288 sec
= bfd_get_section_by_name (abfd
,
2290 + sizeof ".MIPS.post_rel" - 1));
2292 BFD_ASSERT (sec
!= NULL
);
2293 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2300 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
2303 _bfd_mips_elf_set_private_flags (abfd
, flags
)
2307 BFD_ASSERT (!elf_flags_init (abfd
)
2308 || elf_elfheader (abfd
)->e_flags
== flags
);
2310 elf_elfheader (abfd
)->e_flags
= flags
;
2311 elf_flags_init (abfd
) = true;
2315 /* Copy backend specific data from one object module to another */
2318 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
2322 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2323 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2326 BFD_ASSERT (!elf_flags_init (obfd
)
2327 || (elf_elfheader (obfd
)->e_flags
2328 == elf_elfheader (ibfd
)->e_flags
));
2330 elf_gp (obfd
) = elf_gp (ibfd
);
2331 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
2332 elf_flags_init (obfd
) = true;
2336 /* Merge backend specific data from an object file to the output
2337 object file when linking. */
2340 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
2348 /* Check if we have the same endianess */
2349 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2350 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2354 if (bfd_big_endian (ibfd
))
2355 msg
= _("%s: compiled for a big endian system and target is little endian");
2357 msg
= _("%s: compiled for a little endian system and target is big endian");
2359 (*_bfd_error_handler
) (msg
, bfd_get_filename (ibfd
));
2361 bfd_set_error (bfd_error_wrong_format
);
2365 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2366 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2369 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2370 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
2371 old_flags
= elf_elfheader (obfd
)->e_flags
;
2373 if (! elf_flags_init (obfd
))
2375 elf_flags_init (obfd
) = true;
2376 elf_elfheader (obfd
)->e_flags
= new_flags
;
2377 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
2378 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
2380 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2381 && bfd_get_arch_info (obfd
)->the_default
)
2383 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
2384 bfd_get_mach (ibfd
)))
2391 /* Check flag compatibility. */
2393 new_flags
&= ~EF_MIPS_NOREORDER
;
2394 old_flags
&= ~EF_MIPS_NOREORDER
;
2396 if (new_flags
== old_flags
)
2401 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
2403 new_flags
&= ~EF_MIPS_PIC
;
2404 old_flags
&= ~EF_MIPS_PIC
;
2405 (*_bfd_error_handler
)
2406 (_("%s: linking PIC files with non-PIC files"),
2407 bfd_get_filename (ibfd
));
2411 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
2413 new_flags
&= ~EF_MIPS_CPIC
;
2414 old_flags
&= ~EF_MIPS_CPIC
;
2415 (*_bfd_error_handler
)
2416 (_("%s: linking abicalls files with non-abicalls files"),
2417 bfd_get_filename (ibfd
));
2421 /* Compare the ISA's. */
2422 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
2423 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
2425 int new_mach
= new_flags
& EF_MIPS_MACH
;
2426 int old_mach
= old_flags
& EF_MIPS_MACH
;
2427 int new_isa
= elf_mips_isa (new_flags
);
2428 int old_isa
= elf_mips_isa (old_flags
);
2430 /* If either has no machine specified, just compare the general isa's.
2431 Some combinations of machines are ok, if the isa's match. */
2434 || new_mach
== old_mach
2437 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
2438 and -mips4 code. They will normally use the same data sizes and
2439 calling conventions. */
2441 if ((new_isa
== 1 || new_isa
== 2)
2442 ? (old_isa
!= 1 && old_isa
!= 2)
2443 : (old_isa
== 1 || old_isa
== 2))
2445 (*_bfd_error_handler
)
2446 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
2447 bfd_get_filename (ibfd
), new_isa
, old_isa
);
2454 (*_bfd_error_handler
)
2455 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
2456 bfd_get_filename (ibfd
),
2457 elf_mips_mach (new_flags
),
2458 elf_mips_mach (old_flags
));
2462 new_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2463 old_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2466 /* Compare ABI's. The 64-bit ABI does not use EF_MIPS_ABI. But, it
2467 does set EI_CLASS differently from any 32-bit ABI. */
2468 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
2469 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
2470 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
2472 /* Only error if both are set (to different values). */
2473 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
2474 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
2475 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
2477 (*_bfd_error_handler
)
2478 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
2479 bfd_get_filename (ibfd
),
2480 elf_mips_abi_name (ibfd
),
2481 elf_mips_abi_name (obfd
));
2484 new_flags
&= ~EF_MIPS_ABI
;
2485 old_flags
&= ~EF_MIPS_ABI
;
2488 /* Warn about any other mismatches */
2489 if (new_flags
!= old_flags
)
2491 (*_bfd_error_handler
)
2492 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2493 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
2494 (unsigned long) old_flags
);
2500 bfd_set_error (bfd_error_bad_value
);
2508 _bfd_mips_elf_print_private_bfd_data (abfd
, ptr
)
2512 FILE *file
= (FILE *) ptr
;
2514 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
2516 /* Print normal ELF private data. */
2517 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
2519 /* xgettext:c-format */
2520 fprintf (file
, _ ("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
2522 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
2523 fprintf (file
, _ (" [abi=O32]"));
2524 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
2525 fprintf (file
, _ (" [abi=O64]"));
2526 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
2527 fprintf (file
, _ (" [abi=EABI32]"));
2528 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
2529 fprintf (file
, _ (" [abi=EABI64]"));
2530 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
2531 fprintf (file
, _ (" [abi unknown]"));
2532 else if (ABI_N32_P (abfd
))
2533 fprintf (file
, _ (" [abi=N32]"));
2534 else if (ABI_64_P (abfd
))
2535 fprintf (file
, _ (" [abi=64]"));
2537 fprintf (file
, _ (" [no abi set]"));
2539 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
2540 fprintf (file
, _ (" [mips1]"));
2541 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
2542 fprintf (file
, _ (" [mips2]"));
2543 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
2544 fprintf (file
, _ (" [mips3]"));
2545 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
2546 fprintf (file
, _ (" [mips4]"));
2548 fprintf (file
, _ (" [unknown ISA]"));
2550 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
2551 fprintf (file
, _ (" [32bitmode]"));
2553 fprintf (file
, _ (" [not 32bitmode]"));
2560 /* Handle a MIPS specific section when reading an object file. This
2561 is called when elfcode.h finds a section with an unknown type.
2562 This routine supports both the 32-bit and 64-bit ELF ABI.
2564 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2568 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
2570 Elf_Internal_Shdr
*hdr
;
2575 /* There ought to be a place to keep ELF backend specific flags, but
2576 at the moment there isn't one. We just keep track of the
2577 sections by their name, instead. Fortunately, the ABI gives
2578 suggested names for all the MIPS specific sections, so we will
2579 probably get away with this. */
2580 switch (hdr
->sh_type
)
2582 case SHT_MIPS_LIBLIST
:
2583 if (strcmp (name
, ".liblist") != 0)
2587 if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) != 0)
2590 case SHT_MIPS_CONFLICT
:
2591 if (strcmp (name
, ".conflict") != 0)
2594 case SHT_MIPS_GPTAB
:
2595 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
2598 case SHT_MIPS_UCODE
:
2599 if (strcmp (name
, ".ucode") != 0)
2602 case SHT_MIPS_DEBUG
:
2603 if (strcmp (name
, ".mdebug") != 0)
2605 flags
= SEC_DEBUGGING
;
2607 case SHT_MIPS_REGINFO
:
2608 if (strcmp (name
, ".reginfo") != 0
2609 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
2611 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
2613 case SHT_MIPS_IFACE
:
2614 if (strcmp (name
, ".MIPS.interfaces") != 0)
2617 case SHT_MIPS_CONTENT
:
2618 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2621 case SHT_MIPS_OPTIONS
:
2622 if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) != 0)
2625 case SHT_MIPS_DWARF
:
2626 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2629 case SHT_MIPS_SYMBOL_LIB
:
2630 if (strcmp (name
, ".MIPS.symlib") != 0)
2633 case SHT_MIPS_EVENTS
:
2634 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2635 && strncmp (name
, ".MIPS.post_rel",
2636 sizeof ".MIPS.post_rel" - 1) != 0)
2643 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2648 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
2649 (bfd_get_section_flags (abfd
,
2655 /* FIXME: We should record sh_info for a .gptab section. */
2657 /* For a .reginfo section, set the gp value in the tdata information
2658 from the contents of this section. We need the gp value while
2659 processing relocs, so we just get it now. The .reginfo section
2660 is not used in the 64-bit MIPS ELF ABI. */
2661 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2663 Elf32_External_RegInfo ext
;
2666 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
2667 (file_ptr
) 0, sizeof ext
))
2669 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
2670 elf_gp (abfd
) = s
.ri_gp_value
;
2673 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2674 set the gp value based on what we find. We may see both
2675 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2676 they should agree. */
2677 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
2679 bfd_byte
*contents
, *l
, *lend
;
2681 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
2682 if (contents
== NULL
)
2684 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
2685 (file_ptr
) 0, hdr
->sh_size
))
2691 lend
= contents
+ hdr
->sh_size
;
2692 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2694 Elf_Internal_Options intopt
;
2696 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2698 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
2700 Elf64_Internal_RegInfo intreg
;
2702 bfd_mips_elf64_swap_reginfo_in
2704 ((Elf64_External_RegInfo
*)
2705 (l
+ sizeof (Elf_External_Options
))),
2707 elf_gp (abfd
) = intreg
.ri_gp_value
;
2709 else if (intopt
.kind
== ODK_REGINFO
)
2711 Elf32_RegInfo intreg
;
2713 bfd_mips_elf32_swap_reginfo_in
2715 ((Elf32_External_RegInfo
*)
2716 (l
+ sizeof (Elf_External_Options
))),
2718 elf_gp (abfd
) = intreg
.ri_gp_value
;
2728 /* Set the correct type for a MIPS ELF section. We do this by the
2729 section name, which is a hack, but ought to work. This routine is
2730 used by both the 32-bit and the 64-bit ABI. */
2733 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
2735 Elf32_Internal_Shdr
*hdr
;
2738 register const char *name
;
2740 name
= bfd_get_section_name (abfd
, sec
);
2742 if (strcmp (name
, ".liblist") == 0)
2744 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
2745 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
2746 /* The sh_link field is set in final_write_processing. */
2748 else if (strcmp (name
, ".conflict") == 0)
2749 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
2750 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2752 hdr
->sh_type
= SHT_MIPS_GPTAB
;
2753 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
2754 /* The sh_info field is set in final_write_processing. */
2756 else if (strcmp (name
, ".ucode") == 0)
2757 hdr
->sh_type
= SHT_MIPS_UCODE
;
2758 else if (strcmp (name
, ".mdebug") == 0)
2760 hdr
->sh_type
= SHT_MIPS_DEBUG
;
2761 /* In a shared object on Irix 5.3, the .mdebug section has an
2762 entsize of 0. FIXME: Does this matter? */
2763 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2764 hdr
->sh_entsize
= 0;
2766 hdr
->sh_entsize
= 1;
2768 else if (strcmp (name
, ".reginfo") == 0)
2770 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2771 /* In a shared object on Irix 5.3, the .reginfo section has an
2772 entsize of 0x18. FIXME: Does this matter? */
2773 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2774 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2776 hdr
->sh_entsize
= 1;
2778 else if (SGI_COMPAT (abfd
)
2779 && (strcmp (name
, ".hash") == 0
2780 || strcmp (name
, ".dynamic") == 0
2781 || strcmp (name
, ".dynstr") == 0))
2783 hdr
->sh_entsize
= 0;
2785 /* This isn't how the Irix 6 linker behaves. */
2786 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2789 else if (strcmp (name
, ".got") == 0
2790 || strcmp (name
, MIPS_ELF_SRDATA_SECTION_NAME (abfd
)) == 0
2791 || strcmp (name
, ".sdata") == 0
2792 || strcmp (name
, ".sbss") == 0
2793 || strcmp (name
, ".lit4") == 0
2794 || strcmp (name
, ".lit8") == 0)
2795 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2796 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2798 hdr
->sh_type
= SHT_MIPS_IFACE
;
2799 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2801 else if (strncmp (name
, ".MIPS.content", strlen (".MIPS.content")) == 0)
2803 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2804 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2805 /* The sh_info field is set in final_write_processing. */
2807 else if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
2809 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2810 hdr
->sh_entsize
= 1;
2811 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2813 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2814 hdr
->sh_type
= SHT_MIPS_DWARF
;
2815 else if (strcmp (name
, ".MIPS.symlib") == 0)
2817 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2818 /* The sh_link and sh_info fields are set in
2819 final_write_processing. */
2821 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2822 || strncmp (name
, ".MIPS.post_rel",
2823 sizeof ".MIPS.post_rel" - 1) == 0)
2825 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2826 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2827 /* The sh_link field is set in final_write_processing. */
2829 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) == 0)
2831 hdr
->sh_type
= SHT_MIPS_MSYM
;
2832 hdr
->sh_flags
|= SHF_ALLOC
;
2833 hdr
->sh_entsize
= 8;
2836 /* The generic elf_fake_sections will set up REL_HDR using the
2837 default kind of relocations. But, we may actually need both
2838 kinds of relocations, so we set up the second header here. */
2839 if ((sec
->flags
& SEC_RELOC
) != 0)
2841 struct bfd_elf_section_data
*esd
;
2843 esd
= elf_section_data (sec
);
2844 BFD_ASSERT (esd
->rel_hdr2
== NULL
);
2846 = (Elf_Internal_Shdr
*) bfd_zalloc (abfd
, sizeof (Elf_Internal_Shdr
));
2849 _bfd_elf_init_reloc_shdr (abfd
, esd
->rel_hdr2
, sec
,
2850 !elf_section_data (sec
)->use_rela_p
);
2856 /* Given a BFD section, try to locate the corresponding ELF section
2857 index. This is used by both the 32-bit and the 64-bit ABI.
2858 Actually, it's not clear to me that the 64-bit ABI supports these,
2859 but for non-PIC objects we will certainly want support for at least
2860 the .scommon section. */
2863 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2865 Elf32_Internal_Shdr
*hdr
;
2869 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2871 *retval
= SHN_MIPS_SCOMMON
;
2874 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2876 *retval
= SHN_MIPS_ACOMMON
;
2882 /* When are writing out the .options or .MIPS.options section,
2883 remember the bytes we are writing out, so that we can install the
2884 GP value in the section_processing routine. */
2887 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2892 bfd_size_type count
;
2894 if (strcmp (section
->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
2898 if (elf_section_data (section
) == NULL
)
2900 section
->used_by_bfd
=
2901 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
2902 if (elf_section_data (section
) == NULL
)
2905 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
2910 if (section
->_cooked_size
!= 0)
2911 size
= section
->_cooked_size
;
2913 size
= section
->_raw_size
;
2914 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
2917 elf_section_data (section
)->tdata
= (PTR
) c
;
2920 memcpy (c
+ offset
, location
, count
);
2923 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
2927 /* Work over a section just before writing it out. This routine is
2928 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2929 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2933 _bfd_mips_elf_section_processing (abfd
, hdr
)
2935 Elf_Internal_Shdr
*hdr
;
2937 if (hdr
->sh_type
== SHT_MIPS_REGINFO
2938 && hdr
->sh_size
> 0)
2942 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2943 BFD_ASSERT (hdr
->contents
== NULL
);
2946 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2949 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2950 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2954 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2955 && hdr
->bfd_section
!= NULL
2956 && elf_section_data (hdr
->bfd_section
) != NULL
2957 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2959 bfd_byte
*contents
, *l
, *lend
;
2961 /* We stored the section contents in the elf_section_data tdata
2962 field in the set_section_contents routine. We save the
2963 section contents so that we don't have to read them again.
2964 At this point we know that elf_gp is set, so we can look
2965 through the section contents to see if there is an
2966 ODK_REGINFO structure. */
2968 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2970 lend
= contents
+ hdr
->sh_size
;
2971 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2973 Elf_Internal_Options intopt
;
2975 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2977 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
2984 + sizeof (Elf_External_Options
)
2985 + (sizeof (Elf64_External_RegInfo
) - 8)),
2988 bfd_h_put_64 (abfd
, elf_gp (abfd
), buf
);
2989 if (bfd_write (buf
, 1, 8, abfd
) != 8)
2992 else if (intopt
.kind
== ODK_REGINFO
)
2999 + sizeof (Elf_External_Options
)
3000 + (sizeof (Elf32_External_RegInfo
) - 4)),
3003 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
3004 if (bfd_write (buf
, 1, 4, abfd
) != 4)
3011 if (hdr
->bfd_section
!= NULL
)
3013 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
3015 if (strcmp (name
, ".sdata") == 0
3016 || strcmp (name
, ".lit8") == 0
3017 || strcmp (name
, ".lit4") == 0)
3019 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3020 hdr
->sh_type
= SHT_PROGBITS
;
3022 else if (strcmp (name
, ".sbss") == 0)
3024 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3025 hdr
->sh_type
= SHT_NOBITS
;
3027 else if (strcmp (name
, MIPS_ELF_SRDATA_SECTION_NAME (abfd
)) == 0)
3029 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
3030 hdr
->sh_type
= SHT_PROGBITS
;
3032 else if (strcmp (name
, ".compact_rel") == 0)
3035 hdr
->sh_type
= SHT_PROGBITS
;
3037 else if (strcmp (name
, ".rtproc") == 0)
3039 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
3041 unsigned int adjust
;
3043 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
3045 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
3054 /* MIPS ELF uses two common sections. One is the usual one, and the
3055 other is for small objects. All the small objects are kept
3056 together, and then referenced via the gp pointer, which yields
3057 faster assembler code. This is what we use for the small common
3058 section. This approach is copied from ecoff.c. */
3059 static asection mips_elf_scom_section
;
3060 static asymbol mips_elf_scom_symbol
;
3061 static asymbol
*mips_elf_scom_symbol_ptr
;
3063 /* MIPS ELF also uses an acommon section, which represents an
3064 allocated common symbol which may be overridden by a
3065 definition in a shared library. */
3066 static asection mips_elf_acom_section
;
3067 static asymbol mips_elf_acom_symbol
;
3068 static asymbol
*mips_elf_acom_symbol_ptr
;
3070 /* The Irix 5 support uses two virtual sections, which represent
3071 text/data symbols defined in dynamic objects. */
3072 static asection mips_elf_text_section
;
3073 static asection
*mips_elf_text_section_ptr
;
3074 static asymbol mips_elf_text_symbol
;
3075 static asymbol
*mips_elf_text_symbol_ptr
;
3077 static asection mips_elf_data_section
;
3078 static asection
*mips_elf_data_section_ptr
;
3079 static asymbol mips_elf_data_symbol
;
3080 static asymbol
*mips_elf_data_symbol_ptr
;
3082 /* Handle the special MIPS section numbers that a symbol may use.
3083 This is used for both the 32-bit and the 64-bit ABI. */
3086 _bfd_mips_elf_symbol_processing (abfd
, asym
)
3090 elf_symbol_type
*elfsym
;
3092 elfsym
= (elf_symbol_type
*) asym
;
3093 switch (elfsym
->internal_elf_sym
.st_shndx
)
3095 case SHN_MIPS_ACOMMON
:
3096 /* This section is used in a dynamically linked executable file.
3097 It is an allocated common section. The dynamic linker can
3098 either resolve these symbols to something in a shared
3099 library, or it can just leave them here. For our purposes,
3100 we can consider these symbols to be in a new section. */
3101 if (mips_elf_acom_section
.name
== NULL
)
3103 /* Initialize the acommon section. */
3104 mips_elf_acom_section
.name
= ".acommon";
3105 mips_elf_acom_section
.flags
= SEC_ALLOC
;
3106 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
3107 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
3108 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
3109 mips_elf_acom_symbol
.name
= ".acommon";
3110 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
3111 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
3112 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
3114 asym
->section
= &mips_elf_acom_section
;
3118 /* Common symbols less than the GP size are automatically
3119 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
3120 if (asym
->value
> elf_gp_size (abfd
)
3121 || IRIX_COMPAT (abfd
) == ict_irix6
)
3124 case SHN_MIPS_SCOMMON
:
3125 if (mips_elf_scom_section
.name
== NULL
)
3127 /* Initialize the small common section. */
3128 mips_elf_scom_section
.name
= ".scommon";
3129 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
3130 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
3131 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
3132 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
3133 mips_elf_scom_symbol
.name
= ".scommon";
3134 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
3135 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
3136 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
3138 asym
->section
= &mips_elf_scom_section
;
3139 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
3142 case SHN_MIPS_SUNDEFINED
:
3143 asym
->section
= bfd_und_section_ptr
;
3146 #if 0 /* for SGI_COMPAT */
3148 asym
->section
= mips_elf_text_section_ptr
;
3152 asym
->section
= mips_elf_data_section_ptr
;
3158 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
3162 _bfd_mips_elf_additional_program_headers (abfd
)
3168 if (!SGI_COMPAT (abfd
))
3171 /* See if we need a PT_MIPS_REGINFO segment. */
3172 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3173 if (s
&& (s
->flags
& SEC_LOAD
))
3176 /* See if we need a PT_MIPS_OPTIONS segment. */
3177 if (IRIX_COMPAT (abfd
) == ict_irix6
3178 && bfd_get_section_by_name (abfd
,
3179 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
3182 /* See if we need a PT_MIPS_RTPROC segment. */
3183 if (IRIX_COMPAT (abfd
) == ict_irix5
3184 && bfd_get_section_by_name (abfd
, ".dynamic")
3185 && bfd_get_section_by_name (abfd
, ".mdebug"))
3191 /* Modify the segment map for an Irix 5 executable. */
3194 _bfd_mips_elf_modify_segment_map (abfd
)
3198 struct elf_segment_map
*m
, **pm
;
3200 if (! SGI_COMPAT (abfd
))
3203 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
3205 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3206 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3208 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3209 if (m
->p_type
== PT_MIPS_REGINFO
)
3213 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3217 m
->p_type
= PT_MIPS_REGINFO
;
3221 /* We want to put it after the PHDR and INTERP segments. */
3222 pm
= &elf_tdata (abfd
)->segment_map
;
3224 && ((*pm
)->p_type
== PT_PHDR
3225 || (*pm
)->p_type
== PT_INTERP
))
3233 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
3234 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
3235 PT_OPTIONS segement immediately following the program header
3237 if (IRIX_COMPAT (abfd
) == ict_irix6
)
3241 for (s
= abfd
->sections
; s
; s
= s
->next
)
3242 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
3247 struct elf_segment_map
*options_segment
;
3249 for (m
= elf_tdata (abfd
)->segment_map
; m
; m
= m
->next
)
3250 if (m
->p_type
== PT_PHDR
)
3253 /* There should always be a program header table. */
3257 options_segment
= bfd_zalloc (abfd
,
3258 sizeof (struct elf_segment_map
));
3259 options_segment
->next
= m
->next
;
3260 options_segment
->p_type
= PT_MIPS_OPTIONS
;
3261 options_segment
->p_flags
= PF_R
;
3262 options_segment
->p_flags_valid
= true;
3263 options_segment
->count
= 1;
3264 options_segment
->sections
[0] = s
;
3265 m
->next
= options_segment
;
3270 /* If there are .dynamic and .mdebug sections, we make a room
3271 for the RTPROC header. FIXME: Rewrite without section names. */
3272 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
3273 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3274 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3276 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3277 if (m
->p_type
== PT_MIPS_RTPROC
)
3281 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3285 m
->p_type
= PT_MIPS_RTPROC
;
3287 s
= bfd_get_section_by_name (abfd
, ".rtproc");
3292 m
->p_flags_valid
= 1;
3300 /* We want to put it after the DYNAMIC segment. */
3301 pm
= &elf_tdata (abfd
)->segment_map
;
3302 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
3312 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic,
3313 .dynstr, .dynsym, and .hash sections, and everything in
3315 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
3316 if ((*pm
)->p_type
== PT_DYNAMIC
)
3321 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
3323 static const char *sec_names
[] =
3324 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
3327 struct elf_segment_map
*n
;
3331 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
3333 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
3334 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3340 sz
= s
->_cooked_size
;
3343 if (high
< s
->vma
+ sz
)
3349 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3350 if ((s
->flags
& SEC_LOAD
) != 0
3353 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3357 n
= ((struct elf_segment_map
*)
3358 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
3365 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3367 if ((s
->flags
& SEC_LOAD
) != 0
3370 + (s
->_cooked_size
!= 0 ?
3371 s
->_cooked_size
: s
->_raw_size
))
3386 /* The structure of the runtime procedure descriptor created by the
3387 loader for use by the static exception system. */
3389 typedef struct runtime_pdr
{
3390 bfd_vma adr
; /* memory address of start of procedure */
3391 long regmask
; /* save register mask */
3392 long regoffset
; /* save register offset */
3393 long fregmask
; /* save floating point register mask */
3394 long fregoffset
; /* save floating point register offset */
3395 long frameoffset
; /* frame size */
3396 short framereg
; /* frame pointer register */
3397 short pcreg
; /* offset or reg of return pc */
3398 long irpss
; /* index into the runtime string table */
3400 struct exception_info
*exception_info
;/* pointer to exception array */
3402 #define cbRPDR sizeof(RPDR)
3403 #define rpdNil ((pRPDR) 0)
3405 /* Swap RPDR (runtime procedure table entry) for output. */
3407 static void ecoff_swap_rpdr_out
3408 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
3411 ecoff_swap_rpdr_out (abfd
, in
, ex
)
3414 struct rpdr_ext
*ex
;
3416 /* ecoff_put_off was defined in ecoffswap.h. */
3417 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
3418 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
3419 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
3420 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
3421 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
3422 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
3424 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
3425 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
3427 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
3429 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
3433 /* Read ECOFF debugging information from a .mdebug section into a
3434 ecoff_debug_info structure. */
3437 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
3440 struct ecoff_debug_info
*debug
;
3443 const struct ecoff_debug_swap
*swap
;
3444 char *ext_hdr
= NULL
;
3446 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3447 memset (debug
, 0, sizeof(*debug
));
3449 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
3450 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
3453 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
3454 swap
->external_hdr_size
)
3458 symhdr
= &debug
->symbolic_header
;
3459 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
3461 /* The symbolic header contains absolute file offsets and sizes to
3463 #define READ(ptr, offset, count, size, type) \
3464 if (symhdr->count == 0) \
3465 debug->ptr = NULL; \
3468 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
3469 if (debug->ptr == NULL) \
3470 goto error_return; \
3471 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3472 || (bfd_read (debug->ptr, size, symhdr->count, \
3473 abfd) != size * symhdr->count)) \
3474 goto error_return; \
3477 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
3478 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
3479 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
3480 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
3481 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
3482 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
3484 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
3485 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
3486 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
3487 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
3488 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
3492 debug
->adjust
= NULL
;
3497 if (ext_hdr
!= NULL
)
3499 if (debug
->line
!= NULL
)
3501 if (debug
->external_dnr
!= NULL
)
3502 free (debug
->external_dnr
);
3503 if (debug
->external_pdr
!= NULL
)
3504 free (debug
->external_pdr
);
3505 if (debug
->external_sym
!= NULL
)
3506 free (debug
->external_sym
);
3507 if (debug
->external_opt
!= NULL
)
3508 free (debug
->external_opt
);
3509 if (debug
->external_aux
!= NULL
)
3510 free (debug
->external_aux
);
3511 if (debug
->ss
!= NULL
)
3513 if (debug
->ssext
!= NULL
)
3514 free (debug
->ssext
);
3515 if (debug
->external_fdr
!= NULL
)
3516 free (debug
->external_fdr
);
3517 if (debug
->external_rfd
!= NULL
)
3518 free (debug
->external_rfd
);
3519 if (debug
->external_ext
!= NULL
)
3520 free (debug
->external_ext
);
3524 /* MIPS ELF local labels start with '$', not 'L'. */
3528 mips_elf_is_local_label_name (abfd
, name
)
3535 /* On Irix 6, the labels go back to starting with '.', so we accept
3536 the generic ELF local label syntax as well. */
3537 return _bfd_elf_is_local_label_name (abfd
, name
);
3540 /* MIPS ELF uses a special find_nearest_line routine in order the
3541 handle the ECOFF debugging information. */
3543 struct mips_elf_find_line
3545 struct ecoff_debug_info d
;
3546 struct ecoff_find_line i
;
3550 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
3551 functionname_ptr
, line_ptr
)
3556 const char **filename_ptr
;
3557 const char **functionname_ptr
;
3558 unsigned int *line_ptr
;
3562 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
3563 filename_ptr
, functionname_ptr
,
3567 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3568 filename_ptr
, functionname_ptr
,
3570 ABI_64_P (abfd
) ? 8 : 0))
3573 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
3577 struct mips_elf_find_line
*fi
;
3578 const struct ecoff_debug_swap
* const swap
=
3579 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3581 /* If we are called during a link, mips_elf_final_link may have
3582 cleared the SEC_HAS_CONTENTS field. We force it back on here
3583 if appropriate (which it normally will be). */
3584 origflags
= msec
->flags
;
3585 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
3586 msec
->flags
|= SEC_HAS_CONTENTS
;
3588 fi
= elf_tdata (abfd
)->find_line_info
;
3591 bfd_size_type external_fdr_size
;
3594 struct fdr
*fdr_ptr
;
3596 fi
= ((struct mips_elf_find_line
*)
3597 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
3600 msec
->flags
= origflags
;
3604 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
3606 msec
->flags
= origflags
;
3610 /* Swap in the FDR information. */
3611 fi
->d
.fdr
= ((struct fdr
*)
3613 (fi
->d
.symbolic_header
.ifdMax
*
3614 sizeof (struct fdr
))));
3615 if (fi
->d
.fdr
== NULL
)
3617 msec
->flags
= origflags
;
3620 external_fdr_size
= swap
->external_fdr_size
;
3621 fdr_ptr
= fi
->d
.fdr
;
3622 fraw_src
= (char *) fi
->d
.external_fdr
;
3623 fraw_end
= (fraw_src
3624 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
3625 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
3626 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
3628 elf_tdata (abfd
)->find_line_info
= fi
;
3630 /* Note that we don't bother to ever free this information.
3631 find_nearest_line is either called all the time, as in
3632 objdump -l, so the information should be saved, or it is
3633 rarely called, as in ld error messages, so the memory
3634 wasted is unimportant. Still, it would probably be a
3635 good idea for free_cached_info to throw it away. */
3638 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
3639 &fi
->i
, filename_ptr
, functionname_ptr
,
3642 msec
->flags
= origflags
;
3646 msec
->flags
= origflags
;
3649 /* Fall back on the generic ELF find_nearest_line routine. */
3651 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
3652 filename_ptr
, functionname_ptr
,
3656 /* The mips16 compiler uses a couple of special sections to handle
3657 floating point arguments.
3659 Section names that look like .mips16.fn.FNNAME contain stubs that
3660 copy floating point arguments from the fp regs to the gp regs and
3661 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3662 call should be redirected to the stub instead. If no 32 bit
3663 function calls FNNAME, the stub should be discarded. We need to
3664 consider any reference to the function, not just a call, because
3665 if the address of the function is taken we will need the stub,
3666 since the address might be passed to a 32 bit function.
3668 Section names that look like .mips16.call.FNNAME contain stubs
3669 that copy floating point arguments from the gp regs to the fp
3670 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3671 then any 16 bit function that calls FNNAME should be redirected
3672 to the stub instead. If FNNAME is not a 32 bit function, the
3673 stub should be discarded.
3675 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3676 which call FNNAME and then copy the return value from the fp regs
3677 to the gp regs. These stubs store the return value in $18 while
3678 calling FNNAME; any function which might call one of these stubs
3679 must arrange to save $18 around the call. (This case is not
3680 needed for 32 bit functions that call 16 bit functions, because
3681 16 bit functions always return floating point values in both
3684 Note that in all cases FNNAME might be defined statically.
3685 Therefore, FNNAME is not used literally. Instead, the relocation
3686 information will indicate which symbol the section is for.
3688 We record any stubs that we find in the symbol table. */
3690 #define FN_STUB ".mips16.fn."
3691 #define CALL_STUB ".mips16.call."
3692 #define CALL_FP_STUB ".mips16.call.fp."
3694 /* MIPS ELF linker hash table. */
3696 struct mips_elf_link_hash_table
3698 struct elf_link_hash_table root
;
3700 /* We no longer use this. */
3701 /* String section indices for the dynamic section symbols. */
3702 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
3704 /* The number of .rtproc entries. */
3705 bfd_size_type procedure_count
;
3706 /* The size of the .compact_rel section (if SGI_COMPAT). */
3707 bfd_size_type compact_rel_size
;
3708 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3709 entry is set to the address of __rld_obj_head as in Irix 5. */
3710 boolean use_rld_obj_head
;
3711 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3713 /* This is set if we see any mips16 stub sections. */
3714 boolean mips16_stubs_seen
;
3717 /* Look up an entry in a MIPS ELF linker hash table. */
3719 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3720 ((struct mips_elf_link_hash_entry *) \
3721 elf_link_hash_lookup (&(table)->root, (string), (create), \
3724 /* Traverse a MIPS ELF linker hash table. */
3726 #define mips_elf_link_hash_traverse(table, func, info) \
3727 (elf_link_hash_traverse \
3729 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3732 /* Get the MIPS ELF linker hash table from a link_info structure. */
3734 #define mips_elf_hash_table(p) \
3735 ((struct mips_elf_link_hash_table *) ((p)->hash))
3737 static boolean mips_elf_output_extsym
3738 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3740 /* Create an entry in a MIPS ELF linker hash table. */
3742 static struct bfd_hash_entry
*
3743 mips_elf_link_hash_newfunc (entry
, table
, string
)
3744 struct bfd_hash_entry
*entry
;
3745 struct bfd_hash_table
*table
;
3748 struct mips_elf_link_hash_entry
*ret
=
3749 (struct mips_elf_link_hash_entry
*) entry
;
3751 /* Allocate the structure if it has not already been allocated by a
3753 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3754 ret
= ((struct mips_elf_link_hash_entry
*)
3755 bfd_hash_allocate (table
,
3756 sizeof (struct mips_elf_link_hash_entry
)));
3757 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3758 return (struct bfd_hash_entry
*) ret
;
3760 /* Call the allocation method of the superclass. */
3761 ret
= ((struct mips_elf_link_hash_entry
*)
3762 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3764 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3766 /* Set local fields. */
3767 memset (&ret
->esym
, 0, sizeof (EXTR
));
3768 /* We use -2 as a marker to indicate that the information has
3769 not been set. -1 means there is no associated ifd. */
3771 ret
->mips_32_relocs
= 0;
3772 ret
->min_dyn_reloc_index
= 0;
3773 ret
->fn_stub
= NULL
;
3774 ret
->need_fn_stub
= false;
3775 ret
->call_stub
= NULL
;
3776 ret
->call_fp_stub
= NULL
;
3779 return (struct bfd_hash_entry
*) ret
;
3782 /* Create a MIPS ELF linker hash table. */
3784 struct bfd_link_hash_table
*
3785 _bfd_mips_elf_link_hash_table_create (abfd
)
3788 struct mips_elf_link_hash_table
*ret
;
3790 ret
= ((struct mips_elf_link_hash_table
*)
3791 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
3792 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
3795 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3796 mips_elf_link_hash_newfunc
))
3798 bfd_release (abfd
, ret
);
3803 /* We no longer use this. */
3804 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
3805 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
3807 ret
->procedure_count
= 0;
3808 ret
->compact_rel_size
= 0;
3809 ret
->use_rld_obj_head
= false;
3811 ret
->mips16_stubs_seen
= false;
3813 return &ret
->root
.root
;
3816 /* Hook called by the linker routine which adds symbols from an object
3817 file. We must handle the special MIPS section numbers here. */
3821 _bfd_mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3823 struct bfd_link_info
*info
;
3824 const Elf_Internal_Sym
*sym
;
3830 if (SGI_COMPAT (abfd
)
3831 && (abfd
->flags
& DYNAMIC
) != 0
3832 && strcmp (*namep
, "_rld_new_interface") == 0)
3834 /* Skip Irix 5 rld entry name. */
3839 switch (sym
->st_shndx
)
3842 /* Common symbols less than the GP size are automatically
3843 treated as SHN_MIPS_SCOMMON symbols. */
3844 if (sym
->st_size
> elf_gp_size (abfd
)
3845 || IRIX_COMPAT (abfd
) == ict_irix6
)
3848 case SHN_MIPS_SCOMMON
:
3849 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3850 (*secp
)->flags
|= SEC_IS_COMMON
;
3851 *valp
= sym
->st_size
;
3855 /* This section is used in a shared object. */
3856 if (mips_elf_text_section_ptr
== NULL
)
3858 /* Initialize the section. */
3859 mips_elf_text_section
.name
= ".text";
3860 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
3861 mips_elf_text_section
.output_section
= NULL
;
3862 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
3863 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
3864 mips_elf_text_symbol
.name
= ".text";
3865 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
3866 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
3867 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
3868 mips_elf_text_section_ptr
= &mips_elf_text_section
;
3870 /* This code used to do *secp = bfd_und_section_ptr if
3871 info->shared. I don't know why, and that doesn't make sense,
3872 so I took it out. */
3873 *secp
= mips_elf_text_section_ptr
;
3876 case SHN_MIPS_ACOMMON
:
3877 /* Fall through. XXX Can we treat this as allocated data? */
3879 /* This section is used in a shared object. */
3880 if (mips_elf_data_section_ptr
== NULL
)
3882 /* Initialize the section. */
3883 mips_elf_data_section
.name
= ".data";
3884 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
3885 mips_elf_data_section
.output_section
= NULL
;
3886 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
3887 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
3888 mips_elf_data_symbol
.name
= ".data";
3889 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
3890 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
3891 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
3892 mips_elf_data_section_ptr
= &mips_elf_data_section
;
3894 /* This code used to do *secp = bfd_und_section_ptr if
3895 info->shared. I don't know why, and that doesn't make sense,
3896 so I took it out. */
3897 *secp
= mips_elf_data_section_ptr
;
3900 case SHN_MIPS_SUNDEFINED
:
3901 *secp
= bfd_und_section_ptr
;
3905 if (SGI_COMPAT (abfd
)
3907 && info
->hash
->creator
== abfd
->xvec
3908 && strcmp (*namep
, "__rld_obj_head") == 0)
3910 struct elf_link_hash_entry
*h
;
3912 /* Mark __rld_obj_head as dynamic. */
3914 if (! (_bfd_generic_link_add_one_symbol
3915 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3916 (bfd_vma
) *valp
, (const char *) NULL
, false,
3917 get_elf_backend_data (abfd
)->collect
,
3918 (struct bfd_link_hash_entry
**) &h
)))
3920 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
3921 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3922 h
->type
= STT_OBJECT
;
3924 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3927 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3930 /* If this is a mips16 text symbol, add 1 to the value to make it
3931 odd. This will cause something like .word SYM to come up with
3932 the right value when it is loaded into the PC. */
3933 if (sym
->st_other
== STO_MIPS16
)
3939 /* Structure used to pass information to mips_elf_output_extsym. */
3944 struct bfd_link_info
*info
;
3945 struct ecoff_debug_info
*debug
;
3946 const struct ecoff_debug_swap
*swap
;
3950 /* This routine is used to write out ECOFF debugging external symbol
3951 information. It is called via mips_elf_link_hash_traverse. The
3952 ECOFF external symbol information must match the ELF external
3953 symbol information. Unfortunately, at this point we don't know
3954 whether a symbol is required by reloc information, so the two
3955 tables may wind up being different. We must sort out the external
3956 symbol information before we can set the final size of the .mdebug
3957 section, and we must set the size of the .mdebug section before we
3958 can relocate any sections, and we can't know which symbols are
3959 required by relocation until we relocate the sections.
3960 Fortunately, it is relatively unlikely that any symbol will be
3961 stripped but required by a reloc. In particular, it can not happen
3962 when generating a final executable. */
3965 mips_elf_output_extsym (h
, data
)
3966 struct mips_elf_link_hash_entry
*h
;
3969 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
3971 asection
*sec
, *output_section
;
3973 if (h
->root
.indx
== -2)
3975 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3976 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
3977 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3978 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
3980 else if (einfo
->info
->strip
== strip_all
3981 || (einfo
->info
->strip
== strip_some
3982 && bfd_hash_lookup (einfo
->info
->keep_hash
,
3983 h
->root
.root
.root
.string
,
3984 false, false) == NULL
))
3992 if (h
->esym
.ifd
== -2)
3995 h
->esym
.cobol_main
= 0;
3996 h
->esym
.weakext
= 0;
3997 h
->esym
.reserved
= 0;
3998 h
->esym
.ifd
= ifdNil
;
3999 h
->esym
.asym
.value
= 0;
4000 h
->esym
.asym
.st
= stGlobal
;
4002 if (SGI_COMPAT (einfo
->abfd
)
4003 && (h
->root
.root
.type
== bfd_link_hash_undefined
4004 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
4008 /* Use undefined class. Also, set class and type for some
4010 name
= h
->root
.root
.root
.string
;
4011 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
4012 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
4014 h
->esym
.asym
.sc
= scData
;
4015 h
->esym
.asym
.st
= stLabel
;
4016 h
->esym
.asym
.value
= 0;
4018 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
4020 h
->esym
.asym
.sc
= scAbs
;
4021 h
->esym
.asym
.st
= stLabel
;
4022 h
->esym
.asym
.value
=
4023 mips_elf_hash_table (einfo
->info
)->procedure_count
;
4025 else if (strcmp (name
, "_gp_disp") == 0)
4027 h
->esym
.asym
.sc
= scAbs
;
4028 h
->esym
.asym
.st
= stLabel
;
4029 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
4032 h
->esym
.asym
.sc
= scUndefined
;
4034 else if (h
->root
.root
.type
!= bfd_link_hash_defined
4035 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
4036 h
->esym
.asym
.sc
= scAbs
;
4041 sec
= h
->root
.root
.u
.def
.section
;
4042 output_section
= sec
->output_section
;
4044 /* When making a shared library and symbol h is the one from
4045 the another shared library, OUTPUT_SECTION may be null. */
4046 if (output_section
== NULL
)
4047 h
->esym
.asym
.sc
= scUndefined
;
4050 name
= bfd_section_name (output_section
->owner
, output_section
);
4052 if (strcmp (name
, ".text") == 0)
4053 h
->esym
.asym
.sc
= scText
;
4054 else if (strcmp (name
, ".data") == 0)
4055 h
->esym
.asym
.sc
= scData
;
4056 else if (strcmp (name
, ".sdata") == 0)
4057 h
->esym
.asym
.sc
= scSData
;
4058 else if (strcmp (name
, ".rodata") == 0
4059 || strcmp (name
, ".rdata") == 0)
4060 h
->esym
.asym
.sc
= scRData
;
4061 else if (strcmp (name
, ".bss") == 0)
4062 h
->esym
.asym
.sc
= scBss
;
4063 else if (strcmp (name
, ".sbss") == 0)
4064 h
->esym
.asym
.sc
= scSBss
;
4065 else if (strcmp (name
, ".init") == 0)
4066 h
->esym
.asym
.sc
= scInit
;
4067 else if (strcmp (name
, ".fini") == 0)
4068 h
->esym
.asym
.sc
= scFini
;
4070 h
->esym
.asym
.sc
= scAbs
;
4074 h
->esym
.asym
.reserved
= 0;
4075 h
->esym
.asym
.index
= indexNil
;
4078 if (h
->root
.root
.type
== bfd_link_hash_common
)
4079 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
4080 else if (h
->root
.root
.type
== bfd_link_hash_defined
4081 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4083 if (h
->esym
.asym
.sc
== scCommon
)
4084 h
->esym
.asym
.sc
= scBss
;
4085 else if (h
->esym
.asym
.sc
== scSCommon
)
4086 h
->esym
.asym
.sc
= scSBss
;
4088 sec
= h
->root
.root
.u
.def
.section
;
4089 output_section
= sec
->output_section
;
4090 if (output_section
!= NULL
)
4091 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
4092 + sec
->output_offset
4093 + output_section
->vma
);
4095 h
->esym
.asym
.value
= 0;
4097 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4099 /* Set type and value for a symbol with a function stub. */
4100 h
->esym
.asym
.st
= stProc
;
4101 sec
= h
->root
.root
.u
.def
.section
;
4103 h
->esym
.asym
.value
= 0;
4106 output_section
= sec
->output_section
;
4107 if (output_section
!= NULL
)
4108 h
->esym
.asym
.value
= (h
->root
.plt
.offset
4109 + sec
->output_offset
4110 + output_section
->vma
);
4112 h
->esym
.asym
.value
= 0;
4119 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
4120 h
->root
.root
.root
.string
,
4123 einfo
->failed
= true;
4130 /* Create a runtime procedure table from the .mdebug section. */
4133 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
4136 struct bfd_link_info
*info
;
4138 struct ecoff_debug_info
*debug
;
4140 const struct ecoff_debug_swap
*swap
;
4141 HDRR
*hdr
= &debug
->symbolic_header
;
4143 struct rpdr_ext
*erp
;
4145 struct pdr_ext
*epdr
;
4146 struct sym_ext
*esym
;
4149 unsigned long size
, count
;
4150 unsigned long sindex
;
4154 const char *no_name_func
= _("static procedure (no name)");
4162 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4164 sindex
= strlen (no_name_func
) + 1;
4165 count
= hdr
->ipdMax
;
4168 size
= swap
->external_pdr_size
;
4170 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
4174 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
4177 size
= sizeof (RPDR
);
4178 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
4182 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
4186 count
= hdr
->isymMax
;
4187 size
= swap
->external_sym_size
;
4188 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
4192 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
4195 count
= hdr
->issMax
;
4196 ss
= (char *) bfd_malloc (count
);
4199 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
4202 count
= hdr
->ipdMax
;
4203 for (i
= 0; i
< count
; i
++, rp
++)
4205 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
4206 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
4207 rp
->adr
= sym
.value
;
4208 rp
->regmask
= pdr
.regmask
;
4209 rp
->regoffset
= pdr
.regoffset
;
4210 rp
->fregmask
= pdr
.fregmask
;
4211 rp
->fregoffset
= pdr
.fregoffset
;
4212 rp
->frameoffset
= pdr
.frameoffset
;
4213 rp
->framereg
= pdr
.framereg
;
4214 rp
->pcreg
= pdr
.pcreg
;
4216 sv
[i
] = ss
+ sym
.iss
;
4217 sindex
+= strlen (sv
[i
]) + 1;
4221 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
4222 size
= BFD_ALIGN (size
, 16);
4223 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
4226 mips_elf_hash_table (info
)->procedure_count
= 0;
4230 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
4232 erp
= (struct rpdr_ext
*) rtproc
;
4233 memset (erp
, 0, sizeof (struct rpdr_ext
));
4235 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
4236 strcpy (str
, no_name_func
);
4237 str
+= strlen (no_name_func
) + 1;
4238 for (i
= 0; i
< count
; i
++)
4240 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
4241 strcpy (str
, sv
[i
]);
4242 str
+= strlen (sv
[i
]) + 1;
4244 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
4246 /* Set the size and contents of .rtproc section. */
4247 s
->_raw_size
= size
;
4248 s
->contents
= (bfd_byte
*) rtproc
;
4250 /* Skip this section later on (I don't think this currently
4251 matters, but someday it might). */
4252 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
4281 /* A comparison routine used to sort .gptab entries. */
4284 gptab_compare (p1
, p2
)
4288 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
4289 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
4291 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
4294 /* We need to use a special link routine to handle the .reginfo and
4295 the .mdebug sections. We need to merge all instances of these
4296 sections together, not write them all out sequentially. */
4299 _bfd_mips_elf_final_link (abfd
, info
)
4301 struct bfd_link_info
*info
;
4305 struct bfd_link_order
*p
;
4306 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
4307 asection
*rtproc_sec
;
4308 Elf32_RegInfo reginfo
;
4309 struct ecoff_debug_info debug
;
4310 const struct ecoff_debug_swap
*swap
4311 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4312 HDRR
*symhdr
= &debug
.symbolic_header
;
4313 PTR mdebug_handle
= NULL
;
4315 /* If all the things we linked together were PIC, but we're
4316 producing an executable (rather than a shared object), then the
4317 resulting file is CPIC (i.e., it calls PIC code.) */
4319 && !info
->relocateable
4320 && elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
4322 elf_elfheader (abfd
)->e_flags
&= ~EF_MIPS_PIC
;
4323 elf_elfheader (abfd
)->e_flags
|= EF_MIPS_CPIC
;
4326 /* On IRIX5, we omit the .options section. On IRIX6, however, we
4327 include it, even though we don't process it quite right. (Some
4328 entries are supposed to be merged.) Empirically, we seem to be
4329 better off including it then not. */
4330 if (IRIX_COMPAT (abfd
) == ict_irix5
)
4331 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
4333 if (strcmp ((*secpp
)->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
4335 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
4336 if (p
->type
== bfd_indirect_link_order
)
4337 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
4338 (*secpp
)->link_order_head
= NULL
;
4339 *secpp
= (*secpp
)->next
;
4340 --abfd
->section_count
;
4346 /* Get a value for the GP register. */
4347 if (elf_gp (abfd
) == 0)
4349 struct bfd_link_hash_entry
*h
;
4351 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4352 if (h
!= (struct bfd_link_hash_entry
*) NULL
4353 && h
->type
== bfd_link_hash_defined
)
4354 elf_gp (abfd
) = (h
->u
.def
.value
4355 + h
->u
.def
.section
->output_section
->vma
4356 + h
->u
.def
.section
->output_offset
);
4357 else if (info
->relocateable
)
4361 /* Find the GP-relative section with the lowest offset. */
4363 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4365 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
4368 /* And calculate GP relative to that. */
4369 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
4373 /* If the relocate_section function needs to do a reloc
4374 involving the GP value, it should make a reloc_dangerous
4375 callback to warn that GP is not defined. */
4379 /* Go through the sections and collect the .reginfo and .mdebug
4383 gptab_data_sec
= NULL
;
4384 gptab_bss_sec
= NULL
;
4385 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4387 if (strcmp (o
->name
, ".reginfo") == 0)
4389 memset (®info
, 0, sizeof reginfo
);
4391 /* We have found the .reginfo section in the output file.
4392 Look through all the link_orders comprising it and merge
4393 the information together. */
4394 for (p
= o
->link_order_head
;
4395 p
!= (struct bfd_link_order
*) NULL
;
4398 asection
*input_section
;
4400 Elf32_External_RegInfo ext
;
4403 if (p
->type
!= bfd_indirect_link_order
)
4405 if (p
->type
== bfd_fill_link_order
)
4410 input_section
= p
->u
.indirect
.section
;
4411 input_bfd
= input_section
->owner
;
4413 /* The linker emulation code has probably clobbered the
4414 size to be zero bytes. */
4415 if (input_section
->_raw_size
== 0)
4416 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4418 if (! bfd_get_section_contents (input_bfd
, input_section
,
4424 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
4426 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
4427 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
4428 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
4429 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
4430 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
4432 /* ri_gp_value is set by the function
4433 mips_elf32_section_processing when the section is
4434 finally written out. */
4436 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4437 elf_link_input_bfd ignores this section. */
4438 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4441 /* Size has been set in mips_elf_always_size_sections */
4442 BFD_ASSERT(o
->_raw_size
== sizeof (Elf32_External_RegInfo
));
4444 /* Skip this section later on (I don't think this currently
4445 matters, but someday it might). */
4446 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4451 if (strcmp (o
->name
, ".mdebug") == 0)
4453 struct extsym_info einfo
;
4455 /* We have found the .mdebug section in the output file.
4456 Look through all the link_orders comprising it and merge
4457 the information together. */
4458 symhdr
->magic
= swap
->sym_magic
;
4459 /* FIXME: What should the version stamp be? */
4461 symhdr
->ilineMax
= 0;
4465 symhdr
->isymMax
= 0;
4466 symhdr
->ioptMax
= 0;
4467 symhdr
->iauxMax
= 0;
4469 symhdr
->issExtMax
= 0;
4472 symhdr
->iextMax
= 0;
4474 /* We accumulate the debugging information itself in the
4475 debug_info structure. */
4477 debug
.external_dnr
= NULL
;
4478 debug
.external_pdr
= NULL
;
4479 debug
.external_sym
= NULL
;
4480 debug
.external_opt
= NULL
;
4481 debug
.external_aux
= NULL
;
4483 debug
.ssext
= debug
.ssext_end
= NULL
;
4484 debug
.external_fdr
= NULL
;
4485 debug
.external_rfd
= NULL
;
4486 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4488 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4489 if (mdebug_handle
== (PTR
) NULL
)
4492 if (SGI_COMPAT (abfd
))
4498 static const char * const name
[] =
4499 { ".text", ".init", ".fini", ".data",
4500 ".rodata", ".sdata", ".sbss", ".bss" };
4501 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
4502 scRData
, scSData
, scSBss
, scBss
};
4505 esym
.cobol_main
= 0;
4509 esym
.asym
.iss
= issNil
;
4510 esym
.asym
.st
= stLocal
;
4511 esym
.asym
.reserved
= 0;
4512 esym
.asym
.index
= indexNil
;
4514 for (i
= 0; i
< 8; i
++)
4516 esym
.asym
.sc
= sc
[i
];
4517 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4520 esym
.asym
.value
= s
->vma
;
4521 last
= s
->vma
+ s
->_raw_size
;
4524 esym
.asym
.value
= last
;
4526 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4532 for (p
= o
->link_order_head
;
4533 p
!= (struct bfd_link_order
*) NULL
;
4536 asection
*input_section
;
4538 const struct ecoff_debug_swap
*input_swap
;
4539 struct ecoff_debug_info input_debug
;
4543 if (p
->type
!= bfd_indirect_link_order
)
4545 if (p
->type
== bfd_fill_link_order
)
4550 input_section
= p
->u
.indirect
.section
;
4551 input_bfd
= input_section
->owner
;
4553 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4554 || (get_elf_backend_data (input_bfd
)
4555 ->elf_backend_ecoff_debug_swap
) == NULL
)
4557 /* I don't know what a non MIPS ELF bfd would be
4558 doing with a .mdebug section, but I don't really
4559 want to deal with it. */
4563 input_swap
= (get_elf_backend_data (input_bfd
)
4564 ->elf_backend_ecoff_debug_swap
);
4566 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
4568 /* The ECOFF linking code expects that we have already
4569 read in the debugging information and set up an
4570 ecoff_debug_info structure, so we do that now. */
4571 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
4575 if (! (bfd_ecoff_debug_accumulate
4576 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
4577 &input_debug
, input_swap
, info
)))
4580 /* Loop through the external symbols. For each one with
4581 interesting information, try to find the symbol in
4582 the linker global hash table and save the information
4583 for the output external symbols. */
4584 eraw_src
= input_debug
.external_ext
;
4585 eraw_end
= (eraw_src
4586 + (input_debug
.symbolic_header
.iextMax
4587 * input_swap
->external_ext_size
));
4589 eraw_src
< eraw_end
;
4590 eraw_src
+= input_swap
->external_ext_size
)
4594 struct mips_elf_link_hash_entry
*h
;
4596 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4597 if (ext
.asym
.sc
== scNil
4598 || ext
.asym
.sc
== scUndefined
4599 || ext
.asym
.sc
== scSUndefined
)
4602 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4603 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
4604 name
, false, false, true);
4605 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4611 < input_debug
.symbolic_header
.ifdMax
);
4612 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4618 /* Free up the information we just read. */
4619 free (input_debug
.line
);
4620 free (input_debug
.external_dnr
);
4621 free (input_debug
.external_pdr
);
4622 free (input_debug
.external_sym
);
4623 free (input_debug
.external_opt
);
4624 free (input_debug
.external_aux
);
4625 free (input_debug
.ss
);
4626 free (input_debug
.ssext
);
4627 free (input_debug
.external_fdr
);
4628 free (input_debug
.external_rfd
);
4629 free (input_debug
.external_ext
);
4631 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4632 elf_link_input_bfd ignores this section. */
4633 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4636 if (SGI_COMPAT (abfd
) && info
->shared
)
4638 /* Create .rtproc section. */
4639 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4640 if (rtproc_sec
== NULL
)
4642 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4643 | SEC_LINKER_CREATED
| SEC_READONLY
);
4645 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4646 if (rtproc_sec
== NULL
4647 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4648 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
4652 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
4653 info
, rtproc_sec
, &debug
))
4657 /* Build the external symbol information. */
4660 einfo
.debug
= &debug
;
4662 einfo
.failed
= false;
4663 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4664 mips_elf_output_extsym
,
4669 /* Set the size of the .mdebug section. */
4670 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4672 /* Skip this section later on (I don't think this currently
4673 matters, but someday it might). */
4674 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4679 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4681 const char *subname
;
4684 Elf32_External_gptab
*ext_tab
;
4687 /* The .gptab.sdata and .gptab.sbss sections hold
4688 information describing how the small data area would
4689 change depending upon the -G switch. These sections
4690 not used in executables files. */
4691 if (! info
->relocateable
)
4695 for (p
= o
->link_order_head
;
4696 p
!= (struct bfd_link_order
*) NULL
;
4699 asection
*input_section
;
4701 if (p
->type
!= bfd_indirect_link_order
)
4703 if (p
->type
== bfd_fill_link_order
)
4708 input_section
= p
->u
.indirect
.section
;
4710 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4711 elf_link_input_bfd ignores this section. */
4712 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4715 /* Skip this section later on (I don't think this
4716 currently matters, but someday it might). */
4717 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4719 /* Really remove the section. */
4720 for (secpp
= &abfd
->sections
;
4722 secpp
= &(*secpp
)->next
)
4724 *secpp
= (*secpp
)->next
;
4725 --abfd
->section_count
;
4730 /* There is one gptab for initialized data, and one for
4731 uninitialized data. */
4732 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4734 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4738 (*_bfd_error_handler
)
4739 (_("%s: illegal section name `%s'"),
4740 bfd_get_filename (abfd
), o
->name
);
4741 bfd_set_error (bfd_error_nonrepresentable_section
);
4745 /* The linker script always combines .gptab.data and
4746 .gptab.sdata into .gptab.sdata, and likewise for
4747 .gptab.bss and .gptab.sbss. It is possible that there is
4748 no .sdata or .sbss section in the output file, in which
4749 case we must change the name of the output section. */
4750 subname
= o
->name
+ sizeof ".gptab" - 1;
4751 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4753 if (o
== gptab_data_sec
)
4754 o
->name
= ".gptab.data";
4756 o
->name
= ".gptab.bss";
4757 subname
= o
->name
+ sizeof ".gptab" - 1;
4758 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4761 /* Set up the first entry. */
4763 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
4766 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4767 tab
[0].gt_header
.gt_unused
= 0;
4769 /* Combine the input sections. */
4770 for (p
= o
->link_order_head
;
4771 p
!= (struct bfd_link_order
*) NULL
;
4774 asection
*input_section
;
4778 bfd_size_type gpentry
;
4780 if (p
->type
!= bfd_indirect_link_order
)
4782 if (p
->type
== bfd_fill_link_order
)
4787 input_section
= p
->u
.indirect
.section
;
4788 input_bfd
= input_section
->owner
;
4790 /* Combine the gptab entries for this input section one
4791 by one. We know that the input gptab entries are
4792 sorted by ascending -G value. */
4793 size
= bfd_section_size (input_bfd
, input_section
);
4795 for (gpentry
= sizeof (Elf32_External_gptab
);
4797 gpentry
+= sizeof (Elf32_External_gptab
))
4799 Elf32_External_gptab ext_gptab
;
4800 Elf32_gptab int_gptab
;
4806 if (! (bfd_get_section_contents
4807 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4808 gpentry
, sizeof (Elf32_External_gptab
))))
4814 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
4816 val
= int_gptab
.gt_entry
.gt_g_value
;
4817 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4820 for (look
= 1; look
< c
; look
++)
4822 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4823 tab
[look
].gt_entry
.gt_bytes
+= add
;
4825 if (tab
[look
].gt_entry
.gt_g_value
== val
)
4831 Elf32_gptab
*new_tab
;
4834 /* We need a new table entry. */
4835 new_tab
= ((Elf32_gptab
*)
4836 bfd_realloc ((PTR
) tab
,
4837 (c
+ 1) * sizeof (Elf32_gptab
)));
4838 if (new_tab
== NULL
)
4844 tab
[c
].gt_entry
.gt_g_value
= val
;
4845 tab
[c
].gt_entry
.gt_bytes
= add
;
4847 /* Merge in the size for the next smallest -G
4848 value, since that will be implied by this new
4851 for (look
= 1; look
< c
; look
++)
4853 if (tab
[look
].gt_entry
.gt_g_value
< val
4855 || (tab
[look
].gt_entry
.gt_g_value
4856 > tab
[max
].gt_entry
.gt_g_value
)))
4860 tab
[c
].gt_entry
.gt_bytes
+=
4861 tab
[max
].gt_entry
.gt_bytes
;
4866 last
= int_gptab
.gt_entry
.gt_bytes
;
4869 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4870 elf_link_input_bfd ignores this section. */
4871 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4874 /* The table must be sorted by -G value. */
4876 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
4878 /* Swap out the table. */
4879 ext_tab
= ((Elf32_External_gptab
*)
4880 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
4881 if (ext_tab
== NULL
)
4887 for (i
= 0; i
< c
; i
++)
4888 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
4891 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
4892 o
->contents
= (bfd_byte
*) ext_tab
;
4894 /* Skip this section later on (I don't think this currently
4895 matters, but someday it might). */
4896 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4900 /* Invoke the regular ELF backend linker to do all the work. */
4901 if (ABI_64_P (abfd
))
4904 if (!bfd_elf64_bfd_final_link (abfd
, info
))
4911 else if (!bfd_elf32_bfd_final_link (abfd
, info
))
4914 /* Now write out the computed sections. */
4916 if (reginfo_sec
!= (asection
*) NULL
)
4918 Elf32_External_RegInfo ext
;
4920 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
4921 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4922 (file_ptr
) 0, sizeof ext
))
4926 if (mdebug_sec
!= (asection
*) NULL
)
4928 BFD_ASSERT (abfd
->output_has_begun
);
4929 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4931 mdebug_sec
->filepos
))
4934 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4937 if (gptab_data_sec
!= (asection
*) NULL
)
4939 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4940 gptab_data_sec
->contents
,
4942 gptab_data_sec
->_raw_size
))
4946 if (gptab_bss_sec
!= (asection
*) NULL
)
4948 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4949 gptab_bss_sec
->contents
,
4951 gptab_bss_sec
->_raw_size
))
4955 if (SGI_COMPAT (abfd
))
4957 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4958 if (rtproc_sec
!= NULL
)
4960 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
4961 rtproc_sec
->contents
,
4963 rtproc_sec
->_raw_size
))
4971 /* Handle a MIPS ELF HI16 reloc. */
4974 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
4976 Elf_Internal_Rela
*relhi
;
4977 Elf_Internal_Rela
*rello
;
4984 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4986 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4989 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4991 if ((addlo
& 0x8000) != 0)
4993 if ((addend
& 0x8000) != 0)
4996 bfd_put_32 (input_bfd
,
4997 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
4998 contents
+ relhi
->r_offset
);
5001 /* Handle a MIPS ELF local GOT16 reloc. */
5004 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
5009 Elf_Internal_Rela
*relhi
;
5010 Elf_Internal_Rela
*rello
;
5014 unsigned int assigned_gotno
;
5020 bfd_byte
*got_contents
;
5021 struct mips_got_info
*g
;
5023 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
5025 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
5028 addend
+= ((insn
& 0xffff) << 16) + addlo
;
5030 if ((addlo
& 0x8000) != 0)
5032 if ((addend
& 0x8000) != 0)
5035 /* Get a got entry representing requested hipage. */
5036 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5037 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5038 BFD_ASSERT (g
!= NULL
);
5040 assigned_gotno
= g
->assigned_gotno
;
5041 got_contents
= sgot
->contents
;
5042 hipage
= addend
& 0xffff0000;
5044 for (i
= MIPS_RESERVED_GOTNO
; i
< assigned_gotno
; i
++)
5046 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
5047 if (hipage
== (address
& 0xffff0000))
5051 if (i
== assigned_gotno
)
5053 if (assigned_gotno
>= g
->local_gotno
)
5055 (*_bfd_error_handler
)
5056 (_("more got entries are needed for hipage relocations"));
5057 bfd_set_error (bfd_error_bad_value
);
5061 bfd_put_32 (input_bfd
, hipage
, got_contents
+ assigned_gotno
* 4);
5062 ++g
->assigned_gotno
;
5065 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
5066 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
5067 contents
+ relhi
->r_offset
);
5072 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
5075 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
5077 Elf_Internal_Rela
*rel
;
5083 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5084 bfd_put_32 (input_bfd
,
5085 (insn
& 0xffff0000) | (offset
& 0xffff),
5086 contents
+ rel
->r_offset
);
5089 /* Returns the GOT section for ABFD. */
5092 mips_elf_got_section (abfd
)
5095 return bfd_get_section_by_name (abfd
, ".got");
5098 /* Returns the GOT information associated with the link indicated by
5099 INFO. If SGOTP is non-NULL, it is filled in with the GOT
5102 static struct mips_got_info
*
5103 mips_elf_got_info (abfd
, sgotp
)
5108 struct mips_got_info
*g
;
5110 sgot
= mips_elf_got_section (abfd
);
5111 BFD_ASSERT (sgot
!= NULL
);
5112 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5113 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5114 BFD_ASSERT (g
!= NULL
);
5121 /* Sign-extend VALUE, which has the indicated number of BITS. */
5124 mips_elf_sign_extend (value
, bits
)
5128 if (value
& (1 << (bits
- 1)))
5129 /* VALUE is negative. */
5130 value
|= ((bfd_vma
) - 1) << bits
;
5135 /* Return non-zero if the indicated VALUE has overflowed the maximum
5136 range expressable by a signed number with the indicated number of
5140 mips_elf_overflow_p (value
, bits
)
5144 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
5146 if (svalue
> (1 << (bits
- 1)) - 1)
5147 /* The value is too big. */
5149 else if (svalue
< -(1 << (bits
- 1)))
5150 /* The value is too small. */
5157 /* Calculate the %high function. */
5160 mips_elf_high (value
)
5163 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
5166 /* Calculate the %higher function. */
5169 mips_elf_higher (value
)
5173 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
5176 return (bfd_vma
) -1;
5180 /* Calculate the %highest function. */
5183 mips_elf_highest (value
)
5187 return ((value
+ (bfd_vma
) 0x800080008000) > 48) & 0xffff;
5190 return (bfd_vma
) -1;
5194 /* Returns the GOT index for the global symbol indicated by H. */
5197 mips_elf_global_got_index (abfd
, h
)
5199 struct elf_link_hash_entry
*h
;
5203 struct mips_got_info
*g
;
5205 g
= mips_elf_got_info (abfd
, &sgot
);
5207 /* Once we determine the global GOT entry with the lowest dynamic
5208 symbol table index, we must put all dynamic symbols with greater
5209 indices into the GOT. That makes it easy to calculate the GOT
5211 BFD_ASSERT (h
->dynindx
>= g
->global_gotsym
->dynindx
);
5212 index
= ((h
->dynindx
- g
->global_gotsym
->dynindx
+ g
->local_gotno
)
5213 * MIPS_ELF_GOT_SIZE (abfd
));
5214 BFD_ASSERT (index
< sgot
->_raw_size
);
5219 /* Returns the offset for the entry at the INDEXth position
5223 mips_elf_got_offset_from_index (dynobj
, output_bfd
, index
)
5230 char *error_message
;
5232 sgot
= mips_elf_got_section (dynobj
);
5233 gp
= _bfd_get_gp_value (output_bfd
);
5234 return (sgot
->output_section
->vma
+ sgot
->output_offset
+ index
-
5238 /* If H is a symbol that needs a global GOT entry, but has a dynamic
5239 symbol table index lower than any we've seen to date, record it for
5243 mips_elf_record_global_got_symbol (h
, info
, g
)
5244 struct elf_link_hash_entry
*h
;
5245 struct bfd_link_info
*info
;
5246 struct mips_got_info
*g
;
5248 /* A global symbol in the GOT must also be in the dynamic symbol
5250 if (h
->dynindx
== -1
5251 && !bfd_elf32_link_record_dynamic_symbol (info
, h
))
5254 /* If we've already marked this entry as need GOT space, we don't
5255 need to do it again. */
5256 if (h
->got
.offset
!= (bfd_vma
) - 1)
5259 /* By setting this to a value other than -1, we are indicating that
5260 there needs to be a GOT entry for H. */
5266 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
5267 the dynamic symbols. */
5269 struct mips_elf_hash_sort_data
5271 /* The symbol in the global GOT with the lowest dynamic symbol table
5273 struct elf_link_hash_entry
*low
;
5274 /* The least dynamic symbol table index corresponding to a symbol
5275 with a GOT entry. */
5276 long min_got_dynindx
;
5277 /* The greatest dynamic symbol table index not corresponding to a
5278 symbol without a GOT entry. */
5279 long max_non_got_dynindx
;
5282 /* If H needs a GOT entry, assign it the highest available dynamic
5283 index. Otherwise, assign it the lowest available dynamic
5287 mips_elf_sort_hash_table_f (h
, data
)
5288 struct mips_elf_link_hash_entry
*h
;
5291 struct mips_elf_hash_sort_data
*hsd
5292 = (struct mips_elf_hash_sort_data
*) data
;
5294 /* Symbols without dynamic symbol table entries aren't interesting
5296 if (h
->root
.dynindx
== -1)
5299 if (h
->root
.got
.offset
!= 0)
5300 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
5303 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
5304 hsd
->low
= (struct elf_link_hash_entry
*) h
;
5310 /* Sort the dynamic symbol table so that symbols that need GOT entries
5311 appear towards the end. This reduces the amount of GOT space
5315 mips_elf_sort_hash_table (info
)
5316 struct bfd_link_info
*info
;
5318 struct mips_elf_hash_sort_data hsd
;
5319 struct mips_got_info
*g
;
5322 dynobj
= elf_hash_table (info
)->dynobj
;
5325 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
;
5326 hsd
.max_non_got_dynindx
= 1;
5327 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
5328 elf_hash_table (info
)),
5329 mips_elf_sort_hash_table_f
,
5332 /* There shoud have been enough room in the symbol table to
5333 accomodate both the GOT and non-GOT symbols. */
5334 BFD_ASSERT (hsd
.min_got_dynindx
== hsd
.max_non_got_dynindx
);
5336 /* Now we know which dynamic symbol has the lowest dynamic symbol
5337 table index in the GOT. */
5338 g
= mips_elf_got_info (dynobj
, NULL
);
5339 g
->global_gotsym
= hsd
.low
;
5344 /* Create a local GOT entry for VALUE. Return the index of the entry,
5345 or -1 if it could not be created. */
5348 mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
)
5350 struct mips_got_info
*g
;
5354 if (g
->assigned_gotno
>= g
->local_gotno
)
5356 /* We didn't allocate enough space in the GOT. */
5357 (*_bfd_error_handler
)
5358 (_("not enough GOT space for local GOT entries"));
5359 bfd_set_error (bfd_error_bad_value
);
5360 return (bfd_vma
) -1;
5363 MIPS_ELF_PUT_WORD (abfd
, value
,
5365 + MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
));
5366 return MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
5369 /* Returns the GOT offset at which the indicated address can be found.
5370 If there is not yet a GOT entry for this value, create one. Returns
5371 -1 if no satisfactory GOT offset can be found. */
5374 mips_elf_local_got_index (abfd
, info
, value
)
5376 struct bfd_link_info
*info
;
5380 struct mips_got_info
*g
;
5383 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
5385 /* Look to see if we already have an appropriate entry. */
5386 for (entry
= (sgot
->contents
5387 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
5388 entry
!= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
5389 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
5391 bfd_vma address
= MIPS_ELF_GET_WORD (abfd
, entry
);
5392 if (address
== value
)
5393 return entry
- sgot
->contents
;
5396 return mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
5399 /* Find a GOT entry that is within 32KB of the VALUE. These entries
5400 are supposed to be placed at small offsets in the GOT, i.e.,
5401 within 32KB of GP. Return the index into the GOT for this page,
5402 and store the offset from this entry to the desired address in
5403 OFFSETP, if it is non-NULL. */
5406 mips_elf_got_page (abfd
, info
, value
, offsetp
)
5408 struct bfd_link_info
*info
;
5413 struct mips_got_info
*g
;
5415 bfd_byte
*last_entry
;
5419 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
5421 /* Look to see if we aleady have an appropriate entry. */
5422 last_entry
= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
5423 for (entry
= (sgot
->contents
5424 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
5425 entry
!= last_entry
;
5426 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
5428 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
5430 if (!mips_elf_overflow_p (value
- address
, 16))
5432 /* This entry will serve as the page pointer. We can add a
5433 16-bit number to it to get the actual address. */
5434 index
= entry
- sgot
->contents
;
5439 /* If we didn't have an appropriate entry, we create one now. */
5440 if (entry
== last_entry
)
5441 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
5445 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
5446 *offsetp
= value
- address
;
5452 /* Find a GOT entry whose higher-order 16 bits are the same as those
5453 for value. Return the index into the GOT for this entry. */
5456 mips_elf_got16_entry (abfd
, info
, value
)
5458 struct bfd_link_info
*info
;
5462 struct mips_got_info
*g
;
5464 bfd_byte
*last_entry
;
5468 value
&= 0xffff0000;
5469 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
5471 /* Look to see if we already have an appropriate entry. */
5472 last_entry
= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
5473 for (entry
= (sgot
->contents
5474 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
5475 entry
!= last_entry
;
5476 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
5478 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
5479 if (address
& 0xffff0000 == value
)
5481 /* This entry has the right high-order 16 bits. */
5482 index
= MIPS_ELF_GOT_SIZE (abfd
) * (entry
- sgot
->contents
);
5487 /* If we didn't have an appropriate entry, we create one now. */
5488 if (entry
== last_entry
)
5489 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
5494 /* Sets *ADDENDP to the addend for the first R_MIPS_LO16 relocation
5495 found, beginning with RELOCATION. RELEND is one-past-the-end of
5496 the relocation table. */
5499 mips_elf_next_lo16_addend (relocation
, relend
, addendp
)
5500 const Elf_Internal_Rela
*relocation
;
5501 const Elf_Internal_Rela
*relend
;
5504 /* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be
5505 immediately following. However, for the IRIX6 ABI, the next
5506 relocation may be a composed relocation consisting of several
5507 relocations for the same address. In that case, the R_MIPS_LO16
5508 relo!scation may occur as one of these. We permit a similar
5509 extension in general, as that is useful for GCC. */
5510 while (relocation
< relend
)
5512 if (ELF32_R_TYPE (relocation
->r_info
) == R_MIPS_LO16
)
5514 *addendp
= relocation
->r_addend
;
5521 /* We didn't find it. */
5525 /* Create a rel.dyn relocation for the dynamic linker to resolve. The
5526 relocatin is against the symbol with the dynamic symbol table index
5527 DYNINDX. REL is the original relocation, which is now being made
5531 mips_elf_create_dynamic_relocation (output_bfd
, info
, rel
, dynindx
,
5532 addend
, input_section
)
5534 struct bfd_link_info
*info
;
5535 const Elf_Internal_Rela
*rel
;
5538 asection
*input_section
;
5540 Elf_Internal_Rel outrel
;
5546 r_type
= ELF32_R_TYPE (rel
->r_info
);
5547 dynobj
= elf_hash_table (info
)->dynobj
;
5549 = bfd_get_section_by_name (dynobj
,
5550 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd
));
5551 BFD_ASSERT (sreloc
!= NULL
);
5555 /* The symbol for the relocation is the same as it was for the
5556 original relocation. */
5557 outrel
.r_info
= ELF32_R_INFO (dynindx
, R_MIPS_REL32
);
5559 /* The offset for the dynamic relocation is the same as for the
5560 original relocation, adjusted by the offset at which the original
5561 section is output. */
5562 if (elf_section_data (input_section
)->stab_info
== NULL
)
5563 outrel
.r_offset
= rel
->r_offset
;
5568 off
= (_bfd_stab_section_offset
5569 (output_bfd
, &elf_hash_table (info
)->stab_info
,
5571 &elf_section_data (input_section
)->stab_info
,
5573 if (off
== (bfd_vma
) -1)
5575 outrel
.r_offset
= off
;
5577 outrel
.r_offset
+= (input_section
->output_section
->vma
5578 + input_section
->output_offset
);
5580 /* If we've decided to skip this relocation, just output an emtpy
5583 memset (&outrel
, 0, sizeof (outrel
));
5585 if (ABI_64_P (output_bfd
))
5587 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
5588 (output_bfd
, &outrel
,
5590 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
5593 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
5594 (((Elf32_External_Rel
*)
5596 + sreloc
->reloc_count
));
5597 ++sreloc
->reloc_count
;
5599 /* Make sure the output section is writable. The dynamic linker
5600 will be writing to it. */
5601 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
5604 /* On IRIX5, make an entry of compact relocation info. */
5605 if (! skip
&& IRIX_COMPAT (output_bfd
) == ict_irix5
)
5607 asection
* scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5612 Elf32_crinfo cptrel
;
5614 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5615 cptrel
.vaddr
= (rel
->r_offset
5616 + input_section
->output_section
->vma
5617 + input_section
->output_offset
);
5618 if (r_type
== R_MIPS_REL32
)
5619 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5621 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5622 mips_elf_set_cr_dist2to (cptrel
, 0);
5623 cptrel
.konst
= addend
;
5625 cr
= (scpt
->contents
5626 + sizeof (Elf32_External_compact_rel
));
5627 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5628 ((Elf32_External_crinfo
*) cr
5629 + scpt
->reloc_count
));
5630 ++scpt
->reloc_count
;
5634 return sreloc
->reloc_count
- 1;
5637 /* Calculate the value produced by the RELOCATION (which comes from
5638 the INPUT_BFD). The ADDEND is the addend to use for this
5639 RELOCATION; RELOCATION->R_ADDEND is ignored.
5641 The result of the relocation calculation is stored in VALUEP.
5643 This function returns bfd_reloc_continue if the caller need take no
5644 further action regarding this relocation, bfd_reloc_notsupported if
5645 something goes dramatically wrong, bfd_reloc_overflow if an
5646 overflow occurs, and bfd_reloc_ok to indicate success. */
5648 static bfd_reloc_status_type
5649 mips_elf_calculate_relocation (abfd
,
5662 asection
*input_section
;
5663 struct bfd_link_info
*info
;
5664 const Elf_Internal_Rela
*relocation
;
5666 reloc_howto_type
*howto
;
5667 Elf_Internal_Sym
*local_syms
;
5668 asection
**local_sections
;
5672 /* The eventual value we will return. */
5674 /* The address of the symbol against which the relocation is
5677 /* The final GP value to be used for the relocatable, executable, or
5678 shared object file being produced. */
5679 bfd_vma gp
= (bfd_vma
) - 1;
5680 /* The place (section offset or address) of the storage unit being
5683 /* The value of GP used to create the relocatable object. */
5684 bfd_vma gp0
= (bfd_vma
) - 1;
5685 /* The offset into the global offset table at which the address of
5686 the relocation entry symbol, adjusted by the addend, resides
5687 during execution. */
5688 bfd_vma g
= (bfd_vma
) - 1;
5689 /* The section in which the symbol referenced by the relocation is
5691 asection
*sec
= NULL
;
5692 struct mips_elf_link_hash_entry
* h
= NULL
;
5693 /* True if the symbol referred to by this relocation is a local
5696 /* True if the symbol referred to by this relocation is "_gp_disp". */
5697 boolean gp_disp_p
= false;
5698 Elf_Internal_Shdr
*symtab_hdr
;
5700 unsigned long r_symndx
;
5702 /* True if overflow occurred during the calculation of the
5703 relocation value. */
5704 boolean overflowed_p
;
5706 /* Parse the relocation. */
5707 r_symndx
= ELF32_R_SYM (relocation
->r_info
);
5708 r_type
= ELF32_R_TYPE (relocation
->r_info
);
5709 p
= (input_section
->output_section
->vma
5710 + input_section
->output_offset
5711 + relocation
->r_offset
);
5713 /* Assume that there will be no overflow. */
5714 overflowed_p
= false;
5716 /* Figure out whether or not the symbol is local. */
5717 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5718 if (elf_bad_symtab (input_bfd
))
5720 /* The symbol table does not follow the rule that local symbols
5721 must come before globals. */
5723 local_p
= local_sections
[r_symndx
] != NULL
;
5727 extsymoff
= symtab_hdr
->sh_info
;
5728 local_p
= r_symndx
< extsymoff
;
5731 /* Figure out the value of the symbol. */
5734 Elf_Internal_Sym
*sym
;
5736 sym
= local_syms
+ r_symndx
;
5737 sec
= local_sections
[r_symndx
];
5739 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
5740 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5741 symbol
+= sym
->st_value
;
5743 /* MIPS16 text labels should be treated as odd. */
5744 if (sym
->st_other
== STO_MIPS16
)
5747 /* Record the name of this symbol, for our caller. */
5748 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
5749 symtab_hdr
->sh_link
,
5752 *namep
= bfd_section_name (input_bfd
, sec
);
5756 /* For global symbols we look up the symbol in the hash-table. */
5757 h
= ((struct mips_elf_link_hash_entry
*)
5758 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
5759 /* Find the real hash-table entry for this symbol. */
5760 while (h
->root
.type
== bfd_link_hash_indirect
5761 || h
->root
.type
== bfd_link_hash_warning
)
5762 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
5764 /* Record the name of this symbol, for our caller. */
5765 *namep
= h
->root
.root
.root
.string
;
5767 /* See if this is the special _gp_disp symbol. Note that such a
5768 symbol must always be a global symbol. */
5769 if (strcmp (h
->root
.root
.root
.string
, "_gp_disp") == 0)
5771 /* Relocations against _gp_disp are permitted only with
5772 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
5773 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_LO16
)
5774 return bfd_reloc_notsupported
;
5779 /* If this symbol is defined, calculate its address. */
5780 if ((h
->root
.root
.type
== bfd_link_hash_defined
5781 || h
->root
.root
.type
== bfd_link_hash_defweak
)
5782 && h
->root
.root
.u
.def
.section
)
5784 sec
= h
->root
.root
.u
.def
.section
;
5785 if (sec
->output_section
)
5786 symbol
= (h
->root
.root
.u
.def
.value
5787 + sec
->output_section
->vma
5788 + sec
->output_offset
);
5790 symbol
= h
->root
.root
.u
.def
.value
;
5794 (*info
->callbacks
->undefined_symbol
)
5795 (info
, h
->root
.root
.root
.string
, input_bfd
,
5796 input_section
, relocation
->r_offset
);
5797 return bfd_reloc_undefined
;
5801 /* If we haven't already determined the GOT offset, or the GP value,
5802 and we're going to need it, get it now. */
5806 case R_MIPS_GOT_DISP
:
5807 case R_MIPS_GOT_HI16
:
5808 case R_MIPS_CALL_HI16
:
5809 case R_MIPS_GOT_LO16
:
5810 case R_MIPS_CALL_LO16
:
5811 /* Find the index into the GOT where this value is located. */
5814 BFD_ASSERT (addend
== 0);
5815 g
= mips_elf_global_got_index
5816 (elf_hash_table (info
)->dynobj
,
5817 (struct elf_link_hash_entry
*) h
);
5821 g
= mips_elf_local_got_index (abfd
, info
, symbol
+ addend
);
5822 if (g
== (bfd_vma
) -1)
5826 /* Convert GOT indices to actual offsets. */
5827 g
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
5833 case R_MIPS_GPREL16
:
5834 case R_MIPS_GPREL32
:
5835 gp0
= _bfd_get_gp_value (input_bfd
);
5836 gp
= _bfd_get_gp_value (abfd
);
5843 /* Figure out what kind of relocation is being performed. */
5847 return bfd_reloc_continue
;
5850 value
= symbol
+ mips_elf_sign_extend (addend
, 16);
5851 overflowed_p
= mips_elf_overflow_p (value
, 16);
5856 /* If we're creating a shared library, or this relocation is
5857 against a symbol in a shared library, then we can't know
5858 where the symbol will end up. So, we create a relocation
5859 record in the output, and leave the job up to the dynamic
5861 if (info
->shared
|| !sec
->output_section
)
5863 unsigned int reloc_index
;
5865 BFD_ASSERT (h
!= NULL
);
5867 = mips_elf_create_dynamic_relocation (abfd
,
5873 if (h
->min_dyn_reloc_index
== 0
5874 || reloc_index
< h
->min_dyn_reloc_index
)
5875 h
->min_dyn_reloc_index
= reloc_index
;
5876 value
= symbol
+ addend
;
5880 if (r_type
== R_MIPS_32
)
5881 value
= symbol
+ addend
;
5885 value
&= howto
->dst_mask
;
5890 value
= (((addend
<< 2) | (p
& 0xf0000000)) + symbol
) >> 2;
5892 value
= (mips_elf_sign_extend (addend
<< 2, 28) + symbol
) >> 2;
5893 value
&= howto
->dst_mask
;
5899 value
= mips_elf_high (addend
+ symbol
);
5900 value
&= howto
->dst_mask
;
5904 value
= mips_elf_high (addend
+ gp
- p
);
5905 overflowed_p
= mips_elf_overflow_p (value
, 16);
5911 value
= (symbol
+ addend
) & howto
->dst_mask
;
5914 value
= addend
+ gp
- p
+ 4;
5915 overflowed_p
= mips_elf_overflow_p (value
, 16);
5919 case R_MIPS_LITERAL
:
5920 /* Because we don't merge literal sections, we can handle this
5921 just like R_MIPS_GPREL16. In the long run, we should merge
5922 shared literals, and then we will need to additional work
5927 case R_MIPS_GPREL16
:
5929 value
= mips_elf_sign_extend (addend
, 16) + symbol
+ gp0
- gp
;
5931 value
= mips_elf_sign_extend (addend
, 16) + symbol
- gp
;
5932 overflowed_p
= mips_elf_overflow_p (value
, 16);
5938 value
= mips_elf_got16_entry (abfd
, info
, symbol
+ addend
);
5939 if (value
== (bfd_vma
) -1)
5942 = mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
5945 overflowed_p
= mips_elf_overflow_p (value
, 16);
5952 case R_MIPS_GOT_DISP
:
5954 overflowed_p
= mips_elf_overflow_p (value
, 16);
5957 case R_MIPS_GPREL32
:
5958 value
= (addend
+ symbol
+ gp0
- gp
) & howto
->dst_mask
;
5962 value
= mips_elf_sign_extend (addend
, 16) + symbol
- p
;
5963 overflowed_p
= mips_elf_overflow_p (value
, 16);
5966 case R_MIPS_GOT_HI16
:
5967 case R_MIPS_CALL_HI16
:
5968 /* We're allowed to handle these two relocations identically.
5969 The dynamic linker is allowed to handle the CALL relocations
5970 differently by creating a lazy evaluation stub. */
5972 value
= mips_elf_high (value
);
5973 value
&= howto
->dst_mask
;
5976 case R_MIPS_GOT_LO16
:
5977 case R_MIPS_CALL_LO16
:
5978 value
= g
& howto
->dst_mask
;
5982 value
= (symbol
+ addend
) & howto
->dst_mask
;
5985 case R_MIPS_GOT_PAGE
:
5986 value
= mips_elf_got_page (abfd
, info
, symbol
+ addend
, NULL
);
5987 if (value
== (bfd_vma
) -1)
5989 value
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
5992 overflowed_p
= mips_elf_overflow_p (value
, 16);
5995 case R_MIPS_GOT_OFST
:
5996 mips_elf_got_page (abfd
, info
, symbol
+ addend
, &value
);
5997 overflowed_p
= mips_elf_overflow_p (value
, 16);
6001 value
= symbol
- addend
;
6002 value
&= howto
->dst_mask
;
6006 value
= mips_elf_higher (addend
+ symbol
);
6007 value
&= howto
->dst_mask
;
6010 case R_MIPS_HIGHEST
:
6011 value
= mips_elf_highest (addend
+ symbol
);
6012 value
&= howto
->dst_mask
;
6015 case R_MIPS_SCN_DISP
:
6016 value
= symbol
+ addend
- sec
->output_offset
;
6017 value
&= howto
->dst_mask
;
6022 /* Both of these may be ignored. R_MIPS_JALR is an optimization
6023 hint; we could improve performance by honoring that hint. */
6024 return bfd_reloc_continue
;
6026 case R_MIPS_GNU_VTINHERIT
:
6027 case R_MIPS_GNU_VTENTRY
:
6028 /* We don't do anything with these at present. */
6029 return bfd_reloc_continue
;
6032 case R_MIPS16_GPREL
:
6033 /* These relocations, used for MIPS16, are not clearly
6034 documented anywhere. What do they do? */
6035 return bfd_reloc_notsupported
;
6038 /* An unrecognized relocation type. */
6039 return bfd_reloc_notsupported
;
6042 /* Store the VALUE for our caller. */
6044 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
6047 /* Obtain the field relocated by RELOCATION. */
6050 mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
)
6051 reloc_howto_type
*howto
;
6052 const Elf_Internal_Rela
*relocation
;
6057 bfd_byte
*location
= contents
+ relocation
->r_offset
;
6059 switch (bfd_get_reloc_size (howto
))
6066 x
= bfd_get_8 (input_bfd
, location
);
6070 x
= bfd_get_16 (input_bfd
, location
);
6074 x
= bfd_get_32 (input_bfd
, location
);
6079 x
= bfd_get_64 (input_bfd
, location
);
6093 /* It has been determined that the result of the RELOCATION is the
6094 VALUE. Use HOWTO to place VALUE into the output file at the
6095 appropriate position. The SECTION is the section to which the
6098 Returns false if anything goes wrong. */
6101 mips_elf_perform_relocation (howto
, relocation
, value
, input_bfd
, contents
)
6102 reloc_howto_type
*howto
;
6103 const Elf_Internal_Rela
*relocation
;
6109 bfd_byte
*location
= contents
+ relocation
->r_offset
;
6111 /* Obtain the current value. */
6112 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
6114 /* Clear the field we are setting. */
6115 x
&= ~howto
->dst_mask
;
6117 /* Set the field. */
6118 x
|= (value
& howto
->dst_mask
);
6120 /* Put the value into the output. */
6121 switch (bfd_get_reloc_size (howto
))
6128 bfd_put_8 (input_bfd
, x
, location
);
6132 bfd_put_16 (input_bfd
, x
, location
);
6136 bfd_put_32 (input_bfd
, x
, location
);
6141 bfd_put_64 (input_bfd
, x
, location
);
6153 /* Relocate a MIPS ELF section. */
6156 _bfd_mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
6157 contents
, relocs
, local_syms
, local_sections
)
6159 struct bfd_link_info
*info
;
6161 asection
*input_section
;
6163 Elf_Internal_Rela
*relocs
;
6164 Elf_Internal_Sym
*local_syms
;
6165 asection
**local_sections
;
6167 const Elf_Internal_Rela
*rel
;
6168 const Elf_Internal_Rela
*relend
;
6170 bfd_vma last_hi16_addend
;
6171 boolean next_relocation_for_same_address_p
= false;
6172 boolean use_saved_addend_p
= false;
6173 boolean last_hi16_addend_valid_p
= false;
6174 struct elf_backend_data
*bed
;
6176 bed
= get_elf_backend_data (output_bfd
);
6177 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
6178 for (rel
= relocs
; rel
< relend
; ++rel
)
6183 reloc_howto_type
*howto
;
6185 /* Find the relocation howto for this relocation. */
6186 howto
= elf_mips_howto_table
+ ELF32_R_TYPE (rel
->r_info
);
6188 if (!use_saved_addend_p
)
6190 Elf_Internal_Shdr
*rel_hdr
;
6192 /* If these relocations were originally of the REL variety,
6193 we must pull the addend out of the field that will be
6194 relocated. Otherwise, we simply use the contents of the
6195 RELA relocation. To determine which flavor or relocation
6196 this is, we depend on the fact that the INPUT_SECTION's
6197 REL_HDR is read before its REL_HDR2. */
6198 rel_hdr
= &elf_section_data (input_section
)->rel_hdr
;
6200 >= (rel_hdr
->sh_size
/ rel_hdr
->sh_entsize
6201 * bed
->s
->int_rels_per_ext_rel
))
6202 rel_hdr
= elf_section_data (input_section
)->rel_hdr2
;
6203 if (rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (input_bfd
))
6205 int r_type
= ELF32_R_TYPE (rel
->r_info
);
6207 addend
= mips_elf_obtain_contents (howto
,
6211 addend
&= howto
->src_mask
;
6213 /* For some kinds of relocations, the ADDEND is a
6214 combination of the addend stored in two different
6216 if (r_type
== R_MIPS_HI16
|| r_type
== R_MIPS_GOT16
)
6218 /* Scan ahead to find a matching R_MIPS_LO16
6222 if (!mips_elf_next_lo16_addend (rel
, relend
, &l
))
6225 /* Save the high-order bit for later. When we
6226 encounter the R_MIPS_LO16 relocation we will need
6229 last_hi16_addend
= addend
;
6230 last_hi16_addend_valid_p
= true;
6232 /* Compute the combined addend. */
6235 else if (r_type
== R_MIPS_LO16
)
6237 /* Used the saved HI16 addend. */
6238 if (!last_hi16_addend_valid_p
)
6240 addend
|= last_hi16_addend
;
6244 addend
= rel
->r_addend
;
6247 /* In the N32 and 64-bit ABIs there may be multiple consecutive
6248 relocations for the same offset. In that case we are
6249 supposed to treat the output of each relocation as the addend
6251 if (rel
+ 1 < relend
6252 && rel
->r_offset
== rel
[1].r_offset
6253 && ELF32_R_TYPE (rel
[1].r_info
) != R_MIPS_NONE
)
6254 use_saved_addend_p
= true;
6256 use_saved_addend_p
= false;
6258 /* Figure out what value we are supposed to relocate. */
6259 switch (mips_elf_calculate_relocation (output_bfd
,
6271 case bfd_reloc_continue
:
6272 /* There's nothing to do. */
6275 case bfd_reloc_undefined
:
6278 case bfd_reloc_notsupported
:
6282 case bfd_reloc_overflow
:
6283 if (use_saved_addend_p
)
6284 /* Ignore overflow until we reach the last relocation for
6285 a given location. */
6288 || ! ((*info
->callbacks
->reloc_overflow
)
6289 (info
, name
, howto
->name
, (bfd_vma
) 0,
6290 input_bfd
, input_section
, rel
->r_offset
)))
6303 /* If we've got another relocation for the address, keep going
6304 until we reach the last one. */
6305 if (use_saved_addend_p
)
6311 /* Actually perform the relocation. */
6312 mips_elf_perform_relocation (howto
, rel
, value
, input_bfd
,
6319 /* This hook function is called before the linker writes out a global
6320 symbol. We mark symbols as small common if appropriate. This is
6321 also where we undo the increment of the value for a mips16 symbol. */
6325 _bfd_mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
6327 struct bfd_link_info
*info
;
6329 Elf_Internal_Sym
*sym
;
6330 asection
*input_sec
;
6332 /* If we see a common symbol, which implies a relocatable link, then
6333 if a symbol was small common in an input file, mark it as small
6334 common in the output file. */
6335 if (sym
->st_shndx
== SHN_COMMON
6336 && strcmp (input_sec
->name
, ".scommon") == 0)
6337 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
6339 if (sym
->st_other
== STO_MIPS16
6340 && (sym
->st_value
& 1) != 0)
6346 /* Functions for the dynamic linker. */
6348 /* The name of the dynamic interpreter. This is put in the .interp
6351 #define ELF_DYNAMIC_INTERPRETER(abfd) \
6352 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
6353 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
6354 : "/usr/lib/libc.so.1")
6356 /* Create dynamic sections when linking against a dynamic object. */
6359 _bfd_mips_elf_create_dynamic_sections (abfd
, info
)
6361 struct bfd_link_info
*info
;
6363 struct elf_link_hash_entry
*h
;
6365 register asection
*s
;
6366 const char * const *namep
;
6368 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6369 | SEC_LINKER_CREATED
| SEC_READONLY
);
6371 /* Mips ABI requests the .dynamic section to be read only. */
6372 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6375 if (! bfd_set_section_flags (abfd
, s
, flags
))
6379 /* We need to create .got section. */
6380 if (! mips_elf_create_got_section (abfd
, info
))
6383 /* Create the .msym section on IRIX6. It is used by the dynamic
6384 linker to speed up dynamic relocations, and to avoid computing
6385 the ELF hash for symbols. */
6386 if (IRIX_COMPAT (abfd
) == ict_irix6
6387 && !mips_elf_create_msym_section (abfd
))
6390 /* Create .stub section. */
6391 if (bfd_get_section_by_name (abfd
,
6392 MIPS_ELF_STUB_SECTION_NAME (abfd
)) == NULL
)
6394 s
= bfd_make_section (abfd
, MIPS_ELF_STUB_SECTION_NAME (abfd
));
6396 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_CODE
)
6397 || ! bfd_set_section_alignment (abfd
, s
,
6398 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6402 if (IRIX_COMPAT (abfd
) == ict_irix5
6404 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
6406 s
= bfd_make_section (abfd
, ".rld_map");
6408 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
6409 || ! bfd_set_section_alignment (abfd
, s
,
6410 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6414 /* On IRIX5, we adjust add some additional symbols and change the
6415 alignments of several sections. There is no ABI documentation
6416 indicating that this is necessary on IRIX6, nor any evidence that
6417 the linker takes such action. */
6418 if (IRIX_COMPAT (abfd
) == ict_irix5
)
6420 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
6423 if (! (_bfd_generic_link_add_one_symbol
6424 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
6425 (bfd_vma
) 0, (const char *) NULL
, false,
6426 get_elf_backend_data (abfd
)->collect
,
6427 (struct bfd_link_hash_entry
**) &h
)))
6429 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6430 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6431 h
->type
= STT_SECTION
;
6433 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6437 /* We need to create a .compact_rel section. */
6438 if (! mips_elf_create_compact_rel_section (abfd
, info
))
6441 /* Change aligments of some sections. */
6442 s
= bfd_get_section_by_name (abfd
, ".hash");
6444 bfd_set_section_alignment (abfd
, s
, 4);
6445 s
= bfd_get_section_by_name (abfd
, ".dynsym");
6447 bfd_set_section_alignment (abfd
, s
, 4);
6448 s
= bfd_get_section_by_name (abfd
, ".dynstr");
6450 bfd_set_section_alignment (abfd
, s
, 4);
6451 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6453 bfd_set_section_alignment (abfd
, s
, 4);
6454 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6456 bfd_set_section_alignment (abfd
, s
, 4);
6462 if (! (_bfd_generic_link_add_one_symbol
6463 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
6464 (bfd_vma
) 0, (const char *) NULL
, false,
6465 get_elf_backend_data (abfd
)->collect
,
6466 (struct bfd_link_hash_entry
**) &h
)))
6468 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6469 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6470 h
->type
= STT_SECTION
;
6472 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6475 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
6477 /* __rld_map is a four byte word located in the .data section
6478 and is filled in by the rtld to contain a pointer to
6479 the _r_debug structure. Its symbol value will be set in
6480 mips_elf_finish_dynamic_symbol. */
6481 s
= bfd_get_section_by_name (abfd
, ".rld_map");
6482 BFD_ASSERT (s
!= NULL
);
6485 if (! (_bfd_generic_link_add_one_symbol
6486 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
6487 (bfd_vma
) 0, (const char *) NULL
, false,
6488 get_elf_backend_data (abfd
)->collect
,
6489 (struct bfd_link_hash_entry
**) &h
)))
6491 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6492 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6493 h
->type
= STT_OBJECT
;
6495 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6503 /* Create the .compact_rel section. */
6506 mips_elf_create_compact_rel_section (abfd
, info
)
6508 struct bfd_link_info
*info
;
6511 register asection
*s
;
6513 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
6515 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
6518 s
= bfd_make_section (abfd
, ".compact_rel");
6520 || ! bfd_set_section_flags (abfd
, s
, flags
)
6521 || ! bfd_set_section_alignment (abfd
, s
,
6522 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6525 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
6531 /* Create the .got section to hold the global offset table. */
6534 mips_elf_create_got_section (abfd
, info
)
6536 struct bfd_link_info
*info
;
6539 register asection
*s
;
6540 struct elf_link_hash_entry
*h
;
6541 struct mips_got_info
*g
;
6543 /* This function may be called more than once. */
6544 if (mips_elf_got_section (abfd
))
6547 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6548 | SEC_LINKER_CREATED
);
6550 s
= bfd_make_section (abfd
, ".got");
6552 || ! bfd_set_section_flags (abfd
, s
, flags
)
6553 || ! bfd_set_section_alignment (abfd
, s
, 4))
6556 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
6557 linker script because we don't want to define the symbol if we
6558 are not creating a global offset table. */
6560 if (! (_bfd_generic_link_add_one_symbol
6561 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
6562 (bfd_vma
) 0, (const char *) NULL
, false,
6563 get_elf_backend_data (abfd
)->collect
,
6564 (struct bfd_link_hash_entry
**) &h
)))
6566 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6567 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6568 h
->type
= STT_OBJECT
;
6571 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6574 /* The first several global offset table entries are reserved. */
6575 s
->_raw_size
= MIPS_RESERVED_GOTNO
* MIPS_ELF_GOT_SIZE (abfd
);
6577 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
6578 sizeof (struct mips_got_info
));
6581 g
->global_gotsym
= NULL
;
6582 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
6583 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
6584 if (elf_section_data (s
) == NULL
)
6587 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
6588 if (elf_section_data (s
) == NULL
)
6591 elf_section_data (s
)->tdata
= (PTR
) g
;
6592 elf_section_data (s
)->this_hdr
.sh_flags
6593 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
6598 /* Returns the .msym section for ABFD, creating it if it does not
6599 already exist. Returns NULL to indicate error. */
6602 mips_elf_create_msym_section (abfd
)
6607 s
= bfd_get_section_by_name (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
6610 s
= bfd_make_section (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
6612 || !bfd_set_section_flags (abfd
, s
,
6616 | SEC_LINKER_CREATED
6618 || !bfd_set_section_alignment (abfd
, s
,
6619 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6626 /* Add room for N relocations to the .rel.dyn section in ABFD. */
6629 mips_elf_allocate_dynamic_relocations (abfd
, n
)
6635 s
= bfd_get_section_by_name (abfd
, MIPS_ELF_REL_DYN_SECTION_NAME (abfd
));
6636 BFD_ASSERT (s
!= NULL
);
6638 if (s
->_raw_size
== 0)
6640 /* Make room for a null element. */
6641 s
->_raw_size
+= MIPS_ELF_REL_SIZE (abfd
);
6644 s
->_raw_size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
6647 /* Look through the relocs for a section during the first phase, and
6648 allocate space in the global offset table. */
6651 _bfd_mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
6653 struct bfd_link_info
*info
;
6655 const Elf_Internal_Rela
*relocs
;
6659 Elf_Internal_Shdr
*symtab_hdr
;
6660 struct elf_link_hash_entry
**sym_hashes
;
6661 struct mips_got_info
*g
;
6663 const Elf_Internal_Rela
*rel
;
6664 const Elf_Internal_Rela
*rel_end
;
6667 struct elf_backend_data
*bed
;
6669 if (info
->relocateable
)
6672 dynobj
= elf_hash_table (info
)->dynobj
;
6673 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6674 sym_hashes
= elf_sym_hashes (abfd
);
6675 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
6677 /* Check for the mips16 stub sections. */
6679 name
= bfd_get_section_name (abfd
, sec
);
6680 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
6682 unsigned long r_symndx
;
6684 /* Look at the relocation information to figure out which symbol
6687 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6689 if (r_symndx
< extsymoff
6690 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6694 /* This stub is for a local symbol. This stub will only be
6695 needed if there is some relocation in this BFD, other
6696 than a 16 bit function call, which refers to this symbol. */
6697 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6699 Elf_Internal_Rela
*sec_relocs
;
6700 const Elf_Internal_Rela
*r
, *rend
;
6702 /* We can ignore stub sections when looking for relocs. */
6703 if ((o
->flags
& SEC_RELOC
) == 0
6704 || o
->reloc_count
== 0
6705 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
6706 sizeof FN_STUB
- 1) == 0
6707 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
6708 sizeof CALL_STUB
- 1) == 0
6709 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
6710 sizeof CALL_FP_STUB
- 1) == 0)
6713 sec_relocs
= (_bfd_elf32_link_read_relocs
6714 (abfd
, o
, (PTR
) NULL
,
6715 (Elf_Internal_Rela
*) NULL
,
6716 info
->keep_memory
));
6717 if (sec_relocs
== NULL
)
6720 rend
= sec_relocs
+ o
->reloc_count
;
6721 for (r
= sec_relocs
; r
< rend
; r
++)
6722 if (ELF32_R_SYM (r
->r_info
) == r_symndx
6723 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
6726 if (! info
->keep_memory
)
6735 /* There is no non-call reloc for this stub, so we do
6736 not need it. Since this function is called before
6737 the linker maps input sections to output sections, we
6738 can easily discard it by setting the SEC_EXCLUDE
6740 sec
->flags
|= SEC_EXCLUDE
;
6744 /* Record this stub in an array of local symbol stubs for
6746 if (elf_tdata (abfd
)->local_stubs
== NULL
)
6748 unsigned long symcount
;
6751 if (elf_bad_symtab (abfd
))
6752 symcount
= symtab_hdr
->sh_size
/ symtab_hdr
->sh_entsize
;
6754 symcount
= symtab_hdr
->sh_info
;
6755 n
= (asection
**) bfd_zalloc (abfd
,
6756 symcount
* sizeof (asection
*));
6759 elf_tdata (abfd
)->local_stubs
= n
;
6762 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
6764 /* We don't need to set mips16_stubs_seen in this case.
6765 That flag is used to see whether we need to look through
6766 the global symbol table for stubs. We don't need to set
6767 it here, because we just have a local stub. */
6771 struct mips_elf_link_hash_entry
*h
;
6773 h
= ((struct mips_elf_link_hash_entry
*)
6774 sym_hashes
[r_symndx
- extsymoff
]);
6776 /* H is the symbol this stub is for. */
6779 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6782 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
6783 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6785 unsigned long r_symndx
;
6786 struct mips_elf_link_hash_entry
*h
;
6789 /* Look at the relocation information to figure out which symbol
6792 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6794 if (r_symndx
< extsymoff
6795 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6797 /* This stub was actually built for a static symbol defined
6798 in the same file. We assume that all static symbols in
6799 mips16 code are themselves mips16, so we can simply
6800 discard this stub. Since this function is called before
6801 the linker maps input sections to output sections, we can
6802 easily discard it by setting the SEC_EXCLUDE flag. */
6803 sec
->flags
|= SEC_EXCLUDE
;
6807 h
= ((struct mips_elf_link_hash_entry
*)
6808 sym_hashes
[r_symndx
- extsymoff
]);
6810 /* H is the symbol this stub is for. */
6812 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6813 loc
= &h
->call_fp_stub
;
6815 loc
= &h
->call_stub
;
6817 /* If we already have an appropriate stub for this function, we
6818 don't need another one, so we can discard this one. Since
6819 this function is called before the linker maps input sections
6820 to output sections, we can easily discard it by setting the
6821 SEC_EXCLUDE flag. We can also discard this section if we
6822 happen to already know that this is a mips16 function; it is
6823 not necessary to check this here, as it is checked later, but
6824 it is slightly faster to check now. */
6825 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
6827 sec
->flags
|= SEC_EXCLUDE
;
6832 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6842 sgot
= mips_elf_got_section (dynobj
);
6847 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6848 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6849 BFD_ASSERT (g
!= NULL
);
6854 bed
= get_elf_backend_data (abfd
);
6855 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
6856 for (rel
= relocs
; rel
< rel_end
; ++rel
)
6858 unsigned long r_symndx
;
6860 struct elf_link_hash_entry
*h
;
6862 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6863 r_type
= ELF32_R_TYPE (rel
->r_info
);
6865 if (r_symndx
< extsymoff
)
6869 h
= sym_hashes
[r_symndx
- extsymoff
];
6871 /* This may be an indirect symbol created because of a version. */
6874 while (h
->root
.type
== bfd_link_hash_indirect
)
6875 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6879 /* Some relocs require a global offset table. */
6880 if (dynobj
== NULL
|| sgot
== NULL
)
6886 case R_MIPS_CALL_HI16
:
6887 case R_MIPS_CALL_LO16
:
6888 case R_MIPS_GOT_HI16
:
6889 case R_MIPS_GOT_LO16
:
6891 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6892 if (! mips_elf_create_got_section (dynobj
, info
))
6894 g
= mips_elf_got_info (dynobj
, &sgot
);
6900 && (info
->shared
|| h
!= NULL
)
6901 && (sec
->flags
& SEC_ALLOC
) != 0)
6902 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6910 if (!h
&& (r_type
== R_MIPS_CALL_LO16
6911 || r_type
== R_MIPS_GOT_LO16
6912 || r_type
== R_MIPS_GOT_DISP
))
6914 /* We may need a local GOT entry for this relocation. We
6915 don't count R_MIPS_HI16 or R_MIPS_GOT16 relocations
6916 because they are always followed by a R_MIPS_LO16
6917 relocation for the value. We don't R_MIPS_GOT_PAGE
6918 because we can estimate the maximum number of pages
6919 needed by looking at the size of the segment.
6921 This estimation is very conservative since we can merge
6922 duplicate entries in the GOT. In order to be less
6923 conservative, we could actually build the GOT here,
6924 rather than in relocate_section. */
6926 sgot
->_raw_size
+= 4;
6934 (*_bfd_error_handler
)
6935 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
6936 bfd_get_filename (abfd
), (unsigned long) rel
->r_offset
);
6937 bfd_set_error (bfd_error_bad_value
);
6942 case R_MIPS_CALL_HI16
:
6943 case R_MIPS_CALL_LO16
:
6944 /* This symbol requires a global offset table entry. */
6945 if (!mips_elf_record_global_got_symbol (h
, info
, g
))
6948 /* We need a stub, not a plt entry for the undefined
6949 function. But we record it as if it needs plt. See
6950 elf_adjust_dynamic_symbol in elflink.h. */
6951 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6957 case R_MIPS_GOT_HI16
:
6958 case R_MIPS_GOT_LO16
:
6959 case R_MIPS_GOT_DISP
:
6960 /* This symbol requires a global offset table entry. */
6961 if (h
&& !mips_elf_record_global_got_symbol (h
, info
, g
))
6967 if ((info
->shared
|| h
!= NULL
)
6968 && (sec
->flags
& SEC_ALLOC
) != 0)
6972 const char *name
= MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
);
6974 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6977 sreloc
= bfd_make_section (dynobj
, name
);
6979 || ! bfd_set_section_flags (dynobj
, sreloc
,
6984 | SEC_LINKER_CREATED
6986 || ! bfd_set_section_alignment (dynobj
, sreloc
,
6992 /* When creating a shared object, we must copy these
6993 reloc types into the output file as R_MIPS_REL32
6994 relocs. We make room for this reloc in the
6995 .rel.dyn reloc section. */
6996 mips_elf_allocate_dynamic_relocations (dynobj
, 1);
6999 struct mips_elf_link_hash_entry
*hmips
;
7001 /* We only need to copy this reloc if the symbol is
7002 defined in a dynamic object. */
7003 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7004 ++hmips
->mips_32_relocs
;
7007 /* Even though we don't directly need a GOT entry for
7008 this symbol, a symbol must have a dynamic symbol
7009 table index greater that DT_GOTSYM if there are
7010 dynamic relocations against it. */
7011 if (!mips_elf_record_global_got_symbol (h
, info
, g
))
7015 if (SGI_COMPAT (dynobj
))
7016 mips_elf_hash_table (info
)->compact_rel_size
+=
7017 sizeof (Elf32_External_crinfo
);
7021 case R_MIPS_GPREL16
:
7022 case R_MIPS_LITERAL
:
7023 case R_MIPS_GPREL32
:
7024 if (SGI_COMPAT (dynobj
))
7025 mips_elf_hash_table (info
)->compact_rel_size
+=
7026 sizeof (Elf32_External_crinfo
);
7029 /* This relocation describes the C++ object vtable hierarchy.
7030 Reconstruct it for later use during GC. */
7031 case R_MIPS_GNU_VTINHERIT
:
7032 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
7036 /* This relocation describes which C++ vtable entries are actually
7037 used. Record for later use during GC. */
7038 case R_MIPS_GNU_VTENTRY
:
7039 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
7047 /* If this reloc is not a 16 bit call, and it has a global
7048 symbol, then we will need the fn_stub if there is one.
7049 References from a stub section do not count. */
7051 && r_type
!= R_MIPS16_26
7052 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
7053 sizeof FN_STUB
- 1) != 0
7054 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
7055 sizeof CALL_STUB
- 1) != 0
7056 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
7057 sizeof CALL_FP_STUB
- 1) != 0)
7059 struct mips_elf_link_hash_entry
*mh
;
7061 mh
= (struct mips_elf_link_hash_entry
*) h
;
7062 mh
->need_fn_stub
= true;
7069 /* Return the section that should be marked against GC for a given
7073 _bfd_mips_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
7075 struct bfd_link_info
*info
;
7076 Elf_Internal_Rela
*rel
;
7077 struct elf_link_hash_entry
*h
;
7078 Elf_Internal_Sym
*sym
;
7080 /* ??? Do mips16 stub sections need to be handled special? */
7084 switch (ELF32_R_TYPE (rel
->r_info
))
7086 case R_MIPS_GNU_VTINHERIT
:
7087 case R_MIPS_GNU_VTENTRY
:
7091 switch (h
->root
.type
)
7093 case bfd_link_hash_defined
:
7094 case bfd_link_hash_defweak
:
7095 return h
->root
.u
.def
.section
;
7097 case bfd_link_hash_common
:
7098 return h
->root
.u
.c
.p
->section
;
7107 if (!(elf_bad_symtab (abfd
)
7108 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
7109 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
7110 && sym
->st_shndx
!= SHN_COMMON
))
7112 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
7119 /* Update the got entry reference counts for the section being removed. */
7122 _bfd_mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
7124 struct bfd_link_info
*info
;
7126 const Elf_Internal_Rela
*relocs
;
7129 Elf_Internal_Shdr
*symtab_hdr
;
7130 struct elf_link_hash_entry
**sym_hashes
;
7131 bfd_signed_vma
*local_got_refcounts
;
7132 const Elf_Internal_Rela
*rel
, *relend
;
7133 unsigned long r_symndx
;
7134 struct elf_link_hash_entry
*h
;
7136 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7137 sym_hashes
= elf_sym_hashes (abfd
);
7138 local_got_refcounts
= elf_local_got_refcounts (abfd
);
7140 relend
= relocs
+ sec
->reloc_count
;
7141 for (rel
= relocs
; rel
< relend
; rel
++)
7142 switch (ELF32_R_TYPE (rel
->r_info
))
7146 case R_MIPS_CALL_HI16
:
7147 case R_MIPS_CALL_LO16
:
7148 case R_MIPS_GOT_HI16
:
7149 case R_MIPS_GOT_LO16
:
7150 /* ??? It would seem that the existing MIPS code does no sort
7151 of reference counting or whatnot on its GOT and PLT entries,
7152 so it is not possible to garbage collect them at this time. */
7164 /* Adjust a symbol defined by a dynamic object and referenced by a
7165 regular object. The current definition is in some section of the
7166 dynamic object, but we're not including those sections. We have to
7167 change the definition to something the rest of the link can
7171 _bfd_mips_elf_adjust_dynamic_symbol (info
, h
)
7172 struct bfd_link_info
*info
;
7173 struct elf_link_hash_entry
*h
;
7176 struct mips_elf_link_hash_entry
*hmips
;
7179 dynobj
= elf_hash_table (info
)->dynobj
;
7181 /* Make sure we know what is going on here. */
7182 BFD_ASSERT (dynobj
!= NULL
7183 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
7184 || h
->weakdef
!= NULL
7185 || ((h
->elf_link_hash_flags
7186 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
7187 && (h
->elf_link_hash_flags
7188 & ELF_LINK_HASH_REF_REGULAR
) != 0
7189 && (h
->elf_link_hash_flags
7190 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
7192 /* If this symbol is defined in a dynamic object, we need to copy
7193 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
7195 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7196 if (! info
->relocateable
7197 && hmips
->mips_32_relocs
!= 0
7198 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
7199 mips_elf_allocate_dynamic_relocations (dynobj
, hmips
->mips_32_relocs
);
7201 /* For a function, create a stub, if needed. */
7202 if (h
->type
== STT_FUNC
7203 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
7205 if (! elf_hash_table (info
)->dynamic_sections_created
)
7208 /* If this symbol is not defined in a regular file, then set
7209 the symbol to the stub location. This is required to make
7210 function pointers compare as equal between the normal
7211 executable and the shared library. */
7212 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
7214 /* We need .stub section. */
7215 s
= bfd_get_section_by_name (dynobj
,
7216 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
7217 BFD_ASSERT (s
!= NULL
);
7219 h
->root
.u
.def
.section
= s
;
7220 h
->root
.u
.def
.value
= s
->_raw_size
;
7222 /* XXX Write this stub address somewhere. */
7223 h
->plt
.offset
= s
->_raw_size
;
7225 /* Make room for this stub code. */
7226 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
7228 /* The last half word of the stub will be filled with the index
7229 of this symbol in .dynsym section. */
7234 /* If this is a weak symbol, and there is a real definition, the
7235 processor independent code will have arranged for us to see the
7236 real definition first, and we can just use the same value. */
7237 if (h
->weakdef
!= NULL
)
7239 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
7240 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
7241 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
7242 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
7246 /* This is a reference to a symbol defined by a dynamic object which
7247 is not a function. */
7252 /* This function is called after all the input files have been read,
7253 and the input sections have been assigned to output sections. We
7254 check for any mips16 stub sections that we can discard. */
7256 static boolean mips_elf_check_mips16_stubs
7257 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
7260 _bfd_mips_elf_always_size_sections (output_bfd
, info
)
7262 struct bfd_link_info
*info
;
7266 /* The .reginfo section has a fixed size. */
7267 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
7269 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
7271 if (info
->relocateable
7272 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
7275 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
7276 mips_elf_check_mips16_stubs
,
7282 /* Check the mips16 stubs for a particular symbol, and see if we can
7287 mips_elf_check_mips16_stubs (h
, data
)
7288 struct mips_elf_link_hash_entry
*h
;
7291 if (h
->fn_stub
!= NULL
7292 && ! h
->need_fn_stub
)
7294 /* We don't need the fn_stub; the only references to this symbol
7295 are 16 bit calls. Clobber the size to 0 to prevent it from
7296 being included in the link. */
7297 h
->fn_stub
->_raw_size
= 0;
7298 h
->fn_stub
->_cooked_size
= 0;
7299 h
->fn_stub
->flags
&= ~ SEC_RELOC
;
7300 h
->fn_stub
->reloc_count
= 0;
7301 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
7304 if (h
->call_stub
!= NULL
7305 && h
->root
.other
== STO_MIPS16
)
7307 /* We don't need the call_stub; this is a 16 bit function, so
7308 calls from other 16 bit functions are OK. Clobber the size
7309 to 0 to prevent it from being included in the link. */
7310 h
->call_stub
->_raw_size
= 0;
7311 h
->call_stub
->_cooked_size
= 0;
7312 h
->call_stub
->flags
&= ~ SEC_RELOC
;
7313 h
->call_stub
->reloc_count
= 0;
7314 h
->call_stub
->flags
|= SEC_EXCLUDE
;
7317 if (h
->call_fp_stub
!= NULL
7318 && h
->root
.other
== STO_MIPS16
)
7320 /* We don't need the call_stub; this is a 16 bit function, so
7321 calls from other 16 bit functions are OK. Clobber the size
7322 to 0 to prevent it from being included in the link. */
7323 h
->call_fp_stub
->_raw_size
= 0;
7324 h
->call_fp_stub
->_cooked_size
= 0;
7325 h
->call_fp_stub
->flags
&= ~ SEC_RELOC
;
7326 h
->call_fp_stub
->reloc_count
= 0;
7327 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
7333 /* Set the sizes of the dynamic sections. */
7336 _bfd_mips_elf_size_dynamic_sections (output_bfd
, info
)
7338 struct bfd_link_info
*info
;
7343 struct mips_got_info
*g
;
7345 dynobj
= elf_hash_table (info
)->dynobj
;
7346 BFD_ASSERT (dynobj
!= NULL
);
7348 if (elf_hash_table (info
)->dynamic_sections_created
)
7350 /* Set the contents of the .interp section to the interpreter. */
7353 s
= bfd_get_section_by_name (dynobj
, ".interp");
7354 BFD_ASSERT (s
!= NULL
);
7356 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
7358 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
7362 /* The check_relocs and adjust_dynamic_symbol entry points have
7363 determined the sizes of the various dynamic sections. Allocate
7366 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
7371 /* It's OK to base decisions on the section name, because none
7372 of the dynobj section names depend upon the input files. */
7373 name
= bfd_get_section_name (dynobj
, s
);
7375 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
7380 if (strncmp (name
, ".rel", 4) == 0)
7382 if (s
->_raw_size
== 0)
7384 /* We only strip the section if the output section name
7385 has the same name. Otherwise, there might be several
7386 input sections for this output section. FIXME: This
7387 code is probably not needed these days anyhow, since
7388 the linker now does not create empty output sections. */
7389 if (s
->output_section
!= NULL
7391 bfd_get_section_name (s
->output_section
->owner
,
7392 s
->output_section
)) == 0)
7397 const char *outname
;
7400 /* If this relocation section applies to a read only
7401 section, then we probably need a DT_TEXTREL entry.
7402 If the relocation section is .rel.dyn, we always
7403 assert a DT_TEXTREL entry rather than testing whether
7404 there exists a relocation to a read only section or
7406 outname
= bfd_get_section_name (output_bfd
,
7408 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
7410 && (target
->flags
& SEC_READONLY
) != 0
7411 && (target
->flags
& SEC_ALLOC
) != 0)
7413 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd
)) == 0)
7416 /* We use the reloc_count field as a counter if we need
7417 to copy relocs into the output file. */
7419 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd
)) != 0)
7423 else if (strncmp (name
, ".got", 4) == 0)
7426 bfd_size_type loadable_size
= 0;
7427 bfd_size_type local_gotno
;
7430 BFD_ASSERT (elf_section_data (s
) != NULL
);
7431 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
7432 BFD_ASSERT (g
!= NULL
);
7434 /* Calculate the total loadable size of the output. That
7435 will give us the maximum number of GOT_PAGE entries
7437 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
7439 asection
*subsection
;
7441 for (subsection
= sub
->sections
;
7443 subsection
= subsection
->next
)
7445 if ((subsection
->flags
& SEC_ALLOC
) == 0)
7447 loadable_size
+= (subsection
->_raw_size
+ 0xf) & ~0xf;
7450 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
7452 /* Assume there are two loadable segments consisting of
7453 contiguous sections. Is 5 enough? */
7454 local_gotno
= (loadable_size
>> 16) + 5;
7455 g
->local_gotno
+= local_gotno
;
7456 s
->_raw_size
+= local_gotno
* MIPS_ELF_GOT_SIZE (dynobj
);
7458 /* There has to be a global GOT entry for every symbol with
7459 a dynamic symbol table index of DT_MIPS_GOTSYM or
7460 higher. Therefore, it make sense to put those symbols
7461 that need GOT entries at the end of the symbol table. We
7463 if (!mips_elf_sort_hash_table (info
))
7466 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
7467 s
->_raw_size
+= i
* MIPS_ELF_GOT_SIZE (dynobj
);
7469 else if (strcmp (name
, MIPS_ELF_STUB_SECTION_NAME (output_bfd
)) == 0)
7471 /* Irix rld assumes that the function stub isn't at the end
7472 of .text section. So put a dummy. XXX */
7473 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
7475 else if (! info
->shared
7476 && ! mips_elf_hash_table (info
)->use_rld_obj_head
7477 && strncmp (name
, ".rld_map", 8) == 0)
7479 /* We add a room for __rld_map. It will be filled in by the
7480 rtld to contain a pointer to the _r_debug structure. */
7483 else if (SGI_COMPAT (output_bfd
)
7484 && strncmp (name
, ".compact_rel", 12) == 0)
7485 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
7486 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
))
7488 s
->_raw_size
= (sizeof (Elf32_External_Msym
)
7489 * (elf_hash_table (info
)->dynsymcount
7490 + bfd_count_sections (output_bfd
)));
7491 else if (strncmp (name
, ".init", 5) != 0)
7493 /* It's not one of our sections, so don't allocate space. */
7499 _bfd_strip_section_from_output (s
);
7503 /* Allocate memory for the section contents. */
7504 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
7505 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
7507 bfd_set_error (bfd_error_no_memory
);
7512 if (elf_hash_table (info
)->dynamic_sections_created
)
7514 /* Add some entries to the .dynamic section. We fill in the
7515 values later, in elf_mips_finish_dynamic_sections, but we
7516 must add the entries now so that we get the correct size for
7517 the .dynamic section. The DT_DEBUG entry is filled in by the
7518 dynamic linker and used by the debugger. */
7521 if (SGI_COMPAT (output_bfd
))
7523 /* SGI object has the equivalence of DT_DEBUG in the
7524 DT_MIPS_RLD_MAP entry. */
7525 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
7529 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
7535 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
7539 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
7542 if (bfd_get_section_by_name (dynobj
,
7543 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
)))
7545 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
7548 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
7551 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
7555 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICTNO
, 0))
7558 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLISTNO
, 0))
7561 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
7563 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICT
, 0))
7566 s
= bfd_get_section_by_name (dynobj
, ".liblist");
7567 BFD_ASSERT (s
!= NULL
);
7569 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLIST
, 0))
7573 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
7576 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
7580 /* Time stamps in executable files are a bad idea. */
7581 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_TIME_STAMP
, 0))
7586 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_ICHECKSUM
, 0))
7591 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_IVERSION
, 0))
7595 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
7598 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
7601 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
7604 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
7607 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
7610 if (IRIX_COMPAT (dynobj
) == ict_irix5
7611 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
7614 if (IRIX_COMPAT (dynobj
) == ict_irix6
7615 && (bfd_get_section_by_name
7616 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
7617 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
7620 if (bfd_get_section_by_name (dynobj
,
7621 MIPS_ELF_MSYM_SECTION_NAME (dynobj
))
7622 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_MSYM
, 0))
7626 /* If we use dynamic linking, we generate a section symbol for each
7627 output section. These are local symbols, which means that they
7628 must come first in the dynamic symbol table.
7629 That means we must increment the dynamic symbol index of every
7630 other dynamic symbol. */
7633 struct mips_got_info
*g
;
7636 if (elf_hash_table (info
)->dynamic_sections_created
)
7638 c
= bfd_count_sections (output_bfd
);
7639 elf_link_hash_traverse (elf_hash_table (info
),
7640 _bfd_elf_link_adjust_dynindx
,
7642 elf_hash_table (info
)->dynsymcount
+= c
;
7644 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
7646 elf_section_data (s
)->dynindx
= i
;
7647 /* These symbols will have no names, so we don't need to
7648 fiddle with dynstr_index. */
7656 /* If NAME is one of the special IRIX6 symbols defined by the linker,
7657 adjust it appropriately now. */
7660 mips_elf_irix6_finish_dynamic_symbol (abfd
, name
, sym
)
7663 Elf_Internal_Sym
*sym
;
7665 /* The linker script takes care of providing names and values for
7666 these, but we must place them into the right sections. */
7667 static const char* const text_section_symbols
[] = {
7670 "__dso_displacement",
7672 "__program_header_table",
7676 static const char* const data_section_symbols
[] = {
7684 const char* const *p
;
7687 for (i
= 0; i
< 2; ++i
)
7688 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
7691 if (strcmp (*p
, name
) == 0)
7693 /* All of these symbols are given type STT_SECTION by the
7695 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7697 /* The IRIX linker puts these symbols in special sections. */
7699 sym
->st_shndx
= SHN_MIPS_TEXT
;
7701 sym
->st_shndx
= SHN_MIPS_DATA
;
7707 /* Finish up dynamic symbol handling. We set the contents of various
7708 dynamic sections here. */
7711 _bfd_mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
7713 struct bfd_link_info
*info
;
7714 struct elf_link_hash_entry
*h
;
7715 Elf_Internal_Sym
*sym
;
7721 struct mips_got_info
*g
;
7723 struct mips_elf_link_hash_entry
*mh
;
7725 dynobj
= elf_hash_table (info
)->dynobj
;
7726 gval
= sym
->st_value
;
7727 mh
= (struct mips_elf_link_hash_entry
*) h
;
7729 if (h
->plt
.offset
!= (bfd_vma
) -1)
7733 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
7735 /* This symbol has a stub. Set it up. */
7737 BFD_ASSERT (h
->dynindx
!= -1);
7739 s
= bfd_get_section_by_name (dynobj
,
7740 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
7741 BFD_ASSERT (s
!= NULL
);
7743 /* Fill the stub. */
7745 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
7747 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
7750 /* FIXME: Can h->dynindex be more than 64K? */
7751 if (h
->dynindx
& 0xffff0000)
7754 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
7756 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
7758 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
7759 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
7761 /* Mark the symbol as undefined. plt.offset != -1 occurs
7762 only for the referenced symbol. */
7763 sym
->st_shndx
= SHN_UNDEF
;
7765 /* The run-time linker uses the st_value field of the symbol
7766 to reset the global offset table entry for this external
7767 to its stub address when unlinking a shared object. */
7768 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
7769 sym
->st_value
= gval
;
7772 BFD_ASSERT (h
->dynindx
!= -1);
7774 sgot
= mips_elf_got_section (dynobj
);
7775 BFD_ASSERT (sgot
!= NULL
);
7776 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7777 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7778 BFD_ASSERT (g
!= NULL
);
7780 /* Run through the global symbol table, creating GOT entries for all
7781 the symbols that need them. */
7782 if (h
->dynindx
>= g
->global_gotsym
->dynindx
)
7788 value
= sym
->st_value
;
7790 /* For an entity defined in a shared object, this will be
7791 NULL. (For functions in shared objects for
7792 which we have created stubs, ST_VALUE will be non-NULL.
7793 That's because such the functions are now no longer defined
7794 in a shared object.) */
7795 value
= h
->root
.u
.def
.value
;
7797 offset
= mips_elf_global_got_index (dynobj
, h
);
7798 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
7801 /* Create a .msym entry, if appropriate. */
7802 smsym
= bfd_get_section_by_name (dynobj
,
7803 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
7806 Elf32_Internal_Msym msym
;
7808 msym
.ms_hash_value
= bfd_elf_hash (h
->root
.root
.string
);
7809 /* It is undocumented what the `1' indicates, but IRIX6 uses
7811 msym
.ms_info
= ELF32_MS_INFO (mh
->min_dyn_reloc_index
, 1);
7812 bfd_mips_elf_swap_msym_out
7814 ((Elf32_External_Msym
*) smsym
->contents
) + h
->dynindx
);
7817 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7818 name
= h
->root
.root
.string
;
7819 if (strcmp (name
, "_DYNAMIC") == 0
7820 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
7821 sym
->st_shndx
= SHN_ABS
;
7822 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
7824 sym
->st_shndx
= SHN_ABS
;
7825 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7828 else if (SGI_COMPAT (output_bfd
))
7830 if (strcmp (name
, "_gp_disp") == 0)
7832 sym
->st_shndx
= SHN_ABS
;
7833 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7834 sym
->st_value
= elf_gp (output_bfd
);
7836 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
7837 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
7839 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7840 sym
->st_other
= STO_PROTECTED
;
7842 sym
->st_shndx
= SHN_MIPS_DATA
;
7844 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
7846 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7847 sym
->st_other
= STO_PROTECTED
;
7848 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
7849 sym
->st_shndx
= SHN_ABS
;
7851 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
7853 if (h
->type
== STT_FUNC
)
7854 sym
->st_shndx
= SHN_MIPS_TEXT
;
7855 else if (h
->type
== STT_OBJECT
)
7856 sym
->st_shndx
= SHN_MIPS_DATA
;
7860 /* Handle the IRIX6-specific symbols. */
7861 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
7862 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
7864 if (SGI_COMPAT (output_bfd
)
7867 if (! mips_elf_hash_table (info
)->use_rld_obj_head
7868 && strcmp (name
, "__rld_map") == 0)
7870 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7871 BFD_ASSERT (s
!= NULL
);
7872 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
7873 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
7874 if (mips_elf_hash_table (info
)->rld_value
== 0)
7875 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7877 else if (mips_elf_hash_table (info
)->use_rld_obj_head
7878 && strcmp (name
, "__rld_obj_head") == 0)
7880 /* IRIX6 does not use a .rld_map section. */
7881 if (IRIX_COMPAT (output_bfd
) == ict_irix5
)
7882 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
7884 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7888 /* If this is a mips16 symbol, force the value to be even. */
7889 if (sym
->st_other
== STO_MIPS16
7890 && (sym
->st_value
& 1) != 0)
7896 /* Finish up the dynamic sections. */
7899 _bfd_mips_elf_finish_dynamic_sections (output_bfd
, info
)
7901 struct bfd_link_info
*info
;
7906 struct mips_got_info
*g
;
7908 dynobj
= elf_hash_table (info
)->dynobj
;
7910 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
7912 sgot
= mips_elf_got_section (dynobj
);
7917 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7918 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7919 BFD_ASSERT (g
!= NULL
);
7922 if (elf_hash_table (info
)->dynamic_sections_created
)
7926 BFD_ASSERT (sdyn
!= NULL
);
7927 BFD_ASSERT (g
!= NULL
);
7929 for (b
= sdyn
->contents
;
7930 b
< sdyn
->contents
+ sdyn
->_raw_size
;
7931 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
7933 Elf_Internal_Dyn dyn
;
7939 /* Read in the current dynamic entry. */
7940 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
7942 /* Assume that we're going to modify it and write it out. */
7948 s
= (bfd_get_section_by_name
7950 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
)));
7951 BFD_ASSERT (s
!= NULL
);
7952 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
7956 /* Rewrite DT_STRSZ. */
7958 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
7964 case DT_MIPS_CONFLICT
:
7967 case DT_MIPS_LIBLIST
:
7970 s
= bfd_get_section_by_name (output_bfd
, name
);
7971 BFD_ASSERT (s
!= NULL
);
7972 dyn
.d_un
.d_ptr
= s
->vma
;
7975 case DT_MIPS_RLD_VERSION
:
7976 dyn
.d_un
.d_val
= 1; /* XXX */
7980 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
7983 case DT_MIPS_CONFLICTNO
:
7985 elemsize
= sizeof (Elf32_Conflict
);
7988 case DT_MIPS_LIBLISTNO
:
7990 elemsize
= sizeof (Elf32_Lib
);
7992 s
= bfd_get_section_by_name (output_bfd
, name
);
7995 if (s
->_cooked_size
!= 0)
7996 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7998 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
8004 case DT_MIPS_TIME_STAMP
:
8005 time ((time_t *) &dyn
.d_un
.d_val
);
8008 case DT_MIPS_ICHECKSUM
:
8013 case DT_MIPS_IVERSION
:
8018 case DT_MIPS_BASE_ADDRESS
:
8019 s
= output_bfd
->sections
;
8020 BFD_ASSERT (s
!= NULL
);
8021 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
8024 case DT_MIPS_LOCAL_GOTNO
:
8025 dyn
.d_un
.d_val
= g
->local_gotno
;
8028 case DT_MIPS_SYMTABNO
:
8030 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
8031 s
= bfd_get_section_by_name (output_bfd
, name
);
8032 BFD_ASSERT (s
!= NULL
);
8034 if (s
->_cooked_size
!= 0)
8035 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
8037 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
8040 case DT_MIPS_UNREFEXTNO
:
8041 /* The index into the dynamic symbol table which is the
8042 entry of the first external symbol that is not
8043 referenced within the same object. */
8044 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
8047 case DT_MIPS_GOTSYM
:
8048 dyn
.d_un
.d_val
= g
->global_gotsym
->dynindx
;
8051 case DT_MIPS_HIPAGENO
:
8052 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
8055 case DT_MIPS_RLD_MAP
:
8056 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
8059 case DT_MIPS_OPTIONS
:
8060 s
= (bfd_get_section_by_name
8061 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
8062 dyn
.d_un
.d_ptr
= s
->vma
;
8066 s
= (bfd_get_section_by_name
8067 (output_bfd
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
)));
8068 dyn
.d_un
.d_ptr
= s
->vma
;
8077 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
8082 /* The first entry of the global offset table will be filled at
8083 runtime. The second entry will be used by some runtime loaders.
8084 This isn't the case of Irix rld. */
8085 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
8087 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
8088 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0x80000000,
8089 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
8093 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
8094 = MIPS_ELF_GOT_SIZE (output_bfd
);
8100 Elf_Internal_Sym sym
;
8101 Elf32_compact_rel cpt
;
8103 /* Set up the section symbols for the output sections. SGI sets
8104 the STT_NOTYPE attribute for these symbols. Should we do so? */
8106 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
8107 smsym
= bfd_get_section_by_name (dynobj
,
8108 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
8109 if (sdynsym
!= NULL
)
8111 Elf32_Internal_Msym msym
;
8115 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
8118 msym
.ms_hash_value
= 0;
8119 msym
.ms_info
= ELF32_MS_INFO (0, 1);
8121 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
8126 sym
.st_value
= s
->vma
;
8128 indx
= elf_section_data (s
)->this_idx
;
8129 BFD_ASSERT (indx
> 0);
8130 sym
.st_shndx
= indx
;
8132 dynindx
= elf_section_data (s
)->dynindx
;
8134 (*get_elf_backend_data (output_bfd
)->s
->swap_symbol_out
)
8137 + (dynindx
* MIPS_ELF_SYM_SIZE (output_bfd
)));
8140 bfd_mips_elf_swap_msym_out
8142 (((Elf32_External_Msym
*) smsym
->contents
)
8146 /* Set the sh_info field of the output .dynsym section to
8147 the index of the first global symbol. */
8148 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
8149 bfd_count_sections (output_bfd
) + 1;
8152 if (SGI_COMPAT (output_bfd
))
8154 /* Write .compact_rel section out. */
8155 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
8159 cpt
.num
= s
->reloc_count
;
8161 cpt
.offset
= (s
->output_section
->filepos
8162 + sizeof (Elf32_External_compact_rel
));
8165 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
8166 ((Elf32_External_compact_rel
*)
8169 /* Clean up a dummy stub function entry in .text. */
8170 s
= bfd_get_section_by_name (dynobj
,
8171 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
8174 file_ptr dummy_offset
;
8176 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
8177 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
8178 memset (s
->contents
+ dummy_offset
, 0,
8179 MIPS_FUNCTION_STUB_SIZE
);
8184 /* Clean up a first relocation in .rel.dyn. */
8185 s
= bfd_get_section_by_name (dynobj
,
8186 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
));
8187 if (s
!= NULL
&& s
->_raw_size
> 0)
8188 memset (s
->contents
, 0, MIPS_ELF_REL_SIZE (dynobj
));
8194 /* This is almost identical to bfd_generic_get_... except that some
8195 MIPS relocations need to be handled specially. Sigh. */
8198 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
8199 relocateable
, symbols
)
8201 struct bfd_link_info
*link_info
;
8202 struct bfd_link_order
*link_order
;
8204 boolean relocateable
;
8207 /* Get enough memory to hold the stuff */
8208 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
8209 asection
*input_section
= link_order
->u
.indirect
.section
;
8211 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
8212 arelent
**reloc_vector
= NULL
;
8218 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
8219 if (reloc_vector
== NULL
&& reloc_size
!= 0)
8222 /* read in the section */
8223 if (!bfd_get_section_contents (input_bfd
,
8227 input_section
->_raw_size
))
8230 /* We're not relaxing the section, so just copy the size info */
8231 input_section
->_cooked_size
= input_section
->_raw_size
;
8232 input_section
->reloc_done
= true;
8234 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
8238 if (reloc_count
< 0)
8241 if (reloc_count
> 0)
8246 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
8249 struct bfd_hash_entry
*h
;
8250 struct bfd_link_hash_entry
*lh
;
8251 /* Skip all this stuff if we aren't mixing formats. */
8252 if (abfd
&& input_bfd
8253 && abfd
->xvec
== input_bfd
->xvec
)
8257 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
8258 lh
= (struct bfd_link_hash_entry
*) h
;
8265 case bfd_link_hash_undefined
:
8266 case bfd_link_hash_undefweak
:
8267 case bfd_link_hash_common
:
8270 case bfd_link_hash_defined
:
8271 case bfd_link_hash_defweak
:
8273 gp
= lh
->u
.def
.value
;
8275 case bfd_link_hash_indirect
:
8276 case bfd_link_hash_warning
:
8278 /* @@FIXME ignoring warning for now */
8280 case bfd_link_hash_new
:
8289 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
8292 char *error_message
= (char *) NULL
;
8293 bfd_reloc_status_type r
;
8295 /* Specific to MIPS: Deal with relocation types that require
8296 knowing the gp of the output bfd. */
8297 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
8298 if (bfd_is_abs_section (sym
->section
) && abfd
)
8300 /* The special_function wouldn't get called anyways. */
8304 /* The gp isn't there; let the special function code
8305 fall over on its own. */
8307 else if ((*parent
)->howto
->special_function
8308 == _bfd_mips_elf_gprel16_reloc
)
8310 /* bypass special_function call */
8311 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
8312 relocateable
, (PTR
) data
, gp
);
8313 goto skip_bfd_perform_relocation
;
8315 /* end mips specific stuff */
8317 r
= bfd_perform_relocation (input_bfd
,
8321 relocateable
? abfd
: (bfd
*) NULL
,
8323 skip_bfd_perform_relocation
:
8327 asection
*os
= input_section
->output_section
;
8329 /* A partial link, so keep the relocs */
8330 os
->orelocation
[os
->reloc_count
] = *parent
;
8334 if (r
!= bfd_reloc_ok
)
8338 case bfd_reloc_undefined
:
8339 if (!((*link_info
->callbacks
->undefined_symbol
)
8340 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
8341 input_bfd
, input_section
, (*parent
)->address
)))
8344 case bfd_reloc_dangerous
:
8345 BFD_ASSERT (error_message
!= (char *) NULL
);
8346 if (!((*link_info
->callbacks
->reloc_dangerous
)
8347 (link_info
, error_message
, input_bfd
, input_section
,
8348 (*parent
)->address
)))
8351 case bfd_reloc_overflow
:
8352 if (!((*link_info
->callbacks
->reloc_overflow
)
8353 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
8354 (*parent
)->howto
->name
, (*parent
)->addend
,
8355 input_bfd
, input_section
, (*parent
)->address
)))
8358 case bfd_reloc_outofrange
:
8367 if (reloc_vector
!= NULL
)
8368 free (reloc_vector
);
8372 if (reloc_vector
!= NULL
)
8373 free (reloc_vector
);
8376 #define bfd_elf32_bfd_get_relocated_section_contents \
8377 elf32_mips_get_relocated_section_contents
8379 /* ECOFF swapping routines. These are used when dealing with the
8380 .mdebug section, which is in the ECOFF debugging format. */
8381 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
8383 /* Symbol table magic number. */
8385 /* Alignment of debugging information. E.g., 4. */
8387 /* Sizes of external symbolic information. */
8388 sizeof (struct hdr_ext
),
8389 sizeof (struct dnr_ext
),
8390 sizeof (struct pdr_ext
),
8391 sizeof (struct sym_ext
),
8392 sizeof (struct opt_ext
),
8393 sizeof (struct fdr_ext
),
8394 sizeof (struct rfd_ext
),
8395 sizeof (struct ext_ext
),
8396 /* Functions to swap in external symbolic data. */
8405 _bfd_ecoff_swap_tir_in
,
8406 _bfd_ecoff_swap_rndx_in
,
8407 /* Functions to swap out external symbolic data. */
8416 _bfd_ecoff_swap_tir_out
,
8417 _bfd_ecoff_swap_rndx_out
,
8418 /* Function to read in symbolic data. */
8419 _bfd_mips_elf_read_ecoff_info
8422 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
8423 #define TARGET_LITTLE_NAME "elf32-littlemips"
8424 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
8425 #define TARGET_BIG_NAME "elf32-bigmips"
8426 #define ELF_ARCH bfd_arch_mips
8427 #define ELF_MACHINE_CODE EM_MIPS
8429 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
8430 a value of 0x1000, and we are compatible. */
8431 #define ELF_MAXPAGESIZE 0x1000
8433 #define elf_backend_collect true
8434 #define elf_backend_type_change_ok true
8435 #define elf_backend_can_gc_sections true
8436 #define elf_info_to_howto mips_info_to_howto_rela
8437 #define elf_info_to_howto_rel mips_info_to_howto_rel
8438 #define elf_backend_sym_is_global mips_elf_sym_is_global
8439 #define elf_backend_object_p _bfd_mips_elf_object_p
8440 #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
8441 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
8442 #define elf_backend_section_from_bfd_section \
8443 _bfd_mips_elf_section_from_bfd_section
8444 #define elf_backend_section_processing _bfd_mips_elf_section_processing
8445 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
8446 #define elf_backend_additional_program_headers \
8447 _bfd_mips_elf_additional_program_headers
8448 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
8449 #define elf_backend_final_write_processing \
8450 _bfd_mips_elf_final_write_processing
8451 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
8452 #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
8453 #define elf_backend_create_dynamic_sections \
8454 _bfd_mips_elf_create_dynamic_sections
8455 #define elf_backend_check_relocs _bfd_mips_elf_check_relocs
8456 #define elf_backend_adjust_dynamic_symbol \
8457 _bfd_mips_elf_adjust_dynamic_symbol
8458 #define elf_backend_always_size_sections \
8459 _bfd_mips_elf_always_size_sections
8460 #define elf_backend_size_dynamic_sections \
8461 _bfd_mips_elf_size_dynamic_sections
8462 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section
8463 #define elf_backend_link_output_symbol_hook \
8464 _bfd_mips_elf_link_output_symbol_hook
8465 #define elf_backend_finish_dynamic_symbol \
8466 _bfd_mips_elf_finish_dynamic_symbol
8467 #define elf_backend_finish_dynamic_sections \
8468 _bfd_mips_elf_finish_dynamic_sections
8469 #define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
8470 #define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
8472 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
8473 #define elf_backend_plt_header_size 0
8475 #define bfd_elf32_bfd_is_local_label_name \
8476 mips_elf_is_local_label_name
8477 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
8478 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
8479 #define bfd_elf32_bfd_link_hash_table_create \
8480 _bfd_mips_elf_link_hash_table_create
8481 #define bfd_elf32_bfd_final_link _bfd_mips_elf_final_link
8482 #define bfd_elf32_bfd_copy_private_bfd_data \
8483 _bfd_mips_elf_copy_private_bfd_data
8484 #define bfd_elf32_bfd_merge_private_bfd_data \
8485 _bfd_mips_elf_merge_private_bfd_data
8486 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
8487 #define bfd_elf32_bfd_print_private_bfd_data \
8488 _bfd_mips_elf_print_private_bfd_data
8489 #include "elf32-target.h"