1 /* FRV-specific support for 32-bit ELF.
2 Copyright 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
25 #include "elf/dwarf2.h"
28 /* Forward declarations. */
29 static bfd_reloc_status_type elf32_frv_relocate_lo16
30 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
31 static bfd_reloc_status_type elf32_frv_relocate_hi16
32 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
33 static bfd_reloc_status_type elf32_frv_relocate_label24
34 PARAMS ((bfd
*, asection
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
35 static bfd_reloc_status_type elf32_frv_relocate_gprel12
36 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
37 bfd_byte
*, bfd_vma
));
38 static bfd_reloc_status_type elf32_frv_relocate_gprelu12
39 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
40 bfd_byte
*, bfd_vma
));
41 static bfd_reloc_status_type elf32_frv_relocate_gprello
42 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
43 bfd_byte
*, bfd_vma
));
44 static bfd_reloc_status_type elf32_frv_relocate_gprelhi
45 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
46 bfd_byte
*, bfd_vma
));
47 static reloc_howto_type
*frv_reloc_type_lookup
48 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
49 static void frv_info_to_howto_rela
50 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
51 static bfd_boolean elf32_frv_relocate_section
52 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
53 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
54 static bfd_boolean elf32_frv_add_symbol_hook
55 PARAMS (( bfd
*, struct bfd_link_info
*, Elf_Internal_Sym
*,
56 const char **, flagword
*, asection
**, bfd_vma
*));
57 static bfd_reloc_status_type frv_final_link_relocate
58 PARAMS ((reloc_howto_type
*, bfd
*, asection
*, bfd_byte
*,
59 Elf_Internal_Rela
*, bfd_vma
));
60 static bfd_boolean elf32_frv_check_relocs
61 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
62 const Elf_Internal_Rela
*));
63 static int elf32_frv_machine
65 static bfd_boolean elf32_frv_object_p
67 static bfd_boolean frv_elf_set_private_flags
68 PARAMS ((bfd
*, flagword
));
69 static bfd_boolean frv_elf_copy_private_bfd_data
70 PARAMS ((bfd
*, bfd
*));
71 static bfd_boolean frv_elf_merge_private_bfd_data
72 PARAMS ((bfd
*, bfd
*));
73 static bfd_boolean frv_elf_print_private_bfd_data
74 PARAMS ((bfd
*, PTR
));
75 static bfd_boolean
elf32_frv_grok_prstatus (bfd
* abfd
,
76 Elf_Internal_Note
* note
);
77 static bfd_boolean
elf32_frv_grok_psinfo (bfd
* abfd
,
78 Elf_Internal_Note
* note
);
80 static reloc_howto_type elf32_frv_howto_table
[] =
82 /* This reloc does nothing. */
83 HOWTO (R_FRV_NONE
, /* type */
85 2, /* size (0 = byte, 1 = short, 2 = long) */
87 FALSE
, /* pc_relative */
89 complain_overflow_bitfield
, /* complain_on_overflow */
90 bfd_elf_generic_reloc
, /* special_function */
91 "R_FRV_NONE", /* name */
92 FALSE
, /* partial_inplace */
95 FALSE
), /* pcrel_offset */
97 /* A 32 bit absolute relocation. */
98 HOWTO (R_FRV_32
, /* type */
100 2, /* size (0 = byte, 1 = short, 2 = long) */
102 FALSE
, /* pc_relative */
104 complain_overflow_bitfield
, /* complain_on_overflow */
105 bfd_elf_generic_reloc
, /* special_function */
106 "R_FRV_32", /* name */
107 FALSE
, /* partial_inplace */
108 0xffffffff, /* src_mask */
109 0xffffffff, /* dst_mask */
110 FALSE
), /* pcrel_offset */
112 /* A 16 bit pc-relative relocation. */
113 HOWTO (R_FRV_LABEL16
, /* type */
115 2, /* size (0 = byte, 1 = short, 2 = long) */
117 TRUE
, /* pc_relative */
119 complain_overflow_signed
, /* complain_on_overflow */
120 bfd_elf_generic_reloc
, /* special_function */
121 "R_FRV_LABEL16", /* name */
122 FALSE
, /* partial_inplace */
123 0xffff, /* src_mask */
124 0xffff, /* dst_mask */
125 TRUE
), /* pcrel_offset */
127 /* A 24-bit pc-relative relocation. */
128 HOWTO (R_FRV_LABEL24
, /* type */
130 2, /* size (0 = byte, 1 = short, 2 = long) */
132 TRUE
, /* pc_relative */
134 complain_overflow_bitfield
, /* complain_on_overflow */
135 bfd_elf_generic_reloc
, /* special_function */
136 "R_FRV_LABEL24", /* name */
137 FALSE
, /* partial_inplace */
138 0x7e03ffff, /* src_mask */
139 0x7e03ffff, /* dst_mask */
140 TRUE
), /* pcrel_offset */
142 HOWTO (R_FRV_LO16
, /* type */
144 2, /* size (0 = byte, 1 = short, 2 = long) */
146 FALSE
, /* pc_relative */
148 complain_overflow_dont
, /* complain_on_overflow */
149 bfd_elf_generic_reloc
, /* special_function */
150 "R_FRV_LO16", /* name */
151 FALSE
, /* partial_inplace */
152 0xffff, /* src_mask */
153 0xffff, /* dst_mask */
154 FALSE
), /* pcrel_offset */
156 HOWTO (R_FRV_HI16
, /* type */
158 2, /* size (0 = byte, 1 = short, 2 = long) */
160 FALSE
, /* pc_relative */
162 complain_overflow_dont
, /* complain_on_overflow */
163 bfd_elf_generic_reloc
, /* special_function */
164 "R_FRV_HI16", /* name */
165 FALSE
, /* partial_inplace */
166 0xffff, /* src_mask */
167 0xffff, /* dst_mask */
168 FALSE
), /* pcrel_offset */
170 HOWTO (R_FRV_GPREL12
, /* type */
172 2, /* size (0 = byte, 1 = short, 2 = long) */
174 FALSE
, /* pc_relative */
176 complain_overflow_dont
, /* complain_on_overflow */
177 bfd_elf_generic_reloc
, /* special_function */
178 "R_FRV_GPREL12", /* name */
179 FALSE
, /* partial_inplace */
180 0xfff, /* src_mask */
181 0xfff, /* dst_mask */
182 FALSE
), /* pcrel_offset */
184 HOWTO (R_FRV_GPRELU12
, /* type */
186 2, /* size (0 = byte, 1 = short, 2 = long) */
188 FALSE
, /* pc_relative */
190 complain_overflow_dont
, /* complain_on_overflow */
191 bfd_elf_generic_reloc
, /* special_function */
192 "R_FRV_GPRELU12", /* name */
193 FALSE
, /* partial_inplace */
194 0xfff, /* src_mask */
195 0x3f03f, /* dst_mask */
196 FALSE
), /* pcrel_offset */
198 HOWTO (R_FRV_GPREL32
, /* type */
200 2, /* size (0 = byte, 1 = short, 2 = long) */
202 FALSE
, /* pc_relative */
204 complain_overflow_dont
, /* complain_on_overflow */
205 bfd_elf_generic_reloc
, /* special_function */
206 "R_FRV_GPREL32", /* name */
207 FALSE
, /* partial_inplace */
208 0xffffffff, /* src_mask */
209 0xffffffff, /* dst_mask */
210 FALSE
), /* pcrel_offset */
212 HOWTO (R_FRV_GPRELHI
, /* type */
214 2, /* size (0 = byte, 1 = short, 2 = long) */
216 FALSE
, /* pc_relative */
218 complain_overflow_dont
, /* complain_on_overflow */
219 bfd_elf_generic_reloc
, /* special_function */
220 "R_FRV_GPRELHI", /* name */
221 FALSE
, /* partial_inplace */
222 0xffff, /* src_mask */
223 0xffff, /* dst_mask */
224 FALSE
), /* pcrel_offset */
226 HOWTO (R_FRV_GPRELLO
, /* type */
228 2, /* size (0 = byte, 1 = short, 2 = long) */
230 FALSE
, /* pc_relative */
232 complain_overflow_dont
, /* complain_on_overflow */
233 bfd_elf_generic_reloc
, /* special_function */
234 "R_FRV_GPRELLO", /* name */
235 FALSE
, /* partial_inplace */
236 0xffff, /* src_mask */
237 0xffff, /* dst_mask */
238 FALSE
), /* pcrel_offset */
240 /* A 12-bit signed operand with the GOT offset for the address of
242 HOWTO (R_FRV_GOT12
, /* type */
244 2, /* size (0 = byte, 1 = short, 2 = long) */
246 FALSE
, /* pc_relative */
248 complain_overflow_signed
, /* complain_on_overflow */
249 bfd_elf_generic_reloc
, /* special_function */
250 "R_FRV_GOT12", /* name */
251 FALSE
, /* partial_inplace */
252 0xfff, /* src_mask */
253 0xfff, /* dst_mask */
254 FALSE
), /* pcrel_offset */
256 /* The upper 16 bits of the GOT offset for the address of the
258 HOWTO (R_FRV_GOTHI
, /* type */
260 2, /* size (0 = byte, 1 = short, 2 = long) */
262 FALSE
, /* pc_relative */
264 complain_overflow_dont
, /* complain_on_overflow */
265 bfd_elf_generic_reloc
, /* special_function */
266 "R_FRV_GOTHI", /* name */
267 FALSE
, /* partial_inplace */
268 0xffff, /* src_mask */
269 0xffff, /* dst_mask */
270 FALSE
), /* pcrel_offset */
272 /* The lower 16 bits of the GOT offset for the address of the
274 HOWTO (R_FRV_GOTLO
, /* 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_GOTLO", /* name */
283 FALSE
, /* partial_inplace */
284 0xffff, /* src_mask */
285 0xffff, /* dst_mask */
286 FALSE
), /* pcrel_offset */
288 /* The 32-bit address of the canonical descriptor of a function. */
289 HOWTO (R_FRV_FUNCDESC
, /* type */
291 2, /* size (0 = byte, 1 = short, 2 = long) */
293 FALSE
, /* pc_relative */
295 complain_overflow_bitfield
, /* complain_on_overflow */
296 bfd_elf_generic_reloc
, /* special_function */
297 "R_FRV_FUNCDESC", /* name */
298 FALSE
, /* partial_inplace */
299 0xffffffff, /* src_mask */
300 0xffffffff, /* dst_mask */
301 FALSE
), /* pcrel_offset */
303 /* A 12-bit signed operand with the GOT offset for the address of
304 canonical descriptor of a function. */
305 HOWTO (R_FRV_FUNCDESC_GOT12
, /* type */
307 2, /* size (0 = byte, 1 = short, 2 = long) */
309 FALSE
, /* pc_relative */
311 complain_overflow_signed
, /* complain_on_overflow */
312 bfd_elf_generic_reloc
, /* special_function */
313 "R_FRV_FUNCDESC_GOT12", /* name */
314 FALSE
, /* partial_inplace */
315 0xfff, /* src_mask */
316 0xfff, /* dst_mask */
317 FALSE
), /* pcrel_offset */
319 /* The upper 16 bits of the GOT offset for the address of the
320 canonical descriptor of a function. */
321 HOWTO (R_FRV_FUNCDESC_GOTHI
, /* type */
323 2, /* size (0 = byte, 1 = short, 2 = long) */
325 FALSE
, /* pc_relative */
327 complain_overflow_dont
, /* complain_on_overflow */
328 bfd_elf_generic_reloc
, /* special_function */
329 "R_FRV_FUNCDESC_GOTHI", /* name */
330 FALSE
, /* partial_inplace */
331 0xffff, /* src_mask */
332 0xffff, /* dst_mask */
333 FALSE
), /* pcrel_offset */
335 /* The lower 16 bits of the GOT offset for the address of the
336 canonical descriptor of a function. */
337 HOWTO (R_FRV_FUNCDESC_GOTLO
, /* 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_GOTLO", /* name */
346 FALSE
, /* partial_inplace */
347 0xffff, /* src_mask */
348 0xffff, /* dst_mask */
349 FALSE
), /* pcrel_offset */
351 /* The 64-bit descriptor of a function. */
352 HOWTO (R_FRV_FUNCDESC_VALUE
, /* type */
354 2, /* size (0 = byte, 1 = short, 2 = long) */
356 FALSE
, /* pc_relative */
358 complain_overflow_bitfield
, /* complain_on_overflow */
359 bfd_elf_generic_reloc
, /* special_function */
360 "R_FRV_FUNCDESC_VALUE", /* name */
361 FALSE
, /* partial_inplace */
362 0xffffffff, /* src_mask */
363 0xffffffff, /* dst_mask */
364 FALSE
), /* pcrel_offset */
366 /* A 12-bit signed operand with the GOT offset for the address of
367 canonical descriptor of a function. */
368 HOWTO (R_FRV_FUNCDESC_GOTOFF12
, /* type */
370 2, /* size (0 = byte, 1 = short, 2 = long) */
372 FALSE
, /* pc_relative */
374 complain_overflow_signed
, /* complain_on_overflow */
375 bfd_elf_generic_reloc
, /* special_function */
376 "R_FRV_FUNCDESC_GOTOFF12", /* name */
377 FALSE
, /* partial_inplace */
378 0xfff, /* src_mask */
379 0xfff, /* dst_mask */
380 FALSE
), /* pcrel_offset */
382 /* The upper 16 bits of the GOT offset for the address of the
383 canonical descriptor of a function. */
384 HOWTO (R_FRV_FUNCDESC_GOTOFFHI
, /* type */
386 2, /* size (0 = byte, 1 = short, 2 = long) */
388 FALSE
, /* pc_relative */
390 complain_overflow_dont
, /* complain_on_overflow */
391 bfd_elf_generic_reloc
, /* special_function */
392 "R_FRV_FUNCDESC_GOTOFFHI", /* name */
393 FALSE
, /* partial_inplace */
394 0xffff, /* src_mask */
395 0xffff, /* dst_mask */
396 FALSE
), /* pcrel_offset */
398 /* The lower 16 bits of the GOT offset for the address of the
399 canonical descriptor of a function. */
400 HOWTO (R_FRV_FUNCDESC_GOTOFFLO
, /* type */
402 2, /* size (0 = byte, 1 = short, 2 = long) */
404 FALSE
, /* pc_relative */
406 complain_overflow_dont
, /* complain_on_overflow */
407 bfd_elf_generic_reloc
, /* special_function */
408 "R_FRV_FUNCDESC_GOTOFFLO", /* name */
409 FALSE
, /* partial_inplace */
410 0xffff, /* src_mask */
411 0xffff, /* dst_mask */
412 FALSE
), /* pcrel_offset */
414 /* A 12-bit signed operand with the GOT offset for the address of
416 HOWTO (R_FRV_GOTOFF12
, /* type */
418 2, /* size (0 = byte, 1 = short, 2 = long) */
420 FALSE
, /* pc_relative */
422 complain_overflow_signed
, /* complain_on_overflow */
423 bfd_elf_generic_reloc
, /* special_function */
424 "R_FRV_GOTOFF12", /* name */
425 FALSE
, /* partial_inplace */
426 0xfff, /* src_mask */
427 0xfff, /* dst_mask */
428 FALSE
), /* pcrel_offset */
430 /* The upper 16 bits of the GOT offset for the address of the
432 HOWTO (R_FRV_GOTOFFHI
, /* type */
434 2, /* size (0 = byte, 1 = short, 2 = long) */
436 FALSE
, /* pc_relative */
438 complain_overflow_dont
, /* complain_on_overflow */
439 bfd_elf_generic_reloc
, /* special_function */
440 "R_FRV_GOTOFFHI", /* name */
441 FALSE
, /* partial_inplace */
442 0xffff, /* src_mask */
443 0xffff, /* dst_mask */
444 FALSE
), /* pcrel_offset */
446 /* The lower 16 bits of the GOT offset for the address of the
448 HOWTO (R_FRV_GOTOFFLO
, /* type */
450 2, /* size (0 = byte, 1 = short, 2 = long) */
452 FALSE
, /* pc_relative */
454 complain_overflow_dont
, /* complain_on_overflow */
455 bfd_elf_generic_reloc
, /* special_function */
456 "R_FRV_GOTOFFLO", /* name */
457 FALSE
, /* partial_inplace */
458 0xffff, /* src_mask */
459 0xffff, /* dst_mask */
460 FALSE
), /* pcrel_offset */
462 /* A 24-bit pc-relative relocation referencing the TLS PLT entry for
463 a thread-local symbol. If the symbol number is 0, it refers to
465 HOWTO (R_FRV_GETTLSOFF
, /* type */
467 2, /* size (0 = byte, 1 = short, 2 = long) */
469 TRUE
, /* pc_relative */
471 complain_overflow_bitfield
, /* complain_on_overflow */
472 bfd_elf_generic_reloc
, /* special_function */
473 "R_FRV_GETTLSOFF", /* name */
474 FALSE
, /* partial_inplace */
475 0x7e03ffff, /* src_mask */
476 0x7e03ffff, /* dst_mask */
477 TRUE
), /* pcrel_offset */
479 /* A 64-bit TLS descriptor for a symbol. This relocation is only
480 valid as a REL, dynamic relocation. */
481 HOWTO (R_FRV_TLSDESC_VALUE
, /* type */
483 2, /* size (0 = byte, 1 = short, 2 = long) */
485 FALSE
, /* pc_relative */
487 complain_overflow_bitfield
, /* complain_on_overflow */
488 bfd_elf_generic_reloc
, /* special_function */
489 "R_FRV_TLSDESC_VALUE", /* name */
490 FALSE
, /* partial_inplace */
491 0xffffffff, /* src_mask */
492 0xffffffff, /* dst_mask */
493 FALSE
), /* pcrel_offset */
495 /* A 12-bit signed operand with the GOT offset for the TLS
496 descriptor of the symbol. */
497 HOWTO (R_FRV_GOTTLSDESC12
, /* type */
499 2, /* size (0 = byte, 1 = short, 2 = long) */
501 FALSE
, /* pc_relative */
503 complain_overflow_signed
, /* complain_on_overflow */
504 bfd_elf_generic_reloc
, /* special_function */
505 "R_FRV_GOTTLSDESC12", /* name */
506 FALSE
, /* partial_inplace */
507 0xfff, /* src_mask */
508 0xfff, /* dst_mask */
509 FALSE
), /* pcrel_offset */
511 /* The upper 16 bits of the GOT offset for the TLS descriptor of the
513 HOWTO (R_FRV_GOTTLSDESCHI
, /* type */
515 2, /* size (0 = byte, 1 = short, 2 = long) */
517 FALSE
, /* pc_relative */
519 complain_overflow_dont
, /* complain_on_overflow */
520 bfd_elf_generic_reloc
, /* special_function */
521 "R_FRV_GOTTLSDESCHI", /* name */
522 FALSE
, /* partial_inplace */
523 0xffff, /* src_mask */
524 0xffff, /* dst_mask */
525 FALSE
), /* pcrel_offset */
527 /* The lower 16 bits of the GOT offset for the TLS descriptor of the
529 HOWTO (R_FRV_GOTTLSDESCLO
, /* type */
531 2, /* size (0 = byte, 1 = short, 2 = long) */
533 FALSE
, /* pc_relative */
535 complain_overflow_dont
, /* complain_on_overflow */
536 bfd_elf_generic_reloc
, /* special_function */
537 "R_FRV_GOTTLSDESCLO", /* name */
538 FALSE
, /* partial_inplace */
539 0xffff, /* src_mask */
540 0xffff, /* dst_mask */
541 FALSE
), /* pcrel_offset */
543 /* A 12-bit signed operand with the offset from the module base
544 address to the thread-local symbol address. */
545 HOWTO (R_FRV_TLSMOFF12
, /* type */
547 2, /* size (0 = byte, 1 = short, 2 = long) */
549 FALSE
, /* pc_relative */
551 complain_overflow_signed
, /* complain_on_overflow */
552 bfd_elf_generic_reloc
, /* special_function */
553 "R_FRV_TLSMOFF12", /* name */
554 FALSE
, /* partial_inplace */
555 0xfff, /* src_mask */
556 0xfff, /* dst_mask */
557 FALSE
), /* pcrel_offset */
559 /* The upper 16 bits of the offset from the module base address to
560 the thread-local symbol address. */
561 HOWTO (R_FRV_TLSMOFFHI
, /* type */
563 2, /* size (0 = byte, 1 = short, 2 = long) */
565 FALSE
, /* pc_relative */
567 complain_overflow_dont
, /* complain_on_overflow */
568 bfd_elf_generic_reloc
, /* special_function */
569 "R_FRV_TLSMOFFHI", /* name */
570 FALSE
, /* partial_inplace */
571 0xffff, /* src_mask */
572 0xffff, /* dst_mask */
573 FALSE
), /* pcrel_offset */
575 /* The lower 16 bits of the offset from the module base address to
576 the thread-local symbol address. */
577 HOWTO (R_FRV_TLSMOFFLO
, /* type */
579 2, /* size (0 = byte, 1 = short, 2 = long) */
581 FALSE
, /* pc_relative */
583 complain_overflow_dont
, /* complain_on_overflow */
584 bfd_elf_generic_reloc
, /* special_function */
585 "R_FRV_TLSMOFFLO", /* name */
586 FALSE
, /* partial_inplace */
587 0xffff, /* src_mask */
588 0xffff, /* dst_mask */
589 FALSE
), /* pcrel_offset */
591 /* A 12-bit signed operand with the GOT offset for the TLSOFF entry
593 HOWTO (R_FRV_GOTTLSOFF12
, /* type */
595 2, /* size (0 = byte, 1 = short, 2 = long) */
597 FALSE
, /* pc_relative */
599 complain_overflow_signed
, /* complain_on_overflow */
600 bfd_elf_generic_reloc
, /* special_function */
601 "R_FRV_GOTTLSOFF12", /* name */
602 FALSE
, /* partial_inplace */
603 0xfff, /* src_mask */
604 0xfff, /* dst_mask */
605 FALSE
), /* pcrel_offset */
607 /* The upper 16 bits of the GOT offset for the TLSOFF entry for a
609 HOWTO (R_FRV_GOTTLSOFFHI
, /* type */
611 2, /* size (0 = byte, 1 = short, 2 = long) */
613 FALSE
, /* pc_relative */
615 complain_overflow_dont
, /* complain_on_overflow */
616 bfd_elf_generic_reloc
, /* special_function */
617 "R_FRV_GOTTLSOFFHI", /* name */
618 FALSE
, /* partial_inplace */
619 0xffff, /* src_mask */
620 0xffff, /* dst_mask */
621 FALSE
), /* pcrel_offset */
623 /* The lower 16 bits of the GOT offset for the TLSOFF entry for a
625 HOWTO (R_FRV_GOTTLSOFFLO
, /* type */
627 2, /* size (0 = byte, 1 = short, 2 = long) */
629 FALSE
, /* pc_relative */
631 complain_overflow_dont
, /* complain_on_overflow */
632 bfd_elf_generic_reloc
, /* special_function */
633 "R_FRV_GOTTLSOFFLO", /* name */
634 FALSE
, /* partial_inplace */
635 0xffff, /* src_mask */
636 0xffff, /* dst_mask */
637 FALSE
), /* pcrel_offset */
639 /* The 32-bit offset from the thread pointer (not the module base
640 address) to a thread-local symbol. */
641 HOWTO (R_FRV_TLSOFF
, /* type */
643 2, /* size (0 = byte, 1 = short, 2 = long) */
645 FALSE
, /* pc_relative */
647 complain_overflow_dont
, /* complain_on_overflow */
648 bfd_elf_generic_reloc
, /* special_function */
649 "R_FRV_TLSOFF", /* name */
650 FALSE
, /* partial_inplace */
651 0xffffffff, /* src_mask */
652 0xffffffff, /* dst_mask */
653 FALSE
), /* pcrel_offset */
655 /* An annotation for linker relaxation, that denotes the
656 symbol+addend whose TLS descriptor is referenced by the sum of
657 the two input registers of an ldd instruction. */
658 HOWTO (R_FRV_TLSDESC_RELAX
, /* type */
660 2, /* size (0 = byte, 1 = short, 2 = long) */
662 FALSE
, /* pc_relative */
664 complain_overflow_dont
, /* complain_on_overflow */
665 bfd_elf_generic_reloc
, /* special_function */
666 "R_FRV_TLSDESC_RELAX", /* name */
667 FALSE
, /* partial_inplace */
670 FALSE
), /* pcrel_offset */
672 /* An annotation for linker relaxation, that denotes the
673 symbol+addend whose TLS resolver entry point is given by the sum
674 of the two register operands of an calll instruction. */
675 HOWTO (R_FRV_GETTLSOFF_RELAX
, /* type */
677 2, /* size (0 = byte, 1 = short, 2 = long) */
679 FALSE
, /* pc_relative */
681 complain_overflow_dont
, /* complain_on_overflow */
682 bfd_elf_generic_reloc
, /* special_function */
683 "R_FRV_GETTLSOFF_RELAX", /* name */
684 FALSE
, /* partial_inplace */
687 FALSE
), /* pcrel_offset */
689 /* An annotation for linker relaxation, that denotes the
690 symbol+addend whose TLS offset GOT entry is given by the sum of
691 the two input registers of an ld instruction. */
692 HOWTO (R_FRV_TLSOFF_RELAX
, /* type */
694 2, /* size (0 = byte, 1 = short, 2 = long) */
696 FALSE
, /* pc_relative */
698 complain_overflow_bitfield
, /* complain_on_overflow */
699 bfd_elf_generic_reloc
, /* special_function */
700 "R_FRV_TLSOFF_RELAX", /* name */
701 FALSE
, /* partial_inplace */
704 FALSE
), /* pcrel_offset */
706 /* A 32-bit offset from the module base address to
707 the thread-local symbol address. */
708 HOWTO (R_FRV_TLSMOFF
, /* type */
710 2, /* size (0 = byte, 1 = short, 2 = long) */
712 FALSE
, /* pc_relative */
714 complain_overflow_dont
, /* complain_on_overflow */
715 bfd_elf_generic_reloc
, /* special_function */
716 "R_FRV_TLSMOFF", /* name */
717 FALSE
, /* partial_inplace */
718 0xffffffff, /* src_mask */
719 0xffffffff, /* dst_mask */
720 FALSE
), /* pcrel_offset */
723 /* GNU extension to record C++ vtable hierarchy. */
724 static reloc_howto_type elf32_frv_vtinherit_howto
=
725 HOWTO (R_FRV_GNU_VTINHERIT
, /* type */
727 2, /* size (0 = byte, 1 = short, 2 = long) */
729 FALSE
, /* pc_relative */
731 complain_overflow_dont
, /* complain_on_overflow */
732 NULL
, /* special_function */
733 "R_FRV_GNU_VTINHERIT", /* name */
734 FALSE
, /* partial_inplace */
737 FALSE
); /* pcrel_offset */
739 /* GNU extension to record C++ vtable member usage. */
740 static reloc_howto_type elf32_frv_vtentry_howto
=
741 HOWTO (R_FRV_GNU_VTENTRY
, /* type */
743 2, /* size (0 = byte, 1 = short, 2 = long) */
745 FALSE
, /* pc_relative */
747 complain_overflow_dont
, /* complain_on_overflow */
748 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
749 "R_FRV_GNU_VTENTRY", /* name */
750 FALSE
, /* partial_inplace */
753 FALSE
); /* pcrel_offset */
755 /* The following 3 relocations are REL. The only difference to the
756 entries in the table above are that partial_inplace is TRUE. */
757 static reloc_howto_type elf32_frv_rel_32_howto
=
758 HOWTO (R_FRV_32
, /* type */
760 2, /* size (0 = byte, 1 = short, 2 = long) */
762 FALSE
, /* pc_relative */
764 complain_overflow_bitfield
, /* complain_on_overflow */
765 bfd_elf_generic_reloc
, /* special_function */
766 "R_FRV_32", /* name */
767 TRUE
, /* partial_inplace */
768 0xffffffff, /* src_mask */
769 0xffffffff, /* dst_mask */
770 FALSE
); /* pcrel_offset */
772 static reloc_howto_type elf32_frv_rel_funcdesc_howto
=
773 HOWTO (R_FRV_FUNCDESC
, /* type */
775 2, /* size (0 = byte, 1 = short, 2 = long) */
777 FALSE
, /* pc_relative */
779 complain_overflow_bitfield
, /* complain_on_overflow */
780 bfd_elf_generic_reloc
, /* special_function */
781 "R_FRV_FUNCDESC", /* name */
782 TRUE
, /* partial_inplace */
783 0xffffffff, /* src_mask */
784 0xffffffff, /* dst_mask */
785 FALSE
); /* pcrel_offset */
787 static reloc_howto_type elf32_frv_rel_funcdesc_value_howto
=
788 HOWTO (R_FRV_FUNCDESC_VALUE
, /* type */
790 2, /* size (0 = byte, 1 = short, 2 = long) */
792 FALSE
, /* pc_relative */
794 complain_overflow_bitfield
, /* complain_on_overflow */
795 bfd_elf_generic_reloc
, /* special_function */
796 "R_FRV_FUNCDESC_VALUE", /* name */
797 TRUE
, /* partial_inplace */
798 0xffffffff, /* src_mask */
799 0xffffffff, /* dst_mask */
800 FALSE
); /* pcrel_offset */
802 static reloc_howto_type elf32_frv_rel_tlsdesc_value_howto
=
803 /* A 64-bit TLS descriptor for a symbol. The first word resolves to
804 an entry point, and the second resolves to a special argument.
805 If the symbol turns out to be in static TLS, the entry point is a
806 return instruction, and the special argument is the TLS offset
807 for the symbol. If it's in dynamic TLS, the entry point is a TLS
808 offset resolver, and the special argument is a pointer to a data
809 structure allocated by the dynamic loader, containing the GOT
810 address for the offset resolver, the module id, the offset within
811 the module, and anything else the TLS offset resolver might need
812 to determine the TLS offset for the symbol in the running
814 HOWTO (R_FRV_TLSDESC_VALUE
, /* type */
816 2, /* size (0 = byte, 1 = short, 2 = long) */
818 FALSE
, /* pc_relative */
820 complain_overflow_bitfield
, /* complain_on_overflow */
821 bfd_elf_generic_reloc
, /* special_function */
822 "R_FRV_TLSDESC_VALUE", /* name */
823 TRUE
, /* partial_inplace */
824 0xffffffff, /* src_mask */
825 0xffffffff, /* dst_mask */
826 FALSE
); /* pcrel_offset */
828 static reloc_howto_type elf32_frv_rel_tlsoff_howto
=
829 /* The 32-bit offset from the thread pointer (not the module base
830 address) to a thread-local symbol. */
831 HOWTO (R_FRV_TLSOFF
, /* type */
833 2, /* size (0 = byte, 1 = short, 2 = long) */
835 FALSE
, /* pc_relative */
837 complain_overflow_bitfield
, /* complain_on_overflow */
838 bfd_elf_generic_reloc
, /* special_function */
839 "R_FRV_TLSOFF", /* name */
840 TRUE
, /* partial_inplace */
841 0xffffffff, /* src_mask */
842 0xffffffff, /* dst_mask */
843 FALSE
); /* pcrel_offset */
847 extern const bfd_target bfd_elf32_frvfdpic_vec
;
848 #define IS_FDPIC(bfd) ((bfd)->xvec == &bfd_elf32_frvfdpic_vec)
850 /* An extension of the elf hash table data structure, containing some
851 additional FRV-specific data. */
852 struct frvfdpic_elf_link_hash_table
854 struct elf_link_hash_table elf
;
856 /* A pointer to the .got section. */
858 /* A pointer to the .rel.got section. */
860 /* A pointer to the .rofixup section. */
862 /* A pointer to the .plt section. */
864 /* A pointer to the .rel.plt section. */
866 /* GOT base offset. */
868 /* Location of the first non-lazy PLT entry, i.e., the number of
869 bytes taken by lazy PLT entries. If locally-bound TLS
870 descriptors require a ret instruction, it will be placed at this
873 /* A hash table holding information about which symbols were
874 referenced with which PIC-related relocations. */
875 struct htab
*relocs_info
;
876 /* Summary reloc information collected by
877 _frvfdpic_count_got_plt_entries. */
878 struct _frvfdpic_dynamic_got_info
*g
;
881 /* Get the FRV ELF linker hash table from a link_info structure. */
883 #define frvfdpic_hash_table(info) \
884 ((struct frvfdpic_elf_link_hash_table *) ((info)->hash))
886 #define frvfdpic_got_section(info) \
887 (frvfdpic_hash_table (info)->sgot)
888 #define frvfdpic_gotrel_section(info) \
889 (frvfdpic_hash_table (info)->sgotrel)
890 #define frvfdpic_gotfixup_section(info) \
891 (frvfdpic_hash_table (info)->sgotfixup)
892 #define frvfdpic_plt_section(info) \
893 (frvfdpic_hash_table (info)->splt)
894 #define frvfdpic_pltrel_section(info) \
895 (frvfdpic_hash_table (info)->spltrel)
896 #define frvfdpic_relocs_info(info) \
897 (frvfdpic_hash_table (info)->relocs_info)
898 #define frvfdpic_got_initial_offset(info) \
899 (frvfdpic_hash_table (info)->got0)
900 #define frvfdpic_plt_initial_offset(info) \
901 (frvfdpic_hash_table (info)->plt0)
902 #define frvfdpic_dynamic_got_plt_info(info) \
903 (frvfdpic_hash_table (info)->g)
905 /* Currently it's the same, but if some day we have a reason to change
906 it, we'd better be using a different macro.
908 FIXME: if there's any TLS PLT entry that uses local-exec or
909 initial-exec models, we could use the ret at the end of any of them
910 instead of adding one more. */
911 #define frvfdpic_plt_tls_ret_offset(info) \
912 (frvfdpic_plt_initial_offset (info))
914 /* The name of the dynamic interpreter. This is put in the .interp
917 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
919 #define DEFAULT_STACK_SIZE 0x20000
921 /* This structure is used to collect the number of entries present in
922 each addressable range of the got. */
923 struct _frvfdpic_dynamic_got_info
925 /* Several bits of information about the current link. */
926 struct bfd_link_info
*info
;
927 /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit
929 bfd_vma got12
, gotlos
, gothilo
;
930 /* Total GOT size needed for function descriptor entries within the 12-,
931 16- or 32-bit ranges. */
932 bfd_vma fd12
, fdlos
, fdhilo
;
933 /* Total GOT size needed by function descriptor entries referenced
934 in PLT entries, that would be profitable to place in offsets
935 close to the PIC register. */
937 /* Total PLT size needed by lazy PLT entries. */
939 /* Total GOT size needed for TLS descriptor entries within the 12-,
940 16- or 32-bit ranges. */
941 bfd_vma tlsd12
, tlsdlos
, tlsdhilo
;
942 /* Total GOT size needed by TLS descriptors referenced in PLT
943 entries, that would be profitable to place in offers close to the
946 /* Total PLT size needed by TLS lazy PLT entries. */
948 /* Number of relocations carried over from input object files. */
949 unsigned long relocs
;
950 /* Number of fixups introduced by relocations in input object files. */
951 unsigned long fixups
;
952 /* The number of fixups that reference the ret instruction added to
953 the PLT for locally-resolved TLS descriptors. */
954 unsigned long tls_ret_refs
;
957 /* This structure is used to assign offsets to got entries, function
958 descriptors, plt entries and lazy plt entries. */
960 struct _frvfdpic_dynamic_got_plt_info
962 /* Summary information collected with _frvfdpic_count_got_plt_entries. */
963 struct _frvfdpic_dynamic_got_info g
;
965 /* For each addressable range, we record a MAX (positive) and MIN
966 (negative) value. CUR is used to assign got entries, and it's
967 incremented from an initial positive value to MAX, then from MIN
968 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
969 assign function descriptors, and it's decreased from an initial
970 non-positive value to MIN, then from MAX down to CUR (unless CUR
971 wraps around first). All of MIN, MAX, CUR and FDCUR always point
972 to even words. ODD, if non-zero, indicates an odd word to be
973 used for the next got entry, otherwise CUR is used and
974 incremented by a pair of words, wrapping around when it reaches
975 MAX. FDCUR is decremented (and wrapped) before the next function
976 descriptor is chosen. FDPLT indicates the number of remaining
977 slots that can be used for function descriptors used only by PLT
980 TMAX, TMIN and TCUR are used to assign TLS descriptors. TCUR
981 starts as MAX, and grows up to TMAX, then wraps around to TMIN
982 and grows up to MIN. TLSDPLT indicates the number of remaining
983 slots that can be used for TLS descriptors used only by TLS PLT
985 struct _frvfdpic_dynamic_got_alloc_data
987 bfd_signed_vma max
, cur
, odd
, fdcur
, min
;
988 bfd_signed_vma tmax
, tcur
, tmin
;
989 bfd_vma fdplt
, tlsdplt
;
990 } got12
, gotlos
, gothilo
;
993 /* Create an FRV ELF linker hash table. */
995 static struct bfd_link_hash_table
*
996 frvfdpic_elf_link_hash_table_create (bfd
*abfd
)
998 struct frvfdpic_elf_link_hash_table
*ret
;
999 bfd_size_type amt
= sizeof (struct frvfdpic_elf_link_hash_table
);
1001 ret
= bfd_zalloc (abfd
, amt
);
1005 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1006 _bfd_elf_link_hash_newfunc
,
1007 sizeof (struct elf_link_hash_entry
)))
1013 return &ret
->elf
.root
;
1016 /* Decide whether a reference to a symbol can be resolved locally or
1017 not. If the symbol is protected, we want the local address, but
1018 its function descriptor must be assigned by the dynamic linker. */
1019 #define FRVFDPIC_SYM_LOCAL(INFO, H) \
1020 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
1021 || ! elf_hash_table (INFO)->dynamic_sections_created)
1022 #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \
1023 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
1025 /* This structure collects information on what kind of GOT, PLT or
1026 function descriptors are required by relocations that reference a
1028 struct frvfdpic_relocs_info
1030 /* The index of the symbol, as stored in the relocation r_info, if
1031 we have a local symbol; -1 otherwise. */
1035 /* The input bfd in which the symbol is defined, if it's a local
1038 /* If symndx == -1, the hash table entry corresponding to a global
1039 symbol (even if it turns out to bind locally, in which case it
1040 should ideally be replaced with section's symndx + addend). */
1041 struct elf_link_hash_entry
*h
;
1043 /* The addend of the relocation that references the symbol. */
1046 /* The fields above are used to identify an entry. The fields below
1047 contain information on how an entry is used and, later on, which
1048 locations it was assigned. */
1049 /* The following 3 fields record whether the symbol+addend above was
1050 ever referenced with a GOT relocation. The 12 suffix indicates a
1051 GOT12 relocation; los is used for GOTLO relocations that are not
1052 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
1057 /* Whether a FUNCDESC relocation references symbol+addend. */
1059 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
1061 unsigned fdgotlos
:1;
1062 unsigned fdgothilo
:1;
1063 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
1064 unsigned fdgoff12
:1;
1065 unsigned fdgofflos
:1;
1066 unsigned fdgoffhilo
:1;
1067 /* Whether a GETTLSOFF relocation references symbol+addend. */
1069 /* FIXME: we should probably add tlspltdesc, tlspltoff and
1070 tlspltimm, to tell what kind of TLS PLT entry we're generating.
1071 We might instead just pre-compute flags telling whether the
1072 object is suitable for local exec, initial exec or general
1073 dynamic addressing, and use that all over the place. We could
1074 also try to do a better job of merging TLSOFF and TLSDESC entries
1075 in main executables, but perhaps we can get rid of TLSDESC
1076 entirely in them instead. */
1077 /* Whether a GOTTLSDESC relocation references symbol+addend. */
1078 unsigned tlsdesc12
:1;
1079 unsigned tlsdesclos
:1;
1080 unsigned tlsdeschilo
:1;
1081 /* Whether a GOTTLSOFF relocation references symbol+addend. */
1082 unsigned tlsoff12
:1;
1083 unsigned tlsofflos
:1;
1084 unsigned tlsoffhilo
:1;
1085 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
1086 GOTOFFHI relocations. The addend doesn't really matter, since we
1087 envision that this will only be used to check whether the symbol
1088 is mapped to the same segment as the got. */
1090 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
1092 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
1095 /* Whether we need a PLT entry for a symbol. Should be implied by
1097 (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */
1099 /* Whether a function descriptor should be created in this link unit
1100 for symbol+addend. Should be implied by something like:
1101 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
1102 || ((fd || fdgot12 || fdgotlos || fdgothilo)
1103 && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */
1105 /* Whether a lazy PLT entry is needed for this symbol+addend.
1106 Should be implied by something like:
1107 (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)
1108 && ! (info->flags & DF_BIND_NOW)) */
1110 /* Whether we've already emitted GOT relocations and PLT entries as
1111 needed for this symbol. */
1114 /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and
1115 R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing
1117 unsigned relocs32
, relocsfd
, relocsfdv
, relocstlsd
, relocstlsoff
;
1119 /* The number of .rofixups entries and dynamic relocations allocated
1120 for this symbol, minus any that might have already been used. */
1121 unsigned fixups
, dynrelocs
;
1123 /* The offsets of the GOT entries assigned to symbol+addend, to the
1124 function descriptor's address, and to a function descriptor,
1125 respectively. Should be zero if unassigned. The offsets are
1126 counted from the value that will be assigned to the PIC register,
1127 not from the beginning of the .got section. */
1128 bfd_signed_vma got_entry
, fdgot_entry
, fd_entry
;
1129 /* The offsets of the PLT entries assigned to symbol+addend,
1130 non-lazy and lazy, respectively. If unassigned, should be
1132 bfd_vma plt_entry
, lzplt_entry
;
1133 /* The offsets of the GOT entries for TLS offset and TLS descriptor. */
1134 bfd_signed_vma tlsoff_entry
, tlsdesc_entry
;
1135 /* The offset of the TLS offset PLT entry. */
1136 bfd_vma tlsplt_entry
;
1139 /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */
1141 frvfdpic_relocs_info_hash (const void *entry_
)
1143 const struct frvfdpic_relocs_info
*entry
= entry_
;
1145 return (entry
->symndx
== -1
1146 ? (long) entry
->d
.h
->root
.root
.hash
1147 : entry
->symndx
+ (long) entry
->d
.abfd
->id
* 257) + entry
->addend
;
1150 /* Test whether the key fields of two frvfdpic_relocs_info entries are
1153 frvfdpic_relocs_info_eq (const void *entry1
, const void *entry2
)
1155 const struct frvfdpic_relocs_info
*e1
= entry1
;
1156 const struct frvfdpic_relocs_info
*e2
= entry2
;
1158 return e1
->symndx
== e2
->symndx
&& e1
->addend
== e2
->addend
1159 && (e1
->symndx
== -1 ? e1
->d
.h
== e2
->d
.h
: e1
->d
.abfd
== e2
->d
.abfd
);
1162 /* Find or create an entry in a hash table HT that matches the key
1163 fields of the given ENTRY. If it's not found, memory for a new
1164 entry is allocated in ABFD's obstack. */
1165 static struct frvfdpic_relocs_info
*
1166 frvfdpic_relocs_info_find (struct htab
*ht
,
1168 const struct frvfdpic_relocs_info
*entry
,
1169 enum insert_option insert
)
1171 struct frvfdpic_relocs_info
**loc
=
1172 (struct frvfdpic_relocs_info
**) htab_find_slot (ht
, entry
, insert
);
1180 *loc
= bfd_zalloc (abfd
, sizeof (**loc
));
1185 (*loc
)->symndx
= entry
->symndx
;
1186 (*loc
)->d
= entry
->d
;
1187 (*loc
)->addend
= entry
->addend
;
1188 (*loc
)->plt_entry
= (bfd_vma
)-1;
1189 (*loc
)->lzplt_entry
= (bfd_vma
)-1;
1190 (*loc
)->tlsplt_entry
= (bfd_vma
)-1;
1195 /* Obtain the address of the entry in HT associated with H's symbol +
1196 addend, creating a new entry if none existed. ABFD is only used
1197 for memory allocation purposes. */
1198 inline static struct frvfdpic_relocs_info
*
1199 frvfdpic_relocs_info_for_global (struct htab
*ht
,
1201 struct elf_link_hash_entry
*h
,
1203 enum insert_option insert
)
1205 struct frvfdpic_relocs_info entry
;
1209 entry
.addend
= addend
;
1211 return frvfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1214 /* Obtain the address of the entry in HT associated with the SYMNDXth
1215 local symbol of the input bfd ABFD, plus the addend, creating a new
1216 entry if none existed. */
1217 inline static struct frvfdpic_relocs_info
*
1218 frvfdpic_relocs_info_for_local (struct htab
*ht
,
1222 enum insert_option insert
)
1224 struct frvfdpic_relocs_info entry
;
1226 entry
.symndx
= symndx
;
1227 entry
.d
.abfd
= abfd
;
1228 entry
.addend
= addend
;
1230 return frvfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1233 /* Merge fields set by check_relocs() of two entries that end up being
1234 mapped to the same (presumably global) symbol. */
1237 frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info
*e2
,
1238 struct frvfdpic_relocs_info
const *e1
)
1240 e2
->got12
|= e1
->got12
;
1241 e2
->gotlos
|= e1
->gotlos
;
1242 e2
->gothilo
|= e1
->gothilo
;
1244 e2
->fdgot12
|= e1
->fdgot12
;
1245 e2
->fdgotlos
|= e1
->fdgotlos
;
1246 e2
->fdgothilo
|= e1
->fdgothilo
;
1247 e2
->fdgoff12
|= e1
->fdgoff12
;
1248 e2
->fdgofflos
|= e1
->fdgofflos
;
1249 e2
->fdgoffhilo
|= e1
->fdgoffhilo
;
1250 e2
->tlsplt
|= e1
->tlsplt
;
1251 e2
->tlsdesc12
|= e1
->tlsdesc12
;
1252 e2
->tlsdesclos
|= e1
->tlsdesclos
;
1253 e2
->tlsdeschilo
|= e1
->tlsdeschilo
;
1254 e2
->tlsoff12
|= e1
->tlsoff12
;
1255 e2
->tlsofflos
|= e1
->tlsofflos
;
1256 e2
->tlsoffhilo
|= e1
->tlsoffhilo
;
1257 e2
->gotoff
|= e1
->gotoff
;
1258 e2
->call
|= e1
->call
;
1262 /* Every block of 65535 lazy PLT entries shares a single call to the
1263 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
1264 32767, counting from 0). All other lazy PLT entries branch to it
1265 in a single instruction. */
1267 #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
1268 #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767)
1270 /* Add a dynamic relocation to the SRELOC section. */
1272 inline static bfd_vma
1273 _frvfdpic_add_dyn_reloc (bfd
*output_bfd
, asection
*sreloc
, bfd_vma offset
,
1274 int reloc_type
, long dynindx
, bfd_vma addend
,
1275 struct frvfdpic_relocs_info
*entry
)
1277 Elf_Internal_Rela outrel
;
1278 bfd_vma reloc_offset
;
1280 outrel
.r_offset
= offset
;
1281 outrel
.r_info
= ELF32_R_INFO (dynindx
, reloc_type
);
1282 outrel
.r_addend
= addend
;
1284 reloc_offset
= sreloc
->reloc_count
* sizeof (Elf32_External_Rel
);
1285 BFD_ASSERT (reloc_offset
< sreloc
->size
);
1286 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
1287 sreloc
->contents
+ reloc_offset
);
1288 sreloc
->reloc_count
++;
1290 /* If the entry's index is zero, this relocation was probably to a
1291 linkonce section that got discarded. We reserved a dynamic
1292 relocation, but it was for another entry than the one we got at
1293 the time of emitting the relocation. Unfortunately there's no
1294 simple way for us to catch this situation, since the relocation
1295 is cleared right before calling relocate_section, at which point
1296 we no longer know what the relocation used to point to. */
1299 BFD_ASSERT (entry
->dynrelocs
> 0);
1303 return reloc_offset
;
1306 /* Add a fixup to the ROFIXUP section. */
1309 _frvfdpic_add_rofixup (bfd
*output_bfd
, asection
*rofixup
, bfd_vma offset
,
1310 struct frvfdpic_relocs_info
*entry
)
1312 bfd_vma fixup_offset
;
1314 if (rofixup
->flags
& SEC_EXCLUDE
)
1317 fixup_offset
= rofixup
->reloc_count
* 4;
1318 if (rofixup
->contents
)
1320 BFD_ASSERT (fixup_offset
< rofixup
->size
);
1321 bfd_put_32 (output_bfd
, offset
, rofixup
->contents
+ fixup_offset
);
1323 rofixup
->reloc_count
++;
1325 if (entry
&& entry
->symndx
)
1327 /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc
1329 BFD_ASSERT (entry
->fixups
> 0);
1333 return fixup_offset
;
1336 /* Find the segment number in which OSEC, and output section, is
1340 _frvfdpic_osec_to_segment (bfd
*output_bfd
, asection
*osec
)
1342 struct elf_segment_map
*m
;
1343 Elf_Internal_Phdr
*p
;
1345 /* Find the segment that contains the output_section. */
1346 for (m
= elf_tdata (output_bfd
)->segment_map
,
1347 p
= elf_tdata (output_bfd
)->phdr
;
1353 for (i
= m
->count
- 1; i
>= 0; i
--)
1354 if (m
->sections
[i
] == osec
)
1361 return p
- elf_tdata (output_bfd
)->phdr
;
1364 inline static bfd_boolean
1365 _frvfdpic_osec_readonly_p (bfd
*output_bfd
, asection
*osec
)
1367 unsigned seg
= _frvfdpic_osec_to_segment (output_bfd
, osec
);
1369 return ! (elf_tdata (output_bfd
)->phdr
[seg
].p_flags
& PF_W
);
1372 #define FRVFDPIC_TLS_BIAS (2048 - 16)
1374 /* Return the base VMA address which should be subtracted from real addresses
1375 when resolving TLSMOFF relocation.
1376 This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */
1379 tls_biased_base (struct bfd_link_info
*info
)
1381 /* If tls_sec is NULL, we should have signalled an error already. */
1382 if (elf_hash_table (info
)->tls_sec
== NULL
)
1383 return FRVFDPIC_TLS_BIAS
;
1384 return elf_hash_table (info
)->tls_sec
->vma
+ FRVFDPIC_TLS_BIAS
;
1387 /* Generate relocations for GOT entries, function descriptors, and
1388 code for PLT and lazy PLT entries. */
1390 inline static bfd_boolean
1391 _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info
*entry
,
1393 struct bfd_link_info
*info
,
1395 Elf_Internal_Sym
*sym
,
1399 bfd_vma fd_lazy_rel_offset
= (bfd_vma
)-1;
1406 if (entry
->got_entry
|| entry
->fdgot_entry
|| entry
->fd_entry
1407 || entry
->tlsoff_entry
|| entry
->tlsdesc_entry
)
1409 /* If the symbol is dynamic, consider it for dynamic
1410 relocations, otherwise decay to section + offset. */
1411 if (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1)
1412 dynindx
= entry
->d
.h
->dynindx
;
1415 if (sec
->output_section
1416 && ! bfd_is_abs_section (sec
->output_section
)
1417 && ! bfd_is_und_section (sec
->output_section
))
1418 dynindx
= elf_section_data (sec
->output_section
)->dynindx
;
1424 /* Generate relocation for GOT entry pointing to the symbol. */
1425 if (entry
->got_entry
)
1428 bfd_vma ad
= addend
;
1430 /* If the symbol is dynamic but binds locally, use
1432 if (sec
&& (entry
->symndx
!= -1
1433 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1435 if (entry
->symndx
== -1)
1436 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1438 ad
+= sym
->st_value
;
1439 ad
+= sec
->output_offset
;
1440 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1441 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1446 /* If we're linking an executable at a fixed address, we can
1447 omit the dynamic relocation as long as the symbol is local to
1449 if (info
->executable
&& !info
->pie
1450 && (entry
->symndx
!= -1
1451 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1454 ad
+= sec
->output_section
->vma
;
1455 if (entry
->symndx
!= -1
1456 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1457 _frvfdpic_add_rofixup (output_bfd
,
1458 frvfdpic_gotfixup_section (info
),
1459 frvfdpic_got_section (info
)->output_section
1461 + frvfdpic_got_section (info
)->output_offset
1462 + frvfdpic_got_initial_offset (info
)
1463 + entry
->got_entry
, entry
);
1466 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1467 _bfd_elf_section_offset
1469 frvfdpic_got_section (info
),
1470 frvfdpic_got_initial_offset (info
)
1472 + frvfdpic_got_section (info
)
1473 ->output_section
->vma
1474 + frvfdpic_got_section (info
)->output_offset
,
1475 R_FRV_32
, idx
, ad
, entry
);
1477 bfd_put_32 (output_bfd
, ad
,
1478 frvfdpic_got_section (info
)->contents
1479 + frvfdpic_got_initial_offset (info
)
1480 + entry
->got_entry
);
1483 /* Generate relocation for GOT entry pointing to a canonical
1484 function descriptor. */
1485 if (entry
->fdgot_entry
)
1490 if (! (entry
->symndx
== -1
1491 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
1492 && FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1494 /* If the symbol is dynamic and there may be dynamic symbol
1495 resolution because we are, or are linked with, a shared
1496 library, emit a FUNCDESC relocation such that the dynamic
1497 linker will allocate the function descriptor. If the
1498 symbol needs a non-local function descriptor but binds
1499 locally (e.g., its visibility is protected, emit a
1500 dynamic relocation decayed to section+offset. */
1501 if (entry
->symndx
== -1
1502 && ! FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)
1503 && FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)
1504 && !(info
->executable
&& !info
->pie
))
1506 reloc
= R_FRV_FUNCDESC
;
1507 idx
= elf_section_data (entry
->d
.h
->root
.u
.def
.section
1508 ->output_section
)->dynindx
;
1509 ad
= entry
->d
.h
->root
.u
.def
.section
->output_offset
1510 + entry
->d
.h
->root
.u
.def
.value
;
1512 else if (entry
->symndx
== -1
1513 && ! FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
))
1515 reloc
= R_FRV_FUNCDESC
;
1520 (*info
->callbacks
->reloc_dangerous
)
1521 (info
, _("relocation requires zero addend"),
1522 elf_hash_table (info
)->dynobj
,
1523 frvfdpic_got_section (info
),
1524 entry
->fdgot_entry
);
1530 /* Otherwise, we know we have a private function descriptor,
1531 so reference it directly. */
1532 if (elf_hash_table (info
)->dynamic_sections_created
)
1533 BFD_ASSERT (entry
->privfd
);
1535 idx
= elf_section_data (frvfdpic_got_section (info
)
1536 ->output_section
)->dynindx
;
1537 ad
= frvfdpic_got_section (info
)->output_offset
1538 + frvfdpic_got_initial_offset (info
) + entry
->fd_entry
;
1541 /* If there is room for dynamic symbol resolution, emit the
1542 dynamic relocation. However, if we're linking an
1543 executable at a fixed location, we won't have emitted a
1544 dynamic symbol entry for the got section, so idx will be
1545 zero, which means we can and should compute the address
1546 of the private descriptor ourselves. */
1547 if (info
->executable
&& !info
->pie
1548 && (entry
->symndx
!= -1
1549 || FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)))
1551 ad
+= frvfdpic_got_section (info
)->output_section
->vma
;
1552 _frvfdpic_add_rofixup (output_bfd
,
1553 frvfdpic_gotfixup_section (info
),
1554 frvfdpic_got_section (info
)
1555 ->output_section
->vma
1556 + frvfdpic_got_section (info
)
1558 + frvfdpic_got_initial_offset (info
)
1559 + entry
->fdgot_entry
, entry
);
1562 _frvfdpic_add_dyn_reloc (output_bfd
,
1563 frvfdpic_gotrel_section (info
),
1564 _bfd_elf_section_offset
1566 frvfdpic_got_section (info
),
1567 frvfdpic_got_initial_offset (info
)
1568 + entry
->fdgot_entry
)
1569 + frvfdpic_got_section (info
)
1570 ->output_section
->vma
1571 + frvfdpic_got_section (info
)
1573 reloc
, idx
, ad
, entry
);
1576 bfd_put_32 (output_bfd
, ad
,
1577 frvfdpic_got_section (info
)->contents
1578 + frvfdpic_got_initial_offset (info
)
1579 + entry
->fdgot_entry
);
1582 /* Generate relocation to fill in a private function descriptor in
1584 if (entry
->fd_entry
)
1587 bfd_vma ad
= addend
;
1589 long lowword
, highword
;
1591 /* If the symbol is dynamic but binds locally, use
1593 if (sec
&& (entry
->symndx
!= -1
1594 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1596 if (entry
->symndx
== -1)
1597 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1599 ad
+= sym
->st_value
;
1600 ad
+= sec
->output_offset
;
1601 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1602 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1607 /* If we're linking an executable at a fixed address, we can
1608 omit the dynamic relocation as long as the symbol is local to
1610 if (info
->executable
&& !info
->pie
1611 && (entry
->symndx
!= -1 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1614 ad
+= sec
->output_section
->vma
;
1616 if (entry
->symndx
!= -1
1617 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1619 _frvfdpic_add_rofixup (output_bfd
,
1620 frvfdpic_gotfixup_section (info
),
1621 frvfdpic_got_section (info
)
1622 ->output_section
->vma
1623 + frvfdpic_got_section (info
)
1625 + frvfdpic_got_initial_offset (info
)
1626 + entry
->fd_entry
, entry
);
1627 _frvfdpic_add_rofixup (output_bfd
,
1628 frvfdpic_gotfixup_section (info
),
1629 frvfdpic_got_section (info
)
1630 ->output_section
->vma
1631 + frvfdpic_got_section (info
)
1633 + frvfdpic_got_initial_offset (info
)
1634 + entry
->fd_entry
+ 4, entry
);
1640 _frvfdpic_add_dyn_reloc (output_bfd
,
1642 ? frvfdpic_pltrel_section (info
)
1643 : frvfdpic_gotrel_section (info
),
1644 _bfd_elf_section_offset
1646 frvfdpic_got_section (info
),
1647 frvfdpic_got_initial_offset (info
)
1649 + frvfdpic_got_section (info
)
1650 ->output_section
->vma
1651 + frvfdpic_got_section (info
)
1653 R_FRV_FUNCDESC_VALUE
, idx
, ad
, entry
);
1656 /* If we've omitted the dynamic relocation, just emit the fixed
1657 addresses of the symbol and of the local GOT base offset. */
1658 if (info
->executable
&& !info
->pie
&& sec
&& sec
->output_section
)
1661 highword
= frvfdpic_got_section (info
)->output_section
->vma
1662 + frvfdpic_got_section (info
)->output_offset
1663 + frvfdpic_got_initial_offset (info
);
1665 else if (entry
->lazyplt
)
1669 (*info
->callbacks
->reloc_dangerous
)
1670 (info
, _("relocation requires zero addend"),
1671 elf_hash_table (info
)->dynobj
,
1672 frvfdpic_got_section (info
),
1677 fd_lazy_rel_offset
= ofst
;
1679 /* A function descriptor used for lazy or local resolving is
1680 initialized such that its high word contains the output
1681 section index in which the PLT entries are located, and
1682 the low word contains the address of the lazy PLT entry
1683 entry point, that must be within the memory region
1684 assigned to that section. */
1685 lowword
= entry
->lzplt_entry
+ 4
1686 + frvfdpic_plt_section (info
)->output_offset
1687 + frvfdpic_plt_section (info
)->output_section
->vma
;
1688 highword
= _frvfdpic_osec_to_segment
1689 (output_bfd
, frvfdpic_plt_section (info
)->output_section
);
1693 /* A function descriptor for a local function gets the index
1694 of the section. For a non-local function, it's
1697 if (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1
1698 && entry
->d
.h
->dynindx
== idx
)
1701 highword
= _frvfdpic_osec_to_segment
1702 (output_bfd
, sec
->output_section
);
1705 bfd_put_32 (output_bfd
, lowword
,
1706 frvfdpic_got_section (info
)->contents
1707 + frvfdpic_got_initial_offset (info
)
1709 bfd_put_32 (output_bfd
, highword
,
1710 frvfdpic_got_section (info
)->contents
1711 + frvfdpic_got_initial_offset (info
)
1712 + entry
->fd_entry
+ 4);
1715 /* Generate code for the PLT entry. */
1716 if (entry
->plt_entry
!= (bfd_vma
) -1)
1718 bfd_byte
*plt_code
= frvfdpic_plt_section (info
)->contents
1721 BFD_ASSERT (entry
->fd_entry
);
1723 /* Figure out what kind of PLT entry we need, depending on the
1724 location of the function descriptor within the GOT. */
1725 if (entry
->fd_entry
>= -(1 << (12 - 1))
1726 && entry
->fd_entry
< (1 << (12 - 1)))
1728 /* lddi @(gr15, fd_entry), gr14 */
1729 bfd_put_32 (output_bfd
,
1730 0x9cccf000 | (entry
->fd_entry
& ((1 << 12) - 1)),
1736 if (entry
->fd_entry
>= -(1 << (16 - 1))
1737 && entry
->fd_entry
< (1 << (16 - 1)))
1739 /* setlos lo(fd_entry), gr14 */
1740 bfd_put_32 (output_bfd
,
1742 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1748 /* sethi.p hi(fd_entry), gr14
1749 setlo lo(fd_entry), gr14 */
1750 bfd_put_32 (output_bfd
,
1752 | ((entry
->fd_entry
>> 16)
1753 & (((bfd_vma
)1 << 16) - 1)),
1756 bfd_put_32 (output_bfd
,
1758 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1762 /* ldd @(gr14,gr15),gr14 */
1763 bfd_put_32 (output_bfd
, 0x9c08e14f, plt_code
);
1766 /* jmpl @(gr14,gr0) */
1767 bfd_put_32 (output_bfd
, 0x8030e000, plt_code
);
1770 /* Generate code for the lazy PLT entry. */
1771 if (entry
->lzplt_entry
!= (bfd_vma
) -1)
1773 bfd_byte
*lzplt_code
= frvfdpic_plt_section (info
)->contents
1774 + entry
->lzplt_entry
;
1775 bfd_vma resolverStub_addr
;
1777 bfd_put_32 (output_bfd
, fd_lazy_rel_offset
, lzplt_code
);
1780 resolverStub_addr
= entry
->lzplt_entry
/ FRVFDPIC_LZPLT_BLOCK_SIZE
1781 * FRVFDPIC_LZPLT_BLOCK_SIZE
+ FRVFDPIC_LZPLT_RESOLV_LOC
;
1782 if (resolverStub_addr
>= frvfdpic_plt_initial_offset (info
))
1783 resolverStub_addr
= frvfdpic_plt_initial_offset (info
) - 12;
1785 if (entry
->lzplt_entry
== resolverStub_addr
)
1787 /* This is a lazy PLT entry that includes a resolver call. */
1788 /* ldd @(gr15,gr0), gr4
1790 bfd_put_32 (output_bfd
, 0x8808f140, lzplt_code
);
1791 bfd_put_32 (output_bfd
, 0x80304000, lzplt_code
+ 4);
1795 /* bra resolverStub */
1796 bfd_put_32 (output_bfd
,
1798 | (((resolverStub_addr
- entry
->lzplt_entry
)
1799 / 4) & (((bfd_vma
)1 << 16) - 1)),
1804 /* Generate relocation for GOT entry holding the TLS offset. */
1805 if (entry
->tlsoff_entry
)
1808 bfd_vma ad
= addend
;
1810 if (entry
->symndx
!= -1
1811 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
))
1813 /* If the symbol is dynamic but binds locally, use
1817 if (entry
->symndx
== -1)
1818 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1820 ad
+= sym
->st_value
;
1821 ad
+= sec
->output_offset
;
1822 if (sec
->output_section
1823 && elf_section_data (sec
->output_section
))
1824 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1830 /* *ABS*+addend is special for TLS relocations, use only the
1832 if (info
->executable
1834 && (bfd_is_abs_section (sec
)
1835 || bfd_is_und_section (sec
)))
1837 /* If we're linking an executable, we can entirely omit the
1838 dynamic relocation if the symbol is local to this module. */
1839 else if (info
->executable
1840 && (entry
->symndx
!= -1
1841 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1844 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1849 && (bfd_is_abs_section (sec
)
1850 || bfd_is_und_section (sec
)))
1852 if (! elf_hash_table (info
)->tls_sec
)
1854 (*info
->callbacks
->undefined_symbol
)
1855 (info
, "TLS section", elf_hash_table (info
)->dynobj
,
1856 frvfdpic_got_section (info
), entry
->tlsoff_entry
, TRUE
);
1859 idx
= elf_section_data (elf_hash_table (info
)->tls_sec
)->dynindx
;
1860 ad
+= FRVFDPIC_TLS_BIAS
;
1862 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1863 _bfd_elf_section_offset
1865 frvfdpic_got_section (info
),
1866 frvfdpic_got_initial_offset (info
)
1867 + entry
->tlsoff_entry
)
1868 + frvfdpic_got_section (info
)
1869 ->output_section
->vma
1870 + frvfdpic_got_section (info
)
1872 R_FRV_TLSOFF
, idx
, ad
, entry
);
1875 bfd_put_32 (output_bfd
, ad
,
1876 frvfdpic_got_section (info
)->contents
1877 + frvfdpic_got_initial_offset (info
)
1878 + entry
->tlsoff_entry
);
1881 if (entry
->tlsdesc_entry
)
1884 bfd_vma ad
= addend
;
1886 /* If the symbol is dynamic but binds locally, use
1888 if (sec
&& (entry
->symndx
!= -1
1889 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1891 if (entry
->symndx
== -1)
1892 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1894 ad
+= sym
->st_value
;
1895 ad
+= sec
->output_offset
;
1896 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1897 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1902 /* If we didn't set up a TLS offset entry, but we're linking an
1903 executable and the symbol binds locally, we can use the
1904 module offset in the TLS descriptor in relaxations. */
1905 if (info
->executable
&& ! entry
->tlsoff_entry
)
1906 entry
->tlsoff_entry
= entry
->tlsdesc_entry
+ 4;
1908 if (info
->executable
&& !info
->pie
1910 && (bfd_is_abs_section (sec
)
1911 || bfd_is_und_section (sec
)))
1912 || entry
->symndx
!= -1
1913 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1915 /* *ABS*+addend is special for TLS relocations, use only the
1916 addend for the TLS offset, and take the module id as
1919 && (bfd_is_abs_section (sec
)
1920 || bfd_is_und_section (sec
)))
1922 /* For other TLS symbols that bind locally, add the section
1923 TLS offset to the addend. */
1925 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1927 bfd_put_32 (output_bfd
,
1928 frvfdpic_plt_section (info
)->output_section
->vma
1929 + frvfdpic_plt_section (info
)->output_offset
1930 + frvfdpic_plt_tls_ret_offset (info
),
1931 frvfdpic_got_section (info
)->contents
1932 + frvfdpic_got_initial_offset (info
)
1933 + entry
->tlsdesc_entry
);
1935 _frvfdpic_add_rofixup (output_bfd
,
1936 frvfdpic_gotfixup_section (info
),
1937 frvfdpic_got_section (info
)
1938 ->output_section
->vma
1939 + frvfdpic_got_section (info
)
1941 + frvfdpic_got_initial_offset (info
)
1942 + entry
->tlsdesc_entry
, entry
);
1944 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
);
1946 /* We've used one of the reserved fixups, so discount it so
1947 that we can check at the end that we've used them
1949 frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
--;
1951 /* While at that, make sure the ret instruction makes to the
1952 right location in the PLT. We could do it only when we
1953 got to 0, but since the check at the end will only print
1954 a warning, make sure we have the ret in place in case the
1955 warning is missed. */
1956 bfd_put_32 (output_bfd
, 0xc03a4000,
1957 frvfdpic_plt_section (info
)->contents
1958 + frvfdpic_plt_tls_ret_offset (info
));
1963 && (bfd_is_abs_section (sec
)
1964 || bfd_is_und_section (sec
)))
1966 if (! elf_hash_table (info
)->tls_sec
)
1968 (*info
->callbacks
->undefined_symbol
)
1969 (info
, "TLS section", elf_hash_table (info
)->dynobj
,
1970 frvfdpic_got_section (info
), entry
->tlsdesc_entry
, TRUE
);
1973 idx
= elf_section_data (elf_hash_table (info
)->tls_sec
)->dynindx
;
1974 ad
+= FRVFDPIC_TLS_BIAS
;
1977 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1978 _bfd_elf_section_offset
1980 frvfdpic_got_section (info
),
1981 frvfdpic_got_initial_offset (info
)
1982 + entry
->tlsdesc_entry
)
1983 + frvfdpic_got_section (info
)
1984 ->output_section
->vma
1985 + frvfdpic_got_section (info
)
1987 R_FRV_TLSDESC_VALUE
, idx
, ad
, entry
);
1989 bfd_put_32 (output_bfd
, 0,
1990 frvfdpic_got_section (info
)->contents
1991 + frvfdpic_got_initial_offset (info
)
1992 + entry
->tlsdesc_entry
);
1995 bfd_put_32 (output_bfd
, ad
,
1996 frvfdpic_got_section (info
)->contents
1997 + frvfdpic_got_initial_offset (info
)
1998 + entry
->tlsdesc_entry
+ 4);
2001 /* Generate code for the get-TLS-offset PLT entry. */
2002 if (entry
->tlsplt_entry
!= (bfd_vma
) -1)
2004 bfd_byte
*plt_code
= frvfdpic_plt_section (info
)->contents
2005 + entry
->tlsplt_entry
;
2007 if (info
->executable
2008 && (entry
->symndx
!= -1
2009 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
2012 bfd_vma ad
= addend
;
2014 /* sec may be NULL when referencing an undefweak symbol
2015 while linking a static executable. */
2018 BFD_ASSERT (entry
->symndx
== -1
2019 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
);
2023 if (entry
->symndx
== -1)
2024 ad
+= entry
->d
.h
->root
.u
.def
.value
;
2026 ad
+= sym
->st_value
;
2027 ad
+= sec
->output_offset
;
2028 if (sec
->output_section
2029 && elf_section_data (sec
->output_section
))
2030 idx
= elf_section_data (sec
->output_section
)->dynindx
;
2035 /* *ABS*+addend is special for TLS relocations, use only the
2036 addend for the TLS offset, and take the module id as
2039 && (bfd_is_abs_section (sec
)
2040 || bfd_is_und_section (sec
)))
2042 /* For other TLS symbols that bind locally, add the section
2043 TLS offset to the addend. */
2045 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
2047 if ((bfd_signed_vma
)ad
>= -(1 << (16 - 1))
2048 && (bfd_signed_vma
)ad
< (1 << (16 - 1)))
2050 /* setlos lo(ad), gr9 */
2051 bfd_put_32 (output_bfd
,
2054 & (((bfd_vma
)1 << 16) - 1)),
2060 /* sethi.p hi(ad), gr9
2061 setlo lo(ad), gr9 */
2062 bfd_put_32 (output_bfd
,
2065 & (((bfd_vma
)1 << 16) - 1)),
2068 bfd_put_32 (output_bfd
,
2071 & (((bfd_vma
)1 << 16) - 1)),
2076 bfd_put_32 (output_bfd
, 0xc03a4000, plt_code
);
2078 else if (entry
->tlsoff_entry
)
2080 /* Figure out what kind of PLT entry we need, depending on the
2081 location of the TLS descriptor within the GOT. */
2082 if (entry
->tlsoff_entry
>= -(1 << (12 - 1))
2083 && entry
->tlsoff_entry
< (1 << (12 - 1)))
2085 /* ldi @(gr15, tlsoff_entry), gr9 */
2086 bfd_put_32 (output_bfd
,
2087 0x92c8f000 | (entry
->tlsoff_entry
2094 if (entry
->tlsoff_entry
>= -(1 << (16 - 1))
2095 && entry
->tlsoff_entry
< (1 << (16 - 1)))
2097 /* setlos lo(tlsoff_entry), gr8 */
2098 bfd_put_32 (output_bfd
,
2100 | (entry
->tlsoff_entry
2101 & (((bfd_vma
)1 << 16) - 1)),
2107 /* sethi.p hi(tlsoff_entry), gr8
2108 setlo lo(tlsoff_entry), gr8 */
2109 bfd_put_32 (output_bfd
,
2111 | ((entry
->tlsoff_entry
>> 16)
2112 & (((bfd_vma
)1 << 16) - 1)),
2115 bfd_put_32 (output_bfd
,
2117 | (entry
->tlsoff_entry
2118 & (((bfd_vma
)1 << 16) - 1)),
2122 /* ld @(gr15,gr8),gr9 */
2123 bfd_put_32 (output_bfd
, 0x9008f108, plt_code
);
2127 bfd_put_32 (output_bfd
, 0xc03a4000, plt_code
);
2131 BFD_ASSERT (entry
->tlsdesc_entry
);
2133 /* Figure out what kind of PLT entry we need, depending on the
2134 location of the TLS descriptor within the GOT. */
2135 if (entry
->tlsdesc_entry
>= -(1 << (12 - 1))
2136 && entry
->tlsdesc_entry
< (1 << (12 - 1)))
2138 /* lddi @(gr15, tlsdesc_entry), gr8 */
2139 bfd_put_32 (output_bfd
,
2140 0x90ccf000 | (entry
->tlsdesc_entry
2147 if (entry
->tlsdesc_entry
>= -(1 << (16 - 1))
2148 && entry
->tlsdesc_entry
< (1 << (16 - 1)))
2150 /* setlos lo(tlsdesc_entry), gr8 */
2151 bfd_put_32 (output_bfd
,
2153 | (entry
->tlsdesc_entry
2154 & (((bfd_vma
)1 << 16) - 1)),
2160 /* sethi.p hi(tlsdesc_entry), gr8
2161 setlo lo(tlsdesc_entry), gr8 */
2162 bfd_put_32 (output_bfd
,
2164 | ((entry
->tlsdesc_entry
>> 16)
2165 & (((bfd_vma
)1 << 16) - 1)),
2168 bfd_put_32 (output_bfd
,
2170 | (entry
->tlsdesc_entry
2171 & (((bfd_vma
)1 << 16) - 1)),
2175 /* ldd @(gr15,gr8),gr8 */
2176 bfd_put_32 (output_bfd
, 0x9008f148, plt_code
);
2179 /* jmpl @(gr8,gr0) */
2180 bfd_put_32 (output_bfd
, 0x80308000, plt_code
);
2187 /* Handle an FRV small data reloc. */
2189 static bfd_reloc_status_type
2190 elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, relocation
,
2192 struct bfd_link_info
*info
;
2194 asection
*input_section
;
2195 Elf_Internal_Rela
*relocation
;
2201 struct bfd_link_hash_entry
*h
;
2203 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2205 gp
= (h
->u
.def
.value
2206 + h
->u
.def
.section
->output_section
->vma
2207 + h
->u
.def
.section
->output_offset
);
2209 value
-= input_section
->output_section
->vma
;
2210 value
-= (gp
- input_section
->output_section
->vma
);
2212 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2214 value
+= relocation
->r_addend
;
2216 if ((long) value
> 0x7ff || (long) value
< -0x800)
2217 return bfd_reloc_overflow
;
2219 bfd_put_32 (input_bfd
,
2220 (insn
& 0xfffff000) | (value
& 0xfff),
2221 contents
+ relocation
->r_offset
);
2223 return bfd_reloc_ok
;
2226 /* Handle an FRV small data reloc. for the u12 field. */
2228 static bfd_reloc_status_type
2229 elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, relocation
,
2231 struct bfd_link_info
*info
;
2233 asection
*input_section
;
2234 Elf_Internal_Rela
*relocation
;
2240 struct bfd_link_hash_entry
*h
;
2243 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2245 gp
= (h
->u
.def
.value
2246 + h
->u
.def
.section
->output_section
->vma
2247 + h
->u
.def
.section
->output_offset
);
2249 value
-= input_section
->output_section
->vma
;
2250 value
-= (gp
- input_section
->output_section
->vma
);
2252 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2254 value
+= relocation
->r_addend
;
2256 if ((long) value
> 0x7ff || (long) value
< -0x800)
2257 return bfd_reloc_overflow
;
2259 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
2261 insn
= (insn
& ~mask
) | ((value
& 0xfc0) << 12) | (value
& 0x3f);
2263 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2265 return bfd_reloc_ok
;
2268 /* Handle an FRV ELF HI16 reloc. */
2270 static bfd_reloc_status_type
2271 elf32_frv_relocate_hi16 (input_bfd
, relhi
, contents
, value
)
2273 Elf_Internal_Rela
*relhi
;
2279 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
2281 value
+= relhi
->r_addend
;
2282 value
= ((value
>> 16) & 0xffff);
2284 insn
= (insn
& 0xffff0000) | value
;
2286 if ((long) value
> 0xffff || (long) value
< -0x10000)
2287 return bfd_reloc_overflow
;
2289 bfd_put_32 (input_bfd
, insn
, contents
+ relhi
->r_offset
);
2290 return bfd_reloc_ok
;
2293 static bfd_reloc_status_type
2294 elf32_frv_relocate_lo16 (input_bfd
, rello
, contents
, value
)
2296 Elf_Internal_Rela
*rello
;
2302 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2304 value
+= rello
->r_addend
;
2305 value
= value
& 0xffff;
2307 insn
= (insn
& 0xffff0000) | value
;
2309 if ((long) value
> 0xffff || (long) value
< -0x10000)
2310 return bfd_reloc_overflow
;
2312 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
2313 return bfd_reloc_ok
;
2316 /* Perform the relocation for the CALL label24 instruction. */
2318 static bfd_reloc_status_type
2319 elf32_frv_relocate_label24 (input_bfd
, input_section
, rello
, contents
, value
)
2321 asection
*input_section
;
2322 Elf_Internal_Rela
*rello
;
2330 /* The format for the call instruction is:
2332 0 000000 0001111 000000000000000000
2333 label6 opcode label18
2335 The branch calculation is: pc + (4*label24)
2336 where label24 is the concatenation of label6 and label18. */
2338 /* Grab the instruction. */
2339 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2341 value
-= input_section
->output_section
->vma
+ input_section
->output_offset
;
2342 value
-= rello
->r_offset
;
2343 value
+= rello
->r_addend
;
2347 label6
= value
& 0xfc0000;
2348 label6
= label6
<< 7;
2350 label18
= value
& 0x3ffff;
2352 insn
= insn
& 0x803c0000;
2353 insn
= insn
| label6
;
2354 insn
= insn
| label18
;
2356 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
2358 return bfd_reloc_ok
;
2361 static bfd_reloc_status_type
2362 elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, relocation
,
2364 struct bfd_link_info
*info
;
2366 asection
*input_section
;
2367 Elf_Internal_Rela
*relocation
;
2373 struct bfd_link_hash_entry
*h
;
2375 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2377 gp
= (h
->u
.def
.value
2378 + h
->u
.def
.section
->output_section
->vma
2379 + h
->u
.def
.section
->output_offset
);
2381 value
-= input_section
->output_section
->vma
;
2382 value
-= (gp
- input_section
->output_section
->vma
);
2383 value
+= relocation
->r_addend
;
2384 value
= ((value
>> 16) & 0xffff);
2386 if ((long) value
> 0xffff || (long) value
< -0x10000)
2387 return bfd_reloc_overflow
;
2389 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2390 insn
= (insn
& 0xffff0000) | value
;
2392 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2393 return bfd_reloc_ok
;
2396 static bfd_reloc_status_type
2397 elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, relocation
,
2399 struct bfd_link_info
*info
;
2401 asection
*input_section
;
2402 Elf_Internal_Rela
*relocation
;
2408 struct bfd_link_hash_entry
*h
;
2410 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2412 gp
= (h
->u
.def
.value
2413 + h
->u
.def
.section
->output_section
->vma
2414 + h
->u
.def
.section
->output_offset
);
2416 value
-= input_section
->output_section
->vma
;
2417 value
-= (gp
- input_section
->output_section
->vma
);
2418 value
+= relocation
->r_addend
;
2419 value
= value
& 0xffff;
2421 if ((long) value
> 0xffff || (long) value
< -0x10000)
2422 return bfd_reloc_overflow
;
2424 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2425 insn
= (insn
& 0xffff0000) | value
;
2427 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2429 return bfd_reloc_ok
;
2432 static reloc_howto_type
*
2433 frv_reloc_type_lookup (abfd
, code
)
2434 bfd
*abfd ATTRIBUTE_UNUSED
;
2435 bfd_reloc_code_real_type code
;
2442 case BFD_RELOC_NONE
:
2443 return &elf32_frv_howto_table
[ (int) R_FRV_NONE
];
2446 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2447 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2448 return &elf32_frv_rel_32_howto
;
2450 case BFD_RELOC_CTOR
:
2451 return &elf32_frv_howto_table
[ (int) R_FRV_32
];
2453 case BFD_RELOC_FRV_LABEL16
:
2454 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL16
];
2456 case BFD_RELOC_FRV_LABEL24
:
2457 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL24
];
2459 case BFD_RELOC_FRV_LO16
:
2460 return &elf32_frv_howto_table
[ (int) R_FRV_LO16
];
2462 case BFD_RELOC_FRV_HI16
:
2463 return &elf32_frv_howto_table
[ (int) R_FRV_HI16
];
2465 case BFD_RELOC_FRV_GPREL12
:
2466 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL12
];
2468 case BFD_RELOC_FRV_GPRELU12
:
2469 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELU12
];
2471 case BFD_RELOC_FRV_GPREL32
:
2472 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL32
];
2474 case BFD_RELOC_FRV_GPRELHI
:
2475 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELHI
];
2477 case BFD_RELOC_FRV_GPRELLO
:
2478 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELLO
];
2480 case BFD_RELOC_FRV_GOT12
:
2481 return &elf32_frv_howto_table
[ (int) R_FRV_GOT12
];
2483 case BFD_RELOC_FRV_GOTHI
:
2484 return &elf32_frv_howto_table
[ (int) R_FRV_GOTHI
];
2486 case BFD_RELOC_FRV_GOTLO
:
2487 return &elf32_frv_howto_table
[ (int) R_FRV_GOTLO
];
2489 case BFD_RELOC_FRV_FUNCDESC
:
2490 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2491 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2492 return &elf32_frv_rel_funcdesc_howto
;
2493 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC
];
2495 case BFD_RELOC_FRV_FUNCDESC_GOT12
:
2496 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOT12
];
2498 case BFD_RELOC_FRV_FUNCDESC_GOTHI
:
2499 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTHI
];
2501 case BFD_RELOC_FRV_FUNCDESC_GOTLO
:
2502 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTLO
];
2504 case BFD_RELOC_FRV_FUNCDESC_VALUE
:
2505 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2506 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2507 return &elf32_frv_rel_funcdesc_value_howto
;
2508 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_VALUE
];
2510 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12
:
2511 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFF12
];
2513 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI
:
2514 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFHI
];
2516 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO
:
2517 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFLO
];
2519 case BFD_RELOC_FRV_GOTOFF12
:
2520 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFF12
];
2522 case BFD_RELOC_FRV_GOTOFFHI
:
2523 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFHI
];
2525 case BFD_RELOC_FRV_GOTOFFLO
:
2526 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFLO
];
2528 case BFD_RELOC_FRV_GETTLSOFF
:
2529 return &elf32_frv_howto_table
[ (int) R_FRV_GETTLSOFF
];
2531 case BFD_RELOC_FRV_TLSDESC_VALUE
:
2532 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2533 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2534 return &elf32_frv_rel_tlsdesc_value_howto
;
2535 return &elf32_frv_howto_table
[ (int) R_FRV_TLSDESC_VALUE
];
2537 case BFD_RELOC_FRV_GOTTLSDESC12
:
2538 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESC12
];
2540 case BFD_RELOC_FRV_GOTTLSDESCHI
:
2541 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESCHI
];
2543 case BFD_RELOC_FRV_GOTTLSDESCLO
:
2544 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESCLO
];
2546 case BFD_RELOC_FRV_TLSMOFF12
:
2547 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFF12
];
2549 case BFD_RELOC_FRV_TLSMOFFHI
:
2550 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFFHI
];
2552 case BFD_RELOC_FRV_TLSMOFFLO
:
2553 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFFLO
];
2555 case BFD_RELOC_FRV_GOTTLSOFF12
:
2556 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFF12
];
2558 case BFD_RELOC_FRV_GOTTLSOFFHI
:
2559 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFFHI
];
2561 case BFD_RELOC_FRV_GOTTLSOFFLO
:
2562 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFFLO
];
2564 case BFD_RELOC_FRV_TLSOFF
:
2565 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2566 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2567 return &elf32_frv_rel_tlsoff_howto
;
2568 return &elf32_frv_howto_table
[ (int) R_FRV_TLSOFF
];
2570 case BFD_RELOC_FRV_TLSDESC_RELAX
:
2571 return &elf32_frv_howto_table
[ (int) R_FRV_TLSDESC_RELAX
];
2573 case BFD_RELOC_FRV_GETTLSOFF_RELAX
:
2574 return &elf32_frv_howto_table
[ (int) R_FRV_GETTLSOFF_RELAX
];
2576 case BFD_RELOC_FRV_TLSOFF_RELAX
:
2577 return &elf32_frv_howto_table
[ (int) R_FRV_TLSOFF_RELAX
];
2579 case BFD_RELOC_FRV_TLSMOFF
:
2580 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFF
];
2582 case BFD_RELOC_VTABLE_INHERIT
:
2583 return &elf32_frv_vtinherit_howto
;
2585 case BFD_RELOC_VTABLE_ENTRY
:
2586 return &elf32_frv_vtentry_howto
;
2592 /* Set the howto pointer for an FRV ELF reloc. */
2595 frv_info_to_howto_rela (abfd
, cache_ptr
, dst
)
2596 bfd
*abfd ATTRIBUTE_UNUSED
;
2598 Elf_Internal_Rela
*dst
;
2600 unsigned int r_type
;
2602 r_type
= ELF32_R_TYPE (dst
->r_info
);
2605 case R_FRV_GNU_VTINHERIT
:
2606 cache_ptr
->howto
= &elf32_frv_vtinherit_howto
;
2609 case R_FRV_GNU_VTENTRY
:
2610 cache_ptr
->howto
= &elf32_frv_vtentry_howto
;
2614 cache_ptr
->howto
= & elf32_frv_howto_table
[r_type
];
2619 /* Set the howto pointer for an FRV ELF REL reloc. */
2621 frvfdpic_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
2622 arelent
*cache_ptr
, Elf_Internal_Rela
*dst
)
2624 unsigned int r_type
;
2626 r_type
= ELF32_R_TYPE (dst
->r_info
);
2630 cache_ptr
->howto
= &elf32_frv_rel_32_howto
;
2633 case R_FRV_FUNCDESC
:
2634 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_howto
;
2637 case R_FRV_FUNCDESC_VALUE
:
2638 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_value_howto
;
2641 case R_FRV_TLSDESC_VALUE
:
2642 cache_ptr
->howto
= &elf32_frv_rel_tlsdesc_value_howto
;
2646 cache_ptr
->howto
= &elf32_frv_rel_tlsoff_howto
;
2650 cache_ptr
->howto
= NULL
;
2655 /* Perform a single relocation. By default we use the standard BFD
2656 routines, but a few relocs, we have to do them ourselves. */
2658 static bfd_reloc_status_type
2659 frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
, rel
,
2661 reloc_howto_type
*howto
;
2663 asection
*input_section
;
2665 Elf_Internal_Rela
*rel
;
2668 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2669 contents
, rel
->r_offset
, relocation
,
2674 /* Relocate an FRV ELF section.
2676 The RELOCATE_SECTION function is called by the new ELF backend linker
2677 to handle the relocations for a section.
2679 The relocs are always passed as Rela structures; if the section
2680 actually uses Rel structures, the r_addend field will always be
2683 This function is responsible for adjusting the section contents as
2684 necessary, and (if using Rela relocs and generating a relocatable
2685 output file) adjusting the reloc addend as necessary.
2687 This function does not have to worry about setting the reloc
2688 address or the reloc symbol index.
2690 LOCAL_SYMS is a pointer to the swapped in local symbols.
2692 LOCAL_SECTIONS is an array giving the section in the input file
2693 corresponding to the st_shndx field of each local symbol.
2695 The global hash table entry for the global symbols can be found
2696 via elf_sym_hashes (input_bfd).
2698 When generating relocatable output, this function must handle
2699 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2700 going to be the section symbol corresponding to the output
2701 section, which means that the addend must be adjusted
2705 elf32_frv_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2706 contents
, relocs
, local_syms
, local_sections
)
2707 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2708 struct bfd_link_info
*info
;
2710 asection
*input_section
;
2712 Elf_Internal_Rela
*relocs
;
2713 Elf_Internal_Sym
*local_syms
;
2714 asection
**local_sections
;
2716 Elf_Internal_Shdr
*symtab_hdr
;
2717 struct elf_link_hash_entry
**sym_hashes
;
2718 Elf_Internal_Rela
*rel
;
2719 Elf_Internal_Rela
*relend
;
2720 unsigned isec_segment
, got_segment
, plt_segment
, gprel_segment
, tls_segment
,
2722 int silence_segment_error
= !(info
->shared
|| info
->pie
);
2725 if (info
->relocatable
)
2728 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
2729 sym_hashes
= elf_sym_hashes (input_bfd
);
2730 relend
= relocs
+ input_section
->reloc_count
;
2732 isec_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2733 input_section
->output_section
);
2734 if (IS_FDPIC (output_bfd
) && frvfdpic_got_section (info
))
2735 got_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2736 frvfdpic_got_section (info
)
2740 if (IS_FDPIC (output_bfd
) && frvfdpic_gotfixup_section (info
))
2741 gprel_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2742 frvfdpic_gotfixup_section (info
)
2746 if (IS_FDPIC (output_bfd
) && frvfdpic_plt_section (info
))
2747 plt_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2748 frvfdpic_plt_section (info
)
2752 if (elf_hash_table (info
)->tls_sec
)
2753 tls_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2754 elf_hash_table (info
)->tls_sec
);
2758 for (rel
= relocs
; rel
< relend
; rel
++)
2760 reloc_howto_type
*howto
;
2761 unsigned long r_symndx
;
2762 Elf_Internal_Sym
*sym
;
2764 struct elf_link_hash_entry
*h
;
2766 bfd_reloc_status_type r
;
2767 const char * name
= NULL
;
2770 struct frvfdpic_relocs_info
*picrel
;
2771 bfd_vma orig_addend
= rel
->r_addend
;
2773 r_type
= ELF32_R_TYPE (rel
->r_info
);
2775 if ( r_type
== R_FRV_GNU_VTINHERIT
2776 || r_type
== R_FRV_GNU_VTENTRY
)
2779 /* This is a final link. */
2780 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2781 howto
= elf32_frv_howto_table
+ ELF32_R_TYPE (rel
->r_info
);
2786 if (r_symndx
< symtab_hdr
->sh_info
)
2788 sym
= local_syms
+ r_symndx
;
2789 osec
= sec
= local_sections
[r_symndx
];
2790 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2792 name
= bfd_elf_string_from_elf_section
2793 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
2794 name
= (name
== NULL
) ? bfd_section_name (input_bfd
, sec
) : name
;
2798 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2800 while (h
->root
.type
== bfd_link_hash_indirect
2801 || h
->root
.type
== bfd_link_hash_warning
)
2802 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2804 name
= h
->root
.root
.string
;
2806 if ((h
->root
.type
== bfd_link_hash_defined
2807 || h
->root
.type
== bfd_link_hash_defweak
))
2809 if (/* TLSMOFF forces local binding. */
2810 r_type
!= R_FRV_TLSMOFF
2811 && ! FRVFDPIC_SYM_LOCAL (info
, h
))
2818 sec
= h
->root
.u
.def
.section
;
2819 relocation
= (h
->root
.u
.def
.value
2820 + sec
->output_section
->vma
2821 + sec
->output_offset
);
2824 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2828 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
2829 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
2833 if (! ((*info
->callbacks
->undefined_symbol
)
2834 (info
, h
->root
.root
.string
, input_bfd
,
2835 input_section
, rel
->r_offset
,
2836 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
2837 || ELF_ST_VISIBILITY (h
->other
)))))
2848 if (! IS_FDPIC (output_bfd
))
2854 case R_FRV_FUNCDESC_GOT12
:
2855 case R_FRV_FUNCDESC_GOTHI
:
2856 case R_FRV_FUNCDESC_GOTLO
:
2857 case R_FRV_GOTOFF12
:
2858 case R_FRV_GOTOFFHI
:
2859 case R_FRV_GOTOFFLO
:
2860 case R_FRV_FUNCDESC_GOTOFF12
:
2861 case R_FRV_FUNCDESC_GOTOFFHI
:
2862 case R_FRV_FUNCDESC_GOTOFFLO
:
2863 case R_FRV_FUNCDESC
:
2864 case R_FRV_FUNCDESC_VALUE
:
2865 case R_FRV_GETTLSOFF
:
2866 case R_FRV_TLSDESC_VALUE
:
2867 case R_FRV_GOTTLSDESC12
:
2868 case R_FRV_GOTTLSDESCHI
:
2869 case R_FRV_GOTTLSDESCLO
:
2870 case R_FRV_TLSMOFF12
:
2871 case R_FRV_TLSMOFFHI
:
2872 case R_FRV_TLSMOFFLO
:
2873 case R_FRV_GOTTLSOFF12
:
2874 case R_FRV_GOTTLSOFFHI
:
2875 case R_FRV_GOTTLSOFFLO
:
2877 case R_FRV_TLSDESC_RELAX
:
2878 case R_FRV_GETTLSOFF_RELAX
:
2879 case R_FRV_TLSOFF_RELAX
:
2882 picrel
= frvfdpic_relocs_info_for_global (frvfdpic_relocs_info
2883 (info
), input_bfd
, h
,
2884 orig_addend
, INSERT
);
2886 /* In order to find the entry we created before, we must
2887 use the original addend, not the one that may have been
2888 modified by _bfd_elf_rela_local_sym(). */
2889 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
2890 (info
), input_bfd
, r_symndx
,
2891 orig_addend
, INSERT
);
2895 if (!_frvfdpic_emit_got_relocs_plt_entries (picrel
, output_bfd
, info
,
2899 (*_bfd_error_handler
)
2900 (_("%B(%A+0x%x): relocation to `%s+%x' may have caused the error above"),
2901 input_bfd
, input_section
, rel
->r_offset
, name
, rel
->r_addend
);
2910 if (h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
))
2912 info
->callbacks
->warning
2913 (info
, _("relocation references symbol not defined in the module"),
2914 name
, input_bfd
, input_section
, rel
->r_offset
);
2922 case R_FRV_GETTLSOFF
:
2923 case R_FRV_TLSDESC_VALUE
:
2924 case R_FRV_GOTTLSDESC12
:
2925 case R_FRV_GOTTLSDESCHI
:
2926 case R_FRV_GOTTLSDESCLO
:
2927 case R_FRV_TLSMOFF12
:
2928 case R_FRV_TLSMOFFHI
:
2929 case R_FRV_TLSMOFFLO
:
2930 case R_FRV_GOTTLSOFF12
:
2931 case R_FRV_GOTTLSOFFHI
:
2932 case R_FRV_GOTTLSOFFLO
:
2934 case R_FRV_TLSDESC_RELAX
:
2935 case R_FRV_GETTLSOFF_RELAX
:
2936 case R_FRV_TLSOFF_RELAX
:
2938 if (sec
&& (bfd_is_abs_section (sec
) || bfd_is_und_section (sec
)))
2939 relocation
+= tls_biased_base (info
);
2946 /* Try to apply TLS relaxations. */
2951 #define LOCAL_EXEC_P(info, picrel) \
2952 ((info)->executable \
2953 && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h)))
2954 #define INITIAL_EXEC_P(info, picrel) \
2955 (((info)->executable || (info)->flags & DF_STATIC_TLS) \
2956 && (picrel)->tlsoff_entry)
2958 #define IN_RANGE_FOR_OFST12_P(value) \
2959 ((bfd_vma)((value) + 2048) < (bfd_vma)4096)
2960 #define IN_RANGE_FOR_SETLOS_P(value) \
2961 ((bfd_vma)((value) + 32768) < (bfd_vma)65536)
2962 #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \
2963 (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info)))
2965 #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2966 (LOCAL_EXEC_P ((info), (picrel)) \
2967 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2968 #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \
2969 (INITIAL_EXEC_P ((info), (picrel)) \
2970 && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry))
2972 #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \
2973 (LOCAL_EXEC_P ((info), (picrel)))
2974 #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \
2975 (INITIAL_EXEC_P ((info), (picrel)))
2977 #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2978 (LOCAL_EXEC_P ((info), (picrel)) \
2979 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2981 case R_FRV_GETTLSOFF
:
2982 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2984 /* Is this a call instruction? */
2985 if ((insn
& (unsigned long)0x01fc0000) != 0x003c0000)
2987 r
= info
->callbacks
->warning
2989 _("R_FRV_GETTLSOFF not applied to a call instruction"),
2990 name
, input_bfd
, input_section
, rel
->r_offset
);
2994 if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info
, picrel
,
2995 relocation
+ rel
->r_addend
))
2997 /* Replace the call instruction (except the packing bit)
2998 with setlos #tlsmofflo(symbol+offset), gr9. */
2999 insn
&= (unsigned long)0x80000000;
3000 insn
|= (unsigned long)0x12fc0000;
3001 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3003 r_type
= R_FRV_TLSMOFFLO
;
3004 howto
= elf32_frv_howto_table
+ r_type
;
3005 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3008 else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info
, picrel
))
3010 /* Replace the call instruction (except the packing bit)
3011 with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */
3012 insn
&= (unsigned long)0x80000000;
3013 insn
|= (unsigned long)0x12c8f000;
3014 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3016 r_type
= R_FRV_GOTTLSOFF12
;
3017 howto
= elf32_frv_howto_table
+ r_type
;
3018 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3023 case R_FRV_GOTTLSDESC12
:
3024 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3026 /* Is this an lddi instruction? */
3027 if ((insn
& (unsigned long)0x01fc0000) != 0x00cc0000)
3029 r
= info
->callbacks
->warning
3031 _("R_FRV_GOTTLSDESC12 not applied to an lddi instruction"),
3032 name
, input_bfd
, input_section
, rel
->r_offset
);
3036 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3037 relocation
+ rel
->r_addend
)
3038 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3041 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3042 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3043 Preserve the packing bit. */
3044 insn
= (insn
& (unsigned long)0x80000000)
3045 | ((insn
+ (unsigned long)0x02000000)
3046 & (unsigned long)0x7e000000);
3047 insn
|= (unsigned long)0x00fc0000;
3048 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3050 r_type
= R_FRV_TLSMOFFLO
;
3051 howto
= elf32_frv_howto_table
+ r_type
;
3052 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3055 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3056 relocation
+ rel
->r_addend
))
3058 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3059 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3060 Preserve the packing bit. */
3061 insn
= (insn
& (unsigned long)0x80000000)
3062 | ((insn
+ (unsigned long)0x02000000)
3063 & (unsigned long)0x7e000000);
3064 insn
|= (unsigned long)0x00f80000;
3065 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3067 r_type
= R_FRV_TLSMOFFHI
;
3068 howto
= elf32_frv_howto_table
+ r_type
;
3069 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3072 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3074 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3075 with ldi @(grB, #gottlsoff12(symbol+offset),
3076 gr<C+1>. Preserve the packing bit. If gottlsoff12
3077 overflows, we'll error out, but that's sort-of ok,
3078 since we'd started with gottlsdesc12, that's actually
3079 more demanding. Compiling with -fPIE instead of
3080 -fpie would fix it; linking with --relax should fix
3082 insn
= (insn
& (unsigned long)0x80cbf000)
3083 | ((insn
+ (unsigned long)0x02000000)
3084 & (unsigned long)0x7e000000);
3085 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3087 r_type
= R_FRV_GOTTLSOFF12
;
3088 howto
= elf32_frv_howto_table
+ r_type
;
3089 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3094 case R_FRV_GOTTLSDESCHI
:
3095 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3097 /* Is this a sethi instruction? */
3098 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3100 r
= info
->callbacks
->warning
3102 _("R_FRV_GOTTLSDESCHI not applied to a sethi instruction"),
3103 name
, input_bfd
, input_section
, rel
->r_offset
);
3107 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3108 relocation
+ rel
->r_addend
)
3109 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3110 && IN_RANGE_FOR_SETLOS_P (picrel
->tlsoff_entry
)))
3112 /* Replace sethi with a nop. Preserve the packing bit. */
3113 insn
&= (unsigned long)0x80000000;
3114 insn
|= (unsigned long)0x00880000;
3115 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3117 /* Nothing to relocate. */
3121 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3123 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3124 r_type
= R_FRV_GOTTLSOFFHI
;
3125 howto
= elf32_frv_howto_table
+ r_type
;
3126 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3131 case R_FRV_GOTTLSDESCLO
:
3132 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3134 /* Is this a setlo or setlos instruction? */
3135 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3137 r
= info
->callbacks
->warning
3139 _("R_FRV_GOTTLSDESCLO"
3140 " not applied to a setlo or setlos instruction"),
3141 name
, input_bfd
, input_section
, rel
->r_offset
);
3145 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3146 relocation
+ rel
->r_addend
)
3147 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3148 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3150 /* Replace setlo/setlos with a nop. Preserve the
3152 insn
&= (unsigned long)0x80000000;
3153 insn
|= (unsigned long)0x00880000;
3154 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3156 /* Nothing to relocate. */
3160 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3162 /* If the corresponding sethi (if it exists) decayed
3163 to a nop, make sure this becomes (or already is) a
3164 setlos, not setlo. */
3165 if (IN_RANGE_FOR_SETLOS_P (picrel
->tlsoff_entry
))
3167 insn
|= (unsigned long)0x00080000;
3168 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3171 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3172 r_type
= R_FRV_GOTTLSOFFLO
;
3173 howto
= elf32_frv_howto_table
+ r_type
;
3174 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3179 case R_FRV_TLSDESC_RELAX
:
3180 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3182 /* Is this an ldd instruction? */
3183 if ((insn
& (unsigned long)0x01fc0fc0) != 0x00080140)
3185 r
= info
->callbacks
->warning
3187 _("R_FRV_TLSDESC_RELAX not applied to an ldd instruction"),
3188 name
, input_bfd
, input_section
, rel
->r_offset
);
3192 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3193 relocation
+ rel
->r_addend
)
3194 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3197 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3198 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3199 Preserve the packing bit. */
3200 insn
= (insn
& (unsigned long)0x80000000)
3201 | ((insn
+ (unsigned long)0x02000000)
3202 & (unsigned long)0x7e000000);
3203 insn
|= (unsigned long)0x00fc0000;
3204 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3206 r_type
= R_FRV_TLSMOFFLO
;
3207 howto
= elf32_frv_howto_table
+ r_type
;
3208 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3211 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3212 relocation
+ rel
->r_addend
))
3214 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3215 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3216 Preserve the packing bit. */
3217 insn
= (insn
& (unsigned long)0x80000000)
3218 | ((insn
+ (unsigned long)0x02000000)
3219 & (unsigned long)0x7e000000);
3220 insn
|= (unsigned long)0x00f80000;
3221 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3223 r_type
= R_FRV_TLSMOFFHI
;
3224 howto
= elf32_frv_howto_table
+ r_type
;
3225 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3228 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3229 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
))
3231 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3232 with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>.
3233 Preserve the packing bit. */
3234 insn
= (insn
& (unsigned long)0x8003f000)
3235 | (unsigned long)0x00c80000
3236 | ((insn
+ (unsigned long)0x02000000)
3237 & (unsigned long)0x7e000000);
3238 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3240 r_type
= R_FRV_GOTTLSOFF12
;
3241 howto
= elf32_frv_howto_table
+ r_type
;
3242 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3245 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3247 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3248 with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>.
3249 Preserve the packing bit. */
3250 insn
= (insn
& (unsigned long)0x81ffffbf)
3251 | ((insn
+ (unsigned long)0x02000000)
3252 & (unsigned long)0x7e000000);
3253 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3255 /* #tlsoff(symbol+offset) is just a relaxation
3256 annotation, so there's nothing left to
3263 case R_FRV_GETTLSOFF_RELAX
:
3264 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3266 /* Is this a calll or callil instruction? */
3267 if ((insn
& (unsigned long)0x7ff80fc0) != 0x02300000)
3269 r
= info
->callbacks
->warning
3271 _("R_FRV_GETTLSOFF_RELAX"
3272 " not applied to a calll instruction"),
3273 name
, input_bfd
, input_section
, rel
->r_offset
);
3277 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3278 relocation
+ rel
->r_addend
)
3279 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3282 /* Replace calll with a nop. Preserve the packing bit. */
3283 insn
&= (unsigned long)0x80000000;
3284 insn
|= (unsigned long)0x00880000;
3285 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3287 /* Nothing to relocate. */
3291 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3292 relocation
+ rel
->r_addend
))
3294 /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9.
3295 Preserve the packing bit. */
3296 insn
&= (unsigned long)0x80000000;
3297 insn
|= (unsigned long)0x12f40000;
3298 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3300 r_type
= R_FRV_TLSMOFFLO
;
3301 howto
= elf32_frv_howto_table
+ r_type
;
3302 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3305 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3307 /* Replace calll with a nop. Preserve the packing bit. */
3308 insn
&= (unsigned long)0x80000000;
3309 insn
|= (unsigned long)0x00880000;
3310 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3312 /* Nothing to relocate. */
3318 case R_FRV_GOTTLSOFF12
:
3319 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3321 /* Is this an ldi instruction? */
3322 if ((insn
& (unsigned long)0x01fc0000) != 0x00c80000)
3324 r
= info
->callbacks
->warning
3326 _("R_FRV_GOTTLSOFF12 not applied to an ldi instruction"),
3327 name
, input_bfd
, input_section
, rel
->r_offset
);
3331 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3332 relocation
+ rel
->r_addend
))
3334 /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC
3335 with setlos #tlsmofflo(symbol+offset), grC.
3336 Preserve the packing bit. */
3337 insn
&= (unsigned long)0xfe000000;
3338 insn
|= (unsigned long)0x00fc0000;
3339 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3341 r_type
= R_FRV_TLSMOFFLO
;
3342 howto
= elf32_frv_howto_table
+ r_type
;
3343 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3348 case R_FRV_GOTTLSOFFHI
:
3349 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3351 /* Is this a sethi instruction? */
3352 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3354 r
= info
->callbacks
->warning
3356 _("R_FRV_GOTTLSOFFHI not applied to a sethi instruction"),
3357 name
, input_bfd
, input_section
, rel
->r_offset
);
3361 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3362 relocation
+ rel
->r_addend
)
3363 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3364 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3366 /* Replace sethi with a nop. Preserve the packing bit. */
3367 insn
&= (unsigned long)0x80000000;
3368 insn
|= (unsigned long)0x00880000;
3369 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3371 /* Nothing to relocate. */
3377 case R_FRV_GOTTLSOFFLO
:
3378 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3380 /* Is this a setlo or setlos instruction? */
3381 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3383 r
= info
->callbacks
->warning
3385 _("R_FRV_GOTTLSOFFLO"
3386 " not applied to a setlo or setlos instruction"),
3387 name
, input_bfd
, input_section
, rel
->r_offset
);
3391 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3392 relocation
+ rel
->r_addend
)
3393 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3394 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3396 /* Replace setlo/setlos with a nop. Preserve the
3398 insn
&= (unsigned long)0x80000000;
3399 insn
|= (unsigned long)0x00880000;
3400 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3402 /* Nothing to relocate. */
3408 case R_FRV_TLSOFF_RELAX
:
3409 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3411 /* Is this an ld instruction? */
3412 if ((insn
& (unsigned long)0x01fc0fc0) != 0x00080100)
3414 r
= info
->callbacks
->warning
3416 _("R_FRV_TLSOFF_RELAX not applied to an ld instruction"),
3417 name
, input_bfd
, input_section
, rel
->r_offset
);
3421 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3422 relocation
+ rel
->r_addend
))
3424 /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC
3425 with setlos #tlsmofflo(symbol+offset), grC.
3426 Preserve the packing bit. */
3427 insn
&= (unsigned long)0xfe000000;
3428 insn
|= (unsigned long)0x00fc0000;
3429 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3431 r_type
= R_FRV_TLSMOFFLO
;
3432 howto
= elf32_frv_howto_table
+ r_type
;
3433 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3436 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3437 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
))
3439 /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC
3440 with ldi @(grB, #gottlsoff12(symbol+offset), grC.
3441 Preserve the packing bit. */
3442 insn
= (insn
& (unsigned long)0xfe03f000)
3443 | (unsigned long)0x00c80000;;
3444 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3446 r_type
= R_FRV_GOTTLSOFF12
;
3447 howto
= elf32_frv_howto_table
+ r_type
;
3448 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3453 case R_FRV_TLSMOFFHI
:
3454 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3456 /* Is this a sethi instruction? */
3457 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3459 r
= info
->callbacks
->warning
3461 _("R_FRV_TLSMOFFHI not applied to a sethi instruction"),
3462 name
, input_bfd
, input_section
, rel
->r_offset
);
3466 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3469 /* Replace sethi with a nop. Preserve the packing bit. */
3470 insn
&= (unsigned long)0x80000000;
3471 insn
|= (unsigned long)0x00880000;
3472 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3474 /* Nothing to relocate. */
3480 case R_FRV_TLSMOFFLO
:
3481 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3483 /* Is this a setlo or setlos instruction? */
3484 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3486 r
= info
->callbacks
->warning
3489 " not applied to a setlo or setlos instruction"),
3490 name
, input_bfd
, input_section
, rel
->r_offset
);
3494 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3496 /* If the corresponding sethi (if it exists) decayed
3497 to a nop, make sure this becomes (or already is) a
3498 setlos, not setlo. */
3500 insn
|= (unsigned long)0x00080000;
3501 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3507 There's nothing to relax in these:
3523 check_segment
[0] = isec_segment
;
3524 if (! IS_FDPIC (output_bfd
))
3525 check_segment
[1] = isec_segment
;
3526 else if (picrel
->plt
)
3528 relocation
= frvfdpic_plt_section (info
)->output_section
->vma
3529 + frvfdpic_plt_section (info
)->output_offset
3530 + picrel
->plt_entry
;
3531 check_segment
[1] = plt_segment
;
3533 /* We don't want to warn on calls to undefined weak symbols,
3534 as calls to them must be protected by non-NULL tests
3535 anyway, and unprotected calls would invoke undefined
3537 else if (picrel
->symndx
== -1
3538 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefweak
)
3539 check_segment
[1] = check_segment
[0];
3541 check_segment
[1] = sec
3542 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3549 relocation
= picrel
->got_entry
;
3550 check_segment
[0] = check_segment
[1] = got_segment
;
3553 case R_FRV_FUNCDESC_GOT12
:
3554 case R_FRV_FUNCDESC_GOTHI
:
3555 case R_FRV_FUNCDESC_GOTLO
:
3556 relocation
= picrel
->fdgot_entry
;
3557 check_segment
[0] = check_segment
[1] = got_segment
;
3560 case R_FRV_GOTOFFHI
:
3561 case R_FRV_GOTOFF12
:
3562 case R_FRV_GOTOFFLO
:
3563 relocation
-= frvfdpic_got_section (info
)->output_section
->vma
3564 + frvfdpic_got_section (info
)->output_offset
3565 + frvfdpic_got_initial_offset (info
);
3566 check_segment
[0] = got_segment
;
3567 check_segment
[1] = sec
3568 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3572 case R_FRV_FUNCDESC_GOTOFF12
:
3573 case R_FRV_FUNCDESC_GOTOFFHI
:
3574 case R_FRV_FUNCDESC_GOTOFFLO
:
3575 relocation
= picrel
->fd_entry
;
3576 check_segment
[0] = check_segment
[1] = got_segment
;
3579 case R_FRV_FUNCDESC
:
3582 bfd_vma addend
= rel
->r_addend
;
3584 if (! (h
&& h
->root
.type
== bfd_link_hash_undefweak
3585 && FRVFDPIC_SYM_LOCAL (info
, h
)))
3587 /* If the symbol is dynamic and there may be dynamic
3588 symbol resolution because we are or are linked with a
3589 shared library, emit a FUNCDESC relocation such that
3590 the dynamic linker will allocate the function
3591 descriptor. If the symbol needs a non-local function
3592 descriptor but binds locally (e.g., its visibility is
3593 protected, emit a dynamic relocation decayed to
3595 if (h
&& ! FRVFDPIC_FUNCDESC_LOCAL (info
, h
)
3596 && FRVFDPIC_SYM_LOCAL (info
, h
)
3597 && !(info
->executable
&& !info
->pie
))
3599 dynindx
= elf_section_data (h
->root
.u
.def
.section
3600 ->output_section
)->dynindx
;
3601 addend
+= h
->root
.u
.def
.section
->output_offset
3602 + h
->root
.u
.def
.value
;
3604 else if (h
&& ! FRVFDPIC_FUNCDESC_LOCAL (info
, h
))
3608 info
->callbacks
->warning
3609 (info
, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"),
3610 name
, input_bfd
, input_section
, rel
->r_offset
);
3613 dynindx
= h
->dynindx
;
3617 /* Otherwise, we know we have a private function
3618 descriptor, so reference it directly. */
3619 BFD_ASSERT (picrel
->privfd
);
3621 dynindx
= elf_section_data (frvfdpic_got_section (info
)
3622 ->output_section
)->dynindx
;
3623 addend
= frvfdpic_got_section (info
)->output_offset
3624 + frvfdpic_got_initial_offset (info
)
3628 /* If there is room for dynamic symbol resolution, emit
3629 the dynamic relocation. However, if we're linking an
3630 executable at a fixed location, we won't have emitted a
3631 dynamic symbol entry for the got section, so idx will
3632 be zero, which means we can and should compute the
3633 address of the private descriptor ourselves. */
3634 if (info
->executable
&& !info
->pie
3635 && (!h
|| FRVFDPIC_FUNCDESC_LOCAL (info
, h
)))
3637 addend
+= frvfdpic_got_section (info
)->output_section
->vma
;
3638 if ((bfd_get_section_flags (output_bfd
,
3639 input_section
->output_section
)
3640 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3642 if (_frvfdpic_osec_readonly_p (output_bfd
,
3646 info
->callbacks
->warning
3648 _("cannot emit fixups in read-only section"),
3649 name
, input_bfd
, input_section
, rel
->r_offset
);
3652 _frvfdpic_add_rofixup (output_bfd
,
3653 frvfdpic_gotfixup_section
3655 _bfd_elf_section_offset
3657 input_section
, rel
->r_offset
)
3659 ->output_section
->vma
3660 + input_section
->output_offset
,
3664 else if ((bfd_get_section_flags (output_bfd
,
3665 input_section
->output_section
)
3666 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3668 if (_frvfdpic_osec_readonly_p (output_bfd
,
3672 info
->callbacks
->warning
3674 _("cannot emit dynamic relocations in read-only section"),
3675 name
, input_bfd
, input_section
, rel
->r_offset
);
3678 _frvfdpic_add_dyn_reloc (output_bfd
,
3679 frvfdpic_gotrel_section (info
),
3680 _bfd_elf_section_offset
3682 input_section
, rel
->r_offset
)
3684 ->output_section
->vma
3685 + input_section
->output_offset
,
3686 r_type
, dynindx
, addend
, picrel
);
3689 addend
+= frvfdpic_got_section (info
)->output_section
->vma
;
3692 /* We want the addend in-place because dynamic
3693 relocations are REL. Setting relocation to it should
3694 arrange for it to be installed. */
3695 relocation
= addend
- rel
->r_addend
;
3697 check_segment
[0] = check_segment
[1] = got_segment
;
3701 if (! IS_FDPIC (output_bfd
))
3703 check_segment
[0] = check_segment
[1] = -1;
3707 case R_FRV_FUNCDESC_VALUE
:
3710 bfd_vma addend
= rel
->r_addend
;
3712 /* If the symbol is dynamic but binds locally, use
3714 if (h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
))
3716 if (addend
&& r_type
== R_FRV_FUNCDESC_VALUE
)
3718 info
->callbacks
->warning
3719 (info
, _("R_FRV_FUNCDESC_VALUE references dynamic symbol with nonzero addend"),
3720 name
, input_bfd
, input_section
, rel
->r_offset
);
3723 dynindx
= h
->dynindx
;
3728 addend
+= h
->root
.u
.def
.value
;
3730 addend
+= sym
->st_value
;
3732 addend
+= osec
->output_offset
;
3733 if (osec
&& osec
->output_section
3734 && ! bfd_is_abs_section (osec
->output_section
)
3735 && ! bfd_is_und_section (osec
->output_section
))
3736 dynindx
= elf_section_data (osec
->output_section
)->dynindx
;
3741 /* If we're linking an executable at a fixed address, we
3742 can omit the dynamic relocation as long as the symbol
3743 is defined in the current link unit (which is implied
3744 by its output section not being NULL). */
3745 if (info
->executable
&& !info
->pie
3746 && (!h
|| FRVFDPIC_SYM_LOCAL (info
, h
)))
3749 addend
+= osec
->output_section
->vma
;
3750 if (IS_FDPIC (input_bfd
)
3751 && (bfd_get_section_flags (output_bfd
,
3752 input_section
->output_section
)
3753 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3755 if (_frvfdpic_osec_readonly_p (output_bfd
,
3759 info
->callbacks
->warning
3761 _("cannot emit fixups in read-only section"),
3762 name
, input_bfd
, input_section
, rel
->r_offset
);
3765 if (!h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
3767 _frvfdpic_add_rofixup (output_bfd
,
3768 frvfdpic_gotfixup_section
3770 _bfd_elf_section_offset
3772 input_section
, rel
->r_offset
)
3774 ->output_section
->vma
3775 + input_section
->output_offset
,
3777 if (r_type
== R_FRV_FUNCDESC_VALUE
)
3778 _frvfdpic_add_rofixup
3780 frvfdpic_gotfixup_section (info
),
3781 _bfd_elf_section_offset
3783 input_section
, rel
->r_offset
)
3784 + input_section
->output_section
->vma
3785 + input_section
->output_offset
+ 4, picrel
);
3791 if ((bfd_get_section_flags (output_bfd
,
3792 input_section
->output_section
)
3793 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3795 if (_frvfdpic_osec_readonly_p (output_bfd
,
3799 info
->callbacks
->warning
3801 _("cannot emit dynamic relocations in read-only section"),
3802 name
, input_bfd
, input_section
, rel
->r_offset
);
3805 _frvfdpic_add_dyn_reloc (output_bfd
,
3806 frvfdpic_gotrel_section (info
),
3807 _bfd_elf_section_offset
3809 input_section
, rel
->r_offset
)
3811 ->output_section
->vma
3812 + input_section
->output_offset
,
3813 r_type
, dynindx
, addend
, picrel
);
3816 addend
+= osec
->output_section
->vma
;
3817 /* We want the addend in-place because dynamic
3818 relocations are REL. Setting relocation to it
3819 should arrange for it to be installed. */
3820 relocation
= addend
- rel
->r_addend
;
3823 if (r_type
== R_FRV_FUNCDESC_VALUE
)
3825 /* If we've omitted the dynamic relocation, just emit
3826 the fixed addresses of the symbol and of the local
3828 if (info
->executable
&& !info
->pie
3829 && (!h
|| FRVFDPIC_SYM_LOCAL (info
, h
)))
3830 bfd_put_32 (output_bfd
,
3831 frvfdpic_got_section (info
)->output_section
->vma
3832 + frvfdpic_got_section (info
)->output_offset
3833 + frvfdpic_got_initial_offset (info
),
3834 contents
+ rel
->r_offset
+ 4);
3836 /* A function descriptor used for lazy or local
3837 resolving is initialized such that its high word
3838 contains the output section index in which the
3839 PLT entries are located, and the low word
3840 contains the offset of the lazy PLT entry entry
3841 point into that section. */
3842 bfd_put_32 (output_bfd
,
3843 h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
)
3845 : _frvfdpic_osec_to_segment (output_bfd
,
3848 contents
+ rel
->r_offset
+ 4);
3851 check_segment
[0] = check_segment
[1] = got_segment
;
3855 case R_FRV_GPRELU12
:
3859 check_segment
[0] = gprel_segment
;
3860 check_segment
[1] = sec
3861 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3865 case R_FRV_GETTLSOFF
:
3866 relocation
= frvfdpic_plt_section (info
)->output_section
->vma
3867 + frvfdpic_plt_section (info
)->output_offset
3868 + picrel
->tlsplt_entry
;
3869 BFD_ASSERT (picrel
->tlsplt_entry
!= (bfd_vma
)-1
3870 && picrel
->tlsdesc_entry
);
3871 check_segment
[0] = isec_segment
;
3872 check_segment
[1] = plt_segment
;
3875 case R_FRV_GOTTLSDESC12
:
3876 case R_FRV_GOTTLSDESCHI
:
3877 case R_FRV_GOTTLSDESCLO
:
3878 BFD_ASSERT (picrel
->tlsdesc_entry
);
3879 relocation
= picrel
->tlsdesc_entry
;
3880 check_segment
[0] = tls_segment
;
3881 check_segment
[1] = sec
3882 && ! bfd_is_abs_section (sec
)
3883 && ! bfd_is_und_section (sec
)
3884 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3888 case R_FRV_TLSMOFF12
:
3889 case R_FRV_TLSMOFFHI
:
3890 case R_FRV_TLSMOFFLO
:
3892 check_segment
[0] = tls_segment
;
3894 check_segment
[1] = -1;
3895 else if (bfd_is_abs_section (sec
)
3896 || bfd_is_und_section (sec
))
3899 check_segment
[1] = tls_segment
;
3901 else if (sec
->output_section
)
3903 relocation
-= tls_biased_base (info
);
3905 _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
);
3908 check_segment
[1] = -1;
3911 case R_FRV_GOTTLSOFF12
:
3912 case R_FRV_GOTTLSOFFHI
:
3913 case R_FRV_GOTTLSOFFLO
:
3914 BFD_ASSERT (picrel
->tlsoff_entry
);
3915 relocation
= picrel
->tlsoff_entry
;
3916 check_segment
[0] = tls_segment
;
3917 check_segment
[1] = sec
3918 && ! bfd_is_abs_section (sec
)
3919 && ! bfd_is_und_section (sec
)
3920 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3924 case R_FRV_TLSDESC_VALUE
:
3926 /* These shouldn't be present in input object files. */
3927 check_segment
[0] = check_segment
[1] = isec_segment
;
3930 case R_FRV_TLSDESC_RELAX
:
3931 case R_FRV_GETTLSOFF_RELAX
:
3932 case R_FRV_TLSOFF_RELAX
:
3933 /* These are just annotations for relaxation, nothing to do
3938 check_segment
[0] = isec_segment
;
3939 check_segment
[1] = sec
3940 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3945 if (check_segment
[0] != check_segment
[1] && IS_FDPIC (output_bfd
))
3947 /* If you take this out, remove the #error from fdpic-static-6.d
3948 in the ld testsuite. */
3949 /* This helps catch problems in GCC while we can't do more
3950 than static linking. The idea is to test whether the
3951 input file basename is crt0.o only once. */
3952 if (silence_segment_error
== 1)
3953 silence_segment_error
=
3954 (strlen (input_bfd
->filename
) == 6
3955 && strcmp (input_bfd
->filename
, "crt0.o") == 0)
3956 || (strlen (input_bfd
->filename
) > 6
3957 && strcmp (input_bfd
->filename
3958 + strlen (input_bfd
->filename
) - 7,
3961 if (!silence_segment_error
3962 /* We don't want duplicate errors for undefined
3964 && !(picrel
&& picrel
->symndx
== -1
3965 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefined
))
3967 if (info
->shared
|| info
->pie
)
3968 (*_bfd_error_handler
)
3969 (_("%B(%A+0x%lx): reloc against `%s': %s"),
3970 input_bfd
, input_section
, (long)rel
->r_offset
, name
,
3971 _("relocation references a different segment"));
3973 info
->callbacks
->warning
3975 _("relocation references a different segment"),
3976 name
, input_bfd
, input_section
, rel
->r_offset
);
3978 if (!silence_segment_error
&& (info
->shared
|| info
->pie
))
3980 elf_elfheader (output_bfd
)->e_flags
|= EF_FRV_PIC
;
3985 case R_FRV_GOTOFFHI
:
3986 case R_FRV_TLSMOFFHI
:
3987 /* We need the addend to be applied before we shift the
3989 relocation
+= rel
->r_addend
;
3992 case R_FRV_FUNCDESC_GOTHI
:
3993 case R_FRV_FUNCDESC_GOTOFFHI
:
3994 case R_FRV_GOTTLSOFFHI
:
3995 case R_FRV_GOTTLSDESCHI
:
4000 case R_FRV_FUNCDESC_GOTLO
:
4001 case R_FRV_GOTOFFLO
:
4002 case R_FRV_FUNCDESC_GOTOFFLO
:
4003 case R_FRV_GOTTLSOFFLO
:
4004 case R_FRV_GOTTLSDESCLO
:
4005 case R_FRV_TLSMOFFLO
:
4006 relocation
&= 0xffff;
4016 if (! IS_FDPIC (output_bfd
) || ! picrel
->plt
)
4020 /* When referencing a GOT entry, a function descriptor or a
4021 PLT, we don't want the addend to apply to the reference,
4022 but rather to the referenced symbol. The actual entry
4023 will have already been created taking the addend into
4024 account, so cancel it out here. */
4028 case R_FRV_FUNCDESC_GOT12
:
4029 case R_FRV_FUNCDESC_GOTHI
:
4030 case R_FRV_FUNCDESC_GOTLO
:
4031 case R_FRV_FUNCDESC_GOTOFF12
:
4032 case R_FRV_FUNCDESC_GOTOFFHI
:
4033 case R_FRV_FUNCDESC_GOTOFFLO
:
4034 case R_FRV_GETTLSOFF
:
4035 case R_FRV_GOTTLSDESC12
:
4036 case R_FRV_GOTTLSDESCHI
:
4037 case R_FRV_GOTTLSDESCLO
:
4038 case R_FRV_GOTTLSOFF12
:
4039 case R_FRV_GOTTLSOFFHI
:
4040 case R_FRV_GOTTLSOFFLO
:
4041 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
4042 here, since we do want to apply the addend to the others.
4043 Note that we've applied the addend to GOTOFFHI before we
4044 shifted it right. */
4045 case R_FRV_GOTOFFHI
:
4046 case R_FRV_TLSMOFFHI
:
4047 relocation
-= rel
->r_addend
;
4054 if (r_type
== R_FRV_HI16
)
4055 r
= elf32_frv_relocate_hi16 (input_bfd
, rel
, contents
, relocation
);
4057 else if (r_type
== R_FRV_LO16
)
4058 r
= elf32_frv_relocate_lo16 (input_bfd
, rel
, contents
, relocation
);
4060 else if (r_type
== R_FRV_LABEL24
|| r_type
== R_FRV_GETTLSOFF
)
4061 r
= elf32_frv_relocate_label24 (input_bfd
, input_section
, rel
,
4062 contents
, relocation
);
4064 else if (r_type
== R_FRV_GPREL12
)
4065 r
= elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, rel
,
4066 contents
, relocation
);
4068 else if (r_type
== R_FRV_GPRELU12
)
4069 r
= elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, rel
,
4070 contents
, relocation
);
4072 else if (r_type
== R_FRV_GPRELLO
)
4073 r
= elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, rel
,
4074 contents
, relocation
);
4076 else if (r_type
== R_FRV_GPRELHI
)
4077 r
= elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, rel
,
4078 contents
, relocation
);
4080 else if (r_type
== R_FRV_TLSOFF
4081 || r_type
== R_FRV_TLSDESC_VALUE
)
4082 r
= bfd_reloc_notsupported
;
4085 r
= frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
4088 if (r
!= bfd_reloc_ok
)
4090 const char * msg
= (const char *) NULL
;
4094 case bfd_reloc_overflow
:
4095 r
= info
->callbacks
->reloc_overflow
4096 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4097 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
4100 case bfd_reloc_undefined
:
4101 r
= info
->callbacks
->undefined_symbol
4102 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
4105 case bfd_reloc_outofrange
:
4106 msg
= _("internal error: out of range error");
4109 case bfd_reloc_notsupported
:
4110 msg
= _("internal error: unsupported relocation error");
4113 case bfd_reloc_dangerous
:
4114 msg
= _("internal error: dangerous relocation");
4118 msg
= _("internal error: unknown error");
4124 (*_bfd_error_handler
)
4125 (_("%B(%A+0x%lx): reloc against `%s': %s"),
4126 input_bfd
, input_section
, (long)rel
->r_offset
, name
, msg
);
4138 /* Return the section that should be marked against GC for a given
4142 elf32_frv_gc_mark_hook (asection
*sec
,
4143 struct bfd_link_info
*info
,
4144 Elf_Internal_Rela
*rel
,
4145 struct elf_link_hash_entry
*h
,
4146 Elf_Internal_Sym
*sym
)
4149 switch (ELF32_R_TYPE (rel
->r_info
))
4151 case R_FRV_GNU_VTINHERIT
:
4152 case R_FRV_GNU_VTENTRY
:
4156 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
4159 /* Hook called by the linker routine which adds symbols from an object
4160 file. We use it to put .comm items in .scomm, and not .comm. */
4163 elf32_frv_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
4165 struct bfd_link_info
*info
;
4166 Elf_Internal_Sym
*sym
;
4167 const char **namep ATTRIBUTE_UNUSED
;
4168 flagword
*flagsp ATTRIBUTE_UNUSED
;
4172 if (sym
->st_shndx
== SHN_COMMON
4173 && !info
->relocatable
4174 && (int)sym
->st_size
<= (int)bfd_get_gp_size (abfd
))
4176 /* Common symbols less than or equal to -G nn bytes are
4177 automatically put into .sbss. */
4179 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
4183 scomm
= bfd_make_section_with_flags (abfd
, ".scommon",
4186 | SEC_LINKER_CREATED
));
4192 *valp
= sym
->st_size
;
4198 /* We need dynamic symbols for every section, since segments can
4199 relocate independently. */
4201 _frvfdpic_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4202 struct bfd_link_info
*info
4204 asection
*p ATTRIBUTE_UNUSED
)
4206 switch (elf_section_data (p
)->this_hdr
.sh_type
)
4210 /* If sh_type is yet undecided, assume it could be
4211 SHT_PROGBITS/SHT_NOBITS. */
4215 /* There shouldn't be section relative relocations
4216 against any other section. */
4222 /* Create a .got section, as well as its additional info field. This
4223 is almost entirely copied from
4224 elflink.c:_bfd_elf_create_got_section(). */
4227 _frv_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4229 flagword flags
, pltflags
;
4231 struct elf_link_hash_entry
*h
;
4232 struct bfd_link_hash_entry
*bh
;
4233 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4237 /* This function may be called more than once. */
4238 s
= bfd_get_section_by_name (abfd
, ".got");
4239 if (s
!= NULL
&& (s
->flags
& SEC_LINKER_CREATED
) != 0)
4242 /* Machine specific: although pointers are 32-bits wide, we want the
4243 GOT to be aligned to a 64-bit boundary, such that function
4244 descriptors in it can be accessed with 64-bit loads and
4248 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4249 | SEC_LINKER_CREATED
);
4252 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
4254 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
4257 if (bed
->want_got_plt
)
4259 s
= bfd_make_section_with_flags (abfd
, ".got.plt", flags
);
4261 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
4265 if (bed
->want_got_sym
)
4267 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
4268 (or .got.plt) section. We don't do this in the linker script
4269 because we don't want to define the symbol if we are not creating
4270 a global offset table. */
4271 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
, "_GLOBAL_OFFSET_TABLE_");
4272 elf_hash_table (info
)->hgot
= h
;
4276 /* Machine-specific: we want the symbol for executables as
4278 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4282 /* The first bit of the global offset table is the header. */
4283 s
->size
+= bed
->got_header_size
;
4285 /* This is the machine-specific part. Create and initialize section
4286 data for the got. */
4287 if (IS_FDPIC (abfd
))
4289 frvfdpic_got_section (info
) = s
;
4290 frvfdpic_relocs_info (info
) = htab_try_create (1,
4291 frvfdpic_relocs_info_hash
,
4292 frvfdpic_relocs_info_eq
,
4294 if (! frvfdpic_relocs_info (info
))
4297 s
= bfd_make_section_with_flags (abfd
, ".rel.got",
4298 (flags
| SEC_READONLY
));
4300 || ! bfd_set_section_alignment (abfd
, s
, 2))
4303 frvfdpic_gotrel_section (info
) = s
;
4305 /* Machine-specific. */
4306 s
= bfd_make_section_with_flags (abfd
, ".rofixup",
4307 (flags
| SEC_READONLY
));
4309 || ! bfd_set_section_alignment (abfd
, s
, 2))
4312 frvfdpic_gotfixup_section (info
) = s
;
4319 flags
= BSF_GLOBAL
| BSF_WEAK
;
4322 /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it
4323 turns out that we're linking with a different linker script, the
4324 linker script will override it. */
4326 if (!(_bfd_generic_link_add_one_symbol
4327 (info
, abfd
, "_gp", flags
, s
, offset
, (const char *) NULL
, FALSE
,
4328 bed
->collect
, &bh
)))
4330 h
= (struct elf_link_hash_entry
*) bh
;
4332 h
->type
= STT_OBJECT
;
4333 /* h->other = STV_HIDDEN; */ /* Should we? */
4335 /* Machine-specific: we want the symbol for executables as well. */
4336 if (IS_FDPIC (abfd
) && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
4339 if (!IS_FDPIC (abfd
))
4342 /* FDPIC supports Thread Local Storage, and this may require a
4343 procedure linkage table for TLS PLT entries. */
4345 /* This is mostly copied from
4346 elflink.c:_bfd_elf_create_dynamic_sections(). */
4349 pltflags
|= SEC_CODE
;
4350 if (bed
->plt_not_loaded
)
4351 pltflags
&= ~ (SEC_CODE
| SEC_LOAD
| SEC_HAS_CONTENTS
);
4352 if (bed
->plt_readonly
)
4353 pltflags
|= SEC_READONLY
;
4355 s
= bfd_make_section_with_flags (abfd
, ".plt", pltflags
);
4357 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
4359 /* FRV-specific: remember it. */
4360 frvfdpic_plt_section (info
) = s
;
4362 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
4364 if (bed
->want_plt_sym
)
4366 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
4367 "_PROCEDURE_LINKAGE_TABLE_");
4368 elf_hash_table (info
)->hplt
= h
;
4373 /* FRV-specific: we want rel relocations for the plt. */
4374 s
= bfd_make_section_with_flags (abfd
, ".rel.plt",
4375 flags
| SEC_READONLY
);
4377 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
4379 /* FRV-specific: remember it. */
4380 frvfdpic_pltrel_section (info
) = s
;
4385 /* Make sure the got and plt sections exist, and that our pointers in
4386 the link hash table point to them. */
4389 elf32_frvfdpic_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
4391 /* This is mostly copied from
4392 elflink.c:_bfd_elf_create_dynamic_sections(). */
4395 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4397 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4398 | SEC_LINKER_CREATED
);
4400 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
4401 .rel[a].bss sections. */
4403 /* FRV-specific: we want to create the GOT and the PLT in the FRV
4405 if (! _frv_create_got_section (abfd
, info
))
4408 /* FRV-specific: make sure we created everything we wanted. */
4409 BFD_ASSERT (frvfdpic_got_section (info
) && frvfdpic_gotrel_section (info
)
4410 && frvfdpic_gotfixup_section (info
)
4411 && frvfdpic_plt_section (info
)
4412 && frvfdpic_pltrel_section (info
));
4414 if (bed
->want_dynbss
)
4416 /* The .dynbss section is a place to put symbols which are defined
4417 by dynamic objects, are referenced by regular objects, and are
4418 not functions. We must allocate space for them in the process
4419 image and use a R_*_COPY reloc to tell the dynamic linker to
4420 initialize them at run time. The linker script puts the .dynbss
4421 section into the .bss section of the final image. */
4422 s
= bfd_make_section_with_flags (abfd
, ".dynbss",
4423 SEC_ALLOC
| SEC_LINKER_CREATED
);
4427 /* The .rel[a].bss section holds copy relocs. This section is not
4428 normally needed. We need to create it here, though, so that the
4429 linker will map it to an output section. We can't just create it
4430 only if we need it, because we will not know whether we need it
4431 until we have seen all the input files, and the first time the
4432 main linker code calls BFD after examining all the input files
4433 (size_dynamic_sections) the input sections have already been
4434 mapped to the output sections. If the section turns out not to
4435 be needed, we can discard it later. We will never need this
4436 section when generating a shared object, since they do not use
4440 s
= bfd_make_section_with_flags (abfd
,
4441 (bed
->default_use_rela_p
4442 ? ".rela.bss" : ".rel.bss"),
4443 flags
| SEC_READONLY
);
4445 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
4453 /* Compute the total GOT and PLT size required by each symbol in each
4454 range. Symbols may require up to 4 words in the GOT: an entry
4455 pointing to the symbol, an entry pointing to its function
4456 descriptor, and a private function descriptors taking two
4460 _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info
*entry
,
4461 struct _frvfdpic_dynamic_got_info
*dinfo
)
4463 /* Allocate space for a GOT entry pointing to the symbol. */
4466 else if (entry
->gotlos
)
4468 else if (entry
->gothilo
)
4469 dinfo
->gothilo
+= 4;
4474 /* Allocate space for a GOT entry pointing to the function
4478 else if (entry
->fdgotlos
)
4480 else if (entry
->fdgothilo
)
4481 dinfo
->gothilo
+= 4;
4486 /* Decide whether we need a PLT entry, a function descriptor in the
4487 GOT, and a lazy PLT entry for this symbol. */
4488 entry
->plt
= entry
->call
4489 && entry
->symndx
== -1 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4490 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
4491 entry
->privfd
= entry
->plt
4492 || entry
->fdgoff12
|| entry
->fdgofflos
|| entry
->fdgoffhilo
4493 || ((entry
->fd
|| entry
->fdgot12
|| entry
->fdgotlos
|| entry
->fdgothilo
)
4494 && (entry
->symndx
!= -1
4495 || FRVFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
)));
4496 entry
->lazyplt
= entry
->privfd
4497 && entry
->symndx
== -1 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4498 && ! (dinfo
->info
->flags
& DF_BIND_NOW
)
4499 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
4501 /* Allocate space for a function descriptor. */
4502 if (entry
->fdgoff12
)
4504 else if (entry
->fdgofflos
)
4506 else if (entry
->privfd
&& entry
->plt
)
4508 else if (entry
->privfd
)
4518 /* Compute the total GOT size required by each TLS symbol in each
4519 range. Symbols may require up to 5 words in the GOT: an entry
4520 holding the TLS offset for the symbol, and an entry with a full TLS
4521 descriptor taking 4 words. */
4524 _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info
*entry
,
4525 struct _frvfdpic_dynamic_got_info
*dinfo
,
4526 bfd_boolean subtract
)
4528 const int l
= subtract
? -1 : 1;
4530 /* Allocate space for a GOT entry with the TLS offset of the
4532 if (entry
->tlsoff12
)
4533 dinfo
->got12
+= 4 * l
;
4534 else if (entry
->tlsofflos
)
4535 dinfo
->gotlos
+= 4 * l
;
4536 else if (entry
->tlsoffhilo
)
4537 dinfo
->gothilo
+= 4 * l
;
4539 entry
->relocstlsoff
-= l
;
4540 entry
->relocstlsoff
+= l
;
4542 /* If there's any TLSOFF relocation, mark the output file as not
4543 suitable for dlopening. This mark will remain even if we relax
4544 all such relocations, but this is not a problem, since we'll only
4545 do so for executables, and we definitely don't want anyone
4546 dlopening executables. */
4547 if (entry
->relocstlsoff
)
4548 dinfo
->info
->flags
|= DF_STATIC_TLS
;
4550 /* Allocate space for a TLS descriptor. */
4551 if (entry
->tlsdesc12
)
4552 dinfo
->tlsd12
+= 8 * l
;
4553 else if (entry
->tlsdesclos
)
4554 dinfo
->tlsdlos
+= 8 * l
;
4555 else if (entry
->tlsplt
)
4556 dinfo
->tlsdplt
+= 8 * l
;
4557 else if (entry
->tlsdeschilo
)
4558 dinfo
->tlsdhilo
+= 8 * l
;
4560 entry
->relocstlsd
-= l
;
4561 entry
->relocstlsd
+= l
;
4564 /* Compute the number of dynamic relocations and fixups that a symbol
4565 requires, and add (or subtract) from the grand and per-symbol
4569 _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info
*entry
,
4570 struct _frvfdpic_dynamic_got_info
*dinfo
,
4571 bfd_boolean subtract
)
4573 bfd_vma relocs
= 0, fixups
= 0, tlsrets
= 0;
4575 if (!dinfo
->info
->executable
|| dinfo
->info
->pie
)
4577 relocs
= entry
->relocs32
+ entry
->relocsfd
+ entry
->relocsfdv
4578 + entry
->relocstlsd
;
4580 /* In the executable, TLS relocations to symbols that bind
4581 locally (including those that resolve to global TLS offsets)
4582 are resolved immediately, without any need for fixups or
4583 dynamic relocations. In shared libraries, however, we must
4584 emit dynamic relocations even for local symbols, because we
4585 don't know the module id the library is going to get at
4586 run-time, nor its TLS base offset. */
4587 if (!dinfo
->info
->executable
4588 || (entry
->symndx
== -1
4589 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)))
4590 relocs
+= entry
->relocstlsoff
;
4594 if (entry
->symndx
!= -1 || FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
))
4596 if (entry
->symndx
!= -1
4597 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
4598 fixups
+= entry
->relocs32
+ 2 * entry
->relocsfdv
;
4599 fixups
+= entry
->relocstlsd
;
4600 tlsrets
+= entry
->relocstlsd
;
4604 relocs
+= entry
->relocs32
+ entry
->relocsfdv
4605 + entry
->relocstlsoff
+ entry
->relocstlsd
;
4608 if (entry
->symndx
!= -1
4609 || FRVFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
))
4611 if (entry
->symndx
!= -1
4612 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
4613 fixups
+= entry
->relocsfd
;
4616 relocs
+= entry
->relocsfd
;
4623 tlsrets
= - tlsrets
;
4626 entry
->dynrelocs
+= relocs
;
4627 entry
->fixups
+= fixups
;
4628 dinfo
->relocs
+= relocs
;
4629 dinfo
->fixups
+= fixups
;
4630 dinfo
->tls_ret_refs
+= tlsrets
;
4633 /* Look for opportunities to relax TLS relocations. We can assume
4634 we're linking the main executable or a static-tls library, since
4635 otherwise we wouldn't have got here. When relaxing, we have to
4636 first undo any previous accounting of TLS uses of fixups, dynamic
4637 relocations, GOT and PLT entries. */
4640 _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info
*entry
,
4641 struct _frvfdpic_dynamic_got_info
*dinfo
,
4642 bfd_boolean relaxing
)
4644 bfd_boolean changed
= ! relaxing
;
4646 BFD_ASSERT (dinfo
->info
->executable
4647 || (dinfo
->info
->flags
& DF_STATIC_TLS
));
4649 if (entry
->tlsdesc12
|| entry
->tlsdesclos
|| entry
->tlsdeschilo
)
4653 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4654 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4658 /* When linking an executable, we can always decay GOTTLSDESC to
4659 TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise.
4660 When linking a static-tls shared library, using TLSMOFF is
4661 not an option, but we can still use GOTTLSOFF. When decaying
4662 to GOTTLSOFF, we must keep the GOT entry in range. We know
4663 it has to fit because we'll be trading the 4 words of hte TLS
4664 descriptor for a single word in the same range. */
4665 if (! dinfo
->info
->executable
4666 || (entry
->symndx
== -1
4667 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)))
4669 entry
->tlsoff12
|= entry
->tlsdesc12
;
4670 entry
->tlsofflos
|= entry
->tlsdesclos
;
4671 entry
->tlsoffhilo
|= entry
->tlsdeschilo
;
4674 entry
->tlsdesc12
= entry
->tlsdesclos
= entry
->tlsdeschilo
= 0;
4677 /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the
4678 main executable. We have to check whether the symbol's TLSOFF is
4679 in range for a setlos. For symbols with a hash entry, we can
4680 determine exactly what to do; for others locals, we don't have
4681 addresses handy, so we use the size of the TLS section as an
4682 approximation. If we get it wrong, we'll retain a GOT entry
4683 holding the TLS offset (without dynamic relocations or fixups),
4684 but we'll still optimize away the loads from it. Since TLS sizes
4685 are generally very small, it's probably not worth attempting to
4686 do better than this. */
4688 || entry
->tlsoff12
|| entry
->tlsofflos
|| entry
->tlsoffhilo
)
4689 && dinfo
->info
->executable
&& relaxing
4690 && ((entry
->symndx
== -1
4691 && FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4692 /* The above may hold for an undefweak TLS symbol, so make
4693 sure we don't have this case before accessing def.value
4695 && (entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
4696 || (bfd_vma
)(entry
->d
.h
->root
.u
.def
.value
4697 + (entry
->d
.h
->root
.u
.def
.section
4698 ->output_section
->vma
)
4699 + entry
->d
.h
->root
.u
.def
.section
->output_offset
4701 - tls_biased_base (dinfo
->info
)
4702 + 32768) < (bfd_vma
)65536))
4703 || (entry
->symndx
!= -1
4704 && (elf_hash_table (dinfo
->info
)->tls_sec
->size
4705 + abs (entry
->addend
) < 32768 + FRVFDPIC_TLS_BIAS
))))
4709 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4710 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4715 entry
->tlsoff12
= entry
->tlsofflos
= entry
->tlsoffhilo
= 0;
4718 /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already
4719 have a #gottlsoff12 relocation for this entry, or if we can fit
4720 one more in the 12-bit (and 16-bit) ranges. */
4724 && dinfo
->got12
+ dinfo
->fd12
+ dinfo
->tlsd12
<= 4096 - 12 - 4
4725 && (dinfo
->got12
+ dinfo
->fd12
+ dinfo
->tlsd12
4726 + dinfo
->gotlos
+ dinfo
->fdlos
+ dinfo
->tlsdlos
4727 <= 65536 - 12 - 4))))
4731 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4732 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4736 entry
->tlsoff12
= 1;
4742 _frvfdpic_count_tls_entries (entry
, dinfo
, FALSE
);
4743 _frvfdpic_count_relocs_fixups (entry
, dinfo
, FALSE
);
4749 /* Compute the total GOT and PLT size required by each symbol in each range. *
4750 Symbols may require up to 4 words in the GOT: an entry pointing to
4751 the symbol, an entry pointing to its function descriptor, and a
4752 private function descriptors taking two words. */
4755 _frvfdpic_count_got_plt_entries (void **entryp
, void *dinfo_
)
4757 struct frvfdpic_relocs_info
*entry
= *entryp
;
4758 struct _frvfdpic_dynamic_got_info
*dinfo
= dinfo_
;
4760 _frvfdpic_count_nontls_entries (entry
, dinfo
);
4762 if (dinfo
->info
->executable
|| (dinfo
->info
->flags
& DF_STATIC_TLS
))
4763 _frvfdpic_relax_tls_entries (entry
, dinfo
, FALSE
);
4766 _frvfdpic_count_tls_entries (entry
, dinfo
, FALSE
);
4767 _frvfdpic_count_relocs_fixups (entry
, dinfo
, FALSE
);
4773 /* Determine the positive and negative ranges to be used by each
4774 offset range in the GOT. FDCUR and CUR, that must be aligned to a
4775 double-word boundary, are the minimum (negative) and maximum
4776 (positive) GOT offsets already used by previous ranges, except for
4777 an ODD entry that may have been left behind. GOT and FD indicate
4778 the size of GOT entries and function descriptors that must be
4779 placed within the range from -WRAP to WRAP. If there's room left,
4780 up to FDPLT bytes should be reserved for additional function
4783 inline static bfd_signed_vma
4784 _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data
*gad
,
4785 bfd_signed_vma fdcur
,
4795 bfd_signed_vma wrapmin
= -wrap
;
4796 const bfd_vma tdescsz
= 8;
4798 /* Start at the given initial points. */
4802 /* If we had an incoming odd word and we have any got entries that
4803 are going to use it, consume it, otherwise leave gad->odd at
4804 zero. We might force gad->odd to zero and return the incoming
4805 odd such that it is used by the next range, but then GOT entries
4806 might appear to be out of order and we wouldn't be able to
4807 shorten the GOT by one word if it turns out to end with an
4808 unpaired GOT entry. */
4818 /* If we're left with an unpaired GOT entry, compute its location
4819 such that we can return it. Otherwise, if got doesn't require an
4820 odd number of words here, either odd was already zero in the
4821 block above, or it was set to zero because got was non-zero, or
4822 got was already zero. In the latter case, we want the value of
4823 odd to carry over to the return statement, so we don't want to
4824 reset odd unless the condition below is true. */
4831 /* Compute the tentative boundaries of this range. */
4832 gad
->max
= cur
+ got
;
4833 gad
->min
= fdcur
- fd
;
4836 /* If function descriptors took too much space, wrap some of them
4838 if (gad
->min
< wrapmin
)
4840 gad
->max
+= wrapmin
- gad
->min
;
4841 gad
->tmin
= gad
->min
= wrapmin
;
4844 /* If GOT entries took too much space, wrap some of them around.
4845 This may well cause gad->min to become lower than wrapmin. This
4846 will cause a relocation overflow later on, so we don't have to
4848 if ((bfd_vma
) gad
->max
> wrap
)
4850 gad
->min
-= gad
->max
- wrap
;
4854 /* Add TLS descriptors. */
4855 gad
->tmax
= gad
->max
+ tlsd
;
4856 gad
->tmin
= gad
->min
;
4859 /* If TLS descriptors took too much space, wrap an integral number
4861 if ((bfd_vma
) gad
->tmax
> wrap
)
4863 bfd_vma wrapsize
= gad
->tmax
- wrap
;
4865 wrapsize
+= tdescsz
/ 2;
4866 wrapsize
&= ~ tdescsz
/ 2;
4868 gad
->tmin
-= wrapsize
;
4869 gad
->tmax
-= wrapsize
;
4872 /* If there is space left and we have function descriptors
4873 referenced in PLT entries that could take advantage of shorter
4874 offsets, place them now. */
4875 if (fdplt
&& gad
->tmin
> wrapmin
)
4879 if ((bfd_vma
) (gad
->tmin
- wrapmin
) < fdplt
)
4880 fds
= gad
->tmin
- wrapmin
;
4890 /* If there is more space left, try to place some more function
4891 descriptors for PLT entries. */
4892 if (fdplt
&& (bfd_vma
) gad
->tmax
< wrap
)
4896 if ((bfd_vma
) (wrap
- gad
->tmax
) < fdplt
)
4897 fds
= wrap
- gad
->tmax
;
4907 /* If there is space left and we have TLS descriptors referenced in
4908 PLT entries that could take advantage of shorter offsets, place
4910 if (tlsdplt
&& gad
->tmin
> wrapmin
)
4914 if ((bfd_vma
) (gad
->tmin
- wrapmin
) < tlsdplt
)
4915 tlsds
= (gad
->tmin
- wrapmin
) & ~ (tdescsz
/ 2);
4921 gad
->tlsdplt
+= tlsds
;
4924 /* If there is more space left, try to place some more TLS
4925 descriptors for PLT entries. Although we could try to fit an
4926 additional TLS descriptor with half of it just before before the
4927 wrap point and another right past the wrap point, this might
4928 cause us to run out of space for the next region, so don't do
4930 if (tlsdplt
&& (bfd_vma
) gad
->tmax
< wrap
- tdescsz
/ 2)
4934 if ((bfd_vma
) (wrap
- gad
->tmax
) < tlsdplt
)
4935 tlsds
= (wrap
- gad
->tmax
) & ~ (tdescsz
/ 2);
4941 gad
->tlsdplt
+= tlsds
;
4944 /* If odd was initially computed as an offset past the wrap point,
4947 odd
= gad
->min
+ odd
- gad
->max
;
4949 /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed
4950 before returning, so do it here too. This guarantees that,
4951 should cur and fdcur meet at the wrap point, they'll both be
4953 if (gad
->cur
== gad
->max
)
4954 gad
->cur
= gad
->min
;
4956 /* Ditto for _frvfdpic_get_tlsdesc_entry(). */
4957 gad
->tcur
= gad
->max
;
4958 if (gad
->tcur
== gad
->tmax
)
4959 gad
->tcur
= gad
->tmin
;
4964 /* Compute the location of the next GOT entry, given the allocation
4965 data for a range. */
4967 inline static bfd_signed_vma
4968 _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
4974 /* If there was an odd word left behind, use it. */
4980 /* Otherwise, use the word pointed to by cur, reserve the next
4981 as an odd word, and skip to the next pair of words, possibly
4984 gad
->odd
= gad
->cur
+ 4;
4986 if (gad
->cur
== gad
->max
)
4987 gad
->cur
= gad
->min
;
4993 /* Compute the location of the next function descriptor entry in the
4994 GOT, given the allocation data for a range. */
4996 inline static bfd_signed_vma
4997 _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
4999 /* If we're at the bottom, wrap around, and only then allocate the
5000 next pair of words. */
5001 if (gad
->fdcur
== gad
->min
)
5002 gad
->fdcur
= gad
->max
;
5003 return gad
->fdcur
-= 8;
5006 /* Compute the location of the next TLS descriptor entry in the GOT,
5007 given the allocation data for a range. */
5008 inline static bfd_signed_vma
5009 _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
5017 /* If we're at the top of the region, wrap around to the bottom. */
5018 if (gad
->tcur
== gad
->tmax
)
5019 gad
->tcur
= gad
->tmin
;
5024 /* Assign GOT offsets for every GOT entry and function descriptor.
5025 Doing everything in a single pass is tricky. */
5028 _frvfdpic_assign_got_entries (void **entryp
, void *info_
)
5030 struct frvfdpic_relocs_info
*entry
= *entryp
;
5031 struct _frvfdpic_dynamic_got_plt_info
*dinfo
= info_
;
5034 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5035 else if (entry
->gotlos
)
5036 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5037 else if (entry
->gothilo
)
5038 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5041 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5042 else if (entry
->fdgotlos
)
5043 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5044 else if (entry
->fdgothilo
)
5045 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5047 if (entry
->fdgoff12
)
5048 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->got12
);
5049 else if (entry
->plt
&& dinfo
->got12
.fdplt
)
5051 dinfo
->got12
.fdplt
-= 8;
5052 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->got12
);
5054 else if (entry
->fdgofflos
)
5055 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gotlos
);
5056 else if (entry
->plt
&& dinfo
->gotlos
.fdplt
)
5058 dinfo
->gotlos
.fdplt
-= 8;
5059 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gotlos
);
5061 else if (entry
->plt
)
5063 dinfo
->gothilo
.fdplt
-= 8;
5064 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gothilo
);
5066 else if (entry
->privfd
)
5067 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gothilo
);
5069 if (entry
->tlsoff12
)
5070 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5071 else if (entry
->tlsofflos
)
5072 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5073 else if (entry
->tlsoffhilo
)
5074 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5076 if (entry
->tlsdesc12
)
5077 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->got12
);
5078 else if (entry
->tlsplt
&& dinfo
->got12
.tlsdplt
)
5080 dinfo
->got12
.tlsdplt
-= 8;
5081 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->got12
);
5083 else if (entry
->tlsdesclos
)
5084 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gotlos
);
5085 else if (entry
->tlsplt
&& dinfo
->gotlos
.tlsdplt
)
5087 dinfo
->gotlos
.tlsdplt
-= 8;
5088 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gotlos
);
5090 else if (entry
->tlsplt
)
5092 dinfo
->gothilo
.tlsdplt
-= 8;
5093 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gothilo
);
5095 else if (entry
->tlsdeschilo
)
5096 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gothilo
);
5101 /* Assign GOT offsets to private function descriptors used by PLT
5102 entries (or referenced by 32-bit offsets), as well as PLT entries
5103 and lazy PLT entries. */
5106 _frvfdpic_assign_plt_entries (void **entryp
, void *info_
)
5108 struct frvfdpic_relocs_info
*entry
= *entryp
;
5109 struct _frvfdpic_dynamic_got_plt_info
*dinfo
= info_
;
5112 BFD_ASSERT (entry
->fd_entry
);
5118 /* We use the section's raw size to mark the location of the
5120 entry
->plt_entry
= frvfdpic_plt_section (dinfo
->g
.info
)->size
;
5122 /* Figure out the length of this PLT entry based on the
5123 addressing mode we need to reach the function descriptor. */
5124 BFD_ASSERT (entry
->fd_entry
);
5125 if (entry
->fd_entry
>= -(1 << (12 - 1))
5126 && entry
->fd_entry
< (1 << (12 - 1)))
5128 else if (entry
->fd_entry
>= -(1 << (16 - 1))
5129 && entry
->fd_entry
< (1 << (16 - 1)))
5134 frvfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
5139 entry
->lzplt_entry
= dinfo
->g
.lzplt
;
5140 dinfo
->g
.lzplt
+= 8;
5141 /* If this entry is the one that gets the resolver stub, account
5142 for the additional instruction. */
5143 if (entry
->lzplt_entry
% FRVFDPIC_LZPLT_BLOCK_SIZE
5144 == FRVFDPIC_LZPLT_RESOLV_LOC
)
5145 dinfo
->g
.lzplt
+= 4;
5153 = frvfdpic_plt_section (dinfo
->g
.info
)->size
;
5155 if (dinfo
->g
.info
->executable
5156 && (entry
->symndx
!= -1
5157 || FRVFDPIC_SYM_LOCAL (dinfo
->g
.info
, entry
->d
.h
)))
5159 if ((bfd_signed_vma
)entry
->addend
>= -(1 << (16 - 1))
5160 /* FIXME: here we use the size of the TLS section
5161 as an upper bound for the value of the TLS
5162 symbol, because we may not know the exact value
5163 yet. If we get it wrong, we'll just waste a
5164 word in the PLT, and we should never get even
5165 close to 32 KiB of TLS anyway. */
5166 && elf_hash_table (dinfo
->g
.info
)->tls_sec
5167 && (elf_hash_table (dinfo
->g
.info
)->tls_sec
->size
5168 + (bfd_signed_vma
)(entry
->addend
) <= (1 << (16 - 1))))
5173 else if (entry
->tlsoff_entry
)
5175 if (entry
->tlsoff_entry
>= -(1 << (12 - 1))
5176 && entry
->tlsoff_entry
< (1 << (12 - 1)))
5178 else if (entry
->tlsoff_entry
>= -(1 << (16 - 1))
5179 && entry
->tlsoff_entry
< (1 << (16 - 1)))
5186 BFD_ASSERT (entry
->tlsdesc_entry
);
5188 if (entry
->tlsdesc_entry
>= -(1 << (12 - 1))
5189 && entry
->tlsdesc_entry
< (1 << (12 - 1)))
5191 else if (entry
->tlsdesc_entry
>= -(1 << (16 - 1))
5192 && entry
->tlsdesc_entry
< (1 << (16 - 1)))
5198 frvfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
5204 /* Cancel out any effects of calling _frvfdpic_assign_got_entries and
5205 _frvfdpic_assign_plt_entries. */
5208 _frvfdpic_reset_got_plt_entries (void **entryp
, void *ignore ATTRIBUTE_UNUSED
)
5210 struct frvfdpic_relocs_info
*entry
= *entryp
;
5212 entry
->got_entry
= 0;
5213 entry
->fdgot_entry
= 0;
5214 entry
->fd_entry
= 0;
5215 entry
->plt_entry
= (bfd_vma
)-1;
5216 entry
->lzplt_entry
= (bfd_vma
)-1;
5217 entry
->tlsoff_entry
= 0;
5218 entry
->tlsdesc_entry
= 0;
5219 entry
->tlsplt_entry
= (bfd_vma
)-1;
5224 /* Follow indirect and warning hash entries so that each got entry
5225 points to the final symbol definition. P must point to a pointer
5226 to the hash table we're traversing. Since this traversal may
5227 modify the hash table, we set this pointer to NULL to indicate
5228 we've made a potentially-destructive change to the hash table, so
5229 the traversal must be restarted. */
5231 _frvfdpic_resolve_final_relocs_info (void **entryp
, void *p
)
5233 struct frvfdpic_relocs_info
*entry
= *entryp
;
5236 if (entry
->symndx
== -1)
5238 struct elf_link_hash_entry
*h
= entry
->d
.h
;
5239 struct frvfdpic_relocs_info
*oentry
;
5241 while (h
->root
.type
== bfd_link_hash_indirect
5242 || h
->root
.type
== bfd_link_hash_warning
)
5243 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
5245 if (entry
->d
.h
== h
)
5248 oentry
= frvfdpic_relocs_info_for_global (*htab
, 0, h
, entry
->addend
,
5253 /* Merge the two entries. */
5254 frvfdpic_pic_merge_early_relocs_info (oentry
, entry
);
5255 htab_clear_slot (*htab
, entryp
);
5261 /* If we can't find this entry with the new bfd hash, re-insert
5262 it, and get the traversal restarted. */
5263 if (! htab_find (*htab
, entry
))
5265 htab_clear_slot (*htab
, entryp
);
5266 entryp
= htab_find_slot (*htab
, entry
, INSERT
);
5269 /* Abort the traversal, since the whole table may have
5270 moved, and leave it up to the parent to restart the
5272 *(htab_t
*)p
= NULL
;
5280 /* Compute the total size of the GOT, the PLT, the dynamic relocations
5281 section and the rofixup section. Assign locations for GOT and PLT
5285 _frvfdpic_size_got_plt (bfd
*output_bfd
,
5286 struct _frvfdpic_dynamic_got_plt_info
*gpinfop
)
5289 bfd_vma limit
, tlslimit
;
5290 struct bfd_link_info
*info
= gpinfop
->g
.info
;
5291 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
5293 memcpy (frvfdpic_dynamic_got_plt_info (info
), &gpinfop
->g
,
5294 sizeof (gpinfop
->g
));
5297 /* Compute the total size taken by entries in the 12-bit and 16-bit
5298 ranges, to tell how many PLT function descriptors we can bring
5299 into the 12-bit range without causing the 16-bit range to
5301 limit
= odd
+ gpinfop
->g
.got12
+ gpinfop
->g
.gotlos
5302 + gpinfop
->g
.fd12
+ gpinfop
->g
.fdlos
5303 + gpinfop
->g
.tlsd12
+ gpinfop
->g
.tlsdlos
;
5304 if (limit
< (bfd_vma
)1 << 16)
5305 limit
= ((bfd_vma
)1 << 16) - limit
;
5308 if (gpinfop
->g
.fdplt
< limit
)
5310 tlslimit
= (limit
- gpinfop
->g
.fdplt
) & ~ (bfd_vma
) 8;
5311 limit
= gpinfop
->g
.fdplt
;
5315 if (gpinfop
->g
.tlsdplt
< tlslimit
)
5316 tlslimit
= gpinfop
->g
.tlsdplt
;
5318 /* Determine the ranges of GOT offsets that we can use for each
5319 range of addressing modes. */
5320 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->got12
,
5329 (bfd_vma
)1 << (12-1));
5330 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->gotlos
,
5331 gpinfop
->got12
.tmin
,
5333 gpinfop
->got12
.tmax
,
5337 - gpinfop
->got12
.fdplt
,
5340 - gpinfop
->got12
.tlsdplt
,
5341 (bfd_vma
)1 << (16-1));
5342 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->gothilo
,
5343 gpinfop
->gotlos
.tmin
,
5345 gpinfop
->gotlos
.tmax
,
5349 - gpinfop
->got12
.fdplt
5350 - gpinfop
->gotlos
.fdplt
,
5351 gpinfop
->g
.tlsdhilo
,
5353 - gpinfop
->got12
.tlsdplt
5354 - gpinfop
->gotlos
.tlsdplt
,
5355 (bfd_vma
)1 << (32-1));
5357 /* Now assign (most) GOT offsets. */
5358 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_assign_got_entries
,
5361 frvfdpic_got_section (info
)->size
= gpinfop
->gothilo
.tmax
5362 - gpinfop
->gothilo
.tmin
5363 /* If an odd word is the last word of the GOT, we don't need this
5364 word to be part of the GOT. */
5365 - (odd
+ 4 == gpinfop
->gothilo
.tmax
? 4 : 0);
5366 if (frvfdpic_got_section (info
)->size
== 0)
5367 frvfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
5368 else if (frvfdpic_got_section (info
)->size
== 12
5369 && ! elf_hash_table (info
)->dynamic_sections_created
)
5371 frvfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
5372 frvfdpic_got_section (info
)->size
= 0;
5374 /* This will be non-NULL during relaxation. The assumption is that
5375 the size of one of these sections will never grow, only shrink,
5376 so we can use the larger buffer we allocated before. */
5377 else if (frvfdpic_got_section (info
)->contents
== NULL
)
5379 frvfdpic_got_section (info
)->contents
=
5380 (bfd_byte
*) bfd_zalloc (dynobj
,
5381 frvfdpic_got_section (info
)->size
);
5382 if (frvfdpic_got_section (info
)->contents
== NULL
)
5386 if (frvfdpic_gotrel_section (info
))
5387 /* Subtract the number of lzplt entries, since those will generate
5388 relocations in the pltrel section. */
5389 frvfdpic_gotrel_section (info
)->size
=
5390 (gpinfop
->g
.relocs
- gpinfop
->g
.lzplt
/ 8)
5391 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
5393 BFD_ASSERT (gpinfop
->g
.relocs
== 0);
5394 if (frvfdpic_gotrel_section (info
)->size
== 0)
5395 frvfdpic_gotrel_section (info
)->flags
|= SEC_EXCLUDE
;
5396 else if (frvfdpic_gotrel_section (info
)->contents
== NULL
)
5398 frvfdpic_gotrel_section (info
)->contents
=
5399 (bfd_byte
*) bfd_zalloc (dynobj
,
5400 frvfdpic_gotrel_section (info
)->size
);
5401 if (frvfdpic_gotrel_section (info
)->contents
== NULL
)
5405 frvfdpic_gotfixup_section (info
)->size
= (gpinfop
->g
.fixups
+ 1) * 4;
5406 if (frvfdpic_gotfixup_section (info
)->size
== 0)
5407 frvfdpic_gotfixup_section (info
)->flags
|= SEC_EXCLUDE
;
5408 else if (frvfdpic_gotfixup_section (info
)->contents
== NULL
)
5410 frvfdpic_gotfixup_section (info
)->contents
=
5411 (bfd_byte
*) bfd_zalloc (dynobj
,
5412 frvfdpic_gotfixup_section (info
)->size
);
5413 if (frvfdpic_gotfixup_section (info
)->contents
== NULL
)
5417 if (frvfdpic_pltrel_section (info
))
5419 frvfdpic_pltrel_section (info
)->size
=
5420 gpinfop
->g
.lzplt
/ 8
5421 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
5422 if (frvfdpic_pltrel_section (info
)->size
== 0)
5423 frvfdpic_pltrel_section (info
)->flags
|= SEC_EXCLUDE
;
5424 else if (frvfdpic_pltrel_section (info
)->contents
== NULL
)
5426 frvfdpic_pltrel_section (info
)->contents
=
5427 (bfd_byte
*) bfd_zalloc (dynobj
,
5428 frvfdpic_pltrel_section (info
)->size
);
5429 if (frvfdpic_pltrel_section (info
)->contents
== NULL
)
5434 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
5435 such that there's room for the additional instruction needed to
5436 call the resolver. Since _frvfdpic_assign_got_entries didn't
5437 account for them, our block size is 4 bytes smaller than the real
5439 if (frvfdpic_plt_section (info
))
5441 frvfdpic_plt_section (info
)->size
= gpinfop
->g
.lzplt
5442 + ((gpinfop
->g
.lzplt
+ (FRVFDPIC_LZPLT_BLOCK_SIZE
- 4) - 8)
5443 / (FRVFDPIC_LZPLT_BLOCK_SIZE
- 4) * 4);
5446 /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to
5447 actually assign lazy PLT entries addresses. */
5448 gpinfop
->g
.lzplt
= 0;
5450 /* Save information that we're going to need to generate GOT and PLT
5452 frvfdpic_got_initial_offset (info
) = -gpinfop
->gothilo
.tmin
;
5454 if (get_elf_backend_data (output_bfd
)->want_got_sym
)
5455 elf_hash_table (info
)->hgot
->root
.u
.def
.value
5456 = frvfdpic_got_initial_offset (info
);
5458 if (frvfdpic_plt_section (info
))
5459 frvfdpic_plt_initial_offset (info
) =
5460 frvfdpic_plt_section (info
)->size
;
5462 /* Allocate a ret statement at plt_initial_offset, to be used by
5463 locally-resolved TLS descriptors. */
5464 if (gpinfop
->g
.tls_ret_refs
)
5465 frvfdpic_plt_section (info
)->size
+= 4;
5467 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_assign_plt_entries
,
5470 /* Allocate the PLT section contents only after
5471 _frvfdpic_assign_plt_entries has a chance to add the size of the
5472 non-lazy PLT entries. */
5473 if (frvfdpic_plt_section (info
))
5475 if (frvfdpic_plt_section (info
)->size
== 0)
5476 frvfdpic_plt_section (info
)->flags
|= SEC_EXCLUDE
;
5477 else if (frvfdpic_plt_section (info
)->contents
== NULL
)
5479 frvfdpic_plt_section (info
)->contents
=
5480 (bfd_byte
*) bfd_zalloc (dynobj
,
5481 frvfdpic_plt_section (info
)->size
);
5482 if (frvfdpic_plt_section (info
)->contents
== NULL
)
5490 /* Set the sizes of the dynamic sections. */
5493 elf32_frvfdpic_size_dynamic_sections (bfd
*output_bfd
,
5494 struct bfd_link_info
*info
)
5498 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5500 dynobj
= elf_hash_table (info
)->dynobj
;
5501 BFD_ASSERT (dynobj
!= NULL
);
5503 if (elf_hash_table (info
)->dynamic_sections_created
)
5505 /* Set the contents of the .interp section to the interpreter. */
5506 if (info
->executable
)
5508 s
= bfd_get_section_by_name (dynobj
, ".interp");
5509 BFD_ASSERT (s
!= NULL
);
5510 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5511 s
->contents
= (bfd_byte
*) ELF_DYNAMIC_INTERPRETER
;
5515 memset (&gpinfo
, 0, sizeof (gpinfo
));
5516 gpinfo
.g
.info
= info
;
5520 htab_t relocs
= frvfdpic_relocs_info (info
);
5522 htab_traverse (relocs
, _frvfdpic_resolve_final_relocs_info
, &relocs
);
5524 if (relocs
== frvfdpic_relocs_info (info
))
5528 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_count_got_plt_entries
,
5531 /* Allocate space to save the summary information, we're going to
5532 use it if we're doing relaxations. */
5533 frvfdpic_dynamic_got_plt_info (info
) = bfd_alloc (dynobj
, sizeof (gpinfo
.g
));
5535 if (!_frvfdpic_size_got_plt (output_bfd
, &gpinfo
))
5538 if (elf_hash_table (info
)->dynamic_sections_created
)
5540 if (frvfdpic_got_section (info
)->size
)
5541 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTGOT
, 0))
5544 if (frvfdpic_pltrel_section (info
)->size
)
5545 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
5546 || !_bfd_elf_add_dynamic_entry (info
, DT_PLTREL
, DT_REL
)
5547 || !_bfd_elf_add_dynamic_entry (info
, DT_JMPREL
, 0))
5550 if (frvfdpic_gotrel_section (info
)->size
)
5551 if (!_bfd_elf_add_dynamic_entry (info
, DT_REL
, 0)
5552 || !_bfd_elf_add_dynamic_entry (info
, DT_RELSZ
, 0)
5553 || !_bfd_elf_add_dynamic_entry (info
, DT_RELENT
,
5554 sizeof (Elf32_External_Rel
)))
5562 elf32_frvfdpic_always_size_sections (bfd
*output_bfd
,
5563 struct bfd_link_info
*info
)
5565 if (!info
->relocatable
)
5567 struct elf_link_hash_entry
*h
;
5569 /* Force a PT_GNU_STACK segment to be created. */
5570 if (! elf_tdata (output_bfd
)->stack_flags
)
5571 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
| PF_X
;
5573 /* Define __stacksize if it's not defined yet. */
5574 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
5575 FALSE
, FALSE
, FALSE
);
5576 if (! h
|| h
->root
.type
!= bfd_link_hash_defined
5577 || h
->type
!= STT_OBJECT
5580 struct bfd_link_hash_entry
*bh
= NULL
;
5582 if (!(_bfd_generic_link_add_one_symbol
5583 (info
, output_bfd
, "__stacksize",
5584 BSF_GLOBAL
, bfd_abs_section_ptr
, DEFAULT_STACK_SIZE
,
5585 (const char *) NULL
, FALSE
,
5586 get_elf_backend_data (output_bfd
)->collect
, &bh
)))
5589 h
= (struct elf_link_hash_entry
*) bh
;
5591 h
->type
= STT_OBJECT
;
5592 /* This one must NOT be hidden. */
5599 /* Look for opportunities to relax TLS relocations. We can assume
5600 we're linking the main executable or a static-tls library, since
5601 otherwise we wouldn't have got here. */
5604 _frvfdpic_relax_got_plt_entries (void **entryp
, void *dinfo_
)
5606 struct frvfdpic_relocs_info
*entry
= *entryp
;
5607 struct _frvfdpic_dynamic_got_info
*dinfo
= dinfo_
;
5609 _frvfdpic_relax_tls_entries (entry
, dinfo
, TRUE
);
5615 elf32_frvfdpic_relax_section (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
,
5616 struct bfd_link_info
*info
, bfd_boolean
*again
)
5618 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5620 /* If we return early, we didn't change anything. */
5623 /* We'll do our thing when requested to relax the GOT section. */
5624 if (sec
!= frvfdpic_got_section (info
))
5627 /* We can only relax when linking the main executable or a library
5628 that can't be dlopened. */
5629 if (! info
->executable
&& ! (info
->flags
& DF_STATIC_TLS
))
5632 /* If there isn't a TLS section for this binary, we can't do
5633 anything about its TLS relocations (it probably doesn't have
5635 if (elf_hash_table (info
)->tls_sec
== NULL
)
5638 memset (&gpinfo
, 0, sizeof (gpinfo
));
5639 memcpy (&gpinfo
.g
, frvfdpic_dynamic_got_plt_info (info
), sizeof (gpinfo
.g
));
5641 /* Now look for opportunities to relax, adjusting the GOT usage
5643 htab_traverse (frvfdpic_relocs_info (info
),
5644 _frvfdpic_relax_got_plt_entries
,
5647 /* If we changed anything, reset and re-assign GOT and PLT entries. */
5648 if (memcmp (frvfdpic_dynamic_got_plt_info (info
),
5649 &gpinfo
.g
, sizeof (gpinfo
.g
)) != 0)
5651 /* Clear GOT and PLT assignments. */
5652 htab_traverse (frvfdpic_relocs_info (info
),
5653 _frvfdpic_reset_got_plt_entries
,
5656 /* The owner of the TLS section is the output bfd. There should
5657 be a better way to get to it. */
5658 if (!_frvfdpic_size_got_plt (elf_hash_table (info
)->tls_sec
->owner
,
5662 /* Repeat until we don't make any further changes. We could fail to
5663 introduce changes in a round if, for example, the 12-bit range is
5664 full, but we later release some space by getting rid of TLS
5665 descriptors in it. We have to repeat the whole process because
5666 we might have changed the size of a section processed before this
5675 elf32_frvfdpic_modify_program_headers (bfd
*output_bfd
,
5676 struct bfd_link_info
*info
)
5678 struct elf_obj_tdata
*tdata
= elf_tdata (output_bfd
);
5679 struct elf_segment_map
*m
;
5680 Elf_Internal_Phdr
*p
;
5682 /* objcopy and strip preserve what's already there using
5683 elf32_frvfdpic_copy_private_bfd_data (). */
5687 for (p
= tdata
->phdr
, m
= tdata
->segment_map
; m
!= NULL
; m
= m
->next
, p
++)
5688 if (m
->p_type
== PT_GNU_STACK
)
5693 struct elf_link_hash_entry
*h
;
5695 /* Obtain the pointer to the __stacksize symbol. */
5696 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
5697 FALSE
, FALSE
, FALSE
);
5700 while (h
->root
.type
== bfd_link_hash_indirect
5701 || h
->root
.type
== bfd_link_hash_warning
)
5702 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5703 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
5706 /* Set the header p_memsz from the symbol value. We
5707 intentionally ignore the symbol section. */
5708 if (h
&& h
->root
.type
== bfd_link_hash_defined
)
5709 p
->p_memsz
= h
->root
.u
.def
.value
;
5711 p
->p_memsz
= DEFAULT_STACK_SIZE
;
5719 /* Fill in code and data in dynamic sections. */
5722 elf32_frv_finish_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5723 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
5725 /* Nothing to be done for non-FDPIC. */
5730 elf32_frvfdpic_finish_dynamic_sections (bfd
*output_bfd
,
5731 struct bfd_link_info
*info
)
5736 dynobj
= elf_hash_table (info
)->dynobj
;
5738 if (frvfdpic_dynamic_got_plt_info (info
))
5740 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
== 0);
5742 if (frvfdpic_got_section (info
))
5744 BFD_ASSERT (frvfdpic_gotrel_section (info
)->size
5745 == (frvfdpic_gotrel_section (info
)->reloc_count
5746 * sizeof (Elf32_External_Rel
)));
5748 if (frvfdpic_gotfixup_section (info
))
5750 struct elf_link_hash_entry
*hgot
= elf_hash_table (info
)->hgot
;
5751 bfd_vma got_value
= hgot
->root
.u
.def
.value
5752 + hgot
->root
.u
.def
.section
->output_section
->vma
5753 + hgot
->root
.u
.def
.section
->output_offset
;
5754 struct bfd_link_hash_entry
*hend
;
5756 _frvfdpic_add_rofixup (output_bfd
, frvfdpic_gotfixup_section (info
),
5759 if (frvfdpic_gotfixup_section (info
)->size
5760 != (frvfdpic_gotfixup_section (info
)->reloc_count
* 4))
5763 (*_bfd_error_handler
)
5764 ("LINKER BUG: .rofixup section size mismatch");
5768 hend
= bfd_link_hash_lookup (info
->hash
, "__ROFIXUP_END__",
5769 FALSE
, FALSE
, TRUE
);
5771 && (hend
->type
== bfd_link_hash_defined
5772 || hend
->type
== bfd_link_hash_defweak
))
5775 frvfdpic_gotfixup_section (info
)->output_section
->vma
5776 + frvfdpic_gotfixup_section (info
)->output_offset
5777 + frvfdpic_gotfixup_section (info
)->size
5778 - hend
->u
.def
.section
->output_section
->vma
5779 - hend
->u
.def
.section
->output_offset
;
5780 BFD_ASSERT (hend
->u
.def
.value
== value
);
5781 if (hend
->u
.def
.value
!= value
)
5786 if (frvfdpic_pltrel_section (info
))
5788 BFD_ASSERT (frvfdpic_pltrel_section (info
)->size
5789 == (frvfdpic_pltrel_section (info
)->reloc_count
5790 * sizeof (Elf32_External_Rel
)));
5794 if (elf_hash_table (info
)->dynamic_sections_created
)
5796 Elf32_External_Dyn
* dyncon
;
5797 Elf32_External_Dyn
* dynconend
;
5799 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5801 BFD_ASSERT (sdyn
!= NULL
);
5803 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5804 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5806 for (; dyncon
< dynconend
; dyncon
++)
5808 Elf_Internal_Dyn dyn
;
5810 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5818 dyn
.d_un
.d_ptr
= frvfdpic_got_section (info
)->output_section
->vma
5819 + frvfdpic_got_section (info
)->output_offset
5820 + frvfdpic_got_initial_offset (info
);
5821 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5825 dyn
.d_un
.d_ptr
= frvfdpic_pltrel_section (info
)
5826 ->output_section
->vma
5827 + frvfdpic_pltrel_section (info
)->output_offset
;
5828 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5832 dyn
.d_un
.d_val
= frvfdpic_pltrel_section (info
)->size
;
5833 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5842 /* Adjust a symbol defined by a dynamic object and referenced by a
5846 elf32_frvfdpic_adjust_dynamic_symbol
5847 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5848 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
5852 dynobj
= elf_hash_table (info
)->dynobj
;
5854 /* Make sure we know what is going on here. */
5855 BFD_ASSERT (dynobj
!= NULL
5856 && (h
->u
.weakdef
!= NULL
5859 && !h
->def_regular
)));
5861 /* If this is a weak symbol, and there is a real definition, the
5862 processor independent code will have arranged for us to see the
5863 real definition first, and we can just use the same value. */
5864 if (h
->u
.weakdef
!= NULL
)
5866 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
5867 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
5868 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
5869 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
5875 /* Perform any actions needed for dynamic symbols. */
5878 elf32_frvfdpic_finish_dynamic_symbol
5879 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5880 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5881 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
,
5882 Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
)
5887 /* Decide whether to attempt to turn absptr or lsda encodings in
5888 shared libraries into pcrel within the given input section. */
5891 frvfdpic_elf_use_relative_eh_frame
5892 (bfd
*input_bfd ATTRIBUTE_UNUSED
,
5893 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5894 asection
*eh_frame_section ATTRIBUTE_UNUSED
)
5896 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
5900 /* Adjust the contents of an eh_frame_hdr section before they're output. */
5903 frvfdpic_elf_encode_eh_address (bfd
*abfd
,
5904 struct bfd_link_info
*info
,
5905 asection
*osec
, bfd_vma offset
,
5906 asection
*loc_sec
, bfd_vma loc_offset
,
5909 struct elf_link_hash_entry
*h
;
5911 h
= elf_hash_table (info
)->hgot
;
5912 BFD_ASSERT (h
&& h
->root
.type
== bfd_link_hash_defined
);
5914 if (! h
|| (_frvfdpic_osec_to_segment (abfd
, osec
)
5915 == _frvfdpic_osec_to_segment (abfd
, loc_sec
->output_section
)))
5916 return _bfd_elf_encode_eh_address (abfd
, info
, osec
, offset
,
5917 loc_sec
, loc_offset
, encoded
);
5919 BFD_ASSERT (_frvfdpic_osec_to_segment (abfd
, osec
)
5920 == (_frvfdpic_osec_to_segment
5921 (abfd
, h
->root
.u
.def
.section
->output_section
)));
5923 *encoded
= osec
->vma
+ offset
5924 - (h
->root
.u
.def
.value
5925 + h
->root
.u
.def
.section
->output_section
->vma
5926 + h
->root
.u
.def
.section
->output_offset
);
5928 return DW_EH_PE_datarel
| DW_EH_PE_sdata4
;
5931 /* Look through the relocs for a section during the first phase.
5933 Besides handling virtual table relocs for gc, we have to deal with
5934 all sorts of PIC-related relocations. We describe below the
5935 general plan on how to handle such relocations, even though we only
5936 collect information at this point, storing them in hash tables for
5937 perusal of later passes.
5939 32 relocations are propagated to the linker output when creating
5940 position-independent output. LO16 and HI16 relocations are not
5941 supposed to be encountered in this case.
5943 LABEL16 should always be resolvable by the linker, since it's only
5946 LABEL24, on the other hand, is used by calls. If it turns out that
5947 the target of a call is a dynamic symbol, a PLT entry must be
5948 created for it, which triggers the creation of a private function
5949 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
5951 GPREL relocations require the referenced symbol to be in the same
5952 segment as _gp, but this can only be checked later.
5954 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
5955 exist. LABEL24 might as well, since it may require a PLT entry,
5956 that will require a got.
5958 Non-FUNCDESC GOT relocations require a GOT entry to be created
5959 regardless of whether the symbol is dynamic. However, since a
5960 global symbol that turns out to not be exported may have the same
5961 address of a non-dynamic symbol, we don't assign GOT entries at
5962 this point, such that we can share them in this case. A relocation
5963 for the GOT entry always has to be created, be it to offset a
5964 private symbol by the section load address, be it to get the symbol
5965 resolved dynamically.
5967 FUNCDESC GOT relocations require a GOT entry to be created, and
5968 handled as if a FUNCDESC relocation was applied to the GOT entry in
5971 FUNCDESC relocations referencing a symbol that turns out to NOT be
5972 dynamic cause a private function descriptor to be created. The
5973 FUNCDESC relocation then decays to a 32 relocation that points at
5974 the private descriptor. If the symbol is dynamic, the FUNCDESC
5975 relocation is propagated to the linker output, such that the
5976 dynamic linker creates the canonical descriptor, pointing to the
5977 dynamically-resolved definition of the function.
5979 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
5980 symbols that are assigned to the same segment as the GOT, but we
5981 can only check this later, after we know the complete set of
5982 symbols defined and/or exported.
5984 FUNCDESC GOTOFF relocations require a function descriptor to be
5985 created and, unless lazy binding is disabled or the symbol is not
5986 dynamic, a lazy PLT entry. Since we can't tell at this point
5987 whether a symbol is going to be dynamic, we have to decide later
5988 whether to create a lazy PLT entry or bind the descriptor directly
5989 to the private function.
5991 FUNCDESC_VALUE relocations are not supposed to be present in object
5992 files, but they may very well be simply propagated to the linker
5993 output, since they have no side effect.
5996 A function descriptor always requires a FUNCDESC_VALUE relocation.
5997 Whether it's in .plt.rel or not depends on whether lazy binding is
5998 enabled and on whether the referenced symbol is dynamic.
6000 The existence of a lazy PLT requires the resolverStub lazy PLT
6001 entry to be present.
6004 As for assignment of GOT, PLT and lazy PLT entries, and private
6005 descriptors, we might do them all sequentially, but we can do
6006 better than that. For example, we can place GOT entries and
6007 private function descriptors referenced using 12-bit operands
6008 closer to the PIC register value, such that these relocations don't
6009 overflow. Those that are only referenced with LO16 relocations
6010 could come next, but we may as well place PLT-required function
6011 descriptors in the 12-bit range to make them shorter. Symbols
6012 referenced with LO16/HI16 may come next, but we may place
6013 additional function descriptors in the 16-bit range if we can
6014 reliably tell that we've already placed entries that are ever
6015 referenced with only LO16. PLT entries are therefore generated as
6016 small as possible, while not introducing relocation overflows in
6017 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
6018 generated before or after PLT entries, but not intermingled with
6019 them, such that we can have more lazy PLT entries in range for a
6020 branch to the resolverStub. The resolverStub should be emitted at
6021 the most distant location from the first lazy PLT entry such that
6022 it's still in range for a branch, or closer, if there isn't a need
6023 for so many lazy PLT entries. Additional lazy PLT entries may be
6024 emitted after the resolverStub, as long as branches are still in
6025 range. If the branch goes out of range, longer lazy PLT entries
6028 We could further optimize PLT and lazy PLT entries by giving them
6029 priority in assignment to closer-to-gr17 locations depending on the
6030 number of occurrences of references to them (assuming a function
6031 that's called more often is more important for performance, so its
6032 PLT entry should be faster), or taking hints from the compiler.
6033 Given infinite time and money... :-) */
6036 elf32_frv_check_relocs (abfd
, info
, sec
, relocs
)
6038 struct bfd_link_info
*info
;
6040 const Elf_Internal_Rela
*relocs
;
6042 Elf_Internal_Shdr
*symtab_hdr
;
6043 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
6044 const Elf_Internal_Rela
*rel
;
6045 const Elf_Internal_Rela
*rel_end
;
6047 struct frvfdpic_relocs_info
*picrel
;
6049 if (info
->relocatable
)
6052 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6053 sym_hashes
= elf_sym_hashes (abfd
);
6054 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof(Elf32_External_Sym
);
6055 if (!elf_bad_symtab (abfd
))
6056 sym_hashes_end
-= symtab_hdr
->sh_info
;
6058 dynobj
= elf_hash_table (info
)->dynobj
;
6059 rel_end
= relocs
+ sec
->reloc_count
;
6060 for (rel
= relocs
; rel
< rel_end
; rel
++)
6062 struct elf_link_hash_entry
*h
;
6063 unsigned long r_symndx
;
6065 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6066 if (r_symndx
< symtab_hdr
->sh_info
)
6070 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6071 while (h
->root
.type
== bfd_link_hash_indirect
6072 || h
->root
.type
== bfd_link_hash_warning
)
6073 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6076 switch (ELF32_R_TYPE (rel
->r_info
))
6078 case R_FRV_GETTLSOFF
:
6079 case R_FRV_TLSDESC_VALUE
:
6080 case R_FRV_GOTTLSDESC12
:
6081 case R_FRV_GOTTLSDESCHI
:
6082 case R_FRV_GOTTLSDESCLO
:
6083 case R_FRV_GOTTLSOFF12
:
6084 case R_FRV_GOTTLSOFFHI
:
6085 case R_FRV_GOTTLSOFFLO
:
6090 case R_FRV_FUNCDESC_GOT12
:
6091 case R_FRV_FUNCDESC_GOTHI
:
6092 case R_FRV_FUNCDESC_GOTLO
:
6093 case R_FRV_GOTOFF12
:
6094 case R_FRV_GOTOFFHI
:
6095 case R_FRV_GOTOFFLO
:
6096 case R_FRV_FUNCDESC_GOTOFF12
:
6097 case R_FRV_FUNCDESC_GOTOFFHI
:
6098 case R_FRV_FUNCDESC_GOTOFFLO
:
6099 case R_FRV_FUNCDESC
:
6100 case R_FRV_FUNCDESC_VALUE
:
6101 case R_FRV_TLSMOFF12
:
6102 case R_FRV_TLSMOFFHI
:
6103 case R_FRV_TLSMOFFLO
:
6105 if (! IS_FDPIC (abfd
))
6109 case R_FRV_GPRELU12
:
6116 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6117 if (! _frv_create_got_section (abfd
, info
))
6120 if (! IS_FDPIC (abfd
))
6127 if (h
->dynindx
== -1)
6128 switch (ELF_ST_VISIBILITY (h
->other
))
6134 bfd_elf_link_record_dynamic_symbol (info
, h
);
6138 = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info
),
6140 rel
->r_addend
, INSERT
);
6143 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
6144 (info
), abfd
, r_symndx
,
6145 rel
->r_addend
, INSERT
);
6155 switch (ELF32_R_TYPE (rel
->r_info
))
6158 if (IS_FDPIC (abfd
))
6162 case R_FRV_FUNCDESC_VALUE
:
6163 picrel
->relocsfdv
++;
6164 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
6169 if (! IS_FDPIC (abfd
))
6173 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
6183 picrel
->gothilo
= 1;
6186 case R_FRV_FUNCDESC_GOT12
:
6187 picrel
->fdgot12
= 1;
6190 case R_FRV_FUNCDESC_GOTHI
:
6191 case R_FRV_FUNCDESC_GOTLO
:
6192 picrel
->fdgothilo
= 1;
6195 case R_FRV_GOTOFF12
:
6196 case R_FRV_GOTOFFHI
:
6197 case R_FRV_GOTOFFLO
:
6201 case R_FRV_FUNCDESC_GOTOFF12
:
6202 picrel
->fdgoff12
= 1;
6205 case R_FRV_FUNCDESC_GOTOFFHI
:
6206 case R_FRV_FUNCDESC_GOTOFFLO
:
6207 picrel
->fdgoffhilo
= 1;
6210 case R_FRV_FUNCDESC
:
6215 case R_FRV_GETTLSOFF
:
6219 case R_FRV_TLSDESC_VALUE
:
6220 picrel
->relocstlsd
++;
6223 case R_FRV_GOTTLSDESC12
:
6224 picrel
->tlsdesc12
= 1;
6227 case R_FRV_GOTTLSDESCHI
:
6228 case R_FRV_GOTTLSDESCLO
:
6229 picrel
->tlsdeschilo
= 1;
6232 case R_FRV_TLSMOFF12
:
6233 case R_FRV_TLSMOFFHI
:
6234 case R_FRV_TLSMOFFLO
:
6238 case R_FRV_GOTTLSOFF12
:
6239 picrel
->tlsoff12
= 1;
6240 info
->flags
|= DF_STATIC_TLS
;
6243 case R_FRV_GOTTLSOFFHI
:
6244 case R_FRV_GOTTLSOFFLO
:
6245 picrel
->tlsoffhilo
= 1;
6246 info
->flags
|= DF_STATIC_TLS
;
6250 picrel
->relocstlsoff
++;
6251 info
->flags
|= DF_STATIC_TLS
;
6254 /* This relocation describes the C++ object vtable hierarchy.
6255 Reconstruct it for later use during GC. */
6256 case R_FRV_GNU_VTINHERIT
:
6257 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6261 /* This relocation describes which C++ vtable entries are actually
6262 used. Record for later use during GC. */
6263 case R_FRV_GNU_VTENTRY
:
6264 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
6272 case R_FRV_GPRELU12
:
6276 case R_FRV_TLSDESC_RELAX
:
6277 case R_FRV_GETTLSOFF_RELAX
:
6278 case R_FRV_TLSOFF_RELAX
:
6283 (*_bfd_error_handler
)
6284 (_("%B: unsupported relocation type %i"),
6285 abfd
, ELF32_R_TYPE (rel
->r_info
));
6294 /* Return the machine subcode from the ELF e_flags header. */
6297 elf32_frv_machine (abfd
)
6300 switch (elf_elfheader (abfd
)->e_flags
& EF_FRV_CPU_MASK
)
6303 case EF_FRV_CPU_FR550
: return bfd_mach_fr550
;
6304 case EF_FRV_CPU_FR500
: return bfd_mach_fr500
;
6305 case EF_FRV_CPU_FR450
: return bfd_mach_fr450
;
6306 case EF_FRV_CPU_FR405
: return bfd_mach_fr400
;
6307 case EF_FRV_CPU_FR400
: return bfd_mach_fr400
;
6308 case EF_FRV_CPU_FR300
: return bfd_mach_fr300
;
6309 case EF_FRV_CPU_SIMPLE
: return bfd_mach_frvsimple
;
6310 case EF_FRV_CPU_TOMCAT
: return bfd_mach_frvtomcat
;
6313 return bfd_mach_frv
;
6316 /* Set the right machine number for a FRV ELF file. */
6319 elf32_frv_object_p (abfd
)
6322 bfd_default_set_arch_mach (abfd
, bfd_arch_frv
, elf32_frv_machine (abfd
));
6323 return (((elf_elfheader (abfd
)->e_flags
& EF_FRV_FDPIC
) != 0)
6324 == (IS_FDPIC (abfd
)));
6327 /* Function to set the ELF flag bits. */
6330 frv_elf_set_private_flags (abfd
, flags
)
6334 elf_elfheader (abfd
)->e_flags
= flags
;
6335 elf_flags_init (abfd
) = TRUE
;
6339 /* Copy backend specific data from one object module to another. */
6342 frv_elf_copy_private_bfd_data (ibfd
, obfd
)
6346 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6347 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6350 BFD_ASSERT (!elf_flags_init (obfd
)
6351 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
6353 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
6354 elf_flags_init (obfd
) = TRUE
;
6358 /* Return true if the architecture described by elf header flag
6359 EXTENSION is an extension of the architecture described by BASE. */
6362 frv_elf_arch_extension_p (flagword base
, flagword extension
)
6364 if (base
== extension
)
6367 /* CPU_GENERIC code can be merged with code for a specific
6368 architecture, in which case the result is marked as being
6369 for the specific architecture. Everything is therefore
6370 an extension of CPU_GENERIC. */
6371 if (base
== EF_FRV_CPU_GENERIC
)
6374 if (extension
== EF_FRV_CPU_FR450
)
6375 if (base
== EF_FRV_CPU_FR400
|| base
== EF_FRV_CPU_FR405
)
6378 if (extension
== EF_FRV_CPU_FR405
)
6379 if (base
== EF_FRV_CPU_FR400
)
6386 elf32_frvfdpic_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
6390 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6391 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6394 if (! frv_elf_copy_private_bfd_data (ibfd
, obfd
))
6397 if (! elf_tdata (ibfd
) || ! elf_tdata (ibfd
)->phdr
6398 || ! elf_tdata (obfd
) || ! elf_tdata (obfd
)->phdr
)
6401 /* Copy the stack size. */
6402 for (i
= 0; i
< elf_elfheader (ibfd
)->e_phnum
; i
++)
6403 if (elf_tdata (ibfd
)->phdr
[i
].p_type
== PT_GNU_STACK
)
6405 Elf_Internal_Phdr
*iphdr
= &elf_tdata (ibfd
)->phdr
[i
];
6407 for (i
= 0; i
< elf_elfheader (obfd
)->e_phnum
; i
++)
6408 if (elf_tdata (obfd
)->phdr
[i
].p_type
== PT_GNU_STACK
)
6410 memcpy (&elf_tdata (obfd
)->phdr
[i
], iphdr
, sizeof (*iphdr
));
6412 /* Rewrite the phdrs, since we're only called after they
6413 were first written. */
6414 if (bfd_seek (obfd
, (bfd_signed_vma
) get_elf_backend_data (obfd
)
6415 ->s
->sizeof_ehdr
, SEEK_SET
) != 0
6416 || get_elf_backend_data (obfd
)->s
6417 ->write_out_phdrs (obfd
, elf_tdata (obfd
)->phdr
,
6418 elf_elfheader (obfd
)->e_phnum
) != 0)
6429 /* Merge backend specific data from an object file to the output
6430 object file when linking. */
6433 frv_elf_merge_private_bfd_data (ibfd
, obfd
)
6437 flagword old_flags
, old_partial
;
6438 flagword new_flags
, new_partial
;
6439 bfd_boolean error
= FALSE
;
6443 new_opt
[0] = old_opt
[0] = '\0';
6444 new_flags
= elf_elfheader (ibfd
)->e_flags
;
6445 old_flags
= elf_elfheader (obfd
)->e_flags
;
6447 if (new_flags
& EF_FRV_FDPIC
)
6448 new_flags
&= ~EF_FRV_PIC
;
6451 (*_bfd_error_handler
) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s",
6452 old_flags
, new_flags
, elf_flags_init (obfd
) ? "yes" : "no",
6453 bfd_get_filename (ibfd
));
6456 if (!elf_flags_init (obfd
)) /* First call, no flags set. */
6458 elf_flags_init (obfd
) = TRUE
;
6459 old_flags
= new_flags
;
6462 else if (new_flags
== old_flags
) /* Compatible flags are ok. */
6465 else /* Possibly incompatible flags. */
6467 /* Warn if different # of gprs are used. Note, 0 means nothing is
6468 said about the size of gprs. */
6469 new_partial
= (new_flags
& EF_FRV_GPR_MASK
);
6470 old_partial
= (old_flags
& EF_FRV_GPR_MASK
);
6471 if (new_partial
== old_partial
)
6474 else if (new_partial
== 0)
6477 else if (old_partial
== 0)
6478 old_flags
|= new_partial
;
6482 switch (new_partial
)
6484 default: strcat (new_opt
, " -mgpr-??"); break;
6485 case EF_FRV_GPR_32
: strcat (new_opt
, " -mgpr-32"); break;
6486 case EF_FRV_GPR_64
: strcat (new_opt
, " -mgpr-64"); break;
6489 switch (old_partial
)
6491 default: strcat (old_opt
, " -mgpr-??"); break;
6492 case EF_FRV_GPR_32
: strcat (old_opt
, " -mgpr-32"); break;
6493 case EF_FRV_GPR_64
: strcat (old_opt
, " -mgpr-64"); break;
6497 /* Warn if different # of fprs are used. Note, 0 means nothing is
6498 said about the size of fprs. */
6499 new_partial
= (new_flags
& EF_FRV_FPR_MASK
);
6500 old_partial
= (old_flags
& EF_FRV_FPR_MASK
);
6501 if (new_partial
== old_partial
)
6504 else if (new_partial
== 0)
6507 else if (old_partial
== 0)
6508 old_flags
|= new_partial
;
6512 switch (new_partial
)
6514 default: strcat (new_opt
, " -mfpr-?"); break;
6515 case EF_FRV_FPR_32
: strcat (new_opt
, " -mfpr-32"); break;
6516 case EF_FRV_FPR_64
: strcat (new_opt
, " -mfpr-64"); break;
6517 case EF_FRV_FPR_NONE
: strcat (new_opt
, " -msoft-float"); break;
6520 switch (old_partial
)
6522 default: strcat (old_opt
, " -mfpr-?"); break;
6523 case EF_FRV_FPR_32
: strcat (old_opt
, " -mfpr-32"); break;
6524 case EF_FRV_FPR_64
: strcat (old_opt
, " -mfpr-64"); break;
6525 case EF_FRV_FPR_NONE
: strcat (old_opt
, " -msoft-float"); break;
6529 /* Warn if different dword support was used. Note, 0 means nothing is
6530 said about the dword support. */
6531 new_partial
= (new_flags
& EF_FRV_DWORD_MASK
);
6532 old_partial
= (old_flags
& EF_FRV_DWORD_MASK
);
6533 if (new_partial
== old_partial
)
6536 else if (new_partial
== 0)
6539 else if (old_partial
== 0)
6540 old_flags
|= new_partial
;
6544 switch (new_partial
)
6546 default: strcat (new_opt
, " -mdword-?"); break;
6547 case EF_FRV_DWORD_YES
: strcat (new_opt
, " -mdword"); break;
6548 case EF_FRV_DWORD_NO
: strcat (new_opt
, " -mno-dword"); break;
6551 switch (old_partial
)
6553 default: strcat (old_opt
, " -mdword-?"); break;
6554 case EF_FRV_DWORD_YES
: strcat (old_opt
, " -mdword"); break;
6555 case EF_FRV_DWORD_NO
: strcat (old_opt
, " -mno-dword"); break;
6559 /* Or in flags that accumulate (ie, if one module uses it, mark that the
6561 old_flags
|= new_flags
& (EF_FRV_DOUBLE
6564 | EF_FRV_NON_PIC_RELOCS
);
6566 /* If any module was compiled without -G0, clear the G0 bit. */
6567 old_flags
= ((old_flags
& ~ EF_FRV_G0
)
6568 | (old_flags
& new_flags
& EF_FRV_G0
));
6570 /* If any module was compiled without -mnopack, clear the mnopack bit. */
6571 old_flags
= ((old_flags
& ~ EF_FRV_NOPACK
)
6572 | (old_flags
& new_flags
& EF_FRV_NOPACK
));
6574 /* We don't have to do anything if the pic flags are the same, or the new
6575 module(s) were compiled with -mlibrary-pic. */
6576 new_partial
= (new_flags
& EF_FRV_PIC_FLAGS
);
6577 old_partial
= (old_flags
& EF_FRV_PIC_FLAGS
);
6578 if ((new_partial
== old_partial
) || ((new_partial
& EF_FRV_LIBPIC
) != 0))
6581 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
6582 flags if any from the new module. */
6583 else if ((old_partial
& EF_FRV_LIBPIC
) != 0)
6584 old_flags
= (old_flags
& ~ EF_FRV_PIC_FLAGS
) | new_partial
;
6586 /* If we have mixtures of -fpic and -fPIC, or in both bits. */
6587 else if (new_partial
!= 0 && old_partial
!= 0)
6588 old_flags
|= new_partial
;
6590 /* One module was compiled for pic and the other was not, see if we have
6591 had any relocations that are not pic-safe. */
6594 if ((old_flags
& EF_FRV_NON_PIC_RELOCS
) == 0)
6595 old_flags
|= new_partial
;
6598 old_flags
&= ~ EF_FRV_PIC_FLAGS
;
6599 #ifndef FRV_NO_PIC_ERROR
6601 (*_bfd_error_handler
)
6602 (_("%s: compiled with %s and linked with modules that use non-pic relocations"),
6603 bfd_get_filename (ibfd
),
6604 (new_flags
& EF_FRV_BIGPIC
) ? "-fPIC" : "-fpic");
6609 /* Warn if different cpu is used (allow a specific cpu to override
6610 the generic cpu). */
6611 new_partial
= (new_flags
& EF_FRV_CPU_MASK
);
6612 old_partial
= (old_flags
& EF_FRV_CPU_MASK
);
6613 if (frv_elf_arch_extension_p (new_partial
, old_partial
))
6616 else if (frv_elf_arch_extension_p (old_partial
, new_partial
))
6617 old_flags
= (old_flags
& ~EF_FRV_CPU_MASK
) | new_partial
;
6621 switch (new_partial
)
6623 default: strcat (new_opt
, " -mcpu=?"); break;
6624 case EF_FRV_CPU_GENERIC
: strcat (new_opt
, " -mcpu=frv"); break;
6625 case EF_FRV_CPU_SIMPLE
: strcat (new_opt
, " -mcpu=simple"); break;
6626 case EF_FRV_CPU_FR550
: strcat (new_opt
, " -mcpu=fr550"); break;
6627 case EF_FRV_CPU_FR500
: strcat (new_opt
, " -mcpu=fr500"); break;
6628 case EF_FRV_CPU_FR450
: strcat (new_opt
, " -mcpu=fr450"); break;
6629 case EF_FRV_CPU_FR405
: strcat (new_opt
, " -mcpu=fr405"); break;
6630 case EF_FRV_CPU_FR400
: strcat (new_opt
, " -mcpu=fr400"); break;
6631 case EF_FRV_CPU_FR300
: strcat (new_opt
, " -mcpu=fr300"); break;
6632 case EF_FRV_CPU_TOMCAT
: strcat (new_opt
, " -mcpu=tomcat"); break;
6635 switch (old_partial
)
6637 default: strcat (old_opt
, " -mcpu=?"); break;
6638 case EF_FRV_CPU_GENERIC
: strcat (old_opt
, " -mcpu=frv"); break;
6639 case EF_FRV_CPU_SIMPLE
: strcat (old_opt
, " -mcpu=simple"); break;
6640 case EF_FRV_CPU_FR550
: strcat (old_opt
, " -mcpu=fr550"); break;
6641 case EF_FRV_CPU_FR500
: strcat (old_opt
, " -mcpu=fr500"); break;
6642 case EF_FRV_CPU_FR450
: strcat (old_opt
, " -mcpu=fr450"); break;
6643 case EF_FRV_CPU_FR405
: strcat (old_opt
, " -mcpu=fr405"); break;
6644 case EF_FRV_CPU_FR400
: strcat (old_opt
, " -mcpu=fr400"); break;
6645 case EF_FRV_CPU_FR300
: strcat (old_opt
, " -mcpu=fr300"); break;
6646 case EF_FRV_CPU_TOMCAT
: strcat (old_opt
, " -mcpu=tomcat"); break;
6650 /* Print out any mismatches from above. */
6654 (*_bfd_error_handler
)
6655 (_("%s: compiled with %s and linked with modules compiled with %s"),
6656 bfd_get_filename (ibfd
), new_opt
, old_opt
);
6659 /* Warn about any other mismatches */
6660 new_partial
= (new_flags
& ~ EF_FRV_ALL_FLAGS
);
6661 old_partial
= (old_flags
& ~ EF_FRV_ALL_FLAGS
);
6662 if (new_partial
!= old_partial
)
6664 old_flags
|= new_partial
;
6666 (*_bfd_error_handler
)
6667 (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"),
6668 bfd_get_filename (ibfd
), (long)new_partial
, (long)old_partial
);
6672 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
6673 if ((old_flags
& EF_FRV_CPU_MASK
) == EF_FRV_CPU_SIMPLE
)
6674 old_flags
|= EF_FRV_NOPACK
;
6676 /* Update the old flags now with changes made above. */
6677 old_partial
= elf_elfheader (obfd
)->e_flags
& EF_FRV_CPU_MASK
;
6678 elf_elfheader (obfd
)->e_flags
= old_flags
;
6679 if (old_partial
!= (old_flags
& EF_FRV_CPU_MASK
))
6680 bfd_default_set_arch_mach (obfd
, bfd_arch_frv
, elf32_frv_machine (obfd
));
6682 if (((new_flags
& EF_FRV_FDPIC
) == 0)
6683 != (! IS_FDPIC (ibfd
)))
6686 if (IS_FDPIC (obfd
))
6687 (*_bfd_error_handler
)
6688 (_("%s: cannot link non-fdpic object file into fdpic executable"),
6689 bfd_get_filename (ibfd
));
6691 (*_bfd_error_handler
)
6692 (_("%s: cannot link fdpic object file into non-fdpic executable"),
6693 bfd_get_filename (ibfd
));
6697 bfd_set_error (bfd_error_bad_value
);
6704 frv_elf_print_private_bfd_data (abfd
, ptr
)
6708 FILE *file
= (FILE *) ptr
;
6711 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6713 /* Print normal ELF private data. */
6714 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6716 flags
= elf_elfheader (abfd
)->e_flags
;
6717 fprintf (file
, _("private flags = 0x%lx:"), (long)flags
);
6719 switch (flags
& EF_FRV_CPU_MASK
)
6722 case EF_FRV_CPU_SIMPLE
: fprintf (file
, " -mcpu=simple"); break;
6723 case EF_FRV_CPU_FR550
: fprintf (file
, " -mcpu=fr550"); break;
6724 case EF_FRV_CPU_FR500
: fprintf (file
, " -mcpu=fr500"); break;
6725 case EF_FRV_CPU_FR450
: fprintf (file
, " -mcpu=fr450"); break;
6726 case EF_FRV_CPU_FR405
: fprintf (file
, " -mcpu=fr405"); break;
6727 case EF_FRV_CPU_FR400
: fprintf (file
, " -mcpu=fr400"); break;
6728 case EF_FRV_CPU_FR300
: fprintf (file
, " -mcpu=fr300"); break;
6729 case EF_FRV_CPU_TOMCAT
: fprintf (file
, " -mcpu=tomcat"); break;
6732 switch (flags
& EF_FRV_GPR_MASK
)
6735 case EF_FRV_GPR_32
: fprintf (file
, " -mgpr-32"); break;
6736 case EF_FRV_GPR_64
: fprintf (file
, " -mgpr-64"); break;
6739 switch (flags
& EF_FRV_FPR_MASK
)
6742 case EF_FRV_FPR_32
: fprintf (file
, " -mfpr-32"); break;
6743 case EF_FRV_FPR_64
: fprintf (file
, " -mfpr-64"); break;
6744 case EF_FRV_FPR_NONE
: fprintf (file
, " -msoft-float"); break;
6747 switch (flags
& EF_FRV_DWORD_MASK
)
6750 case EF_FRV_DWORD_YES
: fprintf (file
, " -mdword"); break;
6751 case EF_FRV_DWORD_NO
: fprintf (file
, " -mno-dword"); break;
6754 if (flags
& EF_FRV_DOUBLE
)
6755 fprintf (file
, " -mdouble");
6757 if (flags
& EF_FRV_MEDIA
)
6758 fprintf (file
, " -mmedia");
6760 if (flags
& EF_FRV_MULADD
)
6761 fprintf (file
, " -mmuladd");
6763 if (flags
& EF_FRV_PIC
)
6764 fprintf (file
, " -fpic");
6766 if (flags
& EF_FRV_BIGPIC
)
6767 fprintf (file
, " -fPIC");
6769 if (flags
& EF_FRV_LIBPIC
)
6770 fprintf (file
, " -mlibrary-pic");
6772 if (flags
& EF_FRV_FDPIC
)
6773 fprintf (file
, " -mfdpic");
6775 if (flags
& EF_FRV_NON_PIC_RELOCS
)
6776 fprintf (file
, " non-pic relocations");
6778 if (flags
& EF_FRV_G0
)
6779 fprintf (file
, " -G0");
6786 /* Support for core dump NOTE sections. */
6789 elf32_frv_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
6792 unsigned int raw_size
;
6794 switch (note
->descsz
)
6799 /* The Linux/FRV elf_prstatus struct is 268 bytes long. The other
6800 hardcoded offsets and sizes listed below (and contained within
6801 this lexical block) refer to fields in the target's elf_prstatus
6804 /* `pr_cursig' is at offset 12. */
6805 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
6807 /* `pr_pid' is at offset 24. */
6808 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
6810 /* `pr_reg' is at offset 72. */
6813 /* Most grok_prstatus implementations set `raw_size' to the size
6814 of the pr_reg field. For Linux/FRV, we set `raw_size' to be
6815 the size of `pr_reg' plus the size of `pr_exec_fdpic_loadmap'
6816 and `pr_interp_fdpic_loadmap', both of which (by design)
6817 immediately follow `pr_reg'. This will allow these fields to
6818 be viewed by GDB as registers.
6820 `pr_reg' is 184 bytes long. `pr_exec_fdpic_loadmap' and
6821 `pr_interp_fdpic_loadmap' are 4 bytes each. */
6822 raw_size
= 184 + 4 + 4;
6827 /* Make a ".reg/999" section. */
6828 return _bfd_elfcore_make_pseudosection (abfd
, ".reg", raw_size
,
6829 note
->descpos
+ offset
);
6833 elf32_frv_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
6835 switch (note
->descsz
)
6840 /* The Linux/FRV elf_prpsinfo struct is 124 bytes long. */
6843 /* `pr_fname' is found at offset 28 and is 16 bytes long. */
6844 elf_tdata (abfd
)->core_program
6845 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
6847 /* `pr_psargs' is found at offset 44 and is 80 bytes long. */
6848 elf_tdata (abfd
)->core_command
6849 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
6852 /* Note that for some reason, a spurious space is tacked
6853 onto the end of the args in some (at least one anyway)
6854 implementations, so strip it off if it exists. */
6857 char *command
= elf_tdata (abfd
)->core_command
;
6858 int n
= strlen (command
);
6860 if (0 < n
&& command
[n
- 1] == ' ')
6861 command
[n
- 1] = '\0';
6866 #define ELF_ARCH bfd_arch_frv
6867 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
6868 #define ELF_MAXPAGESIZE 0x1000
6870 #define TARGET_BIG_SYM bfd_elf32_frv_vec
6871 #define TARGET_BIG_NAME "elf32-frv"
6873 #define elf_info_to_howto frv_info_to_howto_rela
6874 #define elf_backend_relocate_section elf32_frv_relocate_section
6875 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
6876 #define elf_backend_check_relocs elf32_frv_check_relocs
6877 #define elf_backend_object_p elf32_frv_object_p
6878 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
6880 #define elf_backend_can_gc_sections 1
6881 #define elf_backend_rela_normal 1
6883 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
6884 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
6885 #define bfd_elf32_bfd_copy_private_bfd_data frv_elf_copy_private_bfd_data
6886 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
6887 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
6889 #define elf_backend_want_got_sym 1
6890 #define elf_backend_got_header_size 0
6891 #define elf_backend_want_got_plt 0
6892 #define elf_backend_plt_readonly 1
6893 #define elf_backend_want_plt_sym 0
6894 #define elf_backend_plt_header_size 0
6896 #define elf_backend_finish_dynamic_sections \
6897 elf32_frv_finish_dynamic_sections
6899 #define elf_backend_grok_prstatus elf32_frv_grok_prstatus
6900 #define elf_backend_grok_psinfo elf32_frv_grok_psinfo
6902 #include "elf32-target.h"
6904 #undef ELF_MAXPAGESIZE
6905 #define ELF_MAXPAGESIZE 0x4000
6907 #undef TARGET_BIG_SYM
6908 #define TARGET_BIG_SYM bfd_elf32_frvfdpic_vec
6909 #undef TARGET_BIG_NAME
6910 #define TARGET_BIG_NAME "elf32-frvfdpic"
6912 #define elf32_bed elf32_frvfdpic_bed
6914 #undef elf_info_to_howto_rel
6915 #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel
6917 #undef bfd_elf32_bfd_link_hash_table_create
6918 #define bfd_elf32_bfd_link_hash_table_create \
6919 frvfdpic_elf_link_hash_table_create
6920 #undef elf_backend_always_size_sections
6921 #define elf_backend_always_size_sections \
6922 elf32_frvfdpic_always_size_sections
6923 #undef elf_backend_modify_program_headers
6924 #define elf_backend_modify_program_headers \
6925 elf32_frvfdpic_modify_program_headers
6926 #undef bfd_elf32_bfd_copy_private_bfd_data
6927 #define bfd_elf32_bfd_copy_private_bfd_data \
6928 elf32_frvfdpic_copy_private_bfd_data
6930 #undef elf_backend_create_dynamic_sections
6931 #define elf_backend_create_dynamic_sections \
6932 elf32_frvfdpic_create_dynamic_sections
6933 #undef elf_backend_adjust_dynamic_symbol
6934 #define elf_backend_adjust_dynamic_symbol \
6935 elf32_frvfdpic_adjust_dynamic_symbol
6936 #undef elf_backend_size_dynamic_sections
6937 #define elf_backend_size_dynamic_sections \
6938 elf32_frvfdpic_size_dynamic_sections
6939 #undef bfd_elf32_bfd_relax_section
6940 #define bfd_elf32_bfd_relax_section \
6941 elf32_frvfdpic_relax_section
6942 #undef elf_backend_finish_dynamic_symbol
6943 #define elf_backend_finish_dynamic_symbol \
6944 elf32_frvfdpic_finish_dynamic_symbol
6945 #undef elf_backend_finish_dynamic_sections
6946 #define elf_backend_finish_dynamic_sections \
6947 elf32_frvfdpic_finish_dynamic_sections
6949 #undef elf_backend_can_make_relative_eh_frame
6950 #define elf_backend_can_make_relative_eh_frame \
6951 frvfdpic_elf_use_relative_eh_frame
6952 #undef elf_backend_can_make_lsda_relative_eh_frame
6953 #define elf_backend_can_make_lsda_relative_eh_frame \
6954 frvfdpic_elf_use_relative_eh_frame
6955 #undef elf_backend_encode_eh_address
6956 #define elf_backend_encode_eh_address \
6957 frvfdpic_elf_encode_eh_address
6959 #undef elf_backend_may_use_rel_p
6960 #define elf_backend_may_use_rel_p 1
6961 #undef elf_backend_may_use_rela_p
6962 #define elf_backend_may_use_rela_p 1
6963 /* We use REL for dynamic relocations only. */
6964 #undef elf_backend_default_use_rela_p
6965 #define elf_backend_default_use_rela_p 1
6967 #undef elf_backend_omit_section_dynsym
6968 #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym
6970 #include "elf32-target.h"