1 /* FRV-specific support for 32-bit ELF.
2 Copyright (C) 2002-2017 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 .rofixup section. */
810 /* GOT base offset. */
812 /* Location of the first non-lazy PLT entry, i.e., the number of
813 bytes taken by lazy PLT entries. If locally-bound TLS
814 descriptors require a ret instruction, it will be placed at this
817 /* A hash table holding information about which symbols were
818 referenced with which PIC-related relocations. */
819 struct htab
*relocs_info
;
820 /* Summary reloc information collected by
821 _frvfdpic_count_got_plt_entries. */
822 struct _frvfdpic_dynamic_got_info
*g
;
825 /* Get the FRV ELF linker hash table from a link_info structure. */
827 #define frvfdpic_hash_table(p) \
828 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
829 == FRV_ELF_DATA ? ((struct frvfdpic_elf_link_hash_table *) ((p)->hash)) : NULL)
831 #define frvfdpic_got_section(info) \
832 (frvfdpic_hash_table (info)->elf.sgot)
833 #define frvfdpic_gotrel_section(info) \
834 (frvfdpic_hash_table (info)->elf.srelgot)
835 #define frvfdpic_gotfixup_section(info) \
836 (frvfdpic_hash_table (info)->sgotfixup)
837 #define frvfdpic_plt_section(info) \
838 (frvfdpic_hash_table (info)->elf.splt)
839 #define frvfdpic_pltrel_section(info) \
840 (frvfdpic_hash_table (info)->elf.srelplt)
841 #define frvfdpic_relocs_info(info) \
842 (frvfdpic_hash_table (info)->relocs_info)
843 #define frvfdpic_got_initial_offset(info) \
844 (frvfdpic_hash_table (info)->got0)
845 #define frvfdpic_plt_initial_offset(info) \
846 (frvfdpic_hash_table (info)->plt0)
847 #define frvfdpic_dynamic_got_plt_info(info) \
848 (frvfdpic_hash_table (info)->g)
850 /* Currently it's the same, but if some day we have a reason to change
851 it, we'd better be using a different macro.
853 FIXME: if there's any TLS PLT entry that uses local-exec or
854 initial-exec models, we could use the ret at the end of any of them
855 instead of adding one more. */
856 #define frvfdpic_plt_tls_ret_offset(info) \
857 (frvfdpic_plt_initial_offset (info))
859 /* The name of the dynamic interpreter. This is put in the .interp
862 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
864 #define DEFAULT_STACK_SIZE 0x20000
866 /* This structure is used to collect the number of entries present in
867 each addressable range of the got. */
868 struct _frvfdpic_dynamic_got_info
870 /* Several bits of information about the current link. */
871 struct bfd_link_info
*info
;
872 /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit
874 bfd_vma got12
, gotlos
, gothilo
;
875 /* Total GOT size needed for function descriptor entries within the 12-,
876 16- or 32-bit ranges. */
877 bfd_vma fd12
, fdlos
, fdhilo
;
878 /* Total GOT size needed by function descriptor entries referenced
879 in PLT entries, that would be profitable to place in offsets
880 close to the PIC register. */
882 /* Total PLT size needed by lazy PLT entries. */
884 /* Total GOT size needed for TLS descriptor entries within the 12-,
885 16- or 32-bit ranges. */
886 bfd_vma tlsd12
, tlsdlos
, tlsdhilo
;
887 /* Total GOT size needed by TLS descriptors referenced in PLT
888 entries, that would be profitable to place in offers close to the
891 /* Total PLT size needed by TLS lazy PLT entries. */
893 /* Number of relocations carried over from input object files. */
894 unsigned long relocs
;
895 /* Number of fixups introduced by relocations in input object files. */
896 unsigned long fixups
;
897 /* The number of fixups that reference the ret instruction added to
898 the PLT for locally-resolved TLS descriptors. */
899 unsigned long tls_ret_refs
;
902 /* This structure is used to assign offsets to got entries, function
903 descriptors, plt entries and lazy plt entries. */
905 struct _frvfdpic_dynamic_got_plt_info
907 /* Summary information collected with _frvfdpic_count_got_plt_entries. */
908 struct _frvfdpic_dynamic_got_info g
;
910 /* For each addressable range, we record a MAX (positive) and MIN
911 (negative) value. CUR is used to assign got entries, and it's
912 incremented from an initial positive value to MAX, then from MIN
913 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
914 assign function descriptors, and it's decreased from an initial
915 non-positive value to MIN, then from MAX down to CUR (unless CUR
916 wraps around first). All of MIN, MAX, CUR and FDCUR always point
917 to even words. ODD, if non-zero, indicates an odd word to be
918 used for the next got entry, otherwise CUR is used and
919 incremented by a pair of words, wrapping around when it reaches
920 MAX. FDCUR is decremented (and wrapped) before the next function
921 descriptor is chosen. FDPLT indicates the number of remaining
922 slots that can be used for function descriptors used only by PLT
925 TMAX, TMIN and TCUR are used to assign TLS descriptors. TCUR
926 starts as MAX, and grows up to TMAX, then wraps around to TMIN
927 and grows up to MIN. TLSDPLT indicates the number of remaining
928 slots that can be used for TLS descriptors used only by TLS PLT
930 struct _frvfdpic_dynamic_got_alloc_data
932 bfd_signed_vma max
, cur
, odd
, fdcur
, min
;
933 bfd_signed_vma tmax
, tcur
, tmin
;
934 bfd_vma fdplt
, tlsdplt
;
935 } got12
, gotlos
, gothilo
;
938 /* Create an FRV ELF linker hash table. */
940 static struct bfd_link_hash_table
*
941 frvfdpic_elf_link_hash_table_create (bfd
*abfd
)
943 struct frvfdpic_elf_link_hash_table
*ret
;
944 bfd_size_type amt
= sizeof (struct frvfdpic_elf_link_hash_table
);
946 ret
= bfd_zmalloc (amt
);
950 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
951 _bfd_elf_link_hash_newfunc
,
952 sizeof (struct elf_link_hash_entry
),
959 return &ret
->elf
.root
;
962 /* Decide whether a reference to a symbol can be resolved locally or
963 not. If the symbol is protected, we want the local address, but
964 its function descriptor must be assigned by the dynamic linker. */
965 #define FRVFDPIC_SYM_LOCAL(INFO, H) \
966 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
967 || ! elf_hash_table (INFO)->dynamic_sections_created)
968 #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \
969 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
971 /* This structure collects information on what kind of GOT, PLT or
972 function descriptors are required by relocations that reference a
974 struct frvfdpic_relocs_info
976 /* The index of the symbol, as stored in the relocation r_info, if
977 we have a local symbol; -1 otherwise. */
981 /* The input bfd in which the symbol is defined, if it's a local
984 /* If symndx == -1, the hash table entry corresponding to a global
985 symbol (even if it turns out to bind locally, in which case it
986 should ideally be replaced with section's symndx + addend). */
987 struct elf_link_hash_entry
*h
;
989 /* The addend of the relocation that references the symbol. */
992 /* The fields above are used to identify an entry. The fields below
993 contain information on how an entry is used and, later on, which
994 locations it was assigned. */
995 /* The following 3 fields record whether the symbol+addend above was
996 ever referenced with a GOT relocation. The 12 suffix indicates a
997 GOT12 relocation; los is used for GOTLO relocations that are not
998 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
1003 /* Whether a FUNCDESC relocation references symbol+addend. */
1005 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
1007 unsigned fdgotlos
:1;
1008 unsigned fdgothilo
:1;
1009 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
1010 unsigned fdgoff12
:1;
1011 unsigned fdgofflos
:1;
1012 unsigned fdgoffhilo
:1;
1013 /* Whether a GETTLSOFF relocation references symbol+addend. */
1015 /* FIXME: we should probably add tlspltdesc, tlspltoff and
1016 tlspltimm, to tell what kind of TLS PLT entry we're generating.
1017 We might instead just pre-compute flags telling whether the
1018 object is suitable for local exec, initial exec or general
1019 dynamic addressing, and use that all over the place. We could
1020 also try to do a better job of merging TLSOFF and TLSDESC entries
1021 in main executables, but perhaps we can get rid of TLSDESC
1022 entirely in them instead. */
1023 /* Whether a GOTTLSDESC relocation references symbol+addend. */
1024 unsigned tlsdesc12
:1;
1025 unsigned tlsdesclos
:1;
1026 unsigned tlsdeschilo
:1;
1027 /* Whether a GOTTLSOFF relocation references symbol+addend. */
1028 unsigned tlsoff12
:1;
1029 unsigned tlsofflos
:1;
1030 unsigned tlsoffhilo
:1;
1031 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
1032 GOTOFFHI relocations. The addend doesn't really matter, since we
1033 envision that this will only be used to check whether the symbol
1034 is mapped to the same segment as the got. */
1036 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
1038 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
1041 /* Whether we need a PLT entry for a symbol. Should be implied by
1043 (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */
1045 /* Whether a function descriptor should be created in this link unit
1046 for symbol+addend. Should be implied by something like:
1047 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
1048 || ((fd || fdgot12 || fdgotlos || fdgothilo)
1049 && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */
1051 /* Whether a lazy PLT entry is needed for this symbol+addend.
1052 Should be implied by something like:
1053 (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)
1054 && ! (info->flags & DF_BIND_NOW)) */
1056 /* Whether we've already emitted GOT relocations and PLT entries as
1057 needed for this symbol. */
1060 /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and
1061 R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing
1063 unsigned relocs32
, relocsfd
, relocsfdv
, relocstlsd
, relocstlsoff
;
1065 /* The number of .rofixups entries and dynamic relocations allocated
1066 for this symbol, minus any that might have already been used. */
1067 unsigned fixups
, dynrelocs
;
1069 /* The offsets of the GOT entries assigned to symbol+addend, to the
1070 function descriptor's address, and to a function descriptor,
1071 respectively. Should be zero if unassigned. The offsets are
1072 counted from the value that will be assigned to the PIC register,
1073 not from the beginning of the .got section. */
1074 bfd_signed_vma got_entry
, fdgot_entry
, fd_entry
;
1075 /* The offsets of the PLT entries assigned to symbol+addend,
1076 non-lazy and lazy, respectively. If unassigned, should be
1078 bfd_vma plt_entry
, lzplt_entry
;
1079 /* The offsets of the GOT entries for TLS offset and TLS descriptor. */
1080 bfd_signed_vma tlsoff_entry
, tlsdesc_entry
;
1081 /* The offset of the TLS offset PLT entry. */
1082 bfd_vma tlsplt_entry
;
1085 /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */
1087 frvfdpic_relocs_info_hash (const void *entry_
)
1089 const struct frvfdpic_relocs_info
*entry
= entry_
;
1091 return (entry
->symndx
== -1
1092 ? (long) entry
->d
.h
->root
.root
.hash
1093 : entry
->symndx
+ (long) entry
->d
.abfd
->id
* 257) + entry
->addend
;
1096 /* Test whether the key fields of two frvfdpic_relocs_info entries are
1099 frvfdpic_relocs_info_eq (const void *entry1
, const void *entry2
)
1101 const struct frvfdpic_relocs_info
*e1
= entry1
;
1102 const struct frvfdpic_relocs_info
*e2
= entry2
;
1104 return e1
->symndx
== e2
->symndx
&& e1
->addend
== e2
->addend
1105 && (e1
->symndx
== -1 ? e1
->d
.h
== e2
->d
.h
: e1
->d
.abfd
== e2
->d
.abfd
);
1108 /* Find or create an entry in a hash table HT that matches the key
1109 fields of the given ENTRY. If it's not found, memory for a new
1110 entry is allocated in ABFD's obstack. */
1111 static struct frvfdpic_relocs_info
*
1112 frvfdpic_relocs_info_find (struct htab
*ht
,
1114 const struct frvfdpic_relocs_info
*entry
,
1115 enum insert_option insert
)
1117 struct frvfdpic_relocs_info
**loc
=
1118 (struct frvfdpic_relocs_info
**) htab_find_slot (ht
, entry
, insert
);
1126 *loc
= bfd_zalloc (abfd
, sizeof (**loc
));
1131 (*loc
)->symndx
= entry
->symndx
;
1132 (*loc
)->d
= entry
->d
;
1133 (*loc
)->addend
= entry
->addend
;
1134 (*loc
)->plt_entry
= (bfd_vma
)-1;
1135 (*loc
)->lzplt_entry
= (bfd_vma
)-1;
1136 (*loc
)->tlsplt_entry
= (bfd_vma
)-1;
1141 /* Obtain the address of the entry in HT associated with H's symbol +
1142 addend, creating a new entry if none existed. ABFD is only used
1143 for memory allocation purposes. */
1144 inline static struct frvfdpic_relocs_info
*
1145 frvfdpic_relocs_info_for_global (struct htab
*ht
,
1147 struct elf_link_hash_entry
*h
,
1149 enum insert_option insert
)
1151 struct frvfdpic_relocs_info entry
;
1155 entry
.addend
= addend
;
1157 return frvfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1160 /* Obtain the address of the entry in HT associated with the SYMNDXth
1161 local symbol of the input bfd ABFD, plus the addend, creating a new
1162 entry if none existed. */
1163 inline static struct frvfdpic_relocs_info
*
1164 frvfdpic_relocs_info_for_local (struct htab
*ht
,
1168 enum insert_option insert
)
1170 struct frvfdpic_relocs_info entry
;
1172 entry
.symndx
= symndx
;
1173 entry
.d
.abfd
= abfd
;
1174 entry
.addend
= addend
;
1176 return frvfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1179 /* Merge fields set by check_relocs() of two entries that end up being
1180 mapped to the same (presumably global) symbol. */
1183 frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info
*e2
,
1184 struct frvfdpic_relocs_info
const *e1
)
1186 e2
->got12
|= e1
->got12
;
1187 e2
->gotlos
|= e1
->gotlos
;
1188 e2
->gothilo
|= e1
->gothilo
;
1190 e2
->fdgot12
|= e1
->fdgot12
;
1191 e2
->fdgotlos
|= e1
->fdgotlos
;
1192 e2
->fdgothilo
|= e1
->fdgothilo
;
1193 e2
->fdgoff12
|= e1
->fdgoff12
;
1194 e2
->fdgofflos
|= e1
->fdgofflos
;
1195 e2
->fdgoffhilo
|= e1
->fdgoffhilo
;
1196 e2
->tlsplt
|= e1
->tlsplt
;
1197 e2
->tlsdesc12
|= e1
->tlsdesc12
;
1198 e2
->tlsdesclos
|= e1
->tlsdesclos
;
1199 e2
->tlsdeschilo
|= e1
->tlsdeschilo
;
1200 e2
->tlsoff12
|= e1
->tlsoff12
;
1201 e2
->tlsofflos
|= e1
->tlsofflos
;
1202 e2
->tlsoffhilo
|= e1
->tlsoffhilo
;
1203 e2
->gotoff
|= e1
->gotoff
;
1204 e2
->call
|= e1
->call
;
1208 /* Every block of 65535 lazy PLT entries shares a single call to the
1209 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
1210 32767, counting from 0). All other lazy PLT entries branch to it
1211 in a single instruction. */
1213 #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
1214 #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767)
1216 /* Add a dynamic relocation to the SRELOC section. */
1218 inline static bfd_vma
1219 _frvfdpic_add_dyn_reloc (bfd
*output_bfd
, asection
*sreloc
, bfd_vma offset
,
1220 int reloc_type
, long dynindx
, bfd_vma addend
,
1221 struct frvfdpic_relocs_info
*entry
)
1223 Elf_Internal_Rela outrel
;
1224 bfd_vma reloc_offset
;
1226 outrel
.r_offset
= offset
;
1227 outrel
.r_info
= ELF32_R_INFO (dynindx
, reloc_type
);
1228 outrel
.r_addend
= addend
;
1230 reloc_offset
= sreloc
->reloc_count
* sizeof (Elf32_External_Rel
);
1231 BFD_ASSERT (reloc_offset
< sreloc
->size
);
1232 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
1233 sreloc
->contents
+ reloc_offset
);
1234 sreloc
->reloc_count
++;
1236 /* If the entry's index is zero, this relocation was probably to a
1237 linkonce section that got discarded. We reserved a dynamic
1238 relocation, but it was for another entry than the one we got at
1239 the time of emitting the relocation. Unfortunately there's no
1240 simple way for us to catch this situation, since the relocation
1241 is cleared right before calling relocate_section, at which point
1242 we no longer know what the relocation used to point to. */
1245 BFD_ASSERT (entry
->dynrelocs
> 0);
1249 return reloc_offset
;
1252 /* Add a fixup to the ROFIXUP section. */
1255 _frvfdpic_add_rofixup (bfd
*output_bfd
, asection
*rofixup
, bfd_vma offset
,
1256 struct frvfdpic_relocs_info
*entry
)
1258 bfd_vma fixup_offset
;
1260 if (rofixup
->flags
& SEC_EXCLUDE
)
1263 fixup_offset
= rofixup
->reloc_count
* 4;
1264 if (rofixup
->contents
)
1266 BFD_ASSERT (fixup_offset
< rofixup
->size
);
1267 bfd_put_32 (output_bfd
, offset
, rofixup
->contents
+ fixup_offset
);
1269 rofixup
->reloc_count
++;
1271 if (entry
&& entry
->symndx
)
1273 /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc
1275 BFD_ASSERT (entry
->fixups
> 0);
1279 return fixup_offset
;
1282 /* Find the segment number in which OSEC, and output section, is
1286 _frvfdpic_osec_to_segment (bfd
*output_bfd
, asection
*osec
)
1288 Elf_Internal_Phdr
*p
= _bfd_elf_find_segment_containing_section (output_bfd
, osec
);
1290 return (p
!= NULL
) ? p
- elf_tdata (output_bfd
)->phdr
: -1;
1293 inline static bfd_boolean
1294 _frvfdpic_osec_readonly_p (bfd
*output_bfd
, asection
*osec
)
1296 unsigned seg
= _frvfdpic_osec_to_segment (output_bfd
, osec
);
1298 return ! (elf_tdata (output_bfd
)->phdr
[seg
].p_flags
& PF_W
);
1301 #define FRVFDPIC_TLS_BIAS (2048 - 16)
1303 /* Return the base VMA address which should be subtracted from real addresses
1304 when resolving TLSMOFF relocation.
1305 This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */
1308 tls_biased_base (struct bfd_link_info
*info
)
1310 /* If tls_sec is NULL, we should have signalled an error already. */
1311 if (elf_hash_table (info
)->tls_sec
== NULL
)
1312 return FRVFDPIC_TLS_BIAS
;
1313 return elf_hash_table (info
)->tls_sec
->vma
+ FRVFDPIC_TLS_BIAS
;
1316 /* Generate relocations for GOT entries, function descriptors, and
1317 code for PLT and lazy PLT entries. */
1319 inline static bfd_boolean
1320 _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info
*entry
,
1322 struct bfd_link_info
*info
,
1324 Elf_Internal_Sym
*sym
,
1328 bfd_vma fd_lazy_rel_offset
= (bfd_vma
)-1;
1335 if (entry
->got_entry
|| entry
->fdgot_entry
|| entry
->fd_entry
1336 || entry
->tlsoff_entry
|| entry
->tlsdesc_entry
)
1338 /* If the symbol is dynamic, consider it for dynamic
1339 relocations, otherwise decay to section + offset. */
1340 if (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1)
1341 dynindx
= entry
->d
.h
->dynindx
;
1345 && sec
->output_section
1346 && ! bfd_is_abs_section (sec
->output_section
)
1347 && ! bfd_is_und_section (sec
->output_section
))
1348 dynindx
= elf_section_data (sec
->output_section
)->dynindx
;
1354 /* Generate relocation for GOT entry pointing to the symbol. */
1355 if (entry
->got_entry
)
1358 bfd_vma ad
= addend
;
1360 /* If the symbol is dynamic but binds locally, use
1362 if (sec
&& (entry
->symndx
!= -1
1363 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1365 if (entry
->symndx
== -1)
1366 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1368 ad
+= sym
->st_value
;
1369 ad
+= sec
->output_offset
;
1370 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1371 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1376 /* If we're linking an executable at a fixed address, we can
1377 omit the dynamic relocation as long as the symbol is local to
1379 if (bfd_link_pde (info
)
1380 && (entry
->symndx
!= -1
1381 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1384 ad
+= sec
->output_section
->vma
;
1385 if (entry
->symndx
!= -1
1386 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1387 _frvfdpic_add_rofixup (output_bfd
,
1388 frvfdpic_gotfixup_section (info
),
1389 frvfdpic_got_section (info
)->output_section
1391 + frvfdpic_got_section (info
)->output_offset
1392 + frvfdpic_got_initial_offset (info
)
1393 + entry
->got_entry
, entry
);
1396 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1397 _bfd_elf_section_offset
1399 frvfdpic_got_section (info
),
1400 frvfdpic_got_initial_offset (info
)
1402 + frvfdpic_got_section (info
)
1403 ->output_section
->vma
1404 + frvfdpic_got_section (info
)->output_offset
,
1405 R_FRV_32
, idx
, ad
, entry
);
1407 bfd_put_32 (output_bfd
, ad
,
1408 frvfdpic_got_section (info
)->contents
1409 + frvfdpic_got_initial_offset (info
)
1410 + entry
->got_entry
);
1413 /* Generate relocation for GOT entry pointing to a canonical
1414 function descriptor. */
1415 if (entry
->fdgot_entry
)
1420 if (! (entry
->symndx
== -1
1421 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
1422 && FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1424 /* If the symbol is dynamic and there may be dynamic symbol
1425 resolution because we are, or are linked with, a shared
1426 library, emit a FUNCDESC relocation such that the dynamic
1427 linker will allocate the function descriptor. If the
1428 symbol needs a non-local function descriptor but binds
1429 locally (e.g., its visibility is protected, emit a
1430 dynamic relocation decayed to section+offset. */
1431 if (entry
->symndx
== -1
1432 && ! FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)
1433 && FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)
1434 && !bfd_link_pde (info
))
1436 reloc
= R_FRV_FUNCDESC
;
1437 idx
= elf_section_data (entry
->d
.h
->root
.u
.def
.section
1438 ->output_section
)->dynindx
;
1439 ad
= entry
->d
.h
->root
.u
.def
.section
->output_offset
1440 + entry
->d
.h
->root
.u
.def
.value
;
1442 else if (entry
->symndx
== -1
1443 && ! FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
))
1445 reloc
= R_FRV_FUNCDESC
;
1450 (*info
->callbacks
->reloc_dangerous
)
1451 (info
, _("relocation requires zero addend"),
1452 elf_hash_table (info
)->dynobj
,
1453 frvfdpic_got_section (info
),
1454 entry
->fdgot_entry
);
1460 /* Otherwise, we know we have a private function descriptor,
1461 so reference it directly. */
1462 if (elf_hash_table (info
)->dynamic_sections_created
)
1463 BFD_ASSERT (entry
->privfd
);
1465 idx
= elf_section_data (frvfdpic_got_section (info
)
1466 ->output_section
)->dynindx
;
1467 ad
= frvfdpic_got_section (info
)->output_offset
1468 + frvfdpic_got_initial_offset (info
) + entry
->fd_entry
;
1471 /* If there is room for dynamic symbol resolution, emit the
1472 dynamic relocation. However, if we're linking an
1473 executable at a fixed location, we won't have emitted a
1474 dynamic symbol entry for the got section, so idx will be
1475 zero, which means we can and should compute the address
1476 of the private descriptor ourselves. */
1477 if (bfd_link_pde (info
)
1478 && (entry
->symndx
!= -1
1479 || FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)))
1481 ad
+= frvfdpic_got_section (info
)->output_section
->vma
;
1482 _frvfdpic_add_rofixup (output_bfd
,
1483 frvfdpic_gotfixup_section (info
),
1484 frvfdpic_got_section (info
)
1485 ->output_section
->vma
1486 + frvfdpic_got_section (info
)
1488 + frvfdpic_got_initial_offset (info
)
1489 + entry
->fdgot_entry
, entry
);
1492 _frvfdpic_add_dyn_reloc (output_bfd
,
1493 frvfdpic_gotrel_section (info
),
1494 _bfd_elf_section_offset
1496 frvfdpic_got_section (info
),
1497 frvfdpic_got_initial_offset (info
)
1498 + entry
->fdgot_entry
)
1499 + frvfdpic_got_section (info
)
1500 ->output_section
->vma
1501 + frvfdpic_got_section (info
)
1503 reloc
, idx
, ad
, entry
);
1506 bfd_put_32 (output_bfd
, ad
,
1507 frvfdpic_got_section (info
)->contents
1508 + frvfdpic_got_initial_offset (info
)
1509 + entry
->fdgot_entry
);
1512 /* Generate relocation to fill in a private function descriptor in
1514 if (entry
->fd_entry
)
1517 bfd_vma ad
= addend
;
1519 long lowword
, highword
;
1521 /* If the symbol is dynamic but binds locally, use
1523 if (sec
&& (entry
->symndx
!= -1
1524 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1526 if (entry
->symndx
== -1)
1527 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1529 ad
+= sym
->st_value
;
1530 ad
+= sec
->output_offset
;
1531 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1532 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1537 /* If we're linking an executable at a fixed address, we can
1538 omit the dynamic relocation as long as the symbol is local to
1540 if (bfd_link_pde (info
)
1541 && (entry
->symndx
!= -1 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1544 ad
+= sec
->output_section
->vma
;
1546 if (entry
->symndx
!= -1
1547 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1549 _frvfdpic_add_rofixup (output_bfd
,
1550 frvfdpic_gotfixup_section (info
),
1551 frvfdpic_got_section (info
)
1552 ->output_section
->vma
1553 + frvfdpic_got_section (info
)
1555 + frvfdpic_got_initial_offset (info
)
1556 + entry
->fd_entry
, entry
);
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
+ 4, entry
);
1570 _frvfdpic_add_dyn_reloc (output_bfd
,
1572 ? frvfdpic_pltrel_section (info
)
1573 : frvfdpic_gotrel_section (info
),
1574 _bfd_elf_section_offset
1576 frvfdpic_got_section (info
),
1577 frvfdpic_got_initial_offset (info
)
1579 + frvfdpic_got_section (info
)
1580 ->output_section
->vma
1581 + frvfdpic_got_section (info
)
1583 R_FRV_FUNCDESC_VALUE
, idx
, ad
, entry
);
1586 /* If we've omitted the dynamic relocation, just emit the fixed
1587 addresses of the symbol and of the local GOT base offset. */
1588 if (bfd_link_pde (info
)
1590 && sec
->output_section
)
1593 highword
= frvfdpic_got_section (info
)->output_section
->vma
1594 + frvfdpic_got_section (info
)->output_offset
1595 + frvfdpic_got_initial_offset (info
);
1597 else if (entry
->lazyplt
)
1601 (*info
->callbacks
->reloc_dangerous
)
1602 (info
, _("relocation requires zero addend"),
1603 elf_hash_table (info
)->dynobj
,
1604 frvfdpic_got_section (info
),
1609 fd_lazy_rel_offset
= ofst
;
1611 /* A function descriptor used for lazy or local resolving is
1612 initialized such that its high word contains the output
1613 section index in which the PLT entries are located, and
1614 the low word contains the address of the lazy PLT entry
1615 entry point, that must be within the memory region
1616 assigned to that section. */
1617 lowword
= entry
->lzplt_entry
+ 4
1618 + frvfdpic_plt_section (info
)->output_offset
1619 + frvfdpic_plt_section (info
)->output_section
->vma
;
1620 highword
= _frvfdpic_osec_to_segment
1621 (output_bfd
, frvfdpic_plt_section (info
)->output_section
);
1625 /* A function descriptor for a local function gets the index
1626 of the section. For a non-local function, it's
1630 || (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1
1631 && entry
->d
.h
->dynindx
== idx
))
1634 highword
= _frvfdpic_osec_to_segment
1635 (output_bfd
, sec
->output_section
);
1638 bfd_put_32 (output_bfd
, lowword
,
1639 frvfdpic_got_section (info
)->contents
1640 + frvfdpic_got_initial_offset (info
)
1642 bfd_put_32 (output_bfd
, highword
,
1643 frvfdpic_got_section (info
)->contents
1644 + frvfdpic_got_initial_offset (info
)
1645 + entry
->fd_entry
+ 4);
1648 /* Generate code for the PLT entry. */
1649 if (entry
->plt_entry
!= (bfd_vma
) -1)
1651 bfd_byte
*plt_code
= frvfdpic_plt_section (info
)->contents
1654 BFD_ASSERT (entry
->fd_entry
);
1656 /* Figure out what kind of PLT entry we need, depending on the
1657 location of the function descriptor within the GOT. */
1658 if (entry
->fd_entry
>= -(1 << (12 - 1))
1659 && entry
->fd_entry
< (1 << (12 - 1)))
1661 /* lddi @(gr15, fd_entry), gr14 */
1662 bfd_put_32 (output_bfd
,
1663 0x9cccf000 | (entry
->fd_entry
& ((1 << 12) - 1)),
1669 if (entry
->fd_entry
>= -(1 << (16 - 1))
1670 && entry
->fd_entry
< (1 << (16 - 1)))
1672 /* setlos lo(fd_entry), gr14 */
1673 bfd_put_32 (output_bfd
,
1675 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1681 /* sethi.p hi(fd_entry), gr14
1682 setlo lo(fd_entry), gr14 */
1683 bfd_put_32 (output_bfd
,
1685 | ((entry
->fd_entry
>> 16)
1686 & (((bfd_vma
)1 << 16) - 1)),
1689 bfd_put_32 (output_bfd
,
1691 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1695 /* ldd @(gr14,gr15),gr14 */
1696 bfd_put_32 (output_bfd
, 0x9c08e14f, plt_code
);
1699 /* jmpl @(gr14,gr0) */
1700 bfd_put_32 (output_bfd
, 0x8030e000, plt_code
);
1703 /* Generate code for the lazy PLT entry. */
1704 if (entry
->lzplt_entry
!= (bfd_vma
) -1)
1706 bfd_byte
*lzplt_code
= frvfdpic_plt_section (info
)->contents
1707 + entry
->lzplt_entry
;
1708 bfd_vma resolverStub_addr
;
1710 bfd_put_32 (output_bfd
, fd_lazy_rel_offset
, lzplt_code
);
1713 resolverStub_addr
= entry
->lzplt_entry
/ FRVFDPIC_LZPLT_BLOCK_SIZE
1714 * FRVFDPIC_LZPLT_BLOCK_SIZE
+ FRVFDPIC_LZPLT_RESOLV_LOC
;
1715 if (resolverStub_addr
>= frvfdpic_plt_initial_offset (info
))
1716 resolverStub_addr
= frvfdpic_plt_initial_offset (info
) - 12;
1718 if (entry
->lzplt_entry
== resolverStub_addr
)
1720 /* This is a lazy PLT entry that includes a resolver call. */
1721 /* ldd @(gr15,gr0), gr4
1723 bfd_put_32 (output_bfd
, 0x8808f140, lzplt_code
);
1724 bfd_put_32 (output_bfd
, 0x80304000, lzplt_code
+ 4);
1728 /* bra resolverStub */
1729 bfd_put_32 (output_bfd
,
1731 | (((resolverStub_addr
- entry
->lzplt_entry
)
1732 / 4) & (((bfd_vma
)1 << 16) - 1)),
1737 /* Generate relocation for GOT entry holding the TLS offset. */
1738 if (entry
->tlsoff_entry
)
1741 bfd_vma ad
= addend
;
1743 if (entry
->symndx
!= -1
1744 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
))
1746 /* If the symbol is dynamic but binds locally, use
1750 if (entry
->symndx
== -1)
1751 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1753 ad
+= sym
->st_value
;
1754 ad
+= sec
->output_offset
;
1755 if (sec
->output_section
1756 && elf_section_data (sec
->output_section
))
1757 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1763 /* *ABS*+addend is special for TLS relocations, use only the
1765 if (bfd_link_executable (info
)
1767 && (bfd_is_abs_section (sec
)
1768 || bfd_is_und_section (sec
)))
1770 /* If we're linking an executable, we can entirely omit the
1771 dynamic relocation if the symbol is local to this module. */
1772 else if (bfd_link_executable (info
)
1773 && (entry
->symndx
!= -1
1774 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1777 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1782 && (bfd_is_abs_section (sec
)
1783 || bfd_is_und_section (sec
)))
1785 if (! elf_hash_table (info
)->tls_sec
)
1787 (*info
->callbacks
->undefined_symbol
)
1788 (info
, "TLS section", elf_hash_table (info
)->dynobj
,
1789 frvfdpic_got_section (info
), entry
->tlsoff_entry
, TRUE
);
1792 idx
= elf_section_data (elf_hash_table (info
)->tls_sec
)->dynindx
;
1793 ad
+= FRVFDPIC_TLS_BIAS
;
1795 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1796 _bfd_elf_section_offset
1798 frvfdpic_got_section (info
),
1799 frvfdpic_got_initial_offset (info
)
1800 + entry
->tlsoff_entry
)
1801 + frvfdpic_got_section (info
)
1802 ->output_section
->vma
1803 + frvfdpic_got_section (info
)
1805 R_FRV_TLSOFF
, idx
, ad
, entry
);
1808 bfd_put_32 (output_bfd
, ad
,
1809 frvfdpic_got_section (info
)->contents
1810 + frvfdpic_got_initial_offset (info
)
1811 + entry
->tlsoff_entry
);
1814 if (entry
->tlsdesc_entry
)
1817 bfd_vma ad
= addend
;
1819 /* If the symbol is dynamic but binds locally, use
1821 if (sec
&& (entry
->symndx
!= -1
1822 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1824 if (entry
->symndx
== -1)
1825 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1827 ad
+= sym
->st_value
;
1828 ad
+= sec
->output_offset
;
1829 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1830 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1835 /* If we didn't set up a TLS offset entry, but we're linking an
1836 executable and the symbol binds locally, we can use the
1837 module offset in the TLS descriptor in relaxations. */
1838 if (bfd_link_executable (info
) && ! entry
->tlsoff_entry
)
1839 entry
->tlsoff_entry
= entry
->tlsdesc_entry
+ 4;
1841 if (bfd_link_pde (info
)
1843 && (bfd_is_abs_section (sec
)
1844 || bfd_is_und_section (sec
)))
1845 || entry
->symndx
!= -1
1846 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1848 /* *ABS*+addend is special for TLS relocations, use only the
1849 addend for the TLS offset, and take the module id as
1852 && (bfd_is_abs_section (sec
)
1853 || bfd_is_und_section (sec
)))
1855 /* For other TLS symbols that bind locally, add the section
1856 TLS offset to the addend. */
1858 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1860 bfd_put_32 (output_bfd
,
1861 frvfdpic_plt_section (info
)->output_section
->vma
1862 + frvfdpic_plt_section (info
)->output_offset
1863 + frvfdpic_plt_tls_ret_offset (info
),
1864 frvfdpic_got_section (info
)->contents
1865 + frvfdpic_got_initial_offset (info
)
1866 + entry
->tlsdesc_entry
);
1868 _frvfdpic_add_rofixup (output_bfd
,
1869 frvfdpic_gotfixup_section (info
),
1870 frvfdpic_got_section (info
)
1871 ->output_section
->vma
1872 + frvfdpic_got_section (info
)
1874 + frvfdpic_got_initial_offset (info
)
1875 + entry
->tlsdesc_entry
, entry
);
1877 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
);
1879 /* We've used one of the reserved fixups, so discount it so
1880 that we can check at the end that we've used them
1882 frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
--;
1884 /* While at that, make sure the ret instruction makes to the
1885 right location in the PLT. We could do it only when we
1886 got to 0, but since the check at the end will only print
1887 a warning, make sure we have the ret in place in case the
1888 warning is missed. */
1889 bfd_put_32 (output_bfd
, 0xc03a4000,
1890 frvfdpic_plt_section (info
)->contents
1891 + frvfdpic_plt_tls_ret_offset (info
));
1896 && (bfd_is_abs_section (sec
)
1897 || bfd_is_und_section (sec
)))
1899 if (! elf_hash_table (info
)->tls_sec
)
1901 (*info
->callbacks
->undefined_symbol
)
1902 (info
, "TLS section", elf_hash_table (info
)->dynobj
,
1903 frvfdpic_got_section (info
), entry
->tlsdesc_entry
, TRUE
);
1906 idx
= elf_section_data (elf_hash_table (info
)->tls_sec
)->dynindx
;
1907 ad
+= FRVFDPIC_TLS_BIAS
;
1910 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1911 _bfd_elf_section_offset
1913 frvfdpic_got_section (info
),
1914 frvfdpic_got_initial_offset (info
)
1915 + entry
->tlsdesc_entry
)
1916 + frvfdpic_got_section (info
)
1917 ->output_section
->vma
1918 + frvfdpic_got_section (info
)
1920 R_FRV_TLSDESC_VALUE
, idx
, ad
, entry
);
1922 bfd_put_32 (output_bfd
, 0,
1923 frvfdpic_got_section (info
)->contents
1924 + frvfdpic_got_initial_offset (info
)
1925 + entry
->tlsdesc_entry
);
1928 bfd_put_32 (output_bfd
, ad
,
1929 frvfdpic_got_section (info
)->contents
1930 + frvfdpic_got_initial_offset (info
)
1931 + entry
->tlsdesc_entry
+ 4);
1934 /* Generate code for the get-TLS-offset PLT entry. */
1935 if (entry
->tlsplt_entry
!= (bfd_vma
) -1)
1937 bfd_byte
*plt_code
= frvfdpic_plt_section (info
)->contents
1938 + entry
->tlsplt_entry
;
1940 if (bfd_link_executable (info
)
1941 && (entry
->symndx
!= -1
1942 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1945 bfd_vma ad
= addend
;
1947 /* sec may be NULL when referencing an undefweak symbol
1948 while linking a static executable. */
1951 BFD_ASSERT (entry
->symndx
== -1
1952 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
);
1956 if (entry
->symndx
== -1)
1957 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1959 ad
+= sym
->st_value
;
1960 ad
+= sec
->output_offset
;
1961 if (sec
->output_section
1962 && elf_section_data (sec
->output_section
))
1963 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1968 /* *ABS*+addend is special for TLS relocations, use only the
1969 addend for the TLS offset, and take the module id as
1972 && (bfd_is_abs_section (sec
)
1973 || bfd_is_und_section (sec
)))
1975 /* For other TLS symbols that bind locally, add the section
1976 TLS offset to the addend. */
1978 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1980 if ((bfd_signed_vma
)ad
>= -(1 << (16 - 1))
1981 && (bfd_signed_vma
)ad
< (1 << (16 - 1)))
1983 /* setlos lo(ad), gr9 */
1984 bfd_put_32 (output_bfd
,
1987 & (((bfd_vma
)1 << 16) - 1)),
1993 /* sethi.p hi(ad), gr9
1994 setlo lo(ad), gr9 */
1995 bfd_put_32 (output_bfd
,
1998 & (((bfd_vma
)1 << 16) - 1)),
2001 bfd_put_32 (output_bfd
,
2004 & (((bfd_vma
)1 << 16) - 1)),
2009 bfd_put_32 (output_bfd
, 0xc03a4000, plt_code
);
2011 else if (entry
->tlsoff_entry
)
2013 /* Figure out what kind of PLT entry we need, depending on the
2014 location of the TLS descriptor within the GOT. */
2015 if (entry
->tlsoff_entry
>= -(1 << (12 - 1))
2016 && entry
->tlsoff_entry
< (1 << (12 - 1)))
2018 /* ldi @(gr15, tlsoff_entry), gr9 */
2019 bfd_put_32 (output_bfd
,
2020 0x92c8f000 | (entry
->tlsoff_entry
2027 if (entry
->tlsoff_entry
>= -(1 << (16 - 1))
2028 && entry
->tlsoff_entry
< (1 << (16 - 1)))
2030 /* setlos lo(tlsoff_entry), gr8 */
2031 bfd_put_32 (output_bfd
,
2033 | (entry
->tlsoff_entry
2034 & (((bfd_vma
)1 << 16) - 1)),
2040 /* sethi.p hi(tlsoff_entry), gr8
2041 setlo lo(tlsoff_entry), gr8 */
2042 bfd_put_32 (output_bfd
,
2044 | ((entry
->tlsoff_entry
>> 16)
2045 & (((bfd_vma
)1 << 16) - 1)),
2048 bfd_put_32 (output_bfd
,
2050 | (entry
->tlsoff_entry
2051 & (((bfd_vma
)1 << 16) - 1)),
2055 /* ld @(gr15,gr8),gr9 */
2056 bfd_put_32 (output_bfd
, 0x9008f108, plt_code
);
2060 bfd_put_32 (output_bfd
, 0xc03a4000, plt_code
);
2064 BFD_ASSERT (entry
->tlsdesc_entry
);
2066 /* Figure out what kind of PLT entry we need, depending on the
2067 location of the TLS descriptor within the GOT. */
2068 if (entry
->tlsdesc_entry
>= -(1 << (12 - 1))
2069 && entry
->tlsdesc_entry
< (1 << (12 - 1)))
2071 /* lddi @(gr15, tlsdesc_entry), gr8 */
2072 bfd_put_32 (output_bfd
,
2073 0x90ccf000 | (entry
->tlsdesc_entry
2080 if (entry
->tlsdesc_entry
>= -(1 << (16 - 1))
2081 && entry
->tlsdesc_entry
< (1 << (16 - 1)))
2083 /* setlos lo(tlsdesc_entry), gr8 */
2084 bfd_put_32 (output_bfd
,
2086 | (entry
->tlsdesc_entry
2087 & (((bfd_vma
)1 << 16) - 1)),
2093 /* sethi.p hi(tlsdesc_entry), gr8
2094 setlo lo(tlsdesc_entry), gr8 */
2095 bfd_put_32 (output_bfd
,
2097 | ((entry
->tlsdesc_entry
>> 16)
2098 & (((bfd_vma
)1 << 16) - 1)),
2101 bfd_put_32 (output_bfd
,
2103 | (entry
->tlsdesc_entry
2104 & (((bfd_vma
)1 << 16) - 1)),
2108 /* ldd @(gr15,gr8),gr8 */
2109 bfd_put_32 (output_bfd
, 0x9008f148, plt_code
);
2112 /* jmpl @(gr8,gr0) */
2113 bfd_put_32 (output_bfd
, 0x80308000, plt_code
);
2120 /* Handle an FRV small data reloc. */
2122 static bfd_reloc_status_type
2123 elf32_frv_relocate_gprel12 (struct bfd_link_info
*info
,
2125 asection
*input_section
,
2126 Elf_Internal_Rela
*relocation
,
2132 struct bfd_link_hash_entry
*h
;
2134 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2136 gp
= (h
->u
.def
.value
2137 + h
->u
.def
.section
->output_section
->vma
2138 + h
->u
.def
.section
->output_offset
);
2140 value
-= input_section
->output_section
->vma
;
2141 value
-= (gp
- input_section
->output_section
->vma
);
2143 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2145 value
+= relocation
->r_addend
;
2147 if ((long) value
> 0x7ff || (long) value
< -0x800)
2148 return bfd_reloc_overflow
;
2150 bfd_put_32 (input_bfd
,
2151 (insn
& 0xfffff000) | (value
& 0xfff),
2152 contents
+ relocation
->r_offset
);
2154 return bfd_reloc_ok
;
2157 /* Handle an FRV small data reloc. for the u12 field. */
2159 static bfd_reloc_status_type
2160 elf32_frv_relocate_gprelu12 (struct bfd_link_info
*info
,
2162 asection
*input_section
,
2163 Elf_Internal_Rela
*relocation
,
2169 struct bfd_link_hash_entry
*h
;
2172 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2174 gp
= (h
->u
.def
.value
2175 + h
->u
.def
.section
->output_section
->vma
2176 + h
->u
.def
.section
->output_offset
);
2178 value
-= input_section
->output_section
->vma
;
2179 value
-= (gp
- input_section
->output_section
->vma
);
2181 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2183 value
+= relocation
->r_addend
;
2185 if ((long) value
> 0x7ff || (long) value
< -0x800)
2186 return bfd_reloc_overflow
;
2188 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
2190 insn
= (insn
& ~mask
) | ((value
& 0xfc0) << 12) | (value
& 0x3f);
2192 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2194 return bfd_reloc_ok
;
2197 /* Handle an FRV ELF HI16 reloc. */
2199 static bfd_reloc_status_type
2200 elf32_frv_relocate_hi16 (bfd
*input_bfd
,
2201 Elf_Internal_Rela
*relhi
,
2207 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
2209 value
+= relhi
->r_addend
;
2210 value
= ((value
>> 16) & 0xffff);
2212 insn
= (insn
& 0xffff0000) | value
;
2214 if ((long) value
> 0xffff || (long) value
< -0x10000)
2215 return bfd_reloc_overflow
;
2217 bfd_put_32 (input_bfd
, insn
, contents
+ relhi
->r_offset
);
2218 return bfd_reloc_ok
;
2221 static bfd_reloc_status_type
2222 elf32_frv_relocate_lo16 (bfd
*input_bfd
,
2223 Elf_Internal_Rela
*rello
,
2229 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2231 value
+= rello
->r_addend
;
2232 value
= value
& 0xffff;
2234 insn
= (insn
& 0xffff0000) | value
;
2236 if ((long) value
> 0xffff || (long) value
< -0x10000)
2237 return bfd_reloc_overflow
;
2239 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
2240 return bfd_reloc_ok
;
2243 /* Perform the relocation for the CALL label24 instruction. */
2245 static bfd_reloc_status_type
2246 elf32_frv_relocate_label24 (bfd
*input_bfd
,
2247 asection
*input_section
,
2248 Elf_Internal_Rela
*rello
,
2256 /* The format for the call instruction is:
2258 0 000000 0001111 000000000000000000
2259 label6 opcode label18
2261 The branch calculation is: pc + (4*label24)
2262 where label24 is the concatenation of label6 and label18. */
2264 /* Grab the instruction. */
2265 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2267 value
-= input_section
->output_section
->vma
+ input_section
->output_offset
;
2268 value
-= rello
->r_offset
;
2269 value
+= rello
->r_addend
;
2273 label6
= value
& 0xfc0000;
2274 label6
= label6
<< 7;
2276 label18
= value
& 0x3ffff;
2278 insn
= insn
& 0x803c0000;
2279 insn
= insn
| label6
;
2280 insn
= insn
| label18
;
2282 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
2284 return bfd_reloc_ok
;
2287 static bfd_reloc_status_type
2288 elf32_frv_relocate_gprelhi (struct bfd_link_info
*info
,
2290 asection
*input_section
,
2291 Elf_Internal_Rela
*relocation
,
2297 struct bfd_link_hash_entry
*h
;
2299 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2301 gp
= (h
->u
.def
.value
2302 + h
->u
.def
.section
->output_section
->vma
2303 + h
->u
.def
.section
->output_offset
);
2305 value
-= input_section
->output_section
->vma
;
2306 value
-= (gp
- input_section
->output_section
->vma
);
2307 value
+= relocation
->r_addend
;
2308 value
= ((value
>> 16) & 0xffff);
2310 if ((long) value
> 0xffff || (long) value
< -0x10000)
2311 return bfd_reloc_overflow
;
2313 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2314 insn
= (insn
& 0xffff0000) | value
;
2316 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2317 return bfd_reloc_ok
;
2320 static bfd_reloc_status_type
2321 elf32_frv_relocate_gprello (struct bfd_link_info
*info
,
2323 asection
*input_section
,
2324 Elf_Internal_Rela
*relocation
,
2330 struct bfd_link_hash_entry
*h
;
2332 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2334 gp
= (h
->u
.def
.value
2335 + h
->u
.def
.section
->output_section
->vma
2336 + h
->u
.def
.section
->output_offset
);
2338 value
-= input_section
->output_section
->vma
;
2339 value
-= (gp
- input_section
->output_section
->vma
);
2340 value
+= relocation
->r_addend
;
2341 value
= value
& 0xffff;
2343 if ((long) value
> 0xffff || (long) value
< -0x10000)
2344 return bfd_reloc_overflow
;
2346 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2347 insn
= (insn
& 0xffff0000) | value
;
2349 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2351 return bfd_reloc_ok
;
2354 static reloc_howto_type
*
2355 frv_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2356 bfd_reloc_code_real_type code
)
2363 case BFD_RELOC_NONE
:
2364 return &elf32_frv_howto_table
[ (int) R_FRV_NONE
];
2367 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2368 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2369 return &elf32_frv_rel_32_howto
;
2371 case BFD_RELOC_CTOR
:
2372 return &elf32_frv_howto_table
[ (int) R_FRV_32
];
2374 case BFD_RELOC_FRV_LABEL16
:
2375 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL16
];
2377 case BFD_RELOC_FRV_LABEL24
:
2378 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL24
];
2380 case BFD_RELOC_FRV_LO16
:
2381 return &elf32_frv_howto_table
[ (int) R_FRV_LO16
];
2383 case BFD_RELOC_FRV_HI16
:
2384 return &elf32_frv_howto_table
[ (int) R_FRV_HI16
];
2386 case BFD_RELOC_FRV_GPREL12
:
2387 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL12
];
2389 case BFD_RELOC_FRV_GPRELU12
:
2390 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELU12
];
2392 case BFD_RELOC_FRV_GPREL32
:
2393 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL32
];
2395 case BFD_RELOC_FRV_GPRELHI
:
2396 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELHI
];
2398 case BFD_RELOC_FRV_GPRELLO
:
2399 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELLO
];
2401 case BFD_RELOC_FRV_GOT12
:
2402 return &elf32_frv_howto_table
[ (int) R_FRV_GOT12
];
2404 case BFD_RELOC_FRV_GOTHI
:
2405 return &elf32_frv_howto_table
[ (int) R_FRV_GOTHI
];
2407 case BFD_RELOC_FRV_GOTLO
:
2408 return &elf32_frv_howto_table
[ (int) R_FRV_GOTLO
];
2410 case BFD_RELOC_FRV_FUNCDESC
:
2411 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2412 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2413 return &elf32_frv_rel_funcdesc_howto
;
2414 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC
];
2416 case BFD_RELOC_FRV_FUNCDESC_GOT12
:
2417 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOT12
];
2419 case BFD_RELOC_FRV_FUNCDESC_GOTHI
:
2420 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTHI
];
2422 case BFD_RELOC_FRV_FUNCDESC_GOTLO
:
2423 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTLO
];
2425 case BFD_RELOC_FRV_FUNCDESC_VALUE
:
2426 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2427 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2428 return &elf32_frv_rel_funcdesc_value_howto
;
2429 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_VALUE
];
2431 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12
:
2432 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFF12
];
2434 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI
:
2435 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFHI
];
2437 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO
:
2438 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFLO
];
2440 case BFD_RELOC_FRV_GOTOFF12
:
2441 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFF12
];
2443 case BFD_RELOC_FRV_GOTOFFHI
:
2444 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFHI
];
2446 case BFD_RELOC_FRV_GOTOFFLO
:
2447 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFLO
];
2449 case BFD_RELOC_FRV_GETTLSOFF
:
2450 return &elf32_frv_howto_table
[ (int) R_FRV_GETTLSOFF
];
2452 case BFD_RELOC_FRV_TLSDESC_VALUE
:
2453 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2454 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2455 return &elf32_frv_rel_tlsdesc_value_howto
;
2456 return &elf32_frv_howto_table
[ (int) R_FRV_TLSDESC_VALUE
];
2458 case BFD_RELOC_FRV_GOTTLSDESC12
:
2459 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESC12
];
2461 case BFD_RELOC_FRV_GOTTLSDESCHI
:
2462 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESCHI
];
2464 case BFD_RELOC_FRV_GOTTLSDESCLO
:
2465 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESCLO
];
2467 case BFD_RELOC_FRV_TLSMOFF12
:
2468 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFF12
];
2470 case BFD_RELOC_FRV_TLSMOFFHI
:
2471 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFFHI
];
2473 case BFD_RELOC_FRV_TLSMOFFLO
:
2474 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFFLO
];
2476 case BFD_RELOC_FRV_GOTTLSOFF12
:
2477 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFF12
];
2479 case BFD_RELOC_FRV_GOTTLSOFFHI
:
2480 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFFHI
];
2482 case BFD_RELOC_FRV_GOTTLSOFFLO
:
2483 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFFLO
];
2485 case BFD_RELOC_FRV_TLSOFF
:
2486 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2487 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2488 return &elf32_frv_rel_tlsoff_howto
;
2489 return &elf32_frv_howto_table
[ (int) R_FRV_TLSOFF
];
2491 case BFD_RELOC_FRV_TLSDESC_RELAX
:
2492 return &elf32_frv_howto_table
[ (int) R_FRV_TLSDESC_RELAX
];
2494 case BFD_RELOC_FRV_GETTLSOFF_RELAX
:
2495 return &elf32_frv_howto_table
[ (int) R_FRV_GETTLSOFF_RELAX
];
2497 case BFD_RELOC_FRV_TLSOFF_RELAX
:
2498 return &elf32_frv_howto_table
[ (int) R_FRV_TLSOFF_RELAX
];
2500 case BFD_RELOC_FRV_TLSMOFF
:
2501 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFF
];
2503 case BFD_RELOC_VTABLE_INHERIT
:
2504 return &elf32_frv_vtinherit_howto
;
2506 case BFD_RELOC_VTABLE_ENTRY
:
2507 return &elf32_frv_vtentry_howto
;
2513 static reloc_howto_type
*
2514 frv_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
, const char *r_name
)
2519 i
< sizeof (elf32_frv_howto_table
) / sizeof (elf32_frv_howto_table
[0]);
2521 if (elf32_frv_howto_table
[i
].name
!= NULL
2522 && strcasecmp (elf32_frv_howto_table
[i
].name
, r_name
) == 0)
2523 return &elf32_frv_howto_table
[i
];
2525 if (strcasecmp (elf32_frv_vtinherit_howto
.name
, r_name
) == 0)
2526 return &elf32_frv_vtinherit_howto
;
2527 if (strcasecmp (elf32_frv_vtentry_howto
.name
, r_name
) == 0)
2528 return &elf32_frv_vtentry_howto
;
2533 /* Set the howto pointer for an FRV ELF reloc. */
2536 frv_info_to_howto_rela (bfd
*abfd ATTRIBUTE_UNUSED
,
2538 Elf_Internal_Rela
*dst
)
2540 unsigned int r_type
;
2542 r_type
= ELF32_R_TYPE (dst
->r_info
);
2545 case R_FRV_GNU_VTINHERIT
:
2546 cache_ptr
->howto
= &elf32_frv_vtinherit_howto
;
2549 case R_FRV_GNU_VTENTRY
:
2550 cache_ptr
->howto
= &elf32_frv_vtentry_howto
;
2554 if (r_type
>= (unsigned int) R_FRV_max
)
2556 /* xgettext:c-format */
2557 _bfd_error_handler (_("%B: invalid FRV reloc number: %d"), abfd
, r_type
);
2560 cache_ptr
->howto
= & elf32_frv_howto_table
[r_type
];
2565 /* Set the howto pointer for an FRV ELF REL reloc. */
2567 frvfdpic_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
2568 arelent
*cache_ptr
, Elf_Internal_Rela
*dst
)
2570 unsigned int r_type
;
2572 r_type
= ELF32_R_TYPE (dst
->r_info
);
2576 cache_ptr
->howto
= &elf32_frv_rel_32_howto
;
2579 case R_FRV_FUNCDESC
:
2580 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_howto
;
2583 case R_FRV_FUNCDESC_VALUE
:
2584 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_value_howto
;
2587 case R_FRV_TLSDESC_VALUE
:
2588 cache_ptr
->howto
= &elf32_frv_rel_tlsdesc_value_howto
;
2592 cache_ptr
->howto
= &elf32_frv_rel_tlsoff_howto
;
2596 cache_ptr
->howto
= NULL
;
2601 /* Perform a single relocation. By default we use the standard BFD
2602 routines, but a few relocs, we have to do them ourselves. */
2604 static bfd_reloc_status_type
2605 frv_final_link_relocate (reloc_howto_type
*howto
,
2607 asection
*input_section
,
2609 Elf_Internal_Rela
*rel
,
2612 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2613 contents
, rel
->r_offset
, relocation
,
2618 /* Relocate an FRV ELF section.
2620 The RELOCATE_SECTION function is called by the new ELF backend linker
2621 to handle the relocations for a section.
2623 The relocs are always passed as Rela structures; if the section
2624 actually uses Rel structures, the r_addend field will always be
2627 This function is responsible for adjusting the section contents as
2628 necessary, and (if using Rela relocs and generating a relocatable
2629 output file) adjusting the reloc addend as necessary.
2631 This function does not have to worry about setting the reloc
2632 address or the reloc symbol index.
2634 LOCAL_SYMS is a pointer to the swapped in local symbols.
2636 LOCAL_SECTIONS is an array giving the section in the input file
2637 corresponding to the st_shndx field of each local symbol.
2639 The global hash table entry for the global symbols can be found
2640 via elf_sym_hashes (input_bfd).
2642 When generating relocatable output, this function must handle
2643 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2644 going to be the section symbol corresponding to the output
2645 section, which means that the addend must be adjusted
2649 elf32_frv_relocate_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2650 struct bfd_link_info
*info
,
2652 asection
*input_section
,
2654 Elf_Internal_Rela
*relocs
,
2655 Elf_Internal_Sym
*local_syms
,
2656 asection
**local_sections
)
2658 Elf_Internal_Shdr
*symtab_hdr
;
2659 struct elf_link_hash_entry
**sym_hashes
;
2660 Elf_Internal_Rela
*rel
;
2661 Elf_Internal_Rela
*relend
;
2662 unsigned isec_segment
, got_segment
, plt_segment
, gprel_segment
, tls_segment
,
2664 int silence_segment_error
= !bfd_link_pic (info
);
2667 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
2668 sym_hashes
= elf_sym_hashes (input_bfd
);
2669 relend
= relocs
+ input_section
->reloc_count
;
2671 isec_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2672 input_section
->output_section
);
2673 if (IS_FDPIC (output_bfd
) && frvfdpic_got_section (info
))
2674 got_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2675 frvfdpic_got_section (info
)
2679 if (IS_FDPIC (output_bfd
) && frvfdpic_gotfixup_section (info
))
2680 gprel_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2681 frvfdpic_gotfixup_section (info
)
2685 if (IS_FDPIC (output_bfd
) && frvfdpic_plt_section (info
))
2686 plt_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2687 frvfdpic_plt_section (info
)
2691 if (elf_hash_table (info
)->tls_sec
)
2692 tls_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2693 elf_hash_table (info
)->tls_sec
);
2697 for (rel
= relocs
; rel
< relend
; rel
++)
2699 reloc_howto_type
*howto
;
2700 unsigned long r_symndx
;
2701 Elf_Internal_Sym
*sym
;
2703 struct elf_link_hash_entry
*h
;
2705 bfd_reloc_status_type r
;
2709 struct frvfdpic_relocs_info
*picrel
;
2710 bfd_vma orig_addend
= rel
->r_addend
;
2712 r_type
= ELF32_R_TYPE (rel
->r_info
);
2714 if ( r_type
== R_FRV_GNU_VTINHERIT
2715 || r_type
== R_FRV_GNU_VTENTRY
)
2718 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2719 howto
= elf32_frv_howto_table
+ ELF32_R_TYPE (rel
->r_info
);
2724 if (r_symndx
< symtab_hdr
->sh_info
)
2726 sym
= local_syms
+ r_symndx
;
2727 osec
= sec
= local_sections
[r_symndx
];
2728 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2730 name
= bfd_elf_string_from_elf_section
2731 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
2732 if (name
== NULL
|| name
[0] == 0)
2733 name
= bfd_section_name (input_bfd
, sec
);
2737 bfd_boolean warned
, ignored
;
2738 bfd_boolean unresolved_reloc
;
2740 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2741 r_symndx
, symtab_hdr
, sym_hashes
,
2743 unresolved_reloc
, warned
, ignored
);
2745 name
= h
->root
.root
.string
;
2748 if (sec
!= NULL
&& discarded_section (sec
))
2749 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
2750 rel
, 1, relend
, howto
, 0, contents
);
2752 if (bfd_link_relocatable (info
))
2755 if (r_type
!= R_FRV_TLSMOFF
2757 && (h
->root
.type
== bfd_link_hash_defined
2758 || h
->root
.type
== bfd_link_hash_defweak
)
2759 && !FRVFDPIC_SYM_LOCAL (info
, h
))
2769 if (! IS_FDPIC (output_bfd
))
2776 case R_FRV_FUNCDESC_GOT12
:
2777 case R_FRV_FUNCDESC_GOTHI
:
2778 case R_FRV_FUNCDESC_GOTLO
:
2779 case R_FRV_GOTOFF12
:
2780 case R_FRV_GOTOFFHI
:
2781 case R_FRV_GOTOFFLO
:
2782 case R_FRV_FUNCDESC_GOTOFF12
:
2783 case R_FRV_FUNCDESC_GOTOFFHI
:
2784 case R_FRV_FUNCDESC_GOTOFFLO
:
2785 case R_FRV_FUNCDESC
:
2786 case R_FRV_FUNCDESC_VALUE
:
2787 case R_FRV_GETTLSOFF
:
2788 case R_FRV_TLSDESC_VALUE
:
2789 case R_FRV_GOTTLSDESC12
:
2790 case R_FRV_GOTTLSDESCHI
:
2791 case R_FRV_GOTTLSDESCLO
:
2792 case R_FRV_TLSMOFF12
:
2793 case R_FRV_TLSMOFFHI
:
2794 case R_FRV_TLSMOFFLO
:
2795 case R_FRV_GOTTLSOFF12
:
2796 case R_FRV_GOTTLSOFFHI
:
2797 case R_FRV_GOTTLSOFFLO
:
2799 case R_FRV_TLSDESC_RELAX
:
2800 case R_FRV_GETTLSOFF_RELAX
:
2801 case R_FRV_TLSOFF_RELAX
:
2804 picrel
= frvfdpic_relocs_info_for_global (frvfdpic_relocs_info
2805 (info
), input_bfd
, h
,
2806 orig_addend
, INSERT
);
2808 /* In order to find the entry we created before, we must
2809 use the original addend, not the one that may have been
2810 modified by _bfd_elf_rela_local_sym(). */
2811 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
2812 (info
), input_bfd
, r_symndx
,
2813 orig_addend
, INSERT
);
2817 if (!_frvfdpic_emit_got_relocs_plt_entries (picrel
, output_bfd
, info
,
2821 info
->callbacks
->einfo
2822 /* xgettext:c-format */
2823 (_("%H: relocation to `%s+%v'"
2824 " may have caused the error above\n"),
2825 input_bfd
, input_section
, rel
->r_offset
, name
, rel
->r_addend
);
2835 && ! FRVFDPIC_SYM_LOCAL (info
, h
)
2836 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2837 rel
->r_offset
) != (bfd_vma
) -1)
2839 info
->callbacks
->einfo
2840 (_("%H: relocation references symbol"
2841 " not defined in the module\n"),
2842 input_bfd
, input_section
, rel
->r_offset
);
2850 case R_FRV_GETTLSOFF
:
2851 case R_FRV_TLSDESC_VALUE
:
2852 case R_FRV_GOTTLSDESC12
:
2853 case R_FRV_GOTTLSDESCHI
:
2854 case R_FRV_GOTTLSDESCLO
:
2855 case R_FRV_TLSMOFF12
:
2856 case R_FRV_TLSMOFFHI
:
2857 case R_FRV_TLSMOFFLO
:
2858 case R_FRV_GOTTLSOFF12
:
2859 case R_FRV_GOTTLSOFFHI
:
2860 case R_FRV_GOTTLSOFFLO
:
2862 case R_FRV_TLSDESC_RELAX
:
2863 case R_FRV_GETTLSOFF_RELAX
:
2864 case R_FRV_TLSOFF_RELAX
:
2866 if (sec
&& (bfd_is_abs_section (sec
) || bfd_is_und_section (sec
)))
2867 relocation
+= tls_biased_base (info
);
2874 /* Try to apply TLS relaxations. */
2879 #define LOCAL_EXEC_P(info, picrel) \
2880 (bfd_link_executable (info) \
2881 && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h)))
2882 #define INITIAL_EXEC_P(info, picrel) \
2883 ((bfd_link_executable (info)|| (info)->flags & DF_STATIC_TLS) \
2884 && (picrel)->tlsoff_entry)
2886 #define IN_RANGE_FOR_OFST12_P(value) \
2887 ((bfd_vma)((value) + 2048) < (bfd_vma)4096)
2888 #define IN_RANGE_FOR_SETLOS_P(value) \
2889 ((bfd_vma)((value) + 32768) < (bfd_vma)65536)
2890 #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \
2891 (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info)))
2893 #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2894 (LOCAL_EXEC_P ((info), (picrel)) \
2895 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2896 #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \
2897 (INITIAL_EXEC_P ((info), (picrel)) \
2898 && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry))
2900 #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \
2901 (LOCAL_EXEC_P ((info), (picrel)))
2902 #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \
2903 (INITIAL_EXEC_P ((info), (picrel)))
2905 #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2906 (LOCAL_EXEC_P ((info), (picrel)) \
2907 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2909 case R_FRV_GETTLSOFF
:
2910 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2912 /* Is this a call instruction? */
2913 if ((insn
& (unsigned long)0x01fc0000) != 0x003c0000)
2915 info
->callbacks
->einfo
2916 (_("%H: R_FRV_GETTLSOFF not applied to a call instruction\n"),
2917 input_bfd
, input_section
, rel
->r_offset
);
2921 if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info
, picrel
,
2922 relocation
+ rel
->r_addend
))
2924 /* Replace the call instruction (except the packing bit)
2925 with setlos #tlsmofflo(symbol+offset), gr9. */
2926 insn
&= (unsigned long)0x80000000;
2927 insn
|= (unsigned long)0x12fc0000;
2928 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
2930 r_type
= R_FRV_TLSMOFFLO
;
2931 howto
= elf32_frv_howto_table
+ r_type
;
2932 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
2935 else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info
, picrel
))
2937 /* Replace the call instruction (except the packing bit)
2938 with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */
2939 insn
&= (unsigned long)0x80000000;
2940 insn
|= (unsigned long)0x12c8f000;
2941 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
2943 r_type
= R_FRV_GOTTLSOFF12
;
2944 howto
= elf32_frv_howto_table
+ r_type
;
2945 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
2950 case R_FRV_GOTTLSDESC12
:
2951 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2953 /* Is this an lddi instruction? */
2954 if ((insn
& (unsigned long)0x01fc0000) != 0x00cc0000)
2956 info
->callbacks
->einfo
2957 (_("%H: R_FRV_GOTTLSDESC12"
2958 " not applied to an lddi instruction\n"),
2959 input_bfd
, input_section
, rel
->r_offset
);
2963 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
2964 relocation
+ rel
->r_addend
)
2965 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
2968 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
2969 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
2970 Preserve the packing bit. */
2971 insn
= (insn
& (unsigned long)0x80000000)
2972 | ((insn
+ (unsigned long)0x02000000)
2973 & (unsigned long)0x7e000000);
2974 insn
|= (unsigned long)0x00fc0000;
2975 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
2977 r_type
= R_FRV_TLSMOFFLO
;
2978 howto
= elf32_frv_howto_table
+ r_type
;
2979 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
2982 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
2983 relocation
+ rel
->r_addend
))
2985 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
2986 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
2987 Preserve the packing bit. */
2988 insn
= (insn
& (unsigned long)0x80000000)
2989 | ((insn
+ (unsigned long)0x02000000)
2990 & (unsigned long)0x7e000000);
2991 insn
|= (unsigned long)0x00f80000;
2992 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
2994 r_type
= R_FRV_TLSMOFFHI
;
2995 howto
= elf32_frv_howto_table
+ r_type
;
2996 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
2999 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3001 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3002 with ldi @(grB, #gottlsoff12(symbol+offset),
3003 gr<C+1>. Preserve the packing bit. If gottlsoff12
3004 overflows, we'll error out, but that's sort-of ok,
3005 since we'd started with gottlsdesc12, that's actually
3006 more demanding. Compiling with -fPIE instead of
3007 -fpie would fix it; linking with --relax should fix
3009 insn
= (insn
& (unsigned long)0x80cbf000)
3010 | ((insn
+ (unsigned long)0x02000000)
3011 & (unsigned long)0x7e000000);
3012 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3014 r_type
= R_FRV_GOTTLSOFF12
;
3015 howto
= elf32_frv_howto_table
+ r_type
;
3016 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3021 case R_FRV_GOTTLSDESCHI
:
3022 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3024 /* Is this a sethi instruction? */
3025 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3027 info
->callbacks
->einfo
3028 (_("%H: R_FRV_GOTTLSDESCHI"
3029 " not applied to a sethi instruction\n"),
3030 input_bfd
, input_section
, rel
->r_offset
);
3034 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3035 relocation
+ rel
->r_addend
)
3036 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3037 && IN_RANGE_FOR_SETLOS_P (picrel
->tlsoff_entry
)))
3039 /* Replace sethi with a nop. Preserve the packing bit. */
3040 insn
&= (unsigned long)0x80000000;
3041 insn
|= (unsigned long)0x00880000;
3042 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3044 /* Nothing to relocate. */
3048 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3050 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3051 r_type
= R_FRV_GOTTLSOFFHI
;
3052 howto
= elf32_frv_howto_table
+ r_type
;
3053 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3058 case R_FRV_GOTTLSDESCLO
:
3059 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3061 /* Is this a setlo or setlos instruction? */
3062 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3064 info
->callbacks
->einfo
3065 (_("%H: R_FRV_GOTTLSDESCLO"
3066 " not applied to a setlo or setlos instruction\n"),
3067 input_bfd
, input_section
, rel
->r_offset
);
3071 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3072 relocation
+ rel
->r_addend
)
3073 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3074 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3076 /* Replace setlo/setlos with a nop. Preserve the
3078 insn
&= (unsigned long)0x80000000;
3079 insn
|= (unsigned long)0x00880000;
3080 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3082 /* Nothing to relocate. */
3086 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3088 /* If the corresponding sethi (if it exists) decayed
3089 to a nop, make sure this becomes (or already is) a
3090 setlos, not setlo. */
3091 if (IN_RANGE_FOR_SETLOS_P (picrel
->tlsoff_entry
))
3093 insn
|= (unsigned long)0x00080000;
3094 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3097 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3098 r_type
= R_FRV_GOTTLSOFFLO
;
3099 howto
= elf32_frv_howto_table
+ r_type
;
3100 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3105 case R_FRV_TLSDESC_RELAX
:
3106 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3108 /* Is this an ldd instruction? */
3109 if ((insn
& (unsigned long)0x01fc0fc0) != 0x00080140)
3111 info
->callbacks
->einfo
3112 (_("%H: R_FRV_TLSDESC_RELAX"
3113 " not applied to an ldd instruction\n"),
3114 input_bfd
, input_section
, rel
->r_offset
);
3118 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3119 relocation
+ rel
->r_addend
)
3120 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3123 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3124 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3125 Preserve the packing bit. */
3126 insn
= (insn
& (unsigned long)0x80000000)
3127 | ((insn
+ (unsigned long)0x02000000)
3128 & (unsigned long)0x7e000000);
3129 insn
|= (unsigned long)0x00fc0000;
3130 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3132 r_type
= R_FRV_TLSMOFFLO
;
3133 howto
= elf32_frv_howto_table
+ r_type
;
3134 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3137 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3138 relocation
+ rel
->r_addend
))
3140 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3141 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3142 Preserve the packing bit. */
3143 insn
= (insn
& (unsigned long)0x80000000)
3144 | ((insn
+ (unsigned long)0x02000000)
3145 & (unsigned long)0x7e000000);
3146 insn
|= (unsigned long)0x00f80000;
3147 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3149 r_type
= R_FRV_TLSMOFFHI
;
3150 howto
= elf32_frv_howto_table
+ r_type
;
3151 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3154 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3155 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
))
3157 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3158 with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>.
3159 Preserve the packing bit. */
3160 insn
= (insn
& (unsigned long)0x8003f000)
3161 | (unsigned long)0x00c80000
3162 | ((insn
+ (unsigned long)0x02000000)
3163 & (unsigned long)0x7e000000);
3164 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3166 r_type
= R_FRV_GOTTLSOFF12
;
3167 howto
= elf32_frv_howto_table
+ r_type
;
3168 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3171 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3173 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3174 with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>.
3175 Preserve the packing bit. */
3176 insn
= (insn
& (unsigned long)0x81ffffbf)
3177 | ((insn
+ (unsigned long)0x02000000)
3178 & (unsigned long)0x7e000000);
3179 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3181 /* #tlsoff(symbol+offset) is just a relaxation
3182 annotation, so there's nothing left to
3189 case R_FRV_GETTLSOFF_RELAX
:
3190 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3192 /* Is this a calll or callil instruction? */
3193 if ((insn
& (unsigned long)0x7ff80fc0) != 0x02300000)
3195 info
->callbacks
->einfo
3196 (_("%H: R_FRV_GETTLSOFF_RELAX"
3197 " not applied to a calll instruction\n"),
3198 input_bfd
, input_section
, rel
->r_offset
);
3202 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3203 relocation
+ rel
->r_addend
)
3204 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3207 /* Replace calll with a nop. Preserve the packing bit. */
3208 insn
&= (unsigned long)0x80000000;
3209 insn
|= (unsigned long)0x00880000;
3210 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3212 /* Nothing to relocate. */
3216 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3217 relocation
+ rel
->r_addend
))
3219 /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9.
3220 Preserve the packing bit. */
3221 insn
&= (unsigned long)0x80000000;
3222 insn
|= (unsigned long)0x12f40000;
3223 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3225 r_type
= R_FRV_TLSMOFFLO
;
3226 howto
= elf32_frv_howto_table
+ r_type
;
3227 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3230 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3232 /* Replace calll with a nop. Preserve the packing bit. */
3233 insn
&= (unsigned long)0x80000000;
3234 insn
|= (unsigned long)0x00880000;
3235 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3237 /* Nothing to relocate. */
3243 case R_FRV_GOTTLSOFF12
:
3244 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3246 /* Is this an ldi instruction? */
3247 if ((insn
& (unsigned long)0x01fc0000) != 0x00c80000)
3249 info
->callbacks
->einfo
3250 (_("%H: R_FRV_GOTTLSOFF12"
3251 " not applied to an ldi instruction\n"),
3252 input_bfd
, input_section
, rel
->r_offset
);
3256 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3257 relocation
+ rel
->r_addend
))
3259 /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC
3260 with setlos #tlsmofflo(symbol+offset), grC.
3261 Preserve the packing bit. */
3262 insn
&= (unsigned long)0xfe000000;
3263 insn
|= (unsigned long)0x00fc0000;
3264 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3266 r_type
= R_FRV_TLSMOFFLO
;
3267 howto
= elf32_frv_howto_table
+ r_type
;
3268 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3273 case R_FRV_GOTTLSOFFHI
:
3274 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3276 /* Is this a sethi instruction? */
3277 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3279 info
->callbacks
->einfo
3280 (_("%H: R_FRV_GOTTLSOFFHI"
3281 " not applied to a sethi instruction\n"),
3282 input_bfd
, input_section
, rel
->r_offset
);
3286 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3287 relocation
+ rel
->r_addend
)
3288 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3289 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3291 /* Replace sethi with a nop. Preserve the packing bit. */
3292 insn
&= (unsigned long)0x80000000;
3293 insn
|= (unsigned long)0x00880000;
3294 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3296 /* Nothing to relocate. */
3302 case R_FRV_GOTTLSOFFLO
:
3303 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3305 /* Is this a setlo or setlos instruction? */
3306 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3308 info
->callbacks
->einfo
3309 (_("%H: R_FRV_GOTTLSOFFLO"
3310 " not applied to a setlo or setlos instruction\n"),
3311 input_bfd
, input_section
, rel
->r_offset
);
3315 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3316 relocation
+ rel
->r_addend
)
3317 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3318 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3320 /* Replace setlo/setlos with a nop. Preserve the
3322 insn
&= (unsigned long)0x80000000;
3323 insn
|= (unsigned long)0x00880000;
3324 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3326 /* Nothing to relocate. */
3332 case R_FRV_TLSOFF_RELAX
:
3333 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3335 /* Is this an ld instruction? */
3336 if ((insn
& (unsigned long)0x01fc0fc0) != 0x00080100)
3338 info
->callbacks
->einfo
3339 (_("%H: R_FRV_TLSOFF_RELAX"
3340 " not applied to an ld instruction\n"),
3341 input_bfd
, input_section
, rel
->r_offset
);
3345 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3346 relocation
+ rel
->r_addend
))
3348 /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC
3349 with setlos #tlsmofflo(symbol+offset), grC.
3350 Preserve the packing bit. */
3351 insn
&= (unsigned long)0xfe000000;
3352 insn
|= (unsigned long)0x00fc0000;
3353 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3355 r_type
= R_FRV_TLSMOFFLO
;
3356 howto
= elf32_frv_howto_table
+ r_type
;
3357 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3360 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3361 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
))
3363 /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC
3364 with ldi @(grB, #gottlsoff12(symbol+offset), grC.
3365 Preserve the packing bit. */
3366 insn
= (insn
& (unsigned long)0xfe03f000)
3367 | (unsigned long)0x00c80000;
3368 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3370 r_type
= R_FRV_GOTTLSOFF12
;
3371 howto
= elf32_frv_howto_table
+ r_type
;
3372 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3377 case R_FRV_TLSMOFFHI
:
3378 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3380 /* Is this a sethi instruction? */
3381 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3383 info
->callbacks
->einfo
3384 (_("%H: R_FRV_TLSMOFFHI"
3385 " not applied to a sethi instruction\n"),
3386 input_bfd
, input_section
, rel
->r_offset
);
3390 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3393 /* Replace sethi with a nop. Preserve the packing bit. */
3394 insn
&= (unsigned long)0x80000000;
3395 insn
|= (unsigned long)0x00880000;
3396 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3398 /* Nothing to relocate. */
3404 case R_FRV_TLSMOFFLO
:
3405 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3407 /* Is this a setlo or setlos instruction? */
3408 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3410 info
->callbacks
->einfo
3411 (_("R_FRV_TLSMOFFLO"
3412 " not applied to a setlo or setlos instruction\n"),
3413 input_bfd
, input_section
, rel
->r_offset
);
3417 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3419 /* If the corresponding sethi (if it exists) decayed
3420 to a nop, make sure this becomes (or already is) a
3421 setlos, not setlo. */
3423 insn
|= (unsigned long)0x00080000;
3424 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3430 There's nothing to relax in these:
3446 check_segment
[0] = isec_segment
;
3447 if (! IS_FDPIC (output_bfd
))
3448 check_segment
[1] = isec_segment
;
3449 else if (picrel
->plt
)
3451 relocation
= frvfdpic_plt_section (info
)->output_section
->vma
3452 + frvfdpic_plt_section (info
)->output_offset
3453 + picrel
->plt_entry
;
3454 check_segment
[1] = plt_segment
;
3456 /* We don't want to warn on calls to undefined weak symbols,
3457 as calls to them must be protected by non-NULL tests
3458 anyway, and unprotected calls would invoke undefined
3460 else if (picrel
->symndx
== -1
3461 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefweak
)
3462 check_segment
[1] = check_segment
[0];
3464 check_segment
[1] = sec
3465 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3472 relocation
= picrel
->got_entry
;
3473 check_segment
[0] = check_segment
[1] = got_segment
;
3476 case R_FRV_FUNCDESC_GOT12
:
3477 case R_FRV_FUNCDESC_GOTHI
:
3478 case R_FRV_FUNCDESC_GOTLO
:
3479 relocation
= picrel
->fdgot_entry
;
3480 check_segment
[0] = check_segment
[1] = got_segment
;
3483 case R_FRV_GOTOFFHI
:
3484 case R_FRV_GOTOFF12
:
3485 case R_FRV_GOTOFFLO
:
3486 relocation
-= frvfdpic_got_section (info
)->output_section
->vma
3487 + frvfdpic_got_section (info
)->output_offset
3488 + frvfdpic_got_initial_offset (info
);
3489 check_segment
[0] = got_segment
;
3490 check_segment
[1] = sec
3491 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3495 case R_FRV_FUNCDESC_GOTOFF12
:
3496 case R_FRV_FUNCDESC_GOTOFFHI
:
3497 case R_FRV_FUNCDESC_GOTOFFLO
:
3498 relocation
= picrel
->fd_entry
;
3499 check_segment
[0] = check_segment
[1] = got_segment
;
3502 case R_FRV_FUNCDESC
:
3505 bfd_vma addend
= rel
->r_addend
;
3507 if (! (h
&& h
->root
.type
== bfd_link_hash_undefweak
3508 && FRVFDPIC_SYM_LOCAL (info
, h
)))
3510 /* If the symbol is dynamic and there may be dynamic
3511 symbol resolution because we are or are linked with a
3512 shared library, emit a FUNCDESC relocation such that
3513 the dynamic linker will allocate the function
3514 descriptor. If the symbol needs a non-local function
3515 descriptor but binds locally (e.g., its visibility is
3516 protected, emit a dynamic relocation decayed to
3518 if (h
&& ! FRVFDPIC_FUNCDESC_LOCAL (info
, h
)
3519 && FRVFDPIC_SYM_LOCAL (info
, h
)
3520 && !bfd_link_pde (info
))
3522 dynindx
= elf_section_data (h
->root
.u
.def
.section
3523 ->output_section
)->dynindx
;
3524 addend
+= h
->root
.u
.def
.section
->output_offset
3525 + h
->root
.u
.def
.value
;
3527 else if (h
&& ! FRVFDPIC_FUNCDESC_LOCAL (info
, h
))
3531 info
->callbacks
->einfo
3532 (_("%H: R_FRV_FUNCDESC references dynamic symbol"
3533 " with nonzero addend\n"),
3534 input_bfd
, input_section
, rel
->r_offset
);
3537 dynindx
= h
->dynindx
;
3541 /* Otherwise, we know we have a private function
3542 descriptor, so reference it directly. */
3543 BFD_ASSERT (picrel
->privfd
);
3545 dynindx
= elf_section_data (frvfdpic_got_section (info
)
3546 ->output_section
)->dynindx
;
3547 addend
= frvfdpic_got_section (info
)->output_offset
3548 + frvfdpic_got_initial_offset (info
)
3552 /* If there is room for dynamic symbol resolution, emit
3553 the dynamic relocation. However, if we're linking an
3554 executable at a fixed location, we won't have emitted a
3555 dynamic symbol entry for the got section, so idx will
3556 be zero, which means we can and should compute the
3557 address of the private descriptor ourselves. */
3558 if (bfd_link_pde (info
)
3559 && (!h
|| FRVFDPIC_FUNCDESC_LOCAL (info
, h
)))
3561 addend
+= frvfdpic_got_section (info
)->output_section
->vma
;
3562 if ((bfd_get_section_flags (output_bfd
,
3563 input_section
->output_section
)
3564 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3568 if (_frvfdpic_osec_readonly_p (output_bfd
,
3572 info
->callbacks
->einfo
3573 (_("%H: cannot emit fixups"
3574 " in read-only section\n"),
3575 input_bfd
, input_section
, rel
->r_offset
);
3579 offset
= _bfd_elf_section_offset
3581 input_section
, rel
->r_offset
);
3583 if (offset
!= (bfd_vma
)-1)
3584 _frvfdpic_add_rofixup (output_bfd
,
3585 frvfdpic_gotfixup_section
3587 offset
+ input_section
3588 ->output_section
->vma
3589 + input_section
->output_offset
,
3593 else if ((bfd_get_section_flags (output_bfd
,
3594 input_section
->output_section
)
3595 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3599 if (_frvfdpic_osec_readonly_p (output_bfd
,
3603 info
->callbacks
->einfo
3604 (_("%H: cannot emit dynamic relocations"
3605 " in read-only section\n"),
3606 input_bfd
, input_section
, rel
->r_offset
);
3610 offset
= _bfd_elf_section_offset
3612 input_section
, rel
->r_offset
);
3614 if (offset
!= (bfd_vma
)-1)
3615 _frvfdpic_add_dyn_reloc (output_bfd
,
3616 frvfdpic_gotrel_section (info
),
3617 offset
+ input_section
3618 ->output_section
->vma
3619 + input_section
->output_offset
,
3620 r_type
, dynindx
, addend
, picrel
);
3623 addend
+= frvfdpic_got_section (info
)->output_section
->vma
;
3626 /* We want the addend in-place because dynamic
3627 relocations are REL. Setting relocation to it should
3628 arrange for it to be installed. */
3629 relocation
= addend
- rel
->r_addend
;
3631 check_segment
[0] = check_segment
[1] = got_segment
;
3635 if (! IS_FDPIC (output_bfd
))
3637 check_segment
[0] = check_segment
[1] = -1;
3641 case R_FRV_FUNCDESC_VALUE
:
3644 bfd_vma addend
= rel
->r_addend
;
3646 /* If the symbol is dynamic but binds locally, use
3648 if (h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
))
3650 if (addend
&& r_type
== R_FRV_FUNCDESC_VALUE
)
3652 info
->callbacks
->einfo
3653 (_("%H: R_FRV_FUNCDESC_VALUE"
3654 " references dynamic symbol with nonzero addend\n"),
3655 input_bfd
, input_section
, rel
->r_offset
);
3658 dynindx
= h
->dynindx
;
3663 addend
+= h
->root
.u
.def
.value
;
3665 addend
+= sym
->st_value
;
3667 addend
+= osec
->output_offset
;
3668 if (osec
&& osec
->output_section
3669 && ! bfd_is_abs_section (osec
->output_section
)
3670 && ! bfd_is_und_section (osec
->output_section
))
3671 dynindx
= elf_section_data (osec
->output_section
)->dynindx
;
3676 /* If we're linking an executable at a fixed address, we
3677 can omit the dynamic relocation as long as the symbol
3678 is defined in the current link unit (which is implied
3679 by its output section not being NULL). */
3680 if (bfd_link_pde (info
)
3681 && (!h
|| FRVFDPIC_SYM_LOCAL (info
, h
)))
3684 addend
+= osec
->output_section
->vma
;
3685 if (IS_FDPIC (input_bfd
)
3686 && (bfd_get_section_flags (output_bfd
,
3687 input_section
->output_section
)
3688 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3690 if (_frvfdpic_osec_readonly_p (output_bfd
,
3694 info
->callbacks
->einfo
3695 (_("%H: cannot emit fixups in read-only section\n"),
3696 input_bfd
, input_section
, rel
->r_offset
);
3699 if (!h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
3701 bfd_vma offset
= _bfd_elf_section_offset
3703 input_section
, rel
->r_offset
);
3705 if (offset
!= (bfd_vma
)-1)
3707 _frvfdpic_add_rofixup (output_bfd
,
3708 frvfdpic_gotfixup_section
3710 offset
+ input_section
3711 ->output_section
->vma
3712 + input_section
->output_offset
,
3714 if (r_type
== R_FRV_FUNCDESC_VALUE
)
3715 _frvfdpic_add_rofixup
3717 frvfdpic_gotfixup_section (info
),
3719 + input_section
->output_section
->vma
3720 + input_section
->output_offset
+ 4, picrel
);
3727 if ((bfd_get_section_flags (output_bfd
,
3728 input_section
->output_section
)
3729 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3733 if (_frvfdpic_osec_readonly_p (output_bfd
,
3737 info
->callbacks
->einfo
3738 (_("%H: cannot emit dynamic relocations"
3739 " in read-only section\n"),
3740 input_bfd
, input_section
, rel
->r_offset
);
3744 offset
= _bfd_elf_section_offset
3746 input_section
, rel
->r_offset
);
3748 if (offset
!= (bfd_vma
)-1)
3749 _frvfdpic_add_dyn_reloc (output_bfd
,
3750 frvfdpic_gotrel_section (info
),
3751 offset
+ input_section
3752 ->output_section
->vma
3753 + input_section
->output_offset
,
3754 r_type
, dynindx
, addend
, picrel
);
3757 addend
+= osec
->output_section
->vma
;
3758 /* We want the addend in-place because dynamic
3759 relocations are REL. Setting relocation to it
3760 should arrange for it to be installed. */
3761 relocation
= addend
- rel
->r_addend
;
3764 if (r_type
== R_FRV_FUNCDESC_VALUE
)
3766 /* If we've omitted the dynamic relocation, just emit
3767 the fixed addresses of the symbol and of the local
3769 if (bfd_link_pde (info
)
3770 && (!h
|| FRVFDPIC_SYM_LOCAL (info
, h
)))
3771 bfd_put_32 (output_bfd
,
3772 frvfdpic_got_section (info
)->output_section
->vma
3773 + frvfdpic_got_section (info
)->output_offset
3774 + frvfdpic_got_initial_offset (info
),
3775 contents
+ rel
->r_offset
+ 4);
3777 /* A function descriptor used for lazy or local
3778 resolving is initialized such that its high word
3779 contains the output section index in which the
3780 PLT entries are located, and the low word
3781 contains the offset of the lazy PLT entry entry
3782 point into that section. */
3783 bfd_put_32 (output_bfd
,
3784 h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
)
3786 : _frvfdpic_osec_to_segment (output_bfd
,
3789 contents
+ rel
->r_offset
+ 4);
3792 check_segment
[0] = check_segment
[1] = got_segment
;
3796 case R_FRV_GPRELU12
:
3800 check_segment
[0] = gprel_segment
;
3801 check_segment
[1] = sec
3802 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3806 case R_FRV_GETTLSOFF
:
3807 relocation
= frvfdpic_plt_section (info
)->output_section
->vma
3808 + frvfdpic_plt_section (info
)->output_offset
3809 + picrel
->tlsplt_entry
;
3810 BFD_ASSERT (picrel
->tlsplt_entry
!= (bfd_vma
)-1
3811 && picrel
->tlsdesc_entry
);
3812 check_segment
[0] = isec_segment
;
3813 check_segment
[1] = plt_segment
;
3816 case R_FRV_GOTTLSDESC12
:
3817 case R_FRV_GOTTLSDESCHI
:
3818 case R_FRV_GOTTLSDESCLO
:
3819 BFD_ASSERT (picrel
->tlsdesc_entry
);
3820 relocation
= picrel
->tlsdesc_entry
;
3821 check_segment
[0] = tls_segment
;
3822 check_segment
[1] = sec
3823 && ! bfd_is_abs_section (sec
)
3824 && ! bfd_is_und_section (sec
)
3825 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3829 case R_FRV_TLSMOFF12
:
3830 case R_FRV_TLSMOFFHI
:
3831 case R_FRV_TLSMOFFLO
:
3833 check_segment
[0] = tls_segment
;
3835 check_segment
[1] = -1;
3836 else if (bfd_is_abs_section (sec
)
3837 || bfd_is_und_section (sec
))
3840 check_segment
[1] = tls_segment
;
3842 else if (sec
->output_section
)
3844 relocation
-= tls_biased_base (info
);
3846 _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
);
3849 check_segment
[1] = -1;
3852 case R_FRV_GOTTLSOFF12
:
3853 case R_FRV_GOTTLSOFFHI
:
3854 case R_FRV_GOTTLSOFFLO
:
3855 BFD_ASSERT (picrel
->tlsoff_entry
);
3856 relocation
= picrel
->tlsoff_entry
;
3857 check_segment
[0] = tls_segment
;
3858 check_segment
[1] = sec
3859 && ! bfd_is_abs_section (sec
)
3860 && ! bfd_is_und_section (sec
)
3861 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3865 case R_FRV_TLSDESC_VALUE
:
3867 /* These shouldn't be present in input object files. */
3868 check_segment
[0] = check_segment
[1] = isec_segment
;
3871 case R_FRV_TLSDESC_RELAX
:
3872 case R_FRV_GETTLSOFF_RELAX
:
3873 case R_FRV_TLSOFF_RELAX
:
3874 /* These are just annotations for relaxation, nothing to do
3879 check_segment
[0] = isec_segment
;
3880 check_segment
[1] = sec
3881 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3886 if (check_segment
[0] != check_segment
[1] && IS_FDPIC (output_bfd
))
3888 /* If you take this out, remove the #error from fdpic-static-6.d
3889 in the ld testsuite. */
3890 /* This helps catch problems in GCC while we can't do more
3891 than static linking. The idea is to test whether the
3892 input file basename is crt0.o only once. */
3893 if (silence_segment_error
== 1)
3894 silence_segment_error
=
3895 (strlen (input_bfd
->filename
) == 6
3896 && filename_cmp (input_bfd
->filename
, "crt0.o") == 0)
3897 || (strlen (input_bfd
->filename
) > 6
3898 && filename_cmp (input_bfd
->filename
3899 + strlen (input_bfd
->filename
) - 7,
3902 if (!silence_segment_error
3903 /* We don't want duplicate errors for undefined
3905 && !(picrel
&& picrel
->symndx
== -1
3906 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefined
))
3908 info
->callbacks
->einfo
3909 /* xgettext:c-format */
3910 (_("%H: reloc against `%s' references a different segment\n"),
3911 input_bfd
, input_section
, rel
->r_offset
, name
);
3913 if (!silence_segment_error
&& bfd_link_pic (info
))
3915 elf_elfheader (output_bfd
)->e_flags
|= EF_FRV_PIC
;
3920 case R_FRV_GOTOFFHI
:
3921 case R_FRV_TLSMOFFHI
:
3922 /* We need the addend to be applied before we shift the
3924 relocation
+= rel
->r_addend
;
3927 case R_FRV_FUNCDESC_GOTHI
:
3928 case R_FRV_FUNCDESC_GOTOFFHI
:
3929 case R_FRV_GOTTLSOFFHI
:
3930 case R_FRV_GOTTLSDESCHI
:
3935 case R_FRV_FUNCDESC_GOTLO
:
3936 case R_FRV_GOTOFFLO
:
3937 case R_FRV_FUNCDESC_GOTOFFLO
:
3938 case R_FRV_GOTTLSOFFLO
:
3939 case R_FRV_GOTTLSDESCLO
:
3940 case R_FRV_TLSMOFFLO
:
3941 relocation
&= 0xffff;
3951 if (! IS_FDPIC (output_bfd
) || ! picrel
->plt
)
3955 /* When referencing a GOT entry, a function descriptor or a
3956 PLT, we don't want the addend to apply to the reference,
3957 but rather to the referenced symbol. The actual entry
3958 will have already been created taking the addend into
3959 account, so cancel it out here. */
3963 case R_FRV_FUNCDESC_GOT12
:
3964 case R_FRV_FUNCDESC_GOTHI
:
3965 case R_FRV_FUNCDESC_GOTLO
:
3966 case R_FRV_FUNCDESC_GOTOFF12
:
3967 case R_FRV_FUNCDESC_GOTOFFHI
:
3968 case R_FRV_FUNCDESC_GOTOFFLO
:
3969 case R_FRV_GETTLSOFF
:
3970 case R_FRV_GOTTLSDESC12
:
3971 case R_FRV_GOTTLSDESCHI
:
3972 case R_FRV_GOTTLSDESCLO
:
3973 case R_FRV_GOTTLSOFF12
:
3974 case R_FRV_GOTTLSOFFHI
:
3975 case R_FRV_GOTTLSOFFLO
:
3976 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
3977 here, since we do want to apply the addend to the others.
3978 Note that we've applied the addend to GOTOFFHI before we
3979 shifted it right. */
3980 case R_FRV_GOTOFFHI
:
3981 case R_FRV_TLSMOFFHI
:
3982 relocation
-= rel
->r_addend
;
3989 if (r_type
== R_FRV_HI16
)
3990 r
= elf32_frv_relocate_hi16 (input_bfd
, rel
, contents
, relocation
);
3992 else if (r_type
== R_FRV_LO16
)
3993 r
= elf32_frv_relocate_lo16 (input_bfd
, rel
, contents
, relocation
);
3995 else if (r_type
== R_FRV_LABEL24
|| r_type
== R_FRV_GETTLSOFF
)
3996 r
= elf32_frv_relocate_label24 (input_bfd
, input_section
, rel
,
3997 contents
, relocation
);
3999 else if (r_type
== R_FRV_GPREL12
)
4000 r
= elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, rel
,
4001 contents
, relocation
);
4003 else if (r_type
== R_FRV_GPRELU12
)
4004 r
= elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, rel
,
4005 contents
, relocation
);
4007 else if (r_type
== R_FRV_GPRELLO
)
4008 r
= elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, rel
,
4009 contents
, relocation
);
4011 else if (r_type
== R_FRV_GPRELHI
)
4012 r
= elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, rel
,
4013 contents
, relocation
);
4015 else if (r_type
== R_FRV_TLSOFF
4016 || r_type
== R_FRV_TLSDESC_VALUE
)
4017 r
= bfd_reloc_notsupported
;
4020 r
= frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
4023 if (r
!= bfd_reloc_ok
)
4025 const char * msg
= (const char *) NULL
;
4029 case bfd_reloc_overflow
:
4030 (*info
->callbacks
->reloc_overflow
)
4031 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4032 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
4035 case bfd_reloc_undefined
:
4036 (*info
->callbacks
->undefined_symbol
)
4037 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
4040 case bfd_reloc_outofrange
:
4041 msg
= _("internal error: out of range error");
4044 case bfd_reloc_notsupported
:
4045 msg
= _("internal error: unsupported relocation error");
4048 case bfd_reloc_dangerous
:
4049 msg
= _("internal error: dangerous relocation");
4053 msg
= _("internal error: unknown error");
4059 info
->callbacks
->einfo
4060 /* xgettext:c-format */
4061 (_("%H: reloc against `%s': %s\n"),
4062 input_bfd
, input_section
, rel
->r_offset
, name
, msg
);
4071 /* Return the section that should be marked against GC for a given
4075 elf32_frv_gc_mark_hook (asection
*sec
,
4076 struct bfd_link_info
*info
,
4077 Elf_Internal_Rela
*rel
,
4078 struct elf_link_hash_entry
*h
,
4079 Elf_Internal_Sym
*sym
)
4082 switch (ELF32_R_TYPE (rel
->r_info
))
4084 case R_FRV_GNU_VTINHERIT
:
4085 case R_FRV_GNU_VTENTRY
:
4089 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
4092 /* Hook called by the linker routine which adds symbols from an object
4093 file. We use it to put .comm items in .scomm, and not .comm. */
4096 elf32_frv_add_symbol_hook (bfd
*abfd
,
4097 struct bfd_link_info
*info
,
4098 Elf_Internal_Sym
*sym
,
4099 const char **namep ATTRIBUTE_UNUSED
,
4100 flagword
*flagsp ATTRIBUTE_UNUSED
,
4104 if (sym
->st_shndx
== SHN_COMMON
4105 && !bfd_link_relocatable (info
)
4106 && (int)sym
->st_size
<= (int)bfd_get_gp_size (abfd
))
4108 /* Common symbols less than or equal to -G nn bytes are
4109 automatically put into .sbss. */
4111 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
4115 scomm
= bfd_make_section_with_flags (abfd
, ".scommon",
4118 | SEC_LINKER_CREATED
));
4124 *valp
= sym
->st_size
;
4130 /* We need dynamic symbols for every section, since segments can
4131 relocate independently. */
4133 _frvfdpic_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4134 struct bfd_link_info
*info
4136 asection
*p ATTRIBUTE_UNUSED
)
4138 switch (elf_section_data (p
)->this_hdr
.sh_type
)
4142 /* If sh_type is yet undecided, assume it could be
4143 SHT_PROGBITS/SHT_NOBITS. */
4147 /* There shouldn't be section relative relocations
4148 against any other section. */
4154 /* Create a .got section, as well as its additional info field. This
4155 is almost entirely copied from
4156 elflink.c:_bfd_elf_create_got_section(). */
4159 _frv_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4161 flagword flags
, pltflags
;
4163 struct elf_link_hash_entry
*h
;
4164 struct bfd_link_hash_entry
*bh
;
4165 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4169 /* This function may be called more than once. */
4170 s
= elf_hash_table (info
)->sgot
;
4174 /* Machine specific: although pointers are 32-bits wide, we want the
4175 GOT to be aligned to a 64-bit boundary, such that function
4176 descriptors in it can be accessed with 64-bit loads and
4180 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4181 | SEC_LINKER_CREATED
);
4184 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
4185 elf_hash_table (info
)->sgot
= s
;
4187 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
4190 if (bed
->want_got_sym
)
4192 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
4193 (or .got.plt) section. We don't do this in the linker script
4194 because we don't want to define the symbol if we are not creating
4195 a global offset table. */
4196 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
, "_GLOBAL_OFFSET_TABLE_");
4197 elf_hash_table (info
)->hgot
= h
;
4201 /* Machine-specific: we want the symbol for executables as
4203 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4207 /* The first bit of the global offset table is the header. */
4208 s
->size
+= bed
->got_header_size
;
4210 /* This is the machine-specific part. Create and initialize section
4211 data for the got. */
4212 if (IS_FDPIC (abfd
))
4214 frvfdpic_relocs_info (info
) = htab_try_create (1,
4215 frvfdpic_relocs_info_hash
,
4216 frvfdpic_relocs_info_eq
,
4218 if (! frvfdpic_relocs_info (info
))
4221 s
= bfd_make_section_anyway_with_flags (abfd
, ".rel.got",
4222 (flags
| SEC_READONLY
));
4223 elf_hash_table (info
)->srelgot
= s
;
4225 || ! bfd_set_section_alignment (abfd
, s
, 2))
4228 /* Machine-specific. */
4229 s
= bfd_make_section_anyway_with_flags (abfd
, ".rofixup",
4230 (flags
| SEC_READONLY
));
4232 || ! bfd_set_section_alignment (abfd
, s
, 2))
4235 frvfdpic_gotfixup_section (info
) = s
;
4242 flags
= BSF_GLOBAL
| BSF_WEAK
;
4245 /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it
4246 turns out that we're linking with a different linker script, the
4247 linker script will override it. */
4249 if (!(_bfd_generic_link_add_one_symbol
4250 (info
, abfd
, "_gp", flags
, s
, offset
, (const char *) NULL
, FALSE
,
4251 bed
->collect
, &bh
)))
4253 h
= (struct elf_link_hash_entry
*) bh
;
4255 h
->type
= STT_OBJECT
;
4256 /* h->other = STV_HIDDEN; */ /* Should we? */
4258 /* Machine-specific: we want the symbol for executables as well. */
4259 if (IS_FDPIC (abfd
) && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
4262 if (!IS_FDPIC (abfd
))
4265 /* FDPIC supports Thread Local Storage, and this may require a
4266 procedure linkage table for TLS PLT entries. */
4268 /* This is mostly copied from
4269 elflink.c:_bfd_elf_create_dynamic_sections(). */
4272 pltflags
|= SEC_CODE
;
4273 if (bed
->plt_not_loaded
)
4274 pltflags
&= ~ (SEC_CODE
| SEC_LOAD
| SEC_HAS_CONTENTS
);
4275 if (bed
->plt_readonly
)
4276 pltflags
|= SEC_READONLY
;
4278 s
= bfd_make_section_anyway_with_flags (abfd
, ".plt", pltflags
);
4280 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
4282 /* FRV-specific: remember it. */
4283 frvfdpic_plt_section (info
) = s
;
4285 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
4287 if (bed
->want_plt_sym
)
4289 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
4290 "_PROCEDURE_LINKAGE_TABLE_");
4291 elf_hash_table (info
)->hplt
= h
;
4296 /* FRV-specific: we want rel relocations for the plt. */
4297 s
= bfd_make_section_anyway_with_flags (abfd
, ".rel.plt",
4298 flags
| SEC_READONLY
);
4300 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
4302 /* FRV-specific: remember it. */
4303 frvfdpic_pltrel_section (info
) = s
;
4308 /* Make sure the got and plt sections exist, and that our pointers in
4309 the link hash table point to them. */
4312 elf32_frvfdpic_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
4314 /* This is mostly copied from
4315 elflink.c:_bfd_elf_create_dynamic_sections(). */
4318 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4320 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4321 | SEC_LINKER_CREATED
);
4323 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
4324 .rel[a].bss sections. */
4326 /* FRV-specific: we want to create the GOT and the PLT in the FRV
4328 if (! _frv_create_got_section (abfd
, info
))
4331 /* FRV-specific: make sure we created everything we wanted. */
4332 BFD_ASSERT (frvfdpic_got_section (info
) && frvfdpic_gotrel_section (info
)
4333 && frvfdpic_gotfixup_section (info
)
4334 && frvfdpic_plt_section (info
)
4335 && frvfdpic_pltrel_section (info
));
4337 if (bed
->want_dynbss
)
4339 /* The .dynbss section is a place to put symbols which are defined
4340 by dynamic objects, are referenced by regular objects, and are
4341 not functions. We must allocate space for them in the process
4342 image and use a R_*_COPY reloc to tell the dynamic linker to
4343 initialize them at run time. The linker script puts the .dynbss
4344 section into the .bss section of the final image. */
4345 s
= bfd_make_section_anyway_with_flags (abfd
, ".dynbss",
4346 SEC_ALLOC
| SEC_LINKER_CREATED
);
4350 /* The .rel[a].bss section holds copy relocs. This section is not
4351 normally needed. We need to create it here, though, so that the
4352 linker will map it to an output section. We can't just create it
4353 only if we need it, because we will not know whether we need it
4354 until we have seen all the input files, and the first time the
4355 main linker code calls BFD after examining all the input files
4356 (size_dynamic_sections) the input sections have already been
4357 mapped to the output sections. If the section turns out not to
4358 be needed, we can discard it later. We will never need this
4359 section when generating a shared object, since they do not use
4361 if (! bfd_link_pic (info
))
4363 s
= bfd_make_section_anyway_with_flags (abfd
,
4364 (bed
->default_use_rela_p
4365 ? ".rela.bss" : ".rel.bss"),
4366 flags
| SEC_READONLY
);
4368 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
4376 /* Compute the total GOT and PLT size required by each symbol in each
4377 range. Symbols may require up to 4 words in the GOT: an entry
4378 pointing to the symbol, an entry pointing to its function
4379 descriptor, and a private function descriptors taking two
4383 _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info
*entry
,
4384 struct _frvfdpic_dynamic_got_info
*dinfo
)
4386 /* Allocate space for a GOT entry pointing to the symbol. */
4389 else if (entry
->gotlos
)
4391 else if (entry
->gothilo
)
4392 dinfo
->gothilo
+= 4;
4397 /* Allocate space for a GOT entry pointing to the function
4401 else if (entry
->fdgotlos
)
4403 else if (entry
->fdgothilo
)
4404 dinfo
->gothilo
+= 4;
4409 /* Decide whether we need a PLT entry, a function descriptor in the
4410 GOT, and a lazy PLT entry for this symbol. */
4411 entry
->plt
= entry
->call
4412 && entry
->symndx
== -1 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4413 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
4414 entry
->privfd
= entry
->plt
4415 || entry
->fdgoff12
|| entry
->fdgofflos
|| entry
->fdgoffhilo
4416 || ((entry
->fd
|| entry
->fdgot12
|| entry
->fdgotlos
|| entry
->fdgothilo
)
4417 && (entry
->symndx
!= -1
4418 || FRVFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
)));
4419 entry
->lazyplt
= entry
->privfd
4420 && entry
->symndx
== -1 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4421 && ! (dinfo
->info
->flags
& DF_BIND_NOW
)
4422 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
4424 /* Allocate space for a function descriptor. */
4425 if (entry
->fdgoff12
)
4427 else if (entry
->fdgofflos
)
4429 else if (entry
->privfd
&& entry
->plt
)
4431 else if (entry
->privfd
)
4441 /* Compute the total GOT size required by each TLS symbol in each
4442 range. Symbols may require up to 5 words in the GOT: an entry
4443 holding the TLS offset for the symbol, and an entry with a full TLS
4444 descriptor taking 4 words. */
4447 _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info
*entry
,
4448 struct _frvfdpic_dynamic_got_info
*dinfo
,
4449 bfd_boolean subtract
)
4451 const int l
= subtract
? -1 : 1;
4453 /* Allocate space for a GOT entry with the TLS offset of the
4455 if (entry
->tlsoff12
)
4456 dinfo
->got12
+= 4 * l
;
4457 else if (entry
->tlsofflos
)
4458 dinfo
->gotlos
+= 4 * l
;
4459 else if (entry
->tlsoffhilo
)
4460 dinfo
->gothilo
+= 4 * l
;
4462 entry
->relocstlsoff
-= l
;
4463 entry
->relocstlsoff
+= l
;
4465 /* If there's any TLSOFF relocation, mark the output file as not
4466 suitable for dlopening. This mark will remain even if we relax
4467 all such relocations, but this is not a problem, since we'll only
4468 do so for executables, and we definitely don't want anyone
4469 dlopening executables. */
4470 if (entry
->relocstlsoff
)
4471 dinfo
->info
->flags
|= DF_STATIC_TLS
;
4473 /* Allocate space for a TLS descriptor. */
4474 if (entry
->tlsdesc12
)
4475 dinfo
->tlsd12
+= 8 * l
;
4476 else if (entry
->tlsdesclos
)
4477 dinfo
->tlsdlos
+= 8 * l
;
4478 else if (entry
->tlsplt
)
4479 dinfo
->tlsdplt
+= 8 * l
;
4480 else if (entry
->tlsdeschilo
)
4481 dinfo
->tlsdhilo
+= 8 * l
;
4483 entry
->relocstlsd
-= l
;
4484 entry
->relocstlsd
+= l
;
4487 /* Compute the number of dynamic relocations and fixups that a symbol
4488 requires, and add (or subtract) from the grand and per-symbol
4492 _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info
*entry
,
4493 struct _frvfdpic_dynamic_got_info
*dinfo
,
4494 bfd_boolean subtract
)
4496 bfd_vma relocs
= 0, fixups
= 0, tlsrets
= 0;
4498 if (!bfd_link_pde (dinfo
->info
))
4500 relocs
= entry
->relocs32
+ entry
->relocsfd
+ entry
->relocsfdv
4501 + entry
->relocstlsd
;
4503 /* In the executable, TLS relocations to symbols that bind
4504 locally (including those that resolve to global TLS offsets)
4505 are resolved immediately, without any need for fixups or
4506 dynamic relocations. In shared libraries, however, we must
4507 emit dynamic relocations even for local symbols, because we
4508 don't know the module id the library is going to get at
4509 run-time, nor its TLS base offset. */
4510 if (!bfd_link_executable (dinfo
->info
)
4511 || (entry
->symndx
== -1
4512 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)))
4513 relocs
+= entry
->relocstlsoff
;
4517 if (entry
->symndx
!= -1 || FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
))
4519 if (entry
->symndx
!= -1
4520 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
4521 fixups
+= entry
->relocs32
+ 2 * entry
->relocsfdv
;
4522 fixups
+= entry
->relocstlsd
;
4523 tlsrets
+= entry
->relocstlsd
;
4527 relocs
+= entry
->relocs32
+ entry
->relocsfdv
4528 + entry
->relocstlsoff
+ entry
->relocstlsd
;
4531 if (entry
->symndx
!= -1
4532 || FRVFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
))
4534 if (entry
->symndx
!= -1
4535 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
4536 fixups
+= entry
->relocsfd
;
4539 relocs
+= entry
->relocsfd
;
4546 tlsrets
= - tlsrets
;
4549 entry
->dynrelocs
+= relocs
;
4550 entry
->fixups
+= fixups
;
4551 dinfo
->relocs
+= relocs
;
4552 dinfo
->fixups
+= fixups
;
4553 dinfo
->tls_ret_refs
+= tlsrets
;
4556 /* Look for opportunities to relax TLS relocations. We can assume
4557 we're linking the main executable or a static-tls library, since
4558 otherwise we wouldn't have got here. When relaxing, we have to
4559 first undo any previous accounting of TLS uses of fixups, dynamic
4560 relocations, GOT and PLT entries. */
4563 _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info
*entry
,
4564 struct _frvfdpic_dynamic_got_info
*dinfo
,
4565 bfd_boolean relaxing
)
4567 bfd_boolean changed
= ! relaxing
;
4569 BFD_ASSERT (bfd_link_executable (dinfo
->info
)
4570 || (dinfo
->info
->flags
& DF_STATIC_TLS
));
4572 if (entry
->tlsdesc12
|| entry
->tlsdesclos
|| entry
->tlsdeschilo
)
4576 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4577 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4581 /* When linking an executable, we can always decay GOTTLSDESC to
4582 TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise.
4583 When linking a static-tls shared library, using TLSMOFF is
4584 not an option, but we can still use GOTTLSOFF. When decaying
4585 to GOTTLSOFF, we must keep the GOT entry in range. We know
4586 it has to fit because we'll be trading the 4 words of hte TLS
4587 descriptor for a single word in the same range. */
4588 if (! bfd_link_executable (dinfo
->info
)
4589 || (entry
->symndx
== -1
4590 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)))
4592 entry
->tlsoff12
|= entry
->tlsdesc12
;
4593 entry
->tlsofflos
|= entry
->tlsdesclos
;
4594 entry
->tlsoffhilo
|= entry
->tlsdeschilo
;
4597 entry
->tlsdesc12
= entry
->tlsdesclos
= entry
->tlsdeschilo
= 0;
4600 /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the
4601 main executable. We have to check whether the symbol's TLSOFF is
4602 in range for a setlos. For symbols with a hash entry, we can
4603 determine exactly what to do; for others locals, we don't have
4604 addresses handy, so we use the size of the TLS section as an
4605 approximation. If we get it wrong, we'll retain a GOT entry
4606 holding the TLS offset (without dynamic relocations or fixups),
4607 but we'll still optimize away the loads from it. Since TLS sizes
4608 are generally very small, it's probably not worth attempting to
4609 do better than this. */
4611 || entry
->tlsoff12
|| entry
->tlsofflos
|| entry
->tlsoffhilo
)
4612 && bfd_link_executable (dinfo
->info
) && relaxing
4613 && ((entry
->symndx
== -1
4614 && FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4615 /* The above may hold for an undefweak TLS symbol, so make
4616 sure we don't have this case before accessing def.value
4618 && (entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
4619 || (bfd_vma
)(entry
->d
.h
->root
.u
.def
.value
4620 + (entry
->d
.h
->root
.u
.def
.section
4621 ->output_section
->vma
)
4622 + entry
->d
.h
->root
.u
.def
.section
->output_offset
4624 - tls_biased_base (dinfo
->info
)
4625 + 32768) < (bfd_vma
)65536))
4626 || (entry
->symndx
!= -1
4627 && (elf_hash_table (dinfo
->info
)->tls_sec
->size
4628 + entry
->addend
< 32768 + FRVFDPIC_TLS_BIAS
))))
4632 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4633 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4638 entry
->tlsoff12
= entry
->tlsofflos
= entry
->tlsoffhilo
= 0;
4641 /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already
4642 have a #gottlsoff12 relocation for this entry, or if we can fit
4643 one more in the 12-bit (and 16-bit) ranges. */
4647 && dinfo
->got12
+ dinfo
->fd12
+ dinfo
->tlsd12
<= 4096 - 12 - 4
4648 && (dinfo
->got12
+ dinfo
->fd12
+ dinfo
->tlsd12
4649 + dinfo
->gotlos
+ dinfo
->fdlos
+ dinfo
->tlsdlos
4650 <= 65536 - 12 - 4))))
4654 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4655 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4659 entry
->tlsoff12
= 1;
4665 _frvfdpic_count_tls_entries (entry
, dinfo
, FALSE
);
4666 _frvfdpic_count_relocs_fixups (entry
, dinfo
, FALSE
);
4672 /* Compute the total GOT and PLT size required by each symbol in each range. *
4673 Symbols may require up to 4 words in the GOT: an entry pointing to
4674 the symbol, an entry pointing to its function descriptor, and a
4675 private function descriptors taking two words. */
4678 _frvfdpic_count_got_plt_entries (void **entryp
, void *dinfo_
)
4680 struct frvfdpic_relocs_info
*entry
= *entryp
;
4681 struct _frvfdpic_dynamic_got_info
*dinfo
= dinfo_
;
4683 _frvfdpic_count_nontls_entries (entry
, dinfo
);
4685 if (bfd_link_executable (dinfo
->info
)
4686 || (dinfo
->info
->flags
& DF_STATIC_TLS
))
4687 _frvfdpic_relax_tls_entries (entry
, dinfo
, FALSE
);
4690 _frvfdpic_count_tls_entries (entry
, dinfo
, FALSE
);
4691 _frvfdpic_count_relocs_fixups (entry
, dinfo
, FALSE
);
4697 /* Determine the positive and negative ranges to be used by each
4698 offset range in the GOT. FDCUR and CUR, that must be aligned to a
4699 double-word boundary, are the minimum (negative) and maximum
4700 (positive) GOT offsets already used by previous ranges, except for
4701 an ODD entry that may have been left behind. GOT and FD indicate
4702 the size of GOT entries and function descriptors that must be
4703 placed within the range from -WRAP to WRAP. If there's room left,
4704 up to FDPLT bytes should be reserved for additional function
4707 inline static bfd_signed_vma
4708 _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data
*gad
,
4709 bfd_signed_vma fdcur
,
4719 bfd_signed_vma wrapmin
= -wrap
;
4720 const bfd_vma tdescsz
= 8;
4722 /* Start at the given initial points. */
4726 /* If we had an incoming odd word and we have any got entries that
4727 are going to use it, consume it, otherwise leave gad->odd at
4728 zero. We might force gad->odd to zero and return the incoming
4729 odd such that it is used by the next range, but then GOT entries
4730 might appear to be out of order and we wouldn't be able to
4731 shorten the GOT by one word if it turns out to end with an
4732 unpaired GOT entry. */
4742 /* If we're left with an unpaired GOT entry, compute its location
4743 such that we can return it. Otherwise, if got doesn't require an
4744 odd number of words here, either odd was already zero in the
4745 block above, or it was set to zero because got was non-zero, or
4746 got was already zero. In the latter case, we want the value of
4747 odd to carry over to the return statement, so we don't want to
4748 reset odd unless the condition below is true. */
4755 /* Compute the tentative boundaries of this range. */
4756 gad
->max
= cur
+ got
;
4757 gad
->min
= fdcur
- fd
;
4760 /* If function descriptors took too much space, wrap some of them
4762 if (gad
->min
< wrapmin
)
4764 gad
->max
+= wrapmin
- gad
->min
;
4765 gad
->tmin
= gad
->min
= wrapmin
;
4768 /* If GOT entries took too much space, wrap some of them around.
4769 This may well cause gad->min to become lower than wrapmin. This
4770 will cause a relocation overflow later on, so we don't have to
4772 if ((bfd_vma
) gad
->max
> wrap
)
4774 gad
->min
-= gad
->max
- wrap
;
4778 /* Add TLS descriptors. */
4779 gad
->tmax
= gad
->max
+ tlsd
;
4780 gad
->tmin
= gad
->min
;
4783 /* If TLS descriptors took too much space, wrap an integral number
4785 if ((bfd_vma
) gad
->tmax
> wrap
)
4787 bfd_vma wrapsize
= gad
->tmax
- wrap
;
4789 wrapsize
+= tdescsz
/ 2;
4790 wrapsize
&= ~ tdescsz
/ 2;
4792 gad
->tmin
-= wrapsize
;
4793 gad
->tmax
-= wrapsize
;
4796 /* If there is space left and we have function descriptors
4797 referenced in PLT entries that could take advantage of shorter
4798 offsets, place them now. */
4799 if (fdplt
&& gad
->tmin
> wrapmin
)
4803 if ((bfd_vma
) (gad
->tmin
- wrapmin
) < fdplt
)
4804 fds
= gad
->tmin
- wrapmin
;
4814 /* If there is more space left, try to place some more function
4815 descriptors for PLT entries. */
4816 if (fdplt
&& (bfd_vma
) gad
->tmax
< wrap
)
4820 if ((bfd_vma
) (wrap
- gad
->tmax
) < fdplt
)
4821 fds
= wrap
- gad
->tmax
;
4831 /* If there is space left and we have TLS descriptors referenced in
4832 PLT entries that could take advantage of shorter offsets, place
4834 if (tlsdplt
&& gad
->tmin
> wrapmin
)
4838 if ((bfd_vma
) (gad
->tmin
- wrapmin
) < tlsdplt
)
4839 tlsds
= (gad
->tmin
- wrapmin
) & ~ (tdescsz
/ 2);
4845 gad
->tlsdplt
+= tlsds
;
4848 /* If there is more space left, try to place some more TLS
4849 descriptors for PLT entries. Although we could try to fit an
4850 additional TLS descriptor with half of it just before before the
4851 wrap point and another right past the wrap point, this might
4852 cause us to run out of space for the next region, so don't do
4854 if (tlsdplt
&& (bfd_vma
) gad
->tmax
< wrap
- tdescsz
/ 2)
4858 if ((bfd_vma
) (wrap
- gad
->tmax
) < tlsdplt
)
4859 tlsds
= (wrap
- gad
->tmax
) & ~ (tdescsz
/ 2);
4865 gad
->tlsdplt
+= tlsds
;
4868 /* If odd was initially computed as an offset past the wrap point,
4871 odd
= gad
->min
+ odd
- gad
->max
;
4873 /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed
4874 before returning, so do it here too. This guarantees that,
4875 should cur and fdcur meet at the wrap point, they'll both be
4877 if (gad
->cur
== gad
->max
)
4878 gad
->cur
= gad
->min
;
4880 /* Ditto for _frvfdpic_get_tlsdesc_entry(). */
4881 gad
->tcur
= gad
->max
;
4882 if (gad
->tcur
== gad
->tmax
)
4883 gad
->tcur
= gad
->tmin
;
4888 /* Compute the location of the next GOT entry, given the allocation
4889 data for a range. */
4891 inline static bfd_signed_vma
4892 _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
4898 /* If there was an odd word left behind, use it. */
4904 /* Otherwise, use the word pointed to by cur, reserve the next
4905 as an odd word, and skip to the next pair of words, possibly
4908 gad
->odd
= gad
->cur
+ 4;
4910 if (gad
->cur
== gad
->max
)
4911 gad
->cur
= gad
->min
;
4917 /* Compute the location of the next function descriptor entry in the
4918 GOT, given the allocation data for a range. */
4920 inline static bfd_signed_vma
4921 _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
4923 /* If we're at the bottom, wrap around, and only then allocate the
4924 next pair of words. */
4925 if (gad
->fdcur
== gad
->min
)
4926 gad
->fdcur
= gad
->max
;
4927 return gad
->fdcur
-= 8;
4930 /* Compute the location of the next TLS descriptor entry in the GOT,
4931 given the allocation data for a range. */
4932 inline static bfd_signed_vma
4933 _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
4941 /* If we're at the top of the region, wrap around to the bottom. */
4942 if (gad
->tcur
== gad
->tmax
)
4943 gad
->tcur
= gad
->tmin
;
4948 /* Assign GOT offsets for every GOT entry and function descriptor.
4949 Doing everything in a single pass is tricky. */
4952 _frvfdpic_assign_got_entries (void **entryp
, void *info_
)
4954 struct frvfdpic_relocs_info
*entry
= *entryp
;
4955 struct _frvfdpic_dynamic_got_plt_info
*dinfo
= info_
;
4958 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
4959 else if (entry
->gotlos
)
4960 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
4961 else if (entry
->gothilo
)
4962 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
4965 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
4966 else if (entry
->fdgotlos
)
4967 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
4968 else if (entry
->fdgothilo
)
4969 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
4971 if (entry
->fdgoff12
)
4972 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->got12
);
4973 else if (entry
->plt
&& dinfo
->got12
.fdplt
)
4975 dinfo
->got12
.fdplt
-= 8;
4976 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->got12
);
4978 else if (entry
->fdgofflos
)
4979 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gotlos
);
4980 else if (entry
->plt
&& dinfo
->gotlos
.fdplt
)
4982 dinfo
->gotlos
.fdplt
-= 8;
4983 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gotlos
);
4985 else if (entry
->plt
)
4987 dinfo
->gothilo
.fdplt
-= 8;
4988 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gothilo
);
4990 else if (entry
->privfd
)
4991 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gothilo
);
4993 if (entry
->tlsoff12
)
4994 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
4995 else if (entry
->tlsofflos
)
4996 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
4997 else if (entry
->tlsoffhilo
)
4998 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5000 if (entry
->tlsdesc12
)
5001 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->got12
);
5002 else if (entry
->tlsplt
&& dinfo
->got12
.tlsdplt
)
5004 dinfo
->got12
.tlsdplt
-= 8;
5005 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->got12
);
5007 else if (entry
->tlsdesclos
)
5008 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gotlos
);
5009 else if (entry
->tlsplt
&& dinfo
->gotlos
.tlsdplt
)
5011 dinfo
->gotlos
.tlsdplt
-= 8;
5012 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gotlos
);
5014 else if (entry
->tlsplt
)
5016 dinfo
->gothilo
.tlsdplt
-= 8;
5017 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gothilo
);
5019 else if (entry
->tlsdeschilo
)
5020 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gothilo
);
5025 /* Assign GOT offsets to private function descriptors used by PLT
5026 entries (or referenced by 32-bit offsets), as well as PLT entries
5027 and lazy PLT entries. */
5030 _frvfdpic_assign_plt_entries (void **entryp
, void *info_
)
5032 struct frvfdpic_relocs_info
*entry
= *entryp
;
5033 struct _frvfdpic_dynamic_got_plt_info
*dinfo
= info_
;
5036 BFD_ASSERT (entry
->fd_entry
);
5042 /* We use the section's raw size to mark the location of the
5044 entry
->plt_entry
= frvfdpic_plt_section (dinfo
->g
.info
)->size
;
5046 /* Figure out the length of this PLT entry based on the
5047 addressing mode we need to reach the function descriptor. */
5048 BFD_ASSERT (entry
->fd_entry
);
5049 if (entry
->fd_entry
>= -(1 << (12 - 1))
5050 && entry
->fd_entry
< (1 << (12 - 1)))
5052 else if (entry
->fd_entry
>= -(1 << (16 - 1))
5053 && entry
->fd_entry
< (1 << (16 - 1)))
5058 frvfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
5063 entry
->lzplt_entry
= dinfo
->g
.lzplt
;
5064 dinfo
->g
.lzplt
+= 8;
5065 /* If this entry is the one that gets the resolver stub, account
5066 for the additional instruction. */
5067 if (entry
->lzplt_entry
% FRVFDPIC_LZPLT_BLOCK_SIZE
5068 == FRVFDPIC_LZPLT_RESOLV_LOC
)
5069 dinfo
->g
.lzplt
+= 4;
5077 = frvfdpic_plt_section (dinfo
->g
.info
)->size
;
5079 if (bfd_link_executable (dinfo
->g
.info
)
5080 && (entry
->symndx
!= -1
5081 || FRVFDPIC_SYM_LOCAL (dinfo
->g
.info
, entry
->d
.h
)))
5083 if ((bfd_signed_vma
)entry
->addend
>= -(1 << (16 - 1))
5084 /* FIXME: here we use the size of the TLS section
5085 as an upper bound for the value of the TLS
5086 symbol, because we may not know the exact value
5087 yet. If we get it wrong, we'll just waste a
5088 word in the PLT, and we should never get even
5089 close to 32 KiB of TLS anyway. */
5090 && elf_hash_table (dinfo
->g
.info
)->tls_sec
5091 && (elf_hash_table (dinfo
->g
.info
)->tls_sec
->size
5092 + (bfd_signed_vma
)(entry
->addend
) <= (1 << (16 - 1))))
5097 else if (entry
->tlsoff_entry
)
5099 if (entry
->tlsoff_entry
>= -(1 << (12 - 1))
5100 && entry
->tlsoff_entry
< (1 << (12 - 1)))
5102 else if (entry
->tlsoff_entry
>= -(1 << (16 - 1))
5103 && entry
->tlsoff_entry
< (1 << (16 - 1)))
5110 BFD_ASSERT (entry
->tlsdesc_entry
);
5112 if (entry
->tlsdesc_entry
>= -(1 << (12 - 1))
5113 && entry
->tlsdesc_entry
< (1 << (12 - 1)))
5115 else if (entry
->tlsdesc_entry
>= -(1 << (16 - 1))
5116 && entry
->tlsdesc_entry
< (1 << (16 - 1)))
5122 frvfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
5128 /* Cancel out any effects of calling _frvfdpic_assign_got_entries and
5129 _frvfdpic_assign_plt_entries. */
5132 _frvfdpic_reset_got_plt_entries (void **entryp
, void *ignore ATTRIBUTE_UNUSED
)
5134 struct frvfdpic_relocs_info
*entry
= *entryp
;
5136 entry
->got_entry
= 0;
5137 entry
->fdgot_entry
= 0;
5138 entry
->fd_entry
= 0;
5139 entry
->plt_entry
= (bfd_vma
)-1;
5140 entry
->lzplt_entry
= (bfd_vma
)-1;
5141 entry
->tlsoff_entry
= 0;
5142 entry
->tlsdesc_entry
= 0;
5143 entry
->tlsplt_entry
= (bfd_vma
)-1;
5148 /* Follow indirect and warning hash entries so that each got entry
5149 points to the final symbol definition. P must point to a pointer
5150 to the hash table we're traversing. Since this traversal may
5151 modify the hash table, we set this pointer to NULL to indicate
5152 we've made a potentially-destructive change to the hash table, so
5153 the traversal must be restarted. */
5155 _frvfdpic_resolve_final_relocs_info (void **entryp
, void *p
)
5157 struct frvfdpic_relocs_info
*entry
= *entryp
;
5160 if (entry
->symndx
== -1)
5162 struct elf_link_hash_entry
*h
= entry
->d
.h
;
5163 struct frvfdpic_relocs_info
*oentry
;
5165 while (h
->root
.type
== bfd_link_hash_indirect
5166 || h
->root
.type
== bfd_link_hash_warning
)
5167 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
5169 if (entry
->d
.h
== h
)
5172 oentry
= frvfdpic_relocs_info_for_global (*htab
, 0, h
, entry
->addend
,
5177 /* Merge the two entries. */
5178 frvfdpic_pic_merge_early_relocs_info (oentry
, entry
);
5179 htab_clear_slot (*htab
, entryp
);
5185 /* If we can't find this entry with the new bfd hash, re-insert
5186 it, and get the traversal restarted. */
5187 if (! htab_find (*htab
, entry
))
5189 htab_clear_slot (*htab
, entryp
);
5190 entryp
= htab_find_slot (*htab
, entry
, INSERT
);
5193 /* Abort the traversal, since the whole table may have
5194 moved, and leave it up to the parent to restart the
5196 *(htab_t
*)p
= NULL
;
5204 /* Compute the total size of the GOT, the PLT, the dynamic relocations
5205 section and the rofixup section. Assign locations for GOT and PLT
5209 _frvfdpic_size_got_plt (bfd
*output_bfd
,
5210 struct _frvfdpic_dynamic_got_plt_info
*gpinfop
)
5213 bfd_vma limit
, tlslimit
;
5214 struct bfd_link_info
*info
= gpinfop
->g
.info
;
5215 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
5217 memcpy (frvfdpic_dynamic_got_plt_info (info
), &gpinfop
->g
,
5218 sizeof (gpinfop
->g
));
5221 /* Compute the total size taken by entries in the 12-bit and 16-bit
5222 ranges, to tell how many PLT function descriptors we can bring
5223 into the 12-bit range without causing the 16-bit range to
5225 limit
= odd
+ gpinfop
->g
.got12
+ gpinfop
->g
.gotlos
5226 + gpinfop
->g
.fd12
+ gpinfop
->g
.fdlos
5227 + gpinfop
->g
.tlsd12
+ gpinfop
->g
.tlsdlos
;
5228 if (limit
< (bfd_vma
)1 << 16)
5229 limit
= ((bfd_vma
)1 << 16) - limit
;
5232 if (gpinfop
->g
.fdplt
< limit
)
5234 tlslimit
= (limit
- gpinfop
->g
.fdplt
) & ~ (bfd_vma
) 8;
5235 limit
= gpinfop
->g
.fdplt
;
5239 if (gpinfop
->g
.tlsdplt
< tlslimit
)
5240 tlslimit
= gpinfop
->g
.tlsdplt
;
5242 /* Determine the ranges of GOT offsets that we can use for each
5243 range of addressing modes. */
5244 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->got12
,
5253 (bfd_vma
)1 << (12-1));
5254 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->gotlos
,
5255 gpinfop
->got12
.tmin
,
5257 gpinfop
->got12
.tmax
,
5261 - gpinfop
->got12
.fdplt
,
5264 - gpinfop
->got12
.tlsdplt
,
5265 (bfd_vma
)1 << (16-1));
5266 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->gothilo
,
5267 gpinfop
->gotlos
.tmin
,
5269 gpinfop
->gotlos
.tmax
,
5273 - gpinfop
->got12
.fdplt
5274 - gpinfop
->gotlos
.fdplt
,
5275 gpinfop
->g
.tlsdhilo
,
5277 - gpinfop
->got12
.tlsdplt
5278 - gpinfop
->gotlos
.tlsdplt
,
5279 (bfd_vma
)1 << (32-1));
5281 /* Now assign (most) GOT offsets. */
5282 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_assign_got_entries
,
5285 frvfdpic_got_section (info
)->size
= gpinfop
->gothilo
.tmax
5286 - gpinfop
->gothilo
.tmin
5287 /* If an odd word is the last word of the GOT, we don't need this
5288 word to be part of the GOT. */
5289 - (odd
+ 4 == gpinfop
->gothilo
.tmax
? 4 : 0);
5290 if (frvfdpic_got_section (info
)->size
== 0)
5291 frvfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
5292 else if (frvfdpic_got_section (info
)->size
== 12
5293 && ! elf_hash_table (info
)->dynamic_sections_created
)
5295 frvfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
5296 frvfdpic_got_section (info
)->size
= 0;
5298 /* This will be non-NULL during relaxation. The assumption is that
5299 the size of one of these sections will never grow, only shrink,
5300 so we can use the larger buffer we allocated before. */
5301 else if (frvfdpic_got_section (info
)->contents
== NULL
)
5303 frvfdpic_got_section (info
)->contents
=
5304 (bfd_byte
*) bfd_zalloc (dynobj
,
5305 frvfdpic_got_section (info
)->size
);
5306 if (frvfdpic_got_section (info
)->contents
== NULL
)
5310 if (frvfdpic_gotrel_section (info
))
5311 /* Subtract the number of lzplt entries, since those will generate
5312 relocations in the pltrel section. */
5313 frvfdpic_gotrel_section (info
)->size
=
5314 (gpinfop
->g
.relocs
- gpinfop
->g
.lzplt
/ 8)
5315 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
5317 BFD_ASSERT (gpinfop
->g
.relocs
== 0);
5318 if (frvfdpic_gotrel_section (info
)->size
== 0)
5319 frvfdpic_gotrel_section (info
)->flags
|= SEC_EXCLUDE
;
5320 else if (frvfdpic_gotrel_section (info
)->contents
== NULL
)
5322 frvfdpic_gotrel_section (info
)->contents
=
5323 (bfd_byte
*) bfd_zalloc (dynobj
,
5324 frvfdpic_gotrel_section (info
)->size
);
5325 if (frvfdpic_gotrel_section (info
)->contents
== NULL
)
5329 frvfdpic_gotfixup_section (info
)->size
= (gpinfop
->g
.fixups
+ 1) * 4;
5330 if (frvfdpic_gotfixup_section (info
)->size
== 0)
5331 frvfdpic_gotfixup_section (info
)->flags
|= SEC_EXCLUDE
;
5332 else if (frvfdpic_gotfixup_section (info
)->contents
== NULL
)
5334 frvfdpic_gotfixup_section (info
)->contents
=
5335 (bfd_byte
*) bfd_zalloc (dynobj
,
5336 frvfdpic_gotfixup_section (info
)->size
);
5337 if (frvfdpic_gotfixup_section (info
)->contents
== NULL
)
5341 if (frvfdpic_pltrel_section (info
))
5343 frvfdpic_pltrel_section (info
)->size
=
5344 gpinfop
->g
.lzplt
/ 8
5345 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
5346 if (frvfdpic_pltrel_section (info
)->size
== 0)
5347 frvfdpic_pltrel_section (info
)->flags
|= SEC_EXCLUDE
;
5348 else if (frvfdpic_pltrel_section (info
)->contents
== NULL
)
5350 frvfdpic_pltrel_section (info
)->contents
=
5351 (bfd_byte
*) bfd_zalloc (dynobj
,
5352 frvfdpic_pltrel_section (info
)->size
);
5353 if (frvfdpic_pltrel_section (info
)->contents
== NULL
)
5358 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
5359 such that there's room for the additional instruction needed to
5360 call the resolver. Since _frvfdpic_assign_got_entries didn't
5361 account for them, our block size is 4 bytes smaller than the real
5363 if (frvfdpic_plt_section (info
))
5365 frvfdpic_plt_section (info
)->size
= gpinfop
->g
.lzplt
5366 + ((gpinfop
->g
.lzplt
+ (FRVFDPIC_LZPLT_BLOCK_SIZE
- 4) - 8)
5367 / (FRVFDPIC_LZPLT_BLOCK_SIZE
- 4) * 4);
5370 /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to
5371 actually assign lazy PLT entries addresses. */
5372 gpinfop
->g
.lzplt
= 0;
5374 /* Save information that we're going to need to generate GOT and PLT
5376 frvfdpic_got_initial_offset (info
) = -gpinfop
->gothilo
.tmin
;
5378 if (get_elf_backend_data (output_bfd
)->want_got_sym
)
5379 elf_hash_table (info
)->hgot
->root
.u
.def
.value
5380 = frvfdpic_got_initial_offset (info
);
5382 if (frvfdpic_plt_section (info
))
5383 frvfdpic_plt_initial_offset (info
) =
5384 frvfdpic_plt_section (info
)->size
;
5386 /* Allocate a ret statement at plt_initial_offset, to be used by
5387 locally-resolved TLS descriptors. */
5388 if (gpinfop
->g
.tls_ret_refs
)
5389 frvfdpic_plt_section (info
)->size
+= 4;
5391 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_assign_plt_entries
,
5394 /* Allocate the PLT section contents only after
5395 _frvfdpic_assign_plt_entries has a chance to add the size of the
5396 non-lazy PLT entries. */
5397 if (frvfdpic_plt_section (info
))
5399 if (frvfdpic_plt_section (info
)->size
== 0)
5400 frvfdpic_plt_section (info
)->flags
|= SEC_EXCLUDE
;
5401 else if (frvfdpic_plt_section (info
)->contents
== NULL
)
5403 frvfdpic_plt_section (info
)->contents
=
5404 (bfd_byte
*) bfd_zalloc (dynobj
,
5405 frvfdpic_plt_section (info
)->size
);
5406 if (frvfdpic_plt_section (info
)->contents
== NULL
)
5414 /* Set the sizes of the dynamic sections. */
5417 elf32_frvfdpic_size_dynamic_sections (bfd
*output_bfd
,
5418 struct bfd_link_info
*info
)
5422 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5424 dynobj
= elf_hash_table (info
)->dynobj
;
5425 BFD_ASSERT (dynobj
!= NULL
);
5427 if (elf_hash_table (info
)->dynamic_sections_created
)
5429 /* Set the contents of the .interp section to the interpreter. */
5430 if (bfd_link_executable (info
) && !info
->nointerp
)
5432 s
= bfd_get_linker_section (dynobj
, ".interp");
5433 BFD_ASSERT (s
!= NULL
);
5434 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5435 s
->contents
= (bfd_byte
*) ELF_DYNAMIC_INTERPRETER
;
5439 memset (&gpinfo
, 0, sizeof (gpinfo
));
5440 gpinfo
.g
.info
= info
;
5444 htab_t relocs
= frvfdpic_relocs_info (info
);
5446 htab_traverse (relocs
, _frvfdpic_resolve_final_relocs_info
, &relocs
);
5448 if (relocs
== frvfdpic_relocs_info (info
))
5452 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_count_got_plt_entries
,
5455 /* Allocate space to save the summary information, we're going to
5456 use it if we're doing relaxations. */
5457 frvfdpic_dynamic_got_plt_info (info
) = bfd_alloc (dynobj
, sizeof (gpinfo
.g
));
5459 if (!_frvfdpic_size_got_plt (output_bfd
, &gpinfo
))
5462 if (elf_hash_table (info
)->dynamic_sections_created
)
5464 if (frvfdpic_got_section (info
)->size
)
5465 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTGOT
, 0))
5468 if (frvfdpic_pltrel_section (info
)->size
)
5469 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
5470 || !_bfd_elf_add_dynamic_entry (info
, DT_PLTREL
, DT_REL
)
5471 || !_bfd_elf_add_dynamic_entry (info
, DT_JMPREL
, 0))
5474 if (frvfdpic_gotrel_section (info
)->size
)
5475 if (!_bfd_elf_add_dynamic_entry (info
, DT_REL
, 0)
5476 || !_bfd_elf_add_dynamic_entry (info
, DT_RELSZ
, 0)
5477 || !_bfd_elf_add_dynamic_entry (info
, DT_RELENT
,
5478 sizeof (Elf32_External_Rel
)))
5486 elf32_frvfdpic_always_size_sections (bfd
*output_bfd
,
5487 struct bfd_link_info
*info
)
5489 if (!bfd_link_relocatable (info
)
5490 && !bfd_elf_stack_segment_size (output_bfd
, info
,
5491 "__stacksize", DEFAULT_STACK_SIZE
))
5497 /* Check whether any of the relocations was optimized away, and
5498 subtract it from the relocation or fixup count. */
5500 _frvfdpic_check_discarded_relocs (bfd
*abfd
, asection
*sec
,
5501 struct bfd_link_info
*info
,
5503 bfd_boolean
*changed
)
5505 Elf_Internal_Shdr
*symtab_hdr
;
5506 struct elf_link_hash_entry
**sym_hashes
;
5507 Elf_Internal_Rela
*rel
, *erel
;
5509 if ((sec
->flags
& SEC_RELOC
) == 0
5510 || sec
->reloc_count
== 0)
5513 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5514 sym_hashes
= elf_sym_hashes (abfd
);
5516 rel
= elf_section_data (sec
)->relocs
;
5518 /* Now examine each relocation. */
5519 for (erel
= rel
+ sec
->reloc_count
; rel
< erel
; rel
++)
5521 struct elf_link_hash_entry
*h
;
5522 unsigned long r_symndx
;
5523 struct frvfdpic_relocs_info
*picrel
;
5524 struct _frvfdpic_dynamic_got_info
*dinfo
;
5526 if (ELF32_R_TYPE (rel
->r_info
) != R_FRV_32
5527 && ELF32_R_TYPE (rel
->r_info
) != R_FRV_FUNCDESC
)
5530 if (_bfd_elf_section_offset (sec
->output_section
->owner
,
5531 info
, sec
, rel
->r_offset
)
5535 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5536 if (r_symndx
< symtab_hdr
->sh_info
)
5540 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5541 while (h
->root
.type
== bfd_link_hash_indirect
5542 || h
->root
.type
== bfd_link_hash_warning
)
5543 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
5547 picrel
= frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info
),
5549 rel
->r_addend
, NO_INSERT
);
5551 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info (info
),
5553 rel
->r_addend
, NO_INSERT
);
5559 dinfo
= frvfdpic_dynamic_got_plt_info (info
);
5561 _frvfdpic_count_relocs_fixups (picrel
, dinfo
, TRUE
);
5562 if (ELF32_R_TYPE (rel
->r_info
) == R_FRV_32
)
5564 else /* we know (ELF32_R_TYPE (rel->r_info) == R_FRV_FUNCDESC) */
5566 _frvfdpic_count_relocs_fixups (picrel
, dinfo
, FALSE
);
5573 frvfdpic_elf_discard_info (bfd
*ibfd
,
5574 struct elf_reloc_cookie
*cookie ATTRIBUTE_UNUSED
,
5575 struct bfd_link_info
*info
)
5577 bfd_boolean changed
= FALSE
;
5581 /* Account for relaxation of .eh_frame section. */
5582 for (s
= ibfd
->sections
; s
; s
= s
->next
)
5583 if (s
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
5585 if (!_frvfdpic_check_discarded_relocs (ibfd
, s
, info
, &changed
))
5587 obfd
= s
->output_section
->owner
;
5592 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5594 memset (&gpinfo
, 0, sizeof (gpinfo
));
5595 memcpy (&gpinfo
.g
, frvfdpic_dynamic_got_plt_info (info
),
5598 /* Clear GOT and PLT assignments. */
5599 htab_traverse (frvfdpic_relocs_info (info
),
5600 _frvfdpic_reset_got_plt_entries
,
5603 if (!_frvfdpic_size_got_plt (obfd
, &gpinfo
))
5610 /* Look for opportunities to relax TLS relocations. We can assume
5611 we're linking the main executable or a static-tls library, since
5612 otherwise we wouldn't have got here. */
5615 _frvfdpic_relax_got_plt_entries (void **entryp
, void *dinfo_
)
5617 struct frvfdpic_relocs_info
*entry
= *entryp
;
5618 struct _frvfdpic_dynamic_got_info
*dinfo
= dinfo_
;
5620 _frvfdpic_relax_tls_entries (entry
, dinfo
, TRUE
);
5626 elf32_frvfdpic_relax_section (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
,
5627 struct bfd_link_info
*info
, bfd_boolean
*again
)
5629 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5631 if (bfd_link_relocatable (info
))
5632 (*info
->callbacks
->einfo
)
5633 (_("%P%F: --relax and -r may not be used together\n"));
5635 /* If we return early, we didn't change anything. */
5638 /* We'll do our thing when requested to relax the GOT section. */
5639 if (sec
!= frvfdpic_got_section (info
))
5642 /* We can only relax when linking the main executable or a library
5643 that can't be dlopened. */
5644 if (! bfd_link_executable (info
) && ! (info
->flags
& DF_STATIC_TLS
))
5647 /* If there isn't a TLS section for this binary, we can't do
5648 anything about its TLS relocations (it probably doesn't have
5650 if (elf_hash_table (info
)->tls_sec
== NULL
)
5653 memset (&gpinfo
, 0, sizeof (gpinfo
));
5654 memcpy (&gpinfo
.g
, frvfdpic_dynamic_got_plt_info (info
), sizeof (gpinfo
.g
));
5656 /* Now look for opportunities to relax, adjusting the GOT usage
5658 htab_traverse (frvfdpic_relocs_info (info
),
5659 _frvfdpic_relax_got_plt_entries
,
5662 /* If we changed anything, reset and re-assign GOT and PLT entries. */
5663 if (memcmp (frvfdpic_dynamic_got_plt_info (info
),
5664 &gpinfo
.g
, sizeof (gpinfo
.g
)) != 0)
5666 /* Clear GOT and PLT assignments. */
5667 htab_traverse (frvfdpic_relocs_info (info
),
5668 _frvfdpic_reset_got_plt_entries
,
5671 /* The owner of the TLS section is the output bfd. There should
5672 be a better way to get to it. */
5673 if (!_frvfdpic_size_got_plt (elf_hash_table (info
)->tls_sec
->owner
,
5677 /* Repeat until we don't make any further changes. We could fail to
5678 introduce changes in a round if, for example, the 12-bit range is
5679 full, but we later release some space by getting rid of TLS
5680 descriptors in it. We have to repeat the whole process because
5681 we might have changed the size of a section processed before this
5689 /* Fill in code and data in dynamic sections. */
5692 elf32_frv_finish_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5693 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
5695 /* Nothing to be done for non-FDPIC. */
5700 elf32_frvfdpic_finish_dynamic_sections (bfd
*output_bfd
,
5701 struct bfd_link_info
*info
)
5706 dynobj
= elf_hash_table (info
)->dynobj
;
5708 if (frvfdpic_dynamic_got_plt_info (info
))
5710 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
== 0);
5712 if (frvfdpic_got_section (info
))
5714 BFD_ASSERT (frvfdpic_gotrel_section (info
)->size
5715 == (frvfdpic_gotrel_section (info
)->reloc_count
5716 * sizeof (Elf32_External_Rel
)));
5718 if (frvfdpic_gotfixup_section (info
))
5720 struct elf_link_hash_entry
*hgot
= elf_hash_table (info
)->hgot
;
5721 bfd_vma got_value
= hgot
->root
.u
.def
.value
5722 + hgot
->root
.u
.def
.section
->output_section
->vma
5723 + hgot
->root
.u
.def
.section
->output_offset
;
5724 struct bfd_link_hash_entry
*hend
;
5726 _frvfdpic_add_rofixup (output_bfd
, frvfdpic_gotfixup_section (info
),
5729 if (frvfdpic_gotfixup_section (info
)->size
5730 != (frvfdpic_gotfixup_section (info
)->reloc_count
* 4))
5733 info
->callbacks
->einfo
5734 ("LINKER BUG: .rofixup section size mismatch\n");
5738 hend
= bfd_link_hash_lookup (info
->hash
, "__ROFIXUP_END__",
5739 FALSE
, FALSE
, TRUE
);
5741 && (hend
->type
== bfd_link_hash_defined
5742 || hend
->type
== bfd_link_hash_defweak
)
5743 && hend
->u
.def
.section
->output_section
!= NULL
)
5746 frvfdpic_gotfixup_section (info
)->output_section
->vma
5747 + frvfdpic_gotfixup_section (info
)->output_offset
5748 + frvfdpic_gotfixup_section (info
)->size
5749 - hend
->u
.def
.section
->output_section
->vma
5750 - hend
->u
.def
.section
->output_offset
;
5751 BFD_ASSERT (hend
->u
.def
.value
== value
);
5752 if (hend
->u
.def
.value
!= value
)
5757 if (frvfdpic_pltrel_section (info
))
5759 BFD_ASSERT (frvfdpic_pltrel_section (info
)->size
5760 == (frvfdpic_pltrel_section (info
)->reloc_count
5761 * sizeof (Elf32_External_Rel
)));
5765 if (elf_hash_table (info
)->dynamic_sections_created
)
5767 Elf32_External_Dyn
* dyncon
;
5768 Elf32_External_Dyn
* dynconend
;
5770 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
5772 BFD_ASSERT (sdyn
!= NULL
);
5774 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5775 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5777 for (; dyncon
< dynconend
; dyncon
++)
5779 Elf_Internal_Dyn dyn
;
5781 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5789 dyn
.d_un
.d_ptr
= frvfdpic_got_section (info
)->output_section
->vma
5790 + frvfdpic_got_section (info
)->output_offset
5791 + frvfdpic_got_initial_offset (info
);
5792 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5796 dyn
.d_un
.d_ptr
= frvfdpic_pltrel_section (info
)
5797 ->output_section
->vma
5798 + frvfdpic_pltrel_section (info
)->output_offset
;
5799 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5803 dyn
.d_un
.d_val
= frvfdpic_pltrel_section (info
)->size
;
5804 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5813 /* Adjust a symbol defined by a dynamic object and referenced by a
5817 elf32_frvfdpic_adjust_dynamic_symbol
5818 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5819 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
5823 dynobj
= elf_hash_table (info
)->dynobj
;
5825 /* Make sure we know what is going on here. */
5826 BFD_ASSERT (dynobj
!= NULL
5827 && (h
->u
.weakdef
!= NULL
5830 && !h
->def_regular
)));
5832 /* If this is a weak symbol, and there is a real definition, the
5833 processor independent code will have arranged for us to see the
5834 real definition first, and we can just use the same value. */
5835 if (h
->u
.weakdef
!= NULL
)
5837 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
5838 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
5839 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
5840 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
5846 /* Perform any actions needed for dynamic symbols. */
5849 elf32_frvfdpic_finish_dynamic_symbol
5850 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5851 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5852 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
,
5853 Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
)
5858 /* Decide whether to attempt to turn absptr or lsda encodings in
5859 shared libraries into pcrel within the given input section. */
5862 frvfdpic_elf_use_relative_eh_frame
5863 (bfd
*input_bfd ATTRIBUTE_UNUSED
,
5864 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5865 asection
*eh_frame_section ATTRIBUTE_UNUSED
)
5867 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
5871 /* Adjust the contents of an eh_frame_hdr section before they're output. */
5874 frvfdpic_elf_encode_eh_address (bfd
*abfd
,
5875 struct bfd_link_info
*info
,
5876 asection
*osec
, bfd_vma offset
,
5877 asection
*loc_sec
, bfd_vma loc_offset
,
5880 struct elf_link_hash_entry
*h
;
5882 h
= elf_hash_table (info
)->hgot
;
5883 BFD_ASSERT (h
&& h
->root
.type
== bfd_link_hash_defined
);
5885 if (! h
|| (_frvfdpic_osec_to_segment (abfd
, osec
)
5886 == _frvfdpic_osec_to_segment (abfd
, loc_sec
->output_section
)))
5887 return _bfd_elf_encode_eh_address (abfd
, info
, osec
, offset
,
5888 loc_sec
, loc_offset
, encoded
);
5890 BFD_ASSERT (_frvfdpic_osec_to_segment (abfd
, osec
)
5891 == (_frvfdpic_osec_to_segment
5892 (abfd
, h
->root
.u
.def
.section
->output_section
)));
5894 *encoded
= osec
->vma
+ offset
5895 - (h
->root
.u
.def
.value
5896 + h
->root
.u
.def
.section
->output_section
->vma
5897 + h
->root
.u
.def
.section
->output_offset
);
5899 return DW_EH_PE_datarel
| DW_EH_PE_sdata4
;
5902 /* Look through the relocs for a section during the first phase.
5904 Besides handling virtual table relocs for gc, we have to deal with
5905 all sorts of PIC-related relocations. We describe below the
5906 general plan on how to handle such relocations, even though we only
5907 collect information at this point, storing them in hash tables for
5908 perusal of later passes.
5910 32 relocations are propagated to the linker output when creating
5911 position-independent output. LO16 and HI16 relocations are not
5912 supposed to be encountered in this case.
5914 LABEL16 should always be resolvable by the linker, since it's only
5917 LABEL24, on the other hand, is used by calls. If it turns out that
5918 the target of a call is a dynamic symbol, a PLT entry must be
5919 created for it, which triggers the creation of a private function
5920 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
5922 GPREL relocations require the referenced symbol to be in the same
5923 segment as _gp, but this can only be checked later.
5925 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
5926 exist. LABEL24 might as well, since it may require a PLT entry,
5927 that will require a got.
5929 Non-FUNCDESC GOT relocations require a GOT entry to be created
5930 regardless of whether the symbol is dynamic. However, since a
5931 global symbol that turns out to not be exported may have the same
5932 address of a non-dynamic symbol, we don't assign GOT entries at
5933 this point, such that we can share them in this case. A relocation
5934 for the GOT entry always has to be created, be it to offset a
5935 private symbol by the section load address, be it to get the symbol
5936 resolved dynamically.
5938 FUNCDESC GOT relocations require a GOT entry to be created, and
5939 handled as if a FUNCDESC relocation was applied to the GOT entry in
5942 FUNCDESC relocations referencing a symbol that turns out to NOT be
5943 dynamic cause a private function descriptor to be created. The
5944 FUNCDESC relocation then decays to a 32 relocation that points at
5945 the private descriptor. If the symbol is dynamic, the FUNCDESC
5946 relocation is propagated to the linker output, such that the
5947 dynamic linker creates the canonical descriptor, pointing to the
5948 dynamically-resolved definition of the function.
5950 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
5951 symbols that are assigned to the same segment as the GOT, but we
5952 can only check this later, after we know the complete set of
5953 symbols defined and/or exported.
5955 FUNCDESC GOTOFF relocations require a function descriptor to be
5956 created and, unless lazy binding is disabled or the symbol is not
5957 dynamic, a lazy PLT entry. Since we can't tell at this point
5958 whether a symbol is going to be dynamic, we have to decide later
5959 whether to create a lazy PLT entry or bind the descriptor directly
5960 to the private function.
5962 FUNCDESC_VALUE relocations are not supposed to be present in object
5963 files, but they may very well be simply propagated to the linker
5964 output, since they have no side effect.
5967 A function descriptor always requires a FUNCDESC_VALUE relocation.
5968 Whether it's in .plt.rel or not depends on whether lazy binding is
5969 enabled and on whether the referenced symbol is dynamic.
5971 The existence of a lazy PLT requires the resolverStub lazy PLT
5972 entry to be present.
5975 As for assignment of GOT, PLT and lazy PLT entries, and private
5976 descriptors, we might do them all sequentially, but we can do
5977 better than that. For example, we can place GOT entries and
5978 private function descriptors referenced using 12-bit operands
5979 closer to the PIC register value, such that these relocations don't
5980 overflow. Those that are only referenced with LO16 relocations
5981 could come next, but we may as well place PLT-required function
5982 descriptors in the 12-bit range to make them shorter. Symbols
5983 referenced with LO16/HI16 may come next, but we may place
5984 additional function descriptors in the 16-bit range if we can
5985 reliably tell that we've already placed entries that are ever
5986 referenced with only LO16. PLT entries are therefore generated as
5987 small as possible, while not introducing relocation overflows in
5988 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
5989 generated before or after PLT entries, but not intermingled with
5990 them, such that we can have more lazy PLT entries in range for a
5991 branch to the resolverStub. The resolverStub should be emitted at
5992 the most distant location from the first lazy PLT entry such that
5993 it's still in range for a branch, or closer, if there isn't a need
5994 for so many lazy PLT entries. Additional lazy PLT entries may be
5995 emitted after the resolverStub, as long as branches are still in
5996 range. If the branch goes out of range, longer lazy PLT entries
5999 We could further optimize PLT and lazy PLT entries by giving them
6000 priority in assignment to closer-to-gr17 locations depending on the
6001 number of occurrences of references to them (assuming a function
6002 that's called more often is more important for performance, so its
6003 PLT entry should be faster), or taking hints from the compiler.
6004 Given infinite time and money... :-) */
6007 elf32_frv_check_relocs (bfd
*abfd
,
6008 struct bfd_link_info
*info
,
6010 const Elf_Internal_Rela
*relocs
)
6012 Elf_Internal_Shdr
*symtab_hdr
;
6013 struct elf_link_hash_entry
**sym_hashes
;
6014 const Elf_Internal_Rela
*rel
;
6015 const Elf_Internal_Rela
*rel_end
;
6017 struct frvfdpic_relocs_info
*picrel
;
6019 if (bfd_link_relocatable (info
))
6022 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6023 sym_hashes
= elf_sym_hashes (abfd
);
6025 dynobj
= elf_hash_table (info
)->dynobj
;
6026 rel_end
= relocs
+ sec
->reloc_count
;
6027 for (rel
= relocs
; rel
< rel_end
; rel
++)
6029 struct elf_link_hash_entry
*h
;
6030 unsigned long r_symndx
;
6032 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6033 if (r_symndx
< symtab_hdr
->sh_info
)
6037 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6038 while (h
->root
.type
== bfd_link_hash_indirect
6039 || h
->root
.type
== bfd_link_hash_warning
)
6040 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6042 /* PR15323, ref flags aren't set for references in the same
6044 h
->root
.non_ir_ref
= 1;
6047 switch (ELF32_R_TYPE (rel
->r_info
))
6049 case R_FRV_GETTLSOFF
:
6050 case R_FRV_TLSDESC_VALUE
:
6051 case R_FRV_GOTTLSDESC12
:
6052 case R_FRV_GOTTLSDESCHI
:
6053 case R_FRV_GOTTLSDESCLO
:
6054 case R_FRV_GOTTLSOFF12
:
6055 case R_FRV_GOTTLSOFFHI
:
6056 case R_FRV_GOTTLSOFFLO
:
6061 case R_FRV_FUNCDESC_GOT12
:
6062 case R_FRV_FUNCDESC_GOTHI
:
6063 case R_FRV_FUNCDESC_GOTLO
:
6064 case R_FRV_GOTOFF12
:
6065 case R_FRV_GOTOFFHI
:
6066 case R_FRV_GOTOFFLO
:
6067 case R_FRV_FUNCDESC_GOTOFF12
:
6068 case R_FRV_FUNCDESC_GOTOFFHI
:
6069 case R_FRV_FUNCDESC_GOTOFFLO
:
6070 case R_FRV_FUNCDESC
:
6071 case R_FRV_FUNCDESC_VALUE
:
6072 case R_FRV_TLSMOFF12
:
6073 case R_FRV_TLSMOFFHI
:
6074 case R_FRV_TLSMOFFLO
:
6076 if (! IS_FDPIC (abfd
))
6080 case R_FRV_GPRELU12
:
6087 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6088 if (! _frv_create_got_section (abfd
, info
))
6091 if (! IS_FDPIC (abfd
))
6098 if (h
->dynindx
== -1)
6099 switch (ELF_ST_VISIBILITY (h
->other
))
6105 bfd_elf_link_record_dynamic_symbol (info
, h
);
6109 = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info
),
6111 rel
->r_addend
, INSERT
);
6114 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
6115 (info
), abfd
, r_symndx
,
6116 rel
->r_addend
, INSERT
);
6126 switch (ELF32_R_TYPE (rel
->r_info
))
6129 if (IS_FDPIC (abfd
))
6133 case R_FRV_FUNCDESC_VALUE
:
6134 picrel
->relocsfdv
++;
6135 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
6140 if (! IS_FDPIC (abfd
))
6144 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
6154 picrel
->gothilo
= 1;
6157 case R_FRV_FUNCDESC_GOT12
:
6158 picrel
->fdgot12
= 1;
6161 case R_FRV_FUNCDESC_GOTHI
:
6162 case R_FRV_FUNCDESC_GOTLO
:
6163 picrel
->fdgothilo
= 1;
6166 case R_FRV_GOTOFF12
:
6167 case R_FRV_GOTOFFHI
:
6168 case R_FRV_GOTOFFLO
:
6172 case R_FRV_FUNCDESC_GOTOFF12
:
6173 picrel
->fdgoff12
= 1;
6176 case R_FRV_FUNCDESC_GOTOFFHI
:
6177 case R_FRV_FUNCDESC_GOTOFFLO
:
6178 picrel
->fdgoffhilo
= 1;
6181 case R_FRV_FUNCDESC
:
6186 case R_FRV_GETTLSOFF
:
6190 case R_FRV_TLSDESC_VALUE
:
6191 picrel
->relocstlsd
++;
6194 case R_FRV_GOTTLSDESC12
:
6195 picrel
->tlsdesc12
= 1;
6198 case R_FRV_GOTTLSDESCHI
:
6199 case R_FRV_GOTTLSDESCLO
:
6200 picrel
->tlsdeschilo
= 1;
6203 case R_FRV_TLSMOFF12
:
6204 case R_FRV_TLSMOFFHI
:
6205 case R_FRV_TLSMOFFLO
:
6209 case R_FRV_GOTTLSOFF12
:
6210 picrel
->tlsoff12
= 1;
6211 info
->flags
|= DF_STATIC_TLS
;
6214 case R_FRV_GOTTLSOFFHI
:
6215 case R_FRV_GOTTLSOFFLO
:
6216 picrel
->tlsoffhilo
= 1;
6217 info
->flags
|= DF_STATIC_TLS
;
6221 picrel
->relocstlsoff
++;
6222 info
->flags
|= DF_STATIC_TLS
;
6225 /* This relocation describes the C++ object vtable hierarchy.
6226 Reconstruct it for later use during GC. */
6227 case R_FRV_GNU_VTINHERIT
:
6228 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6232 /* This relocation describes which C++ vtable entries are actually
6233 used. Record for later use during GC. */
6234 case R_FRV_GNU_VTENTRY
:
6235 BFD_ASSERT (h
!= NULL
);
6237 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
6245 case R_FRV_GPRELU12
:
6249 case R_FRV_TLSDESC_RELAX
:
6250 case R_FRV_GETTLSOFF_RELAX
:
6251 case R_FRV_TLSOFF_RELAX
:
6256 info
->callbacks
->einfo
6257 /* xgettext:c-format */
6258 (_("%B: unsupported relocation type %i\n"),
6259 abfd
, ELF32_R_TYPE (rel
->r_info
));
6268 /* Return the machine subcode from the ELF e_flags header. */
6271 elf32_frv_machine (bfd
*abfd
)
6273 switch (elf_elfheader (abfd
)->e_flags
& EF_FRV_CPU_MASK
)
6276 case EF_FRV_CPU_FR550
: return bfd_mach_fr550
;
6277 case EF_FRV_CPU_FR500
: return bfd_mach_fr500
;
6278 case EF_FRV_CPU_FR450
: return bfd_mach_fr450
;
6279 case EF_FRV_CPU_FR405
: return bfd_mach_fr400
;
6280 case EF_FRV_CPU_FR400
: return bfd_mach_fr400
;
6281 case EF_FRV_CPU_FR300
: return bfd_mach_fr300
;
6282 case EF_FRV_CPU_SIMPLE
: return bfd_mach_frvsimple
;
6283 case EF_FRV_CPU_TOMCAT
: return bfd_mach_frvtomcat
;
6286 return bfd_mach_frv
;
6289 /* Set the right machine number for a FRV ELF file. */
6292 elf32_frv_object_p (bfd
*abfd
)
6294 bfd_default_set_arch_mach (abfd
, bfd_arch_frv
, elf32_frv_machine (abfd
));
6295 return (((elf_elfheader (abfd
)->e_flags
& EF_FRV_FDPIC
) != 0)
6296 == (IS_FDPIC (abfd
)));
6299 /* Function to set the ELF flag bits. */
6302 frv_elf_set_private_flags (bfd
*abfd
, flagword flags
)
6304 elf_elfheader (abfd
)->e_flags
= flags
;
6305 elf_flags_init (abfd
) = TRUE
;
6309 /* Return true if the architecture described by elf header flag
6310 EXTENSION is an extension of the architecture described by BASE. */
6313 frv_elf_arch_extension_p (flagword base
, flagword extension
)
6315 if (base
== extension
)
6318 /* CPU_GENERIC code can be merged with code for a specific
6319 architecture, in which case the result is marked as being
6320 for the specific architecture. Everything is therefore
6321 an extension of CPU_GENERIC. */
6322 if (base
== EF_FRV_CPU_GENERIC
)
6325 if (extension
== EF_FRV_CPU_FR450
)
6326 if (base
== EF_FRV_CPU_FR400
|| base
== EF_FRV_CPU_FR405
)
6329 if (extension
== EF_FRV_CPU_FR405
)
6330 if (base
== EF_FRV_CPU_FR400
)
6336 /* Merge backend specific data from an object file to the output
6337 object file when linking. */
6340 frv_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
6342 bfd
*obfd
= info
->output_bfd
;
6343 flagword old_flags
, old_partial
;
6344 flagword new_flags
, new_partial
;
6345 bfd_boolean error
= FALSE
;
6349 new_opt
[0] = old_opt
[0] = '\0';
6350 new_flags
= elf_elfheader (ibfd
)->e_flags
;
6351 old_flags
= elf_elfheader (obfd
)->e_flags
;
6353 if (new_flags
& EF_FRV_FDPIC
)
6354 new_flags
&= ~EF_FRV_PIC
;
6358 ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s",
6359 old_flags
, new_flags
, elf_flags_init (obfd
) ? "yes" : "no",
6360 bfd_get_filename (ibfd
));
6363 if (!elf_flags_init (obfd
)) /* First call, no flags set. */
6365 elf_flags_init (obfd
) = TRUE
;
6366 old_flags
= new_flags
;
6369 else if (new_flags
== old_flags
) /* Compatible flags are ok. */
6372 else /* Possibly incompatible flags. */
6374 /* Warn if different # of gprs are used. Note, 0 means nothing is
6375 said about the size of gprs. */
6376 new_partial
= (new_flags
& EF_FRV_GPR_MASK
);
6377 old_partial
= (old_flags
& EF_FRV_GPR_MASK
);
6378 if (new_partial
== old_partial
)
6381 else if (new_partial
== 0)
6384 else if (old_partial
== 0)
6385 old_flags
|= new_partial
;
6389 switch (new_partial
)
6391 default: strcat (new_opt
, " -mgpr-??"); break;
6392 case EF_FRV_GPR_32
: strcat (new_opt
, " -mgpr-32"); break;
6393 case EF_FRV_GPR_64
: strcat (new_opt
, " -mgpr-64"); break;
6396 switch (old_partial
)
6398 default: strcat (old_opt
, " -mgpr-??"); break;
6399 case EF_FRV_GPR_32
: strcat (old_opt
, " -mgpr-32"); break;
6400 case EF_FRV_GPR_64
: strcat (old_opt
, " -mgpr-64"); break;
6404 /* Warn if different # of fprs are used. Note, 0 means nothing is
6405 said about the size of fprs. */
6406 new_partial
= (new_flags
& EF_FRV_FPR_MASK
);
6407 old_partial
= (old_flags
& EF_FRV_FPR_MASK
);
6408 if (new_partial
== old_partial
)
6411 else if (new_partial
== 0)
6414 else if (old_partial
== 0)
6415 old_flags
|= new_partial
;
6419 switch (new_partial
)
6421 default: strcat (new_opt
, " -mfpr-?"); break;
6422 case EF_FRV_FPR_32
: strcat (new_opt
, " -mfpr-32"); break;
6423 case EF_FRV_FPR_64
: strcat (new_opt
, " -mfpr-64"); break;
6424 case EF_FRV_FPR_NONE
: strcat (new_opt
, " -msoft-float"); break;
6427 switch (old_partial
)
6429 default: strcat (old_opt
, " -mfpr-?"); break;
6430 case EF_FRV_FPR_32
: strcat (old_opt
, " -mfpr-32"); break;
6431 case EF_FRV_FPR_64
: strcat (old_opt
, " -mfpr-64"); break;
6432 case EF_FRV_FPR_NONE
: strcat (old_opt
, " -msoft-float"); break;
6436 /* Warn if different dword support was used. Note, 0 means nothing is
6437 said about the dword support. */
6438 new_partial
= (new_flags
& EF_FRV_DWORD_MASK
);
6439 old_partial
= (old_flags
& EF_FRV_DWORD_MASK
);
6440 if (new_partial
== old_partial
)
6443 else if (new_partial
== 0)
6446 else if (old_partial
== 0)
6447 old_flags
|= new_partial
;
6451 switch (new_partial
)
6453 default: strcat (new_opt
, " -mdword-?"); break;
6454 case EF_FRV_DWORD_YES
: strcat (new_opt
, " -mdword"); break;
6455 case EF_FRV_DWORD_NO
: strcat (new_opt
, " -mno-dword"); break;
6458 switch (old_partial
)
6460 default: strcat (old_opt
, " -mdword-?"); break;
6461 case EF_FRV_DWORD_YES
: strcat (old_opt
, " -mdword"); break;
6462 case EF_FRV_DWORD_NO
: strcat (old_opt
, " -mno-dword"); break;
6466 /* Or in flags that accumulate (ie, if one module uses it, mark that the
6468 old_flags
|= new_flags
& (EF_FRV_DOUBLE
6471 | EF_FRV_NON_PIC_RELOCS
);
6473 /* If any module was compiled without -G0, clear the G0 bit. */
6474 old_flags
= ((old_flags
& ~ EF_FRV_G0
)
6475 | (old_flags
& new_flags
& EF_FRV_G0
));
6477 /* If any module was compiled without -mnopack, clear the mnopack bit. */
6478 old_flags
= ((old_flags
& ~ EF_FRV_NOPACK
)
6479 | (old_flags
& new_flags
& EF_FRV_NOPACK
));
6481 /* We don't have to do anything if the pic flags are the same, or the new
6482 module(s) were compiled with -mlibrary-pic. */
6483 new_partial
= (new_flags
& EF_FRV_PIC_FLAGS
);
6484 old_partial
= (old_flags
& EF_FRV_PIC_FLAGS
);
6485 if ((new_partial
== old_partial
) || ((new_partial
& EF_FRV_LIBPIC
) != 0))
6488 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
6489 flags if any from the new module. */
6490 else if ((old_partial
& EF_FRV_LIBPIC
) != 0)
6491 old_flags
= (old_flags
& ~ EF_FRV_PIC_FLAGS
) | new_partial
;
6493 /* If we have mixtures of -fpic and -fPIC, or in both bits. */
6494 else if (new_partial
!= 0 && old_partial
!= 0)
6495 old_flags
|= new_partial
;
6497 /* One module was compiled for pic and the other was not, see if we have
6498 had any relocations that are not pic-safe. */
6501 if ((old_flags
& EF_FRV_NON_PIC_RELOCS
) == 0)
6502 old_flags
|= new_partial
;
6505 old_flags
&= ~ EF_FRV_PIC_FLAGS
;
6506 #ifndef FRV_NO_PIC_ERROR
6509 /* xgettext:c-format */
6510 (_("%s: compiled with %s and linked with modules that use non-pic relocations"),
6511 bfd_get_filename (ibfd
),
6512 (new_flags
& EF_FRV_BIGPIC
) ? "-fPIC" : "-fpic");
6517 /* Warn if different cpu is used (allow a specific cpu to override
6518 the generic cpu). */
6519 new_partial
= (new_flags
& EF_FRV_CPU_MASK
);
6520 old_partial
= (old_flags
& EF_FRV_CPU_MASK
);
6521 if (frv_elf_arch_extension_p (new_partial
, old_partial
))
6524 else if (frv_elf_arch_extension_p (old_partial
, new_partial
))
6525 old_flags
= (old_flags
& ~EF_FRV_CPU_MASK
) | new_partial
;
6529 switch (new_partial
)
6531 default: strcat (new_opt
, " -mcpu=?"); break;
6532 case EF_FRV_CPU_GENERIC
: strcat (new_opt
, " -mcpu=frv"); break;
6533 case EF_FRV_CPU_SIMPLE
: strcat (new_opt
, " -mcpu=simple"); break;
6534 case EF_FRV_CPU_FR550
: strcat (new_opt
, " -mcpu=fr550"); break;
6535 case EF_FRV_CPU_FR500
: strcat (new_opt
, " -mcpu=fr500"); break;
6536 case EF_FRV_CPU_FR450
: strcat (new_opt
, " -mcpu=fr450"); break;
6537 case EF_FRV_CPU_FR405
: strcat (new_opt
, " -mcpu=fr405"); break;
6538 case EF_FRV_CPU_FR400
: strcat (new_opt
, " -mcpu=fr400"); break;
6539 case EF_FRV_CPU_FR300
: strcat (new_opt
, " -mcpu=fr300"); break;
6540 case EF_FRV_CPU_TOMCAT
: strcat (new_opt
, " -mcpu=tomcat"); break;
6543 switch (old_partial
)
6545 default: strcat (old_opt
, " -mcpu=?"); break;
6546 case EF_FRV_CPU_GENERIC
: strcat (old_opt
, " -mcpu=frv"); break;
6547 case EF_FRV_CPU_SIMPLE
: strcat (old_opt
, " -mcpu=simple"); break;
6548 case EF_FRV_CPU_FR550
: strcat (old_opt
, " -mcpu=fr550"); break;
6549 case EF_FRV_CPU_FR500
: strcat (old_opt
, " -mcpu=fr500"); break;
6550 case EF_FRV_CPU_FR450
: strcat (old_opt
, " -mcpu=fr450"); break;
6551 case EF_FRV_CPU_FR405
: strcat (old_opt
, " -mcpu=fr405"); break;
6552 case EF_FRV_CPU_FR400
: strcat (old_opt
, " -mcpu=fr400"); break;
6553 case EF_FRV_CPU_FR300
: strcat (old_opt
, " -mcpu=fr300"); break;
6554 case EF_FRV_CPU_TOMCAT
: strcat (old_opt
, " -mcpu=tomcat"); break;
6558 /* Print out any mismatches from above. */
6563 /* xgettext:c-format */
6564 (_("%s: compiled with %s and linked with modules compiled with %s"),
6565 bfd_get_filename (ibfd
), new_opt
, old_opt
);
6568 /* Warn about any other mismatches */
6569 new_partial
= (new_flags
& ~ EF_FRV_ALL_FLAGS
);
6570 old_partial
= (old_flags
& ~ EF_FRV_ALL_FLAGS
);
6571 if (new_partial
!= old_partial
)
6573 old_flags
|= new_partial
;
6576 /* xgettext:c-format */
6577 (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"),
6578 bfd_get_filename (ibfd
), (long)new_partial
, (long)old_partial
);
6582 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
6583 if ((old_flags
& EF_FRV_CPU_MASK
) == EF_FRV_CPU_SIMPLE
)
6584 old_flags
|= EF_FRV_NOPACK
;
6586 /* Update the old flags now with changes made above. */
6587 old_partial
= elf_elfheader (obfd
)->e_flags
& EF_FRV_CPU_MASK
;
6588 elf_elfheader (obfd
)->e_flags
= old_flags
;
6589 if (old_partial
!= (old_flags
& EF_FRV_CPU_MASK
))
6590 bfd_default_set_arch_mach (obfd
, bfd_arch_frv
, elf32_frv_machine (obfd
));
6592 if (((new_flags
& EF_FRV_FDPIC
) == 0)
6593 != (! IS_FDPIC (ibfd
)))
6596 if (IS_FDPIC (obfd
))
6598 (_("%s: cannot link non-fdpic object file into fdpic executable"),
6599 bfd_get_filename (ibfd
));
6602 (_("%s: cannot link fdpic object file into non-fdpic executable"),
6603 bfd_get_filename (ibfd
));
6607 bfd_set_error (bfd_error_bad_value
);
6614 frv_elf_print_private_bfd_data (bfd
*abfd
, void * ptr
)
6616 FILE *file
= (FILE *) ptr
;
6619 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6621 /* Print normal ELF private data. */
6622 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6624 flags
= elf_elfheader (abfd
)->e_flags
;
6625 fprintf (file
, _("private flags = 0x%lx:"), (unsigned long) flags
);
6627 switch (flags
& EF_FRV_CPU_MASK
)
6630 case EF_FRV_CPU_SIMPLE
: fprintf (file
, " -mcpu=simple"); break;
6631 case EF_FRV_CPU_FR550
: fprintf (file
, " -mcpu=fr550"); break;
6632 case EF_FRV_CPU_FR500
: fprintf (file
, " -mcpu=fr500"); break;
6633 case EF_FRV_CPU_FR450
: fprintf (file
, " -mcpu=fr450"); break;
6634 case EF_FRV_CPU_FR405
: fprintf (file
, " -mcpu=fr405"); break;
6635 case EF_FRV_CPU_FR400
: fprintf (file
, " -mcpu=fr400"); break;
6636 case EF_FRV_CPU_FR300
: fprintf (file
, " -mcpu=fr300"); break;
6637 case EF_FRV_CPU_TOMCAT
: fprintf (file
, " -mcpu=tomcat"); break;
6640 switch (flags
& EF_FRV_GPR_MASK
)
6643 case EF_FRV_GPR_32
: fprintf (file
, " -mgpr-32"); break;
6644 case EF_FRV_GPR_64
: fprintf (file
, " -mgpr-64"); break;
6647 switch (flags
& EF_FRV_FPR_MASK
)
6650 case EF_FRV_FPR_32
: fprintf (file
, " -mfpr-32"); break;
6651 case EF_FRV_FPR_64
: fprintf (file
, " -mfpr-64"); break;
6652 case EF_FRV_FPR_NONE
: fprintf (file
, " -msoft-float"); break;
6655 switch (flags
& EF_FRV_DWORD_MASK
)
6658 case EF_FRV_DWORD_YES
: fprintf (file
, " -mdword"); break;
6659 case EF_FRV_DWORD_NO
: fprintf (file
, " -mno-dword"); break;
6662 if (flags
& EF_FRV_DOUBLE
)
6663 fprintf (file
, " -mdouble");
6665 if (flags
& EF_FRV_MEDIA
)
6666 fprintf (file
, " -mmedia");
6668 if (flags
& EF_FRV_MULADD
)
6669 fprintf (file
, " -mmuladd");
6671 if (flags
& EF_FRV_PIC
)
6672 fprintf (file
, " -fpic");
6674 if (flags
& EF_FRV_BIGPIC
)
6675 fprintf (file
, " -fPIC");
6677 if (flags
& EF_FRV_LIBPIC
)
6678 fprintf (file
, " -mlibrary-pic");
6680 if (flags
& EF_FRV_FDPIC
)
6681 fprintf (file
, " -mfdpic");
6683 if (flags
& EF_FRV_NON_PIC_RELOCS
)
6684 fprintf (file
, " non-pic relocations");
6686 if (flags
& EF_FRV_G0
)
6687 fprintf (file
, " -G0");
6694 /* Support for core dump NOTE sections. */
6697 elf32_frv_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
6700 unsigned int raw_size
;
6702 switch (note
->descsz
)
6707 /* The Linux/FRV elf_prstatus struct is 268 bytes long. The other
6708 hardcoded offsets and sizes listed below (and contained within
6709 this lexical block) refer to fields in the target's elf_prstatus
6712 /* `pr_cursig' is at offset 12. */
6713 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
6715 /* `pr_pid' is at offset 24. */
6716 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
6718 /* `pr_reg' is at offset 72. */
6721 /* Most grok_prstatus implementations set `raw_size' to the size
6722 of the pr_reg field. For Linux/FRV, we set `raw_size' to be
6723 the size of `pr_reg' plus the size of `pr_exec_fdpic_loadmap'
6724 and `pr_interp_fdpic_loadmap', both of which (by design)
6725 immediately follow `pr_reg'. This will allow these fields to
6726 be viewed by GDB as registers.
6728 `pr_reg' is 184 bytes long. `pr_exec_fdpic_loadmap' and
6729 `pr_interp_fdpic_loadmap' are 4 bytes each. */
6730 raw_size
= 184 + 4 + 4;
6735 /* Make a ".reg/999" section. */
6736 return _bfd_elfcore_make_pseudosection (abfd
, ".reg", raw_size
,
6737 note
->descpos
+ offset
);
6741 elf32_frv_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
6743 switch (note
->descsz
)
6748 /* The Linux/FRV elf_prpsinfo struct is 124 bytes long. */
6751 /* `pr_fname' is found at offset 28 and is 16 bytes long. */
6752 elf_tdata (abfd
)->core
->program
6753 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
6755 /* `pr_psargs' is found at offset 44 and is 80 bytes long. */
6756 elf_tdata (abfd
)->core
->command
6757 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
6760 /* Note that for some reason, a spurious space is tacked
6761 onto the end of the args in some (at least one anyway)
6762 implementations, so strip it off if it exists. */
6765 char *command
= elf_tdata (abfd
)->core
->command
;
6766 int n
= strlen (command
);
6768 if (0 < n
&& command
[n
- 1] == ' ')
6769 command
[n
- 1] = '\0';
6774 #define ELF_ARCH bfd_arch_frv
6775 #define ELF_TARGET_ID FRV_ELF_DATA
6776 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
6777 #define ELF_MAXPAGESIZE 0x1000
6779 #define TARGET_BIG_SYM frv_elf32_vec
6780 #define TARGET_BIG_NAME "elf32-frv"
6782 #define elf_info_to_howto frv_info_to_howto_rela
6783 #define elf_backend_relocate_section elf32_frv_relocate_section
6784 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
6785 #define elf_backend_check_relocs elf32_frv_check_relocs
6786 #define elf_backend_object_p elf32_frv_object_p
6787 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
6789 #define elf_backend_stack_align 8
6790 #define elf_backend_can_gc_sections 1
6791 #define elf_backend_rela_normal 1
6793 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
6794 #define bfd_elf32_bfd_reloc_name_lookup frv_reloc_name_lookup
6795 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
6796 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
6797 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
6799 #define elf_backend_want_got_sym 1
6800 #define elf_backend_got_header_size 0
6801 #define elf_backend_want_got_plt 0
6802 #define elf_backend_plt_readonly 1
6803 #define elf_backend_want_plt_sym 0
6804 #define elf_backend_plt_header_size 0
6806 #define elf_backend_finish_dynamic_sections \
6807 elf32_frv_finish_dynamic_sections
6809 #define elf_backend_grok_prstatus elf32_frv_grok_prstatus
6810 #define elf_backend_grok_psinfo elf32_frv_grok_psinfo
6812 #include "elf32-target.h"
6814 #undef ELF_MAXPAGESIZE
6815 #define ELF_MAXPAGESIZE 0x4000
6817 #undef TARGET_BIG_SYM
6818 #define TARGET_BIG_SYM frv_elf32_fdpic_vec
6819 #undef TARGET_BIG_NAME
6820 #define TARGET_BIG_NAME "elf32-frvfdpic"
6822 #define elf32_bed elf32_frvfdpic_bed
6824 #undef elf_info_to_howto_rel
6825 #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel
6827 #undef bfd_elf32_bfd_link_hash_table_create
6828 #define bfd_elf32_bfd_link_hash_table_create \
6829 frvfdpic_elf_link_hash_table_create
6830 #undef elf_backend_always_size_sections
6831 #define elf_backend_always_size_sections \
6832 elf32_frvfdpic_always_size_sections
6834 #undef elf_backend_create_dynamic_sections
6835 #define elf_backend_create_dynamic_sections \
6836 elf32_frvfdpic_create_dynamic_sections
6837 #undef elf_backend_adjust_dynamic_symbol
6838 #define elf_backend_adjust_dynamic_symbol \
6839 elf32_frvfdpic_adjust_dynamic_symbol
6840 #undef elf_backend_size_dynamic_sections
6841 #define elf_backend_size_dynamic_sections \
6842 elf32_frvfdpic_size_dynamic_sections
6843 #undef bfd_elf32_bfd_relax_section
6844 #define bfd_elf32_bfd_relax_section \
6845 elf32_frvfdpic_relax_section
6846 #undef elf_backend_finish_dynamic_symbol
6847 #define elf_backend_finish_dynamic_symbol \
6848 elf32_frvfdpic_finish_dynamic_symbol
6849 #undef elf_backend_finish_dynamic_sections
6850 #define elf_backend_finish_dynamic_sections \
6851 elf32_frvfdpic_finish_dynamic_sections
6853 #undef elf_backend_discard_info
6854 #define elf_backend_discard_info \
6855 frvfdpic_elf_discard_info
6856 #undef elf_backend_can_make_relative_eh_frame
6857 #define elf_backend_can_make_relative_eh_frame \
6858 frvfdpic_elf_use_relative_eh_frame
6859 #undef elf_backend_can_make_lsda_relative_eh_frame
6860 #define elf_backend_can_make_lsda_relative_eh_frame \
6861 frvfdpic_elf_use_relative_eh_frame
6862 #undef elf_backend_encode_eh_address
6863 #define elf_backend_encode_eh_address \
6864 frvfdpic_elf_encode_eh_address
6866 #undef elf_backend_may_use_rel_p
6867 #define elf_backend_may_use_rel_p 1
6868 #undef elf_backend_may_use_rela_p
6869 #define elf_backend_may_use_rela_p 1
6870 /* We use REL for dynamic relocations only. */
6871 #undef elf_backend_default_use_rela_p
6872 #define elf_backend_default_use_rela_p 1
6874 #undef elf_backend_omit_section_dynsym
6875 #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym
6877 #include "elf32-target.h"