1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 94, 95, 96, 97, 98, 99, 2000
3 Free Software Foundation, Inc.
5 Most of the information added by Ian Lance Taylor, Cygnus Support,
7 N32/64 ABI support added by Mark Mitchell, CodeSourcery, LLC.
8 <mark@codesourcery.com>
9 Traditional MIPS targets support added by Koundinya.K, Dansk Data
10 Elektronik & Operations Research Group. <kk@ddeorg.soft.net>
12 This file is part of BFD, the Binary File Descriptor library.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 /* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
29 different MIPS ELF from other targets. This matters when linking.
30 This file supports both, switching at runtime. */
40 /* Get the ECOFF swapping routines. */
42 #include "coff/symconst.h"
43 #include "coff/internal.h"
44 #include "coff/ecoff.h"
45 #include "coff/mips.h"
46 #define ECOFF_SIGNED_32
47 #include "ecoffswap.h"
49 /* This structure is used to hold .got information when linking. It
50 is stored in the tdata field of the bfd_elf_section_data structure. */
54 /* The global symbol in the GOT with the lowest index in the dynamic
56 struct elf_link_hash_entry
*global_gotsym
;
57 /* The number of global .got entries. */
58 unsigned int global_gotno
;
59 /* The number of local .got entries. */
60 unsigned int local_gotno
;
61 /* The number of local .got entries we have used. */
62 unsigned int assigned_gotno
;
65 /* The MIPS ELF linker needs additional information for each symbol in
66 the global hash table. */
68 struct mips_elf_link_hash_entry
70 struct elf_link_hash_entry root
;
72 /* External symbol information. */
75 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
77 unsigned int possibly_dynamic_relocs
;
79 /* The index of the first dynamic relocation (in the .rel.dyn
80 section) against this symbol. */
81 unsigned int min_dyn_reloc_index
;
83 /* We must not create a stub for a symbol that has relocations
84 related to taking the function's address, i.e. any but
85 R_MIPS_CALL*16 ones -- see "MIPS ABI Supplement, 3rd Edition",
89 /* If there is a stub that 32 bit functions should use to call this
90 16 bit function, this points to the section containing the stub. */
93 /* Whether we need the fn_stub; this is set if this symbol appears
94 in any relocs other than a 16 bit call. */
97 /* If there is a stub that 16 bit functions should use to call this
98 32 bit function, this points to the section containing the stub. */
101 /* This is like the call_stub field, but it is used if the function
102 being called returns a floating point value. */
103 asection
*call_fp_stub
;
106 static bfd_reloc_status_type mips32_64bit_reloc
107 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
108 static reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
109 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
110 static reloc_howto_type
*mips_rtype_to_howto
111 PARAMS ((unsigned int));
112 static void mips_info_to_howto_rel
113 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
114 static void mips_info_to_howto_rela
115 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rela
*));
116 static void bfd_mips_elf32_swap_gptab_in
117 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
118 static void bfd_mips_elf32_swap_gptab_out
119 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
121 static void bfd_mips_elf_swap_msym_in
122 PARAMS ((bfd
*, const Elf32_External_Msym
*, Elf32_Internal_Msym
*));
124 static void bfd_mips_elf_swap_msym_out
125 PARAMS ((bfd
*, const Elf32_Internal_Msym
*, Elf32_External_Msym
*));
126 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
127 static boolean mips_elf_create_procedure_table
128 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
129 struct ecoff_debug_info
*));
130 static INLINE
int elf_mips_isa
PARAMS ((flagword
));
131 static INLINE
int elf_mips_mach
PARAMS ((flagword
));
132 static INLINE
char* elf_mips_abi_name
PARAMS ((bfd
*));
133 static boolean mips_elf_is_local_label_name
134 PARAMS ((bfd
*, const char *));
135 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
136 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
137 static int gptab_compare
PARAMS ((const void *, const void *));
138 static bfd_reloc_status_type mips16_jump_reloc
139 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
140 static bfd_reloc_status_type mips16_gprel_reloc
141 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
142 static boolean mips_elf_create_compact_rel_section
143 PARAMS ((bfd
*, struct bfd_link_info
*));
144 static boolean mips_elf_create_got_section
145 PARAMS ((bfd
*, struct bfd_link_info
*));
146 static bfd_reloc_status_type mips_elf_final_gp
147 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
148 static bfd_byte
*elf32_mips_get_relocated_section_contents
149 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
150 bfd_byte
*, boolean
, asymbol
**));
151 static asection
*mips_elf_create_msym_section
153 static void mips_elf_irix6_finish_dynamic_symbol
154 PARAMS ((bfd
*, const char *, Elf_Internal_Sym
*));
155 static bfd_vma mips_elf_sign_extend
PARAMS ((bfd_vma
, int));
156 static boolean mips_elf_overflow_p
PARAMS ((bfd_vma
, int));
157 static bfd_vma mips_elf_high
PARAMS ((bfd_vma
));
158 static bfd_vma mips_elf_higher
PARAMS ((bfd_vma
));
159 static bfd_vma mips_elf_highest
PARAMS ((bfd_vma
));
160 static bfd_vma mips_elf_global_got_index
161 PARAMS ((bfd
*, struct elf_link_hash_entry
*));
162 static bfd_vma mips_elf_local_got_index
163 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
));
164 static bfd_vma mips_elf_got_offset_from_index
165 PARAMS ((bfd
*, bfd
*, bfd_vma
));
166 static boolean mips_elf_record_global_got_symbol
167 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*,
168 struct mips_got_info
*));
169 static bfd_vma mips_elf_got_page
170 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
, bfd_vma
*));
171 static const Elf_Internal_Rela
*mips_elf_next_relocation
172 PARAMS ((unsigned int, const Elf_Internal_Rela
*,
173 const Elf_Internal_Rela
*));
174 static bfd_reloc_status_type mips_elf_calculate_relocation
175 PARAMS ((bfd
*, bfd
*, asection
*, struct bfd_link_info
*,
176 const Elf_Internal_Rela
*, bfd_vma
, reloc_howto_type
*,
177 Elf_Internal_Sym
*, asection
**, bfd_vma
*, const char **,
179 static bfd_vma mips_elf_obtain_contents
180 PARAMS ((reloc_howto_type
*, const Elf_Internal_Rela
*, bfd
*, bfd_byte
*));
181 static boolean mips_elf_perform_relocation
182 PARAMS ((struct bfd_link_info
*, reloc_howto_type
*,
183 const Elf_Internal_Rela
*, bfd_vma
,
184 bfd
*, asection
*, bfd_byte
*, boolean
));
185 static boolean mips_elf_assign_gp
PARAMS ((bfd
*, bfd_vma
*));
186 static boolean mips_elf_sort_hash_table_f
187 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
188 static boolean mips_elf_sort_hash_table
189 PARAMS ((struct bfd_link_info
*, unsigned long));
190 static asection
* mips_elf_got_section
PARAMS ((bfd
*));
191 static struct mips_got_info
*mips_elf_got_info
192 PARAMS ((bfd
*, asection
**));
193 static boolean mips_elf_local_relocation_p
194 PARAMS ((bfd
*, const Elf_Internal_Rela
*, asection
**, boolean
));
195 static bfd_vma mips_elf_create_local_got_entry
196 PARAMS ((bfd
*, struct mips_got_info
*, asection
*, bfd_vma
));
197 static bfd_vma mips_elf_got16_entry
198 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
, boolean
));
199 static boolean mips_elf_create_dynamic_relocation
200 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
201 struct mips_elf_link_hash_entry
*, asection
*,
202 bfd_vma
, bfd_vma
*, asection
*));
203 static void mips_elf_allocate_dynamic_relocations
204 PARAMS ((bfd
*, unsigned int));
205 static boolean mips_elf_stub_section_p
206 PARAMS ((bfd
*, asection
*));
207 static int sort_dynamic_relocs
208 PARAMS ((const void *, const void *));
210 extern const bfd_target bfd_elf32_tradbigmips_vec
;
212 /* The level of IRIX compatibility we're striving for. */
220 /* This will be used when we sort the dynamic relocation records. */
221 static bfd
*reldyn_sorting_bfd
;
223 /* Nonzero if ABFD is using the N32 ABI. */
225 #define ABI_N32_P(abfd) \
226 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
228 /* Nonzero if ABFD is using the 64-bit ABI. FIXME: This is never
230 #define ABI_64_P(abfd) \
231 ((elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS64) != 0)
233 /* Depending on the target vector we generate some version of Irix
234 executables or "normal" MIPS ELF ABI executables. */
236 #define IRIX_COMPAT(abfd) \
237 (abfd->xvec == &bfd_elf32_tradbigmips_vec ? ict_none : \
238 ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5))
240 /* Whether we are trying to be compatible with IRIX at all. */
242 #define SGI_COMPAT(abfd) \
243 (IRIX_COMPAT (abfd) != ict_none)
245 /* The name of the msym section. */
246 #define MIPS_ELF_MSYM_SECTION_NAME(abfd) ".msym"
248 /* The name of the srdata section. */
249 #define MIPS_ELF_SRDATA_SECTION_NAME(abfd) ".srdata"
251 /* The name of the options section. */
252 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
253 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.options" : ".options")
255 /* The name of the stub section. */
256 #define MIPS_ELF_STUB_SECTION_NAME(abfd) \
257 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.stubs" : ".stub")
259 /* The name of the dynamic relocation section. */
260 #define MIPS_ELF_REL_DYN_SECTION_NAME(abfd) ".rel.dyn"
262 /* The size of an external REL relocation. */
263 #define MIPS_ELF_REL_SIZE(abfd) \
264 (get_elf_backend_data (abfd)->s->sizeof_rel)
266 /* The size of an external dynamic table entry. */
267 #define MIPS_ELF_DYN_SIZE(abfd) \
268 (get_elf_backend_data (abfd)->s->sizeof_dyn)
270 /* The size of a GOT entry. */
271 #define MIPS_ELF_GOT_SIZE(abfd) \
272 (get_elf_backend_data (abfd)->s->arch_size / 8)
274 /* The size of a symbol-table entry. */
275 #define MIPS_ELF_SYM_SIZE(abfd) \
276 (get_elf_backend_data (abfd)->s->sizeof_sym)
278 /* The default alignment for sections, as a power of two. */
279 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
280 (get_elf_backend_data (abfd)->s->file_align == 8 ? 3 : 2)
282 /* Get word-sized data. */
283 #define MIPS_ELF_GET_WORD(abfd, ptr) \
284 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
286 /* Put out word-sized data. */
287 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
289 ? bfd_put_64 (abfd, val, ptr) \
290 : bfd_put_32 (abfd, val, ptr))
292 /* Add a dynamic symbol table-entry. */
294 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
295 (ABI_64_P (elf_hash_table (info)->dynobj) \
296 ? bfd_elf64_add_dynamic_entry (info, tag, val) \
297 : bfd_elf32_add_dynamic_entry (info, tag, val))
299 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
300 (ABI_64_P (elf_hash_table (info)->dynobj) \
301 ? (abort (), false) \
302 : bfd_elf32_add_dynamic_entry (info, tag, val))
305 /* The number of local .got entries we reserve. */
306 #define MIPS_RESERVED_GOTNO (2)
308 /* Instructions which appear in a stub. For some reason the stub is
309 slightly different on an SGI system. */
310 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
311 #define STUB_LW(abfd) \
314 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
315 : 0x8f998010) /* lw t9,0x8010(gp) */ \
316 : 0x8f998010) /* lw t9,0x8000(gp) */
317 #define STUB_MOVE(abfd) \
318 (SGI_COMPAT (abfd) ? 0x03e07825 : 0x03e07821) /* move t7,ra */
319 #define STUB_JALR 0x0320f809 /* jal t9 */
320 #define STUB_LI16(abfd) \
321 (SGI_COMPAT (abfd) ? 0x34180000 : 0x24180000) /* ori t8,zero,0 */
322 #define MIPS_FUNCTION_STUB_SIZE (16)
325 /* We no longer try to identify particular sections for the .dynsym
326 section. When we do, we wind up crashing if there are other random
327 sections with relocations. */
329 /* Names of sections which appear in the .dynsym section in an Irix 5
332 static const char * const mips_elf_dynsym_sec_names
[] =
345 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
346 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
348 /* The number of entries in mips_elf_dynsym_sec_names which go in the
351 #define MIPS_TEXT_DYNSYM_SECNO (3)
355 /* The names of the runtime procedure table symbols used on Irix 5. */
357 static const char * const mips_elf_dynsym_rtproc_names
[] =
360 "_procedure_string_table",
361 "_procedure_table_size",
365 /* These structures are used to generate the .compact_rel section on
370 unsigned long id1
; /* Always one? */
371 unsigned long num
; /* Number of compact relocation entries. */
372 unsigned long id2
; /* Always two? */
373 unsigned long offset
; /* The file offset of the first relocation. */
374 unsigned long reserved0
; /* Zero? */
375 unsigned long reserved1
; /* Zero? */
384 bfd_byte reserved0
[4];
385 bfd_byte reserved1
[4];
386 } Elf32_External_compact_rel
;
390 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
391 unsigned int rtype
: 4; /* Relocation types. See below. */
392 unsigned int dist2to
: 8;
393 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
394 unsigned long konst
; /* KONST field. See below. */
395 unsigned long vaddr
; /* VADDR to be relocated. */
400 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
401 unsigned int rtype
: 4; /* Relocation types. See below. */
402 unsigned int dist2to
: 8;
403 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
404 unsigned long konst
; /* KONST field. See below. */
412 } Elf32_External_crinfo
;
418 } Elf32_External_crinfo2
;
420 /* These are the constants used to swap the bitfields in a crinfo. */
422 #define CRINFO_CTYPE (0x1)
423 #define CRINFO_CTYPE_SH (31)
424 #define CRINFO_RTYPE (0xf)
425 #define CRINFO_RTYPE_SH (27)
426 #define CRINFO_DIST2TO (0xff)
427 #define CRINFO_DIST2TO_SH (19)
428 #define CRINFO_RELVADDR (0x7ffff)
429 #define CRINFO_RELVADDR_SH (0)
431 /* A compact relocation info has long (3 words) or short (2 words)
432 formats. A short format doesn't have VADDR field and relvaddr
433 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
434 #define CRF_MIPS_LONG 1
435 #define CRF_MIPS_SHORT 0
437 /* There are 4 types of compact relocation at least. The value KONST
438 has different meaning for each type:
441 CT_MIPS_REL32 Address in data
442 CT_MIPS_WORD Address in word (XXX)
443 CT_MIPS_GPHI_LO GP - vaddr
444 CT_MIPS_JMPAD Address to jump
447 #define CRT_MIPS_REL32 0xa
448 #define CRT_MIPS_WORD 0xb
449 #define CRT_MIPS_GPHI_LO 0xc
450 #define CRT_MIPS_JMPAD 0xd
452 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
453 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
454 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
455 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
457 static void bfd_elf32_swap_compact_rel_out
458 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
459 static void bfd_elf32_swap_crinfo_out
460 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
462 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
464 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
465 from smaller values. Start with zero, widen, *then* decrement. */
466 #define MINUS_ONE (((bfd_vma)0) - 1)
468 static reloc_howto_type elf_mips_howto_table
[] =
471 HOWTO (R_MIPS_NONE
, /* type */
473 0, /* size (0 = byte, 1 = short, 2 = long) */
475 false, /* pc_relative */
477 complain_overflow_dont
, /* complain_on_overflow */
478 bfd_elf_generic_reloc
, /* special_function */
479 "R_MIPS_NONE", /* name */
480 false, /* partial_inplace */
483 false), /* pcrel_offset */
485 /* 16 bit relocation. */
486 HOWTO (R_MIPS_16
, /* type */
488 1, /* size (0 = byte, 1 = short, 2 = long) */
490 false, /* pc_relative */
492 complain_overflow_bitfield
, /* complain_on_overflow */
493 bfd_elf_generic_reloc
, /* special_function */
494 "R_MIPS_16", /* name */
495 true, /* partial_inplace */
496 0xffff, /* src_mask */
497 0xffff, /* dst_mask */
498 false), /* pcrel_offset */
500 /* 32 bit relocation. */
501 HOWTO (R_MIPS_32
, /* type */
503 2, /* size (0 = byte, 1 = short, 2 = long) */
505 false, /* pc_relative */
507 complain_overflow_bitfield
, /* complain_on_overflow */
508 bfd_elf_generic_reloc
, /* special_function */
509 "R_MIPS_32", /* name */
510 true, /* partial_inplace */
511 0xffffffff, /* src_mask */
512 0xffffffff, /* dst_mask */
513 false), /* pcrel_offset */
515 /* 32 bit symbol relative relocation. */
516 HOWTO (R_MIPS_REL32
, /* type */
518 2, /* size (0 = byte, 1 = short, 2 = long) */
520 false, /* pc_relative */
522 complain_overflow_bitfield
, /* complain_on_overflow */
523 bfd_elf_generic_reloc
, /* special_function */
524 "R_MIPS_REL32", /* name */
525 true, /* partial_inplace */
526 0xffffffff, /* src_mask */
527 0xffffffff, /* dst_mask */
528 false), /* pcrel_offset */
530 /* 26 bit branch address. */
531 HOWTO (R_MIPS_26
, /* type */
533 2, /* size (0 = byte, 1 = short, 2 = long) */
535 false, /* pc_relative */
537 complain_overflow_dont
, /* complain_on_overflow */
538 /* This needs complex overflow
539 detection, because the upper four
540 bits must match the PC + 4. */
541 bfd_elf_generic_reloc
, /* special_function */
542 "R_MIPS_26", /* name */
543 true, /* partial_inplace */
544 0x3ffffff, /* src_mask */
545 0x3ffffff, /* dst_mask */
546 false), /* pcrel_offset */
548 /* High 16 bits of symbol value. */
549 HOWTO (R_MIPS_HI16
, /* type */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
553 false, /* pc_relative */
555 complain_overflow_dont
, /* complain_on_overflow */
556 _bfd_mips_elf_hi16_reloc
, /* special_function */
557 "R_MIPS_HI16", /* name */
558 true, /* partial_inplace */
559 0xffff, /* src_mask */
560 0xffff, /* dst_mask */
561 false), /* pcrel_offset */
563 /* Low 16 bits of symbol value. */
564 HOWTO (R_MIPS_LO16
, /* type */
566 2, /* size (0 = byte, 1 = short, 2 = long) */
568 false, /* pc_relative */
570 complain_overflow_dont
, /* complain_on_overflow */
571 _bfd_mips_elf_lo16_reloc
, /* special_function */
572 "R_MIPS_LO16", /* name */
573 true, /* partial_inplace */
574 0xffff, /* src_mask */
575 0xffff, /* dst_mask */
576 false), /* pcrel_offset */
578 /* GP relative reference. */
579 HOWTO (R_MIPS_GPREL16
, /* type */
581 2, /* size (0 = byte, 1 = short, 2 = long) */
583 false, /* pc_relative */
585 complain_overflow_signed
, /* complain_on_overflow */
586 _bfd_mips_elf_gprel16_reloc
, /* special_function */
587 "R_MIPS_GPREL16", /* name */
588 true, /* partial_inplace */
589 0xffff, /* src_mask */
590 0xffff, /* dst_mask */
591 false), /* pcrel_offset */
593 /* Reference to literal section. */
594 HOWTO (R_MIPS_LITERAL
, /* type */
596 2, /* size (0 = byte, 1 = short, 2 = long) */
598 false, /* pc_relative */
600 complain_overflow_signed
, /* complain_on_overflow */
601 _bfd_mips_elf_gprel16_reloc
, /* special_function */
602 "R_MIPS_LITERAL", /* name */
603 true, /* partial_inplace */
604 0xffff, /* src_mask */
605 0xffff, /* dst_mask */
606 false), /* pcrel_offset */
608 /* Reference to global offset table. */
609 HOWTO (R_MIPS_GOT16
, /* type */
611 2, /* size (0 = byte, 1 = short, 2 = long) */
613 false, /* pc_relative */
615 complain_overflow_signed
, /* complain_on_overflow */
616 _bfd_mips_elf_got16_reloc
, /* special_function */
617 "R_MIPS_GOT16", /* name */
618 false, /* partial_inplace */
619 0xffff, /* src_mask */
620 0xffff, /* dst_mask */
621 false), /* pcrel_offset */
623 /* 16 bit PC relative reference. */
624 HOWTO (R_MIPS_PC16
, /* type */
626 2, /* size (0 = byte, 1 = short, 2 = long) */
628 true, /* pc_relative */
630 complain_overflow_signed
, /* complain_on_overflow */
631 bfd_elf_generic_reloc
, /* special_function */
632 "R_MIPS_PC16", /* name */
633 true, /* partial_inplace */
634 0xffff, /* src_mask */
635 0xffff, /* dst_mask */
636 true), /* pcrel_offset */
638 /* 16 bit call through global offset table. */
639 HOWTO (R_MIPS_CALL16
, /* type */
641 2, /* size (0 = byte, 1 = short, 2 = long) */
643 false, /* pc_relative */
645 complain_overflow_signed
, /* complain_on_overflow */
646 bfd_elf_generic_reloc
, /* special_function */
647 "R_MIPS_CALL16", /* name */
648 false, /* partial_inplace */
649 0xffff, /* src_mask */
650 0xffff, /* dst_mask */
651 false), /* pcrel_offset */
653 /* 32 bit GP relative reference. */
654 HOWTO (R_MIPS_GPREL32
, /* type */
656 2, /* size (0 = byte, 1 = short, 2 = long) */
658 false, /* pc_relative */
660 complain_overflow_bitfield
, /* complain_on_overflow */
661 _bfd_mips_elf_gprel32_reloc
, /* special_function */
662 "R_MIPS_GPREL32", /* name */
663 true, /* partial_inplace */
664 0xffffffff, /* src_mask */
665 0xffffffff, /* dst_mask */
666 false), /* pcrel_offset */
668 /* The remaining relocs are defined on Irix 5, although they are
669 not defined by the ABI. */
674 /* A 5 bit shift field. */
675 HOWTO (R_MIPS_SHIFT5
, /* type */
677 2, /* size (0 = byte, 1 = short, 2 = long) */
679 false, /* pc_relative */
681 complain_overflow_bitfield
, /* complain_on_overflow */
682 bfd_elf_generic_reloc
, /* special_function */
683 "R_MIPS_SHIFT5", /* name */
684 true, /* partial_inplace */
685 0x000007c0, /* src_mask */
686 0x000007c0, /* dst_mask */
687 false), /* pcrel_offset */
689 /* A 6 bit shift field. */
690 /* FIXME: This is not handled correctly; a special function is
691 needed to put the most significant bit in the right place. */
692 HOWTO (R_MIPS_SHIFT6
, /* type */
694 2, /* size (0 = byte, 1 = short, 2 = long) */
696 false, /* pc_relative */
698 complain_overflow_bitfield
, /* complain_on_overflow */
699 bfd_elf_generic_reloc
, /* special_function */
700 "R_MIPS_SHIFT6", /* name */
701 true, /* partial_inplace */
702 0x000007c4, /* src_mask */
703 0x000007c4, /* dst_mask */
704 false), /* pcrel_offset */
706 /* A 64 bit relocation. */
707 HOWTO (R_MIPS_64
, /* type */
709 4, /* size (0 = byte, 1 = short, 2 = long) */
711 false, /* pc_relative */
713 complain_overflow_bitfield
, /* complain_on_overflow */
714 mips32_64bit_reloc
, /* special_function */
715 "R_MIPS_64", /* name */
716 true, /* partial_inplace */
717 MINUS_ONE
, /* src_mask */
718 MINUS_ONE
, /* dst_mask */
719 false), /* pcrel_offset */
721 /* Displacement in the global offset table. */
722 HOWTO (R_MIPS_GOT_DISP
, /* type */
724 2, /* size (0 = byte, 1 = short, 2 = long) */
726 false, /* pc_relative */
728 complain_overflow_bitfield
, /* complain_on_overflow */
729 bfd_elf_generic_reloc
, /* special_function */
730 "R_MIPS_GOT_DISP", /* name */
731 true, /* partial_inplace */
732 0x0000ffff, /* src_mask */
733 0x0000ffff, /* dst_mask */
734 false), /* pcrel_offset */
736 /* Displacement to page pointer in the global offset table. */
737 HOWTO (R_MIPS_GOT_PAGE
, /* type */
739 2, /* size (0 = byte, 1 = short, 2 = long) */
741 false, /* pc_relative */
743 complain_overflow_bitfield
, /* complain_on_overflow */
744 bfd_elf_generic_reloc
, /* special_function */
745 "R_MIPS_GOT_PAGE", /* name */
746 true, /* partial_inplace */
747 0x0000ffff, /* src_mask */
748 0x0000ffff, /* dst_mask */
749 false), /* pcrel_offset */
751 /* Offset from page pointer in the global offset table. */
752 HOWTO (R_MIPS_GOT_OFST
, /* type */
754 2, /* size (0 = byte, 1 = short, 2 = long) */
756 false, /* pc_relative */
758 complain_overflow_bitfield
, /* complain_on_overflow */
759 bfd_elf_generic_reloc
, /* special_function */
760 "R_MIPS_GOT_OFST", /* name */
761 true, /* partial_inplace */
762 0x0000ffff, /* src_mask */
763 0x0000ffff, /* dst_mask */
764 false), /* pcrel_offset */
766 /* High 16 bits of displacement in global offset table. */
767 HOWTO (R_MIPS_GOT_HI16
, /* type */
769 2, /* size (0 = byte, 1 = short, 2 = long) */
771 false, /* pc_relative */
773 complain_overflow_dont
, /* complain_on_overflow */
774 bfd_elf_generic_reloc
, /* special_function */
775 "R_MIPS_GOT_HI16", /* name */
776 true, /* partial_inplace */
777 0x0000ffff, /* src_mask */
778 0x0000ffff, /* dst_mask */
779 false), /* pcrel_offset */
781 /* Low 16 bits of displacement in global offset table. */
782 HOWTO (R_MIPS_GOT_LO16
, /* type */
784 2, /* size (0 = byte, 1 = short, 2 = long) */
786 false, /* pc_relative */
788 complain_overflow_dont
, /* complain_on_overflow */
789 bfd_elf_generic_reloc
, /* special_function */
790 "R_MIPS_GOT_LO16", /* name */
791 true, /* partial_inplace */
792 0x0000ffff, /* src_mask */
793 0x0000ffff, /* dst_mask */
794 false), /* pcrel_offset */
796 /* 64 bit subtraction. Used in the N32 ABI. */
797 HOWTO (R_MIPS_SUB
, /* type */
799 4, /* size (0 = byte, 1 = short, 2 = long) */
801 false, /* pc_relative */
803 complain_overflow_bitfield
, /* complain_on_overflow */
804 bfd_elf_generic_reloc
, /* special_function */
805 "R_MIPS_SUB", /* name */
806 true, /* partial_inplace */
807 MINUS_ONE
, /* src_mask */
808 MINUS_ONE
, /* dst_mask */
809 false), /* pcrel_offset */
811 /* Used to cause the linker to insert and delete instructions? */
812 EMPTY_HOWTO (R_MIPS_INSERT_A
),
813 EMPTY_HOWTO (R_MIPS_INSERT_B
),
814 EMPTY_HOWTO (R_MIPS_DELETE
),
816 /* Get the higher value of a 64 bit addend. */
817 HOWTO (R_MIPS_HIGHER
, /* type */
819 2, /* size (0 = byte, 1 = short, 2 = long) */
821 false, /* pc_relative */
823 complain_overflow_dont
, /* complain_on_overflow */
824 bfd_elf_generic_reloc
, /* special_function */
825 "R_MIPS_HIGHER", /* name */
826 true, /* partial_inplace */
828 0xffff, /* dst_mask */
829 false), /* pcrel_offset */
831 /* Get the highest value of a 64 bit addend. */
832 HOWTO (R_MIPS_HIGHEST
, /* type */
834 2, /* size (0 = byte, 1 = short, 2 = long) */
836 false, /* pc_relative */
838 complain_overflow_dont
, /* complain_on_overflow */
839 bfd_elf_generic_reloc
, /* special_function */
840 "R_MIPS_HIGHEST", /* name */
841 true, /* partial_inplace */
843 0xffff, /* dst_mask */
844 false), /* pcrel_offset */
846 /* High 16 bits of displacement in global offset table. */
847 HOWTO (R_MIPS_CALL_HI16
, /* type */
849 2, /* size (0 = byte, 1 = short, 2 = long) */
851 false, /* pc_relative */
853 complain_overflow_dont
, /* complain_on_overflow */
854 bfd_elf_generic_reloc
, /* special_function */
855 "R_MIPS_CALL_HI16", /* name */
856 true, /* partial_inplace */
857 0x0000ffff, /* src_mask */
858 0x0000ffff, /* dst_mask */
859 false), /* pcrel_offset */
861 /* Low 16 bits of displacement in global offset table. */
862 HOWTO (R_MIPS_CALL_LO16
, /* type */
864 2, /* size (0 = byte, 1 = short, 2 = long) */
866 false, /* pc_relative */
868 complain_overflow_dont
, /* complain_on_overflow */
869 bfd_elf_generic_reloc
, /* special_function */
870 "R_MIPS_CALL_LO16", /* name */
871 true, /* partial_inplace */
872 0x0000ffff, /* src_mask */
873 0x0000ffff, /* dst_mask */
874 false), /* pcrel_offset */
876 /* Section displacement. */
877 HOWTO (R_MIPS_SCN_DISP
, /* type */
879 2, /* size (0 = byte, 1 = short, 2 = long) */
881 false, /* pc_relative */
883 complain_overflow_dont
, /* complain_on_overflow */
884 bfd_elf_generic_reloc
, /* special_function */
885 "R_MIPS_SCN_DISP", /* name */
886 false, /* partial_inplace */
887 0xffffffff, /* src_mask */
888 0xffffffff, /* dst_mask */
889 false), /* pcrel_offset */
891 EMPTY_HOWTO (R_MIPS_REL16
),
892 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE
),
893 EMPTY_HOWTO (R_MIPS_PJUMP
),
894 EMPTY_HOWTO (R_MIPS_RELGOT
),
896 /* Protected jump conversion. This is an optimization hint. No
897 relocation is required for correctness. */
898 HOWTO (R_MIPS_JALR
, /* type */
900 0, /* size (0 = byte, 1 = short, 2 = long) */
902 false, /* pc_relative */
904 complain_overflow_dont
, /* complain_on_overflow */
905 bfd_elf_generic_reloc
, /* special_function */
906 "R_MIPS_JALR", /* name */
907 false, /* partial_inplace */
908 0x00000000, /* src_mask */
909 0x00000000, /* dst_mask */
910 false), /* pcrel_offset */
913 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
914 is a hack to make the linker think that we need 64 bit values. */
915 static reloc_howto_type elf_mips_ctor64_howto
=
916 HOWTO (R_MIPS_64
, /* type */
918 4, /* size (0 = byte, 1 = short, 2 = long) */
920 false, /* pc_relative */
922 complain_overflow_signed
, /* complain_on_overflow */
923 mips32_64bit_reloc
, /* special_function */
924 "R_MIPS_64", /* name */
925 true, /* partial_inplace */
926 0xffffffff, /* src_mask */
927 0xffffffff, /* dst_mask */
928 false); /* pcrel_offset */
930 /* The reloc used for the mips16 jump instruction. */
931 static reloc_howto_type elf_mips16_jump_howto
=
932 HOWTO (R_MIPS16_26
, /* type */
934 2, /* size (0 = byte, 1 = short, 2 = long) */
936 false, /* pc_relative */
938 complain_overflow_dont
, /* complain_on_overflow */
939 /* This needs complex overflow
940 detection, because the upper four
941 bits must match the PC. */
942 mips16_jump_reloc
, /* special_function */
943 "R_MIPS16_26", /* name */
944 true, /* partial_inplace */
945 0x3ffffff, /* src_mask */
946 0x3ffffff, /* dst_mask */
947 false); /* pcrel_offset */
949 /* The reloc used for the mips16 gprel instruction. */
950 static reloc_howto_type elf_mips16_gprel_howto
=
951 HOWTO (R_MIPS16_GPREL
, /* type */
953 2, /* size (0 = byte, 1 = short, 2 = long) */
955 false, /* pc_relative */
957 complain_overflow_signed
, /* complain_on_overflow */
958 mips16_gprel_reloc
, /* special_function */
959 "R_MIPS16_GPREL", /* name */
960 true, /* partial_inplace */
961 0x07ff001f, /* src_mask */
962 0x07ff001f, /* dst_mask */
963 false); /* pcrel_offset */
965 /* GNU extensions for embedded-pic. */
966 /* High 16 bits of symbol value, pc-relative. */
967 static reloc_howto_type elf_mips_gnu_rel_hi16
=
968 HOWTO (R_MIPS_GNU_REL_HI16
, /* type */
970 2, /* size (0 = byte, 1 = short, 2 = long) */
972 true, /* pc_relative */
974 complain_overflow_dont
, /* complain_on_overflow */
975 _bfd_mips_elf_hi16_reloc
, /* special_function */
976 "R_MIPS_GNU_REL_HI16", /* name */
977 true, /* partial_inplace */
978 0xffff, /* src_mask */
979 0xffff, /* dst_mask */
980 true); /* pcrel_offset */
982 /* Low 16 bits of symbol value, pc-relative. */
983 static reloc_howto_type elf_mips_gnu_rel_lo16
=
984 HOWTO (R_MIPS_GNU_REL_LO16
, /* type */
986 2, /* size (0 = byte, 1 = short, 2 = long) */
988 true, /* pc_relative */
990 complain_overflow_dont
, /* complain_on_overflow */
991 _bfd_mips_elf_lo16_reloc
, /* special_function */
992 "R_MIPS_GNU_REL_LO16", /* name */
993 true, /* partial_inplace */
994 0xffff, /* src_mask */
995 0xffff, /* dst_mask */
996 true); /* pcrel_offset */
998 /* 16 bit offset for pc-relative branches. */
999 static reloc_howto_type elf_mips_gnu_rel16_s2
=
1000 HOWTO (R_MIPS_GNU_REL16_S2
, /* type */
1002 2, /* size (0 = byte, 1 = short, 2 = long) */
1004 true, /* pc_relative */
1006 complain_overflow_signed
, /* complain_on_overflow */
1007 bfd_elf_generic_reloc
, /* special_function */
1008 "R_MIPS_GNU_REL16_S2", /* name */
1009 true, /* partial_inplace */
1010 0xffff, /* src_mask */
1011 0xffff, /* dst_mask */
1012 true); /* pcrel_offset */
1014 /* 64 bit pc-relative. */
1015 static reloc_howto_type elf_mips_gnu_pcrel64
=
1016 HOWTO (R_MIPS_PC64
, /* type */
1018 4, /* size (0 = byte, 1 = short, 2 = long) */
1020 true, /* pc_relative */
1022 complain_overflow_signed
, /* complain_on_overflow */
1023 bfd_elf_generic_reloc
, /* special_function */
1024 "R_MIPS_PC64", /* name */
1025 true, /* partial_inplace */
1026 MINUS_ONE
, /* src_mask */
1027 MINUS_ONE
, /* dst_mask */
1028 true); /* pcrel_offset */
1030 /* 32 bit pc-relative. */
1031 static reloc_howto_type elf_mips_gnu_pcrel32
=
1032 HOWTO (R_MIPS_PC32
, /* type */
1034 2, /* size (0 = byte, 1 = short, 2 = long) */
1036 true, /* pc_relative */
1038 complain_overflow_signed
, /* complain_on_overflow */
1039 bfd_elf_generic_reloc
, /* special_function */
1040 "R_MIPS_PC32", /* name */
1041 true, /* partial_inplace */
1042 0xffffffff, /* src_mask */
1043 0xffffffff, /* dst_mask */
1044 true); /* pcrel_offset */
1046 /* GNU extension to record C++ vtable hierarchy */
1047 static reloc_howto_type elf_mips_gnu_vtinherit_howto
=
1048 HOWTO (R_MIPS_GNU_VTINHERIT
, /* type */
1050 2, /* size (0 = byte, 1 = short, 2 = long) */
1052 false, /* pc_relative */
1054 complain_overflow_dont
, /* complain_on_overflow */
1055 NULL
, /* special_function */
1056 "R_MIPS_GNU_VTINHERIT", /* name */
1057 false, /* partial_inplace */
1060 false); /* pcrel_offset */
1062 /* GNU extension to record C++ vtable member usage */
1063 static reloc_howto_type elf_mips_gnu_vtentry_howto
=
1064 HOWTO (R_MIPS_GNU_VTENTRY
, /* type */
1066 2, /* size (0 = byte, 1 = short, 2 = long) */
1068 false, /* pc_relative */
1070 complain_overflow_dont
, /* complain_on_overflow */
1071 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
1072 "R_MIPS_GNU_VTENTRY", /* name */
1073 false, /* partial_inplace */
1076 false); /* pcrel_offset */
1078 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
1079 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
1080 the HI16. Here we just save the information we need; we do the
1081 actual relocation when we see the LO16. MIPS ELF requires that the
1082 LO16 immediately follow the HI16. As a GNU extension, we permit an
1083 arbitrary number of HI16 relocs to be associated with a single LO16
1084 reloc. This extension permits gcc to output the HI and LO relocs
1089 struct mips_hi16
*next
;
1094 /* FIXME: This should not be a static variable. */
1096 static struct mips_hi16
*mips_hi16_list
;
1098 bfd_reloc_status_type
1099 _bfd_mips_elf_hi16_reloc (abfd
,
1106 bfd
*abfd ATTRIBUTE_UNUSED
;
1107 arelent
*reloc_entry
;
1110 asection
*input_section
;
1112 char **error_message
;
1114 bfd_reloc_status_type ret
;
1116 struct mips_hi16
*n
;
1118 /* If we're relocating, and this an external symbol, we don't want
1119 to change anything. */
1120 if (output_bfd
!= (bfd
*) NULL
1121 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1122 && reloc_entry
->addend
== 0)
1124 reloc_entry
->address
+= input_section
->output_offset
;
1125 return bfd_reloc_ok
;
1130 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1132 boolean relocateable
;
1135 if (ret
== bfd_reloc_undefined
)
1138 if (output_bfd
!= NULL
)
1139 relocateable
= true;
1142 relocateable
= false;
1143 output_bfd
= symbol
->section
->output_section
->owner
;
1146 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1147 error_message
, &gp
);
1148 if (ret
!= bfd_reloc_ok
)
1151 relocation
= gp
- reloc_entry
->address
;
1155 if (bfd_is_und_section (symbol
->section
)
1156 && output_bfd
== (bfd
*) NULL
)
1157 ret
= bfd_reloc_undefined
;
1159 if (bfd_is_com_section (symbol
->section
))
1162 relocation
= symbol
->value
;
1165 relocation
+= symbol
->section
->output_section
->vma
;
1166 relocation
+= symbol
->section
->output_offset
;
1167 relocation
+= reloc_entry
->addend
;
1169 if (reloc_entry
->address
> input_section
->_cooked_size
)
1170 return bfd_reloc_outofrange
;
1172 /* Save the information, and let LO16 do the actual relocation. */
1173 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
1175 return bfd_reloc_outofrange
;
1176 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
1177 n
->addend
= relocation
;
1178 n
->next
= mips_hi16_list
;
1181 if (output_bfd
!= (bfd
*) NULL
)
1182 reloc_entry
->address
+= input_section
->output_offset
;
1187 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
1188 inplace relocation; this function exists in order to do the
1189 R_MIPS_HI16 relocation described above. */
1191 bfd_reloc_status_type
1192 _bfd_mips_elf_lo16_reloc (abfd
,
1200 arelent
*reloc_entry
;
1203 asection
*input_section
;
1205 char **error_message
;
1207 arelent gp_disp_relent
;
1209 if (mips_hi16_list
!= NULL
)
1211 struct mips_hi16
*l
;
1218 unsigned long vallo
;
1219 struct mips_hi16
*next
;
1221 /* Do the HI16 relocation. Note that we actually don't need
1222 to know anything about the LO16 itself, except where to
1223 find the low 16 bits of the addend needed by the LO16. */
1224 insn
= bfd_get_32 (abfd
, l
->addr
);
1225 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
1227 val
= ((insn
& 0xffff) << 16) + vallo
;
1230 /* The low order 16 bits are always treated as a signed
1231 value. Therefore, a negative value in the low order bits
1232 requires an adjustment in the high order bits. We need
1233 to make this adjustment in two ways: once for the bits we
1234 took from the data, and once for the bits we are putting
1235 back in to the data. */
1236 if ((vallo
& 0x8000) != 0)
1238 if ((val
& 0x8000) != 0)
1241 insn
= (insn
& ~0xffff) | ((val
>> 16) & 0xffff);
1242 bfd_put_32 (abfd
, insn
, l
->addr
);
1244 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1246 gp_disp_relent
= *reloc_entry
;
1247 reloc_entry
= &gp_disp_relent
;
1248 reloc_entry
->addend
= l
->addend
;
1256 mips_hi16_list
= NULL
;
1258 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1260 bfd_reloc_status_type ret
;
1261 bfd_vma gp
, relocation
;
1263 /* FIXME: Does this case ever occur? */
1265 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
1266 if (ret
!= bfd_reloc_ok
)
1269 relocation
= gp
- reloc_entry
->address
;
1270 relocation
+= symbol
->section
->output_section
->vma
;
1271 relocation
+= symbol
->section
->output_offset
;
1272 relocation
+= reloc_entry
->addend
;
1274 if (reloc_entry
->address
> input_section
->_cooked_size
)
1275 return bfd_reloc_outofrange
;
1277 gp_disp_relent
= *reloc_entry
;
1278 reloc_entry
= &gp_disp_relent
;
1279 reloc_entry
->addend
= relocation
- 4;
1282 /* Now do the LO16 reloc in the usual way. */
1283 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1284 input_section
, output_bfd
, error_message
);
1287 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1288 table used for PIC code. If the symbol is an external symbol, the
1289 instruction is modified to contain the offset of the appropriate
1290 entry in the global offset table. If the symbol is a section
1291 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1292 addends are combined to form the real addend against the section
1293 symbol; the GOT16 is modified to contain the offset of an entry in
1294 the global offset table, and the LO16 is modified to offset it
1295 appropriately. Thus an offset larger than 16 bits requires a
1296 modified value in the global offset table.
1298 This implementation suffices for the assembler, but the linker does
1299 not yet know how to create global offset tables. */
1301 bfd_reloc_status_type
1302 _bfd_mips_elf_got16_reloc (abfd
,
1310 arelent
*reloc_entry
;
1313 asection
*input_section
;
1315 char **error_message
;
1317 /* If we're relocating, and this an external symbol, we don't want
1318 to change anything. */
1319 if (output_bfd
!= (bfd
*) NULL
1320 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1321 && reloc_entry
->addend
== 0)
1323 reloc_entry
->address
+= input_section
->output_offset
;
1324 return bfd_reloc_ok
;
1327 /* If we're relocating, and this is a local symbol, we can handle it
1329 if (output_bfd
!= (bfd
*) NULL
1330 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1331 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1332 input_section
, output_bfd
, error_message
);
1337 /* Set the GP value for OUTPUT_BFD. Returns false if this is a
1338 dangerous relocation. */
1341 mips_elf_assign_gp (output_bfd
, pgp
)
1349 /* If we've already figured out what GP will be, just return it. */
1350 *pgp
= _bfd_get_gp_value (output_bfd
);
1354 count
= bfd_get_symcount (output_bfd
);
1355 sym
= bfd_get_outsymbols (output_bfd
);
1357 /* The linker script will have created a symbol named `_gp' with the
1358 appropriate value. */
1359 if (sym
== (asymbol
**) NULL
)
1363 for (i
= 0; i
< count
; i
++, sym
++)
1365 register CONST
char *name
;
1367 name
= bfd_asymbol_name (*sym
);
1368 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1370 *pgp
= bfd_asymbol_value (*sym
);
1371 _bfd_set_gp_value (output_bfd
, *pgp
);
1379 /* Only get the error once. */
1381 _bfd_set_gp_value (output_bfd
, *pgp
);
1388 /* We have to figure out the gp value, so that we can adjust the
1389 symbol value correctly. We look up the symbol _gp in the output
1390 BFD. If we can't find it, we're stuck. We cache it in the ELF
1391 target data. We don't need to adjust the symbol value for an
1392 external symbol if we are producing relocateable output. */
1394 static bfd_reloc_status_type
1395 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1398 boolean relocateable
;
1399 char **error_message
;
1402 if (bfd_is_und_section (symbol
->section
)
1406 return bfd_reloc_undefined
;
1409 *pgp
= _bfd_get_gp_value (output_bfd
);
1412 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1416 /* Make up a value. */
1417 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1418 _bfd_set_gp_value (output_bfd
, *pgp
);
1420 else if (!mips_elf_assign_gp (output_bfd
, pgp
))
1423 (char *) _("GP relative relocation when _gp not defined");
1424 return bfd_reloc_dangerous
;
1428 return bfd_reloc_ok
;
1431 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1432 become the offset from the gp register. This function also handles
1433 R_MIPS_LITERAL relocations, although those can be handled more
1434 cleverly because the entries in the .lit8 and .lit4 sections can be
1437 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1438 arelent
*, asection
*,
1439 boolean
, PTR
, bfd_vma
));
1441 bfd_reloc_status_type
1442 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1443 output_bfd
, error_message
)
1445 arelent
*reloc_entry
;
1448 asection
*input_section
;
1450 char **error_message
;
1452 boolean relocateable
;
1453 bfd_reloc_status_type ret
;
1456 /* If we're relocating, and this is an external symbol with no
1457 addend, we don't want to change anything. We will only have an
1458 addend if this is a newly created reloc, not read from an ELF
1460 if (output_bfd
!= (bfd
*) NULL
1461 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1462 && reloc_entry
->addend
== 0)
1464 reloc_entry
->address
+= input_section
->output_offset
;
1465 return bfd_reloc_ok
;
1468 if (output_bfd
!= (bfd
*) NULL
)
1469 relocateable
= true;
1472 relocateable
= false;
1473 output_bfd
= symbol
->section
->output_section
->owner
;
1476 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1478 if (ret
!= bfd_reloc_ok
)
1481 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1482 relocateable
, data
, gp
);
1485 static bfd_reloc_status_type
1486 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1490 arelent
*reloc_entry
;
1491 asection
*input_section
;
1492 boolean relocateable
;
1500 if (bfd_is_com_section (symbol
->section
))
1503 relocation
= symbol
->value
;
1505 relocation
+= symbol
->section
->output_section
->vma
;
1506 relocation
+= symbol
->section
->output_offset
;
1508 if (reloc_entry
->address
> input_section
->_cooked_size
)
1509 return bfd_reloc_outofrange
;
1511 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1513 /* Set val to the offset into the section or symbol. */
1514 if (reloc_entry
->howto
->src_mask
== 0)
1516 /* This case occurs with the 64-bit MIPS ELF ABI. */
1517 val
= reloc_entry
->addend
;
1521 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1526 /* Adjust val for the final section location and GP value. If we
1527 are producing relocateable output, we don't want to do this for
1528 an external symbol. */
1530 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1531 val
+= relocation
- gp
;
1533 insn
= (insn
& ~0xffff) | (val
& 0xffff);
1534 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1537 reloc_entry
->address
+= input_section
->output_offset
;
1539 /* Make sure it fit in 16 bits. */
1540 if ((long) val
>= 0x8000 || (long) val
< -0x8000)
1541 return bfd_reloc_overflow
;
1543 return bfd_reloc_ok
;
1546 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1547 from the gp register? XXX */
1549 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1550 arelent
*, asection
*,
1551 boolean
, PTR
, bfd_vma
));
1553 bfd_reloc_status_type
1554 _bfd_mips_elf_gprel32_reloc (abfd
,
1562 arelent
*reloc_entry
;
1565 asection
*input_section
;
1567 char **error_message
;
1569 boolean relocateable
;
1570 bfd_reloc_status_type ret
;
1573 /* If we're relocating, and this is an external symbol with no
1574 addend, we don't want to change anything. We will only have an
1575 addend if this is a newly created reloc, not read from an ELF
1577 if (output_bfd
!= (bfd
*) NULL
1578 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1579 && reloc_entry
->addend
== 0)
1581 *error_message
= (char *)
1582 _("32bits gp relative relocation occurs for an external symbol");
1583 return bfd_reloc_outofrange
;
1586 if (output_bfd
!= (bfd
*) NULL
)
1588 relocateable
= true;
1589 gp
= _bfd_get_gp_value (output_bfd
);
1593 relocateable
= false;
1594 output_bfd
= symbol
->section
->output_section
->owner
;
1596 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1597 error_message
, &gp
);
1598 if (ret
!= bfd_reloc_ok
)
1602 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1603 relocateable
, data
, gp
);
1606 static bfd_reloc_status_type
1607 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1611 arelent
*reloc_entry
;
1612 asection
*input_section
;
1613 boolean relocateable
;
1620 if (bfd_is_com_section (symbol
->section
))
1623 relocation
= symbol
->value
;
1625 relocation
+= symbol
->section
->output_section
->vma
;
1626 relocation
+= symbol
->section
->output_offset
;
1628 if (reloc_entry
->address
> input_section
->_cooked_size
)
1629 return bfd_reloc_outofrange
;
1631 if (reloc_entry
->howto
->src_mask
== 0)
1633 /* This case arises with the 64-bit MIPS ELF ABI. */
1637 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1639 /* Set val to the offset into the section or symbol. */
1640 val
+= reloc_entry
->addend
;
1642 /* Adjust val for the final section location and GP value. If we
1643 are producing relocateable output, we don't want to do this for
1644 an external symbol. */
1646 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1647 val
+= relocation
- gp
;
1649 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1652 reloc_entry
->address
+= input_section
->output_offset
;
1654 return bfd_reloc_ok
;
1657 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1658 generated when addreses are 64 bits. The upper 32 bits are a simle
1661 static bfd_reloc_status_type
1662 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1663 output_bfd
, error_message
)
1665 arelent
*reloc_entry
;
1668 asection
*input_section
;
1670 char **error_message
;
1672 bfd_reloc_status_type r
;
1677 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1678 input_section
, output_bfd
, error_message
);
1679 if (r
!= bfd_reloc_continue
)
1682 /* Do a normal 32 bit relocation on the lower 32 bits. */
1683 reloc32
= *reloc_entry
;
1684 if (bfd_big_endian (abfd
))
1685 reloc32
.address
+= 4;
1686 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1687 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1688 output_bfd
, error_message
);
1690 /* Sign extend into the upper 32 bits. */
1691 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1692 if ((val
& 0x80000000) != 0)
1696 addr
= reloc_entry
->address
;
1697 if (bfd_little_endian (abfd
))
1699 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1704 /* Handle a mips16 jump. */
1706 static bfd_reloc_status_type
1707 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1708 output_bfd
, error_message
)
1709 bfd
*abfd ATTRIBUTE_UNUSED
;
1710 arelent
*reloc_entry
;
1712 PTR data ATTRIBUTE_UNUSED
;
1713 asection
*input_section
;
1715 char **error_message ATTRIBUTE_UNUSED
;
1717 if (output_bfd
!= (bfd
*) NULL
1718 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1719 && reloc_entry
->addend
== 0)
1721 reloc_entry
->address
+= input_section
->output_offset
;
1722 return bfd_reloc_ok
;
1727 static boolean warned
;
1730 (*_bfd_error_handler
)
1731 (_("Linking mips16 objects into %s format is not supported"),
1732 bfd_get_target (input_section
->output_section
->owner
));
1736 return bfd_reloc_undefined
;
1739 /* Handle a mips16 GP relative reloc. */
1741 static bfd_reloc_status_type
1742 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1743 output_bfd
, error_message
)
1745 arelent
*reloc_entry
;
1748 asection
*input_section
;
1750 char **error_message
;
1752 boolean relocateable
;
1753 bfd_reloc_status_type ret
;
1755 unsigned short extend
, insn
;
1756 unsigned long final
;
1758 /* If we're relocating, and this is an external symbol with no
1759 addend, we don't want to change anything. We will only have an
1760 addend if this is a newly created reloc, not read from an ELF
1762 if (output_bfd
!= NULL
1763 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1764 && reloc_entry
->addend
== 0)
1766 reloc_entry
->address
+= input_section
->output_offset
;
1767 return bfd_reloc_ok
;
1770 if (output_bfd
!= NULL
)
1771 relocateable
= true;
1774 relocateable
= false;
1775 output_bfd
= symbol
->section
->output_section
->owner
;
1778 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1780 if (ret
!= bfd_reloc_ok
)
1783 if (reloc_entry
->address
> input_section
->_cooked_size
)
1784 return bfd_reloc_outofrange
;
1786 /* Pick up the mips16 extend instruction and the real instruction. */
1787 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1788 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1790 /* Stuff the current addend back as a 32 bit value, do the usual
1791 relocation, and then clean up. */
1793 (((extend
& 0x1f) << 11)
1796 (bfd_byte
*) data
+ reloc_entry
->address
);
1798 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1799 relocateable
, data
, gp
);
1801 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1804 | ((final
>> 11) & 0x1f)
1806 (bfd_byte
*) data
+ reloc_entry
->address
);
1810 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1815 /* Return the ISA for a MIPS e_flags value. */
1818 elf_mips_isa (flags
)
1821 switch (flags
& EF_MIPS_ARCH
)
1833 case E_MIPS_ARCH_32
:
1835 case E_MIPS_ARCH_64
:
1841 /* Return the MACH for a MIPS e_flags value. */
1844 elf_mips_mach (flags
)
1847 switch (flags
& EF_MIPS_MACH
)
1849 case E_MIPS_MACH_3900
:
1850 return bfd_mach_mips3900
;
1852 case E_MIPS_MACH_4010
:
1853 return bfd_mach_mips4010
;
1855 case E_MIPS_MACH_4100
:
1856 return bfd_mach_mips4100
;
1858 case E_MIPS_MACH_4111
:
1859 return bfd_mach_mips4111
;
1861 case E_MIPS_MACH_4650
:
1862 return bfd_mach_mips4650
;
1864 case E_MIPS_MACH_MIPS32_4K
:
1865 return bfd_mach_mips32_4k
;
1867 case E_MIPS_MACH_SB1
:
1868 return bfd_mach_mips_sb1
;
1871 switch (flags
& EF_MIPS_ARCH
)
1875 return bfd_mach_mips3000
;
1879 return bfd_mach_mips6000
;
1883 return bfd_mach_mips4000
;
1887 return bfd_mach_mips8000
;
1891 return bfd_mach_mips5
;
1894 case E_MIPS_ARCH_32
:
1895 return bfd_mach_mips32
;
1898 case E_MIPS_ARCH_64
:
1899 return bfd_mach_mips64
;
1907 /* Return printable name for ABI. */
1909 static INLINE
char *
1910 elf_mips_abi_name (abfd
)
1915 if (ABI_N32_P (abfd
))
1917 else if (ABI_64_P (abfd
))
1920 flags
= elf_elfheader (abfd
)->e_flags
;
1921 switch (flags
& EF_MIPS_ABI
)
1925 case E_MIPS_ABI_O32
:
1927 case E_MIPS_ABI_O64
:
1929 case E_MIPS_ABI_EABI32
:
1931 case E_MIPS_ABI_EABI64
:
1934 return "unknown abi";
1938 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1940 struct elf_reloc_map
{
1941 bfd_reloc_code_real_type bfd_reloc_val
;
1942 enum elf_mips_reloc_type elf_reloc_val
;
1945 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1947 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1948 { BFD_RELOC_16
, R_MIPS_16
},
1949 { BFD_RELOC_32
, R_MIPS_32
},
1950 { BFD_RELOC_64
, R_MIPS_64
},
1951 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1952 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1953 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1954 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1955 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1956 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1957 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1958 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1959 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1960 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1961 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1962 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1963 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
},
1964 { BFD_RELOC_MIPS_SUB
, R_MIPS_SUB
},
1965 { BFD_RELOC_MIPS_GOT_PAGE
, R_MIPS_GOT_PAGE
},
1966 { BFD_RELOC_MIPS_GOT_OFST
, R_MIPS_GOT_OFST
},
1967 { BFD_RELOC_MIPS_GOT_DISP
, R_MIPS_GOT_DISP
}
1970 /* Given a BFD reloc type, return a howto structure. */
1972 static reloc_howto_type
*
1973 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1975 bfd_reloc_code_real_type code
;
1979 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1981 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1982 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1988 bfd_set_error (bfd_error_bad_value
);
1991 case BFD_RELOC_CTOR
:
1992 /* We need to handle BFD_RELOC_CTOR specially.
1993 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1994 size of addresses on this architecture. */
1995 if (bfd_arch_bits_per_address (abfd
) == 32)
1996 return &elf_mips_howto_table
[(int) R_MIPS_32
];
1998 return &elf_mips_ctor64_howto
;
2000 case BFD_RELOC_MIPS16_JMP
:
2001 return &elf_mips16_jump_howto
;
2002 case BFD_RELOC_MIPS16_GPREL
:
2003 return &elf_mips16_gprel_howto
;
2004 case BFD_RELOC_VTABLE_INHERIT
:
2005 return &elf_mips_gnu_vtinherit_howto
;
2006 case BFD_RELOC_VTABLE_ENTRY
:
2007 return &elf_mips_gnu_vtentry_howto
;
2008 case BFD_RELOC_PCREL_HI16_S
:
2009 return &elf_mips_gnu_rel_hi16
;
2010 case BFD_RELOC_PCREL_LO16
:
2011 return &elf_mips_gnu_rel_lo16
;
2012 case BFD_RELOC_16_PCREL_S2
:
2013 return &elf_mips_gnu_rel16_s2
;
2014 case BFD_RELOC_64_PCREL
:
2015 return &elf_mips_gnu_pcrel64
;
2016 case BFD_RELOC_32_PCREL
:
2017 return &elf_mips_gnu_pcrel32
;
2021 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
2023 static reloc_howto_type
*
2024 mips_rtype_to_howto (r_type
)
2025 unsigned int r_type
;
2030 return &elf_mips16_jump_howto
;
2032 case R_MIPS16_GPREL
:
2033 return &elf_mips16_gprel_howto
;
2035 case R_MIPS_GNU_VTINHERIT
:
2036 return &elf_mips_gnu_vtinherit_howto
;
2038 case R_MIPS_GNU_VTENTRY
:
2039 return &elf_mips_gnu_vtentry_howto
;
2041 case R_MIPS_GNU_REL_HI16
:
2042 return &elf_mips_gnu_rel_hi16
;
2044 case R_MIPS_GNU_REL_LO16
:
2045 return &elf_mips_gnu_rel_lo16
;
2047 case R_MIPS_GNU_REL16_S2
:
2048 return &elf_mips_gnu_rel16_s2
;
2051 return &elf_mips_gnu_pcrel64
;
2054 return &elf_mips_gnu_pcrel32
;
2058 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
2059 return &elf_mips_howto_table
[r_type
];
2064 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
2067 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
2070 Elf32_Internal_Rel
*dst
;
2072 unsigned int r_type
;
2074 r_type
= ELF32_R_TYPE (dst
->r_info
);
2075 cache_ptr
->howto
= mips_rtype_to_howto (r_type
);
2077 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
2078 value for the object file. We get the addend now, rather than
2079 when we do the relocation, because the symbol manipulations done
2080 by the linker may cause us to lose track of the input BFD. */
2081 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
2082 && (r_type
== (unsigned int) R_MIPS_GPREL16
2083 || r_type
== (unsigned int) R_MIPS_LITERAL
))
2084 cache_ptr
->addend
= elf_gp (abfd
);
2087 /* Given a MIPS Elf32_Internal_Rela, fill in an arelent structure. */
2090 mips_info_to_howto_rela (abfd
, cache_ptr
, dst
)
2093 Elf32_Internal_Rela
*dst
;
2095 /* Since an Elf32_Internal_Rel is an initial prefix of an
2096 Elf32_Internal_Rela, we can just use mips_info_to_howto_rel
2098 mips_info_to_howto_rel (abfd
, cache_ptr
, (Elf32_Internal_Rel
*) dst
);
2100 /* If we ever need to do any extra processing with dst->r_addend
2101 (the field omitted in an Elf32_Internal_Rel) we can do it here. */
2104 /* A .reginfo section holds a single Elf32_RegInfo structure. These
2105 routines swap this structure in and out. They are used outside of
2106 BFD, so they are globally visible. */
2109 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
2111 const Elf32_External_RegInfo
*ex
;
2114 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
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_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
2123 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
2125 const Elf32_RegInfo
*in
;
2126 Elf32_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_cprmask
[0],
2131 (bfd_byte
*) ex
->ri_cprmask
[0]);
2132 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
2133 (bfd_byte
*) ex
->ri_cprmask
[1]);
2134 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
2135 (bfd_byte
*) ex
->ri_cprmask
[2]);
2136 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
2137 (bfd_byte
*) ex
->ri_cprmask
[3]);
2138 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
2139 (bfd_byte
*) ex
->ri_gp_value
);
2142 /* In the 64 bit ABI, the .MIPS.options section holds register
2143 information in an Elf64_Reginfo structure. These routines swap
2144 them in and out. They are globally visible because they are used
2145 outside of BFD. These routines are here so that gas can call them
2146 without worrying about whether the 64 bit ABI has been included. */
2149 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
2151 const Elf64_External_RegInfo
*ex
;
2152 Elf64_Internal_RegInfo
*in
;
2154 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
2155 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
2156 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
2157 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
2158 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
2159 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
2160 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
2164 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
2166 const Elf64_Internal_RegInfo
*in
;
2167 Elf64_External_RegInfo
*ex
;
2169 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
2170 (bfd_byte
*) ex
->ri_gprmask
);
2171 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
2172 (bfd_byte
*) ex
->ri_pad
);
2173 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
2174 (bfd_byte
*) ex
->ri_cprmask
[0]);
2175 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
2176 (bfd_byte
*) ex
->ri_cprmask
[1]);
2177 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
2178 (bfd_byte
*) ex
->ri_cprmask
[2]);
2179 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
2180 (bfd_byte
*) ex
->ri_cprmask
[3]);
2181 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
2182 (bfd_byte
*) ex
->ri_gp_value
);
2185 /* Swap an entry in a .gptab section. Note that these routines rely
2186 on the equivalence of the two elements of the union. */
2189 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
2191 const Elf32_External_gptab
*ex
;
2194 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
2195 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
2199 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
2201 const Elf32_gptab
*in
;
2202 Elf32_External_gptab
*ex
;
2204 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
2205 ex
->gt_entry
.gt_g_value
);
2206 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
2207 ex
->gt_entry
.gt_bytes
);
2211 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
2213 const Elf32_compact_rel
*in
;
2214 Elf32_External_compact_rel
*ex
;
2216 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
2217 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
2218 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
2219 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
2220 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
2221 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
2225 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
2227 const Elf32_crinfo
*in
;
2228 Elf32_External_crinfo
*ex
;
2232 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
2233 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
2234 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
2235 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
2236 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
2237 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
2238 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
2241 /* Swap in an options header. */
2244 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
2246 const Elf_External_Options
*ex
;
2247 Elf_Internal_Options
*in
;
2249 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
2250 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
2251 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
2252 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
2255 /* Swap out an options header. */
2258 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
2260 const Elf_Internal_Options
*in
;
2261 Elf_External_Options
*ex
;
2263 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
2264 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
2265 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
2266 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
2269 /* Swap in an MSYM entry. */
2272 bfd_mips_elf_swap_msym_in (abfd
, ex
, in
)
2274 const Elf32_External_Msym
*ex
;
2275 Elf32_Internal_Msym
*in
;
2277 in
->ms_hash_value
= bfd_h_get_32 (abfd
, ex
->ms_hash_value
);
2278 in
->ms_info
= bfd_h_get_32 (abfd
, ex
->ms_info
);
2281 /* Swap out an MSYM entry. */
2284 bfd_mips_elf_swap_msym_out (abfd
, in
, ex
)
2286 const Elf32_Internal_Msym
*in
;
2287 Elf32_External_Msym
*ex
;
2289 bfd_h_put_32 (abfd
, in
->ms_hash_value
, ex
->ms_hash_value
);
2290 bfd_h_put_32 (abfd
, in
->ms_info
, ex
->ms_info
);
2293 /* Determine whether a symbol is global for the purposes of splitting
2294 the symbol table into global symbols and local symbols. At least
2295 on Irix 5, this split must be between section symbols and all other
2296 symbols. On most ELF targets the split is between static symbols
2297 and externally visible symbols. */
2300 mips_elf_sym_is_global (abfd
, sym
)
2301 bfd
*abfd ATTRIBUTE_UNUSED
;
2304 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
2307 /* Set the right machine number for a MIPS ELF file. This is used for
2308 both the 32-bit and the 64-bit ABI. */
2311 _bfd_mips_elf_object_p (abfd
)
2314 /* Irix 5 and 6 is broken. Object file symbol tables are not always
2315 sorted correctly such that local symbols precede global symbols,
2316 and the sh_info field in the symbol table is not always right. */
2317 elf_bad_symtab (abfd
) = true;
2319 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
,
2320 elf_mips_mach (elf_elfheader (abfd
)->e_flags
));
2324 /* The final processing done just before writing out a MIPS ELF object
2325 file. This gets the MIPS architecture right based on the machine
2326 number. This is used by both the 32-bit and the 64-bit ABI. */
2329 _bfd_mips_elf_final_write_processing (abfd
, linker
)
2331 boolean linker ATTRIBUTE_UNUSED
;
2335 Elf_Internal_Shdr
**hdrpp
;
2339 switch (bfd_get_mach (abfd
))
2342 case bfd_mach_mips3000
:
2343 val
= E_MIPS_ARCH_1
;
2346 case bfd_mach_mips3900
:
2347 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
2350 case bfd_mach_mips6000
:
2351 val
= E_MIPS_ARCH_2
;
2354 case bfd_mach_mips4000
:
2355 case bfd_mach_mips4300
:
2356 val
= E_MIPS_ARCH_3
;
2359 case bfd_mach_mips4010
:
2360 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
2363 case bfd_mach_mips4100
:
2364 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
2367 case bfd_mach_mips4111
:
2368 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
2371 case bfd_mach_mips4650
:
2372 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
2375 case bfd_mach_mips8000
:
2376 val
= E_MIPS_ARCH_4
;
2379 case bfd_mach_mips32
:
2380 val
= E_MIPS_ARCH_32
;
2383 case bfd_mach_mips32_4k
:
2384 val
= E_MIPS_ARCH_32
| E_MIPS_MACH_MIPS32_4K
;
2387 case bfd_mach_mips5
:
2388 val
= E_MIPS_ARCH_5
;
2391 case bfd_mach_mips64
:
2392 val
= E_MIPS_ARCH_64
;
2395 case bfd_mach_mips_sb1
:
2396 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
2400 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
2401 elf_elfheader (abfd
)->e_flags
|= val
;
2403 /* Set the sh_info field for .gptab sections and other appropriate
2404 info for each special section. */
2405 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
2406 i
< elf_elfheader (abfd
)->e_shnum
;
2409 switch ((*hdrpp
)->sh_type
)
2412 case SHT_MIPS_LIBLIST
:
2413 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
2415 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2418 case SHT_MIPS_GPTAB
:
2419 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2420 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2421 BFD_ASSERT (name
!= NULL
2422 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
2423 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
2424 BFD_ASSERT (sec
!= NULL
);
2425 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2428 case SHT_MIPS_CONTENT
:
2429 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2430 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2431 BFD_ASSERT (name
!= NULL
2432 && strncmp (name
, ".MIPS.content",
2433 sizeof ".MIPS.content" - 1) == 0);
2434 sec
= bfd_get_section_by_name (abfd
,
2435 name
+ sizeof ".MIPS.content" - 1);
2436 BFD_ASSERT (sec
!= NULL
);
2437 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2440 case SHT_MIPS_SYMBOL_LIB
:
2441 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
2443 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2444 sec
= bfd_get_section_by_name (abfd
, ".liblist");
2446 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2449 case SHT_MIPS_EVENTS
:
2450 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2451 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2452 BFD_ASSERT (name
!= NULL
);
2453 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
2454 sec
= bfd_get_section_by_name (abfd
,
2455 name
+ sizeof ".MIPS.events" - 1);
2458 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
2459 sizeof ".MIPS.post_rel" - 1) == 0);
2460 sec
= bfd_get_section_by_name (abfd
,
2462 + sizeof ".MIPS.post_rel" - 1));
2464 BFD_ASSERT (sec
!= NULL
);
2465 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2472 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
2475 _bfd_mips_elf_set_private_flags (abfd
, flags
)
2479 BFD_ASSERT (!elf_flags_init (abfd
)
2480 || elf_elfheader (abfd
)->e_flags
== flags
);
2482 elf_elfheader (abfd
)->e_flags
= flags
;
2483 elf_flags_init (abfd
) = true;
2487 /* Copy backend specific data from one object module to another */
2490 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
2494 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2495 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2498 BFD_ASSERT (!elf_flags_init (obfd
)
2499 || (elf_elfheader (obfd
)->e_flags
2500 == elf_elfheader (ibfd
)->e_flags
));
2502 elf_gp (obfd
) = elf_gp (ibfd
);
2503 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
2504 elf_flags_init (obfd
) = true;
2508 /* Merge backend specific data from an object file to the output
2509 object file when linking. */
2512 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
2519 boolean null_input_bfd
= true;
2522 /* Check if we have the same endianess */
2523 if (_bfd_generic_verify_endian_match (ibfd
, obfd
) == false)
2526 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2527 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2530 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2531 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
2532 old_flags
= elf_elfheader (obfd
)->e_flags
;
2534 if (! elf_flags_init (obfd
))
2536 elf_flags_init (obfd
) = true;
2537 elf_elfheader (obfd
)->e_flags
= new_flags
;
2538 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
2539 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
2541 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2542 && bfd_get_arch_info (obfd
)->the_default
)
2544 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
2545 bfd_get_mach (ibfd
)))
2552 /* Check flag compatibility. */
2554 new_flags
&= ~EF_MIPS_NOREORDER
;
2555 old_flags
&= ~EF_MIPS_NOREORDER
;
2557 if (new_flags
== old_flags
)
2560 /* Check to see if the input BFD actually contains any sections.
2561 If not, its flags may not have been initialised either, but it cannot
2562 actually cause any incompatibility. */
2563 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2565 /* Ignore synthetic sections and empty .text, .data and .bss sections
2566 which are automatically generated by gas. */
2567 if (strcmp (sec
->name
, ".reginfo")
2568 && strcmp (sec
->name
, ".mdebug")
2569 && ((!strcmp (sec
->name
, ".text")
2570 || !strcmp (sec
->name
, ".data")
2571 || !strcmp (sec
->name
, ".bss"))
2572 && sec
->_raw_size
!= 0))
2574 null_input_bfd
= false;
2583 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
2585 new_flags
&= ~EF_MIPS_PIC
;
2586 old_flags
&= ~EF_MIPS_PIC
;
2587 (*_bfd_error_handler
)
2588 (_("%s: linking PIC files with non-PIC files"),
2589 bfd_get_filename (ibfd
));
2593 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
2595 new_flags
&= ~EF_MIPS_CPIC
;
2596 old_flags
&= ~EF_MIPS_CPIC
;
2597 (*_bfd_error_handler
)
2598 (_("%s: linking abicalls files with non-abicalls files"),
2599 bfd_get_filename (ibfd
));
2603 /* Compare the ISA's. */
2604 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
2605 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
2607 int new_mach
= new_flags
& EF_MIPS_MACH
;
2608 int old_mach
= old_flags
& EF_MIPS_MACH
;
2609 int new_isa
= elf_mips_isa (new_flags
);
2610 int old_isa
= elf_mips_isa (old_flags
);
2612 /* If either has no machine specified, just compare the general isa's.
2613 Some combinations of machines are ok, if the isa's match. */
2616 || new_mach
== old_mach
2619 /* Don't warn about mixing code using 32-bit ISAs, or mixing code
2620 using 64-bit ISAs. They will normally use the same data sizes
2621 and calling conventions. */
2623 if (( (new_isa
== 1 || new_isa
== 2 || new_isa
== 32)
2624 ^ (old_isa
== 1 || old_isa
== 2 || old_isa
== 32)) != 0)
2626 (*_bfd_error_handler
)
2627 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
2628 bfd_get_filename (ibfd
), new_isa
, old_isa
);
2635 (*_bfd_error_handler
)
2636 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
2637 bfd_get_filename (ibfd
),
2638 elf_mips_mach (new_flags
),
2639 elf_mips_mach (old_flags
));
2643 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
2644 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
2647 /* Compare ABI's. The 64-bit ABI does not use EF_MIPS_ABI. But, it
2648 does set EI_CLASS differently from any 32-bit ABI. */
2649 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
2650 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
2651 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
2653 /* Only error if both are set (to different values). */
2654 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
2655 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
2656 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
2658 (*_bfd_error_handler
)
2659 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
2660 bfd_get_filename (ibfd
),
2661 elf_mips_abi_name (ibfd
),
2662 elf_mips_abi_name (obfd
));
2665 new_flags
&= ~EF_MIPS_ABI
;
2666 old_flags
&= ~EF_MIPS_ABI
;
2669 /* Warn about any other mismatches */
2670 if (new_flags
!= old_flags
)
2672 (*_bfd_error_handler
)
2673 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2674 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
2675 (unsigned long) old_flags
);
2681 bfd_set_error (bfd_error_bad_value
);
2689 _bfd_mips_elf_print_private_bfd_data (abfd
, ptr
)
2693 FILE *file
= (FILE *) ptr
;
2695 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
2697 /* Print normal ELF private data. */
2698 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
2700 /* xgettext:c-format */
2701 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
2703 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
2704 fprintf (file
, _(" [abi=O32]"));
2705 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
2706 fprintf (file
, _(" [abi=O64]"));
2707 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
2708 fprintf (file
, _(" [abi=EABI32]"));
2709 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
2710 fprintf (file
, _(" [abi=EABI64]"));
2711 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
2712 fprintf (file
, _(" [abi unknown]"));
2713 else if (ABI_N32_P (abfd
))
2714 fprintf (file
, _(" [abi=N32]"));
2715 else if (ABI_64_P (abfd
))
2716 fprintf (file
, _(" [abi=64]"));
2718 fprintf (file
, _(" [no abi set]"));
2720 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
2721 fprintf (file
, _(" [mips1]"));
2722 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
2723 fprintf (file
, _(" [mips2]"));
2724 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
2725 fprintf (file
, _(" [mips3]"));
2726 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
2727 fprintf (file
, _(" [mips4]"));
2728 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
2729 fprintf (file
, _ (" [mips5]"));
2730 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
2731 fprintf (file
, _ (" [mips32]"));
2732 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
2733 fprintf (file
, _ (" [mips64]"));
2735 fprintf (file
, _(" [unknown ISA]"));
2737 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
2738 fprintf (file
, _(" [32bitmode]"));
2740 fprintf (file
, _(" [not 32bitmode]"));
2747 /* Handle a MIPS specific section when reading an object file. This
2748 is called when elfcode.h finds a section with an unknown type.
2749 This routine supports both the 32-bit and 64-bit ELF ABI.
2751 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2755 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
2757 Elf_Internal_Shdr
*hdr
;
2762 /* There ought to be a place to keep ELF backend specific flags, but
2763 at the moment there isn't one. We just keep track of the
2764 sections by their name, instead. Fortunately, the ABI gives
2765 suggested names for all the MIPS specific sections, so we will
2766 probably get away with this. */
2767 switch (hdr
->sh_type
)
2769 case SHT_MIPS_LIBLIST
:
2770 if (strcmp (name
, ".liblist") != 0)
2774 if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) != 0)
2777 case SHT_MIPS_CONFLICT
:
2778 if (strcmp (name
, ".conflict") != 0)
2781 case SHT_MIPS_GPTAB
:
2782 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
2785 case SHT_MIPS_UCODE
:
2786 if (strcmp (name
, ".ucode") != 0)
2789 case SHT_MIPS_DEBUG
:
2790 if (strcmp (name
, ".mdebug") != 0)
2792 flags
= SEC_DEBUGGING
;
2794 case SHT_MIPS_REGINFO
:
2795 if (strcmp (name
, ".reginfo") != 0
2796 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
2798 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
2800 case SHT_MIPS_IFACE
:
2801 if (strcmp (name
, ".MIPS.interfaces") != 0)
2804 case SHT_MIPS_CONTENT
:
2805 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2808 case SHT_MIPS_OPTIONS
:
2809 if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) != 0)
2812 case SHT_MIPS_DWARF
:
2813 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2816 case SHT_MIPS_SYMBOL_LIB
:
2817 if (strcmp (name
, ".MIPS.symlib") != 0)
2820 case SHT_MIPS_EVENTS
:
2821 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2822 && strncmp (name
, ".MIPS.post_rel",
2823 sizeof ".MIPS.post_rel" - 1) != 0)
2830 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2835 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
2836 (bfd_get_section_flags (abfd
,
2842 /* FIXME: We should record sh_info for a .gptab section. */
2844 /* For a .reginfo section, set the gp value in the tdata information
2845 from the contents of this section. We need the gp value while
2846 processing relocs, so we just get it now. The .reginfo section
2847 is not used in the 64-bit MIPS ELF ABI. */
2848 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2850 Elf32_External_RegInfo ext
;
2853 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
2854 (file_ptr
) 0, sizeof ext
))
2856 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
2857 elf_gp (abfd
) = s
.ri_gp_value
;
2860 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2861 set the gp value based on what we find. We may see both
2862 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2863 they should agree. */
2864 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
2866 bfd_byte
*contents
, *l
, *lend
;
2868 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
2869 if (contents
== NULL
)
2871 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
2872 (file_ptr
) 0, hdr
->sh_size
))
2878 lend
= contents
+ hdr
->sh_size
;
2879 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2881 Elf_Internal_Options intopt
;
2883 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2885 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
2887 Elf64_Internal_RegInfo intreg
;
2889 bfd_mips_elf64_swap_reginfo_in
2891 ((Elf64_External_RegInfo
*)
2892 (l
+ sizeof (Elf_External_Options
))),
2894 elf_gp (abfd
) = intreg
.ri_gp_value
;
2896 else if (intopt
.kind
== ODK_REGINFO
)
2898 Elf32_RegInfo intreg
;
2900 bfd_mips_elf32_swap_reginfo_in
2902 ((Elf32_External_RegInfo
*)
2903 (l
+ sizeof (Elf_External_Options
))),
2905 elf_gp (abfd
) = intreg
.ri_gp_value
;
2915 /* Set the correct type for a MIPS ELF section. We do this by the
2916 section name, which is a hack, but ought to work. This routine is
2917 used by both the 32-bit and the 64-bit ABI. */
2920 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
2922 Elf32_Internal_Shdr
*hdr
;
2925 register const char *name
;
2927 name
= bfd_get_section_name (abfd
, sec
);
2929 if (strcmp (name
, ".liblist") == 0)
2931 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
2932 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
2933 /* The sh_link field is set in final_write_processing. */
2935 else if (strcmp (name
, ".conflict") == 0)
2936 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
2937 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2939 hdr
->sh_type
= SHT_MIPS_GPTAB
;
2940 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
2941 /* The sh_info field is set in final_write_processing. */
2943 else if (strcmp (name
, ".ucode") == 0)
2944 hdr
->sh_type
= SHT_MIPS_UCODE
;
2945 else if (strcmp (name
, ".mdebug") == 0)
2947 hdr
->sh_type
= SHT_MIPS_DEBUG
;
2948 /* In a shared object on Irix 5.3, the .mdebug section has an
2949 entsize of 0. FIXME: Does this matter? */
2950 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2951 hdr
->sh_entsize
= 0;
2953 hdr
->sh_entsize
= 1;
2955 else if (strcmp (name
, ".reginfo") == 0)
2957 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2958 /* In a shared object on Irix 5.3, the .reginfo section has an
2959 entsize of 0x18. FIXME: Does this matter? */
2960 if (SGI_COMPAT (abfd
))
2962 if ((abfd
->flags
& DYNAMIC
) != 0)
2963 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2965 hdr
->sh_entsize
= 1;
2968 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2970 else if (SGI_COMPAT (abfd
)
2971 && (strcmp (name
, ".hash") == 0
2972 || strcmp (name
, ".dynamic") == 0
2973 || strcmp (name
, ".dynstr") == 0))
2975 if (SGI_COMPAT (abfd
))
2976 hdr
->sh_entsize
= 0;
2978 /* This isn't how the Irix 6 linker behaves. */
2979 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2982 else if (strcmp (name
, ".got") == 0
2983 || strcmp (name
, MIPS_ELF_SRDATA_SECTION_NAME (abfd
)) == 0
2984 || strcmp (name
, ".sdata") == 0
2985 || strcmp (name
, ".sbss") == 0
2986 || strcmp (name
, ".lit4") == 0
2987 || strcmp (name
, ".lit8") == 0)
2988 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2989 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2991 hdr
->sh_type
= SHT_MIPS_IFACE
;
2992 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2994 else if (strncmp (name
, ".MIPS.content", strlen (".MIPS.content")) == 0)
2996 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2997 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2998 /* The sh_info field is set in final_write_processing. */
3000 else if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
3002 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
3003 hdr
->sh_entsize
= 1;
3004 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3006 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
3007 hdr
->sh_type
= SHT_MIPS_DWARF
;
3008 else if (strcmp (name
, ".MIPS.symlib") == 0)
3010 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
3011 /* The sh_link and sh_info fields are set in
3012 final_write_processing. */
3014 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
3015 || strncmp (name
, ".MIPS.post_rel",
3016 sizeof ".MIPS.post_rel" - 1) == 0)
3018 hdr
->sh_type
= SHT_MIPS_EVENTS
;
3019 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3020 /* The sh_link field is set in final_write_processing. */
3022 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) == 0)
3024 hdr
->sh_type
= SHT_MIPS_MSYM
;
3025 hdr
->sh_flags
|= SHF_ALLOC
;
3026 hdr
->sh_entsize
= 8;
3029 /* The generic elf_fake_sections will set up REL_HDR using the
3030 default kind of relocations. But, we may actually need both
3031 kinds of relocations, so we set up the second header here. */
3032 if ((sec
->flags
& SEC_RELOC
) != 0)
3034 struct bfd_elf_section_data
*esd
;
3036 esd
= elf_section_data (sec
);
3037 BFD_ASSERT (esd
->rel_hdr2
== NULL
);
3039 = (Elf_Internal_Shdr
*) bfd_zalloc (abfd
, sizeof (Elf_Internal_Shdr
));
3042 _bfd_elf_init_reloc_shdr (abfd
, esd
->rel_hdr2
, sec
,
3043 !elf_section_data (sec
)->use_rela_p
);
3049 /* Given a BFD section, try to locate the corresponding ELF section
3050 index. This is used by both the 32-bit and the 64-bit ABI.
3051 Actually, it's not clear to me that the 64-bit ABI supports these,
3052 but for non-PIC objects we will certainly want support for at least
3053 the .scommon section. */
3056 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
3057 bfd
*abfd ATTRIBUTE_UNUSED
;
3058 Elf32_Internal_Shdr
*hdr ATTRIBUTE_UNUSED
;
3062 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
3064 *retval
= SHN_MIPS_SCOMMON
;
3067 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
3069 *retval
= SHN_MIPS_ACOMMON
;
3075 /* When are writing out the .options or .MIPS.options section,
3076 remember the bytes we are writing out, so that we can install the
3077 GP value in the section_processing routine. */
3080 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
3085 bfd_size_type count
;
3087 if (strcmp (section
->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
3091 if (elf_section_data (section
) == NULL
)
3093 section
->used_by_bfd
=
3094 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
3095 if (elf_section_data (section
) == NULL
)
3098 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
3103 if (section
->_cooked_size
!= 0)
3104 size
= section
->_cooked_size
;
3106 size
= section
->_raw_size
;
3107 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
3110 elf_section_data (section
)->tdata
= (PTR
) c
;
3113 memcpy (c
+ offset
, location
, count
);
3116 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
3120 /* Work over a section just before writing it out. This routine is
3121 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
3122 sections that need the SHF_MIPS_GPREL flag by name; there has to be
3126 _bfd_mips_elf_section_processing (abfd
, hdr
)
3128 Elf_Internal_Shdr
*hdr
;
3130 if (hdr
->sh_type
== SHT_MIPS_REGINFO
3131 && hdr
->sh_size
> 0)
3135 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
3136 BFD_ASSERT (hdr
->contents
== NULL
);
3139 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
3142 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
3143 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
3147 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
3148 && hdr
->bfd_section
!= NULL
3149 && elf_section_data (hdr
->bfd_section
) != NULL
3150 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
3152 bfd_byte
*contents
, *l
, *lend
;
3154 /* We stored the section contents in the elf_section_data tdata
3155 field in the set_section_contents routine. We save the
3156 section contents so that we don't have to read them again.
3157 At this point we know that elf_gp is set, so we can look
3158 through the section contents to see if there is an
3159 ODK_REGINFO structure. */
3161 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
3163 lend
= contents
+ hdr
->sh_size
;
3164 while (l
+ sizeof (Elf_External_Options
) <= lend
)
3166 Elf_Internal_Options intopt
;
3168 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
3170 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
3177 + sizeof (Elf_External_Options
)
3178 + (sizeof (Elf64_External_RegInfo
) - 8)),
3181 bfd_h_put_64 (abfd
, elf_gp (abfd
), buf
);
3182 if (bfd_write (buf
, 1, 8, abfd
) != 8)
3185 else if (intopt
.kind
== ODK_REGINFO
)
3192 + sizeof (Elf_External_Options
)
3193 + (sizeof (Elf32_External_RegInfo
) - 4)),
3196 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
3197 if (bfd_write (buf
, 1, 4, abfd
) != 4)
3204 if (hdr
->bfd_section
!= NULL
)
3206 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
3208 if (strcmp (name
, ".sdata") == 0
3209 || strcmp (name
, ".lit8") == 0
3210 || strcmp (name
, ".lit4") == 0)
3212 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3213 hdr
->sh_type
= SHT_PROGBITS
;
3215 else if (strcmp (name
, ".sbss") == 0)
3217 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3218 hdr
->sh_type
= SHT_NOBITS
;
3220 else if (strcmp (name
, MIPS_ELF_SRDATA_SECTION_NAME (abfd
)) == 0)
3222 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
3223 hdr
->sh_type
= SHT_PROGBITS
;
3225 else if (strcmp (name
, ".compact_rel") == 0)
3228 hdr
->sh_type
= SHT_PROGBITS
;
3230 else if (strcmp (name
, ".rtproc") == 0)
3232 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
3234 unsigned int adjust
;
3236 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
3238 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
3246 /* MIPS ELF uses two common sections. One is the usual one, and the
3247 other is for small objects. All the small objects are kept
3248 together, and then referenced via the gp pointer, which yields
3249 faster assembler code. This is what we use for the small common
3250 section. This approach is copied from ecoff.c. */
3251 static asection mips_elf_scom_section
;
3252 static asymbol mips_elf_scom_symbol
;
3253 static asymbol
*mips_elf_scom_symbol_ptr
;
3255 /* MIPS ELF also uses an acommon section, which represents an
3256 allocated common symbol which may be overridden by a
3257 definition in a shared library. */
3258 static asection mips_elf_acom_section
;
3259 static asymbol mips_elf_acom_symbol
;
3260 static asymbol
*mips_elf_acom_symbol_ptr
;
3262 /* Handle the special MIPS section numbers that a symbol may use.
3263 This is used for both the 32-bit and the 64-bit ABI. */
3266 _bfd_mips_elf_symbol_processing (abfd
, asym
)
3270 elf_symbol_type
*elfsym
;
3272 elfsym
= (elf_symbol_type
*) asym
;
3273 switch (elfsym
->internal_elf_sym
.st_shndx
)
3275 case SHN_MIPS_ACOMMON
:
3276 /* This section is used in a dynamically linked executable file.
3277 It is an allocated common section. The dynamic linker can
3278 either resolve these symbols to something in a shared
3279 library, or it can just leave them here. For our purposes,
3280 we can consider these symbols to be in a new section. */
3281 if (mips_elf_acom_section
.name
== NULL
)
3283 /* Initialize the acommon section. */
3284 mips_elf_acom_section
.name
= ".acommon";
3285 mips_elf_acom_section
.flags
= SEC_ALLOC
;
3286 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
3287 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
3288 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
3289 mips_elf_acom_symbol
.name
= ".acommon";
3290 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
3291 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
3292 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
3294 asym
->section
= &mips_elf_acom_section
;
3298 /* Common symbols less than the GP size are automatically
3299 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
3300 if (asym
->value
> elf_gp_size (abfd
)
3301 || IRIX_COMPAT (abfd
) == ict_irix6
)
3304 case SHN_MIPS_SCOMMON
:
3305 if (mips_elf_scom_section
.name
== NULL
)
3307 /* Initialize the small common section. */
3308 mips_elf_scom_section
.name
= ".scommon";
3309 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
3310 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
3311 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
3312 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
3313 mips_elf_scom_symbol
.name
= ".scommon";
3314 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
3315 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
3316 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
3318 asym
->section
= &mips_elf_scom_section
;
3319 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
3322 case SHN_MIPS_SUNDEFINED
:
3323 asym
->section
= bfd_und_section_ptr
;
3326 #if 0 /* for SGI_COMPAT */
3328 asym
->section
= mips_elf_text_section_ptr
;
3332 asym
->section
= mips_elf_data_section_ptr
;
3338 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
3342 _bfd_mips_elf_additional_program_headers (abfd
)
3348 /* See if we need a PT_MIPS_REGINFO segment. */
3349 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3350 if (s
&& (s
->flags
& SEC_LOAD
))
3353 /* See if we need a PT_MIPS_OPTIONS segment. */
3354 if (IRIX_COMPAT (abfd
) == ict_irix6
3355 && bfd_get_section_by_name (abfd
,
3356 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
3359 /* See if we need a PT_MIPS_RTPROC segment. */
3360 if (IRIX_COMPAT (abfd
) == ict_irix5
3361 && bfd_get_section_by_name (abfd
, ".dynamic")
3362 && bfd_get_section_by_name (abfd
, ".mdebug"))
3368 /* Modify the segment map for an Irix 5 executable. */
3371 _bfd_mips_elf_modify_segment_map (abfd
)
3375 struct elf_segment_map
*m
, **pm
;
3377 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
3379 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3380 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3382 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3383 if (m
->p_type
== PT_MIPS_REGINFO
)
3387 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3391 m
->p_type
= PT_MIPS_REGINFO
;
3395 /* We want to put it after the PHDR and INTERP segments. */
3396 pm
= &elf_tdata (abfd
)->segment_map
;
3398 && ((*pm
)->p_type
== PT_PHDR
3399 || (*pm
)->p_type
== PT_INTERP
))
3407 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
3408 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
3409 PT_OPTIONS segement immediately following the program header
3411 if (IRIX_COMPAT (abfd
) == ict_irix6
)
3415 for (s
= abfd
->sections
; s
; s
= s
->next
)
3416 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
3421 struct elf_segment_map
*options_segment
;
3423 /* Usually, there's a program header table. But, sometimes
3424 there's not (like when running the `ld' testsuite). So,
3425 if there's no program header table, we just put the
3426 options segement at the end. */
3427 for (pm
= &elf_tdata (abfd
)->segment_map
;
3430 if ((*pm
)->p_type
== PT_PHDR
)
3433 options_segment
= bfd_zalloc (abfd
,
3434 sizeof (struct elf_segment_map
));
3435 options_segment
->next
= *pm
;
3436 options_segment
->p_type
= PT_MIPS_OPTIONS
;
3437 options_segment
->p_flags
= PF_R
;
3438 options_segment
->p_flags_valid
= true;
3439 options_segment
->count
= 1;
3440 options_segment
->sections
[0] = s
;
3441 *pm
= options_segment
;
3446 if (IRIX_COMPAT (abfd
) == ict_irix5
)
3448 /* If there are .dynamic and .mdebug sections, we make a room
3449 for the RTPROC header. FIXME: Rewrite without section names. */
3450 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
3451 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3452 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3454 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3455 if (m
->p_type
== PT_MIPS_RTPROC
)
3459 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3463 m
->p_type
= PT_MIPS_RTPROC
;
3465 s
= bfd_get_section_by_name (abfd
, ".rtproc");
3470 m
->p_flags_valid
= 1;
3478 /* We want to put it after the DYNAMIC segment. */
3479 pm
= &elf_tdata (abfd
)->segment_map
;
3480 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
3490 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic,
3491 .dynstr, .dynsym, and .hash sections, and everything in
3493 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
;
3495 if ((*pm
)->p_type
== PT_DYNAMIC
)
3498 if (IRIX_COMPAT (abfd
) == ict_none
)
3500 /* For a normal mips executable the permissions for the PT_DYNAMIC
3501 segment are read, write and execute. We do that here since
3502 the code in elf.c sets only the read permission. This matters
3503 sometimes for the dynamic linker. */
3504 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
3506 m
->p_flags
= PF_R
| PF_W
| PF_X
;
3507 m
->p_flags_valid
= 1;
3511 && m
->count
== 1 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
3513 static const char *sec_names
[] =
3515 ".dynamic", ".dynstr", ".dynsym", ".hash"
3519 struct elf_segment_map
*n
;
3523 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
3525 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
3526 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3532 sz
= s
->_cooked_size
;
3535 if (high
< s
->vma
+ sz
)
3541 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3542 if ((s
->flags
& SEC_LOAD
) != 0
3545 + (s
->_cooked_size
!=
3546 0 ? s
->_cooked_size
: s
->_raw_size
)) <= high
))
3549 n
= ((struct elf_segment_map
*)
3550 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
3557 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3559 if ((s
->flags
& SEC_LOAD
) != 0
3562 + (s
->_cooked_size
!= 0 ?
3563 s
->_cooked_size
: s
->_raw_size
)) <= high
))
3577 /* The structure of the runtime procedure descriptor created by the
3578 loader for use by the static exception system. */
3580 typedef struct runtime_pdr
{
3581 bfd_vma adr
; /* memory address of start of procedure */
3582 long regmask
; /* save register mask */
3583 long regoffset
; /* save register offset */
3584 long fregmask
; /* save floating point register mask */
3585 long fregoffset
; /* save floating point register offset */
3586 long frameoffset
; /* frame size */
3587 short framereg
; /* frame pointer register */
3588 short pcreg
; /* offset or reg of return pc */
3589 long irpss
; /* index into the runtime string table */
3591 struct exception_info
*exception_info
;/* pointer to exception array */
3593 #define cbRPDR sizeof (RPDR)
3594 #define rpdNil ((pRPDR) 0)
3596 /* Swap RPDR (runtime procedure table entry) for output. */
3598 static void ecoff_swap_rpdr_out
3599 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
3602 ecoff_swap_rpdr_out (abfd
, in
, ex
)
3605 struct rpdr_ext
*ex
;
3607 /* ecoff_put_off was defined in ecoffswap.h. */
3608 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
3609 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
3610 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
3611 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
3612 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
3613 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
3615 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
3616 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
3618 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
3620 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
3624 /* Read ECOFF debugging information from a .mdebug section into a
3625 ecoff_debug_info structure. */
3628 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
3631 struct ecoff_debug_info
*debug
;
3634 const struct ecoff_debug_swap
*swap
;
3635 char *ext_hdr
= NULL
;
3637 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3638 memset (debug
, 0, sizeof (*debug
));
3640 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
3641 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
3644 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
3645 swap
->external_hdr_size
)
3649 symhdr
= &debug
->symbolic_header
;
3650 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
3652 /* The symbolic header contains absolute file offsets and sizes to
3654 #define READ(ptr, offset, count, size, type) \
3655 if (symhdr->count == 0) \
3656 debug->ptr = NULL; \
3659 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
3660 if (debug->ptr == NULL) \
3661 goto error_return; \
3662 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3663 || (bfd_read (debug->ptr, size, symhdr->count, \
3664 abfd) != size * symhdr->count)) \
3665 goto error_return; \
3668 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
3669 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
3670 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
3671 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
3672 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
3673 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
3675 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
3676 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
3677 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
3678 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
3679 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
3683 debug
->adjust
= NULL
;
3688 if (ext_hdr
!= NULL
)
3690 if (debug
->line
!= NULL
)
3692 if (debug
->external_dnr
!= NULL
)
3693 free (debug
->external_dnr
);
3694 if (debug
->external_pdr
!= NULL
)
3695 free (debug
->external_pdr
);
3696 if (debug
->external_sym
!= NULL
)
3697 free (debug
->external_sym
);
3698 if (debug
->external_opt
!= NULL
)
3699 free (debug
->external_opt
);
3700 if (debug
->external_aux
!= NULL
)
3701 free (debug
->external_aux
);
3702 if (debug
->ss
!= NULL
)
3704 if (debug
->ssext
!= NULL
)
3705 free (debug
->ssext
);
3706 if (debug
->external_fdr
!= NULL
)
3707 free (debug
->external_fdr
);
3708 if (debug
->external_rfd
!= NULL
)
3709 free (debug
->external_rfd
);
3710 if (debug
->external_ext
!= NULL
)
3711 free (debug
->external_ext
);
3715 /* MIPS ELF local labels start with '$', not 'L'. */
3718 mips_elf_is_local_label_name (abfd
, name
)
3725 /* On Irix 6, the labels go back to starting with '.', so we accept
3726 the generic ELF local label syntax as well. */
3727 return _bfd_elf_is_local_label_name (abfd
, name
);
3730 /* MIPS ELF uses a special find_nearest_line routine in order the
3731 handle the ECOFF debugging information. */
3733 struct mips_elf_find_line
3735 struct ecoff_debug_info d
;
3736 struct ecoff_find_line i
;
3740 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
3741 functionname_ptr
, line_ptr
)
3746 const char **filename_ptr
;
3747 const char **functionname_ptr
;
3748 unsigned int *line_ptr
;
3752 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
3753 filename_ptr
, functionname_ptr
,
3757 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3758 filename_ptr
, functionname_ptr
,
3760 ABI_64_P (abfd
) ? 8 : 0,
3761 &elf_tdata (abfd
)->dwarf2_find_line_info
))
3764 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
3768 struct mips_elf_find_line
*fi
;
3769 const struct ecoff_debug_swap
* const swap
=
3770 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3772 /* If we are called during a link, mips_elf_final_link may have
3773 cleared the SEC_HAS_CONTENTS field. We force it back on here
3774 if appropriate (which it normally will be). */
3775 origflags
= msec
->flags
;
3776 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
3777 msec
->flags
|= SEC_HAS_CONTENTS
;
3779 fi
= elf_tdata (abfd
)->find_line_info
;
3782 bfd_size_type external_fdr_size
;
3785 struct fdr
*fdr_ptr
;
3787 fi
= ((struct mips_elf_find_line
*)
3788 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
3791 msec
->flags
= origflags
;
3795 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
3797 msec
->flags
= origflags
;
3801 /* Swap in the FDR information. */
3802 fi
->d
.fdr
= ((struct fdr
*)
3804 (fi
->d
.symbolic_header
.ifdMax
*
3805 sizeof (struct fdr
))));
3806 if (fi
->d
.fdr
== NULL
)
3808 msec
->flags
= origflags
;
3811 external_fdr_size
= swap
->external_fdr_size
;
3812 fdr_ptr
= fi
->d
.fdr
;
3813 fraw_src
= (char *) fi
->d
.external_fdr
;
3814 fraw_end
= (fraw_src
3815 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
3816 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
3817 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
3819 elf_tdata (abfd
)->find_line_info
= fi
;
3821 /* Note that we don't bother to ever free this information.
3822 find_nearest_line is either called all the time, as in
3823 objdump -l, so the information should be saved, or it is
3824 rarely called, as in ld error messages, so the memory
3825 wasted is unimportant. Still, it would probably be a
3826 good idea for free_cached_info to throw it away. */
3829 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
3830 &fi
->i
, filename_ptr
, functionname_ptr
,
3833 msec
->flags
= origflags
;
3837 msec
->flags
= origflags
;
3840 /* Fall back on the generic ELF find_nearest_line routine. */
3842 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
3843 filename_ptr
, functionname_ptr
,
3847 /* The mips16 compiler uses a couple of special sections to handle
3848 floating point arguments.
3850 Section names that look like .mips16.fn.FNNAME contain stubs that
3851 copy floating point arguments from the fp regs to the gp regs and
3852 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3853 call should be redirected to the stub instead. If no 32 bit
3854 function calls FNNAME, the stub should be discarded. We need to
3855 consider any reference to the function, not just a call, because
3856 if the address of the function is taken we will need the stub,
3857 since the address might be passed to a 32 bit function.
3859 Section names that look like .mips16.call.FNNAME contain stubs
3860 that copy floating point arguments from the gp regs to the fp
3861 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3862 then any 16 bit function that calls FNNAME should be redirected
3863 to the stub instead. If FNNAME is not a 32 bit function, the
3864 stub should be discarded.
3866 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3867 which call FNNAME and then copy the return value from the fp regs
3868 to the gp regs. These stubs store the return value in $18 while
3869 calling FNNAME; any function which might call one of these stubs
3870 must arrange to save $18 around the call. (This case is not
3871 needed for 32 bit functions that call 16 bit functions, because
3872 16 bit functions always return floating point values in both
3875 Note that in all cases FNNAME might be defined statically.
3876 Therefore, FNNAME is not used literally. Instead, the relocation
3877 information will indicate which symbol the section is for.
3879 We record any stubs that we find in the symbol table. */
3881 #define FN_STUB ".mips16.fn."
3882 #define CALL_STUB ".mips16.call."
3883 #define CALL_FP_STUB ".mips16.call.fp."
3885 /* MIPS ELF linker hash table. */
3887 struct mips_elf_link_hash_table
3889 struct elf_link_hash_table root
;
3891 /* We no longer use this. */
3892 /* String section indices for the dynamic section symbols. */
3893 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
3895 /* The number of .rtproc entries. */
3896 bfd_size_type procedure_count
;
3897 /* The size of the .compact_rel section (if SGI_COMPAT). */
3898 bfd_size_type compact_rel_size
;
3899 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3900 entry is set to the address of __rld_obj_head as in Irix 5. */
3901 boolean use_rld_obj_head
;
3902 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3904 /* This is set if we see any mips16 stub sections. */
3905 boolean mips16_stubs_seen
;
3908 /* Look up an entry in a MIPS ELF linker hash table. */
3910 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3911 ((struct mips_elf_link_hash_entry *) \
3912 elf_link_hash_lookup (&(table)->root, (string), (create), \
3915 /* Traverse a MIPS ELF linker hash table. */
3917 #define mips_elf_link_hash_traverse(table, func, info) \
3918 (elf_link_hash_traverse \
3920 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3923 /* Get the MIPS ELF linker hash table from a link_info structure. */
3925 #define mips_elf_hash_table(p) \
3926 ((struct mips_elf_link_hash_table *) ((p)->hash))
3928 static boolean mips_elf_output_extsym
3929 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3931 /* Create an entry in a MIPS ELF linker hash table. */
3933 static struct bfd_hash_entry
*
3934 mips_elf_link_hash_newfunc (entry
, table
, string
)
3935 struct bfd_hash_entry
*entry
;
3936 struct bfd_hash_table
*table
;
3939 struct mips_elf_link_hash_entry
*ret
=
3940 (struct mips_elf_link_hash_entry
*) entry
;
3942 /* Allocate the structure if it has not already been allocated by a
3944 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3945 ret
= ((struct mips_elf_link_hash_entry
*)
3946 bfd_hash_allocate (table
,
3947 sizeof (struct mips_elf_link_hash_entry
)));
3948 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3949 return (struct bfd_hash_entry
*) ret
;
3951 /* Call the allocation method of the superclass. */
3952 ret
= ((struct mips_elf_link_hash_entry
*)
3953 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3955 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3957 /* Set local fields. */
3958 memset (&ret
->esym
, 0, sizeof (EXTR
));
3959 /* We use -2 as a marker to indicate that the information has
3960 not been set. -1 means there is no associated ifd. */
3962 ret
->possibly_dynamic_relocs
= 0;
3963 ret
->min_dyn_reloc_index
= 0;
3964 ret
->no_fn_stub
= false;
3965 ret
->fn_stub
= NULL
;
3966 ret
->need_fn_stub
= false;
3967 ret
->call_stub
= NULL
;
3968 ret
->call_fp_stub
= NULL
;
3971 return (struct bfd_hash_entry
*) ret
;
3975 _bfd_mips_elf_hide_symbol (info
, h
)
3976 struct bfd_link_info
*info
;
3977 struct mips_elf_link_hash_entry
*h
;
3981 struct mips_got_info
*g
;
3982 dynobj
= elf_hash_table (info
)->dynobj
;
3983 got
= bfd_get_section_by_name (dynobj
, ".got");
3984 g
= (struct mips_got_info
*) elf_section_data (got
)->tdata
;
3986 h
->root
.elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3987 h
->root
.plt
.offset
= (bfd_vma
) -1;
3988 h
->root
.dynindx
= -1;
3990 /* FIXME: Do we allocate too much GOT space here? */
3992 got
->_raw_size
+= MIPS_ELF_GOT_SIZE (dynobj
);
3995 /* Create a MIPS ELF linker hash table. */
3997 struct bfd_link_hash_table
*
3998 _bfd_mips_elf_link_hash_table_create (abfd
)
4001 struct mips_elf_link_hash_table
*ret
;
4003 ret
= ((struct mips_elf_link_hash_table
*)
4004 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
4005 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
4008 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
4009 mips_elf_link_hash_newfunc
))
4011 bfd_release (abfd
, ret
);
4016 /* We no longer use this. */
4017 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
4018 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
4020 ret
->procedure_count
= 0;
4021 ret
->compact_rel_size
= 0;
4022 ret
->use_rld_obj_head
= false;
4024 ret
->mips16_stubs_seen
= false;
4026 return &ret
->root
.root
;
4029 /* Hook called by the linker routine which adds symbols from an object
4030 file. We must handle the special MIPS section numbers here. */
4033 _bfd_mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
4035 struct bfd_link_info
*info
;
4036 const Elf_Internal_Sym
*sym
;
4038 flagword
*flagsp ATTRIBUTE_UNUSED
;
4042 if (SGI_COMPAT (abfd
)
4043 && (abfd
->flags
& DYNAMIC
) != 0
4044 && strcmp (*namep
, "_rld_new_interface") == 0)
4046 /* Skip Irix 5 rld entry name. */
4051 switch (sym
->st_shndx
)
4054 /* Common symbols less than the GP size are automatically
4055 treated as SHN_MIPS_SCOMMON symbols. */
4056 if (sym
->st_size
> elf_gp_size (abfd
)
4057 || IRIX_COMPAT (abfd
) == ict_irix6
)
4060 case SHN_MIPS_SCOMMON
:
4061 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
4062 (*secp
)->flags
|= SEC_IS_COMMON
;
4063 *valp
= sym
->st_size
;
4067 /* This section is used in a shared object. */
4068 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
4070 asymbol
*elf_text_symbol
;
4071 asection
*elf_text_section
;
4073 elf_text_section
= bfd_zalloc (abfd
, sizeof (asection
));
4074 if (elf_text_section
== NULL
)
4077 elf_text_symbol
= bfd_zalloc (abfd
, sizeof (asymbol
));
4078 if (elf_text_symbol
== NULL
)
4081 /* Initialize the section. */
4083 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
4084 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
4086 elf_text_section
->symbol
= elf_text_symbol
;
4087 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
4089 elf_text_section
->name
= ".text";
4090 elf_text_section
->flags
= SEC_NO_FLAGS
;
4091 elf_text_section
->output_section
= NULL
;
4092 elf_text_section
->owner
= abfd
;
4093 elf_text_symbol
->name
= ".text";
4094 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
4095 elf_text_symbol
->section
= elf_text_section
;
4097 /* This code used to do *secp = bfd_und_section_ptr if
4098 info->shared. I don't know why, and that doesn't make sense,
4099 so I took it out. */
4100 *secp
= elf_tdata (abfd
)->elf_text_section
;
4103 case SHN_MIPS_ACOMMON
:
4104 /* Fall through. XXX Can we treat this as allocated data? */
4106 /* This section is used in a shared object. */
4107 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
4109 asymbol
*elf_data_symbol
;
4110 asection
*elf_data_section
;
4112 elf_data_section
= bfd_zalloc (abfd
, sizeof (asection
));
4113 if (elf_data_section
== NULL
)
4116 elf_data_symbol
= bfd_zalloc (abfd
, sizeof (asymbol
));
4117 if (elf_data_symbol
== NULL
)
4120 /* Initialize the section. */
4122 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
4123 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
4125 elf_data_section
->symbol
= elf_data_symbol
;
4126 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
4128 elf_data_section
->name
= ".data";
4129 elf_data_section
->flags
= SEC_NO_FLAGS
;
4130 elf_data_section
->output_section
= NULL
;
4131 elf_data_section
->owner
= abfd
;
4132 elf_data_symbol
->name
= ".data";
4133 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
4134 elf_data_symbol
->section
= elf_data_section
;
4136 /* This code used to do *secp = bfd_und_section_ptr if
4137 info->shared. I don't know why, and that doesn't make sense,
4138 so I took it out. */
4139 *secp
= elf_tdata (abfd
)->elf_data_section
;
4142 case SHN_MIPS_SUNDEFINED
:
4143 *secp
= bfd_und_section_ptr
;
4147 if (SGI_COMPAT (abfd
)
4149 && info
->hash
->creator
== abfd
->xvec
4150 && strcmp (*namep
, "__rld_obj_head") == 0)
4152 struct elf_link_hash_entry
*h
;
4154 /* Mark __rld_obj_head as dynamic. */
4156 if (! (_bfd_generic_link_add_one_symbol
4157 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
4158 (bfd_vma
) *valp
, (const char *) NULL
, false,
4159 get_elf_backend_data (abfd
)->collect
,
4160 (struct bfd_link_hash_entry
**) &h
)))
4162 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
4163 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4164 h
->type
= STT_OBJECT
;
4166 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4169 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
4172 /* If this is a mips16 text symbol, add 1 to the value to make it
4173 odd. This will cause something like .word SYM to come up with
4174 the right value when it is loaded into the PC. */
4175 if (sym
->st_other
== STO_MIPS16
)
4181 /* Structure used to pass information to mips_elf_output_extsym. */
4186 struct bfd_link_info
*info
;
4187 struct ecoff_debug_info
*debug
;
4188 const struct ecoff_debug_swap
*swap
;
4192 /* This routine is used to write out ECOFF debugging external symbol
4193 information. It is called via mips_elf_link_hash_traverse. The
4194 ECOFF external symbol information must match the ELF external
4195 symbol information. Unfortunately, at this point we don't know
4196 whether a symbol is required by reloc information, so the two
4197 tables may wind up being different. We must sort out the external
4198 symbol information before we can set the final size of the .mdebug
4199 section, and we must set the size of the .mdebug section before we
4200 can relocate any sections, and we can't know which symbols are
4201 required by relocation until we relocate the sections.
4202 Fortunately, it is relatively unlikely that any symbol will be
4203 stripped but required by a reloc. In particular, it can not happen
4204 when generating a final executable. */
4207 mips_elf_output_extsym (h
, data
)
4208 struct mips_elf_link_hash_entry
*h
;
4211 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
4213 asection
*sec
, *output_section
;
4215 if (h
->root
.indx
== -2)
4217 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4218 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
4219 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
4220 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
4222 else if (einfo
->info
->strip
== strip_all
4223 || (einfo
->info
->strip
== strip_some
4224 && bfd_hash_lookup (einfo
->info
->keep_hash
,
4225 h
->root
.root
.root
.string
,
4226 false, false) == NULL
))
4234 if (h
->esym
.ifd
== -2)
4237 h
->esym
.cobol_main
= 0;
4238 h
->esym
.weakext
= 0;
4239 h
->esym
.reserved
= 0;
4240 h
->esym
.ifd
= ifdNil
;
4241 h
->esym
.asym
.value
= 0;
4242 h
->esym
.asym
.st
= stGlobal
;
4244 if (h
->root
.root
.type
== bfd_link_hash_undefined
4245 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
4249 /* Use undefined class. Also, set class and type for some
4251 name
= h
->root
.root
.root
.string
;
4252 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
4253 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
4255 h
->esym
.asym
.sc
= scData
;
4256 h
->esym
.asym
.st
= stLabel
;
4257 h
->esym
.asym
.value
= 0;
4259 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
4261 h
->esym
.asym
.sc
= scAbs
;
4262 h
->esym
.asym
.st
= stLabel
;
4263 h
->esym
.asym
.value
=
4264 mips_elf_hash_table (einfo
->info
)->procedure_count
;
4266 else if (strcmp (name
, "_gp_disp") == 0)
4268 h
->esym
.asym
.sc
= scAbs
;
4269 h
->esym
.asym
.st
= stLabel
;
4270 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
4273 h
->esym
.asym
.sc
= scUndefined
;
4275 else if (h
->root
.root
.type
!= bfd_link_hash_defined
4276 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
4277 h
->esym
.asym
.sc
= scAbs
;
4282 sec
= h
->root
.root
.u
.def
.section
;
4283 output_section
= sec
->output_section
;
4285 /* When making a shared library and symbol h is the one from
4286 the another shared library, OUTPUT_SECTION may be null. */
4287 if (output_section
== NULL
)
4288 h
->esym
.asym
.sc
= scUndefined
;
4291 name
= bfd_section_name (output_section
->owner
, output_section
);
4293 if (strcmp (name
, ".text") == 0)
4294 h
->esym
.asym
.sc
= scText
;
4295 else if (strcmp (name
, ".data") == 0)
4296 h
->esym
.asym
.sc
= scData
;
4297 else if (strcmp (name
, ".sdata") == 0)
4298 h
->esym
.asym
.sc
= scSData
;
4299 else if (strcmp (name
, ".rodata") == 0
4300 || strcmp (name
, ".rdata") == 0)
4301 h
->esym
.asym
.sc
= scRData
;
4302 else if (strcmp (name
, ".bss") == 0)
4303 h
->esym
.asym
.sc
= scBss
;
4304 else if (strcmp (name
, ".sbss") == 0)
4305 h
->esym
.asym
.sc
= scSBss
;
4306 else if (strcmp (name
, ".init") == 0)
4307 h
->esym
.asym
.sc
= scInit
;
4308 else if (strcmp (name
, ".fini") == 0)
4309 h
->esym
.asym
.sc
= scFini
;
4311 h
->esym
.asym
.sc
= scAbs
;
4315 h
->esym
.asym
.reserved
= 0;
4316 h
->esym
.asym
.index
= indexNil
;
4319 if (h
->root
.root
.type
== bfd_link_hash_common
)
4320 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
4321 else if (h
->root
.root
.type
== bfd_link_hash_defined
4322 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4324 if (h
->esym
.asym
.sc
== scCommon
)
4325 h
->esym
.asym
.sc
= scBss
;
4326 else if (h
->esym
.asym
.sc
== scSCommon
)
4327 h
->esym
.asym
.sc
= scSBss
;
4329 sec
= h
->root
.root
.u
.def
.section
;
4330 output_section
= sec
->output_section
;
4331 if (output_section
!= NULL
)
4332 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
4333 + sec
->output_offset
4334 + output_section
->vma
);
4336 h
->esym
.asym
.value
= 0;
4338 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4340 struct mips_elf_link_hash_entry
*hd
= h
;
4341 boolean no_fn_stub
= h
->no_fn_stub
;
4343 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
4345 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
4346 no_fn_stub
= no_fn_stub
|| hd
->no_fn_stub
;
4351 /* Set type and value for a symbol with a function stub. */
4352 h
->esym
.asym
.st
= stProc
;
4353 sec
= hd
->root
.root
.u
.def
.section
;
4355 h
->esym
.asym
.value
= 0;
4358 output_section
= sec
->output_section
;
4359 if (output_section
!= NULL
)
4360 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
4361 + sec
->output_offset
4362 + output_section
->vma
);
4364 h
->esym
.asym
.value
= 0;
4372 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
4373 h
->root
.root
.root
.string
,
4376 einfo
->failed
= true;
4383 /* Create a runtime procedure table from the .mdebug section. */
4386 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
4389 struct bfd_link_info
*info
;
4391 struct ecoff_debug_info
*debug
;
4393 const struct ecoff_debug_swap
*swap
;
4394 HDRR
*hdr
= &debug
->symbolic_header
;
4396 struct rpdr_ext
*erp
;
4398 struct pdr_ext
*epdr
;
4399 struct sym_ext
*esym
;
4402 unsigned long size
, count
;
4403 unsigned long sindex
;
4407 const char *no_name_func
= _("static procedure (no name)");
4415 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4417 sindex
= strlen (no_name_func
) + 1;
4418 count
= hdr
->ipdMax
;
4421 size
= swap
->external_pdr_size
;
4423 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
4427 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
4430 size
= sizeof (RPDR
);
4431 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
4435 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
4439 count
= hdr
->isymMax
;
4440 size
= swap
->external_sym_size
;
4441 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
4445 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
4448 count
= hdr
->issMax
;
4449 ss
= (char *) bfd_malloc (count
);
4452 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
4455 count
= hdr
->ipdMax
;
4456 for (i
= 0; i
< count
; i
++, rp
++)
4458 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
4459 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
4460 rp
->adr
= sym
.value
;
4461 rp
->regmask
= pdr
.regmask
;
4462 rp
->regoffset
= pdr
.regoffset
;
4463 rp
->fregmask
= pdr
.fregmask
;
4464 rp
->fregoffset
= pdr
.fregoffset
;
4465 rp
->frameoffset
= pdr
.frameoffset
;
4466 rp
->framereg
= pdr
.framereg
;
4467 rp
->pcreg
= pdr
.pcreg
;
4469 sv
[i
] = ss
+ sym
.iss
;
4470 sindex
+= strlen (sv
[i
]) + 1;
4474 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
4475 size
= BFD_ALIGN (size
, 16);
4476 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
4479 mips_elf_hash_table (info
)->procedure_count
= 0;
4483 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
4485 erp
= (struct rpdr_ext
*) rtproc
;
4486 memset (erp
, 0, sizeof (struct rpdr_ext
));
4488 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
4489 strcpy (str
, no_name_func
);
4490 str
+= strlen (no_name_func
) + 1;
4491 for (i
= 0; i
< count
; i
++)
4493 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
4494 strcpy (str
, sv
[i
]);
4495 str
+= strlen (sv
[i
]) + 1;
4497 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
4499 /* Set the size and contents of .rtproc section. */
4500 s
->_raw_size
= size
;
4501 s
->contents
= (bfd_byte
*) rtproc
;
4503 /* Skip this section later on (I don't think this currently
4504 matters, but someday it might). */
4505 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
4534 /* A comparison routine used to sort .gptab entries. */
4537 gptab_compare (p1
, p2
)
4541 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
4542 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
4544 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
4547 /* We need to use a special link routine to handle the .reginfo and
4548 the .mdebug sections. We need to merge all instances of these
4549 sections together, not write them all out sequentially. */
4552 _bfd_mips_elf_final_link (abfd
, info
)
4554 struct bfd_link_info
*info
;
4558 struct bfd_link_order
*p
;
4559 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
4560 asection
*rtproc_sec
;
4561 Elf32_RegInfo reginfo
;
4562 struct ecoff_debug_info debug
;
4563 const struct ecoff_debug_swap
*swap
4564 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4565 HDRR
*symhdr
= &debug
.symbolic_header
;
4566 PTR mdebug_handle
= NULL
;
4571 static const char * const name
[] =
4573 ".text", ".init", ".fini", ".data",
4574 ".rodata", ".sdata", ".sbss", ".bss"
4576 static const int sc
[] =
4578 scText
, scInit
, scFini
, scData
,
4579 scRData
, scSData
, scSBss
, scBss
4582 /* If all the things we linked together were PIC, but we're
4583 producing an executable (rather than a shared object), then the
4584 resulting file is CPIC (i.e., it calls PIC code.) */
4586 && !info
->relocateable
4587 && elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
4589 elf_elfheader (abfd
)->e_flags
&= ~EF_MIPS_PIC
;
4590 elf_elfheader (abfd
)->e_flags
|= EF_MIPS_CPIC
;
4593 /* We'd carefully arranged the dynamic symbol indices, and then the
4594 generic size_dynamic_sections renumbered them out from under us.
4595 Rather than trying somehow to prevent the renumbering, just do
4597 if (elf_hash_table (info
)->dynamic_sections_created
)
4601 struct mips_got_info
*g
;
4603 /* When we resort, we must tell mips_elf_sort_hash_table what
4604 the lowest index it may use is. That's the number of section
4605 symbols we're going to add. The generic ELF linker only
4606 adds these symbols when building a shared object. Note that
4607 we count the sections after (possibly) removing the .options
4609 if (!mips_elf_sort_hash_table (info
, (info
->shared
4610 ? bfd_count_sections (abfd
) + 1
4614 /* Make sure we didn't grow the global .got region. */
4615 dynobj
= elf_hash_table (info
)->dynobj
;
4616 got
= bfd_get_section_by_name (dynobj
, ".got");
4617 g
= (struct mips_got_info
*) elf_section_data (got
)->tdata
;
4619 if (g
->global_gotsym
!= NULL
)
4620 BFD_ASSERT ((elf_hash_table (info
)->dynsymcount
4621 - g
->global_gotsym
->dynindx
)
4622 <= g
->global_gotno
);
4625 /* On IRIX5, we omit the .options section. On IRIX6, however, we
4626 include it, even though we don't process it quite right. (Some
4627 entries are supposed to be merged.) Empirically, we seem to be
4628 better off including it then not. */
4629 if (IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
4630 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
4632 if (strcmp ((*secpp
)->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
4634 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
4635 if (p
->type
== bfd_indirect_link_order
)
4636 p
->u
.indirect
.section
->flags
&= ~SEC_HAS_CONTENTS
;
4637 (*secpp
)->link_order_head
= NULL
;
4638 *secpp
= (*secpp
)->next
;
4639 --abfd
->section_count
;
4645 /* Get a value for the GP register. */
4646 if (elf_gp (abfd
) == 0)
4648 struct bfd_link_hash_entry
*h
;
4650 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4651 if (h
!= (struct bfd_link_hash_entry
*) NULL
4652 && h
->type
== bfd_link_hash_defined
)
4653 elf_gp (abfd
) = (h
->u
.def
.value
4654 + h
->u
.def
.section
->output_section
->vma
4655 + h
->u
.def
.section
->output_offset
);
4656 else if (info
->relocateable
)
4660 /* Find the GP-relative section with the lowest offset. */
4662 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4664 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
4667 /* And calculate GP relative to that. */
4668 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
4672 /* If the relocate_section function needs to do a reloc
4673 involving the GP value, it should make a reloc_dangerous
4674 callback to warn that GP is not defined. */
4678 /* Go through the sections and collect the .reginfo and .mdebug
4682 gptab_data_sec
= NULL
;
4683 gptab_bss_sec
= NULL
;
4684 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4686 if (strcmp (o
->name
, ".reginfo") == 0)
4688 memset (®info
, 0, sizeof reginfo
);
4690 /* We have found the .reginfo section in the output file.
4691 Look through all the link_orders comprising it and merge
4692 the information together. */
4693 for (p
= o
->link_order_head
;
4694 p
!= (struct bfd_link_order
*) NULL
;
4697 asection
*input_section
;
4699 Elf32_External_RegInfo ext
;
4702 if (p
->type
!= bfd_indirect_link_order
)
4704 if (p
->type
== bfd_fill_link_order
)
4709 input_section
= p
->u
.indirect
.section
;
4710 input_bfd
= input_section
->owner
;
4712 /* The linker emulation code has probably clobbered the
4713 size to be zero bytes. */
4714 if (input_section
->_raw_size
== 0)
4715 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4717 if (! bfd_get_section_contents (input_bfd
, input_section
,
4723 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
4725 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
4726 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
4727 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
4728 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
4729 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
4731 /* ri_gp_value is set by the function
4732 mips_elf32_section_processing when the section is
4733 finally written out. */
4735 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4736 elf_link_input_bfd ignores this section. */
4737 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
4740 /* Size has been set in mips_elf_always_size_sections */
4741 BFD_ASSERT(o
->_raw_size
== sizeof (Elf32_External_RegInfo
));
4743 /* Skip this section later on (I don't think this currently
4744 matters, but someday it might). */
4745 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4750 if (strcmp (o
->name
, ".mdebug") == 0)
4752 struct extsym_info einfo
;
4754 /* We have found the .mdebug section in the output file.
4755 Look through all the link_orders comprising it and merge
4756 the information together. */
4757 symhdr
->magic
= swap
->sym_magic
;
4758 /* FIXME: What should the version stamp be? */
4760 symhdr
->ilineMax
= 0;
4764 symhdr
->isymMax
= 0;
4765 symhdr
->ioptMax
= 0;
4766 symhdr
->iauxMax
= 0;
4768 symhdr
->issExtMax
= 0;
4771 symhdr
->iextMax
= 0;
4773 /* We accumulate the debugging information itself in the
4774 debug_info structure. */
4776 debug
.external_dnr
= NULL
;
4777 debug
.external_pdr
= NULL
;
4778 debug
.external_sym
= NULL
;
4779 debug
.external_opt
= NULL
;
4780 debug
.external_aux
= NULL
;
4782 debug
.ssext
= debug
.ssext_end
= NULL
;
4783 debug
.external_fdr
= NULL
;
4784 debug
.external_rfd
= NULL
;
4785 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4787 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4788 if (mdebug_handle
== (PTR
) NULL
)
4792 esym
.cobol_main
= 0;
4796 esym
.asym
.iss
= issNil
;
4797 esym
.asym
.st
= stLocal
;
4798 esym
.asym
.reserved
= 0;
4799 esym
.asym
.index
= indexNil
;
4801 for (i
= 0; i
< 8; i
++)
4803 esym
.asym
.sc
= sc
[i
];
4804 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4807 esym
.asym
.value
= s
->vma
;
4808 last
= s
->vma
+ s
->_raw_size
;
4811 esym
.asym
.value
= last
;
4812 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4817 for (p
= o
->link_order_head
;
4818 p
!= (struct bfd_link_order
*) NULL
;
4821 asection
*input_section
;
4823 const struct ecoff_debug_swap
*input_swap
;
4824 struct ecoff_debug_info input_debug
;
4828 if (p
->type
!= bfd_indirect_link_order
)
4830 if (p
->type
== bfd_fill_link_order
)
4835 input_section
= p
->u
.indirect
.section
;
4836 input_bfd
= input_section
->owner
;
4838 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4839 || (get_elf_backend_data (input_bfd
)
4840 ->elf_backend_ecoff_debug_swap
) == NULL
)
4842 /* I don't know what a non MIPS ELF bfd would be
4843 doing with a .mdebug section, but I don't really
4844 want to deal with it. */
4848 input_swap
= (get_elf_backend_data (input_bfd
)
4849 ->elf_backend_ecoff_debug_swap
);
4851 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
4853 /* The ECOFF linking code expects that we have already
4854 read in the debugging information and set up an
4855 ecoff_debug_info structure, so we do that now. */
4856 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
4860 if (! (bfd_ecoff_debug_accumulate
4861 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
4862 &input_debug
, input_swap
, info
)))
4865 /* Loop through the external symbols. For each one with
4866 interesting information, try to find the symbol in
4867 the linker global hash table and save the information
4868 for the output external symbols. */
4869 eraw_src
= input_debug
.external_ext
;
4870 eraw_end
= (eraw_src
4871 + (input_debug
.symbolic_header
.iextMax
4872 * input_swap
->external_ext_size
));
4874 eraw_src
< eraw_end
;
4875 eraw_src
+= input_swap
->external_ext_size
)
4879 struct mips_elf_link_hash_entry
*h
;
4881 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4882 if (ext
.asym
.sc
== scNil
4883 || ext
.asym
.sc
== scUndefined
4884 || ext
.asym
.sc
== scSUndefined
)
4887 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4888 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
4889 name
, false, false, true);
4890 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4896 < input_debug
.symbolic_header
.ifdMax
);
4897 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4903 /* Free up the information we just read. */
4904 free (input_debug
.line
);
4905 free (input_debug
.external_dnr
);
4906 free (input_debug
.external_pdr
);
4907 free (input_debug
.external_sym
);
4908 free (input_debug
.external_opt
);
4909 free (input_debug
.external_aux
);
4910 free (input_debug
.ss
);
4911 free (input_debug
.ssext
);
4912 free (input_debug
.external_fdr
);
4913 free (input_debug
.external_rfd
);
4914 free (input_debug
.external_ext
);
4916 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4917 elf_link_input_bfd ignores this section. */
4918 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
4921 if (SGI_COMPAT (abfd
) && info
->shared
)
4923 /* Create .rtproc section. */
4924 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4925 if (rtproc_sec
== NULL
)
4927 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4928 | SEC_LINKER_CREATED
| SEC_READONLY
);
4930 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4931 if (rtproc_sec
== NULL
4932 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4933 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
4937 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
4938 info
, rtproc_sec
, &debug
))
4942 /* Build the external symbol information. */
4945 einfo
.debug
= &debug
;
4947 einfo
.failed
= false;
4948 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4949 mips_elf_output_extsym
,
4954 /* Set the size of the .mdebug section. */
4955 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4957 /* Skip this section later on (I don't think this currently
4958 matters, but someday it might). */
4959 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4964 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4966 const char *subname
;
4969 Elf32_External_gptab
*ext_tab
;
4972 /* The .gptab.sdata and .gptab.sbss sections hold
4973 information describing how the small data area would
4974 change depending upon the -G switch. These sections
4975 not used in executables files. */
4976 if (! info
->relocateable
)
4980 for (p
= o
->link_order_head
;
4981 p
!= (struct bfd_link_order
*) NULL
;
4984 asection
*input_section
;
4986 if (p
->type
!= bfd_indirect_link_order
)
4988 if (p
->type
== bfd_fill_link_order
)
4993 input_section
= p
->u
.indirect
.section
;
4995 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4996 elf_link_input_bfd ignores this section. */
4997 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
5000 /* Skip this section later on (I don't think this
5001 currently matters, but someday it might). */
5002 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
5004 /* Really remove the section. */
5005 for (secpp
= &abfd
->sections
;
5007 secpp
= &(*secpp
)->next
)
5009 *secpp
= (*secpp
)->next
;
5010 --abfd
->section_count
;
5015 /* There is one gptab for initialized data, and one for
5016 uninitialized data. */
5017 if (strcmp (o
->name
, ".gptab.sdata") == 0)
5019 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
5023 (*_bfd_error_handler
)
5024 (_("%s: illegal section name `%s'"),
5025 bfd_get_filename (abfd
), o
->name
);
5026 bfd_set_error (bfd_error_nonrepresentable_section
);
5030 /* The linker script always combines .gptab.data and
5031 .gptab.sdata into .gptab.sdata, and likewise for
5032 .gptab.bss and .gptab.sbss. It is possible that there is
5033 no .sdata or .sbss section in the output file, in which
5034 case we must change the name of the output section. */
5035 subname
= o
->name
+ sizeof ".gptab" - 1;
5036 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
5038 if (o
== gptab_data_sec
)
5039 o
->name
= ".gptab.data";
5041 o
->name
= ".gptab.bss";
5042 subname
= o
->name
+ sizeof ".gptab" - 1;
5043 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
5046 /* Set up the first entry. */
5048 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
5051 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
5052 tab
[0].gt_header
.gt_unused
= 0;
5054 /* Combine the input sections. */
5055 for (p
= o
->link_order_head
;
5056 p
!= (struct bfd_link_order
*) NULL
;
5059 asection
*input_section
;
5063 bfd_size_type gpentry
;
5065 if (p
->type
!= bfd_indirect_link_order
)
5067 if (p
->type
== bfd_fill_link_order
)
5072 input_section
= p
->u
.indirect
.section
;
5073 input_bfd
= input_section
->owner
;
5075 /* Combine the gptab entries for this input section one
5076 by one. We know that the input gptab entries are
5077 sorted by ascending -G value. */
5078 size
= bfd_section_size (input_bfd
, input_section
);
5080 for (gpentry
= sizeof (Elf32_External_gptab
);
5082 gpentry
+= sizeof (Elf32_External_gptab
))
5084 Elf32_External_gptab ext_gptab
;
5085 Elf32_gptab int_gptab
;
5091 if (! (bfd_get_section_contents
5092 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
5093 gpentry
, sizeof (Elf32_External_gptab
))))
5099 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
5101 val
= int_gptab
.gt_entry
.gt_g_value
;
5102 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
5105 for (look
= 1; look
< c
; look
++)
5107 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
5108 tab
[look
].gt_entry
.gt_bytes
+= add
;
5110 if (tab
[look
].gt_entry
.gt_g_value
== val
)
5116 Elf32_gptab
*new_tab
;
5119 /* We need a new table entry. */
5120 new_tab
= ((Elf32_gptab
*)
5121 bfd_realloc ((PTR
) tab
,
5122 (c
+ 1) * sizeof (Elf32_gptab
)));
5123 if (new_tab
== NULL
)
5129 tab
[c
].gt_entry
.gt_g_value
= val
;
5130 tab
[c
].gt_entry
.gt_bytes
= add
;
5132 /* Merge in the size for the next smallest -G
5133 value, since that will be implied by this new
5136 for (look
= 1; look
< c
; look
++)
5138 if (tab
[look
].gt_entry
.gt_g_value
< val
5140 || (tab
[look
].gt_entry
.gt_g_value
5141 > tab
[max
].gt_entry
.gt_g_value
)))
5145 tab
[c
].gt_entry
.gt_bytes
+=
5146 tab
[max
].gt_entry
.gt_bytes
;
5151 last
= int_gptab
.gt_entry
.gt_bytes
;
5154 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5155 elf_link_input_bfd ignores this section. */
5156 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
5159 /* The table must be sorted by -G value. */
5161 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
5163 /* Swap out the table. */
5164 ext_tab
= ((Elf32_External_gptab
*)
5165 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
5166 if (ext_tab
== NULL
)
5172 for (i
= 0; i
< c
; i
++)
5173 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
5176 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
5177 o
->contents
= (bfd_byte
*) ext_tab
;
5179 /* Skip this section later on (I don't think this currently
5180 matters, but someday it might). */
5181 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
5185 /* Invoke the regular ELF backend linker to do all the work. */
5186 if (ABI_64_P (abfd
))
5189 if (!bfd_elf64_bfd_final_link (abfd
, info
))
5196 else if (!bfd_elf32_bfd_final_link (abfd
, info
))
5199 /* Now write out the computed sections. */
5201 if (reginfo_sec
!= (asection
*) NULL
)
5203 Elf32_External_RegInfo ext
;
5205 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
5206 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
5207 (file_ptr
) 0, sizeof ext
))
5211 if (mdebug_sec
!= (asection
*) NULL
)
5213 BFD_ASSERT (abfd
->output_has_begun
);
5214 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
5216 mdebug_sec
->filepos
))
5219 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
5222 if (gptab_data_sec
!= (asection
*) NULL
)
5224 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
5225 gptab_data_sec
->contents
,
5227 gptab_data_sec
->_raw_size
))
5231 if (gptab_bss_sec
!= (asection
*) NULL
)
5233 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
5234 gptab_bss_sec
->contents
,
5236 gptab_bss_sec
->_raw_size
))
5240 if (SGI_COMPAT (abfd
))
5242 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
5243 if (rtproc_sec
!= NULL
)
5245 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
5246 rtproc_sec
->contents
,
5248 rtproc_sec
->_raw_size
))
5256 /* This function is called via qsort() to sort the dynamic relocation
5257 entries by increasing r_symndx value. */
5260 sort_dynamic_relocs (arg1
, arg2
)
5264 const Elf32_External_Rel
*ext_reloc1
= (const Elf32_External_Rel
*) arg1
;
5265 const Elf32_External_Rel
*ext_reloc2
= (const Elf32_External_Rel
*) arg2
;
5267 Elf_Internal_Rel int_reloc1
;
5268 Elf_Internal_Rel int_reloc2
;
5270 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, ext_reloc1
, &int_reloc1
);
5271 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, ext_reloc2
, &int_reloc2
);
5273 return (ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
));
5276 /* Returns the GOT section for ABFD. */
5279 mips_elf_got_section (abfd
)
5282 return bfd_get_section_by_name (abfd
, ".got");
5285 /* Returns the GOT information associated with the link indicated by
5286 INFO. If SGOTP is non-NULL, it is filled in with the GOT
5289 static struct mips_got_info
*
5290 mips_elf_got_info (abfd
, sgotp
)
5295 struct mips_got_info
*g
;
5297 sgot
= mips_elf_got_section (abfd
);
5298 BFD_ASSERT (sgot
!= NULL
);
5299 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5300 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5301 BFD_ASSERT (g
!= NULL
);
5308 /* Return whether a relocation is against a local symbol. */
5311 mips_elf_local_relocation_p (input_bfd
, relocation
, local_sections
,
5314 const Elf_Internal_Rela
*relocation
;
5315 asection
**local_sections
;
5316 boolean check_forced
;
5318 unsigned long r_symndx
;
5319 Elf_Internal_Shdr
*symtab_hdr
;
5320 struct mips_elf_link_hash_entry
*h
;
5323 r_symndx
= ELF32_R_SYM (relocation
->r_info
);
5324 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5325 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
5327 if (r_symndx
< extsymoff
)
5329 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
5334 /* Look up the hash table to check whether the symbol
5335 was forced local. */
5336 h
= (struct mips_elf_link_hash_entry
*)
5337 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
5338 /* Find the real hash-table entry for this symbol. */
5339 while (h
->root
.root
.type
== bfd_link_hash_indirect
5340 || h
->root
.root
.type
== bfd_link_hash_warning
)
5341 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
5342 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
5349 /* Sign-extend VALUE, which has the indicated number of BITS. */
5352 mips_elf_sign_extend (value
, bits
)
5356 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
5357 /* VALUE is negative. */
5358 value
|= ((bfd_vma
) - 1) << bits
;
5363 /* Return non-zero if the indicated VALUE has overflowed the maximum
5364 range expressable by a signed number with the indicated number of
5368 mips_elf_overflow_p (value
, bits
)
5372 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
5374 if (svalue
> (1 << (bits
- 1)) - 1)
5375 /* The value is too big. */
5377 else if (svalue
< -(1 << (bits
- 1)))
5378 /* The value is too small. */
5385 /* Calculate the %high function. */
5388 mips_elf_high (value
)
5391 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
5394 /* Calculate the %higher function. */
5397 mips_elf_higher (value
)
5398 bfd_vma value ATTRIBUTE_UNUSED
;
5401 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
5404 return (bfd_vma
) -1;
5408 /* Calculate the %highest function. */
5411 mips_elf_highest (value
)
5412 bfd_vma value ATTRIBUTE_UNUSED
;
5415 return ((value
+ (bfd_vma
) 0x800080008000) >> 48) & 0xffff;
5418 return (bfd_vma
) -1;
5422 /* Returns the GOT index for the global symbol indicated by H. */
5425 mips_elf_global_got_index (abfd
, h
)
5427 struct elf_link_hash_entry
*h
;
5431 struct mips_got_info
*g
;
5433 g
= mips_elf_got_info (abfd
, &sgot
);
5435 /* Once we determine the global GOT entry with the lowest dynamic
5436 symbol table index, we must put all dynamic symbols with greater
5437 indices into the GOT. That makes it easy to calculate the GOT
5439 BFD_ASSERT (h
->dynindx
>= g
->global_gotsym
->dynindx
);
5440 index
= ((h
->dynindx
- g
->global_gotsym
->dynindx
+ g
->local_gotno
)
5441 * MIPS_ELF_GOT_SIZE (abfd
));
5442 BFD_ASSERT (index
< sgot
->_raw_size
);
5447 /* Returns the offset for the entry at the INDEXth position
5451 mips_elf_got_offset_from_index (dynobj
, output_bfd
, index
)
5459 sgot
= mips_elf_got_section (dynobj
);
5460 gp
= _bfd_get_gp_value (output_bfd
);
5461 return (sgot
->output_section
->vma
+ sgot
->output_offset
+ index
-
5465 /* If H is a symbol that needs a global GOT entry, but has a dynamic
5466 symbol table index lower than any we've seen to date, record it for
5470 mips_elf_record_global_got_symbol (h
, info
, g
)
5471 struct elf_link_hash_entry
*h
;
5472 struct bfd_link_info
*info
;
5473 struct mips_got_info
*g ATTRIBUTE_UNUSED
;
5475 /* A global symbol in the GOT must also be in the dynamic symbol
5477 if (h
->dynindx
== -1
5478 && !bfd_elf32_link_record_dynamic_symbol (info
, h
))
5481 /* If we've already marked this entry as need GOT space, we don't
5482 need to do it again. */
5483 if (h
->got
.offset
!= (bfd_vma
) - 1)
5486 /* By setting this to a value other than -1, we are indicating that
5487 there needs to be a GOT entry for H. */
5493 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
5494 the dynamic symbols. */
5496 struct mips_elf_hash_sort_data
5498 /* The symbol in the global GOT with the lowest dynamic symbol table
5500 struct elf_link_hash_entry
*low
;
5501 /* The least dynamic symbol table index corresponding to a symbol
5502 with a GOT entry. */
5503 long min_got_dynindx
;
5504 /* The greatest dynamic symbol table index not corresponding to a
5505 symbol without a GOT entry. */
5506 long max_non_got_dynindx
;
5509 /* If H needs a GOT entry, assign it the highest available dynamic
5510 index. Otherwise, assign it the lowest available dynamic
5514 mips_elf_sort_hash_table_f (h
, data
)
5515 struct mips_elf_link_hash_entry
*h
;
5518 struct mips_elf_hash_sort_data
*hsd
5519 = (struct mips_elf_hash_sort_data
*) data
;
5521 /* Symbols without dynamic symbol table entries aren't interesting
5523 if (h
->root
.dynindx
== -1)
5526 if (h
->root
.got
.offset
!= 0)
5527 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
5530 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
5531 hsd
->low
= (struct elf_link_hash_entry
*) h
;
5537 /* Sort the dynamic symbol table so that symbols that need GOT entries
5538 appear towards the end. This reduces the amount of GOT space
5539 required. MAX_LOCAL is used to set the number of local symbols
5540 known to be in the dynamic symbol table. During
5541 mips_elf_size_dynamic_sections, this value is 1. Afterward, the
5542 section symbols are added and the count is higher. */
5545 mips_elf_sort_hash_table (info
, max_local
)
5546 struct bfd_link_info
*info
;
5547 unsigned long max_local
;
5549 struct mips_elf_hash_sort_data hsd
;
5550 struct mips_got_info
*g
;
5553 dynobj
= elf_hash_table (info
)->dynobj
;
5556 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
;
5557 hsd
.max_non_got_dynindx
= max_local
;
5558 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
5559 elf_hash_table (info
)),
5560 mips_elf_sort_hash_table_f
,
5563 /* There shoud have been enough room in the symbol table to
5564 accomodate both the GOT and non-GOT symbols. */
5565 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
5567 /* Now we know which dynamic symbol has the lowest dynamic symbol
5568 table index in the GOT. */
5569 g
= mips_elf_got_info (dynobj
, NULL
);
5570 g
->global_gotsym
= hsd
.low
;
5575 /* Create a local GOT entry for VALUE. Return the index of the entry,
5576 or -1 if it could not be created. */
5579 mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
)
5581 struct mips_got_info
*g
;
5585 if (g
->assigned_gotno
>= g
->local_gotno
)
5587 /* We didn't allocate enough space in the GOT. */
5588 (*_bfd_error_handler
)
5589 (_("not enough GOT space for local GOT entries"));
5590 bfd_set_error (bfd_error_bad_value
);
5591 return (bfd_vma
) -1;
5594 MIPS_ELF_PUT_WORD (abfd
, value
,
5596 + MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
));
5597 return MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
5600 /* Returns the GOT offset at which the indicated address can be found.
5601 If there is not yet a GOT entry for this value, create one. Returns
5602 -1 if no satisfactory GOT offset can be found. */
5605 mips_elf_local_got_index (abfd
, info
, value
)
5607 struct bfd_link_info
*info
;
5611 struct mips_got_info
*g
;
5614 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
5616 /* Look to see if we already have an appropriate entry. */
5617 for (entry
= (sgot
->contents
5618 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
5619 entry
!= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
5620 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
5622 bfd_vma address
= MIPS_ELF_GET_WORD (abfd
, entry
);
5623 if (address
== value
)
5624 return entry
- sgot
->contents
;
5627 return mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
5630 /* Find a GOT entry that is within 32KB of the VALUE. These entries
5631 are supposed to be placed at small offsets in the GOT, i.e.,
5632 within 32KB of GP. Return the index into the GOT for this page,
5633 and store the offset from this entry to the desired address in
5634 OFFSETP, if it is non-NULL. */
5637 mips_elf_got_page (abfd
, info
, value
, offsetp
)
5639 struct bfd_link_info
*info
;
5644 struct mips_got_info
*g
;
5646 bfd_byte
*last_entry
;
5650 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
5652 /* Look to see if we aleady have an appropriate entry. */
5653 last_entry
= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
5654 for (entry
= (sgot
->contents
5655 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
5656 entry
!= last_entry
;
5657 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
5659 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
5661 if (!mips_elf_overflow_p (value
- address
, 16))
5663 /* This entry will serve as the page pointer. We can add a
5664 16-bit number to it to get the actual address. */
5665 index
= entry
- sgot
->contents
;
5670 /* If we didn't have an appropriate entry, we create one now. */
5671 if (entry
== last_entry
)
5672 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
5676 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
5677 *offsetp
= value
- address
;
5683 /* Find a GOT entry whose higher-order 16 bits are the same as those
5684 for value. Return the index into the GOT for this entry. */
5687 mips_elf_got16_entry (abfd
, info
, value
, external
)
5689 struct bfd_link_info
*info
;
5694 struct mips_got_info
*g
;
5696 bfd_byte
*last_entry
;
5702 /* Although the ABI says that it is "the high-order 16 bits" that we
5703 want, it is really the %high value. The complete value is
5704 calculated with a `addiu' of a LO16 relocation, just as with a
5706 value
= mips_elf_high (value
) << 16;
5709 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
5711 /* Look to see if we already have an appropriate entry. */
5712 last_entry
= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
5713 for (entry
= (sgot
->contents
5714 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
5715 entry
!= last_entry
;
5716 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
5718 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
5719 if (address
== value
)
5721 /* This entry has the right high-order 16 bits, and the low-order
5722 16 bits are set to zero. */
5723 index
= entry
- sgot
->contents
;
5728 /* If we didn't have an appropriate entry, we create one now. */
5729 if (entry
== last_entry
)
5730 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
5735 /* Returns the first relocation of type r_type found, beginning with
5736 RELOCATION. RELEND is one-past-the-end of the relocation table. */
5738 static const Elf_Internal_Rela
*
5739 mips_elf_next_relocation (r_type
, relocation
, relend
)
5740 unsigned int r_type
;
5741 const Elf_Internal_Rela
*relocation
;
5742 const Elf_Internal_Rela
*relend
;
5744 /* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be
5745 immediately following. However, for the IRIX6 ABI, the next
5746 relocation may be a composed relocation consisting of several
5747 relocations for the same address. In that case, the R_MIPS_LO16
5748 relocation may occur as one of these. We permit a similar
5749 extension in general, as that is useful for GCC. */
5750 while (relocation
< relend
)
5752 if (ELF32_R_TYPE (relocation
->r_info
) == r_type
)
5758 /* We didn't find it. */
5759 bfd_set_error (bfd_error_bad_value
);
5763 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
5764 is the original relocation, which is now being transformed into a
5765 dynamic relocation. The ADDENDP is adjusted if necessary; the
5766 caller should store the result in place of the original addend. */
5769 mips_elf_create_dynamic_relocation (output_bfd
, info
, rel
, h
, sec
,
5770 symbol
, addendp
, input_section
)
5772 struct bfd_link_info
*info
;
5773 const Elf_Internal_Rela
*rel
;
5774 struct mips_elf_link_hash_entry
*h
;
5778 asection
*input_section
;
5780 Elf_Internal_Rel outrel
;
5786 r_type
= ELF32_R_TYPE (rel
->r_info
);
5787 dynobj
= elf_hash_table (info
)->dynobj
;
5789 = bfd_get_section_by_name (dynobj
,
5790 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd
));
5791 BFD_ASSERT (sreloc
!= NULL
);
5792 BFD_ASSERT (sreloc
->contents
!= NULL
);
5796 /* We begin by assuming that the offset for the dynamic relocation
5797 is the same as for the original relocation. We'll adjust this
5798 later to reflect the correct output offsets. */
5799 if (elf_section_data (input_section
)->stab_info
== NULL
)
5800 outrel
.r_offset
= rel
->r_offset
;
5803 /* Except that in a stab section things are more complex.
5804 Because we compress stab information, the offset given in the
5805 relocation may not be the one we want; we must let the stabs
5806 machinery tell us the offset. */
5808 = (_bfd_stab_section_offset
5809 (output_bfd
, &elf_hash_table (info
)->stab_info
,
5811 &elf_section_data (input_section
)->stab_info
,
5813 /* If we didn't need the relocation at all, this value will be
5815 if (outrel
.r_offset
== (bfd_vma
) -1)
5819 /* If we've decided to skip this relocation, just output an empty
5820 record. Note that R_MIPS_NONE == 0, so that this call to memset
5821 is a way of setting R_TYPE to R_MIPS_NONE. */
5823 memset (&outrel
, 0, sizeof (outrel
));
5827 bfd_vma section_offset
;
5829 /* We must now calculate the dynamic symbol table index to use
5830 in the relocation. */
5832 && (! info
->symbolic
|| (h
->root
.elf_link_hash_flags
5833 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5835 indx
= h
->root
.dynindx
;
5836 /* h->root.dynindx may be -1 if this symbol was marked to
5843 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5845 else if (sec
== NULL
|| sec
->owner
== NULL
)
5847 bfd_set_error (bfd_error_bad_value
);
5852 indx
= elf_section_data (sec
->output_section
)->dynindx
;
5857 /* Figure out how far the target of the relocation is from
5858 the beginning of its section. */
5859 section_offset
= symbol
- sec
->output_section
->vma
;
5860 /* The relocation we're building is section-relative.
5861 Therefore, the original addend must be adjusted by the
5863 *addendp
+= section_offset
;
5864 /* Now, the relocation is just against the section. */
5865 symbol
= sec
->output_section
->vma
;
5868 /* If the relocation was previously an absolute relocation and
5869 this symbol will not be referred to by the relocation, we must
5870 adjust it by the value we give it in the dynamic symbol table.
5871 Otherwise leave the job up to the dynamic linker. */
5872 if (!indx
&& r_type
!= R_MIPS_REL32
)
5875 /* The relocation is always an REL32 relocation because we don't
5876 know where the shared library will wind up at load-time. */
5877 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
5879 /* Adjust the output offset of the relocation to reference the
5880 correct location in the output file. */
5881 outrel
.r_offset
+= (input_section
->output_section
->vma
5882 + input_section
->output_offset
);
5885 /* Put the relocation back out. We have to use the special
5886 relocation outputter in the 64-bit case since the 64-bit
5887 relocation format is non-standard. */
5888 if (ABI_64_P (output_bfd
))
5890 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
5891 (output_bfd
, &outrel
,
5893 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
5896 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
5897 (((Elf32_External_Rel
*)
5899 + sreloc
->reloc_count
));
5901 /* Record the index of the first relocation referencing H. This
5902 information is later emitted in the .msym section. */
5904 && (h
->min_dyn_reloc_index
== 0
5905 || sreloc
->reloc_count
< h
->min_dyn_reloc_index
))
5906 h
->min_dyn_reloc_index
= sreloc
->reloc_count
;
5908 /* We've now added another relocation. */
5909 ++sreloc
->reloc_count
;
5911 /* Make sure the output section is writable. The dynamic linker
5912 will be writing to it. */
5913 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
5916 /* On IRIX5, make an entry of compact relocation info. */
5917 if (! skip
&& IRIX_COMPAT (output_bfd
) == ict_irix5
)
5919 asection
*scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5924 Elf32_crinfo cptrel
;
5926 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5927 cptrel
.vaddr
= (rel
->r_offset
5928 + input_section
->output_section
->vma
5929 + input_section
->output_offset
);
5930 if (r_type
== R_MIPS_REL32
)
5931 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5933 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5934 mips_elf_set_cr_dist2to (cptrel
, 0);
5935 cptrel
.konst
= *addendp
;
5937 cr
= (scpt
->contents
5938 + sizeof (Elf32_External_compact_rel
));
5939 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5940 ((Elf32_External_crinfo
*) cr
5941 + scpt
->reloc_count
));
5942 ++scpt
->reloc_count
;
5949 /* Calculate the value produced by the RELOCATION (which comes from
5950 the INPUT_BFD). The ADDEND is the addend to use for this
5951 RELOCATION; RELOCATION->R_ADDEND is ignored.
5953 The result of the relocation calculation is stored in VALUEP.
5954 REQUIRE_JALXP indicates whether or not the opcode used with this
5955 relocation must be JALX.
5957 This function returns bfd_reloc_continue if the caller need take no
5958 further action regarding this relocation, bfd_reloc_notsupported if
5959 something goes dramatically wrong, bfd_reloc_overflow if an
5960 overflow occurs, and bfd_reloc_ok to indicate success. */
5962 static bfd_reloc_status_type
5963 mips_elf_calculate_relocation (abfd
,
5977 asection
*input_section
;
5978 struct bfd_link_info
*info
;
5979 const Elf_Internal_Rela
*relocation
;
5981 reloc_howto_type
*howto
;
5982 Elf_Internal_Sym
*local_syms
;
5983 asection
**local_sections
;
5986 boolean
*require_jalxp
;
5988 /* The eventual value we will return. */
5990 /* The address of the symbol against which the relocation is
5993 /* The final GP value to be used for the relocatable, executable, or
5994 shared object file being produced. */
5995 bfd_vma gp
= (bfd_vma
) - 1;
5996 /* The place (section offset or address) of the storage unit being
5999 /* The value of GP used to create the relocatable object. */
6000 bfd_vma gp0
= (bfd_vma
) - 1;
6001 /* The offset into the global offset table at which the address of
6002 the relocation entry symbol, adjusted by the addend, resides
6003 during execution. */
6004 bfd_vma g
= (bfd_vma
) - 1;
6005 /* The section in which the symbol referenced by the relocation is
6007 asection
*sec
= NULL
;
6008 struct mips_elf_link_hash_entry
*h
= NULL
;
6009 /* True if the symbol referred to by this relocation is a local
6012 /* True if the symbol referred to by this relocation is "_gp_disp". */
6013 boolean gp_disp_p
= false;
6014 Elf_Internal_Shdr
*symtab_hdr
;
6016 unsigned long r_symndx
;
6018 /* True if overflow occurred during the calculation of the
6019 relocation value. */
6020 boolean overflowed_p
;
6021 /* True if this relocation refers to a MIPS16 function. */
6022 boolean target_is_16_bit_code_p
= false;
6024 /* Parse the relocation. */
6025 r_symndx
= ELF32_R_SYM (relocation
->r_info
);
6026 r_type
= ELF32_R_TYPE (relocation
->r_info
);
6027 p
= (input_section
->output_section
->vma
6028 + input_section
->output_offset
6029 + relocation
->r_offset
);
6031 /* Assume that there will be no overflow. */
6032 overflowed_p
= false;
6034 /* Figure out whether or not the symbol is local, and get the offset
6035 used in the array of hash table entries. */
6036 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
6037 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
6038 local_sections
, false);
6039 if (! elf_bad_symtab (input_bfd
))
6040 extsymoff
= symtab_hdr
->sh_info
;
6043 /* The symbol table does not follow the rule that local symbols
6044 must come before globals. */
6048 /* Figure out the value of the symbol. */
6051 Elf_Internal_Sym
*sym
;
6053 sym
= local_syms
+ r_symndx
;
6054 sec
= local_sections
[r_symndx
];
6056 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
6057 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
6058 symbol
+= sym
->st_value
;
6060 /* MIPS16 text labels should be treated as odd. */
6061 if (sym
->st_other
== STO_MIPS16
)
6064 /* Record the name of this symbol, for our caller. */
6065 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
6066 symtab_hdr
->sh_link
,
6069 *namep
= bfd_section_name (input_bfd
, sec
);
6071 target_is_16_bit_code_p
= (sym
->st_other
== STO_MIPS16
);
6075 /* For global symbols we look up the symbol in the hash-table. */
6076 h
= ((struct mips_elf_link_hash_entry
*)
6077 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
6078 /* Find the real hash-table entry for this symbol. */
6079 while (h
->root
.root
.type
== bfd_link_hash_indirect
6080 || h
->root
.root
.type
== bfd_link_hash_warning
)
6081 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
6083 /* Record the name of this symbol, for our caller. */
6084 *namep
= h
->root
.root
.root
.string
;
6086 /* See if this is the special _gp_disp symbol. Note that such a
6087 symbol must always be a global symbol. */
6088 if (strcmp (h
->root
.root
.root
.string
, "_gp_disp") == 0)
6090 /* Relocations against _gp_disp are permitted only with
6091 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
6092 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_LO16
)
6093 return bfd_reloc_notsupported
;
6097 /* If this symbol is defined, calculate its address. Note that
6098 _gp_disp is a magic symbol, always implicitly defined by the
6099 linker, so it's inappropriate to check to see whether or not
6101 else if ((h
->root
.root
.type
== bfd_link_hash_defined
6102 || h
->root
.root
.type
== bfd_link_hash_defweak
)
6103 && h
->root
.root
.u
.def
.section
)
6105 sec
= h
->root
.root
.u
.def
.section
;
6106 if (sec
->output_section
)
6107 symbol
= (h
->root
.root
.u
.def
.value
6108 + sec
->output_section
->vma
6109 + sec
->output_offset
);
6111 symbol
= h
->root
.root
.u
.def
.value
;
6113 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
6114 /* We allow relocations against undefined weak symbols, giving
6115 it the value zero, so that you can undefined weak functions
6116 and check to see if they exist by looking at their
6119 else if (info
->shared
&& !info
->symbolic
&& !info
->no_undefined
6120 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
6122 else if (strcmp (h
->root
.root
.root
.string
, "_DYNAMIC_LINK") == 0 ||
6123 strcmp (h
->root
.root
.root
.string
, "_DYNAMIC_LINKING") == 0)
6125 /* If this is a dynamic link, we should have created a
6126 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
6127 in in mips_elf_create_dynamic_sections.
6128 Otherwise, we should define the symbol with a value of 0.
6129 FIXME: It should probably get into the symbol table
6131 BFD_ASSERT (! info
->shared
);
6132 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
6137 if (! ((*info
->callbacks
->undefined_symbol
)
6138 (info
, h
->root
.root
.root
.string
, input_bfd
,
6139 input_section
, relocation
->r_offset
,
6140 (!info
->shared
|| info
->no_undefined
6141 || ELF_ST_VISIBILITY (h
->root
.other
)))))
6142 return bfd_reloc_undefined
;
6146 target_is_16_bit_code_p
= (h
->root
.other
== STO_MIPS16
);
6149 /* If this is a 32-bit call to a 16-bit function with a stub, we
6150 need to redirect the call to the stub, unless we're already *in*
6152 if (r_type
!= R_MIPS16_26
&& !info
->relocateable
6153 && ((h
!= NULL
&& h
->fn_stub
!= NULL
)
6154 || (local_p
&& elf_tdata (input_bfd
)->local_stubs
!= NULL
6155 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
6156 && !mips_elf_stub_section_p (input_bfd
, input_section
))
6158 /* This is a 32-bit call to a 16-bit function. We should
6159 have already noticed that we were going to need the
6162 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
6165 BFD_ASSERT (h
->need_fn_stub
);
6169 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
6171 /* If this is a 16-bit call to a 32-bit function with a stub, we
6172 need to redirect the call to the stub. */
6173 else if (r_type
== R_MIPS16_26
&& !info
->relocateable
6175 && (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
)
6176 && !target_is_16_bit_code_p
)
6178 /* If both call_stub and call_fp_stub are defined, we can figure
6179 out which one to use by seeing which one appears in the input
6181 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
6186 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
6188 if (strncmp (bfd_get_section_name (input_bfd
, o
),
6189 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6191 sec
= h
->call_fp_stub
;
6198 else if (h
->call_stub
!= NULL
)
6201 sec
= h
->call_fp_stub
;
6203 BFD_ASSERT (sec
->_raw_size
> 0);
6204 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
6207 /* Calls from 16-bit code to 32-bit code and vice versa require the
6208 special jalx instruction. */
6209 *require_jalxp
= (!info
->relocateable
6210 && ((r_type
== R_MIPS16_26
) != target_is_16_bit_code_p
));
6212 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
6213 local_sections
, true);
6215 /* If we haven't already determined the GOT offset, or the GP value,
6216 and we're going to need it, get it now. */
6221 case R_MIPS_GOT_DISP
:
6222 case R_MIPS_GOT_HI16
:
6223 case R_MIPS_CALL_HI16
:
6224 case R_MIPS_GOT_LO16
:
6225 case R_MIPS_CALL_LO16
:
6226 /* Find the index into the GOT where this value is located. */
6229 BFD_ASSERT (addend
== 0);
6230 g
= mips_elf_global_got_index
6231 (elf_hash_table (info
)->dynobj
,
6232 (struct elf_link_hash_entry
*) h
);
6233 if (! elf_hash_table(info
)->dynamic_sections_created
6235 && (info
->symbolic
|| h
->root
.dynindx
== -1)
6236 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
6238 /* This is a static link or a -Bsymbolic link. The
6239 symbol is defined locally, or was forced to be local.
6240 We must initialize this entry in the GOT. */
6241 asection
*sgot
= mips_elf_got_section(elf_hash_table
6243 MIPS_ELF_PUT_WORD (elf_hash_table (info
)->dynobj
,
6244 symbol
+ addend
, sgot
->contents
+ g
);
6247 else if (r_type
== R_MIPS_GOT16
|| r_type
== R_MIPS_CALL16
)
6248 /* There's no need to create a local GOT entry here; the
6249 calculation for a local GOT16 entry does not involve G. */
6253 g
= mips_elf_local_got_index (abfd
, info
, symbol
+ addend
);
6254 if (g
== (bfd_vma
) -1)
6258 /* Convert GOT indices to actual offsets. */
6259 g
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
6265 case R_MIPS_GPREL16
:
6266 case R_MIPS_GPREL32
:
6267 case R_MIPS_LITERAL
:
6268 gp0
= _bfd_get_gp_value (input_bfd
);
6269 gp
= _bfd_get_gp_value (abfd
);
6276 /* Figure out what kind of relocation is being performed. */
6280 return bfd_reloc_continue
;
6283 value
= symbol
+ mips_elf_sign_extend (addend
, 16);
6284 overflowed_p
= mips_elf_overflow_p (value
, 16);
6291 || (elf_hash_table (info
)->dynamic_sections_created
6293 && ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)
6295 && (input_section
->flags
& SEC_ALLOC
) != 0)
6297 /* If we're creating a shared library, or this relocation is
6298 against a symbol in a shared library, then we can't know
6299 where the symbol will end up. So, we create a relocation
6300 record in the output, and leave the job up to the dynamic
6303 if (!mips_elf_create_dynamic_relocation (abfd
,
6315 if (r_type
!= R_MIPS_REL32
)
6316 value
= symbol
+ addend
;
6320 value
&= howto
->dst_mask
;
6325 case R_MIPS_GNU_REL_LO16
:
6326 value
= symbol
+ addend
- p
;
6327 value
&= howto
->dst_mask
;
6330 case R_MIPS_GNU_REL16_S2
:
6331 value
= symbol
+ mips_elf_sign_extend (addend
<< 2, 18) - p
;
6332 overflowed_p
= mips_elf_overflow_p (value
, 18);
6333 value
= (value
>> 2) & howto
->dst_mask
;
6336 case R_MIPS_GNU_REL_HI16
:
6337 value
= mips_elf_high (addend
+ symbol
- p
);
6338 value
&= howto
->dst_mask
;
6342 /* The calculation for R_MIPS16_26 is just the same as for an
6343 R_MIPS_26. It's only the storage of the relocated field into
6344 the output file that's different. That's handled in
6345 mips_elf_perform_relocation. So, we just fall through to the
6346 R_MIPS_26 case here. */
6349 value
= (((addend
<< 2) | ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
6351 value
= (mips_elf_sign_extend (addend
<< 2, 28) + symbol
) >> 2;
6352 value
&= howto
->dst_mask
;
6358 value
= mips_elf_high (addend
+ symbol
);
6359 value
&= howto
->dst_mask
;
6363 value
= mips_elf_high (addend
+ gp
- p
);
6364 overflowed_p
= mips_elf_overflow_p (value
, 16);
6370 value
= (symbol
+ addend
) & howto
->dst_mask
;
6373 value
= addend
+ gp
- p
+ 4;
6374 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
6375 for overflow. But, on, say, Irix 5, relocations against
6376 _gp_disp are normally generated from the .cpload
6377 pseudo-op. It generates code that normally looks like
6380 lui $gp,%hi(_gp_disp)
6381 addiu $gp,$gp,%lo(_gp_disp)
6384 Here $t9 holds the address of the function being called,
6385 as required by the MIPS ELF ABI. The R_MIPS_LO16
6386 relocation can easily overflow in this situation, but the
6387 R_MIPS_HI16 relocation will handle the overflow.
6388 Therefore, we consider this a bug in the MIPS ABI, and do
6389 not check for overflow here. */
6393 case R_MIPS_LITERAL
:
6394 /* Because we don't merge literal sections, we can handle this
6395 just like R_MIPS_GPREL16. In the long run, we should merge
6396 shared literals, and then we will need to additional work
6401 case R_MIPS16_GPREL
:
6402 /* The R_MIPS16_GPREL performs the same calculation as
6403 R_MIPS_GPREL16, but stores the relocated bits in a different
6404 order. We don't need to do anything special here; the
6405 differences are handled in mips_elf_perform_relocation. */
6406 case R_MIPS_GPREL16
:
6408 value
= mips_elf_sign_extend (addend
, 16) + symbol
+ gp0
- gp
;
6410 value
= mips_elf_sign_extend (addend
, 16) + symbol
- gp
;
6411 overflowed_p
= mips_elf_overflow_p (value
, 16);
6420 /* The special case is when the symbol is forced to be local. We
6421 need the full address in the GOT since no R_MIPS_LO16 relocation
6423 forced
= ! mips_elf_local_relocation_p (input_bfd
, relocation
,
6424 local_sections
, false);
6425 value
= mips_elf_got16_entry (abfd
, info
, symbol
+ addend
, forced
);
6426 if (value
== (bfd_vma
) -1)
6429 = mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
6432 overflowed_p
= mips_elf_overflow_p (value
, 16);
6438 case R_MIPS_GOT_DISP
:
6440 overflowed_p
= mips_elf_overflow_p (value
, 16);
6443 case R_MIPS_GPREL32
:
6444 value
= (addend
+ symbol
+ gp0
- gp
) & howto
->dst_mask
;
6448 value
= mips_elf_sign_extend (addend
, 16) + symbol
- p
;
6449 value
= (bfd_vma
) ((bfd_signed_vma
) value
/ 4);
6450 overflowed_p
= mips_elf_overflow_p (value
, 16);
6453 case R_MIPS_GOT_HI16
:
6454 case R_MIPS_CALL_HI16
:
6455 /* We're allowed to handle these two relocations identically.
6456 The dynamic linker is allowed to handle the CALL relocations
6457 differently by creating a lazy evaluation stub. */
6459 value
= mips_elf_high (value
);
6460 value
&= howto
->dst_mask
;
6463 case R_MIPS_GOT_LO16
:
6464 case R_MIPS_CALL_LO16
:
6465 value
= g
& howto
->dst_mask
;
6468 case R_MIPS_GOT_PAGE
:
6469 value
= mips_elf_got_page (abfd
, info
, symbol
+ addend
, NULL
);
6470 if (value
== (bfd_vma
) -1)
6472 value
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
6475 overflowed_p
= mips_elf_overflow_p (value
, 16);
6478 case R_MIPS_GOT_OFST
:
6479 mips_elf_got_page (abfd
, info
, symbol
+ addend
, &value
);
6480 overflowed_p
= mips_elf_overflow_p (value
, 16);
6484 value
= symbol
- addend
;
6485 value
&= howto
->dst_mask
;
6489 value
= mips_elf_higher (addend
+ symbol
);
6490 value
&= howto
->dst_mask
;
6493 case R_MIPS_HIGHEST
:
6494 value
= mips_elf_highest (addend
+ symbol
);
6495 value
&= howto
->dst_mask
;
6498 case R_MIPS_SCN_DISP
:
6499 value
= symbol
+ addend
- sec
->output_offset
;
6500 value
&= howto
->dst_mask
;
6505 /* Both of these may be ignored. R_MIPS_JALR is an optimization
6506 hint; we could improve performance by honoring that hint. */
6507 return bfd_reloc_continue
;
6509 case R_MIPS_GNU_VTINHERIT
:
6510 case R_MIPS_GNU_VTENTRY
:
6511 /* We don't do anything with these at present. */
6512 return bfd_reloc_continue
;
6515 /* An unrecognized relocation type. */
6516 return bfd_reloc_notsupported
;
6519 /* Store the VALUE for our caller. */
6521 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
6524 /* Obtain the field relocated by RELOCATION. */
6527 mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
)
6528 reloc_howto_type
*howto
;
6529 const Elf_Internal_Rela
*relocation
;
6534 bfd_byte
*location
= contents
+ relocation
->r_offset
;
6536 /* Obtain the bytes. */
6537 x
= bfd_get (8 * bfd_get_reloc_size (howto
), input_bfd
, location
);
6539 if ((ELF32_R_TYPE (relocation
->r_info
) == R_MIPS16_26
6540 || ELF32_R_TYPE (relocation
->r_info
) == R_MIPS16_GPREL
)
6541 && bfd_little_endian (input_bfd
))
6542 /* The two 16-bit words will be reversed on a little-endian
6543 system. See mips_elf_perform_relocation for more details. */
6544 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
6549 /* It has been determined that the result of the RELOCATION is the
6550 VALUE. Use HOWTO to place VALUE into the output file at the
6551 appropriate position. The SECTION is the section to which the
6552 relocation applies. If REQUIRE_JALX is true, then the opcode used
6553 for the relocation must be either JAL or JALX, and it is
6554 unconditionally converted to JALX.
6556 Returns false if anything goes wrong. */
6559 mips_elf_perform_relocation (info
, howto
, relocation
, value
,
6560 input_bfd
, input_section
,
6561 contents
, require_jalx
)
6562 struct bfd_link_info
*info
;
6563 reloc_howto_type
*howto
;
6564 const Elf_Internal_Rela
*relocation
;
6567 asection
*input_section
;
6569 boolean require_jalx
;
6573 int r_type
= ELF32_R_TYPE (relocation
->r_info
);
6575 /* Figure out where the relocation is occurring. */
6576 location
= contents
+ relocation
->r_offset
;
6578 /* Obtain the current value. */
6579 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
6581 /* Clear the field we are setting. */
6582 x
&= ~howto
->dst_mask
;
6584 /* If this is the R_MIPS16_26 relocation, we must store the
6585 value in a funny way. */
6586 if (r_type
== R_MIPS16_26
)
6588 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
6589 Most mips16 instructions are 16 bits, but these instructions
6592 The format of these instructions is:
6594 +--------------+--------------------------------+
6595 ! JALX ! X! Imm 20:16 ! Imm 25:21 !
6596 +--------------+--------------------------------+
6598 +-----------------------------------------------+
6600 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
6601 Note that the immediate value in the first word is swapped.
6603 When producing a relocateable object file, R_MIPS16_26 is
6604 handled mostly like R_MIPS_26. In particular, the addend is
6605 stored as a straight 26-bit value in a 32-bit instruction.
6606 (gas makes life simpler for itself by never adjusting a
6607 R_MIPS16_26 reloc to be against a section, so the addend is
6608 always zero). However, the 32 bit instruction is stored as 2
6609 16-bit values, rather than a single 32-bit value. In a
6610 big-endian file, the result is the same; in a little-endian
6611 file, the two 16-bit halves of the 32 bit value are swapped.
6612 This is so that a disassembler can recognize the jal
6615 When doing a final link, R_MIPS16_26 is treated as a 32 bit
6616 instruction stored as two 16-bit values. The addend A is the
6617 contents of the targ26 field. The calculation is the same as
6618 R_MIPS_26. When storing the calculated value, reorder the
6619 immediate value as shown above, and don't forget to store the
6620 value as two 16-bit values.
6622 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
6626 +--------+----------------------+
6630 +--------+----------------------+
6633 +----------+------+-------------+
6637 +----------+--------------------+
6638 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
6639 ((sub1 << 16) | sub2)).
6641 When producing a relocateable object file, the calculation is
6642 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
6643 When producing a fully linked file, the calculation is
6644 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
6645 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff) */
6647 if (!info
->relocateable
)
6648 /* Shuffle the bits according to the formula above. */
6649 value
= (((value
& 0x1f0000) << 5)
6650 | ((value
& 0x3e00000) >> 5)
6651 | (value
& 0xffff));
6653 else if (r_type
== R_MIPS16_GPREL
)
6655 /* R_MIPS16_GPREL is used for GP-relative addressing in mips16
6656 mode. A typical instruction will have a format like this:
6658 +--------------+--------------------------------+
6659 ! EXTEND ! Imm 10:5 ! Imm 15:11 !
6660 +--------------+--------------------------------+
6661 ! Major ! rx ! ry ! Imm 4:0 !
6662 +--------------+--------------------------------+
6664 EXTEND is the five bit value 11110. Major is the instruction
6667 This is handled exactly like R_MIPS_GPREL16, except that the
6668 addend is retrieved and stored as shown in this diagram; that
6669 is, the Imm fields above replace the V-rel16 field.
6671 All we need to do here is shuffle the bits appropriately. As
6672 above, the two 16-bit halves must be swapped on a
6673 little-endian system. */
6674 value
= (((value
& 0x7e0) << 16)
6675 | ((value
& 0xf800) << 5)
6679 /* Set the field. */
6680 x
|= (value
& howto
->dst_mask
);
6682 /* If required, turn JAL into JALX. */
6686 bfd_vma opcode
= x
>> 26;
6687 bfd_vma jalx_opcode
;
6689 /* Check to see if the opcode is already JAL or JALX. */
6690 if (r_type
== R_MIPS16_26
)
6692 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
6697 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
6701 /* If the opcode is not JAL or JALX, there's a problem. */
6704 (*_bfd_error_handler
)
6705 (_("%s: %s+0x%lx: jump to stub routine which is not jal"),
6706 bfd_get_filename (input_bfd
),
6707 input_section
->name
,
6708 (unsigned long) relocation
->r_offset
);
6709 bfd_set_error (bfd_error_bad_value
);
6713 /* Make this the JALX opcode. */
6714 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
6717 /* Swap the high- and low-order 16 bits on little-endian systems
6718 when doing a MIPS16 relocation. */
6719 if ((r_type
== R_MIPS16_GPREL
|| r_type
== R_MIPS16_26
)
6720 && bfd_little_endian (input_bfd
))
6721 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
6723 /* Put the value into the output. */
6724 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
6728 /* Returns true if SECTION is a MIPS16 stub section. */
6731 mips_elf_stub_section_p (abfd
, section
)
6732 bfd
*abfd ATTRIBUTE_UNUSED
;
6735 const char *name
= bfd_get_section_name (abfd
, section
);
6737 return (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0
6738 || strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
6739 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0);
6742 /* Relocate a MIPS ELF section. */
6745 _bfd_mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
6746 contents
, relocs
, local_syms
, local_sections
)
6748 struct bfd_link_info
*info
;
6750 asection
*input_section
;
6752 Elf_Internal_Rela
*relocs
;
6753 Elf_Internal_Sym
*local_syms
;
6754 asection
**local_sections
;
6756 Elf_Internal_Rela
*rel
;
6757 const Elf_Internal_Rela
*relend
;
6759 boolean use_saved_addend_p
= false;
6760 struct elf_backend_data
*bed
;
6762 bed
= get_elf_backend_data (output_bfd
);
6763 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
6764 for (rel
= relocs
; rel
< relend
; ++rel
)
6768 reloc_howto_type
*howto
;
6769 boolean require_jalx
;
6770 /* True if the relocation is a RELA relocation, rather than a
6772 boolean rela_relocation_p
= true;
6773 int r_type
= ELF32_R_TYPE (rel
->r_info
);
6775 /* Find the relocation howto for this relocation. */
6776 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
))
6778 /* Some 32-bit code uses R_MIPS_64. In particular, people use
6779 64-bit code, but make sure all their addresses are in the
6780 lowermost or uppermost 32-bit section of the 64-bit address
6781 space. Thus, when they use an R_MIPS_64 they mean what is
6782 usually meant by R_MIPS_32, with the exception that the
6783 stored value is sign-extended to 64 bits. */
6784 howto
= elf_mips_howto_table
+ R_MIPS_32
;
6786 /* On big-endian systems, we need to lie about the position
6788 if (bfd_big_endian (input_bfd
))
6792 howto
= mips_rtype_to_howto (r_type
);
6794 if (!use_saved_addend_p
)
6796 Elf_Internal_Shdr
*rel_hdr
;
6798 /* If these relocations were originally of the REL variety,
6799 we must pull the addend out of the field that will be
6800 relocated. Otherwise, we simply use the contents of the
6801 RELA relocation. To determine which flavor or relocation
6802 this is, we depend on the fact that the INPUT_SECTION's
6803 REL_HDR is read before its REL_HDR2. */
6804 rel_hdr
= &elf_section_data (input_section
)->rel_hdr
;
6805 if ((size_t) (rel
- relocs
)
6806 >= (rel_hdr
->sh_size
/ rel_hdr
->sh_entsize
6807 * bed
->s
->int_rels_per_ext_rel
))
6808 rel_hdr
= elf_section_data (input_section
)->rel_hdr2
;
6809 if (rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (input_bfd
))
6811 /* Note that this is a REL relocation. */
6812 rela_relocation_p
= false;
6814 /* Get the addend, which is stored in the input file. */
6815 addend
= mips_elf_obtain_contents (howto
,
6819 addend
&= howto
->src_mask
;
6821 /* For some kinds of relocations, the ADDEND is a
6822 combination of the addend stored in two different
6824 if (r_type
== R_MIPS_HI16
6825 || r_type
== R_MIPS_GNU_REL_HI16
6826 || (r_type
== R_MIPS_GOT16
6827 && mips_elf_local_relocation_p (input_bfd
, rel
,
6828 local_sections
, false)))
6831 const Elf_Internal_Rela
*lo16_relocation
;
6832 reloc_howto_type
*lo16_howto
;
6835 /* The combined value is the sum of the HI16 addend,
6836 left-shifted by sixteen bits, and the LO16
6837 addend, sign extended. (Usually, the code does
6838 a `lui' of the HI16 value, and then an `addiu' of
6841 Scan ahead to find a matching LO16 relocation. */
6842 if (r_type
== R_MIPS_GNU_REL_HI16
)
6843 lo
= R_MIPS_GNU_REL_LO16
;
6847 = mips_elf_next_relocation (lo
, rel
, relend
);
6848 if (lo16_relocation
== NULL
)
6851 /* Obtain the addend kept there. */
6852 lo16_howto
= mips_rtype_to_howto (lo
);
6853 l
= mips_elf_obtain_contents (lo16_howto
,
6855 input_bfd
, contents
);
6856 l
&= lo16_howto
->src_mask
;
6857 l
= mips_elf_sign_extend (l
, 16);
6861 /* Compute the combined addend. */
6864 else if (r_type
== R_MIPS16_GPREL
)
6866 /* The addend is scrambled in the object file. See
6867 mips_elf_perform_relocation for details on the
6869 addend
= (((addend
& 0x1f0000) >> 5)
6870 | ((addend
& 0x7e00000) >> 16)
6875 addend
= rel
->r_addend
;
6878 if (info
->relocateable
)
6880 Elf_Internal_Sym
*sym
;
6881 unsigned long r_symndx
;
6883 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
)
6884 && bfd_big_endian (input_bfd
))
6887 /* Since we're just relocating, all we need to do is copy
6888 the relocations back out to the object file, unless
6889 they're against a section symbol, in which case we need
6890 to adjust by the section offset, or unless they're GP
6891 relative in which case we need to adjust by the amount
6892 that we're adjusting GP in this relocateable object. */
6894 if (!mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
,
6896 /* There's nothing to do for non-local relocations. */
6899 if (r_type
== R_MIPS16_GPREL
6900 || r_type
== R_MIPS_GPREL16
6901 || r_type
== R_MIPS_GPREL32
6902 || r_type
== R_MIPS_LITERAL
)
6903 addend
-= (_bfd_get_gp_value (output_bfd
)
6904 - _bfd_get_gp_value (input_bfd
));
6905 else if (r_type
== R_MIPS_26
|| r_type
== R_MIPS16_26
6906 || r_type
== R_MIPS_GNU_REL16_S2
)
6907 /* The addend is stored without its two least
6908 significant bits (which are always zero.) In a
6909 non-relocateable link, calculate_relocation will do
6910 this shift; here, we must do it ourselves. */
6913 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6914 sym
= local_syms
+ r_symndx
;
6915 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
6916 /* Adjust the addend appropriately. */
6917 addend
+= local_sections
[r_symndx
]->output_offset
;
6919 /* If the relocation is for a R_MIPS_HI16 or R_MIPS_GOT16,
6920 then we only want to write out the high-order 16 bits.
6921 The subsequent R_MIPS_LO16 will handle the low-order bits. */
6922 if (r_type
== R_MIPS_HI16
|| r_type
== R_MIPS_GOT16
6923 || r_type
== R_MIPS_GNU_REL_HI16
)
6924 addend
= mips_elf_high (addend
);
6925 /* If the relocation is for an R_MIPS_26 relocation, then
6926 the two low-order bits are not stored in the object file;
6927 they are implicitly zero. */
6928 else if (r_type
== R_MIPS_26
|| r_type
== R_MIPS16_26
6929 || r_type
== R_MIPS_GNU_REL16_S2
)
6932 if (rela_relocation_p
)
6933 /* If this is a RELA relocation, just update the addend.
6934 We have to cast away constness for REL. */
6935 rel
->r_addend
= addend
;
6938 /* Otherwise, we have to write the value back out. Note
6939 that we use the source mask, rather than the
6940 destination mask because the place to which we are
6941 writing will be source of the addend in the final
6943 addend
&= howto
->src_mask
;
6945 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
))
6946 /* See the comment above about using R_MIPS_64 in the 32-bit
6947 ABI. Here, we need to update the addend. It would be
6948 possible to get away with just using the R_MIPS_32 reloc
6949 but for endianness. */
6955 if (addend
& ((bfd_vma
) 1 << 31))
6956 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
6960 /* If we don't know that we have a 64-bit type,
6961 do two separate stores. */
6962 if (bfd_big_endian (input_bfd
))
6964 /* Store the sign-bits (which are most significant)
6966 low_bits
= sign_bits
;
6972 high_bits
= sign_bits
;
6974 bfd_put_32 (input_bfd
, low_bits
,
6975 contents
+ rel
->r_offset
);
6976 bfd_put_32 (input_bfd
, high_bits
,
6977 contents
+ rel
->r_offset
+ 4);
6981 if (!mips_elf_perform_relocation (info
, howto
, rel
, addend
,
6982 input_bfd
, input_section
,
6987 /* Go on to the next relocation. */
6991 /* In the N32 and 64-bit ABIs there may be multiple consecutive
6992 relocations for the same offset. In that case we are
6993 supposed to treat the output of each relocation as the addend
6995 if (rel
+ 1 < relend
6996 && rel
->r_offset
== rel
[1].r_offset
6997 && ELF32_R_TYPE (rel
[1].r_info
) != R_MIPS_NONE
)
6998 use_saved_addend_p
= true;
7000 use_saved_addend_p
= false;
7002 /* Figure out what value we are supposed to relocate. */
7003 switch (mips_elf_calculate_relocation (output_bfd
,
7016 case bfd_reloc_continue
:
7017 /* There's nothing to do. */
7020 case bfd_reloc_undefined
:
7021 /* mips_elf_calculate_relocation already called the
7022 undefined_symbol callback. There's no real point in
7023 trying to perform the relocation at this point, so we
7024 just skip ahead to the next relocation. */
7027 case bfd_reloc_notsupported
:
7031 case bfd_reloc_overflow
:
7032 if (use_saved_addend_p
)
7033 /* Ignore overflow until we reach the last relocation for
7034 a given location. */
7038 BFD_ASSERT (name
!= NULL
);
7039 if (! ((*info
->callbacks
->reloc_overflow
)
7040 (info
, name
, howto
->name
, (bfd_vma
) 0,
7041 input_bfd
, input_section
, rel
->r_offset
)))
7054 /* If we've got another relocation for the address, keep going
7055 until we reach the last one. */
7056 if (use_saved_addend_p
)
7062 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
))
7063 /* See the comment above about using R_MIPS_64 in the 32-bit
7064 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
7065 that calculated the right value. Now, however, we
7066 sign-extend the 32-bit result to 64-bits, and store it as a
7067 64-bit value. We are especially generous here in that we
7068 go to extreme lengths to support this usage on systems with
7069 only a 32-bit VMA. */
7075 if (value
& ((bfd_vma
) 1 << 31))
7076 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
7080 /* If we don't know that we have a 64-bit type,
7081 do two separate stores. */
7082 if (bfd_big_endian (input_bfd
))
7084 /* Undo what we did above. */
7086 /* Store the sign-bits (which are most significant)
7088 low_bits
= sign_bits
;
7094 high_bits
= sign_bits
;
7096 bfd_put_32 (input_bfd
, low_bits
,
7097 contents
+ rel
->r_offset
);
7098 bfd_put_32 (input_bfd
, high_bits
,
7099 contents
+ rel
->r_offset
+ 4);
7103 /* Actually perform the relocation. */
7104 if (!mips_elf_perform_relocation (info
, howto
, rel
, value
, input_bfd
,
7105 input_section
, contents
,
7113 /* This hook function is called before the linker writes out a global
7114 symbol. We mark symbols as small common if appropriate. This is
7115 also where we undo the increment of the value for a mips16 symbol. */
7118 _bfd_mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
7119 bfd
*abfd ATTRIBUTE_UNUSED
;
7120 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
7121 const char *name ATTRIBUTE_UNUSED
;
7122 Elf_Internal_Sym
*sym
;
7123 asection
*input_sec
;
7125 /* If we see a common symbol, which implies a relocatable link, then
7126 if a symbol was small common in an input file, mark it as small
7127 common in the output file. */
7128 if (sym
->st_shndx
== SHN_COMMON
7129 && strcmp (input_sec
->name
, ".scommon") == 0)
7130 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
7132 if (sym
->st_other
== STO_MIPS16
7133 && (sym
->st_value
& 1) != 0)
7139 /* Functions for the dynamic linker. */
7141 /* The name of the dynamic interpreter. This is put in the .interp
7144 #define ELF_DYNAMIC_INTERPRETER(abfd) \
7145 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
7146 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
7147 : "/usr/lib/libc.so.1")
7149 /* Create dynamic sections when linking against a dynamic object. */
7152 _bfd_mips_elf_create_dynamic_sections (abfd
, info
)
7154 struct bfd_link_info
*info
;
7156 struct elf_link_hash_entry
*h
;
7158 register asection
*s
;
7159 const char * const *namep
;
7161 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7162 | SEC_LINKER_CREATED
| SEC_READONLY
);
7164 /* Mips ABI requests the .dynamic section to be read only. */
7165 s
= bfd_get_section_by_name (abfd
, ".dynamic");
7168 if (! bfd_set_section_flags (abfd
, s
, flags
))
7172 /* We need to create .got section. */
7173 if (! mips_elf_create_got_section (abfd
, info
))
7176 /* Create the .msym section on IRIX6. It is used by the dynamic
7177 linker to speed up dynamic relocations, and to avoid computing
7178 the ELF hash for symbols. */
7179 if (IRIX_COMPAT (abfd
) == ict_irix6
7180 && !mips_elf_create_msym_section (abfd
))
7183 /* Create .stub section. */
7184 if (bfd_get_section_by_name (abfd
,
7185 MIPS_ELF_STUB_SECTION_NAME (abfd
)) == NULL
)
7187 s
= bfd_make_section (abfd
, MIPS_ELF_STUB_SECTION_NAME (abfd
));
7189 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_CODE
)
7190 || ! bfd_set_section_alignment (abfd
, s
,
7191 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7195 if ((IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
7197 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
7199 s
= bfd_make_section (abfd
, ".rld_map");
7201 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
7202 || ! bfd_set_section_alignment (abfd
, s
,
7203 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7207 /* On IRIX5, we adjust add some additional symbols and change the
7208 alignments of several sections. There is no ABI documentation
7209 indicating that this is necessary on IRIX6, nor any evidence that
7210 the linker takes such action. */
7211 if (IRIX_COMPAT (abfd
) == ict_irix5
)
7213 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
7216 if (! (_bfd_generic_link_add_one_symbol
7217 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
7218 (bfd_vma
) 0, (const char *) NULL
, false,
7219 get_elf_backend_data (abfd
)->collect
,
7220 (struct bfd_link_hash_entry
**) &h
)))
7222 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
7223 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7224 h
->type
= STT_SECTION
;
7226 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7230 /* We need to create a .compact_rel section. */
7231 if (SGI_COMPAT (abfd
))
7233 if (!mips_elf_create_compact_rel_section (abfd
, info
))
7237 /* Change aligments of some sections. */
7238 s
= bfd_get_section_by_name (abfd
, ".hash");
7240 bfd_set_section_alignment (abfd
, s
, 4);
7241 s
= bfd_get_section_by_name (abfd
, ".dynsym");
7243 bfd_set_section_alignment (abfd
, s
, 4);
7244 s
= bfd_get_section_by_name (abfd
, ".dynstr");
7246 bfd_set_section_alignment (abfd
, s
, 4);
7247 s
= bfd_get_section_by_name (abfd
, ".reginfo");
7249 bfd_set_section_alignment (abfd
, s
, 4);
7250 s
= bfd_get_section_by_name (abfd
, ".dynamic");
7252 bfd_set_section_alignment (abfd
, s
, 4);
7258 if (SGI_COMPAT (abfd
))
7260 if (!(_bfd_generic_link_add_one_symbol
7261 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
7262 (bfd_vma
) 0, (const char *) NULL
, false,
7263 get_elf_backend_data (abfd
)->collect
,
7264 (struct bfd_link_hash_entry
**) &h
)))
7269 /* For normal mips it is _DYNAMIC_LINKING. */
7270 if (!(_bfd_generic_link_add_one_symbol
7271 (info
, abfd
, "_DYNAMIC_LINKING", BSF_GLOBAL
,
7272 bfd_abs_section_ptr
, (bfd_vma
) 0, (const char *) NULL
, false,
7273 get_elf_backend_data (abfd
)->collect
,
7274 (struct bfd_link_hash_entry
**) &h
)))
7277 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
7278 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7279 h
->type
= STT_SECTION
;
7281 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7284 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
7286 /* __rld_map is a four byte word located in the .data section
7287 and is filled in by the rtld to contain a pointer to
7288 the _r_debug structure. Its symbol value will be set in
7289 mips_elf_finish_dynamic_symbol. */
7290 s
= bfd_get_section_by_name (abfd
, ".rld_map");
7291 BFD_ASSERT (s
!= NULL
);
7294 if (SGI_COMPAT (abfd
))
7296 if (!(_bfd_generic_link_add_one_symbol
7297 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
7298 (bfd_vma
) 0, (const char *) NULL
, false,
7299 get_elf_backend_data (abfd
)->collect
,
7300 (struct bfd_link_hash_entry
**) &h
)))
7305 /* For normal mips the symbol is __RLD_MAP. */
7306 if (!(_bfd_generic_link_add_one_symbol
7307 (info
, abfd
, "__RLD_MAP", BSF_GLOBAL
, s
,
7308 (bfd_vma
) 0, (const char *) NULL
, false,
7309 get_elf_backend_data (abfd
)->collect
,
7310 (struct bfd_link_hash_entry
**) &h
)))
7313 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
7314 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7315 h
->type
= STT_OBJECT
;
7317 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7325 /* Create the .compact_rel section. */
7328 mips_elf_create_compact_rel_section (abfd
, info
)
7330 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
7333 register asection
*s
;
7335 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
7337 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
7340 s
= bfd_make_section (abfd
, ".compact_rel");
7342 || ! bfd_set_section_flags (abfd
, s
, flags
)
7343 || ! bfd_set_section_alignment (abfd
, s
,
7344 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7347 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
7353 /* Create the .got section to hold the global offset table. */
7356 mips_elf_create_got_section (abfd
, info
)
7358 struct bfd_link_info
*info
;
7361 register asection
*s
;
7362 struct elf_link_hash_entry
*h
;
7363 struct mips_got_info
*g
;
7365 /* This function may be called more than once. */
7366 if (mips_elf_got_section (abfd
))
7369 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7370 | SEC_LINKER_CREATED
);
7372 s
= bfd_make_section (abfd
, ".got");
7374 || ! bfd_set_section_flags (abfd
, s
, flags
)
7375 || ! bfd_set_section_alignment (abfd
, s
, 4))
7378 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
7379 linker script because we don't want to define the symbol if we
7380 are not creating a global offset table. */
7382 if (! (_bfd_generic_link_add_one_symbol
7383 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
7384 (bfd_vma
) 0, (const char *) NULL
, false,
7385 get_elf_backend_data (abfd
)->collect
,
7386 (struct bfd_link_hash_entry
**) &h
)))
7388 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
7389 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
7390 h
->type
= STT_OBJECT
;
7393 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
7396 /* The first several global offset table entries are reserved. */
7397 s
->_raw_size
= MIPS_RESERVED_GOTNO
* MIPS_ELF_GOT_SIZE (abfd
);
7399 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
7400 sizeof (struct mips_got_info
));
7403 g
->global_gotsym
= NULL
;
7404 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
7405 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
7406 if (elf_section_data (s
) == NULL
)
7409 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
7410 if (elf_section_data (s
) == NULL
)
7413 elf_section_data (s
)->tdata
= (PTR
) g
;
7414 elf_section_data (s
)->this_hdr
.sh_flags
7415 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
7420 /* Returns the .msym section for ABFD, creating it if it does not
7421 already exist. Returns NULL to indicate error. */
7424 mips_elf_create_msym_section (abfd
)
7429 s
= bfd_get_section_by_name (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
7432 s
= bfd_make_section (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
7434 || !bfd_set_section_flags (abfd
, s
,
7438 | SEC_LINKER_CREATED
7440 || !bfd_set_section_alignment (abfd
, s
,
7441 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7448 /* Add room for N relocations to the .rel.dyn section in ABFD. */
7451 mips_elf_allocate_dynamic_relocations (abfd
, n
)
7457 s
= bfd_get_section_by_name (abfd
, MIPS_ELF_REL_DYN_SECTION_NAME (abfd
));
7458 BFD_ASSERT (s
!= NULL
);
7460 if (s
->_raw_size
== 0)
7462 /* Make room for a null element. */
7463 s
->_raw_size
+= MIPS_ELF_REL_SIZE (abfd
);
7466 s
->_raw_size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
7469 /* Look through the relocs for a section during the first phase, and
7470 allocate space in the global offset table. */
7473 _bfd_mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
7475 struct bfd_link_info
*info
;
7477 const Elf_Internal_Rela
*relocs
;
7481 Elf_Internal_Shdr
*symtab_hdr
;
7482 struct elf_link_hash_entry
**sym_hashes
;
7483 struct mips_got_info
*g
;
7485 const Elf_Internal_Rela
*rel
;
7486 const Elf_Internal_Rela
*rel_end
;
7489 struct elf_backend_data
*bed
;
7491 if (info
->relocateable
)
7494 dynobj
= elf_hash_table (info
)->dynobj
;
7495 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7496 sym_hashes
= elf_sym_hashes (abfd
);
7497 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
7499 /* Check for the mips16 stub sections. */
7501 name
= bfd_get_section_name (abfd
, sec
);
7502 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
7504 unsigned long r_symndx
;
7506 /* Look at the relocation information to figure out which symbol
7509 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
7511 if (r_symndx
< extsymoff
7512 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
7516 /* This stub is for a local symbol. This stub will only be
7517 needed if there is some relocation in this BFD, other
7518 than a 16 bit function call, which refers to this symbol. */
7519 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
7521 Elf_Internal_Rela
*sec_relocs
;
7522 const Elf_Internal_Rela
*r
, *rend
;
7524 /* We can ignore stub sections when looking for relocs. */
7525 if ((o
->flags
& SEC_RELOC
) == 0
7526 || o
->reloc_count
== 0
7527 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
7528 sizeof FN_STUB
- 1) == 0
7529 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
7530 sizeof CALL_STUB
- 1) == 0
7531 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
7532 sizeof CALL_FP_STUB
- 1) == 0)
7535 sec_relocs
= (_bfd_elf32_link_read_relocs
7536 (abfd
, o
, (PTR
) NULL
,
7537 (Elf_Internal_Rela
*) NULL
,
7538 info
->keep_memory
));
7539 if (sec_relocs
== NULL
)
7542 rend
= sec_relocs
+ o
->reloc_count
;
7543 for (r
= sec_relocs
; r
< rend
; r
++)
7544 if (ELF32_R_SYM (r
->r_info
) == r_symndx
7545 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
7548 if (! info
->keep_memory
)
7557 /* There is no non-call reloc for this stub, so we do
7558 not need it. Since this function is called before
7559 the linker maps input sections to output sections, we
7560 can easily discard it by setting the SEC_EXCLUDE
7562 sec
->flags
|= SEC_EXCLUDE
;
7566 /* Record this stub in an array of local symbol stubs for
7568 if (elf_tdata (abfd
)->local_stubs
== NULL
)
7570 unsigned long symcount
;
7573 if (elf_bad_symtab (abfd
))
7574 symcount
= symtab_hdr
->sh_size
/ symtab_hdr
->sh_entsize
;
7576 symcount
= symtab_hdr
->sh_info
;
7577 n
= (asection
**) bfd_zalloc (abfd
,
7578 symcount
* sizeof (asection
*));
7581 elf_tdata (abfd
)->local_stubs
= n
;
7584 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
7586 /* We don't need to set mips16_stubs_seen in this case.
7587 That flag is used to see whether we need to look through
7588 the global symbol table for stubs. We don't need to set
7589 it here, because we just have a local stub. */
7593 struct mips_elf_link_hash_entry
*h
;
7595 h
= ((struct mips_elf_link_hash_entry
*)
7596 sym_hashes
[r_symndx
- extsymoff
]);
7598 /* H is the symbol this stub is for. */
7601 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
7604 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
7605 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
7607 unsigned long r_symndx
;
7608 struct mips_elf_link_hash_entry
*h
;
7611 /* Look at the relocation information to figure out which symbol
7614 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
7616 if (r_symndx
< extsymoff
7617 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
7619 /* This stub was actually built for a static symbol defined
7620 in the same file. We assume that all static symbols in
7621 mips16 code are themselves mips16, so we can simply
7622 discard this stub. Since this function is called before
7623 the linker maps input sections to output sections, we can
7624 easily discard it by setting the SEC_EXCLUDE flag. */
7625 sec
->flags
|= SEC_EXCLUDE
;
7629 h
= ((struct mips_elf_link_hash_entry
*)
7630 sym_hashes
[r_symndx
- extsymoff
]);
7632 /* H is the symbol this stub is for. */
7634 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
7635 loc
= &h
->call_fp_stub
;
7637 loc
= &h
->call_stub
;
7639 /* If we already have an appropriate stub for this function, we
7640 don't need another one, so we can discard this one. Since
7641 this function is called before the linker maps input sections
7642 to output sections, we can easily discard it by setting the
7643 SEC_EXCLUDE flag. We can also discard this section if we
7644 happen to already know that this is a mips16 function; it is
7645 not necessary to check this here, as it is checked later, but
7646 it is slightly faster to check now. */
7647 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
7649 sec
->flags
|= SEC_EXCLUDE
;
7654 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
7664 sgot
= mips_elf_got_section (dynobj
);
7669 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7670 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7671 BFD_ASSERT (g
!= NULL
);
7676 bed
= get_elf_backend_data (abfd
);
7677 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
7678 for (rel
= relocs
; rel
< rel_end
; ++rel
)
7680 unsigned long r_symndx
;
7682 struct elf_link_hash_entry
*h
;
7684 r_symndx
= ELF32_R_SYM (rel
->r_info
);
7685 r_type
= ELF32_R_TYPE (rel
->r_info
);
7687 if (r_symndx
< extsymoff
)
7689 else if (r_symndx
>= extsymoff
+ (symtab_hdr
->sh_size
/ symtab_hdr
->sh_entsize
))
7691 (*_bfd_error_handler
)
7692 (_("Malformed reloc detected for section %s"), name
);
7693 bfd_set_error (bfd_error_bad_value
);
7698 h
= sym_hashes
[r_symndx
- extsymoff
];
7700 /* This may be an indirect symbol created because of a version. */
7703 while (h
->root
.type
== bfd_link_hash_indirect
)
7704 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7708 /* Some relocs require a global offset table. */
7709 if (dynobj
== NULL
|| sgot
== NULL
)
7715 case R_MIPS_CALL_HI16
:
7716 case R_MIPS_CALL_LO16
:
7717 case R_MIPS_GOT_HI16
:
7718 case R_MIPS_GOT_LO16
:
7719 case R_MIPS_GOT_PAGE
:
7720 case R_MIPS_GOT_OFST
:
7721 case R_MIPS_GOT_DISP
:
7723 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7724 if (! mips_elf_create_got_section (dynobj
, info
))
7726 g
= mips_elf_got_info (dynobj
, &sgot
);
7733 && (info
->shared
|| h
!= NULL
)
7734 && (sec
->flags
& SEC_ALLOC
) != 0)
7735 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7743 if (!h
&& (r_type
== R_MIPS_CALL_LO16
7744 || r_type
== R_MIPS_GOT_LO16
7745 || r_type
== R_MIPS_GOT_DISP
))
7747 /* We may need a local GOT entry for this relocation. We
7748 don't count R_MIPS_GOT_PAGE because we can estimate the
7749 maximum number of pages needed by looking at the size of
7750 the segment. Similar comments apply to R_MIPS_GOT16 and
7751 R_MIPS_CALL16. We don't count R_MIPS_GOT_HI16, or
7752 R_MIPS_CALL_HI16 because these are always followed by an
7753 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16.
7755 This estimation is very conservative since we can merge
7756 duplicate entries in the GOT. In order to be less
7757 conservative, we could actually build the GOT here,
7758 rather than in relocate_section. */
7760 sgot
->_raw_size
+= MIPS_ELF_GOT_SIZE (dynobj
);
7768 (*_bfd_error_handler
)
7769 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
7770 bfd_get_filename (abfd
), (unsigned long) rel
->r_offset
);
7771 bfd_set_error (bfd_error_bad_value
);
7776 case R_MIPS_CALL_HI16
:
7777 case R_MIPS_CALL_LO16
:
7780 /* This symbol requires a global offset table entry. */
7781 if (!mips_elf_record_global_got_symbol (h
, info
, g
))
7784 /* We need a stub, not a plt entry for the undefined
7785 function. But we record it as if it needs plt. See
7786 elf_adjust_dynamic_symbol in elflink.h. */
7787 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
7793 case R_MIPS_GOT_HI16
:
7794 case R_MIPS_GOT_LO16
:
7795 case R_MIPS_GOT_DISP
:
7796 /* This symbol requires a global offset table entry. */
7797 if (h
&& !mips_elf_record_global_got_symbol (h
, info
, g
))
7804 if ((info
->shared
|| h
!= NULL
)
7805 && (sec
->flags
& SEC_ALLOC
) != 0)
7809 const char *name
= MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
);
7811 sreloc
= bfd_get_section_by_name (dynobj
, name
);
7814 sreloc
= bfd_make_section (dynobj
, name
);
7816 || ! bfd_set_section_flags (dynobj
, sreloc
,
7821 | SEC_LINKER_CREATED
7823 || ! bfd_set_section_alignment (dynobj
, sreloc
,
7829 /* When creating a shared object, we must copy these
7830 reloc types into the output file as R_MIPS_REL32
7831 relocs. We make room for this reloc in the
7832 .rel.dyn reloc section. */
7833 mips_elf_allocate_dynamic_relocations (dynobj
, 1);
7836 struct mips_elf_link_hash_entry
*hmips
;
7838 /* We only need to copy this reloc if the symbol is
7839 defined in a dynamic object. */
7840 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7841 ++hmips
->possibly_dynamic_relocs
;
7844 /* Even though we don't directly need a GOT entry for
7845 this symbol, a symbol must have a dynamic symbol
7846 table index greater that DT_MIPS_GOTSYM if there are
7847 dynamic relocations against it. */
7849 && !mips_elf_record_global_got_symbol (h
, info
, g
))
7853 if (SGI_COMPAT (abfd
))
7854 mips_elf_hash_table (info
)->compact_rel_size
+=
7855 sizeof (Elf32_External_crinfo
);
7859 case R_MIPS_GPREL16
:
7860 case R_MIPS_LITERAL
:
7861 case R_MIPS_GPREL32
:
7862 if (SGI_COMPAT (abfd
))
7863 mips_elf_hash_table (info
)->compact_rel_size
+=
7864 sizeof (Elf32_External_crinfo
);
7867 /* This relocation describes the C++ object vtable hierarchy.
7868 Reconstruct it for later use during GC. */
7869 case R_MIPS_GNU_VTINHERIT
:
7870 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
7874 /* This relocation describes which C++ vtable entries are actually
7875 used. Record for later use during GC. */
7876 case R_MIPS_GNU_VTENTRY
:
7877 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
7885 /* We must not create a stub for a symbol that has relocations
7886 related to taking the function's address. */
7892 struct mips_elf_link_hash_entry
*mh
;
7894 mh
= (struct mips_elf_link_hash_entry
*) h
;
7895 mh
->no_fn_stub
= true;
7899 case R_MIPS_CALL_HI16
:
7900 case R_MIPS_CALL_LO16
:
7904 /* If this reloc is not a 16 bit call, and it has a global
7905 symbol, then we will need the fn_stub if there is one.
7906 References from a stub section do not count. */
7908 && r_type
!= R_MIPS16_26
7909 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
7910 sizeof FN_STUB
- 1) != 0
7911 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
7912 sizeof CALL_STUB
- 1) != 0
7913 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
7914 sizeof CALL_FP_STUB
- 1) != 0)
7916 struct mips_elf_link_hash_entry
*mh
;
7918 mh
= (struct mips_elf_link_hash_entry
*) h
;
7919 mh
->need_fn_stub
= true;
7926 /* Return the section that should be marked against GC for a given
7930 _bfd_mips_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
7932 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
7933 Elf_Internal_Rela
*rel
;
7934 struct elf_link_hash_entry
*h
;
7935 Elf_Internal_Sym
*sym
;
7937 /* ??? Do mips16 stub sections need to be handled special? */
7941 switch (ELF32_R_TYPE (rel
->r_info
))
7943 case R_MIPS_GNU_VTINHERIT
:
7944 case R_MIPS_GNU_VTENTRY
:
7948 switch (h
->root
.type
)
7950 case bfd_link_hash_defined
:
7951 case bfd_link_hash_defweak
:
7952 return h
->root
.u
.def
.section
;
7954 case bfd_link_hash_common
:
7955 return h
->root
.u
.c
.p
->section
;
7964 if (!(elf_bad_symtab (abfd
)
7965 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
7966 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
7967 && sym
->st_shndx
!= SHN_COMMON
))
7969 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
7976 /* Update the got entry reference counts for the section being removed. */
7979 _bfd_mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
7980 bfd
*abfd ATTRIBUTE_UNUSED
;
7981 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
7982 asection
*sec ATTRIBUTE_UNUSED
;
7983 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
7986 Elf_Internal_Shdr
*symtab_hdr
;
7987 struct elf_link_hash_entry
**sym_hashes
;
7988 bfd_signed_vma
*local_got_refcounts
;
7989 const Elf_Internal_Rela
*rel
, *relend
;
7990 unsigned long r_symndx
;
7991 struct elf_link_hash_entry
*h
;
7993 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7994 sym_hashes
= elf_sym_hashes (abfd
);
7995 local_got_refcounts
= elf_local_got_refcounts (abfd
);
7997 relend
= relocs
+ sec
->reloc_count
;
7998 for (rel
= relocs
; rel
< relend
; rel
++)
7999 switch (ELF32_R_TYPE (rel
->r_info
))
8003 case R_MIPS_CALL_HI16
:
8004 case R_MIPS_CALL_LO16
:
8005 case R_MIPS_GOT_HI16
:
8006 case R_MIPS_GOT_LO16
:
8007 /* ??? It would seem that the existing MIPS code does no sort
8008 of reference counting or whatnot on its GOT and PLT entries,
8009 so it is not possible to garbage collect them at this time. */
8020 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
8021 hiding the old indirect symbol. Process additional relocation
8025 _bfd_mips_elf_copy_indirect_symbol (dir
, ind
)
8026 struct elf_link_hash_entry
*dir
, *ind
;
8028 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
8030 _bfd_elf_link_hash_copy_indirect (dir
, ind
);
8032 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
8033 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
8034 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
8035 if (dirmips
->min_dyn_reloc_index
== 0
8036 || (indmips
->min_dyn_reloc_index
!= 0
8037 && indmips
->min_dyn_reloc_index
< dirmips
->min_dyn_reloc_index
))
8038 dirmips
->min_dyn_reloc_index
= indmips
->min_dyn_reloc_index
;
8039 if (indmips
->no_fn_stub
)
8040 dirmips
->no_fn_stub
= true;
8043 /* Adjust a symbol defined by a dynamic object and referenced by a
8044 regular object. The current definition is in some section of the
8045 dynamic object, but we're not including those sections. We have to
8046 change the definition to something the rest of the link can
8050 _bfd_mips_elf_adjust_dynamic_symbol (info
, h
)
8051 struct bfd_link_info
*info
;
8052 struct elf_link_hash_entry
*h
;
8055 struct mips_elf_link_hash_entry
*hmips
;
8058 dynobj
= elf_hash_table (info
)->dynobj
;
8060 /* Make sure we know what is going on here. */
8061 BFD_ASSERT (dynobj
!= NULL
8062 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
8063 || h
->weakdef
!= NULL
8064 || ((h
->elf_link_hash_flags
8065 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
8066 && (h
->elf_link_hash_flags
8067 & ELF_LINK_HASH_REF_REGULAR
) != 0
8068 && (h
->elf_link_hash_flags
8069 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
8071 /* If this symbol is defined in a dynamic object, we need to copy
8072 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
8074 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8075 if (! info
->relocateable
8076 && hmips
->possibly_dynamic_relocs
!= 0
8077 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
8078 mips_elf_allocate_dynamic_relocations (dynobj
,
8079 hmips
->possibly_dynamic_relocs
);
8081 /* For a function, create a stub, if allowed. */
8082 if (! hmips
->no_fn_stub
8083 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
8085 if (! elf_hash_table (info
)->dynamic_sections_created
)
8088 /* If this symbol is not defined in a regular file, then set
8089 the symbol to the stub location. This is required to make
8090 function pointers compare as equal between the normal
8091 executable and the shared library. */
8092 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
8094 /* We need .stub section. */
8095 s
= bfd_get_section_by_name (dynobj
,
8096 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
8097 BFD_ASSERT (s
!= NULL
);
8099 h
->root
.u
.def
.section
= s
;
8100 h
->root
.u
.def
.value
= s
->_raw_size
;
8102 /* XXX Write this stub address somewhere. */
8103 h
->plt
.offset
= s
->_raw_size
;
8105 /* Make room for this stub code. */
8106 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
8108 /* The last half word of the stub will be filled with the index
8109 of this symbol in .dynsym section. */
8113 else if ((h
->type
== STT_FUNC
)
8114 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) == 0)
8116 /* This will set the entry for this symbol in the GOT to 0, and
8117 the dynamic linker will take care of this. */
8118 h
->root
.u
.def
.value
= 0;
8122 /* If this is a weak symbol, and there is a real definition, the
8123 processor independent code will have arranged for us to see the
8124 real definition first, and we can just use the same value. */
8125 if (h
->weakdef
!= NULL
)
8127 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
8128 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
8129 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
8130 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
8134 /* This is a reference to a symbol defined by a dynamic object which
8135 is not a function. */
8140 /* This function is called after all the input files have been read,
8141 and the input sections have been assigned to output sections. We
8142 check for any mips16 stub sections that we can discard. */
8144 static boolean mips_elf_check_mips16_stubs
8145 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
8148 _bfd_mips_elf_always_size_sections (output_bfd
, info
)
8150 struct bfd_link_info
*info
;
8154 /* The .reginfo section has a fixed size. */
8155 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
8157 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
8159 if (info
->relocateable
8160 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
8163 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
8164 mips_elf_check_mips16_stubs
,
8170 /* Check the mips16 stubs for a particular symbol, and see if we can
8174 mips_elf_check_mips16_stubs (h
, data
)
8175 struct mips_elf_link_hash_entry
*h
;
8176 PTR data ATTRIBUTE_UNUSED
;
8178 if (h
->fn_stub
!= NULL
8179 && ! h
->need_fn_stub
)
8181 /* We don't need the fn_stub; the only references to this symbol
8182 are 16 bit calls. Clobber the size to 0 to prevent it from
8183 being included in the link. */
8184 h
->fn_stub
->_raw_size
= 0;
8185 h
->fn_stub
->_cooked_size
= 0;
8186 h
->fn_stub
->flags
&= ~SEC_RELOC
;
8187 h
->fn_stub
->reloc_count
= 0;
8188 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
8191 if (h
->call_stub
!= NULL
8192 && h
->root
.other
== STO_MIPS16
)
8194 /* We don't need the call_stub; this is a 16 bit function, so
8195 calls from other 16 bit functions are OK. Clobber the size
8196 to 0 to prevent it from being included in the link. */
8197 h
->call_stub
->_raw_size
= 0;
8198 h
->call_stub
->_cooked_size
= 0;
8199 h
->call_stub
->flags
&= ~SEC_RELOC
;
8200 h
->call_stub
->reloc_count
= 0;
8201 h
->call_stub
->flags
|= SEC_EXCLUDE
;
8204 if (h
->call_fp_stub
!= NULL
8205 && h
->root
.other
== STO_MIPS16
)
8207 /* We don't need the call_stub; this is a 16 bit function, so
8208 calls from other 16 bit functions are OK. Clobber the size
8209 to 0 to prevent it from being included in the link. */
8210 h
->call_fp_stub
->_raw_size
= 0;
8211 h
->call_fp_stub
->_cooked_size
= 0;
8212 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
8213 h
->call_fp_stub
->reloc_count
= 0;
8214 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
8220 /* Set the sizes of the dynamic sections. */
8223 _bfd_mips_elf_size_dynamic_sections (output_bfd
, info
)
8225 struct bfd_link_info
*info
;
8230 struct mips_got_info
*g
= NULL
;
8232 dynobj
= elf_hash_table (info
)->dynobj
;
8233 BFD_ASSERT (dynobj
!= NULL
);
8235 if (elf_hash_table (info
)->dynamic_sections_created
)
8237 /* Set the contents of the .interp section to the interpreter. */
8240 s
= bfd_get_section_by_name (dynobj
, ".interp");
8241 BFD_ASSERT (s
!= NULL
);
8243 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
8245 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
8249 /* The check_relocs and adjust_dynamic_symbol entry points have
8250 determined the sizes of the various dynamic sections. Allocate
8253 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8258 /* It's OK to base decisions on the section name, because none
8259 of the dynobj section names depend upon the input files. */
8260 name
= bfd_get_section_name (dynobj
, s
);
8262 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8267 if (strncmp (name
, ".rel", 4) == 0)
8269 if (s
->_raw_size
== 0)
8271 /* We only strip the section if the output section name
8272 has the same name. Otherwise, there might be several
8273 input sections for this output section. FIXME: This
8274 code is probably not needed these days anyhow, since
8275 the linker now does not create empty output sections. */
8276 if (s
->output_section
!= NULL
8278 bfd_get_section_name (s
->output_section
->owner
,
8279 s
->output_section
)) == 0)
8284 const char *outname
;
8287 /* If this relocation section applies to a read only
8288 section, then we probably need a DT_TEXTREL entry.
8289 If the relocation section is .rel.dyn, we always
8290 assert a DT_TEXTREL entry rather than testing whether
8291 there exists a relocation to a read only section or
8293 outname
= bfd_get_section_name (output_bfd
,
8295 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
8297 && (target
->flags
& SEC_READONLY
) != 0
8298 && (target
->flags
& SEC_ALLOC
) != 0)
8300 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd
)) == 0)
8303 /* We use the reloc_count field as a counter if we need
8304 to copy relocs into the output file. */
8306 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd
)) != 0)
8310 else if (strncmp (name
, ".got", 4) == 0)
8313 bfd_size_type loadable_size
= 0;
8314 bfd_size_type local_gotno
;
8317 BFD_ASSERT (elf_section_data (s
) != NULL
);
8318 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
8319 BFD_ASSERT (g
!= NULL
);
8321 /* Calculate the total loadable size of the output. That
8322 will give us the maximum number of GOT_PAGE entries
8324 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
8326 asection
*subsection
;
8328 for (subsection
= sub
->sections
;
8330 subsection
= subsection
->next
)
8332 if ((subsection
->flags
& SEC_ALLOC
) == 0)
8334 loadable_size
+= (subsection
->_raw_size
+ 0xf) & ~0xf;
8337 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
8339 /* Assume there are two loadable segments consisting of
8340 contiguous sections. Is 5 enough? */
8341 local_gotno
= (loadable_size
>> 16) + 5;
8342 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
8343 /* It's possible we will need GOT_PAGE entries as well as
8344 GOT16 entries. Often, these will be able to share GOT
8345 entries, but not always. */
8348 g
->local_gotno
+= local_gotno
;
8349 s
->_raw_size
+= local_gotno
* MIPS_ELF_GOT_SIZE (dynobj
);
8351 /* There has to be a global GOT entry for every symbol with
8352 a dynamic symbol table index of DT_MIPS_GOTSYM or
8353 higher. Therefore, it make sense to put those symbols
8354 that need GOT entries at the end of the symbol table. We
8356 if (!mips_elf_sort_hash_table (info
, 1))
8359 if (g
->global_gotsym
!= NULL
)
8360 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
8362 /* If there are no global symbols, or none requiring
8363 relocations, then GLOBAL_GOTSYM will be NULL. */
8365 g
->global_gotno
= i
;
8366 s
->_raw_size
+= i
* MIPS_ELF_GOT_SIZE (dynobj
);
8368 else if (strcmp (name
, MIPS_ELF_STUB_SECTION_NAME (output_bfd
)) == 0)
8370 /* Irix rld assumes that the function stub isn't at the end
8371 of .text section. So put a dummy. XXX */
8372 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
8374 else if (! info
->shared
8375 && ! mips_elf_hash_table (info
)->use_rld_obj_head
8376 && strncmp (name
, ".rld_map", 8) == 0)
8378 /* We add a room for __rld_map. It will be filled in by the
8379 rtld to contain a pointer to the _r_debug structure. */
8382 else if (SGI_COMPAT (output_bfd
)
8383 && strncmp (name
, ".compact_rel", 12) == 0)
8384 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
8385 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
))
8387 s
->_raw_size
= (sizeof (Elf32_External_Msym
)
8388 * (elf_hash_table (info
)->dynsymcount
8389 + bfd_count_sections (output_bfd
)));
8390 else if (strncmp (name
, ".init", 5) != 0)
8392 /* It's not one of our sections, so don't allocate space. */
8398 _bfd_strip_section_from_output (info
, s
);
8402 /* Allocate memory for the section contents. */
8403 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
8404 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
8406 bfd_set_error (bfd_error_no_memory
);
8411 if (elf_hash_table (info
)->dynamic_sections_created
)
8413 /* Add some entries to the .dynamic section. We fill in the
8414 values later, in elf_mips_finish_dynamic_sections, but we
8415 must add the entries now so that we get the correct size for
8416 the .dynamic section. The DT_DEBUG entry is filled in by the
8417 dynamic linker and used by the debugger. */
8420 /* SGI object has the equivalence of DT_DEBUG in the
8421 DT_MIPS_RLD_MAP entry. */
8422 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
8424 if (!SGI_COMPAT (output_bfd
))
8426 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
8432 /* Shared libraries on traditional mips have DT_DEBUG. */
8433 if (!SGI_COMPAT (output_bfd
))
8435 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
8439 if (reltext
&& SGI_COMPAT (output_bfd
))
8441 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
8443 info
->flags
|= DF_TEXTREL
;
8446 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
8449 if (bfd_get_section_by_name (dynobj
,
8450 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
)))
8452 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
8455 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
8458 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
8462 if (SGI_COMPAT (output_bfd
))
8464 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICTNO
, 0))
8468 if (SGI_COMPAT (output_bfd
))
8470 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLISTNO
, 0))
8474 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
8476 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICT
, 0))
8479 s
= bfd_get_section_by_name (dynobj
, ".liblist");
8480 BFD_ASSERT (s
!= NULL
);
8482 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLIST
, 0))
8486 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
8489 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
8493 /* Time stamps in executable files are a bad idea. */
8494 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_TIME_STAMP
, 0))
8499 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_ICHECKSUM
, 0))
8504 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_IVERSION
, 0))
8508 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
8511 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
8514 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
8517 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
8520 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
8523 if (IRIX_COMPAT (dynobj
) == ict_irix5
8524 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
8527 if (IRIX_COMPAT (dynobj
) == ict_irix6
8528 && (bfd_get_section_by_name
8529 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
8530 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
8533 if (bfd_get_section_by_name (dynobj
,
8534 MIPS_ELF_MSYM_SECTION_NAME (dynobj
))
8535 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_MSYM
, 0))
8542 /* If NAME is one of the special IRIX6 symbols defined by the linker,
8543 adjust it appropriately now. */
8546 mips_elf_irix6_finish_dynamic_symbol (abfd
, name
, sym
)
8547 bfd
*abfd ATTRIBUTE_UNUSED
;
8549 Elf_Internal_Sym
*sym
;
8551 /* The linker script takes care of providing names and values for
8552 these, but we must place them into the right sections. */
8553 static const char* const text_section_symbols
[] = {
8556 "__dso_displacement",
8558 "__program_header_table",
8562 static const char* const data_section_symbols
[] = {
8570 const char* const *p
;
8573 for (i
= 0; i
< 2; ++i
)
8574 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
8577 if (strcmp (*p
, name
) == 0)
8579 /* All of these symbols are given type STT_SECTION by the
8581 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8583 /* The IRIX linker puts these symbols in special sections. */
8585 sym
->st_shndx
= SHN_MIPS_TEXT
;
8587 sym
->st_shndx
= SHN_MIPS_DATA
;
8593 /* Finish up dynamic symbol handling. We set the contents of various
8594 dynamic sections here. */
8597 _bfd_mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
8599 struct bfd_link_info
*info
;
8600 struct elf_link_hash_entry
*h
;
8601 Elf_Internal_Sym
*sym
;
8607 struct mips_got_info
*g
;
8609 struct mips_elf_link_hash_entry
*mh
;
8611 dynobj
= elf_hash_table (info
)->dynobj
;
8612 gval
= sym
->st_value
;
8613 mh
= (struct mips_elf_link_hash_entry
*) h
;
8615 if (h
->plt
.offset
!= (bfd_vma
) -1)
8619 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
8621 /* This symbol has a stub. Set it up. */
8623 BFD_ASSERT (h
->dynindx
!= -1);
8625 s
= bfd_get_section_by_name (dynobj
,
8626 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
8627 BFD_ASSERT (s
!= NULL
);
8629 /* Fill the stub. */
8631 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), p
);
8633 bfd_put_32 (output_bfd
, STUB_MOVE (output_bfd
), p
);
8636 /* FIXME: Can h->dynindex be more than 64K? */
8637 if (h
->dynindx
& 0xffff0000)
8640 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
8642 bfd_put_32 (output_bfd
, STUB_LI16 (output_bfd
) + h
->dynindx
, p
);
8644 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
8645 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
8647 /* Mark the symbol as undefined. plt.offset != -1 occurs
8648 only for the referenced symbol. */
8649 sym
->st_shndx
= SHN_UNDEF
;
8651 /* The run-time linker uses the st_value field of the symbol
8652 to reset the global offset table entry for this external
8653 to its stub address when unlinking a shared object. */
8654 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
8655 sym
->st_value
= gval
;
8658 BFD_ASSERT (h
->dynindx
!= -1
8659 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0);
8661 sgot
= mips_elf_got_section (dynobj
);
8662 BFD_ASSERT (sgot
!= NULL
);
8663 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
8664 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
8665 BFD_ASSERT (g
!= NULL
);
8667 /* Run through the global symbol table, creating GOT entries for all
8668 the symbols that need them. */
8669 if (g
->global_gotsym
!= NULL
8670 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
8676 value
= sym
->st_value
;
8679 /* For an entity defined in a shared object, this will be
8680 NULL. (For functions in shared objects for
8681 which we have created stubs, ST_VALUE will be non-NULL.
8682 That's because such the functions are now no longer defined
8683 in a shared object.) */
8685 if (info
->shared
&& h
->root
.type
== bfd_link_hash_undefined
)
8688 value
= h
->root
.u
.def
.value
;
8690 offset
= mips_elf_global_got_index (dynobj
, h
);
8691 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
8694 /* Create a .msym entry, if appropriate. */
8695 smsym
= bfd_get_section_by_name (dynobj
,
8696 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
8699 Elf32_Internal_Msym msym
;
8701 msym
.ms_hash_value
= bfd_elf_hash (h
->root
.root
.string
);
8702 /* It is undocumented what the `1' indicates, but IRIX6 uses
8704 msym
.ms_info
= ELF32_MS_INFO (mh
->min_dyn_reloc_index
, 1);
8705 bfd_mips_elf_swap_msym_out
8707 ((Elf32_External_Msym
*) smsym
->contents
) + h
->dynindx
);
8710 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
8711 name
= h
->root
.root
.string
;
8712 if (strcmp (name
, "_DYNAMIC") == 0
8713 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
8714 sym
->st_shndx
= SHN_ABS
;
8715 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
8716 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
8718 sym
->st_shndx
= SHN_ABS
;
8719 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8722 else if (strcmp (name
, "_gp_disp") == 0)
8724 sym
->st_shndx
= SHN_ABS
;
8725 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8726 sym
->st_value
= elf_gp (output_bfd
);
8728 else if (SGI_COMPAT (output_bfd
))
8730 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
8731 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
8733 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8734 sym
->st_other
= STO_PROTECTED
;
8736 sym
->st_shndx
= SHN_MIPS_DATA
;
8738 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
8740 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8741 sym
->st_other
= STO_PROTECTED
;
8742 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
8743 sym
->st_shndx
= SHN_ABS
;
8745 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
8747 if (h
->type
== STT_FUNC
)
8748 sym
->st_shndx
= SHN_MIPS_TEXT
;
8749 else if (h
->type
== STT_OBJECT
)
8750 sym
->st_shndx
= SHN_MIPS_DATA
;
8754 /* Handle the IRIX6-specific symbols. */
8755 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
8756 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
8760 if (! mips_elf_hash_table (info
)->use_rld_obj_head
8761 && (strcmp (name
, "__rld_map") == 0
8762 || strcmp (name
, "__RLD_MAP") == 0))
8764 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
8765 BFD_ASSERT (s
!= NULL
);
8766 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
8767 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
8768 if (mips_elf_hash_table (info
)->rld_value
== 0)
8769 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
8771 else if (mips_elf_hash_table (info
)->use_rld_obj_head
8772 && strcmp (name
, "__rld_obj_head") == 0)
8774 /* IRIX6 does not use a .rld_map section. */
8775 if (IRIX_COMPAT (output_bfd
) == ict_irix5
8776 || IRIX_COMPAT (output_bfd
) == ict_none
)
8777 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
8779 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
8783 /* If this is a mips16 symbol, force the value to be even. */
8784 if (sym
->st_other
== STO_MIPS16
8785 && (sym
->st_value
& 1) != 0)
8791 /* Finish up the dynamic sections. */
8794 _bfd_mips_elf_finish_dynamic_sections (output_bfd
, info
)
8796 struct bfd_link_info
*info
;
8801 struct mips_got_info
*g
;
8803 dynobj
= elf_hash_table (info
)->dynobj
;
8805 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
8807 sgot
= mips_elf_got_section (dynobj
);
8812 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
8813 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
8814 BFD_ASSERT (g
!= NULL
);
8817 if (elf_hash_table (info
)->dynamic_sections_created
)
8821 BFD_ASSERT (sdyn
!= NULL
);
8822 BFD_ASSERT (g
!= NULL
);
8824 for (b
= sdyn
->contents
;
8825 b
< sdyn
->contents
+ sdyn
->_raw_size
;
8826 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
8828 Elf_Internal_Dyn dyn
;
8834 /* Read in the current dynamic entry. */
8835 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
8837 /* Assume that we're going to modify it and write it out. */
8843 s
= (bfd_get_section_by_name
8845 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
)));
8846 BFD_ASSERT (s
!= NULL
);
8847 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
8851 /* Rewrite DT_STRSZ. */
8853 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
8859 case DT_MIPS_CONFLICT
:
8862 case DT_MIPS_LIBLIST
:
8865 s
= bfd_get_section_by_name (output_bfd
, name
);
8866 BFD_ASSERT (s
!= NULL
);
8867 dyn
.d_un
.d_ptr
= s
->vma
;
8870 case DT_MIPS_RLD_VERSION
:
8871 dyn
.d_un
.d_val
= 1; /* XXX */
8875 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
8878 case DT_MIPS_CONFLICTNO
:
8880 elemsize
= sizeof (Elf32_Conflict
);
8883 case DT_MIPS_LIBLISTNO
:
8885 elemsize
= sizeof (Elf32_Lib
);
8887 s
= bfd_get_section_by_name (output_bfd
, name
);
8890 if (s
->_cooked_size
!= 0)
8891 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
8893 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
8899 case DT_MIPS_TIME_STAMP
:
8900 time ((time_t *) &dyn
.d_un
.d_val
);
8903 case DT_MIPS_ICHECKSUM
:
8908 case DT_MIPS_IVERSION
:
8913 case DT_MIPS_BASE_ADDRESS
:
8914 s
= output_bfd
->sections
;
8915 BFD_ASSERT (s
!= NULL
);
8916 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
8919 case DT_MIPS_LOCAL_GOTNO
:
8920 dyn
.d_un
.d_val
= g
->local_gotno
;
8923 case DT_MIPS_UNREFEXTNO
:
8924 /* The index into the dynamic symbol table which is the
8925 entry of the first external symbol that is not
8926 referenced within the same object. */
8927 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
8930 case DT_MIPS_GOTSYM
:
8931 if (g
->global_gotsym
)
8933 dyn
.d_un
.d_val
= g
->global_gotsym
->dynindx
;
8936 /* In case if we don't have global got symbols we default
8937 to setting DT_MIPS_GOTSYM to the same value as
8938 DT_MIPS_SYMTABNO, so we just fall through. */
8940 case DT_MIPS_SYMTABNO
:
8942 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
8943 s
= bfd_get_section_by_name (output_bfd
, name
);
8944 BFD_ASSERT (s
!= NULL
);
8946 if (s
->_cooked_size
!= 0)
8947 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
8949 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
8952 case DT_MIPS_HIPAGENO
:
8953 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
8956 case DT_MIPS_RLD_MAP
:
8957 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
8960 case DT_MIPS_OPTIONS
:
8961 s
= (bfd_get_section_by_name
8962 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
8963 dyn
.d_un
.d_ptr
= s
->vma
;
8967 s
= (bfd_get_section_by_name
8968 (output_bfd
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
)));
8969 dyn
.d_un
.d_ptr
= s
->vma
;
8978 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
8983 /* The first entry of the global offset table will be filled at
8984 runtime. The second entry will be used by some runtime loaders.
8985 This isn't the case of Irix rld. */
8986 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
8988 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
8989 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0x80000000,
8990 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
8994 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
8995 = MIPS_ELF_GOT_SIZE (output_bfd
);
9000 Elf32_compact_rel cpt
;
9002 /* ??? The section symbols for the output sections were set up in
9003 _bfd_elf_final_link. SGI sets the STT_NOTYPE attribute for these
9004 symbols. Should we do so? */
9006 smsym
= bfd_get_section_by_name (dynobj
,
9007 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
9010 Elf32_Internal_Msym msym
;
9012 msym
.ms_hash_value
= 0;
9013 msym
.ms_info
= ELF32_MS_INFO (0, 1);
9015 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
9017 long dynindx
= elf_section_data (s
)->dynindx
;
9019 bfd_mips_elf_swap_msym_out
9021 (((Elf32_External_Msym
*) smsym
->contents
)
9026 if (SGI_COMPAT (output_bfd
))
9028 /* Write .compact_rel section out. */
9029 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
9033 cpt
.num
= s
->reloc_count
;
9035 cpt
.offset
= (s
->output_section
->filepos
9036 + sizeof (Elf32_External_compact_rel
));
9039 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
9040 ((Elf32_External_compact_rel
*)
9043 /* Clean up a dummy stub function entry in .text. */
9044 s
= bfd_get_section_by_name (dynobj
,
9045 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
9048 file_ptr dummy_offset
;
9050 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
9051 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
9052 memset (s
->contents
+ dummy_offset
, 0,
9053 MIPS_FUNCTION_STUB_SIZE
);
9058 /* We need to sort the entries of the dynamic relocation section. */
9060 if (!ABI_64_P (output_bfd
))
9064 reldyn
= bfd_get_section_by_name (dynobj
,
9065 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
));
9066 if (reldyn
!= NULL
&& reldyn
->reloc_count
> 2)
9068 reldyn_sorting_bfd
= output_bfd
;
9069 qsort ((Elf32_External_Rel
*) reldyn
->contents
+ 1,
9070 (size_t) reldyn
->reloc_count
- 1,
9071 sizeof (Elf32_External_Rel
), sort_dynamic_relocs
);
9075 /* Clean up a first relocation in .rel.dyn. */
9076 s
= bfd_get_section_by_name (dynobj
,
9077 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj
));
9078 if (s
!= NULL
&& s
->_raw_size
> 0)
9079 memset (s
->contents
, 0, MIPS_ELF_REL_SIZE (dynobj
));
9085 /* This is almost identical to bfd_generic_get_... except that some
9086 MIPS relocations need to be handled specially. Sigh. */
9089 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
9090 relocateable
, symbols
)
9092 struct bfd_link_info
*link_info
;
9093 struct bfd_link_order
*link_order
;
9095 boolean relocateable
;
9098 /* Get enough memory to hold the stuff */
9099 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
9100 asection
*input_section
= link_order
->u
.indirect
.section
;
9102 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
9103 arelent
**reloc_vector
= NULL
;
9109 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
9110 if (reloc_vector
== NULL
&& reloc_size
!= 0)
9113 /* read in the section */
9114 if (!bfd_get_section_contents (input_bfd
,
9118 input_section
->_raw_size
))
9121 /* We're not relaxing the section, so just copy the size info */
9122 input_section
->_cooked_size
= input_section
->_raw_size
;
9123 input_section
->reloc_done
= true;
9125 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
9129 if (reloc_count
< 0)
9132 if (reloc_count
> 0)
9137 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
9140 struct bfd_hash_entry
*h
;
9141 struct bfd_link_hash_entry
*lh
;
9142 /* Skip all this stuff if we aren't mixing formats. */
9143 if (abfd
&& input_bfd
9144 && abfd
->xvec
== input_bfd
->xvec
)
9148 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
9149 lh
= (struct bfd_link_hash_entry
*) h
;
9156 case bfd_link_hash_undefined
:
9157 case bfd_link_hash_undefweak
:
9158 case bfd_link_hash_common
:
9161 case bfd_link_hash_defined
:
9162 case bfd_link_hash_defweak
:
9164 gp
= lh
->u
.def
.value
;
9166 case bfd_link_hash_indirect
:
9167 case bfd_link_hash_warning
:
9169 /* @@FIXME ignoring warning for now */
9171 case bfd_link_hash_new
:
9180 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
9183 char *error_message
= (char *) NULL
;
9184 bfd_reloc_status_type r
;
9186 /* Specific to MIPS: Deal with relocation types that require
9187 knowing the gp of the output bfd. */
9188 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
9189 if (bfd_is_abs_section (sym
->section
) && abfd
)
9191 /* The special_function wouldn't get called anyways. */
9195 /* The gp isn't there; let the special function code
9196 fall over on its own. */
9198 else if ((*parent
)->howto
->special_function
9199 == _bfd_mips_elf_gprel16_reloc
)
9201 /* bypass special_function call */
9202 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
9203 relocateable
, (PTR
) data
, gp
);
9204 goto skip_bfd_perform_relocation
;
9206 /* end mips specific stuff */
9208 r
= bfd_perform_relocation (input_bfd
,
9212 relocateable
? abfd
: (bfd
*) NULL
,
9214 skip_bfd_perform_relocation
:
9218 asection
*os
= input_section
->output_section
;
9220 /* A partial link, so keep the relocs */
9221 os
->orelocation
[os
->reloc_count
] = *parent
;
9225 if (r
!= bfd_reloc_ok
)
9229 case bfd_reloc_undefined
:
9230 if (!((*link_info
->callbacks
->undefined_symbol
)
9231 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
9232 input_bfd
, input_section
, (*parent
)->address
,
9236 case bfd_reloc_dangerous
:
9237 BFD_ASSERT (error_message
!= (char *) NULL
);
9238 if (!((*link_info
->callbacks
->reloc_dangerous
)
9239 (link_info
, error_message
, input_bfd
, input_section
,
9240 (*parent
)->address
)))
9243 case bfd_reloc_overflow
:
9244 if (!((*link_info
->callbacks
->reloc_overflow
)
9245 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
9246 (*parent
)->howto
->name
, (*parent
)->addend
,
9247 input_bfd
, input_section
, (*parent
)->address
)))
9250 case bfd_reloc_outofrange
:
9259 if (reloc_vector
!= NULL
)
9260 free (reloc_vector
);
9264 if (reloc_vector
!= NULL
)
9265 free (reloc_vector
);
9269 #define bfd_elf32_bfd_get_relocated_section_contents \
9270 elf32_mips_get_relocated_section_contents
9272 /* ECOFF swapping routines. These are used when dealing with the
9273 .mdebug section, which is in the ECOFF debugging format. */
9274 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
= {
9275 /* Symbol table magic number. */
9277 /* Alignment of debugging information. E.g., 4. */
9279 /* Sizes of external symbolic information. */
9280 sizeof (struct hdr_ext
),
9281 sizeof (struct dnr_ext
),
9282 sizeof (struct pdr_ext
),
9283 sizeof (struct sym_ext
),
9284 sizeof (struct opt_ext
),
9285 sizeof (struct fdr_ext
),
9286 sizeof (struct rfd_ext
),
9287 sizeof (struct ext_ext
),
9288 /* Functions to swap in external symbolic data. */
9297 _bfd_ecoff_swap_tir_in
,
9298 _bfd_ecoff_swap_rndx_in
,
9299 /* Functions to swap out external symbolic data. */
9308 _bfd_ecoff_swap_tir_out
,
9309 _bfd_ecoff_swap_rndx_out
,
9310 /* Function to read in symbolic data. */
9311 _bfd_mips_elf_read_ecoff_info
9314 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
9315 #define TARGET_LITTLE_NAME "elf32-littlemips"
9316 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
9317 #define TARGET_BIG_NAME "elf32-bigmips"
9318 #define ELF_ARCH bfd_arch_mips
9319 #define ELF_MACHINE_CODE EM_MIPS
9321 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
9322 a value of 0x1000, and we are compatible. */
9323 #define ELF_MAXPAGESIZE 0x1000
9325 #define elf_backend_collect true
9326 #define elf_backend_type_change_ok true
9327 #define elf_backend_can_gc_sections true
9328 #define elf_backend_sign_extend_vma true
9329 #define elf_info_to_howto mips_info_to_howto_rela
9330 #define elf_info_to_howto_rel mips_info_to_howto_rel
9331 #define elf_backend_sym_is_global mips_elf_sym_is_global
9332 #define elf_backend_object_p _bfd_mips_elf_object_p
9333 #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
9334 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
9335 #define elf_backend_section_from_bfd_section \
9336 _bfd_mips_elf_section_from_bfd_section
9337 #define elf_backend_section_processing _bfd_mips_elf_section_processing
9338 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
9339 #define elf_backend_additional_program_headers \
9340 _bfd_mips_elf_additional_program_headers
9341 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
9342 #define elf_backend_final_write_processing \
9343 _bfd_mips_elf_final_write_processing
9344 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
9345 #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
9346 #define elf_backend_create_dynamic_sections \
9347 _bfd_mips_elf_create_dynamic_sections
9348 #define elf_backend_check_relocs _bfd_mips_elf_check_relocs
9349 #define elf_backend_adjust_dynamic_symbol \
9350 _bfd_mips_elf_adjust_dynamic_symbol
9351 #define elf_backend_always_size_sections \
9352 _bfd_mips_elf_always_size_sections
9353 #define elf_backend_size_dynamic_sections \
9354 _bfd_mips_elf_size_dynamic_sections
9355 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section
9356 #define elf_backend_link_output_symbol_hook \
9357 _bfd_mips_elf_link_output_symbol_hook
9358 #define elf_backend_finish_dynamic_symbol \
9359 _bfd_mips_elf_finish_dynamic_symbol
9360 #define elf_backend_finish_dynamic_sections \
9361 _bfd_mips_elf_finish_dynamic_sections
9362 #define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
9363 #define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
9365 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
9366 #define elf_backend_plt_header_size 0
9368 #define elf_backend_copy_indirect_symbol \
9369 _bfd_mips_elf_copy_indirect_symbol
9371 #define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
9373 #define bfd_elf32_bfd_is_local_label_name \
9374 mips_elf_is_local_label_name
9375 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
9376 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
9377 #define bfd_elf32_bfd_link_hash_table_create \
9378 _bfd_mips_elf_link_hash_table_create
9379 #define bfd_elf32_bfd_final_link _bfd_mips_elf_final_link
9380 #define bfd_elf32_bfd_copy_private_bfd_data \
9381 _bfd_mips_elf_copy_private_bfd_data
9382 #define bfd_elf32_bfd_merge_private_bfd_data \
9383 _bfd_mips_elf_merge_private_bfd_data
9384 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
9385 #define bfd_elf32_bfd_print_private_bfd_data \
9386 _bfd_mips_elf_print_private_bfd_data
9387 #include "elf32-target.h"
9389 /* Support for traditional mips targets */
9391 #define INCLUDED_TARGET_FILE /* More a type of flag */
9393 #undef TARGET_LITTLE_SYM
9394 #undef TARGET_LITTLE_NAME
9395 #undef TARGET_BIG_SYM
9396 #undef TARGET_BIG_NAME
9398 #define TARGET_LITTLE_SYM bfd_elf32_tradlittlemips_vec
9399 #define TARGET_LITTLE_NAME "elf32-tradlittlemips"
9400 #define TARGET_BIG_SYM bfd_elf32_tradbigmips_vec
9401 #define TARGET_BIG_NAME "elf32-tradbigmips"
9403 /* Include the target file again for this target */
9404 #include "elf32-target.h"