1 /* FRV-specific support for 32-bit ELF.
2 Copyright 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
26 #include "elf/dwarf2.h"
29 /* Forward declarations. */
30 static bfd_reloc_status_type elf32_frv_relocate_lo16
31 PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
32 static bfd_reloc_status_type elf32_frv_relocate_hi16
33 PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
34 static bfd_reloc_status_type elf32_frv_relocate_label24
35 PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
36 static bfd_reloc_status_type elf32_frv_relocate_gprel12
37 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
38 bfd_byte *, bfd_vma));
39 static bfd_reloc_status_type elf32_frv_relocate_gprelu12
40 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
41 bfd_byte *, bfd_vma));
42 static bfd_reloc_status_type elf32_frv_relocate_gprello
43 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
44 bfd_byte *, bfd_vma));
45 static bfd_reloc_status_type elf32_frv_relocate_gprelhi
46 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
47 bfd_byte *, bfd_vma));
48 static reloc_howto_type *frv_reloc_type_lookup
49 PARAMS ((bfd *, bfd_reloc_code_real_type));
50 static void frv_info_to_howto_rela
51 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
52 static bfd_boolean elf32_frv_relocate_section
53 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
54 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
55 static bfd_boolean elf32_frv_add_symbol_hook
56 PARAMS (( bfd *, struct bfd_link_info *, Elf_Internal_Sym *,
57 const char **, flagword *, asection **, bfd_vma *));
58 static bfd_reloc_status_type frv_final_link_relocate
59 PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *,
60 Elf_Internal_Rela *, bfd_vma));
61 static bfd_boolean elf32_frv_check_relocs
62 PARAMS ((bfd *, struct bfd_link_info *, asection *,
63 const Elf_Internal_Rela *));
64 static int elf32_frv_machine
66 static bfd_boolean elf32_frv_object_p
68 static bfd_boolean frv_elf_set_private_flags
69 PARAMS ((bfd *, flagword));
70 static bfd_boolean frv_elf_copy_private_bfd_data
71 PARAMS ((bfd *, bfd *));
72 static bfd_boolean frv_elf_merge_private_bfd_data
73 PARAMS ((bfd *, bfd *));
74 static bfd_boolean frv_elf_print_private_bfd_data
75 PARAMS ((bfd *, PTR));
76 static bfd_boolean elf32_frv_grok_prstatus (bfd * abfd,
77 Elf_Internal_Note * note);
78 static bfd_boolean elf32_frv_grok_psinfo (bfd * abfd,
79 Elf_Internal_Note * note);
81 static reloc_howto_type elf32_frv_howto_table [] =
83 /* This reloc does nothing. */
84 HOWTO (R_FRV_NONE, /* type */
86 2, /* size (0 = byte, 1 = short, 2 = long) */
88 FALSE, /* pc_relative */
90 complain_overflow_bitfield, /* complain_on_overflow */
91 bfd_elf_generic_reloc, /* special_function */
92 "R_FRV_NONE", /* name */
93 FALSE, /* partial_inplace */
96 FALSE), /* pcrel_offset */
98 /* A 32 bit absolute relocation. */
99 HOWTO (R_FRV_32, /* type */
101 2, /* size (0 = byte, 1 = short, 2 = long) */
103 FALSE, /* pc_relative */
105 complain_overflow_bitfield, /* complain_on_overflow */
106 bfd_elf_generic_reloc, /* special_function */
107 "R_FRV_32", /* name */
108 FALSE, /* partial_inplace */
109 0xffffffff, /* src_mask */
110 0xffffffff, /* dst_mask */
111 FALSE), /* pcrel_offset */
113 /* A 16 bit pc-relative relocation. */
114 HOWTO (R_FRV_LABEL16, /* type */
116 2, /* size (0 = byte, 1 = short, 2 = long) */
118 TRUE, /* pc_relative */
120 complain_overflow_signed, /* complain_on_overflow */
121 bfd_elf_generic_reloc, /* special_function */
122 "R_FRV_LABEL16", /* name */
123 FALSE, /* partial_inplace */
124 0xffff, /* src_mask */
125 0xffff, /* dst_mask */
126 TRUE), /* pcrel_offset */
128 /* A 24-bit pc-relative relocation. */
129 HOWTO (R_FRV_LABEL24, /* type */
131 2, /* size (0 = byte, 1 = short, 2 = long) */
133 TRUE, /* pc_relative */
135 complain_overflow_bitfield, /* complain_on_overflow */
136 bfd_elf_generic_reloc, /* special_function */
137 "R_FRV_LABEL24", /* name */
138 FALSE, /* partial_inplace */
139 0x7e03ffff, /* src_mask */
140 0x7e03ffff, /* dst_mask */
141 TRUE), /* pcrel_offset */
143 HOWTO (R_FRV_LO16, /* type */
145 2, /* size (0 = byte, 1 = short, 2 = long) */
147 FALSE, /* pc_relative */
149 complain_overflow_dont, /* complain_on_overflow */
150 bfd_elf_generic_reloc, /* special_function */
151 "R_FRV_LO16", /* name */
152 FALSE, /* partial_inplace */
153 0xffff, /* src_mask */
154 0xffff, /* dst_mask */
155 FALSE), /* pcrel_offset */
157 HOWTO (R_FRV_HI16, /* type */
159 2, /* size (0 = byte, 1 = short, 2 = long) */
161 FALSE, /* pc_relative */
163 complain_overflow_dont, /* complain_on_overflow */
164 bfd_elf_generic_reloc, /* special_function */
165 "R_FRV_HI16", /* name */
166 FALSE, /* partial_inplace */
167 0xffff, /* src_mask */
168 0xffff, /* dst_mask */
169 FALSE), /* pcrel_offset */
171 HOWTO (R_FRV_GPREL12, /* type */
173 2, /* size (0 = byte, 1 = short, 2 = long) */
175 FALSE, /* pc_relative */
177 complain_overflow_dont, /* complain_on_overflow */
178 bfd_elf_generic_reloc, /* special_function */
179 "R_FRV_GPREL12", /* name */
180 FALSE, /* partial_inplace */
181 0xfff, /* src_mask */
182 0xfff, /* dst_mask */
183 FALSE), /* pcrel_offset */
185 HOWTO (R_FRV_GPRELU12, /* type */
187 2, /* size (0 = byte, 1 = short, 2 = long) */
189 FALSE, /* pc_relative */
191 complain_overflow_dont, /* complain_on_overflow */
192 bfd_elf_generic_reloc, /* special_function */
193 "R_FRV_GPRELU12", /* name */
194 FALSE, /* partial_inplace */
195 0xfff, /* src_mask */
196 0x3f03f, /* dst_mask */
197 FALSE), /* pcrel_offset */
199 HOWTO (R_FRV_GPREL32, /* type */
201 2, /* size (0 = byte, 1 = short, 2 = long) */
203 FALSE, /* pc_relative */
205 complain_overflow_dont, /* complain_on_overflow */
206 bfd_elf_generic_reloc, /* special_function */
207 "R_FRV_GPREL32", /* name */
208 FALSE, /* partial_inplace */
209 0xffffffff, /* src_mask */
210 0xffffffff, /* dst_mask */
211 FALSE), /* pcrel_offset */
213 HOWTO (R_FRV_GPRELHI, /* type */
215 2, /* size (0 = byte, 1 = short, 2 = long) */
217 FALSE, /* pc_relative */
219 complain_overflow_dont, /* complain_on_overflow */
220 bfd_elf_generic_reloc, /* special_function */
221 "R_FRV_GPRELHI", /* name */
222 FALSE, /* partial_inplace */
223 0xffff, /* src_mask */
224 0xffff, /* dst_mask */
225 FALSE), /* pcrel_offset */
227 HOWTO (R_FRV_GPRELLO, /* type */
229 2, /* size (0 = byte, 1 = short, 2 = long) */
231 FALSE, /* pc_relative */
233 complain_overflow_dont, /* complain_on_overflow */
234 bfd_elf_generic_reloc, /* special_function */
235 "R_FRV_GPRELLO", /* name */
236 FALSE, /* partial_inplace */
237 0xffff, /* src_mask */
238 0xffff, /* dst_mask */
239 FALSE), /* pcrel_offset */
241 /* A 12-bit signed operand with the GOT offset for the address of
243 HOWTO (R_FRV_GOT12, /* type */
245 2, /* size (0 = byte, 1 = short, 2 = long) */
247 FALSE, /* pc_relative */
249 complain_overflow_signed, /* complain_on_overflow */
250 bfd_elf_generic_reloc, /* special_function */
251 "R_FRV_GOT12", /* name */
252 FALSE, /* partial_inplace */
253 0xfff, /* src_mask */
254 0xfff, /* dst_mask */
255 FALSE), /* pcrel_offset */
257 /* The upper 16 bits of the GOT offset for the address of the
259 HOWTO (R_FRV_GOTHI, /* type */
261 2, /* size (0 = byte, 1 = short, 2 = long) */
263 FALSE, /* pc_relative */
265 complain_overflow_dont, /* complain_on_overflow */
266 bfd_elf_generic_reloc, /* special_function */
267 "R_FRV_GOTHI", /* name */
268 FALSE, /* partial_inplace */
269 0xffff, /* src_mask */
270 0xffff, /* dst_mask */
271 FALSE), /* pcrel_offset */
273 /* The lower 16 bits of the GOT offset for the address of the
275 HOWTO (R_FRV_GOTLO, /* type */
277 2, /* size (0 = byte, 1 = short, 2 = long) */
279 FALSE, /* pc_relative */
281 complain_overflow_dont, /* complain_on_overflow */
282 bfd_elf_generic_reloc, /* special_function */
283 "R_FRV_GOTLO", /* name */
284 FALSE, /* partial_inplace */
285 0xffff, /* src_mask */
286 0xffff, /* dst_mask */
287 FALSE), /* pcrel_offset */
289 /* The 32-bit address of the canonical descriptor of a function. */
290 HOWTO (R_FRV_FUNCDESC, /* type */
292 2, /* size (0 = byte, 1 = short, 2 = long) */
294 FALSE, /* pc_relative */
296 complain_overflow_bitfield, /* complain_on_overflow */
297 bfd_elf_generic_reloc, /* special_function */
298 "R_FRV_FUNCDESC", /* name */
299 FALSE, /* partial_inplace */
300 0xffffffff, /* src_mask */
301 0xffffffff, /* dst_mask */
302 FALSE), /* pcrel_offset */
304 /* A 12-bit signed operand with the GOT offset for the address of
305 canonical descriptor of a function. */
306 HOWTO (R_FRV_FUNCDESC_GOT12, /* type */
308 2, /* size (0 = byte, 1 = short, 2 = long) */
310 FALSE, /* pc_relative */
312 complain_overflow_signed, /* complain_on_overflow */
313 bfd_elf_generic_reloc, /* special_function */
314 "R_FRV_FUNCDESC_GOT12", /* name */
315 FALSE, /* partial_inplace */
316 0xfff, /* src_mask */
317 0xfff, /* dst_mask */
318 FALSE), /* pcrel_offset */
320 /* The upper 16 bits of the GOT offset for the address of the
321 canonical descriptor of a function. */
322 HOWTO (R_FRV_FUNCDESC_GOTHI, /* type */
324 2, /* size (0 = byte, 1 = short, 2 = long) */
326 FALSE, /* pc_relative */
328 complain_overflow_dont, /* complain_on_overflow */
329 bfd_elf_generic_reloc, /* special_function */
330 "R_FRV_FUNCDESC_GOTHI", /* name */
331 FALSE, /* partial_inplace */
332 0xffff, /* src_mask */
333 0xffff, /* dst_mask */
334 FALSE), /* pcrel_offset */
336 /* The lower 16 bits of the GOT offset for the address of the
337 canonical descriptor of a function. */
338 HOWTO (R_FRV_FUNCDESC_GOTLO, /* type */
340 2, /* size (0 = byte, 1 = short, 2 = long) */
342 FALSE, /* pc_relative */
344 complain_overflow_dont, /* complain_on_overflow */
345 bfd_elf_generic_reloc, /* special_function */
346 "R_FRV_FUNCDESC_GOTLO", /* name */
347 FALSE, /* partial_inplace */
348 0xffff, /* src_mask */
349 0xffff, /* dst_mask */
350 FALSE), /* pcrel_offset */
352 /* The 64-bit descriptor of a function. */
353 HOWTO (R_FRV_FUNCDESC_VALUE, /* type */
355 2, /* size (0 = byte, 1 = short, 2 = long) */
357 FALSE, /* pc_relative */
359 complain_overflow_bitfield, /* complain_on_overflow */
360 bfd_elf_generic_reloc, /* special_function */
361 "R_FRV_FUNCDESC_VALUE", /* name */
362 FALSE, /* partial_inplace */
363 0xffffffff, /* src_mask */
364 0xffffffff, /* dst_mask */
365 FALSE), /* pcrel_offset */
367 /* A 12-bit signed operand with the GOT offset for the address of
368 canonical descriptor of a function. */
369 HOWTO (R_FRV_FUNCDESC_GOTOFF12, /* type */
371 2, /* size (0 = byte, 1 = short, 2 = long) */
373 FALSE, /* pc_relative */
375 complain_overflow_signed, /* complain_on_overflow */
376 bfd_elf_generic_reloc, /* special_function */
377 "R_FRV_FUNCDESC_GOTOFF12", /* name */
378 FALSE, /* partial_inplace */
379 0xfff, /* src_mask */
380 0xfff, /* dst_mask */
381 FALSE), /* pcrel_offset */
383 /* The upper 16 bits of the GOT offset for the address of the
384 canonical descriptor of a function. */
385 HOWTO (R_FRV_FUNCDESC_GOTOFFHI, /* type */
387 2, /* size (0 = byte, 1 = short, 2 = long) */
389 FALSE, /* pc_relative */
391 complain_overflow_dont, /* complain_on_overflow */
392 bfd_elf_generic_reloc, /* special_function */
393 "R_FRV_FUNCDESC_GOTOFFHI", /* name */
394 FALSE, /* partial_inplace */
395 0xffff, /* src_mask */
396 0xffff, /* dst_mask */
397 FALSE), /* pcrel_offset */
399 /* The lower 16 bits of the GOT offset for the address of the
400 canonical descriptor of a function. */
401 HOWTO (R_FRV_FUNCDESC_GOTOFFLO, /* type */
403 2, /* size (0 = byte, 1 = short, 2 = long) */
405 FALSE, /* pc_relative */
407 complain_overflow_dont, /* complain_on_overflow */
408 bfd_elf_generic_reloc, /* special_function */
409 "R_FRV_FUNCDESC_GOTOFFLO", /* name */
410 FALSE, /* partial_inplace */
411 0xffff, /* src_mask */
412 0xffff, /* dst_mask */
413 FALSE), /* pcrel_offset */
415 /* A 12-bit signed operand with the GOT offset for the address of
417 HOWTO (R_FRV_GOTOFF12, /* type */
419 2, /* size (0 = byte, 1 = short, 2 = long) */
421 FALSE, /* pc_relative */
423 complain_overflow_signed, /* complain_on_overflow */
424 bfd_elf_generic_reloc, /* special_function */
425 "R_FRV_GOTOFF12", /* name */
426 FALSE, /* partial_inplace */
427 0xfff, /* src_mask */
428 0xfff, /* dst_mask */
429 FALSE), /* pcrel_offset */
431 /* The upper 16 bits of the GOT offset for the address of the
433 HOWTO (R_FRV_GOTOFFHI, /* type */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
437 FALSE, /* pc_relative */
439 complain_overflow_dont, /* complain_on_overflow */
440 bfd_elf_generic_reloc, /* special_function */
441 "R_FRV_GOTOFFHI", /* name */
442 FALSE, /* partial_inplace */
443 0xffff, /* src_mask */
444 0xffff, /* dst_mask */
445 FALSE), /* pcrel_offset */
447 /* The lower 16 bits of the GOT offset for the address of the
449 HOWTO (R_FRV_GOTOFFLO, /* type */
451 2, /* size (0 = byte, 1 = short, 2 = long) */
453 FALSE, /* pc_relative */
455 complain_overflow_dont, /* complain_on_overflow */
456 bfd_elf_generic_reloc, /* special_function */
457 "R_FRV_GOTOFFLO", /* name */
458 FALSE, /* partial_inplace */
459 0xffff, /* src_mask */
460 0xffff, /* dst_mask */
461 FALSE), /* pcrel_offset */
463 /* A 24-bit pc-relative relocation referencing the TLS PLT entry for
464 a thread-local symbol. If the symbol number is 0, it refers to
466 HOWTO (R_FRV_GETTLSOFF, /* type */
468 2, /* size (0 = byte, 1 = short, 2 = long) */
470 TRUE, /* pc_relative */
472 complain_overflow_bitfield, /* complain_on_overflow */
473 bfd_elf_generic_reloc, /* special_function */
474 "R_FRV_GETTLSOFF", /* name */
475 FALSE, /* partial_inplace */
476 0x7e03ffff, /* src_mask */
477 0x7e03ffff, /* dst_mask */
478 TRUE), /* pcrel_offset */
480 /* A 64-bit TLS descriptor for a symbol. This relocation is only
481 valid as a REL, dynamic relocation. */
482 HOWTO (R_FRV_TLSDESC_VALUE, /* type */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
486 FALSE, /* pc_relative */
488 complain_overflow_bitfield, /* complain_on_overflow */
489 bfd_elf_generic_reloc, /* special_function */
490 "R_FRV_TLSDESC_VALUE", /* name */
491 FALSE, /* partial_inplace */
492 0xffffffff, /* src_mask */
493 0xffffffff, /* dst_mask */
494 FALSE), /* pcrel_offset */
496 /* A 12-bit signed operand with the GOT offset for the TLS
497 descriptor of the symbol. */
498 HOWTO (R_FRV_GOTTLSDESC12, /* type */
500 2, /* size (0 = byte, 1 = short, 2 = long) */
502 FALSE, /* pc_relative */
504 complain_overflow_signed, /* complain_on_overflow */
505 bfd_elf_generic_reloc, /* special_function */
506 "R_FRV_GOTTLSDESC12", /* name */
507 FALSE, /* partial_inplace */
508 0xfff, /* src_mask */
509 0xfff, /* dst_mask */
510 FALSE), /* pcrel_offset */
512 /* The upper 16 bits of the GOT offset for the TLS descriptor of the
514 HOWTO (R_FRV_GOTTLSDESCHI, /* type */
516 2, /* size (0 = byte, 1 = short, 2 = long) */
518 FALSE, /* pc_relative */
520 complain_overflow_dont, /* complain_on_overflow */
521 bfd_elf_generic_reloc, /* special_function */
522 "R_FRV_GOTTLSDESCHI", /* name */
523 FALSE, /* partial_inplace */
524 0xffff, /* src_mask */
525 0xffff, /* dst_mask */
526 FALSE), /* pcrel_offset */
528 /* The lower 16 bits of the GOT offset for the TLS descriptor of the
530 HOWTO (R_FRV_GOTTLSDESCLO, /* type */
532 2, /* size (0 = byte, 1 = short, 2 = long) */
534 FALSE, /* pc_relative */
536 complain_overflow_dont, /* complain_on_overflow */
537 bfd_elf_generic_reloc, /* special_function */
538 "R_FRV_GOTTLSDESCLO", /* name */
539 FALSE, /* partial_inplace */
540 0xffff, /* src_mask */
541 0xffff, /* dst_mask */
542 FALSE), /* pcrel_offset */
544 /* A 12-bit signed operand with the offset from the module base
545 address to the thread-local symbol address. */
546 HOWTO (R_FRV_TLSMOFF12, /* type */
548 2, /* size (0 = byte, 1 = short, 2 = long) */
550 FALSE, /* pc_relative */
552 complain_overflow_signed, /* complain_on_overflow */
553 bfd_elf_generic_reloc, /* special_function */
554 "R_FRV_TLSMOFF12", /* name */
555 FALSE, /* partial_inplace */
556 0xfff, /* src_mask */
557 0xfff, /* dst_mask */
558 FALSE), /* pcrel_offset */
560 /* The upper 16 bits of the offset from the module base address to
561 the thread-local symbol address. */
562 HOWTO (R_FRV_TLSMOFFHI, /* type */
564 2, /* size (0 = byte, 1 = short, 2 = long) */
566 FALSE, /* pc_relative */
568 complain_overflow_dont, /* complain_on_overflow */
569 bfd_elf_generic_reloc, /* special_function */
570 "R_FRV_TLSMOFFHI", /* name */
571 FALSE, /* partial_inplace */
572 0xffff, /* src_mask */
573 0xffff, /* dst_mask */
574 FALSE), /* pcrel_offset */
576 /* The lower 16 bits of the offset from the module base address to
577 the thread-local symbol address. */
578 HOWTO (R_FRV_TLSMOFFLO, /* type */
580 2, /* size (0 = byte, 1 = short, 2 = long) */
582 FALSE, /* pc_relative */
584 complain_overflow_dont, /* complain_on_overflow */
585 bfd_elf_generic_reloc, /* special_function */
586 "R_FRV_TLSMOFFLO", /* name */
587 FALSE, /* partial_inplace */
588 0xffff, /* src_mask */
589 0xffff, /* dst_mask */
590 FALSE), /* pcrel_offset */
592 /* A 12-bit signed operand with the GOT offset for the TLSOFF entry
594 HOWTO (R_FRV_GOTTLSOFF12, /* type */
596 2, /* size (0 = byte, 1 = short, 2 = long) */
598 FALSE, /* pc_relative */
600 complain_overflow_signed, /* complain_on_overflow */
601 bfd_elf_generic_reloc, /* special_function */
602 "R_FRV_GOTTLSOFF12", /* name */
603 FALSE, /* partial_inplace */
604 0xfff, /* src_mask */
605 0xfff, /* dst_mask */
606 FALSE), /* pcrel_offset */
608 /* The upper 16 bits of the GOT offset for the TLSOFF entry for a
610 HOWTO (R_FRV_GOTTLSOFFHI, /* type */
612 2, /* size (0 = byte, 1 = short, 2 = long) */
614 FALSE, /* pc_relative */
616 complain_overflow_dont, /* complain_on_overflow */
617 bfd_elf_generic_reloc, /* special_function */
618 "R_FRV_GOTTLSOFFHI", /* name */
619 FALSE, /* partial_inplace */
620 0xffff, /* src_mask */
621 0xffff, /* dst_mask */
622 FALSE), /* pcrel_offset */
624 /* The lower 16 bits of the GOT offset for the TLSOFF entry for a
626 HOWTO (R_FRV_GOTTLSOFFLO, /* type */
628 2, /* size (0 = byte, 1 = short, 2 = long) */
630 FALSE, /* pc_relative */
632 complain_overflow_dont, /* complain_on_overflow */
633 bfd_elf_generic_reloc, /* special_function */
634 "R_FRV_GOTTLSOFFLO", /* name */
635 FALSE, /* partial_inplace */
636 0xffff, /* src_mask */
637 0xffff, /* dst_mask */
638 FALSE), /* pcrel_offset */
640 /* The 32-bit offset from the thread pointer (not the module base
641 address) to a thread-local symbol. */
642 HOWTO (R_FRV_TLSOFF, /* type */
644 2, /* size (0 = byte, 1 = short, 2 = long) */
646 FALSE, /* pc_relative */
648 complain_overflow_dont, /* complain_on_overflow */
649 bfd_elf_generic_reloc, /* special_function */
650 "R_FRV_TLSOFF", /* name */
651 FALSE, /* partial_inplace */
652 0xffffffff, /* src_mask */
653 0xffffffff, /* dst_mask */
654 FALSE), /* pcrel_offset */
656 /* An annotation for linker relaxation, that denotes the
657 symbol+addend whose TLS descriptor is referenced by the sum of
658 the two input registers of an ldd instruction. */
659 HOWTO (R_FRV_TLSDESC_RELAX, /* type */
661 2, /* size (0 = byte, 1 = short, 2 = long) */
663 FALSE, /* pc_relative */
665 complain_overflow_dont, /* complain_on_overflow */
666 bfd_elf_generic_reloc, /* special_function */
667 "R_FRV_TLSDESC_RELAX", /* name */
668 FALSE, /* partial_inplace */
671 FALSE), /* pcrel_offset */
673 /* An annotation for linker relaxation, that denotes the
674 symbol+addend whose TLS resolver entry point is given by the sum
675 of the two register operands of an calll instruction. */
676 HOWTO (R_FRV_GETTLSOFF_RELAX, /* type */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
680 FALSE, /* pc_relative */
682 complain_overflow_dont, /* complain_on_overflow */
683 bfd_elf_generic_reloc, /* special_function */
684 "R_FRV_GETTLSOFF_RELAX", /* name */
685 FALSE, /* partial_inplace */
688 FALSE), /* pcrel_offset */
690 /* An annotation for linker relaxation, that denotes the
691 symbol+addend whose TLS offset GOT entry is given by the sum of
692 the two input registers of an ld instruction. */
693 HOWTO (R_FRV_TLSOFF_RELAX, /* type */
695 2, /* size (0 = byte, 1 = short, 2 = long) */
697 FALSE, /* pc_relative */
699 complain_overflow_bitfield, /* complain_on_overflow */
700 bfd_elf_generic_reloc, /* special_function */
701 "R_FRV_TLSOFF_RELAX", /* name */
702 FALSE, /* partial_inplace */
705 FALSE), /* pcrel_offset */
707 /* A 32-bit offset from the module base address to
708 the thread-local symbol address. */
709 HOWTO (R_FRV_TLSMOFF, /* type */
711 2, /* size (0 = byte, 1 = short, 2 = long) */
713 FALSE, /* pc_relative */
715 complain_overflow_dont, /* complain_on_overflow */
716 bfd_elf_generic_reloc, /* special_function */
717 "R_FRV_TLSMOFF", /* name */
718 FALSE, /* partial_inplace */
719 0xffffffff, /* src_mask */
720 0xffffffff, /* dst_mask */
721 FALSE), /* pcrel_offset */
724 /* GNU extension to record C++ vtable hierarchy. */
725 static reloc_howto_type elf32_frv_vtinherit_howto =
726 HOWTO (R_FRV_GNU_VTINHERIT, /* type */
728 2, /* size (0 = byte, 1 = short, 2 = long) */
730 FALSE, /* pc_relative */
732 complain_overflow_dont, /* complain_on_overflow */
733 NULL, /* special_function */
734 "R_FRV_GNU_VTINHERIT", /* name */
735 FALSE, /* partial_inplace */
738 FALSE); /* pcrel_offset */
740 /* GNU extension to record C++ vtable member usage. */
741 static reloc_howto_type elf32_frv_vtentry_howto =
742 HOWTO (R_FRV_GNU_VTENTRY, /* type */
744 2, /* size (0 = byte, 1 = short, 2 = long) */
746 FALSE, /* pc_relative */
748 complain_overflow_dont, /* complain_on_overflow */
749 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
750 "R_FRV_GNU_VTENTRY", /* name */
751 FALSE, /* partial_inplace */
754 FALSE); /* pcrel_offset */
756 /* The following 3 relocations are REL. The only difference to the
757 entries in the table above are that partial_inplace is TRUE. */
758 static reloc_howto_type elf32_frv_rel_32_howto =
759 HOWTO (R_FRV_32, /* type */
761 2, /* size (0 = byte, 1 = short, 2 = long) */
763 FALSE, /* pc_relative */
765 complain_overflow_bitfield, /* complain_on_overflow */
766 bfd_elf_generic_reloc, /* special_function */
767 "R_FRV_32", /* name */
768 TRUE, /* partial_inplace */
769 0xffffffff, /* src_mask */
770 0xffffffff, /* dst_mask */
771 FALSE); /* pcrel_offset */
773 static reloc_howto_type elf32_frv_rel_funcdesc_howto =
774 HOWTO (R_FRV_FUNCDESC, /* type */
776 2, /* size (0 = byte, 1 = short, 2 = long) */
778 FALSE, /* pc_relative */
780 complain_overflow_bitfield, /* complain_on_overflow */
781 bfd_elf_generic_reloc, /* special_function */
782 "R_FRV_FUNCDESC", /* name */
783 TRUE, /* partial_inplace */
784 0xffffffff, /* src_mask */
785 0xffffffff, /* dst_mask */
786 FALSE); /* pcrel_offset */
788 static reloc_howto_type elf32_frv_rel_funcdesc_value_howto =
789 HOWTO (R_FRV_FUNCDESC_VALUE, /* type */
791 2, /* size (0 = byte, 1 = short, 2 = long) */
793 FALSE, /* pc_relative */
795 complain_overflow_bitfield, /* complain_on_overflow */
796 bfd_elf_generic_reloc, /* special_function */
797 "R_FRV_FUNCDESC_VALUE", /* name */
798 TRUE, /* partial_inplace */
799 0xffffffff, /* src_mask */
800 0xffffffff, /* dst_mask */
801 FALSE); /* pcrel_offset */
803 static reloc_howto_type elf32_frv_rel_tlsdesc_value_howto =
804 /* A 64-bit TLS descriptor for a symbol. The first word resolves to
805 an entry point, and the second resolves to a special argument.
806 If the symbol turns out to be in static TLS, the entry point is a
807 return instruction, and the special argument is the TLS offset
808 for the symbol. If it's in dynamic TLS, the entry point is a TLS
809 offset resolver, and the special argument is a pointer to a data
810 structure allocated by the dynamic loader, containing the GOT
811 address for the offset resolver, the module id, the offset within
812 the module, and anything else the TLS offset resolver might need
813 to determine the TLS offset for the symbol in the running
815 HOWTO (R_FRV_TLSDESC_VALUE, /* type */
817 2, /* size (0 = byte, 1 = short, 2 = long) */
819 FALSE, /* pc_relative */
821 complain_overflow_bitfield, /* complain_on_overflow */
822 bfd_elf_generic_reloc, /* special_function */
823 "R_FRV_TLSDESC_VALUE", /* name */
824 TRUE, /* partial_inplace */
825 0xffffffff, /* src_mask */
826 0xffffffff, /* dst_mask */
827 FALSE); /* pcrel_offset */
829 static reloc_howto_type elf32_frv_rel_tlsoff_howto =
830 /* The 32-bit offset from the thread pointer (not the module base
831 address) to a thread-local symbol. */
832 HOWTO (R_FRV_TLSOFF, /* type */
834 2, /* size (0 = byte, 1 = short, 2 = long) */
836 FALSE, /* pc_relative */
838 complain_overflow_bitfield, /* complain_on_overflow */
839 bfd_elf_generic_reloc, /* special_function */
840 "R_FRV_TLSOFF", /* name */
841 TRUE, /* partial_inplace */
842 0xffffffff, /* src_mask */
843 0xffffffff, /* dst_mask */
844 FALSE); /* pcrel_offset */
848 extern const bfd_target bfd_elf32_frvfdpic_vec;
849 #define IS_FDPIC(bfd) ((bfd)->xvec == &bfd_elf32_frvfdpic_vec)
851 /* An extension of the elf hash table data structure, containing some
852 additional FRV-specific data. */
853 struct frvfdpic_elf_link_hash_table
855 struct elf_link_hash_table elf;
857 /* A pointer to the .got section. */
859 /* A pointer to the .rel.got section. */
861 /* A pointer to the .rofixup section. */
863 /* A pointer to the .plt section. */
865 /* A pointer to the .rel.plt section. */
867 /* GOT base offset. */
869 /* Location of the first non-lazy PLT entry, i.e., the number of
870 bytes taken by lazy PLT entries. If locally-bound TLS
871 descriptors require a ret instruction, it will be placed at this
874 /* A hash table holding information about which symbols were
875 referenced with which PIC-related relocations. */
876 struct htab *relocs_info;
877 /* Summary reloc information collected by
878 _frvfdpic_count_got_plt_entries. */
879 struct _frvfdpic_dynamic_got_info *g;
882 /* Get the FRV ELF linker hash table from a link_info structure. */
884 #define frvfdpic_hash_table(info) \
885 ((struct frvfdpic_elf_link_hash_table *) ((info)->hash))
887 #define frvfdpic_got_section(info) \
888 (frvfdpic_hash_table (info)->sgot)
889 #define frvfdpic_gotrel_section(info) \
890 (frvfdpic_hash_table (info)->sgotrel)
891 #define frvfdpic_gotfixup_section(info) \
892 (frvfdpic_hash_table (info)->sgotfixup)
893 #define frvfdpic_plt_section(info) \
894 (frvfdpic_hash_table (info)->splt)
895 #define frvfdpic_pltrel_section(info) \
896 (frvfdpic_hash_table (info)->spltrel)
897 #define frvfdpic_relocs_info(info) \
898 (frvfdpic_hash_table (info)->relocs_info)
899 #define frvfdpic_got_initial_offset(info) \
900 (frvfdpic_hash_table (info)->got0)
901 #define frvfdpic_plt_initial_offset(info) \
902 (frvfdpic_hash_table (info)->plt0)
903 #define frvfdpic_dynamic_got_plt_info(info) \
904 (frvfdpic_hash_table (info)->g)
906 /* Currently it's the same, but if some day we have a reason to change
907 it, we'd better be using a different macro.
909 FIXME: if there's any TLS PLT entry that uses local-exec or
910 initial-exec models, we could use the ret at the end of any of them
911 instead of adding one more. */
912 #define frvfdpic_plt_tls_ret_offset(info) \
913 (frvfdpic_plt_initial_offset (info))
915 /* The name of the dynamic interpreter. This is put in the .interp
918 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
920 #define DEFAULT_STACK_SIZE 0x20000
922 /* This structure is used to collect the number of entries present in
923 each addressable range of the got. */
924 struct _frvfdpic_dynamic_got_info
926 /* Several bits of information about the current link. */
927 struct bfd_link_info *info;
928 /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit
930 bfd_vma got12, gotlos, gothilo;
931 /* Total GOT size needed for function descriptor entries within the 12-,
932 16- or 32-bit ranges. */
933 bfd_vma fd12, fdlos, fdhilo;
934 /* Total GOT size needed by function descriptor entries referenced
935 in PLT entries, that would be profitable to place in offsets
936 close to the PIC register. */
938 /* Total PLT size needed by lazy PLT entries. */
940 /* Total GOT size needed for TLS descriptor entries within the 12-,
941 16- or 32-bit ranges. */
942 bfd_vma tlsd12, tlsdlos, tlsdhilo;
943 /* Total GOT size needed by TLS descriptors referenced in PLT
944 entries, that would be profitable to place in offers close to the
947 /* Total PLT size needed by TLS lazy PLT entries. */
949 /* Number of relocations carried over from input object files. */
950 unsigned long relocs;
951 /* Number of fixups introduced by relocations in input object files. */
952 unsigned long fixups;
953 /* The number of fixups that reference the ret instruction added to
954 the PLT for locally-resolved TLS descriptors. */
955 unsigned long tls_ret_refs;
958 /* This structure is used to assign offsets to got entries, function
959 descriptors, plt entries and lazy plt entries. */
961 struct _frvfdpic_dynamic_got_plt_info
963 /* Summary information collected with _frvfdpic_count_got_plt_entries. */
964 struct _frvfdpic_dynamic_got_info g;
966 /* For each addressable range, we record a MAX (positive) and MIN
967 (negative) value. CUR is used to assign got entries, and it's
968 incremented from an initial positive value to MAX, then from MIN
969 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
970 assign function descriptors, and it's decreased from an initial
971 non-positive value to MIN, then from MAX down to CUR (unless CUR
972 wraps around first). All of MIN, MAX, CUR and FDCUR always point
973 to even words. ODD, if non-zero, indicates an odd word to be
974 used for the next got entry, otherwise CUR is used and
975 incremented by a pair of words, wrapping around when it reaches
976 MAX. FDCUR is decremented (and wrapped) before the next function
977 descriptor is chosen. FDPLT indicates the number of remaining
978 slots that can be used for function descriptors used only by PLT
981 TMAX, TMIN and TCUR are used to assign TLS descriptors. TCUR
982 starts as MAX, and grows up to TMAX, then wraps around to TMIN
983 and grows up to MIN. TLSDPLT indicates the number of remaining
984 slots that can be used for TLS descriptors used only by TLS PLT
986 struct _frvfdpic_dynamic_got_alloc_data
988 bfd_signed_vma max, cur, odd, fdcur, min;
989 bfd_signed_vma tmax, tcur, tmin;
990 bfd_vma fdplt, tlsdplt;
991 } got12, gotlos, gothilo;
994 /* Create an FRV ELF linker hash table. */
996 static struct bfd_link_hash_table *
997 frvfdpic_elf_link_hash_table_create (bfd *abfd)
999 struct frvfdpic_elf_link_hash_table *ret;
1000 bfd_size_type amt = sizeof (struct frvfdpic_elf_link_hash_table);
1002 ret = bfd_zalloc (abfd, amt);
1006 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
1007 _bfd_elf_link_hash_newfunc,
1008 sizeof (struct elf_link_hash_entry)))
1014 return &ret->elf.root;
1017 /* Decide whether a reference to a symbol can be resolved locally or
1018 not. If the symbol is protected, we want the local address, but
1019 its function descriptor must be assigned by the dynamic linker. */
1020 #define FRVFDPIC_SYM_LOCAL(INFO, H) \
1021 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
1022 || ! elf_hash_table (INFO)->dynamic_sections_created)
1023 #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \
1024 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
1026 /* This structure collects information on what kind of GOT, PLT or
1027 function descriptors are required by relocations that reference a
1029 struct frvfdpic_relocs_info
1031 /* The index of the symbol, as stored in the relocation r_info, if
1032 we have a local symbol; -1 otherwise. */
1036 /* The input bfd in which the symbol is defined, if it's a local
1039 /* If symndx == -1, the hash table entry corresponding to a global
1040 symbol (even if it turns out to bind locally, in which case it
1041 should ideally be replaced with section's symndx + addend). */
1042 struct elf_link_hash_entry *h;
1044 /* The addend of the relocation that references the symbol. */
1047 /* The fields above are used to identify an entry. The fields below
1048 contain information on how an entry is used and, later on, which
1049 locations it was assigned. */
1050 /* The following 3 fields record whether the symbol+addend above was
1051 ever referenced with a GOT relocation. The 12 suffix indicates a
1052 GOT12 relocation; los is used for GOTLO relocations that are not
1053 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
1058 /* Whether a FUNCDESC relocation references symbol+addend. */
1060 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
1062 unsigned fdgotlos:1;
1063 unsigned fdgothilo:1;
1064 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
1065 unsigned fdgoff12:1;
1066 unsigned fdgofflos:1;
1067 unsigned fdgoffhilo:1;
1068 /* Whether a GETTLSOFF relocation references symbol+addend. */
1070 /* FIXME: we should probably add tlspltdesc, tlspltoff and
1071 tlspltimm, to tell what kind of TLS PLT entry we're generating.
1072 We might instead just pre-compute flags telling whether the
1073 object is suitable for local exec, initial exec or general
1074 dynamic addressing, and use that all over the place. We could
1075 also try to do a better job of merging TLSOFF and TLSDESC entries
1076 in main executables, but perhaps we can get rid of TLSDESC
1077 entirely in them instead. */
1078 /* Whether a GOTTLSDESC relocation references symbol+addend. */
1079 unsigned tlsdesc12:1;
1080 unsigned tlsdesclos:1;
1081 unsigned tlsdeschilo:1;
1082 /* Whether a GOTTLSOFF relocation references symbol+addend. */
1083 unsigned tlsoff12:1;
1084 unsigned tlsofflos:1;
1085 unsigned tlsoffhilo:1;
1086 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
1087 GOTOFFHI relocations. The addend doesn't really matter, since we
1088 envision that this will only be used to check whether the symbol
1089 is mapped to the same segment as the got. */
1091 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
1093 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
1096 /* Whether we need a PLT entry for a symbol. Should be implied by
1098 (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */
1100 /* Whether a function descriptor should be created in this link unit
1101 for symbol+addend. Should be implied by something like:
1102 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
1103 || ((fd || fdgot12 || fdgotlos || fdgothilo)
1104 && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */
1106 /* Whether a lazy PLT entry is needed for this symbol+addend.
1107 Should be implied by something like:
1108 (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)
1109 && ! (info->flags & DF_BIND_NOW)) */
1111 /* Whether we've already emitted GOT relocations and PLT entries as
1112 needed for this symbol. */
1115 /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and
1116 R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing
1118 unsigned relocs32, relocsfd, relocsfdv, relocstlsd, relocstlsoff;
1120 /* The number of .rofixups entries and dynamic relocations allocated
1121 for this symbol, minus any that might have already been used. */
1122 unsigned fixups, dynrelocs;
1124 /* The offsets of the GOT entries assigned to symbol+addend, to the
1125 function descriptor's address, and to a function descriptor,
1126 respectively. Should be zero if unassigned. The offsets are
1127 counted from the value that will be assigned to the PIC register,
1128 not from the beginning of the .got section. */
1129 bfd_signed_vma got_entry, fdgot_entry, fd_entry;
1130 /* The offsets of the PLT entries assigned to symbol+addend,
1131 non-lazy and lazy, respectively. If unassigned, should be
1133 bfd_vma plt_entry, lzplt_entry;
1134 /* The offsets of the GOT entries for TLS offset and TLS descriptor. */
1135 bfd_signed_vma tlsoff_entry, tlsdesc_entry;
1136 /* The offset of the TLS offset PLT entry. */
1137 bfd_vma tlsplt_entry;
1140 /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */
1142 frvfdpic_relocs_info_hash (const void *entry_)
1144 const struct frvfdpic_relocs_info *entry = entry_;
1146 return (entry->symndx == -1
1147 ? (long) entry->d.h->root.root.hash
1148 : entry->symndx + (long) entry->d.abfd->id * 257) + entry->addend;
1151 /* Test whether the key fields of two frvfdpic_relocs_info entries are
1154 frvfdpic_relocs_info_eq (const void *entry1, const void *entry2)
1156 const struct frvfdpic_relocs_info *e1 = entry1;
1157 const struct frvfdpic_relocs_info *e2 = entry2;
1159 return e1->symndx == e2->symndx && e1->addend == e2->addend
1160 && (e1->symndx == -1 ? e1->d.h == e2->d.h : e1->d.abfd == e2->d.abfd);
1163 /* Find or create an entry in a hash table HT that matches the key
1164 fields of the given ENTRY. If it's not found, memory for a new
1165 entry is allocated in ABFD's obstack. */
1166 static struct frvfdpic_relocs_info *
1167 frvfdpic_relocs_info_find (struct htab *ht,
1169 const struct frvfdpic_relocs_info *entry,
1170 enum insert_option insert)
1172 struct frvfdpic_relocs_info **loc =
1173 (struct frvfdpic_relocs_info **) htab_find_slot (ht, entry, insert);
1181 *loc = bfd_zalloc (abfd, sizeof (**loc));
1186 (*loc)->symndx = entry->symndx;
1187 (*loc)->d = entry->d;
1188 (*loc)->addend = entry->addend;
1189 (*loc)->plt_entry = (bfd_vma)-1;
1190 (*loc)->lzplt_entry = (bfd_vma)-1;
1191 (*loc)->tlsplt_entry = (bfd_vma)-1;
1196 /* Obtain the address of the entry in HT associated with H's symbol +
1197 addend, creating a new entry if none existed. ABFD is only used
1198 for memory allocation purposes. */
1199 inline static struct frvfdpic_relocs_info *
1200 frvfdpic_relocs_info_for_global (struct htab *ht,
1202 struct elf_link_hash_entry *h,
1204 enum insert_option insert)
1206 struct frvfdpic_relocs_info entry;
1210 entry.addend = addend;
1212 return frvfdpic_relocs_info_find (ht, abfd, &entry, insert);
1215 /* Obtain the address of the entry in HT associated with the SYMNDXth
1216 local symbol of the input bfd ABFD, plus the addend, creating a new
1217 entry if none existed. */
1218 inline static struct frvfdpic_relocs_info *
1219 frvfdpic_relocs_info_for_local (struct htab *ht,
1223 enum insert_option insert)
1225 struct frvfdpic_relocs_info entry;
1227 entry.symndx = symndx;
1228 entry.d.abfd = abfd;
1229 entry.addend = addend;
1231 return frvfdpic_relocs_info_find (ht, abfd, &entry, insert);
1234 /* Merge fields set by check_relocs() of two entries that end up being
1235 mapped to the same (presumably global) symbol. */
1238 frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info *e2,
1239 struct frvfdpic_relocs_info const *e1)
1241 e2->got12 |= e1->got12;
1242 e2->gotlos |= e1->gotlos;
1243 e2->gothilo |= e1->gothilo;
1245 e2->fdgot12 |= e1->fdgot12;
1246 e2->fdgotlos |= e1->fdgotlos;
1247 e2->fdgothilo |= e1->fdgothilo;
1248 e2->fdgoff12 |= e1->fdgoff12;
1249 e2->fdgofflos |= e1->fdgofflos;
1250 e2->fdgoffhilo |= e1->fdgoffhilo;
1251 e2->tlsplt |= e1->tlsplt;
1252 e2->tlsdesc12 |= e1->tlsdesc12;
1253 e2->tlsdesclos |= e1->tlsdesclos;
1254 e2->tlsdeschilo |= e1->tlsdeschilo;
1255 e2->tlsoff12 |= e1->tlsoff12;
1256 e2->tlsofflos |= e1->tlsofflos;
1257 e2->tlsoffhilo |= e1->tlsoffhilo;
1258 e2->gotoff |= e1->gotoff;
1259 e2->call |= e1->call;
1263 /* Every block of 65535 lazy PLT entries shares a single call to the
1264 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
1265 32767, counting from 0). All other lazy PLT entries branch to it
1266 in a single instruction. */
1268 #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
1269 #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767)
1271 /* Add a dynamic relocation to the SRELOC section. */
1273 inline static bfd_vma
1274 _frvfdpic_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset,
1275 int reloc_type, long dynindx, bfd_vma addend,
1276 struct frvfdpic_relocs_info *entry)
1278 Elf_Internal_Rela outrel;
1279 bfd_vma reloc_offset;
1281 outrel.r_offset = offset;
1282 outrel.r_info = ELF32_R_INFO (dynindx, reloc_type);
1283 outrel.r_addend = addend;
1285 reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rel);
1286 BFD_ASSERT (reloc_offset < sreloc->size);
1287 bfd_elf32_swap_reloc_out (output_bfd, &outrel,
1288 sreloc->contents + reloc_offset);
1289 sreloc->reloc_count++;
1291 /* If the entry's index is zero, this relocation was probably to a
1292 linkonce section that got discarded. We reserved a dynamic
1293 relocation, but it was for another entry than the one we got at
1294 the time of emitting the relocation. Unfortunately there's no
1295 simple way for us to catch this situation, since the relocation
1296 is cleared right before calling relocate_section, at which point
1297 we no longer know what the relocation used to point to. */
1300 BFD_ASSERT (entry->dynrelocs > 0);
1304 return reloc_offset;
1307 /* Add a fixup to the ROFIXUP section. */
1310 _frvfdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset,
1311 struct frvfdpic_relocs_info *entry)
1313 bfd_vma fixup_offset;
1315 if (rofixup->flags & SEC_EXCLUDE)
1318 fixup_offset = rofixup->reloc_count * 4;
1319 if (rofixup->contents)
1321 BFD_ASSERT (fixup_offset < rofixup->size);
1322 bfd_put_32 (output_bfd, offset, rofixup->contents + fixup_offset);
1324 rofixup->reloc_count++;
1326 if (entry && entry->symndx)
1328 /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc
1330 BFD_ASSERT (entry->fixups > 0);
1334 return fixup_offset;
1337 /* Find the segment number in which OSEC, and output section, is
1341 _frvfdpic_osec_to_segment (bfd *output_bfd, asection *osec)
1343 struct elf_segment_map *m;
1344 Elf_Internal_Phdr *p;
1346 /* Find the segment that contains the output_section. */
1347 for (m = elf_tdata (output_bfd)->segment_map,
1348 p = elf_tdata (output_bfd)->phdr;
1354 for (i = m->count - 1; i >= 0; i--)
1355 if (m->sections[i] == osec)
1362 return p - elf_tdata (output_bfd)->phdr;
1365 inline static bfd_boolean
1366 _frvfdpic_osec_readonly_p (bfd *output_bfd, asection *osec)
1368 unsigned seg = _frvfdpic_osec_to_segment (output_bfd, osec);
1370 return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W);
1373 #define FRVFDPIC_TLS_BIAS (2048 - 16)
1375 /* Return the base VMA address which should be subtracted from real addresses
1376 when resolving TLSMOFF relocation.
1377 This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */
1380 tls_biased_base (struct bfd_link_info *info)
1382 /* If tls_sec is NULL, we should have signalled an error already. */
1383 if (elf_hash_table (info)->tls_sec == NULL)
1384 return FRVFDPIC_TLS_BIAS;
1385 return elf_hash_table (info)->tls_sec->vma + FRVFDPIC_TLS_BIAS;
1388 /* Generate relocations for GOT entries, function descriptors, and
1389 code for PLT and lazy PLT entries. */
1391 inline static bfd_boolean
1392 _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info *entry,
1394 struct bfd_link_info *info,
1396 Elf_Internal_Sym *sym,
1400 bfd_vma fd_lazy_rel_offset = (bfd_vma)-1;
1407 if (entry->got_entry || entry->fdgot_entry || entry->fd_entry
1408 || entry->tlsoff_entry || entry->tlsdesc_entry)
1410 /* If the symbol is dynamic, consider it for dynamic
1411 relocations, otherwise decay to section + offset. */
1412 if (entry->symndx == -1 && entry->d.h->dynindx != -1)
1413 dynindx = entry->d.h->dynindx;
1416 if (sec->output_section
1417 && ! bfd_is_abs_section (sec->output_section)
1418 && ! bfd_is_und_section (sec->output_section))
1419 dynindx = elf_section_data (sec->output_section)->dynindx;
1425 /* Generate relocation for GOT entry pointing to the symbol. */
1426 if (entry->got_entry)
1429 bfd_vma ad = addend;
1431 /* If the symbol is dynamic but binds locally, use
1433 if (sec && (entry->symndx != -1
1434 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1436 if (entry->symndx == -1)
1437 ad += entry->d.h->root.u.def.value;
1439 ad += sym->st_value;
1440 ad += sec->output_offset;
1441 if (sec->output_section && elf_section_data (sec->output_section))
1442 idx = elf_section_data (sec->output_section)->dynindx;
1447 /* If we're linking an executable at a fixed address, we can
1448 omit the dynamic relocation as long as the symbol is local to
1450 if (info->executable && !info->pie
1451 && (entry->symndx != -1
1452 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1455 ad += sec->output_section->vma;
1456 if (entry->symndx != -1
1457 || entry->d.h->root.type != bfd_link_hash_undefweak)
1458 _frvfdpic_add_rofixup (output_bfd,
1459 frvfdpic_gotfixup_section (info),
1460 frvfdpic_got_section (info)->output_section
1462 + frvfdpic_got_section (info)->output_offset
1463 + frvfdpic_got_initial_offset (info)
1464 + entry->got_entry, entry);
1467 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
1468 _bfd_elf_section_offset
1470 frvfdpic_got_section (info),
1471 frvfdpic_got_initial_offset (info)
1473 + frvfdpic_got_section (info)
1474 ->output_section->vma
1475 + frvfdpic_got_section (info)->output_offset,
1476 R_FRV_32, idx, ad, entry);
1478 bfd_put_32 (output_bfd, ad,
1479 frvfdpic_got_section (info)->contents
1480 + frvfdpic_got_initial_offset (info)
1481 + entry->got_entry);
1484 /* Generate relocation for GOT entry pointing to a canonical
1485 function descriptor. */
1486 if (entry->fdgot_entry)
1491 if (! (entry->symndx == -1
1492 && entry->d.h->root.type == bfd_link_hash_undefweak
1493 && FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1495 /* If the symbol is dynamic and there may be dynamic symbol
1496 resolution because we are, or are linked with, a shared
1497 library, emit a FUNCDESC relocation such that the dynamic
1498 linker will allocate the function descriptor. If the
1499 symbol needs a non-local function descriptor but binds
1500 locally (e.g., its visibility is protected, emit a
1501 dynamic relocation decayed to section+offset. */
1502 if (entry->symndx == -1
1503 && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)
1504 && FRVFDPIC_SYM_LOCAL (info, entry->d.h)
1505 && !(info->executable && !info->pie))
1507 reloc = R_FRV_FUNCDESC;
1508 idx = elf_section_data (entry->d.h->root.u.def.section
1509 ->output_section)->dynindx;
1510 ad = entry->d.h->root.u.def.section->output_offset
1511 + entry->d.h->root.u.def.value;
1513 else if (entry->symndx == -1
1514 && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h))
1516 reloc = R_FRV_FUNCDESC;
1521 (*info->callbacks->reloc_dangerous)
1522 (info, _("relocation requires zero addend"),
1523 elf_hash_table (info)->dynobj,
1524 frvfdpic_got_section (info),
1525 entry->fdgot_entry);
1531 /* Otherwise, we know we have a private function descriptor,
1532 so reference it directly. */
1533 if (elf_hash_table (info)->dynamic_sections_created)
1534 BFD_ASSERT (entry->privfd);
1536 idx = elf_section_data (frvfdpic_got_section (info)
1537 ->output_section)->dynindx;
1538 ad = frvfdpic_got_section (info)->output_offset
1539 + frvfdpic_got_initial_offset (info) + entry->fd_entry;
1542 /* If there is room for dynamic symbol resolution, emit the
1543 dynamic relocation. However, if we're linking an
1544 executable at a fixed location, we won't have emitted a
1545 dynamic symbol entry for the got section, so idx will be
1546 zero, which means we can and should compute the address
1547 of the private descriptor ourselves. */
1548 if (info->executable && !info->pie
1549 && (entry->symndx != -1
1550 || FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)))
1552 ad += frvfdpic_got_section (info)->output_section->vma;
1553 _frvfdpic_add_rofixup (output_bfd,
1554 frvfdpic_gotfixup_section (info),
1555 frvfdpic_got_section (info)
1556 ->output_section->vma
1557 + frvfdpic_got_section (info)
1559 + frvfdpic_got_initial_offset (info)
1560 + entry->fdgot_entry, entry);
1563 _frvfdpic_add_dyn_reloc (output_bfd,
1564 frvfdpic_gotrel_section (info),
1565 _bfd_elf_section_offset
1567 frvfdpic_got_section (info),
1568 frvfdpic_got_initial_offset (info)
1569 + entry->fdgot_entry)
1570 + frvfdpic_got_section (info)
1571 ->output_section->vma
1572 + frvfdpic_got_section (info)
1574 reloc, idx, ad, entry);
1577 bfd_put_32 (output_bfd, ad,
1578 frvfdpic_got_section (info)->contents
1579 + frvfdpic_got_initial_offset (info)
1580 + entry->fdgot_entry);
1583 /* Generate relocation to fill in a private function descriptor in
1585 if (entry->fd_entry)
1588 bfd_vma ad = addend;
1590 long lowword, highword;
1592 /* If the symbol is dynamic but binds locally, use
1594 if (sec && (entry->symndx != -1
1595 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1597 if (entry->symndx == -1)
1598 ad += entry->d.h->root.u.def.value;
1600 ad += sym->st_value;
1601 ad += sec->output_offset;
1602 if (sec->output_section && elf_section_data (sec->output_section))
1603 idx = elf_section_data (sec->output_section)->dynindx;
1608 /* If we're linking an executable at a fixed address, we can
1609 omit the dynamic relocation as long as the symbol is local to
1611 if (info->executable && !info->pie
1612 && (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1615 ad += sec->output_section->vma;
1617 if (entry->symndx != -1
1618 || entry->d.h->root.type != bfd_link_hash_undefweak)
1620 _frvfdpic_add_rofixup (output_bfd,
1621 frvfdpic_gotfixup_section (info),
1622 frvfdpic_got_section (info)
1623 ->output_section->vma
1624 + frvfdpic_got_section (info)
1626 + frvfdpic_got_initial_offset (info)
1627 + entry->fd_entry, entry);
1628 _frvfdpic_add_rofixup (output_bfd,
1629 frvfdpic_gotfixup_section (info),
1630 frvfdpic_got_section (info)
1631 ->output_section->vma
1632 + frvfdpic_got_section (info)
1634 + frvfdpic_got_initial_offset (info)
1635 + entry->fd_entry + 4, entry);
1641 _frvfdpic_add_dyn_reloc (output_bfd,
1643 ? frvfdpic_pltrel_section (info)
1644 : frvfdpic_gotrel_section (info),
1645 _bfd_elf_section_offset
1647 frvfdpic_got_section (info),
1648 frvfdpic_got_initial_offset (info)
1650 + frvfdpic_got_section (info)
1651 ->output_section->vma
1652 + frvfdpic_got_section (info)
1654 R_FRV_FUNCDESC_VALUE, idx, ad, entry);
1657 /* If we've omitted the dynamic relocation, just emit the fixed
1658 addresses of the symbol and of the local GOT base offset. */
1659 if (info->executable && !info->pie && sec && sec->output_section)
1662 highword = frvfdpic_got_section (info)->output_section->vma
1663 + frvfdpic_got_section (info)->output_offset
1664 + frvfdpic_got_initial_offset (info);
1666 else if (entry->lazyplt)
1670 (*info->callbacks->reloc_dangerous)
1671 (info, _("relocation requires zero addend"),
1672 elf_hash_table (info)->dynobj,
1673 frvfdpic_got_section (info),
1678 fd_lazy_rel_offset = ofst;
1680 /* A function descriptor used for lazy or local resolving is
1681 initialized such that its high word contains the output
1682 section index in which the PLT entries are located, and
1683 the low word contains the address of the lazy PLT entry
1684 entry point, that must be within the memory region
1685 assigned to that section. */
1686 lowword = entry->lzplt_entry + 4
1687 + frvfdpic_plt_section (info)->output_offset
1688 + frvfdpic_plt_section (info)->output_section->vma;
1689 highword = _frvfdpic_osec_to_segment
1690 (output_bfd, frvfdpic_plt_section (info)->output_section);
1694 /* A function descriptor for a local function gets the index
1695 of the section. For a non-local function, it's
1698 if (entry->symndx == -1 && entry->d.h->dynindx != -1
1699 && entry->d.h->dynindx == idx)
1702 highword = _frvfdpic_osec_to_segment
1703 (output_bfd, sec->output_section);
1706 bfd_put_32 (output_bfd, lowword,
1707 frvfdpic_got_section (info)->contents
1708 + frvfdpic_got_initial_offset (info)
1710 bfd_put_32 (output_bfd, highword,
1711 frvfdpic_got_section (info)->contents
1712 + frvfdpic_got_initial_offset (info)
1713 + entry->fd_entry + 4);
1716 /* Generate code for the PLT entry. */
1717 if (entry->plt_entry != (bfd_vma) -1)
1719 bfd_byte *plt_code = frvfdpic_plt_section (info)->contents
1722 BFD_ASSERT (entry->fd_entry);
1724 /* Figure out what kind of PLT entry we need, depending on the
1725 location of the function descriptor within the GOT. */
1726 if (entry->fd_entry >= -(1 << (12 - 1))
1727 && entry->fd_entry < (1 << (12 - 1)))
1729 /* lddi @(gr15, fd_entry), gr14 */
1730 bfd_put_32 (output_bfd,
1731 0x9cccf000 | (entry->fd_entry & ((1 << 12) - 1)),
1737 if (entry->fd_entry >= -(1 << (16 - 1))
1738 && entry->fd_entry < (1 << (16 - 1)))
1740 /* setlos lo(fd_entry), gr14 */
1741 bfd_put_32 (output_bfd,
1743 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
1749 /* sethi.p hi(fd_entry), gr14
1750 setlo lo(fd_entry), gr14 */
1751 bfd_put_32 (output_bfd,
1753 | ((entry->fd_entry >> 16)
1754 & (((bfd_vma)1 << 16) - 1)),
1757 bfd_put_32 (output_bfd,
1759 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
1763 /* ldd @(gr14,gr15),gr14 */
1764 bfd_put_32 (output_bfd, 0x9c08e14f, plt_code);
1767 /* jmpl @(gr14,gr0) */
1768 bfd_put_32 (output_bfd, 0x8030e000, plt_code);
1771 /* Generate code for the lazy PLT entry. */
1772 if (entry->lzplt_entry != (bfd_vma) -1)
1774 bfd_byte *lzplt_code = frvfdpic_plt_section (info)->contents
1775 + entry->lzplt_entry;
1776 bfd_vma resolverStub_addr;
1778 bfd_put_32 (output_bfd, fd_lazy_rel_offset, lzplt_code);
1781 resolverStub_addr = entry->lzplt_entry / FRVFDPIC_LZPLT_BLOCK_SIZE
1782 * FRVFDPIC_LZPLT_BLOCK_SIZE + FRVFDPIC_LZPLT_RESOLV_LOC;
1783 if (resolverStub_addr >= frvfdpic_plt_initial_offset (info))
1784 resolverStub_addr = frvfdpic_plt_initial_offset (info) - 12;
1786 if (entry->lzplt_entry == resolverStub_addr)
1788 /* This is a lazy PLT entry that includes a resolver call. */
1789 /* ldd @(gr15,gr0), gr4
1791 bfd_put_32 (output_bfd, 0x8808f140, lzplt_code);
1792 bfd_put_32 (output_bfd, 0x80304000, lzplt_code + 4);
1796 /* bra resolverStub */
1797 bfd_put_32 (output_bfd,
1799 | (((resolverStub_addr - entry->lzplt_entry)
1800 / 4) & (((bfd_vma)1 << 16) - 1)),
1805 /* Generate relocation for GOT entry holding the TLS offset. */
1806 if (entry->tlsoff_entry)
1809 bfd_vma ad = addend;
1811 if (entry->symndx != -1
1812 || FRVFDPIC_SYM_LOCAL (info, entry->d.h))
1814 /* If the symbol is dynamic but binds locally, use
1818 if (entry->symndx == -1)
1819 ad += entry->d.h->root.u.def.value;
1821 ad += sym->st_value;
1822 ad += sec->output_offset;
1823 if (sec->output_section
1824 && elf_section_data (sec->output_section))
1825 idx = elf_section_data (sec->output_section)->dynindx;
1831 /* *ABS*+addend is special for TLS relocations, use only the
1833 if (info->executable
1835 && (bfd_is_abs_section (sec)
1836 || bfd_is_und_section (sec)))
1838 /* If we're linking an executable, we can entirely omit the
1839 dynamic relocation if the symbol is local to this module. */
1840 else if (info->executable
1841 && (entry->symndx != -1
1842 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1845 ad += sec->output_section->vma - tls_biased_base (info);
1850 && (bfd_is_abs_section (sec)
1851 || bfd_is_und_section (sec)))
1853 if (! elf_hash_table (info)->tls_sec)
1855 (*info->callbacks->undefined_symbol)
1856 (info, "TLS section", elf_hash_table (info)->dynobj,
1857 frvfdpic_got_section (info), entry->tlsoff_entry, TRUE);
1860 idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx;
1861 ad += FRVFDPIC_TLS_BIAS;
1863 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
1864 _bfd_elf_section_offset
1866 frvfdpic_got_section (info),
1867 frvfdpic_got_initial_offset (info)
1868 + entry->tlsoff_entry)
1869 + frvfdpic_got_section (info)
1870 ->output_section->vma
1871 + frvfdpic_got_section (info)
1873 R_FRV_TLSOFF, idx, ad, entry);
1876 bfd_put_32 (output_bfd, ad,
1877 frvfdpic_got_section (info)->contents
1878 + frvfdpic_got_initial_offset (info)
1879 + entry->tlsoff_entry);
1882 if (entry->tlsdesc_entry)
1885 bfd_vma ad = addend;
1887 /* If the symbol is dynamic but binds locally, use
1889 if (sec && (entry->symndx != -1
1890 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1892 if (entry->symndx == -1)
1893 ad += entry->d.h->root.u.def.value;
1895 ad += sym->st_value;
1896 ad += sec->output_offset;
1897 if (sec->output_section && elf_section_data (sec->output_section))
1898 idx = elf_section_data (sec->output_section)->dynindx;
1903 /* If we didn't set up a TLS offset entry, but we're linking an
1904 executable and the symbol binds locally, we can use the
1905 module offset in the TLS descriptor in relaxations. */
1906 if (info->executable && ! entry->tlsoff_entry)
1907 entry->tlsoff_entry = entry->tlsdesc_entry + 4;
1909 if (info->executable && !info->pie
1911 && (bfd_is_abs_section (sec)
1912 || bfd_is_und_section (sec)))
1913 || entry->symndx != -1
1914 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1916 /* *ABS*+addend is special for TLS relocations, use only the
1917 addend for the TLS offset, and take the module id as
1920 && (bfd_is_abs_section (sec)
1921 || bfd_is_und_section (sec)))
1923 /* For other TLS symbols that bind locally, add the section
1924 TLS offset to the addend. */
1926 ad += sec->output_section->vma - tls_biased_base (info);
1928 bfd_put_32 (output_bfd,
1929 frvfdpic_plt_section (info)->output_section->vma
1930 + frvfdpic_plt_section (info)->output_offset
1931 + frvfdpic_plt_tls_ret_offset (info),
1932 frvfdpic_got_section (info)->contents
1933 + frvfdpic_got_initial_offset (info)
1934 + entry->tlsdesc_entry);
1936 _frvfdpic_add_rofixup (output_bfd,
1937 frvfdpic_gotfixup_section (info),
1938 frvfdpic_got_section (info)
1939 ->output_section->vma
1940 + frvfdpic_got_section (info)
1942 + frvfdpic_got_initial_offset (info)
1943 + entry->tlsdesc_entry, entry);
1945 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs);
1947 /* We've used one of the reserved fixups, so discount it so
1948 that we can check at the end that we've used them
1950 frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs--;
1952 /* While at that, make sure the ret instruction makes to the
1953 right location in the PLT. We could do it only when we
1954 got to 0, but since the check at the end will only print
1955 a warning, make sure we have the ret in place in case the
1956 warning is missed. */
1957 bfd_put_32 (output_bfd, 0xc03a4000,
1958 frvfdpic_plt_section (info)->contents
1959 + frvfdpic_plt_tls_ret_offset (info));
1964 && (bfd_is_abs_section (sec)
1965 || bfd_is_und_section (sec)))
1967 if (! elf_hash_table (info)->tls_sec)
1969 (*info->callbacks->undefined_symbol)
1970 (info, "TLS section", elf_hash_table (info)->dynobj,
1971 frvfdpic_got_section (info), entry->tlsdesc_entry, TRUE);
1974 idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx;
1975 ad += FRVFDPIC_TLS_BIAS;
1978 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
1979 _bfd_elf_section_offset
1981 frvfdpic_got_section (info),
1982 frvfdpic_got_initial_offset (info)
1983 + entry->tlsdesc_entry)
1984 + frvfdpic_got_section (info)
1985 ->output_section->vma
1986 + frvfdpic_got_section (info)
1988 R_FRV_TLSDESC_VALUE, idx, ad, entry);
1990 bfd_put_32 (output_bfd, 0,
1991 frvfdpic_got_section (info)->contents
1992 + frvfdpic_got_initial_offset (info)
1993 + entry->tlsdesc_entry);
1996 bfd_put_32 (output_bfd, ad,
1997 frvfdpic_got_section (info)->contents
1998 + frvfdpic_got_initial_offset (info)
1999 + entry->tlsdesc_entry + 4);
2002 /* Generate code for the get-TLS-offset PLT entry. */
2003 if (entry->tlsplt_entry != (bfd_vma) -1)
2005 bfd_byte *plt_code = frvfdpic_plt_section (info)->contents
2006 + entry->tlsplt_entry;
2008 if (info->executable
2009 && (entry->symndx != -1
2010 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
2013 bfd_vma ad = addend;
2015 /* sec may be NULL when referencing an undefweak symbol
2016 while linking a static executable. */
2019 BFD_ASSERT (entry->symndx == -1
2020 && entry->d.h->root.type == bfd_link_hash_undefweak);
2024 if (entry->symndx == -1)
2025 ad += entry->d.h->root.u.def.value;
2027 ad += sym->st_value;
2028 ad += sec->output_offset;
2029 if (sec->output_section
2030 && elf_section_data (sec->output_section))
2031 idx = elf_section_data (sec->output_section)->dynindx;
2036 /* *ABS*+addend is special for TLS relocations, use only the
2037 addend for the TLS offset, and take the module id as
2040 && (bfd_is_abs_section (sec)
2041 || bfd_is_und_section (sec)))
2043 /* For other TLS symbols that bind locally, add the section
2044 TLS offset to the addend. */
2046 ad += sec->output_section->vma - tls_biased_base (info);
2048 if ((bfd_signed_vma)ad >= -(1 << (16 - 1))
2049 && (bfd_signed_vma)ad < (1 << (16 - 1)))
2051 /* setlos lo(ad), gr9 */
2052 bfd_put_32 (output_bfd,
2055 & (((bfd_vma)1 << 16) - 1)),
2061 /* sethi.p hi(ad), gr9
2062 setlo lo(ad), gr9 */
2063 bfd_put_32 (output_bfd,
2066 & (((bfd_vma)1 << 16) - 1)),
2069 bfd_put_32 (output_bfd,
2072 & (((bfd_vma)1 << 16) - 1)),
2077 bfd_put_32 (output_bfd, 0xc03a4000, plt_code);
2079 else if (entry->tlsoff_entry)
2081 /* Figure out what kind of PLT entry we need, depending on the
2082 location of the TLS descriptor within the GOT. */
2083 if (entry->tlsoff_entry >= -(1 << (12 - 1))
2084 && entry->tlsoff_entry < (1 << (12 - 1)))
2086 /* ldi @(gr15, tlsoff_entry), gr9 */
2087 bfd_put_32 (output_bfd,
2088 0x92c8f000 | (entry->tlsoff_entry
2095 if (entry->tlsoff_entry >= -(1 << (16 - 1))
2096 && entry->tlsoff_entry < (1 << (16 - 1)))
2098 /* setlos lo(tlsoff_entry), gr8 */
2099 bfd_put_32 (output_bfd,
2101 | (entry->tlsoff_entry
2102 & (((bfd_vma)1 << 16) - 1)),
2108 /* sethi.p hi(tlsoff_entry), gr8
2109 setlo lo(tlsoff_entry), gr8 */
2110 bfd_put_32 (output_bfd,
2112 | ((entry->tlsoff_entry >> 16)
2113 & (((bfd_vma)1 << 16) - 1)),
2116 bfd_put_32 (output_bfd,
2118 | (entry->tlsoff_entry
2119 & (((bfd_vma)1 << 16) - 1)),
2123 /* ld @(gr15,gr8),gr9 */
2124 bfd_put_32 (output_bfd, 0x9008f108, plt_code);
2128 bfd_put_32 (output_bfd, 0xc03a4000, plt_code);
2132 BFD_ASSERT (entry->tlsdesc_entry);
2134 /* Figure out what kind of PLT entry we need, depending on the
2135 location of the TLS descriptor within the GOT. */
2136 if (entry->tlsdesc_entry >= -(1 << (12 - 1))
2137 && entry->tlsdesc_entry < (1 << (12 - 1)))
2139 /* lddi @(gr15, tlsdesc_entry), gr8 */
2140 bfd_put_32 (output_bfd,
2141 0x90ccf000 | (entry->tlsdesc_entry
2148 if (entry->tlsdesc_entry >= -(1 << (16 - 1))
2149 && entry->tlsdesc_entry < (1 << (16 - 1)))
2151 /* setlos lo(tlsdesc_entry), gr8 */
2152 bfd_put_32 (output_bfd,
2154 | (entry->tlsdesc_entry
2155 & (((bfd_vma)1 << 16) - 1)),
2161 /* sethi.p hi(tlsdesc_entry), gr8
2162 setlo lo(tlsdesc_entry), gr8 */
2163 bfd_put_32 (output_bfd,
2165 | ((entry->tlsdesc_entry >> 16)
2166 & (((bfd_vma)1 << 16) - 1)),
2169 bfd_put_32 (output_bfd,
2171 | (entry->tlsdesc_entry
2172 & (((bfd_vma)1 << 16) - 1)),
2176 /* ldd @(gr15,gr8),gr8 */
2177 bfd_put_32 (output_bfd, 0x9008f148, plt_code);
2180 /* jmpl @(gr8,gr0) */
2181 bfd_put_32 (output_bfd, 0x80308000, plt_code);
2188 /* Handle an FRV small data reloc. */
2190 static bfd_reloc_status_type
2191 elf32_frv_relocate_gprel12 (info, input_bfd, input_section, relocation,
2193 struct bfd_link_info *info;
2195 asection *input_section;
2196 Elf_Internal_Rela *relocation;
2202 struct bfd_link_hash_entry *h;
2204 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2206 gp = (h->u.def.value
2207 + h->u.def.section->output_section->vma
2208 + h->u.def.section->output_offset);
2210 value -= input_section->output_section->vma;
2211 value -= (gp - input_section->output_section->vma);
2213 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2215 value += relocation->r_addend;
2217 if ((long) value > 0x7ff || (long) value < -0x800)
2218 return bfd_reloc_overflow;
2220 bfd_put_32 (input_bfd,
2221 (insn & 0xfffff000) | (value & 0xfff),
2222 contents + relocation->r_offset);
2224 return bfd_reloc_ok;
2227 /* Handle an FRV small data reloc. for the u12 field. */
2229 static bfd_reloc_status_type
2230 elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, relocation,
2232 struct bfd_link_info *info;
2234 asection *input_section;
2235 Elf_Internal_Rela *relocation;
2241 struct bfd_link_hash_entry *h;
2244 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2246 gp = (h->u.def.value
2247 + h->u.def.section->output_section->vma
2248 + h->u.def.section->output_offset);
2250 value -= input_section->output_section->vma;
2251 value -= (gp - input_section->output_section->vma);
2253 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2255 value += relocation->r_addend;
2257 if ((long) value > 0x7ff || (long) value < -0x800)
2258 return bfd_reloc_overflow;
2260 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
2262 insn = (insn & ~mask) | ((value & 0xfc0) << 12) | (value & 0x3f);
2264 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
2266 return bfd_reloc_ok;
2269 /* Handle an FRV ELF HI16 reloc. */
2271 static bfd_reloc_status_type
2272 elf32_frv_relocate_hi16 (input_bfd, relhi, contents, value)
2274 Elf_Internal_Rela *relhi;
2280 insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
2282 value += relhi->r_addend;
2283 value = ((value >> 16) & 0xffff);
2285 insn = (insn & 0xffff0000) | value;
2287 if ((long) value > 0xffff || (long) value < -0x10000)
2288 return bfd_reloc_overflow;
2290 bfd_put_32 (input_bfd, insn, contents + relhi->r_offset);
2291 return bfd_reloc_ok;
2294 static bfd_reloc_status_type
2295 elf32_frv_relocate_lo16 (input_bfd, rello, contents, value)
2297 Elf_Internal_Rela *rello;
2303 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
2305 value += rello->r_addend;
2306 value = value & 0xffff;
2308 insn = (insn & 0xffff0000) | value;
2310 if ((long) value > 0xffff || (long) value < -0x10000)
2311 return bfd_reloc_overflow;
2313 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
2314 return bfd_reloc_ok;
2317 /* Perform the relocation for the CALL label24 instruction. */
2319 static bfd_reloc_status_type
2320 elf32_frv_relocate_label24 (input_bfd, input_section, rello, contents, value)
2322 asection *input_section;
2323 Elf_Internal_Rela *rello;
2331 /* The format for the call instruction is:
2333 0 000000 0001111 000000000000000000
2334 label6 opcode label18
2336 The branch calculation is: pc + (4*label24)
2337 where label24 is the concatenation of label6 and label18. */
2339 /* Grab the instruction. */
2340 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
2342 value -= input_section->output_section->vma + input_section->output_offset;
2343 value -= rello->r_offset;
2344 value += rello->r_addend;
2348 label6 = value & 0xfc0000;
2349 label6 = label6 << 7;
2351 label18 = value & 0x3ffff;
2353 insn = insn & 0x803c0000;
2354 insn = insn | label6;
2355 insn = insn | label18;
2357 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
2359 return bfd_reloc_ok;
2362 static bfd_reloc_status_type
2363 elf32_frv_relocate_gprelhi (info, input_bfd, input_section, relocation,
2365 struct bfd_link_info *info;
2367 asection *input_section;
2368 Elf_Internal_Rela *relocation;
2374 struct bfd_link_hash_entry *h;
2376 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2378 gp = (h->u.def.value
2379 + h->u.def.section->output_section->vma
2380 + h->u.def.section->output_offset);
2382 value -= input_section->output_section->vma;
2383 value -= (gp - input_section->output_section->vma);
2384 value += relocation->r_addend;
2385 value = ((value >> 16) & 0xffff);
2387 if ((long) value > 0xffff || (long) value < -0x10000)
2388 return bfd_reloc_overflow;
2390 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2391 insn = (insn & 0xffff0000) | value;
2393 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
2394 return bfd_reloc_ok;
2397 static bfd_reloc_status_type
2398 elf32_frv_relocate_gprello (info, input_bfd, input_section, relocation,
2400 struct bfd_link_info *info;
2402 asection *input_section;
2403 Elf_Internal_Rela *relocation;
2409 struct bfd_link_hash_entry *h;
2411 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2413 gp = (h->u.def.value
2414 + h->u.def.section->output_section->vma
2415 + h->u.def.section->output_offset);
2417 value -= input_section->output_section->vma;
2418 value -= (gp - input_section->output_section->vma);
2419 value += relocation->r_addend;
2420 value = value & 0xffff;
2422 if ((long) value > 0xffff || (long) value < -0x10000)
2423 return bfd_reloc_overflow;
2425 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2426 insn = (insn & 0xffff0000) | value;
2428 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
2430 return bfd_reloc_ok;
2433 static reloc_howto_type *
2434 frv_reloc_type_lookup (abfd, code)
2435 bfd *abfd ATTRIBUTE_UNUSED;
2436 bfd_reloc_code_real_type code;
2443 case BFD_RELOC_NONE:
2444 return &elf32_frv_howto_table[ (int) R_FRV_NONE];
2447 if (elf_elfheader (abfd)->e_type == ET_EXEC
2448 || elf_elfheader (abfd)->e_type == ET_DYN)
2449 return &elf32_frv_rel_32_howto;
2451 case BFD_RELOC_CTOR:
2452 return &elf32_frv_howto_table[ (int) R_FRV_32];
2454 case BFD_RELOC_FRV_LABEL16:
2455 return &elf32_frv_howto_table[ (int) R_FRV_LABEL16];
2457 case BFD_RELOC_FRV_LABEL24:
2458 return &elf32_frv_howto_table[ (int) R_FRV_LABEL24];
2460 case BFD_RELOC_FRV_LO16:
2461 return &elf32_frv_howto_table[ (int) R_FRV_LO16];
2463 case BFD_RELOC_FRV_HI16:
2464 return &elf32_frv_howto_table[ (int) R_FRV_HI16];
2466 case BFD_RELOC_FRV_GPREL12:
2467 return &elf32_frv_howto_table[ (int) R_FRV_GPREL12];
2469 case BFD_RELOC_FRV_GPRELU12:
2470 return &elf32_frv_howto_table[ (int) R_FRV_GPRELU12];
2472 case BFD_RELOC_FRV_GPREL32:
2473 return &elf32_frv_howto_table[ (int) R_FRV_GPREL32];
2475 case BFD_RELOC_FRV_GPRELHI:
2476 return &elf32_frv_howto_table[ (int) R_FRV_GPRELHI];
2478 case BFD_RELOC_FRV_GPRELLO:
2479 return &elf32_frv_howto_table[ (int) R_FRV_GPRELLO];
2481 case BFD_RELOC_FRV_GOT12:
2482 return &elf32_frv_howto_table[ (int) R_FRV_GOT12];
2484 case BFD_RELOC_FRV_GOTHI:
2485 return &elf32_frv_howto_table[ (int) R_FRV_GOTHI];
2487 case BFD_RELOC_FRV_GOTLO:
2488 return &elf32_frv_howto_table[ (int) R_FRV_GOTLO];
2490 case BFD_RELOC_FRV_FUNCDESC:
2491 if (elf_elfheader (abfd)->e_type == ET_EXEC
2492 || elf_elfheader (abfd)->e_type == ET_DYN)
2493 return &elf32_frv_rel_funcdesc_howto;
2494 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC];
2496 case BFD_RELOC_FRV_FUNCDESC_GOT12:
2497 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOT12];
2499 case BFD_RELOC_FRV_FUNCDESC_GOTHI:
2500 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTHI];
2502 case BFD_RELOC_FRV_FUNCDESC_GOTLO:
2503 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTLO];
2505 case BFD_RELOC_FRV_FUNCDESC_VALUE:
2506 if (elf_elfheader (abfd)->e_type == ET_EXEC
2507 || elf_elfheader (abfd)->e_type == ET_DYN)
2508 return &elf32_frv_rel_funcdesc_value_howto;
2509 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_VALUE];
2511 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12:
2512 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFF12];
2514 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI:
2515 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFHI];
2517 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO:
2518 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFLO];
2520 case BFD_RELOC_FRV_GOTOFF12:
2521 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFF12];
2523 case BFD_RELOC_FRV_GOTOFFHI:
2524 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFHI];
2526 case BFD_RELOC_FRV_GOTOFFLO:
2527 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFLO];
2529 case BFD_RELOC_FRV_GETTLSOFF:
2530 return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF];
2532 case BFD_RELOC_FRV_TLSDESC_VALUE:
2533 if (elf_elfheader (abfd)->e_type == ET_EXEC
2534 || elf_elfheader (abfd)->e_type == ET_DYN)
2535 return &elf32_frv_rel_tlsdesc_value_howto;
2536 return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_VALUE];
2538 case BFD_RELOC_FRV_GOTTLSDESC12:
2539 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESC12];
2541 case BFD_RELOC_FRV_GOTTLSDESCHI:
2542 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCHI];
2544 case BFD_RELOC_FRV_GOTTLSDESCLO:
2545 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCLO];
2547 case BFD_RELOC_FRV_TLSMOFF12:
2548 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF12];
2550 case BFD_RELOC_FRV_TLSMOFFHI:
2551 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFHI];
2553 case BFD_RELOC_FRV_TLSMOFFLO:
2554 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFLO];
2556 case BFD_RELOC_FRV_GOTTLSOFF12:
2557 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFF12];
2559 case BFD_RELOC_FRV_GOTTLSOFFHI:
2560 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFHI];
2562 case BFD_RELOC_FRV_GOTTLSOFFLO:
2563 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFLO];
2565 case BFD_RELOC_FRV_TLSOFF:
2566 if (elf_elfheader (abfd)->e_type == ET_EXEC
2567 || elf_elfheader (abfd)->e_type == ET_DYN)
2568 return &elf32_frv_rel_tlsoff_howto;
2569 return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF];
2571 case BFD_RELOC_FRV_TLSDESC_RELAX:
2572 return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_RELAX];
2574 case BFD_RELOC_FRV_GETTLSOFF_RELAX:
2575 return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF_RELAX];
2577 case BFD_RELOC_FRV_TLSOFF_RELAX:
2578 return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF_RELAX];
2580 case BFD_RELOC_FRV_TLSMOFF:
2581 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF];
2583 case BFD_RELOC_VTABLE_INHERIT:
2584 return &elf32_frv_vtinherit_howto;
2586 case BFD_RELOC_VTABLE_ENTRY:
2587 return &elf32_frv_vtentry_howto;
2593 static reloc_howto_type *
2594 frv_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
2599 i < sizeof (elf32_frv_howto_table) / sizeof (elf32_frv_howto_table[0]);
2601 if (elf32_frv_howto_table[i].name != NULL
2602 && strcasecmp (elf32_frv_howto_table[i].name, r_name) == 0)
2603 return &elf32_frv_howto_table[i];
2605 if (strcasecmp (elf32_frv_vtinherit_howto.name, r_name) == 0)
2606 return &elf32_frv_vtinherit_howto;
2607 if (strcasecmp (elf32_frv_vtentry_howto.name, r_name) == 0)
2608 return &elf32_frv_vtentry_howto;
2613 /* Set the howto pointer for an FRV ELF reloc. */
2616 frv_info_to_howto_rela (abfd, cache_ptr, dst)
2617 bfd *abfd ATTRIBUTE_UNUSED;
2619 Elf_Internal_Rela *dst;
2621 unsigned int r_type;
2623 r_type = ELF32_R_TYPE (dst->r_info);
2626 case R_FRV_GNU_VTINHERIT:
2627 cache_ptr->howto = &elf32_frv_vtinherit_howto;
2630 case R_FRV_GNU_VTENTRY:
2631 cache_ptr->howto = &elf32_frv_vtentry_howto;
2635 cache_ptr->howto = & elf32_frv_howto_table [r_type];
2640 /* Set the howto pointer for an FRV ELF REL reloc. */
2642 frvfdpic_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
2643 arelent *cache_ptr, Elf_Internal_Rela *dst)
2645 unsigned int r_type;
2647 r_type = ELF32_R_TYPE (dst->r_info);
2651 cache_ptr->howto = &elf32_frv_rel_32_howto;
2654 case R_FRV_FUNCDESC:
2655 cache_ptr->howto = &elf32_frv_rel_funcdesc_howto;
2658 case R_FRV_FUNCDESC_VALUE:
2659 cache_ptr->howto = &elf32_frv_rel_funcdesc_value_howto;
2662 case R_FRV_TLSDESC_VALUE:
2663 cache_ptr->howto = &elf32_frv_rel_tlsdesc_value_howto;
2667 cache_ptr->howto = &elf32_frv_rel_tlsoff_howto;
2671 cache_ptr->howto = NULL;
2676 /* Perform a single relocation. By default we use the standard BFD
2677 routines, but a few relocs, we have to do them ourselves. */
2679 static bfd_reloc_status_type
2680 frv_final_link_relocate (howto, input_bfd, input_section, contents, rel,
2682 reloc_howto_type *howto;
2684 asection *input_section;
2686 Elf_Internal_Rela *rel;
2689 return _bfd_final_link_relocate (howto, input_bfd, input_section,
2690 contents, rel->r_offset, relocation,
2695 /* Relocate an FRV ELF section.
2697 The RELOCATE_SECTION function is called by the new ELF backend linker
2698 to handle the relocations for a section.
2700 The relocs are always passed as Rela structures; if the section
2701 actually uses Rel structures, the r_addend field will always be
2704 This function is responsible for adjusting the section contents as
2705 necessary, and (if using Rela relocs and generating a relocatable
2706 output file) adjusting the reloc addend as necessary.
2708 This function does not have to worry about setting the reloc
2709 address or the reloc symbol index.
2711 LOCAL_SYMS is a pointer to the swapped in local symbols.
2713 LOCAL_SECTIONS is an array giving the section in the input file
2714 corresponding to the st_shndx field of each local symbol.
2716 The global hash table entry for the global symbols can be found
2717 via elf_sym_hashes (input_bfd).
2719 When generating relocatable output, this function must handle
2720 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2721 going to be the section symbol corresponding to the output
2722 section, which means that the addend must be adjusted
2726 elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
2727 contents, relocs, local_syms, local_sections)
2728 bfd *output_bfd ATTRIBUTE_UNUSED;
2729 struct bfd_link_info *info;
2731 asection *input_section;
2733 Elf_Internal_Rela *relocs;
2734 Elf_Internal_Sym *local_syms;
2735 asection **local_sections;
2737 Elf_Internal_Shdr *symtab_hdr;
2738 struct elf_link_hash_entry **sym_hashes;
2739 Elf_Internal_Rela *rel;
2740 Elf_Internal_Rela *relend;
2741 unsigned isec_segment, got_segment, plt_segment, gprel_segment, tls_segment,
2743 int silence_segment_error = !(info->shared || info->pie);
2746 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
2747 sym_hashes = elf_sym_hashes (input_bfd);
2748 relend = relocs + input_section->reloc_count;
2750 isec_segment = _frvfdpic_osec_to_segment (output_bfd,
2751 input_section->output_section);
2752 if (IS_FDPIC (output_bfd) && frvfdpic_got_section (info))
2753 got_segment = _frvfdpic_osec_to_segment (output_bfd,
2754 frvfdpic_got_section (info)
2758 if (IS_FDPIC (output_bfd) && frvfdpic_gotfixup_section (info))
2759 gprel_segment = _frvfdpic_osec_to_segment (output_bfd,
2760 frvfdpic_gotfixup_section (info)
2764 if (IS_FDPIC (output_bfd) && frvfdpic_plt_section (info))
2765 plt_segment = _frvfdpic_osec_to_segment (output_bfd,
2766 frvfdpic_plt_section (info)
2770 if (elf_hash_table (info)->tls_sec)
2771 tls_segment = _frvfdpic_osec_to_segment (output_bfd,
2772 elf_hash_table (info)->tls_sec);
2776 for (rel = relocs; rel < relend; rel ++)
2778 reloc_howto_type *howto;
2779 unsigned long r_symndx;
2780 Elf_Internal_Sym *sym;
2782 struct elf_link_hash_entry *h;
2784 bfd_reloc_status_type r;
2785 const char * name = NULL;
2788 struct frvfdpic_relocs_info *picrel;
2789 bfd_vma orig_addend = rel->r_addend;
2791 r_type = ELF32_R_TYPE (rel->r_info);
2793 if ( r_type == R_FRV_GNU_VTINHERIT
2794 || r_type == R_FRV_GNU_VTENTRY)
2797 r_symndx = ELF32_R_SYM (rel->r_info);
2798 howto = elf32_frv_howto_table + ELF32_R_TYPE (rel->r_info);
2803 if (r_symndx < symtab_hdr->sh_info)
2805 sym = local_syms + r_symndx;
2806 osec = sec = local_sections [r_symndx];
2807 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
2809 name = bfd_elf_string_from_elf_section
2810 (input_bfd, symtab_hdr->sh_link, sym->st_name);
2811 name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
2816 bfd_boolean unresolved_reloc;
2818 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2819 r_symndx, symtab_hdr, sym_hashes,
2821 unresolved_reloc, warned);
2825 if (sec != NULL && elf_discarded_section (sec))
2827 /* For relocs against symbols from removed linkonce sections,
2828 or sections discarded by a linker script, we just want the
2829 section contents zeroed. Avoid any special processing. */
2830 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
2836 if (info->relocatable)
2839 if (r_type != R_FRV_TLSMOFF
2841 && (h->root.type == bfd_link_hash_defined
2842 || h->root.type == bfd_link_hash_defweak)
2843 && !FRVFDPIC_SYM_LOCAL (info, h))
2853 if (! IS_FDPIC (output_bfd))
2859 case R_FRV_FUNCDESC_GOT12:
2860 case R_FRV_FUNCDESC_GOTHI:
2861 case R_FRV_FUNCDESC_GOTLO:
2862 case R_FRV_GOTOFF12:
2863 case R_FRV_GOTOFFHI:
2864 case R_FRV_GOTOFFLO:
2865 case R_FRV_FUNCDESC_GOTOFF12:
2866 case R_FRV_FUNCDESC_GOTOFFHI:
2867 case R_FRV_FUNCDESC_GOTOFFLO:
2868 case R_FRV_FUNCDESC:
2869 case R_FRV_FUNCDESC_VALUE:
2870 case R_FRV_GETTLSOFF:
2871 case R_FRV_TLSDESC_VALUE:
2872 case R_FRV_GOTTLSDESC12:
2873 case R_FRV_GOTTLSDESCHI:
2874 case R_FRV_GOTTLSDESCLO:
2875 case R_FRV_TLSMOFF12:
2876 case R_FRV_TLSMOFFHI:
2877 case R_FRV_TLSMOFFLO:
2878 case R_FRV_GOTTLSOFF12:
2879 case R_FRV_GOTTLSOFFHI:
2880 case R_FRV_GOTTLSOFFLO:
2882 case R_FRV_TLSDESC_RELAX:
2883 case R_FRV_GETTLSOFF_RELAX:
2884 case R_FRV_TLSOFF_RELAX:
2887 picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info
2888 (info), input_bfd, h,
2889 orig_addend, INSERT);
2891 /* In order to find the entry we created before, we must
2892 use the original addend, not the one that may have been
2893 modified by _bfd_elf_rela_local_sym(). */
2894 picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
2895 (info), input_bfd, r_symndx,
2896 orig_addend, INSERT);
2900 if (!_frvfdpic_emit_got_relocs_plt_entries (picrel, output_bfd, info,
2904 (*_bfd_error_handler)
2905 (_("%B(%A+0x%x): relocation to `%s+%x' may have caused the error above"),
2906 input_bfd, input_section, rel->r_offset, name, rel->r_addend);
2915 if (h && ! FRVFDPIC_SYM_LOCAL (info, h))
2917 info->callbacks->warning
2918 (info, _("relocation references symbol not defined in the module"),
2919 name, input_bfd, input_section, rel->r_offset);
2927 case R_FRV_GETTLSOFF:
2928 case R_FRV_TLSDESC_VALUE:
2929 case R_FRV_GOTTLSDESC12:
2930 case R_FRV_GOTTLSDESCHI:
2931 case R_FRV_GOTTLSDESCLO:
2932 case R_FRV_TLSMOFF12:
2933 case R_FRV_TLSMOFFHI:
2934 case R_FRV_TLSMOFFLO:
2935 case R_FRV_GOTTLSOFF12:
2936 case R_FRV_GOTTLSOFFHI:
2937 case R_FRV_GOTTLSOFFLO:
2939 case R_FRV_TLSDESC_RELAX:
2940 case R_FRV_GETTLSOFF_RELAX:
2941 case R_FRV_TLSOFF_RELAX:
2943 if (sec && (bfd_is_abs_section (sec) || bfd_is_und_section (sec)))
2944 relocation += tls_biased_base (info);
2951 /* Try to apply TLS relaxations. */
2956 #define LOCAL_EXEC_P(info, picrel) \
2957 ((info)->executable \
2958 && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h)))
2959 #define INITIAL_EXEC_P(info, picrel) \
2960 (((info)->executable || (info)->flags & DF_STATIC_TLS) \
2961 && (picrel)->tlsoff_entry)
2963 #define IN_RANGE_FOR_OFST12_P(value) \
2964 ((bfd_vma)((value) + 2048) < (bfd_vma)4096)
2965 #define IN_RANGE_FOR_SETLOS_P(value) \
2966 ((bfd_vma)((value) + 32768) < (bfd_vma)65536)
2967 #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \
2968 (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info)))
2970 #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2971 (LOCAL_EXEC_P ((info), (picrel)) \
2972 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2973 #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \
2974 (INITIAL_EXEC_P ((info), (picrel)) \
2975 && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry))
2977 #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \
2978 (LOCAL_EXEC_P ((info), (picrel)))
2979 #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \
2980 (INITIAL_EXEC_P ((info), (picrel)))
2982 #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2983 (LOCAL_EXEC_P ((info), (picrel)) \
2984 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2986 case R_FRV_GETTLSOFF:
2987 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
2989 /* Is this a call instruction? */
2990 if ((insn & (unsigned long)0x01fc0000) != 0x003c0000)
2992 r = info->callbacks->warning
2994 _("R_FRV_GETTLSOFF not applied to a call instruction"),
2995 name, input_bfd, input_section, rel->r_offset);
2999 if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info, picrel,
3000 relocation + rel->r_addend))
3002 /* Replace the call instruction (except the packing bit)
3003 with setlos #tlsmofflo(symbol+offset), gr9. */
3004 insn &= (unsigned long)0x80000000;
3005 insn |= (unsigned long)0x12fc0000;
3006 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3008 r_type = R_FRV_TLSMOFFLO;
3009 howto = elf32_frv_howto_table + r_type;
3010 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3013 else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info, picrel))
3015 /* Replace the call instruction (except the packing bit)
3016 with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */
3017 insn &= (unsigned long)0x80000000;
3018 insn |= (unsigned long)0x12c8f000;
3019 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3021 r_type = R_FRV_GOTTLSOFF12;
3022 howto = elf32_frv_howto_table + r_type;
3023 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3028 case R_FRV_GOTTLSDESC12:
3029 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3031 /* Is this an lddi instruction? */
3032 if ((insn & (unsigned long)0x01fc0000) != 0x00cc0000)
3034 r = info->callbacks->warning
3036 _("R_FRV_GOTTLSDESC12 not applied to an lddi instruction"),
3037 name, input_bfd, input_section, rel->r_offset);
3041 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3042 relocation + rel->r_addend)
3043 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3046 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3047 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3048 Preserve the packing bit. */
3049 insn = (insn & (unsigned long)0x80000000)
3050 | ((insn + (unsigned long)0x02000000)
3051 & (unsigned long)0x7e000000);
3052 insn |= (unsigned long)0x00fc0000;
3053 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3055 r_type = R_FRV_TLSMOFFLO;
3056 howto = elf32_frv_howto_table + r_type;
3057 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3060 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3061 relocation + rel->r_addend))
3063 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3064 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3065 Preserve the packing bit. */
3066 insn = (insn & (unsigned long)0x80000000)
3067 | ((insn + (unsigned long)0x02000000)
3068 & (unsigned long)0x7e000000);
3069 insn |= (unsigned long)0x00f80000;
3070 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3072 r_type = R_FRV_TLSMOFFHI;
3073 howto = elf32_frv_howto_table + r_type;
3074 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3077 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3079 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3080 with ldi @(grB, #gottlsoff12(symbol+offset),
3081 gr<C+1>. Preserve the packing bit. If gottlsoff12
3082 overflows, we'll error out, but that's sort-of ok,
3083 since we'd started with gottlsdesc12, that's actually
3084 more demanding. Compiling with -fPIE instead of
3085 -fpie would fix it; linking with --relax should fix
3087 insn = (insn & (unsigned long)0x80cbf000)
3088 | ((insn + (unsigned long)0x02000000)
3089 & (unsigned long)0x7e000000);
3090 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3092 r_type = R_FRV_GOTTLSOFF12;
3093 howto = elf32_frv_howto_table + r_type;
3094 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3099 case R_FRV_GOTTLSDESCHI:
3100 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3102 /* Is this a sethi instruction? */
3103 if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
3105 r = info->callbacks->warning
3107 _("R_FRV_GOTTLSDESCHI not applied to a sethi instruction"),
3108 name, input_bfd, input_section, rel->r_offset);
3112 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3113 relocation + rel->r_addend)
3114 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3115 && IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry)))
3117 /* Replace sethi with a nop. Preserve the packing bit. */
3118 insn &= (unsigned long)0x80000000;
3119 insn |= (unsigned long)0x00880000;
3120 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3122 /* Nothing to relocate. */
3126 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3128 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3129 r_type = R_FRV_GOTTLSOFFHI;
3130 howto = elf32_frv_howto_table + r_type;
3131 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3136 case R_FRV_GOTTLSDESCLO:
3137 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3139 /* Is this a setlo or setlos instruction? */
3140 if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
3142 r = info->callbacks->warning
3144 _("R_FRV_GOTTLSDESCLO"
3145 " not applied to a setlo or setlos instruction"),
3146 name, input_bfd, input_section, rel->r_offset);
3150 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3151 relocation + rel->r_addend)
3152 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3153 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
3155 /* Replace setlo/setlos with a nop. Preserve the
3157 insn &= (unsigned long)0x80000000;
3158 insn |= (unsigned long)0x00880000;
3159 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3161 /* Nothing to relocate. */
3165 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3167 /* If the corresponding sethi (if it exists) decayed
3168 to a nop, make sure this becomes (or already is) a
3169 setlos, not setlo. */
3170 if (IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry))
3172 insn |= (unsigned long)0x00080000;
3173 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3176 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3177 r_type = R_FRV_GOTTLSOFFLO;
3178 howto = elf32_frv_howto_table + r_type;
3179 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3184 case R_FRV_TLSDESC_RELAX:
3185 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3187 /* Is this an ldd instruction? */
3188 if ((insn & (unsigned long)0x01fc0fc0) != 0x00080140)
3190 r = info->callbacks->warning
3192 _("R_FRV_TLSDESC_RELAX not applied to an ldd instruction"),
3193 name, input_bfd, input_section, rel->r_offset);
3197 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3198 relocation + rel->r_addend)
3199 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3202 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3203 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3204 Preserve the packing bit. */
3205 insn = (insn & (unsigned long)0x80000000)
3206 | ((insn + (unsigned long)0x02000000)
3207 & (unsigned long)0x7e000000);
3208 insn |= (unsigned long)0x00fc0000;
3209 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3211 r_type = R_FRV_TLSMOFFLO;
3212 howto = elf32_frv_howto_table + r_type;
3213 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3216 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3217 relocation + rel->r_addend))
3219 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3220 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3221 Preserve the packing bit. */
3222 insn = (insn & (unsigned long)0x80000000)
3223 | ((insn + (unsigned long)0x02000000)
3224 & (unsigned long)0x7e000000);
3225 insn |= (unsigned long)0x00f80000;
3226 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3228 r_type = R_FRV_TLSMOFFHI;
3229 howto = elf32_frv_howto_table + r_type;
3230 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3233 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3234 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))
3236 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3237 with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>.
3238 Preserve the packing bit. */
3239 insn = (insn & (unsigned long)0x8003f000)
3240 | (unsigned long)0x00c80000
3241 | ((insn + (unsigned long)0x02000000)
3242 & (unsigned long)0x7e000000);
3243 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3245 r_type = R_FRV_GOTTLSOFF12;
3246 howto = elf32_frv_howto_table + r_type;
3247 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3250 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3252 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3253 with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>.
3254 Preserve the packing bit. */
3255 insn = (insn & (unsigned long)0x81ffffbf)
3256 | ((insn + (unsigned long)0x02000000)
3257 & (unsigned long)0x7e000000);
3258 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3260 /* #tlsoff(symbol+offset) is just a relaxation
3261 annotation, so there's nothing left to
3268 case R_FRV_GETTLSOFF_RELAX:
3269 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3271 /* Is this a calll or callil instruction? */
3272 if ((insn & (unsigned long)0x7ff80fc0) != 0x02300000)
3274 r = info->callbacks->warning
3276 _("R_FRV_GETTLSOFF_RELAX"
3277 " not applied to a calll instruction"),
3278 name, input_bfd, input_section, rel->r_offset);
3282 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3283 relocation + rel->r_addend)
3284 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3287 /* Replace calll with a nop. Preserve the packing bit. */
3288 insn &= (unsigned long)0x80000000;
3289 insn |= (unsigned long)0x00880000;
3290 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3292 /* Nothing to relocate. */
3296 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3297 relocation + rel->r_addend))
3299 /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9.
3300 Preserve the packing bit. */
3301 insn &= (unsigned long)0x80000000;
3302 insn |= (unsigned long)0x12f40000;
3303 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3305 r_type = R_FRV_TLSMOFFLO;
3306 howto = elf32_frv_howto_table + r_type;
3307 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3310 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3312 /* Replace calll with a nop. Preserve the packing bit. */
3313 insn &= (unsigned long)0x80000000;
3314 insn |= (unsigned long)0x00880000;
3315 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3317 /* Nothing to relocate. */
3323 case R_FRV_GOTTLSOFF12:
3324 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3326 /* Is this an ldi instruction? */
3327 if ((insn & (unsigned long)0x01fc0000) != 0x00c80000)
3329 r = info->callbacks->warning
3331 _("R_FRV_GOTTLSOFF12 not applied to an ldi instruction"),
3332 name, input_bfd, input_section, rel->r_offset);
3336 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3337 relocation + rel->r_addend))
3339 /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC
3340 with setlos #tlsmofflo(symbol+offset), grC.
3341 Preserve the packing bit. */
3342 insn &= (unsigned long)0xfe000000;
3343 insn |= (unsigned long)0x00fc0000;
3344 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3346 r_type = R_FRV_TLSMOFFLO;
3347 howto = elf32_frv_howto_table + r_type;
3348 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3353 case R_FRV_GOTTLSOFFHI:
3354 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3356 /* Is this a sethi instruction? */
3357 if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
3359 r = info->callbacks->warning
3361 _("R_FRV_GOTTLSOFFHI not applied to a sethi instruction"),
3362 name, input_bfd, input_section, rel->r_offset);
3366 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3367 relocation + rel->r_addend)
3368 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3369 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
3371 /* Replace sethi with a nop. Preserve the packing bit. */
3372 insn &= (unsigned long)0x80000000;
3373 insn |= (unsigned long)0x00880000;
3374 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3376 /* Nothing to relocate. */
3382 case R_FRV_GOTTLSOFFLO:
3383 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3385 /* Is this a setlo or setlos instruction? */
3386 if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
3388 r = info->callbacks->warning
3390 _("R_FRV_GOTTLSOFFLO"
3391 " not applied to a setlo or setlos instruction"),
3392 name, input_bfd, input_section, rel->r_offset);
3396 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3397 relocation + rel->r_addend)
3398 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3399 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
3401 /* Replace setlo/setlos with a nop. Preserve the
3403 insn &= (unsigned long)0x80000000;
3404 insn |= (unsigned long)0x00880000;
3405 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3407 /* Nothing to relocate. */
3413 case R_FRV_TLSOFF_RELAX:
3414 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3416 /* Is this an ld instruction? */
3417 if ((insn & (unsigned long)0x01fc0fc0) != 0x00080100)
3419 r = info->callbacks->warning
3421 _("R_FRV_TLSOFF_RELAX not applied to an ld instruction"),
3422 name, input_bfd, input_section, rel->r_offset);
3426 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3427 relocation + rel->r_addend))
3429 /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC
3430 with setlos #tlsmofflo(symbol+offset), grC.
3431 Preserve the packing bit. */
3432 insn &= (unsigned long)0xfe000000;
3433 insn |= (unsigned long)0x00fc0000;
3434 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3436 r_type = R_FRV_TLSMOFFLO;
3437 howto = elf32_frv_howto_table + r_type;
3438 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3441 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3442 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))
3444 /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC
3445 with ldi @(grB, #gottlsoff12(symbol+offset), grC.
3446 Preserve the packing bit. */
3447 insn = (insn & (unsigned long)0xfe03f000)
3448 | (unsigned long)0x00c80000;;
3449 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3451 r_type = R_FRV_GOTTLSOFF12;
3452 howto = elf32_frv_howto_table + r_type;
3453 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3458 case R_FRV_TLSMOFFHI:
3459 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3461 /* Is this a sethi instruction? */
3462 if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
3464 r = info->callbacks->warning
3466 _("R_FRV_TLSMOFFHI not applied to a sethi instruction"),
3467 name, input_bfd, input_section, rel->r_offset);
3471 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3474 /* Replace sethi with a nop. Preserve the packing bit. */
3475 insn &= (unsigned long)0x80000000;
3476 insn |= (unsigned long)0x00880000;
3477 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3479 /* Nothing to relocate. */
3485 case R_FRV_TLSMOFFLO:
3486 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3488 /* Is this a setlo or setlos instruction? */
3489 if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
3491 r = info->callbacks->warning
3494 " not applied to a setlo or setlos instruction"),
3495 name, input_bfd, input_section, rel->r_offset);
3499 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3501 /* If the corresponding sethi (if it exists) decayed
3502 to a nop, make sure this becomes (or already is) a
3503 setlos, not setlo. */
3505 insn |= (unsigned long)0x00080000;
3506 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3512 There's nothing to relax in these:
3528 check_segment[0] = isec_segment;
3529 if (! IS_FDPIC (output_bfd))
3530 check_segment[1] = isec_segment;
3531 else if (picrel->plt)
3533 relocation = frvfdpic_plt_section (info)->output_section->vma
3534 + frvfdpic_plt_section (info)->output_offset
3535 + picrel->plt_entry;
3536 check_segment[1] = plt_segment;
3538 /* We don't want to warn on calls to undefined weak symbols,
3539 as calls to them must be protected by non-NULL tests
3540 anyway, and unprotected calls would invoke undefined
3542 else if (picrel->symndx == -1
3543 && picrel->d.h->root.type == bfd_link_hash_undefweak)
3544 check_segment[1] = check_segment[0];
3546 check_segment[1] = sec
3547 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3554 relocation = picrel->got_entry;
3555 check_segment[0] = check_segment[1] = got_segment;
3558 case R_FRV_FUNCDESC_GOT12:
3559 case R_FRV_FUNCDESC_GOTHI:
3560 case R_FRV_FUNCDESC_GOTLO:
3561 relocation = picrel->fdgot_entry;
3562 check_segment[0] = check_segment[1] = got_segment;
3565 case R_FRV_GOTOFFHI:
3566 case R_FRV_GOTOFF12:
3567 case R_FRV_GOTOFFLO:
3568 relocation -= frvfdpic_got_section (info)->output_section->vma
3569 + frvfdpic_got_section (info)->output_offset
3570 + frvfdpic_got_initial_offset (info);
3571 check_segment[0] = got_segment;
3572 check_segment[1] = sec
3573 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3577 case R_FRV_FUNCDESC_GOTOFF12:
3578 case R_FRV_FUNCDESC_GOTOFFHI:
3579 case R_FRV_FUNCDESC_GOTOFFLO:
3580 relocation = picrel->fd_entry;
3581 check_segment[0] = check_segment[1] = got_segment;
3584 case R_FRV_FUNCDESC:
3587 bfd_vma addend = rel->r_addend;
3589 if (! (h && h->root.type == bfd_link_hash_undefweak
3590 && FRVFDPIC_SYM_LOCAL (info, h)))
3592 /* If the symbol is dynamic and there may be dynamic
3593 symbol resolution because we are or are linked with a
3594 shared library, emit a FUNCDESC relocation such that
3595 the dynamic linker will allocate the function
3596 descriptor. If the symbol needs a non-local function
3597 descriptor but binds locally (e.g., its visibility is
3598 protected, emit a dynamic relocation decayed to
3600 if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h)
3601 && FRVFDPIC_SYM_LOCAL (info, h)
3602 && !(info->executable && !info->pie))
3604 dynindx = elf_section_data (h->root.u.def.section
3605 ->output_section)->dynindx;
3606 addend += h->root.u.def.section->output_offset
3607 + h->root.u.def.value;
3609 else if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h))
3613 info->callbacks->warning
3614 (info, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"),
3615 name, input_bfd, input_section, rel->r_offset);
3618 dynindx = h->dynindx;
3622 /* Otherwise, we know we have a private function
3623 descriptor, so reference it directly. */
3624 BFD_ASSERT (picrel->privfd);
3626 dynindx = elf_section_data (frvfdpic_got_section (info)
3627 ->output_section)->dynindx;
3628 addend = frvfdpic_got_section (info)->output_offset
3629 + frvfdpic_got_initial_offset (info)
3633 /* If there is room for dynamic symbol resolution, emit
3634 the dynamic relocation. However, if we're linking an
3635 executable at a fixed location, we won't have emitted a
3636 dynamic symbol entry for the got section, so idx will
3637 be zero, which means we can and should compute the
3638 address of the private descriptor ourselves. */
3639 if (info->executable && !info->pie
3640 && (!h || FRVFDPIC_FUNCDESC_LOCAL (info, h)))
3642 addend += frvfdpic_got_section (info)->output_section->vma;
3643 if ((bfd_get_section_flags (output_bfd,
3644 input_section->output_section)
3645 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
3649 if (_frvfdpic_osec_readonly_p (output_bfd,
3653 info->callbacks->warning
3655 _("cannot emit fixups in read-only section"),
3656 name, input_bfd, input_section, rel->r_offset);
3660 offset = _bfd_elf_section_offset
3662 input_section, rel->r_offset);
3664 if (offset != (bfd_vma)-1)
3665 _frvfdpic_add_rofixup (output_bfd,
3666 frvfdpic_gotfixup_section
3668 offset + input_section
3669 ->output_section->vma
3670 + input_section->output_offset,
3674 else if ((bfd_get_section_flags (output_bfd,
3675 input_section->output_section)
3676 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
3680 if (_frvfdpic_osec_readonly_p (output_bfd,
3684 info->callbacks->warning
3686 _("cannot emit dynamic relocations in read-only section"),
3687 name, input_bfd, input_section, rel->r_offset);
3691 offset = _bfd_elf_section_offset
3693 input_section, rel->r_offset);
3695 if (offset != (bfd_vma)-1)
3696 _frvfdpic_add_dyn_reloc (output_bfd,
3697 frvfdpic_gotrel_section (info),
3698 offset + input_section
3699 ->output_section->vma
3700 + input_section->output_offset,
3701 r_type, dynindx, addend, picrel);
3704 addend += frvfdpic_got_section (info)->output_section->vma;
3707 /* We want the addend in-place because dynamic
3708 relocations are REL. Setting relocation to it should
3709 arrange for it to be installed. */
3710 relocation = addend - rel->r_addend;
3712 check_segment[0] = check_segment[1] = got_segment;
3716 if (! IS_FDPIC (output_bfd))
3718 check_segment[0] = check_segment[1] = -1;
3722 case R_FRV_FUNCDESC_VALUE:
3725 bfd_vma addend = rel->r_addend;
3727 /* If the symbol is dynamic but binds locally, use
3729 if (h && ! FRVFDPIC_SYM_LOCAL (info, h))
3731 if (addend && r_type == R_FRV_FUNCDESC_VALUE)
3733 info->callbacks->warning
3734 (info, _("R_FRV_FUNCDESC_VALUE references dynamic symbol with nonzero addend"),
3735 name, input_bfd, input_section, rel->r_offset);
3738 dynindx = h->dynindx;
3743 addend += h->root.u.def.value;
3745 addend += sym->st_value;
3747 addend += osec->output_offset;
3748 if (osec && osec->output_section
3749 && ! bfd_is_abs_section (osec->output_section)
3750 && ! bfd_is_und_section (osec->output_section))
3751 dynindx = elf_section_data (osec->output_section)->dynindx;
3756 /* If we're linking an executable at a fixed address, we
3757 can omit the dynamic relocation as long as the symbol
3758 is defined in the current link unit (which is implied
3759 by its output section not being NULL). */
3760 if (info->executable && !info->pie
3761 && (!h || FRVFDPIC_SYM_LOCAL (info, h)))
3764 addend += osec->output_section->vma;
3765 if (IS_FDPIC (input_bfd)
3766 && (bfd_get_section_flags (output_bfd,
3767 input_section->output_section)
3768 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
3770 if (_frvfdpic_osec_readonly_p (output_bfd,
3774 info->callbacks->warning
3776 _("cannot emit fixups in read-only section"),
3777 name, input_bfd, input_section, rel->r_offset);
3780 if (!h || h->root.type != bfd_link_hash_undefweak)
3782 bfd_vma offset = _bfd_elf_section_offset
3784 input_section, rel->r_offset);
3786 if (offset != (bfd_vma)-1)
3788 _frvfdpic_add_rofixup (output_bfd,
3789 frvfdpic_gotfixup_section
3791 offset + input_section
3792 ->output_section->vma
3793 + input_section->output_offset,
3795 if (r_type == R_FRV_FUNCDESC_VALUE)
3796 _frvfdpic_add_rofixup
3798 frvfdpic_gotfixup_section (info),
3800 + input_section->output_section->vma
3801 + input_section->output_offset + 4, picrel);
3808 if ((bfd_get_section_flags (output_bfd,
3809 input_section->output_section)
3810 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
3814 if (_frvfdpic_osec_readonly_p (output_bfd,
3818 info->callbacks->warning
3820 _("cannot emit dynamic relocations in read-only section"),
3821 name, input_bfd, input_section, rel->r_offset);
3825 offset = _bfd_elf_section_offset
3827 input_section, rel->r_offset);
3829 if (offset != (bfd_vma)-1)
3830 _frvfdpic_add_dyn_reloc (output_bfd,
3831 frvfdpic_gotrel_section (info),
3832 offset + input_section
3833 ->output_section->vma
3834 + input_section->output_offset,
3835 r_type, dynindx, addend, picrel);
3838 addend += osec->output_section->vma;
3839 /* We want the addend in-place because dynamic
3840 relocations are REL. Setting relocation to it
3841 should arrange for it to be installed. */
3842 relocation = addend - rel->r_addend;
3845 if (r_type == R_FRV_FUNCDESC_VALUE)
3847 /* If we've omitted the dynamic relocation, just emit
3848 the fixed addresses of the symbol and of the local
3850 if (info->executable && !info->pie
3851 && (!h || FRVFDPIC_SYM_LOCAL (info, h)))
3852 bfd_put_32 (output_bfd,
3853 frvfdpic_got_section (info)->output_section->vma
3854 + frvfdpic_got_section (info)->output_offset
3855 + frvfdpic_got_initial_offset (info),
3856 contents + rel->r_offset + 4);
3858 /* A function descriptor used for lazy or local
3859 resolving is initialized such that its high word
3860 contains the output section index in which the
3861 PLT entries are located, and the low word
3862 contains the offset of the lazy PLT entry entry
3863 point into that section. */
3864 bfd_put_32 (output_bfd,
3865 h && ! FRVFDPIC_SYM_LOCAL (info, h)
3867 : _frvfdpic_osec_to_segment (output_bfd,
3870 contents + rel->r_offset + 4);
3873 check_segment[0] = check_segment[1] = got_segment;
3877 case R_FRV_GPRELU12:
3881 check_segment[0] = gprel_segment;
3882 check_segment[1] = sec
3883 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3887 case R_FRV_GETTLSOFF:
3888 relocation = frvfdpic_plt_section (info)->output_section->vma
3889 + frvfdpic_plt_section (info)->output_offset
3890 + picrel->tlsplt_entry;
3891 BFD_ASSERT (picrel->tlsplt_entry != (bfd_vma)-1
3892 && picrel->tlsdesc_entry);
3893 check_segment[0] = isec_segment;
3894 check_segment[1] = plt_segment;
3897 case R_FRV_GOTTLSDESC12:
3898 case R_FRV_GOTTLSDESCHI:
3899 case R_FRV_GOTTLSDESCLO:
3900 BFD_ASSERT (picrel->tlsdesc_entry);
3901 relocation = picrel->tlsdesc_entry;
3902 check_segment[0] = tls_segment;
3903 check_segment[1] = sec
3904 && ! bfd_is_abs_section (sec)
3905 && ! bfd_is_und_section (sec)
3906 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3910 case R_FRV_TLSMOFF12:
3911 case R_FRV_TLSMOFFHI:
3912 case R_FRV_TLSMOFFLO:
3914 check_segment[0] = tls_segment;
3916 check_segment[1] = -1;
3917 else if (bfd_is_abs_section (sec)
3918 || bfd_is_und_section (sec))
3921 check_segment[1] = tls_segment;
3923 else if (sec->output_section)
3925 relocation -= tls_biased_base (info);
3927 _frvfdpic_osec_to_segment (output_bfd, sec->output_section);
3930 check_segment[1] = -1;
3933 case R_FRV_GOTTLSOFF12:
3934 case R_FRV_GOTTLSOFFHI:
3935 case R_FRV_GOTTLSOFFLO:
3936 BFD_ASSERT (picrel->tlsoff_entry);
3937 relocation = picrel->tlsoff_entry;
3938 check_segment[0] = tls_segment;
3939 check_segment[1] = sec
3940 && ! bfd_is_abs_section (sec)
3941 && ! bfd_is_und_section (sec)
3942 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3946 case R_FRV_TLSDESC_VALUE:
3948 /* These shouldn't be present in input object files. */
3949 check_segment[0] = check_segment[1] = isec_segment;
3952 case R_FRV_TLSDESC_RELAX:
3953 case R_FRV_GETTLSOFF_RELAX:
3954 case R_FRV_TLSOFF_RELAX:
3955 /* These are just annotations for relaxation, nothing to do
3960 check_segment[0] = isec_segment;
3961 check_segment[1] = sec
3962 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3967 if (check_segment[0] != check_segment[1] && IS_FDPIC (output_bfd))
3969 /* If you take this out, remove the #error from fdpic-static-6.d
3970 in the ld testsuite. */
3971 /* This helps catch problems in GCC while we can't do more
3972 than static linking. The idea is to test whether the
3973 input file basename is crt0.o only once. */
3974 if (silence_segment_error == 1)
3975 silence_segment_error =
3976 (strlen (input_bfd->filename) == 6
3977 && strcmp (input_bfd->filename, "crt0.o") == 0)
3978 || (strlen (input_bfd->filename) > 6
3979 && strcmp (input_bfd->filename
3980 + strlen (input_bfd->filename) - 7,
3983 if (!silence_segment_error
3984 /* We don't want duplicate errors for undefined
3986 && !(picrel && picrel->symndx == -1
3987 && picrel->d.h->root.type == bfd_link_hash_undefined))
3989 if (info->shared || info->pie)
3990 (*_bfd_error_handler)
3991 (_("%B(%A+0x%lx): reloc against `%s': %s"),
3992 input_bfd, input_section, (long)rel->r_offset, name,
3993 _("relocation references a different segment"));
3995 info->callbacks->warning
3997 _("relocation references a different segment"),
3998 name, input_bfd, input_section, rel->r_offset);
4000 if (!silence_segment_error && (info->shared || info->pie))
4002 elf_elfheader (output_bfd)->e_flags |= EF_FRV_PIC;
4007 case R_FRV_GOTOFFHI:
4008 case R_FRV_TLSMOFFHI:
4009 /* We need the addend to be applied before we shift the
4011 relocation += rel->r_addend;
4014 case R_FRV_FUNCDESC_GOTHI:
4015 case R_FRV_FUNCDESC_GOTOFFHI:
4016 case R_FRV_GOTTLSOFFHI:
4017 case R_FRV_GOTTLSDESCHI:
4022 case R_FRV_FUNCDESC_GOTLO:
4023 case R_FRV_GOTOFFLO:
4024 case R_FRV_FUNCDESC_GOTOFFLO:
4025 case R_FRV_GOTTLSOFFLO:
4026 case R_FRV_GOTTLSDESCLO:
4027 case R_FRV_TLSMOFFLO:
4028 relocation &= 0xffff;
4038 if (! IS_FDPIC (output_bfd) || ! picrel->plt)
4042 /* When referencing a GOT entry, a function descriptor or a
4043 PLT, we don't want the addend to apply to the reference,
4044 but rather to the referenced symbol. The actual entry
4045 will have already been created taking the addend into
4046 account, so cancel it out here. */
4050 case R_FRV_FUNCDESC_GOT12:
4051 case R_FRV_FUNCDESC_GOTHI:
4052 case R_FRV_FUNCDESC_GOTLO:
4053 case R_FRV_FUNCDESC_GOTOFF12:
4054 case R_FRV_FUNCDESC_GOTOFFHI:
4055 case R_FRV_FUNCDESC_GOTOFFLO:
4056 case R_FRV_GETTLSOFF:
4057 case R_FRV_GOTTLSDESC12:
4058 case R_FRV_GOTTLSDESCHI:
4059 case R_FRV_GOTTLSDESCLO:
4060 case R_FRV_GOTTLSOFF12:
4061 case R_FRV_GOTTLSOFFHI:
4062 case R_FRV_GOTTLSOFFLO:
4063 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
4064 here, since we do want to apply the addend to the others.
4065 Note that we've applied the addend to GOTOFFHI before we
4066 shifted it right. */
4067 case R_FRV_GOTOFFHI:
4068 case R_FRV_TLSMOFFHI:
4069 relocation -= rel->r_addend;
4076 if (r_type == R_FRV_HI16)
4077 r = elf32_frv_relocate_hi16 (input_bfd, rel, contents, relocation);
4079 else if (r_type == R_FRV_LO16)
4080 r = elf32_frv_relocate_lo16 (input_bfd, rel, contents, relocation);
4082 else if (r_type == R_FRV_LABEL24 || r_type == R_FRV_GETTLSOFF)
4083 r = elf32_frv_relocate_label24 (input_bfd, input_section, rel,
4084 contents, relocation);
4086 else if (r_type == R_FRV_GPREL12)
4087 r = elf32_frv_relocate_gprel12 (info, input_bfd, input_section, rel,
4088 contents, relocation);
4090 else if (r_type == R_FRV_GPRELU12)
4091 r = elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, rel,
4092 contents, relocation);
4094 else if (r_type == R_FRV_GPRELLO)
4095 r = elf32_frv_relocate_gprello (info, input_bfd, input_section, rel,
4096 contents, relocation);
4098 else if (r_type == R_FRV_GPRELHI)
4099 r = elf32_frv_relocate_gprelhi (info, input_bfd, input_section, rel,
4100 contents, relocation);
4102 else if (r_type == R_FRV_TLSOFF
4103 || r_type == R_FRV_TLSDESC_VALUE)
4104 r = bfd_reloc_notsupported;
4107 r = frv_final_link_relocate (howto, input_bfd, input_section, contents,
4110 if (r != bfd_reloc_ok)
4112 const char * msg = (const char *) NULL;
4116 case bfd_reloc_overflow:
4117 r = info->callbacks->reloc_overflow
4118 (info, (h ? &h->root : NULL), name, howto->name,
4119 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
4122 case bfd_reloc_undefined:
4123 r = info->callbacks->undefined_symbol
4124 (info, name, input_bfd, input_section, rel->r_offset, TRUE);
4127 case bfd_reloc_outofrange:
4128 msg = _("internal error: out of range error");
4131 case bfd_reloc_notsupported:
4132 msg = _("internal error: unsupported relocation error");
4135 case bfd_reloc_dangerous:
4136 msg = _("internal error: dangerous relocation");
4140 msg = _("internal error: unknown error");
4146 (*_bfd_error_handler)
4147 (_("%B(%A+0x%lx): reloc against `%s': %s"),
4148 input_bfd, input_section, (long)rel->r_offset, name, msg);
4160 /* Return the section that should be marked against GC for a given
4164 elf32_frv_gc_mark_hook (asection *sec,
4165 struct bfd_link_info *info,
4166 Elf_Internal_Rela *rel,
4167 struct elf_link_hash_entry *h,
4168 Elf_Internal_Sym *sym)
4171 switch (ELF32_R_TYPE (rel->r_info))
4173 case R_FRV_GNU_VTINHERIT:
4174 case R_FRV_GNU_VTENTRY:
4178 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
4181 /* Hook called by the linker routine which adds symbols from an object
4182 file. We use it to put .comm items in .scomm, and not .comm. */
4185 elf32_frv_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
4187 struct bfd_link_info *info;
4188 Elf_Internal_Sym *sym;
4189 const char **namep ATTRIBUTE_UNUSED;
4190 flagword *flagsp ATTRIBUTE_UNUSED;
4194 if (sym->st_shndx == SHN_COMMON
4195 && !info->relocatable
4196 && (int)sym->st_size <= (int)bfd_get_gp_size (abfd))
4198 /* Common symbols less than or equal to -G nn bytes are
4199 automatically put into .sbss. */
4201 asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
4205 scomm = bfd_make_section_with_flags (abfd, ".scommon",
4208 | SEC_LINKER_CREATED));
4214 *valp = sym->st_size;
4220 /* We need dynamic symbols for every section, since segments can
4221 relocate independently. */
4223 _frvfdpic_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED,
4224 struct bfd_link_info *info
4226 asection *p ATTRIBUTE_UNUSED)
4228 switch (elf_section_data (p)->this_hdr.sh_type)
4232 /* If sh_type is yet undecided, assume it could be
4233 SHT_PROGBITS/SHT_NOBITS. */
4237 /* There shouldn't be section relative relocations
4238 against any other section. */
4244 /* Create a .got section, as well as its additional info field. This
4245 is almost entirely copied from
4246 elflink.c:_bfd_elf_create_got_section(). */
4249 _frv_create_got_section (bfd *abfd, struct bfd_link_info *info)
4251 flagword flags, pltflags;
4253 struct elf_link_hash_entry *h;
4254 struct bfd_link_hash_entry *bh;
4255 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
4259 /* This function may be called more than once. */
4260 s = bfd_get_section_by_name (abfd, ".got");
4261 if (s != NULL && (s->flags & SEC_LINKER_CREATED) != 0)
4264 /* Machine specific: although pointers are 32-bits wide, we want the
4265 GOT to be aligned to a 64-bit boundary, such that function
4266 descriptors in it can be accessed with 64-bit loads and
4270 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4271 | SEC_LINKER_CREATED);
4274 s = bfd_make_section_with_flags (abfd, ".got", flags);
4276 || !bfd_set_section_alignment (abfd, s, ptralign))
4279 if (bed->want_got_plt)
4281 s = bfd_make_section_with_flags (abfd, ".got.plt", flags);
4283 || !bfd_set_section_alignment (abfd, s, ptralign))
4287 if (bed->want_got_sym)
4289 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
4290 (or .got.plt) section. We don't do this in the linker script
4291 because we don't want to define the symbol if we are not creating
4292 a global offset table. */
4293 h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_");
4294 elf_hash_table (info)->hgot = h;
4298 /* Machine-specific: we want the symbol for executables as
4300 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4304 /* The first bit of the global offset table is the header. */
4305 s->size += bed->got_header_size;
4307 /* This is the machine-specific part. Create and initialize section
4308 data for the got. */
4309 if (IS_FDPIC (abfd))
4311 frvfdpic_got_section (info) = s;
4312 frvfdpic_relocs_info (info) = htab_try_create (1,
4313 frvfdpic_relocs_info_hash,
4314 frvfdpic_relocs_info_eq,
4316 if (! frvfdpic_relocs_info (info))
4319 s = bfd_make_section_with_flags (abfd, ".rel.got",
4320 (flags | SEC_READONLY));
4322 || ! bfd_set_section_alignment (abfd, s, 2))
4325 frvfdpic_gotrel_section (info) = s;
4327 /* Machine-specific. */
4328 s = bfd_make_section_with_flags (abfd, ".rofixup",
4329 (flags | SEC_READONLY));
4331 || ! bfd_set_section_alignment (abfd, s, 2))
4334 frvfdpic_gotfixup_section (info) = s;
4341 flags = BSF_GLOBAL | BSF_WEAK;
4344 /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it
4345 turns out that we're linking with a different linker script, the
4346 linker script will override it. */
4348 if (!(_bfd_generic_link_add_one_symbol
4349 (info, abfd, "_gp", flags, s, offset, (const char *) NULL, FALSE,
4350 bed->collect, &bh)))
4352 h = (struct elf_link_hash_entry *) bh;
4354 h->type = STT_OBJECT;
4355 /* h->other = STV_HIDDEN; */ /* Should we? */
4357 /* Machine-specific: we want the symbol for executables as well. */
4358 if (IS_FDPIC (abfd) && ! bfd_elf_link_record_dynamic_symbol (info, h))
4361 if (!IS_FDPIC (abfd))
4364 /* FDPIC supports Thread Local Storage, and this may require a
4365 procedure linkage table for TLS PLT entries. */
4367 /* This is mostly copied from
4368 elflink.c:_bfd_elf_create_dynamic_sections(). */
4371 pltflags |= SEC_CODE;
4372 if (bed->plt_not_loaded)
4373 pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS);
4374 if (bed->plt_readonly)
4375 pltflags |= SEC_READONLY;
4377 s = bfd_make_section_with_flags (abfd, ".plt", pltflags);
4379 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
4381 /* FRV-specific: remember it. */
4382 frvfdpic_plt_section (info) = s;
4384 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
4386 if (bed->want_plt_sym)
4388 h = _bfd_elf_define_linkage_sym (abfd, info, s,
4389 "_PROCEDURE_LINKAGE_TABLE_");
4390 elf_hash_table (info)->hplt = h;
4395 /* FRV-specific: we want rel relocations for the plt. */
4396 s = bfd_make_section_with_flags (abfd, ".rel.plt",
4397 flags | SEC_READONLY);
4399 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
4401 /* FRV-specific: remember it. */
4402 frvfdpic_pltrel_section (info) = s;
4407 /* Make sure the got and plt sections exist, and that our pointers in
4408 the link hash table point to them. */
4411 elf32_frvfdpic_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
4413 /* This is mostly copied from
4414 elflink.c:_bfd_elf_create_dynamic_sections(). */
4417 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
4419 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4420 | SEC_LINKER_CREATED);
4422 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
4423 .rel[a].bss sections. */
4425 /* FRV-specific: we want to create the GOT and the PLT in the FRV
4427 if (! _frv_create_got_section (abfd, info))
4430 /* FRV-specific: make sure we created everything we wanted. */
4431 BFD_ASSERT (frvfdpic_got_section (info) && frvfdpic_gotrel_section (info)
4432 && frvfdpic_gotfixup_section (info)
4433 && frvfdpic_plt_section (info)
4434 && frvfdpic_pltrel_section (info));
4436 if (bed->want_dynbss)
4438 /* The .dynbss section is a place to put symbols which are defined
4439 by dynamic objects, are referenced by regular objects, and are
4440 not functions. We must allocate space for them in the process
4441 image and use a R_*_COPY reloc to tell the dynamic linker to
4442 initialize them at run time. The linker script puts the .dynbss
4443 section into the .bss section of the final image. */
4444 s = bfd_make_section_with_flags (abfd, ".dynbss",
4445 SEC_ALLOC | SEC_LINKER_CREATED);
4449 /* The .rel[a].bss section holds copy relocs. This section is not
4450 normally needed. We need to create it here, though, so that the
4451 linker will map it to an output section. We can't just create it
4452 only if we need it, because we will not know whether we need it
4453 until we have seen all the input files, and the first time the
4454 main linker code calls BFD after examining all the input files
4455 (size_dynamic_sections) the input sections have already been
4456 mapped to the output sections. If the section turns out not to
4457 be needed, we can discard it later. We will never need this
4458 section when generating a shared object, since they do not use
4462 s = bfd_make_section_with_flags (abfd,
4463 (bed->default_use_rela_p
4464 ? ".rela.bss" : ".rel.bss"),
4465 flags | SEC_READONLY);
4467 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
4475 /* Compute the total GOT and PLT size required by each symbol in each
4476 range. Symbols may require up to 4 words in the GOT: an entry
4477 pointing to the symbol, an entry pointing to its function
4478 descriptor, and a private function descriptors taking two
4482 _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info *entry,
4483 struct _frvfdpic_dynamic_got_info *dinfo)
4485 /* Allocate space for a GOT entry pointing to the symbol. */
4488 else if (entry->gotlos)
4490 else if (entry->gothilo)
4491 dinfo->gothilo += 4;
4496 /* Allocate space for a GOT entry pointing to the function
4500 else if (entry->fdgotlos)
4502 else if (entry->fdgothilo)
4503 dinfo->gothilo += 4;
4508 /* Decide whether we need a PLT entry, a function descriptor in the
4509 GOT, and a lazy PLT entry for this symbol. */
4510 entry->plt = entry->call
4511 && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
4512 && elf_hash_table (dinfo->info)->dynamic_sections_created;
4513 entry->privfd = entry->plt
4514 || entry->fdgoff12 || entry->fdgofflos || entry->fdgoffhilo
4515 || ((entry->fd || entry->fdgot12 || entry->fdgotlos || entry->fdgothilo)
4516 && (entry->symndx != -1
4517 || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h)));
4518 entry->lazyplt = entry->privfd
4519 && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
4520 && ! (dinfo->info->flags & DF_BIND_NOW)
4521 && elf_hash_table (dinfo->info)->dynamic_sections_created;
4523 /* Allocate space for a function descriptor. */
4524 if (entry->fdgoff12)
4526 else if (entry->fdgofflos)
4528 else if (entry->privfd && entry->plt)
4530 else if (entry->privfd)
4540 /* Compute the total GOT size required by each TLS symbol in each
4541 range. Symbols may require up to 5 words in the GOT: an entry
4542 holding the TLS offset for the symbol, and an entry with a full TLS
4543 descriptor taking 4 words. */
4546 _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info *entry,
4547 struct _frvfdpic_dynamic_got_info *dinfo,
4548 bfd_boolean subtract)
4550 const int l = subtract ? -1 : 1;
4552 /* Allocate space for a GOT entry with the TLS offset of the
4554 if (entry->tlsoff12)
4555 dinfo->got12 += 4 * l;
4556 else if (entry->tlsofflos)
4557 dinfo->gotlos += 4 * l;
4558 else if (entry->tlsoffhilo)
4559 dinfo->gothilo += 4 * l;
4561 entry->relocstlsoff -= l;
4562 entry->relocstlsoff += l;
4564 /* If there's any TLSOFF relocation, mark the output file as not
4565 suitable for dlopening. This mark will remain even if we relax
4566 all such relocations, but this is not a problem, since we'll only
4567 do so for executables, and we definitely don't want anyone
4568 dlopening executables. */
4569 if (entry->relocstlsoff)
4570 dinfo->info->flags |= DF_STATIC_TLS;
4572 /* Allocate space for a TLS descriptor. */
4573 if (entry->tlsdesc12)
4574 dinfo->tlsd12 += 8 * l;
4575 else if (entry->tlsdesclos)
4576 dinfo->tlsdlos += 8 * l;
4577 else if (entry->tlsplt)
4578 dinfo->tlsdplt += 8 * l;
4579 else if (entry->tlsdeschilo)
4580 dinfo->tlsdhilo += 8 * l;
4582 entry->relocstlsd -= l;
4583 entry->relocstlsd += l;
4586 /* Compute the number of dynamic relocations and fixups that a symbol
4587 requires, and add (or subtract) from the grand and per-symbol
4591 _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info *entry,
4592 struct _frvfdpic_dynamic_got_info *dinfo,
4593 bfd_boolean subtract)
4595 bfd_vma relocs = 0, fixups = 0, tlsrets = 0;
4597 if (!dinfo->info->executable || dinfo->info->pie)
4599 relocs = entry->relocs32 + entry->relocsfd + entry->relocsfdv
4600 + entry->relocstlsd;
4602 /* In the executable, TLS relocations to symbols that bind
4603 locally (including those that resolve to global TLS offsets)
4604 are resolved immediately, without any need for fixups or
4605 dynamic relocations. In shared libraries, however, we must
4606 emit dynamic relocations even for local symbols, because we
4607 don't know the module id the library is going to get at
4608 run-time, nor its TLS base offset. */
4609 if (!dinfo->info->executable
4610 || (entry->symndx == -1
4611 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)))
4612 relocs += entry->relocstlsoff;
4616 if (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h))
4618 if (entry->symndx != -1
4619 || entry->d.h->root.type != bfd_link_hash_undefweak)
4620 fixups += entry->relocs32 + 2 * entry->relocsfdv;
4621 fixups += entry->relocstlsd;
4622 tlsrets += entry->relocstlsd;
4626 relocs += entry->relocs32 + entry->relocsfdv
4627 + entry->relocstlsoff + entry->relocstlsd;
4630 if (entry->symndx != -1
4631 || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h))
4633 if (entry->symndx != -1
4634 || entry->d.h->root.type != bfd_link_hash_undefweak)
4635 fixups += entry->relocsfd;
4638 relocs += entry->relocsfd;
4645 tlsrets = - tlsrets;
4648 entry->dynrelocs += relocs;
4649 entry->fixups += fixups;
4650 dinfo->relocs += relocs;
4651 dinfo->fixups += fixups;
4652 dinfo->tls_ret_refs += tlsrets;
4655 /* Look for opportunities to relax TLS relocations. We can assume
4656 we're linking the main executable or a static-tls library, since
4657 otherwise we wouldn't have got here. When relaxing, we have to
4658 first undo any previous accounting of TLS uses of fixups, dynamic
4659 relocations, GOT and PLT entries. */
4662 _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info *entry,
4663 struct _frvfdpic_dynamic_got_info *dinfo,
4664 bfd_boolean relaxing)
4666 bfd_boolean changed = ! relaxing;
4668 BFD_ASSERT (dinfo->info->executable
4669 || (dinfo->info->flags & DF_STATIC_TLS));
4671 if (entry->tlsdesc12 || entry->tlsdesclos || entry->tlsdeschilo)
4675 _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE);
4676 _frvfdpic_count_tls_entries (entry, dinfo, TRUE);
4680 /* When linking an executable, we can always decay GOTTLSDESC to
4681 TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise.
4682 When linking a static-tls shared library, using TLSMOFF is
4683 not an option, but we can still use GOTTLSOFF. When decaying
4684 to GOTTLSOFF, we must keep the GOT entry in range. We know
4685 it has to fit because we'll be trading the 4 words of hte TLS
4686 descriptor for a single word in the same range. */
4687 if (! dinfo->info->executable
4688 || (entry->symndx == -1
4689 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)))
4691 entry->tlsoff12 |= entry->tlsdesc12;
4692 entry->tlsofflos |= entry->tlsdesclos;
4693 entry->tlsoffhilo |= entry->tlsdeschilo;
4696 entry->tlsdesc12 = entry->tlsdesclos = entry->tlsdeschilo = 0;
4699 /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the
4700 main executable. We have to check whether the symbol's TLSOFF is
4701 in range for a setlos. For symbols with a hash entry, we can
4702 determine exactly what to do; for others locals, we don't have
4703 addresses handy, so we use the size of the TLS section as an
4704 approximation. If we get it wrong, we'll retain a GOT entry
4705 holding the TLS offset (without dynamic relocations or fixups),
4706 but we'll still optimize away the loads from it. Since TLS sizes
4707 are generally very small, it's probably not worth attempting to
4708 do better than this. */
4710 || entry->tlsoff12 || entry->tlsofflos || entry->tlsoffhilo)
4711 && dinfo->info->executable && relaxing
4712 && ((entry->symndx == -1
4713 && FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
4714 /* The above may hold for an undefweak TLS symbol, so make
4715 sure we don't have this case before accessing def.value
4717 && (entry->d.h->root.type == bfd_link_hash_undefweak
4718 || (bfd_vma)(entry->d.h->root.u.def.value
4719 + (entry->d.h->root.u.def.section
4720 ->output_section->vma)
4721 + entry->d.h->root.u.def.section->output_offset
4723 - tls_biased_base (dinfo->info)
4724 + 32768) < (bfd_vma)65536))
4725 || (entry->symndx != -1
4726 && (elf_hash_table (dinfo->info)->tls_sec->size
4727 + abs (entry->addend) < 32768 + FRVFDPIC_TLS_BIAS))))
4731 _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE);
4732 _frvfdpic_count_tls_entries (entry, dinfo, TRUE);
4737 entry->tlsoff12 = entry->tlsofflos = entry->tlsoffhilo = 0;
4740 /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already
4741 have a #gottlsoff12 relocation for this entry, or if we can fit
4742 one more in the 12-bit (and 16-bit) ranges. */
4746 && dinfo->got12 + dinfo->fd12 + dinfo->tlsd12 <= 4096 - 12 - 4
4747 && (dinfo->got12 + dinfo->fd12 + dinfo->tlsd12
4748 + dinfo->gotlos + dinfo->fdlos + dinfo->tlsdlos
4749 <= 65536 - 12 - 4))))
4753 _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE);
4754 _frvfdpic_count_tls_entries (entry, dinfo, TRUE);
4758 entry->tlsoff12 = 1;
4764 _frvfdpic_count_tls_entries (entry, dinfo, FALSE);
4765 _frvfdpic_count_relocs_fixups (entry, dinfo, FALSE);
4771 /* Compute the total GOT and PLT size required by each symbol in each range. *
4772 Symbols may require up to 4 words in the GOT: an entry pointing to
4773 the symbol, an entry pointing to its function descriptor, and a
4774 private function descriptors taking two words. */
4777 _frvfdpic_count_got_plt_entries (void **entryp, void *dinfo_)
4779 struct frvfdpic_relocs_info *entry = *entryp;
4780 struct _frvfdpic_dynamic_got_info *dinfo = dinfo_;
4782 _frvfdpic_count_nontls_entries (entry, dinfo);
4784 if (dinfo->info->executable || (dinfo->info->flags & DF_STATIC_TLS))
4785 _frvfdpic_relax_tls_entries (entry, dinfo, FALSE);
4788 _frvfdpic_count_tls_entries (entry, dinfo, FALSE);
4789 _frvfdpic_count_relocs_fixups (entry, dinfo, FALSE);
4795 /* Determine the positive and negative ranges to be used by each
4796 offset range in the GOT. FDCUR and CUR, that must be aligned to a
4797 double-word boundary, are the minimum (negative) and maximum
4798 (positive) GOT offsets already used by previous ranges, except for
4799 an ODD entry that may have been left behind. GOT and FD indicate
4800 the size of GOT entries and function descriptors that must be
4801 placed within the range from -WRAP to WRAP. If there's room left,
4802 up to FDPLT bytes should be reserved for additional function
4805 inline static bfd_signed_vma
4806 _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data *gad,
4807 bfd_signed_vma fdcur,
4817 bfd_signed_vma wrapmin = -wrap;
4818 const bfd_vma tdescsz = 8;
4820 /* Start at the given initial points. */
4824 /* If we had an incoming odd word and we have any got entries that
4825 are going to use it, consume it, otherwise leave gad->odd at
4826 zero. We might force gad->odd to zero and return the incoming
4827 odd such that it is used by the next range, but then GOT entries
4828 might appear to be out of order and we wouldn't be able to
4829 shorten the GOT by one word if it turns out to end with an
4830 unpaired GOT entry. */
4840 /* If we're left with an unpaired GOT entry, compute its location
4841 such that we can return it. Otherwise, if got doesn't require an
4842 odd number of words here, either odd was already zero in the
4843 block above, or it was set to zero because got was non-zero, or
4844 got was already zero. In the latter case, we want the value of
4845 odd to carry over to the return statement, so we don't want to
4846 reset odd unless the condition below is true. */
4853 /* Compute the tentative boundaries of this range. */
4854 gad->max = cur + got;
4855 gad->min = fdcur - fd;
4858 /* If function descriptors took too much space, wrap some of them
4860 if (gad->min < wrapmin)
4862 gad->max += wrapmin - gad->min;
4863 gad->tmin = gad->min = wrapmin;
4866 /* If GOT entries took too much space, wrap some of them around.
4867 This may well cause gad->min to become lower than wrapmin. This
4868 will cause a relocation overflow later on, so we don't have to
4870 if ((bfd_vma) gad->max > wrap)
4872 gad->min -= gad->max - wrap;
4876 /* Add TLS descriptors. */
4877 gad->tmax = gad->max + tlsd;
4878 gad->tmin = gad->min;
4881 /* If TLS descriptors took too much space, wrap an integral number
4883 if ((bfd_vma) gad->tmax > wrap)
4885 bfd_vma wrapsize = gad->tmax - wrap;
4887 wrapsize += tdescsz / 2;
4888 wrapsize &= ~ tdescsz / 2;
4890 gad->tmin -= wrapsize;
4891 gad->tmax -= wrapsize;
4894 /* If there is space left and we have function descriptors
4895 referenced in PLT entries that could take advantage of shorter
4896 offsets, place them now. */
4897 if (fdplt && gad->tmin > wrapmin)
4901 if ((bfd_vma) (gad->tmin - wrapmin) < fdplt)
4902 fds = gad->tmin - wrapmin;
4912 /* If there is more space left, try to place some more function
4913 descriptors for PLT entries. */
4914 if (fdplt && (bfd_vma) gad->tmax < wrap)
4918 if ((bfd_vma) (wrap - gad->tmax) < fdplt)
4919 fds = wrap - gad->tmax;
4929 /* If there is space left and we have TLS descriptors referenced in
4930 PLT entries that could take advantage of shorter offsets, place
4932 if (tlsdplt && gad->tmin > wrapmin)
4936 if ((bfd_vma) (gad->tmin - wrapmin) < tlsdplt)
4937 tlsds = (gad->tmin - wrapmin) & ~ (tdescsz / 2);
4943 gad->tlsdplt += tlsds;
4946 /* If there is more space left, try to place some more TLS
4947 descriptors for PLT entries. Although we could try to fit an
4948 additional TLS descriptor with half of it just before before the
4949 wrap point and another right past the wrap point, this might
4950 cause us to run out of space for the next region, so don't do
4952 if (tlsdplt && (bfd_vma) gad->tmax < wrap - tdescsz / 2)
4956 if ((bfd_vma) (wrap - gad->tmax) < tlsdplt)
4957 tlsds = (wrap - gad->tmax) & ~ (tdescsz / 2);
4963 gad->tlsdplt += tlsds;
4966 /* If odd was initially computed as an offset past the wrap point,
4969 odd = gad->min + odd - gad->max;
4971 /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed
4972 before returning, so do it here too. This guarantees that,
4973 should cur and fdcur meet at the wrap point, they'll both be
4975 if (gad->cur == gad->max)
4976 gad->cur = gad->min;
4978 /* Ditto for _frvfdpic_get_tlsdesc_entry(). */
4979 gad->tcur = gad->max;
4980 if (gad->tcur == gad->tmax)
4981 gad->tcur = gad->tmin;
4986 /* Compute the location of the next GOT entry, given the allocation
4987 data for a range. */
4989 inline static bfd_signed_vma
4990 _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
4996 /* If there was an odd word left behind, use it. */
5002 /* Otherwise, use the word pointed to by cur, reserve the next
5003 as an odd word, and skip to the next pair of words, possibly
5006 gad->odd = gad->cur + 4;
5008 if (gad->cur == gad->max)
5009 gad->cur = gad->min;
5015 /* Compute the location of the next function descriptor entry in the
5016 GOT, given the allocation data for a range. */
5018 inline static bfd_signed_vma
5019 _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
5021 /* If we're at the bottom, wrap around, and only then allocate the
5022 next pair of words. */
5023 if (gad->fdcur == gad->min)
5024 gad->fdcur = gad->max;
5025 return gad->fdcur -= 8;
5028 /* Compute the location of the next TLS descriptor entry in the GOT,
5029 given the allocation data for a range. */
5030 inline static bfd_signed_vma
5031 _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
5039 /* If we're at the top of the region, wrap around to the bottom. */
5040 if (gad->tcur == gad->tmax)
5041 gad->tcur = gad->tmin;
5046 /* Assign GOT offsets for every GOT entry and function descriptor.
5047 Doing everything in a single pass is tricky. */
5050 _frvfdpic_assign_got_entries (void **entryp, void *info_)
5052 struct frvfdpic_relocs_info *entry = *entryp;
5053 struct _frvfdpic_dynamic_got_plt_info *dinfo = info_;
5056 entry->got_entry = _frvfdpic_get_got_entry (&dinfo->got12);
5057 else if (entry->gotlos)
5058 entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
5059 else if (entry->gothilo)
5060 entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
5063 entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->got12);
5064 else if (entry->fdgotlos)
5065 entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
5066 else if (entry->fdgothilo)
5067 entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
5069 if (entry->fdgoff12)
5070 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12);
5071 else if (entry->plt && dinfo->got12.fdplt)
5073 dinfo->got12.fdplt -= 8;
5074 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12);
5076 else if (entry->fdgofflos)
5077 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos);
5078 else if (entry->plt && dinfo->gotlos.fdplt)
5080 dinfo->gotlos.fdplt -= 8;
5081 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos);
5083 else if (entry->plt)
5085 dinfo->gothilo.fdplt -= 8;
5086 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo);
5088 else if (entry->privfd)
5089 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo);
5091 if (entry->tlsoff12)
5092 entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->got12);
5093 else if (entry->tlsofflos)
5094 entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
5095 else if (entry->tlsoffhilo)
5096 entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
5098 if (entry->tlsdesc12)
5099 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12);
5100 else if (entry->tlsplt && dinfo->got12.tlsdplt)
5102 dinfo->got12.tlsdplt -= 8;
5103 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12);
5105 else if (entry->tlsdesclos)
5106 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos);
5107 else if (entry->tlsplt && dinfo->gotlos.tlsdplt)
5109 dinfo->gotlos.tlsdplt -= 8;
5110 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos);
5112 else if (entry->tlsplt)
5114 dinfo->gothilo.tlsdplt -= 8;
5115 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo);
5117 else if (entry->tlsdeschilo)
5118 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo);
5123 /* Assign GOT offsets to private function descriptors used by PLT
5124 entries (or referenced by 32-bit offsets), as well as PLT entries
5125 and lazy PLT entries. */
5128 _frvfdpic_assign_plt_entries (void **entryp, void *info_)
5130 struct frvfdpic_relocs_info *entry = *entryp;
5131 struct _frvfdpic_dynamic_got_plt_info *dinfo = info_;
5134 BFD_ASSERT (entry->fd_entry);
5140 /* We use the section's raw size to mark the location of the
5142 entry->plt_entry = frvfdpic_plt_section (dinfo->g.info)->size;
5144 /* Figure out the length of this PLT entry based on the
5145 addressing mode we need to reach the function descriptor. */
5146 BFD_ASSERT (entry->fd_entry);
5147 if (entry->fd_entry >= -(1 << (12 - 1))
5148 && entry->fd_entry < (1 << (12 - 1)))
5150 else if (entry->fd_entry >= -(1 << (16 - 1))
5151 && entry->fd_entry < (1 << (16 - 1)))
5156 frvfdpic_plt_section (dinfo->g.info)->size += size;
5161 entry->lzplt_entry = dinfo->g.lzplt;
5162 dinfo->g.lzplt += 8;
5163 /* If this entry is the one that gets the resolver stub, account
5164 for the additional instruction. */
5165 if (entry->lzplt_entry % FRVFDPIC_LZPLT_BLOCK_SIZE
5166 == FRVFDPIC_LZPLT_RESOLV_LOC)
5167 dinfo->g.lzplt += 4;
5175 = frvfdpic_plt_section (dinfo->g.info)->size;
5177 if (dinfo->g.info->executable
5178 && (entry->symndx != -1
5179 || FRVFDPIC_SYM_LOCAL (dinfo->g.info, entry->d.h)))
5181 if ((bfd_signed_vma)entry->addend >= -(1 << (16 - 1))
5182 /* FIXME: here we use the size of the TLS section
5183 as an upper bound for the value of the TLS
5184 symbol, because we may not know the exact value
5185 yet. If we get it wrong, we'll just waste a
5186 word in the PLT, and we should never get even
5187 close to 32 KiB of TLS anyway. */
5188 && elf_hash_table (dinfo->g.info)->tls_sec
5189 && (elf_hash_table (dinfo->g.info)->tls_sec->size
5190 + (bfd_signed_vma)(entry->addend) <= (1 << (16 - 1))))
5195 else if (entry->tlsoff_entry)
5197 if (entry->tlsoff_entry >= -(1 << (12 - 1))
5198 && entry->tlsoff_entry < (1 << (12 - 1)))
5200 else if (entry->tlsoff_entry >= -(1 << (16 - 1))
5201 && entry->tlsoff_entry < (1 << (16 - 1)))
5208 BFD_ASSERT (entry->tlsdesc_entry);
5210 if (entry->tlsdesc_entry >= -(1 << (12 - 1))
5211 && entry->tlsdesc_entry < (1 << (12 - 1)))
5213 else if (entry->tlsdesc_entry >= -(1 << (16 - 1))
5214 && entry->tlsdesc_entry < (1 << (16 - 1)))
5220 frvfdpic_plt_section (dinfo->g.info)->size += size;
5226 /* Cancel out any effects of calling _frvfdpic_assign_got_entries and
5227 _frvfdpic_assign_plt_entries. */
5230 _frvfdpic_reset_got_plt_entries (void **entryp, void *ignore ATTRIBUTE_UNUSED)
5232 struct frvfdpic_relocs_info *entry = *entryp;
5234 entry->got_entry = 0;
5235 entry->fdgot_entry = 0;
5236 entry->fd_entry = 0;
5237 entry->plt_entry = (bfd_vma)-1;
5238 entry->lzplt_entry = (bfd_vma)-1;
5239 entry->tlsoff_entry = 0;
5240 entry->tlsdesc_entry = 0;
5241 entry->tlsplt_entry = (bfd_vma)-1;
5246 /* Follow indirect and warning hash entries so that each got entry
5247 points to the final symbol definition. P must point to a pointer
5248 to the hash table we're traversing. Since this traversal may
5249 modify the hash table, we set this pointer to NULL to indicate
5250 we've made a potentially-destructive change to the hash table, so
5251 the traversal must be restarted. */
5253 _frvfdpic_resolve_final_relocs_info (void **entryp, void *p)
5255 struct frvfdpic_relocs_info *entry = *entryp;
5258 if (entry->symndx == -1)
5260 struct elf_link_hash_entry *h = entry->d.h;
5261 struct frvfdpic_relocs_info *oentry;
5263 while (h->root.type == bfd_link_hash_indirect
5264 || h->root.type == bfd_link_hash_warning)
5265 h = (struct elf_link_hash_entry *)h->root.u.i.link;
5267 if (entry->d.h == h)
5270 oentry = frvfdpic_relocs_info_for_global (*htab, 0, h, entry->addend,
5275 /* Merge the two entries. */
5276 frvfdpic_pic_merge_early_relocs_info (oentry, entry);
5277 htab_clear_slot (*htab, entryp);
5283 /* If we can't find this entry with the new bfd hash, re-insert
5284 it, and get the traversal restarted. */
5285 if (! htab_find (*htab, entry))
5287 htab_clear_slot (*htab, entryp);
5288 entryp = htab_find_slot (*htab, entry, INSERT);
5291 /* Abort the traversal, since the whole table may have
5292 moved, and leave it up to the parent to restart the
5294 *(htab_t *)p = NULL;
5302 /* Compute the total size of the GOT, the PLT, the dynamic relocations
5303 section and the rofixup section. Assign locations for GOT and PLT
5307 _frvfdpic_size_got_plt (bfd *output_bfd,
5308 struct _frvfdpic_dynamic_got_plt_info *gpinfop)
5311 bfd_vma limit, tlslimit;
5312 struct bfd_link_info *info = gpinfop->g.info;
5313 bfd *dynobj = elf_hash_table (info)->dynobj;
5315 memcpy (frvfdpic_dynamic_got_plt_info (info), &gpinfop->g,
5316 sizeof (gpinfop->g));
5319 /* Compute the total size taken by entries in the 12-bit and 16-bit
5320 ranges, to tell how many PLT function descriptors we can bring
5321 into the 12-bit range without causing the 16-bit range to
5323 limit = odd + gpinfop->g.got12 + gpinfop->g.gotlos
5324 + gpinfop->g.fd12 + gpinfop->g.fdlos
5325 + gpinfop->g.tlsd12 + gpinfop->g.tlsdlos;
5326 if (limit < (bfd_vma)1 << 16)
5327 limit = ((bfd_vma)1 << 16) - limit;
5330 if (gpinfop->g.fdplt < limit)
5332 tlslimit = (limit - gpinfop->g.fdplt) & ~ (bfd_vma) 8;
5333 limit = gpinfop->g.fdplt;
5337 if (gpinfop->g.tlsdplt < tlslimit)
5338 tlslimit = gpinfop->g.tlsdplt;
5340 /* Determine the ranges of GOT offsets that we can use for each
5341 range of addressing modes. */
5342 odd = _frvfdpic_compute_got_alloc_data (&gpinfop->got12,
5351 (bfd_vma)1 << (12-1));
5352 odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gotlos,
5353 gpinfop->got12.tmin,
5355 gpinfop->got12.tmax,
5359 - gpinfop->got12.fdplt,
5362 - gpinfop->got12.tlsdplt,
5363 (bfd_vma)1 << (16-1));
5364 odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gothilo,
5365 gpinfop->gotlos.tmin,
5367 gpinfop->gotlos.tmax,
5371 - gpinfop->got12.fdplt
5372 - gpinfop->gotlos.fdplt,
5373 gpinfop->g.tlsdhilo,
5375 - gpinfop->got12.tlsdplt
5376 - gpinfop->gotlos.tlsdplt,
5377 (bfd_vma)1 << (32-1));
5379 /* Now assign (most) GOT offsets. */
5380 htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_got_entries,
5383 frvfdpic_got_section (info)->size = gpinfop->gothilo.tmax
5384 - gpinfop->gothilo.tmin
5385 /* If an odd word is the last word of the GOT, we don't need this
5386 word to be part of the GOT. */
5387 - (odd + 4 == gpinfop->gothilo.tmax ? 4 : 0);
5388 if (frvfdpic_got_section (info)->size == 0)
5389 frvfdpic_got_section (info)->flags |= SEC_EXCLUDE;
5390 else if (frvfdpic_got_section (info)->size == 12
5391 && ! elf_hash_table (info)->dynamic_sections_created)
5393 frvfdpic_got_section (info)->flags |= SEC_EXCLUDE;
5394 frvfdpic_got_section (info)->size = 0;
5396 /* This will be non-NULL during relaxation. The assumption is that
5397 the size of one of these sections will never grow, only shrink,
5398 so we can use the larger buffer we allocated before. */
5399 else if (frvfdpic_got_section (info)->contents == NULL)
5401 frvfdpic_got_section (info)->contents =
5402 (bfd_byte *) bfd_zalloc (dynobj,
5403 frvfdpic_got_section (info)->size);
5404 if (frvfdpic_got_section (info)->contents == NULL)
5408 if (frvfdpic_gotrel_section (info))
5409 /* Subtract the number of lzplt entries, since those will generate
5410 relocations in the pltrel section. */
5411 frvfdpic_gotrel_section (info)->size =
5412 (gpinfop->g.relocs - gpinfop->g.lzplt / 8)
5413 * get_elf_backend_data (output_bfd)->s->sizeof_rel;
5415 BFD_ASSERT (gpinfop->g.relocs == 0);
5416 if (frvfdpic_gotrel_section (info)->size == 0)
5417 frvfdpic_gotrel_section (info)->flags |= SEC_EXCLUDE;
5418 else if (frvfdpic_gotrel_section (info)->contents == NULL)
5420 frvfdpic_gotrel_section (info)->contents =
5421 (bfd_byte *) bfd_zalloc (dynobj,
5422 frvfdpic_gotrel_section (info)->size);
5423 if (frvfdpic_gotrel_section (info)->contents == NULL)
5427 frvfdpic_gotfixup_section (info)->size = (gpinfop->g.fixups + 1) * 4;
5428 if (frvfdpic_gotfixup_section (info)->size == 0)
5429 frvfdpic_gotfixup_section (info)->flags |= SEC_EXCLUDE;
5430 else if (frvfdpic_gotfixup_section (info)->contents == NULL)
5432 frvfdpic_gotfixup_section (info)->contents =
5433 (bfd_byte *) bfd_zalloc (dynobj,
5434 frvfdpic_gotfixup_section (info)->size);
5435 if (frvfdpic_gotfixup_section (info)->contents == NULL)
5439 if (frvfdpic_pltrel_section (info))
5441 frvfdpic_pltrel_section (info)->size =
5442 gpinfop->g.lzplt / 8
5443 * get_elf_backend_data (output_bfd)->s->sizeof_rel;
5444 if (frvfdpic_pltrel_section (info)->size == 0)
5445 frvfdpic_pltrel_section (info)->flags |= SEC_EXCLUDE;
5446 else if (frvfdpic_pltrel_section (info)->contents == NULL)
5448 frvfdpic_pltrel_section (info)->contents =
5449 (bfd_byte *) bfd_zalloc (dynobj,
5450 frvfdpic_pltrel_section (info)->size);
5451 if (frvfdpic_pltrel_section (info)->contents == NULL)
5456 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
5457 such that there's room for the additional instruction needed to
5458 call the resolver. Since _frvfdpic_assign_got_entries didn't
5459 account for them, our block size is 4 bytes smaller than the real
5461 if (frvfdpic_plt_section (info))
5463 frvfdpic_plt_section (info)->size = gpinfop->g.lzplt
5464 + ((gpinfop->g.lzplt + (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) - 8)
5465 / (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) * 4);
5468 /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to
5469 actually assign lazy PLT entries addresses. */
5470 gpinfop->g.lzplt = 0;
5472 /* Save information that we're going to need to generate GOT and PLT
5474 frvfdpic_got_initial_offset (info) = -gpinfop->gothilo.tmin;
5476 if (get_elf_backend_data (output_bfd)->want_got_sym)
5477 elf_hash_table (info)->hgot->root.u.def.value
5478 = frvfdpic_got_initial_offset (info);
5480 if (frvfdpic_plt_section (info))
5481 frvfdpic_plt_initial_offset (info) =
5482 frvfdpic_plt_section (info)->size;
5484 /* Allocate a ret statement at plt_initial_offset, to be used by
5485 locally-resolved TLS descriptors. */
5486 if (gpinfop->g.tls_ret_refs)
5487 frvfdpic_plt_section (info)->size += 4;
5489 htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_plt_entries,
5492 /* Allocate the PLT section contents only after
5493 _frvfdpic_assign_plt_entries has a chance to add the size of the
5494 non-lazy PLT entries. */
5495 if (frvfdpic_plt_section (info))
5497 if (frvfdpic_plt_section (info)->size == 0)
5498 frvfdpic_plt_section (info)->flags |= SEC_EXCLUDE;
5499 else if (frvfdpic_plt_section (info)->contents == NULL)
5501 frvfdpic_plt_section (info)->contents =
5502 (bfd_byte *) bfd_zalloc (dynobj,
5503 frvfdpic_plt_section (info)->size);
5504 if (frvfdpic_plt_section (info)->contents == NULL)
5512 /* Set the sizes of the dynamic sections. */
5515 elf32_frvfdpic_size_dynamic_sections (bfd *output_bfd,
5516 struct bfd_link_info *info)
5520 struct _frvfdpic_dynamic_got_plt_info gpinfo;
5522 dynobj = elf_hash_table (info)->dynobj;
5523 BFD_ASSERT (dynobj != NULL);
5525 if (elf_hash_table (info)->dynamic_sections_created)
5527 /* Set the contents of the .interp section to the interpreter. */
5528 if (info->executable)
5530 s = bfd_get_section_by_name (dynobj, ".interp");
5531 BFD_ASSERT (s != NULL);
5532 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
5533 s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
5537 memset (&gpinfo, 0, sizeof (gpinfo));
5538 gpinfo.g.info = info;
5542 htab_t relocs = frvfdpic_relocs_info (info);
5544 htab_traverse (relocs, _frvfdpic_resolve_final_relocs_info, &relocs);
5546 if (relocs == frvfdpic_relocs_info (info))
5550 htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_count_got_plt_entries,
5553 /* Allocate space to save the summary information, we're going to
5554 use it if we're doing relaxations. */
5555 frvfdpic_dynamic_got_plt_info (info) = bfd_alloc (dynobj, sizeof (gpinfo.g));
5557 if (!_frvfdpic_size_got_plt (output_bfd, &gpinfo))
5560 if (elf_hash_table (info)->dynamic_sections_created)
5562 if (frvfdpic_got_section (info)->size)
5563 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0))
5566 if (frvfdpic_pltrel_section (info)->size)
5567 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
5568 || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_REL)
5569 || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
5572 if (frvfdpic_gotrel_section (info)->size)
5573 if (!_bfd_elf_add_dynamic_entry (info, DT_REL, 0)
5574 || !_bfd_elf_add_dynamic_entry (info, DT_RELSZ, 0)
5575 || !_bfd_elf_add_dynamic_entry (info, DT_RELENT,
5576 sizeof (Elf32_External_Rel)))
5584 elf32_frvfdpic_always_size_sections (bfd *output_bfd,
5585 struct bfd_link_info *info)
5587 if (!info->relocatable)
5589 struct elf_link_hash_entry *h;
5591 /* Force a PT_GNU_STACK segment to be created. */
5592 if (! elf_tdata (output_bfd)->stack_flags)
5593 elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
5595 /* Define __stacksize if it's not defined yet. */
5596 h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize",
5597 FALSE, FALSE, FALSE);
5598 if (! h || h->root.type != bfd_link_hash_defined
5599 || h->type != STT_OBJECT
5602 struct bfd_link_hash_entry *bh = NULL;
5604 if (!(_bfd_generic_link_add_one_symbol
5605 (info, output_bfd, "__stacksize",
5606 BSF_GLOBAL, bfd_abs_section_ptr, DEFAULT_STACK_SIZE,
5607 (const char *) NULL, FALSE,
5608 get_elf_backend_data (output_bfd)->collect, &bh)))
5611 h = (struct elf_link_hash_entry *) bh;
5613 h->type = STT_OBJECT;
5614 /* This one must NOT be hidden. */
5621 /* Look for opportunities to relax TLS relocations. We can assume
5622 we're linking the main executable or a static-tls library, since
5623 otherwise we wouldn't have got here. */
5626 _frvfdpic_relax_got_plt_entries (void **entryp, void *dinfo_)
5628 struct frvfdpic_relocs_info *entry = *entryp;
5629 struct _frvfdpic_dynamic_got_info *dinfo = dinfo_;
5631 _frvfdpic_relax_tls_entries (entry, dinfo, TRUE);
5637 elf32_frvfdpic_relax_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
5638 struct bfd_link_info *info, bfd_boolean *again)
5640 struct _frvfdpic_dynamic_got_plt_info gpinfo;
5642 /* If we return early, we didn't change anything. */
5645 /* We'll do our thing when requested to relax the GOT section. */
5646 if (sec != frvfdpic_got_section (info))
5649 /* We can only relax when linking the main executable or a library
5650 that can't be dlopened. */
5651 if (! info->executable && ! (info->flags & DF_STATIC_TLS))
5654 /* If there isn't a TLS section for this binary, we can't do
5655 anything about its TLS relocations (it probably doesn't have
5657 if (elf_hash_table (info)->tls_sec == NULL)
5660 memset (&gpinfo, 0, sizeof (gpinfo));
5661 memcpy (&gpinfo.g, frvfdpic_dynamic_got_plt_info (info), sizeof (gpinfo.g));
5663 /* Now look for opportunities to relax, adjusting the GOT usage
5665 htab_traverse (frvfdpic_relocs_info (info),
5666 _frvfdpic_relax_got_plt_entries,
5669 /* If we changed anything, reset and re-assign GOT and PLT entries. */
5670 if (memcmp (frvfdpic_dynamic_got_plt_info (info),
5671 &gpinfo.g, sizeof (gpinfo.g)) != 0)
5673 /* Clear GOT and PLT assignments. */
5674 htab_traverse (frvfdpic_relocs_info (info),
5675 _frvfdpic_reset_got_plt_entries,
5678 /* The owner of the TLS section is the output bfd. There should
5679 be a better way to get to it. */
5680 if (!_frvfdpic_size_got_plt (elf_hash_table (info)->tls_sec->owner,
5684 /* Repeat until we don't make any further changes. We could fail to
5685 introduce changes in a round if, for example, the 12-bit range is
5686 full, but we later release some space by getting rid of TLS
5687 descriptors in it. We have to repeat the whole process because
5688 we might have changed the size of a section processed before this
5697 elf32_frvfdpic_modify_program_headers (bfd *output_bfd,
5698 struct bfd_link_info *info)
5700 struct elf_obj_tdata *tdata = elf_tdata (output_bfd);
5701 struct elf_segment_map *m;
5702 Elf_Internal_Phdr *p;
5704 /* objcopy and strip preserve what's already there using
5705 elf32_frvfdpic_copy_private_bfd_data (). */
5709 for (p = tdata->phdr, m = tdata->segment_map; m != NULL; m = m->next, p++)
5710 if (m->p_type == PT_GNU_STACK)
5715 struct elf_link_hash_entry *h;
5717 /* Obtain the pointer to the __stacksize symbol. */
5718 h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize",
5719 FALSE, FALSE, FALSE);
5722 while (h->root.type == bfd_link_hash_indirect
5723 || h->root.type == bfd_link_hash_warning)
5724 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5725 BFD_ASSERT (h->root.type == bfd_link_hash_defined);
5728 /* Set the header p_memsz from the symbol value. We
5729 intentionally ignore the symbol section. */
5730 if (h && h->root.type == bfd_link_hash_defined)
5731 p->p_memsz = h->root.u.def.value;
5733 p->p_memsz = DEFAULT_STACK_SIZE;
5741 /* Fill in code and data in dynamic sections. */
5744 elf32_frv_finish_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
5745 struct bfd_link_info *info ATTRIBUTE_UNUSED)
5747 /* Nothing to be done for non-FDPIC. */
5752 elf32_frvfdpic_finish_dynamic_sections (bfd *output_bfd,
5753 struct bfd_link_info *info)
5758 dynobj = elf_hash_table (info)->dynobj;
5760 if (frvfdpic_dynamic_got_plt_info (info))
5762 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs == 0);
5764 if (frvfdpic_got_section (info))
5766 BFD_ASSERT (frvfdpic_gotrel_section (info)->size
5767 == (frvfdpic_gotrel_section (info)->reloc_count
5768 * sizeof (Elf32_External_Rel)));
5770 if (frvfdpic_gotfixup_section (info))
5772 struct elf_link_hash_entry *hgot = elf_hash_table (info)->hgot;
5773 bfd_vma got_value = hgot->root.u.def.value
5774 + hgot->root.u.def.section->output_section->vma
5775 + hgot->root.u.def.section->output_offset;
5776 struct bfd_link_hash_entry *hend;
5778 _frvfdpic_add_rofixup (output_bfd, frvfdpic_gotfixup_section (info),
5781 if (frvfdpic_gotfixup_section (info)->size
5782 != (frvfdpic_gotfixup_section (info)->reloc_count * 4))
5785 (*_bfd_error_handler)
5786 ("LINKER BUG: .rofixup section size mismatch");
5790 hend = bfd_link_hash_lookup (info->hash, "__ROFIXUP_END__",
5791 FALSE, FALSE, TRUE);
5793 && (hend->type == bfd_link_hash_defined
5794 || hend->type == bfd_link_hash_defweak))
5797 frvfdpic_gotfixup_section (info)->output_section->vma
5798 + frvfdpic_gotfixup_section (info)->output_offset
5799 + frvfdpic_gotfixup_section (info)->size
5800 - hend->u.def.section->output_section->vma
5801 - hend->u.def.section->output_offset;
5802 BFD_ASSERT (hend->u.def.value == value);
5803 if (hend->u.def.value != value)
5808 if (frvfdpic_pltrel_section (info))
5810 BFD_ASSERT (frvfdpic_pltrel_section (info)->size
5811 == (frvfdpic_pltrel_section (info)->reloc_count
5812 * sizeof (Elf32_External_Rel)));
5816 if (elf_hash_table (info)->dynamic_sections_created)
5818 Elf32_External_Dyn * dyncon;
5819 Elf32_External_Dyn * dynconend;
5821 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
5823 BFD_ASSERT (sdyn != NULL);
5825 dyncon = (Elf32_External_Dyn *) sdyn->contents;
5826 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
5828 for (; dyncon < dynconend; dyncon++)
5830 Elf_Internal_Dyn dyn;
5832 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
5840 dyn.d_un.d_ptr = frvfdpic_got_section (info)->output_section->vma
5841 + frvfdpic_got_section (info)->output_offset
5842 + frvfdpic_got_initial_offset (info);
5843 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5847 dyn.d_un.d_ptr = frvfdpic_pltrel_section (info)
5848 ->output_section->vma
5849 + frvfdpic_pltrel_section (info)->output_offset;
5850 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5854 dyn.d_un.d_val = frvfdpic_pltrel_section (info)->size;
5855 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5864 /* Adjust a symbol defined by a dynamic object and referenced by a
5868 elf32_frvfdpic_adjust_dynamic_symbol
5869 (struct bfd_link_info *info ATTRIBUTE_UNUSED,
5870 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
5874 dynobj = elf_hash_table (info)->dynobj;
5876 /* Make sure we know what is going on here. */
5877 BFD_ASSERT (dynobj != NULL
5878 && (h->u.weakdef != NULL
5881 && !h->def_regular)));
5883 /* If this is a weak symbol, and there is a real definition, the
5884 processor independent code will have arranged for us to see the
5885 real definition first, and we can just use the same value. */
5886 if (h->u.weakdef != NULL)
5888 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
5889 || h->u.weakdef->root.type == bfd_link_hash_defweak);
5890 h->root.u.def.section = h->u.weakdef->root.u.def.section;
5891 h->root.u.def.value = h->u.weakdef->root.u.def.value;
5897 /* Perform any actions needed for dynamic symbols. */
5900 elf32_frvfdpic_finish_dynamic_symbol
5901 (bfd *output_bfd ATTRIBUTE_UNUSED,
5902 struct bfd_link_info *info ATTRIBUTE_UNUSED,
5903 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED,
5904 Elf_Internal_Sym *sym ATTRIBUTE_UNUSED)
5909 /* Decide whether to attempt to turn absptr or lsda encodings in
5910 shared libraries into pcrel within the given input section. */
5913 frvfdpic_elf_use_relative_eh_frame
5914 (bfd *input_bfd ATTRIBUTE_UNUSED,
5915 struct bfd_link_info *info ATTRIBUTE_UNUSED,
5916 asection *eh_frame_section ATTRIBUTE_UNUSED)
5918 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
5922 /* Adjust the contents of an eh_frame_hdr section before they're output. */
5925 frvfdpic_elf_encode_eh_address (bfd *abfd,
5926 struct bfd_link_info *info,
5927 asection *osec, bfd_vma offset,
5928 asection *loc_sec, bfd_vma loc_offset,
5931 struct elf_link_hash_entry *h;
5933 h = elf_hash_table (info)->hgot;
5934 BFD_ASSERT (h && h->root.type == bfd_link_hash_defined);
5936 if (! h || (_frvfdpic_osec_to_segment (abfd, osec)
5937 == _frvfdpic_osec_to_segment (abfd, loc_sec->output_section)))
5938 return _bfd_elf_encode_eh_address (abfd, info, osec, offset,
5939 loc_sec, loc_offset, encoded);
5941 BFD_ASSERT (_frvfdpic_osec_to_segment (abfd, osec)
5942 == (_frvfdpic_osec_to_segment
5943 (abfd, h->root.u.def.section->output_section)));
5945 *encoded = osec->vma + offset
5946 - (h->root.u.def.value
5947 + h->root.u.def.section->output_section->vma
5948 + h->root.u.def.section->output_offset);
5950 return DW_EH_PE_datarel | DW_EH_PE_sdata4;
5953 /* Look through the relocs for a section during the first phase.
5955 Besides handling virtual table relocs for gc, we have to deal with
5956 all sorts of PIC-related relocations. We describe below the
5957 general plan on how to handle such relocations, even though we only
5958 collect information at this point, storing them in hash tables for
5959 perusal of later passes.
5961 32 relocations are propagated to the linker output when creating
5962 position-independent output. LO16 and HI16 relocations are not
5963 supposed to be encountered in this case.
5965 LABEL16 should always be resolvable by the linker, since it's only
5968 LABEL24, on the other hand, is used by calls. If it turns out that
5969 the target of a call is a dynamic symbol, a PLT entry must be
5970 created for it, which triggers the creation of a private function
5971 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
5973 GPREL relocations require the referenced symbol to be in the same
5974 segment as _gp, but this can only be checked later.
5976 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
5977 exist. LABEL24 might as well, since it may require a PLT entry,
5978 that will require a got.
5980 Non-FUNCDESC GOT relocations require a GOT entry to be created
5981 regardless of whether the symbol is dynamic. However, since a
5982 global symbol that turns out to not be exported may have the same
5983 address of a non-dynamic symbol, we don't assign GOT entries at
5984 this point, such that we can share them in this case. A relocation
5985 for the GOT entry always has to be created, be it to offset a
5986 private symbol by the section load address, be it to get the symbol
5987 resolved dynamically.
5989 FUNCDESC GOT relocations require a GOT entry to be created, and
5990 handled as if a FUNCDESC relocation was applied to the GOT entry in
5993 FUNCDESC relocations referencing a symbol that turns out to NOT be
5994 dynamic cause a private function descriptor to be created. The
5995 FUNCDESC relocation then decays to a 32 relocation that points at
5996 the private descriptor. If the symbol is dynamic, the FUNCDESC
5997 relocation is propagated to the linker output, such that the
5998 dynamic linker creates the canonical descriptor, pointing to the
5999 dynamically-resolved definition of the function.
6001 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
6002 symbols that are assigned to the same segment as the GOT, but we
6003 can only check this later, after we know the complete set of
6004 symbols defined and/or exported.
6006 FUNCDESC GOTOFF relocations require a function descriptor to be
6007 created and, unless lazy binding is disabled or the symbol is not
6008 dynamic, a lazy PLT entry. Since we can't tell at this point
6009 whether a symbol is going to be dynamic, we have to decide later
6010 whether to create a lazy PLT entry or bind the descriptor directly
6011 to the private function.
6013 FUNCDESC_VALUE relocations are not supposed to be present in object
6014 files, but they may very well be simply propagated to the linker
6015 output, since they have no side effect.
6018 A function descriptor always requires a FUNCDESC_VALUE relocation.
6019 Whether it's in .plt.rel or not depends on whether lazy binding is
6020 enabled and on whether the referenced symbol is dynamic.
6022 The existence of a lazy PLT requires the resolverStub lazy PLT
6023 entry to be present.
6026 As for assignment of GOT, PLT and lazy PLT entries, and private
6027 descriptors, we might do them all sequentially, but we can do
6028 better than that. For example, we can place GOT entries and
6029 private function descriptors referenced using 12-bit operands
6030 closer to the PIC register value, such that these relocations don't
6031 overflow. Those that are only referenced with LO16 relocations
6032 could come next, but we may as well place PLT-required function
6033 descriptors in the 12-bit range to make them shorter. Symbols
6034 referenced with LO16/HI16 may come next, but we may place
6035 additional function descriptors in the 16-bit range if we can
6036 reliably tell that we've already placed entries that are ever
6037 referenced with only LO16. PLT entries are therefore generated as
6038 small as possible, while not introducing relocation overflows in
6039 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
6040 generated before or after PLT entries, but not intermingled with
6041 them, such that we can have more lazy PLT entries in range for a
6042 branch to the resolverStub. The resolverStub should be emitted at
6043 the most distant location from the first lazy PLT entry such that
6044 it's still in range for a branch, or closer, if there isn't a need
6045 for so many lazy PLT entries. Additional lazy PLT entries may be
6046 emitted after the resolverStub, as long as branches are still in
6047 range. If the branch goes out of range, longer lazy PLT entries
6050 We could further optimize PLT and lazy PLT entries by giving them
6051 priority in assignment to closer-to-gr17 locations depending on the
6052 number of occurrences of references to them (assuming a function
6053 that's called more often is more important for performance, so its
6054 PLT entry should be faster), or taking hints from the compiler.
6055 Given infinite time and money... :-) */
6058 elf32_frv_check_relocs (abfd, info, sec, relocs)
6060 struct bfd_link_info *info;
6062 const Elf_Internal_Rela *relocs;
6064 Elf_Internal_Shdr *symtab_hdr;
6065 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
6066 const Elf_Internal_Rela *rel;
6067 const Elf_Internal_Rela *rel_end;
6069 struct frvfdpic_relocs_info *picrel;
6071 if (info->relocatable)
6074 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
6075 sym_hashes = elf_sym_hashes (abfd);
6076 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf32_External_Sym);
6077 if (!elf_bad_symtab (abfd))
6078 sym_hashes_end -= symtab_hdr->sh_info;
6080 dynobj = elf_hash_table (info)->dynobj;
6081 rel_end = relocs + sec->reloc_count;
6082 for (rel = relocs; rel < rel_end; rel++)
6084 struct elf_link_hash_entry *h;
6085 unsigned long r_symndx;
6087 r_symndx = ELF32_R_SYM (rel->r_info);
6088 if (r_symndx < symtab_hdr->sh_info)
6092 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6093 while (h->root.type == bfd_link_hash_indirect
6094 || h->root.type == bfd_link_hash_warning)
6095 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6098 switch (ELF32_R_TYPE (rel->r_info))
6100 case R_FRV_GETTLSOFF:
6101 case R_FRV_TLSDESC_VALUE:
6102 case R_FRV_GOTTLSDESC12:
6103 case R_FRV_GOTTLSDESCHI:
6104 case R_FRV_GOTTLSDESCLO:
6105 case R_FRV_GOTTLSOFF12:
6106 case R_FRV_GOTTLSOFFHI:
6107 case R_FRV_GOTTLSOFFLO:
6112 case R_FRV_FUNCDESC_GOT12:
6113 case R_FRV_FUNCDESC_GOTHI:
6114 case R_FRV_FUNCDESC_GOTLO:
6115 case R_FRV_GOTOFF12:
6116 case R_FRV_GOTOFFHI:
6117 case R_FRV_GOTOFFLO:
6118 case R_FRV_FUNCDESC_GOTOFF12:
6119 case R_FRV_FUNCDESC_GOTOFFHI:
6120 case R_FRV_FUNCDESC_GOTOFFLO:
6121 case R_FRV_FUNCDESC:
6122 case R_FRV_FUNCDESC_VALUE:
6123 case R_FRV_TLSMOFF12:
6124 case R_FRV_TLSMOFFHI:
6125 case R_FRV_TLSMOFFLO:
6127 if (! IS_FDPIC (abfd))
6131 case R_FRV_GPRELU12:
6138 elf_hash_table (info)->dynobj = dynobj = abfd;
6139 if (! _frv_create_got_section (abfd, info))
6142 if (! IS_FDPIC (abfd))
6149 if (h->dynindx == -1)
6150 switch (ELF_ST_VISIBILITY (h->other))
6156 bfd_elf_link_record_dynamic_symbol (info, h);
6160 = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info),
6162 rel->r_addend, INSERT);
6165 picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
6166 (info), abfd, r_symndx,
6167 rel->r_addend, INSERT);
6177 switch (ELF32_R_TYPE (rel->r_info))
6180 if (IS_FDPIC (abfd))
6184 case R_FRV_FUNCDESC_VALUE:
6185 picrel->relocsfdv++;
6186 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
6191 if (! IS_FDPIC (abfd))
6195 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
6205 picrel->gothilo = 1;
6208 case R_FRV_FUNCDESC_GOT12:
6209 picrel->fdgot12 = 1;
6212 case R_FRV_FUNCDESC_GOTHI:
6213 case R_FRV_FUNCDESC_GOTLO:
6214 picrel->fdgothilo = 1;
6217 case R_FRV_GOTOFF12:
6218 case R_FRV_GOTOFFHI:
6219 case R_FRV_GOTOFFLO:
6223 case R_FRV_FUNCDESC_GOTOFF12:
6224 picrel->fdgoff12 = 1;
6227 case R_FRV_FUNCDESC_GOTOFFHI:
6228 case R_FRV_FUNCDESC_GOTOFFLO:
6229 picrel->fdgoffhilo = 1;
6232 case R_FRV_FUNCDESC:
6237 case R_FRV_GETTLSOFF:
6241 case R_FRV_TLSDESC_VALUE:
6242 picrel->relocstlsd++;
6245 case R_FRV_GOTTLSDESC12:
6246 picrel->tlsdesc12 = 1;
6249 case R_FRV_GOTTLSDESCHI:
6250 case R_FRV_GOTTLSDESCLO:
6251 picrel->tlsdeschilo = 1;
6254 case R_FRV_TLSMOFF12:
6255 case R_FRV_TLSMOFFHI:
6256 case R_FRV_TLSMOFFLO:
6260 case R_FRV_GOTTLSOFF12:
6261 picrel->tlsoff12 = 1;
6262 info->flags |= DF_STATIC_TLS;
6265 case R_FRV_GOTTLSOFFHI:
6266 case R_FRV_GOTTLSOFFLO:
6267 picrel->tlsoffhilo = 1;
6268 info->flags |= DF_STATIC_TLS;
6272 picrel->relocstlsoff++;
6273 info->flags |= DF_STATIC_TLS;
6276 /* This relocation describes the C++ object vtable hierarchy.
6277 Reconstruct it for later use during GC. */
6278 case R_FRV_GNU_VTINHERIT:
6279 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
6283 /* This relocation describes which C++ vtable entries are actually
6284 used. Record for later use during GC. */
6285 case R_FRV_GNU_VTENTRY:
6286 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
6294 case R_FRV_GPRELU12:
6298 case R_FRV_TLSDESC_RELAX:
6299 case R_FRV_GETTLSOFF_RELAX:
6300 case R_FRV_TLSOFF_RELAX:
6305 (*_bfd_error_handler)
6306 (_("%B: unsupported relocation type %i"),
6307 abfd, ELF32_R_TYPE (rel->r_info));
6316 /* Return the machine subcode from the ELF e_flags header. */
6319 elf32_frv_machine (abfd)
6322 switch (elf_elfheader (abfd)->e_flags & EF_FRV_CPU_MASK)
6325 case EF_FRV_CPU_FR550: return bfd_mach_fr550;
6326 case EF_FRV_CPU_FR500: return bfd_mach_fr500;
6327 case EF_FRV_CPU_FR450: return bfd_mach_fr450;
6328 case EF_FRV_CPU_FR405: return bfd_mach_fr400;
6329 case EF_FRV_CPU_FR400: return bfd_mach_fr400;
6330 case EF_FRV_CPU_FR300: return bfd_mach_fr300;
6331 case EF_FRV_CPU_SIMPLE: return bfd_mach_frvsimple;
6332 case EF_FRV_CPU_TOMCAT: return bfd_mach_frvtomcat;
6335 return bfd_mach_frv;
6338 /* Set the right machine number for a FRV ELF file. */
6341 elf32_frv_object_p (abfd)
6344 bfd_default_set_arch_mach (abfd, bfd_arch_frv, elf32_frv_machine (abfd));
6345 return (((elf_elfheader (abfd)->e_flags & EF_FRV_FDPIC) != 0)
6346 == (IS_FDPIC (abfd)));
6349 /* Function to set the ELF flag bits. */
6352 frv_elf_set_private_flags (abfd, flags)
6356 elf_elfheader (abfd)->e_flags = flags;
6357 elf_flags_init (abfd) = TRUE;
6361 /* Copy backend specific data from one object module to another. */
6364 frv_elf_copy_private_bfd_data (ibfd, obfd)
6368 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6369 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6372 BFD_ASSERT (!elf_flags_init (obfd)
6373 || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
6375 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
6376 elf_flags_init (obfd) = TRUE;
6380 /* Return true if the architecture described by elf header flag
6381 EXTENSION is an extension of the architecture described by BASE. */
6384 frv_elf_arch_extension_p (flagword base, flagword extension)
6386 if (base == extension)
6389 /* CPU_GENERIC code can be merged with code for a specific
6390 architecture, in which case the result is marked as being
6391 for the specific architecture. Everything is therefore
6392 an extension of CPU_GENERIC. */
6393 if (base == EF_FRV_CPU_GENERIC)
6396 if (extension == EF_FRV_CPU_FR450)
6397 if (base == EF_FRV_CPU_FR400 || base == EF_FRV_CPU_FR405)
6400 if (extension == EF_FRV_CPU_FR405)
6401 if (base == EF_FRV_CPU_FR400)
6408 elf32_frvfdpic_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
6412 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6413 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6416 if (! frv_elf_copy_private_bfd_data (ibfd, obfd))
6419 if (! elf_tdata (ibfd) || ! elf_tdata (ibfd)->phdr
6420 || ! elf_tdata (obfd) || ! elf_tdata (obfd)->phdr)
6423 /* Copy the stack size. */
6424 for (i = 0; i < elf_elfheader (ibfd)->e_phnum; i++)
6425 if (elf_tdata (ibfd)->phdr[i].p_type == PT_GNU_STACK)
6427 Elf_Internal_Phdr *iphdr = &elf_tdata (ibfd)->phdr[i];
6429 for (i = 0; i < elf_elfheader (obfd)->e_phnum; i++)
6430 if (elf_tdata (obfd)->phdr[i].p_type == PT_GNU_STACK)
6432 memcpy (&elf_tdata (obfd)->phdr[i], iphdr, sizeof (*iphdr));
6434 /* Rewrite the phdrs, since we're only called after they
6435 were first written. */
6436 if (bfd_seek (obfd, (bfd_signed_vma) get_elf_backend_data (obfd)
6437 ->s->sizeof_ehdr, SEEK_SET) != 0
6438 || get_elf_backend_data (obfd)->s
6439 ->write_out_phdrs (obfd, elf_tdata (obfd)->phdr,
6440 elf_elfheader (obfd)->e_phnum) != 0)
6451 /* Merge backend specific data from an object file to the output
6452 object file when linking. */
6455 frv_elf_merge_private_bfd_data (ibfd, obfd)
6459 flagword old_flags, old_partial;
6460 flagword new_flags, new_partial;
6461 bfd_boolean error = FALSE;
6465 new_opt[0] = old_opt[0] = '\0';
6466 new_flags = elf_elfheader (ibfd)->e_flags;
6467 old_flags = elf_elfheader (obfd)->e_flags;
6469 if (new_flags & EF_FRV_FDPIC)
6470 new_flags &= ~EF_FRV_PIC;
6473 (*_bfd_error_handler) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s",
6474 old_flags, new_flags, elf_flags_init (obfd) ? "yes" : "no",
6475 bfd_get_filename (ibfd));
6478 if (!elf_flags_init (obfd)) /* First call, no flags set. */
6480 elf_flags_init (obfd) = TRUE;
6481 old_flags = new_flags;
6484 else if (new_flags == old_flags) /* Compatible flags are ok. */
6487 else /* Possibly incompatible flags. */
6489 /* Warn if different # of gprs are used. Note, 0 means nothing is
6490 said about the size of gprs. */
6491 new_partial = (new_flags & EF_FRV_GPR_MASK);
6492 old_partial = (old_flags & EF_FRV_GPR_MASK);
6493 if (new_partial == old_partial)
6496 else if (new_partial == 0)
6499 else if (old_partial == 0)
6500 old_flags |= new_partial;
6504 switch (new_partial)
6506 default: strcat (new_opt, " -mgpr-??"); break;
6507 case EF_FRV_GPR_32: strcat (new_opt, " -mgpr-32"); break;
6508 case EF_FRV_GPR_64: strcat (new_opt, " -mgpr-64"); break;
6511 switch (old_partial)
6513 default: strcat (old_opt, " -mgpr-??"); break;
6514 case EF_FRV_GPR_32: strcat (old_opt, " -mgpr-32"); break;
6515 case EF_FRV_GPR_64: strcat (old_opt, " -mgpr-64"); break;
6519 /* Warn if different # of fprs are used. Note, 0 means nothing is
6520 said about the size of fprs. */
6521 new_partial = (new_flags & EF_FRV_FPR_MASK);
6522 old_partial = (old_flags & EF_FRV_FPR_MASK);
6523 if (new_partial == old_partial)
6526 else if (new_partial == 0)
6529 else if (old_partial == 0)
6530 old_flags |= new_partial;
6534 switch (new_partial)
6536 default: strcat (new_opt, " -mfpr-?"); break;
6537 case EF_FRV_FPR_32: strcat (new_opt, " -mfpr-32"); break;
6538 case EF_FRV_FPR_64: strcat (new_opt, " -mfpr-64"); break;
6539 case EF_FRV_FPR_NONE: strcat (new_opt, " -msoft-float"); break;
6542 switch (old_partial)
6544 default: strcat (old_opt, " -mfpr-?"); break;
6545 case EF_FRV_FPR_32: strcat (old_opt, " -mfpr-32"); break;
6546 case EF_FRV_FPR_64: strcat (old_opt, " -mfpr-64"); break;
6547 case EF_FRV_FPR_NONE: strcat (old_opt, " -msoft-float"); break;
6551 /* Warn if different dword support was used. Note, 0 means nothing is
6552 said about the dword support. */
6553 new_partial = (new_flags & EF_FRV_DWORD_MASK);
6554 old_partial = (old_flags & EF_FRV_DWORD_MASK);
6555 if (new_partial == old_partial)
6558 else if (new_partial == 0)
6561 else if (old_partial == 0)
6562 old_flags |= new_partial;
6566 switch (new_partial)
6568 default: strcat (new_opt, " -mdword-?"); break;
6569 case EF_FRV_DWORD_YES: strcat (new_opt, " -mdword"); break;
6570 case EF_FRV_DWORD_NO: strcat (new_opt, " -mno-dword"); break;
6573 switch (old_partial)
6575 default: strcat (old_opt, " -mdword-?"); break;
6576 case EF_FRV_DWORD_YES: strcat (old_opt, " -mdword"); break;
6577 case EF_FRV_DWORD_NO: strcat (old_opt, " -mno-dword"); break;
6581 /* Or in flags that accumulate (ie, if one module uses it, mark that the
6583 old_flags |= new_flags & (EF_FRV_DOUBLE
6586 | EF_FRV_NON_PIC_RELOCS);
6588 /* If any module was compiled without -G0, clear the G0 bit. */
6589 old_flags = ((old_flags & ~ EF_FRV_G0)
6590 | (old_flags & new_flags & EF_FRV_G0));
6592 /* If any module was compiled without -mnopack, clear the mnopack bit. */
6593 old_flags = ((old_flags & ~ EF_FRV_NOPACK)
6594 | (old_flags & new_flags & EF_FRV_NOPACK));
6596 /* We don't have to do anything if the pic flags are the same, or the new
6597 module(s) were compiled with -mlibrary-pic. */
6598 new_partial = (new_flags & EF_FRV_PIC_FLAGS);
6599 old_partial = (old_flags & EF_FRV_PIC_FLAGS);
6600 if ((new_partial == old_partial) || ((new_partial & EF_FRV_LIBPIC) != 0))
6603 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
6604 flags if any from the new module. */
6605 else if ((old_partial & EF_FRV_LIBPIC) != 0)
6606 old_flags = (old_flags & ~ EF_FRV_PIC_FLAGS) | new_partial;
6608 /* If we have mixtures of -fpic and -fPIC, or in both bits. */
6609 else if (new_partial != 0 && old_partial != 0)
6610 old_flags |= new_partial;
6612 /* One module was compiled for pic and the other was not, see if we have
6613 had any relocations that are not pic-safe. */
6616 if ((old_flags & EF_FRV_NON_PIC_RELOCS) == 0)
6617 old_flags |= new_partial;
6620 old_flags &= ~ EF_FRV_PIC_FLAGS;
6621 #ifndef FRV_NO_PIC_ERROR
6623 (*_bfd_error_handler)
6624 (_("%s: compiled with %s and linked with modules that use non-pic relocations"),
6625 bfd_get_filename (ibfd),
6626 (new_flags & EF_FRV_BIGPIC) ? "-fPIC" : "-fpic");
6631 /* Warn if different cpu is used (allow a specific cpu to override
6632 the generic cpu). */
6633 new_partial = (new_flags & EF_FRV_CPU_MASK);
6634 old_partial = (old_flags & EF_FRV_CPU_MASK);
6635 if (frv_elf_arch_extension_p (new_partial, old_partial))
6638 else if (frv_elf_arch_extension_p (old_partial, new_partial))
6639 old_flags = (old_flags & ~EF_FRV_CPU_MASK) | new_partial;
6643 switch (new_partial)
6645 default: strcat (new_opt, " -mcpu=?"); break;
6646 case EF_FRV_CPU_GENERIC: strcat (new_opt, " -mcpu=frv"); break;
6647 case EF_FRV_CPU_SIMPLE: strcat (new_opt, " -mcpu=simple"); break;
6648 case EF_FRV_CPU_FR550: strcat (new_opt, " -mcpu=fr550"); break;
6649 case EF_FRV_CPU_FR500: strcat (new_opt, " -mcpu=fr500"); break;
6650 case EF_FRV_CPU_FR450: strcat (new_opt, " -mcpu=fr450"); break;
6651 case EF_FRV_CPU_FR405: strcat (new_opt, " -mcpu=fr405"); break;
6652 case EF_FRV_CPU_FR400: strcat (new_opt, " -mcpu=fr400"); break;
6653 case EF_FRV_CPU_FR300: strcat (new_opt, " -mcpu=fr300"); break;
6654 case EF_FRV_CPU_TOMCAT: strcat (new_opt, " -mcpu=tomcat"); break;
6657 switch (old_partial)
6659 default: strcat (old_opt, " -mcpu=?"); break;
6660 case EF_FRV_CPU_GENERIC: strcat (old_opt, " -mcpu=frv"); break;
6661 case EF_FRV_CPU_SIMPLE: strcat (old_opt, " -mcpu=simple"); break;
6662 case EF_FRV_CPU_FR550: strcat (old_opt, " -mcpu=fr550"); break;
6663 case EF_FRV_CPU_FR500: strcat (old_opt, " -mcpu=fr500"); break;
6664 case EF_FRV_CPU_FR450: strcat (old_opt, " -mcpu=fr450"); break;
6665 case EF_FRV_CPU_FR405: strcat (old_opt, " -mcpu=fr405"); break;
6666 case EF_FRV_CPU_FR400: strcat (old_opt, " -mcpu=fr400"); break;
6667 case EF_FRV_CPU_FR300: strcat (old_opt, " -mcpu=fr300"); break;
6668 case EF_FRV_CPU_TOMCAT: strcat (old_opt, " -mcpu=tomcat"); break;
6672 /* Print out any mismatches from above. */
6676 (*_bfd_error_handler)
6677 (_("%s: compiled with %s and linked with modules compiled with %s"),
6678 bfd_get_filename (ibfd), new_opt, old_opt);
6681 /* Warn about any other mismatches */
6682 new_partial = (new_flags & ~ EF_FRV_ALL_FLAGS);
6683 old_partial = (old_flags & ~ EF_FRV_ALL_FLAGS);
6684 if (new_partial != old_partial)
6686 old_flags |= new_partial;
6688 (*_bfd_error_handler)
6689 (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"),
6690 bfd_get_filename (ibfd), (long)new_partial, (long)old_partial);
6694 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
6695 if ((old_flags & EF_FRV_CPU_MASK) == EF_FRV_CPU_SIMPLE)
6696 old_flags |= EF_FRV_NOPACK;
6698 /* Update the old flags now with changes made above. */
6699 old_partial = elf_elfheader (obfd)->e_flags & EF_FRV_CPU_MASK;
6700 elf_elfheader (obfd)->e_flags = old_flags;
6701 if (old_partial != (old_flags & EF_FRV_CPU_MASK))
6702 bfd_default_set_arch_mach (obfd, bfd_arch_frv, elf32_frv_machine (obfd));
6704 if (((new_flags & EF_FRV_FDPIC) == 0)
6705 != (! IS_FDPIC (ibfd)))
6708 if (IS_FDPIC (obfd))
6709 (*_bfd_error_handler)
6710 (_("%s: cannot link non-fdpic object file into fdpic executable"),
6711 bfd_get_filename (ibfd));
6713 (*_bfd_error_handler)
6714 (_("%s: cannot link fdpic object file into non-fdpic executable"),
6715 bfd_get_filename (ibfd));
6719 bfd_set_error (bfd_error_bad_value);
6726 frv_elf_print_private_bfd_data (abfd, ptr)
6730 FILE *file = (FILE *) ptr;
6733 BFD_ASSERT (abfd != NULL && ptr != NULL);
6735 /* Print normal ELF private data. */
6736 _bfd_elf_print_private_bfd_data (abfd, ptr);
6738 flags = elf_elfheader (abfd)->e_flags;
6739 fprintf (file, _("private flags = 0x%lx:"), (long)flags);
6741 switch (flags & EF_FRV_CPU_MASK)
6744 case EF_FRV_CPU_SIMPLE: fprintf (file, " -mcpu=simple"); break;
6745 case EF_FRV_CPU_FR550: fprintf (file, " -mcpu=fr550"); break;
6746 case EF_FRV_CPU_FR500: fprintf (file, " -mcpu=fr500"); break;
6747 case EF_FRV_CPU_FR450: fprintf (file, " -mcpu=fr450"); break;
6748 case EF_FRV_CPU_FR405: fprintf (file, " -mcpu=fr405"); break;
6749 case EF_FRV_CPU_FR400: fprintf (file, " -mcpu=fr400"); break;
6750 case EF_FRV_CPU_FR300: fprintf (file, " -mcpu=fr300"); break;
6751 case EF_FRV_CPU_TOMCAT: fprintf (file, " -mcpu=tomcat"); break;
6754 switch (flags & EF_FRV_GPR_MASK)
6757 case EF_FRV_GPR_32: fprintf (file, " -mgpr-32"); break;
6758 case EF_FRV_GPR_64: fprintf (file, " -mgpr-64"); break;
6761 switch (flags & EF_FRV_FPR_MASK)
6764 case EF_FRV_FPR_32: fprintf (file, " -mfpr-32"); break;
6765 case EF_FRV_FPR_64: fprintf (file, " -mfpr-64"); break;
6766 case EF_FRV_FPR_NONE: fprintf (file, " -msoft-float"); break;
6769 switch (flags & EF_FRV_DWORD_MASK)
6772 case EF_FRV_DWORD_YES: fprintf (file, " -mdword"); break;
6773 case EF_FRV_DWORD_NO: fprintf (file, " -mno-dword"); break;
6776 if (flags & EF_FRV_DOUBLE)
6777 fprintf (file, " -mdouble");
6779 if (flags & EF_FRV_MEDIA)
6780 fprintf (file, " -mmedia");
6782 if (flags & EF_FRV_MULADD)
6783 fprintf (file, " -mmuladd");
6785 if (flags & EF_FRV_PIC)
6786 fprintf (file, " -fpic");
6788 if (flags & EF_FRV_BIGPIC)
6789 fprintf (file, " -fPIC");
6791 if (flags & EF_FRV_LIBPIC)
6792 fprintf (file, " -mlibrary-pic");
6794 if (flags & EF_FRV_FDPIC)
6795 fprintf (file, " -mfdpic");
6797 if (flags & EF_FRV_NON_PIC_RELOCS)
6798 fprintf (file, " non-pic relocations");
6800 if (flags & EF_FRV_G0)
6801 fprintf (file, " -G0");
6808 /* Support for core dump NOTE sections. */
6811 elf32_frv_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
6814 unsigned int raw_size;
6816 switch (note->descsz)
6821 /* The Linux/FRV elf_prstatus struct is 268 bytes long. The other
6822 hardcoded offsets and sizes listed below (and contained within
6823 this lexical block) refer to fields in the target's elf_prstatus
6826 /* `pr_cursig' is at offset 12. */
6827 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
6829 /* `pr_pid' is at offset 24. */
6830 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
6832 /* `pr_reg' is at offset 72. */
6835 /* Most grok_prstatus implementations set `raw_size' to the size
6836 of the pr_reg field. For Linux/FRV, we set `raw_size' to be
6837 the size of `pr_reg' plus the size of `pr_exec_fdpic_loadmap'
6838 and `pr_interp_fdpic_loadmap', both of which (by design)
6839 immediately follow `pr_reg'. This will allow these fields to
6840 be viewed by GDB as registers.
6842 `pr_reg' is 184 bytes long. `pr_exec_fdpic_loadmap' and
6843 `pr_interp_fdpic_loadmap' are 4 bytes each. */
6844 raw_size = 184 + 4 + 4;
6849 /* Make a ".reg/999" section. */
6850 return _bfd_elfcore_make_pseudosection (abfd, ".reg", raw_size,
6851 note->descpos + offset);
6855 elf32_frv_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
6857 switch (note->descsz)
6862 /* The Linux/FRV elf_prpsinfo struct is 124 bytes long. */
6865 /* `pr_fname' is found at offset 28 and is 16 bytes long. */
6866 elf_tdata (abfd)->core_program
6867 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
6869 /* `pr_psargs' is found at offset 44 and is 80 bytes long. */
6870 elf_tdata (abfd)->core_command
6871 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
6874 /* Note that for some reason, a spurious space is tacked
6875 onto the end of the args in some (at least one anyway)
6876 implementations, so strip it off if it exists. */
6879 char *command = elf_tdata (abfd)->core_command;
6880 int n = strlen (command);
6882 if (0 < n && command[n - 1] == ' ')
6883 command[n - 1] = '\0';
6888 #define ELF_ARCH bfd_arch_frv
6889 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
6890 #define ELF_MAXPAGESIZE 0x1000
6892 #define TARGET_BIG_SYM bfd_elf32_frv_vec
6893 #define TARGET_BIG_NAME "elf32-frv"
6895 #define elf_info_to_howto frv_info_to_howto_rela
6896 #define elf_backend_relocate_section elf32_frv_relocate_section
6897 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
6898 #define elf_backend_check_relocs elf32_frv_check_relocs
6899 #define elf_backend_object_p elf32_frv_object_p
6900 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
6902 #define elf_backend_can_gc_sections 1
6903 #define elf_backend_rela_normal 1
6905 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
6906 #define bfd_elf32_bfd_reloc_name_lookup frv_reloc_name_lookup
6907 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
6908 #define bfd_elf32_bfd_copy_private_bfd_data frv_elf_copy_private_bfd_data
6909 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
6910 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
6912 #define elf_backend_want_got_sym 1
6913 #define elf_backend_got_header_size 0
6914 #define elf_backend_want_got_plt 0
6915 #define elf_backend_plt_readonly 1
6916 #define elf_backend_want_plt_sym 0
6917 #define elf_backend_plt_header_size 0
6919 #define elf_backend_finish_dynamic_sections \
6920 elf32_frv_finish_dynamic_sections
6922 #define elf_backend_grok_prstatus elf32_frv_grok_prstatus
6923 #define elf_backend_grok_psinfo elf32_frv_grok_psinfo
6925 #include "elf32-target.h"
6927 #undef ELF_MAXPAGESIZE
6928 #define ELF_MAXPAGESIZE 0x4000
6930 #undef TARGET_BIG_SYM
6931 #define TARGET_BIG_SYM bfd_elf32_frvfdpic_vec
6932 #undef TARGET_BIG_NAME
6933 #define TARGET_BIG_NAME "elf32-frvfdpic"
6935 #define elf32_bed elf32_frvfdpic_bed
6937 #undef elf_info_to_howto_rel
6938 #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel
6940 #undef bfd_elf32_bfd_link_hash_table_create
6941 #define bfd_elf32_bfd_link_hash_table_create \
6942 frvfdpic_elf_link_hash_table_create
6943 #undef elf_backend_always_size_sections
6944 #define elf_backend_always_size_sections \
6945 elf32_frvfdpic_always_size_sections
6946 #undef elf_backend_modify_program_headers
6947 #define elf_backend_modify_program_headers \
6948 elf32_frvfdpic_modify_program_headers
6949 #undef bfd_elf32_bfd_copy_private_bfd_data
6950 #define bfd_elf32_bfd_copy_private_bfd_data \
6951 elf32_frvfdpic_copy_private_bfd_data
6953 #undef elf_backend_create_dynamic_sections
6954 #define elf_backend_create_dynamic_sections \
6955 elf32_frvfdpic_create_dynamic_sections
6956 #undef elf_backend_adjust_dynamic_symbol
6957 #define elf_backend_adjust_dynamic_symbol \
6958 elf32_frvfdpic_adjust_dynamic_symbol
6959 #undef elf_backend_size_dynamic_sections
6960 #define elf_backend_size_dynamic_sections \
6961 elf32_frvfdpic_size_dynamic_sections
6962 #undef bfd_elf32_bfd_relax_section
6963 #define bfd_elf32_bfd_relax_section \
6964 elf32_frvfdpic_relax_section
6965 #undef elf_backend_finish_dynamic_symbol
6966 #define elf_backend_finish_dynamic_symbol \
6967 elf32_frvfdpic_finish_dynamic_symbol
6968 #undef elf_backend_finish_dynamic_sections
6969 #define elf_backend_finish_dynamic_sections \
6970 elf32_frvfdpic_finish_dynamic_sections
6972 #undef elf_backend_can_make_relative_eh_frame
6973 #define elf_backend_can_make_relative_eh_frame \
6974 frvfdpic_elf_use_relative_eh_frame
6975 #undef elf_backend_can_make_lsda_relative_eh_frame
6976 #define elf_backend_can_make_lsda_relative_eh_frame \
6977 frvfdpic_elf_use_relative_eh_frame
6978 #undef elf_backend_encode_eh_address
6979 #define elf_backend_encode_eh_address \
6980 frvfdpic_elf_encode_eh_address
6982 #undef elf_backend_may_use_rel_p
6983 #define elf_backend_may_use_rel_p 1
6984 #undef elf_backend_may_use_rela_p
6985 #define elf_backend_may_use_rela_p 1
6986 /* We use REL for dynamic relocations only. */
6987 #undef elf_backend_default_use_rela_p
6988 #define elf_backend_default_use_rela_p 1
6990 #undef elf_backend_omit_section_dynsym
6991 #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym
6993 #include "elf32-target.h"