1 /* FRV-specific support for 32-bit ELF.
2 Copyright 2002, 2003, 2004, 2005 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_gc_sweep_hook
61 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*, const
62 Elf_Internal_Rela
*));
63 static asection
* elf32_frv_gc_mark_hook
64 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
65 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
66 static bfd_boolean elf32_frv_check_relocs
67 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
68 const Elf_Internal_Rela
*));
69 static int elf32_frv_machine
71 static bfd_boolean elf32_frv_object_p
73 static bfd_boolean frv_elf_set_private_flags
74 PARAMS ((bfd
*, flagword
));
75 static bfd_boolean frv_elf_copy_private_bfd_data
76 PARAMS ((bfd
*, bfd
*));
77 static bfd_boolean frv_elf_merge_private_bfd_data
78 PARAMS ((bfd
*, bfd
*));
79 static bfd_boolean frv_elf_print_private_bfd_data
80 PARAMS ((bfd
*, PTR
));
82 static reloc_howto_type elf32_frv_howto_table
[] =
84 /* This reloc does nothing. */
85 HOWTO (R_FRV_NONE
, /* type */
87 2, /* size (0 = byte, 1 = short, 2 = long) */
89 FALSE
, /* pc_relative */
91 complain_overflow_bitfield
, /* complain_on_overflow */
92 bfd_elf_generic_reloc
, /* special_function */
93 "R_FRV_NONE", /* name */
94 FALSE
, /* partial_inplace */
97 FALSE
), /* pcrel_offset */
99 /* A 32 bit absolute relocation. */
100 HOWTO (R_FRV_32
, /* type */
102 2, /* size (0 = byte, 1 = short, 2 = long) */
104 FALSE
, /* pc_relative */
106 complain_overflow_bitfield
, /* complain_on_overflow */
107 bfd_elf_generic_reloc
, /* special_function */
108 "R_FRV_32", /* name */
109 FALSE
, /* partial_inplace */
110 0xffffffff, /* src_mask */
111 0xffffffff, /* dst_mask */
112 FALSE
), /* pcrel_offset */
114 /* A 16 bit pc-relative relocation. */
115 HOWTO (R_FRV_LABEL16
, /* type */
117 2, /* size (0 = byte, 1 = short, 2 = long) */
119 TRUE
, /* pc_relative */
121 complain_overflow_signed
, /* complain_on_overflow */
122 bfd_elf_generic_reloc
, /* special_function */
123 "R_FRV_LABEL16", /* name */
124 FALSE
, /* partial_inplace */
125 0xffff, /* src_mask */
126 0xffff, /* dst_mask */
127 TRUE
), /* pcrel_offset */
129 /* A 24-bit pc-relative relocation. */
130 HOWTO (R_FRV_LABEL24
, /* type */
132 2, /* size (0 = byte, 1 = short, 2 = long) */
134 TRUE
, /* pc_relative */
136 complain_overflow_bitfield
, /* complain_on_overflow */
137 bfd_elf_generic_reloc
, /* special_function */
138 "R_FRV_LABEL24", /* name */
139 FALSE
, /* partial_inplace */
140 0x7e03ffff, /* src_mask */
141 0x7e03ffff, /* dst_mask */
142 TRUE
), /* pcrel_offset */
144 HOWTO (R_FRV_LO16
, /* type */
146 2, /* size (0 = byte, 1 = short, 2 = long) */
148 FALSE
, /* pc_relative */
150 complain_overflow_dont
, /* complain_on_overflow */
151 bfd_elf_generic_reloc
, /* special_function */
152 "R_FRV_LO16", /* name */
153 FALSE
, /* partial_inplace */
154 0xffff, /* src_mask */
155 0xffff, /* dst_mask */
156 FALSE
), /* pcrel_offset */
158 HOWTO (R_FRV_HI16
, /* type */
160 2, /* size (0 = byte, 1 = short, 2 = long) */
162 FALSE
, /* pc_relative */
164 complain_overflow_dont
, /* complain_on_overflow */
165 bfd_elf_generic_reloc
, /* special_function */
166 "R_FRV_HI16", /* name */
167 FALSE
, /* partial_inplace */
168 0xffff, /* src_mask */
169 0xffff, /* dst_mask */
170 FALSE
), /* pcrel_offset */
172 HOWTO (R_FRV_GPREL12
, /* type */
174 2, /* size (0 = byte, 1 = short, 2 = long) */
176 FALSE
, /* pc_relative */
178 complain_overflow_dont
, /* complain_on_overflow */
179 bfd_elf_generic_reloc
, /* special_function */
180 "R_FRV_GPREL12", /* name */
181 FALSE
, /* partial_inplace */
182 0xfff, /* src_mask */
183 0xfff, /* dst_mask */
184 FALSE
), /* pcrel_offset */
186 HOWTO (R_FRV_GPRELU12
, /* type */
188 2, /* size (0 = byte, 1 = short, 2 = long) */
190 FALSE
, /* pc_relative */
192 complain_overflow_dont
, /* complain_on_overflow */
193 bfd_elf_generic_reloc
, /* special_function */
194 "R_FRV_GPRELU12", /* name */
195 FALSE
, /* partial_inplace */
196 0xfff, /* src_mask */
197 0x3f03f, /* dst_mask */
198 FALSE
), /* pcrel_offset */
200 HOWTO (R_FRV_GPREL32
, /* type */
202 2, /* size (0 = byte, 1 = short, 2 = long) */
204 FALSE
, /* pc_relative */
206 complain_overflow_dont
, /* complain_on_overflow */
207 bfd_elf_generic_reloc
, /* special_function */
208 "R_FRV_GPREL32", /* name */
209 FALSE
, /* partial_inplace */
210 0xffffffff, /* src_mask */
211 0xffffffff, /* dst_mask */
212 FALSE
), /* pcrel_offset */
214 HOWTO (R_FRV_GPRELHI
, /* type */
216 2, /* size (0 = byte, 1 = short, 2 = long) */
218 FALSE
, /* pc_relative */
220 complain_overflow_dont
, /* complain_on_overflow */
221 bfd_elf_generic_reloc
, /* special_function */
222 "R_FRV_GPRELHI", /* name */
223 FALSE
, /* partial_inplace */
224 0xffff, /* src_mask */
225 0xffff, /* dst_mask */
226 FALSE
), /* pcrel_offset */
228 HOWTO (R_FRV_GPRELLO
, /* type */
230 2, /* size (0 = byte, 1 = short, 2 = long) */
232 FALSE
, /* pc_relative */
234 complain_overflow_dont
, /* complain_on_overflow */
235 bfd_elf_generic_reloc
, /* special_function */
236 "R_FRV_GPRELLO", /* name */
237 FALSE
, /* partial_inplace */
238 0xffff, /* src_mask */
239 0xffff, /* dst_mask */
240 FALSE
), /* pcrel_offset */
242 /* A 12-bit signed operand with the GOT offset for the address of
244 HOWTO (R_FRV_GOT12
, /* type */
246 2, /* size (0 = byte, 1 = short, 2 = long) */
248 FALSE
, /* pc_relative */
250 complain_overflow_signed
, /* complain_on_overflow */
251 bfd_elf_generic_reloc
, /* special_function */
252 "R_FRV_GOT12", /* name */
253 FALSE
, /* partial_inplace */
254 0xfff, /* src_mask */
255 0xfff, /* dst_mask */
256 FALSE
), /* pcrel_offset */
258 /* The upper 16 bits of the GOT offset for the address of the
260 HOWTO (R_FRV_GOTHI
, /* type */
262 2, /* size (0 = byte, 1 = short, 2 = long) */
264 FALSE
, /* pc_relative */
266 complain_overflow_dont
, /* complain_on_overflow */
267 bfd_elf_generic_reloc
, /* special_function */
268 "R_FRV_GOTHI", /* name */
269 FALSE
, /* partial_inplace */
270 0xffff, /* src_mask */
271 0xffff, /* dst_mask */
272 FALSE
), /* pcrel_offset */
274 /* The lower 16 bits of the GOT offset for the address of the
276 HOWTO (R_FRV_GOTLO
, /* type */
278 2, /* size (0 = byte, 1 = short, 2 = long) */
280 FALSE
, /* pc_relative */
282 complain_overflow_dont
, /* complain_on_overflow */
283 bfd_elf_generic_reloc
, /* special_function */
284 "R_FRV_GOTLO", /* name */
285 FALSE
, /* partial_inplace */
286 0xffff, /* src_mask */
287 0xffff, /* dst_mask */
288 FALSE
), /* pcrel_offset */
290 /* The 32-bit address of the canonical descriptor of a function. */
291 HOWTO (R_FRV_FUNCDESC
, /* type */
293 2, /* size (0 = byte, 1 = short, 2 = long) */
295 FALSE
, /* pc_relative */
297 complain_overflow_bitfield
, /* complain_on_overflow */
298 bfd_elf_generic_reloc
, /* special_function */
299 "R_FRV_FUNCDESC", /* name */
300 FALSE
, /* partial_inplace */
301 0xffffffff, /* src_mask */
302 0xffffffff, /* dst_mask */
303 FALSE
), /* pcrel_offset */
305 /* A 12-bit signed operand with the GOT offset for the address of
306 canonical descriptor of a function. */
307 HOWTO (R_FRV_FUNCDESC_GOT12
, /* type */
309 2, /* size (0 = byte, 1 = short, 2 = long) */
311 FALSE
, /* pc_relative */
313 complain_overflow_signed
, /* complain_on_overflow */
314 bfd_elf_generic_reloc
, /* special_function */
315 "R_FRV_FUNCDESC_GOT12", /* name */
316 FALSE
, /* partial_inplace */
317 0xfff, /* src_mask */
318 0xfff, /* dst_mask */
319 FALSE
), /* pcrel_offset */
321 /* The upper 16 bits of the GOT offset for the address of the
322 canonical descriptor of a function. */
323 HOWTO (R_FRV_FUNCDESC_GOTHI
, /* type */
325 2, /* size (0 = byte, 1 = short, 2 = long) */
327 FALSE
, /* pc_relative */
329 complain_overflow_dont
, /* complain_on_overflow */
330 bfd_elf_generic_reloc
, /* special_function */
331 "R_FRV_FUNCDESC_GOTHI", /* name */
332 FALSE
, /* partial_inplace */
333 0xffff, /* src_mask */
334 0xffff, /* dst_mask */
335 FALSE
), /* pcrel_offset */
337 /* The lower 16 bits of the GOT offset for the address of the
338 canonical descriptor of a function. */
339 HOWTO (R_FRV_FUNCDESC_GOTLO
, /* type */
341 2, /* size (0 = byte, 1 = short, 2 = long) */
343 FALSE
, /* pc_relative */
345 complain_overflow_dont
, /* complain_on_overflow */
346 bfd_elf_generic_reloc
, /* special_function */
347 "R_FRV_FUNCDESC_GOTLO", /* name */
348 FALSE
, /* partial_inplace */
349 0xffff, /* src_mask */
350 0xffff, /* dst_mask */
351 FALSE
), /* pcrel_offset */
353 /* The 64-bit descriptor of a function. */
354 HOWTO (R_FRV_FUNCDESC_VALUE
, /* type */
356 2, /* size (0 = byte, 1 = short, 2 = long) */
358 FALSE
, /* pc_relative */
360 complain_overflow_bitfield
, /* complain_on_overflow */
361 bfd_elf_generic_reloc
, /* special_function */
362 "R_FRV_FUNCDESC_VALUE", /* name */
363 FALSE
, /* partial_inplace */
364 0xffffffff, /* src_mask */
365 0xffffffff, /* dst_mask */
366 FALSE
), /* pcrel_offset */
368 /* A 12-bit signed operand with the GOT offset for the address of
369 canonical descriptor of a function. */
370 HOWTO (R_FRV_FUNCDESC_GOTOFF12
, /* type */
372 2, /* size (0 = byte, 1 = short, 2 = long) */
374 FALSE
, /* pc_relative */
376 complain_overflow_signed
, /* complain_on_overflow */
377 bfd_elf_generic_reloc
, /* special_function */
378 "R_FRV_FUNCDESC_GOTOFF12", /* name */
379 FALSE
, /* partial_inplace */
380 0xfff, /* src_mask */
381 0xfff, /* dst_mask */
382 FALSE
), /* pcrel_offset */
384 /* The upper 16 bits of the GOT offset for the address of the
385 canonical descriptor of a function. */
386 HOWTO (R_FRV_FUNCDESC_GOTOFFHI
, /* type */
388 2, /* size (0 = byte, 1 = short, 2 = long) */
390 FALSE
, /* pc_relative */
392 complain_overflow_dont
, /* complain_on_overflow */
393 bfd_elf_generic_reloc
, /* special_function */
394 "R_FRV_FUNCDESC_GOTOFFHI", /* name */
395 FALSE
, /* partial_inplace */
396 0xffff, /* src_mask */
397 0xffff, /* dst_mask */
398 FALSE
), /* pcrel_offset */
400 /* The lower 16 bits of the GOT offset for the address of the
401 canonical descriptor of a function. */
402 HOWTO (R_FRV_FUNCDESC_GOTOFFLO
, /* type */
404 2, /* size (0 = byte, 1 = short, 2 = long) */
406 FALSE
, /* pc_relative */
408 complain_overflow_dont
, /* complain_on_overflow */
409 bfd_elf_generic_reloc
, /* special_function */
410 "R_FRV_FUNCDESC_GOTOFFLO", /* name */
411 FALSE
, /* partial_inplace */
412 0xffff, /* src_mask */
413 0xffff, /* dst_mask */
414 FALSE
), /* pcrel_offset */
416 /* A 12-bit signed operand with the GOT offset for the address of
418 HOWTO (R_FRV_GOTOFF12
, /* type */
420 2, /* size (0 = byte, 1 = short, 2 = long) */
422 FALSE
, /* pc_relative */
424 complain_overflow_signed
, /* complain_on_overflow */
425 bfd_elf_generic_reloc
, /* special_function */
426 "R_FRV_GOTOFF12", /* name */
427 FALSE
, /* partial_inplace */
428 0xfff, /* src_mask */
429 0xfff, /* dst_mask */
430 FALSE
), /* pcrel_offset */
432 /* The upper 16 bits of the GOT offset for the address of the
434 HOWTO (R_FRV_GOTOFFHI
, /* type */
436 2, /* size (0 = byte, 1 = short, 2 = long) */
438 FALSE
, /* pc_relative */
440 complain_overflow_dont
, /* complain_on_overflow */
441 bfd_elf_generic_reloc
, /* special_function */
442 "R_FRV_GOTOFFHI", /* name */
443 FALSE
, /* partial_inplace */
444 0xffff, /* src_mask */
445 0xffff, /* dst_mask */
446 FALSE
), /* pcrel_offset */
448 /* The lower 16 bits of the GOT offset for the address of the
450 HOWTO (R_FRV_GOTOFFLO
, /* type */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
454 FALSE
, /* pc_relative */
456 complain_overflow_dont
, /* complain_on_overflow */
457 bfd_elf_generic_reloc
, /* special_function */
458 "R_FRV_GOTOFFLO", /* name */
459 FALSE
, /* partial_inplace */
460 0xffff, /* src_mask */
461 0xffff, /* dst_mask */
462 FALSE
), /* pcrel_offset */
464 /* A 24-bit pc-relative relocation referencing the TLS PLT entry for
465 a thread-local symbol. If the symbol number is 0, it refers to
467 HOWTO (R_FRV_GETTLSOFF
, /* type */
469 2, /* size (0 = byte, 1 = short, 2 = long) */
471 TRUE
, /* pc_relative */
473 complain_overflow_bitfield
, /* complain_on_overflow */
474 bfd_elf_generic_reloc
, /* special_function */
475 "R_FRV_GETTLSOFF", /* name */
476 FALSE
, /* partial_inplace */
477 0x7e03ffff, /* src_mask */
478 0x7e03ffff, /* dst_mask */
479 TRUE
), /* pcrel_offset */
481 /* A 64-bit TLS descriptor for a symbol. This relocation is only
482 valid as a REL, dynamic relocation. */
483 HOWTO (R_FRV_TLSDESC_VALUE
, /* type */
485 2, /* size (0 = byte, 1 = short, 2 = long) */
487 FALSE
, /* pc_relative */
489 complain_overflow_bitfield
, /* complain_on_overflow */
490 bfd_elf_generic_reloc
, /* special_function */
491 "R_FRV_TLSDESC_VALUE", /* name */
492 FALSE
, /* partial_inplace */
493 0xffffffff, /* src_mask */
494 0xffffffff, /* dst_mask */
495 FALSE
), /* pcrel_offset */
497 /* A 12-bit signed operand with the GOT offset for the TLS
498 descriptor of the symbol. */
499 HOWTO (R_FRV_GOTTLSDESC12
, /* type */
501 2, /* size (0 = byte, 1 = short, 2 = long) */
503 FALSE
, /* pc_relative */
505 complain_overflow_signed
, /* complain_on_overflow */
506 bfd_elf_generic_reloc
, /* special_function */
507 "R_FRV_GOTTLSDESC12", /* name */
508 FALSE
, /* partial_inplace */
509 0xfff, /* src_mask */
510 0xfff, /* dst_mask */
511 FALSE
), /* pcrel_offset */
513 /* The upper 16 bits of the GOT offset for the TLS descriptor of the
515 HOWTO (R_FRV_GOTTLSDESCHI
, /* type */
517 2, /* size (0 = byte, 1 = short, 2 = long) */
519 FALSE
, /* pc_relative */
521 complain_overflow_dont
, /* complain_on_overflow */
522 bfd_elf_generic_reloc
, /* special_function */
523 "R_FRV_GOTTLSDESCHI", /* name */
524 FALSE
, /* partial_inplace */
525 0xffff, /* src_mask */
526 0xffff, /* dst_mask */
527 FALSE
), /* pcrel_offset */
529 /* The lower 16 bits of the GOT offset for the TLS descriptor of the
531 HOWTO (R_FRV_GOTTLSDESCLO
, /* type */
533 2, /* size (0 = byte, 1 = short, 2 = long) */
535 FALSE
, /* pc_relative */
537 complain_overflow_dont
, /* complain_on_overflow */
538 bfd_elf_generic_reloc
, /* special_function */
539 "R_FRV_GOTTLSDESCLO", /* name */
540 FALSE
, /* partial_inplace */
541 0xffff, /* src_mask */
542 0xffff, /* dst_mask */
543 FALSE
), /* pcrel_offset */
545 /* A 12-bit signed operand with the offset from the module base
546 address to the thread-local symbol address. */
547 HOWTO (R_FRV_TLSMOFF12
, /* type */
549 2, /* size (0 = byte, 1 = short, 2 = long) */
551 FALSE
, /* pc_relative */
553 complain_overflow_signed
, /* complain_on_overflow */
554 bfd_elf_generic_reloc
, /* special_function */
555 "R_FRV_TLSMOFF12", /* name */
556 FALSE
, /* partial_inplace */
557 0xfff, /* src_mask */
558 0xfff, /* dst_mask */
559 FALSE
), /* pcrel_offset */
561 /* The upper 16 bits of the offset from the module base address to
562 the thread-local symbol address. */
563 HOWTO (R_FRV_TLSMOFFHI
, /* type */
565 2, /* size (0 = byte, 1 = short, 2 = long) */
567 FALSE
, /* pc_relative */
569 complain_overflow_dont
, /* complain_on_overflow */
570 bfd_elf_generic_reloc
, /* special_function */
571 "R_FRV_TLSMOFFHI", /* name */
572 FALSE
, /* partial_inplace */
573 0xffff, /* src_mask */
574 0xffff, /* dst_mask */
575 FALSE
), /* pcrel_offset */
577 /* The lower 16 bits of the offset from the module base address to
578 the thread-local symbol address. */
579 HOWTO (R_FRV_TLSMOFFLO
, /* type */
581 2, /* size (0 = byte, 1 = short, 2 = long) */
583 FALSE
, /* pc_relative */
585 complain_overflow_dont
, /* complain_on_overflow */
586 bfd_elf_generic_reloc
, /* special_function */
587 "R_FRV_TLSMOFFLO", /* name */
588 FALSE
, /* partial_inplace */
589 0xffff, /* src_mask */
590 0xffff, /* dst_mask */
591 FALSE
), /* pcrel_offset */
593 /* A 12-bit signed operand with the GOT offset for the TLSOFF entry
595 HOWTO (R_FRV_GOTTLSOFF12
, /* type */
597 2, /* size (0 = byte, 1 = short, 2 = long) */
599 FALSE
, /* pc_relative */
601 complain_overflow_signed
, /* complain_on_overflow */
602 bfd_elf_generic_reloc
, /* special_function */
603 "R_FRV_GOTTLSOFF12", /* name */
604 FALSE
, /* partial_inplace */
605 0xfff, /* src_mask */
606 0xfff, /* dst_mask */
607 FALSE
), /* pcrel_offset */
609 /* The upper 16 bits of the GOT offset for the TLSOFF entry for a
611 HOWTO (R_FRV_GOTTLSOFFHI
, /* type */
613 2, /* size (0 = byte, 1 = short, 2 = long) */
615 FALSE
, /* pc_relative */
617 complain_overflow_dont
, /* complain_on_overflow */
618 bfd_elf_generic_reloc
, /* special_function */
619 "R_FRV_GOTTLSOFFHI", /* name */
620 FALSE
, /* partial_inplace */
621 0xffff, /* src_mask */
622 0xffff, /* dst_mask */
623 FALSE
), /* pcrel_offset */
625 /* The lower 16 bits of the GOT offset for the TLSOFF entry for a
627 HOWTO (R_FRV_GOTTLSOFFLO
, /* type */
629 2, /* size (0 = byte, 1 = short, 2 = long) */
631 FALSE
, /* pc_relative */
633 complain_overflow_dont
, /* complain_on_overflow */
634 bfd_elf_generic_reloc
, /* special_function */
635 "R_FRV_GOTTLSOFFLO", /* name */
636 FALSE
, /* partial_inplace */
637 0xffff, /* src_mask */
638 0xffff, /* dst_mask */
639 FALSE
), /* pcrel_offset */
641 /* The 32-bit offset from the thread pointer (not the module base
642 address) to a thread-local symbol. */
643 HOWTO (R_FRV_TLSOFF
, /* type */
645 2, /* size (0 = byte, 1 = short, 2 = long) */
647 FALSE
, /* pc_relative */
649 complain_overflow_dont
, /* complain_on_overflow */
650 bfd_elf_generic_reloc
, /* special_function */
651 "R_FRV_TLSOFF", /* name */
652 FALSE
, /* partial_inplace */
653 0xffffffff, /* src_mask */
654 0xffffffff, /* dst_mask */
655 FALSE
), /* pcrel_offset */
657 /* An annotation for linker relaxation, that denotes the
658 symbol+addend whose TLS descriptor is referenced by the sum of
659 the two input registers of an ldd instruction. */
660 HOWTO (R_FRV_TLSDESC_RELAX
, /* type */
662 2, /* size (0 = byte, 1 = short, 2 = long) */
664 FALSE
, /* pc_relative */
666 complain_overflow_dont
, /* complain_on_overflow */
667 bfd_elf_generic_reloc
, /* special_function */
668 "R_FRV_TLSDESC_RELAX", /* name */
669 FALSE
, /* partial_inplace */
672 FALSE
), /* pcrel_offset */
674 /* An annotation for linker relaxation, that denotes the
675 symbol+addend whose TLS resolver entry point is given by the sum
676 of the two register operands of an calll instruction. */
677 HOWTO (R_FRV_GETTLSOFF_RELAX
, /* type */
679 2, /* size (0 = byte, 1 = short, 2 = long) */
681 FALSE
, /* pc_relative */
683 complain_overflow_dont
, /* complain_on_overflow */
684 bfd_elf_generic_reloc
, /* special_function */
685 "R_FRV_GETTLSOFF_RELAX", /* name */
686 FALSE
, /* partial_inplace */
689 FALSE
), /* pcrel_offset */
691 /* An annotation for linker relaxation, that denotes the
692 symbol+addend whose TLS offset GOT entry is given by the sum of
693 the two input registers of an ld instruction. */
694 HOWTO (R_FRV_TLSOFF_RELAX
, /* type */
696 2, /* size (0 = byte, 1 = short, 2 = long) */
698 FALSE
, /* pc_relative */
700 complain_overflow_bitfield
, /* complain_on_overflow */
701 bfd_elf_generic_reloc
, /* special_function */
702 "R_FRV_TLSOFF_RELAX", /* name */
703 FALSE
, /* partial_inplace */
706 FALSE
), /* pcrel_offset */
708 /* A 32-bit offset from the module base address to
709 the thread-local symbol address. */
710 HOWTO (R_FRV_TLSMOFF
, /* type */
712 2, /* size (0 = byte, 1 = short, 2 = long) */
714 FALSE
, /* pc_relative */
716 complain_overflow_dont
, /* complain_on_overflow */
717 bfd_elf_generic_reloc
, /* special_function */
718 "R_FRV_TLSMOFF", /* name */
719 FALSE
, /* partial_inplace */
720 0xffffffff, /* src_mask */
721 0xffffffff, /* dst_mask */
722 FALSE
), /* pcrel_offset */
725 /* GNU extension to record C++ vtable hierarchy. */
726 static reloc_howto_type elf32_frv_vtinherit_howto
=
727 HOWTO (R_FRV_GNU_VTINHERIT
, /* type */
729 2, /* size (0 = byte, 1 = short, 2 = long) */
731 FALSE
, /* pc_relative */
733 complain_overflow_dont
, /* complain_on_overflow */
734 NULL
, /* special_function */
735 "R_FRV_GNU_VTINHERIT", /* name */
736 FALSE
, /* partial_inplace */
739 FALSE
); /* pcrel_offset */
741 /* GNU extension to record C++ vtable member usage. */
742 static reloc_howto_type elf32_frv_vtentry_howto
=
743 HOWTO (R_FRV_GNU_VTENTRY
, /* type */
745 2, /* size (0 = byte, 1 = short, 2 = long) */
747 FALSE
, /* pc_relative */
749 complain_overflow_dont
, /* complain_on_overflow */
750 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
751 "R_FRV_GNU_VTENTRY", /* name */
752 FALSE
, /* partial_inplace */
755 FALSE
); /* pcrel_offset */
757 /* The following 3 relocations are REL. The only difference to the
758 entries in the table above are that partial_inplace is TRUE. */
759 static reloc_howto_type elf32_frv_rel_32_howto
=
760 HOWTO (R_FRV_32
, /* type */
762 2, /* size (0 = byte, 1 = short, 2 = long) */
764 FALSE
, /* pc_relative */
766 complain_overflow_bitfield
, /* complain_on_overflow */
767 bfd_elf_generic_reloc
, /* special_function */
768 "R_FRV_32", /* name */
769 TRUE
, /* partial_inplace */
770 0xffffffff, /* src_mask */
771 0xffffffff, /* dst_mask */
772 FALSE
); /* pcrel_offset */
774 static reloc_howto_type elf32_frv_rel_funcdesc_howto
=
775 HOWTO (R_FRV_FUNCDESC
, /* type */
777 2, /* size (0 = byte, 1 = short, 2 = long) */
779 FALSE
, /* pc_relative */
781 complain_overflow_bitfield
, /* complain_on_overflow */
782 bfd_elf_generic_reloc
, /* special_function */
783 "R_FRV_FUNCDESC", /* name */
784 TRUE
, /* partial_inplace */
785 0xffffffff, /* src_mask */
786 0xffffffff, /* dst_mask */
787 FALSE
); /* pcrel_offset */
789 static reloc_howto_type elf32_frv_rel_funcdesc_value_howto
=
790 HOWTO (R_FRV_FUNCDESC_VALUE
, /* type */
792 2, /* size (0 = byte, 1 = short, 2 = long) */
794 FALSE
, /* pc_relative */
796 complain_overflow_bitfield
, /* complain_on_overflow */
797 bfd_elf_generic_reloc
, /* special_function */
798 "R_FRV_FUNCDESC_VALUE", /* name */
799 TRUE
, /* partial_inplace */
800 0xffffffff, /* src_mask */
801 0xffffffff, /* dst_mask */
802 FALSE
); /* pcrel_offset */
804 static reloc_howto_type elf32_frv_rel_tlsdesc_value_howto
=
805 /* A 64-bit TLS descriptor for a symbol. The first word resolves to
806 an entry point, and the second resolves to a special argument.
807 If the symbol turns out to be in static TLS, the entry point is a
808 return instruction, and the special argument is the TLS offset
809 for the symbol. If it's in dynamic TLS, the entry point is a TLS
810 offset resolver, and the special argument is a pointer to a data
811 structure allocated by the dynamic loader, containing the GOT
812 address for the offset resolver, the module id, the offset within
813 the module, and anything else the TLS offset resolver might need
814 to determine the TLS offset for the symbol in the running
816 HOWTO (R_FRV_TLSDESC_VALUE
, /* type */
818 2, /* size (0 = byte, 1 = short, 2 = long) */
820 FALSE
, /* pc_relative */
822 complain_overflow_bitfield
, /* complain_on_overflow */
823 bfd_elf_generic_reloc
, /* special_function */
824 "R_FRV_TLSDESC_VALUE", /* name */
825 TRUE
, /* partial_inplace */
826 0xffffffff, /* src_mask */
827 0xffffffff, /* dst_mask */
828 FALSE
); /* pcrel_offset */
830 static reloc_howto_type elf32_frv_rel_tlsoff_howto
=
831 /* The 32-bit offset from the thread pointer (not the module base
832 address) to a thread-local symbol. */
833 HOWTO (R_FRV_TLSOFF
, /* type */
835 2, /* size (0 = byte, 1 = short, 2 = long) */
837 FALSE
, /* pc_relative */
839 complain_overflow_bitfield
, /* complain_on_overflow */
840 bfd_elf_generic_reloc
, /* special_function */
841 "R_FRV_TLSOFF", /* name */
842 TRUE
, /* partial_inplace */
843 0xffffffff, /* src_mask */
844 0xffffffff, /* dst_mask */
845 FALSE
); /* pcrel_offset */
849 extern const bfd_target bfd_elf32_frvfdpic_vec
;
850 #define IS_FDPIC(bfd) ((bfd)->xvec == &bfd_elf32_frvfdpic_vec)
852 /* An extension of the elf hash table data structure, containing some
853 additional FRV-specific data. */
854 struct frvfdpic_elf_link_hash_table
856 struct elf_link_hash_table elf
;
858 /* A pointer to the .got section. */
860 /* A pointer to the .rel.got section. */
862 /* A pointer to the .rofixup section. */
864 /* A pointer to the .plt section. */
866 /* A pointer to the .rel.plt section. */
868 /* GOT base offset. */
870 /* Location of the first non-lazy PLT entry, i.e., the number of
871 bytes taken by lazy PLT entries. If locally-bound TLS
872 descriptors require a ret instruction, it will be placed at this
875 /* A hash table holding information about which symbols were
876 referenced with which PIC-related relocations. */
877 struct htab
*relocs_info
;
878 /* Summary reloc information collected by
879 _frvfdpic_count_got_plt_entries. */
880 struct _frvfdpic_dynamic_got_info
*g
;
883 /* Get the FRV ELF linker hash table from a link_info structure. */
885 #define frvfdpic_hash_table(info) \
886 ((struct frvfdpic_elf_link_hash_table *) ((info)->hash))
888 #define frvfdpic_got_section(info) \
889 (frvfdpic_hash_table (info)->sgot)
890 #define frvfdpic_gotrel_section(info) \
891 (frvfdpic_hash_table (info)->sgotrel)
892 #define frvfdpic_gotfixup_section(info) \
893 (frvfdpic_hash_table (info)->sgotfixup)
894 #define frvfdpic_plt_section(info) \
895 (frvfdpic_hash_table (info)->splt)
896 #define frvfdpic_pltrel_section(info) \
897 (frvfdpic_hash_table (info)->spltrel)
898 #define frvfdpic_relocs_info(info) \
899 (frvfdpic_hash_table (info)->relocs_info)
900 #define frvfdpic_got_initial_offset(info) \
901 (frvfdpic_hash_table (info)->got0)
902 #define frvfdpic_plt_initial_offset(info) \
903 (frvfdpic_hash_table (info)->plt0)
904 #define frvfdpic_dynamic_got_plt_info(info) \
905 (frvfdpic_hash_table (info)->g)
907 /* Currently it's the same, but if some day we have a reason to change
908 it, we'd better be using a different macro.
910 FIXME: if there's any TLS PLT entry that uses local-exec or
911 initial-exec models, we could use the ret at the end of any of them
912 instead of adding one more. */
913 #define frvfdpic_plt_tls_ret_offset(info) \
914 (frvfdpic_plt_initial_offset (info))
916 /* The name of the dynamic interpreter. This is put in the .interp
919 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
921 #define DEFAULT_STACK_SIZE 0x20000
923 /* This structure is used to collect the number of entries present in
924 each addressable range of the got. */
925 struct _frvfdpic_dynamic_got_info
927 /* Several bits of information about the current link. */
928 struct bfd_link_info
*info
;
929 /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit
931 bfd_vma got12
, gotlos
, gothilo
;
932 /* Total GOT size needed for function descriptor entries within the 12-,
933 16- or 32-bit ranges. */
934 bfd_vma fd12
, fdlos
, fdhilo
;
935 /* Total GOT size needed by function descriptor entries referenced
936 in PLT entries, that would be profitable to place in offsets
937 close to the PIC register. */
939 /* Total PLT size needed by lazy PLT entries. */
941 /* Total GOT size needed for TLS descriptor entries within the 12-,
942 16- or 32-bit ranges. */
943 bfd_vma tlsd12
, tlsdlos
, tlsdhilo
;
944 /* Total GOT size needed by TLS descriptors referenced in PLT
945 entries, that would be profitable to place in offers close to the
948 /* Total PLT size needed by TLS lazy PLT entries. */
950 /* Number of relocations carried over from input object files. */
951 unsigned long relocs
;
952 /* Number of fixups introduced by relocations in input object files. */
953 unsigned long fixups
;
954 /* The number of fixups that reference the ret instruction added to
955 the PLT for locally-resolved TLS descriptors. */
956 unsigned long tls_ret_refs
;
959 /* This structure is used to assign offsets to got entries, function
960 descriptors, plt entries and lazy plt entries. */
962 struct _frvfdpic_dynamic_got_plt_info
964 /* Summary information collected with _frvfdpic_count_got_plt_entries. */
965 struct _frvfdpic_dynamic_got_info g
;
967 /* For each addressable range, we record a MAX (positive) and MIN
968 (negative) value. CUR is used to assign got entries, and it's
969 incremented from an initial positive value to MAX, then from MIN
970 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
971 assign function descriptors, and it's decreased from an initial
972 non-positive value to MIN, then from MAX down to CUR (unless CUR
973 wraps around first). All of MIN, MAX, CUR and FDCUR always point
974 to even words. ODD, if non-zero, indicates an odd word to be
975 used for the next got entry, otherwise CUR is used and
976 incremented by a pair of words, wrapping around when it reaches
977 MAX. FDCUR is decremented (and wrapped) before the next function
978 descriptor is chosen. FDPLT indicates the number of remaining
979 slots that can be used for function descriptors used only by PLT
982 TMAX, TMIN and TCUR are used to assign TLS descriptors. TCUR
983 starts as MAX, and grows up to TMAX, then wraps around to TMIN
984 and grows up to MIN. TLSDPLT indicates the number of remaining
985 slots that can be used for TLS descriptors used only by TLS PLT
987 struct _frvfdpic_dynamic_got_alloc_data
989 bfd_signed_vma max
, cur
, odd
, fdcur
, min
;
990 bfd_signed_vma tmax
, tcur
, tmin
;
991 bfd_vma fdplt
, tlsdplt
;
992 } got12
, gotlos
, gothilo
;
995 /* Create an FRV ELF linker hash table. */
997 static struct bfd_link_hash_table
*
998 frvfdpic_elf_link_hash_table_create (bfd
*abfd
)
1000 struct frvfdpic_elf_link_hash_table
*ret
;
1001 bfd_size_type amt
= sizeof (struct frvfdpic_elf_link_hash_table
);
1003 ret
= bfd_zalloc (abfd
, amt
);
1007 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1008 _bfd_elf_link_hash_newfunc
))
1014 return &ret
->elf
.root
;
1017 /* Decide whether a reference to a symbol can be resolved locally or
1018 not. If the symbol is protected, we want the local address, but
1019 its function descriptor must be assigned by the dynamic linker. */
1020 #define FRVFDPIC_SYM_LOCAL(INFO, H) \
1021 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
1022 || ! elf_hash_table (INFO)->dynamic_sections_created)
1023 #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \
1024 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
1026 /* This structure collects information on what kind of GOT, PLT or
1027 function descriptors are required by relocations that reference a
1029 struct frvfdpic_relocs_info
1031 /* The index of the symbol, as stored in the relocation r_info, if
1032 we have a local symbol; -1 otherwise. */
1036 /* The input bfd in which the symbol is defined, if it's a local
1039 /* If symndx == -1, the hash table entry corresponding to a global
1040 symbol (even if it turns out to bind locally, in which case it
1041 should ideally be replaced with section's symndx + addend). */
1042 struct elf_link_hash_entry
*h
;
1044 /* The addend of the relocation that references the symbol. */
1047 /* The fields above are used to identify an entry. The fields below
1048 contain information on how an entry is used and, later on, which
1049 locations it was assigned. */
1050 /* The following 3 fields record whether the symbol+addend above was
1051 ever referenced with a GOT relocation. The 12 suffix indicates a
1052 GOT12 relocation; los is used for GOTLO relocations that are not
1053 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
1058 /* Whether a FUNCDESC relocation references symbol+addend. */
1060 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
1062 unsigned fdgotlos
:1;
1063 unsigned fdgothilo
:1;
1064 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
1065 unsigned fdgoff12
:1;
1066 unsigned fdgofflos
:1;
1067 unsigned fdgoffhilo
:1;
1068 /* Whether a GETTLSOFF relocation references symbol+addend. */
1070 /* FIXME: we should probably add tlspltdesc, tlspltoff and
1071 tlspltimm, to tell what kind of TLS PLT entry we're generating.
1072 We might instead just pre-compute flags telling whether the
1073 object is suitable for local exec, initial exec or general
1074 dynamic addressing, and use that all over the place. We could
1075 also try to do a better job of merging TLSOFF and TLSDESC entries
1076 in main executables, but perhaps we can get rid of TLSDESC
1077 entirely in them instead. */
1078 /* Whether a GOTTLSDESC relocation references symbol+addend. */
1079 unsigned tlsdesc12
:1;
1080 unsigned tlsdesclos
:1;
1081 unsigned tlsdeschilo
:1;
1082 /* Whether a GOTTLSOFF relocation references symbol+addend. */
1083 unsigned tlsoff12
:1;
1084 unsigned tlsofflos
:1;
1085 unsigned tlsoffhilo
:1;
1086 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
1087 GOTOFFHI relocations. The addend doesn't really matter, since we
1088 envision that this will only be used to check whether the symbol
1089 is mapped to the same segment as the got. */
1091 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
1093 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
1096 /* Whether we need a PLT entry for a symbol. Should be implied by
1098 (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */
1100 /* Whether a function descriptor should be created in this link unit
1101 for symbol+addend. Should be implied by something like:
1102 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
1103 || ((fd || fdgot12 || fdgotlos || fdgothilo)
1104 && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */
1106 /* Whether a lazy PLT entry is needed for this symbol+addend.
1107 Should be implied by something like:
1108 (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)
1109 && ! (info->flags & DF_BIND_NOW)) */
1111 /* Whether we've already emitted GOT relocations and PLT entries as
1112 needed for this symbol. */
1115 /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and
1116 R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing
1118 unsigned relocs32
, relocsfd
, relocsfdv
, relocstlsd
, relocstlsoff
;
1120 /* The number of .rofixups entries and dynamic relocations allocated
1121 for this symbol, minus any that might have already been used. */
1122 unsigned fixups
, dynrelocs
;
1124 /* The offsets of the GOT entries assigned to symbol+addend, to the
1125 function descriptor's address, and to a function descriptor,
1126 respectively. Should be zero if unassigned. The offsets are
1127 counted from the value that will be assigned to the PIC register,
1128 not from the beginning of the .got section. */
1129 bfd_signed_vma got_entry
, fdgot_entry
, fd_entry
;
1130 /* The offsets of the PLT entries assigned to symbol+addend,
1131 non-lazy and lazy, respectively. If unassigned, should be
1133 bfd_vma plt_entry
, lzplt_entry
;
1134 /* The offsets of the GOT entries for TLS offset and TLS descriptor. */
1135 bfd_signed_vma tlsoff_entry
, tlsdesc_entry
;
1136 /* The offset of the TLS offset PLT entry. */
1137 bfd_vma tlsplt_entry
;
1140 /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */
1142 frvfdpic_relocs_info_hash (const void *entry_
)
1144 const struct frvfdpic_relocs_info
*entry
= entry_
;
1146 return (entry
->symndx
== -1
1147 ? (long) entry
->d
.h
->root
.root
.hash
1148 : entry
->symndx
+ (long) entry
->d
.abfd
->id
* 257) + entry
->addend
;
1151 /* Test whether the key fields of two frvfdpic_relocs_info entries are
1154 frvfdpic_relocs_info_eq (const void *entry1
, const void *entry2
)
1156 const struct frvfdpic_relocs_info
*e1
= entry1
;
1157 const struct frvfdpic_relocs_info
*e2
= entry2
;
1159 return e1
->symndx
== e2
->symndx
&& e1
->addend
== e2
->addend
1160 && (e1
->symndx
== -1 ? e1
->d
.h
== e2
->d
.h
: e1
->d
.abfd
== e2
->d
.abfd
);
1163 /* Find or create an entry in a hash table HT that matches the key
1164 fields of the given ENTRY. If it's not found, memory for a new
1165 entry is allocated in ABFD's obstack. */
1166 static struct frvfdpic_relocs_info
*
1167 frvfdpic_relocs_info_find (struct htab
*ht
,
1169 const struct frvfdpic_relocs_info
*entry
,
1170 enum insert_option insert
)
1172 struct frvfdpic_relocs_info
**loc
=
1173 (struct frvfdpic_relocs_info
**) htab_find_slot (ht
, entry
, insert
);
1181 *loc
= bfd_zalloc (abfd
, sizeof (**loc
));
1186 (*loc
)->symndx
= entry
->symndx
;
1187 (*loc
)->d
= entry
->d
;
1188 (*loc
)->addend
= entry
->addend
;
1189 (*loc
)->plt_entry
= (bfd_vma
)-1;
1190 (*loc
)->lzplt_entry
= (bfd_vma
)-1;
1191 (*loc
)->tlsplt_entry
= (bfd_vma
)-1;
1196 /* Obtain the address of the entry in HT associated with H's symbol +
1197 addend, creating a new entry if none existed. ABFD is only used
1198 for memory allocation purposes. */
1199 inline static struct frvfdpic_relocs_info
*
1200 frvfdpic_relocs_info_for_global (struct htab
*ht
,
1202 struct elf_link_hash_entry
*h
,
1204 enum insert_option insert
)
1206 struct frvfdpic_relocs_info entry
;
1210 entry
.addend
= addend
;
1212 return frvfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1215 /* Obtain the address of the entry in HT associated with the SYMNDXth
1216 local symbol of the input bfd ABFD, plus the addend, creating a new
1217 entry if none existed. */
1218 inline static struct frvfdpic_relocs_info
*
1219 frvfdpic_relocs_info_for_local (struct htab
*ht
,
1223 enum insert_option insert
)
1225 struct frvfdpic_relocs_info entry
;
1227 entry
.symndx
= symndx
;
1228 entry
.d
.abfd
= abfd
;
1229 entry
.addend
= addend
;
1231 return frvfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1234 /* Merge fields set by check_relocs() of two entries that end up being
1235 mapped to the same (presumably global) symbol. */
1238 frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info
*e2
,
1239 struct frvfdpic_relocs_info
const *e1
)
1241 e2
->got12
|= e1
->got12
;
1242 e2
->gotlos
|= e1
->gotlos
;
1243 e2
->gothilo
|= e1
->gothilo
;
1245 e2
->fdgot12
|= e1
->fdgot12
;
1246 e2
->fdgotlos
|= e1
->fdgotlos
;
1247 e2
->fdgothilo
|= e1
->fdgothilo
;
1248 e2
->fdgoff12
|= e1
->fdgoff12
;
1249 e2
->fdgofflos
|= e1
->fdgofflos
;
1250 e2
->fdgoffhilo
|= e1
->fdgoffhilo
;
1251 e2
->tlsplt
|= e1
->tlsplt
;
1252 e2
->tlsdesc12
|= e1
->tlsdesc12
;
1253 e2
->tlsdesclos
|= e1
->tlsdesclos
;
1254 e2
->tlsdeschilo
|= e1
->tlsdeschilo
;
1255 e2
->tlsoff12
|= e1
->tlsoff12
;
1256 e2
->tlsofflos
|= e1
->tlsofflos
;
1257 e2
->tlsoffhilo
|= e1
->tlsoffhilo
;
1258 e2
->gotoff
|= e1
->gotoff
;
1259 e2
->call
|= e1
->call
;
1263 /* Every block of 65535 lazy PLT entries shares a single call to the
1264 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
1265 32767, counting from 0). All other lazy PLT entries branch to it
1266 in a single instruction. */
1268 #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
1269 #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767)
1271 /* Add a dynamic relocation to the SRELOC section. */
1273 inline static bfd_vma
1274 _frvfdpic_add_dyn_reloc (bfd
*output_bfd
, asection
*sreloc
, bfd_vma offset
,
1275 int reloc_type
, long dynindx
, bfd_vma addend
,
1276 struct frvfdpic_relocs_info
*entry
)
1278 Elf_Internal_Rela outrel
;
1279 bfd_vma reloc_offset
;
1281 outrel
.r_offset
= offset
;
1282 outrel
.r_info
= ELF32_R_INFO (dynindx
, reloc_type
);
1283 outrel
.r_addend
= addend
;
1285 reloc_offset
= sreloc
->reloc_count
* sizeof (Elf32_External_Rel
);
1286 BFD_ASSERT (reloc_offset
< sreloc
->size
);
1287 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
1288 sreloc
->contents
+ reloc_offset
);
1289 sreloc
->reloc_count
++;
1291 /* If the entry's index is zero, this relocation was probably to a
1292 linkonce section that got discarded. We reserved a dynamic
1293 relocation, but it was for another entry than the one we got at
1294 the time of emitting the relocation. Unfortunately there's no
1295 simple way for us to catch this situation, since the relocation
1296 is cleared right before calling relocate_section, at which point
1297 we no longer know what the relocation used to point to. */
1300 BFD_ASSERT (entry
->dynrelocs
> 0);
1304 return reloc_offset
;
1307 /* Add a fixup to the ROFIXUP section. */
1310 _frvfdpic_add_rofixup (bfd
*output_bfd
, asection
*rofixup
, bfd_vma offset
,
1311 struct frvfdpic_relocs_info
*entry
)
1313 bfd_vma fixup_offset
;
1315 if (rofixup
->flags
& SEC_EXCLUDE
)
1318 fixup_offset
= rofixup
->reloc_count
* 4;
1319 if (rofixup
->contents
)
1321 BFD_ASSERT (fixup_offset
< rofixup
->size
);
1322 bfd_put_32 (output_bfd
, offset
, rofixup
->contents
+ fixup_offset
);
1324 rofixup
->reloc_count
++;
1326 if (entry
&& entry
->symndx
)
1328 /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc
1330 BFD_ASSERT (entry
->fixups
> 0);
1334 return fixup_offset
;
1337 /* Find the segment number in which OSEC, and output section, is
1341 _frvfdpic_osec_to_segment (bfd
*output_bfd
, asection
*osec
)
1343 struct elf_segment_map
*m
;
1344 Elf_Internal_Phdr
*p
;
1346 /* Find the segment that contains the output_section. */
1347 for (m
= elf_tdata (output_bfd
)->segment_map
,
1348 p
= elf_tdata (output_bfd
)->phdr
;
1354 for (i
= m
->count
- 1; i
>= 0; i
--)
1355 if (m
->sections
[i
] == osec
)
1362 return p
- elf_tdata (output_bfd
)->phdr
;
1365 inline static bfd_boolean
1366 _frvfdpic_osec_readonly_p (bfd
*output_bfd
, asection
*osec
)
1368 unsigned seg
= _frvfdpic_osec_to_segment (output_bfd
, osec
);
1370 return ! (elf_tdata (output_bfd
)->phdr
[seg
].p_flags
& PF_W
);
1373 #define FRVFDPIC_TLS_BIAS (2048 - 16)
1375 /* Return the base VMA address which should be subtracted from real addresses
1376 when resolving TLSMOFF relocation.
1377 This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */
1380 tls_biased_base (struct bfd_link_info
*info
)
1382 /* If tls_sec is NULL, we should have signalled an error already. */
1383 if (elf_hash_table (info
)->tls_sec
== NULL
)
1384 return FRVFDPIC_TLS_BIAS
;
1385 return elf_hash_table (info
)->tls_sec
->vma
+ FRVFDPIC_TLS_BIAS
;
1388 /* Generate relocations for GOT entries, function descriptors, and
1389 code for PLT and lazy PLT entries. */
1391 inline static bfd_boolean
1392 _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info
*entry
,
1394 struct bfd_link_info
*info
,
1396 Elf_Internal_Sym
*sym
,
1400 bfd_vma fd_lazy_rel_offset
= (bfd_vma
)-1;
1407 if (entry
->got_entry
|| entry
->fdgot_entry
|| entry
->fd_entry
1408 || entry
->tlsoff_entry
|| entry
->tlsdesc_entry
)
1410 /* If the symbol is dynamic, consider it for dynamic
1411 relocations, otherwise decay to section + offset. */
1412 if (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1)
1413 dynindx
= entry
->d
.h
->dynindx
;
1416 if (sec
->output_section
1417 && ! bfd_is_abs_section (sec
->output_section
)
1418 && ! bfd_is_und_section (sec
->output_section
))
1419 dynindx
= elf_section_data (sec
->output_section
)->dynindx
;
1425 /* Generate relocation for GOT entry pointing to the symbol. */
1426 if (entry
->got_entry
)
1429 bfd_vma ad
= addend
;
1431 /* If the symbol is dynamic but binds locally, use
1433 if (sec
&& (entry
->symndx
!= -1
1434 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1436 if (entry
->symndx
== -1)
1437 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1439 ad
+= sym
->st_value
;
1440 ad
+= sec
->output_offset
;
1441 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1442 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1447 /* If we're linking an executable at a fixed address, we can
1448 omit the dynamic relocation as long as the symbol is local to
1450 if (info
->executable
&& !info
->pie
1451 && (entry
->symndx
!= -1
1452 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1455 ad
+= sec
->output_section
->vma
;
1456 if (entry
->symndx
!= -1
1457 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1458 _frvfdpic_add_rofixup (output_bfd
,
1459 frvfdpic_gotfixup_section (info
),
1460 frvfdpic_got_section (info
)->output_section
1462 + frvfdpic_got_section (info
)->output_offset
1463 + frvfdpic_got_initial_offset (info
)
1464 + entry
->got_entry
, entry
);
1467 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1468 _bfd_elf_section_offset
1470 frvfdpic_got_section (info
),
1471 frvfdpic_got_initial_offset (info
)
1473 + frvfdpic_got_section (info
)
1474 ->output_section
->vma
1475 + frvfdpic_got_section (info
)->output_offset
,
1476 R_FRV_32
, idx
, ad
, entry
);
1478 bfd_put_32 (output_bfd
, ad
,
1479 frvfdpic_got_section (info
)->contents
1480 + frvfdpic_got_initial_offset (info
)
1481 + entry
->got_entry
);
1484 /* Generate relocation for GOT entry pointing to a canonical
1485 function descriptor. */
1486 if (entry
->fdgot_entry
)
1491 if (! (entry
->symndx
== -1
1492 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
1493 && FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1495 /* If the symbol is dynamic and there may be dynamic symbol
1496 resolution because we are, or are linked with, a shared
1497 library, emit a FUNCDESC relocation such that the dynamic
1498 linker will allocate the function descriptor. If the
1499 symbol needs a non-local function descriptor but binds
1500 locally (e.g., its visibility is protected, emit a
1501 dynamic relocation decayed to section+offset. */
1502 if (entry
->symndx
== -1
1503 && ! FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)
1504 && FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)
1505 && !(info
->executable
&& !info
->pie
))
1507 reloc
= R_FRV_FUNCDESC
;
1508 idx
= elf_section_data (entry
->d
.h
->root
.u
.def
.section
1509 ->output_section
)->dynindx
;
1510 ad
= entry
->d
.h
->root
.u
.def
.section
->output_offset
1511 + entry
->d
.h
->root
.u
.def
.value
;
1513 else if (entry
->symndx
== -1
1514 && ! FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
))
1516 reloc
= R_FRV_FUNCDESC
;
1521 (*info
->callbacks
->reloc_dangerous
)
1522 (info
, _("relocation requires zero addend"),
1523 elf_hash_table (info
)->dynobj
,
1524 frvfdpic_got_section (info
),
1525 entry
->fdgot_entry
);
1531 /* Otherwise, we know we have a private function descriptor,
1532 so reference it directly. */
1533 if (elf_hash_table (info
)->dynamic_sections_created
)
1534 BFD_ASSERT (entry
->privfd
);
1536 idx
= elf_section_data (frvfdpic_got_section (info
)
1537 ->output_section
)->dynindx
;
1538 ad
= frvfdpic_got_section (info
)->output_offset
1539 + frvfdpic_got_initial_offset (info
) + entry
->fd_entry
;
1542 /* If there is room for dynamic symbol resolution, emit the
1543 dynamic relocation. However, if we're linking an
1544 executable at a fixed location, we won't have emitted a
1545 dynamic symbol entry for the got section, so idx will be
1546 zero, which means we can and should compute the address
1547 of the private descriptor ourselves. */
1548 if (info
->executable
&& !info
->pie
1549 && (entry
->symndx
!= -1
1550 || FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)))
1552 ad
+= frvfdpic_got_section (info
)->output_section
->vma
;
1553 _frvfdpic_add_rofixup (output_bfd
,
1554 frvfdpic_gotfixup_section (info
),
1555 frvfdpic_got_section (info
)
1556 ->output_section
->vma
1557 + frvfdpic_got_section (info
)
1559 + frvfdpic_got_initial_offset (info
)
1560 + entry
->fdgot_entry
, entry
);
1563 _frvfdpic_add_dyn_reloc (output_bfd
,
1564 frvfdpic_gotrel_section (info
),
1565 _bfd_elf_section_offset
1567 frvfdpic_got_section (info
),
1568 frvfdpic_got_initial_offset (info
)
1569 + entry
->fdgot_entry
)
1570 + frvfdpic_got_section (info
)
1571 ->output_section
->vma
1572 + frvfdpic_got_section (info
)
1574 reloc
, idx
, ad
, entry
);
1577 bfd_put_32 (output_bfd
, ad
,
1578 frvfdpic_got_section (info
)->contents
1579 + frvfdpic_got_initial_offset (info
)
1580 + entry
->fdgot_entry
);
1583 /* Generate relocation to fill in a private function descriptor in
1585 if (entry
->fd_entry
)
1588 bfd_vma ad
= addend
;
1590 long lowword
, highword
;
1592 /* If the symbol is dynamic but binds locally, use
1594 if (sec
&& (entry
->symndx
!= -1
1595 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1597 if (entry
->symndx
== -1)
1598 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1600 ad
+= sym
->st_value
;
1601 ad
+= sec
->output_offset
;
1602 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1603 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1608 /* If we're linking an executable at a fixed address, we can
1609 omit the dynamic relocation as long as the symbol is local to
1611 if (info
->executable
&& !info
->pie
1612 && (entry
->symndx
!= -1 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1615 ad
+= sec
->output_section
->vma
;
1617 if (entry
->symndx
!= -1
1618 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1620 _frvfdpic_add_rofixup (output_bfd
,
1621 frvfdpic_gotfixup_section (info
),
1622 frvfdpic_got_section (info
)
1623 ->output_section
->vma
1624 + frvfdpic_got_section (info
)
1626 + frvfdpic_got_initial_offset (info
)
1627 + entry
->fd_entry
, entry
);
1628 _frvfdpic_add_rofixup (output_bfd
,
1629 frvfdpic_gotfixup_section (info
),
1630 frvfdpic_got_section (info
)
1631 ->output_section
->vma
1632 + frvfdpic_got_section (info
)
1634 + frvfdpic_got_initial_offset (info
)
1635 + entry
->fd_entry
+ 4, entry
);
1641 _frvfdpic_add_dyn_reloc (output_bfd
,
1643 ? frvfdpic_pltrel_section (info
)
1644 : frvfdpic_gotrel_section (info
),
1645 _bfd_elf_section_offset
1647 frvfdpic_got_section (info
),
1648 frvfdpic_got_initial_offset (info
)
1650 + frvfdpic_got_section (info
)
1651 ->output_section
->vma
1652 + frvfdpic_got_section (info
)
1654 R_FRV_FUNCDESC_VALUE
, idx
, ad
, entry
);
1657 /* If we've omitted the dynamic relocation, just emit the fixed
1658 addresses of the symbol and of the local GOT base offset. */
1659 if (info
->executable
&& !info
->pie
&& sec
&& sec
->output_section
)
1662 highword
= frvfdpic_got_section (info
)->output_section
->vma
1663 + frvfdpic_got_section (info
)->output_offset
1664 + frvfdpic_got_initial_offset (info
);
1666 else if (entry
->lazyplt
)
1670 (*info
->callbacks
->reloc_dangerous
)
1671 (info
, _("relocation requires zero addend"),
1672 elf_hash_table (info
)->dynobj
,
1673 frvfdpic_got_section (info
),
1678 fd_lazy_rel_offset
= ofst
;
1680 /* A function descriptor used for lazy or local resolving is
1681 initialized such that its high word contains the output
1682 section index in which the PLT entries are located, and
1683 the low word contains the address of the lazy PLT entry
1684 entry point, that must be within the memory region
1685 assigned to that section. */
1686 lowword
= entry
->lzplt_entry
+ 4
1687 + frvfdpic_plt_section (info
)->output_offset
1688 + frvfdpic_plt_section (info
)->output_section
->vma
;
1689 highword
= _frvfdpic_osec_to_segment
1690 (output_bfd
, frvfdpic_plt_section (info
)->output_section
);
1694 /* A function descriptor for a local function gets the index
1695 of the section. For a non-local function, it's
1698 if (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1
1699 && entry
->d
.h
->dynindx
== idx
)
1702 highword
= _frvfdpic_osec_to_segment
1703 (output_bfd
, sec
->output_section
);
1706 bfd_put_32 (output_bfd
, lowword
,
1707 frvfdpic_got_section (info
)->contents
1708 + frvfdpic_got_initial_offset (info
)
1710 bfd_put_32 (output_bfd
, highword
,
1711 frvfdpic_got_section (info
)->contents
1712 + frvfdpic_got_initial_offset (info
)
1713 + entry
->fd_entry
+ 4);
1716 /* Generate code for the PLT entry. */
1717 if (entry
->plt_entry
!= (bfd_vma
) -1)
1719 bfd_byte
*plt_code
= frvfdpic_plt_section (info
)->contents
1722 BFD_ASSERT (entry
->fd_entry
);
1724 /* Figure out what kind of PLT entry we need, depending on the
1725 location of the function descriptor within the GOT. */
1726 if (entry
->fd_entry
>= -(1 << (12 - 1))
1727 && entry
->fd_entry
< (1 << (12 - 1)))
1729 /* lddi @(gr15, fd_entry), gr14 */
1730 bfd_put_32 (output_bfd
,
1731 0x9cccf000 | (entry
->fd_entry
& ((1 << 12) - 1)),
1737 if (entry
->fd_entry
>= -(1 << (16 - 1))
1738 && entry
->fd_entry
< (1 << (16 - 1)))
1740 /* setlos lo(fd_entry), gr14 */
1741 bfd_put_32 (output_bfd
,
1743 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1749 /* sethi.p hi(fd_entry), gr14
1750 setlo lo(fd_entry), gr14 */
1751 bfd_put_32 (output_bfd
,
1753 | ((entry
->fd_entry
>> 16)
1754 & (((bfd_vma
)1 << 16) - 1)),
1757 bfd_put_32 (output_bfd
,
1759 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1763 /* ldd @(gr14,gr15),gr14 */
1764 bfd_put_32 (output_bfd
, 0x9c08e14f, plt_code
);
1767 /* jmpl @(gr14,gr0) */
1768 bfd_put_32 (output_bfd
, 0x8030e000, plt_code
);
1771 /* Generate code for the lazy PLT entry. */
1772 if (entry
->lzplt_entry
!= (bfd_vma
) -1)
1774 bfd_byte
*lzplt_code
= frvfdpic_plt_section (info
)->contents
1775 + entry
->lzplt_entry
;
1776 bfd_vma resolverStub_addr
;
1778 bfd_put_32 (output_bfd
, fd_lazy_rel_offset
, lzplt_code
);
1781 resolverStub_addr
= entry
->lzplt_entry
/ FRVFDPIC_LZPLT_BLOCK_SIZE
1782 * FRVFDPIC_LZPLT_BLOCK_SIZE
+ FRVFDPIC_LZPLT_RESOLV_LOC
;
1783 if (resolverStub_addr
>= frvfdpic_plt_initial_offset (info
))
1784 resolverStub_addr
= frvfdpic_plt_initial_offset (info
) - 12;
1786 if (entry
->lzplt_entry
== resolverStub_addr
)
1788 /* This is a lazy PLT entry that includes a resolver call. */
1789 /* ldd @(gr15,gr0), gr4
1791 bfd_put_32 (output_bfd
, 0x8808f140, lzplt_code
);
1792 bfd_put_32 (output_bfd
, 0x80304000, lzplt_code
+ 4);
1796 /* bra resolverStub */
1797 bfd_put_32 (output_bfd
,
1799 | (((resolverStub_addr
- entry
->lzplt_entry
)
1800 / 4) & (((bfd_vma
)1 << 16) - 1)),
1805 /* Generate relocation for GOT entry holding the TLS offset. */
1806 if (entry
->tlsoff_entry
)
1809 bfd_vma ad
= addend
;
1811 if (entry
->symndx
!= -1
1812 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
))
1814 /* If the symbol is dynamic but binds locally, use
1818 if (entry
->symndx
== -1)
1819 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1821 ad
+= sym
->st_value
;
1822 ad
+= sec
->output_offset
;
1823 if (sec
->output_section
1824 && elf_section_data (sec
->output_section
))
1825 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1831 /* *ABS*+addend is special for TLS relocations, use only the
1833 if (info
->executable
1835 && (bfd_is_abs_section (sec
)
1836 || bfd_is_und_section (sec
)))
1838 /* If we're linking an executable, we can entirely omit the
1839 dynamic relocation if the symbol is local to this module. */
1840 else if (info
->executable
1841 && (entry
->symndx
!= -1
1842 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1845 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1850 && (bfd_is_abs_section (sec
)
1851 || bfd_is_und_section (sec
)))
1853 if (! elf_hash_table (info
)->tls_sec
)
1855 (*info
->callbacks
->undefined_symbol
)
1856 (info
, "TLS section", elf_hash_table (info
)->dynobj
,
1857 frvfdpic_got_section (info
), entry
->tlsoff_entry
, TRUE
);
1860 idx
= elf_section_data (elf_hash_table (info
)->tls_sec
)->dynindx
;
1861 ad
+= FRVFDPIC_TLS_BIAS
;
1863 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1864 _bfd_elf_section_offset
1866 frvfdpic_got_section (info
),
1867 frvfdpic_got_initial_offset (info
)
1868 + entry
->tlsoff_entry
)
1869 + frvfdpic_got_section (info
)
1870 ->output_section
->vma
1871 + frvfdpic_got_section (info
)
1873 R_FRV_TLSOFF
, idx
, ad
, entry
);
1876 bfd_put_32 (output_bfd
, ad
,
1877 frvfdpic_got_section (info
)->contents
1878 + frvfdpic_got_initial_offset (info
)
1879 + entry
->tlsoff_entry
);
1882 if (entry
->tlsdesc_entry
)
1885 bfd_vma ad
= addend
;
1887 /* If the symbol is dynamic but binds locally, use
1889 if (sec
&& (entry
->symndx
!= -1
1890 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1892 if (entry
->symndx
== -1)
1893 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1895 ad
+= sym
->st_value
;
1896 ad
+= sec
->output_offset
;
1897 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1898 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1903 /* If we didn't set up a TLS offset entry, but we're linking an
1904 executable and the symbol binds locally, we can use the
1905 module offset in the TLS descriptor in relaxations. */
1906 if (info
->executable
&& ! entry
->tlsoff_entry
)
1907 entry
->tlsoff_entry
= entry
->tlsdesc_entry
+ 4;
1909 if (info
->executable
&& !info
->pie
1911 && (bfd_is_abs_section (sec
)
1912 || bfd_is_und_section (sec
)))
1913 || entry
->symndx
!= -1
1914 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1916 /* *ABS*+addend is special for TLS relocations, use only the
1917 addend for the TLS offset, and take the module id as
1920 && (bfd_is_abs_section (sec
)
1921 || bfd_is_und_section (sec
)))
1923 /* For other TLS symbols that bind locally, add the section
1924 TLS offset to the addend. */
1926 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1928 bfd_put_32 (output_bfd
,
1929 frvfdpic_plt_section (info
)->output_section
->vma
1930 + frvfdpic_plt_section (info
)->output_offset
1931 + frvfdpic_plt_tls_ret_offset (info
),
1932 frvfdpic_got_section (info
)->contents
1933 + frvfdpic_got_initial_offset (info
)
1934 + entry
->tlsdesc_entry
);
1936 _frvfdpic_add_rofixup (output_bfd
,
1937 frvfdpic_gotfixup_section (info
),
1938 frvfdpic_got_section (info
)
1939 ->output_section
->vma
1940 + frvfdpic_got_section (info
)
1942 + frvfdpic_got_initial_offset (info
)
1943 + entry
->tlsdesc_entry
, entry
);
1945 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
);
1947 /* We've used one of the reserved fixups, so discount it so
1948 that we can check at the end that we've used them
1950 frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
--;
1952 /* While at that, make sure the ret instruction makes to the
1953 right location in the PLT. We could do it only when we
1954 got to 0, but since the check at the end will only print
1955 a warning, make sure we have the ret in place in case the
1956 warning is missed. */
1957 bfd_put_32 (output_bfd
, 0xc03a4000,
1958 frvfdpic_plt_section (info
)->contents
1959 + frvfdpic_plt_tls_ret_offset (info
));
1964 && (bfd_is_abs_section (sec
)
1965 || bfd_is_und_section (sec
)))
1967 if (! elf_hash_table (info
)->tls_sec
)
1969 (*info
->callbacks
->undefined_symbol
)
1970 (info
, "TLS section", elf_hash_table (info
)->dynobj
,
1971 frvfdpic_got_section (info
), entry
->tlsdesc_entry
, TRUE
);
1974 idx
= elf_section_data (elf_hash_table (info
)->tls_sec
)->dynindx
;
1975 ad
+= FRVFDPIC_TLS_BIAS
;
1978 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1979 _bfd_elf_section_offset
1981 frvfdpic_got_section (info
),
1982 frvfdpic_got_initial_offset (info
)
1983 + entry
->tlsdesc_entry
)
1984 + frvfdpic_got_section (info
)
1985 ->output_section
->vma
1986 + frvfdpic_got_section (info
)
1988 R_FRV_TLSDESC_VALUE
, idx
, ad
, entry
);
1990 bfd_put_32 (output_bfd
, 0,
1991 frvfdpic_got_section (info
)->contents
1992 + frvfdpic_got_initial_offset (info
)
1993 + entry
->tlsdesc_entry
);
1996 bfd_put_32 (output_bfd
, ad
,
1997 frvfdpic_got_section (info
)->contents
1998 + frvfdpic_got_initial_offset (info
)
1999 + entry
->tlsdesc_entry
+ 4);
2002 /* Generate code for the get-TLS-offset PLT entry. */
2003 if (entry
->tlsplt_entry
!= (bfd_vma
) -1)
2005 bfd_byte
*plt_code
= frvfdpic_plt_section (info
)->contents
2006 + entry
->tlsplt_entry
;
2008 if (info
->executable
2009 && (entry
->symndx
!= -1
2010 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
2013 bfd_vma ad
= addend
;
2015 /* sec may be NULL when referencing an undefweak symbol
2016 while linking a static executable. */
2019 BFD_ASSERT (entry
->symndx
== -1
2020 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
);
2024 if (entry
->symndx
== -1)
2025 ad
+= entry
->d
.h
->root
.u
.def
.value
;
2027 ad
+= sym
->st_value
;
2028 ad
+= sec
->output_offset
;
2029 if (sec
->output_section
2030 && elf_section_data (sec
->output_section
))
2031 idx
= elf_section_data (sec
->output_section
)->dynindx
;
2036 /* *ABS*+addend is special for TLS relocations, use only the
2037 addend for the TLS offset, and take the module id as
2040 && (bfd_is_abs_section (sec
)
2041 || bfd_is_und_section (sec
)))
2043 /* For other TLS symbols that bind locally, add the section
2044 TLS offset to the addend. */
2046 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
2048 if ((bfd_signed_vma
)ad
>= -(1 << (16 - 1))
2049 && (bfd_signed_vma
)ad
< (1 << (16 - 1)))
2051 /* setlos lo(ad), gr9 */
2052 bfd_put_32 (output_bfd
,
2055 & (((bfd_vma
)1 << 16) - 1)),
2061 /* sethi.p hi(ad), gr9
2062 setlo lo(ad), gr9 */
2063 bfd_put_32 (output_bfd
,
2066 & (((bfd_vma
)1 << 16) - 1)),
2069 bfd_put_32 (output_bfd
,
2072 & (((bfd_vma
)1 << 16) - 1)),
2077 bfd_put_32 (output_bfd
, 0xc03a4000, plt_code
);
2079 else if (entry
->tlsoff_entry
)
2081 /* Figure out what kind of PLT entry we need, depending on the
2082 location of the TLS descriptor within the GOT. */
2083 if (entry
->tlsoff_entry
>= -(1 << (12 - 1))
2084 && entry
->tlsoff_entry
< (1 << (12 - 1)))
2086 /* ldi @(gr15, tlsoff_entry), gr9 */
2087 bfd_put_32 (output_bfd
,
2088 0x92c8f000 | (entry
->tlsoff_entry
2095 if (entry
->tlsoff_entry
>= -(1 << (16 - 1))
2096 && entry
->tlsoff_entry
< (1 << (16 - 1)))
2098 /* setlos lo(tlsoff_entry), gr8 */
2099 bfd_put_32 (output_bfd
,
2101 | (entry
->tlsoff_entry
2102 & (((bfd_vma
)1 << 16) - 1)),
2108 /* sethi.p hi(tlsoff_entry), gr8
2109 setlo lo(tlsoff_entry), gr8 */
2110 bfd_put_32 (output_bfd
,
2112 | ((entry
->tlsoff_entry
>> 16)
2113 & (((bfd_vma
)1 << 16) - 1)),
2116 bfd_put_32 (output_bfd
,
2118 | (entry
->tlsoff_entry
2119 & (((bfd_vma
)1 << 16) - 1)),
2123 /* ld @(gr15,gr8),gr9 */
2124 bfd_put_32 (output_bfd
, 0x9008f108, plt_code
);
2128 bfd_put_32 (output_bfd
, 0xc03a4000, plt_code
);
2132 BFD_ASSERT (entry
->tlsdesc_entry
);
2134 /* Figure out what kind of PLT entry we need, depending on the
2135 location of the TLS descriptor within the GOT. */
2136 if (entry
->tlsdesc_entry
>= -(1 << (12 - 1))
2137 && entry
->tlsdesc_entry
< (1 << (12 - 1)))
2139 /* lddi @(gr15, tlsdesc_entry), gr8 */
2140 bfd_put_32 (output_bfd
,
2141 0x90ccf000 | (entry
->tlsdesc_entry
2148 if (entry
->tlsdesc_entry
>= -(1 << (16 - 1))
2149 && entry
->tlsdesc_entry
< (1 << (16 - 1)))
2151 /* setlos lo(tlsdesc_entry), gr8 */
2152 bfd_put_32 (output_bfd
,
2154 | (entry
->tlsdesc_entry
2155 & (((bfd_vma
)1 << 16) - 1)),
2161 /* sethi.p hi(tlsdesc_entry), gr8
2162 setlo lo(tlsdesc_entry), gr8 */
2163 bfd_put_32 (output_bfd
,
2165 | ((entry
->tlsdesc_entry
>> 16)
2166 & (((bfd_vma
)1 << 16) - 1)),
2169 bfd_put_32 (output_bfd
,
2171 | (entry
->tlsdesc_entry
2172 & (((bfd_vma
)1 << 16) - 1)),
2176 /* ldd @(gr15,gr8),gr8 */
2177 bfd_put_32 (output_bfd
, 0x9008f148, plt_code
);
2180 /* jmpl @(gr8,gr0) */
2181 bfd_put_32 (output_bfd
, 0x80308000, plt_code
);
2188 /* Handle an FRV small data reloc. */
2190 static bfd_reloc_status_type
2191 elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, relocation
,
2193 struct bfd_link_info
*info
;
2195 asection
*input_section
;
2196 Elf_Internal_Rela
*relocation
;
2202 struct bfd_link_hash_entry
*h
;
2204 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2206 gp
= (h
->u
.def
.value
2207 + h
->u
.def
.section
->output_section
->vma
2208 + h
->u
.def
.section
->output_offset
);
2210 value
-= input_section
->output_section
->vma
;
2211 value
-= (gp
- input_section
->output_section
->vma
);
2213 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2215 value
+= relocation
->r_addend
;
2217 if ((long) value
> 0x7ff || (long) value
< -0x800)
2218 return bfd_reloc_overflow
;
2220 bfd_put_32 (input_bfd
,
2221 (insn
& 0xfffff000) | (value
& 0xfff),
2222 contents
+ relocation
->r_offset
);
2224 return bfd_reloc_ok
;
2227 /* Handle an FRV small data reloc. for the u12 field. */
2229 static bfd_reloc_status_type
2230 elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, relocation
,
2232 struct bfd_link_info
*info
;
2234 asection
*input_section
;
2235 Elf_Internal_Rela
*relocation
;
2241 struct bfd_link_hash_entry
*h
;
2244 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2246 gp
= (h
->u
.def
.value
2247 + h
->u
.def
.section
->output_section
->vma
2248 + h
->u
.def
.section
->output_offset
);
2250 value
-= input_section
->output_section
->vma
;
2251 value
-= (gp
- input_section
->output_section
->vma
);
2253 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2255 value
+= relocation
->r_addend
;
2257 if ((long) value
> 0x7ff || (long) value
< -0x800)
2258 return bfd_reloc_overflow
;
2260 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
2262 insn
= (insn
& ~mask
) | ((value
& 0xfc0) << 12) | (value
& 0x3f);
2264 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2266 return bfd_reloc_ok
;
2269 /* Handle an FRV ELF HI16 reloc. */
2271 static bfd_reloc_status_type
2272 elf32_frv_relocate_hi16 (input_bfd
, relhi
, contents
, value
)
2274 Elf_Internal_Rela
*relhi
;
2280 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
2282 value
+= relhi
->r_addend
;
2283 value
= ((value
>> 16) & 0xffff);
2285 insn
= (insn
& 0xffff0000) | value
;
2287 if ((long) value
> 0xffff || (long) value
< -0x10000)
2288 return bfd_reloc_overflow
;
2290 bfd_put_32 (input_bfd
, insn
, contents
+ relhi
->r_offset
);
2291 return bfd_reloc_ok
;
2294 static bfd_reloc_status_type
2295 elf32_frv_relocate_lo16 (input_bfd
, rello
, contents
, value
)
2297 Elf_Internal_Rela
*rello
;
2303 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2305 value
+= rello
->r_addend
;
2306 value
= value
& 0xffff;
2308 insn
= (insn
& 0xffff0000) | value
;
2310 if ((long) value
> 0xffff || (long) value
< -0x10000)
2311 return bfd_reloc_overflow
;
2313 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
2314 return bfd_reloc_ok
;
2317 /* Perform the relocation for the CALL label24 instruction. */
2319 static bfd_reloc_status_type
2320 elf32_frv_relocate_label24 (input_bfd
, input_section
, rello
, contents
, value
)
2322 asection
*input_section
;
2323 Elf_Internal_Rela
*rello
;
2331 /* The format for the call instruction is:
2333 0 000000 0001111 000000000000000000
2334 label6 opcode label18
2336 The branch calculation is: pc + (4*label24)
2337 where label24 is the concatenation of label6 and label18. */
2339 /* Grab the instruction. */
2340 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2342 value
-= input_section
->output_section
->vma
+ input_section
->output_offset
;
2343 value
-= rello
->r_offset
;
2344 value
+= rello
->r_addend
;
2348 label6
= value
& 0xfc0000;
2349 label6
= label6
<< 7;
2351 label18
= value
& 0x3ffff;
2353 insn
= insn
& 0x803c0000;
2354 insn
= insn
| label6
;
2355 insn
= insn
| label18
;
2357 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
2359 return bfd_reloc_ok
;
2362 static bfd_reloc_status_type
2363 elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, relocation
,
2365 struct bfd_link_info
*info
;
2367 asection
*input_section
;
2368 Elf_Internal_Rela
*relocation
;
2374 struct bfd_link_hash_entry
*h
;
2376 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2378 gp
= (h
->u
.def
.value
2379 + h
->u
.def
.section
->output_section
->vma
2380 + h
->u
.def
.section
->output_offset
);
2382 value
-= input_section
->output_section
->vma
;
2383 value
-= (gp
- input_section
->output_section
->vma
);
2384 value
+= relocation
->r_addend
;
2385 value
= ((value
>> 16) & 0xffff);
2387 if ((long) value
> 0xffff || (long) value
< -0x10000)
2388 return bfd_reloc_overflow
;
2390 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2391 insn
= (insn
& 0xffff0000) | value
;
2393 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2394 return bfd_reloc_ok
;
2397 static bfd_reloc_status_type
2398 elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, relocation
,
2400 struct bfd_link_info
*info
;
2402 asection
*input_section
;
2403 Elf_Internal_Rela
*relocation
;
2409 struct bfd_link_hash_entry
*h
;
2411 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2413 gp
= (h
->u
.def
.value
2414 + h
->u
.def
.section
->output_section
->vma
2415 + h
->u
.def
.section
->output_offset
);
2417 value
-= input_section
->output_section
->vma
;
2418 value
-= (gp
- input_section
->output_section
->vma
);
2419 value
+= relocation
->r_addend
;
2420 value
= value
& 0xffff;
2422 if ((long) value
> 0xffff || (long) value
< -0x10000)
2423 return bfd_reloc_overflow
;
2425 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2426 insn
= (insn
& 0xffff0000) | value
;
2428 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2430 return bfd_reloc_ok
;
2433 static reloc_howto_type
*
2434 frv_reloc_type_lookup (abfd
, code
)
2435 bfd
*abfd ATTRIBUTE_UNUSED
;
2436 bfd_reloc_code_real_type code
;
2443 case BFD_RELOC_NONE
:
2444 return &elf32_frv_howto_table
[ (int) R_FRV_NONE
];
2447 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2448 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2449 return &elf32_frv_rel_32_howto
;
2451 case BFD_RELOC_CTOR
:
2452 return &elf32_frv_howto_table
[ (int) R_FRV_32
];
2454 case BFD_RELOC_FRV_LABEL16
:
2455 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL16
];
2457 case BFD_RELOC_FRV_LABEL24
:
2458 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL24
];
2460 case BFD_RELOC_FRV_LO16
:
2461 return &elf32_frv_howto_table
[ (int) R_FRV_LO16
];
2463 case BFD_RELOC_FRV_HI16
:
2464 return &elf32_frv_howto_table
[ (int) R_FRV_HI16
];
2466 case BFD_RELOC_FRV_GPREL12
:
2467 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL12
];
2469 case BFD_RELOC_FRV_GPRELU12
:
2470 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELU12
];
2472 case BFD_RELOC_FRV_GPREL32
:
2473 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL32
];
2475 case BFD_RELOC_FRV_GPRELHI
:
2476 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELHI
];
2478 case BFD_RELOC_FRV_GPRELLO
:
2479 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELLO
];
2481 case BFD_RELOC_FRV_GOT12
:
2482 return &elf32_frv_howto_table
[ (int) R_FRV_GOT12
];
2484 case BFD_RELOC_FRV_GOTHI
:
2485 return &elf32_frv_howto_table
[ (int) R_FRV_GOTHI
];
2487 case BFD_RELOC_FRV_GOTLO
:
2488 return &elf32_frv_howto_table
[ (int) R_FRV_GOTLO
];
2490 case BFD_RELOC_FRV_FUNCDESC
:
2491 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2492 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2493 return &elf32_frv_rel_funcdesc_howto
;
2494 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC
];
2496 case BFD_RELOC_FRV_FUNCDESC_GOT12
:
2497 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOT12
];
2499 case BFD_RELOC_FRV_FUNCDESC_GOTHI
:
2500 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTHI
];
2502 case BFD_RELOC_FRV_FUNCDESC_GOTLO
:
2503 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTLO
];
2505 case BFD_RELOC_FRV_FUNCDESC_VALUE
:
2506 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2507 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2508 return &elf32_frv_rel_funcdesc_value_howto
;
2509 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_VALUE
];
2511 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12
:
2512 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFF12
];
2514 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI
:
2515 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFHI
];
2517 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO
:
2518 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFLO
];
2520 case BFD_RELOC_FRV_GOTOFF12
:
2521 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFF12
];
2523 case BFD_RELOC_FRV_GOTOFFHI
:
2524 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFHI
];
2526 case BFD_RELOC_FRV_GOTOFFLO
:
2527 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFLO
];
2529 case BFD_RELOC_FRV_GETTLSOFF
:
2530 return &elf32_frv_howto_table
[ (int) R_FRV_GETTLSOFF
];
2532 case BFD_RELOC_FRV_TLSDESC_VALUE
:
2533 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2534 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2535 return &elf32_frv_rel_tlsdesc_value_howto
;
2536 return &elf32_frv_howto_table
[ (int) R_FRV_TLSDESC_VALUE
];
2538 case BFD_RELOC_FRV_GOTTLSDESC12
:
2539 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESC12
];
2541 case BFD_RELOC_FRV_GOTTLSDESCHI
:
2542 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESCHI
];
2544 case BFD_RELOC_FRV_GOTTLSDESCLO
:
2545 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESCLO
];
2547 case BFD_RELOC_FRV_TLSMOFF12
:
2548 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFF12
];
2550 case BFD_RELOC_FRV_TLSMOFFHI
:
2551 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFFHI
];
2553 case BFD_RELOC_FRV_TLSMOFFLO
:
2554 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFFLO
];
2556 case BFD_RELOC_FRV_GOTTLSOFF12
:
2557 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFF12
];
2559 case BFD_RELOC_FRV_GOTTLSOFFHI
:
2560 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFFHI
];
2562 case BFD_RELOC_FRV_GOTTLSOFFLO
:
2563 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFFLO
];
2565 case BFD_RELOC_FRV_TLSOFF
:
2566 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2567 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2568 return &elf32_frv_rel_tlsoff_howto
;
2569 return &elf32_frv_howto_table
[ (int) R_FRV_TLSOFF
];
2571 case BFD_RELOC_FRV_TLSDESC_RELAX
:
2572 return &elf32_frv_howto_table
[ (int) R_FRV_TLSDESC_RELAX
];
2574 case BFD_RELOC_FRV_GETTLSOFF_RELAX
:
2575 return &elf32_frv_howto_table
[ (int) R_FRV_GETTLSOFF_RELAX
];
2577 case BFD_RELOC_FRV_TLSOFF_RELAX
:
2578 return &elf32_frv_howto_table
[ (int) R_FRV_TLSOFF_RELAX
];
2580 case BFD_RELOC_FRV_TLSMOFF
:
2581 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFF
];
2583 case BFD_RELOC_VTABLE_INHERIT
:
2584 return &elf32_frv_vtinherit_howto
;
2586 case BFD_RELOC_VTABLE_ENTRY
:
2587 return &elf32_frv_vtentry_howto
;
2593 /* Set the howto pointer for an FRV ELF reloc. */
2596 frv_info_to_howto_rela (abfd
, cache_ptr
, dst
)
2597 bfd
*abfd ATTRIBUTE_UNUSED
;
2599 Elf_Internal_Rela
*dst
;
2601 unsigned int r_type
;
2603 r_type
= ELF32_R_TYPE (dst
->r_info
);
2606 case R_FRV_GNU_VTINHERIT
:
2607 cache_ptr
->howto
= &elf32_frv_vtinherit_howto
;
2610 case R_FRV_GNU_VTENTRY
:
2611 cache_ptr
->howto
= &elf32_frv_vtentry_howto
;
2615 cache_ptr
->howto
= & elf32_frv_howto_table
[r_type
];
2620 /* Set the howto pointer for an FRV ELF REL reloc. */
2622 frvfdpic_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
2623 arelent
*cache_ptr
, Elf_Internal_Rela
*dst
)
2625 unsigned int r_type
;
2627 r_type
= ELF32_R_TYPE (dst
->r_info
);
2631 cache_ptr
->howto
= &elf32_frv_rel_32_howto
;
2634 case R_FRV_FUNCDESC
:
2635 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_howto
;
2638 case R_FRV_FUNCDESC_VALUE
:
2639 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_value_howto
;
2642 case R_FRV_TLSDESC_VALUE
:
2643 cache_ptr
->howto
= &elf32_frv_rel_tlsdesc_value_howto
;
2647 cache_ptr
->howto
= &elf32_frv_rel_tlsoff_howto
;
2651 cache_ptr
->howto
= NULL
;
2656 /* Perform a single relocation. By default we use the standard BFD
2657 routines, but a few relocs, we have to do them ourselves. */
2659 static bfd_reloc_status_type
2660 frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
, rel
,
2662 reloc_howto_type
*howto
;
2664 asection
*input_section
;
2666 Elf_Internal_Rela
*rel
;
2669 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2670 contents
, rel
->r_offset
, relocation
,
2675 /* Relocate an FRV ELF section.
2677 The RELOCATE_SECTION function is called by the new ELF backend linker
2678 to handle the relocations for a section.
2680 The relocs are always passed as Rela structures; if the section
2681 actually uses Rel structures, the r_addend field will always be
2684 This function is responsible for adjusting the section contents as
2685 necessary, and (if using Rela relocs and generating a relocatable
2686 output file) adjusting the reloc addend as necessary.
2688 This function does not have to worry about setting the reloc
2689 address or the reloc symbol index.
2691 LOCAL_SYMS is a pointer to the swapped in local symbols.
2693 LOCAL_SECTIONS is an array giving the section in the input file
2694 corresponding to the st_shndx field of each local symbol.
2696 The global hash table entry for the global symbols can be found
2697 via elf_sym_hashes (input_bfd).
2699 When generating relocatable output, this function must handle
2700 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2701 going to be the section symbol corresponding to the output
2702 section, which means that the addend must be adjusted
2706 elf32_frv_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2707 contents
, relocs
, local_syms
, local_sections
)
2708 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2709 struct bfd_link_info
*info
;
2711 asection
*input_section
;
2713 Elf_Internal_Rela
*relocs
;
2714 Elf_Internal_Sym
*local_syms
;
2715 asection
**local_sections
;
2717 Elf_Internal_Shdr
*symtab_hdr
;
2718 struct elf_link_hash_entry
**sym_hashes
;
2719 Elf_Internal_Rela
*rel
;
2720 Elf_Internal_Rela
*relend
;
2721 unsigned isec_segment
, got_segment
, plt_segment
, gprel_segment
, tls_segment
,
2723 int silence_segment_error
= !(info
->shared
|| info
->pie
);
2726 if (info
->relocatable
)
2729 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
2730 sym_hashes
= elf_sym_hashes (input_bfd
);
2731 relend
= relocs
+ input_section
->reloc_count
;
2733 isec_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2734 input_section
->output_section
);
2735 if (IS_FDPIC (output_bfd
) && frvfdpic_got_section (info
))
2736 got_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2737 frvfdpic_got_section (info
)
2741 if (IS_FDPIC (output_bfd
) && frvfdpic_gotfixup_section (info
))
2742 gprel_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2743 frvfdpic_gotfixup_section (info
)
2747 if (IS_FDPIC (output_bfd
) && frvfdpic_plt_section (info
))
2748 plt_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2749 frvfdpic_plt_section (info
)
2753 if (elf_hash_table (info
)->tls_sec
)
2754 tls_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2755 elf_hash_table (info
)->tls_sec
);
2759 for (rel
= relocs
; rel
< relend
; rel
++)
2761 reloc_howto_type
*howto
;
2762 unsigned long r_symndx
;
2763 Elf_Internal_Sym
*sym
;
2765 struct elf_link_hash_entry
*h
;
2767 bfd_reloc_status_type r
;
2768 const char * name
= NULL
;
2771 struct frvfdpic_relocs_info
*picrel
;
2772 bfd_vma orig_addend
= rel
->r_addend
;
2774 r_type
= ELF32_R_TYPE (rel
->r_info
);
2776 if ( r_type
== R_FRV_GNU_VTINHERIT
2777 || r_type
== R_FRV_GNU_VTENTRY
)
2780 /* This is a final link. */
2781 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2782 howto
= elf32_frv_howto_table
+ ELF32_R_TYPE (rel
->r_info
);
2787 if (r_symndx
< symtab_hdr
->sh_info
)
2789 sym
= local_syms
+ r_symndx
;
2790 osec
= sec
= local_sections
[r_symndx
];
2791 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2793 name
= bfd_elf_string_from_elf_section
2794 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
2795 name
= (name
== NULL
) ? bfd_section_name (input_bfd
, sec
) : name
;
2799 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2801 while (h
->root
.type
== bfd_link_hash_indirect
2802 || h
->root
.type
== bfd_link_hash_warning
)
2803 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2805 name
= h
->root
.root
.string
;
2807 if ((h
->root
.type
== bfd_link_hash_defined
2808 || h
->root
.type
== bfd_link_hash_defweak
))
2810 if (/* TLSMOFF forces local binding. */
2811 r_type
!= R_FRV_TLSMOFF
2812 && ! FRVFDPIC_SYM_LOCAL (info
, h
))
2819 sec
= h
->root
.u
.def
.section
;
2820 relocation
= (h
->root
.u
.def
.value
2821 + sec
->output_section
->vma
2822 + sec
->output_offset
);
2825 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2829 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
2830 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
2834 if (! ((*info
->callbacks
->undefined_symbol
)
2835 (info
, h
->root
.root
.string
, input_bfd
,
2836 input_section
, rel
->r_offset
,
2837 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
2838 || ELF_ST_VISIBILITY (h
->other
)))))
2849 if (! IS_FDPIC (output_bfd
))
2855 case R_FRV_FUNCDESC_GOT12
:
2856 case R_FRV_FUNCDESC_GOTHI
:
2857 case R_FRV_FUNCDESC_GOTLO
:
2858 case R_FRV_GOTOFF12
:
2859 case R_FRV_GOTOFFHI
:
2860 case R_FRV_GOTOFFLO
:
2861 case R_FRV_FUNCDESC_GOTOFF12
:
2862 case R_FRV_FUNCDESC_GOTOFFHI
:
2863 case R_FRV_FUNCDESC_GOTOFFLO
:
2864 case R_FRV_FUNCDESC
:
2865 case R_FRV_FUNCDESC_VALUE
:
2866 case R_FRV_GETTLSOFF
:
2867 case R_FRV_TLSDESC_VALUE
:
2868 case R_FRV_GOTTLSDESC12
:
2869 case R_FRV_GOTTLSDESCHI
:
2870 case R_FRV_GOTTLSDESCLO
:
2871 case R_FRV_TLSMOFF12
:
2872 case R_FRV_TLSMOFFHI
:
2873 case R_FRV_TLSMOFFLO
:
2874 case R_FRV_GOTTLSOFF12
:
2875 case R_FRV_GOTTLSOFFHI
:
2876 case R_FRV_GOTTLSOFFLO
:
2878 case R_FRV_TLSDESC_RELAX
:
2879 case R_FRV_GETTLSOFF_RELAX
:
2880 case R_FRV_TLSOFF_RELAX
:
2883 picrel
= frvfdpic_relocs_info_for_global (frvfdpic_relocs_info
2884 (info
), input_bfd
, h
,
2885 orig_addend
, INSERT
);
2887 /* In order to find the entry we created before, we must
2888 use the original addend, not the one that may have been
2889 modified by _bfd_elf_rela_local_sym(). */
2890 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
2891 (info
), input_bfd
, r_symndx
,
2892 orig_addend
, INSERT
);
2896 if (!_frvfdpic_emit_got_relocs_plt_entries (picrel
, output_bfd
, info
,
2900 (*_bfd_error_handler
)
2901 (_("%B(%A+0x%x): relocation to `%s+%x' may have caused the error above"),
2902 input_bfd
, input_section
, rel
->r_offset
, name
, rel
->r_addend
);
2911 if (h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
))
2913 info
->callbacks
->warning
2914 (info
, _("relocation references symbol not defined in the module"),
2915 name
, input_bfd
, input_section
, rel
->r_offset
);
2923 case R_FRV_GETTLSOFF
:
2924 case R_FRV_TLSDESC_VALUE
:
2925 case R_FRV_GOTTLSDESC12
:
2926 case R_FRV_GOTTLSDESCHI
:
2927 case R_FRV_GOTTLSDESCLO
:
2928 case R_FRV_TLSMOFF12
:
2929 case R_FRV_TLSMOFFHI
:
2930 case R_FRV_TLSMOFFLO
:
2931 case R_FRV_GOTTLSOFF12
:
2932 case R_FRV_GOTTLSOFFHI
:
2933 case R_FRV_GOTTLSOFFLO
:
2935 case R_FRV_TLSDESC_RELAX
:
2936 case R_FRV_GETTLSOFF_RELAX
:
2937 case R_FRV_TLSOFF_RELAX
:
2939 if (sec
&& (bfd_is_abs_section (sec
) || bfd_is_und_section (sec
)))
2940 relocation
+= tls_biased_base (info
);
2947 /* Try to apply TLS relaxations. */
2952 #define LOCAL_EXEC_P(info, picrel) \
2953 ((info)->executable \
2954 && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h)))
2955 #define INITIAL_EXEC_P(info, picrel) \
2956 (((info)->executable || (info)->flags & DF_STATIC_TLS) \
2957 && (picrel)->tlsoff_entry)
2959 #define IN_RANGE_FOR_OFST12_P(value) \
2960 ((bfd_vma)((value) + 2048) < (bfd_vma)4096)
2961 #define IN_RANGE_FOR_SETLOS_P(value) \
2962 ((bfd_vma)((value) + 32768) < (bfd_vma)65536)
2963 #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \
2964 (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info)))
2966 #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2967 (LOCAL_EXEC_P ((info), (picrel)) \
2968 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2969 #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \
2970 (INITIAL_EXEC_P ((info), (picrel)) \
2971 && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry))
2973 #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \
2974 (LOCAL_EXEC_P ((info), (picrel)))
2975 #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \
2976 (INITIAL_EXEC_P ((info), (picrel)))
2978 #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2979 (LOCAL_EXEC_P ((info), (picrel)) \
2980 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2982 case R_FRV_GETTLSOFF
:
2983 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2985 /* Is this a call instruction? */
2986 if ((insn
& (unsigned long)0x01fc0000) != 0x003c0000)
2988 r
= info
->callbacks
->warning
2990 _("R_FRV_GETTLSOFF not applied to a call instruction"),
2991 name
, input_bfd
, input_section
, rel
->r_offset
);
2995 if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info
, picrel
,
2996 relocation
+ rel
->r_addend
))
2998 /* Replace the call instruction (except the packing bit)
2999 with setlos #tlsmofflo(symbol+offset), gr9. */
3000 insn
&= (unsigned long)0x80000000;
3001 insn
|= (unsigned long)0x12fc0000;
3002 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3004 r_type
= R_FRV_TLSMOFFLO
;
3005 howto
= elf32_frv_howto_table
+ r_type
;
3006 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3009 else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info
, picrel
))
3011 /* Replace the call instruction (except the packing bit)
3012 with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */
3013 insn
&= (unsigned long)0x80000000;
3014 insn
|= (unsigned long)0x12c8f000;
3015 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3017 r_type
= R_FRV_GOTTLSOFF12
;
3018 howto
= elf32_frv_howto_table
+ r_type
;
3019 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3024 case R_FRV_GOTTLSDESC12
:
3025 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3027 /* Is this an lddi instruction? */
3028 if ((insn
& (unsigned long)0x01fc0000) != 0x00cc0000)
3030 r
= info
->callbacks
->warning
3032 _("R_FRV_GOTTLSDESC12 not applied to an lddi instruction"),
3033 name
, input_bfd
, input_section
, rel
->r_offset
);
3037 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3038 relocation
+ rel
->r_addend
)
3039 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3042 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3043 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3044 Preserve the packing bit. */
3045 insn
= (insn
& (unsigned long)0x80000000)
3046 | ((insn
+ (unsigned long)0x02000000)
3047 & (unsigned long)0x7e000000);
3048 insn
|= (unsigned long)0x00fc0000;
3049 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3051 r_type
= R_FRV_TLSMOFFLO
;
3052 howto
= elf32_frv_howto_table
+ r_type
;
3053 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3056 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3057 relocation
+ rel
->r_addend
))
3059 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3060 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3061 Preserve the packing bit. */
3062 insn
= (insn
& (unsigned long)0x80000000)
3063 | ((insn
+ (unsigned long)0x02000000)
3064 & (unsigned long)0x7e000000);
3065 insn
|= (unsigned long)0x00f80000;
3066 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3068 r_type
= R_FRV_TLSMOFFHI
;
3069 howto
= elf32_frv_howto_table
+ r_type
;
3070 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3073 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3075 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3076 with ldi @(grB, #gottlsoff12(symbol+offset),
3077 gr<C+1>. Preserve the packing bit. If gottlsoff12
3078 overflows, we'll error out, but that's sort-of ok,
3079 since we'd started with gottlsdesc12, that's actually
3080 more demanding. Compiling with -fPIE instead of
3081 -fpie would fix it; linking with --relax should fix
3083 insn
= (insn
& (unsigned long)0x80cbf000)
3084 | ((insn
+ (unsigned long)0x02000000)
3085 & (unsigned long)0x7e000000);
3086 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3088 r_type
= R_FRV_GOTTLSOFF12
;
3089 howto
= elf32_frv_howto_table
+ r_type
;
3090 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3095 case R_FRV_GOTTLSDESCHI
:
3096 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3098 /* Is this a sethi instruction? */
3099 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3101 r
= info
->callbacks
->warning
3103 _("R_FRV_GOTTLSDESCHI not applied to a sethi instruction"),
3104 name
, input_bfd
, input_section
, rel
->r_offset
);
3108 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3109 relocation
+ rel
->r_addend
)
3110 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3111 && IN_RANGE_FOR_SETLOS_P (picrel
->tlsoff_entry
)))
3113 /* Replace sethi with a nop. Preserve the packing bit. */
3114 insn
&= (unsigned long)0x80000000;
3115 insn
|= (unsigned long)0x00880000;
3116 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3118 /* Nothing to relocate. */
3122 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3124 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3125 r_type
= R_FRV_GOTTLSOFFHI
;
3126 howto
= elf32_frv_howto_table
+ r_type
;
3127 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3132 case R_FRV_GOTTLSDESCLO
:
3133 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3135 /* Is this a setlo or setlos instruction? */
3136 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3138 r
= info
->callbacks
->warning
3140 _("R_FRV_GOTTLSDESCLO"
3141 " not applied to a setlo or setlos instruction"),
3142 name
, input_bfd
, input_section
, rel
->r_offset
);
3146 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3147 relocation
+ rel
->r_addend
)
3148 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3149 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3151 /* Replace setlo/setlos with a nop. Preserve the
3153 insn
&= (unsigned long)0x80000000;
3154 insn
|= (unsigned long)0x00880000;
3155 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3157 /* Nothing to relocate. */
3161 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3163 /* If the corresponding sethi (if it exists) decayed
3164 to a nop, make sure this becomes (or already is) a
3165 setlos, not setlo. */
3166 if (IN_RANGE_FOR_SETLOS_P (picrel
->tlsoff_entry
))
3168 insn
|= (unsigned long)0x00080000;
3169 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3172 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3173 r_type
= R_FRV_GOTTLSOFFLO
;
3174 howto
= elf32_frv_howto_table
+ r_type
;
3175 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3180 case R_FRV_TLSDESC_RELAX
:
3181 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3183 /* Is this an ldd instruction? */
3184 if ((insn
& (unsigned long)0x01fc0fc0) != 0x00080140)
3186 r
= info
->callbacks
->warning
3188 _("R_FRV_TLSDESC_RELAX not applied to an ldd instruction"),
3189 name
, input_bfd
, input_section
, rel
->r_offset
);
3193 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3194 relocation
+ rel
->r_addend
)
3195 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3198 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3199 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3200 Preserve the packing bit. */
3201 insn
= (insn
& (unsigned long)0x80000000)
3202 | ((insn
+ (unsigned long)0x02000000)
3203 & (unsigned long)0x7e000000);
3204 insn
|= (unsigned long)0x00fc0000;
3205 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3207 r_type
= R_FRV_TLSMOFFLO
;
3208 howto
= elf32_frv_howto_table
+ r_type
;
3209 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3212 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3213 relocation
+ rel
->r_addend
))
3215 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3216 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3217 Preserve the packing bit. */
3218 insn
= (insn
& (unsigned long)0x80000000)
3219 | ((insn
+ (unsigned long)0x02000000)
3220 & (unsigned long)0x7e000000);
3221 insn
|= (unsigned long)0x00f80000;
3222 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3224 r_type
= R_FRV_TLSMOFFHI
;
3225 howto
= elf32_frv_howto_table
+ r_type
;
3226 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3229 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3230 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
))
3232 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3233 with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>.
3234 Preserve the packing bit. */
3235 insn
= (insn
& (unsigned long)0x8003f000)
3236 | (unsigned long)0x00c80000
3237 | ((insn
+ (unsigned long)0x02000000)
3238 & (unsigned long)0x7e000000);
3239 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3241 r_type
= R_FRV_GOTTLSOFF12
;
3242 howto
= elf32_frv_howto_table
+ r_type
;
3243 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3246 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3248 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3249 with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>.
3250 Preserve the packing bit. */
3251 insn
= (insn
& (unsigned long)0x81ffffbf)
3252 | ((insn
+ (unsigned long)0x02000000)
3253 & (unsigned long)0x7e000000);
3254 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3256 /* #tlsoff(symbol+offset) is just a relaxation
3257 annotation, so there's nothing left to
3264 case R_FRV_GETTLSOFF_RELAX
:
3265 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3267 /* Is this a calll or callil instruction? */
3268 if ((insn
& (unsigned long)0x7ff80fc0) != 0x02300000)
3270 r
= info
->callbacks
->warning
3272 _("R_FRV_GETTLSOFF_RELAX"
3273 " not applied to a calll instruction"),
3274 name
, input_bfd
, input_section
, rel
->r_offset
);
3278 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3279 relocation
+ rel
->r_addend
)
3280 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3283 /* Replace calll with a nop. Preserve the packing bit. */
3284 insn
&= (unsigned long)0x80000000;
3285 insn
|= (unsigned long)0x00880000;
3286 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3288 /* Nothing to relocate. */
3292 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3293 relocation
+ rel
->r_addend
))
3295 /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9.
3296 Preserve the packing bit. */
3297 insn
&= (unsigned long)0x80000000;
3298 insn
|= (unsigned long)0x12f40000;
3299 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3301 r_type
= R_FRV_TLSMOFFLO
;
3302 howto
= elf32_frv_howto_table
+ r_type
;
3303 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3306 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3308 /* Replace calll with a nop. Preserve the packing bit. */
3309 insn
&= (unsigned long)0x80000000;
3310 insn
|= (unsigned long)0x00880000;
3311 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3313 /* Nothing to relocate. */
3319 case R_FRV_GOTTLSOFF12
:
3320 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3322 /* Is this an ldi instruction? */
3323 if ((insn
& (unsigned long)0x01fc0000) != 0x00c80000)
3325 r
= info
->callbacks
->warning
3327 _("R_FRV_GOTTLSOFF12 not applied to an ldi instruction"),
3328 name
, input_bfd
, input_section
, rel
->r_offset
);
3332 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3333 relocation
+ rel
->r_addend
))
3335 /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC
3336 with setlos #tlsmofflo(symbol+offset), grC.
3337 Preserve the packing bit. */
3338 insn
&= (unsigned long)0xfe000000;
3339 insn
|= (unsigned long)0x00fc0000;
3340 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3342 r_type
= R_FRV_TLSMOFFLO
;
3343 howto
= elf32_frv_howto_table
+ r_type
;
3344 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3349 case R_FRV_GOTTLSOFFHI
:
3350 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3352 /* Is this a sethi instruction? */
3353 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3355 r
= info
->callbacks
->warning
3357 _("R_FRV_GOTTLSOFFHI not applied to a sethi instruction"),
3358 name
, input_bfd
, input_section
, rel
->r_offset
);
3362 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3363 relocation
+ rel
->r_addend
)
3364 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3365 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3367 /* Replace sethi with a nop. Preserve the packing bit. */
3368 insn
&= (unsigned long)0x80000000;
3369 insn
|= (unsigned long)0x00880000;
3370 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3372 /* Nothing to relocate. */
3378 case R_FRV_GOTTLSOFFLO
:
3379 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3381 /* Is this a setlo or setlos instruction? */
3382 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3384 r
= info
->callbacks
->warning
3386 _("R_FRV_GOTTLSOFFLO"
3387 " not applied to a setlo or setlos instruction"),
3388 name
, input_bfd
, input_section
, rel
->r_offset
);
3392 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3393 relocation
+ rel
->r_addend
)
3394 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3395 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3397 /* Replace setlo/setlos with a nop. Preserve the
3399 insn
&= (unsigned long)0x80000000;
3400 insn
|= (unsigned long)0x00880000;
3401 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3403 /* Nothing to relocate. */
3409 case R_FRV_TLSOFF_RELAX
:
3410 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3412 /* Is this an ld instruction? */
3413 if ((insn
& (unsigned long)0x01fc0fc0) != 0x00080100)
3415 r
= info
->callbacks
->warning
3417 _("R_FRV_TLSOFF_RELAX not applied to an ld instruction"),
3418 name
, input_bfd
, input_section
, rel
->r_offset
);
3422 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3423 relocation
+ rel
->r_addend
))
3425 /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC
3426 with setlos #tlsmofflo(symbol+offset), grC.
3427 Preserve the packing bit. */
3428 insn
&= (unsigned long)0xfe000000;
3429 insn
|= (unsigned long)0x00fc0000;
3430 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3432 r_type
= R_FRV_TLSMOFFLO
;
3433 howto
= elf32_frv_howto_table
+ r_type
;
3434 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3437 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3438 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
))
3440 /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC
3441 with ldi @(grB, #gottlsoff12(symbol+offset), grC.
3442 Preserve the packing bit. */
3443 insn
= (insn
& (unsigned long)0xfe03f000)
3444 | (unsigned long)0x00c80000;;
3445 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3447 r_type
= R_FRV_GOTTLSOFF12
;
3448 howto
= elf32_frv_howto_table
+ r_type
;
3449 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3454 case R_FRV_TLSMOFFHI
:
3455 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3457 /* Is this a sethi instruction? */
3458 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3460 r
= info
->callbacks
->warning
3462 _("R_FRV_TLSMOFFHI not applied to a sethi instruction"),
3463 name
, input_bfd
, input_section
, rel
->r_offset
);
3467 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3470 /* Replace sethi with a nop. Preserve the packing bit. */
3471 insn
&= (unsigned long)0x80000000;
3472 insn
|= (unsigned long)0x00880000;
3473 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3475 /* Nothing to relocate. */
3481 case R_FRV_TLSMOFFLO
:
3482 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3484 /* Is this a setlo or setlos instruction? */
3485 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3487 r
= info
->callbacks
->warning
3490 " not applied to a setlo or setlos instruction"),
3491 name
, input_bfd
, input_section
, rel
->r_offset
);
3495 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3497 /* If the corresponding sethi (if it exists) decayed
3498 to a nop, make sure this becomes (or already is) a
3499 setlos, not setlo. */
3501 insn
|= (unsigned long)0x00080000;
3502 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3508 There's nothing to relax in these:
3524 check_segment
[0] = isec_segment
;
3525 if (! IS_FDPIC (output_bfd
))
3526 check_segment
[1] = isec_segment
;
3527 else if (picrel
->plt
)
3529 relocation
= frvfdpic_plt_section (info
)->output_section
->vma
3530 + frvfdpic_plt_section (info
)->output_offset
3531 + picrel
->plt_entry
;
3532 check_segment
[1] = plt_segment
;
3534 /* We don't want to warn on calls to undefined weak symbols,
3535 as calls to them must be protected by non-NULL tests
3536 anyway, and unprotected calls would invoke undefined
3538 else if (picrel
->symndx
== -1
3539 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefweak
)
3540 check_segment
[1] = check_segment
[0];
3542 check_segment
[1] = sec
3543 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3550 relocation
= picrel
->got_entry
;
3551 check_segment
[0] = check_segment
[1] = got_segment
;
3554 case R_FRV_FUNCDESC_GOT12
:
3555 case R_FRV_FUNCDESC_GOTHI
:
3556 case R_FRV_FUNCDESC_GOTLO
:
3557 relocation
= picrel
->fdgot_entry
;
3558 check_segment
[0] = check_segment
[1] = got_segment
;
3561 case R_FRV_GOTOFFHI
:
3562 case R_FRV_GOTOFF12
:
3563 case R_FRV_GOTOFFLO
:
3564 relocation
-= frvfdpic_got_section (info
)->output_section
->vma
3565 + frvfdpic_got_section (info
)->output_offset
3566 + frvfdpic_got_initial_offset (info
);
3567 check_segment
[0] = got_segment
;
3568 check_segment
[1] = sec
3569 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3573 case R_FRV_FUNCDESC_GOTOFF12
:
3574 case R_FRV_FUNCDESC_GOTOFFHI
:
3575 case R_FRV_FUNCDESC_GOTOFFLO
:
3576 relocation
= picrel
->fd_entry
;
3577 check_segment
[0] = check_segment
[1] = got_segment
;
3580 case R_FRV_FUNCDESC
:
3583 bfd_vma addend
= rel
->r_addend
;
3585 if (! (h
&& h
->root
.type
== bfd_link_hash_undefweak
3586 && FRVFDPIC_SYM_LOCAL (info
, h
)))
3588 /* If the symbol is dynamic and there may be dynamic
3589 symbol resolution because we are or are linked with a
3590 shared library, emit a FUNCDESC relocation such that
3591 the dynamic linker will allocate the function
3592 descriptor. If the symbol needs a non-local function
3593 descriptor but binds locally (e.g., its visibility is
3594 protected, emit a dynamic relocation decayed to
3596 if (h
&& ! FRVFDPIC_FUNCDESC_LOCAL (info
, h
)
3597 && FRVFDPIC_SYM_LOCAL (info
, h
)
3598 && !(info
->executable
&& !info
->pie
))
3600 dynindx
= elf_section_data (h
->root
.u
.def
.section
3601 ->output_section
)->dynindx
;
3602 addend
+= h
->root
.u
.def
.section
->output_offset
3603 + h
->root
.u
.def
.value
;
3605 else if (h
&& ! FRVFDPIC_FUNCDESC_LOCAL (info
, h
))
3609 info
->callbacks
->warning
3610 (info
, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"),
3611 name
, input_bfd
, input_section
, rel
->r_offset
);
3614 dynindx
= h
->dynindx
;
3618 /* Otherwise, we know we have a private function
3619 descriptor, so reference it directly. */
3620 BFD_ASSERT (picrel
->privfd
);
3622 dynindx
= elf_section_data (frvfdpic_got_section (info
)
3623 ->output_section
)->dynindx
;
3624 addend
= frvfdpic_got_section (info
)->output_offset
3625 + frvfdpic_got_initial_offset (info
)
3629 /* If there is room for dynamic symbol resolution, emit
3630 the dynamic relocation. However, if we're linking an
3631 executable at a fixed location, we won't have emitted a
3632 dynamic symbol entry for the got section, so idx will
3633 be zero, which means we can and should compute the
3634 address of the private descriptor ourselves. */
3635 if (info
->executable
&& !info
->pie
3636 && (!h
|| FRVFDPIC_FUNCDESC_LOCAL (info
, h
)))
3638 addend
+= frvfdpic_got_section (info
)->output_section
->vma
;
3639 if ((bfd_get_section_flags (output_bfd
,
3640 input_section
->output_section
)
3641 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3643 if (_frvfdpic_osec_readonly_p (output_bfd
,
3647 info
->callbacks
->warning
3649 _("cannot emit fixups in read-only section"),
3650 name
, input_bfd
, input_section
, rel
->r_offset
);
3653 _frvfdpic_add_rofixup (output_bfd
,
3654 frvfdpic_gotfixup_section
3656 _bfd_elf_section_offset
3658 input_section
, rel
->r_offset
)
3660 ->output_section
->vma
3661 + input_section
->output_offset
,
3665 else if ((bfd_get_section_flags (output_bfd
,
3666 input_section
->output_section
)
3667 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3669 if (_frvfdpic_osec_readonly_p (output_bfd
,
3673 info
->callbacks
->warning
3675 _("cannot emit dynamic relocations in read-only section"),
3676 name
, input_bfd
, input_section
, rel
->r_offset
);
3679 _frvfdpic_add_dyn_reloc (output_bfd
,
3680 frvfdpic_gotrel_section (info
),
3681 _bfd_elf_section_offset
3683 input_section
, rel
->r_offset
)
3685 ->output_section
->vma
3686 + input_section
->output_offset
,
3687 r_type
, dynindx
, addend
, picrel
);
3690 addend
+= frvfdpic_got_section (info
)->output_section
->vma
;
3693 /* We want the addend in-place because dynamic
3694 relocations are REL. Setting relocation to it should
3695 arrange for it to be installed. */
3696 relocation
= addend
- rel
->r_addend
;
3698 check_segment
[0] = check_segment
[1] = got_segment
;
3702 if (! IS_FDPIC (output_bfd
))
3704 check_segment
[0] = check_segment
[1] = -1;
3708 case R_FRV_FUNCDESC_VALUE
:
3711 bfd_vma addend
= rel
->r_addend
;
3713 /* If the symbol is dynamic but binds locally, use
3715 if (h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
))
3717 if (addend
&& r_type
== R_FRV_FUNCDESC_VALUE
)
3719 info
->callbacks
->warning
3720 (info
, _("R_FRV_FUNCDESC_VALUE references dynamic symbol with nonzero addend"),
3721 name
, input_bfd
, input_section
, rel
->r_offset
);
3724 dynindx
= h
->dynindx
;
3729 addend
+= h
->root
.u
.def
.value
;
3731 addend
+= sym
->st_value
;
3733 addend
+= osec
->output_offset
;
3734 if (osec
&& osec
->output_section
3735 && ! bfd_is_abs_section (osec
->output_section
)
3736 && ! bfd_is_und_section (osec
->output_section
))
3737 dynindx
= elf_section_data (osec
->output_section
)->dynindx
;
3742 /* If we're linking an executable at a fixed address, we
3743 can omit the dynamic relocation as long as the symbol
3744 is defined in the current link unit (which is implied
3745 by its output section not being NULL). */
3746 if (info
->executable
&& !info
->pie
3747 && (!h
|| FRVFDPIC_SYM_LOCAL (info
, h
)))
3750 addend
+= osec
->output_section
->vma
;
3751 if (IS_FDPIC (input_bfd
)
3752 && (bfd_get_section_flags (output_bfd
,
3753 input_section
->output_section
)
3754 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3756 if (_frvfdpic_osec_readonly_p (output_bfd
,
3760 info
->callbacks
->warning
3762 _("cannot emit fixups in read-only section"),
3763 name
, input_bfd
, input_section
, rel
->r_offset
);
3766 if (!h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
3768 _frvfdpic_add_rofixup (output_bfd
,
3769 frvfdpic_gotfixup_section
3771 _bfd_elf_section_offset
3773 input_section
, rel
->r_offset
)
3775 ->output_section
->vma
3776 + input_section
->output_offset
,
3778 if (r_type
== R_FRV_FUNCDESC_VALUE
)
3779 _frvfdpic_add_rofixup
3781 frvfdpic_gotfixup_section (info
),
3782 _bfd_elf_section_offset
3784 input_section
, rel
->r_offset
)
3785 + input_section
->output_section
->vma
3786 + input_section
->output_offset
+ 4, picrel
);
3792 if ((bfd_get_section_flags (output_bfd
,
3793 input_section
->output_section
)
3794 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3796 if (_frvfdpic_osec_readonly_p (output_bfd
,
3800 info
->callbacks
->warning
3802 _("cannot emit dynamic relocations in read-only section"),
3803 name
, input_bfd
, input_section
, rel
->r_offset
);
3806 _frvfdpic_add_dyn_reloc (output_bfd
,
3807 frvfdpic_gotrel_section (info
),
3808 _bfd_elf_section_offset
3810 input_section
, rel
->r_offset
)
3812 ->output_section
->vma
3813 + input_section
->output_offset
,
3814 r_type
, dynindx
, addend
, picrel
);
3817 addend
+= osec
->output_section
->vma
;
3818 /* We want the addend in-place because dynamic
3819 relocations are REL. Setting relocation to it
3820 should arrange for it to be installed. */
3821 relocation
= addend
- rel
->r_addend
;
3824 if (r_type
== R_FRV_FUNCDESC_VALUE
)
3826 /* If we've omitted the dynamic relocation, just emit
3827 the fixed addresses of the symbol and of the local
3829 if (info
->executable
&& !info
->pie
3830 && (!h
|| FRVFDPIC_SYM_LOCAL (info
, h
)))
3831 bfd_put_32 (output_bfd
,
3832 frvfdpic_got_section (info
)->output_section
->vma
3833 + frvfdpic_got_section (info
)->output_offset
3834 + frvfdpic_got_initial_offset (info
),
3835 contents
+ rel
->r_offset
+ 4);
3837 /* A function descriptor used for lazy or local
3838 resolving is initialized such that its high word
3839 contains the output section index in which the
3840 PLT entries are located, and the low word
3841 contains the offset of the lazy PLT entry entry
3842 point into that section. */
3843 bfd_put_32 (output_bfd
,
3844 h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
)
3846 : _frvfdpic_osec_to_segment (output_bfd
,
3849 contents
+ rel
->r_offset
+ 4);
3852 check_segment
[0] = check_segment
[1] = got_segment
;
3856 case R_FRV_GPRELU12
:
3860 check_segment
[0] = gprel_segment
;
3861 check_segment
[1] = sec
3862 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3866 case R_FRV_GETTLSOFF
:
3867 relocation
= frvfdpic_plt_section (info
)->output_section
->vma
3868 + frvfdpic_plt_section (info
)->output_offset
3869 + picrel
->tlsplt_entry
;
3870 BFD_ASSERT (picrel
->tlsplt_entry
!= (bfd_vma
)-1
3871 && picrel
->tlsdesc_entry
);
3872 check_segment
[0] = isec_segment
;
3873 check_segment
[1] = plt_segment
;
3876 case R_FRV_GOTTLSDESC12
:
3877 case R_FRV_GOTTLSDESCHI
:
3878 case R_FRV_GOTTLSDESCLO
:
3879 BFD_ASSERT (picrel
->tlsdesc_entry
);
3880 relocation
= picrel
->tlsdesc_entry
;
3881 check_segment
[0] = tls_segment
;
3882 check_segment
[1] = sec
3883 && ! bfd_is_abs_section (sec
)
3884 && ! bfd_is_und_section (sec
)
3885 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3889 case R_FRV_TLSMOFF12
:
3890 case R_FRV_TLSMOFFHI
:
3891 case R_FRV_TLSMOFFLO
:
3893 check_segment
[0] = tls_segment
;
3895 check_segment
[1] = -1;
3896 else if (bfd_is_abs_section (sec
)
3897 || bfd_is_und_section (sec
))
3900 check_segment
[1] = tls_segment
;
3902 else if (sec
->output_section
)
3904 relocation
-= tls_biased_base (info
);
3906 _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
);
3909 check_segment
[1] = -1;
3912 case R_FRV_GOTTLSOFF12
:
3913 case R_FRV_GOTTLSOFFHI
:
3914 case R_FRV_GOTTLSOFFLO
:
3915 BFD_ASSERT (picrel
->tlsoff_entry
);
3916 relocation
= picrel
->tlsoff_entry
;
3917 check_segment
[0] = tls_segment
;
3918 check_segment
[1] = sec
3919 && ! bfd_is_abs_section (sec
)
3920 && ! bfd_is_und_section (sec
)
3921 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3925 case R_FRV_TLSDESC_VALUE
:
3927 /* These shouldn't be present in input object files. */
3928 check_segment
[0] = check_segment
[1] = isec_segment
;
3931 case R_FRV_TLSDESC_RELAX
:
3932 case R_FRV_GETTLSOFF_RELAX
:
3933 case R_FRV_TLSOFF_RELAX
:
3934 /* These are just annotations for relaxation, nothing to do
3939 check_segment
[0] = isec_segment
;
3940 check_segment
[1] = sec
3941 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3946 if (check_segment
[0] != check_segment
[1] && IS_FDPIC (output_bfd
))
3948 /* If you take this out, remove the #error from fdpic-static-6.d
3949 in the ld testsuite. */
3950 /* This helps catch problems in GCC while we can't do more
3951 than static linking. The idea is to test whether the
3952 input file basename is crt0.o only once. */
3953 if (silence_segment_error
== 1)
3954 silence_segment_error
=
3955 (strlen (input_bfd
->filename
) == 6
3956 && strcmp (input_bfd
->filename
, "crt0.o") == 0)
3957 || (strlen (input_bfd
->filename
) > 6
3958 && strcmp (input_bfd
->filename
3959 + strlen (input_bfd
->filename
) - 7,
3962 if (!silence_segment_error
3963 /* We don't want duplicate errors for undefined
3965 && !(picrel
&& picrel
->symndx
== -1
3966 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefined
))
3968 if (info
->shared
|| info
->pie
)
3969 (*_bfd_error_handler
)
3970 (_("%B(%A+0x%lx): reloc against `%s': %s"),
3971 input_bfd
, input_section
, (long)rel
->r_offset
, name
,
3972 _("relocation references a different segment"));
3974 info
->callbacks
->warning
3976 _("relocation references a different segment"),
3977 name
, input_bfd
, input_section
, rel
->r_offset
);
3979 if (!silence_segment_error
&& (info
->shared
|| info
->pie
))
3981 elf_elfheader (output_bfd
)->e_flags
|= EF_FRV_PIC
;
3986 case R_FRV_GOTOFFHI
:
3987 case R_FRV_TLSMOFFHI
:
3988 /* We need the addend to be applied before we shift the
3990 relocation
+= rel
->r_addend
;
3993 case R_FRV_FUNCDESC_GOTHI
:
3994 case R_FRV_FUNCDESC_GOTOFFHI
:
3995 case R_FRV_GOTTLSOFFHI
:
3996 case R_FRV_GOTTLSDESCHI
:
4001 case R_FRV_FUNCDESC_GOTLO
:
4002 case R_FRV_GOTOFFLO
:
4003 case R_FRV_FUNCDESC_GOTOFFLO
:
4004 case R_FRV_GOTTLSOFFLO
:
4005 case R_FRV_GOTTLSDESCLO
:
4006 case R_FRV_TLSMOFFLO
:
4007 relocation
&= 0xffff;
4017 if (! IS_FDPIC (output_bfd
) || ! picrel
->plt
)
4021 /* When referencing a GOT entry, a function descriptor or a
4022 PLT, we don't want the addend to apply to the reference,
4023 but rather to the referenced symbol. The actual entry
4024 will have already been created taking the addend into
4025 account, so cancel it out here. */
4029 case R_FRV_FUNCDESC_GOT12
:
4030 case R_FRV_FUNCDESC_GOTHI
:
4031 case R_FRV_FUNCDESC_GOTLO
:
4032 case R_FRV_FUNCDESC_GOTOFF12
:
4033 case R_FRV_FUNCDESC_GOTOFFHI
:
4034 case R_FRV_FUNCDESC_GOTOFFLO
:
4035 case R_FRV_GETTLSOFF
:
4036 case R_FRV_GOTTLSDESC12
:
4037 case R_FRV_GOTTLSDESCHI
:
4038 case R_FRV_GOTTLSDESCLO
:
4039 case R_FRV_GOTTLSOFF12
:
4040 case R_FRV_GOTTLSOFFHI
:
4041 case R_FRV_GOTTLSOFFLO
:
4042 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
4043 here, since we do want to apply the addend to the others.
4044 Note that we've applied the addend to GOTOFFHI before we
4045 shifted it right. */
4046 case R_FRV_GOTOFFHI
:
4047 case R_FRV_TLSMOFFHI
:
4048 relocation
-= rel
->r_addend
;
4055 if (r_type
== R_FRV_HI16
)
4056 r
= elf32_frv_relocate_hi16 (input_bfd
, rel
, contents
, relocation
);
4058 else if (r_type
== R_FRV_LO16
)
4059 r
= elf32_frv_relocate_lo16 (input_bfd
, rel
, contents
, relocation
);
4061 else if (r_type
== R_FRV_LABEL24
|| r_type
== R_FRV_GETTLSOFF
)
4062 r
= elf32_frv_relocate_label24 (input_bfd
, input_section
, rel
,
4063 contents
, relocation
);
4065 else if (r_type
== R_FRV_GPREL12
)
4066 r
= elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, rel
,
4067 contents
, relocation
);
4069 else if (r_type
== R_FRV_GPRELU12
)
4070 r
= elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, rel
,
4071 contents
, relocation
);
4073 else if (r_type
== R_FRV_GPRELLO
)
4074 r
= elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, rel
,
4075 contents
, relocation
);
4077 else if (r_type
== R_FRV_GPRELHI
)
4078 r
= elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, rel
,
4079 contents
, relocation
);
4081 else if (r_type
== R_FRV_TLSOFF
4082 || r_type
== R_FRV_TLSDESC_VALUE
)
4083 r
= bfd_reloc_notsupported
;
4086 r
= frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
4089 if (r
!= bfd_reloc_ok
)
4091 const char * msg
= (const char *) NULL
;
4095 case bfd_reloc_overflow
:
4096 r
= info
->callbacks
->reloc_overflow
4097 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4098 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
4101 case bfd_reloc_undefined
:
4102 r
= info
->callbacks
->undefined_symbol
4103 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
4106 case bfd_reloc_outofrange
:
4107 msg
= _("internal error: out of range error");
4110 case bfd_reloc_notsupported
:
4111 msg
= _("internal error: unsupported relocation error");
4114 case bfd_reloc_dangerous
:
4115 msg
= _("internal error: dangerous relocation");
4119 msg
= _("internal error: unknown error");
4125 (*_bfd_error_handler
)
4126 (_("%B(%A+0x%lx): reloc against `%s': %s"),
4127 input_bfd
, input_section
, (long)rel
->r_offset
, name
, msg
);
4139 /* Return the section that should be marked against GC for a given
4143 elf32_frv_gc_mark_hook (sec
, info
, rel
, h
, sym
)
4145 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
4146 Elf_Internal_Rela
*rel
;
4147 struct elf_link_hash_entry
*h
;
4148 Elf_Internal_Sym
*sym
;
4152 switch (ELF32_R_TYPE (rel
->r_info
))
4154 case R_FRV_GNU_VTINHERIT
:
4155 case R_FRV_GNU_VTENTRY
:
4159 switch (h
->root
.type
)
4164 case bfd_link_hash_defined
:
4165 case bfd_link_hash_defweak
:
4166 return h
->root
.u
.def
.section
;
4168 case bfd_link_hash_common
:
4169 return h
->root
.u
.c
.p
->section
;
4174 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
4179 /* Update the got entry reference counts for the section being removed. */
4182 elf32_frv_gc_sweep_hook (abfd
, info
, sec
, relocs
)
4183 bfd
*abfd ATTRIBUTE_UNUSED
;
4184 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
4185 asection
*sec ATTRIBUTE_UNUSED
;
4186 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
4192 /* Hook called by the linker routine which adds symbols from an object
4193 file. We use it to put .comm items in .scomm, and not .comm. */
4196 elf32_frv_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
4198 struct bfd_link_info
*info
;
4199 Elf_Internal_Sym
*sym
;
4200 const char **namep ATTRIBUTE_UNUSED
;
4201 flagword
*flagsp ATTRIBUTE_UNUSED
;
4205 if (sym
->st_shndx
== SHN_COMMON
4206 && !info
->relocatable
4207 && (int)sym
->st_size
<= (int)bfd_get_gp_size (abfd
))
4209 /* Common symbols less than or equal to -G nn bytes are
4210 automatically put into .sbss. */
4212 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
4216 scomm
= bfd_make_section_with_flags (abfd
, ".scommon",
4219 | SEC_LINKER_CREATED
));
4225 *valp
= sym
->st_size
;
4231 /* We need dynamic symbols for every section, since segments can
4232 relocate independently. */
4234 _frvfdpic_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4235 struct bfd_link_info
*info
4237 asection
*p ATTRIBUTE_UNUSED
)
4239 switch (elf_section_data (p
)->this_hdr
.sh_type
)
4243 /* If sh_type is yet undecided, assume it could be
4244 SHT_PROGBITS/SHT_NOBITS. */
4248 /* There shouldn't be section relative relocations
4249 against any other section. */
4255 /* Create a .got section, as well as its additional info field. This
4256 is almost entirely copied from
4257 elflink.c:_bfd_elf_create_got_section(). */
4260 _frv_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4262 flagword flags
, pltflags
;
4264 struct elf_link_hash_entry
*h
;
4265 struct bfd_link_hash_entry
*bh
;
4266 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4270 /* This function may be called more than once. */
4271 s
= bfd_get_section_by_name (abfd
, ".got");
4272 if (s
!= NULL
&& (s
->flags
& SEC_LINKER_CREATED
) != 0)
4275 /* Machine specific: although pointers are 32-bits wide, we want the
4276 GOT to be aligned to a 64-bit boundary, such that function
4277 descriptors in it can be accessed with 64-bit loads and
4281 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4282 | SEC_LINKER_CREATED
);
4285 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
4287 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
4290 if (bed
->want_got_plt
)
4292 s
= bfd_make_section_with_flags (abfd
, ".got.plt", flags
);
4294 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
4298 if (bed
->want_got_sym
)
4300 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
4301 (or .got.plt) section. We don't do this in the linker script
4302 because we don't want to define the symbol if we are not creating
4303 a global offset table. */
4304 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
, "_GLOBAL_OFFSET_TABLE_");
4305 elf_hash_table (info
)->hgot
= h
;
4309 /* Machine-specific: we want the symbol for executables as
4311 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4315 /* The first bit of the global offset table is the header. */
4316 s
->size
+= bed
->got_header_size
;
4318 /* This is the machine-specific part. Create and initialize section
4319 data for the got. */
4320 if (IS_FDPIC (abfd
))
4322 frvfdpic_got_section (info
) = s
;
4323 frvfdpic_relocs_info (info
) = htab_try_create (1,
4324 frvfdpic_relocs_info_hash
,
4325 frvfdpic_relocs_info_eq
,
4327 if (! frvfdpic_relocs_info (info
))
4330 s
= bfd_make_section_with_flags (abfd
, ".rel.got",
4331 (flags
| SEC_READONLY
));
4333 || ! bfd_set_section_alignment (abfd
, s
, 2))
4336 frvfdpic_gotrel_section (info
) = s
;
4338 /* Machine-specific. */
4339 s
= bfd_make_section_with_flags (abfd
, ".rofixup",
4340 (flags
| SEC_READONLY
));
4342 || ! bfd_set_section_alignment (abfd
, s
, 2))
4345 frvfdpic_gotfixup_section (info
) = s
;
4352 flags
= BSF_GLOBAL
| BSF_WEAK
;
4355 /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it
4356 turns out that we're linking with a different linker script, the
4357 linker script will override it. */
4359 if (!(_bfd_generic_link_add_one_symbol
4360 (info
, abfd
, "_gp", flags
, s
, offset
, (const char *) NULL
, FALSE
,
4361 bed
->collect
, &bh
)))
4363 h
= (struct elf_link_hash_entry
*) bh
;
4365 h
->type
= STT_OBJECT
;
4366 /* h->other = STV_HIDDEN; */ /* Should we? */
4368 /* Machine-specific: we want the symbol for executables as well. */
4369 if (IS_FDPIC (abfd
) && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
4372 if (!IS_FDPIC (abfd
))
4375 /* FDPIC supports Thread Local Storage, and this may require a
4376 procedure linkage table for TLS PLT entries. */
4378 /* This is mostly copied from
4379 elflink.c:_bfd_elf_create_dynamic_sections(). */
4382 pltflags
|= SEC_CODE
;
4383 if (bed
->plt_not_loaded
)
4384 pltflags
&= ~ (SEC_CODE
| SEC_LOAD
| SEC_HAS_CONTENTS
);
4385 if (bed
->plt_readonly
)
4386 pltflags
|= SEC_READONLY
;
4388 s
= bfd_make_section_with_flags (abfd
, ".plt", pltflags
);
4390 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
4392 /* FRV-specific: remember it. */
4393 frvfdpic_plt_section (info
) = s
;
4395 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
4397 if (bed
->want_plt_sym
4398 && !_bfd_elf_define_linkage_sym (abfd
, info
, s
,
4399 "_PROCEDURE_LINKAGE_TABLE_"))
4402 /* FRV-specific: we want rel relocations for the plt. */
4403 s
= bfd_make_section_with_flags (abfd
, ".rel.plt",
4404 flags
| SEC_READONLY
);
4406 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
4408 /* FRV-specific: remember it. */
4409 frvfdpic_pltrel_section (info
) = s
;
4414 /* Make sure the got and plt sections exist, and that our pointers in
4415 the link hash table point to them. */
4418 elf32_frvfdpic_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
4420 /* This is mostly copied from
4421 elflink.c:_bfd_elf_create_dynamic_sections(). */
4424 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4426 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4427 | SEC_LINKER_CREATED
);
4429 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
4430 .rel[a].bss sections. */
4432 /* FRV-specific: we want to create the GOT and the PLT in the FRV
4434 if (! _frv_create_got_section (abfd
, info
))
4437 /* FRV-specific: make sure we created everything we wanted. */
4438 BFD_ASSERT (frvfdpic_got_section (info
) && frvfdpic_gotrel_section (info
)
4439 && frvfdpic_gotfixup_section (info
)
4440 && frvfdpic_plt_section (info
)
4441 && frvfdpic_pltrel_section (info
));
4443 if (bed
->want_dynbss
)
4445 /* The .dynbss section is a place to put symbols which are defined
4446 by dynamic objects, are referenced by regular objects, and are
4447 not functions. We must allocate space for them in the process
4448 image and use a R_*_COPY reloc to tell the dynamic linker to
4449 initialize them at run time. The linker script puts the .dynbss
4450 section into the .bss section of the final image. */
4451 s
= bfd_make_section_with_flags (abfd
, ".dynbss",
4452 SEC_ALLOC
| SEC_LINKER_CREATED
);
4456 /* The .rel[a].bss section holds copy relocs. This section is not
4457 normally needed. We need to create it here, though, so that the
4458 linker will map it to an output section. We can't just create it
4459 only if we need it, because we will not know whether we need it
4460 until we have seen all the input files, and the first time the
4461 main linker code calls BFD after examining all the input files
4462 (size_dynamic_sections) the input sections have already been
4463 mapped to the output sections. If the section turns out not to
4464 be needed, we can discard it later. We will never need this
4465 section when generating a shared object, since they do not use
4469 s
= bfd_make_section_with_flags (abfd
,
4470 (bed
->default_use_rela_p
4471 ? ".rela.bss" : ".rel.bss"),
4472 flags
| SEC_READONLY
);
4474 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
4482 /* Compute the total GOT and PLT size required by each symbol in each
4483 range. Symbols may require up to 4 words in the GOT: an entry
4484 pointing to the symbol, an entry pointing to its function
4485 descriptor, and a private function descriptors taking two
4489 _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info
*entry
,
4490 struct _frvfdpic_dynamic_got_info
*dinfo
)
4492 /* Allocate space for a GOT entry pointing to the symbol. */
4495 else if (entry
->gotlos
)
4497 else if (entry
->gothilo
)
4498 dinfo
->gothilo
+= 4;
4503 /* Allocate space for a GOT entry pointing to the function
4507 else if (entry
->fdgotlos
)
4509 else if (entry
->fdgothilo
)
4510 dinfo
->gothilo
+= 4;
4515 /* Decide whether we need a PLT entry, a function descriptor in the
4516 GOT, and a lazy PLT entry for this symbol. */
4517 entry
->plt
= entry
->call
4518 && entry
->symndx
== -1 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4519 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
4520 entry
->privfd
= entry
->plt
4521 || entry
->fdgoff12
|| entry
->fdgofflos
|| entry
->fdgoffhilo
4522 || ((entry
->fd
|| entry
->fdgot12
|| entry
->fdgotlos
|| entry
->fdgothilo
)
4523 && (entry
->symndx
!= -1
4524 || FRVFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
)));
4525 entry
->lazyplt
= entry
->privfd
4526 && entry
->symndx
== -1 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4527 && ! (dinfo
->info
->flags
& DF_BIND_NOW
)
4528 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
4530 /* Allocate space for a function descriptor. */
4531 if (entry
->fdgoff12
)
4533 else if (entry
->fdgofflos
)
4535 else if (entry
->privfd
&& entry
->plt
)
4537 else if (entry
->privfd
)
4547 /* Compute the total GOT size required by each TLS symbol in each
4548 range. Symbols may require up to 5 words in the GOT: an entry
4549 holding the TLS offset for the symbol, and an entry with a full TLS
4550 descriptor taking 4 words. */
4553 _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info
*entry
,
4554 struct _frvfdpic_dynamic_got_info
*dinfo
,
4555 bfd_boolean subtract
)
4557 const int l
= subtract
? -1 : 1;
4559 /* Allocate space for a GOT entry with the TLS offset of the
4561 if (entry
->tlsoff12
)
4562 dinfo
->got12
+= 4 * l
;
4563 else if (entry
->tlsofflos
)
4564 dinfo
->gotlos
+= 4 * l
;
4565 else if (entry
->tlsoffhilo
)
4566 dinfo
->gothilo
+= 4 * l
;
4568 entry
->relocstlsoff
-= l
;
4569 entry
->relocstlsoff
+= l
;
4571 /* If there's any TLSOFF relocation, mark the output file as not
4572 suitable for dlopening. This mark will remain even if we relax
4573 all such relocations, but this is not a problem, since we'll only
4574 do so for executables, and we definitely don't want anyone
4575 dlopening executables. */
4576 if (entry
->relocstlsoff
)
4577 dinfo
->info
->flags
|= DF_STATIC_TLS
;
4579 /* Allocate space for a TLS descriptor. */
4580 if (entry
->tlsdesc12
)
4581 dinfo
->tlsd12
+= 8 * l
;
4582 else if (entry
->tlsdesclos
)
4583 dinfo
->tlsdlos
+= 8 * l
;
4584 else if (entry
->tlsplt
)
4585 dinfo
->tlsdplt
+= 8 * l
;
4586 else if (entry
->tlsdeschilo
)
4587 dinfo
->tlsdhilo
+= 8 * l
;
4589 entry
->relocstlsd
-= l
;
4590 entry
->relocstlsd
+= l
;
4593 /* Compute the number of dynamic relocations and fixups that a symbol
4594 requires, and add (or subtract) from the grand and per-symbol
4598 _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info
*entry
,
4599 struct _frvfdpic_dynamic_got_info
*dinfo
,
4600 bfd_boolean subtract
)
4602 bfd_vma relocs
= 0, fixups
= 0, tlsrets
= 0;
4604 if (!dinfo
->info
->executable
|| dinfo
->info
->pie
)
4606 relocs
= entry
->relocs32
+ entry
->relocsfd
+ entry
->relocsfdv
4607 + entry
->relocstlsd
;
4609 /* In the executable, TLS relocations to symbols that bind
4610 locally (including those that resolve to global TLS offsets)
4611 are resolved immediately, without any need for fixups or
4612 dynamic relocations. In shared libraries, however, we must
4613 emit dynamic relocations even for local symbols, because we
4614 don't know the module id the library is going to get at
4615 run-time, nor its TLS base offset. */
4616 if (!dinfo
->info
->executable
4617 || (entry
->symndx
== -1
4618 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)))
4619 relocs
+= entry
->relocstlsoff
;
4623 if (entry
->symndx
!= -1 || FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
))
4625 if (entry
->symndx
!= -1
4626 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
4627 fixups
+= entry
->relocs32
+ 2 * entry
->relocsfdv
;
4628 fixups
+= entry
->relocstlsd
;
4629 tlsrets
+= entry
->relocstlsd
;
4633 relocs
+= entry
->relocs32
+ entry
->relocsfdv
4634 + entry
->relocstlsoff
+ entry
->relocstlsd
;
4637 if (entry
->symndx
!= -1
4638 || FRVFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
))
4640 if (entry
->symndx
!= -1
4641 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
4642 fixups
+= entry
->relocsfd
;
4645 relocs
+= entry
->relocsfd
;
4652 tlsrets
= - tlsrets
;
4655 entry
->dynrelocs
+= relocs
;
4656 entry
->fixups
+= fixups
;
4657 dinfo
->relocs
+= relocs
;
4658 dinfo
->fixups
+= fixups
;
4659 dinfo
->tls_ret_refs
+= tlsrets
;
4662 /* Look for opportunities to relax TLS relocations. We can assume
4663 we're linking the main executable or a static-tls library, since
4664 otherwise we wouldn't have got here. When relaxing, we have to
4665 first undo any previous accounting of TLS uses of fixups, dynamic
4666 relocations, GOT and PLT entries. */
4669 _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info
*entry
,
4670 struct _frvfdpic_dynamic_got_info
*dinfo
,
4671 bfd_boolean relaxing
)
4673 bfd_boolean changed
= ! relaxing
;
4675 BFD_ASSERT (dinfo
->info
->executable
4676 || (dinfo
->info
->flags
& DF_STATIC_TLS
));
4678 if (entry
->tlsdesc12
|| entry
->tlsdesclos
|| entry
->tlsdeschilo
)
4682 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4683 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4687 /* When linking an executable, we can always decay GOTTLSDESC to
4688 TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise.
4689 When linking a static-tls shared library, using TLSMOFF is
4690 not an option, but we can still use GOTTLSOFF. When decaying
4691 to GOTTLSOFF, we must keep the GOT entry in range. We know
4692 it has to fit because we'll be trading the 4 words of hte TLS
4693 descriptor for a single word in the same range. */
4694 if (! dinfo
->info
->executable
4695 || (entry
->symndx
== -1
4696 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)))
4698 entry
->tlsoff12
|= entry
->tlsdesc12
;
4699 entry
->tlsofflos
|= entry
->tlsdesclos
;
4700 entry
->tlsoffhilo
|= entry
->tlsdeschilo
;
4703 entry
->tlsdesc12
= entry
->tlsdesclos
= entry
->tlsdeschilo
= 0;
4706 /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the
4707 main executable. We have to check whether the symbol's TLSOFF is
4708 in range for a setlos. For symbols with a hash entry, we can
4709 determine exactly what to do; for others locals, we don't have
4710 addresses handy, so we use the size of the TLS section as an
4711 approximation. If we get it wrong, we'll retain a GOT entry
4712 holding the TLS offset (without dynamic relocations or fixups),
4713 but we'll still optimize away the loads from it. Since TLS sizes
4714 are generally very small, it's probably not worth attempting to
4715 do better than this. */
4717 || entry
->tlsoff12
|| entry
->tlsofflos
|| entry
->tlsoffhilo
)
4718 && dinfo
->info
->executable
&& relaxing
4719 && ((entry
->symndx
== -1
4720 && FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4721 /* The above may hold for an undefweak TLS symbol, so make
4722 sure we don't have this case before accessing def.value
4724 && (entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
4725 || (bfd_vma
)(entry
->d
.h
->root
.u
.def
.value
4726 + (entry
->d
.h
->root
.u
.def
.section
4727 ->output_section
->vma
)
4728 + entry
->d
.h
->root
.u
.def
.section
->output_offset
4730 - tls_biased_base (dinfo
->info
)
4731 + 32768) < (bfd_vma
)65536))
4732 || (entry
->symndx
!= -1
4733 && (elf_hash_table (dinfo
->info
)->tls_sec
->size
4734 + abs (entry
->addend
) < 32768 + FRVFDPIC_TLS_BIAS
))))
4738 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4739 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4744 entry
->tlsoff12
= entry
->tlsofflos
= entry
->tlsoffhilo
= 0;
4747 /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already
4748 have a #gottlsoff12 relocation for this entry, or if we can fit
4749 one more in the 12-bit (and 16-bit) ranges. */
4753 && dinfo
->got12
+ dinfo
->fd12
+ dinfo
->tlsd12
<= 4096 - 12 - 4
4754 && (dinfo
->got12
+ dinfo
->fd12
+ dinfo
->tlsd12
4755 + dinfo
->gotlos
+ dinfo
->fdlos
+ dinfo
->tlsdlos
4756 <= 65536 - 12 - 4))))
4760 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4761 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4765 entry
->tlsoff12
= 1;
4771 _frvfdpic_count_tls_entries (entry
, dinfo
, FALSE
);
4772 _frvfdpic_count_relocs_fixups (entry
, dinfo
, FALSE
);
4778 /* Compute the total GOT and PLT size required by each symbol in each range. *
4779 Symbols may require up to 4 words in the GOT: an entry pointing to
4780 the symbol, an entry pointing to its function descriptor, and a
4781 private function descriptors taking two words. */
4784 _frvfdpic_count_got_plt_entries (void **entryp
, void *dinfo_
)
4786 struct frvfdpic_relocs_info
*entry
= *entryp
;
4787 struct _frvfdpic_dynamic_got_info
*dinfo
= dinfo_
;
4789 _frvfdpic_count_nontls_entries (entry
, dinfo
);
4791 if (dinfo
->info
->executable
|| (dinfo
->info
->flags
& DF_STATIC_TLS
))
4792 _frvfdpic_relax_tls_entries (entry
, dinfo
, FALSE
);
4795 _frvfdpic_count_tls_entries (entry
, dinfo
, FALSE
);
4796 _frvfdpic_count_relocs_fixups (entry
, dinfo
, FALSE
);
4802 /* Determine the positive and negative ranges to be used by each
4803 offset range in the GOT. FDCUR and CUR, that must be aligned to a
4804 double-word boundary, are the minimum (negative) and maximum
4805 (positive) GOT offsets already used by previous ranges, except for
4806 an ODD entry that may have been left behind. GOT and FD indicate
4807 the size of GOT entries and function descriptors that must be
4808 placed within the range from -WRAP to WRAP. If there's room left,
4809 up to FDPLT bytes should be reserved for additional function
4812 inline static bfd_signed_vma
4813 _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data
*gad
,
4814 bfd_signed_vma fdcur
,
4824 bfd_signed_vma wrapmin
= -wrap
;
4825 const bfd_vma tdescsz
= 8;
4827 /* Start at the given initial points. */
4831 /* If we had an incoming odd word and we have any got entries that
4832 are going to use it, consume it, otherwise leave gad->odd at
4833 zero. We might force gad->odd to zero and return the incoming
4834 odd such that it is used by the next range, but then GOT entries
4835 might appear to be out of order and we wouldn't be able to
4836 shorten the GOT by one word if it turns out to end with an
4837 unpaired GOT entry. */
4847 /* If we're left with an unpaired GOT entry, compute its location
4848 such that we can return it. Otherwise, if got doesn't require an
4849 odd number of words here, either odd was already zero in the
4850 block above, or it was set to zero because got was non-zero, or
4851 got was already zero. In the latter case, we want the value of
4852 odd to carry over to the return statement, so we don't want to
4853 reset odd unless the condition below is true. */
4860 /* Compute the tentative boundaries of this range. */
4861 gad
->max
= cur
+ got
;
4862 gad
->min
= fdcur
- fd
;
4865 /* If function descriptors took too much space, wrap some of them
4867 if (gad
->min
< wrapmin
)
4869 gad
->max
+= wrapmin
- gad
->min
;
4870 gad
->tmin
= gad
->min
= wrapmin
;
4873 /* If GOT entries took too much space, wrap some of them around.
4874 This may well cause gad->min to become lower than wrapmin. This
4875 will cause a relocation overflow later on, so we don't have to
4877 if ((bfd_vma
) gad
->max
> wrap
)
4879 gad
->min
-= gad
->max
- wrap
;
4883 /* Add TLS descriptors. */
4884 gad
->tmax
= gad
->max
+ tlsd
;
4885 gad
->tmin
= gad
->min
;
4888 /* If TLS descriptors took too much space, wrap an integral number
4890 if ((bfd_vma
) gad
->tmax
> wrap
)
4892 bfd_vma wrapsize
= gad
->tmax
- wrap
;
4894 wrapsize
+= tdescsz
/ 2;
4895 wrapsize
&= ~ tdescsz
/ 2;
4897 gad
->tmin
-= wrapsize
;
4898 gad
->tmax
-= wrapsize
;
4901 /* If there is space left and we have function descriptors
4902 referenced in PLT entries that could take advantage of shorter
4903 offsets, place them now. */
4904 if (fdplt
&& gad
->tmin
> wrapmin
)
4908 if ((bfd_vma
) (gad
->tmin
- wrapmin
) < fdplt
)
4909 fds
= gad
->tmin
- wrapmin
;
4919 /* If there is more space left, try to place some more function
4920 descriptors for PLT entries. */
4921 if (fdplt
&& (bfd_vma
) gad
->tmax
< wrap
)
4925 if ((bfd_vma
) (wrap
- gad
->tmax
) < fdplt
)
4926 fds
= wrap
- gad
->tmax
;
4936 /* If there is space left and we have TLS descriptors referenced in
4937 PLT entries that could take advantage of shorter offsets, place
4939 if (tlsdplt
&& gad
->tmin
> wrapmin
)
4943 if ((bfd_vma
) (gad
->tmin
- wrapmin
) < tlsdplt
)
4944 tlsds
= (gad
->tmin
- wrapmin
) & ~ (tdescsz
/ 2);
4950 gad
->tlsdplt
+= tlsds
;
4953 /* If there is more space left, try to place some more TLS
4954 descriptors for PLT entries. Although we could try to fit an
4955 additional TLS descriptor with half of it just before before the
4956 wrap point and another right past the wrap point, this might
4957 cause us to run out of space for the next region, so don't do
4959 if (tlsdplt
&& (bfd_vma
) gad
->tmax
< wrap
- tdescsz
/ 2)
4963 if ((bfd_vma
) (wrap
- gad
->tmax
) < tlsdplt
)
4964 tlsds
= (wrap
- gad
->tmax
) & ~ (tdescsz
/ 2);
4970 gad
->tlsdplt
+= tlsds
;
4973 /* If odd was initially computed as an offset past the wrap point,
4976 odd
= gad
->min
+ odd
- gad
->max
;
4978 /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed
4979 before returning, so do it here too. This guarantees that,
4980 should cur and fdcur meet at the wrap point, they'll both be
4982 if (gad
->cur
== gad
->max
)
4983 gad
->cur
= gad
->min
;
4985 /* Ditto for _frvfdpic_get_tlsdesc_entry(). */
4986 gad
->tcur
= gad
->max
;
4987 if (gad
->tcur
== gad
->tmax
)
4988 gad
->tcur
= gad
->tmin
;
4993 /* Compute the location of the next GOT entry, given the allocation
4994 data for a range. */
4996 inline static bfd_signed_vma
4997 _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
5003 /* If there was an odd word left behind, use it. */
5009 /* Otherwise, use the word pointed to by cur, reserve the next
5010 as an odd word, and skip to the next pair of words, possibly
5013 gad
->odd
= gad
->cur
+ 4;
5015 if (gad
->cur
== gad
->max
)
5016 gad
->cur
= gad
->min
;
5022 /* Compute the location of the next function descriptor entry in the
5023 GOT, given the allocation data for a range. */
5025 inline static bfd_signed_vma
5026 _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
5028 /* If we're at the bottom, wrap around, and only then allocate the
5029 next pair of words. */
5030 if (gad
->fdcur
== gad
->min
)
5031 gad
->fdcur
= gad
->max
;
5032 return gad
->fdcur
-= 8;
5035 /* Compute the location of the next TLS descriptor entry in the GOT,
5036 given the allocation data for a range. */
5037 inline static bfd_signed_vma
5038 _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
5046 /* If we're at the top of the region, wrap around to the bottom. */
5047 if (gad
->tcur
== gad
->tmax
)
5048 gad
->tcur
= gad
->tmin
;
5053 /* Assign GOT offsets for every GOT entry and function descriptor.
5054 Doing everything in a single pass is tricky. */
5057 _frvfdpic_assign_got_entries (void **entryp
, void *info_
)
5059 struct frvfdpic_relocs_info
*entry
= *entryp
;
5060 struct _frvfdpic_dynamic_got_plt_info
*dinfo
= info_
;
5063 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5064 else if (entry
->gotlos
)
5065 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5066 else if (entry
->gothilo
)
5067 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5070 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5071 else if (entry
->fdgotlos
)
5072 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5073 else if (entry
->fdgothilo
)
5074 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5076 if (entry
->fdgoff12
)
5077 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->got12
);
5078 else if (entry
->plt
&& dinfo
->got12
.fdplt
)
5080 dinfo
->got12
.fdplt
-= 8;
5081 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->got12
);
5083 else if (entry
->fdgofflos
)
5084 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gotlos
);
5085 else if (entry
->plt
&& dinfo
->gotlos
.fdplt
)
5087 dinfo
->gotlos
.fdplt
-= 8;
5088 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gotlos
);
5090 else if (entry
->plt
)
5092 dinfo
->gothilo
.fdplt
-= 8;
5093 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gothilo
);
5095 else if (entry
->privfd
)
5096 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gothilo
);
5098 if (entry
->tlsoff12
)
5099 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5100 else if (entry
->tlsofflos
)
5101 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5102 else if (entry
->tlsoffhilo
)
5103 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5105 if (entry
->tlsdesc12
)
5106 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->got12
);
5107 else if (entry
->tlsplt
&& dinfo
->got12
.tlsdplt
)
5109 dinfo
->got12
.tlsdplt
-= 8;
5110 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->got12
);
5112 else if (entry
->tlsdesclos
)
5113 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gotlos
);
5114 else if (entry
->tlsplt
&& dinfo
->gotlos
.tlsdplt
)
5116 dinfo
->gotlos
.tlsdplt
-= 8;
5117 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gotlos
);
5119 else if (entry
->tlsplt
)
5121 dinfo
->gothilo
.tlsdplt
-= 8;
5122 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gothilo
);
5124 else if (entry
->tlsdeschilo
)
5125 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gothilo
);
5130 /* Assign GOT offsets to private function descriptors used by PLT
5131 entries (or referenced by 32-bit offsets), as well as PLT entries
5132 and lazy PLT entries. */
5135 _frvfdpic_assign_plt_entries (void **entryp
, void *info_
)
5137 struct frvfdpic_relocs_info
*entry
= *entryp
;
5138 struct _frvfdpic_dynamic_got_plt_info
*dinfo
= info_
;
5141 BFD_ASSERT (entry
->fd_entry
);
5147 /* We use the section's raw size to mark the location of the
5149 entry
->plt_entry
= frvfdpic_plt_section (dinfo
->g
.info
)->size
;
5151 /* Figure out the length of this PLT entry based on the
5152 addressing mode we need to reach the function descriptor. */
5153 BFD_ASSERT (entry
->fd_entry
);
5154 if (entry
->fd_entry
>= -(1 << (12 - 1))
5155 && entry
->fd_entry
< (1 << (12 - 1)))
5157 else if (entry
->fd_entry
>= -(1 << (16 - 1))
5158 && entry
->fd_entry
< (1 << (16 - 1)))
5163 frvfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
5168 entry
->lzplt_entry
= dinfo
->g
.lzplt
;
5169 dinfo
->g
.lzplt
+= 8;
5170 /* If this entry is the one that gets the resolver stub, account
5171 for the additional instruction. */
5172 if (entry
->lzplt_entry
% FRVFDPIC_LZPLT_BLOCK_SIZE
5173 == FRVFDPIC_LZPLT_RESOLV_LOC
)
5174 dinfo
->g
.lzplt
+= 4;
5182 = frvfdpic_plt_section (dinfo
->g
.info
)->size
;
5184 if (dinfo
->g
.info
->executable
5185 && (entry
->symndx
!= -1
5186 || FRVFDPIC_SYM_LOCAL (dinfo
->g
.info
, entry
->d
.h
)))
5188 if ((bfd_signed_vma
)entry
->addend
>= -(1 << (16 - 1))
5189 /* FIXME: here we use the size of the TLS section
5190 as an upper bound for the value of the TLS
5191 symbol, because we may not know the exact value
5192 yet. If we get it wrong, we'll just waste a
5193 word in the PLT, and we should never get even
5194 close to 32 KiB of TLS anyway. */
5195 && elf_hash_table (dinfo
->g
.info
)->tls_sec
5196 && (elf_hash_table (dinfo
->g
.info
)->tls_sec
->size
5197 + (bfd_signed_vma
)(entry
->addend
) <= (1 << (16 - 1))))
5202 else if (entry
->tlsoff_entry
)
5204 if (entry
->tlsoff_entry
>= -(1 << (12 - 1))
5205 && entry
->tlsoff_entry
< (1 << (12 - 1)))
5207 else if (entry
->tlsoff_entry
>= -(1 << (16 - 1))
5208 && entry
->tlsoff_entry
< (1 << (16 - 1)))
5215 BFD_ASSERT (entry
->tlsdesc_entry
);
5217 if (entry
->tlsdesc_entry
>= -(1 << (12 - 1))
5218 && entry
->tlsdesc_entry
< (1 << (12 - 1)))
5220 else if (entry
->tlsdesc_entry
>= -(1 << (16 - 1))
5221 && entry
->tlsdesc_entry
< (1 << (16 - 1)))
5227 frvfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
5233 /* Cancel out any effects of calling _frvfdpic_assign_got_entries and
5234 _frvfdpic_assign_plt_entries. */
5237 _frvfdpic_reset_got_plt_entries (void **entryp
, void *ignore ATTRIBUTE_UNUSED
)
5239 struct frvfdpic_relocs_info
*entry
= *entryp
;
5241 entry
->got_entry
= 0;
5242 entry
->fdgot_entry
= 0;
5243 entry
->fd_entry
= 0;
5244 entry
->plt_entry
= (bfd_vma
)-1;
5245 entry
->lzplt_entry
= (bfd_vma
)-1;
5246 entry
->tlsoff_entry
= 0;
5247 entry
->tlsdesc_entry
= 0;
5248 entry
->tlsplt_entry
= (bfd_vma
)-1;
5253 /* Follow indirect and warning hash entries so that each got entry
5254 points to the final symbol definition. P must point to a pointer
5255 to the hash table we're traversing. Since this traversal may
5256 modify the hash table, we set this pointer to NULL to indicate
5257 we've made a potentially-destructive change to the hash table, so
5258 the traversal must be restarted. */
5260 _frvfdpic_resolve_final_relocs_info (void **entryp
, void *p
)
5262 struct frvfdpic_relocs_info
*entry
= *entryp
;
5265 if (entry
->symndx
== -1)
5267 struct elf_link_hash_entry
*h
= entry
->d
.h
;
5268 struct frvfdpic_relocs_info
*oentry
;
5270 while (h
->root
.type
== bfd_link_hash_indirect
5271 || h
->root
.type
== bfd_link_hash_warning
)
5272 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
5274 if (entry
->d
.h
== h
)
5277 oentry
= frvfdpic_relocs_info_for_global (*htab
, 0, h
, entry
->addend
,
5282 /* Merge the two entries. */
5283 frvfdpic_pic_merge_early_relocs_info (oentry
, entry
);
5284 htab_clear_slot (*htab
, entryp
);
5290 /* If we can't find this entry with the new bfd hash, re-insert
5291 it, and get the traversal restarted. */
5292 if (! htab_find (*htab
, entry
))
5294 htab_clear_slot (*htab
, entryp
);
5295 entryp
= htab_find_slot (*htab
, entry
, INSERT
);
5298 /* Abort the traversal, since the whole table may have
5299 moved, and leave it up to the parent to restart the
5301 *(htab_t
*)p
= NULL
;
5309 /* Compute the total size of the GOT, the PLT, the dynamic relocations
5310 section and the rofixup section. Assign locations for GOT and PLT
5314 _frvfdpic_size_got_plt (bfd
*output_bfd
,
5315 struct _frvfdpic_dynamic_got_plt_info
*gpinfop
)
5318 bfd_vma limit
, tlslimit
;
5319 struct bfd_link_info
*info
= gpinfop
->g
.info
;
5320 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
5322 memcpy (frvfdpic_dynamic_got_plt_info (info
), &gpinfop
->g
,
5323 sizeof (gpinfop
->g
));
5326 /* Compute the total size taken by entries in the 12-bit and 16-bit
5327 ranges, to tell how many PLT function descriptors we can bring
5328 into the 12-bit range without causing the 16-bit range to
5330 limit
= odd
+ gpinfop
->g
.got12
+ gpinfop
->g
.gotlos
5331 + gpinfop
->g
.fd12
+ gpinfop
->g
.fdlos
5332 + gpinfop
->g
.tlsd12
+ gpinfop
->g
.tlsdlos
;
5333 if (limit
< (bfd_vma
)1 << 16)
5334 limit
= ((bfd_vma
)1 << 16) - limit
;
5337 if (gpinfop
->g
.fdplt
< limit
)
5339 tlslimit
= (limit
- gpinfop
->g
.fdplt
) & ~ (bfd_vma
) 8;
5340 limit
= gpinfop
->g
.fdplt
;
5344 if (gpinfop
->g
.tlsdplt
< tlslimit
)
5345 tlslimit
= gpinfop
->g
.tlsdplt
;
5347 /* Determine the ranges of GOT offsets that we can use for each
5348 range of addressing modes. */
5349 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->got12
,
5358 (bfd_vma
)1 << (12-1));
5359 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->gotlos
,
5360 gpinfop
->got12
.tmin
,
5362 gpinfop
->got12
.tmax
,
5366 - gpinfop
->got12
.fdplt
,
5369 - gpinfop
->got12
.tlsdplt
,
5370 (bfd_vma
)1 << (16-1));
5371 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->gothilo
,
5372 gpinfop
->gotlos
.tmin
,
5374 gpinfop
->gotlos
.tmax
,
5378 - gpinfop
->got12
.fdplt
5379 - gpinfop
->gotlos
.fdplt
,
5380 gpinfop
->g
.tlsdhilo
,
5382 - gpinfop
->got12
.tlsdplt
5383 - gpinfop
->gotlos
.tlsdplt
,
5384 (bfd_vma
)1 << (32-1));
5386 /* Now assign (most) GOT offsets. */
5387 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_assign_got_entries
,
5390 frvfdpic_got_section (info
)->size
= gpinfop
->gothilo
.tmax
5391 - gpinfop
->gothilo
.tmin
5392 /* If an odd word is the last word of the GOT, we don't need this
5393 word to be part of the GOT. */
5394 - (odd
+ 4 == gpinfop
->gothilo
.tmax
? 4 : 0);
5395 if (frvfdpic_got_section (info
)->size
== 0)
5396 frvfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
5397 else if (frvfdpic_got_section (info
)->size
== 12
5398 && ! elf_hash_table (info
)->dynamic_sections_created
)
5400 frvfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
5401 frvfdpic_got_section (info
)->size
= 0;
5403 /* This will be non-NULL during relaxation. The assumption is that
5404 the size of one of these sections will never grow, only shrink,
5405 so we can use the larger buffer we allocated before. */
5406 else if (frvfdpic_got_section (info
)->contents
== NULL
)
5408 frvfdpic_got_section (info
)->contents
=
5409 (bfd_byte
*) bfd_zalloc (dynobj
,
5410 frvfdpic_got_section (info
)->size
);
5411 if (frvfdpic_got_section (info
)->contents
== NULL
)
5415 if (frvfdpic_gotrel_section (info
))
5416 /* Subtract the number of lzplt entries, since those will generate
5417 relocations in the pltrel section. */
5418 frvfdpic_gotrel_section (info
)->size
=
5419 (gpinfop
->g
.relocs
- gpinfop
->g
.lzplt
/ 8)
5420 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
5422 BFD_ASSERT (gpinfop
->g
.relocs
== 0);
5423 if (frvfdpic_gotrel_section (info
)->size
== 0)
5424 frvfdpic_gotrel_section (info
)->flags
|= SEC_EXCLUDE
;
5425 else if (frvfdpic_gotrel_section (info
)->contents
== NULL
)
5427 frvfdpic_gotrel_section (info
)->contents
=
5428 (bfd_byte
*) bfd_zalloc (dynobj
,
5429 frvfdpic_gotrel_section (info
)->size
);
5430 if (frvfdpic_gotrel_section (info
)->contents
== NULL
)
5434 frvfdpic_gotfixup_section (info
)->size
= (gpinfop
->g
.fixups
+ 1) * 4;
5435 if (frvfdpic_gotfixup_section (info
)->size
== 0)
5436 frvfdpic_gotfixup_section (info
)->flags
|= SEC_EXCLUDE
;
5437 else if (frvfdpic_gotfixup_section (info
)->contents
== NULL
)
5439 frvfdpic_gotfixup_section (info
)->contents
=
5440 (bfd_byte
*) bfd_zalloc (dynobj
,
5441 frvfdpic_gotfixup_section (info
)->size
);
5442 if (frvfdpic_gotfixup_section (info
)->contents
== NULL
)
5446 if (frvfdpic_pltrel_section (info
))
5448 frvfdpic_pltrel_section (info
)->size
=
5449 gpinfop
->g
.lzplt
/ 8
5450 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
5451 if (frvfdpic_pltrel_section (info
)->size
== 0)
5452 frvfdpic_pltrel_section (info
)->flags
|= SEC_EXCLUDE
;
5453 else if (frvfdpic_pltrel_section (info
)->contents
== NULL
)
5455 frvfdpic_pltrel_section (info
)->contents
=
5456 (bfd_byte
*) bfd_zalloc (dynobj
,
5457 frvfdpic_pltrel_section (info
)->size
);
5458 if (frvfdpic_pltrel_section (info
)->contents
== NULL
)
5463 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
5464 such that there's room for the additional instruction needed to
5465 call the resolver. Since _frvfdpic_assign_got_entries didn't
5466 account for them, our block size is 4 bytes smaller than the real
5468 if (frvfdpic_plt_section (info
))
5470 frvfdpic_plt_section (info
)->size
= gpinfop
->g
.lzplt
5471 + ((gpinfop
->g
.lzplt
+ (FRVFDPIC_LZPLT_BLOCK_SIZE
- 4) - 8)
5472 / (FRVFDPIC_LZPLT_BLOCK_SIZE
- 4) * 4);
5475 /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to
5476 actually assign lazy PLT entries addresses. */
5477 gpinfop
->g
.lzplt
= 0;
5479 /* Save information that we're going to need to generate GOT and PLT
5481 frvfdpic_got_initial_offset (info
) = -gpinfop
->gothilo
.tmin
;
5483 if (get_elf_backend_data (output_bfd
)->want_got_sym
)
5484 elf_hash_table (info
)->hgot
->root
.u
.def
.value
5485 = frvfdpic_got_initial_offset (info
);
5487 if (frvfdpic_plt_section (info
))
5488 frvfdpic_plt_initial_offset (info
) =
5489 frvfdpic_plt_section (info
)->size
;
5491 /* Allocate a ret statement at plt_initial_offset, to be used by
5492 locally-resolved TLS descriptors. */
5493 if (gpinfop
->g
.tls_ret_refs
)
5494 frvfdpic_plt_section (info
)->size
+= 4;
5496 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_assign_plt_entries
,
5499 /* Allocate the PLT section contents only after
5500 _frvfdpic_assign_plt_entries has a chance to add the size of the
5501 non-lazy PLT entries. */
5502 if (frvfdpic_plt_section (info
))
5504 if (frvfdpic_plt_section (info
)->size
== 0)
5505 frvfdpic_plt_section (info
)->flags
|= SEC_EXCLUDE
;
5506 else if (frvfdpic_plt_section (info
)->contents
== NULL
)
5508 frvfdpic_plt_section (info
)->contents
=
5509 (bfd_byte
*) bfd_zalloc (dynobj
,
5510 frvfdpic_plt_section (info
)->size
);
5511 if (frvfdpic_plt_section (info
)->contents
== NULL
)
5519 /* Set the sizes of the dynamic sections. */
5522 elf32_frvfdpic_size_dynamic_sections (bfd
*output_bfd
,
5523 struct bfd_link_info
*info
)
5527 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5529 dynobj
= elf_hash_table (info
)->dynobj
;
5530 BFD_ASSERT (dynobj
!= NULL
);
5532 if (elf_hash_table (info
)->dynamic_sections_created
)
5534 /* Set the contents of the .interp section to the interpreter. */
5535 if (info
->executable
)
5537 s
= bfd_get_section_by_name (dynobj
, ".interp");
5538 BFD_ASSERT (s
!= NULL
);
5539 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5540 s
->contents
= (bfd_byte
*) ELF_DYNAMIC_INTERPRETER
;
5544 memset (&gpinfo
, 0, sizeof (gpinfo
));
5545 gpinfo
.g
.info
= info
;
5549 htab_t relocs
= frvfdpic_relocs_info (info
);
5551 htab_traverse (relocs
, _frvfdpic_resolve_final_relocs_info
, &relocs
);
5553 if (relocs
== frvfdpic_relocs_info (info
))
5557 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_count_got_plt_entries
,
5560 /* Allocate space to save the summary information, we're going to
5561 use it if we're doing relaxations. */
5562 frvfdpic_dynamic_got_plt_info (info
) = bfd_alloc (dynobj
, sizeof (gpinfo
.g
));
5564 if (!_frvfdpic_size_got_plt (output_bfd
, &gpinfo
))
5567 if (elf_hash_table (info
)->dynamic_sections_created
)
5569 if (frvfdpic_got_section (info
)->size
)
5570 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTGOT
, 0))
5573 if (frvfdpic_pltrel_section (info
)->size
)
5574 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
5575 || !_bfd_elf_add_dynamic_entry (info
, DT_PLTREL
, DT_REL
)
5576 || !_bfd_elf_add_dynamic_entry (info
, DT_JMPREL
, 0))
5579 if (frvfdpic_gotrel_section (info
)->size
)
5580 if (!_bfd_elf_add_dynamic_entry (info
, DT_REL
, 0)
5581 || !_bfd_elf_add_dynamic_entry (info
, DT_RELSZ
, 0)
5582 || !_bfd_elf_add_dynamic_entry (info
, DT_RELENT
,
5583 sizeof (Elf32_External_Rel
)))
5591 elf32_frvfdpic_always_size_sections (bfd
*output_bfd
,
5592 struct bfd_link_info
*info
)
5594 if (!info
->relocatable
)
5596 struct elf_link_hash_entry
*h
;
5599 /* Force a PT_GNU_STACK segment to be created. */
5600 if (! elf_tdata (output_bfd
)->stack_flags
)
5601 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
| PF_X
;
5603 /* Define __stacksize if it's not defined yet. */
5604 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
5605 FALSE
, FALSE
, FALSE
);
5606 if (! h
|| h
->root
.type
!= bfd_link_hash_defined
5607 || h
->type
!= STT_OBJECT
5610 struct bfd_link_hash_entry
*bh
= NULL
;
5612 if (!(_bfd_generic_link_add_one_symbol
5613 (info
, output_bfd
, "__stacksize",
5614 BSF_GLOBAL
, bfd_abs_section_ptr
, DEFAULT_STACK_SIZE
,
5615 (const char *) NULL
, FALSE
,
5616 get_elf_backend_data (output_bfd
)->collect
, &bh
)))
5619 h
= (struct elf_link_hash_entry
*) bh
;
5621 h
->type
= STT_OBJECT
;
5622 /* This one must NOT be hidden. */
5625 /* Create a stack section, and set its alignment. */
5626 sec
= bfd_make_section (output_bfd
, ".stack");
5629 || ! bfd_set_section_alignment (output_bfd
, sec
, 3))
5636 /* Look for opportunities to relax TLS relocations. We can assume
5637 we're linking the main executable or a static-tls library, since
5638 otherwise we wouldn't have got here. */
5641 _frvfdpic_relax_got_plt_entries (void **entryp
, void *dinfo_
)
5643 struct frvfdpic_relocs_info
*entry
= *entryp
;
5644 struct _frvfdpic_dynamic_got_info
*dinfo
= dinfo_
;
5646 _frvfdpic_relax_tls_entries (entry
, dinfo
, TRUE
);
5652 elf32_frvfdpic_relax_section (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
,
5653 struct bfd_link_info
*info
, bfd_boolean
*again
)
5655 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5657 /* If we return early, we didn't change anything. */
5660 /* We'll do our thing when requested to relax the GOT section. */
5661 if (sec
!= frvfdpic_got_section (info
))
5664 /* We can only relax when linking the main executable or a library
5665 that can't be dlopened. */
5666 if (! info
->executable
&& ! (info
->flags
& DF_STATIC_TLS
))
5669 /* If there isn't a TLS section for this binary, we can't do
5670 anything about its TLS relocations (it probably doesn't have
5672 if (elf_hash_table (info
)->tls_sec
== NULL
)
5675 memset (&gpinfo
, 0, sizeof (gpinfo
));
5676 memcpy (&gpinfo
.g
, frvfdpic_dynamic_got_plt_info (info
), sizeof (gpinfo
.g
));
5678 /* Now look for opportunities to relax, adjusting the GOT usage
5680 htab_traverse (frvfdpic_relocs_info (info
),
5681 _frvfdpic_relax_got_plt_entries
,
5684 /* If we changed anything, reset and re-assign GOT and PLT entries. */
5685 if (memcmp (frvfdpic_dynamic_got_plt_info (info
),
5686 &gpinfo
.g
, sizeof (gpinfo
.g
)) != 0)
5688 /* Clear GOT and PLT assignments. */
5689 htab_traverse (frvfdpic_relocs_info (info
),
5690 _frvfdpic_reset_got_plt_entries
,
5693 /* The owner of the TLS section is the output bfd. There should
5694 be a better way to get to it. */
5695 if (!_frvfdpic_size_got_plt (elf_hash_table (info
)->tls_sec
->owner
,
5699 /* Repeat until we don't make any further changes. We could fail to
5700 introduce changes in a round if, for example, the 12-bit range is
5701 full, but we later release some space by getting rid of TLS
5702 descriptors in it. We have to repeat the whole process because
5703 we might have changed the size of a section processed before this
5712 elf32_frvfdpic_modify_segment_map (bfd
*output_bfd
,
5713 struct bfd_link_info
*info
)
5715 struct elf_segment_map
*m
;
5717 /* objcopy and strip preserve what's already there using
5718 elf32_frvfdpic_copy_private_bfd_data (). */
5722 for (m
= elf_tdata (output_bfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
5723 if (m
->p_type
== PT_GNU_STACK
)
5728 asection
*sec
= bfd_get_section_by_name (output_bfd
, ".stack");
5729 struct elf_link_hash_entry
*h
;
5733 /* Obtain the pointer to the __stacksize symbol. */
5734 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
5735 FALSE
, FALSE
, FALSE
);
5736 while (h
->root
.type
== bfd_link_hash_indirect
5737 || h
->root
.type
== bfd_link_hash_warning
)
5738 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
5739 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
5741 /* Set the section size from the symbol value. We
5742 intentionally ignore the symbol section. */
5743 if (h
->root
.type
== bfd_link_hash_defined
)
5744 sec
->size
= h
->root
.u
.def
.value
;
5746 sec
->size
= DEFAULT_STACK_SIZE
;
5748 /* Add the stack section to the PT_GNU_STACK segment,
5749 such that its size and alignment requirements make it
5751 m
->sections
[m
->count
] = sec
;
5759 /* Fill in code and data in dynamic sections. */
5762 elf32_frv_finish_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5763 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
5765 /* Nothing to be done for non-FDPIC. */
5770 elf32_frvfdpic_finish_dynamic_sections (bfd
*output_bfd
,
5771 struct bfd_link_info
*info
)
5776 dynobj
= elf_hash_table (info
)->dynobj
;
5778 if (frvfdpic_dynamic_got_plt_info (info
))
5780 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
== 0);
5782 if (frvfdpic_got_section (info
))
5784 BFD_ASSERT (frvfdpic_gotrel_section (info
)->size
5785 == (frvfdpic_gotrel_section (info
)->reloc_count
5786 * sizeof (Elf32_External_Rel
)));
5788 if (frvfdpic_gotfixup_section (info
))
5790 struct elf_link_hash_entry
*hgot
= elf_hash_table (info
)->hgot
;
5791 bfd_vma got_value
= hgot
->root
.u
.def
.value
5792 + hgot
->root
.u
.def
.section
->output_section
->vma
5793 + hgot
->root
.u
.def
.section
->output_offset
;
5794 struct bfd_link_hash_entry
*hend
;
5796 _frvfdpic_add_rofixup (output_bfd
, frvfdpic_gotfixup_section (info
),
5799 if (frvfdpic_gotfixup_section (info
)->size
5800 != (frvfdpic_gotfixup_section (info
)->reloc_count
* 4))
5803 (*_bfd_error_handler
)
5804 ("LINKER BUG: .rofixup section size mismatch");
5808 hend
= bfd_link_hash_lookup (info
->hash
, "__ROFIXUP_END__",
5809 FALSE
, FALSE
, TRUE
);
5811 && (hend
->type
== bfd_link_hash_defined
5812 || hend
->type
== bfd_link_hash_defweak
))
5815 frvfdpic_gotfixup_section (info
)->output_section
->vma
5816 + frvfdpic_gotfixup_section (info
)->output_offset
5817 + frvfdpic_gotfixup_section (info
)->size
5818 - hend
->u
.def
.section
->output_section
->vma
5819 - hend
->u
.def
.section
->output_offset
;
5820 BFD_ASSERT (hend
->u
.def
.value
== value
);
5821 if (hend
->u
.def
.value
!= value
)
5826 if (frvfdpic_pltrel_section (info
))
5828 BFD_ASSERT (frvfdpic_pltrel_section (info
)->size
5829 == (frvfdpic_pltrel_section (info
)->reloc_count
5830 * sizeof (Elf32_External_Rel
)));
5834 if (elf_hash_table (info
)->dynamic_sections_created
)
5836 Elf32_External_Dyn
* dyncon
;
5837 Elf32_External_Dyn
* dynconend
;
5839 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5841 BFD_ASSERT (sdyn
!= NULL
);
5843 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5844 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5846 for (; dyncon
< dynconend
; dyncon
++)
5848 Elf_Internal_Dyn dyn
;
5850 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5858 dyn
.d_un
.d_ptr
= frvfdpic_got_section (info
)->output_section
->vma
5859 + frvfdpic_got_section (info
)->output_offset
5860 + frvfdpic_got_initial_offset (info
);
5861 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5865 dyn
.d_un
.d_ptr
= frvfdpic_pltrel_section (info
)
5866 ->output_section
->vma
5867 + frvfdpic_pltrel_section (info
)->output_offset
;
5868 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5872 dyn
.d_un
.d_val
= frvfdpic_pltrel_section (info
)->size
;
5873 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5882 /* Adjust a symbol defined by a dynamic object and referenced by a
5886 elf32_frvfdpic_adjust_dynamic_symbol
5887 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5888 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
5892 dynobj
= elf_hash_table (info
)->dynobj
;
5894 /* Make sure we know what is going on here. */
5895 BFD_ASSERT (dynobj
!= NULL
5896 && (h
->u
.weakdef
!= NULL
5899 && !h
->def_regular
)));
5901 /* If this is a weak symbol, and there is a real definition, the
5902 processor independent code will have arranged for us to see the
5903 real definition first, and we can just use the same value. */
5904 if (h
->u
.weakdef
!= NULL
)
5906 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
5907 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
5908 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
5909 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
5915 /* Perform any actions needed for dynamic symbols. */
5918 elf32_frvfdpic_finish_dynamic_symbol
5919 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5920 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5921 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
,
5922 Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
)
5927 /* Decide whether to attempt to turn absptr or lsda encodings in
5928 shared libraries into pcrel within the given input section. */
5931 frvfdpic_elf_use_relative_eh_frame
5932 (bfd
*input_bfd ATTRIBUTE_UNUSED
,
5933 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5934 asection
*eh_frame_section ATTRIBUTE_UNUSED
)
5936 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
5940 /* Adjust the contents of an eh_frame_hdr section before they're output. */
5943 frvfdpic_elf_encode_eh_address (bfd
*abfd
,
5944 struct bfd_link_info
*info
,
5945 asection
*osec
, bfd_vma offset
,
5946 asection
*loc_sec
, bfd_vma loc_offset
,
5949 struct elf_link_hash_entry
*h
;
5951 h
= elf_hash_table (info
)->hgot
;
5952 BFD_ASSERT (h
&& h
->root
.type
== bfd_link_hash_defined
);
5954 if (! h
|| (_frvfdpic_osec_to_segment (abfd
, osec
)
5955 == _frvfdpic_osec_to_segment (abfd
, loc_sec
->output_section
)))
5956 return _bfd_elf_encode_eh_address (abfd
, info
, osec
, offset
,
5957 loc_sec
, loc_offset
, encoded
);
5959 BFD_ASSERT (_frvfdpic_osec_to_segment (abfd
, osec
)
5960 == (_frvfdpic_osec_to_segment
5961 (abfd
, h
->root
.u
.def
.section
->output_section
)));
5963 *encoded
= osec
->vma
+ offset
5964 - (h
->root
.u
.def
.value
5965 + h
->root
.u
.def
.section
->output_section
->vma
5966 + h
->root
.u
.def
.section
->output_offset
);
5968 return DW_EH_PE_datarel
| DW_EH_PE_sdata4
;
5971 /* Look through the relocs for a section during the first phase.
5973 Besides handling virtual table relocs for gc, we have to deal with
5974 all sorts of PIC-related relocations. We describe below the
5975 general plan on how to handle such relocations, even though we only
5976 collect information at this point, storing them in hash tables for
5977 perusal of later passes.
5979 32 relocations are propagated to the linker output when creating
5980 position-independent output. LO16 and HI16 relocations are not
5981 supposed to be encountered in this case.
5983 LABEL16 should always be resolvable by the linker, since it's only
5986 LABEL24, on the other hand, is used by calls. If it turns out that
5987 the target of a call is a dynamic symbol, a PLT entry must be
5988 created for it, which triggers the creation of a private function
5989 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
5991 GPREL relocations require the referenced symbol to be in the same
5992 segment as _gp, but this can only be checked later.
5994 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
5995 exist. LABEL24 might as well, since it may require a PLT entry,
5996 that will require a got.
5998 Non-FUNCDESC GOT relocations require a GOT entry to be created
5999 regardless of whether the symbol is dynamic. However, since a
6000 global symbol that turns out to not be exported may have the same
6001 address of a non-dynamic symbol, we don't assign GOT entries at
6002 this point, such that we can share them in this case. A relocation
6003 for the GOT entry always has to be created, be it to offset a
6004 private symbol by the section load address, be it to get the symbol
6005 resolved dynamically.
6007 FUNCDESC GOT relocations require a GOT entry to be created, and
6008 handled as if a FUNCDESC relocation was applied to the GOT entry in
6011 FUNCDESC relocations referencing a symbol that turns out to NOT be
6012 dynamic cause a private function descriptor to be created. The
6013 FUNCDESC relocation then decays to a 32 relocation that points at
6014 the private descriptor. If the symbol is dynamic, the FUNCDESC
6015 relocation is propagated to the linker output, such that the
6016 dynamic linker creates the canonical descriptor, pointing to the
6017 dynamically-resolved definition of the function.
6019 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
6020 symbols that are assigned to the same segment as the GOT, but we
6021 can only check this later, after we know the complete set of
6022 symbols defined and/or exported.
6024 FUNCDESC GOTOFF relocations require a function descriptor to be
6025 created and, unless lazy binding is disabled or the symbol is not
6026 dynamic, a lazy PLT entry. Since we can't tell at this point
6027 whether a symbol is going to be dynamic, we have to decide later
6028 whether to create a lazy PLT entry or bind the descriptor directly
6029 to the private function.
6031 FUNCDESC_VALUE relocations are not supposed to be present in object
6032 files, but they may very well be simply propagated to the linker
6033 output, since they have no side effect.
6036 A function descriptor always requires a FUNCDESC_VALUE relocation.
6037 Whether it's in .plt.rel or not depends on whether lazy binding is
6038 enabled and on whether the referenced symbol is dynamic.
6040 The existence of a lazy PLT requires the resolverStub lazy PLT
6041 entry to be present.
6044 As for assignment of GOT, PLT and lazy PLT entries, and private
6045 descriptors, we might do them all sequentially, but we can do
6046 better than that. For example, we can place GOT entries and
6047 private function descriptors referenced using 12-bit operands
6048 closer to the PIC register value, such that these relocations don't
6049 overflow. Those that are only referenced with LO16 relocations
6050 could come next, but we may as well place PLT-required function
6051 descriptors in the 12-bit range to make them shorter. Symbols
6052 referenced with LO16/HI16 may come next, but we may place
6053 additional function descriptors in the 16-bit range if we can
6054 reliably tell that we've already placed entries that are ever
6055 referenced with only LO16. PLT entries are therefore generated as
6056 small as possible, while not introducing relocation overflows in
6057 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
6058 generated before or after PLT entries, but not intermingled with
6059 them, such that we can have more lazy PLT entries in range for a
6060 branch to the resolverStub. The resolverStub should be emitted at
6061 the most distant location from the first lazy PLT entry such that
6062 it's still in range for a branch, or closer, if there isn't a need
6063 for so many lazy PLT entries. Additional lazy PLT entries may be
6064 emitted after the resolverStub, as long as branches are still in
6065 range. If the branch goes out of range, longer lazy PLT entries
6068 We could further optimize PLT and lazy PLT entries by giving them
6069 priority in assignment to closer-to-gr17 locations depending on the
6070 number of occurrences of references to them (assuming a function
6071 that's called more often is more important for performance, so its
6072 PLT entry should be faster), or taking hints from the compiler.
6073 Given infinite time and money... :-) */
6076 elf32_frv_check_relocs (abfd
, info
, sec
, relocs
)
6078 struct bfd_link_info
*info
;
6080 const Elf_Internal_Rela
*relocs
;
6082 Elf_Internal_Shdr
*symtab_hdr
;
6083 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
6084 const Elf_Internal_Rela
*rel
;
6085 const Elf_Internal_Rela
*rel_end
;
6087 struct frvfdpic_relocs_info
*picrel
;
6089 if (info
->relocatable
)
6092 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6093 sym_hashes
= elf_sym_hashes (abfd
);
6094 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof(Elf32_External_Sym
);
6095 if (!elf_bad_symtab (abfd
))
6096 sym_hashes_end
-= symtab_hdr
->sh_info
;
6098 dynobj
= elf_hash_table (info
)->dynobj
;
6099 rel_end
= relocs
+ sec
->reloc_count
;
6100 for (rel
= relocs
; rel
< rel_end
; rel
++)
6102 struct elf_link_hash_entry
*h
;
6103 unsigned long r_symndx
;
6105 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6106 if (r_symndx
< symtab_hdr
->sh_info
)
6110 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6111 while (h
->root
.type
== bfd_link_hash_indirect
6112 || h
->root
.type
== bfd_link_hash_warning
)
6113 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6116 switch (ELF32_R_TYPE (rel
->r_info
))
6118 case R_FRV_GETTLSOFF
:
6119 case R_FRV_TLSDESC_VALUE
:
6120 case R_FRV_GOTTLSDESC12
:
6121 case R_FRV_GOTTLSDESCHI
:
6122 case R_FRV_GOTTLSDESCLO
:
6123 case R_FRV_GOTTLSOFF12
:
6124 case R_FRV_GOTTLSOFFHI
:
6125 case R_FRV_GOTTLSOFFLO
:
6130 case R_FRV_FUNCDESC_GOT12
:
6131 case R_FRV_FUNCDESC_GOTHI
:
6132 case R_FRV_FUNCDESC_GOTLO
:
6133 case R_FRV_GOTOFF12
:
6134 case R_FRV_GOTOFFHI
:
6135 case R_FRV_GOTOFFLO
:
6136 case R_FRV_FUNCDESC_GOTOFF12
:
6137 case R_FRV_FUNCDESC_GOTOFFHI
:
6138 case R_FRV_FUNCDESC_GOTOFFLO
:
6139 case R_FRV_FUNCDESC
:
6140 case R_FRV_FUNCDESC_VALUE
:
6141 case R_FRV_TLSMOFF12
:
6142 case R_FRV_TLSMOFFHI
:
6143 case R_FRV_TLSMOFFLO
:
6145 if (! IS_FDPIC (abfd
))
6149 case R_FRV_GPRELU12
:
6156 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6157 if (! _frv_create_got_section (abfd
, info
))
6160 if (! IS_FDPIC (abfd
))
6167 if (h
->dynindx
== -1)
6168 switch (ELF_ST_VISIBILITY (h
->other
))
6174 bfd_elf_link_record_dynamic_symbol (info
, h
);
6178 = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info
),
6180 rel
->r_addend
, INSERT
);
6183 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
6184 (info
), abfd
, r_symndx
,
6185 rel
->r_addend
, INSERT
);
6195 switch (ELF32_R_TYPE (rel
->r_info
))
6198 if (IS_FDPIC (abfd
))
6202 case R_FRV_FUNCDESC_VALUE
:
6203 picrel
->relocsfdv
++;
6204 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
6209 if (! IS_FDPIC (abfd
))
6213 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
6223 picrel
->gothilo
= 1;
6226 case R_FRV_FUNCDESC_GOT12
:
6227 picrel
->fdgot12
= 1;
6230 case R_FRV_FUNCDESC_GOTHI
:
6231 case R_FRV_FUNCDESC_GOTLO
:
6232 picrel
->fdgothilo
= 1;
6235 case R_FRV_GOTOFF12
:
6236 case R_FRV_GOTOFFHI
:
6237 case R_FRV_GOTOFFLO
:
6241 case R_FRV_FUNCDESC_GOTOFF12
:
6242 picrel
->fdgoff12
= 1;
6245 case R_FRV_FUNCDESC_GOTOFFHI
:
6246 case R_FRV_FUNCDESC_GOTOFFLO
:
6247 picrel
->fdgoffhilo
= 1;
6250 case R_FRV_FUNCDESC
:
6255 case R_FRV_GETTLSOFF
:
6259 case R_FRV_TLSDESC_VALUE
:
6260 picrel
->relocstlsd
++;
6263 case R_FRV_GOTTLSDESC12
:
6264 picrel
->tlsdesc12
= 1;
6267 case R_FRV_GOTTLSDESCHI
:
6268 case R_FRV_GOTTLSDESCLO
:
6269 picrel
->tlsdeschilo
= 1;
6272 case R_FRV_TLSMOFF12
:
6273 case R_FRV_TLSMOFFHI
:
6274 case R_FRV_TLSMOFFLO
:
6278 case R_FRV_GOTTLSOFF12
:
6279 picrel
->tlsoff12
= 1;
6280 info
->flags
|= DF_STATIC_TLS
;
6283 case R_FRV_GOTTLSOFFHI
:
6284 case R_FRV_GOTTLSOFFLO
:
6285 picrel
->tlsoffhilo
= 1;
6286 info
->flags
|= DF_STATIC_TLS
;
6290 picrel
->relocstlsoff
++;
6291 info
->flags
|= DF_STATIC_TLS
;
6294 /* This relocation describes the C++ object vtable hierarchy.
6295 Reconstruct it for later use during GC. */
6296 case R_FRV_GNU_VTINHERIT
:
6297 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6301 /* This relocation describes which C++ vtable entries are actually
6302 used. Record for later use during GC. */
6303 case R_FRV_GNU_VTENTRY
:
6304 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
6312 case R_FRV_GPRELU12
:
6316 case R_FRV_TLSDESC_RELAX
:
6317 case R_FRV_GETTLSOFF_RELAX
:
6318 case R_FRV_TLSOFF_RELAX
:
6323 (*_bfd_error_handler
)
6324 (_("%B: unsupported relocation type %i"),
6325 abfd
, ELF32_R_TYPE (rel
->r_info
));
6334 /* Return the machine subcode from the ELF e_flags header. */
6337 elf32_frv_machine (abfd
)
6340 switch (elf_elfheader (abfd
)->e_flags
& EF_FRV_CPU_MASK
)
6343 case EF_FRV_CPU_FR550
: return bfd_mach_fr550
;
6344 case EF_FRV_CPU_FR500
: return bfd_mach_fr500
;
6345 case EF_FRV_CPU_FR450
: return bfd_mach_fr450
;
6346 case EF_FRV_CPU_FR405
: return bfd_mach_fr400
;
6347 case EF_FRV_CPU_FR400
: return bfd_mach_fr400
;
6348 case EF_FRV_CPU_FR300
: return bfd_mach_fr300
;
6349 case EF_FRV_CPU_SIMPLE
: return bfd_mach_frvsimple
;
6350 case EF_FRV_CPU_TOMCAT
: return bfd_mach_frvtomcat
;
6353 return bfd_mach_frv
;
6356 /* Set the right machine number for a FRV ELF file. */
6359 elf32_frv_object_p (abfd
)
6362 bfd_default_set_arch_mach (abfd
, bfd_arch_frv
, elf32_frv_machine (abfd
));
6363 return (((elf_elfheader (abfd
)->e_flags
& EF_FRV_FDPIC
) != 0)
6364 == (IS_FDPIC (abfd
)));
6367 /* Function to set the ELF flag bits. */
6370 frv_elf_set_private_flags (abfd
, flags
)
6374 elf_elfheader (abfd
)->e_flags
= flags
;
6375 elf_flags_init (abfd
) = TRUE
;
6379 /* Copy backend specific data from one object module to another. */
6382 frv_elf_copy_private_bfd_data (ibfd
, obfd
)
6386 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6387 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6390 BFD_ASSERT (!elf_flags_init (obfd
)
6391 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
6393 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
6394 elf_flags_init (obfd
) = TRUE
;
6398 /* Return true if the architecture described by elf header flag
6399 EXTENSION is an extension of the architecture described by BASE. */
6402 frv_elf_arch_extension_p (flagword base
, flagword extension
)
6404 if (base
== extension
)
6407 /* CPU_GENERIC code can be merged with code for a specific
6408 architecture, in which case the result is marked as being
6409 for the specific architecture. Everything is therefore
6410 an extension of CPU_GENERIC. */
6411 if (base
== EF_FRV_CPU_GENERIC
)
6414 if (extension
== EF_FRV_CPU_FR450
)
6415 if (base
== EF_FRV_CPU_FR400
|| base
== EF_FRV_CPU_FR405
)
6418 if (extension
== EF_FRV_CPU_FR405
)
6419 if (base
== EF_FRV_CPU_FR400
)
6426 elf32_frvfdpic_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
6430 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6431 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6434 if (! frv_elf_copy_private_bfd_data (ibfd
, obfd
))
6437 if (! elf_tdata (ibfd
) || ! elf_tdata (ibfd
)->phdr
6438 || ! elf_tdata (obfd
) || ! elf_tdata (obfd
)->phdr
)
6441 /* Copy the stack size. */
6442 for (i
= 0; i
< elf_elfheader (ibfd
)->e_phnum
; i
++)
6443 if (elf_tdata (ibfd
)->phdr
[i
].p_type
== PT_GNU_STACK
)
6445 Elf_Internal_Phdr
*iphdr
= &elf_tdata (ibfd
)->phdr
[i
];
6447 for (i
= 0; i
< elf_elfheader (obfd
)->e_phnum
; i
++)
6448 if (elf_tdata (obfd
)->phdr
[i
].p_type
== PT_GNU_STACK
)
6450 memcpy (&elf_tdata (obfd
)->phdr
[i
], iphdr
, sizeof (*iphdr
));
6452 /* Rewrite the phdrs, since we're only called after they
6453 were first written. */
6454 if (bfd_seek (obfd
, (bfd_signed_vma
) get_elf_backend_data (obfd
)
6455 ->s
->sizeof_ehdr
, SEEK_SET
) != 0
6456 || get_elf_backend_data (obfd
)->s
6457 ->write_out_phdrs (obfd
, elf_tdata (obfd
)->phdr
,
6458 elf_elfheader (obfd
)->e_phnum
) != 0)
6469 /* Merge backend specific data from an object file to the output
6470 object file when linking. */
6473 frv_elf_merge_private_bfd_data (ibfd
, obfd
)
6477 flagword old_flags
, old_partial
;
6478 flagword new_flags
, new_partial
;
6479 bfd_boolean error
= FALSE
;
6483 new_opt
[0] = old_opt
[0] = '\0';
6484 new_flags
= elf_elfheader (ibfd
)->e_flags
;
6485 old_flags
= elf_elfheader (obfd
)->e_flags
;
6487 if (new_flags
& EF_FRV_FDPIC
)
6488 new_flags
&= ~EF_FRV_PIC
;
6491 (*_bfd_error_handler
) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s",
6492 old_flags
, new_flags
, elf_flags_init (obfd
) ? "yes" : "no",
6493 bfd_get_filename (ibfd
));
6496 if (!elf_flags_init (obfd
)) /* First call, no flags set. */
6498 elf_flags_init (obfd
) = TRUE
;
6499 old_flags
= new_flags
;
6502 else if (new_flags
== old_flags
) /* Compatible flags are ok. */
6505 else /* Possibly incompatible flags. */
6507 /* Warn if different # of gprs are used. Note, 0 means nothing is
6508 said about the size of gprs. */
6509 new_partial
= (new_flags
& EF_FRV_GPR_MASK
);
6510 old_partial
= (old_flags
& EF_FRV_GPR_MASK
);
6511 if (new_partial
== old_partial
)
6514 else if (new_partial
== 0)
6517 else if (old_partial
== 0)
6518 old_flags
|= new_partial
;
6522 switch (new_partial
)
6524 default: strcat (new_opt
, " -mgpr-??"); break;
6525 case EF_FRV_GPR_32
: strcat (new_opt
, " -mgpr-32"); break;
6526 case EF_FRV_GPR_64
: strcat (new_opt
, " -mgpr-64"); break;
6529 switch (old_partial
)
6531 default: strcat (old_opt
, " -mgpr-??"); break;
6532 case EF_FRV_GPR_32
: strcat (old_opt
, " -mgpr-32"); break;
6533 case EF_FRV_GPR_64
: strcat (old_opt
, " -mgpr-64"); break;
6537 /* Warn if different # of fprs are used. Note, 0 means nothing is
6538 said about the size of fprs. */
6539 new_partial
= (new_flags
& EF_FRV_FPR_MASK
);
6540 old_partial
= (old_flags
& EF_FRV_FPR_MASK
);
6541 if (new_partial
== old_partial
)
6544 else if (new_partial
== 0)
6547 else if (old_partial
== 0)
6548 old_flags
|= new_partial
;
6552 switch (new_partial
)
6554 default: strcat (new_opt
, " -mfpr-?"); break;
6555 case EF_FRV_FPR_32
: strcat (new_opt
, " -mfpr-32"); break;
6556 case EF_FRV_FPR_64
: strcat (new_opt
, " -mfpr-64"); break;
6557 case EF_FRV_FPR_NONE
: strcat (new_opt
, " -msoft-float"); break;
6560 switch (old_partial
)
6562 default: strcat (old_opt
, " -mfpr-?"); break;
6563 case EF_FRV_FPR_32
: strcat (old_opt
, " -mfpr-32"); break;
6564 case EF_FRV_FPR_64
: strcat (old_opt
, " -mfpr-64"); break;
6565 case EF_FRV_FPR_NONE
: strcat (old_opt
, " -msoft-float"); break;
6569 /* Warn if different dword support was used. Note, 0 means nothing is
6570 said about the dword support. */
6571 new_partial
= (new_flags
& EF_FRV_DWORD_MASK
);
6572 old_partial
= (old_flags
& EF_FRV_DWORD_MASK
);
6573 if (new_partial
== old_partial
)
6576 else if (new_partial
== 0)
6579 else if (old_partial
== 0)
6580 old_flags
|= new_partial
;
6584 switch (new_partial
)
6586 default: strcat (new_opt
, " -mdword-?"); break;
6587 case EF_FRV_DWORD_YES
: strcat (new_opt
, " -mdword"); break;
6588 case EF_FRV_DWORD_NO
: strcat (new_opt
, " -mno-dword"); break;
6591 switch (old_partial
)
6593 default: strcat (old_opt
, " -mdword-?"); break;
6594 case EF_FRV_DWORD_YES
: strcat (old_opt
, " -mdword"); break;
6595 case EF_FRV_DWORD_NO
: strcat (old_opt
, " -mno-dword"); break;
6599 /* Or in flags that accumulate (ie, if one module uses it, mark that the
6601 old_flags
|= new_flags
& (EF_FRV_DOUBLE
6604 | EF_FRV_NON_PIC_RELOCS
);
6606 /* If any module was compiled without -G0, clear the G0 bit. */
6607 old_flags
= ((old_flags
& ~ EF_FRV_G0
)
6608 | (old_flags
& new_flags
& EF_FRV_G0
));
6610 /* If any module was compiled without -mnopack, clear the mnopack bit. */
6611 old_flags
= ((old_flags
& ~ EF_FRV_NOPACK
)
6612 | (old_flags
& new_flags
& EF_FRV_NOPACK
));
6614 /* We don't have to do anything if the pic flags are the same, or the new
6615 module(s) were compiled with -mlibrary-pic. */
6616 new_partial
= (new_flags
& EF_FRV_PIC_FLAGS
);
6617 old_partial
= (old_flags
& EF_FRV_PIC_FLAGS
);
6618 if ((new_partial
== old_partial
) || ((new_partial
& EF_FRV_LIBPIC
) != 0))
6621 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
6622 flags if any from the new module. */
6623 else if ((old_partial
& EF_FRV_LIBPIC
) != 0)
6624 old_flags
= (old_flags
& ~ EF_FRV_PIC_FLAGS
) | new_partial
;
6626 /* If we have mixtures of -fpic and -fPIC, or in both bits. */
6627 else if (new_partial
!= 0 && old_partial
!= 0)
6628 old_flags
|= new_partial
;
6630 /* One module was compiled for pic and the other was not, see if we have
6631 had any relocations that are not pic-safe. */
6634 if ((old_flags
& EF_FRV_NON_PIC_RELOCS
) == 0)
6635 old_flags
|= new_partial
;
6638 old_flags
&= ~ EF_FRV_PIC_FLAGS
;
6639 #ifndef FRV_NO_PIC_ERROR
6641 (*_bfd_error_handler
)
6642 (_("%s: compiled with %s and linked with modules that use non-pic relocations"),
6643 bfd_get_filename (ibfd
),
6644 (new_flags
& EF_FRV_BIGPIC
) ? "-fPIC" : "-fpic");
6649 /* Warn if different cpu is used (allow a specific cpu to override
6650 the generic cpu). */
6651 new_partial
= (new_flags
& EF_FRV_CPU_MASK
);
6652 old_partial
= (old_flags
& EF_FRV_CPU_MASK
);
6653 if (frv_elf_arch_extension_p (new_partial
, old_partial
))
6656 else if (frv_elf_arch_extension_p (old_partial
, new_partial
))
6657 old_flags
= (old_flags
& ~EF_FRV_CPU_MASK
) | new_partial
;
6661 switch (new_partial
)
6663 default: strcat (new_opt
, " -mcpu=?"); break;
6664 case EF_FRV_CPU_GENERIC
: strcat (new_opt
, " -mcpu=frv"); break;
6665 case EF_FRV_CPU_SIMPLE
: strcat (new_opt
, " -mcpu=simple"); break;
6666 case EF_FRV_CPU_FR550
: strcat (new_opt
, " -mcpu=fr550"); break;
6667 case EF_FRV_CPU_FR500
: strcat (new_opt
, " -mcpu=fr500"); break;
6668 case EF_FRV_CPU_FR450
: strcat (new_opt
, " -mcpu=fr450"); break;
6669 case EF_FRV_CPU_FR405
: strcat (new_opt
, " -mcpu=fr405"); break;
6670 case EF_FRV_CPU_FR400
: strcat (new_opt
, " -mcpu=fr400"); break;
6671 case EF_FRV_CPU_FR300
: strcat (new_opt
, " -mcpu=fr300"); break;
6672 case EF_FRV_CPU_TOMCAT
: strcat (new_opt
, " -mcpu=tomcat"); break;
6675 switch (old_partial
)
6677 default: strcat (old_opt
, " -mcpu=?"); break;
6678 case EF_FRV_CPU_GENERIC
: strcat (old_opt
, " -mcpu=frv"); break;
6679 case EF_FRV_CPU_SIMPLE
: strcat (old_opt
, " -mcpu=simple"); break;
6680 case EF_FRV_CPU_FR550
: strcat (old_opt
, " -mcpu=fr550"); break;
6681 case EF_FRV_CPU_FR500
: strcat (old_opt
, " -mcpu=fr500"); break;
6682 case EF_FRV_CPU_FR450
: strcat (old_opt
, " -mcpu=fr450"); break;
6683 case EF_FRV_CPU_FR405
: strcat (old_opt
, " -mcpu=fr405"); break;
6684 case EF_FRV_CPU_FR400
: strcat (old_opt
, " -mcpu=fr400"); break;
6685 case EF_FRV_CPU_FR300
: strcat (old_opt
, " -mcpu=fr300"); break;
6686 case EF_FRV_CPU_TOMCAT
: strcat (old_opt
, " -mcpu=tomcat"); break;
6690 /* Print out any mismatches from above. */
6694 (*_bfd_error_handler
)
6695 (_("%s: compiled with %s and linked with modules compiled with %s"),
6696 bfd_get_filename (ibfd
), new_opt
, old_opt
);
6699 /* Warn about any other mismatches */
6700 new_partial
= (new_flags
& ~ EF_FRV_ALL_FLAGS
);
6701 old_partial
= (old_flags
& ~ EF_FRV_ALL_FLAGS
);
6702 if (new_partial
!= old_partial
)
6704 old_flags
|= new_partial
;
6706 (*_bfd_error_handler
)
6707 (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"),
6708 bfd_get_filename (ibfd
), (long)new_partial
, (long)old_partial
);
6712 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
6713 if ((old_flags
& EF_FRV_CPU_MASK
) == EF_FRV_CPU_SIMPLE
)
6714 old_flags
|= EF_FRV_NOPACK
;
6716 /* Update the old flags now with changes made above. */
6717 old_partial
= elf_elfheader (obfd
)->e_flags
& EF_FRV_CPU_MASK
;
6718 elf_elfheader (obfd
)->e_flags
= old_flags
;
6719 if (old_partial
!= (old_flags
& EF_FRV_CPU_MASK
))
6720 bfd_default_set_arch_mach (obfd
, bfd_arch_frv
, elf32_frv_machine (obfd
));
6722 if (((new_flags
& EF_FRV_FDPIC
) == 0)
6723 != (! IS_FDPIC (ibfd
)))
6726 if (IS_FDPIC (obfd
))
6727 (*_bfd_error_handler
)
6728 (_("%s: cannot link non-fdpic object file into fdpic executable"),
6729 bfd_get_filename (ibfd
));
6731 (*_bfd_error_handler
)
6732 (_("%s: cannot link fdpic object file into non-fdpic executable"),
6733 bfd_get_filename (ibfd
));
6737 bfd_set_error (bfd_error_bad_value
);
6744 frv_elf_print_private_bfd_data (abfd
, ptr
)
6748 FILE *file
= (FILE *) ptr
;
6751 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6753 /* Print normal ELF private data. */
6754 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6756 flags
= elf_elfheader (abfd
)->e_flags
;
6757 fprintf (file
, _("private flags = 0x%lx:"), (long)flags
);
6759 switch (flags
& EF_FRV_CPU_MASK
)
6762 case EF_FRV_CPU_SIMPLE
: fprintf (file
, " -mcpu=simple"); break;
6763 case EF_FRV_CPU_FR550
: fprintf (file
, " -mcpu=fr550"); break;
6764 case EF_FRV_CPU_FR500
: fprintf (file
, " -mcpu=fr500"); break;
6765 case EF_FRV_CPU_FR450
: fprintf (file
, " -mcpu=fr450"); break;
6766 case EF_FRV_CPU_FR405
: fprintf (file
, " -mcpu=fr405"); break;
6767 case EF_FRV_CPU_FR400
: fprintf (file
, " -mcpu=fr400"); break;
6768 case EF_FRV_CPU_FR300
: fprintf (file
, " -mcpu=fr300"); break;
6769 case EF_FRV_CPU_TOMCAT
: fprintf (file
, " -mcpu=tomcat"); break;
6772 switch (flags
& EF_FRV_GPR_MASK
)
6775 case EF_FRV_GPR_32
: fprintf (file
, " -mgpr-32"); break;
6776 case EF_FRV_GPR_64
: fprintf (file
, " -mgpr-64"); break;
6779 switch (flags
& EF_FRV_FPR_MASK
)
6782 case EF_FRV_FPR_32
: fprintf (file
, " -mfpr-32"); break;
6783 case EF_FRV_FPR_64
: fprintf (file
, " -mfpr-64"); break;
6784 case EF_FRV_FPR_NONE
: fprintf (file
, " -msoft-float"); break;
6787 switch (flags
& EF_FRV_DWORD_MASK
)
6790 case EF_FRV_DWORD_YES
: fprintf (file
, " -mdword"); break;
6791 case EF_FRV_DWORD_NO
: fprintf (file
, " -mno-dword"); break;
6794 if (flags
& EF_FRV_DOUBLE
)
6795 fprintf (file
, " -mdouble");
6797 if (flags
& EF_FRV_MEDIA
)
6798 fprintf (file
, " -mmedia");
6800 if (flags
& EF_FRV_MULADD
)
6801 fprintf (file
, " -mmuladd");
6803 if (flags
& EF_FRV_PIC
)
6804 fprintf (file
, " -fpic");
6806 if (flags
& EF_FRV_BIGPIC
)
6807 fprintf (file
, " -fPIC");
6809 if (flags
& EF_FRV_LIBPIC
)
6810 fprintf (file
, " -mlibrary-pic");
6812 if (flags
& EF_FRV_FDPIC
)
6813 fprintf (file
, " -mfdpic");
6815 if (flags
& EF_FRV_NON_PIC_RELOCS
)
6816 fprintf (file
, " non-pic relocations");
6818 if (flags
& EF_FRV_G0
)
6819 fprintf (file
, " -G0");
6826 #define ELF_ARCH bfd_arch_frv
6827 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
6828 #define ELF_MAXPAGESIZE 0x1000
6830 #define TARGET_BIG_SYM bfd_elf32_frv_vec
6831 #define TARGET_BIG_NAME "elf32-frv"
6833 #define elf_info_to_howto frv_info_to_howto_rela
6834 #define elf_backend_relocate_section elf32_frv_relocate_section
6835 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
6836 #define elf_backend_gc_sweep_hook elf32_frv_gc_sweep_hook
6837 #define elf_backend_check_relocs elf32_frv_check_relocs
6838 #define elf_backend_object_p elf32_frv_object_p
6839 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
6841 #define elf_backend_can_gc_sections 1
6842 #define elf_backend_rela_normal 1
6844 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
6845 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
6846 #define bfd_elf32_bfd_copy_private_bfd_data frv_elf_copy_private_bfd_data
6847 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
6848 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
6850 #define elf_backend_want_got_sym 1
6851 #define elf_backend_got_header_size 0
6852 #define elf_backend_want_got_plt 0
6853 #define elf_backend_plt_readonly 1
6854 #define elf_backend_want_plt_sym 0
6855 #define elf_backend_plt_header_size 0
6857 #define elf_backend_finish_dynamic_sections \
6858 elf32_frv_finish_dynamic_sections
6860 #include "elf32-target.h"
6862 #undef ELF_MAXPAGESIZE
6863 #define ELF_MAXPAGESIZE 0x4000
6865 #undef TARGET_BIG_SYM
6866 #define TARGET_BIG_SYM bfd_elf32_frvfdpic_vec
6867 #undef TARGET_BIG_NAME
6868 #define TARGET_BIG_NAME "elf32-frvfdpic"
6870 #define elf32_bed elf32_frvfdpic_bed
6872 #undef elf_info_to_howto_rel
6873 #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel
6875 #undef bfd_elf32_bfd_link_hash_table_create
6876 #define bfd_elf32_bfd_link_hash_table_create \
6877 frvfdpic_elf_link_hash_table_create
6878 #undef elf_backend_always_size_sections
6879 #define elf_backend_always_size_sections \
6880 elf32_frvfdpic_always_size_sections
6881 #undef elf_backend_modify_segment_map
6882 #define elf_backend_modify_segment_map \
6883 elf32_frvfdpic_modify_segment_map
6884 #undef bfd_elf32_bfd_copy_private_bfd_data
6885 #define bfd_elf32_bfd_copy_private_bfd_data \
6886 elf32_frvfdpic_copy_private_bfd_data
6888 #undef elf_backend_create_dynamic_sections
6889 #define elf_backend_create_dynamic_sections \
6890 elf32_frvfdpic_create_dynamic_sections
6891 #undef elf_backend_adjust_dynamic_symbol
6892 #define elf_backend_adjust_dynamic_symbol \
6893 elf32_frvfdpic_adjust_dynamic_symbol
6894 #undef elf_backend_size_dynamic_sections
6895 #define elf_backend_size_dynamic_sections \
6896 elf32_frvfdpic_size_dynamic_sections
6897 #undef bfd_elf32_bfd_relax_section
6898 #define bfd_elf32_bfd_relax_section \
6899 elf32_frvfdpic_relax_section
6900 #undef elf_backend_finish_dynamic_symbol
6901 #define elf_backend_finish_dynamic_symbol \
6902 elf32_frvfdpic_finish_dynamic_symbol
6903 #undef elf_backend_finish_dynamic_sections
6904 #define elf_backend_finish_dynamic_sections \
6905 elf32_frvfdpic_finish_dynamic_sections
6907 #undef elf_backend_can_make_relative_eh_frame
6908 #define elf_backend_can_make_relative_eh_frame \
6909 frvfdpic_elf_use_relative_eh_frame
6910 #undef elf_backend_can_make_lsda_relative_eh_frame
6911 #define elf_backend_can_make_lsda_relative_eh_frame \
6912 frvfdpic_elf_use_relative_eh_frame
6913 #undef elf_backend_encode_eh_address
6914 #define elf_backend_encode_eh_address \
6915 frvfdpic_elf_encode_eh_address
6917 #undef elf_backend_may_use_rel_p
6918 #define elf_backend_may_use_rel_p 1
6919 #undef elf_backend_may_use_rela_p
6920 #define elf_backend_may_use_rela_p 1
6921 /* We use REL for dynamic relocations only. */
6922 #undef elf_backend_default_use_rela_p
6923 #define elf_backend_default_use_rela_p 1
6925 #undef elf_backend_omit_section_dynsym
6926 #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym
6928 #include "elf32-target.h"