1 /* FRV-specific support for 32-bit ELF.
2 Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
30 /* Forward declarations. */
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(p) \
886 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
887 == FRV_ELF_DATA ? ((struct frvfdpic_elf_link_hash_table *) ((p)->hash)) : NULL)
889 #define frvfdpic_got_section(info) \
890 (frvfdpic_hash_table (info)->sgot)
891 #define frvfdpic_gotrel_section(info) \
892 (frvfdpic_hash_table (info)->sgotrel)
893 #define frvfdpic_gotfixup_section(info) \
894 (frvfdpic_hash_table (info)->sgotfixup)
895 #define frvfdpic_plt_section(info) \
896 (frvfdpic_hash_table (info)->splt)
897 #define frvfdpic_pltrel_section(info) \
898 (frvfdpic_hash_table (info)->spltrel)
899 #define frvfdpic_relocs_info(info) \
900 (frvfdpic_hash_table (info)->relocs_info)
901 #define frvfdpic_got_initial_offset(info) \
902 (frvfdpic_hash_table (info)->got0)
903 #define frvfdpic_plt_initial_offset(info) \
904 (frvfdpic_hash_table (info)->plt0)
905 #define frvfdpic_dynamic_got_plt_info(info) \
906 (frvfdpic_hash_table (info)->g)
908 /* Currently it's the same, but if some day we have a reason to change
909 it, we'd better be using a different macro.
911 FIXME: if there's any TLS PLT entry that uses local-exec or
912 initial-exec models, we could use the ret at the end of any of them
913 instead of adding one more. */
914 #define frvfdpic_plt_tls_ret_offset(info) \
915 (frvfdpic_plt_initial_offset (info))
917 /* The name of the dynamic interpreter. This is put in the .interp
920 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
922 #define DEFAULT_STACK_SIZE 0x20000
924 /* This structure is used to collect the number of entries present in
925 each addressable range of the got. */
926 struct _frvfdpic_dynamic_got_info
928 /* Several bits of information about the current link. */
929 struct bfd_link_info
*info
;
930 /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit
932 bfd_vma got12
, gotlos
, gothilo
;
933 /* Total GOT size needed for function descriptor entries within the 12-,
934 16- or 32-bit ranges. */
935 bfd_vma fd12
, fdlos
, fdhilo
;
936 /* Total GOT size needed by function descriptor entries referenced
937 in PLT entries, that would be profitable to place in offsets
938 close to the PIC register. */
940 /* Total PLT size needed by lazy PLT entries. */
942 /* Total GOT size needed for TLS descriptor entries within the 12-,
943 16- or 32-bit ranges. */
944 bfd_vma tlsd12
, tlsdlos
, tlsdhilo
;
945 /* Total GOT size needed by TLS descriptors referenced in PLT
946 entries, that would be profitable to place in offers close to the
949 /* Total PLT size needed by TLS lazy PLT entries. */
951 /* Number of relocations carried over from input object files. */
952 unsigned long relocs
;
953 /* Number of fixups introduced by relocations in input object files. */
954 unsigned long fixups
;
955 /* The number of fixups that reference the ret instruction added to
956 the PLT for locally-resolved TLS descriptors. */
957 unsigned long tls_ret_refs
;
960 /* This structure is used to assign offsets to got entries, function
961 descriptors, plt entries and lazy plt entries. */
963 struct _frvfdpic_dynamic_got_plt_info
965 /* Summary information collected with _frvfdpic_count_got_plt_entries. */
966 struct _frvfdpic_dynamic_got_info g
;
968 /* For each addressable range, we record a MAX (positive) and MIN
969 (negative) value. CUR is used to assign got entries, and it's
970 incremented from an initial positive value to MAX, then from MIN
971 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
972 assign function descriptors, and it's decreased from an initial
973 non-positive value to MIN, then from MAX down to CUR (unless CUR
974 wraps around first). All of MIN, MAX, CUR and FDCUR always point
975 to even words. ODD, if non-zero, indicates an odd word to be
976 used for the next got entry, otherwise CUR is used and
977 incremented by a pair of words, wrapping around when it reaches
978 MAX. FDCUR is decremented (and wrapped) before the next function
979 descriptor is chosen. FDPLT indicates the number of remaining
980 slots that can be used for function descriptors used only by PLT
983 TMAX, TMIN and TCUR are used to assign TLS descriptors. TCUR
984 starts as MAX, and grows up to TMAX, then wraps around to TMIN
985 and grows up to MIN. TLSDPLT indicates the number of remaining
986 slots that can be used for TLS descriptors used only by TLS PLT
988 struct _frvfdpic_dynamic_got_alloc_data
990 bfd_signed_vma max
, cur
, odd
, fdcur
, min
;
991 bfd_signed_vma tmax
, tcur
, tmin
;
992 bfd_vma fdplt
, tlsdplt
;
993 } got12
, gotlos
, gothilo
;
996 /* Create an FRV ELF linker hash table. */
998 static struct bfd_link_hash_table
*
999 frvfdpic_elf_link_hash_table_create (bfd
*abfd
)
1001 struct frvfdpic_elf_link_hash_table
*ret
;
1002 bfd_size_type amt
= sizeof (struct frvfdpic_elf_link_hash_table
);
1004 ret
= bfd_zalloc (abfd
, amt
);
1008 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1009 _bfd_elf_link_hash_newfunc
,
1010 sizeof (struct elf_link_hash_entry
),
1017 return &ret
->elf
.root
;
1020 /* Decide whether a reference to a symbol can be resolved locally or
1021 not. If the symbol is protected, we want the local address, but
1022 its function descriptor must be assigned by the dynamic linker. */
1023 #define FRVFDPIC_SYM_LOCAL(INFO, H) \
1024 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
1025 || ! elf_hash_table (INFO)->dynamic_sections_created)
1026 #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \
1027 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
1029 /* This structure collects information on what kind of GOT, PLT or
1030 function descriptors are required by relocations that reference a
1032 struct frvfdpic_relocs_info
1034 /* The index of the symbol, as stored in the relocation r_info, if
1035 we have a local symbol; -1 otherwise. */
1039 /* The input bfd in which the symbol is defined, if it's a local
1042 /* If symndx == -1, the hash table entry corresponding to a global
1043 symbol (even if it turns out to bind locally, in which case it
1044 should ideally be replaced with section's symndx + addend). */
1045 struct elf_link_hash_entry
*h
;
1047 /* The addend of the relocation that references the symbol. */
1050 /* The fields above are used to identify an entry. The fields below
1051 contain information on how an entry is used and, later on, which
1052 locations it was assigned. */
1053 /* The following 3 fields record whether the symbol+addend above was
1054 ever referenced with a GOT relocation. The 12 suffix indicates a
1055 GOT12 relocation; los is used for GOTLO relocations that are not
1056 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
1061 /* Whether a FUNCDESC relocation references symbol+addend. */
1063 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
1065 unsigned fdgotlos
:1;
1066 unsigned fdgothilo
:1;
1067 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
1068 unsigned fdgoff12
:1;
1069 unsigned fdgofflos
:1;
1070 unsigned fdgoffhilo
:1;
1071 /* Whether a GETTLSOFF relocation references symbol+addend. */
1073 /* FIXME: we should probably add tlspltdesc, tlspltoff and
1074 tlspltimm, to tell what kind of TLS PLT entry we're generating.
1075 We might instead just pre-compute flags telling whether the
1076 object is suitable for local exec, initial exec or general
1077 dynamic addressing, and use that all over the place. We could
1078 also try to do a better job of merging TLSOFF and TLSDESC entries
1079 in main executables, but perhaps we can get rid of TLSDESC
1080 entirely in them instead. */
1081 /* Whether a GOTTLSDESC relocation references symbol+addend. */
1082 unsigned tlsdesc12
:1;
1083 unsigned tlsdesclos
:1;
1084 unsigned tlsdeschilo
:1;
1085 /* Whether a GOTTLSOFF relocation references symbol+addend. */
1086 unsigned tlsoff12
:1;
1087 unsigned tlsofflos
:1;
1088 unsigned tlsoffhilo
:1;
1089 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
1090 GOTOFFHI relocations. The addend doesn't really matter, since we
1091 envision that this will only be used to check whether the symbol
1092 is mapped to the same segment as the got. */
1094 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
1096 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
1099 /* Whether we need a PLT entry for a symbol. Should be implied by
1101 (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */
1103 /* Whether a function descriptor should be created in this link unit
1104 for symbol+addend. Should be implied by something like:
1105 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
1106 || ((fd || fdgot12 || fdgotlos || fdgothilo)
1107 && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */
1109 /* Whether a lazy PLT entry is needed for this symbol+addend.
1110 Should be implied by something like:
1111 (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)
1112 && ! (info->flags & DF_BIND_NOW)) */
1114 /* Whether we've already emitted GOT relocations and PLT entries as
1115 needed for this symbol. */
1118 /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and
1119 R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing
1121 unsigned relocs32
, relocsfd
, relocsfdv
, relocstlsd
, relocstlsoff
;
1123 /* The number of .rofixups entries and dynamic relocations allocated
1124 for this symbol, minus any that might have already been used. */
1125 unsigned fixups
, dynrelocs
;
1127 /* The offsets of the GOT entries assigned to symbol+addend, to the
1128 function descriptor's address, and to a function descriptor,
1129 respectively. Should be zero if unassigned. The offsets are
1130 counted from the value that will be assigned to the PIC register,
1131 not from the beginning of the .got section. */
1132 bfd_signed_vma got_entry
, fdgot_entry
, fd_entry
;
1133 /* The offsets of the PLT entries assigned to symbol+addend,
1134 non-lazy and lazy, respectively. If unassigned, should be
1136 bfd_vma plt_entry
, lzplt_entry
;
1137 /* The offsets of the GOT entries for TLS offset and TLS descriptor. */
1138 bfd_signed_vma tlsoff_entry
, tlsdesc_entry
;
1139 /* The offset of the TLS offset PLT entry. */
1140 bfd_vma tlsplt_entry
;
1143 /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */
1145 frvfdpic_relocs_info_hash (const void *entry_
)
1147 const struct frvfdpic_relocs_info
*entry
= entry_
;
1149 return (entry
->symndx
== -1
1150 ? (long) entry
->d
.h
->root
.root
.hash
1151 : entry
->symndx
+ (long) entry
->d
.abfd
->id
* 257) + entry
->addend
;
1154 /* Test whether the key fields of two frvfdpic_relocs_info entries are
1157 frvfdpic_relocs_info_eq (const void *entry1
, const void *entry2
)
1159 const struct frvfdpic_relocs_info
*e1
= entry1
;
1160 const struct frvfdpic_relocs_info
*e2
= entry2
;
1162 return e1
->symndx
== e2
->symndx
&& e1
->addend
== e2
->addend
1163 && (e1
->symndx
== -1 ? e1
->d
.h
== e2
->d
.h
: e1
->d
.abfd
== e2
->d
.abfd
);
1166 /* Find or create an entry in a hash table HT that matches the key
1167 fields of the given ENTRY. If it's not found, memory for a new
1168 entry is allocated in ABFD's obstack. */
1169 static struct frvfdpic_relocs_info
*
1170 frvfdpic_relocs_info_find (struct htab
*ht
,
1172 const struct frvfdpic_relocs_info
*entry
,
1173 enum insert_option insert
)
1175 struct frvfdpic_relocs_info
**loc
=
1176 (struct frvfdpic_relocs_info
**) htab_find_slot (ht
, entry
, insert
);
1184 *loc
= bfd_zalloc (abfd
, sizeof (**loc
));
1189 (*loc
)->symndx
= entry
->symndx
;
1190 (*loc
)->d
= entry
->d
;
1191 (*loc
)->addend
= entry
->addend
;
1192 (*loc
)->plt_entry
= (bfd_vma
)-1;
1193 (*loc
)->lzplt_entry
= (bfd_vma
)-1;
1194 (*loc
)->tlsplt_entry
= (bfd_vma
)-1;
1199 /* Obtain the address of the entry in HT associated with H's symbol +
1200 addend, creating a new entry if none existed. ABFD is only used
1201 for memory allocation purposes. */
1202 inline static struct frvfdpic_relocs_info
*
1203 frvfdpic_relocs_info_for_global (struct htab
*ht
,
1205 struct elf_link_hash_entry
*h
,
1207 enum insert_option insert
)
1209 struct frvfdpic_relocs_info entry
;
1213 entry
.addend
= addend
;
1215 return frvfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1218 /* Obtain the address of the entry in HT associated with the SYMNDXth
1219 local symbol of the input bfd ABFD, plus the addend, creating a new
1220 entry if none existed. */
1221 inline static struct frvfdpic_relocs_info
*
1222 frvfdpic_relocs_info_for_local (struct htab
*ht
,
1226 enum insert_option insert
)
1228 struct frvfdpic_relocs_info entry
;
1230 entry
.symndx
= symndx
;
1231 entry
.d
.abfd
= abfd
;
1232 entry
.addend
= addend
;
1234 return frvfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1237 /* Merge fields set by check_relocs() of two entries that end up being
1238 mapped to the same (presumably global) symbol. */
1241 frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info
*e2
,
1242 struct frvfdpic_relocs_info
const *e1
)
1244 e2
->got12
|= e1
->got12
;
1245 e2
->gotlos
|= e1
->gotlos
;
1246 e2
->gothilo
|= e1
->gothilo
;
1248 e2
->fdgot12
|= e1
->fdgot12
;
1249 e2
->fdgotlos
|= e1
->fdgotlos
;
1250 e2
->fdgothilo
|= e1
->fdgothilo
;
1251 e2
->fdgoff12
|= e1
->fdgoff12
;
1252 e2
->fdgofflos
|= e1
->fdgofflos
;
1253 e2
->fdgoffhilo
|= e1
->fdgoffhilo
;
1254 e2
->tlsplt
|= e1
->tlsplt
;
1255 e2
->tlsdesc12
|= e1
->tlsdesc12
;
1256 e2
->tlsdesclos
|= e1
->tlsdesclos
;
1257 e2
->tlsdeschilo
|= e1
->tlsdeschilo
;
1258 e2
->tlsoff12
|= e1
->tlsoff12
;
1259 e2
->tlsofflos
|= e1
->tlsofflos
;
1260 e2
->tlsoffhilo
|= e1
->tlsoffhilo
;
1261 e2
->gotoff
|= e1
->gotoff
;
1262 e2
->call
|= e1
->call
;
1266 /* Every block of 65535 lazy PLT entries shares a single call to the
1267 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
1268 32767, counting from 0). All other lazy PLT entries branch to it
1269 in a single instruction. */
1271 #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
1272 #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767)
1274 /* Add a dynamic relocation to the SRELOC section. */
1276 inline static bfd_vma
1277 _frvfdpic_add_dyn_reloc (bfd
*output_bfd
, asection
*sreloc
, bfd_vma offset
,
1278 int reloc_type
, long dynindx
, bfd_vma addend
,
1279 struct frvfdpic_relocs_info
*entry
)
1281 Elf_Internal_Rela outrel
;
1282 bfd_vma reloc_offset
;
1284 outrel
.r_offset
= offset
;
1285 outrel
.r_info
= ELF32_R_INFO (dynindx
, reloc_type
);
1286 outrel
.r_addend
= addend
;
1288 reloc_offset
= sreloc
->reloc_count
* sizeof (Elf32_External_Rel
);
1289 BFD_ASSERT (reloc_offset
< sreloc
->size
);
1290 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
1291 sreloc
->contents
+ reloc_offset
);
1292 sreloc
->reloc_count
++;
1294 /* If the entry's index is zero, this relocation was probably to a
1295 linkonce section that got discarded. We reserved a dynamic
1296 relocation, but it was for another entry than the one we got at
1297 the time of emitting the relocation. Unfortunately there's no
1298 simple way for us to catch this situation, since the relocation
1299 is cleared right before calling relocate_section, at which point
1300 we no longer know what the relocation used to point to. */
1303 BFD_ASSERT (entry
->dynrelocs
> 0);
1307 return reloc_offset
;
1310 /* Add a fixup to the ROFIXUP section. */
1313 _frvfdpic_add_rofixup (bfd
*output_bfd
, asection
*rofixup
, bfd_vma offset
,
1314 struct frvfdpic_relocs_info
*entry
)
1316 bfd_vma fixup_offset
;
1318 if (rofixup
->flags
& SEC_EXCLUDE
)
1321 fixup_offset
= rofixup
->reloc_count
* 4;
1322 if (rofixup
->contents
)
1324 BFD_ASSERT (fixup_offset
< rofixup
->size
);
1325 bfd_put_32 (output_bfd
, offset
, rofixup
->contents
+ fixup_offset
);
1327 rofixup
->reloc_count
++;
1329 if (entry
&& entry
->symndx
)
1331 /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc
1333 BFD_ASSERT (entry
->fixups
> 0);
1337 return fixup_offset
;
1340 /* Find the segment number in which OSEC, and output section, is
1344 _frvfdpic_osec_to_segment (bfd
*output_bfd
, asection
*osec
)
1346 Elf_Internal_Phdr
*p
= _bfd_elf_find_segment_containing_section (output_bfd
, osec
);
1348 return (p
!= NULL
) ? p
- elf_tdata (output_bfd
)->phdr
: -1;
1351 inline static bfd_boolean
1352 _frvfdpic_osec_readonly_p (bfd
*output_bfd
, asection
*osec
)
1354 unsigned seg
= _frvfdpic_osec_to_segment (output_bfd
, osec
);
1356 return ! (elf_tdata (output_bfd
)->phdr
[seg
].p_flags
& PF_W
);
1359 #define FRVFDPIC_TLS_BIAS (2048 - 16)
1361 /* Return the base VMA address which should be subtracted from real addresses
1362 when resolving TLSMOFF relocation.
1363 This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */
1366 tls_biased_base (struct bfd_link_info
*info
)
1368 /* If tls_sec is NULL, we should have signalled an error already. */
1369 if (elf_hash_table (info
)->tls_sec
== NULL
)
1370 return FRVFDPIC_TLS_BIAS
;
1371 return elf_hash_table (info
)->tls_sec
->vma
+ FRVFDPIC_TLS_BIAS
;
1374 /* Generate relocations for GOT entries, function descriptors, and
1375 code for PLT and lazy PLT entries. */
1377 inline static bfd_boolean
1378 _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info
*entry
,
1380 struct bfd_link_info
*info
,
1382 Elf_Internal_Sym
*sym
,
1386 bfd_vma fd_lazy_rel_offset
= (bfd_vma
)-1;
1393 if (entry
->got_entry
|| entry
->fdgot_entry
|| entry
->fd_entry
1394 || entry
->tlsoff_entry
|| entry
->tlsdesc_entry
)
1396 /* If the symbol is dynamic, consider it for dynamic
1397 relocations, otherwise decay to section + offset. */
1398 if (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1)
1399 dynindx
= entry
->d
.h
->dynindx
;
1403 && sec
->output_section
1404 && ! bfd_is_abs_section (sec
->output_section
)
1405 && ! bfd_is_und_section (sec
->output_section
))
1406 dynindx
= elf_section_data (sec
->output_section
)->dynindx
;
1412 /* Generate relocation for GOT entry pointing to the symbol. */
1413 if (entry
->got_entry
)
1416 bfd_vma ad
= addend
;
1418 /* If the symbol is dynamic but binds locally, use
1420 if (sec
&& (entry
->symndx
!= -1
1421 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1423 if (entry
->symndx
== -1)
1424 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1426 ad
+= sym
->st_value
;
1427 ad
+= sec
->output_offset
;
1428 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1429 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1434 /* If we're linking an executable at a fixed address, we can
1435 omit the dynamic relocation as long as the symbol is local to
1437 if (info
->executable
&& !info
->pie
1438 && (entry
->symndx
!= -1
1439 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1442 ad
+= sec
->output_section
->vma
;
1443 if (entry
->symndx
!= -1
1444 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1445 _frvfdpic_add_rofixup (output_bfd
,
1446 frvfdpic_gotfixup_section (info
),
1447 frvfdpic_got_section (info
)->output_section
1449 + frvfdpic_got_section (info
)->output_offset
1450 + frvfdpic_got_initial_offset (info
)
1451 + entry
->got_entry
, entry
);
1454 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1455 _bfd_elf_section_offset
1457 frvfdpic_got_section (info
),
1458 frvfdpic_got_initial_offset (info
)
1460 + frvfdpic_got_section (info
)
1461 ->output_section
->vma
1462 + frvfdpic_got_section (info
)->output_offset
,
1463 R_FRV_32
, idx
, ad
, entry
);
1465 bfd_put_32 (output_bfd
, ad
,
1466 frvfdpic_got_section (info
)->contents
1467 + frvfdpic_got_initial_offset (info
)
1468 + entry
->got_entry
);
1471 /* Generate relocation for GOT entry pointing to a canonical
1472 function descriptor. */
1473 if (entry
->fdgot_entry
)
1478 if (! (entry
->symndx
== -1
1479 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
1480 && FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1482 /* If the symbol is dynamic and there may be dynamic symbol
1483 resolution because we are, or are linked with, a shared
1484 library, emit a FUNCDESC relocation such that the dynamic
1485 linker will allocate the function descriptor. If the
1486 symbol needs a non-local function descriptor but binds
1487 locally (e.g., its visibility is protected, emit a
1488 dynamic relocation decayed to section+offset. */
1489 if (entry
->symndx
== -1
1490 && ! FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)
1491 && FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)
1492 && !(info
->executable
&& !info
->pie
))
1494 reloc
= R_FRV_FUNCDESC
;
1495 idx
= elf_section_data (entry
->d
.h
->root
.u
.def
.section
1496 ->output_section
)->dynindx
;
1497 ad
= entry
->d
.h
->root
.u
.def
.section
->output_offset
1498 + entry
->d
.h
->root
.u
.def
.value
;
1500 else if (entry
->symndx
== -1
1501 && ! FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
))
1503 reloc
= R_FRV_FUNCDESC
;
1508 (*info
->callbacks
->reloc_dangerous
)
1509 (info
, _("relocation requires zero addend"),
1510 elf_hash_table (info
)->dynobj
,
1511 frvfdpic_got_section (info
),
1512 entry
->fdgot_entry
);
1518 /* Otherwise, we know we have a private function descriptor,
1519 so reference it directly. */
1520 if (elf_hash_table (info
)->dynamic_sections_created
)
1521 BFD_ASSERT (entry
->privfd
);
1523 idx
= elf_section_data (frvfdpic_got_section (info
)
1524 ->output_section
)->dynindx
;
1525 ad
= frvfdpic_got_section (info
)->output_offset
1526 + frvfdpic_got_initial_offset (info
) + entry
->fd_entry
;
1529 /* If there is room for dynamic symbol resolution, emit the
1530 dynamic relocation. However, if we're linking an
1531 executable at a fixed location, we won't have emitted a
1532 dynamic symbol entry for the got section, so idx will be
1533 zero, which means we can and should compute the address
1534 of the private descriptor ourselves. */
1535 if (info
->executable
&& !info
->pie
1536 && (entry
->symndx
!= -1
1537 || FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)))
1539 ad
+= frvfdpic_got_section (info
)->output_section
->vma
;
1540 _frvfdpic_add_rofixup (output_bfd
,
1541 frvfdpic_gotfixup_section (info
),
1542 frvfdpic_got_section (info
)
1543 ->output_section
->vma
1544 + frvfdpic_got_section (info
)
1546 + frvfdpic_got_initial_offset (info
)
1547 + entry
->fdgot_entry
, entry
);
1550 _frvfdpic_add_dyn_reloc (output_bfd
,
1551 frvfdpic_gotrel_section (info
),
1552 _bfd_elf_section_offset
1554 frvfdpic_got_section (info
),
1555 frvfdpic_got_initial_offset (info
)
1556 + entry
->fdgot_entry
)
1557 + frvfdpic_got_section (info
)
1558 ->output_section
->vma
1559 + frvfdpic_got_section (info
)
1561 reloc
, idx
, ad
, entry
);
1564 bfd_put_32 (output_bfd
, ad
,
1565 frvfdpic_got_section (info
)->contents
1566 + frvfdpic_got_initial_offset (info
)
1567 + entry
->fdgot_entry
);
1570 /* Generate relocation to fill in a private function descriptor in
1572 if (entry
->fd_entry
)
1575 bfd_vma ad
= addend
;
1577 long lowword
, highword
;
1579 /* If the symbol is dynamic but binds locally, use
1581 if (sec
&& (entry
->symndx
!= -1
1582 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1584 if (entry
->symndx
== -1)
1585 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1587 ad
+= sym
->st_value
;
1588 ad
+= sec
->output_offset
;
1589 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1590 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1595 /* If we're linking an executable at a fixed address, we can
1596 omit the dynamic relocation as long as the symbol is local to
1598 if (info
->executable
&& !info
->pie
1599 && (entry
->symndx
!= -1 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1602 ad
+= sec
->output_section
->vma
;
1604 if (entry
->symndx
!= -1
1605 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1607 _frvfdpic_add_rofixup (output_bfd
,
1608 frvfdpic_gotfixup_section (info
),
1609 frvfdpic_got_section (info
)
1610 ->output_section
->vma
1611 + frvfdpic_got_section (info
)
1613 + frvfdpic_got_initial_offset (info
)
1614 + entry
->fd_entry
, entry
);
1615 _frvfdpic_add_rofixup (output_bfd
,
1616 frvfdpic_gotfixup_section (info
),
1617 frvfdpic_got_section (info
)
1618 ->output_section
->vma
1619 + frvfdpic_got_section (info
)
1621 + frvfdpic_got_initial_offset (info
)
1622 + entry
->fd_entry
+ 4, entry
);
1628 _frvfdpic_add_dyn_reloc (output_bfd
,
1630 ? frvfdpic_pltrel_section (info
)
1631 : frvfdpic_gotrel_section (info
),
1632 _bfd_elf_section_offset
1634 frvfdpic_got_section (info
),
1635 frvfdpic_got_initial_offset (info
)
1637 + frvfdpic_got_section (info
)
1638 ->output_section
->vma
1639 + frvfdpic_got_section (info
)
1641 R_FRV_FUNCDESC_VALUE
, idx
, ad
, entry
);
1644 /* If we've omitted the dynamic relocation, just emit the fixed
1645 addresses of the symbol and of the local GOT base offset. */
1646 if (info
->executable
&& !info
->pie
&& sec
&& sec
->output_section
)
1649 highword
= frvfdpic_got_section (info
)->output_section
->vma
1650 + frvfdpic_got_section (info
)->output_offset
1651 + frvfdpic_got_initial_offset (info
);
1653 else if (entry
->lazyplt
)
1657 (*info
->callbacks
->reloc_dangerous
)
1658 (info
, _("relocation requires zero addend"),
1659 elf_hash_table (info
)->dynobj
,
1660 frvfdpic_got_section (info
),
1665 fd_lazy_rel_offset
= ofst
;
1667 /* A function descriptor used for lazy or local resolving is
1668 initialized such that its high word contains the output
1669 section index in which the PLT entries are located, and
1670 the low word contains the address of the lazy PLT entry
1671 entry point, that must be within the memory region
1672 assigned to that section. */
1673 lowword
= entry
->lzplt_entry
+ 4
1674 + frvfdpic_plt_section (info
)->output_offset
1675 + frvfdpic_plt_section (info
)->output_section
->vma
;
1676 highword
= _frvfdpic_osec_to_segment
1677 (output_bfd
, frvfdpic_plt_section (info
)->output_section
);
1681 /* A function descriptor for a local function gets the index
1682 of the section. For a non-local function, it's
1686 || (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1
1687 && entry
->d
.h
->dynindx
== idx
))
1690 highword
= _frvfdpic_osec_to_segment
1691 (output_bfd
, sec
->output_section
);
1694 bfd_put_32 (output_bfd
, lowword
,
1695 frvfdpic_got_section (info
)->contents
1696 + frvfdpic_got_initial_offset (info
)
1698 bfd_put_32 (output_bfd
, highword
,
1699 frvfdpic_got_section (info
)->contents
1700 + frvfdpic_got_initial_offset (info
)
1701 + entry
->fd_entry
+ 4);
1704 /* Generate code for the PLT entry. */
1705 if (entry
->plt_entry
!= (bfd_vma
) -1)
1707 bfd_byte
*plt_code
= frvfdpic_plt_section (info
)->contents
1710 BFD_ASSERT (entry
->fd_entry
);
1712 /* Figure out what kind of PLT entry we need, depending on the
1713 location of the function descriptor within the GOT. */
1714 if (entry
->fd_entry
>= -(1 << (12 - 1))
1715 && entry
->fd_entry
< (1 << (12 - 1)))
1717 /* lddi @(gr15, fd_entry), gr14 */
1718 bfd_put_32 (output_bfd
,
1719 0x9cccf000 | (entry
->fd_entry
& ((1 << 12) - 1)),
1725 if (entry
->fd_entry
>= -(1 << (16 - 1))
1726 && entry
->fd_entry
< (1 << (16 - 1)))
1728 /* setlos lo(fd_entry), gr14 */
1729 bfd_put_32 (output_bfd
,
1731 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1737 /* sethi.p hi(fd_entry), gr14
1738 setlo lo(fd_entry), gr14 */
1739 bfd_put_32 (output_bfd
,
1741 | ((entry
->fd_entry
>> 16)
1742 & (((bfd_vma
)1 << 16) - 1)),
1745 bfd_put_32 (output_bfd
,
1747 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1751 /* ldd @(gr14,gr15),gr14 */
1752 bfd_put_32 (output_bfd
, 0x9c08e14f, plt_code
);
1755 /* jmpl @(gr14,gr0) */
1756 bfd_put_32 (output_bfd
, 0x8030e000, plt_code
);
1759 /* Generate code for the lazy PLT entry. */
1760 if (entry
->lzplt_entry
!= (bfd_vma
) -1)
1762 bfd_byte
*lzplt_code
= frvfdpic_plt_section (info
)->contents
1763 + entry
->lzplt_entry
;
1764 bfd_vma resolverStub_addr
;
1766 bfd_put_32 (output_bfd
, fd_lazy_rel_offset
, lzplt_code
);
1769 resolverStub_addr
= entry
->lzplt_entry
/ FRVFDPIC_LZPLT_BLOCK_SIZE
1770 * FRVFDPIC_LZPLT_BLOCK_SIZE
+ FRVFDPIC_LZPLT_RESOLV_LOC
;
1771 if (resolverStub_addr
>= frvfdpic_plt_initial_offset (info
))
1772 resolverStub_addr
= frvfdpic_plt_initial_offset (info
) - 12;
1774 if (entry
->lzplt_entry
== resolverStub_addr
)
1776 /* This is a lazy PLT entry that includes a resolver call. */
1777 /* ldd @(gr15,gr0), gr4
1779 bfd_put_32 (output_bfd
, 0x8808f140, lzplt_code
);
1780 bfd_put_32 (output_bfd
, 0x80304000, lzplt_code
+ 4);
1784 /* bra resolverStub */
1785 bfd_put_32 (output_bfd
,
1787 | (((resolverStub_addr
- entry
->lzplt_entry
)
1788 / 4) & (((bfd_vma
)1 << 16) - 1)),
1793 /* Generate relocation for GOT entry holding the TLS offset. */
1794 if (entry
->tlsoff_entry
)
1797 bfd_vma ad
= addend
;
1799 if (entry
->symndx
!= -1
1800 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
))
1802 /* If the symbol is dynamic but binds locally, use
1806 if (entry
->symndx
== -1)
1807 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1809 ad
+= sym
->st_value
;
1810 ad
+= sec
->output_offset
;
1811 if (sec
->output_section
1812 && elf_section_data (sec
->output_section
))
1813 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1819 /* *ABS*+addend is special for TLS relocations, use only the
1821 if (info
->executable
1823 && (bfd_is_abs_section (sec
)
1824 || bfd_is_und_section (sec
)))
1826 /* If we're linking an executable, we can entirely omit the
1827 dynamic relocation if the symbol is local to this module. */
1828 else if (info
->executable
1829 && (entry
->symndx
!= -1
1830 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1833 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1838 && (bfd_is_abs_section (sec
)
1839 || bfd_is_und_section (sec
)))
1841 if (! elf_hash_table (info
)->tls_sec
)
1843 (*info
->callbacks
->undefined_symbol
)
1844 (info
, "TLS section", elf_hash_table (info
)->dynobj
,
1845 frvfdpic_got_section (info
), entry
->tlsoff_entry
, TRUE
);
1848 idx
= elf_section_data (elf_hash_table (info
)->tls_sec
)->dynindx
;
1849 ad
+= FRVFDPIC_TLS_BIAS
;
1851 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1852 _bfd_elf_section_offset
1854 frvfdpic_got_section (info
),
1855 frvfdpic_got_initial_offset (info
)
1856 + entry
->tlsoff_entry
)
1857 + frvfdpic_got_section (info
)
1858 ->output_section
->vma
1859 + frvfdpic_got_section (info
)
1861 R_FRV_TLSOFF
, idx
, ad
, entry
);
1864 bfd_put_32 (output_bfd
, ad
,
1865 frvfdpic_got_section (info
)->contents
1866 + frvfdpic_got_initial_offset (info
)
1867 + entry
->tlsoff_entry
);
1870 if (entry
->tlsdesc_entry
)
1873 bfd_vma ad
= addend
;
1875 /* If the symbol is dynamic but binds locally, use
1877 if (sec
&& (entry
->symndx
!= -1
1878 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1880 if (entry
->symndx
== -1)
1881 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1883 ad
+= sym
->st_value
;
1884 ad
+= sec
->output_offset
;
1885 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1886 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1891 /* If we didn't set up a TLS offset entry, but we're linking an
1892 executable and the symbol binds locally, we can use the
1893 module offset in the TLS descriptor in relaxations. */
1894 if (info
->executable
&& ! entry
->tlsoff_entry
)
1895 entry
->tlsoff_entry
= entry
->tlsdesc_entry
+ 4;
1897 if (info
->executable
&& !info
->pie
1899 && (bfd_is_abs_section (sec
)
1900 || bfd_is_und_section (sec
)))
1901 || entry
->symndx
!= -1
1902 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1904 /* *ABS*+addend is special for TLS relocations, use only the
1905 addend for the TLS offset, and take the module id as
1908 && (bfd_is_abs_section (sec
)
1909 || bfd_is_und_section (sec
)))
1911 /* For other TLS symbols that bind locally, add the section
1912 TLS offset to the addend. */
1914 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1916 bfd_put_32 (output_bfd
,
1917 frvfdpic_plt_section (info
)->output_section
->vma
1918 + frvfdpic_plt_section (info
)->output_offset
1919 + frvfdpic_plt_tls_ret_offset (info
),
1920 frvfdpic_got_section (info
)->contents
1921 + frvfdpic_got_initial_offset (info
)
1922 + entry
->tlsdesc_entry
);
1924 _frvfdpic_add_rofixup (output_bfd
,
1925 frvfdpic_gotfixup_section (info
),
1926 frvfdpic_got_section (info
)
1927 ->output_section
->vma
1928 + frvfdpic_got_section (info
)
1930 + frvfdpic_got_initial_offset (info
)
1931 + entry
->tlsdesc_entry
, entry
);
1933 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
);
1935 /* We've used one of the reserved fixups, so discount it so
1936 that we can check at the end that we've used them
1938 frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
--;
1940 /* While at that, make sure the ret instruction makes to the
1941 right location in the PLT. We could do it only when we
1942 got to 0, but since the check at the end will only print
1943 a warning, make sure we have the ret in place in case the
1944 warning is missed. */
1945 bfd_put_32 (output_bfd
, 0xc03a4000,
1946 frvfdpic_plt_section (info
)->contents
1947 + frvfdpic_plt_tls_ret_offset (info
));
1952 && (bfd_is_abs_section (sec
)
1953 || bfd_is_und_section (sec
)))
1955 if (! elf_hash_table (info
)->tls_sec
)
1957 (*info
->callbacks
->undefined_symbol
)
1958 (info
, "TLS section", elf_hash_table (info
)->dynobj
,
1959 frvfdpic_got_section (info
), entry
->tlsdesc_entry
, TRUE
);
1962 idx
= elf_section_data (elf_hash_table (info
)->tls_sec
)->dynindx
;
1963 ad
+= FRVFDPIC_TLS_BIAS
;
1966 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1967 _bfd_elf_section_offset
1969 frvfdpic_got_section (info
),
1970 frvfdpic_got_initial_offset (info
)
1971 + entry
->tlsdesc_entry
)
1972 + frvfdpic_got_section (info
)
1973 ->output_section
->vma
1974 + frvfdpic_got_section (info
)
1976 R_FRV_TLSDESC_VALUE
, idx
, ad
, entry
);
1978 bfd_put_32 (output_bfd
, 0,
1979 frvfdpic_got_section (info
)->contents
1980 + frvfdpic_got_initial_offset (info
)
1981 + entry
->tlsdesc_entry
);
1984 bfd_put_32 (output_bfd
, ad
,
1985 frvfdpic_got_section (info
)->contents
1986 + frvfdpic_got_initial_offset (info
)
1987 + entry
->tlsdesc_entry
+ 4);
1990 /* Generate code for the get-TLS-offset PLT entry. */
1991 if (entry
->tlsplt_entry
!= (bfd_vma
) -1)
1993 bfd_byte
*plt_code
= frvfdpic_plt_section (info
)->contents
1994 + entry
->tlsplt_entry
;
1996 if (info
->executable
1997 && (entry
->symndx
!= -1
1998 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
2001 bfd_vma ad
= addend
;
2003 /* sec may be NULL when referencing an undefweak symbol
2004 while linking a static executable. */
2007 BFD_ASSERT (entry
->symndx
== -1
2008 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
);
2012 if (entry
->symndx
== -1)
2013 ad
+= entry
->d
.h
->root
.u
.def
.value
;
2015 ad
+= sym
->st_value
;
2016 ad
+= sec
->output_offset
;
2017 if (sec
->output_section
2018 && elf_section_data (sec
->output_section
))
2019 idx
= elf_section_data (sec
->output_section
)->dynindx
;
2024 /* *ABS*+addend is special for TLS relocations, use only the
2025 addend for the TLS offset, and take the module id as
2028 && (bfd_is_abs_section (sec
)
2029 || bfd_is_und_section (sec
)))
2031 /* For other TLS symbols that bind locally, add the section
2032 TLS offset to the addend. */
2034 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
2036 if ((bfd_signed_vma
)ad
>= -(1 << (16 - 1))
2037 && (bfd_signed_vma
)ad
< (1 << (16 - 1)))
2039 /* setlos lo(ad), gr9 */
2040 bfd_put_32 (output_bfd
,
2043 & (((bfd_vma
)1 << 16) - 1)),
2049 /* sethi.p hi(ad), gr9
2050 setlo lo(ad), gr9 */
2051 bfd_put_32 (output_bfd
,
2054 & (((bfd_vma
)1 << 16) - 1)),
2057 bfd_put_32 (output_bfd
,
2060 & (((bfd_vma
)1 << 16) - 1)),
2065 bfd_put_32 (output_bfd
, 0xc03a4000, plt_code
);
2067 else if (entry
->tlsoff_entry
)
2069 /* Figure out what kind of PLT entry we need, depending on the
2070 location of the TLS descriptor within the GOT. */
2071 if (entry
->tlsoff_entry
>= -(1 << (12 - 1))
2072 && entry
->tlsoff_entry
< (1 << (12 - 1)))
2074 /* ldi @(gr15, tlsoff_entry), gr9 */
2075 bfd_put_32 (output_bfd
,
2076 0x92c8f000 | (entry
->tlsoff_entry
2083 if (entry
->tlsoff_entry
>= -(1 << (16 - 1))
2084 && entry
->tlsoff_entry
< (1 << (16 - 1)))
2086 /* setlos lo(tlsoff_entry), gr8 */
2087 bfd_put_32 (output_bfd
,
2089 | (entry
->tlsoff_entry
2090 & (((bfd_vma
)1 << 16) - 1)),
2096 /* sethi.p hi(tlsoff_entry), gr8
2097 setlo lo(tlsoff_entry), gr8 */
2098 bfd_put_32 (output_bfd
,
2100 | ((entry
->tlsoff_entry
>> 16)
2101 & (((bfd_vma
)1 << 16) - 1)),
2104 bfd_put_32 (output_bfd
,
2106 | (entry
->tlsoff_entry
2107 & (((bfd_vma
)1 << 16) - 1)),
2111 /* ld @(gr15,gr8),gr9 */
2112 bfd_put_32 (output_bfd
, 0x9008f108, plt_code
);
2116 bfd_put_32 (output_bfd
, 0xc03a4000, plt_code
);
2120 BFD_ASSERT (entry
->tlsdesc_entry
);
2122 /* Figure out what kind of PLT entry we need, depending on the
2123 location of the TLS descriptor within the GOT. */
2124 if (entry
->tlsdesc_entry
>= -(1 << (12 - 1))
2125 && entry
->tlsdesc_entry
< (1 << (12 - 1)))
2127 /* lddi @(gr15, tlsdesc_entry), gr8 */
2128 bfd_put_32 (output_bfd
,
2129 0x90ccf000 | (entry
->tlsdesc_entry
2136 if (entry
->tlsdesc_entry
>= -(1 << (16 - 1))
2137 && entry
->tlsdesc_entry
< (1 << (16 - 1)))
2139 /* setlos lo(tlsdesc_entry), gr8 */
2140 bfd_put_32 (output_bfd
,
2142 | (entry
->tlsdesc_entry
2143 & (((bfd_vma
)1 << 16) - 1)),
2149 /* sethi.p hi(tlsdesc_entry), gr8
2150 setlo lo(tlsdesc_entry), gr8 */
2151 bfd_put_32 (output_bfd
,
2153 | ((entry
->tlsdesc_entry
>> 16)
2154 & (((bfd_vma
)1 << 16) - 1)),
2157 bfd_put_32 (output_bfd
,
2159 | (entry
->tlsdesc_entry
2160 & (((bfd_vma
)1 << 16) - 1)),
2164 /* ldd @(gr15,gr8),gr8 */
2165 bfd_put_32 (output_bfd
, 0x9008f148, plt_code
);
2168 /* jmpl @(gr8,gr0) */
2169 bfd_put_32 (output_bfd
, 0x80308000, plt_code
);
2176 /* Handle an FRV small data reloc. */
2178 static bfd_reloc_status_type
2179 elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, relocation
,
2181 struct bfd_link_info
*info
;
2183 asection
*input_section
;
2184 Elf_Internal_Rela
*relocation
;
2190 struct bfd_link_hash_entry
*h
;
2192 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2194 gp
= (h
->u
.def
.value
2195 + h
->u
.def
.section
->output_section
->vma
2196 + h
->u
.def
.section
->output_offset
);
2198 value
-= input_section
->output_section
->vma
;
2199 value
-= (gp
- input_section
->output_section
->vma
);
2201 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2203 value
+= relocation
->r_addend
;
2205 if ((long) value
> 0x7ff || (long) value
< -0x800)
2206 return bfd_reloc_overflow
;
2208 bfd_put_32 (input_bfd
,
2209 (insn
& 0xfffff000) | (value
& 0xfff),
2210 contents
+ relocation
->r_offset
);
2212 return bfd_reloc_ok
;
2215 /* Handle an FRV small data reloc. for the u12 field. */
2217 static bfd_reloc_status_type
2218 elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, relocation
,
2220 struct bfd_link_info
*info
;
2222 asection
*input_section
;
2223 Elf_Internal_Rela
*relocation
;
2229 struct bfd_link_hash_entry
*h
;
2232 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2234 gp
= (h
->u
.def
.value
2235 + h
->u
.def
.section
->output_section
->vma
2236 + h
->u
.def
.section
->output_offset
);
2238 value
-= input_section
->output_section
->vma
;
2239 value
-= (gp
- input_section
->output_section
->vma
);
2241 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2243 value
+= relocation
->r_addend
;
2245 if ((long) value
> 0x7ff || (long) value
< -0x800)
2246 return bfd_reloc_overflow
;
2248 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
2250 insn
= (insn
& ~mask
) | ((value
& 0xfc0) << 12) | (value
& 0x3f);
2252 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2254 return bfd_reloc_ok
;
2257 /* Handle an FRV ELF HI16 reloc. */
2259 static bfd_reloc_status_type
2260 elf32_frv_relocate_hi16 (input_bfd
, relhi
, contents
, value
)
2262 Elf_Internal_Rela
*relhi
;
2268 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
2270 value
+= relhi
->r_addend
;
2271 value
= ((value
>> 16) & 0xffff);
2273 insn
= (insn
& 0xffff0000) | value
;
2275 if ((long) value
> 0xffff || (long) value
< -0x10000)
2276 return bfd_reloc_overflow
;
2278 bfd_put_32 (input_bfd
, insn
, contents
+ relhi
->r_offset
);
2279 return bfd_reloc_ok
;
2282 static bfd_reloc_status_type
2283 elf32_frv_relocate_lo16 (input_bfd
, rello
, contents
, value
)
2285 Elf_Internal_Rela
*rello
;
2291 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2293 value
+= rello
->r_addend
;
2294 value
= value
& 0xffff;
2296 insn
= (insn
& 0xffff0000) | value
;
2298 if ((long) value
> 0xffff || (long) value
< -0x10000)
2299 return bfd_reloc_overflow
;
2301 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
2302 return bfd_reloc_ok
;
2305 /* Perform the relocation for the CALL label24 instruction. */
2307 static bfd_reloc_status_type
2308 elf32_frv_relocate_label24 (input_bfd
, input_section
, rello
, contents
, value
)
2310 asection
*input_section
;
2311 Elf_Internal_Rela
*rello
;
2319 /* The format for the call instruction is:
2321 0 000000 0001111 000000000000000000
2322 label6 opcode label18
2324 The branch calculation is: pc + (4*label24)
2325 where label24 is the concatenation of label6 and label18. */
2327 /* Grab the instruction. */
2328 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2330 value
-= input_section
->output_section
->vma
+ input_section
->output_offset
;
2331 value
-= rello
->r_offset
;
2332 value
+= rello
->r_addend
;
2336 label6
= value
& 0xfc0000;
2337 label6
= label6
<< 7;
2339 label18
= value
& 0x3ffff;
2341 insn
= insn
& 0x803c0000;
2342 insn
= insn
| label6
;
2343 insn
= insn
| label18
;
2345 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
2347 return bfd_reloc_ok
;
2350 static bfd_reloc_status_type
2351 elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, relocation
,
2353 struct bfd_link_info
*info
;
2355 asection
*input_section
;
2356 Elf_Internal_Rela
*relocation
;
2362 struct bfd_link_hash_entry
*h
;
2364 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2366 gp
= (h
->u
.def
.value
2367 + h
->u
.def
.section
->output_section
->vma
2368 + h
->u
.def
.section
->output_offset
);
2370 value
-= input_section
->output_section
->vma
;
2371 value
-= (gp
- input_section
->output_section
->vma
);
2372 value
+= relocation
->r_addend
;
2373 value
= ((value
>> 16) & 0xffff);
2375 if ((long) value
> 0xffff || (long) value
< -0x10000)
2376 return bfd_reloc_overflow
;
2378 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2379 insn
= (insn
& 0xffff0000) | value
;
2381 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2382 return bfd_reloc_ok
;
2385 static bfd_reloc_status_type
2386 elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, relocation
,
2388 struct bfd_link_info
*info
;
2390 asection
*input_section
;
2391 Elf_Internal_Rela
*relocation
;
2397 struct bfd_link_hash_entry
*h
;
2399 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2401 gp
= (h
->u
.def
.value
2402 + h
->u
.def
.section
->output_section
->vma
2403 + h
->u
.def
.section
->output_offset
);
2405 value
-= input_section
->output_section
->vma
;
2406 value
-= (gp
- input_section
->output_section
->vma
);
2407 value
+= relocation
->r_addend
;
2408 value
= value
& 0xffff;
2410 if ((long) value
> 0xffff || (long) value
< -0x10000)
2411 return bfd_reloc_overflow
;
2413 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2414 insn
= (insn
& 0xffff0000) | value
;
2416 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2418 return bfd_reloc_ok
;
2421 static reloc_howto_type
*
2422 frv_reloc_type_lookup (abfd
, code
)
2423 bfd
*abfd ATTRIBUTE_UNUSED
;
2424 bfd_reloc_code_real_type code
;
2431 case BFD_RELOC_NONE
:
2432 return &elf32_frv_howto_table
[ (int) R_FRV_NONE
];
2435 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2436 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2437 return &elf32_frv_rel_32_howto
;
2439 case BFD_RELOC_CTOR
:
2440 return &elf32_frv_howto_table
[ (int) R_FRV_32
];
2442 case BFD_RELOC_FRV_LABEL16
:
2443 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL16
];
2445 case BFD_RELOC_FRV_LABEL24
:
2446 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL24
];
2448 case BFD_RELOC_FRV_LO16
:
2449 return &elf32_frv_howto_table
[ (int) R_FRV_LO16
];
2451 case BFD_RELOC_FRV_HI16
:
2452 return &elf32_frv_howto_table
[ (int) R_FRV_HI16
];
2454 case BFD_RELOC_FRV_GPREL12
:
2455 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL12
];
2457 case BFD_RELOC_FRV_GPRELU12
:
2458 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELU12
];
2460 case BFD_RELOC_FRV_GPREL32
:
2461 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL32
];
2463 case BFD_RELOC_FRV_GPRELHI
:
2464 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELHI
];
2466 case BFD_RELOC_FRV_GPRELLO
:
2467 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELLO
];
2469 case BFD_RELOC_FRV_GOT12
:
2470 return &elf32_frv_howto_table
[ (int) R_FRV_GOT12
];
2472 case BFD_RELOC_FRV_GOTHI
:
2473 return &elf32_frv_howto_table
[ (int) R_FRV_GOTHI
];
2475 case BFD_RELOC_FRV_GOTLO
:
2476 return &elf32_frv_howto_table
[ (int) R_FRV_GOTLO
];
2478 case BFD_RELOC_FRV_FUNCDESC
:
2479 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2480 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2481 return &elf32_frv_rel_funcdesc_howto
;
2482 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC
];
2484 case BFD_RELOC_FRV_FUNCDESC_GOT12
:
2485 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOT12
];
2487 case BFD_RELOC_FRV_FUNCDESC_GOTHI
:
2488 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTHI
];
2490 case BFD_RELOC_FRV_FUNCDESC_GOTLO
:
2491 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTLO
];
2493 case BFD_RELOC_FRV_FUNCDESC_VALUE
:
2494 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2495 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2496 return &elf32_frv_rel_funcdesc_value_howto
;
2497 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_VALUE
];
2499 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12
:
2500 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFF12
];
2502 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI
:
2503 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFHI
];
2505 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO
:
2506 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFLO
];
2508 case BFD_RELOC_FRV_GOTOFF12
:
2509 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFF12
];
2511 case BFD_RELOC_FRV_GOTOFFHI
:
2512 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFHI
];
2514 case BFD_RELOC_FRV_GOTOFFLO
:
2515 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFLO
];
2517 case BFD_RELOC_FRV_GETTLSOFF
:
2518 return &elf32_frv_howto_table
[ (int) R_FRV_GETTLSOFF
];
2520 case BFD_RELOC_FRV_TLSDESC_VALUE
:
2521 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2522 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2523 return &elf32_frv_rel_tlsdesc_value_howto
;
2524 return &elf32_frv_howto_table
[ (int) R_FRV_TLSDESC_VALUE
];
2526 case BFD_RELOC_FRV_GOTTLSDESC12
:
2527 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESC12
];
2529 case BFD_RELOC_FRV_GOTTLSDESCHI
:
2530 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESCHI
];
2532 case BFD_RELOC_FRV_GOTTLSDESCLO
:
2533 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESCLO
];
2535 case BFD_RELOC_FRV_TLSMOFF12
:
2536 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFF12
];
2538 case BFD_RELOC_FRV_TLSMOFFHI
:
2539 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFFHI
];
2541 case BFD_RELOC_FRV_TLSMOFFLO
:
2542 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFFLO
];
2544 case BFD_RELOC_FRV_GOTTLSOFF12
:
2545 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFF12
];
2547 case BFD_RELOC_FRV_GOTTLSOFFHI
:
2548 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFFHI
];
2550 case BFD_RELOC_FRV_GOTTLSOFFLO
:
2551 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFFLO
];
2553 case BFD_RELOC_FRV_TLSOFF
:
2554 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2555 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2556 return &elf32_frv_rel_tlsoff_howto
;
2557 return &elf32_frv_howto_table
[ (int) R_FRV_TLSOFF
];
2559 case BFD_RELOC_FRV_TLSDESC_RELAX
:
2560 return &elf32_frv_howto_table
[ (int) R_FRV_TLSDESC_RELAX
];
2562 case BFD_RELOC_FRV_GETTLSOFF_RELAX
:
2563 return &elf32_frv_howto_table
[ (int) R_FRV_GETTLSOFF_RELAX
];
2565 case BFD_RELOC_FRV_TLSOFF_RELAX
:
2566 return &elf32_frv_howto_table
[ (int) R_FRV_TLSOFF_RELAX
];
2568 case BFD_RELOC_FRV_TLSMOFF
:
2569 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFF
];
2571 case BFD_RELOC_VTABLE_INHERIT
:
2572 return &elf32_frv_vtinherit_howto
;
2574 case BFD_RELOC_VTABLE_ENTRY
:
2575 return &elf32_frv_vtentry_howto
;
2581 static reloc_howto_type
*
2582 frv_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
, const char *r_name
)
2587 i
< sizeof (elf32_frv_howto_table
) / sizeof (elf32_frv_howto_table
[0]);
2589 if (elf32_frv_howto_table
[i
].name
!= NULL
2590 && strcasecmp (elf32_frv_howto_table
[i
].name
, r_name
) == 0)
2591 return &elf32_frv_howto_table
[i
];
2593 if (strcasecmp (elf32_frv_vtinherit_howto
.name
, r_name
) == 0)
2594 return &elf32_frv_vtinherit_howto
;
2595 if (strcasecmp (elf32_frv_vtentry_howto
.name
, r_name
) == 0)
2596 return &elf32_frv_vtentry_howto
;
2601 /* Set the howto pointer for an FRV ELF reloc. */
2604 frv_info_to_howto_rela (abfd
, cache_ptr
, dst
)
2605 bfd
*abfd ATTRIBUTE_UNUSED
;
2607 Elf_Internal_Rela
*dst
;
2609 unsigned int r_type
;
2611 r_type
= ELF32_R_TYPE (dst
->r_info
);
2614 case R_FRV_GNU_VTINHERIT
:
2615 cache_ptr
->howto
= &elf32_frv_vtinherit_howto
;
2618 case R_FRV_GNU_VTENTRY
:
2619 cache_ptr
->howto
= &elf32_frv_vtentry_howto
;
2623 cache_ptr
->howto
= & elf32_frv_howto_table
[r_type
];
2628 /* Set the howto pointer for an FRV ELF REL reloc. */
2630 frvfdpic_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
2631 arelent
*cache_ptr
, Elf_Internal_Rela
*dst
)
2633 unsigned int r_type
;
2635 r_type
= ELF32_R_TYPE (dst
->r_info
);
2639 cache_ptr
->howto
= &elf32_frv_rel_32_howto
;
2642 case R_FRV_FUNCDESC
:
2643 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_howto
;
2646 case R_FRV_FUNCDESC_VALUE
:
2647 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_value_howto
;
2650 case R_FRV_TLSDESC_VALUE
:
2651 cache_ptr
->howto
= &elf32_frv_rel_tlsdesc_value_howto
;
2655 cache_ptr
->howto
= &elf32_frv_rel_tlsoff_howto
;
2659 cache_ptr
->howto
= NULL
;
2664 /* Perform a single relocation. By default we use the standard BFD
2665 routines, but a few relocs, we have to do them ourselves. */
2667 static bfd_reloc_status_type
2668 frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
, rel
,
2670 reloc_howto_type
*howto
;
2672 asection
*input_section
;
2674 Elf_Internal_Rela
*rel
;
2677 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2678 contents
, rel
->r_offset
, relocation
,
2683 /* Relocate an FRV ELF section.
2685 The RELOCATE_SECTION function is called by the new ELF backend linker
2686 to handle the relocations for a section.
2688 The relocs are always passed as Rela structures; if the section
2689 actually uses Rel structures, the r_addend field will always be
2692 This function is responsible for adjusting the section contents as
2693 necessary, and (if using Rela relocs and generating a relocatable
2694 output file) adjusting the reloc addend as necessary.
2696 This function does not have to worry about setting the reloc
2697 address or the reloc symbol index.
2699 LOCAL_SYMS is a pointer to the swapped in local symbols.
2701 LOCAL_SECTIONS is an array giving the section in the input file
2702 corresponding to the st_shndx field of each local symbol.
2704 The global hash table entry for the global symbols can be found
2705 via elf_sym_hashes (input_bfd).
2707 When generating relocatable output, this function must handle
2708 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2709 going to be the section symbol corresponding to the output
2710 section, which means that the addend must be adjusted
2714 elf32_frv_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2715 contents
, relocs
, local_syms
, local_sections
)
2716 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2717 struct bfd_link_info
*info
;
2719 asection
*input_section
;
2721 Elf_Internal_Rela
*relocs
;
2722 Elf_Internal_Sym
*local_syms
;
2723 asection
**local_sections
;
2725 Elf_Internal_Shdr
*symtab_hdr
;
2726 struct elf_link_hash_entry
**sym_hashes
;
2727 Elf_Internal_Rela
*rel
;
2728 Elf_Internal_Rela
*relend
;
2729 unsigned isec_segment
, got_segment
, plt_segment
, gprel_segment
, tls_segment
,
2731 int silence_segment_error
= !(info
->shared
|| info
->pie
);
2734 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
2735 sym_hashes
= elf_sym_hashes (input_bfd
);
2736 relend
= relocs
+ input_section
->reloc_count
;
2738 isec_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2739 input_section
->output_section
);
2740 if (IS_FDPIC (output_bfd
) && frvfdpic_got_section (info
))
2741 got_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2742 frvfdpic_got_section (info
)
2746 if (IS_FDPIC (output_bfd
) && frvfdpic_gotfixup_section (info
))
2747 gprel_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2748 frvfdpic_gotfixup_section (info
)
2752 if (IS_FDPIC (output_bfd
) && frvfdpic_plt_section (info
))
2753 plt_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2754 frvfdpic_plt_section (info
)
2758 if (elf_hash_table (info
)->tls_sec
)
2759 tls_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2760 elf_hash_table (info
)->tls_sec
);
2764 for (rel
= relocs
; rel
< relend
; rel
++)
2766 reloc_howto_type
*howto
;
2767 unsigned long r_symndx
;
2768 Elf_Internal_Sym
*sym
;
2770 struct elf_link_hash_entry
*h
;
2772 bfd_reloc_status_type r
;
2776 struct frvfdpic_relocs_info
*picrel
;
2777 bfd_vma orig_addend
= rel
->r_addend
;
2779 r_type
= ELF32_R_TYPE (rel
->r_info
);
2781 if ( r_type
== R_FRV_GNU_VTINHERIT
2782 || r_type
== R_FRV_GNU_VTENTRY
)
2785 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2786 howto
= elf32_frv_howto_table
+ ELF32_R_TYPE (rel
->r_info
);
2791 if (r_symndx
< symtab_hdr
->sh_info
)
2793 sym
= local_syms
+ r_symndx
;
2794 osec
= sec
= local_sections
[r_symndx
];
2795 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2797 name
= bfd_elf_string_from_elf_section
2798 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
2799 if (name
== NULL
|| name
[0] == 0)
2800 name
= bfd_section_name (input_bfd
, sec
);
2805 bfd_boolean unresolved_reloc
;
2807 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2808 r_symndx
, symtab_hdr
, sym_hashes
,
2810 unresolved_reloc
, warned
);
2812 name
= h
->root
.root
.string
;
2815 if (sec
!= NULL
&& elf_discarded_section (sec
))
2816 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
2817 rel
, relend
, howto
, contents
);
2819 if (info
->relocatable
)
2822 if (r_type
!= R_FRV_TLSMOFF
2824 && (h
->root
.type
== bfd_link_hash_defined
2825 || h
->root
.type
== bfd_link_hash_defweak
)
2826 && !FRVFDPIC_SYM_LOCAL (info
, h
))
2836 if (! IS_FDPIC (output_bfd
))
2842 case R_FRV_FUNCDESC_GOT12
:
2843 case R_FRV_FUNCDESC_GOTHI
:
2844 case R_FRV_FUNCDESC_GOTLO
:
2845 case R_FRV_GOTOFF12
:
2846 case R_FRV_GOTOFFHI
:
2847 case R_FRV_GOTOFFLO
:
2848 case R_FRV_FUNCDESC_GOTOFF12
:
2849 case R_FRV_FUNCDESC_GOTOFFHI
:
2850 case R_FRV_FUNCDESC_GOTOFFLO
:
2851 case R_FRV_FUNCDESC
:
2852 case R_FRV_FUNCDESC_VALUE
:
2853 case R_FRV_GETTLSOFF
:
2854 case R_FRV_TLSDESC_VALUE
:
2855 case R_FRV_GOTTLSDESC12
:
2856 case R_FRV_GOTTLSDESCHI
:
2857 case R_FRV_GOTTLSDESCLO
:
2858 case R_FRV_TLSMOFF12
:
2859 case R_FRV_TLSMOFFHI
:
2860 case R_FRV_TLSMOFFLO
:
2861 case R_FRV_GOTTLSOFF12
:
2862 case R_FRV_GOTTLSOFFHI
:
2863 case R_FRV_GOTTLSOFFLO
:
2865 case R_FRV_TLSDESC_RELAX
:
2866 case R_FRV_GETTLSOFF_RELAX
:
2867 case R_FRV_TLSOFF_RELAX
:
2870 picrel
= frvfdpic_relocs_info_for_global (frvfdpic_relocs_info
2871 (info
), input_bfd
, h
,
2872 orig_addend
, INSERT
);
2874 /* In order to find the entry we created before, we must
2875 use the original addend, not the one that may have been
2876 modified by _bfd_elf_rela_local_sym(). */
2877 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
2878 (info
), input_bfd
, r_symndx
,
2879 orig_addend
, INSERT
);
2883 if (!_frvfdpic_emit_got_relocs_plt_entries (picrel
, output_bfd
, info
,
2887 info
->callbacks
->einfo
2888 (_("%H: relocation to `%s+%v'"
2889 " may have caused the error above\n"),
2890 input_bfd
, input_section
, rel
->r_offset
, name
, rel
->r_addend
);
2900 && ! FRVFDPIC_SYM_LOCAL (info
, h
)
2901 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2902 rel
->r_offset
) != (bfd_vma
) -1)
2904 info
->callbacks
->einfo
2905 (_("%H: relocation references symbol"
2906 " not defined in the module\n"),
2907 input_bfd
, input_section
, rel
->r_offset
);
2915 case R_FRV_GETTLSOFF
:
2916 case R_FRV_TLSDESC_VALUE
:
2917 case R_FRV_GOTTLSDESC12
:
2918 case R_FRV_GOTTLSDESCHI
:
2919 case R_FRV_GOTTLSDESCLO
:
2920 case R_FRV_TLSMOFF12
:
2921 case R_FRV_TLSMOFFHI
:
2922 case R_FRV_TLSMOFFLO
:
2923 case R_FRV_GOTTLSOFF12
:
2924 case R_FRV_GOTTLSOFFHI
:
2925 case R_FRV_GOTTLSOFFLO
:
2927 case R_FRV_TLSDESC_RELAX
:
2928 case R_FRV_GETTLSOFF_RELAX
:
2929 case R_FRV_TLSOFF_RELAX
:
2931 if (sec
&& (bfd_is_abs_section (sec
) || bfd_is_und_section (sec
)))
2932 relocation
+= tls_biased_base (info
);
2939 /* Try to apply TLS relaxations. */
2944 #define LOCAL_EXEC_P(info, picrel) \
2945 ((info)->executable \
2946 && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h)))
2947 #define INITIAL_EXEC_P(info, picrel) \
2948 (((info)->executable || (info)->flags & DF_STATIC_TLS) \
2949 && (picrel)->tlsoff_entry)
2951 #define IN_RANGE_FOR_OFST12_P(value) \
2952 ((bfd_vma)((value) + 2048) < (bfd_vma)4096)
2953 #define IN_RANGE_FOR_SETLOS_P(value) \
2954 ((bfd_vma)((value) + 32768) < (bfd_vma)65536)
2955 #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \
2956 (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info)))
2958 #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2959 (LOCAL_EXEC_P ((info), (picrel)) \
2960 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2961 #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \
2962 (INITIAL_EXEC_P ((info), (picrel)) \
2963 && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry))
2965 #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \
2966 (LOCAL_EXEC_P ((info), (picrel)))
2967 #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \
2968 (INITIAL_EXEC_P ((info), (picrel)))
2970 #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2971 (LOCAL_EXEC_P ((info), (picrel)) \
2972 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2974 case R_FRV_GETTLSOFF
:
2975 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2977 /* Is this a call instruction? */
2978 if ((insn
& (unsigned long)0x01fc0000) != 0x003c0000)
2980 info
->callbacks
->einfo
2981 (_("%H: R_FRV_GETTLSOFF not applied to a call instruction\n"),
2982 input_bfd
, input_section
, rel
->r_offset
);
2986 if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info
, picrel
,
2987 relocation
+ rel
->r_addend
))
2989 /* Replace the call instruction (except the packing bit)
2990 with setlos #tlsmofflo(symbol+offset), gr9. */
2991 insn
&= (unsigned long)0x80000000;
2992 insn
|= (unsigned long)0x12fc0000;
2993 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
2995 r_type
= R_FRV_TLSMOFFLO
;
2996 howto
= elf32_frv_howto_table
+ r_type
;
2997 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3000 else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info
, picrel
))
3002 /* Replace the call instruction (except the packing bit)
3003 with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */
3004 insn
&= (unsigned long)0x80000000;
3005 insn
|= (unsigned long)0x12c8f000;
3006 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3008 r_type
= R_FRV_GOTTLSOFF12
;
3009 howto
= elf32_frv_howto_table
+ r_type
;
3010 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3015 case R_FRV_GOTTLSDESC12
:
3016 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3018 /* Is this an lddi instruction? */
3019 if ((insn
& (unsigned long)0x01fc0000) != 0x00cc0000)
3021 info
->callbacks
->einfo
3022 (_("%H: R_FRV_GOTTLSDESC12"
3023 " not applied to an lddi instruction\n"),
3024 input_bfd
, input_section
, rel
->r_offset
);
3028 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3029 relocation
+ rel
->r_addend
)
3030 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3033 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3034 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3035 Preserve the packing bit. */
3036 insn
= (insn
& (unsigned long)0x80000000)
3037 | ((insn
+ (unsigned long)0x02000000)
3038 & (unsigned long)0x7e000000);
3039 insn
|= (unsigned long)0x00fc0000;
3040 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3042 r_type
= R_FRV_TLSMOFFLO
;
3043 howto
= elf32_frv_howto_table
+ r_type
;
3044 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3047 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3048 relocation
+ rel
->r_addend
))
3050 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3051 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3052 Preserve the packing bit. */
3053 insn
= (insn
& (unsigned long)0x80000000)
3054 | ((insn
+ (unsigned long)0x02000000)
3055 & (unsigned long)0x7e000000);
3056 insn
|= (unsigned long)0x00f80000;
3057 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3059 r_type
= R_FRV_TLSMOFFHI
;
3060 howto
= elf32_frv_howto_table
+ r_type
;
3061 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3064 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3066 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3067 with ldi @(grB, #gottlsoff12(symbol+offset),
3068 gr<C+1>. Preserve the packing bit. If gottlsoff12
3069 overflows, we'll error out, but that's sort-of ok,
3070 since we'd started with gottlsdesc12, that's actually
3071 more demanding. Compiling with -fPIE instead of
3072 -fpie would fix it; linking with --relax should fix
3074 insn
= (insn
& (unsigned long)0x80cbf000)
3075 | ((insn
+ (unsigned long)0x02000000)
3076 & (unsigned long)0x7e000000);
3077 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3079 r_type
= R_FRV_GOTTLSOFF12
;
3080 howto
= elf32_frv_howto_table
+ r_type
;
3081 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3086 case R_FRV_GOTTLSDESCHI
:
3087 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3089 /* Is this a sethi instruction? */
3090 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3092 info
->callbacks
->einfo
3093 (_("%H: R_FRV_GOTTLSDESCHI"
3094 " not applied to a sethi instruction\n"),
3095 input_bfd
, input_section
, rel
->r_offset
);
3099 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3100 relocation
+ rel
->r_addend
)
3101 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3102 && IN_RANGE_FOR_SETLOS_P (picrel
->tlsoff_entry
)))
3104 /* Replace sethi with a nop. Preserve the packing bit. */
3105 insn
&= (unsigned long)0x80000000;
3106 insn
|= (unsigned long)0x00880000;
3107 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3109 /* Nothing to relocate. */
3113 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3115 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3116 r_type
= R_FRV_GOTTLSOFFHI
;
3117 howto
= elf32_frv_howto_table
+ r_type
;
3118 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3123 case R_FRV_GOTTLSDESCLO
:
3124 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3126 /* Is this a setlo or setlos instruction? */
3127 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3129 info
->callbacks
->einfo
3130 (_("%H: R_FRV_GOTTLSDESCLO"
3131 " not applied to a setlo or setlos instruction\n"),
3132 input_bfd
, input_section
, rel
->r_offset
);
3136 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3137 relocation
+ rel
->r_addend
)
3138 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3139 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3141 /* Replace setlo/setlos with a nop. Preserve the
3143 insn
&= (unsigned long)0x80000000;
3144 insn
|= (unsigned long)0x00880000;
3145 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3147 /* Nothing to relocate. */
3151 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3153 /* If the corresponding sethi (if it exists) decayed
3154 to a nop, make sure this becomes (or already is) a
3155 setlos, not setlo. */
3156 if (IN_RANGE_FOR_SETLOS_P (picrel
->tlsoff_entry
))
3158 insn
|= (unsigned long)0x00080000;
3159 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3162 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3163 r_type
= R_FRV_GOTTLSOFFLO
;
3164 howto
= elf32_frv_howto_table
+ r_type
;
3165 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3170 case R_FRV_TLSDESC_RELAX
:
3171 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3173 /* Is this an ldd instruction? */
3174 if ((insn
& (unsigned long)0x01fc0fc0) != 0x00080140)
3176 info
->callbacks
->einfo
3177 (_("%H: R_FRV_TLSDESC_RELAX"
3178 " not applied to an ldd instruction\n"),
3179 input_bfd
, input_section
, rel
->r_offset
);
3183 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3184 relocation
+ rel
->r_addend
)
3185 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3188 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3189 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3190 Preserve the packing bit. */
3191 insn
= (insn
& (unsigned long)0x80000000)
3192 | ((insn
+ (unsigned long)0x02000000)
3193 & (unsigned long)0x7e000000);
3194 insn
|= (unsigned long)0x00fc0000;
3195 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3197 r_type
= R_FRV_TLSMOFFLO
;
3198 howto
= elf32_frv_howto_table
+ r_type
;
3199 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3202 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3203 relocation
+ rel
->r_addend
))
3205 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3206 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3207 Preserve the packing bit. */
3208 insn
= (insn
& (unsigned long)0x80000000)
3209 | ((insn
+ (unsigned long)0x02000000)
3210 & (unsigned long)0x7e000000);
3211 insn
|= (unsigned long)0x00f80000;
3212 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3214 r_type
= R_FRV_TLSMOFFHI
;
3215 howto
= elf32_frv_howto_table
+ r_type
;
3216 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3219 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3220 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
))
3222 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3223 with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>.
3224 Preserve the packing bit. */
3225 insn
= (insn
& (unsigned long)0x8003f000)
3226 | (unsigned long)0x00c80000
3227 | ((insn
+ (unsigned long)0x02000000)
3228 & (unsigned long)0x7e000000);
3229 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3231 r_type
= R_FRV_GOTTLSOFF12
;
3232 howto
= elf32_frv_howto_table
+ r_type
;
3233 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3236 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3238 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3239 with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>.
3240 Preserve the packing bit. */
3241 insn
= (insn
& (unsigned long)0x81ffffbf)
3242 | ((insn
+ (unsigned long)0x02000000)
3243 & (unsigned long)0x7e000000);
3244 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3246 /* #tlsoff(symbol+offset) is just a relaxation
3247 annotation, so there's nothing left to
3254 case R_FRV_GETTLSOFF_RELAX
:
3255 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3257 /* Is this a calll or callil instruction? */
3258 if ((insn
& (unsigned long)0x7ff80fc0) != 0x02300000)
3260 info
->callbacks
->einfo
3261 (_("%H: R_FRV_GETTLSOFF_RELAX"
3262 " not applied to a calll instruction\n"),
3263 input_bfd
, input_section
, rel
->r_offset
);
3267 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3268 relocation
+ rel
->r_addend
)
3269 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3272 /* Replace calll with a nop. Preserve the packing bit. */
3273 insn
&= (unsigned long)0x80000000;
3274 insn
|= (unsigned long)0x00880000;
3275 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3277 /* Nothing to relocate. */
3281 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3282 relocation
+ rel
->r_addend
))
3284 /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9.
3285 Preserve the packing bit. */
3286 insn
&= (unsigned long)0x80000000;
3287 insn
|= (unsigned long)0x12f40000;
3288 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3290 r_type
= R_FRV_TLSMOFFLO
;
3291 howto
= elf32_frv_howto_table
+ r_type
;
3292 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3295 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3297 /* Replace calll with a nop. Preserve the packing bit. */
3298 insn
&= (unsigned long)0x80000000;
3299 insn
|= (unsigned long)0x00880000;
3300 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3302 /* Nothing to relocate. */
3308 case R_FRV_GOTTLSOFF12
:
3309 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3311 /* Is this an ldi instruction? */
3312 if ((insn
& (unsigned long)0x01fc0000) != 0x00c80000)
3314 info
->callbacks
->einfo
3315 (_("%H: R_FRV_GOTTLSOFF12"
3316 " not applied to an ldi instruction\n"),
3317 input_bfd
, input_section
, rel
->r_offset
);
3321 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3322 relocation
+ rel
->r_addend
))
3324 /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC
3325 with setlos #tlsmofflo(symbol+offset), grC.
3326 Preserve the packing bit. */
3327 insn
&= (unsigned long)0xfe000000;
3328 insn
|= (unsigned long)0x00fc0000;
3329 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3331 r_type
= R_FRV_TLSMOFFLO
;
3332 howto
= elf32_frv_howto_table
+ r_type
;
3333 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3338 case R_FRV_GOTTLSOFFHI
:
3339 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3341 /* Is this a sethi instruction? */
3342 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3344 info
->callbacks
->einfo
3345 (_("%H: R_FRV_GOTTLSOFFHI"
3346 " not applied to a sethi instruction\n"),
3347 input_bfd
, input_section
, rel
->r_offset
);
3351 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3352 relocation
+ rel
->r_addend
)
3353 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3354 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3356 /* Replace sethi with a nop. Preserve the packing bit. */
3357 insn
&= (unsigned long)0x80000000;
3358 insn
|= (unsigned long)0x00880000;
3359 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3361 /* Nothing to relocate. */
3367 case R_FRV_GOTTLSOFFLO
:
3368 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3370 /* Is this a setlo or setlos instruction? */
3371 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3373 info
->callbacks
->einfo
3374 (_("%H: R_FRV_GOTTLSOFFLO"
3375 " not applied to a setlo or setlos instruction\n"),
3376 input_bfd
, input_section
, rel
->r_offset
);
3380 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3381 relocation
+ rel
->r_addend
)
3382 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3383 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3385 /* Replace setlo/setlos with a nop. Preserve the
3387 insn
&= (unsigned long)0x80000000;
3388 insn
|= (unsigned long)0x00880000;
3389 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3391 /* Nothing to relocate. */
3397 case R_FRV_TLSOFF_RELAX
:
3398 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3400 /* Is this an ld instruction? */
3401 if ((insn
& (unsigned long)0x01fc0fc0) != 0x00080100)
3403 info
->callbacks
->einfo
3404 (_("%H: R_FRV_TLSOFF_RELAX"
3405 " not applied to an ld instruction\n"),
3406 input_bfd
, input_section
, rel
->r_offset
);
3410 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3411 relocation
+ rel
->r_addend
))
3413 /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC
3414 with setlos #tlsmofflo(symbol+offset), grC.
3415 Preserve the packing bit. */
3416 insn
&= (unsigned long)0xfe000000;
3417 insn
|= (unsigned long)0x00fc0000;
3418 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3420 r_type
= R_FRV_TLSMOFFLO
;
3421 howto
= elf32_frv_howto_table
+ r_type
;
3422 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3425 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3426 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
))
3428 /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC
3429 with ldi @(grB, #gottlsoff12(symbol+offset), grC.
3430 Preserve the packing bit. */
3431 insn
= (insn
& (unsigned long)0xfe03f000)
3432 | (unsigned long)0x00c80000;;
3433 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3435 r_type
= R_FRV_GOTTLSOFF12
;
3436 howto
= elf32_frv_howto_table
+ r_type
;
3437 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3442 case R_FRV_TLSMOFFHI
:
3443 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3445 /* Is this a sethi instruction? */
3446 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3448 info
->callbacks
->einfo
3449 (_("%H: R_FRV_TLSMOFFHI"
3450 " not applied to a sethi instruction\n"),
3451 input_bfd
, input_section
, rel
->r_offset
);
3455 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3458 /* Replace sethi with a nop. Preserve the packing bit. */
3459 insn
&= (unsigned long)0x80000000;
3460 insn
|= (unsigned long)0x00880000;
3461 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3463 /* Nothing to relocate. */
3469 case R_FRV_TLSMOFFLO
:
3470 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3472 /* Is this a setlo or setlos instruction? */
3473 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3475 info
->callbacks
->einfo
3476 (_("R_FRV_TLSMOFFLO"
3477 " not applied to a setlo or setlos instruction\n"),
3478 input_bfd
, input_section
, rel
->r_offset
);
3482 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3484 /* If the corresponding sethi (if it exists) decayed
3485 to a nop, make sure this becomes (or already is) a
3486 setlos, not setlo. */
3488 insn
|= (unsigned long)0x00080000;
3489 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3495 There's nothing to relax in these:
3511 check_segment
[0] = isec_segment
;
3512 if (! IS_FDPIC (output_bfd
))
3513 check_segment
[1] = isec_segment
;
3514 else if (picrel
->plt
)
3516 relocation
= frvfdpic_plt_section (info
)->output_section
->vma
3517 + frvfdpic_plt_section (info
)->output_offset
3518 + picrel
->plt_entry
;
3519 check_segment
[1] = plt_segment
;
3521 /* We don't want to warn on calls to undefined weak symbols,
3522 as calls to them must be protected by non-NULL tests
3523 anyway, and unprotected calls would invoke undefined
3525 else if (picrel
->symndx
== -1
3526 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefweak
)
3527 check_segment
[1] = check_segment
[0];
3529 check_segment
[1] = sec
3530 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3537 relocation
= picrel
->got_entry
;
3538 check_segment
[0] = check_segment
[1] = got_segment
;
3541 case R_FRV_FUNCDESC_GOT12
:
3542 case R_FRV_FUNCDESC_GOTHI
:
3543 case R_FRV_FUNCDESC_GOTLO
:
3544 relocation
= picrel
->fdgot_entry
;
3545 check_segment
[0] = check_segment
[1] = got_segment
;
3548 case R_FRV_GOTOFFHI
:
3549 case R_FRV_GOTOFF12
:
3550 case R_FRV_GOTOFFLO
:
3551 relocation
-= frvfdpic_got_section (info
)->output_section
->vma
3552 + frvfdpic_got_section (info
)->output_offset
3553 + frvfdpic_got_initial_offset (info
);
3554 check_segment
[0] = got_segment
;
3555 check_segment
[1] = sec
3556 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3560 case R_FRV_FUNCDESC_GOTOFF12
:
3561 case R_FRV_FUNCDESC_GOTOFFHI
:
3562 case R_FRV_FUNCDESC_GOTOFFLO
:
3563 relocation
= picrel
->fd_entry
;
3564 check_segment
[0] = check_segment
[1] = got_segment
;
3567 case R_FRV_FUNCDESC
:
3570 bfd_vma addend
= rel
->r_addend
;
3572 if (! (h
&& h
->root
.type
== bfd_link_hash_undefweak
3573 && FRVFDPIC_SYM_LOCAL (info
, h
)))
3575 /* If the symbol is dynamic and there may be dynamic
3576 symbol resolution because we are or are linked with a
3577 shared library, emit a FUNCDESC relocation such that
3578 the dynamic linker will allocate the function
3579 descriptor. If the symbol needs a non-local function
3580 descriptor but binds locally (e.g., its visibility is
3581 protected, emit a dynamic relocation decayed to
3583 if (h
&& ! FRVFDPIC_FUNCDESC_LOCAL (info
, h
)
3584 && FRVFDPIC_SYM_LOCAL (info
, h
)
3585 && !(info
->executable
&& !info
->pie
))
3587 dynindx
= elf_section_data (h
->root
.u
.def
.section
3588 ->output_section
)->dynindx
;
3589 addend
+= h
->root
.u
.def
.section
->output_offset
3590 + h
->root
.u
.def
.value
;
3592 else if (h
&& ! FRVFDPIC_FUNCDESC_LOCAL (info
, h
))
3596 info
->callbacks
->einfo
3597 (_("%H: R_FRV_FUNCDESC references dynamic symbol"
3598 " with nonzero addend\n"),
3599 input_bfd
, input_section
, rel
->r_offset
);
3602 dynindx
= h
->dynindx
;
3606 /* Otherwise, we know we have a private function
3607 descriptor, so reference it directly. */
3608 BFD_ASSERT (picrel
->privfd
);
3610 dynindx
= elf_section_data (frvfdpic_got_section (info
)
3611 ->output_section
)->dynindx
;
3612 addend
= frvfdpic_got_section (info
)->output_offset
3613 + frvfdpic_got_initial_offset (info
)
3617 /* If there is room for dynamic symbol resolution, emit
3618 the dynamic relocation. However, if we're linking an
3619 executable at a fixed location, we won't have emitted a
3620 dynamic symbol entry for the got section, so idx will
3621 be zero, which means we can and should compute the
3622 address of the private descriptor ourselves. */
3623 if (info
->executable
&& !info
->pie
3624 && (!h
|| FRVFDPIC_FUNCDESC_LOCAL (info
, h
)))
3626 addend
+= frvfdpic_got_section (info
)->output_section
->vma
;
3627 if ((bfd_get_section_flags (output_bfd
,
3628 input_section
->output_section
)
3629 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3633 if (_frvfdpic_osec_readonly_p (output_bfd
,
3637 info
->callbacks
->einfo
3638 (_("%H: cannot emit fixups"
3639 " in read-only section\n"),
3640 input_bfd
, input_section
, rel
->r_offset
);
3644 offset
= _bfd_elf_section_offset
3646 input_section
, rel
->r_offset
);
3648 if (offset
!= (bfd_vma
)-1)
3649 _frvfdpic_add_rofixup (output_bfd
,
3650 frvfdpic_gotfixup_section
3652 offset
+ input_section
3653 ->output_section
->vma
3654 + input_section
->output_offset
,
3658 else if ((bfd_get_section_flags (output_bfd
,
3659 input_section
->output_section
)
3660 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3664 if (_frvfdpic_osec_readonly_p (output_bfd
,
3668 info
->callbacks
->einfo
3669 (_("%H: cannot emit dynamic relocations"
3670 " in read-only section\n"),
3671 input_bfd
, input_section
, rel
->r_offset
);
3675 offset
= _bfd_elf_section_offset
3677 input_section
, rel
->r_offset
);
3679 if (offset
!= (bfd_vma
)-1)
3680 _frvfdpic_add_dyn_reloc (output_bfd
,
3681 frvfdpic_gotrel_section (info
),
3682 offset
+ input_section
3683 ->output_section
->vma
3684 + input_section
->output_offset
,
3685 r_type
, dynindx
, addend
, picrel
);
3688 addend
+= frvfdpic_got_section (info
)->output_section
->vma
;
3691 /* We want the addend in-place because dynamic
3692 relocations are REL. Setting relocation to it should
3693 arrange for it to be installed. */
3694 relocation
= addend
- rel
->r_addend
;
3696 check_segment
[0] = check_segment
[1] = got_segment
;
3700 if (! IS_FDPIC (output_bfd
))
3702 check_segment
[0] = check_segment
[1] = -1;
3706 case R_FRV_FUNCDESC_VALUE
:
3709 bfd_vma addend
= rel
->r_addend
;
3711 /* If the symbol is dynamic but binds locally, use
3713 if (h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
))
3715 if (addend
&& r_type
== R_FRV_FUNCDESC_VALUE
)
3717 info
->callbacks
->einfo
3718 (_("%H: R_FRV_FUNCDESC_VALUE"
3719 " references dynamic symbol with nonzero addend\n"),
3720 input_bfd
, input_section
, rel
->r_offset
);
3723 dynindx
= h
->dynindx
;
3728 addend
+= h
->root
.u
.def
.value
;
3730 addend
+= sym
->st_value
;
3732 addend
+= osec
->output_offset
;
3733 if (osec
&& osec
->output_section
3734 && ! bfd_is_abs_section (osec
->output_section
)
3735 && ! bfd_is_und_section (osec
->output_section
))
3736 dynindx
= elf_section_data (osec
->output_section
)->dynindx
;
3741 /* If we're linking an executable at a fixed address, we
3742 can omit the dynamic relocation as long as the symbol
3743 is defined in the current link unit (which is implied
3744 by its output section not being NULL). */
3745 if (info
->executable
&& !info
->pie
3746 && (!h
|| FRVFDPIC_SYM_LOCAL (info
, h
)))
3749 addend
+= osec
->output_section
->vma
;
3750 if (IS_FDPIC (input_bfd
)
3751 && (bfd_get_section_flags (output_bfd
,
3752 input_section
->output_section
)
3753 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3755 if (_frvfdpic_osec_readonly_p (output_bfd
,
3759 info
->callbacks
->einfo
3760 (_("%H: cannot emit fixups in read-only section\n"),
3761 input_bfd
, input_section
, rel
->r_offset
);
3764 if (!h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
3766 bfd_vma offset
= _bfd_elf_section_offset
3768 input_section
, rel
->r_offset
);
3770 if (offset
!= (bfd_vma
)-1)
3772 _frvfdpic_add_rofixup (output_bfd
,
3773 frvfdpic_gotfixup_section
3775 offset
+ input_section
3776 ->output_section
->vma
3777 + input_section
->output_offset
,
3779 if (r_type
== R_FRV_FUNCDESC_VALUE
)
3780 _frvfdpic_add_rofixup
3782 frvfdpic_gotfixup_section (info
),
3784 + input_section
->output_section
->vma
3785 + input_section
->output_offset
+ 4, picrel
);
3792 if ((bfd_get_section_flags (output_bfd
,
3793 input_section
->output_section
)
3794 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3798 if (_frvfdpic_osec_readonly_p (output_bfd
,
3802 info
->callbacks
->einfo
3803 (_("%H: cannot emit dynamic relocations"
3804 " in read-only section\n"),
3805 input_bfd
, input_section
, rel
->r_offset
);
3809 offset
= _bfd_elf_section_offset
3811 input_section
, rel
->r_offset
);
3813 if (offset
!= (bfd_vma
)-1)
3814 _frvfdpic_add_dyn_reloc (output_bfd
,
3815 frvfdpic_gotrel_section (info
),
3816 offset
+ input_section
3817 ->output_section
->vma
3818 + input_section
->output_offset
,
3819 r_type
, dynindx
, addend
, picrel
);
3822 addend
+= osec
->output_section
->vma
;
3823 /* We want the addend in-place because dynamic
3824 relocations are REL. Setting relocation to it
3825 should arrange for it to be installed. */
3826 relocation
= addend
- rel
->r_addend
;
3829 if (r_type
== R_FRV_FUNCDESC_VALUE
)
3831 /* If we've omitted the dynamic relocation, just emit
3832 the fixed addresses of the symbol and of the local
3834 if (info
->executable
&& !info
->pie
3835 && (!h
|| FRVFDPIC_SYM_LOCAL (info
, h
)))
3836 bfd_put_32 (output_bfd
,
3837 frvfdpic_got_section (info
)->output_section
->vma
3838 + frvfdpic_got_section (info
)->output_offset
3839 + frvfdpic_got_initial_offset (info
),
3840 contents
+ rel
->r_offset
+ 4);
3842 /* A function descriptor used for lazy or local
3843 resolving is initialized such that its high word
3844 contains the output section index in which the
3845 PLT entries are located, and the low word
3846 contains the offset of the lazy PLT entry entry
3847 point into that section. */
3848 bfd_put_32 (output_bfd
,
3849 h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
)
3851 : _frvfdpic_osec_to_segment (output_bfd
,
3854 contents
+ rel
->r_offset
+ 4);
3857 check_segment
[0] = check_segment
[1] = got_segment
;
3861 case R_FRV_GPRELU12
:
3865 check_segment
[0] = gprel_segment
;
3866 check_segment
[1] = sec
3867 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3871 case R_FRV_GETTLSOFF
:
3872 relocation
= frvfdpic_plt_section (info
)->output_section
->vma
3873 + frvfdpic_plt_section (info
)->output_offset
3874 + picrel
->tlsplt_entry
;
3875 BFD_ASSERT (picrel
->tlsplt_entry
!= (bfd_vma
)-1
3876 && picrel
->tlsdesc_entry
);
3877 check_segment
[0] = isec_segment
;
3878 check_segment
[1] = plt_segment
;
3881 case R_FRV_GOTTLSDESC12
:
3882 case R_FRV_GOTTLSDESCHI
:
3883 case R_FRV_GOTTLSDESCLO
:
3884 BFD_ASSERT (picrel
->tlsdesc_entry
);
3885 relocation
= picrel
->tlsdesc_entry
;
3886 check_segment
[0] = tls_segment
;
3887 check_segment
[1] = sec
3888 && ! bfd_is_abs_section (sec
)
3889 && ! bfd_is_und_section (sec
)
3890 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3894 case R_FRV_TLSMOFF12
:
3895 case R_FRV_TLSMOFFHI
:
3896 case R_FRV_TLSMOFFLO
:
3898 check_segment
[0] = tls_segment
;
3900 check_segment
[1] = -1;
3901 else if (bfd_is_abs_section (sec
)
3902 || bfd_is_und_section (sec
))
3905 check_segment
[1] = tls_segment
;
3907 else if (sec
->output_section
)
3909 relocation
-= tls_biased_base (info
);
3911 _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
);
3914 check_segment
[1] = -1;
3917 case R_FRV_GOTTLSOFF12
:
3918 case R_FRV_GOTTLSOFFHI
:
3919 case R_FRV_GOTTLSOFFLO
:
3920 BFD_ASSERT (picrel
->tlsoff_entry
);
3921 relocation
= picrel
->tlsoff_entry
;
3922 check_segment
[0] = tls_segment
;
3923 check_segment
[1] = sec
3924 && ! bfd_is_abs_section (sec
)
3925 && ! bfd_is_und_section (sec
)
3926 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3930 case R_FRV_TLSDESC_VALUE
:
3932 /* These shouldn't be present in input object files. */
3933 check_segment
[0] = check_segment
[1] = isec_segment
;
3936 case R_FRV_TLSDESC_RELAX
:
3937 case R_FRV_GETTLSOFF_RELAX
:
3938 case R_FRV_TLSOFF_RELAX
:
3939 /* These are just annotations for relaxation, nothing to do
3944 check_segment
[0] = isec_segment
;
3945 check_segment
[1] = sec
3946 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3951 if (check_segment
[0] != check_segment
[1] && IS_FDPIC (output_bfd
))
3953 /* If you take this out, remove the #error from fdpic-static-6.d
3954 in the ld testsuite. */
3955 /* This helps catch problems in GCC while we can't do more
3956 than static linking. The idea is to test whether the
3957 input file basename is crt0.o only once. */
3958 if (silence_segment_error
== 1)
3959 silence_segment_error
=
3960 (strlen (input_bfd
->filename
) == 6
3961 && filename_cmp (input_bfd
->filename
, "crt0.o") == 0)
3962 || (strlen (input_bfd
->filename
) > 6
3963 && filename_cmp (input_bfd
->filename
3964 + strlen (input_bfd
->filename
) - 7,
3967 if (!silence_segment_error
3968 /* We don't want duplicate errors for undefined
3970 && !(picrel
&& picrel
->symndx
== -1
3971 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefined
))
3973 info
->callbacks
->einfo
3974 (_("%H: reloc against `%s' references a different segment\n"),
3975 input_bfd
, input_section
, rel
->r_offset
, name
);
3977 if (!silence_segment_error
&& (info
->shared
|| info
->pie
))
3979 elf_elfheader (output_bfd
)->e_flags
|= EF_FRV_PIC
;
3984 case R_FRV_GOTOFFHI
:
3985 case R_FRV_TLSMOFFHI
:
3986 /* We need the addend to be applied before we shift the
3988 relocation
+= rel
->r_addend
;
3991 case R_FRV_FUNCDESC_GOTHI
:
3992 case R_FRV_FUNCDESC_GOTOFFHI
:
3993 case R_FRV_GOTTLSOFFHI
:
3994 case R_FRV_GOTTLSDESCHI
:
3999 case R_FRV_FUNCDESC_GOTLO
:
4000 case R_FRV_GOTOFFLO
:
4001 case R_FRV_FUNCDESC_GOTOFFLO
:
4002 case R_FRV_GOTTLSOFFLO
:
4003 case R_FRV_GOTTLSDESCLO
:
4004 case R_FRV_TLSMOFFLO
:
4005 relocation
&= 0xffff;
4015 if (! IS_FDPIC (output_bfd
) || ! picrel
->plt
)
4019 /* When referencing a GOT entry, a function descriptor or a
4020 PLT, we don't want the addend to apply to the reference,
4021 but rather to the referenced symbol. The actual entry
4022 will have already been created taking the addend into
4023 account, so cancel it out here. */
4027 case R_FRV_FUNCDESC_GOT12
:
4028 case R_FRV_FUNCDESC_GOTHI
:
4029 case R_FRV_FUNCDESC_GOTLO
:
4030 case R_FRV_FUNCDESC_GOTOFF12
:
4031 case R_FRV_FUNCDESC_GOTOFFHI
:
4032 case R_FRV_FUNCDESC_GOTOFFLO
:
4033 case R_FRV_GETTLSOFF
:
4034 case R_FRV_GOTTLSDESC12
:
4035 case R_FRV_GOTTLSDESCHI
:
4036 case R_FRV_GOTTLSDESCLO
:
4037 case R_FRV_GOTTLSOFF12
:
4038 case R_FRV_GOTTLSOFFHI
:
4039 case R_FRV_GOTTLSOFFLO
:
4040 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
4041 here, since we do want to apply the addend to the others.
4042 Note that we've applied the addend to GOTOFFHI before we
4043 shifted it right. */
4044 case R_FRV_GOTOFFHI
:
4045 case R_FRV_TLSMOFFHI
:
4046 relocation
-= rel
->r_addend
;
4053 if (r_type
== R_FRV_HI16
)
4054 r
= elf32_frv_relocate_hi16 (input_bfd
, rel
, contents
, relocation
);
4056 else if (r_type
== R_FRV_LO16
)
4057 r
= elf32_frv_relocate_lo16 (input_bfd
, rel
, contents
, relocation
);
4059 else if (r_type
== R_FRV_LABEL24
|| r_type
== R_FRV_GETTLSOFF
)
4060 r
= elf32_frv_relocate_label24 (input_bfd
, input_section
, rel
,
4061 contents
, relocation
);
4063 else if (r_type
== R_FRV_GPREL12
)
4064 r
= elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, rel
,
4065 contents
, relocation
);
4067 else if (r_type
== R_FRV_GPRELU12
)
4068 r
= elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, rel
,
4069 contents
, relocation
);
4071 else if (r_type
== R_FRV_GPRELLO
)
4072 r
= elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, rel
,
4073 contents
, relocation
);
4075 else if (r_type
== R_FRV_GPRELHI
)
4076 r
= elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, rel
,
4077 contents
, relocation
);
4079 else if (r_type
== R_FRV_TLSOFF
4080 || r_type
== R_FRV_TLSDESC_VALUE
)
4081 r
= bfd_reloc_notsupported
;
4084 r
= frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
4087 if (r
!= bfd_reloc_ok
)
4089 const char * msg
= (const char *) NULL
;
4093 case bfd_reloc_overflow
:
4094 r
= info
->callbacks
->reloc_overflow
4095 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4096 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
4099 case bfd_reloc_undefined
:
4100 r
= info
->callbacks
->undefined_symbol
4101 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
4104 case bfd_reloc_outofrange
:
4105 msg
= _("internal error: out of range error");
4108 case bfd_reloc_notsupported
:
4109 msg
= _("internal error: unsupported relocation error");
4112 case bfd_reloc_dangerous
:
4113 msg
= _("internal error: dangerous relocation");
4117 msg
= _("internal error: unknown error");
4123 info
->callbacks
->einfo
4124 (_("%H: reloc against `%s': %s\n"),
4125 input_bfd
, input_section
, rel
->r_offset
, name
, msg
);
4137 /* Return the section that should be marked against GC for a given
4141 elf32_frv_gc_mark_hook (asection
*sec
,
4142 struct bfd_link_info
*info
,
4143 Elf_Internal_Rela
*rel
,
4144 struct elf_link_hash_entry
*h
,
4145 Elf_Internal_Sym
*sym
)
4148 switch (ELF32_R_TYPE (rel
->r_info
))
4150 case R_FRV_GNU_VTINHERIT
:
4151 case R_FRV_GNU_VTENTRY
:
4155 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
4158 /* Hook called by the linker routine which adds symbols from an object
4159 file. We use it to put .comm items in .scomm, and not .comm. */
4162 elf32_frv_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
4164 struct bfd_link_info
*info
;
4165 Elf_Internal_Sym
*sym
;
4166 const char **namep ATTRIBUTE_UNUSED
;
4167 flagword
*flagsp ATTRIBUTE_UNUSED
;
4171 if (sym
->st_shndx
== SHN_COMMON
4172 && !info
->relocatable
4173 && (int)sym
->st_size
<= (int)bfd_get_gp_size (abfd
))
4175 /* Common symbols less than or equal to -G nn bytes are
4176 automatically put into .sbss. */
4178 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
4182 scomm
= bfd_make_section_with_flags (abfd
, ".scommon",
4185 | SEC_LINKER_CREATED
));
4191 *valp
= sym
->st_size
;
4197 /* We need dynamic symbols for every section, since segments can
4198 relocate independently. */
4200 _frvfdpic_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4201 struct bfd_link_info
*info
4203 asection
*p ATTRIBUTE_UNUSED
)
4205 switch (elf_section_data (p
)->this_hdr
.sh_type
)
4209 /* If sh_type is yet undecided, assume it could be
4210 SHT_PROGBITS/SHT_NOBITS. */
4214 /* There shouldn't be section relative relocations
4215 against any other section. */
4221 /* Create a .got section, as well as its additional info field. This
4222 is almost entirely copied from
4223 elflink.c:_bfd_elf_create_got_section(). */
4226 _frv_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4228 flagword flags
, pltflags
;
4230 struct elf_link_hash_entry
*h
;
4231 struct bfd_link_hash_entry
*bh
;
4232 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4236 /* This function may be called more than once. */
4237 s
= bfd_get_section_by_name (abfd
, ".got");
4238 if (s
!= NULL
&& (s
->flags
& SEC_LINKER_CREATED
) != 0)
4241 /* Machine specific: although pointers are 32-bits wide, we want the
4242 GOT to be aligned to a 64-bit boundary, such that function
4243 descriptors in it can be accessed with 64-bit loads and
4247 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4248 | SEC_LINKER_CREATED
);
4251 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
4253 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
4256 if (bed
->want_got_plt
)
4258 s
= bfd_make_section_with_flags (abfd
, ".got.plt", flags
);
4260 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
4264 if (bed
->want_got_sym
)
4266 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
4267 (or .got.plt) section. We don't do this in the linker script
4268 because we don't want to define the symbol if we are not creating
4269 a global offset table. */
4270 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
, "_GLOBAL_OFFSET_TABLE_");
4271 elf_hash_table (info
)->hgot
= h
;
4275 /* Machine-specific: we want the symbol for executables as
4277 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4281 /* The first bit of the global offset table is the header. */
4282 s
->size
+= bed
->got_header_size
;
4284 /* This is the machine-specific part. Create and initialize section
4285 data for the got. */
4286 if (IS_FDPIC (abfd
))
4288 frvfdpic_got_section (info
) = s
;
4289 frvfdpic_relocs_info (info
) = htab_try_create (1,
4290 frvfdpic_relocs_info_hash
,
4291 frvfdpic_relocs_info_eq
,
4293 if (! frvfdpic_relocs_info (info
))
4296 s
= bfd_make_section_with_flags (abfd
, ".rel.got",
4297 (flags
| SEC_READONLY
));
4299 || ! bfd_set_section_alignment (abfd
, s
, 2))
4302 frvfdpic_gotrel_section (info
) = s
;
4304 /* Machine-specific. */
4305 s
= bfd_make_section_with_flags (abfd
, ".rofixup",
4306 (flags
| SEC_READONLY
));
4308 || ! bfd_set_section_alignment (abfd
, s
, 2))
4311 frvfdpic_gotfixup_section (info
) = s
;
4318 flags
= BSF_GLOBAL
| BSF_WEAK
;
4321 /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it
4322 turns out that we're linking with a different linker script, the
4323 linker script will override it. */
4325 if (!(_bfd_generic_link_add_one_symbol
4326 (info
, abfd
, "_gp", flags
, s
, offset
, (const char *) NULL
, FALSE
,
4327 bed
->collect
, &bh
)))
4329 h
= (struct elf_link_hash_entry
*) bh
;
4331 h
->type
= STT_OBJECT
;
4332 /* h->other = STV_HIDDEN; */ /* Should we? */
4334 /* Machine-specific: we want the symbol for executables as well. */
4335 if (IS_FDPIC (abfd
) && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
4338 if (!IS_FDPIC (abfd
))
4341 /* FDPIC supports Thread Local Storage, and this may require a
4342 procedure linkage table for TLS PLT entries. */
4344 /* This is mostly copied from
4345 elflink.c:_bfd_elf_create_dynamic_sections(). */
4348 pltflags
|= SEC_CODE
;
4349 if (bed
->plt_not_loaded
)
4350 pltflags
&= ~ (SEC_CODE
| SEC_LOAD
| SEC_HAS_CONTENTS
);
4351 if (bed
->plt_readonly
)
4352 pltflags
|= SEC_READONLY
;
4354 s
= bfd_make_section_with_flags (abfd
, ".plt", pltflags
);
4356 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
4358 /* FRV-specific: remember it. */
4359 frvfdpic_plt_section (info
) = s
;
4361 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
4363 if (bed
->want_plt_sym
)
4365 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
4366 "_PROCEDURE_LINKAGE_TABLE_");
4367 elf_hash_table (info
)->hplt
= h
;
4372 /* FRV-specific: we want rel relocations for the plt. */
4373 s
= bfd_make_section_with_flags (abfd
, ".rel.plt",
4374 flags
| SEC_READONLY
);
4376 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
4378 /* FRV-specific: remember it. */
4379 frvfdpic_pltrel_section (info
) = s
;
4384 /* Make sure the got and plt sections exist, and that our pointers in
4385 the link hash table point to them. */
4388 elf32_frvfdpic_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
4390 /* This is mostly copied from
4391 elflink.c:_bfd_elf_create_dynamic_sections(). */
4394 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4396 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4397 | SEC_LINKER_CREATED
);
4399 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
4400 .rel[a].bss sections. */
4402 /* FRV-specific: we want to create the GOT and the PLT in the FRV
4404 if (! _frv_create_got_section (abfd
, info
))
4407 /* FRV-specific: make sure we created everything we wanted. */
4408 BFD_ASSERT (frvfdpic_got_section (info
) && frvfdpic_gotrel_section (info
)
4409 && frvfdpic_gotfixup_section (info
)
4410 && frvfdpic_plt_section (info
)
4411 && frvfdpic_pltrel_section (info
));
4413 if (bed
->want_dynbss
)
4415 /* The .dynbss section is a place to put symbols which are defined
4416 by dynamic objects, are referenced by regular objects, and are
4417 not functions. We must allocate space for them in the process
4418 image and use a R_*_COPY reloc to tell the dynamic linker to
4419 initialize them at run time. The linker script puts the .dynbss
4420 section into the .bss section of the final image. */
4421 s
= bfd_make_section_with_flags (abfd
, ".dynbss",
4422 SEC_ALLOC
| SEC_LINKER_CREATED
);
4426 /* The .rel[a].bss section holds copy relocs. This section is not
4427 normally needed. We need to create it here, though, so that the
4428 linker will map it to an output section. We can't just create it
4429 only if we need it, because we will not know whether we need it
4430 until we have seen all the input files, and the first time the
4431 main linker code calls BFD after examining all the input files
4432 (size_dynamic_sections) the input sections have already been
4433 mapped to the output sections. If the section turns out not to
4434 be needed, we can discard it later. We will never need this
4435 section when generating a shared object, since they do not use
4439 s
= bfd_make_section_with_flags (abfd
,
4440 (bed
->default_use_rela_p
4441 ? ".rela.bss" : ".rel.bss"),
4442 flags
| SEC_READONLY
);
4444 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
4452 /* Compute the total GOT and PLT size required by each symbol in each
4453 range. Symbols may require up to 4 words in the GOT: an entry
4454 pointing to the symbol, an entry pointing to its function
4455 descriptor, and a private function descriptors taking two
4459 _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info
*entry
,
4460 struct _frvfdpic_dynamic_got_info
*dinfo
)
4462 /* Allocate space for a GOT entry pointing to the symbol. */
4465 else if (entry
->gotlos
)
4467 else if (entry
->gothilo
)
4468 dinfo
->gothilo
+= 4;
4473 /* Allocate space for a GOT entry pointing to the function
4477 else if (entry
->fdgotlos
)
4479 else if (entry
->fdgothilo
)
4480 dinfo
->gothilo
+= 4;
4485 /* Decide whether we need a PLT entry, a function descriptor in the
4486 GOT, and a lazy PLT entry for this symbol. */
4487 entry
->plt
= entry
->call
4488 && entry
->symndx
== -1 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4489 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
4490 entry
->privfd
= entry
->plt
4491 || entry
->fdgoff12
|| entry
->fdgofflos
|| entry
->fdgoffhilo
4492 || ((entry
->fd
|| entry
->fdgot12
|| entry
->fdgotlos
|| entry
->fdgothilo
)
4493 && (entry
->symndx
!= -1
4494 || FRVFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
)));
4495 entry
->lazyplt
= entry
->privfd
4496 && entry
->symndx
== -1 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4497 && ! (dinfo
->info
->flags
& DF_BIND_NOW
)
4498 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
4500 /* Allocate space for a function descriptor. */
4501 if (entry
->fdgoff12
)
4503 else if (entry
->fdgofflos
)
4505 else if (entry
->privfd
&& entry
->plt
)
4507 else if (entry
->privfd
)
4517 /* Compute the total GOT size required by each TLS symbol in each
4518 range. Symbols may require up to 5 words in the GOT: an entry
4519 holding the TLS offset for the symbol, and an entry with a full TLS
4520 descriptor taking 4 words. */
4523 _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info
*entry
,
4524 struct _frvfdpic_dynamic_got_info
*dinfo
,
4525 bfd_boolean subtract
)
4527 const int l
= subtract
? -1 : 1;
4529 /* Allocate space for a GOT entry with the TLS offset of the
4531 if (entry
->tlsoff12
)
4532 dinfo
->got12
+= 4 * l
;
4533 else if (entry
->tlsofflos
)
4534 dinfo
->gotlos
+= 4 * l
;
4535 else if (entry
->tlsoffhilo
)
4536 dinfo
->gothilo
+= 4 * l
;
4538 entry
->relocstlsoff
-= l
;
4539 entry
->relocstlsoff
+= l
;
4541 /* If there's any TLSOFF relocation, mark the output file as not
4542 suitable for dlopening. This mark will remain even if we relax
4543 all such relocations, but this is not a problem, since we'll only
4544 do so for executables, and we definitely don't want anyone
4545 dlopening executables. */
4546 if (entry
->relocstlsoff
)
4547 dinfo
->info
->flags
|= DF_STATIC_TLS
;
4549 /* Allocate space for a TLS descriptor. */
4550 if (entry
->tlsdesc12
)
4551 dinfo
->tlsd12
+= 8 * l
;
4552 else if (entry
->tlsdesclos
)
4553 dinfo
->tlsdlos
+= 8 * l
;
4554 else if (entry
->tlsplt
)
4555 dinfo
->tlsdplt
+= 8 * l
;
4556 else if (entry
->tlsdeschilo
)
4557 dinfo
->tlsdhilo
+= 8 * l
;
4559 entry
->relocstlsd
-= l
;
4560 entry
->relocstlsd
+= l
;
4563 /* Compute the number of dynamic relocations and fixups that a symbol
4564 requires, and add (or subtract) from the grand and per-symbol
4568 _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info
*entry
,
4569 struct _frvfdpic_dynamic_got_info
*dinfo
,
4570 bfd_boolean subtract
)
4572 bfd_vma relocs
= 0, fixups
= 0, tlsrets
= 0;
4574 if (!dinfo
->info
->executable
|| dinfo
->info
->pie
)
4576 relocs
= entry
->relocs32
+ entry
->relocsfd
+ entry
->relocsfdv
4577 + entry
->relocstlsd
;
4579 /* In the executable, TLS relocations to symbols that bind
4580 locally (including those that resolve to global TLS offsets)
4581 are resolved immediately, without any need for fixups or
4582 dynamic relocations. In shared libraries, however, we must
4583 emit dynamic relocations even for local symbols, because we
4584 don't know the module id the library is going to get at
4585 run-time, nor its TLS base offset. */
4586 if (!dinfo
->info
->executable
4587 || (entry
->symndx
== -1
4588 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)))
4589 relocs
+= entry
->relocstlsoff
;
4593 if (entry
->symndx
!= -1 || FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
))
4595 if (entry
->symndx
!= -1
4596 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
4597 fixups
+= entry
->relocs32
+ 2 * entry
->relocsfdv
;
4598 fixups
+= entry
->relocstlsd
;
4599 tlsrets
+= entry
->relocstlsd
;
4603 relocs
+= entry
->relocs32
+ entry
->relocsfdv
4604 + entry
->relocstlsoff
+ entry
->relocstlsd
;
4607 if (entry
->symndx
!= -1
4608 || FRVFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
))
4610 if (entry
->symndx
!= -1
4611 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
4612 fixups
+= entry
->relocsfd
;
4615 relocs
+= entry
->relocsfd
;
4622 tlsrets
= - tlsrets
;
4625 entry
->dynrelocs
+= relocs
;
4626 entry
->fixups
+= fixups
;
4627 dinfo
->relocs
+= relocs
;
4628 dinfo
->fixups
+= fixups
;
4629 dinfo
->tls_ret_refs
+= tlsrets
;
4632 /* Look for opportunities to relax TLS relocations. We can assume
4633 we're linking the main executable or a static-tls library, since
4634 otherwise we wouldn't have got here. When relaxing, we have to
4635 first undo any previous accounting of TLS uses of fixups, dynamic
4636 relocations, GOT and PLT entries. */
4639 _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info
*entry
,
4640 struct _frvfdpic_dynamic_got_info
*dinfo
,
4641 bfd_boolean relaxing
)
4643 bfd_boolean changed
= ! relaxing
;
4645 BFD_ASSERT (dinfo
->info
->executable
4646 || (dinfo
->info
->flags
& DF_STATIC_TLS
));
4648 if (entry
->tlsdesc12
|| entry
->tlsdesclos
|| entry
->tlsdeschilo
)
4652 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4653 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4657 /* When linking an executable, we can always decay GOTTLSDESC to
4658 TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise.
4659 When linking a static-tls shared library, using TLSMOFF is
4660 not an option, but we can still use GOTTLSOFF. When decaying
4661 to GOTTLSOFF, we must keep the GOT entry in range. We know
4662 it has to fit because we'll be trading the 4 words of hte TLS
4663 descriptor for a single word in the same range. */
4664 if (! dinfo
->info
->executable
4665 || (entry
->symndx
== -1
4666 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)))
4668 entry
->tlsoff12
|= entry
->tlsdesc12
;
4669 entry
->tlsofflos
|= entry
->tlsdesclos
;
4670 entry
->tlsoffhilo
|= entry
->tlsdeschilo
;
4673 entry
->tlsdesc12
= entry
->tlsdesclos
= entry
->tlsdeschilo
= 0;
4676 /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the
4677 main executable. We have to check whether the symbol's TLSOFF is
4678 in range for a setlos. For symbols with a hash entry, we can
4679 determine exactly what to do; for others locals, we don't have
4680 addresses handy, so we use the size of the TLS section as an
4681 approximation. If we get it wrong, we'll retain a GOT entry
4682 holding the TLS offset (without dynamic relocations or fixups),
4683 but we'll still optimize away the loads from it. Since TLS sizes
4684 are generally very small, it's probably not worth attempting to
4685 do better than this. */
4687 || entry
->tlsoff12
|| entry
->tlsofflos
|| entry
->tlsoffhilo
)
4688 && dinfo
->info
->executable
&& relaxing
4689 && ((entry
->symndx
== -1
4690 && FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4691 /* The above may hold for an undefweak TLS symbol, so make
4692 sure we don't have this case before accessing def.value
4694 && (entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
4695 || (bfd_vma
)(entry
->d
.h
->root
.u
.def
.value
4696 + (entry
->d
.h
->root
.u
.def
.section
4697 ->output_section
->vma
)
4698 + entry
->d
.h
->root
.u
.def
.section
->output_offset
4700 - tls_biased_base (dinfo
->info
)
4701 + 32768) < (bfd_vma
)65536))
4702 || (entry
->symndx
!= -1
4703 && (elf_hash_table (dinfo
->info
)->tls_sec
->size
4704 + abs (entry
->addend
) < 32768 + FRVFDPIC_TLS_BIAS
))))
4708 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4709 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4714 entry
->tlsoff12
= entry
->tlsofflos
= entry
->tlsoffhilo
= 0;
4717 /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already
4718 have a #gottlsoff12 relocation for this entry, or if we can fit
4719 one more in the 12-bit (and 16-bit) ranges. */
4723 && dinfo
->got12
+ dinfo
->fd12
+ dinfo
->tlsd12
<= 4096 - 12 - 4
4724 && (dinfo
->got12
+ dinfo
->fd12
+ dinfo
->tlsd12
4725 + dinfo
->gotlos
+ dinfo
->fdlos
+ dinfo
->tlsdlos
4726 <= 65536 - 12 - 4))))
4730 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4731 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4735 entry
->tlsoff12
= 1;
4741 _frvfdpic_count_tls_entries (entry
, dinfo
, FALSE
);
4742 _frvfdpic_count_relocs_fixups (entry
, dinfo
, FALSE
);
4748 /* Compute the total GOT and PLT size required by each symbol in each range. *
4749 Symbols may require up to 4 words in the GOT: an entry pointing to
4750 the symbol, an entry pointing to its function descriptor, and a
4751 private function descriptors taking two words. */
4754 _frvfdpic_count_got_plt_entries (void **entryp
, void *dinfo_
)
4756 struct frvfdpic_relocs_info
*entry
= *entryp
;
4757 struct _frvfdpic_dynamic_got_info
*dinfo
= dinfo_
;
4759 _frvfdpic_count_nontls_entries (entry
, dinfo
);
4761 if (dinfo
->info
->executable
|| (dinfo
->info
->flags
& DF_STATIC_TLS
))
4762 _frvfdpic_relax_tls_entries (entry
, dinfo
, FALSE
);
4765 _frvfdpic_count_tls_entries (entry
, dinfo
, FALSE
);
4766 _frvfdpic_count_relocs_fixups (entry
, dinfo
, FALSE
);
4772 /* Determine the positive and negative ranges to be used by each
4773 offset range in the GOT. FDCUR and CUR, that must be aligned to a
4774 double-word boundary, are the minimum (negative) and maximum
4775 (positive) GOT offsets already used by previous ranges, except for
4776 an ODD entry that may have been left behind. GOT and FD indicate
4777 the size of GOT entries and function descriptors that must be
4778 placed within the range from -WRAP to WRAP. If there's room left,
4779 up to FDPLT bytes should be reserved for additional function
4782 inline static bfd_signed_vma
4783 _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data
*gad
,
4784 bfd_signed_vma fdcur
,
4794 bfd_signed_vma wrapmin
= -wrap
;
4795 const bfd_vma tdescsz
= 8;
4797 /* Start at the given initial points. */
4801 /* If we had an incoming odd word and we have any got entries that
4802 are going to use it, consume it, otherwise leave gad->odd at
4803 zero. We might force gad->odd to zero and return the incoming
4804 odd such that it is used by the next range, but then GOT entries
4805 might appear to be out of order and we wouldn't be able to
4806 shorten the GOT by one word if it turns out to end with an
4807 unpaired GOT entry. */
4817 /* If we're left with an unpaired GOT entry, compute its location
4818 such that we can return it. Otherwise, if got doesn't require an
4819 odd number of words here, either odd was already zero in the
4820 block above, or it was set to zero because got was non-zero, or
4821 got was already zero. In the latter case, we want the value of
4822 odd to carry over to the return statement, so we don't want to
4823 reset odd unless the condition below is true. */
4830 /* Compute the tentative boundaries of this range. */
4831 gad
->max
= cur
+ got
;
4832 gad
->min
= fdcur
- fd
;
4835 /* If function descriptors took too much space, wrap some of them
4837 if (gad
->min
< wrapmin
)
4839 gad
->max
+= wrapmin
- gad
->min
;
4840 gad
->tmin
= gad
->min
= wrapmin
;
4843 /* If GOT entries took too much space, wrap some of them around.
4844 This may well cause gad->min to become lower than wrapmin. This
4845 will cause a relocation overflow later on, so we don't have to
4847 if ((bfd_vma
) gad
->max
> wrap
)
4849 gad
->min
-= gad
->max
- wrap
;
4853 /* Add TLS descriptors. */
4854 gad
->tmax
= gad
->max
+ tlsd
;
4855 gad
->tmin
= gad
->min
;
4858 /* If TLS descriptors took too much space, wrap an integral number
4860 if ((bfd_vma
) gad
->tmax
> wrap
)
4862 bfd_vma wrapsize
= gad
->tmax
- wrap
;
4864 wrapsize
+= tdescsz
/ 2;
4865 wrapsize
&= ~ tdescsz
/ 2;
4867 gad
->tmin
-= wrapsize
;
4868 gad
->tmax
-= wrapsize
;
4871 /* If there is space left and we have function descriptors
4872 referenced in PLT entries that could take advantage of shorter
4873 offsets, place them now. */
4874 if (fdplt
&& gad
->tmin
> wrapmin
)
4878 if ((bfd_vma
) (gad
->tmin
- wrapmin
) < fdplt
)
4879 fds
= gad
->tmin
- wrapmin
;
4889 /* If there is more space left, try to place some more function
4890 descriptors for PLT entries. */
4891 if (fdplt
&& (bfd_vma
) gad
->tmax
< wrap
)
4895 if ((bfd_vma
) (wrap
- gad
->tmax
) < fdplt
)
4896 fds
= wrap
- gad
->tmax
;
4906 /* If there is space left and we have TLS descriptors referenced in
4907 PLT entries that could take advantage of shorter offsets, place
4909 if (tlsdplt
&& gad
->tmin
> wrapmin
)
4913 if ((bfd_vma
) (gad
->tmin
- wrapmin
) < tlsdplt
)
4914 tlsds
= (gad
->tmin
- wrapmin
) & ~ (tdescsz
/ 2);
4920 gad
->tlsdplt
+= tlsds
;
4923 /* If there is more space left, try to place some more TLS
4924 descriptors for PLT entries. Although we could try to fit an
4925 additional TLS descriptor with half of it just before before the
4926 wrap point and another right past the wrap point, this might
4927 cause us to run out of space for the next region, so don't do
4929 if (tlsdplt
&& (bfd_vma
) gad
->tmax
< wrap
- tdescsz
/ 2)
4933 if ((bfd_vma
) (wrap
- gad
->tmax
) < tlsdplt
)
4934 tlsds
= (wrap
- gad
->tmax
) & ~ (tdescsz
/ 2);
4940 gad
->tlsdplt
+= tlsds
;
4943 /* If odd was initially computed as an offset past the wrap point,
4946 odd
= gad
->min
+ odd
- gad
->max
;
4948 /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed
4949 before returning, so do it here too. This guarantees that,
4950 should cur and fdcur meet at the wrap point, they'll both be
4952 if (gad
->cur
== gad
->max
)
4953 gad
->cur
= gad
->min
;
4955 /* Ditto for _frvfdpic_get_tlsdesc_entry(). */
4956 gad
->tcur
= gad
->max
;
4957 if (gad
->tcur
== gad
->tmax
)
4958 gad
->tcur
= gad
->tmin
;
4963 /* Compute the location of the next GOT entry, given the allocation
4964 data for a range. */
4966 inline static bfd_signed_vma
4967 _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
4973 /* If there was an odd word left behind, use it. */
4979 /* Otherwise, use the word pointed to by cur, reserve the next
4980 as an odd word, and skip to the next pair of words, possibly
4983 gad
->odd
= gad
->cur
+ 4;
4985 if (gad
->cur
== gad
->max
)
4986 gad
->cur
= gad
->min
;
4992 /* Compute the location of the next function descriptor entry in the
4993 GOT, given the allocation data for a range. */
4995 inline static bfd_signed_vma
4996 _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
4998 /* If we're at the bottom, wrap around, and only then allocate the
4999 next pair of words. */
5000 if (gad
->fdcur
== gad
->min
)
5001 gad
->fdcur
= gad
->max
;
5002 return gad
->fdcur
-= 8;
5005 /* Compute the location of the next TLS descriptor entry in the GOT,
5006 given the allocation data for a range. */
5007 inline static bfd_signed_vma
5008 _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
5016 /* If we're at the top of the region, wrap around to the bottom. */
5017 if (gad
->tcur
== gad
->tmax
)
5018 gad
->tcur
= gad
->tmin
;
5023 /* Assign GOT offsets for every GOT entry and function descriptor.
5024 Doing everything in a single pass is tricky. */
5027 _frvfdpic_assign_got_entries (void **entryp
, void *info_
)
5029 struct frvfdpic_relocs_info
*entry
= *entryp
;
5030 struct _frvfdpic_dynamic_got_plt_info
*dinfo
= info_
;
5033 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5034 else if (entry
->gotlos
)
5035 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5036 else if (entry
->gothilo
)
5037 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5040 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5041 else if (entry
->fdgotlos
)
5042 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5043 else if (entry
->fdgothilo
)
5044 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5046 if (entry
->fdgoff12
)
5047 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->got12
);
5048 else if (entry
->plt
&& dinfo
->got12
.fdplt
)
5050 dinfo
->got12
.fdplt
-= 8;
5051 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->got12
);
5053 else if (entry
->fdgofflos
)
5054 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gotlos
);
5055 else if (entry
->plt
&& dinfo
->gotlos
.fdplt
)
5057 dinfo
->gotlos
.fdplt
-= 8;
5058 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gotlos
);
5060 else if (entry
->plt
)
5062 dinfo
->gothilo
.fdplt
-= 8;
5063 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gothilo
);
5065 else if (entry
->privfd
)
5066 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gothilo
);
5068 if (entry
->tlsoff12
)
5069 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5070 else if (entry
->tlsofflos
)
5071 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5072 else if (entry
->tlsoffhilo
)
5073 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5075 if (entry
->tlsdesc12
)
5076 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->got12
);
5077 else if (entry
->tlsplt
&& dinfo
->got12
.tlsdplt
)
5079 dinfo
->got12
.tlsdplt
-= 8;
5080 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->got12
);
5082 else if (entry
->tlsdesclos
)
5083 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gotlos
);
5084 else if (entry
->tlsplt
&& dinfo
->gotlos
.tlsdplt
)
5086 dinfo
->gotlos
.tlsdplt
-= 8;
5087 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gotlos
);
5089 else if (entry
->tlsplt
)
5091 dinfo
->gothilo
.tlsdplt
-= 8;
5092 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gothilo
);
5094 else if (entry
->tlsdeschilo
)
5095 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gothilo
);
5100 /* Assign GOT offsets to private function descriptors used by PLT
5101 entries (or referenced by 32-bit offsets), as well as PLT entries
5102 and lazy PLT entries. */
5105 _frvfdpic_assign_plt_entries (void **entryp
, void *info_
)
5107 struct frvfdpic_relocs_info
*entry
= *entryp
;
5108 struct _frvfdpic_dynamic_got_plt_info
*dinfo
= info_
;
5111 BFD_ASSERT (entry
->fd_entry
);
5117 /* We use the section's raw size to mark the location of the
5119 entry
->plt_entry
= frvfdpic_plt_section (dinfo
->g
.info
)->size
;
5121 /* Figure out the length of this PLT entry based on the
5122 addressing mode we need to reach the function descriptor. */
5123 BFD_ASSERT (entry
->fd_entry
);
5124 if (entry
->fd_entry
>= -(1 << (12 - 1))
5125 && entry
->fd_entry
< (1 << (12 - 1)))
5127 else if (entry
->fd_entry
>= -(1 << (16 - 1))
5128 && entry
->fd_entry
< (1 << (16 - 1)))
5133 frvfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
5138 entry
->lzplt_entry
= dinfo
->g
.lzplt
;
5139 dinfo
->g
.lzplt
+= 8;
5140 /* If this entry is the one that gets the resolver stub, account
5141 for the additional instruction. */
5142 if (entry
->lzplt_entry
% FRVFDPIC_LZPLT_BLOCK_SIZE
5143 == FRVFDPIC_LZPLT_RESOLV_LOC
)
5144 dinfo
->g
.lzplt
+= 4;
5152 = frvfdpic_plt_section (dinfo
->g
.info
)->size
;
5154 if (dinfo
->g
.info
->executable
5155 && (entry
->symndx
!= -1
5156 || FRVFDPIC_SYM_LOCAL (dinfo
->g
.info
, entry
->d
.h
)))
5158 if ((bfd_signed_vma
)entry
->addend
>= -(1 << (16 - 1))
5159 /* FIXME: here we use the size of the TLS section
5160 as an upper bound for the value of the TLS
5161 symbol, because we may not know the exact value
5162 yet. If we get it wrong, we'll just waste a
5163 word in the PLT, and we should never get even
5164 close to 32 KiB of TLS anyway. */
5165 && elf_hash_table (dinfo
->g
.info
)->tls_sec
5166 && (elf_hash_table (dinfo
->g
.info
)->tls_sec
->size
5167 + (bfd_signed_vma
)(entry
->addend
) <= (1 << (16 - 1))))
5172 else if (entry
->tlsoff_entry
)
5174 if (entry
->tlsoff_entry
>= -(1 << (12 - 1))
5175 && entry
->tlsoff_entry
< (1 << (12 - 1)))
5177 else if (entry
->tlsoff_entry
>= -(1 << (16 - 1))
5178 && entry
->tlsoff_entry
< (1 << (16 - 1)))
5185 BFD_ASSERT (entry
->tlsdesc_entry
);
5187 if (entry
->tlsdesc_entry
>= -(1 << (12 - 1))
5188 && entry
->tlsdesc_entry
< (1 << (12 - 1)))
5190 else if (entry
->tlsdesc_entry
>= -(1 << (16 - 1))
5191 && entry
->tlsdesc_entry
< (1 << (16 - 1)))
5197 frvfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
5203 /* Cancel out any effects of calling _frvfdpic_assign_got_entries and
5204 _frvfdpic_assign_plt_entries. */
5207 _frvfdpic_reset_got_plt_entries (void **entryp
, void *ignore ATTRIBUTE_UNUSED
)
5209 struct frvfdpic_relocs_info
*entry
= *entryp
;
5211 entry
->got_entry
= 0;
5212 entry
->fdgot_entry
= 0;
5213 entry
->fd_entry
= 0;
5214 entry
->plt_entry
= (bfd_vma
)-1;
5215 entry
->lzplt_entry
= (bfd_vma
)-1;
5216 entry
->tlsoff_entry
= 0;
5217 entry
->tlsdesc_entry
= 0;
5218 entry
->tlsplt_entry
= (bfd_vma
)-1;
5223 /* Follow indirect and warning hash entries so that each got entry
5224 points to the final symbol definition. P must point to a pointer
5225 to the hash table we're traversing. Since this traversal may
5226 modify the hash table, we set this pointer to NULL to indicate
5227 we've made a potentially-destructive change to the hash table, so
5228 the traversal must be restarted. */
5230 _frvfdpic_resolve_final_relocs_info (void **entryp
, void *p
)
5232 struct frvfdpic_relocs_info
*entry
= *entryp
;
5235 if (entry
->symndx
== -1)
5237 struct elf_link_hash_entry
*h
= entry
->d
.h
;
5238 struct frvfdpic_relocs_info
*oentry
;
5240 while (h
->root
.type
== bfd_link_hash_indirect
5241 || h
->root
.type
== bfd_link_hash_warning
)
5242 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
5244 if (entry
->d
.h
== h
)
5247 oentry
= frvfdpic_relocs_info_for_global (*htab
, 0, h
, entry
->addend
,
5252 /* Merge the two entries. */
5253 frvfdpic_pic_merge_early_relocs_info (oentry
, entry
);
5254 htab_clear_slot (*htab
, entryp
);
5260 /* If we can't find this entry with the new bfd hash, re-insert
5261 it, and get the traversal restarted. */
5262 if (! htab_find (*htab
, entry
))
5264 htab_clear_slot (*htab
, entryp
);
5265 entryp
= htab_find_slot (*htab
, entry
, INSERT
);
5268 /* Abort the traversal, since the whole table may have
5269 moved, and leave it up to the parent to restart the
5271 *(htab_t
*)p
= NULL
;
5279 /* Compute the total size of the GOT, the PLT, the dynamic relocations
5280 section and the rofixup section. Assign locations for GOT and PLT
5284 _frvfdpic_size_got_plt (bfd
*output_bfd
,
5285 struct _frvfdpic_dynamic_got_plt_info
*gpinfop
)
5288 bfd_vma limit
, tlslimit
;
5289 struct bfd_link_info
*info
= gpinfop
->g
.info
;
5290 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
5292 memcpy (frvfdpic_dynamic_got_plt_info (info
), &gpinfop
->g
,
5293 sizeof (gpinfop
->g
));
5296 /* Compute the total size taken by entries in the 12-bit and 16-bit
5297 ranges, to tell how many PLT function descriptors we can bring
5298 into the 12-bit range without causing the 16-bit range to
5300 limit
= odd
+ gpinfop
->g
.got12
+ gpinfop
->g
.gotlos
5301 + gpinfop
->g
.fd12
+ gpinfop
->g
.fdlos
5302 + gpinfop
->g
.tlsd12
+ gpinfop
->g
.tlsdlos
;
5303 if (limit
< (bfd_vma
)1 << 16)
5304 limit
= ((bfd_vma
)1 << 16) - limit
;
5307 if (gpinfop
->g
.fdplt
< limit
)
5309 tlslimit
= (limit
- gpinfop
->g
.fdplt
) & ~ (bfd_vma
) 8;
5310 limit
= gpinfop
->g
.fdplt
;
5314 if (gpinfop
->g
.tlsdplt
< tlslimit
)
5315 tlslimit
= gpinfop
->g
.tlsdplt
;
5317 /* Determine the ranges of GOT offsets that we can use for each
5318 range of addressing modes. */
5319 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->got12
,
5328 (bfd_vma
)1 << (12-1));
5329 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->gotlos
,
5330 gpinfop
->got12
.tmin
,
5332 gpinfop
->got12
.tmax
,
5336 - gpinfop
->got12
.fdplt
,
5339 - gpinfop
->got12
.tlsdplt
,
5340 (bfd_vma
)1 << (16-1));
5341 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->gothilo
,
5342 gpinfop
->gotlos
.tmin
,
5344 gpinfop
->gotlos
.tmax
,
5348 - gpinfop
->got12
.fdplt
5349 - gpinfop
->gotlos
.fdplt
,
5350 gpinfop
->g
.tlsdhilo
,
5352 - gpinfop
->got12
.tlsdplt
5353 - gpinfop
->gotlos
.tlsdplt
,
5354 (bfd_vma
)1 << (32-1));
5356 /* Now assign (most) GOT offsets. */
5357 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_assign_got_entries
,
5360 frvfdpic_got_section (info
)->size
= gpinfop
->gothilo
.tmax
5361 - gpinfop
->gothilo
.tmin
5362 /* If an odd word is the last word of the GOT, we don't need this
5363 word to be part of the GOT. */
5364 - (odd
+ 4 == gpinfop
->gothilo
.tmax
? 4 : 0);
5365 if (frvfdpic_got_section (info
)->size
== 0)
5366 frvfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
5367 else if (frvfdpic_got_section (info
)->size
== 12
5368 && ! elf_hash_table (info
)->dynamic_sections_created
)
5370 frvfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
5371 frvfdpic_got_section (info
)->size
= 0;
5373 /* This will be non-NULL during relaxation. The assumption is that
5374 the size of one of these sections will never grow, only shrink,
5375 so we can use the larger buffer we allocated before. */
5376 else if (frvfdpic_got_section (info
)->contents
== NULL
)
5378 frvfdpic_got_section (info
)->contents
=
5379 (bfd_byte
*) bfd_zalloc (dynobj
,
5380 frvfdpic_got_section (info
)->size
);
5381 if (frvfdpic_got_section (info
)->contents
== NULL
)
5385 if (frvfdpic_gotrel_section (info
))
5386 /* Subtract the number of lzplt entries, since those will generate
5387 relocations in the pltrel section. */
5388 frvfdpic_gotrel_section (info
)->size
=
5389 (gpinfop
->g
.relocs
- gpinfop
->g
.lzplt
/ 8)
5390 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
5392 BFD_ASSERT (gpinfop
->g
.relocs
== 0);
5393 if (frvfdpic_gotrel_section (info
)->size
== 0)
5394 frvfdpic_gotrel_section (info
)->flags
|= SEC_EXCLUDE
;
5395 else if (frvfdpic_gotrel_section (info
)->contents
== NULL
)
5397 frvfdpic_gotrel_section (info
)->contents
=
5398 (bfd_byte
*) bfd_zalloc (dynobj
,
5399 frvfdpic_gotrel_section (info
)->size
);
5400 if (frvfdpic_gotrel_section (info
)->contents
== NULL
)
5404 frvfdpic_gotfixup_section (info
)->size
= (gpinfop
->g
.fixups
+ 1) * 4;
5405 if (frvfdpic_gotfixup_section (info
)->size
== 0)
5406 frvfdpic_gotfixup_section (info
)->flags
|= SEC_EXCLUDE
;
5407 else if (frvfdpic_gotfixup_section (info
)->contents
== NULL
)
5409 frvfdpic_gotfixup_section (info
)->contents
=
5410 (bfd_byte
*) bfd_zalloc (dynobj
,
5411 frvfdpic_gotfixup_section (info
)->size
);
5412 if (frvfdpic_gotfixup_section (info
)->contents
== NULL
)
5416 if (frvfdpic_pltrel_section (info
))
5418 frvfdpic_pltrel_section (info
)->size
=
5419 gpinfop
->g
.lzplt
/ 8
5420 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
5421 if (frvfdpic_pltrel_section (info
)->size
== 0)
5422 frvfdpic_pltrel_section (info
)->flags
|= SEC_EXCLUDE
;
5423 else if (frvfdpic_pltrel_section (info
)->contents
== NULL
)
5425 frvfdpic_pltrel_section (info
)->contents
=
5426 (bfd_byte
*) bfd_zalloc (dynobj
,
5427 frvfdpic_pltrel_section (info
)->size
);
5428 if (frvfdpic_pltrel_section (info
)->contents
== NULL
)
5433 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
5434 such that there's room for the additional instruction needed to
5435 call the resolver. Since _frvfdpic_assign_got_entries didn't
5436 account for them, our block size is 4 bytes smaller than the real
5438 if (frvfdpic_plt_section (info
))
5440 frvfdpic_plt_section (info
)->size
= gpinfop
->g
.lzplt
5441 + ((gpinfop
->g
.lzplt
+ (FRVFDPIC_LZPLT_BLOCK_SIZE
- 4) - 8)
5442 / (FRVFDPIC_LZPLT_BLOCK_SIZE
- 4) * 4);
5445 /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to
5446 actually assign lazy PLT entries addresses. */
5447 gpinfop
->g
.lzplt
= 0;
5449 /* Save information that we're going to need to generate GOT and PLT
5451 frvfdpic_got_initial_offset (info
) = -gpinfop
->gothilo
.tmin
;
5453 if (get_elf_backend_data (output_bfd
)->want_got_sym
)
5454 elf_hash_table (info
)->hgot
->root
.u
.def
.value
5455 = frvfdpic_got_initial_offset (info
);
5457 if (frvfdpic_plt_section (info
))
5458 frvfdpic_plt_initial_offset (info
) =
5459 frvfdpic_plt_section (info
)->size
;
5461 /* Allocate a ret statement at plt_initial_offset, to be used by
5462 locally-resolved TLS descriptors. */
5463 if (gpinfop
->g
.tls_ret_refs
)
5464 frvfdpic_plt_section (info
)->size
+= 4;
5466 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_assign_plt_entries
,
5469 /* Allocate the PLT section contents only after
5470 _frvfdpic_assign_plt_entries has a chance to add the size of the
5471 non-lazy PLT entries. */
5472 if (frvfdpic_plt_section (info
))
5474 if (frvfdpic_plt_section (info
)->size
== 0)
5475 frvfdpic_plt_section (info
)->flags
|= SEC_EXCLUDE
;
5476 else if (frvfdpic_plt_section (info
)->contents
== NULL
)
5478 frvfdpic_plt_section (info
)->contents
=
5479 (bfd_byte
*) bfd_zalloc (dynobj
,
5480 frvfdpic_plt_section (info
)->size
);
5481 if (frvfdpic_plt_section (info
)->contents
== NULL
)
5489 /* Set the sizes of the dynamic sections. */
5492 elf32_frvfdpic_size_dynamic_sections (bfd
*output_bfd
,
5493 struct bfd_link_info
*info
)
5497 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5499 dynobj
= elf_hash_table (info
)->dynobj
;
5500 BFD_ASSERT (dynobj
!= NULL
);
5502 if (elf_hash_table (info
)->dynamic_sections_created
)
5504 /* Set the contents of the .interp section to the interpreter. */
5505 if (info
->executable
)
5507 s
= bfd_get_section_by_name (dynobj
, ".interp");
5508 BFD_ASSERT (s
!= NULL
);
5509 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5510 s
->contents
= (bfd_byte
*) ELF_DYNAMIC_INTERPRETER
;
5514 memset (&gpinfo
, 0, sizeof (gpinfo
));
5515 gpinfo
.g
.info
= info
;
5519 htab_t relocs
= frvfdpic_relocs_info (info
);
5521 htab_traverse (relocs
, _frvfdpic_resolve_final_relocs_info
, &relocs
);
5523 if (relocs
== frvfdpic_relocs_info (info
))
5527 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_count_got_plt_entries
,
5530 /* Allocate space to save the summary information, we're going to
5531 use it if we're doing relaxations. */
5532 frvfdpic_dynamic_got_plt_info (info
) = bfd_alloc (dynobj
, sizeof (gpinfo
.g
));
5534 if (!_frvfdpic_size_got_plt (output_bfd
, &gpinfo
))
5537 if (elf_hash_table (info
)->dynamic_sections_created
)
5539 if (frvfdpic_got_section (info
)->size
)
5540 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTGOT
, 0))
5543 if (frvfdpic_pltrel_section (info
)->size
)
5544 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
5545 || !_bfd_elf_add_dynamic_entry (info
, DT_PLTREL
, DT_REL
)
5546 || !_bfd_elf_add_dynamic_entry (info
, DT_JMPREL
, 0))
5549 if (frvfdpic_gotrel_section (info
)->size
)
5550 if (!_bfd_elf_add_dynamic_entry (info
, DT_REL
, 0)
5551 || !_bfd_elf_add_dynamic_entry (info
, DT_RELSZ
, 0)
5552 || !_bfd_elf_add_dynamic_entry (info
, DT_RELENT
,
5553 sizeof (Elf32_External_Rel
)))
5561 elf32_frvfdpic_always_size_sections (bfd
*output_bfd
,
5562 struct bfd_link_info
*info
)
5564 if (!info
->relocatable
)
5566 struct elf_link_hash_entry
*h
;
5568 /* Force a PT_GNU_STACK segment to be created. */
5569 if (! elf_tdata (output_bfd
)->stack_flags
)
5570 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
| PF_X
;
5572 /* Define __stacksize if it's not defined yet. */
5573 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
5574 FALSE
, FALSE
, FALSE
);
5575 if (! h
|| h
->root
.type
!= bfd_link_hash_defined
5576 || h
->type
!= STT_OBJECT
5579 struct bfd_link_hash_entry
*bh
= NULL
;
5581 if (!(_bfd_generic_link_add_one_symbol
5582 (info
, output_bfd
, "__stacksize",
5583 BSF_GLOBAL
, bfd_abs_section_ptr
, DEFAULT_STACK_SIZE
,
5584 (const char *) NULL
, FALSE
,
5585 get_elf_backend_data (output_bfd
)->collect
, &bh
)))
5588 h
= (struct elf_link_hash_entry
*) bh
;
5590 h
->type
= STT_OBJECT
;
5591 /* This one must NOT be hidden. */
5598 /* Check whether any of the relocations was optimized away, and
5599 subtract it from the relocation or fixup count. */
5601 _frvfdpic_check_discarded_relocs (bfd
*abfd
, asection
*sec
,
5602 struct bfd_link_info
*info
,
5604 bfd_boolean
*changed
)
5606 Elf_Internal_Shdr
*symtab_hdr
;
5607 struct elf_link_hash_entry
**sym_hashes
;
5608 Elf_Internal_Rela
*rel
, *erel
;
5610 if ((sec
->flags
& SEC_RELOC
) == 0
5611 || sec
->reloc_count
== 0)
5614 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5615 sym_hashes
= elf_sym_hashes (abfd
);
5617 rel
= elf_section_data (sec
)->relocs
;
5619 /* Now examine each relocation. */
5620 for (erel
= rel
+ sec
->reloc_count
; rel
< erel
; rel
++)
5622 struct elf_link_hash_entry
*h
;
5623 unsigned long r_symndx
;
5624 struct frvfdpic_relocs_info
*picrel
;
5625 struct _frvfdpic_dynamic_got_info
*dinfo
;
5627 if (ELF32_R_TYPE (rel
->r_info
) != R_FRV_32
5628 && ELF32_R_TYPE (rel
->r_info
) != R_FRV_FUNCDESC
)
5631 if (_bfd_elf_section_offset (sec
->output_section
->owner
,
5632 info
, sec
, rel
->r_offset
)
5636 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5637 if (r_symndx
< symtab_hdr
->sh_info
)
5641 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5642 while (h
->root
.type
== bfd_link_hash_indirect
5643 || h
->root
.type
== bfd_link_hash_warning
)
5644 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
5648 picrel
= frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info
),
5650 rel
->r_addend
, NO_INSERT
);
5652 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info (info
),
5654 rel
->r_addend
, NO_INSERT
);
5660 dinfo
= frvfdpic_dynamic_got_plt_info (info
);
5662 _frvfdpic_count_relocs_fixups (picrel
, dinfo
, TRUE
);
5663 if (ELF32_R_TYPE (rel
->r_info
) == R_FRV_32
)
5665 else /* we know (ELF32_R_TYPE (rel->r_info) == R_FRV_FUNCDESC) */
5667 _frvfdpic_count_relocs_fixups (picrel
, dinfo
, FALSE
);
5674 frvfdpic_elf_discard_info (bfd
*ibfd
,
5675 struct elf_reloc_cookie
*cookie ATTRIBUTE_UNUSED
,
5676 struct bfd_link_info
*info
)
5678 bfd_boolean changed
= FALSE
;
5682 /* Account for relaxation of .eh_frame section. */
5683 for (s
= ibfd
->sections
; s
; s
= s
->next
)
5684 if (s
->sec_info_type
== ELF_INFO_TYPE_EH_FRAME
)
5686 if (!_frvfdpic_check_discarded_relocs (ibfd
, s
, info
, &changed
))
5688 obfd
= s
->output_section
->owner
;
5693 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5695 memset (&gpinfo
, 0, sizeof (gpinfo
));
5696 memcpy (&gpinfo
.g
, frvfdpic_dynamic_got_plt_info (info
),
5699 /* Clear GOT and PLT assignments. */
5700 htab_traverse (frvfdpic_relocs_info (info
),
5701 _frvfdpic_reset_got_plt_entries
,
5704 if (!_frvfdpic_size_got_plt (obfd
, &gpinfo
))
5711 /* Look for opportunities to relax TLS relocations. We can assume
5712 we're linking the main executable or a static-tls library, since
5713 otherwise we wouldn't have got here. */
5716 _frvfdpic_relax_got_plt_entries (void **entryp
, void *dinfo_
)
5718 struct frvfdpic_relocs_info
*entry
= *entryp
;
5719 struct _frvfdpic_dynamic_got_info
*dinfo
= dinfo_
;
5721 _frvfdpic_relax_tls_entries (entry
, dinfo
, TRUE
);
5727 elf32_frvfdpic_relax_section (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
,
5728 struct bfd_link_info
*info
, bfd_boolean
*again
)
5730 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5732 if (info
->relocatable
)
5733 (*info
->callbacks
->einfo
)
5734 (_("%P%F: --relax and -r may not be used together\n"));
5736 /* If we return early, we didn't change anything. */
5739 /* We'll do our thing when requested to relax the GOT section. */
5740 if (sec
!= frvfdpic_got_section (info
))
5743 /* We can only relax when linking the main executable or a library
5744 that can't be dlopened. */
5745 if (! info
->executable
&& ! (info
->flags
& DF_STATIC_TLS
))
5748 /* If there isn't a TLS section for this binary, we can't do
5749 anything about its TLS relocations (it probably doesn't have
5751 if (elf_hash_table (info
)->tls_sec
== NULL
)
5754 memset (&gpinfo
, 0, sizeof (gpinfo
));
5755 memcpy (&gpinfo
.g
, frvfdpic_dynamic_got_plt_info (info
), sizeof (gpinfo
.g
));
5757 /* Now look for opportunities to relax, adjusting the GOT usage
5759 htab_traverse (frvfdpic_relocs_info (info
),
5760 _frvfdpic_relax_got_plt_entries
,
5763 /* If we changed anything, reset and re-assign GOT and PLT entries. */
5764 if (memcmp (frvfdpic_dynamic_got_plt_info (info
),
5765 &gpinfo
.g
, sizeof (gpinfo
.g
)) != 0)
5767 /* Clear GOT and PLT assignments. */
5768 htab_traverse (frvfdpic_relocs_info (info
),
5769 _frvfdpic_reset_got_plt_entries
,
5772 /* The owner of the TLS section is the output bfd. There should
5773 be a better way to get to it. */
5774 if (!_frvfdpic_size_got_plt (elf_hash_table (info
)->tls_sec
->owner
,
5778 /* Repeat until we don't make any further changes. We could fail to
5779 introduce changes in a round if, for example, the 12-bit range is
5780 full, but we later release some space by getting rid of TLS
5781 descriptors in it. We have to repeat the whole process because
5782 we might have changed the size of a section processed before this
5791 elf32_frvfdpic_modify_program_headers (bfd
*output_bfd
,
5792 struct bfd_link_info
*info
)
5794 struct elf_obj_tdata
*tdata
= elf_tdata (output_bfd
);
5795 struct elf_segment_map
*m
;
5796 Elf_Internal_Phdr
*p
;
5798 /* objcopy and strip preserve what's already there using
5799 elf32_frvfdpic_copy_private_bfd_data (). */
5803 for (p
= tdata
->phdr
, m
= tdata
->segment_map
; m
!= NULL
; m
= m
->next
, p
++)
5804 if (m
->p_type
== PT_GNU_STACK
)
5809 struct elf_link_hash_entry
*h
;
5811 /* Obtain the pointer to the __stacksize symbol. */
5812 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
5813 FALSE
, FALSE
, FALSE
);
5816 while (h
->root
.type
== bfd_link_hash_indirect
5817 || h
->root
.type
== bfd_link_hash_warning
)
5818 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5819 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
5822 /* Set the header p_memsz from the symbol value. We
5823 intentionally ignore the symbol section. */
5824 if (h
&& h
->root
.type
== bfd_link_hash_defined
)
5825 p
->p_memsz
= h
->root
.u
.def
.value
;
5827 p
->p_memsz
= DEFAULT_STACK_SIZE
;
5835 /* Fill in code and data in dynamic sections. */
5838 elf32_frv_finish_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5839 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
5841 /* Nothing to be done for non-FDPIC. */
5846 elf32_frvfdpic_finish_dynamic_sections (bfd
*output_bfd
,
5847 struct bfd_link_info
*info
)
5852 dynobj
= elf_hash_table (info
)->dynobj
;
5854 if (frvfdpic_dynamic_got_plt_info (info
))
5856 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
== 0);
5858 if (frvfdpic_got_section (info
))
5860 BFD_ASSERT (frvfdpic_gotrel_section (info
)->size
5861 == (frvfdpic_gotrel_section (info
)->reloc_count
5862 * sizeof (Elf32_External_Rel
)));
5864 if (frvfdpic_gotfixup_section (info
))
5866 struct elf_link_hash_entry
*hgot
= elf_hash_table (info
)->hgot
;
5867 bfd_vma got_value
= hgot
->root
.u
.def
.value
5868 + hgot
->root
.u
.def
.section
->output_section
->vma
5869 + hgot
->root
.u
.def
.section
->output_offset
;
5870 struct bfd_link_hash_entry
*hend
;
5872 _frvfdpic_add_rofixup (output_bfd
, frvfdpic_gotfixup_section (info
),
5875 if (frvfdpic_gotfixup_section (info
)->size
5876 != (frvfdpic_gotfixup_section (info
)->reloc_count
* 4))
5879 info
->callbacks
->einfo
5880 ("LINKER BUG: .rofixup section size mismatch\n");
5884 hend
= bfd_link_hash_lookup (info
->hash
, "__ROFIXUP_END__",
5885 FALSE
, FALSE
, TRUE
);
5887 && (hend
->type
== bfd_link_hash_defined
5888 || hend
->type
== bfd_link_hash_defweak
)
5889 && hend
->u
.def
.section
->output_section
!= NULL
)
5892 frvfdpic_gotfixup_section (info
)->output_section
->vma
5893 + frvfdpic_gotfixup_section (info
)->output_offset
5894 + frvfdpic_gotfixup_section (info
)->size
5895 - hend
->u
.def
.section
->output_section
->vma
5896 - hend
->u
.def
.section
->output_offset
;
5897 BFD_ASSERT (hend
->u
.def
.value
== value
);
5898 if (hend
->u
.def
.value
!= value
)
5903 if (frvfdpic_pltrel_section (info
))
5905 BFD_ASSERT (frvfdpic_pltrel_section (info
)->size
5906 == (frvfdpic_pltrel_section (info
)->reloc_count
5907 * sizeof (Elf32_External_Rel
)));
5911 if (elf_hash_table (info
)->dynamic_sections_created
)
5913 Elf32_External_Dyn
* dyncon
;
5914 Elf32_External_Dyn
* dynconend
;
5916 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5918 BFD_ASSERT (sdyn
!= NULL
);
5920 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5921 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5923 for (; dyncon
< dynconend
; dyncon
++)
5925 Elf_Internal_Dyn dyn
;
5927 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5935 dyn
.d_un
.d_ptr
= frvfdpic_got_section (info
)->output_section
->vma
5936 + frvfdpic_got_section (info
)->output_offset
5937 + frvfdpic_got_initial_offset (info
);
5938 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5942 dyn
.d_un
.d_ptr
= frvfdpic_pltrel_section (info
)
5943 ->output_section
->vma
5944 + frvfdpic_pltrel_section (info
)->output_offset
;
5945 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5949 dyn
.d_un
.d_val
= frvfdpic_pltrel_section (info
)->size
;
5950 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5959 /* Adjust a symbol defined by a dynamic object and referenced by a
5963 elf32_frvfdpic_adjust_dynamic_symbol
5964 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5965 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
5969 dynobj
= elf_hash_table (info
)->dynobj
;
5971 /* Make sure we know what is going on here. */
5972 BFD_ASSERT (dynobj
!= NULL
5973 && (h
->u
.weakdef
!= NULL
5976 && !h
->def_regular
)));
5978 /* If this is a weak symbol, and there is a real definition, the
5979 processor independent code will have arranged for us to see the
5980 real definition first, and we can just use the same value. */
5981 if (h
->u
.weakdef
!= NULL
)
5983 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
5984 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
5985 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
5986 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
5992 /* Perform any actions needed for dynamic symbols. */
5995 elf32_frvfdpic_finish_dynamic_symbol
5996 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5997 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5998 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
,
5999 Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
)
6004 /* Decide whether to attempt to turn absptr or lsda encodings in
6005 shared libraries into pcrel within the given input section. */
6008 frvfdpic_elf_use_relative_eh_frame
6009 (bfd
*input_bfd ATTRIBUTE_UNUSED
,
6010 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6011 asection
*eh_frame_section ATTRIBUTE_UNUSED
)
6013 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
6017 /* Adjust the contents of an eh_frame_hdr section before they're output. */
6020 frvfdpic_elf_encode_eh_address (bfd
*abfd
,
6021 struct bfd_link_info
*info
,
6022 asection
*osec
, bfd_vma offset
,
6023 asection
*loc_sec
, bfd_vma loc_offset
,
6026 struct elf_link_hash_entry
*h
;
6028 h
= elf_hash_table (info
)->hgot
;
6029 BFD_ASSERT (h
&& h
->root
.type
== bfd_link_hash_defined
);
6031 if (! h
|| (_frvfdpic_osec_to_segment (abfd
, osec
)
6032 == _frvfdpic_osec_to_segment (abfd
, loc_sec
->output_section
)))
6033 return _bfd_elf_encode_eh_address (abfd
, info
, osec
, offset
,
6034 loc_sec
, loc_offset
, encoded
);
6036 BFD_ASSERT (_frvfdpic_osec_to_segment (abfd
, osec
)
6037 == (_frvfdpic_osec_to_segment
6038 (abfd
, h
->root
.u
.def
.section
->output_section
)));
6040 *encoded
= osec
->vma
+ offset
6041 - (h
->root
.u
.def
.value
6042 + h
->root
.u
.def
.section
->output_section
->vma
6043 + h
->root
.u
.def
.section
->output_offset
);
6045 return DW_EH_PE_datarel
| DW_EH_PE_sdata4
;
6048 /* Look through the relocs for a section during the first phase.
6050 Besides handling virtual table relocs for gc, we have to deal with
6051 all sorts of PIC-related relocations. We describe below the
6052 general plan on how to handle such relocations, even though we only
6053 collect information at this point, storing them in hash tables for
6054 perusal of later passes.
6056 32 relocations are propagated to the linker output when creating
6057 position-independent output. LO16 and HI16 relocations are not
6058 supposed to be encountered in this case.
6060 LABEL16 should always be resolvable by the linker, since it's only
6063 LABEL24, on the other hand, is used by calls. If it turns out that
6064 the target of a call is a dynamic symbol, a PLT entry must be
6065 created for it, which triggers the creation of a private function
6066 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
6068 GPREL relocations require the referenced symbol to be in the same
6069 segment as _gp, but this can only be checked later.
6071 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
6072 exist. LABEL24 might as well, since it may require a PLT entry,
6073 that will require a got.
6075 Non-FUNCDESC GOT relocations require a GOT entry to be created
6076 regardless of whether the symbol is dynamic. However, since a
6077 global symbol that turns out to not be exported may have the same
6078 address of a non-dynamic symbol, we don't assign GOT entries at
6079 this point, such that we can share them in this case. A relocation
6080 for the GOT entry always has to be created, be it to offset a
6081 private symbol by the section load address, be it to get the symbol
6082 resolved dynamically.
6084 FUNCDESC GOT relocations require a GOT entry to be created, and
6085 handled as if a FUNCDESC relocation was applied to the GOT entry in
6088 FUNCDESC relocations referencing a symbol that turns out to NOT be
6089 dynamic cause a private function descriptor to be created. The
6090 FUNCDESC relocation then decays to a 32 relocation that points at
6091 the private descriptor. If the symbol is dynamic, the FUNCDESC
6092 relocation is propagated to the linker output, such that the
6093 dynamic linker creates the canonical descriptor, pointing to the
6094 dynamically-resolved definition of the function.
6096 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
6097 symbols that are assigned to the same segment as the GOT, but we
6098 can only check this later, after we know the complete set of
6099 symbols defined and/or exported.
6101 FUNCDESC GOTOFF relocations require a function descriptor to be
6102 created and, unless lazy binding is disabled or the symbol is not
6103 dynamic, a lazy PLT entry. Since we can't tell at this point
6104 whether a symbol is going to be dynamic, we have to decide later
6105 whether to create a lazy PLT entry or bind the descriptor directly
6106 to the private function.
6108 FUNCDESC_VALUE relocations are not supposed to be present in object
6109 files, but they may very well be simply propagated to the linker
6110 output, since they have no side effect.
6113 A function descriptor always requires a FUNCDESC_VALUE relocation.
6114 Whether it's in .plt.rel or not depends on whether lazy binding is
6115 enabled and on whether the referenced symbol is dynamic.
6117 The existence of a lazy PLT requires the resolverStub lazy PLT
6118 entry to be present.
6121 As for assignment of GOT, PLT and lazy PLT entries, and private
6122 descriptors, we might do them all sequentially, but we can do
6123 better than that. For example, we can place GOT entries and
6124 private function descriptors referenced using 12-bit operands
6125 closer to the PIC register value, such that these relocations don't
6126 overflow. Those that are only referenced with LO16 relocations
6127 could come next, but we may as well place PLT-required function
6128 descriptors in the 12-bit range to make them shorter. Symbols
6129 referenced with LO16/HI16 may come next, but we may place
6130 additional function descriptors in the 16-bit range if we can
6131 reliably tell that we've already placed entries that are ever
6132 referenced with only LO16. PLT entries are therefore generated as
6133 small as possible, while not introducing relocation overflows in
6134 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
6135 generated before or after PLT entries, but not intermingled with
6136 them, such that we can have more lazy PLT entries in range for a
6137 branch to the resolverStub. The resolverStub should be emitted at
6138 the most distant location from the first lazy PLT entry such that
6139 it's still in range for a branch, or closer, if there isn't a need
6140 for so many lazy PLT entries. Additional lazy PLT entries may be
6141 emitted after the resolverStub, as long as branches are still in
6142 range. If the branch goes out of range, longer lazy PLT entries
6145 We could further optimize PLT and lazy PLT entries by giving them
6146 priority in assignment to closer-to-gr17 locations depending on the
6147 number of occurrences of references to them (assuming a function
6148 that's called more often is more important for performance, so its
6149 PLT entry should be faster), or taking hints from the compiler.
6150 Given infinite time and money... :-) */
6153 elf32_frv_check_relocs (abfd
, info
, sec
, relocs
)
6155 struct bfd_link_info
*info
;
6157 const Elf_Internal_Rela
*relocs
;
6159 Elf_Internal_Shdr
*symtab_hdr
;
6160 struct elf_link_hash_entry
**sym_hashes
;
6161 const Elf_Internal_Rela
*rel
;
6162 const Elf_Internal_Rela
*rel_end
;
6164 struct frvfdpic_relocs_info
*picrel
;
6166 if (info
->relocatable
)
6169 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6170 sym_hashes
= elf_sym_hashes (abfd
);
6172 dynobj
= elf_hash_table (info
)->dynobj
;
6173 rel_end
= relocs
+ sec
->reloc_count
;
6174 for (rel
= relocs
; rel
< rel_end
; rel
++)
6176 struct elf_link_hash_entry
*h
;
6177 unsigned long r_symndx
;
6179 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6180 if (r_symndx
< symtab_hdr
->sh_info
)
6184 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6185 while (h
->root
.type
== bfd_link_hash_indirect
6186 || h
->root
.type
== bfd_link_hash_warning
)
6187 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6190 switch (ELF32_R_TYPE (rel
->r_info
))
6192 case R_FRV_GETTLSOFF
:
6193 case R_FRV_TLSDESC_VALUE
:
6194 case R_FRV_GOTTLSDESC12
:
6195 case R_FRV_GOTTLSDESCHI
:
6196 case R_FRV_GOTTLSDESCLO
:
6197 case R_FRV_GOTTLSOFF12
:
6198 case R_FRV_GOTTLSOFFHI
:
6199 case R_FRV_GOTTLSOFFLO
:
6204 case R_FRV_FUNCDESC_GOT12
:
6205 case R_FRV_FUNCDESC_GOTHI
:
6206 case R_FRV_FUNCDESC_GOTLO
:
6207 case R_FRV_GOTOFF12
:
6208 case R_FRV_GOTOFFHI
:
6209 case R_FRV_GOTOFFLO
:
6210 case R_FRV_FUNCDESC_GOTOFF12
:
6211 case R_FRV_FUNCDESC_GOTOFFHI
:
6212 case R_FRV_FUNCDESC_GOTOFFLO
:
6213 case R_FRV_FUNCDESC
:
6214 case R_FRV_FUNCDESC_VALUE
:
6215 case R_FRV_TLSMOFF12
:
6216 case R_FRV_TLSMOFFHI
:
6217 case R_FRV_TLSMOFFLO
:
6219 if (! IS_FDPIC (abfd
))
6223 case R_FRV_GPRELU12
:
6230 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6231 if (! _frv_create_got_section (abfd
, info
))
6234 if (! IS_FDPIC (abfd
))
6241 if (h
->dynindx
== -1)
6242 switch (ELF_ST_VISIBILITY (h
->other
))
6248 bfd_elf_link_record_dynamic_symbol (info
, h
);
6252 = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info
),
6254 rel
->r_addend
, INSERT
);
6257 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
6258 (info
), abfd
, r_symndx
,
6259 rel
->r_addend
, INSERT
);
6269 switch (ELF32_R_TYPE (rel
->r_info
))
6272 if (IS_FDPIC (abfd
))
6276 case R_FRV_FUNCDESC_VALUE
:
6277 picrel
->relocsfdv
++;
6278 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
6283 if (! IS_FDPIC (abfd
))
6287 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
6297 picrel
->gothilo
= 1;
6300 case R_FRV_FUNCDESC_GOT12
:
6301 picrel
->fdgot12
= 1;
6304 case R_FRV_FUNCDESC_GOTHI
:
6305 case R_FRV_FUNCDESC_GOTLO
:
6306 picrel
->fdgothilo
= 1;
6309 case R_FRV_GOTOFF12
:
6310 case R_FRV_GOTOFFHI
:
6311 case R_FRV_GOTOFFLO
:
6315 case R_FRV_FUNCDESC_GOTOFF12
:
6316 picrel
->fdgoff12
= 1;
6319 case R_FRV_FUNCDESC_GOTOFFHI
:
6320 case R_FRV_FUNCDESC_GOTOFFLO
:
6321 picrel
->fdgoffhilo
= 1;
6324 case R_FRV_FUNCDESC
:
6329 case R_FRV_GETTLSOFF
:
6333 case R_FRV_TLSDESC_VALUE
:
6334 picrel
->relocstlsd
++;
6337 case R_FRV_GOTTLSDESC12
:
6338 picrel
->tlsdesc12
= 1;
6341 case R_FRV_GOTTLSDESCHI
:
6342 case R_FRV_GOTTLSDESCLO
:
6343 picrel
->tlsdeschilo
= 1;
6346 case R_FRV_TLSMOFF12
:
6347 case R_FRV_TLSMOFFHI
:
6348 case R_FRV_TLSMOFFLO
:
6352 case R_FRV_GOTTLSOFF12
:
6353 picrel
->tlsoff12
= 1;
6354 info
->flags
|= DF_STATIC_TLS
;
6357 case R_FRV_GOTTLSOFFHI
:
6358 case R_FRV_GOTTLSOFFLO
:
6359 picrel
->tlsoffhilo
= 1;
6360 info
->flags
|= DF_STATIC_TLS
;
6364 picrel
->relocstlsoff
++;
6365 info
->flags
|= DF_STATIC_TLS
;
6368 /* This relocation describes the C++ object vtable hierarchy.
6369 Reconstruct it for later use during GC. */
6370 case R_FRV_GNU_VTINHERIT
:
6371 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6375 /* This relocation describes which C++ vtable entries are actually
6376 used. Record for later use during GC. */
6377 case R_FRV_GNU_VTENTRY
:
6378 BFD_ASSERT (h
!= NULL
);
6380 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
6388 case R_FRV_GPRELU12
:
6392 case R_FRV_TLSDESC_RELAX
:
6393 case R_FRV_GETTLSOFF_RELAX
:
6394 case R_FRV_TLSOFF_RELAX
:
6399 info
->callbacks
->einfo
6400 (_("%B: unsupported relocation type %i\n"),
6401 abfd
, ELF32_R_TYPE (rel
->r_info
));
6410 /* Return the machine subcode from the ELF e_flags header. */
6413 elf32_frv_machine (abfd
)
6416 switch (elf_elfheader (abfd
)->e_flags
& EF_FRV_CPU_MASK
)
6419 case EF_FRV_CPU_FR550
: return bfd_mach_fr550
;
6420 case EF_FRV_CPU_FR500
: return bfd_mach_fr500
;
6421 case EF_FRV_CPU_FR450
: return bfd_mach_fr450
;
6422 case EF_FRV_CPU_FR405
: return bfd_mach_fr400
;
6423 case EF_FRV_CPU_FR400
: return bfd_mach_fr400
;
6424 case EF_FRV_CPU_FR300
: return bfd_mach_fr300
;
6425 case EF_FRV_CPU_SIMPLE
: return bfd_mach_frvsimple
;
6426 case EF_FRV_CPU_TOMCAT
: return bfd_mach_frvtomcat
;
6429 return bfd_mach_frv
;
6432 /* Set the right machine number for a FRV ELF file. */
6435 elf32_frv_object_p (abfd
)
6438 bfd_default_set_arch_mach (abfd
, bfd_arch_frv
, elf32_frv_machine (abfd
));
6439 return (((elf_elfheader (abfd
)->e_flags
& EF_FRV_FDPIC
) != 0)
6440 == (IS_FDPIC (abfd
)));
6443 /* Function to set the ELF flag bits. */
6446 frv_elf_set_private_flags (abfd
, flags
)
6450 elf_elfheader (abfd
)->e_flags
= flags
;
6451 elf_flags_init (abfd
) = TRUE
;
6455 /* Copy backend specific data from one object module to another. */
6458 frv_elf_copy_private_bfd_data (ibfd
, obfd
)
6462 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6463 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6466 BFD_ASSERT (!elf_flags_init (obfd
)
6467 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
6469 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
6470 elf_flags_init (obfd
) = TRUE
;
6472 /* Copy object attributes. */
6473 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
6478 /* Return true if the architecture described by elf header flag
6479 EXTENSION is an extension of the architecture described by BASE. */
6482 frv_elf_arch_extension_p (flagword base
, flagword extension
)
6484 if (base
== extension
)
6487 /* CPU_GENERIC code can be merged with code for a specific
6488 architecture, in which case the result is marked as being
6489 for the specific architecture. Everything is therefore
6490 an extension of CPU_GENERIC. */
6491 if (base
== EF_FRV_CPU_GENERIC
)
6494 if (extension
== EF_FRV_CPU_FR450
)
6495 if (base
== EF_FRV_CPU_FR400
|| base
== EF_FRV_CPU_FR405
)
6498 if (extension
== EF_FRV_CPU_FR405
)
6499 if (base
== EF_FRV_CPU_FR400
)
6506 elf32_frvfdpic_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
6510 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6511 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6514 if (! frv_elf_copy_private_bfd_data (ibfd
, obfd
))
6517 if (! elf_tdata (ibfd
) || ! elf_tdata (ibfd
)->phdr
6518 || ! elf_tdata (obfd
) || ! elf_tdata (obfd
)->phdr
)
6521 /* Copy the stack size. */
6522 for (i
= 0; i
< elf_elfheader (ibfd
)->e_phnum
; i
++)
6523 if (elf_tdata (ibfd
)->phdr
[i
].p_type
== PT_GNU_STACK
)
6525 Elf_Internal_Phdr
*iphdr
= &elf_tdata (ibfd
)->phdr
[i
];
6527 for (i
= 0; i
< elf_elfheader (obfd
)->e_phnum
; i
++)
6528 if (elf_tdata (obfd
)->phdr
[i
].p_type
== PT_GNU_STACK
)
6530 memcpy (&elf_tdata (obfd
)->phdr
[i
], iphdr
, sizeof (*iphdr
));
6532 /* Rewrite the phdrs, since we're only called after they
6533 were first written. */
6534 if (bfd_seek (obfd
, (bfd_signed_vma
) get_elf_backend_data (obfd
)
6535 ->s
->sizeof_ehdr
, SEEK_SET
) != 0
6536 || get_elf_backend_data (obfd
)->s
6537 ->write_out_phdrs (obfd
, elf_tdata (obfd
)->phdr
,
6538 elf_elfheader (obfd
)->e_phnum
) != 0)
6549 /* Merge backend specific data from an object file to the output
6550 object file when linking. */
6553 frv_elf_merge_private_bfd_data (ibfd
, obfd
)
6557 flagword old_flags
, old_partial
;
6558 flagword new_flags
, new_partial
;
6559 bfd_boolean error
= FALSE
;
6563 new_opt
[0] = old_opt
[0] = '\0';
6564 new_flags
= elf_elfheader (ibfd
)->e_flags
;
6565 old_flags
= elf_elfheader (obfd
)->e_flags
;
6567 if (new_flags
& EF_FRV_FDPIC
)
6568 new_flags
&= ~EF_FRV_PIC
;
6571 (*_bfd_error_handler
) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s",
6572 old_flags
, new_flags
, elf_flags_init (obfd
) ? "yes" : "no",
6573 bfd_get_filename (ibfd
));
6576 if (!elf_flags_init (obfd
)) /* First call, no flags set. */
6578 elf_flags_init (obfd
) = TRUE
;
6579 old_flags
= new_flags
;
6582 else if (new_flags
== old_flags
) /* Compatible flags are ok. */
6585 else /* Possibly incompatible flags. */
6587 /* Warn if different # of gprs are used. Note, 0 means nothing is
6588 said about the size of gprs. */
6589 new_partial
= (new_flags
& EF_FRV_GPR_MASK
);
6590 old_partial
= (old_flags
& EF_FRV_GPR_MASK
);
6591 if (new_partial
== old_partial
)
6594 else if (new_partial
== 0)
6597 else if (old_partial
== 0)
6598 old_flags
|= new_partial
;
6602 switch (new_partial
)
6604 default: strcat (new_opt
, " -mgpr-??"); break;
6605 case EF_FRV_GPR_32
: strcat (new_opt
, " -mgpr-32"); break;
6606 case EF_FRV_GPR_64
: strcat (new_opt
, " -mgpr-64"); break;
6609 switch (old_partial
)
6611 default: strcat (old_opt
, " -mgpr-??"); break;
6612 case EF_FRV_GPR_32
: strcat (old_opt
, " -mgpr-32"); break;
6613 case EF_FRV_GPR_64
: strcat (old_opt
, " -mgpr-64"); break;
6617 /* Warn if different # of fprs are used. Note, 0 means nothing is
6618 said about the size of fprs. */
6619 new_partial
= (new_flags
& EF_FRV_FPR_MASK
);
6620 old_partial
= (old_flags
& EF_FRV_FPR_MASK
);
6621 if (new_partial
== old_partial
)
6624 else if (new_partial
== 0)
6627 else if (old_partial
== 0)
6628 old_flags
|= new_partial
;
6632 switch (new_partial
)
6634 default: strcat (new_opt
, " -mfpr-?"); break;
6635 case EF_FRV_FPR_32
: strcat (new_opt
, " -mfpr-32"); break;
6636 case EF_FRV_FPR_64
: strcat (new_opt
, " -mfpr-64"); break;
6637 case EF_FRV_FPR_NONE
: strcat (new_opt
, " -msoft-float"); break;
6640 switch (old_partial
)
6642 default: strcat (old_opt
, " -mfpr-?"); break;
6643 case EF_FRV_FPR_32
: strcat (old_opt
, " -mfpr-32"); break;
6644 case EF_FRV_FPR_64
: strcat (old_opt
, " -mfpr-64"); break;
6645 case EF_FRV_FPR_NONE
: strcat (old_opt
, " -msoft-float"); break;
6649 /* Warn if different dword support was used. Note, 0 means nothing is
6650 said about the dword support. */
6651 new_partial
= (new_flags
& EF_FRV_DWORD_MASK
);
6652 old_partial
= (old_flags
& EF_FRV_DWORD_MASK
);
6653 if (new_partial
== old_partial
)
6656 else if (new_partial
== 0)
6659 else if (old_partial
== 0)
6660 old_flags
|= new_partial
;
6664 switch (new_partial
)
6666 default: strcat (new_opt
, " -mdword-?"); break;
6667 case EF_FRV_DWORD_YES
: strcat (new_opt
, " -mdword"); break;
6668 case EF_FRV_DWORD_NO
: strcat (new_opt
, " -mno-dword"); break;
6671 switch (old_partial
)
6673 default: strcat (old_opt
, " -mdword-?"); break;
6674 case EF_FRV_DWORD_YES
: strcat (old_opt
, " -mdword"); break;
6675 case EF_FRV_DWORD_NO
: strcat (old_opt
, " -mno-dword"); break;
6679 /* Or in flags that accumulate (ie, if one module uses it, mark that the
6681 old_flags
|= new_flags
& (EF_FRV_DOUBLE
6684 | EF_FRV_NON_PIC_RELOCS
);
6686 /* If any module was compiled without -G0, clear the G0 bit. */
6687 old_flags
= ((old_flags
& ~ EF_FRV_G0
)
6688 | (old_flags
& new_flags
& EF_FRV_G0
));
6690 /* If any module was compiled without -mnopack, clear the mnopack bit. */
6691 old_flags
= ((old_flags
& ~ EF_FRV_NOPACK
)
6692 | (old_flags
& new_flags
& EF_FRV_NOPACK
));
6694 /* We don't have to do anything if the pic flags are the same, or the new
6695 module(s) were compiled with -mlibrary-pic. */
6696 new_partial
= (new_flags
& EF_FRV_PIC_FLAGS
);
6697 old_partial
= (old_flags
& EF_FRV_PIC_FLAGS
);
6698 if ((new_partial
== old_partial
) || ((new_partial
& EF_FRV_LIBPIC
) != 0))
6701 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
6702 flags if any from the new module. */
6703 else if ((old_partial
& EF_FRV_LIBPIC
) != 0)
6704 old_flags
= (old_flags
& ~ EF_FRV_PIC_FLAGS
) | new_partial
;
6706 /* If we have mixtures of -fpic and -fPIC, or in both bits. */
6707 else if (new_partial
!= 0 && old_partial
!= 0)
6708 old_flags
|= new_partial
;
6710 /* One module was compiled for pic and the other was not, see if we have
6711 had any relocations that are not pic-safe. */
6714 if ((old_flags
& EF_FRV_NON_PIC_RELOCS
) == 0)
6715 old_flags
|= new_partial
;
6718 old_flags
&= ~ EF_FRV_PIC_FLAGS
;
6719 #ifndef FRV_NO_PIC_ERROR
6721 (*_bfd_error_handler
)
6722 (_("%s: compiled with %s and linked with modules that use non-pic relocations"),
6723 bfd_get_filename (ibfd
),
6724 (new_flags
& EF_FRV_BIGPIC
) ? "-fPIC" : "-fpic");
6729 /* Warn if different cpu is used (allow a specific cpu to override
6730 the generic cpu). */
6731 new_partial
= (new_flags
& EF_FRV_CPU_MASK
);
6732 old_partial
= (old_flags
& EF_FRV_CPU_MASK
);
6733 if (frv_elf_arch_extension_p (new_partial
, old_partial
))
6736 else if (frv_elf_arch_extension_p (old_partial
, new_partial
))
6737 old_flags
= (old_flags
& ~EF_FRV_CPU_MASK
) | new_partial
;
6741 switch (new_partial
)
6743 default: strcat (new_opt
, " -mcpu=?"); break;
6744 case EF_FRV_CPU_GENERIC
: strcat (new_opt
, " -mcpu=frv"); break;
6745 case EF_FRV_CPU_SIMPLE
: strcat (new_opt
, " -mcpu=simple"); break;
6746 case EF_FRV_CPU_FR550
: strcat (new_opt
, " -mcpu=fr550"); break;
6747 case EF_FRV_CPU_FR500
: strcat (new_opt
, " -mcpu=fr500"); break;
6748 case EF_FRV_CPU_FR450
: strcat (new_opt
, " -mcpu=fr450"); break;
6749 case EF_FRV_CPU_FR405
: strcat (new_opt
, " -mcpu=fr405"); break;
6750 case EF_FRV_CPU_FR400
: strcat (new_opt
, " -mcpu=fr400"); break;
6751 case EF_FRV_CPU_FR300
: strcat (new_opt
, " -mcpu=fr300"); break;
6752 case EF_FRV_CPU_TOMCAT
: strcat (new_opt
, " -mcpu=tomcat"); break;
6755 switch (old_partial
)
6757 default: strcat (old_opt
, " -mcpu=?"); break;
6758 case EF_FRV_CPU_GENERIC
: strcat (old_opt
, " -mcpu=frv"); break;
6759 case EF_FRV_CPU_SIMPLE
: strcat (old_opt
, " -mcpu=simple"); break;
6760 case EF_FRV_CPU_FR550
: strcat (old_opt
, " -mcpu=fr550"); break;
6761 case EF_FRV_CPU_FR500
: strcat (old_opt
, " -mcpu=fr500"); break;
6762 case EF_FRV_CPU_FR450
: strcat (old_opt
, " -mcpu=fr450"); break;
6763 case EF_FRV_CPU_FR405
: strcat (old_opt
, " -mcpu=fr405"); break;
6764 case EF_FRV_CPU_FR400
: strcat (old_opt
, " -mcpu=fr400"); break;
6765 case EF_FRV_CPU_FR300
: strcat (old_opt
, " -mcpu=fr300"); break;
6766 case EF_FRV_CPU_TOMCAT
: strcat (old_opt
, " -mcpu=tomcat"); break;
6770 /* Print out any mismatches from above. */
6774 (*_bfd_error_handler
)
6775 (_("%s: compiled with %s and linked with modules compiled with %s"),
6776 bfd_get_filename (ibfd
), new_opt
, old_opt
);
6779 /* Warn about any other mismatches */
6780 new_partial
= (new_flags
& ~ EF_FRV_ALL_FLAGS
);
6781 old_partial
= (old_flags
& ~ EF_FRV_ALL_FLAGS
);
6782 if (new_partial
!= old_partial
)
6784 old_flags
|= new_partial
;
6786 (*_bfd_error_handler
)
6787 (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"),
6788 bfd_get_filename (ibfd
), (long)new_partial
, (long)old_partial
);
6792 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
6793 if ((old_flags
& EF_FRV_CPU_MASK
) == EF_FRV_CPU_SIMPLE
)
6794 old_flags
|= EF_FRV_NOPACK
;
6796 /* Update the old flags now with changes made above. */
6797 old_partial
= elf_elfheader (obfd
)->e_flags
& EF_FRV_CPU_MASK
;
6798 elf_elfheader (obfd
)->e_flags
= old_flags
;
6799 if (old_partial
!= (old_flags
& EF_FRV_CPU_MASK
))
6800 bfd_default_set_arch_mach (obfd
, bfd_arch_frv
, elf32_frv_machine (obfd
));
6802 if (((new_flags
& EF_FRV_FDPIC
) == 0)
6803 != (! IS_FDPIC (ibfd
)))
6806 if (IS_FDPIC (obfd
))
6807 (*_bfd_error_handler
)
6808 (_("%s: cannot link non-fdpic object file into fdpic executable"),
6809 bfd_get_filename (ibfd
));
6811 (*_bfd_error_handler
)
6812 (_("%s: cannot link fdpic object file into non-fdpic executable"),
6813 bfd_get_filename (ibfd
));
6817 bfd_set_error (bfd_error_bad_value
);
6824 frv_elf_print_private_bfd_data (abfd
, ptr
)
6828 FILE *file
= (FILE *) ptr
;
6831 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6833 /* Print normal ELF private data. */
6834 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6836 flags
= elf_elfheader (abfd
)->e_flags
;
6837 fprintf (file
, _("private flags = 0x%lx:"), (unsigned long) flags
);
6839 switch (flags
& EF_FRV_CPU_MASK
)
6842 case EF_FRV_CPU_SIMPLE
: fprintf (file
, " -mcpu=simple"); break;
6843 case EF_FRV_CPU_FR550
: fprintf (file
, " -mcpu=fr550"); break;
6844 case EF_FRV_CPU_FR500
: fprintf (file
, " -mcpu=fr500"); break;
6845 case EF_FRV_CPU_FR450
: fprintf (file
, " -mcpu=fr450"); break;
6846 case EF_FRV_CPU_FR405
: fprintf (file
, " -mcpu=fr405"); break;
6847 case EF_FRV_CPU_FR400
: fprintf (file
, " -mcpu=fr400"); break;
6848 case EF_FRV_CPU_FR300
: fprintf (file
, " -mcpu=fr300"); break;
6849 case EF_FRV_CPU_TOMCAT
: fprintf (file
, " -mcpu=tomcat"); break;
6852 switch (flags
& EF_FRV_GPR_MASK
)
6855 case EF_FRV_GPR_32
: fprintf (file
, " -mgpr-32"); break;
6856 case EF_FRV_GPR_64
: fprintf (file
, " -mgpr-64"); break;
6859 switch (flags
& EF_FRV_FPR_MASK
)
6862 case EF_FRV_FPR_32
: fprintf (file
, " -mfpr-32"); break;
6863 case EF_FRV_FPR_64
: fprintf (file
, " -mfpr-64"); break;
6864 case EF_FRV_FPR_NONE
: fprintf (file
, " -msoft-float"); break;
6867 switch (flags
& EF_FRV_DWORD_MASK
)
6870 case EF_FRV_DWORD_YES
: fprintf (file
, " -mdword"); break;
6871 case EF_FRV_DWORD_NO
: fprintf (file
, " -mno-dword"); break;
6874 if (flags
& EF_FRV_DOUBLE
)
6875 fprintf (file
, " -mdouble");
6877 if (flags
& EF_FRV_MEDIA
)
6878 fprintf (file
, " -mmedia");
6880 if (flags
& EF_FRV_MULADD
)
6881 fprintf (file
, " -mmuladd");
6883 if (flags
& EF_FRV_PIC
)
6884 fprintf (file
, " -fpic");
6886 if (flags
& EF_FRV_BIGPIC
)
6887 fprintf (file
, " -fPIC");
6889 if (flags
& EF_FRV_LIBPIC
)
6890 fprintf (file
, " -mlibrary-pic");
6892 if (flags
& EF_FRV_FDPIC
)
6893 fprintf (file
, " -mfdpic");
6895 if (flags
& EF_FRV_NON_PIC_RELOCS
)
6896 fprintf (file
, " non-pic relocations");
6898 if (flags
& EF_FRV_G0
)
6899 fprintf (file
, " -G0");
6906 /* Support for core dump NOTE sections. */
6909 elf32_frv_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
6912 unsigned int raw_size
;
6914 switch (note
->descsz
)
6919 /* The Linux/FRV elf_prstatus struct is 268 bytes long. The other
6920 hardcoded offsets and sizes listed below (and contained within
6921 this lexical block) refer to fields in the target's elf_prstatus
6924 /* `pr_cursig' is at offset 12. */
6925 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
6927 /* `pr_pid' is at offset 24. */
6928 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
6930 /* `pr_reg' is at offset 72. */
6933 /* Most grok_prstatus implementations set `raw_size' to the size
6934 of the pr_reg field. For Linux/FRV, we set `raw_size' to be
6935 the size of `pr_reg' plus the size of `pr_exec_fdpic_loadmap'
6936 and `pr_interp_fdpic_loadmap', both of which (by design)
6937 immediately follow `pr_reg'. This will allow these fields to
6938 be viewed by GDB as registers.
6940 `pr_reg' is 184 bytes long. `pr_exec_fdpic_loadmap' and
6941 `pr_interp_fdpic_loadmap' are 4 bytes each. */
6942 raw_size
= 184 + 4 + 4;
6947 /* Make a ".reg/999" section. */
6948 return _bfd_elfcore_make_pseudosection (abfd
, ".reg", raw_size
,
6949 note
->descpos
+ offset
);
6953 elf32_frv_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
6955 switch (note
->descsz
)
6960 /* The Linux/FRV elf_prpsinfo struct is 124 bytes long. */
6963 /* `pr_fname' is found at offset 28 and is 16 bytes long. */
6964 elf_tdata (abfd
)->core_program
6965 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
6967 /* `pr_psargs' is found at offset 44 and is 80 bytes long. */
6968 elf_tdata (abfd
)->core_command
6969 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
6972 /* Note that for some reason, a spurious space is tacked
6973 onto the end of the args in some (at least one anyway)
6974 implementations, so strip it off if it exists. */
6977 char *command
= elf_tdata (abfd
)->core_command
;
6978 int n
= strlen (command
);
6980 if (0 < n
&& command
[n
- 1] == ' ')
6981 command
[n
- 1] = '\0';
6986 #define ELF_ARCH bfd_arch_frv
6987 #define ELF_TARGET_ID FRV_ELF_DATA
6988 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
6989 #define ELF_MAXPAGESIZE 0x1000
6991 #define TARGET_BIG_SYM bfd_elf32_frv_vec
6992 #define TARGET_BIG_NAME "elf32-frv"
6994 #define elf_info_to_howto frv_info_to_howto_rela
6995 #define elf_backend_relocate_section elf32_frv_relocate_section
6996 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
6997 #define elf_backend_check_relocs elf32_frv_check_relocs
6998 #define elf_backend_object_p elf32_frv_object_p
6999 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
7001 #define elf_backend_can_gc_sections 1
7002 #define elf_backend_rela_normal 1
7004 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
7005 #define bfd_elf32_bfd_reloc_name_lookup frv_reloc_name_lookup
7006 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
7007 #define bfd_elf32_bfd_copy_private_bfd_data frv_elf_copy_private_bfd_data
7008 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
7009 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
7011 #define elf_backend_want_got_sym 1
7012 #define elf_backend_got_header_size 0
7013 #define elf_backend_want_got_plt 0
7014 #define elf_backend_plt_readonly 1
7015 #define elf_backend_want_plt_sym 0
7016 #define elf_backend_plt_header_size 0
7018 #define elf_backend_finish_dynamic_sections \
7019 elf32_frv_finish_dynamic_sections
7021 #define elf_backend_grok_prstatus elf32_frv_grok_prstatus
7022 #define elf_backend_grok_psinfo elf32_frv_grok_psinfo
7024 #include "elf32-target.h"
7026 #undef ELF_MAXPAGESIZE
7027 #define ELF_MAXPAGESIZE 0x4000
7029 #undef TARGET_BIG_SYM
7030 #define TARGET_BIG_SYM bfd_elf32_frvfdpic_vec
7031 #undef TARGET_BIG_NAME
7032 #define TARGET_BIG_NAME "elf32-frvfdpic"
7034 #define elf32_bed elf32_frvfdpic_bed
7036 #undef elf_info_to_howto_rel
7037 #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel
7039 #undef bfd_elf32_bfd_link_hash_table_create
7040 #define bfd_elf32_bfd_link_hash_table_create \
7041 frvfdpic_elf_link_hash_table_create
7042 #undef elf_backend_always_size_sections
7043 #define elf_backend_always_size_sections \
7044 elf32_frvfdpic_always_size_sections
7045 #undef elf_backend_modify_program_headers
7046 #define elf_backend_modify_program_headers \
7047 elf32_frvfdpic_modify_program_headers
7048 #undef bfd_elf32_bfd_copy_private_bfd_data
7049 #define bfd_elf32_bfd_copy_private_bfd_data \
7050 elf32_frvfdpic_copy_private_bfd_data
7052 #undef elf_backend_create_dynamic_sections
7053 #define elf_backend_create_dynamic_sections \
7054 elf32_frvfdpic_create_dynamic_sections
7055 #undef elf_backend_adjust_dynamic_symbol
7056 #define elf_backend_adjust_dynamic_symbol \
7057 elf32_frvfdpic_adjust_dynamic_symbol
7058 #undef elf_backend_size_dynamic_sections
7059 #define elf_backend_size_dynamic_sections \
7060 elf32_frvfdpic_size_dynamic_sections
7061 #undef bfd_elf32_bfd_relax_section
7062 #define bfd_elf32_bfd_relax_section \
7063 elf32_frvfdpic_relax_section
7064 #undef elf_backend_finish_dynamic_symbol
7065 #define elf_backend_finish_dynamic_symbol \
7066 elf32_frvfdpic_finish_dynamic_symbol
7067 #undef elf_backend_finish_dynamic_sections
7068 #define elf_backend_finish_dynamic_sections \
7069 elf32_frvfdpic_finish_dynamic_sections
7071 #undef elf_backend_discard_info
7072 #define elf_backend_discard_info \
7073 frvfdpic_elf_discard_info
7074 #undef elf_backend_can_make_relative_eh_frame
7075 #define elf_backend_can_make_relative_eh_frame \
7076 frvfdpic_elf_use_relative_eh_frame
7077 #undef elf_backend_can_make_lsda_relative_eh_frame
7078 #define elf_backend_can_make_lsda_relative_eh_frame \
7079 frvfdpic_elf_use_relative_eh_frame
7080 #undef elf_backend_encode_eh_address
7081 #define elf_backend_encode_eh_address \
7082 frvfdpic_elf_encode_eh_address
7084 #undef elf_backend_may_use_rel_p
7085 #define elf_backend_may_use_rel_p 1
7086 #undef elf_backend_may_use_rela_p
7087 #define elf_backend_may_use_rela_p 1
7088 /* We use REL for dynamic relocations only. */
7089 #undef elf_backend_default_use_rela_p
7090 #define elf_backend_default_use_rela_p 1
7092 #undef elf_backend_omit_section_dynsym
7093 #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym
7095 #include "elf32-target.h"