1 /* FRV-specific support for 32-bit ELF.
2 Copyright (C) 2002-2016 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
29 /* Forward declarations. */
32 static reloc_howto_type elf32_frv_howto_table [] =
34 /* This reloc does nothing. */
35 HOWTO (R_FRV_NONE, /* type */
37 3, /* size (0 = byte, 1 = short, 2 = long) */
39 FALSE, /* pc_relative */
41 complain_overflow_dont, /* complain_on_overflow */
42 bfd_elf_generic_reloc, /* special_function */
43 "R_FRV_NONE", /* name */
44 FALSE, /* partial_inplace */
47 FALSE), /* pcrel_offset */
49 /* A 32 bit absolute relocation. */
50 HOWTO (R_FRV_32, /* type */
52 2, /* size (0 = byte, 1 = short, 2 = long) */
54 FALSE, /* pc_relative */
56 complain_overflow_bitfield, /* complain_on_overflow */
57 bfd_elf_generic_reloc, /* special_function */
58 "R_FRV_32", /* name */
59 FALSE, /* partial_inplace */
60 0xffffffff, /* src_mask */
61 0xffffffff, /* dst_mask */
62 FALSE), /* pcrel_offset */
64 /* A 16 bit pc-relative relocation. */
65 HOWTO (R_FRV_LABEL16, /* type */
67 2, /* size (0 = byte, 1 = short, 2 = long) */
69 TRUE, /* pc_relative */
71 complain_overflow_signed, /* complain_on_overflow */
72 bfd_elf_generic_reloc, /* special_function */
73 "R_FRV_LABEL16", /* name */
74 FALSE, /* partial_inplace */
75 0xffff, /* src_mask */
76 0xffff, /* dst_mask */
77 TRUE), /* pcrel_offset */
79 /* A 24-bit pc-relative relocation. */
80 HOWTO (R_FRV_LABEL24, /* type */
82 2, /* size (0 = byte, 1 = short, 2 = long) */
84 TRUE, /* pc_relative */
86 complain_overflow_bitfield, /* complain_on_overflow */
87 bfd_elf_generic_reloc, /* special_function */
88 "R_FRV_LABEL24", /* name */
89 FALSE, /* partial_inplace */
90 0x7e03ffff, /* src_mask */
91 0x7e03ffff, /* dst_mask */
92 TRUE), /* pcrel_offset */
94 HOWTO (R_FRV_LO16, /* type */
96 2, /* size (0 = byte, 1 = short, 2 = long) */
98 FALSE, /* pc_relative */
100 complain_overflow_dont, /* complain_on_overflow */
101 bfd_elf_generic_reloc, /* special_function */
102 "R_FRV_LO16", /* name */
103 FALSE, /* partial_inplace */
104 0xffff, /* src_mask */
105 0xffff, /* dst_mask */
106 FALSE), /* pcrel_offset */
108 HOWTO (R_FRV_HI16, /* type */
110 2, /* size (0 = byte, 1 = short, 2 = long) */
112 FALSE, /* pc_relative */
114 complain_overflow_dont, /* complain_on_overflow */
115 bfd_elf_generic_reloc, /* special_function */
116 "R_FRV_HI16", /* name */
117 FALSE, /* partial_inplace */
118 0xffff, /* src_mask */
119 0xffff, /* dst_mask */
120 FALSE), /* pcrel_offset */
122 HOWTO (R_FRV_GPREL12, /* type */
124 2, /* size (0 = byte, 1 = short, 2 = long) */
126 FALSE, /* pc_relative */
128 complain_overflow_dont, /* complain_on_overflow */
129 bfd_elf_generic_reloc, /* special_function */
130 "R_FRV_GPREL12", /* name */
131 FALSE, /* partial_inplace */
132 0xfff, /* src_mask */
133 0xfff, /* dst_mask */
134 FALSE), /* pcrel_offset */
136 HOWTO (R_FRV_GPRELU12, /* type */
138 2, /* size (0 = byte, 1 = short, 2 = long) */
140 FALSE, /* pc_relative */
142 complain_overflow_dont, /* complain_on_overflow */
143 bfd_elf_generic_reloc, /* special_function */
144 "R_FRV_GPRELU12", /* name */
145 FALSE, /* partial_inplace */
146 0xfff, /* src_mask */
147 0x3f03f, /* dst_mask */
148 FALSE), /* pcrel_offset */
150 HOWTO (R_FRV_GPREL32, /* type */
152 2, /* size (0 = byte, 1 = short, 2 = long) */
154 FALSE, /* pc_relative */
156 complain_overflow_dont, /* complain_on_overflow */
157 bfd_elf_generic_reloc, /* special_function */
158 "R_FRV_GPREL32", /* name */
159 FALSE, /* partial_inplace */
160 0xffffffff, /* src_mask */
161 0xffffffff, /* dst_mask */
162 FALSE), /* pcrel_offset */
164 HOWTO (R_FRV_GPRELHI, /* type */
166 2, /* size (0 = byte, 1 = short, 2 = long) */
168 FALSE, /* pc_relative */
170 complain_overflow_dont, /* complain_on_overflow */
171 bfd_elf_generic_reloc, /* special_function */
172 "R_FRV_GPRELHI", /* name */
173 FALSE, /* partial_inplace */
174 0xffff, /* src_mask */
175 0xffff, /* dst_mask */
176 FALSE), /* pcrel_offset */
178 HOWTO (R_FRV_GPRELLO, /* type */
180 2, /* size (0 = byte, 1 = short, 2 = long) */
182 FALSE, /* pc_relative */
184 complain_overflow_dont, /* complain_on_overflow */
185 bfd_elf_generic_reloc, /* special_function */
186 "R_FRV_GPRELLO", /* name */
187 FALSE, /* partial_inplace */
188 0xffff, /* src_mask */
189 0xffff, /* dst_mask */
190 FALSE), /* pcrel_offset */
192 /* A 12-bit signed operand with the GOT offset for the address of
194 HOWTO (R_FRV_GOT12, /* type */
196 2, /* size (0 = byte, 1 = short, 2 = long) */
198 FALSE, /* pc_relative */
200 complain_overflow_signed, /* complain_on_overflow */
201 bfd_elf_generic_reloc, /* special_function */
202 "R_FRV_GOT12", /* name */
203 FALSE, /* partial_inplace */
204 0xfff, /* src_mask */
205 0xfff, /* dst_mask */
206 FALSE), /* pcrel_offset */
208 /* The upper 16 bits of the GOT offset for the address of the
210 HOWTO (R_FRV_GOTHI, /* type */
212 2, /* size (0 = byte, 1 = short, 2 = long) */
214 FALSE, /* pc_relative */
216 complain_overflow_dont, /* complain_on_overflow */
217 bfd_elf_generic_reloc, /* special_function */
218 "R_FRV_GOTHI", /* name */
219 FALSE, /* partial_inplace */
220 0xffff, /* src_mask */
221 0xffff, /* dst_mask */
222 FALSE), /* pcrel_offset */
224 /* The lower 16 bits of the GOT offset for the address of the
226 HOWTO (R_FRV_GOTLO, /* type */
228 2, /* size (0 = byte, 1 = short, 2 = long) */
230 FALSE, /* pc_relative */
232 complain_overflow_dont, /* complain_on_overflow */
233 bfd_elf_generic_reloc, /* special_function */
234 "R_FRV_GOTLO", /* name */
235 FALSE, /* partial_inplace */
236 0xffff, /* src_mask */
237 0xffff, /* dst_mask */
238 FALSE), /* pcrel_offset */
240 /* The 32-bit address of the canonical descriptor of a function. */
241 HOWTO (R_FRV_FUNCDESC, /* type */
243 2, /* size (0 = byte, 1 = short, 2 = long) */
245 FALSE, /* pc_relative */
247 complain_overflow_bitfield, /* complain_on_overflow */
248 bfd_elf_generic_reloc, /* special_function */
249 "R_FRV_FUNCDESC", /* name */
250 FALSE, /* partial_inplace */
251 0xffffffff, /* src_mask */
252 0xffffffff, /* dst_mask */
253 FALSE), /* pcrel_offset */
255 /* A 12-bit signed operand with the GOT offset for the address of
256 canonical descriptor of a function. */
257 HOWTO (R_FRV_FUNCDESC_GOT12, /* type */
259 2, /* size (0 = byte, 1 = short, 2 = long) */
261 FALSE, /* pc_relative */
263 complain_overflow_signed, /* complain_on_overflow */
264 bfd_elf_generic_reloc, /* special_function */
265 "R_FRV_FUNCDESC_GOT12", /* name */
266 FALSE, /* partial_inplace */
267 0xfff, /* src_mask */
268 0xfff, /* dst_mask */
269 FALSE), /* pcrel_offset */
271 /* The upper 16 bits of the GOT offset for the address of the
272 canonical descriptor of a function. */
273 HOWTO (R_FRV_FUNCDESC_GOTHI, /* type */
275 2, /* size (0 = byte, 1 = short, 2 = long) */
277 FALSE, /* pc_relative */
279 complain_overflow_dont, /* complain_on_overflow */
280 bfd_elf_generic_reloc, /* special_function */
281 "R_FRV_FUNCDESC_GOTHI", /* name */
282 FALSE, /* partial_inplace */
283 0xffff, /* src_mask */
284 0xffff, /* dst_mask */
285 FALSE), /* pcrel_offset */
287 /* The lower 16 bits of the GOT offset for the address of the
288 canonical descriptor of a function. */
289 HOWTO (R_FRV_FUNCDESC_GOTLO, /* type */
291 2, /* size (0 = byte, 1 = short, 2 = long) */
293 FALSE, /* pc_relative */
295 complain_overflow_dont, /* complain_on_overflow */
296 bfd_elf_generic_reloc, /* special_function */
297 "R_FRV_FUNCDESC_GOTLO", /* name */
298 FALSE, /* partial_inplace */
299 0xffff, /* src_mask */
300 0xffff, /* dst_mask */
301 FALSE), /* pcrel_offset */
303 /* The 64-bit descriptor of a function. */
304 HOWTO (R_FRV_FUNCDESC_VALUE, /* type */
306 2, /* size (0 = byte, 1 = short, 2 = long) */
308 FALSE, /* pc_relative */
310 complain_overflow_bitfield, /* complain_on_overflow */
311 bfd_elf_generic_reloc, /* special_function */
312 "R_FRV_FUNCDESC_VALUE", /* name */
313 FALSE, /* partial_inplace */
314 0xffffffff, /* src_mask */
315 0xffffffff, /* dst_mask */
316 FALSE), /* pcrel_offset */
318 /* A 12-bit signed operand with the GOT offset for the address of
319 canonical descriptor of a function. */
320 HOWTO (R_FRV_FUNCDESC_GOTOFF12, /* type */
322 2, /* size (0 = byte, 1 = short, 2 = long) */
324 FALSE, /* pc_relative */
326 complain_overflow_signed, /* complain_on_overflow */
327 bfd_elf_generic_reloc, /* special_function */
328 "R_FRV_FUNCDESC_GOTOFF12", /* name */
329 FALSE, /* partial_inplace */
330 0xfff, /* src_mask */
331 0xfff, /* dst_mask */
332 FALSE), /* pcrel_offset */
334 /* The upper 16 bits of the GOT offset for the address of the
335 canonical descriptor of a function. */
336 HOWTO (R_FRV_FUNCDESC_GOTOFFHI, /* type */
338 2, /* size (0 = byte, 1 = short, 2 = long) */
340 FALSE, /* pc_relative */
342 complain_overflow_dont, /* complain_on_overflow */
343 bfd_elf_generic_reloc, /* special_function */
344 "R_FRV_FUNCDESC_GOTOFFHI", /* name */
345 FALSE, /* partial_inplace */
346 0xffff, /* src_mask */
347 0xffff, /* dst_mask */
348 FALSE), /* pcrel_offset */
350 /* The lower 16 bits of the GOT offset for the address of the
351 canonical descriptor of a function. */
352 HOWTO (R_FRV_FUNCDESC_GOTOFFLO, /* type */
354 2, /* size (0 = byte, 1 = short, 2 = long) */
356 FALSE, /* pc_relative */
358 complain_overflow_dont, /* complain_on_overflow */
359 bfd_elf_generic_reloc, /* special_function */
360 "R_FRV_FUNCDESC_GOTOFFLO", /* name */
361 FALSE, /* partial_inplace */
362 0xffff, /* src_mask */
363 0xffff, /* dst_mask */
364 FALSE), /* pcrel_offset */
366 /* A 12-bit signed operand with the GOT offset for the address of
368 HOWTO (R_FRV_GOTOFF12, /* type */
370 2, /* size (0 = byte, 1 = short, 2 = long) */
372 FALSE, /* pc_relative */
374 complain_overflow_signed, /* complain_on_overflow */
375 bfd_elf_generic_reloc, /* special_function */
376 "R_FRV_GOTOFF12", /* name */
377 FALSE, /* partial_inplace */
378 0xfff, /* src_mask */
379 0xfff, /* dst_mask */
380 FALSE), /* pcrel_offset */
382 /* The upper 16 bits of the GOT offset for the address of the
384 HOWTO (R_FRV_GOTOFFHI, /* type */
386 2, /* size (0 = byte, 1 = short, 2 = long) */
388 FALSE, /* pc_relative */
390 complain_overflow_dont, /* complain_on_overflow */
391 bfd_elf_generic_reloc, /* special_function */
392 "R_FRV_GOTOFFHI", /* name */
393 FALSE, /* partial_inplace */
394 0xffff, /* src_mask */
395 0xffff, /* dst_mask */
396 FALSE), /* pcrel_offset */
398 /* The lower 16 bits of the GOT offset for the address of the
400 HOWTO (R_FRV_GOTOFFLO, /* type */
402 2, /* size (0 = byte, 1 = short, 2 = long) */
404 FALSE, /* pc_relative */
406 complain_overflow_dont, /* complain_on_overflow */
407 bfd_elf_generic_reloc, /* special_function */
408 "R_FRV_GOTOFFLO", /* name */
409 FALSE, /* partial_inplace */
410 0xffff, /* src_mask */
411 0xffff, /* dst_mask */
412 FALSE), /* pcrel_offset */
414 /* A 24-bit pc-relative relocation referencing the TLS PLT entry for
415 a thread-local symbol. If the symbol number is 0, it refers to
417 HOWTO (R_FRV_GETTLSOFF, /* type */
419 2, /* size (0 = byte, 1 = short, 2 = long) */
421 TRUE, /* pc_relative */
423 complain_overflow_bitfield, /* complain_on_overflow */
424 bfd_elf_generic_reloc, /* special_function */
425 "R_FRV_GETTLSOFF", /* name */
426 FALSE, /* partial_inplace */
427 0x7e03ffff, /* src_mask */
428 0x7e03ffff, /* dst_mask */
429 TRUE), /* pcrel_offset */
431 /* A 64-bit TLS descriptor for a symbol. This relocation is only
432 valid as a REL, dynamic relocation. */
433 HOWTO (R_FRV_TLSDESC_VALUE, /* type */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
437 FALSE, /* pc_relative */
439 complain_overflow_bitfield, /* complain_on_overflow */
440 bfd_elf_generic_reloc, /* special_function */
441 "R_FRV_TLSDESC_VALUE", /* name */
442 FALSE, /* partial_inplace */
443 0xffffffff, /* src_mask */
444 0xffffffff, /* dst_mask */
445 FALSE), /* pcrel_offset */
447 /* A 12-bit signed operand with the GOT offset for the TLS
448 descriptor of the symbol. */
449 HOWTO (R_FRV_GOTTLSDESC12, /* type */
451 2, /* size (0 = byte, 1 = short, 2 = long) */
453 FALSE, /* pc_relative */
455 complain_overflow_signed, /* complain_on_overflow */
456 bfd_elf_generic_reloc, /* special_function */
457 "R_FRV_GOTTLSDESC12", /* name */
458 FALSE, /* partial_inplace */
459 0xfff, /* src_mask */
460 0xfff, /* dst_mask */
461 FALSE), /* pcrel_offset */
463 /* The upper 16 bits of the GOT offset for the TLS descriptor of the
465 HOWTO (R_FRV_GOTTLSDESCHI, /* type */
467 2, /* size (0 = byte, 1 = short, 2 = long) */
469 FALSE, /* pc_relative */
471 complain_overflow_dont, /* complain_on_overflow */
472 bfd_elf_generic_reloc, /* special_function */
473 "R_FRV_GOTTLSDESCHI", /* name */
474 FALSE, /* partial_inplace */
475 0xffff, /* src_mask */
476 0xffff, /* dst_mask */
477 FALSE), /* pcrel_offset */
479 /* The lower 16 bits of the GOT offset for the TLS descriptor of the
481 HOWTO (R_FRV_GOTTLSDESCLO, /* type */
483 2, /* size (0 = byte, 1 = short, 2 = long) */
485 FALSE, /* pc_relative */
487 complain_overflow_dont, /* complain_on_overflow */
488 bfd_elf_generic_reloc, /* special_function */
489 "R_FRV_GOTTLSDESCLO", /* name */
490 FALSE, /* partial_inplace */
491 0xffff, /* src_mask */
492 0xffff, /* dst_mask */
493 FALSE), /* pcrel_offset */
495 /* A 12-bit signed operand with the offset from the module base
496 address to the thread-local symbol address. */
497 HOWTO (R_FRV_TLSMOFF12, /* type */
499 2, /* size (0 = byte, 1 = short, 2 = long) */
501 FALSE, /* pc_relative */
503 complain_overflow_signed, /* complain_on_overflow */
504 bfd_elf_generic_reloc, /* special_function */
505 "R_FRV_TLSMOFF12", /* name */
506 FALSE, /* partial_inplace */
507 0xfff, /* src_mask */
508 0xfff, /* dst_mask */
509 FALSE), /* pcrel_offset */
511 /* The upper 16 bits of the offset from the module base address to
512 the thread-local symbol address. */
513 HOWTO (R_FRV_TLSMOFFHI, /* type */
515 2, /* size (0 = byte, 1 = short, 2 = long) */
517 FALSE, /* pc_relative */
519 complain_overflow_dont, /* complain_on_overflow */
520 bfd_elf_generic_reloc, /* special_function */
521 "R_FRV_TLSMOFFHI", /* name */
522 FALSE, /* partial_inplace */
523 0xffff, /* src_mask */
524 0xffff, /* dst_mask */
525 FALSE), /* pcrel_offset */
527 /* The lower 16 bits of the offset from the module base address to
528 the thread-local symbol address. */
529 HOWTO (R_FRV_TLSMOFFLO, /* type */
531 2, /* size (0 = byte, 1 = short, 2 = long) */
533 FALSE, /* pc_relative */
535 complain_overflow_dont, /* complain_on_overflow */
536 bfd_elf_generic_reloc, /* special_function */
537 "R_FRV_TLSMOFFLO", /* name */
538 FALSE, /* partial_inplace */
539 0xffff, /* src_mask */
540 0xffff, /* dst_mask */
541 FALSE), /* pcrel_offset */
543 /* A 12-bit signed operand with the GOT offset for the TLSOFF entry
545 HOWTO (R_FRV_GOTTLSOFF12, /* type */
547 2, /* size (0 = byte, 1 = short, 2 = long) */
549 FALSE, /* pc_relative */
551 complain_overflow_signed, /* complain_on_overflow */
552 bfd_elf_generic_reloc, /* special_function */
553 "R_FRV_GOTTLSOFF12", /* name */
554 FALSE, /* partial_inplace */
555 0xfff, /* src_mask */
556 0xfff, /* dst_mask */
557 FALSE), /* pcrel_offset */
559 /* The upper 16 bits of the GOT offset for the TLSOFF entry for a
561 HOWTO (R_FRV_GOTTLSOFFHI, /* type */
563 2, /* size (0 = byte, 1 = short, 2 = long) */
565 FALSE, /* pc_relative */
567 complain_overflow_dont, /* complain_on_overflow */
568 bfd_elf_generic_reloc, /* special_function */
569 "R_FRV_GOTTLSOFFHI", /* name */
570 FALSE, /* partial_inplace */
571 0xffff, /* src_mask */
572 0xffff, /* dst_mask */
573 FALSE), /* pcrel_offset */
575 /* The lower 16 bits of the GOT offset for the TLSOFF entry for a
577 HOWTO (R_FRV_GOTTLSOFFLO, /* type */
579 2, /* size (0 = byte, 1 = short, 2 = long) */
581 FALSE, /* pc_relative */
583 complain_overflow_dont, /* complain_on_overflow */
584 bfd_elf_generic_reloc, /* special_function */
585 "R_FRV_GOTTLSOFFLO", /* name */
586 FALSE, /* partial_inplace */
587 0xffff, /* src_mask */
588 0xffff, /* dst_mask */
589 FALSE), /* pcrel_offset */
591 /* The 32-bit offset from the thread pointer (not the module base
592 address) to a thread-local symbol. */
593 HOWTO (R_FRV_TLSOFF, /* type */
595 2, /* size (0 = byte, 1 = short, 2 = long) */
597 FALSE, /* pc_relative */
599 complain_overflow_dont, /* complain_on_overflow */
600 bfd_elf_generic_reloc, /* special_function */
601 "R_FRV_TLSOFF", /* name */
602 FALSE, /* partial_inplace */
603 0xffffffff, /* src_mask */
604 0xffffffff, /* dst_mask */
605 FALSE), /* pcrel_offset */
607 /* An annotation for linker relaxation, that denotes the
608 symbol+addend whose TLS descriptor is referenced by the sum of
609 the two input registers of an ldd instruction. */
610 HOWTO (R_FRV_TLSDESC_RELAX, /* 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_TLSDESC_RELAX", /* name */
619 FALSE, /* partial_inplace */
622 FALSE), /* pcrel_offset */
624 /* An annotation for linker relaxation, that denotes the
625 symbol+addend whose TLS resolver entry point is given by the sum
626 of the two register operands of an calll instruction. */
627 HOWTO (R_FRV_GETTLSOFF_RELAX, /* type */
629 2, /* size (0 = byte, 1 = short, 2 = long) */
631 FALSE, /* pc_relative */
633 complain_overflow_dont, /* complain_on_overflow */
634 bfd_elf_generic_reloc, /* special_function */
635 "R_FRV_GETTLSOFF_RELAX", /* name */
636 FALSE, /* partial_inplace */
639 FALSE), /* pcrel_offset */
641 /* An annotation for linker relaxation, that denotes the
642 symbol+addend whose TLS offset GOT entry is given by the sum of
643 the two input registers of an ld instruction. */
644 HOWTO (R_FRV_TLSOFF_RELAX, /* type */
646 2, /* size (0 = byte, 1 = short, 2 = long) */
648 FALSE, /* pc_relative */
650 complain_overflow_bitfield, /* complain_on_overflow */
651 bfd_elf_generic_reloc, /* special_function */
652 "R_FRV_TLSOFF_RELAX", /* name */
653 FALSE, /* partial_inplace */
656 FALSE), /* pcrel_offset */
658 /* A 32-bit offset from the module base address to
659 the thread-local symbol address. */
660 HOWTO (R_FRV_TLSMOFF, /* type */
662 2, /* size (0 = byte, 1 = short, 2 = long) */
664 FALSE, /* pc_relative */
666 complain_overflow_dont, /* complain_on_overflow */
667 bfd_elf_generic_reloc, /* special_function */
668 "R_FRV_TLSMOFF", /* name */
669 FALSE, /* partial_inplace */
670 0xffffffff, /* src_mask */
671 0xffffffff, /* dst_mask */
672 FALSE), /* pcrel_offset */
675 /* GNU extension to record C++ vtable hierarchy. */
676 static reloc_howto_type elf32_frv_vtinherit_howto =
677 HOWTO (R_FRV_GNU_VTINHERIT, /* type */
679 2, /* size (0 = byte, 1 = short, 2 = long) */
681 FALSE, /* pc_relative */
683 complain_overflow_dont, /* complain_on_overflow */
684 NULL, /* special_function */
685 "R_FRV_GNU_VTINHERIT", /* name */
686 FALSE, /* partial_inplace */
689 FALSE); /* pcrel_offset */
691 /* GNU extension to record C++ vtable member usage. */
692 static reloc_howto_type elf32_frv_vtentry_howto =
693 HOWTO (R_FRV_GNU_VTENTRY, /* type */
695 2, /* size (0 = byte, 1 = short, 2 = long) */
697 FALSE, /* pc_relative */
699 complain_overflow_dont, /* complain_on_overflow */
700 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
701 "R_FRV_GNU_VTENTRY", /* name */
702 FALSE, /* partial_inplace */
705 FALSE); /* pcrel_offset */
707 /* The following 3 relocations are REL. The only difference to the
708 entries in the table above are that partial_inplace is TRUE. */
709 static reloc_howto_type elf32_frv_rel_32_howto =
710 HOWTO (R_FRV_32, /* type */
712 2, /* size (0 = byte, 1 = short, 2 = long) */
714 FALSE, /* pc_relative */
716 complain_overflow_bitfield, /* complain_on_overflow */
717 bfd_elf_generic_reloc, /* special_function */
718 "R_FRV_32", /* name */
719 TRUE, /* partial_inplace */
720 0xffffffff, /* src_mask */
721 0xffffffff, /* dst_mask */
722 FALSE); /* pcrel_offset */
724 static reloc_howto_type elf32_frv_rel_funcdesc_howto =
725 HOWTO (R_FRV_FUNCDESC, /* type */
727 2, /* size (0 = byte, 1 = short, 2 = long) */
729 FALSE, /* pc_relative */
731 complain_overflow_bitfield, /* complain_on_overflow */
732 bfd_elf_generic_reloc, /* special_function */
733 "R_FRV_FUNCDESC", /* name */
734 TRUE, /* partial_inplace */
735 0xffffffff, /* src_mask */
736 0xffffffff, /* dst_mask */
737 FALSE); /* pcrel_offset */
739 static reloc_howto_type elf32_frv_rel_funcdesc_value_howto =
740 HOWTO (R_FRV_FUNCDESC_VALUE, /* type */
742 2, /* size (0 = byte, 1 = short, 2 = long) */
744 FALSE, /* pc_relative */
746 complain_overflow_bitfield, /* complain_on_overflow */
747 bfd_elf_generic_reloc, /* special_function */
748 "R_FRV_FUNCDESC_VALUE", /* name */
749 TRUE, /* partial_inplace */
750 0xffffffff, /* src_mask */
751 0xffffffff, /* dst_mask */
752 FALSE); /* pcrel_offset */
754 static reloc_howto_type elf32_frv_rel_tlsdesc_value_howto =
755 /* A 64-bit TLS descriptor for a symbol. The first word resolves to
756 an entry point, and the second resolves to a special argument.
757 If the symbol turns out to be in static TLS, the entry point is a
758 return instruction, and the special argument is the TLS offset
759 for the symbol. If it's in dynamic TLS, the entry point is a TLS
760 offset resolver, and the special argument is a pointer to a data
761 structure allocated by the dynamic loader, containing the GOT
762 address for the offset resolver, the module id, the offset within
763 the module, and anything else the TLS offset resolver might need
764 to determine the TLS offset for the symbol in the running
766 HOWTO (R_FRV_TLSDESC_VALUE, /* type */
768 2, /* size (0 = byte, 1 = short, 2 = long) */
770 FALSE, /* pc_relative */
772 complain_overflow_bitfield, /* complain_on_overflow */
773 bfd_elf_generic_reloc, /* special_function */
774 "R_FRV_TLSDESC_VALUE", /* name */
775 TRUE, /* partial_inplace */
776 0xffffffff, /* src_mask */
777 0xffffffff, /* dst_mask */
778 FALSE); /* pcrel_offset */
780 static reloc_howto_type elf32_frv_rel_tlsoff_howto =
781 /* The 32-bit offset from the thread pointer (not the module base
782 address) to a thread-local symbol. */
783 HOWTO (R_FRV_TLSOFF, /* type */
785 2, /* size (0 = byte, 1 = short, 2 = long) */
787 FALSE, /* pc_relative */
789 complain_overflow_bitfield, /* complain_on_overflow */
790 bfd_elf_generic_reloc, /* special_function */
791 "R_FRV_TLSOFF", /* name */
792 TRUE, /* partial_inplace */
793 0xffffffff, /* src_mask */
794 0xffffffff, /* dst_mask */
795 FALSE); /* pcrel_offset */
799 extern const bfd_target frv_elf32_fdpic_vec;
800 #define IS_FDPIC(bfd) ((bfd)->xvec == &frv_elf32_fdpic_vec)
802 /* An extension of the elf hash table data structure, containing some
803 additional FRV-specific data. */
804 struct frvfdpic_elf_link_hash_table
806 struct elf_link_hash_table elf;
808 /* A pointer to the .got section. */
810 /* A pointer to the .rel.got section. */
812 /* A pointer to the .rofixup section. */
814 /* A pointer to the .plt section. */
816 /* A pointer to the .rel.plt section. */
818 /* GOT base offset. */
820 /* Location of the first non-lazy PLT entry, i.e., the number of
821 bytes taken by lazy PLT entries. If locally-bound TLS
822 descriptors require a ret instruction, it will be placed at this
825 /* A hash table holding information about which symbols were
826 referenced with which PIC-related relocations. */
827 struct htab *relocs_info;
828 /* Summary reloc information collected by
829 _frvfdpic_count_got_plt_entries. */
830 struct _frvfdpic_dynamic_got_info *g;
833 /* Get the FRV ELF linker hash table from a link_info structure. */
835 #define frvfdpic_hash_table(p) \
836 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
837 == FRV_ELF_DATA ? ((struct frvfdpic_elf_link_hash_table *) ((p)->hash)) : NULL)
839 #define frvfdpic_got_section(info) \
840 (frvfdpic_hash_table (info)->sgot)
841 #define frvfdpic_gotrel_section(info) \
842 (frvfdpic_hash_table (info)->sgotrel)
843 #define frvfdpic_gotfixup_section(info) \
844 (frvfdpic_hash_table (info)->sgotfixup)
845 #define frvfdpic_plt_section(info) \
846 (frvfdpic_hash_table (info)->splt)
847 #define frvfdpic_pltrel_section(info) \
848 (frvfdpic_hash_table (info)->spltrel)
849 #define frvfdpic_relocs_info(info) \
850 (frvfdpic_hash_table (info)->relocs_info)
851 #define frvfdpic_got_initial_offset(info) \
852 (frvfdpic_hash_table (info)->got0)
853 #define frvfdpic_plt_initial_offset(info) \
854 (frvfdpic_hash_table (info)->plt0)
855 #define frvfdpic_dynamic_got_plt_info(info) \
856 (frvfdpic_hash_table (info)->g)
858 /* Currently it's the same, but if some day we have a reason to change
859 it, we'd better be using a different macro.
861 FIXME: if there's any TLS PLT entry that uses local-exec or
862 initial-exec models, we could use the ret at the end of any of them
863 instead of adding one more. */
864 #define frvfdpic_plt_tls_ret_offset(info) \
865 (frvfdpic_plt_initial_offset (info))
867 /* The name of the dynamic interpreter. This is put in the .interp
870 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
872 #define DEFAULT_STACK_SIZE 0x20000
874 /* This structure is used to collect the number of entries present in
875 each addressable range of the got. */
876 struct _frvfdpic_dynamic_got_info
878 /* Several bits of information about the current link. */
879 struct bfd_link_info *info;
880 /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit
882 bfd_vma got12, gotlos, gothilo;
883 /* Total GOT size needed for function descriptor entries within the 12-,
884 16- or 32-bit ranges. */
885 bfd_vma fd12, fdlos, fdhilo;
886 /* Total GOT size needed by function descriptor entries referenced
887 in PLT entries, that would be profitable to place in offsets
888 close to the PIC register. */
890 /* Total PLT size needed by lazy PLT entries. */
892 /* Total GOT size needed for TLS descriptor entries within the 12-,
893 16- or 32-bit ranges. */
894 bfd_vma tlsd12, tlsdlos, tlsdhilo;
895 /* Total GOT size needed by TLS descriptors referenced in PLT
896 entries, that would be profitable to place in offers close to the
899 /* Total PLT size needed by TLS lazy PLT entries. */
901 /* Number of relocations carried over from input object files. */
902 unsigned long relocs;
903 /* Number of fixups introduced by relocations in input object files. */
904 unsigned long fixups;
905 /* The number of fixups that reference the ret instruction added to
906 the PLT for locally-resolved TLS descriptors. */
907 unsigned long tls_ret_refs;
910 /* This structure is used to assign offsets to got entries, function
911 descriptors, plt entries and lazy plt entries. */
913 struct _frvfdpic_dynamic_got_plt_info
915 /* Summary information collected with _frvfdpic_count_got_plt_entries. */
916 struct _frvfdpic_dynamic_got_info g;
918 /* For each addressable range, we record a MAX (positive) and MIN
919 (negative) value. CUR is used to assign got entries, and it's
920 incremented from an initial positive value to MAX, then from MIN
921 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
922 assign function descriptors, and it's decreased from an initial
923 non-positive value to MIN, then from MAX down to CUR (unless CUR
924 wraps around first). All of MIN, MAX, CUR and FDCUR always point
925 to even words. ODD, if non-zero, indicates an odd word to be
926 used for the next got entry, otherwise CUR is used and
927 incremented by a pair of words, wrapping around when it reaches
928 MAX. FDCUR is decremented (and wrapped) before the next function
929 descriptor is chosen. FDPLT indicates the number of remaining
930 slots that can be used for function descriptors used only by PLT
933 TMAX, TMIN and TCUR are used to assign TLS descriptors. TCUR
934 starts as MAX, and grows up to TMAX, then wraps around to TMIN
935 and grows up to MIN. TLSDPLT indicates the number of remaining
936 slots that can be used for TLS descriptors used only by TLS PLT
938 struct _frvfdpic_dynamic_got_alloc_data
940 bfd_signed_vma max, cur, odd, fdcur, min;
941 bfd_signed_vma tmax, tcur, tmin;
942 bfd_vma fdplt, tlsdplt;
943 } got12, gotlos, gothilo;
946 /* Create an FRV ELF linker hash table. */
948 static struct bfd_link_hash_table *
949 frvfdpic_elf_link_hash_table_create (bfd *abfd)
951 struct frvfdpic_elf_link_hash_table *ret;
952 bfd_size_type amt = sizeof (struct frvfdpic_elf_link_hash_table);
954 ret = bfd_zmalloc (amt);
958 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
959 _bfd_elf_link_hash_newfunc,
960 sizeof (struct elf_link_hash_entry),
967 return &ret->elf.root;
970 /* Decide whether a reference to a symbol can be resolved locally or
971 not. If the symbol is protected, we want the local address, but
972 its function descriptor must be assigned by the dynamic linker. */
973 #define FRVFDPIC_SYM_LOCAL(INFO, H) \
974 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
975 || ! elf_hash_table (INFO)->dynamic_sections_created)
976 #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \
977 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
979 /* This structure collects information on what kind of GOT, PLT or
980 function descriptors are required by relocations that reference a
982 struct frvfdpic_relocs_info
984 /* The index of the symbol, as stored in the relocation r_info, if
985 we have a local symbol; -1 otherwise. */
989 /* The input bfd in which the symbol is defined, if it's a local
992 /* If symndx == -1, the hash table entry corresponding to a global
993 symbol (even if it turns out to bind locally, in which case it
994 should ideally be replaced with section's symndx + addend). */
995 struct elf_link_hash_entry *h;
997 /* The addend of the relocation that references the symbol. */
1000 /* The fields above are used to identify an entry. The fields below
1001 contain information on how an entry is used and, later on, which
1002 locations it was assigned. */
1003 /* The following 3 fields record whether the symbol+addend above was
1004 ever referenced with a GOT relocation. The 12 suffix indicates a
1005 GOT12 relocation; los is used for GOTLO relocations that are not
1006 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
1011 /* Whether a FUNCDESC relocation references symbol+addend. */
1013 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
1015 unsigned fdgotlos:1;
1016 unsigned fdgothilo:1;
1017 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
1018 unsigned fdgoff12:1;
1019 unsigned fdgofflos:1;
1020 unsigned fdgoffhilo:1;
1021 /* Whether a GETTLSOFF relocation references symbol+addend. */
1023 /* FIXME: we should probably add tlspltdesc, tlspltoff and
1024 tlspltimm, to tell what kind of TLS PLT entry we're generating.
1025 We might instead just pre-compute flags telling whether the
1026 object is suitable for local exec, initial exec or general
1027 dynamic addressing, and use that all over the place. We could
1028 also try to do a better job of merging TLSOFF and TLSDESC entries
1029 in main executables, but perhaps we can get rid of TLSDESC
1030 entirely in them instead. */
1031 /* Whether a GOTTLSDESC relocation references symbol+addend. */
1032 unsigned tlsdesc12:1;
1033 unsigned tlsdesclos:1;
1034 unsigned tlsdeschilo:1;
1035 /* Whether a GOTTLSOFF relocation references symbol+addend. */
1036 unsigned tlsoff12:1;
1037 unsigned tlsofflos:1;
1038 unsigned tlsoffhilo:1;
1039 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
1040 GOTOFFHI relocations. The addend doesn't really matter, since we
1041 envision that this will only be used to check whether the symbol
1042 is mapped to the same segment as the got. */
1044 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
1046 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
1049 /* Whether we need a PLT entry for a symbol. Should be implied by
1051 (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */
1053 /* Whether a function descriptor should be created in this link unit
1054 for symbol+addend. Should be implied by something like:
1055 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
1056 || ((fd || fdgot12 || fdgotlos || fdgothilo)
1057 && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */
1059 /* Whether a lazy PLT entry is needed for this symbol+addend.
1060 Should be implied by something like:
1061 (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)
1062 && ! (info->flags & DF_BIND_NOW)) */
1064 /* Whether we've already emitted GOT relocations and PLT entries as
1065 needed for this symbol. */
1068 /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and
1069 R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing
1071 unsigned relocs32, relocsfd, relocsfdv, relocstlsd, relocstlsoff;
1073 /* The number of .rofixups entries and dynamic relocations allocated
1074 for this symbol, minus any that might have already been used. */
1075 unsigned fixups, dynrelocs;
1077 /* The offsets of the GOT entries assigned to symbol+addend, to the
1078 function descriptor's address, and to a function descriptor,
1079 respectively. Should be zero if unassigned. The offsets are
1080 counted from the value that will be assigned to the PIC register,
1081 not from the beginning of the .got section. */
1082 bfd_signed_vma got_entry, fdgot_entry, fd_entry;
1083 /* The offsets of the PLT entries assigned to symbol+addend,
1084 non-lazy and lazy, respectively. If unassigned, should be
1086 bfd_vma plt_entry, lzplt_entry;
1087 /* The offsets of the GOT entries for TLS offset and TLS descriptor. */
1088 bfd_signed_vma tlsoff_entry, tlsdesc_entry;
1089 /* The offset of the TLS offset PLT entry. */
1090 bfd_vma tlsplt_entry;
1093 /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */
1095 frvfdpic_relocs_info_hash (const void *entry_)
1097 const struct frvfdpic_relocs_info *entry = entry_;
1099 return (entry->symndx == -1
1100 ? (long) entry->d.h->root.root.hash
1101 : entry->symndx + (long) entry->d.abfd->id * 257) + entry->addend;
1104 /* Test whether the key fields of two frvfdpic_relocs_info entries are
1107 frvfdpic_relocs_info_eq (const void *entry1, const void *entry2)
1109 const struct frvfdpic_relocs_info *e1 = entry1;
1110 const struct frvfdpic_relocs_info *e2 = entry2;
1112 return e1->symndx == e2->symndx && e1->addend == e2->addend
1113 && (e1->symndx == -1 ? e1->d.h == e2->d.h : e1->d.abfd == e2->d.abfd);
1116 /* Find or create an entry in a hash table HT that matches the key
1117 fields of the given ENTRY. If it's not found, memory for a new
1118 entry is allocated in ABFD's obstack. */
1119 static struct frvfdpic_relocs_info *
1120 frvfdpic_relocs_info_find (struct htab *ht,
1122 const struct frvfdpic_relocs_info *entry,
1123 enum insert_option insert)
1125 struct frvfdpic_relocs_info **loc =
1126 (struct frvfdpic_relocs_info **) htab_find_slot (ht, entry, insert);
1134 *loc = bfd_zalloc (abfd, sizeof (**loc));
1139 (*loc)->symndx = entry->symndx;
1140 (*loc)->d = entry->d;
1141 (*loc)->addend = entry->addend;
1142 (*loc)->plt_entry = (bfd_vma)-1;
1143 (*loc)->lzplt_entry = (bfd_vma)-1;
1144 (*loc)->tlsplt_entry = (bfd_vma)-1;
1149 /* Obtain the address of the entry in HT associated with H's symbol +
1150 addend, creating a new entry if none existed. ABFD is only used
1151 for memory allocation purposes. */
1152 inline static struct frvfdpic_relocs_info *
1153 frvfdpic_relocs_info_for_global (struct htab *ht,
1155 struct elf_link_hash_entry *h,
1157 enum insert_option insert)
1159 struct frvfdpic_relocs_info entry;
1163 entry.addend = addend;
1165 return frvfdpic_relocs_info_find (ht, abfd, &entry, insert);
1168 /* Obtain the address of the entry in HT associated with the SYMNDXth
1169 local symbol of the input bfd ABFD, plus the addend, creating a new
1170 entry if none existed. */
1171 inline static struct frvfdpic_relocs_info *
1172 frvfdpic_relocs_info_for_local (struct htab *ht,
1176 enum insert_option insert)
1178 struct frvfdpic_relocs_info entry;
1180 entry.symndx = symndx;
1181 entry.d.abfd = abfd;
1182 entry.addend = addend;
1184 return frvfdpic_relocs_info_find (ht, abfd, &entry, insert);
1187 /* Merge fields set by check_relocs() of two entries that end up being
1188 mapped to the same (presumably global) symbol. */
1191 frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info *e2,
1192 struct frvfdpic_relocs_info const *e1)
1194 e2->got12 |= e1->got12;
1195 e2->gotlos |= e1->gotlos;
1196 e2->gothilo |= e1->gothilo;
1198 e2->fdgot12 |= e1->fdgot12;
1199 e2->fdgotlos |= e1->fdgotlos;
1200 e2->fdgothilo |= e1->fdgothilo;
1201 e2->fdgoff12 |= e1->fdgoff12;
1202 e2->fdgofflos |= e1->fdgofflos;
1203 e2->fdgoffhilo |= e1->fdgoffhilo;
1204 e2->tlsplt |= e1->tlsplt;
1205 e2->tlsdesc12 |= e1->tlsdesc12;
1206 e2->tlsdesclos |= e1->tlsdesclos;
1207 e2->tlsdeschilo |= e1->tlsdeschilo;
1208 e2->tlsoff12 |= e1->tlsoff12;
1209 e2->tlsofflos |= e1->tlsofflos;
1210 e2->tlsoffhilo |= e1->tlsoffhilo;
1211 e2->gotoff |= e1->gotoff;
1212 e2->call |= e1->call;
1216 /* Every block of 65535 lazy PLT entries shares a single call to the
1217 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
1218 32767, counting from 0). All other lazy PLT entries branch to it
1219 in a single instruction. */
1221 #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
1222 #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767)
1224 /* Add a dynamic relocation to the SRELOC section. */
1226 inline static bfd_vma
1227 _frvfdpic_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset,
1228 int reloc_type, long dynindx, bfd_vma addend,
1229 struct frvfdpic_relocs_info *entry)
1231 Elf_Internal_Rela outrel;
1232 bfd_vma reloc_offset;
1234 outrel.r_offset = offset;
1235 outrel.r_info = ELF32_R_INFO (dynindx, reloc_type);
1236 outrel.r_addend = addend;
1238 reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rel);
1239 BFD_ASSERT (reloc_offset < sreloc->size);
1240 bfd_elf32_swap_reloc_out (output_bfd, &outrel,
1241 sreloc->contents + reloc_offset);
1242 sreloc->reloc_count++;
1244 /* If the entry's index is zero, this relocation was probably to a
1245 linkonce section that got discarded. We reserved a dynamic
1246 relocation, but it was for another entry than the one we got at
1247 the time of emitting the relocation. Unfortunately there's no
1248 simple way for us to catch this situation, since the relocation
1249 is cleared right before calling relocate_section, at which point
1250 we no longer know what the relocation used to point to. */
1253 BFD_ASSERT (entry->dynrelocs > 0);
1257 return reloc_offset;
1260 /* Add a fixup to the ROFIXUP section. */
1263 _frvfdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset,
1264 struct frvfdpic_relocs_info *entry)
1266 bfd_vma fixup_offset;
1268 if (rofixup->flags & SEC_EXCLUDE)
1271 fixup_offset = rofixup->reloc_count * 4;
1272 if (rofixup->contents)
1274 BFD_ASSERT (fixup_offset < rofixup->size);
1275 bfd_put_32 (output_bfd, offset, rofixup->contents + fixup_offset);
1277 rofixup->reloc_count++;
1279 if (entry && entry->symndx)
1281 /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc
1283 BFD_ASSERT (entry->fixups > 0);
1287 return fixup_offset;
1290 /* Find the segment number in which OSEC, and output section, is
1294 _frvfdpic_osec_to_segment (bfd *output_bfd, asection *osec)
1296 Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section (output_bfd, osec);
1298 return (p != NULL) ? p - elf_tdata (output_bfd)->phdr : -1;
1301 inline static bfd_boolean
1302 _frvfdpic_osec_readonly_p (bfd *output_bfd, asection *osec)
1304 unsigned seg = _frvfdpic_osec_to_segment (output_bfd, osec);
1306 return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W);
1309 #define FRVFDPIC_TLS_BIAS (2048 - 16)
1311 /* Return the base VMA address which should be subtracted from real addresses
1312 when resolving TLSMOFF relocation.
1313 This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */
1316 tls_biased_base (struct bfd_link_info *info)
1318 /* If tls_sec is NULL, we should have signalled an error already. */
1319 if (elf_hash_table (info)->tls_sec == NULL)
1320 return FRVFDPIC_TLS_BIAS;
1321 return elf_hash_table (info)->tls_sec->vma + FRVFDPIC_TLS_BIAS;
1324 /* Generate relocations for GOT entries, function descriptors, and
1325 code for PLT and lazy PLT entries. */
1327 inline static bfd_boolean
1328 _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info *entry,
1330 struct bfd_link_info *info,
1332 Elf_Internal_Sym *sym,
1336 bfd_vma fd_lazy_rel_offset = (bfd_vma)-1;
1343 if (entry->got_entry || entry->fdgot_entry || entry->fd_entry
1344 || entry->tlsoff_entry || entry->tlsdesc_entry)
1346 /* If the symbol is dynamic, consider it for dynamic
1347 relocations, otherwise decay to section + offset. */
1348 if (entry->symndx == -1 && entry->d.h->dynindx != -1)
1349 dynindx = entry->d.h->dynindx;
1353 && sec->output_section
1354 && ! bfd_is_abs_section (sec->output_section)
1355 && ! bfd_is_und_section (sec->output_section))
1356 dynindx = elf_section_data (sec->output_section)->dynindx;
1362 /* Generate relocation for GOT entry pointing to the symbol. */
1363 if (entry->got_entry)
1366 bfd_vma ad = addend;
1368 /* If the symbol is dynamic but binds locally, use
1370 if (sec && (entry->symndx != -1
1371 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1373 if (entry->symndx == -1)
1374 ad += entry->d.h->root.u.def.value;
1376 ad += sym->st_value;
1377 ad += sec->output_offset;
1378 if (sec->output_section && elf_section_data (sec->output_section))
1379 idx = elf_section_data (sec->output_section)->dynindx;
1384 /* If we're linking an executable at a fixed address, we can
1385 omit the dynamic relocation as long as the symbol is local to
1387 if (bfd_link_pde (info)
1388 && (entry->symndx != -1
1389 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1392 ad += sec->output_section->vma;
1393 if (entry->symndx != -1
1394 || entry->d.h->root.type != bfd_link_hash_undefweak)
1395 _frvfdpic_add_rofixup (output_bfd,
1396 frvfdpic_gotfixup_section (info),
1397 frvfdpic_got_section (info)->output_section
1399 + frvfdpic_got_section (info)->output_offset
1400 + frvfdpic_got_initial_offset (info)
1401 + entry->got_entry, entry);
1404 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
1405 _bfd_elf_section_offset
1407 frvfdpic_got_section (info),
1408 frvfdpic_got_initial_offset (info)
1410 + frvfdpic_got_section (info)
1411 ->output_section->vma
1412 + frvfdpic_got_section (info)->output_offset,
1413 R_FRV_32, idx, ad, entry);
1415 bfd_put_32 (output_bfd, ad,
1416 frvfdpic_got_section (info)->contents
1417 + frvfdpic_got_initial_offset (info)
1418 + entry->got_entry);
1421 /* Generate relocation for GOT entry pointing to a canonical
1422 function descriptor. */
1423 if (entry->fdgot_entry)
1428 if (! (entry->symndx == -1
1429 && entry->d.h->root.type == bfd_link_hash_undefweak
1430 && FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1432 /* If the symbol is dynamic and there may be dynamic symbol
1433 resolution because we are, or are linked with, a shared
1434 library, emit a FUNCDESC relocation such that the dynamic
1435 linker will allocate the function descriptor. If the
1436 symbol needs a non-local function descriptor but binds
1437 locally (e.g., its visibility is protected, emit a
1438 dynamic relocation decayed to section+offset. */
1439 if (entry->symndx == -1
1440 && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)
1441 && FRVFDPIC_SYM_LOCAL (info, entry->d.h)
1442 && !bfd_link_pde (info))
1444 reloc = R_FRV_FUNCDESC;
1445 idx = elf_section_data (entry->d.h->root.u.def.section
1446 ->output_section)->dynindx;
1447 ad = entry->d.h->root.u.def.section->output_offset
1448 + entry->d.h->root.u.def.value;
1450 else if (entry->symndx == -1
1451 && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h))
1453 reloc = R_FRV_FUNCDESC;
1458 (*info->callbacks->reloc_dangerous)
1459 (info, _("relocation requires zero addend"),
1460 elf_hash_table (info)->dynobj,
1461 frvfdpic_got_section (info),
1462 entry->fdgot_entry);
1468 /* Otherwise, we know we have a private function descriptor,
1469 so reference it directly. */
1470 if (elf_hash_table (info)->dynamic_sections_created)
1471 BFD_ASSERT (entry->privfd);
1473 idx = elf_section_data (frvfdpic_got_section (info)
1474 ->output_section)->dynindx;
1475 ad = frvfdpic_got_section (info)->output_offset
1476 + frvfdpic_got_initial_offset (info) + entry->fd_entry;
1479 /* If there is room for dynamic symbol resolution, emit the
1480 dynamic relocation. However, if we're linking an
1481 executable at a fixed location, we won't have emitted a
1482 dynamic symbol entry for the got section, so idx will be
1483 zero, which means we can and should compute the address
1484 of the private descriptor ourselves. */
1485 if (bfd_link_pde (info)
1486 && (entry->symndx != -1
1487 || FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)))
1489 ad += frvfdpic_got_section (info)->output_section->vma;
1490 _frvfdpic_add_rofixup (output_bfd,
1491 frvfdpic_gotfixup_section (info),
1492 frvfdpic_got_section (info)
1493 ->output_section->vma
1494 + frvfdpic_got_section (info)
1496 + frvfdpic_got_initial_offset (info)
1497 + entry->fdgot_entry, entry);
1500 _frvfdpic_add_dyn_reloc (output_bfd,
1501 frvfdpic_gotrel_section (info),
1502 _bfd_elf_section_offset
1504 frvfdpic_got_section (info),
1505 frvfdpic_got_initial_offset (info)
1506 + entry->fdgot_entry)
1507 + frvfdpic_got_section (info)
1508 ->output_section->vma
1509 + frvfdpic_got_section (info)
1511 reloc, idx, ad, entry);
1514 bfd_put_32 (output_bfd, ad,
1515 frvfdpic_got_section (info)->contents
1516 + frvfdpic_got_initial_offset (info)
1517 + entry->fdgot_entry);
1520 /* Generate relocation to fill in a private function descriptor in
1522 if (entry->fd_entry)
1525 bfd_vma ad = addend;
1527 long lowword, highword;
1529 /* If the symbol is dynamic but binds locally, use
1531 if (sec && (entry->symndx != -1
1532 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1534 if (entry->symndx == -1)
1535 ad += entry->d.h->root.u.def.value;
1537 ad += sym->st_value;
1538 ad += sec->output_offset;
1539 if (sec->output_section && elf_section_data (sec->output_section))
1540 idx = elf_section_data (sec->output_section)->dynindx;
1545 /* If we're linking an executable at a fixed address, we can
1546 omit the dynamic relocation as long as the symbol is local to
1548 if (bfd_link_pde (info)
1549 && (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1552 ad += sec->output_section->vma;
1554 if (entry->symndx != -1
1555 || entry->d.h->root.type != bfd_link_hash_undefweak)
1557 _frvfdpic_add_rofixup (output_bfd,
1558 frvfdpic_gotfixup_section (info),
1559 frvfdpic_got_section (info)
1560 ->output_section->vma
1561 + frvfdpic_got_section (info)
1563 + frvfdpic_got_initial_offset (info)
1564 + entry->fd_entry, entry);
1565 _frvfdpic_add_rofixup (output_bfd,
1566 frvfdpic_gotfixup_section (info),
1567 frvfdpic_got_section (info)
1568 ->output_section->vma
1569 + frvfdpic_got_section (info)
1571 + frvfdpic_got_initial_offset (info)
1572 + entry->fd_entry + 4, entry);
1578 _frvfdpic_add_dyn_reloc (output_bfd,
1580 ? frvfdpic_pltrel_section (info)
1581 : frvfdpic_gotrel_section (info),
1582 _bfd_elf_section_offset
1584 frvfdpic_got_section (info),
1585 frvfdpic_got_initial_offset (info)
1587 + frvfdpic_got_section (info)
1588 ->output_section->vma
1589 + frvfdpic_got_section (info)
1591 R_FRV_FUNCDESC_VALUE, idx, ad, entry);
1594 /* If we've omitted the dynamic relocation, just emit the fixed
1595 addresses of the symbol and of the local GOT base offset. */
1596 if (bfd_link_pde (info)
1598 && sec->output_section)
1601 highword = frvfdpic_got_section (info)->output_section->vma
1602 + frvfdpic_got_section (info)->output_offset
1603 + frvfdpic_got_initial_offset (info);
1605 else if (entry->lazyplt)
1609 (*info->callbacks->reloc_dangerous)
1610 (info, _("relocation requires zero addend"),
1611 elf_hash_table (info)->dynobj,
1612 frvfdpic_got_section (info),
1617 fd_lazy_rel_offset = ofst;
1619 /* A function descriptor used for lazy or local resolving is
1620 initialized such that its high word contains the output
1621 section index in which the PLT entries are located, and
1622 the low word contains the address of the lazy PLT entry
1623 entry point, that must be within the memory region
1624 assigned to that section. */
1625 lowword = entry->lzplt_entry + 4
1626 + frvfdpic_plt_section (info)->output_offset
1627 + frvfdpic_plt_section (info)->output_section->vma;
1628 highword = _frvfdpic_osec_to_segment
1629 (output_bfd, frvfdpic_plt_section (info)->output_section);
1633 /* A function descriptor for a local function gets the index
1634 of the section. For a non-local function, it's
1638 || (entry->symndx == -1 && entry->d.h->dynindx != -1
1639 && entry->d.h->dynindx == idx))
1642 highword = _frvfdpic_osec_to_segment
1643 (output_bfd, sec->output_section);
1646 bfd_put_32 (output_bfd, lowword,
1647 frvfdpic_got_section (info)->contents
1648 + frvfdpic_got_initial_offset (info)
1650 bfd_put_32 (output_bfd, highword,
1651 frvfdpic_got_section (info)->contents
1652 + frvfdpic_got_initial_offset (info)
1653 + entry->fd_entry + 4);
1656 /* Generate code for the PLT entry. */
1657 if (entry->plt_entry != (bfd_vma) -1)
1659 bfd_byte *plt_code = frvfdpic_plt_section (info)->contents
1662 BFD_ASSERT (entry->fd_entry);
1664 /* Figure out what kind of PLT entry we need, depending on the
1665 location of the function descriptor within the GOT. */
1666 if (entry->fd_entry >= -(1 << (12 - 1))
1667 && entry->fd_entry < (1 << (12 - 1)))
1669 /* lddi @(gr15, fd_entry), gr14 */
1670 bfd_put_32 (output_bfd,
1671 0x9cccf000 | (entry->fd_entry & ((1 << 12) - 1)),
1677 if (entry->fd_entry >= -(1 << (16 - 1))
1678 && entry->fd_entry < (1 << (16 - 1)))
1680 /* setlos lo(fd_entry), gr14 */
1681 bfd_put_32 (output_bfd,
1683 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
1689 /* sethi.p hi(fd_entry), gr14
1690 setlo lo(fd_entry), gr14 */
1691 bfd_put_32 (output_bfd,
1693 | ((entry->fd_entry >> 16)
1694 & (((bfd_vma)1 << 16) - 1)),
1697 bfd_put_32 (output_bfd,
1699 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
1703 /* ldd @(gr14,gr15),gr14 */
1704 bfd_put_32 (output_bfd, 0x9c08e14f, plt_code);
1707 /* jmpl @(gr14,gr0) */
1708 bfd_put_32 (output_bfd, 0x8030e000, plt_code);
1711 /* Generate code for the lazy PLT entry. */
1712 if (entry->lzplt_entry != (bfd_vma) -1)
1714 bfd_byte *lzplt_code = frvfdpic_plt_section (info)->contents
1715 + entry->lzplt_entry;
1716 bfd_vma resolverStub_addr;
1718 bfd_put_32 (output_bfd, fd_lazy_rel_offset, lzplt_code);
1721 resolverStub_addr = entry->lzplt_entry / FRVFDPIC_LZPLT_BLOCK_SIZE
1722 * FRVFDPIC_LZPLT_BLOCK_SIZE + FRVFDPIC_LZPLT_RESOLV_LOC;
1723 if (resolverStub_addr >= frvfdpic_plt_initial_offset (info))
1724 resolverStub_addr = frvfdpic_plt_initial_offset (info) - 12;
1726 if (entry->lzplt_entry == resolverStub_addr)
1728 /* This is a lazy PLT entry that includes a resolver call. */
1729 /* ldd @(gr15,gr0), gr4
1731 bfd_put_32 (output_bfd, 0x8808f140, lzplt_code);
1732 bfd_put_32 (output_bfd, 0x80304000, lzplt_code + 4);
1736 /* bra resolverStub */
1737 bfd_put_32 (output_bfd,
1739 | (((resolverStub_addr - entry->lzplt_entry)
1740 / 4) & (((bfd_vma)1 << 16) - 1)),
1745 /* Generate relocation for GOT entry holding the TLS offset. */
1746 if (entry->tlsoff_entry)
1749 bfd_vma ad = addend;
1751 if (entry->symndx != -1
1752 || FRVFDPIC_SYM_LOCAL (info, entry->d.h))
1754 /* If the symbol is dynamic but binds locally, use
1758 if (entry->symndx == -1)
1759 ad += entry->d.h->root.u.def.value;
1761 ad += sym->st_value;
1762 ad += sec->output_offset;
1763 if (sec->output_section
1764 && elf_section_data (sec->output_section))
1765 idx = elf_section_data (sec->output_section)->dynindx;
1771 /* *ABS*+addend is special for TLS relocations, use only the
1773 if (bfd_link_executable (info)
1775 && (bfd_is_abs_section (sec)
1776 || bfd_is_und_section (sec)))
1778 /* If we're linking an executable, we can entirely omit the
1779 dynamic relocation if the symbol is local to this module. */
1780 else if (bfd_link_executable (info)
1781 && (entry->symndx != -1
1782 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1785 ad += sec->output_section->vma - tls_biased_base (info);
1790 && (bfd_is_abs_section (sec)
1791 || bfd_is_und_section (sec)))
1793 if (! elf_hash_table (info)->tls_sec)
1795 (*info->callbacks->undefined_symbol)
1796 (info, "TLS section", elf_hash_table (info)->dynobj,
1797 frvfdpic_got_section (info), entry->tlsoff_entry, TRUE);
1800 idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx;
1801 ad += FRVFDPIC_TLS_BIAS;
1803 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
1804 _bfd_elf_section_offset
1806 frvfdpic_got_section (info),
1807 frvfdpic_got_initial_offset (info)
1808 + entry->tlsoff_entry)
1809 + frvfdpic_got_section (info)
1810 ->output_section->vma
1811 + frvfdpic_got_section (info)
1813 R_FRV_TLSOFF, idx, ad, entry);
1816 bfd_put_32 (output_bfd, ad,
1817 frvfdpic_got_section (info)->contents
1818 + frvfdpic_got_initial_offset (info)
1819 + entry->tlsoff_entry);
1822 if (entry->tlsdesc_entry)
1825 bfd_vma ad = addend;
1827 /* If the symbol is dynamic but binds locally, use
1829 if (sec && (entry->symndx != -1
1830 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1832 if (entry->symndx == -1)
1833 ad += entry->d.h->root.u.def.value;
1835 ad += sym->st_value;
1836 ad += sec->output_offset;
1837 if (sec->output_section && elf_section_data (sec->output_section))
1838 idx = elf_section_data (sec->output_section)->dynindx;
1843 /* If we didn't set up a TLS offset entry, but we're linking an
1844 executable and the symbol binds locally, we can use the
1845 module offset in the TLS descriptor in relaxations. */
1846 if (bfd_link_executable (info) && ! entry->tlsoff_entry)
1847 entry->tlsoff_entry = entry->tlsdesc_entry + 4;
1849 if (bfd_link_pde (info)
1851 && (bfd_is_abs_section (sec)
1852 || bfd_is_und_section (sec)))
1853 || entry->symndx != -1
1854 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1856 /* *ABS*+addend is special for TLS relocations, use only the
1857 addend for the TLS offset, and take the module id as
1860 && (bfd_is_abs_section (sec)
1861 || bfd_is_und_section (sec)))
1863 /* For other TLS symbols that bind locally, add the section
1864 TLS offset to the addend. */
1866 ad += sec->output_section->vma - tls_biased_base (info);
1868 bfd_put_32 (output_bfd,
1869 frvfdpic_plt_section (info)->output_section->vma
1870 + frvfdpic_plt_section (info)->output_offset
1871 + frvfdpic_plt_tls_ret_offset (info),
1872 frvfdpic_got_section (info)->contents
1873 + frvfdpic_got_initial_offset (info)
1874 + entry->tlsdesc_entry);
1876 _frvfdpic_add_rofixup (output_bfd,
1877 frvfdpic_gotfixup_section (info),
1878 frvfdpic_got_section (info)
1879 ->output_section->vma
1880 + frvfdpic_got_section (info)
1882 + frvfdpic_got_initial_offset (info)
1883 + entry->tlsdesc_entry, entry);
1885 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs);
1887 /* We've used one of the reserved fixups, so discount it so
1888 that we can check at the end that we've used them
1890 frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs--;
1892 /* While at that, make sure the ret instruction makes to the
1893 right location in the PLT. We could do it only when we
1894 got to 0, but since the check at the end will only print
1895 a warning, make sure we have the ret in place in case the
1896 warning is missed. */
1897 bfd_put_32 (output_bfd, 0xc03a4000,
1898 frvfdpic_plt_section (info)->contents
1899 + frvfdpic_plt_tls_ret_offset (info));
1904 && (bfd_is_abs_section (sec)
1905 || bfd_is_und_section (sec)))
1907 if (! elf_hash_table (info)->tls_sec)
1909 (*info->callbacks->undefined_symbol)
1910 (info, "TLS section", elf_hash_table (info)->dynobj,
1911 frvfdpic_got_section (info), entry->tlsdesc_entry, TRUE);
1914 idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx;
1915 ad += FRVFDPIC_TLS_BIAS;
1918 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
1919 _bfd_elf_section_offset
1921 frvfdpic_got_section (info),
1922 frvfdpic_got_initial_offset (info)
1923 + entry->tlsdesc_entry)
1924 + frvfdpic_got_section (info)
1925 ->output_section->vma
1926 + frvfdpic_got_section (info)
1928 R_FRV_TLSDESC_VALUE, idx, ad, entry);
1930 bfd_put_32 (output_bfd, 0,
1931 frvfdpic_got_section (info)->contents
1932 + frvfdpic_got_initial_offset (info)
1933 + entry->tlsdesc_entry);
1936 bfd_put_32 (output_bfd, ad,
1937 frvfdpic_got_section (info)->contents
1938 + frvfdpic_got_initial_offset (info)
1939 + entry->tlsdesc_entry + 4);
1942 /* Generate code for the get-TLS-offset PLT entry. */
1943 if (entry->tlsplt_entry != (bfd_vma) -1)
1945 bfd_byte *plt_code = frvfdpic_plt_section (info)->contents
1946 + entry->tlsplt_entry;
1948 if (bfd_link_executable (info)
1949 && (entry->symndx != -1
1950 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1953 bfd_vma ad = addend;
1955 /* sec may be NULL when referencing an undefweak symbol
1956 while linking a static executable. */
1959 BFD_ASSERT (entry->symndx == -1
1960 && entry->d.h->root.type == bfd_link_hash_undefweak);
1964 if (entry->symndx == -1)
1965 ad += entry->d.h->root.u.def.value;
1967 ad += sym->st_value;
1968 ad += sec->output_offset;
1969 if (sec->output_section
1970 && elf_section_data (sec->output_section))
1971 idx = elf_section_data (sec->output_section)->dynindx;
1976 /* *ABS*+addend is special for TLS relocations, use only the
1977 addend for the TLS offset, and take the module id as
1980 && (bfd_is_abs_section (sec)
1981 || bfd_is_und_section (sec)))
1983 /* For other TLS symbols that bind locally, add the section
1984 TLS offset to the addend. */
1986 ad += sec->output_section->vma - tls_biased_base (info);
1988 if ((bfd_signed_vma)ad >= -(1 << (16 - 1))
1989 && (bfd_signed_vma)ad < (1 << (16 - 1)))
1991 /* setlos lo(ad), gr9 */
1992 bfd_put_32 (output_bfd,
1995 & (((bfd_vma)1 << 16) - 1)),
2001 /* sethi.p hi(ad), gr9
2002 setlo lo(ad), gr9 */
2003 bfd_put_32 (output_bfd,
2006 & (((bfd_vma)1 << 16) - 1)),
2009 bfd_put_32 (output_bfd,
2012 & (((bfd_vma)1 << 16) - 1)),
2017 bfd_put_32 (output_bfd, 0xc03a4000, plt_code);
2019 else if (entry->tlsoff_entry)
2021 /* Figure out what kind of PLT entry we need, depending on the
2022 location of the TLS descriptor within the GOT. */
2023 if (entry->tlsoff_entry >= -(1 << (12 - 1))
2024 && entry->tlsoff_entry < (1 << (12 - 1)))
2026 /* ldi @(gr15, tlsoff_entry), gr9 */
2027 bfd_put_32 (output_bfd,
2028 0x92c8f000 | (entry->tlsoff_entry
2035 if (entry->tlsoff_entry >= -(1 << (16 - 1))
2036 && entry->tlsoff_entry < (1 << (16 - 1)))
2038 /* setlos lo(tlsoff_entry), gr8 */
2039 bfd_put_32 (output_bfd,
2041 | (entry->tlsoff_entry
2042 & (((bfd_vma)1 << 16) - 1)),
2048 /* sethi.p hi(tlsoff_entry), gr8
2049 setlo lo(tlsoff_entry), gr8 */
2050 bfd_put_32 (output_bfd,
2052 | ((entry->tlsoff_entry >> 16)
2053 & (((bfd_vma)1 << 16) - 1)),
2056 bfd_put_32 (output_bfd,
2058 | (entry->tlsoff_entry
2059 & (((bfd_vma)1 << 16) - 1)),
2063 /* ld @(gr15,gr8),gr9 */
2064 bfd_put_32 (output_bfd, 0x9008f108, plt_code);
2068 bfd_put_32 (output_bfd, 0xc03a4000, plt_code);
2072 BFD_ASSERT (entry->tlsdesc_entry);
2074 /* Figure out what kind of PLT entry we need, depending on the
2075 location of the TLS descriptor within the GOT. */
2076 if (entry->tlsdesc_entry >= -(1 << (12 - 1))
2077 && entry->tlsdesc_entry < (1 << (12 - 1)))
2079 /* lddi @(gr15, tlsdesc_entry), gr8 */
2080 bfd_put_32 (output_bfd,
2081 0x90ccf000 | (entry->tlsdesc_entry
2088 if (entry->tlsdesc_entry >= -(1 << (16 - 1))
2089 && entry->tlsdesc_entry < (1 << (16 - 1)))
2091 /* setlos lo(tlsdesc_entry), gr8 */
2092 bfd_put_32 (output_bfd,
2094 | (entry->tlsdesc_entry
2095 & (((bfd_vma)1 << 16) - 1)),
2101 /* sethi.p hi(tlsdesc_entry), gr8
2102 setlo lo(tlsdesc_entry), gr8 */
2103 bfd_put_32 (output_bfd,
2105 | ((entry->tlsdesc_entry >> 16)
2106 & (((bfd_vma)1 << 16) - 1)),
2109 bfd_put_32 (output_bfd,
2111 | (entry->tlsdesc_entry
2112 & (((bfd_vma)1 << 16) - 1)),
2116 /* ldd @(gr15,gr8),gr8 */
2117 bfd_put_32 (output_bfd, 0x9008f148, plt_code);
2120 /* jmpl @(gr8,gr0) */
2121 bfd_put_32 (output_bfd, 0x80308000, plt_code);
2128 /* Handle an FRV small data reloc. */
2130 static bfd_reloc_status_type
2131 elf32_frv_relocate_gprel12 (struct bfd_link_info *info,
2133 asection *input_section,
2134 Elf_Internal_Rela *relocation,
2140 struct bfd_link_hash_entry *h;
2142 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2144 gp = (h->u.def.value
2145 + h->u.def.section->output_section->vma
2146 + h->u.def.section->output_offset);
2148 value -= input_section->output_section->vma;
2149 value -= (gp - input_section->output_section->vma);
2151 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2153 value += relocation->r_addend;
2155 if ((long) value > 0x7ff || (long) value < -0x800)
2156 return bfd_reloc_overflow;
2158 bfd_put_32 (input_bfd,
2159 (insn & 0xfffff000) | (value & 0xfff),
2160 contents + relocation->r_offset);
2162 return bfd_reloc_ok;
2165 /* Handle an FRV small data reloc. for the u12 field. */
2167 static bfd_reloc_status_type
2168 elf32_frv_relocate_gprelu12 (struct bfd_link_info *info,
2170 asection *input_section,
2171 Elf_Internal_Rela *relocation,
2177 struct bfd_link_hash_entry *h;
2180 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2182 gp = (h->u.def.value
2183 + h->u.def.section->output_section->vma
2184 + h->u.def.section->output_offset);
2186 value -= input_section->output_section->vma;
2187 value -= (gp - input_section->output_section->vma);
2189 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2191 value += relocation->r_addend;
2193 if ((long) value > 0x7ff || (long) value < -0x800)
2194 return bfd_reloc_overflow;
2196 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
2198 insn = (insn & ~mask) | ((value & 0xfc0) << 12) | (value & 0x3f);
2200 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
2202 return bfd_reloc_ok;
2205 /* Handle an FRV ELF HI16 reloc. */
2207 static bfd_reloc_status_type
2208 elf32_frv_relocate_hi16 (bfd *input_bfd,
2209 Elf_Internal_Rela *relhi,
2215 insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
2217 value += relhi->r_addend;
2218 value = ((value >> 16) & 0xffff);
2220 insn = (insn & 0xffff0000) | value;
2222 if ((long) value > 0xffff || (long) value < -0x10000)
2223 return bfd_reloc_overflow;
2225 bfd_put_32 (input_bfd, insn, contents + relhi->r_offset);
2226 return bfd_reloc_ok;
2229 static bfd_reloc_status_type
2230 elf32_frv_relocate_lo16 (bfd *input_bfd,
2231 Elf_Internal_Rela *rello,
2237 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
2239 value += rello->r_addend;
2240 value = value & 0xffff;
2242 insn = (insn & 0xffff0000) | value;
2244 if ((long) value > 0xffff || (long) value < -0x10000)
2245 return bfd_reloc_overflow;
2247 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
2248 return bfd_reloc_ok;
2251 /* Perform the relocation for the CALL label24 instruction. */
2253 static bfd_reloc_status_type
2254 elf32_frv_relocate_label24 (bfd *input_bfd,
2255 asection *input_section,
2256 Elf_Internal_Rela *rello,
2264 /* The format for the call instruction is:
2266 0 000000 0001111 000000000000000000
2267 label6 opcode label18
2269 The branch calculation is: pc + (4*label24)
2270 where label24 is the concatenation of label6 and label18. */
2272 /* Grab the instruction. */
2273 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
2275 value -= input_section->output_section->vma + input_section->output_offset;
2276 value -= rello->r_offset;
2277 value += rello->r_addend;
2281 label6 = value & 0xfc0000;
2282 label6 = label6 << 7;
2284 label18 = value & 0x3ffff;
2286 insn = insn & 0x803c0000;
2287 insn = insn | label6;
2288 insn = insn | label18;
2290 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
2292 return bfd_reloc_ok;
2295 static bfd_reloc_status_type
2296 elf32_frv_relocate_gprelhi (struct bfd_link_info *info,
2298 asection *input_section,
2299 Elf_Internal_Rela *relocation,
2305 struct bfd_link_hash_entry *h;
2307 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2309 gp = (h->u.def.value
2310 + h->u.def.section->output_section->vma
2311 + h->u.def.section->output_offset);
2313 value -= input_section->output_section->vma;
2314 value -= (gp - input_section->output_section->vma);
2315 value += relocation->r_addend;
2316 value = ((value >> 16) & 0xffff);
2318 if ((long) value > 0xffff || (long) value < -0x10000)
2319 return bfd_reloc_overflow;
2321 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2322 insn = (insn & 0xffff0000) | value;
2324 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
2325 return bfd_reloc_ok;
2328 static bfd_reloc_status_type
2329 elf32_frv_relocate_gprello (struct bfd_link_info *info,
2331 asection *input_section,
2332 Elf_Internal_Rela *relocation,
2338 struct bfd_link_hash_entry *h;
2340 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2342 gp = (h->u.def.value
2343 + h->u.def.section->output_section->vma
2344 + h->u.def.section->output_offset);
2346 value -= input_section->output_section->vma;
2347 value -= (gp - input_section->output_section->vma);
2348 value += relocation->r_addend;
2349 value = value & 0xffff;
2351 if ((long) value > 0xffff || (long) value < -0x10000)
2352 return bfd_reloc_overflow;
2354 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2355 insn = (insn & 0xffff0000) | value;
2357 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
2359 return bfd_reloc_ok;
2362 static reloc_howto_type *
2363 frv_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2364 bfd_reloc_code_real_type code)
2371 case BFD_RELOC_NONE:
2372 return &elf32_frv_howto_table[ (int) R_FRV_NONE];
2375 if (elf_elfheader (abfd)->e_type == ET_EXEC
2376 || elf_elfheader (abfd)->e_type == ET_DYN)
2377 return &elf32_frv_rel_32_howto;
2379 case BFD_RELOC_CTOR:
2380 return &elf32_frv_howto_table[ (int) R_FRV_32];
2382 case BFD_RELOC_FRV_LABEL16:
2383 return &elf32_frv_howto_table[ (int) R_FRV_LABEL16];
2385 case BFD_RELOC_FRV_LABEL24:
2386 return &elf32_frv_howto_table[ (int) R_FRV_LABEL24];
2388 case BFD_RELOC_FRV_LO16:
2389 return &elf32_frv_howto_table[ (int) R_FRV_LO16];
2391 case BFD_RELOC_FRV_HI16:
2392 return &elf32_frv_howto_table[ (int) R_FRV_HI16];
2394 case BFD_RELOC_FRV_GPREL12:
2395 return &elf32_frv_howto_table[ (int) R_FRV_GPREL12];
2397 case BFD_RELOC_FRV_GPRELU12:
2398 return &elf32_frv_howto_table[ (int) R_FRV_GPRELU12];
2400 case BFD_RELOC_FRV_GPREL32:
2401 return &elf32_frv_howto_table[ (int) R_FRV_GPREL32];
2403 case BFD_RELOC_FRV_GPRELHI:
2404 return &elf32_frv_howto_table[ (int) R_FRV_GPRELHI];
2406 case BFD_RELOC_FRV_GPRELLO:
2407 return &elf32_frv_howto_table[ (int) R_FRV_GPRELLO];
2409 case BFD_RELOC_FRV_GOT12:
2410 return &elf32_frv_howto_table[ (int) R_FRV_GOT12];
2412 case BFD_RELOC_FRV_GOTHI:
2413 return &elf32_frv_howto_table[ (int) R_FRV_GOTHI];
2415 case BFD_RELOC_FRV_GOTLO:
2416 return &elf32_frv_howto_table[ (int) R_FRV_GOTLO];
2418 case BFD_RELOC_FRV_FUNCDESC:
2419 if (elf_elfheader (abfd)->e_type == ET_EXEC
2420 || elf_elfheader (abfd)->e_type == ET_DYN)
2421 return &elf32_frv_rel_funcdesc_howto;
2422 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC];
2424 case BFD_RELOC_FRV_FUNCDESC_GOT12:
2425 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOT12];
2427 case BFD_RELOC_FRV_FUNCDESC_GOTHI:
2428 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTHI];
2430 case BFD_RELOC_FRV_FUNCDESC_GOTLO:
2431 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTLO];
2433 case BFD_RELOC_FRV_FUNCDESC_VALUE:
2434 if (elf_elfheader (abfd)->e_type == ET_EXEC
2435 || elf_elfheader (abfd)->e_type == ET_DYN)
2436 return &elf32_frv_rel_funcdesc_value_howto;
2437 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_VALUE];
2439 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12:
2440 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFF12];
2442 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI:
2443 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFHI];
2445 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO:
2446 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFLO];
2448 case BFD_RELOC_FRV_GOTOFF12:
2449 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFF12];
2451 case BFD_RELOC_FRV_GOTOFFHI:
2452 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFHI];
2454 case BFD_RELOC_FRV_GOTOFFLO:
2455 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFLO];
2457 case BFD_RELOC_FRV_GETTLSOFF:
2458 return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF];
2460 case BFD_RELOC_FRV_TLSDESC_VALUE:
2461 if (elf_elfheader (abfd)->e_type == ET_EXEC
2462 || elf_elfheader (abfd)->e_type == ET_DYN)
2463 return &elf32_frv_rel_tlsdesc_value_howto;
2464 return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_VALUE];
2466 case BFD_RELOC_FRV_GOTTLSDESC12:
2467 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESC12];
2469 case BFD_RELOC_FRV_GOTTLSDESCHI:
2470 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCHI];
2472 case BFD_RELOC_FRV_GOTTLSDESCLO:
2473 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCLO];
2475 case BFD_RELOC_FRV_TLSMOFF12:
2476 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF12];
2478 case BFD_RELOC_FRV_TLSMOFFHI:
2479 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFHI];
2481 case BFD_RELOC_FRV_TLSMOFFLO:
2482 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFLO];
2484 case BFD_RELOC_FRV_GOTTLSOFF12:
2485 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFF12];
2487 case BFD_RELOC_FRV_GOTTLSOFFHI:
2488 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFHI];
2490 case BFD_RELOC_FRV_GOTTLSOFFLO:
2491 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFLO];
2493 case BFD_RELOC_FRV_TLSOFF:
2494 if (elf_elfheader (abfd)->e_type == ET_EXEC
2495 || elf_elfheader (abfd)->e_type == ET_DYN)
2496 return &elf32_frv_rel_tlsoff_howto;
2497 return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF];
2499 case BFD_RELOC_FRV_TLSDESC_RELAX:
2500 return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_RELAX];
2502 case BFD_RELOC_FRV_GETTLSOFF_RELAX:
2503 return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF_RELAX];
2505 case BFD_RELOC_FRV_TLSOFF_RELAX:
2506 return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF_RELAX];
2508 case BFD_RELOC_FRV_TLSMOFF:
2509 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF];
2511 case BFD_RELOC_VTABLE_INHERIT:
2512 return &elf32_frv_vtinherit_howto;
2514 case BFD_RELOC_VTABLE_ENTRY:
2515 return &elf32_frv_vtentry_howto;
2521 static reloc_howto_type *
2522 frv_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
2527 i < sizeof (elf32_frv_howto_table) / sizeof (elf32_frv_howto_table[0]);
2529 if (elf32_frv_howto_table[i].name != NULL
2530 && strcasecmp (elf32_frv_howto_table[i].name, r_name) == 0)
2531 return &elf32_frv_howto_table[i];
2533 if (strcasecmp (elf32_frv_vtinherit_howto.name, r_name) == 0)
2534 return &elf32_frv_vtinherit_howto;
2535 if (strcasecmp (elf32_frv_vtentry_howto.name, r_name) == 0)
2536 return &elf32_frv_vtentry_howto;
2541 /* Set the howto pointer for an FRV ELF reloc. */
2544 frv_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
2546 Elf_Internal_Rela *dst)
2548 unsigned int r_type;
2550 r_type = ELF32_R_TYPE (dst->r_info);
2553 case R_FRV_GNU_VTINHERIT:
2554 cache_ptr->howto = &elf32_frv_vtinherit_howto;
2557 case R_FRV_GNU_VTENTRY:
2558 cache_ptr->howto = &elf32_frv_vtentry_howto;
2562 if (r_type >= (unsigned int) R_FRV_max)
2564 _bfd_error_handler (_("%B: invalid FRV reloc number: %d"), abfd, r_type);
2567 cache_ptr->howto = & elf32_frv_howto_table [r_type];
2572 /* Set the howto pointer for an FRV ELF REL reloc. */
2574 frvfdpic_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
2575 arelent *cache_ptr, Elf_Internal_Rela *dst)
2577 unsigned int r_type;
2579 r_type = ELF32_R_TYPE (dst->r_info);
2583 cache_ptr->howto = &elf32_frv_rel_32_howto;
2586 case R_FRV_FUNCDESC:
2587 cache_ptr->howto = &elf32_frv_rel_funcdesc_howto;
2590 case R_FRV_FUNCDESC_VALUE:
2591 cache_ptr->howto = &elf32_frv_rel_funcdesc_value_howto;
2594 case R_FRV_TLSDESC_VALUE:
2595 cache_ptr->howto = &elf32_frv_rel_tlsdesc_value_howto;
2599 cache_ptr->howto = &elf32_frv_rel_tlsoff_howto;
2603 cache_ptr->howto = NULL;
2608 /* Perform a single relocation. By default we use the standard BFD
2609 routines, but a few relocs, we have to do them ourselves. */
2611 static bfd_reloc_status_type
2612 frv_final_link_relocate (reloc_howto_type *howto,
2614 asection *input_section,
2616 Elf_Internal_Rela *rel,
2619 return _bfd_final_link_relocate (howto, input_bfd, input_section,
2620 contents, rel->r_offset, relocation,
2625 /* Relocate an FRV ELF section.
2627 The RELOCATE_SECTION function is called by the new ELF backend linker
2628 to handle the relocations for a section.
2630 The relocs are always passed as Rela structures; if the section
2631 actually uses Rel structures, the r_addend field will always be
2634 This function is responsible for adjusting the section contents as
2635 necessary, and (if using Rela relocs and generating a relocatable
2636 output file) adjusting the reloc addend as necessary.
2638 This function does not have to worry about setting the reloc
2639 address or the reloc symbol index.
2641 LOCAL_SYMS is a pointer to the swapped in local symbols.
2643 LOCAL_SECTIONS is an array giving the section in the input file
2644 corresponding to the st_shndx field of each local symbol.
2646 The global hash table entry for the global symbols can be found
2647 via elf_sym_hashes (input_bfd).
2649 When generating relocatable output, this function must handle
2650 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2651 going to be the section symbol corresponding to the output
2652 section, which means that the addend must be adjusted
2656 elf32_frv_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
2657 struct bfd_link_info *info,
2659 asection *input_section,
2661 Elf_Internal_Rela *relocs,
2662 Elf_Internal_Sym *local_syms,
2663 asection **local_sections)
2665 Elf_Internal_Shdr *symtab_hdr;
2666 struct elf_link_hash_entry **sym_hashes;
2667 Elf_Internal_Rela *rel;
2668 Elf_Internal_Rela *relend;
2669 unsigned isec_segment, got_segment, plt_segment, gprel_segment, tls_segment,
2671 int silence_segment_error = !bfd_link_pic (info);
2674 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
2675 sym_hashes = elf_sym_hashes (input_bfd);
2676 relend = relocs + input_section->reloc_count;
2678 isec_segment = _frvfdpic_osec_to_segment (output_bfd,
2679 input_section->output_section);
2680 if (IS_FDPIC (output_bfd) && frvfdpic_got_section (info))
2681 got_segment = _frvfdpic_osec_to_segment (output_bfd,
2682 frvfdpic_got_section (info)
2686 if (IS_FDPIC (output_bfd) && frvfdpic_gotfixup_section (info))
2687 gprel_segment = _frvfdpic_osec_to_segment (output_bfd,
2688 frvfdpic_gotfixup_section (info)
2692 if (IS_FDPIC (output_bfd) && frvfdpic_plt_section (info))
2693 plt_segment = _frvfdpic_osec_to_segment (output_bfd,
2694 frvfdpic_plt_section (info)
2698 if (elf_hash_table (info)->tls_sec)
2699 tls_segment = _frvfdpic_osec_to_segment (output_bfd,
2700 elf_hash_table (info)->tls_sec);
2704 for (rel = relocs; rel < relend; rel ++)
2706 reloc_howto_type *howto;
2707 unsigned long r_symndx;
2708 Elf_Internal_Sym *sym;
2710 struct elf_link_hash_entry *h;
2712 bfd_reloc_status_type r;
2716 struct frvfdpic_relocs_info *picrel;
2717 bfd_vma orig_addend = rel->r_addend;
2719 r_type = ELF32_R_TYPE (rel->r_info);
2721 if ( r_type == R_FRV_GNU_VTINHERIT
2722 || r_type == R_FRV_GNU_VTENTRY)
2725 r_symndx = ELF32_R_SYM (rel->r_info);
2726 howto = elf32_frv_howto_table + ELF32_R_TYPE (rel->r_info);
2731 if (r_symndx < symtab_hdr->sh_info)
2733 sym = local_syms + r_symndx;
2734 osec = sec = local_sections [r_symndx];
2735 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
2737 name = bfd_elf_string_from_elf_section
2738 (input_bfd, symtab_hdr->sh_link, sym->st_name);
2739 if (name == NULL || name[0] == 0)
2740 name = bfd_section_name (input_bfd, sec);
2744 bfd_boolean warned, ignored;
2745 bfd_boolean unresolved_reloc;
2747 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2748 r_symndx, symtab_hdr, sym_hashes,
2750 unresolved_reloc, warned, ignored);
2752 name = h->root.root.string;
2755 if (sec != NULL && discarded_section (sec))
2756 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
2757 rel, 1, relend, howto, 0, contents);
2759 if (bfd_link_relocatable (info))
2762 if (r_type != R_FRV_TLSMOFF
2764 && (h->root.type == bfd_link_hash_defined
2765 || h->root.type == bfd_link_hash_defweak)
2766 && !FRVFDPIC_SYM_LOCAL (info, h))
2776 if (! IS_FDPIC (output_bfd))
2783 case R_FRV_FUNCDESC_GOT12:
2784 case R_FRV_FUNCDESC_GOTHI:
2785 case R_FRV_FUNCDESC_GOTLO:
2786 case R_FRV_GOTOFF12:
2787 case R_FRV_GOTOFFHI:
2788 case R_FRV_GOTOFFLO:
2789 case R_FRV_FUNCDESC_GOTOFF12:
2790 case R_FRV_FUNCDESC_GOTOFFHI:
2791 case R_FRV_FUNCDESC_GOTOFFLO:
2792 case R_FRV_FUNCDESC:
2793 case R_FRV_FUNCDESC_VALUE:
2794 case R_FRV_GETTLSOFF:
2795 case R_FRV_TLSDESC_VALUE:
2796 case R_FRV_GOTTLSDESC12:
2797 case R_FRV_GOTTLSDESCHI:
2798 case R_FRV_GOTTLSDESCLO:
2799 case R_FRV_TLSMOFF12:
2800 case R_FRV_TLSMOFFHI:
2801 case R_FRV_TLSMOFFLO:
2802 case R_FRV_GOTTLSOFF12:
2803 case R_FRV_GOTTLSOFFHI:
2804 case R_FRV_GOTTLSOFFLO:
2806 case R_FRV_TLSDESC_RELAX:
2807 case R_FRV_GETTLSOFF_RELAX:
2808 case R_FRV_TLSOFF_RELAX:
2811 picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info
2812 (info), input_bfd, h,
2813 orig_addend, INSERT);
2815 /* In order to find the entry we created before, we must
2816 use the original addend, not the one that may have been
2817 modified by _bfd_elf_rela_local_sym(). */
2818 picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
2819 (info), input_bfd, r_symndx,
2820 orig_addend, INSERT);
2824 if (!_frvfdpic_emit_got_relocs_plt_entries (picrel, output_bfd, info,
2828 info->callbacks->einfo
2829 (_("%H: relocation to `%s+%v'"
2830 " may have caused the error above\n"),
2831 input_bfd, input_section, rel->r_offset, name, rel->r_addend);
2841 && ! FRVFDPIC_SYM_LOCAL (info, h)
2842 && _bfd_elf_section_offset (output_bfd, info, input_section,
2843 rel->r_offset) != (bfd_vma) -1)
2845 info->callbacks->einfo
2846 (_("%H: relocation references symbol"
2847 " not defined in the module\n"),
2848 input_bfd, input_section, rel->r_offset);
2856 case R_FRV_GETTLSOFF:
2857 case R_FRV_TLSDESC_VALUE:
2858 case R_FRV_GOTTLSDESC12:
2859 case R_FRV_GOTTLSDESCHI:
2860 case R_FRV_GOTTLSDESCLO:
2861 case R_FRV_TLSMOFF12:
2862 case R_FRV_TLSMOFFHI:
2863 case R_FRV_TLSMOFFLO:
2864 case R_FRV_GOTTLSOFF12:
2865 case R_FRV_GOTTLSOFFHI:
2866 case R_FRV_GOTTLSOFFLO:
2868 case R_FRV_TLSDESC_RELAX:
2869 case R_FRV_GETTLSOFF_RELAX:
2870 case R_FRV_TLSOFF_RELAX:
2872 if (sec && (bfd_is_abs_section (sec) || bfd_is_und_section (sec)))
2873 relocation += tls_biased_base (info);
2880 /* Try to apply TLS relaxations. */
2885 #define LOCAL_EXEC_P(info, picrel) \
2886 (bfd_link_executable (info) \
2887 && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h)))
2888 #define INITIAL_EXEC_P(info, picrel) \
2889 ((bfd_link_executable (info)|| (info)->flags & DF_STATIC_TLS) \
2890 && (picrel)->tlsoff_entry)
2892 #define IN_RANGE_FOR_OFST12_P(value) \
2893 ((bfd_vma)((value) + 2048) < (bfd_vma)4096)
2894 #define IN_RANGE_FOR_SETLOS_P(value) \
2895 ((bfd_vma)((value) + 32768) < (bfd_vma)65536)
2896 #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \
2897 (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info)))
2899 #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2900 (LOCAL_EXEC_P ((info), (picrel)) \
2901 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2902 #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \
2903 (INITIAL_EXEC_P ((info), (picrel)) \
2904 && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry))
2906 #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \
2907 (LOCAL_EXEC_P ((info), (picrel)))
2908 #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \
2909 (INITIAL_EXEC_P ((info), (picrel)))
2911 #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2912 (LOCAL_EXEC_P ((info), (picrel)) \
2913 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2915 case R_FRV_GETTLSOFF:
2916 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
2918 /* Is this a call instruction? */
2919 if ((insn & (unsigned long)0x01fc0000) != 0x003c0000)
2921 info->callbacks->einfo
2922 (_("%H: R_FRV_GETTLSOFF not applied to a call instruction\n"),
2923 input_bfd, input_section, rel->r_offset);
2927 if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info, picrel,
2928 relocation + rel->r_addend))
2930 /* Replace the call instruction (except the packing bit)
2931 with setlos #tlsmofflo(symbol+offset), gr9. */
2932 insn &= (unsigned long)0x80000000;
2933 insn |= (unsigned long)0x12fc0000;
2934 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
2936 r_type = R_FRV_TLSMOFFLO;
2937 howto = elf32_frv_howto_table + r_type;
2938 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
2941 else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info, picrel))
2943 /* Replace the call instruction (except the packing bit)
2944 with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */
2945 insn &= (unsigned long)0x80000000;
2946 insn |= (unsigned long)0x12c8f000;
2947 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
2949 r_type = R_FRV_GOTTLSOFF12;
2950 howto = elf32_frv_howto_table + r_type;
2951 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
2956 case R_FRV_GOTTLSDESC12:
2957 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
2959 /* Is this an lddi instruction? */
2960 if ((insn & (unsigned long)0x01fc0000) != 0x00cc0000)
2962 info->callbacks->einfo
2963 (_("%H: R_FRV_GOTTLSDESC12"
2964 " not applied to an lddi instruction\n"),
2965 input_bfd, input_section, rel->r_offset);
2969 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
2970 relocation + rel->r_addend)
2971 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
2974 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
2975 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
2976 Preserve the packing bit. */
2977 insn = (insn & (unsigned long)0x80000000)
2978 | ((insn + (unsigned long)0x02000000)
2979 & (unsigned long)0x7e000000);
2980 insn |= (unsigned long)0x00fc0000;
2981 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
2983 r_type = R_FRV_TLSMOFFLO;
2984 howto = elf32_frv_howto_table + r_type;
2985 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
2988 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
2989 relocation + rel->r_addend))
2991 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
2992 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
2993 Preserve the packing bit. */
2994 insn = (insn & (unsigned long)0x80000000)
2995 | ((insn + (unsigned long)0x02000000)
2996 & (unsigned long)0x7e000000);
2997 insn |= (unsigned long)0x00f80000;
2998 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3000 r_type = R_FRV_TLSMOFFHI;
3001 howto = elf32_frv_howto_table + r_type;
3002 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3005 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3007 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3008 with ldi @(grB, #gottlsoff12(symbol+offset),
3009 gr<C+1>. Preserve the packing bit. If gottlsoff12
3010 overflows, we'll error out, but that's sort-of ok,
3011 since we'd started with gottlsdesc12, that's actually
3012 more demanding. Compiling with -fPIE instead of
3013 -fpie would fix it; linking with --relax should fix
3015 insn = (insn & (unsigned long)0x80cbf000)
3016 | ((insn + (unsigned long)0x02000000)
3017 & (unsigned long)0x7e000000);
3018 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3020 r_type = R_FRV_GOTTLSOFF12;
3021 howto = elf32_frv_howto_table + r_type;
3022 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3027 case R_FRV_GOTTLSDESCHI:
3028 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3030 /* Is this a sethi instruction? */
3031 if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
3033 info->callbacks->einfo
3034 (_("%H: R_FRV_GOTTLSDESCHI"
3035 " not applied to a sethi instruction\n"),
3036 input_bfd, input_section, rel->r_offset);
3040 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3041 relocation + rel->r_addend)
3042 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3043 && IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry)))
3045 /* Replace sethi with a nop. Preserve the packing bit. */
3046 insn &= (unsigned long)0x80000000;
3047 insn |= (unsigned long)0x00880000;
3048 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3050 /* Nothing to relocate. */
3054 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3056 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3057 r_type = R_FRV_GOTTLSOFFHI;
3058 howto = elf32_frv_howto_table + r_type;
3059 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3064 case R_FRV_GOTTLSDESCLO:
3065 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3067 /* Is this a setlo or setlos instruction? */
3068 if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
3070 info->callbacks->einfo
3071 (_("%H: R_FRV_GOTTLSDESCLO"
3072 " not applied to a setlo or setlos instruction\n"),
3073 input_bfd, input_section, rel->r_offset);
3077 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3078 relocation + rel->r_addend)
3079 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3080 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
3082 /* Replace setlo/setlos with a nop. Preserve the
3084 insn &= (unsigned long)0x80000000;
3085 insn |= (unsigned long)0x00880000;
3086 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3088 /* Nothing to relocate. */
3092 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3094 /* If the corresponding sethi (if it exists) decayed
3095 to a nop, make sure this becomes (or already is) a
3096 setlos, not setlo. */
3097 if (IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry))
3099 insn |= (unsigned long)0x00080000;
3100 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3103 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3104 r_type = R_FRV_GOTTLSOFFLO;
3105 howto = elf32_frv_howto_table + r_type;
3106 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3111 case R_FRV_TLSDESC_RELAX:
3112 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3114 /* Is this an ldd instruction? */
3115 if ((insn & (unsigned long)0x01fc0fc0) != 0x00080140)
3117 info->callbacks->einfo
3118 (_("%H: R_FRV_TLSDESC_RELAX"
3119 " not applied to an ldd instruction\n"),
3120 input_bfd, input_section, rel->r_offset);
3124 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3125 relocation + rel->r_addend)
3126 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3129 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3130 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3131 Preserve the packing bit. */
3132 insn = (insn & (unsigned long)0x80000000)
3133 | ((insn + (unsigned long)0x02000000)
3134 & (unsigned long)0x7e000000);
3135 insn |= (unsigned long)0x00fc0000;
3136 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3138 r_type = R_FRV_TLSMOFFLO;
3139 howto = elf32_frv_howto_table + r_type;
3140 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3143 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3144 relocation + rel->r_addend))
3146 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3147 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3148 Preserve the packing bit. */
3149 insn = (insn & (unsigned long)0x80000000)
3150 | ((insn + (unsigned long)0x02000000)
3151 & (unsigned long)0x7e000000);
3152 insn |= (unsigned long)0x00f80000;
3153 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3155 r_type = R_FRV_TLSMOFFHI;
3156 howto = elf32_frv_howto_table + r_type;
3157 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3160 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3161 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))
3163 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3164 with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>.
3165 Preserve the packing bit. */
3166 insn = (insn & (unsigned long)0x8003f000)
3167 | (unsigned long)0x00c80000
3168 | ((insn + (unsigned long)0x02000000)
3169 & (unsigned long)0x7e000000);
3170 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3172 r_type = R_FRV_GOTTLSOFF12;
3173 howto = elf32_frv_howto_table + r_type;
3174 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3177 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3179 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3180 with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>.
3181 Preserve the packing bit. */
3182 insn = (insn & (unsigned long)0x81ffffbf)
3183 | ((insn + (unsigned long)0x02000000)
3184 & (unsigned long)0x7e000000);
3185 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3187 /* #tlsoff(symbol+offset) is just a relaxation
3188 annotation, so there's nothing left to
3195 case R_FRV_GETTLSOFF_RELAX:
3196 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3198 /* Is this a calll or callil instruction? */
3199 if ((insn & (unsigned long)0x7ff80fc0) != 0x02300000)
3201 info->callbacks->einfo
3202 (_("%H: R_FRV_GETTLSOFF_RELAX"
3203 " not applied to a calll instruction\n"),
3204 input_bfd, input_section, rel->r_offset);
3208 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3209 relocation + rel->r_addend)
3210 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3213 /* Replace calll with a nop. Preserve the packing bit. */
3214 insn &= (unsigned long)0x80000000;
3215 insn |= (unsigned long)0x00880000;
3216 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3218 /* Nothing to relocate. */
3222 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3223 relocation + rel->r_addend))
3225 /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9.
3226 Preserve the packing bit. */
3227 insn &= (unsigned long)0x80000000;
3228 insn |= (unsigned long)0x12f40000;
3229 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3231 r_type = R_FRV_TLSMOFFLO;
3232 howto = elf32_frv_howto_table + r_type;
3233 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3236 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3238 /* Replace calll with a nop. Preserve the packing bit. */
3239 insn &= (unsigned long)0x80000000;
3240 insn |= (unsigned long)0x00880000;
3241 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3243 /* Nothing to relocate. */
3249 case R_FRV_GOTTLSOFF12:
3250 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3252 /* Is this an ldi instruction? */
3253 if ((insn & (unsigned long)0x01fc0000) != 0x00c80000)
3255 info->callbacks->einfo
3256 (_("%H: R_FRV_GOTTLSOFF12"
3257 " not applied to an ldi instruction\n"),
3258 input_bfd, input_section, rel->r_offset);
3262 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3263 relocation + rel->r_addend))
3265 /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC
3266 with setlos #tlsmofflo(symbol+offset), grC.
3267 Preserve the packing bit. */
3268 insn &= (unsigned long)0xfe000000;
3269 insn |= (unsigned long)0x00fc0000;
3270 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3272 r_type = R_FRV_TLSMOFFLO;
3273 howto = elf32_frv_howto_table + r_type;
3274 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3279 case R_FRV_GOTTLSOFFHI:
3280 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3282 /* Is this a sethi instruction? */
3283 if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
3285 info->callbacks->einfo
3286 (_("%H: R_FRV_GOTTLSOFFHI"
3287 " not applied to a sethi instruction\n"),
3288 input_bfd, input_section, rel->r_offset);
3292 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3293 relocation + rel->r_addend)
3294 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3295 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
3297 /* Replace sethi with a nop. Preserve the packing bit. */
3298 insn &= (unsigned long)0x80000000;
3299 insn |= (unsigned long)0x00880000;
3300 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3302 /* Nothing to relocate. */
3308 case R_FRV_GOTTLSOFFLO:
3309 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3311 /* Is this a setlo or setlos instruction? */
3312 if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
3314 info->callbacks->einfo
3315 (_("%H: R_FRV_GOTTLSOFFLO"
3316 " not applied to a setlo or setlos instruction\n"),
3317 input_bfd, input_section, rel->r_offset);
3321 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3322 relocation + rel->r_addend)
3323 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3324 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
3326 /* Replace setlo/setlos with a nop. Preserve the
3328 insn &= (unsigned long)0x80000000;
3329 insn |= (unsigned long)0x00880000;
3330 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3332 /* Nothing to relocate. */
3338 case R_FRV_TLSOFF_RELAX:
3339 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3341 /* Is this an ld instruction? */
3342 if ((insn & (unsigned long)0x01fc0fc0) != 0x00080100)
3344 info->callbacks->einfo
3345 (_("%H: R_FRV_TLSOFF_RELAX"
3346 " not applied to an ld instruction\n"),
3347 input_bfd, input_section, rel->r_offset);
3351 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3352 relocation + rel->r_addend))
3354 /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC
3355 with setlos #tlsmofflo(symbol+offset), grC.
3356 Preserve the packing bit. */
3357 insn &= (unsigned long)0xfe000000;
3358 insn |= (unsigned long)0x00fc0000;
3359 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3361 r_type = R_FRV_TLSMOFFLO;
3362 howto = elf32_frv_howto_table + r_type;
3363 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3366 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3367 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))
3369 /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC
3370 with ldi @(grB, #gottlsoff12(symbol+offset), grC.
3371 Preserve the packing bit. */
3372 insn = (insn & (unsigned long)0xfe03f000)
3373 | (unsigned long)0x00c80000;
3374 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3376 r_type = R_FRV_GOTTLSOFF12;
3377 howto = elf32_frv_howto_table + r_type;
3378 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3383 case R_FRV_TLSMOFFHI:
3384 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3386 /* Is this a sethi instruction? */
3387 if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
3389 info->callbacks->einfo
3390 (_("%H: R_FRV_TLSMOFFHI"
3391 " not applied to a sethi instruction\n"),
3392 input_bfd, input_section, rel->r_offset);
3396 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3399 /* Replace sethi with a nop. Preserve the packing bit. */
3400 insn &= (unsigned long)0x80000000;
3401 insn |= (unsigned long)0x00880000;
3402 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3404 /* Nothing to relocate. */
3410 case R_FRV_TLSMOFFLO:
3411 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3413 /* Is this a setlo or setlos instruction? */
3414 if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
3416 info->callbacks->einfo
3417 (_("R_FRV_TLSMOFFLO"
3418 " not applied to a setlo or setlos instruction\n"),
3419 input_bfd, input_section, rel->r_offset);
3423 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3425 /* If the corresponding sethi (if it exists) decayed
3426 to a nop, make sure this becomes (or already is) a
3427 setlos, not setlo. */
3429 insn |= (unsigned long)0x00080000;
3430 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3436 There's nothing to relax in these:
3452 check_segment[0] = isec_segment;
3453 if (! IS_FDPIC (output_bfd))
3454 check_segment[1] = isec_segment;
3455 else if (picrel->plt)
3457 relocation = frvfdpic_plt_section (info)->output_section->vma
3458 + frvfdpic_plt_section (info)->output_offset
3459 + picrel->plt_entry;
3460 check_segment[1] = plt_segment;
3462 /* We don't want to warn on calls to undefined weak symbols,
3463 as calls to them must be protected by non-NULL tests
3464 anyway, and unprotected calls would invoke undefined
3466 else if (picrel->symndx == -1
3467 && picrel->d.h->root.type == bfd_link_hash_undefweak)
3468 check_segment[1] = check_segment[0];
3470 check_segment[1] = sec
3471 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3478 relocation = picrel->got_entry;
3479 check_segment[0] = check_segment[1] = got_segment;
3482 case R_FRV_FUNCDESC_GOT12:
3483 case R_FRV_FUNCDESC_GOTHI:
3484 case R_FRV_FUNCDESC_GOTLO:
3485 relocation = picrel->fdgot_entry;
3486 check_segment[0] = check_segment[1] = got_segment;
3489 case R_FRV_GOTOFFHI:
3490 case R_FRV_GOTOFF12:
3491 case R_FRV_GOTOFFLO:
3492 relocation -= frvfdpic_got_section (info)->output_section->vma
3493 + frvfdpic_got_section (info)->output_offset
3494 + frvfdpic_got_initial_offset (info);
3495 check_segment[0] = got_segment;
3496 check_segment[1] = sec
3497 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3501 case R_FRV_FUNCDESC_GOTOFF12:
3502 case R_FRV_FUNCDESC_GOTOFFHI:
3503 case R_FRV_FUNCDESC_GOTOFFLO:
3504 relocation = picrel->fd_entry;
3505 check_segment[0] = check_segment[1] = got_segment;
3508 case R_FRV_FUNCDESC:
3511 bfd_vma addend = rel->r_addend;
3513 if (! (h && h->root.type == bfd_link_hash_undefweak
3514 && FRVFDPIC_SYM_LOCAL (info, h)))
3516 /* If the symbol is dynamic and there may be dynamic
3517 symbol resolution because we are or are linked with a
3518 shared library, emit a FUNCDESC relocation such that
3519 the dynamic linker will allocate the function
3520 descriptor. If the symbol needs a non-local function
3521 descriptor but binds locally (e.g., its visibility is
3522 protected, emit a dynamic relocation decayed to
3524 if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h)
3525 && FRVFDPIC_SYM_LOCAL (info, h)
3526 && !bfd_link_pde (info))
3528 dynindx = elf_section_data (h->root.u.def.section
3529 ->output_section)->dynindx;
3530 addend += h->root.u.def.section->output_offset
3531 + h->root.u.def.value;
3533 else if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h))
3537 info->callbacks->einfo
3538 (_("%H: R_FRV_FUNCDESC references dynamic symbol"
3539 " with nonzero addend\n"),
3540 input_bfd, input_section, rel->r_offset);
3543 dynindx = h->dynindx;
3547 /* Otherwise, we know we have a private function
3548 descriptor, so reference it directly. */
3549 BFD_ASSERT (picrel->privfd);
3551 dynindx = elf_section_data (frvfdpic_got_section (info)
3552 ->output_section)->dynindx;
3553 addend = frvfdpic_got_section (info)->output_offset
3554 + frvfdpic_got_initial_offset (info)
3558 /* If there is room for dynamic symbol resolution, emit
3559 the dynamic relocation. However, if we're linking an
3560 executable at a fixed location, we won't have emitted a
3561 dynamic symbol entry for the got section, so idx will
3562 be zero, which means we can and should compute the
3563 address of the private descriptor ourselves. */
3564 if (bfd_link_pde (info)
3565 && (!h || FRVFDPIC_FUNCDESC_LOCAL (info, h)))
3567 addend += frvfdpic_got_section (info)->output_section->vma;
3568 if ((bfd_get_section_flags (output_bfd,
3569 input_section->output_section)
3570 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
3574 if (_frvfdpic_osec_readonly_p (output_bfd,
3578 info->callbacks->einfo
3579 (_("%H: cannot emit fixups"
3580 " in read-only section\n"),
3581 input_bfd, input_section, rel->r_offset);
3585 offset = _bfd_elf_section_offset
3587 input_section, rel->r_offset);
3589 if (offset != (bfd_vma)-1)
3590 _frvfdpic_add_rofixup (output_bfd,
3591 frvfdpic_gotfixup_section
3593 offset + input_section
3594 ->output_section->vma
3595 + input_section->output_offset,
3599 else if ((bfd_get_section_flags (output_bfd,
3600 input_section->output_section)
3601 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
3605 if (_frvfdpic_osec_readonly_p (output_bfd,
3609 info->callbacks->einfo
3610 (_("%H: cannot emit dynamic relocations"
3611 " in read-only section\n"),
3612 input_bfd, input_section, rel->r_offset);
3616 offset = _bfd_elf_section_offset
3618 input_section, rel->r_offset);
3620 if (offset != (bfd_vma)-1)
3621 _frvfdpic_add_dyn_reloc (output_bfd,
3622 frvfdpic_gotrel_section (info),
3623 offset + input_section
3624 ->output_section->vma
3625 + input_section->output_offset,
3626 r_type, dynindx, addend, picrel);
3629 addend += frvfdpic_got_section (info)->output_section->vma;
3632 /* We want the addend in-place because dynamic
3633 relocations are REL. Setting relocation to it should
3634 arrange for it to be installed. */
3635 relocation = addend - rel->r_addend;
3637 check_segment[0] = check_segment[1] = got_segment;
3641 if (! IS_FDPIC (output_bfd))
3643 check_segment[0] = check_segment[1] = -1;
3647 case R_FRV_FUNCDESC_VALUE:
3650 bfd_vma addend = rel->r_addend;
3652 /* If the symbol is dynamic but binds locally, use
3654 if (h && ! FRVFDPIC_SYM_LOCAL (info, h))
3656 if (addend && r_type == R_FRV_FUNCDESC_VALUE)
3658 info->callbacks->einfo
3659 (_("%H: R_FRV_FUNCDESC_VALUE"
3660 " references dynamic symbol with nonzero addend\n"),
3661 input_bfd, input_section, rel->r_offset);
3664 dynindx = h->dynindx;
3669 addend += h->root.u.def.value;
3671 addend += sym->st_value;
3673 addend += osec->output_offset;
3674 if (osec && osec->output_section
3675 && ! bfd_is_abs_section (osec->output_section)
3676 && ! bfd_is_und_section (osec->output_section))
3677 dynindx = elf_section_data (osec->output_section)->dynindx;
3682 /* If we're linking an executable at a fixed address, we
3683 can omit the dynamic relocation as long as the symbol
3684 is defined in the current link unit (which is implied
3685 by its output section not being NULL). */
3686 if (bfd_link_pde (info)
3687 && (!h || FRVFDPIC_SYM_LOCAL (info, h)))
3690 addend += osec->output_section->vma;
3691 if (IS_FDPIC (input_bfd)
3692 && (bfd_get_section_flags (output_bfd,
3693 input_section->output_section)
3694 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
3696 if (_frvfdpic_osec_readonly_p (output_bfd,
3700 info->callbacks->einfo
3701 (_("%H: cannot emit fixups in read-only section\n"),
3702 input_bfd, input_section, rel->r_offset);
3705 if (!h || h->root.type != bfd_link_hash_undefweak)
3707 bfd_vma offset = _bfd_elf_section_offset
3709 input_section, rel->r_offset);
3711 if (offset != (bfd_vma)-1)
3713 _frvfdpic_add_rofixup (output_bfd,
3714 frvfdpic_gotfixup_section
3716 offset + input_section
3717 ->output_section->vma
3718 + input_section->output_offset,
3720 if (r_type == R_FRV_FUNCDESC_VALUE)
3721 _frvfdpic_add_rofixup
3723 frvfdpic_gotfixup_section (info),
3725 + input_section->output_section->vma
3726 + input_section->output_offset + 4, picrel);
3733 if ((bfd_get_section_flags (output_bfd,
3734 input_section->output_section)
3735 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
3739 if (_frvfdpic_osec_readonly_p (output_bfd,
3743 info->callbacks->einfo
3744 (_("%H: cannot emit dynamic relocations"
3745 " in read-only section\n"),
3746 input_bfd, input_section, rel->r_offset);
3750 offset = _bfd_elf_section_offset
3752 input_section, rel->r_offset);
3754 if (offset != (bfd_vma)-1)
3755 _frvfdpic_add_dyn_reloc (output_bfd,
3756 frvfdpic_gotrel_section (info),
3757 offset + input_section
3758 ->output_section->vma
3759 + input_section->output_offset,
3760 r_type, dynindx, addend, picrel);
3763 addend += osec->output_section->vma;
3764 /* We want the addend in-place because dynamic
3765 relocations are REL. Setting relocation to it
3766 should arrange for it to be installed. */
3767 relocation = addend - rel->r_addend;
3770 if (r_type == R_FRV_FUNCDESC_VALUE)
3772 /* If we've omitted the dynamic relocation, just emit
3773 the fixed addresses of the symbol and of the local
3775 if (bfd_link_pde (info)
3776 && (!h || FRVFDPIC_SYM_LOCAL (info, h)))
3777 bfd_put_32 (output_bfd,
3778 frvfdpic_got_section (info)->output_section->vma
3779 + frvfdpic_got_section (info)->output_offset
3780 + frvfdpic_got_initial_offset (info),
3781 contents + rel->r_offset + 4);
3783 /* A function descriptor used for lazy or local
3784 resolving is initialized such that its high word
3785 contains the output section index in which the
3786 PLT entries are located, and the low word
3787 contains the offset of the lazy PLT entry entry
3788 point into that section. */
3789 bfd_put_32 (output_bfd,
3790 h && ! FRVFDPIC_SYM_LOCAL (info, h)
3792 : _frvfdpic_osec_to_segment (output_bfd,
3795 contents + rel->r_offset + 4);
3798 check_segment[0] = check_segment[1] = got_segment;
3802 case R_FRV_GPRELU12:
3806 check_segment[0] = gprel_segment;
3807 check_segment[1] = sec
3808 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3812 case R_FRV_GETTLSOFF:
3813 relocation = frvfdpic_plt_section (info)->output_section->vma
3814 + frvfdpic_plt_section (info)->output_offset
3815 + picrel->tlsplt_entry;
3816 BFD_ASSERT (picrel->tlsplt_entry != (bfd_vma)-1
3817 && picrel->tlsdesc_entry);
3818 check_segment[0] = isec_segment;
3819 check_segment[1] = plt_segment;
3822 case R_FRV_GOTTLSDESC12:
3823 case R_FRV_GOTTLSDESCHI:
3824 case R_FRV_GOTTLSDESCLO:
3825 BFD_ASSERT (picrel->tlsdesc_entry);
3826 relocation = picrel->tlsdesc_entry;
3827 check_segment[0] = tls_segment;
3828 check_segment[1] = sec
3829 && ! bfd_is_abs_section (sec)
3830 && ! bfd_is_und_section (sec)
3831 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3835 case R_FRV_TLSMOFF12:
3836 case R_FRV_TLSMOFFHI:
3837 case R_FRV_TLSMOFFLO:
3839 check_segment[0] = tls_segment;
3841 check_segment[1] = -1;
3842 else if (bfd_is_abs_section (sec)
3843 || bfd_is_und_section (sec))
3846 check_segment[1] = tls_segment;
3848 else if (sec->output_section)
3850 relocation -= tls_biased_base (info);
3852 _frvfdpic_osec_to_segment (output_bfd, sec->output_section);
3855 check_segment[1] = -1;
3858 case R_FRV_GOTTLSOFF12:
3859 case R_FRV_GOTTLSOFFHI:
3860 case R_FRV_GOTTLSOFFLO:
3861 BFD_ASSERT (picrel->tlsoff_entry);
3862 relocation = picrel->tlsoff_entry;
3863 check_segment[0] = tls_segment;
3864 check_segment[1] = sec
3865 && ! bfd_is_abs_section (sec)
3866 && ! bfd_is_und_section (sec)
3867 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3871 case R_FRV_TLSDESC_VALUE:
3873 /* These shouldn't be present in input object files. */
3874 check_segment[0] = check_segment[1] = isec_segment;
3877 case R_FRV_TLSDESC_RELAX:
3878 case R_FRV_GETTLSOFF_RELAX:
3879 case R_FRV_TLSOFF_RELAX:
3880 /* These are just annotations for relaxation, nothing to do
3885 check_segment[0] = isec_segment;
3886 check_segment[1] = sec
3887 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3892 if (check_segment[0] != check_segment[1] && IS_FDPIC (output_bfd))
3894 /* If you take this out, remove the #error from fdpic-static-6.d
3895 in the ld testsuite. */
3896 /* This helps catch problems in GCC while we can't do more
3897 than static linking. The idea is to test whether the
3898 input file basename is crt0.o only once. */
3899 if (silence_segment_error == 1)
3900 silence_segment_error =
3901 (strlen (input_bfd->filename) == 6
3902 && filename_cmp (input_bfd->filename, "crt0.o") == 0)
3903 || (strlen (input_bfd->filename) > 6
3904 && filename_cmp (input_bfd->filename
3905 + strlen (input_bfd->filename) - 7,
3908 if (!silence_segment_error
3909 /* We don't want duplicate errors for undefined
3911 && !(picrel && picrel->symndx == -1
3912 && picrel->d.h->root.type == bfd_link_hash_undefined))
3914 info->callbacks->einfo
3915 (_("%H: reloc against `%s' references a different segment\n"),
3916 input_bfd, input_section, rel->r_offset, name);
3918 if (!silence_segment_error && bfd_link_pic (info))
3920 elf_elfheader (output_bfd)->e_flags |= EF_FRV_PIC;
3925 case R_FRV_GOTOFFHI:
3926 case R_FRV_TLSMOFFHI:
3927 /* We need the addend to be applied before we shift the
3929 relocation += rel->r_addend;
3932 case R_FRV_FUNCDESC_GOTHI:
3933 case R_FRV_FUNCDESC_GOTOFFHI:
3934 case R_FRV_GOTTLSOFFHI:
3935 case R_FRV_GOTTLSDESCHI:
3940 case R_FRV_FUNCDESC_GOTLO:
3941 case R_FRV_GOTOFFLO:
3942 case R_FRV_FUNCDESC_GOTOFFLO:
3943 case R_FRV_GOTTLSOFFLO:
3944 case R_FRV_GOTTLSDESCLO:
3945 case R_FRV_TLSMOFFLO:
3946 relocation &= 0xffff;
3956 if (! IS_FDPIC (output_bfd) || ! picrel->plt)
3960 /* When referencing a GOT entry, a function descriptor or a
3961 PLT, we don't want the addend to apply to the reference,
3962 but rather to the referenced symbol. The actual entry
3963 will have already been created taking the addend into
3964 account, so cancel it out here. */
3968 case R_FRV_FUNCDESC_GOT12:
3969 case R_FRV_FUNCDESC_GOTHI:
3970 case R_FRV_FUNCDESC_GOTLO:
3971 case R_FRV_FUNCDESC_GOTOFF12:
3972 case R_FRV_FUNCDESC_GOTOFFHI:
3973 case R_FRV_FUNCDESC_GOTOFFLO:
3974 case R_FRV_GETTLSOFF:
3975 case R_FRV_GOTTLSDESC12:
3976 case R_FRV_GOTTLSDESCHI:
3977 case R_FRV_GOTTLSDESCLO:
3978 case R_FRV_GOTTLSOFF12:
3979 case R_FRV_GOTTLSOFFHI:
3980 case R_FRV_GOTTLSOFFLO:
3981 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
3982 here, since we do want to apply the addend to the others.
3983 Note that we've applied the addend to GOTOFFHI before we
3984 shifted it right. */
3985 case R_FRV_GOTOFFHI:
3986 case R_FRV_TLSMOFFHI:
3987 relocation -= rel->r_addend;
3994 if (r_type == R_FRV_HI16)
3995 r = elf32_frv_relocate_hi16 (input_bfd, rel, contents, relocation);
3997 else if (r_type == R_FRV_LO16)
3998 r = elf32_frv_relocate_lo16 (input_bfd, rel, contents, relocation);
4000 else if (r_type == R_FRV_LABEL24 || r_type == R_FRV_GETTLSOFF)
4001 r = elf32_frv_relocate_label24 (input_bfd, input_section, rel,
4002 contents, relocation);
4004 else if (r_type == R_FRV_GPREL12)
4005 r = elf32_frv_relocate_gprel12 (info, input_bfd, input_section, rel,
4006 contents, relocation);
4008 else if (r_type == R_FRV_GPRELU12)
4009 r = elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, rel,
4010 contents, relocation);
4012 else if (r_type == R_FRV_GPRELLO)
4013 r = elf32_frv_relocate_gprello (info, input_bfd, input_section, rel,
4014 contents, relocation);
4016 else if (r_type == R_FRV_GPRELHI)
4017 r = elf32_frv_relocate_gprelhi (info, input_bfd, input_section, rel,
4018 contents, relocation);
4020 else if (r_type == R_FRV_TLSOFF
4021 || r_type == R_FRV_TLSDESC_VALUE)
4022 r = bfd_reloc_notsupported;
4025 r = frv_final_link_relocate (howto, input_bfd, input_section, contents,
4028 if (r != bfd_reloc_ok)
4030 const char * msg = (const char *) NULL;
4034 case bfd_reloc_overflow:
4035 (*info->callbacks->reloc_overflow)
4036 (info, (h ? &h->root : NULL), name, howto->name,
4037 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
4040 case bfd_reloc_undefined:
4041 (*info->callbacks->undefined_symbol)
4042 (info, name, input_bfd, input_section, rel->r_offset, TRUE);
4045 case bfd_reloc_outofrange:
4046 msg = _("internal error: out of range error");
4049 case bfd_reloc_notsupported:
4050 msg = _("internal error: unsupported relocation error");
4053 case bfd_reloc_dangerous:
4054 msg = _("internal error: dangerous relocation");
4058 msg = _("internal error: unknown error");
4064 info->callbacks->einfo
4065 (_("%H: reloc against `%s': %s\n"),
4066 input_bfd, input_section, rel->r_offset, name, msg);
4075 /* Return the section that should be marked against GC for a given
4079 elf32_frv_gc_mark_hook (asection *sec,
4080 struct bfd_link_info *info,
4081 Elf_Internal_Rela *rel,
4082 struct elf_link_hash_entry *h,
4083 Elf_Internal_Sym *sym)
4086 switch (ELF32_R_TYPE (rel->r_info))
4088 case R_FRV_GNU_VTINHERIT:
4089 case R_FRV_GNU_VTENTRY:
4093 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
4096 /* Hook called by the linker routine which adds symbols from an object
4097 file. We use it to put .comm items in .scomm, and not .comm. */
4100 elf32_frv_add_symbol_hook (bfd *abfd,
4101 struct bfd_link_info *info,
4102 Elf_Internal_Sym *sym,
4103 const char **namep ATTRIBUTE_UNUSED,
4104 flagword *flagsp ATTRIBUTE_UNUSED,
4108 if (sym->st_shndx == SHN_COMMON
4109 && !bfd_link_relocatable (info)
4110 && (int)sym->st_size <= (int)bfd_get_gp_size (abfd))
4112 /* Common symbols less than or equal to -G nn bytes are
4113 automatically put into .sbss. */
4115 asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
4119 scomm = bfd_make_section_with_flags (abfd, ".scommon",
4122 | SEC_LINKER_CREATED));
4128 *valp = sym->st_size;
4134 /* We need dynamic symbols for every section, since segments can
4135 relocate independently. */
4137 _frvfdpic_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED,
4138 struct bfd_link_info *info
4140 asection *p ATTRIBUTE_UNUSED)
4142 switch (elf_section_data (p)->this_hdr.sh_type)
4146 /* If sh_type is yet undecided, assume it could be
4147 SHT_PROGBITS/SHT_NOBITS. */
4151 /* There shouldn't be section relative relocations
4152 against any other section. */
4158 /* Create a .got section, as well as its additional info field. This
4159 is almost entirely copied from
4160 elflink.c:_bfd_elf_create_got_section(). */
4163 _frv_create_got_section (bfd *abfd, struct bfd_link_info *info)
4165 flagword flags, pltflags;
4167 struct elf_link_hash_entry *h;
4168 struct bfd_link_hash_entry *bh;
4169 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
4173 /* This function may be called more than once. */
4174 s = bfd_get_linker_section (abfd, ".got");
4178 /* Machine specific: although pointers are 32-bits wide, we want the
4179 GOT to be aligned to a 64-bit boundary, such that function
4180 descriptors in it can be accessed with 64-bit loads and
4184 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4185 | SEC_LINKER_CREATED);
4188 s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
4190 || !bfd_set_section_alignment (abfd, s, ptralign))
4193 if (bed->want_got_plt)
4195 s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
4197 || !bfd_set_section_alignment (abfd, s, ptralign))
4201 if (bed->want_got_sym)
4203 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
4204 (or .got.plt) section. We don't do this in the linker script
4205 because we don't want to define the symbol if we are not creating
4206 a global offset table. */
4207 h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_");
4208 elf_hash_table (info)->hgot = h;
4212 /* Machine-specific: we want the symbol for executables as
4214 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4218 /* The first bit of the global offset table is the header. */
4219 s->size += bed->got_header_size;
4221 /* This is the machine-specific part. Create and initialize section
4222 data for the got. */
4223 if (IS_FDPIC (abfd))
4225 frvfdpic_got_section (info) = s;
4226 frvfdpic_relocs_info (info) = htab_try_create (1,
4227 frvfdpic_relocs_info_hash,
4228 frvfdpic_relocs_info_eq,
4230 if (! frvfdpic_relocs_info (info))
4233 s = bfd_make_section_anyway_with_flags (abfd, ".rel.got",
4234 (flags | SEC_READONLY));
4236 || ! bfd_set_section_alignment (abfd, s, 2))
4239 frvfdpic_gotrel_section (info) = s;
4241 /* Machine-specific. */
4242 s = bfd_make_section_anyway_with_flags (abfd, ".rofixup",
4243 (flags | SEC_READONLY));
4245 || ! bfd_set_section_alignment (abfd, s, 2))
4248 frvfdpic_gotfixup_section (info) = s;
4255 flags = BSF_GLOBAL | BSF_WEAK;
4258 /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it
4259 turns out that we're linking with a different linker script, the
4260 linker script will override it. */
4262 if (!(_bfd_generic_link_add_one_symbol
4263 (info, abfd, "_gp", flags, s, offset, (const char *) NULL, FALSE,
4264 bed->collect, &bh)))
4266 h = (struct elf_link_hash_entry *) bh;
4268 h->type = STT_OBJECT;
4269 /* h->other = STV_HIDDEN; */ /* Should we? */
4271 /* Machine-specific: we want the symbol for executables as well. */
4272 if (IS_FDPIC (abfd) && ! bfd_elf_link_record_dynamic_symbol (info, h))
4275 if (!IS_FDPIC (abfd))
4278 /* FDPIC supports Thread Local Storage, and this may require a
4279 procedure linkage table for TLS PLT entries. */
4281 /* This is mostly copied from
4282 elflink.c:_bfd_elf_create_dynamic_sections(). */
4285 pltflags |= SEC_CODE;
4286 if (bed->plt_not_loaded)
4287 pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS);
4288 if (bed->plt_readonly)
4289 pltflags |= SEC_READONLY;
4291 s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags);
4293 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
4295 /* FRV-specific: remember it. */
4296 frvfdpic_plt_section (info) = s;
4298 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
4300 if (bed->want_plt_sym)
4302 h = _bfd_elf_define_linkage_sym (abfd, info, s,
4303 "_PROCEDURE_LINKAGE_TABLE_");
4304 elf_hash_table (info)->hplt = h;
4309 /* FRV-specific: we want rel relocations for the plt. */
4310 s = bfd_make_section_anyway_with_flags (abfd, ".rel.plt",
4311 flags | SEC_READONLY);
4313 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
4315 /* FRV-specific: remember it. */
4316 frvfdpic_pltrel_section (info) = s;
4321 /* Make sure the got and plt sections exist, and that our pointers in
4322 the link hash table point to them. */
4325 elf32_frvfdpic_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
4327 /* This is mostly copied from
4328 elflink.c:_bfd_elf_create_dynamic_sections(). */
4331 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
4333 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4334 | SEC_LINKER_CREATED);
4336 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
4337 .rel[a].bss sections. */
4339 /* FRV-specific: we want to create the GOT and the PLT in the FRV
4341 if (! _frv_create_got_section (abfd, info))
4344 /* FRV-specific: make sure we created everything we wanted. */
4345 BFD_ASSERT (frvfdpic_got_section (info) && frvfdpic_gotrel_section (info)
4346 && frvfdpic_gotfixup_section (info)
4347 && frvfdpic_plt_section (info)
4348 && frvfdpic_pltrel_section (info));
4350 if (bed->want_dynbss)
4352 /* The .dynbss section is a place to put symbols which are defined
4353 by dynamic objects, are referenced by regular objects, and are
4354 not functions. We must allocate space for them in the process
4355 image and use a R_*_COPY reloc to tell the dynamic linker to
4356 initialize them at run time. The linker script puts the .dynbss
4357 section into the .bss section of the final image. */
4358 s = bfd_make_section_anyway_with_flags (abfd, ".dynbss",
4359 SEC_ALLOC | SEC_LINKER_CREATED);
4363 /* The .rel[a].bss section holds copy relocs. This section is not
4364 normally needed. We need to create it here, though, so that the
4365 linker will map it to an output section. We can't just create it
4366 only if we need it, because we will not know whether we need it
4367 until we have seen all the input files, and the first time the
4368 main linker code calls BFD after examining all the input files
4369 (size_dynamic_sections) the input sections have already been
4370 mapped to the output sections. If the section turns out not to
4371 be needed, we can discard it later. We will never need this
4372 section when generating a shared object, since they do not use
4374 if (! bfd_link_pic (info))
4376 s = bfd_make_section_anyway_with_flags (abfd,
4377 (bed->default_use_rela_p
4378 ? ".rela.bss" : ".rel.bss"),
4379 flags | SEC_READONLY);
4381 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
4389 /* Compute the total GOT and PLT size required by each symbol in each
4390 range. Symbols may require up to 4 words in the GOT: an entry
4391 pointing to the symbol, an entry pointing to its function
4392 descriptor, and a private function descriptors taking two
4396 _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info *entry,
4397 struct _frvfdpic_dynamic_got_info *dinfo)
4399 /* Allocate space for a GOT entry pointing to the symbol. */
4402 else if (entry->gotlos)
4404 else if (entry->gothilo)
4405 dinfo->gothilo += 4;
4410 /* Allocate space for a GOT entry pointing to the function
4414 else if (entry->fdgotlos)
4416 else if (entry->fdgothilo)
4417 dinfo->gothilo += 4;
4422 /* Decide whether we need a PLT entry, a function descriptor in the
4423 GOT, and a lazy PLT entry for this symbol. */
4424 entry->plt = entry->call
4425 && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
4426 && elf_hash_table (dinfo->info)->dynamic_sections_created;
4427 entry->privfd = entry->plt
4428 || entry->fdgoff12 || entry->fdgofflos || entry->fdgoffhilo
4429 || ((entry->fd || entry->fdgot12 || entry->fdgotlos || entry->fdgothilo)
4430 && (entry->symndx != -1
4431 || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h)));
4432 entry->lazyplt = entry->privfd
4433 && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
4434 && ! (dinfo->info->flags & DF_BIND_NOW)
4435 && elf_hash_table (dinfo->info)->dynamic_sections_created;
4437 /* Allocate space for a function descriptor. */
4438 if (entry->fdgoff12)
4440 else if (entry->fdgofflos)
4442 else if (entry->privfd && entry->plt)
4444 else if (entry->privfd)
4454 /* Compute the total GOT size required by each TLS symbol in each
4455 range. Symbols may require up to 5 words in the GOT: an entry
4456 holding the TLS offset for the symbol, and an entry with a full TLS
4457 descriptor taking 4 words. */
4460 _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info *entry,
4461 struct _frvfdpic_dynamic_got_info *dinfo,
4462 bfd_boolean subtract)
4464 const int l = subtract ? -1 : 1;
4466 /* Allocate space for a GOT entry with the TLS offset of the
4468 if (entry->tlsoff12)
4469 dinfo->got12 += 4 * l;
4470 else if (entry->tlsofflos)
4471 dinfo->gotlos += 4 * l;
4472 else if (entry->tlsoffhilo)
4473 dinfo->gothilo += 4 * l;
4475 entry->relocstlsoff -= l;
4476 entry->relocstlsoff += l;
4478 /* If there's any TLSOFF relocation, mark the output file as not
4479 suitable for dlopening. This mark will remain even if we relax
4480 all such relocations, but this is not a problem, since we'll only
4481 do so for executables, and we definitely don't want anyone
4482 dlopening executables. */
4483 if (entry->relocstlsoff)
4484 dinfo->info->flags |= DF_STATIC_TLS;
4486 /* Allocate space for a TLS descriptor. */
4487 if (entry->tlsdesc12)
4488 dinfo->tlsd12 += 8 * l;
4489 else if (entry->tlsdesclos)
4490 dinfo->tlsdlos += 8 * l;
4491 else if (entry->tlsplt)
4492 dinfo->tlsdplt += 8 * l;
4493 else if (entry->tlsdeschilo)
4494 dinfo->tlsdhilo += 8 * l;
4496 entry->relocstlsd -= l;
4497 entry->relocstlsd += l;
4500 /* Compute the number of dynamic relocations and fixups that a symbol
4501 requires, and add (or subtract) from the grand and per-symbol
4505 _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info *entry,
4506 struct _frvfdpic_dynamic_got_info *dinfo,
4507 bfd_boolean subtract)
4509 bfd_vma relocs = 0, fixups = 0, tlsrets = 0;
4511 if (!bfd_link_pde (dinfo->info))
4513 relocs = entry->relocs32 + entry->relocsfd + entry->relocsfdv
4514 + entry->relocstlsd;
4516 /* In the executable, TLS relocations to symbols that bind
4517 locally (including those that resolve to global TLS offsets)
4518 are resolved immediately, without any need for fixups or
4519 dynamic relocations. In shared libraries, however, we must
4520 emit dynamic relocations even for local symbols, because we
4521 don't know the module id the library is going to get at
4522 run-time, nor its TLS base offset. */
4523 if (!bfd_link_executable (dinfo->info)
4524 || (entry->symndx == -1
4525 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)))
4526 relocs += entry->relocstlsoff;
4530 if (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h))
4532 if (entry->symndx != -1
4533 || entry->d.h->root.type != bfd_link_hash_undefweak)
4534 fixups += entry->relocs32 + 2 * entry->relocsfdv;
4535 fixups += entry->relocstlsd;
4536 tlsrets += entry->relocstlsd;
4540 relocs += entry->relocs32 + entry->relocsfdv
4541 + entry->relocstlsoff + entry->relocstlsd;
4544 if (entry->symndx != -1
4545 || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h))
4547 if (entry->symndx != -1
4548 || entry->d.h->root.type != bfd_link_hash_undefweak)
4549 fixups += entry->relocsfd;
4552 relocs += entry->relocsfd;
4559 tlsrets = - tlsrets;
4562 entry->dynrelocs += relocs;
4563 entry->fixups += fixups;
4564 dinfo->relocs += relocs;
4565 dinfo->fixups += fixups;
4566 dinfo->tls_ret_refs += tlsrets;
4569 /* Look for opportunities to relax TLS relocations. We can assume
4570 we're linking the main executable or a static-tls library, since
4571 otherwise we wouldn't have got here. When relaxing, we have to
4572 first undo any previous accounting of TLS uses of fixups, dynamic
4573 relocations, GOT and PLT entries. */
4576 _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info *entry,
4577 struct _frvfdpic_dynamic_got_info *dinfo,
4578 bfd_boolean relaxing)
4580 bfd_boolean changed = ! relaxing;
4582 BFD_ASSERT (bfd_link_executable (dinfo->info)
4583 || (dinfo->info->flags & DF_STATIC_TLS));
4585 if (entry->tlsdesc12 || entry->tlsdesclos || entry->tlsdeschilo)
4589 _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE);
4590 _frvfdpic_count_tls_entries (entry, dinfo, TRUE);
4594 /* When linking an executable, we can always decay GOTTLSDESC to
4595 TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise.
4596 When linking a static-tls shared library, using TLSMOFF is
4597 not an option, but we can still use GOTTLSOFF. When decaying
4598 to GOTTLSOFF, we must keep the GOT entry in range. We know
4599 it has to fit because we'll be trading the 4 words of hte TLS
4600 descriptor for a single word in the same range. */
4601 if (! bfd_link_executable (dinfo->info)
4602 || (entry->symndx == -1
4603 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)))
4605 entry->tlsoff12 |= entry->tlsdesc12;
4606 entry->tlsofflos |= entry->tlsdesclos;
4607 entry->tlsoffhilo |= entry->tlsdeschilo;
4610 entry->tlsdesc12 = entry->tlsdesclos = entry->tlsdeschilo = 0;
4613 /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the
4614 main executable. We have to check whether the symbol's TLSOFF is
4615 in range for a setlos. For symbols with a hash entry, we can
4616 determine exactly what to do; for others locals, we don't have
4617 addresses handy, so we use the size of the TLS section as an
4618 approximation. If we get it wrong, we'll retain a GOT entry
4619 holding the TLS offset (without dynamic relocations or fixups),
4620 but we'll still optimize away the loads from it. Since TLS sizes
4621 are generally very small, it's probably not worth attempting to
4622 do better than this. */
4624 || entry->tlsoff12 || entry->tlsofflos || entry->tlsoffhilo)
4625 && bfd_link_executable (dinfo->info) && relaxing
4626 && ((entry->symndx == -1
4627 && FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
4628 /* The above may hold for an undefweak TLS symbol, so make
4629 sure we don't have this case before accessing def.value
4631 && (entry->d.h->root.type == bfd_link_hash_undefweak
4632 || (bfd_vma)(entry->d.h->root.u.def.value
4633 + (entry->d.h->root.u.def.section
4634 ->output_section->vma)
4635 + entry->d.h->root.u.def.section->output_offset
4637 - tls_biased_base (dinfo->info)
4638 + 32768) < (bfd_vma)65536))
4639 || (entry->symndx != -1
4640 && (elf_hash_table (dinfo->info)->tls_sec->size
4641 + entry->addend < 32768 + FRVFDPIC_TLS_BIAS))))
4645 _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE);
4646 _frvfdpic_count_tls_entries (entry, dinfo, TRUE);
4651 entry->tlsoff12 = entry->tlsofflos = entry->tlsoffhilo = 0;
4654 /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already
4655 have a #gottlsoff12 relocation for this entry, or if we can fit
4656 one more in the 12-bit (and 16-bit) ranges. */
4660 && dinfo->got12 + dinfo->fd12 + dinfo->tlsd12 <= 4096 - 12 - 4
4661 && (dinfo->got12 + dinfo->fd12 + dinfo->tlsd12
4662 + dinfo->gotlos + dinfo->fdlos + dinfo->tlsdlos
4663 <= 65536 - 12 - 4))))
4667 _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE);
4668 _frvfdpic_count_tls_entries (entry, dinfo, TRUE);
4672 entry->tlsoff12 = 1;
4678 _frvfdpic_count_tls_entries (entry, dinfo, FALSE);
4679 _frvfdpic_count_relocs_fixups (entry, dinfo, FALSE);
4685 /* Compute the total GOT and PLT size required by each symbol in each range. *
4686 Symbols may require up to 4 words in the GOT: an entry pointing to
4687 the symbol, an entry pointing to its function descriptor, and a
4688 private function descriptors taking two words. */
4691 _frvfdpic_count_got_plt_entries (void **entryp, void *dinfo_)
4693 struct frvfdpic_relocs_info *entry = *entryp;
4694 struct _frvfdpic_dynamic_got_info *dinfo = dinfo_;
4696 _frvfdpic_count_nontls_entries (entry, dinfo);
4698 if (bfd_link_executable (dinfo->info)
4699 || (dinfo->info->flags & DF_STATIC_TLS))
4700 _frvfdpic_relax_tls_entries (entry, dinfo, FALSE);
4703 _frvfdpic_count_tls_entries (entry, dinfo, FALSE);
4704 _frvfdpic_count_relocs_fixups (entry, dinfo, FALSE);
4710 /* Determine the positive and negative ranges to be used by each
4711 offset range in the GOT. FDCUR and CUR, that must be aligned to a
4712 double-word boundary, are the minimum (negative) and maximum
4713 (positive) GOT offsets already used by previous ranges, except for
4714 an ODD entry that may have been left behind. GOT and FD indicate
4715 the size of GOT entries and function descriptors that must be
4716 placed within the range from -WRAP to WRAP. If there's room left,
4717 up to FDPLT bytes should be reserved for additional function
4720 inline static bfd_signed_vma
4721 _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data *gad,
4722 bfd_signed_vma fdcur,
4732 bfd_signed_vma wrapmin = -wrap;
4733 const bfd_vma tdescsz = 8;
4735 /* Start at the given initial points. */
4739 /* If we had an incoming odd word and we have any got entries that
4740 are going to use it, consume it, otherwise leave gad->odd at
4741 zero. We might force gad->odd to zero and return the incoming
4742 odd such that it is used by the next range, but then GOT entries
4743 might appear to be out of order and we wouldn't be able to
4744 shorten the GOT by one word if it turns out to end with an
4745 unpaired GOT entry. */
4755 /* If we're left with an unpaired GOT entry, compute its location
4756 such that we can return it. Otherwise, if got doesn't require an
4757 odd number of words here, either odd was already zero in the
4758 block above, or it was set to zero because got was non-zero, or
4759 got was already zero. In the latter case, we want the value of
4760 odd to carry over to the return statement, so we don't want to
4761 reset odd unless the condition below is true. */
4768 /* Compute the tentative boundaries of this range. */
4769 gad->max = cur + got;
4770 gad->min = fdcur - fd;
4773 /* If function descriptors took too much space, wrap some of them
4775 if (gad->min < wrapmin)
4777 gad->max += wrapmin - gad->min;
4778 gad->tmin = gad->min = wrapmin;
4781 /* If GOT entries took too much space, wrap some of them around.
4782 This may well cause gad->min to become lower than wrapmin. This
4783 will cause a relocation overflow later on, so we don't have to
4785 if ((bfd_vma) gad->max > wrap)
4787 gad->min -= gad->max - wrap;
4791 /* Add TLS descriptors. */
4792 gad->tmax = gad->max + tlsd;
4793 gad->tmin = gad->min;
4796 /* If TLS descriptors took too much space, wrap an integral number
4798 if ((bfd_vma) gad->tmax > wrap)
4800 bfd_vma wrapsize = gad->tmax - wrap;
4802 wrapsize += tdescsz / 2;
4803 wrapsize &= ~ tdescsz / 2;
4805 gad->tmin -= wrapsize;
4806 gad->tmax -= wrapsize;
4809 /* If there is space left and we have function descriptors
4810 referenced in PLT entries that could take advantage of shorter
4811 offsets, place them now. */
4812 if (fdplt && gad->tmin > wrapmin)
4816 if ((bfd_vma) (gad->tmin - wrapmin) < fdplt)
4817 fds = gad->tmin - wrapmin;
4827 /* If there is more space left, try to place some more function
4828 descriptors for PLT entries. */
4829 if (fdplt && (bfd_vma) gad->tmax < wrap)
4833 if ((bfd_vma) (wrap - gad->tmax) < fdplt)
4834 fds = wrap - gad->tmax;
4844 /* If there is space left and we have TLS descriptors referenced in
4845 PLT entries that could take advantage of shorter offsets, place
4847 if (tlsdplt && gad->tmin > wrapmin)
4851 if ((bfd_vma) (gad->tmin - wrapmin) < tlsdplt)
4852 tlsds = (gad->tmin - wrapmin) & ~ (tdescsz / 2);
4858 gad->tlsdplt += tlsds;
4861 /* If there is more space left, try to place some more TLS
4862 descriptors for PLT entries. Although we could try to fit an
4863 additional TLS descriptor with half of it just before before the
4864 wrap point and another right past the wrap point, this might
4865 cause us to run out of space for the next region, so don't do
4867 if (tlsdplt && (bfd_vma) gad->tmax < wrap - tdescsz / 2)
4871 if ((bfd_vma) (wrap - gad->tmax) < tlsdplt)
4872 tlsds = (wrap - gad->tmax) & ~ (tdescsz / 2);
4878 gad->tlsdplt += tlsds;
4881 /* If odd was initially computed as an offset past the wrap point,
4884 odd = gad->min + odd - gad->max;
4886 /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed
4887 before returning, so do it here too. This guarantees that,
4888 should cur and fdcur meet at the wrap point, they'll both be
4890 if (gad->cur == gad->max)
4891 gad->cur = gad->min;
4893 /* Ditto for _frvfdpic_get_tlsdesc_entry(). */
4894 gad->tcur = gad->max;
4895 if (gad->tcur == gad->tmax)
4896 gad->tcur = gad->tmin;
4901 /* Compute the location of the next GOT entry, given the allocation
4902 data for a range. */
4904 inline static bfd_signed_vma
4905 _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
4911 /* If there was an odd word left behind, use it. */
4917 /* Otherwise, use the word pointed to by cur, reserve the next
4918 as an odd word, and skip to the next pair of words, possibly
4921 gad->odd = gad->cur + 4;
4923 if (gad->cur == gad->max)
4924 gad->cur = gad->min;
4930 /* Compute the location of the next function descriptor entry in the
4931 GOT, given the allocation data for a range. */
4933 inline static bfd_signed_vma
4934 _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
4936 /* If we're at the bottom, wrap around, and only then allocate the
4937 next pair of words. */
4938 if (gad->fdcur == gad->min)
4939 gad->fdcur = gad->max;
4940 return gad->fdcur -= 8;
4943 /* Compute the location of the next TLS descriptor entry in the GOT,
4944 given the allocation data for a range. */
4945 inline static bfd_signed_vma
4946 _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
4954 /* If we're at the top of the region, wrap around to the bottom. */
4955 if (gad->tcur == gad->tmax)
4956 gad->tcur = gad->tmin;
4961 /* Assign GOT offsets for every GOT entry and function descriptor.
4962 Doing everything in a single pass is tricky. */
4965 _frvfdpic_assign_got_entries (void **entryp, void *info_)
4967 struct frvfdpic_relocs_info *entry = *entryp;
4968 struct _frvfdpic_dynamic_got_plt_info *dinfo = info_;
4971 entry->got_entry = _frvfdpic_get_got_entry (&dinfo->got12);
4972 else if (entry->gotlos)
4973 entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
4974 else if (entry->gothilo)
4975 entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
4978 entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->got12);
4979 else if (entry->fdgotlos)
4980 entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
4981 else if (entry->fdgothilo)
4982 entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
4984 if (entry->fdgoff12)
4985 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12);
4986 else if (entry->plt && dinfo->got12.fdplt)
4988 dinfo->got12.fdplt -= 8;
4989 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12);
4991 else if (entry->fdgofflos)
4992 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos);
4993 else if (entry->plt && dinfo->gotlos.fdplt)
4995 dinfo->gotlos.fdplt -= 8;
4996 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos);
4998 else if (entry->plt)
5000 dinfo->gothilo.fdplt -= 8;
5001 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo);
5003 else if (entry->privfd)
5004 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo);
5006 if (entry->tlsoff12)
5007 entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->got12);
5008 else if (entry->tlsofflos)
5009 entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
5010 else if (entry->tlsoffhilo)
5011 entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
5013 if (entry->tlsdesc12)
5014 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12);
5015 else if (entry->tlsplt && dinfo->got12.tlsdplt)
5017 dinfo->got12.tlsdplt -= 8;
5018 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12);
5020 else if (entry->tlsdesclos)
5021 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos);
5022 else if (entry->tlsplt && dinfo->gotlos.tlsdplt)
5024 dinfo->gotlos.tlsdplt -= 8;
5025 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos);
5027 else if (entry->tlsplt)
5029 dinfo->gothilo.tlsdplt -= 8;
5030 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo);
5032 else if (entry->tlsdeschilo)
5033 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo);
5038 /* Assign GOT offsets to private function descriptors used by PLT
5039 entries (or referenced by 32-bit offsets), as well as PLT entries
5040 and lazy PLT entries. */
5043 _frvfdpic_assign_plt_entries (void **entryp, void *info_)
5045 struct frvfdpic_relocs_info *entry = *entryp;
5046 struct _frvfdpic_dynamic_got_plt_info *dinfo = info_;
5049 BFD_ASSERT (entry->fd_entry);
5055 /* We use the section's raw size to mark the location of the
5057 entry->plt_entry = frvfdpic_plt_section (dinfo->g.info)->size;
5059 /* Figure out the length of this PLT entry based on the
5060 addressing mode we need to reach the function descriptor. */
5061 BFD_ASSERT (entry->fd_entry);
5062 if (entry->fd_entry >= -(1 << (12 - 1))
5063 && entry->fd_entry < (1 << (12 - 1)))
5065 else if (entry->fd_entry >= -(1 << (16 - 1))
5066 && entry->fd_entry < (1 << (16 - 1)))
5071 frvfdpic_plt_section (dinfo->g.info)->size += size;
5076 entry->lzplt_entry = dinfo->g.lzplt;
5077 dinfo->g.lzplt += 8;
5078 /* If this entry is the one that gets the resolver stub, account
5079 for the additional instruction. */
5080 if (entry->lzplt_entry % FRVFDPIC_LZPLT_BLOCK_SIZE
5081 == FRVFDPIC_LZPLT_RESOLV_LOC)
5082 dinfo->g.lzplt += 4;
5090 = frvfdpic_plt_section (dinfo->g.info)->size;
5092 if (bfd_link_executable (dinfo->g.info)
5093 && (entry->symndx != -1
5094 || FRVFDPIC_SYM_LOCAL (dinfo->g.info, entry->d.h)))
5096 if ((bfd_signed_vma)entry->addend >= -(1 << (16 - 1))
5097 /* FIXME: here we use the size of the TLS section
5098 as an upper bound for the value of the TLS
5099 symbol, because we may not know the exact value
5100 yet. If we get it wrong, we'll just waste a
5101 word in the PLT, and we should never get even
5102 close to 32 KiB of TLS anyway. */
5103 && elf_hash_table (dinfo->g.info)->tls_sec
5104 && (elf_hash_table (dinfo->g.info)->tls_sec->size
5105 + (bfd_signed_vma)(entry->addend) <= (1 << (16 - 1))))
5110 else if (entry->tlsoff_entry)
5112 if (entry->tlsoff_entry >= -(1 << (12 - 1))
5113 && entry->tlsoff_entry < (1 << (12 - 1)))
5115 else if (entry->tlsoff_entry >= -(1 << (16 - 1))
5116 && entry->tlsoff_entry < (1 << (16 - 1)))
5123 BFD_ASSERT (entry->tlsdesc_entry);
5125 if (entry->tlsdesc_entry >= -(1 << (12 - 1))
5126 && entry->tlsdesc_entry < (1 << (12 - 1)))
5128 else if (entry->tlsdesc_entry >= -(1 << (16 - 1))
5129 && entry->tlsdesc_entry < (1 << (16 - 1)))
5135 frvfdpic_plt_section (dinfo->g.info)->size += size;
5141 /* Cancel out any effects of calling _frvfdpic_assign_got_entries and
5142 _frvfdpic_assign_plt_entries. */
5145 _frvfdpic_reset_got_plt_entries (void **entryp, void *ignore ATTRIBUTE_UNUSED)
5147 struct frvfdpic_relocs_info *entry = *entryp;
5149 entry->got_entry = 0;
5150 entry->fdgot_entry = 0;
5151 entry->fd_entry = 0;
5152 entry->plt_entry = (bfd_vma)-1;
5153 entry->lzplt_entry = (bfd_vma)-1;
5154 entry->tlsoff_entry = 0;
5155 entry->tlsdesc_entry = 0;
5156 entry->tlsplt_entry = (bfd_vma)-1;
5161 /* Follow indirect and warning hash entries so that each got entry
5162 points to the final symbol definition. P must point to a pointer
5163 to the hash table we're traversing. Since this traversal may
5164 modify the hash table, we set this pointer to NULL to indicate
5165 we've made a potentially-destructive change to the hash table, so
5166 the traversal must be restarted. */
5168 _frvfdpic_resolve_final_relocs_info (void **entryp, void *p)
5170 struct frvfdpic_relocs_info *entry = *entryp;
5173 if (entry->symndx == -1)
5175 struct elf_link_hash_entry *h = entry->d.h;
5176 struct frvfdpic_relocs_info *oentry;
5178 while (h->root.type == bfd_link_hash_indirect
5179 || h->root.type == bfd_link_hash_warning)
5180 h = (struct elf_link_hash_entry *)h->root.u.i.link;
5182 if (entry->d.h == h)
5185 oentry = frvfdpic_relocs_info_for_global (*htab, 0, h, entry->addend,
5190 /* Merge the two entries. */
5191 frvfdpic_pic_merge_early_relocs_info (oentry, entry);
5192 htab_clear_slot (*htab, entryp);
5198 /* If we can't find this entry with the new bfd hash, re-insert
5199 it, and get the traversal restarted. */
5200 if (! htab_find (*htab, entry))
5202 htab_clear_slot (*htab, entryp);
5203 entryp = htab_find_slot (*htab, entry, INSERT);
5206 /* Abort the traversal, since the whole table may have
5207 moved, and leave it up to the parent to restart the
5209 *(htab_t *)p = NULL;
5217 /* Compute the total size of the GOT, the PLT, the dynamic relocations
5218 section and the rofixup section. Assign locations for GOT and PLT
5222 _frvfdpic_size_got_plt (bfd *output_bfd,
5223 struct _frvfdpic_dynamic_got_plt_info *gpinfop)
5226 bfd_vma limit, tlslimit;
5227 struct bfd_link_info *info = gpinfop->g.info;
5228 bfd *dynobj = elf_hash_table (info)->dynobj;
5230 memcpy (frvfdpic_dynamic_got_plt_info (info), &gpinfop->g,
5231 sizeof (gpinfop->g));
5234 /* Compute the total size taken by entries in the 12-bit and 16-bit
5235 ranges, to tell how many PLT function descriptors we can bring
5236 into the 12-bit range without causing the 16-bit range to
5238 limit = odd + gpinfop->g.got12 + gpinfop->g.gotlos
5239 + gpinfop->g.fd12 + gpinfop->g.fdlos
5240 + gpinfop->g.tlsd12 + gpinfop->g.tlsdlos;
5241 if (limit < (bfd_vma)1 << 16)
5242 limit = ((bfd_vma)1 << 16) - limit;
5245 if (gpinfop->g.fdplt < limit)
5247 tlslimit = (limit - gpinfop->g.fdplt) & ~ (bfd_vma) 8;
5248 limit = gpinfop->g.fdplt;
5252 if (gpinfop->g.tlsdplt < tlslimit)
5253 tlslimit = gpinfop->g.tlsdplt;
5255 /* Determine the ranges of GOT offsets that we can use for each
5256 range of addressing modes. */
5257 odd = _frvfdpic_compute_got_alloc_data (&gpinfop->got12,
5266 (bfd_vma)1 << (12-1));
5267 odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gotlos,
5268 gpinfop->got12.tmin,
5270 gpinfop->got12.tmax,
5274 - gpinfop->got12.fdplt,
5277 - gpinfop->got12.tlsdplt,
5278 (bfd_vma)1 << (16-1));
5279 odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gothilo,
5280 gpinfop->gotlos.tmin,
5282 gpinfop->gotlos.tmax,
5286 - gpinfop->got12.fdplt
5287 - gpinfop->gotlos.fdplt,
5288 gpinfop->g.tlsdhilo,
5290 - gpinfop->got12.tlsdplt
5291 - gpinfop->gotlos.tlsdplt,
5292 (bfd_vma)1 << (32-1));
5294 /* Now assign (most) GOT offsets. */
5295 htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_got_entries,
5298 frvfdpic_got_section (info)->size = gpinfop->gothilo.tmax
5299 - gpinfop->gothilo.tmin
5300 /* If an odd word is the last word of the GOT, we don't need this
5301 word to be part of the GOT. */
5302 - (odd + 4 == gpinfop->gothilo.tmax ? 4 : 0);
5303 if (frvfdpic_got_section (info)->size == 0)
5304 frvfdpic_got_section (info)->flags |= SEC_EXCLUDE;
5305 else if (frvfdpic_got_section (info)->size == 12
5306 && ! elf_hash_table (info)->dynamic_sections_created)
5308 frvfdpic_got_section (info)->flags |= SEC_EXCLUDE;
5309 frvfdpic_got_section (info)->size = 0;
5311 /* This will be non-NULL during relaxation. The assumption is that
5312 the size of one of these sections will never grow, only shrink,
5313 so we can use the larger buffer we allocated before. */
5314 else if (frvfdpic_got_section (info)->contents == NULL)
5316 frvfdpic_got_section (info)->contents =
5317 (bfd_byte *) bfd_zalloc (dynobj,
5318 frvfdpic_got_section (info)->size);
5319 if (frvfdpic_got_section (info)->contents == NULL)
5323 if (frvfdpic_gotrel_section (info))
5324 /* Subtract the number of lzplt entries, since those will generate
5325 relocations in the pltrel section. */
5326 frvfdpic_gotrel_section (info)->size =
5327 (gpinfop->g.relocs - gpinfop->g.lzplt / 8)
5328 * get_elf_backend_data (output_bfd)->s->sizeof_rel;
5330 BFD_ASSERT (gpinfop->g.relocs == 0);
5331 if (frvfdpic_gotrel_section (info)->size == 0)
5332 frvfdpic_gotrel_section (info)->flags |= SEC_EXCLUDE;
5333 else if (frvfdpic_gotrel_section (info)->contents == NULL)
5335 frvfdpic_gotrel_section (info)->contents =
5336 (bfd_byte *) bfd_zalloc (dynobj,
5337 frvfdpic_gotrel_section (info)->size);
5338 if (frvfdpic_gotrel_section (info)->contents == NULL)
5342 frvfdpic_gotfixup_section (info)->size = (gpinfop->g.fixups + 1) * 4;
5343 if (frvfdpic_gotfixup_section (info)->size == 0)
5344 frvfdpic_gotfixup_section (info)->flags |= SEC_EXCLUDE;
5345 else if (frvfdpic_gotfixup_section (info)->contents == NULL)
5347 frvfdpic_gotfixup_section (info)->contents =
5348 (bfd_byte *) bfd_zalloc (dynobj,
5349 frvfdpic_gotfixup_section (info)->size);
5350 if (frvfdpic_gotfixup_section (info)->contents == NULL)
5354 if (frvfdpic_pltrel_section (info))
5356 frvfdpic_pltrel_section (info)->size =
5357 gpinfop->g.lzplt / 8
5358 * get_elf_backend_data (output_bfd)->s->sizeof_rel;
5359 if (frvfdpic_pltrel_section (info)->size == 0)
5360 frvfdpic_pltrel_section (info)->flags |= SEC_EXCLUDE;
5361 else if (frvfdpic_pltrel_section (info)->contents == NULL)
5363 frvfdpic_pltrel_section (info)->contents =
5364 (bfd_byte *) bfd_zalloc (dynobj,
5365 frvfdpic_pltrel_section (info)->size);
5366 if (frvfdpic_pltrel_section (info)->contents == NULL)
5371 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
5372 such that there's room for the additional instruction needed to
5373 call the resolver. Since _frvfdpic_assign_got_entries didn't
5374 account for them, our block size is 4 bytes smaller than the real
5376 if (frvfdpic_plt_section (info))
5378 frvfdpic_plt_section (info)->size = gpinfop->g.lzplt
5379 + ((gpinfop->g.lzplt + (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) - 8)
5380 / (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) * 4);
5383 /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to
5384 actually assign lazy PLT entries addresses. */
5385 gpinfop->g.lzplt = 0;
5387 /* Save information that we're going to need to generate GOT and PLT
5389 frvfdpic_got_initial_offset (info) = -gpinfop->gothilo.tmin;
5391 if (get_elf_backend_data (output_bfd)->want_got_sym)
5392 elf_hash_table (info)->hgot->root.u.def.value
5393 = frvfdpic_got_initial_offset (info);
5395 if (frvfdpic_plt_section (info))
5396 frvfdpic_plt_initial_offset (info) =
5397 frvfdpic_plt_section (info)->size;
5399 /* Allocate a ret statement at plt_initial_offset, to be used by
5400 locally-resolved TLS descriptors. */
5401 if (gpinfop->g.tls_ret_refs)
5402 frvfdpic_plt_section (info)->size += 4;
5404 htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_plt_entries,
5407 /* Allocate the PLT section contents only after
5408 _frvfdpic_assign_plt_entries has a chance to add the size of the
5409 non-lazy PLT entries. */
5410 if (frvfdpic_plt_section (info))
5412 if (frvfdpic_plt_section (info)->size == 0)
5413 frvfdpic_plt_section (info)->flags |= SEC_EXCLUDE;
5414 else if (frvfdpic_plt_section (info)->contents == NULL)
5416 frvfdpic_plt_section (info)->contents =
5417 (bfd_byte *) bfd_zalloc (dynobj,
5418 frvfdpic_plt_section (info)->size);
5419 if (frvfdpic_plt_section (info)->contents == NULL)
5427 /* Set the sizes of the dynamic sections. */
5430 elf32_frvfdpic_size_dynamic_sections (bfd *output_bfd,
5431 struct bfd_link_info *info)
5435 struct _frvfdpic_dynamic_got_plt_info gpinfo;
5437 dynobj = elf_hash_table (info)->dynobj;
5438 BFD_ASSERT (dynobj != NULL);
5440 if (elf_hash_table (info)->dynamic_sections_created)
5442 /* Set the contents of the .interp section to the interpreter. */
5443 if (bfd_link_executable (info) && !info->nointerp)
5445 s = bfd_get_linker_section (dynobj, ".interp");
5446 BFD_ASSERT (s != NULL);
5447 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
5448 s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
5452 memset (&gpinfo, 0, sizeof (gpinfo));
5453 gpinfo.g.info = info;
5457 htab_t relocs = frvfdpic_relocs_info (info);
5459 htab_traverse (relocs, _frvfdpic_resolve_final_relocs_info, &relocs);
5461 if (relocs == frvfdpic_relocs_info (info))
5465 htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_count_got_plt_entries,
5468 /* Allocate space to save the summary information, we're going to
5469 use it if we're doing relaxations. */
5470 frvfdpic_dynamic_got_plt_info (info) = bfd_alloc (dynobj, sizeof (gpinfo.g));
5472 if (!_frvfdpic_size_got_plt (output_bfd, &gpinfo))
5475 if (elf_hash_table (info)->dynamic_sections_created)
5477 if (frvfdpic_got_section (info)->size)
5478 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0))
5481 if (frvfdpic_pltrel_section (info)->size)
5482 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
5483 || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_REL)
5484 || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
5487 if (frvfdpic_gotrel_section (info)->size)
5488 if (!_bfd_elf_add_dynamic_entry (info, DT_REL, 0)
5489 || !_bfd_elf_add_dynamic_entry (info, DT_RELSZ, 0)
5490 || !_bfd_elf_add_dynamic_entry (info, DT_RELENT,
5491 sizeof (Elf32_External_Rel)))
5499 elf32_frvfdpic_always_size_sections (bfd *output_bfd,
5500 struct bfd_link_info *info)
5502 if (!bfd_link_relocatable (info)
5503 && !bfd_elf_stack_segment_size (output_bfd, info,
5504 "__stacksize", DEFAULT_STACK_SIZE))
5510 /* Check whether any of the relocations was optimized away, and
5511 subtract it from the relocation or fixup count. */
5513 _frvfdpic_check_discarded_relocs (bfd *abfd, asection *sec,
5514 struct bfd_link_info *info,
5516 bfd_boolean *changed)
5518 Elf_Internal_Shdr *symtab_hdr;
5519 struct elf_link_hash_entry **sym_hashes;
5520 Elf_Internal_Rela *rel, *erel;
5522 if ((sec->flags & SEC_RELOC) == 0
5523 || sec->reloc_count == 0)
5526 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
5527 sym_hashes = elf_sym_hashes (abfd);
5529 rel = elf_section_data (sec)->relocs;
5531 /* Now examine each relocation. */
5532 for (erel = rel + sec->reloc_count; rel < erel; rel++)
5534 struct elf_link_hash_entry *h;
5535 unsigned long r_symndx;
5536 struct frvfdpic_relocs_info *picrel;
5537 struct _frvfdpic_dynamic_got_info *dinfo;
5539 if (ELF32_R_TYPE (rel->r_info) != R_FRV_32
5540 && ELF32_R_TYPE (rel->r_info) != R_FRV_FUNCDESC)
5543 if (_bfd_elf_section_offset (sec->output_section->owner,
5544 info, sec, rel->r_offset)
5548 r_symndx = ELF32_R_SYM (rel->r_info);
5549 if (r_symndx < symtab_hdr->sh_info)
5553 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5554 while (h->root.type == bfd_link_hash_indirect
5555 || h->root.type == bfd_link_hash_warning)
5556 h = (struct elf_link_hash_entry *)h->root.u.i.link;
5560 picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info),
5562 rel->r_addend, NO_INSERT);
5564 picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info (info),
5566 rel->r_addend, NO_INSERT);
5572 dinfo = frvfdpic_dynamic_got_plt_info (info);
5574 _frvfdpic_count_relocs_fixups (picrel, dinfo, TRUE);
5575 if (ELF32_R_TYPE (rel->r_info) == R_FRV_32)
5577 else /* we know (ELF32_R_TYPE (rel->r_info) == R_FRV_FUNCDESC) */
5579 _frvfdpic_count_relocs_fixups (picrel, dinfo, FALSE);
5586 frvfdpic_elf_discard_info (bfd *ibfd,
5587 struct elf_reloc_cookie *cookie ATTRIBUTE_UNUSED,
5588 struct bfd_link_info *info)
5590 bfd_boolean changed = FALSE;
5594 /* Account for relaxation of .eh_frame section. */
5595 for (s = ibfd->sections; s; s = s->next)
5596 if (s->sec_info_type == SEC_INFO_TYPE_EH_FRAME)
5598 if (!_frvfdpic_check_discarded_relocs (ibfd, s, info, &changed))
5600 obfd = s->output_section->owner;
5605 struct _frvfdpic_dynamic_got_plt_info gpinfo;
5607 memset (&gpinfo, 0, sizeof (gpinfo));
5608 memcpy (&gpinfo.g, frvfdpic_dynamic_got_plt_info (info),
5611 /* Clear GOT and PLT assignments. */
5612 htab_traverse (frvfdpic_relocs_info (info),
5613 _frvfdpic_reset_got_plt_entries,
5616 if (!_frvfdpic_size_got_plt (obfd, &gpinfo))
5623 /* Look for opportunities to relax TLS relocations. We can assume
5624 we're linking the main executable or a static-tls library, since
5625 otherwise we wouldn't have got here. */
5628 _frvfdpic_relax_got_plt_entries (void **entryp, void *dinfo_)
5630 struct frvfdpic_relocs_info *entry = *entryp;
5631 struct _frvfdpic_dynamic_got_info *dinfo = dinfo_;
5633 _frvfdpic_relax_tls_entries (entry, dinfo, TRUE);
5639 elf32_frvfdpic_relax_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
5640 struct bfd_link_info *info, bfd_boolean *again)
5642 struct _frvfdpic_dynamic_got_plt_info gpinfo;
5644 if (bfd_link_relocatable (info))
5645 (*info->callbacks->einfo)
5646 (_("%P%F: --relax and -r may not be used together\n"));
5648 /* If we return early, we didn't change anything. */
5651 /* We'll do our thing when requested to relax the GOT section. */
5652 if (sec != frvfdpic_got_section (info))
5655 /* We can only relax when linking the main executable or a library
5656 that can't be dlopened. */
5657 if (! bfd_link_executable (info) && ! (info->flags & DF_STATIC_TLS))
5660 /* If there isn't a TLS section for this binary, we can't do
5661 anything about its TLS relocations (it probably doesn't have
5663 if (elf_hash_table (info)->tls_sec == NULL)
5666 memset (&gpinfo, 0, sizeof (gpinfo));
5667 memcpy (&gpinfo.g, frvfdpic_dynamic_got_plt_info (info), sizeof (gpinfo.g));
5669 /* Now look for opportunities to relax, adjusting the GOT usage
5671 htab_traverse (frvfdpic_relocs_info (info),
5672 _frvfdpic_relax_got_plt_entries,
5675 /* If we changed anything, reset and re-assign GOT and PLT entries. */
5676 if (memcmp (frvfdpic_dynamic_got_plt_info (info),
5677 &gpinfo.g, sizeof (gpinfo.g)) != 0)
5679 /* Clear GOT and PLT assignments. */
5680 htab_traverse (frvfdpic_relocs_info (info),
5681 _frvfdpic_reset_got_plt_entries,
5684 /* The owner of the TLS section is the output bfd. There should
5685 be a better way to get to it. */
5686 if (!_frvfdpic_size_got_plt (elf_hash_table (info)->tls_sec->owner,
5690 /* Repeat until we don't make any further changes. We could fail to
5691 introduce changes in a round if, for example, the 12-bit range is
5692 full, but we later release some space by getting rid of TLS
5693 descriptors in it. We have to repeat the whole process because
5694 we might have changed the size of a section processed before this
5702 /* Fill in code and data in dynamic sections. */
5705 elf32_frv_finish_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
5706 struct bfd_link_info *info ATTRIBUTE_UNUSED)
5708 /* Nothing to be done for non-FDPIC. */
5713 elf32_frvfdpic_finish_dynamic_sections (bfd *output_bfd,
5714 struct bfd_link_info *info)
5719 dynobj = elf_hash_table (info)->dynobj;
5721 if (frvfdpic_dynamic_got_plt_info (info))
5723 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs == 0);
5725 if (frvfdpic_got_section (info))
5727 BFD_ASSERT (frvfdpic_gotrel_section (info)->size
5728 == (frvfdpic_gotrel_section (info)->reloc_count
5729 * sizeof (Elf32_External_Rel)));
5731 if (frvfdpic_gotfixup_section (info))
5733 struct elf_link_hash_entry *hgot = elf_hash_table (info)->hgot;
5734 bfd_vma got_value = hgot->root.u.def.value
5735 + hgot->root.u.def.section->output_section->vma
5736 + hgot->root.u.def.section->output_offset;
5737 struct bfd_link_hash_entry *hend;
5739 _frvfdpic_add_rofixup (output_bfd, frvfdpic_gotfixup_section (info),
5742 if (frvfdpic_gotfixup_section (info)->size
5743 != (frvfdpic_gotfixup_section (info)->reloc_count * 4))
5746 info->callbacks->einfo
5747 ("LINKER BUG: .rofixup section size mismatch\n");
5751 hend = bfd_link_hash_lookup (info->hash, "__ROFIXUP_END__",
5752 FALSE, FALSE, TRUE);
5754 && (hend->type == bfd_link_hash_defined
5755 || hend->type == bfd_link_hash_defweak)
5756 && hend->u.def.section->output_section != NULL)
5759 frvfdpic_gotfixup_section (info)->output_section->vma
5760 + frvfdpic_gotfixup_section (info)->output_offset
5761 + frvfdpic_gotfixup_section (info)->size
5762 - hend->u.def.section->output_section->vma
5763 - hend->u.def.section->output_offset;
5764 BFD_ASSERT (hend->u.def.value == value);
5765 if (hend->u.def.value != value)
5770 if (frvfdpic_pltrel_section (info))
5772 BFD_ASSERT (frvfdpic_pltrel_section (info)->size
5773 == (frvfdpic_pltrel_section (info)->reloc_count
5774 * sizeof (Elf32_External_Rel)));
5778 if (elf_hash_table (info)->dynamic_sections_created)
5780 Elf32_External_Dyn * dyncon;
5781 Elf32_External_Dyn * dynconend;
5783 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
5785 BFD_ASSERT (sdyn != NULL);
5787 dyncon = (Elf32_External_Dyn *) sdyn->contents;
5788 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
5790 for (; dyncon < dynconend; dyncon++)
5792 Elf_Internal_Dyn dyn;
5794 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
5802 dyn.d_un.d_ptr = frvfdpic_got_section (info)->output_section->vma
5803 + frvfdpic_got_section (info)->output_offset
5804 + frvfdpic_got_initial_offset (info);
5805 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5809 dyn.d_un.d_ptr = frvfdpic_pltrel_section (info)
5810 ->output_section->vma
5811 + frvfdpic_pltrel_section (info)->output_offset;
5812 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5816 dyn.d_un.d_val = frvfdpic_pltrel_section (info)->size;
5817 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5826 /* Adjust a symbol defined by a dynamic object and referenced by a
5830 elf32_frvfdpic_adjust_dynamic_symbol
5831 (struct bfd_link_info *info ATTRIBUTE_UNUSED,
5832 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
5836 dynobj = elf_hash_table (info)->dynobj;
5838 /* Make sure we know what is going on here. */
5839 BFD_ASSERT (dynobj != NULL
5840 && (h->u.weakdef != NULL
5843 && !h->def_regular)));
5845 /* If this is a weak symbol, and there is a real definition, the
5846 processor independent code will have arranged for us to see the
5847 real definition first, and we can just use the same value. */
5848 if (h->u.weakdef != NULL)
5850 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
5851 || h->u.weakdef->root.type == bfd_link_hash_defweak);
5852 h->root.u.def.section = h->u.weakdef->root.u.def.section;
5853 h->root.u.def.value = h->u.weakdef->root.u.def.value;
5859 /* Perform any actions needed for dynamic symbols. */
5862 elf32_frvfdpic_finish_dynamic_symbol
5863 (bfd *output_bfd ATTRIBUTE_UNUSED,
5864 struct bfd_link_info *info ATTRIBUTE_UNUSED,
5865 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED,
5866 Elf_Internal_Sym *sym ATTRIBUTE_UNUSED)
5871 /* Decide whether to attempt to turn absptr or lsda encodings in
5872 shared libraries into pcrel within the given input section. */
5875 frvfdpic_elf_use_relative_eh_frame
5876 (bfd *input_bfd ATTRIBUTE_UNUSED,
5877 struct bfd_link_info *info ATTRIBUTE_UNUSED,
5878 asection *eh_frame_section ATTRIBUTE_UNUSED)
5880 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
5884 /* Adjust the contents of an eh_frame_hdr section before they're output. */
5887 frvfdpic_elf_encode_eh_address (bfd *abfd,
5888 struct bfd_link_info *info,
5889 asection *osec, bfd_vma offset,
5890 asection *loc_sec, bfd_vma loc_offset,
5893 struct elf_link_hash_entry *h;
5895 h = elf_hash_table (info)->hgot;
5896 BFD_ASSERT (h && h->root.type == bfd_link_hash_defined);
5898 if (! h || (_frvfdpic_osec_to_segment (abfd, osec)
5899 == _frvfdpic_osec_to_segment (abfd, loc_sec->output_section)))
5900 return _bfd_elf_encode_eh_address (abfd, info, osec, offset,
5901 loc_sec, loc_offset, encoded);
5903 BFD_ASSERT (_frvfdpic_osec_to_segment (abfd, osec)
5904 == (_frvfdpic_osec_to_segment
5905 (abfd, h->root.u.def.section->output_section)));
5907 *encoded = osec->vma + offset
5908 - (h->root.u.def.value
5909 + h->root.u.def.section->output_section->vma
5910 + h->root.u.def.section->output_offset);
5912 return DW_EH_PE_datarel | DW_EH_PE_sdata4;
5915 /* Look through the relocs for a section during the first phase.
5917 Besides handling virtual table relocs for gc, we have to deal with
5918 all sorts of PIC-related relocations. We describe below the
5919 general plan on how to handle such relocations, even though we only
5920 collect information at this point, storing them in hash tables for
5921 perusal of later passes.
5923 32 relocations are propagated to the linker output when creating
5924 position-independent output. LO16 and HI16 relocations are not
5925 supposed to be encountered in this case.
5927 LABEL16 should always be resolvable by the linker, since it's only
5930 LABEL24, on the other hand, is used by calls. If it turns out that
5931 the target of a call is a dynamic symbol, a PLT entry must be
5932 created for it, which triggers the creation of a private function
5933 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
5935 GPREL relocations require the referenced symbol to be in the same
5936 segment as _gp, but this can only be checked later.
5938 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
5939 exist. LABEL24 might as well, since it may require a PLT entry,
5940 that will require a got.
5942 Non-FUNCDESC GOT relocations require a GOT entry to be created
5943 regardless of whether the symbol is dynamic. However, since a
5944 global symbol that turns out to not be exported may have the same
5945 address of a non-dynamic symbol, we don't assign GOT entries at
5946 this point, such that we can share them in this case. A relocation
5947 for the GOT entry always has to be created, be it to offset a
5948 private symbol by the section load address, be it to get the symbol
5949 resolved dynamically.
5951 FUNCDESC GOT relocations require a GOT entry to be created, and
5952 handled as if a FUNCDESC relocation was applied to the GOT entry in
5955 FUNCDESC relocations referencing a symbol that turns out to NOT be
5956 dynamic cause a private function descriptor to be created. The
5957 FUNCDESC relocation then decays to a 32 relocation that points at
5958 the private descriptor. If the symbol is dynamic, the FUNCDESC
5959 relocation is propagated to the linker output, such that the
5960 dynamic linker creates the canonical descriptor, pointing to the
5961 dynamically-resolved definition of the function.
5963 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
5964 symbols that are assigned to the same segment as the GOT, but we
5965 can only check this later, after we know the complete set of
5966 symbols defined and/or exported.
5968 FUNCDESC GOTOFF relocations require a function descriptor to be
5969 created and, unless lazy binding is disabled or the symbol is not
5970 dynamic, a lazy PLT entry. Since we can't tell at this point
5971 whether a symbol is going to be dynamic, we have to decide later
5972 whether to create a lazy PLT entry or bind the descriptor directly
5973 to the private function.
5975 FUNCDESC_VALUE relocations are not supposed to be present in object
5976 files, but they may very well be simply propagated to the linker
5977 output, since they have no side effect.
5980 A function descriptor always requires a FUNCDESC_VALUE relocation.
5981 Whether it's in .plt.rel or not depends on whether lazy binding is
5982 enabled and on whether the referenced symbol is dynamic.
5984 The existence of a lazy PLT requires the resolverStub lazy PLT
5985 entry to be present.
5988 As for assignment of GOT, PLT and lazy PLT entries, and private
5989 descriptors, we might do them all sequentially, but we can do
5990 better than that. For example, we can place GOT entries and
5991 private function descriptors referenced using 12-bit operands
5992 closer to the PIC register value, such that these relocations don't
5993 overflow. Those that are only referenced with LO16 relocations
5994 could come next, but we may as well place PLT-required function
5995 descriptors in the 12-bit range to make them shorter. Symbols
5996 referenced with LO16/HI16 may come next, but we may place
5997 additional function descriptors in the 16-bit range if we can
5998 reliably tell that we've already placed entries that are ever
5999 referenced with only LO16. PLT entries are therefore generated as
6000 small as possible, while not introducing relocation overflows in
6001 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
6002 generated before or after PLT entries, but not intermingled with
6003 them, such that we can have more lazy PLT entries in range for a
6004 branch to the resolverStub. The resolverStub should be emitted at
6005 the most distant location from the first lazy PLT entry such that
6006 it's still in range for a branch, or closer, if there isn't a need
6007 for so many lazy PLT entries. Additional lazy PLT entries may be
6008 emitted after the resolverStub, as long as branches are still in
6009 range. If the branch goes out of range, longer lazy PLT entries
6012 We could further optimize PLT and lazy PLT entries by giving them
6013 priority in assignment to closer-to-gr17 locations depending on the
6014 number of occurrences of references to them (assuming a function
6015 that's called more often is more important for performance, so its
6016 PLT entry should be faster), or taking hints from the compiler.
6017 Given infinite time and money... :-) */
6020 elf32_frv_check_relocs (bfd *abfd,
6021 struct bfd_link_info *info,
6023 const Elf_Internal_Rela *relocs)
6025 Elf_Internal_Shdr *symtab_hdr;
6026 struct elf_link_hash_entry **sym_hashes;
6027 const Elf_Internal_Rela *rel;
6028 const Elf_Internal_Rela *rel_end;
6030 struct frvfdpic_relocs_info *picrel;
6032 if (bfd_link_relocatable (info))
6035 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
6036 sym_hashes = elf_sym_hashes (abfd);
6038 dynobj = elf_hash_table (info)->dynobj;
6039 rel_end = relocs + sec->reloc_count;
6040 for (rel = relocs; rel < rel_end; rel++)
6042 struct elf_link_hash_entry *h;
6043 unsigned long r_symndx;
6045 r_symndx = ELF32_R_SYM (rel->r_info);
6046 if (r_symndx < symtab_hdr->sh_info)
6050 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6051 while (h->root.type == bfd_link_hash_indirect
6052 || h->root.type == bfd_link_hash_warning)
6053 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6055 /* PR15323, ref flags aren't set for references in the same
6057 h->root.non_ir_ref = 1;
6060 switch (ELF32_R_TYPE (rel->r_info))
6062 case R_FRV_GETTLSOFF:
6063 case R_FRV_TLSDESC_VALUE:
6064 case R_FRV_GOTTLSDESC12:
6065 case R_FRV_GOTTLSDESCHI:
6066 case R_FRV_GOTTLSDESCLO:
6067 case R_FRV_GOTTLSOFF12:
6068 case R_FRV_GOTTLSOFFHI:
6069 case R_FRV_GOTTLSOFFLO:
6074 case R_FRV_FUNCDESC_GOT12:
6075 case R_FRV_FUNCDESC_GOTHI:
6076 case R_FRV_FUNCDESC_GOTLO:
6077 case R_FRV_GOTOFF12:
6078 case R_FRV_GOTOFFHI:
6079 case R_FRV_GOTOFFLO:
6080 case R_FRV_FUNCDESC_GOTOFF12:
6081 case R_FRV_FUNCDESC_GOTOFFHI:
6082 case R_FRV_FUNCDESC_GOTOFFLO:
6083 case R_FRV_FUNCDESC:
6084 case R_FRV_FUNCDESC_VALUE:
6085 case R_FRV_TLSMOFF12:
6086 case R_FRV_TLSMOFFHI:
6087 case R_FRV_TLSMOFFLO:
6089 if (! IS_FDPIC (abfd))
6093 case R_FRV_GPRELU12:
6100 elf_hash_table (info)->dynobj = dynobj = abfd;
6101 if (! _frv_create_got_section (abfd, info))
6104 if (! IS_FDPIC (abfd))
6111 if (h->dynindx == -1)
6112 switch (ELF_ST_VISIBILITY (h->other))
6118 bfd_elf_link_record_dynamic_symbol (info, h);
6122 = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info),
6124 rel->r_addend, INSERT);
6127 picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
6128 (info), abfd, r_symndx,
6129 rel->r_addend, INSERT);
6139 switch (ELF32_R_TYPE (rel->r_info))
6142 if (IS_FDPIC (abfd))
6146 case R_FRV_FUNCDESC_VALUE:
6147 picrel->relocsfdv++;
6148 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
6153 if (! IS_FDPIC (abfd))
6157 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
6167 picrel->gothilo = 1;
6170 case R_FRV_FUNCDESC_GOT12:
6171 picrel->fdgot12 = 1;
6174 case R_FRV_FUNCDESC_GOTHI:
6175 case R_FRV_FUNCDESC_GOTLO:
6176 picrel->fdgothilo = 1;
6179 case R_FRV_GOTOFF12:
6180 case R_FRV_GOTOFFHI:
6181 case R_FRV_GOTOFFLO:
6185 case R_FRV_FUNCDESC_GOTOFF12:
6186 picrel->fdgoff12 = 1;
6189 case R_FRV_FUNCDESC_GOTOFFHI:
6190 case R_FRV_FUNCDESC_GOTOFFLO:
6191 picrel->fdgoffhilo = 1;
6194 case R_FRV_FUNCDESC:
6199 case R_FRV_GETTLSOFF:
6203 case R_FRV_TLSDESC_VALUE:
6204 picrel->relocstlsd++;
6207 case R_FRV_GOTTLSDESC12:
6208 picrel->tlsdesc12 = 1;
6211 case R_FRV_GOTTLSDESCHI:
6212 case R_FRV_GOTTLSDESCLO:
6213 picrel->tlsdeschilo = 1;
6216 case R_FRV_TLSMOFF12:
6217 case R_FRV_TLSMOFFHI:
6218 case R_FRV_TLSMOFFLO:
6222 case R_FRV_GOTTLSOFF12:
6223 picrel->tlsoff12 = 1;
6224 info->flags |= DF_STATIC_TLS;
6227 case R_FRV_GOTTLSOFFHI:
6228 case R_FRV_GOTTLSOFFLO:
6229 picrel->tlsoffhilo = 1;
6230 info->flags |= DF_STATIC_TLS;
6234 picrel->relocstlsoff++;
6235 info->flags |= DF_STATIC_TLS;
6238 /* This relocation describes the C++ object vtable hierarchy.
6239 Reconstruct it for later use during GC. */
6240 case R_FRV_GNU_VTINHERIT:
6241 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
6245 /* This relocation describes which C++ vtable entries are actually
6246 used. Record for later use during GC. */
6247 case R_FRV_GNU_VTENTRY:
6248 BFD_ASSERT (h != NULL);
6250 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
6258 case R_FRV_GPRELU12:
6262 case R_FRV_TLSDESC_RELAX:
6263 case R_FRV_GETTLSOFF_RELAX:
6264 case R_FRV_TLSOFF_RELAX:
6269 info->callbacks->einfo
6270 (_("%B: unsupported relocation type %i\n"),
6271 abfd, ELF32_R_TYPE (rel->r_info));
6280 /* Return the machine subcode from the ELF e_flags header. */
6283 elf32_frv_machine (bfd *abfd)
6285 switch (elf_elfheader (abfd)->e_flags & EF_FRV_CPU_MASK)
6288 case EF_FRV_CPU_FR550: return bfd_mach_fr550;
6289 case EF_FRV_CPU_FR500: return bfd_mach_fr500;
6290 case EF_FRV_CPU_FR450: return bfd_mach_fr450;
6291 case EF_FRV_CPU_FR405: return bfd_mach_fr400;
6292 case EF_FRV_CPU_FR400: return bfd_mach_fr400;
6293 case EF_FRV_CPU_FR300: return bfd_mach_fr300;
6294 case EF_FRV_CPU_SIMPLE: return bfd_mach_frvsimple;
6295 case EF_FRV_CPU_TOMCAT: return bfd_mach_frvtomcat;
6298 return bfd_mach_frv;
6301 /* Set the right machine number for a FRV ELF file. */
6304 elf32_frv_object_p (bfd *abfd)
6306 bfd_default_set_arch_mach (abfd, bfd_arch_frv, elf32_frv_machine (abfd));
6307 return (((elf_elfheader (abfd)->e_flags & EF_FRV_FDPIC) != 0)
6308 == (IS_FDPIC (abfd)));
6311 /* Function to set the ELF flag bits. */
6314 frv_elf_set_private_flags (bfd *abfd, flagword flags)
6316 elf_elfheader (abfd)->e_flags = flags;
6317 elf_flags_init (abfd) = TRUE;
6321 /* Return true if the architecture described by elf header flag
6322 EXTENSION is an extension of the architecture described by BASE. */
6325 frv_elf_arch_extension_p (flagword base, flagword extension)
6327 if (base == extension)
6330 /* CPU_GENERIC code can be merged with code for a specific
6331 architecture, in which case the result is marked as being
6332 for the specific architecture. Everything is therefore
6333 an extension of CPU_GENERIC. */
6334 if (base == EF_FRV_CPU_GENERIC)
6337 if (extension == EF_FRV_CPU_FR450)
6338 if (base == EF_FRV_CPU_FR400 || base == EF_FRV_CPU_FR405)
6341 if (extension == EF_FRV_CPU_FR405)
6342 if (base == EF_FRV_CPU_FR400)
6348 /* Merge backend specific data from an object file to the output
6349 object file when linking. */
6352 frv_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
6354 flagword old_flags, old_partial;
6355 flagword new_flags, new_partial;
6356 bfd_boolean error = FALSE;
6360 new_opt[0] = old_opt[0] = '\0';
6361 new_flags = elf_elfheader (ibfd)->e_flags;
6362 old_flags = elf_elfheader (obfd)->e_flags;
6364 if (new_flags & EF_FRV_FDPIC)
6365 new_flags &= ~EF_FRV_PIC;
6369 ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s",
6370 old_flags, new_flags, elf_flags_init (obfd) ? "yes" : "no",
6371 bfd_get_filename (ibfd));
6374 if (!elf_flags_init (obfd)) /* First call, no flags set. */
6376 elf_flags_init (obfd) = TRUE;
6377 old_flags = new_flags;
6380 else if (new_flags == old_flags) /* Compatible flags are ok. */
6383 else /* Possibly incompatible flags. */
6385 /* Warn if different # of gprs are used. Note, 0 means nothing is
6386 said about the size of gprs. */
6387 new_partial = (new_flags & EF_FRV_GPR_MASK);
6388 old_partial = (old_flags & EF_FRV_GPR_MASK);
6389 if (new_partial == old_partial)
6392 else if (new_partial == 0)
6395 else if (old_partial == 0)
6396 old_flags |= new_partial;
6400 switch (new_partial)
6402 default: strcat (new_opt, " -mgpr-??"); break;
6403 case EF_FRV_GPR_32: strcat (new_opt, " -mgpr-32"); break;
6404 case EF_FRV_GPR_64: strcat (new_opt, " -mgpr-64"); break;
6407 switch (old_partial)
6409 default: strcat (old_opt, " -mgpr-??"); break;
6410 case EF_FRV_GPR_32: strcat (old_opt, " -mgpr-32"); break;
6411 case EF_FRV_GPR_64: strcat (old_opt, " -mgpr-64"); break;
6415 /* Warn if different # of fprs are used. Note, 0 means nothing is
6416 said about the size of fprs. */
6417 new_partial = (new_flags & EF_FRV_FPR_MASK);
6418 old_partial = (old_flags & EF_FRV_FPR_MASK);
6419 if (new_partial == old_partial)
6422 else if (new_partial == 0)
6425 else if (old_partial == 0)
6426 old_flags |= new_partial;
6430 switch (new_partial)
6432 default: strcat (new_opt, " -mfpr-?"); break;
6433 case EF_FRV_FPR_32: strcat (new_opt, " -mfpr-32"); break;
6434 case EF_FRV_FPR_64: strcat (new_opt, " -mfpr-64"); break;
6435 case EF_FRV_FPR_NONE: strcat (new_opt, " -msoft-float"); break;
6438 switch (old_partial)
6440 default: strcat (old_opt, " -mfpr-?"); break;
6441 case EF_FRV_FPR_32: strcat (old_opt, " -mfpr-32"); break;
6442 case EF_FRV_FPR_64: strcat (old_opt, " -mfpr-64"); break;
6443 case EF_FRV_FPR_NONE: strcat (old_opt, " -msoft-float"); break;
6447 /* Warn if different dword support was used. Note, 0 means nothing is
6448 said about the dword support. */
6449 new_partial = (new_flags & EF_FRV_DWORD_MASK);
6450 old_partial = (old_flags & EF_FRV_DWORD_MASK);
6451 if (new_partial == old_partial)
6454 else if (new_partial == 0)
6457 else if (old_partial == 0)
6458 old_flags |= new_partial;
6462 switch (new_partial)
6464 default: strcat (new_opt, " -mdword-?"); break;
6465 case EF_FRV_DWORD_YES: strcat (new_opt, " -mdword"); break;
6466 case EF_FRV_DWORD_NO: strcat (new_opt, " -mno-dword"); break;
6469 switch (old_partial)
6471 default: strcat (old_opt, " -mdword-?"); break;
6472 case EF_FRV_DWORD_YES: strcat (old_opt, " -mdword"); break;
6473 case EF_FRV_DWORD_NO: strcat (old_opt, " -mno-dword"); break;
6477 /* Or in flags that accumulate (ie, if one module uses it, mark that the
6479 old_flags |= new_flags & (EF_FRV_DOUBLE
6482 | EF_FRV_NON_PIC_RELOCS);
6484 /* If any module was compiled without -G0, clear the G0 bit. */
6485 old_flags = ((old_flags & ~ EF_FRV_G0)
6486 | (old_flags & new_flags & EF_FRV_G0));
6488 /* If any module was compiled without -mnopack, clear the mnopack bit. */
6489 old_flags = ((old_flags & ~ EF_FRV_NOPACK)
6490 | (old_flags & new_flags & EF_FRV_NOPACK));
6492 /* We don't have to do anything if the pic flags are the same, or the new
6493 module(s) were compiled with -mlibrary-pic. */
6494 new_partial = (new_flags & EF_FRV_PIC_FLAGS);
6495 old_partial = (old_flags & EF_FRV_PIC_FLAGS);
6496 if ((new_partial == old_partial) || ((new_partial & EF_FRV_LIBPIC) != 0))
6499 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
6500 flags if any from the new module. */
6501 else if ((old_partial & EF_FRV_LIBPIC) != 0)
6502 old_flags = (old_flags & ~ EF_FRV_PIC_FLAGS) | new_partial;
6504 /* If we have mixtures of -fpic and -fPIC, or in both bits. */
6505 else if (new_partial != 0 && old_partial != 0)
6506 old_flags |= new_partial;
6508 /* One module was compiled for pic and the other was not, see if we have
6509 had any relocations that are not pic-safe. */
6512 if ((old_flags & EF_FRV_NON_PIC_RELOCS) == 0)
6513 old_flags |= new_partial;
6516 old_flags &= ~ EF_FRV_PIC_FLAGS;
6517 #ifndef FRV_NO_PIC_ERROR
6520 (_("%s: compiled with %s and linked with modules that use non-pic relocations"),
6521 bfd_get_filename (ibfd),
6522 (new_flags & EF_FRV_BIGPIC) ? "-fPIC" : "-fpic");
6527 /* Warn if different cpu is used (allow a specific cpu to override
6528 the generic cpu). */
6529 new_partial = (new_flags & EF_FRV_CPU_MASK);
6530 old_partial = (old_flags & EF_FRV_CPU_MASK);
6531 if (frv_elf_arch_extension_p (new_partial, old_partial))
6534 else if (frv_elf_arch_extension_p (old_partial, new_partial))
6535 old_flags = (old_flags & ~EF_FRV_CPU_MASK) | new_partial;
6539 switch (new_partial)
6541 default: strcat (new_opt, " -mcpu=?"); break;
6542 case EF_FRV_CPU_GENERIC: strcat (new_opt, " -mcpu=frv"); break;
6543 case EF_FRV_CPU_SIMPLE: strcat (new_opt, " -mcpu=simple"); break;
6544 case EF_FRV_CPU_FR550: strcat (new_opt, " -mcpu=fr550"); break;
6545 case EF_FRV_CPU_FR500: strcat (new_opt, " -mcpu=fr500"); break;
6546 case EF_FRV_CPU_FR450: strcat (new_opt, " -mcpu=fr450"); break;
6547 case EF_FRV_CPU_FR405: strcat (new_opt, " -mcpu=fr405"); break;
6548 case EF_FRV_CPU_FR400: strcat (new_opt, " -mcpu=fr400"); break;
6549 case EF_FRV_CPU_FR300: strcat (new_opt, " -mcpu=fr300"); break;
6550 case EF_FRV_CPU_TOMCAT: strcat (new_opt, " -mcpu=tomcat"); break;
6553 switch (old_partial)
6555 default: strcat (old_opt, " -mcpu=?"); break;
6556 case EF_FRV_CPU_GENERIC: strcat (old_opt, " -mcpu=frv"); break;
6557 case EF_FRV_CPU_SIMPLE: strcat (old_opt, " -mcpu=simple"); break;
6558 case EF_FRV_CPU_FR550: strcat (old_opt, " -mcpu=fr550"); break;
6559 case EF_FRV_CPU_FR500: strcat (old_opt, " -mcpu=fr500"); break;
6560 case EF_FRV_CPU_FR450: strcat (old_opt, " -mcpu=fr450"); break;
6561 case EF_FRV_CPU_FR405: strcat (old_opt, " -mcpu=fr405"); break;
6562 case EF_FRV_CPU_FR400: strcat (old_opt, " -mcpu=fr400"); break;
6563 case EF_FRV_CPU_FR300: strcat (old_opt, " -mcpu=fr300"); break;
6564 case EF_FRV_CPU_TOMCAT: strcat (old_opt, " -mcpu=tomcat"); break;
6568 /* Print out any mismatches from above. */
6573 (_("%s: compiled with %s and linked with modules compiled with %s"),
6574 bfd_get_filename (ibfd), new_opt, old_opt);
6577 /* Warn about any other mismatches */
6578 new_partial = (new_flags & ~ EF_FRV_ALL_FLAGS);
6579 old_partial = (old_flags & ~ EF_FRV_ALL_FLAGS);
6580 if (new_partial != old_partial)
6582 old_flags |= new_partial;
6585 (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"),
6586 bfd_get_filename (ibfd), (long)new_partial, (long)old_partial);
6590 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
6591 if ((old_flags & EF_FRV_CPU_MASK) == EF_FRV_CPU_SIMPLE)
6592 old_flags |= EF_FRV_NOPACK;
6594 /* Update the old flags now with changes made above. */
6595 old_partial = elf_elfheader (obfd)->e_flags & EF_FRV_CPU_MASK;
6596 elf_elfheader (obfd)->e_flags = old_flags;
6597 if (old_partial != (old_flags & EF_FRV_CPU_MASK))
6598 bfd_default_set_arch_mach (obfd, bfd_arch_frv, elf32_frv_machine (obfd));
6600 if (((new_flags & EF_FRV_FDPIC) == 0)
6601 != (! IS_FDPIC (ibfd)))
6604 if (IS_FDPIC (obfd))
6606 (_("%s: cannot link non-fdpic object file into fdpic executable"),
6607 bfd_get_filename (ibfd));
6610 (_("%s: cannot link fdpic object file into non-fdpic executable"),
6611 bfd_get_filename (ibfd));
6615 bfd_set_error (bfd_error_bad_value);
6622 frv_elf_print_private_bfd_data (bfd *abfd, void * ptr)
6624 FILE *file = (FILE *) ptr;
6627 BFD_ASSERT (abfd != NULL && ptr != NULL);
6629 /* Print normal ELF private data. */
6630 _bfd_elf_print_private_bfd_data (abfd, ptr);
6632 flags = elf_elfheader (abfd)->e_flags;
6633 fprintf (file, _("private flags = 0x%lx:"), (unsigned long) flags);
6635 switch (flags & EF_FRV_CPU_MASK)
6638 case EF_FRV_CPU_SIMPLE: fprintf (file, " -mcpu=simple"); break;
6639 case EF_FRV_CPU_FR550: fprintf (file, " -mcpu=fr550"); break;
6640 case EF_FRV_CPU_FR500: fprintf (file, " -mcpu=fr500"); break;
6641 case EF_FRV_CPU_FR450: fprintf (file, " -mcpu=fr450"); break;
6642 case EF_FRV_CPU_FR405: fprintf (file, " -mcpu=fr405"); break;
6643 case EF_FRV_CPU_FR400: fprintf (file, " -mcpu=fr400"); break;
6644 case EF_FRV_CPU_FR300: fprintf (file, " -mcpu=fr300"); break;
6645 case EF_FRV_CPU_TOMCAT: fprintf (file, " -mcpu=tomcat"); break;
6648 switch (flags & EF_FRV_GPR_MASK)
6651 case EF_FRV_GPR_32: fprintf (file, " -mgpr-32"); break;
6652 case EF_FRV_GPR_64: fprintf (file, " -mgpr-64"); break;
6655 switch (flags & EF_FRV_FPR_MASK)
6658 case EF_FRV_FPR_32: fprintf (file, " -mfpr-32"); break;
6659 case EF_FRV_FPR_64: fprintf (file, " -mfpr-64"); break;
6660 case EF_FRV_FPR_NONE: fprintf (file, " -msoft-float"); break;
6663 switch (flags & EF_FRV_DWORD_MASK)
6666 case EF_FRV_DWORD_YES: fprintf (file, " -mdword"); break;
6667 case EF_FRV_DWORD_NO: fprintf (file, " -mno-dword"); break;
6670 if (flags & EF_FRV_DOUBLE)
6671 fprintf (file, " -mdouble");
6673 if (flags & EF_FRV_MEDIA)
6674 fprintf (file, " -mmedia");
6676 if (flags & EF_FRV_MULADD)
6677 fprintf (file, " -mmuladd");
6679 if (flags & EF_FRV_PIC)
6680 fprintf (file, " -fpic");
6682 if (flags & EF_FRV_BIGPIC)
6683 fprintf (file, " -fPIC");
6685 if (flags & EF_FRV_LIBPIC)
6686 fprintf (file, " -mlibrary-pic");
6688 if (flags & EF_FRV_FDPIC)
6689 fprintf (file, " -mfdpic");
6691 if (flags & EF_FRV_NON_PIC_RELOCS)
6692 fprintf (file, " non-pic relocations");
6694 if (flags & EF_FRV_G0)
6695 fprintf (file, " -G0");
6702 /* Support for core dump NOTE sections. */
6705 elf32_frv_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
6708 unsigned int raw_size;
6710 switch (note->descsz)
6715 /* The Linux/FRV elf_prstatus struct is 268 bytes long. The other
6716 hardcoded offsets and sizes listed below (and contained within
6717 this lexical block) refer to fields in the target's elf_prstatus
6720 /* `pr_cursig' is at offset 12. */
6721 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
6723 /* `pr_pid' is at offset 24. */
6724 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
6726 /* `pr_reg' is at offset 72. */
6729 /* Most grok_prstatus implementations set `raw_size' to the size
6730 of the pr_reg field. For Linux/FRV, we set `raw_size' to be
6731 the size of `pr_reg' plus the size of `pr_exec_fdpic_loadmap'
6732 and `pr_interp_fdpic_loadmap', both of which (by design)
6733 immediately follow `pr_reg'. This will allow these fields to
6734 be viewed by GDB as registers.
6736 `pr_reg' is 184 bytes long. `pr_exec_fdpic_loadmap' and
6737 `pr_interp_fdpic_loadmap' are 4 bytes each. */
6738 raw_size = 184 + 4 + 4;
6743 /* Make a ".reg/999" section. */
6744 return _bfd_elfcore_make_pseudosection (abfd, ".reg", raw_size,
6745 note->descpos + offset);
6749 elf32_frv_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
6751 switch (note->descsz)
6756 /* The Linux/FRV elf_prpsinfo struct is 124 bytes long. */
6759 /* `pr_fname' is found at offset 28 and is 16 bytes long. */
6760 elf_tdata (abfd)->core->program
6761 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
6763 /* `pr_psargs' is found at offset 44 and is 80 bytes long. */
6764 elf_tdata (abfd)->core->command
6765 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
6768 /* Note that for some reason, a spurious space is tacked
6769 onto the end of the args in some (at least one anyway)
6770 implementations, so strip it off if it exists. */
6773 char *command = elf_tdata (abfd)->core->command;
6774 int n = strlen (command);
6776 if (0 < n && command[n - 1] == ' ')
6777 command[n - 1] = '\0';
6782 #define ELF_ARCH bfd_arch_frv
6783 #define ELF_TARGET_ID FRV_ELF_DATA
6784 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
6785 #define ELF_MAXPAGESIZE 0x1000
6787 #define TARGET_BIG_SYM frv_elf32_vec
6788 #define TARGET_BIG_NAME "elf32-frv"
6790 #define elf_info_to_howto frv_info_to_howto_rela
6791 #define elf_backend_relocate_section elf32_frv_relocate_section
6792 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
6793 #define elf_backend_check_relocs elf32_frv_check_relocs
6794 #define elf_backend_object_p elf32_frv_object_p
6795 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
6797 #define elf_backend_stack_align 8
6798 #define elf_backend_can_gc_sections 1
6799 #define elf_backend_rela_normal 1
6801 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
6802 #define bfd_elf32_bfd_reloc_name_lookup frv_reloc_name_lookup
6803 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
6804 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
6805 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
6807 #define elf_backend_want_got_sym 1
6808 #define elf_backend_got_header_size 0
6809 #define elf_backend_want_got_plt 0
6810 #define elf_backend_plt_readonly 1
6811 #define elf_backend_want_plt_sym 0
6812 #define elf_backend_plt_header_size 0
6814 #define elf_backend_finish_dynamic_sections \
6815 elf32_frv_finish_dynamic_sections
6817 #define elf_backend_grok_prstatus elf32_frv_grok_prstatus
6818 #define elf_backend_grok_psinfo elf32_frv_grok_psinfo
6820 #include "elf32-target.h"
6822 #undef ELF_MAXPAGESIZE
6823 #define ELF_MAXPAGESIZE 0x4000
6825 #undef TARGET_BIG_SYM
6826 #define TARGET_BIG_SYM frv_elf32_fdpic_vec
6827 #undef TARGET_BIG_NAME
6828 #define TARGET_BIG_NAME "elf32-frvfdpic"
6830 #define elf32_bed elf32_frvfdpic_bed
6832 #undef elf_info_to_howto_rel
6833 #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel
6835 #undef bfd_elf32_bfd_link_hash_table_create
6836 #define bfd_elf32_bfd_link_hash_table_create \
6837 frvfdpic_elf_link_hash_table_create
6838 #undef elf_backend_always_size_sections
6839 #define elf_backend_always_size_sections \
6840 elf32_frvfdpic_always_size_sections
6842 #undef elf_backend_create_dynamic_sections
6843 #define elf_backend_create_dynamic_sections \
6844 elf32_frvfdpic_create_dynamic_sections
6845 #undef elf_backend_adjust_dynamic_symbol
6846 #define elf_backend_adjust_dynamic_symbol \
6847 elf32_frvfdpic_adjust_dynamic_symbol
6848 #undef elf_backend_size_dynamic_sections
6849 #define elf_backend_size_dynamic_sections \
6850 elf32_frvfdpic_size_dynamic_sections
6851 #undef bfd_elf32_bfd_relax_section
6852 #define bfd_elf32_bfd_relax_section \
6853 elf32_frvfdpic_relax_section
6854 #undef elf_backend_finish_dynamic_symbol
6855 #define elf_backend_finish_dynamic_symbol \
6856 elf32_frvfdpic_finish_dynamic_symbol
6857 #undef elf_backend_finish_dynamic_sections
6858 #define elf_backend_finish_dynamic_sections \
6859 elf32_frvfdpic_finish_dynamic_sections
6861 #undef elf_backend_discard_info
6862 #define elf_backend_discard_info \
6863 frvfdpic_elf_discard_info
6864 #undef elf_backend_can_make_relative_eh_frame
6865 #define elf_backend_can_make_relative_eh_frame \
6866 frvfdpic_elf_use_relative_eh_frame
6867 #undef elf_backend_can_make_lsda_relative_eh_frame
6868 #define elf_backend_can_make_lsda_relative_eh_frame \
6869 frvfdpic_elf_use_relative_eh_frame
6870 #undef elf_backend_encode_eh_address
6871 #define elf_backend_encode_eh_address \
6872 frvfdpic_elf_encode_eh_address
6874 #undef elf_backend_may_use_rel_p
6875 #define elf_backend_may_use_rel_p 1
6876 #undef elf_backend_may_use_rela_p
6877 #define elf_backend_may_use_rela_p 1
6878 /* We use REL for dynamic relocations only. */
6879 #undef elf_backend_default_use_rela_p
6880 #define elf_backend_default_use_rela_p 1
6882 #undef elf_backend_omit_section_dynsym
6883 #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym
6885 #include "elf32-target.h"