1 /* MIPS-specific support for 64-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Ian Lance Taylor, Cygnus Support
5 Linker support added by Mark Mitchell, CodeSourcery, LLC.
6 <mark@codesourcery.com>
8 This file is part of BFD, the Binary File Descriptor library.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 /* This file supports the 64-bit MIPS ELF ABI.
26 The MIPS 64-bit ELF ABI uses an unusual reloc format. This file
27 overrides the usual ELF reloc handling, and handles reading and
28 writing the relocations here. */
30 /* TODO: Many things are unsupported, even if there is some code for it
31 . (which was mostly stolen from elf32-mips.c and slightly adapted).
33 . - Relocation handling for REL relocs is wrong in many cases and
35 . - Relocation handling for RELA relocs related to GOT support are
36 . also likely to be wrong.
37 . - Support for MIPS16 is only partially implemented.
38 . - Embedded PIC is only partially implemented (is it needed?).
39 . - Combined relocs with RSS_* entries are unsupported.
40 . - The whole GOT handling for NewABI is missing, some parts of
41 . the OldABI version is still lying around and shold be removed.
53 /* Get the ECOFF swapping routines. The 64-bit ABI is not supposed to
54 use ECOFF. However, we support it anyhow for an easier changeover. */
56 #include "coff/symconst.h"
57 #include "coff/internal.h"
58 #include "coff/ecoff.h"
59 /* The 64 bit versions of the mdebug data structures are in alpha.h. */
60 #include "coff/alpha.h"
61 #define ECOFF_SIGNED_64
62 #include "ecoffswap.h"
64 struct mips_elf64_link_hash_entry
;
66 static void mips_elf64_swap_reloc_in
67 PARAMS ((bfd
*, const Elf64_Mips_External_Rel
*,
68 Elf64_Mips_Internal_Rel
*));
69 static void mips_elf64_swap_reloca_in
70 PARAMS ((bfd
*, const Elf64_Mips_External_Rela
*,
71 Elf64_Mips_Internal_Rela
*));
72 static void mips_elf64_swap_reloc_out
73 PARAMS ((bfd
*, const Elf64_Mips_Internal_Rel
*,
74 Elf64_Mips_External_Rel
*));
75 static void mips_elf64_swap_reloca_out
76 PARAMS ((bfd
*, const Elf64_Mips_Internal_Rela
*,
77 Elf64_Mips_External_Rela
*));
78 static void mips_elf64_be_swap_reloc_in
79 PARAMS ((bfd
*, const bfd_byte
*, Elf_Internal_Rel
*));
80 static void mips_elf64_be_swap_reloc_out
81 PARAMS ((bfd
*, const Elf_Internal_Rel
*, bfd_byte
*));
82 static void mips_elf64_be_swap_reloca_in
83 PARAMS ((bfd
*, const bfd_byte
*, Elf_Internal_Rela
*));
84 static void mips_elf64_be_swap_reloca_out
85 PARAMS ((bfd
*, const Elf_Internal_Rela
*, bfd_byte
*));
86 static bfd_vma mips_elf64_high
PARAMS ((bfd_vma
));
87 static bfd_vma mips_elf64_higher
PARAMS ((bfd_vma
));
88 static bfd_vma mips_elf64_highest
PARAMS ((bfd_vma
));
89 static reloc_howto_type
*mips_elf64_reloc_type_lookup
90 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
91 static void mips_elf64_info_to_howto_rel
92 PARAMS ((bfd
*, arelent
*, Elf64_Internal_Rel
*));
93 static void mips_elf64_info_to_howto_rela
94 PARAMS ((bfd
*, arelent
*, Elf64_Internal_Rela
*));
95 static long mips_elf64_get_reloc_upper_bound
PARAMS ((bfd
*, asection
*));
96 static boolean mips_elf64_slurp_one_reloc_table
97 PARAMS ((bfd
*, asection
*, asymbol
**, const Elf_Internal_Shdr
*));
98 static boolean mips_elf64_slurp_reloc_table
99 PARAMS ((bfd
*, asection
*, asymbol
**, boolean
));
100 static void mips_elf64_write_relocs
PARAMS ((bfd
*, asection
*, PTR
));
101 static void mips_elf64_write_rel
102 PARAMS((bfd
*, asection
*, Elf_Internal_Shdr
*, int *, PTR
));
103 static void mips_elf64_write_rela
104 PARAMS((bfd
*, asection
*, Elf_Internal_Shdr
*, int *, PTR
));
105 static struct bfd_hash_entry
*mips_elf64_link_hash_newfunc
106 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
107 static bfd_reloc_status_type mips_elf64_hi16_reloc
108 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
109 static bfd_reloc_status_type mips_elf64_higher_reloc
110 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
111 static bfd_reloc_status_type mips_elf64_highest_reloc
112 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
113 static bfd_reloc_status_type mips_elf64_gprel16_reloc
114 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
115 static bfd_reloc_status_type mips_elf64_gprel16_reloca
116 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
117 static bfd_reloc_status_type mips_elf64_literal_reloc
118 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
119 static bfd_reloc_status_type mips_elf64_gprel32_reloc
120 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
121 static bfd_reloc_status_type mips_elf64_shift6_reloc
122 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
123 static bfd_reloc_status_type mips_elf64_got16_reloc
124 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
125 static boolean mips_elf64_assign_gp
PARAMS ((bfd
*, bfd_vma
*));
126 static bfd_reloc_status_type mips_elf64_final_gp
127 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
128 static bfd_reloc_status_type gprel16_with_gp
129 PARAMS ((bfd
*, asymbol
*, arelent
*, asection
*, boolean
, PTR
, bfd_vma
));
130 static int mips_elf64_additional_program_headers
PARAMS ((bfd
*));
131 static struct bfd_link_hash_table
*mips_elf64_link_hash_table_create
133 static bfd_vma mips_elf64_got_offset_from_index
134 PARAMS ((bfd
*, bfd
*, bfd_vma
));
135 static struct mips_elf64_got_info
*_mips_elf64_got_info
136 PARAMS ((bfd
*, asection
**));
137 static bfd_vma mips_elf64_sign_extend
PARAMS ((bfd_vma
, int));
138 static boolean mips_elf64_overflow_p
PARAMS ((bfd_vma
, int));
139 static bfd_vma mips_elf64_global_got_index
140 PARAMS ((bfd
*, struct elf_link_hash_entry
*));
141 static boolean mips_elf64_sort_hash_table_f
142 PARAMS ((struct mips_elf64_link_hash_entry
*, PTR
));
143 static boolean mips_elf64_sort_hash_table
144 PARAMS ((struct bfd_link_info
*, unsigned long));
145 static void mips_elf64_swap_msym_out
146 PARAMS ((bfd
*, const Elf32_Internal_Msym
*, Elf32_External_Msym
*));
147 static bfd_vma mips_elf64_create_local_got_entry
148 PARAMS ((bfd
*abfd
, struct mips_elf64_got_info
*, asection
*,
150 static bfd_vma mips_elf64_local_got_index
151 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
));
152 static bfd_vma mips_elf64_got_page
153 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
, bfd_vma
*));
154 static bfd_vma mips_elf64_got16_entry
155 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
, boolean
));
156 static boolean mips_elf64_local_relocation_p
157 PARAMS ((bfd
*, const Elf_Internal_Rela
*, asection
**, boolean
));
158 static const Elf_Internal_Rela
*mips_elf64_next_relocation
159 PARAMS ((unsigned int, const Elf_Internal_Rela
*,
160 const Elf_Internal_Rela
*));
161 static boolean mips_elf64_create_dynamic_relocation
162 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
163 struct mips_elf64_link_hash_entry
*, asection
*, bfd_vma
,
164 bfd_vma
*, asection
*));
165 static bfd_reloc_status_type mips_elf64_calculate_relocation
166 PARAMS ((bfd
*, bfd
*, asection
*, struct bfd_link_info
*,
167 const Elf_Internal_Rela
*, bfd_vma
, reloc_howto_type
*,
168 Elf_Internal_Sym
*, asection
**, bfd_vma
*, const char **,
170 static bfd_vma mips_elf64_obtain_contents
171 PARAMS ((reloc_howto_type
*, const Elf_Internal_Rela
*, bfd
*, bfd_byte
*));
172 static boolean mips_elf64_perform_relocation
173 PARAMS ((struct bfd_link_info
*, reloc_howto_type
*,
174 const Elf_Internal_Rela
*, bfd_vma
,
175 bfd
*, asection
*, bfd_byte
*, boolean
));
176 static boolean mips_elf64_relocate_section
177 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
178 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
179 boolean mips_elf64_create_dynamic_sections
180 PARAMS ((bfd
*, struct bfd_link_info
*));
181 boolean mips_elf64_adjust_dynamic_symbol
182 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*h
));
183 boolean mips_elf64_always_size_sections
184 PARAMS ((bfd
*, struct bfd_link_info
*));
185 static boolean mips_elf64_check_mips16_stubs
186 PARAMS ((struct mips_elf64_link_hash_entry
*, PTR
));
187 boolean mips_elf64_size_dynamic_sections
188 PARAMS ((bfd
*, struct bfd_link_info
*));
189 boolean mips_elf64_finish_dynamic_symbol
190 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
191 Elf_Internal_Sym
*));
192 boolean mips_elf64_finish_dynamic_sections
193 PARAMS ((bfd
*, struct bfd_link_info
*info
));
194 asection
*mips_elf64_gc_mark_hook
195 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
196 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
197 boolean mips_elf64_gc_sweep_hook
198 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
199 const Elf_Internal_Rela
*));
200 static boolean mips_elf64_create_got_section
201 PARAMS ((bfd
*, struct bfd_link_info
*));
202 static boolean mips_elf64_record_global_got_symbol
203 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*,
204 struct mips_elf64_got_info
*));
205 static asection
*mips_elf64_create_msym_section
PARAMS((bfd
*));
206 static void mips_elf64_allocate_dynamic_relocations
207 PARAMS ((bfd
*, unsigned int));
208 static boolean mips_elf64_stub_section_p
PARAMS ((bfd
*, asection
*));
209 boolean mips_elf64_check_relocs
210 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
211 const Elf_Internal_Rela
*));
212 static boolean mips_elf64_output_extsym
213 PARAMS ((struct mips_elf64_link_hash_entry
*, PTR
));
214 static void mips_elf64_swap_gptab_in
215 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
216 static void mips_elf64_swap_gptab_out
217 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
218 static int gptab_compare
PARAMS ((const PTR
, const PTR
));
219 boolean mips_elf64_final_link
PARAMS ((bfd
*, struct bfd_link_info
*));
221 extern const bfd_target bfd_elf64_bigmips_vec
;
222 extern const bfd_target bfd_elf64_littlemips_vec
;
224 static bfd_vma prev_reloc_addend
= 0;
225 static bfd_size_type prev_reloc_address
= 0;
227 /* Whether we are trying to be compatible with IRIX6 (or little endianers
228 which are otherwise IRIX-ABI compliant). */
229 #define SGI_COMPAT(abfd) \
230 ((abfd->xvec == &bfd_elf64_bigmips_vec) \
231 || (abfd->xvec == &bfd_elf64_littlemips_vec) ? true : false)
233 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
234 from smaller values. Start with zero, widen, *then* decrement. */
235 #define MINUS_ONE (((bfd_vma)0) - 1)
237 /* The number of local .got entries we reserve. */
238 #define MIPS_RESERVED_GOTNO (2)
240 /* Instructions which appear in a stub. */
241 #define ELF_MIPS_GP_OFFSET(abfd) 0x7ff0
242 #define STUB_LW 0xdf998010 /* ld t9,0x8010(gp) */
243 #define STUB_MOVE 0x03e07825 /* move t7,ra */
244 #define STUB_JALR 0x0320f809 /* jal t9 */
245 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
246 #define MIPS_FUNCTION_STUB_SIZE (16)
248 /* The relocation table used for SHT_REL sections. */
250 #define UNUSED_RELOC(num) { num, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
252 static reloc_howto_type mips_elf64_howto_table_rel
[] =
255 HOWTO (R_MIPS_NONE
, /* type */
257 0, /* size (0 = byte, 1 = short, 2 = long) */
259 false, /* pc_relative */
261 complain_overflow_dont
, /* complain_on_overflow */
262 bfd_elf_generic_reloc
, /* special_function */
263 "R_MIPS_NONE", /* name */
264 false, /* partial_inplace */
267 false), /* pcrel_offset */
269 /* 16 bit relocation. */
270 HOWTO (R_MIPS_16
, /* type */
272 2, /* size (0 = byte, 1 = short, 2 = long) */
274 false, /* pc_relative */
276 complain_overflow_signed
, /* complain_on_overflow */
277 bfd_elf_generic_reloc
, /* special_function */
278 "R_MIPS_16", /* name */
279 true, /* partial_inplace */
280 0x0000ffff, /* src_mask */
281 0x0000ffff, /* dst_mask */
282 false), /* pcrel_offset */
284 /* 32 bit relocation. */
285 HOWTO (R_MIPS_32
, /* type */
287 2, /* size (0 = byte, 1 = short, 2 = long) */
289 false, /* pc_relative */
291 complain_overflow_dont
, /* complain_on_overflow */
292 bfd_elf_generic_reloc
, /* special_function */
293 "R_MIPS_32", /* name */
294 true, /* partial_inplace */
295 0xffffffff, /* src_mask */
296 0xffffffff, /* dst_mask */
297 false), /* pcrel_offset */
299 /* 32 bit symbol relative relocation. */
300 HOWTO (R_MIPS_REL32
, /* type */
302 2, /* size (0 = byte, 1 = short, 2 = long) */
304 false, /* pc_relative */
306 complain_overflow_dont
, /* complain_on_overflow */
307 bfd_elf_generic_reloc
, /* special_function */
308 "R_MIPS_REL32", /* name */
309 true, /* partial_inplace */
310 0xffffffff, /* src_mask */
311 0xffffffff, /* dst_mask */
312 false), /* pcrel_offset */
314 /* 26 bit jump address. */
315 HOWTO (R_MIPS_26
, /* type */
317 2, /* size (0 = byte, 1 = short, 2 = long) */
319 false, /* pc_relative */
321 complain_overflow_dont
, /* complain_on_overflow */
322 /* This needs complex overflow
323 detection, because the upper 36
324 bits must match the PC + 4. */
325 bfd_elf_generic_reloc
, /* special_function */
326 "R_MIPS_26", /* name */
327 true, /* partial_inplace */
328 0x03ffffff, /* src_mask */
329 0x03ffffff, /* dst_mask */
330 false), /* pcrel_offset */
332 /* High 16 bits of symbol value. */
333 HOWTO (R_MIPS_HI16
, /* type */
335 2, /* size (0 = byte, 1 = short, 2 = long) */
337 false, /* pc_relative */
339 complain_overflow_dont
, /* complain_on_overflow */
340 bfd_elf_generic_reloc
, /* special_function */
341 "R_MIPS_HI16", /* name */
342 true, /* partial_inplace */
343 0x0000ffff, /* src_mask */
344 0x0000ffff, /* dst_mask */
345 false), /* pcrel_offset */
347 /* Low 16 bits of symbol value. */
348 HOWTO (R_MIPS_LO16
, /* type */
350 2, /* size (0 = byte, 1 = short, 2 = long) */
352 false, /* pc_relative */
354 complain_overflow_dont
, /* complain_on_overflow */
355 bfd_elf_generic_reloc
, /* special_function */
356 "R_MIPS_LO16", /* name */
357 true, /* partial_inplace */
358 0x0000ffff, /* src_mask */
359 0x0000ffff, /* dst_mask */
360 false), /* pcrel_offset */
362 /* GP relative reference. */
363 HOWTO (R_MIPS_GPREL16
, /* type */
365 2, /* size (0 = byte, 1 = short, 2 = long) */
367 false, /* pc_relative */
369 complain_overflow_signed
, /* complain_on_overflow */
370 mips_elf64_gprel16_reloc
, /* special_function */
371 "R_MIPS_GPREL16", /* name */
372 true, /* partial_inplace */
373 0x0000ffff, /* src_mask */
374 0x0000ffff, /* dst_mask */
375 false), /* pcrel_offset */
377 /* Reference to literal section. */
378 HOWTO (R_MIPS_LITERAL
, /* type */
380 2, /* size (0 = byte, 1 = short, 2 = long) */
382 false, /* pc_relative */
384 complain_overflow_signed
, /* complain_on_overflow */
385 mips_elf64_literal_reloc
, /* special_function */
386 "R_MIPS_LITERAL", /* name */
387 true, /* partial_inplace */
388 0x0000ffff, /* src_mask */
389 0x0000ffff, /* dst_mask */
390 false), /* pcrel_offset */
392 /* Reference to global offset table. */
393 HOWTO (R_MIPS_GOT16
, /* type */
395 2, /* size (0 = byte, 1 = short, 2 = long) */
397 false, /* pc_relative */
399 complain_overflow_signed
, /* complain_on_overflow */
400 mips_elf64_got16_reloc
, /* special_function */
401 "R_MIPS_GOT16", /* name */
402 true, /* partial_inplace */
403 0x0000ffff, /* src_mask */
404 0x0000ffff, /* dst_mask */
405 false), /* pcrel_offset */
407 /* 16 bit PC relative reference. */
408 HOWTO (R_MIPS_PC16
, /* type */
410 2, /* size (0 = byte, 1 = short, 2 = long) */
412 true, /* pc_relative */
414 complain_overflow_signed
, /* complain_on_overflow */
415 bfd_elf_generic_reloc
, /* special_function */
416 "R_MIPS_PC16", /* name */
417 true, /* partial_inplace */
418 0x0000ffff, /* src_mask */
419 0x0000ffff, /* dst_mask */
420 true), /* pcrel_offset */
422 /* 16 bit call through global offset table. */
423 /* FIXME: This is not handled correctly. */
424 HOWTO (R_MIPS_CALL16
, /* type */
426 2, /* size (0 = byte, 1 = short, 2 = long) */
428 false, /* pc_relative */
430 complain_overflow_signed
, /* complain_on_overflow */
431 bfd_elf_generic_reloc
, /* special_function */
432 "R_MIPS_CALL16", /* name */
433 true, /* partial_inplace */
434 0x0000ffff, /* src_mask */
435 0x0000ffff, /* dst_mask */
436 false), /* pcrel_offset */
438 /* 32 bit GP relative reference. */
439 HOWTO (R_MIPS_GPREL32
, /* type */
441 2, /* size (0 = byte, 1 = short, 2 = long) */
443 false, /* pc_relative */
445 complain_overflow_dont
, /* complain_on_overflow */
446 mips_elf64_gprel32_reloc
, /* special_function */
447 "R_MIPS_GPREL32", /* name */
448 true, /* partial_inplace */
449 0xffffffff, /* src_mask */
450 0xffffffff, /* dst_mask */
451 false), /* pcrel_offset */
457 /* A 5 bit shift field. */
458 HOWTO (R_MIPS_SHIFT5
, /* type */
460 2, /* size (0 = byte, 1 = short, 2 = long) */
462 false, /* pc_relative */
464 complain_overflow_bitfield
, /* complain_on_overflow */
465 bfd_elf_generic_reloc
, /* special_function */
466 "R_MIPS_SHIFT5", /* name */
467 true, /* partial_inplace */
468 0x000007c0, /* src_mask */
469 0x000007c0, /* dst_mask */
470 false), /* pcrel_offset */
472 /* A 6 bit shift field. */
473 HOWTO (R_MIPS_SHIFT6
, /* type */
475 2, /* size (0 = byte, 1 = short, 2 = long) */
477 false, /* pc_relative */
479 complain_overflow_bitfield
, /* complain_on_overflow */
480 mips_elf64_shift6_reloc
, /* special_function */
481 "R_MIPS_SHIFT6", /* name */
482 true, /* partial_inplace */
483 0x000007c4, /* src_mask */
484 0x000007c4, /* dst_mask */
485 false), /* pcrel_offset */
487 /* 64 bit relocation. */
488 HOWTO (R_MIPS_64
, /* type */
490 4, /* size (0 = byte, 1 = short, 2 = long) */
492 false, /* pc_relative */
494 complain_overflow_dont
, /* complain_on_overflow */
495 bfd_elf_generic_reloc
, /* special_function */
496 "R_MIPS_64", /* name */
497 true, /* partial_inplace */
498 MINUS_ONE
, /* src_mask */
499 MINUS_ONE
, /* dst_mask */
500 false), /* pcrel_offset */
502 /* Displacement in the global offset table. */
503 /* FIXME: Not handled correctly. */
504 HOWTO (R_MIPS_GOT_DISP
, /* type */
506 2, /* size (0 = byte, 1 = short, 2 = long) */
508 false, /* pc_relative */
510 complain_overflow_signed
, /* complain_on_overflow */
511 bfd_elf_generic_reloc
, /* special_function */
512 "R_MIPS_GOT_DISP", /* name */
513 true, /* partial_inplace */
514 0x0000ffff, /* src_mask */
515 0x0000ffff, /* dst_mask */
516 false), /* pcrel_offset */
518 /* Displacement to page pointer in the global offset table. */
519 /* FIXME: Not handled correctly. */
520 HOWTO (R_MIPS_GOT_PAGE
, /* type */
522 2, /* size (0 = byte, 1 = short, 2 = long) */
524 false, /* pc_relative */
526 complain_overflow_signed
, /* complain_on_overflow */
527 bfd_elf_generic_reloc
, /* special_function */
528 "R_MIPS_GOT_PAGE", /* name */
529 true, /* partial_inplace */
530 0x0000ffff, /* src_mask */
531 0x0000ffff, /* dst_mask */
532 false), /* pcrel_offset */
534 /* Offset from page pointer in the global offset table. */
535 /* FIXME: Not handled correctly. */
536 HOWTO (R_MIPS_GOT_OFST
, /* type */
538 2, /* size (0 = byte, 1 = short, 2 = long) */
540 false, /* pc_relative */
542 complain_overflow_signed
, /* complain_on_overflow */
543 bfd_elf_generic_reloc
, /* special_function */
544 "R_MIPS_GOT_OFST", /* name */
545 true, /* partial_inplace */
546 0x0000ffff, /* src_mask */
547 0x0000ffff, /* dst_mask */
548 false), /* pcrel_offset */
550 /* High 16 bits of displacement in global offset table. */
551 /* FIXME: Not handled correctly. */
552 HOWTO (R_MIPS_GOT_HI16
, /* type */
554 2, /* size (0 = byte, 1 = short, 2 = long) */
556 false, /* pc_relative */
558 complain_overflow_dont
, /* complain_on_overflow */
559 bfd_elf_generic_reloc
, /* special_function */
560 "R_MIPS_GOT_HI16", /* name */
561 true, /* partial_inplace */
562 0x0000ffff, /* src_mask */
563 0x0000ffff, /* dst_mask */
564 false), /* pcrel_offset */
566 /* Low 16 bits of displacement in global offset table. */
567 /* FIXME: Not handled correctly. */
568 HOWTO (R_MIPS_GOT_LO16
, /* type */
570 2, /* size (0 = byte, 1 = short, 2 = long) */
572 false, /* pc_relative */
574 complain_overflow_dont
, /* complain_on_overflow */
575 bfd_elf_generic_reloc
, /* special_function */
576 "R_MIPS_GOT_LO16", /* name */
577 true, /* partial_inplace */
578 0x0000ffff, /* src_mask */
579 0x0000ffff, /* dst_mask */
580 false), /* pcrel_offset */
582 /* 64 bit substraction. */
583 /* FIXME: Not handled correctly. */
584 HOWTO (R_MIPS_SUB
, /* type */
586 4, /* size (0 = byte, 1 = short, 2 = long) */
588 false, /* pc_relative */
590 complain_overflow_dont
, /* complain_on_overflow */
591 bfd_elf_generic_reloc
, /* special_function */
592 "R_MIPS_SUB", /* name */
593 true, /* partial_inplace */
594 MINUS_ONE
, /* src_mask */
595 MINUS_ONE
, /* dst_mask */
596 false), /* pcrel_offset */
598 /* Insert the addend as an instruction. */
599 /* FIXME: Not handled correctly. */
600 HOWTO (R_MIPS_INSERT_A
, /* type */
602 2, /* size (0 = byte, 1 = short, 2 = long) */
604 false, /* pc_relative */
606 complain_overflow_dont
, /* complain_on_overflow */
607 bfd_elf_generic_reloc
, /* special_function */
608 "R_MIPS_INSERT_A", /* name */
609 true, /* partial_inplace */
610 0xffffffff, /* src_mask */
611 0xffffffff, /* dst_mask */
612 false), /* pcrel_offset */
614 /* Insert the addend as an instruction, and change all relocations
615 to refer to the old instruction at the address. */
616 /* FIXME: Not handled correctly. */
617 HOWTO (R_MIPS_INSERT_B
, /* type */
619 2, /* size (0 = byte, 1 = short, 2 = long) */
621 false, /* pc_relative */
623 complain_overflow_dont
, /* complain_on_overflow */
624 bfd_elf_generic_reloc
, /* special_function */
625 "R_MIPS_INSERT_B", /* name */
626 true, /* partial_inplace */
627 0xffffffff, /* src_mask */
628 0xffffffff, /* dst_mask */
629 false), /* pcrel_offset */
631 /* Delete a 32 bit instruction. */
632 /* FIXME: Not handled correctly. */
633 HOWTO (R_MIPS_DELETE
, /* type */
635 2, /* size (0 = byte, 1 = short, 2 = long) */
637 false, /* pc_relative */
639 complain_overflow_dont
, /* complain_on_overflow */
640 bfd_elf_generic_reloc
, /* special_function */
641 "R_MIPS_DELETE", /* name */
642 true, /* partial_inplace */
643 0xffffffff, /* src_mask */
644 0xffffffff, /* dst_mask */
645 false), /* pcrel_offset */
647 /* Get the higher value of a 64 bit addend. */
648 HOWTO (R_MIPS_HIGHER
, /* type */
650 2, /* size (0 = byte, 1 = short, 2 = long) */
652 false, /* pc_relative */
654 complain_overflow_dont
, /* complain_on_overflow */
655 mips_elf64_higher_reloc
, /* special_function */
656 "R_MIPS_HIGHER", /* name */
657 true, /* partial_inplace */
658 0x0000ffff, /* src_mask */
659 0x0000ffff, /* dst_mask */
660 false), /* pcrel_offset */
662 /* Get the highest value of a 64 bit addend. */
663 HOWTO (R_MIPS_HIGHEST
, /* type */
665 2, /* size (0 = byte, 1 = short, 2 = long) */
667 false, /* pc_relative */
669 complain_overflow_dont
, /* complain_on_overflow */
670 mips_elf64_highest_reloc
, /* special_function */
671 "R_MIPS_HIGHEST", /* name */
672 true, /* partial_inplace */
673 0x0000ffff, /* src_mask */
674 0x0000ffff, /* dst_mask */
675 false), /* pcrel_offset */
677 /* High 16 bits of displacement in global offset table. */
678 /* FIXME: Not handled correctly. */
679 HOWTO (R_MIPS_CALL_HI16
, /* type */
681 2, /* size (0 = byte, 1 = short, 2 = long) */
683 false, /* pc_relative */
685 complain_overflow_dont
, /* complain_on_overflow */
686 bfd_elf_generic_reloc
, /* special_function */
687 "R_MIPS_CALL_HI16", /* name */
688 true, /* partial_inplace */
689 0x0000ffff, /* src_mask */
690 0x0000ffff, /* dst_mask */
691 false), /* pcrel_offset */
693 /* Low 16 bits of displacement in global offset table. */
694 /* FIXME: Not handled correctly. */
695 HOWTO (R_MIPS_CALL_LO16
, /* type */
697 2, /* size (0 = byte, 1 = short, 2 = long) */
699 false, /* pc_relative */
701 complain_overflow_dont
, /* complain_on_overflow */
702 bfd_elf_generic_reloc
, /* special_function */
703 "R_MIPS_CALL_LO16", /* name */
704 true, /* partial_inplace */
705 0x0000ffff, /* src_mask */
706 0x0000ffff, /* dst_mask */
707 false), /* pcrel_offset */
709 /* Section displacement, used by an associated event location section. */
710 /* FIXME: Not handled correctly. */
711 HOWTO (R_MIPS_SCN_DISP
, /* type */
713 2, /* size (0 = byte, 1 = short, 2 = long) */
715 false, /* pc_relative */
717 complain_overflow_dont
, /* complain_on_overflow */
718 bfd_elf_generic_reloc
, /* special_function */
719 "R_MIPS_SCN_DISP", /* name */
720 true, /* partial_inplace */
721 0xffffffff, /* src_mask */
722 0xffffffff, /* dst_mask */
723 false), /* pcrel_offset */
725 HOWTO (R_MIPS_REL16
, /* type */
727 1, /* size (0 = byte, 1 = short, 2 = long) */
729 false, /* pc_relative */
731 complain_overflow_signed
, /* complain_on_overflow */
732 bfd_elf_generic_reloc
, /* special_function */
733 "R_MIPS_REL16", /* name */
734 true, /* partial_inplace */
735 0xffff, /* src_mask */
736 0xffff, /* dst_mask */
737 false), /* pcrel_offset */
739 /* These two are obsolete. */
740 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE
),
741 EMPTY_HOWTO (R_MIPS_PJUMP
),
743 /* Similiar to R_MIPS_REL32, but used for relocations in a GOT section.
744 It must be used for multigot GOT's (and only there). */
745 HOWTO (R_MIPS_RELGOT
, /* type */
747 2, /* size (0 = byte, 1 = short, 2 = long) */
749 false, /* pc_relative */
751 complain_overflow_dont
, /* complain_on_overflow */
752 bfd_elf_generic_reloc
, /* special_function */
753 "R_MIPS_RELGOT", /* name */
754 true, /* partial_inplace */
755 0xffffffff, /* src_mask */
756 0xffffffff, /* dst_mask */
757 false), /* pcrel_offset */
759 /* Protected jump conversion. This is an optimization hint. No
760 relocation is required for correctness. */
761 HOWTO (R_MIPS_JALR
, /* type */
763 2, /* size (0 = byte, 1 = short, 2 = long) */
765 false, /* pc_relative */
767 complain_overflow_dont
, /* complain_on_overflow */
768 bfd_elf_generic_reloc
, /* special_function */
769 "R_MIPS_JALR", /* name */
770 false, /* partial_inplace */
772 0x00000000, /* dst_mask */
773 false), /* pcrel_offset */
776 /* The relocation table used for SHT_RELA sections. */
778 static reloc_howto_type mips_elf64_howto_table_rela
[] =
781 HOWTO (R_MIPS_NONE
, /* type */
783 0, /* size (0 = byte, 1 = short, 2 = long) */
785 false, /* pc_relative */
787 complain_overflow_dont
, /* complain_on_overflow */
788 bfd_elf_generic_reloc
, /* special_function */
789 "R_MIPS_NONE", /* name */
790 false, /* partial_inplace */
793 false), /* pcrel_offset */
795 /* 16 bit relocation. */
796 HOWTO (R_MIPS_16
, /* type */
798 2, /* size (0 = byte, 1 = short, 2 = long) */
800 false, /* pc_relative */
802 complain_overflow_signed
, /* complain_on_overflow */
803 bfd_elf_generic_reloc
, /* special_function */
804 "R_MIPS_16", /* name */
805 false, /* partial_inplace */
807 0x0000ffff, /* dst_mask */
808 false), /* pcrel_offset */
810 /* 32 bit relocation. */
811 HOWTO (R_MIPS_32
, /* type */
813 2, /* size (0 = byte, 1 = short, 2 = long) */
815 false, /* pc_relative */
817 complain_overflow_dont
, /* complain_on_overflow */
818 bfd_elf_generic_reloc
, /* special_function */
819 "R_MIPS_32", /* name */
820 false, /* partial_inplace */
822 0xffffffff, /* dst_mask */
823 false), /* pcrel_offset */
825 /* 32 bit symbol relative relocation. */
826 HOWTO (R_MIPS_REL32
, /* type */
828 2, /* size (0 = byte, 1 = short, 2 = long) */
830 false, /* pc_relative */
832 complain_overflow_dont
, /* complain_on_overflow */
833 bfd_elf_generic_reloc
, /* special_function */
834 "R_MIPS_REL32", /* name */
835 false, /* partial_inplace */
837 0xffffffff, /* dst_mask */
838 false), /* pcrel_offset */
840 /* 26 bit jump address. */
841 HOWTO (R_MIPS_26
, /* type */
843 2, /* size (0 = byte, 1 = short, 2 = long) */
845 false, /* pc_relative */
847 complain_overflow_dont
, /* complain_on_overflow */
848 /* This needs complex overflow
849 detection, because the upper 36
850 bits must match the PC + 4. */
851 bfd_elf_generic_reloc
, /* special_function */
852 "R_MIPS_26", /* name */
853 false, /* partial_inplace */
855 0x03ffffff, /* dst_mask */
856 false), /* pcrel_offset */
858 /* R_MIPS_HI16 and R_MIPS_LO16 are unsupported for 64 bit REL. */
859 /* High 16 bits of symbol value. */
860 HOWTO (R_MIPS_HI16
, /* type */
862 2, /* size (0 = byte, 1 = short, 2 = long) */
864 false, /* pc_relative */
866 complain_overflow_dont
, /* complain_on_overflow */
867 bfd_elf_generic_reloc
, /* special_function */
868 "R_MIPS_HI16", /* name */
869 false, /* partial_inplace */
871 0x0000ffff, /* dst_mask */
872 false), /* pcrel_offset */
874 /* Low 16 bits of symbol value. */
875 HOWTO (R_MIPS_LO16
, /* type */
877 2, /* size (0 = byte, 1 = short, 2 = long) */
879 false, /* pc_relative */
881 complain_overflow_dont
, /* complain_on_overflow */
882 bfd_elf_generic_reloc
, /* special_function */
883 "R_MIPS_LO16", /* name */
884 false, /* partial_inplace */
886 0x0000ffff, /* dst_mask */
887 false), /* pcrel_offset */
889 /* GP relative reference. */
890 HOWTO (R_MIPS_GPREL16
, /* type */
892 2, /* size (0 = byte, 1 = short, 2 = long) */
894 false, /* pc_relative */
896 complain_overflow_signed
, /* complain_on_overflow */
897 mips_elf64_gprel16_reloca
, /* special_function */
898 "R_MIPS_GPREL16", /* name */
899 false, /* partial_inplace */
901 0x0000ffff, /* dst_mask */
902 false), /* pcrel_offset */
904 /* Reference to literal section. */
905 HOWTO (R_MIPS_LITERAL
, /* type */
907 2, /* size (0 = byte, 1 = short, 2 = long) */
909 false, /* pc_relative */
911 complain_overflow_signed
, /* complain_on_overflow */
912 mips_elf64_literal_reloc
, /* special_function */
913 "R_MIPS_LITERAL", /* name */
914 false, /* partial_inplace */
916 0x0000ffff, /* dst_mask */
917 false), /* pcrel_offset */
919 /* Reference to global offset table. */
920 /* FIXME: This is not handled correctly. */
921 HOWTO (R_MIPS_GOT16
, /* type */
923 2, /* size (0 = byte, 1 = short, 2 = long) */
925 false, /* pc_relative */
927 complain_overflow_signed
, /* complain_on_overflow */
928 bfd_elf_generic_reloc
, /* special_function */
929 "R_MIPS_GOT16", /* name */
930 false, /* partial_inplace */
932 0x0000ffff, /* dst_mask */
933 false), /* pcrel_offset */
935 /* 16 bit PC relative reference. */
936 HOWTO (R_MIPS_PC16
, /* type */
938 2, /* size (0 = byte, 1 = short, 2 = long) */
940 true, /* pc_relative */
942 complain_overflow_signed
, /* complain_on_overflow */
943 bfd_elf_generic_reloc
, /* special_function */
944 "R_MIPS_PC16", /* name */
945 false, /* partial_inplace */
947 0x0000ffff, /* dst_mask */
948 true), /* pcrel_offset */
950 /* 16 bit call through global offset table. */
951 /* FIXME: This is not handled correctly. */
952 HOWTO (R_MIPS_CALL16
, /* type */
954 2, /* size (0 = byte, 1 = short, 2 = long) */
956 false, /* pc_relative */
958 complain_overflow_signed
, /* complain_on_overflow */
959 bfd_elf_generic_reloc
, /* special_function */
960 "R_MIPS_CALL16", /* name */
961 false, /* partial_inplace */
963 0x0000ffff, /* dst_mask */
964 false), /* pcrel_offset */
966 /* 32 bit GP relative reference. */
967 HOWTO (R_MIPS_GPREL32
, /* type */
969 2, /* size (0 = byte, 1 = short, 2 = long) */
971 false, /* pc_relative */
973 complain_overflow_dont
, /* complain_on_overflow */
974 mips_elf64_gprel32_reloc
, /* special_function */
975 "R_MIPS_GPREL32", /* name */
976 false, /* partial_inplace */
978 0xffffffff, /* dst_mask */
979 false), /* pcrel_offset */
985 /* A 5 bit shift field. */
986 HOWTO (R_MIPS_SHIFT5
, /* type */
988 2, /* size (0 = byte, 1 = short, 2 = long) */
990 false, /* pc_relative */
992 complain_overflow_bitfield
, /* complain_on_overflow */
993 bfd_elf_generic_reloc
, /* special_function */
994 "R_MIPS_SHIFT5", /* name */
995 false, /* partial_inplace */
997 0x000007c0, /* dst_mask */
998 false), /* pcrel_offset */
1000 /* A 6 bit shift field. */
1001 HOWTO (R_MIPS_SHIFT6
, /* type */
1003 2, /* size (0 = byte, 1 = short, 2 = long) */
1005 false, /* pc_relative */
1007 complain_overflow_bitfield
, /* complain_on_overflow */
1008 mips_elf64_shift6_reloc
, /* special_function */
1009 "R_MIPS_SHIFT6", /* name */
1010 false, /* partial_inplace */
1012 0x000007c4, /* dst_mask */
1013 false), /* pcrel_offset */
1015 /* 64 bit relocation. */
1016 HOWTO (R_MIPS_64
, /* type */
1018 4, /* size (0 = byte, 1 = short, 2 = long) */
1020 false, /* pc_relative */
1022 complain_overflow_dont
, /* complain_on_overflow */
1023 bfd_elf_generic_reloc
, /* special_function */
1024 "R_MIPS_64", /* name */
1025 false, /* partial_inplace */
1027 MINUS_ONE
, /* dst_mask */
1028 false), /* pcrel_offset */
1030 /* Displacement in the global offset table. */
1031 /* FIXME: Not handled correctly. */
1032 HOWTO (R_MIPS_GOT_DISP
, /* type */
1034 2, /* size (0 = byte, 1 = short, 2 = long) */
1036 false, /* pc_relative */
1038 complain_overflow_signed
, /* complain_on_overflow */
1039 bfd_elf_generic_reloc
, /* special_function */
1040 "R_MIPS_GOT_DISP", /* name */
1041 false, /* partial_inplace */
1043 0x0000ffff, /* dst_mask */
1044 false), /* pcrel_offset */
1046 /* Displacement to page pointer in the global offset table. */
1047 /* FIXME: Not handled correctly. */
1048 HOWTO (R_MIPS_GOT_PAGE
, /* type */
1050 2, /* size (0 = byte, 1 = short, 2 = long) */
1052 false, /* pc_relative */
1054 complain_overflow_signed
, /* complain_on_overflow */
1055 bfd_elf_generic_reloc
, /* special_function */
1056 "R_MIPS_GOT_PAGE", /* name */
1057 false, /* partial_inplace */
1059 0x0000ffff, /* dst_mask */
1060 false), /* pcrel_offset */
1062 /* Offset from page pointer in the global offset table. */
1063 /* FIXME: Not handled correctly. */
1064 HOWTO (R_MIPS_GOT_OFST
, /* type */
1066 2, /* size (0 = byte, 1 = short, 2 = long) */
1068 false, /* pc_relative */
1070 complain_overflow_signed
, /* complain_on_overflow */
1071 bfd_elf_generic_reloc
, /* special_function */
1072 "R_MIPS_GOT_OFST", /* name */
1073 false, /* partial_inplace */
1075 0x0000ffff, /* dst_mask */
1076 false), /* pcrel_offset */
1078 /* High 16 bits of displacement in global offset table. */
1079 /* FIXME: Not handled correctly. */
1080 HOWTO (R_MIPS_GOT_HI16
, /* type */
1082 2, /* size (0 = byte, 1 = short, 2 = long) */
1084 false, /* pc_relative */
1086 complain_overflow_dont
, /* complain_on_overflow */
1087 bfd_elf_generic_reloc
, /* special_function */
1088 "R_MIPS_GOT_HI16", /* name */
1089 false, /* partial_inplace */
1091 0x0000ffff, /* dst_mask */
1092 false), /* pcrel_offset */
1094 /* Low 16 bits of displacement in global offset table. */
1095 /* FIXME: Not handled correctly. */
1096 HOWTO (R_MIPS_GOT_LO16
, /* type */
1098 2, /* size (0 = byte, 1 = short, 2 = long) */
1100 false, /* pc_relative */
1102 complain_overflow_dont
, /* complain_on_overflow */
1103 bfd_elf_generic_reloc
, /* special_function */
1104 "R_MIPS_GOT_LO16", /* name */
1105 false, /* partial_inplace */
1107 0x0000ffff, /* dst_mask */
1108 false), /* pcrel_offset */
1110 /* 64 bit substraction. */
1111 /* FIXME: Not handled correctly. */
1112 HOWTO (R_MIPS_SUB
, /* type */
1114 4, /* size (0 = byte, 1 = short, 2 = long) */
1116 false, /* pc_relative */
1118 complain_overflow_dont
, /* complain_on_overflow */
1119 bfd_elf_generic_reloc
, /* special_function */
1120 "R_MIPS_SUB", /* name */
1121 false, /* partial_inplace */
1123 MINUS_ONE
, /* dst_mask */
1124 false), /* pcrel_offset */
1126 /* Insert the addend as an instruction. */
1127 /* FIXME: Not handled correctly. */
1128 HOWTO (R_MIPS_INSERT_A
, /* type */
1130 2, /* size (0 = byte, 1 = short, 2 = long) */
1132 false, /* pc_relative */
1134 complain_overflow_dont
, /* complain_on_overflow */
1135 bfd_elf_generic_reloc
, /* special_function */
1136 "R_MIPS_INSERT_A", /* name */
1137 false, /* partial_inplace */
1139 0xffffffff, /* dst_mask */
1140 false), /* pcrel_offset */
1142 /* Insert the addend as an instruction, and change all relocations
1143 to refer to the old instruction at the address. */
1144 /* FIXME: Not handled correctly. */
1145 HOWTO (R_MIPS_INSERT_B
, /* type */
1147 2, /* size (0 = byte, 1 = short, 2 = long) */
1149 false, /* pc_relative */
1151 complain_overflow_dont
, /* complain_on_overflow */
1152 bfd_elf_generic_reloc
, /* special_function */
1153 "R_MIPS_INSERT_B", /* name */
1154 false, /* partial_inplace */
1156 0xffffffff, /* dst_mask */
1157 false), /* pcrel_offset */
1159 /* Delete a 32 bit instruction. */
1160 /* FIXME: Not handled correctly. */
1161 HOWTO (R_MIPS_DELETE
, /* type */
1163 2, /* size (0 = byte, 1 = short, 2 = long) */
1165 false, /* pc_relative */
1167 complain_overflow_dont
, /* complain_on_overflow */
1168 bfd_elf_generic_reloc
, /* special_function */
1169 "R_MIPS_DELETE", /* name */
1170 false, /* partial_inplace */
1172 0xffffffff, /* dst_mask */
1173 false), /* pcrel_offset */
1175 /* Get the higher value of a 64 bit addend. */
1176 HOWTO (R_MIPS_HIGHER
, /* type */
1178 2, /* size (0 = byte, 1 = short, 2 = long) */
1180 false, /* pc_relative */
1182 complain_overflow_dont
, /* complain_on_overflow */
1183 bfd_elf_generic_reloc
, /* special_function */
1184 "R_MIPS_HIGHER", /* name */
1185 false, /* partial_inplace */
1187 0x0000ffff, /* dst_mask */
1188 false), /* pcrel_offset */
1190 /* Get the highest value of a 64 bit addend. */
1191 HOWTO (R_MIPS_HIGHEST
, /* type */
1193 2, /* size (0 = byte, 1 = short, 2 = long) */
1195 false, /* pc_relative */
1197 complain_overflow_dont
, /* complain_on_overflow */
1198 bfd_elf_generic_reloc
, /* special_function */
1199 "R_MIPS_HIGHEST", /* name */
1200 false, /* partial_inplace */
1202 0x0000ffff, /* dst_mask */
1203 false), /* pcrel_offset */
1205 /* High 16 bits of displacement in global offset table. */
1206 /* FIXME: Not handled correctly. */
1207 HOWTO (R_MIPS_CALL_HI16
, /* type */
1209 2, /* size (0 = byte, 1 = short, 2 = long) */
1211 false, /* pc_relative */
1213 complain_overflow_dont
, /* complain_on_overflow */
1214 bfd_elf_generic_reloc
, /* special_function */
1215 "R_MIPS_CALL_HI16", /* name */
1216 false, /* partial_inplace */
1218 0x0000ffff, /* dst_mask */
1219 false), /* pcrel_offset */
1221 /* Low 16 bits of displacement in global offset table. */
1222 /* FIXME: Not handled correctly. */
1223 HOWTO (R_MIPS_CALL_LO16
, /* type */
1225 2, /* size (0 = byte, 1 = short, 2 = long) */
1227 false, /* pc_relative */
1229 complain_overflow_dont
, /* complain_on_overflow */
1230 bfd_elf_generic_reloc
, /* special_function */
1231 "R_MIPS_CALL_LO16", /* name */
1232 false, /* partial_inplace */
1234 0x0000ffff, /* dst_mask */
1235 false), /* pcrel_offset */
1237 /* Section displacement, used by an associated event location section. */
1238 /* FIXME: Not handled correctly. */
1239 HOWTO (R_MIPS_SCN_DISP
, /* type */
1241 2, /* size (0 = byte, 1 = short, 2 = long) */
1243 false, /* pc_relative */
1245 complain_overflow_dont
, /* complain_on_overflow */
1246 bfd_elf_generic_reloc
, /* special_function */
1247 "R_MIPS_SCN_DISP", /* name */
1248 false, /* partial_inplace */
1250 0xffffffff, /* dst_mask */
1251 false), /* pcrel_offset */
1253 HOWTO (R_MIPS_REL16
, /* type */
1255 1, /* size (0 = byte, 1 = short, 2 = long) */
1257 false, /* pc_relative */
1259 complain_overflow_signed
, /* complain_on_overflow */
1260 bfd_elf_generic_reloc
, /* special_function */
1261 "R_MIPS_REL16", /* name */
1262 false, /* partial_inplace */
1264 0xffff, /* dst_mask */
1265 false), /* pcrel_offset */
1267 /* These two are obsolete. */
1268 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE
),
1269 EMPTY_HOWTO (R_MIPS_PJUMP
),
1271 /* Similiar to R_MIPS_REL32, but used for relocations in a GOT section.
1272 It must be used for multigot GOT's (and only there). */
1273 HOWTO (R_MIPS_RELGOT
, /* type */
1275 2, /* size (0 = byte, 1 = short, 2 = long) */
1277 false, /* pc_relative */
1279 complain_overflow_dont
, /* complain_on_overflow */
1280 bfd_elf_generic_reloc
, /* special_function */
1281 "R_MIPS_RELGOT", /* name */
1282 false, /* partial_inplace */
1284 0xffffffff, /* dst_mask */
1285 false), /* pcrel_offset */
1287 /* Protected jump conversion. This is an optimization hint. No
1288 relocation is required for correctness. */
1289 HOWTO (R_MIPS_JALR
, /* type */
1291 2, /* size (0 = byte, 1 = short, 2 = long) */
1293 false, /* pc_relative */
1295 complain_overflow_dont
, /* complain_on_overflow */
1296 bfd_elf_generic_reloc
, /* special_function */
1297 "R_MIPS_JALR", /* name */
1298 false, /* partial_inplace */
1300 0x00000000, /* dst_mask */
1301 false), /* pcrel_offset */
1304 /* Swap in a MIPS 64-bit Rel reloc. */
1307 mips_elf64_swap_reloc_in (abfd
, src
, dst
)
1309 const Elf64_Mips_External_Rel
*src
;
1310 Elf64_Mips_Internal_Rel
*dst
;
1312 dst
->r_offset
= H_GET_64 (abfd
, src
->r_offset
);
1313 dst
->r_sym
= H_GET_32 (abfd
, src
->r_sym
);
1314 dst
->r_ssym
= H_GET_8 (abfd
, src
->r_ssym
);
1315 dst
->r_type3
= H_GET_8 (abfd
, src
->r_type3
);
1316 dst
->r_type2
= H_GET_8 (abfd
, src
->r_type2
);
1317 dst
->r_type
= H_GET_8 (abfd
, src
->r_type
);
1320 /* Swap in a MIPS 64-bit Rela reloc. */
1323 mips_elf64_swap_reloca_in (abfd
, src
, dst
)
1325 const Elf64_Mips_External_Rela
*src
;
1326 Elf64_Mips_Internal_Rela
*dst
;
1328 dst
->r_offset
= H_GET_64 (abfd
, src
->r_offset
);
1329 dst
->r_sym
= H_GET_32 (abfd
, src
->r_sym
);
1330 dst
->r_ssym
= H_GET_8 (abfd
, src
->r_ssym
);
1331 dst
->r_type3
= H_GET_8 (abfd
, src
->r_type3
);
1332 dst
->r_type2
= H_GET_8 (abfd
, src
->r_type2
);
1333 dst
->r_type
= H_GET_8 (abfd
, src
->r_type
);
1334 dst
->r_addend
= H_GET_S64 (abfd
, src
->r_addend
);
1337 /* Swap out a MIPS 64-bit Rel reloc. */
1340 mips_elf64_swap_reloc_out (abfd
, src
, dst
)
1342 const Elf64_Mips_Internal_Rel
*src
;
1343 Elf64_Mips_External_Rel
*dst
;
1345 H_PUT_64 (abfd
, src
->r_offset
, dst
->r_offset
);
1346 H_PUT_32 (abfd
, src
->r_sym
, dst
->r_sym
);
1347 H_PUT_8 (abfd
, src
->r_ssym
, dst
->r_ssym
);
1348 H_PUT_8 (abfd
, src
->r_type3
, dst
->r_type3
);
1349 H_PUT_8 (abfd
, src
->r_type2
, dst
->r_type2
);
1350 H_PUT_8 (abfd
, src
->r_type
, dst
->r_type
);
1353 /* Swap out a MIPS 64-bit Rela reloc. */
1356 mips_elf64_swap_reloca_out (abfd
, src
, dst
)
1358 const Elf64_Mips_Internal_Rela
*src
;
1359 Elf64_Mips_External_Rela
*dst
;
1361 H_PUT_64 (abfd
, src
->r_offset
, dst
->r_offset
);
1362 H_PUT_32 (abfd
, src
->r_sym
, dst
->r_sym
);
1363 H_PUT_8 (abfd
, src
->r_ssym
, dst
->r_ssym
);
1364 H_PUT_8 (abfd
, src
->r_type3
, dst
->r_type3
);
1365 H_PUT_8 (abfd
, src
->r_type2
, dst
->r_type2
);
1366 H_PUT_8 (abfd
, src
->r_type
, dst
->r_type
);
1367 H_PUT_S64 (abfd
, src
->r_addend
, dst
->r_addend
);
1370 /* Swap in a MIPS 64-bit Rel reloc. */
1373 mips_elf64_be_swap_reloc_in (abfd
, src
, dst
)
1375 const bfd_byte
*src
;
1376 Elf_Internal_Rel
*dst
;
1378 Elf64_Mips_Internal_Rel mirel
;
1380 mips_elf64_swap_reloc_in (abfd
,
1381 (const Elf64_Mips_External_Rel
*) src
,
1384 dst
[0].r_offset
= mirel
.r_offset
;
1385 dst
[0].r_info
= ELF64_R_INFO (mirel
.r_sym
, mirel
.r_type
);
1386 dst
[1].r_offset
= mirel
.r_offset
;
1387 dst
[1].r_info
= ELF64_R_INFO (mirel
.r_ssym
, mirel
.r_type2
);
1388 dst
[2].r_offset
= mirel
.r_offset
;
1389 dst
[2].r_info
= ELF64_R_INFO (STN_UNDEF
, mirel
.r_type3
);
1392 /* Swap in a MIPS 64-bit Rela reloc. */
1395 mips_elf64_be_swap_reloca_in (abfd
, src
, dst
)
1397 const bfd_byte
*src
;
1398 Elf_Internal_Rela
*dst
;
1400 Elf64_Mips_Internal_Rela mirela
;
1402 mips_elf64_swap_reloca_in (abfd
,
1403 (const Elf64_Mips_External_Rela
*) src
,
1406 dst
[0].r_offset
= mirela
.r_offset
;
1407 dst
[0].r_info
= ELF64_R_INFO (mirela
.r_sym
, mirela
.r_type
);
1408 dst
[0].r_addend
= mirela
.r_addend
;
1409 dst
[1].r_offset
= mirela
.r_offset
;
1410 dst
[1].r_info
= ELF64_R_INFO (mirela
.r_ssym
, mirela
.r_type2
);
1411 dst
[1].r_addend
= 0;
1412 dst
[2].r_offset
= mirela
.r_offset
;
1413 dst
[2].r_info
= ELF64_R_INFO (STN_UNDEF
, mirela
.r_type3
);
1414 dst
[2].r_addend
= 0;
1417 /* Swap out a MIPS 64-bit Rel reloc. */
1420 mips_elf64_be_swap_reloc_out (abfd
, src
, dst
)
1422 const Elf_Internal_Rel
*src
;
1425 Elf64_Mips_Internal_Rel mirel
;
1427 mirel
.r_offset
= src
[0].r_offset
;
1428 BFD_ASSERT(src
[0].r_offset
== src
[1].r_offset
);
1429 BFD_ASSERT(src
[0].r_offset
== src
[2].r_offset
);
1431 mirel
.r_type
= ELF64_MIPS_R_TYPE (src
[0].r_info
);
1432 mirel
.r_sym
= ELF64_R_SYM (src
[0].r_info
);
1433 mirel
.r_type2
= ELF64_MIPS_R_TYPE2 (src
[1].r_info
);
1434 mirel
.r_ssym
= ELF64_MIPS_R_SSYM (src
[1].r_info
);
1435 mirel
.r_type3
= ELF64_MIPS_R_TYPE3 (src
[2].r_info
);
1437 mips_elf64_swap_reloc_out (abfd
, &mirel
,
1438 (Elf64_Mips_External_Rel
*) dst
);
1441 /* Swap out a MIPS 64-bit Rela reloc. */
1444 mips_elf64_be_swap_reloca_out (abfd
, src
, dst
)
1446 const Elf_Internal_Rela
*src
;
1449 Elf64_Mips_Internal_Rela mirela
;
1451 mirela
.r_offset
= src
[0].r_offset
;
1452 BFD_ASSERT(src
[0].r_offset
== src
[1].r_offset
);
1453 BFD_ASSERT(src
[0].r_offset
== src
[2].r_offset
);
1455 mirela
.r_type
= ELF64_MIPS_R_TYPE (src
[0].r_info
);
1456 mirela
.r_sym
= ELF64_R_SYM (src
[0].r_info
);
1457 mirela
.r_addend
= src
[0].r_addend
;
1458 BFD_ASSERT(src
[1].r_addend
== 0);
1459 BFD_ASSERT(src
[2].r_addend
== 0);
1461 mirela
.r_type2
= ELF64_MIPS_R_TYPE2 (src
[1].r_info
);
1462 mirela
.r_ssym
= ELF64_MIPS_R_SSYM (src
[1].r_info
);
1463 mirela
.r_type3
= ELF64_MIPS_R_TYPE3 (src
[2].r_info
);
1465 mips_elf64_swap_reloca_out (abfd
, &mirela
,
1466 (Elf64_Mips_External_Rela
*) dst
);
1469 /* Calculate the %high function. */
1472 mips_elf64_high (value
)
1475 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
1478 /* Calculate the %higher function. */
1481 mips_elf64_higher (value
)
1484 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
1487 /* Calculate the %highest function. */
1490 mips_elf64_highest (value
)
1493 return ((value
+ (bfd_vma
) 0x800080008000) >> 48) & 0xffff;
1496 /* Do a R_MIPS_HI16 relocation. */
1498 bfd_reloc_status_type
1499 mips_elf64_hi16_reloc (abfd
,
1506 bfd
*abfd ATTRIBUTE_UNUSED
;
1507 arelent
*reloc_entry
;
1509 PTR data ATTRIBUTE_UNUSED
;
1510 asection
*input_section
;
1512 char **error_message ATTRIBUTE_UNUSED
;
1514 /* If we're relocating, and this is an external symbol, we don't
1515 want to change anything. */
1516 if (output_bfd
!= (bfd
*) NULL
1517 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1518 && (! reloc_entry
->howto
->partial_inplace
1519 || reloc_entry
->addend
== 0))
1521 reloc_entry
->address
+= input_section
->output_offset
;
1522 return bfd_reloc_ok
;
1525 if (((reloc_entry
->addend
& 0xffff) + 0x8000) & ~0xffff)
1526 reloc_entry
->addend
+= 0x8000;
1528 return bfd_reloc_continue
;
1531 /* Do a R_MIPS_HIGHER relocation. */
1533 bfd_reloc_status_type
1534 mips_elf64_higher_reloc (abfd
,
1541 bfd
*abfd ATTRIBUTE_UNUSED
;
1542 arelent
*reloc_entry
;
1544 PTR data ATTRIBUTE_UNUSED
;
1545 asection
*input_section
;
1547 char **error_message ATTRIBUTE_UNUSED
;
1549 /* If we're relocating, and this is an external symbol, we don't
1550 want to change anything. */
1551 if (output_bfd
!= (bfd
*) NULL
1552 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1553 && (! reloc_entry
->howto
->partial_inplace
1554 || reloc_entry
->addend
== 0))
1556 reloc_entry
->address
+= input_section
->output_offset
;
1557 return bfd_reloc_ok
;
1560 if (((reloc_entry
->addend
& 0xffffffff) + 0x80008000)
1562 reloc_entry
->addend
+= 0x80008000;
1564 return bfd_reloc_continue
;
1567 /* Do a R_MIPS_HIGHEST relocation. */
1569 bfd_reloc_status_type
1570 mips_elf64_highest_reloc (abfd
,
1577 bfd
*abfd ATTRIBUTE_UNUSED
;
1578 arelent
*reloc_entry
;
1580 PTR data ATTRIBUTE_UNUSED
;
1581 asection
*input_section
;
1583 char **error_message ATTRIBUTE_UNUSED
;
1585 /* If we're relocating, and this is an external symbol, we don't
1586 want to change anything. */
1587 if (output_bfd
!= (bfd
*) NULL
1588 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1589 && (! reloc_entry
->howto
->partial_inplace
1590 || reloc_entry
->addend
== 0))
1592 reloc_entry
->address
+= input_section
->output_offset
;
1593 return bfd_reloc_ok
;
1596 if (((reloc_entry
->addend
& 0xffffffffffff) + 0x800080008000)
1598 reloc_entry
->addend
+= 0x800080008000;
1600 return bfd_reloc_continue
;
1603 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
1604 table used for PIC code. If the symbol is an external symbol, the
1605 instruction is modified to contain the offset of the appropriate
1606 entry in the global offset table. If the symbol is a section
1607 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
1608 addends are combined to form the real addend against the section
1609 symbol; the GOT16 is modified to contain the offset of an entry in
1610 the global offset table, and the LO16 is modified to offset it
1611 appropriately. Thus an offset larger than 16 bits requires a
1612 modified value in the global offset table.
1614 This implementation suffices for the assembler, but the linker does
1615 not yet know how to create global offset tables. */
1617 bfd_reloc_status_type
1618 mips_elf64_got16_reloc (abfd
,
1626 arelent
*reloc_entry
;
1629 asection
*input_section
;
1631 char **error_message
;
1633 /* If we're relocating, and this an external symbol, we don't want
1634 to change anything. */
1635 if (output_bfd
!= (bfd
*) NULL
1636 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1637 && reloc_entry
->addend
== 0)
1639 reloc_entry
->address
+= input_section
->output_offset
;
1640 return bfd_reloc_ok
;
1643 /* If we're relocating, and this is a local symbol, we can handle it
1645 if (output_bfd
!= (bfd
*) NULL
1646 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1647 return mips_elf64_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1648 input_section
, output_bfd
, error_message
);
1653 /* Set the GP value for OUTPUT_BFD. Returns false if this is a
1654 dangerous relocation. */
1657 mips_elf64_assign_gp (output_bfd
, pgp
)
1665 /* If we've already figured out what GP will be, just return it. */
1666 *pgp
= _bfd_get_gp_value (output_bfd
);
1670 count
= bfd_get_symcount (output_bfd
);
1671 sym
= bfd_get_outsymbols (output_bfd
);
1673 /* The linker script will have created a symbol named `_gp' with the
1674 appropriate value. */
1675 if (sym
== (asymbol
**) NULL
)
1679 for (i
= 0; i
< count
; i
++, sym
++)
1681 register CONST
char *name
;
1683 name
= bfd_asymbol_name (*sym
);
1684 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1686 *pgp
= bfd_asymbol_value (*sym
);
1687 _bfd_set_gp_value (output_bfd
, *pgp
);
1695 /* Only get the error once. */
1697 _bfd_set_gp_value (output_bfd
, *pgp
);
1704 /* We have to figure out the gp value, so that we can adjust the
1705 symbol value correctly. We look up the symbol _gp in the output
1706 BFD. If we can't find it, we're stuck. We cache it in the ELF
1707 target data. We don't need to adjust the symbol value for an
1708 external symbol if we are producing relocateable output. */
1710 static bfd_reloc_status_type
1711 mips_elf64_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1714 boolean relocateable
;
1715 char **error_message
;
1718 if (bfd_is_und_section (symbol
->section
)
1722 return bfd_reloc_undefined
;
1725 *pgp
= _bfd_get_gp_value (output_bfd
);
1728 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1732 /* Make up a value. */
1733 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1734 _bfd_set_gp_value (output_bfd
, *pgp
);
1736 else if (!mips_elf64_assign_gp (output_bfd
, pgp
))
1739 (char *) _("GP relative relocation when _gp not defined");
1740 return bfd_reloc_dangerous
;
1744 return bfd_reloc_ok
;
1747 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1748 become the offset from the gp register. */
1750 bfd_reloc_status_type
1751 mips_elf64_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1752 output_bfd
, error_message
)
1754 arelent
*reloc_entry
;
1757 asection
*input_section
;
1759 char **error_message
;
1761 boolean relocateable
;
1762 bfd_reloc_status_type ret
;
1765 /* If we're relocating, and this is an external symbol with no
1766 addend, we don't want to change anything. We will only have an
1767 addend if this is a newly created reloc, not read from an ELF
1769 if (output_bfd
!= (bfd
*) NULL
1770 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1771 && reloc_entry
->addend
== 0)
1773 reloc_entry
->address
+= input_section
->output_offset
;
1774 return bfd_reloc_ok
;
1777 if (output_bfd
!= (bfd
*) NULL
)
1778 relocateable
= true;
1781 relocateable
= false;
1782 output_bfd
= symbol
->section
->output_section
->owner
;
1785 ret
= mips_elf64_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1787 if (ret
!= bfd_reloc_ok
)
1790 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1791 relocateable
, data
, gp
);
1794 static bfd_reloc_status_type
1795 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1799 arelent
*reloc_entry
;
1800 asection
*input_section
;
1801 boolean relocateable
;
1809 if (bfd_is_com_section (symbol
->section
))
1812 relocation
= symbol
->value
;
1814 relocation
+= symbol
->section
->output_section
->vma
;
1815 relocation
+= symbol
->section
->output_offset
;
1817 if (reloc_entry
->address
> input_section
->_cooked_size
)
1818 return bfd_reloc_outofrange
;
1820 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1822 /* Set val to the offset into the section or symbol. */
1823 if (reloc_entry
->howto
->src_mask
== 0)
1825 /* This case occurs with the 64-bit MIPS ELF ABI. */
1826 val
= reloc_entry
->addend
;
1830 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1835 /* Adjust val for the final section location and GP value. If we
1836 are producing relocateable output, we don't want to do this for
1837 an external symbol. */
1839 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1840 val
+= relocation
- gp
;
1842 insn
= (insn
& ~0xffff) | (val
& 0xffff);
1843 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1846 reloc_entry
->address
+= input_section
->output_offset
;
1848 else if ((long) val
>= 0x8000 || (long) val
< -0x8000)
1849 return bfd_reloc_overflow
;
1851 return bfd_reloc_ok
;
1854 /* Do a R_MIPS_GPREL16 RELA relocation. */
1856 bfd_reloc_status_type
1857 mips_elf64_gprel16_reloca (abfd
, reloc_entry
, symbol
, data
, input_section
,
1858 output_bfd
, error_message
)
1860 arelent
*reloc_entry
;
1862 PTR data ATTRIBUTE_UNUSED
;
1863 asection
*input_section
;
1865 char **error_message
;
1867 boolean relocateable
;
1870 /* This works only for NewABI. */
1871 BFD_ASSERT (reloc_entry
->howto
->src_mask
== 0);
1873 /* If we're relocating, and this is an external symbol with no
1874 addend, we don't want to change anything. We will only have an
1875 addend if this is a newly created reloc, not read from an ELF
1877 if (output_bfd
!= (bfd
*) NULL
1878 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1879 && reloc_entry
->addend
== 0)
1881 reloc_entry
->address
+= input_section
->output_offset
;
1882 return bfd_reloc_ok
;
1885 if (output_bfd
!= (bfd
*) NULL
)
1886 relocateable
= true;
1889 relocateable
= false;
1890 output_bfd
= symbol
->section
->output_section
->owner
;
1893 if (prev_reloc_address
!= reloc_entry
->address
)
1894 prev_reloc_address
= reloc_entry
->address
;
1897 mips_elf64_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1899 prev_reloc_addend
= reloc_entry
->addend
+ reloc_entry
->address
- gp
;
1900 if (symbol
->flags
& BSF_LOCAL
)
1901 prev_reloc_addend
+= _bfd_get_gp_value (abfd
);
1902 /*fprintf(stderr, "Addend: %lx, Next Addend: %lx\n", reloc_entry->addend, prev_reloc_addend);*/
1905 return bfd_reloc_ok
;
1908 /* Do a R_MIPS_LITERAL relocation. */
1910 bfd_reloc_status_type
1911 mips_elf64_literal_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1912 output_bfd
, error_message
)
1914 arelent
*reloc_entry
;
1917 asection
*input_section
;
1919 char **error_message
;
1921 /* If we're relocating, and this is an external symbol, we don't
1922 want to change anything. */
1923 if (output_bfd
!= (bfd
*) NULL
1924 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1925 && (! reloc_entry
->howto
->partial_inplace
1926 || reloc_entry
->addend
== 0))
1928 reloc_entry
->address
+= input_section
->output_offset
;
1929 return bfd_reloc_ok
;
1932 /* FIXME: The entries in the .lit8 and .lit4 sections should be merged.
1933 Currently we simply call mips_elf64_gprel16_reloc. */
1934 return mips_elf64_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
,
1935 input_section
, output_bfd
, error_message
);
1938 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1939 from the gp register? XXX */
1941 bfd_reloc_status_type
1942 mips_elf64_gprel32_reloc (abfd
,
1950 arelent
*reloc_entry
;
1953 asection
*input_section
;
1955 char **error_message
;
1957 boolean relocateable
;
1958 bfd_reloc_status_type ret
;
1963 /* If we're relocating, and this is an external symbol with no
1964 addend, we don't want to change anything. We will only have an
1965 addend if this is a newly created reloc, not read from an ELF
1967 if (output_bfd
!= (bfd
*) NULL
1968 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1969 && reloc_entry
->addend
== 0)
1971 *error_message
= (char *)
1972 _("32bits gp relative relocation occurs for an external symbol");
1973 return bfd_reloc_outofrange
;
1976 if (output_bfd
!= (bfd
*) NULL
)
1978 relocateable
= true;
1979 gp
= _bfd_get_gp_value (output_bfd
);
1983 relocateable
= false;
1984 output_bfd
= symbol
->section
->output_section
->owner
;
1986 ret
= mips_elf64_final_gp (output_bfd
, symbol
, relocateable
,
1987 error_message
, &gp
);
1988 if (ret
!= bfd_reloc_ok
)
1992 if (bfd_is_com_section (symbol
->section
))
1995 relocation
= symbol
->value
;
1997 relocation
+= symbol
->section
->output_section
->vma
;
1998 relocation
+= symbol
->section
->output_offset
;
2000 if (reloc_entry
->address
> input_section
->_cooked_size
)
2001 return bfd_reloc_outofrange
;
2003 if (reloc_entry
->howto
->src_mask
== 0)
2005 /* This case arises with the 64-bit MIPS ELF ABI. */
2009 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
2011 /* Set val to the offset into the section or symbol. */
2012 val
+= reloc_entry
->addend
;
2014 /* Adjust val for the final section location and GP value. If we
2015 are producing relocateable output, we don't want to do this for
2016 an external symbol. */
2018 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
2019 val
+= relocation
- gp
;
2021 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
2024 reloc_entry
->address
+= input_section
->output_offset
;
2026 return bfd_reloc_ok
;
2029 /* Do a R_MIPS_SHIFT6 relocation. The MSB of the shift is stored at bit 2,
2030 the rest is at bits 6-10. The bitpos alredy got right by the howto. */
2032 bfd_reloc_status_type
2033 mips_elf64_shift6_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
2034 output_bfd
, error_message
)
2035 bfd
*abfd ATTRIBUTE_UNUSED
;
2036 arelent
*reloc_entry
;
2038 PTR data ATTRIBUTE_UNUSED
;
2039 asection
*input_section
;
2041 char **error_message ATTRIBUTE_UNUSED
;
2043 /* If we're relocating, and this is an external symbol, we don't
2044 want to change anything. */
2045 if (output_bfd
!= (bfd
*) NULL
2046 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
2047 && (! reloc_entry
->howto
->partial_inplace
2048 || reloc_entry
->addend
== 0))
2050 reloc_entry
->address
+= input_section
->output_offset
;
2051 return bfd_reloc_ok
;
2054 reloc_entry
->addend
= (reloc_entry
->addend
& 0x00007c0)
2055 | (reloc_entry
->addend
& 0x00000800) >> 9;
2057 return bfd_reloc_continue
;
2061 mips_elf64_additional_program_headers (abfd
)
2066 /* See if we need a PT_MIPS_OPTIONS segment. */
2067 if (bfd_get_section_by_name (abfd
, ".MIPS.options"))
2073 /* Given a BFD reloc type, return a howto structure. */
2075 static reloc_howto_type
*
2076 mips_elf64_reloc_type_lookup (abfd
, code
)
2077 bfd
*abfd ATTRIBUTE_UNUSED
;
2078 bfd_reloc_code_real_type code
;
2080 /* FIXME: We default to RELA here instead of choosing the right
2081 relocation variant. */
2082 reloc_howto_type
*howto_table
= mips_elf64_howto_table_rela
;
2086 case BFD_RELOC_NONE
:
2087 return &howto_table
[R_MIPS_NONE
];
2089 return &howto_table
[R_MIPS_16
];
2091 return &howto_table
[R_MIPS_32
];
2093 case BFD_RELOC_CTOR
:
2094 /* We need to handle these specially. Select the right
2095 relocation (R_MIPS_32 or R_MIPS_64) based on the
2096 size of addresses on this architecture. */
2097 if (bfd_arch_bits_per_address (abfd
) == 32)
2098 return &howto_table
[R_MIPS_32
];
2100 return &howto_table
[R_MIPS_64
];
2102 case BFD_RELOC_16_PCREL
:
2103 return &howto_table
[R_MIPS_PC16
];
2104 case BFD_RELOC_HI16_S
:
2105 return &howto_table
[R_MIPS_HI16
];
2106 case BFD_RELOC_LO16
:
2107 return &howto_table
[R_MIPS_LO16
];
2108 case BFD_RELOC_GPREL16
:
2109 return &howto_table
[R_MIPS_GPREL16
];
2110 case BFD_RELOC_GPREL32
:
2111 return &howto_table
[R_MIPS_GPREL32
];
2112 case BFD_RELOC_MIPS_JMP
:
2113 return &howto_table
[R_MIPS_26
];
2114 case BFD_RELOC_MIPS_LITERAL
:
2115 return &howto_table
[R_MIPS_LITERAL
];
2116 case BFD_RELOC_MIPS_GOT16
:
2117 return &howto_table
[R_MIPS_GOT16
];
2118 case BFD_RELOC_MIPS_CALL16
:
2119 return &howto_table
[R_MIPS_CALL16
];
2120 case BFD_RELOC_MIPS_SHIFT5
:
2121 return &howto_table
[R_MIPS_SHIFT5
];
2122 case BFD_RELOC_MIPS_SHIFT6
:
2123 return &howto_table
[R_MIPS_SHIFT6
];
2124 case BFD_RELOC_MIPS_GOT_DISP
:
2125 return &howto_table
[R_MIPS_GOT_DISP
];
2126 case BFD_RELOC_MIPS_GOT_PAGE
:
2127 return &howto_table
[R_MIPS_GOT_PAGE
];
2128 case BFD_RELOC_MIPS_GOT_OFST
:
2129 return &howto_table
[R_MIPS_GOT_OFST
];
2130 case BFD_RELOC_MIPS_GOT_HI16
:
2131 return &howto_table
[R_MIPS_GOT_HI16
];
2132 case BFD_RELOC_MIPS_GOT_LO16
:
2133 return &howto_table
[R_MIPS_GOT_LO16
];
2134 case BFD_RELOC_MIPS_SUB
:
2135 return &howto_table
[R_MIPS_SUB
];
2136 case BFD_RELOC_MIPS_INSERT_A
:
2137 return &howto_table
[R_MIPS_INSERT_A
];
2138 case BFD_RELOC_MIPS_INSERT_B
:
2139 return &howto_table
[R_MIPS_INSERT_B
];
2140 case BFD_RELOC_MIPS_DELETE
:
2141 return &howto_table
[R_MIPS_DELETE
];
2142 case BFD_RELOC_MIPS_HIGHEST
:
2143 return &howto_table
[R_MIPS_HIGHEST
];
2144 case BFD_RELOC_MIPS_HIGHER
:
2145 return &howto_table
[R_MIPS_HIGHER
];
2146 case BFD_RELOC_MIPS_CALL_HI16
:
2147 return &howto_table
[R_MIPS_CALL_HI16
];
2148 case BFD_RELOC_MIPS_CALL_LO16
:
2149 return &howto_table
[R_MIPS_CALL_LO16
];
2150 case BFD_RELOC_MIPS_SCN_DISP
:
2151 return &howto_table
[R_MIPS_SCN_DISP
];
2152 case BFD_RELOC_MIPS_REL16
:
2153 return &howto_table
[R_MIPS_REL16
];
2154 /* Use of R_MIPS_ADD_IMMEDIATE and R_MIPS_PJUMP is deprecated. */
2155 case BFD_RELOC_MIPS_RELGOT
:
2156 return &howto_table
[R_MIPS_RELGOT
];
2157 case BFD_RELOC_MIPS_JALR
:
2158 return &howto_table
[R_MIPS_JALR
];
2160 case BFD_RELOC_MIPS16_JMP:
2161 return &elf_mips16_jump_howto;
2162 case BFD_RELOC_MIPS16_GPREL:
2163 return &elf_mips16_gprel_howto;
2164 case BFD_RELOC_VTABLE_INHERIT:
2165 return &elf_mips_gnu_vtinherit_howto;
2166 case BFD_RELOC_VTABLE_ENTRY:
2167 return &elf_mips_gnu_vtentry_howto;
2168 case BFD_RELOC_PCREL_HI16_S:
2169 return &elf_mips_gnu_rel_hi16;
2170 case BFD_RELOC_PCREL_LO16:
2171 return &elf_mips_gnu_rel_lo16;
2172 case BFD_RELOC_16_PCREL_S2:
2173 return &elf_mips_gnu_rel16_s2;
2174 case BFD_RELOC_64_PCREL:
2175 return &elf_mips_gnu_pcrel64;
2176 case BFD_RELOC_32_PCREL:
2177 return &elf_mips_gnu_pcrel32;
2180 bfd_set_error (bfd_error_bad_value
);
2185 /* Prevent relocation handling by bfd for MIPS ELF64. */
2188 mips_elf64_info_to_howto_rel (abfd
, cache_ptr
, dst
)
2189 bfd
*abfd ATTRIBUTE_UNUSED
;
2190 arelent
*cache_ptr ATTRIBUTE_UNUSED
;
2191 Elf64_Internal_Rel
*dst ATTRIBUTE_UNUSED
;
2197 mips_elf64_info_to_howto_rela (abfd
, cache_ptr
, dst
)
2198 bfd
*abfd ATTRIBUTE_UNUSED
;
2199 arelent
*cache_ptr ATTRIBUTE_UNUSED
;
2200 Elf64_Internal_Rela
*dst ATTRIBUTE_UNUSED
;
2205 /* Since each entry in an SHT_REL or SHT_RELA section can represent up
2206 to three relocs, we must tell the user to allocate more space. */
2209 mips_elf64_get_reloc_upper_bound (abfd
, sec
)
2210 bfd
*abfd ATTRIBUTE_UNUSED
;
2213 return (sec
->reloc_count
* 3 + 1) * sizeof (arelent
*);
2216 /* Read the relocations from one reloc section. */
2219 mips_elf64_slurp_one_reloc_table (abfd
, asect
, symbols
, rel_hdr
)
2223 const Elf_Internal_Shdr
*rel_hdr
;
2225 PTR allocated
= NULL
;
2226 bfd_byte
*native_relocs
;
2232 reloc_howto_type
*howto_table
;
2234 allocated
= (PTR
) bfd_malloc (rel_hdr
->sh_size
);
2235 if (allocated
== NULL
)
2238 if (bfd_seek (abfd
, rel_hdr
->sh_offset
, SEEK_SET
) != 0
2239 || (bfd_bread (allocated
, rel_hdr
->sh_size
, abfd
) != rel_hdr
->sh_size
))
2242 native_relocs
= (bfd_byte
*) allocated
;
2244 relents
= asect
->relocation
+ asect
->reloc_count
;
2246 entsize
= rel_hdr
->sh_entsize
;
2247 BFD_ASSERT (entsize
== sizeof (Elf64_Mips_External_Rel
)
2248 || entsize
== sizeof (Elf64_Mips_External_Rela
));
2250 count
= rel_hdr
->sh_size
/ entsize
;
2252 if (entsize
== sizeof (Elf64_Mips_External_Rel
))
2253 howto_table
= mips_elf64_howto_table_rel
;
2255 howto_table
= mips_elf64_howto_table_rela
;
2258 for (i
= 0; i
< count
; i
++, native_relocs
+= entsize
)
2260 Elf64_Mips_Internal_Rela rela
;
2261 boolean used_sym
, used_ssym
;
2264 if (entsize
== sizeof (Elf64_Mips_External_Rela
))
2265 mips_elf64_swap_reloca_in (abfd
,
2266 (Elf64_Mips_External_Rela
*) native_relocs
,
2270 Elf64_Mips_Internal_Rel rel
;
2272 mips_elf64_swap_reloc_in (abfd
,
2273 (Elf64_Mips_External_Rel
*) native_relocs
,
2275 rela
.r_offset
= rel
.r_offset
;
2276 rela
.r_sym
= rel
.r_sym
;
2277 rela
.r_ssym
= rel
.r_ssym
;
2278 rela
.r_type3
= rel
.r_type3
;
2279 rela
.r_type2
= rel
.r_type2
;
2280 rela
.r_type
= rel
.r_type
;
2284 /* Each entry represents up to three actual relocations. */
2288 for (ir
= 0; ir
< 3; ir
++)
2290 enum elf_mips_reloc_type type
;
2297 type
= (enum elf_mips_reloc_type
) rela
.r_type
;
2300 type
= (enum elf_mips_reloc_type
) rela
.r_type2
;
2303 type
= (enum elf_mips_reloc_type
) rela
.r_type3
;
2307 if (type
== R_MIPS_NONE
)
2309 /* There are no more relocations in this entry. If this
2310 is the first entry, we need to generate a dummy
2311 relocation so that the generic linker knows that
2312 there has been a break in the sequence of relocations
2313 applying to a particular address. */
2316 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
2317 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
2318 relent
->address
= rela
.r_offset
;
2320 relent
->address
= rela
.r_offset
- asect
->vma
;
2322 relent
->howto
= &howto_table
[(int) R_MIPS_NONE
];
2328 /* Some types require symbols, whereas some do not. */
2332 case R_MIPS_LITERAL
:
2333 case R_MIPS_INSERT_A
:
2334 case R_MIPS_INSERT_B
:
2336 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
2342 if (rela
.r_sym
== 0)
2343 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
2348 ps
= symbols
+ rela
.r_sym
- 1;
2350 if ((s
->flags
& BSF_SECTION_SYM
) == 0)
2351 relent
->sym_ptr_ptr
= ps
;
2353 relent
->sym_ptr_ptr
= s
->section
->symbol_ptr_ptr
;
2358 else if (! used_ssym
)
2360 switch (rela
.r_ssym
)
2363 relent
->sym_ptr_ptr
=
2364 bfd_abs_section_ptr
->symbol_ptr_ptr
;
2370 /* FIXME: I think these need to be handled using
2371 special howto structures. */
2383 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
2388 /* The address of an ELF reloc is section relative for an
2389 object file, and absolute for an executable file or
2390 shared library. The address of a BFD reloc is always
2391 section relative. */
2392 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
2393 relent
->address
= rela
.r_offset
;
2395 relent
->address
= rela
.r_offset
- asect
->vma
;
2397 relent
->addend
= rela
.r_addend
;
2399 relent
->howto
= &howto_table
[(int) type
];
2405 asect
->reloc_count
+= relent
- relents
;
2407 if (allocated
!= NULL
)
2413 if (allocated
!= NULL
)
2418 /* Read the relocations. On Irix 6, there can be two reloc sections
2419 associated with a single data section. */
2422 mips_elf64_slurp_reloc_table (abfd
, asect
, symbols
, dynamic
)
2429 struct bfd_elf_section_data
* const d
= elf_section_data (asect
);
2433 bfd_set_error (bfd_error_invalid_operation
);
2437 if (asect
->relocation
!= NULL
2438 || (asect
->flags
& SEC_RELOC
) == 0
2439 || asect
->reloc_count
== 0)
2442 /* Allocate space for 3 arelent structures for each Rel structure. */
2443 amt
= asect
->reloc_count
;
2444 amt
*= 3 * sizeof (arelent
);
2445 asect
->relocation
= (arelent
*) bfd_alloc (abfd
, amt
);
2446 if (asect
->relocation
== NULL
)
2449 /* The slurp_one_reloc_table routine increments reloc_count. */
2450 asect
->reloc_count
= 0;
2452 if (! mips_elf64_slurp_one_reloc_table (abfd
, asect
, symbols
, &d
->rel_hdr
))
2454 if (d
->rel_hdr2
!= NULL
)
2456 if (! mips_elf64_slurp_one_reloc_table (abfd
, asect
, symbols
,
2464 /* Write out the relocations. */
2467 mips_elf64_write_relocs (abfd
, sec
, data
)
2472 boolean
*failedp
= (boolean
*) data
;
2474 Elf_Internal_Shdr
*rel_hdr
;
2477 /* If we have already failed, don't do anything. */
2481 if ((sec
->flags
& SEC_RELOC
) == 0)
2484 /* The linker backend writes the relocs out itself, and sets the
2485 reloc_count field to zero to inhibit writing them here. Also,
2486 sometimes the SEC_RELOC flag gets set even when there aren't any
2488 if (sec
->reloc_count
== 0)
2491 /* We can combine up to three relocs that refer to the same address
2492 if the latter relocs have no associated symbol. */
2494 for (idx
= 0; idx
< sec
->reloc_count
; idx
++)
2501 addr
= sec
->orelocation
[idx
]->address
;
2502 for (i
= 0; i
< 2; i
++)
2506 if (idx
+ 1 >= sec
->reloc_count
)
2508 r
= sec
->orelocation
[idx
+ 1];
2509 if (r
->address
!= addr
2510 || ! bfd_is_abs_section ((*r
->sym_ptr_ptr
)->section
)
2511 || (*r
->sym_ptr_ptr
)->value
!= 0)
2514 /* We can merge the reloc at IDX + 1 with the reloc at IDX. */
2520 rel_hdr
= &elf_section_data (sec
)->rel_hdr
;
2522 /* Do the actual relocation. */
2524 if (rel_hdr
->sh_entsize
== sizeof(Elf64_Mips_External_Rel
))
2525 mips_elf64_write_rel (abfd
, sec
, rel_hdr
, &count
, data
);
2526 else if (rel_hdr
->sh_entsize
== sizeof(Elf64_Mips_External_Rela
))
2527 mips_elf64_write_rela (abfd
, sec
, rel_hdr
, &count
, data
);
2533 mips_elf64_write_rel (abfd
, sec
, rel_hdr
, count
, data
)
2536 Elf_Internal_Shdr
*rel_hdr
;
2540 boolean
*failedp
= (boolean
*) data
;
2541 Elf64_Mips_External_Rel
*ext_rel
;
2543 asymbol
*last_sym
= 0;
2544 int last_sym_idx
= 0;
2546 rel_hdr
->sh_size
= (bfd_vma
)(rel_hdr
->sh_entsize
* *count
);
2547 rel_hdr
->contents
= (PTR
) bfd_alloc (abfd
, rel_hdr
->sh_size
);
2548 if (rel_hdr
->contents
== NULL
)
2554 ext_rel
= (Elf64_Mips_External_Rel
*) rel_hdr
->contents
;
2555 for (idx
= 0; idx
< sec
->reloc_count
; idx
++, ext_rel
++)
2558 Elf64_Mips_Internal_Rel int_rel
;
2563 ptr
= sec
->orelocation
[idx
];
2565 /* The address of an ELF reloc is section relative for an object
2566 file, and absolute for an executable file or shared library.
2567 The address of a BFD reloc is always section relative. */
2568 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
2569 int_rel
.r_offset
= ptr
->address
;
2571 int_rel
.r_offset
= ptr
->address
+ sec
->vma
;
2573 sym
= *ptr
->sym_ptr_ptr
;
2574 if (sym
== last_sym
)
2579 n
= _bfd_elf_symbol_from_bfd_symbol (abfd
, &sym
);
2589 int_rel
.r_ssym
= RSS_UNDEF
;
2591 if ((*ptr
->sym_ptr_ptr
)->the_bfd
->xvec
!= abfd
->xvec
2592 && ! _bfd_elf_validate_reloc (abfd
, ptr
))
2598 int_rel
.r_type
= ptr
->howto
->type
;
2599 int_rel
.r_type2
= (int) R_MIPS_NONE
;
2600 int_rel
.r_type3
= (int) R_MIPS_NONE
;
2602 for (i
= 0; i
< 2; i
++)
2606 if (idx
+ 1 >= sec
->reloc_count
)
2608 r
= sec
->orelocation
[idx
+ 1];
2609 if (r
->address
!= ptr
->address
2610 || ! bfd_is_abs_section ((*r
->sym_ptr_ptr
)->section
)
2611 || (*r
->sym_ptr_ptr
)->value
!= 0)
2614 /* We can merge the reloc at IDX + 1 with the reloc at IDX. */
2617 int_rel
.r_type2
= r
->howto
->type
;
2619 int_rel
.r_type3
= r
->howto
->type
;
2624 mips_elf64_swap_reloc_out (abfd
, &int_rel
, ext_rel
);
2627 BFD_ASSERT (ext_rel
- (Elf64_Mips_External_Rel
*) rel_hdr
->contents
2632 mips_elf64_write_rela (abfd
, sec
, rela_hdr
, count
, data
)
2635 Elf_Internal_Shdr
*rela_hdr
;
2639 boolean
*failedp
= (boolean
*) data
;
2640 Elf64_Mips_External_Rela
*ext_rela
;
2642 asymbol
*last_sym
= 0;
2643 int last_sym_idx
= 0;
2645 rela_hdr
->sh_size
= (bfd_vma
)(rela_hdr
->sh_entsize
* *count
);
2646 rela_hdr
->contents
= (PTR
) bfd_alloc (abfd
, rela_hdr
->sh_size
);
2647 if (rela_hdr
->contents
== NULL
)
2653 ext_rela
= (Elf64_Mips_External_Rela
*) rela_hdr
->contents
;
2654 for (idx
= 0; idx
< sec
->reloc_count
; idx
++, ext_rela
++)
2657 Elf64_Mips_Internal_Rela int_rela
;
2662 ptr
= sec
->orelocation
[idx
];
2664 /* The address of an ELF reloc is section relative for an object
2665 file, and absolute for an executable file or shared library.
2666 The address of a BFD reloc is always section relative. */
2667 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
2668 int_rela
.r_offset
= ptr
->address
;
2670 int_rela
.r_offset
= ptr
->address
+ sec
->vma
;
2672 sym
= *ptr
->sym_ptr_ptr
;
2673 if (sym
== last_sym
)
2678 n
= _bfd_elf_symbol_from_bfd_symbol (abfd
, &sym
);
2688 int_rela
.r_addend
= ptr
->addend
;
2689 int_rela
.r_ssym
= RSS_UNDEF
;
2691 if ((*ptr
->sym_ptr_ptr
)->the_bfd
->xvec
!= abfd
->xvec
2692 && ! _bfd_elf_validate_reloc (abfd
, ptr
))
2698 int_rela
.r_type
= ptr
->howto
->type
;
2699 int_rela
.r_type2
= (int) R_MIPS_NONE
;
2700 int_rela
.r_type3
= (int) R_MIPS_NONE
;
2702 for (i
= 0; i
< 2; i
++)
2706 if (idx
+ 1 >= sec
->reloc_count
)
2708 r
= sec
->orelocation
[idx
+ 1];
2709 if (r
->address
!= ptr
->address
2710 || ! bfd_is_abs_section ((*r
->sym_ptr_ptr
)->section
)
2711 || (*r
->sym_ptr_ptr
)->value
!= 0)
2714 /* We can merge the reloc at IDX + 1 with the reloc at IDX. */
2717 int_rela
.r_type2
= r
->howto
->type
;
2719 int_rela
.r_type3
= r
->howto
->type
;
2724 mips_elf64_swap_reloca_out (abfd
, &int_rela
, ext_rela
);
2727 BFD_ASSERT (ext_rela
- (Elf64_Mips_External_Rela
*) rela_hdr
->contents
2731 /* This structure is used to hold .got information when linking. It
2732 is stored in the tdata field of the bfd_elf_section_data structure. */
2734 struct mips_elf64_got_info
2736 /* The global symbol in the GOT with the lowest index in the dynamic
2738 struct elf_link_hash_entry
*global_gotsym
;
2739 /* The number of global .got entries. */
2740 unsigned int global_gotno
;
2741 /* The number of local .got entries. */
2742 unsigned int local_gotno
;
2743 /* The number of local .got entries we have used. */
2744 unsigned int assigned_gotno
;
2747 /* The MIPS ELF64 linker needs additional information for each symbol in
2748 the global hash table. */
2750 struct mips_elf64_link_hash_entry
2752 struct elf_link_hash_entry root
;
2754 /* External symbol information. */
2757 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
2759 unsigned int possibly_dynamic_relocs
;
2761 /* If the R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 reloc is against
2762 a readonly section. */
2763 boolean readonly_reloc
;
2765 /* The index of the first dynamic relocation (in the .rel.dyn
2766 section) against this symbol. */
2767 unsigned int min_dyn_reloc_index
;
2769 /* We must not create a stub for a symbol that has relocations
2770 related to taking the function's address, i.e. any but
2771 R_MIPS_CALL*16 ones -- see "MIPS ABI Supplement, 3rd Edition",
2775 /* If there is a stub that 32 bit functions should use to call this
2776 16 bit function, this points to the section containing the stub. */
2779 /* Whether we need the fn_stub; this is set if this symbol appears
2780 in any relocs other than a 16 bit call. */
2781 boolean need_fn_stub
;
2783 /* If there is a stub that 16 bit functions should use to call this
2784 32 bit function, this points to the section containing the stub. */
2785 asection
*call_stub
;
2787 /* This is like the call_stub field, but it is used if the function
2788 being called returns a floating point value. */
2789 asection
*call_fp_stub
;
2792 /* The mips16 compiler uses a couple of special sections to handle
2793 floating point arguments.
2795 Section names that look like .mips16.fn.FNNAME contain stubs that
2796 copy floating point arguments from the fp regs to the gp regs and
2797 then jump to FNNAME. If any 32 bit function calls FNNAME, the
2798 call should be redirected to the stub instead. If no 32 bit
2799 function calls FNNAME, the stub should be discarded. We need to
2800 consider any reference to the function, not just a call, because
2801 if the address of the function is taken we will need the stub,
2802 since the address might be passed to a 32 bit function.
2804 Section names that look like .mips16.call.FNNAME contain stubs
2805 that copy floating point arguments from the gp regs to the fp
2806 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
2807 then any 16 bit function that calls FNNAME should be redirected
2808 to the stub instead. If FNNAME is not a 32 bit function, the
2809 stub should be discarded.
2811 .mips16.call.fp.FNNAME sections are similar, but contain stubs
2812 which call FNNAME and then copy the return value from the fp regs
2813 to the gp regs. These stubs store the return value in $18 while
2814 calling FNNAME; any function which might call one of these stubs
2815 must arrange to save $18 around the call. (This case is not
2816 needed for 32 bit functions that call 16 bit functions, because
2817 16 bit functions always return floating point values in both
2820 Note that in all cases FNNAME might be defined statically.
2821 Therefore, FNNAME is not used literally. Instead, the relocation
2822 information will indicate which symbol the section is for.
2824 We record any stubs that we find in the symbol table. */
2826 #define FN_STUB ".mips16.fn."
2827 #define CALL_STUB ".mips16.call."
2828 #define CALL_FP_STUB ".mips16.call.fp."
2830 /* MIPS ELF64 linker hash table. */
2832 struct mips_elf64_link_hash_table
2834 struct elf_link_hash_table root
;
2835 /* This is set if we see any mips16 stub sections. */
2836 boolean mips16_stubs_seen
;
2839 /* Look up an entry in a MIPS ELF64 linker hash table. */
2841 #define mips_elf64_link_hash_lookup(table, string, create, copy, follow) \
2842 ((struct mips_elf64_link_hash_entry *) \
2843 elf_link_hash_lookup (&(table)->root, (string), (create), \
2846 /* Traverse a MIPS ELF linker hash table. */
2848 #define mips_elf64_link_hash_traverse(table, func, info) \
2849 (elf_link_hash_traverse \
2851 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
2854 /* Get the MIPS ELF64 linker hash table from a link_info structure. */
2856 #define mips_elf64_hash_table(p) \
2857 ((struct mips_elf64_link_hash_table *) ((p)->hash))
2859 /* Create an entry in a MIPS ELF64 linker hash table. */
2861 static struct bfd_hash_entry
*
2862 mips_elf64_link_hash_newfunc (entry
, table
, string
)
2863 struct bfd_hash_entry
*entry
;
2864 struct bfd_hash_table
*table
;
2867 struct mips_elf64_link_hash_entry
*ret
=
2868 (struct mips_elf64_link_hash_entry
*) entry
;
2870 /* Allocate the structure if it has not already been allocated by a
2872 if (ret
== (struct mips_elf64_link_hash_entry
*) NULL
)
2873 ret
= ((struct mips_elf64_link_hash_entry
*)
2874 bfd_hash_allocate (table
,
2875 sizeof (struct mips_elf64_link_hash_entry
)));
2876 if (ret
== (struct mips_elf64_link_hash_entry
*) NULL
)
2877 return (struct bfd_hash_entry
*) ret
;
2879 /* Call the allocation method of the superclass. */
2880 ret
= ((struct mips_elf64_link_hash_entry
*)
2881 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2883 if (ret
!= (struct mips_elf64_link_hash_entry
*) NULL
)
2885 /* Set local fields. */
2886 memset (&ret
->esym
, 0, sizeof (EXTR
));
2887 /* We use -2 as a marker to indicate that the information has
2888 not been set. -1 means there is no associated ifd. */
2890 ret
->possibly_dynamic_relocs
= 0;
2891 ret
->readonly_reloc
= false;
2892 ret
->min_dyn_reloc_index
= 0;
2893 ret
->no_fn_stub
= false;
2894 ret
->fn_stub
= NULL
;
2895 ret
->need_fn_stub
= false;
2896 ret
->call_stub
= NULL
;
2897 ret
->call_fp_stub
= NULL
;
2900 return (struct bfd_hash_entry
*) ret
;
2903 /* Create a MIPS ELF64 linker hash table. */
2905 struct bfd_link_hash_table
*
2906 mips_elf64_link_hash_table_create (abfd
)
2909 struct mips_elf64_link_hash_table
*ret
;
2911 ret
= ((struct mips_elf64_link_hash_table
*)
2912 bfd_alloc (abfd
, sizeof (struct mips_elf64_link_hash_table
)));
2913 if (ret
== (struct mips_elf64_link_hash_table
*) NULL
)
2916 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
2917 mips_elf64_link_hash_newfunc
))
2919 bfd_release (abfd
, ret
);
2923 ret
->mips16_stubs_seen
= false;
2925 return &ret
->root
.root
;
2928 /* Returns the offset for the entry at the INDEXth position
2932 mips_elf64_got_offset_from_index (dynobj
, output_bfd
, index
)
2940 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2941 gp
= _bfd_get_gp_value (output_bfd
);
2942 return (sgot
->output_section
->vma
+ sgot
->output_offset
+ index
-
2946 /* Returns the GOT information associated with the link indicated by
2947 INFO. If SGOTP is non-NULL, it is filled in with the GOT
2950 static struct mips_elf64_got_info
*
2951 _mips_elf64_got_info (abfd
, sgotp
)
2956 struct mips_elf64_got_info
*g
;
2958 sgot
= bfd_get_section_by_name (abfd
, ".got");
2959 BFD_ASSERT (sgot
!= NULL
);
2960 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
2961 g
= (struct mips_elf64_got_info
*) elf_section_data (sgot
)->tdata
;
2962 BFD_ASSERT (g
!= NULL
);
2969 /* Sign-extend VALUE, which has the indicated number of BITS. */
2972 mips_elf64_sign_extend (value
, bits
)
2976 if (value
& ((bfd_vma
)1 << (bits
- 1)))
2977 /* VALUE is negative. */
2978 value
|= ((bfd_vma
) - 1) << bits
;
2983 /* Return non-zero if the indicated VALUE has overflowed the maximum
2984 range expressable by a signed number with the indicated number of
2988 mips_elf64_overflow_p (value
, bits
)
2992 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
2994 if (svalue
> (1 << (bits
- 1)) - 1)
2995 /* The value is too big. */
2997 else if (svalue
< -(1 << (bits
- 1)))
2998 /* The value is too small. */
3005 /* Returns the GOT index for the global symbol indicated by H. */
3008 mips_elf64_global_got_index (abfd
, h
)
3010 struct elf_link_hash_entry
*h
;
3014 struct mips_elf64_got_info
*g
;
3016 g
= _mips_elf64_got_info (abfd
, &sgot
);
3018 /* Once we determine the global GOT entry with the lowest dynamic
3019 symbol table index, we must put all dynamic symbols with greater
3020 indices into the GOT. That makes it easy to calculate the GOT
3022 BFD_ASSERT (h
->dynindx
>= g
->global_gotsym
->dynindx
);
3023 index
= ((h
->dynindx
- g
->global_gotsym
->dynindx
+ g
->local_gotno
)
3024 * (get_elf_backend_data (abfd
)->s
->arch_size
/ 8));
3025 BFD_ASSERT (index
< sgot
->_raw_size
);
3030 struct mips_elf64_hash_sort_data
3032 /* The symbol in the global GOT with the lowest dynamic symbol table
3034 struct elf_link_hash_entry
*low
;
3035 /* The least dynamic symbol table index corresponding to a symbol
3036 with a GOT entry. */
3037 long min_got_dynindx
;
3038 /* The greatest dynamic symbol table index not corresponding to a
3039 symbol without a GOT entry. */
3040 long max_non_got_dynindx
;
3043 /* If H needs a GOT entry, assign it the highest available dynamic
3044 index. Otherwise, assign it the lowest available dynamic
3048 mips_elf64_sort_hash_table_f (h
, data
)
3049 struct mips_elf64_link_hash_entry
*h
;
3052 struct mips_elf64_hash_sort_data
*hsd
3053 = (struct mips_elf64_hash_sort_data
*) data
;
3055 /* Symbols without dynamic symbol table entries aren't interesting
3057 if (h
->root
.dynindx
== -1)
3060 if (h
->root
.got
.offset
!= 1)
3061 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
3064 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
3065 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3071 /* Sort the dynamic symbol table so that symbols that need GOT entries
3072 appear towards the end. This reduces the amount of GOT space
3073 required. MAX_LOCAL is used to set the number of local symbols
3074 known to be in the dynamic symbol table. During
3075 mips_elf64_size_dynamic_sections, this value is 1. Afterward, the
3076 section symbols are added and the count is higher. */
3079 mips_elf64_sort_hash_table (info
, max_local
)
3080 struct bfd_link_info
*info
;
3081 unsigned long max_local
;
3083 struct mips_elf64_hash_sort_data hsd
;
3084 struct mips_elf64_got_info
*g
;
3087 dynobj
= elf_hash_table (info
)->dynobj
;
3090 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
;
3091 hsd
.max_non_got_dynindx
= max_local
;
3092 mips_elf64_link_hash_traverse (((struct mips_elf64_link_hash_table
*)
3093 elf_hash_table (info
)),
3094 mips_elf64_sort_hash_table_f
,
3097 /* There shoud have been enough room in the symbol table to
3098 accomodate both the GOT and non-GOT symbols. */
3099 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
3101 /* Now we know which dynamic symbol has the lowest dynamic symbol
3102 table index in the GOT. */
3103 g
= _mips_elf64_got_info (dynobj
, NULL
);
3104 g
->global_gotsym
= hsd
.low
;
3110 /* Swap in an MSYM entry. */
3113 mips_elf64_swap_msym_in (abfd
, ex
, in
)
3115 const Elf32_External_Msym
*ex
;
3116 Elf32_Internal_Msym
*in
;
3118 in
->ms_hash_value
= H_GET_32 (abfd
, ex
->ms_hash_value
);
3119 in
->ms_info
= H_GET_32 (abfd
, ex
->ms_info
);
3122 /* Swap out an MSYM entry. */
3125 mips_elf64_swap_msym_out (abfd
, in
, ex
)
3127 const Elf32_Internal_Msym
*in
;
3128 Elf32_External_Msym
*ex
;
3130 H_PUT_32 (abfd
, in
->ms_hash_value
, ex
->ms_hash_value
);
3131 H_PUT_32 (abfd
, in
->ms_info
, ex
->ms_info
);
3134 /* Create a local GOT entry for VALUE. Return the index of the entry,
3135 or -1 if it could not be created. */
3138 mips_elf64_create_local_got_entry (abfd
, g
, sgot
, value
)
3140 struct mips_elf64_got_info
*g
;
3144 CONST bfd_vma got_size
= get_elf_backend_data (abfd
)->s
->arch_size
/ 8;
3146 if (g
->assigned_gotno
>= g
->local_gotno
)
3148 /* We didn't allocate enough space in the GOT. */
3149 (*_bfd_error_handler
)
3150 (_("not enough GOT space for local GOT entries"));
3151 bfd_set_error (bfd_error_bad_value
);
3152 return (bfd_vma
) -1;
3155 bfd_put_64 (abfd
, value
, (sgot
->contents
+ got_size
* g
->assigned_gotno
));
3156 return got_size
* g
->assigned_gotno
++;
3159 /* Returns the GOT offset at which the indicated address can be found.
3160 If there is not yet a GOT entry for this value, create one. Returns
3161 -1 if no satisfactory GOT offset can be found. */
3164 mips_elf64_local_got_index (abfd
, info
, value
)
3166 struct bfd_link_info
*info
;
3169 CONST bfd_vma got_size
= get_elf_backend_data (abfd
)->s
->arch_size
/ 8;
3171 struct mips_elf64_got_info
*g
;
3174 g
= _mips_elf64_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
3176 /* Look to see if we already have an appropriate entry. */
3177 for (entry
= (sgot
->contents
+ got_size
* MIPS_RESERVED_GOTNO
);
3178 entry
!= sgot
->contents
+ got_size
* g
->assigned_gotno
;
3181 bfd_vma address
= bfd_get_64 (abfd
, entry
);
3182 if (address
== value
)
3183 return entry
- sgot
->contents
;
3186 return mips_elf64_create_local_got_entry (abfd
, g
, sgot
, value
);
3189 /* Find a GOT entry that is within 32KB of the VALUE. These entries
3190 are supposed to be placed at small offsets in the GOT, i.e.,
3191 within 32KB of GP. Return the index into the GOT for this page,
3192 and store the offset from this entry to the desired address in
3193 OFFSETP, if it is non-NULL. */
3196 mips_elf64_got_page (abfd
, info
, value
, offsetp
)
3198 struct bfd_link_info
*info
;
3202 CONST bfd_vma got_size
= get_elf_backend_data (abfd
)->s
->arch_size
/ 8;
3204 struct mips_elf64_got_info
*g
;
3206 bfd_byte
*last_entry
;
3210 g
= _mips_elf64_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
3212 /* Look to see if we aleady have an appropriate entry. */
3213 last_entry
= sgot
->contents
+ got_size
* g
->assigned_gotno
;
3214 for (entry
= (sgot
->contents
+ got_size
* MIPS_RESERVED_GOTNO
);
3215 entry
!= last_entry
;
3218 address
= bfd_get_64 (abfd
, entry
);
3220 if (!mips_elf64_overflow_p (value
- address
, 16))
3222 /* This entry will serve as the page pointer. We can add a
3223 16-bit number to it to get the actual address. */
3224 index
= entry
- sgot
->contents
;
3229 /* If we didn't have an appropriate entry, we create one now. */
3230 if (entry
== last_entry
)
3231 index
= mips_elf64_create_local_got_entry (abfd
, g
, sgot
, value
);
3235 address
= bfd_get_64 (abfd
, entry
);
3236 *offsetp
= value
- address
;
3242 /* Find a GOT entry whose higher-order 16 bits are the same as those
3243 for value. Return the index into the GOT for this entry. */
3246 mips_elf64_got16_entry (abfd
, info
, value
, external
)
3248 struct bfd_link_info
*info
;
3252 CONST bfd_vma got_size
= get_elf_backend_data (abfd
)->s
->arch_size
/ 8;
3254 struct mips_elf64_got_info
*g
;
3256 bfd_byte
*last_entry
;
3262 /* Although the ABI says that it is "the high-order 16 bits" that we
3263 want, it is really the %high value. The complete value is
3264 calculated with a `addiu' of a LO16 relocation, just as with a
3266 value
= mips_elf64_high (value
) << 16;
3269 g
= _mips_elf64_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
3271 /* Look to see if we already have an appropriate entry. */
3272 last_entry
= sgot
->contents
+ got_size
* g
->assigned_gotno
;
3273 for (entry
= (sgot
->contents
+ got_size
* MIPS_RESERVED_GOTNO
);
3274 entry
!= last_entry
;
3277 address
= bfd_get_64 (abfd
, entry
);
3278 if (address
== value
)
3280 /* This entry has the right high-order 16 bits, and the low-order
3281 16 bits are set to zero. */
3282 index
= entry
- sgot
->contents
;
3287 /* If we didn't have an appropriate entry, we create one now. */
3288 if (entry
== last_entry
)
3289 index
= mips_elf64_create_local_got_entry (abfd
, g
, sgot
, value
);
3294 /* Return whether a relocation is against a local symbol. */
3297 mips_elf64_local_relocation_p (input_bfd
, relocation
, local_sections
,
3300 const Elf_Internal_Rela
*relocation
;
3301 asection
**local_sections
;
3302 boolean check_forced
;
3304 unsigned long r_symndx
;
3305 Elf_Internal_Shdr
*symtab_hdr
;
3306 struct mips_elf64_link_hash_entry
* h
;
3309 r_symndx
= ELF64_R_SYM (relocation
->r_info
);
3310 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3311 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
3313 if (r_symndx
< extsymoff
)
3315 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
3320 /* Look up the hash table to check whether the symbol
3321 was forced local. */
3322 h
= (struct mips_elf64_link_hash_entry
*)
3323 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
3324 /* Find the real hash-table entry for this symbol. */
3325 while (h
->root
.root
.type
== bfd_link_hash_indirect
3326 || h
->root
.root
.type
== bfd_link_hash_warning
)
3327 h
= (struct mips_elf64_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3328 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
3335 /* Returns the first relocation of type r_type found, beginning with
3336 RELOCATION. RELEND is one-past-the-end of the relocation table. */
3338 static const Elf_Internal_Rela
*
3339 mips_elf64_next_relocation (r_type
, relocation
, relend
)
3340 unsigned int r_type
;
3341 const Elf_Internal_Rela
*relocation
;
3342 const Elf_Internal_Rela
*relend
;
3344 /* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be
3345 immediately following. However, for the IRIX6 ABI, the next
3346 relocation may be a composed relocation consisting of several
3347 relocations for the same address. In that case, the R_MIPS_LO16
3348 relocation may occur as one of these. We permit a similar
3349 extension in general, as that is useful for GCC. */
3350 while (relocation
< relend
)
3352 if (ELF64_MIPS_R_TYPE (relocation
->r_info
) == r_type
)
3358 /* We didn't find it. */
3359 bfd_set_error (bfd_error_bad_value
);
3363 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
3364 is the original relocation, which is now being transformed into a
3365 dynamic relocation. The ADDENDP is adjusted if necessary; the
3366 caller should store the result in place of the original addend. */
3369 mips_elf64_create_dynamic_relocation (output_bfd
, info
, rel
, h
, sec
,
3370 symbol
, addendp
, input_section
)
3372 struct bfd_link_info
*info
;
3373 const Elf_Internal_Rela
*rel
;
3374 struct mips_elf64_link_hash_entry
*h
;
3378 asection
*input_section
;
3380 Elf_Internal_Rel outrel
[3];
3386 r_type
= ELF64_MIPS_R_TYPE (rel
->r_info
);
3387 dynobj
= elf_hash_table (info
)->dynobj
;
3388 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
3389 BFD_ASSERT (sreloc
!= NULL
);
3390 BFD_ASSERT (sreloc
->contents
!= NULL
);
3391 BFD_ASSERT ((sreloc
->reloc_count
3392 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
)
3393 < sreloc
->_raw_size
);
3396 outrel
[0].r_offset
= _bfd_elf_section_offset (output_bfd
, info
,
3399 /* FIXME: For -2 runtime relocation needs to be skipped, but
3400 properly resolved statically and installed. */
3401 BFD_ASSERT (outrel
[0].r_offset
!= (bfd_vma
) -2);
3403 /* We begin by assuming that the offset for the dynamic relocation
3404 is the same as for the original relocation. We'll adjust this
3405 later to reflect the correct output offsets. */
3406 if (elf_section_data (input_section
)->sec_info_type
!= ELF_INFO_TYPE_STABS
)
3408 outrel
[1].r_offset
= rel
[1].r_offset
;
3409 outrel
[2].r_offset
= rel
[2].r_offset
;
3413 /* Except that in a stab section things are more complex.
3414 Because we compress stab information, the offset given in the
3415 relocation may not be the one we want; we must let the stabs
3416 machinery tell us the offset. */
3417 outrel
[1].r_offset
= outrel
[0].r_offset
;
3418 outrel
[2].r_offset
= outrel
[0].r_offset
;
3419 /* If we didn't need the relocation at all, this value will be
3421 if (outrel
[0].r_offset
== (bfd_vma
) -1)
3425 /* If we've decided to skip this relocation, just output an empty
3426 record. Note that R_MIPS_NONE == 0, so that this call to memset
3427 is a way of setting R_TYPE to R_MIPS_NONE. */
3429 memset (outrel
, 0, sizeof (Elf_Internal_Rel
) * 3);
3433 bfd_vma section_offset
;
3435 /* We must now calculate the dynamic symbol table index to use
3436 in the relocation. */
3438 && (! info
->symbolic
|| (h
->root
.elf_link_hash_flags
3439 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
3441 indx
= h
->root
.dynindx
;
3442 /* h->root.dynindx may be -1 if this symbol was marked to
3449 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
3451 else if (sec
== NULL
|| sec
->owner
== NULL
)
3453 bfd_set_error (bfd_error_bad_value
);
3458 indx
= elf_section_data (sec
->output_section
)->dynindx
;
3463 /* Figure out how far the target of the relocation is from
3464 the beginning of its section. */
3465 section_offset
= symbol
- sec
->output_section
->vma
;
3466 /* The relocation we're building is section-relative.
3467 Therefore, the original addend must be adjusted by the
3469 *addendp
+= section_offset
;
3470 /* Now, the relocation is just against the section. */
3471 symbol
= sec
->output_section
->vma
;
3474 /* If the relocation was previously an absolute relocation and
3475 this symbol will not be referred to by the relocation, we must
3476 adjust it by the value we give it in the dynamic symbol table.
3477 Otherwise leave the job up to the dynamic linker. */
3478 if (!indx
&& r_type
!= R_MIPS_REL32
)
3481 /* The relocation is always an REL32 relocation because we don't
3482 know where the shared library will wind up at load-time. */
3483 outrel
[0].r_info
= ELF64_R_INFO (indx
, R_MIPS_REL32
);
3485 /* Adjust the output offset of the relocation to reference the
3486 correct location in the output file. */
3487 outrel
[0].r_offset
+= (input_section
->output_section
->vma
3488 + input_section
->output_offset
);
3489 outrel
[1].r_offset
+= (input_section
->output_section
->vma
3490 + input_section
->output_offset
);
3491 outrel
[2].r_offset
+= (input_section
->output_section
->vma
3492 + input_section
->output_offset
);
3495 /* Put the relocation back out. */
3496 mips_elf64_be_swap_reloc_out (output_bfd
, outrel
,
3498 + sreloc
->reloc_count
3499 * sizeof (Elf64_Mips_External_Rel
)));
3501 /* Record the index of the first relocation referencing H. This
3502 information is later emitted in the .msym section. */
3504 && (h
->min_dyn_reloc_index
== 0
3505 || sreloc
->reloc_count
< h
->min_dyn_reloc_index
))
3506 h
->min_dyn_reloc_index
= sreloc
->reloc_count
;
3508 /* We've now added another relocation. */
3509 ++sreloc
->reloc_count
;
3511 /* Make sure the output section is writable. The dynamic linker
3512 will be writing to it. */
3513 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
3519 /* Calculate the value produced by the RELOCATION (which comes from
3520 the INPUT_BFD). The ADDEND is the addend to use for this
3521 RELOCATION; RELOCATION->R_ADDEND is ignored.
3523 The result of the relocation calculation is stored in VALUEP.
3524 REQUIRE_JALXP indicates whether or not the opcode used with this
3525 relocation must be JALX.
3527 This function returns bfd_reloc_continue if the caller need take no
3528 further action regarding this relocation, bfd_reloc_notsupported if
3529 something goes dramatically wrong, bfd_reloc_overflow if an
3530 overflow occurs, and bfd_reloc_ok to indicate success. */
3532 static bfd_reloc_status_type
3533 mips_elf64_calculate_relocation (abfd
, input_bfd
, input_section
, info
,
3534 relocation
, addend
, howto
, local_syms
,
3535 local_sections
, valuep
, namep
, require_jalxp
)
3538 asection
*input_section
;
3539 struct bfd_link_info
*info
;
3540 const Elf_Internal_Rela
*relocation
;
3542 reloc_howto_type
*howto
;
3543 Elf_Internal_Sym
*local_syms
;
3544 asection
**local_sections
;
3547 boolean
*require_jalxp
;
3549 /* The eventual value we will return. */
3551 /* The address of the symbol against which the relocation is
3554 /* The final GP value to be used for the relocatable, executable, or
3555 shared object file being produced. */
3556 bfd_vma gp
= (bfd_vma
) - 1;
3557 /* The place (section offset or address) of the storage unit being
3560 /* The value of GP used to create the relocatable object. */
3561 bfd_vma gp0
= (bfd_vma
) - 1;
3562 /* The offset into the global offset table at which the address of
3563 the relocation entry symbol, adjusted by the addend, resides
3564 during execution. */
3565 bfd_vma g
= (bfd_vma
) - 1;
3566 /* The section in which the symbol referenced by the relocation is
3568 asection
*sec
= NULL
;
3569 struct mips_elf64_link_hash_entry
* h
= NULL
;
3570 /* True if the symbol referred to by this relocation is a local
3573 Elf_Internal_Shdr
*symtab_hdr
;
3575 unsigned long r_symndx
;
3577 /* True if overflow occurred during the calculation of the
3578 relocation value. */
3579 boolean overflowed_p
;
3580 /* True if this relocation refers to a MIPS16 function. */
3581 boolean target_is_16_bit_code_p
= false;
3583 /* Parse the relocation. */
3584 r_symndx
= ELF64_R_SYM (relocation
->r_info
);
3585 r_type
= ELF64_MIPS_R_TYPE (relocation
->r_info
);
3586 p
= (input_section
->output_section
->vma
3587 + input_section
->output_offset
3588 + relocation
->r_offset
);
3590 /* Assume that there will be no overflow. */
3591 overflowed_p
= false;
3593 /* Figure out whether or not the symbol is local, and get the offset
3594 used in the array of hash table entries. */
3595 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3596 local_p
= mips_elf64_local_relocation_p (input_bfd
, relocation
,
3597 local_sections
, false);
3598 if (! elf_bad_symtab (input_bfd
))
3599 extsymoff
= symtab_hdr
->sh_info
;
3602 /* The symbol table does not follow the rule that local symbols
3603 must come before globals. */
3607 /* Figure out the value of the symbol. */
3610 Elf_Internal_Sym
*sym
;
3612 sym
= local_syms
+ r_symndx
;
3613 sec
= local_sections
[r_symndx
];
3615 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
3616 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
3617 symbol
+= sym
->st_value
;
3619 /* MIPS16 text labels should be treated as odd. */
3620 if (sym
->st_other
== STO_MIPS16
)
3623 /* Record the name of this symbol, for our caller. */
3624 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
3625 symtab_hdr
->sh_link
,
3628 *namep
= bfd_section_name (input_bfd
, sec
);
3630 target_is_16_bit_code_p
= (sym
->st_other
== STO_MIPS16
);
3634 /* For global symbols we look up the symbol in the hash-table. */
3635 h
= ((struct mips_elf64_link_hash_entry
*)
3636 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
3637 /* Find the real hash-table entry for this symbol. */
3638 while (h
->root
.root
.type
== bfd_link_hash_indirect
3639 || h
->root
.root
.type
== bfd_link_hash_warning
)
3640 h
= (struct mips_elf64_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3642 /* Record the name of this symbol, for our caller. */
3643 *namep
= h
->root
.root
.root
.string
;
3645 /* If this symbol is defined, calculate its address. */
3646 if ((h
->root
.root
.type
== bfd_link_hash_defined
3647 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3648 && h
->root
.root
.u
.def
.section
)
3650 sec
= h
->root
.root
.u
.def
.section
;
3651 if (sec
->output_section
)
3652 symbol
= (h
->root
.root
.u
.def
.value
3653 + sec
->output_section
->vma
3654 + sec
->output_offset
);
3656 symbol
= h
->root
.root
.u
.def
.value
;
3658 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
3659 /* We allow relocations against undefined weak symbols, giving
3660 it the value zero, so that you can undefined weak functions
3661 and check to see if they exist by looking at their
3664 else if (info
->shared
3665 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
3666 && !info
->no_undefined
3667 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
3669 else if (strcmp (h
->root
.root
.root
.string
, "_DYNAMIC_LINK") == 0 ||
3670 strcmp (h
->root
.root
.root
.string
, "_DYNAMIC_LINKING") == 0)
3672 /* If this is a dynamic link, we should have created a
3673 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
3674 in in mips_elf64_create_dynamic_sections.
3675 Otherwise, we should define the symbol with a value of 0.
3676 FIXME: It should probably get into the symbol table
3678 BFD_ASSERT (! info
->shared
);
3679 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
3684 if (! ((*info
->callbacks
->undefined_symbol
)
3685 (info
, h
->root
.root
.root
.string
, input_bfd
,
3686 input_section
, relocation
->r_offset
,
3687 (!info
->shared
|| info
->no_undefined
3688 || ELF_ST_VISIBILITY (h
->root
.other
)))))
3689 return bfd_reloc_undefined
;
3693 target_is_16_bit_code_p
= (h
->root
.other
== STO_MIPS16
);
3696 /* If this is a 64-bit call to a 16-bit function with a stub, we
3697 need to redirect the call to the stub, unless we're already *in*
3699 if (r_type
!= R_MIPS16_26
&& !info
->relocateable
3700 && ((h
!= NULL
&& h
->fn_stub
!= NULL
)
3701 || (local_p
&& elf_tdata (input_bfd
)->local_stubs
!= NULL
3702 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
3703 && !mips_elf64_stub_section_p (input_bfd
, input_section
))
3705 /* This is a 64-bit call to a 16-bit function. We should
3706 have already noticed that we were going to need the
3709 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
3712 BFD_ASSERT (h
->need_fn_stub
);
3716 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
3718 /* If this is a 16-bit call to a 64-bit function with a stub, we
3719 need to redirect the call to the stub. */
3720 else if (r_type
== R_MIPS16_26
&& !info
->relocateable
3722 && (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
)
3723 && !target_is_16_bit_code_p
)
3725 /* If both call_stub and call_fp_stub are defined, we can figure
3726 out which one to use by seeing which one appears in the input
3728 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
3733 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
3735 if (strncmp (bfd_get_section_name (input_bfd
, o
),
3736 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
3738 sec
= h
->call_fp_stub
;
3745 else if (h
->call_stub
!= NULL
)
3748 sec
= h
->call_fp_stub
;
3750 BFD_ASSERT (sec
->_raw_size
> 0);
3751 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
3754 /* Calls from 16-bit code to 32-bit code and vice versa require the
3755 special jalx instruction. */
3756 *require_jalxp
= (!info
->relocateable
3757 && ((r_type
== R_MIPS16_26
) != target_is_16_bit_code_p
));
3759 local_p
= mips_elf64_local_relocation_p (input_bfd
, relocation
,
3760 local_sections
, true);
3762 /* If we haven't already determined the GOT offset, or the GP value,
3763 and we're going to need it, get it now. */
3768 case R_MIPS_GOT_DISP
:
3769 case R_MIPS_GOT_HI16
:
3770 case R_MIPS_CALL_HI16
:
3771 case R_MIPS_GOT_LO16
:
3772 case R_MIPS_CALL_LO16
:
3773 /* Find the index into the GOT where this value is located. */
3776 BFD_ASSERT (addend
== 0);
3777 g
= mips_elf64_global_got_index (elf_hash_table (info
)->dynobj
,
3778 (struct elf_link_hash_entry
*) h
);
3779 if (! elf_hash_table(info
)->dynamic_sections_created
3781 && (info
->symbolic
|| h
->root
.dynindx
== -1)
3782 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
3784 /* This is a static link or a -Bsymbolic link. The
3785 symbol is defined locally, or was forced to be local.
3786 We must initialize this entry in the GOT. */
3787 bfd
*tmpbfd
= elf_hash_table (info
)->dynobj
;
3789 asection
*sgot
= bfd_get_section_by_name (tmpbfd
, ".got");
3790 bfd_put_64 (tmpbfd
, symbol
+ addend
, sgot
->contents
+ g
);
3793 else if (r_type
== R_MIPS_GOT16
|| r_type
== R_MIPS_CALL16
)
3794 /* There's no need to create a local GOT entry here; the
3795 calculation for a local GOT16 entry does not involve G. */
3799 g
= mips_elf64_local_got_index (abfd
, info
, symbol
+ addend
);
3800 if (g
== (bfd_vma
) -1)
3804 /* Convert GOT indices to actual offsets. */
3805 g
= mips_elf64_got_offset_from_index (elf_hash_table (info
)->dynobj
,
3811 case R_MIPS_GPREL16
:
3812 case R_MIPS_GPREL32
:
3813 case R_MIPS_LITERAL
:
3814 gp0
= _bfd_get_gp_value (input_bfd
);
3815 gp
= _bfd_get_gp_value (abfd
);
3822 /* Figure out what kind of relocation is being performed. */
3826 return bfd_reloc_continue
;
3829 value
= symbol
+ mips_elf64_sign_extend (addend
, 16);
3830 overflowed_p
= mips_elf64_overflow_p (value
, 16);
3837 || (elf_hash_table (info
)->dynamic_sections_created
3839 && ((h
->root
.elf_link_hash_flags
3840 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0)
3841 && ((h
->root
.elf_link_hash_flags
3842 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
3844 && (input_section
->flags
& SEC_ALLOC
) != 0)
3846 /* If we're creating a shared library, or this relocation is
3847 against a symbol in a shared library, then we can't know
3848 where the symbol will end up. So, we create a relocation
3849 record in the output, and leave the job up to the dynamic
3852 if (!mips_elf64_create_dynamic_relocation (abfd
, info
, relocation
,
3853 h
, sec
, symbol
, &value
,
3859 if (r_type
!= R_MIPS_REL32
)
3860 value
= symbol
+ addend
;
3864 value
&= howto
->dst_mask
;
3869 case R_MIPS_GNU_REL_LO16
:
3870 value
= symbol
+ addend
- p
;
3871 value
&= howto
->dst_mask
;
3874 case R_MIPS_GNU_REL16_S2
:
3875 value
= symbol
+ mips_elf64_sign_extend (addend
<< 2, 18) - p
;
3876 overflowed_p
= mips_elf64_overflow_p (value
, 18);
3877 value
= (value
>> 2) & howto
->dst_mask
;
3880 case R_MIPS_GNU_REL_HI16
:
3881 value
= mips_elf64_high (addend
+ symbol
- p
);
3882 value
&= howto
->dst_mask
;
3886 /* The calculation for R_MIPS16_26 is just the same as for an
3887 R_MIPS_26. It's only the storage of the relocated field into
3888 the output file that's different. That's handled in
3889 mips_elf_perform_relocation. So, we just fall through to the
3890 R_MIPS_26 case here. */
3893 value
= (((addend
<< 2) | ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
3895 value
= (mips_elf64_sign_extend (addend
<< 2, 28) + symbol
) >> 2;
3896 value
&= howto
->dst_mask
;
3900 value
= mips_elf64_high (addend
+ symbol
);
3901 value
&= howto
->dst_mask
;
3905 value
= (addend
+ symbol
) & 0xffff;
3906 value
&= howto
->dst_mask
;
3909 case R_MIPS_LITERAL
:
3910 /* Because we don't merge literal sections, we can handle this
3911 just like R_MIPS_GPREL16. In the long run, we should merge
3912 shared literals, and then we will need to additional work
3917 case R_MIPS_GPREL16
:
3919 value
= mips_elf64_sign_extend (addend
, 16) + symbol
+ gp0
- gp
;
3921 value
= mips_elf64_sign_extend (addend
, 16) + symbol
- gp
;
3922 overflowed_p
= mips_elf64_overflow_p (value
, 16);
3926 value
= mips_elf64_sign_extend (addend
, 16) + symbol
- p
;
3927 overflowed_p
= mips_elf64_overflow_p (value
, 16);
3928 value
= (bfd_vma
) ((bfd_signed_vma
) value
/ 4);
3937 /* The special case is when the symbol is forced to be local. We
3938 need the full address in the GOT since no R_MIPS_LO16 relocation
3940 forced
= ! mips_elf64_local_relocation_p (input_bfd
, relocation
,
3941 local_sections
, false);
3942 value
= mips_elf64_got16_entry (abfd
, info
, symbol
+ addend
, forced
);
3943 if (value
== (bfd_vma
) -1)
3946 = mips_elf64_got_offset_from_index (elf_hash_table (info
)->dynobj
,
3949 overflowed_p
= mips_elf64_overflow_p (value
, 16);
3955 case R_MIPS_GOT_DISP
:
3957 overflowed_p
= mips_elf64_overflow_p (value
, 16);
3960 case R_MIPS_GPREL32
:
3961 value
= (addend
+ symbol
+ gp0
- gp
) & howto
->dst_mask
;
3964 case R_MIPS_GOT_HI16
:
3965 case R_MIPS_CALL_HI16
:
3966 /* We're allowed to handle these two relocations identically.
3967 The dynamic linker is allowed to handle the CALL relocations
3968 differently by creating a lazy evaluation stub. */
3970 value
= mips_elf64_high (value
);
3971 value
&= howto
->dst_mask
;
3974 case R_MIPS_GOT_LO16
:
3975 case R_MIPS_CALL_LO16
:
3976 value
= g
& howto
->dst_mask
;
3979 case R_MIPS_GOT_PAGE
:
3980 value
= mips_elf64_got_page (abfd
, info
, symbol
+ addend
, NULL
);
3981 if (value
== (bfd_vma
) -1)
3983 value
= mips_elf64_got_offset_from_index (elf_hash_table (info
)->dynobj
,
3986 overflowed_p
= mips_elf64_overflow_p (value
, 16);
3989 case R_MIPS_GOT_OFST
:
3990 mips_elf64_got_page (abfd
, info
, symbol
+ addend
, &value
);
3991 overflowed_p
= mips_elf64_overflow_p (value
, 16);
3995 value
= symbol
- addend
;
3996 value
&= howto
->dst_mask
;
4000 value
= mips_elf64_higher (addend
+ symbol
);
4001 value
&= howto
->dst_mask
;
4004 case R_MIPS_HIGHEST
:
4005 value
= mips_elf64_highest (addend
+ symbol
);
4006 value
&= howto
->dst_mask
;
4009 case R_MIPS_SCN_DISP
:
4010 value
= symbol
+ addend
- sec
->output_offset
;
4011 value
&= howto
->dst_mask
;
4016 /* Both of these may be ignored. R_MIPS_JALR is an optimization
4017 hint; we could improve performance by honoring that hint. */
4018 return bfd_reloc_continue
;
4020 case R_MIPS_GNU_VTINHERIT
:
4021 case R_MIPS_GNU_VTENTRY
:
4022 /* We don't do anything with these at present. */
4023 return bfd_reloc_continue
;
4026 /* An unrecognized relocation type. */
4027 return bfd_reloc_notsupported
;
4030 /* Store the VALUE for our caller. */
4032 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
4035 /* Obtain the field relocated by RELOCATION. */
4038 mips_elf64_obtain_contents (howto
, relocation
, input_bfd
, contents
)
4039 reloc_howto_type
*howto
;
4040 const Elf_Internal_Rela
*relocation
;
4044 bfd_byte
*location
= contents
+ relocation
->r_offset
;
4046 /* Obtain the bytes. */
4047 return bfd_get (8 * bfd_get_reloc_size (howto
), input_bfd
, location
);
4050 /* It has been determined that the result of the RELOCATION is the
4051 VALUE. Use HOWTO to place VALUE into the output file at the
4052 appropriate position. The SECTION is the section to which the
4053 relocation applies. If REQUIRE_JALX is true, then the opcode used
4054 for the relocation must be either JAL or JALX, and it is
4055 unconditionally converted to JALX.
4057 Returns false if anything goes wrong. */
4060 mips_elf64_perform_relocation (info
, howto
, relocation
, value
,
4061 input_bfd
, input_section
,
4062 contents
, require_jalx
)
4063 struct bfd_link_info
*info
;
4064 reloc_howto_type
*howto
;
4065 const Elf_Internal_Rela
*relocation
;
4068 asection
*input_section
;
4070 boolean require_jalx
;
4074 int r_type
= ELF32_R_TYPE (relocation
->r_info
);
4076 /* Figure out where the relocation is occurring. */
4077 location
= contents
+ relocation
->r_offset
;
4079 /* Obtain the current value. */
4080 x
= mips_elf64_obtain_contents (howto
, relocation
, input_bfd
, contents
);
4082 /* Clear the field we are setting. */
4083 x
&= ~howto
->dst_mask
;
4085 /* If this is the R_MIPS16_26 relocation, we must store the
4086 value in a funny way. */
4087 if (r_type
== R_MIPS16_26
)
4089 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
4090 Most mips16 instructions are 16 bits, but these instructions
4093 The format of these instructions is:
4095 +--------------+--------------------------------+
4096 ! JALX ! X! Imm 20:16 ! Imm 25:21 !
4097 +--------------+--------------------------------+
4099 +-----------------------------------------------+
4101 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
4102 Note that the immediate value in the first word is swapped.
4104 When producing a relocateable object file, R_MIPS16_26 is
4105 handled mostly like R_MIPS_26. In particular, the addend is
4106 stored as a straight 26-bit value in a 32-bit instruction.
4107 (gas makes life simpler for itself by never adjusting a
4108 R_MIPS16_26 reloc to be against a section, so the addend is
4109 always zero). However, the 32 bit instruction is stored as 2
4110 16-bit values, rather than a single 32-bit value. In a
4111 big-endian file, the result is the same; in a little-endian
4112 file, the two 16-bit halves of the 32 bit value are swapped.
4113 This is so that a disassembler can recognize the jal
4116 When doing a final link, R_MIPS16_26 is treated as a 32 bit
4117 instruction stored as two 16-bit values. The addend A is the
4118 contents of the targ26 field. The calculation is the same as
4119 R_MIPS_26. When storing the calculated value, reorder the
4120 immediate value as shown above, and don't forget to store the
4121 value as two 16-bit values.
4123 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
4127 +--------+----------------------+
4131 +--------+----------------------+
4134 +----------+------+-------------+
4138 +----------+--------------------+
4139 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
4140 ((sub1 << 16) | sub2)).
4142 When producing a relocateable object file, the calculation is
4143 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
4144 When producing a fully linked file, the calculation is
4145 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
4146 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff) */
4148 if (!info
->relocateable
)
4149 /* Shuffle the bits according to the formula above. */
4150 value
= (((value
& 0x1f0000) << 5)
4151 | ((value
& 0x3e00000) >> 5)
4152 | (value
& 0xffff));
4154 else if (r_type
== R_MIPS16_GPREL
)
4156 /* R_MIPS16_GPREL is used for GP-relative addressing in mips16
4157 mode. A typical instruction will have a format like this:
4159 +--------------+--------------------------------+
4160 ! EXTEND ! Imm 10:5 ! Imm 15:11 !
4161 +--------------+--------------------------------+
4162 ! Major ! rx ! ry ! Imm 4:0 !
4163 +--------------+--------------------------------+
4165 EXTEND is the five bit value 11110. Major is the instruction
4168 This is handled exactly like R_MIPS_GPREL16, except that the
4169 addend is retrieved and stored as shown in this diagram; that
4170 is, the Imm fields above replace the V-rel16 field.
4172 All we need to do here is shuffle the bits appropriately. As
4173 above, the two 16-bit halves must be swapped on a
4174 little-endian system. */
4175 value
= (((value
& 0x7e0) << 16)
4176 | ((value
& 0xf800) << 5)
4180 /* Set the field. */
4181 x
|= (value
& howto
->dst_mask
);
4183 /* If required, turn JAL into JALX. */
4187 bfd_vma opcode
= x
>> 26;
4188 bfd_vma jalx_opcode
;
4190 /* Check to see if the opcode is already JAL or JALX. */
4191 if (r_type
== R_MIPS16_26
)
4193 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
4198 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
4202 /* If the opcode is not JAL or JALX, there's a problem. */
4205 (*_bfd_error_handler
)
4206 (_("%s: %s+0x%lx: jump to stub routine which is not jal"),
4207 bfd_archive_filename (input_bfd
),
4208 input_section
->name
,
4209 (unsigned long) relocation
->r_offset
);
4210 bfd_set_error (bfd_error_bad_value
);
4214 /* Make this the JALX opcode. */
4215 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
4218 /* Swap the high- and low-order 16 bits on little-endian systems
4219 when doing a MIPS16 relocation. */
4220 if ((r_type
== R_MIPS16_GPREL
|| r_type
== R_MIPS16_26
)
4221 && bfd_little_endian (input_bfd
))
4222 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
4224 /* Put the value into the output. */
4225 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
4229 /* Returns true if SECTION is a MIPS16 stub section. */
4232 mips_elf64_stub_section_p (abfd
, section
)
4233 bfd
*abfd ATTRIBUTE_UNUSED
;
4236 const char *name
= bfd_get_section_name (abfd
, section
);
4238 return (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0
4239 || strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
4240 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0);
4243 /* Relocate a MIPS ELF64 section. */
4246 mips_elf64_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4247 contents
, relocs
, local_syms
, local_sections
)
4249 struct bfd_link_info
*info
;
4251 asection
*input_section
;
4253 Elf_Internal_Rela
*relocs
;
4254 Elf_Internal_Sym
*local_syms
;
4255 asection
**local_sections
;
4257 Elf_Internal_Rela
*rel
;
4258 const Elf_Internal_Rela
*relend
;
4260 boolean use_saved_addend_p
= false;
4261 struct elf_backend_data
*bed
;
4263 bed
= get_elf_backend_data (output_bfd
);
4264 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
4265 for (rel
= relocs
; rel
< relend
; ++rel
)
4269 reloc_howto_type
*howto
;
4270 boolean require_jalx
;
4271 /* True if the relocation is a RELA relocation, rather than a
4273 boolean rela_relocation_p
= true;
4274 int r_type
= ELF64_MIPS_R_TYPE (rel
->r_info
);
4275 const char *msg
= (const char *) NULL
;
4277 /* Find the relocation howto for this relocation. */
4278 howto
= &mips_elf64_howto_table_rela
[r_type
];
4280 if (!use_saved_addend_p
)
4282 Elf_Internal_Shdr
*rel_hdr
;
4284 /* If these relocations were originally of the REL variety,
4285 we must pull the addend out of the field that will be
4286 relocated. Otherwise, we simply use the contents of the
4287 RELA relocation. To determine which flavor or relocation
4288 this is, we depend on the fact that the INPUT_SECTION's
4289 REL_HDR is read before its REL_HDR2. */
4290 rel_hdr
= &elf_section_data (input_section
)->rel_hdr
;
4291 if ((size_t) (rel
- relocs
)
4292 >= (NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
))
4293 rel_hdr
= elf_section_data (input_section
)->rel_hdr2
;
4294 if (rel_hdr
->sh_entsize
4295 == (get_elf_backend_data (input_bfd
)->s
->sizeof_rel
))
4297 /* Note that this is a REL relocation. */
4298 rela_relocation_p
= false;
4300 /* Find the relocation howto for this relocation. */
4301 howto
= &mips_elf64_howto_table_rel
[r_type
];
4303 /* Get the addend, which is stored in the input file. */
4304 addend
= mips_elf64_obtain_contents (howto
,
4308 addend
&= howto
->src_mask
;
4310 /* For some kinds of relocations, the ADDEND is a
4311 combination of the addend stored in two different
4313 if (r_type
== R_MIPS_HI16
4314 || r_type
== R_MIPS_GNU_REL_HI16
4315 || (r_type
== R_MIPS_GOT16
4316 && mips_elf64_local_relocation_p (input_bfd
, rel
,
4317 local_sections
, false)))
4320 const Elf_Internal_Rela
*lo16_relocation
;
4321 reloc_howto_type
*lo16_howto
;
4324 /* The combined value is the sum of the HI16 addend,
4325 left-shifted by sixteen bits, and the LO16
4326 addend, sign extended. (Usually, the code does
4327 a `lui' of the HI16 value, and then an `addiu' of
4330 Scan ahead to find a matching LO16 relocation. */
4331 if (r_type
== R_MIPS_GNU_REL_HI16
)
4332 lo
= R_MIPS_GNU_REL_LO16
;
4336 = mips_elf64_next_relocation (lo
, rel
, relend
);
4337 if (lo16_relocation
== NULL
)
4340 /* Obtain the addend kept there. */
4341 if (rela_relocation_p
== false)
4342 lo16_howto
= &mips_elf64_howto_table_rel
[lo
];
4344 lo16_howto
= &mips_elf64_howto_table_rela
[lo
];
4345 l
= mips_elf64_obtain_contents (lo16_howto
,
4347 input_bfd
, contents
);
4348 l
&= lo16_howto
->src_mask
;
4349 l
= mips_elf64_sign_extend (l
, 16);
4353 /* Compute the combined addend. */
4358 addend
= rel
->r_addend
;
4361 if (info
->relocateable
)
4363 Elf_Internal_Sym
*sym
;
4364 unsigned long r_symndx
;
4366 /* Since we're just relocating, all we need to do is copy
4367 the relocations back out to the object file, unless
4368 they're against a section symbol, in which case we need
4369 to adjust by the section offset, or unless they're GP
4370 relative in which case we need to adjust by the amount
4371 that we're adjusting GP in this relocateable object. */
4373 if (!mips_elf64_local_relocation_p (input_bfd
, rel
, local_sections
,
4375 /* There's nothing to do for non-local relocations. */
4378 if (r_type
== R_MIPS_GPREL16
4379 || r_type
== R_MIPS_GPREL32
4380 || r_type
== R_MIPS_LITERAL
)
4381 addend
-= (_bfd_get_gp_value (output_bfd
)
4382 - _bfd_get_gp_value (input_bfd
));
4383 else if (r_type
== R_MIPS_26
|| r_type
== R_MIPS_GNU_REL16_S2
)
4384 /* The addend is stored without its two least
4385 significant bits (which are always zero.) In a
4386 non-relocateable link, calculate_relocation will do
4387 this shift; here, we must do it ourselves. */
4390 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4391 sym
= local_syms
+ r_symndx
;
4392 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4393 /* Adjust the addend appropriately. */
4394 addend
+= local_sections
[r_symndx
]->output_offset
;
4397 /* If the relocation is for a R_MIPS_HI16 or R_MIPS_GOT16,
4398 then we only want to write out the high-order 16 bits.
4399 The subsequent R_MIPS_LO16 will handle the low-order bits. */
4400 if (r_type
== R_MIPS_HI16
|| r_type
== R_MIPS_GOT16
4401 || r_type
== R_MIPS_GNU_REL_HI16
)
4402 addend
= mips_elf64_high (addend
);
4403 else if (r_type
== R_MIPS_HIGHER
)
4404 addend
= mips_elf64_higher (addend
);
4405 else if (r_type
== R_MIPS_HIGHEST
)
4406 addend
= mips_elf64_highest (addend
);
4408 /* If the relocation is for an R_MIPS_26 relocation, then
4409 the two low-order bits are not stored in the object file;
4410 they are implicitly zero. */
4411 if (r_type
== R_MIPS_26
|| r_type
== R_MIPS_GNU_REL16_S2
)
4414 if (rela_relocation_p
)
4415 /* If this is a RELA relocation, just update the addend.
4416 We have to cast away constness for REL. */
4417 rel
->r_addend
= addend
;
4420 /* Otherwise, we have to write the value back out. Note
4421 that we use the source mask, rather than the
4422 destination mask because the place to which we are
4423 writing will be source of the addend in the final
4425 addend
&= howto
->src_mask
;
4427 if (!mips_elf64_perform_relocation (info
, howto
, rel
, addend
,
4428 input_bfd
, input_section
,
4433 /* Go on to the next relocation. */
4437 /* In the N32 and 64-bit ABIs there may be multiple consecutive
4438 relocations for the same offset. In that case we are
4439 supposed to treat the output of each relocation as the addend
4441 if (rel
+ 1 < relend
4442 && rel
->r_offset
== rel
[1].r_offset
4443 && ELF64_MIPS_R_TYPE (rel
[1].r_info
) != R_MIPS_NONE
)
4444 use_saved_addend_p
= true;
4446 use_saved_addend_p
= false;
4448 /* Figure out what value we are supposed to relocate. */
4449 switch (mips_elf64_calculate_relocation (output_bfd
, input_bfd
,
4450 input_section
, info
, rel
,
4451 addend
, howto
, local_syms
,
4452 local_sections
, &value
, &name
,
4455 case bfd_reloc_continue
:
4456 /* There's nothing to do. */
4459 case bfd_reloc_undefined
:
4460 /* mips_elf64_calculate_relocation already called the
4461 undefined_symbol callback. There's no real point in
4462 trying to perform the relocation at this point, so we
4463 just skip ahead to the next relocation. */
4466 case bfd_reloc_notsupported
:
4467 msg
= _("internal error: unsupported relocation error");
4468 info
->callbacks
->warning
4469 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
4472 case bfd_reloc_overflow
:
4473 if (use_saved_addend_p
)
4474 /* Ignore overflow until we reach the last relocation for
4475 a given location. */
4479 BFD_ASSERT (name
!= NULL
);
4480 if (! ((*info
->callbacks
->reloc_overflow
)
4481 (info
, name
, howto
->name
, (bfd_vma
) 0,
4482 input_bfd
, input_section
, rel
->r_offset
)))
4495 /* If we've got another relocation for the address, keep going
4496 until we reach the last one. */
4497 if (use_saved_addend_p
)
4503 /* Actually perform the relocation. */
4504 if (!mips_elf64_perform_relocation (info
, howto
, rel
, value
, input_bfd
,
4505 input_section
, contents
,
4513 /* Create dynamic sections when linking against a dynamic object. */
4516 mips_elf64_create_dynamic_sections (abfd
, info
)
4518 struct bfd_link_info
*info
;
4521 register asection
*s
;
4523 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4524 | SEC_LINKER_CREATED
| SEC_READONLY
);
4526 /* Mips ABI requests the .dynamic section to be read only. */
4527 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4530 if (! bfd_set_section_flags (abfd
, s
, flags
))
4534 /* We need to create .got section. */
4535 if (! mips_elf64_create_got_section (abfd
, info
))
4538 /* Create the .msym section on IRIX6. It is used by the dynamic
4539 linker to speed up dynamic relocations, and to avoid computing
4540 the ELF hash for symbols. */
4541 if (!mips_elf64_create_msym_section (abfd
))
4544 /* Create .stub section. */
4545 if (bfd_get_section_by_name (abfd
, ".MIPS.stubs") == NULL
)
4547 s
= bfd_make_section (abfd
, ".MIPS.stubs");
4549 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_CODE
)
4550 || ! bfd_set_section_alignment (abfd
, s
, 3))
4557 /* Adjust a symbol defined by a dynamic object and referenced by a
4558 regular object. The current definition is in some section of the
4559 dynamic object, but we're not including those sections. We have to
4560 change the definition to something the rest of the link can
4564 mips_elf64_adjust_dynamic_symbol (info
, h
)
4565 struct bfd_link_info
*info
;
4566 struct elf_link_hash_entry
*h
;
4569 struct mips_elf64_link_hash_entry
*hmips
;
4572 dynobj
= elf_hash_table (info
)->dynobj
;
4574 /* Make sure we know what is going on here. */
4575 BFD_ASSERT (dynobj
!= NULL
4576 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
4577 || h
->weakdef
!= NULL
4578 || ((h
->elf_link_hash_flags
4579 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4580 && (h
->elf_link_hash_flags
4581 & ELF_LINK_HASH_REF_REGULAR
) != 0
4582 && (h
->elf_link_hash_flags
4583 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
4585 /* If this symbol is defined in a dynamic object, we need to copy
4586 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
4588 hmips
= (struct mips_elf64_link_hash_entry
*) h
;
4589 if (! info
->relocateable
4590 && hmips
->possibly_dynamic_relocs
!= 0
4591 && (h
->root
.type
== bfd_link_hash_defweak
4592 || (h
->elf_link_hash_flags
4593 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4595 mips_elf64_allocate_dynamic_relocations (dynobj
,
4596 hmips
->possibly_dynamic_relocs
);
4597 if (hmips
->readonly_reloc
)
4598 /* We tell the dynamic linker that there are relocations
4599 against the text segment. */
4600 info
->flags
|= DF_TEXTREL
;
4603 /* For a function, create a stub, if allowed. */
4604 if (! hmips
->no_fn_stub
4605 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4607 if (! elf_hash_table (info
)->dynamic_sections_created
)
4610 /* If this symbol is not defined in a regular file, then set
4611 the symbol to the stub location. This is required to make
4612 function pointers compare as equal between the normal
4613 executable and the shared library. */
4614 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4616 /* We need .stub section. */
4617 s
= bfd_get_section_by_name (dynobj
, ".MIPS.stubs");
4618 BFD_ASSERT (s
!= NULL
);
4620 h
->root
.u
.def
.section
= s
;
4621 h
->root
.u
.def
.value
= s
->_raw_size
;
4623 /* XXX Write this stub address somewhere. */
4624 h
->plt
.offset
= s
->_raw_size
;
4626 /* Make room for this stub code. */
4627 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
4629 /* The last half word of the stub will be filled with the index
4630 of this symbol in .dynsym section. */
4634 else if ((h
->type
== STT_FUNC
)
4635 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) == 0)
4637 /* This will set the entry for this symbol in the GOT to 0, and
4638 the dynamic linker will take care of this. */
4639 h
->root
.u
.def
.value
= 0;
4643 /* If this is a weak symbol, and there is a real definition, the
4644 processor independent code will have arranged for us to see the
4645 real definition first, and we can just use the same value. */
4646 if (h
->weakdef
!= NULL
)
4648 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
4649 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
4650 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
4651 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
4655 /* This is a reference to a symbol defined by a dynamic object which
4656 is not a function. */
4661 /* This function is called after all the input files have been read,
4662 and the input sections have been assigned to output sections. */
4665 mips_elf64_always_size_sections (output_bfd
, info
)
4666 bfd
*output_bfd ATTRIBUTE_UNUSED
;
4667 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
4669 if (info
->relocateable
4670 || ! mips_elf64_hash_table (info
)->mips16_stubs_seen
)
4673 mips_elf64_link_hash_traverse (mips_elf64_hash_table (info
),
4674 mips_elf64_check_mips16_stubs
,
4680 /* Check the mips16 stubs for a particular symbol, and see if we can
4684 mips_elf64_check_mips16_stubs (h
, data
)
4685 struct mips_elf64_link_hash_entry
*h
;
4686 PTR data ATTRIBUTE_UNUSED
;
4688 if (h
->fn_stub
!= NULL
4689 && ! h
->need_fn_stub
)
4691 /* We don't need the fn_stub; the only references to this symbol
4692 are 16 bit calls. Clobber the size to 0 to prevent it from
4693 being included in the link. */
4694 h
->fn_stub
->_raw_size
= 0;
4695 h
->fn_stub
->_cooked_size
= 0;
4696 h
->fn_stub
->flags
&= ~SEC_RELOC
;
4697 h
->fn_stub
->reloc_count
= 0;
4698 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
4701 if (h
->call_stub
!= NULL
4702 && h
->root
.other
== STO_MIPS16
)
4704 /* We don't need the call_stub; this is a 16 bit function, so
4705 calls from other 16 bit functions are OK. Clobber the size
4706 to 0 to prevent it from being included in the link. */
4707 h
->call_stub
->_raw_size
= 0;
4708 h
->call_stub
->_cooked_size
= 0;
4709 h
->call_stub
->flags
&= ~SEC_RELOC
;
4710 h
->call_stub
->reloc_count
= 0;
4711 h
->call_stub
->flags
|= SEC_EXCLUDE
;
4714 if (h
->call_fp_stub
!= NULL
4715 && h
->root
.other
== STO_MIPS16
)
4717 /* We don't need the call_stub; this is a 16 bit function, so
4718 calls from other 16 bit functions are OK. Clobber the size
4719 to 0 to prevent it from being included in the link. */
4720 h
->call_fp_stub
->_raw_size
= 0;
4721 h
->call_fp_stub
->_cooked_size
= 0;
4722 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
4723 h
->call_fp_stub
->reloc_count
= 0;
4724 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
4730 /* Set the sizes of the dynamic sections. */
4733 mips_elf64_size_dynamic_sections (output_bfd
, info
)
4735 struct bfd_link_info
*info
;
4740 struct mips_elf64_got_info
*g
= NULL
;
4742 dynobj
= elf_hash_table (info
)->dynobj
;
4743 BFD_ASSERT (dynobj
!= NULL
);
4745 if (elf_hash_table (info
)->dynamic_sections_created
)
4747 /* Set the contents of the .interp section to the interpreter. */
4750 s
= bfd_get_section_by_name (dynobj
, ".interp");
4751 BFD_ASSERT (s
!= NULL
);
4752 s
->_raw_size
= strlen ("/usr/lib64/libc.so.1") + 1;
4753 s
->contents
= (bfd_byte
*) "/usr/lib64/libc.so.1";
4757 /* The check_relocs and adjust_dynamic_symbol entry points have
4758 determined the sizes of the various dynamic sections. Allocate
4761 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4766 /* It's OK to base decisions on the section name, because none
4767 of the dynobj section names depend upon the input files. */
4768 name
= bfd_get_section_name (dynobj
, s
);
4770 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4775 if (strncmp (name
, ".rel", 4) == 0)
4777 if (s
->_raw_size
== 0)
4779 /* We only strip the section if the output section name
4780 has the same name. Otherwise, there might be several
4781 input sections for this output section. FIXME: This
4782 code is probably not needed these days anyhow, since
4783 the linker now does not create empty output sections. */
4784 if (s
->output_section
!= NULL
4786 bfd_get_section_name (s
->output_section
->owner
,
4787 s
->output_section
)) == 0)
4792 const char *outname
;
4795 /* If this relocation section applies to a read only
4796 section, then we probably need a DT_TEXTREL entry.
4797 If the relocation section is .rel.dyn, we always
4798 assert a DT_TEXTREL entry rather than testing whether
4799 there exists a relocation to a read only section or
4801 outname
= bfd_get_section_name (output_bfd
,
4803 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
4805 && (target
->flags
& SEC_READONLY
) != 0
4806 && (target
->flags
& SEC_ALLOC
) != 0)
4807 || strcmp (outname
, "rel.dyn") == 0)
4810 /* We use the reloc_count field as a counter if we need
4811 to copy relocs into the output file. */
4812 if (strcmp (name
, "rel.dyn") != 0)
4816 else if (strncmp (name
, ".got", 4) == 0)
4819 bfd_size_type loadable_size
= 0;
4820 bfd_size_type local_gotno
;
4823 BFD_ASSERT (elf_section_data (s
) != NULL
);
4824 g
= (struct mips_elf64_got_info
*) elf_section_data (s
)->tdata
;
4825 BFD_ASSERT (g
!= NULL
);
4827 /* Calculate the total loadable size of the output. That
4828 will give us the maximum number of GOT_PAGE entries
4830 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
4832 asection
*subsection
;
4834 for (subsection
= sub
->sections
;
4836 subsection
= subsection
->next
)
4838 if ((subsection
->flags
& SEC_ALLOC
) == 0)
4840 loadable_size
+= (subsection
->_raw_size
+ 0xf) & ~0xf;
4843 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
4845 /* Assume there are two loadable segments consisting of
4846 contiguous sections. Is 5 enough? */
4847 local_gotno
= (loadable_size
>> 16) + 5;
4848 /* It's possible we will need GOT_PAGE entries as well as
4849 GOT16 entries. Often, these will be able to share GOT
4850 entries, but not always. */
4853 g
->local_gotno
+= local_gotno
;
4854 s
->_raw_size
+= local_gotno
* 8;
4856 /* There has to be a global GOT entry for every symbol with
4857 a dynamic symbol table index of DT_MIPS_GOTSYM or
4858 higher. Therefore, it make sense to put those symbols
4859 that need GOT entries at the end of the symbol table. We
4861 if (!mips_elf64_sort_hash_table (info
, 1))
4864 if (g
->global_gotsym
!= NULL
)
4865 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
4867 /* If there are no global symbols, or none requiring
4868 relocations, then GLOBAL_GOTSYM will be NULL. */
4870 g
->global_gotno
= i
;
4871 s
->_raw_size
+= i
* 8;
4873 else if (strcmp (name
, ".MIPS.stubs") == 0)
4875 /* Irix rld assumes that the function stub isn't at the end
4876 of .text section. So put a dummy. XXX */
4877 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
4879 else if (strcmp (name
, ".msym")
4881 s
->_raw_size
= (sizeof (Elf32_External_Msym
)
4882 * (elf_hash_table (info
)->dynsymcount
4883 + bfd_count_sections (output_bfd
)));
4884 else if (strncmp (name
, ".init", 5) != 0)
4886 /* It's not one of our sections, so don't allocate space. */
4892 _bfd_strip_section_from_output (info
, s
);
4896 /* Allocate memory for the section contents. */
4897 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
4898 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
4900 bfd_set_error (bfd_error_no_memory
);
4905 if (elf_hash_table (info
)->dynamic_sections_created
)
4907 /* Add some entries to the .dynamic section. We fill in the
4908 values later, in elf_mips_finish_dynamic_sections, but we
4909 must add the entries now so that we get the correct size for
4910 the .dynamic section. The DT_DEBUG entry is filled in by the
4911 dynamic linker and used by the debugger. */
4914 /* SGI object has the equivalence of DT_DEBUG in the
4915 DT_MIPS_RLD_MAP entry. */
4916 if (!bfd_elf64_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
4918 if (!SGI_COMPAT (output_bfd
))
4920 if (!bfd_elf64_add_dynamic_entry (info
, DT_DEBUG
, 0))
4926 /* Shared libraries on traditional mips have DT_DEBUG. */
4927 if (!SGI_COMPAT (output_bfd
))
4929 if (!bfd_elf64_add_dynamic_entry (info
, DT_DEBUG
, 0))
4934 if (reltext
&& SGI_COMPAT (output_bfd
))
4935 info
->flags
|= DF_TEXTREL
;
4937 if ((info
->flags
& DF_TEXTREL
) != 0)
4939 if (! bfd_elf64_add_dynamic_entry (info
, DT_TEXTREL
, 0))
4943 if (! bfd_elf64_add_dynamic_entry (info
, DT_PLTGOT
, 0))
4946 if (bfd_get_section_by_name (dynobj
, "rel.dyn"))
4948 if (! bfd_elf64_add_dynamic_entry (info
, DT_REL
, 0))
4951 if (! bfd_elf64_add_dynamic_entry (info
, DT_RELSZ
, 0))
4954 if (! bfd_elf64_add_dynamic_entry (info
, DT_RELENT
, 0))
4958 if (SGI_COMPAT (output_bfd
))
4960 if (!bfd_elf64_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
4964 if (SGI_COMPAT (output_bfd
))
4966 if (!bfd_elf64_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
4970 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
4972 if (! bfd_elf64_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
4975 s
= bfd_get_section_by_name (dynobj
, ".liblist");
4976 BFD_ASSERT (s
!= NULL
);
4978 if (! bfd_elf64_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
4982 if (! bfd_elf64_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
4985 if (! bfd_elf64_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
4989 /* Time stamps in executable files are a bad idea. */
4990 if (! bfd_elf64_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
4995 if (! bfd_elf64_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
5000 if (! bfd_elf64_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
5004 if (! bfd_elf64_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
5007 if (! bfd_elf64_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
5010 if (! bfd_elf64_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
5013 if (! bfd_elf64_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
5016 if (! bfd_elf64_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
5019 if ((bfd_get_section_by_name(dynobj
, ".MIPS.options"))
5020 && !bfd_elf64_add_dynamic_entry (info
, DT_MIPS_OPTIONS
, 0))
5023 if (bfd_get_section_by_name (dynobj
, ".msym")
5024 && !bfd_elf64_add_dynamic_entry (info
, DT_MIPS_MSYM
, 0))
5031 /* Finish up dynamic symbol handling. We set the contents of various
5032 dynamic sections here. */
5035 mips_elf64_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
5037 struct bfd_link_info
*info
;
5038 struct elf_link_hash_entry
*h
;
5039 Elf_Internal_Sym
*sym
;
5045 struct mips_elf64_got_info
*g
;
5047 struct mips_elf64_link_hash_entry
*mh
;
5049 dynobj
= elf_hash_table (info
)->dynobj
;
5050 gval
= sym
->st_value
;
5051 mh
= (struct mips_elf64_link_hash_entry
*) h
;
5053 if (h
->plt
.offset
!= (bfd_vma
) -1)
5056 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
5058 /* This symbol has a stub. Set it up. */
5060 BFD_ASSERT (h
->dynindx
!= -1);
5062 s
= bfd_get_section_by_name (dynobj
, ".MIPS.stubs");
5063 BFD_ASSERT (s
!= NULL
);
5065 /* FIXME: Can h->dynindex be more than 64K? */
5066 if (h
->dynindx
& 0xffff0000)
5069 /* Fill the stub. */
5070 bfd_put_32 (output_bfd
, STUB_LW
, stub
);
5071 bfd_put_32 (output_bfd
, STUB_MOVE
, stub
+ 4);
5072 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ 8);
5073 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, stub
+ 12);
5075 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
5076 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
5078 /* Mark the symbol as undefined. plt.offset != -1 occurs
5079 only for the referenced symbol. */
5080 sym
->st_shndx
= SHN_UNDEF
;
5082 /* The run-time linker uses the st_value field of the symbol
5083 to reset the global offset table entry for this external
5084 to its stub address when unlinking a shared object. */
5085 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
5086 sym
->st_value
= gval
;
5089 BFD_ASSERT (h
->dynindx
!= -1
5090 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0);
5092 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5093 BFD_ASSERT (sgot
!= NULL
);
5094 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5095 g
= (struct mips_elf64_got_info
*) elf_section_data (sgot
)->tdata
;
5096 BFD_ASSERT (g
!= NULL
);
5098 /* Run through the global symbol table, creating GOT entries for all
5099 the symbols that need them. */
5100 if (g
->global_gotsym
!= NULL
5101 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
5107 value
= sym
->st_value
;
5110 /* For an entity defined in a shared object, this will be
5111 NULL. (For functions in shared objects for
5112 which we have created stubs, ST_VALUE will be non-NULL.
5113 That's because such the functions are now no longer defined
5114 in a shared object.) */
5116 if (info
->shared
&& h
->root
.type
== bfd_link_hash_undefined
)
5119 value
= h
->root
.u
.def
.value
;
5121 offset
= mips_elf64_global_got_index (dynobj
, h
);
5122 bfd_put_64 (output_bfd
, value
, sgot
->contents
+ offset
);
5125 /* Create a .msym entry, if appropriate. */
5126 smsym
= bfd_get_section_by_name (dynobj
, ".msym");
5129 Elf32_Internal_Msym msym
;
5131 msym
.ms_hash_value
= bfd_elf_hash (h
->root
.root
.string
);
5132 /* It is undocumented what the `1' indicates, but IRIX6 uses
5134 msym
.ms_info
= ELF32_MS_INFO (mh
->min_dyn_reloc_index
, 1);
5135 mips_elf64_swap_msym_out
5137 ((Elf32_External_Msym
*) smsym
->contents
) + h
->dynindx
);
5140 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
5141 name
= h
->root
.root
.string
;
5142 if (strcmp (name
, "_DYNAMIC") == 0
5143 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
5144 sym
->st_shndx
= SHN_ABS
;
5145 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
5146 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
5148 sym
->st_shndx
= SHN_ABS
;
5149 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5152 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
5154 if (h
->type
== STT_FUNC
)
5155 sym
->st_shndx
= SHN_MIPS_TEXT
;
5156 else if (h
->type
== STT_OBJECT
)
5157 sym
->st_shndx
= SHN_MIPS_DATA
;
5160 /* Handle the IRIX6-specific symbols. */
5163 /* The linker script takes care of providing names and values for
5164 these, but we must place them into the right sections. */
5165 static const char* const text_section_symbols
[] = {
5168 "__dso_displacement",
5170 "__program_header_table",
5174 static const char* const data_section_symbols
[] = {
5182 const char* const *p
;
5185 for (i
= 0; i
< 2; ++i
)
5186 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
5189 if (strcmp (*p
, name
) == 0)
5191 /* All of these symbols are given type STT_SECTION by the
5193 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5195 /* The IRIX linker puts these symbols in special sections. */
5197 sym
->st_shndx
= SHN_MIPS_TEXT
;
5199 sym
->st_shndx
= SHN_MIPS_DATA
;
5208 /* Finish up the dynamic sections. */
5211 mips_elf64_finish_dynamic_sections (output_bfd
, info
)
5213 struct bfd_link_info
*info
;
5218 struct mips_elf64_got_info
*g
;
5220 dynobj
= elf_hash_table (info
)->dynobj
;
5222 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5224 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5229 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5230 g
= (struct mips_elf64_got_info
*) elf_section_data (sgot
)->tdata
;
5231 BFD_ASSERT (g
!= NULL
);
5234 if (elf_hash_table (info
)->dynamic_sections_created
)
5238 BFD_ASSERT (sdyn
!= NULL
);
5239 BFD_ASSERT (g
!= NULL
);
5241 for (b
= sdyn
->contents
;
5242 b
< sdyn
->contents
+ sdyn
->_raw_size
;
5243 b
+= get_elf_backend_data (dynobj
)->s
->sizeof_dyn
)
5245 Elf_Internal_Dyn dyn
;
5251 /* Read in the current dynamic entry. */
5252 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
5254 /* Assume that we're going to modify it and write it out. */
5260 s
= bfd_get_section_by_name(dynobj
, "rel.dyn");
5261 BFD_ASSERT (s
!= NULL
);
5262 dyn
.d_un
.d_val
= get_elf_backend_data (dynobj
)->s
->sizeof_rel
;
5266 /* Rewrite DT_STRSZ. */
5268 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
5274 case DT_MIPS_CONFLICT
:
5277 case DT_MIPS_LIBLIST
:
5280 s
= bfd_get_section_by_name (output_bfd
, name
);
5281 BFD_ASSERT (s
!= NULL
);
5282 dyn
.d_un
.d_ptr
= s
->vma
;
5285 case DT_MIPS_RLD_VERSION
:
5286 dyn
.d_un
.d_val
= 1; /* XXX */
5290 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
5293 case DT_MIPS_CONFLICTNO
:
5295 elemsize
= sizeof (Elf32_Conflict
);
5298 case DT_MIPS_LIBLISTNO
:
5300 elemsize
= sizeof (Elf32_Lib
);
5302 s
= bfd_get_section_by_name (output_bfd
, name
);
5305 if (s
->_cooked_size
!= 0)
5306 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5308 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5314 case DT_MIPS_TIME_STAMP
:
5315 time ((time_t *) &dyn
.d_un
.d_val
);
5318 case DT_MIPS_ICHECKSUM
:
5323 case DT_MIPS_IVERSION
:
5328 case DT_MIPS_BASE_ADDRESS
:
5329 s
= output_bfd
->sections
;
5330 BFD_ASSERT (s
!= NULL
);
5331 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
5334 case DT_MIPS_LOCAL_GOTNO
:
5335 dyn
.d_un
.d_val
= g
->local_gotno
;
5338 case DT_MIPS_UNREFEXTNO
:
5339 /* The index into the dynamic symbol table which is the
5340 entry of the first external symbol that is not
5341 referenced within the same object. */
5342 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
5345 case DT_MIPS_GOTSYM
:
5346 if (g
->global_gotsym
)
5348 dyn
.d_un
.d_val
= g
->global_gotsym
->dynindx
;
5351 /* In case if we don't have global got symbols we default
5352 to setting DT_MIPS_GOTSYM to the same value as
5353 DT_MIPS_SYMTABNO, so we just fall through. */
5355 case DT_MIPS_SYMTABNO
:
5357 elemsize
= get_elf_backend_data (output_bfd
)->s
->sizeof_sym
;
5358 s
= bfd_get_section_by_name (output_bfd
, name
);
5359 BFD_ASSERT (s
!= NULL
);
5361 if (s
->_cooked_size
!= 0)
5362 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5364 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5367 case DT_MIPS_HIPAGENO
:
5368 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
5371 case DT_MIPS_OPTIONS
:
5372 s
= bfd_get_section_by_name(output_bfd
, ".MIPS.options");
5373 dyn
.d_un
.d_ptr
= s
->vma
;
5377 s
= bfd_get_section_by_name(output_bfd
, ".msym");
5378 dyn
.d_un
.d_ptr
= s
->vma
;
5387 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
5392 /* The first entry of the global offset table will be filled at
5393 runtime. The second entry will be used by some runtime loaders.
5394 This isn't the case of Irix rld. */
5395 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
5397 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
5398 bfd_put_64 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 8);
5402 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
5408 /* ??? The section symbols for the output sections were set up in
5409 _bfd_elf_final_link. SGI sets the STT_NOTYPE attribute for these
5410 symbols. Should we do so? */
5412 smsym
= bfd_get_section_by_name (dynobj
, ".msym");
5415 Elf32_Internal_Msym msym
;
5417 msym
.ms_hash_value
= 0;
5418 msym
.ms_info
= ELF32_MS_INFO (0, 1);
5420 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
5422 long dynindx
= elf_section_data (s
)->dynindx
;
5424 mips_elf64_swap_msym_out
5426 (((Elf32_External_Msym
*) smsym
->contents
)
5431 /* Clean up a first relocation in .rel.dyn. */
5432 s
= bfd_get_section_by_name (dynobj
, "rel.dyn");
5433 if (s
!= NULL
&& s
->_raw_size
> 0)
5434 memset (s
->contents
, 0, get_elf_backend_data (dynobj
)->s
->sizeof_rel
);
5440 /* Return the section that should be marked against GC for a given
5444 mips_elf64_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
5446 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
5447 Elf_Internal_Rela
*rel
;
5448 struct elf_link_hash_entry
*h
;
5449 Elf_Internal_Sym
*sym
;
5453 switch (ELF64_R_TYPE (rel
->r_info
))
5455 case R_MIPS_GNU_VTINHERIT
:
5456 case R_MIPS_GNU_VTENTRY
:
5460 switch (h
->root
.type
)
5462 case bfd_link_hash_defined
:
5463 case bfd_link_hash_defweak
:
5464 return h
->root
.u
.def
.section
;
5466 case bfd_link_hash_common
:
5467 return h
->root
.u
.c
.p
->section
;
5476 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
5482 /* Update the got entry reference counts for the section being removed. */
5485 mips_elf64_gc_sweep_hook (abfd
, info
, sec
, relocs
)
5486 bfd
*abfd ATTRIBUTE_UNUSED
;
5487 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
5488 asection
*sec ATTRIBUTE_UNUSED
;
5489 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
5492 Elf_Internal_Shdr
*symtab_hdr
;
5493 struct elf_link_hash_entry
**sym_hashes
;
5494 bfd_signed_vma
*local_got_refcounts
;
5495 const Elf_Internal_Rela
*rel
, *relend
;
5496 unsigned long r_symndx
;
5497 struct elf_link_hash_entry
*h
;
5499 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5500 sym_hashes
= elf_sym_hashes (abfd
);
5501 local_got_refcounts
= elf_local_got_refcounts (abfd
);
5503 relend
= relocs
+ sec
->reloc_count
;
5504 for (rel
= relocs
; rel
< relend
; rel
++)
5505 switch (ELF64_R_TYPE (rel
->r_info
))
5509 case R_MIPS_CALL_HI16
:
5510 case R_MIPS_CALL_LO16
:
5511 case R_MIPS_GOT_HI16
:
5512 case R_MIPS_GOT_LO16
:
5513 /* ??? It would seem that the existing MIPS code does no sort
5514 of reference counting or whatnot on its GOT and PLT entries,
5515 so it is not possible to garbage collect them at this time. */
5526 /* Create the .got section to hold the global offset table. */
5529 mips_elf64_create_got_section (abfd
, info
)
5531 struct bfd_link_info
*info
;
5534 register asection
*s
;
5535 struct elf_link_hash_entry
*h
;
5536 struct mips_elf64_got_info
*g
;
5538 /* This function may be called more than once. */
5539 if (bfd_get_section_by_name (abfd
, ".got"))
5542 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5543 | SEC_LINKER_CREATED
);
5545 s
= bfd_make_section (abfd
, ".got");
5547 || ! bfd_set_section_flags (abfd
, s
, flags
)
5548 || ! bfd_set_section_alignment (abfd
, s
, 4))
5551 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
5552 linker script because we don't want to define the symbol if we
5553 are not creating a global offset table. */
5555 if (! (_bfd_generic_link_add_one_symbol
5556 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
5557 (bfd_vma
) 0, (const char *) NULL
, false,
5558 get_elf_backend_data (abfd
)->collect
,
5559 (struct bfd_link_hash_entry
**) &h
)))
5561 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
5562 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5563 h
->type
= STT_OBJECT
;
5566 && ! bfd_elf64_link_record_dynamic_symbol (info
, h
))
5569 /* The first several global offset table entries are reserved. */
5570 s
->_raw_size
= MIPS_RESERVED_GOTNO
* (get_elf_backend_data (abfd
)->s
->arch_size
/ 8);
5572 g
= (struct mips_elf64_got_info
*) bfd_alloc (abfd
,
5573 sizeof (struct mips_elf64_got_info
));
5576 g
->global_gotsym
= NULL
;
5577 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
5578 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
5579 if (elf_section_data (s
) == NULL
)
5582 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
5583 if (elf_section_data (s
) == NULL
)
5586 elf_section_data (s
)->tdata
= (PTR
) g
;
5587 elf_section_data (s
)->this_hdr
.sh_flags
5588 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
5593 /* If H is a symbol that needs a global GOT entry, but has a dynamic
5594 symbol table index lower than any we've seen to date, record it for
5598 mips_elf64_record_global_got_symbol (h
, info
, g
)
5599 struct elf_link_hash_entry
*h
;
5600 struct bfd_link_info
*info
;
5601 struct mips_elf64_got_info
*g ATTRIBUTE_UNUSED
;
5603 /* A global symbol in the GOT must also be in the dynamic symbol
5605 if (h
->dynindx
== -1
5606 && !bfd_elf64_link_record_dynamic_symbol (info
, h
))
5609 /* If we've already marked this entry as needing GOT space, we don't
5610 need to do it again. */
5611 if (h
->got
.offset
!= (bfd_vma
) - 1)
5614 /* By setting this to a value other than -1, we are indicating that
5615 there needs to be a GOT entry for H. Avoid using zero, as the
5616 generic ELF copy_indirect_symbol tests for <= 0. */
5622 /* Returns the .msym section for ABFD, creating it if it does not
5623 already exist. Returns NULL to indicate error. */
5626 mips_elf64_create_msym_section (abfd
)
5631 s
= bfd_get_section_by_name (abfd
, ".msym");
5634 s
= bfd_make_section (abfd
, ".msym");
5636 || !bfd_set_section_flags (abfd
, s
,
5640 | SEC_LINKER_CREATED
5642 || !bfd_set_section_alignment (abfd
, s
, 3))
5649 /* Add room for N relocations to the .rel.dyn section in ABFD. */
5652 mips_elf64_allocate_dynamic_relocations (abfd
, n
)
5658 s
= bfd_get_section_by_name (abfd
, ".rel.dyn");
5659 BFD_ASSERT (s
!= NULL
);
5661 if (s
->_raw_size
== 0)
5663 /* Make room for a null element. */
5664 s
->_raw_size
+= get_elf_backend_data (abfd
)->s
->sizeof_rel
;
5667 s
->_raw_size
+= n
* get_elf_backend_data (abfd
)->s
->sizeof_rel
;
5670 /* Look through the relocs for a section during the first phase, and
5671 allocate space in the global offset table. */
5674 mips_elf64_check_relocs (abfd
, info
, sec
, relocs
)
5676 struct bfd_link_info
*info
;
5678 const Elf_Internal_Rela
*relocs
;
5682 Elf_Internal_Shdr
*symtab_hdr
;
5683 struct elf_link_hash_entry
**sym_hashes
;
5684 struct mips_elf64_got_info
*g
;
5686 const Elf_Internal_Rela
*rel
;
5687 const Elf_Internal_Rela
*rel_end
;
5690 struct elf_backend_data
*bed
;
5692 if (info
->relocateable
)
5695 dynobj
= elf_hash_table (info
)->dynobj
;
5696 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5697 sym_hashes
= elf_sym_hashes (abfd
);
5698 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
5700 /* Check for the mips16 stub sections. */
5702 name
= bfd_get_section_name (abfd
, sec
);
5703 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
5705 unsigned long r_symndx
;
5707 /* Look at the relocation information to figure out which symbol
5710 r_symndx
= ELF64_R_SYM (relocs
->r_info
);
5712 if (r_symndx
< extsymoff
5713 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
5717 /* This stub is for a local symbol. This stub will only be
5718 needed if there is some relocation in this BFD, other
5719 than a 16 bit function call, which refers to this symbol. */
5720 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5722 Elf_Internal_Rela
*sec_relocs
;
5723 const Elf_Internal_Rela
*r
, *rend
;
5725 /* We can ignore stub sections when looking for relocs. */
5726 if ((o
->flags
& SEC_RELOC
) == 0
5727 || o
->reloc_count
== 0
5728 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
5729 sizeof FN_STUB
- 1) == 0
5730 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
5731 sizeof CALL_STUB
- 1) == 0
5732 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
5733 sizeof CALL_FP_STUB
- 1) == 0)
5736 sec_relocs
= (_bfd_elf64_link_read_relocs
5737 (abfd
, o
, (PTR
) NULL
,
5738 (Elf_Internal_Rela
*) NULL
,
5739 info
->keep_memory
));
5740 if (sec_relocs
== NULL
)
5743 rend
= sec_relocs
+ o
->reloc_count
;
5744 for (r
= sec_relocs
; r
< rend
; r
++)
5745 if (ELF64_R_SYM (r
->r_info
) == r_symndx
5746 && ELF64_R_TYPE (r
->r_info
) != R_MIPS16_26
)
5749 if (! info
->keep_memory
)
5758 /* There is no non-call reloc for this stub, so we do
5759 not need it. Since this function is called before
5760 the linker maps input sections to output sections, we
5761 can easily discard it by setting the SEC_EXCLUDE
5763 sec
->flags
|= SEC_EXCLUDE
;
5767 /* Record this stub in an array of local symbol stubs for
5769 if (elf_tdata (abfd
)->local_stubs
== NULL
)
5771 unsigned long symcount
;
5775 if (elf_bad_symtab (abfd
))
5776 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
5778 symcount
= symtab_hdr
->sh_info
;
5779 amt
= symcount
* sizeof (asection
*);
5780 n
= (asection
**) bfd_zalloc (abfd
, amt
);
5783 elf_tdata (abfd
)->local_stubs
= n
;
5786 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
5788 /* We don't need to set mips16_stubs_seen in this case.
5789 That flag is used to see whether we need to look through
5790 the global symbol table for stubs. We don't need to set
5791 it here, because we just have a local stub. */
5795 struct mips_elf64_link_hash_entry
*h
;
5797 h
= ((struct mips_elf64_link_hash_entry
*)
5798 sym_hashes
[r_symndx
- extsymoff
]);
5800 /* H is the symbol this stub is for. */
5803 mips_elf64_hash_table (info
)->mips16_stubs_seen
= true;
5806 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
5807 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5809 unsigned long r_symndx
;
5810 struct mips_elf64_link_hash_entry
*h
;
5813 /* Look at the relocation information to figure out which symbol
5816 r_symndx
= ELF64_R_SYM (relocs
->r_info
);
5818 if (r_symndx
< extsymoff
5819 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
5821 /* This stub was actually built for a static symbol defined
5822 in the same file. We assume that all static symbols in
5823 mips16 code are themselves mips16, so we can simply
5824 discard this stub. Since this function is called before
5825 the linker maps input sections to output sections, we can
5826 easily discard it by setting the SEC_EXCLUDE flag. */
5827 sec
->flags
|= SEC_EXCLUDE
;
5831 h
= ((struct mips_elf64_link_hash_entry
*)
5832 sym_hashes
[r_symndx
- extsymoff
]);
5834 /* H is the symbol this stub is for. */
5836 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5837 loc
= &h
->call_fp_stub
;
5839 loc
= &h
->call_stub
;
5841 /* If we already have an appropriate stub for this function, we
5842 don't need another one, so we can discard this one. Since
5843 this function is called before the linker maps input sections
5844 to output sections, we can easily discard it by setting the
5845 SEC_EXCLUDE flag. We can also discard this section if we
5846 happen to already know that this is a mips16 function; it is
5847 not necessary to check this here, as it is checked later, but
5848 it is slightly faster to check now. */
5849 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
5851 sec
->flags
|= SEC_EXCLUDE
;
5856 mips_elf64_hash_table (info
)->mips16_stubs_seen
= true;
5866 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5871 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5872 g
= (struct mips_elf64_got_info
*) elf_section_data (sgot
)->tdata
;
5873 BFD_ASSERT (g
!= NULL
);
5878 bed
= get_elf_backend_data (abfd
);
5879 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
5880 for (rel
= relocs
; rel
< rel_end
; ++rel
)
5882 unsigned long r_symndx
;
5884 struct elf_link_hash_entry
*h
;
5886 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5887 r_type
= ELF64_MIPS_R_TYPE (rel
->r_info
);
5889 if (r_symndx
< extsymoff
)
5891 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
5893 (*_bfd_error_handler
)
5894 (_("%s: Malformed reloc detected for section %s"),
5895 bfd_archive_filename (abfd
), name
);
5896 bfd_set_error (bfd_error_bad_value
);
5901 h
= sym_hashes
[r_symndx
- extsymoff
];
5903 /* This may be an indirect symbol created because of a version. */
5906 while (h
->root
.type
== bfd_link_hash_indirect
)
5907 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5911 /* Some relocs require a global offset table. */
5912 if (dynobj
== NULL
|| sgot
== NULL
)
5918 case R_MIPS_CALL_HI16
:
5919 case R_MIPS_CALL_LO16
:
5920 case R_MIPS_GOT_HI16
:
5921 case R_MIPS_GOT_LO16
:
5922 case R_MIPS_GOT_PAGE
:
5923 case R_MIPS_GOT_OFST
:
5924 case R_MIPS_GOT_DISP
:
5926 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
5927 if (! mips_elf64_create_got_section (dynobj
, info
))
5929 g
= _mips_elf64_got_info (dynobj
, &sgot
);
5936 && (info
->shared
|| h
!= NULL
)
5937 && (sec
->flags
& SEC_ALLOC
) != 0)
5938 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
5946 if (!h
&& (r_type
== R_MIPS_CALL_LO16
5947 || r_type
== R_MIPS_GOT_LO16
5948 || r_type
== R_MIPS_GOT_DISP
))
5950 /* We may need a local GOT entry for this relocation. We
5951 don't count R_MIPS_GOT_PAGE because we can estimate the
5952 maximum number of pages needed by looking at the size of
5953 the segment. Similar comments apply to R_MIPS_GOT16 and
5954 R_MIPS_CALL16. We don't count R_MIPS_GOT_HI16, or
5955 R_MIPS_CALL_HI16 because these are always followed by an
5956 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16.
5958 This estimation is very conservative since we can merge
5959 duplicate entries in the GOT. In order to be less
5960 conservative, we could actually build the GOT here,
5961 rather than in relocate_section. */
5963 sgot
->_raw_size
+= get_elf_backend_data (dynobj
)->s
->arch_size
/ 8;
5971 (*_bfd_error_handler
)
5972 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
5973 bfd_archive_filename (abfd
), (unsigned long) rel
->r_offset
);
5974 bfd_set_error (bfd_error_bad_value
);
5979 case R_MIPS_CALL_HI16
:
5980 case R_MIPS_CALL_LO16
:
5983 /* This symbol requires a global offset table entry. */
5984 if (!mips_elf64_record_global_got_symbol (h
, info
, g
))
5987 /* We need a stub, not a plt entry for the undefined
5988 function. But we record it as if it needs plt. See
5989 elf_adjust_dynamic_symbol in elflink.h. */
5990 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
5996 case R_MIPS_GOT_HI16
:
5997 case R_MIPS_GOT_LO16
:
5998 case R_MIPS_GOT_DISP
:
5999 /* This symbol requires a global offset table entry. */
6000 if (h
&& !mips_elf64_record_global_got_symbol (h
, info
, g
))
6007 if ((info
->shared
|| h
!= NULL
)
6008 && (sec
->flags
& SEC_ALLOC
) != 0)
6012 const char *name
= ".rel.dyn";
6014 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6017 sreloc
= bfd_make_section (dynobj
, name
);
6019 || ! bfd_set_section_flags (dynobj
, sreloc
,
6024 | SEC_LINKER_CREATED
6026 || ! bfd_set_section_alignment (dynobj
, sreloc
,
6031 #define MIPS_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
6034 /* When creating a shared object, we must copy these
6035 reloc types into the output file as R_MIPS_REL32
6036 relocs. We make room for this reloc in the
6037 .rel.dyn reloc section. */
6038 mips_elf64_allocate_dynamic_relocations (dynobj
, 1);
6039 if ((sec
->flags
& MIPS_READONLY_SECTION
)
6040 == MIPS_READONLY_SECTION
)
6041 /* We tell the dynamic linker that there are
6042 relocations against the text segment. */
6043 info
->flags
|= DF_TEXTREL
;
6047 struct mips_elf64_link_hash_entry
*hmips
;
6049 /* We only need to copy this reloc if the symbol is
6050 defined in a dynamic object. */
6051 hmips
= (struct mips_elf64_link_hash_entry
*) h
;
6052 ++hmips
->possibly_dynamic_relocs
;
6053 if ((sec
->flags
& MIPS_READONLY_SECTION
)
6054 == MIPS_READONLY_SECTION
)
6055 /* We need it to tell the dynamic linker if there
6056 are relocations against the text segment. */
6057 hmips
->readonly_reloc
= true;
6060 /* Even though we don't directly need a GOT entry for
6061 this symbol, a symbol must have a dynamic symbol
6062 table index greater that DT_MIPS_GOTSYM if there are
6063 dynamic relocations against it. */
6065 && !mips_elf64_record_global_got_symbol (h
, info
, g
))
6071 case R_MIPS_GPREL16
:
6072 case R_MIPS_LITERAL
:
6073 case R_MIPS_GPREL32
:
6076 /* This relocation describes the C++ object vtable hierarchy.
6077 Reconstruct it for later use during GC. */
6078 case R_MIPS_GNU_VTINHERIT
:
6079 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6083 /* This relocation describes which C++ vtable entries are actually
6084 used. Record for later use during GC. */
6085 case R_MIPS_GNU_VTENTRY
:
6086 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
6098 /* Structure used to pass information to mips_elf64_output_extsym. */
6103 struct bfd_link_info
*info
;
6104 struct ecoff_debug_info
*debug
;
6105 const struct ecoff_debug_swap
*swap
;
6109 /* This routine is used to write out ECOFF debugging external symbol
6110 information. It is called via mips_elf64_link_hash_traverse. The
6111 ECOFF external symbol information must match the ELF external
6112 symbol information. Unfortunately, at this point we don't know
6113 whether a symbol is required by reloc information, so the two
6114 tables may wind up being different. We must sort out the external
6115 symbol information before we can set the final size of the .mdebug
6116 section, and we must set the size of the .mdebug section before we
6117 can relocate any sections, and we can't know which symbols are
6118 required by relocation until we relocate the sections.
6119 Fortunately, it is relatively unlikely that any symbol will be
6120 stripped but required by a reloc. In particular, it can not happen
6121 when generating a final executable. */
6124 mips_elf64_output_extsym (h
, data
)
6125 struct mips_elf64_link_hash_entry
*h
;
6128 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
6130 asection
*sec
, *output_section
;
6132 if (h
->root
.indx
== -2)
6134 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
6135 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
6136 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
6137 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
6139 else if (einfo
->info
->strip
== strip_all
6140 || (einfo
->info
->strip
== strip_some
6141 && bfd_hash_lookup (einfo
->info
->keep_hash
,
6142 h
->root
.root
.root
.string
,
6143 false, false) == NULL
))
6151 if (h
->esym
.ifd
== -2)
6154 h
->esym
.cobol_main
= 0;
6155 h
->esym
.weakext
= 0;
6156 h
->esym
.reserved
= 0;
6157 h
->esym
.ifd
= ifdNil
;
6158 h
->esym
.asym
.value
= 0;
6159 h
->esym
.asym
.st
= stGlobal
;
6161 if (h
->root
.root
.type
== bfd_link_hash_undefined
6162 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
6166 /* Use undefined class. Also, set class and type for some
6168 name
= h
->root
.root
.root
.string
;
6169 h
->esym
.asym
.sc
= scUndefined
;
6171 else if (h
->root
.root
.type
!= bfd_link_hash_defined
6172 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
6173 h
->esym
.asym
.sc
= scAbs
;
6178 sec
= h
->root
.root
.u
.def
.section
;
6179 output_section
= sec
->output_section
;
6181 /* When making a shared library and symbol h is the one from
6182 the another shared library, OUTPUT_SECTION may be null. */
6183 if (output_section
== NULL
)
6184 h
->esym
.asym
.sc
= scUndefined
;
6187 name
= bfd_section_name (output_section
->owner
, output_section
);
6189 if (strcmp (name
, ".text") == 0)
6190 h
->esym
.asym
.sc
= scText
;
6191 else if (strcmp (name
, ".data") == 0)
6192 h
->esym
.asym
.sc
= scData
;
6193 else if (strcmp (name
, ".sdata") == 0)
6194 h
->esym
.asym
.sc
= scSData
;
6195 else if (strcmp (name
, ".rodata") == 0
6196 || strcmp (name
, ".rdata") == 0)
6197 h
->esym
.asym
.sc
= scRData
;
6198 else if (strcmp (name
, ".bss") == 0)
6199 h
->esym
.asym
.sc
= scBss
;
6200 else if (strcmp (name
, ".sbss") == 0)
6201 h
->esym
.asym
.sc
= scSBss
;
6202 else if (strcmp (name
, ".init") == 0)
6203 h
->esym
.asym
.sc
= scInit
;
6204 else if (strcmp (name
, ".fini") == 0)
6205 h
->esym
.asym
.sc
= scFini
;
6207 h
->esym
.asym
.sc
= scAbs
;
6211 h
->esym
.asym
.reserved
= 0;
6212 h
->esym
.asym
.index
= indexNil
;
6215 if (h
->root
.root
.type
== bfd_link_hash_common
)
6216 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
6217 else if (h
->root
.root
.type
== bfd_link_hash_defined
6218 || h
->root
.root
.type
== bfd_link_hash_defweak
)
6220 if (h
->esym
.asym
.sc
== scCommon
)
6221 h
->esym
.asym
.sc
= scBss
;
6222 else if (h
->esym
.asym
.sc
== scSCommon
)
6223 h
->esym
.asym
.sc
= scSBss
;
6225 sec
= h
->root
.root
.u
.def
.section
;
6226 output_section
= sec
->output_section
;
6227 if (output_section
!= NULL
)
6228 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
6229 + sec
->output_offset
6230 + output_section
->vma
);
6232 h
->esym
.asym
.value
= 0;
6234 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
6236 struct mips_elf64_link_hash_entry
*hd
= h
;
6237 boolean no_fn_stub
= h
->no_fn_stub
;
6239 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
6241 hd
= (struct mips_elf64_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
6242 no_fn_stub
= no_fn_stub
|| hd
->no_fn_stub
;
6247 /* Set type and value for a symbol with a function stub. */
6248 h
->esym
.asym
.st
= stProc
;
6249 sec
= hd
->root
.root
.u
.def
.section
;
6251 h
->esym
.asym
.value
= 0;
6254 output_section
= sec
->output_section
;
6255 if (output_section
!= NULL
)
6256 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
6257 + sec
->output_offset
6258 + output_section
->vma
);
6260 h
->esym
.asym
.value
= 0;
6268 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
6269 h
->root
.root
.root
.string
,
6272 einfo
->failed
= true;
6279 /* Swap an entry in a .gptab section. Note that these routines rely
6280 on the equivalence of the two elements of the union. */
6283 mips_elf64_swap_gptab_in (abfd
, ex
, in
)
6285 const Elf32_External_gptab
*ex
;
6288 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
6289 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
6293 mips_elf64_swap_gptab_out (abfd
, in
, ex
)
6295 const Elf32_gptab
*in
;
6296 Elf32_External_gptab
*ex
;
6298 H_PUT_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
6299 ex
->gt_entry
.gt_g_value
);
6300 H_PUT_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
6301 ex
->gt_entry
.gt_bytes
);
6304 /* A comparison routine used to sort .gptab entries. */
6307 gptab_compare (p1
, p2
)
6311 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
6312 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
6314 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
6317 /* We need to use a special link routine to handle the .mdebug section.
6318 We need to merge all instances of this section together, not write
6319 them all out sequentially. */
6322 mips_elf64_final_link (abfd
, info
)
6324 struct bfd_link_info
*info
;
6328 struct bfd_link_order
*p
;
6329 asection
*mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
6330 struct ecoff_debug_info debug
;
6331 const struct ecoff_debug_swap
*swap
6332 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
6333 HDRR
*symhdr
= &debug
.symbolic_header
;
6334 PTR mdebug_handle
= NULL
;
6338 static const char * const secname
[] =
6339 { ".text", ".init", ".fini", ".data",
6340 ".rodata", ".sdata", ".sbss", ".bss" };
6341 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
6342 scRData
, scSData
, scSBss
, scBss
};
6344 /* If all the things we linked together were PIC, but we're
6345 producing an executable (rather than a shared object), then the
6346 resulting file is CPIC (i.e., it calls PIC code.) */
6348 && !info
->relocateable
6349 && elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
6351 elf_elfheader (abfd
)->e_flags
&= ~EF_MIPS_PIC
;
6352 elf_elfheader (abfd
)->e_flags
|= EF_MIPS_CPIC
;
6355 /* We'd carefully arranged the dynamic symbol indices, and then the
6356 generic size_dynamic_sections renumbered them out from under us.
6357 Rather than trying somehow to prevent the renumbering, just do
6359 if (elf_hash_table (info
)->dynamic_sections_created
)
6363 struct mips_elf64_got_info
*g
;
6365 /* When we resort, we must tell mips_elf64_sort_hash_table what
6366 the lowest index it may use is. That's the number of section
6367 symbols we're going to add. The generic ELF linker only
6368 adds these symbols when building a shared object. Note that
6369 we count the sections after (possibly) removing the .options
6371 if (!mips_elf64_sort_hash_table (info
, (info
->shared
6372 ? bfd_count_sections (abfd
) + 1
6376 /* Make sure we didn't grow the global .got region. */
6377 dynobj
= elf_hash_table (info
)->dynobj
;
6378 got
= bfd_get_section_by_name (dynobj
, ".got");
6379 g
= (struct mips_elf64_got_info
*) elf_section_data (got
)->tdata
;
6381 if (g
->global_gotsym
!= NULL
)
6382 BFD_ASSERT ((elf_hash_table (info
)->dynsymcount
6383 - g
->global_gotsym
->dynindx
)
6384 <= g
->global_gotno
);
6387 /* We include .MIPS.options, even though we don't process it quite right.
6388 (Some entries are supposed to be merged.) At IRIX6 empirically we seem
6389 to be better off including it than not. */
6390 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
6392 if (strcmp ((*secpp
)->name
, ".MIPS.options") == 0)
6394 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
6395 if (p
->type
== bfd_indirect_link_order
)
6396 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
6397 (*secpp
)->link_order_head
= NULL
;
6398 bfd_section_list_remove (abfd
, secpp
);
6399 --abfd
->section_count
;
6405 /* Get a value for the GP register. */
6406 if (elf_gp (abfd
) == 0)
6408 struct bfd_link_hash_entry
*h
;
6410 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
6411 if (h
!= (struct bfd_link_hash_entry
*) NULL
6412 && h
->type
== bfd_link_hash_defined
)
6413 elf_gp (abfd
) = (h
->u
.def
.value
6414 + h
->u
.def
.section
->output_section
->vma
6415 + h
->u
.def
.section
->output_offset
);
6416 else if (info
->relocateable
)
6418 bfd_vma lo
= MINUS_ONE
;
6420 /* Find the GP-relative section with the lowest offset. */
6421 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6423 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
6426 /* And calculate GP relative to that. */
6427 elf_gp (abfd
) = (lo
+ 0x7ff0);
6431 /* If the relocate_section function needs to do a reloc
6432 involving the GP value, it should make a reloc_dangerous
6433 callback to warn that GP is not defined. */
6437 /* Go through the sections and collect the .mdebug information. */
6439 gptab_data_sec
= NULL
;
6440 gptab_bss_sec
= NULL
;
6441 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
6443 if (strcmp (o
->name
, ".mdebug") == 0)
6445 struct extsym_info einfo
;
6448 /* We have found the .mdebug section in the output file.
6449 Look through all the link_orders comprising it and merge
6450 the information together. */
6451 symhdr
->magic
= swap
->sym_magic
;
6452 /* FIXME: What should the version stamp be? */
6454 symhdr
->ilineMax
= 0;
6458 symhdr
->isymMax
= 0;
6459 symhdr
->ioptMax
= 0;
6460 symhdr
->iauxMax
= 0;
6462 symhdr
->issExtMax
= 0;
6465 symhdr
->iextMax
= 0;
6467 /* We accumulate the debugging information itself in the
6468 debug_info structure. */
6470 debug
.external_dnr
= NULL
;
6471 debug
.external_pdr
= NULL
;
6472 debug
.external_sym
= NULL
;
6473 debug
.external_opt
= NULL
;
6474 debug
.external_aux
= NULL
;
6476 debug
.ssext
= debug
.ssext_end
= NULL
;
6477 debug
.external_fdr
= NULL
;
6478 debug
.external_rfd
= NULL
;
6479 debug
.external_ext
= debug
.external_ext_end
= NULL
;
6481 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
6482 if (mdebug_handle
== (PTR
) NULL
)
6486 esym
.cobol_main
= 0;
6490 esym
.asym
.iss
= issNil
;
6491 esym
.asym
.st
= stLocal
;
6492 esym
.asym
.reserved
= 0;
6493 esym
.asym
.index
= indexNil
;
6495 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
6497 esym
.asym
.sc
= sc
[i
];
6498 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
6501 esym
.asym
.value
= s
->vma
;
6502 last
= s
->vma
+ s
->_raw_size
;
6505 esym
.asym
.value
= last
;
6506 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
6511 for (p
= o
->link_order_head
;
6512 p
!= (struct bfd_link_order
*) NULL
;
6515 asection
*input_section
;
6517 const struct ecoff_debug_swap
*input_swap
;
6518 struct ecoff_debug_info input_debug
;
6522 if (p
->type
!= bfd_indirect_link_order
)
6524 if (p
->type
== bfd_data_link_order
)
6529 input_section
= p
->u
.indirect
.section
;
6530 input_bfd
= input_section
->owner
;
6532 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
6533 || (get_elf_backend_data (input_bfd
)
6534 ->elf_backend_ecoff_debug_swap
) == NULL
)
6536 /* I don't know what a non MIPS ELF bfd would be
6537 doing with a .mdebug section, but I don't really
6538 want to deal with it. */
6542 input_swap
= (get_elf_backend_data (input_bfd
)
6543 ->elf_backend_ecoff_debug_swap
);
6545 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
6547 /* The ECOFF linking code expects that we have already
6548 read in the debugging information and set up an
6549 ecoff_debug_info structure, so we do that now. */
6550 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
6554 if (! (bfd_ecoff_debug_accumulate
6555 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
6556 &input_debug
, input_swap
, info
)))
6559 /* Loop through the external symbols. For each one with
6560 interesting information, try to find the symbol in
6561 the linker global hash table and save the information
6562 for the output external symbols. */
6563 eraw_src
= input_debug
.external_ext
;
6564 eraw_end
= (eraw_src
6565 + (input_debug
.symbolic_header
.iextMax
6566 * input_swap
->external_ext_size
));
6568 eraw_src
< eraw_end
;
6569 eraw_src
+= input_swap
->external_ext_size
)
6573 struct mips_elf64_link_hash_entry
*h
;
6575 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
6576 if (ext
.asym
.sc
== scNil
6577 || ext
.asym
.sc
== scUndefined
6578 || ext
.asym
.sc
== scSUndefined
)
6581 name
= input_debug
.ssext
+ ext
.asym
.iss
;
6582 h
= mips_elf64_link_hash_lookup (mips_elf64_hash_table (info
),
6583 name
, false, false, true);
6584 if (h
== NULL
|| h
->esym
.ifd
!= -2)
6590 < input_debug
.symbolic_header
.ifdMax
);
6591 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
6597 /* Free up the information we just read. */
6598 free (input_debug
.line
);
6599 free (input_debug
.external_dnr
);
6600 free (input_debug
.external_pdr
);
6601 free (input_debug
.external_sym
);
6602 free (input_debug
.external_opt
);
6603 free (input_debug
.external_aux
);
6604 free (input_debug
.ss
);
6605 free (input_debug
.ssext
);
6606 free (input_debug
.external_fdr
);
6607 free (input_debug
.external_rfd
);
6608 free (input_debug
.external_ext
);
6610 /* Hack: reset the SEC_HAS_CONTENTS flag so that
6611 elf_link_input_bfd ignores this section. */
6612 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
6615 /* Build the external symbol information. */
6618 einfo
.debug
= &debug
;
6620 einfo
.failed
= false;
6621 mips_elf64_link_hash_traverse (mips_elf64_hash_table (info
),
6622 mips_elf64_output_extsym
,
6627 /* Set the size of the .mdebug section. */
6628 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
6630 /* Skip this section later on (I don't think this currently
6631 matters, but someday it might). */
6632 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
6637 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
6639 const char *subname
;
6642 Elf32_External_gptab
*ext_tab
;
6645 /* The .gptab.sdata and .gptab.sbss sections hold
6646 information describing how the small data area would
6647 change depending upon the -G switch. These sections
6648 not used in executables files. */
6649 if (! info
->relocateable
)
6653 for (p
= o
->link_order_head
;
6654 p
!= (struct bfd_link_order
*) NULL
;
6657 asection
*input_section
;
6659 if (p
->type
!= bfd_indirect_link_order
)
6661 if (p
->type
== bfd_data_link_order
)
6666 input_section
= p
->u
.indirect
.section
;
6668 /* Hack: reset the SEC_HAS_CONTENTS flag so that
6669 elf_link_input_bfd ignores this section. */
6670 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
6673 /* Skip this section later on (I don't think this
6674 currently matters, but someday it might). */
6675 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
6677 /* Really remove the section. */
6678 for (secpp
= &abfd
->sections
;
6680 secpp
= &(*secpp
)->next
)
6682 bfd_section_list_remove (abfd
, secpp
);
6683 --abfd
->section_count
;
6688 /* There is one gptab for initialized data, and one for
6689 uninitialized data. */
6690 if (strcmp (o
->name
, ".gptab.sdata") == 0)
6692 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
6696 (*_bfd_error_handler
)
6697 (_("%s: illegal section name `%s'"),
6698 bfd_archive_filename (abfd
), o
->name
);
6699 bfd_set_error (bfd_error_nonrepresentable_section
);
6703 /* The linker script always combines .gptab.data and
6704 .gptab.sdata into .gptab.sdata, and likewise for
6705 .gptab.bss and .gptab.sbss. It is possible that there is
6706 no .sdata or .sbss section in the output file, in which
6707 case we must change the name of the output section. */
6708 subname
= o
->name
+ sizeof ".gptab" - 1;
6709 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
6711 if (o
== gptab_data_sec
)
6712 o
->name
= ".gptab.data";
6714 o
->name
= ".gptab.bss";
6715 subname
= o
->name
+ sizeof ".gptab" - 1;
6716 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
6719 /* Set up the first entry. */
6721 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
6724 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
6725 tab
[0].gt_header
.gt_unused
= 0;
6727 /* Combine the input sections. */
6728 for (p
= o
->link_order_head
;
6729 p
!= (struct bfd_link_order
*) NULL
;
6732 asection
*input_section
;
6736 bfd_size_type gpentry
;
6738 if (p
->type
!= bfd_indirect_link_order
)
6740 if (p
->type
== bfd_data_link_order
)
6745 input_section
= p
->u
.indirect
.section
;
6746 input_bfd
= input_section
->owner
;
6748 /* Combine the gptab entries for this input section one
6749 by one. We know that the input gptab entries are
6750 sorted by ascending -G value. */
6751 size
= bfd_section_size (input_bfd
, input_section
);
6753 for (gpentry
= sizeof (Elf32_External_gptab
);
6755 gpentry
+= sizeof (Elf32_External_gptab
))
6757 Elf32_External_gptab ext_gptab
;
6758 Elf32_gptab int_gptab
;
6764 if (! (bfd_get_section_contents
6765 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
6766 gpentry
, sizeof (Elf32_External_gptab
))))
6772 mips_elf64_swap_gptab_in (input_bfd
, &ext_gptab
,
6774 val
= int_gptab
.gt_entry
.gt_g_value
;
6775 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
6778 for (look
= 1; look
< c
; look
++)
6780 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
6781 tab
[look
].gt_entry
.gt_bytes
+= add
;
6783 if (tab
[look
].gt_entry
.gt_g_value
== val
)
6789 Elf32_gptab
*new_tab
;
6792 /* We need a new table entry. */
6793 new_tab
= ((Elf32_gptab
*)
6794 bfd_realloc ((PTR
) tab
,
6795 (c
+ 1) * sizeof (Elf32_gptab
)));
6796 if (new_tab
== NULL
)
6802 tab
[c
].gt_entry
.gt_g_value
= val
;
6803 tab
[c
].gt_entry
.gt_bytes
= add
;
6805 /* Merge in the size for the next smallest -G
6806 value, since that will be implied by this new
6809 for (look
= 1; look
< c
; look
++)
6811 if (tab
[look
].gt_entry
.gt_g_value
< val
6813 || (tab
[look
].gt_entry
.gt_g_value
6814 > tab
[max
].gt_entry
.gt_g_value
)))
6818 tab
[c
].gt_entry
.gt_bytes
+=
6819 tab
[max
].gt_entry
.gt_bytes
;
6824 last
= int_gptab
.gt_entry
.gt_bytes
;
6827 /* Hack: reset the SEC_HAS_CONTENTS flag so that
6828 elf_link_input_bfd ignores this section. */
6829 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
6832 /* The table must be sorted by -G value. */
6834 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
6836 /* Swap out the table. */
6837 ext_tab
= ((Elf32_External_gptab
*)
6838 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
6839 if (ext_tab
== NULL
)
6845 for (i
= 0; i
< c
; i
++)
6846 mips_elf64_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
6849 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
6850 o
->contents
= (bfd_byte
*) ext_tab
;
6852 /* Skip this section later on (I don't think this currently
6853 matters, but someday it might). */
6854 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
6858 /* Invoke the regular ELF backend linker to do all the work. */
6859 if (!bfd_elf64_bfd_final_link (abfd
, info
))
6862 /* Now write out the computed sections. */
6863 if (mdebug_sec
!= (asection
*) NULL
)
6865 BFD_ASSERT (abfd
->output_has_begun
);
6866 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
6868 mdebug_sec
->filepos
))
6871 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
6873 if (gptab_data_sec
!= (asection
*) NULL
)
6875 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
6876 gptab_data_sec
->contents
,
6878 gptab_data_sec
->_raw_size
))
6882 if (gptab_bss_sec
!= (asection
*) NULL
)
6884 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
6885 gptab_bss_sec
->contents
,
6887 gptab_bss_sec
->_raw_size
))
6894 /* ECOFF swapping routines. These are used when dealing with the
6895 .mdebug section, which is in the ECOFF debugging format. */
6896 static const struct ecoff_debug_swap mips_elf64_ecoff_debug_swap
=
6898 /* Symbol table magic number. */
6900 /* Alignment of debugging information. E.g., 4. */
6902 /* Sizes of external symbolic information. */
6903 sizeof (struct hdr_ext
),
6904 sizeof (struct dnr_ext
),
6905 sizeof (struct pdr_ext
),
6906 sizeof (struct sym_ext
),
6907 sizeof (struct opt_ext
),
6908 sizeof (struct fdr_ext
),
6909 sizeof (struct rfd_ext
),
6910 sizeof (struct ext_ext
),
6911 /* Functions to swap in external symbolic data. */
6920 _bfd_ecoff_swap_tir_in
,
6921 _bfd_ecoff_swap_rndx_in
,
6922 /* Functions to swap out external symbolic data. */
6931 _bfd_ecoff_swap_tir_out
,
6932 _bfd_ecoff_swap_rndx_out
,
6933 /* Function to read in symbolic data. */
6934 _bfd_mips_elf_read_ecoff_info
6937 /* Relocations in the 64 bit MIPS ELF ABI are more complex than in
6938 standard ELF. This structure is used to redirect the relocation
6939 handling routines. */
6941 const struct elf_size_info mips_elf64_size_info
=
6943 sizeof (Elf64_External_Ehdr
),
6944 sizeof (Elf64_External_Phdr
),
6945 sizeof (Elf64_External_Shdr
),
6946 sizeof (Elf64_Mips_External_Rel
),
6947 sizeof (Elf64_Mips_External_Rela
),
6948 sizeof (Elf64_External_Sym
),
6949 sizeof (Elf64_External_Dyn
),
6950 sizeof (Elf_External_Note
),
6951 4, /* hash-table entry size */
6952 3, /* internal relocations per external relocations */
6957 bfd_elf64_write_out_phdrs
,
6958 bfd_elf64_write_shdrs_and_ehdr
,
6959 mips_elf64_write_relocs
,
6960 bfd_elf64_swap_symbol_out
,
6961 mips_elf64_slurp_reloc_table
,
6962 bfd_elf64_slurp_symbol_table
,
6963 bfd_elf64_swap_dyn_in
,
6964 bfd_elf64_swap_dyn_out
,
6965 mips_elf64_be_swap_reloc_in
,
6966 mips_elf64_be_swap_reloc_out
,
6967 mips_elf64_be_swap_reloca_in
,
6968 mips_elf64_be_swap_reloca_out
6971 #define ELF_ARCH bfd_arch_mips
6972 #define ELF_MACHINE_CODE EM_MIPS
6974 #define ELF_MAXPAGESIZE 0x1000
6976 #define elf_backend_collect true
6977 #define elf_backend_type_change_ok true
6978 #define elf_backend_can_gc_sections true
6979 #define elf_info_to_howto mips_elf64_info_to_howto_rela
6980 #define elf_info_to_howto_rel mips_elf64_info_to_howto_rel
6981 #define elf_backend_object_p _bfd_mips_elf_object_p
6982 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
6983 #define elf_backend_section_processing _bfd_mips_elf_section_processing
6984 #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
6985 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
6986 #define elf_backend_section_from_bfd_section \
6987 _bfd_mips_elf_section_from_bfd_section
6988 #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
6989 #define elf_backend_link_output_symbol_hook \
6990 _bfd_mips_elf_link_output_symbol_hook
6991 #define elf_backend_create_dynamic_sections \
6992 mips_elf64_create_dynamic_sections
6993 #define elf_backend_check_relocs mips_elf64_check_relocs
6994 #define elf_backend_adjust_dynamic_symbol \
6995 mips_elf64_adjust_dynamic_symbol
6996 #define elf_backend_always_size_sections \
6997 mips_elf64_always_size_sections
6998 #define elf_backend_size_dynamic_sections \
6999 mips_elf64_size_dynamic_sections
7000 #define elf_backend_relocate_section mips_elf64_relocate_section
7001 #define elf_backend_finish_dynamic_symbol \
7002 mips_elf64_finish_dynamic_symbol
7003 #define elf_backend_finish_dynamic_sections \
7004 mips_elf64_finish_dynamic_sections
7005 #define elf_backend_final_write_processing \
7006 _bfd_mips_elf_final_write_processing
7007 #define elf_backend_additional_program_headers \
7008 mips_elf64_additional_program_headers
7009 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
7010 #define elf_backend_gc_mark_hook mips_elf64_gc_mark_hook
7011 #define elf_backend_gc_sweep_hook mips_elf64_gc_sweep_hook
7012 #define elf_backend_ecoff_debug_swap &mips_elf64_ecoff_debug_swap
7013 #define elf_backend_size_info mips_elf64_size_info
7015 #define elf_backend_got_header_size (4 * MIPS_RESERVED_GOTNO)
7016 #define elf_backend_plt_header_size 0
7018 /* MIPS ELF64 can use a mixture of REL and RELA, but some Relocations
7019 * work better/work only in RELA, so we default to this. */
7020 #define elf_backend_may_use_rel_p 1
7021 #define elf_backend_may_use_rela_p 1
7022 #define elf_backend_default_use_rela_p 1
7024 /* We don't set bfd_elf64_bfd_is_local_label_name because the 32-bit
7025 MIPS-specific function only applies to IRIX5, which had no 64-bit
7027 #define bfd_elf64_find_nearest_line _bfd_mips_elf_find_nearest_line
7028 #define bfd_elf64_set_section_contents _bfd_mips_elf_set_section_contents
7029 #define bfd_elf64_bfd_link_hash_table_create \
7030 mips_elf64_link_hash_table_create
7031 #define bfd_elf64_bfd_final_link mips_elf64_final_link
7032 #define bfd_elf64_bfd_merge_private_bfd_data \
7033 _bfd_mips_elf_merge_private_bfd_data
7034 #define bfd_elf64_bfd_set_private_flags _bfd_mips_elf_set_private_flags
7035 #define bfd_elf64_bfd_print_private_bfd_data \
7036 _bfd_mips_elf_print_private_bfd_data
7038 #define bfd_elf64_get_reloc_upper_bound mips_elf64_get_reloc_upper_bound
7039 #define bfd_elf64_bfd_reloc_type_lookup mips_elf64_reloc_type_lookup
7040 #define bfd_elf64_archive_functions
7041 extern boolean bfd_elf64_archive_slurp_armap
7043 extern boolean bfd_elf64_archive_write_armap
7044 PARAMS((bfd
*, unsigned int, struct orl
*, unsigned int, int));
7045 #define bfd_elf64_archive_slurp_extended_name_table \
7046 _bfd_archive_coff_slurp_extended_name_table
7047 #define bfd_elf64_archive_construct_extended_name_table \
7048 _bfd_archive_coff_construct_extended_name_table
7049 #define bfd_elf64_archive_truncate_arname \
7050 _bfd_archive_coff_truncate_arname
7051 #define bfd_elf64_archive_read_ar_hdr _bfd_archive_coff_read_ar_hdr
7052 #define bfd_elf64_archive_openr_next_archived_file \
7053 _bfd_archive_coff_openr_next_archived_file
7054 #define bfd_elf64_archive_get_elt_at_index \
7055 _bfd_archive_coff_get_elt_at_index
7056 #define bfd_elf64_archive_generic_stat_arch_elt \
7057 _bfd_archive_coff_generic_stat_arch_elt
7058 #define bfd_elf64_archive_update_armap_timestamp \
7059 _bfd_archive_coff_update_armap_timestamp
7061 /* The SGI style (n)64 NewABI. */
7062 #define TARGET_LITTLE_SYM bfd_elf64_littlemips_vec
7063 #define TARGET_LITTLE_NAME "elf64-littlemips"
7064 #define TARGET_BIG_SYM bfd_elf64_bigmips_vec
7065 #define TARGET_BIG_NAME "elf64-bigmips"
7067 #include "elf64-target.h"
7069 #define INCLUDED_TARGET_FILE /* More a type of flag. */
7071 /* The SYSV-style 'traditional' (n)64 NewABI. */
7072 #undef TARGET_LITTLE_SYM
7073 #undef TARGET_LITTLE_NAME
7074 #undef TARGET_BIG_SYM
7075 #undef TARGET_BIG_NAME
7077 #define TARGET_LITTLE_SYM bfd_elf64_tradlittlemips_vec
7078 #define TARGET_LITTLE_NAME "elf64-tradlittlemips"
7079 #define TARGET_BIG_SYM bfd_elf64_tradbigmips_vec
7080 #define TARGET_BIG_NAME "elf64-tradbigmips"
7082 /* Include the target file again for this target. */
7083 #include "elf64-target.h"