1 /* FRV-specific support for 32-bit ELF.
2 Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
30 /* Forward declarations. */
33 static reloc_howto_type elf32_frv_howto_table
[] =
35 /* This reloc does nothing. */
36 HOWTO (R_FRV_NONE
, /* type */
38 2, /* size (0 = byte, 1 = short, 2 = long) */
40 FALSE
, /* pc_relative */
42 complain_overflow_bitfield
, /* 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 bfd_elf32_frvfdpic_vec
;
801 #define IS_FDPIC(bfd) ((bfd)->xvec == &bfd_elf32_frvfdpic_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 .got section. */
811 /* A pointer to the .rel.got section. */
813 /* A pointer to the .rofixup section. */
815 /* A pointer to the .plt section. */
817 /* A pointer to the .rel.plt section. */
819 /* GOT base offset. */
821 /* Location of the first non-lazy PLT entry, i.e., the number of
822 bytes taken by lazy PLT entries. If locally-bound TLS
823 descriptors require a ret instruction, it will be placed at this
826 /* A hash table holding information about which symbols were
827 referenced with which PIC-related relocations. */
828 struct htab
*relocs_info
;
829 /* Summary reloc information collected by
830 _frvfdpic_count_got_plt_entries. */
831 struct _frvfdpic_dynamic_got_info
*g
;
834 /* Get the FRV ELF linker hash table from a link_info structure. */
836 #define frvfdpic_hash_table(p) \
837 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
838 == FRV_ELF_DATA ? ((struct frvfdpic_elf_link_hash_table *) ((p)->hash)) : NULL)
840 #define frvfdpic_got_section(info) \
841 (frvfdpic_hash_table (info)->sgot)
842 #define frvfdpic_gotrel_section(info) \
843 (frvfdpic_hash_table (info)->sgotrel)
844 #define frvfdpic_gotfixup_section(info) \
845 (frvfdpic_hash_table (info)->sgotfixup)
846 #define frvfdpic_plt_section(info) \
847 (frvfdpic_hash_table (info)->splt)
848 #define frvfdpic_pltrel_section(info) \
849 (frvfdpic_hash_table (info)->spltrel)
850 #define frvfdpic_relocs_info(info) \
851 (frvfdpic_hash_table (info)->relocs_info)
852 #define frvfdpic_got_initial_offset(info) \
853 (frvfdpic_hash_table (info)->got0)
854 #define frvfdpic_plt_initial_offset(info) \
855 (frvfdpic_hash_table (info)->plt0)
856 #define frvfdpic_dynamic_got_plt_info(info) \
857 (frvfdpic_hash_table (info)->g)
859 /* Currently it's the same, but if some day we have a reason to change
860 it, we'd better be using a different macro.
862 FIXME: if there's any TLS PLT entry that uses local-exec or
863 initial-exec models, we could use the ret at the end of any of them
864 instead of adding one more. */
865 #define frvfdpic_plt_tls_ret_offset(info) \
866 (frvfdpic_plt_initial_offset (info))
868 /* The name of the dynamic interpreter. This is put in the .interp
871 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
873 #define DEFAULT_STACK_SIZE 0x20000
875 /* This structure is used to collect the number of entries present in
876 each addressable range of the got. */
877 struct _frvfdpic_dynamic_got_info
879 /* Several bits of information about the current link. */
880 struct bfd_link_info
*info
;
881 /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit
883 bfd_vma got12
, gotlos
, gothilo
;
884 /* Total GOT size needed for function descriptor entries within the 12-,
885 16- or 32-bit ranges. */
886 bfd_vma fd12
, fdlos
, fdhilo
;
887 /* Total GOT size needed by function descriptor entries referenced
888 in PLT entries, that would be profitable to place in offsets
889 close to the PIC register. */
891 /* Total PLT size needed by lazy PLT entries. */
893 /* Total GOT size needed for TLS descriptor entries within the 12-,
894 16- or 32-bit ranges. */
895 bfd_vma tlsd12
, tlsdlos
, tlsdhilo
;
896 /* Total GOT size needed by TLS descriptors referenced in PLT
897 entries, that would be profitable to place in offers close to the
900 /* Total PLT size needed by TLS lazy PLT entries. */
902 /* Number of relocations carried over from input object files. */
903 unsigned long relocs
;
904 /* Number of fixups introduced by relocations in input object files. */
905 unsigned long fixups
;
906 /* The number of fixups that reference the ret instruction added to
907 the PLT for locally-resolved TLS descriptors. */
908 unsigned long tls_ret_refs
;
911 /* This structure is used to assign offsets to got entries, function
912 descriptors, plt entries and lazy plt entries. */
914 struct _frvfdpic_dynamic_got_plt_info
916 /* Summary information collected with _frvfdpic_count_got_plt_entries. */
917 struct _frvfdpic_dynamic_got_info g
;
919 /* For each addressable range, we record a MAX (positive) and MIN
920 (negative) value. CUR is used to assign got entries, and it's
921 incremented from an initial positive value to MAX, then from MIN
922 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
923 assign function descriptors, and it's decreased from an initial
924 non-positive value to MIN, then from MAX down to CUR (unless CUR
925 wraps around first). All of MIN, MAX, CUR and FDCUR always point
926 to even words. ODD, if non-zero, indicates an odd word to be
927 used for the next got entry, otherwise CUR is used and
928 incremented by a pair of words, wrapping around when it reaches
929 MAX. FDCUR is decremented (and wrapped) before the next function
930 descriptor is chosen. FDPLT indicates the number of remaining
931 slots that can be used for function descriptors used only by PLT
934 TMAX, TMIN and TCUR are used to assign TLS descriptors. TCUR
935 starts as MAX, and grows up to TMAX, then wraps around to TMIN
936 and grows up to MIN. TLSDPLT indicates the number of remaining
937 slots that can be used for TLS descriptors used only by TLS PLT
939 struct _frvfdpic_dynamic_got_alloc_data
941 bfd_signed_vma max
, cur
, odd
, fdcur
, min
;
942 bfd_signed_vma tmax
, tcur
, tmin
;
943 bfd_vma fdplt
, tlsdplt
;
944 } got12
, gotlos
, gothilo
;
947 /* Create an FRV ELF linker hash table. */
949 static struct bfd_link_hash_table
*
950 frvfdpic_elf_link_hash_table_create (bfd
*abfd
)
952 struct frvfdpic_elf_link_hash_table
*ret
;
953 bfd_size_type amt
= sizeof (struct frvfdpic_elf_link_hash_table
);
955 ret
= bfd_zalloc (abfd
, amt
);
959 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
960 _bfd_elf_link_hash_newfunc
,
961 sizeof (struct elf_link_hash_entry
),
968 return &ret
->elf
.root
;
971 /* Decide whether a reference to a symbol can be resolved locally or
972 not. If the symbol is protected, we want the local address, but
973 its function descriptor must be assigned by the dynamic linker. */
974 #define FRVFDPIC_SYM_LOCAL(INFO, H) \
975 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
976 || ! elf_hash_table (INFO)->dynamic_sections_created)
977 #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \
978 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
980 /* This structure collects information on what kind of GOT, PLT or
981 function descriptors are required by relocations that reference a
983 struct frvfdpic_relocs_info
985 /* The index of the symbol, as stored in the relocation r_info, if
986 we have a local symbol; -1 otherwise. */
990 /* The input bfd in which the symbol is defined, if it's a local
993 /* If symndx == -1, the hash table entry corresponding to a global
994 symbol (even if it turns out to bind locally, in which case it
995 should ideally be replaced with section's symndx + addend). */
996 struct elf_link_hash_entry
*h
;
998 /* The addend of the relocation that references the symbol. */
1001 /* The fields above are used to identify an entry. The fields below
1002 contain information on how an entry is used and, later on, which
1003 locations it was assigned. */
1004 /* The following 3 fields record whether the symbol+addend above was
1005 ever referenced with a GOT relocation. The 12 suffix indicates a
1006 GOT12 relocation; los is used for GOTLO relocations that are not
1007 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
1012 /* Whether a FUNCDESC relocation references symbol+addend. */
1014 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
1016 unsigned fdgotlos
:1;
1017 unsigned fdgothilo
:1;
1018 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
1019 unsigned fdgoff12
:1;
1020 unsigned fdgofflos
:1;
1021 unsigned fdgoffhilo
:1;
1022 /* Whether a GETTLSOFF relocation references symbol+addend. */
1024 /* FIXME: we should probably add tlspltdesc, tlspltoff and
1025 tlspltimm, to tell what kind of TLS PLT entry we're generating.
1026 We might instead just pre-compute flags telling whether the
1027 object is suitable for local exec, initial exec or general
1028 dynamic addressing, and use that all over the place. We could
1029 also try to do a better job of merging TLSOFF and TLSDESC entries
1030 in main executables, but perhaps we can get rid of TLSDESC
1031 entirely in them instead. */
1032 /* Whether a GOTTLSDESC relocation references symbol+addend. */
1033 unsigned tlsdesc12
:1;
1034 unsigned tlsdesclos
:1;
1035 unsigned tlsdeschilo
:1;
1036 /* Whether a GOTTLSOFF relocation references symbol+addend. */
1037 unsigned tlsoff12
:1;
1038 unsigned tlsofflos
:1;
1039 unsigned tlsoffhilo
:1;
1040 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
1041 GOTOFFHI relocations. The addend doesn't really matter, since we
1042 envision that this will only be used to check whether the symbol
1043 is mapped to the same segment as the got. */
1045 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
1047 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
1050 /* Whether we need a PLT entry for a symbol. Should be implied by
1052 (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */
1054 /* Whether a function descriptor should be created in this link unit
1055 for symbol+addend. Should be implied by something like:
1056 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
1057 || ((fd || fdgot12 || fdgotlos || fdgothilo)
1058 && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */
1060 /* Whether a lazy PLT entry is needed for this symbol+addend.
1061 Should be implied by something like:
1062 (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)
1063 && ! (info->flags & DF_BIND_NOW)) */
1065 /* Whether we've already emitted GOT relocations and PLT entries as
1066 needed for this symbol. */
1069 /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and
1070 R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing
1072 unsigned relocs32
, relocsfd
, relocsfdv
, relocstlsd
, relocstlsoff
;
1074 /* The number of .rofixups entries and dynamic relocations allocated
1075 for this symbol, minus any that might have already been used. */
1076 unsigned fixups
, dynrelocs
;
1078 /* The offsets of the GOT entries assigned to symbol+addend, to the
1079 function descriptor's address, and to a function descriptor,
1080 respectively. Should be zero if unassigned. The offsets are
1081 counted from the value that will be assigned to the PIC register,
1082 not from the beginning of the .got section. */
1083 bfd_signed_vma got_entry
, fdgot_entry
, fd_entry
;
1084 /* The offsets of the PLT entries assigned to symbol+addend,
1085 non-lazy and lazy, respectively. If unassigned, should be
1087 bfd_vma plt_entry
, lzplt_entry
;
1088 /* The offsets of the GOT entries for TLS offset and TLS descriptor. */
1089 bfd_signed_vma tlsoff_entry
, tlsdesc_entry
;
1090 /* The offset of the TLS offset PLT entry. */
1091 bfd_vma tlsplt_entry
;
1094 /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */
1096 frvfdpic_relocs_info_hash (const void *entry_
)
1098 const struct frvfdpic_relocs_info
*entry
= entry_
;
1100 return (entry
->symndx
== -1
1101 ? (long) entry
->d
.h
->root
.root
.hash
1102 : entry
->symndx
+ (long) entry
->d
.abfd
->id
* 257) + entry
->addend
;
1105 /* Test whether the key fields of two frvfdpic_relocs_info entries are
1108 frvfdpic_relocs_info_eq (const void *entry1
, const void *entry2
)
1110 const struct frvfdpic_relocs_info
*e1
= entry1
;
1111 const struct frvfdpic_relocs_info
*e2
= entry2
;
1113 return e1
->symndx
== e2
->symndx
&& e1
->addend
== e2
->addend
1114 && (e1
->symndx
== -1 ? e1
->d
.h
== e2
->d
.h
: e1
->d
.abfd
== e2
->d
.abfd
);
1117 /* Find or create an entry in a hash table HT that matches the key
1118 fields of the given ENTRY. If it's not found, memory for a new
1119 entry is allocated in ABFD's obstack. */
1120 static struct frvfdpic_relocs_info
*
1121 frvfdpic_relocs_info_find (struct htab
*ht
,
1123 const struct frvfdpic_relocs_info
*entry
,
1124 enum insert_option insert
)
1126 struct frvfdpic_relocs_info
**loc
=
1127 (struct frvfdpic_relocs_info
**) htab_find_slot (ht
, entry
, insert
);
1135 *loc
= bfd_zalloc (abfd
, sizeof (**loc
));
1140 (*loc
)->symndx
= entry
->symndx
;
1141 (*loc
)->d
= entry
->d
;
1142 (*loc
)->addend
= entry
->addend
;
1143 (*loc
)->plt_entry
= (bfd_vma
)-1;
1144 (*loc
)->lzplt_entry
= (bfd_vma
)-1;
1145 (*loc
)->tlsplt_entry
= (bfd_vma
)-1;
1150 /* Obtain the address of the entry in HT associated with H's symbol +
1151 addend, creating a new entry if none existed. ABFD is only used
1152 for memory allocation purposes. */
1153 inline static struct frvfdpic_relocs_info
*
1154 frvfdpic_relocs_info_for_global (struct htab
*ht
,
1156 struct elf_link_hash_entry
*h
,
1158 enum insert_option insert
)
1160 struct frvfdpic_relocs_info entry
;
1164 entry
.addend
= addend
;
1166 return frvfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1169 /* Obtain the address of the entry in HT associated with the SYMNDXth
1170 local symbol of the input bfd ABFD, plus the addend, creating a new
1171 entry if none existed. */
1172 inline static struct frvfdpic_relocs_info
*
1173 frvfdpic_relocs_info_for_local (struct htab
*ht
,
1177 enum insert_option insert
)
1179 struct frvfdpic_relocs_info entry
;
1181 entry
.symndx
= symndx
;
1182 entry
.d
.abfd
= abfd
;
1183 entry
.addend
= addend
;
1185 return frvfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1188 /* Merge fields set by check_relocs() of two entries that end up being
1189 mapped to the same (presumably global) symbol. */
1192 frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info
*e2
,
1193 struct frvfdpic_relocs_info
const *e1
)
1195 e2
->got12
|= e1
->got12
;
1196 e2
->gotlos
|= e1
->gotlos
;
1197 e2
->gothilo
|= e1
->gothilo
;
1199 e2
->fdgot12
|= e1
->fdgot12
;
1200 e2
->fdgotlos
|= e1
->fdgotlos
;
1201 e2
->fdgothilo
|= e1
->fdgothilo
;
1202 e2
->fdgoff12
|= e1
->fdgoff12
;
1203 e2
->fdgofflos
|= e1
->fdgofflos
;
1204 e2
->fdgoffhilo
|= e1
->fdgoffhilo
;
1205 e2
->tlsplt
|= e1
->tlsplt
;
1206 e2
->tlsdesc12
|= e1
->tlsdesc12
;
1207 e2
->tlsdesclos
|= e1
->tlsdesclos
;
1208 e2
->tlsdeschilo
|= e1
->tlsdeschilo
;
1209 e2
->tlsoff12
|= e1
->tlsoff12
;
1210 e2
->tlsofflos
|= e1
->tlsofflos
;
1211 e2
->tlsoffhilo
|= e1
->tlsoffhilo
;
1212 e2
->gotoff
|= e1
->gotoff
;
1213 e2
->call
|= e1
->call
;
1217 /* Every block of 65535 lazy PLT entries shares a single call to the
1218 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
1219 32767, counting from 0). All other lazy PLT entries branch to it
1220 in a single instruction. */
1222 #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
1223 #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767)
1225 /* Add a dynamic relocation to the SRELOC section. */
1227 inline static bfd_vma
1228 _frvfdpic_add_dyn_reloc (bfd
*output_bfd
, asection
*sreloc
, bfd_vma offset
,
1229 int reloc_type
, long dynindx
, bfd_vma addend
,
1230 struct frvfdpic_relocs_info
*entry
)
1232 Elf_Internal_Rela outrel
;
1233 bfd_vma reloc_offset
;
1235 outrel
.r_offset
= offset
;
1236 outrel
.r_info
= ELF32_R_INFO (dynindx
, reloc_type
);
1237 outrel
.r_addend
= addend
;
1239 reloc_offset
= sreloc
->reloc_count
* sizeof (Elf32_External_Rel
);
1240 BFD_ASSERT (reloc_offset
< sreloc
->size
);
1241 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
1242 sreloc
->contents
+ reloc_offset
);
1243 sreloc
->reloc_count
++;
1245 /* If the entry's index is zero, this relocation was probably to a
1246 linkonce section that got discarded. We reserved a dynamic
1247 relocation, but it was for another entry than the one we got at
1248 the time of emitting the relocation. Unfortunately there's no
1249 simple way for us to catch this situation, since the relocation
1250 is cleared right before calling relocate_section, at which point
1251 we no longer know what the relocation used to point to. */
1254 BFD_ASSERT (entry
->dynrelocs
> 0);
1258 return reloc_offset
;
1261 /* Add a fixup to the ROFIXUP section. */
1264 _frvfdpic_add_rofixup (bfd
*output_bfd
, asection
*rofixup
, bfd_vma offset
,
1265 struct frvfdpic_relocs_info
*entry
)
1267 bfd_vma fixup_offset
;
1269 if (rofixup
->flags
& SEC_EXCLUDE
)
1272 fixup_offset
= rofixup
->reloc_count
* 4;
1273 if (rofixup
->contents
)
1275 BFD_ASSERT (fixup_offset
< rofixup
->size
);
1276 bfd_put_32 (output_bfd
, offset
, rofixup
->contents
+ fixup_offset
);
1278 rofixup
->reloc_count
++;
1280 if (entry
&& entry
->symndx
)
1282 /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc
1284 BFD_ASSERT (entry
->fixups
> 0);
1288 return fixup_offset
;
1291 /* Find the segment number in which OSEC, and output section, is
1295 _frvfdpic_osec_to_segment (bfd
*output_bfd
, asection
*osec
)
1297 Elf_Internal_Phdr
*p
= _bfd_elf_find_segment_containing_section (output_bfd
, osec
);
1299 return (p
!= NULL
) ? p
- elf_tdata (output_bfd
)->phdr
: -1;
1302 inline static bfd_boolean
1303 _frvfdpic_osec_readonly_p (bfd
*output_bfd
, asection
*osec
)
1305 unsigned seg
= _frvfdpic_osec_to_segment (output_bfd
, osec
);
1307 return ! (elf_tdata (output_bfd
)->phdr
[seg
].p_flags
& PF_W
);
1310 #define FRVFDPIC_TLS_BIAS (2048 - 16)
1312 /* Return the base VMA address which should be subtracted from real addresses
1313 when resolving TLSMOFF relocation.
1314 This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */
1317 tls_biased_base (struct bfd_link_info
*info
)
1319 /* If tls_sec is NULL, we should have signalled an error already. */
1320 if (elf_hash_table (info
)->tls_sec
== NULL
)
1321 return FRVFDPIC_TLS_BIAS
;
1322 return elf_hash_table (info
)->tls_sec
->vma
+ FRVFDPIC_TLS_BIAS
;
1325 /* Generate relocations for GOT entries, function descriptors, and
1326 code for PLT and lazy PLT entries. */
1328 inline static bfd_boolean
1329 _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info
*entry
,
1331 struct bfd_link_info
*info
,
1333 Elf_Internal_Sym
*sym
,
1337 bfd_vma fd_lazy_rel_offset
= (bfd_vma
)-1;
1344 if (entry
->got_entry
|| entry
->fdgot_entry
|| entry
->fd_entry
1345 || entry
->tlsoff_entry
|| entry
->tlsdesc_entry
)
1347 /* If the symbol is dynamic, consider it for dynamic
1348 relocations, otherwise decay to section + offset. */
1349 if (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1)
1350 dynindx
= entry
->d
.h
->dynindx
;
1354 && sec
->output_section
1355 && ! bfd_is_abs_section (sec
->output_section
)
1356 && ! bfd_is_und_section (sec
->output_section
))
1357 dynindx
= elf_section_data (sec
->output_section
)->dynindx
;
1363 /* Generate relocation for GOT entry pointing to the symbol. */
1364 if (entry
->got_entry
)
1367 bfd_vma ad
= addend
;
1369 /* If the symbol is dynamic but binds locally, use
1371 if (sec
&& (entry
->symndx
!= -1
1372 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1374 if (entry
->symndx
== -1)
1375 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1377 ad
+= sym
->st_value
;
1378 ad
+= sec
->output_offset
;
1379 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1380 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1385 /* If we're linking an executable at a fixed address, we can
1386 omit the dynamic relocation as long as the symbol is local to
1388 if (info
->executable
&& !info
->pie
1389 && (entry
->symndx
!= -1
1390 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1393 ad
+= sec
->output_section
->vma
;
1394 if (entry
->symndx
!= -1
1395 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1396 _frvfdpic_add_rofixup (output_bfd
,
1397 frvfdpic_gotfixup_section (info
),
1398 frvfdpic_got_section (info
)->output_section
1400 + frvfdpic_got_section (info
)->output_offset
1401 + frvfdpic_got_initial_offset (info
)
1402 + entry
->got_entry
, entry
);
1405 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1406 _bfd_elf_section_offset
1408 frvfdpic_got_section (info
),
1409 frvfdpic_got_initial_offset (info
)
1411 + frvfdpic_got_section (info
)
1412 ->output_section
->vma
1413 + frvfdpic_got_section (info
)->output_offset
,
1414 R_FRV_32
, idx
, ad
, entry
);
1416 bfd_put_32 (output_bfd
, ad
,
1417 frvfdpic_got_section (info
)->contents
1418 + frvfdpic_got_initial_offset (info
)
1419 + entry
->got_entry
);
1422 /* Generate relocation for GOT entry pointing to a canonical
1423 function descriptor. */
1424 if (entry
->fdgot_entry
)
1429 if (! (entry
->symndx
== -1
1430 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
1431 && FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1433 /* If the symbol is dynamic and there may be dynamic symbol
1434 resolution because we are, or are linked with, a shared
1435 library, emit a FUNCDESC relocation such that the dynamic
1436 linker will allocate the function descriptor. If the
1437 symbol needs a non-local function descriptor but binds
1438 locally (e.g., its visibility is protected, emit a
1439 dynamic relocation decayed to section+offset. */
1440 if (entry
->symndx
== -1
1441 && ! FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)
1442 && FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)
1443 && !(info
->executable
&& !info
->pie
))
1445 reloc
= R_FRV_FUNCDESC
;
1446 idx
= elf_section_data (entry
->d
.h
->root
.u
.def
.section
1447 ->output_section
)->dynindx
;
1448 ad
= entry
->d
.h
->root
.u
.def
.section
->output_offset
1449 + entry
->d
.h
->root
.u
.def
.value
;
1451 else if (entry
->symndx
== -1
1452 && ! FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
))
1454 reloc
= R_FRV_FUNCDESC
;
1459 (*info
->callbacks
->reloc_dangerous
)
1460 (info
, _("relocation requires zero addend"),
1461 elf_hash_table (info
)->dynobj
,
1462 frvfdpic_got_section (info
),
1463 entry
->fdgot_entry
);
1469 /* Otherwise, we know we have a private function descriptor,
1470 so reference it directly. */
1471 if (elf_hash_table (info
)->dynamic_sections_created
)
1472 BFD_ASSERT (entry
->privfd
);
1474 idx
= elf_section_data (frvfdpic_got_section (info
)
1475 ->output_section
)->dynindx
;
1476 ad
= frvfdpic_got_section (info
)->output_offset
1477 + frvfdpic_got_initial_offset (info
) + entry
->fd_entry
;
1480 /* If there is room for dynamic symbol resolution, emit the
1481 dynamic relocation. However, if we're linking an
1482 executable at a fixed location, we won't have emitted a
1483 dynamic symbol entry for the got section, so idx will be
1484 zero, which means we can and should compute the address
1485 of the private descriptor ourselves. */
1486 if (info
->executable
&& !info
->pie
1487 && (entry
->symndx
!= -1
1488 || FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)))
1490 ad
+= frvfdpic_got_section (info
)->output_section
->vma
;
1491 _frvfdpic_add_rofixup (output_bfd
,
1492 frvfdpic_gotfixup_section (info
),
1493 frvfdpic_got_section (info
)
1494 ->output_section
->vma
1495 + frvfdpic_got_section (info
)
1497 + frvfdpic_got_initial_offset (info
)
1498 + entry
->fdgot_entry
, entry
);
1501 _frvfdpic_add_dyn_reloc (output_bfd
,
1502 frvfdpic_gotrel_section (info
),
1503 _bfd_elf_section_offset
1505 frvfdpic_got_section (info
),
1506 frvfdpic_got_initial_offset (info
)
1507 + entry
->fdgot_entry
)
1508 + frvfdpic_got_section (info
)
1509 ->output_section
->vma
1510 + frvfdpic_got_section (info
)
1512 reloc
, idx
, ad
, entry
);
1515 bfd_put_32 (output_bfd
, ad
,
1516 frvfdpic_got_section (info
)->contents
1517 + frvfdpic_got_initial_offset (info
)
1518 + entry
->fdgot_entry
);
1521 /* Generate relocation to fill in a private function descriptor in
1523 if (entry
->fd_entry
)
1526 bfd_vma ad
= addend
;
1528 long lowword
, highword
;
1530 /* If the symbol is dynamic but binds locally, use
1532 if (sec
&& (entry
->symndx
!= -1
1533 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1535 if (entry
->symndx
== -1)
1536 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1538 ad
+= sym
->st_value
;
1539 ad
+= sec
->output_offset
;
1540 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1541 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1546 /* If we're linking an executable at a fixed address, we can
1547 omit the dynamic relocation as long as the symbol is local to
1549 if (info
->executable
&& !info
->pie
1550 && (entry
->symndx
!= -1 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1553 ad
+= sec
->output_section
->vma
;
1555 if (entry
->symndx
!= -1
1556 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
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
, entry
);
1566 _frvfdpic_add_rofixup (output_bfd
,
1567 frvfdpic_gotfixup_section (info
),
1568 frvfdpic_got_section (info
)
1569 ->output_section
->vma
1570 + frvfdpic_got_section (info
)
1572 + frvfdpic_got_initial_offset (info
)
1573 + entry
->fd_entry
+ 4, entry
);
1579 _frvfdpic_add_dyn_reloc (output_bfd
,
1581 ? frvfdpic_pltrel_section (info
)
1582 : frvfdpic_gotrel_section (info
),
1583 _bfd_elf_section_offset
1585 frvfdpic_got_section (info
),
1586 frvfdpic_got_initial_offset (info
)
1588 + frvfdpic_got_section (info
)
1589 ->output_section
->vma
1590 + frvfdpic_got_section (info
)
1592 R_FRV_FUNCDESC_VALUE
, idx
, ad
, entry
);
1595 /* If we've omitted the dynamic relocation, just emit the fixed
1596 addresses of the symbol and of the local GOT base offset. */
1597 if (info
->executable
&& !info
->pie
&& sec
&& sec
->output_section
)
1600 highword
= frvfdpic_got_section (info
)->output_section
->vma
1601 + frvfdpic_got_section (info
)->output_offset
1602 + frvfdpic_got_initial_offset (info
);
1604 else if (entry
->lazyplt
)
1608 (*info
->callbacks
->reloc_dangerous
)
1609 (info
, _("relocation requires zero addend"),
1610 elf_hash_table (info
)->dynobj
,
1611 frvfdpic_got_section (info
),
1616 fd_lazy_rel_offset
= ofst
;
1618 /* A function descriptor used for lazy or local resolving is
1619 initialized such that its high word contains the output
1620 section index in which the PLT entries are located, and
1621 the low word contains the address of the lazy PLT entry
1622 entry point, that must be within the memory region
1623 assigned to that section. */
1624 lowword
= entry
->lzplt_entry
+ 4
1625 + frvfdpic_plt_section (info
)->output_offset
1626 + frvfdpic_plt_section (info
)->output_section
->vma
;
1627 highword
= _frvfdpic_osec_to_segment
1628 (output_bfd
, frvfdpic_plt_section (info
)->output_section
);
1632 /* A function descriptor for a local function gets the index
1633 of the section. For a non-local function, it's
1637 || (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1
1638 && entry
->d
.h
->dynindx
== idx
))
1641 highword
= _frvfdpic_osec_to_segment
1642 (output_bfd
, sec
->output_section
);
1645 bfd_put_32 (output_bfd
, lowword
,
1646 frvfdpic_got_section (info
)->contents
1647 + frvfdpic_got_initial_offset (info
)
1649 bfd_put_32 (output_bfd
, highword
,
1650 frvfdpic_got_section (info
)->contents
1651 + frvfdpic_got_initial_offset (info
)
1652 + entry
->fd_entry
+ 4);
1655 /* Generate code for the PLT entry. */
1656 if (entry
->plt_entry
!= (bfd_vma
) -1)
1658 bfd_byte
*plt_code
= frvfdpic_plt_section (info
)->contents
1661 BFD_ASSERT (entry
->fd_entry
);
1663 /* Figure out what kind of PLT entry we need, depending on the
1664 location of the function descriptor within the GOT. */
1665 if (entry
->fd_entry
>= -(1 << (12 - 1))
1666 && entry
->fd_entry
< (1 << (12 - 1)))
1668 /* lddi @(gr15, fd_entry), gr14 */
1669 bfd_put_32 (output_bfd
,
1670 0x9cccf000 | (entry
->fd_entry
& ((1 << 12) - 1)),
1676 if (entry
->fd_entry
>= -(1 << (16 - 1))
1677 && entry
->fd_entry
< (1 << (16 - 1)))
1679 /* setlos lo(fd_entry), gr14 */
1680 bfd_put_32 (output_bfd
,
1682 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1688 /* sethi.p hi(fd_entry), gr14
1689 setlo lo(fd_entry), gr14 */
1690 bfd_put_32 (output_bfd
,
1692 | ((entry
->fd_entry
>> 16)
1693 & (((bfd_vma
)1 << 16) - 1)),
1696 bfd_put_32 (output_bfd
,
1698 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1702 /* ldd @(gr14,gr15),gr14 */
1703 bfd_put_32 (output_bfd
, 0x9c08e14f, plt_code
);
1706 /* jmpl @(gr14,gr0) */
1707 bfd_put_32 (output_bfd
, 0x8030e000, plt_code
);
1710 /* Generate code for the lazy PLT entry. */
1711 if (entry
->lzplt_entry
!= (bfd_vma
) -1)
1713 bfd_byte
*lzplt_code
= frvfdpic_plt_section (info
)->contents
1714 + entry
->lzplt_entry
;
1715 bfd_vma resolverStub_addr
;
1717 bfd_put_32 (output_bfd
, fd_lazy_rel_offset
, lzplt_code
);
1720 resolverStub_addr
= entry
->lzplt_entry
/ FRVFDPIC_LZPLT_BLOCK_SIZE
1721 * FRVFDPIC_LZPLT_BLOCK_SIZE
+ FRVFDPIC_LZPLT_RESOLV_LOC
;
1722 if (resolverStub_addr
>= frvfdpic_plt_initial_offset (info
))
1723 resolverStub_addr
= frvfdpic_plt_initial_offset (info
) - 12;
1725 if (entry
->lzplt_entry
== resolverStub_addr
)
1727 /* This is a lazy PLT entry that includes a resolver call. */
1728 /* ldd @(gr15,gr0), gr4
1730 bfd_put_32 (output_bfd
, 0x8808f140, lzplt_code
);
1731 bfd_put_32 (output_bfd
, 0x80304000, lzplt_code
+ 4);
1735 /* bra resolverStub */
1736 bfd_put_32 (output_bfd
,
1738 | (((resolverStub_addr
- entry
->lzplt_entry
)
1739 / 4) & (((bfd_vma
)1 << 16) - 1)),
1744 /* Generate relocation for GOT entry holding the TLS offset. */
1745 if (entry
->tlsoff_entry
)
1748 bfd_vma ad
= addend
;
1750 if (entry
->symndx
!= -1
1751 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
))
1753 /* If the symbol is dynamic but binds locally, use
1757 if (entry
->symndx
== -1)
1758 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1760 ad
+= sym
->st_value
;
1761 ad
+= sec
->output_offset
;
1762 if (sec
->output_section
1763 && elf_section_data (sec
->output_section
))
1764 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1770 /* *ABS*+addend is special for TLS relocations, use only the
1772 if (info
->executable
1774 && (bfd_is_abs_section (sec
)
1775 || bfd_is_und_section (sec
)))
1777 /* If we're linking an executable, we can entirely omit the
1778 dynamic relocation if the symbol is local to this module. */
1779 else if (info
->executable
1780 && (entry
->symndx
!= -1
1781 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1784 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1789 && (bfd_is_abs_section (sec
)
1790 || bfd_is_und_section (sec
)))
1792 if (! elf_hash_table (info
)->tls_sec
)
1794 (*info
->callbacks
->undefined_symbol
)
1795 (info
, "TLS section", elf_hash_table (info
)->dynobj
,
1796 frvfdpic_got_section (info
), entry
->tlsoff_entry
, TRUE
);
1799 idx
= elf_section_data (elf_hash_table (info
)->tls_sec
)->dynindx
;
1800 ad
+= FRVFDPIC_TLS_BIAS
;
1802 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1803 _bfd_elf_section_offset
1805 frvfdpic_got_section (info
),
1806 frvfdpic_got_initial_offset (info
)
1807 + entry
->tlsoff_entry
)
1808 + frvfdpic_got_section (info
)
1809 ->output_section
->vma
1810 + frvfdpic_got_section (info
)
1812 R_FRV_TLSOFF
, idx
, ad
, entry
);
1815 bfd_put_32 (output_bfd
, ad
,
1816 frvfdpic_got_section (info
)->contents
1817 + frvfdpic_got_initial_offset (info
)
1818 + entry
->tlsoff_entry
);
1821 if (entry
->tlsdesc_entry
)
1824 bfd_vma ad
= addend
;
1826 /* If the symbol is dynamic but binds locally, use
1828 if (sec
&& (entry
->symndx
!= -1
1829 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1831 if (entry
->symndx
== -1)
1832 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1834 ad
+= sym
->st_value
;
1835 ad
+= sec
->output_offset
;
1836 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1837 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1842 /* If we didn't set up a TLS offset entry, but we're linking an
1843 executable and the symbol binds locally, we can use the
1844 module offset in the TLS descriptor in relaxations. */
1845 if (info
->executable
&& ! entry
->tlsoff_entry
)
1846 entry
->tlsoff_entry
= entry
->tlsdesc_entry
+ 4;
1848 if (info
->executable
&& !info
->pie
1850 && (bfd_is_abs_section (sec
)
1851 || bfd_is_und_section (sec
)))
1852 || entry
->symndx
!= -1
1853 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1855 /* *ABS*+addend is special for TLS relocations, use only the
1856 addend for the TLS offset, and take the module id as
1859 && (bfd_is_abs_section (sec
)
1860 || bfd_is_und_section (sec
)))
1862 /* For other TLS symbols that bind locally, add the section
1863 TLS offset to the addend. */
1865 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1867 bfd_put_32 (output_bfd
,
1868 frvfdpic_plt_section (info
)->output_section
->vma
1869 + frvfdpic_plt_section (info
)->output_offset
1870 + frvfdpic_plt_tls_ret_offset (info
),
1871 frvfdpic_got_section (info
)->contents
1872 + frvfdpic_got_initial_offset (info
)
1873 + entry
->tlsdesc_entry
);
1875 _frvfdpic_add_rofixup (output_bfd
,
1876 frvfdpic_gotfixup_section (info
),
1877 frvfdpic_got_section (info
)
1878 ->output_section
->vma
1879 + frvfdpic_got_section (info
)
1881 + frvfdpic_got_initial_offset (info
)
1882 + entry
->tlsdesc_entry
, entry
);
1884 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
);
1886 /* We've used one of the reserved fixups, so discount it so
1887 that we can check at the end that we've used them
1889 frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
--;
1891 /* While at that, make sure the ret instruction makes to the
1892 right location in the PLT. We could do it only when we
1893 got to 0, but since the check at the end will only print
1894 a warning, make sure we have the ret in place in case the
1895 warning is missed. */
1896 bfd_put_32 (output_bfd
, 0xc03a4000,
1897 frvfdpic_plt_section (info
)->contents
1898 + frvfdpic_plt_tls_ret_offset (info
));
1903 && (bfd_is_abs_section (sec
)
1904 || bfd_is_und_section (sec
)))
1906 if (! elf_hash_table (info
)->tls_sec
)
1908 (*info
->callbacks
->undefined_symbol
)
1909 (info
, "TLS section", elf_hash_table (info
)->dynobj
,
1910 frvfdpic_got_section (info
), entry
->tlsdesc_entry
, TRUE
);
1913 idx
= elf_section_data (elf_hash_table (info
)->tls_sec
)->dynindx
;
1914 ad
+= FRVFDPIC_TLS_BIAS
;
1917 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1918 _bfd_elf_section_offset
1920 frvfdpic_got_section (info
),
1921 frvfdpic_got_initial_offset (info
)
1922 + entry
->tlsdesc_entry
)
1923 + frvfdpic_got_section (info
)
1924 ->output_section
->vma
1925 + frvfdpic_got_section (info
)
1927 R_FRV_TLSDESC_VALUE
, idx
, ad
, entry
);
1929 bfd_put_32 (output_bfd
, 0,
1930 frvfdpic_got_section (info
)->contents
1931 + frvfdpic_got_initial_offset (info
)
1932 + entry
->tlsdesc_entry
);
1935 bfd_put_32 (output_bfd
, ad
,
1936 frvfdpic_got_section (info
)->contents
1937 + frvfdpic_got_initial_offset (info
)
1938 + entry
->tlsdesc_entry
+ 4);
1941 /* Generate code for the get-TLS-offset PLT entry. */
1942 if (entry
->tlsplt_entry
!= (bfd_vma
) -1)
1944 bfd_byte
*plt_code
= frvfdpic_plt_section (info
)->contents
1945 + entry
->tlsplt_entry
;
1947 if (info
->executable
1948 && (entry
->symndx
!= -1
1949 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1952 bfd_vma ad
= addend
;
1954 /* sec may be NULL when referencing an undefweak symbol
1955 while linking a static executable. */
1958 BFD_ASSERT (entry
->symndx
== -1
1959 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
);
1963 if (entry
->symndx
== -1)
1964 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1966 ad
+= sym
->st_value
;
1967 ad
+= sec
->output_offset
;
1968 if (sec
->output_section
1969 && elf_section_data (sec
->output_section
))
1970 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1975 /* *ABS*+addend is special for TLS relocations, use only the
1976 addend for the TLS offset, and take the module id as
1979 && (bfd_is_abs_section (sec
)
1980 || bfd_is_und_section (sec
)))
1982 /* For other TLS symbols that bind locally, add the section
1983 TLS offset to the addend. */
1985 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1987 if ((bfd_signed_vma
)ad
>= -(1 << (16 - 1))
1988 && (bfd_signed_vma
)ad
< (1 << (16 - 1)))
1990 /* setlos lo(ad), gr9 */
1991 bfd_put_32 (output_bfd
,
1994 & (((bfd_vma
)1 << 16) - 1)),
2000 /* sethi.p hi(ad), gr9
2001 setlo lo(ad), gr9 */
2002 bfd_put_32 (output_bfd
,
2005 & (((bfd_vma
)1 << 16) - 1)),
2008 bfd_put_32 (output_bfd
,
2011 & (((bfd_vma
)1 << 16) - 1)),
2016 bfd_put_32 (output_bfd
, 0xc03a4000, plt_code
);
2018 else if (entry
->tlsoff_entry
)
2020 /* Figure out what kind of PLT entry we need, depending on the
2021 location of the TLS descriptor within the GOT. */
2022 if (entry
->tlsoff_entry
>= -(1 << (12 - 1))
2023 && entry
->tlsoff_entry
< (1 << (12 - 1)))
2025 /* ldi @(gr15, tlsoff_entry), gr9 */
2026 bfd_put_32 (output_bfd
,
2027 0x92c8f000 | (entry
->tlsoff_entry
2034 if (entry
->tlsoff_entry
>= -(1 << (16 - 1))
2035 && entry
->tlsoff_entry
< (1 << (16 - 1)))
2037 /* setlos lo(tlsoff_entry), gr8 */
2038 bfd_put_32 (output_bfd
,
2040 | (entry
->tlsoff_entry
2041 & (((bfd_vma
)1 << 16) - 1)),
2047 /* sethi.p hi(tlsoff_entry), gr8
2048 setlo lo(tlsoff_entry), gr8 */
2049 bfd_put_32 (output_bfd
,
2051 | ((entry
->tlsoff_entry
>> 16)
2052 & (((bfd_vma
)1 << 16) - 1)),
2055 bfd_put_32 (output_bfd
,
2057 | (entry
->tlsoff_entry
2058 & (((bfd_vma
)1 << 16) - 1)),
2062 /* ld @(gr15,gr8),gr9 */
2063 bfd_put_32 (output_bfd
, 0x9008f108, plt_code
);
2067 bfd_put_32 (output_bfd
, 0xc03a4000, plt_code
);
2071 BFD_ASSERT (entry
->tlsdesc_entry
);
2073 /* Figure out what kind of PLT entry we need, depending on the
2074 location of the TLS descriptor within the GOT. */
2075 if (entry
->tlsdesc_entry
>= -(1 << (12 - 1))
2076 && entry
->tlsdesc_entry
< (1 << (12 - 1)))
2078 /* lddi @(gr15, tlsdesc_entry), gr8 */
2079 bfd_put_32 (output_bfd
,
2080 0x90ccf000 | (entry
->tlsdesc_entry
2087 if (entry
->tlsdesc_entry
>= -(1 << (16 - 1))
2088 && entry
->tlsdesc_entry
< (1 << (16 - 1)))
2090 /* setlos lo(tlsdesc_entry), gr8 */
2091 bfd_put_32 (output_bfd
,
2093 | (entry
->tlsdesc_entry
2094 & (((bfd_vma
)1 << 16) - 1)),
2100 /* sethi.p hi(tlsdesc_entry), gr8
2101 setlo lo(tlsdesc_entry), gr8 */
2102 bfd_put_32 (output_bfd
,
2104 | ((entry
->tlsdesc_entry
>> 16)
2105 & (((bfd_vma
)1 << 16) - 1)),
2108 bfd_put_32 (output_bfd
,
2110 | (entry
->tlsdesc_entry
2111 & (((bfd_vma
)1 << 16) - 1)),
2115 /* ldd @(gr15,gr8),gr8 */
2116 bfd_put_32 (output_bfd
, 0x9008f148, plt_code
);
2119 /* jmpl @(gr8,gr0) */
2120 bfd_put_32 (output_bfd
, 0x80308000, plt_code
);
2127 /* Handle an FRV small data reloc. */
2129 static bfd_reloc_status_type
2130 elf32_frv_relocate_gprel12 (struct bfd_link_info
*info
,
2132 asection
*input_section
,
2133 Elf_Internal_Rela
*relocation
,
2139 struct bfd_link_hash_entry
*h
;
2141 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2143 gp
= (h
->u
.def
.value
2144 + h
->u
.def
.section
->output_section
->vma
2145 + h
->u
.def
.section
->output_offset
);
2147 value
-= input_section
->output_section
->vma
;
2148 value
-= (gp
- input_section
->output_section
->vma
);
2150 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2152 value
+= relocation
->r_addend
;
2154 if ((long) value
> 0x7ff || (long) value
< -0x800)
2155 return bfd_reloc_overflow
;
2157 bfd_put_32 (input_bfd
,
2158 (insn
& 0xfffff000) | (value
& 0xfff),
2159 contents
+ relocation
->r_offset
);
2161 return bfd_reloc_ok
;
2164 /* Handle an FRV small data reloc. for the u12 field. */
2166 static bfd_reloc_status_type
2167 elf32_frv_relocate_gprelu12 (struct bfd_link_info
*info
,
2169 asection
*input_section
,
2170 Elf_Internal_Rela
*relocation
,
2176 struct bfd_link_hash_entry
*h
;
2179 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2181 gp
= (h
->u
.def
.value
2182 + h
->u
.def
.section
->output_section
->vma
2183 + h
->u
.def
.section
->output_offset
);
2185 value
-= input_section
->output_section
->vma
;
2186 value
-= (gp
- input_section
->output_section
->vma
);
2188 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2190 value
+= relocation
->r_addend
;
2192 if ((long) value
> 0x7ff || (long) value
< -0x800)
2193 return bfd_reloc_overflow
;
2195 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
2197 insn
= (insn
& ~mask
) | ((value
& 0xfc0) << 12) | (value
& 0x3f);
2199 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2201 return bfd_reloc_ok
;
2204 /* Handle an FRV ELF HI16 reloc. */
2206 static bfd_reloc_status_type
2207 elf32_frv_relocate_hi16 (bfd
*input_bfd
,
2208 Elf_Internal_Rela
*relhi
,
2214 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
2216 value
+= relhi
->r_addend
;
2217 value
= ((value
>> 16) & 0xffff);
2219 insn
= (insn
& 0xffff0000) | value
;
2221 if ((long) value
> 0xffff || (long) value
< -0x10000)
2222 return bfd_reloc_overflow
;
2224 bfd_put_32 (input_bfd
, insn
, contents
+ relhi
->r_offset
);
2225 return bfd_reloc_ok
;
2228 static bfd_reloc_status_type
2229 elf32_frv_relocate_lo16 (bfd
*input_bfd
,
2230 Elf_Internal_Rela
*rello
,
2236 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2238 value
+= rello
->r_addend
;
2239 value
= value
& 0xffff;
2241 insn
= (insn
& 0xffff0000) | value
;
2243 if ((long) value
> 0xffff || (long) value
< -0x10000)
2244 return bfd_reloc_overflow
;
2246 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
2247 return bfd_reloc_ok
;
2250 /* Perform the relocation for the CALL label24 instruction. */
2252 static bfd_reloc_status_type
2253 elf32_frv_relocate_label24 (bfd
*input_bfd
,
2254 asection
*input_section
,
2255 Elf_Internal_Rela
*rello
,
2263 /* The format for the call instruction is:
2265 0 000000 0001111 000000000000000000
2266 label6 opcode label18
2268 The branch calculation is: pc + (4*label24)
2269 where label24 is the concatenation of label6 and label18. */
2271 /* Grab the instruction. */
2272 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2274 value
-= input_section
->output_section
->vma
+ input_section
->output_offset
;
2275 value
-= rello
->r_offset
;
2276 value
+= rello
->r_addend
;
2280 label6
= value
& 0xfc0000;
2281 label6
= label6
<< 7;
2283 label18
= value
& 0x3ffff;
2285 insn
= insn
& 0x803c0000;
2286 insn
= insn
| label6
;
2287 insn
= insn
| label18
;
2289 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
2291 return bfd_reloc_ok
;
2294 static bfd_reloc_status_type
2295 elf32_frv_relocate_gprelhi (struct bfd_link_info
*info
,
2297 asection
*input_section
,
2298 Elf_Internal_Rela
*relocation
,
2304 struct bfd_link_hash_entry
*h
;
2306 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2308 gp
= (h
->u
.def
.value
2309 + h
->u
.def
.section
->output_section
->vma
2310 + h
->u
.def
.section
->output_offset
);
2312 value
-= input_section
->output_section
->vma
;
2313 value
-= (gp
- input_section
->output_section
->vma
);
2314 value
+= relocation
->r_addend
;
2315 value
= ((value
>> 16) & 0xffff);
2317 if ((long) value
> 0xffff || (long) value
< -0x10000)
2318 return bfd_reloc_overflow
;
2320 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2321 insn
= (insn
& 0xffff0000) | value
;
2323 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2324 return bfd_reloc_ok
;
2327 static bfd_reloc_status_type
2328 elf32_frv_relocate_gprello (struct bfd_link_info
*info
,
2330 asection
*input_section
,
2331 Elf_Internal_Rela
*relocation
,
2337 struct bfd_link_hash_entry
*h
;
2339 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2341 gp
= (h
->u
.def
.value
2342 + h
->u
.def
.section
->output_section
->vma
2343 + h
->u
.def
.section
->output_offset
);
2345 value
-= input_section
->output_section
->vma
;
2346 value
-= (gp
- input_section
->output_section
->vma
);
2347 value
+= relocation
->r_addend
;
2348 value
= value
& 0xffff;
2350 if ((long) value
> 0xffff || (long) value
< -0x10000)
2351 return bfd_reloc_overflow
;
2353 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2354 insn
= (insn
& 0xffff0000) | value
;
2356 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2358 return bfd_reloc_ok
;
2361 static reloc_howto_type
*
2362 frv_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2363 bfd_reloc_code_real_type code
)
2370 case BFD_RELOC_NONE
:
2371 return &elf32_frv_howto_table
[ (int) R_FRV_NONE
];
2374 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2375 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2376 return &elf32_frv_rel_32_howto
;
2378 case BFD_RELOC_CTOR
:
2379 return &elf32_frv_howto_table
[ (int) R_FRV_32
];
2381 case BFD_RELOC_FRV_LABEL16
:
2382 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL16
];
2384 case BFD_RELOC_FRV_LABEL24
:
2385 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL24
];
2387 case BFD_RELOC_FRV_LO16
:
2388 return &elf32_frv_howto_table
[ (int) R_FRV_LO16
];
2390 case BFD_RELOC_FRV_HI16
:
2391 return &elf32_frv_howto_table
[ (int) R_FRV_HI16
];
2393 case BFD_RELOC_FRV_GPREL12
:
2394 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL12
];
2396 case BFD_RELOC_FRV_GPRELU12
:
2397 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELU12
];
2399 case BFD_RELOC_FRV_GPREL32
:
2400 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL32
];
2402 case BFD_RELOC_FRV_GPRELHI
:
2403 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELHI
];
2405 case BFD_RELOC_FRV_GPRELLO
:
2406 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELLO
];
2408 case BFD_RELOC_FRV_GOT12
:
2409 return &elf32_frv_howto_table
[ (int) R_FRV_GOT12
];
2411 case BFD_RELOC_FRV_GOTHI
:
2412 return &elf32_frv_howto_table
[ (int) R_FRV_GOTHI
];
2414 case BFD_RELOC_FRV_GOTLO
:
2415 return &elf32_frv_howto_table
[ (int) R_FRV_GOTLO
];
2417 case BFD_RELOC_FRV_FUNCDESC
:
2418 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2419 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2420 return &elf32_frv_rel_funcdesc_howto
;
2421 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC
];
2423 case BFD_RELOC_FRV_FUNCDESC_GOT12
:
2424 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOT12
];
2426 case BFD_RELOC_FRV_FUNCDESC_GOTHI
:
2427 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTHI
];
2429 case BFD_RELOC_FRV_FUNCDESC_GOTLO
:
2430 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTLO
];
2432 case BFD_RELOC_FRV_FUNCDESC_VALUE
:
2433 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2434 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2435 return &elf32_frv_rel_funcdesc_value_howto
;
2436 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_VALUE
];
2438 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12
:
2439 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFF12
];
2441 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI
:
2442 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFHI
];
2444 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO
:
2445 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFLO
];
2447 case BFD_RELOC_FRV_GOTOFF12
:
2448 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFF12
];
2450 case BFD_RELOC_FRV_GOTOFFHI
:
2451 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFHI
];
2453 case BFD_RELOC_FRV_GOTOFFLO
:
2454 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFLO
];
2456 case BFD_RELOC_FRV_GETTLSOFF
:
2457 return &elf32_frv_howto_table
[ (int) R_FRV_GETTLSOFF
];
2459 case BFD_RELOC_FRV_TLSDESC_VALUE
:
2460 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2461 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2462 return &elf32_frv_rel_tlsdesc_value_howto
;
2463 return &elf32_frv_howto_table
[ (int) R_FRV_TLSDESC_VALUE
];
2465 case BFD_RELOC_FRV_GOTTLSDESC12
:
2466 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESC12
];
2468 case BFD_RELOC_FRV_GOTTLSDESCHI
:
2469 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESCHI
];
2471 case BFD_RELOC_FRV_GOTTLSDESCLO
:
2472 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESCLO
];
2474 case BFD_RELOC_FRV_TLSMOFF12
:
2475 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFF12
];
2477 case BFD_RELOC_FRV_TLSMOFFHI
:
2478 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFFHI
];
2480 case BFD_RELOC_FRV_TLSMOFFLO
:
2481 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFFLO
];
2483 case BFD_RELOC_FRV_GOTTLSOFF12
:
2484 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFF12
];
2486 case BFD_RELOC_FRV_GOTTLSOFFHI
:
2487 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFFHI
];
2489 case BFD_RELOC_FRV_GOTTLSOFFLO
:
2490 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFFLO
];
2492 case BFD_RELOC_FRV_TLSOFF
:
2493 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2494 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2495 return &elf32_frv_rel_tlsoff_howto
;
2496 return &elf32_frv_howto_table
[ (int) R_FRV_TLSOFF
];
2498 case BFD_RELOC_FRV_TLSDESC_RELAX
:
2499 return &elf32_frv_howto_table
[ (int) R_FRV_TLSDESC_RELAX
];
2501 case BFD_RELOC_FRV_GETTLSOFF_RELAX
:
2502 return &elf32_frv_howto_table
[ (int) R_FRV_GETTLSOFF_RELAX
];
2504 case BFD_RELOC_FRV_TLSOFF_RELAX
:
2505 return &elf32_frv_howto_table
[ (int) R_FRV_TLSOFF_RELAX
];
2507 case BFD_RELOC_FRV_TLSMOFF
:
2508 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFF
];
2510 case BFD_RELOC_VTABLE_INHERIT
:
2511 return &elf32_frv_vtinherit_howto
;
2513 case BFD_RELOC_VTABLE_ENTRY
:
2514 return &elf32_frv_vtentry_howto
;
2520 static reloc_howto_type
*
2521 frv_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
, const char *r_name
)
2526 i
< sizeof (elf32_frv_howto_table
) / sizeof (elf32_frv_howto_table
[0]);
2528 if (elf32_frv_howto_table
[i
].name
!= NULL
2529 && strcasecmp (elf32_frv_howto_table
[i
].name
, r_name
) == 0)
2530 return &elf32_frv_howto_table
[i
];
2532 if (strcasecmp (elf32_frv_vtinherit_howto
.name
, r_name
) == 0)
2533 return &elf32_frv_vtinherit_howto
;
2534 if (strcasecmp (elf32_frv_vtentry_howto
.name
, r_name
) == 0)
2535 return &elf32_frv_vtentry_howto
;
2540 /* Set the howto pointer for an FRV ELF reloc. */
2543 frv_info_to_howto_rela (bfd
*abfd ATTRIBUTE_UNUSED
,
2545 Elf_Internal_Rela
*dst
)
2547 unsigned int r_type
;
2549 r_type
= ELF32_R_TYPE (dst
->r_info
);
2552 case R_FRV_GNU_VTINHERIT
:
2553 cache_ptr
->howto
= &elf32_frv_vtinherit_howto
;
2556 case R_FRV_GNU_VTENTRY
:
2557 cache_ptr
->howto
= &elf32_frv_vtentry_howto
;
2561 cache_ptr
->howto
= & elf32_frv_howto_table
[r_type
];
2566 /* Set the howto pointer for an FRV ELF REL reloc. */
2568 frvfdpic_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
2569 arelent
*cache_ptr
, Elf_Internal_Rela
*dst
)
2571 unsigned int r_type
;
2573 r_type
= ELF32_R_TYPE (dst
->r_info
);
2577 cache_ptr
->howto
= &elf32_frv_rel_32_howto
;
2580 case R_FRV_FUNCDESC
:
2581 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_howto
;
2584 case R_FRV_FUNCDESC_VALUE
:
2585 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_value_howto
;
2588 case R_FRV_TLSDESC_VALUE
:
2589 cache_ptr
->howto
= &elf32_frv_rel_tlsdesc_value_howto
;
2593 cache_ptr
->howto
= &elf32_frv_rel_tlsoff_howto
;
2597 cache_ptr
->howto
= NULL
;
2602 /* Perform a single relocation. By default we use the standard BFD
2603 routines, but a few relocs, we have to do them ourselves. */
2605 static bfd_reloc_status_type
2606 frv_final_link_relocate (reloc_howto_type
*howto
,
2608 asection
*input_section
,
2610 Elf_Internal_Rela
*rel
,
2613 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2614 contents
, rel
->r_offset
, relocation
,
2619 /* Relocate an FRV ELF section.
2621 The RELOCATE_SECTION function is called by the new ELF backend linker
2622 to handle the relocations for a section.
2624 The relocs are always passed as Rela structures; if the section
2625 actually uses Rel structures, the r_addend field will always be
2628 This function is responsible for adjusting the section contents as
2629 necessary, and (if using Rela relocs and generating a relocatable
2630 output file) adjusting the reloc addend as necessary.
2632 This function does not have to worry about setting the reloc
2633 address or the reloc symbol index.
2635 LOCAL_SYMS is a pointer to the swapped in local symbols.
2637 LOCAL_SECTIONS is an array giving the section in the input file
2638 corresponding to the st_shndx field of each local symbol.
2640 The global hash table entry for the global symbols can be found
2641 via elf_sym_hashes (input_bfd).
2643 When generating relocatable output, this function must handle
2644 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2645 going to be the section symbol corresponding to the output
2646 section, which means that the addend must be adjusted
2650 elf32_frv_relocate_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2651 struct bfd_link_info
*info
,
2653 asection
*input_section
,
2655 Elf_Internal_Rela
*relocs
,
2656 Elf_Internal_Sym
*local_syms
,
2657 asection
**local_sections
)
2659 Elf_Internal_Shdr
*symtab_hdr
;
2660 struct elf_link_hash_entry
**sym_hashes
;
2661 Elf_Internal_Rela
*rel
;
2662 Elf_Internal_Rela
*relend
;
2663 unsigned isec_segment
, got_segment
, plt_segment
, gprel_segment
, tls_segment
,
2665 int silence_segment_error
= !(info
->shared
|| info
->pie
);
2668 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
2669 sym_hashes
= elf_sym_hashes (input_bfd
);
2670 relend
= relocs
+ input_section
->reloc_count
;
2672 isec_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2673 input_section
->output_section
);
2674 if (IS_FDPIC (output_bfd
) && frvfdpic_got_section (info
))
2675 got_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2676 frvfdpic_got_section (info
)
2680 if (IS_FDPIC (output_bfd
) && frvfdpic_gotfixup_section (info
))
2681 gprel_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2682 frvfdpic_gotfixup_section (info
)
2686 if (IS_FDPIC (output_bfd
) && frvfdpic_plt_section (info
))
2687 plt_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2688 frvfdpic_plt_section (info
)
2692 if (elf_hash_table (info
)->tls_sec
)
2693 tls_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2694 elf_hash_table (info
)->tls_sec
);
2698 for (rel
= relocs
; rel
< relend
; rel
++)
2700 reloc_howto_type
*howto
;
2701 unsigned long r_symndx
;
2702 Elf_Internal_Sym
*sym
;
2704 struct elf_link_hash_entry
*h
;
2706 bfd_reloc_status_type r
;
2710 struct frvfdpic_relocs_info
*picrel
;
2711 bfd_vma orig_addend
= rel
->r_addend
;
2713 r_type
= ELF32_R_TYPE (rel
->r_info
);
2715 if ( r_type
== R_FRV_GNU_VTINHERIT
2716 || r_type
== R_FRV_GNU_VTENTRY
)
2719 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2720 howto
= elf32_frv_howto_table
+ ELF32_R_TYPE (rel
->r_info
);
2725 if (r_symndx
< symtab_hdr
->sh_info
)
2727 sym
= local_syms
+ r_symndx
;
2728 osec
= sec
= local_sections
[r_symndx
];
2729 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2731 name
= bfd_elf_string_from_elf_section
2732 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
2733 if (name
== NULL
|| name
[0] == 0)
2734 name
= bfd_section_name (input_bfd
, sec
);
2739 bfd_boolean unresolved_reloc
;
2741 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2742 r_symndx
, symtab_hdr
, sym_hashes
,
2744 unresolved_reloc
, warned
);
2746 name
= h
->root
.root
.string
;
2749 if (sec
!= NULL
&& discarded_section (sec
))
2750 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
2751 rel
, 1, relend
, howto
, 0, contents
);
2753 if (info
->relocatable
)
2756 if (r_type
!= R_FRV_TLSMOFF
2758 && (h
->root
.type
== bfd_link_hash_defined
2759 || h
->root
.type
== bfd_link_hash_defweak
)
2760 && !FRVFDPIC_SYM_LOCAL (info
, h
))
2770 if (! IS_FDPIC (output_bfd
))
2776 case R_FRV_FUNCDESC_GOT12
:
2777 case R_FRV_FUNCDESC_GOTHI
:
2778 case R_FRV_FUNCDESC_GOTLO
:
2779 case R_FRV_GOTOFF12
:
2780 case R_FRV_GOTOFFHI
:
2781 case R_FRV_GOTOFFLO
:
2782 case R_FRV_FUNCDESC_GOTOFF12
:
2783 case R_FRV_FUNCDESC_GOTOFFHI
:
2784 case R_FRV_FUNCDESC_GOTOFFLO
:
2785 case R_FRV_FUNCDESC
:
2786 case R_FRV_FUNCDESC_VALUE
:
2787 case R_FRV_GETTLSOFF
:
2788 case R_FRV_TLSDESC_VALUE
:
2789 case R_FRV_GOTTLSDESC12
:
2790 case R_FRV_GOTTLSDESCHI
:
2791 case R_FRV_GOTTLSDESCLO
:
2792 case R_FRV_TLSMOFF12
:
2793 case R_FRV_TLSMOFFHI
:
2794 case R_FRV_TLSMOFFLO
:
2795 case R_FRV_GOTTLSOFF12
:
2796 case R_FRV_GOTTLSOFFHI
:
2797 case R_FRV_GOTTLSOFFLO
:
2799 case R_FRV_TLSDESC_RELAX
:
2800 case R_FRV_GETTLSOFF_RELAX
:
2801 case R_FRV_TLSOFF_RELAX
:
2804 picrel
= frvfdpic_relocs_info_for_global (frvfdpic_relocs_info
2805 (info
), input_bfd
, h
,
2806 orig_addend
, INSERT
);
2808 /* In order to find the entry we created before, we must
2809 use the original addend, not the one that may have been
2810 modified by _bfd_elf_rela_local_sym(). */
2811 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
2812 (info
), input_bfd
, r_symndx
,
2813 orig_addend
, INSERT
);
2817 if (!_frvfdpic_emit_got_relocs_plt_entries (picrel
, output_bfd
, info
,
2821 info
->callbacks
->einfo
2822 (_("%H: relocation to `%s+%v'"
2823 " may have caused the error above\n"),
2824 input_bfd
, input_section
, rel
->r_offset
, name
, rel
->r_addend
);
2834 && ! FRVFDPIC_SYM_LOCAL (info
, h
)
2835 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2836 rel
->r_offset
) != (bfd_vma
) -1)
2838 info
->callbacks
->einfo
2839 (_("%H: relocation references symbol"
2840 " not defined in the module\n"),
2841 input_bfd
, input_section
, rel
->r_offset
);
2849 case R_FRV_GETTLSOFF
:
2850 case R_FRV_TLSDESC_VALUE
:
2851 case R_FRV_GOTTLSDESC12
:
2852 case R_FRV_GOTTLSDESCHI
:
2853 case R_FRV_GOTTLSDESCLO
:
2854 case R_FRV_TLSMOFF12
:
2855 case R_FRV_TLSMOFFHI
:
2856 case R_FRV_TLSMOFFLO
:
2857 case R_FRV_GOTTLSOFF12
:
2858 case R_FRV_GOTTLSOFFHI
:
2859 case R_FRV_GOTTLSOFFLO
:
2861 case R_FRV_TLSDESC_RELAX
:
2862 case R_FRV_GETTLSOFF_RELAX
:
2863 case R_FRV_TLSOFF_RELAX
:
2865 if (sec
&& (bfd_is_abs_section (sec
) || bfd_is_und_section (sec
)))
2866 relocation
+= tls_biased_base (info
);
2873 /* Try to apply TLS relaxations. */
2878 #define LOCAL_EXEC_P(info, picrel) \
2879 ((info)->executable \
2880 && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h)))
2881 #define INITIAL_EXEC_P(info, picrel) \
2882 (((info)->executable || (info)->flags & DF_STATIC_TLS) \
2883 && (picrel)->tlsoff_entry)
2885 #define IN_RANGE_FOR_OFST12_P(value) \
2886 ((bfd_vma)((value) + 2048) < (bfd_vma)4096)
2887 #define IN_RANGE_FOR_SETLOS_P(value) \
2888 ((bfd_vma)((value) + 32768) < (bfd_vma)65536)
2889 #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \
2890 (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info)))
2892 #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2893 (LOCAL_EXEC_P ((info), (picrel)) \
2894 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2895 #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \
2896 (INITIAL_EXEC_P ((info), (picrel)) \
2897 && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry))
2899 #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \
2900 (LOCAL_EXEC_P ((info), (picrel)))
2901 #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \
2902 (INITIAL_EXEC_P ((info), (picrel)))
2904 #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2905 (LOCAL_EXEC_P ((info), (picrel)) \
2906 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2908 case R_FRV_GETTLSOFF
:
2909 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2911 /* Is this a call instruction? */
2912 if ((insn
& (unsigned long)0x01fc0000) != 0x003c0000)
2914 info
->callbacks
->einfo
2915 (_("%H: R_FRV_GETTLSOFF not applied to a call instruction\n"),
2916 input_bfd
, input_section
, rel
->r_offset
);
2920 if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info
, picrel
,
2921 relocation
+ rel
->r_addend
))
2923 /* Replace the call instruction (except the packing bit)
2924 with setlos #tlsmofflo(symbol+offset), gr9. */
2925 insn
&= (unsigned long)0x80000000;
2926 insn
|= (unsigned long)0x12fc0000;
2927 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
2929 r_type
= R_FRV_TLSMOFFLO
;
2930 howto
= elf32_frv_howto_table
+ r_type
;
2931 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
2934 else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info
, picrel
))
2936 /* Replace the call instruction (except the packing bit)
2937 with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */
2938 insn
&= (unsigned long)0x80000000;
2939 insn
|= (unsigned long)0x12c8f000;
2940 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
2942 r_type
= R_FRV_GOTTLSOFF12
;
2943 howto
= elf32_frv_howto_table
+ r_type
;
2944 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
2949 case R_FRV_GOTTLSDESC12
:
2950 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2952 /* Is this an lddi instruction? */
2953 if ((insn
& (unsigned long)0x01fc0000) != 0x00cc0000)
2955 info
->callbacks
->einfo
2956 (_("%H: R_FRV_GOTTLSDESC12"
2957 " not applied to an lddi instruction\n"),
2958 input_bfd
, input_section
, rel
->r_offset
);
2962 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
2963 relocation
+ rel
->r_addend
)
2964 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
2967 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
2968 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
2969 Preserve the packing bit. */
2970 insn
= (insn
& (unsigned long)0x80000000)
2971 | ((insn
+ (unsigned long)0x02000000)
2972 & (unsigned long)0x7e000000);
2973 insn
|= (unsigned long)0x00fc0000;
2974 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
2976 r_type
= R_FRV_TLSMOFFLO
;
2977 howto
= elf32_frv_howto_table
+ r_type
;
2978 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
2981 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
2982 relocation
+ rel
->r_addend
))
2984 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
2985 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
2986 Preserve the packing bit. */
2987 insn
= (insn
& (unsigned long)0x80000000)
2988 | ((insn
+ (unsigned long)0x02000000)
2989 & (unsigned long)0x7e000000);
2990 insn
|= (unsigned long)0x00f80000;
2991 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
2993 r_type
= R_FRV_TLSMOFFHI
;
2994 howto
= elf32_frv_howto_table
+ r_type
;
2995 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
2998 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3000 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3001 with ldi @(grB, #gottlsoff12(symbol+offset),
3002 gr<C+1>. Preserve the packing bit. If gottlsoff12
3003 overflows, we'll error out, but that's sort-of ok,
3004 since we'd started with gottlsdesc12, that's actually
3005 more demanding. Compiling with -fPIE instead of
3006 -fpie would fix it; linking with --relax should fix
3008 insn
= (insn
& (unsigned long)0x80cbf000)
3009 | ((insn
+ (unsigned long)0x02000000)
3010 & (unsigned long)0x7e000000);
3011 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3013 r_type
= R_FRV_GOTTLSOFF12
;
3014 howto
= elf32_frv_howto_table
+ r_type
;
3015 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3020 case R_FRV_GOTTLSDESCHI
:
3021 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3023 /* Is this a sethi instruction? */
3024 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3026 info
->callbacks
->einfo
3027 (_("%H: R_FRV_GOTTLSDESCHI"
3028 " not applied to a sethi instruction\n"),
3029 input_bfd
, input_section
, rel
->r_offset
);
3033 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3034 relocation
+ rel
->r_addend
)
3035 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3036 && IN_RANGE_FOR_SETLOS_P (picrel
->tlsoff_entry
)))
3038 /* Replace sethi with a nop. Preserve the packing bit. */
3039 insn
&= (unsigned long)0x80000000;
3040 insn
|= (unsigned long)0x00880000;
3041 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3043 /* Nothing to relocate. */
3047 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3049 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3050 r_type
= R_FRV_GOTTLSOFFHI
;
3051 howto
= elf32_frv_howto_table
+ r_type
;
3052 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3057 case R_FRV_GOTTLSDESCLO
:
3058 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3060 /* Is this a setlo or setlos instruction? */
3061 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3063 info
->callbacks
->einfo
3064 (_("%H: R_FRV_GOTTLSDESCLO"
3065 " not applied to a setlo or setlos instruction\n"),
3066 input_bfd
, input_section
, rel
->r_offset
);
3070 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3071 relocation
+ rel
->r_addend
)
3072 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3073 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3075 /* Replace setlo/setlos with a nop. Preserve the
3077 insn
&= (unsigned long)0x80000000;
3078 insn
|= (unsigned long)0x00880000;
3079 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3081 /* Nothing to relocate. */
3085 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3087 /* If the corresponding sethi (if it exists) decayed
3088 to a nop, make sure this becomes (or already is) a
3089 setlos, not setlo. */
3090 if (IN_RANGE_FOR_SETLOS_P (picrel
->tlsoff_entry
))
3092 insn
|= (unsigned long)0x00080000;
3093 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3096 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3097 r_type
= R_FRV_GOTTLSOFFLO
;
3098 howto
= elf32_frv_howto_table
+ r_type
;
3099 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3104 case R_FRV_TLSDESC_RELAX
:
3105 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3107 /* Is this an ldd instruction? */
3108 if ((insn
& (unsigned long)0x01fc0fc0) != 0x00080140)
3110 info
->callbacks
->einfo
3111 (_("%H: R_FRV_TLSDESC_RELAX"
3112 " not applied to an ldd instruction\n"),
3113 input_bfd
, input_section
, rel
->r_offset
);
3117 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3118 relocation
+ rel
->r_addend
)
3119 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3122 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3123 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3124 Preserve the packing bit. */
3125 insn
= (insn
& (unsigned long)0x80000000)
3126 | ((insn
+ (unsigned long)0x02000000)
3127 & (unsigned long)0x7e000000);
3128 insn
|= (unsigned long)0x00fc0000;
3129 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3131 r_type
= R_FRV_TLSMOFFLO
;
3132 howto
= elf32_frv_howto_table
+ r_type
;
3133 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3136 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3137 relocation
+ rel
->r_addend
))
3139 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3140 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3141 Preserve the packing bit. */
3142 insn
= (insn
& (unsigned long)0x80000000)
3143 | ((insn
+ (unsigned long)0x02000000)
3144 & (unsigned long)0x7e000000);
3145 insn
|= (unsigned long)0x00f80000;
3146 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3148 r_type
= R_FRV_TLSMOFFHI
;
3149 howto
= elf32_frv_howto_table
+ r_type
;
3150 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3153 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3154 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
))
3156 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3157 with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>.
3158 Preserve the packing bit. */
3159 insn
= (insn
& (unsigned long)0x8003f000)
3160 | (unsigned long)0x00c80000
3161 | ((insn
+ (unsigned long)0x02000000)
3162 & (unsigned long)0x7e000000);
3163 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3165 r_type
= R_FRV_GOTTLSOFF12
;
3166 howto
= elf32_frv_howto_table
+ r_type
;
3167 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3170 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3172 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3173 with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>.
3174 Preserve the packing bit. */
3175 insn
= (insn
& (unsigned long)0x81ffffbf)
3176 | ((insn
+ (unsigned long)0x02000000)
3177 & (unsigned long)0x7e000000);
3178 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3180 /* #tlsoff(symbol+offset) is just a relaxation
3181 annotation, so there's nothing left to
3188 case R_FRV_GETTLSOFF_RELAX
:
3189 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3191 /* Is this a calll or callil instruction? */
3192 if ((insn
& (unsigned long)0x7ff80fc0) != 0x02300000)
3194 info
->callbacks
->einfo
3195 (_("%H: R_FRV_GETTLSOFF_RELAX"
3196 " not applied to a calll instruction\n"),
3197 input_bfd
, input_section
, rel
->r_offset
);
3201 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3202 relocation
+ rel
->r_addend
)
3203 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3206 /* Replace calll with a nop. Preserve the packing bit. */
3207 insn
&= (unsigned long)0x80000000;
3208 insn
|= (unsigned long)0x00880000;
3209 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3211 /* Nothing to relocate. */
3215 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3216 relocation
+ rel
->r_addend
))
3218 /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9.
3219 Preserve the packing bit. */
3220 insn
&= (unsigned long)0x80000000;
3221 insn
|= (unsigned long)0x12f40000;
3222 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3224 r_type
= R_FRV_TLSMOFFLO
;
3225 howto
= elf32_frv_howto_table
+ r_type
;
3226 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3229 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3231 /* Replace calll with a nop. Preserve the packing bit. */
3232 insn
&= (unsigned long)0x80000000;
3233 insn
|= (unsigned long)0x00880000;
3234 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3236 /* Nothing to relocate. */
3242 case R_FRV_GOTTLSOFF12
:
3243 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3245 /* Is this an ldi instruction? */
3246 if ((insn
& (unsigned long)0x01fc0000) != 0x00c80000)
3248 info
->callbacks
->einfo
3249 (_("%H: R_FRV_GOTTLSOFF12"
3250 " not applied to an ldi instruction\n"),
3251 input_bfd
, input_section
, rel
->r_offset
);
3255 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3256 relocation
+ rel
->r_addend
))
3258 /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC
3259 with setlos #tlsmofflo(symbol+offset), grC.
3260 Preserve the packing bit. */
3261 insn
&= (unsigned long)0xfe000000;
3262 insn
|= (unsigned long)0x00fc0000;
3263 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3265 r_type
= R_FRV_TLSMOFFLO
;
3266 howto
= elf32_frv_howto_table
+ r_type
;
3267 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3272 case R_FRV_GOTTLSOFFHI
:
3273 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3275 /* Is this a sethi instruction? */
3276 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3278 info
->callbacks
->einfo
3279 (_("%H: R_FRV_GOTTLSOFFHI"
3280 " not applied to a sethi instruction\n"),
3281 input_bfd
, input_section
, rel
->r_offset
);
3285 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3286 relocation
+ rel
->r_addend
)
3287 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3288 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3290 /* Replace sethi with a nop. Preserve the packing bit. */
3291 insn
&= (unsigned long)0x80000000;
3292 insn
|= (unsigned long)0x00880000;
3293 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3295 /* Nothing to relocate. */
3301 case R_FRV_GOTTLSOFFLO
:
3302 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3304 /* Is this a setlo or setlos instruction? */
3305 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3307 info
->callbacks
->einfo
3308 (_("%H: R_FRV_GOTTLSOFFLO"
3309 " not applied to a setlo or setlos instruction\n"),
3310 input_bfd
, input_section
, rel
->r_offset
);
3314 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3315 relocation
+ rel
->r_addend
)
3316 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3317 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3319 /* Replace setlo/setlos with a nop. Preserve the
3321 insn
&= (unsigned long)0x80000000;
3322 insn
|= (unsigned long)0x00880000;
3323 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3325 /* Nothing to relocate. */
3331 case R_FRV_TLSOFF_RELAX
:
3332 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3334 /* Is this an ld instruction? */
3335 if ((insn
& (unsigned long)0x01fc0fc0) != 0x00080100)
3337 info
->callbacks
->einfo
3338 (_("%H: R_FRV_TLSOFF_RELAX"
3339 " not applied to an ld instruction\n"),
3340 input_bfd
, input_section
, rel
->r_offset
);
3344 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3345 relocation
+ rel
->r_addend
))
3347 /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC
3348 with setlos #tlsmofflo(symbol+offset), grC.
3349 Preserve the packing bit. */
3350 insn
&= (unsigned long)0xfe000000;
3351 insn
|= (unsigned long)0x00fc0000;
3352 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3354 r_type
= R_FRV_TLSMOFFLO
;
3355 howto
= elf32_frv_howto_table
+ r_type
;
3356 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3359 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3360 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
))
3362 /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC
3363 with ldi @(grB, #gottlsoff12(symbol+offset), grC.
3364 Preserve the packing bit. */
3365 insn
= (insn
& (unsigned long)0xfe03f000)
3366 | (unsigned long)0x00c80000;
3367 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3369 r_type
= R_FRV_GOTTLSOFF12
;
3370 howto
= elf32_frv_howto_table
+ r_type
;
3371 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3376 case R_FRV_TLSMOFFHI
:
3377 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3379 /* Is this a sethi instruction? */
3380 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3382 info
->callbacks
->einfo
3383 (_("%H: R_FRV_TLSMOFFHI"
3384 " not applied to a sethi instruction\n"),
3385 input_bfd
, input_section
, rel
->r_offset
);
3389 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3392 /* Replace sethi with a nop. Preserve the packing bit. */
3393 insn
&= (unsigned long)0x80000000;
3394 insn
|= (unsigned long)0x00880000;
3395 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3397 /* Nothing to relocate. */
3403 case R_FRV_TLSMOFFLO
:
3404 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3406 /* Is this a setlo or setlos instruction? */
3407 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3409 info
->callbacks
->einfo
3410 (_("R_FRV_TLSMOFFLO"
3411 " not applied to a setlo or setlos instruction\n"),
3412 input_bfd
, input_section
, rel
->r_offset
);
3416 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3418 /* If the corresponding sethi (if it exists) decayed
3419 to a nop, make sure this becomes (or already is) a
3420 setlos, not setlo. */
3422 insn
|= (unsigned long)0x00080000;
3423 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3429 There's nothing to relax in these:
3445 check_segment
[0] = isec_segment
;
3446 if (! IS_FDPIC (output_bfd
))
3447 check_segment
[1] = isec_segment
;
3448 else if (picrel
->plt
)
3450 relocation
= frvfdpic_plt_section (info
)->output_section
->vma
3451 + frvfdpic_plt_section (info
)->output_offset
3452 + picrel
->plt_entry
;
3453 check_segment
[1] = plt_segment
;
3455 /* We don't want to warn on calls to undefined weak symbols,
3456 as calls to them must be protected by non-NULL tests
3457 anyway, and unprotected calls would invoke undefined
3459 else if (picrel
->symndx
== -1
3460 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefweak
)
3461 check_segment
[1] = check_segment
[0];
3463 check_segment
[1] = sec
3464 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3471 relocation
= picrel
->got_entry
;
3472 check_segment
[0] = check_segment
[1] = got_segment
;
3475 case R_FRV_FUNCDESC_GOT12
:
3476 case R_FRV_FUNCDESC_GOTHI
:
3477 case R_FRV_FUNCDESC_GOTLO
:
3478 relocation
= picrel
->fdgot_entry
;
3479 check_segment
[0] = check_segment
[1] = got_segment
;
3482 case R_FRV_GOTOFFHI
:
3483 case R_FRV_GOTOFF12
:
3484 case R_FRV_GOTOFFLO
:
3485 relocation
-= frvfdpic_got_section (info
)->output_section
->vma
3486 + frvfdpic_got_section (info
)->output_offset
3487 + frvfdpic_got_initial_offset (info
);
3488 check_segment
[0] = got_segment
;
3489 check_segment
[1] = sec
3490 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3494 case R_FRV_FUNCDESC_GOTOFF12
:
3495 case R_FRV_FUNCDESC_GOTOFFHI
:
3496 case R_FRV_FUNCDESC_GOTOFFLO
:
3497 relocation
= picrel
->fd_entry
;
3498 check_segment
[0] = check_segment
[1] = got_segment
;
3501 case R_FRV_FUNCDESC
:
3504 bfd_vma addend
= rel
->r_addend
;
3506 if (! (h
&& h
->root
.type
== bfd_link_hash_undefweak
3507 && FRVFDPIC_SYM_LOCAL (info
, h
)))
3509 /* If the symbol is dynamic and there may be dynamic
3510 symbol resolution because we are or are linked with a
3511 shared library, emit a FUNCDESC relocation such that
3512 the dynamic linker will allocate the function
3513 descriptor. If the symbol needs a non-local function
3514 descriptor but binds locally (e.g., its visibility is
3515 protected, emit a dynamic relocation decayed to
3517 if (h
&& ! FRVFDPIC_FUNCDESC_LOCAL (info
, h
)
3518 && FRVFDPIC_SYM_LOCAL (info
, h
)
3519 && !(info
->executable
&& !info
->pie
))
3521 dynindx
= elf_section_data (h
->root
.u
.def
.section
3522 ->output_section
)->dynindx
;
3523 addend
+= h
->root
.u
.def
.section
->output_offset
3524 + h
->root
.u
.def
.value
;
3526 else if (h
&& ! FRVFDPIC_FUNCDESC_LOCAL (info
, h
))
3530 info
->callbacks
->einfo
3531 (_("%H: R_FRV_FUNCDESC references dynamic symbol"
3532 " with nonzero addend\n"),
3533 input_bfd
, input_section
, rel
->r_offset
);
3536 dynindx
= h
->dynindx
;
3540 /* Otherwise, we know we have a private function
3541 descriptor, so reference it directly. */
3542 BFD_ASSERT (picrel
->privfd
);
3544 dynindx
= elf_section_data (frvfdpic_got_section (info
)
3545 ->output_section
)->dynindx
;
3546 addend
= frvfdpic_got_section (info
)->output_offset
3547 + frvfdpic_got_initial_offset (info
)
3551 /* If there is room for dynamic symbol resolution, emit
3552 the dynamic relocation. However, if we're linking an
3553 executable at a fixed location, we won't have emitted a
3554 dynamic symbol entry for the got section, so idx will
3555 be zero, which means we can and should compute the
3556 address of the private descriptor ourselves. */
3557 if (info
->executable
&& !info
->pie
3558 && (!h
|| FRVFDPIC_FUNCDESC_LOCAL (info
, h
)))
3560 addend
+= frvfdpic_got_section (info
)->output_section
->vma
;
3561 if ((bfd_get_section_flags (output_bfd
,
3562 input_section
->output_section
)
3563 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3567 if (_frvfdpic_osec_readonly_p (output_bfd
,
3571 info
->callbacks
->einfo
3572 (_("%H: cannot emit fixups"
3573 " in read-only section\n"),
3574 input_bfd
, input_section
, rel
->r_offset
);
3578 offset
= _bfd_elf_section_offset
3580 input_section
, rel
->r_offset
);
3582 if (offset
!= (bfd_vma
)-1)
3583 _frvfdpic_add_rofixup (output_bfd
,
3584 frvfdpic_gotfixup_section
3586 offset
+ input_section
3587 ->output_section
->vma
3588 + input_section
->output_offset
,
3592 else if ((bfd_get_section_flags (output_bfd
,
3593 input_section
->output_section
)
3594 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3598 if (_frvfdpic_osec_readonly_p (output_bfd
,
3602 info
->callbacks
->einfo
3603 (_("%H: cannot emit dynamic relocations"
3604 " in read-only section\n"),
3605 input_bfd
, input_section
, rel
->r_offset
);
3609 offset
= _bfd_elf_section_offset
3611 input_section
, rel
->r_offset
);
3613 if (offset
!= (bfd_vma
)-1)
3614 _frvfdpic_add_dyn_reloc (output_bfd
,
3615 frvfdpic_gotrel_section (info
),
3616 offset
+ input_section
3617 ->output_section
->vma
3618 + input_section
->output_offset
,
3619 r_type
, dynindx
, addend
, picrel
);
3622 addend
+= frvfdpic_got_section (info
)->output_section
->vma
;
3625 /* We want the addend in-place because dynamic
3626 relocations are REL. Setting relocation to it should
3627 arrange for it to be installed. */
3628 relocation
= addend
- rel
->r_addend
;
3630 check_segment
[0] = check_segment
[1] = got_segment
;
3634 if (! IS_FDPIC (output_bfd
))
3636 check_segment
[0] = check_segment
[1] = -1;
3640 case R_FRV_FUNCDESC_VALUE
:
3643 bfd_vma addend
= rel
->r_addend
;
3645 /* If the symbol is dynamic but binds locally, use
3647 if (h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
))
3649 if (addend
&& r_type
== R_FRV_FUNCDESC_VALUE
)
3651 info
->callbacks
->einfo
3652 (_("%H: R_FRV_FUNCDESC_VALUE"
3653 " references dynamic symbol with nonzero addend\n"),
3654 input_bfd
, input_section
, rel
->r_offset
);
3657 dynindx
= h
->dynindx
;
3662 addend
+= h
->root
.u
.def
.value
;
3664 addend
+= sym
->st_value
;
3666 addend
+= osec
->output_offset
;
3667 if (osec
&& osec
->output_section
3668 && ! bfd_is_abs_section (osec
->output_section
)
3669 && ! bfd_is_und_section (osec
->output_section
))
3670 dynindx
= elf_section_data (osec
->output_section
)->dynindx
;
3675 /* If we're linking an executable at a fixed address, we
3676 can omit the dynamic relocation as long as the symbol
3677 is defined in the current link unit (which is implied
3678 by its output section not being NULL). */
3679 if (info
->executable
&& !info
->pie
3680 && (!h
|| FRVFDPIC_SYM_LOCAL (info
, h
)))
3683 addend
+= osec
->output_section
->vma
;
3684 if (IS_FDPIC (input_bfd
)
3685 && (bfd_get_section_flags (output_bfd
,
3686 input_section
->output_section
)
3687 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3689 if (_frvfdpic_osec_readonly_p (output_bfd
,
3693 info
->callbacks
->einfo
3694 (_("%H: cannot emit fixups in read-only section\n"),
3695 input_bfd
, input_section
, rel
->r_offset
);
3698 if (!h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
3700 bfd_vma offset
= _bfd_elf_section_offset
3702 input_section
, rel
->r_offset
);
3704 if (offset
!= (bfd_vma
)-1)
3706 _frvfdpic_add_rofixup (output_bfd
,
3707 frvfdpic_gotfixup_section
3709 offset
+ input_section
3710 ->output_section
->vma
3711 + input_section
->output_offset
,
3713 if (r_type
== R_FRV_FUNCDESC_VALUE
)
3714 _frvfdpic_add_rofixup
3716 frvfdpic_gotfixup_section (info
),
3718 + input_section
->output_section
->vma
3719 + input_section
->output_offset
+ 4, picrel
);
3726 if ((bfd_get_section_flags (output_bfd
,
3727 input_section
->output_section
)
3728 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3732 if (_frvfdpic_osec_readonly_p (output_bfd
,
3736 info
->callbacks
->einfo
3737 (_("%H: cannot emit dynamic relocations"
3738 " in read-only section\n"),
3739 input_bfd
, input_section
, rel
->r_offset
);
3743 offset
= _bfd_elf_section_offset
3745 input_section
, rel
->r_offset
);
3747 if (offset
!= (bfd_vma
)-1)
3748 _frvfdpic_add_dyn_reloc (output_bfd
,
3749 frvfdpic_gotrel_section (info
),
3750 offset
+ input_section
3751 ->output_section
->vma
3752 + input_section
->output_offset
,
3753 r_type
, dynindx
, addend
, picrel
);
3756 addend
+= osec
->output_section
->vma
;
3757 /* We want the addend in-place because dynamic
3758 relocations are REL. Setting relocation to it
3759 should arrange for it to be installed. */
3760 relocation
= addend
- rel
->r_addend
;
3763 if (r_type
== R_FRV_FUNCDESC_VALUE
)
3765 /* If we've omitted the dynamic relocation, just emit
3766 the fixed addresses of the symbol and of the local
3768 if (info
->executable
&& !info
->pie
3769 && (!h
|| FRVFDPIC_SYM_LOCAL (info
, h
)))
3770 bfd_put_32 (output_bfd
,
3771 frvfdpic_got_section (info
)->output_section
->vma
3772 + frvfdpic_got_section (info
)->output_offset
3773 + frvfdpic_got_initial_offset (info
),
3774 contents
+ rel
->r_offset
+ 4);
3776 /* A function descriptor used for lazy or local
3777 resolving is initialized such that its high word
3778 contains the output section index in which the
3779 PLT entries are located, and the low word
3780 contains the offset of the lazy PLT entry entry
3781 point into that section. */
3782 bfd_put_32 (output_bfd
,
3783 h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
)
3785 : _frvfdpic_osec_to_segment (output_bfd
,
3788 contents
+ rel
->r_offset
+ 4);
3791 check_segment
[0] = check_segment
[1] = got_segment
;
3795 case R_FRV_GPRELU12
:
3799 check_segment
[0] = gprel_segment
;
3800 check_segment
[1] = sec
3801 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3805 case R_FRV_GETTLSOFF
:
3806 relocation
= frvfdpic_plt_section (info
)->output_section
->vma
3807 + frvfdpic_plt_section (info
)->output_offset
3808 + picrel
->tlsplt_entry
;
3809 BFD_ASSERT (picrel
->tlsplt_entry
!= (bfd_vma
)-1
3810 && picrel
->tlsdesc_entry
);
3811 check_segment
[0] = isec_segment
;
3812 check_segment
[1] = plt_segment
;
3815 case R_FRV_GOTTLSDESC12
:
3816 case R_FRV_GOTTLSDESCHI
:
3817 case R_FRV_GOTTLSDESCLO
:
3818 BFD_ASSERT (picrel
->tlsdesc_entry
);
3819 relocation
= picrel
->tlsdesc_entry
;
3820 check_segment
[0] = tls_segment
;
3821 check_segment
[1] = sec
3822 && ! bfd_is_abs_section (sec
)
3823 && ! bfd_is_und_section (sec
)
3824 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3828 case R_FRV_TLSMOFF12
:
3829 case R_FRV_TLSMOFFHI
:
3830 case R_FRV_TLSMOFFLO
:
3832 check_segment
[0] = tls_segment
;
3834 check_segment
[1] = -1;
3835 else if (bfd_is_abs_section (sec
)
3836 || bfd_is_und_section (sec
))
3839 check_segment
[1] = tls_segment
;
3841 else if (sec
->output_section
)
3843 relocation
-= tls_biased_base (info
);
3845 _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
);
3848 check_segment
[1] = -1;
3851 case R_FRV_GOTTLSOFF12
:
3852 case R_FRV_GOTTLSOFFHI
:
3853 case R_FRV_GOTTLSOFFLO
:
3854 BFD_ASSERT (picrel
->tlsoff_entry
);
3855 relocation
= picrel
->tlsoff_entry
;
3856 check_segment
[0] = tls_segment
;
3857 check_segment
[1] = sec
3858 && ! bfd_is_abs_section (sec
)
3859 && ! bfd_is_und_section (sec
)
3860 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3864 case R_FRV_TLSDESC_VALUE
:
3866 /* These shouldn't be present in input object files. */
3867 check_segment
[0] = check_segment
[1] = isec_segment
;
3870 case R_FRV_TLSDESC_RELAX
:
3871 case R_FRV_GETTLSOFF_RELAX
:
3872 case R_FRV_TLSOFF_RELAX
:
3873 /* These are just annotations for relaxation, nothing to do
3878 check_segment
[0] = isec_segment
;
3879 check_segment
[1] = sec
3880 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3885 if (check_segment
[0] != check_segment
[1] && IS_FDPIC (output_bfd
))
3887 /* If you take this out, remove the #error from fdpic-static-6.d
3888 in the ld testsuite. */
3889 /* This helps catch problems in GCC while we can't do more
3890 than static linking. The idea is to test whether the
3891 input file basename is crt0.o only once. */
3892 if (silence_segment_error
== 1)
3893 silence_segment_error
=
3894 (strlen (input_bfd
->filename
) == 6
3895 && filename_cmp (input_bfd
->filename
, "crt0.o") == 0)
3896 || (strlen (input_bfd
->filename
) > 6
3897 && filename_cmp (input_bfd
->filename
3898 + strlen (input_bfd
->filename
) - 7,
3901 if (!silence_segment_error
3902 /* We don't want duplicate errors for undefined
3904 && !(picrel
&& picrel
->symndx
== -1
3905 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefined
))
3907 info
->callbacks
->einfo
3908 (_("%H: reloc against `%s' references a different segment\n"),
3909 input_bfd
, input_section
, rel
->r_offset
, name
);
3911 if (!silence_segment_error
&& (info
->shared
|| info
->pie
))
3913 elf_elfheader (output_bfd
)->e_flags
|= EF_FRV_PIC
;
3918 case R_FRV_GOTOFFHI
:
3919 case R_FRV_TLSMOFFHI
:
3920 /* We need the addend to be applied before we shift the
3922 relocation
+= rel
->r_addend
;
3925 case R_FRV_FUNCDESC_GOTHI
:
3926 case R_FRV_FUNCDESC_GOTOFFHI
:
3927 case R_FRV_GOTTLSOFFHI
:
3928 case R_FRV_GOTTLSDESCHI
:
3933 case R_FRV_FUNCDESC_GOTLO
:
3934 case R_FRV_GOTOFFLO
:
3935 case R_FRV_FUNCDESC_GOTOFFLO
:
3936 case R_FRV_GOTTLSOFFLO
:
3937 case R_FRV_GOTTLSDESCLO
:
3938 case R_FRV_TLSMOFFLO
:
3939 relocation
&= 0xffff;
3949 if (! IS_FDPIC (output_bfd
) || ! picrel
->plt
)
3953 /* When referencing a GOT entry, a function descriptor or a
3954 PLT, we don't want the addend to apply to the reference,
3955 but rather to the referenced symbol. The actual entry
3956 will have already been created taking the addend into
3957 account, so cancel it out here. */
3961 case R_FRV_FUNCDESC_GOT12
:
3962 case R_FRV_FUNCDESC_GOTHI
:
3963 case R_FRV_FUNCDESC_GOTLO
:
3964 case R_FRV_FUNCDESC_GOTOFF12
:
3965 case R_FRV_FUNCDESC_GOTOFFHI
:
3966 case R_FRV_FUNCDESC_GOTOFFLO
:
3967 case R_FRV_GETTLSOFF
:
3968 case R_FRV_GOTTLSDESC12
:
3969 case R_FRV_GOTTLSDESCHI
:
3970 case R_FRV_GOTTLSDESCLO
:
3971 case R_FRV_GOTTLSOFF12
:
3972 case R_FRV_GOTTLSOFFHI
:
3973 case R_FRV_GOTTLSOFFLO
:
3974 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
3975 here, since we do want to apply the addend to the others.
3976 Note that we've applied the addend to GOTOFFHI before we
3977 shifted it right. */
3978 case R_FRV_GOTOFFHI
:
3979 case R_FRV_TLSMOFFHI
:
3980 relocation
-= rel
->r_addend
;
3987 if (r_type
== R_FRV_HI16
)
3988 r
= elf32_frv_relocate_hi16 (input_bfd
, rel
, contents
, relocation
);
3990 else if (r_type
== R_FRV_LO16
)
3991 r
= elf32_frv_relocate_lo16 (input_bfd
, rel
, contents
, relocation
);
3993 else if (r_type
== R_FRV_LABEL24
|| r_type
== R_FRV_GETTLSOFF
)
3994 r
= elf32_frv_relocate_label24 (input_bfd
, input_section
, rel
,
3995 contents
, relocation
);
3997 else if (r_type
== R_FRV_GPREL12
)
3998 r
= elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, rel
,
3999 contents
, relocation
);
4001 else if (r_type
== R_FRV_GPRELU12
)
4002 r
= elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, rel
,
4003 contents
, relocation
);
4005 else if (r_type
== R_FRV_GPRELLO
)
4006 r
= elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, rel
,
4007 contents
, relocation
);
4009 else if (r_type
== R_FRV_GPRELHI
)
4010 r
= elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, rel
,
4011 contents
, relocation
);
4013 else if (r_type
== R_FRV_TLSOFF
4014 || r_type
== R_FRV_TLSDESC_VALUE
)
4015 r
= bfd_reloc_notsupported
;
4018 r
= frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
4021 if (r
!= bfd_reloc_ok
)
4023 const char * msg
= (const char *) NULL
;
4027 case bfd_reloc_overflow
:
4028 r
= info
->callbacks
->reloc_overflow
4029 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4030 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
4033 case bfd_reloc_undefined
:
4034 r
= info
->callbacks
->undefined_symbol
4035 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
4038 case bfd_reloc_outofrange
:
4039 msg
= _("internal error: out of range error");
4042 case bfd_reloc_notsupported
:
4043 msg
= _("internal error: unsupported relocation error");
4046 case bfd_reloc_dangerous
:
4047 msg
= _("internal error: dangerous relocation");
4051 msg
= _("internal error: unknown error");
4057 info
->callbacks
->einfo
4058 (_("%H: reloc against `%s': %s\n"),
4059 input_bfd
, input_section
, rel
->r_offset
, name
, msg
);
4071 /* Return the section that should be marked against GC for a given
4075 elf32_frv_gc_mark_hook (asection
*sec
,
4076 struct bfd_link_info
*info
,
4077 Elf_Internal_Rela
*rel
,
4078 struct elf_link_hash_entry
*h
,
4079 Elf_Internal_Sym
*sym
)
4082 switch (ELF32_R_TYPE (rel
->r_info
))
4084 case R_FRV_GNU_VTINHERIT
:
4085 case R_FRV_GNU_VTENTRY
:
4089 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
4092 /* Hook called by the linker routine which adds symbols from an object
4093 file. We use it to put .comm items in .scomm, and not .comm. */
4096 elf32_frv_add_symbol_hook (bfd
*abfd
,
4097 struct bfd_link_info
*info
,
4098 Elf_Internal_Sym
*sym
,
4099 const char **namep ATTRIBUTE_UNUSED
,
4100 flagword
*flagsp ATTRIBUTE_UNUSED
,
4104 if (sym
->st_shndx
== SHN_COMMON
4105 && !info
->relocatable
4106 && (int)sym
->st_size
<= (int)bfd_get_gp_size (abfd
))
4108 /* Common symbols less than or equal to -G nn bytes are
4109 automatically put into .sbss. */
4111 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
4115 scomm
= bfd_make_section_with_flags (abfd
, ".scommon",
4118 | SEC_LINKER_CREATED
));
4124 *valp
= sym
->st_size
;
4130 /* We need dynamic symbols for every section, since segments can
4131 relocate independently. */
4133 _frvfdpic_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4134 struct bfd_link_info
*info
4136 asection
*p ATTRIBUTE_UNUSED
)
4138 switch (elf_section_data (p
)->this_hdr
.sh_type
)
4142 /* If sh_type is yet undecided, assume it could be
4143 SHT_PROGBITS/SHT_NOBITS. */
4147 /* There shouldn't be section relative relocations
4148 against any other section. */
4154 /* Create a .got section, as well as its additional info field. This
4155 is almost entirely copied from
4156 elflink.c:_bfd_elf_create_got_section(). */
4159 _frv_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4161 flagword flags
, pltflags
;
4163 struct elf_link_hash_entry
*h
;
4164 struct bfd_link_hash_entry
*bh
;
4165 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4169 /* This function may be called more than once. */
4170 s
= bfd_get_linker_section (abfd
, ".got");
4174 /* Machine specific: although pointers are 32-bits wide, we want the
4175 GOT to be aligned to a 64-bit boundary, such that function
4176 descriptors in it can be accessed with 64-bit loads and
4180 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4181 | SEC_LINKER_CREATED
);
4184 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
4186 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
4189 if (bed
->want_got_plt
)
4191 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt", flags
);
4193 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
4197 if (bed
->want_got_sym
)
4199 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
4200 (or .got.plt) section. We don't do this in the linker script
4201 because we don't want to define the symbol if we are not creating
4202 a global offset table. */
4203 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
, "_GLOBAL_OFFSET_TABLE_");
4204 elf_hash_table (info
)->hgot
= h
;
4208 /* Machine-specific: we want the symbol for executables as
4210 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4214 /* The first bit of the global offset table is the header. */
4215 s
->size
+= bed
->got_header_size
;
4217 /* This is the machine-specific part. Create and initialize section
4218 data for the got. */
4219 if (IS_FDPIC (abfd
))
4221 frvfdpic_got_section (info
) = s
;
4222 frvfdpic_relocs_info (info
) = htab_try_create (1,
4223 frvfdpic_relocs_info_hash
,
4224 frvfdpic_relocs_info_eq
,
4226 if (! frvfdpic_relocs_info (info
))
4229 s
= bfd_make_section_anyway_with_flags (abfd
, ".rel.got",
4230 (flags
| SEC_READONLY
));
4232 || ! bfd_set_section_alignment (abfd
, s
, 2))
4235 frvfdpic_gotrel_section (info
) = s
;
4237 /* Machine-specific. */
4238 s
= bfd_make_section_anyway_with_flags (abfd
, ".rofixup",
4239 (flags
| SEC_READONLY
));
4241 || ! bfd_set_section_alignment (abfd
, s
, 2))
4244 frvfdpic_gotfixup_section (info
) = s
;
4251 flags
= BSF_GLOBAL
| BSF_WEAK
;
4254 /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it
4255 turns out that we're linking with a different linker script, the
4256 linker script will override it. */
4258 if (!(_bfd_generic_link_add_one_symbol
4259 (info
, abfd
, "_gp", flags
, s
, offset
, (const char *) NULL
, FALSE
,
4260 bed
->collect
, &bh
)))
4262 h
= (struct elf_link_hash_entry
*) bh
;
4264 h
->type
= STT_OBJECT
;
4265 /* h->other = STV_HIDDEN; */ /* Should we? */
4267 /* Machine-specific: we want the symbol for executables as well. */
4268 if (IS_FDPIC (abfd
) && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
4271 if (!IS_FDPIC (abfd
))
4274 /* FDPIC supports Thread Local Storage, and this may require a
4275 procedure linkage table for TLS PLT entries. */
4277 /* This is mostly copied from
4278 elflink.c:_bfd_elf_create_dynamic_sections(). */
4281 pltflags
|= SEC_CODE
;
4282 if (bed
->plt_not_loaded
)
4283 pltflags
&= ~ (SEC_CODE
| SEC_LOAD
| SEC_HAS_CONTENTS
);
4284 if (bed
->plt_readonly
)
4285 pltflags
|= SEC_READONLY
;
4287 s
= bfd_make_section_anyway_with_flags (abfd
, ".plt", pltflags
);
4289 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
4291 /* FRV-specific: remember it. */
4292 frvfdpic_plt_section (info
) = s
;
4294 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
4296 if (bed
->want_plt_sym
)
4298 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
4299 "_PROCEDURE_LINKAGE_TABLE_");
4300 elf_hash_table (info
)->hplt
= h
;
4305 /* FRV-specific: we want rel relocations for the plt. */
4306 s
= bfd_make_section_anyway_with_flags (abfd
, ".rel.plt",
4307 flags
| SEC_READONLY
);
4309 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
4311 /* FRV-specific: remember it. */
4312 frvfdpic_pltrel_section (info
) = s
;
4317 /* Make sure the got and plt sections exist, and that our pointers in
4318 the link hash table point to them. */
4321 elf32_frvfdpic_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
4323 /* This is mostly copied from
4324 elflink.c:_bfd_elf_create_dynamic_sections(). */
4327 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4329 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4330 | SEC_LINKER_CREATED
);
4332 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
4333 .rel[a].bss sections. */
4335 /* FRV-specific: we want to create the GOT and the PLT in the FRV
4337 if (! _frv_create_got_section (abfd
, info
))
4340 /* FRV-specific: make sure we created everything we wanted. */
4341 BFD_ASSERT (frvfdpic_got_section (info
) && frvfdpic_gotrel_section (info
)
4342 && frvfdpic_gotfixup_section (info
)
4343 && frvfdpic_plt_section (info
)
4344 && frvfdpic_pltrel_section (info
));
4346 if (bed
->want_dynbss
)
4348 /* The .dynbss section is a place to put symbols which are defined
4349 by dynamic objects, are referenced by regular objects, and are
4350 not functions. We must allocate space for them in the process
4351 image and use a R_*_COPY reloc to tell the dynamic linker to
4352 initialize them at run time. The linker script puts the .dynbss
4353 section into the .bss section of the final image. */
4354 s
= bfd_make_section_anyway_with_flags (abfd
, ".dynbss",
4355 SEC_ALLOC
| SEC_LINKER_CREATED
);
4359 /* The .rel[a].bss section holds copy relocs. This section is not
4360 normally needed. We need to create it here, though, so that the
4361 linker will map it to an output section. We can't just create it
4362 only if we need it, because we will not know whether we need it
4363 until we have seen all the input files, and the first time the
4364 main linker code calls BFD after examining all the input files
4365 (size_dynamic_sections) the input sections have already been
4366 mapped to the output sections. If the section turns out not to
4367 be needed, we can discard it later. We will never need this
4368 section when generating a shared object, since they do not use
4372 s
= bfd_make_section_anyway_with_flags (abfd
,
4373 (bed
->default_use_rela_p
4374 ? ".rela.bss" : ".rel.bss"),
4375 flags
| SEC_READONLY
);
4377 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
4385 /* Compute the total GOT and PLT size required by each symbol in each
4386 range. Symbols may require up to 4 words in the GOT: an entry
4387 pointing to the symbol, an entry pointing to its function
4388 descriptor, and a private function descriptors taking two
4392 _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info
*entry
,
4393 struct _frvfdpic_dynamic_got_info
*dinfo
)
4395 /* Allocate space for a GOT entry pointing to the symbol. */
4398 else if (entry
->gotlos
)
4400 else if (entry
->gothilo
)
4401 dinfo
->gothilo
+= 4;
4406 /* Allocate space for a GOT entry pointing to the function
4410 else if (entry
->fdgotlos
)
4412 else if (entry
->fdgothilo
)
4413 dinfo
->gothilo
+= 4;
4418 /* Decide whether we need a PLT entry, a function descriptor in the
4419 GOT, and a lazy PLT entry for this symbol. */
4420 entry
->plt
= entry
->call
4421 && entry
->symndx
== -1 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4422 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
4423 entry
->privfd
= entry
->plt
4424 || entry
->fdgoff12
|| entry
->fdgofflos
|| entry
->fdgoffhilo
4425 || ((entry
->fd
|| entry
->fdgot12
|| entry
->fdgotlos
|| entry
->fdgothilo
)
4426 && (entry
->symndx
!= -1
4427 || FRVFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
)));
4428 entry
->lazyplt
= entry
->privfd
4429 && entry
->symndx
== -1 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4430 && ! (dinfo
->info
->flags
& DF_BIND_NOW
)
4431 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
4433 /* Allocate space for a function descriptor. */
4434 if (entry
->fdgoff12
)
4436 else if (entry
->fdgofflos
)
4438 else if (entry
->privfd
&& entry
->plt
)
4440 else if (entry
->privfd
)
4450 /* Compute the total GOT size required by each TLS symbol in each
4451 range. Symbols may require up to 5 words in the GOT: an entry
4452 holding the TLS offset for the symbol, and an entry with a full TLS
4453 descriptor taking 4 words. */
4456 _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info
*entry
,
4457 struct _frvfdpic_dynamic_got_info
*dinfo
,
4458 bfd_boolean subtract
)
4460 const int l
= subtract
? -1 : 1;
4462 /* Allocate space for a GOT entry with the TLS offset of the
4464 if (entry
->tlsoff12
)
4465 dinfo
->got12
+= 4 * l
;
4466 else if (entry
->tlsofflos
)
4467 dinfo
->gotlos
+= 4 * l
;
4468 else if (entry
->tlsoffhilo
)
4469 dinfo
->gothilo
+= 4 * l
;
4471 entry
->relocstlsoff
-= l
;
4472 entry
->relocstlsoff
+= l
;
4474 /* If there's any TLSOFF relocation, mark the output file as not
4475 suitable for dlopening. This mark will remain even if we relax
4476 all such relocations, but this is not a problem, since we'll only
4477 do so for executables, and we definitely don't want anyone
4478 dlopening executables. */
4479 if (entry
->relocstlsoff
)
4480 dinfo
->info
->flags
|= DF_STATIC_TLS
;
4482 /* Allocate space for a TLS descriptor. */
4483 if (entry
->tlsdesc12
)
4484 dinfo
->tlsd12
+= 8 * l
;
4485 else if (entry
->tlsdesclos
)
4486 dinfo
->tlsdlos
+= 8 * l
;
4487 else if (entry
->tlsplt
)
4488 dinfo
->tlsdplt
+= 8 * l
;
4489 else if (entry
->tlsdeschilo
)
4490 dinfo
->tlsdhilo
+= 8 * l
;
4492 entry
->relocstlsd
-= l
;
4493 entry
->relocstlsd
+= l
;
4496 /* Compute the number of dynamic relocations and fixups that a symbol
4497 requires, and add (or subtract) from the grand and per-symbol
4501 _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info
*entry
,
4502 struct _frvfdpic_dynamic_got_info
*dinfo
,
4503 bfd_boolean subtract
)
4505 bfd_vma relocs
= 0, fixups
= 0, tlsrets
= 0;
4507 if (!dinfo
->info
->executable
|| dinfo
->info
->pie
)
4509 relocs
= entry
->relocs32
+ entry
->relocsfd
+ entry
->relocsfdv
4510 + entry
->relocstlsd
;
4512 /* In the executable, TLS relocations to symbols that bind
4513 locally (including those that resolve to global TLS offsets)
4514 are resolved immediately, without any need for fixups or
4515 dynamic relocations. In shared libraries, however, we must
4516 emit dynamic relocations even for local symbols, because we
4517 don't know the module id the library is going to get at
4518 run-time, nor its TLS base offset. */
4519 if (!dinfo
->info
->executable
4520 || (entry
->symndx
== -1
4521 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)))
4522 relocs
+= entry
->relocstlsoff
;
4526 if (entry
->symndx
!= -1 || FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
))
4528 if (entry
->symndx
!= -1
4529 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
4530 fixups
+= entry
->relocs32
+ 2 * entry
->relocsfdv
;
4531 fixups
+= entry
->relocstlsd
;
4532 tlsrets
+= entry
->relocstlsd
;
4536 relocs
+= entry
->relocs32
+ entry
->relocsfdv
4537 + entry
->relocstlsoff
+ entry
->relocstlsd
;
4540 if (entry
->symndx
!= -1
4541 || FRVFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
))
4543 if (entry
->symndx
!= -1
4544 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
4545 fixups
+= entry
->relocsfd
;
4548 relocs
+= entry
->relocsfd
;
4555 tlsrets
= - tlsrets
;
4558 entry
->dynrelocs
+= relocs
;
4559 entry
->fixups
+= fixups
;
4560 dinfo
->relocs
+= relocs
;
4561 dinfo
->fixups
+= fixups
;
4562 dinfo
->tls_ret_refs
+= tlsrets
;
4565 /* Look for opportunities to relax TLS relocations. We can assume
4566 we're linking the main executable or a static-tls library, since
4567 otherwise we wouldn't have got here. When relaxing, we have to
4568 first undo any previous accounting of TLS uses of fixups, dynamic
4569 relocations, GOT and PLT entries. */
4572 _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info
*entry
,
4573 struct _frvfdpic_dynamic_got_info
*dinfo
,
4574 bfd_boolean relaxing
)
4576 bfd_boolean changed
= ! relaxing
;
4578 BFD_ASSERT (dinfo
->info
->executable
4579 || (dinfo
->info
->flags
& DF_STATIC_TLS
));
4581 if (entry
->tlsdesc12
|| entry
->tlsdesclos
|| entry
->tlsdeschilo
)
4585 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4586 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4590 /* When linking an executable, we can always decay GOTTLSDESC to
4591 TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise.
4592 When linking a static-tls shared library, using TLSMOFF is
4593 not an option, but we can still use GOTTLSOFF. When decaying
4594 to GOTTLSOFF, we must keep the GOT entry in range. We know
4595 it has to fit because we'll be trading the 4 words of hte TLS
4596 descriptor for a single word in the same range. */
4597 if (! dinfo
->info
->executable
4598 || (entry
->symndx
== -1
4599 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)))
4601 entry
->tlsoff12
|= entry
->tlsdesc12
;
4602 entry
->tlsofflos
|= entry
->tlsdesclos
;
4603 entry
->tlsoffhilo
|= entry
->tlsdeschilo
;
4606 entry
->tlsdesc12
= entry
->tlsdesclos
= entry
->tlsdeschilo
= 0;
4609 /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the
4610 main executable. We have to check whether the symbol's TLSOFF is
4611 in range for a setlos. For symbols with a hash entry, we can
4612 determine exactly what to do; for others locals, we don't have
4613 addresses handy, so we use the size of the TLS section as an
4614 approximation. If we get it wrong, we'll retain a GOT entry
4615 holding the TLS offset (without dynamic relocations or fixups),
4616 but we'll still optimize away the loads from it. Since TLS sizes
4617 are generally very small, it's probably not worth attempting to
4618 do better than this. */
4620 || entry
->tlsoff12
|| entry
->tlsofflos
|| entry
->tlsoffhilo
)
4621 && dinfo
->info
->executable
&& relaxing
4622 && ((entry
->symndx
== -1
4623 && FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4624 /* The above may hold for an undefweak TLS symbol, so make
4625 sure we don't have this case before accessing def.value
4627 && (entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
4628 || (bfd_vma
)(entry
->d
.h
->root
.u
.def
.value
4629 + (entry
->d
.h
->root
.u
.def
.section
4630 ->output_section
->vma
)
4631 + entry
->d
.h
->root
.u
.def
.section
->output_offset
4633 - tls_biased_base (dinfo
->info
)
4634 + 32768) < (bfd_vma
)65536))
4635 || (entry
->symndx
!= -1
4636 && (elf_hash_table (dinfo
->info
)->tls_sec
->size
4637 + abs (entry
->addend
) < 32768 + FRVFDPIC_TLS_BIAS
))))
4641 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4642 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4647 entry
->tlsoff12
= entry
->tlsofflos
= entry
->tlsoffhilo
= 0;
4650 /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already
4651 have a #gottlsoff12 relocation for this entry, or if we can fit
4652 one more in the 12-bit (and 16-bit) ranges. */
4656 && dinfo
->got12
+ dinfo
->fd12
+ dinfo
->tlsd12
<= 4096 - 12 - 4
4657 && (dinfo
->got12
+ dinfo
->fd12
+ dinfo
->tlsd12
4658 + dinfo
->gotlos
+ dinfo
->fdlos
+ dinfo
->tlsdlos
4659 <= 65536 - 12 - 4))))
4663 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4664 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4668 entry
->tlsoff12
= 1;
4674 _frvfdpic_count_tls_entries (entry
, dinfo
, FALSE
);
4675 _frvfdpic_count_relocs_fixups (entry
, dinfo
, FALSE
);
4681 /* Compute the total GOT and PLT size required by each symbol in each range. *
4682 Symbols may require up to 4 words in the GOT: an entry pointing to
4683 the symbol, an entry pointing to its function descriptor, and a
4684 private function descriptors taking two words. */
4687 _frvfdpic_count_got_plt_entries (void **entryp
, void *dinfo_
)
4689 struct frvfdpic_relocs_info
*entry
= *entryp
;
4690 struct _frvfdpic_dynamic_got_info
*dinfo
= dinfo_
;
4692 _frvfdpic_count_nontls_entries (entry
, dinfo
);
4694 if (dinfo
->info
->executable
|| (dinfo
->info
->flags
& DF_STATIC_TLS
))
4695 _frvfdpic_relax_tls_entries (entry
, dinfo
, FALSE
);
4698 _frvfdpic_count_tls_entries (entry
, dinfo
, FALSE
);
4699 _frvfdpic_count_relocs_fixups (entry
, dinfo
, FALSE
);
4705 /* Determine the positive and negative ranges to be used by each
4706 offset range in the GOT. FDCUR and CUR, that must be aligned to a
4707 double-word boundary, are the minimum (negative) and maximum
4708 (positive) GOT offsets already used by previous ranges, except for
4709 an ODD entry that may have been left behind. GOT and FD indicate
4710 the size of GOT entries and function descriptors that must be
4711 placed within the range from -WRAP to WRAP. If there's room left,
4712 up to FDPLT bytes should be reserved for additional function
4715 inline static bfd_signed_vma
4716 _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data
*gad
,
4717 bfd_signed_vma fdcur
,
4727 bfd_signed_vma wrapmin
= -wrap
;
4728 const bfd_vma tdescsz
= 8;
4730 /* Start at the given initial points. */
4734 /* If we had an incoming odd word and we have any got entries that
4735 are going to use it, consume it, otherwise leave gad->odd at
4736 zero. We might force gad->odd to zero and return the incoming
4737 odd such that it is used by the next range, but then GOT entries
4738 might appear to be out of order and we wouldn't be able to
4739 shorten the GOT by one word if it turns out to end with an
4740 unpaired GOT entry. */
4750 /* If we're left with an unpaired GOT entry, compute its location
4751 such that we can return it. Otherwise, if got doesn't require an
4752 odd number of words here, either odd was already zero in the
4753 block above, or it was set to zero because got was non-zero, or
4754 got was already zero. In the latter case, we want the value of
4755 odd to carry over to the return statement, so we don't want to
4756 reset odd unless the condition below is true. */
4763 /* Compute the tentative boundaries of this range. */
4764 gad
->max
= cur
+ got
;
4765 gad
->min
= fdcur
- fd
;
4768 /* If function descriptors took too much space, wrap some of them
4770 if (gad
->min
< wrapmin
)
4772 gad
->max
+= wrapmin
- gad
->min
;
4773 gad
->tmin
= gad
->min
= wrapmin
;
4776 /* If GOT entries took too much space, wrap some of them around.
4777 This may well cause gad->min to become lower than wrapmin. This
4778 will cause a relocation overflow later on, so we don't have to
4780 if ((bfd_vma
) gad
->max
> wrap
)
4782 gad
->min
-= gad
->max
- wrap
;
4786 /* Add TLS descriptors. */
4787 gad
->tmax
= gad
->max
+ tlsd
;
4788 gad
->tmin
= gad
->min
;
4791 /* If TLS descriptors took too much space, wrap an integral number
4793 if ((bfd_vma
) gad
->tmax
> wrap
)
4795 bfd_vma wrapsize
= gad
->tmax
- wrap
;
4797 wrapsize
+= tdescsz
/ 2;
4798 wrapsize
&= ~ tdescsz
/ 2;
4800 gad
->tmin
-= wrapsize
;
4801 gad
->tmax
-= wrapsize
;
4804 /* If there is space left and we have function descriptors
4805 referenced in PLT entries that could take advantage of shorter
4806 offsets, place them now. */
4807 if (fdplt
&& gad
->tmin
> wrapmin
)
4811 if ((bfd_vma
) (gad
->tmin
- wrapmin
) < fdplt
)
4812 fds
= gad
->tmin
- wrapmin
;
4822 /* If there is more space left, try to place some more function
4823 descriptors for PLT entries. */
4824 if (fdplt
&& (bfd_vma
) gad
->tmax
< wrap
)
4828 if ((bfd_vma
) (wrap
- gad
->tmax
) < fdplt
)
4829 fds
= wrap
- gad
->tmax
;
4839 /* If there is space left and we have TLS descriptors referenced in
4840 PLT entries that could take advantage of shorter offsets, place
4842 if (tlsdplt
&& gad
->tmin
> wrapmin
)
4846 if ((bfd_vma
) (gad
->tmin
- wrapmin
) < tlsdplt
)
4847 tlsds
= (gad
->tmin
- wrapmin
) & ~ (tdescsz
/ 2);
4853 gad
->tlsdplt
+= tlsds
;
4856 /* If there is more space left, try to place some more TLS
4857 descriptors for PLT entries. Although we could try to fit an
4858 additional TLS descriptor with half of it just before before the
4859 wrap point and another right past the wrap point, this might
4860 cause us to run out of space for the next region, so don't do
4862 if (tlsdplt
&& (bfd_vma
) gad
->tmax
< wrap
- tdescsz
/ 2)
4866 if ((bfd_vma
) (wrap
- gad
->tmax
) < tlsdplt
)
4867 tlsds
= (wrap
- gad
->tmax
) & ~ (tdescsz
/ 2);
4873 gad
->tlsdplt
+= tlsds
;
4876 /* If odd was initially computed as an offset past the wrap point,
4879 odd
= gad
->min
+ odd
- gad
->max
;
4881 /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed
4882 before returning, so do it here too. This guarantees that,
4883 should cur and fdcur meet at the wrap point, they'll both be
4885 if (gad
->cur
== gad
->max
)
4886 gad
->cur
= gad
->min
;
4888 /* Ditto for _frvfdpic_get_tlsdesc_entry(). */
4889 gad
->tcur
= gad
->max
;
4890 if (gad
->tcur
== gad
->tmax
)
4891 gad
->tcur
= gad
->tmin
;
4896 /* Compute the location of the next GOT entry, given the allocation
4897 data for a range. */
4899 inline static bfd_signed_vma
4900 _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
4906 /* If there was an odd word left behind, use it. */
4912 /* Otherwise, use the word pointed to by cur, reserve the next
4913 as an odd word, and skip to the next pair of words, possibly
4916 gad
->odd
= gad
->cur
+ 4;
4918 if (gad
->cur
== gad
->max
)
4919 gad
->cur
= gad
->min
;
4925 /* Compute the location of the next function descriptor entry in the
4926 GOT, given the allocation data for a range. */
4928 inline static bfd_signed_vma
4929 _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
4931 /* If we're at the bottom, wrap around, and only then allocate the
4932 next pair of words. */
4933 if (gad
->fdcur
== gad
->min
)
4934 gad
->fdcur
= gad
->max
;
4935 return gad
->fdcur
-= 8;
4938 /* Compute the location of the next TLS descriptor entry in the GOT,
4939 given the allocation data for a range. */
4940 inline static bfd_signed_vma
4941 _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
4949 /* If we're at the top of the region, wrap around to the bottom. */
4950 if (gad
->tcur
== gad
->tmax
)
4951 gad
->tcur
= gad
->tmin
;
4956 /* Assign GOT offsets for every GOT entry and function descriptor.
4957 Doing everything in a single pass is tricky. */
4960 _frvfdpic_assign_got_entries (void **entryp
, void *info_
)
4962 struct frvfdpic_relocs_info
*entry
= *entryp
;
4963 struct _frvfdpic_dynamic_got_plt_info
*dinfo
= info_
;
4966 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
4967 else if (entry
->gotlos
)
4968 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
4969 else if (entry
->gothilo
)
4970 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
4973 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
4974 else if (entry
->fdgotlos
)
4975 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
4976 else if (entry
->fdgothilo
)
4977 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
4979 if (entry
->fdgoff12
)
4980 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->got12
);
4981 else if (entry
->plt
&& dinfo
->got12
.fdplt
)
4983 dinfo
->got12
.fdplt
-= 8;
4984 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->got12
);
4986 else if (entry
->fdgofflos
)
4987 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gotlos
);
4988 else if (entry
->plt
&& dinfo
->gotlos
.fdplt
)
4990 dinfo
->gotlos
.fdplt
-= 8;
4991 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gotlos
);
4993 else if (entry
->plt
)
4995 dinfo
->gothilo
.fdplt
-= 8;
4996 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gothilo
);
4998 else if (entry
->privfd
)
4999 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gothilo
);
5001 if (entry
->tlsoff12
)
5002 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5003 else if (entry
->tlsofflos
)
5004 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5005 else if (entry
->tlsoffhilo
)
5006 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5008 if (entry
->tlsdesc12
)
5009 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->got12
);
5010 else if (entry
->tlsplt
&& dinfo
->got12
.tlsdplt
)
5012 dinfo
->got12
.tlsdplt
-= 8;
5013 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->got12
);
5015 else if (entry
->tlsdesclos
)
5016 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gotlos
);
5017 else if (entry
->tlsplt
&& dinfo
->gotlos
.tlsdplt
)
5019 dinfo
->gotlos
.tlsdplt
-= 8;
5020 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gotlos
);
5022 else if (entry
->tlsplt
)
5024 dinfo
->gothilo
.tlsdplt
-= 8;
5025 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gothilo
);
5027 else if (entry
->tlsdeschilo
)
5028 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gothilo
);
5033 /* Assign GOT offsets to private function descriptors used by PLT
5034 entries (or referenced by 32-bit offsets), as well as PLT entries
5035 and lazy PLT entries. */
5038 _frvfdpic_assign_plt_entries (void **entryp
, void *info_
)
5040 struct frvfdpic_relocs_info
*entry
= *entryp
;
5041 struct _frvfdpic_dynamic_got_plt_info
*dinfo
= info_
;
5044 BFD_ASSERT (entry
->fd_entry
);
5050 /* We use the section's raw size to mark the location of the
5052 entry
->plt_entry
= frvfdpic_plt_section (dinfo
->g
.info
)->size
;
5054 /* Figure out the length of this PLT entry based on the
5055 addressing mode we need to reach the function descriptor. */
5056 BFD_ASSERT (entry
->fd_entry
);
5057 if (entry
->fd_entry
>= -(1 << (12 - 1))
5058 && entry
->fd_entry
< (1 << (12 - 1)))
5060 else if (entry
->fd_entry
>= -(1 << (16 - 1))
5061 && entry
->fd_entry
< (1 << (16 - 1)))
5066 frvfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
5071 entry
->lzplt_entry
= dinfo
->g
.lzplt
;
5072 dinfo
->g
.lzplt
+= 8;
5073 /* If this entry is the one that gets the resolver stub, account
5074 for the additional instruction. */
5075 if (entry
->lzplt_entry
% FRVFDPIC_LZPLT_BLOCK_SIZE
5076 == FRVFDPIC_LZPLT_RESOLV_LOC
)
5077 dinfo
->g
.lzplt
+= 4;
5085 = frvfdpic_plt_section (dinfo
->g
.info
)->size
;
5087 if (dinfo
->g
.info
->executable
5088 && (entry
->symndx
!= -1
5089 || FRVFDPIC_SYM_LOCAL (dinfo
->g
.info
, entry
->d
.h
)))
5091 if ((bfd_signed_vma
)entry
->addend
>= -(1 << (16 - 1))
5092 /* FIXME: here we use the size of the TLS section
5093 as an upper bound for the value of the TLS
5094 symbol, because we may not know the exact value
5095 yet. If we get it wrong, we'll just waste a
5096 word in the PLT, and we should never get even
5097 close to 32 KiB of TLS anyway. */
5098 && elf_hash_table (dinfo
->g
.info
)->tls_sec
5099 && (elf_hash_table (dinfo
->g
.info
)->tls_sec
->size
5100 + (bfd_signed_vma
)(entry
->addend
) <= (1 << (16 - 1))))
5105 else if (entry
->tlsoff_entry
)
5107 if (entry
->tlsoff_entry
>= -(1 << (12 - 1))
5108 && entry
->tlsoff_entry
< (1 << (12 - 1)))
5110 else if (entry
->tlsoff_entry
>= -(1 << (16 - 1))
5111 && entry
->tlsoff_entry
< (1 << (16 - 1)))
5118 BFD_ASSERT (entry
->tlsdesc_entry
);
5120 if (entry
->tlsdesc_entry
>= -(1 << (12 - 1))
5121 && entry
->tlsdesc_entry
< (1 << (12 - 1)))
5123 else if (entry
->tlsdesc_entry
>= -(1 << (16 - 1))
5124 && entry
->tlsdesc_entry
< (1 << (16 - 1)))
5130 frvfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
5136 /* Cancel out any effects of calling _frvfdpic_assign_got_entries and
5137 _frvfdpic_assign_plt_entries. */
5140 _frvfdpic_reset_got_plt_entries (void **entryp
, void *ignore ATTRIBUTE_UNUSED
)
5142 struct frvfdpic_relocs_info
*entry
= *entryp
;
5144 entry
->got_entry
= 0;
5145 entry
->fdgot_entry
= 0;
5146 entry
->fd_entry
= 0;
5147 entry
->plt_entry
= (bfd_vma
)-1;
5148 entry
->lzplt_entry
= (bfd_vma
)-1;
5149 entry
->tlsoff_entry
= 0;
5150 entry
->tlsdesc_entry
= 0;
5151 entry
->tlsplt_entry
= (bfd_vma
)-1;
5156 /* Follow indirect and warning hash entries so that each got entry
5157 points to the final symbol definition. P must point to a pointer
5158 to the hash table we're traversing. Since this traversal may
5159 modify the hash table, we set this pointer to NULL to indicate
5160 we've made a potentially-destructive change to the hash table, so
5161 the traversal must be restarted. */
5163 _frvfdpic_resolve_final_relocs_info (void **entryp
, void *p
)
5165 struct frvfdpic_relocs_info
*entry
= *entryp
;
5168 if (entry
->symndx
== -1)
5170 struct elf_link_hash_entry
*h
= entry
->d
.h
;
5171 struct frvfdpic_relocs_info
*oentry
;
5173 while (h
->root
.type
== bfd_link_hash_indirect
5174 || h
->root
.type
== bfd_link_hash_warning
)
5175 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
5177 if (entry
->d
.h
== h
)
5180 oentry
= frvfdpic_relocs_info_for_global (*htab
, 0, h
, entry
->addend
,
5185 /* Merge the two entries. */
5186 frvfdpic_pic_merge_early_relocs_info (oentry
, entry
);
5187 htab_clear_slot (*htab
, entryp
);
5193 /* If we can't find this entry with the new bfd hash, re-insert
5194 it, and get the traversal restarted. */
5195 if (! htab_find (*htab
, entry
))
5197 htab_clear_slot (*htab
, entryp
);
5198 entryp
= htab_find_slot (*htab
, entry
, INSERT
);
5201 /* Abort the traversal, since the whole table may have
5202 moved, and leave it up to the parent to restart the
5204 *(htab_t
*)p
= NULL
;
5212 /* Compute the total size of the GOT, the PLT, the dynamic relocations
5213 section and the rofixup section. Assign locations for GOT and PLT
5217 _frvfdpic_size_got_plt (bfd
*output_bfd
,
5218 struct _frvfdpic_dynamic_got_plt_info
*gpinfop
)
5221 bfd_vma limit
, tlslimit
;
5222 struct bfd_link_info
*info
= gpinfop
->g
.info
;
5223 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
5225 memcpy (frvfdpic_dynamic_got_plt_info (info
), &gpinfop
->g
,
5226 sizeof (gpinfop
->g
));
5229 /* Compute the total size taken by entries in the 12-bit and 16-bit
5230 ranges, to tell how many PLT function descriptors we can bring
5231 into the 12-bit range without causing the 16-bit range to
5233 limit
= odd
+ gpinfop
->g
.got12
+ gpinfop
->g
.gotlos
5234 + gpinfop
->g
.fd12
+ gpinfop
->g
.fdlos
5235 + gpinfop
->g
.tlsd12
+ gpinfop
->g
.tlsdlos
;
5236 if (limit
< (bfd_vma
)1 << 16)
5237 limit
= ((bfd_vma
)1 << 16) - limit
;
5240 if (gpinfop
->g
.fdplt
< limit
)
5242 tlslimit
= (limit
- gpinfop
->g
.fdplt
) & ~ (bfd_vma
) 8;
5243 limit
= gpinfop
->g
.fdplt
;
5247 if (gpinfop
->g
.tlsdplt
< tlslimit
)
5248 tlslimit
= gpinfop
->g
.tlsdplt
;
5250 /* Determine the ranges of GOT offsets that we can use for each
5251 range of addressing modes. */
5252 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->got12
,
5261 (bfd_vma
)1 << (12-1));
5262 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->gotlos
,
5263 gpinfop
->got12
.tmin
,
5265 gpinfop
->got12
.tmax
,
5269 - gpinfop
->got12
.fdplt
,
5272 - gpinfop
->got12
.tlsdplt
,
5273 (bfd_vma
)1 << (16-1));
5274 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->gothilo
,
5275 gpinfop
->gotlos
.tmin
,
5277 gpinfop
->gotlos
.tmax
,
5281 - gpinfop
->got12
.fdplt
5282 - gpinfop
->gotlos
.fdplt
,
5283 gpinfop
->g
.tlsdhilo
,
5285 - gpinfop
->got12
.tlsdplt
5286 - gpinfop
->gotlos
.tlsdplt
,
5287 (bfd_vma
)1 << (32-1));
5289 /* Now assign (most) GOT offsets. */
5290 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_assign_got_entries
,
5293 frvfdpic_got_section (info
)->size
= gpinfop
->gothilo
.tmax
5294 - gpinfop
->gothilo
.tmin
5295 /* If an odd word is the last word of the GOT, we don't need this
5296 word to be part of the GOT. */
5297 - (odd
+ 4 == gpinfop
->gothilo
.tmax
? 4 : 0);
5298 if (frvfdpic_got_section (info
)->size
== 0)
5299 frvfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
5300 else if (frvfdpic_got_section (info
)->size
== 12
5301 && ! elf_hash_table (info
)->dynamic_sections_created
)
5303 frvfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
5304 frvfdpic_got_section (info
)->size
= 0;
5306 /* This will be non-NULL during relaxation. The assumption is that
5307 the size of one of these sections will never grow, only shrink,
5308 so we can use the larger buffer we allocated before. */
5309 else if (frvfdpic_got_section (info
)->contents
== NULL
)
5311 frvfdpic_got_section (info
)->contents
=
5312 (bfd_byte
*) bfd_zalloc (dynobj
,
5313 frvfdpic_got_section (info
)->size
);
5314 if (frvfdpic_got_section (info
)->contents
== NULL
)
5318 if (frvfdpic_gotrel_section (info
))
5319 /* Subtract the number of lzplt entries, since those will generate
5320 relocations in the pltrel section. */
5321 frvfdpic_gotrel_section (info
)->size
=
5322 (gpinfop
->g
.relocs
- gpinfop
->g
.lzplt
/ 8)
5323 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
5325 BFD_ASSERT (gpinfop
->g
.relocs
== 0);
5326 if (frvfdpic_gotrel_section (info
)->size
== 0)
5327 frvfdpic_gotrel_section (info
)->flags
|= SEC_EXCLUDE
;
5328 else if (frvfdpic_gotrel_section (info
)->contents
== NULL
)
5330 frvfdpic_gotrel_section (info
)->contents
=
5331 (bfd_byte
*) bfd_zalloc (dynobj
,
5332 frvfdpic_gotrel_section (info
)->size
);
5333 if (frvfdpic_gotrel_section (info
)->contents
== NULL
)
5337 frvfdpic_gotfixup_section (info
)->size
= (gpinfop
->g
.fixups
+ 1) * 4;
5338 if (frvfdpic_gotfixup_section (info
)->size
== 0)
5339 frvfdpic_gotfixup_section (info
)->flags
|= SEC_EXCLUDE
;
5340 else if (frvfdpic_gotfixup_section (info
)->contents
== NULL
)
5342 frvfdpic_gotfixup_section (info
)->contents
=
5343 (bfd_byte
*) bfd_zalloc (dynobj
,
5344 frvfdpic_gotfixup_section (info
)->size
);
5345 if (frvfdpic_gotfixup_section (info
)->contents
== NULL
)
5349 if (frvfdpic_pltrel_section (info
))
5351 frvfdpic_pltrel_section (info
)->size
=
5352 gpinfop
->g
.lzplt
/ 8
5353 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
5354 if (frvfdpic_pltrel_section (info
)->size
== 0)
5355 frvfdpic_pltrel_section (info
)->flags
|= SEC_EXCLUDE
;
5356 else if (frvfdpic_pltrel_section (info
)->contents
== NULL
)
5358 frvfdpic_pltrel_section (info
)->contents
=
5359 (bfd_byte
*) bfd_zalloc (dynobj
,
5360 frvfdpic_pltrel_section (info
)->size
);
5361 if (frvfdpic_pltrel_section (info
)->contents
== NULL
)
5366 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
5367 such that there's room for the additional instruction needed to
5368 call the resolver. Since _frvfdpic_assign_got_entries didn't
5369 account for them, our block size is 4 bytes smaller than the real
5371 if (frvfdpic_plt_section (info
))
5373 frvfdpic_plt_section (info
)->size
= gpinfop
->g
.lzplt
5374 + ((gpinfop
->g
.lzplt
+ (FRVFDPIC_LZPLT_BLOCK_SIZE
- 4) - 8)
5375 / (FRVFDPIC_LZPLT_BLOCK_SIZE
- 4) * 4);
5378 /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to
5379 actually assign lazy PLT entries addresses. */
5380 gpinfop
->g
.lzplt
= 0;
5382 /* Save information that we're going to need to generate GOT and PLT
5384 frvfdpic_got_initial_offset (info
) = -gpinfop
->gothilo
.tmin
;
5386 if (get_elf_backend_data (output_bfd
)->want_got_sym
)
5387 elf_hash_table (info
)->hgot
->root
.u
.def
.value
5388 = frvfdpic_got_initial_offset (info
);
5390 if (frvfdpic_plt_section (info
))
5391 frvfdpic_plt_initial_offset (info
) =
5392 frvfdpic_plt_section (info
)->size
;
5394 /* Allocate a ret statement at plt_initial_offset, to be used by
5395 locally-resolved TLS descriptors. */
5396 if (gpinfop
->g
.tls_ret_refs
)
5397 frvfdpic_plt_section (info
)->size
+= 4;
5399 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_assign_plt_entries
,
5402 /* Allocate the PLT section contents only after
5403 _frvfdpic_assign_plt_entries has a chance to add the size of the
5404 non-lazy PLT entries. */
5405 if (frvfdpic_plt_section (info
))
5407 if (frvfdpic_plt_section (info
)->size
== 0)
5408 frvfdpic_plt_section (info
)->flags
|= SEC_EXCLUDE
;
5409 else if (frvfdpic_plt_section (info
)->contents
== NULL
)
5411 frvfdpic_plt_section (info
)->contents
=
5412 (bfd_byte
*) bfd_zalloc (dynobj
,
5413 frvfdpic_plt_section (info
)->size
);
5414 if (frvfdpic_plt_section (info
)->contents
== NULL
)
5422 /* Set the sizes of the dynamic sections. */
5425 elf32_frvfdpic_size_dynamic_sections (bfd
*output_bfd
,
5426 struct bfd_link_info
*info
)
5430 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5432 dynobj
= elf_hash_table (info
)->dynobj
;
5433 BFD_ASSERT (dynobj
!= NULL
);
5435 if (elf_hash_table (info
)->dynamic_sections_created
)
5437 /* Set the contents of the .interp section to the interpreter. */
5438 if (info
->executable
)
5440 s
= bfd_get_linker_section (dynobj
, ".interp");
5441 BFD_ASSERT (s
!= NULL
);
5442 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5443 s
->contents
= (bfd_byte
*) ELF_DYNAMIC_INTERPRETER
;
5447 memset (&gpinfo
, 0, sizeof (gpinfo
));
5448 gpinfo
.g
.info
= info
;
5452 htab_t relocs
= frvfdpic_relocs_info (info
);
5454 htab_traverse (relocs
, _frvfdpic_resolve_final_relocs_info
, &relocs
);
5456 if (relocs
== frvfdpic_relocs_info (info
))
5460 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_count_got_plt_entries
,
5463 /* Allocate space to save the summary information, we're going to
5464 use it if we're doing relaxations. */
5465 frvfdpic_dynamic_got_plt_info (info
) = bfd_alloc (dynobj
, sizeof (gpinfo
.g
));
5467 if (!_frvfdpic_size_got_plt (output_bfd
, &gpinfo
))
5470 if (elf_hash_table (info
)->dynamic_sections_created
)
5472 if (frvfdpic_got_section (info
)->size
)
5473 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTGOT
, 0))
5476 if (frvfdpic_pltrel_section (info
)->size
)
5477 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
5478 || !_bfd_elf_add_dynamic_entry (info
, DT_PLTREL
, DT_REL
)
5479 || !_bfd_elf_add_dynamic_entry (info
, DT_JMPREL
, 0))
5482 if (frvfdpic_gotrel_section (info
)->size
)
5483 if (!_bfd_elf_add_dynamic_entry (info
, DT_REL
, 0)
5484 || !_bfd_elf_add_dynamic_entry (info
, DT_RELSZ
, 0)
5485 || !_bfd_elf_add_dynamic_entry (info
, DT_RELENT
,
5486 sizeof (Elf32_External_Rel
)))
5494 elf32_frvfdpic_always_size_sections (bfd
*output_bfd
,
5495 struct bfd_link_info
*info
)
5497 if (!info
->relocatable
5498 && !bfd_elf_stack_segment_size (output_bfd
, info
,
5499 "__stacksize", DEFAULT_STACK_SIZE
))
5505 /* Check whether any of the relocations was optimized away, and
5506 subtract it from the relocation or fixup count. */
5508 _frvfdpic_check_discarded_relocs (bfd
*abfd
, asection
*sec
,
5509 struct bfd_link_info
*info
,
5511 bfd_boolean
*changed
)
5513 Elf_Internal_Shdr
*symtab_hdr
;
5514 struct elf_link_hash_entry
**sym_hashes
;
5515 Elf_Internal_Rela
*rel
, *erel
;
5517 if ((sec
->flags
& SEC_RELOC
) == 0
5518 || sec
->reloc_count
== 0)
5521 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5522 sym_hashes
= elf_sym_hashes (abfd
);
5524 rel
= elf_section_data (sec
)->relocs
;
5526 /* Now examine each relocation. */
5527 for (erel
= rel
+ sec
->reloc_count
; rel
< erel
; rel
++)
5529 struct elf_link_hash_entry
*h
;
5530 unsigned long r_symndx
;
5531 struct frvfdpic_relocs_info
*picrel
;
5532 struct _frvfdpic_dynamic_got_info
*dinfo
;
5534 if (ELF32_R_TYPE (rel
->r_info
) != R_FRV_32
5535 && ELF32_R_TYPE (rel
->r_info
) != R_FRV_FUNCDESC
)
5538 if (_bfd_elf_section_offset (sec
->output_section
->owner
,
5539 info
, sec
, rel
->r_offset
)
5543 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5544 if (r_symndx
< symtab_hdr
->sh_info
)
5548 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5549 while (h
->root
.type
== bfd_link_hash_indirect
5550 || h
->root
.type
== bfd_link_hash_warning
)
5551 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
5555 picrel
= frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info
),
5557 rel
->r_addend
, NO_INSERT
);
5559 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info (info
),
5561 rel
->r_addend
, NO_INSERT
);
5567 dinfo
= frvfdpic_dynamic_got_plt_info (info
);
5569 _frvfdpic_count_relocs_fixups (picrel
, dinfo
, TRUE
);
5570 if (ELF32_R_TYPE (rel
->r_info
) == R_FRV_32
)
5572 else /* we know (ELF32_R_TYPE (rel->r_info) == R_FRV_FUNCDESC) */
5574 _frvfdpic_count_relocs_fixups (picrel
, dinfo
, FALSE
);
5581 frvfdpic_elf_discard_info (bfd
*ibfd
,
5582 struct elf_reloc_cookie
*cookie ATTRIBUTE_UNUSED
,
5583 struct bfd_link_info
*info
)
5585 bfd_boolean changed
= FALSE
;
5589 /* Account for relaxation of .eh_frame section. */
5590 for (s
= ibfd
->sections
; s
; s
= s
->next
)
5591 if (s
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
5593 if (!_frvfdpic_check_discarded_relocs (ibfd
, s
, info
, &changed
))
5595 obfd
= s
->output_section
->owner
;
5600 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5602 memset (&gpinfo
, 0, sizeof (gpinfo
));
5603 memcpy (&gpinfo
.g
, frvfdpic_dynamic_got_plt_info (info
),
5606 /* Clear GOT and PLT assignments. */
5607 htab_traverse (frvfdpic_relocs_info (info
),
5608 _frvfdpic_reset_got_plt_entries
,
5611 if (!_frvfdpic_size_got_plt (obfd
, &gpinfo
))
5618 /* Look for opportunities to relax TLS relocations. We can assume
5619 we're linking the main executable or a static-tls library, since
5620 otherwise we wouldn't have got here. */
5623 _frvfdpic_relax_got_plt_entries (void **entryp
, void *dinfo_
)
5625 struct frvfdpic_relocs_info
*entry
= *entryp
;
5626 struct _frvfdpic_dynamic_got_info
*dinfo
= dinfo_
;
5628 _frvfdpic_relax_tls_entries (entry
, dinfo
, TRUE
);
5634 elf32_frvfdpic_relax_section (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
,
5635 struct bfd_link_info
*info
, bfd_boolean
*again
)
5637 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5639 if (info
->relocatable
)
5640 (*info
->callbacks
->einfo
)
5641 (_("%P%F: --relax and -r may not be used together\n"));
5643 /* If we return early, we didn't change anything. */
5646 /* We'll do our thing when requested to relax the GOT section. */
5647 if (sec
!= frvfdpic_got_section (info
))
5650 /* We can only relax when linking the main executable or a library
5651 that can't be dlopened. */
5652 if (! info
->executable
&& ! (info
->flags
& DF_STATIC_TLS
))
5655 /* If there isn't a TLS section for this binary, we can't do
5656 anything about its TLS relocations (it probably doesn't have
5658 if (elf_hash_table (info
)->tls_sec
== NULL
)
5661 memset (&gpinfo
, 0, sizeof (gpinfo
));
5662 memcpy (&gpinfo
.g
, frvfdpic_dynamic_got_plt_info (info
), sizeof (gpinfo
.g
));
5664 /* Now look for opportunities to relax, adjusting the GOT usage
5666 htab_traverse (frvfdpic_relocs_info (info
),
5667 _frvfdpic_relax_got_plt_entries
,
5670 /* If we changed anything, reset and re-assign GOT and PLT entries. */
5671 if (memcmp (frvfdpic_dynamic_got_plt_info (info
),
5672 &gpinfo
.g
, sizeof (gpinfo
.g
)) != 0)
5674 /* Clear GOT and PLT assignments. */
5675 htab_traverse (frvfdpic_relocs_info (info
),
5676 _frvfdpic_reset_got_plt_entries
,
5679 /* The owner of the TLS section is the output bfd. There should
5680 be a better way to get to it. */
5681 if (!_frvfdpic_size_got_plt (elf_hash_table (info
)->tls_sec
->owner
,
5685 /* Repeat until we don't make any further changes. We could fail to
5686 introduce changes in a round if, for example, the 12-bit range is
5687 full, but we later release some space by getting rid of TLS
5688 descriptors in it. We have to repeat the whole process because
5689 we might have changed the size of a section processed before this
5697 /* Fill in code and data in dynamic sections. */
5700 elf32_frv_finish_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5701 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
5703 /* Nothing to be done for non-FDPIC. */
5708 elf32_frvfdpic_finish_dynamic_sections (bfd
*output_bfd
,
5709 struct bfd_link_info
*info
)
5714 dynobj
= elf_hash_table (info
)->dynobj
;
5716 if (frvfdpic_dynamic_got_plt_info (info
))
5718 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
== 0);
5720 if (frvfdpic_got_section (info
))
5722 BFD_ASSERT (frvfdpic_gotrel_section (info
)->size
5723 == (frvfdpic_gotrel_section (info
)->reloc_count
5724 * sizeof (Elf32_External_Rel
)));
5726 if (frvfdpic_gotfixup_section (info
))
5728 struct elf_link_hash_entry
*hgot
= elf_hash_table (info
)->hgot
;
5729 bfd_vma got_value
= hgot
->root
.u
.def
.value
5730 + hgot
->root
.u
.def
.section
->output_section
->vma
5731 + hgot
->root
.u
.def
.section
->output_offset
;
5732 struct bfd_link_hash_entry
*hend
;
5734 _frvfdpic_add_rofixup (output_bfd
, frvfdpic_gotfixup_section (info
),
5737 if (frvfdpic_gotfixup_section (info
)->size
5738 != (frvfdpic_gotfixup_section (info
)->reloc_count
* 4))
5741 info
->callbacks
->einfo
5742 ("LINKER BUG: .rofixup section size mismatch\n");
5746 hend
= bfd_link_hash_lookup (info
->hash
, "__ROFIXUP_END__",
5747 FALSE
, FALSE
, TRUE
);
5749 && (hend
->type
== bfd_link_hash_defined
5750 || hend
->type
== bfd_link_hash_defweak
)
5751 && hend
->u
.def
.section
->output_section
!= NULL
)
5754 frvfdpic_gotfixup_section (info
)->output_section
->vma
5755 + frvfdpic_gotfixup_section (info
)->output_offset
5756 + frvfdpic_gotfixup_section (info
)->size
5757 - hend
->u
.def
.section
->output_section
->vma
5758 - hend
->u
.def
.section
->output_offset
;
5759 BFD_ASSERT (hend
->u
.def
.value
== value
);
5760 if (hend
->u
.def
.value
!= value
)
5765 if (frvfdpic_pltrel_section (info
))
5767 BFD_ASSERT (frvfdpic_pltrel_section (info
)->size
5768 == (frvfdpic_pltrel_section (info
)->reloc_count
5769 * sizeof (Elf32_External_Rel
)));
5773 if (elf_hash_table (info
)->dynamic_sections_created
)
5775 Elf32_External_Dyn
* dyncon
;
5776 Elf32_External_Dyn
* dynconend
;
5778 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
5780 BFD_ASSERT (sdyn
!= NULL
);
5782 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5783 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5785 for (; dyncon
< dynconend
; dyncon
++)
5787 Elf_Internal_Dyn dyn
;
5789 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5797 dyn
.d_un
.d_ptr
= frvfdpic_got_section (info
)->output_section
->vma
5798 + frvfdpic_got_section (info
)->output_offset
5799 + frvfdpic_got_initial_offset (info
);
5800 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5804 dyn
.d_un
.d_ptr
= frvfdpic_pltrel_section (info
)
5805 ->output_section
->vma
5806 + frvfdpic_pltrel_section (info
)->output_offset
;
5807 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5811 dyn
.d_un
.d_val
= frvfdpic_pltrel_section (info
)->size
;
5812 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5821 /* Adjust a symbol defined by a dynamic object and referenced by a
5825 elf32_frvfdpic_adjust_dynamic_symbol
5826 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5827 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
5831 dynobj
= elf_hash_table (info
)->dynobj
;
5833 /* Make sure we know what is going on here. */
5834 BFD_ASSERT (dynobj
!= NULL
5835 && (h
->u
.weakdef
!= NULL
5838 && !h
->def_regular
)));
5840 /* If this is a weak symbol, and there is a real definition, the
5841 processor independent code will have arranged for us to see the
5842 real definition first, and we can just use the same value. */
5843 if (h
->u
.weakdef
!= NULL
)
5845 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
5846 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
5847 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
5848 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
5854 /* Perform any actions needed for dynamic symbols. */
5857 elf32_frvfdpic_finish_dynamic_symbol
5858 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5859 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5860 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
,
5861 Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
)
5866 /* Decide whether to attempt to turn absptr or lsda encodings in
5867 shared libraries into pcrel within the given input section. */
5870 frvfdpic_elf_use_relative_eh_frame
5871 (bfd
*input_bfd ATTRIBUTE_UNUSED
,
5872 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5873 asection
*eh_frame_section ATTRIBUTE_UNUSED
)
5875 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
5879 /* Adjust the contents of an eh_frame_hdr section before they're output. */
5882 frvfdpic_elf_encode_eh_address (bfd
*abfd
,
5883 struct bfd_link_info
*info
,
5884 asection
*osec
, bfd_vma offset
,
5885 asection
*loc_sec
, bfd_vma loc_offset
,
5888 struct elf_link_hash_entry
*h
;
5890 h
= elf_hash_table (info
)->hgot
;
5891 BFD_ASSERT (h
&& h
->root
.type
== bfd_link_hash_defined
);
5893 if (! h
|| (_frvfdpic_osec_to_segment (abfd
, osec
)
5894 == _frvfdpic_osec_to_segment (abfd
, loc_sec
->output_section
)))
5895 return _bfd_elf_encode_eh_address (abfd
, info
, osec
, offset
,
5896 loc_sec
, loc_offset
, encoded
);
5898 BFD_ASSERT (_frvfdpic_osec_to_segment (abfd
, osec
)
5899 == (_frvfdpic_osec_to_segment
5900 (abfd
, h
->root
.u
.def
.section
->output_section
)));
5902 *encoded
= osec
->vma
+ offset
5903 - (h
->root
.u
.def
.value
5904 + h
->root
.u
.def
.section
->output_section
->vma
5905 + h
->root
.u
.def
.section
->output_offset
);
5907 return DW_EH_PE_datarel
| DW_EH_PE_sdata4
;
5910 /* Look through the relocs for a section during the first phase.
5912 Besides handling virtual table relocs for gc, we have to deal with
5913 all sorts of PIC-related relocations. We describe below the
5914 general plan on how to handle such relocations, even though we only
5915 collect information at this point, storing them in hash tables for
5916 perusal of later passes.
5918 32 relocations are propagated to the linker output when creating
5919 position-independent output. LO16 and HI16 relocations are not
5920 supposed to be encountered in this case.
5922 LABEL16 should always be resolvable by the linker, since it's only
5925 LABEL24, on the other hand, is used by calls. If it turns out that
5926 the target of a call is a dynamic symbol, a PLT entry must be
5927 created for it, which triggers the creation of a private function
5928 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
5930 GPREL relocations require the referenced symbol to be in the same
5931 segment as _gp, but this can only be checked later.
5933 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
5934 exist. LABEL24 might as well, since it may require a PLT entry,
5935 that will require a got.
5937 Non-FUNCDESC GOT relocations require a GOT entry to be created
5938 regardless of whether the symbol is dynamic. However, since a
5939 global symbol that turns out to not be exported may have the same
5940 address of a non-dynamic symbol, we don't assign GOT entries at
5941 this point, such that we can share them in this case. A relocation
5942 for the GOT entry always has to be created, be it to offset a
5943 private symbol by the section load address, be it to get the symbol
5944 resolved dynamically.
5946 FUNCDESC GOT relocations require a GOT entry to be created, and
5947 handled as if a FUNCDESC relocation was applied to the GOT entry in
5950 FUNCDESC relocations referencing a symbol that turns out to NOT be
5951 dynamic cause a private function descriptor to be created. The
5952 FUNCDESC relocation then decays to a 32 relocation that points at
5953 the private descriptor. If the symbol is dynamic, the FUNCDESC
5954 relocation is propagated to the linker output, such that the
5955 dynamic linker creates the canonical descriptor, pointing to the
5956 dynamically-resolved definition of the function.
5958 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
5959 symbols that are assigned to the same segment as the GOT, but we
5960 can only check this later, after we know the complete set of
5961 symbols defined and/or exported.
5963 FUNCDESC GOTOFF relocations require a function descriptor to be
5964 created and, unless lazy binding is disabled or the symbol is not
5965 dynamic, a lazy PLT entry. Since we can't tell at this point
5966 whether a symbol is going to be dynamic, we have to decide later
5967 whether to create a lazy PLT entry or bind the descriptor directly
5968 to the private function.
5970 FUNCDESC_VALUE relocations are not supposed to be present in object
5971 files, but they may very well be simply propagated to the linker
5972 output, since they have no side effect.
5975 A function descriptor always requires a FUNCDESC_VALUE relocation.
5976 Whether it's in .plt.rel or not depends on whether lazy binding is
5977 enabled and on whether the referenced symbol is dynamic.
5979 The existence of a lazy PLT requires the resolverStub lazy PLT
5980 entry to be present.
5983 As for assignment of GOT, PLT and lazy PLT entries, and private
5984 descriptors, we might do them all sequentially, but we can do
5985 better than that. For example, we can place GOT entries and
5986 private function descriptors referenced using 12-bit operands
5987 closer to the PIC register value, such that these relocations don't
5988 overflow. Those that are only referenced with LO16 relocations
5989 could come next, but we may as well place PLT-required function
5990 descriptors in the 12-bit range to make them shorter. Symbols
5991 referenced with LO16/HI16 may come next, but we may place
5992 additional function descriptors in the 16-bit range if we can
5993 reliably tell that we've already placed entries that are ever
5994 referenced with only LO16. PLT entries are therefore generated as
5995 small as possible, while not introducing relocation overflows in
5996 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
5997 generated before or after PLT entries, but not intermingled with
5998 them, such that we can have more lazy PLT entries in range for a
5999 branch to the resolverStub. The resolverStub should be emitted at
6000 the most distant location from the first lazy PLT entry such that
6001 it's still in range for a branch, or closer, if there isn't a need
6002 for so many lazy PLT entries. Additional lazy PLT entries may be
6003 emitted after the resolverStub, as long as branches are still in
6004 range. If the branch goes out of range, longer lazy PLT entries
6007 We could further optimize PLT and lazy PLT entries by giving them
6008 priority in assignment to closer-to-gr17 locations depending on the
6009 number of occurrences of references to them (assuming a function
6010 that's called more often is more important for performance, so its
6011 PLT entry should be faster), or taking hints from the compiler.
6012 Given infinite time and money... :-) */
6015 elf32_frv_check_relocs (bfd
*abfd
,
6016 struct bfd_link_info
*info
,
6018 const Elf_Internal_Rela
*relocs
)
6020 Elf_Internal_Shdr
*symtab_hdr
;
6021 struct elf_link_hash_entry
**sym_hashes
;
6022 const Elf_Internal_Rela
*rel
;
6023 const Elf_Internal_Rela
*rel_end
;
6025 struct frvfdpic_relocs_info
*picrel
;
6027 if (info
->relocatable
)
6030 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6031 sym_hashes
= elf_sym_hashes (abfd
);
6033 dynobj
= elf_hash_table (info
)->dynobj
;
6034 rel_end
= relocs
+ sec
->reloc_count
;
6035 for (rel
= relocs
; rel
< rel_end
; rel
++)
6037 struct elf_link_hash_entry
*h
;
6038 unsigned long r_symndx
;
6040 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6041 if (r_symndx
< symtab_hdr
->sh_info
)
6045 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6046 while (h
->root
.type
== bfd_link_hash_indirect
6047 || h
->root
.type
== bfd_link_hash_warning
)
6048 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6051 switch (ELF32_R_TYPE (rel
->r_info
))
6053 case R_FRV_GETTLSOFF
:
6054 case R_FRV_TLSDESC_VALUE
:
6055 case R_FRV_GOTTLSDESC12
:
6056 case R_FRV_GOTTLSDESCHI
:
6057 case R_FRV_GOTTLSDESCLO
:
6058 case R_FRV_GOTTLSOFF12
:
6059 case R_FRV_GOTTLSOFFHI
:
6060 case R_FRV_GOTTLSOFFLO
:
6065 case R_FRV_FUNCDESC_GOT12
:
6066 case R_FRV_FUNCDESC_GOTHI
:
6067 case R_FRV_FUNCDESC_GOTLO
:
6068 case R_FRV_GOTOFF12
:
6069 case R_FRV_GOTOFFHI
:
6070 case R_FRV_GOTOFFLO
:
6071 case R_FRV_FUNCDESC_GOTOFF12
:
6072 case R_FRV_FUNCDESC_GOTOFFHI
:
6073 case R_FRV_FUNCDESC_GOTOFFLO
:
6074 case R_FRV_FUNCDESC
:
6075 case R_FRV_FUNCDESC_VALUE
:
6076 case R_FRV_TLSMOFF12
:
6077 case R_FRV_TLSMOFFHI
:
6078 case R_FRV_TLSMOFFLO
:
6080 if (! IS_FDPIC (abfd
))
6084 case R_FRV_GPRELU12
:
6091 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6092 if (! _frv_create_got_section (abfd
, info
))
6095 if (! IS_FDPIC (abfd
))
6102 if (h
->dynindx
== -1)
6103 switch (ELF_ST_VISIBILITY (h
->other
))
6109 bfd_elf_link_record_dynamic_symbol (info
, h
);
6113 = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info
),
6115 rel
->r_addend
, INSERT
);
6118 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
6119 (info
), abfd
, r_symndx
,
6120 rel
->r_addend
, INSERT
);
6130 switch (ELF32_R_TYPE (rel
->r_info
))
6133 if (IS_FDPIC (abfd
))
6137 case R_FRV_FUNCDESC_VALUE
:
6138 picrel
->relocsfdv
++;
6139 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
6144 if (! IS_FDPIC (abfd
))
6148 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
6158 picrel
->gothilo
= 1;
6161 case R_FRV_FUNCDESC_GOT12
:
6162 picrel
->fdgot12
= 1;
6165 case R_FRV_FUNCDESC_GOTHI
:
6166 case R_FRV_FUNCDESC_GOTLO
:
6167 picrel
->fdgothilo
= 1;
6170 case R_FRV_GOTOFF12
:
6171 case R_FRV_GOTOFFHI
:
6172 case R_FRV_GOTOFFLO
:
6176 case R_FRV_FUNCDESC_GOTOFF12
:
6177 picrel
->fdgoff12
= 1;
6180 case R_FRV_FUNCDESC_GOTOFFHI
:
6181 case R_FRV_FUNCDESC_GOTOFFLO
:
6182 picrel
->fdgoffhilo
= 1;
6185 case R_FRV_FUNCDESC
:
6190 case R_FRV_GETTLSOFF
:
6194 case R_FRV_TLSDESC_VALUE
:
6195 picrel
->relocstlsd
++;
6198 case R_FRV_GOTTLSDESC12
:
6199 picrel
->tlsdesc12
= 1;
6202 case R_FRV_GOTTLSDESCHI
:
6203 case R_FRV_GOTTLSDESCLO
:
6204 picrel
->tlsdeschilo
= 1;
6207 case R_FRV_TLSMOFF12
:
6208 case R_FRV_TLSMOFFHI
:
6209 case R_FRV_TLSMOFFLO
:
6213 case R_FRV_GOTTLSOFF12
:
6214 picrel
->tlsoff12
= 1;
6215 info
->flags
|= DF_STATIC_TLS
;
6218 case R_FRV_GOTTLSOFFHI
:
6219 case R_FRV_GOTTLSOFFLO
:
6220 picrel
->tlsoffhilo
= 1;
6221 info
->flags
|= DF_STATIC_TLS
;
6225 picrel
->relocstlsoff
++;
6226 info
->flags
|= DF_STATIC_TLS
;
6229 /* This relocation describes the C++ object vtable hierarchy.
6230 Reconstruct it for later use during GC. */
6231 case R_FRV_GNU_VTINHERIT
:
6232 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6236 /* This relocation describes which C++ vtable entries are actually
6237 used. Record for later use during GC. */
6238 case R_FRV_GNU_VTENTRY
:
6239 BFD_ASSERT (h
!= NULL
);
6241 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
6249 case R_FRV_GPRELU12
:
6253 case R_FRV_TLSDESC_RELAX
:
6254 case R_FRV_GETTLSOFF_RELAX
:
6255 case R_FRV_TLSOFF_RELAX
:
6260 info
->callbacks
->einfo
6261 (_("%B: unsupported relocation type %i\n"),
6262 abfd
, ELF32_R_TYPE (rel
->r_info
));
6271 /* Return the machine subcode from the ELF e_flags header. */
6274 elf32_frv_machine (bfd
*abfd
)
6276 switch (elf_elfheader (abfd
)->e_flags
& EF_FRV_CPU_MASK
)
6279 case EF_FRV_CPU_FR550
: return bfd_mach_fr550
;
6280 case EF_FRV_CPU_FR500
: return bfd_mach_fr500
;
6281 case EF_FRV_CPU_FR450
: return bfd_mach_fr450
;
6282 case EF_FRV_CPU_FR405
: return bfd_mach_fr400
;
6283 case EF_FRV_CPU_FR400
: return bfd_mach_fr400
;
6284 case EF_FRV_CPU_FR300
: return bfd_mach_fr300
;
6285 case EF_FRV_CPU_SIMPLE
: return bfd_mach_frvsimple
;
6286 case EF_FRV_CPU_TOMCAT
: return bfd_mach_frvtomcat
;
6289 return bfd_mach_frv
;
6292 /* Set the right machine number for a FRV ELF file. */
6295 elf32_frv_object_p (bfd
*abfd
)
6297 bfd_default_set_arch_mach (abfd
, bfd_arch_frv
, elf32_frv_machine (abfd
));
6298 return (((elf_elfheader (abfd
)->e_flags
& EF_FRV_FDPIC
) != 0)
6299 == (IS_FDPIC (abfd
)));
6302 /* Function to set the ELF flag bits. */
6305 frv_elf_set_private_flags (bfd
*abfd
, flagword flags
)
6307 elf_elfheader (abfd
)->e_flags
= flags
;
6308 elf_flags_init (abfd
) = TRUE
;
6312 /* Copy backend specific data from one object module to another. */
6315 frv_elf_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
6317 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6318 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6321 BFD_ASSERT (!elf_flags_init (obfd
)
6322 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
6324 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
6325 elf_flags_init (obfd
) = TRUE
;
6327 /* Copy object attributes. */
6328 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
6333 /* Return true if the architecture described by elf header flag
6334 EXTENSION is an extension of the architecture described by BASE. */
6337 frv_elf_arch_extension_p (flagword base
, flagword extension
)
6339 if (base
== extension
)
6342 /* CPU_GENERIC code can be merged with code for a specific
6343 architecture, in which case the result is marked as being
6344 for the specific architecture. Everything is therefore
6345 an extension of CPU_GENERIC. */
6346 if (base
== EF_FRV_CPU_GENERIC
)
6349 if (extension
== EF_FRV_CPU_FR450
)
6350 if (base
== EF_FRV_CPU_FR400
|| base
== EF_FRV_CPU_FR405
)
6353 if (extension
== EF_FRV_CPU_FR405
)
6354 if (base
== EF_FRV_CPU_FR400
)
6361 elf32_frvfdpic_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
6363 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6364 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6367 if (! frv_elf_copy_private_bfd_data (ibfd
, obfd
))
6370 if (! elf_tdata (ibfd
) || ! elf_tdata (ibfd
)->phdr
6371 || ! elf_tdata (obfd
) || ! elf_tdata (obfd
)->phdr
)
6377 /* Merge backend specific data from an object file to the output
6378 object file when linking. */
6381 frv_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
6383 flagword old_flags
, old_partial
;
6384 flagword new_flags
, new_partial
;
6385 bfd_boolean error
= FALSE
;
6389 new_opt
[0] = old_opt
[0] = '\0';
6390 new_flags
= elf_elfheader (ibfd
)->e_flags
;
6391 old_flags
= elf_elfheader (obfd
)->e_flags
;
6393 if (new_flags
& EF_FRV_FDPIC
)
6394 new_flags
&= ~EF_FRV_PIC
;
6397 (*_bfd_error_handler
) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s",
6398 old_flags
, new_flags
, elf_flags_init (obfd
) ? "yes" : "no",
6399 bfd_get_filename (ibfd
));
6402 if (!elf_flags_init (obfd
)) /* First call, no flags set. */
6404 elf_flags_init (obfd
) = TRUE
;
6405 old_flags
= new_flags
;
6408 else if (new_flags
== old_flags
) /* Compatible flags are ok. */
6411 else /* Possibly incompatible flags. */
6413 /* Warn if different # of gprs are used. Note, 0 means nothing is
6414 said about the size of gprs. */
6415 new_partial
= (new_flags
& EF_FRV_GPR_MASK
);
6416 old_partial
= (old_flags
& EF_FRV_GPR_MASK
);
6417 if (new_partial
== old_partial
)
6420 else if (new_partial
== 0)
6423 else if (old_partial
== 0)
6424 old_flags
|= new_partial
;
6428 switch (new_partial
)
6430 default: strcat (new_opt
, " -mgpr-??"); break;
6431 case EF_FRV_GPR_32
: strcat (new_opt
, " -mgpr-32"); break;
6432 case EF_FRV_GPR_64
: strcat (new_opt
, " -mgpr-64"); break;
6435 switch (old_partial
)
6437 default: strcat (old_opt
, " -mgpr-??"); break;
6438 case EF_FRV_GPR_32
: strcat (old_opt
, " -mgpr-32"); break;
6439 case EF_FRV_GPR_64
: strcat (old_opt
, " -mgpr-64"); break;
6443 /* Warn if different # of fprs are used. Note, 0 means nothing is
6444 said about the size of fprs. */
6445 new_partial
= (new_flags
& EF_FRV_FPR_MASK
);
6446 old_partial
= (old_flags
& EF_FRV_FPR_MASK
);
6447 if (new_partial
== old_partial
)
6450 else if (new_partial
== 0)
6453 else if (old_partial
== 0)
6454 old_flags
|= new_partial
;
6458 switch (new_partial
)
6460 default: strcat (new_opt
, " -mfpr-?"); break;
6461 case EF_FRV_FPR_32
: strcat (new_opt
, " -mfpr-32"); break;
6462 case EF_FRV_FPR_64
: strcat (new_opt
, " -mfpr-64"); break;
6463 case EF_FRV_FPR_NONE
: strcat (new_opt
, " -msoft-float"); break;
6466 switch (old_partial
)
6468 default: strcat (old_opt
, " -mfpr-?"); break;
6469 case EF_FRV_FPR_32
: strcat (old_opt
, " -mfpr-32"); break;
6470 case EF_FRV_FPR_64
: strcat (old_opt
, " -mfpr-64"); break;
6471 case EF_FRV_FPR_NONE
: strcat (old_opt
, " -msoft-float"); break;
6475 /* Warn if different dword support was used. Note, 0 means nothing is
6476 said about the dword support. */
6477 new_partial
= (new_flags
& EF_FRV_DWORD_MASK
);
6478 old_partial
= (old_flags
& EF_FRV_DWORD_MASK
);
6479 if (new_partial
== old_partial
)
6482 else if (new_partial
== 0)
6485 else if (old_partial
== 0)
6486 old_flags
|= new_partial
;
6490 switch (new_partial
)
6492 default: strcat (new_opt
, " -mdword-?"); break;
6493 case EF_FRV_DWORD_YES
: strcat (new_opt
, " -mdword"); break;
6494 case EF_FRV_DWORD_NO
: strcat (new_opt
, " -mno-dword"); break;
6497 switch (old_partial
)
6499 default: strcat (old_opt
, " -mdword-?"); break;
6500 case EF_FRV_DWORD_YES
: strcat (old_opt
, " -mdword"); break;
6501 case EF_FRV_DWORD_NO
: strcat (old_opt
, " -mno-dword"); break;
6505 /* Or in flags that accumulate (ie, if one module uses it, mark that the
6507 old_flags
|= new_flags
& (EF_FRV_DOUBLE
6510 | EF_FRV_NON_PIC_RELOCS
);
6512 /* If any module was compiled without -G0, clear the G0 bit. */
6513 old_flags
= ((old_flags
& ~ EF_FRV_G0
)
6514 | (old_flags
& new_flags
& EF_FRV_G0
));
6516 /* If any module was compiled without -mnopack, clear the mnopack bit. */
6517 old_flags
= ((old_flags
& ~ EF_FRV_NOPACK
)
6518 | (old_flags
& new_flags
& EF_FRV_NOPACK
));
6520 /* We don't have to do anything if the pic flags are the same, or the new
6521 module(s) were compiled with -mlibrary-pic. */
6522 new_partial
= (new_flags
& EF_FRV_PIC_FLAGS
);
6523 old_partial
= (old_flags
& EF_FRV_PIC_FLAGS
);
6524 if ((new_partial
== old_partial
) || ((new_partial
& EF_FRV_LIBPIC
) != 0))
6527 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
6528 flags if any from the new module. */
6529 else if ((old_partial
& EF_FRV_LIBPIC
) != 0)
6530 old_flags
= (old_flags
& ~ EF_FRV_PIC_FLAGS
) | new_partial
;
6532 /* If we have mixtures of -fpic and -fPIC, or in both bits. */
6533 else if (new_partial
!= 0 && old_partial
!= 0)
6534 old_flags
|= new_partial
;
6536 /* One module was compiled for pic and the other was not, see if we have
6537 had any relocations that are not pic-safe. */
6540 if ((old_flags
& EF_FRV_NON_PIC_RELOCS
) == 0)
6541 old_flags
|= new_partial
;
6544 old_flags
&= ~ EF_FRV_PIC_FLAGS
;
6545 #ifndef FRV_NO_PIC_ERROR
6547 (*_bfd_error_handler
)
6548 (_("%s: compiled with %s and linked with modules that use non-pic relocations"),
6549 bfd_get_filename (ibfd
),
6550 (new_flags
& EF_FRV_BIGPIC
) ? "-fPIC" : "-fpic");
6555 /* Warn if different cpu is used (allow a specific cpu to override
6556 the generic cpu). */
6557 new_partial
= (new_flags
& EF_FRV_CPU_MASK
);
6558 old_partial
= (old_flags
& EF_FRV_CPU_MASK
);
6559 if (frv_elf_arch_extension_p (new_partial
, old_partial
))
6562 else if (frv_elf_arch_extension_p (old_partial
, new_partial
))
6563 old_flags
= (old_flags
& ~EF_FRV_CPU_MASK
) | new_partial
;
6567 switch (new_partial
)
6569 default: strcat (new_opt
, " -mcpu=?"); break;
6570 case EF_FRV_CPU_GENERIC
: strcat (new_opt
, " -mcpu=frv"); break;
6571 case EF_FRV_CPU_SIMPLE
: strcat (new_opt
, " -mcpu=simple"); break;
6572 case EF_FRV_CPU_FR550
: strcat (new_opt
, " -mcpu=fr550"); break;
6573 case EF_FRV_CPU_FR500
: strcat (new_opt
, " -mcpu=fr500"); break;
6574 case EF_FRV_CPU_FR450
: strcat (new_opt
, " -mcpu=fr450"); break;
6575 case EF_FRV_CPU_FR405
: strcat (new_opt
, " -mcpu=fr405"); break;
6576 case EF_FRV_CPU_FR400
: strcat (new_opt
, " -mcpu=fr400"); break;
6577 case EF_FRV_CPU_FR300
: strcat (new_opt
, " -mcpu=fr300"); break;
6578 case EF_FRV_CPU_TOMCAT
: strcat (new_opt
, " -mcpu=tomcat"); break;
6581 switch (old_partial
)
6583 default: strcat (old_opt
, " -mcpu=?"); break;
6584 case EF_FRV_CPU_GENERIC
: strcat (old_opt
, " -mcpu=frv"); break;
6585 case EF_FRV_CPU_SIMPLE
: strcat (old_opt
, " -mcpu=simple"); break;
6586 case EF_FRV_CPU_FR550
: strcat (old_opt
, " -mcpu=fr550"); break;
6587 case EF_FRV_CPU_FR500
: strcat (old_opt
, " -mcpu=fr500"); break;
6588 case EF_FRV_CPU_FR450
: strcat (old_opt
, " -mcpu=fr450"); break;
6589 case EF_FRV_CPU_FR405
: strcat (old_opt
, " -mcpu=fr405"); break;
6590 case EF_FRV_CPU_FR400
: strcat (old_opt
, " -mcpu=fr400"); break;
6591 case EF_FRV_CPU_FR300
: strcat (old_opt
, " -mcpu=fr300"); break;
6592 case EF_FRV_CPU_TOMCAT
: strcat (old_opt
, " -mcpu=tomcat"); break;
6596 /* Print out any mismatches from above. */
6600 (*_bfd_error_handler
)
6601 (_("%s: compiled with %s and linked with modules compiled with %s"),
6602 bfd_get_filename (ibfd
), new_opt
, old_opt
);
6605 /* Warn about any other mismatches */
6606 new_partial
= (new_flags
& ~ EF_FRV_ALL_FLAGS
);
6607 old_partial
= (old_flags
& ~ EF_FRV_ALL_FLAGS
);
6608 if (new_partial
!= old_partial
)
6610 old_flags
|= new_partial
;
6612 (*_bfd_error_handler
)
6613 (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"),
6614 bfd_get_filename (ibfd
), (long)new_partial
, (long)old_partial
);
6618 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
6619 if ((old_flags
& EF_FRV_CPU_MASK
) == EF_FRV_CPU_SIMPLE
)
6620 old_flags
|= EF_FRV_NOPACK
;
6622 /* Update the old flags now with changes made above. */
6623 old_partial
= elf_elfheader (obfd
)->e_flags
& EF_FRV_CPU_MASK
;
6624 elf_elfheader (obfd
)->e_flags
= old_flags
;
6625 if (old_partial
!= (old_flags
& EF_FRV_CPU_MASK
))
6626 bfd_default_set_arch_mach (obfd
, bfd_arch_frv
, elf32_frv_machine (obfd
));
6628 if (((new_flags
& EF_FRV_FDPIC
) == 0)
6629 != (! IS_FDPIC (ibfd
)))
6632 if (IS_FDPIC (obfd
))
6633 (*_bfd_error_handler
)
6634 (_("%s: cannot link non-fdpic object file into fdpic executable"),
6635 bfd_get_filename (ibfd
));
6637 (*_bfd_error_handler
)
6638 (_("%s: cannot link fdpic object file into non-fdpic executable"),
6639 bfd_get_filename (ibfd
));
6643 bfd_set_error (bfd_error_bad_value
);
6650 frv_elf_print_private_bfd_data (bfd
*abfd
, void * ptr
)
6652 FILE *file
= (FILE *) ptr
;
6655 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6657 /* Print normal ELF private data. */
6658 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6660 flags
= elf_elfheader (abfd
)->e_flags
;
6661 fprintf (file
, _("private flags = 0x%lx:"), (unsigned long) flags
);
6663 switch (flags
& EF_FRV_CPU_MASK
)
6666 case EF_FRV_CPU_SIMPLE
: fprintf (file
, " -mcpu=simple"); break;
6667 case EF_FRV_CPU_FR550
: fprintf (file
, " -mcpu=fr550"); break;
6668 case EF_FRV_CPU_FR500
: fprintf (file
, " -mcpu=fr500"); break;
6669 case EF_FRV_CPU_FR450
: fprintf (file
, " -mcpu=fr450"); break;
6670 case EF_FRV_CPU_FR405
: fprintf (file
, " -mcpu=fr405"); break;
6671 case EF_FRV_CPU_FR400
: fprintf (file
, " -mcpu=fr400"); break;
6672 case EF_FRV_CPU_FR300
: fprintf (file
, " -mcpu=fr300"); break;
6673 case EF_FRV_CPU_TOMCAT
: fprintf (file
, " -mcpu=tomcat"); break;
6676 switch (flags
& EF_FRV_GPR_MASK
)
6679 case EF_FRV_GPR_32
: fprintf (file
, " -mgpr-32"); break;
6680 case EF_FRV_GPR_64
: fprintf (file
, " -mgpr-64"); break;
6683 switch (flags
& EF_FRV_FPR_MASK
)
6686 case EF_FRV_FPR_32
: fprintf (file
, " -mfpr-32"); break;
6687 case EF_FRV_FPR_64
: fprintf (file
, " -mfpr-64"); break;
6688 case EF_FRV_FPR_NONE
: fprintf (file
, " -msoft-float"); break;
6691 switch (flags
& EF_FRV_DWORD_MASK
)
6694 case EF_FRV_DWORD_YES
: fprintf (file
, " -mdword"); break;
6695 case EF_FRV_DWORD_NO
: fprintf (file
, " -mno-dword"); break;
6698 if (flags
& EF_FRV_DOUBLE
)
6699 fprintf (file
, " -mdouble");
6701 if (flags
& EF_FRV_MEDIA
)
6702 fprintf (file
, " -mmedia");
6704 if (flags
& EF_FRV_MULADD
)
6705 fprintf (file
, " -mmuladd");
6707 if (flags
& EF_FRV_PIC
)
6708 fprintf (file
, " -fpic");
6710 if (flags
& EF_FRV_BIGPIC
)
6711 fprintf (file
, " -fPIC");
6713 if (flags
& EF_FRV_LIBPIC
)
6714 fprintf (file
, " -mlibrary-pic");
6716 if (flags
& EF_FRV_FDPIC
)
6717 fprintf (file
, " -mfdpic");
6719 if (flags
& EF_FRV_NON_PIC_RELOCS
)
6720 fprintf (file
, " non-pic relocations");
6722 if (flags
& EF_FRV_G0
)
6723 fprintf (file
, " -G0");
6730 /* Support for core dump NOTE sections. */
6733 elf32_frv_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
6736 unsigned int raw_size
;
6738 switch (note
->descsz
)
6743 /* The Linux/FRV elf_prstatus struct is 268 bytes long. The other
6744 hardcoded offsets and sizes listed below (and contained within
6745 this lexical block) refer to fields in the target's elf_prstatus
6748 /* `pr_cursig' is at offset 12. */
6749 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
6751 /* `pr_pid' is at offset 24. */
6752 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
6754 /* `pr_reg' is at offset 72. */
6757 /* Most grok_prstatus implementations set `raw_size' to the size
6758 of the pr_reg field. For Linux/FRV, we set `raw_size' to be
6759 the size of `pr_reg' plus the size of `pr_exec_fdpic_loadmap'
6760 and `pr_interp_fdpic_loadmap', both of which (by design)
6761 immediately follow `pr_reg'. This will allow these fields to
6762 be viewed by GDB as registers.
6764 `pr_reg' is 184 bytes long. `pr_exec_fdpic_loadmap' and
6765 `pr_interp_fdpic_loadmap' are 4 bytes each. */
6766 raw_size
= 184 + 4 + 4;
6771 /* Make a ".reg/999" section. */
6772 return _bfd_elfcore_make_pseudosection (abfd
, ".reg", raw_size
,
6773 note
->descpos
+ offset
);
6777 elf32_frv_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
6779 switch (note
->descsz
)
6784 /* The Linux/FRV elf_prpsinfo struct is 124 bytes long. */
6787 /* `pr_fname' is found at offset 28 and is 16 bytes long. */
6788 elf_tdata (abfd
)->core_program
6789 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
6791 /* `pr_psargs' is found at offset 44 and is 80 bytes long. */
6792 elf_tdata (abfd
)->core_command
6793 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
6796 /* Note that for some reason, a spurious space is tacked
6797 onto the end of the args in some (at least one anyway)
6798 implementations, so strip it off if it exists. */
6801 char *command
= elf_tdata (abfd
)->core_command
;
6802 int n
= strlen (command
);
6804 if (0 < n
&& command
[n
- 1] == ' ')
6805 command
[n
- 1] = '\0';
6810 #define ELF_ARCH bfd_arch_frv
6811 #define ELF_TARGET_ID FRV_ELF_DATA
6812 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
6813 #define ELF_MAXPAGESIZE 0x1000
6815 #define TARGET_BIG_SYM bfd_elf32_frv_vec
6816 #define TARGET_BIG_NAME "elf32-frv"
6818 #define elf_info_to_howto frv_info_to_howto_rela
6819 #define elf_backend_relocate_section elf32_frv_relocate_section
6820 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
6821 #define elf_backend_check_relocs elf32_frv_check_relocs
6822 #define elf_backend_object_p elf32_frv_object_p
6823 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
6825 #define elf_backend_stack_align 8
6826 #define elf_backend_can_gc_sections 1
6827 #define elf_backend_rela_normal 1
6829 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
6830 #define bfd_elf32_bfd_reloc_name_lookup frv_reloc_name_lookup
6831 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
6832 #define bfd_elf32_bfd_copy_private_bfd_data frv_elf_copy_private_bfd_data
6833 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
6834 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
6836 #define elf_backend_want_got_sym 1
6837 #define elf_backend_got_header_size 0
6838 #define elf_backend_want_got_plt 0
6839 #define elf_backend_plt_readonly 1
6840 #define elf_backend_want_plt_sym 0
6841 #define elf_backend_plt_header_size 0
6843 #define elf_backend_finish_dynamic_sections \
6844 elf32_frv_finish_dynamic_sections
6846 #define elf_backend_grok_prstatus elf32_frv_grok_prstatus
6847 #define elf_backend_grok_psinfo elf32_frv_grok_psinfo
6849 #include "elf32-target.h"
6851 #undef ELF_MAXPAGESIZE
6852 #define ELF_MAXPAGESIZE 0x4000
6854 #undef TARGET_BIG_SYM
6855 #define TARGET_BIG_SYM bfd_elf32_frvfdpic_vec
6856 #undef TARGET_BIG_NAME
6857 #define TARGET_BIG_NAME "elf32-frvfdpic"
6859 #define elf32_bed elf32_frvfdpic_bed
6861 #undef elf_info_to_howto_rel
6862 #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel
6864 #undef bfd_elf32_bfd_link_hash_table_create
6865 #define bfd_elf32_bfd_link_hash_table_create \
6866 frvfdpic_elf_link_hash_table_create
6867 #undef elf_backend_always_size_sections
6868 #define elf_backend_always_size_sections \
6869 elf32_frvfdpic_always_size_sections
6870 #undef bfd_elf32_bfd_copy_private_bfd_data
6871 #define bfd_elf32_bfd_copy_private_bfd_data \
6872 elf32_frvfdpic_copy_private_bfd_data
6874 #undef elf_backend_create_dynamic_sections
6875 #define elf_backend_create_dynamic_sections \
6876 elf32_frvfdpic_create_dynamic_sections
6877 #undef elf_backend_adjust_dynamic_symbol
6878 #define elf_backend_adjust_dynamic_symbol \
6879 elf32_frvfdpic_adjust_dynamic_symbol
6880 #undef elf_backend_size_dynamic_sections
6881 #define elf_backend_size_dynamic_sections \
6882 elf32_frvfdpic_size_dynamic_sections
6883 #undef bfd_elf32_bfd_relax_section
6884 #define bfd_elf32_bfd_relax_section \
6885 elf32_frvfdpic_relax_section
6886 #undef elf_backend_finish_dynamic_symbol
6887 #define elf_backend_finish_dynamic_symbol \
6888 elf32_frvfdpic_finish_dynamic_symbol
6889 #undef elf_backend_finish_dynamic_sections
6890 #define elf_backend_finish_dynamic_sections \
6891 elf32_frvfdpic_finish_dynamic_sections
6893 #undef elf_backend_discard_info
6894 #define elf_backend_discard_info \
6895 frvfdpic_elf_discard_info
6896 #undef elf_backend_can_make_relative_eh_frame
6897 #define elf_backend_can_make_relative_eh_frame \
6898 frvfdpic_elf_use_relative_eh_frame
6899 #undef elf_backend_can_make_lsda_relative_eh_frame
6900 #define elf_backend_can_make_lsda_relative_eh_frame \
6901 frvfdpic_elf_use_relative_eh_frame
6902 #undef elf_backend_encode_eh_address
6903 #define elf_backend_encode_eh_address \
6904 frvfdpic_elf_encode_eh_address
6906 #undef elf_backend_may_use_rel_p
6907 #define elf_backend_may_use_rel_p 1
6908 #undef elf_backend_may_use_rela_p
6909 #define elf_backend_may_use_rela_p 1
6910 /* We use REL for dynamic relocations only. */
6911 #undef elf_backend_default_use_rela_p
6912 #define elf_backend_default_use_rela_p 1
6914 #undef elf_backend_omit_section_dynsym
6915 #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym
6917 #include "elf32-target.h"