1 /* FRV-specific support for 32-bit ELF.
2 Copyright 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
27 #include "elf/dwarf2.h"
30 /* Forward declarations. */
31 static bfd_reloc_status_type elf32_frv_relocate_lo16
32 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
33 static bfd_reloc_status_type elf32_frv_relocate_hi16
34 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
35 static bfd_reloc_status_type elf32_frv_relocate_label24
36 PARAMS ((bfd
*, asection
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
37 static bfd_reloc_status_type elf32_frv_relocate_gprel12
38 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
39 bfd_byte
*, bfd_vma
));
40 static bfd_reloc_status_type elf32_frv_relocate_gprelu12
41 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
42 bfd_byte
*, bfd_vma
));
43 static bfd_reloc_status_type elf32_frv_relocate_gprello
44 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
45 bfd_byte
*, bfd_vma
));
46 static bfd_reloc_status_type elf32_frv_relocate_gprelhi
47 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
48 bfd_byte
*, bfd_vma
));
49 static reloc_howto_type
*frv_reloc_type_lookup
50 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
51 static void frv_info_to_howto_rela
52 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
53 static bfd_boolean elf32_frv_relocate_section
54 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
55 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
56 static bfd_boolean elf32_frv_add_symbol_hook
57 PARAMS (( bfd
*, struct bfd_link_info
*, Elf_Internal_Sym
*,
58 const char **, flagword
*, asection
**, bfd_vma
*));
59 static bfd_reloc_status_type frv_final_link_relocate
60 PARAMS ((reloc_howto_type
*, bfd
*, asection
*, bfd_byte
*,
61 Elf_Internal_Rela
*, bfd_vma
));
62 static bfd_boolean elf32_frv_check_relocs
63 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
64 const Elf_Internal_Rela
*));
65 static int elf32_frv_machine
67 static bfd_boolean elf32_frv_object_p
69 static bfd_boolean frv_elf_set_private_flags
70 PARAMS ((bfd
*, flagword
));
71 static bfd_boolean frv_elf_copy_private_bfd_data
72 PARAMS ((bfd
*, bfd
*));
73 static bfd_boolean frv_elf_merge_private_bfd_data
74 PARAMS ((bfd
*, bfd
*));
75 static bfd_boolean frv_elf_print_private_bfd_data
76 PARAMS ((bfd
*, PTR
));
77 static bfd_boolean
elf32_frv_grok_prstatus (bfd
* abfd
,
78 Elf_Internal_Note
* note
);
79 static bfd_boolean
elf32_frv_grok_psinfo (bfd
* abfd
,
80 Elf_Internal_Note
* note
);
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
,
1009 sizeof (struct elf_link_hash_entry
)))
1015 return &ret
->elf
.root
;
1018 /* Decide whether a reference to a symbol can be resolved locally or
1019 not. If the symbol is protected, we want the local address, but
1020 its function descriptor must be assigned by the dynamic linker. */
1021 #define FRVFDPIC_SYM_LOCAL(INFO, H) \
1022 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
1023 || ! elf_hash_table (INFO)->dynamic_sections_created)
1024 #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \
1025 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
1027 /* This structure collects information on what kind of GOT, PLT or
1028 function descriptors are required by relocations that reference a
1030 struct frvfdpic_relocs_info
1032 /* The index of the symbol, as stored in the relocation r_info, if
1033 we have a local symbol; -1 otherwise. */
1037 /* The input bfd in which the symbol is defined, if it's a local
1040 /* If symndx == -1, the hash table entry corresponding to a global
1041 symbol (even if it turns out to bind locally, in which case it
1042 should ideally be replaced with section's symndx + addend). */
1043 struct elf_link_hash_entry
*h
;
1045 /* The addend of the relocation that references the symbol. */
1048 /* The fields above are used to identify an entry. The fields below
1049 contain information on how an entry is used and, later on, which
1050 locations it was assigned. */
1051 /* The following 3 fields record whether the symbol+addend above was
1052 ever referenced with a GOT relocation. The 12 suffix indicates a
1053 GOT12 relocation; los is used for GOTLO relocations that are not
1054 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
1059 /* Whether a FUNCDESC relocation references symbol+addend. */
1061 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
1063 unsigned fdgotlos
:1;
1064 unsigned fdgothilo
:1;
1065 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
1066 unsigned fdgoff12
:1;
1067 unsigned fdgofflos
:1;
1068 unsigned fdgoffhilo
:1;
1069 /* Whether a GETTLSOFF relocation references symbol+addend. */
1071 /* FIXME: we should probably add tlspltdesc, tlspltoff and
1072 tlspltimm, to tell what kind of TLS PLT entry we're generating.
1073 We might instead just pre-compute flags telling whether the
1074 object is suitable for local exec, initial exec or general
1075 dynamic addressing, and use that all over the place. We could
1076 also try to do a better job of merging TLSOFF and TLSDESC entries
1077 in main executables, but perhaps we can get rid of TLSDESC
1078 entirely in them instead. */
1079 /* Whether a GOTTLSDESC relocation references symbol+addend. */
1080 unsigned tlsdesc12
:1;
1081 unsigned tlsdesclos
:1;
1082 unsigned tlsdeschilo
:1;
1083 /* Whether a GOTTLSOFF relocation references symbol+addend. */
1084 unsigned tlsoff12
:1;
1085 unsigned tlsofflos
:1;
1086 unsigned tlsoffhilo
:1;
1087 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
1088 GOTOFFHI relocations. The addend doesn't really matter, since we
1089 envision that this will only be used to check whether the symbol
1090 is mapped to the same segment as the got. */
1092 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
1094 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
1097 /* Whether we need a PLT entry for a symbol. Should be implied by
1099 (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */
1101 /* Whether a function descriptor should be created in this link unit
1102 for symbol+addend. Should be implied by something like:
1103 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
1104 || ((fd || fdgot12 || fdgotlos || fdgothilo)
1105 && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */
1107 /* Whether a lazy PLT entry is needed for this symbol+addend.
1108 Should be implied by something like:
1109 (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)
1110 && ! (info->flags & DF_BIND_NOW)) */
1112 /* Whether we've already emitted GOT relocations and PLT entries as
1113 needed for this symbol. */
1116 /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and
1117 R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing
1119 unsigned relocs32
, relocsfd
, relocsfdv
, relocstlsd
, relocstlsoff
;
1121 /* The number of .rofixups entries and dynamic relocations allocated
1122 for this symbol, minus any that might have already been used. */
1123 unsigned fixups
, dynrelocs
;
1125 /* The offsets of the GOT entries assigned to symbol+addend, to the
1126 function descriptor's address, and to a function descriptor,
1127 respectively. Should be zero if unassigned. The offsets are
1128 counted from the value that will be assigned to the PIC register,
1129 not from the beginning of the .got section. */
1130 bfd_signed_vma got_entry
, fdgot_entry
, fd_entry
;
1131 /* The offsets of the PLT entries assigned to symbol+addend,
1132 non-lazy and lazy, respectively. If unassigned, should be
1134 bfd_vma plt_entry
, lzplt_entry
;
1135 /* The offsets of the GOT entries for TLS offset and TLS descriptor. */
1136 bfd_signed_vma tlsoff_entry
, tlsdesc_entry
;
1137 /* The offset of the TLS offset PLT entry. */
1138 bfd_vma tlsplt_entry
;
1141 /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */
1143 frvfdpic_relocs_info_hash (const void *entry_
)
1145 const struct frvfdpic_relocs_info
*entry
= entry_
;
1147 return (entry
->symndx
== -1
1148 ? (long) entry
->d
.h
->root
.root
.hash
1149 : entry
->symndx
+ (long) entry
->d
.abfd
->id
* 257) + entry
->addend
;
1152 /* Test whether the key fields of two frvfdpic_relocs_info entries are
1155 frvfdpic_relocs_info_eq (const void *entry1
, const void *entry2
)
1157 const struct frvfdpic_relocs_info
*e1
= entry1
;
1158 const struct frvfdpic_relocs_info
*e2
= entry2
;
1160 return e1
->symndx
== e2
->symndx
&& e1
->addend
== e2
->addend
1161 && (e1
->symndx
== -1 ? e1
->d
.h
== e2
->d
.h
: e1
->d
.abfd
== e2
->d
.abfd
);
1164 /* Find or create an entry in a hash table HT that matches the key
1165 fields of the given ENTRY. If it's not found, memory for a new
1166 entry is allocated in ABFD's obstack. */
1167 static struct frvfdpic_relocs_info
*
1168 frvfdpic_relocs_info_find (struct htab
*ht
,
1170 const struct frvfdpic_relocs_info
*entry
,
1171 enum insert_option insert
)
1173 struct frvfdpic_relocs_info
**loc
=
1174 (struct frvfdpic_relocs_info
**) htab_find_slot (ht
, entry
, insert
);
1182 *loc
= bfd_zalloc (abfd
, sizeof (**loc
));
1187 (*loc
)->symndx
= entry
->symndx
;
1188 (*loc
)->d
= entry
->d
;
1189 (*loc
)->addend
= entry
->addend
;
1190 (*loc
)->plt_entry
= (bfd_vma
)-1;
1191 (*loc
)->lzplt_entry
= (bfd_vma
)-1;
1192 (*loc
)->tlsplt_entry
= (bfd_vma
)-1;
1197 /* Obtain the address of the entry in HT associated with H's symbol +
1198 addend, creating a new entry if none existed. ABFD is only used
1199 for memory allocation purposes. */
1200 inline static struct frvfdpic_relocs_info
*
1201 frvfdpic_relocs_info_for_global (struct htab
*ht
,
1203 struct elf_link_hash_entry
*h
,
1205 enum insert_option insert
)
1207 struct frvfdpic_relocs_info entry
;
1211 entry
.addend
= addend
;
1213 return frvfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1216 /* Obtain the address of the entry in HT associated with the SYMNDXth
1217 local symbol of the input bfd ABFD, plus the addend, creating a new
1218 entry if none existed. */
1219 inline static struct frvfdpic_relocs_info
*
1220 frvfdpic_relocs_info_for_local (struct htab
*ht
,
1224 enum insert_option insert
)
1226 struct frvfdpic_relocs_info entry
;
1228 entry
.symndx
= symndx
;
1229 entry
.d
.abfd
= abfd
;
1230 entry
.addend
= addend
;
1232 return frvfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1235 /* Merge fields set by check_relocs() of two entries that end up being
1236 mapped to the same (presumably global) symbol. */
1239 frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info
*e2
,
1240 struct frvfdpic_relocs_info
const *e1
)
1242 e2
->got12
|= e1
->got12
;
1243 e2
->gotlos
|= e1
->gotlos
;
1244 e2
->gothilo
|= e1
->gothilo
;
1246 e2
->fdgot12
|= e1
->fdgot12
;
1247 e2
->fdgotlos
|= e1
->fdgotlos
;
1248 e2
->fdgothilo
|= e1
->fdgothilo
;
1249 e2
->fdgoff12
|= e1
->fdgoff12
;
1250 e2
->fdgofflos
|= e1
->fdgofflos
;
1251 e2
->fdgoffhilo
|= e1
->fdgoffhilo
;
1252 e2
->tlsplt
|= e1
->tlsplt
;
1253 e2
->tlsdesc12
|= e1
->tlsdesc12
;
1254 e2
->tlsdesclos
|= e1
->tlsdesclos
;
1255 e2
->tlsdeschilo
|= e1
->tlsdeschilo
;
1256 e2
->tlsoff12
|= e1
->tlsoff12
;
1257 e2
->tlsofflos
|= e1
->tlsofflos
;
1258 e2
->tlsoffhilo
|= e1
->tlsoffhilo
;
1259 e2
->gotoff
|= e1
->gotoff
;
1260 e2
->call
|= e1
->call
;
1264 /* Every block of 65535 lazy PLT entries shares a single call to the
1265 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
1266 32767, counting from 0). All other lazy PLT entries branch to it
1267 in a single instruction. */
1269 #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
1270 #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767)
1272 /* Add a dynamic relocation to the SRELOC section. */
1274 inline static bfd_vma
1275 _frvfdpic_add_dyn_reloc (bfd
*output_bfd
, asection
*sreloc
, bfd_vma offset
,
1276 int reloc_type
, long dynindx
, bfd_vma addend
,
1277 struct frvfdpic_relocs_info
*entry
)
1279 Elf_Internal_Rela outrel
;
1280 bfd_vma reloc_offset
;
1282 outrel
.r_offset
= offset
;
1283 outrel
.r_info
= ELF32_R_INFO (dynindx
, reloc_type
);
1284 outrel
.r_addend
= addend
;
1286 reloc_offset
= sreloc
->reloc_count
* sizeof (Elf32_External_Rel
);
1287 BFD_ASSERT (reloc_offset
< sreloc
->size
);
1288 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
1289 sreloc
->contents
+ reloc_offset
);
1290 sreloc
->reloc_count
++;
1292 /* If the entry's index is zero, this relocation was probably to a
1293 linkonce section that got discarded. We reserved a dynamic
1294 relocation, but it was for another entry than the one we got at
1295 the time of emitting the relocation. Unfortunately there's no
1296 simple way for us to catch this situation, since the relocation
1297 is cleared right before calling relocate_section, at which point
1298 we no longer know what the relocation used to point to. */
1301 BFD_ASSERT (entry
->dynrelocs
> 0);
1305 return reloc_offset
;
1308 /* Add a fixup to the ROFIXUP section. */
1311 _frvfdpic_add_rofixup (bfd
*output_bfd
, asection
*rofixup
, bfd_vma offset
,
1312 struct frvfdpic_relocs_info
*entry
)
1314 bfd_vma fixup_offset
;
1316 if (rofixup
->flags
& SEC_EXCLUDE
)
1319 fixup_offset
= rofixup
->reloc_count
* 4;
1320 if (rofixup
->contents
)
1322 BFD_ASSERT (fixup_offset
< rofixup
->size
);
1323 bfd_put_32 (output_bfd
, offset
, rofixup
->contents
+ fixup_offset
);
1325 rofixup
->reloc_count
++;
1327 if (entry
&& entry
->symndx
)
1329 /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc
1331 BFD_ASSERT (entry
->fixups
> 0);
1335 return fixup_offset
;
1338 /* Find the segment number in which OSEC, and output section, is
1342 _frvfdpic_osec_to_segment (bfd
*output_bfd
, asection
*osec
)
1344 Elf_Internal_Phdr
*p
= _bfd_elf_find_segment_containing_section (output_bfd
, osec
);
1346 return (p
!= NULL
) ? p
- elf_tdata (output_bfd
)->phdr
: -1;
1349 inline static bfd_boolean
1350 _frvfdpic_osec_readonly_p (bfd
*output_bfd
, asection
*osec
)
1352 unsigned seg
= _frvfdpic_osec_to_segment (output_bfd
, osec
);
1354 return ! (elf_tdata (output_bfd
)->phdr
[seg
].p_flags
& PF_W
);
1357 #define FRVFDPIC_TLS_BIAS (2048 - 16)
1359 /* Return the base VMA address which should be subtracted from real addresses
1360 when resolving TLSMOFF relocation.
1361 This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */
1364 tls_biased_base (struct bfd_link_info
*info
)
1366 /* If tls_sec is NULL, we should have signalled an error already. */
1367 if (elf_hash_table (info
)->tls_sec
== NULL
)
1368 return FRVFDPIC_TLS_BIAS
;
1369 return elf_hash_table (info
)->tls_sec
->vma
+ FRVFDPIC_TLS_BIAS
;
1372 /* Generate relocations for GOT entries, function descriptors, and
1373 code for PLT and lazy PLT entries. */
1375 inline static bfd_boolean
1376 _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info
*entry
,
1378 struct bfd_link_info
*info
,
1380 Elf_Internal_Sym
*sym
,
1384 bfd_vma fd_lazy_rel_offset
= (bfd_vma
)-1;
1391 if (entry
->got_entry
|| entry
->fdgot_entry
|| entry
->fd_entry
1392 || entry
->tlsoff_entry
|| entry
->tlsdesc_entry
)
1394 /* If the symbol is dynamic, consider it for dynamic
1395 relocations, otherwise decay to section + offset. */
1396 if (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1)
1397 dynindx
= entry
->d
.h
->dynindx
;
1401 && sec
->output_section
1402 && ! bfd_is_abs_section (sec
->output_section
)
1403 && ! bfd_is_und_section (sec
->output_section
))
1404 dynindx
= elf_section_data (sec
->output_section
)->dynindx
;
1410 /* Generate relocation for GOT entry pointing to the symbol. */
1411 if (entry
->got_entry
)
1414 bfd_vma ad
= addend
;
1416 /* If the symbol is dynamic but binds locally, use
1418 if (sec
&& (entry
->symndx
!= -1
1419 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1421 if (entry
->symndx
== -1)
1422 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1424 ad
+= sym
->st_value
;
1425 ad
+= sec
->output_offset
;
1426 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1427 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1432 /* If we're linking an executable at a fixed address, we can
1433 omit the dynamic relocation as long as the symbol is local to
1435 if (info
->executable
&& !info
->pie
1436 && (entry
->symndx
!= -1
1437 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1440 ad
+= sec
->output_section
->vma
;
1441 if (entry
->symndx
!= -1
1442 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1443 _frvfdpic_add_rofixup (output_bfd
,
1444 frvfdpic_gotfixup_section (info
),
1445 frvfdpic_got_section (info
)->output_section
1447 + frvfdpic_got_section (info
)->output_offset
1448 + frvfdpic_got_initial_offset (info
)
1449 + entry
->got_entry
, entry
);
1452 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1453 _bfd_elf_section_offset
1455 frvfdpic_got_section (info
),
1456 frvfdpic_got_initial_offset (info
)
1458 + frvfdpic_got_section (info
)
1459 ->output_section
->vma
1460 + frvfdpic_got_section (info
)->output_offset
,
1461 R_FRV_32
, idx
, ad
, entry
);
1463 bfd_put_32 (output_bfd
, ad
,
1464 frvfdpic_got_section (info
)->contents
1465 + frvfdpic_got_initial_offset (info
)
1466 + entry
->got_entry
);
1469 /* Generate relocation for GOT entry pointing to a canonical
1470 function descriptor. */
1471 if (entry
->fdgot_entry
)
1476 if (! (entry
->symndx
== -1
1477 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
1478 && FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1480 /* If the symbol is dynamic and there may be dynamic symbol
1481 resolution because we are, or are linked with, a shared
1482 library, emit a FUNCDESC relocation such that the dynamic
1483 linker will allocate the function descriptor. If the
1484 symbol needs a non-local function descriptor but binds
1485 locally (e.g., its visibility is protected, emit a
1486 dynamic relocation decayed to section+offset. */
1487 if (entry
->symndx
== -1
1488 && ! FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)
1489 && FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)
1490 && !(info
->executable
&& !info
->pie
))
1492 reloc
= R_FRV_FUNCDESC
;
1493 idx
= elf_section_data (entry
->d
.h
->root
.u
.def
.section
1494 ->output_section
)->dynindx
;
1495 ad
= entry
->d
.h
->root
.u
.def
.section
->output_offset
1496 + entry
->d
.h
->root
.u
.def
.value
;
1498 else if (entry
->symndx
== -1
1499 && ! FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
))
1501 reloc
= R_FRV_FUNCDESC
;
1506 (*info
->callbacks
->reloc_dangerous
)
1507 (info
, _("relocation requires zero addend"),
1508 elf_hash_table (info
)->dynobj
,
1509 frvfdpic_got_section (info
),
1510 entry
->fdgot_entry
);
1516 /* Otherwise, we know we have a private function descriptor,
1517 so reference it directly. */
1518 if (elf_hash_table (info
)->dynamic_sections_created
)
1519 BFD_ASSERT (entry
->privfd
);
1521 idx
= elf_section_data (frvfdpic_got_section (info
)
1522 ->output_section
)->dynindx
;
1523 ad
= frvfdpic_got_section (info
)->output_offset
1524 + frvfdpic_got_initial_offset (info
) + entry
->fd_entry
;
1527 /* If there is room for dynamic symbol resolution, emit the
1528 dynamic relocation. However, if we're linking an
1529 executable at a fixed location, we won't have emitted a
1530 dynamic symbol entry for the got section, so idx will be
1531 zero, which means we can and should compute the address
1532 of the private descriptor ourselves. */
1533 if (info
->executable
&& !info
->pie
1534 && (entry
->symndx
!= -1
1535 || FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)))
1537 ad
+= frvfdpic_got_section (info
)->output_section
->vma
;
1538 _frvfdpic_add_rofixup (output_bfd
,
1539 frvfdpic_gotfixup_section (info
),
1540 frvfdpic_got_section (info
)
1541 ->output_section
->vma
1542 + frvfdpic_got_section (info
)
1544 + frvfdpic_got_initial_offset (info
)
1545 + entry
->fdgot_entry
, entry
);
1548 _frvfdpic_add_dyn_reloc (output_bfd
,
1549 frvfdpic_gotrel_section (info
),
1550 _bfd_elf_section_offset
1552 frvfdpic_got_section (info
),
1553 frvfdpic_got_initial_offset (info
)
1554 + entry
->fdgot_entry
)
1555 + frvfdpic_got_section (info
)
1556 ->output_section
->vma
1557 + frvfdpic_got_section (info
)
1559 reloc
, idx
, ad
, entry
);
1562 bfd_put_32 (output_bfd
, ad
,
1563 frvfdpic_got_section (info
)->contents
1564 + frvfdpic_got_initial_offset (info
)
1565 + entry
->fdgot_entry
);
1568 /* Generate relocation to fill in a private function descriptor in
1570 if (entry
->fd_entry
)
1573 bfd_vma ad
= addend
;
1575 long lowword
, highword
;
1577 /* If the symbol is dynamic but binds locally, use
1579 if (sec
&& (entry
->symndx
!= -1
1580 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1582 if (entry
->symndx
== -1)
1583 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1585 ad
+= sym
->st_value
;
1586 ad
+= sec
->output_offset
;
1587 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1588 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1593 /* If we're linking an executable at a fixed address, we can
1594 omit the dynamic relocation as long as the symbol is local to
1596 if (info
->executable
&& !info
->pie
1597 && (entry
->symndx
!= -1 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1600 ad
+= sec
->output_section
->vma
;
1602 if (entry
->symndx
!= -1
1603 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1605 _frvfdpic_add_rofixup (output_bfd
,
1606 frvfdpic_gotfixup_section (info
),
1607 frvfdpic_got_section (info
)
1608 ->output_section
->vma
1609 + frvfdpic_got_section (info
)
1611 + frvfdpic_got_initial_offset (info
)
1612 + entry
->fd_entry
, entry
);
1613 _frvfdpic_add_rofixup (output_bfd
,
1614 frvfdpic_gotfixup_section (info
),
1615 frvfdpic_got_section (info
)
1616 ->output_section
->vma
1617 + frvfdpic_got_section (info
)
1619 + frvfdpic_got_initial_offset (info
)
1620 + entry
->fd_entry
+ 4, entry
);
1626 _frvfdpic_add_dyn_reloc (output_bfd
,
1628 ? frvfdpic_pltrel_section (info
)
1629 : frvfdpic_gotrel_section (info
),
1630 _bfd_elf_section_offset
1632 frvfdpic_got_section (info
),
1633 frvfdpic_got_initial_offset (info
)
1635 + frvfdpic_got_section (info
)
1636 ->output_section
->vma
1637 + frvfdpic_got_section (info
)
1639 R_FRV_FUNCDESC_VALUE
, idx
, ad
, entry
);
1642 /* If we've omitted the dynamic relocation, just emit the fixed
1643 addresses of the symbol and of the local GOT base offset. */
1644 if (info
->executable
&& !info
->pie
&& sec
&& sec
->output_section
)
1647 highword
= frvfdpic_got_section (info
)->output_section
->vma
1648 + frvfdpic_got_section (info
)->output_offset
1649 + frvfdpic_got_initial_offset (info
);
1651 else if (entry
->lazyplt
)
1655 (*info
->callbacks
->reloc_dangerous
)
1656 (info
, _("relocation requires zero addend"),
1657 elf_hash_table (info
)->dynobj
,
1658 frvfdpic_got_section (info
),
1663 fd_lazy_rel_offset
= ofst
;
1665 /* A function descriptor used for lazy or local resolving is
1666 initialized such that its high word contains the output
1667 section index in which the PLT entries are located, and
1668 the low word contains the address of the lazy PLT entry
1669 entry point, that must be within the memory region
1670 assigned to that section. */
1671 lowword
= entry
->lzplt_entry
+ 4
1672 + frvfdpic_plt_section (info
)->output_offset
1673 + frvfdpic_plt_section (info
)->output_section
->vma
;
1674 highword
= _frvfdpic_osec_to_segment
1675 (output_bfd
, frvfdpic_plt_section (info
)->output_section
);
1679 /* A function descriptor for a local function gets the index
1680 of the section. For a non-local function, it's
1684 || (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1
1685 && entry
->d
.h
->dynindx
== idx
))
1688 highword
= _frvfdpic_osec_to_segment
1689 (output_bfd
, sec
->output_section
);
1692 bfd_put_32 (output_bfd
, lowword
,
1693 frvfdpic_got_section (info
)->contents
1694 + frvfdpic_got_initial_offset (info
)
1696 bfd_put_32 (output_bfd
, highword
,
1697 frvfdpic_got_section (info
)->contents
1698 + frvfdpic_got_initial_offset (info
)
1699 + entry
->fd_entry
+ 4);
1702 /* Generate code for the PLT entry. */
1703 if (entry
->plt_entry
!= (bfd_vma
) -1)
1705 bfd_byte
*plt_code
= frvfdpic_plt_section (info
)->contents
1708 BFD_ASSERT (entry
->fd_entry
);
1710 /* Figure out what kind of PLT entry we need, depending on the
1711 location of the function descriptor within the GOT. */
1712 if (entry
->fd_entry
>= -(1 << (12 - 1))
1713 && entry
->fd_entry
< (1 << (12 - 1)))
1715 /* lddi @(gr15, fd_entry), gr14 */
1716 bfd_put_32 (output_bfd
,
1717 0x9cccf000 | (entry
->fd_entry
& ((1 << 12) - 1)),
1723 if (entry
->fd_entry
>= -(1 << (16 - 1))
1724 && entry
->fd_entry
< (1 << (16 - 1)))
1726 /* setlos lo(fd_entry), gr14 */
1727 bfd_put_32 (output_bfd
,
1729 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1735 /* sethi.p hi(fd_entry), gr14
1736 setlo lo(fd_entry), gr14 */
1737 bfd_put_32 (output_bfd
,
1739 | ((entry
->fd_entry
>> 16)
1740 & (((bfd_vma
)1 << 16) - 1)),
1743 bfd_put_32 (output_bfd
,
1745 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1749 /* ldd @(gr14,gr15),gr14 */
1750 bfd_put_32 (output_bfd
, 0x9c08e14f, plt_code
);
1753 /* jmpl @(gr14,gr0) */
1754 bfd_put_32 (output_bfd
, 0x8030e000, plt_code
);
1757 /* Generate code for the lazy PLT entry. */
1758 if (entry
->lzplt_entry
!= (bfd_vma
) -1)
1760 bfd_byte
*lzplt_code
= frvfdpic_plt_section (info
)->contents
1761 + entry
->lzplt_entry
;
1762 bfd_vma resolverStub_addr
;
1764 bfd_put_32 (output_bfd
, fd_lazy_rel_offset
, lzplt_code
);
1767 resolverStub_addr
= entry
->lzplt_entry
/ FRVFDPIC_LZPLT_BLOCK_SIZE
1768 * FRVFDPIC_LZPLT_BLOCK_SIZE
+ FRVFDPIC_LZPLT_RESOLV_LOC
;
1769 if (resolverStub_addr
>= frvfdpic_plt_initial_offset (info
))
1770 resolverStub_addr
= frvfdpic_plt_initial_offset (info
) - 12;
1772 if (entry
->lzplt_entry
== resolverStub_addr
)
1774 /* This is a lazy PLT entry that includes a resolver call. */
1775 /* ldd @(gr15,gr0), gr4
1777 bfd_put_32 (output_bfd
, 0x8808f140, lzplt_code
);
1778 bfd_put_32 (output_bfd
, 0x80304000, lzplt_code
+ 4);
1782 /* bra resolverStub */
1783 bfd_put_32 (output_bfd
,
1785 | (((resolverStub_addr
- entry
->lzplt_entry
)
1786 / 4) & (((bfd_vma
)1 << 16) - 1)),
1791 /* Generate relocation for GOT entry holding the TLS offset. */
1792 if (entry
->tlsoff_entry
)
1795 bfd_vma ad
= addend
;
1797 if (entry
->symndx
!= -1
1798 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
))
1800 /* If the symbol is dynamic but binds locally, use
1804 if (entry
->symndx
== -1)
1805 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1807 ad
+= sym
->st_value
;
1808 ad
+= sec
->output_offset
;
1809 if (sec
->output_section
1810 && elf_section_data (sec
->output_section
))
1811 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1817 /* *ABS*+addend is special for TLS relocations, use only the
1819 if (info
->executable
1821 && (bfd_is_abs_section (sec
)
1822 || bfd_is_und_section (sec
)))
1824 /* If we're linking an executable, we can entirely omit the
1825 dynamic relocation if the symbol is local to this module. */
1826 else if (info
->executable
1827 && (entry
->symndx
!= -1
1828 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1831 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1836 && (bfd_is_abs_section (sec
)
1837 || bfd_is_und_section (sec
)))
1839 if (! elf_hash_table (info
)->tls_sec
)
1841 (*info
->callbacks
->undefined_symbol
)
1842 (info
, "TLS section", elf_hash_table (info
)->dynobj
,
1843 frvfdpic_got_section (info
), entry
->tlsoff_entry
, TRUE
);
1846 idx
= elf_section_data (elf_hash_table (info
)->tls_sec
)->dynindx
;
1847 ad
+= FRVFDPIC_TLS_BIAS
;
1849 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1850 _bfd_elf_section_offset
1852 frvfdpic_got_section (info
),
1853 frvfdpic_got_initial_offset (info
)
1854 + entry
->tlsoff_entry
)
1855 + frvfdpic_got_section (info
)
1856 ->output_section
->vma
1857 + frvfdpic_got_section (info
)
1859 R_FRV_TLSOFF
, idx
, ad
, entry
);
1862 bfd_put_32 (output_bfd
, ad
,
1863 frvfdpic_got_section (info
)->contents
1864 + frvfdpic_got_initial_offset (info
)
1865 + entry
->tlsoff_entry
);
1868 if (entry
->tlsdesc_entry
)
1871 bfd_vma ad
= addend
;
1873 /* If the symbol is dynamic but binds locally, use
1875 if (sec
&& (entry
->symndx
!= -1
1876 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1878 if (entry
->symndx
== -1)
1879 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1881 ad
+= sym
->st_value
;
1882 ad
+= sec
->output_offset
;
1883 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1884 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1889 /* If we didn't set up a TLS offset entry, but we're linking an
1890 executable and the symbol binds locally, we can use the
1891 module offset in the TLS descriptor in relaxations. */
1892 if (info
->executable
&& ! entry
->tlsoff_entry
)
1893 entry
->tlsoff_entry
= entry
->tlsdesc_entry
+ 4;
1895 if (info
->executable
&& !info
->pie
1897 && (bfd_is_abs_section (sec
)
1898 || bfd_is_und_section (sec
)))
1899 || entry
->symndx
!= -1
1900 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1902 /* *ABS*+addend is special for TLS relocations, use only the
1903 addend for the TLS offset, and take the module id as
1906 && (bfd_is_abs_section (sec
)
1907 || bfd_is_und_section (sec
)))
1909 /* For other TLS symbols that bind locally, add the section
1910 TLS offset to the addend. */
1912 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1914 bfd_put_32 (output_bfd
,
1915 frvfdpic_plt_section (info
)->output_section
->vma
1916 + frvfdpic_plt_section (info
)->output_offset
1917 + frvfdpic_plt_tls_ret_offset (info
),
1918 frvfdpic_got_section (info
)->contents
1919 + frvfdpic_got_initial_offset (info
)
1920 + entry
->tlsdesc_entry
);
1922 _frvfdpic_add_rofixup (output_bfd
,
1923 frvfdpic_gotfixup_section (info
),
1924 frvfdpic_got_section (info
)
1925 ->output_section
->vma
1926 + frvfdpic_got_section (info
)
1928 + frvfdpic_got_initial_offset (info
)
1929 + entry
->tlsdesc_entry
, entry
);
1931 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
);
1933 /* We've used one of the reserved fixups, so discount it so
1934 that we can check at the end that we've used them
1936 frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
--;
1938 /* While at that, make sure the ret instruction makes to the
1939 right location in the PLT. We could do it only when we
1940 got to 0, but since the check at the end will only print
1941 a warning, make sure we have the ret in place in case the
1942 warning is missed. */
1943 bfd_put_32 (output_bfd
, 0xc03a4000,
1944 frvfdpic_plt_section (info
)->contents
1945 + frvfdpic_plt_tls_ret_offset (info
));
1950 && (bfd_is_abs_section (sec
)
1951 || bfd_is_und_section (sec
)))
1953 if (! elf_hash_table (info
)->tls_sec
)
1955 (*info
->callbacks
->undefined_symbol
)
1956 (info
, "TLS section", elf_hash_table (info
)->dynobj
,
1957 frvfdpic_got_section (info
), entry
->tlsdesc_entry
, TRUE
);
1960 idx
= elf_section_data (elf_hash_table (info
)->tls_sec
)->dynindx
;
1961 ad
+= FRVFDPIC_TLS_BIAS
;
1964 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1965 _bfd_elf_section_offset
1967 frvfdpic_got_section (info
),
1968 frvfdpic_got_initial_offset (info
)
1969 + entry
->tlsdesc_entry
)
1970 + frvfdpic_got_section (info
)
1971 ->output_section
->vma
1972 + frvfdpic_got_section (info
)
1974 R_FRV_TLSDESC_VALUE
, idx
, ad
, entry
);
1976 bfd_put_32 (output_bfd
, 0,
1977 frvfdpic_got_section (info
)->contents
1978 + frvfdpic_got_initial_offset (info
)
1979 + entry
->tlsdesc_entry
);
1982 bfd_put_32 (output_bfd
, ad
,
1983 frvfdpic_got_section (info
)->contents
1984 + frvfdpic_got_initial_offset (info
)
1985 + entry
->tlsdesc_entry
+ 4);
1988 /* Generate code for the get-TLS-offset PLT entry. */
1989 if (entry
->tlsplt_entry
!= (bfd_vma
) -1)
1991 bfd_byte
*plt_code
= frvfdpic_plt_section (info
)->contents
1992 + entry
->tlsplt_entry
;
1994 if (info
->executable
1995 && (entry
->symndx
!= -1
1996 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1999 bfd_vma ad
= addend
;
2001 /* sec may be NULL when referencing an undefweak symbol
2002 while linking a static executable. */
2005 BFD_ASSERT (entry
->symndx
== -1
2006 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
);
2010 if (entry
->symndx
== -1)
2011 ad
+= entry
->d
.h
->root
.u
.def
.value
;
2013 ad
+= sym
->st_value
;
2014 ad
+= sec
->output_offset
;
2015 if (sec
->output_section
2016 && elf_section_data (sec
->output_section
))
2017 idx
= elf_section_data (sec
->output_section
)->dynindx
;
2022 /* *ABS*+addend is special for TLS relocations, use only the
2023 addend for the TLS offset, and take the module id as
2026 && (bfd_is_abs_section (sec
)
2027 || bfd_is_und_section (sec
)))
2029 /* For other TLS symbols that bind locally, add the section
2030 TLS offset to the addend. */
2032 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
2034 if ((bfd_signed_vma
)ad
>= -(1 << (16 - 1))
2035 && (bfd_signed_vma
)ad
< (1 << (16 - 1)))
2037 /* setlos lo(ad), gr9 */
2038 bfd_put_32 (output_bfd
,
2041 & (((bfd_vma
)1 << 16) - 1)),
2047 /* sethi.p hi(ad), gr9
2048 setlo lo(ad), gr9 */
2049 bfd_put_32 (output_bfd
,
2052 & (((bfd_vma
)1 << 16) - 1)),
2055 bfd_put_32 (output_bfd
,
2058 & (((bfd_vma
)1 << 16) - 1)),
2063 bfd_put_32 (output_bfd
, 0xc03a4000, plt_code
);
2065 else if (entry
->tlsoff_entry
)
2067 /* Figure out what kind of PLT entry we need, depending on the
2068 location of the TLS descriptor within the GOT. */
2069 if (entry
->tlsoff_entry
>= -(1 << (12 - 1))
2070 && entry
->tlsoff_entry
< (1 << (12 - 1)))
2072 /* ldi @(gr15, tlsoff_entry), gr9 */
2073 bfd_put_32 (output_bfd
,
2074 0x92c8f000 | (entry
->tlsoff_entry
2081 if (entry
->tlsoff_entry
>= -(1 << (16 - 1))
2082 && entry
->tlsoff_entry
< (1 << (16 - 1)))
2084 /* setlos lo(tlsoff_entry), gr8 */
2085 bfd_put_32 (output_bfd
,
2087 | (entry
->tlsoff_entry
2088 & (((bfd_vma
)1 << 16) - 1)),
2094 /* sethi.p hi(tlsoff_entry), gr8
2095 setlo lo(tlsoff_entry), gr8 */
2096 bfd_put_32 (output_bfd
,
2098 | ((entry
->tlsoff_entry
>> 16)
2099 & (((bfd_vma
)1 << 16) - 1)),
2102 bfd_put_32 (output_bfd
,
2104 | (entry
->tlsoff_entry
2105 & (((bfd_vma
)1 << 16) - 1)),
2109 /* ld @(gr15,gr8),gr9 */
2110 bfd_put_32 (output_bfd
, 0x9008f108, plt_code
);
2114 bfd_put_32 (output_bfd
, 0xc03a4000, plt_code
);
2118 BFD_ASSERT (entry
->tlsdesc_entry
);
2120 /* Figure out what kind of PLT entry we need, depending on the
2121 location of the TLS descriptor within the GOT. */
2122 if (entry
->tlsdesc_entry
>= -(1 << (12 - 1))
2123 && entry
->tlsdesc_entry
< (1 << (12 - 1)))
2125 /* lddi @(gr15, tlsdesc_entry), gr8 */
2126 bfd_put_32 (output_bfd
,
2127 0x90ccf000 | (entry
->tlsdesc_entry
2134 if (entry
->tlsdesc_entry
>= -(1 << (16 - 1))
2135 && entry
->tlsdesc_entry
< (1 << (16 - 1)))
2137 /* setlos lo(tlsdesc_entry), gr8 */
2138 bfd_put_32 (output_bfd
,
2140 | (entry
->tlsdesc_entry
2141 & (((bfd_vma
)1 << 16) - 1)),
2147 /* sethi.p hi(tlsdesc_entry), gr8
2148 setlo lo(tlsdesc_entry), gr8 */
2149 bfd_put_32 (output_bfd
,
2151 | ((entry
->tlsdesc_entry
>> 16)
2152 & (((bfd_vma
)1 << 16) - 1)),
2155 bfd_put_32 (output_bfd
,
2157 | (entry
->tlsdesc_entry
2158 & (((bfd_vma
)1 << 16) - 1)),
2162 /* ldd @(gr15,gr8),gr8 */
2163 bfd_put_32 (output_bfd
, 0x9008f148, plt_code
);
2166 /* jmpl @(gr8,gr0) */
2167 bfd_put_32 (output_bfd
, 0x80308000, plt_code
);
2174 /* Handle an FRV small data reloc. */
2176 static bfd_reloc_status_type
2177 elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, relocation
,
2179 struct bfd_link_info
*info
;
2181 asection
*input_section
;
2182 Elf_Internal_Rela
*relocation
;
2188 struct bfd_link_hash_entry
*h
;
2190 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2192 gp
= (h
->u
.def
.value
2193 + h
->u
.def
.section
->output_section
->vma
2194 + h
->u
.def
.section
->output_offset
);
2196 value
-= input_section
->output_section
->vma
;
2197 value
-= (gp
- input_section
->output_section
->vma
);
2199 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2201 value
+= relocation
->r_addend
;
2203 if ((long) value
> 0x7ff || (long) value
< -0x800)
2204 return bfd_reloc_overflow
;
2206 bfd_put_32 (input_bfd
,
2207 (insn
& 0xfffff000) | (value
& 0xfff),
2208 contents
+ relocation
->r_offset
);
2210 return bfd_reloc_ok
;
2213 /* Handle an FRV small data reloc. for the u12 field. */
2215 static bfd_reloc_status_type
2216 elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, relocation
,
2218 struct bfd_link_info
*info
;
2220 asection
*input_section
;
2221 Elf_Internal_Rela
*relocation
;
2227 struct bfd_link_hash_entry
*h
;
2230 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2232 gp
= (h
->u
.def
.value
2233 + h
->u
.def
.section
->output_section
->vma
2234 + h
->u
.def
.section
->output_offset
);
2236 value
-= input_section
->output_section
->vma
;
2237 value
-= (gp
- input_section
->output_section
->vma
);
2239 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2241 value
+= relocation
->r_addend
;
2243 if ((long) value
> 0x7ff || (long) value
< -0x800)
2244 return bfd_reloc_overflow
;
2246 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
2248 insn
= (insn
& ~mask
) | ((value
& 0xfc0) << 12) | (value
& 0x3f);
2250 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2252 return bfd_reloc_ok
;
2255 /* Handle an FRV ELF HI16 reloc. */
2257 static bfd_reloc_status_type
2258 elf32_frv_relocate_hi16 (input_bfd
, relhi
, contents
, value
)
2260 Elf_Internal_Rela
*relhi
;
2266 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
2268 value
+= relhi
->r_addend
;
2269 value
= ((value
>> 16) & 0xffff);
2271 insn
= (insn
& 0xffff0000) | value
;
2273 if ((long) value
> 0xffff || (long) value
< -0x10000)
2274 return bfd_reloc_overflow
;
2276 bfd_put_32 (input_bfd
, insn
, contents
+ relhi
->r_offset
);
2277 return bfd_reloc_ok
;
2280 static bfd_reloc_status_type
2281 elf32_frv_relocate_lo16 (input_bfd
, rello
, contents
, value
)
2283 Elf_Internal_Rela
*rello
;
2289 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2291 value
+= rello
->r_addend
;
2292 value
= value
& 0xffff;
2294 insn
= (insn
& 0xffff0000) | value
;
2296 if ((long) value
> 0xffff || (long) value
< -0x10000)
2297 return bfd_reloc_overflow
;
2299 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
2300 return bfd_reloc_ok
;
2303 /* Perform the relocation for the CALL label24 instruction. */
2305 static bfd_reloc_status_type
2306 elf32_frv_relocate_label24 (input_bfd
, input_section
, rello
, contents
, value
)
2308 asection
*input_section
;
2309 Elf_Internal_Rela
*rello
;
2317 /* The format for the call instruction is:
2319 0 000000 0001111 000000000000000000
2320 label6 opcode label18
2322 The branch calculation is: pc + (4*label24)
2323 where label24 is the concatenation of label6 and label18. */
2325 /* Grab the instruction. */
2326 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2328 value
-= input_section
->output_section
->vma
+ input_section
->output_offset
;
2329 value
-= rello
->r_offset
;
2330 value
+= rello
->r_addend
;
2334 label6
= value
& 0xfc0000;
2335 label6
= label6
<< 7;
2337 label18
= value
& 0x3ffff;
2339 insn
= insn
& 0x803c0000;
2340 insn
= insn
| label6
;
2341 insn
= insn
| label18
;
2343 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
2345 return bfd_reloc_ok
;
2348 static bfd_reloc_status_type
2349 elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, relocation
,
2351 struct bfd_link_info
*info
;
2353 asection
*input_section
;
2354 Elf_Internal_Rela
*relocation
;
2360 struct bfd_link_hash_entry
*h
;
2362 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2364 gp
= (h
->u
.def
.value
2365 + h
->u
.def
.section
->output_section
->vma
2366 + h
->u
.def
.section
->output_offset
);
2368 value
-= input_section
->output_section
->vma
;
2369 value
-= (gp
- input_section
->output_section
->vma
);
2370 value
+= relocation
->r_addend
;
2371 value
= ((value
>> 16) & 0xffff);
2373 if ((long) value
> 0xffff || (long) value
< -0x10000)
2374 return bfd_reloc_overflow
;
2376 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2377 insn
= (insn
& 0xffff0000) | value
;
2379 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2380 return bfd_reloc_ok
;
2383 static bfd_reloc_status_type
2384 elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, relocation
,
2386 struct bfd_link_info
*info
;
2388 asection
*input_section
;
2389 Elf_Internal_Rela
*relocation
;
2395 struct bfd_link_hash_entry
*h
;
2397 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2399 gp
= (h
->u
.def
.value
2400 + h
->u
.def
.section
->output_section
->vma
2401 + h
->u
.def
.section
->output_offset
);
2403 value
-= input_section
->output_section
->vma
;
2404 value
-= (gp
- input_section
->output_section
->vma
);
2405 value
+= relocation
->r_addend
;
2406 value
= value
& 0xffff;
2408 if ((long) value
> 0xffff || (long) value
< -0x10000)
2409 return bfd_reloc_overflow
;
2411 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2412 insn
= (insn
& 0xffff0000) | value
;
2414 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2416 return bfd_reloc_ok
;
2419 static reloc_howto_type
*
2420 frv_reloc_type_lookup (abfd
, code
)
2421 bfd
*abfd ATTRIBUTE_UNUSED
;
2422 bfd_reloc_code_real_type code
;
2429 case BFD_RELOC_NONE
:
2430 return &elf32_frv_howto_table
[ (int) R_FRV_NONE
];
2433 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2434 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2435 return &elf32_frv_rel_32_howto
;
2437 case BFD_RELOC_CTOR
:
2438 return &elf32_frv_howto_table
[ (int) R_FRV_32
];
2440 case BFD_RELOC_FRV_LABEL16
:
2441 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL16
];
2443 case BFD_RELOC_FRV_LABEL24
:
2444 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL24
];
2446 case BFD_RELOC_FRV_LO16
:
2447 return &elf32_frv_howto_table
[ (int) R_FRV_LO16
];
2449 case BFD_RELOC_FRV_HI16
:
2450 return &elf32_frv_howto_table
[ (int) R_FRV_HI16
];
2452 case BFD_RELOC_FRV_GPREL12
:
2453 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL12
];
2455 case BFD_RELOC_FRV_GPRELU12
:
2456 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELU12
];
2458 case BFD_RELOC_FRV_GPREL32
:
2459 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL32
];
2461 case BFD_RELOC_FRV_GPRELHI
:
2462 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELHI
];
2464 case BFD_RELOC_FRV_GPRELLO
:
2465 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELLO
];
2467 case BFD_RELOC_FRV_GOT12
:
2468 return &elf32_frv_howto_table
[ (int) R_FRV_GOT12
];
2470 case BFD_RELOC_FRV_GOTHI
:
2471 return &elf32_frv_howto_table
[ (int) R_FRV_GOTHI
];
2473 case BFD_RELOC_FRV_GOTLO
:
2474 return &elf32_frv_howto_table
[ (int) R_FRV_GOTLO
];
2476 case BFD_RELOC_FRV_FUNCDESC
:
2477 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2478 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2479 return &elf32_frv_rel_funcdesc_howto
;
2480 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC
];
2482 case BFD_RELOC_FRV_FUNCDESC_GOT12
:
2483 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOT12
];
2485 case BFD_RELOC_FRV_FUNCDESC_GOTHI
:
2486 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTHI
];
2488 case BFD_RELOC_FRV_FUNCDESC_GOTLO
:
2489 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTLO
];
2491 case BFD_RELOC_FRV_FUNCDESC_VALUE
:
2492 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2493 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2494 return &elf32_frv_rel_funcdesc_value_howto
;
2495 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_VALUE
];
2497 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12
:
2498 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFF12
];
2500 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI
:
2501 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFHI
];
2503 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO
:
2504 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFLO
];
2506 case BFD_RELOC_FRV_GOTOFF12
:
2507 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFF12
];
2509 case BFD_RELOC_FRV_GOTOFFHI
:
2510 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFHI
];
2512 case BFD_RELOC_FRV_GOTOFFLO
:
2513 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFLO
];
2515 case BFD_RELOC_FRV_GETTLSOFF
:
2516 return &elf32_frv_howto_table
[ (int) R_FRV_GETTLSOFF
];
2518 case BFD_RELOC_FRV_TLSDESC_VALUE
:
2519 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2520 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2521 return &elf32_frv_rel_tlsdesc_value_howto
;
2522 return &elf32_frv_howto_table
[ (int) R_FRV_TLSDESC_VALUE
];
2524 case BFD_RELOC_FRV_GOTTLSDESC12
:
2525 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESC12
];
2527 case BFD_RELOC_FRV_GOTTLSDESCHI
:
2528 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESCHI
];
2530 case BFD_RELOC_FRV_GOTTLSDESCLO
:
2531 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESCLO
];
2533 case BFD_RELOC_FRV_TLSMOFF12
:
2534 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFF12
];
2536 case BFD_RELOC_FRV_TLSMOFFHI
:
2537 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFFHI
];
2539 case BFD_RELOC_FRV_TLSMOFFLO
:
2540 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFFLO
];
2542 case BFD_RELOC_FRV_GOTTLSOFF12
:
2543 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFF12
];
2545 case BFD_RELOC_FRV_GOTTLSOFFHI
:
2546 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFFHI
];
2548 case BFD_RELOC_FRV_GOTTLSOFFLO
:
2549 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFFLO
];
2551 case BFD_RELOC_FRV_TLSOFF
:
2552 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2553 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2554 return &elf32_frv_rel_tlsoff_howto
;
2555 return &elf32_frv_howto_table
[ (int) R_FRV_TLSOFF
];
2557 case BFD_RELOC_FRV_TLSDESC_RELAX
:
2558 return &elf32_frv_howto_table
[ (int) R_FRV_TLSDESC_RELAX
];
2560 case BFD_RELOC_FRV_GETTLSOFF_RELAX
:
2561 return &elf32_frv_howto_table
[ (int) R_FRV_GETTLSOFF_RELAX
];
2563 case BFD_RELOC_FRV_TLSOFF_RELAX
:
2564 return &elf32_frv_howto_table
[ (int) R_FRV_TLSOFF_RELAX
];
2566 case BFD_RELOC_FRV_TLSMOFF
:
2567 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFF
];
2569 case BFD_RELOC_VTABLE_INHERIT
:
2570 return &elf32_frv_vtinherit_howto
;
2572 case BFD_RELOC_VTABLE_ENTRY
:
2573 return &elf32_frv_vtentry_howto
;
2579 static reloc_howto_type
*
2580 frv_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
, const char *r_name
)
2585 i
< sizeof (elf32_frv_howto_table
) / sizeof (elf32_frv_howto_table
[0]);
2587 if (elf32_frv_howto_table
[i
].name
!= NULL
2588 && strcasecmp (elf32_frv_howto_table
[i
].name
, r_name
) == 0)
2589 return &elf32_frv_howto_table
[i
];
2591 if (strcasecmp (elf32_frv_vtinherit_howto
.name
, r_name
) == 0)
2592 return &elf32_frv_vtinherit_howto
;
2593 if (strcasecmp (elf32_frv_vtentry_howto
.name
, r_name
) == 0)
2594 return &elf32_frv_vtentry_howto
;
2599 /* Set the howto pointer for an FRV ELF reloc. */
2602 frv_info_to_howto_rela (abfd
, cache_ptr
, dst
)
2603 bfd
*abfd ATTRIBUTE_UNUSED
;
2605 Elf_Internal_Rela
*dst
;
2607 unsigned int r_type
;
2609 r_type
= ELF32_R_TYPE (dst
->r_info
);
2612 case R_FRV_GNU_VTINHERIT
:
2613 cache_ptr
->howto
= &elf32_frv_vtinherit_howto
;
2616 case R_FRV_GNU_VTENTRY
:
2617 cache_ptr
->howto
= &elf32_frv_vtentry_howto
;
2621 cache_ptr
->howto
= & elf32_frv_howto_table
[r_type
];
2626 /* Set the howto pointer for an FRV ELF REL reloc. */
2628 frvfdpic_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
2629 arelent
*cache_ptr
, Elf_Internal_Rela
*dst
)
2631 unsigned int r_type
;
2633 r_type
= ELF32_R_TYPE (dst
->r_info
);
2637 cache_ptr
->howto
= &elf32_frv_rel_32_howto
;
2640 case R_FRV_FUNCDESC
:
2641 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_howto
;
2644 case R_FRV_FUNCDESC_VALUE
:
2645 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_value_howto
;
2648 case R_FRV_TLSDESC_VALUE
:
2649 cache_ptr
->howto
= &elf32_frv_rel_tlsdesc_value_howto
;
2653 cache_ptr
->howto
= &elf32_frv_rel_tlsoff_howto
;
2657 cache_ptr
->howto
= NULL
;
2662 /* Perform a single relocation. By default we use the standard BFD
2663 routines, but a few relocs, we have to do them ourselves. */
2665 static bfd_reloc_status_type
2666 frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
, rel
,
2668 reloc_howto_type
*howto
;
2670 asection
*input_section
;
2672 Elf_Internal_Rela
*rel
;
2675 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2676 contents
, rel
->r_offset
, relocation
,
2681 /* Relocate an FRV ELF section.
2683 The RELOCATE_SECTION function is called by the new ELF backend linker
2684 to handle the relocations for a section.
2686 The relocs are always passed as Rela structures; if the section
2687 actually uses Rel structures, the r_addend field will always be
2690 This function is responsible for adjusting the section contents as
2691 necessary, and (if using Rela relocs and generating a relocatable
2692 output file) adjusting the reloc addend as necessary.
2694 This function does not have to worry about setting the reloc
2695 address or the reloc symbol index.
2697 LOCAL_SYMS is a pointer to the swapped in local symbols.
2699 LOCAL_SECTIONS is an array giving the section in the input file
2700 corresponding to the st_shndx field of each local symbol.
2702 The global hash table entry for the global symbols can be found
2703 via elf_sym_hashes (input_bfd).
2705 When generating relocatable output, this function must handle
2706 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2707 going to be the section symbol corresponding to the output
2708 section, which means that the addend must be adjusted
2712 elf32_frv_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2713 contents
, relocs
, local_syms
, local_sections
)
2714 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2715 struct bfd_link_info
*info
;
2717 asection
*input_section
;
2719 Elf_Internal_Rela
*relocs
;
2720 Elf_Internal_Sym
*local_syms
;
2721 asection
**local_sections
;
2723 Elf_Internal_Shdr
*symtab_hdr
;
2724 struct elf_link_hash_entry
**sym_hashes
;
2725 Elf_Internal_Rela
*rel
;
2726 Elf_Internal_Rela
*relend
;
2727 unsigned isec_segment
, got_segment
, plt_segment
, gprel_segment
, tls_segment
,
2729 int silence_segment_error
= !(info
->shared
|| info
->pie
);
2731 static bfd_boolean ef_frv_pic_flag_set
= FALSE
;
2733 if (! ef_frv_pic_flag_set
&& IS_FDPIC (output_bfd
))
2735 elf_elfheader (output_bfd
)->e_flags
|= EF_FRV_PIC
;
2736 ef_frv_pic_flag_set
= TRUE
;
2739 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
2740 sym_hashes
= elf_sym_hashes (input_bfd
);
2741 relend
= relocs
+ input_section
->reloc_count
;
2743 isec_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2744 input_section
->output_section
);
2745 if (IS_FDPIC (output_bfd
) && frvfdpic_got_section (info
))
2746 got_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2747 frvfdpic_got_section (info
)
2751 if (IS_FDPIC (output_bfd
) && frvfdpic_gotfixup_section (info
))
2752 gprel_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2753 frvfdpic_gotfixup_section (info
)
2757 if (IS_FDPIC (output_bfd
) && frvfdpic_plt_section (info
))
2758 plt_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2759 frvfdpic_plt_section (info
)
2763 if (elf_hash_table (info
)->tls_sec
)
2764 tls_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2765 elf_hash_table (info
)->tls_sec
);
2769 for (rel
= relocs
; rel
< relend
; rel
++)
2771 reloc_howto_type
*howto
;
2772 unsigned long r_symndx
;
2773 Elf_Internal_Sym
*sym
;
2775 struct elf_link_hash_entry
*h
;
2777 bfd_reloc_status_type r
;
2778 const char * name
= NULL
;
2781 struct frvfdpic_relocs_info
*picrel
;
2782 bfd_vma orig_addend
= rel
->r_addend
;
2784 r_type
= ELF32_R_TYPE (rel
->r_info
);
2786 if ( r_type
== R_FRV_GNU_VTINHERIT
2787 || r_type
== R_FRV_GNU_VTENTRY
)
2790 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2791 howto
= elf32_frv_howto_table
+ ELF32_R_TYPE (rel
->r_info
);
2796 if (r_symndx
< symtab_hdr
->sh_info
)
2798 sym
= local_syms
+ r_symndx
;
2799 osec
= sec
= local_sections
[r_symndx
];
2800 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2802 name
= bfd_elf_string_from_elf_section
2803 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
2804 name
= (name
== NULL
) ? bfd_section_name (input_bfd
, sec
) : name
;
2809 bfd_boolean unresolved_reloc
;
2811 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2812 r_symndx
, symtab_hdr
, sym_hashes
,
2814 unresolved_reloc
, warned
);
2818 if (sec
!= NULL
&& elf_discarded_section (sec
))
2820 /* For relocs against symbols from removed linkonce sections,
2821 or sections discarded by a linker script, we just want the
2822 section contents zeroed. Avoid any special processing. */
2823 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
2829 if (info
->relocatable
)
2832 if (r_type
!= R_FRV_TLSMOFF
2834 && (h
->root
.type
== bfd_link_hash_defined
2835 || h
->root
.type
== bfd_link_hash_defweak
)
2836 && !FRVFDPIC_SYM_LOCAL (info
, h
))
2846 if (! IS_FDPIC (output_bfd
))
2852 case R_FRV_FUNCDESC_GOT12
:
2853 case R_FRV_FUNCDESC_GOTHI
:
2854 case R_FRV_FUNCDESC_GOTLO
:
2855 case R_FRV_GOTOFF12
:
2856 case R_FRV_GOTOFFHI
:
2857 case R_FRV_GOTOFFLO
:
2858 case R_FRV_FUNCDESC_GOTOFF12
:
2859 case R_FRV_FUNCDESC_GOTOFFHI
:
2860 case R_FRV_FUNCDESC_GOTOFFLO
:
2861 case R_FRV_FUNCDESC
:
2862 case R_FRV_FUNCDESC_VALUE
:
2863 case R_FRV_GETTLSOFF
:
2864 case R_FRV_TLSDESC_VALUE
:
2865 case R_FRV_GOTTLSDESC12
:
2866 case R_FRV_GOTTLSDESCHI
:
2867 case R_FRV_GOTTLSDESCLO
:
2868 case R_FRV_TLSMOFF12
:
2869 case R_FRV_TLSMOFFHI
:
2870 case R_FRV_TLSMOFFLO
:
2871 case R_FRV_GOTTLSOFF12
:
2872 case R_FRV_GOTTLSOFFHI
:
2873 case R_FRV_GOTTLSOFFLO
:
2875 case R_FRV_TLSDESC_RELAX
:
2876 case R_FRV_GETTLSOFF_RELAX
:
2877 case R_FRV_TLSOFF_RELAX
:
2880 picrel
= frvfdpic_relocs_info_for_global (frvfdpic_relocs_info
2881 (info
), input_bfd
, h
,
2882 orig_addend
, INSERT
);
2884 /* In order to find the entry we created before, we must
2885 use the original addend, not the one that may have been
2886 modified by _bfd_elf_rela_local_sym(). */
2887 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
2888 (info
), input_bfd
, r_symndx
,
2889 orig_addend
, INSERT
);
2893 if (!_frvfdpic_emit_got_relocs_plt_entries (picrel
, output_bfd
, info
,
2897 (*_bfd_error_handler
)
2898 (_("%B(%A+0x%x): relocation to `%s+%x' may have caused the error above"),
2899 input_bfd
, input_section
, rel
->r_offset
, name
, rel
->r_addend
);
2908 if (h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
))
2910 info
->callbacks
->warning
2911 (info
, _("relocation references symbol not defined in the module"),
2912 name
, input_bfd
, input_section
, rel
->r_offset
);
2920 case R_FRV_GETTLSOFF
:
2921 case R_FRV_TLSDESC_VALUE
:
2922 case R_FRV_GOTTLSDESC12
:
2923 case R_FRV_GOTTLSDESCHI
:
2924 case R_FRV_GOTTLSDESCLO
:
2925 case R_FRV_TLSMOFF12
:
2926 case R_FRV_TLSMOFFHI
:
2927 case R_FRV_TLSMOFFLO
:
2928 case R_FRV_GOTTLSOFF12
:
2929 case R_FRV_GOTTLSOFFHI
:
2930 case R_FRV_GOTTLSOFFLO
:
2932 case R_FRV_TLSDESC_RELAX
:
2933 case R_FRV_GETTLSOFF_RELAX
:
2934 case R_FRV_TLSOFF_RELAX
:
2936 if (sec
&& (bfd_is_abs_section (sec
) || bfd_is_und_section (sec
)))
2937 relocation
+= tls_biased_base (info
);
2944 /* Try to apply TLS relaxations. */
2949 #define LOCAL_EXEC_P(info, picrel) \
2950 ((info)->executable \
2951 && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h)))
2952 #define INITIAL_EXEC_P(info, picrel) \
2953 (((info)->executable || (info)->flags & DF_STATIC_TLS) \
2954 && (picrel)->tlsoff_entry)
2956 #define IN_RANGE_FOR_OFST12_P(value) \
2957 ((bfd_vma)((value) + 2048) < (bfd_vma)4096)
2958 #define IN_RANGE_FOR_SETLOS_P(value) \
2959 ((bfd_vma)((value) + 32768) < (bfd_vma)65536)
2960 #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \
2961 (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info)))
2963 #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2964 (LOCAL_EXEC_P ((info), (picrel)) \
2965 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2966 #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \
2967 (INITIAL_EXEC_P ((info), (picrel)) \
2968 && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry))
2970 #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \
2971 (LOCAL_EXEC_P ((info), (picrel)))
2972 #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \
2973 (INITIAL_EXEC_P ((info), (picrel)))
2975 #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2976 (LOCAL_EXEC_P ((info), (picrel)) \
2977 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2979 case R_FRV_GETTLSOFF
:
2980 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2982 /* Is this a call instruction? */
2983 if ((insn
& (unsigned long)0x01fc0000) != 0x003c0000)
2985 r
= info
->callbacks
->warning
2987 _("R_FRV_GETTLSOFF not applied to a call instruction"),
2988 name
, input_bfd
, input_section
, rel
->r_offset
);
2992 if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info
, picrel
,
2993 relocation
+ rel
->r_addend
))
2995 /* Replace the call instruction (except the packing bit)
2996 with setlos #tlsmofflo(symbol+offset), gr9. */
2997 insn
&= (unsigned long)0x80000000;
2998 insn
|= (unsigned long)0x12fc0000;
2999 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3001 r_type
= R_FRV_TLSMOFFLO
;
3002 howto
= elf32_frv_howto_table
+ r_type
;
3003 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3006 else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info
, picrel
))
3008 /* Replace the call instruction (except the packing bit)
3009 with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */
3010 insn
&= (unsigned long)0x80000000;
3011 insn
|= (unsigned long)0x12c8f000;
3012 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3014 r_type
= R_FRV_GOTTLSOFF12
;
3015 howto
= elf32_frv_howto_table
+ r_type
;
3016 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3021 case R_FRV_GOTTLSDESC12
:
3022 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3024 /* Is this an lddi instruction? */
3025 if ((insn
& (unsigned long)0x01fc0000) != 0x00cc0000)
3027 r
= info
->callbacks
->warning
3029 _("R_FRV_GOTTLSDESC12 not applied to an lddi instruction"),
3030 name
, input_bfd
, input_section
, rel
->r_offset
);
3034 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3035 relocation
+ rel
->r_addend
)
3036 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3039 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3040 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3041 Preserve the packing bit. */
3042 insn
= (insn
& (unsigned long)0x80000000)
3043 | ((insn
+ (unsigned long)0x02000000)
3044 & (unsigned long)0x7e000000);
3045 insn
|= (unsigned long)0x00fc0000;
3046 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3048 r_type
= R_FRV_TLSMOFFLO
;
3049 howto
= elf32_frv_howto_table
+ r_type
;
3050 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3053 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3054 relocation
+ rel
->r_addend
))
3056 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3057 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3058 Preserve the packing bit. */
3059 insn
= (insn
& (unsigned long)0x80000000)
3060 | ((insn
+ (unsigned long)0x02000000)
3061 & (unsigned long)0x7e000000);
3062 insn
|= (unsigned long)0x00f80000;
3063 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3065 r_type
= R_FRV_TLSMOFFHI
;
3066 howto
= elf32_frv_howto_table
+ r_type
;
3067 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3070 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3072 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3073 with ldi @(grB, #gottlsoff12(symbol+offset),
3074 gr<C+1>. Preserve the packing bit. If gottlsoff12
3075 overflows, we'll error out, but that's sort-of ok,
3076 since we'd started with gottlsdesc12, that's actually
3077 more demanding. Compiling with -fPIE instead of
3078 -fpie would fix it; linking with --relax should fix
3080 insn
= (insn
& (unsigned long)0x80cbf000)
3081 | ((insn
+ (unsigned long)0x02000000)
3082 & (unsigned long)0x7e000000);
3083 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3085 r_type
= R_FRV_GOTTLSOFF12
;
3086 howto
= elf32_frv_howto_table
+ r_type
;
3087 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3092 case R_FRV_GOTTLSDESCHI
:
3093 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3095 /* Is this a sethi instruction? */
3096 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3098 r
= info
->callbacks
->warning
3100 _("R_FRV_GOTTLSDESCHI not applied to a sethi instruction"),
3101 name
, input_bfd
, input_section
, rel
->r_offset
);
3105 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3106 relocation
+ rel
->r_addend
)
3107 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3108 && IN_RANGE_FOR_SETLOS_P (picrel
->tlsoff_entry
)))
3110 /* Replace sethi with a nop. Preserve the packing bit. */
3111 insn
&= (unsigned long)0x80000000;
3112 insn
|= (unsigned long)0x00880000;
3113 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3115 /* Nothing to relocate. */
3119 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3121 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3122 r_type
= R_FRV_GOTTLSOFFHI
;
3123 howto
= elf32_frv_howto_table
+ r_type
;
3124 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3129 case R_FRV_GOTTLSDESCLO
:
3130 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3132 /* Is this a setlo or setlos instruction? */
3133 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3135 r
= info
->callbacks
->warning
3137 _("R_FRV_GOTTLSDESCLO"
3138 " not applied to a setlo or setlos instruction"),
3139 name
, input_bfd
, input_section
, rel
->r_offset
);
3143 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3144 relocation
+ rel
->r_addend
)
3145 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3146 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3148 /* Replace setlo/setlos with a nop. Preserve the
3150 insn
&= (unsigned long)0x80000000;
3151 insn
|= (unsigned long)0x00880000;
3152 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3154 /* Nothing to relocate. */
3158 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3160 /* If the corresponding sethi (if it exists) decayed
3161 to a nop, make sure this becomes (or already is) a
3162 setlos, not setlo. */
3163 if (IN_RANGE_FOR_SETLOS_P (picrel
->tlsoff_entry
))
3165 insn
|= (unsigned long)0x00080000;
3166 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3169 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3170 r_type
= R_FRV_GOTTLSOFFLO
;
3171 howto
= elf32_frv_howto_table
+ r_type
;
3172 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3177 case R_FRV_TLSDESC_RELAX
:
3178 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3180 /* Is this an ldd instruction? */
3181 if ((insn
& (unsigned long)0x01fc0fc0) != 0x00080140)
3183 r
= info
->callbacks
->warning
3185 _("R_FRV_TLSDESC_RELAX not applied to an ldd instruction"),
3186 name
, input_bfd
, input_section
, rel
->r_offset
);
3190 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3191 relocation
+ rel
->r_addend
)
3192 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3195 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3196 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3197 Preserve the packing bit. */
3198 insn
= (insn
& (unsigned long)0x80000000)
3199 | ((insn
+ (unsigned long)0x02000000)
3200 & (unsigned long)0x7e000000);
3201 insn
|= (unsigned long)0x00fc0000;
3202 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3204 r_type
= R_FRV_TLSMOFFLO
;
3205 howto
= elf32_frv_howto_table
+ r_type
;
3206 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3209 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3210 relocation
+ rel
->r_addend
))
3212 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3213 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3214 Preserve the packing bit. */
3215 insn
= (insn
& (unsigned long)0x80000000)
3216 | ((insn
+ (unsigned long)0x02000000)
3217 & (unsigned long)0x7e000000);
3218 insn
|= (unsigned long)0x00f80000;
3219 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3221 r_type
= R_FRV_TLSMOFFHI
;
3222 howto
= elf32_frv_howto_table
+ r_type
;
3223 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3226 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3227 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
))
3229 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3230 with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>.
3231 Preserve the packing bit. */
3232 insn
= (insn
& (unsigned long)0x8003f000)
3233 | (unsigned long)0x00c80000
3234 | ((insn
+ (unsigned long)0x02000000)
3235 & (unsigned long)0x7e000000);
3236 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3238 r_type
= R_FRV_GOTTLSOFF12
;
3239 howto
= elf32_frv_howto_table
+ r_type
;
3240 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3243 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3245 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3246 with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>.
3247 Preserve the packing bit. */
3248 insn
= (insn
& (unsigned long)0x81ffffbf)
3249 | ((insn
+ (unsigned long)0x02000000)
3250 & (unsigned long)0x7e000000);
3251 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3253 /* #tlsoff(symbol+offset) is just a relaxation
3254 annotation, so there's nothing left to
3261 case R_FRV_GETTLSOFF_RELAX
:
3262 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3264 /* Is this a calll or callil instruction? */
3265 if ((insn
& (unsigned long)0x7ff80fc0) != 0x02300000)
3267 r
= info
->callbacks
->warning
3269 _("R_FRV_GETTLSOFF_RELAX"
3270 " not applied to a calll instruction"),
3271 name
, input_bfd
, input_section
, rel
->r_offset
);
3275 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3276 relocation
+ rel
->r_addend
)
3277 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3280 /* Replace calll with a nop. Preserve the packing bit. */
3281 insn
&= (unsigned long)0x80000000;
3282 insn
|= (unsigned long)0x00880000;
3283 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3285 /* Nothing to relocate. */
3289 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3290 relocation
+ rel
->r_addend
))
3292 /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9.
3293 Preserve the packing bit. */
3294 insn
&= (unsigned long)0x80000000;
3295 insn
|= (unsigned long)0x12f40000;
3296 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3298 r_type
= R_FRV_TLSMOFFLO
;
3299 howto
= elf32_frv_howto_table
+ r_type
;
3300 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3303 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3305 /* Replace calll with a nop. Preserve the packing bit. */
3306 insn
&= (unsigned long)0x80000000;
3307 insn
|= (unsigned long)0x00880000;
3308 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3310 /* Nothing to relocate. */
3316 case R_FRV_GOTTLSOFF12
:
3317 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3319 /* Is this an ldi instruction? */
3320 if ((insn
& (unsigned long)0x01fc0000) != 0x00c80000)
3322 r
= info
->callbacks
->warning
3324 _("R_FRV_GOTTLSOFF12 not applied to an ldi instruction"),
3325 name
, input_bfd
, input_section
, rel
->r_offset
);
3329 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3330 relocation
+ rel
->r_addend
))
3332 /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC
3333 with setlos #tlsmofflo(symbol+offset), grC.
3334 Preserve the packing bit. */
3335 insn
&= (unsigned long)0xfe000000;
3336 insn
|= (unsigned long)0x00fc0000;
3337 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3339 r_type
= R_FRV_TLSMOFFLO
;
3340 howto
= elf32_frv_howto_table
+ r_type
;
3341 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3346 case R_FRV_GOTTLSOFFHI
:
3347 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3349 /* Is this a sethi instruction? */
3350 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3352 r
= info
->callbacks
->warning
3354 _("R_FRV_GOTTLSOFFHI not applied to a sethi instruction"),
3355 name
, input_bfd
, input_section
, rel
->r_offset
);
3359 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3360 relocation
+ rel
->r_addend
)
3361 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3362 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3364 /* Replace sethi with a nop. Preserve the packing bit. */
3365 insn
&= (unsigned long)0x80000000;
3366 insn
|= (unsigned long)0x00880000;
3367 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3369 /* Nothing to relocate. */
3375 case R_FRV_GOTTLSOFFLO
:
3376 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3378 /* Is this a setlo or setlos instruction? */
3379 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3381 r
= info
->callbacks
->warning
3383 _("R_FRV_GOTTLSOFFLO"
3384 " not applied to a setlo or setlos instruction"),
3385 name
, input_bfd
, input_section
, rel
->r_offset
);
3389 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3390 relocation
+ rel
->r_addend
)
3391 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3392 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3394 /* Replace setlo/setlos with a nop. Preserve the
3396 insn
&= (unsigned long)0x80000000;
3397 insn
|= (unsigned long)0x00880000;
3398 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3400 /* Nothing to relocate. */
3406 case R_FRV_TLSOFF_RELAX
:
3407 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3409 /* Is this an ld instruction? */
3410 if ((insn
& (unsigned long)0x01fc0fc0) != 0x00080100)
3412 r
= info
->callbacks
->warning
3414 _("R_FRV_TLSOFF_RELAX not applied to an ld instruction"),
3415 name
, input_bfd
, input_section
, rel
->r_offset
);
3419 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3420 relocation
+ rel
->r_addend
))
3422 /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC
3423 with setlos #tlsmofflo(symbol+offset), grC.
3424 Preserve the packing bit. */
3425 insn
&= (unsigned long)0xfe000000;
3426 insn
|= (unsigned long)0x00fc0000;
3427 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3429 r_type
= R_FRV_TLSMOFFLO
;
3430 howto
= elf32_frv_howto_table
+ r_type
;
3431 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3434 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3435 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
))
3437 /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC
3438 with ldi @(grB, #gottlsoff12(symbol+offset), grC.
3439 Preserve the packing bit. */
3440 insn
= (insn
& (unsigned long)0xfe03f000)
3441 | (unsigned long)0x00c80000;;
3442 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3444 r_type
= R_FRV_GOTTLSOFF12
;
3445 howto
= elf32_frv_howto_table
+ r_type
;
3446 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3451 case R_FRV_TLSMOFFHI
:
3452 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3454 /* Is this a sethi instruction? */
3455 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3457 r
= info
->callbacks
->warning
3459 _("R_FRV_TLSMOFFHI not applied to a sethi instruction"),
3460 name
, input_bfd
, input_section
, rel
->r_offset
);
3464 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3467 /* Replace sethi with a nop. Preserve the packing bit. */
3468 insn
&= (unsigned long)0x80000000;
3469 insn
|= (unsigned long)0x00880000;
3470 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3472 /* Nothing to relocate. */
3478 case R_FRV_TLSMOFFLO
:
3479 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3481 /* Is this a setlo or setlos instruction? */
3482 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3484 r
= info
->callbacks
->warning
3487 " not applied to a setlo or setlos instruction"),
3488 name
, input_bfd
, input_section
, rel
->r_offset
);
3492 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3494 /* If the corresponding sethi (if it exists) decayed
3495 to a nop, make sure this becomes (or already is) a
3496 setlos, not setlo. */
3498 insn
|= (unsigned long)0x00080000;
3499 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3505 There's nothing to relax in these:
3521 check_segment
[0] = isec_segment
;
3522 if (! IS_FDPIC (output_bfd
))
3523 check_segment
[1] = isec_segment
;
3524 else if (picrel
->plt
)
3526 relocation
= frvfdpic_plt_section (info
)->output_section
->vma
3527 + frvfdpic_plt_section (info
)->output_offset
3528 + picrel
->plt_entry
;
3529 check_segment
[1] = plt_segment
;
3531 /* We don't want to warn on calls to undefined weak symbols,
3532 as calls to them must be protected by non-NULL tests
3533 anyway, and unprotected calls would invoke undefined
3535 else if (picrel
->symndx
== -1
3536 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefweak
)
3537 check_segment
[1] = check_segment
[0];
3539 check_segment
[1] = sec
3540 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3547 relocation
= picrel
->got_entry
;
3548 check_segment
[0] = check_segment
[1] = got_segment
;
3551 case R_FRV_FUNCDESC_GOT12
:
3552 case R_FRV_FUNCDESC_GOTHI
:
3553 case R_FRV_FUNCDESC_GOTLO
:
3554 relocation
= picrel
->fdgot_entry
;
3555 check_segment
[0] = check_segment
[1] = got_segment
;
3558 case R_FRV_GOTOFFHI
:
3559 case R_FRV_GOTOFF12
:
3560 case R_FRV_GOTOFFLO
:
3561 relocation
-= frvfdpic_got_section (info
)->output_section
->vma
3562 + frvfdpic_got_section (info
)->output_offset
3563 + frvfdpic_got_initial_offset (info
);
3564 check_segment
[0] = got_segment
;
3565 check_segment
[1] = sec
3566 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3570 case R_FRV_FUNCDESC_GOTOFF12
:
3571 case R_FRV_FUNCDESC_GOTOFFHI
:
3572 case R_FRV_FUNCDESC_GOTOFFLO
:
3573 relocation
= picrel
->fd_entry
;
3574 check_segment
[0] = check_segment
[1] = got_segment
;
3577 case R_FRV_FUNCDESC
:
3580 bfd_vma addend
= rel
->r_addend
;
3582 if (! (h
&& h
->root
.type
== bfd_link_hash_undefweak
3583 && FRVFDPIC_SYM_LOCAL (info
, h
)))
3585 /* If the symbol is dynamic and there may be dynamic
3586 symbol resolution because we are or are linked with a
3587 shared library, emit a FUNCDESC relocation such that
3588 the dynamic linker will allocate the function
3589 descriptor. If the symbol needs a non-local function
3590 descriptor but binds locally (e.g., its visibility is
3591 protected, emit a dynamic relocation decayed to
3593 if (h
&& ! FRVFDPIC_FUNCDESC_LOCAL (info
, h
)
3594 && FRVFDPIC_SYM_LOCAL (info
, h
)
3595 && !(info
->executable
&& !info
->pie
))
3597 dynindx
= elf_section_data (h
->root
.u
.def
.section
3598 ->output_section
)->dynindx
;
3599 addend
+= h
->root
.u
.def
.section
->output_offset
3600 + h
->root
.u
.def
.value
;
3602 else if (h
&& ! FRVFDPIC_FUNCDESC_LOCAL (info
, h
))
3606 info
->callbacks
->warning
3607 (info
, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"),
3608 name
, input_bfd
, input_section
, rel
->r_offset
);
3611 dynindx
= h
->dynindx
;
3615 /* Otherwise, we know we have a private function
3616 descriptor, so reference it directly. */
3617 BFD_ASSERT (picrel
->privfd
);
3619 dynindx
= elf_section_data (frvfdpic_got_section (info
)
3620 ->output_section
)->dynindx
;
3621 addend
= frvfdpic_got_section (info
)->output_offset
3622 + frvfdpic_got_initial_offset (info
)
3626 /* If there is room for dynamic symbol resolution, emit
3627 the dynamic relocation. However, if we're linking an
3628 executable at a fixed location, we won't have emitted a
3629 dynamic symbol entry for the got section, so idx will
3630 be zero, which means we can and should compute the
3631 address of the private descriptor ourselves. */
3632 if (info
->executable
&& !info
->pie
3633 && (!h
|| FRVFDPIC_FUNCDESC_LOCAL (info
, h
)))
3635 addend
+= frvfdpic_got_section (info
)->output_section
->vma
;
3636 if ((bfd_get_section_flags (output_bfd
,
3637 input_section
->output_section
)
3638 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3642 if (_frvfdpic_osec_readonly_p (output_bfd
,
3646 info
->callbacks
->warning
3648 _("cannot emit fixups in read-only section"),
3649 name
, input_bfd
, input_section
, rel
->r_offset
);
3653 offset
= _bfd_elf_section_offset
3655 input_section
, rel
->r_offset
);
3657 if (offset
!= (bfd_vma
)-1)
3658 _frvfdpic_add_rofixup (output_bfd
,
3659 frvfdpic_gotfixup_section
3661 offset
+ input_section
3662 ->output_section
->vma
3663 + input_section
->output_offset
,
3667 else if ((bfd_get_section_flags (output_bfd
,
3668 input_section
->output_section
)
3669 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3673 if (_frvfdpic_osec_readonly_p (output_bfd
,
3677 info
->callbacks
->warning
3679 _("cannot emit dynamic relocations in read-only section"),
3680 name
, input_bfd
, input_section
, rel
->r_offset
);
3684 offset
= _bfd_elf_section_offset
3686 input_section
, rel
->r_offset
);
3688 if (offset
!= (bfd_vma
)-1)
3689 _frvfdpic_add_dyn_reloc (output_bfd
,
3690 frvfdpic_gotrel_section (info
),
3691 offset
+ input_section
3692 ->output_section
->vma
3693 + input_section
->output_offset
,
3694 r_type
, dynindx
, addend
, picrel
);
3697 addend
+= frvfdpic_got_section (info
)->output_section
->vma
;
3700 /* We want the addend in-place because dynamic
3701 relocations are REL. Setting relocation to it should
3702 arrange for it to be installed. */
3703 relocation
= addend
- rel
->r_addend
;
3705 check_segment
[0] = check_segment
[1] = got_segment
;
3709 if (! IS_FDPIC (output_bfd
))
3711 check_segment
[0] = check_segment
[1] = -1;
3715 case R_FRV_FUNCDESC_VALUE
:
3718 bfd_vma addend
= rel
->r_addend
;
3720 /* If the symbol is dynamic but binds locally, use
3722 if (h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
))
3724 if (addend
&& r_type
== R_FRV_FUNCDESC_VALUE
)
3726 info
->callbacks
->warning
3727 (info
, _("R_FRV_FUNCDESC_VALUE references dynamic symbol with nonzero addend"),
3728 name
, input_bfd
, input_section
, rel
->r_offset
);
3731 dynindx
= h
->dynindx
;
3736 addend
+= h
->root
.u
.def
.value
;
3738 addend
+= sym
->st_value
;
3740 addend
+= osec
->output_offset
;
3741 if (osec
&& osec
->output_section
3742 && ! bfd_is_abs_section (osec
->output_section
)
3743 && ! bfd_is_und_section (osec
->output_section
))
3744 dynindx
= elf_section_data (osec
->output_section
)->dynindx
;
3749 /* If we're linking an executable at a fixed address, we
3750 can omit the dynamic relocation as long as the symbol
3751 is defined in the current link unit (which is implied
3752 by its output section not being NULL). */
3753 if (info
->executable
&& !info
->pie
3754 && (!h
|| FRVFDPIC_SYM_LOCAL (info
, h
)))
3757 addend
+= osec
->output_section
->vma
;
3758 if (IS_FDPIC (input_bfd
)
3759 && (bfd_get_section_flags (output_bfd
,
3760 input_section
->output_section
)
3761 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3763 if (_frvfdpic_osec_readonly_p (output_bfd
,
3767 info
->callbacks
->warning
3769 _("cannot emit fixups in read-only section"),
3770 name
, input_bfd
, input_section
, rel
->r_offset
);
3773 if (!h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
3775 bfd_vma offset
= _bfd_elf_section_offset
3777 input_section
, rel
->r_offset
);
3779 if (offset
!= (bfd_vma
)-1)
3781 _frvfdpic_add_rofixup (output_bfd
,
3782 frvfdpic_gotfixup_section
3784 offset
+ input_section
3785 ->output_section
->vma
3786 + input_section
->output_offset
,
3788 if (r_type
== R_FRV_FUNCDESC_VALUE
)
3789 _frvfdpic_add_rofixup
3791 frvfdpic_gotfixup_section (info
),
3793 + input_section
->output_section
->vma
3794 + input_section
->output_offset
+ 4, picrel
);
3801 if ((bfd_get_section_flags (output_bfd
,
3802 input_section
->output_section
)
3803 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3807 if (_frvfdpic_osec_readonly_p (output_bfd
,
3811 info
->callbacks
->warning
3813 _("cannot emit dynamic relocations in read-only section"),
3814 name
, input_bfd
, input_section
, rel
->r_offset
);
3818 offset
= _bfd_elf_section_offset
3820 input_section
, rel
->r_offset
);
3822 if (offset
!= (bfd_vma
)-1)
3823 _frvfdpic_add_dyn_reloc (output_bfd
,
3824 frvfdpic_gotrel_section (info
),
3825 offset
+ input_section
3826 ->output_section
->vma
3827 + input_section
->output_offset
,
3828 r_type
, dynindx
, addend
, picrel
);
3831 addend
+= osec
->output_section
->vma
;
3832 /* We want the addend in-place because dynamic
3833 relocations are REL. Setting relocation to it
3834 should arrange for it to be installed. */
3835 relocation
= addend
- rel
->r_addend
;
3838 if (r_type
== R_FRV_FUNCDESC_VALUE
)
3840 /* If we've omitted the dynamic relocation, just emit
3841 the fixed addresses of the symbol and of the local
3843 if (info
->executable
&& !info
->pie
3844 && (!h
|| FRVFDPIC_SYM_LOCAL (info
, h
)))
3845 bfd_put_32 (output_bfd
,
3846 frvfdpic_got_section (info
)->output_section
->vma
3847 + frvfdpic_got_section (info
)->output_offset
3848 + frvfdpic_got_initial_offset (info
),
3849 contents
+ rel
->r_offset
+ 4);
3851 /* A function descriptor used for lazy or local
3852 resolving is initialized such that its high word
3853 contains the output section index in which the
3854 PLT entries are located, and the low word
3855 contains the offset of the lazy PLT entry entry
3856 point into that section. */
3857 bfd_put_32 (output_bfd
,
3858 h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
)
3860 : _frvfdpic_osec_to_segment (output_bfd
,
3863 contents
+ rel
->r_offset
+ 4);
3866 check_segment
[0] = check_segment
[1] = got_segment
;
3870 case R_FRV_GPRELU12
:
3874 check_segment
[0] = gprel_segment
;
3875 check_segment
[1] = sec
3876 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3880 case R_FRV_GETTLSOFF
:
3881 relocation
= frvfdpic_plt_section (info
)->output_section
->vma
3882 + frvfdpic_plt_section (info
)->output_offset
3883 + picrel
->tlsplt_entry
;
3884 BFD_ASSERT (picrel
->tlsplt_entry
!= (bfd_vma
)-1
3885 && picrel
->tlsdesc_entry
);
3886 check_segment
[0] = isec_segment
;
3887 check_segment
[1] = plt_segment
;
3890 case R_FRV_GOTTLSDESC12
:
3891 case R_FRV_GOTTLSDESCHI
:
3892 case R_FRV_GOTTLSDESCLO
:
3893 BFD_ASSERT (picrel
->tlsdesc_entry
);
3894 relocation
= picrel
->tlsdesc_entry
;
3895 check_segment
[0] = tls_segment
;
3896 check_segment
[1] = sec
3897 && ! bfd_is_abs_section (sec
)
3898 && ! bfd_is_und_section (sec
)
3899 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3903 case R_FRV_TLSMOFF12
:
3904 case R_FRV_TLSMOFFHI
:
3905 case R_FRV_TLSMOFFLO
:
3907 check_segment
[0] = tls_segment
;
3909 check_segment
[1] = -1;
3910 else if (bfd_is_abs_section (sec
)
3911 || bfd_is_und_section (sec
))
3914 check_segment
[1] = tls_segment
;
3916 else if (sec
->output_section
)
3918 relocation
-= tls_biased_base (info
);
3920 _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
);
3923 check_segment
[1] = -1;
3926 case R_FRV_GOTTLSOFF12
:
3927 case R_FRV_GOTTLSOFFHI
:
3928 case R_FRV_GOTTLSOFFLO
:
3929 BFD_ASSERT (picrel
->tlsoff_entry
);
3930 relocation
= picrel
->tlsoff_entry
;
3931 check_segment
[0] = tls_segment
;
3932 check_segment
[1] = sec
3933 && ! bfd_is_abs_section (sec
)
3934 && ! bfd_is_und_section (sec
)
3935 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3939 case R_FRV_TLSDESC_VALUE
:
3941 /* These shouldn't be present in input object files. */
3942 check_segment
[0] = check_segment
[1] = isec_segment
;
3945 case R_FRV_TLSDESC_RELAX
:
3946 case R_FRV_GETTLSOFF_RELAX
:
3947 case R_FRV_TLSOFF_RELAX
:
3948 /* These are just annotations for relaxation, nothing to do
3953 check_segment
[0] = isec_segment
;
3954 check_segment
[1] = sec
3955 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3960 if (check_segment
[0] != check_segment
[1] && IS_FDPIC (output_bfd
))
3962 /* If you take this out, remove the #error from fdpic-static-6.d
3963 in the ld testsuite. */
3964 /* This helps catch problems in GCC while we can't do more
3965 than static linking. The idea is to test whether the
3966 input file basename is crt0.o only once. */
3967 if (silence_segment_error
== 1)
3968 silence_segment_error
=
3969 (strlen (input_bfd
->filename
) == 6
3970 && strcmp (input_bfd
->filename
, "crt0.o") == 0)
3971 || (strlen (input_bfd
->filename
) > 6
3972 && strcmp (input_bfd
->filename
3973 + strlen (input_bfd
->filename
) - 7,
3976 if (!silence_segment_error
3977 /* We don't want duplicate errors for undefined
3979 && !(picrel
&& picrel
->symndx
== -1
3980 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefined
))
3982 if (info
->shared
|| info
->pie
)
3983 (*_bfd_error_handler
)
3984 (_("%B(%A+0x%lx): reloc against `%s': %s"),
3985 input_bfd
, input_section
, (long)rel
->r_offset
, name
,
3986 _("relocation references a different segment"));
3988 info
->callbacks
->warning
3990 _("relocation references a different segment"),
3991 name
, input_bfd
, input_section
, rel
->r_offset
);
3993 if (!silence_segment_error
&& (info
->shared
|| info
->pie
))
3995 /* PR 6446: EF_FRV_PIC should be cleared if
3996 there are any inter-segment relocations. */
3997 elf_elfheader (output_bfd
)->e_flags
&= ~ EF_FRV_PIC
;
4002 case R_FRV_GOTOFFHI
:
4003 case R_FRV_TLSMOFFHI
:
4004 /* We need the addend to be applied before we shift the
4006 relocation
+= rel
->r_addend
;
4009 case R_FRV_FUNCDESC_GOTHI
:
4010 case R_FRV_FUNCDESC_GOTOFFHI
:
4011 case R_FRV_GOTTLSOFFHI
:
4012 case R_FRV_GOTTLSDESCHI
:
4017 case R_FRV_FUNCDESC_GOTLO
:
4018 case R_FRV_GOTOFFLO
:
4019 case R_FRV_FUNCDESC_GOTOFFLO
:
4020 case R_FRV_GOTTLSOFFLO
:
4021 case R_FRV_GOTTLSDESCLO
:
4022 case R_FRV_TLSMOFFLO
:
4023 relocation
&= 0xffff;
4033 if (! IS_FDPIC (output_bfd
) || ! picrel
->plt
)
4037 /* When referencing a GOT entry, a function descriptor or a
4038 PLT, we don't want the addend to apply to the reference,
4039 but rather to the referenced symbol. The actual entry
4040 will have already been created taking the addend into
4041 account, so cancel it out here. */
4045 case R_FRV_FUNCDESC_GOT12
:
4046 case R_FRV_FUNCDESC_GOTHI
:
4047 case R_FRV_FUNCDESC_GOTLO
:
4048 case R_FRV_FUNCDESC_GOTOFF12
:
4049 case R_FRV_FUNCDESC_GOTOFFHI
:
4050 case R_FRV_FUNCDESC_GOTOFFLO
:
4051 case R_FRV_GETTLSOFF
:
4052 case R_FRV_GOTTLSDESC12
:
4053 case R_FRV_GOTTLSDESCHI
:
4054 case R_FRV_GOTTLSDESCLO
:
4055 case R_FRV_GOTTLSOFF12
:
4056 case R_FRV_GOTTLSOFFHI
:
4057 case R_FRV_GOTTLSOFFLO
:
4058 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
4059 here, since we do want to apply the addend to the others.
4060 Note that we've applied the addend to GOTOFFHI before we
4061 shifted it right. */
4062 case R_FRV_GOTOFFHI
:
4063 case R_FRV_TLSMOFFHI
:
4064 relocation
-= rel
->r_addend
;
4071 if (r_type
== R_FRV_HI16
)
4072 r
= elf32_frv_relocate_hi16 (input_bfd
, rel
, contents
, relocation
);
4074 else if (r_type
== R_FRV_LO16
)
4075 r
= elf32_frv_relocate_lo16 (input_bfd
, rel
, contents
, relocation
);
4077 else if (r_type
== R_FRV_LABEL24
|| r_type
== R_FRV_GETTLSOFF
)
4078 r
= elf32_frv_relocate_label24 (input_bfd
, input_section
, rel
,
4079 contents
, relocation
);
4081 else if (r_type
== R_FRV_GPREL12
)
4082 r
= elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, rel
,
4083 contents
, relocation
);
4085 else if (r_type
== R_FRV_GPRELU12
)
4086 r
= elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, rel
,
4087 contents
, relocation
);
4089 else if (r_type
== R_FRV_GPRELLO
)
4090 r
= elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, rel
,
4091 contents
, relocation
);
4093 else if (r_type
== R_FRV_GPRELHI
)
4094 r
= elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, rel
,
4095 contents
, relocation
);
4097 else if (r_type
== R_FRV_TLSOFF
4098 || r_type
== R_FRV_TLSDESC_VALUE
)
4099 r
= bfd_reloc_notsupported
;
4102 r
= frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
4105 if (r
!= bfd_reloc_ok
)
4107 const char * msg
= (const char *) NULL
;
4111 case bfd_reloc_overflow
:
4112 r
= info
->callbacks
->reloc_overflow
4113 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4114 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
4117 case bfd_reloc_undefined
:
4118 r
= info
->callbacks
->undefined_symbol
4119 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
4122 case bfd_reloc_outofrange
:
4123 msg
= _("internal error: out of range error");
4126 case bfd_reloc_notsupported
:
4127 msg
= _("internal error: unsupported relocation error");
4130 case bfd_reloc_dangerous
:
4131 msg
= _("internal error: dangerous relocation");
4135 msg
= _("internal error: unknown error");
4141 (*_bfd_error_handler
)
4142 (_("%B(%A+0x%lx): reloc against `%s': %s"),
4143 input_bfd
, input_section
, (long)rel
->r_offset
, name
, msg
);
4155 /* Return the section that should be marked against GC for a given
4159 elf32_frv_gc_mark_hook (asection
*sec
,
4160 struct bfd_link_info
*info
,
4161 Elf_Internal_Rela
*rel
,
4162 struct elf_link_hash_entry
*h
,
4163 Elf_Internal_Sym
*sym
)
4166 switch (ELF32_R_TYPE (rel
->r_info
))
4168 case R_FRV_GNU_VTINHERIT
:
4169 case R_FRV_GNU_VTENTRY
:
4173 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
4176 /* Hook called by the linker routine which adds symbols from an object
4177 file. We use it to put .comm items in .scomm, and not .comm. */
4180 elf32_frv_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
4182 struct bfd_link_info
*info
;
4183 Elf_Internal_Sym
*sym
;
4184 const char **namep ATTRIBUTE_UNUSED
;
4185 flagword
*flagsp ATTRIBUTE_UNUSED
;
4189 if (sym
->st_shndx
== SHN_COMMON
4190 && !info
->relocatable
4191 && (int)sym
->st_size
<= (int)bfd_get_gp_size (abfd
))
4193 /* Common symbols less than or equal to -G nn bytes are
4194 automatically put into .sbss. */
4196 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
4200 scomm
= bfd_make_section_with_flags (abfd
, ".scommon",
4203 | SEC_LINKER_CREATED
));
4209 *valp
= sym
->st_size
;
4215 /* We need dynamic symbols for every section, since segments can
4216 relocate independently. */
4218 _frvfdpic_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4219 struct bfd_link_info
*info
4221 asection
*p ATTRIBUTE_UNUSED
)
4223 switch (elf_section_data (p
)->this_hdr
.sh_type
)
4227 /* If sh_type is yet undecided, assume it could be
4228 SHT_PROGBITS/SHT_NOBITS. */
4232 /* There shouldn't be section relative relocations
4233 against any other section. */
4239 /* Create a .got section, as well as its additional info field. This
4240 is almost entirely copied from
4241 elflink.c:_bfd_elf_create_got_section(). */
4244 _frv_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4246 flagword flags
, pltflags
;
4248 struct elf_link_hash_entry
*h
;
4249 struct bfd_link_hash_entry
*bh
;
4250 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4254 /* This function may be called more than once. */
4255 s
= bfd_get_section_by_name (abfd
, ".got");
4256 if (s
!= NULL
&& (s
->flags
& SEC_LINKER_CREATED
) != 0)
4259 /* Machine specific: although pointers are 32-bits wide, we want the
4260 GOT to be aligned to a 64-bit boundary, such that function
4261 descriptors in it can be accessed with 64-bit loads and
4265 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4266 | SEC_LINKER_CREATED
);
4269 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
4271 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
4274 if (bed
->want_got_plt
)
4276 s
= bfd_make_section_with_flags (abfd
, ".got.plt", flags
);
4278 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
4282 if (bed
->want_got_sym
)
4284 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
4285 (or .got.plt) section. We don't do this in the linker script
4286 because we don't want to define the symbol if we are not creating
4287 a global offset table. */
4288 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
, "_GLOBAL_OFFSET_TABLE_");
4289 elf_hash_table (info
)->hgot
= h
;
4293 /* Machine-specific: we want the symbol for executables as
4295 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4299 /* The first bit of the global offset table is the header. */
4300 s
->size
+= bed
->got_header_size
;
4302 /* This is the machine-specific part. Create and initialize section
4303 data for the got. */
4304 if (IS_FDPIC (abfd
))
4306 frvfdpic_got_section (info
) = s
;
4307 frvfdpic_relocs_info (info
) = htab_try_create (1,
4308 frvfdpic_relocs_info_hash
,
4309 frvfdpic_relocs_info_eq
,
4311 if (! frvfdpic_relocs_info (info
))
4314 s
= bfd_make_section_with_flags (abfd
, ".rel.got",
4315 (flags
| SEC_READONLY
));
4317 || ! bfd_set_section_alignment (abfd
, s
, 2))
4320 frvfdpic_gotrel_section (info
) = s
;
4322 /* Machine-specific. */
4323 s
= bfd_make_section_with_flags (abfd
, ".rofixup",
4324 (flags
| SEC_READONLY
));
4326 || ! bfd_set_section_alignment (abfd
, s
, 2))
4329 frvfdpic_gotfixup_section (info
) = s
;
4336 flags
= BSF_GLOBAL
| BSF_WEAK
;
4339 /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it
4340 turns out that we're linking with a different linker script, the
4341 linker script will override it. */
4343 if (!(_bfd_generic_link_add_one_symbol
4344 (info
, abfd
, "_gp", flags
, s
, offset
, (const char *) NULL
, FALSE
,
4345 bed
->collect
, &bh
)))
4347 h
= (struct elf_link_hash_entry
*) bh
;
4349 h
->type
= STT_OBJECT
;
4350 /* h->other = STV_HIDDEN; */ /* Should we? */
4352 /* Machine-specific: we want the symbol for executables as well. */
4353 if (IS_FDPIC (abfd
) && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
4356 if (!IS_FDPIC (abfd
))
4359 /* FDPIC supports Thread Local Storage, and this may require a
4360 procedure linkage table for TLS PLT entries. */
4362 /* This is mostly copied from
4363 elflink.c:_bfd_elf_create_dynamic_sections(). */
4366 pltflags
|= SEC_CODE
;
4367 if (bed
->plt_not_loaded
)
4368 pltflags
&= ~ (SEC_CODE
| SEC_LOAD
| SEC_HAS_CONTENTS
);
4369 if (bed
->plt_readonly
)
4370 pltflags
|= SEC_READONLY
;
4372 s
= bfd_make_section_with_flags (abfd
, ".plt", pltflags
);
4374 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
4376 /* FRV-specific: remember it. */
4377 frvfdpic_plt_section (info
) = s
;
4379 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
4381 if (bed
->want_plt_sym
)
4383 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
4384 "_PROCEDURE_LINKAGE_TABLE_");
4385 elf_hash_table (info
)->hplt
= h
;
4390 /* FRV-specific: we want rel relocations for the plt. */
4391 s
= bfd_make_section_with_flags (abfd
, ".rel.plt",
4392 flags
| SEC_READONLY
);
4394 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
4396 /* FRV-specific: remember it. */
4397 frvfdpic_pltrel_section (info
) = s
;
4402 /* Make sure the got and plt sections exist, and that our pointers in
4403 the link hash table point to them. */
4406 elf32_frvfdpic_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
4408 /* This is mostly copied from
4409 elflink.c:_bfd_elf_create_dynamic_sections(). */
4412 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4414 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4415 | SEC_LINKER_CREATED
);
4417 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
4418 .rel[a].bss sections. */
4420 /* FRV-specific: we want to create the GOT and the PLT in the FRV
4422 if (! _frv_create_got_section (abfd
, info
))
4425 /* FRV-specific: make sure we created everything we wanted. */
4426 BFD_ASSERT (frvfdpic_got_section (info
) && frvfdpic_gotrel_section (info
)
4427 && frvfdpic_gotfixup_section (info
)
4428 && frvfdpic_plt_section (info
)
4429 && frvfdpic_pltrel_section (info
));
4431 if (bed
->want_dynbss
)
4433 /* The .dynbss section is a place to put symbols which are defined
4434 by dynamic objects, are referenced by regular objects, and are
4435 not functions. We must allocate space for them in the process
4436 image and use a R_*_COPY reloc to tell the dynamic linker to
4437 initialize them at run time. The linker script puts the .dynbss
4438 section into the .bss section of the final image. */
4439 s
= bfd_make_section_with_flags (abfd
, ".dynbss",
4440 SEC_ALLOC
| SEC_LINKER_CREATED
);
4444 /* The .rel[a].bss section holds copy relocs. This section is not
4445 normally needed. We need to create it here, though, so that the
4446 linker will map it to an output section. We can't just create it
4447 only if we need it, because we will not know whether we need it
4448 until we have seen all the input files, and the first time the
4449 main linker code calls BFD after examining all the input files
4450 (size_dynamic_sections) the input sections have already been
4451 mapped to the output sections. If the section turns out not to
4452 be needed, we can discard it later. We will never need this
4453 section when generating a shared object, since they do not use
4457 s
= bfd_make_section_with_flags (abfd
,
4458 (bed
->default_use_rela_p
4459 ? ".rela.bss" : ".rel.bss"),
4460 flags
| SEC_READONLY
);
4462 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
4470 /* Compute the total GOT and PLT size required by each symbol in each
4471 range. Symbols may require up to 4 words in the GOT: an entry
4472 pointing to the symbol, an entry pointing to its function
4473 descriptor, and a private function descriptors taking two
4477 _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info
*entry
,
4478 struct _frvfdpic_dynamic_got_info
*dinfo
)
4480 /* Allocate space for a GOT entry pointing to the symbol. */
4483 else if (entry
->gotlos
)
4485 else if (entry
->gothilo
)
4486 dinfo
->gothilo
+= 4;
4491 /* Allocate space for a GOT entry pointing to the function
4495 else if (entry
->fdgotlos
)
4497 else if (entry
->fdgothilo
)
4498 dinfo
->gothilo
+= 4;
4503 /* Decide whether we need a PLT entry, a function descriptor in the
4504 GOT, and a lazy PLT entry for this symbol. */
4505 entry
->plt
= entry
->call
4506 && entry
->symndx
== -1 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4507 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
4508 entry
->privfd
= entry
->plt
4509 || entry
->fdgoff12
|| entry
->fdgofflos
|| entry
->fdgoffhilo
4510 || ((entry
->fd
|| entry
->fdgot12
|| entry
->fdgotlos
|| entry
->fdgothilo
)
4511 && (entry
->symndx
!= -1
4512 || FRVFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
)));
4513 entry
->lazyplt
= entry
->privfd
4514 && entry
->symndx
== -1 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4515 && ! (dinfo
->info
->flags
& DF_BIND_NOW
)
4516 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
4518 /* Allocate space for a function descriptor. */
4519 if (entry
->fdgoff12
)
4521 else if (entry
->fdgofflos
)
4523 else if (entry
->privfd
&& entry
->plt
)
4525 else if (entry
->privfd
)
4535 /* Compute the total GOT size required by each TLS symbol in each
4536 range. Symbols may require up to 5 words in the GOT: an entry
4537 holding the TLS offset for the symbol, and an entry with a full TLS
4538 descriptor taking 4 words. */
4541 _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info
*entry
,
4542 struct _frvfdpic_dynamic_got_info
*dinfo
,
4543 bfd_boolean subtract
)
4545 const int l
= subtract
? -1 : 1;
4547 /* Allocate space for a GOT entry with the TLS offset of the
4549 if (entry
->tlsoff12
)
4550 dinfo
->got12
+= 4 * l
;
4551 else if (entry
->tlsofflos
)
4552 dinfo
->gotlos
+= 4 * l
;
4553 else if (entry
->tlsoffhilo
)
4554 dinfo
->gothilo
+= 4 * l
;
4556 entry
->relocstlsoff
-= l
;
4557 entry
->relocstlsoff
+= l
;
4559 /* If there's any TLSOFF relocation, mark the output file as not
4560 suitable for dlopening. This mark will remain even if we relax
4561 all such relocations, but this is not a problem, since we'll only
4562 do so for executables, and we definitely don't want anyone
4563 dlopening executables. */
4564 if (entry
->relocstlsoff
)
4565 dinfo
->info
->flags
|= DF_STATIC_TLS
;
4567 /* Allocate space for a TLS descriptor. */
4568 if (entry
->tlsdesc12
)
4569 dinfo
->tlsd12
+= 8 * l
;
4570 else if (entry
->tlsdesclos
)
4571 dinfo
->tlsdlos
+= 8 * l
;
4572 else if (entry
->tlsplt
)
4573 dinfo
->tlsdplt
+= 8 * l
;
4574 else if (entry
->tlsdeschilo
)
4575 dinfo
->tlsdhilo
+= 8 * l
;
4577 entry
->relocstlsd
-= l
;
4578 entry
->relocstlsd
+= l
;
4581 /* Compute the number of dynamic relocations and fixups that a symbol
4582 requires, and add (or subtract) from the grand and per-symbol
4586 _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info
*entry
,
4587 struct _frvfdpic_dynamic_got_info
*dinfo
,
4588 bfd_boolean subtract
)
4590 bfd_vma relocs
= 0, fixups
= 0, tlsrets
= 0;
4592 if (!dinfo
->info
->executable
|| dinfo
->info
->pie
)
4594 relocs
= entry
->relocs32
+ entry
->relocsfd
+ entry
->relocsfdv
4595 + entry
->relocstlsd
;
4597 /* In the executable, TLS relocations to symbols that bind
4598 locally (including those that resolve to global TLS offsets)
4599 are resolved immediately, without any need for fixups or
4600 dynamic relocations. In shared libraries, however, we must
4601 emit dynamic relocations even for local symbols, because we
4602 don't know the module id the library is going to get at
4603 run-time, nor its TLS base offset. */
4604 if (!dinfo
->info
->executable
4605 || (entry
->symndx
== -1
4606 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)))
4607 relocs
+= entry
->relocstlsoff
;
4611 if (entry
->symndx
!= -1 || FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
))
4613 if (entry
->symndx
!= -1
4614 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
4615 fixups
+= entry
->relocs32
+ 2 * entry
->relocsfdv
;
4616 fixups
+= entry
->relocstlsd
;
4617 tlsrets
+= entry
->relocstlsd
;
4621 relocs
+= entry
->relocs32
+ entry
->relocsfdv
4622 + entry
->relocstlsoff
+ entry
->relocstlsd
;
4625 if (entry
->symndx
!= -1
4626 || FRVFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
))
4628 if (entry
->symndx
!= -1
4629 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
4630 fixups
+= entry
->relocsfd
;
4633 relocs
+= entry
->relocsfd
;
4640 tlsrets
= - tlsrets
;
4643 entry
->dynrelocs
+= relocs
;
4644 entry
->fixups
+= fixups
;
4645 dinfo
->relocs
+= relocs
;
4646 dinfo
->fixups
+= fixups
;
4647 dinfo
->tls_ret_refs
+= tlsrets
;
4650 /* Look for opportunities to relax TLS relocations. We can assume
4651 we're linking the main executable or a static-tls library, since
4652 otherwise we wouldn't have got here. When relaxing, we have to
4653 first undo any previous accounting of TLS uses of fixups, dynamic
4654 relocations, GOT and PLT entries. */
4657 _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info
*entry
,
4658 struct _frvfdpic_dynamic_got_info
*dinfo
,
4659 bfd_boolean relaxing
)
4661 bfd_boolean changed
= ! relaxing
;
4663 BFD_ASSERT (dinfo
->info
->executable
4664 || (dinfo
->info
->flags
& DF_STATIC_TLS
));
4666 if (entry
->tlsdesc12
|| entry
->tlsdesclos
|| entry
->tlsdeschilo
)
4670 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4671 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4675 /* When linking an executable, we can always decay GOTTLSDESC to
4676 TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise.
4677 When linking a static-tls shared library, using TLSMOFF is
4678 not an option, but we can still use GOTTLSOFF. When decaying
4679 to GOTTLSOFF, we must keep the GOT entry in range. We know
4680 it has to fit because we'll be trading the 4 words of hte TLS
4681 descriptor for a single word in the same range. */
4682 if (! dinfo
->info
->executable
4683 || (entry
->symndx
== -1
4684 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)))
4686 entry
->tlsoff12
|= entry
->tlsdesc12
;
4687 entry
->tlsofflos
|= entry
->tlsdesclos
;
4688 entry
->tlsoffhilo
|= entry
->tlsdeschilo
;
4691 entry
->tlsdesc12
= entry
->tlsdesclos
= entry
->tlsdeschilo
= 0;
4694 /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the
4695 main executable. We have to check whether the symbol's TLSOFF is
4696 in range for a setlos. For symbols with a hash entry, we can
4697 determine exactly what to do; for others locals, we don't have
4698 addresses handy, so we use the size of the TLS section as an
4699 approximation. If we get it wrong, we'll retain a GOT entry
4700 holding the TLS offset (without dynamic relocations or fixups),
4701 but we'll still optimize away the loads from it. Since TLS sizes
4702 are generally very small, it's probably not worth attempting to
4703 do better than this. */
4705 || entry
->tlsoff12
|| entry
->tlsofflos
|| entry
->tlsoffhilo
)
4706 && dinfo
->info
->executable
&& relaxing
4707 && ((entry
->symndx
== -1
4708 && FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4709 /* The above may hold for an undefweak TLS symbol, so make
4710 sure we don't have this case before accessing def.value
4712 && (entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
4713 || (bfd_vma
)(entry
->d
.h
->root
.u
.def
.value
4714 + (entry
->d
.h
->root
.u
.def
.section
4715 ->output_section
->vma
)
4716 + entry
->d
.h
->root
.u
.def
.section
->output_offset
4718 - tls_biased_base (dinfo
->info
)
4719 + 32768) < (bfd_vma
)65536))
4720 || (entry
->symndx
!= -1
4721 && (elf_hash_table (dinfo
->info
)->tls_sec
->size
4722 + abs (entry
->addend
) < 32768 + FRVFDPIC_TLS_BIAS
))))
4726 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4727 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4732 entry
->tlsoff12
= entry
->tlsofflos
= entry
->tlsoffhilo
= 0;
4735 /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already
4736 have a #gottlsoff12 relocation for this entry, or if we can fit
4737 one more in the 12-bit (and 16-bit) ranges. */
4741 && dinfo
->got12
+ dinfo
->fd12
+ dinfo
->tlsd12
<= 4096 - 12 - 4
4742 && (dinfo
->got12
+ dinfo
->fd12
+ dinfo
->tlsd12
4743 + dinfo
->gotlos
+ dinfo
->fdlos
+ dinfo
->tlsdlos
4744 <= 65536 - 12 - 4))))
4748 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4749 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4753 entry
->tlsoff12
= 1;
4759 _frvfdpic_count_tls_entries (entry
, dinfo
, FALSE
);
4760 _frvfdpic_count_relocs_fixups (entry
, dinfo
, FALSE
);
4766 /* Compute the total GOT and PLT size required by each symbol in each range. *
4767 Symbols may require up to 4 words in the GOT: an entry pointing to
4768 the symbol, an entry pointing to its function descriptor, and a
4769 private function descriptors taking two words. */
4772 _frvfdpic_count_got_plt_entries (void **entryp
, void *dinfo_
)
4774 struct frvfdpic_relocs_info
*entry
= *entryp
;
4775 struct _frvfdpic_dynamic_got_info
*dinfo
= dinfo_
;
4777 _frvfdpic_count_nontls_entries (entry
, dinfo
);
4779 if (dinfo
->info
->executable
|| (dinfo
->info
->flags
& DF_STATIC_TLS
))
4780 _frvfdpic_relax_tls_entries (entry
, dinfo
, FALSE
);
4783 _frvfdpic_count_tls_entries (entry
, dinfo
, FALSE
);
4784 _frvfdpic_count_relocs_fixups (entry
, dinfo
, FALSE
);
4790 /* Determine the positive and negative ranges to be used by each
4791 offset range in the GOT. FDCUR and CUR, that must be aligned to a
4792 double-word boundary, are the minimum (negative) and maximum
4793 (positive) GOT offsets already used by previous ranges, except for
4794 an ODD entry that may have been left behind. GOT and FD indicate
4795 the size of GOT entries and function descriptors that must be
4796 placed within the range from -WRAP to WRAP. If there's room left,
4797 up to FDPLT bytes should be reserved for additional function
4800 inline static bfd_signed_vma
4801 _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data
*gad
,
4802 bfd_signed_vma fdcur
,
4812 bfd_signed_vma wrapmin
= -wrap
;
4813 const bfd_vma tdescsz
= 8;
4815 /* Start at the given initial points. */
4819 /* If we had an incoming odd word and we have any got entries that
4820 are going to use it, consume it, otherwise leave gad->odd at
4821 zero. We might force gad->odd to zero and return the incoming
4822 odd such that it is used by the next range, but then GOT entries
4823 might appear to be out of order and we wouldn't be able to
4824 shorten the GOT by one word if it turns out to end with an
4825 unpaired GOT entry. */
4835 /* If we're left with an unpaired GOT entry, compute its location
4836 such that we can return it. Otherwise, if got doesn't require an
4837 odd number of words here, either odd was already zero in the
4838 block above, or it was set to zero because got was non-zero, or
4839 got was already zero. In the latter case, we want the value of
4840 odd to carry over to the return statement, so we don't want to
4841 reset odd unless the condition below is true. */
4848 /* Compute the tentative boundaries of this range. */
4849 gad
->max
= cur
+ got
;
4850 gad
->min
= fdcur
- fd
;
4853 /* If function descriptors took too much space, wrap some of them
4855 if (gad
->min
< wrapmin
)
4857 gad
->max
+= wrapmin
- gad
->min
;
4858 gad
->tmin
= gad
->min
= wrapmin
;
4861 /* If GOT entries took too much space, wrap some of them around.
4862 This may well cause gad->min to become lower than wrapmin. This
4863 will cause a relocation overflow later on, so we don't have to
4865 if ((bfd_vma
) gad
->max
> wrap
)
4867 gad
->min
-= gad
->max
- wrap
;
4871 /* Add TLS descriptors. */
4872 gad
->tmax
= gad
->max
+ tlsd
;
4873 gad
->tmin
= gad
->min
;
4876 /* If TLS descriptors took too much space, wrap an integral number
4878 if ((bfd_vma
) gad
->tmax
> wrap
)
4880 bfd_vma wrapsize
= gad
->tmax
- wrap
;
4882 wrapsize
+= tdescsz
/ 2;
4883 wrapsize
&= ~ tdescsz
/ 2;
4885 gad
->tmin
-= wrapsize
;
4886 gad
->tmax
-= wrapsize
;
4889 /* If there is space left and we have function descriptors
4890 referenced in PLT entries that could take advantage of shorter
4891 offsets, place them now. */
4892 if (fdplt
&& gad
->tmin
> wrapmin
)
4896 if ((bfd_vma
) (gad
->tmin
- wrapmin
) < fdplt
)
4897 fds
= gad
->tmin
- wrapmin
;
4907 /* If there is more space left, try to place some more function
4908 descriptors for PLT entries. */
4909 if (fdplt
&& (bfd_vma
) gad
->tmax
< wrap
)
4913 if ((bfd_vma
) (wrap
- gad
->tmax
) < fdplt
)
4914 fds
= wrap
- gad
->tmax
;
4924 /* If there is space left and we have TLS descriptors referenced in
4925 PLT entries that could take advantage of shorter offsets, place
4927 if (tlsdplt
&& gad
->tmin
> wrapmin
)
4931 if ((bfd_vma
) (gad
->tmin
- wrapmin
) < tlsdplt
)
4932 tlsds
= (gad
->tmin
- wrapmin
) & ~ (tdescsz
/ 2);
4938 gad
->tlsdplt
+= tlsds
;
4941 /* If there is more space left, try to place some more TLS
4942 descriptors for PLT entries. Although we could try to fit an
4943 additional TLS descriptor with half of it just before before the
4944 wrap point and another right past the wrap point, this might
4945 cause us to run out of space for the next region, so don't do
4947 if (tlsdplt
&& (bfd_vma
) gad
->tmax
< wrap
- tdescsz
/ 2)
4951 if ((bfd_vma
) (wrap
- gad
->tmax
) < tlsdplt
)
4952 tlsds
= (wrap
- gad
->tmax
) & ~ (tdescsz
/ 2);
4958 gad
->tlsdplt
+= tlsds
;
4961 /* If odd was initially computed as an offset past the wrap point,
4964 odd
= gad
->min
+ odd
- gad
->max
;
4966 /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed
4967 before returning, so do it here too. This guarantees that,
4968 should cur and fdcur meet at the wrap point, they'll both be
4970 if (gad
->cur
== gad
->max
)
4971 gad
->cur
= gad
->min
;
4973 /* Ditto for _frvfdpic_get_tlsdesc_entry(). */
4974 gad
->tcur
= gad
->max
;
4975 if (gad
->tcur
== gad
->tmax
)
4976 gad
->tcur
= gad
->tmin
;
4981 /* Compute the location of the next GOT entry, given the allocation
4982 data for a range. */
4984 inline static bfd_signed_vma
4985 _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
4991 /* If there was an odd word left behind, use it. */
4997 /* Otherwise, use the word pointed to by cur, reserve the next
4998 as an odd word, and skip to the next pair of words, possibly
5001 gad
->odd
= gad
->cur
+ 4;
5003 if (gad
->cur
== gad
->max
)
5004 gad
->cur
= gad
->min
;
5010 /* Compute the location of the next function descriptor entry in the
5011 GOT, given the allocation data for a range. */
5013 inline static bfd_signed_vma
5014 _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
5016 /* If we're at the bottom, wrap around, and only then allocate the
5017 next pair of words. */
5018 if (gad
->fdcur
== gad
->min
)
5019 gad
->fdcur
= gad
->max
;
5020 return gad
->fdcur
-= 8;
5023 /* Compute the location of the next TLS descriptor entry in the GOT,
5024 given the allocation data for a range. */
5025 inline static bfd_signed_vma
5026 _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
5034 /* If we're at the top of the region, wrap around to the bottom. */
5035 if (gad
->tcur
== gad
->tmax
)
5036 gad
->tcur
= gad
->tmin
;
5041 /* Assign GOT offsets for every GOT entry and function descriptor.
5042 Doing everything in a single pass is tricky. */
5045 _frvfdpic_assign_got_entries (void **entryp
, void *info_
)
5047 struct frvfdpic_relocs_info
*entry
= *entryp
;
5048 struct _frvfdpic_dynamic_got_plt_info
*dinfo
= info_
;
5051 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5052 else if (entry
->gotlos
)
5053 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5054 else if (entry
->gothilo
)
5055 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5058 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5059 else if (entry
->fdgotlos
)
5060 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5061 else if (entry
->fdgothilo
)
5062 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5064 if (entry
->fdgoff12
)
5065 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->got12
);
5066 else if (entry
->plt
&& dinfo
->got12
.fdplt
)
5068 dinfo
->got12
.fdplt
-= 8;
5069 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->got12
);
5071 else if (entry
->fdgofflos
)
5072 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gotlos
);
5073 else if (entry
->plt
&& dinfo
->gotlos
.fdplt
)
5075 dinfo
->gotlos
.fdplt
-= 8;
5076 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gotlos
);
5078 else if (entry
->plt
)
5080 dinfo
->gothilo
.fdplt
-= 8;
5081 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gothilo
);
5083 else if (entry
->privfd
)
5084 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gothilo
);
5086 if (entry
->tlsoff12
)
5087 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5088 else if (entry
->tlsofflos
)
5089 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5090 else if (entry
->tlsoffhilo
)
5091 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5093 if (entry
->tlsdesc12
)
5094 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->got12
);
5095 else if (entry
->tlsplt
&& dinfo
->got12
.tlsdplt
)
5097 dinfo
->got12
.tlsdplt
-= 8;
5098 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->got12
);
5100 else if (entry
->tlsdesclos
)
5101 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gotlos
);
5102 else if (entry
->tlsplt
&& dinfo
->gotlos
.tlsdplt
)
5104 dinfo
->gotlos
.tlsdplt
-= 8;
5105 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gotlos
);
5107 else if (entry
->tlsplt
)
5109 dinfo
->gothilo
.tlsdplt
-= 8;
5110 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gothilo
);
5112 else if (entry
->tlsdeschilo
)
5113 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gothilo
);
5118 /* Assign GOT offsets to private function descriptors used by PLT
5119 entries (or referenced by 32-bit offsets), as well as PLT entries
5120 and lazy PLT entries. */
5123 _frvfdpic_assign_plt_entries (void **entryp
, void *info_
)
5125 struct frvfdpic_relocs_info
*entry
= *entryp
;
5126 struct _frvfdpic_dynamic_got_plt_info
*dinfo
= info_
;
5129 BFD_ASSERT (entry
->fd_entry
);
5135 /* We use the section's raw size to mark the location of the
5137 entry
->plt_entry
= frvfdpic_plt_section (dinfo
->g
.info
)->size
;
5139 /* Figure out the length of this PLT entry based on the
5140 addressing mode we need to reach the function descriptor. */
5141 BFD_ASSERT (entry
->fd_entry
);
5142 if (entry
->fd_entry
>= -(1 << (12 - 1))
5143 && entry
->fd_entry
< (1 << (12 - 1)))
5145 else if (entry
->fd_entry
>= -(1 << (16 - 1))
5146 && entry
->fd_entry
< (1 << (16 - 1)))
5151 frvfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
5156 entry
->lzplt_entry
= dinfo
->g
.lzplt
;
5157 dinfo
->g
.lzplt
+= 8;
5158 /* If this entry is the one that gets the resolver stub, account
5159 for the additional instruction. */
5160 if (entry
->lzplt_entry
% FRVFDPIC_LZPLT_BLOCK_SIZE
5161 == FRVFDPIC_LZPLT_RESOLV_LOC
)
5162 dinfo
->g
.lzplt
+= 4;
5170 = frvfdpic_plt_section (dinfo
->g
.info
)->size
;
5172 if (dinfo
->g
.info
->executable
5173 && (entry
->symndx
!= -1
5174 || FRVFDPIC_SYM_LOCAL (dinfo
->g
.info
, entry
->d
.h
)))
5176 if ((bfd_signed_vma
)entry
->addend
>= -(1 << (16 - 1))
5177 /* FIXME: here we use the size of the TLS section
5178 as an upper bound for the value of the TLS
5179 symbol, because we may not know the exact value
5180 yet. If we get it wrong, we'll just waste a
5181 word in the PLT, and we should never get even
5182 close to 32 KiB of TLS anyway. */
5183 && elf_hash_table (dinfo
->g
.info
)->tls_sec
5184 && (elf_hash_table (dinfo
->g
.info
)->tls_sec
->size
5185 + (bfd_signed_vma
)(entry
->addend
) <= (1 << (16 - 1))))
5190 else if (entry
->tlsoff_entry
)
5192 if (entry
->tlsoff_entry
>= -(1 << (12 - 1))
5193 && entry
->tlsoff_entry
< (1 << (12 - 1)))
5195 else if (entry
->tlsoff_entry
>= -(1 << (16 - 1))
5196 && entry
->tlsoff_entry
< (1 << (16 - 1)))
5203 BFD_ASSERT (entry
->tlsdesc_entry
);
5205 if (entry
->tlsdesc_entry
>= -(1 << (12 - 1))
5206 && entry
->tlsdesc_entry
< (1 << (12 - 1)))
5208 else if (entry
->tlsdesc_entry
>= -(1 << (16 - 1))
5209 && entry
->tlsdesc_entry
< (1 << (16 - 1)))
5215 frvfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
5221 /* Cancel out any effects of calling _frvfdpic_assign_got_entries and
5222 _frvfdpic_assign_plt_entries. */
5225 _frvfdpic_reset_got_plt_entries (void **entryp
, void *ignore ATTRIBUTE_UNUSED
)
5227 struct frvfdpic_relocs_info
*entry
= *entryp
;
5229 entry
->got_entry
= 0;
5230 entry
->fdgot_entry
= 0;
5231 entry
->fd_entry
= 0;
5232 entry
->plt_entry
= (bfd_vma
)-1;
5233 entry
->lzplt_entry
= (bfd_vma
)-1;
5234 entry
->tlsoff_entry
= 0;
5235 entry
->tlsdesc_entry
= 0;
5236 entry
->tlsplt_entry
= (bfd_vma
)-1;
5241 /* Follow indirect and warning hash entries so that each got entry
5242 points to the final symbol definition. P must point to a pointer
5243 to the hash table we're traversing. Since this traversal may
5244 modify the hash table, we set this pointer to NULL to indicate
5245 we've made a potentially-destructive change to the hash table, so
5246 the traversal must be restarted. */
5248 _frvfdpic_resolve_final_relocs_info (void **entryp
, void *p
)
5250 struct frvfdpic_relocs_info
*entry
= *entryp
;
5253 if (entry
->symndx
== -1)
5255 struct elf_link_hash_entry
*h
= entry
->d
.h
;
5256 struct frvfdpic_relocs_info
*oentry
;
5258 while (h
->root
.type
== bfd_link_hash_indirect
5259 || h
->root
.type
== bfd_link_hash_warning
)
5260 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
5262 if (entry
->d
.h
== h
)
5265 oentry
= frvfdpic_relocs_info_for_global (*htab
, 0, h
, entry
->addend
,
5270 /* Merge the two entries. */
5271 frvfdpic_pic_merge_early_relocs_info (oentry
, entry
);
5272 htab_clear_slot (*htab
, entryp
);
5278 /* If we can't find this entry with the new bfd hash, re-insert
5279 it, and get the traversal restarted. */
5280 if (! htab_find (*htab
, entry
))
5282 htab_clear_slot (*htab
, entryp
);
5283 entryp
= htab_find_slot (*htab
, entry
, INSERT
);
5286 /* Abort the traversal, since the whole table may have
5287 moved, and leave it up to the parent to restart the
5289 *(htab_t
*)p
= NULL
;
5297 /* Compute the total size of the GOT, the PLT, the dynamic relocations
5298 section and the rofixup section. Assign locations for GOT and PLT
5302 _frvfdpic_size_got_plt (bfd
*output_bfd
,
5303 struct _frvfdpic_dynamic_got_plt_info
*gpinfop
)
5306 bfd_vma limit
, tlslimit
;
5307 struct bfd_link_info
*info
= gpinfop
->g
.info
;
5308 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
5310 memcpy (frvfdpic_dynamic_got_plt_info (info
), &gpinfop
->g
,
5311 sizeof (gpinfop
->g
));
5314 /* Compute the total size taken by entries in the 12-bit and 16-bit
5315 ranges, to tell how many PLT function descriptors we can bring
5316 into the 12-bit range without causing the 16-bit range to
5318 limit
= odd
+ gpinfop
->g
.got12
+ gpinfop
->g
.gotlos
5319 + gpinfop
->g
.fd12
+ gpinfop
->g
.fdlos
5320 + gpinfop
->g
.tlsd12
+ gpinfop
->g
.tlsdlos
;
5321 if (limit
< (bfd_vma
)1 << 16)
5322 limit
= ((bfd_vma
)1 << 16) - limit
;
5325 if (gpinfop
->g
.fdplt
< limit
)
5327 tlslimit
= (limit
- gpinfop
->g
.fdplt
) & ~ (bfd_vma
) 8;
5328 limit
= gpinfop
->g
.fdplt
;
5332 if (gpinfop
->g
.tlsdplt
< tlslimit
)
5333 tlslimit
= gpinfop
->g
.tlsdplt
;
5335 /* Determine the ranges of GOT offsets that we can use for each
5336 range of addressing modes. */
5337 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->got12
,
5346 (bfd_vma
)1 << (12-1));
5347 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->gotlos
,
5348 gpinfop
->got12
.tmin
,
5350 gpinfop
->got12
.tmax
,
5354 - gpinfop
->got12
.fdplt
,
5357 - gpinfop
->got12
.tlsdplt
,
5358 (bfd_vma
)1 << (16-1));
5359 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->gothilo
,
5360 gpinfop
->gotlos
.tmin
,
5362 gpinfop
->gotlos
.tmax
,
5366 - gpinfop
->got12
.fdplt
5367 - gpinfop
->gotlos
.fdplt
,
5368 gpinfop
->g
.tlsdhilo
,
5370 - gpinfop
->got12
.tlsdplt
5371 - gpinfop
->gotlos
.tlsdplt
,
5372 (bfd_vma
)1 << (32-1));
5374 /* Now assign (most) GOT offsets. */
5375 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_assign_got_entries
,
5378 frvfdpic_got_section (info
)->size
= gpinfop
->gothilo
.tmax
5379 - gpinfop
->gothilo
.tmin
5380 /* If an odd word is the last word of the GOT, we don't need this
5381 word to be part of the GOT. */
5382 - (odd
+ 4 == gpinfop
->gothilo
.tmax
? 4 : 0);
5383 if (frvfdpic_got_section (info
)->size
== 0)
5384 frvfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
5385 else if (frvfdpic_got_section (info
)->size
== 12
5386 && ! elf_hash_table (info
)->dynamic_sections_created
)
5388 frvfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
5389 frvfdpic_got_section (info
)->size
= 0;
5391 /* This will be non-NULL during relaxation. The assumption is that
5392 the size of one of these sections will never grow, only shrink,
5393 so we can use the larger buffer we allocated before. */
5394 else if (frvfdpic_got_section (info
)->contents
== NULL
)
5396 frvfdpic_got_section (info
)->contents
=
5397 (bfd_byte
*) bfd_zalloc (dynobj
,
5398 frvfdpic_got_section (info
)->size
);
5399 if (frvfdpic_got_section (info
)->contents
== NULL
)
5403 if (frvfdpic_gotrel_section (info
))
5404 /* Subtract the number of lzplt entries, since those will generate
5405 relocations in the pltrel section. */
5406 frvfdpic_gotrel_section (info
)->size
=
5407 (gpinfop
->g
.relocs
- gpinfop
->g
.lzplt
/ 8)
5408 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
5410 BFD_ASSERT (gpinfop
->g
.relocs
== 0);
5411 if (frvfdpic_gotrel_section (info
)->size
== 0)
5412 frvfdpic_gotrel_section (info
)->flags
|= SEC_EXCLUDE
;
5413 else if (frvfdpic_gotrel_section (info
)->contents
== NULL
)
5415 frvfdpic_gotrel_section (info
)->contents
=
5416 (bfd_byte
*) bfd_zalloc (dynobj
,
5417 frvfdpic_gotrel_section (info
)->size
);
5418 if (frvfdpic_gotrel_section (info
)->contents
== NULL
)
5422 frvfdpic_gotfixup_section (info
)->size
= (gpinfop
->g
.fixups
+ 1) * 4;
5423 if (frvfdpic_gotfixup_section (info
)->size
== 0)
5424 frvfdpic_gotfixup_section (info
)->flags
|= SEC_EXCLUDE
;
5425 else if (frvfdpic_gotfixup_section (info
)->contents
== NULL
)
5427 frvfdpic_gotfixup_section (info
)->contents
=
5428 (bfd_byte
*) bfd_zalloc (dynobj
,
5429 frvfdpic_gotfixup_section (info
)->size
);
5430 if (frvfdpic_gotfixup_section (info
)->contents
== NULL
)
5434 if (frvfdpic_pltrel_section (info
))
5436 frvfdpic_pltrel_section (info
)->size
=
5437 gpinfop
->g
.lzplt
/ 8
5438 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
5439 if (frvfdpic_pltrel_section (info
)->size
== 0)
5440 frvfdpic_pltrel_section (info
)->flags
|= SEC_EXCLUDE
;
5441 else if (frvfdpic_pltrel_section (info
)->contents
== NULL
)
5443 frvfdpic_pltrel_section (info
)->contents
=
5444 (bfd_byte
*) bfd_zalloc (dynobj
,
5445 frvfdpic_pltrel_section (info
)->size
);
5446 if (frvfdpic_pltrel_section (info
)->contents
== NULL
)
5451 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
5452 such that there's room for the additional instruction needed to
5453 call the resolver. Since _frvfdpic_assign_got_entries didn't
5454 account for them, our block size is 4 bytes smaller than the real
5456 if (frvfdpic_plt_section (info
))
5458 frvfdpic_plt_section (info
)->size
= gpinfop
->g
.lzplt
5459 + ((gpinfop
->g
.lzplt
+ (FRVFDPIC_LZPLT_BLOCK_SIZE
- 4) - 8)
5460 / (FRVFDPIC_LZPLT_BLOCK_SIZE
- 4) * 4);
5463 /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to
5464 actually assign lazy PLT entries addresses. */
5465 gpinfop
->g
.lzplt
= 0;
5467 /* Save information that we're going to need to generate GOT and PLT
5469 frvfdpic_got_initial_offset (info
) = -gpinfop
->gothilo
.tmin
;
5471 if (get_elf_backend_data (output_bfd
)->want_got_sym
)
5472 elf_hash_table (info
)->hgot
->root
.u
.def
.value
5473 = frvfdpic_got_initial_offset (info
);
5475 if (frvfdpic_plt_section (info
))
5476 frvfdpic_plt_initial_offset (info
) =
5477 frvfdpic_plt_section (info
)->size
;
5479 /* Allocate a ret statement at plt_initial_offset, to be used by
5480 locally-resolved TLS descriptors. */
5481 if (gpinfop
->g
.tls_ret_refs
)
5482 frvfdpic_plt_section (info
)->size
+= 4;
5484 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_assign_plt_entries
,
5487 /* Allocate the PLT section contents only after
5488 _frvfdpic_assign_plt_entries has a chance to add the size of the
5489 non-lazy PLT entries. */
5490 if (frvfdpic_plt_section (info
))
5492 if (frvfdpic_plt_section (info
)->size
== 0)
5493 frvfdpic_plt_section (info
)->flags
|= SEC_EXCLUDE
;
5494 else if (frvfdpic_plt_section (info
)->contents
== NULL
)
5496 frvfdpic_plt_section (info
)->contents
=
5497 (bfd_byte
*) bfd_zalloc (dynobj
,
5498 frvfdpic_plt_section (info
)->size
);
5499 if (frvfdpic_plt_section (info
)->contents
== NULL
)
5507 /* Set the sizes of the dynamic sections. */
5510 elf32_frvfdpic_size_dynamic_sections (bfd
*output_bfd
,
5511 struct bfd_link_info
*info
)
5515 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5517 dynobj
= elf_hash_table (info
)->dynobj
;
5518 BFD_ASSERT (dynobj
!= NULL
);
5520 if (elf_hash_table (info
)->dynamic_sections_created
)
5522 /* Set the contents of the .interp section to the interpreter. */
5523 if (info
->executable
)
5525 s
= bfd_get_section_by_name (dynobj
, ".interp");
5526 BFD_ASSERT (s
!= NULL
);
5527 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5528 s
->contents
= (bfd_byte
*) ELF_DYNAMIC_INTERPRETER
;
5532 memset (&gpinfo
, 0, sizeof (gpinfo
));
5533 gpinfo
.g
.info
= info
;
5537 htab_t relocs
= frvfdpic_relocs_info (info
);
5539 htab_traverse (relocs
, _frvfdpic_resolve_final_relocs_info
, &relocs
);
5541 if (relocs
== frvfdpic_relocs_info (info
))
5545 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_count_got_plt_entries
,
5548 /* Allocate space to save the summary information, we're going to
5549 use it if we're doing relaxations. */
5550 frvfdpic_dynamic_got_plt_info (info
) = bfd_alloc (dynobj
, sizeof (gpinfo
.g
));
5552 if (!_frvfdpic_size_got_plt (output_bfd
, &gpinfo
))
5555 if (elf_hash_table (info
)->dynamic_sections_created
)
5557 if (frvfdpic_got_section (info
)->size
)
5558 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTGOT
, 0))
5561 if (frvfdpic_pltrel_section (info
)->size
)
5562 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
5563 || !_bfd_elf_add_dynamic_entry (info
, DT_PLTREL
, DT_REL
)
5564 || !_bfd_elf_add_dynamic_entry (info
, DT_JMPREL
, 0))
5567 if (frvfdpic_gotrel_section (info
)->size
)
5568 if (!_bfd_elf_add_dynamic_entry (info
, DT_REL
, 0)
5569 || !_bfd_elf_add_dynamic_entry (info
, DT_RELSZ
, 0)
5570 || !_bfd_elf_add_dynamic_entry (info
, DT_RELENT
,
5571 sizeof (Elf32_External_Rel
)))
5579 elf32_frvfdpic_always_size_sections (bfd
*output_bfd
,
5580 struct bfd_link_info
*info
)
5582 if (!info
->relocatable
)
5584 struct elf_link_hash_entry
*h
;
5586 /* Force a PT_GNU_STACK segment to be created. */
5587 if (! elf_tdata (output_bfd
)->stack_flags
)
5588 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
| PF_X
;
5590 /* Define __stacksize if it's not defined yet. */
5591 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
5592 FALSE
, FALSE
, FALSE
);
5593 if (! h
|| h
->root
.type
!= bfd_link_hash_defined
5594 || h
->type
!= STT_OBJECT
5597 struct bfd_link_hash_entry
*bh
= NULL
;
5599 if (!(_bfd_generic_link_add_one_symbol
5600 (info
, output_bfd
, "__stacksize",
5601 BSF_GLOBAL
, bfd_abs_section_ptr
, DEFAULT_STACK_SIZE
,
5602 (const char *) NULL
, FALSE
,
5603 get_elf_backend_data (output_bfd
)->collect
, &bh
)))
5606 h
= (struct elf_link_hash_entry
*) bh
;
5608 h
->type
= STT_OBJECT
;
5609 /* This one must NOT be hidden. */
5616 /* Check whether any of the relocations was optimized away, and
5617 subtract it from the relocation or fixup count. */
5619 _frvfdpic_check_discarded_relocs (bfd
*abfd
, asection
*sec
,
5620 struct bfd_link_info
*info
,
5622 bfd_boolean
*changed
)
5624 Elf_Internal_Shdr
*symtab_hdr
;
5625 struct elf_link_hash_entry
**sym_hashes
;
5626 Elf_Internal_Rela
*rel
, *erel
;
5628 if ((sec
->flags
& SEC_RELOC
) == 0
5629 || sec
->reloc_count
== 0)
5632 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5633 sym_hashes
= elf_sym_hashes (abfd
);
5635 rel
= elf_section_data (sec
)->relocs
;
5637 /* Now examine each relocation. */
5638 for (erel
= rel
+ sec
->reloc_count
; rel
< erel
; rel
++)
5640 struct elf_link_hash_entry
*h
;
5641 unsigned long r_symndx
;
5642 struct frvfdpic_relocs_info
*picrel
;
5643 struct _frvfdpic_dynamic_got_info
*dinfo
;
5645 if (ELF32_R_TYPE (rel
->r_info
) != R_FRV_32
5646 && ELF32_R_TYPE (rel
->r_info
) != R_FRV_FUNCDESC
)
5649 if (_bfd_elf_section_offset (sec
->output_section
->owner
,
5650 info
, sec
, rel
->r_offset
)
5654 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5655 if (r_symndx
< symtab_hdr
->sh_info
)
5659 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5660 while (h
->root
.type
== bfd_link_hash_indirect
5661 || h
->root
.type
== bfd_link_hash_warning
)
5662 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
5666 picrel
= frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info
),
5668 rel
->r_addend
, NO_INSERT
);
5670 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info (info
),
5672 rel
->r_addend
, NO_INSERT
);
5678 dinfo
= frvfdpic_dynamic_got_plt_info (info
);
5680 _frvfdpic_count_relocs_fixups (picrel
, dinfo
, TRUE
);
5681 if (ELF32_R_TYPE (rel
->r_info
) == R_FRV_32
)
5683 else /* we know (ELF32_R_TYPE (rel->r_info) == R_FRV_FUNCDESC) */
5685 _frvfdpic_count_relocs_fixups (picrel
, dinfo
, FALSE
);
5692 frvfdpic_elf_discard_info (bfd
*ibfd
,
5693 struct elf_reloc_cookie
*cookie ATTRIBUTE_UNUSED
,
5694 struct bfd_link_info
*info
)
5696 bfd_boolean changed
= FALSE
;
5700 /* Account for relaxation of .eh_frame section. */
5701 for (s
= ibfd
->sections
; s
; s
= s
->next
)
5702 if (s
->sec_info_type
== ELF_INFO_TYPE_EH_FRAME
)
5704 if (!_frvfdpic_check_discarded_relocs (ibfd
, s
, info
, &changed
))
5706 obfd
= s
->output_section
->owner
;
5711 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5713 memset (&gpinfo
, 0, sizeof (gpinfo
));
5714 memcpy (&gpinfo
.g
, frvfdpic_dynamic_got_plt_info (info
),
5717 /* Clear GOT and PLT assignments. */
5718 htab_traverse (frvfdpic_relocs_info (info
),
5719 _frvfdpic_reset_got_plt_entries
,
5722 if (!_frvfdpic_size_got_plt (obfd
, &gpinfo
))
5729 /* Look for opportunities to relax TLS relocations. We can assume
5730 we're linking the main executable or a static-tls library, since
5731 otherwise we wouldn't have got here. */
5734 _frvfdpic_relax_got_plt_entries (void **entryp
, void *dinfo_
)
5736 struct frvfdpic_relocs_info
*entry
= *entryp
;
5737 struct _frvfdpic_dynamic_got_info
*dinfo
= dinfo_
;
5739 _frvfdpic_relax_tls_entries (entry
, dinfo
, TRUE
);
5745 elf32_frvfdpic_relax_section (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
,
5746 struct bfd_link_info
*info
, bfd_boolean
*again
)
5748 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5750 /* If we return early, we didn't change anything. */
5753 /* We'll do our thing when requested to relax the GOT section. */
5754 if (sec
!= frvfdpic_got_section (info
))
5757 /* We can only relax when linking the main executable or a library
5758 that can't be dlopened. */
5759 if (! info
->executable
&& ! (info
->flags
& DF_STATIC_TLS
))
5762 /* If there isn't a TLS section for this binary, we can't do
5763 anything about its TLS relocations (it probably doesn't have
5765 if (elf_hash_table (info
)->tls_sec
== NULL
)
5768 memset (&gpinfo
, 0, sizeof (gpinfo
));
5769 memcpy (&gpinfo
.g
, frvfdpic_dynamic_got_plt_info (info
), sizeof (gpinfo
.g
));
5771 /* Now look for opportunities to relax, adjusting the GOT usage
5773 htab_traverse (frvfdpic_relocs_info (info
),
5774 _frvfdpic_relax_got_plt_entries
,
5777 /* If we changed anything, reset and re-assign GOT and PLT entries. */
5778 if (memcmp (frvfdpic_dynamic_got_plt_info (info
),
5779 &gpinfo
.g
, sizeof (gpinfo
.g
)) != 0)
5781 /* Clear GOT and PLT assignments. */
5782 htab_traverse (frvfdpic_relocs_info (info
),
5783 _frvfdpic_reset_got_plt_entries
,
5786 /* The owner of the TLS section is the output bfd. There should
5787 be a better way to get to it. */
5788 if (!_frvfdpic_size_got_plt (elf_hash_table (info
)->tls_sec
->owner
,
5792 /* Repeat until we don't make any further changes. We could fail to
5793 introduce changes in a round if, for example, the 12-bit range is
5794 full, but we later release some space by getting rid of TLS
5795 descriptors in it. We have to repeat the whole process because
5796 we might have changed the size of a section processed before this
5805 elf32_frvfdpic_modify_program_headers (bfd
*output_bfd
,
5806 struct bfd_link_info
*info
)
5808 struct elf_obj_tdata
*tdata
= elf_tdata (output_bfd
);
5809 struct elf_segment_map
*m
;
5810 Elf_Internal_Phdr
*p
;
5812 /* objcopy and strip preserve what's already there using
5813 elf32_frvfdpic_copy_private_bfd_data (). */
5817 for (p
= tdata
->phdr
, m
= tdata
->segment_map
; m
!= NULL
; m
= m
->next
, p
++)
5818 if (m
->p_type
== PT_GNU_STACK
)
5823 struct elf_link_hash_entry
*h
;
5825 /* Obtain the pointer to the __stacksize symbol. */
5826 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
5827 FALSE
, FALSE
, FALSE
);
5830 while (h
->root
.type
== bfd_link_hash_indirect
5831 || h
->root
.type
== bfd_link_hash_warning
)
5832 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5833 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
5836 /* Set the header p_memsz from the symbol value. We
5837 intentionally ignore the symbol section. */
5838 if (h
&& h
->root
.type
== bfd_link_hash_defined
)
5839 p
->p_memsz
= h
->root
.u
.def
.value
;
5841 p
->p_memsz
= DEFAULT_STACK_SIZE
;
5849 /* Fill in code and data in dynamic sections. */
5852 elf32_frv_finish_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5853 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
5855 /* Nothing to be done for non-FDPIC. */
5860 elf32_frvfdpic_finish_dynamic_sections (bfd
*output_bfd
,
5861 struct bfd_link_info
*info
)
5866 dynobj
= elf_hash_table (info
)->dynobj
;
5868 if (frvfdpic_dynamic_got_plt_info (info
))
5870 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
== 0);
5872 if (frvfdpic_got_section (info
))
5874 BFD_ASSERT (frvfdpic_gotrel_section (info
)->size
5875 == (frvfdpic_gotrel_section (info
)->reloc_count
5876 * sizeof (Elf32_External_Rel
)));
5878 if (frvfdpic_gotfixup_section (info
))
5880 struct elf_link_hash_entry
*hgot
= elf_hash_table (info
)->hgot
;
5881 bfd_vma got_value
= hgot
->root
.u
.def
.value
5882 + hgot
->root
.u
.def
.section
->output_section
->vma
5883 + hgot
->root
.u
.def
.section
->output_offset
;
5884 struct bfd_link_hash_entry
*hend
;
5886 _frvfdpic_add_rofixup (output_bfd
, frvfdpic_gotfixup_section (info
),
5889 if (frvfdpic_gotfixup_section (info
)->size
5890 != (frvfdpic_gotfixup_section (info
)->reloc_count
* 4))
5893 (*_bfd_error_handler
)
5894 ("LINKER BUG: .rofixup section size mismatch");
5898 hend
= bfd_link_hash_lookup (info
->hash
, "__ROFIXUP_END__",
5899 FALSE
, FALSE
, TRUE
);
5901 && (hend
->type
== bfd_link_hash_defined
5902 || hend
->type
== bfd_link_hash_defweak
))
5905 frvfdpic_gotfixup_section (info
)->output_section
->vma
5906 + frvfdpic_gotfixup_section (info
)->output_offset
5907 + frvfdpic_gotfixup_section (info
)->size
5908 - hend
->u
.def
.section
->output_section
->vma
5909 - hend
->u
.def
.section
->output_offset
;
5910 BFD_ASSERT (hend
->u
.def
.value
== value
);
5911 if (hend
->u
.def
.value
!= value
)
5916 if (frvfdpic_pltrel_section (info
))
5918 BFD_ASSERT (frvfdpic_pltrel_section (info
)->size
5919 == (frvfdpic_pltrel_section (info
)->reloc_count
5920 * sizeof (Elf32_External_Rel
)));
5924 if (elf_hash_table (info
)->dynamic_sections_created
)
5926 Elf32_External_Dyn
* dyncon
;
5927 Elf32_External_Dyn
* dynconend
;
5929 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5931 BFD_ASSERT (sdyn
!= NULL
);
5933 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5934 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5936 for (; dyncon
< dynconend
; dyncon
++)
5938 Elf_Internal_Dyn dyn
;
5940 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5948 dyn
.d_un
.d_ptr
= frvfdpic_got_section (info
)->output_section
->vma
5949 + frvfdpic_got_section (info
)->output_offset
5950 + frvfdpic_got_initial_offset (info
);
5951 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5955 dyn
.d_un
.d_ptr
= frvfdpic_pltrel_section (info
)
5956 ->output_section
->vma
5957 + frvfdpic_pltrel_section (info
)->output_offset
;
5958 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5962 dyn
.d_un
.d_val
= frvfdpic_pltrel_section (info
)->size
;
5963 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5972 /* Adjust a symbol defined by a dynamic object and referenced by a
5976 elf32_frvfdpic_adjust_dynamic_symbol
5977 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5978 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
5982 dynobj
= elf_hash_table (info
)->dynobj
;
5984 /* Make sure we know what is going on here. */
5985 BFD_ASSERT (dynobj
!= NULL
5986 && (h
->u
.weakdef
!= NULL
5989 && !h
->def_regular
)));
5991 /* If this is a weak symbol, and there is a real definition, the
5992 processor independent code will have arranged for us to see the
5993 real definition first, and we can just use the same value. */
5994 if (h
->u
.weakdef
!= NULL
)
5996 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
5997 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
5998 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
5999 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
6005 /* Perform any actions needed for dynamic symbols. */
6008 elf32_frvfdpic_finish_dynamic_symbol
6009 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
6010 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6011 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
,
6012 Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
)
6017 /* Decide whether to attempt to turn absptr or lsda encodings in
6018 shared libraries into pcrel within the given input section. */
6021 frvfdpic_elf_use_relative_eh_frame
6022 (bfd
*input_bfd ATTRIBUTE_UNUSED
,
6023 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6024 asection
*eh_frame_section ATTRIBUTE_UNUSED
)
6026 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
6030 /* Adjust the contents of an eh_frame_hdr section before they're output. */
6033 frvfdpic_elf_encode_eh_address (bfd
*abfd
,
6034 struct bfd_link_info
*info
,
6035 asection
*osec
, bfd_vma offset
,
6036 asection
*loc_sec
, bfd_vma loc_offset
,
6039 struct elf_link_hash_entry
*h
;
6041 h
= elf_hash_table (info
)->hgot
;
6042 BFD_ASSERT (h
&& h
->root
.type
== bfd_link_hash_defined
);
6044 if (! h
|| (_frvfdpic_osec_to_segment (abfd
, osec
)
6045 == _frvfdpic_osec_to_segment (abfd
, loc_sec
->output_section
)))
6046 return _bfd_elf_encode_eh_address (abfd
, info
, osec
, offset
,
6047 loc_sec
, loc_offset
, encoded
);
6049 BFD_ASSERT (_frvfdpic_osec_to_segment (abfd
, osec
)
6050 == (_frvfdpic_osec_to_segment
6051 (abfd
, h
->root
.u
.def
.section
->output_section
)));
6053 *encoded
= osec
->vma
+ offset
6054 - (h
->root
.u
.def
.value
6055 + h
->root
.u
.def
.section
->output_section
->vma
6056 + h
->root
.u
.def
.section
->output_offset
);
6058 return DW_EH_PE_datarel
| DW_EH_PE_sdata4
;
6061 /* Look through the relocs for a section during the first phase.
6063 Besides handling virtual table relocs for gc, we have to deal with
6064 all sorts of PIC-related relocations. We describe below the
6065 general plan on how to handle such relocations, even though we only
6066 collect information at this point, storing them in hash tables for
6067 perusal of later passes.
6069 32 relocations are propagated to the linker output when creating
6070 position-independent output. LO16 and HI16 relocations are not
6071 supposed to be encountered in this case.
6073 LABEL16 should always be resolvable by the linker, since it's only
6076 LABEL24, on the other hand, is used by calls. If it turns out that
6077 the target of a call is a dynamic symbol, a PLT entry must be
6078 created for it, which triggers the creation of a private function
6079 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
6081 GPREL relocations require the referenced symbol to be in the same
6082 segment as _gp, but this can only be checked later.
6084 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
6085 exist. LABEL24 might as well, since it may require a PLT entry,
6086 that will require a got.
6088 Non-FUNCDESC GOT relocations require a GOT entry to be created
6089 regardless of whether the symbol is dynamic. However, since a
6090 global symbol that turns out to not be exported may have the same
6091 address of a non-dynamic symbol, we don't assign GOT entries at
6092 this point, such that we can share them in this case. A relocation
6093 for the GOT entry always has to be created, be it to offset a
6094 private symbol by the section load address, be it to get the symbol
6095 resolved dynamically.
6097 FUNCDESC GOT relocations require a GOT entry to be created, and
6098 handled as if a FUNCDESC relocation was applied to the GOT entry in
6101 FUNCDESC relocations referencing a symbol that turns out to NOT be
6102 dynamic cause a private function descriptor to be created. The
6103 FUNCDESC relocation then decays to a 32 relocation that points at
6104 the private descriptor. If the symbol is dynamic, the FUNCDESC
6105 relocation is propagated to the linker output, such that the
6106 dynamic linker creates the canonical descriptor, pointing to the
6107 dynamically-resolved definition of the function.
6109 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
6110 symbols that are assigned to the same segment as the GOT, but we
6111 can only check this later, after we know the complete set of
6112 symbols defined and/or exported.
6114 FUNCDESC GOTOFF relocations require a function descriptor to be
6115 created and, unless lazy binding is disabled or the symbol is not
6116 dynamic, a lazy PLT entry. Since we can't tell at this point
6117 whether a symbol is going to be dynamic, we have to decide later
6118 whether to create a lazy PLT entry or bind the descriptor directly
6119 to the private function.
6121 FUNCDESC_VALUE relocations are not supposed to be present in object
6122 files, but they may very well be simply propagated to the linker
6123 output, since they have no side effect.
6126 A function descriptor always requires a FUNCDESC_VALUE relocation.
6127 Whether it's in .plt.rel or not depends on whether lazy binding is
6128 enabled and on whether the referenced symbol is dynamic.
6130 The existence of a lazy PLT requires the resolverStub lazy PLT
6131 entry to be present.
6134 As for assignment of GOT, PLT and lazy PLT entries, and private
6135 descriptors, we might do them all sequentially, but we can do
6136 better than that. For example, we can place GOT entries and
6137 private function descriptors referenced using 12-bit operands
6138 closer to the PIC register value, such that these relocations don't
6139 overflow. Those that are only referenced with LO16 relocations
6140 could come next, but we may as well place PLT-required function
6141 descriptors in the 12-bit range to make them shorter. Symbols
6142 referenced with LO16/HI16 may come next, but we may place
6143 additional function descriptors in the 16-bit range if we can
6144 reliably tell that we've already placed entries that are ever
6145 referenced with only LO16. PLT entries are therefore generated as
6146 small as possible, while not introducing relocation overflows in
6147 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
6148 generated before or after PLT entries, but not intermingled with
6149 them, such that we can have more lazy PLT entries in range for a
6150 branch to the resolverStub. The resolverStub should be emitted at
6151 the most distant location from the first lazy PLT entry such that
6152 it's still in range for a branch, or closer, if there isn't a need
6153 for so many lazy PLT entries. Additional lazy PLT entries may be
6154 emitted after the resolverStub, as long as branches are still in
6155 range. If the branch goes out of range, longer lazy PLT entries
6158 We could further optimize PLT and lazy PLT entries by giving them
6159 priority in assignment to closer-to-gr17 locations depending on the
6160 number of occurrences of references to them (assuming a function
6161 that's called more often is more important for performance, so its
6162 PLT entry should be faster), or taking hints from the compiler.
6163 Given infinite time and money... :-) */
6166 elf32_frv_check_relocs (abfd
, info
, sec
, relocs
)
6168 struct bfd_link_info
*info
;
6170 const Elf_Internal_Rela
*relocs
;
6172 Elf_Internal_Shdr
*symtab_hdr
;
6173 struct elf_link_hash_entry
**sym_hashes
;
6174 const Elf_Internal_Rela
*rel
;
6175 const Elf_Internal_Rela
*rel_end
;
6177 struct frvfdpic_relocs_info
*picrel
;
6179 if (info
->relocatable
)
6182 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6183 sym_hashes
= elf_sym_hashes (abfd
);
6185 dynobj
= elf_hash_table (info
)->dynobj
;
6186 rel_end
= relocs
+ sec
->reloc_count
;
6187 for (rel
= relocs
; rel
< rel_end
; rel
++)
6189 struct elf_link_hash_entry
*h
;
6190 unsigned long r_symndx
;
6192 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6193 if (r_symndx
< symtab_hdr
->sh_info
)
6197 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6198 while (h
->root
.type
== bfd_link_hash_indirect
6199 || h
->root
.type
== bfd_link_hash_warning
)
6200 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6203 switch (ELF32_R_TYPE (rel
->r_info
))
6205 case R_FRV_GETTLSOFF
:
6206 case R_FRV_TLSDESC_VALUE
:
6207 case R_FRV_GOTTLSDESC12
:
6208 case R_FRV_GOTTLSDESCHI
:
6209 case R_FRV_GOTTLSDESCLO
:
6210 case R_FRV_GOTTLSOFF12
:
6211 case R_FRV_GOTTLSOFFHI
:
6212 case R_FRV_GOTTLSOFFLO
:
6217 case R_FRV_FUNCDESC_GOT12
:
6218 case R_FRV_FUNCDESC_GOTHI
:
6219 case R_FRV_FUNCDESC_GOTLO
:
6220 case R_FRV_GOTOFF12
:
6221 case R_FRV_GOTOFFHI
:
6222 case R_FRV_GOTOFFLO
:
6223 case R_FRV_FUNCDESC_GOTOFF12
:
6224 case R_FRV_FUNCDESC_GOTOFFHI
:
6225 case R_FRV_FUNCDESC_GOTOFFLO
:
6226 case R_FRV_FUNCDESC
:
6227 case R_FRV_FUNCDESC_VALUE
:
6228 case R_FRV_TLSMOFF12
:
6229 case R_FRV_TLSMOFFHI
:
6230 case R_FRV_TLSMOFFLO
:
6232 if (! IS_FDPIC (abfd
))
6236 case R_FRV_GPRELU12
:
6243 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6244 if (! _frv_create_got_section (abfd
, info
))
6247 if (! IS_FDPIC (abfd
))
6254 if (h
->dynindx
== -1)
6255 switch (ELF_ST_VISIBILITY (h
->other
))
6261 bfd_elf_link_record_dynamic_symbol (info
, h
);
6265 = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info
),
6267 rel
->r_addend
, INSERT
);
6270 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
6271 (info
), abfd
, r_symndx
,
6272 rel
->r_addend
, INSERT
);
6282 switch (ELF32_R_TYPE (rel
->r_info
))
6285 if (IS_FDPIC (abfd
))
6289 case R_FRV_FUNCDESC_VALUE
:
6290 picrel
->relocsfdv
++;
6291 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
6296 if (! IS_FDPIC (abfd
))
6300 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
6310 picrel
->gothilo
= 1;
6313 case R_FRV_FUNCDESC_GOT12
:
6314 picrel
->fdgot12
= 1;
6317 case R_FRV_FUNCDESC_GOTHI
:
6318 case R_FRV_FUNCDESC_GOTLO
:
6319 picrel
->fdgothilo
= 1;
6322 case R_FRV_GOTOFF12
:
6323 case R_FRV_GOTOFFHI
:
6324 case R_FRV_GOTOFFLO
:
6328 case R_FRV_FUNCDESC_GOTOFF12
:
6329 picrel
->fdgoff12
= 1;
6332 case R_FRV_FUNCDESC_GOTOFFHI
:
6333 case R_FRV_FUNCDESC_GOTOFFLO
:
6334 picrel
->fdgoffhilo
= 1;
6337 case R_FRV_FUNCDESC
:
6342 case R_FRV_GETTLSOFF
:
6346 case R_FRV_TLSDESC_VALUE
:
6347 picrel
->relocstlsd
++;
6350 case R_FRV_GOTTLSDESC12
:
6351 picrel
->tlsdesc12
= 1;
6354 case R_FRV_GOTTLSDESCHI
:
6355 case R_FRV_GOTTLSDESCLO
:
6356 picrel
->tlsdeschilo
= 1;
6359 case R_FRV_TLSMOFF12
:
6360 case R_FRV_TLSMOFFHI
:
6361 case R_FRV_TLSMOFFLO
:
6365 case R_FRV_GOTTLSOFF12
:
6366 picrel
->tlsoff12
= 1;
6367 info
->flags
|= DF_STATIC_TLS
;
6370 case R_FRV_GOTTLSOFFHI
:
6371 case R_FRV_GOTTLSOFFLO
:
6372 picrel
->tlsoffhilo
= 1;
6373 info
->flags
|= DF_STATIC_TLS
;
6377 picrel
->relocstlsoff
++;
6378 info
->flags
|= DF_STATIC_TLS
;
6381 /* This relocation describes the C++ object vtable hierarchy.
6382 Reconstruct it for later use during GC. */
6383 case R_FRV_GNU_VTINHERIT
:
6384 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6388 /* This relocation describes which C++ vtable entries are actually
6389 used. Record for later use during GC. */
6390 case R_FRV_GNU_VTENTRY
:
6391 BFD_ASSERT (h
!= NULL
);
6393 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
6401 case R_FRV_GPRELU12
:
6405 case R_FRV_TLSDESC_RELAX
:
6406 case R_FRV_GETTLSOFF_RELAX
:
6407 case R_FRV_TLSOFF_RELAX
:
6412 (*_bfd_error_handler
)
6413 (_("%B: unsupported relocation type %i"),
6414 abfd
, ELF32_R_TYPE (rel
->r_info
));
6423 /* Return the machine subcode from the ELF e_flags header. */
6426 elf32_frv_machine (abfd
)
6429 switch (elf_elfheader (abfd
)->e_flags
& EF_FRV_CPU_MASK
)
6432 case EF_FRV_CPU_FR550
: return bfd_mach_fr550
;
6433 case EF_FRV_CPU_FR500
: return bfd_mach_fr500
;
6434 case EF_FRV_CPU_FR450
: return bfd_mach_fr450
;
6435 case EF_FRV_CPU_FR405
: return bfd_mach_fr400
;
6436 case EF_FRV_CPU_FR400
: return bfd_mach_fr400
;
6437 case EF_FRV_CPU_FR300
: return bfd_mach_fr300
;
6438 case EF_FRV_CPU_SIMPLE
: return bfd_mach_frvsimple
;
6439 case EF_FRV_CPU_TOMCAT
: return bfd_mach_frvtomcat
;
6442 return bfd_mach_frv
;
6445 /* Set the right machine number for a FRV ELF file. */
6448 elf32_frv_object_p (abfd
)
6451 bfd_default_set_arch_mach (abfd
, bfd_arch_frv
, elf32_frv_machine (abfd
));
6452 return (((elf_elfheader (abfd
)->e_flags
& EF_FRV_FDPIC
) != 0)
6453 == (IS_FDPIC (abfd
)));
6456 /* Function to set the ELF flag bits. */
6459 frv_elf_set_private_flags (abfd
, flags
)
6463 elf_elfheader (abfd
)->e_flags
= flags
;
6464 elf_flags_init (abfd
) = TRUE
;
6468 /* Copy backend specific data from one object module to another. */
6471 frv_elf_copy_private_bfd_data (ibfd
, obfd
)
6475 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6476 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6479 BFD_ASSERT (!elf_flags_init (obfd
)
6480 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
6482 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
6483 elf_flags_init (obfd
) = TRUE
;
6485 /* Copy object attributes. */
6486 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
6491 /* Return true if the architecture described by elf header flag
6492 EXTENSION is an extension of the architecture described by BASE. */
6495 frv_elf_arch_extension_p (flagword base
, flagword extension
)
6497 if (base
== extension
)
6500 /* CPU_GENERIC code can be merged with code for a specific
6501 architecture, in which case the result is marked as being
6502 for the specific architecture. Everything is therefore
6503 an extension of CPU_GENERIC. */
6504 if (base
== EF_FRV_CPU_GENERIC
)
6507 if (extension
== EF_FRV_CPU_FR450
)
6508 if (base
== EF_FRV_CPU_FR400
|| base
== EF_FRV_CPU_FR405
)
6511 if (extension
== EF_FRV_CPU_FR405
)
6512 if (base
== EF_FRV_CPU_FR400
)
6519 elf32_frvfdpic_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
6523 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6524 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6527 if (! frv_elf_copy_private_bfd_data (ibfd
, obfd
))
6530 if (! elf_tdata (ibfd
) || ! elf_tdata (ibfd
)->phdr
6531 || ! elf_tdata (obfd
) || ! elf_tdata (obfd
)->phdr
)
6534 /* Copy the stack size. */
6535 for (i
= 0; i
< elf_elfheader (ibfd
)->e_phnum
; i
++)
6536 if (elf_tdata (ibfd
)->phdr
[i
].p_type
== PT_GNU_STACK
)
6538 Elf_Internal_Phdr
*iphdr
= &elf_tdata (ibfd
)->phdr
[i
];
6540 for (i
= 0; i
< elf_elfheader (obfd
)->e_phnum
; i
++)
6541 if (elf_tdata (obfd
)->phdr
[i
].p_type
== PT_GNU_STACK
)
6543 memcpy (&elf_tdata (obfd
)->phdr
[i
], iphdr
, sizeof (*iphdr
));
6545 /* Rewrite the phdrs, since we're only called after they
6546 were first written. */
6547 if (bfd_seek (obfd
, (bfd_signed_vma
) get_elf_backend_data (obfd
)
6548 ->s
->sizeof_ehdr
, SEEK_SET
) != 0
6549 || get_elf_backend_data (obfd
)->s
6550 ->write_out_phdrs (obfd
, elf_tdata (obfd
)->phdr
,
6551 elf_elfheader (obfd
)->e_phnum
) != 0)
6562 /* Merge backend specific data from an object file to the output
6563 object file when linking. */
6566 frv_elf_merge_private_bfd_data (ibfd
, obfd
)
6570 flagword old_flags
, old_partial
;
6571 flagword new_flags
, new_partial
;
6572 bfd_boolean error
= FALSE
;
6576 new_opt
[0] = old_opt
[0] = '\0';
6577 new_flags
= elf_elfheader (ibfd
)->e_flags
;
6578 old_flags
= elf_elfheader (obfd
)->e_flags
;
6580 if (new_flags
& EF_FRV_FDPIC
)
6581 new_flags
&= ~EF_FRV_PIC
;
6584 (*_bfd_error_handler
) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s",
6585 old_flags
, new_flags
, elf_flags_init (obfd
) ? "yes" : "no",
6586 bfd_get_filename (ibfd
));
6589 if (!elf_flags_init (obfd
)) /* First call, no flags set. */
6591 elf_flags_init (obfd
) = TRUE
;
6592 old_flags
= new_flags
;
6595 else if (new_flags
== old_flags
) /* Compatible flags are ok. */
6598 else /* Possibly incompatible flags. */
6600 /* Warn if different # of gprs are used. Note, 0 means nothing is
6601 said about the size of gprs. */
6602 new_partial
= (new_flags
& EF_FRV_GPR_MASK
);
6603 old_partial
= (old_flags
& EF_FRV_GPR_MASK
);
6604 if (new_partial
== old_partial
)
6607 else if (new_partial
== 0)
6610 else if (old_partial
== 0)
6611 old_flags
|= new_partial
;
6615 switch (new_partial
)
6617 default: strcat (new_opt
, " -mgpr-??"); break;
6618 case EF_FRV_GPR_32
: strcat (new_opt
, " -mgpr-32"); break;
6619 case EF_FRV_GPR_64
: strcat (new_opt
, " -mgpr-64"); break;
6622 switch (old_partial
)
6624 default: strcat (old_opt
, " -mgpr-??"); break;
6625 case EF_FRV_GPR_32
: strcat (old_opt
, " -mgpr-32"); break;
6626 case EF_FRV_GPR_64
: strcat (old_opt
, " -mgpr-64"); break;
6630 /* Warn if different # of fprs are used. Note, 0 means nothing is
6631 said about the size of fprs. */
6632 new_partial
= (new_flags
& EF_FRV_FPR_MASK
);
6633 old_partial
= (old_flags
& EF_FRV_FPR_MASK
);
6634 if (new_partial
== old_partial
)
6637 else if (new_partial
== 0)
6640 else if (old_partial
== 0)
6641 old_flags
|= new_partial
;
6645 switch (new_partial
)
6647 default: strcat (new_opt
, " -mfpr-?"); break;
6648 case EF_FRV_FPR_32
: strcat (new_opt
, " -mfpr-32"); break;
6649 case EF_FRV_FPR_64
: strcat (new_opt
, " -mfpr-64"); break;
6650 case EF_FRV_FPR_NONE
: strcat (new_opt
, " -msoft-float"); break;
6653 switch (old_partial
)
6655 default: strcat (old_opt
, " -mfpr-?"); break;
6656 case EF_FRV_FPR_32
: strcat (old_opt
, " -mfpr-32"); break;
6657 case EF_FRV_FPR_64
: strcat (old_opt
, " -mfpr-64"); break;
6658 case EF_FRV_FPR_NONE
: strcat (old_opt
, " -msoft-float"); break;
6662 /* Warn if different dword support was used. Note, 0 means nothing is
6663 said about the dword support. */
6664 new_partial
= (new_flags
& EF_FRV_DWORD_MASK
);
6665 old_partial
= (old_flags
& EF_FRV_DWORD_MASK
);
6666 if (new_partial
== old_partial
)
6669 else if (new_partial
== 0)
6672 else if (old_partial
== 0)
6673 old_flags
|= new_partial
;
6677 switch (new_partial
)
6679 default: strcat (new_opt
, " -mdword-?"); break;
6680 case EF_FRV_DWORD_YES
: strcat (new_opt
, " -mdword"); break;
6681 case EF_FRV_DWORD_NO
: strcat (new_opt
, " -mno-dword"); break;
6684 switch (old_partial
)
6686 default: strcat (old_opt
, " -mdword-?"); break;
6687 case EF_FRV_DWORD_YES
: strcat (old_opt
, " -mdword"); break;
6688 case EF_FRV_DWORD_NO
: strcat (old_opt
, " -mno-dword"); break;
6692 /* Or in flags that accumulate (ie, if one module uses it, mark that the
6694 old_flags
|= new_flags
& (EF_FRV_DOUBLE
6697 | EF_FRV_NON_PIC_RELOCS
);
6699 /* If any module was compiled without -G0, clear the G0 bit. */
6700 old_flags
= ((old_flags
& ~ EF_FRV_G0
)
6701 | (old_flags
& new_flags
& EF_FRV_G0
));
6703 /* If any module was compiled without -mnopack, clear the mnopack bit. */
6704 old_flags
= ((old_flags
& ~ EF_FRV_NOPACK
)
6705 | (old_flags
& new_flags
& EF_FRV_NOPACK
));
6707 /* We don't have to do anything if the pic flags are the same, or the new
6708 module(s) were compiled with -mlibrary-pic. */
6709 new_partial
= (new_flags
& EF_FRV_PIC_FLAGS
);
6710 old_partial
= (old_flags
& EF_FRV_PIC_FLAGS
);
6711 if ((new_partial
== old_partial
) || ((new_partial
& EF_FRV_LIBPIC
) != 0))
6714 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
6715 flags if any from the new module. */
6716 else if ((old_partial
& EF_FRV_LIBPIC
) != 0)
6717 old_flags
= (old_flags
& ~ EF_FRV_PIC_FLAGS
) | new_partial
;
6719 /* If we have mixtures of -fpic and -fPIC, or in both bits. */
6720 else if (new_partial
!= 0 && old_partial
!= 0)
6721 old_flags
|= new_partial
;
6723 /* One module was compiled for pic and the other was not, see if we have
6724 had any relocations that are not pic-safe. */
6727 if ((old_flags
& EF_FRV_NON_PIC_RELOCS
) == 0)
6728 old_flags
|= new_partial
;
6731 old_flags
&= ~ EF_FRV_PIC_FLAGS
;
6732 #ifndef FRV_NO_PIC_ERROR
6734 (*_bfd_error_handler
)
6735 (_("%s: compiled with %s and linked with modules that use non-pic relocations"),
6736 bfd_get_filename (ibfd
),
6737 (new_flags
& EF_FRV_BIGPIC
) ? "-fPIC" : "-fpic");
6742 /* Warn if different cpu is used (allow a specific cpu to override
6743 the generic cpu). */
6744 new_partial
= (new_flags
& EF_FRV_CPU_MASK
);
6745 old_partial
= (old_flags
& EF_FRV_CPU_MASK
);
6746 if (frv_elf_arch_extension_p (new_partial
, old_partial
))
6749 else if (frv_elf_arch_extension_p (old_partial
, new_partial
))
6750 old_flags
= (old_flags
& ~EF_FRV_CPU_MASK
) | new_partial
;
6754 switch (new_partial
)
6756 default: strcat (new_opt
, " -mcpu=?"); break;
6757 case EF_FRV_CPU_GENERIC
: strcat (new_opt
, " -mcpu=frv"); break;
6758 case EF_FRV_CPU_SIMPLE
: strcat (new_opt
, " -mcpu=simple"); break;
6759 case EF_FRV_CPU_FR550
: strcat (new_opt
, " -mcpu=fr550"); break;
6760 case EF_FRV_CPU_FR500
: strcat (new_opt
, " -mcpu=fr500"); break;
6761 case EF_FRV_CPU_FR450
: strcat (new_opt
, " -mcpu=fr450"); break;
6762 case EF_FRV_CPU_FR405
: strcat (new_opt
, " -mcpu=fr405"); break;
6763 case EF_FRV_CPU_FR400
: strcat (new_opt
, " -mcpu=fr400"); break;
6764 case EF_FRV_CPU_FR300
: strcat (new_opt
, " -mcpu=fr300"); break;
6765 case EF_FRV_CPU_TOMCAT
: strcat (new_opt
, " -mcpu=tomcat"); break;
6768 switch (old_partial
)
6770 default: strcat (old_opt
, " -mcpu=?"); break;
6771 case EF_FRV_CPU_GENERIC
: strcat (old_opt
, " -mcpu=frv"); break;
6772 case EF_FRV_CPU_SIMPLE
: strcat (old_opt
, " -mcpu=simple"); break;
6773 case EF_FRV_CPU_FR550
: strcat (old_opt
, " -mcpu=fr550"); break;
6774 case EF_FRV_CPU_FR500
: strcat (old_opt
, " -mcpu=fr500"); break;
6775 case EF_FRV_CPU_FR450
: strcat (old_opt
, " -mcpu=fr450"); break;
6776 case EF_FRV_CPU_FR405
: strcat (old_opt
, " -mcpu=fr405"); break;
6777 case EF_FRV_CPU_FR400
: strcat (old_opt
, " -mcpu=fr400"); break;
6778 case EF_FRV_CPU_FR300
: strcat (old_opt
, " -mcpu=fr300"); break;
6779 case EF_FRV_CPU_TOMCAT
: strcat (old_opt
, " -mcpu=tomcat"); break;
6783 /* Print out any mismatches from above. */
6787 (*_bfd_error_handler
)
6788 (_("%s: compiled with %s and linked with modules compiled with %s"),
6789 bfd_get_filename (ibfd
), new_opt
, old_opt
);
6792 /* Warn about any other mismatches */
6793 new_partial
= (new_flags
& ~ EF_FRV_ALL_FLAGS
);
6794 old_partial
= (old_flags
& ~ EF_FRV_ALL_FLAGS
);
6795 if (new_partial
!= old_partial
)
6797 old_flags
|= new_partial
;
6799 (*_bfd_error_handler
)
6800 (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"),
6801 bfd_get_filename (ibfd
), (long)new_partial
, (long)old_partial
);
6805 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
6806 if ((old_flags
& EF_FRV_CPU_MASK
) == EF_FRV_CPU_SIMPLE
)
6807 old_flags
|= EF_FRV_NOPACK
;
6809 /* Update the old flags now with changes made above. */
6810 old_partial
= elf_elfheader (obfd
)->e_flags
& EF_FRV_CPU_MASK
;
6811 elf_elfheader (obfd
)->e_flags
= old_flags
;
6812 if (old_partial
!= (old_flags
& EF_FRV_CPU_MASK
))
6813 bfd_default_set_arch_mach (obfd
, bfd_arch_frv
, elf32_frv_machine (obfd
));
6815 if (((new_flags
& EF_FRV_FDPIC
) == 0)
6816 != (! IS_FDPIC (ibfd
)))
6819 if (IS_FDPIC (obfd
))
6820 (*_bfd_error_handler
)
6821 (_("%s: cannot link non-fdpic object file into fdpic executable"),
6822 bfd_get_filename (ibfd
));
6824 (*_bfd_error_handler
)
6825 (_("%s: cannot link fdpic object file into non-fdpic executable"),
6826 bfd_get_filename (ibfd
));
6830 bfd_set_error (bfd_error_bad_value
);
6837 frv_elf_print_private_bfd_data (abfd
, ptr
)
6841 FILE *file
= (FILE *) ptr
;
6844 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6846 /* Print normal ELF private data. */
6847 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6849 flags
= elf_elfheader (abfd
)->e_flags
;
6850 fprintf (file
, _("private flags = 0x%lx:"), (long)flags
);
6852 switch (flags
& EF_FRV_CPU_MASK
)
6855 case EF_FRV_CPU_SIMPLE
: fprintf (file
, " -mcpu=simple"); break;
6856 case EF_FRV_CPU_FR550
: fprintf (file
, " -mcpu=fr550"); break;
6857 case EF_FRV_CPU_FR500
: fprintf (file
, " -mcpu=fr500"); break;
6858 case EF_FRV_CPU_FR450
: fprintf (file
, " -mcpu=fr450"); break;
6859 case EF_FRV_CPU_FR405
: fprintf (file
, " -mcpu=fr405"); break;
6860 case EF_FRV_CPU_FR400
: fprintf (file
, " -mcpu=fr400"); break;
6861 case EF_FRV_CPU_FR300
: fprintf (file
, " -mcpu=fr300"); break;
6862 case EF_FRV_CPU_TOMCAT
: fprintf (file
, " -mcpu=tomcat"); break;
6865 switch (flags
& EF_FRV_GPR_MASK
)
6868 case EF_FRV_GPR_32
: fprintf (file
, " -mgpr-32"); break;
6869 case EF_FRV_GPR_64
: fprintf (file
, " -mgpr-64"); break;
6872 switch (flags
& EF_FRV_FPR_MASK
)
6875 case EF_FRV_FPR_32
: fprintf (file
, " -mfpr-32"); break;
6876 case EF_FRV_FPR_64
: fprintf (file
, " -mfpr-64"); break;
6877 case EF_FRV_FPR_NONE
: fprintf (file
, " -msoft-float"); break;
6880 switch (flags
& EF_FRV_DWORD_MASK
)
6883 case EF_FRV_DWORD_YES
: fprintf (file
, " -mdword"); break;
6884 case EF_FRV_DWORD_NO
: fprintf (file
, " -mno-dword"); break;
6887 if (flags
& EF_FRV_DOUBLE
)
6888 fprintf (file
, " -mdouble");
6890 if (flags
& EF_FRV_MEDIA
)
6891 fprintf (file
, " -mmedia");
6893 if (flags
& EF_FRV_MULADD
)
6894 fprintf (file
, " -mmuladd");
6896 if (flags
& EF_FRV_PIC
)
6897 fprintf (file
, " -fpic");
6899 if (flags
& EF_FRV_BIGPIC
)
6900 fprintf (file
, " -fPIC");
6902 if (flags
& EF_FRV_LIBPIC
)
6903 fprintf (file
, " -mlibrary-pic");
6905 if (flags
& EF_FRV_FDPIC
)
6906 fprintf (file
, " -mfdpic");
6908 if (flags
& EF_FRV_NON_PIC_RELOCS
)
6909 fprintf (file
, " non-pic relocations");
6911 if (flags
& EF_FRV_G0
)
6912 fprintf (file
, " -G0");
6919 /* Support for core dump NOTE sections. */
6922 elf32_frv_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
6925 unsigned int raw_size
;
6927 switch (note
->descsz
)
6932 /* The Linux/FRV elf_prstatus struct is 268 bytes long. The other
6933 hardcoded offsets and sizes listed below (and contained within
6934 this lexical block) refer to fields in the target's elf_prstatus
6937 /* `pr_cursig' is at offset 12. */
6938 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
6940 /* `pr_pid' is at offset 24. */
6941 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
6943 /* `pr_reg' is at offset 72. */
6946 /* Most grok_prstatus implementations set `raw_size' to the size
6947 of the pr_reg field. For Linux/FRV, we set `raw_size' to be
6948 the size of `pr_reg' plus the size of `pr_exec_fdpic_loadmap'
6949 and `pr_interp_fdpic_loadmap', both of which (by design)
6950 immediately follow `pr_reg'. This will allow these fields to
6951 be viewed by GDB as registers.
6953 `pr_reg' is 184 bytes long. `pr_exec_fdpic_loadmap' and
6954 `pr_interp_fdpic_loadmap' are 4 bytes each. */
6955 raw_size
= 184 + 4 + 4;
6960 /* Make a ".reg/999" section. */
6961 return _bfd_elfcore_make_pseudosection (abfd
, ".reg", raw_size
,
6962 note
->descpos
+ offset
);
6966 elf32_frv_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
6968 switch (note
->descsz
)
6973 /* The Linux/FRV elf_prpsinfo struct is 124 bytes long. */
6976 /* `pr_fname' is found at offset 28 and is 16 bytes long. */
6977 elf_tdata (abfd
)->core_program
6978 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
6980 /* `pr_psargs' is found at offset 44 and is 80 bytes long. */
6981 elf_tdata (abfd
)->core_command
6982 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
6985 /* Note that for some reason, a spurious space is tacked
6986 onto the end of the args in some (at least one anyway)
6987 implementations, so strip it off if it exists. */
6990 char *command
= elf_tdata (abfd
)->core_command
;
6991 int n
= strlen (command
);
6993 if (0 < n
&& command
[n
- 1] == ' ')
6994 command
[n
- 1] = '\0';
6999 #define ELF_ARCH bfd_arch_frv
7000 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
7001 #define ELF_MAXPAGESIZE 0x1000
7003 #define TARGET_BIG_SYM bfd_elf32_frv_vec
7004 #define TARGET_BIG_NAME "elf32-frv"
7006 #define elf_info_to_howto frv_info_to_howto_rela
7007 #define elf_backend_relocate_section elf32_frv_relocate_section
7008 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
7009 #define elf_backend_check_relocs elf32_frv_check_relocs
7010 #define elf_backend_object_p elf32_frv_object_p
7011 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
7013 #define elf_backend_can_gc_sections 1
7014 #define elf_backend_rela_normal 1
7016 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
7017 #define bfd_elf32_bfd_reloc_name_lookup frv_reloc_name_lookup
7018 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
7019 #define bfd_elf32_bfd_copy_private_bfd_data frv_elf_copy_private_bfd_data
7020 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
7021 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
7023 #define elf_backend_want_got_sym 1
7024 #define elf_backend_got_header_size 0
7025 #define elf_backend_want_got_plt 0
7026 #define elf_backend_plt_readonly 1
7027 #define elf_backend_want_plt_sym 0
7028 #define elf_backend_plt_header_size 0
7030 #define elf_backend_finish_dynamic_sections \
7031 elf32_frv_finish_dynamic_sections
7033 #define elf_backend_grok_prstatus elf32_frv_grok_prstatus
7034 #define elf_backend_grok_psinfo elf32_frv_grok_psinfo
7036 #include "elf32-target.h"
7038 #undef ELF_MAXPAGESIZE
7039 #define ELF_MAXPAGESIZE 0x4000
7041 #undef TARGET_BIG_SYM
7042 #define TARGET_BIG_SYM bfd_elf32_frvfdpic_vec
7043 #undef TARGET_BIG_NAME
7044 #define TARGET_BIG_NAME "elf32-frvfdpic"
7046 #define elf32_bed elf32_frvfdpic_bed
7048 #undef elf_info_to_howto_rel
7049 #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel
7051 #undef bfd_elf32_bfd_link_hash_table_create
7052 #define bfd_elf32_bfd_link_hash_table_create \
7053 frvfdpic_elf_link_hash_table_create
7054 #undef elf_backend_always_size_sections
7055 #define elf_backend_always_size_sections \
7056 elf32_frvfdpic_always_size_sections
7057 #undef elf_backend_modify_program_headers
7058 #define elf_backend_modify_program_headers \
7059 elf32_frvfdpic_modify_program_headers
7060 #undef bfd_elf32_bfd_copy_private_bfd_data
7061 #define bfd_elf32_bfd_copy_private_bfd_data \
7062 elf32_frvfdpic_copy_private_bfd_data
7064 #undef elf_backend_create_dynamic_sections
7065 #define elf_backend_create_dynamic_sections \
7066 elf32_frvfdpic_create_dynamic_sections
7067 #undef elf_backend_adjust_dynamic_symbol
7068 #define elf_backend_adjust_dynamic_symbol \
7069 elf32_frvfdpic_adjust_dynamic_symbol
7070 #undef elf_backend_size_dynamic_sections
7071 #define elf_backend_size_dynamic_sections \
7072 elf32_frvfdpic_size_dynamic_sections
7073 #undef bfd_elf32_bfd_relax_section
7074 #define bfd_elf32_bfd_relax_section \
7075 elf32_frvfdpic_relax_section
7076 #undef elf_backend_finish_dynamic_symbol
7077 #define elf_backend_finish_dynamic_symbol \
7078 elf32_frvfdpic_finish_dynamic_symbol
7079 #undef elf_backend_finish_dynamic_sections
7080 #define elf_backend_finish_dynamic_sections \
7081 elf32_frvfdpic_finish_dynamic_sections
7083 #undef elf_backend_discard_info
7084 #define elf_backend_discard_info \
7085 frvfdpic_elf_discard_info
7086 #undef elf_backend_can_make_relative_eh_frame
7087 #define elf_backend_can_make_relative_eh_frame \
7088 frvfdpic_elf_use_relative_eh_frame
7089 #undef elf_backend_can_make_lsda_relative_eh_frame
7090 #define elf_backend_can_make_lsda_relative_eh_frame \
7091 frvfdpic_elf_use_relative_eh_frame
7092 #undef elf_backend_encode_eh_address
7093 #define elf_backend_encode_eh_address \
7094 frvfdpic_elf_encode_eh_address
7096 #undef elf_backend_may_use_rel_p
7097 #define elf_backend_may_use_rel_p 1
7098 #undef elf_backend_may_use_rela_p
7099 #define elf_backend_may_use_rela_p 1
7100 /* We use REL for dynamic relocations only. */
7101 #undef elf_backend_default_use_rela_p
7102 #define elf_backend_default_use_rela_p 1
7104 #undef elf_backend_omit_section_dynsym
7105 #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym
7107 #include "elf32-target.h"