1 /* FRV-specific support for 32-bit ELF.
2 Copyright 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 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, MA 02110-1301, USA. */
26 #include "elf/dwarf2.h"
29 /* Forward declarations. */
30 static bfd_reloc_status_type elf32_frv_relocate_lo16
31 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
32 static bfd_reloc_status_type elf32_frv_relocate_hi16
33 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
34 static bfd_reloc_status_type elf32_frv_relocate_label24
35 PARAMS ((bfd
*, asection
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
36 static bfd_reloc_status_type elf32_frv_relocate_gprel12
37 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
38 bfd_byte
*, bfd_vma
));
39 static bfd_reloc_status_type elf32_frv_relocate_gprelu12
40 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
41 bfd_byte
*, bfd_vma
));
42 static bfd_reloc_status_type elf32_frv_relocate_gprello
43 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
44 bfd_byte
*, bfd_vma
));
45 static bfd_reloc_status_type elf32_frv_relocate_gprelhi
46 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
47 bfd_byte
*, bfd_vma
));
48 static reloc_howto_type
*frv_reloc_type_lookup
49 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
50 static void frv_info_to_howto_rela
51 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
52 static bfd_boolean elf32_frv_relocate_section
53 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
54 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
55 static bfd_boolean elf32_frv_add_symbol_hook
56 PARAMS (( bfd
*, struct bfd_link_info
*, Elf_Internal_Sym
*,
57 const char **, flagword
*, asection
**, bfd_vma
*));
58 static bfd_reloc_status_type frv_final_link_relocate
59 PARAMS ((reloc_howto_type
*, bfd
*, asection
*, bfd_byte
*,
60 Elf_Internal_Rela
*, bfd_vma
));
61 static bfd_boolean elf32_frv_check_relocs
62 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
63 const Elf_Internal_Rela
*));
64 static int elf32_frv_machine
66 static bfd_boolean elf32_frv_object_p
68 static bfd_boolean frv_elf_set_private_flags
69 PARAMS ((bfd
*, flagword
));
70 static bfd_boolean frv_elf_copy_private_bfd_data
71 PARAMS ((bfd
*, bfd
*));
72 static bfd_boolean frv_elf_merge_private_bfd_data
73 PARAMS ((bfd
*, bfd
*));
74 static bfd_boolean frv_elf_print_private_bfd_data
75 PARAMS ((bfd
*, PTR
));
76 static bfd_boolean
elf32_frv_grok_prstatus (bfd
* abfd
,
77 Elf_Internal_Note
* note
);
78 static bfd_boolean
elf32_frv_grok_psinfo (bfd
* abfd
,
79 Elf_Internal_Note
* note
);
81 static reloc_howto_type elf32_frv_howto_table
[] =
83 /* This reloc does nothing. */
84 HOWTO (R_FRV_NONE
, /* type */
86 2, /* size (0 = byte, 1 = short, 2 = long) */
88 FALSE
, /* pc_relative */
90 complain_overflow_bitfield
, /* complain_on_overflow */
91 bfd_elf_generic_reloc
, /* special_function */
92 "R_FRV_NONE", /* name */
93 FALSE
, /* partial_inplace */
96 FALSE
), /* pcrel_offset */
98 /* A 32 bit absolute relocation. */
99 HOWTO (R_FRV_32
, /* type */
101 2, /* size (0 = byte, 1 = short, 2 = long) */
103 FALSE
, /* pc_relative */
105 complain_overflow_bitfield
, /* complain_on_overflow */
106 bfd_elf_generic_reloc
, /* special_function */
107 "R_FRV_32", /* name */
108 FALSE
, /* partial_inplace */
109 0xffffffff, /* src_mask */
110 0xffffffff, /* dst_mask */
111 FALSE
), /* pcrel_offset */
113 /* A 16 bit pc-relative relocation. */
114 HOWTO (R_FRV_LABEL16
, /* type */
116 2, /* size (0 = byte, 1 = short, 2 = long) */
118 TRUE
, /* pc_relative */
120 complain_overflow_signed
, /* complain_on_overflow */
121 bfd_elf_generic_reloc
, /* special_function */
122 "R_FRV_LABEL16", /* name */
123 FALSE
, /* partial_inplace */
124 0xffff, /* src_mask */
125 0xffff, /* dst_mask */
126 TRUE
), /* pcrel_offset */
128 /* A 24-bit pc-relative relocation. */
129 HOWTO (R_FRV_LABEL24
, /* type */
131 2, /* size (0 = byte, 1 = short, 2 = long) */
133 TRUE
, /* pc_relative */
135 complain_overflow_bitfield
, /* complain_on_overflow */
136 bfd_elf_generic_reloc
, /* special_function */
137 "R_FRV_LABEL24", /* name */
138 FALSE
, /* partial_inplace */
139 0x7e03ffff, /* src_mask */
140 0x7e03ffff, /* dst_mask */
141 TRUE
), /* pcrel_offset */
143 HOWTO (R_FRV_LO16
, /* type */
145 2, /* size (0 = byte, 1 = short, 2 = long) */
147 FALSE
, /* pc_relative */
149 complain_overflow_dont
, /* complain_on_overflow */
150 bfd_elf_generic_reloc
, /* special_function */
151 "R_FRV_LO16", /* name */
152 FALSE
, /* partial_inplace */
153 0xffff, /* src_mask */
154 0xffff, /* dst_mask */
155 FALSE
), /* pcrel_offset */
157 HOWTO (R_FRV_HI16
, /* type */
159 2, /* size (0 = byte, 1 = short, 2 = long) */
161 FALSE
, /* pc_relative */
163 complain_overflow_dont
, /* complain_on_overflow */
164 bfd_elf_generic_reloc
, /* special_function */
165 "R_FRV_HI16", /* name */
166 FALSE
, /* partial_inplace */
167 0xffff, /* src_mask */
168 0xffff, /* dst_mask */
169 FALSE
), /* pcrel_offset */
171 HOWTO (R_FRV_GPREL12
, /* type */
173 2, /* size (0 = byte, 1 = short, 2 = long) */
175 FALSE
, /* pc_relative */
177 complain_overflow_dont
, /* complain_on_overflow */
178 bfd_elf_generic_reloc
, /* special_function */
179 "R_FRV_GPREL12", /* name */
180 FALSE
, /* partial_inplace */
181 0xfff, /* src_mask */
182 0xfff, /* dst_mask */
183 FALSE
), /* pcrel_offset */
185 HOWTO (R_FRV_GPRELU12
, /* type */
187 2, /* size (0 = byte, 1 = short, 2 = long) */
189 FALSE
, /* pc_relative */
191 complain_overflow_dont
, /* complain_on_overflow */
192 bfd_elf_generic_reloc
, /* special_function */
193 "R_FRV_GPRELU12", /* name */
194 FALSE
, /* partial_inplace */
195 0xfff, /* src_mask */
196 0x3f03f, /* dst_mask */
197 FALSE
), /* pcrel_offset */
199 HOWTO (R_FRV_GPREL32
, /* type */
201 2, /* size (0 = byte, 1 = short, 2 = long) */
203 FALSE
, /* pc_relative */
205 complain_overflow_dont
, /* complain_on_overflow */
206 bfd_elf_generic_reloc
, /* special_function */
207 "R_FRV_GPREL32", /* name */
208 FALSE
, /* partial_inplace */
209 0xffffffff, /* src_mask */
210 0xffffffff, /* dst_mask */
211 FALSE
), /* pcrel_offset */
213 HOWTO (R_FRV_GPRELHI
, /* type */
215 2, /* size (0 = byte, 1 = short, 2 = long) */
217 FALSE
, /* pc_relative */
219 complain_overflow_dont
, /* complain_on_overflow */
220 bfd_elf_generic_reloc
, /* special_function */
221 "R_FRV_GPRELHI", /* name */
222 FALSE
, /* partial_inplace */
223 0xffff, /* src_mask */
224 0xffff, /* dst_mask */
225 FALSE
), /* pcrel_offset */
227 HOWTO (R_FRV_GPRELLO
, /* type */
229 2, /* size (0 = byte, 1 = short, 2 = long) */
231 FALSE
, /* pc_relative */
233 complain_overflow_dont
, /* complain_on_overflow */
234 bfd_elf_generic_reloc
, /* special_function */
235 "R_FRV_GPRELLO", /* name */
236 FALSE
, /* partial_inplace */
237 0xffff, /* src_mask */
238 0xffff, /* dst_mask */
239 FALSE
), /* pcrel_offset */
241 /* A 12-bit signed operand with the GOT offset for the address of
243 HOWTO (R_FRV_GOT12
, /* type */
245 2, /* size (0 = byte, 1 = short, 2 = long) */
247 FALSE
, /* pc_relative */
249 complain_overflow_signed
, /* complain_on_overflow */
250 bfd_elf_generic_reloc
, /* special_function */
251 "R_FRV_GOT12", /* name */
252 FALSE
, /* partial_inplace */
253 0xfff, /* src_mask */
254 0xfff, /* dst_mask */
255 FALSE
), /* pcrel_offset */
257 /* The upper 16 bits of the GOT offset for the address of the
259 HOWTO (R_FRV_GOTHI
, /* type */
261 2, /* size (0 = byte, 1 = short, 2 = long) */
263 FALSE
, /* pc_relative */
265 complain_overflow_dont
, /* complain_on_overflow */
266 bfd_elf_generic_reloc
, /* special_function */
267 "R_FRV_GOTHI", /* name */
268 FALSE
, /* partial_inplace */
269 0xffff, /* src_mask */
270 0xffff, /* dst_mask */
271 FALSE
), /* pcrel_offset */
273 /* The lower 16 bits of the GOT offset for the address of the
275 HOWTO (R_FRV_GOTLO
, /* type */
277 2, /* size (0 = byte, 1 = short, 2 = long) */
279 FALSE
, /* pc_relative */
281 complain_overflow_dont
, /* complain_on_overflow */
282 bfd_elf_generic_reloc
, /* special_function */
283 "R_FRV_GOTLO", /* name */
284 FALSE
, /* partial_inplace */
285 0xffff, /* src_mask */
286 0xffff, /* dst_mask */
287 FALSE
), /* pcrel_offset */
289 /* The 32-bit address of the canonical descriptor of a function. */
290 HOWTO (R_FRV_FUNCDESC
, /* type */
292 2, /* size (0 = byte, 1 = short, 2 = long) */
294 FALSE
, /* pc_relative */
296 complain_overflow_bitfield
, /* complain_on_overflow */
297 bfd_elf_generic_reloc
, /* special_function */
298 "R_FRV_FUNCDESC", /* name */
299 FALSE
, /* partial_inplace */
300 0xffffffff, /* src_mask */
301 0xffffffff, /* dst_mask */
302 FALSE
), /* pcrel_offset */
304 /* A 12-bit signed operand with the GOT offset for the address of
305 canonical descriptor of a function. */
306 HOWTO (R_FRV_FUNCDESC_GOT12
, /* type */
308 2, /* size (0 = byte, 1 = short, 2 = long) */
310 FALSE
, /* pc_relative */
312 complain_overflow_signed
, /* complain_on_overflow */
313 bfd_elf_generic_reloc
, /* special_function */
314 "R_FRV_FUNCDESC_GOT12", /* name */
315 FALSE
, /* partial_inplace */
316 0xfff, /* src_mask */
317 0xfff, /* dst_mask */
318 FALSE
), /* pcrel_offset */
320 /* The upper 16 bits of the GOT offset for the address of the
321 canonical descriptor of a function. */
322 HOWTO (R_FRV_FUNCDESC_GOTHI
, /* type */
324 2, /* size (0 = byte, 1 = short, 2 = long) */
326 FALSE
, /* pc_relative */
328 complain_overflow_dont
, /* complain_on_overflow */
329 bfd_elf_generic_reloc
, /* special_function */
330 "R_FRV_FUNCDESC_GOTHI", /* name */
331 FALSE
, /* partial_inplace */
332 0xffff, /* src_mask */
333 0xffff, /* dst_mask */
334 FALSE
), /* pcrel_offset */
336 /* The lower 16 bits of the GOT offset for the address of the
337 canonical descriptor of a function. */
338 HOWTO (R_FRV_FUNCDESC_GOTLO
, /* type */
340 2, /* size (0 = byte, 1 = short, 2 = long) */
342 FALSE
, /* pc_relative */
344 complain_overflow_dont
, /* complain_on_overflow */
345 bfd_elf_generic_reloc
, /* special_function */
346 "R_FRV_FUNCDESC_GOTLO", /* name */
347 FALSE
, /* partial_inplace */
348 0xffff, /* src_mask */
349 0xffff, /* dst_mask */
350 FALSE
), /* pcrel_offset */
352 /* The 64-bit descriptor of a function. */
353 HOWTO (R_FRV_FUNCDESC_VALUE
, /* type */
355 2, /* size (0 = byte, 1 = short, 2 = long) */
357 FALSE
, /* pc_relative */
359 complain_overflow_bitfield
, /* complain_on_overflow */
360 bfd_elf_generic_reloc
, /* special_function */
361 "R_FRV_FUNCDESC_VALUE", /* name */
362 FALSE
, /* partial_inplace */
363 0xffffffff, /* src_mask */
364 0xffffffff, /* dst_mask */
365 FALSE
), /* pcrel_offset */
367 /* A 12-bit signed operand with the GOT offset for the address of
368 canonical descriptor of a function. */
369 HOWTO (R_FRV_FUNCDESC_GOTOFF12
, /* type */
371 2, /* size (0 = byte, 1 = short, 2 = long) */
373 FALSE
, /* pc_relative */
375 complain_overflow_signed
, /* complain_on_overflow */
376 bfd_elf_generic_reloc
, /* special_function */
377 "R_FRV_FUNCDESC_GOTOFF12", /* name */
378 FALSE
, /* partial_inplace */
379 0xfff, /* src_mask */
380 0xfff, /* dst_mask */
381 FALSE
), /* pcrel_offset */
383 /* The upper 16 bits of the GOT offset for the address of the
384 canonical descriptor of a function. */
385 HOWTO (R_FRV_FUNCDESC_GOTOFFHI
, /* type */
387 2, /* size (0 = byte, 1 = short, 2 = long) */
389 FALSE
, /* pc_relative */
391 complain_overflow_dont
, /* complain_on_overflow */
392 bfd_elf_generic_reloc
, /* special_function */
393 "R_FRV_FUNCDESC_GOTOFFHI", /* name */
394 FALSE
, /* partial_inplace */
395 0xffff, /* src_mask */
396 0xffff, /* dst_mask */
397 FALSE
), /* pcrel_offset */
399 /* The lower 16 bits of the GOT offset for the address of the
400 canonical descriptor of a function. */
401 HOWTO (R_FRV_FUNCDESC_GOTOFFLO
, /* type */
403 2, /* size (0 = byte, 1 = short, 2 = long) */
405 FALSE
, /* pc_relative */
407 complain_overflow_dont
, /* complain_on_overflow */
408 bfd_elf_generic_reloc
, /* special_function */
409 "R_FRV_FUNCDESC_GOTOFFLO", /* name */
410 FALSE
, /* partial_inplace */
411 0xffff, /* src_mask */
412 0xffff, /* dst_mask */
413 FALSE
), /* pcrel_offset */
415 /* A 12-bit signed operand with the GOT offset for the address of
417 HOWTO (R_FRV_GOTOFF12
, /* type */
419 2, /* size (0 = byte, 1 = short, 2 = long) */
421 FALSE
, /* pc_relative */
423 complain_overflow_signed
, /* complain_on_overflow */
424 bfd_elf_generic_reloc
, /* special_function */
425 "R_FRV_GOTOFF12", /* name */
426 FALSE
, /* partial_inplace */
427 0xfff, /* src_mask */
428 0xfff, /* dst_mask */
429 FALSE
), /* pcrel_offset */
431 /* The upper 16 bits of the GOT offset for the address of the
433 HOWTO (R_FRV_GOTOFFHI
, /* type */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
437 FALSE
, /* pc_relative */
439 complain_overflow_dont
, /* complain_on_overflow */
440 bfd_elf_generic_reloc
, /* special_function */
441 "R_FRV_GOTOFFHI", /* name */
442 FALSE
, /* partial_inplace */
443 0xffff, /* src_mask */
444 0xffff, /* dst_mask */
445 FALSE
), /* pcrel_offset */
447 /* The lower 16 bits of the GOT offset for the address of the
449 HOWTO (R_FRV_GOTOFFLO
, /* type */
451 2, /* size (0 = byte, 1 = short, 2 = long) */
453 FALSE
, /* pc_relative */
455 complain_overflow_dont
, /* complain_on_overflow */
456 bfd_elf_generic_reloc
, /* special_function */
457 "R_FRV_GOTOFFLO", /* name */
458 FALSE
, /* partial_inplace */
459 0xffff, /* src_mask */
460 0xffff, /* dst_mask */
461 FALSE
), /* pcrel_offset */
463 /* A 24-bit pc-relative relocation referencing the TLS PLT entry for
464 a thread-local symbol. If the symbol number is 0, it refers to
466 HOWTO (R_FRV_GETTLSOFF
, /* type */
468 2, /* size (0 = byte, 1 = short, 2 = long) */
470 TRUE
, /* pc_relative */
472 complain_overflow_bitfield
, /* complain_on_overflow */
473 bfd_elf_generic_reloc
, /* special_function */
474 "R_FRV_GETTLSOFF", /* name */
475 FALSE
, /* partial_inplace */
476 0x7e03ffff, /* src_mask */
477 0x7e03ffff, /* dst_mask */
478 TRUE
), /* pcrel_offset */
480 /* A 64-bit TLS descriptor for a symbol. This relocation is only
481 valid as a REL, dynamic relocation. */
482 HOWTO (R_FRV_TLSDESC_VALUE
, /* type */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
486 FALSE
, /* pc_relative */
488 complain_overflow_bitfield
, /* complain_on_overflow */
489 bfd_elf_generic_reloc
, /* special_function */
490 "R_FRV_TLSDESC_VALUE", /* name */
491 FALSE
, /* partial_inplace */
492 0xffffffff, /* src_mask */
493 0xffffffff, /* dst_mask */
494 FALSE
), /* pcrel_offset */
496 /* A 12-bit signed operand with the GOT offset for the TLS
497 descriptor of the symbol. */
498 HOWTO (R_FRV_GOTTLSDESC12
, /* type */
500 2, /* size (0 = byte, 1 = short, 2 = long) */
502 FALSE
, /* pc_relative */
504 complain_overflow_signed
, /* complain_on_overflow */
505 bfd_elf_generic_reloc
, /* special_function */
506 "R_FRV_GOTTLSDESC12", /* name */
507 FALSE
, /* partial_inplace */
508 0xfff, /* src_mask */
509 0xfff, /* dst_mask */
510 FALSE
), /* pcrel_offset */
512 /* The upper 16 bits of the GOT offset for the TLS descriptor of the
514 HOWTO (R_FRV_GOTTLSDESCHI
, /* type */
516 2, /* size (0 = byte, 1 = short, 2 = long) */
518 FALSE
, /* pc_relative */
520 complain_overflow_dont
, /* complain_on_overflow */
521 bfd_elf_generic_reloc
, /* special_function */
522 "R_FRV_GOTTLSDESCHI", /* name */
523 FALSE
, /* partial_inplace */
524 0xffff, /* src_mask */
525 0xffff, /* dst_mask */
526 FALSE
), /* pcrel_offset */
528 /* The lower 16 bits of the GOT offset for the TLS descriptor of the
530 HOWTO (R_FRV_GOTTLSDESCLO
, /* type */
532 2, /* size (0 = byte, 1 = short, 2 = long) */
534 FALSE
, /* pc_relative */
536 complain_overflow_dont
, /* complain_on_overflow */
537 bfd_elf_generic_reloc
, /* special_function */
538 "R_FRV_GOTTLSDESCLO", /* name */
539 FALSE
, /* partial_inplace */
540 0xffff, /* src_mask */
541 0xffff, /* dst_mask */
542 FALSE
), /* pcrel_offset */
544 /* A 12-bit signed operand with the offset from the module base
545 address to the thread-local symbol address. */
546 HOWTO (R_FRV_TLSMOFF12
, /* type */
548 2, /* size (0 = byte, 1 = short, 2 = long) */
550 FALSE
, /* pc_relative */
552 complain_overflow_signed
, /* complain_on_overflow */
553 bfd_elf_generic_reloc
, /* special_function */
554 "R_FRV_TLSMOFF12", /* name */
555 FALSE
, /* partial_inplace */
556 0xfff, /* src_mask */
557 0xfff, /* dst_mask */
558 FALSE
), /* pcrel_offset */
560 /* The upper 16 bits of the offset from the module base address to
561 the thread-local symbol address. */
562 HOWTO (R_FRV_TLSMOFFHI
, /* type */
564 2, /* size (0 = byte, 1 = short, 2 = long) */
566 FALSE
, /* pc_relative */
568 complain_overflow_dont
, /* complain_on_overflow */
569 bfd_elf_generic_reloc
, /* special_function */
570 "R_FRV_TLSMOFFHI", /* name */
571 FALSE
, /* partial_inplace */
572 0xffff, /* src_mask */
573 0xffff, /* dst_mask */
574 FALSE
), /* pcrel_offset */
576 /* The lower 16 bits of the offset from the module base address to
577 the thread-local symbol address. */
578 HOWTO (R_FRV_TLSMOFFLO
, /* type */
580 2, /* size (0 = byte, 1 = short, 2 = long) */
582 FALSE
, /* pc_relative */
584 complain_overflow_dont
, /* complain_on_overflow */
585 bfd_elf_generic_reloc
, /* special_function */
586 "R_FRV_TLSMOFFLO", /* name */
587 FALSE
, /* partial_inplace */
588 0xffff, /* src_mask */
589 0xffff, /* dst_mask */
590 FALSE
), /* pcrel_offset */
592 /* A 12-bit signed operand with the GOT offset for the TLSOFF entry
594 HOWTO (R_FRV_GOTTLSOFF12
, /* type */
596 2, /* size (0 = byte, 1 = short, 2 = long) */
598 FALSE
, /* pc_relative */
600 complain_overflow_signed
, /* complain_on_overflow */
601 bfd_elf_generic_reloc
, /* special_function */
602 "R_FRV_GOTTLSOFF12", /* name */
603 FALSE
, /* partial_inplace */
604 0xfff, /* src_mask */
605 0xfff, /* dst_mask */
606 FALSE
), /* pcrel_offset */
608 /* The upper 16 bits of the GOT offset for the TLSOFF entry for a
610 HOWTO (R_FRV_GOTTLSOFFHI
, /* type */
612 2, /* size (0 = byte, 1 = short, 2 = long) */
614 FALSE
, /* pc_relative */
616 complain_overflow_dont
, /* complain_on_overflow */
617 bfd_elf_generic_reloc
, /* special_function */
618 "R_FRV_GOTTLSOFFHI", /* name */
619 FALSE
, /* partial_inplace */
620 0xffff, /* src_mask */
621 0xffff, /* dst_mask */
622 FALSE
), /* pcrel_offset */
624 /* The lower 16 bits of the GOT offset for the TLSOFF entry for a
626 HOWTO (R_FRV_GOTTLSOFFLO
, /* type */
628 2, /* size (0 = byte, 1 = short, 2 = long) */
630 FALSE
, /* pc_relative */
632 complain_overflow_dont
, /* complain_on_overflow */
633 bfd_elf_generic_reloc
, /* special_function */
634 "R_FRV_GOTTLSOFFLO", /* name */
635 FALSE
, /* partial_inplace */
636 0xffff, /* src_mask */
637 0xffff, /* dst_mask */
638 FALSE
), /* pcrel_offset */
640 /* The 32-bit offset from the thread pointer (not the module base
641 address) to a thread-local symbol. */
642 HOWTO (R_FRV_TLSOFF
, /* type */
644 2, /* size (0 = byte, 1 = short, 2 = long) */
646 FALSE
, /* pc_relative */
648 complain_overflow_dont
, /* complain_on_overflow */
649 bfd_elf_generic_reloc
, /* special_function */
650 "R_FRV_TLSOFF", /* name */
651 FALSE
, /* partial_inplace */
652 0xffffffff, /* src_mask */
653 0xffffffff, /* dst_mask */
654 FALSE
), /* pcrel_offset */
656 /* An annotation for linker relaxation, that denotes the
657 symbol+addend whose TLS descriptor is referenced by the sum of
658 the two input registers of an ldd instruction. */
659 HOWTO (R_FRV_TLSDESC_RELAX
, /* type */
661 2, /* size (0 = byte, 1 = short, 2 = long) */
663 FALSE
, /* pc_relative */
665 complain_overflow_dont
, /* complain_on_overflow */
666 bfd_elf_generic_reloc
, /* special_function */
667 "R_FRV_TLSDESC_RELAX", /* name */
668 FALSE
, /* partial_inplace */
671 FALSE
), /* pcrel_offset */
673 /* An annotation for linker relaxation, that denotes the
674 symbol+addend whose TLS resolver entry point is given by the sum
675 of the two register operands of an calll instruction. */
676 HOWTO (R_FRV_GETTLSOFF_RELAX
, /* type */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
680 FALSE
, /* pc_relative */
682 complain_overflow_dont
, /* complain_on_overflow */
683 bfd_elf_generic_reloc
, /* special_function */
684 "R_FRV_GETTLSOFF_RELAX", /* name */
685 FALSE
, /* partial_inplace */
688 FALSE
), /* pcrel_offset */
690 /* An annotation for linker relaxation, that denotes the
691 symbol+addend whose TLS offset GOT entry is given by the sum of
692 the two input registers of an ld instruction. */
693 HOWTO (R_FRV_TLSOFF_RELAX
, /* type */
695 2, /* size (0 = byte, 1 = short, 2 = long) */
697 FALSE
, /* pc_relative */
699 complain_overflow_bitfield
, /* complain_on_overflow */
700 bfd_elf_generic_reloc
, /* special_function */
701 "R_FRV_TLSOFF_RELAX", /* name */
702 FALSE
, /* partial_inplace */
705 FALSE
), /* pcrel_offset */
707 /* A 32-bit offset from the module base address to
708 the thread-local symbol address. */
709 HOWTO (R_FRV_TLSMOFF
, /* type */
711 2, /* size (0 = byte, 1 = short, 2 = long) */
713 FALSE
, /* pc_relative */
715 complain_overflow_dont
, /* complain_on_overflow */
716 bfd_elf_generic_reloc
, /* special_function */
717 "R_FRV_TLSMOFF", /* name */
718 FALSE
, /* partial_inplace */
719 0xffffffff, /* src_mask */
720 0xffffffff, /* dst_mask */
721 FALSE
), /* pcrel_offset */
724 /* GNU extension to record C++ vtable hierarchy. */
725 static reloc_howto_type elf32_frv_vtinherit_howto
=
726 HOWTO (R_FRV_GNU_VTINHERIT
, /* type */
728 2, /* size (0 = byte, 1 = short, 2 = long) */
730 FALSE
, /* pc_relative */
732 complain_overflow_dont
, /* complain_on_overflow */
733 NULL
, /* special_function */
734 "R_FRV_GNU_VTINHERIT", /* name */
735 FALSE
, /* partial_inplace */
738 FALSE
); /* pcrel_offset */
740 /* GNU extension to record C++ vtable member usage. */
741 static reloc_howto_type elf32_frv_vtentry_howto
=
742 HOWTO (R_FRV_GNU_VTENTRY
, /* type */
744 2, /* size (0 = byte, 1 = short, 2 = long) */
746 FALSE
, /* pc_relative */
748 complain_overflow_dont
, /* complain_on_overflow */
749 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
750 "R_FRV_GNU_VTENTRY", /* name */
751 FALSE
, /* partial_inplace */
754 FALSE
); /* pcrel_offset */
756 /* The following 3 relocations are REL. The only difference to the
757 entries in the table above are that partial_inplace is TRUE. */
758 static reloc_howto_type elf32_frv_rel_32_howto
=
759 HOWTO (R_FRV_32
, /* type */
761 2, /* size (0 = byte, 1 = short, 2 = long) */
763 FALSE
, /* pc_relative */
765 complain_overflow_bitfield
, /* complain_on_overflow */
766 bfd_elf_generic_reloc
, /* special_function */
767 "R_FRV_32", /* name */
768 TRUE
, /* partial_inplace */
769 0xffffffff, /* src_mask */
770 0xffffffff, /* dst_mask */
771 FALSE
); /* pcrel_offset */
773 static reloc_howto_type elf32_frv_rel_funcdesc_howto
=
774 HOWTO (R_FRV_FUNCDESC
, /* type */
776 2, /* size (0 = byte, 1 = short, 2 = long) */
778 FALSE
, /* pc_relative */
780 complain_overflow_bitfield
, /* complain_on_overflow */
781 bfd_elf_generic_reloc
, /* special_function */
782 "R_FRV_FUNCDESC", /* name */
783 TRUE
, /* partial_inplace */
784 0xffffffff, /* src_mask */
785 0xffffffff, /* dst_mask */
786 FALSE
); /* pcrel_offset */
788 static reloc_howto_type elf32_frv_rel_funcdesc_value_howto
=
789 HOWTO (R_FRV_FUNCDESC_VALUE
, /* type */
791 2, /* size (0 = byte, 1 = short, 2 = long) */
793 FALSE
, /* pc_relative */
795 complain_overflow_bitfield
, /* complain_on_overflow */
796 bfd_elf_generic_reloc
, /* special_function */
797 "R_FRV_FUNCDESC_VALUE", /* name */
798 TRUE
, /* partial_inplace */
799 0xffffffff, /* src_mask */
800 0xffffffff, /* dst_mask */
801 FALSE
); /* pcrel_offset */
803 static reloc_howto_type elf32_frv_rel_tlsdesc_value_howto
=
804 /* A 64-bit TLS descriptor for a symbol. The first word resolves to
805 an entry point, and the second resolves to a special argument.
806 If the symbol turns out to be in static TLS, the entry point is a
807 return instruction, and the special argument is the TLS offset
808 for the symbol. If it's in dynamic TLS, the entry point is a TLS
809 offset resolver, and the special argument is a pointer to a data
810 structure allocated by the dynamic loader, containing the GOT
811 address for the offset resolver, the module id, the offset within
812 the module, and anything else the TLS offset resolver might need
813 to determine the TLS offset for the symbol in the running
815 HOWTO (R_FRV_TLSDESC_VALUE
, /* type */
817 2, /* size (0 = byte, 1 = short, 2 = long) */
819 FALSE
, /* pc_relative */
821 complain_overflow_bitfield
, /* complain_on_overflow */
822 bfd_elf_generic_reloc
, /* special_function */
823 "R_FRV_TLSDESC_VALUE", /* name */
824 TRUE
, /* partial_inplace */
825 0xffffffff, /* src_mask */
826 0xffffffff, /* dst_mask */
827 FALSE
); /* pcrel_offset */
829 static reloc_howto_type elf32_frv_rel_tlsoff_howto
=
830 /* The 32-bit offset from the thread pointer (not the module base
831 address) to a thread-local symbol. */
832 HOWTO (R_FRV_TLSOFF
, /* type */
834 2, /* size (0 = byte, 1 = short, 2 = long) */
836 FALSE
, /* pc_relative */
838 complain_overflow_bitfield
, /* complain_on_overflow */
839 bfd_elf_generic_reloc
, /* special_function */
840 "R_FRV_TLSOFF", /* name */
841 TRUE
, /* partial_inplace */
842 0xffffffff, /* src_mask */
843 0xffffffff, /* dst_mask */
844 FALSE
); /* pcrel_offset */
848 extern const bfd_target bfd_elf32_frvfdpic_vec
;
849 #define IS_FDPIC(bfd) ((bfd)->xvec == &bfd_elf32_frvfdpic_vec)
851 /* An extension of the elf hash table data structure, containing some
852 additional FRV-specific data. */
853 struct frvfdpic_elf_link_hash_table
855 struct elf_link_hash_table elf
;
857 /* A pointer to the .got section. */
859 /* A pointer to the .rel.got section. */
861 /* A pointer to the .rofixup section. */
863 /* A pointer to the .plt section. */
865 /* A pointer to the .rel.plt section. */
867 /* GOT base offset. */
869 /* Location of the first non-lazy PLT entry, i.e., the number of
870 bytes taken by lazy PLT entries. If locally-bound TLS
871 descriptors require a ret instruction, it will be placed at this
874 /* A hash table holding information about which symbols were
875 referenced with which PIC-related relocations. */
876 struct htab
*relocs_info
;
877 /* Summary reloc information collected by
878 _frvfdpic_count_got_plt_entries. */
879 struct _frvfdpic_dynamic_got_info
*g
;
882 /* Get the FRV ELF linker hash table from a link_info structure. */
884 #define frvfdpic_hash_table(info) \
885 ((struct frvfdpic_elf_link_hash_table *) ((info)->hash))
887 #define frvfdpic_got_section(info) \
888 (frvfdpic_hash_table (info)->sgot)
889 #define frvfdpic_gotrel_section(info) \
890 (frvfdpic_hash_table (info)->sgotrel)
891 #define frvfdpic_gotfixup_section(info) \
892 (frvfdpic_hash_table (info)->sgotfixup)
893 #define frvfdpic_plt_section(info) \
894 (frvfdpic_hash_table (info)->splt)
895 #define frvfdpic_pltrel_section(info) \
896 (frvfdpic_hash_table (info)->spltrel)
897 #define frvfdpic_relocs_info(info) \
898 (frvfdpic_hash_table (info)->relocs_info)
899 #define frvfdpic_got_initial_offset(info) \
900 (frvfdpic_hash_table (info)->got0)
901 #define frvfdpic_plt_initial_offset(info) \
902 (frvfdpic_hash_table (info)->plt0)
903 #define frvfdpic_dynamic_got_plt_info(info) \
904 (frvfdpic_hash_table (info)->g)
906 /* Currently it's the same, but if some day we have a reason to change
907 it, we'd better be using a different macro.
909 FIXME: if there's any TLS PLT entry that uses local-exec or
910 initial-exec models, we could use the ret at the end of any of them
911 instead of adding one more. */
912 #define frvfdpic_plt_tls_ret_offset(info) \
913 (frvfdpic_plt_initial_offset (info))
915 /* The name of the dynamic interpreter. This is put in the .interp
918 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
920 #define DEFAULT_STACK_SIZE 0x20000
922 /* This structure is used to collect the number of entries present in
923 each addressable range of the got. */
924 struct _frvfdpic_dynamic_got_info
926 /* Several bits of information about the current link. */
927 struct bfd_link_info
*info
;
928 /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit
930 bfd_vma got12
, gotlos
, gothilo
;
931 /* Total GOT size needed for function descriptor entries within the 12-,
932 16- or 32-bit ranges. */
933 bfd_vma fd12
, fdlos
, fdhilo
;
934 /* Total GOT size needed by function descriptor entries referenced
935 in PLT entries, that would be profitable to place in offsets
936 close to the PIC register. */
938 /* Total PLT size needed by lazy PLT entries. */
940 /* Total GOT size needed for TLS descriptor entries within the 12-,
941 16- or 32-bit ranges. */
942 bfd_vma tlsd12
, tlsdlos
, tlsdhilo
;
943 /* Total GOT size needed by TLS descriptors referenced in PLT
944 entries, that would be profitable to place in offers close to the
947 /* Total PLT size needed by TLS lazy PLT entries. */
949 /* Number of relocations carried over from input object files. */
950 unsigned long relocs
;
951 /* Number of fixups introduced by relocations in input object files. */
952 unsigned long fixups
;
953 /* The number of fixups that reference the ret instruction added to
954 the PLT for locally-resolved TLS descriptors. */
955 unsigned long tls_ret_refs
;
958 /* This structure is used to assign offsets to got entries, function
959 descriptors, plt entries and lazy plt entries. */
961 struct _frvfdpic_dynamic_got_plt_info
963 /* Summary information collected with _frvfdpic_count_got_plt_entries. */
964 struct _frvfdpic_dynamic_got_info g
;
966 /* For each addressable range, we record a MAX (positive) and MIN
967 (negative) value. CUR is used to assign got entries, and it's
968 incremented from an initial positive value to MAX, then from MIN
969 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
970 assign function descriptors, and it's decreased from an initial
971 non-positive value to MIN, then from MAX down to CUR (unless CUR
972 wraps around first). All of MIN, MAX, CUR and FDCUR always point
973 to even words. ODD, if non-zero, indicates an odd word to be
974 used for the next got entry, otherwise CUR is used and
975 incremented by a pair of words, wrapping around when it reaches
976 MAX. FDCUR is decremented (and wrapped) before the next function
977 descriptor is chosen. FDPLT indicates the number of remaining
978 slots that can be used for function descriptors used only by PLT
981 TMAX, TMIN and TCUR are used to assign TLS descriptors. TCUR
982 starts as MAX, and grows up to TMAX, then wraps around to TMIN
983 and grows up to MIN. TLSDPLT indicates the number of remaining
984 slots that can be used for TLS descriptors used only by TLS PLT
986 struct _frvfdpic_dynamic_got_alloc_data
988 bfd_signed_vma max
, cur
, odd
, fdcur
, min
;
989 bfd_signed_vma tmax
, tcur
, tmin
;
990 bfd_vma fdplt
, tlsdplt
;
991 } got12
, gotlos
, gothilo
;
994 /* Create an FRV ELF linker hash table. */
996 static struct bfd_link_hash_table
*
997 frvfdpic_elf_link_hash_table_create (bfd
*abfd
)
999 struct frvfdpic_elf_link_hash_table
*ret
;
1000 bfd_size_type amt
= sizeof (struct frvfdpic_elf_link_hash_table
);
1002 ret
= bfd_zalloc (abfd
, amt
);
1006 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1007 _bfd_elf_link_hash_newfunc
,
1008 sizeof (struct elf_link_hash_entry
)))
1014 return &ret
->elf
.root
;
1017 /* Decide whether a reference to a symbol can be resolved locally or
1018 not. If the symbol is protected, we want the local address, but
1019 its function descriptor must be assigned by the dynamic linker. */
1020 #define FRVFDPIC_SYM_LOCAL(INFO, H) \
1021 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
1022 || ! elf_hash_table (INFO)->dynamic_sections_created)
1023 #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \
1024 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
1026 /* This structure collects information on what kind of GOT, PLT or
1027 function descriptors are required by relocations that reference a
1029 struct frvfdpic_relocs_info
1031 /* The index of the symbol, as stored in the relocation r_info, if
1032 we have a local symbol; -1 otherwise. */
1036 /* The input bfd in which the symbol is defined, if it's a local
1039 /* If symndx == -1, the hash table entry corresponding to a global
1040 symbol (even if it turns out to bind locally, in which case it
1041 should ideally be replaced with section's symndx + addend). */
1042 struct elf_link_hash_entry
*h
;
1044 /* The addend of the relocation that references the symbol. */
1047 /* The fields above are used to identify an entry. The fields below
1048 contain information on how an entry is used and, later on, which
1049 locations it was assigned. */
1050 /* The following 3 fields record whether the symbol+addend above was
1051 ever referenced with a GOT relocation. The 12 suffix indicates a
1052 GOT12 relocation; los is used for GOTLO relocations that are not
1053 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
1058 /* Whether a FUNCDESC relocation references symbol+addend. */
1060 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
1062 unsigned fdgotlos
:1;
1063 unsigned fdgothilo
:1;
1064 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
1065 unsigned fdgoff12
:1;
1066 unsigned fdgofflos
:1;
1067 unsigned fdgoffhilo
:1;
1068 /* Whether a GETTLSOFF relocation references symbol+addend. */
1070 /* FIXME: we should probably add tlspltdesc, tlspltoff and
1071 tlspltimm, to tell what kind of TLS PLT entry we're generating.
1072 We might instead just pre-compute flags telling whether the
1073 object is suitable for local exec, initial exec or general
1074 dynamic addressing, and use that all over the place. We could
1075 also try to do a better job of merging TLSOFF and TLSDESC entries
1076 in main executables, but perhaps we can get rid of TLSDESC
1077 entirely in them instead. */
1078 /* Whether a GOTTLSDESC relocation references symbol+addend. */
1079 unsigned tlsdesc12
:1;
1080 unsigned tlsdesclos
:1;
1081 unsigned tlsdeschilo
:1;
1082 /* Whether a GOTTLSOFF relocation references symbol+addend. */
1083 unsigned tlsoff12
:1;
1084 unsigned tlsofflos
:1;
1085 unsigned tlsoffhilo
:1;
1086 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
1087 GOTOFFHI relocations. The addend doesn't really matter, since we
1088 envision that this will only be used to check whether the symbol
1089 is mapped to the same segment as the got. */
1091 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
1093 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
1096 /* Whether we need a PLT entry for a symbol. Should be implied by
1098 (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */
1100 /* Whether a function descriptor should be created in this link unit
1101 for symbol+addend. Should be implied by something like:
1102 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
1103 || ((fd || fdgot12 || fdgotlos || fdgothilo)
1104 && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */
1106 /* Whether a lazy PLT entry is needed for this symbol+addend.
1107 Should be implied by something like:
1108 (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)
1109 && ! (info->flags & DF_BIND_NOW)) */
1111 /* Whether we've already emitted GOT relocations and PLT entries as
1112 needed for this symbol. */
1115 /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and
1116 R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing
1118 unsigned relocs32
, relocsfd
, relocsfdv
, relocstlsd
, relocstlsoff
;
1120 /* The number of .rofixups entries and dynamic relocations allocated
1121 for this symbol, minus any that might have already been used. */
1122 unsigned fixups
, dynrelocs
;
1124 /* The offsets of the GOT entries assigned to symbol+addend, to the
1125 function descriptor's address, and to a function descriptor,
1126 respectively. Should be zero if unassigned. The offsets are
1127 counted from the value that will be assigned to the PIC register,
1128 not from the beginning of the .got section. */
1129 bfd_signed_vma got_entry
, fdgot_entry
, fd_entry
;
1130 /* The offsets of the PLT entries assigned to symbol+addend,
1131 non-lazy and lazy, respectively. If unassigned, should be
1133 bfd_vma plt_entry
, lzplt_entry
;
1134 /* The offsets of the GOT entries for TLS offset and TLS descriptor. */
1135 bfd_signed_vma tlsoff_entry
, tlsdesc_entry
;
1136 /* The offset of the TLS offset PLT entry. */
1137 bfd_vma tlsplt_entry
;
1140 /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */
1142 frvfdpic_relocs_info_hash (const void *entry_
)
1144 const struct frvfdpic_relocs_info
*entry
= entry_
;
1146 return (entry
->symndx
== -1
1147 ? (long) entry
->d
.h
->root
.root
.hash
1148 : entry
->symndx
+ (long) entry
->d
.abfd
->id
* 257) + entry
->addend
;
1151 /* Test whether the key fields of two frvfdpic_relocs_info entries are
1154 frvfdpic_relocs_info_eq (const void *entry1
, const void *entry2
)
1156 const struct frvfdpic_relocs_info
*e1
= entry1
;
1157 const struct frvfdpic_relocs_info
*e2
= entry2
;
1159 return e1
->symndx
== e2
->symndx
&& e1
->addend
== e2
->addend
1160 && (e1
->symndx
== -1 ? e1
->d
.h
== e2
->d
.h
: e1
->d
.abfd
== e2
->d
.abfd
);
1163 /* Find or create an entry in a hash table HT that matches the key
1164 fields of the given ENTRY. If it's not found, memory for a new
1165 entry is allocated in ABFD's obstack. */
1166 static struct frvfdpic_relocs_info
*
1167 frvfdpic_relocs_info_find (struct htab
*ht
,
1169 const struct frvfdpic_relocs_info
*entry
,
1170 enum insert_option insert
)
1172 struct frvfdpic_relocs_info
**loc
=
1173 (struct frvfdpic_relocs_info
**) htab_find_slot (ht
, entry
, insert
);
1181 *loc
= bfd_zalloc (abfd
, sizeof (**loc
));
1186 (*loc
)->symndx
= entry
->symndx
;
1187 (*loc
)->d
= entry
->d
;
1188 (*loc
)->addend
= entry
->addend
;
1189 (*loc
)->plt_entry
= (bfd_vma
)-1;
1190 (*loc
)->lzplt_entry
= (bfd_vma
)-1;
1191 (*loc
)->tlsplt_entry
= (bfd_vma
)-1;
1196 /* Obtain the address of the entry in HT associated with H's symbol +
1197 addend, creating a new entry if none existed. ABFD is only used
1198 for memory allocation purposes. */
1199 inline static struct frvfdpic_relocs_info
*
1200 frvfdpic_relocs_info_for_global (struct htab
*ht
,
1202 struct elf_link_hash_entry
*h
,
1204 enum insert_option insert
)
1206 struct frvfdpic_relocs_info entry
;
1210 entry
.addend
= addend
;
1212 return frvfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1215 /* Obtain the address of the entry in HT associated with the SYMNDXth
1216 local symbol of the input bfd ABFD, plus the addend, creating a new
1217 entry if none existed. */
1218 inline static struct frvfdpic_relocs_info
*
1219 frvfdpic_relocs_info_for_local (struct htab
*ht
,
1223 enum insert_option insert
)
1225 struct frvfdpic_relocs_info entry
;
1227 entry
.symndx
= symndx
;
1228 entry
.d
.abfd
= abfd
;
1229 entry
.addend
= addend
;
1231 return frvfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1234 /* Merge fields set by check_relocs() of two entries that end up being
1235 mapped to the same (presumably global) symbol. */
1238 frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info
*e2
,
1239 struct frvfdpic_relocs_info
const *e1
)
1241 e2
->got12
|= e1
->got12
;
1242 e2
->gotlos
|= e1
->gotlos
;
1243 e2
->gothilo
|= e1
->gothilo
;
1245 e2
->fdgot12
|= e1
->fdgot12
;
1246 e2
->fdgotlos
|= e1
->fdgotlos
;
1247 e2
->fdgothilo
|= e1
->fdgothilo
;
1248 e2
->fdgoff12
|= e1
->fdgoff12
;
1249 e2
->fdgofflos
|= e1
->fdgofflos
;
1250 e2
->fdgoffhilo
|= e1
->fdgoffhilo
;
1251 e2
->tlsplt
|= e1
->tlsplt
;
1252 e2
->tlsdesc12
|= e1
->tlsdesc12
;
1253 e2
->tlsdesclos
|= e1
->tlsdesclos
;
1254 e2
->tlsdeschilo
|= e1
->tlsdeschilo
;
1255 e2
->tlsoff12
|= e1
->tlsoff12
;
1256 e2
->tlsofflos
|= e1
->tlsofflos
;
1257 e2
->tlsoffhilo
|= e1
->tlsoffhilo
;
1258 e2
->gotoff
|= e1
->gotoff
;
1259 e2
->call
|= e1
->call
;
1263 /* Every block of 65535 lazy PLT entries shares a single call to the
1264 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
1265 32767, counting from 0). All other lazy PLT entries branch to it
1266 in a single instruction. */
1268 #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
1269 #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767)
1271 /* Add a dynamic relocation to the SRELOC section. */
1273 inline static bfd_vma
1274 _frvfdpic_add_dyn_reloc (bfd
*output_bfd
, asection
*sreloc
, bfd_vma offset
,
1275 int reloc_type
, long dynindx
, bfd_vma addend
,
1276 struct frvfdpic_relocs_info
*entry
)
1278 Elf_Internal_Rela outrel
;
1279 bfd_vma reloc_offset
;
1281 outrel
.r_offset
= offset
;
1282 outrel
.r_info
= ELF32_R_INFO (dynindx
, reloc_type
);
1283 outrel
.r_addend
= addend
;
1285 reloc_offset
= sreloc
->reloc_count
* sizeof (Elf32_External_Rel
);
1286 BFD_ASSERT (reloc_offset
< sreloc
->size
);
1287 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
1288 sreloc
->contents
+ reloc_offset
);
1289 sreloc
->reloc_count
++;
1291 /* If the entry's index is zero, this relocation was probably to a
1292 linkonce section that got discarded. We reserved a dynamic
1293 relocation, but it was for another entry than the one we got at
1294 the time of emitting the relocation. Unfortunately there's no
1295 simple way for us to catch this situation, since the relocation
1296 is cleared right before calling relocate_section, at which point
1297 we no longer know what the relocation used to point to. */
1300 BFD_ASSERT (entry
->dynrelocs
> 0);
1304 return reloc_offset
;
1307 /* Add a fixup to the ROFIXUP section. */
1310 _frvfdpic_add_rofixup (bfd
*output_bfd
, asection
*rofixup
, bfd_vma offset
,
1311 struct frvfdpic_relocs_info
*entry
)
1313 bfd_vma fixup_offset
;
1315 if (rofixup
->flags
& SEC_EXCLUDE
)
1318 fixup_offset
= rofixup
->reloc_count
* 4;
1319 if (rofixup
->contents
)
1321 BFD_ASSERT (fixup_offset
< rofixup
->size
);
1322 bfd_put_32 (output_bfd
, offset
, rofixup
->contents
+ fixup_offset
);
1324 rofixup
->reloc_count
++;
1326 if (entry
&& entry
->symndx
)
1328 /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc
1330 BFD_ASSERT (entry
->fixups
> 0);
1334 return fixup_offset
;
1337 /* Find the segment number in which OSEC, and output section, is
1341 _frvfdpic_osec_to_segment (bfd
*output_bfd
, asection
*osec
)
1343 struct elf_segment_map
*m
;
1344 Elf_Internal_Phdr
*p
;
1346 /* Find the segment that contains the output_section. */
1347 for (m
= elf_tdata (output_bfd
)->segment_map
,
1348 p
= elf_tdata (output_bfd
)->phdr
;
1354 for (i
= m
->count
- 1; i
>= 0; i
--)
1355 if (m
->sections
[i
] == osec
)
1362 return p
- elf_tdata (output_bfd
)->phdr
;
1365 inline static bfd_boolean
1366 _frvfdpic_osec_readonly_p (bfd
*output_bfd
, asection
*osec
)
1368 unsigned seg
= _frvfdpic_osec_to_segment (output_bfd
, osec
);
1370 return ! (elf_tdata (output_bfd
)->phdr
[seg
].p_flags
& PF_W
);
1373 #define FRVFDPIC_TLS_BIAS (2048 - 16)
1375 /* Return the base VMA address which should be subtracted from real addresses
1376 when resolving TLSMOFF relocation.
1377 This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */
1380 tls_biased_base (struct bfd_link_info
*info
)
1382 /* If tls_sec is NULL, we should have signalled an error already. */
1383 if (elf_hash_table (info
)->tls_sec
== NULL
)
1384 return FRVFDPIC_TLS_BIAS
;
1385 return elf_hash_table (info
)->tls_sec
->vma
+ FRVFDPIC_TLS_BIAS
;
1388 /* Generate relocations for GOT entries, function descriptors, and
1389 code for PLT and lazy PLT entries. */
1391 inline static bfd_boolean
1392 _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info
*entry
,
1394 struct bfd_link_info
*info
,
1396 Elf_Internal_Sym
*sym
,
1400 bfd_vma fd_lazy_rel_offset
= (bfd_vma
)-1;
1407 if (entry
->got_entry
|| entry
->fdgot_entry
|| entry
->fd_entry
1408 || entry
->tlsoff_entry
|| entry
->tlsdesc_entry
)
1410 /* If the symbol is dynamic, consider it for dynamic
1411 relocations, otherwise decay to section + offset. */
1412 if (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1)
1413 dynindx
= entry
->d
.h
->dynindx
;
1416 if (sec
->output_section
1417 && ! bfd_is_abs_section (sec
->output_section
)
1418 && ! bfd_is_und_section (sec
->output_section
))
1419 dynindx
= elf_section_data (sec
->output_section
)->dynindx
;
1425 /* Generate relocation for GOT entry pointing to the symbol. */
1426 if (entry
->got_entry
)
1429 bfd_vma ad
= addend
;
1431 /* If the symbol is dynamic but binds locally, use
1433 if (sec
&& (entry
->symndx
!= -1
1434 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1436 if (entry
->symndx
== -1)
1437 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1439 ad
+= sym
->st_value
;
1440 ad
+= sec
->output_offset
;
1441 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1442 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1447 /* If we're linking an executable at a fixed address, we can
1448 omit the dynamic relocation as long as the symbol is local to
1450 if (info
->executable
&& !info
->pie
1451 && (entry
->symndx
!= -1
1452 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1455 ad
+= sec
->output_section
->vma
;
1456 if (entry
->symndx
!= -1
1457 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1458 _frvfdpic_add_rofixup (output_bfd
,
1459 frvfdpic_gotfixup_section (info
),
1460 frvfdpic_got_section (info
)->output_section
1462 + frvfdpic_got_section (info
)->output_offset
1463 + frvfdpic_got_initial_offset (info
)
1464 + entry
->got_entry
, entry
);
1467 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1468 _bfd_elf_section_offset
1470 frvfdpic_got_section (info
),
1471 frvfdpic_got_initial_offset (info
)
1473 + frvfdpic_got_section (info
)
1474 ->output_section
->vma
1475 + frvfdpic_got_section (info
)->output_offset
,
1476 R_FRV_32
, idx
, ad
, entry
);
1478 bfd_put_32 (output_bfd
, ad
,
1479 frvfdpic_got_section (info
)->contents
1480 + frvfdpic_got_initial_offset (info
)
1481 + entry
->got_entry
);
1484 /* Generate relocation for GOT entry pointing to a canonical
1485 function descriptor. */
1486 if (entry
->fdgot_entry
)
1491 if (! (entry
->symndx
== -1
1492 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
1493 && FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1495 /* If the symbol is dynamic and there may be dynamic symbol
1496 resolution because we are, or are linked with, a shared
1497 library, emit a FUNCDESC relocation such that the dynamic
1498 linker will allocate the function descriptor. If the
1499 symbol needs a non-local function descriptor but binds
1500 locally (e.g., its visibility is protected, emit a
1501 dynamic relocation decayed to section+offset. */
1502 if (entry
->symndx
== -1
1503 && ! FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)
1504 && FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)
1505 && !(info
->executable
&& !info
->pie
))
1507 reloc
= R_FRV_FUNCDESC
;
1508 idx
= elf_section_data (entry
->d
.h
->root
.u
.def
.section
1509 ->output_section
)->dynindx
;
1510 ad
= entry
->d
.h
->root
.u
.def
.section
->output_offset
1511 + entry
->d
.h
->root
.u
.def
.value
;
1513 else if (entry
->symndx
== -1
1514 && ! FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
))
1516 reloc
= R_FRV_FUNCDESC
;
1521 (*info
->callbacks
->reloc_dangerous
)
1522 (info
, _("relocation requires zero addend"),
1523 elf_hash_table (info
)->dynobj
,
1524 frvfdpic_got_section (info
),
1525 entry
->fdgot_entry
);
1531 /* Otherwise, we know we have a private function descriptor,
1532 so reference it directly. */
1533 if (elf_hash_table (info
)->dynamic_sections_created
)
1534 BFD_ASSERT (entry
->privfd
);
1536 idx
= elf_section_data (frvfdpic_got_section (info
)
1537 ->output_section
)->dynindx
;
1538 ad
= frvfdpic_got_section (info
)->output_offset
1539 + frvfdpic_got_initial_offset (info
) + entry
->fd_entry
;
1542 /* If there is room for dynamic symbol resolution, emit the
1543 dynamic relocation. However, if we're linking an
1544 executable at a fixed location, we won't have emitted a
1545 dynamic symbol entry for the got section, so idx will be
1546 zero, which means we can and should compute the address
1547 of the private descriptor ourselves. */
1548 if (info
->executable
&& !info
->pie
1549 && (entry
->symndx
!= -1
1550 || FRVFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)))
1552 ad
+= frvfdpic_got_section (info
)->output_section
->vma
;
1553 _frvfdpic_add_rofixup (output_bfd
,
1554 frvfdpic_gotfixup_section (info
),
1555 frvfdpic_got_section (info
)
1556 ->output_section
->vma
1557 + frvfdpic_got_section (info
)
1559 + frvfdpic_got_initial_offset (info
)
1560 + entry
->fdgot_entry
, entry
);
1563 _frvfdpic_add_dyn_reloc (output_bfd
,
1564 frvfdpic_gotrel_section (info
),
1565 _bfd_elf_section_offset
1567 frvfdpic_got_section (info
),
1568 frvfdpic_got_initial_offset (info
)
1569 + entry
->fdgot_entry
)
1570 + frvfdpic_got_section (info
)
1571 ->output_section
->vma
1572 + frvfdpic_got_section (info
)
1574 reloc
, idx
, ad
, entry
);
1577 bfd_put_32 (output_bfd
, ad
,
1578 frvfdpic_got_section (info
)->contents
1579 + frvfdpic_got_initial_offset (info
)
1580 + entry
->fdgot_entry
);
1583 /* Generate relocation to fill in a private function descriptor in
1585 if (entry
->fd_entry
)
1588 bfd_vma ad
= addend
;
1590 long lowword
, highword
;
1592 /* If the symbol is dynamic but binds locally, use
1594 if (sec
&& (entry
->symndx
!= -1
1595 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1597 if (entry
->symndx
== -1)
1598 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1600 ad
+= sym
->st_value
;
1601 ad
+= sec
->output_offset
;
1602 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1603 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1608 /* If we're linking an executable at a fixed address, we can
1609 omit the dynamic relocation as long as the symbol is local to
1611 if (info
->executable
&& !info
->pie
1612 && (entry
->symndx
!= -1 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1615 ad
+= sec
->output_section
->vma
;
1617 if (entry
->symndx
!= -1
1618 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1620 _frvfdpic_add_rofixup (output_bfd
,
1621 frvfdpic_gotfixup_section (info
),
1622 frvfdpic_got_section (info
)
1623 ->output_section
->vma
1624 + frvfdpic_got_section (info
)
1626 + frvfdpic_got_initial_offset (info
)
1627 + entry
->fd_entry
, entry
);
1628 _frvfdpic_add_rofixup (output_bfd
,
1629 frvfdpic_gotfixup_section (info
),
1630 frvfdpic_got_section (info
)
1631 ->output_section
->vma
1632 + frvfdpic_got_section (info
)
1634 + frvfdpic_got_initial_offset (info
)
1635 + entry
->fd_entry
+ 4, entry
);
1641 _frvfdpic_add_dyn_reloc (output_bfd
,
1643 ? frvfdpic_pltrel_section (info
)
1644 : frvfdpic_gotrel_section (info
),
1645 _bfd_elf_section_offset
1647 frvfdpic_got_section (info
),
1648 frvfdpic_got_initial_offset (info
)
1650 + frvfdpic_got_section (info
)
1651 ->output_section
->vma
1652 + frvfdpic_got_section (info
)
1654 R_FRV_FUNCDESC_VALUE
, idx
, ad
, entry
);
1657 /* If we've omitted the dynamic relocation, just emit the fixed
1658 addresses of the symbol and of the local GOT base offset. */
1659 if (info
->executable
&& !info
->pie
&& sec
&& sec
->output_section
)
1662 highword
= frvfdpic_got_section (info
)->output_section
->vma
1663 + frvfdpic_got_section (info
)->output_offset
1664 + frvfdpic_got_initial_offset (info
);
1666 else if (entry
->lazyplt
)
1670 (*info
->callbacks
->reloc_dangerous
)
1671 (info
, _("relocation requires zero addend"),
1672 elf_hash_table (info
)->dynobj
,
1673 frvfdpic_got_section (info
),
1678 fd_lazy_rel_offset
= ofst
;
1680 /* A function descriptor used for lazy or local resolving is
1681 initialized such that its high word contains the output
1682 section index in which the PLT entries are located, and
1683 the low word contains the address of the lazy PLT entry
1684 entry point, that must be within the memory region
1685 assigned to that section. */
1686 lowword
= entry
->lzplt_entry
+ 4
1687 + frvfdpic_plt_section (info
)->output_offset
1688 + frvfdpic_plt_section (info
)->output_section
->vma
;
1689 highword
= _frvfdpic_osec_to_segment
1690 (output_bfd
, frvfdpic_plt_section (info
)->output_section
);
1694 /* A function descriptor for a local function gets the index
1695 of the section. For a non-local function, it's
1698 if (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1
1699 && entry
->d
.h
->dynindx
== idx
)
1702 highword
= _frvfdpic_osec_to_segment
1703 (output_bfd
, sec
->output_section
);
1706 bfd_put_32 (output_bfd
, lowword
,
1707 frvfdpic_got_section (info
)->contents
1708 + frvfdpic_got_initial_offset (info
)
1710 bfd_put_32 (output_bfd
, highword
,
1711 frvfdpic_got_section (info
)->contents
1712 + frvfdpic_got_initial_offset (info
)
1713 + entry
->fd_entry
+ 4);
1716 /* Generate code for the PLT entry. */
1717 if (entry
->plt_entry
!= (bfd_vma
) -1)
1719 bfd_byte
*plt_code
= frvfdpic_plt_section (info
)->contents
1722 BFD_ASSERT (entry
->fd_entry
);
1724 /* Figure out what kind of PLT entry we need, depending on the
1725 location of the function descriptor within the GOT. */
1726 if (entry
->fd_entry
>= -(1 << (12 - 1))
1727 && entry
->fd_entry
< (1 << (12 - 1)))
1729 /* lddi @(gr15, fd_entry), gr14 */
1730 bfd_put_32 (output_bfd
,
1731 0x9cccf000 | (entry
->fd_entry
& ((1 << 12) - 1)),
1737 if (entry
->fd_entry
>= -(1 << (16 - 1))
1738 && entry
->fd_entry
< (1 << (16 - 1)))
1740 /* setlos lo(fd_entry), gr14 */
1741 bfd_put_32 (output_bfd
,
1743 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1749 /* sethi.p hi(fd_entry), gr14
1750 setlo lo(fd_entry), gr14 */
1751 bfd_put_32 (output_bfd
,
1753 | ((entry
->fd_entry
>> 16)
1754 & (((bfd_vma
)1 << 16) - 1)),
1757 bfd_put_32 (output_bfd
,
1759 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1763 /* ldd @(gr14,gr15),gr14 */
1764 bfd_put_32 (output_bfd
, 0x9c08e14f, plt_code
);
1767 /* jmpl @(gr14,gr0) */
1768 bfd_put_32 (output_bfd
, 0x8030e000, plt_code
);
1771 /* Generate code for the lazy PLT entry. */
1772 if (entry
->lzplt_entry
!= (bfd_vma
) -1)
1774 bfd_byte
*lzplt_code
= frvfdpic_plt_section (info
)->contents
1775 + entry
->lzplt_entry
;
1776 bfd_vma resolverStub_addr
;
1778 bfd_put_32 (output_bfd
, fd_lazy_rel_offset
, lzplt_code
);
1781 resolverStub_addr
= entry
->lzplt_entry
/ FRVFDPIC_LZPLT_BLOCK_SIZE
1782 * FRVFDPIC_LZPLT_BLOCK_SIZE
+ FRVFDPIC_LZPLT_RESOLV_LOC
;
1783 if (resolverStub_addr
>= frvfdpic_plt_initial_offset (info
))
1784 resolverStub_addr
= frvfdpic_plt_initial_offset (info
) - 12;
1786 if (entry
->lzplt_entry
== resolverStub_addr
)
1788 /* This is a lazy PLT entry that includes a resolver call. */
1789 /* ldd @(gr15,gr0), gr4
1791 bfd_put_32 (output_bfd
, 0x8808f140, lzplt_code
);
1792 bfd_put_32 (output_bfd
, 0x80304000, lzplt_code
+ 4);
1796 /* bra resolverStub */
1797 bfd_put_32 (output_bfd
,
1799 | (((resolverStub_addr
- entry
->lzplt_entry
)
1800 / 4) & (((bfd_vma
)1 << 16) - 1)),
1805 /* Generate relocation for GOT entry holding the TLS offset. */
1806 if (entry
->tlsoff_entry
)
1809 bfd_vma ad
= addend
;
1811 if (entry
->symndx
!= -1
1812 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
))
1814 /* If the symbol is dynamic but binds locally, use
1818 if (entry
->symndx
== -1)
1819 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1821 ad
+= sym
->st_value
;
1822 ad
+= sec
->output_offset
;
1823 if (sec
->output_section
1824 && elf_section_data (sec
->output_section
))
1825 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1831 /* *ABS*+addend is special for TLS relocations, use only the
1833 if (info
->executable
1835 && (bfd_is_abs_section (sec
)
1836 || bfd_is_und_section (sec
)))
1838 /* If we're linking an executable, we can entirely omit the
1839 dynamic relocation if the symbol is local to this module. */
1840 else if (info
->executable
1841 && (entry
->symndx
!= -1
1842 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1845 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1850 && (bfd_is_abs_section (sec
)
1851 || bfd_is_und_section (sec
)))
1853 if (! elf_hash_table (info
)->tls_sec
)
1855 (*info
->callbacks
->undefined_symbol
)
1856 (info
, "TLS section", elf_hash_table (info
)->dynobj
,
1857 frvfdpic_got_section (info
), entry
->tlsoff_entry
, TRUE
);
1860 idx
= elf_section_data (elf_hash_table (info
)->tls_sec
)->dynindx
;
1861 ad
+= FRVFDPIC_TLS_BIAS
;
1863 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1864 _bfd_elf_section_offset
1866 frvfdpic_got_section (info
),
1867 frvfdpic_got_initial_offset (info
)
1868 + entry
->tlsoff_entry
)
1869 + frvfdpic_got_section (info
)
1870 ->output_section
->vma
1871 + frvfdpic_got_section (info
)
1873 R_FRV_TLSOFF
, idx
, ad
, entry
);
1876 bfd_put_32 (output_bfd
, ad
,
1877 frvfdpic_got_section (info
)->contents
1878 + frvfdpic_got_initial_offset (info
)
1879 + entry
->tlsoff_entry
);
1882 if (entry
->tlsdesc_entry
)
1885 bfd_vma ad
= addend
;
1887 /* If the symbol is dynamic but binds locally, use
1889 if (sec
&& (entry
->symndx
!= -1
1890 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1892 if (entry
->symndx
== -1)
1893 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1895 ad
+= sym
->st_value
;
1896 ad
+= sec
->output_offset
;
1897 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1898 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1903 /* If we didn't set up a TLS offset entry, but we're linking an
1904 executable and the symbol binds locally, we can use the
1905 module offset in the TLS descriptor in relaxations. */
1906 if (info
->executable
&& ! entry
->tlsoff_entry
)
1907 entry
->tlsoff_entry
= entry
->tlsdesc_entry
+ 4;
1909 if (info
->executable
&& !info
->pie
1911 && (bfd_is_abs_section (sec
)
1912 || bfd_is_und_section (sec
)))
1913 || entry
->symndx
!= -1
1914 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
1916 /* *ABS*+addend is special for TLS relocations, use only the
1917 addend for the TLS offset, and take the module id as
1920 && (bfd_is_abs_section (sec
)
1921 || bfd_is_und_section (sec
)))
1923 /* For other TLS symbols that bind locally, add the section
1924 TLS offset to the addend. */
1926 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
1928 bfd_put_32 (output_bfd
,
1929 frvfdpic_plt_section (info
)->output_section
->vma
1930 + frvfdpic_plt_section (info
)->output_offset
1931 + frvfdpic_plt_tls_ret_offset (info
),
1932 frvfdpic_got_section (info
)->contents
1933 + frvfdpic_got_initial_offset (info
)
1934 + entry
->tlsdesc_entry
);
1936 _frvfdpic_add_rofixup (output_bfd
,
1937 frvfdpic_gotfixup_section (info
),
1938 frvfdpic_got_section (info
)
1939 ->output_section
->vma
1940 + frvfdpic_got_section (info
)
1942 + frvfdpic_got_initial_offset (info
)
1943 + entry
->tlsdesc_entry
, entry
);
1945 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
);
1947 /* We've used one of the reserved fixups, so discount it so
1948 that we can check at the end that we've used them
1950 frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
--;
1952 /* While at that, make sure the ret instruction makes to the
1953 right location in the PLT. We could do it only when we
1954 got to 0, but since the check at the end will only print
1955 a warning, make sure we have the ret in place in case the
1956 warning is missed. */
1957 bfd_put_32 (output_bfd
, 0xc03a4000,
1958 frvfdpic_plt_section (info
)->contents
1959 + frvfdpic_plt_tls_ret_offset (info
));
1964 && (bfd_is_abs_section (sec
)
1965 || bfd_is_und_section (sec
)))
1967 if (! elf_hash_table (info
)->tls_sec
)
1969 (*info
->callbacks
->undefined_symbol
)
1970 (info
, "TLS section", elf_hash_table (info
)->dynobj
,
1971 frvfdpic_got_section (info
), entry
->tlsdesc_entry
, TRUE
);
1974 idx
= elf_section_data (elf_hash_table (info
)->tls_sec
)->dynindx
;
1975 ad
+= FRVFDPIC_TLS_BIAS
;
1978 _frvfdpic_add_dyn_reloc (output_bfd
, frvfdpic_gotrel_section (info
),
1979 _bfd_elf_section_offset
1981 frvfdpic_got_section (info
),
1982 frvfdpic_got_initial_offset (info
)
1983 + entry
->tlsdesc_entry
)
1984 + frvfdpic_got_section (info
)
1985 ->output_section
->vma
1986 + frvfdpic_got_section (info
)
1988 R_FRV_TLSDESC_VALUE
, idx
, ad
, entry
);
1990 bfd_put_32 (output_bfd
, 0,
1991 frvfdpic_got_section (info
)->contents
1992 + frvfdpic_got_initial_offset (info
)
1993 + entry
->tlsdesc_entry
);
1996 bfd_put_32 (output_bfd
, ad
,
1997 frvfdpic_got_section (info
)->contents
1998 + frvfdpic_got_initial_offset (info
)
1999 + entry
->tlsdesc_entry
+ 4);
2002 /* Generate code for the get-TLS-offset PLT entry. */
2003 if (entry
->tlsplt_entry
!= (bfd_vma
) -1)
2005 bfd_byte
*plt_code
= frvfdpic_plt_section (info
)->contents
2006 + entry
->tlsplt_entry
;
2008 if (info
->executable
2009 && (entry
->symndx
!= -1
2010 || FRVFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
2013 bfd_vma ad
= addend
;
2015 /* sec may be NULL when referencing an undefweak symbol
2016 while linking a static executable. */
2019 BFD_ASSERT (entry
->symndx
== -1
2020 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
);
2024 if (entry
->symndx
== -1)
2025 ad
+= entry
->d
.h
->root
.u
.def
.value
;
2027 ad
+= sym
->st_value
;
2028 ad
+= sec
->output_offset
;
2029 if (sec
->output_section
2030 && elf_section_data (sec
->output_section
))
2031 idx
= elf_section_data (sec
->output_section
)->dynindx
;
2036 /* *ABS*+addend is special for TLS relocations, use only the
2037 addend for the TLS offset, and take the module id as
2040 && (bfd_is_abs_section (sec
)
2041 || bfd_is_und_section (sec
)))
2043 /* For other TLS symbols that bind locally, add the section
2044 TLS offset to the addend. */
2046 ad
+= sec
->output_section
->vma
- tls_biased_base (info
);
2048 if ((bfd_signed_vma
)ad
>= -(1 << (16 - 1))
2049 && (bfd_signed_vma
)ad
< (1 << (16 - 1)))
2051 /* setlos lo(ad), gr9 */
2052 bfd_put_32 (output_bfd
,
2055 & (((bfd_vma
)1 << 16) - 1)),
2061 /* sethi.p hi(ad), gr9
2062 setlo lo(ad), gr9 */
2063 bfd_put_32 (output_bfd
,
2066 & (((bfd_vma
)1 << 16) - 1)),
2069 bfd_put_32 (output_bfd
,
2072 & (((bfd_vma
)1 << 16) - 1)),
2077 bfd_put_32 (output_bfd
, 0xc03a4000, plt_code
);
2079 else if (entry
->tlsoff_entry
)
2081 /* Figure out what kind of PLT entry we need, depending on the
2082 location of the TLS descriptor within the GOT. */
2083 if (entry
->tlsoff_entry
>= -(1 << (12 - 1))
2084 && entry
->tlsoff_entry
< (1 << (12 - 1)))
2086 /* ldi @(gr15, tlsoff_entry), gr9 */
2087 bfd_put_32 (output_bfd
,
2088 0x92c8f000 | (entry
->tlsoff_entry
2095 if (entry
->tlsoff_entry
>= -(1 << (16 - 1))
2096 && entry
->tlsoff_entry
< (1 << (16 - 1)))
2098 /* setlos lo(tlsoff_entry), gr8 */
2099 bfd_put_32 (output_bfd
,
2101 | (entry
->tlsoff_entry
2102 & (((bfd_vma
)1 << 16) - 1)),
2108 /* sethi.p hi(tlsoff_entry), gr8
2109 setlo lo(tlsoff_entry), gr8 */
2110 bfd_put_32 (output_bfd
,
2112 | ((entry
->tlsoff_entry
>> 16)
2113 & (((bfd_vma
)1 << 16) - 1)),
2116 bfd_put_32 (output_bfd
,
2118 | (entry
->tlsoff_entry
2119 & (((bfd_vma
)1 << 16) - 1)),
2123 /* ld @(gr15,gr8),gr9 */
2124 bfd_put_32 (output_bfd
, 0x9008f108, plt_code
);
2128 bfd_put_32 (output_bfd
, 0xc03a4000, plt_code
);
2132 BFD_ASSERT (entry
->tlsdesc_entry
);
2134 /* Figure out what kind of PLT entry we need, depending on the
2135 location of the TLS descriptor within the GOT. */
2136 if (entry
->tlsdesc_entry
>= -(1 << (12 - 1))
2137 && entry
->tlsdesc_entry
< (1 << (12 - 1)))
2139 /* lddi @(gr15, tlsdesc_entry), gr8 */
2140 bfd_put_32 (output_bfd
,
2141 0x90ccf000 | (entry
->tlsdesc_entry
2148 if (entry
->tlsdesc_entry
>= -(1 << (16 - 1))
2149 && entry
->tlsdesc_entry
< (1 << (16 - 1)))
2151 /* setlos lo(tlsdesc_entry), gr8 */
2152 bfd_put_32 (output_bfd
,
2154 | (entry
->tlsdesc_entry
2155 & (((bfd_vma
)1 << 16) - 1)),
2161 /* sethi.p hi(tlsdesc_entry), gr8
2162 setlo lo(tlsdesc_entry), gr8 */
2163 bfd_put_32 (output_bfd
,
2165 | ((entry
->tlsdesc_entry
>> 16)
2166 & (((bfd_vma
)1 << 16) - 1)),
2169 bfd_put_32 (output_bfd
,
2171 | (entry
->tlsdesc_entry
2172 & (((bfd_vma
)1 << 16) - 1)),
2176 /* ldd @(gr15,gr8),gr8 */
2177 bfd_put_32 (output_bfd
, 0x9008f148, plt_code
);
2180 /* jmpl @(gr8,gr0) */
2181 bfd_put_32 (output_bfd
, 0x80308000, plt_code
);
2188 /* Handle an FRV small data reloc. */
2190 static bfd_reloc_status_type
2191 elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, relocation
,
2193 struct bfd_link_info
*info
;
2195 asection
*input_section
;
2196 Elf_Internal_Rela
*relocation
;
2202 struct bfd_link_hash_entry
*h
;
2204 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2206 gp
= (h
->u
.def
.value
2207 + h
->u
.def
.section
->output_section
->vma
2208 + h
->u
.def
.section
->output_offset
);
2210 value
-= input_section
->output_section
->vma
;
2211 value
-= (gp
- input_section
->output_section
->vma
);
2213 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2215 value
+= relocation
->r_addend
;
2217 if ((long) value
> 0x7ff || (long) value
< -0x800)
2218 return bfd_reloc_overflow
;
2220 bfd_put_32 (input_bfd
,
2221 (insn
& 0xfffff000) | (value
& 0xfff),
2222 contents
+ relocation
->r_offset
);
2224 return bfd_reloc_ok
;
2227 /* Handle an FRV small data reloc. for the u12 field. */
2229 static bfd_reloc_status_type
2230 elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, relocation
,
2232 struct bfd_link_info
*info
;
2234 asection
*input_section
;
2235 Elf_Internal_Rela
*relocation
;
2241 struct bfd_link_hash_entry
*h
;
2244 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2246 gp
= (h
->u
.def
.value
2247 + h
->u
.def
.section
->output_section
->vma
2248 + h
->u
.def
.section
->output_offset
);
2250 value
-= input_section
->output_section
->vma
;
2251 value
-= (gp
- input_section
->output_section
->vma
);
2253 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2255 value
+= relocation
->r_addend
;
2257 if ((long) value
> 0x7ff || (long) value
< -0x800)
2258 return bfd_reloc_overflow
;
2260 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
2262 insn
= (insn
& ~mask
) | ((value
& 0xfc0) << 12) | (value
& 0x3f);
2264 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2266 return bfd_reloc_ok
;
2269 /* Handle an FRV ELF HI16 reloc. */
2271 static bfd_reloc_status_type
2272 elf32_frv_relocate_hi16 (input_bfd
, relhi
, contents
, value
)
2274 Elf_Internal_Rela
*relhi
;
2280 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
2282 value
+= relhi
->r_addend
;
2283 value
= ((value
>> 16) & 0xffff);
2285 insn
= (insn
& 0xffff0000) | value
;
2287 if ((long) value
> 0xffff || (long) value
< -0x10000)
2288 return bfd_reloc_overflow
;
2290 bfd_put_32 (input_bfd
, insn
, contents
+ relhi
->r_offset
);
2291 return bfd_reloc_ok
;
2294 static bfd_reloc_status_type
2295 elf32_frv_relocate_lo16 (input_bfd
, rello
, contents
, value
)
2297 Elf_Internal_Rela
*rello
;
2303 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2305 value
+= rello
->r_addend
;
2306 value
= value
& 0xffff;
2308 insn
= (insn
& 0xffff0000) | value
;
2310 if ((long) value
> 0xffff || (long) value
< -0x10000)
2311 return bfd_reloc_overflow
;
2313 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
2314 return bfd_reloc_ok
;
2317 /* Perform the relocation for the CALL label24 instruction. */
2319 static bfd_reloc_status_type
2320 elf32_frv_relocate_label24 (input_bfd
, input_section
, rello
, contents
, value
)
2322 asection
*input_section
;
2323 Elf_Internal_Rela
*rello
;
2331 /* The format for the call instruction is:
2333 0 000000 0001111 000000000000000000
2334 label6 opcode label18
2336 The branch calculation is: pc + (4*label24)
2337 where label24 is the concatenation of label6 and label18. */
2339 /* Grab the instruction. */
2340 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2342 value
-= input_section
->output_section
->vma
+ input_section
->output_offset
;
2343 value
-= rello
->r_offset
;
2344 value
+= rello
->r_addend
;
2348 label6
= value
& 0xfc0000;
2349 label6
= label6
<< 7;
2351 label18
= value
& 0x3ffff;
2353 insn
= insn
& 0x803c0000;
2354 insn
= insn
| label6
;
2355 insn
= insn
| label18
;
2357 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
2359 return bfd_reloc_ok
;
2362 static bfd_reloc_status_type
2363 elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, relocation
,
2365 struct bfd_link_info
*info
;
2367 asection
*input_section
;
2368 Elf_Internal_Rela
*relocation
;
2374 struct bfd_link_hash_entry
*h
;
2376 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2378 gp
= (h
->u
.def
.value
2379 + h
->u
.def
.section
->output_section
->vma
2380 + h
->u
.def
.section
->output_offset
);
2382 value
-= input_section
->output_section
->vma
;
2383 value
-= (gp
- input_section
->output_section
->vma
);
2384 value
+= relocation
->r_addend
;
2385 value
= ((value
>> 16) & 0xffff);
2387 if ((long) value
> 0xffff || (long) value
< -0x10000)
2388 return bfd_reloc_overflow
;
2390 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2391 insn
= (insn
& 0xffff0000) | value
;
2393 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2394 return bfd_reloc_ok
;
2397 static bfd_reloc_status_type
2398 elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, relocation
,
2400 struct bfd_link_info
*info
;
2402 asection
*input_section
;
2403 Elf_Internal_Rela
*relocation
;
2409 struct bfd_link_hash_entry
*h
;
2411 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
2413 gp
= (h
->u
.def
.value
2414 + h
->u
.def
.section
->output_section
->vma
2415 + h
->u
.def
.section
->output_offset
);
2417 value
-= input_section
->output_section
->vma
;
2418 value
-= (gp
- input_section
->output_section
->vma
);
2419 value
+= relocation
->r_addend
;
2420 value
= value
& 0xffff;
2422 if ((long) value
> 0xffff || (long) value
< -0x10000)
2423 return bfd_reloc_overflow
;
2425 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
2426 insn
= (insn
& 0xffff0000) | value
;
2428 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
2430 return bfd_reloc_ok
;
2433 static reloc_howto_type
*
2434 frv_reloc_type_lookup (abfd
, code
)
2435 bfd
*abfd ATTRIBUTE_UNUSED
;
2436 bfd_reloc_code_real_type code
;
2443 case BFD_RELOC_NONE
:
2444 return &elf32_frv_howto_table
[ (int) R_FRV_NONE
];
2447 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2448 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2449 return &elf32_frv_rel_32_howto
;
2451 case BFD_RELOC_CTOR
:
2452 return &elf32_frv_howto_table
[ (int) R_FRV_32
];
2454 case BFD_RELOC_FRV_LABEL16
:
2455 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL16
];
2457 case BFD_RELOC_FRV_LABEL24
:
2458 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL24
];
2460 case BFD_RELOC_FRV_LO16
:
2461 return &elf32_frv_howto_table
[ (int) R_FRV_LO16
];
2463 case BFD_RELOC_FRV_HI16
:
2464 return &elf32_frv_howto_table
[ (int) R_FRV_HI16
];
2466 case BFD_RELOC_FRV_GPREL12
:
2467 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL12
];
2469 case BFD_RELOC_FRV_GPRELU12
:
2470 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELU12
];
2472 case BFD_RELOC_FRV_GPREL32
:
2473 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL32
];
2475 case BFD_RELOC_FRV_GPRELHI
:
2476 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELHI
];
2478 case BFD_RELOC_FRV_GPRELLO
:
2479 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELLO
];
2481 case BFD_RELOC_FRV_GOT12
:
2482 return &elf32_frv_howto_table
[ (int) R_FRV_GOT12
];
2484 case BFD_RELOC_FRV_GOTHI
:
2485 return &elf32_frv_howto_table
[ (int) R_FRV_GOTHI
];
2487 case BFD_RELOC_FRV_GOTLO
:
2488 return &elf32_frv_howto_table
[ (int) R_FRV_GOTLO
];
2490 case BFD_RELOC_FRV_FUNCDESC
:
2491 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2492 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2493 return &elf32_frv_rel_funcdesc_howto
;
2494 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC
];
2496 case BFD_RELOC_FRV_FUNCDESC_GOT12
:
2497 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOT12
];
2499 case BFD_RELOC_FRV_FUNCDESC_GOTHI
:
2500 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTHI
];
2502 case BFD_RELOC_FRV_FUNCDESC_GOTLO
:
2503 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTLO
];
2505 case BFD_RELOC_FRV_FUNCDESC_VALUE
:
2506 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2507 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2508 return &elf32_frv_rel_funcdesc_value_howto
;
2509 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_VALUE
];
2511 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12
:
2512 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFF12
];
2514 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI
:
2515 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFHI
];
2517 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO
:
2518 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFLO
];
2520 case BFD_RELOC_FRV_GOTOFF12
:
2521 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFF12
];
2523 case BFD_RELOC_FRV_GOTOFFHI
:
2524 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFHI
];
2526 case BFD_RELOC_FRV_GOTOFFLO
:
2527 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFLO
];
2529 case BFD_RELOC_FRV_GETTLSOFF
:
2530 return &elf32_frv_howto_table
[ (int) R_FRV_GETTLSOFF
];
2532 case BFD_RELOC_FRV_TLSDESC_VALUE
:
2533 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2534 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2535 return &elf32_frv_rel_tlsdesc_value_howto
;
2536 return &elf32_frv_howto_table
[ (int) R_FRV_TLSDESC_VALUE
];
2538 case BFD_RELOC_FRV_GOTTLSDESC12
:
2539 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESC12
];
2541 case BFD_RELOC_FRV_GOTTLSDESCHI
:
2542 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESCHI
];
2544 case BFD_RELOC_FRV_GOTTLSDESCLO
:
2545 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSDESCLO
];
2547 case BFD_RELOC_FRV_TLSMOFF12
:
2548 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFF12
];
2550 case BFD_RELOC_FRV_TLSMOFFHI
:
2551 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFFHI
];
2553 case BFD_RELOC_FRV_TLSMOFFLO
:
2554 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFFLO
];
2556 case BFD_RELOC_FRV_GOTTLSOFF12
:
2557 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFF12
];
2559 case BFD_RELOC_FRV_GOTTLSOFFHI
:
2560 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFFHI
];
2562 case BFD_RELOC_FRV_GOTTLSOFFLO
:
2563 return &elf32_frv_howto_table
[ (int) R_FRV_GOTTLSOFFLO
];
2565 case BFD_RELOC_FRV_TLSOFF
:
2566 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
2567 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
2568 return &elf32_frv_rel_tlsoff_howto
;
2569 return &elf32_frv_howto_table
[ (int) R_FRV_TLSOFF
];
2571 case BFD_RELOC_FRV_TLSDESC_RELAX
:
2572 return &elf32_frv_howto_table
[ (int) R_FRV_TLSDESC_RELAX
];
2574 case BFD_RELOC_FRV_GETTLSOFF_RELAX
:
2575 return &elf32_frv_howto_table
[ (int) R_FRV_GETTLSOFF_RELAX
];
2577 case BFD_RELOC_FRV_TLSOFF_RELAX
:
2578 return &elf32_frv_howto_table
[ (int) R_FRV_TLSOFF_RELAX
];
2580 case BFD_RELOC_FRV_TLSMOFF
:
2581 return &elf32_frv_howto_table
[ (int) R_FRV_TLSMOFF
];
2583 case BFD_RELOC_VTABLE_INHERIT
:
2584 return &elf32_frv_vtinherit_howto
;
2586 case BFD_RELOC_VTABLE_ENTRY
:
2587 return &elf32_frv_vtentry_howto
;
2593 /* Set the howto pointer for an FRV ELF reloc. */
2596 frv_info_to_howto_rela (abfd
, cache_ptr
, dst
)
2597 bfd
*abfd ATTRIBUTE_UNUSED
;
2599 Elf_Internal_Rela
*dst
;
2601 unsigned int r_type
;
2603 r_type
= ELF32_R_TYPE (dst
->r_info
);
2606 case R_FRV_GNU_VTINHERIT
:
2607 cache_ptr
->howto
= &elf32_frv_vtinherit_howto
;
2610 case R_FRV_GNU_VTENTRY
:
2611 cache_ptr
->howto
= &elf32_frv_vtentry_howto
;
2615 cache_ptr
->howto
= & elf32_frv_howto_table
[r_type
];
2620 /* Set the howto pointer for an FRV ELF REL reloc. */
2622 frvfdpic_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
2623 arelent
*cache_ptr
, Elf_Internal_Rela
*dst
)
2625 unsigned int r_type
;
2627 r_type
= ELF32_R_TYPE (dst
->r_info
);
2631 cache_ptr
->howto
= &elf32_frv_rel_32_howto
;
2634 case R_FRV_FUNCDESC
:
2635 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_howto
;
2638 case R_FRV_FUNCDESC_VALUE
:
2639 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_value_howto
;
2642 case R_FRV_TLSDESC_VALUE
:
2643 cache_ptr
->howto
= &elf32_frv_rel_tlsdesc_value_howto
;
2647 cache_ptr
->howto
= &elf32_frv_rel_tlsoff_howto
;
2651 cache_ptr
->howto
= NULL
;
2656 /* Perform a single relocation. By default we use the standard BFD
2657 routines, but a few relocs, we have to do them ourselves. */
2659 static bfd_reloc_status_type
2660 frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
, rel
,
2662 reloc_howto_type
*howto
;
2664 asection
*input_section
;
2666 Elf_Internal_Rela
*rel
;
2669 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2670 contents
, rel
->r_offset
, relocation
,
2675 /* Relocate an FRV ELF section.
2677 The RELOCATE_SECTION function is called by the new ELF backend linker
2678 to handle the relocations for a section.
2680 The relocs are always passed as Rela structures; if the section
2681 actually uses Rel structures, the r_addend field will always be
2684 This function is responsible for adjusting the section contents as
2685 necessary, and (if using Rela relocs and generating a relocatable
2686 output file) adjusting the reloc addend as necessary.
2688 This function does not have to worry about setting the reloc
2689 address or the reloc symbol index.
2691 LOCAL_SYMS is a pointer to the swapped in local symbols.
2693 LOCAL_SECTIONS is an array giving the section in the input file
2694 corresponding to the st_shndx field of each local symbol.
2696 The global hash table entry for the global symbols can be found
2697 via elf_sym_hashes (input_bfd).
2699 When generating relocatable output, this function must handle
2700 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2701 going to be the section symbol corresponding to the output
2702 section, which means that the addend must be adjusted
2706 elf32_frv_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2707 contents
, relocs
, local_syms
, local_sections
)
2708 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2709 struct bfd_link_info
*info
;
2711 asection
*input_section
;
2713 Elf_Internal_Rela
*relocs
;
2714 Elf_Internal_Sym
*local_syms
;
2715 asection
**local_sections
;
2717 Elf_Internal_Shdr
*symtab_hdr
;
2718 struct elf_link_hash_entry
**sym_hashes
;
2719 Elf_Internal_Rela
*rel
;
2720 Elf_Internal_Rela
*relend
;
2721 unsigned isec_segment
, got_segment
, plt_segment
, gprel_segment
, tls_segment
,
2723 int silence_segment_error
= !(info
->shared
|| info
->pie
);
2726 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
2727 sym_hashes
= elf_sym_hashes (input_bfd
);
2728 relend
= relocs
+ input_section
->reloc_count
;
2730 isec_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2731 input_section
->output_section
);
2732 if (IS_FDPIC (output_bfd
) && frvfdpic_got_section (info
))
2733 got_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2734 frvfdpic_got_section (info
)
2738 if (IS_FDPIC (output_bfd
) && frvfdpic_gotfixup_section (info
))
2739 gprel_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2740 frvfdpic_gotfixup_section (info
)
2744 if (IS_FDPIC (output_bfd
) && frvfdpic_plt_section (info
))
2745 plt_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2746 frvfdpic_plt_section (info
)
2750 if (elf_hash_table (info
)->tls_sec
)
2751 tls_segment
= _frvfdpic_osec_to_segment (output_bfd
,
2752 elf_hash_table (info
)->tls_sec
);
2756 for (rel
= relocs
; rel
< relend
; rel
++)
2758 reloc_howto_type
*howto
;
2759 unsigned long r_symndx
;
2760 Elf_Internal_Sym
*sym
;
2762 struct elf_link_hash_entry
*h
;
2764 bfd_reloc_status_type r
;
2765 const char * name
= NULL
;
2768 struct frvfdpic_relocs_info
*picrel
;
2769 bfd_vma orig_addend
= rel
->r_addend
;
2771 r_type
= ELF32_R_TYPE (rel
->r_info
);
2773 if ( r_type
== R_FRV_GNU_VTINHERIT
2774 || r_type
== R_FRV_GNU_VTENTRY
)
2777 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2778 howto
= elf32_frv_howto_table
+ ELF32_R_TYPE (rel
->r_info
);
2783 if (r_symndx
< symtab_hdr
->sh_info
)
2785 sym
= local_syms
+ r_symndx
;
2786 osec
= sec
= local_sections
[r_symndx
];
2787 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2789 name
= bfd_elf_string_from_elf_section
2790 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
2791 name
= (name
== NULL
) ? bfd_section_name (input_bfd
, sec
) : name
;
2796 bfd_boolean unresolved_reloc
;
2798 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2799 r_symndx
, symtab_hdr
, sym_hashes
,
2801 unresolved_reloc
, warned
);
2805 if (sec
!= NULL
&& elf_discarded_section (sec
))
2807 /* For relocs against symbols from removed linkonce sections,
2808 or sections discarded by a linker script, we just want the
2809 section contents zeroed. Avoid any special processing. */
2810 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
2816 if (info
->relocatable
)
2819 if (r_type
!= R_FRV_TLSMOFF
2821 && (h
->root
.type
== bfd_link_hash_defined
2822 || h
->root
.type
== bfd_link_hash_defweak
)
2823 && !FRVFDPIC_SYM_LOCAL (info
, h
))
2833 if (! IS_FDPIC (output_bfd
))
2839 case R_FRV_FUNCDESC_GOT12
:
2840 case R_FRV_FUNCDESC_GOTHI
:
2841 case R_FRV_FUNCDESC_GOTLO
:
2842 case R_FRV_GOTOFF12
:
2843 case R_FRV_GOTOFFHI
:
2844 case R_FRV_GOTOFFLO
:
2845 case R_FRV_FUNCDESC_GOTOFF12
:
2846 case R_FRV_FUNCDESC_GOTOFFHI
:
2847 case R_FRV_FUNCDESC_GOTOFFLO
:
2848 case R_FRV_FUNCDESC
:
2849 case R_FRV_FUNCDESC_VALUE
:
2850 case R_FRV_GETTLSOFF
:
2851 case R_FRV_TLSDESC_VALUE
:
2852 case R_FRV_GOTTLSDESC12
:
2853 case R_FRV_GOTTLSDESCHI
:
2854 case R_FRV_GOTTLSDESCLO
:
2855 case R_FRV_TLSMOFF12
:
2856 case R_FRV_TLSMOFFHI
:
2857 case R_FRV_TLSMOFFLO
:
2858 case R_FRV_GOTTLSOFF12
:
2859 case R_FRV_GOTTLSOFFHI
:
2860 case R_FRV_GOTTLSOFFLO
:
2862 case R_FRV_TLSDESC_RELAX
:
2863 case R_FRV_GETTLSOFF_RELAX
:
2864 case R_FRV_TLSOFF_RELAX
:
2867 picrel
= frvfdpic_relocs_info_for_global (frvfdpic_relocs_info
2868 (info
), input_bfd
, h
,
2869 orig_addend
, INSERT
);
2871 /* In order to find the entry we created before, we must
2872 use the original addend, not the one that may have been
2873 modified by _bfd_elf_rela_local_sym(). */
2874 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
2875 (info
), input_bfd
, r_symndx
,
2876 orig_addend
, INSERT
);
2880 if (!_frvfdpic_emit_got_relocs_plt_entries (picrel
, output_bfd
, info
,
2884 (*_bfd_error_handler
)
2885 (_("%B(%A+0x%x): relocation to `%s+%x' may have caused the error above"),
2886 input_bfd
, input_section
, rel
->r_offset
, name
, rel
->r_addend
);
2895 if (h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
))
2897 info
->callbacks
->warning
2898 (info
, _("relocation references symbol not defined in the module"),
2899 name
, input_bfd
, input_section
, rel
->r_offset
);
2907 case R_FRV_GETTLSOFF
:
2908 case R_FRV_TLSDESC_VALUE
:
2909 case R_FRV_GOTTLSDESC12
:
2910 case R_FRV_GOTTLSDESCHI
:
2911 case R_FRV_GOTTLSDESCLO
:
2912 case R_FRV_TLSMOFF12
:
2913 case R_FRV_TLSMOFFHI
:
2914 case R_FRV_TLSMOFFLO
:
2915 case R_FRV_GOTTLSOFF12
:
2916 case R_FRV_GOTTLSOFFHI
:
2917 case R_FRV_GOTTLSOFFLO
:
2919 case R_FRV_TLSDESC_RELAX
:
2920 case R_FRV_GETTLSOFF_RELAX
:
2921 case R_FRV_TLSOFF_RELAX
:
2923 if (sec
&& (bfd_is_abs_section (sec
) || bfd_is_und_section (sec
)))
2924 relocation
+= tls_biased_base (info
);
2931 /* Try to apply TLS relaxations. */
2936 #define LOCAL_EXEC_P(info, picrel) \
2937 ((info)->executable \
2938 && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h)))
2939 #define INITIAL_EXEC_P(info, picrel) \
2940 (((info)->executable || (info)->flags & DF_STATIC_TLS) \
2941 && (picrel)->tlsoff_entry)
2943 #define IN_RANGE_FOR_OFST12_P(value) \
2944 ((bfd_vma)((value) + 2048) < (bfd_vma)4096)
2945 #define IN_RANGE_FOR_SETLOS_P(value) \
2946 ((bfd_vma)((value) + 32768) < (bfd_vma)65536)
2947 #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \
2948 (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info)))
2950 #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2951 (LOCAL_EXEC_P ((info), (picrel)) \
2952 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2953 #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \
2954 (INITIAL_EXEC_P ((info), (picrel)) \
2955 && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry))
2957 #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \
2958 (LOCAL_EXEC_P ((info), (picrel)))
2959 #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \
2960 (INITIAL_EXEC_P ((info), (picrel)))
2962 #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2963 (LOCAL_EXEC_P ((info), (picrel)) \
2964 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2966 case R_FRV_GETTLSOFF
:
2967 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2969 /* Is this a call instruction? */
2970 if ((insn
& (unsigned long)0x01fc0000) != 0x003c0000)
2972 r
= info
->callbacks
->warning
2974 _("R_FRV_GETTLSOFF not applied to a call instruction"),
2975 name
, input_bfd
, input_section
, rel
->r_offset
);
2979 if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info
, picrel
,
2980 relocation
+ rel
->r_addend
))
2982 /* Replace the call instruction (except the packing bit)
2983 with setlos #tlsmofflo(symbol+offset), gr9. */
2984 insn
&= (unsigned long)0x80000000;
2985 insn
|= (unsigned long)0x12fc0000;
2986 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
2988 r_type
= R_FRV_TLSMOFFLO
;
2989 howto
= elf32_frv_howto_table
+ r_type
;
2990 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
2993 else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info
, picrel
))
2995 /* Replace the call instruction (except the packing bit)
2996 with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */
2997 insn
&= (unsigned long)0x80000000;
2998 insn
|= (unsigned long)0x12c8f000;
2999 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3001 r_type
= R_FRV_GOTTLSOFF12
;
3002 howto
= elf32_frv_howto_table
+ r_type
;
3003 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3008 case R_FRV_GOTTLSDESC12
:
3009 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3011 /* Is this an lddi instruction? */
3012 if ((insn
& (unsigned long)0x01fc0000) != 0x00cc0000)
3014 r
= info
->callbacks
->warning
3016 _("R_FRV_GOTTLSDESC12 not applied to an lddi instruction"),
3017 name
, input_bfd
, input_section
, rel
->r_offset
);
3021 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3022 relocation
+ rel
->r_addend
)
3023 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3026 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3027 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3028 Preserve the packing bit. */
3029 insn
= (insn
& (unsigned long)0x80000000)
3030 | ((insn
+ (unsigned long)0x02000000)
3031 & (unsigned long)0x7e000000);
3032 insn
|= (unsigned long)0x00fc0000;
3033 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3035 r_type
= R_FRV_TLSMOFFLO
;
3036 howto
= elf32_frv_howto_table
+ r_type
;
3037 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3040 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3041 relocation
+ rel
->r_addend
))
3043 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3044 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3045 Preserve the packing bit. */
3046 insn
= (insn
& (unsigned long)0x80000000)
3047 | ((insn
+ (unsigned long)0x02000000)
3048 & (unsigned long)0x7e000000);
3049 insn
|= (unsigned long)0x00f80000;
3050 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3052 r_type
= R_FRV_TLSMOFFHI
;
3053 howto
= elf32_frv_howto_table
+ r_type
;
3054 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3057 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3059 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3060 with ldi @(grB, #gottlsoff12(symbol+offset),
3061 gr<C+1>. Preserve the packing bit. If gottlsoff12
3062 overflows, we'll error out, but that's sort-of ok,
3063 since we'd started with gottlsdesc12, that's actually
3064 more demanding. Compiling with -fPIE instead of
3065 -fpie would fix it; linking with --relax should fix
3067 insn
= (insn
& (unsigned long)0x80cbf000)
3068 | ((insn
+ (unsigned long)0x02000000)
3069 & (unsigned long)0x7e000000);
3070 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3072 r_type
= R_FRV_GOTTLSOFF12
;
3073 howto
= elf32_frv_howto_table
+ r_type
;
3074 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3079 case R_FRV_GOTTLSDESCHI
:
3080 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3082 /* Is this a sethi instruction? */
3083 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3085 r
= info
->callbacks
->warning
3087 _("R_FRV_GOTTLSDESCHI not applied to a sethi instruction"),
3088 name
, input_bfd
, input_section
, rel
->r_offset
);
3092 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3093 relocation
+ rel
->r_addend
)
3094 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3095 && IN_RANGE_FOR_SETLOS_P (picrel
->tlsoff_entry
)))
3097 /* Replace sethi with a nop. Preserve the packing bit. */
3098 insn
&= (unsigned long)0x80000000;
3099 insn
|= (unsigned long)0x00880000;
3100 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3102 /* Nothing to relocate. */
3106 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3108 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3109 r_type
= R_FRV_GOTTLSOFFHI
;
3110 howto
= elf32_frv_howto_table
+ r_type
;
3111 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3116 case R_FRV_GOTTLSDESCLO
:
3117 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3119 /* Is this a setlo or setlos instruction? */
3120 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3122 r
= info
->callbacks
->warning
3124 _("R_FRV_GOTTLSDESCLO"
3125 " not applied to a setlo or setlos instruction"),
3126 name
, input_bfd
, input_section
, rel
->r_offset
);
3130 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3131 relocation
+ rel
->r_addend
)
3132 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3133 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3135 /* Replace setlo/setlos with a nop. Preserve the
3137 insn
&= (unsigned long)0x80000000;
3138 insn
|= (unsigned long)0x00880000;
3139 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3141 /* Nothing to relocate. */
3145 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3147 /* If the corresponding sethi (if it exists) decayed
3148 to a nop, make sure this becomes (or already is) a
3149 setlos, not setlo. */
3150 if (IN_RANGE_FOR_SETLOS_P (picrel
->tlsoff_entry
))
3152 insn
|= (unsigned long)0x00080000;
3153 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3156 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3157 r_type
= R_FRV_GOTTLSOFFLO
;
3158 howto
= elf32_frv_howto_table
+ r_type
;
3159 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3164 case R_FRV_TLSDESC_RELAX
:
3165 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3167 /* Is this an ldd instruction? */
3168 if ((insn
& (unsigned long)0x01fc0fc0) != 0x00080140)
3170 r
= info
->callbacks
->warning
3172 _("R_FRV_TLSDESC_RELAX not applied to an ldd instruction"),
3173 name
, input_bfd
, input_section
, rel
->r_offset
);
3177 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3178 relocation
+ rel
->r_addend
)
3179 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3182 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3183 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3184 Preserve the packing bit. */
3185 insn
= (insn
& (unsigned long)0x80000000)
3186 | ((insn
+ (unsigned long)0x02000000)
3187 & (unsigned long)0x7e000000);
3188 insn
|= (unsigned long)0x00fc0000;
3189 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3191 r_type
= R_FRV_TLSMOFFLO
;
3192 howto
= elf32_frv_howto_table
+ r_type
;
3193 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3196 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3197 relocation
+ rel
->r_addend
))
3199 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3200 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3201 Preserve the packing bit. */
3202 insn
= (insn
& (unsigned long)0x80000000)
3203 | ((insn
+ (unsigned long)0x02000000)
3204 & (unsigned long)0x7e000000);
3205 insn
|= (unsigned long)0x00f80000;
3206 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3208 r_type
= R_FRV_TLSMOFFHI
;
3209 howto
= elf32_frv_howto_table
+ r_type
;
3210 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3213 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3214 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
))
3216 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3217 with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>.
3218 Preserve the packing bit. */
3219 insn
= (insn
& (unsigned long)0x8003f000)
3220 | (unsigned long)0x00c80000
3221 | ((insn
+ (unsigned long)0x02000000)
3222 & (unsigned long)0x7e000000);
3223 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3225 r_type
= R_FRV_GOTTLSOFF12
;
3226 howto
= elf32_frv_howto_table
+ r_type
;
3227 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3230 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3232 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3233 with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>.
3234 Preserve the packing bit. */
3235 insn
= (insn
& (unsigned long)0x81ffffbf)
3236 | ((insn
+ (unsigned long)0x02000000)
3237 & (unsigned long)0x7e000000);
3238 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3240 /* #tlsoff(symbol+offset) is just a relaxation
3241 annotation, so there's nothing left to
3248 case R_FRV_GETTLSOFF_RELAX
:
3249 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3251 /* Is this a calll or callil instruction? */
3252 if ((insn
& (unsigned long)0x7ff80fc0) != 0x02300000)
3254 r
= info
->callbacks
->warning
3256 _("R_FRV_GETTLSOFF_RELAX"
3257 " not applied to a calll instruction"),
3258 name
, input_bfd
, input_section
, rel
->r_offset
);
3262 if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3263 relocation
+ rel
->r_addend
)
3264 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3267 /* Replace calll with a nop. Preserve the packing bit. */
3268 insn
&= (unsigned long)0x80000000;
3269 insn
|= (unsigned long)0x00880000;
3270 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3272 /* Nothing to relocate. */
3276 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info
, picrel
,
3277 relocation
+ rel
->r_addend
))
3279 /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9.
3280 Preserve the packing bit. */
3281 insn
&= (unsigned long)0x80000000;
3282 insn
|= (unsigned long)0x12f40000;
3283 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3285 r_type
= R_FRV_TLSMOFFLO
;
3286 howto
= elf32_frv_howto_table
+ r_type
;
3287 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3290 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
))
3292 /* Replace calll with a nop. Preserve the packing bit. */
3293 insn
&= (unsigned long)0x80000000;
3294 insn
|= (unsigned long)0x00880000;
3295 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3297 /* Nothing to relocate. */
3303 case R_FRV_GOTTLSOFF12
:
3304 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3306 /* Is this an ldi instruction? */
3307 if ((insn
& (unsigned long)0x01fc0000) != 0x00c80000)
3309 r
= info
->callbacks
->warning
3311 _("R_FRV_GOTTLSOFF12 not applied to an ldi instruction"),
3312 name
, input_bfd
, input_section
, rel
->r_offset
);
3316 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3317 relocation
+ rel
->r_addend
))
3319 /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC
3320 with setlos #tlsmofflo(symbol+offset), grC.
3321 Preserve the packing bit. */
3322 insn
&= (unsigned long)0xfe000000;
3323 insn
|= (unsigned long)0x00fc0000;
3324 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3326 r_type
= R_FRV_TLSMOFFLO
;
3327 howto
= elf32_frv_howto_table
+ r_type
;
3328 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3333 case R_FRV_GOTTLSOFFHI
:
3334 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3336 /* Is this a sethi instruction? */
3337 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3339 r
= info
->callbacks
->warning
3341 _("R_FRV_GOTTLSOFFHI not applied to a sethi instruction"),
3342 name
, input_bfd
, input_section
, rel
->r_offset
);
3346 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3347 relocation
+ rel
->r_addend
)
3348 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3349 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3351 /* Replace sethi with a nop. Preserve the packing bit. */
3352 insn
&= (unsigned long)0x80000000;
3353 insn
|= (unsigned long)0x00880000;
3354 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3356 /* Nothing to relocate. */
3362 case R_FRV_GOTTLSOFFLO
:
3363 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3365 /* Is this a setlo or setlos instruction? */
3366 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3368 r
= info
->callbacks
->warning
3370 _("R_FRV_GOTTLSOFFLO"
3371 " not applied to a setlo or setlos instruction"),
3372 name
, input_bfd
, input_section
, rel
->r_offset
);
3376 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3377 relocation
+ rel
->r_addend
)
3378 || (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3379 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
)))
3381 /* Replace setlo/setlos with a nop. Preserve the
3383 insn
&= (unsigned long)0x80000000;
3384 insn
|= (unsigned long)0x00880000;
3385 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3387 /* Nothing to relocate. */
3393 case R_FRV_TLSOFF_RELAX
:
3394 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3396 /* Is this an ld instruction? */
3397 if ((insn
& (unsigned long)0x01fc0fc0) != 0x00080100)
3399 r
= info
->callbacks
->warning
3401 _("R_FRV_TLSOFF_RELAX not applied to an ld instruction"),
3402 name
, input_bfd
, input_section
, rel
->r_offset
);
3406 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info
, picrel
,
3407 relocation
+ rel
->r_addend
))
3409 /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC
3410 with setlos #tlsmofflo(symbol+offset), grC.
3411 Preserve the packing bit. */
3412 insn
&= (unsigned long)0xfe000000;
3413 insn
|= (unsigned long)0x00fc0000;
3414 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3416 r_type
= R_FRV_TLSMOFFLO
;
3417 howto
= elf32_frv_howto_table
+ r_type
;
3418 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3421 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info
, picrel
)
3422 && IN_RANGE_FOR_OFST12_P (picrel
->tlsoff_entry
))
3424 /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC
3425 with ldi @(grB, #gottlsoff12(symbol+offset), grC.
3426 Preserve the packing bit. */
3427 insn
= (insn
& (unsigned long)0xfe03f000)
3428 | (unsigned long)0x00c80000;;
3429 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3431 r_type
= R_FRV_GOTTLSOFF12
;
3432 howto
= elf32_frv_howto_table
+ r_type
;
3433 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
3438 case R_FRV_TLSMOFFHI
:
3439 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3441 /* Is this a sethi instruction? */
3442 if ((insn
& (unsigned long)0x01ff0000) != 0x00f80000)
3444 r
= info
->callbacks
->warning
3446 _("R_FRV_TLSMOFFHI not applied to a sethi instruction"),
3447 name
, input_bfd
, input_section
, rel
->r_offset
);
3451 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3454 /* Replace sethi with a nop. Preserve the packing bit. */
3455 insn
&= (unsigned long)0x80000000;
3456 insn
|= (unsigned long)0x00880000;
3457 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3459 /* Nothing to relocate. */
3465 case R_FRV_TLSMOFFLO
:
3466 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3468 /* Is this a setlo or setlos instruction? */
3469 if ((insn
& (unsigned long)0x01f70000) != 0x00f40000)
3471 r
= info
->callbacks
->warning
3474 " not applied to a setlo or setlos instruction"),
3475 name
, input_bfd
, input_section
, rel
->r_offset
);
3479 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation
+ rel
->r_addend
,
3481 /* If the corresponding sethi (if it exists) decayed
3482 to a nop, make sure this becomes (or already is) a
3483 setlos, not setlo. */
3485 insn
|= (unsigned long)0x00080000;
3486 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
3492 There's nothing to relax in these:
3508 check_segment
[0] = isec_segment
;
3509 if (! IS_FDPIC (output_bfd
))
3510 check_segment
[1] = isec_segment
;
3511 else if (picrel
->plt
)
3513 relocation
= frvfdpic_plt_section (info
)->output_section
->vma
3514 + frvfdpic_plt_section (info
)->output_offset
3515 + picrel
->plt_entry
;
3516 check_segment
[1] = plt_segment
;
3518 /* We don't want to warn on calls to undefined weak symbols,
3519 as calls to them must be protected by non-NULL tests
3520 anyway, and unprotected calls would invoke undefined
3522 else if (picrel
->symndx
== -1
3523 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefweak
)
3524 check_segment
[1] = check_segment
[0];
3526 check_segment
[1] = sec
3527 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3534 relocation
= picrel
->got_entry
;
3535 check_segment
[0] = check_segment
[1] = got_segment
;
3538 case R_FRV_FUNCDESC_GOT12
:
3539 case R_FRV_FUNCDESC_GOTHI
:
3540 case R_FRV_FUNCDESC_GOTLO
:
3541 relocation
= picrel
->fdgot_entry
;
3542 check_segment
[0] = check_segment
[1] = got_segment
;
3545 case R_FRV_GOTOFFHI
:
3546 case R_FRV_GOTOFF12
:
3547 case R_FRV_GOTOFFLO
:
3548 relocation
-= frvfdpic_got_section (info
)->output_section
->vma
3549 + frvfdpic_got_section (info
)->output_offset
3550 + frvfdpic_got_initial_offset (info
);
3551 check_segment
[0] = got_segment
;
3552 check_segment
[1] = sec
3553 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3557 case R_FRV_FUNCDESC_GOTOFF12
:
3558 case R_FRV_FUNCDESC_GOTOFFHI
:
3559 case R_FRV_FUNCDESC_GOTOFFLO
:
3560 relocation
= picrel
->fd_entry
;
3561 check_segment
[0] = check_segment
[1] = got_segment
;
3564 case R_FRV_FUNCDESC
:
3567 bfd_vma addend
= rel
->r_addend
;
3569 if (! (h
&& h
->root
.type
== bfd_link_hash_undefweak
3570 && FRVFDPIC_SYM_LOCAL (info
, h
)))
3572 /* If the symbol is dynamic and there may be dynamic
3573 symbol resolution because we are or are linked with a
3574 shared library, emit a FUNCDESC relocation such that
3575 the dynamic linker will allocate the function
3576 descriptor. If the symbol needs a non-local function
3577 descriptor but binds locally (e.g., its visibility is
3578 protected, emit a dynamic relocation decayed to
3580 if (h
&& ! FRVFDPIC_FUNCDESC_LOCAL (info
, h
)
3581 && FRVFDPIC_SYM_LOCAL (info
, h
)
3582 && !(info
->executable
&& !info
->pie
))
3584 dynindx
= elf_section_data (h
->root
.u
.def
.section
3585 ->output_section
)->dynindx
;
3586 addend
+= h
->root
.u
.def
.section
->output_offset
3587 + h
->root
.u
.def
.value
;
3589 else if (h
&& ! FRVFDPIC_FUNCDESC_LOCAL (info
, h
))
3593 info
->callbacks
->warning
3594 (info
, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"),
3595 name
, input_bfd
, input_section
, rel
->r_offset
);
3598 dynindx
= h
->dynindx
;
3602 /* Otherwise, we know we have a private function
3603 descriptor, so reference it directly. */
3604 BFD_ASSERT (picrel
->privfd
);
3606 dynindx
= elf_section_data (frvfdpic_got_section (info
)
3607 ->output_section
)->dynindx
;
3608 addend
= frvfdpic_got_section (info
)->output_offset
3609 + frvfdpic_got_initial_offset (info
)
3613 /* If there is room for dynamic symbol resolution, emit
3614 the dynamic relocation. However, if we're linking an
3615 executable at a fixed location, we won't have emitted a
3616 dynamic symbol entry for the got section, so idx will
3617 be zero, which means we can and should compute the
3618 address of the private descriptor ourselves. */
3619 if (info
->executable
&& !info
->pie
3620 && (!h
|| FRVFDPIC_FUNCDESC_LOCAL (info
, h
)))
3622 addend
+= frvfdpic_got_section (info
)->output_section
->vma
;
3623 if ((bfd_get_section_flags (output_bfd
,
3624 input_section
->output_section
)
3625 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3627 if (_frvfdpic_osec_readonly_p (output_bfd
,
3631 info
->callbacks
->warning
3633 _("cannot emit fixups in read-only section"),
3634 name
, input_bfd
, input_section
, rel
->r_offset
);
3637 _frvfdpic_add_rofixup (output_bfd
,
3638 frvfdpic_gotfixup_section
3640 _bfd_elf_section_offset
3642 input_section
, rel
->r_offset
)
3644 ->output_section
->vma
3645 + input_section
->output_offset
,
3649 else if ((bfd_get_section_flags (output_bfd
,
3650 input_section
->output_section
)
3651 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3653 if (_frvfdpic_osec_readonly_p (output_bfd
,
3657 info
->callbacks
->warning
3659 _("cannot emit dynamic relocations in read-only section"),
3660 name
, input_bfd
, input_section
, rel
->r_offset
);
3663 _frvfdpic_add_dyn_reloc (output_bfd
,
3664 frvfdpic_gotrel_section (info
),
3665 _bfd_elf_section_offset
3667 input_section
, rel
->r_offset
)
3669 ->output_section
->vma
3670 + input_section
->output_offset
,
3671 r_type
, dynindx
, addend
, picrel
);
3674 addend
+= frvfdpic_got_section (info
)->output_section
->vma
;
3677 /* We want the addend in-place because dynamic
3678 relocations are REL. Setting relocation to it should
3679 arrange for it to be installed. */
3680 relocation
= addend
- rel
->r_addend
;
3682 check_segment
[0] = check_segment
[1] = got_segment
;
3686 if (! IS_FDPIC (output_bfd
))
3688 check_segment
[0] = check_segment
[1] = -1;
3692 case R_FRV_FUNCDESC_VALUE
:
3695 bfd_vma addend
= rel
->r_addend
;
3697 /* If the symbol is dynamic but binds locally, use
3699 if (h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
))
3701 if (addend
&& r_type
== R_FRV_FUNCDESC_VALUE
)
3703 info
->callbacks
->warning
3704 (info
, _("R_FRV_FUNCDESC_VALUE references dynamic symbol with nonzero addend"),
3705 name
, input_bfd
, input_section
, rel
->r_offset
);
3708 dynindx
= h
->dynindx
;
3713 addend
+= h
->root
.u
.def
.value
;
3715 addend
+= sym
->st_value
;
3717 addend
+= osec
->output_offset
;
3718 if (osec
&& osec
->output_section
3719 && ! bfd_is_abs_section (osec
->output_section
)
3720 && ! bfd_is_und_section (osec
->output_section
))
3721 dynindx
= elf_section_data (osec
->output_section
)->dynindx
;
3726 /* If we're linking an executable at a fixed address, we
3727 can omit the dynamic relocation as long as the symbol
3728 is defined in the current link unit (which is implied
3729 by its output section not being NULL). */
3730 if (info
->executable
&& !info
->pie
3731 && (!h
|| FRVFDPIC_SYM_LOCAL (info
, h
)))
3734 addend
+= osec
->output_section
->vma
;
3735 if (IS_FDPIC (input_bfd
)
3736 && (bfd_get_section_flags (output_bfd
,
3737 input_section
->output_section
)
3738 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3740 if (_frvfdpic_osec_readonly_p (output_bfd
,
3744 info
->callbacks
->warning
3746 _("cannot emit fixups in read-only section"),
3747 name
, input_bfd
, input_section
, rel
->r_offset
);
3750 if (!h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
3752 _frvfdpic_add_rofixup (output_bfd
,
3753 frvfdpic_gotfixup_section
3755 _bfd_elf_section_offset
3757 input_section
, rel
->r_offset
)
3759 ->output_section
->vma
3760 + input_section
->output_offset
,
3762 if (r_type
== R_FRV_FUNCDESC_VALUE
)
3763 _frvfdpic_add_rofixup
3765 frvfdpic_gotfixup_section (info
),
3766 _bfd_elf_section_offset
3768 input_section
, rel
->r_offset
)
3769 + input_section
->output_section
->vma
3770 + input_section
->output_offset
+ 4, picrel
);
3776 if ((bfd_get_section_flags (output_bfd
,
3777 input_section
->output_section
)
3778 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3780 if (_frvfdpic_osec_readonly_p (output_bfd
,
3784 info
->callbacks
->warning
3786 _("cannot emit dynamic relocations in read-only section"),
3787 name
, input_bfd
, input_section
, rel
->r_offset
);
3790 _frvfdpic_add_dyn_reloc (output_bfd
,
3791 frvfdpic_gotrel_section (info
),
3792 _bfd_elf_section_offset
3794 input_section
, rel
->r_offset
)
3796 ->output_section
->vma
3797 + input_section
->output_offset
,
3798 r_type
, dynindx
, addend
, picrel
);
3801 addend
+= osec
->output_section
->vma
;
3802 /* We want the addend in-place because dynamic
3803 relocations are REL. Setting relocation to it
3804 should arrange for it to be installed. */
3805 relocation
= addend
- rel
->r_addend
;
3808 if (r_type
== R_FRV_FUNCDESC_VALUE
)
3810 /* If we've omitted the dynamic relocation, just emit
3811 the fixed addresses of the symbol and of the local
3813 if (info
->executable
&& !info
->pie
3814 && (!h
|| FRVFDPIC_SYM_LOCAL (info
, h
)))
3815 bfd_put_32 (output_bfd
,
3816 frvfdpic_got_section (info
)->output_section
->vma
3817 + frvfdpic_got_section (info
)->output_offset
3818 + frvfdpic_got_initial_offset (info
),
3819 contents
+ rel
->r_offset
+ 4);
3821 /* A function descriptor used for lazy or local
3822 resolving is initialized such that its high word
3823 contains the output section index in which the
3824 PLT entries are located, and the low word
3825 contains the offset of the lazy PLT entry entry
3826 point into that section. */
3827 bfd_put_32 (output_bfd
,
3828 h
&& ! FRVFDPIC_SYM_LOCAL (info
, h
)
3830 : _frvfdpic_osec_to_segment (output_bfd
,
3833 contents
+ rel
->r_offset
+ 4);
3836 check_segment
[0] = check_segment
[1] = got_segment
;
3840 case R_FRV_GPRELU12
:
3844 check_segment
[0] = gprel_segment
;
3845 check_segment
[1] = sec
3846 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3850 case R_FRV_GETTLSOFF
:
3851 relocation
= frvfdpic_plt_section (info
)->output_section
->vma
3852 + frvfdpic_plt_section (info
)->output_offset
3853 + picrel
->tlsplt_entry
;
3854 BFD_ASSERT (picrel
->tlsplt_entry
!= (bfd_vma
)-1
3855 && picrel
->tlsdesc_entry
);
3856 check_segment
[0] = isec_segment
;
3857 check_segment
[1] = plt_segment
;
3860 case R_FRV_GOTTLSDESC12
:
3861 case R_FRV_GOTTLSDESCHI
:
3862 case R_FRV_GOTTLSDESCLO
:
3863 BFD_ASSERT (picrel
->tlsdesc_entry
);
3864 relocation
= picrel
->tlsdesc_entry
;
3865 check_segment
[0] = tls_segment
;
3866 check_segment
[1] = sec
3867 && ! bfd_is_abs_section (sec
)
3868 && ! bfd_is_und_section (sec
)
3869 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3873 case R_FRV_TLSMOFF12
:
3874 case R_FRV_TLSMOFFHI
:
3875 case R_FRV_TLSMOFFLO
:
3877 check_segment
[0] = tls_segment
;
3879 check_segment
[1] = -1;
3880 else if (bfd_is_abs_section (sec
)
3881 || bfd_is_und_section (sec
))
3884 check_segment
[1] = tls_segment
;
3886 else if (sec
->output_section
)
3888 relocation
-= tls_biased_base (info
);
3890 _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
);
3893 check_segment
[1] = -1;
3896 case R_FRV_GOTTLSOFF12
:
3897 case R_FRV_GOTTLSOFFHI
:
3898 case R_FRV_GOTTLSOFFLO
:
3899 BFD_ASSERT (picrel
->tlsoff_entry
);
3900 relocation
= picrel
->tlsoff_entry
;
3901 check_segment
[0] = tls_segment
;
3902 check_segment
[1] = sec
3903 && ! bfd_is_abs_section (sec
)
3904 && ! bfd_is_und_section (sec
)
3905 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3909 case R_FRV_TLSDESC_VALUE
:
3911 /* These shouldn't be present in input object files. */
3912 check_segment
[0] = check_segment
[1] = isec_segment
;
3915 case R_FRV_TLSDESC_RELAX
:
3916 case R_FRV_GETTLSOFF_RELAX
:
3917 case R_FRV_TLSOFF_RELAX
:
3918 /* These are just annotations for relaxation, nothing to do
3923 check_segment
[0] = isec_segment
;
3924 check_segment
[1] = sec
3925 ? _frvfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3930 if (check_segment
[0] != check_segment
[1] && IS_FDPIC (output_bfd
))
3932 /* If you take this out, remove the #error from fdpic-static-6.d
3933 in the ld testsuite. */
3934 /* This helps catch problems in GCC while we can't do more
3935 than static linking. The idea is to test whether the
3936 input file basename is crt0.o only once. */
3937 if (silence_segment_error
== 1)
3938 silence_segment_error
=
3939 (strlen (input_bfd
->filename
) == 6
3940 && strcmp (input_bfd
->filename
, "crt0.o") == 0)
3941 || (strlen (input_bfd
->filename
) > 6
3942 && strcmp (input_bfd
->filename
3943 + strlen (input_bfd
->filename
) - 7,
3946 if (!silence_segment_error
3947 /* We don't want duplicate errors for undefined
3949 && !(picrel
&& picrel
->symndx
== -1
3950 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefined
))
3952 if (info
->shared
|| info
->pie
)
3953 (*_bfd_error_handler
)
3954 (_("%B(%A+0x%lx): reloc against `%s': %s"),
3955 input_bfd
, input_section
, (long)rel
->r_offset
, name
,
3956 _("relocation references a different segment"));
3958 info
->callbacks
->warning
3960 _("relocation references a different segment"),
3961 name
, input_bfd
, input_section
, rel
->r_offset
);
3963 if (!silence_segment_error
&& (info
->shared
|| info
->pie
))
3965 elf_elfheader (output_bfd
)->e_flags
|= EF_FRV_PIC
;
3970 case R_FRV_GOTOFFHI
:
3971 case R_FRV_TLSMOFFHI
:
3972 /* We need the addend to be applied before we shift the
3974 relocation
+= rel
->r_addend
;
3977 case R_FRV_FUNCDESC_GOTHI
:
3978 case R_FRV_FUNCDESC_GOTOFFHI
:
3979 case R_FRV_GOTTLSOFFHI
:
3980 case R_FRV_GOTTLSDESCHI
:
3985 case R_FRV_FUNCDESC_GOTLO
:
3986 case R_FRV_GOTOFFLO
:
3987 case R_FRV_FUNCDESC_GOTOFFLO
:
3988 case R_FRV_GOTTLSOFFLO
:
3989 case R_FRV_GOTTLSDESCLO
:
3990 case R_FRV_TLSMOFFLO
:
3991 relocation
&= 0xffff;
4001 if (! IS_FDPIC (output_bfd
) || ! picrel
->plt
)
4005 /* When referencing a GOT entry, a function descriptor or a
4006 PLT, we don't want the addend to apply to the reference,
4007 but rather to the referenced symbol. The actual entry
4008 will have already been created taking the addend into
4009 account, so cancel it out here. */
4013 case R_FRV_FUNCDESC_GOT12
:
4014 case R_FRV_FUNCDESC_GOTHI
:
4015 case R_FRV_FUNCDESC_GOTLO
:
4016 case R_FRV_FUNCDESC_GOTOFF12
:
4017 case R_FRV_FUNCDESC_GOTOFFHI
:
4018 case R_FRV_FUNCDESC_GOTOFFLO
:
4019 case R_FRV_GETTLSOFF
:
4020 case R_FRV_GOTTLSDESC12
:
4021 case R_FRV_GOTTLSDESCHI
:
4022 case R_FRV_GOTTLSDESCLO
:
4023 case R_FRV_GOTTLSOFF12
:
4024 case R_FRV_GOTTLSOFFHI
:
4025 case R_FRV_GOTTLSOFFLO
:
4026 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
4027 here, since we do want to apply the addend to the others.
4028 Note that we've applied the addend to GOTOFFHI before we
4029 shifted it right. */
4030 case R_FRV_GOTOFFHI
:
4031 case R_FRV_TLSMOFFHI
:
4032 relocation
-= rel
->r_addend
;
4039 if (r_type
== R_FRV_HI16
)
4040 r
= elf32_frv_relocate_hi16 (input_bfd
, rel
, contents
, relocation
);
4042 else if (r_type
== R_FRV_LO16
)
4043 r
= elf32_frv_relocate_lo16 (input_bfd
, rel
, contents
, relocation
);
4045 else if (r_type
== R_FRV_LABEL24
|| r_type
== R_FRV_GETTLSOFF
)
4046 r
= elf32_frv_relocate_label24 (input_bfd
, input_section
, rel
,
4047 contents
, relocation
);
4049 else if (r_type
== R_FRV_GPREL12
)
4050 r
= elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, rel
,
4051 contents
, relocation
);
4053 else if (r_type
== R_FRV_GPRELU12
)
4054 r
= elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, rel
,
4055 contents
, relocation
);
4057 else if (r_type
== R_FRV_GPRELLO
)
4058 r
= elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, rel
,
4059 contents
, relocation
);
4061 else if (r_type
== R_FRV_GPRELHI
)
4062 r
= elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, rel
,
4063 contents
, relocation
);
4065 else if (r_type
== R_FRV_TLSOFF
4066 || r_type
== R_FRV_TLSDESC_VALUE
)
4067 r
= bfd_reloc_notsupported
;
4070 r
= frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
4073 if (r
!= bfd_reloc_ok
)
4075 const char * msg
= (const char *) NULL
;
4079 case bfd_reloc_overflow
:
4080 r
= info
->callbacks
->reloc_overflow
4081 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4082 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
4085 case bfd_reloc_undefined
:
4086 r
= info
->callbacks
->undefined_symbol
4087 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
4090 case bfd_reloc_outofrange
:
4091 msg
= _("internal error: out of range error");
4094 case bfd_reloc_notsupported
:
4095 msg
= _("internal error: unsupported relocation error");
4098 case bfd_reloc_dangerous
:
4099 msg
= _("internal error: dangerous relocation");
4103 msg
= _("internal error: unknown error");
4109 (*_bfd_error_handler
)
4110 (_("%B(%A+0x%lx): reloc against `%s': %s"),
4111 input_bfd
, input_section
, (long)rel
->r_offset
, name
, msg
);
4123 /* Return the section that should be marked against GC for a given
4127 elf32_frv_gc_mark_hook (asection
*sec
,
4128 struct bfd_link_info
*info
,
4129 Elf_Internal_Rela
*rel
,
4130 struct elf_link_hash_entry
*h
,
4131 Elf_Internal_Sym
*sym
)
4134 switch (ELF32_R_TYPE (rel
->r_info
))
4136 case R_FRV_GNU_VTINHERIT
:
4137 case R_FRV_GNU_VTENTRY
:
4141 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
4144 /* Hook called by the linker routine which adds symbols from an object
4145 file. We use it to put .comm items in .scomm, and not .comm. */
4148 elf32_frv_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
4150 struct bfd_link_info
*info
;
4151 Elf_Internal_Sym
*sym
;
4152 const char **namep ATTRIBUTE_UNUSED
;
4153 flagword
*flagsp ATTRIBUTE_UNUSED
;
4157 if (sym
->st_shndx
== SHN_COMMON
4158 && !info
->relocatable
4159 && (int)sym
->st_size
<= (int)bfd_get_gp_size (abfd
))
4161 /* Common symbols less than or equal to -G nn bytes are
4162 automatically put into .sbss. */
4164 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
4168 scomm
= bfd_make_section_with_flags (abfd
, ".scommon",
4171 | SEC_LINKER_CREATED
));
4177 *valp
= sym
->st_size
;
4183 /* We need dynamic symbols for every section, since segments can
4184 relocate independently. */
4186 _frvfdpic_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4187 struct bfd_link_info
*info
4189 asection
*p ATTRIBUTE_UNUSED
)
4191 switch (elf_section_data (p
)->this_hdr
.sh_type
)
4195 /* If sh_type is yet undecided, assume it could be
4196 SHT_PROGBITS/SHT_NOBITS. */
4200 /* There shouldn't be section relative relocations
4201 against any other section. */
4207 /* Create a .got section, as well as its additional info field. This
4208 is almost entirely copied from
4209 elflink.c:_bfd_elf_create_got_section(). */
4212 _frv_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4214 flagword flags
, pltflags
;
4216 struct elf_link_hash_entry
*h
;
4217 struct bfd_link_hash_entry
*bh
;
4218 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4222 /* This function may be called more than once. */
4223 s
= bfd_get_section_by_name (abfd
, ".got");
4224 if (s
!= NULL
&& (s
->flags
& SEC_LINKER_CREATED
) != 0)
4227 /* Machine specific: although pointers are 32-bits wide, we want the
4228 GOT to be aligned to a 64-bit boundary, such that function
4229 descriptors in it can be accessed with 64-bit loads and
4233 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4234 | SEC_LINKER_CREATED
);
4237 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
4239 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
4242 if (bed
->want_got_plt
)
4244 s
= bfd_make_section_with_flags (abfd
, ".got.plt", flags
);
4246 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
4250 if (bed
->want_got_sym
)
4252 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
4253 (or .got.plt) section. We don't do this in the linker script
4254 because we don't want to define the symbol if we are not creating
4255 a global offset table. */
4256 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
, "_GLOBAL_OFFSET_TABLE_");
4257 elf_hash_table (info
)->hgot
= h
;
4261 /* Machine-specific: we want the symbol for executables as
4263 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4267 /* The first bit of the global offset table is the header. */
4268 s
->size
+= bed
->got_header_size
;
4270 /* This is the machine-specific part. Create and initialize section
4271 data for the got. */
4272 if (IS_FDPIC (abfd
))
4274 frvfdpic_got_section (info
) = s
;
4275 frvfdpic_relocs_info (info
) = htab_try_create (1,
4276 frvfdpic_relocs_info_hash
,
4277 frvfdpic_relocs_info_eq
,
4279 if (! frvfdpic_relocs_info (info
))
4282 s
= bfd_make_section_with_flags (abfd
, ".rel.got",
4283 (flags
| SEC_READONLY
));
4285 || ! bfd_set_section_alignment (abfd
, s
, 2))
4288 frvfdpic_gotrel_section (info
) = s
;
4290 /* Machine-specific. */
4291 s
= bfd_make_section_with_flags (abfd
, ".rofixup",
4292 (flags
| SEC_READONLY
));
4294 || ! bfd_set_section_alignment (abfd
, s
, 2))
4297 frvfdpic_gotfixup_section (info
) = s
;
4304 flags
= BSF_GLOBAL
| BSF_WEAK
;
4307 /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it
4308 turns out that we're linking with a different linker script, the
4309 linker script will override it. */
4311 if (!(_bfd_generic_link_add_one_symbol
4312 (info
, abfd
, "_gp", flags
, s
, offset
, (const char *) NULL
, FALSE
,
4313 bed
->collect
, &bh
)))
4315 h
= (struct elf_link_hash_entry
*) bh
;
4317 h
->type
= STT_OBJECT
;
4318 /* h->other = STV_HIDDEN; */ /* Should we? */
4320 /* Machine-specific: we want the symbol for executables as well. */
4321 if (IS_FDPIC (abfd
) && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
4324 if (!IS_FDPIC (abfd
))
4327 /* FDPIC supports Thread Local Storage, and this may require a
4328 procedure linkage table for TLS PLT entries. */
4330 /* This is mostly copied from
4331 elflink.c:_bfd_elf_create_dynamic_sections(). */
4334 pltflags
|= SEC_CODE
;
4335 if (bed
->plt_not_loaded
)
4336 pltflags
&= ~ (SEC_CODE
| SEC_LOAD
| SEC_HAS_CONTENTS
);
4337 if (bed
->plt_readonly
)
4338 pltflags
|= SEC_READONLY
;
4340 s
= bfd_make_section_with_flags (abfd
, ".plt", pltflags
);
4342 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
4344 /* FRV-specific: remember it. */
4345 frvfdpic_plt_section (info
) = s
;
4347 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
4349 if (bed
->want_plt_sym
)
4351 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
4352 "_PROCEDURE_LINKAGE_TABLE_");
4353 elf_hash_table (info
)->hplt
= h
;
4358 /* FRV-specific: we want rel relocations for the plt. */
4359 s
= bfd_make_section_with_flags (abfd
, ".rel.plt",
4360 flags
| SEC_READONLY
);
4362 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
4364 /* FRV-specific: remember it. */
4365 frvfdpic_pltrel_section (info
) = s
;
4370 /* Make sure the got and plt sections exist, and that our pointers in
4371 the link hash table point to them. */
4374 elf32_frvfdpic_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
4376 /* This is mostly copied from
4377 elflink.c:_bfd_elf_create_dynamic_sections(). */
4380 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4382 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4383 | SEC_LINKER_CREATED
);
4385 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
4386 .rel[a].bss sections. */
4388 /* FRV-specific: we want to create the GOT and the PLT in the FRV
4390 if (! _frv_create_got_section (abfd
, info
))
4393 /* FRV-specific: make sure we created everything we wanted. */
4394 BFD_ASSERT (frvfdpic_got_section (info
) && frvfdpic_gotrel_section (info
)
4395 && frvfdpic_gotfixup_section (info
)
4396 && frvfdpic_plt_section (info
)
4397 && frvfdpic_pltrel_section (info
));
4399 if (bed
->want_dynbss
)
4401 /* The .dynbss section is a place to put symbols which are defined
4402 by dynamic objects, are referenced by regular objects, and are
4403 not functions. We must allocate space for them in the process
4404 image and use a R_*_COPY reloc to tell the dynamic linker to
4405 initialize them at run time. The linker script puts the .dynbss
4406 section into the .bss section of the final image. */
4407 s
= bfd_make_section_with_flags (abfd
, ".dynbss",
4408 SEC_ALLOC
| SEC_LINKER_CREATED
);
4412 /* The .rel[a].bss section holds copy relocs. This section is not
4413 normally needed. We need to create it here, though, so that the
4414 linker will map it to an output section. We can't just create it
4415 only if we need it, because we will not know whether we need it
4416 until we have seen all the input files, and the first time the
4417 main linker code calls BFD after examining all the input files
4418 (size_dynamic_sections) the input sections have already been
4419 mapped to the output sections. If the section turns out not to
4420 be needed, we can discard it later. We will never need this
4421 section when generating a shared object, since they do not use
4425 s
= bfd_make_section_with_flags (abfd
,
4426 (bed
->default_use_rela_p
4427 ? ".rela.bss" : ".rel.bss"),
4428 flags
| SEC_READONLY
);
4430 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
4438 /* Compute the total GOT and PLT size required by each symbol in each
4439 range. Symbols may require up to 4 words in the GOT: an entry
4440 pointing to the symbol, an entry pointing to its function
4441 descriptor, and a private function descriptors taking two
4445 _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info
*entry
,
4446 struct _frvfdpic_dynamic_got_info
*dinfo
)
4448 /* Allocate space for a GOT entry pointing to the symbol. */
4451 else if (entry
->gotlos
)
4453 else if (entry
->gothilo
)
4454 dinfo
->gothilo
+= 4;
4459 /* Allocate space for a GOT entry pointing to the function
4463 else if (entry
->fdgotlos
)
4465 else if (entry
->fdgothilo
)
4466 dinfo
->gothilo
+= 4;
4471 /* Decide whether we need a PLT entry, a function descriptor in the
4472 GOT, and a lazy PLT entry for this symbol. */
4473 entry
->plt
= entry
->call
4474 && entry
->symndx
== -1 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4475 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
4476 entry
->privfd
= entry
->plt
4477 || entry
->fdgoff12
|| entry
->fdgofflos
|| entry
->fdgoffhilo
4478 || ((entry
->fd
|| entry
->fdgot12
|| entry
->fdgotlos
|| entry
->fdgothilo
)
4479 && (entry
->symndx
!= -1
4480 || FRVFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
)));
4481 entry
->lazyplt
= entry
->privfd
4482 && entry
->symndx
== -1 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4483 && ! (dinfo
->info
->flags
& DF_BIND_NOW
)
4484 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
4486 /* Allocate space for a function descriptor. */
4487 if (entry
->fdgoff12
)
4489 else if (entry
->fdgofflos
)
4491 else if (entry
->privfd
&& entry
->plt
)
4493 else if (entry
->privfd
)
4503 /* Compute the total GOT size required by each TLS symbol in each
4504 range. Symbols may require up to 5 words in the GOT: an entry
4505 holding the TLS offset for the symbol, and an entry with a full TLS
4506 descriptor taking 4 words. */
4509 _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info
*entry
,
4510 struct _frvfdpic_dynamic_got_info
*dinfo
,
4511 bfd_boolean subtract
)
4513 const int l
= subtract
? -1 : 1;
4515 /* Allocate space for a GOT entry with the TLS offset of the
4517 if (entry
->tlsoff12
)
4518 dinfo
->got12
+= 4 * l
;
4519 else if (entry
->tlsofflos
)
4520 dinfo
->gotlos
+= 4 * l
;
4521 else if (entry
->tlsoffhilo
)
4522 dinfo
->gothilo
+= 4 * l
;
4524 entry
->relocstlsoff
-= l
;
4525 entry
->relocstlsoff
+= l
;
4527 /* If there's any TLSOFF relocation, mark the output file as not
4528 suitable for dlopening. This mark will remain even if we relax
4529 all such relocations, but this is not a problem, since we'll only
4530 do so for executables, and we definitely don't want anyone
4531 dlopening executables. */
4532 if (entry
->relocstlsoff
)
4533 dinfo
->info
->flags
|= DF_STATIC_TLS
;
4535 /* Allocate space for a TLS descriptor. */
4536 if (entry
->tlsdesc12
)
4537 dinfo
->tlsd12
+= 8 * l
;
4538 else if (entry
->tlsdesclos
)
4539 dinfo
->tlsdlos
+= 8 * l
;
4540 else if (entry
->tlsplt
)
4541 dinfo
->tlsdplt
+= 8 * l
;
4542 else if (entry
->tlsdeschilo
)
4543 dinfo
->tlsdhilo
+= 8 * l
;
4545 entry
->relocstlsd
-= l
;
4546 entry
->relocstlsd
+= l
;
4549 /* Compute the number of dynamic relocations and fixups that a symbol
4550 requires, and add (or subtract) from the grand and per-symbol
4554 _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info
*entry
,
4555 struct _frvfdpic_dynamic_got_info
*dinfo
,
4556 bfd_boolean subtract
)
4558 bfd_vma relocs
= 0, fixups
= 0, tlsrets
= 0;
4560 if (!dinfo
->info
->executable
|| dinfo
->info
->pie
)
4562 relocs
= entry
->relocs32
+ entry
->relocsfd
+ entry
->relocsfdv
4563 + entry
->relocstlsd
;
4565 /* In the executable, TLS relocations to symbols that bind
4566 locally (including those that resolve to global TLS offsets)
4567 are resolved immediately, without any need for fixups or
4568 dynamic relocations. In shared libraries, however, we must
4569 emit dynamic relocations even for local symbols, because we
4570 don't know the module id the library is going to get at
4571 run-time, nor its TLS base offset. */
4572 if (!dinfo
->info
->executable
4573 || (entry
->symndx
== -1
4574 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)))
4575 relocs
+= entry
->relocstlsoff
;
4579 if (entry
->symndx
!= -1 || FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
))
4581 if (entry
->symndx
!= -1
4582 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
4583 fixups
+= entry
->relocs32
+ 2 * entry
->relocsfdv
;
4584 fixups
+= entry
->relocstlsd
;
4585 tlsrets
+= entry
->relocstlsd
;
4589 relocs
+= entry
->relocs32
+ entry
->relocsfdv
4590 + entry
->relocstlsoff
+ entry
->relocstlsd
;
4593 if (entry
->symndx
!= -1
4594 || FRVFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
))
4596 if (entry
->symndx
!= -1
4597 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
4598 fixups
+= entry
->relocsfd
;
4601 relocs
+= entry
->relocsfd
;
4608 tlsrets
= - tlsrets
;
4611 entry
->dynrelocs
+= relocs
;
4612 entry
->fixups
+= fixups
;
4613 dinfo
->relocs
+= relocs
;
4614 dinfo
->fixups
+= fixups
;
4615 dinfo
->tls_ret_refs
+= tlsrets
;
4618 /* Look for opportunities to relax TLS relocations. We can assume
4619 we're linking the main executable or a static-tls library, since
4620 otherwise we wouldn't have got here. When relaxing, we have to
4621 first undo any previous accounting of TLS uses of fixups, dynamic
4622 relocations, GOT and PLT entries. */
4625 _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info
*entry
,
4626 struct _frvfdpic_dynamic_got_info
*dinfo
,
4627 bfd_boolean relaxing
)
4629 bfd_boolean changed
= ! relaxing
;
4631 BFD_ASSERT (dinfo
->info
->executable
4632 || (dinfo
->info
->flags
& DF_STATIC_TLS
));
4634 if (entry
->tlsdesc12
|| entry
->tlsdesclos
|| entry
->tlsdeschilo
)
4638 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4639 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4643 /* When linking an executable, we can always decay GOTTLSDESC to
4644 TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise.
4645 When linking a static-tls shared library, using TLSMOFF is
4646 not an option, but we can still use GOTTLSOFF. When decaying
4647 to GOTTLSOFF, we must keep the GOT entry in range. We know
4648 it has to fit because we'll be trading the 4 words of hte TLS
4649 descriptor for a single word in the same range. */
4650 if (! dinfo
->info
->executable
4651 || (entry
->symndx
== -1
4652 && ! FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)))
4654 entry
->tlsoff12
|= entry
->tlsdesc12
;
4655 entry
->tlsofflos
|= entry
->tlsdesclos
;
4656 entry
->tlsoffhilo
|= entry
->tlsdeschilo
;
4659 entry
->tlsdesc12
= entry
->tlsdesclos
= entry
->tlsdeschilo
= 0;
4662 /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the
4663 main executable. We have to check whether the symbol's TLSOFF is
4664 in range for a setlos. For symbols with a hash entry, we can
4665 determine exactly what to do; for others locals, we don't have
4666 addresses handy, so we use the size of the TLS section as an
4667 approximation. If we get it wrong, we'll retain a GOT entry
4668 holding the TLS offset (without dynamic relocations or fixups),
4669 but we'll still optimize away the loads from it. Since TLS sizes
4670 are generally very small, it's probably not worth attempting to
4671 do better than this. */
4673 || entry
->tlsoff12
|| entry
->tlsofflos
|| entry
->tlsoffhilo
)
4674 && dinfo
->info
->executable
&& relaxing
4675 && ((entry
->symndx
== -1
4676 && FRVFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
4677 /* The above may hold for an undefweak TLS symbol, so make
4678 sure we don't have this case before accessing def.value
4680 && (entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
4681 || (bfd_vma
)(entry
->d
.h
->root
.u
.def
.value
4682 + (entry
->d
.h
->root
.u
.def
.section
4683 ->output_section
->vma
)
4684 + entry
->d
.h
->root
.u
.def
.section
->output_offset
4686 - tls_biased_base (dinfo
->info
)
4687 + 32768) < (bfd_vma
)65536))
4688 || (entry
->symndx
!= -1
4689 && (elf_hash_table (dinfo
->info
)->tls_sec
->size
4690 + abs (entry
->addend
) < 32768 + FRVFDPIC_TLS_BIAS
))))
4694 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4695 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4700 entry
->tlsoff12
= entry
->tlsofflos
= entry
->tlsoffhilo
= 0;
4703 /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already
4704 have a #gottlsoff12 relocation for this entry, or if we can fit
4705 one more in the 12-bit (and 16-bit) ranges. */
4709 && dinfo
->got12
+ dinfo
->fd12
+ dinfo
->tlsd12
<= 4096 - 12 - 4
4710 && (dinfo
->got12
+ dinfo
->fd12
+ dinfo
->tlsd12
4711 + dinfo
->gotlos
+ dinfo
->fdlos
+ dinfo
->tlsdlos
4712 <= 65536 - 12 - 4))))
4716 _frvfdpic_count_relocs_fixups (entry
, dinfo
, TRUE
);
4717 _frvfdpic_count_tls_entries (entry
, dinfo
, TRUE
);
4721 entry
->tlsoff12
= 1;
4727 _frvfdpic_count_tls_entries (entry
, dinfo
, FALSE
);
4728 _frvfdpic_count_relocs_fixups (entry
, dinfo
, FALSE
);
4734 /* Compute the total GOT and PLT size required by each symbol in each range. *
4735 Symbols may require up to 4 words in the GOT: an entry pointing to
4736 the symbol, an entry pointing to its function descriptor, and a
4737 private function descriptors taking two words. */
4740 _frvfdpic_count_got_plt_entries (void **entryp
, void *dinfo_
)
4742 struct frvfdpic_relocs_info
*entry
= *entryp
;
4743 struct _frvfdpic_dynamic_got_info
*dinfo
= dinfo_
;
4745 _frvfdpic_count_nontls_entries (entry
, dinfo
);
4747 if (dinfo
->info
->executable
|| (dinfo
->info
->flags
& DF_STATIC_TLS
))
4748 _frvfdpic_relax_tls_entries (entry
, dinfo
, FALSE
);
4751 _frvfdpic_count_tls_entries (entry
, dinfo
, FALSE
);
4752 _frvfdpic_count_relocs_fixups (entry
, dinfo
, FALSE
);
4758 /* Determine the positive and negative ranges to be used by each
4759 offset range in the GOT. FDCUR and CUR, that must be aligned to a
4760 double-word boundary, are the minimum (negative) and maximum
4761 (positive) GOT offsets already used by previous ranges, except for
4762 an ODD entry that may have been left behind. GOT and FD indicate
4763 the size of GOT entries and function descriptors that must be
4764 placed within the range from -WRAP to WRAP. If there's room left,
4765 up to FDPLT bytes should be reserved for additional function
4768 inline static bfd_signed_vma
4769 _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data
*gad
,
4770 bfd_signed_vma fdcur
,
4780 bfd_signed_vma wrapmin
= -wrap
;
4781 const bfd_vma tdescsz
= 8;
4783 /* Start at the given initial points. */
4787 /* If we had an incoming odd word and we have any got entries that
4788 are going to use it, consume it, otherwise leave gad->odd at
4789 zero. We might force gad->odd to zero and return the incoming
4790 odd such that it is used by the next range, but then GOT entries
4791 might appear to be out of order and we wouldn't be able to
4792 shorten the GOT by one word if it turns out to end with an
4793 unpaired GOT entry. */
4803 /* If we're left with an unpaired GOT entry, compute its location
4804 such that we can return it. Otherwise, if got doesn't require an
4805 odd number of words here, either odd was already zero in the
4806 block above, or it was set to zero because got was non-zero, or
4807 got was already zero. In the latter case, we want the value of
4808 odd to carry over to the return statement, so we don't want to
4809 reset odd unless the condition below is true. */
4816 /* Compute the tentative boundaries of this range. */
4817 gad
->max
= cur
+ got
;
4818 gad
->min
= fdcur
- fd
;
4821 /* If function descriptors took too much space, wrap some of them
4823 if (gad
->min
< wrapmin
)
4825 gad
->max
+= wrapmin
- gad
->min
;
4826 gad
->tmin
= gad
->min
= wrapmin
;
4829 /* If GOT entries took too much space, wrap some of them around.
4830 This may well cause gad->min to become lower than wrapmin. This
4831 will cause a relocation overflow later on, so we don't have to
4833 if ((bfd_vma
) gad
->max
> wrap
)
4835 gad
->min
-= gad
->max
- wrap
;
4839 /* Add TLS descriptors. */
4840 gad
->tmax
= gad
->max
+ tlsd
;
4841 gad
->tmin
= gad
->min
;
4844 /* If TLS descriptors took too much space, wrap an integral number
4846 if ((bfd_vma
) gad
->tmax
> wrap
)
4848 bfd_vma wrapsize
= gad
->tmax
- wrap
;
4850 wrapsize
+= tdescsz
/ 2;
4851 wrapsize
&= ~ tdescsz
/ 2;
4853 gad
->tmin
-= wrapsize
;
4854 gad
->tmax
-= wrapsize
;
4857 /* If there is space left and we have function descriptors
4858 referenced in PLT entries that could take advantage of shorter
4859 offsets, place them now. */
4860 if (fdplt
&& gad
->tmin
> wrapmin
)
4864 if ((bfd_vma
) (gad
->tmin
- wrapmin
) < fdplt
)
4865 fds
= gad
->tmin
- wrapmin
;
4875 /* If there is more space left, try to place some more function
4876 descriptors for PLT entries. */
4877 if (fdplt
&& (bfd_vma
) gad
->tmax
< wrap
)
4881 if ((bfd_vma
) (wrap
- gad
->tmax
) < fdplt
)
4882 fds
= wrap
- gad
->tmax
;
4892 /* If there is space left and we have TLS descriptors referenced in
4893 PLT entries that could take advantage of shorter offsets, place
4895 if (tlsdplt
&& gad
->tmin
> wrapmin
)
4899 if ((bfd_vma
) (gad
->tmin
- wrapmin
) < tlsdplt
)
4900 tlsds
= (gad
->tmin
- wrapmin
) & ~ (tdescsz
/ 2);
4906 gad
->tlsdplt
+= tlsds
;
4909 /* If there is more space left, try to place some more TLS
4910 descriptors for PLT entries. Although we could try to fit an
4911 additional TLS descriptor with half of it just before before the
4912 wrap point and another right past the wrap point, this might
4913 cause us to run out of space for the next region, so don't do
4915 if (tlsdplt
&& (bfd_vma
) gad
->tmax
< wrap
- tdescsz
/ 2)
4919 if ((bfd_vma
) (wrap
- gad
->tmax
) < tlsdplt
)
4920 tlsds
= (wrap
- gad
->tmax
) & ~ (tdescsz
/ 2);
4926 gad
->tlsdplt
+= tlsds
;
4929 /* If odd was initially computed as an offset past the wrap point,
4932 odd
= gad
->min
+ odd
- gad
->max
;
4934 /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed
4935 before returning, so do it here too. This guarantees that,
4936 should cur and fdcur meet at the wrap point, they'll both be
4938 if (gad
->cur
== gad
->max
)
4939 gad
->cur
= gad
->min
;
4941 /* Ditto for _frvfdpic_get_tlsdesc_entry(). */
4942 gad
->tcur
= gad
->max
;
4943 if (gad
->tcur
== gad
->tmax
)
4944 gad
->tcur
= gad
->tmin
;
4949 /* Compute the location of the next GOT entry, given the allocation
4950 data for a range. */
4952 inline static bfd_signed_vma
4953 _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
4959 /* If there was an odd word left behind, use it. */
4965 /* Otherwise, use the word pointed to by cur, reserve the next
4966 as an odd word, and skip to the next pair of words, possibly
4969 gad
->odd
= gad
->cur
+ 4;
4971 if (gad
->cur
== gad
->max
)
4972 gad
->cur
= gad
->min
;
4978 /* Compute the location of the next function descriptor entry in the
4979 GOT, given the allocation data for a range. */
4981 inline static bfd_signed_vma
4982 _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
4984 /* If we're at the bottom, wrap around, and only then allocate the
4985 next pair of words. */
4986 if (gad
->fdcur
== gad
->min
)
4987 gad
->fdcur
= gad
->max
;
4988 return gad
->fdcur
-= 8;
4991 /* Compute the location of the next TLS descriptor entry in the GOT,
4992 given the allocation data for a range. */
4993 inline static bfd_signed_vma
4994 _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data
*gad
)
5002 /* If we're at the top of the region, wrap around to the bottom. */
5003 if (gad
->tcur
== gad
->tmax
)
5004 gad
->tcur
= gad
->tmin
;
5009 /* Assign GOT offsets for every GOT entry and function descriptor.
5010 Doing everything in a single pass is tricky. */
5013 _frvfdpic_assign_got_entries (void **entryp
, void *info_
)
5015 struct frvfdpic_relocs_info
*entry
= *entryp
;
5016 struct _frvfdpic_dynamic_got_plt_info
*dinfo
= info_
;
5019 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5020 else if (entry
->gotlos
)
5021 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5022 else if (entry
->gothilo
)
5023 entry
->got_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5026 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5027 else if (entry
->fdgotlos
)
5028 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5029 else if (entry
->fdgothilo
)
5030 entry
->fdgot_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5032 if (entry
->fdgoff12
)
5033 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->got12
);
5034 else if (entry
->plt
&& dinfo
->got12
.fdplt
)
5036 dinfo
->got12
.fdplt
-= 8;
5037 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->got12
);
5039 else if (entry
->fdgofflos
)
5040 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gotlos
);
5041 else if (entry
->plt
&& dinfo
->gotlos
.fdplt
)
5043 dinfo
->gotlos
.fdplt
-= 8;
5044 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gotlos
);
5046 else if (entry
->plt
)
5048 dinfo
->gothilo
.fdplt
-= 8;
5049 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gothilo
);
5051 else if (entry
->privfd
)
5052 entry
->fd_entry
= _frvfdpic_get_fd_entry (&dinfo
->gothilo
);
5054 if (entry
->tlsoff12
)
5055 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->got12
);
5056 else if (entry
->tlsofflos
)
5057 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->gotlos
);
5058 else if (entry
->tlsoffhilo
)
5059 entry
->tlsoff_entry
= _frvfdpic_get_got_entry (&dinfo
->gothilo
);
5061 if (entry
->tlsdesc12
)
5062 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->got12
);
5063 else if (entry
->tlsplt
&& dinfo
->got12
.tlsdplt
)
5065 dinfo
->got12
.tlsdplt
-= 8;
5066 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->got12
);
5068 else if (entry
->tlsdesclos
)
5069 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gotlos
);
5070 else if (entry
->tlsplt
&& dinfo
->gotlos
.tlsdplt
)
5072 dinfo
->gotlos
.tlsdplt
-= 8;
5073 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gotlos
);
5075 else if (entry
->tlsplt
)
5077 dinfo
->gothilo
.tlsdplt
-= 8;
5078 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gothilo
);
5080 else if (entry
->tlsdeschilo
)
5081 entry
->tlsdesc_entry
= _frvfdpic_get_tlsdesc_entry (&dinfo
->gothilo
);
5086 /* Assign GOT offsets to private function descriptors used by PLT
5087 entries (or referenced by 32-bit offsets), as well as PLT entries
5088 and lazy PLT entries. */
5091 _frvfdpic_assign_plt_entries (void **entryp
, void *info_
)
5093 struct frvfdpic_relocs_info
*entry
= *entryp
;
5094 struct _frvfdpic_dynamic_got_plt_info
*dinfo
= info_
;
5097 BFD_ASSERT (entry
->fd_entry
);
5103 /* We use the section's raw size to mark the location of the
5105 entry
->plt_entry
= frvfdpic_plt_section (dinfo
->g
.info
)->size
;
5107 /* Figure out the length of this PLT entry based on the
5108 addressing mode we need to reach the function descriptor. */
5109 BFD_ASSERT (entry
->fd_entry
);
5110 if (entry
->fd_entry
>= -(1 << (12 - 1))
5111 && entry
->fd_entry
< (1 << (12 - 1)))
5113 else if (entry
->fd_entry
>= -(1 << (16 - 1))
5114 && entry
->fd_entry
< (1 << (16 - 1)))
5119 frvfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
5124 entry
->lzplt_entry
= dinfo
->g
.lzplt
;
5125 dinfo
->g
.lzplt
+= 8;
5126 /* If this entry is the one that gets the resolver stub, account
5127 for the additional instruction. */
5128 if (entry
->lzplt_entry
% FRVFDPIC_LZPLT_BLOCK_SIZE
5129 == FRVFDPIC_LZPLT_RESOLV_LOC
)
5130 dinfo
->g
.lzplt
+= 4;
5138 = frvfdpic_plt_section (dinfo
->g
.info
)->size
;
5140 if (dinfo
->g
.info
->executable
5141 && (entry
->symndx
!= -1
5142 || FRVFDPIC_SYM_LOCAL (dinfo
->g
.info
, entry
->d
.h
)))
5144 if ((bfd_signed_vma
)entry
->addend
>= -(1 << (16 - 1))
5145 /* FIXME: here we use the size of the TLS section
5146 as an upper bound for the value of the TLS
5147 symbol, because we may not know the exact value
5148 yet. If we get it wrong, we'll just waste a
5149 word in the PLT, and we should never get even
5150 close to 32 KiB of TLS anyway. */
5151 && elf_hash_table (dinfo
->g
.info
)->tls_sec
5152 && (elf_hash_table (dinfo
->g
.info
)->tls_sec
->size
5153 + (bfd_signed_vma
)(entry
->addend
) <= (1 << (16 - 1))))
5158 else if (entry
->tlsoff_entry
)
5160 if (entry
->tlsoff_entry
>= -(1 << (12 - 1))
5161 && entry
->tlsoff_entry
< (1 << (12 - 1)))
5163 else if (entry
->tlsoff_entry
>= -(1 << (16 - 1))
5164 && entry
->tlsoff_entry
< (1 << (16 - 1)))
5171 BFD_ASSERT (entry
->tlsdesc_entry
);
5173 if (entry
->tlsdesc_entry
>= -(1 << (12 - 1))
5174 && entry
->tlsdesc_entry
< (1 << (12 - 1)))
5176 else if (entry
->tlsdesc_entry
>= -(1 << (16 - 1))
5177 && entry
->tlsdesc_entry
< (1 << (16 - 1)))
5183 frvfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
5189 /* Cancel out any effects of calling _frvfdpic_assign_got_entries and
5190 _frvfdpic_assign_plt_entries. */
5193 _frvfdpic_reset_got_plt_entries (void **entryp
, void *ignore ATTRIBUTE_UNUSED
)
5195 struct frvfdpic_relocs_info
*entry
= *entryp
;
5197 entry
->got_entry
= 0;
5198 entry
->fdgot_entry
= 0;
5199 entry
->fd_entry
= 0;
5200 entry
->plt_entry
= (bfd_vma
)-1;
5201 entry
->lzplt_entry
= (bfd_vma
)-1;
5202 entry
->tlsoff_entry
= 0;
5203 entry
->tlsdesc_entry
= 0;
5204 entry
->tlsplt_entry
= (bfd_vma
)-1;
5209 /* Follow indirect and warning hash entries so that each got entry
5210 points to the final symbol definition. P must point to a pointer
5211 to the hash table we're traversing. Since this traversal may
5212 modify the hash table, we set this pointer to NULL to indicate
5213 we've made a potentially-destructive change to the hash table, so
5214 the traversal must be restarted. */
5216 _frvfdpic_resolve_final_relocs_info (void **entryp
, void *p
)
5218 struct frvfdpic_relocs_info
*entry
= *entryp
;
5221 if (entry
->symndx
== -1)
5223 struct elf_link_hash_entry
*h
= entry
->d
.h
;
5224 struct frvfdpic_relocs_info
*oentry
;
5226 while (h
->root
.type
== bfd_link_hash_indirect
5227 || h
->root
.type
== bfd_link_hash_warning
)
5228 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
5230 if (entry
->d
.h
== h
)
5233 oentry
= frvfdpic_relocs_info_for_global (*htab
, 0, h
, entry
->addend
,
5238 /* Merge the two entries. */
5239 frvfdpic_pic_merge_early_relocs_info (oentry
, entry
);
5240 htab_clear_slot (*htab
, entryp
);
5246 /* If we can't find this entry with the new bfd hash, re-insert
5247 it, and get the traversal restarted. */
5248 if (! htab_find (*htab
, entry
))
5250 htab_clear_slot (*htab
, entryp
);
5251 entryp
= htab_find_slot (*htab
, entry
, INSERT
);
5254 /* Abort the traversal, since the whole table may have
5255 moved, and leave it up to the parent to restart the
5257 *(htab_t
*)p
= NULL
;
5265 /* Compute the total size of the GOT, the PLT, the dynamic relocations
5266 section and the rofixup section. Assign locations for GOT and PLT
5270 _frvfdpic_size_got_plt (bfd
*output_bfd
,
5271 struct _frvfdpic_dynamic_got_plt_info
*gpinfop
)
5274 bfd_vma limit
, tlslimit
;
5275 struct bfd_link_info
*info
= gpinfop
->g
.info
;
5276 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
5278 memcpy (frvfdpic_dynamic_got_plt_info (info
), &gpinfop
->g
,
5279 sizeof (gpinfop
->g
));
5282 /* Compute the total size taken by entries in the 12-bit and 16-bit
5283 ranges, to tell how many PLT function descriptors we can bring
5284 into the 12-bit range without causing the 16-bit range to
5286 limit
= odd
+ gpinfop
->g
.got12
+ gpinfop
->g
.gotlos
5287 + gpinfop
->g
.fd12
+ gpinfop
->g
.fdlos
5288 + gpinfop
->g
.tlsd12
+ gpinfop
->g
.tlsdlos
;
5289 if (limit
< (bfd_vma
)1 << 16)
5290 limit
= ((bfd_vma
)1 << 16) - limit
;
5293 if (gpinfop
->g
.fdplt
< limit
)
5295 tlslimit
= (limit
- gpinfop
->g
.fdplt
) & ~ (bfd_vma
) 8;
5296 limit
= gpinfop
->g
.fdplt
;
5300 if (gpinfop
->g
.tlsdplt
< tlslimit
)
5301 tlslimit
= gpinfop
->g
.tlsdplt
;
5303 /* Determine the ranges of GOT offsets that we can use for each
5304 range of addressing modes. */
5305 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->got12
,
5314 (bfd_vma
)1 << (12-1));
5315 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->gotlos
,
5316 gpinfop
->got12
.tmin
,
5318 gpinfop
->got12
.tmax
,
5322 - gpinfop
->got12
.fdplt
,
5325 - gpinfop
->got12
.tlsdplt
,
5326 (bfd_vma
)1 << (16-1));
5327 odd
= _frvfdpic_compute_got_alloc_data (&gpinfop
->gothilo
,
5328 gpinfop
->gotlos
.tmin
,
5330 gpinfop
->gotlos
.tmax
,
5334 - gpinfop
->got12
.fdplt
5335 - gpinfop
->gotlos
.fdplt
,
5336 gpinfop
->g
.tlsdhilo
,
5338 - gpinfop
->got12
.tlsdplt
5339 - gpinfop
->gotlos
.tlsdplt
,
5340 (bfd_vma
)1 << (32-1));
5342 /* Now assign (most) GOT offsets. */
5343 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_assign_got_entries
,
5346 frvfdpic_got_section (info
)->size
= gpinfop
->gothilo
.tmax
5347 - gpinfop
->gothilo
.tmin
5348 /* If an odd word is the last word of the GOT, we don't need this
5349 word to be part of the GOT. */
5350 - (odd
+ 4 == gpinfop
->gothilo
.tmax
? 4 : 0);
5351 if (frvfdpic_got_section (info
)->size
== 0)
5352 frvfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
5353 else if (frvfdpic_got_section (info
)->size
== 12
5354 && ! elf_hash_table (info
)->dynamic_sections_created
)
5356 frvfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
5357 frvfdpic_got_section (info
)->size
= 0;
5359 /* This will be non-NULL during relaxation. The assumption is that
5360 the size of one of these sections will never grow, only shrink,
5361 so we can use the larger buffer we allocated before. */
5362 else if (frvfdpic_got_section (info
)->contents
== NULL
)
5364 frvfdpic_got_section (info
)->contents
=
5365 (bfd_byte
*) bfd_zalloc (dynobj
,
5366 frvfdpic_got_section (info
)->size
);
5367 if (frvfdpic_got_section (info
)->contents
== NULL
)
5371 if (frvfdpic_gotrel_section (info
))
5372 /* Subtract the number of lzplt entries, since those will generate
5373 relocations in the pltrel section. */
5374 frvfdpic_gotrel_section (info
)->size
=
5375 (gpinfop
->g
.relocs
- gpinfop
->g
.lzplt
/ 8)
5376 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
5378 BFD_ASSERT (gpinfop
->g
.relocs
== 0);
5379 if (frvfdpic_gotrel_section (info
)->size
== 0)
5380 frvfdpic_gotrel_section (info
)->flags
|= SEC_EXCLUDE
;
5381 else if (frvfdpic_gotrel_section (info
)->contents
== NULL
)
5383 frvfdpic_gotrel_section (info
)->contents
=
5384 (bfd_byte
*) bfd_zalloc (dynobj
,
5385 frvfdpic_gotrel_section (info
)->size
);
5386 if (frvfdpic_gotrel_section (info
)->contents
== NULL
)
5390 frvfdpic_gotfixup_section (info
)->size
= (gpinfop
->g
.fixups
+ 1) * 4;
5391 if (frvfdpic_gotfixup_section (info
)->size
== 0)
5392 frvfdpic_gotfixup_section (info
)->flags
|= SEC_EXCLUDE
;
5393 else if (frvfdpic_gotfixup_section (info
)->contents
== NULL
)
5395 frvfdpic_gotfixup_section (info
)->contents
=
5396 (bfd_byte
*) bfd_zalloc (dynobj
,
5397 frvfdpic_gotfixup_section (info
)->size
);
5398 if (frvfdpic_gotfixup_section (info
)->contents
== NULL
)
5402 if (frvfdpic_pltrel_section (info
))
5404 frvfdpic_pltrel_section (info
)->size
=
5405 gpinfop
->g
.lzplt
/ 8
5406 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
5407 if (frvfdpic_pltrel_section (info
)->size
== 0)
5408 frvfdpic_pltrel_section (info
)->flags
|= SEC_EXCLUDE
;
5409 else if (frvfdpic_pltrel_section (info
)->contents
== NULL
)
5411 frvfdpic_pltrel_section (info
)->contents
=
5412 (bfd_byte
*) bfd_zalloc (dynobj
,
5413 frvfdpic_pltrel_section (info
)->size
);
5414 if (frvfdpic_pltrel_section (info
)->contents
== NULL
)
5419 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
5420 such that there's room for the additional instruction needed to
5421 call the resolver. Since _frvfdpic_assign_got_entries didn't
5422 account for them, our block size is 4 bytes smaller than the real
5424 if (frvfdpic_plt_section (info
))
5426 frvfdpic_plt_section (info
)->size
= gpinfop
->g
.lzplt
5427 + ((gpinfop
->g
.lzplt
+ (FRVFDPIC_LZPLT_BLOCK_SIZE
- 4) - 8)
5428 / (FRVFDPIC_LZPLT_BLOCK_SIZE
- 4) * 4);
5431 /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to
5432 actually assign lazy PLT entries addresses. */
5433 gpinfop
->g
.lzplt
= 0;
5435 /* Save information that we're going to need to generate GOT and PLT
5437 frvfdpic_got_initial_offset (info
) = -gpinfop
->gothilo
.tmin
;
5439 if (get_elf_backend_data (output_bfd
)->want_got_sym
)
5440 elf_hash_table (info
)->hgot
->root
.u
.def
.value
5441 = frvfdpic_got_initial_offset (info
);
5443 if (frvfdpic_plt_section (info
))
5444 frvfdpic_plt_initial_offset (info
) =
5445 frvfdpic_plt_section (info
)->size
;
5447 /* Allocate a ret statement at plt_initial_offset, to be used by
5448 locally-resolved TLS descriptors. */
5449 if (gpinfop
->g
.tls_ret_refs
)
5450 frvfdpic_plt_section (info
)->size
+= 4;
5452 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_assign_plt_entries
,
5455 /* Allocate the PLT section contents only after
5456 _frvfdpic_assign_plt_entries has a chance to add the size of the
5457 non-lazy PLT entries. */
5458 if (frvfdpic_plt_section (info
))
5460 if (frvfdpic_plt_section (info
)->size
== 0)
5461 frvfdpic_plt_section (info
)->flags
|= SEC_EXCLUDE
;
5462 else if (frvfdpic_plt_section (info
)->contents
== NULL
)
5464 frvfdpic_plt_section (info
)->contents
=
5465 (bfd_byte
*) bfd_zalloc (dynobj
,
5466 frvfdpic_plt_section (info
)->size
);
5467 if (frvfdpic_plt_section (info
)->contents
== NULL
)
5475 /* Set the sizes of the dynamic sections. */
5478 elf32_frvfdpic_size_dynamic_sections (bfd
*output_bfd
,
5479 struct bfd_link_info
*info
)
5483 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5485 dynobj
= elf_hash_table (info
)->dynobj
;
5486 BFD_ASSERT (dynobj
!= NULL
);
5488 if (elf_hash_table (info
)->dynamic_sections_created
)
5490 /* Set the contents of the .interp section to the interpreter. */
5491 if (info
->executable
)
5493 s
= bfd_get_section_by_name (dynobj
, ".interp");
5494 BFD_ASSERT (s
!= NULL
);
5495 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5496 s
->contents
= (bfd_byte
*) ELF_DYNAMIC_INTERPRETER
;
5500 memset (&gpinfo
, 0, sizeof (gpinfo
));
5501 gpinfo
.g
.info
= info
;
5505 htab_t relocs
= frvfdpic_relocs_info (info
);
5507 htab_traverse (relocs
, _frvfdpic_resolve_final_relocs_info
, &relocs
);
5509 if (relocs
== frvfdpic_relocs_info (info
))
5513 htab_traverse (frvfdpic_relocs_info (info
), _frvfdpic_count_got_plt_entries
,
5516 /* Allocate space to save the summary information, we're going to
5517 use it if we're doing relaxations. */
5518 frvfdpic_dynamic_got_plt_info (info
) = bfd_alloc (dynobj
, sizeof (gpinfo
.g
));
5520 if (!_frvfdpic_size_got_plt (output_bfd
, &gpinfo
))
5523 if (elf_hash_table (info
)->dynamic_sections_created
)
5525 if (frvfdpic_got_section (info
)->size
)
5526 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTGOT
, 0))
5529 if (frvfdpic_pltrel_section (info
)->size
)
5530 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
5531 || !_bfd_elf_add_dynamic_entry (info
, DT_PLTREL
, DT_REL
)
5532 || !_bfd_elf_add_dynamic_entry (info
, DT_JMPREL
, 0))
5535 if (frvfdpic_gotrel_section (info
)->size
)
5536 if (!_bfd_elf_add_dynamic_entry (info
, DT_REL
, 0)
5537 || !_bfd_elf_add_dynamic_entry (info
, DT_RELSZ
, 0)
5538 || !_bfd_elf_add_dynamic_entry (info
, DT_RELENT
,
5539 sizeof (Elf32_External_Rel
)))
5547 elf32_frvfdpic_always_size_sections (bfd
*output_bfd
,
5548 struct bfd_link_info
*info
)
5550 if (!info
->relocatable
)
5552 struct elf_link_hash_entry
*h
;
5554 /* Force a PT_GNU_STACK segment to be created. */
5555 if (! elf_tdata (output_bfd
)->stack_flags
)
5556 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
| PF_X
;
5558 /* Define __stacksize if it's not defined yet. */
5559 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
5560 FALSE
, FALSE
, FALSE
);
5561 if (! h
|| h
->root
.type
!= bfd_link_hash_defined
5562 || h
->type
!= STT_OBJECT
5565 struct bfd_link_hash_entry
*bh
= NULL
;
5567 if (!(_bfd_generic_link_add_one_symbol
5568 (info
, output_bfd
, "__stacksize",
5569 BSF_GLOBAL
, bfd_abs_section_ptr
, DEFAULT_STACK_SIZE
,
5570 (const char *) NULL
, FALSE
,
5571 get_elf_backend_data (output_bfd
)->collect
, &bh
)))
5574 h
= (struct elf_link_hash_entry
*) bh
;
5576 h
->type
= STT_OBJECT
;
5577 /* This one must NOT be hidden. */
5584 /* Look for opportunities to relax TLS relocations. We can assume
5585 we're linking the main executable or a static-tls library, since
5586 otherwise we wouldn't have got here. */
5589 _frvfdpic_relax_got_plt_entries (void **entryp
, void *dinfo_
)
5591 struct frvfdpic_relocs_info
*entry
= *entryp
;
5592 struct _frvfdpic_dynamic_got_info
*dinfo
= dinfo_
;
5594 _frvfdpic_relax_tls_entries (entry
, dinfo
, TRUE
);
5600 elf32_frvfdpic_relax_section (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
,
5601 struct bfd_link_info
*info
, bfd_boolean
*again
)
5603 struct _frvfdpic_dynamic_got_plt_info gpinfo
;
5605 /* If we return early, we didn't change anything. */
5608 /* We'll do our thing when requested to relax the GOT section. */
5609 if (sec
!= frvfdpic_got_section (info
))
5612 /* We can only relax when linking the main executable or a library
5613 that can't be dlopened. */
5614 if (! info
->executable
&& ! (info
->flags
& DF_STATIC_TLS
))
5617 /* If there isn't a TLS section for this binary, we can't do
5618 anything about its TLS relocations (it probably doesn't have
5620 if (elf_hash_table (info
)->tls_sec
== NULL
)
5623 memset (&gpinfo
, 0, sizeof (gpinfo
));
5624 memcpy (&gpinfo
.g
, frvfdpic_dynamic_got_plt_info (info
), sizeof (gpinfo
.g
));
5626 /* Now look for opportunities to relax, adjusting the GOT usage
5628 htab_traverse (frvfdpic_relocs_info (info
),
5629 _frvfdpic_relax_got_plt_entries
,
5632 /* If we changed anything, reset and re-assign GOT and PLT entries. */
5633 if (memcmp (frvfdpic_dynamic_got_plt_info (info
),
5634 &gpinfo
.g
, sizeof (gpinfo
.g
)) != 0)
5636 /* Clear GOT and PLT assignments. */
5637 htab_traverse (frvfdpic_relocs_info (info
),
5638 _frvfdpic_reset_got_plt_entries
,
5641 /* The owner of the TLS section is the output bfd. There should
5642 be a better way to get to it. */
5643 if (!_frvfdpic_size_got_plt (elf_hash_table (info
)->tls_sec
->owner
,
5647 /* Repeat until we don't make any further changes. We could fail to
5648 introduce changes in a round if, for example, the 12-bit range is
5649 full, but we later release some space by getting rid of TLS
5650 descriptors in it. We have to repeat the whole process because
5651 we might have changed the size of a section processed before this
5660 elf32_frvfdpic_modify_program_headers (bfd
*output_bfd
,
5661 struct bfd_link_info
*info
)
5663 struct elf_obj_tdata
*tdata
= elf_tdata (output_bfd
);
5664 struct elf_segment_map
*m
;
5665 Elf_Internal_Phdr
*p
;
5667 /* objcopy and strip preserve what's already there using
5668 elf32_frvfdpic_copy_private_bfd_data (). */
5672 for (p
= tdata
->phdr
, m
= tdata
->segment_map
; m
!= NULL
; m
= m
->next
, p
++)
5673 if (m
->p_type
== PT_GNU_STACK
)
5678 struct elf_link_hash_entry
*h
;
5680 /* Obtain the pointer to the __stacksize symbol. */
5681 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
5682 FALSE
, FALSE
, FALSE
);
5685 while (h
->root
.type
== bfd_link_hash_indirect
5686 || h
->root
.type
== bfd_link_hash_warning
)
5687 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5688 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
5691 /* Set the header p_memsz from the symbol value. We
5692 intentionally ignore the symbol section. */
5693 if (h
&& h
->root
.type
== bfd_link_hash_defined
)
5694 p
->p_memsz
= h
->root
.u
.def
.value
;
5696 p
->p_memsz
= DEFAULT_STACK_SIZE
;
5704 /* Fill in code and data in dynamic sections. */
5707 elf32_frv_finish_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5708 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
5710 /* Nothing to be done for non-FDPIC. */
5715 elf32_frvfdpic_finish_dynamic_sections (bfd
*output_bfd
,
5716 struct bfd_link_info
*info
)
5721 dynobj
= elf_hash_table (info
)->dynobj
;
5723 if (frvfdpic_dynamic_got_plt_info (info
))
5725 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info
)->tls_ret_refs
== 0);
5727 if (frvfdpic_got_section (info
))
5729 BFD_ASSERT (frvfdpic_gotrel_section (info
)->size
5730 == (frvfdpic_gotrel_section (info
)->reloc_count
5731 * sizeof (Elf32_External_Rel
)));
5733 if (frvfdpic_gotfixup_section (info
))
5735 struct elf_link_hash_entry
*hgot
= elf_hash_table (info
)->hgot
;
5736 bfd_vma got_value
= hgot
->root
.u
.def
.value
5737 + hgot
->root
.u
.def
.section
->output_section
->vma
5738 + hgot
->root
.u
.def
.section
->output_offset
;
5739 struct bfd_link_hash_entry
*hend
;
5741 _frvfdpic_add_rofixup (output_bfd
, frvfdpic_gotfixup_section (info
),
5744 if (frvfdpic_gotfixup_section (info
)->size
5745 != (frvfdpic_gotfixup_section (info
)->reloc_count
* 4))
5748 (*_bfd_error_handler
)
5749 ("LINKER BUG: .rofixup section size mismatch");
5753 hend
= bfd_link_hash_lookup (info
->hash
, "__ROFIXUP_END__",
5754 FALSE
, FALSE
, TRUE
);
5756 && (hend
->type
== bfd_link_hash_defined
5757 || hend
->type
== bfd_link_hash_defweak
))
5760 frvfdpic_gotfixup_section (info
)->output_section
->vma
5761 + frvfdpic_gotfixup_section (info
)->output_offset
5762 + frvfdpic_gotfixup_section (info
)->size
5763 - hend
->u
.def
.section
->output_section
->vma
5764 - hend
->u
.def
.section
->output_offset
;
5765 BFD_ASSERT (hend
->u
.def
.value
== value
);
5766 if (hend
->u
.def
.value
!= value
)
5771 if (frvfdpic_pltrel_section (info
))
5773 BFD_ASSERT (frvfdpic_pltrel_section (info
)->size
5774 == (frvfdpic_pltrel_section (info
)->reloc_count
5775 * sizeof (Elf32_External_Rel
)));
5779 if (elf_hash_table (info
)->dynamic_sections_created
)
5781 Elf32_External_Dyn
* dyncon
;
5782 Elf32_External_Dyn
* dynconend
;
5784 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5786 BFD_ASSERT (sdyn
!= NULL
);
5788 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5789 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5791 for (; dyncon
< dynconend
; dyncon
++)
5793 Elf_Internal_Dyn dyn
;
5795 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5803 dyn
.d_un
.d_ptr
= frvfdpic_got_section (info
)->output_section
->vma
5804 + frvfdpic_got_section (info
)->output_offset
5805 + frvfdpic_got_initial_offset (info
);
5806 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5810 dyn
.d_un
.d_ptr
= frvfdpic_pltrel_section (info
)
5811 ->output_section
->vma
5812 + frvfdpic_pltrel_section (info
)->output_offset
;
5813 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5817 dyn
.d_un
.d_val
= frvfdpic_pltrel_section (info
)->size
;
5818 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5827 /* Adjust a symbol defined by a dynamic object and referenced by a
5831 elf32_frvfdpic_adjust_dynamic_symbol
5832 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5833 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
5837 dynobj
= elf_hash_table (info
)->dynobj
;
5839 /* Make sure we know what is going on here. */
5840 BFD_ASSERT (dynobj
!= NULL
5841 && (h
->u
.weakdef
!= NULL
5844 && !h
->def_regular
)));
5846 /* If this is a weak symbol, and there is a real definition, the
5847 processor independent code will have arranged for us to see the
5848 real definition first, and we can just use the same value. */
5849 if (h
->u
.weakdef
!= NULL
)
5851 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
5852 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
5853 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
5854 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
5860 /* Perform any actions needed for dynamic symbols. */
5863 elf32_frvfdpic_finish_dynamic_symbol
5864 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5865 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5866 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
,
5867 Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
)
5872 /* Decide whether to attempt to turn absptr or lsda encodings in
5873 shared libraries into pcrel within the given input section. */
5876 frvfdpic_elf_use_relative_eh_frame
5877 (bfd
*input_bfd ATTRIBUTE_UNUSED
,
5878 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5879 asection
*eh_frame_section ATTRIBUTE_UNUSED
)
5881 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
5885 /* Adjust the contents of an eh_frame_hdr section before they're output. */
5888 frvfdpic_elf_encode_eh_address (bfd
*abfd
,
5889 struct bfd_link_info
*info
,
5890 asection
*osec
, bfd_vma offset
,
5891 asection
*loc_sec
, bfd_vma loc_offset
,
5894 struct elf_link_hash_entry
*h
;
5896 h
= elf_hash_table (info
)->hgot
;
5897 BFD_ASSERT (h
&& h
->root
.type
== bfd_link_hash_defined
);
5899 if (! h
|| (_frvfdpic_osec_to_segment (abfd
, osec
)
5900 == _frvfdpic_osec_to_segment (abfd
, loc_sec
->output_section
)))
5901 return _bfd_elf_encode_eh_address (abfd
, info
, osec
, offset
,
5902 loc_sec
, loc_offset
, encoded
);
5904 BFD_ASSERT (_frvfdpic_osec_to_segment (abfd
, osec
)
5905 == (_frvfdpic_osec_to_segment
5906 (abfd
, h
->root
.u
.def
.section
->output_section
)));
5908 *encoded
= osec
->vma
+ offset
5909 - (h
->root
.u
.def
.value
5910 + h
->root
.u
.def
.section
->output_section
->vma
5911 + h
->root
.u
.def
.section
->output_offset
);
5913 return DW_EH_PE_datarel
| DW_EH_PE_sdata4
;
5916 /* Look through the relocs for a section during the first phase.
5918 Besides handling virtual table relocs for gc, we have to deal with
5919 all sorts of PIC-related relocations. We describe below the
5920 general plan on how to handle such relocations, even though we only
5921 collect information at this point, storing them in hash tables for
5922 perusal of later passes.
5924 32 relocations are propagated to the linker output when creating
5925 position-independent output. LO16 and HI16 relocations are not
5926 supposed to be encountered in this case.
5928 LABEL16 should always be resolvable by the linker, since it's only
5931 LABEL24, on the other hand, is used by calls. If it turns out that
5932 the target of a call is a dynamic symbol, a PLT entry must be
5933 created for it, which triggers the creation of a private function
5934 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
5936 GPREL relocations require the referenced symbol to be in the same
5937 segment as _gp, but this can only be checked later.
5939 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
5940 exist. LABEL24 might as well, since it may require a PLT entry,
5941 that will require a got.
5943 Non-FUNCDESC GOT relocations require a GOT entry to be created
5944 regardless of whether the symbol is dynamic. However, since a
5945 global symbol that turns out to not be exported may have the same
5946 address of a non-dynamic symbol, we don't assign GOT entries at
5947 this point, such that we can share them in this case. A relocation
5948 for the GOT entry always has to be created, be it to offset a
5949 private symbol by the section load address, be it to get the symbol
5950 resolved dynamically.
5952 FUNCDESC GOT relocations require a GOT entry to be created, and
5953 handled as if a FUNCDESC relocation was applied to the GOT entry in
5956 FUNCDESC relocations referencing a symbol that turns out to NOT be
5957 dynamic cause a private function descriptor to be created. The
5958 FUNCDESC relocation then decays to a 32 relocation that points at
5959 the private descriptor. If the symbol is dynamic, the FUNCDESC
5960 relocation is propagated to the linker output, such that the
5961 dynamic linker creates the canonical descriptor, pointing to the
5962 dynamically-resolved definition of the function.
5964 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
5965 symbols that are assigned to the same segment as the GOT, but we
5966 can only check this later, after we know the complete set of
5967 symbols defined and/or exported.
5969 FUNCDESC GOTOFF relocations require a function descriptor to be
5970 created and, unless lazy binding is disabled or the symbol is not
5971 dynamic, a lazy PLT entry. Since we can't tell at this point
5972 whether a symbol is going to be dynamic, we have to decide later
5973 whether to create a lazy PLT entry or bind the descriptor directly
5974 to the private function.
5976 FUNCDESC_VALUE relocations are not supposed to be present in object
5977 files, but they may very well be simply propagated to the linker
5978 output, since they have no side effect.
5981 A function descriptor always requires a FUNCDESC_VALUE relocation.
5982 Whether it's in .plt.rel or not depends on whether lazy binding is
5983 enabled and on whether the referenced symbol is dynamic.
5985 The existence of a lazy PLT requires the resolverStub lazy PLT
5986 entry to be present.
5989 As for assignment of GOT, PLT and lazy PLT entries, and private
5990 descriptors, we might do them all sequentially, but we can do
5991 better than that. For example, we can place GOT entries and
5992 private function descriptors referenced using 12-bit operands
5993 closer to the PIC register value, such that these relocations don't
5994 overflow. Those that are only referenced with LO16 relocations
5995 could come next, but we may as well place PLT-required function
5996 descriptors in the 12-bit range to make them shorter. Symbols
5997 referenced with LO16/HI16 may come next, but we may place
5998 additional function descriptors in the 16-bit range if we can
5999 reliably tell that we've already placed entries that are ever
6000 referenced with only LO16. PLT entries are therefore generated as
6001 small as possible, while not introducing relocation overflows in
6002 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
6003 generated before or after PLT entries, but not intermingled with
6004 them, such that we can have more lazy PLT entries in range for a
6005 branch to the resolverStub. The resolverStub should be emitted at
6006 the most distant location from the first lazy PLT entry such that
6007 it's still in range for a branch, or closer, if there isn't a need
6008 for so many lazy PLT entries. Additional lazy PLT entries may be
6009 emitted after the resolverStub, as long as branches are still in
6010 range. If the branch goes out of range, longer lazy PLT entries
6013 We could further optimize PLT and lazy PLT entries by giving them
6014 priority in assignment to closer-to-gr17 locations depending on the
6015 number of occurrences of references to them (assuming a function
6016 that's called more often is more important for performance, so its
6017 PLT entry should be faster), or taking hints from the compiler.
6018 Given infinite time and money... :-) */
6021 elf32_frv_check_relocs (abfd
, info
, sec
, relocs
)
6023 struct bfd_link_info
*info
;
6025 const Elf_Internal_Rela
*relocs
;
6027 Elf_Internal_Shdr
*symtab_hdr
;
6028 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
6029 const Elf_Internal_Rela
*rel
;
6030 const Elf_Internal_Rela
*rel_end
;
6032 struct frvfdpic_relocs_info
*picrel
;
6034 if (info
->relocatable
)
6037 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6038 sym_hashes
= elf_sym_hashes (abfd
);
6039 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof(Elf32_External_Sym
);
6040 if (!elf_bad_symtab (abfd
))
6041 sym_hashes_end
-= symtab_hdr
->sh_info
;
6043 dynobj
= elf_hash_table (info
)->dynobj
;
6044 rel_end
= relocs
+ sec
->reloc_count
;
6045 for (rel
= relocs
; rel
< rel_end
; rel
++)
6047 struct elf_link_hash_entry
*h
;
6048 unsigned long r_symndx
;
6050 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6051 if (r_symndx
< symtab_hdr
->sh_info
)
6055 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6056 while (h
->root
.type
== bfd_link_hash_indirect
6057 || h
->root
.type
== bfd_link_hash_warning
)
6058 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6061 switch (ELF32_R_TYPE (rel
->r_info
))
6063 case R_FRV_GETTLSOFF
:
6064 case R_FRV_TLSDESC_VALUE
:
6065 case R_FRV_GOTTLSDESC12
:
6066 case R_FRV_GOTTLSDESCHI
:
6067 case R_FRV_GOTTLSDESCLO
:
6068 case R_FRV_GOTTLSOFF12
:
6069 case R_FRV_GOTTLSOFFHI
:
6070 case R_FRV_GOTTLSOFFLO
:
6075 case R_FRV_FUNCDESC_GOT12
:
6076 case R_FRV_FUNCDESC_GOTHI
:
6077 case R_FRV_FUNCDESC_GOTLO
:
6078 case R_FRV_GOTOFF12
:
6079 case R_FRV_GOTOFFHI
:
6080 case R_FRV_GOTOFFLO
:
6081 case R_FRV_FUNCDESC_GOTOFF12
:
6082 case R_FRV_FUNCDESC_GOTOFFHI
:
6083 case R_FRV_FUNCDESC_GOTOFFLO
:
6084 case R_FRV_FUNCDESC
:
6085 case R_FRV_FUNCDESC_VALUE
:
6086 case R_FRV_TLSMOFF12
:
6087 case R_FRV_TLSMOFFHI
:
6088 case R_FRV_TLSMOFFLO
:
6090 if (! IS_FDPIC (abfd
))
6094 case R_FRV_GPRELU12
:
6101 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6102 if (! _frv_create_got_section (abfd
, info
))
6105 if (! IS_FDPIC (abfd
))
6112 if (h
->dynindx
== -1)
6113 switch (ELF_ST_VISIBILITY (h
->other
))
6119 bfd_elf_link_record_dynamic_symbol (info
, h
);
6123 = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info
),
6125 rel
->r_addend
, INSERT
);
6128 picrel
= frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
6129 (info
), abfd
, r_symndx
,
6130 rel
->r_addend
, INSERT
);
6140 switch (ELF32_R_TYPE (rel
->r_info
))
6143 if (IS_FDPIC (abfd
))
6147 case R_FRV_FUNCDESC_VALUE
:
6148 picrel
->relocsfdv
++;
6149 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
6154 if (! IS_FDPIC (abfd
))
6158 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
6168 picrel
->gothilo
= 1;
6171 case R_FRV_FUNCDESC_GOT12
:
6172 picrel
->fdgot12
= 1;
6175 case R_FRV_FUNCDESC_GOTHI
:
6176 case R_FRV_FUNCDESC_GOTLO
:
6177 picrel
->fdgothilo
= 1;
6180 case R_FRV_GOTOFF12
:
6181 case R_FRV_GOTOFFHI
:
6182 case R_FRV_GOTOFFLO
:
6186 case R_FRV_FUNCDESC_GOTOFF12
:
6187 picrel
->fdgoff12
= 1;
6190 case R_FRV_FUNCDESC_GOTOFFHI
:
6191 case R_FRV_FUNCDESC_GOTOFFLO
:
6192 picrel
->fdgoffhilo
= 1;
6195 case R_FRV_FUNCDESC
:
6200 case R_FRV_GETTLSOFF
:
6204 case R_FRV_TLSDESC_VALUE
:
6205 picrel
->relocstlsd
++;
6208 case R_FRV_GOTTLSDESC12
:
6209 picrel
->tlsdesc12
= 1;
6212 case R_FRV_GOTTLSDESCHI
:
6213 case R_FRV_GOTTLSDESCLO
:
6214 picrel
->tlsdeschilo
= 1;
6217 case R_FRV_TLSMOFF12
:
6218 case R_FRV_TLSMOFFHI
:
6219 case R_FRV_TLSMOFFLO
:
6223 case R_FRV_GOTTLSOFF12
:
6224 picrel
->tlsoff12
= 1;
6225 info
->flags
|= DF_STATIC_TLS
;
6228 case R_FRV_GOTTLSOFFHI
:
6229 case R_FRV_GOTTLSOFFLO
:
6230 picrel
->tlsoffhilo
= 1;
6231 info
->flags
|= DF_STATIC_TLS
;
6235 picrel
->relocstlsoff
++;
6236 info
->flags
|= DF_STATIC_TLS
;
6239 /* This relocation describes the C++ object vtable hierarchy.
6240 Reconstruct it for later use during GC. */
6241 case R_FRV_GNU_VTINHERIT
:
6242 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6246 /* This relocation describes which C++ vtable entries are actually
6247 used. Record for later use during GC. */
6248 case R_FRV_GNU_VTENTRY
:
6249 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
6257 case R_FRV_GPRELU12
:
6261 case R_FRV_TLSDESC_RELAX
:
6262 case R_FRV_GETTLSOFF_RELAX
:
6263 case R_FRV_TLSOFF_RELAX
:
6268 (*_bfd_error_handler
)
6269 (_("%B: unsupported relocation type %i"),
6270 abfd
, ELF32_R_TYPE (rel
->r_info
));
6279 /* Return the machine subcode from the ELF e_flags header. */
6282 elf32_frv_machine (abfd
)
6285 switch (elf_elfheader (abfd
)->e_flags
& EF_FRV_CPU_MASK
)
6288 case EF_FRV_CPU_FR550
: return bfd_mach_fr550
;
6289 case EF_FRV_CPU_FR500
: return bfd_mach_fr500
;
6290 case EF_FRV_CPU_FR450
: return bfd_mach_fr450
;
6291 case EF_FRV_CPU_FR405
: return bfd_mach_fr400
;
6292 case EF_FRV_CPU_FR400
: return bfd_mach_fr400
;
6293 case EF_FRV_CPU_FR300
: return bfd_mach_fr300
;
6294 case EF_FRV_CPU_SIMPLE
: return bfd_mach_frvsimple
;
6295 case EF_FRV_CPU_TOMCAT
: return bfd_mach_frvtomcat
;
6298 return bfd_mach_frv
;
6301 /* Set the right machine number for a FRV ELF file. */
6304 elf32_frv_object_p (abfd
)
6307 bfd_default_set_arch_mach (abfd
, bfd_arch_frv
, elf32_frv_machine (abfd
));
6308 return (((elf_elfheader (abfd
)->e_flags
& EF_FRV_FDPIC
) != 0)
6309 == (IS_FDPIC (abfd
)));
6312 /* Function to set the ELF flag bits. */
6315 frv_elf_set_private_flags (abfd
, flags
)
6319 elf_elfheader (abfd
)->e_flags
= flags
;
6320 elf_flags_init (abfd
) = TRUE
;
6324 /* Copy backend specific data from one object module to another. */
6327 frv_elf_copy_private_bfd_data (ibfd
, obfd
)
6331 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6332 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6335 BFD_ASSERT (!elf_flags_init (obfd
)
6336 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
6338 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
6339 elf_flags_init (obfd
) = TRUE
;
6343 /* Return true if the architecture described by elf header flag
6344 EXTENSION is an extension of the architecture described by BASE. */
6347 frv_elf_arch_extension_p (flagword base
, flagword extension
)
6349 if (base
== extension
)
6352 /* CPU_GENERIC code can be merged with code for a specific
6353 architecture, in which case the result is marked as being
6354 for the specific architecture. Everything is therefore
6355 an extension of CPU_GENERIC. */
6356 if (base
== EF_FRV_CPU_GENERIC
)
6359 if (extension
== EF_FRV_CPU_FR450
)
6360 if (base
== EF_FRV_CPU_FR400
|| base
== EF_FRV_CPU_FR405
)
6363 if (extension
== EF_FRV_CPU_FR405
)
6364 if (base
== EF_FRV_CPU_FR400
)
6371 elf32_frvfdpic_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
6375 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6376 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6379 if (! frv_elf_copy_private_bfd_data (ibfd
, obfd
))
6382 if (! elf_tdata (ibfd
) || ! elf_tdata (ibfd
)->phdr
6383 || ! elf_tdata (obfd
) || ! elf_tdata (obfd
)->phdr
)
6386 /* Copy the stack size. */
6387 for (i
= 0; i
< elf_elfheader (ibfd
)->e_phnum
; i
++)
6388 if (elf_tdata (ibfd
)->phdr
[i
].p_type
== PT_GNU_STACK
)
6390 Elf_Internal_Phdr
*iphdr
= &elf_tdata (ibfd
)->phdr
[i
];
6392 for (i
= 0; i
< elf_elfheader (obfd
)->e_phnum
; i
++)
6393 if (elf_tdata (obfd
)->phdr
[i
].p_type
== PT_GNU_STACK
)
6395 memcpy (&elf_tdata (obfd
)->phdr
[i
], iphdr
, sizeof (*iphdr
));
6397 /* Rewrite the phdrs, since we're only called after they
6398 were first written. */
6399 if (bfd_seek (obfd
, (bfd_signed_vma
) get_elf_backend_data (obfd
)
6400 ->s
->sizeof_ehdr
, SEEK_SET
) != 0
6401 || get_elf_backend_data (obfd
)->s
6402 ->write_out_phdrs (obfd
, elf_tdata (obfd
)->phdr
,
6403 elf_elfheader (obfd
)->e_phnum
) != 0)
6414 /* Merge backend specific data from an object file to the output
6415 object file when linking. */
6418 frv_elf_merge_private_bfd_data (ibfd
, obfd
)
6422 flagword old_flags
, old_partial
;
6423 flagword new_flags
, new_partial
;
6424 bfd_boolean error
= FALSE
;
6428 new_opt
[0] = old_opt
[0] = '\0';
6429 new_flags
= elf_elfheader (ibfd
)->e_flags
;
6430 old_flags
= elf_elfheader (obfd
)->e_flags
;
6432 if (new_flags
& EF_FRV_FDPIC
)
6433 new_flags
&= ~EF_FRV_PIC
;
6436 (*_bfd_error_handler
) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s",
6437 old_flags
, new_flags
, elf_flags_init (obfd
) ? "yes" : "no",
6438 bfd_get_filename (ibfd
));
6441 if (!elf_flags_init (obfd
)) /* First call, no flags set. */
6443 elf_flags_init (obfd
) = TRUE
;
6444 old_flags
= new_flags
;
6447 else if (new_flags
== old_flags
) /* Compatible flags are ok. */
6450 else /* Possibly incompatible flags. */
6452 /* Warn if different # of gprs are used. Note, 0 means nothing is
6453 said about the size of gprs. */
6454 new_partial
= (new_flags
& EF_FRV_GPR_MASK
);
6455 old_partial
= (old_flags
& EF_FRV_GPR_MASK
);
6456 if (new_partial
== old_partial
)
6459 else if (new_partial
== 0)
6462 else if (old_partial
== 0)
6463 old_flags
|= new_partial
;
6467 switch (new_partial
)
6469 default: strcat (new_opt
, " -mgpr-??"); break;
6470 case EF_FRV_GPR_32
: strcat (new_opt
, " -mgpr-32"); break;
6471 case EF_FRV_GPR_64
: strcat (new_opt
, " -mgpr-64"); break;
6474 switch (old_partial
)
6476 default: strcat (old_opt
, " -mgpr-??"); break;
6477 case EF_FRV_GPR_32
: strcat (old_opt
, " -mgpr-32"); break;
6478 case EF_FRV_GPR_64
: strcat (old_opt
, " -mgpr-64"); break;
6482 /* Warn if different # of fprs are used. Note, 0 means nothing is
6483 said about the size of fprs. */
6484 new_partial
= (new_flags
& EF_FRV_FPR_MASK
);
6485 old_partial
= (old_flags
& EF_FRV_FPR_MASK
);
6486 if (new_partial
== old_partial
)
6489 else if (new_partial
== 0)
6492 else if (old_partial
== 0)
6493 old_flags
|= new_partial
;
6497 switch (new_partial
)
6499 default: strcat (new_opt
, " -mfpr-?"); break;
6500 case EF_FRV_FPR_32
: strcat (new_opt
, " -mfpr-32"); break;
6501 case EF_FRV_FPR_64
: strcat (new_opt
, " -mfpr-64"); break;
6502 case EF_FRV_FPR_NONE
: strcat (new_opt
, " -msoft-float"); break;
6505 switch (old_partial
)
6507 default: strcat (old_opt
, " -mfpr-?"); break;
6508 case EF_FRV_FPR_32
: strcat (old_opt
, " -mfpr-32"); break;
6509 case EF_FRV_FPR_64
: strcat (old_opt
, " -mfpr-64"); break;
6510 case EF_FRV_FPR_NONE
: strcat (old_opt
, " -msoft-float"); break;
6514 /* Warn if different dword support was used. Note, 0 means nothing is
6515 said about the dword support. */
6516 new_partial
= (new_flags
& EF_FRV_DWORD_MASK
);
6517 old_partial
= (old_flags
& EF_FRV_DWORD_MASK
);
6518 if (new_partial
== old_partial
)
6521 else if (new_partial
== 0)
6524 else if (old_partial
== 0)
6525 old_flags
|= new_partial
;
6529 switch (new_partial
)
6531 default: strcat (new_opt
, " -mdword-?"); break;
6532 case EF_FRV_DWORD_YES
: strcat (new_opt
, " -mdword"); break;
6533 case EF_FRV_DWORD_NO
: strcat (new_opt
, " -mno-dword"); break;
6536 switch (old_partial
)
6538 default: strcat (old_opt
, " -mdword-?"); break;
6539 case EF_FRV_DWORD_YES
: strcat (old_opt
, " -mdword"); break;
6540 case EF_FRV_DWORD_NO
: strcat (old_opt
, " -mno-dword"); break;
6544 /* Or in flags that accumulate (ie, if one module uses it, mark that the
6546 old_flags
|= new_flags
& (EF_FRV_DOUBLE
6549 | EF_FRV_NON_PIC_RELOCS
);
6551 /* If any module was compiled without -G0, clear the G0 bit. */
6552 old_flags
= ((old_flags
& ~ EF_FRV_G0
)
6553 | (old_flags
& new_flags
& EF_FRV_G0
));
6555 /* If any module was compiled without -mnopack, clear the mnopack bit. */
6556 old_flags
= ((old_flags
& ~ EF_FRV_NOPACK
)
6557 | (old_flags
& new_flags
& EF_FRV_NOPACK
));
6559 /* We don't have to do anything if the pic flags are the same, or the new
6560 module(s) were compiled with -mlibrary-pic. */
6561 new_partial
= (new_flags
& EF_FRV_PIC_FLAGS
);
6562 old_partial
= (old_flags
& EF_FRV_PIC_FLAGS
);
6563 if ((new_partial
== old_partial
) || ((new_partial
& EF_FRV_LIBPIC
) != 0))
6566 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
6567 flags if any from the new module. */
6568 else if ((old_partial
& EF_FRV_LIBPIC
) != 0)
6569 old_flags
= (old_flags
& ~ EF_FRV_PIC_FLAGS
) | new_partial
;
6571 /* If we have mixtures of -fpic and -fPIC, or in both bits. */
6572 else if (new_partial
!= 0 && old_partial
!= 0)
6573 old_flags
|= new_partial
;
6575 /* One module was compiled for pic and the other was not, see if we have
6576 had any relocations that are not pic-safe. */
6579 if ((old_flags
& EF_FRV_NON_PIC_RELOCS
) == 0)
6580 old_flags
|= new_partial
;
6583 old_flags
&= ~ EF_FRV_PIC_FLAGS
;
6584 #ifndef FRV_NO_PIC_ERROR
6586 (*_bfd_error_handler
)
6587 (_("%s: compiled with %s and linked with modules that use non-pic relocations"),
6588 bfd_get_filename (ibfd
),
6589 (new_flags
& EF_FRV_BIGPIC
) ? "-fPIC" : "-fpic");
6594 /* Warn if different cpu is used (allow a specific cpu to override
6595 the generic cpu). */
6596 new_partial
= (new_flags
& EF_FRV_CPU_MASK
);
6597 old_partial
= (old_flags
& EF_FRV_CPU_MASK
);
6598 if (frv_elf_arch_extension_p (new_partial
, old_partial
))
6601 else if (frv_elf_arch_extension_p (old_partial
, new_partial
))
6602 old_flags
= (old_flags
& ~EF_FRV_CPU_MASK
) | new_partial
;
6606 switch (new_partial
)
6608 default: strcat (new_opt
, " -mcpu=?"); break;
6609 case EF_FRV_CPU_GENERIC
: strcat (new_opt
, " -mcpu=frv"); break;
6610 case EF_FRV_CPU_SIMPLE
: strcat (new_opt
, " -mcpu=simple"); break;
6611 case EF_FRV_CPU_FR550
: strcat (new_opt
, " -mcpu=fr550"); break;
6612 case EF_FRV_CPU_FR500
: strcat (new_opt
, " -mcpu=fr500"); break;
6613 case EF_FRV_CPU_FR450
: strcat (new_opt
, " -mcpu=fr450"); break;
6614 case EF_FRV_CPU_FR405
: strcat (new_opt
, " -mcpu=fr405"); break;
6615 case EF_FRV_CPU_FR400
: strcat (new_opt
, " -mcpu=fr400"); break;
6616 case EF_FRV_CPU_FR300
: strcat (new_opt
, " -mcpu=fr300"); break;
6617 case EF_FRV_CPU_TOMCAT
: strcat (new_opt
, " -mcpu=tomcat"); break;
6620 switch (old_partial
)
6622 default: strcat (old_opt
, " -mcpu=?"); break;
6623 case EF_FRV_CPU_GENERIC
: strcat (old_opt
, " -mcpu=frv"); break;
6624 case EF_FRV_CPU_SIMPLE
: strcat (old_opt
, " -mcpu=simple"); break;
6625 case EF_FRV_CPU_FR550
: strcat (old_opt
, " -mcpu=fr550"); break;
6626 case EF_FRV_CPU_FR500
: strcat (old_opt
, " -mcpu=fr500"); break;
6627 case EF_FRV_CPU_FR450
: strcat (old_opt
, " -mcpu=fr450"); break;
6628 case EF_FRV_CPU_FR405
: strcat (old_opt
, " -mcpu=fr405"); break;
6629 case EF_FRV_CPU_FR400
: strcat (old_opt
, " -mcpu=fr400"); break;
6630 case EF_FRV_CPU_FR300
: strcat (old_opt
, " -mcpu=fr300"); break;
6631 case EF_FRV_CPU_TOMCAT
: strcat (old_opt
, " -mcpu=tomcat"); break;
6635 /* Print out any mismatches from above. */
6639 (*_bfd_error_handler
)
6640 (_("%s: compiled with %s and linked with modules compiled with %s"),
6641 bfd_get_filename (ibfd
), new_opt
, old_opt
);
6644 /* Warn about any other mismatches */
6645 new_partial
= (new_flags
& ~ EF_FRV_ALL_FLAGS
);
6646 old_partial
= (old_flags
& ~ EF_FRV_ALL_FLAGS
);
6647 if (new_partial
!= old_partial
)
6649 old_flags
|= new_partial
;
6651 (*_bfd_error_handler
)
6652 (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"),
6653 bfd_get_filename (ibfd
), (long)new_partial
, (long)old_partial
);
6657 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
6658 if ((old_flags
& EF_FRV_CPU_MASK
) == EF_FRV_CPU_SIMPLE
)
6659 old_flags
|= EF_FRV_NOPACK
;
6661 /* Update the old flags now with changes made above. */
6662 old_partial
= elf_elfheader (obfd
)->e_flags
& EF_FRV_CPU_MASK
;
6663 elf_elfheader (obfd
)->e_flags
= old_flags
;
6664 if (old_partial
!= (old_flags
& EF_FRV_CPU_MASK
))
6665 bfd_default_set_arch_mach (obfd
, bfd_arch_frv
, elf32_frv_machine (obfd
));
6667 if (((new_flags
& EF_FRV_FDPIC
) == 0)
6668 != (! IS_FDPIC (ibfd
)))
6671 if (IS_FDPIC (obfd
))
6672 (*_bfd_error_handler
)
6673 (_("%s: cannot link non-fdpic object file into fdpic executable"),
6674 bfd_get_filename (ibfd
));
6676 (*_bfd_error_handler
)
6677 (_("%s: cannot link fdpic object file into non-fdpic executable"),
6678 bfd_get_filename (ibfd
));
6682 bfd_set_error (bfd_error_bad_value
);
6689 frv_elf_print_private_bfd_data (abfd
, ptr
)
6693 FILE *file
= (FILE *) ptr
;
6696 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6698 /* Print normal ELF private data. */
6699 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6701 flags
= elf_elfheader (abfd
)->e_flags
;
6702 fprintf (file
, _("private flags = 0x%lx:"), (long)flags
);
6704 switch (flags
& EF_FRV_CPU_MASK
)
6707 case EF_FRV_CPU_SIMPLE
: fprintf (file
, " -mcpu=simple"); break;
6708 case EF_FRV_CPU_FR550
: fprintf (file
, " -mcpu=fr550"); break;
6709 case EF_FRV_CPU_FR500
: fprintf (file
, " -mcpu=fr500"); break;
6710 case EF_FRV_CPU_FR450
: fprintf (file
, " -mcpu=fr450"); break;
6711 case EF_FRV_CPU_FR405
: fprintf (file
, " -mcpu=fr405"); break;
6712 case EF_FRV_CPU_FR400
: fprintf (file
, " -mcpu=fr400"); break;
6713 case EF_FRV_CPU_FR300
: fprintf (file
, " -mcpu=fr300"); break;
6714 case EF_FRV_CPU_TOMCAT
: fprintf (file
, " -mcpu=tomcat"); break;
6717 switch (flags
& EF_FRV_GPR_MASK
)
6720 case EF_FRV_GPR_32
: fprintf (file
, " -mgpr-32"); break;
6721 case EF_FRV_GPR_64
: fprintf (file
, " -mgpr-64"); break;
6724 switch (flags
& EF_FRV_FPR_MASK
)
6727 case EF_FRV_FPR_32
: fprintf (file
, " -mfpr-32"); break;
6728 case EF_FRV_FPR_64
: fprintf (file
, " -mfpr-64"); break;
6729 case EF_FRV_FPR_NONE
: fprintf (file
, " -msoft-float"); break;
6732 switch (flags
& EF_FRV_DWORD_MASK
)
6735 case EF_FRV_DWORD_YES
: fprintf (file
, " -mdword"); break;
6736 case EF_FRV_DWORD_NO
: fprintf (file
, " -mno-dword"); break;
6739 if (flags
& EF_FRV_DOUBLE
)
6740 fprintf (file
, " -mdouble");
6742 if (flags
& EF_FRV_MEDIA
)
6743 fprintf (file
, " -mmedia");
6745 if (flags
& EF_FRV_MULADD
)
6746 fprintf (file
, " -mmuladd");
6748 if (flags
& EF_FRV_PIC
)
6749 fprintf (file
, " -fpic");
6751 if (flags
& EF_FRV_BIGPIC
)
6752 fprintf (file
, " -fPIC");
6754 if (flags
& EF_FRV_LIBPIC
)
6755 fprintf (file
, " -mlibrary-pic");
6757 if (flags
& EF_FRV_FDPIC
)
6758 fprintf (file
, " -mfdpic");
6760 if (flags
& EF_FRV_NON_PIC_RELOCS
)
6761 fprintf (file
, " non-pic relocations");
6763 if (flags
& EF_FRV_G0
)
6764 fprintf (file
, " -G0");
6771 /* Support for core dump NOTE sections. */
6774 elf32_frv_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
6777 unsigned int raw_size
;
6779 switch (note
->descsz
)
6784 /* The Linux/FRV elf_prstatus struct is 268 bytes long. The other
6785 hardcoded offsets and sizes listed below (and contained within
6786 this lexical block) refer to fields in the target's elf_prstatus
6789 /* `pr_cursig' is at offset 12. */
6790 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
6792 /* `pr_pid' is at offset 24. */
6793 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
6795 /* `pr_reg' is at offset 72. */
6798 /* Most grok_prstatus implementations set `raw_size' to the size
6799 of the pr_reg field. For Linux/FRV, we set `raw_size' to be
6800 the size of `pr_reg' plus the size of `pr_exec_fdpic_loadmap'
6801 and `pr_interp_fdpic_loadmap', both of which (by design)
6802 immediately follow `pr_reg'. This will allow these fields to
6803 be viewed by GDB as registers.
6805 `pr_reg' is 184 bytes long. `pr_exec_fdpic_loadmap' and
6806 `pr_interp_fdpic_loadmap' are 4 bytes each. */
6807 raw_size
= 184 + 4 + 4;
6812 /* Make a ".reg/999" section. */
6813 return _bfd_elfcore_make_pseudosection (abfd
, ".reg", raw_size
,
6814 note
->descpos
+ offset
);
6818 elf32_frv_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
6820 switch (note
->descsz
)
6825 /* The Linux/FRV elf_prpsinfo struct is 124 bytes long. */
6828 /* `pr_fname' is found at offset 28 and is 16 bytes long. */
6829 elf_tdata (abfd
)->core_program
6830 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
6832 /* `pr_psargs' is found at offset 44 and is 80 bytes long. */
6833 elf_tdata (abfd
)->core_command
6834 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
6837 /* Note that for some reason, a spurious space is tacked
6838 onto the end of the args in some (at least one anyway)
6839 implementations, so strip it off if it exists. */
6842 char *command
= elf_tdata (abfd
)->core_command
;
6843 int n
= strlen (command
);
6845 if (0 < n
&& command
[n
- 1] == ' ')
6846 command
[n
- 1] = '\0';
6851 #define ELF_ARCH bfd_arch_frv
6852 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
6853 #define ELF_MAXPAGESIZE 0x1000
6855 #define TARGET_BIG_SYM bfd_elf32_frv_vec
6856 #define TARGET_BIG_NAME "elf32-frv"
6858 #define elf_info_to_howto frv_info_to_howto_rela
6859 #define elf_backend_relocate_section elf32_frv_relocate_section
6860 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
6861 #define elf_backend_check_relocs elf32_frv_check_relocs
6862 #define elf_backend_object_p elf32_frv_object_p
6863 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
6865 #define elf_backend_can_gc_sections 1
6866 #define elf_backend_rela_normal 1
6868 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
6869 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
6870 #define bfd_elf32_bfd_copy_private_bfd_data frv_elf_copy_private_bfd_data
6871 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
6872 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
6874 #define elf_backend_want_got_sym 1
6875 #define elf_backend_got_header_size 0
6876 #define elf_backend_want_got_plt 0
6877 #define elf_backend_plt_readonly 1
6878 #define elf_backend_want_plt_sym 0
6879 #define elf_backend_plt_header_size 0
6881 #define elf_backend_finish_dynamic_sections \
6882 elf32_frv_finish_dynamic_sections
6884 #define elf_backend_grok_prstatus elf32_frv_grok_prstatus
6885 #define elf_backend_grok_psinfo elf32_frv_grok_psinfo
6887 #include "elf32-target.h"
6889 #undef ELF_MAXPAGESIZE
6890 #define ELF_MAXPAGESIZE 0x4000
6892 #undef TARGET_BIG_SYM
6893 #define TARGET_BIG_SYM bfd_elf32_frvfdpic_vec
6894 #undef TARGET_BIG_NAME
6895 #define TARGET_BIG_NAME "elf32-frvfdpic"
6897 #define elf32_bed elf32_frvfdpic_bed
6899 #undef elf_info_to_howto_rel
6900 #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel
6902 #undef bfd_elf32_bfd_link_hash_table_create
6903 #define bfd_elf32_bfd_link_hash_table_create \
6904 frvfdpic_elf_link_hash_table_create
6905 #undef elf_backend_always_size_sections
6906 #define elf_backend_always_size_sections \
6907 elf32_frvfdpic_always_size_sections
6908 #undef elf_backend_modify_program_headers
6909 #define elf_backend_modify_program_headers \
6910 elf32_frvfdpic_modify_program_headers
6911 #undef bfd_elf32_bfd_copy_private_bfd_data
6912 #define bfd_elf32_bfd_copy_private_bfd_data \
6913 elf32_frvfdpic_copy_private_bfd_data
6915 #undef elf_backend_create_dynamic_sections
6916 #define elf_backend_create_dynamic_sections \
6917 elf32_frvfdpic_create_dynamic_sections
6918 #undef elf_backend_adjust_dynamic_symbol
6919 #define elf_backend_adjust_dynamic_symbol \
6920 elf32_frvfdpic_adjust_dynamic_symbol
6921 #undef elf_backend_size_dynamic_sections
6922 #define elf_backend_size_dynamic_sections \
6923 elf32_frvfdpic_size_dynamic_sections
6924 #undef bfd_elf32_bfd_relax_section
6925 #define bfd_elf32_bfd_relax_section \
6926 elf32_frvfdpic_relax_section
6927 #undef elf_backend_finish_dynamic_symbol
6928 #define elf_backend_finish_dynamic_symbol \
6929 elf32_frvfdpic_finish_dynamic_symbol
6930 #undef elf_backend_finish_dynamic_sections
6931 #define elf_backend_finish_dynamic_sections \
6932 elf32_frvfdpic_finish_dynamic_sections
6934 #undef elf_backend_can_make_relative_eh_frame
6935 #define elf_backend_can_make_relative_eh_frame \
6936 frvfdpic_elf_use_relative_eh_frame
6937 #undef elf_backend_can_make_lsda_relative_eh_frame
6938 #define elf_backend_can_make_lsda_relative_eh_frame \
6939 frvfdpic_elf_use_relative_eh_frame
6940 #undef elf_backend_encode_eh_address
6941 #define elf_backend_encode_eh_address \
6942 frvfdpic_elf_encode_eh_address
6944 #undef elf_backend_may_use_rel_p
6945 #define elf_backend_may_use_rel_p 1
6946 #undef elf_backend_may_use_rela_p
6947 #define elf_backend_may_use_rela_p 1
6948 /* We use REL for dynamic relocations only. */
6949 #undef elf_backend_default_use_rela_p
6950 #define elf_backend_default_use_rela_p 1
6952 #undef elf_backend_omit_section_dynsym
6953 #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym
6955 #include "elf32-target.h"