1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 94, 95, 96, 97, 98, 1999 Free Software Foundation, Inc.
4 Most of the information added by Ian Lance Taylor, Cygnus Support,
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 /* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
24 different MIPS ELF from other targets. This matters when linking.
25 This file supports both, switching at runtime. */
35 /* Get the ECOFF swapping routines. */
37 #include "coff/symconst.h"
38 #include "coff/internal.h"
39 #include "coff/ecoff.h"
40 #include "coff/mips.h"
42 #include "ecoffswap.h"
44 /* This structure is used to hold .got information when linking. It
45 is stored in the tdata field of the bfd_elf_section_data structure. */
49 /* The global symbol in the GOT with the lowest index in the dynamic
51 struct elf_link_hash_entry
*global_gotsym
;
52 /* The number of local .got entries. */
53 unsigned int local_gotno
;
54 /* The number of local .got entries we have used. */
55 unsigned int assigned_gotno
;
58 /* The MIPS ELF linker needs additional information for each symbol in
59 the global hash table. */
61 struct mips_elf_link_hash_entry
63 struct elf_link_hash_entry root
;
65 /* External symbol information. */
68 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
69 unsigned int mips_32_relocs
;
71 /* The index of the first dynamic relocation (in the .rel.dyn
72 section) against this symbol. */
73 unsigned int min_dyn_reloc_index
;
75 /* If there is a stub that 32 bit functions should use to call this
76 16 bit function, this points to the section containing the stub. */
79 /* Whether we need the fn_stub; this is set if this symbol appears
80 in any relocs other than a 16 bit call. */
83 /* If there is a stub that 16 bit functions should use to call this
84 32 bit function, this points to the section containing the stub. */
87 /* This is like the call_stub field, but it is used if the function
88 being called returns a floating point value. */
89 asection
*call_fp_stub
;
92 static bfd_reloc_status_type mips32_64bit_reloc
93 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
94 static reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
95 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
96 static void mips_info_to_howto_rel
97 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
98 static void mips_info_to_howto_rela
99 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rela
*));
100 static void bfd_mips_elf32_swap_gptab_in
101 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
102 static void bfd_mips_elf32_swap_gptab_out
103 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
104 static void bfd_mips_elf_swap_msym_in
105 PARAMS ((bfd
*, const Elf32_External_Msym
*, Elf32_Internal_Msym
*));
106 static void bfd_mips_elf_swap_msym_out
107 PARAMS ((bfd
*, const Elf32_Internal_Msym
*, Elf32_External_Msym
*));
108 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
109 static boolean mips_elf32_object_p
PARAMS ((bfd
*));
110 static boolean mips_elf_create_procedure_table
111 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
112 struct ecoff_debug_info
*));
113 static int mips_elf_additional_program_headers
PARAMS ((bfd
*));
114 static boolean mips_elf_modify_segment_map
PARAMS ((bfd
*));
115 static INLINE
int elf_mips_isa
PARAMS ((flagword
));
116 static INLINE
int elf_mips_mach
PARAMS ((flagword
));
117 static INLINE
char* elf_mips_abi_name
PARAMS ((flagword
));
118 static boolean mips_elf32_section_from_shdr
119 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, char *));
120 static boolean mips_elf32_section_processing
121 PARAMS ((bfd
*, Elf32_Internal_Shdr
*));
122 static boolean mips_elf_is_local_label_name
123 PARAMS ((bfd
*, const char *));
124 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
125 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
126 static struct bfd_link_hash_table
*mips_elf_link_hash_table_create
128 static int gptab_compare
PARAMS ((const void *, const void *));
129 static boolean mips_elf_final_link
130 PARAMS ((bfd
*, struct bfd_link_info
*));
131 static void mips_elf_relocate_hi16
132 PARAMS ((bfd
*, Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_byte
*,
134 static boolean mips_elf_relocate_got_local
135 PARAMS ((bfd
*, bfd
*, asection
*, Elf_Internal_Rela
*,
136 Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
137 static void mips_elf_relocate_global_got
138 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
139 static bfd_reloc_status_type mips16_jump_reloc
140 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
141 static bfd_reloc_status_type mips16_gprel_reloc
142 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
143 static boolean mips_elf_relocate_section
144 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
145 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
146 static boolean mips_elf_link_output_symbol_hook
147 PARAMS ((bfd
*, struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
149 static boolean mips_elf_create_dynamic_sections
150 PARAMS ((bfd
*, struct bfd_link_info
*));
151 static boolean mips_elf_create_compact_rel_section
152 PARAMS ((bfd
*, struct bfd_link_info
*));
153 static boolean mips_elf_create_got_section
154 PARAMS ((bfd
*, struct bfd_link_info
*));
155 static boolean mips_elf_check_relocs
156 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
157 const Elf_Internal_Rela
*));
158 static boolean mips_elf_adjust_dynamic_symbol
159 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
160 static boolean mips_elf_always_size_sections
161 PARAMS ((bfd
*, struct bfd_link_info
*));
162 static boolean mips_elf_size_dynamic_sections
163 PARAMS ((bfd
*, struct bfd_link_info
*));
164 static boolean mips_elf_finish_dynamic_symbol
165 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
166 Elf_Internal_Sym
*));
167 static boolean mips_elf_finish_dynamic_sections
168 PARAMS ((bfd
*, struct bfd_link_info
*));
169 static boolean mips_elf_add_symbol_hook
170 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
171 const char **, flagword
*, asection
**, bfd_vma
*));
172 static bfd_reloc_status_type mips_elf_final_gp
173 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
174 static bfd_byte
*elf32_mips_get_relocated_section_contents
175 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
176 bfd_byte
*, boolean
, asymbol
**));
177 static asection
*mips_elf_create_msym_section
179 static void mips_elf_irix6_finish_dynamic_symbol
180 PARAMS ((bfd
*, const char *, Elf_Internal_Sym
*));
181 static bfd_vma mips_elf_sign_extend
PARAMS ((bfd_vma
, int));
182 static boolean mips_elf_overflow_p
PARAMS ((bfd_vma
, int));
183 static bfd_vma mips_elf_high
PARAMS ((bfd_vma
));
184 static bfd_vma mips_elf_higher
PARAMS ((bfd_vma
));
185 static bfd_vma mips_elf_highest
PARAMS ((bfd_vma
));
186 static bfd_vma mips_elf_global_got_index
187 PARAMS ((bfd
*, struct elf_link_hash_entry
*));
188 static bfd_vma mips_elf_local_got_index
189 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
));
190 static bfd_vma mips_elf_got_offset_from_index
191 PARAMS ((bfd
*, bfd
*, bfd_vma
));
192 static boolean mips_elf_record_global_got_symbol
193 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*,
194 struct mips_got_info
*));
195 static bfd_vma mips_elf_got_page
196 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
, bfd_vma
*));
197 static boolean mips_elf_next_lo16_addend
198 PARAMS ((Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_vma
*));
199 static bfd_reloc_status_type mips_elf_calculate_relocation
200 PARAMS ((bfd
*, bfd
*, asection
*, struct bfd_link_info
*,
201 Elf_Internal_Rela
*, bfd_vma
, reloc_howto_type
*,
202 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**,
203 bfd_vma
*, const char **));
204 static bfd_vma mips_elf_obtain_contents
205 PARAMS ((reloc_howto_type
*, Elf_Internal_Rela
*, bfd
*, bfd_byte
*));
206 static void mips_elf_perform_relocation
207 PARAMS ((reloc_howto_type
*, Elf_Internal_Rela
*, bfd_vma
,
209 static boolean mips_elf_assign_gp
PARAMS ((bfd
*, bfd_vma
*));
210 static boolean mips_elf_sort_hash_table_f
211 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
212 static boolean mips_elf_sort_hash_table
213 PARAMS ((struct bfd_link_info
*));
214 static asection
* mips_elf_got_section
PARAMS ((bfd
*));
215 static struct mips_got_info
*mips_elf_got_info
216 PARAMS ((bfd
*, asection
**));
217 static bfd_vma mips_elf_create_local_got_entry
218 PARAMS ((bfd
*, struct mips_got_info
*, asection
*, bfd_vma
));
219 static bfd_vma mips_elf_got16_entry
220 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
));
221 static unsigned int mips_elf_create_dynamic_relocation
222 PARAMS ((bfd
*, struct bfd_link_info
*, Elf32_Internal_Rela
*,
223 long, bfd_vma
, asection
*));
225 /* The level of IRIX compatibility we're striving for. */
233 /* Nonzero if ABFD is using the N32 ABI. */
235 #define ABI_N32_P(abfd) \
236 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
238 /* What version of Irix we are trying to be compatible with. FIXME:
239 At the moment, we never generate "normal" MIPS ELF ABI executables;
240 we always use some version of Irix. */
242 #define IRIX_COMPAT(abfd) \
243 (ABI_N32_P (abfd) ? ict_irix6 : ict_irix5)
245 /* Whether we are trying to be compatible with IRIX at all. */
247 #define SGI_COMPAT(abfd) \
248 (IRIX_COMPAT (abfd) != ict_none)
250 /* The name of the msym section. */
251 #define MIPS_ELF_MSYM_SECTION_NAME(abfd) ".msym"
253 /* The name of the srdata section. */
254 #define MIPS_ELF_SRDATA_SECTION_NAME(abfd) ".srdata"
256 /* The name of the options section. */
257 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
258 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.options" : ".options")
260 /* The name of the stub section. */
261 #define MIPS_ELF_STUB_SECTION_NAME(abfd) \
262 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.stubs" : ".stub")
264 /* The number of local .got entries we reserve. */
265 #define MIPS_RESERVED_GOTNO (2)
267 /* Instructions which appear in a stub. For some reason the stub is
268 slightly different on an SGI system. */
269 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
270 #define STUB_LW(abfd) \
272 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
273 : 0x8f998000) /* lw t9,0x8000(gp) */
274 #define STUB_MOVE 0x03e07825 /* move t7,ra */
275 #define STUB_JALR 0x0320f809 /* jal t9 */
276 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
277 #define MIPS_FUNCTION_STUB_SIZE (16)
280 /* We no longer try to identify particular sections for the .dynsym
281 section. When we do, we wind up crashing if there are other random
282 sections with relocations. */
284 /* Names of sections which appear in the .dynsym section in an Irix 5
287 static const char * const mips_elf_dynsym_sec_names
[] =
300 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
301 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
303 /* The number of entries in mips_elf_dynsym_sec_names which go in the
306 #define MIPS_TEXT_DYNSYM_SECNO (3)
310 /* The names of the runtime procedure table symbols used on Irix 5. */
312 static const char * const mips_elf_dynsym_rtproc_names
[] =
315 "_procedure_string_table",
316 "_procedure_table_size",
320 /* These structures are used to generate the .compact_rel section on
325 unsigned long id1
; /* Always one? */
326 unsigned long num
; /* Number of compact relocation entries. */
327 unsigned long id2
; /* Always two? */
328 unsigned long offset
; /* The file offset of the first relocation. */
329 unsigned long reserved0
; /* Zero? */
330 unsigned long reserved1
; /* Zero? */
339 bfd_byte reserved0
[4];
340 bfd_byte reserved1
[4];
341 } Elf32_External_compact_rel
;
345 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
346 unsigned int rtype
: 4; /* Relocation types. See below. */
347 unsigned int dist2to
: 8;
348 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
349 unsigned long konst
; /* KONST field. See below. */
350 unsigned long vaddr
; /* VADDR to be relocated. */
355 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
356 unsigned int rtype
: 4; /* Relocation types. See below. */
357 unsigned int dist2to
: 8;
358 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
359 unsigned long konst
; /* KONST field. See below. */
367 } Elf32_External_crinfo
;
373 } Elf32_External_crinfo2
;
375 /* These are the constants used to swap the bitfields in a crinfo. */
377 #define CRINFO_CTYPE (0x1)
378 #define CRINFO_CTYPE_SH (31)
379 #define CRINFO_RTYPE (0xf)
380 #define CRINFO_RTYPE_SH (27)
381 #define CRINFO_DIST2TO (0xff)
382 #define CRINFO_DIST2TO_SH (19)
383 #define CRINFO_RELVADDR (0x7ffff)
384 #define CRINFO_RELVADDR_SH (0)
386 /* A compact relocation info has long (3 words) or short (2 words)
387 formats. A short format doesn't have VADDR field and relvaddr
388 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
389 #define CRF_MIPS_LONG 1
390 #define CRF_MIPS_SHORT 0
392 /* There are 4 types of compact relocation at least. The value KONST
393 has different meaning for each type:
396 CT_MIPS_REL32 Address in data
397 CT_MIPS_WORD Address in word (XXX)
398 CT_MIPS_GPHI_LO GP - vaddr
399 CT_MIPS_JMPAD Address to jump
402 #define CRT_MIPS_REL32 0xa
403 #define CRT_MIPS_WORD 0xb
404 #define CRT_MIPS_GPHI_LO 0xc
405 #define CRT_MIPS_JMPAD 0xd
407 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
408 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
409 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
410 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
412 static void bfd_elf32_swap_compact_rel_out
413 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
414 static void bfd_elf32_swap_crinfo_out
415 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
417 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
419 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
420 from smaller values. Start with zero, widen, *then* decrement. */
421 #define MINUS_ONE (((bfd_vma)0) - 1)
423 static reloc_howto_type elf_mips_howto_table
[] =
426 HOWTO (R_MIPS_NONE
, /* type */
428 0, /* size (0 = byte, 1 = short, 2 = long) */
430 false, /* pc_relative */
432 complain_overflow_dont
, /* complain_on_overflow */
433 bfd_elf_generic_reloc
, /* special_function */
434 "R_MIPS_NONE", /* name */
435 false, /* partial_inplace */
438 false), /* pcrel_offset */
440 /* 16 bit relocation. */
441 HOWTO (R_MIPS_16
, /* type */
443 1, /* size (0 = byte, 1 = short, 2 = long) */
445 false, /* pc_relative */
447 complain_overflow_bitfield
, /* complain_on_overflow */
448 bfd_elf_generic_reloc
, /* special_function */
449 "R_MIPS_16", /* name */
450 true, /* partial_inplace */
451 0xffff, /* src_mask */
452 0xffff, /* dst_mask */
453 false), /* pcrel_offset */
455 /* 32 bit relocation. */
456 HOWTO (R_MIPS_32
, /* type */
458 2, /* size (0 = byte, 1 = short, 2 = long) */
460 false, /* pc_relative */
462 complain_overflow_bitfield
, /* complain_on_overflow */
463 bfd_elf_generic_reloc
, /* special_function */
464 "R_MIPS_32", /* name */
465 true, /* partial_inplace */
466 0xffffffff, /* src_mask */
467 0xffffffff, /* dst_mask */
468 false), /* pcrel_offset */
470 /* 32 bit symbol relative relocation. */
471 HOWTO (R_MIPS_REL32
, /* type */
473 2, /* size (0 = byte, 1 = short, 2 = long) */
475 false, /* pc_relative */
477 complain_overflow_bitfield
, /* complain_on_overflow */
478 bfd_elf_generic_reloc
, /* special_function */
479 "R_MIPS_REL32", /* name */
480 true, /* partial_inplace */
481 0xffffffff, /* src_mask */
482 0xffffffff, /* dst_mask */
483 false), /* pcrel_offset */
485 /* 26 bit branch address. */
486 HOWTO (R_MIPS_26
, /* type */
488 2, /* size (0 = byte, 1 = short, 2 = long) */
490 false, /* pc_relative */
492 complain_overflow_dont
, /* complain_on_overflow */
493 /* This needs complex overflow
494 detection, because the upper four
495 bits must match the PC. */
496 bfd_elf_generic_reloc
, /* special_function */
497 "R_MIPS_26", /* name */
498 true, /* partial_inplace */
499 0x3ffffff, /* src_mask */
500 0x3ffffff, /* dst_mask */
501 false), /* pcrel_offset */
503 /* High 16 bits of symbol value. */
504 HOWTO (R_MIPS_HI16
, /* type */
506 2, /* size (0 = byte, 1 = short, 2 = long) */
508 false, /* pc_relative */
510 complain_overflow_dont
, /* complain_on_overflow */
511 _bfd_mips_elf_hi16_reloc
, /* special_function */
512 "R_MIPS_HI16", /* name */
513 true, /* partial_inplace */
514 0xffff, /* src_mask */
515 0xffff, /* dst_mask */
516 false), /* pcrel_offset */
518 /* Low 16 bits of symbol value. */
519 HOWTO (R_MIPS_LO16
, /* type */
521 2, /* size (0 = byte, 1 = short, 2 = long) */
523 false, /* pc_relative */
525 complain_overflow_dont
, /* complain_on_overflow */
526 _bfd_mips_elf_lo16_reloc
, /* special_function */
527 "R_MIPS_LO16", /* name */
528 true, /* partial_inplace */
529 0xffff, /* src_mask */
530 0xffff, /* dst_mask */
531 false), /* pcrel_offset */
533 /* GP relative reference. */
534 HOWTO (R_MIPS_GPREL16
, /* type */
536 2, /* size (0 = byte, 1 = short, 2 = long) */
538 false, /* pc_relative */
540 complain_overflow_signed
, /* complain_on_overflow */
541 _bfd_mips_elf_gprel16_reloc
, /* special_function */
542 "R_MIPS_GPREL16", /* name */
543 true, /* partial_inplace */
544 0xffff, /* src_mask */
545 0xffff, /* dst_mask */
546 false), /* pcrel_offset */
548 /* Reference to literal section. */
549 HOWTO (R_MIPS_LITERAL
, /* type */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
553 false, /* pc_relative */
555 complain_overflow_signed
, /* complain_on_overflow */
556 _bfd_mips_elf_gprel16_reloc
, /* special_function */
557 "R_MIPS_LITERAL", /* name */
558 true, /* partial_inplace */
559 0xffff, /* src_mask */
560 0xffff, /* dst_mask */
561 false), /* pcrel_offset */
563 /* Reference to global offset table. */
564 HOWTO (R_MIPS_GOT16
, /* type */
566 2, /* size (0 = byte, 1 = short, 2 = long) */
568 false, /* pc_relative */
570 complain_overflow_signed
, /* complain_on_overflow */
571 _bfd_mips_elf_got16_reloc
, /* special_function */
572 "R_MIPS_GOT16", /* name */
573 false, /* partial_inplace */
575 0xffff, /* dst_mask */
576 false), /* pcrel_offset */
578 /* 16 bit PC relative reference. */
579 HOWTO (R_MIPS_PC16
, /* type */
581 2, /* size (0 = byte, 1 = short, 2 = long) */
583 true, /* pc_relative */
585 complain_overflow_signed
, /* complain_on_overflow */
586 bfd_elf_generic_reloc
, /* special_function */
587 "R_MIPS_PC16", /* name */
588 true, /* partial_inplace */
589 0xffff, /* src_mask */
590 0xffff, /* dst_mask */
591 false), /* pcrel_offset */
593 /* 16 bit call through global offset table. */
594 HOWTO (R_MIPS_CALL16
, /* type */
596 2, /* size (0 = byte, 1 = short, 2 = long) */
598 false, /* pc_relative */
600 complain_overflow_signed
, /* complain_on_overflow */
601 bfd_elf_generic_reloc
, /* special_function */
602 "R_MIPS_CALL16", /* name */
603 false, /* partial_inplace */
605 0xffff, /* dst_mask */
606 false), /* pcrel_offset */
608 /* 32 bit GP relative reference. */
609 HOWTO (R_MIPS_GPREL32
, /* type */
611 2, /* size (0 = byte, 1 = short, 2 = long) */
613 false, /* pc_relative */
615 complain_overflow_bitfield
, /* complain_on_overflow */
616 _bfd_mips_elf_gprel32_reloc
, /* special_function */
617 "R_MIPS_GPREL32", /* name */
618 true, /* partial_inplace */
619 0xffffffff, /* src_mask */
620 0xffffffff, /* dst_mask */
621 false), /* pcrel_offset */
623 /* The remaining relocs are defined on Irix 5, although they are
624 not defined by the ABI. */
629 /* A 5 bit shift field. */
630 HOWTO (R_MIPS_SHIFT5
, /* type */
632 2, /* size (0 = byte, 1 = short, 2 = long) */
634 false, /* pc_relative */
636 complain_overflow_bitfield
, /* complain_on_overflow */
637 bfd_elf_generic_reloc
, /* special_function */
638 "R_MIPS_SHIFT5", /* name */
639 true, /* partial_inplace */
640 0x000007c0, /* src_mask */
641 0x000007c0, /* dst_mask */
642 false), /* pcrel_offset */
644 /* A 6 bit shift field. */
645 /* FIXME: This is not handled correctly; a special function is
646 needed to put the most significant bit in the right place. */
647 HOWTO (R_MIPS_SHIFT6
, /* type */
649 2, /* size (0 = byte, 1 = short, 2 = long) */
651 false, /* pc_relative */
653 complain_overflow_bitfield
, /* complain_on_overflow */
654 bfd_elf_generic_reloc
, /* special_function */
655 "R_MIPS_SHIFT6", /* name */
656 true, /* partial_inplace */
657 0x000007c4, /* src_mask */
658 0x000007c4, /* dst_mask */
659 false), /* pcrel_offset */
661 /* A 64 bit relocation. This is used in 32 bit ELF when addresses
662 are 64 bits long; the upper 32 bits are simply a sign extension.
663 The fields of the howto should be the same as for R_MIPS_32,
664 other than the type, name, and special_function. */
665 HOWTO (R_MIPS_64
, /* type */
667 2, /* size (0 = byte, 1 = short, 2 = long) */
669 false, /* pc_relative */
671 complain_overflow_bitfield
, /* complain_on_overflow */
672 mips32_64bit_reloc
, /* special_function */
673 "R_MIPS_64", /* name */
674 true, /* partial_inplace */
675 0xffffffff, /* src_mask */
676 0xffffffff, /* dst_mask */
677 false), /* pcrel_offset */
679 /* Displacement in the global offset table. */
680 HOWTO (R_MIPS_GOT_DISP
, /* type */
682 2, /* size (0 = byte, 1 = short, 2 = long) */
684 false, /* pc_relative */
686 complain_overflow_bitfield
, /* complain_on_overflow */
687 bfd_elf_generic_reloc
, /* special_function */
688 "R_MIPS_GOT_DISP", /* name */
689 true, /* partial_inplace */
690 0x0000ffff, /* src_mask */
691 0x0000ffff, /* dst_mask */
692 false), /* pcrel_offset */
694 /* Displacement to page pointer in the global offset table. */
695 HOWTO (R_MIPS_GOT_PAGE
, /* type */
697 2, /* size (0 = byte, 1 = short, 2 = long) */
699 false, /* pc_relative */
701 complain_overflow_bitfield
, /* complain_on_overflow */
702 bfd_elf_generic_reloc
, /* special_function */
703 "R_MIPS_GOT_PAGE", /* name */
704 true, /* partial_inplace */
705 0x0000ffff, /* src_mask */
706 0x0000ffff, /* dst_mask */
707 false), /* pcrel_offset */
709 /* Offset from page pointer in the global offset table. */
710 HOWTO (R_MIPS_GOT_OFST
, /* type */
712 2, /* size (0 = byte, 1 = short, 2 = long) */
714 false, /* pc_relative */
716 complain_overflow_bitfield
, /* complain_on_overflow */
717 bfd_elf_generic_reloc
, /* special_function */
718 "R_MIPS_GOT_OFST", /* name */
719 true, /* partial_inplace */
720 0x0000ffff, /* src_mask */
721 0x0000ffff, /* dst_mask */
722 false), /* pcrel_offset */
724 /* High 16 bits of displacement in global offset table. */
725 HOWTO (R_MIPS_GOT_HI16
, /* type */
727 2, /* size (0 = byte, 1 = short, 2 = long) */
729 false, /* pc_relative */
731 complain_overflow_dont
, /* complain_on_overflow */
732 bfd_elf_generic_reloc
, /* special_function */
733 "R_MIPS_GOT_HI16", /* name */
734 true, /* partial_inplace */
735 0x0000ffff, /* src_mask */
736 0x0000ffff, /* dst_mask */
737 false), /* pcrel_offset */
739 /* Low 16 bits of displacement in global offset table. */
740 HOWTO (R_MIPS_GOT_LO16
, /* type */
742 2, /* size (0 = byte, 1 = short, 2 = long) */
744 false, /* pc_relative */
746 complain_overflow_dont
, /* complain_on_overflow */
747 bfd_elf_generic_reloc
, /* special_function */
748 "R_MIPS_GOT_LO16", /* name */
749 true, /* partial_inplace */
750 0x0000ffff, /* src_mask */
751 0x0000ffff, /* dst_mask */
752 false), /* pcrel_offset */
754 /* 64 bit subtraction. Used in the N32 ABI. */
755 HOWTO (R_MIPS_SUB
, /* type */
757 4, /* size (0 = byte, 1 = short, 2 = long) */
759 false, /* pc_relative */
761 complain_overflow_bitfield
, /* complain_on_overflow */
762 bfd_elf_generic_reloc
, /* special_function */
763 "R_MIPS_SUB", /* name */
764 true, /* partial_inplace */
765 MINUS_ONE
, /* src_mask */
766 MINUS_ONE
, /* dst_mask */
767 false), /* pcrel_offset */
769 /* Used to cause the linker to insert and delete instructions? */
774 /* Get the higher values of a 64 bit addend. Presumably not used in
779 /* High 16 bits of displacement in global offset table. */
780 HOWTO (R_MIPS_CALL_HI16
, /* type */
782 2, /* size (0 = byte, 1 = short, 2 = long) */
784 false, /* pc_relative */
786 complain_overflow_dont
, /* complain_on_overflow */
787 bfd_elf_generic_reloc
, /* special_function */
788 "R_MIPS_CALL_HI16", /* name */
789 true, /* partial_inplace */
790 0x0000ffff, /* src_mask */
791 0x0000ffff, /* dst_mask */
792 false), /* pcrel_offset */
794 /* Low 16 bits of displacement in global offset table. */
795 HOWTO (R_MIPS_CALL_LO16
, /* type */
797 2, /* size (0 = byte, 1 = short, 2 = long) */
799 false, /* pc_relative */
801 complain_overflow_dont
, /* complain_on_overflow */
802 bfd_elf_generic_reloc
, /* special_function */
803 "R_MIPS_CALL_LO16", /* name */
804 true, /* partial_inplace */
805 0x0000ffff, /* src_mask */
806 0x0000ffff, /* dst_mask */
807 false), /* pcrel_offset */
809 /* Section displacement. */
810 HOWTO (R_MIPS_SCN_DISP
, /* type */
812 2, /* size (0 = byte, 1 = short, 2 = long) */
814 false, /* pc_relative */
816 complain_overflow_dont
, /* complain_on_overflow */
817 bfd_elf_generic_reloc
, /* special_function */
818 "R_MIPS_SCN_DISP", /* name */
819 false, /* partial_inplace */
820 0xffffffff, /* src_mask */
821 0xffffffff, /* dst_mask */
822 false), /* pcrel_offset */
825 { R_MIPS_ADD_IMMEDIATE
},
829 /* Protected jump conversion. This is an optimization hint. No
830 relocation is required for correctness. */
831 HOWTO (R_MIPS_JALR
, /* type */
833 0, /* size (0 = byte, 1 = short, 2 = long) */
835 false, /* pc_relative */
837 complain_overflow_dont
, /* complain_on_overflow */
838 bfd_elf_generic_reloc
, /* special_function */
839 "R_MIPS_JALR", /* name */
840 false, /* partial_inplace */
841 0x00000000, /* src_mask */
842 0x00000000, /* dst_mask */
843 false), /* pcrel_offset */
846 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
847 is a hack to make the linker think that we need 64 bit values. */
848 static reloc_howto_type elf_mips_ctor64_howto
=
849 HOWTO (R_MIPS_64
, /* type */
851 4, /* size (0 = byte, 1 = short, 2 = long) */
853 false, /* pc_relative */
855 complain_overflow_signed
, /* complain_on_overflow */
856 mips32_64bit_reloc
, /* special_function */
857 "R_MIPS_64", /* name */
858 true, /* partial_inplace */
859 0xffffffff, /* src_mask */
860 0xffffffff, /* dst_mask */
861 false); /* pcrel_offset */
863 /* The reloc used for the mips16 jump instruction. */
864 static reloc_howto_type elf_mips16_jump_howto
=
865 HOWTO (R_MIPS16_26
, /* type */
867 2, /* size (0 = byte, 1 = short, 2 = long) */
869 false, /* pc_relative */
871 complain_overflow_dont
, /* complain_on_overflow */
872 /* This needs complex overflow
873 detection, because the upper four
874 bits must match the PC. */
875 mips16_jump_reloc
, /* special_function */
876 "R_MIPS16_26", /* name */
877 true, /* partial_inplace */
878 0x3ffffff, /* src_mask */
879 0x3ffffff, /* dst_mask */
880 false); /* pcrel_offset */
882 /* The reloc used for the mips16 gprel instruction. The src_mask and
883 dsk_mask for this howto do not reflect the actual instruction, in
884 which the value is not contiguous; the masks are for the
885 convenience of the relocate_section routine. */
886 static reloc_howto_type elf_mips16_gprel_howto
=
887 HOWTO (R_MIPS16_GPREL
, /* type */
889 2, /* size (0 = byte, 1 = short, 2 = long) */
891 false, /* pc_relative */
893 complain_overflow_signed
, /* complain_on_overflow */
894 mips16_gprel_reloc
, /* special_function */
895 "R_MIPS16_GPREL", /* name */
896 true, /* partial_inplace */
897 0xffff, /* src_mask */
898 0xffff, /* dst_mask */
899 false); /* pcrel_offset */
902 /* GNU extension to record C++ vtable hierarchy */
903 static reloc_howto_type elf_mips_gnu_vtinherit_howto
=
904 HOWTO (R_MIPS_GNU_VTINHERIT
, /* type */
906 2, /* size (0 = byte, 1 = short, 2 = long) */
908 false, /* pc_relative */
910 complain_overflow_dont
, /* complain_on_overflow */
911 NULL
, /* special_function */
912 "R_MIPS_GNU_VTINHERIT", /* name */
913 false, /* partial_inplace */
916 false); /* pcrel_offset */
918 /* GNU extension to record C++ vtable member usage */
919 static reloc_howto_type elf_mips_gnu_vtentry_howto
=
920 HOWTO (R_MIPS_GNU_VTENTRY
, /* type */
922 2, /* size (0 = byte, 1 = short, 2 = long) */
924 false, /* pc_relative */
926 complain_overflow_dont
, /* complain_on_overflow */
927 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
928 "R_MIPS_GNU_VTENTRY", /* name */
929 false, /* partial_inplace */
932 false); /* pcrel_offset */
934 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
935 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
936 the HI16. Here we just save the information we need; we do the
937 actual relocation when we see the LO16. MIPS ELF requires that the
938 LO16 immediately follow the HI16. As a GNU extension, we permit an
939 arbitrary number of HI16 relocs to be associated with a single LO16
940 reloc. This extension permits gcc to output the HI and LO relocs
945 struct mips_hi16
*next
;
950 /* FIXME: This should not be a static variable. */
952 static struct mips_hi16
*mips_hi16_list
;
954 bfd_reloc_status_type
955 _bfd_mips_elf_hi16_reloc (abfd
,
963 arelent
*reloc_entry
;
966 asection
*input_section
;
968 char **error_message
;
970 bfd_reloc_status_type ret
;
974 /* If we're relocating, and this an external symbol, we don't want
975 to change anything. */
976 if (output_bfd
!= (bfd
*) NULL
977 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
978 && reloc_entry
->addend
== 0)
980 reloc_entry
->address
+= input_section
->output_offset
;
986 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
988 boolean relocateable
;
991 if (ret
== bfd_reloc_undefined
)
994 if (output_bfd
!= NULL
)
998 relocateable
= false;
999 output_bfd
= symbol
->section
->output_section
->owner
;
1002 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1003 error_message
, &gp
);
1004 if (ret
!= bfd_reloc_ok
)
1007 relocation
= gp
- reloc_entry
->address
;
1011 if (bfd_is_und_section (symbol
->section
)
1012 && output_bfd
== (bfd
*) NULL
)
1013 ret
= bfd_reloc_undefined
;
1015 if (bfd_is_com_section (symbol
->section
))
1018 relocation
= symbol
->value
;
1021 relocation
+= symbol
->section
->output_section
->vma
;
1022 relocation
+= symbol
->section
->output_offset
;
1023 relocation
+= reloc_entry
->addend
;
1025 if (reloc_entry
->address
> input_section
->_cooked_size
)
1026 return bfd_reloc_outofrange
;
1028 /* Save the information, and let LO16 do the actual relocation. */
1029 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
1031 return bfd_reloc_outofrange
;
1032 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
1033 n
->addend
= relocation
;
1034 n
->next
= mips_hi16_list
;
1037 if (output_bfd
!= (bfd
*) NULL
)
1038 reloc_entry
->address
+= input_section
->output_offset
;
1043 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
1044 inplace relocation; this function exists in order to do the
1045 R_MIPS_HI16 relocation described above. */
1047 bfd_reloc_status_type
1048 _bfd_mips_elf_lo16_reloc (abfd
,
1056 arelent
*reloc_entry
;
1059 asection
*input_section
;
1061 char **error_message
;
1063 arelent gp_disp_relent
;
1065 if (mips_hi16_list
!= NULL
)
1067 struct mips_hi16
*l
;
1074 unsigned long vallo
;
1075 struct mips_hi16
*next
;
1077 /* Do the HI16 relocation. Note that we actually don't need
1078 to know anything about the LO16 itself, except where to
1079 find the low 16 bits of the addend needed by the LO16. */
1080 insn
= bfd_get_32 (abfd
, l
->addr
);
1081 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
1083 val
= ((insn
& 0xffff) << 16) + vallo
;
1086 /* The low order 16 bits are always treated as a signed
1087 value. Therefore, a negative value in the low order bits
1088 requires an adjustment in the high order bits. We need
1089 to make this adjustment in two ways: once for the bits we
1090 took from the data, and once for the bits we are putting
1091 back in to the data. */
1092 if ((vallo
& 0x8000) != 0)
1094 if ((val
& 0x8000) != 0)
1097 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
1098 bfd_put_32 (abfd
, insn
, l
->addr
);
1100 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1102 gp_disp_relent
= *reloc_entry
;
1103 reloc_entry
= &gp_disp_relent
;
1104 reloc_entry
->addend
= l
->addend
;
1112 mips_hi16_list
= NULL
;
1114 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
1116 bfd_reloc_status_type ret
;
1117 bfd_vma gp
, relocation
;
1119 /* FIXME: Does this case ever occur? */
1121 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
1122 if (ret
!= bfd_reloc_ok
)
1125 relocation
= gp
- reloc_entry
->address
;
1126 relocation
+= symbol
->section
->output_section
->vma
;
1127 relocation
+= symbol
->section
->output_offset
;
1128 relocation
+= reloc_entry
->addend
;
1130 if (reloc_entry
->address
> input_section
->_cooked_size
)
1131 return bfd_reloc_outofrange
;
1133 gp_disp_relent
= *reloc_entry
;
1134 reloc_entry
= &gp_disp_relent
;
1135 reloc_entry
->addend
= relocation
- 4;
1138 /* Now do the LO16 reloc in the usual way. */
1139 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1140 input_section
, output_bfd
, error_message
);
1143 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1144 table used for PIC code. If the symbol is an external symbol, the
1145 instruction is modified to contain the offset of the appropriate
1146 entry in the global offset table. If the symbol is a section
1147 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1148 addends are combined to form the real addend against the section
1149 symbol; the GOT16 is modified to contain the offset of an entry in
1150 the global offset table, and the LO16 is modified to offset it
1151 appropriately. Thus an offset larger than 16 bits requires a
1152 modified value in the global offset table.
1154 This implementation suffices for the assembler, but the linker does
1155 not yet know how to create global offset tables. */
1157 bfd_reloc_status_type
1158 _bfd_mips_elf_got16_reloc (abfd
,
1166 arelent
*reloc_entry
;
1169 asection
*input_section
;
1171 char **error_message
;
1173 /* If we're relocating, and this an external symbol, we don't want
1174 to change anything. */
1175 if (output_bfd
!= (bfd
*) NULL
1176 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1177 && reloc_entry
->addend
== 0)
1179 reloc_entry
->address
+= input_section
->output_offset
;
1180 return bfd_reloc_ok
;
1183 /* If we're relocating, and this is a local symbol, we can handle it
1185 if (output_bfd
!= (bfd
*) NULL
1186 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1187 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1188 input_section
, output_bfd
, error_message
);
1193 /* Set the GP value for OUTPUT_BFD. Returns false if this is a
1194 dangerous relocation. */
1197 mips_elf_assign_gp (output_bfd
, pgp
)
1205 /* If we've already figured out what GP will be, just return it. */
1206 *pgp
= _bfd_get_gp_value (output_bfd
);
1210 count
= bfd_get_symcount (output_bfd
);
1211 sym
= bfd_get_outsymbols (output_bfd
);
1213 /* The linker script will have created a symbol named `_gp' with the
1214 appropriate value. */
1215 if (sym
== (asymbol
**) NULL
)
1219 for (i
= 0; i
< count
; i
++, sym
++)
1221 register CONST
char *name
;
1223 name
= bfd_asymbol_name (*sym
);
1224 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1226 *pgp
= bfd_asymbol_value (*sym
);
1227 _bfd_set_gp_value (output_bfd
, *pgp
);
1235 /* Only get the error once. */
1237 _bfd_set_gp_value (output_bfd
, *pgp
);
1244 /* We have to figure out the gp value, so that we can adjust the
1245 symbol value correctly. We look up the symbol _gp in the output
1246 BFD. If we can't find it, we're stuck. We cache it in the ELF
1247 target data. We don't need to adjust the symbol value for an
1248 external symbol if we are producing relocateable output. */
1250 static bfd_reloc_status_type
1251 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1254 boolean relocateable
;
1255 char **error_message
;
1258 if (bfd_is_und_section (symbol
->section
)
1262 return bfd_reloc_undefined
;
1265 *pgp
= _bfd_get_gp_value (output_bfd
);
1268 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1272 /* Make up a value. */
1273 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1274 _bfd_set_gp_value (output_bfd
, *pgp
);
1276 else if (!mips_elf_assign_gp (output_bfd
, pgp
))
1279 (char *) _("GP relative relocation when _gp not defined");
1280 return bfd_reloc_dangerous
;
1284 return bfd_reloc_ok
;
1287 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1288 become the offset from the gp register. This function also handles
1289 R_MIPS_LITERAL relocations, although those can be handled more
1290 cleverly because the entries in the .lit8 and .lit4 sections can be
1293 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1294 arelent
*, asection
*,
1295 boolean
, PTR
, bfd_vma
));
1297 bfd_reloc_status_type
1298 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1299 output_bfd
, error_message
)
1301 arelent
*reloc_entry
;
1304 asection
*input_section
;
1306 char **error_message
;
1308 boolean relocateable
;
1309 bfd_reloc_status_type ret
;
1312 /* If we're relocating, and this is an external symbol with no
1313 addend, we don't want to change anything. We will only have an
1314 addend if this is a newly created reloc, not read from an ELF
1316 if (output_bfd
!= (bfd
*) NULL
1317 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1318 && reloc_entry
->addend
== 0)
1320 reloc_entry
->address
+= input_section
->output_offset
;
1321 return bfd_reloc_ok
;
1324 if (output_bfd
!= (bfd
*) NULL
)
1325 relocateable
= true;
1328 relocateable
= false;
1329 output_bfd
= symbol
->section
->output_section
->owner
;
1332 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1334 if (ret
!= bfd_reloc_ok
)
1337 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1338 relocateable
, data
, gp
);
1341 static bfd_reloc_status_type
1342 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1346 arelent
*reloc_entry
;
1347 asection
*input_section
;
1348 boolean relocateable
;
1356 if (bfd_is_com_section (symbol
->section
))
1359 relocation
= symbol
->value
;
1361 relocation
+= symbol
->section
->output_section
->vma
;
1362 relocation
+= symbol
->section
->output_offset
;
1364 if (reloc_entry
->address
> input_section
->_cooked_size
)
1365 return bfd_reloc_outofrange
;
1367 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1369 /* Set val to the offset into the section or symbol. */
1370 if (reloc_entry
->howto
->src_mask
== 0)
1372 /* This case occurs with the 64-bit MIPS ELF ABI. */
1373 val
= reloc_entry
->addend
;
1377 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1382 /* Adjust val for the final section location and GP value. If we
1383 are producing relocateable output, we don't want to do this for
1384 an external symbol. */
1386 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1387 val
+= relocation
- gp
;
1389 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1390 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1393 reloc_entry
->address
+= input_section
->output_offset
;
1395 /* Make sure it fit in 16 bits. */
1396 if (val
>= 0x8000 && val
< 0xffff8000)
1397 return bfd_reloc_overflow
;
1399 return bfd_reloc_ok
;
1402 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1403 from the gp register? XXX */
1405 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1406 arelent
*, asection
*,
1407 boolean
, PTR
, bfd_vma
));
1409 bfd_reloc_status_type
1410 _bfd_mips_elf_gprel32_reloc (abfd
,
1418 arelent
*reloc_entry
;
1421 asection
*input_section
;
1423 char **error_message
;
1425 boolean relocateable
;
1426 bfd_reloc_status_type ret
;
1429 /* If we're relocating, and this is an external symbol with no
1430 addend, we don't want to change anything. We will only have an
1431 addend if this is a newly created reloc, not read from an ELF
1433 if (output_bfd
!= (bfd
*) NULL
1434 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1435 && reloc_entry
->addend
== 0)
1437 *error_message
= (char *)
1438 _("32bits gp relative relocation occurs for an external symbol");
1439 return bfd_reloc_outofrange
;
1442 if (output_bfd
!= (bfd
*) NULL
)
1444 relocateable
= true;
1445 gp
= _bfd_get_gp_value (output_bfd
);
1449 relocateable
= false;
1450 output_bfd
= symbol
->section
->output_section
->owner
;
1452 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1453 error_message
, &gp
);
1454 if (ret
!= bfd_reloc_ok
)
1458 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1459 relocateable
, data
, gp
);
1462 static bfd_reloc_status_type
1463 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1467 arelent
*reloc_entry
;
1468 asection
*input_section
;
1469 boolean relocateable
;
1476 if (bfd_is_com_section (symbol
->section
))
1479 relocation
= symbol
->value
;
1481 relocation
+= symbol
->section
->output_section
->vma
;
1482 relocation
+= symbol
->section
->output_offset
;
1484 if (reloc_entry
->address
> input_section
->_cooked_size
)
1485 return bfd_reloc_outofrange
;
1487 if (reloc_entry
->howto
->src_mask
== 0)
1489 /* This case arises with the 64-bit MIPS ELF ABI. */
1493 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1495 /* Set val to the offset into the section or symbol. */
1496 val
+= reloc_entry
->addend
;
1498 /* Adjust val for the final section location and GP value. If we
1499 are producing relocateable output, we don't want to do this for
1500 an external symbol. */
1502 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1503 val
+= relocation
- gp
;
1505 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1508 reloc_entry
->address
+= input_section
->output_offset
;
1510 return bfd_reloc_ok
;
1513 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1514 generated when addreses are 64 bits. The upper 32 bits are a simle
1517 static bfd_reloc_status_type
1518 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1519 output_bfd
, error_message
)
1521 arelent
*reloc_entry
;
1524 asection
*input_section
;
1526 char **error_message
;
1528 bfd_reloc_status_type r
;
1533 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1534 input_section
, output_bfd
, error_message
);
1535 if (r
!= bfd_reloc_continue
)
1538 /* Do a normal 32 bit relocation on the lower 32 bits. */
1539 reloc32
= *reloc_entry
;
1540 if (bfd_big_endian (abfd
))
1541 reloc32
.address
+= 4;
1542 reloc32
.howto
= &elf_mips_howto_table
[R_MIPS_32
];
1543 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1544 output_bfd
, error_message
);
1546 /* Sign extend into the upper 32 bits. */
1547 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1548 if ((val
& 0x80000000) != 0)
1552 addr
= reloc_entry
->address
;
1553 if (bfd_little_endian (abfd
))
1555 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ addr
);
1560 /* Handle a mips16 jump. */
1562 static bfd_reloc_status_type
1563 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1564 output_bfd
, error_message
)
1566 arelent
*reloc_entry
;
1569 asection
*input_section
;
1571 char **error_message
;
1573 if (output_bfd
!= (bfd
*) NULL
1574 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1575 && reloc_entry
->addend
== 0)
1577 reloc_entry
->address
+= input_section
->output_offset
;
1578 return bfd_reloc_ok
;
1583 static boolean warned
;
1586 (*_bfd_error_handler
)
1587 (_("Linking mips16 objects into %s format is not supported"),
1588 bfd_get_target (input_section
->output_section
->owner
));
1592 return bfd_reloc_undefined
;
1595 /* Handle a mips16 GP relative reloc. */
1597 static bfd_reloc_status_type
1598 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1599 output_bfd
, error_message
)
1601 arelent
*reloc_entry
;
1604 asection
*input_section
;
1606 char **error_message
;
1608 boolean relocateable
;
1609 bfd_reloc_status_type ret
;
1611 unsigned short extend
, insn
;
1612 unsigned long final
;
1614 /* If we're relocating, and this is an external symbol with no
1615 addend, we don't want to change anything. We will only have an
1616 addend if this is a newly created reloc, not read from an ELF
1618 if (output_bfd
!= NULL
1619 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1620 && reloc_entry
->addend
== 0)
1622 reloc_entry
->address
+= input_section
->output_offset
;
1623 return bfd_reloc_ok
;
1626 if (output_bfd
!= NULL
)
1627 relocateable
= true;
1630 relocateable
= false;
1631 output_bfd
= symbol
->section
->output_section
->owner
;
1634 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1636 if (ret
!= bfd_reloc_ok
)
1639 if (reloc_entry
->address
> input_section
->_cooked_size
)
1640 return bfd_reloc_outofrange
;
1642 /* Pick up the mips16 extend instruction and the real instruction. */
1643 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1644 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1646 /* Stuff the current addend back as a 32 bit value, do the usual
1647 relocation, and then clean up. */
1649 (((extend
& 0x1f) << 11)
1652 (bfd_byte
*) data
+ reloc_entry
->address
);
1654 ret
= gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1655 relocateable
, data
, gp
);
1657 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1660 | ((final
>> 11) & 0x1f)
1662 (bfd_byte
*) data
+ reloc_entry
->address
);
1666 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1671 /* Return the ISA for a MIPS e_flags value. */
1674 elf_mips_isa (flags
)
1677 switch (flags
& EF_MIPS_ARCH
)
1691 /* Return the MACH for a MIPS e_flags value. */
1694 elf_mips_mach (flags
)
1697 switch (flags
& EF_MIPS_MACH
)
1699 case E_MIPS_MACH_3900
:
1700 return bfd_mach_mips3900
;
1702 case E_MIPS_MACH_4010
:
1703 return bfd_mach_mips4010
;
1705 case E_MIPS_MACH_4100
:
1706 return bfd_mach_mips4100
;
1708 case E_MIPS_MACH_4111
:
1709 return bfd_mach_mips4111
;
1711 case E_MIPS_MACH_4650
:
1712 return bfd_mach_mips4650
;
1715 switch (flags
& EF_MIPS_ARCH
)
1719 return bfd_mach_mips3000
;
1723 return bfd_mach_mips6000
;
1727 return bfd_mach_mips4000
;
1731 return bfd_mach_mips8000
;
1739 /* Return printable name for ABI from flagword. */
1742 elf_mips_abi_name (flags
)
1745 switch (flags
& EF_MIPS_ABI
)
1749 case E_MIPS_ABI_O32
:
1751 case E_MIPS_ABI_O64
:
1753 case E_MIPS_ABI_EABI32
:
1755 case E_MIPS_ABI_EABI64
:
1758 return "unknown abi";
1762 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1764 struct elf_reloc_map
{
1765 bfd_reloc_code_real_type bfd_reloc_val
;
1766 enum elf_mips_reloc_type elf_reloc_val
;
1769 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1771 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1772 { BFD_RELOC_16
, R_MIPS_16
},
1773 { BFD_RELOC_32
, R_MIPS_32
},
1774 { BFD_RELOC_64
, R_MIPS_64
},
1775 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1776 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1777 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1778 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1779 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1780 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1781 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1782 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1783 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1784 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1785 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1786 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1787 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
},
1788 { BFD_RELOC_MIPS_SUB
, R_MIPS_SUB
},
1789 { BFD_RELOC_MIPS_GOT_PAGE
, R_MIPS_GOT_PAGE
},
1790 { BFD_RELOC_MIPS_GOT_OFST
, R_MIPS_GOT_OFST
},
1791 { BFD_RELOC_MIPS_GOT_DISP
, R_MIPS_GOT_DISP
}
1794 /* Given a BFD reloc type, return a howto structure. */
1796 static reloc_howto_type
*
1797 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1799 bfd_reloc_code_real_type code
;
1803 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1805 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1806 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1812 bfd_set_error (bfd_error_bad_value
);
1815 case BFD_RELOC_CTOR
:
1816 /* We need to handle BFD_RELOC_CTOR specially.
1817 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1818 size of addresses on this architecture. */
1819 if (bfd_arch_bits_per_address (abfd
) == 32)
1820 return &elf_mips_howto_table
[(int) R_MIPS_32
];
1822 return &elf_mips_ctor64_howto
;
1824 case BFD_RELOC_MIPS16_JMP
:
1825 return &elf_mips16_jump_howto
;
1826 case BFD_RELOC_MIPS16_GPREL
:
1827 return &elf_mips16_gprel_howto
;
1828 case BFD_RELOC_VTABLE_INHERIT
:
1829 return &elf_mips_gnu_vtinherit_howto
;
1830 case BFD_RELOC_VTABLE_ENTRY
:
1831 return &elf_mips_gnu_vtentry_howto
;
1835 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
1838 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1841 Elf32_Internal_Rel
*dst
;
1843 unsigned int r_type
;
1845 r_type
= ELF32_R_TYPE (dst
->r_info
);
1849 cache_ptr
->howto
= &elf_mips16_jump_howto
;
1851 case R_MIPS16_GPREL
:
1852 cache_ptr
->howto
= &elf_mips16_gprel_howto
;
1854 case R_MIPS_GNU_VTINHERIT
:
1855 cache_ptr
->howto
= &elf_mips_gnu_vtinherit_howto
;
1857 case R_MIPS_GNU_VTENTRY
:
1858 cache_ptr
->howto
= &elf_mips_gnu_vtentry_howto
;
1862 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1863 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1867 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1868 value for the object file. We get the addend now, rather than
1869 when we do the relocation, because the symbol manipulations done
1870 by the linker may cause us to lose track of the input BFD. */
1871 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1872 && (r_type
== (unsigned int) R_MIPS_GPREL16
1873 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1874 cache_ptr
->addend
= elf_gp (abfd
);
1877 /* Given a MIPS Elf32_Internal_Rela, fill in an arelent structure. */
1880 mips_info_to_howto_rela (abfd
, cache_ptr
, dst
)
1883 Elf32_Internal_Rela
*dst
;
1885 /* Since an Elf32_Internal_Rel is an initial prefix of an
1886 Elf32_Internal_Rela, we can just use mips_info_to_howto_rel
1888 mips_info_to_howto_rel (abfd
, cache_ptr
, (Elf32_Internal_Rel
*) dst
);
1890 /* If we ever need to do any extra processing with dst->r_addend
1891 (the field omitted in an Elf32_Internal_Rel) we can do it here. */
1894 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1895 routines swap this structure in and out. They are used outside of
1896 BFD, so they are globally visible. */
1899 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1901 const Elf32_External_RegInfo
*ex
;
1904 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1905 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1906 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1907 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1908 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1909 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1913 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1915 const Elf32_RegInfo
*in
;
1916 Elf32_External_RegInfo
*ex
;
1918 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1919 (bfd_byte
*) ex
->ri_gprmask
);
1920 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1921 (bfd_byte
*) ex
->ri_cprmask
[0]);
1922 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1923 (bfd_byte
*) ex
->ri_cprmask
[1]);
1924 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1925 (bfd_byte
*) ex
->ri_cprmask
[2]);
1926 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1927 (bfd_byte
*) ex
->ri_cprmask
[3]);
1928 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1929 (bfd_byte
*) ex
->ri_gp_value
);
1932 /* In the 64 bit ABI, the .MIPS.options section holds register
1933 information in an Elf64_Reginfo structure. These routines swap
1934 them in and out. They are globally visible because they are used
1935 outside of BFD. These routines are here so that gas can call them
1936 without worrying about whether the 64 bit ABI has been included. */
1939 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1941 const Elf64_External_RegInfo
*ex
;
1942 Elf64_Internal_RegInfo
*in
;
1944 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1945 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
1946 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1947 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1948 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1949 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1950 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1954 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1956 const Elf64_Internal_RegInfo
*in
;
1957 Elf64_External_RegInfo
*ex
;
1959 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1960 (bfd_byte
*) ex
->ri_gprmask
);
1961 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
1962 (bfd_byte
*) ex
->ri_pad
);
1963 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1964 (bfd_byte
*) ex
->ri_cprmask
[0]);
1965 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1966 (bfd_byte
*) ex
->ri_cprmask
[1]);
1967 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1968 (bfd_byte
*) ex
->ri_cprmask
[2]);
1969 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1970 (bfd_byte
*) ex
->ri_cprmask
[3]);
1971 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1972 (bfd_byte
*) ex
->ri_gp_value
);
1975 /* Swap an entry in a .gptab section. Note that these routines rely
1976 on the equivalence of the two elements of the union. */
1979 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1981 const Elf32_External_gptab
*ex
;
1984 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1985 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1989 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1991 const Elf32_gptab
*in
;
1992 Elf32_External_gptab
*ex
;
1994 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1995 ex
->gt_entry
.gt_g_value
);
1996 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1997 ex
->gt_entry
.gt_bytes
);
2001 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
2003 const Elf32_compact_rel
*in
;
2004 Elf32_External_compact_rel
*ex
;
2006 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
2007 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
2008 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
2009 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
2010 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
2011 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
2015 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
2017 const Elf32_crinfo
*in
;
2018 Elf32_External_crinfo
*ex
;
2022 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
2023 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
2024 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
2025 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
2026 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
2027 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
2028 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
2031 /* Swap in an options header. */
2034 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
2036 const Elf_External_Options
*ex
;
2037 Elf_Internal_Options
*in
;
2039 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
2040 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
2041 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
2042 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
2045 /* Swap out an options header. */
2048 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
2050 const Elf_Internal_Options
*in
;
2051 Elf_External_Options
*ex
;
2053 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
2054 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
2055 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
2056 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
2059 /* Swap in an MSYM entry. */
2062 bfd_mips_elf_swap_msym_in (abfd
, ex
, in
)
2064 const Elf32_External_Msym
*ex
;
2065 Elf32_Internal_Msym
*in
;
2067 in
->ms_hash_value
= bfd_h_get_32 (abfd
, ex
->ms_hash_value
);
2068 in
->ms_info
= bfd_h_get_32 (abfd
, ex
->ms_info
);
2071 /* Swap out an MSYM entry. */
2074 bfd_mips_elf_swap_msym_out (abfd
, in
, ex
)
2076 const Elf32_Internal_Msym
*in
;
2077 Elf32_External_Msym
*ex
;
2079 bfd_h_put_32 (abfd
, in
->ms_hash_value
, ex
->ms_hash_value
);
2080 bfd_h_put_32 (abfd
, in
->ms_info
, ex
->ms_info
);
2084 /* Determine whether a symbol is global for the purposes of splitting
2085 the symbol table into global symbols and local symbols. At least
2086 on Irix 5, this split must be between section symbols and all other
2087 symbols. On most ELF targets the split is between static symbols
2088 and externally visible symbols. */
2092 mips_elf_sym_is_global (abfd
, sym
)
2096 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
2099 /* Set the right machine number for a MIPS ELF file. This is used for
2100 both the 32-bit and the 64-bit ABI. */
2103 _bfd_mips_elf_object_p (abfd
)
2106 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
,
2107 elf_mips_mach (elf_elfheader (abfd
)->e_flags
));
2111 /* Set the right machine number for a 32-bit MIPS ELF file. */
2114 mips_elf32_object_p (abfd
)
2117 /* Irix 5 is broken. Object file symbol tables are not always
2118 sorted correctly such that local symbols precede global symbols,
2119 and the sh_info field in the symbol table is not always right. */
2120 elf_bad_symtab (abfd
) = true;
2122 return _bfd_mips_elf_object_p (abfd
);
2125 /* The final processing done just before writing out a MIPS ELF object
2126 file. This gets the MIPS architecture right based on the machine
2127 number. This is used by both the 32-bit and the 64-bit ABI. */
2131 _bfd_mips_elf_final_write_processing (abfd
, linker
)
2137 Elf_Internal_Shdr
**hdrpp
;
2141 switch (bfd_get_mach (abfd
))
2144 case bfd_mach_mips3000
:
2145 val
= E_MIPS_ARCH_1
;
2148 case bfd_mach_mips3900
:
2149 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
2152 case bfd_mach_mips6000
:
2153 val
= E_MIPS_ARCH_2
;
2156 case bfd_mach_mips4000
:
2157 case bfd_mach_mips4300
:
2158 val
= E_MIPS_ARCH_3
;
2161 case bfd_mach_mips4010
:
2162 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
2165 case bfd_mach_mips4100
:
2166 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
2169 case bfd_mach_mips4111
:
2170 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
2173 case bfd_mach_mips4650
:
2174 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
2177 case bfd_mach_mips8000
:
2178 val
= E_MIPS_ARCH_4
;
2182 elf_elfheader (abfd
)->e_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2183 elf_elfheader (abfd
)->e_flags
|= val
;
2185 /* Set the sh_info field for .gptab sections and other appropriate
2186 info for each special section. */
2187 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
2188 i
< elf_elfheader (abfd
)->e_shnum
;
2191 switch ((*hdrpp
)->sh_type
)
2194 case SHT_MIPS_LIBLIST
:
2195 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
2197 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2200 case SHT_MIPS_GPTAB
:
2201 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2202 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2203 BFD_ASSERT (name
!= NULL
2204 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
2205 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
2206 BFD_ASSERT (sec
!= NULL
);
2207 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2210 case SHT_MIPS_CONTENT
:
2211 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2212 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2213 BFD_ASSERT (name
!= NULL
2214 && strncmp (name
, ".MIPS.content",
2215 sizeof ".MIPS.content" - 1) == 0);
2216 sec
= bfd_get_section_by_name (abfd
,
2217 name
+ sizeof ".MIPS.content" - 1);
2218 BFD_ASSERT (sec
!= NULL
);
2219 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2222 case SHT_MIPS_SYMBOL_LIB
:
2223 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
2225 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2226 sec
= bfd_get_section_by_name (abfd
, ".liblist");
2228 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
2231 case SHT_MIPS_EVENTS
:
2232 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
2233 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
2234 BFD_ASSERT (name
!= NULL
);
2235 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
2236 sec
= bfd_get_section_by_name (abfd
,
2237 name
+ sizeof ".MIPS.events" - 1);
2240 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
2241 sizeof ".MIPS.post_rel" - 1) == 0);
2242 sec
= bfd_get_section_by_name (abfd
,
2244 + sizeof ".MIPS.post_rel" - 1));
2246 BFD_ASSERT (sec
!= NULL
);
2247 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
2254 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
2257 _bfd_mips_elf_set_private_flags (abfd
, flags
)
2261 BFD_ASSERT (!elf_flags_init (abfd
)
2262 || elf_elfheader (abfd
)->e_flags
== flags
);
2264 elf_elfheader (abfd
)->e_flags
= flags
;
2265 elf_flags_init (abfd
) = true;
2269 /* Copy backend specific data from one object module to another */
2272 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
2276 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2277 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2280 BFD_ASSERT (!elf_flags_init (obfd
)
2281 || (elf_elfheader (obfd
)->e_flags
2282 == elf_elfheader (ibfd
)->e_flags
));
2284 elf_gp (obfd
) = elf_gp (ibfd
);
2285 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
2286 elf_flags_init (obfd
) = true;
2290 /* Merge backend specific data from an object file to the output
2291 object file when linking. */
2294 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
2302 /* Check if we have the same endianess */
2303 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2304 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2308 if (bfd_big_endian (ibfd
))
2309 msg
= _("%s: compiled for a big endian system and target is little endian");
2311 msg
= _("%s: compiled for a little endian system and target is big endian");
2313 (*_bfd_error_handler
) (msg
, bfd_get_filename (ibfd
));
2315 bfd_set_error (bfd_error_wrong_format
);
2319 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2320 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2323 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2324 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
2325 old_flags
= elf_elfheader (obfd
)->e_flags
;
2327 if (! elf_flags_init (obfd
))
2329 elf_flags_init (obfd
) = true;
2330 elf_elfheader (obfd
)->e_flags
= new_flags
;
2332 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2333 && bfd_get_arch_info (obfd
)->the_default
)
2335 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
2336 bfd_get_mach (ibfd
)))
2343 /* Check flag compatibility. */
2345 new_flags
&= ~EF_MIPS_NOREORDER
;
2346 old_flags
&= ~EF_MIPS_NOREORDER
;
2348 if (new_flags
== old_flags
)
2353 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
2355 new_flags
&= ~EF_MIPS_PIC
;
2356 old_flags
&= ~EF_MIPS_PIC
;
2357 (*_bfd_error_handler
)
2358 (_("%s: linking PIC files with non-PIC files"),
2359 bfd_get_filename (ibfd
));
2363 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
2365 new_flags
&= ~EF_MIPS_CPIC
;
2366 old_flags
&= ~EF_MIPS_CPIC
;
2367 (*_bfd_error_handler
)
2368 (_("%s: linking abicalls files with non-abicalls files"),
2369 bfd_get_filename (ibfd
));
2373 /* Compare the ISA's. */
2374 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
2375 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
2377 int new_mach
= new_flags
& EF_MIPS_MACH
;
2378 int old_mach
= old_flags
& EF_MIPS_MACH
;
2379 int new_isa
= elf_mips_isa (new_flags
);
2380 int old_isa
= elf_mips_isa (old_flags
);
2382 /* If either has no machine specified, just compare the general isa's.
2383 Some combinations of machines are ok, if the isa's match. */
2386 || new_mach
== old_mach
2389 /* Don't warn about mixing -mips1 and -mips2 code, or mixing -mips3
2390 and -mips4 code. They will normally use the same data sizes and
2391 calling conventions. */
2393 if ((new_isa
== 1 || new_isa
== 2)
2394 ? (old_isa
!= 1 && old_isa
!= 2)
2395 : (old_isa
== 1 || old_isa
== 2))
2397 (*_bfd_error_handler
)
2398 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
2399 bfd_get_filename (ibfd
), new_isa
, old_isa
);
2406 (*_bfd_error_handler
)
2407 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
2408 bfd_get_filename (ibfd
),
2409 elf_mips_mach (new_flags
),
2410 elf_mips_mach (old_flags
));
2414 new_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2415 old_flags
&= ~ (EF_MIPS_ARCH
| EF_MIPS_MACH
);
2419 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
))
2421 /* Only error if both are set (to different values). */
2422 if ((new_flags
& EF_MIPS_ABI
)
2423 && (old_flags
& EF_MIPS_ABI
))
2425 (*_bfd_error_handler
)
2426 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
2427 bfd_get_filename (ibfd
),
2428 elf_mips_abi_name (new_flags
),
2429 elf_mips_abi_name (old_flags
));
2432 new_flags
&= ~EF_MIPS_ABI
;
2433 old_flags
&= ~EF_MIPS_ABI
;
2436 /* Warn about any other mismatches */
2437 if (new_flags
!= old_flags
)
2439 (*_bfd_error_handler
)
2440 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2441 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
2442 (unsigned long) old_flags
);
2448 bfd_set_error (bfd_error_bad_value
);
2456 _bfd_mips_elf_print_private_bfd_data (abfd
, ptr
)
2460 FILE *file
= (FILE *) ptr
;
2462 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
2464 /* Print normal ELF private data. */
2465 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
2467 /* xgettext:c-format */
2468 fprintf (file
, _ ("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
2470 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
2471 fprintf (file
, _ (" [abi=O32]"));
2472 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
2473 fprintf (file
, _ (" [abi=O64]"));
2474 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
2475 fprintf (file
, _ (" [abi=EABI32]"));
2476 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
2477 fprintf (file
, _ (" [abi=EABI64]"));
2478 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
2479 fprintf (file
, _ (" [abi unknown]"));
2480 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI2
))
2481 fprintf (file
, _ (" [abi=N32]"));
2483 fprintf (file
, _ (" [no abi set]"));
2485 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
2486 fprintf (file
, _ (" [mips1]"));
2487 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
2488 fprintf (file
, _ (" [mips2]"));
2489 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
2490 fprintf (file
, _ (" [mips3]"));
2491 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
2492 fprintf (file
, _ (" [mips4]"));
2494 fprintf (file
, _ (" [unknown ISA]"));
2496 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
2497 fprintf (file
, _ (" [32bitmode]"));
2499 fprintf (file
, _ (" [not 32bitmode]"));
2506 /* Handle a MIPS specific section when reading an object file. This
2507 is called when elfcode.h finds a section with an unknown type.
2508 This routine supports both the 32-bit and 64-bit ELF ABI.
2510 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
2514 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
2516 Elf_Internal_Shdr
*hdr
;
2521 /* There ought to be a place to keep ELF backend specific flags, but
2522 at the moment there isn't one. We just keep track of the
2523 sections by their name, instead. Fortunately, the ABI gives
2524 suggested names for all the MIPS specific sections, so we will
2525 probably get away with this. */
2526 switch (hdr
->sh_type
)
2528 case SHT_MIPS_LIBLIST
:
2529 if (strcmp (name
, ".liblist") != 0)
2533 if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) != 0)
2536 case SHT_MIPS_CONFLICT
:
2537 if (strcmp (name
, ".conflict") != 0)
2540 case SHT_MIPS_GPTAB
:
2541 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
2544 case SHT_MIPS_UCODE
:
2545 if (strcmp (name
, ".ucode") != 0)
2548 case SHT_MIPS_DEBUG
:
2549 if (strcmp (name
, ".mdebug") != 0)
2551 flags
= SEC_DEBUGGING
;
2553 case SHT_MIPS_REGINFO
:
2554 if (strcmp (name
, ".reginfo") != 0
2555 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
2557 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
2559 case SHT_MIPS_IFACE
:
2560 if (strcmp (name
, ".MIPS.interfaces") != 0)
2563 case SHT_MIPS_CONTENT
:
2564 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
2567 case SHT_MIPS_OPTIONS
:
2568 if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) != 0)
2571 case SHT_MIPS_DWARF
:
2572 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
2575 case SHT_MIPS_SYMBOL_LIB
:
2576 if (strcmp (name
, ".MIPS.symlib") != 0)
2579 case SHT_MIPS_EVENTS
:
2580 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
2581 && strncmp (name
, ".MIPS.post_rel",
2582 sizeof ".MIPS.post_rel" - 1) != 0)
2589 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2594 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
2595 (bfd_get_section_flags (abfd
,
2604 /* Handle a 32-bit MIPS ELF specific section. */
2607 mips_elf32_section_from_shdr (abfd
, hdr
, name
)
2609 Elf_Internal_Shdr
*hdr
;
2612 if (! _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
))
2615 /* FIXME: We should record sh_info for a .gptab section. */
2617 /* For a .reginfo section, set the gp value in the tdata information
2618 from the contents of this section. We need the gp value while
2619 processing relocs, so we just get it now. The .reginfo section
2620 is not used in the 64-bit MIPS ELF ABI. */
2621 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2623 Elf32_External_RegInfo ext
;
2626 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
2627 (file_ptr
) 0, sizeof ext
))
2629 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
2630 elf_gp (abfd
) = s
.ri_gp_value
;
2633 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
2634 set the gp value based on what we find. We may see both
2635 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
2636 they should agree. */
2637 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
2639 bfd_byte
*contents
, *l
, *lend
;
2641 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
2642 if (contents
== NULL
)
2644 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
2645 (file_ptr
) 0, hdr
->sh_size
))
2651 lend
= contents
+ hdr
->sh_size
;
2652 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2654 Elf_Internal_Options intopt
;
2656 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2658 if (intopt
.kind
== ODK_REGINFO
)
2660 Elf32_RegInfo intreg
;
2662 bfd_mips_elf32_swap_reginfo_in
2664 ((Elf32_External_RegInfo
*)
2665 (l
+ sizeof (Elf_External_Options
))),
2667 elf_gp (abfd
) = intreg
.ri_gp_value
;
2677 /* Set the correct type for a MIPS ELF section. We do this by the
2678 section name, which is a hack, but ought to work. This routine is
2679 used by both the 32-bit and the 64-bit ABI. */
2682 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
2684 Elf32_Internal_Shdr
*hdr
;
2687 register const char *name
;
2689 name
= bfd_get_section_name (abfd
, sec
);
2691 if (strcmp (name
, ".liblist") == 0)
2693 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
2694 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
2695 /* The sh_link field is set in final_write_processing. */
2697 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) == 0)
2699 hdr
->sh_type
= SHT_MIPS_MSYM
;
2700 hdr
->sh_entsize
= 8;
2701 /* FIXME: Set the sh_info field. */
2703 else if (strcmp (name
, ".conflict") == 0)
2704 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
2705 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2707 hdr
->sh_type
= SHT_MIPS_GPTAB
;
2708 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
2709 /* The sh_info field is set in final_write_processing. */
2711 else if (strcmp (name
, ".ucode") == 0)
2712 hdr
->sh_type
= SHT_MIPS_UCODE
;
2713 else if (strcmp (name
, ".mdebug") == 0)
2715 hdr
->sh_type
= SHT_MIPS_DEBUG
;
2716 /* In a shared object on Irix 5.3, the .mdebug section has an
2717 entsize of 0. FIXME: Does this matter? */
2718 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2719 hdr
->sh_entsize
= 0;
2721 hdr
->sh_entsize
= 1;
2723 else if (strcmp (name
, ".reginfo") == 0)
2725 hdr
->sh_type
= SHT_MIPS_REGINFO
;
2726 /* In a shared object on Irix 5.3, the .reginfo section has an
2727 entsize of 0x18. FIXME: Does this matter? */
2728 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
2729 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
2731 hdr
->sh_entsize
= 1;
2733 else if (SGI_COMPAT (abfd
)
2734 && (strcmp (name
, ".hash") == 0
2735 || strcmp (name
, ".dynamic") == 0
2736 || strcmp (name
, ".dynstr") == 0))
2738 hdr
->sh_entsize
= 0;
2740 /* This isn't how the Irix 6 linker behaves. */
2741 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
2744 else if (strcmp (name
, ".got") == 0
2745 || strcmp (name
, MIPS_ELF_SRDATA_SECTION_NAME (abfd
)) == 0
2746 || strcmp (name
, ".sdata") == 0
2747 || strcmp (name
, ".sbss") == 0
2748 || strcmp (name
, ".lit4") == 0
2749 || strcmp (name
, ".lit8") == 0)
2750 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
2751 else if (strcmp (name
, ".MIPS.interfaces") == 0)
2753 hdr
->sh_type
= SHT_MIPS_IFACE
;
2754 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2756 else if (strncmp (name
, ".MIPS.content", strlen (".MIPS.content")) == 0)
2758 hdr
->sh_type
= SHT_MIPS_CONTENT
;
2759 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2760 /* The sh_info field is set in final_write_processing. */
2762 else if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
2764 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
2765 hdr
->sh_entsize
= 1;
2766 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2768 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
2769 hdr
->sh_type
= SHT_MIPS_DWARF
;
2770 else if (strcmp (name
, ".MIPS.symlib") == 0)
2772 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
2773 /* The sh_link and sh_info fields are set in
2774 final_write_processing. */
2776 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
2777 || strncmp (name
, ".MIPS.post_rel",
2778 sizeof ".MIPS.post_rel" - 1) == 0)
2780 hdr
->sh_type
= SHT_MIPS_EVENTS
;
2781 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
2782 /* The sh_link field is set in final_write_processing. */
2784 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (abfd
)) == 0)
2786 hdr
->sh_type
= SHT_MIPS_MSYM
;
2787 hdr
->sh_flags
|= SHF_ALLOC
;
2788 hdr
->sh_entsize
= 8;
2794 /* Given a BFD section, try to locate the corresponding ELF section
2795 index. This is used by both the 32-bit and the 64-bit ABI.
2796 Actually, it's not clear to me that the 64-bit ABI supports these,
2797 but for non-PIC objects we will certainly want support for at least
2798 the .scommon section. */
2801 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
2803 Elf32_Internal_Shdr
*hdr
;
2807 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2809 *retval
= SHN_MIPS_SCOMMON
;
2812 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
2814 *retval
= SHN_MIPS_ACOMMON
;
2820 /* When are writing out the .options or .MIPS.options section,
2821 remember the bytes we are writing out, so that we can install the
2822 GP value in the section_processing routine. */
2825 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2830 bfd_size_type count
;
2832 if (strcmp (section
->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
2836 if (elf_section_data (section
) == NULL
)
2838 section
->used_by_bfd
=
2839 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
2840 if (elf_section_data (section
) == NULL
)
2843 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
2848 if (section
->_cooked_size
!= 0)
2849 size
= section
->_cooked_size
;
2851 size
= section
->_raw_size
;
2852 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
2855 elf_section_data (section
)->tdata
= (PTR
) c
;
2858 memcpy (c
+ offset
, location
, count
);
2861 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
2865 /* Work over a section just before writing it out. This routine is
2866 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2867 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2871 _bfd_mips_elf_section_processing (abfd
, hdr
)
2873 Elf_Internal_Shdr
*hdr
;
2875 if (hdr
->bfd_section
!= NULL
)
2877 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
2879 if (strcmp (name
, ".sdata") == 0
2880 || strcmp (name
, ".lit8") == 0
2881 || strcmp (name
, ".lit4") == 0)
2883 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2884 hdr
->sh_type
= SHT_PROGBITS
;
2886 else if (strcmp (name
, ".sbss") == 0)
2888 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2889 hdr
->sh_type
= SHT_NOBITS
;
2891 else if (strcmp (name
, MIPS_ELF_SRDATA_SECTION_NAME (abfd
)) == 0)
2893 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
2894 hdr
->sh_type
= SHT_PROGBITS
;
2896 else if (strcmp (name
, ".compact_rel") == 0)
2899 hdr
->sh_type
= SHT_PROGBITS
;
2901 else if (strcmp (name
, ".rtproc") == 0)
2903 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
2905 unsigned int adjust
;
2907 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
2909 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
2917 /* Work over a section just before writing it out. We update the GP
2918 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2919 on the value we are using. */
2922 mips_elf32_section_processing (abfd
, hdr
)
2924 Elf32_Internal_Shdr
*hdr
;
2926 if (hdr
->sh_type
== SHT_MIPS_REGINFO
2927 && hdr
->sh_size
> 0)
2931 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2932 BFD_ASSERT (hdr
->contents
== NULL
);
2935 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2938 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2939 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2943 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2944 && hdr
->bfd_section
!= NULL
2945 && elf_section_data (hdr
->bfd_section
) != NULL
2946 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2948 bfd_byte
*contents
, *l
, *lend
;
2950 /* We stored the section contents in the elf_section_data tdata
2951 field in the set_section_contents routine. We save the
2952 section contents so that we don't have to read them again.
2953 At this point we know that elf_gp is set, so we can look
2954 through the section contents to see if there is an
2955 ODK_REGINFO structure. */
2957 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2959 lend
= contents
+ hdr
->sh_size
;
2960 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2962 Elf_Internal_Options intopt
;
2964 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2966 if (intopt
.kind
== ODK_REGINFO
)
2973 + sizeof (Elf_External_Options
)
2974 + (sizeof (Elf32_External_RegInfo
) - 4)),
2977 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
2978 if (bfd_write (buf
, 1, 4, abfd
) != 4)
2985 return _bfd_mips_elf_section_processing (abfd
, hdr
);
2988 /* MIPS ELF uses two common sections. One is the usual one, and the
2989 other is for small objects. All the small objects are kept
2990 together, and then referenced via the gp pointer, which yields
2991 faster assembler code. This is what we use for the small common
2992 section. This approach is copied from ecoff.c. */
2993 static asection mips_elf_scom_section
;
2994 static asymbol mips_elf_scom_symbol
;
2995 static asymbol
*mips_elf_scom_symbol_ptr
;
2997 /* MIPS ELF also uses an acommon section, which represents an
2998 allocated common symbol which may be overridden by a
2999 definition in a shared library. */
3000 static asection mips_elf_acom_section
;
3001 static asymbol mips_elf_acom_symbol
;
3002 static asymbol
*mips_elf_acom_symbol_ptr
;
3004 /* The Irix 5 support uses two virtual sections, which represent
3005 text/data symbols defined in dynamic objects. */
3006 static asection mips_elf_text_section
;
3007 static asection
*mips_elf_text_section_ptr
;
3008 static asymbol mips_elf_text_symbol
;
3009 static asymbol
*mips_elf_text_symbol_ptr
;
3011 static asection mips_elf_data_section
;
3012 static asection
*mips_elf_data_section_ptr
;
3013 static asymbol mips_elf_data_symbol
;
3014 static asymbol
*mips_elf_data_symbol_ptr
;
3016 /* Handle the special MIPS section numbers that a symbol may use.
3017 This is used for both the 32-bit and the 64-bit ABI. */
3020 _bfd_mips_elf_symbol_processing (abfd
, asym
)
3024 elf_symbol_type
*elfsym
;
3026 elfsym
= (elf_symbol_type
*) asym
;
3027 switch (elfsym
->internal_elf_sym
.st_shndx
)
3029 case SHN_MIPS_ACOMMON
:
3030 /* This section is used in a dynamically linked executable file.
3031 It is an allocated common section. The dynamic linker can
3032 either resolve these symbols to something in a shared
3033 library, or it can just leave them here. For our purposes,
3034 we can consider these symbols to be in a new section. */
3035 if (mips_elf_acom_section
.name
== NULL
)
3037 /* Initialize the acommon section. */
3038 mips_elf_acom_section
.name
= ".acommon";
3039 mips_elf_acom_section
.flags
= SEC_ALLOC
;
3040 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
3041 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
3042 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
3043 mips_elf_acom_symbol
.name
= ".acommon";
3044 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
3045 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
3046 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
3048 asym
->section
= &mips_elf_acom_section
;
3052 /* Common symbols less than the GP size are automatically
3053 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
3054 if (asym
->value
> elf_gp_size (abfd
)
3055 || IRIX_COMPAT (abfd
) == ict_irix6
)
3058 case SHN_MIPS_SCOMMON
:
3059 if (mips_elf_scom_section
.name
== NULL
)
3061 /* Initialize the small common section. */
3062 mips_elf_scom_section
.name
= ".scommon";
3063 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
3064 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
3065 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
3066 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
3067 mips_elf_scom_symbol
.name
= ".scommon";
3068 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
3069 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
3070 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
3072 asym
->section
= &mips_elf_scom_section
;
3073 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
3076 case SHN_MIPS_SUNDEFINED
:
3077 asym
->section
= bfd_und_section_ptr
;
3080 #if 0 /* for SGI_COMPAT */
3082 asym
->section
= mips_elf_text_section_ptr
;
3086 asym
->section
= mips_elf_data_section_ptr
;
3092 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
3096 mips_elf_additional_program_headers (abfd
)
3102 if (!SGI_COMPAT (abfd
))
3105 /* See if we need a PT_MIPS_REGINFO segment. */
3106 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3107 if (s
&& (s
->flags
& SEC_LOAD
))
3110 /* See if we need a PT_MIPS_OPTIONS segment. */
3111 if (IRIX_COMPAT (abfd
) == ict_irix6
3112 && bfd_get_section_by_name (abfd
,
3113 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
3116 /* See if we need a PT_MIPS_RTPROC segment. */
3117 if (IRIX_COMPAT (abfd
) == ict_irix5
3118 && bfd_get_section_by_name (abfd
, ".dynamic")
3119 && bfd_get_section_by_name (abfd
, ".mdebug"))
3125 /* Modify the segment map for an Irix 5 executable. */
3128 mips_elf_modify_segment_map (abfd
)
3132 struct elf_segment_map
*m
, **pm
;
3134 if (! SGI_COMPAT (abfd
))
3137 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
3139 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3140 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3142 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3143 if (m
->p_type
== PT_MIPS_REGINFO
)
3147 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3151 m
->p_type
= PT_MIPS_REGINFO
;
3155 /* We want to put it after the PHDR and INTERP segments. */
3156 pm
= &elf_tdata (abfd
)->segment_map
;
3158 && ((*pm
)->p_type
== PT_PHDR
3159 || (*pm
)->p_type
== PT_INTERP
))
3167 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
3168 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
3169 PT_OPTIONS segement immediately following the program header
3171 if (IRIX_COMPAT (abfd
) == ict_irix6
)
3175 for (s
= abfd
->sections
; s
; s
= s
->next
)
3176 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
3181 struct elf_segment_map
*options_segment
;
3183 for (m
= elf_tdata (abfd
)->segment_map
; m
; m
= m
->next
)
3184 if (m
->p_type
== PT_PHDR
)
3187 /* There should always be a program header table. */
3191 options_segment
= bfd_zalloc (abfd
,
3192 sizeof (struct elf_segment_map
));
3193 options_segment
->next
= m
->next
;
3194 options_segment
->p_type
= PT_MIPS_OPTIONS
;
3195 options_segment
->p_flags
= PF_R
;
3196 options_segment
->p_flags_valid
= true;
3197 options_segment
->count
= 1;
3198 options_segment
->sections
[0] = s
;
3199 m
->next
= options_segment
;
3204 /* If there are .dynamic and .mdebug sections, we make a room
3205 for the RTPROC header. FIXME: Rewrite without section names. */
3206 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
3207 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
3208 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
3210 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3211 if (m
->p_type
== PT_MIPS_RTPROC
)
3215 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
3219 m
->p_type
= PT_MIPS_RTPROC
;
3221 s
= bfd_get_section_by_name (abfd
, ".rtproc");
3226 m
->p_flags_valid
= 1;
3234 /* We want to put it after the DYNAMIC segment. */
3235 pm
= &elf_tdata (abfd
)->segment_map
;
3236 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
3246 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic,
3247 .dynstr, .dynsym, and .hash sections, and everything in
3249 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
3250 if ((*pm
)->p_type
== PT_DYNAMIC
)
3255 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
3257 static const char *sec_names
[] =
3258 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
3261 struct elf_segment_map
*n
;
3265 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
3267 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
3268 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
3274 sz
= s
->_cooked_size
;
3277 if (high
< s
->vma
+ sz
)
3283 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3284 if ((s
->flags
& SEC_LOAD
) != 0
3287 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
3291 n
= ((struct elf_segment_map
*)
3292 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
3299 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3301 if ((s
->flags
& SEC_LOAD
) != 0
3304 + (s
->_cooked_size
!= 0 ?
3305 s
->_cooked_size
: s
->_raw_size
))
3320 /* The structure of the runtime procedure descriptor created by the
3321 loader for use by the static exception system. */
3323 typedef struct runtime_pdr
{
3324 bfd_vma adr
; /* memory address of start of procedure */
3325 long regmask
; /* save register mask */
3326 long regoffset
; /* save register offset */
3327 long fregmask
; /* save floating point register mask */
3328 long fregoffset
; /* save floating point register offset */
3329 long frameoffset
; /* frame size */
3330 short framereg
; /* frame pointer register */
3331 short pcreg
; /* offset or reg of return pc */
3332 long irpss
; /* index into the runtime string table */
3334 struct exception_info
*exception_info
;/* pointer to exception array */
3336 #define cbRPDR sizeof(RPDR)
3337 #define rpdNil ((pRPDR) 0)
3339 /* Swap RPDR (runtime procedure table entry) for output. */
3341 static void ecoff_swap_rpdr_out
3342 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
3345 ecoff_swap_rpdr_out (abfd
, in
, ex
)
3348 struct rpdr_ext
*ex
;
3350 /* ecoff_put_off was defined in ecoffswap.h. */
3351 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
3352 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
3353 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
3354 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
3355 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
3356 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
3358 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
3359 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
3361 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
3363 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
3367 /* Read ECOFF debugging information from a .mdebug section into a
3368 ecoff_debug_info structure. */
3371 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
3374 struct ecoff_debug_info
*debug
;
3377 const struct ecoff_debug_swap
*swap
;
3378 char *ext_hdr
= NULL
;
3380 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3381 memset (debug
, 0, sizeof(*debug
));
3383 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
3384 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
3387 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
3388 swap
->external_hdr_size
)
3392 symhdr
= &debug
->symbolic_header
;
3393 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
3395 /* The symbolic header contains absolute file offsets and sizes to
3397 #define READ(ptr, offset, count, size, type) \
3398 if (symhdr->count == 0) \
3399 debug->ptr = NULL; \
3402 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
3403 if (debug->ptr == NULL) \
3404 goto error_return; \
3405 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
3406 || (bfd_read (debug->ptr, size, symhdr->count, \
3407 abfd) != size * symhdr->count)) \
3408 goto error_return; \
3411 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
3412 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
3413 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
3414 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
3415 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
3416 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
3418 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
3419 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
3420 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
3421 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
3422 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
3426 debug
->adjust
= NULL
;
3431 if (ext_hdr
!= NULL
)
3433 if (debug
->line
!= NULL
)
3435 if (debug
->external_dnr
!= NULL
)
3436 free (debug
->external_dnr
);
3437 if (debug
->external_pdr
!= NULL
)
3438 free (debug
->external_pdr
);
3439 if (debug
->external_sym
!= NULL
)
3440 free (debug
->external_sym
);
3441 if (debug
->external_opt
!= NULL
)
3442 free (debug
->external_opt
);
3443 if (debug
->external_aux
!= NULL
)
3444 free (debug
->external_aux
);
3445 if (debug
->ss
!= NULL
)
3447 if (debug
->ssext
!= NULL
)
3448 free (debug
->ssext
);
3449 if (debug
->external_fdr
!= NULL
)
3450 free (debug
->external_fdr
);
3451 if (debug
->external_rfd
!= NULL
)
3452 free (debug
->external_rfd
);
3453 if (debug
->external_ext
!= NULL
)
3454 free (debug
->external_ext
);
3458 /* MIPS ELF local labels start with '$', not 'L'. */
3462 mips_elf_is_local_label_name (abfd
, name
)
3469 /* On Irix 6, the labels go back to starting with '.', so we accept
3470 the generic ELF local label syntax as well. */
3471 return _bfd_elf_is_local_label_name (abfd
, name
);
3474 /* MIPS ELF uses a special find_nearest_line routine in order the
3475 handle the ECOFF debugging information. */
3477 struct mips_elf_find_line
3479 struct ecoff_debug_info d
;
3480 struct ecoff_find_line i
;
3484 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
3485 functionname_ptr
, line_ptr
)
3490 const char **filename_ptr
;
3491 const char **functionname_ptr
;
3492 unsigned int *line_ptr
;
3496 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
3497 filename_ptr
, functionname_ptr
,
3501 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3502 filename_ptr
, functionname_ptr
,
3506 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
3510 struct mips_elf_find_line
*fi
;
3511 const struct ecoff_debug_swap
* const swap
=
3512 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3514 /* If we are called during a link, mips_elf_final_link may have
3515 cleared the SEC_HAS_CONTENTS field. We force it back on here
3516 if appropriate (which it normally will be). */
3517 origflags
= msec
->flags
;
3518 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
3519 msec
->flags
|= SEC_HAS_CONTENTS
;
3521 fi
= elf_tdata (abfd
)->find_line_info
;
3524 bfd_size_type external_fdr_size
;
3527 struct fdr
*fdr_ptr
;
3529 fi
= ((struct mips_elf_find_line
*)
3530 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
3533 msec
->flags
= origflags
;
3537 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
3539 msec
->flags
= origflags
;
3543 /* Swap in the FDR information. */
3544 fi
->d
.fdr
= ((struct fdr
*)
3546 (fi
->d
.symbolic_header
.ifdMax
*
3547 sizeof (struct fdr
))));
3548 if (fi
->d
.fdr
== NULL
)
3550 msec
->flags
= origflags
;
3553 external_fdr_size
= swap
->external_fdr_size
;
3554 fdr_ptr
= fi
->d
.fdr
;
3555 fraw_src
= (char *) fi
->d
.external_fdr
;
3556 fraw_end
= (fraw_src
3557 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
3558 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
3559 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
3561 elf_tdata (abfd
)->find_line_info
= fi
;
3563 /* Note that we don't bother to ever free this information.
3564 find_nearest_line is either called all the time, as in
3565 objdump -l, so the information should be saved, or it is
3566 rarely called, as in ld error messages, so the memory
3567 wasted is unimportant. Still, it would probably be a
3568 good idea for free_cached_info to throw it away. */
3571 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
3572 &fi
->i
, filename_ptr
, functionname_ptr
,
3575 msec
->flags
= origflags
;
3579 msec
->flags
= origflags
;
3582 /* Fall back on the generic ELF find_nearest_line routine. */
3584 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
3585 filename_ptr
, functionname_ptr
,
3589 /* The mips16 compiler uses a couple of special sections to handle
3590 floating point arguments.
3592 Section names that look like .mips16.fn.FNNAME contain stubs that
3593 copy floating point arguments from the fp regs to the gp regs and
3594 then jump to FNNAME. If any 32 bit function calls FNNAME, the
3595 call should be redirected to the stub instead. If no 32 bit
3596 function calls FNNAME, the stub should be discarded. We need to
3597 consider any reference to the function, not just a call, because
3598 if the address of the function is taken we will need the stub,
3599 since the address might be passed to a 32 bit function.
3601 Section names that look like .mips16.call.FNNAME contain stubs
3602 that copy floating point arguments from the gp regs to the fp
3603 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
3604 then any 16 bit function that calls FNNAME should be redirected
3605 to the stub instead. If FNNAME is not a 32 bit function, the
3606 stub should be discarded.
3608 .mips16.call.fp.FNNAME sections are similar, but contain stubs
3609 which call FNNAME and then copy the return value from the fp regs
3610 to the gp regs. These stubs store the return value in $18 while
3611 calling FNNAME; any function which might call one of these stubs
3612 must arrange to save $18 around the call. (This case is not
3613 needed for 32 bit functions that call 16 bit functions, because
3614 16 bit functions always return floating point values in both
3617 Note that in all cases FNNAME might be defined statically.
3618 Therefore, FNNAME is not used literally. Instead, the relocation
3619 information will indicate which symbol the section is for.
3621 We record any stubs that we find in the symbol table. */
3623 #define FN_STUB ".mips16.fn."
3624 #define CALL_STUB ".mips16.call."
3625 #define CALL_FP_STUB ".mips16.call.fp."
3627 /* MIPS ELF linker hash table. */
3629 struct mips_elf_link_hash_table
3631 struct elf_link_hash_table root
;
3633 /* We no longer use this. */
3634 /* String section indices for the dynamic section symbols. */
3635 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
3637 /* The number of .rtproc entries. */
3638 bfd_size_type procedure_count
;
3639 /* The size of the .compact_rel section (if SGI_COMPAT). */
3640 bfd_size_type compact_rel_size
;
3641 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
3642 entry is set to the address of __rld_obj_head as in Irix 5. */
3643 boolean use_rld_obj_head
;
3644 /* This is the value of the __rld_map or __rld_obj_head symbol. */
3646 /* This is set if we see any mips16 stub sections. */
3647 boolean mips16_stubs_seen
;
3650 /* Look up an entry in a MIPS ELF linker hash table. */
3652 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
3653 ((struct mips_elf_link_hash_entry *) \
3654 elf_link_hash_lookup (&(table)->root, (string), (create), \
3657 /* Traverse a MIPS ELF linker hash table. */
3659 #define mips_elf_link_hash_traverse(table, func, info) \
3660 (elf_link_hash_traverse \
3662 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3665 /* Get the MIPS ELF linker hash table from a link_info structure. */
3667 #define mips_elf_hash_table(p) \
3668 ((struct mips_elf_link_hash_table *) ((p)->hash))
3670 static boolean mips_elf_output_extsym
3671 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
3673 /* Create an entry in a MIPS ELF linker hash table. */
3675 static struct bfd_hash_entry
*
3676 mips_elf_link_hash_newfunc (entry
, table
, string
)
3677 struct bfd_hash_entry
*entry
;
3678 struct bfd_hash_table
*table
;
3681 struct mips_elf_link_hash_entry
*ret
=
3682 (struct mips_elf_link_hash_entry
*) entry
;
3684 /* Allocate the structure if it has not already been allocated by a
3686 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3687 ret
= ((struct mips_elf_link_hash_entry
*)
3688 bfd_hash_allocate (table
,
3689 sizeof (struct mips_elf_link_hash_entry
)));
3690 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
3691 return (struct bfd_hash_entry
*) ret
;
3693 /* Call the allocation method of the superclass. */
3694 ret
= ((struct mips_elf_link_hash_entry
*)
3695 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3697 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
3699 /* Set local fields. */
3700 memset (&ret
->esym
, 0, sizeof (EXTR
));
3701 /* We use -2 as a marker to indicate that the information has
3702 not been set. -1 means there is no associated ifd. */
3704 ret
->mips_32_relocs
= 0;
3705 ret
->min_dyn_reloc_index
= 0;
3706 ret
->fn_stub
= NULL
;
3707 ret
->need_fn_stub
= false;
3708 ret
->call_stub
= NULL
;
3709 ret
->call_fp_stub
= NULL
;
3712 return (struct bfd_hash_entry
*) ret
;
3715 /* Create a MIPS ELF linker hash table. */
3717 static struct bfd_link_hash_table
*
3718 mips_elf_link_hash_table_create (abfd
)
3721 struct mips_elf_link_hash_table
*ret
;
3723 ret
= ((struct mips_elf_link_hash_table
*)
3724 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
3725 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
3728 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3729 mips_elf_link_hash_newfunc
))
3731 bfd_release (abfd
, ret
);
3736 /* We no longer use this. */
3737 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
3738 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
3740 ret
->procedure_count
= 0;
3741 ret
->compact_rel_size
= 0;
3742 ret
->use_rld_obj_head
= false;
3744 ret
->mips16_stubs_seen
= false;
3746 return &ret
->root
.root
;
3749 /* Hook called by the linker routine which adds symbols from an object
3750 file. We must handle the special MIPS section numbers here. */
3754 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3756 struct bfd_link_info
*info
;
3757 const Elf_Internal_Sym
*sym
;
3763 if (SGI_COMPAT (abfd
)
3764 && (abfd
->flags
& DYNAMIC
) != 0
3765 && strcmp (*namep
, "_rld_new_interface") == 0)
3767 /* Skip Irix 5 rld entry name. */
3772 switch (sym
->st_shndx
)
3775 /* Common symbols less than the GP size are automatically
3776 treated as SHN_MIPS_SCOMMON symbols. */
3777 if (sym
->st_size
> elf_gp_size (abfd
)
3778 || IRIX_COMPAT (abfd
) == ict_irix6
)
3781 case SHN_MIPS_SCOMMON
:
3782 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3783 (*secp
)->flags
|= SEC_IS_COMMON
;
3784 *valp
= sym
->st_size
;
3788 /* This section is used in a shared object. */
3789 if (mips_elf_text_section_ptr
== NULL
)
3791 /* Initialize the section. */
3792 mips_elf_text_section
.name
= ".text";
3793 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
3794 mips_elf_text_section
.output_section
= NULL
;
3795 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
3796 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
3797 mips_elf_text_symbol
.name
= ".text";
3798 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
3799 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
3800 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
3801 mips_elf_text_section_ptr
= &mips_elf_text_section
;
3803 /* This code used to do *secp = bfd_und_section_ptr if
3804 info->shared. I don't know why, and that doesn't make sense,
3805 so I took it out. */
3806 *secp
= mips_elf_text_section_ptr
;
3809 case SHN_MIPS_ACOMMON
:
3810 /* Fall through. XXX Can we treat this as allocated data? */
3812 /* This section is used in a shared object. */
3813 if (mips_elf_data_section_ptr
== NULL
)
3815 /* Initialize the section. */
3816 mips_elf_data_section
.name
= ".data";
3817 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
3818 mips_elf_data_section
.output_section
= NULL
;
3819 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
3820 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
3821 mips_elf_data_symbol
.name
= ".data";
3822 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
3823 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
3824 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
3825 mips_elf_data_section_ptr
= &mips_elf_data_section
;
3827 /* This code used to do *secp = bfd_und_section_ptr if
3828 info->shared. I don't know why, and that doesn't make sense,
3829 so I took it out. */
3830 *secp
= mips_elf_data_section_ptr
;
3833 case SHN_MIPS_SUNDEFINED
:
3834 *secp
= bfd_und_section_ptr
;
3838 if (SGI_COMPAT (abfd
)
3840 && info
->hash
->creator
== abfd
->xvec
3841 && strcmp (*namep
, "__rld_obj_head") == 0)
3843 struct elf_link_hash_entry
*h
;
3845 /* Mark __rld_obj_head as dynamic. */
3847 if (! (_bfd_generic_link_add_one_symbol
3848 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3849 (bfd_vma
) *valp
, (const char *) NULL
, false,
3850 get_elf_backend_data (abfd
)->collect
,
3851 (struct bfd_link_hash_entry
**) &h
)))
3853 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
3854 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3855 h
->type
= STT_OBJECT
;
3857 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3860 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3863 /* If this is a mips16 text symbol, add 1 to the value to make it
3864 odd. This will cause something like .word SYM to come up with
3865 the right value when it is loaded into the PC. */
3866 if (sym
->st_other
== STO_MIPS16
)
3872 /* Structure used to pass information to mips_elf_output_extsym. */
3877 struct bfd_link_info
*info
;
3878 struct ecoff_debug_info
*debug
;
3879 const struct ecoff_debug_swap
*swap
;
3883 /* This routine is used to write out ECOFF debugging external symbol
3884 information. It is called via mips_elf_link_hash_traverse. The
3885 ECOFF external symbol information must match the ELF external
3886 symbol information. Unfortunately, at this point we don't know
3887 whether a symbol is required by reloc information, so the two
3888 tables may wind up being different. We must sort out the external
3889 symbol information before we can set the final size of the .mdebug
3890 section, and we must set the size of the .mdebug section before we
3891 can relocate any sections, and we can't know which symbols are
3892 required by relocation until we relocate the sections.
3893 Fortunately, it is relatively unlikely that any symbol will be
3894 stripped but required by a reloc. In particular, it can not happen
3895 when generating a final executable. */
3898 mips_elf_output_extsym (h
, data
)
3899 struct mips_elf_link_hash_entry
*h
;
3902 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
3904 asection
*sec
, *output_section
;
3906 if (h
->root
.indx
== -2)
3908 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3909 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
3910 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3911 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
3913 else if (einfo
->info
->strip
== strip_all
3914 || (einfo
->info
->strip
== strip_some
3915 && bfd_hash_lookup (einfo
->info
->keep_hash
,
3916 h
->root
.root
.root
.string
,
3917 false, false) == NULL
))
3925 if (h
->esym
.ifd
== -2)
3928 h
->esym
.cobol_main
= 0;
3929 h
->esym
.weakext
= 0;
3930 h
->esym
.reserved
= 0;
3931 h
->esym
.ifd
= ifdNil
;
3932 h
->esym
.asym
.value
= 0;
3933 h
->esym
.asym
.st
= stGlobal
;
3935 if (SGI_COMPAT (einfo
->abfd
)
3936 && (h
->root
.root
.type
== bfd_link_hash_undefined
3937 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
3941 /* Use undefined class. Also, set class and type for some
3943 name
= h
->root
.root
.root
.string
;
3944 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
3945 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
3947 h
->esym
.asym
.sc
= scData
;
3948 h
->esym
.asym
.st
= stLabel
;
3949 h
->esym
.asym
.value
= 0;
3951 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
3953 h
->esym
.asym
.sc
= scAbs
;
3954 h
->esym
.asym
.st
= stLabel
;
3955 h
->esym
.asym
.value
=
3956 mips_elf_hash_table (einfo
->info
)->procedure_count
;
3958 else if (strcmp (name
, "_gp_disp") == 0)
3960 h
->esym
.asym
.sc
= scAbs
;
3961 h
->esym
.asym
.st
= stLabel
;
3962 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
3965 h
->esym
.asym
.sc
= scUndefined
;
3967 else if (h
->root
.root
.type
!= bfd_link_hash_defined
3968 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
3969 h
->esym
.asym
.sc
= scAbs
;
3974 sec
= h
->root
.root
.u
.def
.section
;
3975 output_section
= sec
->output_section
;
3977 /* When making a shared library and symbol h is the one from
3978 the another shared library, OUTPUT_SECTION may be null. */
3979 if (output_section
== NULL
)
3980 h
->esym
.asym
.sc
= scUndefined
;
3983 name
= bfd_section_name (output_section
->owner
, output_section
);
3985 if (strcmp (name
, ".text") == 0)
3986 h
->esym
.asym
.sc
= scText
;
3987 else if (strcmp (name
, ".data") == 0)
3988 h
->esym
.asym
.sc
= scData
;
3989 else if (strcmp (name
, ".sdata") == 0)
3990 h
->esym
.asym
.sc
= scSData
;
3991 else if (strcmp (name
, ".rodata") == 0
3992 || strcmp (name
, ".rdata") == 0)
3993 h
->esym
.asym
.sc
= scRData
;
3994 else if (strcmp (name
, ".bss") == 0)
3995 h
->esym
.asym
.sc
= scBss
;
3996 else if (strcmp (name
, ".sbss") == 0)
3997 h
->esym
.asym
.sc
= scSBss
;
3998 else if (strcmp (name
, ".init") == 0)
3999 h
->esym
.asym
.sc
= scInit
;
4000 else if (strcmp (name
, ".fini") == 0)
4001 h
->esym
.asym
.sc
= scFini
;
4003 h
->esym
.asym
.sc
= scAbs
;
4007 h
->esym
.asym
.reserved
= 0;
4008 h
->esym
.asym
.index
= indexNil
;
4011 if (h
->root
.root
.type
== bfd_link_hash_common
)
4012 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
4013 else if (h
->root
.root
.type
== bfd_link_hash_defined
4014 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4016 if (h
->esym
.asym
.sc
== scCommon
)
4017 h
->esym
.asym
.sc
= scBss
;
4018 else if (h
->esym
.asym
.sc
== scSCommon
)
4019 h
->esym
.asym
.sc
= scSBss
;
4021 sec
= h
->root
.root
.u
.def
.section
;
4022 output_section
= sec
->output_section
;
4023 if (output_section
!= NULL
)
4024 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
4025 + sec
->output_offset
4026 + output_section
->vma
);
4028 h
->esym
.asym
.value
= 0;
4030 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4032 /* Set type and value for a symbol with a function stub. */
4033 h
->esym
.asym
.st
= stProc
;
4034 sec
= h
->root
.root
.u
.def
.section
;
4036 h
->esym
.asym
.value
= 0;
4039 output_section
= sec
->output_section
;
4040 if (output_section
!= NULL
)
4041 h
->esym
.asym
.value
= (h
->root
.plt
.offset
4042 + sec
->output_offset
4043 + output_section
->vma
);
4045 h
->esym
.asym
.value
= 0;
4052 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
4053 h
->root
.root
.root
.string
,
4056 einfo
->failed
= true;
4063 /* Create a runtime procedure table from the .mdebug section. */
4066 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
4069 struct bfd_link_info
*info
;
4071 struct ecoff_debug_info
*debug
;
4073 const struct ecoff_debug_swap
*swap
;
4074 HDRR
*hdr
= &debug
->symbolic_header
;
4076 struct rpdr_ext
*erp
;
4078 struct pdr_ext
*epdr
;
4079 struct sym_ext
*esym
;
4082 unsigned long size
, count
;
4083 unsigned long sindex
;
4087 const char *no_name_func
= _("static procedure (no name)");
4095 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4097 sindex
= strlen (no_name_func
) + 1;
4098 count
= hdr
->ipdMax
;
4101 size
= swap
->external_pdr_size
;
4103 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
4107 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
4110 size
= sizeof (RPDR
);
4111 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
4115 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
4119 count
= hdr
->isymMax
;
4120 size
= swap
->external_sym_size
;
4121 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
4125 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
4128 count
= hdr
->issMax
;
4129 ss
= (char *) bfd_malloc (count
);
4132 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
4135 count
= hdr
->ipdMax
;
4136 for (i
= 0; i
< count
; i
++, rp
++)
4138 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
4139 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
4140 rp
->adr
= sym
.value
;
4141 rp
->regmask
= pdr
.regmask
;
4142 rp
->regoffset
= pdr
.regoffset
;
4143 rp
->fregmask
= pdr
.fregmask
;
4144 rp
->fregoffset
= pdr
.fregoffset
;
4145 rp
->frameoffset
= pdr
.frameoffset
;
4146 rp
->framereg
= pdr
.framereg
;
4147 rp
->pcreg
= pdr
.pcreg
;
4149 sv
[i
] = ss
+ sym
.iss
;
4150 sindex
+= strlen (sv
[i
]) + 1;
4154 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
4155 size
= BFD_ALIGN (size
, 16);
4156 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
4159 mips_elf_hash_table (info
)->procedure_count
= 0;
4163 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
4165 erp
= (struct rpdr_ext
*) rtproc
;
4166 memset (erp
, 0, sizeof (struct rpdr_ext
));
4168 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
4169 strcpy (str
, no_name_func
);
4170 str
+= strlen (no_name_func
) + 1;
4171 for (i
= 0; i
< count
; i
++)
4173 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
4174 strcpy (str
, sv
[i
]);
4175 str
+= strlen (sv
[i
]) + 1;
4177 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
4179 /* Set the size and contents of .rtproc section. */
4180 s
->_raw_size
= size
;
4181 s
->contents
= (bfd_byte
*) rtproc
;
4183 /* Skip this section later on (I don't think this currently
4184 matters, but someday it might). */
4185 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
4214 /* A comparison routine used to sort .gptab entries. */
4217 gptab_compare (p1
, p2
)
4221 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
4222 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
4224 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
4227 /* We need to use a special link routine to handle the .reginfo and
4228 the .mdebug sections. We need to merge all instances of these
4229 sections together, not write them all out sequentially. */
4232 mips_elf_final_link (abfd
, info
)
4234 struct bfd_link_info
*info
;
4238 struct bfd_link_order
*p
;
4239 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
4240 asection
*rtproc_sec
;
4241 Elf32_RegInfo reginfo
;
4242 struct ecoff_debug_info debug
;
4243 const struct ecoff_debug_swap
*swap
4244 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4245 HDRR
*symhdr
= &debug
.symbolic_header
;
4246 PTR mdebug_handle
= NULL
;
4248 /* If all the things we linked together were PIC, but we're
4249 producing an executable (rather than a shared object), then the
4250 resulting file is CPIC (i.e., it calls PIC code.) */
4252 && !info
->relocateable
4253 && elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
4255 elf_elfheader (abfd
)->e_flags
&= ~EF_MIPS_PIC
;
4256 elf_elfheader (abfd
)->e_flags
|= EF_MIPS_CPIC
;
4259 /* On IRIX5, we omit the .options section. On IRIX6, however, we
4260 include it, even though we don't process it quite right. (Some
4261 entries are supposed to be merged.) Empirically, we seem to be
4262 better off including it then not. */
4263 if (IRIX_COMPAT (abfd
) == ict_irix5
)
4264 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
4266 if (strcmp ((*secpp
)->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
4268 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
4269 if (p
->type
== bfd_indirect_link_order
)
4270 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
4271 (*secpp
)->link_order_head
= NULL
;
4272 *secpp
= (*secpp
)->next
;
4273 --abfd
->section_count
;
4279 /* Get a value for the GP register. */
4280 if (elf_gp (abfd
) == 0)
4282 struct bfd_link_hash_entry
*h
;
4284 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4285 if (h
!= (struct bfd_link_hash_entry
*) NULL
4286 && h
->type
== bfd_link_hash_defined
)
4287 elf_gp (abfd
) = (h
->u
.def
.value
4288 + h
->u
.def
.section
->output_section
->vma
4289 + h
->u
.def
.section
->output_offset
);
4290 else if (info
->relocateable
)
4294 /* Find the GP-relative section with the lowest offset. */
4296 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4298 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
4301 /* And calculate GP relative to that. */
4302 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
4306 /* If the relocate_section function needs to do a reloc
4307 involving the GP value, it should make a reloc_dangerous
4308 callback to warn that GP is not defined. */
4312 /* Go through the sections and collect the .reginfo and .mdebug
4316 gptab_data_sec
= NULL
;
4317 gptab_bss_sec
= NULL
;
4318 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4320 if (strcmp (o
->name
, ".reginfo") == 0)
4322 memset (®info
, 0, sizeof reginfo
);
4324 /* We have found the .reginfo section in the output file.
4325 Look through all the link_orders comprising it and merge
4326 the information together. */
4327 for (p
= o
->link_order_head
;
4328 p
!= (struct bfd_link_order
*) NULL
;
4331 asection
*input_section
;
4333 Elf32_External_RegInfo ext
;
4336 if (p
->type
!= bfd_indirect_link_order
)
4338 if (p
->type
== bfd_fill_link_order
)
4343 input_section
= p
->u
.indirect
.section
;
4344 input_bfd
= input_section
->owner
;
4346 /* The linker emulation code has probably clobbered the
4347 size to be zero bytes. */
4348 if (input_section
->_raw_size
== 0)
4349 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
4351 if (! bfd_get_section_contents (input_bfd
, input_section
,
4357 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
4359 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
4360 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
4361 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
4362 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
4363 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
4365 /* ri_gp_value is set by the function
4366 mips_elf32_section_processing when the section is
4367 finally written out. */
4369 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4370 elf_link_input_bfd ignores this section. */
4371 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4374 /* Size has been set in mips_elf_always_size_sections */
4375 BFD_ASSERT(o
->_raw_size
== sizeof (Elf32_External_RegInfo
));
4377 /* Skip this section later on (I don't think this currently
4378 matters, but someday it might). */
4379 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4384 if (strcmp (o
->name
, ".mdebug") == 0)
4386 struct extsym_info einfo
;
4388 /* We have found the .mdebug section in the output file.
4389 Look through all the link_orders comprising it and merge
4390 the information together. */
4391 symhdr
->magic
= swap
->sym_magic
;
4392 /* FIXME: What should the version stamp be? */
4394 symhdr
->ilineMax
= 0;
4398 symhdr
->isymMax
= 0;
4399 symhdr
->ioptMax
= 0;
4400 symhdr
->iauxMax
= 0;
4402 symhdr
->issExtMax
= 0;
4405 symhdr
->iextMax
= 0;
4407 /* We accumulate the debugging information itself in the
4408 debug_info structure. */
4410 debug
.external_dnr
= NULL
;
4411 debug
.external_pdr
= NULL
;
4412 debug
.external_sym
= NULL
;
4413 debug
.external_opt
= NULL
;
4414 debug
.external_aux
= NULL
;
4416 debug
.ssext
= debug
.ssext_end
= NULL
;
4417 debug
.external_fdr
= NULL
;
4418 debug
.external_rfd
= NULL
;
4419 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4421 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4422 if (mdebug_handle
== (PTR
) NULL
)
4425 if (SGI_COMPAT (abfd
))
4431 static const char * const name
[] =
4432 { ".text", ".init", ".fini", ".data",
4433 ".rodata", ".sdata", ".sbss", ".bss" };
4434 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
4435 scRData
, scSData
, scSBss
, scBss
};
4438 esym
.cobol_main
= 0;
4442 esym
.asym
.iss
= issNil
;
4443 esym
.asym
.st
= stLocal
;
4444 esym
.asym
.reserved
= 0;
4445 esym
.asym
.index
= indexNil
;
4447 for (i
= 0; i
< 8; i
++)
4449 esym
.asym
.sc
= sc
[i
];
4450 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4453 esym
.asym
.value
= s
->vma
;
4454 last
= s
->vma
+ s
->_raw_size
;
4457 esym
.asym
.value
= last
;
4459 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4465 for (p
= o
->link_order_head
;
4466 p
!= (struct bfd_link_order
*) NULL
;
4469 asection
*input_section
;
4471 const struct ecoff_debug_swap
*input_swap
;
4472 struct ecoff_debug_info input_debug
;
4476 if (p
->type
!= bfd_indirect_link_order
)
4478 if (p
->type
== bfd_fill_link_order
)
4483 input_section
= p
->u
.indirect
.section
;
4484 input_bfd
= input_section
->owner
;
4486 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4487 || (get_elf_backend_data (input_bfd
)
4488 ->elf_backend_ecoff_debug_swap
) == NULL
)
4490 /* I don't know what a non MIPS ELF bfd would be
4491 doing with a .mdebug section, but I don't really
4492 want to deal with it. */
4496 input_swap
= (get_elf_backend_data (input_bfd
)
4497 ->elf_backend_ecoff_debug_swap
);
4499 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
4501 /* The ECOFF linking code expects that we have already
4502 read in the debugging information and set up an
4503 ecoff_debug_info structure, so we do that now. */
4504 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
4508 if (! (bfd_ecoff_debug_accumulate
4509 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
4510 &input_debug
, input_swap
, info
)))
4513 /* Loop through the external symbols. For each one with
4514 interesting information, try to find the symbol in
4515 the linker global hash table and save the information
4516 for the output external symbols. */
4517 eraw_src
= input_debug
.external_ext
;
4518 eraw_end
= (eraw_src
4519 + (input_debug
.symbolic_header
.iextMax
4520 * input_swap
->external_ext_size
));
4522 eraw_src
< eraw_end
;
4523 eraw_src
+= input_swap
->external_ext_size
)
4527 struct mips_elf_link_hash_entry
*h
;
4529 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4530 if (ext
.asym
.sc
== scNil
4531 || ext
.asym
.sc
== scUndefined
4532 || ext
.asym
.sc
== scSUndefined
)
4535 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4536 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
4537 name
, false, false, true);
4538 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4544 < input_debug
.symbolic_header
.ifdMax
);
4545 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4551 /* Free up the information we just read. */
4552 free (input_debug
.line
);
4553 free (input_debug
.external_dnr
);
4554 free (input_debug
.external_pdr
);
4555 free (input_debug
.external_sym
);
4556 free (input_debug
.external_opt
);
4557 free (input_debug
.external_aux
);
4558 free (input_debug
.ss
);
4559 free (input_debug
.ssext
);
4560 free (input_debug
.external_fdr
);
4561 free (input_debug
.external_rfd
);
4562 free (input_debug
.external_ext
);
4564 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4565 elf_link_input_bfd ignores this section. */
4566 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4569 if (SGI_COMPAT (abfd
) && info
->shared
)
4571 /* Create .rtproc section. */
4572 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4573 if (rtproc_sec
== NULL
)
4575 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4576 | SEC_LINKER_CREATED
| SEC_READONLY
);
4578 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4579 if (rtproc_sec
== NULL
4580 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4581 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
4585 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
4586 info
, rtproc_sec
, &debug
))
4590 /* Build the external symbol information. */
4593 einfo
.debug
= &debug
;
4595 einfo
.failed
= false;
4596 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4597 mips_elf_output_extsym
,
4602 /* Set the size of the .mdebug section. */
4603 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4605 /* Skip this section later on (I don't think this currently
4606 matters, but someday it might). */
4607 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4612 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4614 const char *subname
;
4617 Elf32_External_gptab
*ext_tab
;
4620 /* The .gptab.sdata and .gptab.sbss sections hold
4621 information describing how the small data area would
4622 change depending upon the -G switch. These sections
4623 not used in executables files. */
4624 if (! info
->relocateable
)
4628 for (p
= o
->link_order_head
;
4629 p
!= (struct bfd_link_order
*) NULL
;
4632 asection
*input_section
;
4634 if (p
->type
!= bfd_indirect_link_order
)
4636 if (p
->type
== bfd_fill_link_order
)
4641 input_section
= p
->u
.indirect
.section
;
4643 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4644 elf_link_input_bfd ignores this section. */
4645 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4648 /* Skip this section later on (I don't think this
4649 currently matters, but someday it might). */
4650 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4652 /* Really remove the section. */
4653 for (secpp
= &abfd
->sections
;
4655 secpp
= &(*secpp
)->next
)
4657 *secpp
= (*secpp
)->next
;
4658 --abfd
->section_count
;
4663 /* There is one gptab for initialized data, and one for
4664 uninitialized data. */
4665 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4667 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4671 (*_bfd_error_handler
)
4672 (_("%s: illegal section name `%s'"),
4673 bfd_get_filename (abfd
), o
->name
);
4674 bfd_set_error (bfd_error_nonrepresentable_section
);
4678 /* The linker script always combines .gptab.data and
4679 .gptab.sdata into .gptab.sdata, and likewise for
4680 .gptab.bss and .gptab.sbss. It is possible that there is
4681 no .sdata or .sbss section in the output file, in which
4682 case we must change the name of the output section. */
4683 subname
= o
->name
+ sizeof ".gptab" - 1;
4684 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4686 if (o
== gptab_data_sec
)
4687 o
->name
= ".gptab.data";
4689 o
->name
= ".gptab.bss";
4690 subname
= o
->name
+ sizeof ".gptab" - 1;
4691 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4694 /* Set up the first entry. */
4696 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
4699 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4700 tab
[0].gt_header
.gt_unused
= 0;
4702 /* Combine the input sections. */
4703 for (p
= o
->link_order_head
;
4704 p
!= (struct bfd_link_order
*) NULL
;
4707 asection
*input_section
;
4711 bfd_size_type gpentry
;
4713 if (p
->type
!= bfd_indirect_link_order
)
4715 if (p
->type
== bfd_fill_link_order
)
4720 input_section
= p
->u
.indirect
.section
;
4721 input_bfd
= input_section
->owner
;
4723 /* Combine the gptab entries for this input section one
4724 by one. We know that the input gptab entries are
4725 sorted by ascending -G value. */
4726 size
= bfd_section_size (input_bfd
, input_section
);
4728 for (gpentry
= sizeof (Elf32_External_gptab
);
4730 gpentry
+= sizeof (Elf32_External_gptab
))
4732 Elf32_External_gptab ext_gptab
;
4733 Elf32_gptab int_gptab
;
4739 if (! (bfd_get_section_contents
4740 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4741 gpentry
, sizeof (Elf32_External_gptab
))))
4747 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
4749 val
= int_gptab
.gt_entry
.gt_g_value
;
4750 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4753 for (look
= 1; look
< c
; look
++)
4755 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4756 tab
[look
].gt_entry
.gt_bytes
+= add
;
4758 if (tab
[look
].gt_entry
.gt_g_value
== val
)
4764 Elf32_gptab
*new_tab
;
4767 /* We need a new table entry. */
4768 new_tab
= ((Elf32_gptab
*)
4769 bfd_realloc ((PTR
) tab
,
4770 (c
+ 1) * sizeof (Elf32_gptab
)));
4771 if (new_tab
== NULL
)
4777 tab
[c
].gt_entry
.gt_g_value
= val
;
4778 tab
[c
].gt_entry
.gt_bytes
= add
;
4780 /* Merge in the size for the next smallest -G
4781 value, since that will be implied by this new
4784 for (look
= 1; look
< c
; look
++)
4786 if (tab
[look
].gt_entry
.gt_g_value
< val
4788 || (tab
[look
].gt_entry
.gt_g_value
4789 > tab
[max
].gt_entry
.gt_g_value
)))
4793 tab
[c
].gt_entry
.gt_bytes
+=
4794 tab
[max
].gt_entry
.gt_bytes
;
4799 last
= int_gptab
.gt_entry
.gt_bytes
;
4802 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4803 elf_link_input_bfd ignores this section. */
4804 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4807 /* The table must be sorted by -G value. */
4809 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
4811 /* Swap out the table. */
4812 ext_tab
= ((Elf32_External_gptab
*)
4813 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
4814 if (ext_tab
== NULL
)
4820 for (i
= 0; i
< c
; i
++)
4821 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
4824 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
4825 o
->contents
= (bfd_byte
*) ext_tab
;
4827 /* Skip this section later on (I don't think this currently
4828 matters, but someday it might). */
4829 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4833 /* Invoke the regular ELF backend linker to do all the work. */
4834 if (! bfd_elf32_bfd_final_link (abfd
, info
))
4837 /* Now write out the computed sections. */
4839 if (reginfo_sec
!= (asection
*) NULL
)
4841 Elf32_External_RegInfo ext
;
4843 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
4844 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4845 (file_ptr
) 0, sizeof ext
))
4849 if (mdebug_sec
!= (asection
*) NULL
)
4851 BFD_ASSERT (abfd
->output_has_begun
);
4852 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4854 mdebug_sec
->filepos
))
4857 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4860 if (gptab_data_sec
!= (asection
*) NULL
)
4862 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4863 gptab_data_sec
->contents
,
4865 gptab_data_sec
->_raw_size
))
4869 if (gptab_bss_sec
!= (asection
*) NULL
)
4871 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4872 gptab_bss_sec
->contents
,
4874 gptab_bss_sec
->_raw_size
))
4878 if (SGI_COMPAT (abfd
))
4880 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4881 if (rtproc_sec
!= NULL
)
4883 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
4884 rtproc_sec
->contents
,
4886 rtproc_sec
->_raw_size
))
4894 /* Handle a MIPS ELF HI16 reloc. */
4897 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
4899 Elf_Internal_Rela
*relhi
;
4900 Elf_Internal_Rela
*rello
;
4907 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4909 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4912 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4914 if ((addlo
& 0x8000) != 0)
4916 if ((addend
& 0x8000) != 0)
4919 bfd_put_32 (input_bfd
,
4920 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
4921 contents
+ relhi
->r_offset
);
4924 /* Handle a MIPS ELF local GOT16 reloc. */
4927 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
4932 Elf_Internal_Rela
*relhi
;
4933 Elf_Internal_Rela
*rello
;
4937 unsigned int assigned_gotno
;
4943 bfd_byte
*got_contents
;
4944 struct mips_got_info
*g
;
4946 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
4948 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
4951 addend
+= ((insn
& 0xffff) << 16) + addlo
;
4953 if ((addlo
& 0x8000) != 0)
4955 if ((addend
& 0x8000) != 0)
4958 /* Get a got entry representing requested hipage. */
4959 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4960 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4961 BFD_ASSERT (g
!= NULL
);
4963 assigned_gotno
= g
->assigned_gotno
;
4964 got_contents
= sgot
->contents
;
4965 hipage
= addend
& 0xffff0000;
4967 for (i
= MIPS_RESERVED_GOTNO
; i
< assigned_gotno
; i
++)
4969 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
4970 if (hipage
== (address
& 0xffff0000))
4974 if (i
== assigned_gotno
)
4976 if (assigned_gotno
>= g
->local_gotno
)
4978 (*_bfd_error_handler
)
4979 (_("more got entries are needed for hipage relocations"));
4980 bfd_set_error (bfd_error_bad_value
);
4984 bfd_put_32 (input_bfd
, hipage
, got_contents
+ assigned_gotno
* 4);
4985 ++g
->assigned_gotno
;
4988 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
4989 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
4990 contents
+ relhi
->r_offset
);
4995 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
4998 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
5000 Elf_Internal_Rela
*rel
;
5006 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5007 bfd_put_32 (input_bfd
,
5008 (insn
& 0xffff0000) | (offset
& 0xffff),
5009 contents
+ rel
->r_offset
);
5012 /* Returns the GOT section for ABFD. */
5015 mips_elf_got_section (abfd
)
5018 return bfd_get_section_by_name (abfd
, ".got");
5021 /* Returns the GOT information associated with the link indicated by
5022 INFO. If SGOTP is non-NULL, it is filled in with the GOT
5025 static struct mips_got_info
*
5026 mips_elf_got_info (abfd
, sgotp
)
5031 struct mips_got_info
*g
;
5033 sgot
= mips_elf_got_section (abfd
);
5034 BFD_ASSERT (sgot
!= NULL
);
5035 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5036 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5037 BFD_ASSERT (g
!= NULL
);
5044 /* Sign-extend VALUE, which has the indicated number of BITS. */
5047 mips_elf_sign_extend (value
, bits
)
5051 if (value
& (1 << (bits
- 1)))
5052 /* VALUE is negative. */
5053 value
|= ((bfd_vma
) - 1) << bits
;
5058 /* Return non-zero if the indicated VALUE has overflowed the maximum
5059 range expressable by a signed number with the indicated number of
5063 mips_elf_overflow_p (value
, bits
)
5067 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
5069 if (svalue
> (1 << (bits
- 1)) - 1)
5070 /* The value is too big. */
5072 else if (svalue
< -(1 << (bits
- 1)))
5073 /* The value is too small. */
5080 /* Calculate the %high function. */
5083 mips_elf_high (value
)
5086 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
5089 /* Calculate the %higher function. */
5092 mips_elf_higher (value
)
5096 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
5099 return (bfd_vma
) -1;
5103 /* Calculate the %highest function. */
5106 mips_elf_highest (value
)
5110 return ((value
+ (bfd_vma
) 0x800080008000) > 48) & 0xffff;
5113 return (bfd_vma
) -1;
5117 /* Returns the GOT index for the global symbol indicated by H. */
5120 mips_elf_global_got_index (abfd
, h
)
5122 struct elf_link_hash_entry
*h
;
5126 struct mips_got_info
*g
;
5128 g
= mips_elf_got_info (abfd
, &sgot
);
5130 /* Once we determine the global GOT entry with the lowest dynamic
5131 symbol table index, we must put all dynamic symbols with greater
5132 indices into the GOT. That makes it easy to calculate the GOT
5134 BFD_ASSERT (h
->dynindx
>= g
->global_gotsym
->dynindx
);
5135 index
= (h
->dynindx
- g
->global_gotsym
->dynindx
+ g
->local_gotno
) * 4;
5136 BFD_ASSERT (index
< sgot
->_raw_size
);
5141 /* Returns the offset for the entry at the INDEXth position
5145 mips_elf_got_offset_from_index (dynobj
, output_bfd
, index
)
5152 char *error_message
;
5154 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5155 gp
= _bfd_get_gp_value (output_bfd
);
5156 return (sgot
->output_section
->vma
+ sgot
->output_offset
+ index
-
5160 /* If H is a symbol that needs a global GOT entry, but has a dynamic
5161 symbol table index lower than any we've seen to date, record it for
5165 mips_elf_record_global_got_symbol (h
, info
, g
)
5166 struct elf_link_hash_entry
*h
;
5167 struct bfd_link_info
*info
;
5168 struct mips_got_info
*g
;
5170 /* A global symbol in the GOT must also be in the dynamic symbol
5172 if (h
->dynindx
== -1
5173 && !bfd_elf32_link_record_dynamic_symbol (info
, h
))
5176 /* If we've already marked this entry as need GOT space, we don't
5177 need to do it again. */
5178 if (h
->got
.offset
!= (bfd_vma
) - 1)
5181 /* By setting this to a value other than -1, we are indicating that
5182 there needs to be a GOT entry for H. */
5188 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
5189 the dynamic symbols. */
5191 struct mips_elf_hash_sort_data
5193 /* The symbol in the global GOT with the lowest dynamic symbol table
5195 struct elf_link_hash_entry
*low
;
5196 /* The least dynamic symbol table index corresponding to a symbol
5197 with a GOT entry. */
5198 long min_got_dynindx
;
5199 /* The greatest dynamic symbol table index not corresponding to a
5200 symbol without a GOT entry. */
5201 long max_non_got_dynindx
;
5204 /* If H needs a GOT entry, assign it the highest available dynamic
5205 index. Otherwise, assign it the lowest available dynamic
5209 mips_elf_sort_hash_table_f (h
, data
)
5210 struct mips_elf_link_hash_entry
*h
;
5213 struct mips_elf_hash_sort_data
*hsd
5214 = (struct mips_elf_hash_sort_data
*) data
;
5216 /* Symbols without dynamic symbol table entries aren't interesting
5218 if (h
->root
.dynindx
== -1)
5221 if (h
->root
.got
.offset
!= 0)
5222 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
5225 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
5226 hsd
->low
= (struct elf_link_hash_entry
*) h
;
5232 /* Sort the dynamic symbol table so that symbols that need GOT entries
5233 appear towards the end. This reduces the amount of GOT space
5237 mips_elf_sort_hash_table (info
)
5238 struct bfd_link_info
*info
;
5240 struct mips_elf_hash_sort_data hsd
;
5241 struct mips_got_info
*g
;
5244 dynobj
= elf_hash_table (info
)->dynobj
;
5247 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
;
5248 hsd
.max_non_got_dynindx
= 1;
5249 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
5250 elf_hash_table (info
)),
5251 mips_elf_sort_hash_table_f
,
5254 /* There shoud have been enough room in the symbol table to
5255 accomodate both the GOT and non-GOT symbols. */
5256 BFD_ASSERT (hsd
.min_got_dynindx
== hsd
.max_non_got_dynindx
);
5258 /* Now we know which dynamic symbol has the lowest dynamic symbol
5259 table index in the GOT. */
5260 g
= mips_elf_got_info (dynobj
, NULL
);
5261 g
->global_gotsym
= hsd
.low
;
5266 /* Create a local GOT entry for VALUE. Return the index of the entry,
5267 or -1 if it could not be created. */
5270 mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
)
5272 struct mips_got_info
*g
;
5276 if (g
->assigned_gotno
>= g
->local_gotno
)
5278 /* We didn't allocate enough space in the GOT. */
5279 (*_bfd_error_handler
)
5280 (_("not enough GOT space for local GOT entries"));
5281 bfd_set_error (bfd_error_bad_value
);
5282 return (bfd_vma
) -1;
5285 bfd_put_32 (abfd
, value
, sgot
->contents
+ 4 * g
->assigned_gotno
);
5286 return 4 * g
->assigned_gotno
++;
5289 /* Returns the GOT offset at which the indicated address can be found.
5290 If there is not yet a GOT entry for this value, create one. Returns
5291 -1 if no satisfactory GOT offset can be found. */
5294 mips_elf_local_got_index (abfd
, info
, value
)
5296 struct bfd_link_info
*info
;
5300 struct mips_got_info
*g
;
5303 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
5305 /* Look to see if we already have an appropriate entry. */
5306 for (entry
= sgot
->contents
+ 4 * MIPS_RESERVED_GOTNO
;
5307 entry
!= sgot
->contents
+ 4 * g
->assigned_gotno
;
5310 bfd_vma address
= bfd_get_32 (abfd
, entry
);
5312 if (address
== value
)
5313 return entry
- sgot
->contents
;
5316 return mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
5319 /* Find a GOT entry that is within 32KB of the VALUE. These entries
5320 are supposed to be placed at small offsets in the GOT, i.e.,
5321 within 32KB of GP. Return the index into the GOT for this page,
5322 and store the offset from this entry to the desired address in
5323 OFFSETP, if it is non-NULL. */
5326 mips_elf_got_page (abfd
, info
, value
, offsetp
)
5328 struct bfd_link_info
*info
;
5333 struct mips_got_info
*g
;
5335 bfd_byte
*last_entry
;
5339 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
5341 /* Look to see if we aleady have an appropriate entry. */
5342 last_entry
= sgot
->contents
+ 4 * g
->assigned_gotno
;
5343 for (entry
= sgot
->contents
+ 4 * MIPS_RESERVED_GOTNO
;
5344 entry
!= last_entry
;
5347 address
= bfd_get_32 (abfd
, entry
);
5348 if (!mips_elf_overflow_p (value
- address
, 16))
5350 /* This entry will serve as the page pointer. We can add a
5351 16-bit number to it to get the actual address. */
5352 index
= entry
- sgot
->contents
;
5357 /* If we didn't have an appropriate entry, we create one now. */
5358 if (entry
== last_entry
)
5359 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
5363 address
= bfd_get_32 (abfd
, entry
);
5364 *offsetp
= value
- address
;
5370 /* Find a GOT entry whose higher-order 16 bits are the same as those
5371 for value. Return the index into the GOT for this entry. */
5374 mips_elf_got16_entry (abfd
, info
, value
)
5376 struct bfd_link_info
*info
;
5380 struct mips_got_info
*g
;
5382 bfd_byte
*last_entry
;
5386 value
&= 0xffff0000;
5387 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
5389 /* Look to see if we already have an appropriate entry. */
5390 last_entry
= sgot
->contents
+ 4 * g
->assigned_gotno
;
5391 for (entry
= sgot
->contents
+ 4 * MIPS_RESERVED_GOTNO
;
5392 entry
!= last_entry
;
5395 address
= bfd_get_32 (abfd
, entry
);
5396 if (address
& 0xffff0000 == value
)
5398 /* This entry has the right high-order 16 bits. */
5399 index
= 4 * (entry
- sgot
->contents
);
5404 /* If we didn't have an appropriate entry, we create one now. */
5405 if (entry
== last_entry
)
5406 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
5411 /* Sets *ADDENDP to the addend for the first R_MIPS_LO16 relocation
5412 found, beginning with RELOCATION. RELEND is one-past-the-end of
5413 the relocation table. */
5416 mips_elf_next_lo16_addend (relocation
, relend
, addendp
)
5417 Elf_Internal_Rela
*relocation
;
5418 Elf_Internal_Rela
*relend
;
5421 /* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be
5422 immediately following. However, for the IRIX6 ABI, the next
5423 relocation may be a composed relocation consisting of several
5424 relocations for the same address. In that case, the R_MIPS_LO16
5425 relo!scation may occur as one of these. We permit a similar
5426 extension in general, as that is useful for GCC. */
5427 while (relocation
< relend
)
5429 if (ELF32_R_TYPE (relocation
->r_info
) == R_MIPS_LO16
)
5431 *addendp
= relocation
->r_addend
;
5438 /* We didn't find it. */
5442 /* Create a rel.dyn relocation for the dynamic linker to resolve. The
5443 relocatin is against the symbol with the dynamic symbol table index
5444 DYNINDX. REL is the original relocation, which is now being made
5448 mips_elf_create_dynamic_relocation (output_bfd
, info
, rel
, dynindx
,
5449 addend
, input_section
)
5451 struct bfd_link_info
*info
;
5452 Elf_Internal_Rela
*rel
;
5455 asection
*input_section
;
5457 Elf_Internal_Rel outrel
;
5463 r_type
= ELF32_R_TYPE (rel
->r_info
);
5464 dynobj
= elf_hash_table (info
)->dynobj
;
5465 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5466 BFD_ASSERT (sreloc
!= NULL
);
5470 /* The symbol for the relocation is the same as it was for the
5471 original relocation. */
5472 outrel
.r_info
= ELF32_R_INFO (dynindx
, R_MIPS_REL32
);
5474 /* The offset for the dynamic relocation is the same as for the
5475 original relocation, adjusted by the offset at which the original
5476 section is output. */
5477 if (elf_section_data (input_section
)->stab_info
== NULL
)
5478 outrel
.r_offset
= rel
->r_offset
;
5483 off
= (_bfd_stab_section_offset
5484 (output_bfd
, &elf_hash_table (info
)->stab_info
,
5486 &elf_section_data (input_section
)->stab_info
,
5488 if (off
== (bfd_vma
) -1)
5490 outrel
.r_offset
= off
;
5492 outrel
.r_offset
+= (input_section
->output_section
->vma
5493 + input_section
->output_offset
);
5495 /* If we've decided to skip this relocation, just output an emtpy
5498 memset (&outrel
, 0, sizeof (outrel
));
5500 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
5501 (((Elf32_External_Rel
*)
5503 + sreloc
->reloc_count
));
5504 ++sreloc
->reloc_count
;
5506 /* Make sure the output section is writable. The dynamic linker
5507 will be writing to it. */
5508 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
5511 /* On IRIX5, make an entry of compact relocation info. */
5512 if (! skip
&& IRIX_COMPAT (output_bfd
) == ict_irix5
)
5514 asection
* scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5519 Elf32_crinfo cptrel
;
5521 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5522 cptrel
.vaddr
= (rel
->r_offset
5523 + input_section
->output_section
->vma
5524 + input_section
->output_offset
);
5525 if (r_type
== R_MIPS_REL32
)
5526 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5528 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5529 mips_elf_set_cr_dist2to (cptrel
, 0);
5530 cptrel
.konst
= addend
;
5532 cr
= (scpt
->contents
5533 + sizeof (Elf32_External_compact_rel
));
5534 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5535 ((Elf32_External_crinfo
*) cr
5536 + scpt
->reloc_count
));
5537 ++scpt
->reloc_count
;
5541 return sreloc
->reloc_count
- 1;
5544 /* Calculate the value produced by the RELOCATION (which comes from
5545 the INPUT_BFD). The ADDEND is the addend to use for this
5546 RELOCATION; RELOCATION->R_ADDEND is ignored.
5548 The result of the relocation calculation is stored in VALUEP.
5550 This function returns bfd_reloc_continue if the caller need take no
5551 further action regarding this relocation, bfd_reloc_notsupported if
5552 something goes dramatically wrong, bfd_reloc_overflow if an
5553 overflow occurs, and bfd_reloc_ok to indicate success. */
5555 static bfd_reloc_status_type
5556 mips_elf_calculate_relocation (abfd
,
5570 asection
*input_section
;
5571 struct bfd_link_info
*info
;
5572 Elf_Internal_Rela
*relocation
;
5574 reloc_howto_type
*howto
;
5575 Elf_Internal_Rela
*relend
;
5576 Elf_Internal_Sym
*local_syms
;
5577 asection
**local_sections
;
5581 /* The eventual value we will return. */
5583 /* The address of the symbol against which the relocation is
5586 /* The final GP value to be used for the relocatable, executable, or
5587 shared object file being produced. */
5588 bfd_vma gp
= (bfd_vma
) - 1;
5589 /* The place (section offset or address) of the storage unit being
5592 /* The value of GP used to create the relocatable object. */
5593 bfd_vma gp0
= (bfd_vma
) - 1;
5594 /* The offset into the global offset table at which the address of
5595 the relocation entry symbol, adjusted by the addend, resides
5596 during execution. */
5597 bfd_vma g
= (bfd_vma
) - 1;
5598 /* The section in which the symbol referenced by the relocation is
5600 asection
*sec
= NULL
;
5601 struct mips_elf_link_hash_entry
* h
= NULL
;
5602 unsigned long r_symndx
;
5604 boolean gp_disp_p
= false;
5605 Elf_Internal_Shdr
*symtab_hdr
;
5608 boolean overflowed_p
;
5610 /* Parse the relocation. */
5611 r_symndx
= ELF32_R_SYM (relocation
->r_info
);
5612 r_type
= ELF32_R_TYPE (relocation
->r_info
);
5613 p
= (input_section
->output_section
->vma
5614 + input_section
->output_offset
5615 + relocation
->r_offset
);
5617 /* Assume that there will be no overflow. */
5618 overflowed_p
= false;
5620 /* Figure out whether or not the symbol is local. */
5621 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5622 if (elf_bad_symtab (input_bfd
))
5624 /* The symbol table does not follow the rule that local symbols
5625 must come before globals. */
5627 local_p
= local_sections
[r_symndx
] != NULL
;
5631 extsymoff
= symtab_hdr
->sh_info
;
5632 local_p
= r_symndx
< extsymoff
;
5635 /* Figure out the value of the symbol. */
5638 Elf_Internal_Sym
*sym
;
5640 sym
= local_syms
+ r_symndx
;
5641 sec
= local_sections
[r_symndx
];
5643 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
5644 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5645 symbol
+= sym
->st_value
;
5647 /* MIPS16 text labels should be treated as odd. */
5648 if (sym
->st_other
== STO_MIPS16
)
5651 /* Record the name of this symbol, for our caller. */
5652 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
5653 symtab_hdr
->sh_link
,
5656 *namep
= bfd_section_name (input_bfd
, sec
);
5660 /* For global symbols we look up the symbol in the hash-table. */
5661 h
= ((struct mips_elf_link_hash_entry
*)
5662 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
5663 /* Find the real hash-table entry for this symbol. */
5664 while (h
->root
.type
== bfd_link_hash_indirect
5665 || h
->root
.type
== bfd_link_hash_warning
)
5666 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
5668 /* Record the name of this symbol, for our caller. */
5669 *namep
= h
->root
.root
.root
.string
;
5671 /* See if this is the special _gp_disp symbol. Note that such a
5672 symbol must always be a global symbol. */
5673 if (strcmp (h
->root
.root
.root
.string
, "_gp_disp") == 0)
5675 /* Relocations against _gp_disp are permitted only with
5676 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
5677 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_LO16
)
5678 return bfd_reloc_notsupported
;
5683 /* If this symbol is defined, calculate its address. */
5684 if ((h
->root
.root
.type
== bfd_link_hash_defined
5685 || h
->root
.root
.type
== bfd_link_hash_defweak
)
5686 && h
->root
.root
.u
.def
.section
)
5688 sec
= h
->root
.root
.u
.def
.section
;
5689 if (sec
->output_section
)
5690 symbol
= (h
->root
.root
.u
.def
.value
5691 + sec
->output_section
->vma
5692 + sec
->output_offset
);
5694 symbol
= h
->root
.root
.u
.def
.value
;
5698 (*info
->callbacks
->undefined_symbol
)
5699 (info
, h
->root
.root
.root
.string
, input_bfd
,
5700 input_section
, relocation
->r_offset
);
5701 return bfd_reloc_undefined
;
5705 /* If we haven't already determined the GOT offset, or the GP value,
5706 and we're going to need it, get it now. */
5710 case R_MIPS_GOT_DISP
:
5711 case R_MIPS_GOT_HI16
:
5712 case R_MIPS_CALL_HI16
:
5713 case R_MIPS_GOT_LO16
:
5714 case R_MIPS_CALL_LO16
:
5715 /* Find the index into the GOT where this value is located. */
5718 BFD_ASSERT (addend
== 0);
5719 g
= mips_elf_global_got_index
5720 (elf_hash_table (info
)->dynobj
,
5721 (struct elf_link_hash_entry
*) h
);
5725 g
= mips_elf_local_got_index (abfd
, info
, symbol
+ addend
);
5726 if (g
== (bfd_vma
) -1)
5730 /* Convert GOT indices to actual offsets. */
5731 g
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
5737 case R_MIPS_GPREL16
:
5738 case R_MIPS_GPREL32
:
5739 gp0
= _bfd_get_gp_value (input_bfd
);
5740 gp
= _bfd_get_gp_value (abfd
);
5747 /* Figure out what kind of relocation is being performed. */
5751 return bfd_reloc_continue
;
5754 value
= symbol
+ mips_elf_sign_extend (addend
, 16);
5755 overflowed_p
= mips_elf_overflow_p (value
, 16);
5760 /* If we're creating a shared library, or this relocation is
5761 against a symbol in a shared library, then we can't know
5762 where the symbol will end up. So, we create a relocation
5763 record in the output, and leave the job up to the dynamic
5765 if (info
->shared
|| !sec
->output_section
)
5767 unsigned int reloc_index
;
5769 BFD_ASSERT (h
!= NULL
);
5771 = mips_elf_create_dynamic_relocation (abfd
,
5777 if (h
->min_dyn_reloc_index
== 0
5778 || reloc_index
< h
->min_dyn_reloc_index
)
5779 h
->min_dyn_reloc_index
= reloc_index
;
5780 value
= symbol
+ addend
;
5784 if (r_type
== R_MIPS_32
)
5785 value
= symbol
+ addend
;
5789 value
&= howto
->dst_mask
;
5794 value
= (((addend
<< 2) | (p
& 0xf0000000)) + symbol
) >> 2;
5796 value
= (mips_elf_sign_extend (addend
<< 2, 28) + symbol
) >> 2;
5797 value
&= howto
->dst_mask
;
5803 value
= mips_elf_high (addend
+ symbol
);
5804 value
&= howto
->dst_mask
;
5808 value
= mips_elf_high (addend
+ gp
- p
);
5809 overflowed_p
= mips_elf_overflow_p (value
, 16);
5815 value
= (symbol
+ addend
) & howto
->dst_mask
;
5818 value
= addend
+ gp
- p
+ 4;
5819 overflowed_p
= mips_elf_overflow_p (value
, 16);
5823 case R_MIPS_LITERAL
:
5824 /* Because we don't merge literal sections, we can handle this
5825 just like R_MIPS_GPREL16. In the long run, we should merge
5826 shared literals, and then we will need to additional work
5831 case R_MIPS_GPREL16
:
5833 value
= mips_elf_sign_extend (addend
, 16) + symbol
+ gp0
- gp
;
5835 value
= mips_elf_sign_extend (addend
, 16) + symbol
- gp
;
5836 overflowed_p
= mips_elf_overflow_p (value
, 16);
5842 value
= mips_elf_got16_entry (abfd
, info
, symbol
+ addend
);
5843 if (value
== (bfd_vma
) -1)
5846 = mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
5849 overflowed_p
= mips_elf_overflow_p (value
, 16);
5856 case R_MIPS_GOT_DISP
:
5858 overflowed_p
= mips_elf_overflow_p (value
, 16);
5861 case R_MIPS_GPREL32
:
5862 value
= (addend
+ symbol
+ gp0
- gp
) & howto
->dst_mask
;
5866 value
= mips_elf_sign_extend (addend
, 16) + symbol
- p
;
5867 overflowed_p
= mips_elf_overflow_p (value
, 16);
5870 case R_MIPS_GOT_HI16
:
5871 case R_MIPS_CALL_HI16
:
5872 /* We're allowed to handle these two relocations identically.
5873 The dynamic linker is allowed to handle the CALL relocations
5874 differently by creating a lazy evaluation stub. */
5876 value
= mips_elf_high (value
);
5877 value
&= howto
->dst_mask
;
5880 case R_MIPS_GOT_LO16
:
5881 case R_MIPS_CALL_LO16
:
5882 value
= g
& howto
->dst_mask
;
5886 value
= (symbol
+ addend
) & howto
->dst_mask
;
5889 case R_MIPS_GOT_PAGE
:
5890 value
= mips_elf_got_page (abfd
, info
, symbol
+ addend
, NULL
);
5891 if (value
== (bfd_vma
) -1)
5893 value
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
5896 overflowed_p
= mips_elf_overflow_p (value
, 16);
5899 case R_MIPS_GOT_OFST
:
5900 mips_elf_got_page (abfd
, info
, symbol
+ addend
, &value
);
5901 overflowed_p
= mips_elf_overflow_p (value
, 16);
5905 value
= symbol
- addend
;
5906 value
&= howto
->dst_mask
;
5910 value
= mips_elf_higher (addend
+ symbol
);
5911 value
&= howto
->dst_mask
;
5914 case R_MIPS_HIGHEST
:
5915 value
= mips_elf_highest (addend
+ symbol
);
5916 value
&= howto
->dst_mask
;
5919 case R_MIPS_SCN_DISP
:
5920 value
= symbol
+ addend
- sec
->output_offset
;
5921 value
&= howto
->dst_mask
;
5926 /* Both of these may be ignored. R_MIPS_JALR is an optimization
5927 hint; we could improve performance by honoring that hint. */
5928 return bfd_reloc_continue
;
5930 case R_MIPS_GNU_VTINHERIT
:
5931 case R_MIPS_GNU_VTENTRY
:
5932 /* We don't do anything with these at present. */
5933 return bfd_reloc_continue
;
5936 case R_MIPS16_GPREL
:
5937 /* These relocations, used for MIPS16, are not clearly
5938 documented anywhere. What do they do? */
5939 return bfd_reloc_notsupported
;
5942 /* An unrecognized relocation type. */
5943 return bfd_reloc_notsupported
;
5946 /* Store the VALUE for our caller. */
5948 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
5951 /* Obtain the field relocated by RELOCATION. */
5954 mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
)
5955 reloc_howto_type
*howto
;
5956 Elf_Internal_Rela
*relocation
;
5961 bfd_byte
*location
= contents
+ relocation
->r_offset
;
5963 switch (bfd_get_reloc_size (howto
))
5970 x
= bfd_get_8 (input_bfd
, location
);
5974 x
= bfd_get_16 (input_bfd
, location
);
5978 x
= bfd_get_32 (input_bfd
, location
);
5983 x
= bfd_get_64 (input_bfd
, location
);
5997 /* It has been determined that the result of the RELOCATION is the
5998 VALUE. Use HOWTO to place VALUE into the output file at the
5999 appropriate position. The SECTION is the section to which the
6002 Returns false if anything goes wrong. */
6005 mips_elf_perform_relocation (howto
, relocation
, value
, input_bfd
, contents
)
6006 reloc_howto_type
*howto
;
6007 Elf_Internal_Rela
*relocation
;
6013 bfd_byte
*location
= contents
+ relocation
->r_offset
;
6015 /* Obtain the current value. */
6016 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
6018 /* Clear the field we are setting. */
6019 x
&= ~howto
->dst_mask
;
6021 /* Set the field. */
6022 x
|= (value
& howto
->dst_mask
);
6024 /* Put the value into the output. */
6025 switch (bfd_get_reloc_size (howto
))
6032 bfd_put_8 (input_bfd
, x
, location
);
6036 bfd_put_16 (input_bfd
, x
, location
);
6040 bfd_put_32 (input_bfd
, x
, location
);
6045 bfd_put_64 (input_bfd
, x
, location
);
6057 /* Relocate a MIPS ELF section. */
6060 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
6061 contents
, relocs
, local_syms
, local_sections
)
6063 struct bfd_link_info
*info
;
6065 asection
*input_section
;
6067 Elf_Internal_Rela
*relocs
;
6068 Elf_Internal_Sym
*local_syms
;
6069 asection
**local_sections
;
6071 Elf_Internal_Shdr
*symtab_hdr
;
6074 asection
*sgot
, *sreloc
, *scpt
;
6077 Elf_Internal_Rela
*rel
;
6078 Elf_Internal_Rela
*relend
;
6079 struct mips_got_info
*g
;
6081 bfd_vma last_hi16_addend
;
6082 boolean next_relocation_for_same_address_p
= false;
6083 boolean use_saved_addend_p
= false;
6084 boolean last_hi16_addend_valid_p
= false;
6086 dynobj
= elf_hash_table (info
)->dynobj
;
6087 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
6091 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
6094 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
6097 if (elf_bad_symtab (input_bfd
))
6099 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
6104 locsymcount
= symtab_hdr
->sh_info
;
6105 extsymoff
= symtab_hdr
->sh_info
;
6108 gp
= _bfd_get_gp_value (output_bfd
);
6109 relend
= relocs
+ input_section
->reloc_count
;
6111 for (rel
= relocs
; rel
< relend
; ++rel
)
6116 reloc_howto_type
*howto
;
6118 /* Find the relocation howto for this relocation. */
6119 howto
= elf_mips_howto_table
+ ELF32_R_TYPE (rel
->r_info
);
6121 if (!use_saved_addend_p
)
6123 Elf_Internal_Shdr
*rel_hdr
;
6125 /* If these relocations were originally of the REL variety,
6126 we must pull the addend out of the field that will be
6127 relocated. Otherwise, we simply use the contents of the
6128 RELA relocation. To determine which flavor or relocation
6129 this is, we depend on the fact that the INPUT_SECTION's
6130 REL_HDR is read before its REL_HDR2. */
6131 rel_hdr
= &elf_section_data (input_section
)->rel_hdr
;
6132 if (rel
- relocs
>= rel_hdr
->sh_size
/ rel_hdr
->sh_entsize
)
6133 rel_hdr
= elf_section_data (input_section
)->rel_hdr2
;
6134 if (rel_hdr
->sh_entsize
== sizeof (Elf32_External_Rel
))
6136 int r_type
= ELF32_R_TYPE (rel
->r_info
);
6138 addend
= mips_elf_obtain_contents (howto
,
6142 addend
&= howto
->src_mask
;
6144 /* For some kinds of relocations, the ADDEND is a
6145 combination of the addend stored in two different
6147 if (r_type
== R_MIPS_HI16
|| r_type
== R_MIPS_GOT16
)
6149 /* Scan ahead to find a matching R_MIPS_LO16
6153 if (!mips_elf_next_lo16_addend (rel
, relend
, &l
))
6156 /* Save the high-order bit for later. When we
6157 encounter the R_MIPS_LO16 relocation we will need
6160 last_hi16_addend
= addend
;
6161 last_hi16_addend_valid_p
= true;
6163 /* Compute the combined addend. */
6166 else if (r_type
== R_MIPS_LO16
)
6168 /* Used the saved HI16 addend. */
6169 if (!last_hi16_addend_valid_p
)
6171 addend
|= last_hi16_addend
;
6175 addend
= rel
->r_addend
;
6178 /* In the N32 and 64-bit ABIs there may be multiple consecutive
6179 relocations for the same offset. In that case we are
6180 supposed to treat the output of each relocation as the addend
6182 if (rel
+ 1 < relend
&& rel
->r_offset
== (rel
+ 1)->r_offset
)
6183 use_saved_addend_p
= true;
6185 use_saved_addend_p
= false;
6187 /* Figure out what value we are supposed to relocate. */
6188 switch (mips_elf_calculate_relocation (output_bfd
,
6201 case bfd_reloc_continue
:
6202 /* There's nothing to do. */
6205 case bfd_reloc_undefined
:
6208 case bfd_reloc_notsupported
:
6212 case bfd_reloc_overflow
:
6213 if (use_saved_addend_p
)
6214 /* Ignore overflow until we reach the last relocation for
6215 a given location. */
6218 || ! ((*info
->callbacks
->reloc_overflow
)
6219 (info
, name
, howto
->name
, (bfd_vma
) 0,
6220 input_bfd
, input_section
, rel
->r_offset
)))
6233 /* If we've got another relocation for the address, keep going
6234 until we reach the last one. */
6235 if (use_saved_addend_p
)
6241 /* Actually perform the relocation. */
6242 mips_elf_perform_relocation (howto
, rel
, value
, input_bfd
,
6249 /* This hook function is called before the linker writes out a global
6250 symbol. We mark symbols as small common if appropriate. This is
6251 also where we undo the increment of the value for a mips16 symbol. */
6255 mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
6257 struct bfd_link_info
*info
;
6259 Elf_Internal_Sym
*sym
;
6260 asection
*input_sec
;
6262 /* If we see a common symbol, which implies a relocatable link, then
6263 if a symbol was small common in an input file, mark it as small
6264 common in the output file. */
6265 if (sym
->st_shndx
== SHN_COMMON
6266 && strcmp (input_sec
->name
, ".scommon") == 0)
6267 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
6269 if (sym
->st_other
== STO_MIPS16
6270 && (sym
->st_value
& 1) != 0)
6276 /* Functions for the dynamic linker. */
6278 /* The name of the dynamic interpreter. This is put in the .interp
6281 #define ELF_DYNAMIC_INTERPRETER(abfd) \
6282 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" : "/usr/lib/libc.so.1")
6284 /* Create dynamic sections when linking against a dynamic object. */
6287 mips_elf_create_dynamic_sections (abfd
, info
)
6289 struct bfd_link_info
*info
;
6291 struct elf_link_hash_entry
*h
;
6293 register asection
*s
;
6294 const char * const *namep
;
6296 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6297 | SEC_LINKER_CREATED
| SEC_READONLY
);
6299 /* Mips ABI requests the .dynamic section to be read only. */
6300 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6303 if (! bfd_set_section_flags (abfd
, s
, flags
))
6307 /* We need to create .got section. */
6308 if (! mips_elf_create_got_section (abfd
, info
))
6311 /* Create the .msym section on IRIX6. It is used by the dynamic
6312 linker to speed up dynamic relocations, and to avoid computing
6313 the ELF hash for symbols. */
6314 if (IRIX_COMPAT (abfd
) == ict_irix6
6315 && !mips_elf_create_msym_section (abfd
))
6318 /* Create .stub section. */
6319 if (bfd_get_section_by_name (abfd
,
6320 MIPS_ELF_STUB_SECTION_NAME (abfd
)) == NULL
)
6322 s
= bfd_make_section (abfd
, MIPS_ELF_STUB_SECTION_NAME (abfd
));
6324 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_CODE
)
6325 || ! bfd_set_section_alignment (abfd
, s
, 2))
6329 if (IRIX_COMPAT (abfd
) == ict_irix5
6331 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
6333 s
= bfd_make_section (abfd
, ".rld_map");
6335 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
6336 || ! bfd_set_section_alignment (abfd
, s
, 2))
6340 /* On IRIX5, we adjust add some additional symbols and change the
6341 alignments of several sections. There is no ABI documentation
6342 indicating that this is necessary on IRIX6, nor any evidence that
6343 the linker takes such action. */
6344 if (IRIX_COMPAT (abfd
) == ict_irix5
)
6346 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
6349 if (! (_bfd_generic_link_add_one_symbol
6350 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
6351 (bfd_vma
) 0, (const char *) NULL
, false,
6352 get_elf_backend_data (abfd
)->collect
,
6353 (struct bfd_link_hash_entry
**) &h
)))
6355 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6356 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6357 h
->type
= STT_SECTION
;
6359 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6363 /* We need to create a .compact_rel section. */
6364 if (! mips_elf_create_compact_rel_section (abfd
, info
))
6367 /* Change aligments of some sections. */
6368 s
= bfd_get_section_by_name (abfd
, ".hash");
6370 bfd_set_section_alignment (abfd
, s
, 4);
6371 s
= bfd_get_section_by_name (abfd
, ".dynsym");
6373 bfd_set_section_alignment (abfd
, s
, 4);
6374 s
= bfd_get_section_by_name (abfd
, ".dynstr");
6376 bfd_set_section_alignment (abfd
, s
, 4);
6377 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6379 bfd_set_section_alignment (abfd
, s
, 4);
6380 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6382 bfd_set_section_alignment (abfd
, s
, 4);
6388 if (! (_bfd_generic_link_add_one_symbol
6389 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
6390 (bfd_vma
) 0, (const char *) NULL
, false,
6391 get_elf_backend_data (abfd
)->collect
,
6392 (struct bfd_link_hash_entry
**) &h
)))
6394 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6395 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6396 h
->type
= STT_SECTION
;
6398 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6401 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
6403 /* __rld_map is a four byte word located in the .data section
6404 and is filled in by the rtld to contain a pointer to
6405 the _r_debug structure. Its symbol value will be set in
6406 mips_elf_finish_dynamic_symbol. */
6407 s
= bfd_get_section_by_name (abfd
, ".rld_map");
6408 BFD_ASSERT (s
!= NULL
);
6411 if (! (_bfd_generic_link_add_one_symbol
6412 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
6413 (bfd_vma
) 0, (const char *) NULL
, false,
6414 get_elf_backend_data (abfd
)->collect
,
6415 (struct bfd_link_hash_entry
**) &h
)))
6417 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6418 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6419 h
->type
= STT_OBJECT
;
6421 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6429 /* Create the .compact_rel section. */
6432 mips_elf_create_compact_rel_section (abfd
, info
)
6434 struct bfd_link_info
*info
;
6437 register asection
*s
;
6439 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
6441 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
6444 s
= bfd_make_section (abfd
, ".compact_rel");
6446 || ! bfd_set_section_flags (abfd
, s
, flags
)
6447 || ! bfd_set_section_alignment (abfd
, s
, 2))
6450 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
6456 /* Create the .got section to hold the global offset table. */
6459 mips_elf_create_got_section (abfd
, info
)
6461 struct bfd_link_info
*info
;
6464 register asection
*s
;
6465 struct elf_link_hash_entry
*h
;
6466 struct mips_got_info
*g
;
6468 /* This function may be called more than once. */
6469 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
6472 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6473 | SEC_LINKER_CREATED
);
6475 s
= bfd_make_section (abfd
, ".got");
6477 || ! bfd_set_section_flags (abfd
, s
, flags
)
6478 || ! bfd_set_section_alignment (abfd
, s
, 4))
6481 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
6482 linker script because we don't want to define the symbol if we
6483 are not creating a global offset table. */
6485 if (! (_bfd_generic_link_add_one_symbol
6486 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
6487 (bfd_vma
) 0, (const char *) NULL
, false,
6488 get_elf_backend_data (abfd
)->collect
,
6489 (struct bfd_link_hash_entry
**) &h
)))
6491 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
6492 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
6493 h
->type
= STT_OBJECT
;
6496 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
6499 /* The first several global offset table entries are reserved. */
6500 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
6502 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
6503 sizeof (struct mips_got_info
));
6506 g
->global_gotsym
= NULL
;
6507 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
6508 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
6509 if (elf_section_data (s
) == NULL
)
6512 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
6513 if (elf_section_data (s
) == NULL
)
6516 elf_section_data (s
)->tdata
= (PTR
) g
;
6517 elf_section_data (s
)->this_hdr
.sh_flags
6518 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
6523 /* Returns the .msym section for ABFD, creating it if it does not
6524 already exist. Returns NULL to indicate error. */
6527 mips_elf_create_msym_section (abfd
)
6532 s
= bfd_get_section_by_name (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
6535 s
= bfd_make_section (abfd
, MIPS_ELF_MSYM_SECTION_NAME (abfd
));
6537 || !bfd_set_section_flags (abfd
, s
,
6541 | SEC_LINKER_CREATED
6543 || !bfd_set_section_alignment (abfd
, s
, 2))
6550 /* Look through the relocs for a section during the first phase, and
6551 allocate space in the global offset table. */
6554 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
6556 struct bfd_link_info
*info
;
6558 const Elf_Internal_Rela
*relocs
;
6562 Elf_Internal_Shdr
*symtab_hdr
;
6563 struct elf_link_hash_entry
**sym_hashes
;
6564 struct mips_got_info
*g
;
6566 const Elf_Internal_Rela
*rel
;
6567 const Elf_Internal_Rela
*rel_end
;
6571 if (info
->relocateable
)
6574 dynobj
= elf_hash_table (info
)->dynobj
;
6575 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6576 sym_hashes
= elf_sym_hashes (abfd
);
6577 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
6579 /* Check for the mips16 stub sections. */
6581 name
= bfd_get_section_name (abfd
, sec
);
6582 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
6584 unsigned long r_symndx
;
6586 /* Look at the relocation information to figure out which symbol
6589 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6591 if (r_symndx
< extsymoff
6592 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6596 /* This stub is for a local symbol. This stub will only be
6597 needed if there is some relocation in this BFD, other
6598 than a 16 bit function call, which refers to this symbol. */
6599 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6601 Elf_Internal_Rela
*sec_relocs
;
6602 const Elf_Internal_Rela
*r
, *rend
;
6604 /* We can ignore stub sections when looking for relocs. */
6605 if ((o
->flags
& SEC_RELOC
) == 0
6606 || o
->reloc_count
== 0
6607 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
6608 sizeof FN_STUB
- 1) == 0
6609 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
6610 sizeof CALL_STUB
- 1) == 0
6611 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
6612 sizeof CALL_FP_STUB
- 1) == 0)
6615 sec_relocs
= (_bfd_elf32_link_read_relocs
6616 (abfd
, o
, (PTR
) NULL
,
6617 (Elf_Internal_Rela
*) NULL
,
6618 info
->keep_memory
));
6619 if (sec_relocs
== NULL
)
6622 rend
= sec_relocs
+ o
->reloc_count
;
6623 for (r
= sec_relocs
; r
< rend
; r
++)
6624 if (ELF32_R_SYM (r
->r_info
) == r_symndx
6625 && ELF32_R_TYPE (r
->r_info
) != R_MIPS16_26
)
6628 if (! info
->keep_memory
)
6637 /* There is no non-call reloc for this stub, so we do
6638 not need it. Since this function is called before
6639 the linker maps input sections to output sections, we
6640 can easily discard it by setting the SEC_EXCLUDE
6642 sec
->flags
|= SEC_EXCLUDE
;
6646 /* Record this stub in an array of local symbol stubs for
6648 if (elf_tdata (abfd
)->local_stubs
== NULL
)
6650 unsigned long symcount
;
6653 if (elf_bad_symtab (abfd
))
6654 symcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
6656 symcount
= symtab_hdr
->sh_info
;
6657 n
= (asection
**) bfd_zalloc (abfd
,
6658 symcount
* sizeof (asection
*));
6661 elf_tdata (abfd
)->local_stubs
= n
;
6664 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
6666 /* We don't need to set mips16_stubs_seen in this case.
6667 That flag is used to see whether we need to look through
6668 the global symbol table for stubs. We don't need to set
6669 it here, because we just have a local stub. */
6673 struct mips_elf_link_hash_entry
*h
;
6675 h
= ((struct mips_elf_link_hash_entry
*)
6676 sym_hashes
[r_symndx
- extsymoff
]);
6678 /* H is the symbol this stub is for. */
6681 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6684 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
6685 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6687 unsigned long r_symndx
;
6688 struct mips_elf_link_hash_entry
*h
;
6691 /* Look at the relocation information to figure out which symbol
6694 r_symndx
= ELF32_R_SYM (relocs
->r_info
);
6696 if (r_symndx
< extsymoff
6697 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6699 /* This stub was actually built for a static symbol defined
6700 in the same file. We assume that all static symbols in
6701 mips16 code are themselves mips16, so we can simply
6702 discard this stub. Since this function is called before
6703 the linker maps input sections to output sections, we can
6704 easily discard it by setting the SEC_EXCLUDE flag. */
6705 sec
->flags
|= SEC_EXCLUDE
;
6709 h
= ((struct mips_elf_link_hash_entry
*)
6710 sym_hashes
[r_symndx
- extsymoff
]);
6712 /* H is the symbol this stub is for. */
6714 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6715 loc
= &h
->call_fp_stub
;
6717 loc
= &h
->call_stub
;
6719 /* If we already have an appropriate stub for this function, we
6720 don't need another one, so we can discard this one. Since
6721 this function is called before the linker maps input sections
6722 to output sections, we can easily discard it by setting the
6723 SEC_EXCLUDE flag. We can also discard this section if we
6724 happen to already know that this is a mips16 function; it is
6725 not necessary to check this here, as it is checked later, but
6726 it is slightly faster to check now. */
6727 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
6729 sec
->flags
|= SEC_EXCLUDE
;
6734 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
6744 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6749 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
6750 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
6751 BFD_ASSERT (g
!= NULL
);
6757 rel_end
= relocs
+ sec
->reloc_count
;
6758 for (rel
= relocs
; rel
< rel_end
; rel
++)
6760 unsigned long r_symndx
;
6762 struct elf_link_hash_entry
*h
;
6764 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6765 r_type
= ELF32_R_TYPE (rel
->r_info
);
6767 if (r_symndx
< extsymoff
)
6771 h
= sym_hashes
[r_symndx
- extsymoff
];
6773 /* This may be an indirect symbol created because of a version. */
6776 while (h
->root
.type
== bfd_link_hash_indirect
)
6777 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6781 /* Some relocs require a global offset table. */
6782 if (dynobj
== NULL
|| sgot
== NULL
)
6788 case R_MIPS_CALL_HI16
:
6789 case R_MIPS_CALL_LO16
:
6790 case R_MIPS_GOT_HI16
:
6791 case R_MIPS_GOT_LO16
:
6793 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6794 if (! mips_elf_create_got_section (dynobj
, info
))
6796 g
= mips_elf_got_info (dynobj
, &sgot
);
6802 && (info
->shared
|| h
!= NULL
)
6803 && (sec
->flags
& SEC_ALLOC
) != 0)
6804 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6812 if (!h
&& (r_type
== R_MIPS_CALL_LO16
6813 || r_type
== R_MIPS_GOT_LO16
6814 || r_type
== R_MIPS_GOT_DISP
))
6816 /* We may need a local GOT entry for this relocation. We
6817 don't count R_MIPS_HI16 or R_MIPS_GOT16 relocations
6818 because they are always followed by a R_MIPS_LO16
6819 relocation for the value. We don't R_MIPS_GOT_PAGE
6820 because we can estimate the maximum number of pages
6821 needed by looking at the size of the segment.
6823 This estimation is very conservative since we can merge
6824 duplicate entries in the GOT. In order to be less
6825 conservative, we could actually build the GOT here,
6826 rather than in relocate_section. */
6828 sgot
->_raw_size
+= 4;
6836 (*_bfd_error_handler
)
6837 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
6838 bfd_get_filename (abfd
), (unsigned long) rel
->r_offset
);
6839 bfd_set_error (bfd_error_bad_value
);
6844 case R_MIPS_CALL_HI16
:
6845 case R_MIPS_CALL_LO16
:
6846 /* This symbol requires a global offset table entry. */
6847 if (!mips_elf_record_global_got_symbol (h
, info
, g
))
6850 /* We need a stub, not a plt entry for the undefined
6851 function. But we record it as if it needs plt. See
6852 elf_adjust_dynamic_symbol in elflink.h. */
6853 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6859 case R_MIPS_GOT_HI16
:
6860 case R_MIPS_GOT_LO16
:
6861 case R_MIPS_GOT_DISP
:
6862 /* This symbol requires a global offset table entry. */
6863 if (h
&& !mips_elf_record_global_got_symbol (h
, info
, g
))
6869 if ((info
->shared
|| h
!= NULL
)
6870 && (sec
->flags
& SEC_ALLOC
) != 0)
6874 const char *name
= ".rel.dyn";
6876 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6879 sreloc
= bfd_make_section (dynobj
, name
);
6881 || ! bfd_set_section_flags (dynobj
, sreloc
,
6886 | SEC_LINKER_CREATED
6888 || ! bfd_set_section_alignment (dynobj
, sreloc
,
6895 /* When creating a shared object, we must copy these
6896 reloc types into the output file as R_MIPS_REL32
6897 relocs. We make room for this reloc in the
6898 .rel.dyn reloc section */
6899 if (sreloc
->_raw_size
== 0)
6901 /* Add a null element. */
6902 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6903 ++sreloc
->reloc_count
;
6905 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
6909 struct mips_elf_link_hash_entry
*hmips
;
6911 /* We only need to copy this reloc if the symbol is
6912 defined in a dynamic object. */
6913 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6914 ++hmips
->mips_32_relocs
;
6917 /* Even though we don't directly need a GOT entry for
6918 this symbol, a symbol must have a dynamic symbol
6919 table index greater that DT_GOTSYM if there are
6920 dynamic relocations against it. */
6921 if (!mips_elf_record_global_got_symbol (h
, info
, g
))
6925 if (SGI_COMPAT (abfd
))
6926 mips_elf_hash_table (info
)->compact_rel_size
+=
6927 sizeof (Elf32_External_crinfo
);
6932 case R_MIPS_GPREL16
:
6933 case R_MIPS_LITERAL
:
6934 case R_MIPS_GPREL32
:
6935 if (SGI_COMPAT (abfd
))
6936 mips_elf_hash_table (info
)->compact_rel_size
+=
6937 sizeof (Elf32_External_crinfo
);
6940 /* This relocation describes the C++ object vtable hierarchy.
6941 Reconstruct it for later use during GC. */
6942 case R_MIPS_GNU_VTINHERIT
:
6943 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6947 /* This relocation describes which C++ vtable entries are actually
6948 used. Record for later use during GC. */
6949 case R_MIPS_GNU_VTENTRY
:
6950 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
6958 /* If this reloc is not a 16 bit call, and it has a global
6959 symbol, then we will need the fn_stub if there is one.
6960 References from a stub section do not count. */
6962 && r_type
!= R_MIPS16_26
6963 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
6964 sizeof FN_STUB
- 1) != 0
6965 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
6966 sizeof CALL_STUB
- 1) != 0
6967 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
6968 sizeof CALL_FP_STUB
- 1) != 0)
6970 struct mips_elf_link_hash_entry
*mh
;
6972 mh
= (struct mips_elf_link_hash_entry
*) h
;
6973 mh
->need_fn_stub
= true;
6980 /* Return the section that should be marked against GC for a given
6984 mips_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
6986 struct bfd_link_info
*info
;
6987 Elf_Internal_Rela
*rel
;
6988 struct elf_link_hash_entry
*h
;
6989 Elf_Internal_Sym
*sym
;
6991 /* ??? Do mips16 stub sections need to be handled special? */
6995 switch (ELF32_R_TYPE (rel
->r_info
))
6997 case R_MIPS_GNU_VTINHERIT
:
6998 case R_MIPS_GNU_VTENTRY
:
7002 switch (h
->root
.type
)
7004 case bfd_link_hash_defined
:
7005 case bfd_link_hash_defweak
:
7006 return h
->root
.u
.def
.section
;
7008 case bfd_link_hash_common
:
7009 return h
->root
.u
.c
.p
->section
;
7018 if (!(elf_bad_symtab (abfd
)
7019 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
7020 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
7021 && sym
->st_shndx
!= SHN_COMMON
))
7023 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
7030 /* Update the got entry reference counts for the section being removed. */
7033 mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
7035 struct bfd_link_info
*info
;
7037 const Elf_Internal_Rela
*relocs
;
7040 Elf_Internal_Shdr
*symtab_hdr
;
7041 struct elf_link_hash_entry
**sym_hashes
;
7042 bfd_signed_vma
*local_got_refcounts
;
7043 const Elf_Internal_Rela
*rel
, *relend
;
7044 unsigned long r_symndx
;
7045 struct elf_link_hash_entry
*h
;
7047 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7048 sym_hashes
= elf_sym_hashes (abfd
);
7049 local_got_refcounts
= elf_local_got_refcounts (abfd
);
7051 relend
= relocs
+ sec
->reloc_count
;
7052 for (rel
= relocs
; rel
< relend
; rel
++)
7053 switch (ELF32_R_TYPE (rel
->r_info
))
7057 case R_MIPS_CALL_HI16
:
7058 case R_MIPS_CALL_LO16
:
7059 case R_MIPS_GOT_HI16
:
7060 case R_MIPS_GOT_LO16
:
7061 /* ??? It would seem that the existing MIPS code does no sort
7062 of reference counting or whatnot on its GOT and PLT entries,
7063 so it is not possible to garbage collect them at this time. */
7075 /* Adjust a symbol defined by a dynamic object and referenced by a
7076 regular object. The current definition is in some section of the
7077 dynamic object, but we're not including those sections. We have to
7078 change the definition to something the rest of the link can
7082 mips_elf_adjust_dynamic_symbol (info
, h
)
7083 struct bfd_link_info
*info
;
7084 struct elf_link_hash_entry
*h
;
7087 struct mips_elf_link_hash_entry
*hmips
;
7090 dynobj
= elf_hash_table (info
)->dynobj
;
7092 /* Make sure we know what is going on here. */
7093 BFD_ASSERT (dynobj
!= NULL
7094 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
7095 || h
->weakdef
!= NULL
7096 || ((h
->elf_link_hash_flags
7097 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
7098 && (h
->elf_link_hash_flags
7099 & ELF_LINK_HASH_REF_REGULAR
) != 0
7100 && (h
->elf_link_hash_flags
7101 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
7103 /* If this symbol is defined in a dynamic object, we need to copy
7104 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
7106 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7107 if (! info
->relocateable
7108 && hmips
->mips_32_relocs
!= 0
7109 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
7111 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7112 BFD_ASSERT (s
!= NULL
);
7114 if (s
->_raw_size
== 0)
7116 /* Make room for a null element. */
7117 s
->_raw_size
+= sizeof (Elf32_External_Rel
);
7120 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
7123 /* For a function, create a stub, if needed. */
7124 if (h
->type
== STT_FUNC
7125 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
7127 if (! elf_hash_table (info
)->dynamic_sections_created
)
7130 /* If this symbol is not defined in a regular file, then set
7131 the symbol to the stub location. This is required to make
7132 function pointers compare as equal between the normal
7133 executable and the shared library. */
7134 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
7136 /* We need .stub section. */
7137 s
= bfd_get_section_by_name (dynobj
,
7138 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
7139 BFD_ASSERT (s
!= NULL
);
7141 h
->root
.u
.def
.section
= s
;
7142 h
->root
.u
.def
.value
= s
->_raw_size
;
7144 /* XXX Write this stub address somewhere. */
7145 h
->plt
.offset
= s
->_raw_size
;
7147 /* Make room for this stub code. */
7148 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
7150 /* The last half word of the stub will be filled with the index
7151 of this symbol in .dynsym section. */
7156 /* If this is a weak symbol, and there is a real definition, the
7157 processor independent code will have arranged for us to see the
7158 real definition first, and we can just use the same value. */
7159 if (h
->weakdef
!= NULL
)
7161 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
7162 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
7163 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
7164 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
7168 /* This is a reference to a symbol defined by a dynamic object which
7169 is not a function. */
7174 /* This function is called after all the input files have been read,
7175 and the input sections have been assigned to output sections. We
7176 check for any mips16 stub sections that we can discard. */
7178 static boolean mips_elf_check_mips16_stubs
7179 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
7182 mips_elf_always_size_sections (output_bfd
, info
)
7184 struct bfd_link_info
*info
;
7188 /* The .reginfo section has a fixed size. */
7189 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
7191 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
7193 if (info
->relocateable
7194 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
7197 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
7198 mips_elf_check_mips16_stubs
,
7204 /* Check the mips16 stubs for a particular symbol, and see if we can
7209 mips_elf_check_mips16_stubs (h
, data
)
7210 struct mips_elf_link_hash_entry
*h
;
7213 if (h
->fn_stub
!= NULL
7214 && ! h
->need_fn_stub
)
7216 /* We don't need the fn_stub; the only references to this symbol
7217 are 16 bit calls. Clobber the size to 0 to prevent it from
7218 being included in the link. */
7219 h
->fn_stub
->_raw_size
= 0;
7220 h
->fn_stub
->_cooked_size
= 0;
7221 h
->fn_stub
->flags
&= ~ SEC_RELOC
;
7222 h
->fn_stub
->reloc_count
= 0;
7223 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
7226 if (h
->call_stub
!= NULL
7227 && h
->root
.other
== STO_MIPS16
)
7229 /* We don't need the call_stub; this is a 16 bit function, so
7230 calls from other 16 bit functions are OK. Clobber the size
7231 to 0 to prevent it from being included in the link. */
7232 h
->call_stub
->_raw_size
= 0;
7233 h
->call_stub
->_cooked_size
= 0;
7234 h
->call_stub
->flags
&= ~ SEC_RELOC
;
7235 h
->call_stub
->reloc_count
= 0;
7236 h
->call_stub
->flags
|= SEC_EXCLUDE
;
7239 if (h
->call_fp_stub
!= NULL
7240 && h
->root
.other
== STO_MIPS16
)
7242 /* We don't need the call_stub; this is a 16 bit function, so
7243 calls from other 16 bit functions are OK. Clobber the size
7244 to 0 to prevent it from being included in the link. */
7245 h
->call_fp_stub
->_raw_size
= 0;
7246 h
->call_fp_stub
->_cooked_size
= 0;
7247 h
->call_fp_stub
->flags
&= ~ SEC_RELOC
;
7248 h
->call_fp_stub
->reloc_count
= 0;
7249 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
7255 /* Set the sizes of the dynamic sections. */
7258 mips_elf_size_dynamic_sections (output_bfd
, info
)
7260 struct bfd_link_info
*info
;
7265 struct mips_got_info
*g
;
7267 dynobj
= elf_hash_table (info
)->dynobj
;
7268 BFD_ASSERT (dynobj
!= NULL
);
7270 if (elf_hash_table (info
)->dynamic_sections_created
)
7272 /* Set the contents of the .interp section to the interpreter. */
7275 s
= bfd_get_section_by_name (dynobj
, ".interp");
7276 BFD_ASSERT (s
!= NULL
);
7278 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
7280 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
7284 /* The check_relocs and adjust_dynamic_symbol entry points have
7285 determined the sizes of the various dynamic sections. Allocate
7288 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
7293 /* It's OK to base decisions on the section name, because none
7294 of the dynobj section names depend upon the input files. */
7295 name
= bfd_get_section_name (dynobj
, s
);
7297 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
7302 if (strncmp (name
, ".rel", 4) == 0)
7304 if (s
->_raw_size
== 0)
7306 /* We only strip the section if the output section name
7307 has the same name. Otherwise, there might be several
7308 input sections for this output section. FIXME: This
7309 code is probably not needed these days anyhow, since
7310 the linker now does not create empty output sections. */
7311 if (s
->output_section
!= NULL
7313 bfd_get_section_name (s
->output_section
->owner
,
7314 s
->output_section
)) == 0)
7319 const char *outname
;
7322 /* If this relocation section applies to a read only
7323 section, then we probably need a DT_TEXTREL entry.
7324 If the relocation section is .rel.dyn, we always
7325 assert a DT_TEXTREL entry rather than testing whether
7326 there exists a relocation to a read only section or
7328 outname
= bfd_get_section_name (output_bfd
,
7330 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
7332 && (target
->flags
& SEC_READONLY
) != 0
7333 && (target
->flags
& SEC_ALLOC
) != 0)
7334 || strcmp (outname
, ".rel.dyn") == 0)
7337 /* We use the reloc_count field as a counter if we need
7338 to copy relocs into the output file. */
7339 if (strcmp (name
, ".rel.dyn") != 0)
7343 else if (strncmp (name
, ".got", 4) == 0)
7346 bfd_size_type loadable_size
= 0;
7347 bfd_size_type local_gotno
;
7350 BFD_ASSERT (elf_section_data (s
) != NULL
);
7351 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
7352 BFD_ASSERT (g
!= NULL
);
7354 /* Calculate the total loadable size of the output. That
7355 will give us the maximum number of GOT_PAGE entries
7357 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
7359 asection
*subsection
;
7361 for (subsection
= sub
->sections
;
7363 subsection
= subsection
->next
)
7365 if ((subsection
->flags
& SEC_ALLOC
) == 0)
7367 loadable_size
+= (subsection
->_raw_size
+ 0xf) & ~0xf;
7370 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
7372 /* Assume there are two loadable segments consisting of
7373 contiguous sections. Is 5 enough? */
7374 local_gotno
= (loadable_size
>> 16) + 5;
7375 g
->local_gotno
+= local_gotno
;
7376 s
->_raw_size
+= local_gotno
* 4;
7378 /* There has to be a global GOT entry for every symbol with
7379 a dynamic symbol table index of DT_MIPS_GOTSYM or
7380 higher. Therefore, it make sense to put those symbols
7381 that need GOT entries at the end of the symbol table. We
7383 if (!mips_elf_sort_hash_table (info
))
7386 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
7387 s
->_raw_size
+= i
* 4;
7389 else if (strcmp (name
, MIPS_ELF_STUB_SECTION_NAME (output_bfd
)) == 0)
7391 /* Irix rld assumes that the function stub isn't at the end
7392 of .text section. So put a dummy. XXX */
7393 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
7395 else if (! info
->shared
7396 && ! mips_elf_hash_table (info
)->use_rld_obj_head
7397 && strncmp (name
, ".rld_map", 8) == 0)
7399 /* We add a room for __rld_map. It will be filled in by the
7400 rtld to contain a pointer to the _r_debug structure. */
7403 else if (SGI_COMPAT (output_bfd
)
7404 && strncmp (name
, ".compact_rel", 12) == 0)
7405 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
7406 else if (strcmp (name
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
))
7408 s
->_raw_size
= (sizeof (Elf32_External_Msym
)
7409 * (elf_hash_table (info
)->dynsymcount
7410 + bfd_count_sections (output_bfd
)));
7411 else if (strncmp (name
, ".init", 5) != 0)
7413 /* It's not one of our sections, so don't allocate space. */
7419 _bfd_strip_section_from_output (s
);
7423 /* Allocate memory for the section contents. */
7424 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
7425 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
7427 bfd_set_error (bfd_error_no_memory
);
7432 if (elf_hash_table (info
)->dynamic_sections_created
)
7434 /* Add some entries to the .dynamic section. We fill in the
7435 values later, in elf_mips_finish_dynamic_sections, but we
7436 must add the entries now so that we get the correct size for
7437 the .dynamic section. The DT_DEBUG entry is filled in by the
7438 dynamic linker and used by the debugger. */
7441 if (SGI_COMPAT (output_bfd
))
7443 /* SGI object has the equivalence of DT_DEBUG in the
7444 DT_MIPS_RLD_MAP entry. */
7445 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
7449 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
7455 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
7459 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
7462 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
7464 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
7467 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
7470 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
7474 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
7477 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
7480 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
7482 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
7485 s
= bfd_get_section_by_name (dynobj
, ".liblist");
7486 BFD_ASSERT (s
!= NULL
);
7488 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
7492 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
7495 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
7499 /* Time stamps in executable files are a bad idea. */
7500 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
7505 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
7510 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
7514 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
7517 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
7520 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
7523 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
7526 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
7529 if (IRIX_COMPAT (dynobj
) == ict_irix5
7530 && ! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
7533 if (IRIX_COMPAT (dynobj
) == ict_irix6
7534 && (bfd_get_section_by_name
7535 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
7536 && !bfd_elf32_add_dynamic_entry (info
, DT_MIPS_OPTIONS
, 0))
7539 if (bfd_get_section_by_name (dynobj
,
7540 MIPS_ELF_MSYM_SECTION_NAME (dynobj
))
7541 && !bfd_elf32_add_dynamic_entry (info
, DT_MIPS_MSYM
, 0))
7545 /* If we use dynamic linking, we generate a section symbol for each
7546 output section. These are local symbols, which means that they
7547 must come first in the dynamic symbol table.
7548 That means we must increment the dynamic symbol index of every
7549 other dynamic symbol. */
7552 struct mips_got_info
*g
;
7555 if (elf_hash_table (info
)->dynamic_sections_created
)
7558 /* We no longer try to restrict the set of sections which get
7559 dynamic symbol table entries, since it fails if we have
7560 other random sections which need dynamic relocations. */
7561 const char * const *namep
;
7562 bfd_size_type strindex
;
7563 struct bfd_strtab_hash
*dynstr
;
7565 if (SGI_COMPAT (output_bfd
))
7567 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
7568 elf_link_hash_traverse (elf_hash_table (info
),
7569 mips_elf_adjust_dynindx
,
7571 elf_hash_table (info
)->dynsymcount
+= c
;
7573 dynstr
= elf_hash_table (info
)->dynstr
;
7574 BFD_ASSERT (dynstr
!= NULL
);
7576 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
7580 s
= bfd_get_section_by_name (output_bfd
, *namep
);
7582 elf_section_data (s
)->dynindx
= i
;
7584 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
7585 if (strindex
== (bfd_size_type
) -1)
7588 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
7594 c
= bfd_count_sections (output_bfd
);
7595 elf_link_hash_traverse (elf_hash_table (info
),
7596 _bfd_elf_link_adjust_dynindx
,
7598 elf_hash_table (info
)->dynsymcount
+= c
;
7600 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
7602 elf_section_data (s
)->dynindx
= i
;
7603 /* These symbols will have no names, so we don't need to
7604 fiddle with dynstr_index. */
7613 /* If NAME is one of the special IRIX6 symbols defined by the linker,
7614 adjust it appropriately now. */
7617 mips_elf_irix6_finish_dynamic_symbol (abfd
, name
, sym
)
7620 Elf_Internal_Sym
*sym
;
7622 /* The linker script takes care of providing names and values for
7623 these, but we must place them into the right sections. */
7624 static const char* const text_section_symbols
[] = {
7627 "__dso_displacement",
7629 "__program_header_table",
7633 static const char* const data_section_symbols
[] = {
7641 const char* const *p
;
7644 for (i
= 0; i
< 2; ++i
)
7645 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
7648 if (strcmp (*p
, name
) == 0)
7650 /* All of these symbols are given type STT_SECTION by the
7652 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7654 /* The IRIX linker puts these symbols in special sections. */
7656 sym
->st_shndx
= SHN_MIPS_TEXT
;
7658 sym
->st_shndx
= SHN_MIPS_DATA
;
7664 /* Finish up dynamic symbol handling. We set the contents of various
7665 dynamic sections here. */
7668 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
7670 struct bfd_link_info
*info
;
7671 struct elf_link_hash_entry
*h
;
7672 Elf_Internal_Sym
*sym
;
7678 struct mips_got_info
*g
;
7680 struct mips_elf_link_hash_entry
*mh
;
7682 dynobj
= elf_hash_table (info
)->dynobj
;
7683 gval
= sym
->st_value
;
7684 mh
= (struct mips_elf_link_hash_entry
*) h
;
7686 if (h
->plt
.offset
!= (bfd_vma
) -1)
7690 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
7692 /* This symbol has a stub. Set it up. */
7694 BFD_ASSERT (h
->dynindx
!= -1);
7696 s
= bfd_get_section_by_name (dynobj
,
7697 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
7698 BFD_ASSERT (s
!= NULL
);
7700 /* Fill the stub. */
7702 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
7704 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
7707 /* FIXME: Can h->dynindex be more than 64K? */
7708 if (h
->dynindx
& 0xffff0000)
7711 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
7713 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
7715 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
7716 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
7718 /* Mark the symbol as undefined. plt.offset != -1 occurs
7719 only for the referenced symbol. */
7720 sym
->st_shndx
= SHN_UNDEF
;
7722 /* The run-time linker uses the st_value field of the symbol
7723 to reset the global offset table entry for this external
7724 to its stub address when unlinking a shared object. */
7725 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
7726 sym
->st_value
= gval
;
7729 BFD_ASSERT (h
->dynindx
!= -1);
7731 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7732 BFD_ASSERT (sgot
!= NULL
);
7733 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7734 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7735 BFD_ASSERT (g
!= NULL
);
7737 /* Run through the global symbol table, creating GOT entries for all
7738 the symbols that need them. */
7739 if (h
->dynindx
>= g
->global_gotsym
->dynindx
)
7745 value
= sym
->st_value
;
7747 /* For an entity defined in a shared object, this will be
7748 NULL. (For functions in shared objects for
7749 which we have created stubs, ST_VALUE will be non-NULL.
7750 That's because such the functions are now no longer defined
7751 in a shared object.) */
7752 value
= h
->root
.u
.def
.value
;
7754 offset
= mips_elf_global_got_index (dynobj
, h
);
7755 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ offset
);
7758 /* Create a .msym entry, if appropriate. */
7759 smsym
= bfd_get_section_by_name (dynobj
,
7760 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
7763 Elf32_Internal_Msym msym
;
7765 msym
.ms_hash_value
= bfd_elf_hash (h
->root
.root
.string
);
7766 /* It is undocumented what the `1' indicates, but IRIX6 uses
7768 msym
.ms_info
= ELF32_MS_INFO (mh
->min_dyn_reloc_index
, 1);
7769 bfd_mips_elf_swap_msym_out
7771 ((Elf32_External_Msym
*) smsym
->contents
) + h
->dynindx
);
7774 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7775 name
= h
->root
.root
.string
;
7776 if (strcmp (name
, "_DYNAMIC") == 0
7777 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
7778 sym
->st_shndx
= SHN_ABS
;
7779 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
7781 sym
->st_shndx
= SHN_ABS
;
7782 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7785 else if (SGI_COMPAT (output_bfd
))
7787 if (strcmp (name
, "_gp_disp") == 0)
7789 sym
->st_shndx
= SHN_ABS
;
7790 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7791 sym
->st_value
= elf_gp (output_bfd
);
7793 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
7794 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
7796 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7797 sym
->st_other
= STO_PROTECTED
;
7799 sym
->st_shndx
= SHN_MIPS_DATA
;
7801 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
7803 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7804 sym
->st_other
= STO_PROTECTED
;
7805 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
7806 sym
->st_shndx
= SHN_ABS
;
7808 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
7810 if (h
->type
== STT_FUNC
)
7811 sym
->st_shndx
= SHN_MIPS_TEXT
;
7812 else if (h
->type
== STT_OBJECT
)
7813 sym
->st_shndx
= SHN_MIPS_DATA
;
7817 /* Handle the IRIX6-specific symbols. */
7818 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
7819 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
7821 if (SGI_COMPAT (output_bfd
)
7824 if (! mips_elf_hash_table (info
)->use_rld_obj_head
7825 && strcmp (name
, "__rld_map") == 0)
7827 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7828 BFD_ASSERT (s
!= NULL
);
7829 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
7830 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
7831 if (mips_elf_hash_table (info
)->rld_value
== 0)
7832 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7834 else if (mips_elf_hash_table (info
)->use_rld_obj_head
7835 && strcmp (name
, "__rld_obj_head") == 0)
7837 /* IRIX6 does not use a .rld_map section. */
7838 if (IRIX_COMPAT (output_bfd
) == ict_irix5
)
7839 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
7841 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7845 /* If this is a mips16 symbol, force the value to be even. */
7846 if (sym
->st_other
== STO_MIPS16
7847 && (sym
->st_value
& 1) != 0)
7853 /* Finish up the dynamic sections. */
7856 mips_elf_finish_dynamic_sections (output_bfd
, info
)
7858 struct bfd_link_info
*info
;
7863 struct mips_got_info
*g
;
7865 dynobj
= elf_hash_table (info
)->dynobj
;
7867 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
7869 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7874 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
7875 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
7876 BFD_ASSERT (g
!= NULL
);
7879 if (elf_hash_table (info
)->dynamic_sections_created
)
7881 Elf32_External_Dyn
*dyncon
, *dynconend
;
7883 BFD_ASSERT (sdyn
!= NULL
);
7884 BFD_ASSERT (g
!= NULL
);
7886 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7887 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
7888 for (; dyncon
< dynconend
; dyncon
++)
7890 Elf_Internal_Dyn dyn
;
7895 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
7903 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
7904 BFD_ASSERT (s
!= NULL
);
7905 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
7906 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7910 /* Rewrite DT_STRSZ. */
7912 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
7913 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7919 case DT_MIPS_CONFLICT
:
7922 case DT_MIPS_LIBLIST
:
7925 s
= bfd_get_section_by_name (output_bfd
, name
);
7926 BFD_ASSERT (s
!= NULL
);
7927 dyn
.d_un
.d_ptr
= s
->vma
;
7928 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7931 case DT_MIPS_RLD_VERSION
:
7932 dyn
.d_un
.d_val
= 1; /* XXX */
7933 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7937 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
7938 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7941 case DT_MIPS_CONFLICTNO
:
7943 elemsize
= sizeof (Elf32_Conflict
);
7946 case DT_MIPS_LIBLISTNO
:
7948 elemsize
= sizeof (Elf32_Lib
);
7950 s
= bfd_get_section_by_name (output_bfd
, name
);
7953 if (s
->_cooked_size
!= 0)
7954 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7956 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7961 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7964 case DT_MIPS_TIME_STAMP
:
7965 time ((time_t *) &dyn
.d_un
.d_val
);
7966 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7969 case DT_MIPS_ICHECKSUM
:
7973 case DT_MIPS_IVERSION
:
7977 case DT_MIPS_BASE_ADDRESS
:
7978 s
= output_bfd
->sections
;
7979 BFD_ASSERT (s
!= NULL
);
7980 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
7981 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7984 case DT_MIPS_LOCAL_GOTNO
:
7985 dyn
.d_un
.d_val
= g
->local_gotno
;
7986 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7989 case DT_MIPS_SYMTABNO
:
7991 elemsize
= sizeof (Elf32_External_Sym
);
7992 s
= bfd_get_section_by_name (output_bfd
, name
);
7993 BFD_ASSERT (s
!= NULL
);
7995 if (s
->_cooked_size
!= 0)
7996 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
7998 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
7999 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8002 case DT_MIPS_UNREFEXTNO
:
8003 /* The index into the dynamic symbol table which is the
8004 entry of the first external symbol that is not
8005 referenced within the same object. */
8006 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
8007 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8010 case DT_MIPS_GOTSYM
:
8011 dyn
.d_un
.d_val
= g
->global_gotsym
->dynindx
;
8012 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8015 case DT_MIPS_HIPAGENO
:
8016 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
8017 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8020 case DT_MIPS_RLD_MAP
:
8021 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
8022 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8025 case DT_MIPS_OPTIONS
:
8026 s
= (bfd_get_section_by_name
8027 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
8028 dyn
.d_un
.d_ptr
= s
->vma
;
8029 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8033 s
= (bfd_get_section_by_name
8034 (output_bfd
, MIPS_ELF_MSYM_SECTION_NAME (output_bfd
)));
8035 dyn
.d_un
.d_ptr
= s
->vma
;
8036 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8042 /* The first entry of the global offset table will be filled at
8043 runtime. The second entry will be used by some runtime loaders.
8044 This isn't the case of Irix rld. */
8045 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
8047 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
8048 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
8052 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
8058 Elf_Internal_Sym sym
;
8059 Elf32_compact_rel cpt
;
8061 /* Set up the section symbols for the output sections. SGI sets
8062 the STT_NOTYPE attribute for these symbols. Should we do so? */
8064 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
8065 smsym
= bfd_get_section_by_name (dynobj
,
8066 MIPS_ELF_MSYM_SECTION_NAME (dynobj
));
8067 if (sdynsym
!= NULL
)
8071 const char * const * namep
= mips_elf_dynsym_sec_names
;
8076 /* We no longer try to restrict the set of sections which get
8077 dynamic symbol table entries, since it fails if we have
8078 other random sections which need dynamic relocations. */
8079 if (SGI_COMPAT (output_bfd
))
8083 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
8089 while ((name
= *namep
++) != NULL
)
8091 s
= bfd_get_section_by_name (output_bfd
, name
);
8094 sym
.st_value
= s
->vma
;
8095 dindx
= elf_section_data (s
)->dynindx
;
8096 last
= s
->vma
+ s
->_raw_size
;
8100 sym
.st_value
= last
;
8104 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
8109 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
8111 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
8112 (((Elf32_External_Sym
*)
8117 /* Set the sh_info field of the output .dynsym section to
8118 the index of the first global symbol. */
8119 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
8120 SIZEOF_MIPS_DYNSYM_SECNAMES
;
8125 Elf32_Internal_Msym msym
;
8129 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
8132 msym
.ms_hash_value
= 0;
8133 msym
.ms_info
= ELF32_MS_INFO (0, 1);
8135 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
8140 sym
.st_value
= s
->vma
;
8142 indx
= elf_section_data (s
)->this_idx
;
8143 BFD_ASSERT (indx
> 0);
8144 sym
.st_shndx
= indx
;
8146 dynindx
= elf_section_data (s
)->dynindx
;
8148 bfd_elf32_swap_symbol_out
8150 (((Elf32_External_Sym
*) sdynsym
->contents
)
8154 bfd_mips_elf_swap_msym_out
8156 (((Elf32_External_Msym
*) smsym
->contents
)
8160 /* Set the sh_info field of the output .dynsym section to
8161 the index of the first global symbol. */
8162 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
8163 bfd_count_sections (output_bfd
) + 1;
8167 if (SGI_COMPAT (output_bfd
))
8169 /* Write .compact_rel section out. */
8170 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
8174 cpt
.num
= s
->reloc_count
;
8176 cpt
.offset
= (s
->output_section
->filepos
8177 + sizeof (Elf32_External_compact_rel
));
8180 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
8181 ((Elf32_External_compact_rel
*)
8184 /* Clean up a dummy stub function entry in .text. */
8185 s
= bfd_get_section_by_name (dynobj
,
8186 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
8189 file_ptr dummy_offset
;
8191 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
8192 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
8193 memset (s
->contents
+ dummy_offset
, 0,
8194 MIPS_FUNCTION_STUB_SIZE
);
8199 /* Clean up a first relocation in .rel.dyn. */
8200 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
8201 if (s
!= NULL
&& s
->_raw_size
> 0)
8202 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
8208 /* This is almost identical to bfd_generic_get_... except that some
8209 MIPS relocations need to be handled specially. Sigh. */
8212 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
8213 relocateable
, symbols
)
8215 struct bfd_link_info
*link_info
;
8216 struct bfd_link_order
*link_order
;
8218 boolean relocateable
;
8221 /* Get enough memory to hold the stuff */
8222 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
8223 asection
*input_section
= link_order
->u
.indirect
.section
;
8225 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
8226 arelent
**reloc_vector
= NULL
;
8232 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
8233 if (reloc_vector
== NULL
&& reloc_size
!= 0)
8236 /* read in the section */
8237 if (!bfd_get_section_contents (input_bfd
,
8241 input_section
->_raw_size
))
8244 /* We're not relaxing the section, so just copy the size info */
8245 input_section
->_cooked_size
= input_section
->_raw_size
;
8246 input_section
->reloc_done
= true;
8248 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
8252 if (reloc_count
< 0)
8255 if (reloc_count
> 0)
8260 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
8263 struct bfd_hash_entry
*h
;
8264 struct bfd_link_hash_entry
*lh
;
8265 /* Skip all this stuff if we aren't mixing formats. */
8266 if (abfd
&& input_bfd
8267 && abfd
->xvec
== input_bfd
->xvec
)
8271 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
8272 lh
= (struct bfd_link_hash_entry
*) h
;
8279 case bfd_link_hash_undefined
:
8280 case bfd_link_hash_undefweak
:
8281 case bfd_link_hash_common
:
8284 case bfd_link_hash_defined
:
8285 case bfd_link_hash_defweak
:
8287 gp
= lh
->u
.def
.value
;
8289 case bfd_link_hash_indirect
:
8290 case bfd_link_hash_warning
:
8292 /* @@FIXME ignoring warning for now */
8294 case bfd_link_hash_new
:
8303 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
8306 char *error_message
= (char *) NULL
;
8307 bfd_reloc_status_type r
;
8309 /* Specific to MIPS: Deal with relocation types that require
8310 knowing the gp of the output bfd. */
8311 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
8312 if (bfd_is_abs_section (sym
->section
) && abfd
)
8314 /* The special_function wouldn't get called anyways. */
8318 /* The gp isn't there; let the special function code
8319 fall over on its own. */
8321 else if ((*parent
)->howto
->special_function
8322 == _bfd_mips_elf_gprel16_reloc
)
8324 /* bypass special_function call */
8325 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
8326 relocateable
, (PTR
) data
, gp
);
8327 goto skip_bfd_perform_relocation
;
8329 /* end mips specific stuff */
8331 r
= bfd_perform_relocation (input_bfd
,
8335 relocateable
? abfd
: (bfd
*) NULL
,
8337 skip_bfd_perform_relocation
:
8341 asection
*os
= input_section
->output_section
;
8343 /* A partial link, so keep the relocs */
8344 os
->orelocation
[os
->reloc_count
] = *parent
;
8348 if (r
!= bfd_reloc_ok
)
8352 case bfd_reloc_undefined
:
8353 if (!((*link_info
->callbacks
->undefined_symbol
)
8354 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
8355 input_bfd
, input_section
, (*parent
)->address
)))
8358 case bfd_reloc_dangerous
:
8359 BFD_ASSERT (error_message
!= (char *) NULL
);
8360 if (!((*link_info
->callbacks
->reloc_dangerous
)
8361 (link_info
, error_message
, input_bfd
, input_section
,
8362 (*parent
)->address
)))
8365 case bfd_reloc_overflow
:
8366 if (!((*link_info
->callbacks
->reloc_overflow
)
8367 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
8368 (*parent
)->howto
->name
, (*parent
)->addend
,
8369 input_bfd
, input_section
, (*parent
)->address
)))
8372 case bfd_reloc_outofrange
:
8381 if (reloc_vector
!= NULL
)
8382 free (reloc_vector
);
8386 if (reloc_vector
!= NULL
)
8387 free (reloc_vector
);
8390 #define bfd_elf32_bfd_get_relocated_section_contents \
8391 elf32_mips_get_relocated_section_contents
8393 /* ECOFF swapping routines. These are used when dealing with the
8394 .mdebug section, which is in the ECOFF debugging format. */
8395 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
8397 /* Symbol table magic number. */
8399 /* Alignment of debugging information. E.g., 4. */
8401 /* Sizes of external symbolic information. */
8402 sizeof (struct hdr_ext
),
8403 sizeof (struct dnr_ext
),
8404 sizeof (struct pdr_ext
),
8405 sizeof (struct sym_ext
),
8406 sizeof (struct opt_ext
),
8407 sizeof (struct fdr_ext
),
8408 sizeof (struct rfd_ext
),
8409 sizeof (struct ext_ext
),
8410 /* Functions to swap in external symbolic data. */
8419 _bfd_ecoff_swap_tir_in
,
8420 _bfd_ecoff_swap_rndx_in
,
8421 /* Functions to swap out external symbolic data. */
8430 _bfd_ecoff_swap_tir_out
,
8431 _bfd_ecoff_swap_rndx_out
,
8432 /* Function to read in symbolic data. */
8433 _bfd_mips_elf_read_ecoff_info
8436 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
8437 #define TARGET_LITTLE_NAME "elf32-littlemips"
8438 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
8439 #define TARGET_BIG_NAME "elf32-bigmips"
8440 #define ELF_ARCH bfd_arch_mips
8441 #define ELF_MACHINE_CODE EM_MIPS
8443 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
8444 a value of 0x1000, and we are compatible. */
8445 #define ELF_MAXPAGESIZE 0x1000
8447 #define elf_backend_collect true
8448 #define elf_backend_type_change_ok true
8449 #define elf_backend_can_gc_sections true
8450 #define elf_info_to_howto mips_info_to_howto_rela
8451 #define elf_info_to_howto_rel mips_info_to_howto_rel
8452 #define elf_backend_sym_is_global mips_elf_sym_is_global
8453 #define elf_backend_object_p mips_elf32_object_p
8454 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
8455 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
8456 #define elf_backend_section_from_bfd_section \
8457 _bfd_mips_elf_section_from_bfd_section
8458 #define elf_backend_section_processing mips_elf32_section_processing
8459 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
8460 #define elf_backend_additional_program_headers \
8461 mips_elf_additional_program_headers
8462 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
8463 #define elf_backend_final_write_processing \
8464 _bfd_mips_elf_final_write_processing
8465 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
8467 #define bfd_elf32_bfd_is_local_label_name \
8468 mips_elf_is_local_label_name
8469 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
8470 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
8471 #define bfd_elf32_bfd_link_hash_table_create \
8472 mips_elf_link_hash_table_create
8473 #define bfd_elf32_bfd_final_link mips_elf_final_link
8474 #define bfd_elf32_bfd_copy_private_bfd_data \
8475 _bfd_mips_elf_copy_private_bfd_data
8476 #define bfd_elf32_bfd_merge_private_bfd_data \
8477 _bfd_mips_elf_merge_private_bfd_data
8478 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
8479 #define bfd_elf32_bfd_print_private_bfd_data \
8480 _bfd_mips_elf_print_private_bfd_data
8481 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
8482 #define elf_backend_create_dynamic_sections \
8483 mips_elf_create_dynamic_sections
8484 #define elf_backend_check_relocs mips_elf_check_relocs
8485 #define elf_backend_adjust_dynamic_symbol \
8486 mips_elf_adjust_dynamic_symbol
8487 #define elf_backend_always_size_sections \
8488 mips_elf_always_size_sections
8489 #define elf_backend_size_dynamic_sections \
8490 mips_elf_size_dynamic_sections
8491 #define elf_backend_relocate_section mips_elf_relocate_section
8492 #define elf_backend_link_output_symbol_hook \
8493 mips_elf_link_output_symbol_hook
8494 #define elf_backend_finish_dynamic_symbol \
8495 mips_elf_finish_dynamic_symbol
8496 #define elf_backend_finish_dynamic_sections \
8497 mips_elf_finish_dynamic_sections
8498 #define elf_backend_gc_mark_hook mips_elf_gc_mark_hook
8499 #define elf_backend_gc_sweep_hook mips_elf_gc_sweep_hook
8501 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
8502 #define elf_backend_plt_header_size 0
8504 #include "elf32-target.h"