1 /* FRV-specific support for 32-bit ELF.
2 Copyright 2002, 2003, 2004 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 #include "elf/dwarf2.h"
28 /* Forward declarations. */
29 static bfd_reloc_status_type elf32_frv_relocate_lo16
30 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
31 static bfd_reloc_status_type elf32_frv_relocate_hi16
32 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
33 static bfd_reloc_status_type elf32_frv_relocate_label24
34 PARAMS ((bfd
*, asection
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
35 static bfd_reloc_status_type elf32_frv_relocate_gprel12
36 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
37 bfd_byte
*, bfd_vma
));
38 static bfd_reloc_status_type elf32_frv_relocate_gprelu12
39 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
40 bfd_byte
*, bfd_vma
));
41 static bfd_reloc_status_type elf32_frv_relocate_gprello
42 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
43 bfd_byte
*, bfd_vma
));
44 static bfd_reloc_status_type elf32_frv_relocate_gprelhi
45 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
46 bfd_byte
*, bfd_vma
));
47 static reloc_howto_type
*frv_reloc_type_lookup
48 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
49 static void frv_info_to_howto_rela
50 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
51 static bfd_boolean elf32_frv_relocate_section
52 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
53 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
54 static bfd_boolean elf32_frv_add_symbol_hook
55 PARAMS (( bfd
*, struct bfd_link_info
*, Elf_Internal_Sym
*,
56 const char **, flagword
*, asection
**, bfd_vma
*));
57 static bfd_reloc_status_type frv_final_link_relocate
58 PARAMS ((reloc_howto_type
*, bfd
*, asection
*, bfd_byte
*,
59 Elf_Internal_Rela
*, bfd_vma
));
60 static bfd_boolean elf32_frv_gc_sweep_hook
61 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*, const
62 Elf_Internal_Rela
*));
63 static asection
* elf32_frv_gc_mark_hook
64 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
65 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
66 static bfd_boolean elf32_frv_check_relocs
67 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
68 const Elf_Internal_Rela
*));
69 static int elf32_frv_machine
71 static bfd_boolean elf32_frv_object_p
73 static bfd_boolean frv_elf_set_private_flags
74 PARAMS ((bfd
*, flagword
));
75 static bfd_boolean frv_elf_copy_private_bfd_data
76 PARAMS ((bfd
*, bfd
*));
77 static bfd_boolean frv_elf_merge_private_bfd_data
78 PARAMS ((bfd
*, bfd
*));
79 static bfd_boolean frv_elf_print_private_bfd_data
80 PARAMS ((bfd
*, PTR
));
82 static reloc_howto_type elf32_frv_howto_table
[] =
84 /* This reloc does nothing. */
85 HOWTO (R_FRV_NONE
, /* type */
87 2, /* size (0 = byte, 1 = short, 2 = long) */
89 FALSE
, /* pc_relative */
91 complain_overflow_bitfield
, /* complain_on_overflow */
92 bfd_elf_generic_reloc
, /* special_function */
93 "R_FRV_NONE", /* name */
94 FALSE
, /* partial_inplace */
97 FALSE
), /* pcrel_offset */
99 /* A 32 bit absolute relocation. */
100 HOWTO (R_FRV_32
, /* type */
102 2, /* size (0 = byte, 1 = short, 2 = long) */
104 FALSE
, /* pc_relative */
106 complain_overflow_bitfield
, /* complain_on_overflow */
107 bfd_elf_generic_reloc
, /* special_function */
108 "R_FRV_32", /* name */
109 FALSE
, /* partial_inplace */
110 0xffffffff, /* src_mask */
111 0xffffffff, /* dst_mask */
112 FALSE
), /* pcrel_offset */
114 /* A 16 bit pc-relative relocation. */
115 HOWTO (R_FRV_LABEL16
, /* type */
117 2, /* size (0 = byte, 1 = short, 2 = long) */
119 TRUE
, /* pc_relative */
121 complain_overflow_signed
, /* complain_on_overflow */
122 bfd_elf_generic_reloc
, /* special_function */
123 "R_FRV_LABEL16", /* name */
124 FALSE
, /* partial_inplace */
125 0xffff, /* src_mask */
126 0xffff, /* dst_mask */
127 TRUE
), /* pcrel_offset */
129 /* A 24-bit pc-relative relocation. */
130 HOWTO (R_FRV_LABEL24
, /* type */
132 2, /* size (0 = byte, 1 = short, 2 = long) */
134 TRUE
, /* pc_relative */
136 complain_overflow_bitfield
, /* complain_on_overflow */
137 bfd_elf_generic_reloc
, /* special_function */
138 "R_FRV_LABEL24", /* name */
139 FALSE
, /* partial_inplace */
140 0x7e03ffff, /* src_mask */
141 0x7e03ffff, /* dst_mask */
142 TRUE
), /* pcrel_offset */
144 HOWTO (R_FRV_LO16
, /* type */
146 2, /* size (0 = byte, 1 = short, 2 = long) */
148 FALSE
, /* pc_relative */
150 complain_overflow_dont
, /* complain_on_overflow */
151 bfd_elf_generic_reloc
, /* special_function */
152 "R_FRV_LO16", /* name */
153 FALSE
, /* partial_inplace */
154 0xffff, /* src_mask */
155 0xffff, /* dst_mask */
156 FALSE
), /* pcrel_offset */
158 HOWTO (R_FRV_HI16
, /* type */
160 2, /* size (0 = byte, 1 = short, 2 = long) */
162 FALSE
, /* pc_relative */
164 complain_overflow_dont
, /* complain_on_overflow */
165 bfd_elf_generic_reloc
, /* special_function */
166 "R_FRV_HI16", /* name */
167 FALSE
, /* partial_inplace */
168 0xffff, /* src_mask */
169 0xffff, /* dst_mask */
170 FALSE
), /* pcrel_offset */
172 HOWTO (R_FRV_GPREL12
, /* type */
174 2, /* size (0 = byte, 1 = short, 2 = long) */
176 FALSE
, /* pc_relative */
178 complain_overflow_dont
, /* complain_on_overflow */
179 bfd_elf_generic_reloc
, /* special_function */
180 "R_FRV_GPREL12", /* name */
181 FALSE
, /* partial_inplace */
182 0xfff, /* src_mask */
183 0xfff, /* dst_mask */
184 FALSE
), /* pcrel_offset */
186 HOWTO (R_FRV_GPRELU12
, /* type */
188 2, /* size (0 = byte, 1 = short, 2 = long) */
190 FALSE
, /* pc_relative */
192 complain_overflow_dont
, /* complain_on_overflow */
193 bfd_elf_generic_reloc
, /* special_function */
194 "R_FRV_GPRELU12", /* name */
195 FALSE
, /* partial_inplace */
196 0xfff, /* src_mask */
197 0x3f03f, /* dst_mask */
198 FALSE
), /* pcrel_offset */
200 HOWTO (R_FRV_GPREL32
, /* type */
202 2, /* size (0 = byte, 1 = short, 2 = long) */
204 FALSE
, /* pc_relative */
206 complain_overflow_dont
, /* complain_on_overflow */
207 bfd_elf_generic_reloc
, /* special_function */
208 "R_FRV_GPREL32", /* name */
209 FALSE
, /* partial_inplace */
210 0xffffffff, /* src_mask */
211 0xffffffff, /* dst_mask */
212 FALSE
), /* pcrel_offset */
214 HOWTO (R_FRV_GPRELHI
, /* type */
216 2, /* size (0 = byte, 1 = short, 2 = long) */
218 FALSE
, /* pc_relative */
220 complain_overflow_dont
, /* complain_on_overflow */
221 bfd_elf_generic_reloc
, /* special_function */
222 "R_FRV_GPRELHI", /* name */
223 FALSE
, /* partial_inplace */
224 0xffff, /* src_mask */
225 0xffff, /* dst_mask */
226 FALSE
), /* pcrel_offset */
228 HOWTO (R_FRV_GPRELLO
, /* type */
230 2, /* size (0 = byte, 1 = short, 2 = long) */
232 FALSE
, /* pc_relative */
234 complain_overflow_dont
, /* complain_on_overflow */
235 bfd_elf_generic_reloc
, /* special_function */
236 "R_FRV_GPRELLO", /* name */
237 FALSE
, /* partial_inplace */
238 0xffff, /* src_mask */
239 0xffff, /* dst_mask */
240 FALSE
), /* pcrel_offset */
242 /* A 12-bit signed operand with the GOT offset for the address of
244 HOWTO (R_FRV_GOT12
, /* type */
246 2, /* size (0 = byte, 1 = short, 2 = long) */
248 FALSE
, /* pc_relative */
250 complain_overflow_signed
, /* complain_on_overflow */
251 bfd_elf_generic_reloc
, /* special_function */
252 "R_FRV_GOT12", /* name */
253 FALSE
, /* partial_inplace */
254 0xfff, /* src_mask */
255 0xfff, /* dst_mask */
256 FALSE
), /* pcrel_offset */
258 /* The upper 16 bits of the GOT offset for the address of the
260 HOWTO (R_FRV_GOTHI
, /* type */
262 2, /* size (0 = byte, 1 = short, 2 = long) */
264 FALSE
, /* pc_relative */
266 complain_overflow_dont
, /* complain_on_overflow */
267 bfd_elf_generic_reloc
, /* special_function */
268 "R_FRV_GOTHI", /* name */
269 FALSE
, /* partial_inplace */
270 0xffff, /* src_mask */
271 0xffff, /* dst_mask */
272 FALSE
), /* pcrel_offset */
274 /* The lower 16 bits of the GOT offset for the address of the
276 HOWTO (R_FRV_GOTLO
, /* type */
278 2, /* size (0 = byte, 1 = short, 2 = long) */
280 FALSE
, /* pc_relative */
282 complain_overflow_dont
, /* complain_on_overflow */
283 bfd_elf_generic_reloc
, /* special_function */
284 "R_FRV_GOTLO", /* name */
285 FALSE
, /* partial_inplace */
286 0xffff, /* src_mask */
287 0xffff, /* dst_mask */
288 FALSE
), /* pcrel_offset */
290 /* The 32-bit address of the canonical descriptor of a function. */
291 HOWTO (R_FRV_FUNCDESC
, /* type */
293 2, /* size (0 = byte, 1 = short, 2 = long) */
295 FALSE
, /* pc_relative */
297 complain_overflow_bitfield
, /* complain_on_overflow */
298 bfd_elf_generic_reloc
, /* special_function */
299 "R_FRV_FUNCDESC", /* name */
300 FALSE
, /* partial_inplace */
301 0xffffffff, /* src_mask */
302 0xffffffff, /* dst_mask */
303 FALSE
), /* pcrel_offset */
305 /* A 12-bit signed operand with the GOT offset for the address of
306 canonical descriptor of a function. */
307 HOWTO (R_FRV_FUNCDESC_GOT12
, /* type */
309 2, /* size (0 = byte, 1 = short, 2 = long) */
311 FALSE
, /* pc_relative */
313 complain_overflow_signed
, /* complain_on_overflow */
314 bfd_elf_generic_reloc
, /* special_function */
315 "R_FRV_FUNCDESC_GOT12", /* name */
316 FALSE
, /* partial_inplace */
317 0xfff, /* src_mask */
318 0xfff, /* dst_mask */
319 FALSE
), /* pcrel_offset */
321 /* The upper 16 bits of the GOT offset for the address of the
322 canonical descriptor of a function. */
323 HOWTO (R_FRV_FUNCDESC_GOTHI
, /* type */
325 2, /* size (0 = byte, 1 = short, 2 = long) */
327 FALSE
, /* pc_relative */
329 complain_overflow_dont
, /* complain_on_overflow */
330 bfd_elf_generic_reloc
, /* special_function */
331 "R_FRV_FUNCDESC_GOTHI", /* name */
332 FALSE
, /* partial_inplace */
333 0xffff, /* src_mask */
334 0xffff, /* dst_mask */
335 FALSE
), /* pcrel_offset */
337 /* The lower 16 bits of the GOT offset for the address of the
338 canonical descriptor of a function. */
339 HOWTO (R_FRV_FUNCDESC_GOTLO
, /* type */
341 2, /* size (0 = byte, 1 = short, 2 = long) */
343 FALSE
, /* pc_relative */
345 complain_overflow_dont
, /* complain_on_overflow */
346 bfd_elf_generic_reloc
, /* special_function */
347 "R_FRV_FUNCDESC_GOTLO", /* name */
348 FALSE
, /* partial_inplace */
349 0xffff, /* src_mask */
350 0xffff, /* dst_mask */
351 FALSE
), /* pcrel_offset */
353 /* The 64-bit descriptor of a function. */
354 HOWTO (R_FRV_FUNCDESC_VALUE
, /* type */
356 2, /* size (0 = byte, 1 = short, 2 = long) */
358 FALSE
, /* pc_relative */
360 complain_overflow_bitfield
, /* complain_on_overflow */
361 bfd_elf_generic_reloc
, /* special_function */
362 "R_FRV_FUNCDESC_VALUE", /* name */
363 FALSE
, /* partial_inplace */
364 0xffffffff, /* src_mask */
365 0xffffffff, /* dst_mask */
366 FALSE
), /* pcrel_offset */
368 /* A 12-bit signed operand with the GOT offset for the address of
369 canonical descriptor of a function. */
370 HOWTO (R_FRV_FUNCDESC_GOTOFF12
, /* type */
372 2, /* size (0 = byte, 1 = short, 2 = long) */
374 FALSE
, /* pc_relative */
376 complain_overflow_signed
, /* complain_on_overflow */
377 bfd_elf_generic_reloc
, /* special_function */
378 "R_FRV_FUNCDESC_GOTOFF12", /* name */
379 FALSE
, /* partial_inplace */
380 0xfff, /* src_mask */
381 0xfff, /* dst_mask */
382 FALSE
), /* pcrel_offset */
384 /* The upper 16 bits of the GOT offset for the address of the
385 canonical descriptor of a function. */
386 HOWTO (R_FRV_FUNCDESC_GOTOFFHI
, /* type */
388 2, /* size (0 = byte, 1 = short, 2 = long) */
390 FALSE
, /* pc_relative */
392 complain_overflow_dont
, /* complain_on_overflow */
393 bfd_elf_generic_reloc
, /* special_function */
394 "R_FRV_FUNCDESC_GOTOFFHI", /* name */
395 FALSE
, /* partial_inplace */
396 0xffff, /* src_mask */
397 0xffff, /* dst_mask */
398 FALSE
), /* pcrel_offset */
400 /* The lower 16 bits of the GOT offset for the address of the
401 canonical descriptor of a function. */
402 HOWTO (R_FRV_FUNCDESC_GOTOFFLO
, /* type */
404 2, /* size (0 = byte, 1 = short, 2 = long) */
406 FALSE
, /* pc_relative */
408 complain_overflow_dont
, /* complain_on_overflow */
409 bfd_elf_generic_reloc
, /* special_function */
410 "R_FRV_FUNCDESC_GOTOFFLO", /* name */
411 FALSE
, /* partial_inplace */
412 0xffff, /* src_mask */
413 0xffff, /* dst_mask */
414 FALSE
), /* pcrel_offset */
416 /* A 12-bit signed operand with the GOT offset for the address of
418 HOWTO (R_FRV_GOTOFF12
, /* type */
420 2, /* size (0 = byte, 1 = short, 2 = long) */
422 FALSE
, /* pc_relative */
424 complain_overflow_signed
, /* complain_on_overflow */
425 bfd_elf_generic_reloc
, /* special_function */
426 "R_FRV_GOTOFF12", /* name */
427 FALSE
, /* partial_inplace */
428 0xfff, /* src_mask */
429 0xfff, /* dst_mask */
430 FALSE
), /* pcrel_offset */
432 /* The upper 16 bits of the GOT offset for the address of the
434 HOWTO (R_FRV_GOTOFFHI
, /* type */
436 2, /* size (0 = byte, 1 = short, 2 = long) */
438 FALSE
, /* pc_relative */
440 complain_overflow_dont
, /* complain_on_overflow */
441 bfd_elf_generic_reloc
, /* special_function */
442 "R_FRV_GOTOFFHI", /* name */
443 FALSE
, /* partial_inplace */
444 0xffff, /* src_mask */
445 0xffff, /* dst_mask */
446 FALSE
), /* pcrel_offset */
448 /* The lower 16 bits of the GOT offset for the address of the
450 HOWTO (R_FRV_GOTOFFLO
, /* type */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
454 FALSE
, /* pc_relative */
456 complain_overflow_dont
, /* complain_on_overflow */
457 bfd_elf_generic_reloc
, /* special_function */
458 "R_FRV_GOTOFFLO", /* name */
459 FALSE
, /* partial_inplace */
460 0xffff, /* src_mask */
461 0xffff, /* dst_mask */
462 FALSE
), /* pcrel_offset */
464 /* A 24-bit pc-relative relocation referencing the TLS PLT entry for
465 a thread-local symbol. If the symbol number is 0, it refers to
467 HOWTO (R_FRV_GETTLSOFF
, /* type */
469 2, /* size (0 = byte, 1 = short, 2 = long) */
471 TRUE
, /* pc_relative */
473 complain_overflow_bitfield
, /* complain_on_overflow */
474 bfd_elf_generic_reloc
, /* special_function */
475 "R_FRV_GETTLSOFF", /* name */
476 FALSE
, /* partial_inplace */
477 0x7e03ffff, /* src_mask */
478 0x7e03ffff, /* dst_mask */
479 TRUE
), /* pcrel_offset */
481 /* A 64-bit TLS descriptor for a symbol. This relocation is only
482 valid as a REL, dynamic relocation. */
483 HOWTO (R_FRV_TLSDESC_VALUE
, /* type */
485 2, /* size (0 = byte, 1 = short, 2 = long) */
487 FALSE
, /* pc_relative */
489 complain_overflow_bitfield
, /* complain_on_overflow */
490 bfd_elf_generic_reloc
, /* special_function */
491 "R_FRV_TLSDESC_VALUE", /* name */
492 FALSE
, /* partial_inplace */
493 0xffffffff, /* src_mask */
494 0xffffffff, /* dst_mask */
495 FALSE
), /* pcrel_offset */
497 /* A 12-bit signed operand with the GOT offset for the TLS
498 descriptor of the symbol. */
499 HOWTO (R_FRV_GOTTLSDESC12
, /* type */
501 2, /* size (0 = byte, 1 = short, 2 = long) */
503 FALSE
, /* pc_relative */
505 complain_overflow_signed
, /* complain_on_overflow */
506 bfd_elf_generic_reloc
, /* special_function */
507 "R_FRV_GOTTLSDESC12", /* name */
508 FALSE
, /* partial_inplace */
509 0xfff, /* src_mask */
510 0xfff, /* dst_mask */
511 FALSE
), /* pcrel_offset */
513 /* The upper 16 bits of the GOT offset for the TLS descriptor of the
515 HOWTO (R_FRV_GOTTLSDESCHI
, /* type */
517 2, /* size (0 = byte, 1 = short, 2 = long) */
519 FALSE
, /* pc_relative */
521 complain_overflow_dont
, /* complain_on_overflow */
522 bfd_elf_generic_reloc
, /* special_function */
523 "R_FRV_GOTTLSDESCHI", /* name */
524 FALSE
, /* partial_inplace */
525 0xffff, /* src_mask */
526 0xffff, /* dst_mask */
527 FALSE
), /* pcrel_offset */
529 /* The lower 16 bits of the GOT offset for the TLS descriptor of the
531 HOWTO (R_FRV_GOTTLSDESCLO
, /* type */
533 2, /* size (0 = byte, 1 = short, 2 = long) */
535 FALSE
, /* pc_relative */
537 complain_overflow_dont
, /* complain_on_overflow */
538 bfd_elf_generic_reloc
, /* special_function */
539 "R_FRV_GOTTLSDESCLO", /* name */
540 FALSE
, /* partial_inplace */
541 0xffff, /* src_mask */
542 0xffff, /* dst_mask */
543 FALSE
), /* pcrel_offset */
545 /* A 12-bit signed operand with the offset from the module base
546 address to the thread-local symbol address. */
547 HOWTO (R_FRV_TLSMOFF12
, /* type */
549 2, /* size (0 = byte, 1 = short, 2 = long) */
551 FALSE
, /* pc_relative */
553 complain_overflow_signed
, /* complain_on_overflow */
554 bfd_elf_generic_reloc
, /* special_function */
555 "R_FRV_TLSMOFF12", /* name */
556 FALSE
, /* partial_inplace */
557 0xfff, /* src_mask */
558 0xfff, /* dst_mask */
559 FALSE
), /* pcrel_offset */
561 /* The upper 16 bits of the offset from the module base address to
562 the thread-local symbol address. */
563 HOWTO (R_FRV_TLSMOFFHI
, /* type */
565 2, /* size (0 = byte, 1 = short, 2 = long) */
567 FALSE
, /* pc_relative */
569 complain_overflow_dont
, /* complain_on_overflow */
570 bfd_elf_generic_reloc
, /* special_function */
571 "R_FRV_TLSMOFFHI", /* name */
572 FALSE
, /* partial_inplace */
573 0xffff, /* src_mask */
574 0xffff, /* dst_mask */
575 FALSE
), /* pcrel_offset */
577 /* The lower 16 bits of the offset from the module base address to
578 the thread-local symbol address. */
579 HOWTO (R_FRV_TLSMOFFLO
, /* type */
581 2, /* size (0 = byte, 1 = short, 2 = long) */
583 FALSE
, /* pc_relative */
585 complain_overflow_dont
, /* complain_on_overflow */
586 bfd_elf_generic_reloc
, /* special_function */
587 "R_FRV_TLSMOFFLO", /* name */
588 FALSE
, /* partial_inplace */
589 0xffff, /* src_mask */
590 0xffff, /* dst_mask */
591 FALSE
), /* pcrel_offset */
593 /* A 12-bit signed operand with the GOT offset for the TLSOFF entry
595 HOWTO (R_FRV_GOTTLSOFF12
, /* type */
597 2, /* size (0 = byte, 1 = short, 2 = long) */
599 FALSE
, /* pc_relative */
601 complain_overflow_signed
, /* complain_on_overflow */
602 bfd_elf_generic_reloc
, /* special_function */
603 "R_FRV_GOTTLSOFF12", /* name */
604 FALSE
, /* partial_inplace */
605 0xfff, /* src_mask */
606 0xfff, /* dst_mask */
607 FALSE
), /* pcrel_offset */
609 /* The upper 16 bits of the GOT offset for the TLSOFF entry for a
611 HOWTO (R_FRV_GOTTLSOFFHI
, /* type */
613 2, /* size (0 = byte, 1 = short, 2 = long) */
615 FALSE
, /* pc_relative */
617 complain_overflow_dont
, /* complain_on_overflow */
618 bfd_elf_generic_reloc
, /* special_function */
619 "R_FRV_GOTTLSOFFHI", /* name */
620 FALSE
, /* partial_inplace */
621 0xffff, /* src_mask */
622 0xffff, /* dst_mask */
623 FALSE
), /* pcrel_offset */
625 /* The lower 16 bits of the GOT offset for the TLSOFF entry for a
627 HOWTO (R_FRV_GOTTLSOFFLO
, /* type */
629 2, /* size (0 = byte, 1 = short, 2 = long) */
631 FALSE
, /* pc_relative */
633 complain_overflow_dont
, /* complain_on_overflow */
634 bfd_elf_generic_reloc
, /* special_function */
635 "R_FRV_GOTTLSOFFLO", /* name */
636 FALSE
, /* partial_inplace */
637 0xffff, /* src_mask */
638 0xffff, /* dst_mask */
639 FALSE
), /* pcrel_offset */
641 /* The 32-bit offset from the thread pointer (not the module base
642 address) to a thread-local symbol. */
643 HOWTO (R_FRV_TLSOFF
, /* type */
645 2, /* size (0 = byte, 1 = short, 2 = long) */
647 FALSE
, /* pc_relative */
649 complain_overflow_dont
, /* complain_on_overflow */
650 bfd_elf_generic_reloc
, /* special_function */
651 "R_FRV_TLSOFF", /* name */
652 FALSE
, /* partial_inplace */
653 0xffffffff, /* src_mask */
654 0xffffffff, /* dst_mask */
655 FALSE
), /* pcrel_offset */
657 /* An annotation for linker relaxation, that denotes the
658 symbol+addend whose TLS descriptor is referenced by the sum of
659 the two input registers of an ldd instruction. */
660 HOWTO (R_FRV_TLSDESC_RELAX
, /* type */
662 2, /* size (0 = byte, 1 = short, 2 = long) */
664 FALSE
, /* pc_relative */
666 complain_overflow_dont
, /* complain_on_overflow */
667 bfd_elf_generic_reloc
, /* special_function */
668 "R_FRV_TLSDESC_RELAX", /* name */
669 FALSE
, /* partial_inplace */
672 FALSE
), /* pcrel_offset */
674 /* An annotation for linker relaxation, that denotes the
675 symbol+addend whose TLS resolver entry point is given by the sum
676 of the two register operands of an calll instruction. */
677 HOWTO (R_FRV_GETTLSOFF_RELAX
, /* type */
679 2, /* size (0 = byte, 1 = short, 2 = long) */
681 FALSE
, /* pc_relative */
683 complain_overflow_dont
, /* complain_on_overflow */
684 bfd_elf_generic_reloc
, /* special_function */
685 "R_FRV_GETTLSOFF_RELAX", /* name */
686 FALSE
, /* partial_inplace */
689 FALSE
), /* pcrel_offset */
691 /* An annotation for linker relaxation, that denotes the
692 symbol+addend whose TLS offset GOT entry is given by the sum of
693 the two input registers of an ld instruction. */
694 HOWTO (R_FRV_TLSOFF_RELAX
, /* type */
696 2, /* size (0 = byte, 1 = short, 2 = long) */
698 FALSE
, /* pc_relative */
700 complain_overflow_bitfield
, /* complain_on_overflow */
701 bfd_elf_generic_reloc
, /* special_function */
702 "R_FRV_TLSOFF_RELAX", /* name */
703 FALSE
, /* partial_inplace */
706 FALSE
), /* pcrel_offset */
708 /* A 32-bit offset from the module base address to
709 the thread-local symbol address. */
710 HOWTO (R_FRV_TLSMOFF
, /* type */
712 2, /* size (0 = byte, 1 = short, 2 = long) */
714 FALSE
, /* pc_relative */
716 complain_overflow_dont
, /* complain_on_overflow */
717 bfd_elf_generic_reloc
, /* special_function */
718 "R_FRV_TLSMOFF", /* name */
719 FALSE
, /* partial_inplace */
720 0xffffffff, /* src_mask */
721 0xffffffff, /* dst_mask */
722 FALSE
), /* pcrel_offset */
725 /* GNU extension to record C++ vtable hierarchy. */
726 static reloc_howto_type elf32_frv_vtinherit_howto
=
727 HOWTO (R_FRV_GNU_VTINHERIT
, /* type */
729 2, /* size (0 = byte, 1 = short, 2 = long) */
731 FALSE
, /* pc_relative */
733 complain_overflow_dont
, /* complain_on_overflow */
734 NULL
, /* special_function */
735 "R_FRV_GNU_VTINHERIT", /* name */
736 FALSE
, /* partial_inplace */
739 FALSE
); /* pcrel_offset */
741 /* GNU extension to record C++ vtable member usage. */
742 static reloc_howto_type elf32_frv_vtentry_howto
=
743 HOWTO (R_FRV_GNU_VTENTRY
, /* type */
745 2, /* size (0 = byte, 1 = short, 2 = long) */
747 FALSE
, /* pc_relative */
749 complain_overflow_dont
, /* complain_on_overflow */
750 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
751 "R_FRV_GNU_VTENTRY", /* name */
752 FALSE
, /* partial_inplace */
755 FALSE
); /* pcrel_offset */
757 /* The following 3 relocations are REL. The only difference to the
758 entries in the table above are that partial_inplace is TRUE. */
759 static reloc_howto_type elf32_frv_rel_32_howto
=
760 HOWTO (R_FRV_32
, /* type */
762 2, /* size (0 = byte, 1 = short, 2 = long) */
764 FALSE
, /* pc_relative */
766 complain_overflow_bitfield
, /* complain_on_overflow */
767 bfd_elf_generic_reloc
, /* special_function */
768 "R_FRV_32", /* name */
769 TRUE
, /* partial_inplace */
770 0xffffffff, /* src_mask */
771 0xffffffff, /* dst_mask */
772 FALSE
); /* pcrel_offset */
774 static reloc_howto_type elf32_frv_rel_funcdesc_howto
=
775 HOWTO (R_FRV_FUNCDESC
, /* type */
777 2, /* size (0 = byte, 1 = short, 2 = long) */
779 FALSE
, /* pc_relative */
781 complain_overflow_bitfield
, /* complain_on_overflow */
782 bfd_elf_generic_reloc
, /* special_function */
783 "R_FRV_FUNCDESC", /* name */
784 TRUE
, /* partial_inplace */
785 0xffffffff, /* src_mask */
786 0xffffffff, /* dst_mask */
787 FALSE
); /* pcrel_offset */
789 static reloc_howto_type elf32_frv_rel_funcdesc_value_howto
=
790 HOWTO (R_FRV_FUNCDESC_VALUE
, /* type */
792 2, /* size (0 = byte, 1 = short, 2 = long) */
794 FALSE
, /* pc_relative */
796 complain_overflow_bitfield
, /* complain_on_overflow */
797 bfd_elf_generic_reloc
, /* special_function */
798 "R_FRV_FUNCDESC_VALUE", /* name */
799 TRUE
, /* partial_inplace */
800 0xffffffff, /* src_mask */
801 0xffffffff, /* dst_mask */
802 FALSE
); /* pcrel_offset */
804 static reloc_howto_type elf32_frv_rel_tlsdesc_value_howto
=
805 /* A 64-bit TLS descriptor for a symbol. The first word resolves to
806 an entry point, and the second resolves to a special argument.
807 If the symbol turns out to be in static TLS, the entry point is a
808 return instruction, and the special argument is the TLS offset
809 for the symbol. If it's in dynamic TLS, the entry point is a TLS
810 offset resolver, and the special argument is a pointer to a data
811 structure allocated by the dynamic loader, containing the GOT
812 address for the offset resolver, the module id, the offset within
813 the module, and anything else the TLS offset resolver might need
814 to determine the TLS offset for the symbol in the running
816 HOWTO (R_FRV_TLSDESC_VALUE
, /* type */
818 2, /* size (0 = byte, 1 = short, 2 = long) */
820 FALSE
, /* pc_relative */
822 complain_overflow_bitfield
, /* complain_on_overflow */
823 bfd_elf_generic_reloc
, /* special_function */
824 "R_FRV_TLSDESC_VALUE", /* name */
825 TRUE
, /* partial_inplace */
826 0xffffffff, /* src_mask */
827 0xffffffff, /* dst_mask */
828 FALSE
); /* pcrel_offset */
830 static reloc_howto_type elf32_frv_rel_tlsoff_howto
=
831 /* The 32-bit offset from the thread pointer (not the module base
832 address) to a thread-local symbol. */
833 HOWTO (R_FRV_TLSOFF
, /* type */
835 2, /* size (0 = byte, 1 = short, 2 = long) */
837 FALSE
, /* pc_relative */
839 complain_overflow_bitfield
, /* complain_on_overflow */
840 bfd_elf_generic_reloc
, /* special_function */
841 "R_FRV_TLSOFF", /* name */
842 TRUE
, /* partial_inplace */
843 0xffffffff, /* src_mask */
844 0xffffffff, /* dst_mask */
845 FALSE
); /* pcrel_offset */
849 extern const bfd_target bfd_elf32_frvfdpic_vec
;
850 #define IS_FDPIC(bfd) ((bfd)->xvec == &bfd_elf32_frvfdpic_vec)
852 /* An extension of the elf hash table data structure, containing some
853 additional FRV-specific data. */
854 struct frvfdpic_elf_link_hash_table
856 struct elf_link_hash_table elf
;
858 /* A pointer to the .got section. */
860 /* A pointer to the .rel.got section. */
862 /* A pointer to the .rofixup section. */
864 /* A pointer to the .plt section. */
866 /* A pointer to the .rel.plt section. */
868 /* GOT base offset. */
870 /* Location of the first non-lazy PLT entry, i.e., the number of
871 bytes taken by lazy PLT entries. If locally-bound TLS
872 descriptors require a ret instruction, it will be placed at this
875 /* A hash table holding information about which symbols were
876 referenced with which PIC-related relocations. */
877 struct htab
*relocs_info
;
878 /* Summary reloc information collected by
879 _frvfdpic_count_got_plt_entries. */
880 struct _frvfdpic_dynamic_got_info
*g
;
883 /* Get the FRV ELF linker hash table from a link_info structure. */
885 #define frvfdpic_hash_table(info) \
886 ((struct frvfdpic_elf_link_hash_table *) ((info)->hash))
888 #define frvfdpic_got_section(info) \
889 (frvfdpic_hash_table (info)->sgot)
890 #define frvfdpic_gotrel_section(info) \
891 (frvfdpic_hash_table (info)->sgotrel)
892 #define frvfdpic_gotfixup_section(info) \
893 (frvfdpic_hash_table (info)->sgotfixup)
894 #define frvfdpic_plt_section(info) \
895 (frvfdpic_hash_table (info)->splt)
896 #define frvfdpic_pltrel_section(info) \
897 (frvfdpic_hash_table (info)->spltrel)
898 #define frvfdpic_relocs_info(info) \
899 (frvfdpic_hash_table (info)->relocs_info)
900 #define frvfdpic_got_initial_offset(info) \
901 (frvfdpic_hash_table (info)->got0)
902 #define frvfdpic_plt_initial_offset(info) \
903 (frvfdpic_hash_table (info)->plt0)
904 #define frvfdpic_dynamic_got_plt_info(info) \
905 (frvfdpic_hash_table (info)->g)
907 /* Currently it's the same, but if some day we have a reason to change
908 it, we'd better be using a different macro.
910 FIXME: if there's any TLS PLT entry that uses local-exec or
911 initial-exec models, we could use the ret at the end of any of them
912 instead of adding one more. */
913 #define frvfdpic_plt_tls_ret_offset(info) \
914 (frvfdpic_plt_initial_offset (info))
916 /* The name of the dynamic interpreter. This is put in the .interp
919 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
921 #define DEFAULT_STACK_SIZE 0x20000
923 /* This structure is used to collect the number of entries present in
924 each addressable range of the got. */
925 struct _frvfdpic_dynamic_got_info
927 /* Several bits of information about the current link. */
928 struct bfd_link_info
*info
;
929 /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit
931 bfd_vma got12
, gotlos
, gothilo
;
932 /* Total GOT size needed for function descriptor entries within the 12-,
933 16- or 32-bit ranges. */
934 bfd_vma fd12
, fdlos
, fdhilo
;
935 /* Total GOT size needed by function descriptor entries referenced
936 in PLT entries, that would be profitable to place in offsets
937 close to the PIC register. */
939 /* Total PLT size needed by lazy PLT entries. */
941 /* Total GOT size needed for TLS descriptor entries within the 12-,
942 16- or 32-bit ranges. */
943 bfd_vma tlsd12
, tlsdlos
, tlsdhilo
;
944 /* Total GOT size needed by TLS descriptors referenced in PLT
945 entries, that would be profitable to place in offers close to the
948 /* Total PLT size needed by TLS lazy PLT entries. */
950 /* Number of relocations carried over from input object files. */
951 unsigned long relocs
;
952 /* Number of fixups introduced by relocations in input object files. */
953 unsigned long fixups
;
954 /* The number of fixups that reference the ret instruction added to
955 the PLT for locally-resolved TLS descriptors. */
956 unsigned long tls_ret_refs
;
959 /* This structure is used to assign offsets to got entries, function
960 descriptors, plt entries and lazy plt entries. */
962 struct _frvfdpic_dynamic_got_plt_info
964 /* Summary information collected with _frvfdpic_count_got_plt_entries. */
965 struct _frvfdpic_dynamic_got_info g
;
967 /* For each addressable range, we record a MAX (positive) and MIN
968 (negative) value. CUR is used to assign got entries, and it's
969 incremented from an initial positive value to MAX, then from MIN
970 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
971 assign function descriptors, and it's decreased from an initial
972 non-positive value to MIN, then from MAX down to CUR (unless CUR
973 wraps around first). All of MIN, MAX, CUR and FDCUR always point
974 to even words. ODD, if non-zero, indicates an odd word to be
975 used for the next got entry, otherwise CUR is used and
976 incremented by a pair of words, wrapping around when it reaches
977 MAX. FDCUR is decremented (and wrapped) before the next function
978 descriptor is chosen. FDPLT indicates the number of remaining
979 slots that can be used for function descriptors used only by PLT
982 TMAX, TMIN and TCUR are used to assign TLS descriptors. TCUR
983 starts as MAX, and grows up to TMAX, then wraps around to TMIN
984 and grows up to MIN. TLSDPLT indicates the number of remaining
985 slots that can be used for TLS descriptors used only by TLS PLT
987 struct _frvfdpic_dynamic_got_alloc_data
989 bfd_signed_vma max
, cur
, odd
, fdcur
, min
;
990 bfd_signed_vma tmax
, tcur
, tmin
;
991 bfd_vma fdplt
, tlsdplt
;
992 } got12
, gotlos
, gothilo
;
995 /* Create an FRV ELF linker hash table. */
997 static struct bfd_link_hash_table
*
998 frvfdpic_elf_link_hash_table_create (bfd
*abfd
)
1000 struct frvfdpic_elf_link_hash_table
*ret
;
1001 bfd_size_type amt
= sizeof (struct frvfdpic_elf_link_hash_table
);
1003 ret
= bfd_zalloc (abfd
, amt
);
1007 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1008 _bfd_elf_link_hash_newfunc
))
1014 return &ret
->elf
.root
;
1017 /* Decide whether a reference to a symbol can be resolved locally or
1018 not. If the symbol is protected, we want the local address, but
1019 its function descriptor must be assigned by the dynamic linker. */
1020 #define FRVFDPIC_SYM_LOCAL(INFO, H) \
1021 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
1022 || ! elf_hash_table (INFO)->dynamic_sections_created \
1023 /* These two additional alternatives are needed for TLS
1024 relocations, that use *ABS*+offset relocations to refer to the
1025 TLS section of the local module. FIXME: At some point during
1026 linking, the definition section ceases to be regarded as the
1027 absolute section, and starts being regarded as the undefined
1029 || bfd_is_abs_section ((H)->root.u.def.section) \
1030 || bfd_is_und_section ((H)->root.u.def.section))
1031 #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \
1032 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
1034 /* This structure collects information on what kind of GOT, PLT or
1035 function descriptors are required by relocations that reference a
1037 struct frvfdpic_relocs_info
1039 /* The index of the symbol, as stored in the relocation r_info, if
1040 we have a local symbol; -1 otherwise. */
1044 /* The input bfd in which the symbol is defined, if it's a local
1047 /* If symndx == -1, the hash table entry corresponding to a global
1048 symbol (even if it turns out to bind locally, in which case it
1049 should ideally be replaced with section's symndx + addend). */
1050 struct elf_link_hash_entry
*h
;
1052 /* The addend of the relocation that references the symbol. */
1055 /* The fields above are used to identify an entry. The fields below
1056 contain information on how an entry is used and, later on, which
1057 locations it was assigned. */
1058 /* The following 3 fields record whether the symbol+addend above was
1059 ever referenced with a GOT relocation. The 12 suffix indicates a
1060 GOT12 relocation; los is used for GOTLO relocations that are not
1061 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
1066 /* Whether a FUNCDESC relocation references symbol+addend. */
1068 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
1070 unsigned fdgotlos
:1;
1071 unsigned fdgothilo
:1;
1072 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
1073 unsigned fdgoff12
:1;
1074 unsigned fdgofflos
:1;
1075 unsigned fdgoffhilo
:1;
1076 /* Whether a GETTLSOFF relocation references symbol+addend. */
1078 /* FIXME: we should probably add tlspltdesc, tlspltoff and
1079 tlspltimm, to tell what kind of TLS PLT entry we're generating.
1080 We might instead just pre-compute flags telling whether the
1081 object is suitable for local exec, initial exec or general
1082 dynamic addressing, and use that all over the place. We could
1083 also try to do a better job of merging TLSOFF and TLSDESC entries
1084 in main executables, but perhaps we can get rid of TLSDESC
1085 entirely in them instead. */
1086 /* Whether a GOTTLSDESC relocation references symbol+addend. */
1087 unsigned tlsdesc12
:1;
1088 unsigned tlsdesclos
:1;
1089 unsigned tlsdeschilo
:1;
1090 /* Whether a GOTTLSOFF relocation references symbol+addend. */
1091 unsigned tlsoff12
:1;
1092 unsigned tlsofflos
:1;
1093 unsigned tlsoffhilo
:1;
1094 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
1095 GOTOFFHI relocations. The addend doesn't really matter, since we
1096 envision that this will only be used to check whether the symbol
1097 is mapped to the same segment as the got. */
1099 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
1101 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
1104 /* Whether we need a PLT entry for a symbol. Should be implied by
1106 (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */
1108 /* Whether a function descriptor should be created in this link unit
1109 for symbol+addend. Should be implied by something like:
1110 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
1111 || ((fd || fdgot12 || fdgotlos || fdgothilo)
1112 && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */
1114 /* Whether a lazy PLT entry is needed for this symbol+addend.
1115 Should be implied by something like:
1116 (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)
1117 && ! (info->flags & DF_BIND_NOW)) */
1119 /* Whether we've already emitted GOT relocations and PLT entries as
1120 needed for this symbol. */
1123 /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and
1124 R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing
1126 unsigned relocs32
, relocsfd
, relocsfdv
, relocstlsd
, relocstlsoff
;
1128 /* The number of .rofixups entries and dynamic relocations allocated
1129 for this symbol, minus any that might have already been used. */
1130 unsigned fixups
, dynrelocs
;
1132 /* The offsets of the GOT entries assigned to symbol+addend, to the
1133 function descriptor's address, and to a function descriptor,
1134 respectively. Should be zero if unassigned. The offsets are
1135 counted from the value that will be assigned to the PIC register,
1136 not from the beginning of the .got section. */
1137 bfd_signed_vma got_entry
, fdgot_entry
, fd_entry
;
1138 /* The offsets of the PLT entries assigned to symbol+addend,
1139 non-lazy and lazy, respectively. If unassigned, should be
1141 bfd_vma plt_entry
, lzplt_entry
;
1142 /* The offsets of the GOT entries for TLS offset and TLS descriptor. */
1143 bfd_signed_vma tlsoff_entry
, tlsdesc_entry
;
1144 /* The offset of the TLS offset PLT entry. */
1145 bfd_vma tlsplt_entry
;
1148 /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */
1150 frvfdpic_relocs_info_hash (const void *entry_
)
1152 const struct frvfdpic_relocs_info
*entry
= entry_
;
1154 return (entry
->symndx
== -1
1155 ? (long)entry
->d
.h
->root
.root
.hash
1156 : entry
->symndx
+ entry
->d
.abfd
->id
* 257) + entry
->addend
;
1159 /* Test whether the key fields of two frvfdpic_relocs_info entries are
1162 frvfdpic_relocs_info_eq (const void *entry1
, const void *entry2
)
1164 const struct frvfdpic_relocs_info
*e1
= entry1
;
1165 const struct frvfdpic_relocs_info
*e2
= entry2
;
1167 return e1
->symndx
== e2
->symndx
&& e1
->addend
== e2
->addend
1168 && (e1
->symndx
== -1 ? e1
->d
.h
== e2
->d
.h
: e1
->d
.abfd
== e2
->d
.abfd
);
1171 /* Find or create an entry in a hash table HT that matches the key
1172 fields of the given ENTRY. If it's not found, memory for a new
1173 entry is allocated in ABFD's obstack. */
1174 static struct frvfdpic_relocs_info
*
1175 frvfdpic_relocs_info_find (struct htab
*ht
,
1177 const struct frvfdpic_relocs_info
*entry
,
1178 enum insert_option insert
)
1180 struct frvfdpic_relocs_info
**loc
=
1181 (struct frvfdpic_relocs_info
**) htab_find_slot (ht
, entry
, insert
);
1189 *loc
= bfd_zalloc (abfd
, sizeof (**loc
));
1194 (*loc
)->symndx
= entry
->symndx
;
1195 (*loc
)->d
= entry
->d
;
1196 (*loc
)->addend
= entry
->addend
;
1197 (*loc
)->plt_entry
= (bfd_vma
)-1;
1198 (*loc
)->lzplt_entry
= (bfd_vma
)-1;
1199 (*loc
)->tlsplt_entry
= (bfd_vma
)-1;
1204 /* Obtain the address of the entry in HT associated with H's symbol +
1205 addend, creating a new entry if none existed. ABFD is only used
1206 for memory allocation purposes. */
1207 inline static struct frvfdpic_relocs_info
*
1208 frvfdpic_relocs_info_for_global (struct htab
*ht
,
1210 struct elf_link_hash_entry
*h
,
1212 enum insert_option insert
)
1214 struct frvfdpic_relocs_info entry
;
1218 entry
.addend
= addend
;
1220 return frvfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1223 /* Obtain the address of the entry in HT associated with the SYMNDXth
1224 local symbol of the input bfd ABFD, plus the addend, creating a new
1225 entry if none existed. */
1226 inline static struct frvfdpic_relocs_info
*
1227 frvfdpic_relocs_info_for_local (struct htab
*ht
,
1231 enum insert_option insert
)
1233 struct frvfdpic_relocs_info entry
;
1235 entry
.symndx
= symndx
;
1236 entry
.d
.abfd
= abfd
;
1237 entry
.addend
= addend
;
1239 return frvfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1242 /* Merge fields set by check_relocs() of two entries that end up being
1243 mapped to the same (presumably global) symbol. */
1246 frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info
*e2
,
1247 struct frvfdpic_relocs_info
const *e1
)
1249 e2
->got12
|= e1
->got12
;
1250 e2
->gotlos
|= e1
->gotlos
;
1251 e2
->gothilo
|= e1
->gothilo
;
1253 e2
->fdgot12
|= e1
->fdgot12
;
1254 e2
->fdgotlos
|= e1
->fdgotlos
;
1255 e2
->fdgothilo
|= e1
->fdgothilo
;
1256 e2
->fdgoff12
|= e1
->fdgoff12
;
1257 e2
->fdgofflos
|= e1
->fdgofflos
;
1258 e2
->fdgoffhilo
|= e1
->fdgoffhilo
;
1259 e2
->tlsplt
|= e1
->tlsplt
;
1260 e2
->tlsdesc12
|= e1
->tlsdesc12
;
1261 e2
->tlsdesclos
|= e1
->tlsdesclos
;
1262 e2
->tlsdeschilo
|= e1
->tlsdeschilo
;
1263 e2
->tlsoff12
|= e1
->tlsoff12
;
1264 e2
->tlsofflos
|= e1
->tlsofflos
;
1265 e2
->tlsoffhilo
|= e1
->tlsoffhilo
;
1266 e2
->gotoff
|= e1
->gotoff
;
1267 e2
->call
|= e1
->call
;
1271 /* Every block of 65535 lazy PLT entries shares a single call to the
1272 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
1273 32767, counting from 0). All other lazy PLT entries branch to it
1274 in a single instruction. */
1276 #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
1277 #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767)
1279 /* Add a dynamic relocation to the SRELOC section. */
1281 inline static bfd_vma
1282 _frvfdpic_add_dyn_reloc (bfd
*output_bfd
, asection
*sreloc
, bfd_vma offset
,
1283 int reloc_type
, long dynindx
, bfd_vma addend
,
1284 struct frvfdpic_relocs_info
*entry
)
1286 Elf_Internal_Rela outrel
;
1287 bfd_vma reloc_offset
;
1289 outrel
.r_offset
= offset
;
1290 outrel
.r_info
= ELF32_R_INFO (dynindx
, reloc_type
);
1291 outrel
.r_addend
= addend
;
1293 reloc_offset
= sreloc
->reloc_count
* sizeof (Elf32_External_Rel
);
1294 BFD_ASSERT (reloc_offset
< sreloc
->size
);
1295 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
1296 sreloc
->contents
+ reloc_offset
);
1297 sreloc
->reloc_count
++;
1299 /* If the entry's index is zero, this relocation was probably to a
1300 linkonce section that got discarded. We reserved a dynamic
1301 relocation, but it was for another entry than the one we got at
1302 the time of emitting the relocation. Unfortunately there's no
1303 simple way for us to catch this situation, since the relocation
1304 is cleared right before calling relocate_section, at which point
1305 we no longer know what the relocation used to point to. */
1308 BFD_ASSERT (entry
->dynrelocs
> 0);
1312 return reloc_offset
;
1315 /* Add a fixup to the ROFIXUP section. */
1318 _frvfdpic_add_rofixup (bfd
*output_bfd
, asection
*rofixup
, bfd_vma offset
,
1319 struct frvfdpic_relocs_info
*entry
)
1321 bfd_vma fixup_offset
;
1323 if (rofixup
->flags
& SEC_EXCLUDE
)
1326 fixup_offset
= rofixup
->reloc_count
* 4;
1327 if (rofixup
->contents
)
1329 BFD_ASSERT (fixup_offset
< rofixup
->size
);
1330 bfd_put_32 (output_bfd
, offset
, rofixup
->contents
+ fixup_offset
);
1332 rofixup
->reloc_count
++;
1334 if (entry
&& entry
->symndx
)
1336 /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc
1338 BFD_ASSERT (entry
->fixups
> 0);
1342 return fixup_offset
;
1345 /* Find the segment number in which OSEC, and output section, is
1349 _frvfdpic_osec_to_segment (bfd
*output_bfd
, asection
*osec
)
1351 struct elf_segment_map
*m
;
1352 Elf_Internal_Phdr
*p
;
1354 /* Find the segment that contains the output_section. */
1355 for (m
= elf_tdata (output_bfd
)->segment_map
,
1356 p
= elf_tdata (output_bfd
)->phdr
;
1362 for (i
= m
->count
- 1; i
>= 0; i
--)
1363 if (m
->sections
[i
] == osec
)
1370 return p
- elf_tdata (output_bfd
)->phdr
;
1373 inline static bfd_boolean
1374 _frvfdpic_osec_readonly_p (bfd
*output_bfd
, asection
*osec
)
1376 unsigned seg
= _frvfdpic_osec_to_segment (output_bfd
, osec
);
1378 return ! (elf_tdata (output_bfd
)->phdr
[seg
].p_flags
& PF_W
);
1381 #define FRVFDPIC_TLS_BIAS (2048 - 16)
1383 /* Return the base VMA address which should be subtracted from real addresses
1384 when resolving TLSMOFF relocation.
1385 This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */
1388 tls_biased_base (struct bfd_link_info
*info
)
1390 /* If tls_sec is NULL, we should have signalled an error already. */
1391 if (elf_hash_table (info
)->tls_sec
== NULL
)
1392 return FRVFDPIC_TLS_BIAS
;
1393 return elf_hash_table (info
)->tls_sec
->vma
+ FRVFDPIC_TLS_BIAS
;
1396 /* Generate relocations for GOT entries, function descriptors, and
1397 code for PLT and lazy PLT entries. */
1399 inline static bfd_boolean
1400 _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info
*entry
,
1402 struct bfd_link_info
*info
,
1404 Elf_Internal_Sym
*sym
,
1408 bfd_vma fd_lazy_rel_offset
= (bfd_vma
)-1;
1415 if (entry
->got_entry
|| entry
->fdgot_entry
|| entry
->fd_entry
1416 || entry
->tlsoff_entry
|| entry
->tlsdesc_entry
)
1418 /* If the symbol is dynamic, consider it for dynamic
1419 relocations, otherwise decay to section + offset. */
1420 if (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1)
1421 dynindx
= entry
->d
.h
->dynindx
;
1424 if (sec
->output_section
1425 && ! bfd_is_abs_section (sec
->output_section
)
1426 && ! bfd_is_und_section (sec
->output_section
))
1427 dynindx
= elf_section_data (sec
->output_section
)->dynindx
;
1433 /* Generate relocation for GOT entry pointing to the symbol. */
1434 if (entry
->got_entry
)
1437 bfd_vma ad
= addend
;
1439 /* If the symbol is dynamic but binds locally, use
1441 if (sec
&& (entry
->symndx
!= -1
1442 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1444 if (entry
->symndx
== -1)
1445 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1447 ad
+= sym
->st_value
;
1448 ad
+= sec
->output_offset
;
1449 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1450 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1455 /* If we're linking an executable at a fixed address, we can
1456 omit the dynamic relocation as long as the symbol is local to
1458 if (info
->executable
&& !info
->pie
1459 && (entry
->symndx
!= -1
1460 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1463 ad
+= sec
->output_section
->vma
;
1464 if (entry
->symndx
!= -1
1465 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1466 _frvfdpic_add_rofixup (output_bfd
,
1467 frvfdpic_gotfixup_section (info
),
1468 frvfdpic_got_section (info
)->output_section
1470 + frvfdpic_got_section (info
)->output_offset
1471 + frvfdpic_got_initial_offset (info
)
1472 + entry
->got_entry
, entry
);
1475 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1476 _bfd_elf_section_offset
1478 frvfdpic_got_section (info
),
1479 frvfdpic_got_initial_offset (info
)
1481 + frvfdpic_got_section (info
)
1482 ->output_section
->vma
1483 + frvfdpic_got_section (info
)->output_offset
,
1484 R_FRV_32
, idx
, ad
, entry
);
1486 bfd_put_32 (output_bfd
, ad
,
1487 frvfdpic_got_section (info
)->contents
1488 + frvfdpic_got_initial_offset (info
)
1489 + entry
->got_entry
);
1492 /* Generate relocation for GOT entry pointing to a canonical
1493 function descriptor. */
1494 if (entry
->fdgot_entry
)
1499 if (! (entry
->symndx
== -1
1500 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
1501 && FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1503 /* If the symbol is dynamic and there may be dynamic symbol
1504 resolution because we are, or are linked with, a shared
1505 library, emit a FUNCDESC relocation such that the dynamic
1506 linker will allocate the function descriptor. If the
1507 symbol needs a non-local function descriptor but binds
1508 locally (e.g., its visibility is protected, emit a
1509 dynamic relocation decayed to section+offset. */
1510 if (entry
->symndx
== -1
1511 && ! FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)
1512 && FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)
1513 && !(info
->executable
&& !info
->pie
))
1515 reloc
= R_FRV_FUNCDESC
;
1516 idx
= elf_section_data (entry
->d
.h
->root
.u
.def
.section
1517 ->output_section
)->dynindx
;
1518 ad
= entry
->d
.h
->root
.u
.def
.section
->output_offset
1519 + entry
->d
.h
->root
.u
.def
.value
;
1521 else if (entry
->symndx
== -1
1522 && ! FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
))
1524 reloc
= R_FRV_FUNCDESC
;
1532 /* Otherwise, we know we have a private function descriptor,
1533 so reference it directly. */
1534 if (elf_hash_table (info
)->dynamic_sections_created
)
1535 BFD_ASSERT (entry
->privfd
);
1537 idx
= elf_section_data (frvfdpic_got_section (info
)
1538 ->output_section
)->dynindx
;
1539 ad
= frvfdpic_got_section (info
)->output_offset
1540 + frvfdpic_got_initial_offset (info
) + entry
->fd_entry
;
1543 /* If there is room for dynamic symbol resolution, emit the
1544 dynamic relocation. However, if we're linking an
1545 executable at a fixed location, we won't have emitted a
1546 dynamic symbol entry for the got section, so idx will be
1547 zero, which means we can and should compute the address
1548 of the private descriptor ourselves. */
1549 if (info
->executable
&& !info
->pie
1550 && (entry
->symndx
!= -1
1551 || FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)))
1553 ad
+= frvfdpic_got_section (info
)->output_section
->vma
;
1554 _frvfdpic_add_rofixup (output_bfd
,
1555 frvfdpic_gotfixup_section (info
),
1556 frvfdpic_got_section (info
)
1557 ->output_section
->vma
1558 + frvfdpic_got_section (info
)
1560 + frvfdpic_got_initial_offset (info
)
1561 + entry
->fdgot_entry
, entry
);
1564 _frvfdpic_add_dyn_reloc (output_bfd
,
1565 frvfdpic_gotrel_section (info
),
1566 _bfd_elf_section_offset
1568 frvfdpic_got_section (info
),
1569 frvfdpic_got_initial_offset (info
)
1570 + entry
->fdgot_entry
)
1571 + frvfdpic_got_section (info
)
1572 ->output_section
->vma
1573 + frvfdpic_got_section (info
)
1575 reloc
, idx
, ad
, entry
);
1578 bfd_put_32 (output_bfd
, ad
,
1579 frvfdpic_got_section (info
)->contents
1580 + frvfdpic_got_initial_offset (info
)
1581 + entry
->fdgot_entry
);
1584 /* Generate relocation to fill in a private function descriptor in
1586 if (entry
->fd_entry
)
1589 bfd_vma ad
= addend
;
1591 long lowword
, highword
;
1593 /* If the symbol is dynamic but binds locally, use
1595 if (sec
&& (entry
->symndx
!= -1
1596 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1598 if (entry
->symndx
== -1)
1599 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1601 ad
+= sym
->st_value
;
1602 ad
+= sec
->output_offset
;
1603 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1604 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1609 /* If we're linking an executable at a fixed address, we can
1610 omit the dynamic relocation as long as the symbol is local to
1612 if (info
->executable
&& !info
->pie
1613 && (entry
->symndx
!= -1 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1616 ad
+= sec
->output_section
->vma
;
1618 if (entry
->symndx
!= -1
1619 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1621 _frvfdpic_add_rofixup (output_bfd
,
1622 frvfdpic_gotfixup_section (info
),
1623 frvfdpic_got_section (info
)
1624 ->output_section
->vma
1625 + frvfdpic_got_section (info
)
1627 + frvfdpic_got_initial_offset (info
)
1628 + entry
->fd_entry
, entry
);
1629 _frvfdpic_add_rofixup (output_bfd
,
1630 frvfdpic_gotfixup_section (info
),
1631 frvfdpic_got_section (info
)
1632 ->output_section
->vma
1633 + frvfdpic_got_section (info
)
1635 + frvfdpic_got_initial_offset (info
)
1636 + entry
->fd_entry
+ 4, entry
);
1642 _frvfdpic_add_dyn_reloc (output_bfd
,
1644 ? frvfdpic_pltrel_section (info
)
1645 : frvfdpic_gotrel_section (info
),
1646 _bfd_elf_section_offset
1648 frvfdpic_got_section (info
),
1649 frvfdpic_got_initial_offset (info
)
1651 + frvfdpic_got_section (info
)
1652 ->output_section
->vma
1653 + frvfdpic_got_section (info
)
1655 R_FRV_FUNCDESC_VALUE
, idx
, ad
, entry
);
1658 /* If we've omitted the dynamic relocation, just emit the fixed
1659 addresses of the symbol and of the local GOT base offset. */
1660 if (info
->executable
&& !info
->pie
&& sec
&& sec
->output_section
)
1663 highword
= frvfdpic_got_section (info
)->output_section
->vma
1664 + frvfdpic_got_section (info
)->output_offset
1665 + frvfdpic_got_initial_offset (info
);
1667 else if (entry
->lazyplt
)
1672 fd_lazy_rel_offset
= ofst
;
1674 /* A function descriptor used for lazy or local resolving is
1675 initialized such that its high word contains the output
1676 section index in which the PLT entries are located, and
1677 the low word contains the address of the lazy PLT entry
1678 entry point, that must be within the memory region
1679 assigned to that section. */
1680 lowword
= entry
->lzplt_entry
+ 4
1681 + frvfdpic_plt_section (info
)->output_offset
1682 + frvfdpic_plt_section (info
)->output_section
->vma
;
1683 highword
= _frvfdpic_osec_to_segment
1684 (output_bfd
, frvfdpic_plt_section (info
)->output_section
);
1688 /* A function descriptor for a local function gets the index
1689 of the section. For a non-local function, it's
1692 if (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1
1693 && entry
->d
.h
->dynindx
== idx
)
1696 highword
= _frvfdpic_osec_to_segment
1697 (output_bfd
, sec
->output_section
);
1700 bfd_put_32 (output_bfd
, lowword
,
1701 frvfdpic_got_section (info
)->contents
1702 + frvfdpic_got_initial_offset (info
)
1704 bfd_put_32 (output_bfd
, highword
,
1705 frvfdpic_got_section (info
)->contents
1706 + frvfdpic_got_initial_offset (info
)
1707 + entry
->fd_entry
+ 4);
1710 /* Generate code for the PLT entry. */
1711 if (entry
->plt_entry
!= (bfd_vma
) -1)
1713 bfd_byte
*plt_code
= frvfdpic_plt_section (info
)->contents
1716 BFD_ASSERT (entry
->fd_entry
);
1718 /* Figure out what kind of PLT entry we need, depending on the
1719 location of the function descriptor within the GOT. */
1720 if (entry
->fd_entry
>= -(1 << (12 - 1))
1721 && entry
->fd_entry
< (1 << (12 - 1)))
1723 /* lddi @(gr15, fd_entry), gr14 */
1724 bfd_put_32 (output_bfd
,
1725 0x9cccf000 | (entry
->fd_entry
& ((1 << 12) - 1)),
1731 if (entry
->fd_entry
>= -(1 << (16 - 1))
1732 && entry
->fd_entry
< (1 << (16 - 1)))
1734 /* setlos lo(fd_entry), gr14 */
1735 bfd_put_32 (output_bfd
,
1737 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1743 /* sethi.p hi(fd_entry), gr14
1744 setlo lo(fd_entry), gr14 */
1745 bfd_put_32 (output_bfd
,
1747 | ((entry
->fd_entry
>> 16)
1748 & (((bfd_vma
)1 << 16) - 1)),
1751 bfd_put_32 (output_bfd
,
1753 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1757 /* ldd @(gr14,gr15),gr14 */
1758 bfd_put_32 (output_bfd
, 0x9c08e14f, plt_code
);
1761 /* jmpl @(gr14,gr0) */
1762 bfd_put_32 (output_bfd
, 0x8030e000, plt_code
);
1765 /* Generate code for the lazy PLT entry. */
1766 if (entry
->lzplt_entry
!= (bfd_vma
) -1)
1768 bfd_byte
*lzplt_code
= frvfdpic_plt_section (info
)->contents
1769 + entry
->lzplt_entry
;
1770 bfd_vma resolverStub_addr
;
1772 bfd_put_32 (output_bfd
, fd_lazy_rel_offset
, lzplt_code
);
1775 resolverStub_addr
= entry
->lzplt_entry
/ FRVFDPIC_LZPLT_BLOCK_SIZE
1776 * FRVFDPIC_LZPLT_BLOCK_SIZE
+ FRVFDPIC_LZPLT_RESOLV_LOC
;
1777 if (resolverStub_addr
>= frvfdpic_plt_initial_offset (info
))
1778 resolverStub_addr
= frvfdpic_plt_initial_offset (info
) - 12;
1780 if (entry
->lzplt_entry
== resolverStub_addr
)
1782 /* This is a lazy PLT entry that includes a resolver call. */
1783 /* ldd @(gr15,gr0), gr4
1785 bfd_put_32 (output_bfd
, 0x8808f140, lzplt_code
);
1786 bfd_put_32 (output_bfd
, 0x80304000, lzplt_code
+ 4);
1790 /* bra resolverStub */
1791 bfd_put_32 (output_bfd
,
1793 | (((resolverStub_addr
- entry
->lzplt_entry
)
1794 / 4) & (((bfd_vma
)1 << 16) - 1)),
1799 /* Generate relocation for GOT entry holding the TLS offset. */
1800 if (entry
->tlsoff_entry
)
1803 bfd_vma ad
= addend
;
1805 if (entry
->symndx
!= -1
1806 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
))
1808 /* If the symbol is dynamic but binds locally, use
1812 if (entry
->symndx
== -1)
1813 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1815 ad
+= sym
->st_value
;
1816 ad
+= sec
->output_offset
;
1817 if (sec
->output_section
1818 && elf_section_data (sec
->output_section
))
1819 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1825 /* *ABS*+addend is special for TLS relocations, use only the
1827 if (info
->executable
1829 && (bfd_is_abs_section (sec
)
1830 || bfd_is_und_section (sec
)))
1832 /* If we're linking an executable, we can entirely omit the
1833 dynamic relocation if the symbol is local to this module. */
1834 else if (info
->executable
1835 && (entry
->symndx
!= -1
1836 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1839 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1844 && (bfd_is_abs_section (sec
)
1845 || bfd_is_und_section (sec
)))
1847 idx
= elf_section_data (elf_hash_table (info
)->tls_sec
)->dynindx
;
1848 ad
+= FRVFDPIC_TLS_BIAS
;
1850 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1851 _bfd_elf_section_offset
1853 frvfdpic_got_section (info
),
1854 frvfdpic_got_initial_offset (info
)
1855 + entry
->tlsoff_entry
)
1856 + frvfdpic_got_section (info
)
1857 ->output_section
->vma
1858 + frvfdpic_got_section (info
)
1860 R_FRV_TLSOFF
, idx
, ad
, entry
);
1863 bfd_put_32 (output_bfd
, ad
,
1864 frvfdpic_got_section (info
)->contents
1865 + frvfdpic_got_initial_offset (info
)
1866 + entry
->tlsoff_entry
);
1869 if (entry
->tlsdesc_entry
)
1872 bfd_vma ad
= addend
;
1874 /* If the symbol is dynamic but binds locally, use
1876 if (sec
&& (entry
->symndx
!= -1
1877 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1879 if (entry
->symndx
== -1)
1880 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1882 ad
+= sym
->st_value
;
1883 ad
+= sec
->output_offset
;
1884 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1885 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1890 /* If we didn't set up a TLS offset entry, but we're linking an
1891 executable and the symbol binds locally, we can use the
1892 module offset in the TLS descriptor in relaxations. */
1893 if (info
->executable
&& ! entry
->tlsoff_entry
)
1894 entry
->tlsoff_entry
= entry
->tlsdesc_entry
+ 4;
1896 if (info
->executable
&& !info
->pie
1898 && (bfd_is_abs_section (sec
)
1899 || bfd_is_und_section (sec
)))
1900 || entry
->symndx
!= -1
1901 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1903 /* *ABS*+addend is special for TLS relocations, use only the
1904 addend for the TLS offset, and take the module id as
1907 && (bfd_is_abs_section (sec
)
1908 || bfd_is_und_section (sec
)))
1910 /* For other TLS symbols that bind locally, add the section
1911 TLS offset to the addend. */
1913 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1915 bfd_put_32 (output_bfd
,
1916 frvfdpic_plt_section (info
)->output_section
->vma
1917 + frvfdpic_plt_section (info
)->output_offset
1918 + frvfdpic_plt_tls_ret_offset (info
),
1919 frvfdpic_got_section (info
)->contents
1920 + frvfdpic_got_initial_offset (info
)
1921 + entry
->tlsdesc_entry
);
1923 _frvfdpic_add_rofixup (output_bfd
,
1924 frvfdpic_gotfixup_section (info
),
1925 frvfdpic_got_section (info
)
1926 ->output_section
->vma
1927 + frvfdpic_got_section (info
)
1929 + frvfdpic_got_initial_offset (info
)
1930 + entry
->tlsdesc_entry
, entry
);
1932 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
);
1934 /* We've used one of the reserved fixups, so discount it so
1935 that we can check at the end that we've used them
1937 frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
--;
1939 /* While at that, make sure the ret instruction makes to the
1940 right location in the PLT. We could do it only when we
1941 got to 0, but since the check at the end will only print
1942 a warning, make sure we have the ret in place in case the
1943 warning is missed. */
1944 bfd_put_32 (output_bfd
, 0xc03a4000,
1945 frvfdpic_plt_section (info
)->contents
1946 + frvfdpic_plt_tls_ret_offset (info
));
1951 && (bfd_is_abs_section (sec
)
1952 || bfd_is_und_section (sec
)))
1954 idx
= elf_section_data (elf_hash_table (info
)->tls_sec
)->dynindx
;
1955 ad
+= FRVFDPIC_TLS_BIAS
;
1958 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1959 _bfd_elf_section_offset
1961 frvfdpic_got_section (info
),
1962 frvfdpic_got_initial_offset (info
)
1963 + entry
->tlsdesc_entry
)
1964 + frvfdpic_got_section (info
)
1965 ->output_section
->vma
1966 + frvfdpic_got_section (info
)
1968 R_FRV_TLSDESC_VALUE
, idx
, ad
, entry
);
1970 bfd_put_32 (output_bfd
, 0,
1971 frvfdpic_got_section (info
)->contents
1972 + frvfdpic_got_initial_offset (info
)
1973 + entry
->tlsdesc_entry
);
1976 bfd_put_32 (output_bfd
, ad
,
1977 frvfdpic_got_section (info
)->contents
1978 + frvfdpic_got_initial_offset (info
)
1979 + entry
->tlsdesc_entry
+ 4);
1982 /* Generate code for the get-TLS-offset PLT entry. */
1983 if (entry
->tlsplt_entry
!= (bfd_vma
) -1)
1985 bfd_byte
*plt_code
= frvfdpic_plt_section (info
)->contents
1986 + entry
->tlsplt_entry
;
1988 if (info
->executable
1989 && (entry
->symndx
!= -1
1990 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1993 bfd_vma ad
= addend
;
1995 /* sec may be NULL when referencing an undefweak symbol
1996 while linking a static executable. */
1999 BFD_ASSERT (entry
->symndx
== -1
2000 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
);
2004 if (entry
->symndx
== -1)
2005 ad
+= entry
->d
.h
->root
.u
.def
.value
;
2007 ad
+= sym
->st_value
;
2008 ad
+= sec
->output_offset
;
2009 if (sec
->output_section
2010 && elf_section_data (sec
->output_section
))
2011 idx
= elf_section_data (sec
->output_section
)->dynindx
;
2016 /* *ABS*+addend is special for TLS relocations, use only the
2017 addend for the TLS offset, and take the module id as
2020 && (bfd_is_abs_section (sec
)
2021 || bfd_is_und_section (sec
)))
2023 /* For other TLS symbols that bind locally, add the section
2024 TLS offset to the addend. */
2026 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
2028 if ((bfd_signed_vma
)ad
>= -(1 << (16 - 1))
2029 && (bfd_signed_vma
)ad
< (1 << (16 - 1)))
2031 /* setlos lo(ad), gr9 */
2032 bfd_put_32 (output_bfd
,
2035 & (((bfd_vma
)1 << 16) - 1)),
2041 /* sethi.p hi(ad), gr9
2042 setlo lo(ad), gr9 */
2043 bfd_put_32 (output_bfd
,
2046 & (((bfd_vma
)1 << 16) - 1)),
2049 bfd_put_32 (output_bfd
,
2052 & (((bfd_vma
)1 << 16) - 1)),
2057 bfd_put_32 (output_bfd
, 0xc03a4000, plt_code
);
2059 else if (entry
->tlsoff_entry
)
2061 /* Figure out what kind of PLT entry we need, depending on the
2062 location of the TLS descriptor within the GOT. */
2063 if (entry
->tlsoff_entry
>= -(1 << (12 - 1))
2064 && entry
->tlsoff_entry
< (1 << (12 - 1)))
2066 /* ldi @(gr15, tlsoff_entry), gr9 */
2067 bfd_put_32 (output_bfd
,
2068 0x92c8f000 | (entry
->tlsoff_entry
2075 if (entry
->tlsoff_entry
>= -(1 << (16 - 1))
2076 && entry
->tlsoff_entry
< (1 << (16 - 1)))
2078 /* setlos lo(tlsoff_entry), gr8 */
2079 bfd_put_32 (output_bfd
,
2081 | (entry
->tlsoff_entry
2082 & (((bfd_vma
)1 << 16) - 1)),
2088 /* sethi.p hi(tlsoff_entry), gr8
2089 setlo lo(tlsoff_entry), gr8 */
2090 bfd_put_32 (output_bfd
,
2092 | ((entry
->tlsoff_entry
>> 16)
2093 & (((bfd_vma
)1 << 16) - 1)),
2096 bfd_put_32 (output_bfd
,
2098 | (entry
->tlsoff_entry
2099 & (((bfd_vma
)1 << 16) - 1)),
2103 /* ld @(gr15,gr8),gr9 */
2104 bfd_put_32 (output_bfd
, 0x9008f108, plt_code
);
2108 bfd_put_32 (output_bfd
, 0xc03a4000, plt_code
);
2112 BFD_ASSERT (entry
->tlsdesc_entry
);
2114 /* Figure out what kind of PLT entry we need, depending on the
2115 location of the TLS descriptor within the GOT. */
2116 if (entry
->tlsdesc_entry
>= -(1 << (12 - 1))
2117 && entry
->tlsdesc_entry
< (1 << (12 - 1)))
2119 /* lddi @(gr15, tlsdesc_entry), gr8 */
2120 bfd_put_32 (output_bfd
,
2121 0x90ccf000 | (entry
->tlsdesc_entry
2128 if (entry
->tlsdesc_entry
>= -(1 << (16 - 1))
2129 && entry
->tlsdesc_entry
< (1 << (16 - 1)))
2131 /* setlos lo(tlsdesc_entry), gr8 */
2132 bfd_put_32 (output_bfd
,
2134 | (entry
->tlsdesc_entry
2135 & (((bfd_vma
)1 << 16) - 1)),
2141 /* sethi.p hi(tlsdesc_entry), gr8
2142 setlo lo(tlsdesc_entry), gr8 */
2143 bfd_put_32 (output_bfd
,
2145 | ((entry
->tlsdesc_entry
>> 16)
2146 & (((bfd_vma
)1 << 16) - 1)),
2149 bfd_put_32 (output_bfd
,
2151 | (entry
->tlsdesc_entry
2152 & (((bfd_vma
)1 << 16) - 1)),
2156 /* ldd @(gr15,gr8),gr8 */
2157 bfd_put_32 (output_bfd
, 0x9008f148, plt_code
);
2160 /* jmpl @(gr8,gr0) */
2161 bfd_put_32 (output_bfd
, 0x80308000, plt_code
);
2168 /* Handle an FRV small data reloc. */
2170 static bfd_reloc_status_type
2171 elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, relocation
,
2173 struct bfd_link_info
*info
;
2175 asection
*input_section
;
2176 Elf_Internal_Rela
*relocation
;
2182 struct bfd_link_hash_entry
*h
;
2184 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2186 gp
= (h
->u
.def
.value
2187 + h
->u
.def
.section
->output_section
->vma
2188 + h
->u
.def
.section
->output_offset
);
2190 value
-= input_section
->output_section
->vma
;
2191 value
-= (gp
- input_section
->output_section
->vma
);
2193 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2195 value
+= relocation
->r_addend
;
2197 if ((long) value
> 0x7ff || (long) value
< -0x800)
2198 return bfd_reloc_overflow
;
2200 bfd_put_32 (input_bfd
,
2201 (insn
& 0xfffff000) | (value
& 0xfff),
2202 contents
+ relocation
->r_offset
);
2204 return bfd_reloc_ok
;
2207 /* Handle an FRV small data reloc. for the u12 field. */
2209 static bfd_reloc_status_type
2210 elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, relocation
,
2212 struct bfd_link_info
*info
;
2214 asection
*input_section
;
2215 Elf_Internal_Rela
*relocation
;
2221 struct bfd_link_hash_entry
*h
;
2224 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2226 gp
= (h
->u
.def
.value
2227 + h
->u
.def
.section
->output_section
->vma
2228 + h
->u
.def
.section
->output_offset
);
2230 value
-= input_section
->output_section
->vma
;
2231 value
-= (gp
- input_section
->output_section
->vma
);
2233 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2235 value
+= relocation
->r_addend
;
2237 if ((long) value
> 0x7ff || (long) value
< -0x800)
2238 return bfd_reloc_overflow
;
2240 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
2242 insn
= (insn
& ~mask
) | ((value
& 0xfc0) << 12) | (value
& 0x3f);
2244 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2246 return bfd_reloc_ok
;
2249 /* Handle an FRV ELF HI16 reloc. */
2251 static bfd_reloc_status_type
2252 elf32_frv_relocate_hi16 (input_bfd
, relhi
, contents
, value
)
2254 Elf_Internal_Rela
*relhi
;
2260 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
2262 value
+= relhi
->r_addend
;
2263 value
= ((value
>> 16) & 0xffff);
2265 insn
= (insn
& 0xffff0000) | value
;
2267 if ((long) value
> 0xffff || (long) value
< -0x10000)
2268 return bfd_reloc_overflow
;
2270 bfd_put_32 (input_bfd
, insn
, contents
+ relhi
->r_offset
);
2271 return bfd_reloc_ok
;
2274 static bfd_reloc_status_type
2275 elf32_frv_relocate_lo16 (input_bfd
, rello
, contents
, value
)
2277 Elf_Internal_Rela
*rello
;
2283 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2285 value
+= rello
->r_addend
;
2286 value
= value
& 0xffff;
2288 insn
= (insn
& 0xffff0000) | value
;
2290 if ((long) value
> 0xffff || (long) value
< -0x10000)
2291 return bfd_reloc_overflow
;
2293 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
2294 return bfd_reloc_ok
;
2297 /* Perform the relocation for the CALL label24 instruction. */
2299 static bfd_reloc_status_type
2300 elf32_frv_relocate_label24 (input_bfd
, input_section
, rello
, contents
, value
)
2302 asection
*input_section
;
2303 Elf_Internal_Rela
*rello
;
2311 /* The format for the call instruction is:
2313 0 000000 0001111 000000000000000000
2314 label6 opcode label18
2316 The branch calculation is: pc + (4*label24)
2317 where label24 is the concatenation of label6 and label18. */
2319 /* Grab the instruction. */
2320 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2322 value
-= input_section
->output_section
->vma
+ input_section
->output_offset
;
2323 value
-= rello
->r_offset
;
2324 value
+= rello
->r_addend
;
2328 label6
= value
& 0xfc0000;
2329 label6
= label6
<< 7;
2331 label18
= value
& 0x3ffff;
2333 insn
= insn
& 0x803c0000;
2334 insn
= insn
| label6
;
2335 insn
= insn
| label18
;
2337 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
2339 return bfd_reloc_ok
;
2342 static bfd_reloc_status_type
2343 elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, relocation
,
2345 struct bfd_link_info
*info
;
2347 asection
*input_section
;
2348 Elf_Internal_Rela
*relocation
;
2354 struct bfd_link_hash_entry
*h
;
2356 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2358 gp
= (h
->u
.def
.value
2359 + h
->u
.def
.section
->output_section
->vma
2360 + h
->u
.def
.section
->output_offset
);
2362 value
-= input_section
->output_section
->vma
;
2363 value
-= (gp
- input_section
->output_section
->vma
);
2364 value
+= relocation
->r_addend
;
2365 value
= ((value
>> 16) & 0xffff);
2367 if ((long) value
> 0xffff || (long) value
< -0x10000)
2368 return bfd_reloc_overflow
;
2370 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2371 insn
= (insn
& 0xffff0000) | value
;
2373 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2374 return bfd_reloc_ok
;
2377 static bfd_reloc_status_type
2378 elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, relocation
,
2380 struct bfd_link_info
*info
;
2382 asection
*input_section
;
2383 Elf_Internal_Rela
*relocation
;
2389 struct bfd_link_hash_entry
*h
;
2391 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2393 gp
= (h
->u
.def
.value
2394 + h
->u
.def
.section
->output_section
->vma
2395 + h
->u
.def
.section
->output_offset
);
2397 value
-= input_section
->output_section
->vma
;
2398 value
-= (gp
- input_section
->output_section
->vma
);
2399 value
+= relocation
->r_addend
;
2400 value
= value
& 0xffff;
2402 if ((long) value
> 0xffff || (long) value
< -0x10000)
2403 return bfd_reloc_overflow
;
2405 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2406 insn
= (insn
& 0xffff0000) | value
;
2408 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2410 return bfd_reloc_ok
;
2413 static reloc_howto_type
*
2414 frv_reloc_type_lookup (abfd
, code
)
2415 bfd
*abfd ATTRIBUTE_UNUSED
;
2416 bfd_reloc_code_real_type code
;
2423 case BFD_RELOC_NONE
:
2424 return &elf32_frv_howto_table
[ (int) R_FRV_NONE
];
2427 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2428 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2429 return &elf32_frv_rel_32_howto
;
2431 case BFD_RELOC_CTOR
:
2432 return &elf32_frv_howto_table
[ (int) R_FRV_32
];
2434 case BFD_RELOC_FRV_LABEL16
:
2435 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL16
];
2437 case BFD_RELOC_FRV_LABEL24
:
2438 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL24
];
2440 case BFD_RELOC_FRV_LO16
:
2441 return &elf32_frv_howto_table
[ (int) R_FRV_LO16
];
2443 case BFD_RELOC_FRV_HI16
:
2444 return &elf32_frv_howto_table
[ (int) R_FRV_HI16
];
2446 case BFD_RELOC_FRV_GPREL12
:
2447 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL12
];
2449 case BFD_RELOC_FRV_GPRELU12
:
2450 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELU12
];
2452 case BFD_RELOC_FRV_GPREL32
:
2453 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL32
];
2455 case BFD_RELOC_FRV_GPRELHI
:
2456 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELHI
];
2458 case BFD_RELOC_FRV_GPRELLO
:
2459 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELLO
];
2461 case BFD_RELOC_FRV_GOT12
:
2462 return &elf32_frv_howto_table
[ (int) R_FRV_GOT12
];
2464 case BFD_RELOC_FRV_GOTHI
:
2465 return &elf32_frv_howto_table
[ (int) R_FRV_GOTHI
];
2467 case BFD_RELOC_FRV_GOTLO
:
2468 return &elf32_frv_howto_table
[ (int) R_FRV_GOTLO
];
2470 case BFD_RELOC_FRV_FUNCDESC
:
2471 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2472 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2473 return &elf32_frv_rel_funcdesc_howto
;
2474 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC
];
2476 case BFD_RELOC_FRV_FUNCDESC_GOT12
:
2477 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOT12
];
2479 case BFD_RELOC_FRV_FUNCDESC_GOTHI
:
2480 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTHI
];
2482 case BFD_RELOC_FRV_FUNCDESC_GOTLO
:
2483 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTLO
];
2485 case BFD_RELOC_FRV_FUNCDESC_VALUE
:
2486 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2487 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2488 return &elf32_frv_rel_funcdesc_value_howto
;
2489 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_VALUE
];
2491 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12
:
2492 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFF12
];
2494 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI
:
2495 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFHI
];
2497 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO
:
2498 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFLO
];
2500 case BFD_RELOC_FRV_GOTOFF12
:
2501 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFF12
];
2503 case BFD_RELOC_FRV_GOTOFFHI
:
2504 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFHI
];
2506 case BFD_RELOC_FRV_GOTOFFLO
:
2507 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFLO
];
2509 case BFD_RELOC_FRV_GETTLSOFF
:
2510 return &elf32_frv_howto_table
[ (int) R_FRV_GETTLSOFF
];
2512 case BFD_RELOC_FRV_TLSDESC_VALUE
:
2513 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2514 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2515 return &elf32_frv_rel_tlsdesc_value_howto
;
2516 return &elf32_frv_howto_table
[ (int) R_FRV_TLSDESC_VALUE
];
2518 case BFD_RELOC_FRV_GOTTLSDESC12
:
2519 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESC12
];
2521 case BFD_RELOC_FRV_GOTTLSDESCHI
:
2522 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESCHI
];
2524 case BFD_RELOC_FRV_GOTTLSDESCLO
:
2525 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESCLO
];
2527 case BFD_RELOC_FRV_TLSMOFF12
:
2528 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFF12
];
2530 case BFD_RELOC_FRV_TLSMOFFHI
:
2531 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFFHI
];
2533 case BFD_RELOC_FRV_TLSMOFFLO
:
2534 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFFLO
];
2536 case BFD_RELOC_FRV_GOTTLSOFF12
:
2537 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFF12
];
2539 case BFD_RELOC_FRV_GOTTLSOFFHI
:
2540 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFFHI
];
2542 case BFD_RELOC_FRV_GOTTLSOFFLO
:
2543 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFFLO
];
2545 case BFD_RELOC_FRV_TLSOFF
:
2546 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2547 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2548 return &elf32_frv_rel_tlsoff_howto
;
2549 return &elf32_frv_howto_table
[ (int) R_FRV_TLSOFF
];
2551 case BFD_RELOC_FRV_TLSDESC_RELAX
:
2552 return &elf32_frv_howto_table
[ (int) R_FRV_TLSDESC_RELAX
];
2554 case BFD_RELOC_FRV_GETTLSOFF_RELAX
:
2555 return &elf32_frv_howto_table
[ (int) R_FRV_GETTLSOFF_RELAX
];
2557 case BFD_RELOC_FRV_TLSOFF_RELAX
:
2558 return &elf32_frv_howto_table
[ (int) R_FRV_TLSOFF_RELAX
];
2560 case BFD_RELOC_FRV_TLSMOFF
:
2561 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFF
];
2563 case BFD_RELOC_VTABLE_INHERIT
:
2564 return &elf32_frv_vtinherit_howto
;
2566 case BFD_RELOC_VTABLE_ENTRY
:
2567 return &elf32_frv_vtentry_howto
;
2573 /* Set the howto pointer for an FRV ELF reloc. */
2576 frv_info_to_howto_rela (abfd
, cache_ptr
, dst
)
2577 bfd
*abfd ATTRIBUTE_UNUSED
;
2579 Elf_Internal_Rela
*dst
;
2581 unsigned int r_type
;
2583 r_type
= ELF32_R_TYPE (dst
->r_info
);
2586 case R_FRV_GNU_VTINHERIT
:
2587 cache_ptr
->howto
= &elf32_frv_vtinherit_howto
;
2590 case R_FRV_GNU_VTENTRY
:
2591 cache_ptr
->howto
= &elf32_frv_vtentry_howto
;
2595 cache_ptr
->howto
= & elf32_frv_howto_table
[r_type
];
2600 /* Set the howto pointer for an FRV ELF REL reloc. */
2602 frvfdpic_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
2603 arelent
*cache_ptr
, Elf_Internal_Rela
*dst
)
2605 unsigned int r_type
;
2607 r_type
= ELF32_R_TYPE (dst
->r_info
);
2611 cache_ptr
->howto
= &elf32_frv_rel_32_howto
;
2614 case R_FRV_FUNCDESC
:
2615 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_howto
;
2618 case R_FRV_FUNCDESC_VALUE
:
2619 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_value_howto
;
2622 case R_FRV_TLSDESC_VALUE
:
2623 cache_ptr
->howto
= &elf32_frv_rel_tlsdesc_value_howto
;
2627 cache_ptr
->howto
= &elf32_frv_rel_tlsoff_howto
;
2631 cache_ptr
->howto
= NULL
;
2636 /* Perform a single relocation. By default we use the standard BFD
2637 routines, but a few relocs, we have to do them ourselves. */
2639 static bfd_reloc_status_type
2640 frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
, rel
,
2642 reloc_howto_type
*howto
;
2644 asection
*input_section
;
2646 Elf_Internal_Rela
*rel
;
2649 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2650 contents
, rel
->r_offset
, relocation
,
2655 /* Relocate an FRV ELF section.
2657 The RELOCATE_SECTION function is called by the new ELF backend linker
2658 to handle the relocations for a section.
2660 The relocs are always passed as Rela structures; if the section
2661 actually uses Rel structures, the r_addend field will always be
2664 This function is responsible for adjusting the section contents as
2665 necessary, and (if using Rela relocs and generating a relocatable
2666 output file) adjusting the reloc addend as necessary.
2668 This function does not have to worry about setting the reloc
2669 address or the reloc symbol index.
2671 LOCAL_SYMS is a pointer to the swapped in local symbols.
2673 LOCAL_SECTIONS is an array giving the section in the input file
2674 corresponding to the st_shndx field of each local symbol.
2676 The global hash table entry for the global symbols can be found
2677 via elf_sym_hashes (input_bfd).
2679 When generating relocatable output, this function must handle
2680 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2681 going to be the section symbol corresponding to the output
2682 section, which means that the addend must be adjusted
2686 elf32_frv_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2687 contents
, relocs
, local_syms
, local_sections
)
2688 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2689 struct bfd_link_info
*info
;
2691 asection
*input_section
;
2693 Elf_Internal_Rela
*relocs
;
2694 Elf_Internal_Sym
*local_syms
;
2695 asection
**local_sections
;
2697 Elf_Internal_Shdr
*symtab_hdr
;
2698 struct elf_link_hash_entry
**sym_hashes
;
2699 Elf_Internal_Rela
*rel
;
2700 Elf_Internal_Rela
*relend
;
2701 unsigned isec_segment
, got_segment
, plt_segment
, gprel_segment
, tls_segment
,
2703 int silence_segment_error
= !(info
->shared
|| info
->pie
);
2706 if (info
->relocatable
)
2709 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
2710 sym_hashes
= elf_sym_hashes (input_bfd
);
2711 relend
= relocs
+ input_section
->reloc_count
;
2713 isec_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2714 input_section
->output_section
);
2715 if (IS_FDPIC (output_bfd
) && frvfdpic_got_section (info
))
2716 got_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2717 frvfdpic_got_section (info
)
2721 if (IS_FDPIC (output_bfd
) && frvfdpic_gotfixup_section (info
))
2722 gprel_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2723 frvfdpic_gotfixup_section (info
)
2727 if (IS_FDPIC (output_bfd
) && frvfdpic_plt_section (info
))
2728 plt_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2729 frvfdpic_plt_section (info
)
2733 if (elf_hash_table (info
)->tls_sec
)
2734 tls_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2735 elf_hash_table (info
)->tls_sec
);
2739 for (rel
= relocs
; rel
< relend
; rel
++)
2741 reloc_howto_type
*howto
;
2742 unsigned long r_symndx
;
2743 Elf_Internal_Sym
*sym
;
2745 struct elf_link_hash_entry
*h
;
2747 bfd_reloc_status_type r
;
2748 const char * name
= NULL
;
2751 struct frvfdpic_relocs_info
*picrel
;
2752 bfd_vma orig_addend
= rel
->r_addend
;
2754 r_type
= ELF32_R_TYPE (rel
->r_info
);
2756 if ( r_type
== R_FRV_GNU_VTINHERIT
2757 || r_type
== R_FRV_GNU_VTENTRY
)
2760 /* This is a final link. */
2761 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2762 howto
= elf32_frv_howto_table
+ ELF32_R_TYPE (rel
->r_info
);
2767 if (r_symndx
< symtab_hdr
->sh_info
)
2769 sym
= local_syms
+ r_symndx
;
2770 osec
= sec
= local_sections
[r_symndx
];
2771 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2773 name
= bfd_elf_string_from_elf_section
2774 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
2775 name
= (name
== NULL
) ? bfd_section_name (input_bfd
, sec
) : name
;
2779 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2781 while (h
->root
.type
== bfd_link_hash_indirect
2782 || h
->root
.type
== bfd_link_hash_warning
)
2783 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2785 name
= h
->root
.root
.string
;
2787 if ((h
->root
.type
== bfd_link_hash_defined
2788 || h
->root
.type
== bfd_link_hash_defweak
))
2790 if (/* TLSMOFF forces local binding. */
2791 r_type
!= R_FRV_TLSMOFF
2792 && ! FRVFDPIC_SYM_LOCAL (info
, h
))
2799 sec
= h
->root
.u
.def
.section
;
2800 relocation
= (h
->root
.u
.def
.value
2801 + sec
->output_section
->vma
2802 + sec
->output_offset
);
2805 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2809 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
2810 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
2814 if (! ((*info
->callbacks
->undefined_symbol
)
2815 (info
, h
->root
.root
.string
, input_bfd
,
2816 input_section
, rel
->r_offset
,
2817 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
2818 || ELF_ST_VISIBILITY (h
->other
)))))
2829 if (! IS_FDPIC (output_bfd
))
2835 case R_FRV_FUNCDESC_GOT12
:
2836 case R_FRV_FUNCDESC_GOTHI
:
2837 case R_FRV_FUNCDESC_GOTLO
:
2838 case R_FRV_GOTOFF12
:
2839 case R_FRV_GOTOFFHI
:
2840 case R_FRV_GOTOFFLO
:
2841 case R_FRV_FUNCDESC_GOTOFF12
:
2842 case R_FRV_FUNCDESC_GOTOFFHI
:
2843 case R_FRV_FUNCDESC_GOTOFFLO
:
2844 case R_FRV_FUNCDESC
:
2845 case R_FRV_FUNCDESC_VALUE
:
2846 case R_FRV_GETTLSOFF
:
2847 case R_FRV_TLSDESC_VALUE
:
2848 case R_FRV_GOTTLSDESC12
:
2849 case R_FRV_GOTTLSDESCHI
:
2850 case R_FRV_GOTTLSDESCLO
:
2851 case R_FRV_TLSMOFF12
:
2852 case R_FRV_TLSMOFFHI
:
2853 case R_FRV_TLSMOFFLO
:
2854 case R_FRV_GOTTLSOFF12
:
2855 case R_FRV_GOTTLSOFFHI
:
2856 case R_FRV_GOTTLSOFFLO
:
2858 case R_FRV_TLSDESC_RELAX
:
2859 case R_FRV_GETTLSOFF_RELAX
:
2860 case R_FRV_TLSOFF_RELAX
:
2863 picrel
= frvfdpic_relocs_info_for_global (frvfdpic_relocs_info
2864 (info
), input_bfd
, h
,
2865 orig_addend
, INSERT
);
2867 /* In order to find the entry we created before, we must
2868 use the original addend, not the one that may have been
2869 modified by _bfd_elf_rela_local_sym(). */
2870 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
2871 (info
), input_bfd
, r_symndx
,
2872 orig_addend
, INSERT
);
2876 if (!_frvfdpic_emit_got_relocs_plt_entries (picrel
, output_bfd
, info
,
2880 (*_bfd_error_handler
)
2881 (_("%B: relocation at `%A+0x%x' references symbol `%s' with nonzero addend"),
2882 input_bfd
, input_section
, rel
->r_offset
, name
);
2892 if (h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
))
2894 info
->callbacks
->warning
2895 (info
, _("relocation references symbol not defined in the module"),
2896 name
, input_bfd
, input_section
, rel
->r_offset
);
2904 case R_FRV_GETTLSOFF
:
2905 case R_FRV_TLSDESC_VALUE
:
2906 case R_FRV_GOTTLSDESC12
:
2907 case R_FRV_GOTTLSDESCHI
:
2908 case R_FRV_GOTTLSDESCLO
:
2909 case R_FRV_TLSMOFF12
:
2910 case R_FRV_TLSMOFFHI
:
2911 case R_FRV_TLSMOFFLO
:
2912 case R_FRV_GOTTLSOFF12
:
2913 case R_FRV_GOTTLSOFFHI
:
2914 case R_FRV_GOTTLSOFFLO
:
2916 case R_FRV_TLSDESC_RELAX
:
2917 case R_FRV_GETTLSOFF_RELAX
:
2918 case R_FRV_TLSOFF_RELAX
:
2920 if (sec
&& (bfd_is_abs_section (sec
) || bfd_is_und_section (sec
)))
2921 relocation
+= tls_biased_base (info
);
2928 /* Try to apply TLS relaxations. */
2933 #define LOCAL_EXEC_P(info, picrel) \
2934 ((info)->executable \
2935 && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h)))
2936 #define INITIAL_EXEC_P(info, picrel) \
2937 (((info)->executable || (info)->flags & DF_STATIC_TLS) \
2938 && (picrel)->tlsoff_entry)
2940 #define IN_RANGE_FOR_OFST12_P(value) \
2941 ((bfd_vma)((value) + 2048) < (bfd_vma)4096)
2942 #define IN_RANGE_FOR_SETLOS_P(value) \
2943 ((bfd_vma)((value) + 32768) < (bfd_vma)65536)
2944 #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \
2945 (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info)))
2947 #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2948 (LOCAL_EXEC_P ((info), (picrel)) \
2949 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2950 #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \
2951 (INITIAL_EXEC_P ((info), (picrel)) \
2952 && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry))
2954 #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \
2955 (LOCAL_EXEC_P ((info), (picrel)))
2956 #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \
2957 (INITIAL_EXEC_P ((info), (picrel)))
2959 #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2960 (LOCAL_EXEC_P ((info), (picrel)) \
2961 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2963 case R_FRV_GETTLSOFF
:
2964 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2966 /* Is this a call instruction? */
2967 if ((insn
& (unsigned long)0x01fc0000) != 0x003c0000)
2969 r
= info
->callbacks
->warning
2971 _("R_FRV_GETTLSOFF not applied to a call instruction"),
2972 name
, input_bfd
, input_section
, rel
->r_offset
);
2976 if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info
, picrel
,
2977 relocation
+ rel
->r_addend
))
2979 /* Replace the call instruction (except the packing bit)
2980 with setlos #tlsmofflo(symbol+offset), gr9. */
2981 insn
&= (unsigned long)0x80000000;
2982 insn
|= (unsigned long)0x12fc0000;
2983 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
2985 r_type
= R_FRV_TLSMOFFLO
;
2986 howto
= elf32_frv_howto_table
+ r_type
;
2987 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
2990 else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info
, picrel
))
2992 /* Replace the call instruction (except the packing bit)
2993 with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */
2994 insn
&= (unsigned long)0x80000000;
2995 insn
|= (unsigned long)0x12c8f000;
2996 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
2998 r_type
= R_FRV_GOTTLSOFF12
;
2999 howto
= elf32_frv_howto_table
+ r_type
;
3000 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3005 case R_FRV_GOTTLSDESC12
:
3006 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3008 /* Is this an lddi instruction? */
3009 if ((insn
& (unsigned long)0x01fc0000) != 0x00cc0000)
3011 r
= info
->callbacks
->warning
3013 _("R_FRV_GOTTLSDESC12 not applied to an lddi instruction"),
3014 name
, input_bfd
, input_section
, rel
->r_offset
);
3018 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3019 relocation
+ rel
->r_addend
)
3020 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3023 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3024 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3025 Preserve the packing bit. */
3026 insn
= (insn
& (unsigned long)0x80000000)
3027 | ((insn
+ (unsigned long)0x02000000)
3028 & (unsigned long)0x7e000000);
3029 insn
|= (unsigned long)0x00fc0000;
3030 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3032 r_type
= R_FRV_TLSMOFFLO
;
3033 howto
= elf32_frv_howto_table
+ r_type
;
3034 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3037 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3038 relocation
+ rel
->r_addend
))
3040 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3041 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3042 Preserve the packing bit. */
3043 insn
= (insn
& (unsigned long)0x80000000)
3044 | ((insn
+ (unsigned long)0x02000000)
3045 & (unsigned long)0x7e000000);
3046 insn
|= (unsigned long)0x00f80000;
3047 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3049 r_type
= R_FRV_TLSMOFFHI
;
3050 howto
= elf32_frv_howto_table
+ r_type
;
3051 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3054 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3056 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3057 with ldi @(grB, #gottlsoff12(symbol+offset),
3058 gr<C+1>. Preserve the packing bit. If gottlsoff12
3059 overflows, we'll error out, but that's sort-of ok,
3060 since we'd started with gottlsdesc12, that's actually
3061 more demanding. Compiling with -fPIE instead of
3062 -fpie would fix it; linking with --relax should fix
3064 insn
= (insn
& (unsigned long)0x80cbf000)
3065 | ((insn
+ (unsigned long)0x02000000)
3066 & (unsigned long)0x7e000000);
3067 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3069 r_type
= R_FRV_GOTTLSOFF12
;
3070 howto
= elf32_frv_howto_table
+ r_type
;
3071 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3076 case R_FRV_GOTTLSDESCHI
:
3077 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3079 /* Is this a sethi instruction? */
3080 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3082 r
= info
->callbacks
->warning
3084 _("R_FRV_GOTTLSDESCHI not applied to a sethi instruction"),
3085 name
, input_bfd
, input_section
, rel
->r_offset
);
3089 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3090 relocation
+ rel
->r_addend
)
3091 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3092 && IN_RANGE_FOR_SETLOS_P (picrel
->tlsoff_entry
)))
3094 /* Replace sethi with a nop. Preserve the packing bit. */
3095 insn
&= (unsigned long)0x80000000;
3096 insn
|= (unsigned long)0x00880000;
3097 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3099 /* Nothing to relocate. */
3103 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3105 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3106 r_type
= R_FRV_GOTTLSOFFHI
;
3107 howto
= elf32_frv_howto_table
+ r_type
;
3108 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3113 case R_FRV_GOTTLSDESCLO
:
3114 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3116 /* Is this a setlo or setlos instruction? */
3117 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3119 r
= info
->callbacks
->warning
3121 _("R_FRV_GOTTLSDESCLO"
3122 " not applied to a setlo or setlos instruction"),
3123 name
, input_bfd
, input_section
, rel
->r_offset
);
3127 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3128 relocation
+ rel
->r_addend
)
3129 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3130 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3132 /* Replace setlo/setlos with a nop. Preserve the
3134 insn
&= (unsigned long)0x80000000;
3135 insn
|= (unsigned long)0x00880000;
3136 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3138 /* Nothing to relocate. */
3142 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3144 /* If the corresponding sethi (if it exists) decayed
3145 to a nop, make sure this becomes (or already is) a
3146 setlos, not setlo. */
3147 if (IN_RANGE_FOR_SETLOS_P (picrel
->tlsoff_entry
))
3149 insn
|= (unsigned long)0x00080000;
3150 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3153 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3154 r_type
= R_FRV_GOTTLSOFFLO
;
3155 howto
= elf32_frv_howto_table
+ r_type
;
3156 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3161 case R_FRV_TLSDESC_RELAX
:
3162 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3164 /* Is this an ldd instruction? */
3165 if ((insn
& (unsigned long)0x01fc0fc0) != 0x00080140)
3167 r
= info
->callbacks
->warning
3169 _("R_FRV_TLSDESC_RELAX not applied to an ldd instruction"),
3170 name
, input_bfd
, input_section
, rel
->r_offset
);
3174 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3175 relocation
+ rel
->r_addend
)
3176 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3179 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3180 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3181 Preserve the packing bit. */
3182 insn
= (insn
& (unsigned long)0x80000000)
3183 | ((insn
+ (unsigned long)0x02000000)
3184 & (unsigned long)0x7e000000);
3185 insn
|= (unsigned long)0x00fc0000;
3186 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3188 r_type
= R_FRV_TLSMOFFLO
;
3189 howto
= elf32_frv_howto_table
+ r_type
;
3190 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3193 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3194 relocation
+ rel
->r_addend
))
3196 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3197 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3198 Preserve the packing bit. */
3199 insn
= (insn
& (unsigned long)0x80000000)
3200 | ((insn
+ (unsigned long)0x02000000)
3201 & (unsigned long)0x7e000000);
3202 insn
|= (unsigned long)0x00f80000;
3203 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3205 r_type
= R_FRV_TLSMOFFHI
;
3206 howto
= elf32_frv_howto_table
+ r_type
;
3207 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3210 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3211 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
))
3213 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3214 with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>.
3215 Preserve the packing bit. */
3216 insn
= (insn
& (unsigned long)0x8003f000)
3217 | (unsigned long)0x00c80000
3218 | ((insn
+ (unsigned long)0x02000000)
3219 & (unsigned long)0x7e000000);
3220 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3222 r_type
= R_FRV_GOTTLSOFF12
;
3223 howto
= elf32_frv_howto_table
+ r_type
;
3224 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3227 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3229 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3230 with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>.
3231 Preserve the packing bit. */
3232 insn
= (insn
& (unsigned long)0x81ffffbf)
3233 | ((insn
+ (unsigned long)0x02000000)
3234 & (unsigned long)0x7e000000);
3235 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3237 /* #tlsoff(symbol+offset) is just a relaxation
3238 annotation, so there's nothing left to
3245 case R_FRV_GETTLSOFF_RELAX
:
3246 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3248 /* Is this a calll or callil instruction? */
3249 if ((insn
& (unsigned long)0x7ff80fc0) != 0x02300000)
3251 r
= info
->callbacks
->warning
3253 _("R_FRV_GETTLSOFF_RELAX"
3254 " not applied to a calll instruction"),
3255 name
, input_bfd
, input_section
, rel
->r_offset
);
3259 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3260 relocation
+ rel
->r_addend
)
3261 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3264 /* Replace calll with a nop. Preserve the packing bit. */
3265 insn
&= (unsigned long)0x80000000;
3266 insn
|= (unsigned long)0x00880000;
3267 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3269 /* Nothing to relocate. */
3273 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3274 relocation
+ rel
->r_addend
))
3276 /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9.
3277 Preserve the packing bit. */
3278 insn
&= (unsigned long)0x80000000;
3279 insn
|= (unsigned long)0x12f40000;
3280 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3282 r_type
= R_FRV_TLSMOFFLO
;
3283 howto
= elf32_frv_howto_table
+ r_type
;
3284 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3287 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3289 /* Replace calll with a nop. Preserve the packing bit. */
3290 insn
&= (unsigned long)0x80000000;
3291 insn
|= (unsigned long)0x00880000;
3292 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3294 /* Nothing to relocate. */
3300 case R_FRV_GOTTLSOFF12
:
3301 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3303 /* Is this an ldi instruction? */
3304 if ((insn
& (unsigned long)0x01fc0000) != 0x00c80000)
3306 r
= info
->callbacks
->warning
3308 _("R_FRV_GOTTLSOFF12 not applied to an ldi instruction"),
3309 name
, input_bfd
, input_section
, rel
->r_offset
);
3313 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3314 relocation
+ rel
->r_addend
))
3316 /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC
3317 with setlos #tlsmofflo(symbol+offset), grC.
3318 Preserve the packing bit. */
3319 insn
&= (unsigned long)0xfe000000;
3320 insn
|= (unsigned long)0x00fc0000;
3321 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3323 r_type
= R_FRV_TLSMOFFLO
;
3324 howto
= elf32_frv_howto_table
+ r_type
;
3325 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3330 case R_FRV_GOTTLSOFFHI
:
3331 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3333 /* Is this a sethi instruction? */
3334 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3336 r
= info
->callbacks
->warning
3338 _("R_FRV_GOTTLSOFFHI not applied to a sethi instruction"),
3339 name
, input_bfd
, input_section
, rel
->r_offset
);
3343 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3344 relocation
+ rel
->r_addend
)
3345 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3346 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3348 /* Replace sethi with a nop. Preserve the packing bit. */
3349 insn
&= (unsigned long)0x80000000;
3350 insn
|= (unsigned long)0x00880000;
3351 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3353 /* Nothing to relocate. */
3359 case R_FRV_GOTTLSOFFLO
:
3360 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3362 /* Is this a setlo or setlos instruction? */
3363 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3365 r
= info
->callbacks
->warning
3367 _("R_FRV_GOTTLSOFFLO"
3368 " not applied to a setlo or setlos instruction"),
3369 name
, input_bfd
, input_section
, rel
->r_offset
);
3373 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3374 relocation
+ rel
->r_addend
)
3375 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3376 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3378 /* Replace setlo/setlos with a nop. Preserve the
3380 insn
&= (unsigned long)0x80000000;
3381 insn
|= (unsigned long)0x00880000;
3382 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3384 /* Nothing to relocate. */
3390 case R_FRV_TLSOFF_RELAX
:
3391 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3393 /* Is this an ld instruction? */
3394 if ((insn
& (unsigned long)0x01fc0fc0) != 0x00080100)
3396 r
= info
->callbacks
->warning
3398 _("R_FRV_TLSOFF_RELAX not applied to an ld instruction"),
3399 name
, input_bfd
, input_section
, rel
->r_offset
);
3403 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3404 relocation
+ rel
->r_addend
))
3406 /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC
3407 with setlos #tlsmofflo(symbol+offset), grC.
3408 Preserve the packing bit. */
3409 insn
&= (unsigned long)0xfe000000;
3410 insn
|= (unsigned long)0x00fc0000;
3411 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3413 r_type
= R_FRV_TLSMOFFLO
;
3414 howto
= elf32_frv_howto_table
+ r_type
;
3415 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3418 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3419 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
))
3421 /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC
3422 with ldi @(grB, #gottlsoff12(symbol+offset), grC.
3423 Preserve the packing bit. */
3424 insn
= (insn
& (unsigned long)0xfe03f000)
3425 | (unsigned long)0x00c80000;;
3426 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3428 r_type
= R_FRV_GOTTLSOFF12
;
3429 howto
= elf32_frv_howto_table
+ r_type
;
3430 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3435 case R_FRV_TLSMOFFHI
:
3436 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3438 /* Is this a sethi instruction? */
3439 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3441 r
= info
->callbacks
->warning
3443 _("R_FRV_TLSMOFFHI not applied to a sethi instruction"),
3444 name
, input_bfd
, input_section
, rel
->r_offset
);
3448 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3451 /* Replace sethi with a nop. Preserve the packing bit. */
3452 insn
&= (unsigned long)0x80000000;
3453 insn
|= (unsigned long)0x00880000;
3454 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3456 /* Nothing to relocate. */
3462 case R_FRV_TLSMOFFLO
:
3463 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3465 /* Is this a setlo or setlos instruction? */
3466 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3468 r
= info
->callbacks
->warning
3471 " not applied to a setlo or setlos instruction"),
3472 name
, input_bfd
, input_section
, rel
->r_offset
);
3476 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3478 /* If the corresponding sethi (if it exists) decayed
3479 to a nop, make sure this becomes (or already is) a
3480 setlos, not setlo. */
3482 insn
|= (unsigned long)0x00080000;
3483 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3489 There's nothing to relax in these:
3505 check_segment
[0] = isec_segment
;
3506 if (! IS_FDPIC (output_bfd
))
3507 check_segment
[1] = isec_segment
;
3508 else if (picrel
->plt
)
3510 relocation
= frvfdpic_plt_section (info
)->output_section
->vma
3511 + frvfdpic_plt_section (info
)->output_offset
3512 + picrel
->plt_entry
;
3513 check_segment
[1] = plt_segment
;
3515 /* We don't want to warn on calls to undefined weak symbols,
3516 as calls to them must be protected by non-NULL tests
3517 anyway, and unprotected calls would invoke undefined
3519 else if (picrel
->symndx
== -1
3520 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefweak
)
3521 check_segment
[1] = check_segment
[0];
3523 check_segment
[1] = sec
3524 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3531 relocation
= picrel
->got_entry
;
3532 check_segment
[0] = check_segment
[1] = got_segment
;
3535 case R_FRV_FUNCDESC_GOT12
:
3536 case R_FRV_FUNCDESC_GOTHI
:
3537 case R_FRV_FUNCDESC_GOTLO
:
3538 relocation
= picrel
->fdgot_entry
;
3539 check_segment
[0] = check_segment
[1] = got_segment
;
3542 case R_FRV_GOTOFFHI
:
3543 case R_FRV_GOTOFF12
:
3544 case R_FRV_GOTOFFLO
:
3545 relocation
-= frvfdpic_got_section (info
)->output_section
->vma
3546 + frvfdpic_got_section (info
)->output_offset
3547 + frvfdpic_got_initial_offset (info
);
3548 check_segment
[0] = got_segment
;
3549 check_segment
[1] = sec
3550 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3554 case R_FRV_FUNCDESC_GOTOFF12
:
3555 case R_FRV_FUNCDESC_GOTOFFHI
:
3556 case R_FRV_FUNCDESC_GOTOFFLO
:
3557 relocation
= picrel
->fd_entry
;
3558 check_segment
[0] = check_segment
[1] = got_segment
;
3561 case R_FRV_FUNCDESC
:
3564 bfd_vma addend
= rel
->r_addend
;
3566 if (! (h
&& h
->root
.type
== bfd_link_hash_undefweak
3567 && FRVFDPIC_SYM_LOCAL (info
, h
)))
3569 /* If the symbol is dynamic and there may be dynamic
3570 symbol resolution because we are or are linked with a
3571 shared library, emit a FUNCDESC relocation such that
3572 the dynamic linker will allocate the function
3573 descriptor. If the symbol needs a non-local function
3574 descriptor but binds locally (e.g., its visibility is
3575 protected, emit a dynamic relocation decayed to
3577 if (h
&& ! FRVFDPIC_FUNCDESC_LOCAL (info
, h
)
3578 && FRVFDPIC_SYM_LOCAL (info
, h
)
3579 && !(info
->executable
&& !info
->pie
))
3581 dynindx
= elf_section_data (h
->root
.u
.def
.section
3582 ->output_section
)->dynindx
;
3583 addend
+= h
->root
.u
.def
.section
->output_offset
3584 + h
->root
.u
.def
.value
;
3586 else if (h
&& ! FRVFDPIC_FUNCDESC_LOCAL (info
, h
))
3590 info
->callbacks
->warning
3591 (info
, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"),
3592 name
, input_bfd
, input_section
, rel
->r_offset
);
3595 dynindx
= h
->dynindx
;
3599 /* Otherwise, we know we have a private function
3600 descriptor, so reference it directly. */
3601 BFD_ASSERT (picrel
->privfd
);
3603 dynindx
= elf_section_data (frvfdpic_got_section (info
)
3604 ->output_section
)->dynindx
;
3605 addend
= frvfdpic_got_section (info
)->output_offset
3606 + frvfdpic_got_initial_offset (info
)
3610 /* If there is room for dynamic symbol resolution, emit
3611 the dynamic relocation. However, if we're linking an
3612 executable at a fixed location, we won't have emitted a
3613 dynamic symbol entry for the got section, so idx will
3614 be zero, which means we can and should compute the
3615 address of the private descriptor ourselves. */
3616 if (info
->executable
&& !info
->pie
3617 && (!h
|| FRVFDPIC_FUNCDESC_LOCAL (info
, h
)))
3619 addend
+= frvfdpic_got_section (info
)->output_section
->vma
;
3620 if ((bfd_get_section_flags (output_bfd
,
3621 input_section
->output_section
)
3622 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3624 if (_frvfdpic_osec_readonly_p (output_bfd
,
3628 info
->callbacks
->warning
3630 _("cannot emit fixups in read-only section"),
3631 name
, input_bfd
, input_section
, rel
->r_offset
);
3634 _frvfdpic_add_rofixup (output_bfd
,
3635 frvfdpic_gotfixup_section
3637 _bfd_elf_section_offset
3639 input_section
, rel
->r_offset
)
3641 ->output_section
->vma
3642 + input_section
->output_offset
,
3646 else if ((bfd_get_section_flags (output_bfd
,
3647 input_section
->output_section
)
3648 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3650 if (_frvfdpic_osec_readonly_p (output_bfd
,
3654 info
->callbacks
->warning
3656 _("cannot emit dynamic relocations in read-only section"),
3657 name
, input_bfd
, input_section
, rel
->r_offset
);
3660 _frvfdpic_add_dyn_reloc (output_bfd
,
3661 frvfdpic_gotrel_section (info
),
3662 _bfd_elf_section_offset
3664 input_section
, rel
->r_offset
)
3666 ->output_section
->vma
3667 + input_section
->output_offset
,
3668 r_type
, dynindx
, addend
, picrel
);
3671 addend
+= frvfdpic_got_section (info
)->output_section
->vma
;
3674 /* We want the addend in-place because dynamic
3675 relocations are REL. Setting relocation to it should
3676 arrange for it to be installed. */
3677 relocation
= addend
- rel
->r_addend
;
3679 check_segment
[0] = check_segment
[1] = got_segment
;
3683 if (! IS_FDPIC (output_bfd
))
3685 check_segment
[0] = check_segment
[1] = -1;
3689 case R_FRV_FUNCDESC_VALUE
:
3692 bfd_vma addend
= rel
->r_addend
;
3694 /* If the symbol is dynamic but binds locally, use
3696 if (h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
))
3698 if (addend
&& r_type
== R_FRV_FUNCDESC_VALUE
)
3700 info
->callbacks
->warning
3701 (info
, _("R_FRV_FUNCDESC_VALUE references dynamic symbol with nonzero addend"),
3702 name
, input_bfd
, input_section
, rel
->r_offset
);
3705 dynindx
= h
->dynindx
;
3710 addend
+= h
->root
.u
.def
.value
;
3712 addend
+= sym
->st_value
;
3714 addend
+= osec
->output_offset
;
3715 if (osec
&& osec
->output_section
3716 && ! bfd_is_abs_section (osec
->output_section
)
3717 && ! bfd_is_und_section (osec
->output_section
))
3718 dynindx
= elf_section_data (osec
->output_section
)->dynindx
;
3723 /* If we're linking an executable at a fixed address, we
3724 can omit the dynamic relocation as long as the symbol
3725 is defined in the current link unit (which is implied
3726 by its output section not being NULL). */
3727 if (info
->executable
&& !info
->pie
3728 && (!h
|| FRVFDPIC_SYM_LOCAL (info
, h
)))
3731 addend
+= osec
->output_section
->vma
;
3732 if (IS_FDPIC (input_bfd
)
3733 && (bfd_get_section_flags (output_bfd
,
3734 input_section
->output_section
)
3735 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3737 if (_frvfdpic_osec_readonly_p (output_bfd
,
3741 info
->callbacks
->warning
3743 _("cannot emit fixups in read-only section"),
3744 name
, input_bfd
, input_section
, rel
->r_offset
);
3747 if (!h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
3749 _frvfdpic_add_rofixup (output_bfd
,
3750 frvfdpic_gotfixup_section
3752 _bfd_elf_section_offset
3754 input_section
, rel
->r_offset
)
3756 ->output_section
->vma
3757 + input_section
->output_offset
,
3759 if (r_type
== R_FRV_FUNCDESC_VALUE
)
3760 _frvfdpic_add_rofixup
3762 frvfdpic_gotfixup_section (info
),
3763 _bfd_elf_section_offset
3765 input_section
, rel
->r_offset
)
3766 + input_section
->output_section
->vma
3767 + input_section
->output_offset
+ 4, picrel
);
3773 if ((bfd_get_section_flags (output_bfd
,
3774 input_section
->output_section
)
3775 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3777 if (_frvfdpic_osec_readonly_p (output_bfd
,
3781 info
->callbacks
->warning
3783 _("cannot emit dynamic relocations in read-only section"),
3784 name
, input_bfd
, input_section
, rel
->r_offset
);
3787 _frvfdpic_add_dyn_reloc (output_bfd
,
3788 frvfdpic_gotrel_section (info
),
3789 _bfd_elf_section_offset
3791 input_section
, rel
->r_offset
)
3793 ->output_section
->vma
3794 + input_section
->output_offset
,
3795 r_type
, dynindx
, addend
, picrel
);
3798 addend
+= osec
->output_section
->vma
;
3799 /* We want the addend in-place because dynamic
3800 relocations are REL. Setting relocation to it
3801 should arrange for it to be installed. */
3802 relocation
= addend
- rel
->r_addend
;
3805 if (r_type
== R_FRV_FUNCDESC_VALUE
)
3807 /* If we've omitted the dynamic relocation, just emit
3808 the fixed addresses of the symbol and of the local
3810 if (info
->executable
&& !info
->pie
3811 && (!h
|| FRVFDPIC_SYM_LOCAL (info
, h
)))
3812 bfd_put_32 (output_bfd
,
3813 frvfdpic_got_section (info
)->output_section
->vma
3814 + frvfdpic_got_section (info
)->output_offset
3815 + frvfdpic_got_initial_offset (info
),
3816 contents
+ rel
->r_offset
+ 4);
3818 /* A function descriptor used for lazy or local
3819 resolving is initialized such that its high word
3820 contains the output section index in which the
3821 PLT entries are located, and the low word
3822 contains the offset of the lazy PLT entry entry
3823 point into that section. */
3824 bfd_put_32 (output_bfd
,
3825 h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
)
3827 : _frvfdpic_osec_to_segment (output_bfd
,
3830 contents
+ rel
->r_offset
+ 4);
3833 check_segment
[0] = check_segment
[1] = got_segment
;
3837 case R_FRV_GPRELU12
:
3841 check_segment
[0] = gprel_segment
;
3842 check_segment
[1] = sec
3843 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3847 case R_FRV_GETTLSOFF
:
3848 relocation
= frvfdpic_plt_section (info
)->output_section
->vma
3849 + frvfdpic_plt_section (info
)->output_offset
3850 + picrel
->tlsplt_entry
;
3851 BFD_ASSERT (picrel
->tlsplt_entry
!= (bfd_vma
)-1
3852 && picrel
->tlsdesc_entry
);
3853 check_segment
[0] = isec_segment
;
3854 check_segment
[1] = plt_segment
;
3857 case R_FRV_GOTTLSDESC12
:
3858 case R_FRV_GOTTLSDESCHI
:
3859 case R_FRV_GOTTLSDESCLO
:
3860 BFD_ASSERT (picrel
->tlsdesc_entry
);
3861 relocation
= picrel
->tlsdesc_entry
;
3862 check_segment
[0] = tls_segment
;
3863 check_segment
[1] = sec
3864 && ! bfd_is_abs_section (sec
)
3865 && ! bfd_is_und_section (sec
)
3866 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3870 case R_FRV_TLSMOFF12
:
3871 case R_FRV_TLSMOFFHI
:
3872 case R_FRV_TLSMOFFLO
:
3874 check_segment
[0] = tls_segment
;
3876 check_segment
[1] = -1;
3877 else if (bfd_is_abs_section (sec
)
3878 || bfd_is_und_section (sec
))
3881 check_segment
[1] = tls_segment
;
3883 else if (sec
->output_section
)
3885 relocation
-= tls_biased_base (info
);
3887 _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
);
3891 case R_FRV_GOTTLSOFF12
:
3892 case R_FRV_GOTTLSOFFHI
:
3893 case R_FRV_GOTTLSOFFLO
:
3894 BFD_ASSERT (picrel
->tlsoff_entry
);
3895 relocation
= picrel
->tlsoff_entry
;
3896 check_segment
[0] = tls_segment
;
3897 check_segment
[1] = sec
3898 && ! bfd_is_abs_section (sec
)
3899 && ! bfd_is_und_section (sec
)
3900 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3904 case R_FRV_TLSDESC_VALUE
:
3906 /* These shouldn't be present in input object files. */
3907 check_segment
[0] = check_segment
[1] = isec_segment
;
3910 case R_FRV_TLSDESC_RELAX
:
3911 case R_FRV_GETTLSOFF_RELAX
:
3912 case R_FRV_TLSOFF_RELAX
:
3913 /* These are just annotations for relaxation, nothing to do
3918 check_segment
[0] = isec_segment
;
3919 check_segment
[1] = sec
3920 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3925 if (check_segment
[0] != check_segment
[1] && IS_FDPIC (output_bfd
))
3927 /* If you take this out, remove the #error from fdpic-static-6.d
3928 in the ld testsuite. */
3929 /* This helps catch problems in GCC while we can't do more
3930 than static linking. The idea is to test whether the
3931 input file basename is crt0.o only once. */
3932 if (silence_segment_error
== 1)
3933 silence_segment_error
=
3934 (strlen (input_bfd
->filename
) == 6
3935 && strcmp (input_bfd
->filename
, "crt0.o") == 0)
3936 || (strlen (input_bfd
->filename
) > 6
3937 && strcmp (input_bfd
->filename
3938 + strlen (input_bfd
->filename
) - 7,
3941 if (!silence_segment_error
3942 /* We don't want duplicate errors for undefined
3944 && !(picrel
&& picrel
->symndx
== -1
3945 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefined
))
3946 info
->callbacks
->warning
3948 (info
->shared
|| info
->pie
)
3949 ? _("relocations between different segments are not supported")
3950 : _("warning: relocation references a different segment"),
3951 name
, input_bfd
, input_section
, rel
->r_offset
);
3952 if (!silence_segment_error
&& (info
->shared
|| info
->pie
))
3954 elf_elfheader (output_bfd
)->e_flags
|= EF_FRV_PIC
;
3959 case R_FRV_GOTOFFHI
:
3960 case R_FRV_TLSMOFFHI
:
3961 /* We need the addend to be applied before we shift the
3963 relocation
+= rel
->r_addend
;
3966 case R_FRV_FUNCDESC_GOTHI
:
3967 case R_FRV_FUNCDESC_GOTOFFHI
:
3968 case R_FRV_GOTTLSOFFHI
:
3969 case R_FRV_GOTTLSDESCHI
:
3974 case R_FRV_FUNCDESC_GOTLO
:
3975 case R_FRV_GOTOFFLO
:
3976 case R_FRV_FUNCDESC_GOTOFFLO
:
3977 case R_FRV_GOTTLSOFFLO
:
3978 case R_FRV_GOTTLSDESCLO
:
3979 case R_FRV_TLSMOFFLO
:
3980 relocation
&= 0xffff;
3990 if (! IS_FDPIC (output_bfd
) || ! picrel
->plt
)
3994 /* When referencing a GOT entry, a function descriptor or a
3995 PLT, we don't want the addend to apply to the reference,
3996 but rather to the referenced symbol. The actual entry
3997 will have already been created taking the addend into
3998 account, so cancel it out here. */
4002 case R_FRV_FUNCDESC_GOT12
:
4003 case R_FRV_FUNCDESC_GOTHI
:
4004 case R_FRV_FUNCDESC_GOTLO
:
4005 case R_FRV_FUNCDESC_GOTOFF12
:
4006 case R_FRV_FUNCDESC_GOTOFFHI
:
4007 case R_FRV_FUNCDESC_GOTOFFLO
:
4008 case R_FRV_GETTLSOFF
:
4009 case R_FRV_GOTTLSDESC12
:
4010 case R_FRV_GOTTLSDESCHI
:
4011 case R_FRV_GOTTLSDESCLO
:
4012 case R_FRV_GOTTLSOFF12
:
4013 case R_FRV_GOTTLSOFFHI
:
4014 case R_FRV_GOTTLSOFFLO
:
4015 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
4016 here, since we do want to apply the addend to the others.
4017 Note that we've applied the addend to GOTOFFHI before we
4018 shifted it right. */
4019 case R_FRV_GOTOFFHI
:
4020 case R_FRV_TLSMOFFHI
:
4021 relocation
-= rel
->r_addend
;
4028 if (r_type
== R_FRV_HI16
)
4029 r
= elf32_frv_relocate_hi16 (input_bfd
, rel
, contents
, relocation
);
4031 else if (r_type
== R_FRV_LO16
)
4032 r
= elf32_frv_relocate_lo16 (input_bfd
, rel
, contents
, relocation
);
4034 else if (r_type
== R_FRV_LABEL24
|| r_type
== R_FRV_GETTLSOFF
)
4035 r
= elf32_frv_relocate_label24 (input_bfd
, input_section
, rel
,
4036 contents
, relocation
);
4038 else if (r_type
== R_FRV_GPREL12
)
4039 r
= elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, rel
,
4040 contents
, relocation
);
4042 else if (r_type
== R_FRV_GPRELU12
)
4043 r
= elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, rel
,
4044 contents
, relocation
);
4046 else if (r_type
== R_FRV_GPRELLO
)
4047 r
= elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, rel
,
4048 contents
, relocation
);
4050 else if (r_type
== R_FRV_GPRELHI
)
4051 r
= elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, rel
,
4052 contents
, relocation
);
4054 else if (r_type
== R_FRV_TLSOFF
4055 || r_type
== R_FRV_TLSDESC_VALUE
)
4056 r
= bfd_reloc_notsupported
;
4059 r
= frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
4062 if (r
!= bfd_reloc_ok
)
4064 const char * msg
= (const char *) NULL
;
4068 case bfd_reloc_overflow
:
4069 r
= info
->callbacks
->reloc_overflow
4070 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4071 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
4074 case bfd_reloc_undefined
:
4075 r
= info
->callbacks
->undefined_symbol
4076 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
4079 case bfd_reloc_outofrange
:
4080 msg
= _("internal error: out of range error");
4083 case bfd_reloc_notsupported
:
4084 msg
= _("internal error: unsupported relocation error");
4087 case bfd_reloc_dangerous
:
4088 msg
= _("internal error: dangerous relocation");
4092 msg
= _("internal error: unknown error");
4097 r
= info
->callbacks
->warning
4098 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
4108 /* Return the section that should be marked against GC for a given
4112 elf32_frv_gc_mark_hook (sec
, info
, rel
, h
, sym
)
4114 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
4115 Elf_Internal_Rela
*rel
;
4116 struct elf_link_hash_entry
*h
;
4117 Elf_Internal_Sym
*sym
;
4121 switch (ELF32_R_TYPE (rel
->r_info
))
4123 case R_FRV_GNU_VTINHERIT
:
4124 case R_FRV_GNU_VTENTRY
:
4128 switch (h
->root
.type
)
4133 case bfd_link_hash_defined
:
4134 case bfd_link_hash_defweak
:
4135 return h
->root
.u
.def
.section
;
4137 case bfd_link_hash_common
:
4138 return h
->root
.u
.c
.p
->section
;
4143 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
4148 /* Update the got entry reference counts for the section being removed. */
4151 elf32_frv_gc_sweep_hook (abfd
, info
, sec
, relocs
)
4152 bfd
*abfd ATTRIBUTE_UNUSED
;
4153 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
4154 asection
*sec ATTRIBUTE_UNUSED
;
4155 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
4161 /* Hook called by the linker routine which adds symbols from an object
4162 file. We use it to put .comm items in .scomm, and not .comm. */
4165 elf32_frv_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
4167 struct bfd_link_info
*info
;
4168 Elf_Internal_Sym
*sym
;
4169 const char **namep ATTRIBUTE_UNUSED
;
4170 flagword
*flagsp ATTRIBUTE_UNUSED
;
4174 if (sym
->st_shndx
== SHN_COMMON
4175 && !info
->relocatable
4176 && (int)sym
->st_size
<= (int)bfd_get_gp_size (abfd
))
4178 /* Common symbols less than or equal to -G nn bytes are
4179 automatically put into .sbss. */
4181 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
4185 scomm
= bfd_make_section (abfd
, ".scommon");
4187 || !bfd_set_section_flags (abfd
, scomm
, (SEC_ALLOC
4189 | SEC_LINKER_CREATED
)))
4194 *valp
= sym
->st_size
;
4200 /* We need dynamic symbols for every section, since segments can
4201 relocate independently. */
4203 _frvfdpic_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4204 struct bfd_link_info
*info
4206 asection
*p ATTRIBUTE_UNUSED
)
4208 switch (elf_section_data (p
)->this_hdr
.sh_type
)
4212 /* If sh_type is yet undecided, assume it could be
4213 SHT_PROGBITS/SHT_NOBITS. */
4217 /* There shouldn't be section relative relocations
4218 against any other section. */
4224 /* Create a .got section, as well as its additional info field. This
4225 is almost entirely copied from
4226 elflink.c:_bfd_elf_create_got_section(). */
4229 _frv_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4231 flagword flags
, pltflags
;
4233 struct elf_link_hash_entry
*h
;
4234 struct bfd_link_hash_entry
*bh
;
4235 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4239 /* This function may be called more than once. */
4240 s
= bfd_get_section_by_name (abfd
, ".got");
4241 if (s
!= NULL
&& (s
->flags
& SEC_LINKER_CREATED
) != 0)
4244 /* Machine specific: although pointers are 32-bits wide, we want the
4245 GOT to be aligned to a 64-bit boundary, such that function
4246 descriptors in it can be accessed with 64-bit loads and
4250 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4251 | SEC_LINKER_CREATED
);
4254 s
= bfd_make_section (abfd
, ".got");
4256 || !bfd_set_section_flags (abfd
, s
, flags
)
4257 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
4260 if (bed
->want_got_plt
)
4262 s
= bfd_make_section (abfd
, ".got.plt");
4264 || !bfd_set_section_flags (abfd
, s
, flags
)
4265 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
4269 if (bed
->want_got_sym
)
4271 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
4272 (or .got.plt) section. We don't do this in the linker script
4273 because we don't want to define the symbol if we are not creating
4274 a global offset table. */
4276 if (!(_bfd_generic_link_add_one_symbol
4277 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
4278 bed
->got_symbol_offset
, (const char *) NULL
, FALSE
,
4279 bed
->collect
, &bh
)))
4281 h
= (struct elf_link_hash_entry
*) bh
;
4283 h
->type
= STT_OBJECT
;
4284 /* h->other = STV_HIDDEN; */ /* Should we? */
4286 /* Machine-specific: we want the symbol for executables as
4288 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4291 elf_hash_table (info
)->hgot
= h
;
4294 /* The first bit of the global offset table is the header. */
4295 s
->size
+= bed
->got_header_size
+ bed
->got_symbol_offset
;
4297 /* This is the machine-specific part. Create and initialize section
4298 data for the got. */
4299 if (IS_FDPIC (abfd
))
4301 frvfdpic_got_section (info
) = s
;
4302 frvfdpic_relocs_info (info
) = htab_try_create (1,
4303 frvfdpic_relocs_info_hash
,
4304 frvfdpic_relocs_info_eq
,
4306 if (! frvfdpic_relocs_info (info
))
4309 s
= bfd_make_section (abfd
, ".rel.got");
4311 || ! bfd_set_section_flags (abfd
, s
, (flags
| SEC_READONLY
))
4312 || ! bfd_set_section_alignment (abfd
, s
, 2))
4315 frvfdpic_gotrel_section (info
) = s
;
4317 /* Machine-specific. */
4318 s
= bfd_make_section (abfd
, ".rofixup");
4320 || ! bfd_set_section_flags (abfd
, s
, (flags
| SEC_READONLY
))
4321 || ! bfd_set_section_alignment (abfd
, s
, 2))
4324 frvfdpic_gotfixup_section (info
) = s
;
4331 flags
= BSF_GLOBAL
| BSF_WEAK
;
4334 /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it
4335 turns out that we're linking with a different linker script, the
4336 linker script will override it. */
4338 if (!(_bfd_generic_link_add_one_symbol
4339 (info
, abfd
, "_gp", flags
, s
, offset
, (const char *) NULL
, FALSE
,
4340 bed
->collect
, &bh
)))
4342 h
= (struct elf_link_hash_entry
*) bh
;
4344 h
->type
= STT_OBJECT
;
4345 /* h->other = STV_HIDDEN; */ /* Should we? */
4347 /* Machine-specific: we want the symbol for executables as well. */
4348 if (IS_FDPIC (abfd
) && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
4351 if (!IS_FDPIC (abfd
))
4354 /* FDPIC supports Thread Local Storage, and this may require a
4355 procedure linkage table for TLS PLT entries. */
4357 /* This is mostly copied from
4358 elflink.c:_bfd_elf_create_dynamic_sections(). */
4361 pltflags
|= SEC_CODE
;
4362 if (bed
->plt_not_loaded
)
4363 pltflags
&= ~ (SEC_CODE
| SEC_LOAD
| SEC_HAS_CONTENTS
);
4364 if (bed
->plt_readonly
)
4365 pltflags
|= SEC_READONLY
;
4367 s
= bfd_make_section (abfd
, ".plt");
4369 || ! bfd_set_section_flags (abfd
, s
, pltflags
)
4370 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
4372 /* FRV-specific: remember it. */
4373 frvfdpic_plt_section (info
) = s
;
4375 if (bed
->want_plt_sym
)
4377 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
4379 struct elf_link_hash_entry
*h
;
4380 struct bfd_link_hash_entry
*bh
= NULL
;
4382 if (! (_bfd_generic_link_add_one_symbol
4383 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
, 0, NULL
,
4384 FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
4386 h
= (struct elf_link_hash_entry
*) bh
;
4388 h
->type
= STT_OBJECT
;
4389 /* h->other = STV_HIDDEN; */ /* Should we? */
4391 if (! info
->executable
4392 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
4396 /* FRV-specific: we want rel relocations for the plt. */
4397 s
= bfd_make_section (abfd
, ".rel.plt");
4399 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
4400 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
4402 /* FRV-specific: remember it. */
4403 frvfdpic_pltrel_section (info
) = s
;
4408 /* Make sure the got and plt sections exist, and that our pointers in
4409 the link hash table point to them. */
4412 elf32_frvfdpic_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
4414 /* This is mostly copied from
4415 elflink.c:_bfd_elf_create_dynamic_sections(). */
4418 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4420 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4421 | SEC_LINKER_CREATED
);
4423 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
4424 .rel[a].bss sections. */
4426 /* FRV-specific: we want to create the GOT and the PLT in the FRV
4428 if (! _frv_create_got_section (abfd
, info
))
4431 /* FRV-specific: make sure we created everything we wanted. */
4432 BFD_ASSERT (frvfdpic_got_section (info
) && frvfdpic_gotrel_section (info
)
4433 && frvfdpic_gotfixup_section (info
)
4434 && frvfdpic_plt_section (info
)
4435 && frvfdpic_pltrel_section (info
));
4437 if (bed
->want_dynbss
)
4439 /* The .dynbss section is a place to put symbols which are defined
4440 by dynamic objects, are referenced by regular objects, and are
4441 not functions. We must allocate space for them in the process
4442 image and use a R_*_COPY reloc to tell the dynamic linker to
4443 initialize them at run time. The linker script puts the .dynbss
4444 section into the .bss section of the final image. */
4445 s
= bfd_make_section (abfd
, ".dynbss");
4447 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
| SEC_LINKER_CREATED
))
4450 /* The .rel[a].bss section holds copy relocs. This section is not
4451 normally needed. We need to create it here, though, so that the
4452 linker will map it to an output section. We can't just create it
4453 only if we need it, because we will not know whether we need it
4454 until we have seen all the input files, and the first time the
4455 main linker code calls BFD after examining all the input files
4456 (size_dynamic_sections) the input sections have already been
4457 mapped to the output sections. If the section turns out not to
4458 be needed, we can discard it later. We will never need this
4459 section when generating a shared object, since they do not use
4463 s
= bfd_make_section (abfd
,
4464 (bed
->default_use_rela_p
4465 ? ".rela.bss" : ".rel.bss"));
4467 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
4468 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
4476 /* Compute the total GOT and PLT size required by each symbol in each
4477 range. Symbols may require up to 4 words in the GOT: an entry
4478 pointing to the symbol, an entry pointing to its function
4479 descriptor, and a private function descriptors taking two
4483 _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info
*entry
,
4484 struct _frvfdpic_dynamic_got_info
*dinfo
)
4486 /* Allocate space for a GOT entry pointing to the symbol. */
4489 else if (entry
->gotlos
)
4491 else if (entry
->gothilo
)
4492 dinfo
->gothilo
+= 4;
4497 /* Allocate space for a GOT entry pointing to the function
4501 else if (entry
->fdgotlos
)
4503 else if (entry
->fdgothilo
)
4504 dinfo
->gothilo
+= 4;
4509 /* Decide whether we need a PLT entry, a function descriptor in the
4510 GOT, and a lazy PLT entry for this symbol. */
4511 entry
->plt
= entry
->call
4512 && entry
->symndx
== -1 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4513 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
4514 entry
->privfd
= entry
->plt
4515 || entry
->fdgoff12
|| entry
->fdgofflos
|| entry
->fdgoffhilo
4516 || ((entry
->fd
|| entry
->fdgot12
|| entry
->fdgotlos
|| entry
->fdgothilo
)
4517 && (entry
->symndx
!= -1
4518 || FRVFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
)));
4519 entry
->lazyplt
= entry
->privfd
4520 && entry
->symndx
== -1 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4521 && ! (dinfo
->info
->flags
& DF_BIND_NOW
)
4522 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
4524 /* Allocate space for a function descriptor. */
4525 if (entry
->fdgoff12
)
4527 else if (entry
->fdgofflos
)
4529 else if (entry
->privfd
&& entry
->plt
)
4531 else if (entry
->privfd
)
4541 /* Compute the total GOT size required by each TLS symbol in each
4542 range. Symbols may require up to 5 words in the GOT: an entry
4543 holding the TLS offset for the symbol, and an entry with a full TLS
4544 descriptor taking 4 words. */
4547 _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info
*entry
,
4548 struct _frvfdpic_dynamic_got_info
*dinfo
,
4549 bfd_boolean subtract
)
4551 const int l
= subtract
? -1 : 1;
4553 /* Allocate space for a GOT entry with the TLS offset of the
4555 if (entry
->tlsoff12
)
4556 dinfo
->got12
+= 4 * l
;
4557 else if (entry
->tlsofflos
)
4558 dinfo
->gotlos
+= 4 * l
;
4559 else if (entry
->tlsoffhilo
)
4560 dinfo
->gothilo
+= 4 * l
;
4562 entry
->relocstlsoff
-= l
;
4563 entry
->relocstlsoff
+= l
;
4565 /* If there's any TLSOFF relocation, mark the output file as not
4566 suitable for dlopening. This mark will remain even if we relax
4567 all such relocations, but this is not a problem, since we'll only
4568 do so for executables, and we definitely don't want anyone
4569 dlopening executables. */
4570 if (entry
->relocstlsoff
)
4571 dinfo
->info
->flags
|= DF_STATIC_TLS
;
4573 /* Allocate space for a TLS descriptor. */
4574 if (entry
->tlsdesc12
)
4575 dinfo
->tlsd12
+= 8 * l
;
4576 else if (entry
->tlsdesclos
)
4577 dinfo
->tlsdlos
+= 8 * l
;
4578 else if (entry
->tlsplt
)
4579 dinfo
->tlsdplt
+= 8 * l
;
4580 else if (entry
->tlsdeschilo
)
4581 dinfo
->tlsdhilo
+= 8 * l
;
4583 entry
->relocstlsd
-= l
;
4584 entry
->relocstlsd
+= l
;
4587 /* Compute the number of dynamic relocations and fixups that a symbol
4588 requires, and add (or subtract) from the grand and per-symbol
4592 _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info
*entry
,
4593 struct _frvfdpic_dynamic_got_info
*dinfo
,
4594 bfd_boolean subtract
)
4596 bfd_vma relocs
= 0, fixups
= 0, tlsrets
= 0;
4598 if (!dinfo
->info
->executable
|| dinfo
->info
->pie
)
4600 relocs
= entry
->relocs32
+ entry
->relocsfd
+ entry
->relocsfdv
4601 + entry
->relocstlsd
;
4603 /* In the executable, TLS relocations to symbols that bind
4604 locally (including those that resolve to global TLS offsets)
4605 are resolved immediately, without any need for fixups or
4606 dynamic relocations. In shared libraries, however, we must
4607 emit dynamic relocations even for local symbols, because we
4608 don't know the module id the library is going to get at
4609 run-time, nor its TLS base offset. */
4610 if (!dinfo
->info
->executable
4611 || (entry
->symndx
== -1
4612 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)))
4613 relocs
+= entry
->relocstlsoff
;
4617 if (entry
->symndx
!= -1 || FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
))
4619 if (entry
->symndx
!= -1
4620 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
4621 fixups
+= entry
->relocs32
+ 2 * entry
->relocsfdv
;
4622 fixups
+= entry
->relocstlsd
;
4623 tlsrets
+= entry
->relocstlsd
;
4627 relocs
+= entry
->relocs32
+ entry
->relocsfdv
4628 + entry
->relocstlsoff
+ entry
->relocstlsd
;
4631 if (entry
->symndx
!= -1
4632 || FRVFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
))
4634 if (entry
->symndx
!= -1
4635 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
4636 fixups
+= entry
->relocsfd
;
4639 relocs
+= entry
->relocsfd
;
4646 tlsrets
= - tlsrets
;
4649 entry
->dynrelocs
+= relocs
;
4650 entry
->fixups
+= fixups
;
4651 dinfo
->relocs
+= relocs
;
4652 dinfo
->fixups
+= fixups
;
4653 dinfo
->tls_ret_refs
+= tlsrets
;
4656 /* Look for opportunities to relax TLS relocations. We can assume
4657 we're linking the main executable or a static-tls library, since
4658 otherwise we wouldn't have got here. When relaxing, we have to
4659 first undo any previous accounting of TLS uses of fixups, dynamic
4660 relocations, GOT and PLT entries. */
4663 _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info
*entry
,
4664 struct _frvfdpic_dynamic_got_info
*dinfo
,
4665 bfd_boolean relaxing
)
4667 bfd_boolean changed
= ! relaxing
;
4669 BFD_ASSERT (dinfo
->info
->executable
4670 || (dinfo
->info
->flags
& DF_STATIC_TLS
));
4672 if (entry
->tlsdesc12
|| entry
->tlsdesclos
|| entry
->tlsdeschilo
)
4676 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4677 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4681 /* When linking an executable, we can always decay GOTTLSDESC to
4682 TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise.
4683 When linking a static-tls shared library, using TLSMOFF is
4684 not an option, but we can still use GOTTLSOFF. When decaying
4685 to GOTTLSOFF, we must keep the GOT entry in range. We know
4686 it has to fit because we'll be trading the 4 words of hte TLS
4687 descriptor for a single word in the same range. */
4688 if (! dinfo
->info
->executable
4689 || (entry
->symndx
== -1
4690 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)))
4692 entry
->tlsoff12
|= entry
->tlsdesc12
;
4693 entry
->tlsofflos
|= entry
->tlsdesclos
;
4694 entry
->tlsoffhilo
|= entry
->tlsdeschilo
;
4697 entry
->tlsdesc12
= entry
->tlsdesclos
= entry
->tlsdeschilo
= 0;
4700 /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the
4701 main executable. We have to check whether the symbol's TLSOFF is
4702 in range for a setlos. For symbols with a hash entry, we can
4703 determine exactly what to do; for others locals, we don't have
4704 addresses handy, so we use the size of the TLS section as an
4705 approximation. If we get it wrong, we'll retain a GOT entry
4706 holding the TLS offset (without dynamic relocations or fixups),
4707 but we'll still optimize away the loads from it. Since TLS sizes
4708 are generally very small, it's probably not worth attempting to
4709 do better than this. */
4711 || entry
->tlsoff12
|| entry
->tlsofflos
|| entry
->tlsoffhilo
)
4712 && dinfo
->info
->executable
&& relaxing
4713 && ((entry
->symndx
== -1
4714 && FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4715 /* The above may hold for an undefweak TLS symbol, so make
4716 sure we don't have this case before accessing def.value
4718 && (entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
4719 || (bfd_vma
)(entry
->d
.h
->root
.u
.def
.value
4720 + (entry
->d
.h
->root
.u
.def
.section
4721 ->output_section
->vma
)
4722 + entry
->d
.h
->root
.u
.def
.section
->output_offset
4724 - tls_biased_base (dinfo
->info
)
4725 + 32768) < (bfd_vma
)65536))
4726 || (entry
->symndx
!= -1
4727 && (elf_hash_table (dinfo
->info
)->tls_sec
->size
4728 + abs (entry
->addend
) < 32768 + FRVFDPIC_TLS_BIAS
))))
4732 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4733 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4738 entry
->tlsoff12
= entry
->tlsofflos
= entry
->tlsoffhilo
= 0;
4741 /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already
4742 have a #gottlsoff12 relocation for this entry, or if we can fit
4743 one more in the 12-bit (and 16-bit) ranges. */
4747 && dinfo
->got12
+ dinfo
->fd12
+ dinfo
->tlsd12
<= 4096 - 12 - 4
4748 && (dinfo
->got12
+ dinfo
->fd12
+ dinfo
->tlsd12
4749 + dinfo
->gotlos
+ dinfo
->fdlos
+ dinfo
->tlsdlos
4750 <= 65536 - 12 - 4))))
4754 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4755 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4759 entry
->tlsoff12
= 1;
4765 _frvfdpic_count_tls_entries (entry
, dinfo
, FALSE
);
4766 _frvfdpic_count_relocs_fixups (entry
, dinfo
, FALSE
);
4772 /* Compute the total GOT and PLT size required by each symbol in each range. *
4773 Symbols may require up to 4 words in the GOT: an entry pointing to
4774 the symbol, an entry pointing to its function descriptor, and a
4775 private function descriptors taking two words. */
4778 _frvfdpic_count_got_plt_entries (void **entryp
, void *dinfo_
)
4780 struct frvfdpic_relocs_info
*entry
= *entryp
;
4781 struct _frvfdpic_dynamic_got_info
*dinfo
= dinfo_
;
4783 _frvfdpic_count_nontls_entries (entry
, dinfo
);
4785 if (dinfo
->info
->executable
|| (dinfo
->info
->flags
& DF_STATIC_TLS
))
4786 _frvfdpic_relax_tls_entries (entry
, dinfo
, FALSE
);
4789 _frvfdpic_count_tls_entries (entry
, dinfo
, FALSE
);
4790 _frvfdpic_count_relocs_fixups (entry
, dinfo
, FALSE
);
4796 /* Determine the positive and negative ranges to be used by each
4797 offset range in the GOT. FDCUR and CUR, that must be aligned to a
4798 double-word boundary, are the minimum (negative) and maximum
4799 (positive) GOT offsets already used by previous ranges, except for
4800 an ODD entry that may have been left behind. GOT and FD indicate
4801 the size of GOT entries and function descriptors that must be
4802 placed within the range from -WRAP to WRAP. If there's room left,
4803 up to FDPLT bytes should be reserved for additional function
4806 inline static bfd_signed_vma
4807 _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data
*gad
,
4808 bfd_signed_vma fdcur
,
4818 bfd_signed_vma wrapmin
= -wrap
;
4819 const bfd_vma tdescsz
= 8;
4821 /* Start at the given initial points. */
4825 /* If we had an incoming odd word and we have any got entries that
4826 are going to use it, consume it, otherwise leave gad->odd at
4827 zero. We might force gad->odd to zero and return the incoming
4828 odd such that it is used by the next range, but then GOT entries
4829 might appear to be out of order and we wouldn't be able to
4830 shorten the GOT by one word if it turns out to end with an
4831 unpaired GOT entry. */
4841 /* If we're left with an unpaired GOT entry, compute its location
4842 such that we can return it. Otherwise, if got doesn't require an
4843 odd number of words here, either odd was already zero in the
4844 block above, or it was set to zero because got was non-zero, or
4845 got was already zero. In the latter case, we want the value of
4846 odd to carry over to the return statement, so we don't want to
4847 reset odd unless the condition below is true. */
4854 /* Compute the tentative boundaries of this range. */
4855 gad
->max
= cur
+ got
;
4856 gad
->min
= fdcur
- fd
;
4859 /* If function descriptors took too much space, wrap some of them
4861 if (gad
->min
< wrapmin
)
4863 gad
->max
+= wrapmin
- gad
->min
;
4864 gad
->tmin
= gad
->min
= wrapmin
;
4867 /* If GOT entries took too much space, wrap some of them around.
4868 This may well cause gad->min to become lower than wrapmin. This
4869 will cause a relocation overflow later on, so we don't have to
4871 if ((bfd_vma
) gad
->max
> wrap
)
4873 gad
->min
-= gad
->max
- wrap
;
4877 /* Add TLS descriptors. */
4878 gad
->tmax
= gad
->max
+ tlsd
;
4879 gad
->tmin
= gad
->min
;
4882 /* If TLS descriptors took too much space, wrap an integral number
4884 if ((bfd_vma
) gad
->tmax
> wrap
)
4886 bfd_vma wrapsize
= gad
->tmax
- wrap
;
4888 wrapsize
+= tdescsz
/ 2;
4889 wrapsize
&= ~ tdescsz
/ 2;
4891 gad
->tmin
-= wrapsize
;
4892 gad
->tmax
-= wrapsize
;
4895 /* If there is space left and we have function descriptors
4896 referenced in PLT entries that could take advantage of shorter
4897 offsets, place them now. */
4898 if (fdplt
&& gad
->tmin
> wrapmin
)
4902 if ((bfd_vma
) (gad
->tmin
- wrapmin
) < fdplt
)
4903 fds
= gad
->tmin
- wrapmin
;
4913 /* If there is more space left, try to place some more function
4914 descriptors for PLT entries. */
4915 if (fdplt
&& (bfd_vma
) gad
->tmax
< wrap
)
4919 if ((bfd_vma
) (wrap
- gad
->tmax
) < fdplt
)
4920 fds
= wrap
- gad
->tmax
;
4930 /* If there is space left and we have TLS descriptors referenced in
4931 PLT entries that could take advantage of shorter offsets, place
4933 if (tlsdplt
&& gad
->tmin
> wrapmin
)
4937 if ((bfd_vma
) (gad
->tmin
- wrapmin
) < tlsdplt
)
4938 tlsds
= (gad
->tmin
- wrapmin
) & ~ (tdescsz
/ 2);
4944 gad
->tlsdplt
+= tlsds
;
4947 /* If there is more space left, try to place some more TLS
4948 descriptors for PLT entries. Although we could try to fit an
4949 additional TLS descriptor with half of it just before before the
4950 wrap point and another right past the wrap point, this might
4951 cause us to run out of space for the next region, so don't do
4953 if (tlsdplt
&& (bfd_vma
) gad
->tmax
< wrap
- tdescsz
/ 2)
4957 if ((bfd_vma
) (wrap
- gad
->tmax
) < tlsdplt
)
4958 tlsds
= (wrap
- gad
->tmax
) & ~ (tdescsz
/ 2);
4964 gad
->tlsdplt
+= tlsds
;
4967 /* If odd was initially computed as an offset past the wrap point,
4970 odd
= gad
->min
+ odd
- gad
->max
;
4972 /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed
4973 before returning, so do it here too. This guarantees that,
4974 should cur and fdcur meet at the wrap point, they'll both be
4976 if (gad
->cur
== gad
->max
)
4977 gad
->cur
= gad
->min
;
4979 /* Ditto for _frvfdpic_get_tlsdesc_entry(). */
4980 gad
->tcur
= gad
->max
;
4981 if (gad
->tcur
== gad
->tmax
)
4982 gad
->tcur
= gad
->tmin
;
4987 /* Compute the location of the next GOT entry, given the allocation
4988 data for a range. */
4990 inline static bfd_signed_vma
4991 _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
4997 /* If there was an odd word left behind, use it. */
5003 /* Otherwise, use the word pointed to by cur, reserve the next
5004 as an odd word, and skip to the next pair of words, possibly
5007 gad
->odd
= gad
->cur
+ 4;
5009 if (gad
->cur
== gad
->max
)
5010 gad
->cur
= gad
->min
;
5016 /* Compute the location of the next function descriptor entry in the
5017 GOT, given the allocation data for a range. */
5019 inline static bfd_signed_vma
5020 _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
5022 /* If we're at the bottom, wrap around, and only then allocate the
5023 next pair of words. */
5024 if (gad
->fdcur
== gad
->min
)
5025 gad
->fdcur
= gad
->max
;
5026 return gad
->fdcur
-= 8;
5029 /* Compute the location of the next TLS descriptor entry in the GOT,
5030 given the allocation data for a range. */
5031 inline static bfd_signed_vma
5032 _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
5040 /* If we're at the top of the region, wrap around to the bottom. */
5041 if (gad
->tcur
== gad
->tmax
)
5042 gad
->tcur
= gad
->tmin
;
5047 /* Assign GOT offsets for every GOT entry and function descriptor.
5048 Doing everything in a single pass is tricky. */
5051 _frvfdpic_assign_got_entries (void **entryp
, void *info_
)
5053 struct frvfdpic_relocs_info
*entry
= *entryp
;
5054 struct _frvfdpic_dynamic_got_plt_info
*dinfo
= info_
;
5057 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5058 else if (entry
->gotlos
)
5059 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5060 else if (entry
->gothilo
)
5061 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5064 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5065 else if (entry
->fdgotlos
)
5066 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5067 else if (entry
->fdgothilo
)
5068 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5070 if (entry
->fdgoff12
)
5071 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->got12
);
5072 else if (entry
->plt
&& dinfo
->got12
.fdplt
)
5074 dinfo
->got12
.fdplt
-= 8;
5075 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->got12
);
5077 else if (entry
->fdgofflos
)
5078 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gotlos
);
5079 else if (entry
->plt
&& dinfo
->gotlos
.fdplt
)
5081 dinfo
->gotlos
.fdplt
-= 8;
5082 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gotlos
);
5084 else if (entry
->plt
)
5086 dinfo
->gothilo
.fdplt
-= 8;
5087 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gothilo
);
5089 else if (entry
->privfd
)
5090 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gothilo
);
5092 if (entry
->tlsoff12
)
5093 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5094 else if (entry
->tlsofflos
)
5095 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5096 else if (entry
->tlsoffhilo
)
5097 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5099 if (entry
->tlsdesc12
)
5100 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->got12
);
5101 else if (entry
->tlsplt
&& dinfo
->got12
.tlsdplt
)
5103 dinfo
->got12
.tlsdplt
-= 8;
5104 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->got12
);
5106 else if (entry
->tlsdesclos
)
5107 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gotlos
);
5108 else if (entry
->tlsplt
&& dinfo
->gotlos
.tlsdplt
)
5110 dinfo
->gotlos
.tlsdplt
-= 8;
5111 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gotlos
);
5113 else if (entry
->tlsplt
)
5115 dinfo
->gothilo
.tlsdplt
-= 8;
5116 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gothilo
);
5118 else if (entry
->tlsdeschilo
)
5119 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gothilo
);
5124 /* Assign GOT offsets to private function descriptors used by PLT
5125 entries (or referenced by 32-bit offsets), as well as PLT entries
5126 and lazy PLT entries. */
5129 _frvfdpic_assign_plt_entries (void **entryp
, void *info_
)
5131 struct frvfdpic_relocs_info
*entry
= *entryp
;
5132 struct _frvfdpic_dynamic_got_plt_info
*dinfo
= info_
;
5135 BFD_ASSERT (entry
->fd_entry
);
5141 /* We use the section's raw size to mark the location of the
5143 entry
->plt_entry
= frvfdpic_plt_section (dinfo
->g
.info
)->size
;
5145 /* Figure out the length of this PLT entry based on the
5146 addressing mode we need to reach the function descriptor. */
5147 BFD_ASSERT (entry
->fd_entry
);
5148 if (entry
->fd_entry
>= -(1 << (12 - 1))
5149 && entry
->fd_entry
< (1 << (12 - 1)))
5151 else if (entry
->fd_entry
>= -(1 << (16 - 1))
5152 && entry
->fd_entry
< (1 << (16 - 1)))
5157 frvfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
5162 entry
->lzplt_entry
= dinfo
->g
.lzplt
;
5163 dinfo
->g
.lzplt
+= 8;
5164 /* If this entry is the one that gets the resolver stub, account
5165 for the additional instruction. */
5166 if (entry
->lzplt_entry
% FRVFDPIC_LZPLT_BLOCK_SIZE
5167 == FRVFDPIC_LZPLT_RESOLV_LOC
)
5168 dinfo
->g
.lzplt
+= 4;
5176 = frvfdpic_plt_section (dinfo
->g
.info
)->size
;
5178 if (dinfo
->g
.info
->executable
5179 && (entry
->symndx
!= -1
5180 || FRVFDPIC_SYM_LOCAL (dinfo
->g
.info
, entry
->d
.h
)))
5182 if ((bfd_signed_vma
)entry
->addend
>= -(1 << (16 - 1))
5183 /* FIXME: here we use the size of the TLS section
5184 as an upper bound for the value of the TLS
5185 symbol, because we may not know the exact value
5186 yet. If we get it wrong, we'll just waste a
5187 word in the PLT, and we should never get even
5188 close to 32 KiB of TLS anyway. */
5189 && elf_hash_table (dinfo
->g
.info
)->tls_sec
5190 && (elf_hash_table (dinfo
->g
.info
)->tls_sec
->size
5191 + (bfd_signed_vma
)(entry
->addend
) <= (1 << (16 - 1))))
5196 else if (entry
->tlsoff_entry
)
5198 if (entry
->tlsoff_entry
>= -(1 << (12 - 1))
5199 && entry
->tlsoff_entry
< (1 << (12 - 1)))
5201 else if (entry
->tlsoff_entry
>= -(1 << (16 - 1))
5202 && entry
->tlsoff_entry
< (1 << (16 - 1)))
5209 BFD_ASSERT (entry
->tlsdesc_entry
);
5211 if (entry
->tlsdesc_entry
>= -(1 << (12 - 1))
5212 && entry
->tlsdesc_entry
< (1 << (12 - 1)))
5214 else if (entry
->tlsdesc_entry
>= -(1 << (16 - 1))
5215 && entry
->tlsdesc_entry
< (1 << (16 - 1)))
5221 frvfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
5227 /* Cancel out any effects of calling _frvfdpic_assign_got_entries and
5228 _frvfdpic_assign_plt_entries. */
5231 _frvfdpic_reset_got_plt_entries (void **entryp
, void *ignore ATTRIBUTE_UNUSED
)
5233 struct frvfdpic_relocs_info
*entry
= *entryp
;
5235 entry
->got_entry
= 0;
5236 entry
->fdgot_entry
= 0;
5237 entry
->fd_entry
= 0;
5238 entry
->plt_entry
= (bfd_vma
)-1;
5239 entry
->lzplt_entry
= (bfd_vma
)-1;
5240 entry
->tlsoff_entry
= 0;
5241 entry
->tlsdesc_entry
= 0;
5242 entry
->tlsplt_entry
= (bfd_vma
)-1;
5247 /* Follow indirect and warning hash entries so that each got entry
5248 points to the final symbol definition. P must point to a pointer
5249 to the hash table we're traversing. Since this traversal may
5250 modify the hash table, we set this pointer to NULL to indicate
5251 we've made a potentially-destructive change to the hash table, so
5252 the traversal must be restarted. */
5254 _frvfdpic_resolve_final_relocs_info (void **entryp
, void *p
)
5256 struct frvfdpic_relocs_info
*entry
= *entryp
;
5259 if (entry
->symndx
== -1)
5261 struct elf_link_hash_entry
*h
= entry
->d
.h
;
5262 struct frvfdpic_relocs_info
*oentry
;
5264 while (h
->root
.type
== bfd_link_hash_indirect
5265 || h
->root
.type
== bfd_link_hash_warning
)
5266 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
5268 if (entry
->d
.h
== h
)
5271 oentry
= frvfdpic_relocs_info_for_global (*htab
, 0, h
, entry
->addend
,
5276 /* Merge the two entries. */
5277 frvfdpic_pic_merge_early_relocs_info (oentry
, entry
);
5278 htab_clear_slot (*htab
, entryp
);
5284 /* If we can't find this entry with the new bfd hash, re-insert
5285 it, and get the traversal restarted. */
5286 if (! htab_find (*htab
, entry
))
5288 htab_clear_slot (*htab
, entryp
);
5289 entryp
= htab_find_slot (*htab
, entry
, INSERT
);
5292 /* Abort the traversal, since the whole table may have
5293 moved, and leave it up to the parent to restart the
5295 *(htab_t
*)p
= NULL
;
5303 /* Compute the total size of the GOT, the PLT, the dynamic relocations
5304 section and the rofixup section. Assign locations for GOT and PLT
5308 _frvfdpic_size_got_plt (bfd
*output_bfd
,
5309 struct _frvfdpic_dynamic_got_plt_info
*gpinfop
)
5312 bfd_vma limit
, tlslimit
;
5313 struct bfd_link_info
*info
= gpinfop
->g
.info
;
5314 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
5316 memcpy (frvfdpic_dynamic_got_plt_info (info
), &gpinfop
->g
,
5317 sizeof (gpinfop
->g
));
5320 /* Compute the total size taken by entries in the 12-bit and 16-bit
5321 ranges, to tell how many PLT function descriptors we can bring
5322 into the 12-bit range without causing the 16-bit range to
5324 limit
= odd
+ gpinfop
->g
.got12
+ gpinfop
->g
.gotlos
5325 + gpinfop
->g
.fd12
+ gpinfop
->g
.fdlos
5326 + gpinfop
->g
.tlsd12
+ gpinfop
->g
.tlsdlos
;
5327 if (limit
< (bfd_vma
)1 << 16)
5328 limit
= ((bfd_vma
)1 << 16) - limit
;
5331 if (gpinfop
->g
.fdplt
< limit
)
5333 tlslimit
= (limit
- gpinfop
->g
.fdplt
) & ~ (bfd_vma
) 8;
5334 limit
= gpinfop
->g
.fdplt
;
5338 if (gpinfop
->g
.tlsdplt
< tlslimit
)
5339 tlslimit
= gpinfop
->g
.tlsdplt
;
5341 /* Determine the ranges of GOT offsets that we can use for each
5342 range of addressing modes. */
5343 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->got12
,
5352 (bfd_vma
)1 << (12-1));
5353 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->gotlos
,
5354 gpinfop
->got12
.tmin
,
5356 gpinfop
->got12
.tmax
,
5360 - gpinfop
->got12
.fdplt
,
5363 - gpinfop
->got12
.tlsdplt
,
5364 (bfd_vma
)1 << (16-1));
5365 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->gothilo
,
5366 gpinfop
->gotlos
.tmin
,
5368 gpinfop
->gotlos
.tmax
,
5372 - gpinfop
->got12
.fdplt
5373 - gpinfop
->gotlos
.fdplt
,
5374 gpinfop
->g
.tlsdhilo
,
5376 - gpinfop
->got12
.tlsdplt
5377 - gpinfop
->gotlos
.tlsdplt
,
5378 (bfd_vma
)1 << (32-1));
5380 /* Now assign (most) GOT offsets. */
5381 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_assign_got_entries
,
5384 frvfdpic_got_section (info
)->size
= gpinfop
->gothilo
.tmax
5385 - gpinfop
->gothilo
.tmin
5386 /* If an odd word is the last word of the GOT, we don't need this
5387 word to be part of the GOT. */
5388 - (odd
+ 4 == gpinfop
->gothilo
.tmax
? 4 : 0);
5389 if (frvfdpic_got_section (info
)->size
== 0)
5390 frvfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
5391 else if (frvfdpic_got_section (info
)->size
== 12
5392 && ! elf_hash_table (info
)->dynamic_sections_created
)
5394 frvfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
5395 frvfdpic_got_section (info
)->size
= 0;
5397 /* This will be non-NULL during relaxation. The assumption is that
5398 the size of one of these sections will never grow, only shrink,
5399 so we can use the larger buffer we allocated before. */
5400 else if (frvfdpic_got_section (info
)->contents
== NULL
)
5402 frvfdpic_got_section (info
)->contents
=
5403 (bfd_byte
*) bfd_zalloc (dynobj
,
5404 frvfdpic_got_section (info
)->size
);
5405 if (frvfdpic_got_section (info
)->contents
== NULL
)
5409 if (frvfdpic_gotrel_section (info
))
5410 /* Subtract the number of lzplt entries, since those will generate
5411 relocations in the pltrel section. */
5412 frvfdpic_gotrel_section (info
)->size
=
5413 (gpinfop
->g
.relocs
- gpinfop
->g
.lzplt
/ 8)
5414 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
5416 BFD_ASSERT (gpinfop
->g
.relocs
== 0);
5417 if (frvfdpic_gotrel_section (info
)->size
== 0)
5418 frvfdpic_gotrel_section (info
)->flags
|= SEC_EXCLUDE
;
5419 else if (frvfdpic_gotrel_section (info
)->contents
== NULL
)
5421 frvfdpic_gotrel_section (info
)->contents
=
5422 (bfd_byte
*) bfd_zalloc (dynobj
,
5423 frvfdpic_gotrel_section (info
)->size
);
5424 if (frvfdpic_gotrel_section (info
)->contents
== NULL
)
5428 frvfdpic_gotfixup_section (info
)->size
= (gpinfop
->g
.fixups
+ 1) * 4;
5429 if (frvfdpic_gotfixup_section (info
)->size
== 0)
5430 frvfdpic_gotfixup_section (info
)->flags
|= SEC_EXCLUDE
;
5431 else if (frvfdpic_gotfixup_section (info
)->contents
== NULL
)
5433 frvfdpic_gotfixup_section (info
)->contents
=
5434 (bfd_byte
*) bfd_zalloc (dynobj
,
5435 frvfdpic_gotfixup_section (info
)->size
);
5436 if (frvfdpic_gotfixup_section (info
)->contents
== NULL
)
5440 if (frvfdpic_pltrel_section (info
))
5442 frvfdpic_pltrel_section (info
)->size
=
5443 gpinfop
->g
.lzplt
/ 8
5444 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
5445 if (frvfdpic_pltrel_section (info
)->size
== 0)
5446 frvfdpic_pltrel_section (info
)->flags
|= SEC_EXCLUDE
;
5447 else if (frvfdpic_pltrel_section (info
)->contents
== NULL
)
5449 frvfdpic_pltrel_section (info
)->contents
=
5450 (bfd_byte
*) bfd_zalloc (dynobj
,
5451 frvfdpic_pltrel_section (info
)->size
);
5452 if (frvfdpic_pltrel_section (info
)->contents
== NULL
)
5457 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
5458 such that there's room for the additional instruction needed to
5459 call the resolver. Since _frvfdpic_assign_got_entries didn't
5460 account for them, our block size is 4 bytes smaller than the real
5462 if (frvfdpic_plt_section (info
))
5464 frvfdpic_plt_section (info
)->size
= gpinfop
->g
.lzplt
5465 + ((gpinfop
->g
.lzplt
+ (FRVFDPIC_LZPLT_BLOCK_SIZE
- 4) - 8)
5466 / (FRVFDPIC_LZPLT_BLOCK_SIZE
- 4) * 4);
5469 /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to
5470 actually assign lazy PLT entries addresses. */
5471 gpinfop
->g
.lzplt
= 0;
5473 /* Save information that we're going to need to generate GOT and PLT
5475 frvfdpic_got_initial_offset (info
) = -gpinfop
->gothilo
.tmin
;
5477 if (get_elf_backend_data (output_bfd
)->want_got_sym
)
5478 elf_hash_table (info
)->hgot
->root
.u
.def
.value
5479 = frvfdpic_got_initial_offset (info
);
5481 if (frvfdpic_plt_section (info
))
5482 frvfdpic_plt_initial_offset (info
) =
5483 frvfdpic_plt_section (info
)->size
;
5485 /* Allocate a ret statement at plt_initial_offset, to be used by
5486 locally-resolved TLS descriptors. */
5487 if (gpinfop
->g
.tls_ret_refs
)
5488 frvfdpic_plt_section (info
)->size
+= 4;
5490 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_assign_plt_entries
,
5493 /* Allocate the PLT section contents only after
5494 _frvfdpic_assign_plt_entries has a chance to add the size of the
5495 non-lazy PLT entries. */
5496 if (frvfdpic_plt_section (info
))
5498 if (frvfdpic_plt_section (info
)->size
== 0)
5499 frvfdpic_plt_section (info
)->flags
|= SEC_EXCLUDE
;
5500 else if (frvfdpic_plt_section (info
)->contents
== NULL
)
5502 frvfdpic_plt_section (info
)->contents
=
5503 (bfd_byte
*) bfd_zalloc (dynobj
,
5504 frvfdpic_plt_section (info
)->size
);
5505 if (frvfdpic_plt_section (info
)->contents
== NULL
)
5513 /* Set the sizes of the dynamic sections. */
5516 elf32_frvfdpic_size_dynamic_sections (bfd
*output_bfd
,
5517 struct bfd_link_info
*info
)
5521 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5523 dynobj
= elf_hash_table (info
)->dynobj
;
5524 BFD_ASSERT (dynobj
!= NULL
);
5526 if (elf_hash_table (info
)->dynamic_sections_created
)
5528 /* Set the contents of the .interp section to the interpreter. */
5529 if (info
->executable
)
5531 s
= bfd_get_section_by_name (dynobj
, ".interp");
5532 BFD_ASSERT (s
!= NULL
);
5533 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5534 s
->contents
= (bfd_byte
*) ELF_DYNAMIC_INTERPRETER
;
5538 memset (&gpinfo
, 0, sizeof (gpinfo
));
5539 gpinfo
.g
.info
= info
;
5543 htab_t relocs
= frvfdpic_relocs_info (info
);
5545 htab_traverse (relocs
, _frvfdpic_resolve_final_relocs_info
, &relocs
);
5547 if (relocs
== frvfdpic_relocs_info (info
))
5551 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_count_got_plt_entries
,
5554 /* Allocate space to save the summary information, we're going to
5555 use it if we're doing relaxations. */
5556 frvfdpic_dynamic_got_plt_info (info
) = bfd_alloc (dynobj
, sizeof (gpinfo
.g
));
5558 if (!_frvfdpic_size_got_plt (output_bfd
, &gpinfo
))
5561 if (elf_hash_table (info
)->dynamic_sections_created
)
5563 if (frvfdpic_got_section (info
)->size
)
5564 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTGOT
, 0))
5567 if (frvfdpic_pltrel_section (info
)->size
)
5568 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
5569 || !_bfd_elf_add_dynamic_entry (info
, DT_PLTREL
, DT_REL
)
5570 || !_bfd_elf_add_dynamic_entry (info
, DT_JMPREL
, 0))
5573 if (frvfdpic_gotrel_section (info
)->size
)
5574 if (!_bfd_elf_add_dynamic_entry (info
, DT_REL
, 0)
5575 || !_bfd_elf_add_dynamic_entry (info
, DT_RELSZ
, 0)
5576 || !_bfd_elf_add_dynamic_entry (info
, DT_RELENT
,
5577 sizeof (Elf32_External_Rel
)))
5585 elf32_frvfdpic_always_size_sections (bfd
*output_bfd
,
5586 struct bfd_link_info
*info
)
5588 if (!info
->relocatable
)
5590 struct elf_link_hash_entry
*h
;
5593 /* Force a PT_GNU_STACK segment to be created. */
5594 if (! elf_tdata (output_bfd
)->stack_flags
)
5595 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
| PF_X
;
5597 /* Define __stacksize if it's not defined yet. */
5598 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
5599 FALSE
, FALSE
, FALSE
);
5600 if (! h
|| h
->root
.type
!= bfd_link_hash_defined
5601 || h
->type
!= STT_OBJECT
5604 struct bfd_link_hash_entry
*bh
= NULL
;
5606 if (!(_bfd_generic_link_add_one_symbol
5607 (info
, output_bfd
, "__stacksize",
5608 BSF_GLOBAL
, bfd_abs_section_ptr
, DEFAULT_STACK_SIZE
,
5609 (const char *) NULL
, FALSE
,
5610 get_elf_backend_data (output_bfd
)->collect
, &bh
)))
5613 h
= (struct elf_link_hash_entry
*) bh
;
5615 h
->type
= STT_OBJECT
;
5616 /* This one must NOT be hidden. */
5619 /* Create a stack section, and set its alignment. */
5620 sec
= bfd_make_section (output_bfd
, ".stack");
5623 || ! bfd_set_section_alignment (output_bfd
, sec
, 3))
5630 /* Look for opportunities to relax TLS relocations. We can assume
5631 we're linking the main executable or a static-tls library, since
5632 otherwise we wouldn't have got here. */
5635 _frvfdpic_relax_got_plt_entries (void **entryp
, void *dinfo_
)
5637 struct frvfdpic_relocs_info
*entry
= *entryp
;
5638 struct _frvfdpic_dynamic_got_info
*dinfo
= dinfo_
;
5640 _frvfdpic_relax_tls_entries (entry
, dinfo
, TRUE
);
5646 elf32_frvfdpic_relax_section (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
,
5647 struct bfd_link_info
*info
, bfd_boolean
*again
)
5649 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5651 /* If we return early, we didn't change anything. */
5654 /* We'll do our thing when requested to relax the GOT section. */
5655 if (sec
!= frvfdpic_got_section (info
))
5658 /* We can only relax when linking the main executable or a library
5659 that can't be dlopened. */
5660 if (! info
->executable
&& ! (info
->flags
& DF_STATIC_TLS
))
5663 /* If there isn't a TLS section for this binary, we can't do
5664 anything about its TLS relocations (it probably doesn't have
5666 if (elf_hash_table (info
)->tls_sec
== NULL
)
5669 memset (&gpinfo
, 0, sizeof (gpinfo
));
5670 memcpy (&gpinfo
.g
, frvfdpic_dynamic_got_plt_info (info
), sizeof (gpinfo
.g
));
5672 /* Now look for opportunities to relax, adjusting the GOT usage
5674 htab_traverse (frvfdpic_relocs_info (info
),
5675 _frvfdpic_relax_got_plt_entries
,
5678 /* If we changed anything, reset and re-assign GOT and PLT entries. */
5679 if (memcmp (frvfdpic_dynamic_got_plt_info (info
),
5680 &gpinfo
.g
, sizeof (gpinfo
.g
)) != 0)
5682 /* Clear GOT and PLT assignments. */
5683 htab_traverse (frvfdpic_relocs_info (info
),
5684 _frvfdpic_reset_got_plt_entries
,
5687 /* The owner of the TLS section is the output bfd. There should
5688 be a better way to get to it. */
5689 if (!_frvfdpic_size_got_plt (elf_hash_table (info
)->tls_sec
->owner
,
5693 /* Repeat until we don't make any further changes. We could fail to
5694 introduce changes in a round if, for example, the 12-bit range is
5695 full, but we later release some space by getting rid of TLS
5696 descriptors in it. We have to repeat the whole process because
5697 we might have changed the size of a section processed before this
5706 elf32_frvfdpic_modify_segment_map (bfd
*output_bfd
,
5707 struct bfd_link_info
*info
)
5709 struct elf_segment_map
*m
;
5711 /* objcopy and strip preserve what's already there using
5712 elf32_frvfdpic_copy_private_bfd_data (). */
5716 for (m
= elf_tdata (output_bfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
5717 if (m
->p_type
== PT_GNU_STACK
)
5722 asection
*sec
= bfd_get_section_by_name (output_bfd
, ".stack");
5723 struct elf_link_hash_entry
*h
;
5727 /* Obtain the pointer to the __stacksize symbol. */
5728 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
5729 FALSE
, FALSE
, FALSE
);
5730 while (h
->root
.type
== bfd_link_hash_indirect
5731 || h
->root
.type
== bfd_link_hash_warning
)
5732 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
5733 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
5735 /* Set the section size from the symbol value. We
5736 intentionally ignore the symbol section. */
5737 if (h
->root
.type
== bfd_link_hash_defined
)
5738 sec
->size
= h
->root
.u
.def
.value
;
5740 sec
->size
= DEFAULT_STACK_SIZE
;
5742 /* Add the stack section to the PT_GNU_STACK segment,
5743 such that its size and alignment requirements make it
5745 m
->sections
[m
->count
] = sec
;
5753 /* Fill in code and data in dynamic sections. */
5756 elf32_frv_finish_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5757 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
5759 /* Nothing to be done for non-FDPIC. */
5764 elf32_frvfdpic_finish_dynamic_sections (bfd
*output_bfd
,
5765 struct bfd_link_info
*info
)
5770 dynobj
= elf_hash_table (info
)->dynobj
;
5772 if (frvfdpic_dynamic_got_plt_info (info
))
5774 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
== 0);
5776 if (frvfdpic_got_section (info
))
5778 BFD_ASSERT (frvfdpic_gotrel_section (info
)->size
5779 == (frvfdpic_gotrel_section (info
)->reloc_count
5780 * sizeof (Elf32_External_Rel
)));
5782 if (frvfdpic_gotfixup_section (info
))
5784 struct elf_link_hash_entry
*hgot
= elf_hash_table (info
)->hgot
;
5785 bfd_vma got_value
= hgot
->root
.u
.def
.value
5786 + hgot
->root
.u
.def
.section
->output_section
->vma
5787 + hgot
->root
.u
.def
.section
->output_offset
;
5788 struct bfd_link_hash_entry
*hend
;
5790 _frvfdpic_add_rofixup (output_bfd
, frvfdpic_gotfixup_section (info
),
5793 if (frvfdpic_gotfixup_section (info
)->size
5794 != (frvfdpic_gotfixup_section (info
)->reloc_count
* 4))
5797 (*_bfd_error_handler
)
5798 ("LINKER BUG: .rofixup section size mismatch");
5802 hend
= bfd_link_hash_lookup (info
->hash
, "__ROFIXUP_END__",
5803 FALSE
, FALSE
, TRUE
);
5805 && (hend
->type
== bfd_link_hash_defined
5806 || hend
->type
== bfd_link_hash_defweak
))
5809 frvfdpic_gotfixup_section (info
)->output_section
->vma
5810 + frvfdpic_gotfixup_section (info
)->output_offset
5811 + frvfdpic_gotfixup_section (info
)->size
5812 - hend
->u
.def
.section
->output_section
->vma
5813 - hend
->u
.def
.section
->output_offset
;
5814 BFD_ASSERT (hend
->u
.def
.value
== value
);
5815 if (hend
->u
.def
.value
!= value
)
5820 if (frvfdpic_pltrel_section (info
))
5822 BFD_ASSERT (frvfdpic_pltrel_section (info
)->size
5823 == (frvfdpic_pltrel_section (info
)->reloc_count
5824 * sizeof (Elf32_External_Rel
)));
5828 if (elf_hash_table (info
)->dynamic_sections_created
)
5830 Elf32_External_Dyn
* dyncon
;
5831 Elf32_External_Dyn
* dynconend
;
5833 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5835 BFD_ASSERT (sdyn
!= NULL
);
5837 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5838 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5840 for (; dyncon
< dynconend
; dyncon
++)
5842 Elf_Internal_Dyn dyn
;
5844 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5852 dyn
.d_un
.d_ptr
= frvfdpic_got_section (info
)->output_section
->vma
5853 + frvfdpic_got_section (info
)->output_offset
5854 + frvfdpic_got_initial_offset (info
);
5855 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5859 dyn
.d_un
.d_ptr
= frvfdpic_pltrel_section (info
)
5860 ->output_section
->vma
5861 + frvfdpic_pltrel_section (info
)->output_offset
;
5862 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5866 dyn
.d_un
.d_val
= frvfdpic_pltrel_section (info
)->size
;
5867 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5876 /* Adjust a symbol defined by a dynamic object and referenced by a
5880 elf32_frvfdpic_adjust_dynamic_symbol
5881 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5882 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
5886 dynobj
= elf_hash_table (info
)->dynobj
;
5888 /* Make sure we know what is going on here. */
5889 BFD_ASSERT (dynobj
!= NULL
5890 && (h
->u
.weakdef
!= NULL
5893 && !h
->def_regular
)));
5895 /* If this is a weak symbol, and there is a real definition, the
5896 processor independent code will have arranged for us to see the
5897 real definition first, and we can just use the same value. */
5898 if (h
->u
.weakdef
!= NULL
)
5900 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
5901 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
5902 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
5903 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
5909 /* Perform any actions needed for dynamic symbols. */
5912 elf32_frvfdpic_finish_dynamic_symbol
5913 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5914 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5915 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
,
5916 Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
)
5921 /* Decide whether to attempt to turn absptr or lsda encodings in
5922 shared libraries into pcrel within the given input section. */
5925 frvfdpic_elf_use_relative_eh_frame
5926 (bfd
*input_bfd ATTRIBUTE_UNUSED
,
5927 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5928 asection
*eh_frame_section ATTRIBUTE_UNUSED
)
5930 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
5934 /* Adjust the contents of an eh_frame_hdr section before they're output. */
5937 frvfdpic_elf_encode_eh_address (bfd
*abfd
,
5938 struct bfd_link_info
*info
,
5939 asection
*osec
, bfd_vma offset
,
5940 asection
*loc_sec
, bfd_vma loc_offset
,
5943 struct elf_link_hash_entry
*h
;
5945 h
= elf_hash_table (info
)->hgot
;
5946 BFD_ASSERT (h
&& h
->root
.type
== bfd_link_hash_defined
);
5948 if (! h
|| (_frvfdpic_osec_to_segment (abfd
, osec
)
5949 == _frvfdpic_osec_to_segment (abfd
, loc_sec
->output_section
)))
5950 return _bfd_elf_encode_eh_address (abfd
, info
, osec
, offset
,
5951 loc_sec
, loc_offset
, encoded
);
5953 BFD_ASSERT (_frvfdpic_osec_to_segment (abfd
, osec
)
5954 == (_frvfdpic_osec_to_segment
5955 (abfd
, h
->root
.u
.def
.section
->output_section
)));
5957 *encoded
= osec
->vma
+ offset
5958 - (h
->root
.u
.def
.value
5959 + h
->root
.u
.def
.section
->output_section
->vma
5960 + h
->root
.u
.def
.section
->output_offset
);
5962 return DW_EH_PE_datarel
| DW_EH_PE_sdata4
;
5965 /* Look through the relocs for a section during the first phase.
5967 Besides handling virtual table relocs for gc, we have to deal with
5968 all sorts of PIC-related relocations. We describe below the
5969 general plan on how to handle such relocations, even though we only
5970 collect information at this point, storing them in hash tables for
5971 perusal of later passes.
5973 32 relocations are propagated to the linker output when creating
5974 position-independent output. LO16 and HI16 relocations are not
5975 supposed to be encountered in this case.
5977 LABEL16 should always be resolvable by the linker, since it's only
5980 LABEL24, on the other hand, is used by calls. If it turns out that
5981 the target of a call is a dynamic symbol, a PLT entry must be
5982 created for it, which triggers the creation of a private function
5983 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
5985 GPREL relocations require the referenced symbol to be in the same
5986 segment as _gp, but this can only be checked later.
5988 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
5989 exist. LABEL24 might as well, since it may require a PLT entry,
5990 that will require a got.
5992 Non-FUNCDESC GOT relocations require a GOT entry to be created
5993 regardless of whether the symbol is dynamic. However, since a
5994 global symbol that turns out to not be exported may have the same
5995 address of a non-dynamic symbol, we don't assign GOT entries at
5996 this point, such that we can share them in this case. A relocation
5997 for the GOT entry always has to be created, be it to offset a
5998 private symbol by the section load address, be it to get the symbol
5999 resolved dynamically.
6001 FUNCDESC GOT relocations require a GOT entry to be created, and
6002 handled as if a FUNCDESC relocation was applied to the GOT entry in
6005 FUNCDESC relocations referencing a symbol that turns out to NOT be
6006 dynamic cause a private function descriptor to be created. The
6007 FUNCDESC relocation then decays to a 32 relocation that points at
6008 the private descriptor. If the symbol is dynamic, the FUNCDESC
6009 relocation is propagated to the linker output, such that the
6010 dynamic linker creates the canonical descriptor, pointing to the
6011 dynamically-resolved definition of the function.
6013 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
6014 symbols that are assigned to the same segment as the GOT, but we
6015 can only check this later, after we know the complete set of
6016 symbols defined and/or exported.
6018 FUNCDESC GOTOFF relocations require a function descriptor to be
6019 created and, unless lazy binding is disabled or the symbol is not
6020 dynamic, a lazy PLT entry. Since we can't tell at this point
6021 whether a symbol is going to be dynamic, we have to decide later
6022 whether to create a lazy PLT entry or bind the descriptor directly
6023 to the private function.
6025 FUNCDESC_VALUE relocations are not supposed to be present in object
6026 files, but they may very well be simply propagated to the linker
6027 output, since they have no side effect.
6030 A function descriptor always requires a FUNCDESC_VALUE relocation.
6031 Whether it's in .plt.rel or not depends on whether lazy binding is
6032 enabled and on whether the referenced symbol is dynamic.
6034 The existence of a lazy PLT requires the resolverStub lazy PLT
6035 entry to be present.
6038 As for assignment of GOT, PLT and lazy PLT entries, and private
6039 descriptors, we might do them all sequentially, but we can do
6040 better than that. For example, we can place GOT entries and
6041 private function descriptors referenced using 12-bit operands
6042 closer to the PIC register value, such that these relocations don't
6043 overflow. Those that are only referenced with LO16 relocations
6044 could come next, but we may as well place PLT-required function
6045 descriptors in the 12-bit range to make them shorter. Symbols
6046 referenced with LO16/HI16 may come next, but we may place
6047 additional function descriptors in the 16-bit range if we can
6048 reliably tell that we've already placed entries that are ever
6049 referenced with only LO16. PLT entries are therefore generated as
6050 small as possible, while not introducing relocation overflows in
6051 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
6052 generated before or after PLT entries, but not intermingled with
6053 them, such that we can have more lazy PLT entries in range for a
6054 branch to the resolverStub. The resolverStub should be emitted at
6055 the most distant location from the first lazy PLT entry such that
6056 it's still in range for a branch, or closer, if there isn't a need
6057 for so many lazy PLT entries. Additional lazy PLT entries may be
6058 emitted after the resolverStub, as long as branches are still in
6059 range. If the branch goes out of range, longer lazy PLT entries
6062 We could further optimize PLT and lazy PLT entries by giving them
6063 priority in assignment to closer-to-gr17 locations depending on the
6064 number of occurrences of references to them (assuming a function
6065 that's called more often is more important for performance, so its
6066 PLT entry should be faster), or taking hints from the compiler.
6067 Given infinite time and money... :-) */
6070 elf32_frv_check_relocs (abfd
, info
, sec
, relocs
)
6072 struct bfd_link_info
*info
;
6074 const Elf_Internal_Rela
*relocs
;
6076 Elf_Internal_Shdr
*symtab_hdr
;
6077 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
6078 const Elf_Internal_Rela
*rel
;
6079 const Elf_Internal_Rela
*rel_end
;
6081 struct frvfdpic_relocs_info
*picrel
;
6083 if (info
->relocatable
)
6086 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6087 sym_hashes
= elf_sym_hashes (abfd
);
6088 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof(Elf32_External_Sym
);
6089 if (!elf_bad_symtab (abfd
))
6090 sym_hashes_end
-= symtab_hdr
->sh_info
;
6092 dynobj
= elf_hash_table (info
)->dynobj
;
6093 rel_end
= relocs
+ sec
->reloc_count
;
6094 for (rel
= relocs
; rel
< rel_end
; rel
++)
6096 struct elf_link_hash_entry
*h
;
6097 unsigned long r_symndx
;
6099 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6100 if (r_symndx
< symtab_hdr
->sh_info
)
6103 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6105 switch (ELF32_R_TYPE (rel
->r_info
))
6107 case R_FRV_GETTLSOFF
:
6108 case R_FRV_TLSDESC_VALUE
:
6109 case R_FRV_GOTTLSDESC12
:
6110 case R_FRV_GOTTLSDESCHI
:
6111 case R_FRV_GOTTLSDESCLO
:
6112 case R_FRV_GOTTLSOFF12
:
6113 case R_FRV_GOTTLSOFFHI
:
6114 case R_FRV_GOTTLSOFFLO
:
6119 case R_FRV_FUNCDESC_GOT12
:
6120 case R_FRV_FUNCDESC_GOTHI
:
6121 case R_FRV_FUNCDESC_GOTLO
:
6122 case R_FRV_GOTOFF12
:
6123 case R_FRV_GOTOFFHI
:
6124 case R_FRV_GOTOFFLO
:
6125 case R_FRV_FUNCDESC_GOTOFF12
:
6126 case R_FRV_FUNCDESC_GOTOFFHI
:
6127 case R_FRV_FUNCDESC_GOTOFFLO
:
6128 case R_FRV_FUNCDESC
:
6129 case R_FRV_FUNCDESC_VALUE
:
6130 case R_FRV_TLSMOFF12
:
6131 case R_FRV_TLSMOFFHI
:
6132 case R_FRV_TLSMOFFLO
:
6134 if (! IS_FDPIC (abfd
))
6138 case R_FRV_GPRELU12
:
6145 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6146 if (! _frv_create_got_section (abfd
, info
))
6149 if (! IS_FDPIC (abfd
))
6156 if (h
->dynindx
== -1)
6157 switch (ELF_ST_VISIBILITY (h
->other
))
6163 bfd_elf_link_record_dynamic_symbol (info
, h
);
6167 = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info
),
6169 rel
->r_addend
, INSERT
);
6172 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
6173 (info
), abfd
, r_symndx
,
6174 rel
->r_addend
, INSERT
);
6184 switch (ELF32_R_TYPE (rel
->r_info
))
6187 if (IS_FDPIC (abfd
))
6191 case R_FRV_FUNCDESC_VALUE
:
6192 picrel
->relocsfdv
++;
6193 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
6198 if (! IS_FDPIC (abfd
))
6202 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
6212 picrel
->gothilo
= 1;
6215 case R_FRV_FUNCDESC_GOT12
:
6216 picrel
->fdgot12
= 1;
6219 case R_FRV_FUNCDESC_GOTHI
:
6220 case R_FRV_FUNCDESC_GOTLO
:
6221 picrel
->fdgothilo
= 1;
6224 case R_FRV_GOTOFF12
:
6225 case R_FRV_GOTOFFHI
:
6226 case R_FRV_GOTOFFLO
:
6230 case R_FRV_FUNCDESC_GOTOFF12
:
6231 picrel
->fdgoff12
= 1;
6234 case R_FRV_FUNCDESC_GOTOFFHI
:
6235 case R_FRV_FUNCDESC_GOTOFFLO
:
6236 picrel
->fdgoffhilo
= 1;
6239 case R_FRV_FUNCDESC
:
6244 case R_FRV_GETTLSOFF
:
6248 case R_FRV_TLSDESC_VALUE
:
6249 picrel
->relocstlsd
++;
6252 case R_FRV_GOTTLSDESC12
:
6253 picrel
->tlsdesc12
= 1;
6256 case R_FRV_GOTTLSDESCHI
:
6257 case R_FRV_GOTTLSDESCLO
:
6258 picrel
->tlsdeschilo
= 1;
6261 case R_FRV_TLSMOFF12
:
6262 case R_FRV_TLSMOFFHI
:
6263 case R_FRV_TLSMOFFLO
:
6267 case R_FRV_GOTTLSOFF12
:
6268 picrel
->tlsoff12
= 1;
6269 info
->flags
|= DF_STATIC_TLS
;
6272 case R_FRV_GOTTLSOFFHI
:
6273 case R_FRV_GOTTLSOFFLO
:
6274 picrel
->tlsoffhilo
= 1;
6275 info
->flags
|= DF_STATIC_TLS
;
6279 picrel
->relocstlsoff
++;
6280 info
->flags
|= DF_STATIC_TLS
;
6283 /* This relocation describes the C++ object vtable hierarchy.
6284 Reconstruct it for later use during GC. */
6285 case R_FRV_GNU_VTINHERIT
:
6286 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6290 /* This relocation describes which C++ vtable entries are actually
6291 used. Record for later use during GC. */
6292 case R_FRV_GNU_VTENTRY
:
6293 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
6301 case R_FRV_GPRELU12
:
6305 case R_FRV_TLSDESC_RELAX
:
6306 case R_FRV_GETTLSOFF_RELAX
:
6307 case R_FRV_TLSOFF_RELAX
:
6312 (*_bfd_error_handler
)
6313 (_("%B: unsupported relocation type %i"),
6314 abfd
, ELF32_R_TYPE (rel
->r_info
));
6323 /* Return the machine subcode from the ELF e_flags header. */
6326 elf32_frv_machine (abfd
)
6329 switch (elf_elfheader (abfd
)->e_flags
& EF_FRV_CPU_MASK
)
6332 case EF_FRV_CPU_FR550
: return bfd_mach_fr550
;
6333 case EF_FRV_CPU_FR500
: return bfd_mach_fr500
;
6334 case EF_FRV_CPU_FR450
: return bfd_mach_fr450
;
6335 case EF_FRV_CPU_FR405
: return bfd_mach_fr400
;
6336 case EF_FRV_CPU_FR400
: return bfd_mach_fr400
;
6337 case EF_FRV_CPU_FR300
: return bfd_mach_fr300
;
6338 case EF_FRV_CPU_SIMPLE
: return bfd_mach_frvsimple
;
6339 case EF_FRV_CPU_TOMCAT
: return bfd_mach_frvtomcat
;
6342 return bfd_mach_frv
;
6345 /* Set the right machine number for a FRV ELF file. */
6348 elf32_frv_object_p (abfd
)
6351 bfd_default_set_arch_mach (abfd
, bfd_arch_frv
, elf32_frv_machine (abfd
));
6352 return (((elf_elfheader (abfd
)->e_flags
& EF_FRV_FDPIC
) != 0)
6353 == (IS_FDPIC (abfd
)));
6356 /* Function to set the ELF flag bits. */
6359 frv_elf_set_private_flags (abfd
, flags
)
6363 elf_elfheader (abfd
)->e_flags
= flags
;
6364 elf_flags_init (abfd
) = TRUE
;
6368 /* Copy backend specific data from one object module to another. */
6371 frv_elf_copy_private_bfd_data (ibfd
, obfd
)
6375 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6376 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6379 BFD_ASSERT (!elf_flags_init (obfd
)
6380 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
6382 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
6383 elf_flags_init (obfd
) = TRUE
;
6387 /* Return true if the architecture described by elf header flag
6388 EXTENSION is an extension of the architecture described by BASE. */
6391 frv_elf_arch_extension_p (flagword base
, flagword extension
)
6393 if (base
== extension
)
6396 /* CPU_GENERIC code can be merged with code for a specific
6397 architecture, in which case the result is marked as being
6398 for the specific architecture. Everything is therefore
6399 an extension of CPU_GENERIC. */
6400 if (base
== EF_FRV_CPU_GENERIC
)
6403 if (extension
== EF_FRV_CPU_FR450
)
6404 if (base
== EF_FRV_CPU_FR400
|| base
== EF_FRV_CPU_FR405
)
6407 if (extension
== EF_FRV_CPU_FR405
)
6408 if (base
== EF_FRV_CPU_FR400
)
6415 elf32_frvfdpic_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
6419 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6420 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6423 if (! frv_elf_copy_private_bfd_data (ibfd
, obfd
))
6426 if (! elf_tdata (ibfd
) || ! elf_tdata (ibfd
)->phdr
6427 || ! elf_tdata (obfd
) || ! elf_tdata (obfd
)->phdr
)
6430 /* Copy the stack size. */
6431 for (i
= 0; i
< elf_elfheader (ibfd
)->e_phnum
; i
++)
6432 if (elf_tdata (ibfd
)->phdr
[i
].p_type
== PT_GNU_STACK
)
6434 Elf_Internal_Phdr
*iphdr
= &elf_tdata (ibfd
)->phdr
[i
];
6436 for (i
= 0; i
< elf_elfheader (obfd
)->e_phnum
; i
++)
6437 if (elf_tdata (obfd
)->phdr
[i
].p_type
== PT_GNU_STACK
)
6439 memcpy (&elf_tdata (obfd
)->phdr
[i
], iphdr
, sizeof (*iphdr
));
6441 /* Rewrite the phdrs, since we're only called after they
6442 were first written. */
6443 if (bfd_seek (obfd
, (bfd_signed_vma
) get_elf_backend_data (obfd
)
6444 ->s
->sizeof_ehdr
, SEEK_SET
) != 0
6445 || get_elf_backend_data (obfd
)->s
6446 ->write_out_phdrs (obfd
, elf_tdata (obfd
)->phdr
,
6447 elf_elfheader (obfd
)->e_phnum
) != 0)
6458 /* Merge backend specific data from an object file to the output
6459 object file when linking. */
6462 frv_elf_merge_private_bfd_data (ibfd
, obfd
)
6466 flagword old_flags
, old_partial
;
6467 flagword new_flags
, new_partial
;
6468 bfd_boolean error
= FALSE
;
6472 new_opt
[0] = old_opt
[0] = '\0';
6473 new_flags
= elf_elfheader (ibfd
)->e_flags
;
6474 old_flags
= elf_elfheader (obfd
)->e_flags
;
6476 if (new_flags
& EF_FRV_FDPIC
)
6477 new_flags
&= ~EF_FRV_PIC
;
6480 (*_bfd_error_handler
) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s",
6481 old_flags
, new_flags
, elf_flags_init (obfd
) ? "yes" : "no",
6482 bfd_get_filename (ibfd
));
6485 if (!elf_flags_init (obfd
)) /* First call, no flags set. */
6487 elf_flags_init (obfd
) = TRUE
;
6488 old_flags
= new_flags
;
6491 else if (new_flags
== old_flags
) /* Compatible flags are ok. */
6494 else /* Possibly incompatible flags. */
6496 /* Warn if different # of gprs are used. Note, 0 means nothing is
6497 said about the size of gprs. */
6498 new_partial
= (new_flags
& EF_FRV_GPR_MASK
);
6499 old_partial
= (old_flags
& EF_FRV_GPR_MASK
);
6500 if (new_partial
== old_partial
)
6503 else if (new_partial
== 0)
6506 else if (old_partial
== 0)
6507 old_flags
|= new_partial
;
6511 switch (new_partial
)
6513 default: strcat (new_opt
, " -mgpr-??"); break;
6514 case EF_FRV_GPR_32
: strcat (new_opt
, " -mgpr-32"); break;
6515 case EF_FRV_GPR_64
: strcat (new_opt
, " -mgpr-64"); break;
6518 switch (old_partial
)
6520 default: strcat (old_opt
, " -mgpr-??"); break;
6521 case EF_FRV_GPR_32
: strcat (old_opt
, " -mgpr-32"); break;
6522 case EF_FRV_GPR_64
: strcat (old_opt
, " -mgpr-64"); break;
6526 /* Warn if different # of fprs are used. Note, 0 means nothing is
6527 said about the size of fprs. */
6528 new_partial
= (new_flags
& EF_FRV_FPR_MASK
);
6529 old_partial
= (old_flags
& EF_FRV_FPR_MASK
);
6530 if (new_partial
== old_partial
)
6533 else if (new_partial
== 0)
6536 else if (old_partial
== 0)
6537 old_flags
|= new_partial
;
6541 switch (new_partial
)
6543 default: strcat (new_opt
, " -mfpr-?"); break;
6544 case EF_FRV_FPR_32
: strcat (new_opt
, " -mfpr-32"); break;
6545 case EF_FRV_FPR_64
: strcat (new_opt
, " -mfpr-64"); break;
6546 case EF_FRV_FPR_NONE
: strcat (new_opt
, " -msoft-float"); break;
6549 switch (old_partial
)
6551 default: strcat (old_opt
, " -mfpr-?"); break;
6552 case EF_FRV_FPR_32
: strcat (old_opt
, " -mfpr-32"); break;
6553 case EF_FRV_FPR_64
: strcat (old_opt
, " -mfpr-64"); break;
6554 case EF_FRV_FPR_NONE
: strcat (old_opt
, " -msoft-float"); break;
6558 /* Warn if different dword support was used. Note, 0 means nothing is
6559 said about the dword support. */
6560 new_partial
= (new_flags
& EF_FRV_DWORD_MASK
);
6561 old_partial
= (old_flags
& EF_FRV_DWORD_MASK
);
6562 if (new_partial
== old_partial
)
6565 else if (new_partial
== 0)
6568 else if (old_partial
== 0)
6569 old_flags
|= new_partial
;
6573 switch (new_partial
)
6575 default: strcat (new_opt
, " -mdword-?"); break;
6576 case EF_FRV_DWORD_YES
: strcat (new_opt
, " -mdword"); break;
6577 case EF_FRV_DWORD_NO
: strcat (new_opt
, " -mno-dword"); break;
6580 switch (old_partial
)
6582 default: strcat (old_opt
, " -mdword-?"); break;
6583 case EF_FRV_DWORD_YES
: strcat (old_opt
, " -mdword"); break;
6584 case EF_FRV_DWORD_NO
: strcat (old_opt
, " -mno-dword"); break;
6588 /* Or in flags that accumulate (ie, if one module uses it, mark that the
6590 old_flags
|= new_flags
& (EF_FRV_DOUBLE
6593 | EF_FRV_NON_PIC_RELOCS
);
6595 /* If any module was compiled without -G0, clear the G0 bit. */
6596 old_flags
= ((old_flags
& ~ EF_FRV_G0
)
6597 | (old_flags
& new_flags
& EF_FRV_G0
));
6599 /* If any module was compiled without -mnopack, clear the mnopack bit. */
6600 old_flags
= ((old_flags
& ~ EF_FRV_NOPACK
)
6601 | (old_flags
& new_flags
& EF_FRV_NOPACK
));
6603 /* We don't have to do anything if the pic flags are the same, or the new
6604 module(s) were compiled with -mlibrary-pic. */
6605 new_partial
= (new_flags
& EF_FRV_PIC_FLAGS
);
6606 old_partial
= (old_flags
& EF_FRV_PIC_FLAGS
);
6607 if ((new_partial
== old_partial
) || ((new_partial
& EF_FRV_LIBPIC
) != 0))
6610 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
6611 flags if any from the new module. */
6612 else if ((old_partial
& EF_FRV_LIBPIC
) != 0)
6613 old_flags
= (old_flags
& ~ EF_FRV_PIC_FLAGS
) | new_partial
;
6615 /* If we have mixtures of -fpic and -fPIC, or in both bits. */
6616 else if (new_partial
!= 0 && old_partial
!= 0)
6617 old_flags
|= new_partial
;
6619 /* One module was compiled for pic and the other was not, see if we have
6620 had any relocations that are not pic-safe. */
6623 if ((old_flags
& EF_FRV_NON_PIC_RELOCS
) == 0)
6624 old_flags
|= new_partial
;
6627 old_flags
&= ~ EF_FRV_PIC_FLAGS
;
6628 #ifndef FRV_NO_PIC_ERROR
6630 (*_bfd_error_handler
)
6631 (_("%s: compiled with %s and linked with modules that use non-pic relocations"),
6632 bfd_get_filename (ibfd
),
6633 (new_flags
& EF_FRV_BIGPIC
) ? "-fPIC" : "-fpic");
6638 /* Warn if different cpu is used (allow a specific cpu to override
6639 the generic cpu). */
6640 new_partial
= (new_flags
& EF_FRV_CPU_MASK
);
6641 old_partial
= (old_flags
& EF_FRV_CPU_MASK
);
6642 if (frv_elf_arch_extension_p (new_partial
, old_partial
))
6645 else if (frv_elf_arch_extension_p (old_partial
, new_partial
))
6646 old_flags
= (old_flags
& ~EF_FRV_CPU_MASK
) | new_partial
;
6650 switch (new_partial
)
6652 default: strcat (new_opt
, " -mcpu=?"); break;
6653 case EF_FRV_CPU_GENERIC
: strcat (new_opt
, " -mcpu=frv"); break;
6654 case EF_FRV_CPU_SIMPLE
: strcat (new_opt
, " -mcpu=simple"); break;
6655 case EF_FRV_CPU_FR550
: strcat (new_opt
, " -mcpu=fr550"); break;
6656 case EF_FRV_CPU_FR500
: strcat (new_opt
, " -mcpu=fr500"); break;
6657 case EF_FRV_CPU_FR450
: strcat (new_opt
, " -mcpu=fr450"); break;
6658 case EF_FRV_CPU_FR405
: strcat (new_opt
, " -mcpu=fr405"); break;
6659 case EF_FRV_CPU_FR400
: strcat (new_opt
, " -mcpu=fr400"); break;
6660 case EF_FRV_CPU_FR300
: strcat (new_opt
, " -mcpu=fr300"); break;
6661 case EF_FRV_CPU_TOMCAT
: strcat (new_opt
, " -mcpu=tomcat"); break;
6664 switch (old_partial
)
6666 default: strcat (old_opt
, " -mcpu=?"); break;
6667 case EF_FRV_CPU_GENERIC
: strcat (old_opt
, " -mcpu=frv"); break;
6668 case EF_FRV_CPU_SIMPLE
: strcat (old_opt
, " -mcpu=simple"); break;
6669 case EF_FRV_CPU_FR550
: strcat (old_opt
, " -mcpu=fr550"); break;
6670 case EF_FRV_CPU_FR500
: strcat (old_opt
, " -mcpu=fr500"); break;
6671 case EF_FRV_CPU_FR450
: strcat (old_opt
, " -mcpu=fr450"); break;
6672 case EF_FRV_CPU_FR405
: strcat (old_opt
, " -mcpu=fr405"); break;
6673 case EF_FRV_CPU_FR400
: strcat (old_opt
, " -mcpu=fr400"); break;
6674 case EF_FRV_CPU_FR300
: strcat (old_opt
, " -mcpu=fr300"); break;
6675 case EF_FRV_CPU_TOMCAT
: strcat (old_opt
, " -mcpu=tomcat"); break;
6679 /* Print out any mismatches from above. */
6683 (*_bfd_error_handler
)
6684 (_("%s: compiled with %s and linked with modules compiled with %s"),
6685 bfd_get_filename (ibfd
), new_opt
, old_opt
);
6688 /* Warn about any other mismatches */
6689 new_partial
= (new_flags
& ~ EF_FRV_ALL_FLAGS
);
6690 old_partial
= (old_flags
& ~ EF_FRV_ALL_FLAGS
);
6691 if (new_partial
!= old_partial
)
6693 old_flags
|= new_partial
;
6695 (*_bfd_error_handler
)
6696 (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"),
6697 bfd_get_filename (ibfd
), (long)new_partial
, (long)old_partial
);
6701 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
6702 if ((old_flags
& EF_FRV_CPU_MASK
) == EF_FRV_CPU_SIMPLE
)
6703 old_flags
|= EF_FRV_NOPACK
;
6705 /* Update the old flags now with changes made above. */
6706 old_partial
= elf_elfheader (obfd
)->e_flags
& EF_FRV_CPU_MASK
;
6707 elf_elfheader (obfd
)->e_flags
= old_flags
;
6708 if (old_partial
!= (old_flags
& EF_FRV_CPU_MASK
))
6709 bfd_default_set_arch_mach (obfd
, bfd_arch_frv
, elf32_frv_machine (obfd
));
6711 if (((new_flags
& EF_FRV_FDPIC
) == 0)
6712 != (! IS_FDPIC (ibfd
)))
6715 if (IS_FDPIC (obfd
))
6716 (*_bfd_error_handler
)
6717 (_("%s: cannot link non-fdpic object file into fdpic executable"),
6718 bfd_get_filename (ibfd
));
6720 (*_bfd_error_handler
)
6721 (_("%s: cannot link fdpic object file into non-fdpic executable"),
6722 bfd_get_filename (ibfd
));
6726 bfd_set_error (bfd_error_bad_value
);
6733 frv_elf_print_private_bfd_data (abfd
, ptr
)
6737 FILE *file
= (FILE *) ptr
;
6740 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6742 /* Print normal ELF private data. */
6743 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6745 flags
= elf_elfheader (abfd
)->e_flags
;
6746 fprintf (file
, _("private flags = 0x%lx:"), (long)flags
);
6748 switch (flags
& EF_FRV_CPU_MASK
)
6751 case EF_FRV_CPU_SIMPLE
: fprintf (file
, " -mcpu=simple"); break;
6752 case EF_FRV_CPU_FR550
: fprintf (file
, " -mcpu=fr550"); break;
6753 case EF_FRV_CPU_FR500
: fprintf (file
, " -mcpu=fr500"); break;
6754 case EF_FRV_CPU_FR450
: fprintf (file
, " -mcpu=fr450"); break;
6755 case EF_FRV_CPU_FR405
: fprintf (file
, " -mcpu=fr405"); break;
6756 case EF_FRV_CPU_FR400
: fprintf (file
, " -mcpu=fr400"); break;
6757 case EF_FRV_CPU_FR300
: fprintf (file
, " -mcpu=fr300"); break;
6758 case EF_FRV_CPU_TOMCAT
: fprintf (file
, " -mcpu=tomcat"); break;
6761 switch (flags
& EF_FRV_GPR_MASK
)
6764 case EF_FRV_GPR_32
: fprintf (file
, " -mgpr-32"); break;
6765 case EF_FRV_GPR_64
: fprintf (file
, " -mgpr-64"); break;
6768 switch (flags
& EF_FRV_FPR_MASK
)
6771 case EF_FRV_FPR_32
: fprintf (file
, " -mfpr-32"); break;
6772 case EF_FRV_FPR_64
: fprintf (file
, " -mfpr-64"); break;
6773 case EF_FRV_FPR_NONE
: fprintf (file
, " -msoft-float"); break;
6776 switch (flags
& EF_FRV_DWORD_MASK
)
6779 case EF_FRV_DWORD_YES
: fprintf (file
, " -mdword"); break;
6780 case EF_FRV_DWORD_NO
: fprintf (file
, " -mno-dword"); break;
6783 if (flags
& EF_FRV_DOUBLE
)
6784 fprintf (file
, " -mdouble");
6786 if (flags
& EF_FRV_MEDIA
)
6787 fprintf (file
, " -mmedia");
6789 if (flags
& EF_FRV_MULADD
)
6790 fprintf (file
, " -mmuladd");
6792 if (flags
& EF_FRV_PIC
)
6793 fprintf (file
, " -fpic");
6795 if (flags
& EF_FRV_BIGPIC
)
6796 fprintf (file
, " -fPIC");
6798 if (flags
& EF_FRV_LIBPIC
)
6799 fprintf (file
, " -mlibrary-pic");
6801 if (flags
& EF_FRV_FDPIC
)
6802 fprintf (file
, " -mfdpic");
6804 if (flags
& EF_FRV_NON_PIC_RELOCS
)
6805 fprintf (file
, " non-pic relocations");
6807 if (flags
& EF_FRV_G0
)
6808 fprintf (file
, " -G0");
6815 #define ELF_ARCH bfd_arch_frv
6816 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
6817 #define ELF_MAXPAGESIZE 0x1000
6819 #define TARGET_BIG_SYM bfd_elf32_frv_vec
6820 #define TARGET_BIG_NAME "elf32-frv"
6822 #define elf_info_to_howto frv_info_to_howto_rela
6823 #define elf_backend_relocate_section elf32_frv_relocate_section
6824 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
6825 #define elf_backend_gc_sweep_hook elf32_frv_gc_sweep_hook
6826 #define elf_backend_check_relocs elf32_frv_check_relocs
6827 #define elf_backend_object_p elf32_frv_object_p
6828 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
6830 #define elf_backend_can_gc_sections 1
6831 #define elf_backend_rela_normal 1
6833 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
6834 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
6835 #define bfd_elf32_bfd_copy_private_bfd_data frv_elf_copy_private_bfd_data
6836 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
6837 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
6839 #define elf_backend_want_got_sym 1
6840 #define elf_backend_got_header_size 0
6841 #define elf_backend_want_got_plt 0
6842 #define elf_backend_plt_readonly 1
6843 #define elf_backend_want_plt_sym 0
6844 #define elf_backend_plt_header_size 0
6846 #define elf_backend_finish_dynamic_sections \
6847 elf32_frv_finish_dynamic_sections
6849 #include "elf32-target.h"
6851 #undef ELF_MAXPAGESIZE
6852 #define ELF_MAXPAGESIZE 0x4000
6854 #undef TARGET_BIG_SYM
6855 #define TARGET_BIG_SYM bfd_elf32_frvfdpic_vec
6856 #undef TARGET_BIG_NAME
6857 #define TARGET_BIG_NAME "elf32-frvfdpic"
6859 #define elf32_bed elf32_frvfdpic_bed
6861 #undef elf_info_to_howto_rel
6862 #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel
6864 #undef bfd_elf32_bfd_link_hash_table_create
6865 #define bfd_elf32_bfd_link_hash_table_create \
6866 frvfdpic_elf_link_hash_table_create
6867 #undef elf_backend_always_size_sections
6868 #define elf_backend_always_size_sections \
6869 elf32_frvfdpic_always_size_sections
6870 #undef elf_backend_modify_segment_map
6871 #define elf_backend_modify_segment_map \
6872 elf32_frvfdpic_modify_segment_map
6873 #undef bfd_elf32_bfd_copy_private_bfd_data
6874 #define bfd_elf32_bfd_copy_private_bfd_data \
6875 elf32_frvfdpic_copy_private_bfd_data
6877 #undef elf_backend_create_dynamic_sections
6878 #define elf_backend_create_dynamic_sections \
6879 elf32_frvfdpic_create_dynamic_sections
6880 #undef elf_backend_adjust_dynamic_symbol
6881 #define elf_backend_adjust_dynamic_symbol \
6882 elf32_frvfdpic_adjust_dynamic_symbol
6883 #undef elf_backend_size_dynamic_sections
6884 #define elf_backend_size_dynamic_sections \
6885 elf32_frvfdpic_size_dynamic_sections
6886 #undef bfd_elf32_bfd_relax_section
6887 #define bfd_elf32_bfd_relax_section \
6888 elf32_frvfdpic_relax_section
6889 #undef elf_backend_finish_dynamic_symbol
6890 #define elf_backend_finish_dynamic_symbol \
6891 elf32_frvfdpic_finish_dynamic_symbol
6892 #undef elf_backend_finish_dynamic_sections
6893 #define elf_backend_finish_dynamic_sections \
6894 elf32_frvfdpic_finish_dynamic_sections
6896 #undef elf_backend_can_make_relative_eh_frame
6897 #define elf_backend_can_make_relative_eh_frame \
6898 frvfdpic_elf_use_relative_eh_frame
6899 #undef elf_backend_can_make_lsda_relative_eh_frame
6900 #define elf_backend_can_make_lsda_relative_eh_frame \
6901 frvfdpic_elf_use_relative_eh_frame
6902 #undef elf_backend_encode_eh_address
6903 #define elf_backend_encode_eh_address \
6904 frvfdpic_elf_encode_eh_address
6906 #undef elf_backend_may_use_rel_p
6907 #define elf_backend_may_use_rel_p 1
6908 #undef elf_backend_may_use_rela_p
6909 #define elf_backend_may_use_rela_p 1
6910 /* We use REL for dynamic relocations only. */
6911 #undef elf_backend_default_use_rela_p
6912 #define elf_backend_default_use_rela_p 1
6914 #undef elf_backend_omit_section_dynsym
6915 #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym
6917 #include "elf32-target.h"