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 global .got entries. */
55 unsigned int global_gotno
;
56 /* The number of local .got entries. */
57 unsigned int local_gotno
;
58 /* The number of local .got entries we have used. */
59 unsigned int assigned_gotno
;
62 /* The MIPS ELF linker needs additional information for each symbol in
63 the global hash table. */
65 struct mips_elf_link_hash_entry
67 struct elf_link_hash_entry root
;
69 /* External symbol information. */
72 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
74 unsigned int possibly_dynamic_relocs
;
76 /* The index of the first dynamic relocation (in the .rel.dyn
77 section) against this symbol. */
78 unsigned int min_dyn_reloc_index
;
80 /* If there is a stub that 32 bit functions should use to call this
81 16 bit function, this points to the section containing the stub. */
84 /* Whether we need the fn_stub; this is set if this symbol appears
85 in any relocs other than a 16 bit call. */
88 /* If there is a stub that 16 bit functions should use to call this
89 32 bit function, this points to the section containing the stub. */
92 /* This is like the call_stub field, but it is used if the function
93 being called returns a floating point value. */
94 asection
*call_fp_stub
;
97 static bfd_reloc_status_type mips32_64bit_reloc
98 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
99 static reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
100 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
101 static reloc_howto_type
*mips_rtype_to_howto
102 PARAMS ((unsigned int));
103 static void mips_info_to_howto_rel
104 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
105 static void mips_info_to_howto_rela
106 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rela
*));
107 static void bfd_mips_elf32_swap_gptab_in
108 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
109 static void bfd_mips_elf32_swap_gptab_out
110 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
112 static void bfd_mips_elf_swap_msym_in
113 PARAMS ((bfd
*, const Elf32_External_Msym
*, Elf32_Internal_Msym
*));
115 static void bfd_mips_elf_swap_msym_out
116 PARAMS ((bfd
*, const Elf32_Internal_Msym
*, Elf32_External_Msym
*));
117 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
118 static boolean mips_elf_create_procedure_table
119 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
120 struct ecoff_debug_info
*));
121 static INLINE
int elf_mips_isa
PARAMS ((flagword
));
122 static INLINE
int elf_mips_mach
PARAMS ((flagword
));
123 static INLINE
char* elf_mips_abi_name
PARAMS ((bfd
*));
124 static boolean mips_elf_is_local_label_name
125 PARAMS ((bfd
*, const char *));
126 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
127 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
128 static int gptab_compare
PARAMS ((const void *, const void *));
129 static bfd_reloc_status_type mips16_jump_reloc
130 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
131 static bfd_reloc_status_type mips16_gprel_reloc
132 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
133 static boolean mips_elf_create_compact_rel_section
134 PARAMS ((bfd
*, struct bfd_link_info
*));
135 static boolean mips_elf_create_got_section
136 PARAMS ((bfd
*, struct bfd_link_info
*));
137 static bfd_reloc_status_type mips_elf_final_gp
138 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
139 static bfd_byte
*elf32_mips_get_relocated_section_contents
140 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
141 bfd_byte
*, boolean
, asymbol
**));
142 static asection
*mips_elf_create_msym_section
144 static void mips_elf_irix6_finish_dynamic_symbol
145 PARAMS ((bfd
*, const char *, Elf_Internal_Sym
*));
146 static bfd_vma mips_elf_sign_extend
PARAMS ((bfd_vma
, int));
147 static boolean mips_elf_overflow_p
PARAMS ((bfd_vma
, int));
148 static bfd_vma mips_elf_high
PARAMS ((bfd_vma
));
149 static bfd_vma mips_elf_higher
PARAMS ((bfd_vma
));
150 static bfd_vma mips_elf_highest
PARAMS ((bfd_vma
));
151 static bfd_vma mips_elf_global_got_index
152 PARAMS ((bfd
*, struct elf_link_hash_entry
*));
153 static bfd_vma mips_elf_local_got_index
154 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
));
155 static bfd_vma mips_elf_got_offset_from_index
156 PARAMS ((bfd
*, bfd
*, bfd_vma
));
157 static boolean mips_elf_record_global_got_symbol
158 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*,
159 struct mips_got_info
*));
160 static bfd_vma mips_elf_got_page
161 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
, bfd_vma
*));
162 static const Elf_Internal_Rela
*mips_elf_next_relocation
163 PARAMS ((unsigned int, const Elf_Internal_Rela
*,
164 const Elf_Internal_Rela
*));
165 static bfd_reloc_status_type mips_elf_calculate_relocation
166 PARAMS ((bfd
*, bfd
*, asection
*, struct bfd_link_info
*,
167 const Elf_Internal_Rela
*, bfd_vma
, reloc_howto_type
*,
168 Elf_Internal_Sym
*, asection
**, bfd_vma
*, const char **,
170 static bfd_vma mips_elf_obtain_contents
171 PARAMS ((reloc_howto_type
*, const Elf_Internal_Rela
*, bfd
*, bfd_byte
*));
172 static boolean mips_elf_perform_relocation
173 PARAMS ((struct bfd_link_info
*, reloc_howto_type
*,
174 const Elf_Internal_Rela
*, bfd_vma
,
175 bfd
*, asection
*, bfd_byte
*, boolean
));
176 static boolean mips_elf_assign_gp
PARAMS ((bfd
*, bfd_vma
*));
177 static boolean mips_elf_sort_hash_table_f
178 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
179 static boolean mips_elf_sort_hash_table
180 PARAMS ((struct bfd_link_info
*, unsigned long));
181 static asection
* mips_elf_got_section
PARAMS ((bfd
*));
182 static struct mips_got_info
*mips_elf_got_info
183 PARAMS ((bfd
*, asection
**));
184 static boolean mips_elf_local_relocation_p
185 PARAMS ((bfd
*, const Elf_Internal_Rela
*, asection
**, boolean
));
186 static bfd_vma mips_elf_create_local_got_entry
187 PARAMS ((bfd
*, struct mips_got_info
*, asection
*, bfd_vma
));
188 static bfd_vma mips_elf_got16_entry
189 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
, boolean
));
190 static boolean mips_elf_create_dynamic_relocation
191 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
192 struct mips_elf_link_hash_entry
*, asection
*,
193 bfd_vma
, bfd_vma
*, asection
*));
194 static void mips_elf_allocate_dynamic_relocations
195 PARAMS ((bfd
*, unsigned int));
196 static boolean mips_elf_stub_section_p
197 PARAMS ((bfd
*, asection
*));
199 /* The level of IRIX compatibility we're striving for. */
207 /* Nonzero if ABFD is using the N32 ABI. */
209 #define ABI_N32_P(abfd) \
210 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
212 /* Nonzero if ABFD is using the 64-bit ABI. FIXME: This is never
214 #define ABI_64_P(abfd) \
215 ((elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS64) != 0)
217 /* What version of Irix we are trying to be compatible with. FIXME:
218 At the moment, we never generate "normal" MIPS ELF ABI executables;
219 we always use some version of Irix. */
221 #define IRIX_COMPAT(abfd) \
222 ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5)
224 /* Whether we are trying to be compatible with IRIX at all. */
226 #define SGI_COMPAT(abfd) \
227 (IRIX_COMPAT (abfd) != ict_none)
229 /* The name of the msym section. */
230 #define MIPS_ELF_MSYM_SECTION_NAME(abfd) ".msym"
232 /* The name of the srdata section. */
233 #define MIPS_ELF_SRDATA_SECTION_NAME(abfd) ".srdata"
235 /* The name of the options section. */
236 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
237 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.options" : ".options")
239 /* The name of the stub section. */
240 #define MIPS_ELF_STUB_SECTION_NAME(abfd) \
241 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.stubs" : ".stub")
243 /* The name of the dynamic relocation section. */
244 #define MIPS_ELF_REL_DYN_SECTION_NAME(abfd) ".rel.dyn"
246 /* The size of an external REL relocation. */
247 #define MIPS_ELF_REL_SIZE(abfd) \
248 (get_elf_backend_data (abfd)->s->sizeof_rel)
250 /* The size of an external dynamic table entry. */
251 #define MIPS_ELF_DYN_SIZE(abfd) \
252 (get_elf_backend_data (abfd)->s->sizeof_dyn)
254 /* The size of a GOT entry. */
255 #define MIPS_ELF_GOT_SIZE(abfd) \
256 (get_elf_backend_data (abfd)->s->arch_size / 8)
258 /* The size of a symbol-table entry. */
259 #define MIPS_ELF_SYM_SIZE(abfd) \
260 (get_elf_backend_data (abfd)->s->sizeof_sym)
262 /* The default alignment for sections, as a power of two. */
263 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
264 (get_elf_backend_data (abfd)->s->file_align == 8 ? 3 : 2)
266 /* Get word-sized data. */
267 #define MIPS_ELF_GET_WORD(abfd, ptr) \
268 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
270 /* Put out word-sized data. */
271 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
273 ? bfd_put_64 (abfd, val, ptr) \
274 : bfd_put_32 (abfd, val, ptr))
276 /* Add a dynamic symbol table-entry. */
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) \
281 : bfd_elf32_add_dynamic_entry (info, tag, val))
283 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
284 (ABI_64_P (elf_hash_table (info)->dynobj) \
285 ? (abort (), false) \
286 : bfd_elf32_add_dynamic_entry (info, tag, val))
289 /* The number of local .got entries we reserve. */
290 #define MIPS_RESERVED_GOTNO (2)
292 /* Instructions which appear in a stub. For some reason the stub is
293 slightly different on an SGI system. */
294 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
295 #define STUB_LW(abfd) \
298 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
299 : 0x8f998010) /* lw t9,0x8010(gp) */ \
300 : 0x8f998000) /* lw t9,0x8000(gp) */
301 #define STUB_MOVE 0x03e07825 /* move t7,ra */
302 #define STUB_JALR 0x0320f809 /* jal t9 */
303 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
304 #define MIPS_FUNCTION_STUB_SIZE (16)
307 /* We no longer try to identify particular sections for the .dynsym
308 section. When we do, we wind up crashing if there are other random
309 sections with relocations. */
311 /* Names of sections which appear in the .dynsym section in an Irix 5
314 static const char * const mips_elf_dynsym_sec_names
[] =
327 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
328 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
330 /* The number of entries in mips_elf_dynsym_sec_names which go in the
333 #define MIPS_TEXT_DYNSYM_SECNO (3)
337 /* The names of the runtime procedure table symbols used on Irix 5. */
339 static const char * const mips_elf_dynsym_rtproc_names
[] =
342 "_procedure_string_table",
343 "_procedure_table_size",
347 /* These structures are used to generate the .compact_rel section on
352 unsigned long id1
; /* Always one? */
353 unsigned long num
; /* Number of compact relocation entries. */
354 unsigned long id2
; /* Always two? */
355 unsigned long offset
; /* The file offset of the first relocation. */
356 unsigned long reserved0
; /* Zero? */
357 unsigned long reserved1
; /* Zero? */
366 bfd_byte reserved0
[4];
367 bfd_byte reserved1
[4];
368 } Elf32_External_compact_rel
;
372 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
373 unsigned int rtype
: 4; /* Relocation types. See below. */
374 unsigned int dist2to
: 8;
375 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
376 unsigned long konst
; /* KONST field. See below. */
377 unsigned long vaddr
; /* VADDR to be relocated. */
382 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
383 unsigned int rtype
: 4; /* Relocation types. See below. */
384 unsigned int dist2to
: 8;
385 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
386 unsigned long konst
; /* KONST field. See below. */
394 } Elf32_External_crinfo
;
400 } Elf32_External_crinfo2
;
402 /* These are the constants used to swap the bitfields in a crinfo. */
404 #define CRINFO_CTYPE (0x1)
405 #define CRINFO_CTYPE_SH (31)
406 #define CRINFO_RTYPE (0xf)
407 #define CRINFO_RTYPE_SH (27)
408 #define CRINFO_DIST2TO (0xff)
409 #define CRINFO_DIST2TO_SH (19)
410 #define CRINFO_RELVADDR (0x7ffff)
411 #define CRINFO_RELVADDR_SH (0)
413 /* A compact relocation info has long (3 words) or short (2 words)
414 formats. A short format doesn't have VADDR field and relvaddr
415 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
416 #define CRF_MIPS_LONG 1
417 #define CRF_MIPS_SHORT 0
419 /* There are 4 types of compact relocation at least. The value KONST
420 has different meaning for each type:
423 CT_MIPS_REL32 Address in data
424 CT_MIPS_WORD Address in word (XXX)
425 CT_MIPS_GPHI_LO GP - vaddr
426 CT_MIPS_JMPAD Address to jump
429 #define CRT_MIPS_REL32 0xa
430 #define CRT_MIPS_WORD 0xb
431 #define CRT_MIPS_GPHI_LO 0xc
432 #define CRT_MIPS_JMPAD 0xd
434 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
435 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
436 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
437 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
439 static void bfd_elf32_swap_compact_rel_out
440 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
441 static void bfd_elf32_swap_crinfo_out
442 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
444 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
446 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
447 from smaller values. Start with zero, widen, *then* decrement. */
448 #define MINUS_ONE (((bfd_vma)0) - 1)
450 static reloc_howto_type elf_mips_howto_table
[] =
453 HOWTO (R_MIPS_NONE
, /* type */
455 0, /* size (0 = byte, 1 = short, 2 = long) */
457 false, /* pc_relative */
459 complain_overflow_dont
, /* complain_on_overflow */
460 bfd_elf_generic_reloc
, /* special_function */
461 "R_MIPS_NONE", /* name */
462 false, /* partial_inplace */
465 false), /* pcrel_offset */
467 /* 16 bit relocation. */
468 HOWTO (R_MIPS_16
, /* type */
470 1, /* size (0 = byte, 1 = short, 2 = long) */
472 false, /* pc_relative */
474 complain_overflow_bitfield
, /* complain_on_overflow */
475 bfd_elf_generic_reloc
, /* special_function */
476 "R_MIPS_16", /* name */
477 true, /* partial_inplace */
478 0xffff, /* src_mask */
479 0xffff, /* dst_mask */
480 false), /* pcrel_offset */
482 /* 32 bit relocation. */
483 HOWTO (R_MIPS_32
, /* type */
485 2, /* size (0 = byte, 1 = short, 2 = long) */
487 false, /* pc_relative */
489 complain_overflow_bitfield
, /* complain_on_overflow */
490 bfd_elf_generic_reloc
, /* special_function */
491 "R_MIPS_32", /* name */
492 true, /* partial_inplace */
493 0xffffffff, /* src_mask */
494 0xffffffff, /* dst_mask */
495 false), /* pcrel_offset */
497 /* 32 bit symbol relative relocation. */
498 HOWTO (R_MIPS_REL32
, /* type */
500 2, /* size (0 = byte, 1 = short, 2 = long) */
502 false, /* pc_relative */
504 complain_overflow_bitfield
, /* complain_on_overflow */
505 bfd_elf_generic_reloc
, /* special_function */
506 "R_MIPS_REL32", /* name */
507 true, /* partial_inplace */
508 0xffffffff, /* src_mask */
509 0xffffffff, /* dst_mask */
510 false), /* pcrel_offset */
512 /* 26 bit branch address. */
513 HOWTO (R_MIPS_26
, /* type */
515 2, /* size (0 = byte, 1 = short, 2 = long) */
517 false, /* pc_relative */
519 complain_overflow_dont
, /* complain_on_overflow */
520 /* This needs complex overflow
521 detection, because the upper four
522 bits must match the PC. */
523 bfd_elf_generic_reloc
, /* special_function */
524 "R_MIPS_26", /* name */
525 true, /* partial_inplace */
526 0x3ffffff, /* src_mask */
527 0x3ffffff, /* dst_mask */
528 false), /* pcrel_offset */
530 /* High 16 bits of symbol value. */
531 HOWTO (R_MIPS_HI16
, /* type */
533 2, /* size (0 = byte, 1 = short, 2 = long) */
535 false, /* pc_relative */
537 complain_overflow_dont
, /* complain_on_overflow */
538 _bfd_mips_elf_hi16_reloc
, /* special_function */
539 "R_MIPS_HI16", /* name */
540 true, /* partial_inplace */
541 0xffff, /* src_mask */
542 0xffff, /* dst_mask */
543 false), /* pcrel_offset */
545 /* Low 16 bits of symbol value. */
546 HOWTO (R_MIPS_LO16
, /* type */
548 2, /* size (0 = byte, 1 = short, 2 = long) */
550 false, /* pc_relative */
552 complain_overflow_dont
, /* complain_on_overflow */
553 _bfd_mips_elf_lo16_reloc
, /* special_function */
554 "R_MIPS_LO16", /* name */
555 true, /* partial_inplace */
556 0xffff, /* src_mask */
557 0xffff, /* dst_mask */
558 false), /* pcrel_offset */
560 /* GP relative reference. */
561 HOWTO (R_MIPS_GPREL16
, /* type */
563 2, /* size (0 = byte, 1 = short, 2 = long) */
565 false, /* pc_relative */
567 complain_overflow_signed
, /* complain_on_overflow */
568 _bfd_mips_elf_gprel16_reloc
, /* special_function */
569 "R_MIPS_GPREL16", /* name */
570 true, /* partial_inplace */
571 0xffff, /* src_mask */
572 0xffff, /* dst_mask */
573 false), /* pcrel_offset */
575 /* Reference to literal section. */
576 HOWTO (R_MIPS_LITERAL
, /* type */
578 2, /* size (0 = byte, 1 = short, 2 = long) */
580 false, /* pc_relative */
582 complain_overflow_signed
, /* complain_on_overflow */
583 _bfd_mips_elf_gprel16_reloc
, /* special_function */
584 "R_MIPS_LITERAL", /* name */
585 true, /* partial_inplace */
586 0xffff, /* src_mask */
587 0xffff, /* dst_mask */
588 false), /* pcrel_offset */
590 /* Reference to global offset table. */
591 HOWTO (R_MIPS_GOT16
, /* type */
593 2, /* size (0 = byte, 1 = short, 2 = long) */
595 false, /* pc_relative */
597 complain_overflow_signed
, /* complain_on_overflow */
598 _bfd_mips_elf_got16_reloc
, /* special_function */
599 "R_MIPS_GOT16", /* name */
600 false, /* partial_inplace */
601 0xffff, /* src_mask */
602 0xffff, /* dst_mask */
603 false), /* pcrel_offset */
605 /* 16 bit PC relative reference. */
606 HOWTO (R_MIPS_PC16
, /* type */
608 2, /* size (0 = byte, 1 = short, 2 = long) */
610 true, /* pc_relative */
612 complain_overflow_signed
, /* complain_on_overflow */
613 bfd_elf_generic_reloc
, /* special_function */
614 "R_MIPS_PC16", /* name */
615 true, /* partial_inplace */
616 0xffff, /* src_mask */
617 0xffff, /* dst_mask */
618 true), /* pcrel_offset */
620 /* 16 bit call through global offset table. */
621 HOWTO (R_MIPS_CALL16
, /* type */
623 2, /* size (0 = byte, 1 = short, 2 = long) */
625 false, /* pc_relative */
627 complain_overflow_signed
, /* complain_on_overflow */
628 bfd_elf_generic_reloc
, /* special_function */
629 "R_MIPS_CALL16", /* name */
630 false, /* partial_inplace */
631 0xffff, /* src_mask */
632 0xffff, /* dst_mask */
633 false), /* pcrel_offset */
635 /* 32 bit GP relative reference. */
636 HOWTO (R_MIPS_GPREL32
, /* type */
638 2, /* size (0 = byte, 1 = short, 2 = long) */
640 false, /* pc_relative */
642 complain_overflow_bitfield
, /* complain_on_overflow */
643 _bfd_mips_elf_gprel32_reloc
, /* special_function */
644 "R_MIPS_GPREL32", /* name */
645 true, /* partial_inplace */
646 0xffffffff, /* src_mask */
647 0xffffffff, /* dst_mask */
648 false), /* pcrel_offset */
650 /* The remaining relocs are defined on Irix 5, although they are
651 not defined by the ABI. */
656 /* A 5 bit shift field. */
657 HOWTO (R_MIPS_SHIFT5
, /* type */
659 2, /* size (0 = byte, 1 = short, 2 = long) */
661 false, /* pc_relative */
663 complain_overflow_bitfield
, /* complain_on_overflow */
664 bfd_elf_generic_reloc
, /* special_function */
665 "R_MIPS_SHIFT5", /* name */
666 true, /* partial_inplace */
667 0x000007c0, /* src_mask */
668 0x000007c0, /* dst_mask */
669 false), /* pcrel_offset */
671 /* A 6 bit shift field. */
672 /* FIXME: This is not handled correctly; a special function is
673 needed to put the most significant bit in the right place. */
674 HOWTO (R_MIPS_SHIFT6
, /* type */
676 2, /* size (0 = byte, 1 = short, 2 = long) */
678 false, /* pc_relative */
680 complain_overflow_bitfield
, /* complain_on_overflow */
681 bfd_elf_generic_reloc
, /* special_function */
682 "R_MIPS_SHIFT6", /* name */
683 true, /* partial_inplace */
684 0x000007c4, /* src_mask */
685 0x000007c4, /* dst_mask */
686 false), /* pcrel_offset */
688 /* A 64 bit relocation. */
689 HOWTO (R_MIPS_64
, /* type */
691 4, /* size (0 = byte, 1 = short, 2 = long) */
693 false, /* pc_relative */
695 complain_overflow_bitfield
, /* complain_on_overflow */
696 mips32_64bit_reloc
, /* special_function */
697 "R_MIPS_64", /* name */
698 true, /* partial_inplace */
699 MINUS_ONE
, /* src_mask */
700 MINUS_ONE
, /* dst_mask */
701 false), /* pcrel_offset */
703 /* Displacement in the global offset table. */
704 HOWTO (R_MIPS_GOT_DISP
, /* type */
706 2, /* size (0 = byte, 1 = short, 2 = long) */
708 false, /* pc_relative */
710 complain_overflow_bitfield
, /* complain_on_overflow */
711 bfd_elf_generic_reloc
, /* special_function */
712 "R_MIPS_GOT_DISP", /* name */
713 true, /* partial_inplace */
714 0x0000ffff, /* src_mask */
715 0x0000ffff, /* dst_mask */
716 false), /* pcrel_offset */
718 /* Displacement to page pointer in the global offset table. */
719 HOWTO (R_MIPS_GOT_PAGE
, /* type */
721 2, /* size (0 = byte, 1 = short, 2 = long) */
723 false, /* pc_relative */
725 complain_overflow_bitfield
, /* complain_on_overflow */
726 bfd_elf_generic_reloc
, /* special_function */
727 "R_MIPS_GOT_PAGE", /* name */
728 true, /* partial_inplace */
729 0x0000ffff, /* src_mask */
730 0x0000ffff, /* dst_mask */
731 false), /* pcrel_offset */
733 /* Offset from page pointer in the global offset table. */
734 HOWTO (R_MIPS_GOT_OFST
, /* type */
736 2, /* size (0 = byte, 1 = short, 2 = long) */
738 false, /* pc_relative */
740 complain_overflow_bitfield
, /* complain_on_overflow */
741 bfd_elf_generic_reloc
, /* special_function */
742 "R_MIPS_GOT_OFST", /* name */
743 true, /* partial_inplace */
744 0x0000ffff, /* src_mask */
745 0x0000ffff, /* dst_mask */
746 false), /* pcrel_offset */
748 /* High 16 bits of displacement in global offset table. */
749 HOWTO (R_MIPS_GOT_HI16
, /* type */
751 2, /* size (0 = byte, 1 = short, 2 = long) */
753 false, /* pc_relative */
755 complain_overflow_dont
, /* complain_on_overflow */
756 bfd_elf_generic_reloc
, /* special_function */
757 "R_MIPS_GOT_HI16", /* name */
758 true, /* partial_inplace */
759 0x0000ffff, /* src_mask */
760 0x0000ffff, /* dst_mask */
761 false), /* pcrel_offset */
763 /* Low 16 bits of displacement in global offset table. */
764 HOWTO (R_MIPS_GOT_LO16
, /* type */
766 2, /* size (0 = byte, 1 = short, 2 = long) */
768 false, /* pc_relative */
770 complain_overflow_dont
, /* complain_on_overflow */
771 bfd_elf_generic_reloc
, /* special_function */
772 "R_MIPS_GOT_LO16", /* name */
773 true, /* partial_inplace */
774 0x0000ffff, /* src_mask */
775 0x0000ffff, /* dst_mask */
776 false), /* pcrel_offset */
778 /* 64 bit subtraction. Used in the N32 ABI. */
779 HOWTO (R_MIPS_SUB
, /* type */
781 4, /* size (0 = byte, 1 = short, 2 = long) */
783 false, /* pc_relative */
785 complain_overflow_bitfield
, /* complain_on_overflow */
786 bfd_elf_generic_reloc
, /* special_function */
787 "R_MIPS_SUB", /* name */
788 true, /* partial_inplace */
789 MINUS_ONE
, /* src_mask */
790 MINUS_ONE
, /* dst_mask */
791 false), /* pcrel_offset */
793 /* Used to cause the linker to insert and delete instructions? */
794 EMPTY_HOWTO (R_MIPS_INSERT_A
),
795 EMPTY_HOWTO (R_MIPS_INSERT_B
),
796 EMPTY_HOWTO (R_MIPS_DELETE
),
798 /* Get the higher value of a 64 bit addend. */
799 HOWTO (R_MIPS_HIGHER
, /* type */
801 2, /* size (0 = byte, 1 = short, 2 = long) */
803 false, /* pc_relative */
805 complain_overflow_dont
, /* complain_on_overflow */
806 bfd_elf_generic_reloc
, /* special_function */
807 "R_MIPS_HIGHER", /* name */
808 true, /* partial_inplace */
810 0xffff, /* dst_mask */
811 false), /* pcrel_offset */
813 /* Get the highest value of a 64 bit addend. */
814 HOWTO (R_MIPS_HIGHEST
, /* type */
816 2, /* size (0 = byte, 1 = short, 2 = long) */
818 false, /* pc_relative */
820 complain_overflow_dont
, /* complain_on_overflow */
821 bfd_elf_generic_reloc
, /* special_function */
822 "R_MIPS_HIGHEST", /* name */
823 true, /* partial_inplace */
825 0xffff, /* dst_mask */
826 false), /* pcrel_offset */
828 /* High 16 bits of displacement in global offset table. */
829 HOWTO (R_MIPS_CALL_HI16
, /* type */
831 2, /* size (0 = byte, 1 = short, 2 = long) */
833 false, /* pc_relative */
835 complain_overflow_dont
, /* complain_on_overflow */
836 bfd_elf_generic_reloc
, /* special_function */
837 "R_MIPS_CALL_HI16", /* name */
838 true, /* partial_inplace */
839 0x0000ffff, /* src_mask */
840 0x0000ffff, /* dst_mask */
841 false), /* pcrel_offset */
843 /* Low 16 bits of displacement in global offset table. */
844 HOWTO (R_MIPS_CALL_LO16
, /* type */
846 2, /* size (0 = byte, 1 = short, 2 = long) */
848 false, /* pc_relative */
850 complain_overflow_dont
, /* complain_on_overflow */
851 bfd_elf_generic_reloc
, /* special_function */
852 "R_MIPS_CALL_LO16", /* name */
853 true, /* partial_inplace */
854 0x0000ffff, /* src_mask */
855 0x0000ffff, /* dst_mask */
856 false), /* pcrel_offset */
858 /* Section displacement. */
859 HOWTO (R_MIPS_SCN_DISP
, /* type */
861 2, /* size (0 = byte, 1 = short, 2 = long) */
863 false, /* pc_relative */
865 complain_overflow_dont
, /* complain_on_overflow */
866 bfd_elf_generic_reloc
, /* special_function */
867 "R_MIPS_SCN_DISP", /* name */
868 false, /* partial_inplace */
869 0xffffffff, /* src_mask */
870 0xffffffff, /* dst_mask */
871 false), /* pcrel_offset */
873 EMPTY_HOWTO (R_MIPS_REL16
),
874 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE
),
875 EMPTY_HOWTO (R_MIPS_PJUMP
),
876 EMPTY_HOWTO (R_MIPS_RELGOT
),
878 /* Protected jump conversion. This is an optimization hint. No
879 relocation is required for correctness. */
880 HOWTO (R_MIPS_JALR
, /* type */
882 0, /* size (0 = byte, 1 = short, 2 = long) */
884 false, /* pc_relative */
886 complain_overflow_dont
, /* complain_on_overflow */
887 bfd_elf_generic_reloc
, /* special_function */
888 "R_MIPS_JALR", /* name */
889 false, /* partial_inplace */
890 0x00000000, /* src_mask */
891 0x00000000, /* dst_mask */
892 false), /* pcrel_offset */
895 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
896 is a hack to make the linker think that we need 64 bit values. */
897 static reloc_howto_type elf_mips_ctor64_howto
=
898 HOWTO (R_MIPS_64
, /* type */
900 4, /* size (0 = byte, 1 = short, 2 = long) */
902 false, /* pc_relative */
904 complain_overflow_signed
, /* complain_on_overflow */
905 mips32_64bit_reloc
, /* special_function */
906 "R_MIPS_64", /* name */
907 true, /* partial_inplace */
908 0xffffffff, /* src_mask */
909 0xffffffff, /* dst_mask */
910 false); /* pcrel_offset */
912 /* The reloc used for the mips16 jump instruction. */
913 static reloc_howto_type elf_mips16_jump_howto
=
914 HOWTO (R_MIPS16_26
, /* type */
916 2, /* size (0 = byte, 1 = short, 2 = long) */
918 false, /* pc_relative */
920 complain_overflow_dont
, /* complain_on_overflow */
921 /* This needs complex overflow
922 detection, because the upper four
923 bits must match the PC. */
924 mips16_jump_reloc
, /* special_function */
925 "R_MIPS16_26", /* name */
926 true, /* partial_inplace */
927 0x3ffffff, /* src_mask */
928 0x3ffffff, /* dst_mask */
929 false); /* pcrel_offset */
931 /* The reloc used for the mips16 gprel instruction. */
932 static reloc_howto_type elf_mips16_gprel_howto
=
933 HOWTO (R_MIPS16_GPREL
, /* type */
935 2, /* size (0 = byte, 1 = short, 2 = long) */
937 false, /* pc_relative */
939 complain_overflow_signed
, /* complain_on_overflow */
940 mips16_gprel_reloc
, /* special_function */
941 "R_MIPS16_GPREL", /* name */
942 true, /* partial_inplace */
943 0x07ff001f, /* src_mask */
944 0x07ff001f, /* dst_mask */
945 false); /* pcrel_offset */
948 /* GNU extensions for embedded-pic. */
949 /* High 16 bits of symbol value, pc-relative. */
950 static reloc_howto_type elf_mips_gnu_rel_hi16
=
951 HOWTO (R_MIPS_GNU_REL_HI16
, /* type */
953 2, /* size (0 = byte, 1 = short, 2 = long) */
955 true, /* pc_relative */
957 complain_overflow_dont
, /* complain_on_overflow */
958 _bfd_mips_elf_hi16_reloc
, /* special_function */
959 "R_MIPS_GNU_REL_HI16", /* name */
960 true, /* partial_inplace */
961 0xffff, /* src_mask */
962 0xffff, /* dst_mask */
963 true); /* pcrel_offset */
965 /* Low 16 bits of symbol value, pc-relative. */
966 static reloc_howto_type elf_mips_gnu_rel_lo16
=
967 HOWTO (R_MIPS_GNU_REL_LO16
, /* type */
969 2, /* size (0 = byte, 1 = short, 2 = long) */
971 true, /* pc_relative */
973 complain_overflow_dont
, /* complain_on_overflow */
974 _bfd_mips_elf_lo16_reloc
, /* special_function */
975 "R_MIPS_GNU_REL_LO16", /* name */
976 true, /* partial_inplace */
977 0xffff, /* src_mask */
978 0xffff, /* dst_mask */
979 true); /* pcrel_offset */
981 /* 16 bit offset for pc-relative branches. */
982 static reloc_howto_type elf_mips_gnu_rel16_s2
=
983 HOWTO (R_MIPS_GNU_REL16_S2
, /* type */
985 2, /* size (0 = byte, 1 = short, 2 = long) */
987 true, /* pc_relative */
989 complain_overflow_signed
, /* complain_on_overflow */
990 bfd_elf_generic_reloc
, /* special_function */
991 "R_MIPS_GNU_REL16_S2", /* name */
992 true, /* partial_inplace */
993 0xffff, /* src_mask */
994 0xffff, /* dst_mask */
995 true); /* pcrel_offset */
997 /* 64 bit pc-relative. */
998 static reloc_howto_type elf_mips_gnu_pcrel64
=
999 HOWTO (R_MIPS_PC64
, /* type */
1001 4, /* size (0 = byte, 1 = short, 2 = long) */
1003 true, /* pc_relative */
1005 complain_overflow_signed
, /* complain_on_overflow */
1006 bfd_elf_generic_reloc
, /* special_function */
1007 "R_MIPS_PC64", /* name */
1008 true, /* partial_inplace */
1009 MINUS_ONE
, /* src_mask */
1010 MINUS_ONE
, /* dst_mask */
1011 true); /* pcrel_offset */
1013 /* 32 bit pc-relative. */
1014 static reloc_howto_type elf_mips_gnu_pcrel32
=
1015 HOWTO (R_MIPS_PC32
, /* type */
1017 2, /* size (0 = byte, 1 = short, 2 = long) */
1019 true, /* pc_relative */
1021 complain_overflow_signed
, /* complain_on_overflow */
1022 bfd_elf_generic_reloc
, /* special_function */
1023 "R_MIPS_PC32", /* name */
1024 true, /* partial_inplace */
1025 0xffffffff, /* src_mask */
1026 0xffffffff, /* dst_mask */
1027 true); /* pcrel_offset */
1029 /* GNU extension to record C++ vtable hierarchy */
1030 static reloc_howto_type elf_mips_gnu_vtinherit_howto
=
1031 HOWTO (R_MIPS_GNU_VTINHERIT
, /* type */
1033 2, /* size (0 = byte, 1 = short, 2 = long) */
1035 false, /* pc_relative */
1037 complain_overflow_dont
, /* complain_on_overflow */
1038 NULL
, /* special_function */
1039 "R_MIPS_GNU_VTINHERIT", /* name */
1040 false, /* partial_inplace */
1043 false); /* pcrel_offset */
1045 /* GNU extension to record C++ vtable member usage */
1046 static reloc_howto_type elf_mips_gnu_vtentry_howto
=
1047 HOWTO (R_MIPS_GNU_VTENTRY
, /* type */
1049 2, /* size (0 = byte, 1 = short, 2 = long) */
1051 false, /* pc_relative */
1053 complain_overflow_dont
, /* complain_on_overflow */
1054 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
1055 "R_MIPS_GNU_VTENTRY", /* name */
1056 false, /* partial_inplace */
1059 false); /* pcrel_offset */
1061 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
1062 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
1063 the HI16. Here we just save the information we need; we do the
1064 actual relocation when we see the LO16. MIPS ELF requires that the
1065 LO16 immediately follow the HI16. As a GNU extension, we permit an
1066 arbitrary number of HI16 relocs to be associated with a single LO16
1067 reloc. This extension permits gcc to output the HI and LO relocs
1072 struct mips_hi16
*next
;
1077 /* FIXME: This should not be a static variable. */
1079 static struct mips_hi16
*mips_hi16_list
;
1081 bfd_reloc_status_type
1082 _bfd_mips_elf_hi16_reloc (abfd
,
1089 bfd
*abfd ATTRIBUTE_UNUSED
;
1090 arelent
*reloc_entry
;
1093 asection
*input_section
;
1095 char **error_message
;
1097 bfd_reloc_status_type ret
;
1099 struct mips_hi16
*n
;
1101 /* If we're relocating, and this an external symbol, we don't want
1102 to change anything. */
1103 if (output_bfd
!= (bfd
*) NULL
1104 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1105 && reloc_entry
->addend
== 0)
1107 reloc_entry
->address
+= input_section
->output_offset
;
1108 return bfd_reloc_ok
;
1113 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1115 boolean relocateable
;
1118 if (ret
== bfd_reloc_undefined
)
1121 if (output_bfd
!= NULL
)
1122 relocateable
= true;
1125 relocateable
= false;
1126 output_bfd
= symbol
->section
->output_section
->owner
;
1129 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1130 error_message
, &gp
);
1131 if (ret
!= bfd_reloc_ok
)
1134 relocation
= gp
- reloc_entry
->address
;
1138 if (bfd_is_und_section (symbol
->section
)
1139 && output_bfd
== (bfd
*) NULL
)
1140 ret
= bfd_reloc_undefined
;
1142 if (bfd_is_com_section (symbol
->section
))
1145 relocation
= symbol
->value
;
1148 relocation
+= symbol
->section
->output_section
->vma
;
1149 relocation
+= symbol
->section
->output_offset
;
1150 relocation
+= reloc_entry
->addend
;
1152 if (reloc_entry
->address
> input_section
->_cooked_size
)
1153 return bfd_reloc_outofrange
;
1155 /* Save the information, and let LO16 do the actual relocation. */
1156 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
1158 return bfd_reloc_outofrange
;
1159 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
1160 n
->addend
= relocation
;
1161 n
->next
= mips_hi16_list
;
1164 if (output_bfd
!= (bfd
*) NULL
)
1165 reloc_entry
->address
+= input_section
->output_offset
;
1170 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
1171 inplace relocation; this function exists in order to do the
1172 R_MIPS_HI16 relocation described above. */
1174 bfd_reloc_status_type
1175 _bfd_mips_elf_lo16_reloc (abfd
,
1183 arelent
*reloc_entry
;
1186 asection
*input_section
;
1188 char **error_message
;
1190 arelent gp_disp_relent
;
1192 if (mips_hi16_list
!= NULL
)
1194 struct mips_hi16
*l
;
1201 unsigned long vallo
;
1202 struct mips_hi16
*next
;
1204 /* Do the HI16 relocation. Note that we actually don't need
1205 to know anything about the LO16 itself, except where to
1206 find the low 16 bits of the addend needed by the LO16. */
1207 insn
= bfd_get_32 (abfd
, l
->addr
);
1208 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
1210 val
= ((insn
& 0xffff) << 16) + vallo
;
1213 /* The low order 16 bits are always treated as a signed
1214 value. Therefore, a negative value in the low order bits
1215 requires an adjustment in the high order bits. We need
1216 to make this adjustment in two ways: once for the bits we
1217 took from the data, and once for the bits we are putting
1218 back in to the data. */
1219 if ((vallo
& 0x8000) != 0)
1221 if ((val
& 0x8000) != 0)
1224 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
1225 bfd_put_32 (abfd
, insn
, l
->addr
);
1227 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1229 gp_disp_relent
= *reloc_entry
;
1230 reloc_entry
= &gp_disp_relent
;
1231 reloc_entry
->addend
= l
->addend
;
1239 mips_hi16_list
= NULL
;
1241 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1243 bfd_reloc_status_type ret
;
1244 bfd_vma gp
, relocation
;
1246 /* FIXME: Does this case ever occur? */
1248 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
1249 if (ret
!= bfd_reloc_ok
)
1252 relocation
= gp
- reloc_entry
->address
;
1253 relocation
+= symbol
->section
->output_section
->vma
;
1254 relocation
+= symbol
->section
->output_offset
;
1255 relocation
+= reloc_entry
->addend
;
1257 if (reloc_entry
->address
> input_section
->_cooked_size
)
1258 return bfd_reloc_outofrange
;
1260 gp_disp_relent
= *reloc_entry
;
1261 reloc_entry
= &gp_disp_relent
;
1262 reloc_entry
->addend
= relocation
- 4;
1265 /* Now do the LO16 reloc in the usual way. */
1266 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1267 input_section
, output_bfd
, error_message
);
1270 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1271 table used for PIC code. If the symbol is an external symbol, the
1272 instruction is modified to contain the offset of the appropriate
1273 entry in the global offset table. If the symbol is a section
1274 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1275 addends are combined to form the real addend against the section
1276 symbol; the GOT16 is modified to contain the offset of an entry in
1277 the global offset table, and the LO16 is modified to offset it
1278 appropriately. Thus an offset larger than 16 bits requires a
1279 modified value in the global offset table.
1281 This implementation suffices for the assembler, but the linker does
1282 not yet know how to create global offset tables. */
1284 bfd_reloc_status_type
1285 _bfd_mips_elf_got16_reloc (abfd
,
1293 arelent
*reloc_entry
;
1296 asection
*input_section
;
1298 char **error_message
;
1300 /* If we're relocating, and this an external symbol, we don't want
1301 to change anything. */
1302 if (output_bfd
!= (bfd
*) NULL
1303 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1304 && reloc_entry
->addend
== 0)
1306 reloc_entry
->address
+= input_section
->output_offset
;
1307 return bfd_reloc_ok
;
1310 /* If we're relocating, and this is a local symbol, we can handle it
1312 if (output_bfd
!= (bfd
*) NULL
1313 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1314 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1315 input_section
, output_bfd
, error_message
);
1320 /* Set the GP value for OUTPUT_BFD. Returns false if this is a
1321 dangerous relocation. */
1324 mips_elf_assign_gp (output_bfd
, pgp
)
1332 /* If we've already figured out what GP will be, just return it. */
1333 *pgp
= _bfd_get_gp_value (output_bfd
);
1337 count
= bfd_get_symcount (output_bfd
);
1338 sym
= bfd_get_outsymbols (output_bfd
);
1340 /* The linker script will have created a symbol named `_gp' with the
1341 appropriate value. */
1342 if (sym
== (asymbol
**) NULL
)
1346 for (i
= 0; i
< count
; i
++, sym
++)
1348 register CONST
char *name
;
1350 name
= bfd_asymbol_name (*sym
);
1351 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1353 *pgp
= bfd_asymbol_value (*sym
);
1354 _bfd_set_gp_value (output_bfd
, *pgp
);
1362 /* Only get the error once. */
1364 _bfd_set_gp_value (output_bfd
, *pgp
);
1371 /* We have to figure out the gp value, so that we can adjust the
1372 symbol value correctly. We look up the symbol _gp in the output
1373 BFD. If we can't find it, we're stuck. We cache it in the ELF
1374 target data. We don't need to adjust the symbol value for an
1375 external symbol if we are producing relocateable output. */
1377 static bfd_reloc_status_type
1378 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1381 boolean relocateable
;
1382 char **error_message
;
1385 if (bfd_is_und_section (symbol
->section
)
1389 return bfd_reloc_undefined
;
1392 *pgp
= _bfd_get_gp_value (output_bfd
);
1395 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1399 /* Make up a value. */
1400 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1401 _bfd_set_gp_value (output_bfd
, *pgp
);
1403 else if (!mips_elf_assign_gp (output_bfd
, pgp
))
1406 (char *) _("GP relative relocation when _gp not defined");
1407 return bfd_reloc_dangerous
;
1411 return bfd_reloc_ok
;
1414 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1415 become the offset from the gp register. This function also handles
1416 R_MIPS_LITERAL relocations, although those can be handled more
1417 cleverly because the entries in the .lit8 and .lit4 sections can be
1420 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1421 arelent
*, asection
*,
1422 boolean
, PTR
, bfd_vma
));
1424 bfd_reloc_status_type
1425 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1426 output_bfd
, error_message
)
1428 arelent
*reloc_entry
;
1431 asection
*input_section
;
1433 char **error_message
;
1435 boolean relocateable
;
1436 bfd_reloc_status_type ret
;
1439 /* If we're relocating, and this is an external symbol with no
1440 addend, we don't want to change anything. We will only have an
1441 addend if this is a newly created reloc, not read from an ELF
1443 if (output_bfd
!= (bfd
*) NULL
1444 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1445 && reloc_entry
->addend
== 0)
1447 reloc_entry
->address
+= input_section
->output_offset
;
1448 return bfd_reloc_ok
;
1451 if (output_bfd
!= (bfd
*) NULL
)
1452 relocateable
= true;
1455 relocateable
= false;
1456 output_bfd
= symbol
->section
->output_section
->owner
;
1459 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1461 if (ret
!= bfd_reloc_ok
)
1464 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1465 relocateable
, data
, gp
);
1468 static bfd_reloc_status_type
1469 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1473 arelent
*reloc_entry
;
1474 asection
*input_section
;
1475 boolean relocateable
;
1483 if (bfd_is_com_section (symbol
->section
))
1486 relocation
= symbol
->value
;
1488 relocation
+= symbol
->section
->output_section
->vma
;
1489 relocation
+= symbol
->section
->output_offset
;
1491 if (reloc_entry
->address
> input_section
->_cooked_size
)
1492 return bfd_reloc_outofrange
;
1494 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1496 /* Set val to the offset into the section or symbol. */
1497 if (reloc_entry
->howto
->src_mask
== 0)
1499 /* This case occurs with the 64-bit MIPS ELF ABI. */
1500 val
= reloc_entry
->addend
;
1504 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1509 /* Adjust val for the final section location and GP value. If we
1510 are producing relocateable output, we don't want to do this for
1511 an external symbol. */
1513 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1514 val
+= relocation
- gp
;
1516 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1517 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1520 reloc_entry
->address
+= input_section
->output_offset
;
1522 /* Make sure it fit in 16 bits. */
1523 if ((long) val
>= 0x8000 || (long) val
< -0x8000)
1524 return bfd_reloc_overflow
;
1526 return bfd_reloc_ok
;
1529 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1530 from the gp register? XXX */
1532 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1533 arelent
*, asection
*,
1534 boolean
, PTR
, bfd_vma
));
1536 bfd_reloc_status_type
1537 _bfd_mips_elf_gprel32_reloc (abfd
,
1545 arelent
*reloc_entry
;
1548 asection
*input_section
;
1550 char **error_message
;
1552 boolean relocateable
;
1553 bfd_reloc_status_type ret
;
1556 /* If we're relocating, and this is an external symbol with no
1557 addend, we don't want to change anything. We will only have an
1558 addend if this is a newly created reloc, not read from an ELF
1560 if (output_bfd
!= (bfd
*) NULL
1561 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1562 && reloc_entry
->addend
== 0)
1564 *error_message
= (char *)
1565 _("32bits gp relative relocation occurs for an external symbol");
1566 return bfd_reloc_outofrange
;
1569 if (output_bfd
!= (bfd
*) NULL
)
1571 relocateable
= true;
1572 gp
= _bfd_get_gp_value (output_bfd
);
1576 relocateable
= false;
1577 output_bfd
= symbol
->section
->output_section
->owner
;
1579 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1580 error_message
, &gp
);
1581 if (ret
!= bfd_reloc_ok
)
1585 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1586 relocateable
, data
, gp
);
1589 static bfd_reloc_status_type
1590 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1594 arelent
*reloc_entry
;
1595 asection
*input_section
;
1596 boolean relocateable
;
1603 if (bfd_is_com_section (symbol
->section
))
1606 relocation
= symbol
->value
;
1608 relocation
+= symbol
->section
->output_section
->vma
;
1609 relocation
+= symbol
->section
->output_offset
;
1611 if (reloc_entry
->address
> input_section
->_cooked_size
)
1612 return bfd_reloc_outofrange
;
1614 if (reloc_entry
->howto
->src_mask
== 0)
1616 /* This case arises with the 64-bit MIPS ELF ABI. */
1620 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1622 /* Set val to the offset into the section or symbol. */
1623 val
+= reloc_entry
->addend
;
1625 /* Adjust val for the final section location and GP value. If we
1626 are producing relocateable output, we don't want to do this for
1627 an external symbol. */
1629 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1630 val
+= relocation
- gp
;
1632 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1635 reloc_entry
->address
+= input_section
->output_offset
;
1637 return bfd_reloc_ok
;
1640 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1641 generated when addreses are 64 bits. The upper 32 bits are a simle
1644 static bfd_reloc_status_type
1645 mips32_64bit_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 bfd_reloc_status_type r
;
1660 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1661 input_section
, output_bfd
, error_message
);
1662 if (r
!= bfd_reloc_continue
)
1665 /* Do a normal 32 bit relocation on the lower 32 bits. */
1666 reloc32
= *reloc_entry
;
1667 if (bfd_big_endian (abfd
))
1668 reloc32
.address
+= 4;
1669 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1670 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1671 output_bfd
, error_message
);
1673 /* Sign extend into the upper 32 bits. */
1674 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1675 if ((val
& 0x80000000) != 0)
1679 addr
= reloc_entry
->address
;
1680 if (bfd_little_endian (abfd
))
1682 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1687 /* Handle a mips16 jump. */
1689 static bfd_reloc_status_type
1690 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1691 output_bfd
, error_message
)
1692 bfd
*abfd ATTRIBUTE_UNUSED
;
1693 arelent
*reloc_entry
;
1695 PTR data ATTRIBUTE_UNUSED
;
1696 asection
*input_section
;
1698 char **error_message ATTRIBUTE_UNUSED
;
1700 if (output_bfd
!= (bfd
*) NULL
1701 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1702 && reloc_entry
->addend
== 0)
1704 reloc_entry
->address
+= input_section
->output_offset
;
1705 return bfd_reloc_ok
;
1710 static boolean warned
;
1713 (*_bfd_error_handler
)
1714 (_("Linking mips16 objects into %s format is not supported"),
1715 bfd_get_target (input_section
->output_section
->owner
));
1719 return bfd_reloc_undefined
;
1722 /* Handle a mips16 GP relative reloc. */
1724 static bfd_reloc_status_type
1725 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1726 output_bfd
, error_message
)
1728 arelent
*reloc_entry
;
1731 asection
*input_section
;
1733 char **error_message
;
1735 boolean relocateable
;
1736 bfd_reloc_status_type ret
;
1738 unsigned short extend
, insn
;
1739 unsigned long final
;
1741 /* If we're relocating, and this is an external symbol with no
1742 addend, we don't want to change anything. We will only have an
1743 addend if this is a newly created reloc, not read from an ELF
1745 if (output_bfd
!= NULL
1746 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1747 && reloc_entry
->addend
== 0)
1749 reloc_entry
->address
+= input_section
->output_offset
;
1750 return bfd_reloc_ok
;
1753 if (output_bfd
!= NULL
)
1754 relocateable
= true;
1757 relocateable
= false;
1758 output_bfd
= symbol
->section
->output_section
->owner
;
1761 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1763 if (ret
!= bfd_reloc_ok
)
1766 if (reloc_entry
->address
> input_section
->_cooked_size
)
1767 return bfd_reloc_outofrange
;
1769 /* Pick up the mips16 extend instruction and the real instruction. */
1770 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1771 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1773 /* Stuff the current addend back as a 32 bit value, do the usual
1774 relocation, and then clean up. */
1776 (((extend
& 0x1f) << 11)
1779 (bfd_byte
*) data
+ reloc_entry
->address
);
1781 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1782 relocateable
, data
, gp
);
1784 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1787 | ((final
>> 11) & 0x1f)
1789 (bfd_byte
*) data
+ reloc_entry
->address
);
1793 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1798 /* Return the ISA for a MIPS e_flags value. */
1801 elf_mips_isa (flags
)
1804 switch (flags
& EF_MIPS_ARCH
)
1818 /* Return the MACH for a MIPS e_flags value. */
1821 elf_mips_mach (flags
)
1824 switch (flags
& EF_MIPS_MACH
)
1826 case E_MIPS_MACH_3900
:
1827 return bfd_mach_mips3900
;
1829 case E_MIPS_MACH_4010
:
1830 return bfd_mach_mips4010
;
1832 case E_MIPS_MACH_4100
:
1833 return bfd_mach_mips4100
;
1835 case E_MIPS_MACH_4111
:
1836 return bfd_mach_mips4111
;
1838 case E_MIPS_MACH_4650
:
1839 return bfd_mach_mips4650
;
1842 switch (flags
& EF_MIPS_ARCH
)
1846 return bfd_mach_mips3000
;
1850 return bfd_mach_mips6000
;
1854 return bfd_mach_mips4000
;
1858 return bfd_mach_mips8000
;
1866 /* Return printable name for ABI. */
1869 elf_mips_abi_name (abfd
)
1874 if (ABI_N32_P (abfd
))
1876 else if (ABI_64_P (abfd
))
1879 flags
= elf_elfheader (abfd
)->e_flags
;
1880 switch (flags
& EF_MIPS_ABI
)
1884 case E_MIPS_ABI_O32
:
1886 case E_MIPS_ABI_O64
:
1888 case E_MIPS_ABI_EABI32
:
1890 case E_MIPS_ABI_EABI64
:
1893 return "unknown abi";
1897 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1899 struct elf_reloc_map
{
1900 bfd_reloc_code_real_type bfd_reloc_val
;
1901 enum elf_mips_reloc_type elf_reloc_val
;
1904 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1906 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1907 { BFD_RELOC_16
, R_MIPS_16
},
1908 { BFD_RELOC_32
, R_MIPS_32
},
1909 { BFD_RELOC_64
, R_MIPS_64
},
1910 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1911 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1912 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1913 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1914 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1915 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1916 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1917 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1918 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1919 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1920 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1921 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1922 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
},
1923 { BFD_RELOC_MIPS_SUB
, R_MIPS_SUB
},
1924 { BFD_RELOC_MIPS_GOT_PAGE
, R_MIPS_GOT_PAGE
},
1925 { BFD_RELOC_MIPS_GOT_OFST
, R_MIPS_GOT_OFST
},
1926 { BFD_RELOC_MIPS_GOT_DISP
, R_MIPS_GOT_DISP
}
1929 /* Given a BFD reloc type, return a howto structure. */
1931 static reloc_howto_type
*
1932 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1934 bfd_reloc_code_real_type code
;
1938 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1940 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1941 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1947 bfd_set_error (bfd_error_bad_value
);
1950 case BFD_RELOC_CTOR
:
1951 /* We need to handle BFD_RELOC_CTOR specially.
1952 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1953 size of addresses on this architecture. */
1954 if (bfd_arch_bits_per_address (abfd
) == 32)
1955 return &elf_mips_howto_table
[(int) R_MIPS_32
];
1957 return &elf_mips_ctor64_howto
;
1959 case BFD_RELOC_MIPS16_JMP
:
1960 return &elf_mips16_jump_howto
;
1961 case BFD_RELOC_MIPS16_GPREL
:
1962 return &elf_mips16_gprel_howto
;
1963 case BFD_RELOC_VTABLE_INHERIT
:
1964 return &elf_mips_gnu_vtinherit_howto
;
1965 case BFD_RELOC_VTABLE_ENTRY
:
1966 return &elf_mips_gnu_vtentry_howto
;
1967 case BFD_RELOC_PCREL_HI16_S
:
1968 return &elf_mips_gnu_rel_hi16
;
1969 case BFD_RELOC_PCREL_LO16
:
1970 return &elf_mips_gnu_rel_lo16
;
1971 case BFD_RELOC_16_PCREL_S2
:
1972 return &elf_mips_gnu_rel16_s2
;
1973 case BFD_RELOC_64_PCREL
:
1974 return &elf_mips_gnu_pcrel64
;
1975 case BFD_RELOC_32_PCREL
:
1976 return &elf_mips_gnu_pcrel32
;
1980 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
1982 static reloc_howto_type
*
1983 mips_rtype_to_howto (r_type
)
1984 unsigned int r_type
;
1989 return &elf_mips16_jump_howto
;
1991 case R_MIPS16_GPREL
:
1992 return &elf_mips16_gprel_howto
;
1994 case R_MIPS_GNU_VTINHERIT
:
1995 return &elf_mips_gnu_vtinherit_howto
;
1997 case R_MIPS_GNU_VTENTRY
:
1998 return &elf_mips_gnu_vtentry_howto
;
2000 case R_MIPS_GNU_REL_HI16
:
2001 return &elf_mips_gnu_rel_hi16
;
2003 case R_MIPS_GNU_REL_LO16
:
2004 return &elf_mips_gnu_rel_lo16
;
2006 case R_MIPS_GNU_REL16_S2
:
2007 return &elf_mips_gnu_rel16_s2
;
2010 return &elf_mips_gnu_pcrel64
;
2013 return &elf_mips_gnu_pcrel32
;
2017 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
2018 return &elf_mips_howto_table
[r_type
];
2023 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
2026 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
2029 Elf32_Internal_Rel
*dst
;
2031 unsigned int r_type
;
2033 r_type
= ELF32_R_TYPE (dst
->r_info
);
2034 cache_ptr
->howto
= mips_rtype_to_howto (r_type
);
2036 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
2037 value for the object file. We get the addend now, rather than
2038 when we do the relocation, because the symbol manipulations done
2039 by the linker may cause us to lose track of the input BFD. */
2040 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
2041 && (r_type
== (unsigned int) R_MIPS_GPREL16
2042 || r_type
== (unsigned int) R_MIPS_LITERAL
))
2043 cache_ptr
->addend
= elf_gp (abfd
);
2046 /* Given a MIPS Elf32_Internal_Rela, fill in an arelent structure. */
2049 mips_info_to_howto_rela (abfd
, cache_ptr
, dst
)
2052 Elf32_Internal_Rela
*dst
;
2054 /* Since an Elf32_Internal_Rel is an initial prefix of an
2055 Elf32_Internal_Rela, we can just use mips_info_to_howto_rel
2057 mips_info_to_howto_rel (abfd
, cache_ptr
, (Elf32_Internal_Rel
*) dst
);
2059 /* If we ever need to do any extra processing with dst->r_addend
2060 (the field omitted in an Elf32_Internal_Rel) we can do it here. */
2063 /* A .reginfo section holds a single Elf32_RegInfo structure. These
2064 routines swap this structure in and out. They are used outside of
2065 BFD, so they are globally visible. */
2068 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
2070 const Elf32_External_RegInfo
*ex
;
2073 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
2074 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
2075 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
2076 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
2077 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
2078 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
2082 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
2084 const Elf32_RegInfo
*in
;
2085 Elf32_External_RegInfo
*ex
;
2087 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
2088 (bfd_byte
*) ex
->ri_gprmask
);
2089 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
2090 (bfd_byte
*) ex
->ri_cprmask
[0]);
2091 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
2092 (bfd_byte
*) ex
->ri_cprmask
[1]);
2093 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
2094 (bfd_byte
*) ex
->ri_cprmask
[2]);
2095 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
2096 (bfd_byte
*) ex
->ri_cprmask
[3]);
2097 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
2098 (bfd_byte
*) ex
->ri_gp_value
);
2101 /* In the 64 bit ABI, the .MIPS.options section holds register
2102 information in an Elf64_Reginfo structure. These routines swap
2103 them in and out. They are globally visible because they are used
2104 outside of BFD. These routines are here so that gas can call them
2105 without worrying about whether the 64 bit ABI has been included. */
2108 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
2110 const Elf64_External_RegInfo
*ex
;
2111 Elf64_Internal_RegInfo
*in
;
2113 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
2114 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
2115 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
2116 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
2117 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
2118 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
2119 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
2123 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
2125 const Elf64_Internal_RegInfo
*in
;
2126 Elf64_External_RegInfo
*ex
;
2128 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
2129 (bfd_byte
*) ex
->ri_gprmask
);
2130 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
2131 (bfd_byte
*) ex
->ri_pad
);
2132 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
2133 (bfd_byte
*) ex
->ri_cprmask
[0]);
2134 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
2135 (bfd_byte
*) ex
->ri_cprmask
[1]);
2136 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
2137 (bfd_byte
*) ex
->ri_cprmask
[2]);
2138 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
2139 (bfd_byte
*) ex
->ri_cprmask
[3]);
2140 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
2141 (bfd_byte
*) ex
->ri_gp_value
);
2144 /* Swap an entry in a .gptab section. Note that these routines rely
2145 on the equivalence of the two elements of the union. */
2148 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
2150 const Elf32_External_gptab
*ex
;
2153 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
2154 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
2158 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
2160 const Elf32_gptab
*in
;
2161 Elf32_External_gptab
*ex
;
2163 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
2164 ex
->gt_entry
.gt_g_value
);
2165 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
2166 ex
->gt_entry
.gt_bytes
);
2170 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
2172 const Elf32_compact_rel
*in
;
2173 Elf32_External_compact_rel
*ex
;
2175 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
2176 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
2177 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
2178 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
2179 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
2180 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
2184 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
2186 const Elf32_crinfo
*in
;
2187 Elf32_External_crinfo
*ex
;
2191 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
2192 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
2193 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
2194 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
2195 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
2196 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
2197 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
2200 /* Swap in an options header. */
2203 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
2205 const Elf_External_Options
*ex
;
2206 Elf_Internal_Options
*in
;
2208 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
2209 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
2210 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
2211 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
2214 /* Swap out an options header. */
2217 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
2219 const Elf_Internal_Options
*in
;
2220 Elf_External_Options
*ex
;
2222 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
2223 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
2224 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
2225 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
2228 /* Swap in an MSYM entry. */
2231 bfd_mips_elf_swap_msym_in (abfd
, ex
, in
)
2233 const Elf32_External_Msym
*ex
;
2234 Elf32_Internal_Msym
*in
;
2236 in
->ms_hash_value
= bfd_h_get_32 (abfd
, ex
->ms_hash_value
);
2237 in
->ms_info
= bfd_h_get_32 (abfd
, ex
->ms_info
);
2240 /* Swap out an MSYM entry. */
2243 bfd_mips_elf_swap_msym_out (abfd
, in
, ex
)
2245 const Elf32_Internal_Msym
*in
;
2246 Elf32_External_Msym
*ex
;
2248 bfd_h_put_32 (abfd
, in
->ms_hash_value
, ex
->ms_hash_value
);
2249 bfd_h_put_32 (abfd
, in
->ms_info
, ex
->ms_info
);
2253 /* Determine whether a symbol is global for the purposes of splitting
2254 the symbol table into global symbols and local symbols. At least
2255 on Irix 5, this split must be between section symbols and all other
2256 symbols. On most ELF targets the split is between static symbols
2257 and externally visible symbols. */
2261 mips_elf_sym_is_global (abfd
, sym
)
2262 bfd
*abfd ATTRIBUTE_UNUSED
;
2265 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
2268 /* Set the right machine number for a MIPS ELF file. This is used for
2269 both the 32-bit and the 64-bit ABI. */
2272 _bfd_mips_elf_object_p (abfd
)
2275 /* Irix 5 and 6 is broken. Object file symbol tables are not always
2276 sorted correctly such that local symbols precede global symbols,
2277 and the sh_info field in the symbol table is not always right. */
2278 elf_bad_symtab (abfd
) = true;
2280 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
,
2281 elf_mips_mach (elf_elfheader (abfd
)->e_flags
));
2285 /* The final processing done just before writing out a MIPS ELF object
2286 file. This gets the MIPS architecture right based on the machine
2287 number. This is used by both the 32-bit and the 64-bit ABI. */
2291 _bfd_mips_elf_final_write_processing (abfd
, linker
)
2293 boolean linker ATTRIBUTE_UNUSED
;
2297 Elf_Internal_Shdr
**hdrpp
;
2301 switch (bfd_get_mach (abfd
))
2304 case bfd_mach_mips3000
:
2305 val
= E_MIPS_ARCH_1
;
2308 case bfd_mach_mips3900
:
2309 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
2312 case bfd_mach_mips6000
:
2313 val
= E_MIPS_ARCH_2
;
2316 case bfd_mach_mips4000
:
2317 case bfd_mach_mips4300
:
2318 val
= E_MIPS_ARCH_3
;
2321 case bfd_mach_mips4010
:
2322 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
2325 case bfd_mach_mips4100
:
2326 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
2329 case bfd_mach_mips4111
:
2330 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
2333 case bfd_mach_mips4650
:
2334 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
2337 case bfd_mach_mips8000
:
2338 val
= E_MIPS_ARCH_4
;
2342 elf_elfheader (abfd
)->e_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2343 elf_elfheader (abfd
)->e_flags
|= val
;
2345 /* Set the sh_info field for .gptab sections and other appropriate
2346 info for each special section. */
2347 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
2348 i
< elf_elfheader (abfd
)->e_shnum
;
2351 switch ((*hdrpp
)->sh_type
)
2354 case SHT_MIPS_LIBLIST
:
2355 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
2357 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2360 case SHT_MIPS_GPTAB
:
2361 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2362 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2363 BFD_ASSERT (name
!= NULL
2364 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
2365 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
2366 BFD_ASSERT (sec
!= NULL
);
2367 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2370 case SHT_MIPS_CONTENT
:
2371 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2372 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2373 BFD_ASSERT (name
!= NULL
2374 && strncmp (name
, ".MIPS.content",
2375 sizeof ".MIPS.content" - 1) == 0);
2376 sec
= bfd_get_section_by_name (abfd
,
2377 name
+ sizeof ".MIPS.content" - 1);
2378 BFD_ASSERT (sec
!= NULL
);
2379 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2382 case SHT_MIPS_SYMBOL_LIB
:
2383 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
2385 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2386 sec
= bfd_get_section_by_name (abfd
, ".liblist");
2388 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2391 case SHT_MIPS_EVENTS
:
2392 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2393 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2394 BFD_ASSERT (name
!= NULL
);
2395 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
2396 sec
= bfd_get_section_by_name (abfd
,
2397 name
+ sizeof ".MIPS.events" - 1);
2400 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
2401 sizeof ".MIPS.post_rel" - 1) == 0);
2402 sec
= bfd_get_section_by_name (abfd
,
2404 + sizeof ".MIPS.post_rel" - 1));
2406 BFD_ASSERT (sec
!= NULL
);
2407 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2414 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
2417 _bfd_mips_elf_set_private_flags (abfd
, flags
)
2421 BFD_ASSERT (!elf_flags_init (abfd
)
2422 || elf_elfheader (abfd
)->e_flags
== flags
);
2424 elf_elfheader (abfd
)->e_flags
= flags
;
2425 elf_flags_init (abfd
) = true;
2429 /* Copy backend specific data from one object module to another */
2432 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
2436 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2437 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2440 BFD_ASSERT (!elf_flags_init (obfd
)
2441 || (elf_elfheader (obfd
)->e_flags
2442 == elf_elfheader (ibfd
)->e_flags
));
2444 elf_gp (obfd
) = elf_gp (ibfd
);
2445 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
2446 elf_flags_init (obfd
) = true;
2450 /* Merge backend specific data from an object file to the output
2451 object file when linking. */
2454 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
2462 /* Check if we have the same endianess */
2463 if (_bfd_generic_verify_endian_match (ibfd
, obfd
) == false)
2466 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2467 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2470 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2471 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
2472 old_flags
= elf_elfheader (obfd
)->e_flags
;
2474 if (! elf_flags_init (obfd
))
2476 elf_flags_init (obfd
) = true;
2477 elf_elfheader (obfd
)->e_flags
= new_flags
;
2478 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
2479 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
2481 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2482 && bfd_get_arch_info (obfd
)->the_default
)
2484 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
2485 bfd_get_mach (ibfd
)))
2492 /* Check flag compatibility. */
2494 new_flags
&= ~EF_MIPS_NOREORDER
;
2495 old_flags
&= ~EF_MIPS_NOREORDER
;
2497 if (new_flags
== old_flags
)
2502 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
2504 new_flags
&= ~EF_MIPS_PIC
;
2505 old_flags
&= ~EF_MIPS_PIC
;
2506 (*_bfd_error_handler
)
2507 (_("%s: linking PIC files with non-PIC files"),
2508 bfd_get_filename (ibfd
));
2512 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
2514 new_flags
&= ~EF_MIPS_CPIC
;
2515 old_flags
&= ~EF_MIPS_CPIC
;
2516 (*_bfd_error_handler
)
2517 (_("%s: linking abicalls files with non-abicalls files"),
2518 bfd_get_filename (ibfd
));
2522 /* Compare the ISA's. */
2523 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
2524 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
2526 int new_mach
= new_flags
& EF_MIPS_MACH
;
2527 int old_mach
= old_flags
& EF_MIPS_MACH
;
2528 int new_isa
= elf_mips_isa (new_flags
);
2529 int old_isa
= elf_mips_isa (old_flags
);
2531 /* If either has no machine specified, just compare the general isa's.
2532 Some combinations of machines are ok, if the isa's match. */
2535 || new_mach
== old_mach
2538 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
2539 and -mips4 code. They will normally use the same data sizes and
2540 calling conventions. */
2542 if ((new_isa
== 1 || new_isa
== 2)
2543 ? (old_isa
!= 1 && old_isa
!= 2)
2544 : (old_isa
== 1 || old_isa
== 2))
2546 (*_bfd_error_handler
)
2547 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
2548 bfd_get_filename (ibfd
), new_isa
, old_isa
);
2555 (*_bfd_error_handler
)
2556 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
2557 bfd_get_filename (ibfd
),
2558 elf_mips_mach (new_flags
),
2559 elf_mips_mach (old_flags
));
2563 new_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2564 old_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2567 /* Compare ABI's. The 64-bit ABI does not use EF_MIPS_ABI. But, it
2568 does set EI_CLASS differently from any 32-bit ABI. */
2569 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
2570 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
2571 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
2573 /* Only error if both are set (to different values). */
2574 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
2575 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
2576 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
2578 (*_bfd_error_handler
)
2579 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
2580 bfd_get_filename (ibfd
),
2581 elf_mips_abi_name (ibfd
),
2582 elf_mips_abi_name (obfd
));
2585 new_flags
&= ~EF_MIPS_ABI
;
2586 old_flags
&= ~EF_MIPS_ABI
;
2589 /* Warn about any other mismatches */
2590 if (new_flags
!= old_flags
)
2592 (*_bfd_error_handler
)
2593 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2594 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
2595 (unsigned long) old_flags
);
2601 bfd_set_error (bfd_error_bad_value
);
2609 _bfd_mips_elf_print_private_bfd_data (abfd
, ptr
)
2613 FILE *file
= (FILE *) ptr
;
2615 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
2617 /* Print normal ELF private data. */
2618 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
2620 /* xgettext:c-format */
2621 fprintf (file
, _ ("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
2623 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
2624 fprintf (file
, _ (" [abi=O32]"));
2625 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
2626 fprintf (file
, _ (" [abi=O64]"));
2627 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
2628 fprintf (file
, _ (" [abi=EABI32]"));
2629 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
2630 fprintf (file
, _ (" [abi=EABI64]"));
2631 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
2632 fprintf (file
, _ (" [abi unknown]"));
2633 else if (ABI_N32_P (abfd
))
2634 fprintf (file
, _ (" [abi=N32]"));
2635 else if (ABI_64_P (abfd
))
2636 fprintf (file
, _ (" [abi=64]"));
2638 fprintf (file
, _ (" [no abi set]"));
2640 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
2641 fprintf (file
, _ (" [mips1]"));
2642 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
2643 fprintf (file
, _ (" [mips2]"));
2644 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
2645 fprintf (file
, _ (" [mips3]"));
2646 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
2647 fprintf (file
, _ (" [mips4]"));
2649 fprintf (file
, _ (" [unknown ISA]"));
2651 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
2652 fprintf (file
, _ (" [32bitmode]"));
2654 fprintf (file
, _ (" [not 32bitmode]"));
2661 /* Handle a MIPS specific section when reading an object file. This
2662 is called when elfcode.h finds a section with an unknown type.
2663 This routine supports both the 32-bit and 64-bit ELF ABI.
2665 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2669 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
2671 Elf_Internal_Shdr
*hdr
;
2676 /* There ought to be a place to keep ELF backend specific flags, but
2677 at the moment there isn't one. We just keep track of the
2678 sections by their name, instead. Fortunately, the ABI gives
2679 suggested names for all the MIPS specific sections, so we will
2680 probably get away with this. */
2681 switch (hdr
->sh_type
)
2683 case SHT_MIPS_LIBLIST
:
2684 if (strcmp (name
, ".liblist") != 0)
2688 if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) != 0)
2691 case SHT_MIPS_CONFLICT
:
2692 if (strcmp (name
, ".conflict") != 0)
2695 case SHT_MIPS_GPTAB
:
2696 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
2699 case SHT_MIPS_UCODE
:
2700 if (strcmp (name
, ".ucode") != 0)
2703 case SHT_MIPS_DEBUG
:
2704 if (strcmp (name
, ".mdebug") != 0)
2706 flags
= SEC_DEBUGGING
;
2708 case SHT_MIPS_REGINFO
:
2709 if (strcmp (name
, ".reginfo") != 0
2710 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
2712 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
2714 case SHT_MIPS_IFACE
:
2715 if (strcmp (name
, ".MIPS.interfaces") != 0)
2718 case SHT_MIPS_CONTENT
:
2719 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2722 case SHT_MIPS_OPTIONS
:
2723 if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) != 0)
2726 case SHT_MIPS_DWARF
:
2727 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2730 case SHT_MIPS_SYMBOL_LIB
:
2731 if (strcmp (name
, ".MIPS.symlib") != 0)
2734 case SHT_MIPS_EVENTS
:
2735 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2736 && strncmp (name
, ".MIPS.post_rel",
2737 sizeof ".MIPS.post_rel" - 1) != 0)
2744 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2749 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
2750 (bfd_get_section_flags (abfd
,
2756 /* FIXME: We should record sh_info for a .gptab section. */
2758 /* For a .reginfo section, set the gp value in the tdata information
2759 from the contents of this section. We need the gp value while
2760 processing relocs, so we just get it now. The .reginfo section
2761 is not used in the 64-bit MIPS ELF ABI. */
2762 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2764 Elf32_External_RegInfo ext
;
2767 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
2768 (file_ptr
) 0, sizeof ext
))
2770 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
2771 elf_gp (abfd
) = s
.ri_gp_value
;
2774 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2775 set the gp value based on what we find. We may see both
2776 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2777 they should agree. */
2778 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
2780 bfd_byte
*contents
, *l
, *lend
;
2782 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
2783 if (contents
== NULL
)
2785 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
2786 (file_ptr
) 0, hdr
->sh_size
))
2792 lend
= contents
+ hdr
->sh_size
;
2793 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2795 Elf_Internal_Options intopt
;
2797 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2799 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
2801 Elf64_Internal_RegInfo intreg
;
2803 bfd_mips_elf64_swap_reginfo_in
2805 ((Elf64_External_RegInfo
*)
2806 (l
+ sizeof (Elf_External_Options
))),
2808 elf_gp (abfd
) = intreg
.ri_gp_value
;
2810 else if (intopt
.kind
== ODK_REGINFO
)
2812 Elf32_RegInfo intreg
;
2814 bfd_mips_elf32_swap_reginfo_in
2816 ((Elf32_External_RegInfo
*)
2817 (l
+ sizeof (Elf_External_Options
))),
2819 elf_gp (abfd
) = intreg
.ri_gp_value
;
2829 /* Set the correct type for a MIPS ELF section. We do this by the
2830 section name, which is a hack, but ought to work. This routine is
2831 used by both the 32-bit and the 64-bit ABI. */
2834 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
2836 Elf32_Internal_Shdr
*hdr
;
2839 register const char *name
;
2841 name
= bfd_get_section_name (abfd
, sec
);
2843 if (strcmp (name
, ".liblist") == 0)
2845 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
2846 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
2847 /* The sh_link field is set in final_write_processing. */
2849 else if (strcmp (name
, ".conflict") == 0)
2850 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
2851 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2853 hdr
->sh_type
= SHT_MIPS_GPTAB
;
2854 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
2855 /* The sh_info field is set in final_write_processing. */
2857 else if (strcmp (name
, ".ucode") == 0)
2858 hdr
->sh_type
= SHT_MIPS_UCODE
;
2859 else if (strcmp (name
, ".mdebug") == 0)
2861 hdr
->sh_type
= SHT_MIPS_DEBUG
;
2862 /* In a shared object on Irix 5.3, the .mdebug section has an
2863 entsize of 0. FIXME: Does this matter? */
2864 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2865 hdr
->sh_entsize
= 0;
2867 hdr
->sh_entsize
= 1;
2869 else if (strcmp (name
, ".reginfo") == 0)
2871 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2872 /* In a shared object on Irix 5.3, the .reginfo section has an
2873 entsize of 0x18. FIXME: Does this matter? */
2874 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2875 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2877 hdr
->sh_entsize
= 1;
2879 else if (SGI_COMPAT (abfd
)
2880 && (strcmp (name
, ".hash") == 0
2881 || strcmp (name
, ".dynamic") == 0
2882 || strcmp (name
, ".dynstr") == 0))
2884 hdr
->sh_entsize
= 0;
2886 /* This isn't how the Irix 6 linker behaves. */
2887 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2890 else if (strcmp (name
, ".got") == 0
2891 || strcmp (name
, MIPS_ELF_SRDATA_SECTION_NAME (abfd
)) == 0
2892 || strcmp (name
, ".sdata") == 0
2893 || strcmp (name
, ".sbss") == 0
2894 || strcmp (name
, ".lit4") == 0
2895 || strcmp (name
, ".lit8") == 0)
2896 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2897 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2899 hdr
->sh_type
= SHT_MIPS_IFACE
;
2900 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2902 else if (strncmp (name
, ".MIPS.content", strlen (".MIPS.content")) == 0)
2904 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2905 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2906 /* The sh_info field is set in final_write_processing. */
2908 else if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
2910 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2911 hdr
->sh_entsize
= 1;
2912 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2914 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2915 hdr
->sh_type
= SHT_MIPS_DWARF
;
2916 else if (strcmp (name
, ".MIPS.symlib") == 0)
2918 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2919 /* The sh_link and sh_info fields are set in
2920 final_write_processing. */
2922 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2923 || strncmp (name
, ".MIPS.post_rel",
2924 sizeof ".MIPS.post_rel" - 1) == 0)
2926 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2927 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2928 /* The sh_link field is set in final_write_processing. */
2930 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) == 0)
2932 hdr
->sh_type
= SHT_MIPS_MSYM
;
2933 hdr
->sh_flags
|= SHF_ALLOC
;
2934 hdr
->sh_entsize
= 8;
2937 /* The generic elf_fake_sections will set up REL_HDR using the
2938 default kind of relocations. But, we may actually need both
2939 kinds of relocations, so we set up the second header here. */
2940 if ((sec
->flags
& SEC_RELOC
) != 0)
2942 struct bfd_elf_section_data
*esd
;
2944 esd
= elf_section_data (sec
);
2945 BFD_ASSERT (esd
->rel_hdr2
== NULL
);
2947 = (Elf_Internal_Shdr
*) bfd_zalloc (abfd
, sizeof (Elf_Internal_Shdr
));
2950 _bfd_elf_init_reloc_shdr (abfd
, esd
->rel_hdr2
, sec
,
2951 !elf_section_data (sec
)->use_rela_p
);
2957 /* Given a BFD section, try to locate the corresponding ELF section
2958 index. This is used by both the 32-bit and the 64-bit ABI.
2959 Actually, it's not clear to me that the 64-bit ABI supports these,
2960 but for non-PIC objects we will certainly want support for at least
2961 the .scommon section. */
2964 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2965 bfd
*abfd ATTRIBUTE_UNUSED
;
2966 Elf32_Internal_Shdr
*hdr ATTRIBUTE_UNUSED
;
2970 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2972 *retval
= SHN_MIPS_SCOMMON
;
2975 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2977 *retval
= SHN_MIPS_ACOMMON
;
2983 /* When are writing out the .options or .MIPS.options section,
2984 remember the bytes we are writing out, so that we can install the
2985 GP value in the section_processing routine. */
2988 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2993 bfd_size_type count
;
2995 if (strcmp (section
->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
2999 if (elf_section_data (section
) == NULL
)
3001 section
->used_by_bfd
=
3002 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
3003 if (elf_section_data (section
) == NULL
)
3006 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
3011 if (section
->_cooked_size
!= 0)
3012 size
= section
->_cooked_size
;
3014 size
= section
->_raw_size
;
3015 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
3018 elf_section_data (section
)->tdata
= (PTR
) c
;
3021 memcpy (c
+ offset
, location
, count
);
3024 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
3028 /* Work over a section just before writing it out. This routine is
3029 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
3030 sections that need the SHF_MIPS_GPREL flag by name; there has to be
3034 _bfd_mips_elf_section_processing (abfd
, hdr
)
3036 Elf_Internal_Shdr
*hdr
;
3038 if (hdr
->sh_type
== SHT_MIPS_REGINFO
3039 && hdr
->sh_size
> 0)
3043 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
3044 BFD_ASSERT (hdr
->contents
== NULL
);
3047 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
3050 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
3051 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
3055 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
3056 && hdr
->bfd_section
!= NULL
3057 && elf_section_data (hdr
->bfd_section
) != NULL
3058 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
3060 bfd_byte
*contents
, *l
, *lend
;
3062 /* We stored the section contents in the elf_section_data tdata
3063 field in the set_section_contents routine. We save the
3064 section contents so that we don't have to read them again.
3065 At this point we know that elf_gp is set, so we can look
3066 through the section contents to see if there is an
3067 ODK_REGINFO structure. */
3069 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
3071 lend
= contents
+ hdr
->sh_size
;
3072 while (l
+ sizeof (Elf_External_Options
) <= lend
)
3074 Elf_Internal_Options intopt
;
3076 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
3078 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
3085 + sizeof (Elf_External_Options
)
3086 + (sizeof (Elf64_External_RegInfo
) - 8)),
3089 bfd_h_put_64 (abfd
, elf_gp (abfd
), buf
);
3090 if (bfd_write (buf
, 1, 8, abfd
) != 8)
3093 else if (intopt
.kind
== ODK_REGINFO
)
3100 + sizeof (Elf_External_Options
)
3101 + (sizeof (Elf32_External_RegInfo
) - 4)),
3104 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
3105 if (bfd_write (buf
, 1, 4, abfd
) != 4)
3112 if (hdr
->bfd_section
!= NULL
)
3114 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
3116 if (strcmp (name
, ".sdata") == 0
3117 || strcmp (name
, ".lit8") == 0
3118 || strcmp (name
, ".lit4") == 0)
3120 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3121 hdr
->sh_type
= SHT_PROGBITS
;
3123 else if (strcmp (name
, ".sbss") == 0)
3125 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3126 hdr
->sh_type
= SHT_NOBITS
;
3128 else if (strcmp (name
, MIPS_ELF_SRDATA_SECTION_NAME (abfd
)) == 0)
3130 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
3131 hdr
->sh_type
= SHT_PROGBITS
;
3133 else if (strcmp (name
, ".compact_rel") == 0)
3136 hdr
->sh_type
= SHT_PROGBITS
;
3138 else if (strcmp (name
, ".rtproc") == 0)
3140 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
3142 unsigned int adjust
;
3144 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
3146 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
3155 /* MIPS ELF uses two common sections. One is the usual one, and the
3156 other is for small objects. All the small objects are kept
3157 together, and then referenced via the gp pointer, which yields
3158 faster assembler code. This is what we use for the small common
3159 section. This approach is copied from ecoff.c. */
3160 static asection mips_elf_scom_section
;
3161 static asymbol mips_elf_scom_symbol
;
3162 static asymbol
*mips_elf_scom_symbol_ptr
;
3164 /* MIPS ELF also uses an acommon section, which represents an
3165 allocated common symbol which may be overridden by a
3166 definition in a shared library. */
3167 static asection mips_elf_acom_section
;
3168 static asymbol mips_elf_acom_symbol
;
3169 static asymbol
*mips_elf_acom_symbol_ptr
;
3171 /* Handle the special MIPS section numbers that a symbol may use.
3172 This is used for both the 32-bit and the 64-bit ABI. */
3175 _bfd_mips_elf_symbol_processing (abfd
, asym
)
3179 elf_symbol_type
*elfsym
;
3181 elfsym
= (elf_symbol_type
*) asym
;
3182 switch (elfsym
->internal_elf_sym
.st_shndx
)
3184 case SHN_MIPS_ACOMMON
:
3185 /* This section is used in a dynamically linked executable file.
3186 It is an allocated common section. The dynamic linker can
3187 either resolve these symbols to something in a shared
3188 library, or it can just leave them here. For our purposes,
3189 we can consider these symbols to be in a new section. */
3190 if (mips_elf_acom_section
.name
== NULL
)
3192 /* Initialize the acommon section. */
3193 mips_elf_acom_section
.name
= ".acommon";
3194 mips_elf_acom_section
.flags
= SEC_ALLOC
;
3195 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
3196 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
3197 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
3198 mips_elf_acom_symbol
.name
= ".acommon";
3199 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
3200 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
3201 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
3203 asym
->section
= &mips_elf_acom_section
;
3207 /* Common symbols less than the GP size are automatically
3208 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
3209 if (asym
->value
> elf_gp_size (abfd
)
3210 || IRIX_COMPAT (abfd
) == ict_irix6
)
3213 case SHN_MIPS_SCOMMON
:
3214 if (mips_elf_scom_section
.name
== NULL
)
3216 /* Initialize the small common section. */
3217 mips_elf_scom_section
.name
= ".scommon";
3218 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
3219 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
3220 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
3221 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
3222 mips_elf_scom_symbol
.name
= ".scommon";
3223 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
3224 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
3225 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
3227 asym
->section
= &mips_elf_scom_section
;
3228 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
3231 case SHN_MIPS_SUNDEFINED
:
3232 asym
->section
= bfd_und_section_ptr
;
3235 #if 0 /* for SGI_COMPAT */
3237 asym
->section
= mips_elf_text_section_ptr
;
3241 asym
->section
= mips_elf_data_section_ptr
;
3247 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
3251 _bfd_mips_elf_additional_program_headers (abfd
)
3257 if (!SGI_COMPAT (abfd
))
3260 /* See if we need a PT_MIPS_REGINFO segment. */
3261 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3262 if (s
&& (s
->flags
& SEC_LOAD
))
3265 /* See if we need a PT_MIPS_OPTIONS segment. */
3266 if (IRIX_COMPAT (abfd
) == ict_irix6
3267 && bfd_get_section_by_name (abfd
,
3268 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
3271 /* See if we need a PT_MIPS_RTPROC segment. */
3272 if (IRIX_COMPAT (abfd
) == ict_irix5
3273 && bfd_get_section_by_name (abfd
, ".dynamic")
3274 && bfd_get_section_by_name (abfd
, ".mdebug"))
3280 /* Modify the segment map for an Irix 5 executable. */
3283 _bfd_mips_elf_modify_segment_map (abfd
)
3287 struct elf_segment_map
*m
, **pm
;
3289 if (! SGI_COMPAT (abfd
))
3292 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
3294 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3295 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3297 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3298 if (m
->p_type
== PT_MIPS_REGINFO
)
3302 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3306 m
->p_type
= PT_MIPS_REGINFO
;
3310 /* We want to put it after the PHDR and INTERP segments. */
3311 pm
= &elf_tdata (abfd
)->segment_map
;
3313 && ((*pm
)->p_type
== PT_PHDR
3314 || (*pm
)->p_type
== PT_INTERP
))
3322 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
3323 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
3324 PT_OPTIONS segement immediately following the program header
3326 if (IRIX_COMPAT (abfd
) == ict_irix6
)
3330 for (s
= abfd
->sections
; s
; s
= s
->next
)
3331 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
3336 struct elf_segment_map
*options_segment
;
3338 /* Usually, there's a program header table. But, sometimes
3339 there's not (like when running the `ld' testsuite). So,
3340 if there's no program header table, we just put the
3341 options segement at the end. */
3342 for (pm
= &elf_tdata (abfd
)->segment_map
;
3345 if ((*pm
)->p_type
== PT_PHDR
)
3348 options_segment
= bfd_zalloc (abfd
,
3349 sizeof (struct elf_segment_map
));
3350 options_segment
->next
= *pm
;
3351 options_segment
->p_type
= PT_MIPS_OPTIONS
;
3352 options_segment
->p_flags
= PF_R
;
3353 options_segment
->p_flags_valid
= true;
3354 options_segment
->count
= 1;
3355 options_segment
->sections
[0] = s
;
3356 *pm
= options_segment
;
3361 /* If there are .dynamic and .mdebug sections, we make a room
3362 for the RTPROC header. FIXME: Rewrite without section names. */
3363 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
3364 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3365 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3367 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3368 if (m
->p_type
== PT_MIPS_RTPROC
)
3372 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3376 m
->p_type
= PT_MIPS_RTPROC
;
3378 s
= bfd_get_section_by_name (abfd
, ".rtproc");
3383 m
->p_flags_valid
= 1;
3391 /* We want to put it after the DYNAMIC segment. */
3392 pm
= &elf_tdata (abfd
)->segment_map
;
3393 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
3403 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic,
3404 .dynstr, .dynsym, and .hash sections, and everything in
3406 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
3407 if ((*pm
)->p_type
== PT_DYNAMIC
)
3412 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
3414 static const char *sec_names
[] =
3415 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
3418 struct elf_segment_map
*n
;
3422 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
3424 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
3425 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3431 sz
= s
->_cooked_size
;
3434 if (high
< s
->vma
+ sz
)
3440 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3441 if ((s
->flags
& SEC_LOAD
) != 0
3444 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3448 n
= ((struct elf_segment_map
*)
3449 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
3456 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3458 if ((s
->flags
& SEC_LOAD
) != 0
3461 + (s
->_cooked_size
!= 0 ?
3462 s
->_cooked_size
: s
->_raw_size
))
3477 /* The structure of the runtime procedure descriptor created by the
3478 loader for use by the static exception system. */
3480 typedef struct runtime_pdr
{
3481 bfd_vma adr
; /* memory address of start of procedure */
3482 long regmask
; /* save register mask */
3483 long regoffset
; /* save register offset */
3484 long fregmask
; /* save floating point register mask */
3485 long fregoffset
; /* save floating point register offset */
3486 long frameoffset
; /* frame size */
3487 short framereg
; /* frame pointer register */
3488 short pcreg
; /* offset or reg of return pc */
3489 long irpss
; /* index into the runtime string table */
3491 struct exception_info
*exception_info
;/* pointer to exception array */
3493 #define cbRPDR sizeof(RPDR)
3494 #define rpdNil ((pRPDR) 0)
3496 /* Swap RPDR (runtime procedure table entry) for output. */
3498 static void ecoff_swap_rpdr_out
3499 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
3502 ecoff_swap_rpdr_out (abfd
, in
, ex
)
3505 struct rpdr_ext
*ex
;
3507 /* ecoff_put_off was defined in ecoffswap.h. */
3508 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
3509 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
3510 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
3511 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
3512 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
3513 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
3515 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
3516 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
3518 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
3520 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
3524 /* Read ECOFF debugging information from a .mdebug section into a
3525 ecoff_debug_info structure. */
3528 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
3531 struct ecoff_debug_info
*debug
;
3534 const struct ecoff_debug_swap
*swap
;
3535 char *ext_hdr
= NULL
;
3537 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3538 memset (debug
, 0, sizeof(*debug
));
3540 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
3541 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
3544 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
3545 swap
->external_hdr_size
)
3549 symhdr
= &debug
->symbolic_header
;
3550 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
3552 /* The symbolic header contains absolute file offsets and sizes to
3554 #define READ(ptr, offset, count, size, type) \
3555 if (symhdr->count == 0) \
3556 debug->ptr = NULL; \
3559 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
3560 if (debug->ptr == NULL) \
3561 goto error_return; \
3562 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3563 || (bfd_read (debug->ptr, size, symhdr->count, \
3564 abfd) != size * symhdr->count)) \
3565 goto error_return; \
3568 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
3569 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
3570 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
3571 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
3572 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
3573 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
3575 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
3576 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
3577 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
3578 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
3579 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
3583 debug
->adjust
= NULL
;
3588 if (ext_hdr
!= NULL
)
3590 if (debug
->line
!= NULL
)
3592 if (debug
->external_dnr
!= NULL
)
3593 free (debug
->external_dnr
);
3594 if (debug
->external_pdr
!= NULL
)
3595 free (debug
->external_pdr
);
3596 if (debug
->external_sym
!= NULL
)
3597 free (debug
->external_sym
);
3598 if (debug
->external_opt
!= NULL
)
3599 free (debug
->external_opt
);
3600 if (debug
->external_aux
!= NULL
)
3601 free (debug
->external_aux
);
3602 if (debug
->ss
!= NULL
)
3604 if (debug
->ssext
!= NULL
)
3605 free (debug
->ssext
);
3606 if (debug
->external_fdr
!= NULL
)
3607 free (debug
->external_fdr
);
3608 if (debug
->external_rfd
!= NULL
)
3609 free (debug
->external_rfd
);
3610 if (debug
->external_ext
!= NULL
)
3611 free (debug
->external_ext
);
3615 /* MIPS ELF local labels start with '$', not 'L'. */
3619 mips_elf_is_local_label_name (abfd
, name
)
3626 /* On Irix 6, the labels go back to starting with '.', so we accept
3627 the generic ELF local label syntax as well. */
3628 return _bfd_elf_is_local_label_name (abfd
, name
);
3631 /* MIPS ELF uses a special find_nearest_line routine in order the
3632 handle the ECOFF debugging information. */
3634 struct mips_elf_find_line
3636 struct ecoff_debug_info d
;
3637 struct ecoff_find_line i
;
3641 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
3642 functionname_ptr
, line_ptr
)
3647 const char **filename_ptr
;
3648 const char **functionname_ptr
;
3649 unsigned int *line_ptr
;
3653 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
3654 filename_ptr
, functionname_ptr
,
3658 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3659 filename_ptr
, functionname_ptr
,
3661 ABI_64_P (abfd
) ? 8 : 0))
3664 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
3668 struct mips_elf_find_line
*fi
;
3669 const struct ecoff_debug_swap
* const swap
=
3670 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3672 /* If we are called during a link, mips_elf_final_link may have
3673 cleared the SEC_HAS_CONTENTS field. We force it back on here
3674 if appropriate (which it normally will be). */
3675 origflags
= msec
->flags
;
3676 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
3677 msec
->flags
|= SEC_HAS_CONTENTS
;
3679 fi
= elf_tdata (abfd
)->find_line_info
;
3682 bfd_size_type external_fdr_size
;
3685 struct fdr
*fdr_ptr
;
3687 fi
= ((struct mips_elf_find_line
*)
3688 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
3691 msec
->flags
= origflags
;
3695 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
3697 msec
->flags
= origflags
;
3701 /* Swap in the FDR information. */
3702 fi
->d
.fdr
= ((struct fdr
*)
3704 (fi
->d
.symbolic_header
.ifdMax
*
3705 sizeof (struct fdr
))));
3706 if (fi
->d
.fdr
== NULL
)
3708 msec
->flags
= origflags
;
3711 external_fdr_size
= swap
->external_fdr_size
;
3712 fdr_ptr
= fi
->d
.fdr
;
3713 fraw_src
= (char *) fi
->d
.external_fdr
;
3714 fraw_end
= (fraw_src
3715 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
3716 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
3717 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
3719 elf_tdata (abfd
)->find_line_info
= fi
;
3721 /* Note that we don't bother to ever free this information.
3722 find_nearest_line is either called all the time, as in
3723 objdump -l, so the information should be saved, or it is
3724 rarely called, as in ld error messages, so the memory
3725 wasted is unimportant. Still, it would probably be a
3726 good idea for free_cached_info to throw it away. */
3729 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
3730 &fi
->i
, filename_ptr
, functionname_ptr
,
3733 msec
->flags
= origflags
;
3737 msec
->flags
= origflags
;
3740 /* Fall back on the generic ELF find_nearest_line routine. */
3742 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
3743 filename_ptr
, functionname_ptr
,
3747 /* The mips16 compiler uses a couple of special sections to handle
3748 floating point arguments.
3750 Section names that look like .mips16.fn.FNNAME contain stubs that
3751 copy floating point arguments from the fp regs to the gp regs and
3752 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3753 call should be redirected to the stub instead. If no 32 bit
3754 function calls FNNAME, the stub should be discarded. We need to
3755 consider any reference to the function, not just a call, because
3756 if the address of the function is taken we will need the stub,
3757 since the address might be passed to a 32 bit function.
3759 Section names that look like .mips16.call.FNNAME contain stubs
3760 that copy floating point arguments from the gp regs to the fp
3761 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3762 then any 16 bit function that calls FNNAME should be redirected
3763 to the stub instead. If FNNAME is not a 32 bit function, the
3764 stub should be discarded.
3766 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3767 which call FNNAME and then copy the return value from the fp regs
3768 to the gp regs. These stubs store the return value in $18 while
3769 calling FNNAME; any function which might call one of these stubs
3770 must arrange to save $18 around the call. (This case is not
3771 needed for 32 bit functions that call 16 bit functions, because
3772 16 bit functions always return floating point values in both
3775 Note that in all cases FNNAME might be defined statically.
3776 Therefore, FNNAME is not used literally. Instead, the relocation
3777 information will indicate which symbol the section is for.
3779 We record any stubs that we find in the symbol table. */
3781 #define FN_STUB ".mips16.fn."
3782 #define CALL_STUB ".mips16.call."
3783 #define CALL_FP_STUB ".mips16.call.fp."
3785 /* MIPS ELF linker hash table. */
3787 struct mips_elf_link_hash_table
3789 struct elf_link_hash_table root
;
3791 /* We no longer use this. */
3792 /* String section indices for the dynamic section symbols. */
3793 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
3795 /* The number of .rtproc entries. */
3796 bfd_size_type procedure_count
;
3797 /* The size of the .compact_rel section (if SGI_COMPAT). */
3798 bfd_size_type compact_rel_size
;
3799 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3800 entry is set to the address of __rld_obj_head as in Irix 5. */
3801 boolean use_rld_obj_head
;
3802 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3804 /* This is set if we see any mips16 stub sections. */
3805 boolean mips16_stubs_seen
;
3808 /* Look up an entry in a MIPS ELF linker hash table. */
3810 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3811 ((struct mips_elf_link_hash_entry *) \
3812 elf_link_hash_lookup (&(table)->root, (string), (create), \
3815 /* Traverse a MIPS ELF linker hash table. */
3817 #define mips_elf_link_hash_traverse(table, func, info) \
3818 (elf_link_hash_traverse \
3820 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3823 /* Get the MIPS ELF linker hash table from a link_info structure. */
3825 #define mips_elf_hash_table(p) \
3826 ((struct mips_elf_link_hash_table *) ((p)->hash))
3828 static boolean mips_elf_output_extsym
3829 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3831 /* Create an entry in a MIPS ELF linker hash table. */
3833 static struct bfd_hash_entry
*
3834 mips_elf_link_hash_newfunc (entry
, table
, string
)
3835 struct bfd_hash_entry
*entry
;
3836 struct bfd_hash_table
*table
;
3839 struct mips_elf_link_hash_entry
*ret
=
3840 (struct mips_elf_link_hash_entry
*) entry
;
3842 /* Allocate the structure if it has not already been allocated by a
3844 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3845 ret
= ((struct mips_elf_link_hash_entry
*)
3846 bfd_hash_allocate (table
,
3847 sizeof (struct mips_elf_link_hash_entry
)));
3848 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3849 return (struct bfd_hash_entry
*) ret
;
3851 /* Call the allocation method of the superclass. */
3852 ret
= ((struct mips_elf_link_hash_entry
*)
3853 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3855 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3857 /* Set local fields. */
3858 memset (&ret
->esym
, 0, sizeof (EXTR
));
3859 /* We use -2 as a marker to indicate that the information has
3860 not been set. -1 means there is no associated ifd. */
3862 ret
->possibly_dynamic_relocs
= 0;
3863 ret
->min_dyn_reloc_index
= 0;
3864 ret
->fn_stub
= NULL
;
3865 ret
->need_fn_stub
= false;
3866 ret
->call_stub
= NULL
;
3867 ret
->call_fp_stub
= NULL
;
3870 return (struct bfd_hash_entry
*) ret
;
3874 _bfd_mips_elf_hide_symbol(info
, h
)
3875 struct bfd_link_info
*info
;
3876 struct mips_elf_link_hash_entry
*h
;
3880 struct mips_got_info
*g
;
3881 dynobj
= elf_hash_table (info
)->dynobj
;
3882 got
= bfd_get_section_by_name (dynobj
, ".got");
3883 g
= (struct mips_got_info
*) elf_section_data (got
)->tdata
;
3885 h
->root
.elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3886 h
->root
.plt
.offset
= (bfd_vma
) -1;
3887 h
->root
.dynindx
= -1;
3889 /* FIXME: Do we allocate too much GOT space here? */
3891 got
->_raw_size
+= MIPS_ELF_GOT_SIZE (dynobj
);
3894 /* Create a MIPS ELF linker hash table. */
3896 struct bfd_link_hash_table
*
3897 _bfd_mips_elf_link_hash_table_create (abfd
)
3900 struct mips_elf_link_hash_table
*ret
;
3902 ret
= ((struct mips_elf_link_hash_table
*)
3903 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
3904 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
3907 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3908 mips_elf_link_hash_newfunc
))
3910 bfd_release (abfd
, ret
);
3915 /* We no longer use this. */
3916 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
3917 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
3919 ret
->procedure_count
= 0;
3920 ret
->compact_rel_size
= 0;
3921 ret
->use_rld_obj_head
= false;
3923 ret
->mips16_stubs_seen
= false;
3925 return &ret
->root
.root
;
3928 /* Hook called by the linker routine which adds symbols from an object
3929 file. We must handle the special MIPS section numbers here. */
3933 _bfd_mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3935 struct bfd_link_info
*info
;
3936 const Elf_Internal_Sym
*sym
;
3938 flagword
*flagsp ATTRIBUTE_UNUSED
;
3942 if (SGI_COMPAT (abfd
)
3943 && (abfd
->flags
& DYNAMIC
) != 0
3944 && strcmp (*namep
, "_rld_new_interface") == 0)
3946 /* Skip Irix 5 rld entry name. */
3951 switch (sym
->st_shndx
)
3954 /* Common symbols less than the GP size are automatically
3955 treated as SHN_MIPS_SCOMMON symbols. */
3956 if (sym
->st_size
> elf_gp_size (abfd
)
3957 || IRIX_COMPAT (abfd
) == ict_irix6
)
3960 case SHN_MIPS_SCOMMON
:
3961 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3962 (*secp
)->flags
|= SEC_IS_COMMON
;
3963 *valp
= sym
->st_size
;
3967 /* This section is used in a shared object. */
3968 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
3970 asymbol
*elf_text_symbol
;
3971 asection
*elf_text_section
;
3973 elf_text_section
= bfd_zalloc (abfd
, sizeof (asection
));
3974 if (elf_text_section
== NULL
)
3977 elf_text_symbol
= bfd_zalloc (abfd
, sizeof (asymbol
));
3978 if (elf_text_symbol
== NULL
)
3981 /* Initialize the section. */
3983 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
3984 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
3986 elf_text_section
->symbol
= elf_text_symbol
;
3987 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
3989 elf_text_section
->name
= ".text";
3990 elf_text_section
->flags
= SEC_NO_FLAGS
;
3991 elf_text_section
->output_section
= NULL
;
3992 elf_text_section
->owner
= abfd
;
3993 elf_text_symbol
->name
= ".text";
3994 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
3995 elf_text_symbol
->section
= elf_text_section
;
3997 /* This code used to do *secp = bfd_und_section_ptr if
3998 info->shared. I don't know why, and that doesn't make sense,
3999 so I took it out. */
4000 *secp
= elf_tdata (abfd
)->elf_text_section
;
4003 case SHN_MIPS_ACOMMON
:
4004 /* Fall through. XXX Can we treat this as allocated data? */
4006 /* This section is used in a shared object. */
4007 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
4009 asymbol
*elf_data_symbol
;
4010 asection
*elf_data_section
;
4012 elf_data_section
= bfd_zalloc (abfd
, sizeof (asection
));
4013 if (elf_data_section
== NULL
)
4016 elf_data_symbol
= bfd_zalloc (abfd
, sizeof (asymbol
));
4017 if (elf_data_symbol
== NULL
)
4020 /* Initialize the section. */
4022 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
4023 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
4025 elf_data_section
->symbol
= elf_data_symbol
;
4026 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
4028 elf_data_section
->name
= ".data";
4029 elf_data_section
->flags
= SEC_NO_FLAGS
;
4030 elf_data_section
->output_section
= NULL
;
4031 elf_data_section
->owner
= abfd
;
4032 elf_data_symbol
->name
= ".data";
4033 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
4034 elf_data_symbol
->section
= elf_data_section
;
4036 /* This code used to do *secp = bfd_und_section_ptr if
4037 info->shared. I don't know why, and that doesn't make sense,
4038 so I took it out. */
4039 *secp
= elf_tdata (abfd
)->elf_data_section
;
4042 case SHN_MIPS_SUNDEFINED
:
4043 *secp
= bfd_und_section_ptr
;
4047 if (SGI_COMPAT (abfd
)
4049 && info
->hash
->creator
== abfd
->xvec
4050 && strcmp (*namep
, "__rld_obj_head") == 0)
4052 struct elf_link_hash_entry
*h
;
4054 /* Mark __rld_obj_head as dynamic. */
4056 if (! (_bfd_generic_link_add_one_symbol
4057 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
4058 (bfd_vma
) *valp
, (const char *) NULL
, false,
4059 get_elf_backend_data (abfd
)->collect
,
4060 (struct bfd_link_hash_entry
**) &h
)))
4062 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
4063 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4064 h
->type
= STT_OBJECT
;
4066 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4069 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
4072 /* If this is a mips16 text symbol, add 1 to the value to make it
4073 odd. This will cause something like .word SYM to come up with
4074 the right value when it is loaded into the PC. */
4075 if (sym
->st_other
== STO_MIPS16
)
4081 /* Structure used to pass information to mips_elf_output_extsym. */
4086 struct bfd_link_info
*info
;
4087 struct ecoff_debug_info
*debug
;
4088 const struct ecoff_debug_swap
*swap
;
4092 /* This routine is used to write out ECOFF debugging external symbol
4093 information. It is called via mips_elf_link_hash_traverse. The
4094 ECOFF external symbol information must match the ELF external
4095 symbol information. Unfortunately, at this point we don't know
4096 whether a symbol is required by reloc information, so the two
4097 tables may wind up being different. We must sort out the external
4098 symbol information before we can set the final size of the .mdebug
4099 section, and we must set the size of the .mdebug section before we
4100 can relocate any sections, and we can't know which symbols are
4101 required by relocation until we relocate the sections.
4102 Fortunately, it is relatively unlikely that any symbol will be
4103 stripped but required by a reloc. In particular, it can not happen
4104 when generating a final executable. */
4107 mips_elf_output_extsym (h
, data
)
4108 struct mips_elf_link_hash_entry
*h
;
4111 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
4113 asection
*sec
, *output_section
;
4115 if (h
->root
.indx
== -2)
4117 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4118 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
4119 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
4120 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
4122 else if (einfo
->info
->strip
== strip_all
4123 || (einfo
->info
->strip
== strip_some
4124 && bfd_hash_lookup (einfo
->info
->keep_hash
,
4125 h
->root
.root
.root
.string
,
4126 false, false) == NULL
))
4134 if (h
->esym
.ifd
== -2)
4137 h
->esym
.cobol_main
= 0;
4138 h
->esym
.weakext
= 0;
4139 h
->esym
.reserved
= 0;
4140 h
->esym
.ifd
= ifdNil
;
4141 h
->esym
.asym
.value
= 0;
4142 h
->esym
.asym
.st
= stGlobal
;
4144 if (SGI_COMPAT (einfo
->abfd
)
4145 && (h
->root
.root
.type
== bfd_link_hash_undefined
4146 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
4150 /* Use undefined class. Also, set class and type for some
4152 name
= h
->root
.root
.root
.string
;
4153 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
4154 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
4156 h
->esym
.asym
.sc
= scData
;
4157 h
->esym
.asym
.st
= stLabel
;
4158 h
->esym
.asym
.value
= 0;
4160 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
4162 h
->esym
.asym
.sc
= scAbs
;
4163 h
->esym
.asym
.st
= stLabel
;
4164 h
->esym
.asym
.value
=
4165 mips_elf_hash_table (einfo
->info
)->procedure_count
;
4167 else if (strcmp (name
, "_gp_disp") == 0)
4169 h
->esym
.asym
.sc
= scAbs
;
4170 h
->esym
.asym
.st
= stLabel
;
4171 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
4174 h
->esym
.asym
.sc
= scUndefined
;
4176 else if (h
->root
.root
.type
!= bfd_link_hash_defined
4177 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
4178 h
->esym
.asym
.sc
= scAbs
;
4183 sec
= h
->root
.root
.u
.def
.section
;
4184 output_section
= sec
->output_section
;
4186 /* When making a shared library and symbol h is the one from
4187 the another shared library, OUTPUT_SECTION may be null. */
4188 if (output_section
== NULL
)
4189 h
->esym
.asym
.sc
= scUndefined
;
4192 name
= bfd_section_name (output_section
->owner
, output_section
);
4194 if (strcmp (name
, ".text") == 0)
4195 h
->esym
.asym
.sc
= scText
;
4196 else if (strcmp (name
, ".data") == 0)
4197 h
->esym
.asym
.sc
= scData
;
4198 else if (strcmp (name
, ".sdata") == 0)
4199 h
->esym
.asym
.sc
= scSData
;
4200 else if (strcmp (name
, ".rodata") == 0
4201 || strcmp (name
, ".rdata") == 0)
4202 h
->esym
.asym
.sc
= scRData
;
4203 else if (strcmp (name
, ".bss") == 0)
4204 h
->esym
.asym
.sc
= scBss
;
4205 else if (strcmp (name
, ".sbss") == 0)
4206 h
->esym
.asym
.sc
= scSBss
;
4207 else if (strcmp (name
, ".init") == 0)
4208 h
->esym
.asym
.sc
= scInit
;
4209 else if (strcmp (name
, ".fini") == 0)
4210 h
->esym
.asym
.sc
= scFini
;
4212 h
->esym
.asym
.sc
= scAbs
;
4216 h
->esym
.asym
.reserved
= 0;
4217 h
->esym
.asym
.index
= indexNil
;
4220 if (h
->root
.root
.type
== bfd_link_hash_common
)
4221 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
4222 else if (h
->root
.root
.type
== bfd_link_hash_defined
4223 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4225 if (h
->esym
.asym
.sc
== scCommon
)
4226 h
->esym
.asym
.sc
= scBss
;
4227 else if (h
->esym
.asym
.sc
== scSCommon
)
4228 h
->esym
.asym
.sc
= scSBss
;
4230 sec
= h
->root
.root
.u
.def
.section
;
4231 output_section
= sec
->output_section
;
4232 if (output_section
!= NULL
)
4233 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
4234 + sec
->output_offset
4235 + output_section
->vma
);
4237 h
->esym
.asym
.value
= 0;
4239 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4241 /* Set type and value for a symbol with a function stub. */
4242 h
->esym
.asym
.st
= stProc
;
4243 sec
= h
->root
.root
.u
.def
.section
;
4245 h
->esym
.asym
.value
= 0;
4248 output_section
= sec
->output_section
;
4249 if (output_section
!= NULL
)
4250 h
->esym
.asym
.value
= (h
->root
.plt
.offset
4251 + sec
->output_offset
4252 + output_section
->vma
);
4254 h
->esym
.asym
.value
= 0;
4261 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
4262 h
->root
.root
.root
.string
,
4265 einfo
->failed
= true;
4272 /* Create a runtime procedure table from the .mdebug section. */
4275 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
4278 struct bfd_link_info
*info
;
4280 struct ecoff_debug_info
*debug
;
4282 const struct ecoff_debug_swap
*swap
;
4283 HDRR
*hdr
= &debug
->symbolic_header
;
4285 struct rpdr_ext
*erp
;
4287 struct pdr_ext
*epdr
;
4288 struct sym_ext
*esym
;
4291 unsigned long size
, count
;
4292 unsigned long sindex
;
4296 const char *no_name_func
= _("static procedure (no name)");
4304 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4306 sindex
= strlen (no_name_func
) + 1;
4307 count
= hdr
->ipdMax
;
4310 size
= swap
->external_pdr_size
;
4312 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
4316 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
4319 size
= sizeof (RPDR
);
4320 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
4324 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
4328 count
= hdr
->isymMax
;
4329 size
= swap
->external_sym_size
;
4330 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
4334 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
4337 count
= hdr
->issMax
;
4338 ss
= (char *) bfd_malloc (count
);
4341 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
4344 count
= hdr
->ipdMax
;
4345 for (i
= 0; i
< count
; i
++, rp
++)
4347 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
4348 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
4349 rp
->adr
= sym
.value
;
4350 rp
->regmask
= pdr
.regmask
;
4351 rp
->regoffset
= pdr
.regoffset
;
4352 rp
->fregmask
= pdr
.fregmask
;
4353 rp
->fregoffset
= pdr
.fregoffset
;
4354 rp
->frameoffset
= pdr
.frameoffset
;
4355 rp
->framereg
= pdr
.framereg
;
4356 rp
->pcreg
= pdr
.pcreg
;
4358 sv
[i
] = ss
+ sym
.iss
;
4359 sindex
+= strlen (sv
[i
]) + 1;
4363 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
4364 size
= BFD_ALIGN (size
, 16);
4365 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
4368 mips_elf_hash_table (info
)->procedure_count
= 0;
4372 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
4374 erp
= (struct rpdr_ext
*) rtproc
;
4375 memset (erp
, 0, sizeof (struct rpdr_ext
));
4377 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
4378 strcpy (str
, no_name_func
);
4379 str
+= strlen (no_name_func
) + 1;
4380 for (i
= 0; i
< count
; i
++)
4382 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
4383 strcpy (str
, sv
[i
]);
4384 str
+= strlen (sv
[i
]) + 1;
4386 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
4388 /* Set the size and contents of .rtproc section. */
4389 s
->_raw_size
= size
;
4390 s
->contents
= (bfd_byte
*) rtproc
;
4392 /* Skip this section later on (I don't think this currently
4393 matters, but someday it might). */
4394 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
4423 /* A comparison routine used to sort .gptab entries. */
4426 gptab_compare (p1
, p2
)
4430 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
4431 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
4433 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
4436 /* We need to use a special link routine to handle the .reginfo and
4437 the .mdebug sections. We need to merge all instances of these
4438 sections together, not write them all out sequentially. */
4441 _bfd_mips_elf_final_link (abfd
, info
)
4443 struct bfd_link_info
*info
;
4447 struct bfd_link_order
*p
;
4448 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
4449 asection
*rtproc_sec
;
4450 Elf32_RegInfo reginfo
;
4451 struct ecoff_debug_info debug
;
4452 const struct ecoff_debug_swap
*swap
4453 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4454 HDRR
*symhdr
= &debug
.symbolic_header
;
4455 PTR mdebug_handle
= NULL
;
4457 /* If all the things we linked together were PIC, but we're
4458 producing an executable (rather than a shared object), then the
4459 resulting file is CPIC (i.e., it calls PIC code.) */
4461 && !info
->relocateable
4462 && elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
4464 elf_elfheader (abfd
)->e_flags
&= ~EF_MIPS_PIC
;
4465 elf_elfheader (abfd
)->e_flags
|= EF_MIPS_CPIC
;
4468 /* We'd carefully arranged the dynamic symbol indices, and then the
4469 generic size_dynamic_sections renumbered them out from under us.
4470 Rather than trying somehow to prevent the renumbering, just do
4472 if (elf_hash_table (info
)->dynamic_sections_created
)
4476 struct mips_got_info
*g
;
4478 /* When we resort, we must tell mips_elf_sort_hash_table what
4479 the lowest index it may use is. That's the number of section
4480 symbols we're going to add. The generic ELF linker only
4481 adds these symbols when building a shared object. Note that
4482 we count the sections after (possibly) removing the .options
4484 if (!mips_elf_sort_hash_table (info
, (info
->shared
4485 ? bfd_count_sections (abfd
) + 1
4489 /* Make sure we didn't grow the global .got region. */
4490 dynobj
= elf_hash_table (info
)->dynobj
;
4491 got
= bfd_get_section_by_name (dynobj
, ".got");
4492 g
= (struct mips_got_info
*) elf_section_data (got
)->tdata
;
4494 if (g
->global_gotsym
!= NULL
)
4495 BFD_ASSERT ((elf_hash_table (info
)->dynsymcount
4496 - g
->global_gotsym
->dynindx
)
4497 <= g
->global_gotno
);
4500 /* On IRIX5, we omit the .options section. On IRIX6, however, we
4501 include it, even though we don't process it quite right. (Some
4502 entries are supposed to be merged.) Empirically, we seem to be
4503 better off including it then not. */
4504 if (IRIX_COMPAT (abfd
) == ict_irix5
)
4505 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
4507 if (strcmp ((*secpp
)->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
4509 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
4510 if (p
->type
== bfd_indirect_link_order
)
4511 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
4512 (*secpp
)->link_order_head
= NULL
;
4513 *secpp
= (*secpp
)->next
;
4514 --abfd
->section_count
;
4520 /* Get a value for the GP register. */
4521 if (elf_gp (abfd
) == 0)
4523 struct bfd_link_hash_entry
*h
;
4525 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4526 if (h
!= (struct bfd_link_hash_entry
*) NULL
4527 && h
->type
== bfd_link_hash_defined
)
4528 elf_gp (abfd
) = (h
->u
.def
.value
4529 + h
->u
.def
.section
->output_section
->vma
4530 + h
->u
.def
.section
->output_offset
);
4531 else if (info
->relocateable
)
4535 /* Find the GP-relative section with the lowest offset. */
4537 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4539 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
4542 /* And calculate GP relative to that. */
4543 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
4547 /* If the relocate_section function needs to do a reloc
4548 involving the GP value, it should make a reloc_dangerous
4549 callback to warn that GP is not defined. */
4553 /* Go through the sections and collect the .reginfo and .mdebug
4557 gptab_data_sec
= NULL
;
4558 gptab_bss_sec
= NULL
;
4559 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4561 if (strcmp (o
->name
, ".reginfo") == 0)
4563 memset (®info
, 0, sizeof reginfo
);
4565 /* We have found the .reginfo section in the output file.
4566 Look through all the link_orders comprising it and merge
4567 the information together. */
4568 for (p
= o
->link_order_head
;
4569 p
!= (struct bfd_link_order
*) NULL
;
4572 asection
*input_section
;
4574 Elf32_External_RegInfo ext
;
4577 if (p
->type
!= bfd_indirect_link_order
)
4579 if (p
->type
== bfd_fill_link_order
)
4584 input_section
= p
->u
.indirect
.section
;
4585 input_bfd
= input_section
->owner
;
4587 /* The linker emulation code has probably clobbered the
4588 size to be zero bytes. */
4589 if (input_section
->_raw_size
== 0)
4590 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4592 if (! bfd_get_section_contents (input_bfd
, input_section
,
4598 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
4600 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
4601 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
4602 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
4603 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
4604 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
4606 /* ri_gp_value is set by the function
4607 mips_elf32_section_processing when the section is
4608 finally written out. */
4610 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4611 elf_link_input_bfd ignores this section. */
4612 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4615 /* Size has been set in mips_elf_always_size_sections */
4616 BFD_ASSERT(o
->_raw_size
== sizeof (Elf32_External_RegInfo
));
4618 /* Skip this section later on (I don't think this currently
4619 matters, but someday it might). */
4620 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4625 if (strcmp (o
->name
, ".mdebug") == 0)
4627 struct extsym_info einfo
;
4629 /* We have found the .mdebug section in the output file.
4630 Look through all the link_orders comprising it and merge
4631 the information together. */
4632 symhdr
->magic
= swap
->sym_magic
;
4633 /* FIXME: What should the version stamp be? */
4635 symhdr
->ilineMax
= 0;
4639 symhdr
->isymMax
= 0;
4640 symhdr
->ioptMax
= 0;
4641 symhdr
->iauxMax
= 0;
4643 symhdr
->issExtMax
= 0;
4646 symhdr
->iextMax
= 0;
4648 /* We accumulate the debugging information itself in the
4649 debug_info structure. */
4651 debug
.external_dnr
= NULL
;
4652 debug
.external_pdr
= NULL
;
4653 debug
.external_sym
= NULL
;
4654 debug
.external_opt
= NULL
;
4655 debug
.external_aux
= NULL
;
4657 debug
.ssext
= debug
.ssext_end
= NULL
;
4658 debug
.external_fdr
= NULL
;
4659 debug
.external_rfd
= NULL
;
4660 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4662 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4663 if (mdebug_handle
== (PTR
) NULL
)
4666 if (SGI_COMPAT (abfd
))
4672 static const char * const name
[] =
4673 { ".text", ".init", ".fini", ".data",
4674 ".rodata", ".sdata", ".sbss", ".bss" };
4675 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
4676 scRData
, scSData
, scSBss
, scBss
};
4679 esym
.cobol_main
= 0;
4683 esym
.asym
.iss
= issNil
;
4684 esym
.asym
.st
= stLocal
;
4685 esym
.asym
.reserved
= 0;
4686 esym
.asym
.index
= indexNil
;
4688 for (i
= 0; i
< 8; i
++)
4690 esym
.asym
.sc
= sc
[i
];
4691 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4694 esym
.asym
.value
= s
->vma
;
4695 last
= s
->vma
+ s
->_raw_size
;
4698 esym
.asym
.value
= last
;
4700 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4706 for (p
= o
->link_order_head
;
4707 p
!= (struct bfd_link_order
*) NULL
;
4710 asection
*input_section
;
4712 const struct ecoff_debug_swap
*input_swap
;
4713 struct ecoff_debug_info input_debug
;
4717 if (p
->type
!= bfd_indirect_link_order
)
4719 if (p
->type
== bfd_fill_link_order
)
4724 input_section
= p
->u
.indirect
.section
;
4725 input_bfd
= input_section
->owner
;
4727 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4728 || (get_elf_backend_data (input_bfd
)
4729 ->elf_backend_ecoff_debug_swap
) == NULL
)
4731 /* I don't know what a non MIPS ELF bfd would be
4732 doing with a .mdebug section, but I don't really
4733 want to deal with it. */
4737 input_swap
= (get_elf_backend_data (input_bfd
)
4738 ->elf_backend_ecoff_debug_swap
);
4740 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
4742 /* The ECOFF linking code expects that we have already
4743 read in the debugging information and set up an
4744 ecoff_debug_info structure, so we do that now. */
4745 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
4749 if (! (bfd_ecoff_debug_accumulate
4750 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
4751 &input_debug
, input_swap
, info
)))
4754 /* Loop through the external symbols. For each one with
4755 interesting information, try to find the symbol in
4756 the linker global hash table and save the information
4757 for the output external symbols. */
4758 eraw_src
= input_debug
.external_ext
;
4759 eraw_end
= (eraw_src
4760 + (input_debug
.symbolic_header
.iextMax
4761 * input_swap
->external_ext_size
));
4763 eraw_src
< eraw_end
;
4764 eraw_src
+= input_swap
->external_ext_size
)
4768 struct mips_elf_link_hash_entry
*h
;
4770 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4771 if (ext
.asym
.sc
== scNil
4772 || ext
.asym
.sc
== scUndefined
4773 || ext
.asym
.sc
== scSUndefined
)
4776 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4777 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
4778 name
, false, false, true);
4779 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4785 < input_debug
.symbolic_header
.ifdMax
);
4786 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4792 /* Free up the information we just read. */
4793 free (input_debug
.line
);
4794 free (input_debug
.external_dnr
);
4795 free (input_debug
.external_pdr
);
4796 free (input_debug
.external_sym
);
4797 free (input_debug
.external_opt
);
4798 free (input_debug
.external_aux
);
4799 free (input_debug
.ss
);
4800 free (input_debug
.ssext
);
4801 free (input_debug
.external_fdr
);
4802 free (input_debug
.external_rfd
);
4803 free (input_debug
.external_ext
);
4805 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4806 elf_link_input_bfd ignores this section. */
4807 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4810 if (SGI_COMPAT (abfd
) && info
->shared
)
4812 /* Create .rtproc section. */
4813 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4814 if (rtproc_sec
== NULL
)
4816 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4817 | SEC_LINKER_CREATED
| SEC_READONLY
);
4819 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4820 if (rtproc_sec
== NULL
4821 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4822 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
4826 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
4827 info
, rtproc_sec
, &debug
))
4831 /* Build the external symbol information. */
4834 einfo
.debug
= &debug
;
4836 einfo
.failed
= false;
4837 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4838 mips_elf_output_extsym
,
4843 /* Set the size of the .mdebug section. */
4844 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4846 /* Skip this section later on (I don't think this currently
4847 matters, but someday it might). */
4848 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4853 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4855 const char *subname
;
4858 Elf32_External_gptab
*ext_tab
;
4861 /* The .gptab.sdata and .gptab.sbss sections hold
4862 information describing how the small data area would
4863 change depending upon the -G switch. These sections
4864 not used in executables files. */
4865 if (! info
->relocateable
)
4869 for (p
= o
->link_order_head
;
4870 p
!= (struct bfd_link_order
*) NULL
;
4873 asection
*input_section
;
4875 if (p
->type
!= bfd_indirect_link_order
)
4877 if (p
->type
== bfd_fill_link_order
)
4882 input_section
= p
->u
.indirect
.section
;
4884 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4885 elf_link_input_bfd ignores this section. */
4886 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4889 /* Skip this section later on (I don't think this
4890 currently matters, but someday it might). */
4891 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4893 /* Really remove the section. */
4894 for (secpp
= &abfd
->sections
;
4896 secpp
= &(*secpp
)->next
)
4898 *secpp
= (*secpp
)->next
;
4899 --abfd
->section_count
;
4904 /* There is one gptab for initialized data, and one for
4905 uninitialized data. */
4906 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4908 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4912 (*_bfd_error_handler
)
4913 (_("%s: illegal section name `%s'"),
4914 bfd_get_filename (abfd
), o
->name
);
4915 bfd_set_error (bfd_error_nonrepresentable_section
);
4919 /* The linker script always combines .gptab.data and
4920 .gptab.sdata into .gptab.sdata, and likewise for
4921 .gptab.bss and .gptab.sbss. It is possible that there is
4922 no .sdata or .sbss section in the output file, in which
4923 case we must change the name of the output section. */
4924 subname
= o
->name
+ sizeof ".gptab" - 1;
4925 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4927 if (o
== gptab_data_sec
)
4928 o
->name
= ".gptab.data";
4930 o
->name
= ".gptab.bss";
4931 subname
= o
->name
+ sizeof ".gptab" - 1;
4932 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4935 /* Set up the first entry. */
4937 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
4940 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4941 tab
[0].gt_header
.gt_unused
= 0;
4943 /* Combine the input sections. */
4944 for (p
= o
->link_order_head
;
4945 p
!= (struct bfd_link_order
*) NULL
;
4948 asection
*input_section
;
4952 bfd_size_type gpentry
;
4954 if (p
->type
!= bfd_indirect_link_order
)
4956 if (p
->type
== bfd_fill_link_order
)
4961 input_section
= p
->u
.indirect
.section
;
4962 input_bfd
= input_section
->owner
;
4964 /* Combine the gptab entries for this input section one
4965 by one. We know that the input gptab entries are
4966 sorted by ascending -G value. */
4967 size
= bfd_section_size (input_bfd
, input_section
);
4969 for (gpentry
= sizeof (Elf32_External_gptab
);
4971 gpentry
+= sizeof (Elf32_External_gptab
))
4973 Elf32_External_gptab ext_gptab
;
4974 Elf32_gptab int_gptab
;
4980 if (! (bfd_get_section_contents
4981 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4982 gpentry
, sizeof (Elf32_External_gptab
))))
4988 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
4990 val
= int_gptab
.gt_entry
.gt_g_value
;
4991 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4994 for (look
= 1; look
< c
; look
++)
4996 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4997 tab
[look
].gt_entry
.gt_bytes
+= add
;
4999 if (tab
[look
].gt_entry
.gt_g_value
== val
)
5005 Elf32_gptab
*new_tab
;
5008 /* We need a new table entry. */
5009 new_tab
= ((Elf32_gptab
*)
5010 bfd_realloc ((PTR
) tab
,
5011 (c
+ 1) * sizeof (Elf32_gptab
)));
5012 if (new_tab
== NULL
)
5018 tab
[c
].gt_entry
.gt_g_value
= val
;
5019 tab
[c
].gt_entry
.gt_bytes
= add
;
5021 /* Merge in the size for the next smallest -G
5022 value, since that will be implied by this new
5025 for (look
= 1; look
< c
; look
++)
5027 if (tab
[look
].gt_entry
.gt_g_value
< val
5029 || (tab
[look
].gt_entry
.gt_g_value
5030 > tab
[max
].gt_entry
.gt_g_value
)))
5034 tab
[c
].gt_entry
.gt_bytes
+=
5035 tab
[max
].gt_entry
.gt_bytes
;
5040 last
= int_gptab
.gt_entry
.gt_bytes
;
5043 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5044 elf_link_input_bfd ignores this section. */
5045 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
5048 /* The table must be sorted by -G value. */
5050 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
5052 /* Swap out the table. */
5053 ext_tab
= ((Elf32_External_gptab
*)
5054 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
5055 if (ext_tab
== NULL
)
5061 for (i
= 0; i
< c
; i
++)
5062 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
5065 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
5066 o
->contents
= (bfd_byte
*) ext_tab
;
5068 /* Skip this section later on (I don't think this currently
5069 matters, but someday it might). */
5070 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
5074 /* Invoke the regular ELF backend linker to do all the work. */
5075 if (ABI_64_P (abfd
))
5078 if (!bfd_elf64_bfd_final_link (abfd
, info
))
5085 else if (!bfd_elf32_bfd_final_link (abfd
, info
))
5088 /* Now write out the computed sections. */
5090 if (reginfo_sec
!= (asection
*) NULL
)
5092 Elf32_External_RegInfo ext
;
5094 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
5095 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
5096 (file_ptr
) 0, sizeof ext
))
5100 if (mdebug_sec
!= (asection
*) NULL
)
5102 BFD_ASSERT (abfd
->output_has_begun
);
5103 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
5105 mdebug_sec
->filepos
))
5108 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
5111 if (gptab_data_sec
!= (asection
*) NULL
)
5113 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
5114 gptab_data_sec
->contents
,
5116 gptab_data_sec
->_raw_size
))
5120 if (gptab_bss_sec
!= (asection
*) NULL
)
5122 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
5123 gptab_bss_sec
->contents
,
5125 gptab_bss_sec
->_raw_size
))
5129 if (SGI_COMPAT (abfd
))
5131 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
5132 if (rtproc_sec
!= NULL
)
5134 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
5135 rtproc_sec
->contents
,
5137 rtproc_sec
->_raw_size
))
5145 /* Returns the GOT section for ABFD. */
5148 mips_elf_got_section (abfd
)
5151 return bfd_get_section_by_name (abfd
, ".got");
5154 /* Returns the GOT information associated with the link indicated by
5155 INFO. If SGOTP is non-NULL, it is filled in with the GOT
5158 static struct mips_got_info
*
5159 mips_elf_got_info (abfd
, sgotp
)
5164 struct mips_got_info
*g
;
5166 sgot
= mips_elf_got_section (abfd
);
5167 BFD_ASSERT (sgot
!= NULL
);
5168 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5169 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5170 BFD_ASSERT (g
!= NULL
);
5177 /* Return whether a relocation is against a local symbol. */
5180 mips_elf_local_relocation_p (input_bfd
, relocation
, local_sections
,
5183 const Elf_Internal_Rela
*relocation
;
5184 asection
**local_sections
;
5185 boolean check_forced
;
5187 unsigned long r_symndx
;
5188 Elf_Internal_Shdr
*symtab_hdr
;
5189 struct mips_elf_link_hash_entry
* h
;
5192 r_symndx
= ELF32_R_SYM (relocation
->r_info
);
5193 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5194 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
5196 if (r_symndx
< extsymoff
)
5198 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
5203 /* Look up the hash table to check whether the symbol
5204 was forced local. */
5205 h
= (struct mips_elf_link_hash_entry
*)
5206 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
5207 /* Find the real hash-table entry for this symbol. */
5208 while (h
->root
.root
.type
== bfd_link_hash_indirect
5209 || h
->root
.root
.type
== bfd_link_hash_warning
)
5210 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
5211 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
5218 /* Sign-extend VALUE, which has the indicated number of BITS. */
5221 mips_elf_sign_extend (value
, bits
)
5225 if (value
& ((bfd_vma
)1 << (bits
- 1)))
5226 /* VALUE is negative. */
5227 value
|= ((bfd_vma
) - 1) << bits
;
5232 /* Return non-zero if the indicated VALUE has overflowed the maximum
5233 range expressable by a signed number with the indicated number of
5237 mips_elf_overflow_p (value
, bits
)
5241 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
5243 if (svalue
> (1 << (bits
- 1)) - 1)
5244 /* The value is too big. */
5246 else if (svalue
< -(1 << (bits
- 1)))
5247 /* The value is too small. */
5254 /* Calculate the %high function. */
5257 mips_elf_high (value
)
5260 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
5263 /* Calculate the %higher function. */
5266 mips_elf_higher (value
)
5267 bfd_vma value ATTRIBUTE_UNUSED
;
5270 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
5273 return (bfd_vma
) -1;
5277 /* Calculate the %highest function. */
5280 mips_elf_highest (value
)
5281 bfd_vma value ATTRIBUTE_UNUSED
;
5284 return ((value
+ (bfd_vma
) 0x800080008000) >> 48) & 0xffff;
5287 return (bfd_vma
) -1;
5291 /* Returns the GOT index for the global symbol indicated by H. */
5294 mips_elf_global_got_index (abfd
, h
)
5296 struct elf_link_hash_entry
*h
;
5300 struct mips_got_info
*g
;
5302 g
= mips_elf_got_info (abfd
, &sgot
);
5304 /* Once we determine the global GOT entry with the lowest dynamic
5305 symbol table index, we must put all dynamic symbols with greater
5306 indices into the GOT. That makes it easy to calculate the GOT
5308 BFD_ASSERT (h
->dynindx
>= g
->global_gotsym
->dynindx
);
5309 index
= ((h
->dynindx
- g
->global_gotsym
->dynindx
+ g
->local_gotno
)
5310 * MIPS_ELF_GOT_SIZE (abfd
));
5311 BFD_ASSERT (index
< sgot
->_raw_size
);
5316 /* Returns the offset for the entry at the INDEXth position
5320 mips_elf_got_offset_from_index (dynobj
, output_bfd
, index
)
5328 sgot
= mips_elf_got_section (dynobj
);
5329 gp
= _bfd_get_gp_value (output_bfd
);
5330 return (sgot
->output_section
->vma
+ sgot
->output_offset
+ index
-
5334 /* If H is a symbol that needs a global GOT entry, but has a dynamic
5335 symbol table index lower than any we've seen to date, record it for
5339 mips_elf_record_global_got_symbol (h
, info
, g
)
5340 struct elf_link_hash_entry
*h
;
5341 struct bfd_link_info
*info
;
5342 struct mips_got_info
*g ATTRIBUTE_UNUSED
;
5344 /* A global symbol in the GOT must also be in the dynamic symbol
5346 if (h
->dynindx
== -1
5347 && !bfd_elf32_link_record_dynamic_symbol (info
, h
))
5350 /* If we've already marked this entry as need GOT space, we don't
5351 need to do it again. */
5352 if (h
->got
.offset
!= (bfd_vma
) - 1)
5355 /* By setting this to a value other than -1, we are indicating that
5356 there needs to be a GOT entry for H. */
5362 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
5363 the dynamic symbols. */
5365 struct mips_elf_hash_sort_data
5367 /* The symbol in the global GOT with the lowest dynamic symbol table
5369 struct elf_link_hash_entry
*low
;
5370 /* The least dynamic symbol table index corresponding to a symbol
5371 with a GOT entry. */
5372 long min_got_dynindx
;
5373 /* The greatest dynamic symbol table index not corresponding to a
5374 symbol without a GOT entry. */
5375 long max_non_got_dynindx
;
5378 /* If H needs a GOT entry, assign it the highest available dynamic
5379 index. Otherwise, assign it the lowest available dynamic
5383 mips_elf_sort_hash_table_f (h
, data
)
5384 struct mips_elf_link_hash_entry
*h
;
5387 struct mips_elf_hash_sort_data
*hsd
5388 = (struct mips_elf_hash_sort_data
*) data
;
5390 /* Symbols without dynamic symbol table entries aren't interesting
5392 if (h
->root
.dynindx
== -1)
5395 if (h
->root
.got
.offset
!= 0)
5396 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
5399 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
5400 hsd
->low
= (struct elf_link_hash_entry
*) h
;
5406 /* Sort the dynamic symbol table so that symbols that need GOT entries
5407 appear towards the end. This reduces the amount of GOT space
5408 required. MAX_LOCAL is used to set the number of local symbols
5409 known to be in the dynamic symbol table. During
5410 mips_elf_size_dynamic_sections, this value is 1. Afterward, the
5411 section symbols are added and the count is higher. */
5414 mips_elf_sort_hash_table (info
, max_local
)
5415 struct bfd_link_info
*info
;
5416 unsigned long max_local
;
5418 struct mips_elf_hash_sort_data hsd
;
5419 struct mips_got_info
*g
;
5422 dynobj
= elf_hash_table (info
)->dynobj
;
5425 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
;
5426 hsd
.max_non_got_dynindx
= max_local
;
5427 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
5428 elf_hash_table (info
)),
5429 mips_elf_sort_hash_table_f
,
5432 /* There shoud have been enough room in the symbol table to
5433 accomodate both the GOT and non-GOT symbols. */
5434 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
5436 /* Now we know which dynamic symbol has the lowest dynamic symbol
5437 table index in the GOT. */
5438 g
= mips_elf_got_info (dynobj
, NULL
);
5439 g
->global_gotsym
= hsd
.low
;
5444 /* Create a local GOT entry for VALUE. Return the index of the entry,
5445 or -1 if it could not be created. */
5448 mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
)
5450 struct mips_got_info
*g
;
5454 if (g
->assigned_gotno
>= g
->local_gotno
)
5456 /* We didn't allocate enough space in the GOT. */
5457 (*_bfd_error_handler
)
5458 (_("not enough GOT space for local GOT entries"));
5459 bfd_set_error (bfd_error_bad_value
);
5460 return (bfd_vma
) -1;
5463 MIPS_ELF_PUT_WORD (abfd
, value
,
5465 + MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
));
5466 return MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
5469 /* Returns the GOT offset at which the indicated address can be found.
5470 If there is not yet a GOT entry for this value, create one. Returns
5471 -1 if no satisfactory GOT offset can be found. */
5474 mips_elf_local_got_index (abfd
, info
, value
)
5476 struct bfd_link_info
*info
;
5480 struct mips_got_info
*g
;
5483 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
5485 /* Look to see if we already have an appropriate entry. */
5486 for (entry
= (sgot
->contents
5487 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
5488 entry
!= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
5489 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
5491 bfd_vma address
= MIPS_ELF_GET_WORD (abfd
, entry
);
5492 if (address
== value
)
5493 return entry
- sgot
->contents
;
5496 return mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
5499 /* Find a GOT entry that is within 32KB of the VALUE. These entries
5500 are supposed to be placed at small offsets in the GOT, i.e.,
5501 within 32KB of GP. Return the index into the GOT for this page,
5502 and store the offset from this entry to the desired address in
5503 OFFSETP, if it is non-NULL. */
5506 mips_elf_got_page (abfd
, info
, value
, offsetp
)
5508 struct bfd_link_info
*info
;
5513 struct mips_got_info
*g
;
5515 bfd_byte
*last_entry
;
5519 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
5521 /* Look to see if we aleady have an appropriate entry. */
5522 last_entry
= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
5523 for (entry
= (sgot
->contents
5524 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
5525 entry
!= last_entry
;
5526 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
5528 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
5530 if (!mips_elf_overflow_p (value
- address
, 16))
5532 /* This entry will serve as the page pointer. We can add a
5533 16-bit number to it to get the actual address. */
5534 index
= entry
- sgot
->contents
;
5539 /* If we didn't have an appropriate entry, we create one now. */
5540 if (entry
== last_entry
)
5541 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
5545 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
5546 *offsetp
= value
- address
;
5552 /* Find a GOT entry whose higher-order 16 bits are the same as those
5553 for value. Return the index into the GOT for this entry. */
5556 mips_elf_got16_entry (abfd
, info
, value
, external
)
5558 struct bfd_link_info
*info
;
5563 struct mips_got_info
*g
;
5565 bfd_byte
*last_entry
;
5571 /* Although the ABI says that it is "the high-order 16 bits" that we
5572 want, it is really the %high value. The complete value is
5573 calculated with a `addiu' of a LO16 relocation, just as with a
5575 value
= mips_elf_high (value
) << 16;
5578 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
5580 /* Look to see if we already have an appropriate entry. */
5581 last_entry
= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
5582 for (entry
= (sgot
->contents
5583 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
5584 entry
!= last_entry
;
5585 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
5587 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
5588 if (address
== value
)
5590 /* This entry has the right high-order 16 bits, and the low-order
5591 16 bits are set to zero. */
5592 index
= entry
- sgot
->contents
;
5597 /* If we didn't have an appropriate entry, we create one now. */
5598 if (entry
== last_entry
)
5599 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
5604 /* Returns the first relocation of type r_type found, beginning with
5605 RELOCATION. RELEND is one-past-the-end of the relocation table. */
5607 static const Elf_Internal_Rela
*
5608 mips_elf_next_relocation (r_type
, relocation
, relend
)
5609 unsigned int r_type
;
5610 const Elf_Internal_Rela
*relocation
;
5611 const Elf_Internal_Rela
*relend
;
5613 /* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be
5614 immediately following. However, for the IRIX6 ABI, the next
5615 relocation may be a composed relocation consisting of several
5616 relocations for the same address. In that case, the R_MIPS_LO16
5617 relocation may occur as one of these. We permit a similar
5618 extension in general, as that is useful for GCC. */
5619 while (relocation
< relend
)
5621 if (ELF32_R_TYPE (relocation
->r_info
) == r_type
)
5627 /* We didn't find it. */
5628 bfd_set_error (bfd_error_bad_value
);
5632 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
5633 is the original relocation, which is now being transformed into a
5634 dynamic relocation. The ADDENDP is adjusted if necessary; the
5635 caller should store the result in place of the original addend. */
5638 mips_elf_create_dynamic_relocation (output_bfd
, info
, rel
, h
, sec
,
5639 symbol
, addendp
, input_section
)
5641 struct bfd_link_info
*info
;
5642 const Elf_Internal_Rela
*rel
;
5643 struct mips_elf_link_hash_entry
*h
;
5647 asection
*input_section
;
5649 Elf_Internal_Rel outrel
;
5655 r_type
= ELF32_R_TYPE (rel
->r_info
);
5656 dynobj
= elf_hash_table (info
)->dynobj
;
5658 = bfd_get_section_by_name (dynobj
,
5659 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd
));
5660 BFD_ASSERT (sreloc
!= NULL
);
5661 BFD_ASSERT (sreloc
->contents
!= NULL
);
5665 /* We begin by assuming that the offset for the dynamic relocation
5666 is the same as for the original relocation. We'll adjust this
5667 later to reflect the correct output offsets. */
5668 if (elf_section_data (input_section
)->stab_info
== NULL
)
5669 outrel
.r_offset
= rel
->r_offset
;
5672 /* Except that in a stab section things are more complex.
5673 Because we compress stab information, the offset given in the
5674 relocation may not be the one we want; we must let the stabs
5675 machinery tell us the offset. */
5677 = (_bfd_stab_section_offset
5678 (output_bfd
, &elf_hash_table (info
)->stab_info
,
5680 &elf_section_data (input_section
)->stab_info
,
5682 /* If we didn't need the relocation at all, this value will be
5684 if (outrel
.r_offset
== (bfd_vma
) -1)
5688 /* If we've decided to skip this relocation, just output an empty
5689 record. Note that R_MIPS_NONE == 0, so that this call to memset
5690 is a way of setting R_TYPE to R_MIPS_NONE. */
5692 memset (&outrel
, 0, sizeof (outrel
));
5696 bfd_vma section_offset
;
5698 /* We must now calculate the dynamic symbol table index to use
5699 in the relocation. */
5701 && (! info
->symbolic
|| (h
->root
.elf_link_hash_flags
5702 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5704 indx
= h
->root
.dynindx
;
5705 /* h->root.dynindx may be -1 if this symbol was marked to
5712 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5714 else if (sec
== NULL
|| sec
->owner
== NULL
)
5716 bfd_set_error (bfd_error_bad_value
);
5721 indx
= elf_section_data (sec
->output_section
)->dynindx
;
5726 /* Figure out how far the target of the relocation is from
5727 the beginning of its section. */
5728 section_offset
= symbol
- sec
->output_section
->vma
;
5729 /* The relocation we're building is section-relative.
5730 Therefore, the original addend must be adjusted by the
5732 *addendp
+= symbol
- sec
->output_section
->vma
;
5733 /* Now, the relocation is just against the section. */
5734 symbol
= sec
->output_section
->vma
;
5737 /* If the relocation was previously an absolute relocation, we
5738 must adjust it by the value we give it in the dynamic symbol
5740 if (r_type
!= R_MIPS_REL32
)
5743 /* The relocation is always an REL32 relocation because we don't
5744 know where the shared library will wind up at load-time. */
5745 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
5747 /* Adjust the output offset of the relocation to reference the
5748 correct location in the output file. */
5749 outrel
.r_offset
+= (input_section
->output_section
->vma
5750 + input_section
->output_offset
);
5753 /* Put the relocation back out. We have to use the special
5754 relocation outputter in the 64-bit case since the 64-bit
5755 relocation format is non-standard. */
5756 if (ABI_64_P (output_bfd
))
5758 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
5759 (output_bfd
, &outrel
,
5761 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
5764 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
5765 (((Elf32_External_Rel
*)
5767 + sreloc
->reloc_count
));
5769 /* Record the index of the first relocation referencing H. This
5770 information is later emitted in the .msym section. */
5772 && (h
->min_dyn_reloc_index
== 0
5773 || sreloc
->reloc_count
< h
->min_dyn_reloc_index
))
5774 h
->min_dyn_reloc_index
= sreloc
->reloc_count
;
5776 /* We've now added another relocation. */
5777 ++sreloc
->reloc_count
;
5779 /* Make sure the output section is writable. The dynamic linker
5780 will be writing to it. */
5781 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
5784 /* On IRIX5, make an entry of compact relocation info. */
5785 if (! skip
&& IRIX_COMPAT (output_bfd
) == ict_irix5
)
5787 asection
* scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5792 Elf32_crinfo cptrel
;
5794 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5795 cptrel
.vaddr
= (rel
->r_offset
5796 + input_section
->output_section
->vma
5797 + input_section
->output_offset
);
5798 if (r_type
== R_MIPS_REL32
)
5799 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5801 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5802 mips_elf_set_cr_dist2to (cptrel
, 0);
5803 cptrel
.konst
= *addendp
;
5805 cr
= (scpt
->contents
5806 + sizeof (Elf32_External_compact_rel
));
5807 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5808 ((Elf32_External_crinfo
*) cr
5809 + scpt
->reloc_count
));
5810 ++scpt
->reloc_count
;
5817 /* Calculate the value produced by the RELOCATION (which comes from
5818 the INPUT_BFD). The ADDEND is the addend to use for this
5819 RELOCATION; RELOCATION->R_ADDEND is ignored.
5821 The result of the relocation calculation is stored in VALUEP.
5822 REQUIRE_JALXP indicates whether or not the opcode used with this
5823 relocation must be JALX.
5825 This function returns bfd_reloc_continue if the caller need take no
5826 further action regarding this relocation, bfd_reloc_notsupported if
5827 something goes dramatically wrong, bfd_reloc_overflow if an
5828 overflow occurs, and bfd_reloc_ok to indicate success. */
5830 static bfd_reloc_status_type
5831 mips_elf_calculate_relocation (abfd
,
5845 asection
*input_section
;
5846 struct bfd_link_info
*info
;
5847 const Elf_Internal_Rela
*relocation
;
5849 reloc_howto_type
*howto
;
5850 Elf_Internal_Sym
*local_syms
;
5851 asection
**local_sections
;
5854 boolean
*require_jalxp
;
5856 /* The eventual value we will return. */
5858 /* The address of the symbol against which the relocation is
5861 /* The final GP value to be used for the relocatable, executable, or
5862 shared object file being produced. */
5863 bfd_vma gp
= (bfd_vma
) - 1;
5864 /* The place (section offset or address) of the storage unit being
5867 /* The value of GP used to create the relocatable object. */
5868 bfd_vma gp0
= (bfd_vma
) - 1;
5869 /* The offset into the global offset table at which the address of
5870 the relocation entry symbol, adjusted by the addend, resides
5871 during execution. */
5872 bfd_vma g
= (bfd_vma
) - 1;
5873 /* The section in which the symbol referenced by the relocation is
5875 asection
*sec
= NULL
;
5876 struct mips_elf_link_hash_entry
* h
= NULL
;
5877 /* True if the symbol referred to by this relocation is a local
5880 /* True if the symbol referred to by this relocation is "_gp_disp". */
5881 boolean gp_disp_p
= false;
5882 Elf_Internal_Shdr
*symtab_hdr
;
5884 unsigned long r_symndx
;
5886 /* True if overflow occurred during the calculation of the
5887 relocation value. */
5888 boolean overflowed_p
;
5889 /* True if this relocation refers to a MIPS16 function. */
5890 boolean target_is_16_bit_code_p
= false;
5892 /* Parse the relocation. */
5893 r_symndx
= ELF32_R_SYM (relocation
->r_info
);
5894 r_type
= ELF32_R_TYPE (relocation
->r_info
);
5895 p
= (input_section
->output_section
->vma
5896 + input_section
->output_offset
5897 + relocation
->r_offset
);
5899 /* Assume that there will be no overflow. */
5900 overflowed_p
= false;
5902 /* Figure out whether or not the symbol is local, and get the offset
5903 used in the array of hash table entries. */
5904 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5905 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
5906 local_sections
, false);
5907 if (! elf_bad_symtab (input_bfd
))
5908 extsymoff
= symtab_hdr
->sh_info
;
5911 /* The symbol table does not follow the rule that local symbols
5912 must come before globals. */
5916 /* Figure out the value of the symbol. */
5919 Elf_Internal_Sym
*sym
;
5921 sym
= local_syms
+ r_symndx
;
5922 sec
= local_sections
[r_symndx
];
5924 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
5925 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5926 symbol
+= sym
->st_value
;
5928 /* MIPS16 text labels should be treated as odd. */
5929 if (sym
->st_other
== STO_MIPS16
)
5932 /* Record the name of this symbol, for our caller. */
5933 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
5934 symtab_hdr
->sh_link
,
5937 *namep
= bfd_section_name (input_bfd
, sec
);
5939 target_is_16_bit_code_p
= (sym
->st_other
== STO_MIPS16
);
5943 /* For global symbols we look up the symbol in the hash-table. */
5944 h
= ((struct mips_elf_link_hash_entry
*)
5945 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
5946 /* Find the real hash-table entry for this symbol. */
5947 while (h
->root
.root
.type
== bfd_link_hash_indirect
5948 || h
->root
.root
.type
== bfd_link_hash_warning
)
5949 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
5951 /* Record the name of this symbol, for our caller. */
5952 *namep
= h
->root
.root
.root
.string
;
5954 /* See if this is the special _gp_disp symbol. Note that such a
5955 symbol must always be a global symbol. */
5956 if (strcmp (h
->root
.root
.root
.string
, "_gp_disp") == 0)
5958 /* Relocations against _gp_disp are permitted only with
5959 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
5960 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_LO16
)
5961 return bfd_reloc_notsupported
;
5965 /* If this symbol is defined, calculate its address. Note that
5966 _gp_disp is a magic symbol, always implicitly defined by the
5967 linker, so it's inappropriate to check to see whether or not
5969 else if ((h
->root
.root
.type
== bfd_link_hash_defined
5970 || h
->root
.root
.type
== bfd_link_hash_defweak
)
5971 && h
->root
.root
.u
.def
.section
)
5973 sec
= h
->root
.root
.u
.def
.section
;
5974 if (sec
->output_section
)
5975 symbol
= (h
->root
.root
.u
.def
.value
5976 + sec
->output_section
->vma
5977 + sec
->output_offset
);
5979 symbol
= h
->root
.root
.u
.def
.value
;
5981 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
5982 /* We allow relocations against undefined weak symbols, giving
5983 it the value zero, so that you can undefined weak functions
5984 and check to see if they exist by looking at their
5987 else if (info
->shared
&& !info
->symbolic
&& !info
->no_undefined
5988 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
5990 else if (strcmp (h
->root
.root
.root
.string
, "_DYNAMIC_LINK") == 0)
5992 /* If this is a dynamic link, we should have created a
5993 _DYNAMIC_LINK symbol in mips_elf_create_dynamic_sections.
5994 Otherwise, we should define the symbol with a value of 0.
5995 FIXME: It should probably get into the symbol table
5997 BFD_ASSERT (! info
->shared
);
5998 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
6003 if (! ((*info
->callbacks
->undefined_symbol
)
6004 (info
, h
->root
.root
.root
.string
, input_bfd
,
6005 input_section
, relocation
->r_offset
,
6006 (!info
->shared
|| info
->no_undefined
6007 || ELF_ST_VISIBILITY (h
->root
.other
)))))
6008 return bfd_reloc_undefined
;
6012 target_is_16_bit_code_p
= (h
->root
.other
== STO_MIPS16
);
6015 /* If this is a 32-bit call to a 16-bit function with a stub, we
6016 need to redirect the call to the stub, unless we're already *in*
6018 if (r_type
!= R_MIPS16_26
&& !info
->relocateable
6019 && ((h
!= NULL
&& h
->fn_stub
!= NULL
)
6020 || (local_p
&& elf_tdata (input_bfd
)->local_stubs
!= NULL
6021 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
6022 && !mips_elf_stub_section_p (input_bfd
, input_section
))
6024 /* This is a 32-bit call to a 16-bit function. We should
6025 have already noticed that we were going to need the
6028 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
6031 BFD_ASSERT (h
->need_fn_stub
);
6035 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
6037 /* If this is a 16-bit call to a 32-bit function with a stub, we
6038 need to redirect the call to the stub. */
6039 else if (r_type
== R_MIPS16_26
&& !info
->relocateable
6041 && (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
)
6042 && !target_is_16_bit_code_p
)
6044 /* If both call_stub and call_fp_stub are defined, we can figure
6045 out which one to use by seeing which one appears in the input
6047 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
6052 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
6054 if (strncmp (bfd_get_section_name (input_bfd
, o
),
6055 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6057 sec
= h
->call_fp_stub
;
6064 else if (h
->call_stub
!= NULL
)
6067 sec
= h
->call_fp_stub
;
6069 BFD_ASSERT (sec
->_raw_size
> 0);
6070 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
6073 /* Calls from 16-bit code to 32-bit code and vice versa require the
6074 special jalx instruction. */
6075 *require_jalxp
= (!info
->relocateable
6076 && ((r_type
== R_MIPS16_26
) != target_is_16_bit_code_p
));
6078 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
6079 local_sections
, true);
6081 /* If we haven't already determined the GOT offset, or the GP value,
6082 and we're going to need it, get it now. */
6087 case R_MIPS_GOT_DISP
:
6088 case R_MIPS_GOT_HI16
:
6089 case R_MIPS_CALL_HI16
:
6090 case R_MIPS_GOT_LO16
:
6091 case R_MIPS_CALL_LO16
:
6092 /* Find the index into the GOT where this value is located. */
6095 BFD_ASSERT (addend
== 0);
6096 g
= mips_elf_global_got_index
6097 (elf_hash_table (info
)->dynobj
,
6098 (struct elf_link_hash_entry
*) h
);
6099 if (! elf_hash_table(info
)->dynamic_sections_created
6101 && (info
->symbolic
|| h
->root
.dynindx
== -1)
6102 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
6104 /* This is a static link or a -Bsymbolic link. The
6105 symbol is defined locally, or was forced to be local.
6106 We must initialize this entry in the GOT. */
6107 asection
*sgot
= mips_elf_got_section(elf_hash_table
6109 MIPS_ELF_PUT_WORD (elf_hash_table (info
)->dynobj
,
6110 symbol
+ addend
, sgot
->contents
+ g
);
6113 else if (r_type
== R_MIPS_GOT16
)
6114 /* There's no need to create a local GOT entry here; the
6115 calculation for a local GOT16 entry does not involve G. */
6119 g
= mips_elf_local_got_index (abfd
, info
, symbol
+ addend
);
6120 if (g
== (bfd_vma
) -1)
6124 /* Convert GOT indices to actual offsets. */
6125 g
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
6131 case R_MIPS_GPREL16
:
6132 case R_MIPS_GPREL32
:
6133 case R_MIPS_LITERAL
:
6134 gp0
= _bfd_get_gp_value (input_bfd
);
6135 gp
= _bfd_get_gp_value (abfd
);
6142 /* Figure out what kind of relocation is being performed. */
6146 return bfd_reloc_continue
;
6149 value
= symbol
+ mips_elf_sign_extend (addend
, 16);
6150 overflowed_p
= mips_elf_overflow_p (value
, 16);
6157 || (elf_hash_table (info
)->dynamic_sections_created
6159 && ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)
6161 && (input_section
->flags
& SEC_ALLOC
) != 0)
6163 /* If we're creating a shared library, or this relocation is
6164 against a symbol in a shared library, then we can't know
6165 where the symbol will end up. So, we create a relocation
6166 record in the output, and leave the job up to the dynamic
6169 if (!mips_elf_create_dynamic_relocation (abfd
,
6181 if (r_type
!= R_MIPS_REL32
)
6182 value
= symbol
+ addend
;
6186 value
&= howto
->dst_mask
;
6191 case R_MIPS_GNU_REL_LO16
:
6192 value
= symbol
+ addend
- p
;
6193 value
&= howto
->dst_mask
;
6196 case R_MIPS_GNU_REL16_S2
:
6197 value
= symbol
+ mips_elf_sign_extend (addend
<< 2, 18) - p
;
6198 overflowed_p
= mips_elf_overflow_p (value
, 18);
6199 value
= (value
>> 2) & howto
->dst_mask
;
6202 case R_MIPS_GNU_REL_HI16
:
6203 value
= mips_elf_high (addend
+ symbol
- p
);
6204 value
&= howto
->dst_mask
;
6208 /* The calculation for R_MIPS_26 is just the same as for an
6209 R_MIPS_26. It's only the storage of the relocated field into
6210 the output file that's different. That's handled in
6211 mips_elf_perform_relocation. So, we just fall through to the
6212 R_MIPS_26 case here. */
6215 value
= (((addend
<< 2) | (p
& 0xf0000000)) + symbol
) >> 2;
6217 value
= (mips_elf_sign_extend (addend
<< 2, 28) + symbol
) >> 2;
6218 value
&= howto
->dst_mask
;
6224 value
= mips_elf_high (addend
+ symbol
);
6225 value
&= howto
->dst_mask
;
6229 value
= mips_elf_high (addend
+ gp
- p
);
6230 overflowed_p
= mips_elf_overflow_p (value
, 16);
6236 value
= (symbol
+ addend
) & howto
->dst_mask
;
6239 value
= addend
+ gp
- p
+ 4;
6240 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
6241 for overflow. But, on, say, Irix 5, relocations against
6242 _gp_disp are normally generated from the .cpload
6243 pseudo-op. It generates code that normally looks like
6246 lui $gp,%hi(_gp_disp)
6247 addiu $gp,$gp,%lo(_gp_disp)
6250 Here $t9 holds the address of the function being called,
6251 as required by the MIPS ELF ABI. The R_MIPS_LO16
6252 relocation can easily overflow in this situation, but the
6253 R_MIPS_HI16 relocation will handle the overflow.
6254 Therefore, we consider this a bug in the MIPS ABI, and do
6255 not check for overflow here. */
6259 case R_MIPS_LITERAL
:
6260 /* Because we don't merge literal sections, we can handle this
6261 just like R_MIPS_GPREL16. In the long run, we should merge
6262 shared literals, and then we will need to additional work
6267 case R_MIPS16_GPREL
:
6268 /* The R_MIPS16_GPREL performs the same calculation as
6269 R_MIPS_GPREL16, but stores the relocated bits in a different
6270 order. We don't need to do anything special here; the
6271 differences are handled in mips_elf_perform_relocation. */
6272 case R_MIPS_GPREL16
:
6274 value
= mips_elf_sign_extend (addend
, 16) + symbol
+ gp0
- gp
;
6276 value
= mips_elf_sign_extend (addend
, 16) + symbol
- gp
;
6277 overflowed_p
= mips_elf_overflow_p (value
, 16);
6285 /* The special case is when the symbol is forced to be local. We
6286 need the full address in the GOT since no R_MIPS_LO16 relocation
6288 forced
= ! mips_elf_local_relocation_p (input_bfd
, relocation
,
6289 local_sections
, false);
6290 value
= mips_elf_got16_entry (abfd
, info
, symbol
+ addend
, forced
);
6291 if (value
== (bfd_vma
) -1)
6294 = mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
6297 overflowed_p
= mips_elf_overflow_p (value
, 16);
6304 case R_MIPS_GOT_DISP
:
6306 overflowed_p
= mips_elf_overflow_p (value
, 16);
6309 case R_MIPS_GPREL32
:
6310 value
= (addend
+ symbol
+ gp0
- gp
) & howto
->dst_mask
;
6314 value
= mips_elf_sign_extend (addend
, 16) + symbol
- p
;
6315 value
= (bfd_vma
) ((bfd_signed_vma
) value
/ 4);
6316 overflowed_p
= mips_elf_overflow_p (value
, 16);
6319 case R_MIPS_GOT_HI16
:
6320 case R_MIPS_CALL_HI16
:
6321 /* We're allowed to handle these two relocations identically.
6322 The dynamic linker is allowed to handle the CALL relocations
6323 differently by creating a lazy evaluation stub. */
6325 value
= mips_elf_high (value
);
6326 value
&= howto
->dst_mask
;
6329 case R_MIPS_GOT_LO16
:
6330 case R_MIPS_CALL_LO16
:
6331 value
= g
& howto
->dst_mask
;
6334 case R_MIPS_GOT_PAGE
:
6335 value
= mips_elf_got_page (abfd
, info
, symbol
+ addend
, NULL
);
6336 if (value
== (bfd_vma
) -1)
6338 value
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
6341 overflowed_p
= mips_elf_overflow_p (value
, 16);
6344 case R_MIPS_GOT_OFST
:
6345 mips_elf_got_page (abfd
, info
, symbol
+ addend
, &value
);
6346 overflowed_p
= mips_elf_overflow_p (value
, 16);
6350 value
= symbol
- addend
;
6351 value
&= howto
->dst_mask
;
6355 value
= mips_elf_higher (addend
+ symbol
);
6356 value
&= howto
->dst_mask
;
6359 case R_MIPS_HIGHEST
:
6360 value
= mips_elf_highest (addend
+ symbol
);
6361 value
&= howto
->dst_mask
;
6364 case R_MIPS_SCN_DISP
:
6365 value
= symbol
+ addend
- sec
->output_offset
;
6366 value
&= howto
->dst_mask
;
6371 /* Both of these may be ignored. R_MIPS_JALR is an optimization
6372 hint; we could improve performance by honoring that hint. */
6373 return bfd_reloc_continue
;
6375 case R_MIPS_GNU_VTINHERIT
:
6376 case R_MIPS_GNU_VTENTRY
:
6377 /* We don't do anything with these at present. */
6378 return bfd_reloc_continue
;
6381 /* An unrecognized relocation type. */
6382 return bfd_reloc_notsupported
;
6385 /* Store the VALUE for our caller. */
6387 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
6390 /* Obtain the field relocated by RELOCATION. */
6393 mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
)
6394 reloc_howto_type
*howto
;
6395 const Elf_Internal_Rela
*relocation
;
6400 bfd_byte
*location
= contents
+ relocation
->r_offset
;
6402 /* Obtain the bytes. */
6403 x
= bfd_get (8 * bfd_get_reloc_size (howto
), input_bfd
, location
);
6405 if ((ELF32_R_TYPE (relocation
->r_info
) == R_MIPS16_26
6406 || ELF32_R_TYPE (relocation
->r_info
) == R_MIPS16_GPREL
)
6407 && bfd_little_endian (input_bfd
))
6408 /* The two 16-bit words will be reversed on a little-endian
6409 system. See mips_elf_perform_relocation for more details. */
6410 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
6415 /* It has been determined that the result of the RELOCATION is the
6416 VALUE. Use HOWTO to place VALUE into the output file at the
6417 appropriate position. The SECTION is the section to which the
6418 relocation applies. If REQUIRE_JALX is true, then the opcode used
6419 for the relocation must be either JAL or JALX, and it is
6420 unconditionally converted to JALX.
6422 Returns false if anything goes wrong. */
6425 mips_elf_perform_relocation (info
, howto
, relocation
, value
,
6426 input_bfd
, input_section
,
6427 contents
, require_jalx
)
6428 struct bfd_link_info
*info
;
6429 reloc_howto_type
*howto
;
6430 const Elf_Internal_Rela
*relocation
;
6433 asection
*input_section
;
6435 boolean require_jalx
;
6439 int r_type
= ELF32_R_TYPE (relocation
->r_info
);
6441 /* Figure out where the relocation is occurring. */
6442 location
= contents
+ relocation
->r_offset
;
6444 /* Obtain the current value. */
6445 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
6447 /* Clear the field we are setting. */
6448 x
&= ~howto
->dst_mask
;
6450 /* If this is the R_MIPS16_26 relocation, we must store the
6451 value in a funny way. */
6452 if (r_type
== R_MIPS16_26
)
6454 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
6455 Most mips16 instructions are 16 bits, but these instructions
6458 The format of these instructions is:
6460 +--------------+--------------------------------+
6461 ! JALX ! X! Imm 20:16 ! Imm 25:21 !
6462 +--------------+--------------------------------+
6464 +-----------------------------------------------+
6466 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
6467 Note that the immediate value in the first word is swapped.
6469 When producing a relocateable object file, R_MIPS16_26 is
6470 handled mostly like R_MIPS_26. In particular, the addend is
6471 stored as a straight 26-bit value in a 32-bit instruction.
6472 (gas makes life simpler for itself by never adjusting a
6473 R_MIPS16_26 reloc to be against a section, so the addend is
6474 always zero). However, the 32 bit instruction is stored as 2
6475 16-bit values, rather than a single 32-bit value. In a
6476 big-endian file, the result is the same; in a little-endian
6477 file, the two 16-bit halves of the 32 bit value are swapped.
6478 This is so that a disassembler can recognize the jal
6481 When doing a final link, R_MIPS16_26 is treated as a 32 bit
6482 instruction stored as two 16-bit values. The addend A is the
6483 contents of the targ26 field. The calculation is the same as
6484 R_MIPS_26. When storing the calculated value, reorder the
6485 immediate value as shown above, and don't forget to store the
6486 value as two 16-bit values.
6488 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
6492 +--------+----------------------+
6496 +--------+----------------------+
6499 +----------+------+-------------+
6503 +----------+--------------------+
6504 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
6505 ((sub1 << 16) | sub2)).
6507 When producing a relocateable object file, the calculation is
6508 (((A < 2) | (P & 0xf0000000) + S) >> 2)
6509 When producing a fully linked file, the calculation is
6510 let R = (((A < 2) | (P & 0xf0000000) + S) >> 2)
6511 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff) */
6513 if (!info
->relocateable
)
6514 /* Shuffle the bits according to the formula above. */
6515 value
= (((value
& 0x1f0000) << 5)
6516 | ((value
& 0x3e00000) >> 5)
6517 | (value
& 0xffff));
6520 else if (r_type
== R_MIPS16_GPREL
)
6522 /* R_MIPS16_GPREL is used for GP-relative addressing in mips16
6523 mode. A typical instruction will have a format like this:
6525 +--------------+--------------------------------+
6526 ! EXTEND ! Imm 10:5 ! Imm 15:11 !
6527 +--------------+--------------------------------+
6528 ! Major ! rx ! ry ! Imm 4:0 !
6529 +--------------+--------------------------------+
6531 EXTEND is the five bit value 11110. Major is the instruction
6534 This is handled exactly like R_MIPS_GPREL16, except that the
6535 addend is retrieved and stored as shown in this diagram; that
6536 is, the Imm fields above replace the V-rel16 field.
6538 All we need to do here is shuffle the bits appropriately. As
6539 above, the two 16-bit halves must be swapped on a
6540 little-endian system. */
6541 value
= (((value
& 0x7e0) << 16)
6542 | ((value
& 0xf800) << 5)
6546 /* Set the field. */
6547 x
|= (value
& howto
->dst_mask
);
6549 /* If required, turn JAL into JALX. */
6553 bfd_vma opcode
= x
>> 26;
6554 bfd_vma jalx_opcode
;
6556 /* Check to see if the opcode is already JAL or JALX. */
6557 if (r_type
== R_MIPS16_26
)
6559 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
6564 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
6568 /* If the opcode is not JAL or JALX, there's a problem. */
6571 (*_bfd_error_handler
)
6572 (_("%s: %s+0x%lx: jump to stub routine which is not jal"),
6573 bfd_get_filename (input_bfd
),
6574 input_section
->name
,
6575 (unsigned long) relocation
->r_offset
);
6576 bfd_set_error (bfd_error_bad_value
);
6580 /* Make this the JALX opcode. */
6581 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
6584 /* Swap the high- and low-order 16 bits on little-endian systems
6585 when doing a MIPS16 relocation. */
6586 if ((r_type
== R_MIPS16_GPREL
|| r_type
== R_MIPS16_26
)
6587 && bfd_little_endian (input_bfd
))
6588 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
6590 /* Put the value into the output. */
6591 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
6595 /* Returns true if SECTION is a MIPS16 stub section. */
6598 mips_elf_stub_section_p (abfd
, section
)
6599 bfd
*abfd ATTRIBUTE_UNUSED
;
6602 const char *name
= bfd_get_section_name (abfd
, section
);
6604 return (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0
6605 || strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
6606 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0);
6609 /* Relocate a MIPS ELF section. */
6612 _bfd_mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
6613 contents
, relocs
, local_syms
, local_sections
)
6615 struct bfd_link_info
*info
;
6617 asection
*input_section
;
6619 Elf_Internal_Rela
*relocs
;
6620 Elf_Internal_Sym
*local_syms
;
6621 asection
**local_sections
;
6623 Elf_Internal_Rela
*rel
;
6624 const Elf_Internal_Rela
*relend
;
6626 boolean use_saved_addend_p
= false;
6627 struct elf_backend_data
*bed
;
6629 bed
= get_elf_backend_data (output_bfd
);
6630 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
6631 for (rel
= relocs
; rel
< relend
; ++rel
)
6635 reloc_howto_type
*howto
;
6636 boolean require_jalx
;
6637 /* True if the relocation is a RELA relocation, rather than a
6639 boolean rela_relocation_p
= true;
6640 int r_type
= ELF32_R_TYPE (rel
->r_info
);
6642 /* Find the relocation howto for this relocation. */
6643 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
))
6645 /* Some 32-bit code uses R_MIPS_64. In particular, people use
6646 64-bit code, but make sure all their addresses are in the
6647 lowermost or uppermost 32-bit section of the 64-bit address
6648 space. Thus, when they use an R_MIPS_64 they mean what is
6649 usually meant by R_MIPS_32, with the exception that the
6650 stored value is sign-extended to 64 bits. */
6651 howto
= elf_mips_howto_table
+ R_MIPS_32
;
6653 /* On big-endian systems, we need to lie about the position
6655 if (bfd_big_endian (input_bfd
))
6659 howto
= mips_rtype_to_howto (r_type
);
6661 if (!use_saved_addend_p
)
6663 Elf_Internal_Shdr
*rel_hdr
;
6665 /* If these relocations were originally of the REL variety,
6666 we must pull the addend out of the field that will be
6667 relocated. Otherwise, we simply use the contents of the
6668 RELA relocation. To determine which flavor or relocation
6669 this is, we depend on the fact that the INPUT_SECTION's
6670 REL_HDR is read before its REL_HDR2. */
6671 rel_hdr
= &elf_section_data (input_section
)->rel_hdr
;
6672 if ((size_t) (rel
- relocs
)
6673 >= (rel_hdr
->sh_size
/ rel_hdr
->sh_entsize
6674 * bed
->s
->int_rels_per_ext_rel
))
6675 rel_hdr
= elf_section_data (input_section
)->rel_hdr2
;
6676 if (rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (input_bfd
))
6678 /* Note that this is a REL relocation. */
6679 rela_relocation_p
= false;
6681 /* Get the addend, which is stored in the input file. */
6682 addend
= mips_elf_obtain_contents (howto
,
6686 addend
&= howto
->src_mask
;
6688 /* For some kinds of relocations, the ADDEND is a
6689 combination of the addend stored in two different
6691 if (r_type
== R_MIPS_HI16
6692 || r_type
== R_MIPS_GNU_REL_HI16
6693 || (r_type
== R_MIPS_GOT16
6694 && mips_elf_local_relocation_p (input_bfd
, rel
,
6695 local_sections
, false)))
6698 const Elf_Internal_Rela
*lo16_relocation
;
6699 reloc_howto_type
*lo16_howto
;
6702 /* The combined value is the sum of the HI16 addend,
6703 left-shifted by sixteen bits, and the LO16
6704 addend, sign extended. (Usually, the code does
6705 a `lui' of the HI16 value, and then an `addiu' of
6708 Scan ahead to find a matching LO16 relocation. */
6709 if (r_type
== R_MIPS_GNU_REL_HI16
)
6710 lo
= R_MIPS_GNU_REL_LO16
;
6714 = mips_elf_next_relocation (lo
, rel
, relend
);
6715 if (lo16_relocation
== NULL
)
6718 /* Obtain the addend kept there. */
6719 lo16_howto
= mips_rtype_to_howto (lo
);
6720 l
= mips_elf_obtain_contents (lo16_howto
,
6722 input_bfd
, contents
);
6723 l
&= lo16_howto
->src_mask
;
6724 l
= mips_elf_sign_extend (l
, 16);
6728 /* Compute the combined addend. */
6731 else if (r_type
== R_MIPS16_GPREL
)
6733 /* The addend is scrambled in the object file. See
6734 mips_elf_perform_relocation for details on the
6736 addend
= (((addend
& 0x1f0000) >> 5)
6737 | ((addend
& 0x7e00000) >> 16)
6742 addend
= rel
->r_addend
;
6745 if (info
->relocateable
)
6747 Elf_Internal_Sym
*sym
;
6748 unsigned long r_symndx
;
6750 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
)
6751 && bfd_big_endian (input_bfd
))
6754 /* Since we're just relocating, all we need to do is copy
6755 the relocations back out to the object file, unless
6756 they're against a section symbol, in which case we need
6757 to adjust by the section offset, or unless they're GP
6758 relative in which case we need to adjust by the amount
6759 that we're adjusting GP in this relocateable object. */
6761 if (!mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
,
6763 /* There's nothing to do for non-local relocations. */
6766 if (r_type
== R_MIPS16_GPREL
6767 || r_type
== R_MIPS_GPREL16
6768 || r_type
== R_MIPS_GPREL32
6769 || r_type
== R_MIPS_LITERAL
)
6770 addend
-= (_bfd_get_gp_value (output_bfd
)
6771 - _bfd_get_gp_value (input_bfd
));
6772 else if (r_type
== R_MIPS_26
|| r_type
== R_MIPS16_26
6773 || r_type
== R_MIPS_GNU_REL16_S2
)
6774 /* The addend is stored without its two least
6775 significant bits (which are always zero.) In a
6776 non-relocateable link, calculate_relocation will do
6777 this shift; here, we must do it ourselves. */
6780 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6781 sym
= local_syms
+ r_symndx
;
6782 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
6783 /* Adjust the addend appropriately. */
6784 addend
+= local_sections
[r_symndx
]->output_offset
;
6786 /* If the relocation is for a R_MIPS_HI16 or R_MIPS_GOT16,
6787 then we only want to write out the high-order 16 bits.
6788 The subsequent R_MIPS_LO16 will handle the low-order bits. */
6789 if (r_type
== R_MIPS_HI16
|| r_type
== R_MIPS_GOT16
6790 || r_type
== R_MIPS_GNU_REL_HI16
)
6791 addend
= mips_elf_high (addend
);
6792 /* If the relocation is for an R_MIPS_26 relocation, then
6793 the two low-order bits are not stored in the object file;
6794 they are implicitly zero. */
6795 else if (r_type
== R_MIPS_26
|| r_type
== R_MIPS16_26
6796 || r_type
== R_MIPS_GNU_REL16_S2
)
6799 if (rela_relocation_p
)
6800 /* If this is a RELA relocation, just update the addend.
6801 We have to cast away constness for REL. */
6802 rel
->r_addend
= addend
;
6805 /* Otherwise, we have to write the value back out. Note
6806 that we use the source mask, rather than the
6807 destination mask because the place to which we are
6808 writing will be source of the addend in the final
6810 addend
&= howto
->src_mask
;
6812 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
))
6813 /* See the comment above about using R_MIPS_64 in the 32-bit
6814 ABI. Here, we need to update the addend. It would be
6815 possible to get away with just using the R_MIPS_32 reloc
6816 but for endianness. */
6822 if (addend
& ((bfd_vma
) 1 << 31))
6823 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
6827 /* If we don't know that we have a 64-bit type,
6828 do two separate stores. */
6829 if (bfd_big_endian (input_bfd
))
6831 /* Store the sign-bits (which are most significant)
6833 low_bits
= sign_bits
;
6839 high_bits
= sign_bits
;
6841 bfd_put_32 (input_bfd
, low_bits
,
6842 contents
+ rel
->r_offset
);
6843 bfd_put_32 (input_bfd
, high_bits
,
6844 contents
+ rel
->r_offset
+ 4);
6848 if (!mips_elf_perform_relocation (info
, howto
, rel
, addend
,
6849 input_bfd
, input_section
,
6854 /* Go on to the next relocation. */
6858 /* In the N32 and 64-bit ABIs there may be multiple consecutive
6859 relocations for the same offset. In that case we are
6860 supposed to treat the output of each relocation as the addend
6862 if (rel
+ 1 < relend
6863 && rel
->r_offset
== rel
[1].r_offset
6864 && ELF32_R_TYPE (rel
[1].r_info
) != R_MIPS_NONE
)
6865 use_saved_addend_p
= true;
6867 use_saved_addend_p
= false;
6869 /* Figure out what value we are supposed to relocate. */
6870 switch (mips_elf_calculate_relocation (output_bfd
,
6883 case bfd_reloc_continue
:
6884 /* There's nothing to do. */
6887 case bfd_reloc_undefined
:
6888 /* mips_elf_calculate_relocation already called the
6889 undefined_symbol callback. There's no real point in
6890 trying to perform the relocation at this point, so we
6891 just skip ahead to the next relocation. */
6894 case bfd_reloc_notsupported
:
6898 case bfd_reloc_overflow
:
6899 if (use_saved_addend_p
)
6900 /* Ignore overflow until we reach the last relocation for
6901 a given location. */
6905 BFD_ASSERT (name
!= NULL
);
6906 if (! ((*info
->callbacks
->reloc_overflow
)
6907 (info
, name
, howto
->name
, (bfd_vma
) 0,
6908 input_bfd
, input_section
, rel
->r_offset
)))
6921 /* If we've got another relocation for the address, keep going
6922 until we reach the last one. */
6923 if (use_saved_addend_p
)
6929 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
))
6930 /* See the comment above about using R_MIPS_64 in the 32-bit
6931 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
6932 that calculated the right value. Now, however, we
6933 sign-extend the 32-bit result to 64-bits, and store it as a
6934 64-bit value. We are especially generous here in that we
6935 go to extreme lengths to support this usage on systems with
6936 only a 32-bit VMA. */
6942 if (value
& ((bfd_vma
) 1 << 31))
6943 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
6947 /* If we don't know that we have a 64-bit type,
6948 do two separate stores. */
6949 if (bfd_big_endian (input_bfd
))
6951 /* Undo what we did above. */
6953 /* Store the sign-bits (which are most significant)
6955 low_bits
= sign_bits
;
6961 high_bits
= sign_bits
;
6963 bfd_put_32 (input_bfd
, low_bits
,
6964 contents
+ rel
->r_offset
);
6965 bfd_put_32 (input_bfd
, high_bits
,
6966 contents
+ rel
->r_offset
+ 4);
6970 /* Actually perform the relocation. */
6971 if (!mips_elf_perform_relocation (info
, howto
, rel
, value
, input_bfd
,
6972 input_section
, contents
,
6980 /* This hook function is called before the linker writes out a global
6981 symbol. We mark symbols as small common if appropriate. This is
6982 also where we undo the increment of the value for a mips16 symbol. */
6986 _bfd_mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
6987 bfd
*abfd ATTRIBUTE_UNUSED
;
6988 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
6989 const char *name ATTRIBUTE_UNUSED
;
6990 Elf_Internal_Sym
*sym
;
6991 asection
*input_sec
;
6993 /* If we see a common symbol, which implies a relocatable link, then
6994 if a symbol was small common in an input file, mark it as small
6995 common in the output file. */
6996 if (sym
->st_shndx
== SHN_COMMON
6997 && strcmp (input_sec
->name
, ".scommon") == 0)
6998 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
7000 if (sym
->st_other
== STO_MIPS16
7001 && (sym
->st_value
& 1) != 0)
7007 /* Functions for the dynamic linker. */
7009 /* The name of the dynamic interpreter. This is put in the .interp
7012 #define ELF_DYNAMIC_INTERPRETER(abfd) \
7013 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
7014 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
7015 : "/usr/lib/libc.so.1")
7017 /* Create dynamic sections when linking against a dynamic object. */
7020 _bfd_mips_elf_create_dynamic_sections (abfd
, info
)
7022 struct bfd_link_info
*info
;
7024 struct elf_link_hash_entry
*h
;
7026 register asection
*s
;
7027 const char * const *namep
;
7029 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7030 | SEC_LINKER_CREATED
| SEC_READONLY
);
7032 /* Mips ABI requests the .dynamic section to be read only. */
7033 s
= bfd_get_section_by_name (abfd
, ".dynamic");
7036 if (! bfd_set_section_flags (abfd
, s
, flags
))
7040 /* We need to create .got section. */
7041 if (! mips_elf_create_got_section (abfd
, info
))
7044 /* Create the .msym section on IRIX6. It is used by the dynamic
7045 linker to speed up dynamic relocations, and to avoid computing
7046 the ELF hash for symbols. */
7047 if (IRIX_COMPAT (abfd
) == ict_irix6
7048 && !mips_elf_create_msym_section (abfd
))
7051 /* Create .stub section. */
7052 if (bfd_get_section_by_name (abfd
,
7053 MIPS_ELF_STUB_SECTION_NAME (abfd
)) == NULL
)
7055 s
= bfd_make_section (abfd
, MIPS_ELF_STUB_SECTION_NAME (abfd
));
7057 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_CODE
)
7058 || ! bfd_set_section_alignment (abfd
, s
,
7059 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7063 if (IRIX_COMPAT (abfd
) == ict_irix5
7065 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
7067 s
= bfd_make_section (abfd
, ".rld_map");
7069 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
7070 || ! bfd_set_section_alignment (abfd
, s
,
7071 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7075 /* On IRIX5, we adjust add some additional symbols and change the
7076 alignments of several sections. There is no ABI documentation
7077 indicating that this is necessary on IRIX6, nor any evidence that
7078 the linker takes such action. */
7079 if (IRIX_COMPAT (abfd
) == ict_irix5
)
7081 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
7084 if (! (_bfd_generic_link_add_one_symbol
7085 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
7086 (bfd_vma
) 0, (const char *) NULL
, false,
7087 get_elf_backend_data (abfd
)->collect
,
7088 (struct bfd_link_hash_entry
**) &h
)))
7090 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
7091 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7092 h
->type
= STT_SECTION
;
7094 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7098 /* We need to create a .compact_rel section. */
7099 if (! mips_elf_create_compact_rel_section (abfd
, info
))
7102 /* Change aligments of some sections. */
7103 s
= bfd_get_section_by_name (abfd
, ".hash");
7105 bfd_set_section_alignment (abfd
, s
, 4);
7106 s
= bfd_get_section_by_name (abfd
, ".dynsym");
7108 bfd_set_section_alignment (abfd
, s
, 4);
7109 s
= bfd_get_section_by_name (abfd
, ".dynstr");
7111 bfd_set_section_alignment (abfd
, s
, 4);
7112 s
= bfd_get_section_by_name (abfd
, ".reginfo");
7114 bfd_set_section_alignment (abfd
, s
, 4);
7115 s
= bfd_get_section_by_name (abfd
, ".dynamic");
7117 bfd_set_section_alignment (abfd
, s
, 4);
7123 if (! (_bfd_generic_link_add_one_symbol
7124 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
7125 (bfd_vma
) 0, (const char *) NULL
, false,
7126 get_elf_backend_data (abfd
)->collect
,
7127 (struct bfd_link_hash_entry
**) &h
)))
7129 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
7130 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7131 h
->type
= STT_SECTION
;
7133 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7136 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
7138 /* __rld_map is a four byte word located in the .data section
7139 and is filled in by the rtld to contain a pointer to
7140 the _r_debug structure. Its symbol value will be set in
7141 mips_elf_finish_dynamic_symbol. */
7142 s
= bfd_get_section_by_name (abfd
, ".rld_map");
7143 BFD_ASSERT (s
!= NULL
);
7146 if (! (_bfd_generic_link_add_one_symbol
7147 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
7148 (bfd_vma
) 0, (const char *) NULL
, false,
7149 get_elf_backend_data (abfd
)->collect
,
7150 (struct bfd_link_hash_entry
**) &h
)))
7152 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
7153 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7154 h
->type
= STT_OBJECT
;
7156 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7164 /* Create the .compact_rel section. */
7167 mips_elf_create_compact_rel_section (abfd
, info
)
7169 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
7172 register asection
*s
;
7174 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
7176 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
7179 s
= bfd_make_section (abfd
, ".compact_rel");
7181 || ! bfd_set_section_flags (abfd
, s
, flags
)
7182 || ! bfd_set_section_alignment (abfd
, s
,
7183 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7186 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
7192 /* Create the .got section to hold the global offset table. */
7195 mips_elf_create_got_section (abfd
, info
)
7197 struct bfd_link_info
*info
;
7200 register asection
*s
;
7201 struct elf_link_hash_entry
*h
;
7202 struct mips_got_info
*g
;
7204 /* This function may be called more than once. */
7205 if (mips_elf_got_section (abfd
))
7208 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7209 | SEC_LINKER_CREATED
);
7211 s
= bfd_make_section (abfd
, ".got");
7213 || ! bfd_set_section_flags (abfd
, s
, flags
)
7214 || ! bfd_set_section_alignment (abfd
, s
, 4))
7217 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
7218 linker script because we don't want to define the symbol if we
7219 are not creating a global offset table. */
7221 if (! (_bfd_generic_link_add_one_symbol
7222 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
7223 (bfd_vma
) 0, (const char *) NULL
, false,
7224 get_elf_backend_data (abfd
)->collect
,
7225 (struct bfd_link_hash_entry
**) &h
)))
7227 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
7228 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7229 h
->type
= STT_OBJECT
;
7232 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7235 /* The first several global offset table entries are reserved. */
7236 s
->_raw_size
= MIPS_RESERVED_GOTNO
* MIPS_ELF_GOT_SIZE (abfd
);
7238 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
7239 sizeof (struct mips_got_info
));
7242 g
->global_gotsym
= NULL
;
7243 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
7244 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
7245 if (elf_section_data (s
) == NULL
)
7248 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
7249 if (elf_section_data (s
) == NULL
)
7252 elf_section_data (s
)->tdata
= (PTR
) g
;
7253 elf_section_data (s
)->this_hdr
.sh_flags
7254 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
7259 /* Returns the .msym section for ABFD, creating it if it does not
7260 already exist. Returns NULL to indicate error. */
7263 mips_elf_create_msym_section (abfd
)
7268 s
= bfd_get_section_by_name (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
7271 s
= bfd_make_section (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
7273 || !bfd_set_section_flags (abfd
, s
,
7277 | SEC_LINKER_CREATED
7279 || !bfd_set_section_alignment (abfd
, s
,
7280 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7287 /* Add room for N relocations to the .rel.dyn section in ABFD. */
7290 mips_elf_allocate_dynamic_relocations (abfd
, n
)
7296 s
= bfd_get_section_by_name (abfd
, MIPS_ELF_REL_DYN_SECTION_NAME (abfd
));
7297 BFD_ASSERT (s
!= NULL
);
7299 if (s
->_raw_size
== 0)
7301 /* Make room for a null element. */
7302 s
->_raw_size
+= MIPS_ELF_REL_SIZE (abfd
);
7305 s
->_raw_size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
7308 /* Look through the relocs for a section during the first phase, and
7309 allocate space in the global offset table. */
7312 _bfd_mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
7314 struct bfd_link_info
*info
;
7316 const Elf_Internal_Rela
*relocs
;
7320 Elf_Internal_Shdr
*symtab_hdr
;
7321 struct elf_link_hash_entry
**sym_hashes
;
7322 struct mips_got_info
*g
;
7324 const Elf_Internal_Rela
*rel
;
7325 const Elf_Internal_Rela
*rel_end
;
7328 struct elf_backend_data
*bed
;
7330 if (info
->relocateable
)
7333 dynobj
= elf_hash_table (info
)->dynobj
;
7334 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7335 sym_hashes
= elf_sym_hashes (abfd
);
7336 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
7338 /* Check for the mips16 stub sections. */
7340 name
= bfd_get_section_name (abfd
, sec
);
7341 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
7343 unsigned long r_symndx
;
7345 /* Look at the relocation information to figure out which symbol
7348 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
7350 if (r_symndx
< extsymoff
7351 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
7355 /* This stub is for a local symbol. This stub will only be
7356 needed if there is some relocation in this BFD, other
7357 than a 16 bit function call, which refers to this symbol. */
7358 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
7360 Elf_Internal_Rela
*sec_relocs
;
7361 const Elf_Internal_Rela
*r
, *rend
;
7363 /* We can ignore stub sections when looking for relocs. */
7364 if ((o
->flags
& SEC_RELOC
) == 0
7365 || o
->reloc_count
== 0
7366 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
7367 sizeof FN_STUB
- 1) == 0
7368 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
7369 sizeof CALL_STUB
- 1) == 0
7370 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
7371 sizeof CALL_FP_STUB
- 1) == 0)
7374 sec_relocs
= (_bfd_elf32_link_read_relocs
7375 (abfd
, o
, (PTR
) NULL
,
7376 (Elf_Internal_Rela
*) NULL
,
7377 info
->keep_memory
));
7378 if (sec_relocs
== NULL
)
7381 rend
= sec_relocs
+ o
->reloc_count
;
7382 for (r
= sec_relocs
; r
< rend
; r
++)
7383 if (ELF32_R_SYM (r
->r_info
) == r_symndx
7384 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
7387 if (! info
->keep_memory
)
7396 /* There is no non-call reloc for this stub, so we do
7397 not need it. Since this function is called before
7398 the linker maps input sections to output sections, we
7399 can easily discard it by setting the SEC_EXCLUDE
7401 sec
->flags
|= SEC_EXCLUDE
;
7405 /* Record this stub in an array of local symbol stubs for
7407 if (elf_tdata (abfd
)->local_stubs
== NULL
)
7409 unsigned long symcount
;
7412 if (elf_bad_symtab (abfd
))
7413 symcount
= symtab_hdr
->sh_size
/ symtab_hdr
->sh_entsize
;
7415 symcount
= symtab_hdr
->sh_info
;
7416 n
= (asection
**) bfd_zalloc (abfd
,
7417 symcount
* sizeof (asection
*));
7420 elf_tdata (abfd
)->local_stubs
= n
;
7423 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
7425 /* We don't need to set mips16_stubs_seen in this case.
7426 That flag is used to see whether we need to look through
7427 the global symbol table for stubs. We don't need to set
7428 it here, because we just have a local stub. */
7432 struct mips_elf_link_hash_entry
*h
;
7434 h
= ((struct mips_elf_link_hash_entry
*)
7435 sym_hashes
[r_symndx
- extsymoff
]);
7437 /* H is the symbol this stub is for. */
7440 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
7443 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
7444 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
7446 unsigned long r_symndx
;
7447 struct mips_elf_link_hash_entry
*h
;
7450 /* Look at the relocation information to figure out which symbol
7453 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
7455 if (r_symndx
< extsymoff
7456 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
7458 /* This stub was actually built for a static symbol defined
7459 in the same file. We assume that all static symbols in
7460 mips16 code are themselves mips16, so we can simply
7461 discard this stub. Since this function is called before
7462 the linker maps input sections to output sections, we can
7463 easily discard it by setting the SEC_EXCLUDE flag. */
7464 sec
->flags
|= SEC_EXCLUDE
;
7468 h
= ((struct mips_elf_link_hash_entry
*)
7469 sym_hashes
[r_symndx
- extsymoff
]);
7471 /* H is the symbol this stub is for. */
7473 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
7474 loc
= &h
->call_fp_stub
;
7476 loc
= &h
->call_stub
;
7478 /* If we already have an appropriate stub for this function, we
7479 don't need another one, so we can discard this one. Since
7480 this function is called before the linker maps input sections
7481 to output sections, we can easily discard it by setting the
7482 SEC_EXCLUDE flag. We can also discard this section if we
7483 happen to already know that this is a mips16 function; it is
7484 not necessary to check this here, as it is checked later, but
7485 it is slightly faster to check now. */
7486 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
7488 sec
->flags
|= SEC_EXCLUDE
;
7493 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
7503 sgot
= mips_elf_got_section (dynobj
);
7508 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7509 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7510 BFD_ASSERT (g
!= NULL
);
7515 bed
= get_elf_backend_data (abfd
);
7516 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
7517 for (rel
= relocs
; rel
< rel_end
; ++rel
)
7519 unsigned long r_symndx
;
7521 struct elf_link_hash_entry
*h
;
7523 r_symndx
= ELF32_R_SYM (rel
->r_info
);
7524 r_type
= ELF32_R_TYPE (rel
->r_info
);
7526 if (r_symndx
< extsymoff
)
7530 h
= sym_hashes
[r_symndx
- extsymoff
];
7532 /* This may be an indirect symbol created because of a version. */
7535 while (h
->root
.type
== bfd_link_hash_indirect
)
7536 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7540 /* Some relocs require a global offset table. */
7541 if (dynobj
== NULL
|| sgot
== NULL
)
7547 case R_MIPS_CALL_HI16
:
7548 case R_MIPS_CALL_LO16
:
7549 case R_MIPS_GOT_HI16
:
7550 case R_MIPS_GOT_LO16
:
7551 case R_MIPS_GOT_PAGE
:
7552 case R_MIPS_GOT_OFST
:
7553 case R_MIPS_GOT_DISP
:
7555 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7556 if (! mips_elf_create_got_section (dynobj
, info
))
7558 g
= mips_elf_got_info (dynobj
, &sgot
);
7565 && (info
->shared
|| h
!= NULL
)
7566 && (sec
->flags
& SEC_ALLOC
) != 0)
7567 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7575 if (!h
&& (r_type
== R_MIPS_CALL_LO16
7576 || r_type
== R_MIPS_GOT_LO16
7577 || r_type
== R_MIPS_GOT_DISP
))
7579 /* We may need a local GOT entry for this relocation. We
7580 don't count R_MIPS_GOT_PAGE because we can estimate the
7581 maximum number of pages needed by looking at the size of
7582 the segment. Similar comments apply to R_MIPS_GOT16. We
7583 don't count R_MIPS_GOT_HI16, or R_MIPS_CALL_HI16 because
7584 these are always followed by an R_MIPS_GOT_LO16 or
7587 This estimation is very conservative since we can merge
7588 duplicate entries in the GOT. In order to be less
7589 conservative, we could actually build the GOT here,
7590 rather than in relocate_section. */
7592 sgot
->_raw_size
+= MIPS_ELF_GOT_SIZE (dynobj
);
7600 (*_bfd_error_handler
)
7601 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
7602 bfd_get_filename (abfd
), (unsigned long) rel
->r_offset
);
7603 bfd_set_error (bfd_error_bad_value
);
7608 case R_MIPS_CALL_HI16
:
7609 case R_MIPS_CALL_LO16
:
7612 /* This symbol requires a global offset table entry. */
7613 if (!mips_elf_record_global_got_symbol (h
, info
, g
))
7616 /* We need a stub, not a plt entry for the undefined
7617 function. But we record it as if it needs plt. See
7618 elf_adjust_dynamic_symbol in elflink.h. */
7619 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
7625 case R_MIPS_GOT_HI16
:
7626 case R_MIPS_GOT_LO16
:
7627 case R_MIPS_GOT_DISP
:
7628 /* This symbol requires a global offset table entry. */
7629 if (h
&& !mips_elf_record_global_got_symbol (h
, info
, g
))
7636 if ((info
->shared
|| h
!= NULL
)
7637 && (sec
->flags
& SEC_ALLOC
) != 0)
7641 const char *name
= MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
);
7643 sreloc
= bfd_get_section_by_name (dynobj
, name
);
7646 sreloc
= bfd_make_section (dynobj
, name
);
7648 || ! bfd_set_section_flags (dynobj
, sreloc
,
7653 | SEC_LINKER_CREATED
7655 || ! bfd_set_section_alignment (dynobj
, sreloc
,
7661 /* When creating a shared object, we must copy these
7662 reloc types into the output file as R_MIPS_REL32
7663 relocs. We make room for this reloc in the
7664 .rel.dyn reloc section. */
7665 mips_elf_allocate_dynamic_relocations (dynobj
, 1);
7668 struct mips_elf_link_hash_entry
*hmips
;
7670 /* We only need to copy this reloc if the symbol is
7671 defined in a dynamic object. */
7672 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7673 ++hmips
->possibly_dynamic_relocs
;
7676 /* Even though we don't directly need a GOT entry for
7677 this symbol, a symbol must have a dynamic symbol
7678 table index greater that DT_MIPS_GOTSYM if there are
7679 dynamic relocations against it. */
7681 && !mips_elf_record_global_got_symbol (h
, info
, g
))
7685 if (SGI_COMPAT (dynobj
))
7686 mips_elf_hash_table (info
)->compact_rel_size
+=
7687 sizeof (Elf32_External_crinfo
);
7691 case R_MIPS_GPREL16
:
7692 case R_MIPS_LITERAL
:
7693 case R_MIPS_GPREL32
:
7694 if (SGI_COMPAT (dynobj
))
7695 mips_elf_hash_table (info
)->compact_rel_size
+=
7696 sizeof (Elf32_External_crinfo
);
7699 /* This relocation describes the C++ object vtable hierarchy.
7700 Reconstruct it for later use during GC. */
7701 case R_MIPS_GNU_VTINHERIT
:
7702 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
7706 /* This relocation describes which C++ vtable entries are actually
7707 used. Record for later use during GC. */
7708 case R_MIPS_GNU_VTENTRY
:
7709 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
7717 /* If this reloc is not a 16 bit call, and it has a global
7718 symbol, then we will need the fn_stub if there is one.
7719 References from a stub section do not count. */
7721 && r_type
!= R_MIPS16_26
7722 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
7723 sizeof FN_STUB
- 1) != 0
7724 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
7725 sizeof CALL_STUB
- 1) != 0
7726 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
7727 sizeof CALL_FP_STUB
- 1) != 0)
7729 struct mips_elf_link_hash_entry
*mh
;
7731 mh
= (struct mips_elf_link_hash_entry
*) h
;
7732 mh
->need_fn_stub
= true;
7739 /* Return the section that should be marked against GC for a given
7743 _bfd_mips_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
7745 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
7746 Elf_Internal_Rela
*rel
;
7747 struct elf_link_hash_entry
*h
;
7748 Elf_Internal_Sym
*sym
;
7750 /* ??? Do mips16 stub sections need to be handled special? */
7754 switch (ELF32_R_TYPE (rel
->r_info
))
7756 case R_MIPS_GNU_VTINHERIT
:
7757 case R_MIPS_GNU_VTENTRY
:
7761 switch (h
->root
.type
)
7763 case bfd_link_hash_defined
:
7764 case bfd_link_hash_defweak
:
7765 return h
->root
.u
.def
.section
;
7767 case bfd_link_hash_common
:
7768 return h
->root
.u
.c
.p
->section
;
7777 if (!(elf_bad_symtab (abfd
)
7778 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
7779 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
7780 && sym
->st_shndx
!= SHN_COMMON
))
7782 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
7789 /* Update the got entry reference counts for the section being removed. */
7792 _bfd_mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
7793 bfd
*abfd ATTRIBUTE_UNUSED
;
7794 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
7795 asection
*sec ATTRIBUTE_UNUSED
;
7796 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
7799 Elf_Internal_Shdr
*symtab_hdr
;
7800 struct elf_link_hash_entry
**sym_hashes
;
7801 bfd_signed_vma
*local_got_refcounts
;
7802 const Elf_Internal_Rela
*rel
, *relend
;
7803 unsigned long r_symndx
;
7804 struct elf_link_hash_entry
*h
;
7806 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7807 sym_hashes
= elf_sym_hashes (abfd
);
7808 local_got_refcounts
= elf_local_got_refcounts (abfd
);
7810 relend
= relocs
+ sec
->reloc_count
;
7811 for (rel
= relocs
; rel
< relend
; rel
++)
7812 switch (ELF32_R_TYPE (rel
->r_info
))
7816 case R_MIPS_CALL_HI16
:
7817 case R_MIPS_CALL_LO16
:
7818 case R_MIPS_GOT_HI16
:
7819 case R_MIPS_GOT_LO16
:
7820 /* ??? It would seem that the existing MIPS code does no sort
7821 of reference counting or whatnot on its GOT and PLT entries,
7822 so it is not possible to garbage collect them at this time. */
7833 /* Adjust a symbol defined by a dynamic object and referenced by a
7834 regular object. The current definition is in some section of the
7835 dynamic object, but we're not including those sections. We have to
7836 change the definition to something the rest of the link can
7840 _bfd_mips_elf_adjust_dynamic_symbol (info
, h
)
7841 struct bfd_link_info
*info
;
7842 struct elf_link_hash_entry
*h
;
7845 struct mips_elf_link_hash_entry
*hmips
;
7848 dynobj
= elf_hash_table (info
)->dynobj
;
7850 /* Make sure we know what is going on here. */
7851 BFD_ASSERT (dynobj
!= NULL
7852 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
7853 || h
->weakdef
!= NULL
7854 || ((h
->elf_link_hash_flags
7855 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
7856 && (h
->elf_link_hash_flags
7857 & ELF_LINK_HASH_REF_REGULAR
) != 0
7858 && (h
->elf_link_hash_flags
7859 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
7861 /* If this symbol is defined in a dynamic object, we need to copy
7862 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
7864 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7865 if (! info
->relocateable
7866 && hmips
->possibly_dynamic_relocs
!= 0
7867 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
7868 mips_elf_allocate_dynamic_relocations (dynobj
,
7869 hmips
->possibly_dynamic_relocs
);
7871 /* For a function, create a stub, if needed. */
7872 if (h
->type
== STT_FUNC
7873 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
7875 if (! elf_hash_table (info
)->dynamic_sections_created
)
7878 /* If this symbol is not defined in a regular file, then set
7879 the symbol to the stub location. This is required to make
7880 function pointers compare as equal between the normal
7881 executable and the shared library. */
7882 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
7884 /* We need .stub section. */
7885 s
= bfd_get_section_by_name (dynobj
,
7886 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
7887 BFD_ASSERT (s
!= NULL
);
7889 h
->root
.u
.def
.section
= s
;
7890 h
->root
.u
.def
.value
= s
->_raw_size
;
7892 /* XXX Write this stub address somewhere. */
7893 h
->plt
.offset
= s
->_raw_size
;
7895 /* Make room for this stub code. */
7896 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
7898 /* The last half word of the stub will be filled with the index
7899 of this symbol in .dynsym section. */
7904 /* If this is a weak symbol, and there is a real definition, the
7905 processor independent code will have arranged for us to see the
7906 real definition first, and we can just use the same value. */
7907 if (h
->weakdef
!= NULL
)
7909 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
7910 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
7911 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
7912 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
7916 /* This is a reference to a symbol defined by a dynamic object which
7917 is not a function. */
7922 /* This function is called after all the input files have been read,
7923 and the input sections have been assigned to output sections. We
7924 check for any mips16 stub sections that we can discard. */
7926 static boolean mips_elf_check_mips16_stubs
7927 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
7930 _bfd_mips_elf_always_size_sections (output_bfd
, info
)
7932 struct bfd_link_info
*info
;
7936 /* The .reginfo section has a fixed size. */
7937 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
7939 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
7941 if (info
->relocateable
7942 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
7945 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
7946 mips_elf_check_mips16_stubs
,
7952 /* Check the mips16 stubs for a particular symbol, and see if we can
7957 mips_elf_check_mips16_stubs (h
, data
)
7958 struct mips_elf_link_hash_entry
*h
;
7959 PTR data ATTRIBUTE_UNUSED
;
7961 if (h
->fn_stub
!= NULL
7962 && ! h
->need_fn_stub
)
7964 /* We don't need the fn_stub; the only references to this symbol
7965 are 16 bit calls. Clobber the size to 0 to prevent it from
7966 being included in the link. */
7967 h
->fn_stub
->_raw_size
= 0;
7968 h
->fn_stub
->_cooked_size
= 0;
7969 h
->fn_stub
->flags
&= ~ SEC_RELOC
;
7970 h
->fn_stub
->reloc_count
= 0;
7971 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
7974 if (h
->call_stub
!= NULL
7975 && h
->root
.other
== STO_MIPS16
)
7977 /* We don't need the call_stub; this is a 16 bit function, so
7978 calls from other 16 bit functions are OK. Clobber the size
7979 to 0 to prevent it from being included in the link. */
7980 h
->call_stub
->_raw_size
= 0;
7981 h
->call_stub
->_cooked_size
= 0;
7982 h
->call_stub
->flags
&= ~ SEC_RELOC
;
7983 h
->call_stub
->reloc_count
= 0;
7984 h
->call_stub
->flags
|= SEC_EXCLUDE
;
7987 if (h
->call_fp_stub
!= NULL
7988 && h
->root
.other
== STO_MIPS16
)
7990 /* We don't need the call_stub; this is a 16 bit function, so
7991 calls from other 16 bit functions are OK. Clobber the size
7992 to 0 to prevent it from being included in the link. */
7993 h
->call_fp_stub
->_raw_size
= 0;
7994 h
->call_fp_stub
->_cooked_size
= 0;
7995 h
->call_fp_stub
->flags
&= ~ SEC_RELOC
;
7996 h
->call_fp_stub
->reloc_count
= 0;
7997 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
8003 /* Set the sizes of the dynamic sections. */
8006 _bfd_mips_elf_size_dynamic_sections (output_bfd
, info
)
8008 struct bfd_link_info
*info
;
8013 struct mips_got_info
*g
= NULL
;
8015 dynobj
= elf_hash_table (info
)->dynobj
;
8016 BFD_ASSERT (dynobj
!= NULL
);
8018 if (elf_hash_table (info
)->dynamic_sections_created
)
8020 /* Set the contents of the .interp section to the interpreter. */
8023 s
= bfd_get_section_by_name (dynobj
, ".interp");
8024 BFD_ASSERT (s
!= NULL
);
8026 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
8028 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
8032 /* The check_relocs and adjust_dynamic_symbol entry points have
8033 determined the sizes of the various dynamic sections. Allocate
8036 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8041 /* It's OK to base decisions on the section name, because none
8042 of the dynobj section names depend upon the input files. */
8043 name
= bfd_get_section_name (dynobj
, s
);
8045 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8050 if (strncmp (name
, ".rel", 4) == 0)
8052 if (s
->_raw_size
== 0)
8054 /* We only strip the section if the output section name
8055 has the same name. Otherwise, there might be several
8056 input sections for this output section. FIXME: This
8057 code is probably not needed these days anyhow, since
8058 the linker now does not create empty output sections. */
8059 if (s
->output_section
!= NULL
8061 bfd_get_section_name (s
->output_section
->owner
,
8062 s
->output_section
)) == 0)
8067 const char *outname
;
8070 /* If this relocation section applies to a read only
8071 section, then we probably need a DT_TEXTREL entry.
8072 If the relocation section is .rel.dyn, we always
8073 assert a DT_TEXTREL entry rather than testing whether
8074 there exists a relocation to a read only section or
8076 outname
= bfd_get_section_name (output_bfd
,
8078 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
8080 && (target
->flags
& SEC_READONLY
) != 0
8081 && (target
->flags
& SEC_ALLOC
) != 0)
8083 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd
)) == 0)
8086 /* We use the reloc_count field as a counter if we need
8087 to copy relocs into the output file. */
8089 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd
)) != 0)
8093 else if (strncmp (name
, ".got", 4) == 0)
8096 bfd_size_type loadable_size
= 0;
8097 bfd_size_type local_gotno
;
8100 BFD_ASSERT (elf_section_data (s
) != NULL
);
8101 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
8102 BFD_ASSERT (g
!= NULL
);
8104 /* Calculate the total loadable size of the output. That
8105 will give us the maximum number of GOT_PAGE entries
8107 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
8109 asection
*subsection
;
8111 for (subsection
= sub
->sections
;
8113 subsection
= subsection
->next
)
8115 if ((subsection
->flags
& SEC_ALLOC
) == 0)
8117 loadable_size
+= (subsection
->_raw_size
+ 0xf) & ~0xf;
8120 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
8122 /* Assume there are two loadable segments consisting of
8123 contiguous sections. Is 5 enough? */
8124 local_gotno
= (loadable_size
>> 16) + 5;
8125 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
8126 /* It's possible we will need GOT_PAGE entries as well as
8127 GOT16 entries. Often, these will be able to share GOT
8128 entries, but not always. */
8131 g
->local_gotno
+= local_gotno
;
8132 s
->_raw_size
+= local_gotno
* MIPS_ELF_GOT_SIZE (dynobj
);
8134 /* There has to be a global GOT entry for every symbol with
8135 a dynamic symbol table index of DT_MIPS_GOTSYM or
8136 higher. Therefore, it make sense to put those symbols
8137 that need GOT entries at the end of the symbol table. We
8139 if (!mips_elf_sort_hash_table (info
, 1))
8142 if (g
->global_gotsym
!= NULL
)
8143 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
8145 /* If there are no global symbols, or none requiring
8146 relocations, then GLOBAL_GOTSYM will be NULL. */
8148 g
->global_gotno
= i
;
8149 s
->_raw_size
+= i
* MIPS_ELF_GOT_SIZE (dynobj
);
8151 else if (strcmp (name
, MIPS_ELF_STUB_SECTION_NAME (output_bfd
)) == 0)
8153 /* Irix rld assumes that the function stub isn't at the end
8154 of .text section. So put a dummy. XXX */
8155 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
8157 else if (! info
->shared
8158 && ! mips_elf_hash_table (info
)->use_rld_obj_head
8159 && strncmp (name
, ".rld_map", 8) == 0)
8161 /* We add a room for __rld_map. It will be filled in by the
8162 rtld to contain a pointer to the _r_debug structure. */
8165 else if (SGI_COMPAT (output_bfd
)
8166 && strncmp (name
, ".compact_rel", 12) == 0)
8167 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
8168 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
))
8170 s
->_raw_size
= (sizeof (Elf32_External_Msym
)
8171 * (elf_hash_table (info
)->dynsymcount
8172 + bfd_count_sections (output_bfd
)));
8173 else if (strncmp (name
, ".init", 5) != 0)
8175 /* It's not one of our sections, so don't allocate space. */
8181 _bfd_strip_section_from_output (info
, s
);
8185 /* Allocate memory for the section contents. */
8186 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
8187 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
8189 bfd_set_error (bfd_error_no_memory
);
8194 if (elf_hash_table (info
)->dynamic_sections_created
)
8196 /* Add some entries to the .dynamic section. We fill in the
8197 values later, in elf_mips_finish_dynamic_sections, but we
8198 must add the entries now so that we get the correct size for
8199 the .dynamic section. The DT_DEBUG entry is filled in by the
8200 dynamic linker and used by the debugger. */
8203 if (SGI_COMPAT (output_bfd
))
8205 /* SGI object has the equivalence of DT_DEBUG in the
8206 DT_MIPS_RLD_MAP entry. */
8207 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
8211 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
8217 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
8221 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
8224 if (bfd_get_section_by_name (dynobj
,
8225 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
)))
8227 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
8230 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
8233 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
8237 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICTNO
, 0))
8240 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLISTNO
, 0))
8243 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
8245 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICT
, 0))
8248 s
= bfd_get_section_by_name (dynobj
, ".liblist");
8249 BFD_ASSERT (s
!= NULL
);
8251 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLIST
, 0))
8255 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
8258 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
8262 /* Time stamps in executable files are a bad idea. */
8263 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_TIME_STAMP
, 0))
8268 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_ICHECKSUM
, 0))
8273 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_IVERSION
, 0))
8277 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
8280 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
8283 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
8286 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
8289 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
8292 if (IRIX_COMPAT (dynobj
) == ict_irix5
8293 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
8296 if (IRIX_COMPAT (dynobj
) == ict_irix6
8297 && (bfd_get_section_by_name
8298 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
8299 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
8302 if (bfd_get_section_by_name (dynobj
,
8303 MIPS_ELF_MSYM_SECTION_NAME (dynobj
))
8304 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_MSYM
, 0))
8311 /* If NAME is one of the special IRIX6 symbols defined by the linker,
8312 adjust it appropriately now. */
8315 mips_elf_irix6_finish_dynamic_symbol (abfd
, name
, sym
)
8316 bfd
*abfd ATTRIBUTE_UNUSED
;
8318 Elf_Internal_Sym
*sym
;
8320 /* The linker script takes care of providing names and values for
8321 these, but we must place them into the right sections. */
8322 static const char* const text_section_symbols
[] = {
8325 "__dso_displacement",
8327 "__program_header_table",
8331 static const char* const data_section_symbols
[] = {
8339 const char* const *p
;
8342 for (i
= 0; i
< 2; ++i
)
8343 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
8346 if (strcmp (*p
, name
) == 0)
8348 /* All of these symbols are given type STT_SECTION by the
8350 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8352 /* The IRIX linker puts these symbols in special sections. */
8354 sym
->st_shndx
= SHN_MIPS_TEXT
;
8356 sym
->st_shndx
= SHN_MIPS_DATA
;
8362 /* Finish up dynamic symbol handling. We set the contents of various
8363 dynamic sections here. */
8366 _bfd_mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
8368 struct bfd_link_info
*info
;
8369 struct elf_link_hash_entry
*h
;
8370 Elf_Internal_Sym
*sym
;
8376 struct mips_got_info
*g
;
8378 struct mips_elf_link_hash_entry
*mh
;
8380 dynobj
= elf_hash_table (info
)->dynobj
;
8381 gval
= sym
->st_value
;
8382 mh
= (struct mips_elf_link_hash_entry
*) h
;
8384 if (h
->plt
.offset
!= (bfd_vma
) -1)
8388 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
8390 /* This symbol has a stub. Set it up. */
8392 BFD_ASSERT (h
->dynindx
!= -1);
8394 s
= bfd_get_section_by_name (dynobj
,
8395 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
8396 BFD_ASSERT (s
!= NULL
);
8398 /* Fill the stub. */
8400 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
8402 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
8405 /* FIXME: Can h->dynindex be more than 64K? */
8406 if (h
->dynindx
& 0xffff0000)
8409 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
8411 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
8413 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
8414 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
8416 /* Mark the symbol as undefined. plt.offset != -1 occurs
8417 only for the referenced symbol. */
8418 sym
->st_shndx
= SHN_UNDEF
;
8420 /* The run-time linker uses the st_value field of the symbol
8421 to reset the global offset table entry for this external
8422 to its stub address when unlinking a shared object. */
8423 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
8424 sym
->st_value
= gval
;
8427 BFD_ASSERT (h
->dynindx
!= -1
8428 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0);
8430 sgot
= mips_elf_got_section (dynobj
);
8431 BFD_ASSERT (sgot
!= NULL
);
8432 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
8433 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
8434 BFD_ASSERT (g
!= NULL
);
8436 /* Run through the global symbol table, creating GOT entries for all
8437 the symbols that need them. */
8438 if (g
->global_gotsym
!= NULL
8439 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
8445 value
= sym
->st_value
;
8447 /* For an entity defined in a shared object, this will be
8448 NULL. (For functions in shared objects for
8449 which we have created stubs, ST_VALUE will be non-NULL.
8450 That's because such the functions are now no longer defined
8451 in a shared object.) */
8452 value
= h
->root
.u
.def
.value
;
8454 offset
= mips_elf_global_got_index (dynobj
, h
);
8455 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
8458 /* Create a .msym entry, if appropriate. */
8459 smsym
= bfd_get_section_by_name (dynobj
,
8460 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
8463 Elf32_Internal_Msym msym
;
8465 msym
.ms_hash_value
= bfd_elf_hash (h
->root
.root
.string
);
8466 /* It is undocumented what the `1' indicates, but IRIX6 uses
8468 msym
.ms_info
= ELF32_MS_INFO (mh
->min_dyn_reloc_index
, 1);
8469 bfd_mips_elf_swap_msym_out
8471 ((Elf32_External_Msym
*) smsym
->contents
) + h
->dynindx
);
8474 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
8475 name
= h
->root
.root
.string
;
8476 if (strcmp (name
, "_DYNAMIC") == 0
8477 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
8478 sym
->st_shndx
= SHN_ABS
;
8479 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
8481 sym
->st_shndx
= SHN_ABS
;
8482 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8485 else if (SGI_COMPAT (output_bfd
))
8487 if (strcmp (name
, "_gp_disp") == 0)
8489 sym
->st_shndx
= SHN_ABS
;
8490 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8491 sym
->st_value
= elf_gp (output_bfd
);
8493 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
8494 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
8496 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8497 sym
->st_other
= STO_PROTECTED
;
8499 sym
->st_shndx
= SHN_MIPS_DATA
;
8501 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
8503 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8504 sym
->st_other
= STO_PROTECTED
;
8505 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
8506 sym
->st_shndx
= SHN_ABS
;
8508 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
8510 if (h
->type
== STT_FUNC
)
8511 sym
->st_shndx
= SHN_MIPS_TEXT
;
8512 else if (h
->type
== STT_OBJECT
)
8513 sym
->st_shndx
= SHN_MIPS_DATA
;
8517 /* Handle the IRIX6-specific symbols. */
8518 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
8519 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
8521 if (SGI_COMPAT (output_bfd
)
8524 if (! mips_elf_hash_table (info
)->use_rld_obj_head
8525 && strcmp (name
, "__rld_map") == 0)
8527 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
8528 BFD_ASSERT (s
!= NULL
);
8529 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
8530 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
8531 if (mips_elf_hash_table (info
)->rld_value
== 0)
8532 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
8534 else if (mips_elf_hash_table (info
)->use_rld_obj_head
8535 && strcmp (name
, "__rld_obj_head") == 0)
8537 /* IRIX6 does not use a .rld_map section. */
8538 if (IRIX_COMPAT (output_bfd
) == ict_irix5
)
8539 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
8541 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
8545 /* If this is a mips16 symbol, force the value to be even. */
8546 if (sym
->st_other
== STO_MIPS16
8547 && (sym
->st_value
& 1) != 0)
8553 /* Finish up the dynamic sections. */
8556 _bfd_mips_elf_finish_dynamic_sections (output_bfd
, info
)
8558 struct bfd_link_info
*info
;
8563 struct mips_got_info
*g
;
8565 dynobj
= elf_hash_table (info
)->dynobj
;
8567 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
8569 sgot
= mips_elf_got_section (dynobj
);
8574 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
8575 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
8576 BFD_ASSERT (g
!= NULL
);
8579 if (elf_hash_table (info
)->dynamic_sections_created
)
8583 BFD_ASSERT (sdyn
!= NULL
);
8584 BFD_ASSERT (g
!= NULL
);
8586 for (b
= sdyn
->contents
;
8587 b
< sdyn
->contents
+ sdyn
->_raw_size
;
8588 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
8590 Elf_Internal_Dyn dyn
;
8596 /* Read in the current dynamic entry. */
8597 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
8599 /* Assume that we're going to modify it and write it out. */
8605 s
= (bfd_get_section_by_name
8607 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
)));
8608 BFD_ASSERT (s
!= NULL
);
8609 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
8613 /* Rewrite DT_STRSZ. */
8615 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
8621 case DT_MIPS_CONFLICT
:
8624 case DT_MIPS_LIBLIST
:
8627 s
= bfd_get_section_by_name (output_bfd
, name
);
8628 BFD_ASSERT (s
!= NULL
);
8629 dyn
.d_un
.d_ptr
= s
->vma
;
8632 case DT_MIPS_RLD_VERSION
:
8633 dyn
.d_un
.d_val
= 1; /* XXX */
8637 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
8640 case DT_MIPS_CONFLICTNO
:
8642 elemsize
= sizeof (Elf32_Conflict
);
8645 case DT_MIPS_LIBLISTNO
:
8647 elemsize
= sizeof (Elf32_Lib
);
8649 s
= bfd_get_section_by_name (output_bfd
, name
);
8652 if (s
->_cooked_size
!= 0)
8653 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
8655 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
8661 case DT_MIPS_TIME_STAMP
:
8662 time ((time_t *) &dyn
.d_un
.d_val
);
8665 case DT_MIPS_ICHECKSUM
:
8670 case DT_MIPS_IVERSION
:
8675 case DT_MIPS_BASE_ADDRESS
:
8676 s
= output_bfd
->sections
;
8677 BFD_ASSERT (s
!= NULL
);
8678 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
8681 case DT_MIPS_LOCAL_GOTNO
:
8682 dyn
.d_un
.d_val
= g
->local_gotno
;
8685 case DT_MIPS_UNREFEXTNO
:
8686 /* The index into the dynamic symbol table which is the
8687 entry of the first external symbol that is not
8688 referenced within the same object. */
8689 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
8692 case DT_MIPS_GOTSYM
:
8693 if (g
->global_gotsym
)
8695 dyn
.d_un
.d_val
= g
->global_gotsym
->dynindx
;
8698 /* In case if we don't have global got symbols we default
8699 to setting DT_MIPS_GOTSYM to the same value as
8700 DT_MIPS_SYMTABNO, so we just fall through. */
8702 case DT_MIPS_SYMTABNO
:
8704 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
8705 s
= bfd_get_section_by_name (output_bfd
, name
);
8706 BFD_ASSERT (s
!= NULL
);
8708 if (s
->_cooked_size
!= 0)
8709 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
8711 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
8714 case DT_MIPS_HIPAGENO
:
8715 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
8718 case DT_MIPS_RLD_MAP
:
8719 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
8722 case DT_MIPS_OPTIONS
:
8723 s
= (bfd_get_section_by_name
8724 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
8725 dyn
.d_un
.d_ptr
= s
->vma
;
8729 s
= (bfd_get_section_by_name
8730 (output_bfd
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
)));
8731 dyn
.d_un
.d_ptr
= s
->vma
;
8740 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
8745 /* The first entry of the global offset table will be filled at
8746 runtime. The second entry will be used by some runtime loaders.
8747 This isn't the case of Irix rld. */
8748 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
8750 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
8751 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0x80000000,
8752 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
8756 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
8757 = MIPS_ELF_GOT_SIZE (output_bfd
);
8762 Elf32_compact_rel cpt
;
8764 /* ??? The section symbols for the output sections were set up in
8765 _bfd_elf_final_link. SGI sets the STT_NOTYPE attribute for these
8766 symbols. Should we do so? */
8768 smsym
= bfd_get_section_by_name (dynobj
,
8769 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
8772 Elf32_Internal_Msym msym
;
8774 msym
.ms_hash_value
= 0;
8775 msym
.ms_info
= ELF32_MS_INFO (0, 1);
8777 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
8779 long dynindx
= elf_section_data (s
)->dynindx
;
8781 bfd_mips_elf_swap_msym_out
8783 (((Elf32_External_Msym
*) smsym
->contents
)
8788 if (SGI_COMPAT (output_bfd
))
8790 /* Write .compact_rel section out. */
8791 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
8795 cpt
.num
= s
->reloc_count
;
8797 cpt
.offset
= (s
->output_section
->filepos
8798 + sizeof (Elf32_External_compact_rel
));
8801 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
8802 ((Elf32_External_compact_rel
*)
8805 /* Clean up a dummy stub function entry in .text. */
8806 s
= bfd_get_section_by_name (dynobj
,
8807 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
8810 file_ptr dummy_offset
;
8812 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
8813 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
8814 memset (s
->contents
+ dummy_offset
, 0,
8815 MIPS_FUNCTION_STUB_SIZE
);
8820 /* Clean up a first relocation in .rel.dyn. */
8821 s
= bfd_get_section_by_name (dynobj
,
8822 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
));
8823 if (s
!= NULL
&& s
->_raw_size
> 0)
8824 memset (s
->contents
, 0, MIPS_ELF_REL_SIZE (dynobj
));
8830 /* This is almost identical to bfd_generic_get_... except that some
8831 MIPS relocations need to be handled specially. Sigh. */
8834 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
8835 relocateable
, symbols
)
8837 struct bfd_link_info
*link_info
;
8838 struct bfd_link_order
*link_order
;
8840 boolean relocateable
;
8843 /* Get enough memory to hold the stuff */
8844 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
8845 asection
*input_section
= link_order
->u
.indirect
.section
;
8847 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
8848 arelent
**reloc_vector
= NULL
;
8854 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
8855 if (reloc_vector
== NULL
&& reloc_size
!= 0)
8858 /* read in the section */
8859 if (!bfd_get_section_contents (input_bfd
,
8863 input_section
->_raw_size
))
8866 /* We're not relaxing the section, so just copy the size info */
8867 input_section
->_cooked_size
= input_section
->_raw_size
;
8868 input_section
->reloc_done
= true;
8870 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
8874 if (reloc_count
< 0)
8877 if (reloc_count
> 0)
8882 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
8885 struct bfd_hash_entry
*h
;
8886 struct bfd_link_hash_entry
*lh
;
8887 /* Skip all this stuff if we aren't mixing formats. */
8888 if (abfd
&& input_bfd
8889 && abfd
->xvec
== input_bfd
->xvec
)
8893 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
8894 lh
= (struct bfd_link_hash_entry
*) h
;
8901 case bfd_link_hash_undefined
:
8902 case bfd_link_hash_undefweak
:
8903 case bfd_link_hash_common
:
8906 case bfd_link_hash_defined
:
8907 case bfd_link_hash_defweak
:
8909 gp
= lh
->u
.def
.value
;
8911 case bfd_link_hash_indirect
:
8912 case bfd_link_hash_warning
:
8914 /* @@FIXME ignoring warning for now */
8916 case bfd_link_hash_new
:
8925 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
8928 char *error_message
= (char *) NULL
;
8929 bfd_reloc_status_type r
;
8931 /* Specific to MIPS: Deal with relocation types that require
8932 knowing the gp of the output bfd. */
8933 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
8934 if (bfd_is_abs_section (sym
->section
) && abfd
)
8936 /* The special_function wouldn't get called anyways. */
8940 /* The gp isn't there; let the special function code
8941 fall over on its own. */
8943 else if ((*parent
)->howto
->special_function
8944 == _bfd_mips_elf_gprel16_reloc
)
8946 /* bypass special_function call */
8947 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
8948 relocateable
, (PTR
) data
, gp
);
8949 goto skip_bfd_perform_relocation
;
8951 /* end mips specific stuff */
8953 r
= bfd_perform_relocation (input_bfd
,
8957 relocateable
? abfd
: (bfd
*) NULL
,
8959 skip_bfd_perform_relocation
:
8963 asection
*os
= input_section
->output_section
;
8965 /* A partial link, so keep the relocs */
8966 os
->orelocation
[os
->reloc_count
] = *parent
;
8970 if (r
!= bfd_reloc_ok
)
8974 case bfd_reloc_undefined
:
8975 if (!((*link_info
->callbacks
->undefined_symbol
)
8976 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
8977 input_bfd
, input_section
, (*parent
)->address
,
8981 case bfd_reloc_dangerous
:
8982 BFD_ASSERT (error_message
!= (char *) NULL
);
8983 if (!((*link_info
->callbacks
->reloc_dangerous
)
8984 (link_info
, error_message
, input_bfd
, input_section
,
8985 (*parent
)->address
)))
8988 case bfd_reloc_overflow
:
8989 if (!((*link_info
->callbacks
->reloc_overflow
)
8990 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
8991 (*parent
)->howto
->name
, (*parent
)->addend
,
8992 input_bfd
, input_section
, (*parent
)->address
)))
8995 case bfd_reloc_outofrange
:
9004 if (reloc_vector
!= NULL
)
9005 free (reloc_vector
);
9009 if (reloc_vector
!= NULL
)
9010 free (reloc_vector
);
9013 #define bfd_elf32_bfd_get_relocated_section_contents \
9014 elf32_mips_get_relocated_section_contents
9016 /* ECOFF swapping routines. These are used when dealing with the
9017 .mdebug section, which is in the ECOFF debugging format. */
9018 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
9020 /* Symbol table magic number. */
9022 /* Alignment of debugging information. E.g., 4. */
9024 /* Sizes of external symbolic information. */
9025 sizeof (struct hdr_ext
),
9026 sizeof (struct dnr_ext
),
9027 sizeof (struct pdr_ext
),
9028 sizeof (struct sym_ext
),
9029 sizeof (struct opt_ext
),
9030 sizeof (struct fdr_ext
),
9031 sizeof (struct rfd_ext
),
9032 sizeof (struct ext_ext
),
9033 /* Functions to swap in external symbolic data. */
9042 _bfd_ecoff_swap_tir_in
,
9043 _bfd_ecoff_swap_rndx_in
,
9044 /* Functions to swap out external symbolic data. */
9053 _bfd_ecoff_swap_tir_out
,
9054 _bfd_ecoff_swap_rndx_out
,
9055 /* Function to read in symbolic data. */
9056 _bfd_mips_elf_read_ecoff_info
9059 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
9060 #define TARGET_LITTLE_NAME "elf32-littlemips"
9061 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
9062 #define TARGET_BIG_NAME "elf32-bigmips"
9063 #define ELF_ARCH bfd_arch_mips
9064 #define ELF_MACHINE_CODE EM_MIPS
9066 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
9067 a value of 0x1000, and we are compatible. */
9068 #define ELF_MAXPAGESIZE 0x1000
9070 #define elf_backend_collect true
9071 #define elf_backend_type_change_ok true
9072 #define elf_backend_can_gc_sections true
9073 #define elf_backend_sign_extend_vma true
9074 #define elf_info_to_howto mips_info_to_howto_rela
9075 #define elf_info_to_howto_rel mips_info_to_howto_rel
9076 #define elf_backend_sym_is_global mips_elf_sym_is_global
9077 #define elf_backend_object_p _bfd_mips_elf_object_p
9078 #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
9079 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
9080 #define elf_backend_section_from_bfd_section \
9081 _bfd_mips_elf_section_from_bfd_section
9082 #define elf_backend_section_processing _bfd_mips_elf_section_processing
9083 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
9084 #define elf_backend_additional_program_headers \
9085 _bfd_mips_elf_additional_program_headers
9086 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
9087 #define elf_backend_final_write_processing \
9088 _bfd_mips_elf_final_write_processing
9089 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
9090 #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
9091 #define elf_backend_create_dynamic_sections \
9092 _bfd_mips_elf_create_dynamic_sections
9093 #define elf_backend_check_relocs _bfd_mips_elf_check_relocs
9094 #define elf_backend_adjust_dynamic_symbol \
9095 _bfd_mips_elf_adjust_dynamic_symbol
9096 #define elf_backend_always_size_sections \
9097 _bfd_mips_elf_always_size_sections
9098 #define elf_backend_size_dynamic_sections \
9099 _bfd_mips_elf_size_dynamic_sections
9100 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section
9101 #define elf_backend_link_output_symbol_hook \
9102 _bfd_mips_elf_link_output_symbol_hook
9103 #define elf_backend_finish_dynamic_symbol \
9104 _bfd_mips_elf_finish_dynamic_symbol
9105 #define elf_backend_finish_dynamic_sections \
9106 _bfd_mips_elf_finish_dynamic_sections
9107 #define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
9108 #define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
9110 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
9111 #define elf_backend_plt_header_size 0
9113 #define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
9115 #define bfd_elf32_bfd_is_local_label_name \
9116 mips_elf_is_local_label_name
9117 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
9118 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
9119 #define bfd_elf32_bfd_link_hash_table_create \
9120 _bfd_mips_elf_link_hash_table_create
9121 #define bfd_elf32_bfd_final_link _bfd_mips_elf_final_link
9122 #define bfd_elf32_bfd_copy_private_bfd_data \
9123 _bfd_mips_elf_copy_private_bfd_data
9124 #define bfd_elf32_bfd_merge_private_bfd_data \
9125 _bfd_mips_elf_merge_private_bfd_data
9126 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
9127 #define bfd_elf32_bfd_print_private_bfd_data \
9128 _bfd_mips_elf_print_private_bfd_data
9129 #include "elf32-target.h"