1 /* FRV-specific support for 32-bit ELF.
2 Copyright (C) 2002-2019 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. */
28 #include "libiberty.h"
30 /* Forward declarations. */
33 static reloc_howto_type elf32_frv_howto_table
[] =
35 /* This reloc does nothing. */
36 HOWTO (R_FRV_NONE
, /* type */
38 3, /* size (0 = byte, 1 = short, 2 = long) */
40 FALSE
, /* pc_relative */
42 complain_overflow_dont
, /* complain_on_overflow */
43 bfd_elf_generic_reloc
, /* special_function */
44 "R_FRV_NONE", /* name */
45 FALSE
, /* partial_inplace */
48 FALSE
), /* pcrel_offset */
50 /* A 32 bit absolute relocation. */
51 HOWTO (R_FRV_32
, /* type */
53 2, /* size (0 = byte, 1 = short, 2 = long) */
55 FALSE
, /* pc_relative */
57 complain_overflow_bitfield
, /* complain_on_overflow */
58 bfd_elf_generic_reloc
, /* special_function */
59 "R_FRV_32", /* name */
60 FALSE
, /* partial_inplace */
61 0xffffffff, /* src_mask */
62 0xffffffff, /* dst_mask */
63 FALSE
), /* pcrel_offset */
65 /* A 16 bit pc-relative relocation. */
66 HOWTO (R_FRV_LABEL16
, /* type */
68 2, /* size (0 = byte, 1 = short, 2 = long) */
70 TRUE
, /* pc_relative */
72 complain_overflow_signed
, /* complain_on_overflow */
73 bfd_elf_generic_reloc
, /* special_function */
74 "R_FRV_LABEL16", /* name */
75 FALSE
, /* partial_inplace */
76 0xffff, /* src_mask */
77 0xffff, /* dst_mask */
78 TRUE
), /* pcrel_offset */
80 /* A 24-bit pc-relative relocation. */
81 HOWTO (R_FRV_LABEL24
, /* type */
83 2, /* size (0 = byte, 1 = short, 2 = long) */
85 TRUE
, /* pc_relative */
87 complain_overflow_bitfield
, /* complain_on_overflow */
88 bfd_elf_generic_reloc
, /* special_function */
89 "R_FRV_LABEL24", /* name */
90 FALSE
, /* partial_inplace */
91 0x7e03ffff, /* src_mask */
92 0x7e03ffff, /* dst_mask */
93 TRUE
), /* pcrel_offset */
95 HOWTO (R_FRV_LO16
, /* type */
97 2, /* size (0 = byte, 1 = short, 2 = long) */
99 FALSE
, /* pc_relative */
101 complain_overflow_dont
, /* complain_on_overflow */
102 bfd_elf_generic_reloc
, /* special_function */
103 "R_FRV_LO16", /* name */
104 FALSE
, /* partial_inplace */
105 0xffff, /* src_mask */
106 0xffff, /* dst_mask */
107 FALSE
), /* pcrel_offset */
109 HOWTO (R_FRV_HI16
, /* type */
111 2, /* size (0 = byte, 1 = short, 2 = long) */
113 FALSE
, /* pc_relative */
115 complain_overflow_dont
, /* complain_on_overflow */
116 bfd_elf_generic_reloc
, /* special_function */
117 "R_FRV_HI16", /* name */
118 FALSE
, /* partial_inplace */
119 0xffff, /* src_mask */
120 0xffff, /* dst_mask */
121 FALSE
), /* pcrel_offset */
123 HOWTO (R_FRV_GPREL12
, /* type */
125 2, /* size (0 = byte, 1 = short, 2 = long) */
127 FALSE
, /* pc_relative */
129 complain_overflow_dont
, /* complain_on_overflow */
130 bfd_elf_generic_reloc
, /* special_function */
131 "R_FRV_GPREL12", /* name */
132 FALSE
, /* partial_inplace */
133 0xfff, /* src_mask */
134 0xfff, /* dst_mask */
135 FALSE
), /* pcrel_offset */
137 HOWTO (R_FRV_GPRELU12
, /* type */
139 2, /* size (0 = byte, 1 = short, 2 = long) */
141 FALSE
, /* pc_relative */
143 complain_overflow_dont
, /* complain_on_overflow */
144 bfd_elf_generic_reloc
, /* special_function */
145 "R_FRV_GPRELU12", /* name */
146 FALSE
, /* partial_inplace */
147 0xfff, /* src_mask */
148 0x3f03f, /* dst_mask */
149 FALSE
), /* pcrel_offset */
151 HOWTO (R_FRV_GPREL32
, /* type */
153 2, /* size (0 = byte, 1 = short, 2 = long) */
155 FALSE
, /* pc_relative */
157 complain_overflow_dont
, /* complain_on_overflow */
158 bfd_elf_generic_reloc
, /* special_function */
159 "R_FRV_GPREL32", /* name */
160 FALSE
, /* partial_inplace */
161 0xffffffff, /* src_mask */
162 0xffffffff, /* dst_mask */
163 FALSE
), /* pcrel_offset */
165 HOWTO (R_FRV_GPRELHI
, /* type */
167 2, /* size (0 = byte, 1 = short, 2 = long) */
169 FALSE
, /* pc_relative */
171 complain_overflow_dont
, /* complain_on_overflow */
172 bfd_elf_generic_reloc
, /* special_function */
173 "R_FRV_GPRELHI", /* name */
174 FALSE
, /* partial_inplace */
175 0xffff, /* src_mask */
176 0xffff, /* dst_mask */
177 FALSE
), /* pcrel_offset */
179 HOWTO (R_FRV_GPRELLO
, /* type */
181 2, /* size (0 = byte, 1 = short, 2 = long) */
183 FALSE
, /* pc_relative */
185 complain_overflow_dont
, /* complain_on_overflow */
186 bfd_elf_generic_reloc
, /* special_function */
187 "R_FRV_GPRELLO", /* name */
188 FALSE
, /* partial_inplace */
189 0xffff, /* src_mask */
190 0xffff, /* dst_mask */
191 FALSE
), /* pcrel_offset */
193 /* A 12-bit signed operand with the GOT offset for the address of
195 HOWTO (R_FRV_GOT12
, /* type */
197 2, /* size (0 = byte, 1 = short, 2 = long) */
199 FALSE
, /* pc_relative */
201 complain_overflow_signed
, /* complain_on_overflow */
202 bfd_elf_generic_reloc
, /* special_function */
203 "R_FRV_GOT12", /* name */
204 FALSE
, /* partial_inplace */
205 0xfff, /* src_mask */
206 0xfff, /* dst_mask */
207 FALSE
), /* pcrel_offset */
209 /* The upper 16 bits of the GOT offset for the address of the
211 HOWTO (R_FRV_GOTHI
, /* type */
213 2, /* size (0 = byte, 1 = short, 2 = long) */
215 FALSE
, /* pc_relative */
217 complain_overflow_dont
, /* complain_on_overflow */
218 bfd_elf_generic_reloc
, /* special_function */
219 "R_FRV_GOTHI", /* name */
220 FALSE
, /* partial_inplace */
221 0xffff, /* src_mask */
222 0xffff, /* dst_mask */
223 FALSE
), /* pcrel_offset */
225 /* The lower 16 bits of the GOT offset for the address of the
227 HOWTO (R_FRV_GOTLO
, /* type */
229 2, /* size (0 = byte, 1 = short, 2 = long) */
231 FALSE
, /* pc_relative */
233 complain_overflow_dont
, /* complain_on_overflow */
234 bfd_elf_generic_reloc
, /* special_function */
235 "R_FRV_GOTLO", /* name */
236 FALSE
, /* partial_inplace */
237 0xffff, /* src_mask */
238 0xffff, /* dst_mask */
239 FALSE
), /* pcrel_offset */
241 /* The 32-bit address of the canonical descriptor of a function. */
242 HOWTO (R_FRV_FUNCDESC
, /* type */
244 2, /* size (0 = byte, 1 = short, 2 = long) */
246 FALSE
, /* pc_relative */
248 complain_overflow_bitfield
, /* complain_on_overflow */
249 bfd_elf_generic_reloc
, /* special_function */
250 "R_FRV_FUNCDESC", /* name */
251 FALSE
, /* partial_inplace */
252 0xffffffff, /* src_mask */
253 0xffffffff, /* dst_mask */
254 FALSE
), /* pcrel_offset */
256 /* A 12-bit signed operand with the GOT offset for the address of
257 canonical descriptor of a function. */
258 HOWTO (R_FRV_FUNCDESC_GOT12
, /* type */
260 2, /* size (0 = byte, 1 = short, 2 = long) */
262 FALSE
, /* pc_relative */
264 complain_overflow_signed
, /* complain_on_overflow */
265 bfd_elf_generic_reloc
, /* special_function */
266 "R_FRV_FUNCDESC_GOT12", /* name */
267 FALSE
, /* partial_inplace */
268 0xfff, /* src_mask */
269 0xfff, /* dst_mask */
270 FALSE
), /* pcrel_offset */
272 /* The upper 16 bits of the GOT offset for the address of the
273 canonical descriptor of a function. */
274 HOWTO (R_FRV_FUNCDESC_GOTHI
, /* type */
276 2, /* size (0 = byte, 1 = short, 2 = long) */
278 FALSE
, /* pc_relative */
280 complain_overflow_dont
, /* complain_on_overflow */
281 bfd_elf_generic_reloc
, /* special_function */
282 "R_FRV_FUNCDESC_GOTHI", /* name */
283 FALSE
, /* partial_inplace */
284 0xffff, /* src_mask */
285 0xffff, /* dst_mask */
286 FALSE
), /* pcrel_offset */
288 /* The lower 16 bits of the GOT offset for the address of the
289 canonical descriptor of a function. */
290 HOWTO (R_FRV_FUNCDESC_GOTLO
, /* type */
292 2, /* size (0 = byte, 1 = short, 2 = long) */
294 FALSE
, /* pc_relative */
296 complain_overflow_dont
, /* complain_on_overflow */
297 bfd_elf_generic_reloc
, /* special_function */
298 "R_FRV_FUNCDESC_GOTLO", /* name */
299 FALSE
, /* partial_inplace */
300 0xffff, /* src_mask */
301 0xffff, /* dst_mask */
302 FALSE
), /* pcrel_offset */
304 /* The 64-bit descriptor of a function. */
305 HOWTO (R_FRV_FUNCDESC_VALUE
, /* type */
307 2, /* size (0 = byte, 1 = short, 2 = long) */
309 FALSE
, /* pc_relative */
311 complain_overflow_bitfield
, /* complain_on_overflow */
312 bfd_elf_generic_reloc
, /* special_function */
313 "R_FRV_FUNCDESC_VALUE", /* name */
314 FALSE
, /* partial_inplace */
315 0xffffffff, /* src_mask */
316 0xffffffff, /* dst_mask */
317 FALSE
), /* pcrel_offset */
319 /* A 12-bit signed operand with the GOT offset for the address of
320 canonical descriptor of a function. */
321 HOWTO (R_FRV_FUNCDESC_GOTOFF12
, /* type */
323 2, /* size (0 = byte, 1 = short, 2 = long) */
325 FALSE
, /* pc_relative */
327 complain_overflow_signed
, /* complain_on_overflow */
328 bfd_elf_generic_reloc
, /* special_function */
329 "R_FRV_FUNCDESC_GOTOFF12", /* name */
330 FALSE
, /* partial_inplace */
331 0xfff, /* src_mask */
332 0xfff, /* dst_mask */
333 FALSE
), /* pcrel_offset */
335 /* The upper 16 bits of the GOT offset for the address of the
336 canonical descriptor of a function. */
337 HOWTO (R_FRV_FUNCDESC_GOTOFFHI
, /* type */
339 2, /* size (0 = byte, 1 = short, 2 = long) */
341 FALSE
, /* pc_relative */
343 complain_overflow_dont
, /* complain_on_overflow */
344 bfd_elf_generic_reloc
, /* special_function */
345 "R_FRV_FUNCDESC_GOTOFFHI", /* name */
346 FALSE
, /* partial_inplace */
347 0xffff, /* src_mask */
348 0xffff, /* dst_mask */
349 FALSE
), /* pcrel_offset */
351 /* The lower 16 bits of the GOT offset for the address of the
352 canonical descriptor of a function. */
353 HOWTO (R_FRV_FUNCDESC_GOTOFFLO
, /* type */
355 2, /* size (0 = byte, 1 = short, 2 = long) */
357 FALSE
, /* pc_relative */
359 complain_overflow_dont
, /* complain_on_overflow */
360 bfd_elf_generic_reloc
, /* special_function */
361 "R_FRV_FUNCDESC_GOTOFFLO", /* name */
362 FALSE
, /* partial_inplace */
363 0xffff, /* src_mask */
364 0xffff, /* dst_mask */
365 FALSE
), /* pcrel_offset */
367 /* A 12-bit signed operand with the GOT offset for the address of
369 HOWTO (R_FRV_GOTOFF12
, /* type */
371 2, /* size (0 = byte, 1 = short, 2 = long) */
373 FALSE
, /* pc_relative */
375 complain_overflow_signed
, /* complain_on_overflow */
376 bfd_elf_generic_reloc
, /* special_function */
377 "R_FRV_GOTOFF12", /* name */
378 FALSE
, /* partial_inplace */
379 0xfff, /* src_mask */
380 0xfff, /* dst_mask */
381 FALSE
), /* pcrel_offset */
383 /* The upper 16 bits of the GOT offset for the address of the
385 HOWTO (R_FRV_GOTOFFHI
, /* type */
387 2, /* size (0 = byte, 1 = short, 2 = long) */
389 FALSE
, /* pc_relative */
391 complain_overflow_dont
, /* complain_on_overflow */
392 bfd_elf_generic_reloc
, /* special_function */
393 "R_FRV_GOTOFFHI", /* name */
394 FALSE
, /* partial_inplace */
395 0xffff, /* src_mask */
396 0xffff, /* dst_mask */
397 FALSE
), /* pcrel_offset */
399 /* The lower 16 bits of the GOT offset for the address of the
401 HOWTO (R_FRV_GOTOFFLO
, /* type */
403 2, /* size (0 = byte, 1 = short, 2 = long) */
405 FALSE
, /* pc_relative */
407 complain_overflow_dont
, /* complain_on_overflow */
408 bfd_elf_generic_reloc
, /* special_function */
409 "R_FRV_GOTOFFLO", /* name */
410 FALSE
, /* partial_inplace */
411 0xffff, /* src_mask */
412 0xffff, /* dst_mask */
413 FALSE
), /* pcrel_offset */
415 /* A 24-bit pc-relative relocation referencing the TLS PLT entry for
416 a thread-local symbol. If the symbol number is 0, it refers to
418 HOWTO (R_FRV_GETTLSOFF
, /* type */
420 2, /* size (0 = byte, 1 = short, 2 = long) */
422 TRUE
, /* pc_relative */
424 complain_overflow_bitfield
, /* complain_on_overflow */
425 bfd_elf_generic_reloc
, /* special_function */
426 "R_FRV_GETTLSOFF", /* name */
427 FALSE
, /* partial_inplace */
428 0x7e03ffff, /* src_mask */
429 0x7e03ffff, /* dst_mask */
430 TRUE
), /* pcrel_offset */
432 /* A 64-bit TLS descriptor for a symbol. This relocation is only
433 valid as a REL, dynamic relocation. */
434 HOWTO (R_FRV_TLSDESC_VALUE
, /* type */
436 2, /* size (0 = byte, 1 = short, 2 = long) */
438 FALSE
, /* pc_relative */
440 complain_overflow_bitfield
, /* complain_on_overflow */
441 bfd_elf_generic_reloc
, /* special_function */
442 "R_FRV_TLSDESC_VALUE", /* name */
443 FALSE
, /* partial_inplace */
444 0xffffffff, /* src_mask */
445 0xffffffff, /* dst_mask */
446 FALSE
), /* pcrel_offset */
448 /* A 12-bit signed operand with the GOT offset for the TLS
449 descriptor of the symbol. */
450 HOWTO (R_FRV_GOTTLSDESC12
, /* type */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
454 FALSE
, /* pc_relative */
456 complain_overflow_signed
, /* complain_on_overflow */
457 bfd_elf_generic_reloc
, /* special_function */
458 "R_FRV_GOTTLSDESC12", /* name */
459 FALSE
, /* partial_inplace */
460 0xfff, /* src_mask */
461 0xfff, /* dst_mask */
462 FALSE
), /* pcrel_offset */
464 /* The upper 16 bits of the GOT offset for the TLS descriptor of the
466 HOWTO (R_FRV_GOTTLSDESCHI
, /* type */
468 2, /* size (0 = byte, 1 = short, 2 = long) */
470 FALSE
, /* pc_relative */
472 complain_overflow_dont
, /* complain_on_overflow */
473 bfd_elf_generic_reloc
, /* special_function */
474 "R_FRV_GOTTLSDESCHI", /* name */
475 FALSE
, /* partial_inplace */
476 0xffff, /* src_mask */
477 0xffff, /* dst_mask */
478 FALSE
), /* pcrel_offset */
480 /* The lower 16 bits of the GOT offset for the TLS descriptor of the
482 HOWTO (R_FRV_GOTTLSDESCLO
, /* type */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
486 FALSE
, /* pc_relative */
488 complain_overflow_dont
, /* complain_on_overflow */
489 bfd_elf_generic_reloc
, /* special_function */
490 "R_FRV_GOTTLSDESCLO", /* name */
491 FALSE
, /* partial_inplace */
492 0xffff, /* src_mask */
493 0xffff, /* dst_mask */
494 FALSE
), /* pcrel_offset */
496 /* A 12-bit signed operand with the offset from the module base
497 address to the thread-local symbol address. */
498 HOWTO (R_FRV_TLSMOFF12
, /* type */
500 2, /* size (0 = byte, 1 = short, 2 = long) */
502 FALSE
, /* pc_relative */
504 complain_overflow_signed
, /* complain_on_overflow */
505 bfd_elf_generic_reloc
, /* special_function */
506 "R_FRV_TLSMOFF12", /* name */
507 FALSE
, /* partial_inplace */
508 0xfff, /* src_mask */
509 0xfff, /* dst_mask */
510 FALSE
), /* pcrel_offset */
512 /* The upper 16 bits of the offset from the module base address to
513 the thread-local symbol address. */
514 HOWTO (R_FRV_TLSMOFFHI
, /* type */
516 2, /* size (0 = byte, 1 = short, 2 = long) */
518 FALSE
, /* pc_relative */
520 complain_overflow_dont
, /* complain_on_overflow */
521 bfd_elf_generic_reloc
, /* special_function */
522 "R_FRV_TLSMOFFHI", /* name */
523 FALSE
, /* partial_inplace */
524 0xffff, /* src_mask */
525 0xffff, /* dst_mask */
526 FALSE
), /* pcrel_offset */
528 /* The lower 16 bits of the offset from the module base address to
529 the thread-local symbol address. */
530 HOWTO (R_FRV_TLSMOFFLO
, /* type */
532 2, /* size (0 = byte, 1 = short, 2 = long) */
534 FALSE
, /* pc_relative */
536 complain_overflow_dont
, /* complain_on_overflow */
537 bfd_elf_generic_reloc
, /* special_function */
538 "R_FRV_TLSMOFFLO", /* name */
539 FALSE
, /* partial_inplace */
540 0xffff, /* src_mask */
541 0xffff, /* dst_mask */
542 FALSE
), /* pcrel_offset */
544 /* A 12-bit signed operand with the GOT offset for the TLSOFF entry
546 HOWTO (R_FRV_GOTTLSOFF12
, /* type */
548 2, /* size (0 = byte, 1 = short, 2 = long) */
550 FALSE
, /* pc_relative */
552 complain_overflow_signed
, /* complain_on_overflow */
553 bfd_elf_generic_reloc
, /* special_function */
554 "R_FRV_GOTTLSOFF12", /* name */
555 FALSE
, /* partial_inplace */
556 0xfff, /* src_mask */
557 0xfff, /* dst_mask */
558 FALSE
), /* pcrel_offset */
560 /* The upper 16 bits of the GOT offset for the TLSOFF entry for a
562 HOWTO (R_FRV_GOTTLSOFFHI
, /* type */
564 2, /* size (0 = byte, 1 = short, 2 = long) */
566 FALSE
, /* pc_relative */
568 complain_overflow_dont
, /* complain_on_overflow */
569 bfd_elf_generic_reloc
, /* special_function */
570 "R_FRV_GOTTLSOFFHI", /* name */
571 FALSE
, /* partial_inplace */
572 0xffff, /* src_mask */
573 0xffff, /* dst_mask */
574 FALSE
), /* pcrel_offset */
576 /* The lower 16 bits of the GOT offset for the TLSOFF entry for a
578 HOWTO (R_FRV_GOTTLSOFFLO
, /* type */
580 2, /* size (0 = byte, 1 = short, 2 = long) */
582 FALSE
, /* pc_relative */
584 complain_overflow_dont
, /* complain_on_overflow */
585 bfd_elf_generic_reloc
, /* special_function */
586 "R_FRV_GOTTLSOFFLO", /* name */
587 FALSE
, /* partial_inplace */
588 0xffff, /* src_mask */
589 0xffff, /* dst_mask */
590 FALSE
), /* pcrel_offset */
592 /* The 32-bit offset from the thread pointer (not the module base
593 address) to a thread-local symbol. */
594 HOWTO (R_FRV_TLSOFF
, /* type */
596 2, /* size (0 = byte, 1 = short, 2 = long) */
598 FALSE
, /* pc_relative */
600 complain_overflow_dont
, /* complain_on_overflow */
601 bfd_elf_generic_reloc
, /* special_function */
602 "R_FRV_TLSOFF", /* name */
603 FALSE
, /* partial_inplace */
604 0xffffffff, /* src_mask */
605 0xffffffff, /* dst_mask */
606 FALSE
), /* pcrel_offset */
608 /* An annotation for linker relaxation, that denotes the
609 symbol+addend whose TLS descriptor is referenced by the sum of
610 the two input registers of an ldd instruction. */
611 HOWTO (R_FRV_TLSDESC_RELAX
, /* type */
613 2, /* size (0 = byte, 1 = short, 2 = long) */
615 FALSE
, /* pc_relative */
617 complain_overflow_dont
, /* complain_on_overflow */
618 bfd_elf_generic_reloc
, /* special_function */
619 "R_FRV_TLSDESC_RELAX", /* name */
620 FALSE
, /* partial_inplace */
623 FALSE
), /* pcrel_offset */
625 /* An annotation for linker relaxation, that denotes the
626 symbol+addend whose TLS resolver entry point is given by the sum
627 of the two register operands of an calll instruction. */
628 HOWTO (R_FRV_GETTLSOFF_RELAX
, /* type */
630 2, /* size (0 = byte, 1 = short, 2 = long) */
632 FALSE
, /* pc_relative */
634 complain_overflow_dont
, /* complain_on_overflow */
635 bfd_elf_generic_reloc
, /* special_function */
636 "R_FRV_GETTLSOFF_RELAX", /* name */
637 FALSE
, /* partial_inplace */
640 FALSE
), /* pcrel_offset */
642 /* An annotation for linker relaxation, that denotes the
643 symbol+addend whose TLS offset GOT entry is given by the sum of
644 the two input registers of an ld instruction. */
645 HOWTO (R_FRV_TLSOFF_RELAX
, /* type */
647 2, /* size (0 = byte, 1 = short, 2 = long) */
649 FALSE
, /* pc_relative */
651 complain_overflow_bitfield
, /* complain_on_overflow */
652 bfd_elf_generic_reloc
, /* special_function */
653 "R_FRV_TLSOFF_RELAX", /* name */
654 FALSE
, /* partial_inplace */
657 FALSE
), /* pcrel_offset */
659 /* A 32-bit offset from the module base address to
660 the thread-local symbol address. */
661 HOWTO (R_FRV_TLSMOFF
, /* type */
663 2, /* size (0 = byte, 1 = short, 2 = long) */
665 FALSE
, /* pc_relative */
667 complain_overflow_dont
, /* complain_on_overflow */
668 bfd_elf_generic_reloc
, /* special_function */
669 "R_FRV_TLSMOFF", /* name */
670 FALSE
, /* partial_inplace */
671 0xffffffff, /* src_mask */
672 0xffffffff, /* dst_mask */
673 FALSE
), /* pcrel_offset */
676 /* GNU extension to record C++ vtable hierarchy. */
677 static reloc_howto_type elf32_frv_vtinherit_howto
=
678 HOWTO (R_FRV_GNU_VTINHERIT
, /* type */
680 2, /* size (0 = byte, 1 = short, 2 = long) */
682 FALSE
, /* pc_relative */
684 complain_overflow_dont
, /* complain_on_overflow */
685 NULL
, /* special_function */
686 "R_FRV_GNU_VTINHERIT", /* name */
687 FALSE
, /* partial_inplace */
690 FALSE
); /* pcrel_offset */
692 /* GNU extension to record C++ vtable member usage. */
693 static reloc_howto_type elf32_frv_vtentry_howto
=
694 HOWTO (R_FRV_GNU_VTENTRY
, /* type */
696 2, /* size (0 = byte, 1 = short, 2 = long) */
698 FALSE
, /* pc_relative */
700 complain_overflow_dont
, /* complain_on_overflow */
701 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
702 "R_FRV_GNU_VTENTRY", /* name */
703 FALSE
, /* partial_inplace */
706 FALSE
); /* pcrel_offset */
708 /* The following 3 relocations are REL. The only difference to the
709 entries in the table above are that partial_inplace is TRUE. */
710 static reloc_howto_type elf32_frv_rel_32_howto
=
711 HOWTO (R_FRV_32
, /* type */
713 2, /* size (0 = byte, 1 = short, 2 = long) */
715 FALSE
, /* pc_relative */
717 complain_overflow_bitfield
, /* complain_on_overflow */
718 bfd_elf_generic_reloc
, /* special_function */
719 "R_FRV_32", /* name */
720 TRUE
, /* partial_inplace */
721 0xffffffff, /* src_mask */
722 0xffffffff, /* dst_mask */
723 FALSE
); /* pcrel_offset */
725 static reloc_howto_type elf32_frv_rel_funcdesc_howto
=
726 HOWTO (R_FRV_FUNCDESC
, /* type */
728 2, /* size (0 = byte, 1 = short, 2 = long) */
730 FALSE
, /* pc_relative */
732 complain_overflow_bitfield
, /* complain_on_overflow */
733 bfd_elf_generic_reloc
, /* special_function */
734 "R_FRV_FUNCDESC", /* name */
735 TRUE
, /* partial_inplace */
736 0xffffffff, /* src_mask */
737 0xffffffff, /* dst_mask */
738 FALSE
); /* pcrel_offset */
740 static reloc_howto_type elf32_frv_rel_funcdesc_value_howto
=
741 HOWTO (R_FRV_FUNCDESC_VALUE
, /* type */
743 2, /* size (0 = byte, 1 = short, 2 = long) */
745 FALSE
, /* pc_relative */
747 complain_overflow_bitfield
, /* complain_on_overflow */
748 bfd_elf_generic_reloc
, /* special_function */
749 "R_FRV_FUNCDESC_VALUE", /* name */
750 TRUE
, /* partial_inplace */
751 0xffffffff, /* src_mask */
752 0xffffffff, /* dst_mask */
753 FALSE
); /* pcrel_offset */
755 static reloc_howto_type elf32_frv_rel_tlsdesc_value_howto
=
756 /* A 64-bit TLS descriptor for a symbol. The first word resolves to
757 an entry point, and the second resolves to a special argument.
758 If the symbol turns out to be in static TLS, the entry point is a
759 return instruction, and the special argument is the TLS offset
760 for the symbol. If it's in dynamic TLS, the entry point is a TLS
761 offset resolver, and the special argument is a pointer to a data
762 structure allocated by the dynamic loader, containing the GOT
763 address for the offset resolver, the module id, the offset within
764 the module, and anything else the TLS offset resolver might need
765 to determine the TLS offset for the symbol in the running
767 HOWTO (R_FRV_TLSDESC_VALUE
, /* type */
769 2, /* size (0 = byte, 1 = short, 2 = long) */
771 FALSE
, /* pc_relative */
773 complain_overflow_bitfield
, /* complain_on_overflow */
774 bfd_elf_generic_reloc
, /* special_function */
775 "R_FRV_TLSDESC_VALUE", /* name */
776 TRUE
, /* partial_inplace */
777 0xffffffff, /* src_mask */
778 0xffffffff, /* dst_mask */
779 FALSE
); /* pcrel_offset */
781 static reloc_howto_type elf32_frv_rel_tlsoff_howto
=
782 /* The 32-bit offset from the thread pointer (not the module base
783 address) to a thread-local symbol. */
784 HOWTO (R_FRV_TLSOFF
, /* type */
786 2, /* size (0 = byte, 1 = short, 2 = long) */
788 FALSE
, /* pc_relative */
790 complain_overflow_bitfield
, /* complain_on_overflow */
791 bfd_elf_generic_reloc
, /* special_function */
792 "R_FRV_TLSOFF", /* name */
793 TRUE
, /* partial_inplace */
794 0xffffffff, /* src_mask */
795 0xffffffff, /* dst_mask */
796 FALSE
); /* pcrel_offset */
800 extern const bfd_target frv_elf32_fdpic_vec
;
801 #define IS_FDPIC(bfd) ((bfd)->xvec == &frv_elf32_fdpic_vec)
803 /* An extension of the elf hash table data structure, containing some
804 additional FRV-specific data. */
805 struct frvfdpic_elf_link_hash_table
807 struct elf_link_hash_table elf
;
809 /* A pointer to the .rofixup section. */
811 /* GOT base offset. */
813 /* Location of the first non-lazy PLT entry, i.e., the number of
814 bytes taken by lazy PLT entries. If locally-bound TLS
815 descriptors require a ret instruction, it will be placed at this
818 /* A hash table holding information about which symbols were
819 referenced with which PIC-related relocations. */
820 struct htab
*relocs_info
;
821 /* Summary reloc information collected by
822 _frvfdpic_count_got_plt_entries. */
823 struct _frvfdpic_dynamic_got_info
*g
;
826 /* Get the FRV ELF linker hash table from a link_info structure. */
828 #define frvfdpic_hash_table(p) \
829 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
830 == FRV_ELF_DATA ? ((struct frvfdpic_elf_link_hash_table *) ((p)->hash)) : NULL)
832 #define frvfdpic_got_section(info) \
833 (frvfdpic_hash_table (info)->elf.sgot)
834 #define frvfdpic_gotrel_section(info) \
835 (frvfdpic_hash_table (info)->elf.srelgot)
836 #define frvfdpic_gotfixup_section(info) \
837 (frvfdpic_hash_table (info)->sgotfixup)
838 #define frvfdpic_plt_section(info) \
839 (frvfdpic_hash_table (info)->elf.splt)
840 #define frvfdpic_pltrel_section(info) \
841 (frvfdpic_hash_table (info)->elf.srelplt)
842 #define frvfdpic_relocs_info(info) \
843 (frvfdpic_hash_table (info)->relocs_info)
844 #define frvfdpic_got_initial_offset(info) \
845 (frvfdpic_hash_table (info)->got0)
846 #define frvfdpic_plt_initial_offset(info) \
847 (frvfdpic_hash_table (info)->plt0)
848 #define frvfdpic_dynamic_got_plt_info(info) \
849 (frvfdpic_hash_table (info)->g)
851 /* Currently it's the same, but if some day we have a reason to change
852 it, we'd better be using a different macro.
854 FIXME: if there's any TLS PLT entry that uses local-exec or
855 initial-exec models, we could use the ret at the end of any of them
856 instead of adding one more. */
857 #define frvfdpic_plt_tls_ret_offset(info) \
858 (frvfdpic_plt_initial_offset (info))
860 /* The name of the dynamic interpreter. This is put in the .interp
863 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
865 #define DEFAULT_STACK_SIZE 0x20000
867 /* This structure is used to collect the number of entries present in
868 each addressable range of the got. */
869 struct _frvfdpic_dynamic_got_info
871 /* Several bits of information about the current link. */
872 struct bfd_link_info
*info
;
873 /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit
875 bfd_vma got12
, gotlos
, gothilo
;
876 /* Total GOT size needed for function descriptor entries within the 12-,
877 16- or 32-bit ranges. */
878 bfd_vma fd12
, fdlos
, fdhilo
;
879 /* Total GOT size needed by function descriptor entries referenced
880 in PLT entries, that would be profitable to place in offsets
881 close to the PIC register. */
883 /* Total PLT size needed by lazy PLT entries. */
885 /* Total GOT size needed for TLS descriptor entries within the 12-,
886 16- or 32-bit ranges. */
887 bfd_vma tlsd12
, tlsdlos
, tlsdhilo
;
888 /* Total GOT size needed by TLS descriptors referenced in PLT
889 entries, that would be profitable to place in offers close to the
892 /* Total PLT size needed by TLS lazy PLT entries. */
894 /* Number of relocations carried over from input object files. */
895 unsigned long relocs
;
896 /* Number of fixups introduced by relocations in input object files. */
897 unsigned long fixups
;
898 /* The number of fixups that reference the ret instruction added to
899 the PLT for locally-resolved TLS descriptors. */
900 unsigned long tls_ret_refs
;
903 /* This structure is used to assign offsets to got entries, function
904 descriptors, plt entries and lazy plt entries. */
906 struct _frvfdpic_dynamic_got_plt_info
908 /* Summary information collected with _frvfdpic_count_got_plt_entries. */
909 struct _frvfdpic_dynamic_got_info g
;
911 /* For each addressable range, we record a MAX (positive) and MIN
912 (negative) value. CUR is used to assign got entries, and it's
913 incremented from an initial positive value to MAX, then from MIN
914 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
915 assign function descriptors, and it's decreased from an initial
916 non-positive value to MIN, then from MAX down to CUR (unless CUR
917 wraps around first). All of MIN, MAX, CUR and FDCUR always point
918 to even words. ODD, if non-zero, indicates an odd word to be
919 used for the next got entry, otherwise CUR is used and
920 incremented by a pair of words, wrapping around when it reaches
921 MAX. FDCUR is decremented (and wrapped) before the next function
922 descriptor is chosen. FDPLT indicates the number of remaining
923 slots that can be used for function descriptors used only by PLT
926 TMAX, TMIN and TCUR are used to assign TLS descriptors. TCUR
927 starts as MAX, and grows up to TMAX, then wraps around to TMIN
928 and grows up to MIN. TLSDPLT indicates the number of remaining
929 slots that can be used for TLS descriptors used only by TLS PLT
931 struct _frvfdpic_dynamic_got_alloc_data
933 bfd_signed_vma max
, cur
, odd
, fdcur
, min
;
934 bfd_signed_vma tmax
, tcur
, tmin
;
935 bfd_vma fdplt
, tlsdplt
;
936 } got12
, gotlos
, gothilo
;
939 /* Create an FRV ELF linker hash table. */
941 static struct bfd_link_hash_table
*
942 frvfdpic_elf_link_hash_table_create (bfd
*abfd
)
944 struct frvfdpic_elf_link_hash_table
*ret
;
945 bfd_size_type amt
= sizeof (struct frvfdpic_elf_link_hash_table
);
947 ret
= bfd_zmalloc (amt
);
951 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
952 _bfd_elf_link_hash_newfunc
,
953 sizeof (struct elf_link_hash_entry
),
960 return &ret
->elf
.root
;
963 /* Decide whether a reference to a symbol can be resolved locally or
964 not. If the symbol is protected, we want the local address, but
965 its function descriptor must be assigned by the dynamic linker. */
966 #define FRVFDPIC_SYM_LOCAL(INFO, H) \
967 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
968 || ! elf_hash_table (INFO)->dynamic_sections_created)
969 #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \
970 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
972 /* This structure collects information on what kind of GOT, PLT or
973 function descriptors are required by relocations that reference a
975 struct frvfdpic_relocs_info
977 /* The index of the symbol, as stored in the relocation r_info, if
978 we have a local symbol; -1 otherwise. */
982 /* The input bfd in which the symbol is defined, if it's a local
985 /* If symndx == -1, the hash table entry corresponding to a global
986 symbol (even if it turns out to bind locally, in which case it
987 should ideally be replaced with section's symndx + addend). */
988 struct elf_link_hash_entry
*h
;
990 /* The addend of the relocation that references the symbol. */
993 /* The fields above are used to identify an entry. The fields below
994 contain information on how an entry is used and, later on, which
995 locations it was assigned. */
996 /* The following 3 fields record whether the symbol+addend above was
997 ever referenced with a GOT relocation. The 12 suffix indicates a
998 GOT12 relocation; los is used for GOTLO relocations that are not
999 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
1004 /* Whether a FUNCDESC relocation references symbol+addend. */
1006 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
1008 unsigned fdgotlos
:1;
1009 unsigned fdgothilo
:1;
1010 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
1011 unsigned fdgoff12
:1;
1012 unsigned fdgofflos
:1;
1013 unsigned fdgoffhilo
:1;
1014 /* Whether a GETTLSOFF relocation references symbol+addend. */
1016 /* FIXME: we should probably add tlspltdesc, tlspltoff and
1017 tlspltimm, to tell what kind of TLS PLT entry we're generating.
1018 We might instead just pre-compute flags telling whether the
1019 object is suitable for local exec, initial exec or general
1020 dynamic addressing, and use that all over the place. We could
1021 also try to do a better job of merging TLSOFF and TLSDESC entries
1022 in main executables, but perhaps we can get rid of TLSDESC
1023 entirely in them instead. */
1024 /* Whether a GOTTLSDESC relocation references symbol+addend. */
1025 unsigned tlsdesc12
:1;
1026 unsigned tlsdesclos
:1;
1027 unsigned tlsdeschilo
:1;
1028 /* Whether a GOTTLSOFF relocation references symbol+addend. */
1029 unsigned tlsoff12
:1;
1030 unsigned tlsofflos
:1;
1031 unsigned tlsoffhilo
:1;
1032 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
1033 GOTOFFHI relocations. The addend doesn't really matter, since we
1034 envision that this will only be used to check whether the symbol
1035 is mapped to the same segment as the got. */
1037 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
1039 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
1042 /* Whether we need a PLT entry for a symbol. Should be implied by
1044 (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */
1046 /* Whether a function descriptor should be created in this link unit
1047 for symbol+addend. Should be implied by something like:
1048 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
1049 || ((fd || fdgot12 || fdgotlos || fdgothilo)
1050 && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */
1052 /* Whether a lazy PLT entry is needed for this symbol+addend.
1053 Should be implied by something like:
1054 (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)
1055 && ! (info->flags & DF_BIND_NOW)) */
1057 /* Whether we've already emitted GOT relocations and PLT entries as
1058 needed for this symbol. */
1061 /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and
1062 R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing
1064 unsigned relocs32
, relocsfd
, relocsfdv
, relocstlsd
, relocstlsoff
;
1066 /* The number of .rofixups entries and dynamic relocations allocated
1067 for this symbol, minus any that might have already been used. */
1068 unsigned fixups
, dynrelocs
;
1070 /* The offsets of the GOT entries assigned to symbol+addend, to the
1071 function descriptor's address, and to a function descriptor,
1072 respectively. Should be zero if unassigned. The offsets are
1073 counted from the value that will be assigned to the PIC register,
1074 not from the beginning of the .got section. */
1075 bfd_signed_vma got_entry
, fdgot_entry
, fd_entry
;
1076 /* The offsets of the PLT entries assigned to symbol+addend,
1077 non-lazy and lazy, respectively. If unassigned, should be
1079 bfd_vma plt_entry
, lzplt_entry
;
1080 /* The offsets of the GOT entries for TLS offset and TLS descriptor. */
1081 bfd_signed_vma tlsoff_entry
, tlsdesc_entry
;
1082 /* The offset of the TLS offset PLT entry. */
1083 bfd_vma tlsplt_entry
;
1086 /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */
1088 frvfdpic_relocs_info_hash (const void *entry_
)
1090 const struct frvfdpic_relocs_info
*entry
= entry_
;
1092 return (entry
->symndx
== -1
1093 ? (long) entry
->d
.h
->root
.root
.hash
1094 : entry
->symndx
+ (long) entry
->d
.abfd
->id
* 257) + entry
->addend
;
1097 /* Test whether the key fields of two frvfdpic_relocs_info entries are
1100 frvfdpic_relocs_info_eq (const void *entry1
, const void *entry2
)
1102 const struct frvfdpic_relocs_info
*e1
= entry1
;
1103 const struct frvfdpic_relocs_info
*e2
= entry2
;
1105 return e1
->symndx
== e2
->symndx
&& e1
->addend
== e2
->addend
1106 && (e1
->symndx
== -1 ? e1
->d
.h
== e2
->d
.h
: e1
->d
.abfd
== e2
->d
.abfd
);
1109 /* Find or create an entry in a hash table HT that matches the key
1110 fields of the given ENTRY. If it's not found, memory for a new
1111 entry is allocated in ABFD's obstack. */
1112 static struct frvfdpic_relocs_info
*
1113 frvfdpic_relocs_info_find (struct htab
*ht
,
1115 const struct frvfdpic_relocs_info
*entry
,
1116 enum insert_option insert
)
1118 struct frvfdpic_relocs_info
**loc
=
1119 (struct frvfdpic_relocs_info
**) htab_find_slot (ht
, entry
, insert
);
1127 *loc
= bfd_zalloc (abfd
, sizeof (**loc
));
1132 (*loc
)->symndx
= entry
->symndx
;
1133 (*loc
)->d
= entry
->d
;
1134 (*loc
)->addend
= entry
->addend
;
1135 (*loc
)->plt_entry
= (bfd_vma
)-1;
1136 (*loc
)->lzplt_entry
= (bfd_vma
)-1;
1137 (*loc
)->tlsplt_entry
= (bfd_vma
)-1;
1142 /* Obtain the address of the entry in HT associated with H's symbol +
1143 addend, creating a new entry if none existed. ABFD is only used
1144 for memory allocation purposes. */
1145 inline static struct frvfdpic_relocs_info
*
1146 frvfdpic_relocs_info_for_global (struct htab
*ht
,
1148 struct elf_link_hash_entry
*h
,
1150 enum insert_option insert
)
1152 struct frvfdpic_relocs_info entry
;
1156 entry
.addend
= addend
;
1158 return frvfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1161 /* Obtain the address of the entry in HT associated with the SYMNDXth
1162 local symbol of the input bfd ABFD, plus the addend, creating a new
1163 entry if none existed. */
1164 inline static struct frvfdpic_relocs_info
*
1165 frvfdpic_relocs_info_for_local (struct htab
*ht
,
1169 enum insert_option insert
)
1171 struct frvfdpic_relocs_info entry
;
1173 entry
.symndx
= symndx
;
1174 entry
.d
.abfd
= abfd
;
1175 entry
.addend
= addend
;
1177 return frvfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1180 /* Merge fields set by check_relocs() of two entries that end up being
1181 mapped to the same (presumably global) symbol. */
1184 frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info
*e2
,
1185 struct frvfdpic_relocs_info
const *e1
)
1187 e2
->got12
|= e1
->got12
;
1188 e2
->gotlos
|= e1
->gotlos
;
1189 e2
->gothilo
|= e1
->gothilo
;
1191 e2
->fdgot12
|= e1
->fdgot12
;
1192 e2
->fdgotlos
|= e1
->fdgotlos
;
1193 e2
->fdgothilo
|= e1
->fdgothilo
;
1194 e2
->fdgoff12
|= e1
->fdgoff12
;
1195 e2
->fdgofflos
|= e1
->fdgofflos
;
1196 e2
->fdgoffhilo
|= e1
->fdgoffhilo
;
1197 e2
->tlsplt
|= e1
->tlsplt
;
1198 e2
->tlsdesc12
|= e1
->tlsdesc12
;
1199 e2
->tlsdesclos
|= e1
->tlsdesclos
;
1200 e2
->tlsdeschilo
|= e1
->tlsdeschilo
;
1201 e2
->tlsoff12
|= e1
->tlsoff12
;
1202 e2
->tlsofflos
|= e1
->tlsofflos
;
1203 e2
->tlsoffhilo
|= e1
->tlsoffhilo
;
1204 e2
->gotoff
|= e1
->gotoff
;
1205 e2
->call
|= e1
->call
;
1209 /* Every block of 65535 lazy PLT entries shares a single call to the
1210 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
1211 32767, counting from 0). All other lazy PLT entries branch to it
1212 in a single instruction. */
1214 #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
1215 #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767)
1217 /* Add a dynamic relocation to the SRELOC section. */
1219 inline static bfd_vma
1220 _frvfdpic_add_dyn_reloc (bfd
*output_bfd
, asection
*sreloc
, bfd_vma offset
,
1221 int reloc_type
, long dynindx
, bfd_vma addend
,
1222 struct frvfdpic_relocs_info
*entry
)
1224 Elf_Internal_Rela outrel
;
1225 bfd_vma reloc_offset
;
1227 outrel
.r_offset
= offset
;
1228 outrel
.r_info
= ELF32_R_INFO (dynindx
, reloc_type
);
1229 outrel
.r_addend
= addend
;
1231 reloc_offset
= sreloc
->reloc_count
* sizeof (Elf32_External_Rel
);
1232 BFD_ASSERT (reloc_offset
< sreloc
->size
);
1233 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
1234 sreloc
->contents
+ reloc_offset
);
1235 sreloc
->reloc_count
++;
1237 /* If the entry's index is zero, this relocation was probably to a
1238 linkonce section that got discarded. We reserved a dynamic
1239 relocation, but it was for another entry than the one we got at
1240 the time of emitting the relocation. Unfortunately there's no
1241 simple way for us to catch this situation, since the relocation
1242 is cleared right before calling relocate_section, at which point
1243 we no longer know what the relocation used to point to. */
1246 BFD_ASSERT (entry
->dynrelocs
> 0);
1250 return reloc_offset
;
1253 /* Add a fixup to the ROFIXUP section. */
1256 _frvfdpic_add_rofixup (bfd
*output_bfd
, asection
*rofixup
, bfd_vma offset
,
1257 struct frvfdpic_relocs_info
*entry
)
1259 bfd_vma fixup_offset
;
1261 if (rofixup
->flags
& SEC_EXCLUDE
)
1264 fixup_offset
= rofixup
->reloc_count
* 4;
1265 if (rofixup
->contents
)
1267 BFD_ASSERT (fixup_offset
< rofixup
->size
);
1268 bfd_put_32 (output_bfd
, offset
, rofixup
->contents
+ fixup_offset
);
1270 rofixup
->reloc_count
++;
1272 if (entry
&& entry
->symndx
)
1274 /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc
1276 BFD_ASSERT (entry
->fixups
> 0);
1280 return fixup_offset
;
1283 /* Find the segment number in which OSEC, and output section, is
1287 _frvfdpic_osec_to_segment (bfd
*output_bfd
, asection
*osec
)
1289 Elf_Internal_Phdr
*p
= _bfd_elf_find_segment_containing_section (output_bfd
, osec
);
1291 return (p
!= NULL
) ? p
- elf_tdata (output_bfd
)->phdr
: -1;
1294 inline static bfd_boolean
1295 _frvfdpic_osec_readonly_p (bfd
*output_bfd
, asection
*osec
)
1297 unsigned seg
= _frvfdpic_osec_to_segment (output_bfd
, osec
);
1299 return ! (elf_tdata (output_bfd
)->phdr
[seg
].p_flags
& PF_W
);
1302 #define FRVFDPIC_TLS_BIAS (2048 - 16)
1304 /* Return the base VMA address which should be subtracted from real addresses
1305 when resolving TLSMOFF relocation.
1306 This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */
1309 tls_biased_base (struct bfd_link_info
*info
)
1311 /* If tls_sec is NULL, we should have signalled an error already. */
1312 if (elf_hash_table (info
)->tls_sec
== NULL
)
1313 return FRVFDPIC_TLS_BIAS
;
1314 return elf_hash_table (info
)->tls_sec
->vma
+ FRVFDPIC_TLS_BIAS
;
1317 /* Generate relocations for GOT entries, function descriptors, and
1318 code for PLT and lazy PLT entries. */
1320 inline static bfd_boolean
1321 _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info
*entry
,
1323 struct bfd_link_info
*info
,
1325 Elf_Internal_Sym
*sym
,
1329 bfd_vma fd_lazy_rel_offset
= (bfd_vma
)-1;
1336 if (entry
->got_entry
|| entry
->fdgot_entry
|| entry
->fd_entry
1337 || entry
->tlsoff_entry
|| entry
->tlsdesc_entry
)
1339 /* If the symbol is dynamic, consider it for dynamic
1340 relocations, otherwise decay to section + offset. */
1341 if (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1)
1342 dynindx
= entry
->d
.h
->dynindx
;
1346 && sec
->output_section
1347 && ! bfd_is_abs_section (sec
->output_section
)
1348 && ! bfd_is_und_section (sec
->output_section
))
1349 dynindx
= elf_section_data (sec
->output_section
)->dynindx
;
1355 /* Generate relocation for GOT entry pointing to the symbol. */
1356 if (entry
->got_entry
)
1359 bfd_vma ad
= addend
;
1361 /* If the symbol is dynamic but binds locally, use
1363 if (sec
&& (entry
->symndx
!= -1
1364 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1366 if (entry
->symndx
== -1)
1367 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1369 ad
+= sym
->st_value
;
1370 ad
+= sec
->output_offset
;
1371 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1372 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1377 /* If we're linking an executable at a fixed address, we can
1378 omit the dynamic relocation as long as the symbol is local to
1380 if (bfd_link_pde (info
)
1381 && (entry
->symndx
!= -1
1382 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1385 ad
+= sec
->output_section
->vma
;
1386 if (entry
->symndx
!= -1
1387 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1388 _frvfdpic_add_rofixup (output_bfd
,
1389 frvfdpic_gotfixup_section (info
),
1390 frvfdpic_got_section (info
)->output_section
1392 + frvfdpic_got_section (info
)->output_offset
1393 + frvfdpic_got_initial_offset (info
)
1394 + entry
->got_entry
, entry
);
1397 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1398 _bfd_elf_section_offset
1400 frvfdpic_got_section (info
),
1401 frvfdpic_got_initial_offset (info
)
1403 + frvfdpic_got_section (info
)
1404 ->output_section
->vma
1405 + frvfdpic_got_section (info
)->output_offset
,
1406 R_FRV_32
, idx
, ad
, entry
);
1408 bfd_put_32 (output_bfd
, ad
,
1409 frvfdpic_got_section (info
)->contents
1410 + frvfdpic_got_initial_offset (info
)
1411 + entry
->got_entry
);
1414 /* Generate relocation for GOT entry pointing to a canonical
1415 function descriptor. */
1416 if (entry
->fdgot_entry
)
1421 if (! (entry
->symndx
== -1
1422 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
1423 && FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1425 /* If the symbol is dynamic and there may be dynamic symbol
1426 resolution because we are, or are linked with, a shared
1427 library, emit a FUNCDESC relocation such that the dynamic
1428 linker will allocate the function descriptor. If the
1429 symbol needs a non-local function descriptor but binds
1430 locally (e.g., its visibility is protected, emit a
1431 dynamic relocation decayed to section+offset. */
1432 if (entry
->symndx
== -1
1433 && ! FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)
1434 && FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)
1435 && !bfd_link_pde (info
))
1437 reloc
= R_FRV_FUNCDESC
;
1438 idx
= elf_section_data (entry
->d
.h
->root
.u
.def
.section
1439 ->output_section
)->dynindx
;
1440 ad
= entry
->d
.h
->root
.u
.def
.section
->output_offset
1441 + entry
->d
.h
->root
.u
.def
.value
;
1443 else if (entry
->symndx
== -1
1444 && ! FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
))
1446 reloc
= R_FRV_FUNCDESC
;
1451 (*info
->callbacks
->reloc_dangerous
)
1452 (info
, _("relocation requires zero addend"),
1453 elf_hash_table (info
)->dynobj
,
1454 frvfdpic_got_section (info
),
1455 entry
->fdgot_entry
);
1461 /* Otherwise, we know we have a private function descriptor,
1462 so reference it directly. */
1463 if (elf_hash_table (info
)->dynamic_sections_created
)
1464 BFD_ASSERT (entry
->privfd
);
1466 idx
= elf_section_data (frvfdpic_got_section (info
)
1467 ->output_section
)->dynindx
;
1468 ad
= frvfdpic_got_section (info
)->output_offset
1469 + frvfdpic_got_initial_offset (info
) + entry
->fd_entry
;
1472 /* If there is room for dynamic symbol resolution, emit the
1473 dynamic relocation. However, if we're linking an
1474 executable at a fixed location, we won't have emitted a
1475 dynamic symbol entry for the got section, so idx will be
1476 zero, which means we can and should compute the address
1477 of the private descriptor ourselves. */
1478 if (bfd_link_pde (info
)
1479 && (entry
->symndx
!= -1
1480 || FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)))
1482 ad
+= frvfdpic_got_section (info
)->output_section
->vma
;
1483 _frvfdpic_add_rofixup (output_bfd
,
1484 frvfdpic_gotfixup_section (info
),
1485 frvfdpic_got_section (info
)
1486 ->output_section
->vma
1487 + frvfdpic_got_section (info
)
1489 + frvfdpic_got_initial_offset (info
)
1490 + entry
->fdgot_entry
, entry
);
1493 _frvfdpic_add_dyn_reloc (output_bfd
,
1494 frvfdpic_gotrel_section (info
),
1495 _bfd_elf_section_offset
1497 frvfdpic_got_section (info
),
1498 frvfdpic_got_initial_offset (info
)
1499 + entry
->fdgot_entry
)
1500 + frvfdpic_got_section (info
)
1501 ->output_section
->vma
1502 + frvfdpic_got_section (info
)
1504 reloc
, idx
, ad
, entry
);
1507 bfd_put_32 (output_bfd
, ad
,
1508 frvfdpic_got_section (info
)->contents
1509 + frvfdpic_got_initial_offset (info
)
1510 + entry
->fdgot_entry
);
1513 /* Generate relocation to fill in a private function descriptor in
1515 if (entry
->fd_entry
)
1518 bfd_vma ad
= addend
;
1520 long lowword
, highword
;
1522 /* If the symbol is dynamic but binds locally, use
1524 if (sec
&& (entry
->symndx
!= -1
1525 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1527 if (entry
->symndx
== -1)
1528 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1530 ad
+= sym
->st_value
;
1531 ad
+= sec
->output_offset
;
1532 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1533 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1538 /* If we're linking an executable at a fixed address, we can
1539 omit the dynamic relocation as long as the symbol is local to
1541 if (bfd_link_pde (info
)
1542 && (entry
->symndx
!= -1 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1545 ad
+= sec
->output_section
->vma
;
1547 if (entry
->symndx
!= -1
1548 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1550 _frvfdpic_add_rofixup (output_bfd
,
1551 frvfdpic_gotfixup_section (info
),
1552 frvfdpic_got_section (info
)
1553 ->output_section
->vma
1554 + frvfdpic_got_section (info
)
1556 + frvfdpic_got_initial_offset (info
)
1557 + entry
->fd_entry
, entry
);
1558 _frvfdpic_add_rofixup (output_bfd
,
1559 frvfdpic_gotfixup_section (info
),
1560 frvfdpic_got_section (info
)
1561 ->output_section
->vma
1562 + frvfdpic_got_section (info
)
1564 + frvfdpic_got_initial_offset (info
)
1565 + entry
->fd_entry
+ 4, entry
);
1571 _frvfdpic_add_dyn_reloc (output_bfd
,
1573 ? frvfdpic_pltrel_section (info
)
1574 : frvfdpic_gotrel_section (info
),
1575 _bfd_elf_section_offset
1577 frvfdpic_got_section (info
),
1578 frvfdpic_got_initial_offset (info
)
1580 + frvfdpic_got_section (info
)
1581 ->output_section
->vma
1582 + frvfdpic_got_section (info
)
1584 R_FRV_FUNCDESC_VALUE
, idx
, ad
, entry
);
1587 /* If we've omitted the dynamic relocation, just emit the fixed
1588 addresses of the symbol and of the local GOT base offset. */
1589 if (bfd_link_pde (info
)
1591 && sec
->output_section
)
1594 highword
= frvfdpic_got_section (info
)->output_section
->vma
1595 + frvfdpic_got_section (info
)->output_offset
1596 + frvfdpic_got_initial_offset (info
);
1598 else if (entry
->lazyplt
)
1602 (*info
->callbacks
->reloc_dangerous
)
1603 (info
, _("relocation requires zero addend"),
1604 elf_hash_table (info
)->dynobj
,
1605 frvfdpic_got_section (info
),
1610 fd_lazy_rel_offset
= ofst
;
1612 /* A function descriptor used for lazy or local resolving is
1613 initialized such that its high word contains the output
1614 section index in which the PLT entries are located, and
1615 the low word contains the address of the lazy PLT entry
1616 entry point, that must be within the memory region
1617 assigned to that section. */
1618 lowword
= entry
->lzplt_entry
+ 4
1619 + frvfdpic_plt_section (info
)->output_offset
1620 + frvfdpic_plt_section (info
)->output_section
->vma
;
1621 highword
= _frvfdpic_osec_to_segment
1622 (output_bfd
, frvfdpic_plt_section (info
)->output_section
);
1626 /* A function descriptor for a local function gets the index
1627 of the section. For a non-local function, it's
1631 || (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1
1632 && entry
->d
.h
->dynindx
== idx
))
1635 highword
= _frvfdpic_osec_to_segment
1636 (output_bfd
, sec
->output_section
);
1639 bfd_put_32 (output_bfd
, lowword
,
1640 frvfdpic_got_section (info
)->contents
1641 + frvfdpic_got_initial_offset (info
)
1643 bfd_put_32 (output_bfd
, highword
,
1644 frvfdpic_got_section (info
)->contents
1645 + frvfdpic_got_initial_offset (info
)
1646 + entry
->fd_entry
+ 4);
1649 /* Generate code for the PLT entry. */
1650 if (entry
->plt_entry
!= (bfd_vma
) -1)
1652 bfd_byte
*plt_code
= frvfdpic_plt_section (info
)->contents
1655 BFD_ASSERT (entry
->fd_entry
);
1657 /* Figure out what kind of PLT entry we need, depending on the
1658 location of the function descriptor within the GOT. */
1659 if (entry
->fd_entry
>= -(1 << (12 - 1))
1660 && entry
->fd_entry
< (1 << (12 - 1)))
1662 /* lddi @(gr15, fd_entry), gr14 */
1663 bfd_put_32 (output_bfd
,
1664 0x9cccf000 | (entry
->fd_entry
& ((1 << 12) - 1)),
1670 if (entry
->fd_entry
>= -(1 << (16 - 1))
1671 && entry
->fd_entry
< (1 << (16 - 1)))
1673 /* setlos lo(fd_entry), gr14 */
1674 bfd_put_32 (output_bfd
,
1676 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1682 /* sethi.p hi(fd_entry), gr14
1683 setlo lo(fd_entry), gr14 */
1684 bfd_put_32 (output_bfd
,
1686 | ((entry
->fd_entry
>> 16)
1687 & (((bfd_vma
)1 << 16) - 1)),
1690 bfd_put_32 (output_bfd
,
1692 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1696 /* ldd @(gr14,gr15),gr14 */
1697 bfd_put_32 (output_bfd
, 0x9c08e14f, plt_code
);
1700 /* jmpl @(gr14,gr0) */
1701 bfd_put_32 (output_bfd
, 0x8030e000, plt_code
);
1704 /* Generate code for the lazy PLT entry. */
1705 if (entry
->lzplt_entry
!= (bfd_vma
) -1)
1707 bfd_byte
*lzplt_code
= frvfdpic_plt_section (info
)->contents
1708 + entry
->lzplt_entry
;
1709 bfd_vma resolverStub_addr
;
1711 bfd_put_32 (output_bfd
, fd_lazy_rel_offset
, lzplt_code
);
1714 resolverStub_addr
= entry
->lzplt_entry
/ FRVFDPIC_LZPLT_BLOCK_SIZE
1715 * FRVFDPIC_LZPLT_BLOCK_SIZE
+ FRVFDPIC_LZPLT_RESOLV_LOC
;
1716 if (resolverStub_addr
>= frvfdpic_plt_initial_offset (info
))
1717 resolverStub_addr
= frvfdpic_plt_initial_offset (info
) - 12;
1719 if (entry
->lzplt_entry
== resolverStub_addr
)
1721 /* This is a lazy PLT entry that includes a resolver call. */
1722 /* ldd @(gr15,gr0), gr4
1724 bfd_put_32 (output_bfd
, 0x8808f140, lzplt_code
);
1725 bfd_put_32 (output_bfd
, 0x80304000, lzplt_code
+ 4);
1729 /* bra resolverStub */
1730 bfd_put_32 (output_bfd
,
1732 | (((resolverStub_addr
- entry
->lzplt_entry
)
1733 / 4) & (((bfd_vma
)1 << 16) - 1)),
1738 /* Generate relocation for GOT entry holding the TLS offset. */
1739 if (entry
->tlsoff_entry
)
1742 bfd_vma ad
= addend
;
1744 if (entry
->symndx
!= -1
1745 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
))
1747 /* If the symbol is dynamic but binds locally, use
1751 if (entry
->symndx
== -1)
1752 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1754 ad
+= sym
->st_value
;
1755 ad
+= sec
->output_offset
;
1756 if (sec
->output_section
1757 && elf_section_data (sec
->output_section
))
1758 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1764 /* *ABS*+addend is special for TLS relocations, use only the
1766 if (bfd_link_executable (info
)
1768 && (bfd_is_abs_section (sec
)
1769 || bfd_is_und_section (sec
)))
1771 /* If we're linking an executable, we can entirely omit the
1772 dynamic relocation if the symbol is local to this module. */
1773 else if (bfd_link_executable (info
)
1774 && (entry
->symndx
!= -1
1775 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1778 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1783 && (bfd_is_abs_section (sec
)
1784 || bfd_is_und_section (sec
)))
1786 if (! elf_hash_table (info
)->tls_sec
)
1788 (*info
->callbacks
->undefined_symbol
)
1789 (info
, "TLS section", elf_hash_table (info
)->dynobj
,
1790 frvfdpic_got_section (info
), entry
->tlsoff_entry
, TRUE
);
1793 idx
= elf_section_data (elf_hash_table (info
)->tls_sec
)->dynindx
;
1794 ad
+= FRVFDPIC_TLS_BIAS
;
1796 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1797 _bfd_elf_section_offset
1799 frvfdpic_got_section (info
),
1800 frvfdpic_got_initial_offset (info
)
1801 + entry
->tlsoff_entry
)
1802 + frvfdpic_got_section (info
)
1803 ->output_section
->vma
1804 + frvfdpic_got_section (info
)
1806 R_FRV_TLSOFF
, idx
, ad
, entry
);
1809 bfd_put_32 (output_bfd
, ad
,
1810 frvfdpic_got_section (info
)->contents
1811 + frvfdpic_got_initial_offset (info
)
1812 + entry
->tlsoff_entry
);
1815 if (entry
->tlsdesc_entry
)
1818 bfd_vma ad
= addend
;
1820 /* If the symbol is dynamic but binds locally, use
1822 if (sec
&& (entry
->symndx
!= -1
1823 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1825 if (entry
->symndx
== -1)
1826 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1828 ad
+= sym
->st_value
;
1829 ad
+= sec
->output_offset
;
1830 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1831 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1836 /* If we didn't set up a TLS offset entry, but we're linking an
1837 executable and the symbol binds locally, we can use the
1838 module offset in the TLS descriptor in relaxations. */
1839 if (bfd_link_executable (info
) && ! entry
->tlsoff_entry
)
1840 entry
->tlsoff_entry
= entry
->tlsdesc_entry
+ 4;
1842 if (bfd_link_pde (info
)
1844 && (bfd_is_abs_section (sec
)
1845 || bfd_is_und_section (sec
)))
1846 || entry
->symndx
!= -1
1847 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1849 /* *ABS*+addend is special for TLS relocations, use only the
1850 addend for the TLS offset, and take the module id as
1853 && (bfd_is_abs_section (sec
)
1854 || bfd_is_und_section (sec
)))
1856 /* For other TLS symbols that bind locally, add the section
1857 TLS offset to the addend. */
1859 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1861 bfd_put_32 (output_bfd
,
1862 frvfdpic_plt_section (info
)->output_section
->vma
1863 + frvfdpic_plt_section (info
)->output_offset
1864 + frvfdpic_plt_tls_ret_offset (info
),
1865 frvfdpic_got_section (info
)->contents
1866 + frvfdpic_got_initial_offset (info
)
1867 + entry
->tlsdesc_entry
);
1869 _frvfdpic_add_rofixup (output_bfd
,
1870 frvfdpic_gotfixup_section (info
),
1871 frvfdpic_got_section (info
)
1872 ->output_section
->vma
1873 + frvfdpic_got_section (info
)
1875 + frvfdpic_got_initial_offset (info
)
1876 + entry
->tlsdesc_entry
, entry
);
1878 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
);
1880 /* We've used one of the reserved fixups, so discount it so
1881 that we can check at the end that we've used them
1883 frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
--;
1885 /* While at that, make sure the ret instruction makes to the
1886 right location in the PLT. We could do it only when we
1887 got to 0, but since the check at the end will only print
1888 a warning, make sure we have the ret in place in case the
1889 warning is missed. */
1890 bfd_put_32 (output_bfd
, 0xc03a4000,
1891 frvfdpic_plt_section (info
)->contents
1892 + frvfdpic_plt_tls_ret_offset (info
));
1897 && (bfd_is_abs_section (sec
)
1898 || bfd_is_und_section (sec
)))
1900 if (! elf_hash_table (info
)->tls_sec
)
1902 (*info
->callbacks
->undefined_symbol
)
1903 (info
, "TLS section", elf_hash_table (info
)->dynobj
,
1904 frvfdpic_got_section (info
), entry
->tlsdesc_entry
, TRUE
);
1907 idx
= elf_section_data (elf_hash_table (info
)->tls_sec
)->dynindx
;
1908 ad
+= FRVFDPIC_TLS_BIAS
;
1911 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1912 _bfd_elf_section_offset
1914 frvfdpic_got_section (info
),
1915 frvfdpic_got_initial_offset (info
)
1916 + entry
->tlsdesc_entry
)
1917 + frvfdpic_got_section (info
)
1918 ->output_section
->vma
1919 + frvfdpic_got_section (info
)
1921 R_FRV_TLSDESC_VALUE
, idx
, ad
, entry
);
1923 bfd_put_32 (output_bfd
, 0,
1924 frvfdpic_got_section (info
)->contents
1925 + frvfdpic_got_initial_offset (info
)
1926 + entry
->tlsdesc_entry
);
1929 bfd_put_32 (output_bfd
, ad
,
1930 frvfdpic_got_section (info
)->contents
1931 + frvfdpic_got_initial_offset (info
)
1932 + entry
->tlsdesc_entry
+ 4);
1935 /* Generate code for the get-TLS-offset PLT entry. */
1936 if (entry
->tlsplt_entry
!= (bfd_vma
) -1)
1938 bfd_byte
*plt_code
= frvfdpic_plt_section (info
)->contents
1939 + entry
->tlsplt_entry
;
1941 if (bfd_link_executable (info
)
1942 && (entry
->symndx
!= -1
1943 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1946 bfd_vma ad
= addend
;
1948 /* sec may be NULL when referencing an undefweak symbol
1949 while linking a static executable. */
1952 BFD_ASSERT (entry
->symndx
== -1
1953 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
);
1957 if (entry
->symndx
== -1)
1958 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1960 ad
+= sym
->st_value
;
1961 ad
+= sec
->output_offset
;
1962 if (sec
->output_section
1963 && elf_section_data (sec
->output_section
))
1964 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1969 /* *ABS*+addend is special for TLS relocations, use only the
1970 addend for the TLS offset, and take the module id as
1973 && (bfd_is_abs_section (sec
)
1974 || bfd_is_und_section (sec
)))
1976 /* For other TLS symbols that bind locally, add the section
1977 TLS offset to the addend. */
1979 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1981 if ((bfd_signed_vma
)ad
>= -(1 << (16 - 1))
1982 && (bfd_signed_vma
)ad
< (1 << (16 - 1)))
1984 /* setlos lo(ad), gr9 */
1985 bfd_put_32 (output_bfd
,
1988 & (((bfd_vma
)1 << 16) - 1)),
1994 /* sethi.p hi(ad), gr9
1995 setlo lo(ad), gr9 */
1996 bfd_put_32 (output_bfd
,
1999 & (((bfd_vma
)1 << 16) - 1)),
2002 bfd_put_32 (output_bfd
,
2005 & (((bfd_vma
)1 << 16) - 1)),
2010 bfd_put_32 (output_bfd
, 0xc03a4000, plt_code
);
2012 else if (entry
->tlsoff_entry
)
2014 /* Figure out what kind of PLT entry we need, depending on the
2015 location of the TLS descriptor within the GOT. */
2016 if (entry
->tlsoff_entry
>= -(1 << (12 - 1))
2017 && entry
->tlsoff_entry
< (1 << (12 - 1)))
2019 /* ldi @(gr15, tlsoff_entry), gr9 */
2020 bfd_put_32 (output_bfd
,
2021 0x92c8f000 | (entry
->tlsoff_entry
2028 if (entry
->tlsoff_entry
>= -(1 << (16 - 1))
2029 && entry
->tlsoff_entry
< (1 << (16 - 1)))
2031 /* setlos lo(tlsoff_entry), gr8 */
2032 bfd_put_32 (output_bfd
,
2034 | (entry
->tlsoff_entry
2035 & (((bfd_vma
)1 << 16) - 1)),
2041 /* sethi.p hi(tlsoff_entry), gr8
2042 setlo lo(tlsoff_entry), gr8 */
2043 bfd_put_32 (output_bfd
,
2045 | ((entry
->tlsoff_entry
>> 16)
2046 & (((bfd_vma
)1 << 16) - 1)),
2049 bfd_put_32 (output_bfd
,
2051 | (entry
->tlsoff_entry
2052 & (((bfd_vma
)1 << 16) - 1)),
2056 /* ld @(gr15,gr8),gr9 */
2057 bfd_put_32 (output_bfd
, 0x9008f108, plt_code
);
2061 bfd_put_32 (output_bfd
, 0xc03a4000, plt_code
);
2065 BFD_ASSERT (entry
->tlsdesc_entry
);
2067 /* Figure out what kind of PLT entry we need, depending on the
2068 location of the TLS descriptor within the GOT. */
2069 if (entry
->tlsdesc_entry
>= -(1 << (12 - 1))
2070 && entry
->tlsdesc_entry
< (1 << (12 - 1)))
2072 /* lddi @(gr15, tlsdesc_entry), gr8 */
2073 bfd_put_32 (output_bfd
,
2074 0x90ccf000 | (entry
->tlsdesc_entry
2081 if (entry
->tlsdesc_entry
>= -(1 << (16 - 1))
2082 && entry
->tlsdesc_entry
< (1 << (16 - 1)))
2084 /* setlos lo(tlsdesc_entry), gr8 */
2085 bfd_put_32 (output_bfd
,
2087 | (entry
->tlsdesc_entry
2088 & (((bfd_vma
)1 << 16) - 1)),
2094 /* sethi.p hi(tlsdesc_entry), gr8
2095 setlo lo(tlsdesc_entry), gr8 */
2096 bfd_put_32 (output_bfd
,
2098 | ((entry
->tlsdesc_entry
>> 16)
2099 & (((bfd_vma
)1 << 16) - 1)),
2102 bfd_put_32 (output_bfd
,
2104 | (entry
->tlsdesc_entry
2105 & (((bfd_vma
)1 << 16) - 1)),
2109 /* ldd @(gr15,gr8),gr8 */
2110 bfd_put_32 (output_bfd
, 0x9008f148, plt_code
);
2113 /* jmpl @(gr8,gr0) */
2114 bfd_put_32 (output_bfd
, 0x80308000, plt_code
);
2121 /* Handle an FRV small data reloc. */
2123 static bfd_reloc_status_type
2124 elf32_frv_relocate_gprel12 (struct bfd_link_info
*info
,
2126 asection
*input_section
,
2127 Elf_Internal_Rela
*relocation
,
2133 struct bfd_link_hash_entry
*h
;
2135 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2137 gp
= (h
->u
.def
.value
2138 + h
->u
.def
.section
->output_section
->vma
2139 + h
->u
.def
.section
->output_offset
);
2141 value
-= input_section
->output_section
->vma
;
2142 value
-= (gp
- input_section
->output_section
->vma
);
2144 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2146 value
+= relocation
->r_addend
;
2148 if ((long) value
> 0x7ff || (long) value
< -0x800)
2149 return bfd_reloc_overflow
;
2151 bfd_put_32 (input_bfd
,
2152 (insn
& 0xfffff000) | (value
& 0xfff),
2153 contents
+ relocation
->r_offset
);
2155 return bfd_reloc_ok
;
2158 /* Handle an FRV small data reloc. for the u12 field. */
2160 static bfd_reloc_status_type
2161 elf32_frv_relocate_gprelu12 (struct bfd_link_info
*info
,
2163 asection
*input_section
,
2164 Elf_Internal_Rela
*relocation
,
2170 struct bfd_link_hash_entry
*h
;
2173 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2175 gp
= (h
->u
.def
.value
2176 + h
->u
.def
.section
->output_section
->vma
2177 + h
->u
.def
.section
->output_offset
);
2179 value
-= input_section
->output_section
->vma
;
2180 value
-= (gp
- input_section
->output_section
->vma
);
2182 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2184 value
+= relocation
->r_addend
;
2186 if ((long) value
> 0x7ff || (long) value
< -0x800)
2187 return bfd_reloc_overflow
;
2189 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
2191 insn
= (insn
& ~mask
) | ((value
& 0xfc0) << 12) | (value
& 0x3f);
2193 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2195 return bfd_reloc_ok
;
2198 /* Handle an FRV ELF HI16 reloc. */
2200 static bfd_reloc_status_type
2201 elf32_frv_relocate_hi16 (bfd
*input_bfd
,
2202 Elf_Internal_Rela
*relhi
,
2208 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
2210 value
+= relhi
->r_addend
;
2211 value
= ((value
>> 16) & 0xffff);
2213 insn
= (insn
& 0xffff0000) | value
;
2215 if ((long) value
> 0xffff || (long) value
< -0x10000)
2216 return bfd_reloc_overflow
;
2218 bfd_put_32 (input_bfd
, insn
, contents
+ relhi
->r_offset
);
2219 return bfd_reloc_ok
;
2222 static bfd_reloc_status_type
2223 elf32_frv_relocate_lo16 (bfd
*input_bfd
,
2224 Elf_Internal_Rela
*rello
,
2230 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2232 value
+= rello
->r_addend
;
2233 value
= value
& 0xffff;
2235 insn
= (insn
& 0xffff0000) | value
;
2237 if ((long) value
> 0xffff || (long) value
< -0x10000)
2238 return bfd_reloc_overflow
;
2240 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
2241 return bfd_reloc_ok
;
2244 /* Perform the relocation for the CALL label24 instruction. */
2246 static bfd_reloc_status_type
2247 elf32_frv_relocate_label24 (bfd
*input_bfd
,
2248 asection
*input_section
,
2249 Elf_Internal_Rela
*rello
,
2257 /* The format for the call instruction is:
2259 0 000000 0001111 000000000000000000
2260 label6 opcode label18
2262 The branch calculation is: pc + (4*label24)
2263 where label24 is the concatenation of label6 and label18. */
2265 /* Grab the instruction. */
2266 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2268 value
-= input_section
->output_section
->vma
+ input_section
->output_offset
;
2269 value
-= rello
->r_offset
;
2270 value
+= rello
->r_addend
;
2274 label6
= value
& 0xfc0000;
2275 label6
= label6
<< 7;
2277 label18
= value
& 0x3ffff;
2279 insn
= insn
& 0x803c0000;
2280 insn
= insn
| label6
;
2281 insn
= insn
| label18
;
2283 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
2285 return bfd_reloc_ok
;
2288 static bfd_reloc_status_type
2289 elf32_frv_relocate_gprelhi (struct bfd_link_info
*info
,
2291 asection
*input_section
,
2292 Elf_Internal_Rela
*relocation
,
2298 struct bfd_link_hash_entry
*h
;
2300 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2302 gp
= (h
->u
.def
.value
2303 + h
->u
.def
.section
->output_section
->vma
2304 + h
->u
.def
.section
->output_offset
);
2306 value
-= input_section
->output_section
->vma
;
2307 value
-= (gp
- input_section
->output_section
->vma
);
2308 value
+= relocation
->r_addend
;
2309 value
= ((value
>> 16) & 0xffff);
2311 if ((long) value
> 0xffff || (long) value
< -0x10000)
2312 return bfd_reloc_overflow
;
2314 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2315 insn
= (insn
& 0xffff0000) | value
;
2317 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2318 return bfd_reloc_ok
;
2321 static bfd_reloc_status_type
2322 elf32_frv_relocate_gprello (struct bfd_link_info
*info
,
2324 asection
*input_section
,
2325 Elf_Internal_Rela
*relocation
,
2331 struct bfd_link_hash_entry
*h
;
2333 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2335 gp
= (h
->u
.def
.value
2336 + h
->u
.def
.section
->output_section
->vma
2337 + h
->u
.def
.section
->output_offset
);
2339 value
-= input_section
->output_section
->vma
;
2340 value
-= (gp
- input_section
->output_section
->vma
);
2341 value
+= relocation
->r_addend
;
2342 value
= value
& 0xffff;
2344 if ((long) value
> 0xffff || (long) value
< -0x10000)
2345 return bfd_reloc_overflow
;
2347 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2348 insn
= (insn
& 0xffff0000) | value
;
2350 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2352 return bfd_reloc_ok
;
2355 static reloc_howto_type
*
2356 frv_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2357 bfd_reloc_code_real_type code
)
2364 case BFD_RELOC_NONE
:
2365 return &elf32_frv_howto_table
[ (int) R_FRV_NONE
];
2368 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2369 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2370 return &elf32_frv_rel_32_howto
;
2372 case BFD_RELOC_CTOR
:
2373 return &elf32_frv_howto_table
[ (int) R_FRV_32
];
2375 case BFD_RELOC_FRV_LABEL16
:
2376 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL16
];
2378 case BFD_RELOC_FRV_LABEL24
:
2379 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL24
];
2381 case BFD_RELOC_FRV_LO16
:
2382 return &elf32_frv_howto_table
[ (int) R_FRV_LO16
];
2384 case BFD_RELOC_FRV_HI16
:
2385 return &elf32_frv_howto_table
[ (int) R_FRV_HI16
];
2387 case BFD_RELOC_FRV_GPREL12
:
2388 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL12
];
2390 case BFD_RELOC_FRV_GPRELU12
:
2391 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELU12
];
2393 case BFD_RELOC_FRV_GPREL32
:
2394 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL32
];
2396 case BFD_RELOC_FRV_GPRELHI
:
2397 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELHI
];
2399 case BFD_RELOC_FRV_GPRELLO
:
2400 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELLO
];
2402 case BFD_RELOC_FRV_GOT12
:
2403 return &elf32_frv_howto_table
[ (int) R_FRV_GOT12
];
2405 case BFD_RELOC_FRV_GOTHI
:
2406 return &elf32_frv_howto_table
[ (int) R_FRV_GOTHI
];
2408 case BFD_RELOC_FRV_GOTLO
:
2409 return &elf32_frv_howto_table
[ (int) R_FRV_GOTLO
];
2411 case BFD_RELOC_FRV_FUNCDESC
:
2412 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2413 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2414 return &elf32_frv_rel_funcdesc_howto
;
2415 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC
];
2417 case BFD_RELOC_FRV_FUNCDESC_GOT12
:
2418 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOT12
];
2420 case BFD_RELOC_FRV_FUNCDESC_GOTHI
:
2421 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTHI
];
2423 case BFD_RELOC_FRV_FUNCDESC_GOTLO
:
2424 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTLO
];
2426 case BFD_RELOC_FRV_FUNCDESC_VALUE
:
2427 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2428 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2429 return &elf32_frv_rel_funcdesc_value_howto
;
2430 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_VALUE
];
2432 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12
:
2433 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFF12
];
2435 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI
:
2436 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFHI
];
2438 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO
:
2439 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFLO
];
2441 case BFD_RELOC_FRV_GOTOFF12
:
2442 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFF12
];
2444 case BFD_RELOC_FRV_GOTOFFHI
:
2445 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFHI
];
2447 case BFD_RELOC_FRV_GOTOFFLO
:
2448 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFLO
];
2450 case BFD_RELOC_FRV_GETTLSOFF
:
2451 return &elf32_frv_howto_table
[ (int) R_FRV_GETTLSOFF
];
2453 case BFD_RELOC_FRV_TLSDESC_VALUE
:
2454 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2455 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2456 return &elf32_frv_rel_tlsdesc_value_howto
;
2457 return &elf32_frv_howto_table
[ (int) R_FRV_TLSDESC_VALUE
];
2459 case BFD_RELOC_FRV_GOTTLSDESC12
:
2460 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESC12
];
2462 case BFD_RELOC_FRV_GOTTLSDESCHI
:
2463 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESCHI
];
2465 case BFD_RELOC_FRV_GOTTLSDESCLO
:
2466 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESCLO
];
2468 case BFD_RELOC_FRV_TLSMOFF12
:
2469 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFF12
];
2471 case BFD_RELOC_FRV_TLSMOFFHI
:
2472 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFFHI
];
2474 case BFD_RELOC_FRV_TLSMOFFLO
:
2475 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFFLO
];
2477 case BFD_RELOC_FRV_GOTTLSOFF12
:
2478 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFF12
];
2480 case BFD_RELOC_FRV_GOTTLSOFFHI
:
2481 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFFHI
];
2483 case BFD_RELOC_FRV_GOTTLSOFFLO
:
2484 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFFLO
];
2486 case BFD_RELOC_FRV_TLSOFF
:
2487 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2488 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2489 return &elf32_frv_rel_tlsoff_howto
;
2490 return &elf32_frv_howto_table
[ (int) R_FRV_TLSOFF
];
2492 case BFD_RELOC_FRV_TLSDESC_RELAX
:
2493 return &elf32_frv_howto_table
[ (int) R_FRV_TLSDESC_RELAX
];
2495 case BFD_RELOC_FRV_GETTLSOFF_RELAX
:
2496 return &elf32_frv_howto_table
[ (int) R_FRV_GETTLSOFF_RELAX
];
2498 case BFD_RELOC_FRV_TLSOFF_RELAX
:
2499 return &elf32_frv_howto_table
[ (int) R_FRV_TLSOFF_RELAX
];
2501 case BFD_RELOC_FRV_TLSMOFF
:
2502 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFF
];
2504 case BFD_RELOC_VTABLE_INHERIT
:
2505 return &elf32_frv_vtinherit_howto
;
2507 case BFD_RELOC_VTABLE_ENTRY
:
2508 return &elf32_frv_vtentry_howto
;
2514 static reloc_howto_type
*
2515 frv_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
, const char *r_name
)
2520 i
< sizeof (elf32_frv_howto_table
) / sizeof (elf32_frv_howto_table
[0]);
2522 if (elf32_frv_howto_table
[i
].name
!= NULL
2523 && strcasecmp (elf32_frv_howto_table
[i
].name
, r_name
) == 0)
2524 return &elf32_frv_howto_table
[i
];
2526 if (strcasecmp (elf32_frv_vtinherit_howto
.name
, r_name
) == 0)
2527 return &elf32_frv_vtinherit_howto
;
2528 if (strcasecmp (elf32_frv_vtentry_howto
.name
, r_name
) == 0)
2529 return &elf32_frv_vtentry_howto
;
2534 /* Set the howto pointer for an FRV ELF reloc. */
2537 frv_info_to_howto_rela (bfd
*abfd ATTRIBUTE_UNUSED
,
2539 Elf_Internal_Rela
*dst
)
2541 unsigned int r_type
;
2543 r_type
= ELF32_R_TYPE (dst
->r_info
);
2546 case R_FRV_GNU_VTINHERIT
:
2547 cache_ptr
->howto
= &elf32_frv_vtinherit_howto
;
2550 case R_FRV_GNU_VTENTRY
:
2551 cache_ptr
->howto
= &elf32_frv_vtentry_howto
;
2555 if (r_type
>= ARRAY_SIZE (elf32_frv_howto_table
))
2557 /* xgettext:c-format */
2558 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2560 bfd_set_error (bfd_error_bad_value
);
2563 cache_ptr
->howto
= & elf32_frv_howto_table
[r_type
];
2569 /* Set the howto pointer for an FRV ELF REL reloc. */
2572 frvfdpic_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
2573 arelent
*cache_ptr
, Elf_Internal_Rela
*dst
)
2575 unsigned int r_type
;
2577 r_type
= ELF32_R_TYPE (dst
->r_info
);
2581 cache_ptr
->howto
= &elf32_frv_rel_32_howto
;
2584 case R_FRV_FUNCDESC
:
2585 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_howto
;
2588 case R_FRV_FUNCDESC_VALUE
:
2589 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_value_howto
;
2592 case R_FRV_TLSDESC_VALUE
:
2593 cache_ptr
->howto
= &elf32_frv_rel_tlsdesc_value_howto
;
2597 cache_ptr
->howto
= &elf32_frv_rel_tlsoff_howto
;
2601 cache_ptr
->howto
= NULL
;
2607 /* Perform a single relocation. By default we use the standard BFD
2608 routines, but a few relocs, we have to do them ourselves. */
2610 static bfd_reloc_status_type
2611 frv_final_link_relocate (reloc_howto_type
*howto
,
2613 asection
*input_section
,
2615 Elf_Internal_Rela
*rel
,
2618 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2619 contents
, rel
->r_offset
, relocation
,
2624 /* Relocate an FRV ELF section.
2626 The RELOCATE_SECTION function is called by the new ELF backend linker
2627 to handle the relocations for a section.
2629 The relocs are always passed as Rela structures; if the section
2630 actually uses Rel structures, the r_addend field will always be
2633 This function is responsible for adjusting the section contents as
2634 necessary, and (if using Rela relocs and generating a relocatable
2635 output file) adjusting the reloc addend as necessary.
2637 This function does not have to worry about setting the reloc
2638 address or the reloc symbol index.
2640 LOCAL_SYMS is a pointer to the swapped in local symbols.
2642 LOCAL_SECTIONS is an array giving the section in the input file
2643 corresponding to the st_shndx field of each local symbol.
2645 The global hash table entry for the global symbols can be found
2646 via elf_sym_hashes (input_bfd).
2648 When generating relocatable output, this function must handle
2649 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2650 going to be the section symbol corresponding to the output
2651 section, which means that the addend must be adjusted
2655 elf32_frv_relocate_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2656 struct bfd_link_info
*info
,
2658 asection
*input_section
,
2660 Elf_Internal_Rela
*relocs
,
2661 Elf_Internal_Sym
*local_syms
,
2662 asection
**local_sections
)
2664 Elf_Internal_Shdr
*symtab_hdr
;
2665 struct elf_link_hash_entry
**sym_hashes
;
2666 Elf_Internal_Rela
*rel
;
2667 Elf_Internal_Rela
*relend
;
2668 unsigned isec_segment
, got_segment
, plt_segment
, gprel_segment
, tls_segment
,
2670 int silence_segment_error
= !bfd_link_pic (info
);
2673 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
2674 sym_hashes
= elf_sym_hashes (input_bfd
);
2675 relend
= relocs
+ input_section
->reloc_count
;
2677 isec_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2678 input_section
->output_section
);
2679 if (IS_FDPIC (output_bfd
) && frvfdpic_got_section (info
))
2680 got_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2681 frvfdpic_got_section (info
)
2685 if (IS_FDPIC (output_bfd
) && frvfdpic_gotfixup_section (info
))
2686 gprel_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2687 frvfdpic_gotfixup_section (info
)
2691 if (IS_FDPIC (output_bfd
) && frvfdpic_plt_section (info
))
2692 plt_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2693 frvfdpic_plt_section (info
)
2697 if (elf_hash_table (info
)->tls_sec
)
2698 tls_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2699 elf_hash_table (info
)->tls_sec
);
2703 for (rel
= relocs
; rel
< relend
; rel
++)
2705 reloc_howto_type
*howto
;
2706 unsigned long r_symndx
;
2707 Elf_Internal_Sym
*sym
;
2709 struct elf_link_hash_entry
*h
;
2711 bfd_reloc_status_type r
;
2715 struct frvfdpic_relocs_info
*picrel
;
2716 bfd_vma orig_addend
= rel
->r_addend
;
2718 r_type
= ELF32_R_TYPE (rel
->r_info
);
2720 if ( r_type
== R_FRV_GNU_VTINHERIT
2721 || r_type
== R_FRV_GNU_VTENTRY
)
2724 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2725 howto
= elf32_frv_howto_table
+ ELF32_R_TYPE (rel
->r_info
);
2730 if (r_symndx
< symtab_hdr
->sh_info
)
2732 sym
= local_syms
+ r_symndx
;
2733 osec
= sec
= local_sections
[r_symndx
];
2734 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2736 name
= bfd_elf_string_from_elf_section
2737 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
2738 if (name
== NULL
|| name
[0] == 0)
2739 name
= bfd_section_name (sec
);
2743 bfd_boolean warned
, ignored
;
2744 bfd_boolean unresolved_reloc
;
2746 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2747 r_symndx
, symtab_hdr
, sym_hashes
,
2749 unresolved_reloc
, warned
, ignored
);
2751 name
= h
->root
.root
.string
;
2754 if (sec
!= NULL
&& discarded_section (sec
))
2755 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
2756 rel
, 1, relend
, howto
, 0, contents
);
2758 if (bfd_link_relocatable (info
))
2761 if (r_type
!= R_FRV_TLSMOFF
2763 && (h
->root
.type
== bfd_link_hash_defined
2764 || h
->root
.type
== bfd_link_hash_defweak
)
2765 && !FRVFDPIC_SYM_LOCAL (info
, h
))
2775 if (! IS_FDPIC (output_bfd
))
2782 case R_FRV_FUNCDESC_GOT12
:
2783 case R_FRV_FUNCDESC_GOTHI
:
2784 case R_FRV_FUNCDESC_GOTLO
:
2785 case R_FRV_GOTOFF12
:
2786 case R_FRV_GOTOFFHI
:
2787 case R_FRV_GOTOFFLO
:
2788 case R_FRV_FUNCDESC_GOTOFF12
:
2789 case R_FRV_FUNCDESC_GOTOFFHI
:
2790 case R_FRV_FUNCDESC_GOTOFFLO
:
2791 case R_FRV_FUNCDESC
:
2792 case R_FRV_FUNCDESC_VALUE
:
2793 case R_FRV_GETTLSOFF
:
2794 case R_FRV_TLSDESC_VALUE
:
2795 case R_FRV_GOTTLSDESC12
:
2796 case R_FRV_GOTTLSDESCHI
:
2797 case R_FRV_GOTTLSDESCLO
:
2798 case R_FRV_TLSMOFF12
:
2799 case R_FRV_TLSMOFFHI
:
2800 case R_FRV_TLSMOFFLO
:
2801 case R_FRV_GOTTLSOFF12
:
2802 case R_FRV_GOTTLSOFFHI
:
2803 case R_FRV_GOTTLSOFFLO
:
2805 case R_FRV_TLSDESC_RELAX
:
2806 case R_FRV_GETTLSOFF_RELAX
:
2807 case R_FRV_TLSOFF_RELAX
:
2810 picrel
= frvfdpic_relocs_info_for_global (frvfdpic_relocs_info
2811 (info
), input_bfd
, h
,
2812 orig_addend
, INSERT
);
2814 /* In order to find the entry we created before, we must
2815 use the original addend, not the one that may have been
2816 modified by _bfd_elf_rela_local_sym(). */
2817 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
2818 (info
), input_bfd
, r_symndx
,
2819 orig_addend
, INSERT
);
2823 if (!_frvfdpic_emit_got_relocs_plt_entries (picrel
, output_bfd
, info
,
2827 info
->callbacks
->einfo
2828 /* xgettext:c-format */
2829 (_("%H: relocation to `%s+%v'"
2830 " may have caused the error above\n"),
2831 input_bfd
, input_section
, rel
->r_offset
, name
, rel
->r_addend
);
2841 && ! FRVFDPIC_SYM_LOCAL (info
, h
)
2842 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2843 rel
->r_offset
) != (bfd_vma
) -1)
2845 info
->callbacks
->einfo
2846 (_("%H: relocation references symbol"
2847 " not defined in the module\n"),
2848 input_bfd
, input_section
, rel
->r_offset
);
2856 case R_FRV_GETTLSOFF
:
2857 case R_FRV_TLSDESC_VALUE
:
2858 case R_FRV_GOTTLSDESC12
:
2859 case R_FRV_GOTTLSDESCHI
:
2860 case R_FRV_GOTTLSDESCLO
:
2861 case R_FRV_TLSMOFF12
:
2862 case R_FRV_TLSMOFFHI
:
2863 case R_FRV_TLSMOFFLO
:
2864 case R_FRV_GOTTLSOFF12
:
2865 case R_FRV_GOTTLSOFFHI
:
2866 case R_FRV_GOTTLSOFFLO
:
2868 case R_FRV_TLSDESC_RELAX
:
2869 case R_FRV_GETTLSOFF_RELAX
:
2870 case R_FRV_TLSOFF_RELAX
:
2872 if (sec
&& (bfd_is_abs_section (sec
) || bfd_is_und_section (sec
)))
2873 relocation
+= tls_biased_base (info
);
2880 /* Try to apply TLS relaxations. */
2885 #define LOCAL_EXEC_P(info, picrel) \
2886 (bfd_link_executable (info) \
2887 && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h)))
2888 #define INITIAL_EXEC_P(info, picrel) \
2889 ((bfd_link_executable (info)|| (info)->flags & DF_STATIC_TLS) \
2890 && (picrel)->tlsoff_entry)
2892 #define IN_RANGE_FOR_OFST12_P(value) \
2893 ((bfd_vma)((value) + 2048) < (bfd_vma)4096)
2894 #define IN_RANGE_FOR_SETLOS_P(value) \
2895 ((bfd_vma)((value) + 32768) < (bfd_vma)65536)
2896 #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \
2897 (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info)))
2899 #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2900 (LOCAL_EXEC_P ((info), (picrel)) \
2901 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2902 #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \
2903 (INITIAL_EXEC_P ((info), (picrel)) \
2904 && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry))
2906 #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \
2907 (LOCAL_EXEC_P ((info), (picrel)))
2908 #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \
2909 (INITIAL_EXEC_P ((info), (picrel)))
2911 #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2912 (LOCAL_EXEC_P ((info), (picrel)) \
2913 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2915 case R_FRV_GETTLSOFF
:
2916 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2918 /* Is this a call instruction? */
2919 if ((insn
& (unsigned long)0x01fc0000) != 0x003c0000)
2921 info
->callbacks
->einfo
2922 (_("%H: R_FRV_GETTLSOFF not applied to a call instruction\n"),
2923 input_bfd
, input_section
, rel
->r_offset
);
2927 if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info
, picrel
,
2928 relocation
+ rel
->r_addend
))
2930 /* Replace the call instruction (except the packing bit)
2931 with setlos #tlsmofflo(symbol+offset), gr9. */
2932 insn
&= (unsigned long)0x80000000;
2933 insn
|= (unsigned long)0x12fc0000;
2934 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
2936 r_type
= R_FRV_TLSMOFFLO
;
2937 howto
= elf32_frv_howto_table
+ r_type
;
2938 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
2941 else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info
, picrel
))
2943 /* Replace the call instruction (except the packing bit)
2944 with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */
2945 insn
&= (unsigned long)0x80000000;
2946 insn
|= (unsigned long)0x12c8f000;
2947 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
2949 r_type
= R_FRV_GOTTLSOFF12
;
2950 howto
= elf32_frv_howto_table
+ r_type
;
2951 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
2956 case R_FRV_GOTTLSDESC12
:
2957 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2959 /* Is this an lddi instruction? */
2960 if ((insn
& (unsigned long)0x01fc0000) != 0x00cc0000)
2962 info
->callbacks
->einfo
2963 (_("%H: R_FRV_GOTTLSDESC12"
2964 " not applied to an lddi instruction\n"),
2965 input_bfd
, input_section
, rel
->r_offset
);
2969 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
2970 relocation
+ rel
->r_addend
)
2971 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
2974 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
2975 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
2976 Preserve the packing bit. */
2977 insn
= (insn
& (unsigned long)0x80000000)
2978 | ((insn
+ (unsigned long)0x02000000)
2979 & (unsigned long)0x7e000000);
2980 insn
|= (unsigned long)0x00fc0000;
2981 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
2983 r_type
= R_FRV_TLSMOFFLO
;
2984 howto
= elf32_frv_howto_table
+ r_type
;
2985 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
2988 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
2989 relocation
+ rel
->r_addend
))
2991 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
2992 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
2993 Preserve the packing bit. */
2994 insn
= (insn
& (unsigned long)0x80000000)
2995 | ((insn
+ (unsigned long)0x02000000)
2996 & (unsigned long)0x7e000000);
2997 insn
|= (unsigned long)0x00f80000;
2998 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3000 r_type
= R_FRV_TLSMOFFHI
;
3001 howto
= elf32_frv_howto_table
+ r_type
;
3002 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3005 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3007 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3008 with ldi @(grB, #gottlsoff12(symbol+offset),
3009 gr<C+1>. Preserve the packing bit. If gottlsoff12
3010 overflows, we'll error out, but that's sort-of ok,
3011 since we'd started with gottlsdesc12, that's actually
3012 more demanding. Compiling with -fPIE instead of
3013 -fpie would fix it; linking with --relax should fix
3015 insn
= (insn
& (unsigned long)0x80cbf000)
3016 | ((insn
+ (unsigned long)0x02000000)
3017 & (unsigned long)0x7e000000);
3018 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3020 r_type
= R_FRV_GOTTLSOFF12
;
3021 howto
= elf32_frv_howto_table
+ r_type
;
3022 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3027 case R_FRV_GOTTLSDESCHI
:
3028 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3030 /* Is this a sethi instruction? */
3031 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3033 info
->callbacks
->einfo
3034 (_("%H: R_FRV_GOTTLSDESCHI"
3035 " not applied to a sethi instruction\n"),
3036 input_bfd
, input_section
, rel
->r_offset
);
3040 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3041 relocation
+ rel
->r_addend
)
3042 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3043 && IN_RANGE_FOR_SETLOS_P (picrel
->tlsoff_entry
)))
3045 /* Replace sethi with a nop. Preserve the packing bit. */
3046 insn
&= (unsigned long)0x80000000;
3047 insn
|= (unsigned long)0x00880000;
3048 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3050 /* Nothing to relocate. */
3054 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3056 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3057 r_type
= R_FRV_GOTTLSOFFHI
;
3058 howto
= elf32_frv_howto_table
+ r_type
;
3059 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3064 case R_FRV_GOTTLSDESCLO
:
3065 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3067 /* Is this a setlo or setlos instruction? */
3068 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3070 info
->callbacks
->einfo
3071 (_("%H: R_FRV_GOTTLSDESCLO"
3072 " not applied to a setlo or setlos instruction\n"),
3073 input_bfd
, input_section
, rel
->r_offset
);
3077 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3078 relocation
+ rel
->r_addend
)
3079 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3080 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3082 /* Replace setlo/setlos with a nop. Preserve the
3084 insn
&= (unsigned long)0x80000000;
3085 insn
|= (unsigned long)0x00880000;
3086 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3088 /* Nothing to relocate. */
3092 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3094 /* If the corresponding sethi (if it exists) decayed
3095 to a nop, make sure this becomes (or already is) a
3096 setlos, not setlo. */
3097 if (IN_RANGE_FOR_SETLOS_P (picrel
->tlsoff_entry
))
3099 insn
|= (unsigned long)0x00080000;
3100 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3103 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3104 r_type
= R_FRV_GOTTLSOFFLO
;
3105 howto
= elf32_frv_howto_table
+ r_type
;
3106 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3111 case R_FRV_TLSDESC_RELAX
:
3112 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3114 /* Is this an ldd instruction? */
3115 if ((insn
& (unsigned long)0x01fc0fc0) != 0x00080140)
3117 info
->callbacks
->einfo
3118 (_("%H: R_FRV_TLSDESC_RELAX"
3119 " not applied to an ldd instruction\n"),
3120 input_bfd
, input_section
, rel
->r_offset
);
3124 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3125 relocation
+ rel
->r_addend
)
3126 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3129 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3130 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3131 Preserve the packing bit. */
3132 insn
= (insn
& (unsigned long)0x80000000)
3133 | ((insn
+ (unsigned long)0x02000000)
3134 & (unsigned long)0x7e000000);
3135 insn
|= (unsigned long)0x00fc0000;
3136 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3138 r_type
= R_FRV_TLSMOFFLO
;
3139 howto
= elf32_frv_howto_table
+ r_type
;
3140 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3143 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3144 relocation
+ rel
->r_addend
))
3146 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3147 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3148 Preserve the packing bit. */
3149 insn
= (insn
& (unsigned long)0x80000000)
3150 | ((insn
+ (unsigned long)0x02000000)
3151 & (unsigned long)0x7e000000);
3152 insn
|= (unsigned long)0x00f80000;
3153 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3155 r_type
= R_FRV_TLSMOFFHI
;
3156 howto
= elf32_frv_howto_table
+ r_type
;
3157 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3160 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3161 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
))
3163 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3164 with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>.
3165 Preserve the packing bit. */
3166 insn
= (insn
& (unsigned long)0x8003f000)
3167 | (unsigned long)0x00c80000
3168 | ((insn
+ (unsigned long)0x02000000)
3169 & (unsigned long)0x7e000000);
3170 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3172 r_type
= R_FRV_GOTTLSOFF12
;
3173 howto
= elf32_frv_howto_table
+ r_type
;
3174 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3177 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3179 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3180 with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>.
3181 Preserve the packing bit. */
3182 insn
= (insn
& (unsigned long)0x81ffffbf)
3183 | ((insn
+ (unsigned long)0x02000000)
3184 & (unsigned long)0x7e000000);
3185 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3187 /* #tlsoff(symbol+offset) is just a relaxation
3188 annotation, so there's nothing left to
3195 case R_FRV_GETTLSOFF_RELAX
:
3196 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3198 /* Is this a calll or callil instruction? */
3199 if ((insn
& (unsigned long)0x7ff80fc0) != 0x02300000)
3201 info
->callbacks
->einfo
3202 (_("%H: R_FRV_GETTLSOFF_RELAX"
3203 " not applied to a calll instruction\n"),
3204 input_bfd
, input_section
, rel
->r_offset
);
3208 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3209 relocation
+ rel
->r_addend
)
3210 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3213 /* Replace calll with a nop. Preserve the packing bit. */
3214 insn
&= (unsigned long)0x80000000;
3215 insn
|= (unsigned long)0x00880000;
3216 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3218 /* Nothing to relocate. */
3222 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3223 relocation
+ rel
->r_addend
))
3225 /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9.
3226 Preserve the packing bit. */
3227 insn
&= (unsigned long)0x80000000;
3228 insn
|= (unsigned long)0x12f40000;
3229 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3231 r_type
= R_FRV_TLSMOFFLO
;
3232 howto
= elf32_frv_howto_table
+ r_type
;
3233 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3236 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3238 /* Replace calll with a nop. Preserve the packing bit. */
3239 insn
&= (unsigned long)0x80000000;
3240 insn
|= (unsigned long)0x00880000;
3241 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3243 /* Nothing to relocate. */
3249 case R_FRV_GOTTLSOFF12
:
3250 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3252 /* Is this an ldi instruction? */
3253 if ((insn
& (unsigned long)0x01fc0000) != 0x00c80000)
3255 info
->callbacks
->einfo
3256 (_("%H: R_FRV_GOTTLSOFF12"
3257 " not applied to an ldi instruction\n"),
3258 input_bfd
, input_section
, rel
->r_offset
);
3262 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3263 relocation
+ rel
->r_addend
))
3265 /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC
3266 with setlos #tlsmofflo(symbol+offset), grC.
3267 Preserve the packing bit. */
3268 insn
&= (unsigned long)0xfe000000;
3269 insn
|= (unsigned long)0x00fc0000;
3270 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3272 r_type
= R_FRV_TLSMOFFLO
;
3273 howto
= elf32_frv_howto_table
+ r_type
;
3274 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3279 case R_FRV_GOTTLSOFFHI
:
3280 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3282 /* Is this a sethi instruction? */
3283 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3285 info
->callbacks
->einfo
3286 (_("%H: R_FRV_GOTTLSOFFHI"
3287 " not applied to a sethi instruction\n"),
3288 input_bfd
, input_section
, rel
->r_offset
);
3292 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3293 relocation
+ rel
->r_addend
)
3294 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3295 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3297 /* Replace sethi with a nop. Preserve the packing bit. */
3298 insn
&= (unsigned long)0x80000000;
3299 insn
|= (unsigned long)0x00880000;
3300 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3302 /* Nothing to relocate. */
3308 case R_FRV_GOTTLSOFFLO
:
3309 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3311 /* Is this a setlo or setlos instruction? */
3312 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3314 info
->callbacks
->einfo
3315 (_("%H: R_FRV_GOTTLSOFFLO"
3316 " not applied to a setlo or setlos instruction\n"),
3317 input_bfd
, input_section
, rel
->r_offset
);
3321 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3322 relocation
+ rel
->r_addend
)
3323 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3324 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3326 /* Replace setlo/setlos with a nop. Preserve the
3328 insn
&= (unsigned long)0x80000000;
3329 insn
|= (unsigned long)0x00880000;
3330 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3332 /* Nothing to relocate. */
3338 case R_FRV_TLSOFF_RELAX
:
3339 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3341 /* Is this an ld instruction? */
3342 if ((insn
& (unsigned long)0x01fc0fc0) != 0x00080100)
3344 info
->callbacks
->einfo
3345 (_("%H: R_FRV_TLSOFF_RELAX"
3346 " not applied to an ld instruction\n"),
3347 input_bfd
, input_section
, rel
->r_offset
);
3351 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3352 relocation
+ rel
->r_addend
))
3354 /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC
3355 with setlos #tlsmofflo(symbol+offset), grC.
3356 Preserve the packing bit. */
3357 insn
&= (unsigned long)0xfe000000;
3358 insn
|= (unsigned long)0x00fc0000;
3359 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3361 r_type
= R_FRV_TLSMOFFLO
;
3362 howto
= elf32_frv_howto_table
+ r_type
;
3363 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3366 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3367 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
))
3369 /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC
3370 with ldi @(grB, #gottlsoff12(symbol+offset), grC.
3371 Preserve the packing bit. */
3372 insn
= (insn
& (unsigned long)0xfe03f000)
3373 | (unsigned long)0x00c80000;
3374 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3376 r_type
= R_FRV_GOTTLSOFF12
;
3377 howto
= elf32_frv_howto_table
+ r_type
;
3378 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3383 case R_FRV_TLSMOFFHI
:
3384 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3386 /* Is this a sethi instruction? */
3387 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3389 info
->callbacks
->einfo
3390 (_("%H: R_FRV_TLSMOFFHI"
3391 " not applied to a sethi instruction\n"),
3392 input_bfd
, input_section
, rel
->r_offset
);
3396 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3399 /* Replace sethi with a nop. Preserve the packing bit. */
3400 insn
&= (unsigned long)0x80000000;
3401 insn
|= (unsigned long)0x00880000;
3402 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3404 /* Nothing to relocate. */
3410 case R_FRV_TLSMOFFLO
:
3411 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3413 /* Is this a setlo or setlos instruction? */
3414 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3416 info
->callbacks
->einfo
3417 (_("R_FRV_TLSMOFFLO"
3418 " not applied to a setlo or setlos instruction\n"),
3419 input_bfd
, input_section
, rel
->r_offset
);
3423 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3425 /* If the corresponding sethi (if it exists) decayed
3426 to a nop, make sure this becomes (or already is) a
3427 setlos, not setlo. */
3429 insn
|= (unsigned long)0x00080000;
3430 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3436 There's nothing to relax in these:
3452 check_segment
[0] = isec_segment
;
3453 if (! IS_FDPIC (output_bfd
))
3454 check_segment
[1] = isec_segment
;
3455 else if (picrel
->plt
)
3457 relocation
= frvfdpic_plt_section (info
)->output_section
->vma
3458 + frvfdpic_plt_section (info
)->output_offset
3459 + picrel
->plt_entry
;
3460 check_segment
[1] = plt_segment
;
3462 /* We don't want to warn on calls to undefined weak symbols,
3463 as calls to them must be protected by non-NULL tests
3464 anyway, and unprotected calls would invoke undefined
3466 else if (picrel
->symndx
== -1
3467 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefweak
)
3468 check_segment
[1] = check_segment
[0];
3470 check_segment
[1] = sec
3471 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3478 relocation
= picrel
->got_entry
;
3479 check_segment
[0] = check_segment
[1] = got_segment
;
3482 case R_FRV_FUNCDESC_GOT12
:
3483 case R_FRV_FUNCDESC_GOTHI
:
3484 case R_FRV_FUNCDESC_GOTLO
:
3485 relocation
= picrel
->fdgot_entry
;
3486 check_segment
[0] = check_segment
[1] = got_segment
;
3489 case R_FRV_GOTOFFHI
:
3490 case R_FRV_GOTOFF12
:
3491 case R_FRV_GOTOFFLO
:
3492 relocation
-= frvfdpic_got_section (info
)->output_section
->vma
3493 + frvfdpic_got_section (info
)->output_offset
3494 + frvfdpic_got_initial_offset (info
);
3495 check_segment
[0] = got_segment
;
3496 check_segment
[1] = sec
3497 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3501 case R_FRV_FUNCDESC_GOTOFF12
:
3502 case R_FRV_FUNCDESC_GOTOFFHI
:
3503 case R_FRV_FUNCDESC_GOTOFFLO
:
3504 relocation
= picrel
->fd_entry
;
3505 check_segment
[0] = check_segment
[1] = got_segment
;
3508 case R_FRV_FUNCDESC
:
3511 bfd_vma addend
= rel
->r_addend
;
3513 if (! (h
&& h
->root
.type
== bfd_link_hash_undefweak
3514 && FRVFDPIC_SYM_LOCAL (info
, h
)))
3516 /* If the symbol is dynamic and there may be dynamic
3517 symbol resolution because we are or are linked with a
3518 shared library, emit a FUNCDESC relocation such that
3519 the dynamic linker will allocate the function
3520 descriptor. If the symbol needs a non-local function
3521 descriptor but binds locally (e.g., its visibility is
3522 protected, emit a dynamic relocation decayed to
3524 if (h
&& ! FRVFDPIC_FUNCDESC_LOCAL (info
, h
)
3525 && FRVFDPIC_SYM_LOCAL (info
, h
)
3526 && !bfd_link_pde (info
))
3528 dynindx
= elf_section_data (h
->root
.u
.def
.section
3529 ->output_section
)->dynindx
;
3530 addend
+= h
->root
.u
.def
.section
->output_offset
3531 + h
->root
.u
.def
.value
;
3533 else if (h
&& ! FRVFDPIC_FUNCDESC_LOCAL (info
, h
))
3537 info
->callbacks
->einfo
3538 (_("%H: %s references dynamic symbol"
3539 " with nonzero addend\n"),
3540 input_bfd
, input_section
, rel
->r_offset
,
3544 dynindx
= h
->dynindx
;
3548 /* Otherwise, we know we have a private function
3549 descriptor, so reference it directly. */
3550 BFD_ASSERT (picrel
->privfd
);
3552 dynindx
= elf_section_data (frvfdpic_got_section (info
)
3553 ->output_section
)->dynindx
;
3554 addend
= frvfdpic_got_section (info
)->output_offset
3555 + frvfdpic_got_initial_offset (info
)
3559 /* If there is room for dynamic symbol resolution, emit
3560 the dynamic relocation. However, if we're linking an
3561 executable at a fixed location, we won't have emitted a
3562 dynamic symbol entry for the got section, so idx will
3563 be zero, which means we can and should compute the
3564 address of the private descriptor ourselves. */
3565 if (bfd_link_pde (info
)
3566 && (!h
|| FRVFDPIC_FUNCDESC_LOCAL (info
, h
)))
3568 addend
+= frvfdpic_got_section (info
)->output_section
->vma
;
3569 if ((bfd_section_flags (input_section
->output_section
)
3570 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3574 if (_frvfdpic_osec_readonly_p (output_bfd
,
3578 info
->callbacks
->einfo
3579 (_("%H: cannot emit fixups"
3580 " in read-only section\n"),
3581 input_bfd
, input_section
, rel
->r_offset
);
3585 offset
= _bfd_elf_section_offset
3587 input_section
, rel
->r_offset
);
3589 if (offset
!= (bfd_vma
)-1)
3590 _frvfdpic_add_rofixup (output_bfd
,
3591 frvfdpic_gotfixup_section
3593 offset
+ input_section
3594 ->output_section
->vma
3595 + input_section
->output_offset
,
3599 else if ((bfd_section_flags (input_section
->output_section
)
3600 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3604 if (_frvfdpic_osec_readonly_p (output_bfd
,
3608 info
->callbacks
->einfo
3609 (_("%H: cannot emit dynamic relocations"
3610 " in read-only section\n"),
3611 input_bfd
, input_section
, rel
->r_offset
);
3615 offset
= _bfd_elf_section_offset
3617 input_section
, rel
->r_offset
);
3619 if (offset
!= (bfd_vma
)-1)
3620 _frvfdpic_add_dyn_reloc (output_bfd
,
3621 frvfdpic_gotrel_section (info
),
3622 offset
+ input_section
3623 ->output_section
->vma
3624 + input_section
->output_offset
,
3625 r_type
, dynindx
, addend
, picrel
);
3628 addend
+= frvfdpic_got_section (info
)->output_section
->vma
;
3631 /* We want the addend in-place because dynamic
3632 relocations are REL. Setting relocation to it should
3633 arrange for it to be installed. */
3634 relocation
= addend
- rel
->r_addend
;
3636 check_segment
[0] = check_segment
[1] = got_segment
;
3640 if (! IS_FDPIC (output_bfd
))
3642 check_segment
[0] = check_segment
[1] = -1;
3646 case R_FRV_FUNCDESC_VALUE
:
3649 bfd_vma addend
= rel
->r_addend
;
3651 /* If the symbol is dynamic but binds locally, use
3653 if (h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
))
3655 if (addend
&& r_type
== R_FRV_FUNCDESC_VALUE
)
3657 info
->callbacks
->einfo
3658 (_("%H: %s references dynamic symbol"
3659 " with nonzero addend\n"),
3660 input_bfd
, input_section
, rel
->r_offset
,
3661 "R_FRV_FUNCDESC_VALUE");
3664 dynindx
= h
->dynindx
;
3669 addend
+= h
->root
.u
.def
.value
;
3671 addend
+= sym
->st_value
;
3673 addend
+= osec
->output_offset
;
3674 if (osec
&& osec
->output_section
3675 && ! bfd_is_abs_section (osec
->output_section
)
3676 && ! bfd_is_und_section (osec
->output_section
))
3677 dynindx
= elf_section_data (osec
->output_section
)->dynindx
;
3682 /* If we're linking an executable at a fixed address, we
3683 can omit the dynamic relocation as long as the symbol
3684 is defined in the current link unit (which is implied
3685 by its output section not being NULL). */
3686 if (bfd_link_pde (info
)
3687 && (!h
|| FRVFDPIC_SYM_LOCAL (info
, h
)))
3690 addend
+= osec
->output_section
->vma
;
3691 if (IS_FDPIC (input_bfd
)
3692 && (bfd_section_flags (input_section
->output_section
)
3693 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3695 if (_frvfdpic_osec_readonly_p (output_bfd
,
3699 info
->callbacks
->einfo
3700 (_("%H: cannot emit fixups in read-only section\n"),
3701 input_bfd
, input_section
, rel
->r_offset
);
3704 if (!h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
3706 bfd_vma offset
= _bfd_elf_section_offset
3708 input_section
, rel
->r_offset
);
3710 if (offset
!= (bfd_vma
)-1)
3712 _frvfdpic_add_rofixup (output_bfd
,
3713 frvfdpic_gotfixup_section
3715 offset
+ input_section
3716 ->output_section
->vma
3717 + input_section
->output_offset
,
3719 if (r_type
== R_FRV_FUNCDESC_VALUE
)
3720 _frvfdpic_add_rofixup
3722 frvfdpic_gotfixup_section (info
),
3724 + input_section
->output_section
->vma
3725 + input_section
->output_offset
+ 4, picrel
);
3732 if ((bfd_section_flags (input_section
->output_section
)
3733 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3737 if (_frvfdpic_osec_readonly_p (output_bfd
,
3741 info
->callbacks
->einfo
3742 (_("%H: cannot emit dynamic relocations"
3743 " in read-only section\n"),
3744 input_bfd
, input_section
, rel
->r_offset
);
3748 offset
= _bfd_elf_section_offset
3750 input_section
, rel
->r_offset
);
3752 if (offset
!= (bfd_vma
)-1)
3753 _frvfdpic_add_dyn_reloc (output_bfd
,
3754 frvfdpic_gotrel_section (info
),
3755 offset
+ input_section
3756 ->output_section
->vma
3757 + input_section
->output_offset
,
3758 r_type
, dynindx
, addend
, picrel
);
3761 addend
+= osec
->output_section
->vma
;
3762 /* We want the addend in-place because dynamic
3763 relocations are REL. Setting relocation to it
3764 should arrange for it to be installed. */
3765 relocation
= addend
- rel
->r_addend
;
3768 if (r_type
== R_FRV_FUNCDESC_VALUE
)
3770 /* If we've omitted the dynamic relocation, just emit
3771 the fixed addresses of the symbol and of the local
3773 if (bfd_link_pde (info
)
3774 && (!h
|| FRVFDPIC_SYM_LOCAL (info
, h
)))
3775 bfd_put_32 (output_bfd
,
3776 frvfdpic_got_section (info
)->output_section
->vma
3777 + frvfdpic_got_section (info
)->output_offset
3778 + frvfdpic_got_initial_offset (info
),
3779 contents
+ rel
->r_offset
+ 4);
3781 /* A function descriptor used for lazy or local
3782 resolving is initialized such that its high word
3783 contains the output section index in which the
3784 PLT entries are located, and the low word
3785 contains the offset of the lazy PLT entry entry
3786 point into that section. */
3787 bfd_put_32 (output_bfd
,
3788 h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
)
3790 : _frvfdpic_osec_to_segment (output_bfd
,
3793 contents
+ rel
->r_offset
+ 4);
3796 check_segment
[0] = check_segment
[1] = got_segment
;
3800 case R_FRV_GPRELU12
:
3804 check_segment
[0] = gprel_segment
;
3805 check_segment
[1] = sec
3806 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3810 case R_FRV_GETTLSOFF
:
3811 relocation
= frvfdpic_plt_section (info
)->output_section
->vma
3812 + frvfdpic_plt_section (info
)->output_offset
3813 + picrel
->tlsplt_entry
;
3814 BFD_ASSERT (picrel
->tlsplt_entry
!= (bfd_vma
)-1
3815 && picrel
->tlsdesc_entry
);
3816 check_segment
[0] = isec_segment
;
3817 check_segment
[1] = plt_segment
;
3820 case R_FRV_GOTTLSDESC12
:
3821 case R_FRV_GOTTLSDESCHI
:
3822 case R_FRV_GOTTLSDESCLO
:
3823 BFD_ASSERT (picrel
->tlsdesc_entry
);
3824 relocation
= picrel
->tlsdesc_entry
;
3825 check_segment
[0] = tls_segment
;
3826 check_segment
[1] = sec
3827 && ! bfd_is_abs_section (sec
)
3828 && ! bfd_is_und_section (sec
)
3829 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3833 case R_FRV_TLSMOFF12
:
3834 case R_FRV_TLSMOFFHI
:
3835 case R_FRV_TLSMOFFLO
:
3837 check_segment
[0] = tls_segment
;
3839 check_segment
[1] = -1;
3840 else if (bfd_is_abs_section (sec
)
3841 || bfd_is_und_section (sec
))
3844 check_segment
[1] = tls_segment
;
3846 else if (sec
->output_section
)
3848 relocation
-= tls_biased_base (info
);
3850 _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
);
3853 check_segment
[1] = -1;
3856 case R_FRV_GOTTLSOFF12
:
3857 case R_FRV_GOTTLSOFFHI
:
3858 case R_FRV_GOTTLSOFFLO
:
3859 BFD_ASSERT (picrel
->tlsoff_entry
);
3860 relocation
= picrel
->tlsoff_entry
;
3861 check_segment
[0] = tls_segment
;
3862 check_segment
[1] = sec
3863 && ! bfd_is_abs_section (sec
)
3864 && ! bfd_is_und_section (sec
)
3865 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3869 case R_FRV_TLSDESC_VALUE
:
3871 /* These shouldn't be present in input object files. */
3872 check_segment
[0] = check_segment
[1] = isec_segment
;
3875 case R_FRV_TLSDESC_RELAX
:
3876 case R_FRV_GETTLSOFF_RELAX
:
3877 case R_FRV_TLSOFF_RELAX
:
3878 /* These are just annotations for relaxation, nothing to do
3883 check_segment
[0] = isec_segment
;
3884 check_segment
[1] = sec
3885 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3890 if (check_segment
[0] != check_segment
[1] && IS_FDPIC (output_bfd
))
3892 /* If you take this out, remove the #error from fdpic-static-6.d
3893 in the ld testsuite. */
3894 /* This helps catch problems in GCC while we can't do more
3895 than static linking. The idea is to test whether the
3896 input file basename is crt0.o only once. */
3897 if (silence_segment_error
== 1)
3898 silence_segment_error
=
3899 (strlen (input_bfd
->filename
) == 6
3900 && filename_cmp (input_bfd
->filename
, "crt0.o") == 0)
3901 || (strlen (input_bfd
->filename
) > 6
3902 && filename_cmp (input_bfd
->filename
3903 + strlen (input_bfd
->filename
) - 7,
3906 if (!silence_segment_error
3907 /* We don't want duplicate errors for undefined
3909 && !(picrel
&& picrel
->symndx
== -1
3910 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefined
))
3912 info
->callbacks
->einfo
3913 /* xgettext:c-format */
3914 (_("%H: reloc against `%s' references a different segment\n"),
3915 input_bfd
, input_section
, rel
->r_offset
, name
);
3917 if (!silence_segment_error
&& bfd_link_pic (info
))
3919 elf_elfheader (output_bfd
)->e_flags
|= EF_FRV_PIC
;
3924 case R_FRV_GOTOFFHI
:
3925 case R_FRV_TLSMOFFHI
:
3926 /* We need the addend to be applied before we shift the
3928 relocation
+= rel
->r_addend
;
3931 case R_FRV_FUNCDESC_GOTHI
:
3932 case R_FRV_FUNCDESC_GOTOFFHI
:
3933 case R_FRV_GOTTLSOFFHI
:
3934 case R_FRV_GOTTLSDESCHI
:
3939 case R_FRV_FUNCDESC_GOTLO
:
3940 case R_FRV_GOTOFFLO
:
3941 case R_FRV_FUNCDESC_GOTOFFLO
:
3942 case R_FRV_GOTTLSOFFLO
:
3943 case R_FRV_GOTTLSDESCLO
:
3944 case R_FRV_TLSMOFFLO
:
3945 relocation
&= 0xffff;
3955 if (! IS_FDPIC (output_bfd
) || ! picrel
->plt
)
3959 /* When referencing a GOT entry, a function descriptor or a
3960 PLT, we don't want the addend to apply to the reference,
3961 but rather to the referenced symbol. The actual entry
3962 will have already been created taking the addend into
3963 account, so cancel it out here. */
3967 case R_FRV_FUNCDESC_GOT12
:
3968 case R_FRV_FUNCDESC_GOTHI
:
3969 case R_FRV_FUNCDESC_GOTLO
:
3970 case R_FRV_FUNCDESC_GOTOFF12
:
3971 case R_FRV_FUNCDESC_GOTOFFHI
:
3972 case R_FRV_FUNCDESC_GOTOFFLO
:
3973 case R_FRV_GETTLSOFF
:
3974 case R_FRV_GOTTLSDESC12
:
3975 case R_FRV_GOTTLSDESCHI
:
3976 case R_FRV_GOTTLSDESCLO
:
3977 case R_FRV_GOTTLSOFF12
:
3978 case R_FRV_GOTTLSOFFHI
:
3979 case R_FRV_GOTTLSOFFLO
:
3980 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
3981 here, since we do want to apply the addend to the others.
3982 Note that we've applied the addend to GOTOFFHI before we
3983 shifted it right. */
3984 case R_FRV_GOTOFFHI
:
3985 case R_FRV_TLSMOFFHI
:
3986 relocation
-= rel
->r_addend
;
3993 if (r_type
== R_FRV_HI16
)
3994 r
= elf32_frv_relocate_hi16 (input_bfd
, rel
, contents
, relocation
);
3996 else if (r_type
== R_FRV_LO16
)
3997 r
= elf32_frv_relocate_lo16 (input_bfd
, rel
, contents
, relocation
);
3999 else if (r_type
== R_FRV_LABEL24
|| r_type
== R_FRV_GETTLSOFF
)
4000 r
= elf32_frv_relocate_label24 (input_bfd
, input_section
, rel
,
4001 contents
, relocation
);
4003 else if (r_type
== R_FRV_GPREL12
)
4004 r
= elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, rel
,
4005 contents
, relocation
);
4007 else if (r_type
== R_FRV_GPRELU12
)
4008 r
= elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, rel
,
4009 contents
, relocation
);
4011 else if (r_type
== R_FRV_GPRELLO
)
4012 r
= elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, rel
,
4013 contents
, relocation
);
4015 else if (r_type
== R_FRV_GPRELHI
)
4016 r
= elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, rel
,
4017 contents
, relocation
);
4019 else if (r_type
== R_FRV_TLSOFF
4020 || r_type
== R_FRV_TLSDESC_VALUE
)
4021 r
= bfd_reloc_notsupported
;
4024 r
= frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
4027 if (r
!= bfd_reloc_ok
)
4029 const char * msg
= (const char *) NULL
;
4033 case bfd_reloc_overflow
:
4034 (*info
->callbacks
->reloc_overflow
)
4035 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4036 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
4039 case bfd_reloc_undefined
:
4040 (*info
->callbacks
->undefined_symbol
)
4041 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
4044 case bfd_reloc_outofrange
:
4045 msg
= _("internal error: out of range error");
4048 case bfd_reloc_notsupported
:
4049 msg
= _("internal error: unsupported relocation error");
4052 case bfd_reloc_dangerous
:
4053 msg
= _("internal error: dangerous relocation");
4057 msg
= _("internal error: unknown error");
4063 info
->callbacks
->einfo
4064 /* xgettext:c-format */
4065 (_("%H: reloc against `%s': %s\n"),
4066 input_bfd
, input_section
, rel
->r_offset
, name
, msg
);
4075 /* Return the section that should be marked against GC for a given
4079 elf32_frv_gc_mark_hook (asection
*sec
,
4080 struct bfd_link_info
*info
,
4081 Elf_Internal_Rela
*rel
,
4082 struct elf_link_hash_entry
*h
,
4083 Elf_Internal_Sym
*sym
)
4086 switch (ELF32_R_TYPE (rel
->r_info
))
4088 case R_FRV_GNU_VTINHERIT
:
4089 case R_FRV_GNU_VTENTRY
:
4093 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
4096 /* Hook called by the linker routine which adds symbols from an object
4097 file. We use it to put .comm items in .scomm, and not .comm. */
4100 elf32_frv_add_symbol_hook (bfd
*abfd
,
4101 struct bfd_link_info
*info
,
4102 Elf_Internal_Sym
*sym
,
4103 const char **namep ATTRIBUTE_UNUSED
,
4104 flagword
*flagsp ATTRIBUTE_UNUSED
,
4108 if (sym
->st_shndx
== SHN_COMMON
4109 && !bfd_link_relocatable (info
)
4110 && (int)sym
->st_size
<= (int)bfd_get_gp_size (abfd
))
4112 /* Common symbols less than or equal to -G nn bytes are
4113 automatically put into .sbss. */
4115 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
4119 scomm
= bfd_make_section_with_flags (abfd
, ".scommon",
4122 | SEC_LINKER_CREATED
));
4128 *valp
= sym
->st_size
;
4134 /* We need dynamic symbols for every section, since segments can
4135 relocate independently. */
4137 _frvfdpic_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4138 struct bfd_link_info
*info
4140 asection
*p ATTRIBUTE_UNUSED
)
4142 switch (elf_section_data (p
)->this_hdr
.sh_type
)
4146 /* If sh_type is yet undecided, assume it could be
4147 SHT_PROGBITS/SHT_NOBITS. */
4151 /* There shouldn't be section relative relocations
4152 against any other section. */
4158 /* Create a .got section, as well as its additional info field. This
4159 is almost entirely copied from
4160 elflink.c:_bfd_elf_create_got_section(). */
4163 _frv_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4165 flagword flags
, pltflags
;
4167 struct elf_link_hash_entry
*h
;
4168 struct bfd_link_hash_entry
*bh
;
4169 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4173 /* This function may be called more than once. */
4174 s
= elf_hash_table (info
)->sgot
;
4178 /* Machine specific: although pointers are 32-bits wide, we want the
4179 GOT to be aligned to a 64-bit boundary, such that function
4180 descriptors in it can be accessed with 64-bit loads and
4184 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4185 | SEC_LINKER_CREATED
);
4188 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
4189 elf_hash_table (info
)->sgot
= s
;
4191 || !bfd_set_section_alignment (s
, ptralign
))
4194 if (bed
->want_got_sym
)
4196 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
4197 (or .got.plt) section. We don't do this in the linker script
4198 because we don't want to define the symbol if we are not creating
4199 a global offset table. */
4200 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
, "_GLOBAL_OFFSET_TABLE_");
4201 elf_hash_table (info
)->hgot
= h
;
4205 /* Machine-specific: we want the symbol for executables as
4207 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4211 /* The first bit of the global offset table is the header. */
4212 s
->size
+= bed
->got_header_size
;
4214 /* This is the machine-specific part. Create and initialize section
4215 data for the got. */
4216 if (IS_FDPIC (abfd
))
4218 frvfdpic_relocs_info (info
) = htab_try_create (1,
4219 frvfdpic_relocs_info_hash
,
4220 frvfdpic_relocs_info_eq
,
4222 if (! frvfdpic_relocs_info (info
))
4225 s
= bfd_make_section_anyway_with_flags (abfd
, ".rel.got",
4226 (flags
| SEC_READONLY
));
4227 elf_hash_table (info
)->srelgot
= s
;
4229 || !bfd_set_section_alignment (s
, 2))
4232 /* Machine-specific. */
4233 s
= bfd_make_section_anyway_with_flags (abfd
, ".rofixup",
4234 (flags
| SEC_READONLY
));
4236 || !bfd_set_section_alignment (s
, 2))
4239 frvfdpic_gotfixup_section (info
) = s
;
4246 flags
= BSF_GLOBAL
| BSF_WEAK
;
4249 /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it
4250 turns out that we're linking with a different linker script, the
4251 linker script will override it. */
4253 if (!(_bfd_generic_link_add_one_symbol
4254 (info
, abfd
, "_gp", flags
, s
, offset
, (const char *) NULL
, FALSE
,
4255 bed
->collect
, &bh
)))
4257 h
= (struct elf_link_hash_entry
*) bh
;
4259 h
->type
= STT_OBJECT
;
4260 /* h->other = STV_HIDDEN; */ /* Should we? */
4262 /* Machine-specific: we want the symbol for executables as well. */
4263 if (IS_FDPIC (abfd
) && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
4266 if (!IS_FDPIC (abfd
))
4269 /* FDPIC supports Thread Local Storage, and this may require a
4270 procedure linkage table for TLS PLT entries. */
4272 /* This is mostly copied from
4273 elflink.c:_bfd_elf_create_dynamic_sections(). */
4276 pltflags
|= SEC_CODE
;
4277 if (bed
->plt_not_loaded
)
4278 pltflags
&= ~ (SEC_CODE
| SEC_LOAD
| SEC_HAS_CONTENTS
);
4279 if (bed
->plt_readonly
)
4280 pltflags
|= SEC_READONLY
;
4282 s
= bfd_make_section_anyway_with_flags (abfd
, ".plt", pltflags
);
4284 || !bfd_set_section_alignment (s
, bed
->plt_alignment
))
4286 /* FRV-specific: remember it. */
4287 frvfdpic_plt_section (info
) = s
;
4289 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
4291 if (bed
->want_plt_sym
)
4293 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
4294 "_PROCEDURE_LINKAGE_TABLE_");
4295 elf_hash_table (info
)->hplt
= h
;
4300 /* FRV-specific: we want rel relocations for the plt. */
4301 s
= bfd_make_section_anyway_with_flags (abfd
, ".rel.plt",
4302 flags
| SEC_READONLY
);
4304 || !bfd_set_section_alignment (s
, bed
->s
->log_file_align
))
4306 /* FRV-specific: remember it. */
4307 frvfdpic_pltrel_section (info
) = s
;
4312 /* Make sure the got and plt sections exist, and that our pointers in
4313 the link hash table point to them. */
4316 elf32_frvfdpic_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
4318 /* This is mostly copied from
4319 elflink.c:_bfd_elf_create_dynamic_sections(). */
4322 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4324 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4325 | SEC_LINKER_CREATED
);
4327 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
4328 .rel[a].bss sections. */
4330 /* FRV-specific: we want to create the GOT and the PLT in the FRV
4332 if (! _frv_create_got_section (abfd
, info
))
4335 /* FRV-specific: make sure we created everything we wanted. */
4336 BFD_ASSERT (frvfdpic_got_section (info
) && frvfdpic_gotrel_section (info
)
4337 && frvfdpic_gotfixup_section (info
)
4338 && frvfdpic_plt_section (info
)
4339 && frvfdpic_pltrel_section (info
));
4341 if (bed
->want_dynbss
)
4343 /* The .dynbss section is a place to put symbols which are defined
4344 by dynamic objects, are referenced by regular objects, and are
4345 not functions. We must allocate space for them in the process
4346 image and use a R_*_COPY reloc to tell the dynamic linker to
4347 initialize them at run time. The linker script puts the .dynbss
4348 section into the .bss section of the final image. */
4349 s
= bfd_make_section_anyway_with_flags (abfd
, ".dynbss",
4350 SEC_ALLOC
| SEC_LINKER_CREATED
);
4354 /* The .rel[a].bss section holds copy relocs. This section is not
4355 normally needed. We need to create it here, though, so that the
4356 linker will map it to an output section. We can't just create it
4357 only if we need it, because we will not know whether we need it
4358 until we have seen all the input files, and the first time the
4359 main linker code calls BFD after examining all the input files
4360 (size_dynamic_sections) the input sections have already been
4361 mapped to the output sections. If the section turns out not to
4362 be needed, we can discard it later. We will never need this
4363 section when generating a shared object, since they do not use
4365 if (! bfd_link_pic (info
))
4367 s
= bfd_make_section_anyway_with_flags (abfd
,
4368 (bed
->default_use_rela_p
4369 ? ".rela.bss" : ".rel.bss"),
4370 flags
| SEC_READONLY
);
4372 || !bfd_set_section_alignment (s
, bed
->s
->log_file_align
))
4380 /* Compute the total GOT and PLT size required by each symbol in each
4381 range. Symbols may require up to 4 words in the GOT: an entry
4382 pointing to the symbol, an entry pointing to its function
4383 descriptor, and a private function descriptors taking two
4387 _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info
*entry
,
4388 struct _frvfdpic_dynamic_got_info
*dinfo
)
4390 /* Allocate space for a GOT entry pointing to the symbol. */
4393 else if (entry
->gotlos
)
4395 else if (entry
->gothilo
)
4396 dinfo
->gothilo
+= 4;
4401 /* Allocate space for a GOT entry pointing to the function
4405 else if (entry
->fdgotlos
)
4407 else if (entry
->fdgothilo
)
4408 dinfo
->gothilo
+= 4;
4413 /* Decide whether we need a PLT entry, a function descriptor in the
4414 GOT, and a lazy PLT entry for this symbol. */
4415 entry
->plt
= entry
->call
4416 && entry
->symndx
== -1 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4417 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
4418 entry
->privfd
= entry
->plt
4419 || entry
->fdgoff12
|| entry
->fdgofflos
|| entry
->fdgoffhilo
4420 || ((entry
->fd
|| entry
->fdgot12
|| entry
->fdgotlos
|| entry
->fdgothilo
)
4421 && (entry
->symndx
!= -1
4422 || FRVFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
)));
4423 entry
->lazyplt
= entry
->privfd
4424 && entry
->symndx
== -1 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4425 && ! (dinfo
->info
->flags
& DF_BIND_NOW
)
4426 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
4428 /* Allocate space for a function descriptor. */
4429 if (entry
->fdgoff12
)
4431 else if (entry
->fdgofflos
)
4433 else if (entry
->privfd
&& entry
->plt
)
4435 else if (entry
->privfd
)
4445 /* Compute the total GOT size required by each TLS symbol in each
4446 range. Symbols may require up to 5 words in the GOT: an entry
4447 holding the TLS offset for the symbol, and an entry with a full TLS
4448 descriptor taking 4 words. */
4451 _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info
*entry
,
4452 struct _frvfdpic_dynamic_got_info
*dinfo
,
4453 bfd_boolean subtract
)
4455 const int l
= subtract
? -1 : 1;
4457 /* Allocate space for a GOT entry with the TLS offset of the
4459 if (entry
->tlsoff12
)
4460 dinfo
->got12
+= 4 * l
;
4461 else if (entry
->tlsofflos
)
4462 dinfo
->gotlos
+= 4 * l
;
4463 else if (entry
->tlsoffhilo
)
4464 dinfo
->gothilo
+= 4 * l
;
4466 entry
->relocstlsoff
-= l
;
4467 entry
->relocstlsoff
+= l
;
4469 /* If there's any TLSOFF relocation, mark the output file as not
4470 suitable for dlopening. This mark will remain even if we relax
4471 all such relocations, but this is not a problem, since we'll only
4472 do so for executables, and we definitely don't want anyone
4473 dlopening executables. */
4474 if (entry
->relocstlsoff
)
4475 dinfo
->info
->flags
|= DF_STATIC_TLS
;
4477 /* Allocate space for a TLS descriptor. */
4478 if (entry
->tlsdesc12
)
4479 dinfo
->tlsd12
+= 8 * l
;
4480 else if (entry
->tlsdesclos
)
4481 dinfo
->tlsdlos
+= 8 * l
;
4482 else if (entry
->tlsplt
)
4483 dinfo
->tlsdplt
+= 8 * l
;
4484 else if (entry
->tlsdeschilo
)
4485 dinfo
->tlsdhilo
+= 8 * l
;
4487 entry
->relocstlsd
-= l
;
4488 entry
->relocstlsd
+= l
;
4491 /* Compute the number of dynamic relocations and fixups that a symbol
4492 requires, and add (or subtract) from the grand and per-symbol
4496 _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info
*entry
,
4497 struct _frvfdpic_dynamic_got_info
*dinfo
,
4498 bfd_boolean subtract
)
4500 bfd_vma relocs
= 0, fixups
= 0, tlsrets
= 0;
4502 if (!bfd_link_pde (dinfo
->info
))
4504 relocs
= entry
->relocs32
+ entry
->relocsfd
+ entry
->relocsfdv
4505 + entry
->relocstlsd
;
4507 /* In the executable, TLS relocations to symbols that bind
4508 locally (including those that resolve to global TLS offsets)
4509 are resolved immediately, without any need for fixups or
4510 dynamic relocations. In shared libraries, however, we must
4511 emit dynamic relocations even for local symbols, because we
4512 don't know the module id the library is going to get at
4513 run-time, nor its TLS base offset. */
4514 if (!bfd_link_executable (dinfo
->info
)
4515 || (entry
->symndx
== -1
4516 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)))
4517 relocs
+= entry
->relocstlsoff
;
4521 if (entry
->symndx
!= -1 || FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
))
4523 if (entry
->symndx
!= -1
4524 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
4525 fixups
+= entry
->relocs32
+ 2 * entry
->relocsfdv
;
4526 fixups
+= entry
->relocstlsd
;
4527 tlsrets
+= entry
->relocstlsd
;
4531 relocs
+= entry
->relocs32
+ entry
->relocsfdv
4532 + entry
->relocstlsoff
+ entry
->relocstlsd
;
4535 if (entry
->symndx
!= -1
4536 || FRVFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
))
4538 if (entry
->symndx
!= -1
4539 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
4540 fixups
+= entry
->relocsfd
;
4543 relocs
+= entry
->relocsfd
;
4550 tlsrets
= - tlsrets
;
4553 entry
->dynrelocs
+= relocs
;
4554 entry
->fixups
+= fixups
;
4555 dinfo
->relocs
+= relocs
;
4556 dinfo
->fixups
+= fixups
;
4557 dinfo
->tls_ret_refs
+= tlsrets
;
4560 /* Look for opportunities to relax TLS relocations. We can assume
4561 we're linking the main executable or a static-tls library, since
4562 otherwise we wouldn't have got here. When relaxing, we have to
4563 first undo any previous accounting of TLS uses of fixups, dynamic
4564 relocations, GOT and PLT entries. */
4567 _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info
*entry
,
4568 struct _frvfdpic_dynamic_got_info
*dinfo
,
4569 bfd_boolean relaxing
)
4571 bfd_boolean changed
= ! relaxing
;
4573 BFD_ASSERT (bfd_link_executable (dinfo
->info
)
4574 || (dinfo
->info
->flags
& DF_STATIC_TLS
));
4576 if (entry
->tlsdesc12
|| entry
->tlsdesclos
|| entry
->tlsdeschilo
)
4580 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4581 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4585 /* When linking an executable, we can always decay GOTTLSDESC to
4586 TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise.
4587 When linking a static-tls shared library, using TLSMOFF is
4588 not an option, but we can still use GOTTLSOFF. When decaying
4589 to GOTTLSOFF, we must keep the GOT entry in range. We know
4590 it has to fit because we'll be trading the 4 words of hte TLS
4591 descriptor for a single word in the same range. */
4592 if (! bfd_link_executable (dinfo
->info
)
4593 || (entry
->symndx
== -1
4594 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)))
4596 entry
->tlsoff12
|= entry
->tlsdesc12
;
4597 entry
->tlsofflos
|= entry
->tlsdesclos
;
4598 entry
->tlsoffhilo
|= entry
->tlsdeschilo
;
4601 entry
->tlsdesc12
= entry
->tlsdesclos
= entry
->tlsdeschilo
= 0;
4604 /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the
4605 main executable. We have to check whether the symbol's TLSOFF is
4606 in range for a setlos. For symbols with a hash entry, we can
4607 determine exactly what to do; for others locals, we don't have
4608 addresses handy, so we use the size of the TLS section as an
4609 approximation. If we get it wrong, we'll retain a GOT entry
4610 holding the TLS offset (without dynamic relocations or fixups),
4611 but we'll still optimize away the loads from it. Since TLS sizes
4612 are generally very small, it's probably not worth attempting to
4613 do better than this. */
4615 || entry
->tlsoff12
|| entry
->tlsofflos
|| entry
->tlsoffhilo
)
4616 && bfd_link_executable (dinfo
->info
) && relaxing
4617 && ((entry
->symndx
== -1
4618 && FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4619 /* The above may hold for an undefweak TLS symbol, so make
4620 sure we don't have this case before accessing def.value
4622 && (entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
4623 || (bfd_vma
)(entry
->d
.h
->root
.u
.def
.value
4624 + (entry
->d
.h
->root
.u
.def
.section
4625 ->output_section
->vma
)
4626 + entry
->d
.h
->root
.u
.def
.section
->output_offset
4628 - tls_biased_base (dinfo
->info
)
4629 + 32768) < (bfd_vma
)65536))
4630 || (entry
->symndx
!= -1
4631 && (elf_hash_table (dinfo
->info
)->tls_sec
->size
4632 + entry
->addend
< 32768 + FRVFDPIC_TLS_BIAS
))))
4636 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4637 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4642 entry
->tlsoff12
= entry
->tlsofflos
= entry
->tlsoffhilo
= 0;
4645 /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already
4646 have a #gottlsoff12 relocation for this entry, or if we can fit
4647 one more in the 12-bit (and 16-bit) ranges. */
4651 && dinfo
->got12
+ dinfo
->fd12
+ dinfo
->tlsd12
<= 4096 - 12 - 4
4652 && (dinfo
->got12
+ dinfo
->fd12
+ dinfo
->tlsd12
4653 + dinfo
->gotlos
+ dinfo
->fdlos
+ dinfo
->tlsdlos
4654 <= 65536 - 12 - 4))))
4658 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4659 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4663 entry
->tlsoff12
= 1;
4669 _frvfdpic_count_tls_entries (entry
, dinfo
, FALSE
);
4670 _frvfdpic_count_relocs_fixups (entry
, dinfo
, FALSE
);
4676 /* Compute the total GOT and PLT size required by each symbol in each range. *
4677 Symbols may require up to 4 words in the GOT: an entry pointing to
4678 the symbol, an entry pointing to its function descriptor, and a
4679 private function descriptors taking two words. */
4682 _frvfdpic_count_got_plt_entries (void **entryp
, void *dinfo_
)
4684 struct frvfdpic_relocs_info
*entry
= *entryp
;
4685 struct _frvfdpic_dynamic_got_info
*dinfo
= dinfo_
;
4687 _frvfdpic_count_nontls_entries (entry
, dinfo
);
4689 if (bfd_link_executable (dinfo
->info
)
4690 || (dinfo
->info
->flags
& DF_STATIC_TLS
))
4691 _frvfdpic_relax_tls_entries (entry
, dinfo
, FALSE
);
4694 _frvfdpic_count_tls_entries (entry
, dinfo
, FALSE
);
4695 _frvfdpic_count_relocs_fixups (entry
, dinfo
, FALSE
);
4701 /* Determine the positive and negative ranges to be used by each
4702 offset range in the GOT. FDCUR and CUR, that must be aligned to a
4703 double-word boundary, are the minimum (negative) and maximum
4704 (positive) GOT offsets already used by previous ranges, except for
4705 an ODD entry that may have been left behind. GOT and FD indicate
4706 the size of GOT entries and function descriptors that must be
4707 placed within the range from -WRAP to WRAP. If there's room left,
4708 up to FDPLT bytes should be reserved for additional function
4711 inline static bfd_signed_vma
4712 _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data
*gad
,
4713 bfd_signed_vma fdcur
,
4723 bfd_signed_vma wrapmin
= -wrap
;
4724 const bfd_vma tdescsz
= 8;
4726 /* Start at the given initial points. */
4730 /* If we had an incoming odd word and we have any got entries that
4731 are going to use it, consume it, otherwise leave gad->odd at
4732 zero. We might force gad->odd to zero and return the incoming
4733 odd such that it is used by the next range, but then GOT entries
4734 might appear to be out of order and we wouldn't be able to
4735 shorten the GOT by one word if it turns out to end with an
4736 unpaired GOT entry. */
4746 /* If we're left with an unpaired GOT entry, compute its location
4747 such that we can return it. Otherwise, if got doesn't require an
4748 odd number of words here, either odd was already zero in the
4749 block above, or it was set to zero because got was non-zero, or
4750 got was already zero. In the latter case, we want the value of
4751 odd to carry over to the return statement, so we don't want to
4752 reset odd unless the condition below is true. */
4759 /* Compute the tentative boundaries of this range. */
4760 gad
->max
= cur
+ got
;
4761 gad
->min
= fdcur
- fd
;
4764 /* If function descriptors took too much space, wrap some of them
4766 if (gad
->min
< wrapmin
)
4768 gad
->max
+= wrapmin
- gad
->min
;
4769 gad
->tmin
= gad
->min
= wrapmin
;
4772 /* If GOT entries took too much space, wrap some of them around.
4773 This may well cause gad->min to become lower than wrapmin. This
4774 will cause a relocation overflow later on, so we don't have to
4776 if ((bfd_vma
) gad
->max
> wrap
)
4778 gad
->min
-= gad
->max
- wrap
;
4782 /* Add TLS descriptors. */
4783 gad
->tmax
= gad
->max
+ tlsd
;
4784 gad
->tmin
= gad
->min
;
4787 /* If TLS descriptors took too much space, wrap an integral number
4789 if ((bfd_vma
) gad
->tmax
> wrap
)
4791 bfd_vma wrapsize
= gad
->tmax
- wrap
;
4793 wrapsize
+= tdescsz
/ 2;
4794 wrapsize
&= ~ tdescsz
/ 2;
4796 gad
->tmin
-= wrapsize
;
4797 gad
->tmax
-= wrapsize
;
4800 /* If there is space left and we have function descriptors
4801 referenced in PLT entries that could take advantage of shorter
4802 offsets, place them now. */
4803 if (fdplt
&& gad
->tmin
> wrapmin
)
4807 if ((bfd_vma
) (gad
->tmin
- wrapmin
) < fdplt
)
4808 fds
= gad
->tmin
- wrapmin
;
4818 /* If there is more space left, try to place some more function
4819 descriptors for PLT entries. */
4820 if (fdplt
&& (bfd_vma
) gad
->tmax
< wrap
)
4824 if ((bfd_vma
) (wrap
- gad
->tmax
) < fdplt
)
4825 fds
= wrap
- gad
->tmax
;
4835 /* If there is space left and we have TLS descriptors referenced in
4836 PLT entries that could take advantage of shorter offsets, place
4838 if (tlsdplt
&& gad
->tmin
> wrapmin
)
4842 if ((bfd_vma
) (gad
->tmin
- wrapmin
) < tlsdplt
)
4843 tlsds
= (gad
->tmin
- wrapmin
) & ~ (tdescsz
/ 2);
4849 gad
->tlsdplt
+= tlsds
;
4852 /* If there is more space left, try to place some more TLS
4853 descriptors for PLT entries. Although we could try to fit an
4854 additional TLS descriptor with half of it just before before the
4855 wrap point and another right past the wrap point, this might
4856 cause us to run out of space for the next region, so don't do
4858 if (tlsdplt
&& (bfd_vma
) gad
->tmax
< wrap
- tdescsz
/ 2)
4862 if ((bfd_vma
) (wrap
- gad
->tmax
) < tlsdplt
)
4863 tlsds
= (wrap
- gad
->tmax
) & ~ (tdescsz
/ 2);
4869 gad
->tlsdplt
+= tlsds
;
4872 /* If odd was initially computed as an offset past the wrap point,
4875 odd
= gad
->min
+ odd
- gad
->max
;
4877 /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed
4878 before returning, so do it here too. This guarantees that,
4879 should cur and fdcur meet at the wrap point, they'll both be
4881 if (gad
->cur
== gad
->max
)
4882 gad
->cur
= gad
->min
;
4884 /* Ditto for _frvfdpic_get_tlsdesc_entry(). */
4885 gad
->tcur
= gad
->max
;
4886 if (gad
->tcur
== gad
->tmax
)
4887 gad
->tcur
= gad
->tmin
;
4892 /* Compute the location of the next GOT entry, given the allocation
4893 data for a range. */
4895 inline static bfd_signed_vma
4896 _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
4902 /* If there was an odd word left behind, use it. */
4908 /* Otherwise, use the word pointed to by cur, reserve the next
4909 as an odd word, and skip to the next pair of words, possibly
4912 gad
->odd
= gad
->cur
+ 4;
4914 if (gad
->cur
== gad
->max
)
4915 gad
->cur
= gad
->min
;
4921 /* Compute the location of the next function descriptor entry in the
4922 GOT, given the allocation data for a range. */
4924 inline static bfd_signed_vma
4925 _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
4927 /* If we're at the bottom, wrap around, and only then allocate the
4928 next pair of words. */
4929 if (gad
->fdcur
== gad
->min
)
4930 gad
->fdcur
= gad
->max
;
4931 return gad
->fdcur
-= 8;
4934 /* Compute the location of the next TLS descriptor entry in the GOT,
4935 given the allocation data for a range. */
4936 inline static bfd_signed_vma
4937 _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
4945 /* If we're at the top of the region, wrap around to the bottom. */
4946 if (gad
->tcur
== gad
->tmax
)
4947 gad
->tcur
= gad
->tmin
;
4952 /* Assign GOT offsets for every GOT entry and function descriptor.
4953 Doing everything in a single pass is tricky. */
4956 _frvfdpic_assign_got_entries (void **entryp
, void *info_
)
4958 struct frvfdpic_relocs_info
*entry
= *entryp
;
4959 struct _frvfdpic_dynamic_got_plt_info
*dinfo
= info_
;
4962 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
4963 else if (entry
->gotlos
)
4964 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
4965 else if (entry
->gothilo
)
4966 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
4969 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
4970 else if (entry
->fdgotlos
)
4971 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
4972 else if (entry
->fdgothilo
)
4973 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
4975 if (entry
->fdgoff12
)
4976 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->got12
);
4977 else if (entry
->plt
&& dinfo
->got12
.fdplt
)
4979 dinfo
->got12
.fdplt
-= 8;
4980 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->got12
);
4982 else if (entry
->fdgofflos
)
4983 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gotlos
);
4984 else if (entry
->plt
&& dinfo
->gotlos
.fdplt
)
4986 dinfo
->gotlos
.fdplt
-= 8;
4987 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gotlos
);
4989 else if (entry
->plt
)
4991 dinfo
->gothilo
.fdplt
-= 8;
4992 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gothilo
);
4994 else if (entry
->privfd
)
4995 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gothilo
);
4997 if (entry
->tlsoff12
)
4998 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
4999 else if (entry
->tlsofflos
)
5000 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5001 else if (entry
->tlsoffhilo
)
5002 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5004 if (entry
->tlsdesc12
)
5005 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->got12
);
5006 else if (entry
->tlsplt
&& dinfo
->got12
.tlsdplt
)
5008 dinfo
->got12
.tlsdplt
-= 8;
5009 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->got12
);
5011 else if (entry
->tlsdesclos
)
5012 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gotlos
);
5013 else if (entry
->tlsplt
&& dinfo
->gotlos
.tlsdplt
)
5015 dinfo
->gotlos
.tlsdplt
-= 8;
5016 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gotlos
);
5018 else if (entry
->tlsplt
)
5020 dinfo
->gothilo
.tlsdplt
-= 8;
5021 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gothilo
);
5023 else if (entry
->tlsdeschilo
)
5024 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gothilo
);
5029 /* Assign GOT offsets to private function descriptors used by PLT
5030 entries (or referenced by 32-bit offsets), as well as PLT entries
5031 and lazy PLT entries. */
5034 _frvfdpic_assign_plt_entries (void **entryp
, void *info_
)
5036 struct frvfdpic_relocs_info
*entry
= *entryp
;
5037 struct _frvfdpic_dynamic_got_plt_info
*dinfo
= info_
;
5040 BFD_ASSERT (entry
->fd_entry
);
5046 /* We use the section's raw size to mark the location of the
5048 entry
->plt_entry
= frvfdpic_plt_section (dinfo
->g
.info
)->size
;
5050 /* Figure out the length of this PLT entry based on the
5051 addressing mode we need to reach the function descriptor. */
5052 BFD_ASSERT (entry
->fd_entry
);
5053 if (entry
->fd_entry
>= -(1 << (12 - 1))
5054 && entry
->fd_entry
< (1 << (12 - 1)))
5056 else if (entry
->fd_entry
>= -(1 << (16 - 1))
5057 && entry
->fd_entry
< (1 << (16 - 1)))
5062 frvfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
5067 entry
->lzplt_entry
= dinfo
->g
.lzplt
;
5068 dinfo
->g
.lzplt
+= 8;
5069 /* If this entry is the one that gets the resolver stub, account
5070 for the additional instruction. */
5071 if (entry
->lzplt_entry
% FRVFDPIC_LZPLT_BLOCK_SIZE
5072 == FRVFDPIC_LZPLT_RESOLV_LOC
)
5073 dinfo
->g
.lzplt
+= 4;
5081 = frvfdpic_plt_section (dinfo
->g
.info
)->size
;
5083 if (bfd_link_executable (dinfo
->g
.info
)
5084 && (entry
->symndx
!= -1
5085 || FRVFDPIC_SYM_LOCAL (dinfo
->g
.info
, entry
->d
.h
)))
5087 if ((bfd_signed_vma
)entry
->addend
>= -(1 << (16 - 1))
5088 /* FIXME: here we use the size of the TLS section
5089 as an upper bound for the value of the TLS
5090 symbol, because we may not know the exact value
5091 yet. If we get it wrong, we'll just waste a
5092 word in the PLT, and we should never get even
5093 close to 32 KiB of TLS anyway. */
5094 && elf_hash_table (dinfo
->g
.info
)->tls_sec
5095 && (elf_hash_table (dinfo
->g
.info
)->tls_sec
->size
5096 + (bfd_signed_vma
)(entry
->addend
) <= (1 << (16 - 1))))
5101 else if (entry
->tlsoff_entry
)
5103 if (entry
->tlsoff_entry
>= -(1 << (12 - 1))
5104 && entry
->tlsoff_entry
< (1 << (12 - 1)))
5106 else if (entry
->tlsoff_entry
>= -(1 << (16 - 1))
5107 && entry
->tlsoff_entry
< (1 << (16 - 1)))
5114 BFD_ASSERT (entry
->tlsdesc_entry
);
5116 if (entry
->tlsdesc_entry
>= -(1 << (12 - 1))
5117 && entry
->tlsdesc_entry
< (1 << (12 - 1)))
5119 else if (entry
->tlsdesc_entry
>= -(1 << (16 - 1))
5120 && entry
->tlsdesc_entry
< (1 << (16 - 1)))
5126 frvfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
5132 /* Cancel out any effects of calling _frvfdpic_assign_got_entries and
5133 _frvfdpic_assign_plt_entries. */
5136 _frvfdpic_reset_got_plt_entries (void **entryp
, void *ignore ATTRIBUTE_UNUSED
)
5138 struct frvfdpic_relocs_info
*entry
= *entryp
;
5140 entry
->got_entry
= 0;
5141 entry
->fdgot_entry
= 0;
5142 entry
->fd_entry
= 0;
5143 entry
->plt_entry
= (bfd_vma
)-1;
5144 entry
->lzplt_entry
= (bfd_vma
)-1;
5145 entry
->tlsoff_entry
= 0;
5146 entry
->tlsdesc_entry
= 0;
5147 entry
->tlsplt_entry
= (bfd_vma
)-1;
5152 /* Follow indirect and warning hash entries so that each got entry
5153 points to the final symbol definition. P must point to a pointer
5154 to the hash table we're traversing. Since this traversal may
5155 modify the hash table, we set this pointer to NULL to indicate
5156 we've made a potentially-destructive change to the hash table, so
5157 the traversal must be restarted. */
5159 _frvfdpic_resolve_final_relocs_info (void **entryp
, void *p
)
5161 struct frvfdpic_relocs_info
*entry
= *entryp
;
5164 if (entry
->symndx
== -1)
5166 struct elf_link_hash_entry
*h
= entry
->d
.h
;
5167 struct frvfdpic_relocs_info
*oentry
;
5169 while (h
->root
.type
== bfd_link_hash_indirect
5170 || h
->root
.type
== bfd_link_hash_warning
)
5171 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
5173 if (entry
->d
.h
== h
)
5176 oentry
= frvfdpic_relocs_info_for_global (*htab
, 0, h
, entry
->addend
,
5181 /* Merge the two entries. */
5182 frvfdpic_pic_merge_early_relocs_info (oentry
, entry
);
5183 htab_clear_slot (*htab
, entryp
);
5189 /* If we can't find this entry with the new bfd hash, re-insert
5190 it, and get the traversal restarted. */
5191 if (! htab_find (*htab
, entry
))
5193 htab_clear_slot (*htab
, entryp
);
5194 entryp
= htab_find_slot (*htab
, entry
, INSERT
);
5197 /* Abort the traversal, since the whole table may have
5198 moved, and leave it up to the parent to restart the
5200 *(htab_t
*)p
= NULL
;
5208 /* Compute the total size of the GOT, the PLT, the dynamic relocations
5209 section and the rofixup section. Assign locations for GOT and PLT
5213 _frvfdpic_size_got_plt (bfd
*output_bfd
,
5214 struct _frvfdpic_dynamic_got_plt_info
*gpinfop
)
5217 bfd_vma limit
, tlslimit
;
5218 struct bfd_link_info
*info
= gpinfop
->g
.info
;
5219 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
5221 memcpy (frvfdpic_dynamic_got_plt_info (info
), &gpinfop
->g
,
5222 sizeof (gpinfop
->g
));
5225 /* Compute the total size taken by entries in the 12-bit and 16-bit
5226 ranges, to tell how many PLT function descriptors we can bring
5227 into the 12-bit range without causing the 16-bit range to
5229 limit
= odd
+ gpinfop
->g
.got12
+ gpinfop
->g
.gotlos
5230 + gpinfop
->g
.fd12
+ gpinfop
->g
.fdlos
5231 + gpinfop
->g
.tlsd12
+ gpinfop
->g
.tlsdlos
;
5232 if (limit
< (bfd_vma
)1 << 16)
5233 limit
= ((bfd_vma
)1 << 16) - limit
;
5236 if (gpinfop
->g
.fdplt
< limit
)
5238 tlslimit
= (limit
- gpinfop
->g
.fdplt
) & ~ (bfd_vma
) 8;
5239 limit
= gpinfop
->g
.fdplt
;
5243 if (gpinfop
->g
.tlsdplt
< tlslimit
)
5244 tlslimit
= gpinfop
->g
.tlsdplt
;
5246 /* Determine the ranges of GOT offsets that we can use for each
5247 range of addressing modes. */
5248 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->got12
,
5257 (bfd_vma
)1 << (12-1));
5258 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->gotlos
,
5259 gpinfop
->got12
.tmin
,
5261 gpinfop
->got12
.tmax
,
5265 - gpinfop
->got12
.fdplt
,
5268 - gpinfop
->got12
.tlsdplt
,
5269 (bfd_vma
)1 << (16-1));
5270 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->gothilo
,
5271 gpinfop
->gotlos
.tmin
,
5273 gpinfop
->gotlos
.tmax
,
5277 - gpinfop
->got12
.fdplt
5278 - gpinfop
->gotlos
.fdplt
,
5279 gpinfop
->g
.tlsdhilo
,
5281 - gpinfop
->got12
.tlsdplt
5282 - gpinfop
->gotlos
.tlsdplt
,
5283 (bfd_vma
)1 << (32-1));
5285 /* Now assign (most) GOT offsets. */
5286 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_assign_got_entries
,
5289 frvfdpic_got_section (info
)->size
= gpinfop
->gothilo
.tmax
5290 - gpinfop
->gothilo
.tmin
5291 /* If an odd word is the last word of the GOT, we don't need this
5292 word to be part of the GOT. */
5293 - (odd
+ 4 == gpinfop
->gothilo
.tmax
? 4 : 0);
5294 if (frvfdpic_got_section (info
)->size
== 0)
5295 frvfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
5296 else if (frvfdpic_got_section (info
)->size
== 12
5297 && ! elf_hash_table (info
)->dynamic_sections_created
)
5299 frvfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
5300 frvfdpic_got_section (info
)->size
= 0;
5302 /* This will be non-NULL during relaxation. The assumption is that
5303 the size of one of these sections will never grow, only shrink,
5304 so we can use the larger buffer we allocated before. */
5305 else if (frvfdpic_got_section (info
)->contents
== NULL
)
5307 frvfdpic_got_section (info
)->contents
=
5308 (bfd_byte
*) bfd_zalloc (dynobj
,
5309 frvfdpic_got_section (info
)->size
);
5310 if (frvfdpic_got_section (info
)->contents
== NULL
)
5314 if (frvfdpic_gotrel_section (info
))
5315 /* Subtract the number of lzplt entries, since those will generate
5316 relocations in the pltrel section. */
5317 frvfdpic_gotrel_section (info
)->size
=
5318 (gpinfop
->g
.relocs
- gpinfop
->g
.lzplt
/ 8)
5319 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
5321 BFD_ASSERT (gpinfop
->g
.relocs
== 0);
5322 if (frvfdpic_gotrel_section (info
)->size
== 0)
5323 frvfdpic_gotrel_section (info
)->flags
|= SEC_EXCLUDE
;
5324 else if (frvfdpic_gotrel_section (info
)->contents
== NULL
)
5326 frvfdpic_gotrel_section (info
)->contents
=
5327 (bfd_byte
*) bfd_zalloc (dynobj
,
5328 frvfdpic_gotrel_section (info
)->size
);
5329 if (frvfdpic_gotrel_section (info
)->contents
== NULL
)
5333 frvfdpic_gotfixup_section (info
)->size
= (gpinfop
->g
.fixups
+ 1) * 4;
5334 if (frvfdpic_gotfixup_section (info
)->size
== 0)
5335 frvfdpic_gotfixup_section (info
)->flags
|= SEC_EXCLUDE
;
5336 else if (frvfdpic_gotfixup_section (info
)->contents
== NULL
)
5338 frvfdpic_gotfixup_section (info
)->contents
=
5339 (bfd_byte
*) bfd_zalloc (dynobj
,
5340 frvfdpic_gotfixup_section (info
)->size
);
5341 if (frvfdpic_gotfixup_section (info
)->contents
== NULL
)
5345 if (frvfdpic_pltrel_section (info
))
5347 frvfdpic_pltrel_section (info
)->size
=
5348 gpinfop
->g
.lzplt
/ 8
5349 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
5350 if (frvfdpic_pltrel_section (info
)->size
== 0)
5351 frvfdpic_pltrel_section (info
)->flags
|= SEC_EXCLUDE
;
5352 else if (frvfdpic_pltrel_section (info
)->contents
== NULL
)
5354 frvfdpic_pltrel_section (info
)->contents
=
5355 (bfd_byte
*) bfd_zalloc (dynobj
,
5356 frvfdpic_pltrel_section (info
)->size
);
5357 if (frvfdpic_pltrel_section (info
)->contents
== NULL
)
5362 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
5363 such that there's room for the additional instruction needed to
5364 call the resolver. Since _frvfdpic_assign_got_entries didn't
5365 account for them, our block size is 4 bytes smaller than the real
5367 if (frvfdpic_plt_section (info
))
5369 frvfdpic_plt_section (info
)->size
= gpinfop
->g
.lzplt
5370 + ((gpinfop
->g
.lzplt
+ (FRVFDPIC_LZPLT_BLOCK_SIZE
- 4) - 8)
5371 / (FRVFDPIC_LZPLT_BLOCK_SIZE
- 4) * 4);
5374 /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to
5375 actually assign lazy PLT entries addresses. */
5376 gpinfop
->g
.lzplt
= 0;
5378 /* Save information that we're going to need to generate GOT and PLT
5380 frvfdpic_got_initial_offset (info
) = -gpinfop
->gothilo
.tmin
;
5382 if (get_elf_backend_data (output_bfd
)->want_got_sym
)
5383 elf_hash_table (info
)->hgot
->root
.u
.def
.value
5384 = frvfdpic_got_initial_offset (info
);
5386 if (frvfdpic_plt_section (info
))
5387 frvfdpic_plt_initial_offset (info
) =
5388 frvfdpic_plt_section (info
)->size
;
5390 /* Allocate a ret statement at plt_initial_offset, to be used by
5391 locally-resolved TLS descriptors. */
5392 if (gpinfop
->g
.tls_ret_refs
)
5393 frvfdpic_plt_section (info
)->size
+= 4;
5395 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_assign_plt_entries
,
5398 /* Allocate the PLT section contents only after
5399 _frvfdpic_assign_plt_entries has a chance to add the size of the
5400 non-lazy PLT entries. */
5401 if (frvfdpic_plt_section (info
))
5403 if (frvfdpic_plt_section (info
)->size
== 0)
5404 frvfdpic_plt_section (info
)->flags
|= SEC_EXCLUDE
;
5405 else if (frvfdpic_plt_section (info
)->contents
== NULL
)
5407 frvfdpic_plt_section (info
)->contents
=
5408 (bfd_byte
*) bfd_zalloc (dynobj
,
5409 frvfdpic_plt_section (info
)->size
);
5410 if (frvfdpic_plt_section (info
)->contents
== NULL
)
5418 /* Set the sizes of the dynamic sections. */
5421 elf32_frvfdpic_size_dynamic_sections (bfd
*output_bfd
,
5422 struct bfd_link_info
*info
)
5426 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5428 dynobj
= elf_hash_table (info
)->dynobj
;
5429 BFD_ASSERT (dynobj
!= NULL
);
5431 if (elf_hash_table (info
)->dynamic_sections_created
)
5433 /* Set the contents of the .interp section to the interpreter. */
5434 if (bfd_link_executable (info
) && !info
->nointerp
)
5436 s
= bfd_get_linker_section (dynobj
, ".interp");
5437 BFD_ASSERT (s
!= NULL
);
5438 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5439 s
->contents
= (bfd_byte
*) ELF_DYNAMIC_INTERPRETER
;
5443 memset (&gpinfo
, 0, sizeof (gpinfo
));
5444 gpinfo
.g
.info
= info
;
5448 htab_t relocs
= frvfdpic_relocs_info (info
);
5450 htab_traverse (relocs
, _frvfdpic_resolve_final_relocs_info
, &relocs
);
5452 if (relocs
== frvfdpic_relocs_info (info
))
5456 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_count_got_plt_entries
,
5459 /* Allocate space to save the summary information, we're going to
5460 use it if we're doing relaxations. */
5461 frvfdpic_dynamic_got_plt_info (info
) = bfd_alloc (dynobj
, sizeof (gpinfo
.g
));
5463 if (!_frvfdpic_size_got_plt (output_bfd
, &gpinfo
))
5466 if (elf_hash_table (info
)->dynamic_sections_created
)
5468 if (frvfdpic_got_section (info
)->size
)
5469 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTGOT
, 0))
5472 if (frvfdpic_pltrel_section (info
)->size
)
5473 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
5474 || !_bfd_elf_add_dynamic_entry (info
, DT_PLTREL
, DT_REL
)
5475 || !_bfd_elf_add_dynamic_entry (info
, DT_JMPREL
, 0))
5478 if (frvfdpic_gotrel_section (info
)->size
)
5479 if (!_bfd_elf_add_dynamic_entry (info
, DT_REL
, 0)
5480 || !_bfd_elf_add_dynamic_entry (info
, DT_RELSZ
, 0)
5481 || !_bfd_elf_add_dynamic_entry (info
, DT_RELENT
,
5482 sizeof (Elf32_External_Rel
)))
5490 elf32_frvfdpic_always_size_sections (bfd
*output_bfd
,
5491 struct bfd_link_info
*info
)
5493 if (!bfd_link_relocatable (info
)
5494 && !bfd_elf_stack_segment_size (output_bfd
, info
,
5495 "__stacksize", DEFAULT_STACK_SIZE
))
5501 /* Check whether any of the relocations was optimized away, and
5502 subtract it from the relocation or fixup count. */
5504 _frvfdpic_check_discarded_relocs (bfd
*abfd
, asection
*sec
,
5505 struct bfd_link_info
*info
,
5507 bfd_boolean
*changed
)
5509 Elf_Internal_Shdr
*symtab_hdr
;
5510 struct elf_link_hash_entry
**sym_hashes
;
5511 Elf_Internal_Rela
*rel
, *erel
;
5513 if ((sec
->flags
& SEC_RELOC
) == 0
5514 || sec
->reloc_count
== 0)
5517 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5518 sym_hashes
= elf_sym_hashes (abfd
);
5520 rel
= elf_section_data (sec
)->relocs
;
5522 /* Now examine each relocation. */
5523 for (erel
= rel
+ sec
->reloc_count
; rel
< erel
; rel
++)
5525 struct elf_link_hash_entry
*h
;
5526 unsigned long r_symndx
;
5527 struct frvfdpic_relocs_info
*picrel
;
5528 struct _frvfdpic_dynamic_got_info
*dinfo
;
5530 if (ELF32_R_TYPE (rel
->r_info
) != R_FRV_32
5531 && ELF32_R_TYPE (rel
->r_info
) != R_FRV_FUNCDESC
)
5534 if (_bfd_elf_section_offset (sec
->output_section
->owner
,
5535 info
, sec
, rel
->r_offset
)
5539 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5540 if (r_symndx
< symtab_hdr
->sh_info
)
5544 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5545 while (h
->root
.type
== bfd_link_hash_indirect
5546 || h
->root
.type
== bfd_link_hash_warning
)
5547 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
5551 picrel
= frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info
),
5553 rel
->r_addend
, NO_INSERT
);
5555 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info (info
),
5557 rel
->r_addend
, NO_INSERT
);
5563 dinfo
= frvfdpic_dynamic_got_plt_info (info
);
5565 _frvfdpic_count_relocs_fixups (picrel
, dinfo
, TRUE
);
5566 if (ELF32_R_TYPE (rel
->r_info
) == R_FRV_32
)
5568 else /* we know (ELF32_R_TYPE (rel->r_info) == R_FRV_FUNCDESC) */
5570 _frvfdpic_count_relocs_fixups (picrel
, dinfo
, FALSE
);
5577 frvfdpic_elf_discard_info (bfd
*ibfd
,
5578 struct elf_reloc_cookie
*cookie ATTRIBUTE_UNUSED
,
5579 struct bfd_link_info
*info
)
5581 bfd_boolean changed
= FALSE
;
5585 /* Account for relaxation of .eh_frame section. */
5586 for (s
= ibfd
->sections
; s
; s
= s
->next
)
5587 if (s
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
5589 if (!_frvfdpic_check_discarded_relocs (ibfd
, s
, info
, &changed
))
5591 obfd
= s
->output_section
->owner
;
5596 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5598 memset (&gpinfo
, 0, sizeof (gpinfo
));
5599 memcpy (&gpinfo
.g
, frvfdpic_dynamic_got_plt_info (info
),
5602 /* Clear GOT and PLT assignments. */
5603 htab_traverse (frvfdpic_relocs_info (info
),
5604 _frvfdpic_reset_got_plt_entries
,
5607 if (!_frvfdpic_size_got_plt (obfd
, &gpinfo
))
5614 /* Look for opportunities to relax TLS relocations. We can assume
5615 we're linking the main executable or a static-tls library, since
5616 otherwise we wouldn't have got here. */
5619 _frvfdpic_relax_got_plt_entries (void **entryp
, void *dinfo_
)
5621 struct frvfdpic_relocs_info
*entry
= *entryp
;
5622 struct _frvfdpic_dynamic_got_info
*dinfo
= dinfo_
;
5624 _frvfdpic_relax_tls_entries (entry
, dinfo
, TRUE
);
5630 elf32_frvfdpic_relax_section (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
,
5631 struct bfd_link_info
*info
, bfd_boolean
*again
)
5633 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5635 if (bfd_link_relocatable (info
))
5636 (*info
->callbacks
->einfo
)
5637 (_("%P%F: --relax and -r may not be used together\n"));
5639 /* If we return early, we didn't change anything. */
5642 /* We'll do our thing when requested to relax the GOT section. */
5643 if (sec
!= frvfdpic_got_section (info
))
5646 /* We can only relax when linking the main executable or a library
5647 that can't be dlopened. */
5648 if (! bfd_link_executable (info
) && ! (info
->flags
& DF_STATIC_TLS
))
5651 /* If there isn't a TLS section for this binary, we can't do
5652 anything about its TLS relocations (it probably doesn't have
5654 if (elf_hash_table (info
)->tls_sec
== NULL
)
5657 memset (&gpinfo
, 0, sizeof (gpinfo
));
5658 memcpy (&gpinfo
.g
, frvfdpic_dynamic_got_plt_info (info
), sizeof (gpinfo
.g
));
5660 /* Now look for opportunities to relax, adjusting the GOT usage
5662 htab_traverse (frvfdpic_relocs_info (info
),
5663 _frvfdpic_relax_got_plt_entries
,
5666 /* If we changed anything, reset and re-assign GOT and PLT entries. */
5667 if (memcmp (frvfdpic_dynamic_got_plt_info (info
),
5668 &gpinfo
.g
, sizeof (gpinfo
.g
)) != 0)
5670 /* Clear GOT and PLT assignments. */
5671 htab_traverse (frvfdpic_relocs_info (info
),
5672 _frvfdpic_reset_got_plt_entries
,
5675 /* The owner of the TLS section is the output bfd. There should
5676 be a better way to get to it. */
5677 if (!_frvfdpic_size_got_plt (elf_hash_table (info
)->tls_sec
->owner
,
5681 /* Repeat until we don't make any further changes. We could fail to
5682 introduce changes in a round if, for example, the 12-bit range is
5683 full, but we later release some space by getting rid of TLS
5684 descriptors in it. We have to repeat the whole process because
5685 we might have changed the size of a section processed before this
5693 /* Fill in code and data in dynamic sections. */
5696 elf32_frv_finish_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5697 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
5699 /* Nothing to be done for non-FDPIC. */
5704 elf32_frvfdpic_finish_dynamic_sections (bfd
*output_bfd
,
5705 struct bfd_link_info
*info
)
5710 dynobj
= elf_hash_table (info
)->dynobj
;
5712 if (frvfdpic_dynamic_got_plt_info (info
))
5714 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
== 0);
5716 if (frvfdpic_got_section (info
))
5718 BFD_ASSERT (frvfdpic_gotrel_section (info
)->size
5719 == (frvfdpic_gotrel_section (info
)->reloc_count
5720 * sizeof (Elf32_External_Rel
)));
5722 if (frvfdpic_gotfixup_section (info
))
5724 struct elf_link_hash_entry
*hgot
= elf_hash_table (info
)->hgot
;
5725 bfd_vma got_value
= hgot
->root
.u
.def
.value
5726 + hgot
->root
.u
.def
.section
->output_section
->vma
5727 + hgot
->root
.u
.def
.section
->output_offset
;
5728 struct bfd_link_hash_entry
*hend
;
5730 _frvfdpic_add_rofixup (output_bfd
, frvfdpic_gotfixup_section (info
),
5733 if (frvfdpic_gotfixup_section (info
)->size
5734 != (frvfdpic_gotfixup_section (info
)->reloc_count
* 4))
5737 info
->callbacks
->einfo
5738 ("LINKER BUG: .rofixup section size mismatch\n");
5742 hend
= bfd_link_hash_lookup (info
->hash
, "__ROFIXUP_END__",
5743 FALSE
, FALSE
, TRUE
);
5745 && (hend
->type
== bfd_link_hash_defined
5746 || hend
->type
== bfd_link_hash_defweak
)
5747 && hend
->u
.def
.section
->output_section
!= NULL
)
5750 frvfdpic_gotfixup_section (info
)->output_section
->vma
5751 + frvfdpic_gotfixup_section (info
)->output_offset
5752 + frvfdpic_gotfixup_section (info
)->size
5753 - hend
->u
.def
.section
->output_section
->vma
5754 - hend
->u
.def
.section
->output_offset
;
5755 BFD_ASSERT (hend
->u
.def
.value
== value
);
5756 if (hend
->u
.def
.value
!= value
)
5761 if (frvfdpic_pltrel_section (info
))
5763 BFD_ASSERT (frvfdpic_pltrel_section (info
)->size
5764 == (frvfdpic_pltrel_section (info
)->reloc_count
5765 * sizeof (Elf32_External_Rel
)));
5769 if (elf_hash_table (info
)->dynamic_sections_created
)
5771 Elf32_External_Dyn
* dyncon
;
5772 Elf32_External_Dyn
* dynconend
;
5774 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
5776 BFD_ASSERT (sdyn
!= NULL
);
5778 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5779 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5781 for (; dyncon
< dynconend
; dyncon
++)
5783 Elf_Internal_Dyn dyn
;
5785 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5793 dyn
.d_un
.d_ptr
= frvfdpic_got_section (info
)->output_section
->vma
5794 + frvfdpic_got_section (info
)->output_offset
5795 + frvfdpic_got_initial_offset (info
);
5796 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5800 dyn
.d_un
.d_ptr
= frvfdpic_pltrel_section (info
)
5801 ->output_section
->vma
5802 + frvfdpic_pltrel_section (info
)->output_offset
;
5803 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5807 dyn
.d_un
.d_val
= frvfdpic_pltrel_section (info
)->size
;
5808 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5817 /* Adjust a symbol defined by a dynamic object and referenced by a
5821 elf32_frvfdpic_adjust_dynamic_symbol
5822 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5823 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
5827 dynobj
= elf_hash_table (info
)->dynobj
;
5829 /* Make sure we know what is going on here. */
5830 BFD_ASSERT (dynobj
!= NULL
5834 && !h
->def_regular
)));
5836 /* If this is a weak symbol, and there is a real definition, the
5837 processor independent code will have arranged for us to see the
5838 real definition first, and we can just use the same value. */
5839 if (h
->is_weakalias
)
5841 struct elf_link_hash_entry
*def
= weakdef (h
);
5842 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
5843 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
5844 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
5851 /* Perform any actions needed for dynamic symbols. */
5854 elf32_frvfdpic_finish_dynamic_symbol
5855 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5856 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5857 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
,
5858 Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
)
5863 /* Decide whether to attempt to turn absptr or lsda encodings in
5864 shared libraries into pcrel within the given input section. */
5867 frvfdpic_elf_use_relative_eh_frame
5868 (bfd
*input_bfd ATTRIBUTE_UNUSED
,
5869 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5870 asection
*eh_frame_section ATTRIBUTE_UNUSED
)
5872 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
5876 /* Adjust the contents of an eh_frame_hdr section before they're output. */
5879 frvfdpic_elf_encode_eh_address (bfd
*abfd
,
5880 struct bfd_link_info
*info
,
5881 asection
*osec
, bfd_vma offset
,
5882 asection
*loc_sec
, bfd_vma loc_offset
,
5885 struct elf_link_hash_entry
*h
;
5887 h
= elf_hash_table (info
)->hgot
;
5888 BFD_ASSERT (h
&& h
->root
.type
== bfd_link_hash_defined
);
5890 if (! h
|| (_frvfdpic_osec_to_segment (abfd
, osec
)
5891 == _frvfdpic_osec_to_segment (abfd
, loc_sec
->output_section
)))
5892 return _bfd_elf_encode_eh_address (abfd
, info
, osec
, offset
,
5893 loc_sec
, loc_offset
, encoded
);
5895 BFD_ASSERT (_frvfdpic_osec_to_segment (abfd
, osec
)
5896 == (_frvfdpic_osec_to_segment
5897 (abfd
, h
->root
.u
.def
.section
->output_section
)));
5899 *encoded
= osec
->vma
+ offset
5900 - (h
->root
.u
.def
.value
5901 + h
->root
.u
.def
.section
->output_section
->vma
5902 + h
->root
.u
.def
.section
->output_offset
);
5904 return DW_EH_PE_datarel
| DW_EH_PE_sdata4
;
5907 /* Look through the relocs for a section during the first phase.
5909 Besides handling virtual table relocs for gc, we have to deal with
5910 all sorts of PIC-related relocations. We describe below the
5911 general plan on how to handle such relocations, even though we only
5912 collect information at this point, storing them in hash tables for
5913 perusal of later passes.
5915 32 relocations are propagated to the linker output when creating
5916 position-independent output. LO16 and HI16 relocations are not
5917 supposed to be encountered in this case.
5919 LABEL16 should always be resolvable by the linker, since it's only
5922 LABEL24, on the other hand, is used by calls. If it turns out that
5923 the target of a call is a dynamic symbol, a PLT entry must be
5924 created for it, which triggers the creation of a private function
5925 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
5927 GPREL relocations require the referenced symbol to be in the same
5928 segment as _gp, but this can only be checked later.
5930 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
5931 exist. LABEL24 might as well, since it may require a PLT entry,
5932 that will require a got.
5934 Non-FUNCDESC GOT relocations require a GOT entry to be created
5935 regardless of whether the symbol is dynamic. However, since a
5936 global symbol that turns out to not be exported may have the same
5937 address of a non-dynamic symbol, we don't assign GOT entries at
5938 this point, such that we can share them in this case. A relocation
5939 for the GOT entry always has to be created, be it to offset a
5940 private symbol by the section load address, be it to get the symbol
5941 resolved dynamically.
5943 FUNCDESC GOT relocations require a GOT entry to be created, and
5944 handled as if a FUNCDESC relocation was applied to the GOT entry in
5947 FUNCDESC relocations referencing a symbol that turns out to NOT be
5948 dynamic cause a private function descriptor to be created. The
5949 FUNCDESC relocation then decays to a 32 relocation that points at
5950 the private descriptor. If the symbol is dynamic, the FUNCDESC
5951 relocation is propagated to the linker output, such that the
5952 dynamic linker creates the canonical descriptor, pointing to the
5953 dynamically-resolved definition of the function.
5955 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
5956 symbols that are assigned to the same segment as the GOT, but we
5957 can only check this later, after we know the complete set of
5958 symbols defined and/or exported.
5960 FUNCDESC GOTOFF relocations require a function descriptor to be
5961 created and, unless lazy binding is disabled or the symbol is not
5962 dynamic, a lazy PLT entry. Since we can't tell at this point
5963 whether a symbol is going to be dynamic, we have to decide later
5964 whether to create a lazy PLT entry or bind the descriptor directly
5965 to the private function.
5967 FUNCDESC_VALUE relocations are not supposed to be present in object
5968 files, but they may very well be simply propagated to the linker
5969 output, since they have no side effect.
5972 A function descriptor always requires a FUNCDESC_VALUE relocation.
5973 Whether it's in .plt.rel or not depends on whether lazy binding is
5974 enabled and on whether the referenced symbol is dynamic.
5976 The existence of a lazy PLT requires the resolverStub lazy PLT
5977 entry to be present.
5980 As for assignment of GOT, PLT and lazy PLT entries, and private
5981 descriptors, we might do them all sequentially, but we can do
5982 better than that. For example, we can place GOT entries and
5983 private function descriptors referenced using 12-bit operands
5984 closer to the PIC register value, such that these relocations don't
5985 overflow. Those that are only referenced with LO16 relocations
5986 could come next, but we may as well place PLT-required function
5987 descriptors in the 12-bit range to make them shorter. Symbols
5988 referenced with LO16/HI16 may come next, but we may place
5989 additional function descriptors in the 16-bit range if we can
5990 reliably tell that we've already placed entries that are ever
5991 referenced with only LO16. PLT entries are therefore generated as
5992 small as possible, while not introducing relocation overflows in
5993 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
5994 generated before or after PLT entries, but not intermingled with
5995 them, such that we can have more lazy PLT entries in range for a
5996 branch to the resolverStub. The resolverStub should be emitted at
5997 the most distant location from the first lazy PLT entry such that
5998 it's still in range for a branch, or closer, if there isn't a need
5999 for so many lazy PLT entries. Additional lazy PLT entries may be
6000 emitted after the resolverStub, as long as branches are still in
6001 range. If the branch goes out of range, longer lazy PLT entries
6004 We could further optimize PLT and lazy PLT entries by giving them
6005 priority in assignment to closer-to-gr17 locations depending on the
6006 number of occurrences of references to them (assuming a function
6007 that's called more often is more important for performance, so its
6008 PLT entry should be faster), or taking hints from the compiler.
6009 Given infinite time and money... :-) */
6012 elf32_frv_check_relocs (bfd
*abfd
,
6013 struct bfd_link_info
*info
,
6015 const Elf_Internal_Rela
*relocs
)
6017 Elf_Internal_Shdr
*symtab_hdr
;
6018 struct elf_link_hash_entry
**sym_hashes
;
6019 const Elf_Internal_Rela
*rel
;
6020 const Elf_Internal_Rela
*rel_end
;
6022 struct frvfdpic_relocs_info
*picrel
;
6024 if (bfd_link_relocatable (info
))
6027 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6028 sym_hashes
= elf_sym_hashes (abfd
);
6030 dynobj
= elf_hash_table (info
)->dynobj
;
6031 rel_end
= relocs
+ sec
->reloc_count
;
6032 for (rel
= relocs
; rel
< rel_end
; rel
++)
6034 struct elf_link_hash_entry
*h
;
6035 unsigned long r_symndx
;
6037 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6038 if (r_symndx
< symtab_hdr
->sh_info
)
6042 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6043 while (h
->root
.type
== bfd_link_hash_indirect
6044 || h
->root
.type
== bfd_link_hash_warning
)
6045 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6048 switch (ELF32_R_TYPE (rel
->r_info
))
6050 case R_FRV_GETTLSOFF
:
6051 case R_FRV_TLSDESC_VALUE
:
6052 case R_FRV_GOTTLSDESC12
:
6053 case R_FRV_GOTTLSDESCHI
:
6054 case R_FRV_GOTTLSDESCLO
:
6055 case R_FRV_GOTTLSOFF12
:
6056 case R_FRV_GOTTLSOFFHI
:
6057 case R_FRV_GOTTLSOFFLO
:
6062 case R_FRV_FUNCDESC_GOT12
:
6063 case R_FRV_FUNCDESC_GOTHI
:
6064 case R_FRV_FUNCDESC_GOTLO
:
6065 case R_FRV_GOTOFF12
:
6066 case R_FRV_GOTOFFHI
:
6067 case R_FRV_GOTOFFLO
:
6068 case R_FRV_FUNCDESC_GOTOFF12
:
6069 case R_FRV_FUNCDESC_GOTOFFHI
:
6070 case R_FRV_FUNCDESC_GOTOFFLO
:
6071 case R_FRV_FUNCDESC
:
6072 case R_FRV_FUNCDESC_VALUE
:
6073 case R_FRV_TLSMOFF12
:
6074 case R_FRV_TLSMOFFHI
:
6075 case R_FRV_TLSMOFFLO
:
6077 if (! IS_FDPIC (abfd
))
6081 case R_FRV_GPRELU12
:
6088 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6089 if (! _frv_create_got_section (abfd
, info
))
6092 if (! IS_FDPIC (abfd
))
6099 if (h
->dynindx
== -1)
6100 switch (ELF_ST_VISIBILITY (h
->other
))
6106 bfd_elf_link_record_dynamic_symbol (info
, h
);
6110 = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info
),
6112 rel
->r_addend
, INSERT
);
6115 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
6116 (info
), abfd
, r_symndx
,
6117 rel
->r_addend
, INSERT
);
6127 switch (ELF32_R_TYPE (rel
->r_info
))
6130 if (IS_FDPIC (abfd
))
6134 case R_FRV_FUNCDESC_VALUE
:
6135 picrel
->relocsfdv
++;
6136 if (bfd_section_flags (sec
) & SEC_ALLOC
)
6141 if (! IS_FDPIC (abfd
))
6145 if (bfd_section_flags (sec
) & SEC_ALLOC
)
6155 picrel
->gothilo
= 1;
6158 case R_FRV_FUNCDESC_GOT12
:
6159 picrel
->fdgot12
= 1;
6162 case R_FRV_FUNCDESC_GOTHI
:
6163 case R_FRV_FUNCDESC_GOTLO
:
6164 picrel
->fdgothilo
= 1;
6167 case R_FRV_GOTOFF12
:
6168 case R_FRV_GOTOFFHI
:
6169 case R_FRV_GOTOFFLO
:
6173 case R_FRV_FUNCDESC_GOTOFF12
:
6174 picrel
->fdgoff12
= 1;
6177 case R_FRV_FUNCDESC_GOTOFFHI
:
6178 case R_FRV_FUNCDESC_GOTOFFLO
:
6179 picrel
->fdgoffhilo
= 1;
6182 case R_FRV_FUNCDESC
:
6187 case R_FRV_GETTLSOFF
:
6191 case R_FRV_TLSDESC_VALUE
:
6192 picrel
->relocstlsd
++;
6195 case R_FRV_GOTTLSDESC12
:
6196 picrel
->tlsdesc12
= 1;
6199 case R_FRV_GOTTLSDESCHI
:
6200 case R_FRV_GOTTLSDESCLO
:
6201 picrel
->tlsdeschilo
= 1;
6204 case R_FRV_TLSMOFF12
:
6205 case R_FRV_TLSMOFFHI
:
6206 case R_FRV_TLSMOFFLO
:
6210 case R_FRV_GOTTLSOFF12
:
6211 picrel
->tlsoff12
= 1;
6212 info
->flags
|= DF_STATIC_TLS
;
6215 case R_FRV_GOTTLSOFFHI
:
6216 case R_FRV_GOTTLSOFFLO
:
6217 picrel
->tlsoffhilo
= 1;
6218 info
->flags
|= DF_STATIC_TLS
;
6222 picrel
->relocstlsoff
++;
6223 info
->flags
|= DF_STATIC_TLS
;
6226 /* This relocation describes the C++ object vtable hierarchy.
6227 Reconstruct it for later use during GC. */
6228 case R_FRV_GNU_VTINHERIT
:
6229 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6233 /* This relocation describes which C++ vtable entries are actually
6234 used. Record for later use during GC. */
6235 case R_FRV_GNU_VTENTRY
:
6236 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
6244 case R_FRV_GPRELU12
:
6248 case R_FRV_TLSDESC_RELAX
:
6249 case R_FRV_GETTLSOFF_RELAX
:
6250 case R_FRV_TLSOFF_RELAX
:
6255 /* xgettext:c-format */
6256 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
6257 abfd
, (unsigned int) ELF32_R_TYPE (rel
->r_info
));
6266 /* Return the machine subcode from the ELF e_flags header. */
6269 elf32_frv_machine (bfd
*abfd
)
6271 switch (elf_elfheader (abfd
)->e_flags
& EF_FRV_CPU_MASK
)
6274 case EF_FRV_CPU_FR550
: return bfd_mach_fr550
;
6275 case EF_FRV_CPU_FR500
: return bfd_mach_fr500
;
6276 case EF_FRV_CPU_FR450
: return bfd_mach_fr450
;
6277 case EF_FRV_CPU_FR405
: return bfd_mach_fr400
;
6278 case EF_FRV_CPU_FR400
: return bfd_mach_fr400
;
6279 case EF_FRV_CPU_FR300
: return bfd_mach_fr300
;
6280 case EF_FRV_CPU_SIMPLE
: return bfd_mach_frvsimple
;
6281 case EF_FRV_CPU_TOMCAT
: return bfd_mach_frvtomcat
;
6284 return bfd_mach_frv
;
6287 /* Set the right machine number for a FRV ELF file. */
6290 elf32_frv_object_p (bfd
*abfd
)
6292 bfd_default_set_arch_mach (abfd
, bfd_arch_frv
, elf32_frv_machine (abfd
));
6293 return (((elf_elfheader (abfd
)->e_flags
& EF_FRV_FDPIC
) != 0)
6294 == (IS_FDPIC (abfd
)));
6297 /* Function to set the ELF flag bits. */
6300 frv_elf_set_private_flags (bfd
*abfd
, flagword flags
)
6302 elf_elfheader (abfd
)->e_flags
= flags
;
6303 elf_flags_init (abfd
) = TRUE
;
6307 /* Return true if the architecture described by elf header flag
6308 EXTENSION is an extension of the architecture described by BASE. */
6311 frv_elf_arch_extension_p (flagword base
, flagword extension
)
6313 if (base
== extension
)
6316 /* CPU_GENERIC code can be merged with code for a specific
6317 architecture, in which case the result is marked as being
6318 for the specific architecture. Everything is therefore
6319 an extension of CPU_GENERIC. */
6320 if (base
== EF_FRV_CPU_GENERIC
)
6323 if (extension
== EF_FRV_CPU_FR450
)
6324 if (base
== EF_FRV_CPU_FR400
|| base
== EF_FRV_CPU_FR405
)
6327 if (extension
== EF_FRV_CPU_FR405
)
6328 if (base
== EF_FRV_CPU_FR400
)
6334 /* Merge backend specific data from an object file to the output
6335 object file when linking. */
6338 frv_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
6340 bfd
*obfd
= info
->output_bfd
;
6341 flagword old_flags
, old_partial
;
6342 flagword new_flags
, new_partial
;
6343 bfd_boolean error
= FALSE
;
6347 new_opt
[0] = old_opt
[0] = '\0';
6348 new_flags
= elf_elfheader (ibfd
)->e_flags
;
6349 old_flags
= elf_elfheader (obfd
)->e_flags
;
6351 if (new_flags
& EF_FRV_FDPIC
)
6352 new_flags
&= ~EF_FRV_PIC
;
6356 ("old_flags = 0x%.8x, new_flags = 0x%.8x, init = %s, filename = %s",
6357 old_flags
, new_flags
, elf_flags_init (obfd
) ? "yes" : "no",
6358 bfd_get_filename (ibfd
));
6361 if (!elf_flags_init (obfd
)) /* First call, no flags set. */
6363 elf_flags_init (obfd
) = TRUE
;
6364 old_flags
= new_flags
;
6367 else if (new_flags
== old_flags
) /* Compatible flags are ok. */
6370 else /* Possibly incompatible flags. */
6372 /* Warn if different # of gprs are used. Note, 0 means nothing is
6373 said about the size of gprs. */
6374 new_partial
= (new_flags
& EF_FRV_GPR_MASK
);
6375 old_partial
= (old_flags
& EF_FRV_GPR_MASK
);
6376 if (new_partial
== old_partial
)
6379 else if (new_partial
== 0)
6382 else if (old_partial
== 0)
6383 old_flags
|= new_partial
;
6387 switch (new_partial
)
6389 default: strcat (new_opt
, " -mgpr-??"); break;
6390 case EF_FRV_GPR_32
: strcat (new_opt
, " -mgpr-32"); break;
6391 case EF_FRV_GPR_64
: strcat (new_opt
, " -mgpr-64"); break;
6394 switch (old_partial
)
6396 default: strcat (old_opt
, " -mgpr-??"); break;
6397 case EF_FRV_GPR_32
: strcat (old_opt
, " -mgpr-32"); break;
6398 case EF_FRV_GPR_64
: strcat (old_opt
, " -mgpr-64"); break;
6402 /* Warn if different # of fprs are used. Note, 0 means nothing is
6403 said about the size of fprs. */
6404 new_partial
= (new_flags
& EF_FRV_FPR_MASK
);
6405 old_partial
= (old_flags
& EF_FRV_FPR_MASK
);
6406 if (new_partial
== old_partial
)
6409 else if (new_partial
== 0)
6412 else if (old_partial
== 0)
6413 old_flags
|= new_partial
;
6417 switch (new_partial
)
6419 default: strcat (new_opt
, " -mfpr-?"); break;
6420 case EF_FRV_FPR_32
: strcat (new_opt
, " -mfpr-32"); break;
6421 case EF_FRV_FPR_64
: strcat (new_opt
, " -mfpr-64"); break;
6422 case EF_FRV_FPR_NONE
: strcat (new_opt
, " -msoft-float"); break;
6425 switch (old_partial
)
6427 default: strcat (old_opt
, " -mfpr-?"); break;
6428 case EF_FRV_FPR_32
: strcat (old_opt
, " -mfpr-32"); break;
6429 case EF_FRV_FPR_64
: strcat (old_opt
, " -mfpr-64"); break;
6430 case EF_FRV_FPR_NONE
: strcat (old_opt
, " -msoft-float"); break;
6434 /* Warn if different dword support was used. Note, 0 means nothing is
6435 said about the dword support. */
6436 new_partial
= (new_flags
& EF_FRV_DWORD_MASK
);
6437 old_partial
= (old_flags
& EF_FRV_DWORD_MASK
);
6438 if (new_partial
== old_partial
)
6441 else if (new_partial
== 0)
6444 else if (old_partial
== 0)
6445 old_flags
|= new_partial
;
6449 switch (new_partial
)
6451 default: strcat (new_opt
, " -mdword-?"); break;
6452 case EF_FRV_DWORD_YES
: strcat (new_opt
, " -mdword"); break;
6453 case EF_FRV_DWORD_NO
: strcat (new_opt
, " -mno-dword"); break;
6456 switch (old_partial
)
6458 default: strcat (old_opt
, " -mdword-?"); break;
6459 case EF_FRV_DWORD_YES
: strcat (old_opt
, " -mdword"); break;
6460 case EF_FRV_DWORD_NO
: strcat (old_opt
, " -mno-dword"); break;
6464 /* Or in flags that accumulate (ie, if one module uses it, mark that the
6466 old_flags
|= new_flags
& (EF_FRV_DOUBLE
6469 | EF_FRV_NON_PIC_RELOCS
);
6471 /* If any module was compiled without -G0, clear the G0 bit. */
6472 old_flags
= ((old_flags
& ~ EF_FRV_G0
)
6473 | (old_flags
& new_flags
& EF_FRV_G0
));
6475 /* If any module was compiled without -mnopack, clear the mnopack bit. */
6476 old_flags
= ((old_flags
& ~ EF_FRV_NOPACK
)
6477 | (old_flags
& new_flags
& EF_FRV_NOPACK
));
6479 /* We don't have to do anything if the pic flags are the same, or the new
6480 module(s) were compiled with -mlibrary-pic. */
6481 new_partial
= (new_flags
& EF_FRV_PIC_FLAGS
);
6482 old_partial
= (old_flags
& EF_FRV_PIC_FLAGS
);
6483 if ((new_partial
== old_partial
) || ((new_partial
& EF_FRV_LIBPIC
) != 0))
6486 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
6487 flags if any from the new module. */
6488 else if ((old_partial
& EF_FRV_LIBPIC
) != 0)
6489 old_flags
= (old_flags
& ~ EF_FRV_PIC_FLAGS
) | new_partial
;
6491 /* If we have mixtures of -fpic and -fPIC, or in both bits. */
6492 else if (new_partial
!= 0 && old_partial
!= 0)
6493 old_flags
|= new_partial
;
6495 /* One module was compiled for pic and the other was not, see if we have
6496 had any relocations that are not pic-safe. */
6499 if ((old_flags
& EF_FRV_NON_PIC_RELOCS
) == 0)
6500 old_flags
|= new_partial
;
6503 old_flags
&= ~ EF_FRV_PIC_FLAGS
;
6504 #ifndef FRV_NO_PIC_ERROR
6507 /* xgettext:c-format */
6508 (_("%pB: compiled with %s and linked with modules"
6509 " that use non-pic relocations"),
6510 ibfd
, (new_flags
& EF_FRV_BIGPIC
) ? "-fPIC" : "-fpic");
6515 /* Warn if different cpu is used (allow a specific cpu to override
6516 the generic cpu). */
6517 new_partial
= (new_flags
& EF_FRV_CPU_MASK
);
6518 old_partial
= (old_flags
& EF_FRV_CPU_MASK
);
6519 if (frv_elf_arch_extension_p (new_partial
, old_partial
))
6522 else if (frv_elf_arch_extension_p (old_partial
, new_partial
))
6523 old_flags
= (old_flags
& ~EF_FRV_CPU_MASK
) | new_partial
;
6527 switch (new_partial
)
6529 default: strcat (new_opt
, " -mcpu=?"); break;
6530 case EF_FRV_CPU_GENERIC
: strcat (new_opt
, " -mcpu=frv"); break;
6531 case EF_FRV_CPU_SIMPLE
: strcat (new_opt
, " -mcpu=simple"); break;
6532 case EF_FRV_CPU_FR550
: strcat (new_opt
, " -mcpu=fr550"); break;
6533 case EF_FRV_CPU_FR500
: strcat (new_opt
, " -mcpu=fr500"); break;
6534 case EF_FRV_CPU_FR450
: strcat (new_opt
, " -mcpu=fr450"); break;
6535 case EF_FRV_CPU_FR405
: strcat (new_opt
, " -mcpu=fr405"); break;
6536 case EF_FRV_CPU_FR400
: strcat (new_opt
, " -mcpu=fr400"); break;
6537 case EF_FRV_CPU_FR300
: strcat (new_opt
, " -mcpu=fr300"); break;
6538 case EF_FRV_CPU_TOMCAT
: strcat (new_opt
, " -mcpu=tomcat"); break;
6541 switch (old_partial
)
6543 default: strcat (old_opt
, " -mcpu=?"); break;
6544 case EF_FRV_CPU_GENERIC
: strcat (old_opt
, " -mcpu=frv"); break;
6545 case EF_FRV_CPU_SIMPLE
: strcat (old_opt
, " -mcpu=simple"); break;
6546 case EF_FRV_CPU_FR550
: strcat (old_opt
, " -mcpu=fr550"); break;
6547 case EF_FRV_CPU_FR500
: strcat (old_opt
, " -mcpu=fr500"); break;
6548 case EF_FRV_CPU_FR450
: strcat (old_opt
, " -mcpu=fr450"); break;
6549 case EF_FRV_CPU_FR405
: strcat (old_opt
, " -mcpu=fr405"); break;
6550 case EF_FRV_CPU_FR400
: strcat (old_opt
, " -mcpu=fr400"); break;
6551 case EF_FRV_CPU_FR300
: strcat (old_opt
, " -mcpu=fr300"); break;
6552 case EF_FRV_CPU_TOMCAT
: strcat (old_opt
, " -mcpu=tomcat"); break;
6556 /* Print out any mismatches from above. */
6561 /* xgettext:c-format */
6562 (_("%pB: compiled with %s and linked with modules compiled with %s"),
6563 ibfd
, new_opt
, old_opt
);
6566 /* Warn about any other mismatches */
6567 new_partial
= (new_flags
& ~ EF_FRV_ALL_FLAGS
);
6568 old_partial
= (old_flags
& ~ EF_FRV_ALL_FLAGS
);
6569 if (new_partial
!= old_partial
)
6571 old_flags
|= new_partial
;
6574 /* xgettext:c-format */
6575 (_("%pB: uses different unknown e_flags (%#x) fields"
6576 " than previous modules (%#x)"),
6577 ibfd
, new_partial
, old_partial
);
6581 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
6582 if ((old_flags
& EF_FRV_CPU_MASK
) == EF_FRV_CPU_SIMPLE
)
6583 old_flags
|= EF_FRV_NOPACK
;
6585 /* Update the old flags now with changes made above. */
6586 old_partial
= elf_elfheader (obfd
)->e_flags
& EF_FRV_CPU_MASK
;
6587 elf_elfheader (obfd
)->e_flags
= old_flags
;
6588 if (old_partial
!= (old_flags
& EF_FRV_CPU_MASK
))
6589 bfd_default_set_arch_mach (obfd
, bfd_arch_frv
, elf32_frv_machine (obfd
));
6591 if (((new_flags
& EF_FRV_FDPIC
) == 0)
6592 != (! IS_FDPIC (ibfd
)))
6595 if (IS_FDPIC (obfd
))
6597 (_("%pB: cannot link non-fdpic object file into fdpic executable"),
6601 (_("%pB: cannot link fdpic object file into non-fdpic executable"),
6606 bfd_set_error (bfd_error_bad_value
);
6613 frv_elf_print_private_bfd_data (bfd
*abfd
, void * ptr
)
6615 FILE *file
= (FILE *) ptr
;
6618 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6620 /* Print normal ELF private data. */
6621 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6623 flags
= elf_elfheader (abfd
)->e_flags
;
6624 fprintf (file
, _("private flags = 0x%lx:"), (unsigned long) flags
);
6626 switch (flags
& EF_FRV_CPU_MASK
)
6629 case EF_FRV_CPU_SIMPLE
: fprintf (file
, " -mcpu=simple"); break;
6630 case EF_FRV_CPU_FR550
: fprintf (file
, " -mcpu=fr550"); break;
6631 case EF_FRV_CPU_FR500
: fprintf (file
, " -mcpu=fr500"); break;
6632 case EF_FRV_CPU_FR450
: fprintf (file
, " -mcpu=fr450"); break;
6633 case EF_FRV_CPU_FR405
: fprintf (file
, " -mcpu=fr405"); break;
6634 case EF_FRV_CPU_FR400
: fprintf (file
, " -mcpu=fr400"); break;
6635 case EF_FRV_CPU_FR300
: fprintf (file
, " -mcpu=fr300"); break;
6636 case EF_FRV_CPU_TOMCAT
: fprintf (file
, " -mcpu=tomcat"); break;
6639 switch (flags
& EF_FRV_GPR_MASK
)
6642 case EF_FRV_GPR_32
: fprintf (file
, " -mgpr-32"); break;
6643 case EF_FRV_GPR_64
: fprintf (file
, " -mgpr-64"); break;
6646 switch (flags
& EF_FRV_FPR_MASK
)
6649 case EF_FRV_FPR_32
: fprintf (file
, " -mfpr-32"); break;
6650 case EF_FRV_FPR_64
: fprintf (file
, " -mfpr-64"); break;
6651 case EF_FRV_FPR_NONE
: fprintf (file
, " -msoft-float"); break;
6654 switch (flags
& EF_FRV_DWORD_MASK
)
6657 case EF_FRV_DWORD_YES
: fprintf (file
, " -mdword"); break;
6658 case EF_FRV_DWORD_NO
: fprintf (file
, " -mno-dword"); break;
6661 if (flags
& EF_FRV_DOUBLE
)
6662 fprintf (file
, " -mdouble");
6664 if (flags
& EF_FRV_MEDIA
)
6665 fprintf (file
, " -mmedia");
6667 if (flags
& EF_FRV_MULADD
)
6668 fprintf (file
, " -mmuladd");
6670 if (flags
& EF_FRV_PIC
)
6671 fprintf (file
, " -fpic");
6673 if (flags
& EF_FRV_BIGPIC
)
6674 fprintf (file
, " -fPIC");
6676 if (flags
& EF_FRV_LIBPIC
)
6677 fprintf (file
, " -mlibrary-pic");
6679 if (flags
& EF_FRV_FDPIC
)
6680 fprintf (file
, " -mfdpic");
6682 if (flags
& EF_FRV_NON_PIC_RELOCS
)
6683 fprintf (file
, " non-pic relocations");
6685 if (flags
& EF_FRV_G0
)
6686 fprintf (file
, " -G0");
6693 /* Support for core dump NOTE sections. */
6696 elf32_frv_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
6699 unsigned int raw_size
;
6701 switch (note
->descsz
)
6706 /* The Linux/FRV elf_prstatus struct is 268 bytes long. The other
6707 hardcoded offsets and sizes listed below (and contained within
6708 this lexical block) refer to fields in the target's elf_prstatus
6711 /* `pr_cursig' is at offset 12. */
6712 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
6714 /* `pr_pid' is at offset 24. */
6715 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
6717 /* `pr_reg' is at offset 72. */
6720 /* Most grok_prstatus implementations set `raw_size' to the size
6721 of the pr_reg field. For Linux/FRV, we set `raw_size' to be
6722 the size of `pr_reg' plus the size of `pr_exec_fdpic_loadmap'
6723 and `pr_interp_fdpic_loadmap', both of which (by design)
6724 immediately follow `pr_reg'. This will allow these fields to
6725 be viewed by GDB as registers.
6727 `pr_reg' is 184 bytes long. `pr_exec_fdpic_loadmap' and
6728 `pr_interp_fdpic_loadmap' are 4 bytes each. */
6729 raw_size
= 184 + 4 + 4;
6734 /* Make a ".reg/999" section. */
6735 return _bfd_elfcore_make_pseudosection (abfd
, ".reg", raw_size
,
6736 note
->descpos
+ offset
);
6740 elf32_frv_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
6742 switch (note
->descsz
)
6747 /* The Linux/FRV elf_prpsinfo struct is 124 bytes long. */
6750 /* `pr_fname' is found at offset 28 and is 16 bytes long. */
6751 elf_tdata (abfd
)->core
->program
6752 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
6754 /* `pr_psargs' is found at offset 44 and is 80 bytes long. */
6755 elf_tdata (abfd
)->core
->command
6756 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
6759 /* Note that for some reason, a spurious space is tacked
6760 onto the end of the args in some (at least one anyway)
6761 implementations, so strip it off if it exists. */
6764 char *command
= elf_tdata (abfd
)->core
->command
;
6765 int n
= strlen (command
);
6767 if (0 < n
&& command
[n
- 1] == ' ')
6768 command
[n
- 1] = '\0';
6773 #define ELF_ARCH bfd_arch_frv
6774 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
6775 #define ELF_MAXPAGESIZE 0x1000
6777 #define TARGET_BIG_SYM frv_elf32_vec
6778 #define TARGET_BIG_NAME "elf32-frv"
6780 #define elf_info_to_howto frv_info_to_howto_rela
6781 #define elf_backend_relocate_section elf32_frv_relocate_section
6782 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
6783 #define elf_backend_check_relocs elf32_frv_check_relocs
6784 #define elf_backend_object_p elf32_frv_object_p
6785 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
6787 #define elf_backend_stack_align 8
6788 #define elf_backend_can_gc_sections 1
6789 #define elf_backend_rela_normal 1
6791 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
6792 #define bfd_elf32_bfd_reloc_name_lookup frv_reloc_name_lookup
6793 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
6794 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
6795 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
6797 #define elf_backend_want_got_sym 1
6798 #define elf_backend_got_header_size 0
6799 #define elf_backend_want_got_plt 0
6800 #define elf_backend_plt_readonly 1
6801 #define elf_backend_want_plt_sym 0
6802 #define elf_backend_plt_header_size 0
6804 #define elf_backend_finish_dynamic_sections \
6805 elf32_frv_finish_dynamic_sections
6807 #define elf_backend_grok_prstatus elf32_frv_grok_prstatus
6808 #define elf_backend_grok_psinfo elf32_frv_grok_psinfo
6810 #define elf_backend_linux_prpsinfo32_ugid16 TRUE
6812 #include "elf32-target.h"
6814 #undef ELF_TARGET_ID
6815 #define ELF_TARGET_ID FRV_ELF_DATA
6816 #undef ELF_MAXPAGESIZE
6817 #define ELF_MAXPAGESIZE 0x4000
6819 #undef TARGET_BIG_SYM
6820 #define TARGET_BIG_SYM frv_elf32_fdpic_vec
6821 #undef TARGET_BIG_NAME
6822 #define TARGET_BIG_NAME "elf32-frvfdpic"
6824 #define elf32_bed elf32_frvfdpic_bed
6826 #undef elf_info_to_howto_rel
6827 #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel
6829 #undef bfd_elf32_bfd_link_hash_table_create
6830 #define bfd_elf32_bfd_link_hash_table_create \
6831 frvfdpic_elf_link_hash_table_create
6832 #undef elf_backend_always_size_sections
6833 #define elf_backend_always_size_sections \
6834 elf32_frvfdpic_always_size_sections
6836 #undef elf_backend_create_dynamic_sections
6837 #define elf_backend_create_dynamic_sections \
6838 elf32_frvfdpic_create_dynamic_sections
6839 #undef elf_backend_adjust_dynamic_symbol
6840 #define elf_backend_adjust_dynamic_symbol \
6841 elf32_frvfdpic_adjust_dynamic_symbol
6842 #undef elf_backend_size_dynamic_sections
6843 #define elf_backend_size_dynamic_sections \
6844 elf32_frvfdpic_size_dynamic_sections
6845 #undef bfd_elf32_bfd_relax_section
6846 #define bfd_elf32_bfd_relax_section \
6847 elf32_frvfdpic_relax_section
6848 #undef elf_backend_finish_dynamic_symbol
6849 #define elf_backend_finish_dynamic_symbol \
6850 elf32_frvfdpic_finish_dynamic_symbol
6851 #undef elf_backend_finish_dynamic_sections
6852 #define elf_backend_finish_dynamic_sections \
6853 elf32_frvfdpic_finish_dynamic_sections
6855 #undef elf_backend_discard_info
6856 #define elf_backend_discard_info \
6857 frvfdpic_elf_discard_info
6858 #undef elf_backend_can_make_relative_eh_frame
6859 #define elf_backend_can_make_relative_eh_frame \
6860 frvfdpic_elf_use_relative_eh_frame
6861 #undef elf_backend_can_make_lsda_relative_eh_frame
6862 #define elf_backend_can_make_lsda_relative_eh_frame \
6863 frvfdpic_elf_use_relative_eh_frame
6864 #undef elf_backend_encode_eh_address
6865 #define elf_backend_encode_eh_address \
6866 frvfdpic_elf_encode_eh_address
6868 #undef elf_backend_may_use_rel_p
6869 #define elf_backend_may_use_rel_p 1
6870 #undef elf_backend_may_use_rela_p
6871 #define elf_backend_may_use_rela_p 1
6872 /* We use REL for dynamic relocations only. */
6873 #undef elf_backend_default_use_rela_p
6874 #define elf_backend_default_use_rela_p 1
6876 #undef elf_backend_omit_section_dynsym
6877 #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym
6879 #include "elf32-target.h"