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 /* Map BFD reloc types to FRV ELF reloc types. */
853 unsigned int bfd_reloc_val;
854 unsigned int frv_reloc_val;
857 static const struct frv_reloc_map frv_reloc_map [] =
859 { BFD_RELOC_NONE, R_FRV_NONE },
860 { BFD_RELOC_32, R_FRV_32 },
861 { BFD_RELOC_FRV_LABEL16, R_FRV_LABEL16 },
862 { BFD_RELOC_FRV_LABEL24, R_FRV_LABEL24 },
863 { BFD_RELOC_FRV_LO16, R_FRV_LO16 },
864 { BFD_RELOC_FRV_HI16, R_FRV_HI16 },
865 { BFD_RELOC_FRV_GPREL12, R_FRV_GPREL12 },
866 { BFD_RELOC_FRV_GPRELU12, R_FRV_GPRELU12 },
867 { BFD_RELOC_FRV_GPREL32, R_FRV_GPREL32 },
868 { BFD_RELOC_FRV_GPRELHI, R_FRV_GPRELHI },
869 { BFD_RELOC_FRV_GPRELLO, R_FRV_GPRELLO },
870 { BFD_RELOC_FRV_GOT12, R_FRV_GOT12 },
871 { BFD_RELOC_FRV_GOTHI, R_FRV_GOTHI },
872 { BFD_RELOC_FRV_GOTLO, R_FRV_GOTLO },
873 { BFD_RELOC_FRV_FUNCDESC, R_FRV_FUNCDESC },
874 { BFD_RELOC_FRV_FUNCDESC_GOT12, R_FRV_FUNCDESC_GOT12 },
875 { BFD_RELOC_FRV_FUNCDESC_GOTHI, R_FRV_FUNCDESC_GOTHI },
876 { BFD_RELOC_FRV_FUNCDESC_GOTLO, R_FRV_FUNCDESC_GOTLO },
877 { BFD_RELOC_FRV_FUNCDESC_VALUE, R_FRV_FUNCDESC_VALUE },
878 { BFD_RELOC_FRV_FUNCDESC_GOTOFF12, R_FRV_FUNCDESC_GOTOFF12 },
879 { BFD_RELOC_FRV_FUNCDESC_GOTOFFHI, R_FRV_FUNCDESC_GOTOFFHI },
880 { BFD_RELOC_FRV_FUNCDESC_GOTOFFLO, R_FRV_FUNCDESC_GOTOFFLO },
881 { BFD_RELOC_FRV_GOTOFF12, R_FRV_GOTOFF12 },
882 { BFD_RELOC_FRV_GOTOFFHI, R_FRV_GOTOFFHI },
883 { BFD_RELOC_FRV_GOTOFFLO, R_FRV_GOTOFFLO },
884 { BFD_RELOC_FRV_GETTLSOFF, R_FRV_GETTLSOFF },
885 { BFD_RELOC_FRV_TLSDESC_VALUE, R_FRV_TLSDESC_VALUE },
886 { BFD_RELOC_FRV_GOTTLSDESC12, R_FRV_GOTTLSDESC12 },
887 { BFD_RELOC_FRV_GOTTLSDESCHI, R_FRV_GOTTLSDESCHI },
888 { BFD_RELOC_FRV_GOTTLSDESCLO, R_FRV_GOTTLSDESCLO },
889 { BFD_RELOC_FRV_TLSMOFF12, R_FRV_TLSMOFF12 },
890 { BFD_RELOC_FRV_TLSMOFFHI, R_FRV_TLSMOFFHI },
891 { BFD_RELOC_FRV_TLSMOFFLO, R_FRV_TLSMOFFLO },
892 { BFD_RELOC_FRV_GOTTLSOFF12, R_FRV_GOTTLSOFF12 },
893 { BFD_RELOC_FRV_GOTTLSOFFHI, R_FRV_GOTTLSOFFHI },
894 { BFD_RELOC_FRV_GOTTLSOFFLO, R_FRV_GOTTLSOFFLO },
895 { BFD_RELOC_FRV_TLSOFF, R_FRV_TLSOFF },
896 { BFD_RELOC_FRV_TLSDESC_RELAX, R_FRV_TLSDESC_RELAX },
897 { BFD_RELOC_FRV_GETTLSOFF_RELAX, R_FRV_GETTLSOFF_RELAX },
898 { BFD_RELOC_FRV_TLSOFF_RELAX, R_FRV_TLSOFF_RELAX },
899 { BFD_RELOC_FRV_TLSMOFF, R_FRV_TLSMOFF },
900 { BFD_RELOC_VTABLE_INHERIT, R_FRV_GNU_VTINHERIT },
901 { BFD_RELOC_VTABLE_ENTRY, R_FRV_GNU_VTENTRY },
905 extern const bfd_target bfd_elf32_frvfdpic_vec;
906 #define IS_FDPIC(bfd) ((bfd)->xvec == &bfd_elf32_frvfdpic_vec)
908 /* An extension of the elf hash table data structure, containing some
909 additional FRV-specific data. */
910 struct frvfdpic_elf_link_hash_table
912 struct elf_link_hash_table elf;
914 /* A pointer to the .got section. */
916 /* A pointer to the .rel.got section. */
918 /* A pointer to the .rofixup section. */
920 /* A pointer to the .plt section. */
922 /* A pointer to the .rel.plt section. */
924 /* GOT base offset. */
926 /* Location of the first non-lazy PLT entry, i.e., the number of
927 bytes taken by lazy PLT entries. If locally-bound TLS
928 descriptors require a ret instruction, it will be placed at this
931 /* A hash table holding information about which symbols were
932 referenced with which PIC-related relocations. */
933 struct htab *relocs_info;
934 /* Summary reloc information collected by
935 _frvfdpic_count_got_plt_entries. */
936 struct _frvfdpic_dynamic_got_info *g;
939 /* Get the FRV ELF linker hash table from a link_info structure. */
941 #define frvfdpic_hash_table(info) \
942 ((struct frvfdpic_elf_link_hash_table *) ((info)->hash))
944 #define frvfdpic_got_section(info) \
945 (frvfdpic_hash_table (info)->sgot)
946 #define frvfdpic_gotrel_section(info) \
947 (frvfdpic_hash_table (info)->sgotrel)
948 #define frvfdpic_gotfixup_section(info) \
949 (frvfdpic_hash_table (info)->sgotfixup)
950 #define frvfdpic_plt_section(info) \
951 (frvfdpic_hash_table (info)->splt)
952 #define frvfdpic_pltrel_section(info) \
953 (frvfdpic_hash_table (info)->spltrel)
954 #define frvfdpic_relocs_info(info) \
955 (frvfdpic_hash_table (info)->relocs_info)
956 #define frvfdpic_got_initial_offset(info) \
957 (frvfdpic_hash_table (info)->got0)
958 #define frvfdpic_plt_initial_offset(info) \
959 (frvfdpic_hash_table (info)->plt0)
960 #define frvfdpic_dynamic_got_plt_info(info) \
961 (frvfdpic_hash_table (info)->g)
963 /* Currently it's the same, but if some day we have a reason to change
964 it, we'd better be using a different macro.
966 FIXME: if there's any TLS PLT entry that uses local-exec or
967 initial-exec models, we could use the ret at the end of any of them
968 instead of adding one more. */
969 #define frvfdpic_plt_tls_ret_offset(info) \
970 (frvfdpic_plt_initial_offset (info))
972 /* The name of the dynamic interpreter. This is put in the .interp
975 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
977 #define DEFAULT_STACK_SIZE 0x20000
979 /* This structure is used to collect the number of entries present in
980 each addressable range of the got. */
981 struct _frvfdpic_dynamic_got_info
983 /* Several bits of information about the current link. */
984 struct bfd_link_info *info;
985 /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit
987 bfd_vma got12, gotlos, gothilo;
988 /* Total GOT size needed for function descriptor entries within the 12-,
989 16- or 32-bit ranges. */
990 bfd_vma fd12, fdlos, fdhilo;
991 /* Total GOT size needed by function descriptor entries referenced
992 in PLT entries, that would be profitable to place in offsets
993 close to the PIC register. */
995 /* Total PLT size needed by lazy PLT entries. */
997 /* Total GOT size needed for TLS descriptor entries within the 12-,
998 16- or 32-bit ranges. */
999 bfd_vma tlsd12, tlsdlos, tlsdhilo;
1000 /* Total GOT size needed by TLS descriptors referenced in PLT
1001 entries, that would be profitable to place in offers close to the
1004 /* Total PLT size needed by TLS lazy PLT entries. */
1006 /* Number of relocations carried over from input object files. */
1007 unsigned long relocs;
1008 /* Number of fixups introduced by relocations in input object files. */
1009 unsigned long fixups;
1010 /* The number of fixups that reference the ret instruction added to
1011 the PLT for locally-resolved TLS descriptors. */
1012 unsigned long tls_ret_refs;
1015 /* This structure is used to assign offsets to got entries, function
1016 descriptors, plt entries and lazy plt entries. */
1018 struct _frvfdpic_dynamic_got_plt_info
1020 /* Summary information collected with _frvfdpic_count_got_plt_entries. */
1021 struct _frvfdpic_dynamic_got_info g;
1023 /* For each addressable range, we record a MAX (positive) and MIN
1024 (negative) value. CUR is used to assign got entries, and it's
1025 incremented from an initial positive value to MAX, then from MIN
1026 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
1027 assign function descriptors, and it's decreased from an initial
1028 non-positive value to MIN, then from MAX down to CUR (unless CUR
1029 wraps around first). All of MIN, MAX, CUR and FDCUR always point
1030 to even words. ODD, if non-zero, indicates an odd word to be
1031 used for the next got entry, otherwise CUR is used and
1032 incremented by a pair of words, wrapping around when it reaches
1033 MAX. FDCUR is decremented (and wrapped) before the next function
1034 descriptor is chosen. FDPLT indicates the number of remaining
1035 slots that can be used for function descriptors used only by PLT
1038 TMAX, TMIN and TCUR are used to assign TLS descriptors. TCUR
1039 starts as MAX, and grows up to TMAX, then wraps around to TMIN
1040 and grows up to MIN. TLSDPLT indicates the number of remaining
1041 slots that can be used for TLS descriptors used only by TLS PLT
1043 struct _frvfdpic_dynamic_got_alloc_data
1045 bfd_signed_vma max, cur, odd, fdcur, min;
1046 bfd_signed_vma tmax, tcur, tmin;
1047 bfd_vma fdplt, tlsdplt;
1048 } got12, gotlos, gothilo;
1051 /* Create an FRV ELF linker hash table. */
1053 static struct bfd_link_hash_table *
1054 frvfdpic_elf_link_hash_table_create (bfd *abfd)
1056 struct frvfdpic_elf_link_hash_table *ret;
1057 bfd_size_type amt = sizeof (struct frvfdpic_elf_link_hash_table);
1059 ret = bfd_zalloc (abfd, amt);
1063 if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd,
1064 _bfd_elf_link_hash_newfunc))
1070 return &ret->elf.root;
1073 /* Decide whether a reference to a symbol can be resolved locally or
1074 not. If the symbol is protected, we want the local address, but
1075 its function descriptor must be assigned by the dynamic linker. */
1076 #define FRVFDPIC_SYM_LOCAL(INFO, H) \
1077 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
1078 || ! elf_hash_table (INFO)->dynamic_sections_created \
1079 /* These two additional alternatives are needed for TLS
1080 relocations, that use *ABS*+offset relocations to refer to the
1081 TLS section of the local module. FIXME: At some point during
1082 linking, the definition section ceases to be regarded as the
1083 absolute section, and starts being regarded as the undefined
1085 || bfd_is_abs_section ((H)->root.u.def.section) \
1086 || bfd_is_und_section ((H)->root.u.def.section))
1087 #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \
1088 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
1090 /* This structure collects information on what kind of GOT, PLT or
1091 function descriptors are required by relocations that reference a
1093 struct frvfdpic_relocs_info
1095 /* The index of the symbol, as stored in the relocation r_info, if
1096 we have a local symbol; -1 otherwise. */
1100 /* The input bfd in which the symbol is defined, if it's a local
1103 /* If symndx == -1, the hash table entry corresponding to a global
1104 symbol (even if it turns out to bind locally, in which case it
1105 should ideally be replaced with section's symndx + addend). */
1106 struct elf_link_hash_entry *h;
1108 /* The addend of the relocation that references the symbol. */
1111 /* The fields above are used to identify an entry. The fields below
1112 contain information on how an entry is used and, later on, which
1113 locations it was assigned. */
1114 /* The following 3 fields record whether the symbol+addend above was
1115 ever referenced with a GOT relocation. The 12 suffix indicates a
1116 GOT12 relocation; los is used for GOTLO relocations that are not
1117 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
1122 /* Whether a FUNCDESC relocation references symbol+addend. */
1124 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
1126 unsigned fdgotlos:1;
1127 unsigned fdgothilo:1;
1128 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
1129 unsigned fdgoff12:1;
1130 unsigned fdgofflos:1;
1131 unsigned fdgoffhilo:1;
1132 /* Whether a GETTLSOFF relocation references symbol+addend. */
1134 /* FIXME: we should probably add tlspltdesc, tlspltoff and
1135 tlspltimm, to tell what kind of TLS PLT entry we're generating.
1136 We might instead just pre-compute flags telling whether the
1137 object is suitable for local exec, initial exec or general
1138 dynamic addressing, and use that all over the place. We could
1139 also try to do a better job of merging TLSOFF and TLSDESC entries
1140 in main executables, but perhaps we can get rid of TLSDESC
1141 entirely in them instead. */
1142 /* Whether a GOTTLSDESC relocation references symbol+addend. */
1143 unsigned tlsdesc12:1;
1144 unsigned tlsdesclos:1;
1145 unsigned tlsdeschilo:1;
1146 /* Whether a GOTTLSOFF relocation references symbol+addend. */
1147 unsigned tlsoff12:1;
1148 unsigned tlsofflos:1;
1149 unsigned tlsoffhilo:1;
1150 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
1151 GOTOFFHI relocations. The addend doesn't really matter, since we
1152 envision that this will only be used to check whether the symbol
1153 is mapped to the same segment as the got. */
1155 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
1157 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
1160 /* Whether we need a PLT entry for a symbol. Should be implied by
1162 (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */
1164 /* Whether a function descriptor should be created in this link unit
1165 for symbol+addend. Should be implied by something like:
1166 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
1167 || ((fd || fdgot12 || fdgotlos || fdgothilo)
1168 && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */
1170 /* Whether a lazy PLT entry is needed for this symbol+addend.
1171 Should be implied by something like:
1172 (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)
1173 && ! (info->flags & DF_BIND_NOW)) */
1175 /* Whether we've already emitted GOT relocations and PLT entries as
1176 needed for this symbol. */
1179 /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and
1180 R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing
1182 unsigned relocs32, relocsfd, relocsfdv, relocstlsd, relocstlsoff;
1184 /* The number of .rofixups entries and dynamic relocations allocated
1185 for this symbol, minus any that might have already been used. */
1186 unsigned fixups, dynrelocs;
1188 /* The offsets of the GOT entries assigned to symbol+addend, to the
1189 function descriptor's address, and to a function descriptor,
1190 respectively. Should be zero if unassigned. The offsets are
1191 counted from the value that will be assigned to the PIC register,
1192 not from the beginning of the .got section. */
1193 bfd_signed_vma got_entry, fdgot_entry, fd_entry;
1194 /* The offsets of the PLT entries assigned to symbol+addend,
1195 non-lazy and lazy, respectively. If unassigned, should be
1197 bfd_vma plt_entry, lzplt_entry;
1198 /* The offsets of the GOT entries for TLS offset and TLS descriptor. */
1199 bfd_signed_vma tlsoff_entry, tlsdesc_entry;
1200 /* The offset of the TLS offset PLT entry. */
1201 bfd_vma tlsplt_entry;
1204 /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */
1206 frvfdpic_relocs_info_hash (const void *entry_)
1208 const struct frvfdpic_relocs_info *entry = entry_;
1210 return (entry->symndx == -1
1211 ? (long)entry->d.h->root.root.hash
1212 : entry->symndx + entry->d.abfd->id * 257) + entry->addend;
1215 /* Test whether the key fields of two frvfdpic_relocs_info entries are
1218 frvfdpic_relocs_info_eq (const void *entry1, const void *entry2)
1220 const struct frvfdpic_relocs_info *e1 = entry1;
1221 const struct frvfdpic_relocs_info *e2 = entry2;
1223 return e1->symndx == e2->symndx && e1->addend == e2->addend
1224 && (e1->symndx == -1 ? e1->d.h == e2->d.h : e1->d.abfd == e2->d.abfd);
1227 /* Find or create an entry in a hash table HT that matches the key
1228 fields of the given ENTRY. If it's not found, memory for a new
1229 entry is allocated in ABFD's obstack. */
1230 static struct frvfdpic_relocs_info *
1231 frvfdpic_relocs_info_find (struct htab *ht,
1233 const struct frvfdpic_relocs_info *entry,
1234 enum insert_option insert)
1236 struct frvfdpic_relocs_info **loc =
1237 (struct frvfdpic_relocs_info **) htab_find_slot (ht, entry, insert);
1245 *loc = bfd_zalloc (abfd, sizeof (**loc));
1250 (*loc)->symndx = entry->symndx;
1251 (*loc)->d = entry->d;
1252 (*loc)->addend = entry->addend;
1253 (*loc)->plt_entry = (bfd_vma)-1;
1254 (*loc)->lzplt_entry = (bfd_vma)-1;
1255 (*loc)->tlsplt_entry = (bfd_vma)-1;
1260 /* Obtain the address of the entry in HT associated with H's symbol +
1261 addend, creating a new entry if none existed. ABFD is only used
1262 for memory allocation purposes. */
1263 inline static struct frvfdpic_relocs_info *
1264 frvfdpic_relocs_info_for_global (struct htab *ht,
1266 struct elf_link_hash_entry *h,
1268 enum insert_option insert)
1270 struct frvfdpic_relocs_info entry;
1274 entry.addend = addend;
1276 return frvfdpic_relocs_info_find (ht, abfd, &entry, insert);
1279 /* Obtain the address of the entry in HT associated with the SYMNDXth
1280 local symbol of the input bfd ABFD, plus the addend, creating a new
1281 entry if none existed. */
1282 inline static struct frvfdpic_relocs_info *
1283 frvfdpic_relocs_info_for_local (struct htab *ht,
1287 enum insert_option insert)
1289 struct frvfdpic_relocs_info entry;
1291 entry.symndx = symndx;
1292 entry.d.abfd = abfd;
1293 entry.addend = addend;
1295 return frvfdpic_relocs_info_find (ht, abfd, &entry, insert);
1298 /* Merge fields set by check_relocs() of two entries that end up being
1299 mapped to the same (presumably global) symbol. */
1302 frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info *e2,
1303 struct frvfdpic_relocs_info const *e1)
1305 e2->got12 |= e1->got12;
1306 e2->gotlos |= e1->gotlos;
1307 e2->gothilo |= e1->gothilo;
1309 e2->fdgot12 |= e1->fdgot12;
1310 e2->fdgotlos |= e1->fdgotlos;
1311 e2->fdgothilo |= e1->fdgothilo;
1312 e2->fdgoff12 |= e1->fdgoff12;
1313 e2->fdgofflos |= e1->fdgofflos;
1314 e2->fdgoffhilo |= e1->fdgoffhilo;
1315 e2->tlsplt |= e1->tlsplt;
1316 e2->tlsdesc12 |= e1->tlsdesc12;
1317 e2->tlsdesclos |= e1->tlsdesclos;
1318 e2->tlsdeschilo |= e1->tlsdeschilo;
1319 e2->tlsoff12 |= e1->tlsoff12;
1320 e2->tlsofflos |= e1->tlsofflos;
1321 e2->tlsoffhilo |= e1->tlsoffhilo;
1322 e2->gotoff |= e1->gotoff;
1323 e2->call |= e1->call;
1327 /* These are set in _frvfdpic_count_got_plt_entries() or later, and this
1328 function is only called in _frvfdpic_resolve_final_relocs_info(), that
1329 runs just before it, so we don't have to worry about the fields
1333 e2->privfd |= e1->privfd;
1334 e2->lazyplt |= e1->lazyplt;
1335 e2->done |= e1->done;
1337 e2->relocs32 += e1->relocs32;
1338 e2->relocsfd += e1->relocsfd;
1339 e2->relocsfdv += e1->relocsfdv;
1340 e2->relocstlsd += e1->relocstlsd;
1341 e2->relocstlsoff += e1->relocstlsoff;
1342 e2->fixups += e1->fixups;
1343 e2->dynrelocs += e1->dynrelocs;
1345 if (abs (e1->got_entry) < abs (e2->got_entry))
1346 e2->got_entry = e1->got_entry;
1347 if (abs (e1->fdgot_entry) < abs (e2->fdgot_entry))
1348 e2->fdgot_entry = e1->fdgot_entry;
1349 if (abs (e1->fd_entry) < abs (e2->fd_entry))
1350 e2->fd_entry = e1->fd_entry;
1352 if (e1->plt_entry < e2->plt_entry)
1353 e2->plt_entry = e1->plt_entry;
1354 if (e1->lzplt_entry < e2->lzplt_entry)
1355 e2->lzplt_entry = e1->lzplt_entry;
1357 if (abs (e1->tlsoff_entry) < abs (e2->tlsoff_entry))
1358 e2->tlsoff_entry = e1->tlsoff_entry;
1359 if (abs (e1->tlsdesc_entry) < abs (e2->tlsdesc_entry))
1360 e2->tlsdesc_entry = e1->tlsdesc_entry;
1362 if (e1->tlsplt_entry < e2->tlsplt_entry)
1363 t2->tlsplt_entry = t1->tlsplt_entry;
1367 /* Every block of 65535 lazy PLT entries shares a single call to the
1368 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
1369 32767, counting from 0). All other lazy PLT entries branch to it
1370 in a single instruction. */
1372 #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
1373 #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767)
1375 /* Add a dynamic relocation to the SRELOC section. */
1377 inline static bfd_vma
1378 _frvfdpic_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset,
1379 int reloc_type, long dynindx, bfd_vma addend,
1380 struct frvfdpic_relocs_info *entry)
1382 Elf_Internal_Rela outrel;
1383 bfd_vma reloc_offset;
1385 outrel.r_offset = offset;
1386 outrel.r_info = ELF32_R_INFO (dynindx, reloc_type);
1387 outrel.r_addend = addend;
1389 reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rel);
1390 BFD_ASSERT (reloc_offset < sreloc->size);
1391 bfd_elf32_swap_reloc_out (output_bfd, &outrel,
1392 sreloc->contents + reloc_offset);
1393 sreloc->reloc_count++;
1395 /* If the entry's index is zero, this relocation was probably to a
1396 linkonce section that got discarded. We reserved a dynamic
1397 relocation, but it was for another entry than the one we got at
1398 the time of emitting the relocation. Unfortunately there's no
1399 simple way for us to catch this situation, since the relocation
1400 is cleared right before calling relocate_section, at which point
1401 we no longer know what the relocation used to point to. */
1404 BFD_ASSERT (entry->dynrelocs > 0);
1408 return reloc_offset;
1411 /* Add a fixup to the ROFIXUP section. */
1414 _frvfdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset,
1415 struct frvfdpic_relocs_info *entry)
1417 bfd_vma fixup_offset;
1419 if (rofixup->flags & SEC_EXCLUDE)
1422 fixup_offset = rofixup->reloc_count * 4;
1423 if (rofixup->contents)
1425 BFD_ASSERT (fixup_offset < rofixup->size);
1426 bfd_put_32 (output_bfd, offset, rofixup->contents + fixup_offset);
1428 rofixup->reloc_count++;
1430 if (entry && entry->symndx)
1432 /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc
1434 BFD_ASSERT (entry->fixups > 0);
1438 return fixup_offset;
1441 /* Find the segment number in which OSEC, and output section, is
1445 _frvfdpic_osec_to_segment (bfd *output_bfd, asection *osec)
1447 struct elf_segment_map *m;
1448 Elf_Internal_Phdr *p;
1450 /* Find the segment that contains the output_section. */
1451 for (m = elf_tdata (output_bfd)->segment_map,
1452 p = elf_tdata (output_bfd)->phdr;
1458 for (i = m->count - 1; i >= 0; i--)
1459 if (m->sections[i] == osec)
1466 return p - elf_tdata (output_bfd)->phdr;
1469 inline static bfd_boolean
1470 _frvfdpic_osec_readonly_p (bfd *output_bfd, asection *osec)
1472 unsigned seg = _frvfdpic_osec_to_segment (output_bfd, osec);
1474 return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W);
1477 #define FRVFDPIC_TLS_BIAS (2048 - 16)
1479 /* Return the base VMA address which should be subtracted from real addresses
1480 when resolving TLSMOFF relocation.
1481 This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */
1484 tls_biased_base (struct bfd_link_info *info)
1486 /* If tls_sec is NULL, we should have signalled an error already. */
1487 if (elf_hash_table (info)->tls_sec == NULL)
1488 return FRVFDPIC_TLS_BIAS;
1489 return elf_hash_table (info)->tls_sec->vma + FRVFDPIC_TLS_BIAS;
1492 /* Generate relocations for GOT entries, function descriptors, and
1493 code for PLT and lazy PLT entries. */
1495 inline static bfd_boolean
1496 _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info *entry,
1498 struct bfd_link_info *info,
1500 Elf_Internal_Sym *sym,
1504 bfd_vma fd_lazy_rel_offset = (bfd_vma)-1;
1511 if (entry->got_entry || entry->fdgot_entry || entry->fd_entry
1512 || entry->tlsoff_entry || entry->tlsdesc_entry)
1514 /* If the symbol is dynamic, consider it for dynamic
1515 relocations, otherwise decay to section + offset. */
1516 if (entry->symndx == -1 && entry->d.h->dynindx != -1)
1517 dynindx = entry->d.h->dynindx;
1520 if (sec->output_section
1521 && ! bfd_is_abs_section (sec->output_section)
1522 && ! bfd_is_und_section (sec->output_section))
1523 dynindx = elf_section_data (sec->output_section)->dynindx;
1529 /* Generate relocation for GOT entry pointing to the symbol. */
1530 if (entry->got_entry)
1533 bfd_vma ad = addend;
1535 /* If the symbol is dynamic but binds locally, use
1537 if (sec && (entry->symndx != -1
1538 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1540 if (entry->symndx == -1)
1541 ad += entry->d.h->root.u.def.value;
1543 ad += sym->st_value;
1544 ad += sec->output_offset;
1545 if (sec->output_section && elf_section_data (sec->output_section))
1546 idx = elf_section_data (sec->output_section)->dynindx;
1551 /* If we're linking an executable at a fixed address, we can
1552 omit the dynamic relocation as long as the symbol is local to
1554 if (info->executable && !info->pie
1555 && (entry->symndx != -1
1556 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1559 ad += sec->output_section->vma;
1560 if (entry->symndx != -1
1561 || entry->d.h->root.type != bfd_link_hash_undefweak)
1562 _frvfdpic_add_rofixup (output_bfd,
1563 frvfdpic_gotfixup_section (info),
1564 frvfdpic_got_section (info)->output_section
1566 + frvfdpic_got_section (info)->output_offset
1567 + frvfdpic_got_initial_offset (info)
1568 + entry->got_entry, entry);
1571 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
1572 _bfd_elf_section_offset
1574 frvfdpic_got_section (info),
1575 frvfdpic_got_initial_offset (info)
1577 + frvfdpic_got_section (info)
1578 ->output_section->vma
1579 + frvfdpic_got_section (info)->output_offset,
1580 R_FRV_32, idx, ad, entry);
1582 bfd_put_32 (output_bfd, ad,
1583 frvfdpic_got_section (info)->contents
1584 + frvfdpic_got_initial_offset (info)
1585 + entry->got_entry);
1588 /* Generate relocation for GOT entry pointing to a canonical
1589 function descriptor. */
1590 if (entry->fdgot_entry)
1595 if (! (entry->symndx == -1
1596 && entry->d.h->root.type == bfd_link_hash_undefweak
1597 && FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1599 /* If the symbol is dynamic and there may be dynamic symbol
1600 resolution because we are, or are linked with, a shared
1601 library, emit a FUNCDESC relocation such that the dynamic
1602 linker will allocate the function descriptor. If the
1603 symbol needs a non-local function descriptor but binds
1604 locally (e.g., its visibility is protected, emit a
1605 dynamic relocation decayed to section+offset. */
1606 if (entry->symndx == -1
1607 && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)
1608 && FRVFDPIC_SYM_LOCAL (info, entry->d.h)
1609 && !(info->executable && !info->pie))
1611 reloc = R_FRV_FUNCDESC;
1612 idx = elf_section_data (entry->d.h->root.u.def.section
1613 ->output_section)->dynindx;
1614 ad = entry->d.h->root.u.def.section->output_offset
1615 + entry->d.h->root.u.def.value;
1617 else if (entry->symndx == -1
1618 && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h))
1620 reloc = R_FRV_FUNCDESC;
1628 /* Otherwise, we know we have a private function descriptor,
1629 so reference it directly. */
1630 if (elf_hash_table (info)->dynamic_sections_created)
1631 BFD_ASSERT (entry->privfd);
1633 idx = elf_section_data (frvfdpic_got_section (info)
1634 ->output_section)->dynindx;
1635 ad = frvfdpic_got_section (info)->output_offset
1636 + frvfdpic_got_initial_offset (info) + entry->fd_entry;
1639 /* If there is room for dynamic symbol resolution, emit the
1640 dynamic relocation. However, if we're linking an
1641 executable at a fixed location, we won't have emitted a
1642 dynamic symbol entry for the got section, so idx will be
1643 zero, which means we can and should compute the address
1644 of the private descriptor ourselves. */
1645 if (info->executable && !info->pie
1646 && (entry->symndx != -1
1647 || FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)))
1649 ad += frvfdpic_got_section (info)->output_section->vma;
1650 _frvfdpic_add_rofixup (output_bfd,
1651 frvfdpic_gotfixup_section (info),
1652 frvfdpic_got_section (info)
1653 ->output_section->vma
1654 + frvfdpic_got_section (info)
1656 + frvfdpic_got_initial_offset (info)
1657 + entry->fdgot_entry, entry);
1660 _frvfdpic_add_dyn_reloc (output_bfd,
1661 frvfdpic_gotrel_section (info),
1662 _bfd_elf_section_offset
1664 frvfdpic_got_section (info),
1665 frvfdpic_got_initial_offset (info)
1666 + entry->fdgot_entry)
1667 + frvfdpic_got_section (info)
1668 ->output_section->vma
1669 + frvfdpic_got_section (info)
1671 reloc, idx, ad, entry);
1674 bfd_put_32 (output_bfd, ad,
1675 frvfdpic_got_section (info)->contents
1676 + frvfdpic_got_initial_offset (info)
1677 + entry->fdgot_entry);
1680 /* Generate relocation to fill in a private function descriptor in
1682 if (entry->fd_entry)
1685 bfd_vma ad = addend;
1687 long lowword, highword;
1689 /* If the symbol is dynamic but binds locally, use
1691 if (sec && (entry->symndx != -1
1692 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1694 if (entry->symndx == -1)
1695 ad += entry->d.h->root.u.def.value;
1697 ad += sym->st_value;
1698 ad += sec->output_offset;
1699 if (sec->output_section && elf_section_data (sec->output_section))
1700 idx = elf_section_data (sec->output_section)->dynindx;
1705 /* If we're linking an executable at a fixed address, we can
1706 omit the dynamic relocation as long as the symbol is local to
1708 if (info->executable && !info->pie
1709 && (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1712 ad += sec->output_section->vma;
1714 if (entry->symndx != -1
1715 || entry->d.h->root.type != bfd_link_hash_undefweak)
1717 _frvfdpic_add_rofixup (output_bfd,
1718 frvfdpic_gotfixup_section (info),
1719 frvfdpic_got_section (info)
1720 ->output_section->vma
1721 + frvfdpic_got_section (info)
1723 + frvfdpic_got_initial_offset (info)
1724 + entry->fd_entry, entry);
1725 _frvfdpic_add_rofixup (output_bfd,
1726 frvfdpic_gotfixup_section (info),
1727 frvfdpic_got_section (info)
1728 ->output_section->vma
1729 + frvfdpic_got_section (info)
1731 + frvfdpic_got_initial_offset (info)
1732 + entry->fd_entry + 4, entry);
1738 _frvfdpic_add_dyn_reloc (output_bfd,
1740 ? frvfdpic_pltrel_section (info)
1741 : frvfdpic_gotrel_section (info),
1742 _bfd_elf_section_offset
1744 frvfdpic_got_section (info),
1745 frvfdpic_got_initial_offset (info)
1747 + frvfdpic_got_section (info)
1748 ->output_section->vma
1749 + frvfdpic_got_section (info)
1751 R_FRV_FUNCDESC_VALUE, idx, ad, entry);
1754 /* If we've omitted the dynamic relocation, just emit the fixed
1755 addresses of the symbol and of the local GOT base offset. */
1756 if (info->executable && !info->pie && sec && sec->output_section)
1759 highword = frvfdpic_got_section (info)->output_section->vma
1760 + frvfdpic_got_section (info)->output_offset
1761 + frvfdpic_got_initial_offset (info);
1763 else if (entry->lazyplt)
1768 fd_lazy_rel_offset = ofst;
1770 /* A function descriptor used for lazy or local resolving is
1771 initialized such that its high word contains the output
1772 section index in which the PLT entries are located, and
1773 the low word contains the address of the lazy PLT entry
1774 entry point, that must be within the memory region
1775 assigned to that section. */
1776 lowword = entry->lzplt_entry + 4
1777 + frvfdpic_plt_section (info)->output_offset
1778 + frvfdpic_plt_section (info)->output_section->vma;
1779 highword = _frvfdpic_osec_to_segment
1780 (output_bfd, frvfdpic_plt_section (info)->output_section);
1784 /* A function descriptor for a local function gets the index
1785 of the section. For a non-local function, it's
1788 if (entry->symndx == -1 && entry->d.h->dynindx != -1
1789 && entry->d.h->dynindx == idx)
1792 highword = _frvfdpic_osec_to_segment
1793 (output_bfd, sec->output_section);
1796 bfd_put_32 (output_bfd, lowword,
1797 frvfdpic_got_section (info)->contents
1798 + frvfdpic_got_initial_offset (info)
1800 bfd_put_32 (output_bfd, highword,
1801 frvfdpic_got_section (info)->contents
1802 + frvfdpic_got_initial_offset (info)
1803 + entry->fd_entry + 4);
1806 /* Generate code for the PLT entry. */
1807 if (entry->plt_entry != (bfd_vma) -1)
1809 bfd_byte *plt_code = frvfdpic_plt_section (info)->contents
1812 BFD_ASSERT (entry->fd_entry);
1814 /* Figure out what kind of PLT entry we need, depending on the
1815 location of the function descriptor within the GOT. */
1816 if (entry->fd_entry >= -(1 << (12 - 1))
1817 && entry->fd_entry < (1 << (12 - 1)))
1819 /* lddi @(gr15, fd_entry), gr14 */
1820 bfd_put_32 (output_bfd,
1821 0x9cccf000 | (entry->fd_entry & ((1 << 12) - 1)),
1827 if (entry->fd_entry >= -(1 << (16 - 1))
1828 && entry->fd_entry < (1 << (16 - 1)))
1830 /* setlos lo(fd_entry), gr14 */
1831 bfd_put_32 (output_bfd,
1833 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
1839 /* sethi.p hi(fd_entry), gr14
1840 setlo lo(fd_entry), gr14 */
1841 bfd_put_32 (output_bfd,
1843 | ((entry->fd_entry >> 16)
1844 & (((bfd_vma)1 << 16) - 1)),
1847 bfd_put_32 (output_bfd,
1849 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
1853 /* ldd @(gr14,gr15),gr14 */
1854 bfd_put_32 (output_bfd, 0x9c08e14f, plt_code);
1857 /* jmpl @(gr14,gr0) */
1858 bfd_put_32 (output_bfd, 0x8030e000, plt_code);
1861 /* Generate code for the lazy PLT entry. */
1862 if (entry->lzplt_entry != (bfd_vma) -1)
1864 bfd_byte *lzplt_code = frvfdpic_plt_section (info)->contents
1865 + entry->lzplt_entry;
1866 bfd_vma resolverStub_addr;
1868 bfd_put_32 (output_bfd, fd_lazy_rel_offset, lzplt_code);
1871 resolverStub_addr = entry->lzplt_entry / FRVFDPIC_LZPLT_BLOCK_SIZE
1872 * FRVFDPIC_LZPLT_BLOCK_SIZE + FRVFDPIC_LZPLT_RESOLV_LOC;
1873 if (resolverStub_addr >= frvfdpic_plt_initial_offset (info))
1874 resolverStub_addr = frvfdpic_plt_initial_offset (info) - 12;
1876 if (entry->lzplt_entry == resolverStub_addr)
1878 /* This is a lazy PLT entry that includes a resolver call. */
1879 /* ldd @(gr15,gr0), gr4
1881 bfd_put_32 (output_bfd, 0x8808f140, lzplt_code);
1882 bfd_put_32 (output_bfd, 0x80304000, lzplt_code + 4);
1886 /* bra resolverStub */
1887 bfd_put_32 (output_bfd,
1889 | (((resolverStub_addr - entry->lzplt_entry)
1890 / 4) & (((bfd_vma)1 << 16) - 1)),
1895 /* Generate relocation for GOT entry holding the TLS offset. */
1896 if (entry->tlsoff_entry)
1899 bfd_vma ad = addend;
1901 if (entry->symndx != -1
1902 || FRVFDPIC_SYM_LOCAL (info, entry->d.h))
1904 /* If the symbol is dynamic but binds locally, use
1908 if (entry->symndx == -1)
1909 ad += entry->d.h->root.u.def.value;
1911 ad += sym->st_value;
1912 ad += sec->output_offset;
1913 if (sec->output_section
1914 && elf_section_data (sec->output_section))
1915 idx = elf_section_data (sec->output_section)->dynindx;
1921 /* *ABS*+addend is special for TLS relocations, use only the
1923 if (info->executable
1925 && (bfd_is_abs_section (sec)
1926 || bfd_is_und_section (sec)))
1928 /* If we're linking an executable, we can entirely omit the
1929 dynamic relocation if the symbol is local to this module. */
1930 else if (info->executable
1931 && (entry->symndx != -1
1932 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1935 ad += sec->output_section->vma - tls_biased_base (info);
1940 && (bfd_is_abs_section (sec)
1941 || bfd_is_und_section (sec)))
1943 idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx;
1944 ad += FRVFDPIC_TLS_BIAS;
1946 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
1947 _bfd_elf_section_offset
1949 frvfdpic_got_section (info),
1950 frvfdpic_got_initial_offset (info)
1951 + entry->tlsoff_entry)
1952 + frvfdpic_got_section (info)
1953 ->output_section->vma
1954 + frvfdpic_got_section (info)
1956 R_FRV_TLSOFF, idx, ad, entry);
1959 bfd_put_32 (output_bfd, ad,
1960 frvfdpic_got_section (info)->contents
1961 + frvfdpic_got_initial_offset (info)
1962 + entry->tlsoff_entry);
1965 if (entry->tlsdesc_entry)
1968 bfd_vma ad = addend;
1970 /* If the symbol is dynamic but binds locally, use
1972 if (sec && (entry->symndx != -1
1973 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1975 if (entry->symndx == -1)
1976 ad += entry->d.h->root.u.def.value;
1978 ad += sym->st_value;
1979 ad += sec->output_offset;
1980 if (sec->output_section && elf_section_data (sec->output_section))
1981 idx = elf_section_data (sec->output_section)->dynindx;
1986 /* If we didn't set up a TLS offset entry, but we're linking an
1987 executable and the symbol binds locally, we can use the
1988 module offset in the TLS descriptor in relaxations. */
1989 if (info->executable && ! entry->tlsoff_entry)
1990 entry->tlsoff_entry = entry->tlsdesc_entry + 4;
1992 if (info->executable && !info->pie
1994 && (bfd_is_abs_section (sec)
1995 || bfd_is_und_section (sec)))
1996 || entry->symndx != -1
1997 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1999 /* *ABS*+addend is special for TLS relocations, use only the
2000 addend for the TLS offset, and take the module id as
2003 && (bfd_is_abs_section (sec)
2004 || bfd_is_und_section (sec)))
2006 /* For other TLS symbols that bind locally, add the section
2007 TLS offset to the addend. */
2009 ad += sec->output_section->vma - tls_biased_base (info);
2011 bfd_put_32 (output_bfd,
2012 frvfdpic_plt_section (info)->output_section->vma
2013 + frvfdpic_plt_section (info)->output_offset
2014 + frvfdpic_plt_tls_ret_offset (info),
2015 frvfdpic_got_section (info)->contents
2016 + frvfdpic_got_initial_offset (info)
2017 + entry->tlsdesc_entry);
2019 _frvfdpic_add_rofixup (output_bfd,
2020 frvfdpic_gotfixup_section (info),
2021 frvfdpic_got_section (info)
2022 ->output_section->vma
2023 + frvfdpic_got_section (info)
2025 + frvfdpic_got_initial_offset (info)
2026 + entry->tlsdesc_entry, entry);
2028 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs);
2030 /* We've used one of the reserved fixups, so discount it so
2031 that we can check at the end that we've used them
2033 frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs--;
2035 /* While at that, make sure the ret instruction makes to the
2036 right location in the PLT. We could do it only when we
2037 got to 0, but since the check at the end will only print
2038 a warning, make sure we have the ret in place in case the
2039 warning is missed. */
2040 bfd_put_32 (output_bfd, 0xc03a4000,
2041 frvfdpic_plt_section (info)->contents
2042 + frvfdpic_plt_tls_ret_offset (info));
2047 && (bfd_is_abs_section (sec)
2048 || bfd_is_und_section (sec)))
2050 idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx;
2051 ad += FRVFDPIC_TLS_BIAS;
2054 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
2055 _bfd_elf_section_offset
2057 frvfdpic_got_section (info),
2058 frvfdpic_got_initial_offset (info)
2059 + entry->tlsdesc_entry)
2060 + frvfdpic_got_section (info)
2061 ->output_section->vma
2062 + frvfdpic_got_section (info)
2064 R_FRV_TLSDESC_VALUE, idx, ad, entry);
2066 bfd_put_32 (output_bfd, 0,
2067 frvfdpic_got_section (info)->contents
2068 + frvfdpic_got_initial_offset (info)
2069 + entry->tlsdesc_entry);
2072 bfd_put_32 (output_bfd, ad,
2073 frvfdpic_got_section (info)->contents
2074 + frvfdpic_got_initial_offset (info)
2075 + entry->tlsdesc_entry + 4);
2078 /* Generate code for the get-TLS-offset PLT entry. */
2079 if (entry->tlsplt_entry != (bfd_vma) -1)
2081 bfd_byte *plt_code = frvfdpic_plt_section (info)->contents
2082 + entry->tlsplt_entry;
2084 if (info->executable
2085 && (entry->symndx != -1
2086 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
2089 bfd_vma ad = addend;
2091 /* sec may be NULL when referencing an undefweak symbol
2092 while linking a static executable. */
2095 BFD_ASSERT (entry->symndx == -1
2096 && entry->d.h->root.type == bfd_link_hash_undefweak);
2100 if (entry->symndx == -1)
2101 ad += entry->d.h->root.u.def.value;
2103 ad += sym->st_value;
2104 ad += sec->output_offset;
2105 if (sec->output_section
2106 && elf_section_data (sec->output_section))
2107 idx = elf_section_data (sec->output_section)->dynindx;
2112 /* *ABS*+addend is special for TLS relocations, use only the
2113 addend for the TLS offset, and take the module id as
2116 && (bfd_is_abs_section (sec)
2117 || bfd_is_und_section (sec)))
2119 /* For other TLS symbols that bind locally, add the section
2120 TLS offset to the addend. */
2122 ad += sec->output_section->vma - tls_biased_base (info);
2124 if ((bfd_signed_vma)ad >= -(1 << (16 - 1))
2125 && (bfd_signed_vma)ad < (1 << (16 - 1)))
2127 /* setlos lo(ad), gr9 */
2128 bfd_put_32 (output_bfd,
2131 & (((bfd_vma)1 << 16) - 1)),
2137 /* sethi.p hi(ad), gr9
2138 setlo lo(ad), gr9 */
2139 bfd_put_32 (output_bfd,
2142 & (((bfd_vma)1 << 16) - 1)),
2145 bfd_put_32 (output_bfd,
2148 & (((bfd_vma)1 << 16) - 1)),
2153 bfd_put_32 (output_bfd, 0xc03a4000, plt_code);
2155 else if (entry->tlsoff_entry)
2157 /* Figure out what kind of PLT entry we need, depending on the
2158 location of the TLS descriptor within the GOT. */
2159 if (entry->tlsoff_entry >= -(1 << (12 - 1))
2160 && entry->tlsoff_entry < (1 << (12 - 1)))
2162 /* ldi @(gr15, tlsoff_entry), gr9 */
2163 bfd_put_32 (output_bfd,
2164 0x92c8f000 | (entry->tlsoff_entry
2171 if (entry->tlsoff_entry >= -(1 << (16 - 1))
2172 && entry->tlsoff_entry < (1 << (16 - 1)))
2174 /* setlos lo(tlsoff_entry), gr8 */
2175 bfd_put_32 (output_bfd,
2177 | (entry->tlsoff_entry
2178 & (((bfd_vma)1 << 16) - 1)),
2184 /* sethi.p hi(tlsoff_entry), gr8
2185 setlo lo(tlsoff_entry), gr8 */
2186 bfd_put_32 (output_bfd,
2188 | ((entry->tlsoff_entry >> 16)
2189 & (((bfd_vma)1 << 16) - 1)),
2192 bfd_put_32 (output_bfd,
2194 | (entry->tlsoff_entry
2195 & (((bfd_vma)1 << 16) - 1)),
2199 /* ld @(gr15,gr8),gr9 */
2200 bfd_put_32 (output_bfd, 0x9008f108, plt_code);
2204 bfd_put_32 (output_bfd, 0xc03a4000, plt_code);
2208 BFD_ASSERT (entry->tlsdesc_entry);
2210 /* Figure out what kind of PLT entry we need, depending on the
2211 location of the TLS descriptor within the GOT. */
2212 if (entry->tlsdesc_entry >= -(1 << (12 - 1))
2213 && entry->tlsdesc_entry < (1 << (12 - 1)))
2215 /* lddi @(gr15, tlsdesc_entry), gr8 */
2216 bfd_put_32 (output_bfd,
2217 0x90ccf000 | (entry->tlsdesc_entry
2224 if (entry->tlsdesc_entry >= -(1 << (16 - 1))
2225 && entry->tlsdesc_entry < (1 << (16 - 1)))
2227 /* setlos lo(tlsdesc_entry), gr8 */
2228 bfd_put_32 (output_bfd,
2230 | (entry->tlsdesc_entry
2231 & (((bfd_vma)1 << 16) - 1)),
2237 /* sethi.p hi(tlsdesc_entry), gr8
2238 setlo lo(tlsdesc_entry), gr8 */
2239 bfd_put_32 (output_bfd,
2241 | ((entry->tlsdesc_entry >> 16)
2242 & (((bfd_vma)1 << 16) - 1)),
2245 bfd_put_32 (output_bfd,
2247 | (entry->tlsdesc_entry
2248 & (((bfd_vma)1 << 16) - 1)),
2252 /* ldd @(gr15,gr8),gr8 */
2253 bfd_put_32 (output_bfd, 0x9008f148, plt_code);
2256 /* jmpl @(gr8,gr0) */
2257 bfd_put_32 (output_bfd, 0x80308000, plt_code);
2264 /* Handle an FRV small data reloc. */
2266 static bfd_reloc_status_type
2267 elf32_frv_relocate_gprel12 (info, input_bfd, input_section, relocation,
2269 struct bfd_link_info *info;
2271 asection *input_section;
2272 Elf_Internal_Rela *relocation;
2278 struct bfd_link_hash_entry *h;
2280 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2282 gp = (h->u.def.value
2283 + h->u.def.section->output_section->vma
2284 + h->u.def.section->output_offset);
2286 value -= input_section->output_section->vma;
2287 value -= (gp - input_section->output_section->vma);
2289 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2291 value += relocation->r_addend;
2293 if ((long) value > 0x7ff || (long) value < -0x800)
2294 return bfd_reloc_overflow;
2296 bfd_put_32 (input_bfd,
2297 (insn & 0xfffff000) | (value & 0xfff),
2298 contents + relocation->r_offset);
2300 return bfd_reloc_ok;
2303 /* Handle an FRV small data reloc. for the u12 field. */
2305 static bfd_reloc_status_type
2306 elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, relocation,
2308 struct bfd_link_info *info;
2310 asection *input_section;
2311 Elf_Internal_Rela *relocation;
2317 struct bfd_link_hash_entry *h;
2320 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2322 gp = (h->u.def.value
2323 + h->u.def.section->output_section->vma
2324 + h->u.def.section->output_offset);
2326 value -= input_section->output_section->vma;
2327 value -= (gp - input_section->output_section->vma);
2329 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2331 value += relocation->r_addend;
2333 if ((long) value > 0x7ff || (long) value < -0x800)
2334 return bfd_reloc_overflow;
2336 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
2338 insn = (insn & ~mask) | ((value & 0xfc0) << 12) | (value & 0x3f);
2340 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
2342 return bfd_reloc_ok;
2345 /* Handle an FRV ELF HI16 reloc. */
2347 static bfd_reloc_status_type
2348 elf32_frv_relocate_hi16 (input_bfd, relhi, contents, value)
2350 Elf_Internal_Rela *relhi;
2356 insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
2358 value += relhi->r_addend;
2359 value = ((value >> 16) & 0xffff);
2361 insn = (insn & 0xffff0000) | value;
2363 if ((long) value > 0xffff || (long) value < -0x10000)
2364 return bfd_reloc_overflow;
2366 bfd_put_32 (input_bfd, insn, contents + relhi->r_offset);
2367 return bfd_reloc_ok;
2370 static bfd_reloc_status_type
2371 elf32_frv_relocate_lo16 (input_bfd, rello, contents, value)
2373 Elf_Internal_Rela *rello;
2379 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
2381 value += rello->r_addend;
2382 value = value & 0xffff;
2384 insn = (insn & 0xffff0000) | value;
2386 if ((long) value > 0xffff || (long) value < -0x10000)
2387 return bfd_reloc_overflow;
2389 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
2390 return bfd_reloc_ok;
2393 /* Perform the relocation for the CALL label24 instruction. */
2395 static bfd_reloc_status_type
2396 elf32_frv_relocate_label24 (input_bfd, input_section, rello, contents, value)
2398 asection *input_section;
2399 Elf_Internal_Rela *rello;
2407 /* The format for the call instruction is:
2409 0 000000 0001111 000000000000000000
2410 label6 opcode label18
2412 The branch calculation is: pc + (4*label24)
2413 where label24 is the concatenation of label6 and label18. */
2415 /* Grab the instruction. */
2416 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
2418 value -= input_section->output_section->vma + input_section->output_offset;
2419 value -= rello->r_offset;
2420 value += rello->r_addend;
2424 label6 = value & 0xfc0000;
2425 label6 = label6 << 7;
2427 label18 = value & 0x3ffff;
2429 insn = insn & 0x803c0000;
2430 insn = insn | label6;
2431 insn = insn | label18;
2433 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
2435 return bfd_reloc_ok;
2438 static bfd_reloc_status_type
2439 elf32_frv_relocate_gprelhi (info, input_bfd, input_section, relocation,
2441 struct bfd_link_info *info;
2443 asection *input_section;
2444 Elf_Internal_Rela *relocation;
2450 struct bfd_link_hash_entry *h;
2452 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2454 gp = (h->u.def.value
2455 + h->u.def.section->output_section->vma
2456 + h->u.def.section->output_offset);
2458 value -= input_section->output_section->vma;
2459 value -= (gp - input_section->output_section->vma);
2460 value += relocation->r_addend;
2461 value = ((value >> 16) & 0xffff);
2463 if ((long) value > 0xffff || (long) value < -0x10000)
2464 return bfd_reloc_overflow;
2466 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2467 insn = (insn & 0xffff0000) | value;
2469 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
2470 return bfd_reloc_ok;
2473 static bfd_reloc_status_type
2474 elf32_frv_relocate_gprello (info, input_bfd, input_section, relocation,
2476 struct bfd_link_info *info;
2478 asection *input_section;
2479 Elf_Internal_Rela *relocation;
2485 struct bfd_link_hash_entry *h;
2487 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2489 gp = (h->u.def.value
2490 + h->u.def.section->output_section->vma
2491 + h->u.def.section->output_offset);
2493 value -= input_section->output_section->vma;
2494 value -= (gp - input_section->output_section->vma);
2495 value += relocation->r_addend;
2496 value = value & 0xffff;
2498 if ((long) value > 0xffff || (long) value < -0x10000)
2499 return bfd_reloc_overflow;
2501 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2502 insn = (insn & 0xffff0000) | value;
2504 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
2506 return bfd_reloc_ok;
2509 static reloc_howto_type *
2510 frv_reloc_type_lookup (abfd, code)
2511 bfd *abfd ATTRIBUTE_UNUSED;
2512 bfd_reloc_code_real_type code;
2519 case BFD_RELOC_NONE:
2520 return &elf32_frv_howto_table[ (int) R_FRV_NONE];
2523 if (elf_elfheader (abfd)->e_type == ET_EXEC
2524 || elf_elfheader (abfd)->e_type == ET_DYN)
2525 return &elf32_frv_rel_32_howto;
2527 case BFD_RELOC_CTOR:
2528 return &elf32_frv_howto_table[ (int) R_FRV_32];
2530 case BFD_RELOC_FRV_LABEL16:
2531 return &elf32_frv_howto_table[ (int) R_FRV_LABEL16];
2533 case BFD_RELOC_FRV_LABEL24:
2534 return &elf32_frv_howto_table[ (int) R_FRV_LABEL24];
2536 case BFD_RELOC_FRV_LO16:
2537 return &elf32_frv_howto_table[ (int) R_FRV_LO16];
2539 case BFD_RELOC_FRV_HI16:
2540 return &elf32_frv_howto_table[ (int) R_FRV_HI16];
2542 case BFD_RELOC_FRV_GPREL12:
2543 return &elf32_frv_howto_table[ (int) R_FRV_GPREL12];
2545 case BFD_RELOC_FRV_GPRELU12:
2546 return &elf32_frv_howto_table[ (int) R_FRV_GPRELU12];
2548 case BFD_RELOC_FRV_GPREL32:
2549 return &elf32_frv_howto_table[ (int) R_FRV_GPREL32];
2551 case BFD_RELOC_FRV_GPRELHI:
2552 return &elf32_frv_howto_table[ (int) R_FRV_GPRELHI];
2554 case BFD_RELOC_FRV_GPRELLO:
2555 return &elf32_frv_howto_table[ (int) R_FRV_GPRELLO];
2557 case BFD_RELOC_FRV_GOT12:
2558 return &elf32_frv_howto_table[ (int) R_FRV_GOT12];
2560 case BFD_RELOC_FRV_GOTHI:
2561 return &elf32_frv_howto_table[ (int) R_FRV_GOTHI];
2563 case BFD_RELOC_FRV_GOTLO:
2564 return &elf32_frv_howto_table[ (int) R_FRV_GOTLO];
2566 case BFD_RELOC_FRV_FUNCDESC:
2567 if (elf_elfheader (abfd)->e_type == ET_EXEC
2568 || elf_elfheader (abfd)->e_type == ET_DYN)
2569 return &elf32_frv_rel_funcdesc_howto;
2570 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC];
2572 case BFD_RELOC_FRV_FUNCDESC_GOT12:
2573 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOT12];
2575 case BFD_RELOC_FRV_FUNCDESC_GOTHI:
2576 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTHI];
2578 case BFD_RELOC_FRV_FUNCDESC_GOTLO:
2579 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTLO];
2581 case BFD_RELOC_FRV_FUNCDESC_VALUE:
2582 if (elf_elfheader (abfd)->e_type == ET_EXEC
2583 || elf_elfheader (abfd)->e_type == ET_DYN)
2584 return &elf32_frv_rel_funcdesc_value_howto;
2585 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_VALUE];
2587 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12:
2588 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFF12];
2590 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI:
2591 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFHI];
2593 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO:
2594 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFLO];
2596 case BFD_RELOC_FRV_GOTOFF12:
2597 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFF12];
2599 case BFD_RELOC_FRV_GOTOFFHI:
2600 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFHI];
2602 case BFD_RELOC_FRV_GOTOFFLO:
2603 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFLO];
2605 case BFD_RELOC_FRV_GETTLSOFF:
2606 return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF];
2608 case BFD_RELOC_FRV_TLSDESC_VALUE:
2609 if (elf_elfheader (abfd)->e_type == ET_EXEC
2610 || elf_elfheader (abfd)->e_type == ET_DYN)
2611 return &elf32_frv_rel_tlsdesc_value_howto;
2612 return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_VALUE];
2614 case BFD_RELOC_FRV_GOTTLSDESC12:
2615 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESC12];
2617 case BFD_RELOC_FRV_GOTTLSDESCHI:
2618 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCHI];
2620 case BFD_RELOC_FRV_GOTTLSDESCLO:
2621 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCLO];
2623 case BFD_RELOC_FRV_TLSMOFF12:
2624 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF12];
2626 case BFD_RELOC_FRV_TLSMOFFHI:
2627 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFHI];
2629 case BFD_RELOC_FRV_TLSMOFFLO:
2630 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFLO];
2632 case BFD_RELOC_FRV_GOTTLSOFF12:
2633 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFF12];
2635 case BFD_RELOC_FRV_GOTTLSOFFHI:
2636 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFHI];
2638 case BFD_RELOC_FRV_GOTTLSOFFLO:
2639 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFLO];
2641 case BFD_RELOC_FRV_TLSOFF:
2642 if (elf_elfheader (abfd)->e_type == ET_EXEC
2643 || elf_elfheader (abfd)->e_type == ET_DYN)
2644 return &elf32_frv_rel_tlsoff_howto;
2645 return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF];
2647 case BFD_RELOC_FRV_TLSDESC_RELAX:
2648 return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_RELAX];
2650 case BFD_RELOC_FRV_GETTLSOFF_RELAX:
2651 return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF_RELAX];
2653 case BFD_RELOC_FRV_TLSOFF_RELAX:
2654 return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF_RELAX];
2656 case BFD_RELOC_FRV_TLSMOFF:
2657 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF];
2659 case BFD_RELOC_VTABLE_INHERIT:
2660 return &elf32_frv_vtinherit_howto;
2662 case BFD_RELOC_VTABLE_ENTRY:
2663 return &elf32_frv_vtentry_howto;
2669 /* Set the howto pointer for an FRV ELF reloc. */
2672 frv_info_to_howto_rela (abfd, cache_ptr, dst)
2673 bfd *abfd ATTRIBUTE_UNUSED;
2675 Elf_Internal_Rela *dst;
2677 unsigned int r_type;
2679 r_type = ELF32_R_TYPE (dst->r_info);
2682 case R_FRV_GNU_VTINHERIT:
2683 cache_ptr->howto = &elf32_frv_vtinherit_howto;
2686 case R_FRV_GNU_VTENTRY:
2687 cache_ptr->howto = &elf32_frv_vtentry_howto;
2691 cache_ptr->howto = & elf32_frv_howto_table [r_type];
2696 /* Set the howto pointer for an FRV ELF REL reloc. */
2698 frvfdpic_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
2699 arelent *cache_ptr, Elf_Internal_Rela *dst)
2701 unsigned int r_type;
2703 r_type = ELF32_R_TYPE (dst->r_info);
2707 cache_ptr->howto = &elf32_frv_rel_32_howto;
2710 case R_FRV_FUNCDESC:
2711 cache_ptr->howto = &elf32_frv_rel_funcdesc_howto;
2714 case R_FRV_FUNCDESC_VALUE:
2715 cache_ptr->howto = &elf32_frv_rel_funcdesc_value_howto;
2718 case R_FRV_TLSDESC_VALUE:
2719 cache_ptr->howto = &elf32_frv_rel_tlsdesc_value_howto;
2723 cache_ptr->howto = &elf32_frv_rel_tlsoff_howto;
2727 cache_ptr->howto = NULL;
2732 /* Perform a single relocation. By default we use the standard BFD
2733 routines, but a few relocs, we have to do them ourselves. */
2735 static bfd_reloc_status_type
2736 frv_final_link_relocate (howto, input_bfd, input_section, contents, rel,
2738 reloc_howto_type *howto;
2740 asection *input_section;
2742 Elf_Internal_Rela *rel;
2745 return _bfd_final_link_relocate (howto, input_bfd, input_section,
2746 contents, rel->r_offset, relocation,
2751 /* Relocate an FRV ELF section.
2753 The RELOCATE_SECTION function is called by the new ELF backend linker
2754 to handle the relocations for a section.
2756 The relocs are always passed as Rela structures; if the section
2757 actually uses Rel structures, the r_addend field will always be
2760 This function is responsible for adjusting the section contents as
2761 necessary, and (if using Rela relocs and generating a relocatable
2762 output file) adjusting the reloc addend as necessary.
2764 This function does not have to worry about setting the reloc
2765 address or the reloc symbol index.
2767 LOCAL_SYMS is a pointer to the swapped in local symbols.
2769 LOCAL_SECTIONS is an array giving the section in the input file
2770 corresponding to the st_shndx field of each local symbol.
2772 The global hash table entry for the global symbols can be found
2773 via elf_sym_hashes (input_bfd).
2775 When generating relocatable output, this function must handle
2776 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2777 going to be the section symbol corresponding to the output
2778 section, which means that the addend must be adjusted
2782 elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
2783 contents, relocs, local_syms, local_sections)
2784 bfd *output_bfd ATTRIBUTE_UNUSED;
2785 struct bfd_link_info *info;
2787 asection *input_section;
2789 Elf_Internal_Rela *relocs;
2790 Elf_Internal_Sym *local_syms;
2791 asection **local_sections;
2793 Elf_Internal_Shdr *symtab_hdr;
2794 struct elf_link_hash_entry **sym_hashes;
2795 Elf_Internal_Rela *rel;
2796 Elf_Internal_Rela *relend;
2797 unsigned isec_segment, got_segment, plt_segment, gprel_segment, tls_segment,
2799 int silence_segment_error = !(info->shared || info->pie);
2802 if (info->relocatable)
2805 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
2806 sym_hashes = elf_sym_hashes (input_bfd);
2807 relend = relocs + input_section->reloc_count;
2809 isec_segment = _frvfdpic_osec_to_segment (output_bfd,
2810 input_section->output_section);
2811 if (IS_FDPIC (output_bfd) && frvfdpic_got_section (info))
2812 got_segment = _frvfdpic_osec_to_segment (output_bfd,
2813 frvfdpic_got_section (info)
2817 if (IS_FDPIC (output_bfd) && frvfdpic_gotfixup_section (info))
2818 gprel_segment = _frvfdpic_osec_to_segment (output_bfd,
2819 frvfdpic_gotfixup_section (info)
2823 if (IS_FDPIC (output_bfd) && frvfdpic_plt_section (info))
2824 plt_segment = _frvfdpic_osec_to_segment (output_bfd,
2825 frvfdpic_plt_section (info)
2829 if (elf_hash_table (info)->tls_sec)
2830 tls_segment = _frvfdpic_osec_to_segment (output_bfd,
2831 elf_hash_table (info)->tls_sec);
2835 for (rel = relocs; rel < relend; rel ++)
2837 reloc_howto_type *howto;
2838 unsigned long r_symndx;
2839 Elf_Internal_Sym *sym;
2841 struct elf_link_hash_entry *h;
2843 bfd_reloc_status_type r;
2844 const char * name = NULL;
2847 struct frvfdpic_relocs_info *picrel;
2848 bfd_vma orig_addend = rel->r_addend;
2850 r_type = ELF32_R_TYPE (rel->r_info);
2852 if ( r_type == R_FRV_GNU_VTINHERIT
2853 || r_type == R_FRV_GNU_VTENTRY)
2856 /* This is a final link. */
2857 r_symndx = ELF32_R_SYM (rel->r_info);
2858 howto = elf32_frv_howto_table + ELF32_R_TYPE (rel->r_info);
2863 if (r_symndx < symtab_hdr->sh_info)
2865 sym = local_syms + r_symndx;
2866 osec = sec = local_sections [r_symndx];
2867 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
2869 name = bfd_elf_string_from_elf_section
2870 (input_bfd, symtab_hdr->sh_link, sym->st_name);
2871 name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
2875 h = sym_hashes [r_symndx - symtab_hdr->sh_info];
2877 while (h->root.type == bfd_link_hash_indirect
2878 || h->root.type == bfd_link_hash_warning)
2879 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2881 name = h->root.root.string;
2883 if ((h->root.type == bfd_link_hash_defined
2884 || h->root.type == bfd_link_hash_defweak))
2886 if (/* TLSMOFF forces local binding. */
2887 r_type != R_FRV_TLSMOFF
2888 && ! FRVFDPIC_SYM_LOCAL (info, h))
2895 sec = h->root.u.def.section;
2896 relocation = (h->root.u.def.value
2897 + sec->output_section->vma
2898 + sec->output_offset);
2901 else if (h->root.type == bfd_link_hash_undefweak)
2905 else if (info->unresolved_syms_in_objects == RM_IGNORE
2906 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
2910 if (! ((*info->callbacks->undefined_symbol)
2911 (info, h->root.root.string, input_bfd,
2912 input_section, rel->r_offset,
2913 (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
2914 || ELF_ST_VISIBILITY (h->other)))))
2925 if (! IS_FDPIC (output_bfd))
2931 case R_FRV_FUNCDESC_GOT12:
2932 case R_FRV_FUNCDESC_GOTHI:
2933 case R_FRV_FUNCDESC_GOTLO:
2934 case R_FRV_GOTOFF12:
2935 case R_FRV_GOTOFFHI:
2936 case R_FRV_GOTOFFLO:
2937 case R_FRV_FUNCDESC_GOTOFF12:
2938 case R_FRV_FUNCDESC_GOTOFFHI:
2939 case R_FRV_FUNCDESC_GOTOFFLO:
2940 case R_FRV_FUNCDESC:
2941 case R_FRV_FUNCDESC_VALUE:
2942 case R_FRV_GETTLSOFF:
2943 case R_FRV_TLSDESC_VALUE:
2944 case R_FRV_GOTTLSDESC12:
2945 case R_FRV_GOTTLSDESCHI:
2946 case R_FRV_GOTTLSDESCLO:
2947 case R_FRV_TLSMOFF12:
2948 case R_FRV_TLSMOFFHI:
2949 case R_FRV_TLSMOFFLO:
2950 case R_FRV_GOTTLSOFF12:
2951 case R_FRV_GOTTLSOFFHI:
2952 case R_FRV_GOTTLSOFFLO:
2954 case R_FRV_TLSDESC_RELAX:
2955 case R_FRV_GETTLSOFF_RELAX:
2956 case R_FRV_TLSOFF_RELAX:
2959 picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info
2960 (info), input_bfd, h,
2961 orig_addend, INSERT);
2963 /* In order to find the entry we created before, we must
2964 use the original addend, not the one that may have been
2965 modified by _bfd_elf_rela_local_sym(). */
2966 picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
2967 (info), input_bfd, r_symndx,
2968 orig_addend, INSERT);
2972 if (!_frvfdpic_emit_got_relocs_plt_entries (picrel, output_bfd, info,
2976 (*_bfd_error_handler)
2977 (_("%B: relocation at `%A+0x%x' references symbol `%s' with nonzero addend"),
2978 input_bfd, input_section, rel->r_offset, name);
2988 if (h && ! FRVFDPIC_SYM_LOCAL (info, h))
2990 info->callbacks->warning
2991 (info, _("relocation references symbol not defined in the module"),
2992 name, input_bfd, input_section, rel->r_offset);
3000 case R_FRV_GETTLSOFF:
3001 case R_FRV_TLSDESC_VALUE:
3002 case R_FRV_GOTTLSDESC12:
3003 case R_FRV_GOTTLSDESCHI:
3004 case R_FRV_GOTTLSDESCLO:
3005 case R_FRV_TLSMOFF12:
3006 case R_FRV_TLSMOFFHI:
3007 case R_FRV_TLSMOFFLO:
3008 case R_FRV_GOTTLSOFF12:
3009 case R_FRV_GOTTLSOFFHI:
3010 case R_FRV_GOTTLSOFFLO:
3012 case R_FRV_TLSDESC_RELAX:
3013 case R_FRV_GETTLSOFF_RELAX:
3014 case R_FRV_TLSOFF_RELAX:
3016 if (sec && (bfd_is_abs_section (sec) || bfd_is_und_section (sec)))
3017 relocation += tls_biased_base (info);
3024 /* Try to apply TLS relaxations. */
3029 #define LOCAL_EXEC_P(info, picrel) \
3030 ((info)->executable \
3031 && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h)))
3032 #define INITIAL_EXEC_P(info, picrel) \
3033 (((info)->executable || (info)->flags & DF_STATIC_TLS) \
3034 && (picrel)->tlsoff_entry)
3036 #define IN_RANGE_FOR_OFST12_P(value) \
3037 ((bfd_vma)((value) + 2048) < (bfd_vma)4096)
3038 #define IN_RANGE_FOR_SETLOS_P(value) \
3039 ((bfd_vma)((value) + 32768) < (bfd_vma)65536)
3040 #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \
3041 (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info)))
3043 #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
3044 (LOCAL_EXEC_P ((info), (picrel)) \
3045 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
3046 #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \
3047 (INITIAL_EXEC_P ((info), (picrel)) \
3048 && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry))
3050 #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \
3051 (LOCAL_EXEC_P ((info), (picrel)))
3052 #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \
3053 (INITIAL_EXEC_P ((info), (picrel)))
3055 #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
3056 (LOCAL_EXEC_P ((info), (picrel)) \
3057 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
3059 case R_FRV_GETTLSOFF:
3060 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3062 /* Is this a call instruction? */
3063 if ((insn & (unsigned long)0x01fc0000) != 0x003c0000)
3065 r = info->callbacks->warning
3067 _("R_FRV_GETTLSOFF not applied to a call instruction"),
3068 name, input_bfd, input_section, rel->r_offset);
3072 if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info, picrel,
3073 relocation + rel->r_addend))
3075 /* Replace the call instruction (except the packing bit)
3076 with setlos #tlsmofflo(symbol+offset), gr9. */
3077 insn &= (unsigned long)0x80000000;
3078 insn |= (unsigned long)0x12fc0000;
3079 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3081 r_type = R_FRV_TLSMOFFLO;
3082 howto = elf32_frv_howto_table + r_type;
3083 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3086 else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info, picrel))
3088 /* Replace the call instruction (except the packing bit)
3089 with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */
3090 insn &= (unsigned long)0x80000000;
3091 insn |= (unsigned long)0x12c8f000;
3092 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3094 r_type = R_FRV_GOTTLSOFF12;
3095 howto = elf32_frv_howto_table + r_type;
3096 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3101 case R_FRV_GOTTLSDESC12:
3102 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3104 /* Is this an lddi instruction? */
3105 if ((insn & (unsigned long)0x01fc0000) != 0x00cc0000)
3107 r = info->callbacks->warning
3109 _("R_FRV_GOTTLSDESC12 not applied to an lddi instruction"),
3110 name, input_bfd, input_section, rel->r_offset);
3114 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3115 relocation + rel->r_addend)
3116 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3119 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3120 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3121 Preserve the packing bit. */
3122 insn = (insn & (unsigned long)0x80000000)
3123 | ((insn + (unsigned long)0x02000000)
3124 & (unsigned long)0x7e000000);
3125 insn |= (unsigned long)0x00fc0000;
3126 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3128 r_type = R_FRV_TLSMOFFLO;
3129 howto = elf32_frv_howto_table + r_type;
3130 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3133 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3134 relocation + rel->r_addend))
3136 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3137 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3138 Preserve the packing bit. */
3139 insn = (insn & (unsigned long)0x80000000)
3140 | ((insn + (unsigned long)0x02000000)
3141 & (unsigned long)0x7e000000);
3142 insn |= (unsigned long)0x00f80000;
3143 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3145 r_type = R_FRV_TLSMOFFHI;
3146 howto = elf32_frv_howto_table + r_type;
3147 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3150 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3152 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3153 with ldi @(grB, #gottlsoff12(symbol+offset),
3154 gr<C+1>. Preserve the packing bit. If gottlsoff12
3155 overflows, we'll error out, but that's sort-of ok,
3156 since we'd started with gottlsdesc12, that's actually
3157 more demanding. Compiling with -fPIE instead of
3158 -fpie would fix it; linking with --relax should fix
3160 insn = (insn & (unsigned long)0x80cbf000)
3161 | ((insn + (unsigned long)0x02000000)
3162 & (unsigned long)0x7e000000);
3163 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3165 r_type = R_FRV_GOTTLSOFF12;
3166 howto = elf32_frv_howto_table + r_type;
3167 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3172 case R_FRV_GOTTLSDESCHI:
3173 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3175 /* Is this a sethi instruction? */
3176 if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
3178 r = info->callbacks->warning
3180 _("R_FRV_GOTTLSDESCHI not applied to a sethi instruction"),
3181 name, input_bfd, input_section, rel->r_offset);
3185 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3186 relocation + rel->r_addend)
3187 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3188 && IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry)))
3190 /* Replace sethi with a nop. Preserve the packing bit. */
3191 insn &= (unsigned long)0x80000000;
3192 insn |= (unsigned long)0x00880000;
3193 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3195 /* Nothing to relocate. */
3199 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3201 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3202 r_type = R_FRV_GOTTLSOFFHI;
3203 howto = elf32_frv_howto_table + r_type;
3204 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3209 case R_FRV_GOTTLSDESCLO:
3210 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3212 /* Is this a setlo or setlos instruction? */
3213 if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
3215 r = info->callbacks->warning
3217 _("R_FRV_GOTTLSDESCLO"
3218 " not applied to a setlo or setlos instruction"),
3219 name, input_bfd, input_section, rel->r_offset);
3223 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3224 relocation + rel->r_addend)
3225 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3226 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
3228 /* Replace setlo/setlos with a nop. Preserve the
3230 insn &= (unsigned long)0x80000000;
3231 insn |= (unsigned long)0x00880000;
3232 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3234 /* Nothing to relocate. */
3238 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3240 /* If the corresponding sethi (if it exists) decayed
3241 to a nop, make sure this becomes (or already is) a
3242 setlos, not setlo. */
3243 if (IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry))
3245 insn |= (unsigned long)0x00080000;
3246 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3249 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3250 r_type = R_FRV_GOTTLSOFFLO;
3251 howto = elf32_frv_howto_table + r_type;
3252 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3257 case R_FRV_TLSDESC_RELAX:
3258 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3260 /* Is this an ldd instruction? */
3261 if ((insn & (unsigned long)0x01fc0fc0) != 0x00080140)
3263 r = info->callbacks->warning
3265 _("R_FRV_TLSDESC_RELAX not applied to an ldd instruction"),
3266 name, input_bfd, input_section, rel->r_offset);
3270 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3271 relocation + rel->r_addend)
3272 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3275 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3276 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3277 Preserve the packing bit. */
3278 insn = (insn & (unsigned long)0x80000000)
3279 | ((insn + (unsigned long)0x02000000)
3280 & (unsigned long)0x7e000000);
3281 insn |= (unsigned long)0x00fc0000;
3282 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3284 r_type = R_FRV_TLSMOFFLO;
3285 howto = elf32_frv_howto_table + r_type;
3286 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3289 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3290 relocation + rel->r_addend))
3292 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3293 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3294 Preserve the packing bit. */
3295 insn = (insn & (unsigned long)0x80000000)
3296 | ((insn + (unsigned long)0x02000000)
3297 & (unsigned long)0x7e000000);
3298 insn |= (unsigned long)0x00f80000;
3299 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3301 r_type = R_FRV_TLSMOFFHI;
3302 howto = elf32_frv_howto_table + r_type;
3303 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3306 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3307 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))
3309 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3310 with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>.
3311 Preserve the packing bit. */
3312 insn = (insn & (unsigned long)0x8003f000)
3313 | (unsigned long)0x00c80000
3314 | ((insn + (unsigned long)0x02000000)
3315 & (unsigned long)0x7e000000);
3316 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3318 r_type = R_FRV_GOTTLSOFF12;
3319 howto = elf32_frv_howto_table + r_type;
3320 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3323 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3325 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3326 with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>.
3327 Preserve the packing bit. */
3328 insn = (insn & (unsigned long)0x81ffffbf)
3329 | ((insn + (unsigned long)0x02000000)
3330 & (unsigned long)0x7e000000);
3331 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3333 /* #tlsoff(symbol+offset) is just a relaxation
3334 annotation, so there's nothing left to
3341 case R_FRV_GETTLSOFF_RELAX:
3342 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3344 /* Is this a calll or callil instruction? */
3345 if ((insn & (unsigned long)0x7ff80fc0) != 0x02300000)
3347 r = info->callbacks->warning
3349 _("R_FRV_GETTLSOFF_RELAX"
3350 " not applied to a calll instruction"),
3351 name, input_bfd, input_section, rel->r_offset);
3355 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3356 relocation + rel->r_addend)
3357 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3360 /* Replace calll with a nop. Preserve the packing bit. */
3361 insn &= (unsigned long)0x80000000;
3362 insn |= (unsigned long)0x00880000;
3363 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3365 /* Nothing to relocate. */
3369 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3370 relocation + rel->r_addend))
3372 /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9.
3373 Preserve the packing bit. */
3374 insn &= (unsigned long)0x80000000;
3375 insn |= (unsigned long)0x12f40000;
3376 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3378 r_type = R_FRV_TLSMOFFLO;
3379 howto = elf32_frv_howto_table + r_type;
3380 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3383 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3385 /* Replace calll with a nop. Preserve the packing bit. */
3386 insn &= (unsigned long)0x80000000;
3387 insn |= (unsigned long)0x00880000;
3388 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3390 /* Nothing to relocate. */
3396 case R_FRV_GOTTLSOFF12:
3397 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3399 /* Is this an ldi instruction? */
3400 if ((insn & (unsigned long)0x01fc0000) != 0x00c80000)
3402 r = info->callbacks->warning
3404 _("R_FRV_GOTTLSOFF12 not applied to an ldi instruction"),
3405 name, input_bfd, input_section, rel->r_offset);
3409 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3410 relocation + rel->r_addend))
3412 /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC
3413 with setlos #tlsmofflo(symbol+offset), grC.
3414 Preserve the packing bit. */
3415 insn &= (unsigned long)0xfe000000;
3416 insn |= (unsigned long)0x00fc0000;
3417 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3419 r_type = R_FRV_TLSMOFFLO;
3420 howto = elf32_frv_howto_table + r_type;
3421 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3426 case R_FRV_GOTTLSOFFHI:
3427 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3429 /* Is this a sethi instruction? */
3430 if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
3432 r = info->callbacks->warning
3434 _("R_FRV_GOTTLSOFFHI not applied to a sethi instruction"),
3435 name, input_bfd, input_section, rel->r_offset);
3439 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3440 relocation + rel->r_addend)
3441 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3442 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
3444 /* Replace sethi with a nop. Preserve the packing bit. */
3445 insn &= (unsigned long)0x80000000;
3446 insn |= (unsigned long)0x00880000;
3447 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3449 /* Nothing to relocate. */
3455 case R_FRV_GOTTLSOFFLO:
3456 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3458 /* Is this a setlo or setlos instruction? */
3459 if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
3461 r = info->callbacks->warning
3463 _("R_FRV_GOTTLSOFFLO"
3464 " not applied to a setlo or setlos instruction"),
3465 name, input_bfd, input_section, rel->r_offset);
3469 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3470 relocation + rel->r_addend)
3471 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3472 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
3474 /* Replace setlo/setlos with a nop. Preserve the
3476 insn &= (unsigned long)0x80000000;
3477 insn |= (unsigned long)0x00880000;
3478 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3480 /* Nothing to relocate. */
3486 case R_FRV_TLSOFF_RELAX:
3487 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3489 /* Is this an ld instruction? */
3490 if ((insn & (unsigned long)0x01fc0fc0) != 0x00080100)
3492 r = info->callbacks->warning
3494 _("R_FRV_TLSOFF_RELAX not applied to an ld instruction"),
3495 name, input_bfd, input_section, rel->r_offset);
3499 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3500 relocation + rel->r_addend))
3502 /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC
3503 with setlos #tlsmofflo(symbol+offset), grC.
3504 Preserve the packing bit. */
3505 insn &= (unsigned long)0xfe000000;
3506 insn |= (unsigned long)0x00fc0000;
3507 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3509 r_type = R_FRV_TLSMOFFLO;
3510 howto = elf32_frv_howto_table + r_type;
3511 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3514 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3515 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))
3517 /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC
3518 with ldi @(grB, #gottlsoff12(symbol+offset), grC.
3519 Preserve the packing bit. */
3520 insn = (insn & (unsigned long)0xfe03f000)
3521 | (unsigned long)0x00c80000;;
3522 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3524 r_type = R_FRV_GOTTLSOFF12;
3525 howto = elf32_frv_howto_table + r_type;
3526 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3531 case R_FRV_TLSMOFFHI:
3532 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3534 /* Is this a sethi instruction? */
3535 if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
3537 r = info->callbacks->warning
3539 _("R_FRV_TLSMOFFHI not applied to a sethi instruction"),
3540 name, input_bfd, input_section, rel->r_offset);
3544 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3547 /* Replace sethi with a nop. Preserve the packing bit. */
3548 insn &= (unsigned long)0x80000000;
3549 insn |= (unsigned long)0x00880000;
3550 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3552 /* Nothing to relocate. */
3558 case R_FRV_TLSMOFFLO:
3559 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3561 /* Is this a setlo or setlos instruction? */
3562 if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
3564 r = info->callbacks->warning
3567 " not applied to a setlo or setlos instruction"),
3568 name, input_bfd, input_section, rel->r_offset);
3572 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3574 /* If the corresponding sethi (if it exists) decayed
3575 to a nop, make sure this becomes (or already is) a
3576 setlos, not setlo. */
3578 insn |= (unsigned long)0x00080000;
3579 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3584 #if 0 /* There's nothing to relax in these. */
3585 case R_FRV_TLSDESC_VALUE:
3587 case R_FRV_TLSMOFF12:
3588 case R_FRV_TLSMOFFHI:
3589 case R_FRV_TLSMOFFLO:
3599 check_segment[0] = isec_segment;
3600 if (! IS_FDPIC (output_bfd))
3601 check_segment[1] = isec_segment;
3602 else if (picrel->plt)
3604 relocation = frvfdpic_plt_section (info)->output_section->vma
3605 + frvfdpic_plt_section (info)->output_offset
3606 + picrel->plt_entry;
3607 check_segment[1] = plt_segment;
3609 /* We don't want to warn on calls to undefined weak symbols,
3610 as calls to them must be protected by non-NULL tests
3611 anyway, and unprotected calls would invoke undefined
3613 else if (picrel->symndx == -1
3614 && picrel->d.h->root.type == bfd_link_hash_undefweak)
3615 check_segment[1] = check_segment[0];
3617 check_segment[1] = sec
3618 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3625 relocation = picrel->got_entry;
3626 check_segment[0] = check_segment[1] = got_segment;
3629 case R_FRV_FUNCDESC_GOT12:
3630 case R_FRV_FUNCDESC_GOTHI:
3631 case R_FRV_FUNCDESC_GOTLO:
3632 relocation = picrel->fdgot_entry;
3633 check_segment[0] = check_segment[1] = got_segment;
3636 case R_FRV_GOTOFFHI:
3637 case R_FRV_GOTOFF12:
3638 case R_FRV_GOTOFFLO:
3639 relocation -= frvfdpic_got_section (info)->output_section->vma
3640 + frvfdpic_got_section (info)->output_offset
3641 + frvfdpic_got_initial_offset (info);
3642 check_segment[0] = got_segment;
3643 check_segment[1] = sec
3644 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3648 case R_FRV_FUNCDESC_GOTOFF12:
3649 case R_FRV_FUNCDESC_GOTOFFHI:
3650 case R_FRV_FUNCDESC_GOTOFFLO:
3651 relocation = picrel->fd_entry;
3652 check_segment[0] = check_segment[1] = got_segment;
3655 case R_FRV_FUNCDESC:
3658 bfd_vma addend = rel->r_addend;
3660 if (! (h && h->root.type == bfd_link_hash_undefweak
3661 && FRVFDPIC_SYM_LOCAL (info, h)))
3663 /* If the symbol is dynamic and there may be dynamic
3664 symbol resolution because we are or are linked with a
3665 shared library, emit a FUNCDESC relocation such that
3666 the dynamic linker will allocate the function
3667 descriptor. If the symbol needs a non-local function
3668 descriptor but binds locally (e.g., its visibility is
3669 protected, emit a dynamic relocation decayed to
3671 if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h)
3672 && FRVFDPIC_SYM_LOCAL (info, h)
3673 && !(info->executable && !info->pie))
3675 dynindx = elf_section_data (h->root.u.def.section
3676 ->output_section)->dynindx;
3677 addend += h->root.u.def.section->output_offset
3678 + h->root.u.def.value;
3680 else if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h))
3684 info->callbacks->warning
3685 (info, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"),
3686 name, input_bfd, input_section, rel->r_offset);
3689 dynindx = h->dynindx;
3693 /* Otherwise, we know we have a private function
3694 descriptor, so reference it directly. */
3695 BFD_ASSERT (picrel->privfd);
3697 dynindx = elf_section_data (frvfdpic_got_section (info)
3698 ->output_section)->dynindx;
3699 addend = frvfdpic_got_section (info)->output_offset
3700 + frvfdpic_got_initial_offset (info)
3704 /* If there is room for dynamic symbol resolution, emit
3705 the dynamic relocation. However, if we're linking an
3706 executable at a fixed location, we won't have emitted a
3707 dynamic symbol entry for the got section, so idx will
3708 be zero, which means we can and should compute the
3709 address of the private descriptor ourselves. */
3710 if (info->executable && !info->pie
3711 && (!h || FRVFDPIC_FUNCDESC_LOCAL (info, h)))
3713 addend += frvfdpic_got_section (info)->output_section->vma;
3714 if ((bfd_get_section_flags (output_bfd,
3715 input_section->output_section)
3716 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
3718 if (_frvfdpic_osec_readonly_p (output_bfd,
3722 info->callbacks->warning
3724 _("cannot emit fixups in read-only section"),
3725 name, input_bfd, input_section, rel->r_offset);
3728 _frvfdpic_add_rofixup (output_bfd,
3729 frvfdpic_gotfixup_section
3731 _bfd_elf_section_offset
3733 input_section, rel->r_offset)
3735 ->output_section->vma
3736 + input_section->output_offset,
3740 else if ((bfd_get_section_flags (output_bfd,
3741 input_section->output_section)
3742 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
3744 if (_frvfdpic_osec_readonly_p (output_bfd,
3748 info->callbacks->warning
3750 _("cannot emit dynamic relocations in read-only section"),
3751 name, input_bfd, input_section, rel->r_offset);
3754 _frvfdpic_add_dyn_reloc (output_bfd,
3755 frvfdpic_gotrel_section (info),
3756 _bfd_elf_section_offset
3758 input_section, rel->r_offset)
3760 ->output_section->vma
3761 + input_section->output_offset,
3762 r_type, dynindx, addend, picrel);
3765 addend += frvfdpic_got_section (info)->output_section->vma;
3768 /* We want the addend in-place because dynamic
3769 relocations are REL. Setting relocation to it should
3770 arrange for it to be installed. */
3771 relocation = addend - rel->r_addend;
3773 check_segment[0] = check_segment[1] = got_segment;
3777 if (! IS_FDPIC (output_bfd))
3779 check_segment[0] = check_segment[1] = -1;
3783 case R_FRV_FUNCDESC_VALUE:
3786 bfd_vma addend = rel->r_addend;
3788 /* If the symbol is dynamic but binds locally, use
3790 if (h && ! FRVFDPIC_SYM_LOCAL (info, h))
3792 if (addend && r_type == R_FRV_FUNCDESC_VALUE)
3794 info->callbacks->warning
3795 (info, _("R_FRV_FUNCDESC_VALUE references dynamic symbol with nonzero addend"),
3796 name, input_bfd, input_section, rel->r_offset);
3799 dynindx = h->dynindx;
3804 addend += h->root.u.def.value;
3806 addend += sym->st_value;
3808 addend += osec->output_offset;
3809 if (osec && osec->output_section
3810 && ! bfd_is_abs_section (osec->output_section)
3811 && ! bfd_is_und_section (osec->output_section))
3812 dynindx = elf_section_data (osec->output_section)->dynindx;
3817 /* If we're linking an executable at a fixed address, we
3818 can omit the dynamic relocation as long as the symbol
3819 is defined in the current link unit (which is implied
3820 by its output section not being NULL). */
3821 if (info->executable && !info->pie
3822 && (!h || FRVFDPIC_SYM_LOCAL (info, h)))
3825 addend += osec->output_section->vma;
3826 if (IS_FDPIC (input_bfd)
3827 && (bfd_get_section_flags (output_bfd,
3828 input_section->output_section)
3829 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
3831 if (_frvfdpic_osec_readonly_p (output_bfd,
3835 info->callbacks->warning
3837 _("cannot emit fixups in read-only section"),
3838 name, input_bfd, input_section, rel->r_offset);
3841 if (!h || h->root.type != bfd_link_hash_undefweak)
3843 _frvfdpic_add_rofixup (output_bfd,
3844 frvfdpic_gotfixup_section
3846 _bfd_elf_section_offset
3848 input_section, rel->r_offset)
3850 ->output_section->vma
3851 + input_section->output_offset,
3853 if (r_type == R_FRV_FUNCDESC_VALUE)
3854 _frvfdpic_add_rofixup
3856 frvfdpic_gotfixup_section (info),
3857 _bfd_elf_section_offset
3859 input_section, rel->r_offset)
3860 + input_section->output_section->vma
3861 + input_section->output_offset + 4, picrel);
3867 if ((bfd_get_section_flags (output_bfd,
3868 input_section->output_section)
3869 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
3871 if (_frvfdpic_osec_readonly_p (output_bfd,
3875 info->callbacks->warning
3877 _("cannot emit dynamic relocations in read-only section"),
3878 name, input_bfd, input_section, rel->r_offset);
3881 _frvfdpic_add_dyn_reloc (output_bfd,
3882 frvfdpic_gotrel_section (info),
3883 _bfd_elf_section_offset
3885 input_section, rel->r_offset)
3887 ->output_section->vma
3888 + input_section->output_offset,
3889 r_type, dynindx, addend, picrel);
3892 addend += osec->output_section->vma;
3893 /* We want the addend in-place because dynamic
3894 relocations are REL. Setting relocation to it
3895 should arrange for it to be installed. */
3896 relocation = addend - rel->r_addend;
3899 if (r_type == R_FRV_FUNCDESC_VALUE)
3901 /* If we've omitted the dynamic relocation, just emit
3902 the fixed addresses of the symbol and of the local
3904 if (info->executable && !info->pie
3905 && (!h || FRVFDPIC_SYM_LOCAL (info, h)))
3906 bfd_put_32 (output_bfd,
3907 frvfdpic_got_section (info)->output_section->vma
3908 + frvfdpic_got_section (info)->output_offset
3909 + frvfdpic_got_initial_offset (info),
3910 contents + rel->r_offset + 4);
3912 /* A function descriptor used for lazy or local
3913 resolving is initialized such that its high word
3914 contains the output section index in which the
3915 PLT entries are located, and the low word
3916 contains the offset of the lazy PLT entry entry
3917 point into that section. */
3918 bfd_put_32 (output_bfd,
3919 h && ! FRVFDPIC_SYM_LOCAL (info, h)
3921 : _frvfdpic_osec_to_segment (output_bfd,
3924 contents + rel->r_offset + 4);
3927 check_segment[0] = check_segment[1] = got_segment;
3931 case R_FRV_GPRELU12:
3935 check_segment[0] = gprel_segment;
3936 check_segment[1] = sec
3937 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3941 case R_FRV_GETTLSOFF:
3942 relocation = frvfdpic_plt_section (info)->output_section->vma
3943 + frvfdpic_plt_section (info)->output_offset
3944 + picrel->tlsplt_entry;
3945 BFD_ASSERT (picrel->tlsplt_entry != (bfd_vma)-1
3946 && picrel->tlsdesc_entry);
3947 check_segment[0] = isec_segment;
3948 check_segment[1] = plt_segment;
3951 case R_FRV_GOTTLSDESC12:
3952 case R_FRV_GOTTLSDESCHI:
3953 case R_FRV_GOTTLSDESCLO:
3954 BFD_ASSERT (picrel->tlsdesc_entry);
3955 relocation = picrel->tlsdesc_entry;
3956 check_segment[0] = tls_segment;
3957 check_segment[1] = sec
3958 && ! bfd_is_abs_section (sec)
3959 && ! bfd_is_und_section (sec)
3960 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3964 case R_FRV_TLSMOFF12:
3965 case R_FRV_TLSMOFFHI:
3966 case R_FRV_TLSMOFFLO:
3968 check_segment[0] = tls_segment;
3970 check_segment[1] = -1;
3971 else if (bfd_is_abs_section (sec)
3972 || bfd_is_und_section (sec))
3975 check_segment[1] = tls_segment;
3977 else if (sec->output_section)
3979 relocation -= tls_biased_base (info);
3981 _frvfdpic_osec_to_segment (output_bfd, sec->output_section);
3985 case R_FRV_GOTTLSOFF12:
3986 case R_FRV_GOTTLSOFFHI:
3987 case R_FRV_GOTTLSOFFLO:
3988 BFD_ASSERT (picrel->tlsoff_entry);
3989 relocation = picrel->tlsoff_entry;
3990 check_segment[0] = tls_segment;
3991 check_segment[1] = sec
3992 && ! bfd_is_abs_section (sec)
3993 && ! bfd_is_und_section (sec)
3994 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3998 case R_FRV_TLSDESC_VALUE:
4000 /* These shouldn't be present in input object files. */
4001 check_segment[0] = check_segment[1] = isec_segment;
4004 case R_FRV_TLSDESC_RELAX:
4005 case R_FRV_GETTLSOFF_RELAX:
4006 case R_FRV_TLSOFF_RELAX:
4007 /* These are just annotations for relaxation, nothing to do
4012 check_segment[0] = isec_segment;
4013 check_segment[1] = sec
4014 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
4019 if (check_segment[0] != check_segment[1] && IS_FDPIC (output_bfd))
4021 #if 1 /* If you take this out, remove the #error from fdpic-static-6.d
4022 in the ld testsuite. */
4023 /* This helps catch problems in GCC while we can't do more
4024 than static linking. The idea is to test whether the
4025 input file basename is crt0.o only once. */
4026 if (silence_segment_error == 1)
4027 silence_segment_error =
4028 (strlen (input_bfd->filename) == 6
4029 && strcmp (input_bfd->filename, "crt0.o") == 0)
4030 || (strlen (input_bfd->filename) > 6
4031 && strcmp (input_bfd->filename
4032 + strlen (input_bfd->filename) - 7,
4036 if (!silence_segment_error
4037 /* We don't want duplicate errors for undefined
4039 && !(picrel && picrel->symndx == -1
4040 && picrel->d.h->root.type == bfd_link_hash_undefined))
4041 info->callbacks->warning
4043 (info->shared || info->pie)
4044 ? _("relocations between different segments are not supported")
4045 : _("warning: relocation references a different segment"),
4046 name, input_bfd, input_section, rel->r_offset);
4047 if (!silence_segment_error && (info->shared || info->pie))
4049 elf_elfheader (output_bfd)->e_flags |= EF_FRV_PIC;
4054 case R_FRV_GOTOFFHI:
4055 case R_FRV_TLSMOFFHI:
4056 /* We need the addend to be applied before we shift the
4058 relocation += rel->r_addend;
4061 case R_FRV_FUNCDESC_GOTHI:
4062 case R_FRV_FUNCDESC_GOTOFFHI:
4063 case R_FRV_GOTTLSOFFHI:
4064 case R_FRV_GOTTLSDESCHI:
4069 case R_FRV_FUNCDESC_GOTLO:
4070 case R_FRV_GOTOFFLO:
4071 case R_FRV_FUNCDESC_GOTOFFLO:
4072 case R_FRV_GOTTLSOFFLO:
4073 case R_FRV_GOTTLSDESCLO:
4074 case R_FRV_TLSMOFFLO:
4075 relocation &= 0xffff;
4085 if (! IS_FDPIC (output_bfd) || ! picrel->plt)
4089 /* When referencing a GOT entry, a function descriptor or a
4090 PLT, we don't want the addend to apply to the reference,
4091 but rather to the referenced symbol. The actual entry
4092 will have already been created taking the addend into
4093 account, so cancel it out here. */
4097 case R_FRV_FUNCDESC_GOT12:
4098 case R_FRV_FUNCDESC_GOTHI:
4099 case R_FRV_FUNCDESC_GOTLO:
4100 case R_FRV_FUNCDESC_GOTOFF12:
4101 case R_FRV_FUNCDESC_GOTOFFHI:
4102 case R_FRV_FUNCDESC_GOTOFFLO:
4103 case R_FRV_GETTLSOFF:
4104 case R_FRV_GOTTLSDESC12:
4105 case R_FRV_GOTTLSDESCHI:
4106 case R_FRV_GOTTLSDESCLO:
4107 case R_FRV_GOTTLSOFF12:
4108 case R_FRV_GOTTLSOFFHI:
4109 case R_FRV_GOTTLSOFFLO:
4110 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
4111 here, since we do want to apply the addend to the others.
4112 Note that we've applied the addend to GOTOFFHI before we
4113 shifted it right. */
4114 case R_FRV_GOTOFFHI:
4115 case R_FRV_TLSMOFFHI:
4116 relocation -= rel->r_addend;
4123 if (r_type == R_FRV_HI16)
4124 r = elf32_frv_relocate_hi16 (input_bfd, rel, contents, relocation);
4126 else if (r_type == R_FRV_LO16)
4127 r = elf32_frv_relocate_lo16 (input_bfd, rel, contents, relocation);
4129 else if (r_type == R_FRV_LABEL24 || r_type == R_FRV_GETTLSOFF)
4130 r = elf32_frv_relocate_label24 (input_bfd, input_section, rel,
4131 contents, relocation);
4133 else if (r_type == R_FRV_GPREL12)
4134 r = elf32_frv_relocate_gprel12 (info, input_bfd, input_section, rel,
4135 contents, relocation);
4137 else if (r_type == R_FRV_GPRELU12)
4138 r = elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, rel,
4139 contents, relocation);
4141 else if (r_type == R_FRV_GPRELLO)
4142 r = elf32_frv_relocate_gprello (info, input_bfd, input_section, rel,
4143 contents, relocation);
4145 else if (r_type == R_FRV_GPRELHI)
4146 r = elf32_frv_relocate_gprelhi (info, input_bfd, input_section, rel,
4147 contents, relocation);
4149 else if (r_type == R_FRV_TLSOFF
4150 || r_type == R_FRV_TLSDESC_VALUE)
4151 r = bfd_reloc_notsupported;
4154 r = frv_final_link_relocate (howto, input_bfd, input_section, contents,
4157 if (r != bfd_reloc_ok)
4159 const char * msg = (const char *) NULL;
4163 case bfd_reloc_overflow:
4164 r = info->callbacks->reloc_overflow
4165 (info, (h ? &h->root : NULL), name, howto->name,
4166 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
4169 case bfd_reloc_undefined:
4170 r = info->callbacks->undefined_symbol
4171 (info, name, input_bfd, input_section, rel->r_offset, TRUE);
4174 case bfd_reloc_outofrange:
4175 msg = _("internal error: out of range error");
4178 case bfd_reloc_notsupported:
4179 msg = _("internal error: unsupported relocation error");
4182 case bfd_reloc_dangerous:
4183 msg = _("internal error: dangerous relocation");
4187 msg = _("internal error: unknown error");
4192 r = info->callbacks->warning
4193 (info, msg, name, input_bfd, input_section, rel->r_offset);
4203 /* Return the section that should be marked against GC for a given
4207 elf32_frv_gc_mark_hook (sec, info, rel, h, sym)
4209 struct bfd_link_info *info ATTRIBUTE_UNUSED;
4210 Elf_Internal_Rela *rel;
4211 struct elf_link_hash_entry *h;
4212 Elf_Internal_Sym *sym;
4216 switch (ELF32_R_TYPE (rel->r_info))
4218 case R_FRV_GNU_VTINHERIT:
4219 case R_FRV_GNU_VTENTRY:
4223 switch (h->root.type)
4228 case bfd_link_hash_defined:
4229 case bfd_link_hash_defweak:
4230 return h->root.u.def.section;
4232 case bfd_link_hash_common:
4233 return h->root.u.c.p->section;
4238 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
4243 /* Update the got entry reference counts for the section being removed. */
4246 elf32_frv_gc_sweep_hook (abfd, info, sec, relocs)
4247 bfd *abfd ATTRIBUTE_UNUSED;
4248 struct bfd_link_info *info ATTRIBUTE_UNUSED;
4249 asection *sec ATTRIBUTE_UNUSED;
4250 const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
4256 /* Hook called by the linker routine which adds symbols from an object
4257 file. We use it to put .comm items in .scomm, and not .comm. */
4260 elf32_frv_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
4262 struct bfd_link_info *info;
4263 Elf_Internal_Sym *sym;
4264 const char **namep ATTRIBUTE_UNUSED;
4265 flagword *flagsp ATTRIBUTE_UNUSED;
4269 if (sym->st_shndx == SHN_COMMON
4270 && !info->relocatable
4271 && (int)sym->st_size <= (int)bfd_get_gp_size (abfd))
4273 /* Common symbols less than or equal to -G nn bytes are
4274 automatically put into .sbss. */
4276 asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
4280 scomm = bfd_make_section (abfd, ".scommon");
4282 || !bfd_set_section_flags (abfd, scomm, (SEC_ALLOC
4284 | SEC_LINKER_CREATED)))
4289 *valp = sym->st_size;
4295 /* We need dynamic symbols for every section, since segments can
4296 relocate independently. */
4298 _frvfdpic_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED,
4299 struct bfd_link_info *info
4301 asection *p ATTRIBUTE_UNUSED)
4303 switch (elf_section_data (p)->this_hdr.sh_type)
4307 /* If sh_type is yet undecided, assume it could be
4308 SHT_PROGBITS/SHT_NOBITS. */
4312 /* There shouldn't be section relative relocations
4313 against any other section. */
4319 /* Create a .got section, as well as its additional info field. This
4320 is almost entirely copied from
4321 elflink.c:_bfd_elf_create_got_section(). */
4324 _frv_create_got_section (bfd *abfd, struct bfd_link_info *info)
4326 flagword flags, pltflags;
4328 struct elf_link_hash_entry *h;
4329 struct bfd_link_hash_entry *bh;
4330 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
4334 /* This function may be called more than once. */
4335 s = bfd_get_section_by_name (abfd, ".got");
4336 if (s != NULL && (s->flags & SEC_LINKER_CREATED) != 0)
4339 /* Machine specific: although pointers are 32-bits wide, we want the
4340 GOT to be aligned to a 64-bit boundary, such that function
4341 descriptors in it can be accessed with 64-bit loads and
4345 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4346 | SEC_LINKER_CREATED);
4349 s = bfd_make_section (abfd, ".got");
4351 || !bfd_set_section_flags (abfd, s, flags)
4352 || !bfd_set_section_alignment (abfd, s, ptralign))
4355 if (bed->want_got_plt)
4357 s = bfd_make_section (abfd, ".got.plt");
4359 || !bfd_set_section_flags (abfd, s, flags)
4360 || !bfd_set_section_alignment (abfd, s, ptralign))
4364 if (bed->want_got_sym)
4366 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
4367 (or .got.plt) section. We don't do this in the linker script
4368 because we don't want to define the symbol if we are not creating
4369 a global offset table. */
4371 if (!(_bfd_generic_link_add_one_symbol
4372 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
4373 bed->got_symbol_offset, (const char *) NULL, FALSE,
4374 bed->collect, &bh)))
4376 h = (struct elf_link_hash_entry *) bh;
4378 h->type = STT_OBJECT;
4379 /* h->other = STV_HIDDEN; */ /* Should we? */
4381 /* Machine-specific: we want the symbol for executables as
4383 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4386 elf_hash_table (info)->hgot = h;
4389 /* The first bit of the global offset table is the header. */
4390 s->size += bed->got_header_size + bed->got_symbol_offset;
4392 /* This is the machine-specific part. Create and initialize section
4393 data for the got. */
4394 if (IS_FDPIC (abfd))
4396 frvfdpic_got_section (info) = s;
4397 frvfdpic_relocs_info (info) = htab_try_create (1,
4398 frvfdpic_relocs_info_hash,
4399 frvfdpic_relocs_info_eq,
4401 if (! frvfdpic_relocs_info (info))
4404 s = bfd_make_section (abfd, ".rel.got");
4406 || ! bfd_set_section_flags (abfd, s, (flags | SEC_READONLY))
4407 || ! bfd_set_section_alignment (abfd, s, 2))
4410 frvfdpic_gotrel_section (info) = s;
4412 /* Machine-specific. */
4413 s = bfd_make_section (abfd, ".rofixup");
4415 || ! bfd_set_section_flags (abfd, s, (flags | SEC_READONLY))
4416 || ! bfd_set_section_alignment (abfd, s, 2))
4419 frvfdpic_gotfixup_section (info) = s;
4426 flags = BSF_GLOBAL | BSF_WEAK;
4429 /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it
4430 turns out that we're linking with a different linker script, the
4431 linker script will override it. */
4433 if (!(_bfd_generic_link_add_one_symbol
4434 (info, abfd, "_gp", flags, s, offset, (const char *) NULL, FALSE,
4435 bed->collect, &bh)))
4437 h = (struct elf_link_hash_entry *) bh;
4439 h->type = STT_OBJECT;
4440 /* h->other = STV_HIDDEN; */ /* Should we? */
4442 /* Machine-specific: we want the symbol for executables as well. */
4443 if (IS_FDPIC (abfd) && ! bfd_elf_link_record_dynamic_symbol (info, h))
4446 if (!IS_FDPIC (abfd))
4449 /* FDPIC supports Thread Local Storage, and this may require a
4450 procedure linkage table for TLS PLT entries. */
4452 /* This is mostly copied from
4453 elflink.c:_bfd_elf_create_dynamic_sections(). */
4456 pltflags |= SEC_CODE;
4457 if (bed->plt_not_loaded)
4458 pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS);
4459 if (bed->plt_readonly)
4460 pltflags |= SEC_READONLY;
4462 s = bfd_make_section (abfd, ".plt");
4464 || ! bfd_set_section_flags (abfd, s, pltflags)
4465 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
4467 /* FRV-specific: remember it. */
4468 frvfdpic_plt_section (info) = s;
4470 if (bed->want_plt_sym)
4472 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
4474 struct elf_link_hash_entry *h;
4475 struct bfd_link_hash_entry *bh = NULL;
4477 if (! (_bfd_generic_link_add_one_symbol
4478 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s, 0, NULL,
4479 FALSE, get_elf_backend_data (abfd)->collect, &bh)))
4481 h = (struct elf_link_hash_entry *) bh;
4483 h->type = STT_OBJECT;
4484 /* h->other = STV_HIDDEN; */ /* Should we? */
4486 if (! info->executable
4487 && ! bfd_elf_link_record_dynamic_symbol (info, h))
4491 /* FRV-specific: we want rel relocations for the plt. */
4492 s = bfd_make_section (abfd, ".rel.plt");
4494 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
4495 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
4497 /* FRV-specific: remember it. */
4498 frvfdpic_pltrel_section (info) = s;
4503 /* Make sure the got and plt sections exist, and that our pointers in
4504 the link hash table point to them. */
4507 elf32_frvfdpic_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
4509 /* This is mostly copied from
4510 elflink.c:_bfd_elf_create_dynamic_sections(). */
4513 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
4515 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4516 | SEC_LINKER_CREATED);
4518 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
4519 .rel[a].bss sections. */
4521 /* FRV-specific: we want to create the GOT and the PLT in the FRV
4523 if (! _frv_create_got_section (abfd, info))
4526 /* FRV-specific: make sure we created everything we wanted. */
4527 BFD_ASSERT (frvfdpic_got_section (info) && frvfdpic_gotrel_section (info)
4528 && frvfdpic_gotfixup_section (info)
4529 && frvfdpic_plt_section (info)
4530 && frvfdpic_pltrel_section (info));
4532 if (bed->want_dynbss)
4534 /* The .dynbss section is a place to put symbols which are defined
4535 by dynamic objects, are referenced by regular objects, and are
4536 not functions. We must allocate space for them in the process
4537 image and use a R_*_COPY reloc to tell the dynamic linker to
4538 initialize them at run time. The linker script puts the .dynbss
4539 section into the .bss section of the final image. */
4540 s = bfd_make_section (abfd, ".dynbss");
4542 || ! bfd_set_section_flags (abfd, s, SEC_ALLOC | SEC_LINKER_CREATED))
4545 /* The .rel[a].bss section holds copy relocs. This section is not
4546 normally needed. We need to create it here, though, so that the
4547 linker will map it to an output section. We can't just create it
4548 only if we need it, because we will not know whether we need it
4549 until we have seen all the input files, and the first time the
4550 main linker code calls BFD after examining all the input files
4551 (size_dynamic_sections) the input sections have already been
4552 mapped to the output sections. If the section turns out not to
4553 be needed, we can discard it later. We will never need this
4554 section when generating a shared object, since they do not use
4558 s = bfd_make_section (abfd,
4559 (bed->default_use_rela_p
4560 ? ".rela.bss" : ".rel.bss"));
4562 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
4563 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
4571 /* Compute the total GOT and PLT size required by each symbol in each
4572 range. Symbols may require up to 4 words in the GOT: an entry
4573 pointing to the symbol, an entry pointing to its function
4574 descriptor, and a private function descriptors taking two
4578 _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info *entry,
4579 struct _frvfdpic_dynamic_got_info *dinfo)
4581 /* Allocate space for a GOT entry pointing to the symbol. */
4584 else if (entry->gotlos)
4586 else if (entry->gothilo)
4587 dinfo->gothilo += 4;
4592 /* Allocate space for a GOT entry pointing to the function
4596 else if (entry->fdgotlos)
4598 else if (entry->fdgothilo)
4599 dinfo->gothilo += 4;
4604 /* Decide whether we need a PLT entry, a function descriptor in the
4605 GOT, and a lazy PLT entry for this symbol. */
4606 entry->plt = entry->call
4607 && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
4608 && elf_hash_table (dinfo->info)->dynamic_sections_created;
4609 entry->privfd = entry->plt
4610 || entry->fdgoff12 || entry->fdgofflos || entry->fdgoffhilo
4611 || ((entry->fd || entry->fdgot12 || entry->fdgotlos || entry->fdgothilo)
4612 && (entry->symndx != -1
4613 || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h)));
4614 entry->lazyplt = entry->privfd
4615 && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
4616 && ! (dinfo->info->flags & DF_BIND_NOW)
4617 && elf_hash_table (dinfo->info)->dynamic_sections_created;
4619 /* Allocate space for a function descriptor. */
4620 if (entry->fdgoff12)
4622 else if (entry->fdgofflos)
4624 else if (entry->privfd && entry->plt)
4626 else if (entry->privfd)
4636 /* Compute the total GOT size required by each TLS symbol in each
4637 range. Symbols may require up to 5 words in the GOT: an entry
4638 holding the TLS offset for the symbol, and an entry with a full TLS
4639 descriptor taking 4 words. */
4642 _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info *entry,
4643 struct _frvfdpic_dynamic_got_info *dinfo,
4644 bfd_boolean subtract)
4646 const int l = subtract ? -1 : 1;
4648 /* Allocate space for a GOT entry with the TLS offset of the
4650 if (entry->tlsoff12)
4651 dinfo->got12 += 4 * l;
4652 else if (entry->tlsofflos)
4653 dinfo->gotlos += 4 * l;
4654 else if (entry->tlsoffhilo)
4655 dinfo->gothilo += 4 * l;
4657 entry->relocstlsoff -= l;
4658 entry->relocstlsoff += l;
4660 /* If there's any TLSOFF relocation, mark the output file as not
4661 suitable for dlopening. This mark will remain even if we relax
4662 all such relocations, but this is not a problem, since we'll only
4663 do so for executables, and we definitely don't want anyone
4664 dlopening executables. */
4665 if (entry->relocstlsoff)
4666 dinfo->info->flags |= DF_STATIC_TLS;
4668 /* Allocate space for a TLS descriptor. */
4669 if (entry->tlsdesc12)
4670 dinfo->tlsd12 += 8 * l;
4671 else if (entry->tlsdesclos)
4672 dinfo->tlsdlos += 8 * l;
4673 else if (entry->tlsplt)
4674 dinfo->tlsdplt += 8 * l;
4675 else if (entry->tlsdeschilo)
4676 dinfo->tlsdhilo += 8 * l;
4678 entry->relocstlsd -= l;
4679 entry->relocstlsd += l;
4682 /* Compute the number of dynamic relocations and fixups that a symbol
4683 requires, and add (or subtract) from the grand and per-symbol
4687 _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info *entry,
4688 struct _frvfdpic_dynamic_got_info *dinfo,
4689 bfd_boolean subtract)
4691 bfd_vma relocs = 0, fixups = 0, tlsrets = 0;
4693 if (!dinfo->info->executable || dinfo->info->pie)
4695 relocs = entry->relocs32 + entry->relocsfd + entry->relocsfdv
4696 + entry->relocstlsd;
4698 /* In the executable, TLS relocations to symbols that bind
4699 locally (including those that resolve to global TLS offsets)
4700 are resolved immediately, without any need for fixups or
4701 dynamic relocations. In shared libraries, however, we must
4702 emit dynamic relocations even for local symbols, because we
4703 don't know the module id the library is going to get at
4704 run-time, nor its TLS base offset. */
4705 if (!dinfo->info->executable
4706 || (entry->symndx == -1
4707 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)))
4708 relocs += entry->relocstlsoff;
4712 if (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h))
4714 if (entry->symndx != -1
4715 || entry->d.h->root.type != bfd_link_hash_undefweak)
4716 fixups += entry->relocs32 + 2 * entry->relocsfdv;
4717 fixups += entry->relocstlsd;
4718 tlsrets += entry->relocstlsd;
4722 relocs += entry->relocs32 + entry->relocsfdv
4723 + entry->relocstlsoff + entry->relocstlsd;
4726 if (entry->symndx != -1
4727 || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h))
4729 if (entry->symndx != -1
4730 || entry->d.h->root.type != bfd_link_hash_undefweak)
4731 fixups += entry->relocsfd;
4734 relocs += entry->relocsfd;
4741 tlsrets = - tlsrets;
4744 entry->dynrelocs += relocs;
4745 entry->fixups += fixups;
4746 dinfo->relocs += relocs;
4747 dinfo->fixups += fixups;
4748 dinfo->tls_ret_refs += tlsrets;
4751 /* Look for opportunities to relax TLS relocations. We can assume
4752 we're linking the main executable or a static-tls library, since
4753 otherwise we wouldn't have got here. When relaxing, we have to
4754 first undo any previous accounting of TLS uses of fixups, dynamic
4755 relocations, GOT and PLT entries. */
4758 _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info *entry,
4759 struct _frvfdpic_dynamic_got_info *dinfo,
4760 bfd_boolean relaxing)
4762 bfd_boolean changed = ! relaxing;
4764 BFD_ASSERT (dinfo->info->executable
4765 || (dinfo->info->flags & DF_STATIC_TLS));
4767 if (entry->tlsdesc12 || entry->tlsdesclos || entry->tlsdeschilo)
4771 _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE);
4772 _frvfdpic_count_tls_entries (entry, dinfo, TRUE);
4776 /* When linking an executable, we can always decay GOTTLSDESC to
4777 TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise.
4778 When linking a static-tls shared library, using TLSMOFF is
4779 not an option, but we can still use GOTTLSOFF. When decaying
4780 to GOTTLSOFF, we must keep the GOT entry in range. We know
4781 it has to fit because we'll be trading the 4 words of hte TLS
4782 descriptor for a single word in the same range. */
4783 if (! dinfo->info->executable
4784 || (entry->symndx == -1
4785 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)))
4787 entry->tlsoff12 |= entry->tlsdesc12;
4788 entry->tlsofflos |= entry->tlsdesclos;
4789 entry->tlsoffhilo |= entry->tlsdeschilo;
4792 entry->tlsdesc12 = entry->tlsdesclos = entry->tlsdeschilo = 0;
4795 /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the
4796 main executable. We have to check whether the symbol's TLSOFF is
4797 in range for a setlos. For symbols with a hash entry, we can
4798 determine exactly what to do; for others locals, we don't have
4799 addresses handy, so we use the size of the TLS section as an
4800 approximation. If we get it wrong, we'll retain a GOT entry
4801 holding the TLS offset (without dynamic relocations or fixups),
4802 but we'll still optimize away the loads from it. Since TLS sizes
4803 are generally very small, it's probably not worth attempting to
4804 do better than this. */
4806 || entry->tlsoff12 || entry->tlsofflos || entry->tlsoffhilo)
4807 && dinfo->info->executable && relaxing
4808 && ((entry->symndx == -1
4809 && FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
4810 /* The above may hold for an undefweak TLS symbol, so make
4811 sure we don't have this case before accessing def.value
4813 && (entry->d.h->root.type == bfd_link_hash_undefweak
4814 || (bfd_vma)(entry->d.h->root.u.def.value
4815 + (entry->d.h->root.u.def.section
4816 ->output_section->vma)
4817 + entry->d.h->root.u.def.section->output_offset
4819 - tls_biased_base (dinfo->info)
4820 + 32768) < (bfd_vma)65536))
4821 || (entry->symndx != -1
4822 && (elf_hash_table (dinfo->info)->tls_sec->size
4823 + abs (entry->addend) < 32768 + FRVFDPIC_TLS_BIAS))))
4827 _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE);
4828 _frvfdpic_count_tls_entries (entry, dinfo, TRUE);
4833 entry->tlsoff12 = entry->tlsofflos = entry->tlsoffhilo = 0;
4836 /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already
4837 have a #gottlsoff12 relocation for this entry, or if we can fit
4838 one more in the 12-bit (and 16-bit) ranges. */
4842 && dinfo->got12 + dinfo->fd12 + dinfo->tlsd12 <= 4096 - 12 - 4
4843 && (dinfo->got12 + dinfo->fd12 + dinfo->tlsd12
4844 + dinfo->gotlos + dinfo->fdlos + dinfo->tlsdlos
4845 <= 65536 - 12 - 4))))
4849 _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE);
4850 _frvfdpic_count_tls_entries (entry, dinfo, TRUE);
4854 entry->tlsoff12 = 1;
4860 _frvfdpic_count_tls_entries (entry, dinfo, FALSE);
4861 _frvfdpic_count_relocs_fixups (entry, dinfo, FALSE);
4867 /* Compute the total GOT and PLT size required by each symbol in each range. *
4868 Symbols may require up to 4 words in the GOT: an entry pointing to
4869 the symbol, an entry pointing to its function descriptor, and a
4870 private function descriptors taking two words. */
4873 _frvfdpic_count_got_plt_entries (void **entryp, void *dinfo_)
4875 struct frvfdpic_relocs_info *entry = *entryp;
4876 struct _frvfdpic_dynamic_got_info *dinfo = dinfo_;
4878 _frvfdpic_count_nontls_entries (entry, dinfo);
4880 if (dinfo->info->executable || (dinfo->info->flags & DF_STATIC_TLS))
4881 _frvfdpic_relax_tls_entries (entry, dinfo, FALSE);
4884 _frvfdpic_count_tls_entries (entry, dinfo, FALSE);
4885 _frvfdpic_count_relocs_fixups (entry, dinfo, FALSE);
4891 /* Determine the positive and negative ranges to be used by each
4892 offset range in the GOT. FDCUR and CUR, that must be aligned to a
4893 double-word boundary, are the minimum (negative) and maximum
4894 (positive) GOT offsets already used by previous ranges, except for
4895 an ODD entry that may have been left behind. GOT and FD indicate
4896 the size of GOT entries and function descriptors that must be
4897 placed within the range from -WRAP to WRAP. If there's room left,
4898 up to FDPLT bytes should be reserved for additional function
4901 inline static bfd_signed_vma
4902 _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data *gad,
4903 bfd_signed_vma fdcur,
4913 bfd_signed_vma wrapmin = -wrap;
4914 const bfd_vma tdescsz = 8;
4916 /* Start at the given initial points. */
4920 /* If we had an incoming odd word and we have any got entries that
4921 are going to use it, consume it, otherwise leave gad->odd at
4922 zero. We might force gad->odd to zero and return the incoming
4923 odd such that it is used by the next range, but then GOT entries
4924 might appear to be out of order and we wouldn't be able to
4925 shorten the GOT by one word if it turns out to end with an
4926 unpaired GOT entry. */
4936 /* If we're left with an unpaired GOT entry, compute its location
4937 such that we can return it. Otherwise, if got doesn't require an
4938 odd number of words here, either odd was already zero in the
4939 block above, or it was set to zero because got was non-zero, or
4940 got was already zero. In the latter case, we want the value of
4941 odd to carry over to the return statement, so we don't want to
4942 reset odd unless the condition below is true. */
4949 /* Compute the tentative boundaries of this range. */
4950 gad->max = cur + got;
4951 gad->min = fdcur - fd;
4954 /* If function descriptors took too much space, wrap some of them
4956 if (gad->min < wrapmin)
4958 gad->max += wrapmin - gad->min;
4959 gad->tmin = gad->min = wrapmin;
4962 /* If GOT entries took too much space, wrap some of them around.
4963 This may well cause gad->min to become lower than wrapmin. This
4964 will cause a relocation overflow later on, so we don't have to
4966 if ((bfd_vma) gad->max > wrap)
4968 gad->min -= gad->max - wrap;
4972 /* Add TLS descriptors. */
4973 gad->tmax = gad->max + tlsd;
4974 gad->tmin = gad->min;
4977 /* If TLS descriptors took too much space, wrap an integral number
4979 if ((bfd_vma) gad->tmax > wrap)
4981 bfd_vma wrapsize = gad->tmax - wrap;
4983 wrapsize += tdescsz / 2;
4984 wrapsize &= ~ tdescsz / 2;
4986 gad->tmin -= wrapsize;
4987 gad->tmax -= wrapsize;
4990 /* If there is space left and we have function descriptors
4991 referenced in PLT entries that could take advantage of shorter
4992 offsets, place them now. */
4993 if (fdplt && gad->tmin > wrapmin)
4997 if ((bfd_vma) (gad->tmin - wrapmin) < fdplt)
4998 fds = gad->tmin - wrapmin;
5008 /* If there is more space left, try to place some more function
5009 descriptors for PLT entries. */
5010 if (fdplt && (bfd_vma) gad->tmax < wrap)
5014 if ((bfd_vma) (wrap - gad->tmax) < fdplt)
5015 fds = wrap - gad->tmax;
5025 /* If there is space left and we have TLS descriptors referenced in
5026 PLT entries that could take advantage of shorter offsets, place
5028 if (tlsdplt && gad->tmin > wrapmin)
5032 if ((bfd_vma) (gad->tmin - wrapmin) < tlsdplt)
5033 tlsds = (gad->tmin - wrapmin) & ~ (tdescsz / 2);
5039 gad->tlsdplt += tlsds;
5042 /* If there is more space left, try to place some more TLS
5043 descriptors for PLT entries. Although we could try to fit an
5044 additional TLS descriptor with half of it just before before the
5045 wrap point and another right past the wrap point, this might
5046 cause us to run out of space for the next region, so don't do
5048 if (tlsdplt && (bfd_vma) gad->tmax < wrap - tdescsz / 2)
5052 if ((bfd_vma) (wrap - gad->tmax) < tlsdplt)
5053 tlsds = (wrap - gad->tmax) & ~ (tdescsz / 2);
5059 gad->tlsdplt += tlsds;
5062 /* If odd was initially computed as an offset past the wrap point,
5065 odd = gad->min + odd - gad->max;
5067 /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed
5068 before returning, so do it here too. This guarantees that,
5069 should cur and fdcur meet at the wrap point, they'll both be
5071 if (gad->cur == gad->max)
5072 gad->cur = gad->min;
5074 /* Ditto for _frvfdpic_get_tlsdesc_entry(). */
5075 gad->tcur = gad->max;
5076 if (gad->tcur == gad->tmax)
5077 gad->tcur = gad->tmin;
5082 /* Compute the location of the next GOT entry, given the allocation
5083 data for a range. */
5085 inline static bfd_signed_vma
5086 _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
5092 /* If there was an odd word left behind, use it. */
5098 /* Otherwise, use the word pointed to by cur, reserve the next
5099 as an odd word, and skip to the next pair of words, possibly
5102 gad->odd = gad->cur + 4;
5104 if (gad->cur == gad->max)
5105 gad->cur = gad->min;
5111 /* Compute the location of the next function descriptor entry in the
5112 GOT, given the allocation data for a range. */
5114 inline static bfd_signed_vma
5115 _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
5117 /* If we're at the bottom, wrap around, and only then allocate the
5118 next pair of words. */
5119 if (gad->fdcur == gad->min)
5120 gad->fdcur = gad->max;
5121 return gad->fdcur -= 8;
5124 /* Compute the location of the next TLS descriptor entry in the GOT,
5125 given the allocation data for a range. */
5126 inline static bfd_signed_vma
5127 _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
5135 /* If we're at the top of the region, wrap around to the bottom. */
5136 if (gad->tcur == gad->tmax)
5137 gad->tcur = gad->tmin;
5142 /* Assign GOT offsets for every GOT entry and function descriptor.
5143 Doing everything in a single pass is tricky. */
5146 _frvfdpic_assign_got_entries (void **entryp, void *info_)
5148 struct frvfdpic_relocs_info *entry = *entryp;
5149 struct _frvfdpic_dynamic_got_plt_info *dinfo = info_;
5152 entry->got_entry = _frvfdpic_get_got_entry (&dinfo->got12);
5153 else if (entry->gotlos)
5154 entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
5155 else if (entry->gothilo)
5156 entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
5159 entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->got12);
5160 else if (entry->fdgotlos)
5161 entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
5162 else if (entry->fdgothilo)
5163 entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
5165 if (entry->fdgoff12)
5166 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12);
5167 else if (entry->plt && dinfo->got12.fdplt)
5169 dinfo->got12.fdplt -= 8;
5170 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12);
5172 else if (entry->fdgofflos)
5173 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos);
5174 else if (entry->plt && dinfo->gotlos.fdplt)
5176 dinfo->gotlos.fdplt -= 8;
5177 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos);
5179 else if (entry->plt)
5181 dinfo->gothilo.fdplt -= 8;
5182 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo);
5184 else if (entry->privfd)
5185 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo);
5187 if (entry->tlsoff12)
5188 entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->got12);
5189 else if (entry->tlsofflos)
5190 entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
5191 else if (entry->tlsoffhilo)
5192 entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
5194 if (entry->tlsdesc12)
5195 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12);
5196 else if (entry->tlsplt && dinfo->got12.tlsdplt)
5198 dinfo->got12.tlsdplt -= 8;
5199 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12);
5201 else if (entry->tlsdesclos)
5202 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos);
5203 else if (entry->tlsplt && dinfo->gotlos.tlsdplt)
5205 dinfo->gotlos.tlsdplt -= 8;
5206 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos);
5208 else if (entry->tlsplt)
5210 dinfo->gothilo.tlsdplt -= 8;
5211 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo);
5213 else if (entry->tlsdeschilo)
5214 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo);
5219 /* Assign GOT offsets to private function descriptors used by PLT
5220 entries (or referenced by 32-bit offsets), as well as PLT entries
5221 and lazy PLT entries. */
5224 _frvfdpic_assign_plt_entries (void **entryp, void *info_)
5226 struct frvfdpic_relocs_info *entry = *entryp;
5227 struct _frvfdpic_dynamic_got_plt_info *dinfo = info_;
5231 BFD_ASSERT (entry->fd_entry);
5233 /* If this symbol requires a local function descriptor, allocate
5235 if (entry->privfd && entry->fd_entry == 0)
5237 if (dinfo->got12.fdplt)
5239 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12);
5240 dinfo->got12.fdplt -= 8;
5242 else if (dinfo->gotlos.fdplt)
5244 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos);
5245 dinfo->gotlos.fdplt -= 8;
5249 BFD_ASSERT (dinfo->gothilo.fdplt);
5250 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo);
5251 dinfo->gothilo.fdplt -= 8;
5260 /* We use the section's raw size to mark the location of the
5262 entry->plt_entry = frvfdpic_plt_section (dinfo->g.info)->size;
5264 /* Figure out the length of this PLT entry based on the
5265 addressing mode we need to reach the function descriptor. */
5266 BFD_ASSERT (entry->fd_entry);
5267 if (entry->fd_entry >= -(1 << (12 - 1))
5268 && entry->fd_entry < (1 << (12 - 1)))
5270 else if (entry->fd_entry >= -(1 << (16 - 1))
5271 && entry->fd_entry < (1 << (16 - 1)))
5276 frvfdpic_plt_section (dinfo->g.info)->size += size;
5281 entry->lzplt_entry = dinfo->g.lzplt;
5282 dinfo->g.lzplt += 8;
5283 /* If this entry is the one that gets the resolver stub, account
5284 for the additional instruction. */
5285 if (entry->lzplt_entry % FRVFDPIC_LZPLT_BLOCK_SIZE
5286 == FRVFDPIC_LZPLT_RESOLV_LOC)
5287 dinfo->g.lzplt += 4;
5295 = frvfdpic_plt_section (dinfo->g.info)->size;
5297 if (dinfo->g.info->executable
5298 && (entry->symndx != -1
5299 || FRVFDPIC_SYM_LOCAL (dinfo->g.info, entry->d.h)))
5301 if ((bfd_signed_vma)entry->addend >= -(1 << (16 - 1))
5302 /* FIXME: here we use the size of the TLS section
5303 as an upper bound for the value of the TLS
5304 symbol, because we may not know the exact value
5305 yet. If we get it wrong, we'll just waste a
5306 word in the PLT, and we should never get even
5307 close to 32 KiB of TLS anyway. */
5308 && elf_hash_table (dinfo->g.info)->tls_sec
5309 && (elf_hash_table (dinfo->g.info)->tls_sec->size
5310 + (bfd_signed_vma)(entry->addend) <= (1 << (16 - 1))))
5315 else if (entry->tlsoff_entry)
5317 if (entry->tlsoff_entry >= -(1 << (12 - 1))
5318 && entry->tlsoff_entry < (1 << (12 - 1)))
5320 else if (entry->tlsoff_entry >= -(1 << (16 - 1))
5321 && entry->tlsoff_entry < (1 << (16 - 1)))
5328 BFD_ASSERT (entry->tlsdesc_entry);
5330 if (entry->tlsdesc_entry >= -(1 << (12 - 1))
5331 && entry->tlsdesc_entry < (1 << (12 - 1)))
5333 else if (entry->tlsdesc_entry >= -(1 << (16 - 1))
5334 && entry->tlsdesc_entry < (1 << (16 - 1)))
5340 frvfdpic_plt_section (dinfo->g.info)->size += size;
5346 /* Cancel out any effects of calling _frvfdpic_assign_got_entries and
5347 _frvfdpic_assign_plt_entries. */
5350 _frvfdpic_reset_got_plt_entries (void **entryp, void *ignore ATTRIBUTE_UNUSED)
5352 struct frvfdpic_relocs_info *entry = *entryp;
5354 entry->got_entry = 0;
5355 entry->fdgot_entry = 0;
5356 entry->fd_entry = 0;
5357 entry->plt_entry = (bfd_vma)-1;
5358 entry->lzplt_entry = (bfd_vma)-1;
5359 entry->tlsoff_entry = 0;
5360 entry->tlsdesc_entry = 0;
5361 entry->tlsplt_entry = (bfd_vma)-1;
5366 /* Follow indirect and warning hash entries so that each got entry
5367 points to the final symbol definition. P must point to a pointer
5368 to the hash table we're traversing. Since this traversal may
5369 modify the hash table, we set this pointer to NULL to indicate
5370 we've made a potentially-destructive change to the hash table, so
5371 the traversal must be restarted. */
5373 _frvfdpic_resolve_final_relocs_info (void **entryp, void *p)
5375 struct frvfdpic_relocs_info *entry = *entryp;
5378 if (entry->symndx == -1)
5380 struct elf_link_hash_entry *h = entry->d.h;
5381 struct frvfdpic_relocs_info *oentry;
5383 while (h->root.type == bfd_link_hash_indirect
5384 || h->root.type == bfd_link_hash_warning)
5385 h = (struct elf_link_hash_entry *)h->root.u.i.link;
5387 if (entry->d.h == h)
5390 oentry = frvfdpic_relocs_info_for_global (*htab, 0, h, entry->addend,
5395 /* Merge the two entries. */
5396 frvfdpic_pic_merge_early_relocs_info (oentry, entry);
5397 htab_clear_slot (*htab, entryp);
5403 /* If we can't find this entry with the new bfd hash, re-insert
5404 it, and get the traversal restarted. */
5405 if (! htab_find (*htab, entry))
5407 htab_clear_slot (*htab, entryp);
5408 entryp = htab_find_slot (*htab, entry, INSERT);
5411 /* Abort the traversal, since the whole table may have
5412 moved, and leave it up to the parent to restart the
5414 *(htab_t *)p = NULL;
5422 /* Compute the total size of the GOT, the PLT, the dynamic relocations
5423 section and the rofixup section. Assign locations for GOT and PLT
5427 _frvfdpic_size_got_plt (bfd *output_bfd,
5428 struct _frvfdpic_dynamic_got_plt_info *gpinfop)
5431 bfd_vma limit, tlslimit;
5432 struct bfd_link_info *info = gpinfop->g.info;
5433 bfd *dynobj = elf_hash_table (info)->dynobj;
5435 memcpy (frvfdpic_dynamic_got_plt_info (info), &gpinfop->g,
5436 sizeof (gpinfop->g));
5439 /* Compute the total size taken by entries in the 12-bit and 16-bit
5440 ranges, to tell how many PLT function descriptors we can bring
5441 into the 12-bit range without causing the 16-bit range to
5443 limit = odd + gpinfop->g.got12 + gpinfop->g.gotlos
5444 + gpinfop->g.fd12 + gpinfop->g.fdlos
5445 + gpinfop->g.tlsd12 + gpinfop->g.tlsdlos;
5446 if (limit < (bfd_vma)1 << 16)
5447 limit = ((bfd_vma)1 << 16) - limit;
5450 if (gpinfop->g.fdplt < limit)
5452 tlslimit = (limit - gpinfop->g.fdplt) & ~ (bfd_vma) 8;
5453 limit = gpinfop->g.fdplt;
5457 if (gpinfop->g.tlsdplt < tlslimit)
5458 tlslimit = gpinfop->g.tlsdplt;
5460 /* Determine the ranges of GOT offsets that we can use for each
5461 range of addressing modes. */
5462 odd = _frvfdpic_compute_got_alloc_data (&gpinfop->got12,
5471 (bfd_vma)1 << (12-1));
5472 odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gotlos,
5473 gpinfop->got12.tmin,
5475 gpinfop->got12.tmax,
5479 - gpinfop->got12.fdplt,
5482 - gpinfop->got12.tlsdplt,
5483 (bfd_vma)1 << (16-1));
5484 odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gothilo,
5485 gpinfop->gotlos.tmin,
5487 gpinfop->gotlos.tmax,
5491 - gpinfop->got12.fdplt
5492 - gpinfop->gotlos.fdplt,
5493 gpinfop->g.tlsdhilo,
5495 - gpinfop->got12.tlsdplt
5496 - gpinfop->gotlos.tlsdplt,
5497 (bfd_vma)1 << (32-1));
5499 /* Now assign (most) GOT offsets. */
5500 htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_got_entries,
5503 frvfdpic_got_section (info)->size = gpinfop->gothilo.tmax
5504 - gpinfop->gothilo.tmin
5505 /* If an odd word is the last word of the GOT, we don't need this
5506 word to be part of the GOT. */
5507 - (odd + 4 == gpinfop->gothilo.tmax ? 4 : 0);
5508 if (frvfdpic_got_section (info)->size == 0)
5509 frvfdpic_got_section (info)->flags |= SEC_EXCLUDE;
5510 else if (frvfdpic_got_section (info)->size == 12
5511 && ! elf_hash_table (info)->dynamic_sections_created)
5513 frvfdpic_got_section (info)->flags |= SEC_EXCLUDE;
5514 frvfdpic_got_section (info)->size = 0;
5516 /* This will be non-NULL during relaxation. The assumption is that
5517 the size of one of these sections will never grow, only shrink,
5518 so we can use the larger buffer we allocated before. */
5519 else if (frvfdpic_got_section (info)->contents == NULL)
5521 frvfdpic_got_section (info)->contents =
5522 (bfd_byte *) bfd_zalloc (dynobj,
5523 frvfdpic_got_section (info)->size);
5524 if (frvfdpic_got_section (info)->contents == NULL)
5528 if (frvfdpic_gotrel_section (info))
5529 /* Subtract the number of lzplt entries, since those will generate
5530 relocations in the pltrel section. */
5531 frvfdpic_gotrel_section (info)->size =
5532 (gpinfop->g.relocs - gpinfop->g.lzplt / 8)
5533 * get_elf_backend_data (output_bfd)->s->sizeof_rel;
5535 BFD_ASSERT (gpinfop->g.relocs == 0);
5536 if (frvfdpic_gotrel_section (info)->size == 0)
5537 frvfdpic_gotrel_section (info)->flags |= SEC_EXCLUDE;
5538 else if (frvfdpic_gotrel_section (info)->contents == NULL)
5540 frvfdpic_gotrel_section (info)->contents =
5541 (bfd_byte *) bfd_zalloc (dynobj,
5542 frvfdpic_gotrel_section (info)->size);
5543 if (frvfdpic_gotrel_section (info)->contents == NULL)
5547 frvfdpic_gotfixup_section (info)->size = (gpinfop->g.fixups + 1) * 4;
5548 if (frvfdpic_gotfixup_section (info)->size == 0)
5549 frvfdpic_gotfixup_section (info)->flags |= SEC_EXCLUDE;
5550 else if (frvfdpic_gotfixup_section (info)->contents == NULL)
5552 frvfdpic_gotfixup_section (info)->contents =
5553 (bfd_byte *) bfd_zalloc (dynobj,
5554 frvfdpic_gotfixup_section (info)->size);
5555 if (frvfdpic_gotfixup_section (info)->contents == NULL)
5559 if (frvfdpic_pltrel_section (info))
5561 frvfdpic_pltrel_section (info)->size =
5562 gpinfop->g.lzplt / 8
5563 * get_elf_backend_data (output_bfd)->s->sizeof_rel;
5564 if (frvfdpic_pltrel_section (info)->size == 0)
5565 frvfdpic_pltrel_section (info)->flags |= SEC_EXCLUDE;
5566 else if (frvfdpic_pltrel_section (info)->contents == NULL)
5568 frvfdpic_pltrel_section (info)->contents =
5569 (bfd_byte *) bfd_zalloc (dynobj,
5570 frvfdpic_pltrel_section (info)->size);
5571 if (frvfdpic_pltrel_section (info)->contents == NULL)
5576 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
5577 such that there's room for the additional instruction needed to
5578 call the resolver. Since _frvfdpic_assign_got_entries didn't
5579 account for them, our block size is 4 bytes smaller than the real
5581 if (frvfdpic_plt_section (info))
5583 frvfdpic_plt_section (info)->size = gpinfop->g.lzplt
5584 + ((gpinfop->g.lzplt + (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) - 8)
5585 / (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) * 4);
5588 /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to
5589 actually assign lazy PLT entries addresses. */
5590 gpinfop->g.lzplt = 0;
5592 /* Save information that we're going to need to generate GOT and PLT
5594 frvfdpic_got_initial_offset (info) = -gpinfop->gothilo.tmin;
5596 if (get_elf_backend_data (output_bfd)->want_got_sym)
5597 elf_hash_table (info)->hgot->root.u.def.value
5598 = frvfdpic_got_initial_offset (info);
5600 if (frvfdpic_plt_section (info))
5601 frvfdpic_plt_initial_offset (info) =
5602 frvfdpic_plt_section (info)->size;
5604 /* Allocate a ret statement at plt_initial_offset, to be used by
5605 locally-resolved TLS descriptors. */
5606 if (gpinfop->g.tls_ret_refs)
5607 frvfdpic_plt_section (info)->size += 4;
5609 htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_plt_entries,
5612 /* Allocate the PLT section contents only after
5613 _frvfdpic_assign_plt_entries has a chance to add the size of the
5614 non-lazy PLT entries. */
5615 if (frvfdpic_plt_section (info))
5617 if (frvfdpic_plt_section (info)->size == 0)
5618 frvfdpic_plt_section (info)->flags |= SEC_EXCLUDE;
5619 else if (frvfdpic_plt_section (info)->contents == NULL)
5621 frvfdpic_plt_section (info)->contents =
5622 (bfd_byte *) bfd_zalloc (dynobj,
5623 frvfdpic_plt_section (info)->size);
5624 if (frvfdpic_plt_section (info)->contents == NULL)
5632 /* Set the sizes of the dynamic sections. */
5635 elf32_frvfdpic_size_dynamic_sections (bfd *output_bfd,
5636 struct bfd_link_info *info)
5640 struct _frvfdpic_dynamic_got_plt_info gpinfo;
5642 dynobj = elf_hash_table (info)->dynobj;
5643 BFD_ASSERT (dynobj != NULL);
5645 if (elf_hash_table (info)->dynamic_sections_created)
5647 /* Set the contents of the .interp section to the interpreter. */
5648 if (info->executable)
5650 s = bfd_get_section_by_name (dynobj, ".interp");
5651 BFD_ASSERT (s != NULL);
5652 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
5653 s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
5657 memset (&gpinfo, 0, sizeof (gpinfo));
5658 gpinfo.g.info = info;
5662 htab_t relocs = frvfdpic_relocs_info (info);
5664 htab_traverse (relocs, _frvfdpic_resolve_final_relocs_info, &relocs);
5666 if (relocs == frvfdpic_relocs_info (info))
5670 htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_count_got_plt_entries,
5673 /* Allocate space to save the summary information, we're going to
5674 use it if we're doing relaxations. */
5675 frvfdpic_dynamic_got_plt_info (info) = bfd_alloc (dynobj, sizeof (gpinfo.g));
5677 if (!_frvfdpic_size_got_plt (output_bfd, &gpinfo))
5680 if (elf_hash_table (info)->dynamic_sections_created)
5682 if (frvfdpic_got_section (info)->size)
5683 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0))
5686 if (frvfdpic_pltrel_section (info)->size)
5687 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
5688 || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_REL)
5689 || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
5692 if (frvfdpic_gotrel_section (info)->size)
5693 if (!_bfd_elf_add_dynamic_entry (info, DT_REL, 0)
5694 || !_bfd_elf_add_dynamic_entry (info, DT_RELSZ, 0)
5695 || !_bfd_elf_add_dynamic_entry (info, DT_RELENT,
5696 sizeof (Elf32_External_Rel)))
5704 elf32_frvfdpic_always_size_sections (bfd *output_bfd,
5705 struct bfd_link_info *info)
5707 if (!info->relocatable)
5709 struct elf_link_hash_entry *h;
5712 /* Force a PT_GNU_STACK segment to be created. */
5713 if (! elf_tdata (output_bfd)->stack_flags)
5714 elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
5716 /* Define __stacksize if it's not defined yet. */
5717 h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize",
5718 FALSE, FALSE, FALSE);
5719 if (! h || h->root.type != bfd_link_hash_defined
5720 || h->type != STT_OBJECT
5723 struct bfd_link_hash_entry *bh = NULL;
5725 if (!(_bfd_generic_link_add_one_symbol
5726 (info, output_bfd, "__stacksize",
5727 BSF_GLOBAL, bfd_abs_section_ptr, DEFAULT_STACK_SIZE,
5728 (const char *) NULL, FALSE,
5729 get_elf_backend_data (output_bfd)->collect, &bh)))
5732 h = (struct elf_link_hash_entry *) bh;
5734 h->type = STT_OBJECT;
5735 /* This one must NOT be hidden. */
5738 /* Create a stack section, and set its alignment. */
5739 sec = bfd_make_section (output_bfd, ".stack");
5742 || ! bfd_set_section_alignment (output_bfd, sec, 3))
5749 /* Look for opportunities to relax TLS relocations. We can assume
5750 we're linking the main executable or a static-tls library, since
5751 otherwise we wouldn't have got here. */
5754 _frvfdpic_relax_got_plt_entries (void **entryp, void *dinfo_)
5756 struct frvfdpic_relocs_info *entry = *entryp;
5757 struct _frvfdpic_dynamic_got_info *dinfo = dinfo_;
5759 _frvfdpic_relax_tls_entries (entry, dinfo, TRUE);
5765 elf32_frvfdpic_relax_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
5766 struct bfd_link_info *info, bfd_boolean *again)
5768 struct _frvfdpic_dynamic_got_plt_info gpinfo;
5770 /* If we return early, we didn't change anything. */
5773 /* We'll do our thing when requested to relax the GOT section. */
5774 if (sec != frvfdpic_got_section (info))
5777 /* We can only relax when linking the main executable or a library
5778 that can't be dlopened. */
5779 if (! info->executable && ! (info->flags & DF_STATIC_TLS))
5782 /* If there isn't a TLS section for this binary, we can't do
5783 anything about its TLS relocations (it probably doesn't have
5785 if (elf_hash_table (info)->tls_sec == NULL)
5788 memset (&gpinfo, 0, sizeof (gpinfo));
5789 memcpy (&gpinfo.g, frvfdpic_dynamic_got_plt_info (info), sizeof (gpinfo.g));
5791 /* Now look for opportunities to relax, adjusting the GOT usage
5793 htab_traverse (frvfdpic_relocs_info (info),
5794 _frvfdpic_relax_got_plt_entries,
5797 /* If we changed anything, reset and re-assign GOT and PLT entries. */
5798 if (memcmp (frvfdpic_dynamic_got_plt_info (info),
5799 &gpinfo.g, sizeof (gpinfo.g)) != 0)
5801 /* Clear GOT and PLT assignments. */
5802 htab_traverse (frvfdpic_relocs_info (info),
5803 _frvfdpic_reset_got_plt_entries,
5806 /* The owner of the TLS section is the output bfd. There should
5807 be a better way to get to it. */
5808 if (!_frvfdpic_size_got_plt (elf_hash_table (info)->tls_sec->owner,
5812 /* Repeat until we don't make any further changes. We could fail to
5813 introduce changes in a round if, for example, the 12-bit range is
5814 full, but we later release some space by getting rid of TLS
5815 descriptors in it. We have to repeat the whole process because
5816 we might have changed the size of a section processed before this
5825 elf32_frvfdpic_modify_segment_map (bfd *output_bfd,
5826 struct bfd_link_info *info)
5828 struct elf_segment_map *m;
5830 /* objcopy and strip preserve what's already there using
5831 elf32_frvfdpic_copy_private_bfd_data (). */
5835 for (m = elf_tdata (output_bfd)->segment_map; m != NULL; m = m->next)
5836 if (m->p_type == PT_GNU_STACK)
5841 asection *sec = bfd_get_section_by_name (output_bfd, ".stack");
5842 struct elf_link_hash_entry *h;
5846 /* Obtain the pointer to the __stacksize symbol. */
5847 h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize",
5848 FALSE, FALSE, FALSE);
5849 while (h->root.type == bfd_link_hash_indirect
5850 || h->root.type == bfd_link_hash_warning)
5851 h = (struct elf_link_hash_entry *)h->root.u.i.link;
5852 BFD_ASSERT (h->root.type == bfd_link_hash_defined);
5854 /* Set the section size from the symbol value. We
5855 intentionally ignore the symbol section. */
5856 if (h->root.type == bfd_link_hash_defined)
5857 sec->size = h->root.u.def.value;
5859 sec->size = DEFAULT_STACK_SIZE;
5861 /* Add the stack section to the PT_GNU_STACK segment,
5862 such that its size and alignment requirements make it
5864 m->sections[m->count] = sec;
5872 /* Fill in code and data in dynamic sections. */
5875 elf32_frv_finish_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
5876 struct bfd_link_info *info ATTRIBUTE_UNUSED)
5878 /* Nothing to be done for non-FDPIC. */
5883 elf32_frvfdpic_finish_dynamic_sections (bfd *output_bfd,
5884 struct bfd_link_info *info)
5889 dynobj = elf_hash_table (info)->dynobj;
5891 if (frvfdpic_dynamic_got_plt_info (info))
5893 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs == 0);
5895 if (frvfdpic_got_section (info))
5897 BFD_ASSERT (frvfdpic_gotrel_section (info)->size
5898 == (frvfdpic_gotrel_section (info)->reloc_count
5899 * sizeof (Elf32_External_Rel)));
5901 if (frvfdpic_gotfixup_section (info))
5903 struct elf_link_hash_entry *hgot = elf_hash_table (info)->hgot;
5904 bfd_vma got_value = hgot->root.u.def.value
5905 + hgot->root.u.def.section->output_section->vma
5906 + hgot->root.u.def.section->output_offset;
5907 struct bfd_link_hash_entry *hend;
5909 _frvfdpic_add_rofixup (output_bfd, frvfdpic_gotfixup_section (info),
5912 if (frvfdpic_gotfixup_section (info)->size
5913 != (frvfdpic_gotfixup_section (info)->reloc_count * 4))
5916 (*_bfd_error_handler)
5917 ("LINKER BUG: .rofixup section size mismatch");
5921 hend = bfd_link_hash_lookup (info->hash, "__ROFIXUP_END__",
5922 FALSE, FALSE, TRUE);
5924 && (hend->type == bfd_link_hash_defined
5925 || hend->type == bfd_link_hash_defweak))
5928 frvfdpic_gotfixup_section (info)->output_section->vma
5929 + frvfdpic_gotfixup_section (info)->output_offset
5930 + frvfdpic_gotfixup_section (info)->size
5931 - hend->u.def.section->output_section->vma
5932 - hend->u.def.section->output_offset;
5933 BFD_ASSERT (hend->u.def.value == value);
5934 if (hend->u.def.value != value)
5939 if (frvfdpic_pltrel_section (info))
5941 BFD_ASSERT (frvfdpic_pltrel_section (info)->size
5942 == (frvfdpic_pltrel_section (info)->reloc_count
5943 * sizeof (Elf32_External_Rel)));
5947 if (elf_hash_table (info)->dynamic_sections_created)
5949 Elf32_External_Dyn * dyncon;
5950 Elf32_External_Dyn * dynconend;
5952 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
5954 BFD_ASSERT (sdyn != NULL);
5956 dyncon = (Elf32_External_Dyn *) sdyn->contents;
5957 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
5959 for (; dyncon < dynconend; dyncon++)
5961 Elf_Internal_Dyn dyn;
5963 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
5971 dyn.d_un.d_ptr = frvfdpic_got_section (info)->output_section->vma
5972 + frvfdpic_got_section (info)->output_offset
5973 + frvfdpic_got_initial_offset (info);
5974 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5978 dyn.d_un.d_ptr = frvfdpic_pltrel_section (info)
5979 ->output_section->vma
5980 + frvfdpic_pltrel_section (info)->output_offset;
5981 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5985 dyn.d_un.d_val = frvfdpic_pltrel_section (info)->size;
5986 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5995 /* Adjust a symbol defined by a dynamic object and referenced by a
5999 elf32_frvfdpic_adjust_dynamic_symbol
6000 (struct bfd_link_info *info ATTRIBUTE_UNUSED,
6001 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
6005 dynobj = elf_hash_table (info)->dynobj;
6007 /* Make sure we know what is going on here. */
6008 BFD_ASSERT (dynobj != NULL
6009 && (h->u.weakdef != NULL
6012 && !h->def_regular)));
6014 /* If this is a weak symbol, and there is a real definition, the
6015 processor independent code will have arranged for us to see the
6016 real definition first, and we can just use the same value. */
6017 if (h->u.weakdef != NULL)
6019 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
6020 || h->u.weakdef->root.type == bfd_link_hash_defweak);
6021 h->root.u.def.section = h->u.weakdef->root.u.def.section;
6022 h->root.u.def.value = h->u.weakdef->root.u.def.value;
6028 /* Perform any actions needed for dynamic symbols. */
6031 elf32_frvfdpic_finish_dynamic_symbol
6032 (bfd *output_bfd ATTRIBUTE_UNUSED,
6033 struct bfd_link_info *info ATTRIBUTE_UNUSED,
6034 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED,
6035 Elf_Internal_Sym *sym ATTRIBUTE_UNUSED)
6040 /* Decide whether to attempt to turn absptr or lsda encodings in
6041 shared libraries into pcrel within the given input section. */
6044 frvfdpic_elf_use_relative_eh_frame
6045 (bfd *input_bfd ATTRIBUTE_UNUSED,
6046 struct bfd_link_info *info ATTRIBUTE_UNUSED,
6047 asection *eh_frame_section ATTRIBUTE_UNUSED)
6049 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
6053 /* Adjust the contents of an eh_frame_hdr section before they're output. */
6056 frvfdpic_elf_encode_eh_address (bfd *abfd,
6057 struct bfd_link_info *info,
6058 asection *osec, bfd_vma offset,
6059 asection *loc_sec, bfd_vma loc_offset,
6062 struct elf_link_hash_entry *h;
6064 h = elf_hash_table (info)->hgot;
6065 BFD_ASSERT (h && h->root.type == bfd_link_hash_defined);
6067 if (! h || (_frvfdpic_osec_to_segment (abfd, osec)
6068 == _frvfdpic_osec_to_segment (abfd, loc_sec->output_section)))
6069 return _bfd_elf_encode_eh_address (abfd, info, osec, offset,
6070 loc_sec, loc_offset, encoded);
6072 BFD_ASSERT (_frvfdpic_osec_to_segment (abfd, osec)
6073 == (_frvfdpic_osec_to_segment
6074 (abfd, h->root.u.def.section->output_section)));
6076 *encoded = osec->vma + offset
6077 - (h->root.u.def.value
6078 + h->root.u.def.section->output_section->vma
6079 + h->root.u.def.section->output_offset);
6081 return DW_EH_PE_datarel | DW_EH_PE_sdata4;
6084 /* Look through the relocs for a section during the first phase.
6086 Besides handling virtual table relocs for gc, we have to deal with
6087 all sorts of PIC-related relocations. We describe below the
6088 general plan on how to handle such relocations, even though we only
6089 collect information at this point, storing them in hash tables for
6090 perusal of later passes.
6092 32 relocations are propagated to the linker output when creating
6093 position-independent output. LO16 and HI16 relocations are not
6094 supposed to be encountered in this case.
6096 LABEL16 should always be resolvable by the linker, since it's only
6099 LABEL24, on the other hand, is used by calls. If it turns out that
6100 the target of a call is a dynamic symbol, a PLT entry must be
6101 created for it, which triggers the creation of a private function
6102 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
6104 GPREL relocations require the referenced symbol to be in the same
6105 segment as _gp, but this can only be checked later.
6107 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
6108 exist. LABEL24 might as well, since it may require a PLT entry,
6109 that will require a got.
6111 Non-FUNCDESC GOT relocations require a GOT entry to be created
6112 regardless of whether the symbol is dynamic. However, since a
6113 global symbol that turns out to not be exported may have the same
6114 address of a non-dynamic symbol, we don't assign GOT entries at
6115 this point, such that we can share them in this case. A relocation
6116 for the GOT entry always has to be created, be it to offset a
6117 private symbol by the section load address, be it to get the symbol
6118 resolved dynamically.
6120 FUNCDESC GOT relocations require a GOT entry to be created, and
6121 handled as if a FUNCDESC relocation was applied to the GOT entry in
6124 FUNCDESC relocations referencing a symbol that turns out to NOT be
6125 dynamic cause a private function descriptor to be created. The
6126 FUNCDESC relocation then decays to a 32 relocation that points at
6127 the private descriptor. If the symbol is dynamic, the FUNCDESC
6128 relocation is propagated to the linker output, such that the
6129 dynamic linker creates the canonical descriptor, pointing to the
6130 dynamically-resolved definition of the function.
6132 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
6133 symbols that are assigned to the same segment as the GOT, but we
6134 can only check this later, after we know the complete set of
6135 symbols defined and/or exported.
6137 FUNCDESC GOTOFF relocations require a function descriptor to be
6138 created and, unless lazy binding is disabled or the symbol is not
6139 dynamic, a lazy PLT entry. Since we can't tell at this point
6140 whether a symbol is going to be dynamic, we have to decide later
6141 whether to create a lazy PLT entry or bind the descriptor directly
6142 to the private function.
6144 FUNCDESC_VALUE relocations are not supposed to be present in object
6145 files, but they may very well be simply propagated to the linker
6146 output, since they have no side effect.
6149 A function descriptor always requires a FUNCDESC_VALUE relocation.
6150 Whether it's in .plt.rel or not depends on whether lazy binding is
6151 enabled and on whether the referenced symbol is dynamic.
6153 The existence of a lazy PLT requires the resolverStub lazy PLT
6154 entry to be present.
6157 As for assignment of GOT, PLT and lazy PLT entries, and private
6158 descriptors, we might do them all sequentially, but we can do
6159 better than that. For example, we can place GOT entries and
6160 private function descriptors referenced using 12-bit operands
6161 closer to the PIC register value, such that these relocations don't
6162 overflow. Those that are only referenced with LO16 relocations
6163 could come next, but we may as well place PLT-required function
6164 descriptors in the 12-bit range to make them shorter. Symbols
6165 referenced with LO16/HI16 may come next, but we may place
6166 additional function descriptors in the 16-bit range if we can
6167 reliably tell that we've already placed entries that are ever
6168 referenced with only LO16. PLT entries are therefore generated as
6169 small as possible, while not introducing relocation overflows in
6170 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
6171 generated before or after PLT entries, but not intermingled with
6172 them, such that we can have more lazy PLT entries in range for a
6173 branch to the resolverStub. The resolverStub should be emitted at
6174 the most distant location from the first lazy PLT entry such that
6175 it's still in range for a branch, or closer, if there isn't a need
6176 for so many lazy PLT entries. Additional lazy PLT entries may be
6177 emitted after the resolverStub, as long as branches are still in
6178 range. If the branch goes out of range, longer lazy PLT entries
6181 We could further optimize PLT and lazy PLT entries by giving them
6182 priority in assignment to closer-to-gr17 locations depending on the
6183 number of occurrences of references to them (assuming a function
6184 that's called more often is more important for performance, so its
6185 PLT entry should be faster), or taking hints from the compiler.
6186 Given infinite time and money... :-) */
6189 elf32_frv_check_relocs (abfd, info, sec, relocs)
6191 struct bfd_link_info *info;
6193 const Elf_Internal_Rela *relocs;
6195 Elf_Internal_Shdr *symtab_hdr;
6196 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
6197 const Elf_Internal_Rela *rel;
6198 const Elf_Internal_Rela *rel_end;
6200 struct frvfdpic_relocs_info *picrel;
6202 if (info->relocatable)
6205 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
6206 sym_hashes = elf_sym_hashes (abfd);
6207 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf32_External_Sym);
6208 if (!elf_bad_symtab (abfd))
6209 sym_hashes_end -= symtab_hdr->sh_info;
6211 dynobj = elf_hash_table (info)->dynobj;
6212 rel_end = relocs + sec->reloc_count;
6213 for (rel = relocs; rel < rel_end; rel++)
6215 struct elf_link_hash_entry *h;
6216 unsigned long r_symndx;
6218 r_symndx = ELF32_R_SYM (rel->r_info);
6219 if (r_symndx < symtab_hdr->sh_info)
6222 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6224 switch (ELF32_R_TYPE (rel->r_info))
6226 case R_FRV_GETTLSOFF:
6227 case R_FRV_TLSDESC_VALUE:
6228 case R_FRV_GOTTLSDESC12:
6229 case R_FRV_GOTTLSDESCHI:
6230 case R_FRV_GOTTLSDESCLO:
6231 case R_FRV_GOTTLSOFF12:
6232 case R_FRV_GOTTLSOFFHI:
6233 case R_FRV_GOTTLSOFFLO:
6238 case R_FRV_FUNCDESC_GOT12:
6239 case R_FRV_FUNCDESC_GOTHI:
6240 case R_FRV_FUNCDESC_GOTLO:
6241 case R_FRV_GOTOFF12:
6242 case R_FRV_GOTOFFHI:
6243 case R_FRV_GOTOFFLO:
6244 case R_FRV_FUNCDESC_GOTOFF12:
6245 case R_FRV_FUNCDESC_GOTOFFHI:
6246 case R_FRV_FUNCDESC_GOTOFFLO:
6247 case R_FRV_FUNCDESC:
6248 case R_FRV_FUNCDESC_VALUE:
6249 case R_FRV_TLSMOFF12:
6250 case R_FRV_TLSMOFFHI:
6251 case R_FRV_TLSMOFFLO:
6253 if (! IS_FDPIC (abfd))
6257 case R_FRV_GPRELU12:
6264 elf_hash_table (info)->dynobj = dynobj = abfd;
6265 if (! _frv_create_got_section (abfd, info))
6268 if (! IS_FDPIC (abfd))
6275 if (h->dynindx == -1)
6276 switch (ELF_ST_VISIBILITY (h->other))
6282 bfd_elf_link_record_dynamic_symbol (info, h);
6286 = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info),
6288 rel->r_addend, INSERT);
6291 picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
6292 (info), abfd, r_symndx,
6293 rel->r_addend, INSERT);
6303 switch (ELF32_R_TYPE (rel->r_info))
6306 if (IS_FDPIC (abfd))
6310 case R_FRV_FUNCDESC_VALUE:
6311 picrel->relocsfdv++;
6312 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
6317 if (! IS_FDPIC (abfd))
6321 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
6331 picrel->gothilo = 1;
6334 case R_FRV_FUNCDESC_GOT12:
6335 picrel->fdgot12 = 1;
6338 case R_FRV_FUNCDESC_GOTHI:
6339 case R_FRV_FUNCDESC_GOTLO:
6340 picrel->fdgothilo = 1;
6343 case R_FRV_GOTOFF12:
6344 case R_FRV_GOTOFFHI:
6345 case R_FRV_GOTOFFLO:
6349 case R_FRV_FUNCDESC_GOTOFF12:
6350 picrel->fdgoff12 = 1;
6353 case R_FRV_FUNCDESC_GOTOFFHI:
6354 case R_FRV_FUNCDESC_GOTOFFLO:
6355 picrel->fdgoffhilo = 1;
6358 case R_FRV_FUNCDESC:
6363 case R_FRV_GETTLSOFF:
6367 case R_FRV_TLSDESC_VALUE:
6368 picrel->relocstlsd++;
6371 case R_FRV_GOTTLSDESC12:
6372 picrel->tlsdesc12 = 1;
6375 case R_FRV_GOTTLSDESCHI:
6376 case R_FRV_GOTTLSDESCLO:
6377 picrel->tlsdeschilo = 1;
6380 case R_FRV_TLSMOFF12:
6381 case R_FRV_TLSMOFFHI:
6382 case R_FRV_TLSMOFFLO:
6386 case R_FRV_GOTTLSOFF12:
6387 picrel->tlsoff12 = 1;
6388 info->flags |= DF_STATIC_TLS;
6391 case R_FRV_GOTTLSOFFHI:
6392 case R_FRV_GOTTLSOFFLO:
6393 picrel->tlsoffhilo = 1;
6394 info->flags |= DF_STATIC_TLS;
6398 picrel->relocstlsoff++;
6399 info->flags |= DF_STATIC_TLS;
6402 /* This relocation describes the C++ object vtable hierarchy.
6403 Reconstruct it for later use during GC. */
6404 case R_FRV_GNU_VTINHERIT:
6405 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
6409 /* This relocation describes which C++ vtable entries are actually
6410 used. Record for later use during GC. */
6411 case R_FRV_GNU_VTENTRY:
6412 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
6420 case R_FRV_GPRELU12:
6424 case R_FRV_TLSDESC_RELAX:
6425 case R_FRV_GETTLSOFF_RELAX:
6426 case R_FRV_TLSOFF_RELAX:
6431 (*_bfd_error_handler)
6432 (_("%B: unsupported relocation type %i"),
6433 abfd, ELF32_R_TYPE (rel->r_info));
6442 /* Return the machine subcode from the ELF e_flags header. */
6445 elf32_frv_machine (abfd)
6448 switch (elf_elfheader (abfd)->e_flags & EF_FRV_CPU_MASK)
6451 case EF_FRV_CPU_FR550: return bfd_mach_fr550;
6452 case EF_FRV_CPU_FR500: return bfd_mach_fr500;
6453 case EF_FRV_CPU_FR450: return bfd_mach_fr450;
6454 case EF_FRV_CPU_FR405: return bfd_mach_fr400;
6455 case EF_FRV_CPU_FR400: return bfd_mach_fr400;
6456 case EF_FRV_CPU_FR300: return bfd_mach_fr300;
6457 case EF_FRV_CPU_SIMPLE: return bfd_mach_frvsimple;
6458 case EF_FRV_CPU_TOMCAT: return bfd_mach_frvtomcat;
6461 return bfd_mach_frv;
6464 /* Set the right machine number for a FRV ELF file. */
6467 elf32_frv_object_p (abfd)
6470 bfd_default_set_arch_mach (abfd, bfd_arch_frv, elf32_frv_machine (abfd));
6471 return (((elf_elfheader (abfd)->e_flags & EF_FRV_FDPIC) != 0)
6472 == (IS_FDPIC (abfd)));
6475 /* Function to set the ELF flag bits. */
6478 frv_elf_set_private_flags (abfd, flags)
6482 elf_elfheader (abfd)->e_flags = flags;
6483 elf_flags_init (abfd) = TRUE;
6487 /* Copy backend specific data from one object module to another. */
6490 frv_elf_copy_private_bfd_data (ibfd, obfd)
6494 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6495 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6498 BFD_ASSERT (!elf_flags_init (obfd)
6499 || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
6501 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
6502 elf_flags_init (obfd) = TRUE;
6506 /* Return true if the architecture described by elf header flag
6507 EXTENSION is an extension of the architecture described by BASE. */
6510 frv_elf_arch_extension_p (flagword base, flagword extension)
6512 if (base == extension)
6515 /* CPU_GENERIC code can be merged with code for a specific
6516 architecture, in which case the result is marked as being
6517 for the specific architecture. Everything is therefore
6518 an extension of CPU_GENERIC. */
6519 if (base == EF_FRV_CPU_GENERIC)
6522 if (extension == EF_FRV_CPU_FR450)
6523 if (base == EF_FRV_CPU_FR400 || base == EF_FRV_CPU_FR405)
6526 if (extension == EF_FRV_CPU_FR405)
6527 if (base == EF_FRV_CPU_FR400)
6534 elf32_frvfdpic_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
6538 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6539 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6542 if (! frv_elf_copy_private_bfd_data (ibfd, obfd))
6545 if (! elf_tdata (ibfd) || ! elf_tdata (ibfd)->phdr
6546 || ! elf_tdata (obfd) || ! elf_tdata (obfd)->phdr)
6549 /* Copy the stack size. */
6550 for (i = 0; i < elf_elfheader (ibfd)->e_phnum; i++)
6551 if (elf_tdata (ibfd)->phdr[i].p_type == PT_GNU_STACK)
6553 Elf_Internal_Phdr *iphdr = &elf_tdata (ibfd)->phdr[i];
6555 for (i = 0; i < elf_elfheader (obfd)->e_phnum; i++)
6556 if (elf_tdata (obfd)->phdr[i].p_type == PT_GNU_STACK)
6558 memcpy (&elf_tdata (obfd)->phdr[i], iphdr, sizeof (*iphdr));
6560 /* Rewrite the phdrs, since we're only called after they
6561 were first written. */
6562 if (bfd_seek (obfd, (bfd_signed_vma) get_elf_backend_data (obfd)
6563 ->s->sizeof_ehdr, SEEK_SET) != 0
6564 || get_elf_backend_data (obfd)->s
6565 ->write_out_phdrs (obfd, elf_tdata (obfd)->phdr,
6566 elf_elfheader (obfd)->e_phnum) != 0)
6577 /* Merge backend specific data from an object file to the output
6578 object file when linking. */
6581 frv_elf_merge_private_bfd_data (ibfd, obfd)
6585 flagword old_flags, old_partial;
6586 flagword new_flags, new_partial;
6587 bfd_boolean error = FALSE;
6591 new_opt[0] = old_opt[0] = '\0';
6592 new_flags = elf_elfheader (ibfd)->e_flags;
6593 old_flags = elf_elfheader (obfd)->e_flags;
6595 if (new_flags & EF_FRV_FDPIC)
6596 new_flags &= ~EF_FRV_PIC;
6599 (*_bfd_error_handler) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s",
6600 old_flags, new_flags, elf_flags_init (obfd) ? "yes" : "no",
6601 bfd_get_filename (ibfd));
6604 if (!elf_flags_init (obfd)) /* First call, no flags set. */
6606 elf_flags_init (obfd) = TRUE;
6607 old_flags = new_flags;
6610 else if (new_flags == old_flags) /* Compatible flags are ok. */
6613 else /* Possibly incompatible flags. */
6615 /* Warn if different # of gprs are used. Note, 0 means nothing is
6616 said about the size of gprs. */
6617 new_partial = (new_flags & EF_FRV_GPR_MASK);
6618 old_partial = (old_flags & EF_FRV_GPR_MASK);
6619 if (new_partial == old_partial)
6622 else if (new_partial == 0)
6625 else if (old_partial == 0)
6626 old_flags |= new_partial;
6630 switch (new_partial)
6632 default: strcat (new_opt, " -mgpr-??"); break;
6633 case EF_FRV_GPR_32: strcat (new_opt, " -mgpr-32"); break;
6634 case EF_FRV_GPR_64: strcat (new_opt, " -mgpr-64"); break;
6637 switch (old_partial)
6639 default: strcat (old_opt, " -mgpr-??"); break;
6640 case EF_FRV_GPR_32: strcat (old_opt, " -mgpr-32"); break;
6641 case EF_FRV_GPR_64: strcat (old_opt, " -mgpr-64"); break;
6645 /* Warn if different # of fprs are used. Note, 0 means nothing is
6646 said about the size of fprs. */
6647 new_partial = (new_flags & EF_FRV_FPR_MASK);
6648 old_partial = (old_flags & EF_FRV_FPR_MASK);
6649 if (new_partial == old_partial)
6652 else if (new_partial == 0)
6655 else if (old_partial == 0)
6656 old_flags |= new_partial;
6660 switch (new_partial)
6662 default: strcat (new_opt, " -mfpr-?"); break;
6663 case EF_FRV_FPR_32: strcat (new_opt, " -mfpr-32"); break;
6664 case EF_FRV_FPR_64: strcat (new_opt, " -mfpr-64"); break;
6665 case EF_FRV_FPR_NONE: strcat (new_opt, " -msoft-float"); break;
6668 switch (old_partial)
6670 default: strcat (old_opt, " -mfpr-?"); break;
6671 case EF_FRV_FPR_32: strcat (old_opt, " -mfpr-32"); break;
6672 case EF_FRV_FPR_64: strcat (old_opt, " -mfpr-64"); break;
6673 case EF_FRV_FPR_NONE: strcat (old_opt, " -msoft-float"); break;
6677 /* Warn if different dword support was used. Note, 0 means nothing is
6678 said about the dword support. */
6679 new_partial = (new_flags & EF_FRV_DWORD_MASK);
6680 old_partial = (old_flags & EF_FRV_DWORD_MASK);
6681 if (new_partial == old_partial)
6684 else if (new_partial == 0)
6687 else if (old_partial == 0)
6688 old_flags |= new_partial;
6692 switch (new_partial)
6694 default: strcat (new_opt, " -mdword-?"); break;
6695 case EF_FRV_DWORD_YES: strcat (new_opt, " -mdword"); break;
6696 case EF_FRV_DWORD_NO: strcat (new_opt, " -mno-dword"); break;
6699 switch (old_partial)
6701 default: strcat (old_opt, " -mdword-?"); break;
6702 case EF_FRV_DWORD_YES: strcat (old_opt, " -mdword"); break;
6703 case EF_FRV_DWORD_NO: strcat (old_opt, " -mno-dword"); break;
6707 /* Or in flags that accumulate (ie, if one module uses it, mark that the
6709 old_flags |= new_flags & (EF_FRV_DOUBLE
6712 | EF_FRV_NON_PIC_RELOCS);
6714 /* If any module was compiled without -G0, clear the G0 bit. */
6715 old_flags = ((old_flags & ~ EF_FRV_G0)
6716 | (old_flags & new_flags & EF_FRV_G0));
6718 /* If any module was compiled without -mnopack, clear the mnopack bit. */
6719 old_flags = ((old_flags & ~ EF_FRV_NOPACK)
6720 | (old_flags & new_flags & EF_FRV_NOPACK));
6722 /* We don't have to do anything if the pic flags are the same, or the new
6723 module(s) were compiled with -mlibrary-pic. */
6724 new_partial = (new_flags & EF_FRV_PIC_FLAGS);
6725 old_partial = (old_flags & EF_FRV_PIC_FLAGS);
6726 if ((new_partial == old_partial) || ((new_partial & EF_FRV_LIBPIC) != 0))
6729 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
6730 flags if any from the new module. */
6731 else if ((old_partial & EF_FRV_LIBPIC) != 0)
6732 old_flags = (old_flags & ~ EF_FRV_PIC_FLAGS) | new_partial;
6734 /* If we have mixtures of -fpic and -fPIC, or in both bits. */
6735 else if (new_partial != 0 && old_partial != 0)
6736 old_flags |= new_partial;
6738 /* One module was compiled for pic and the other was not, see if we have
6739 had any relocations that are not pic-safe. */
6742 if ((old_flags & EF_FRV_NON_PIC_RELOCS) == 0)
6743 old_flags |= new_partial;
6746 old_flags &= ~ EF_FRV_PIC_FLAGS;
6747 #ifndef FRV_NO_PIC_ERROR
6749 (*_bfd_error_handler)
6750 (_("%s: compiled with %s and linked with modules that use non-pic relocations"),
6751 bfd_get_filename (ibfd),
6752 (new_flags & EF_FRV_BIGPIC) ? "-fPIC" : "-fpic");
6757 /* Warn if different cpu is used (allow a specific cpu to override
6758 the generic cpu). */
6759 new_partial = (new_flags & EF_FRV_CPU_MASK);
6760 old_partial = (old_flags & EF_FRV_CPU_MASK);
6761 if (frv_elf_arch_extension_p (new_partial, old_partial))
6764 else if (frv_elf_arch_extension_p (old_partial, new_partial))
6765 old_flags = (old_flags & ~EF_FRV_CPU_MASK) | new_partial;
6769 switch (new_partial)
6771 default: strcat (new_opt, " -mcpu=?"); break;
6772 case EF_FRV_CPU_GENERIC: strcat (new_opt, " -mcpu=frv"); break;
6773 case EF_FRV_CPU_SIMPLE: strcat (new_opt, " -mcpu=simple"); break;
6774 case EF_FRV_CPU_FR550: strcat (new_opt, " -mcpu=fr550"); break;
6775 case EF_FRV_CPU_FR500: strcat (new_opt, " -mcpu=fr500"); break;
6776 case EF_FRV_CPU_FR450: strcat (new_opt, " -mcpu=fr450"); break;
6777 case EF_FRV_CPU_FR405: strcat (new_opt, " -mcpu=fr405"); break;
6778 case EF_FRV_CPU_FR400: strcat (new_opt, " -mcpu=fr400"); break;
6779 case EF_FRV_CPU_FR300: strcat (new_opt, " -mcpu=fr300"); break;
6780 case EF_FRV_CPU_TOMCAT: strcat (new_opt, " -mcpu=tomcat"); break;
6783 switch (old_partial)
6785 default: strcat (old_opt, " -mcpu=?"); break;
6786 case EF_FRV_CPU_GENERIC: strcat (old_opt, " -mcpu=frv"); break;
6787 case EF_FRV_CPU_SIMPLE: strcat (old_opt, " -mcpu=simple"); break;
6788 case EF_FRV_CPU_FR550: strcat (old_opt, " -mcpu=fr550"); break;
6789 case EF_FRV_CPU_FR500: strcat (old_opt, " -mcpu=fr500"); break;
6790 case EF_FRV_CPU_FR450: strcat (old_opt, " -mcpu=fr450"); break;
6791 case EF_FRV_CPU_FR405: strcat (old_opt, " -mcpu=fr405"); break;
6792 case EF_FRV_CPU_FR400: strcat (old_opt, " -mcpu=fr400"); break;
6793 case EF_FRV_CPU_FR300: strcat (old_opt, " -mcpu=fr300"); break;
6794 case EF_FRV_CPU_TOMCAT: strcat (old_opt, " -mcpu=tomcat"); break;
6798 /* Print out any mismatches from above. */
6802 (*_bfd_error_handler)
6803 (_("%s: compiled with %s and linked with modules compiled with %s"),
6804 bfd_get_filename (ibfd), new_opt, old_opt);
6807 /* Warn about any other mismatches */
6808 new_partial = (new_flags & ~ EF_FRV_ALL_FLAGS);
6809 old_partial = (old_flags & ~ EF_FRV_ALL_FLAGS);
6810 if (new_partial != old_partial)
6812 old_flags |= new_partial;
6814 (*_bfd_error_handler)
6815 (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"),
6816 bfd_get_filename (ibfd), (long)new_partial, (long)old_partial);
6820 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
6821 if ((old_flags & EF_FRV_CPU_MASK) == EF_FRV_CPU_SIMPLE)
6822 old_flags |= EF_FRV_NOPACK;
6824 /* Update the old flags now with changes made above. */
6825 old_partial = elf_elfheader (obfd)->e_flags & EF_FRV_CPU_MASK;
6826 elf_elfheader (obfd)->e_flags = old_flags;
6827 if (old_partial != (old_flags & EF_FRV_CPU_MASK))
6828 bfd_default_set_arch_mach (obfd, bfd_arch_frv, elf32_frv_machine (obfd));
6830 if (((new_flags & EF_FRV_FDPIC) == 0)
6831 != (! IS_FDPIC (ibfd)))
6834 if (IS_FDPIC (obfd))
6835 (*_bfd_error_handler)
6836 (_("%s: cannot link non-fdpic object file into fdpic executable"),
6837 bfd_get_filename (ibfd));
6839 (*_bfd_error_handler)
6840 (_("%s: cannot link fdpic object file into non-fdpic executable"),
6841 bfd_get_filename (ibfd));
6845 bfd_set_error (bfd_error_bad_value);
6852 frv_elf_print_private_bfd_data (abfd, ptr)
6856 FILE *file = (FILE *) ptr;
6859 BFD_ASSERT (abfd != NULL && ptr != NULL);
6861 /* Print normal ELF private data. */
6862 _bfd_elf_print_private_bfd_data (abfd, ptr);
6864 flags = elf_elfheader (abfd)->e_flags;
6865 fprintf (file, _("private flags = 0x%lx:"), (long)flags);
6867 switch (flags & EF_FRV_CPU_MASK)
6870 case EF_FRV_CPU_SIMPLE: fprintf (file, " -mcpu=simple"); break;
6871 case EF_FRV_CPU_FR550: fprintf (file, " -mcpu=fr550"); break;
6872 case EF_FRV_CPU_FR500: fprintf (file, " -mcpu=fr500"); break;
6873 case EF_FRV_CPU_FR450: fprintf (file, " -mcpu=fr450"); break;
6874 case EF_FRV_CPU_FR405: fprintf (file, " -mcpu=fr405"); break;
6875 case EF_FRV_CPU_FR400: fprintf (file, " -mcpu=fr400"); break;
6876 case EF_FRV_CPU_FR300: fprintf (file, " -mcpu=fr300"); break;
6877 case EF_FRV_CPU_TOMCAT: fprintf (file, " -mcpu=tomcat"); break;
6880 switch (flags & EF_FRV_GPR_MASK)
6883 case EF_FRV_GPR_32: fprintf (file, " -mgpr-32"); break;
6884 case EF_FRV_GPR_64: fprintf (file, " -mgpr-64"); break;
6887 switch (flags & EF_FRV_FPR_MASK)
6890 case EF_FRV_FPR_32: fprintf (file, " -mfpr-32"); break;
6891 case EF_FRV_FPR_64: fprintf (file, " -mfpr-64"); break;
6892 case EF_FRV_FPR_NONE: fprintf (file, " -msoft-float"); break;
6895 switch (flags & EF_FRV_DWORD_MASK)
6898 case EF_FRV_DWORD_YES: fprintf (file, " -mdword"); break;
6899 case EF_FRV_DWORD_NO: fprintf (file, " -mno-dword"); break;
6902 if (flags & EF_FRV_DOUBLE)
6903 fprintf (file, " -mdouble");
6905 if (flags & EF_FRV_MEDIA)
6906 fprintf (file, " -mmedia");
6908 if (flags & EF_FRV_MULADD)
6909 fprintf (file, " -mmuladd");
6911 if (flags & EF_FRV_PIC)
6912 fprintf (file, " -fpic");
6914 if (flags & EF_FRV_BIGPIC)
6915 fprintf (file, " -fPIC");
6917 if (flags & EF_FRV_LIBPIC)
6918 fprintf (file, " -mlibrary-pic");
6920 if (flags & EF_FRV_FDPIC)
6921 fprintf (file, " -mfdpic");
6923 if (flags & EF_FRV_NON_PIC_RELOCS)
6924 fprintf (file, " non-pic relocations");
6926 if (flags & EF_FRV_G0)
6927 fprintf (file, " -G0");
6934 #define ELF_ARCH bfd_arch_frv
6935 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
6936 #define ELF_MAXPAGESIZE 0x1000
6938 #define TARGET_BIG_SYM bfd_elf32_frv_vec
6939 #define TARGET_BIG_NAME "elf32-frv"
6941 #define elf_info_to_howto frv_info_to_howto_rela
6942 #define elf_backend_relocate_section elf32_frv_relocate_section
6943 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
6944 #define elf_backend_gc_sweep_hook elf32_frv_gc_sweep_hook
6945 #define elf_backend_check_relocs elf32_frv_check_relocs
6946 #define elf_backend_object_p elf32_frv_object_p
6947 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
6949 #define elf_backend_can_gc_sections 1
6950 #define elf_backend_rela_normal 1
6952 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
6953 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
6954 #define bfd_elf32_bfd_copy_private_bfd_data frv_elf_copy_private_bfd_data
6955 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
6956 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
6958 #define elf_backend_want_got_sym 1
6959 #define elf_backend_got_header_size 0
6960 #define elf_backend_want_got_plt 0
6961 #define elf_backend_plt_readonly 1
6962 #define elf_backend_want_plt_sym 0
6963 #define elf_backend_plt_header_size 0
6965 #define elf_backend_finish_dynamic_sections \
6966 elf32_frv_finish_dynamic_sections
6968 #include "elf32-target.h"
6970 #undef ELF_MAXPAGESIZE
6971 #define ELF_MAXPAGESIZE 0x4000
6973 #undef TARGET_BIG_SYM
6974 #define TARGET_BIG_SYM bfd_elf32_frvfdpic_vec
6975 #undef TARGET_BIG_NAME
6976 #define TARGET_BIG_NAME "elf32-frvfdpic"
6978 #define elf32_bed elf32_frvfdpic_bed
6980 #undef elf_info_to_howto_rel
6981 #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel
6983 #undef bfd_elf32_bfd_link_hash_table_create
6984 #define bfd_elf32_bfd_link_hash_table_create \
6985 frvfdpic_elf_link_hash_table_create
6986 #undef elf_backend_always_size_sections
6987 #define elf_backend_always_size_sections \
6988 elf32_frvfdpic_always_size_sections
6989 #undef elf_backend_modify_segment_map
6990 #define elf_backend_modify_segment_map \
6991 elf32_frvfdpic_modify_segment_map
6992 #undef bfd_elf32_bfd_copy_private_bfd_data
6993 #define bfd_elf32_bfd_copy_private_bfd_data \
6994 elf32_frvfdpic_copy_private_bfd_data
6996 #undef elf_backend_create_dynamic_sections
6997 #define elf_backend_create_dynamic_sections \
6998 elf32_frvfdpic_create_dynamic_sections
6999 #undef elf_backend_adjust_dynamic_symbol
7000 #define elf_backend_adjust_dynamic_symbol \
7001 elf32_frvfdpic_adjust_dynamic_symbol
7002 #undef elf_backend_size_dynamic_sections
7003 #define elf_backend_size_dynamic_sections \
7004 elf32_frvfdpic_size_dynamic_sections
7005 #undef bfd_elf32_bfd_relax_section
7006 #define bfd_elf32_bfd_relax_section \
7007 elf32_frvfdpic_relax_section
7008 #undef elf_backend_finish_dynamic_symbol
7009 #define elf_backend_finish_dynamic_symbol \
7010 elf32_frvfdpic_finish_dynamic_symbol
7011 #undef elf_backend_finish_dynamic_sections
7012 #define elf_backend_finish_dynamic_sections \
7013 elf32_frvfdpic_finish_dynamic_sections
7015 #undef elf_backend_can_make_relative_eh_frame
7016 #define elf_backend_can_make_relative_eh_frame \
7017 frvfdpic_elf_use_relative_eh_frame
7018 #undef elf_backend_can_make_lsda_relative_eh_frame
7019 #define elf_backend_can_make_lsda_relative_eh_frame \
7020 frvfdpic_elf_use_relative_eh_frame
7021 #undef elf_backend_encode_eh_address
7022 #define elf_backend_encode_eh_address \
7023 frvfdpic_elf_encode_eh_address
7025 #undef elf_backend_may_use_rel_p
7026 #define elf_backend_may_use_rel_p 1
7027 #undef elf_backend_may_use_rela_p
7028 #define elf_backend_may_use_rela_p 1
7029 /* We use REL for dynamic relocations only. */
7030 #undef elf_backend_default_use_rela_p
7031 #define elf_backend_default_use_rela_p 1
7033 #undef elf_backend_omit_section_dynsym
7034 #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym
7036 #include "elf32-target.h"