1 /* FRV-specific support for 32-bit ELF.
2 Copyright 2002, 2003 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 #include "elf/dwarf2.h"
28 /* Forward declarations. */
29 static bfd_reloc_status_type elf32_frv_relocate_lo16
30 PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
31 static bfd_reloc_status_type elf32_frv_relocate_hi16
32 PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
33 static bfd_reloc_status_type elf32_frv_relocate_label24
34 PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
35 static bfd_reloc_status_type elf32_frv_relocate_gprel12
36 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
37 bfd_byte *, bfd_vma));
38 static bfd_reloc_status_type elf32_frv_relocate_gprelu12
39 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
40 bfd_byte *, bfd_vma));
41 static bfd_reloc_status_type elf32_frv_relocate_gprello
42 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
43 bfd_byte *, bfd_vma));
44 static bfd_reloc_status_type elf32_frv_relocate_gprelhi
45 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
46 bfd_byte *, bfd_vma));
47 static reloc_howto_type *frv_reloc_type_lookup
48 PARAMS ((bfd *, bfd_reloc_code_real_type));
49 static void frv_info_to_howto_rela
50 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
51 static bfd_boolean elf32_frv_relocate_section
52 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
53 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
54 static bfd_boolean elf32_frv_add_symbol_hook
55 PARAMS (( bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
56 const char **, flagword *, asection **, bfd_vma *));
57 static bfd_reloc_status_type frv_final_link_relocate
58 PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *,
59 Elf_Internal_Rela *, bfd_vma));
60 static bfd_boolean elf32_frv_gc_sweep_hook
61 PARAMS ((bfd *, struct bfd_link_info *, asection *, const
62 Elf_Internal_Rela *));
63 static asection * elf32_frv_gc_mark_hook
64 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
65 struct elf_link_hash_entry *, Elf_Internal_Sym *));
66 static bfd_boolean elf32_frv_check_relocs
67 PARAMS ((bfd *, struct bfd_link_info *, asection *,
68 const Elf_Internal_Rela *));
69 static int elf32_frv_machine
71 static bfd_boolean elf32_frv_object_p
73 static bfd_boolean frv_elf_set_private_flags
74 PARAMS ((bfd *, flagword));
75 static bfd_boolean frv_elf_copy_private_bfd_data
76 PARAMS ((bfd *, bfd *));
77 static bfd_boolean frv_elf_merge_private_bfd_data
78 PARAMS ((bfd *, bfd *));
79 static bfd_boolean frv_elf_print_private_bfd_data
80 PARAMS ((bfd *, PTR));
82 static reloc_howto_type elf32_frv_howto_table [] =
84 /* This reloc does nothing. */
85 HOWTO (R_FRV_NONE, /* type */
87 2, /* size (0 = byte, 1 = short, 2 = long) */
89 FALSE, /* pc_relative */
91 complain_overflow_bitfield, /* complain_on_overflow */
92 bfd_elf_generic_reloc, /* special_function */
93 "R_FRV_NONE", /* name */
94 FALSE, /* partial_inplace */
97 FALSE), /* pcrel_offset */
99 /* A 32 bit absolute relocation. */
100 HOWTO (R_FRV_32, /* type */
102 2, /* size (0 = byte, 1 = short, 2 = long) */
104 FALSE, /* pc_relative */
106 complain_overflow_bitfield, /* complain_on_overflow */
107 bfd_elf_generic_reloc, /* special_function */
108 "R_FRV_32", /* name */
109 FALSE, /* partial_inplace */
110 0xffffffff, /* src_mask */
111 0xffffffff, /* dst_mask */
112 FALSE), /* pcrel_offset */
114 /* A 16 bit pc-relative relocation. */
115 HOWTO (R_FRV_LABEL16, /* type */
117 2, /* size (0 = byte, 1 = short, 2 = long) */
119 TRUE, /* pc_relative */
121 complain_overflow_signed, /* complain_on_overflow */
122 bfd_elf_generic_reloc, /* special_function */
123 "R_FRV_LABEL16", /* name */
124 FALSE, /* partial_inplace */
125 0xffff, /* src_mask */
126 0xffff, /* dst_mask */
127 TRUE), /* pcrel_offset */
129 /* A 24-bit pc-relative relocation. */
130 HOWTO (R_FRV_LABEL24, /* type */
132 2, /* size (0 = byte, 1 = short, 2 = long) */
134 TRUE, /* pc_relative */
136 complain_overflow_bitfield, /* complain_on_overflow */
137 bfd_elf_generic_reloc, /* special_function */
138 "R_FRV_LABEL24", /* name */
139 FALSE, /* partial_inplace */
140 0x7e03ffff, /* src_mask */
141 0x7e03ffff, /* dst_mask */
142 TRUE), /* pcrel_offset */
144 HOWTO (R_FRV_LO16, /* type */
146 2, /* size (0 = byte, 1 = short, 2 = long) */
148 FALSE, /* pc_relative */
150 complain_overflow_dont, /* complain_on_overflow */
151 bfd_elf_generic_reloc, /* special_function */
152 "R_FRV_LO16", /* name */
153 FALSE, /* partial_inplace */
154 0xffff, /* src_mask */
155 0xffff, /* dst_mask */
156 FALSE), /* pcrel_offset */
158 HOWTO (R_FRV_HI16, /* type */
160 2, /* size (0 = byte, 1 = short, 2 = long) */
162 FALSE, /* pc_relative */
164 complain_overflow_dont, /* complain_on_overflow */
165 bfd_elf_generic_reloc, /* special_function */
166 "R_FRV_HI16", /* name */
167 FALSE, /* partial_inplace */
168 0xffff, /* src_mask */
169 0xffff, /* dst_mask */
170 FALSE), /* pcrel_offset */
172 HOWTO (R_FRV_GPREL12, /* type */
174 2, /* size (0 = byte, 1 = short, 2 = long) */
176 FALSE, /* pc_relative */
178 complain_overflow_dont, /* complain_on_overflow */
179 bfd_elf_generic_reloc, /* special_function */
180 "R_FRV_GPREL12", /* name */
181 FALSE, /* partial_inplace */
182 0xfff, /* src_mask */
183 0xfff, /* dst_mask */
184 FALSE), /* pcrel_offset */
186 HOWTO (R_FRV_GPRELU12, /* type */
188 2, /* size (0 = byte, 1 = short, 2 = long) */
190 FALSE, /* pc_relative */
192 complain_overflow_dont, /* complain_on_overflow */
193 bfd_elf_generic_reloc, /* special_function */
194 "R_FRV_GPRELU12", /* name */
195 FALSE, /* partial_inplace */
196 0xfff, /* src_mask */
197 0x3f03f, /* dst_mask */
198 FALSE), /* pcrel_offset */
200 HOWTO (R_FRV_GPREL32, /* type */
202 2, /* size (0 = byte, 1 = short, 2 = long) */
204 FALSE, /* pc_relative */
206 complain_overflow_dont, /* complain_on_overflow */
207 bfd_elf_generic_reloc, /* special_function */
208 "R_FRV_GPREL32", /* name */
209 FALSE, /* partial_inplace */
210 0xffffffff, /* src_mask */
211 0xffffffff, /* dst_mask */
212 FALSE), /* pcrel_offset */
214 HOWTO (R_FRV_GPRELHI, /* type */
216 2, /* size (0 = byte, 1 = short, 2 = long) */
218 FALSE, /* pc_relative */
220 complain_overflow_dont, /* complain_on_overflow */
221 bfd_elf_generic_reloc, /* special_function */
222 "R_FRV_GPRELHI", /* name */
223 FALSE, /* partial_inplace */
224 0xffff, /* src_mask */
225 0xffff, /* dst_mask */
226 FALSE), /* pcrel_offset */
228 HOWTO (R_FRV_GPRELLO, /* type */
230 2, /* size (0 = byte, 1 = short, 2 = long) */
232 FALSE, /* pc_relative */
234 complain_overflow_dont, /* complain_on_overflow */
235 bfd_elf_generic_reloc, /* special_function */
236 "R_FRV_GPRELLO", /* name */
237 FALSE, /* partial_inplace */
238 0xffff, /* src_mask */
239 0xffff, /* dst_mask */
240 FALSE), /* pcrel_offset */
242 /* A 12-bit signed operand with the GOT offset for the address of
244 HOWTO (R_FRV_GOT12, /* type */
246 2, /* size (0 = byte, 1 = short, 2 = long) */
248 FALSE, /* pc_relative */
250 complain_overflow_signed, /* complain_on_overflow */
251 bfd_elf_generic_reloc, /* special_function */
252 "R_FRV_GOT12", /* name */
253 FALSE, /* partial_inplace */
254 0xfff, /* src_mask */
255 0xfff, /* dst_mask */
256 FALSE), /* pcrel_offset */
258 /* The upper 16 bits of the GOT offset for the address of the
260 HOWTO (R_FRV_GOTHI, /* type */
262 2, /* size (0 = byte, 1 = short, 2 = long) */
264 FALSE, /* pc_relative */
266 complain_overflow_dont, /* complain_on_overflow */
267 bfd_elf_generic_reloc, /* special_function */
268 "R_FRV_GOTHI", /* name */
269 FALSE, /* partial_inplace */
270 0xffff, /* src_mask */
271 0xffff, /* dst_mask */
272 FALSE), /* pcrel_offset */
274 /* The lower 16 bits of the GOT offset for the address of the
276 HOWTO (R_FRV_GOTLO, /* type */
278 2, /* size (0 = byte, 1 = short, 2 = long) */
280 FALSE, /* pc_relative */
282 complain_overflow_dont, /* complain_on_overflow */
283 bfd_elf_generic_reloc, /* special_function */
284 "R_FRV_GOTLO", /* name */
285 FALSE, /* partial_inplace */
286 0xffff, /* src_mask */
287 0xffff, /* dst_mask */
288 FALSE), /* pcrel_offset */
290 /* The 32-bit address of the canonical descriptor of a function. */
291 HOWTO (R_FRV_FUNCDESC, /* type */
293 2, /* size (0 = byte, 1 = short, 2 = long) */
295 FALSE, /* pc_relative */
297 complain_overflow_bitfield, /* complain_on_overflow */
298 bfd_elf_generic_reloc, /* special_function */
299 "R_FRV_FUNCDESC", /* name */
300 FALSE, /* partial_inplace */
301 0xffffffff, /* src_mask */
302 0xffffffff, /* dst_mask */
303 FALSE), /* pcrel_offset */
305 /* A 12-bit signed operand with the GOT offset for the address of
306 canonical descriptor of a function. */
307 HOWTO (R_FRV_FUNCDESC_GOT12, /* type */
309 2, /* size (0 = byte, 1 = short, 2 = long) */
311 FALSE, /* pc_relative */
313 complain_overflow_signed, /* complain_on_overflow */
314 bfd_elf_generic_reloc, /* special_function */
315 "R_FRV_FUNCDESC_GOT12", /* name */
316 FALSE, /* partial_inplace */
317 0xfff, /* src_mask */
318 0xfff, /* dst_mask */
319 FALSE), /* pcrel_offset */
321 /* The upper 16 bits of the GOT offset for the address of the
322 canonical descriptor of a function. */
323 HOWTO (R_FRV_FUNCDESC_GOTHI, /* type */
325 2, /* size (0 = byte, 1 = short, 2 = long) */
327 FALSE, /* pc_relative */
329 complain_overflow_dont, /* complain_on_overflow */
330 bfd_elf_generic_reloc, /* special_function */
331 "R_FRV_FUNCDESC_GOTHI", /* name */
332 FALSE, /* partial_inplace */
333 0xffff, /* src_mask */
334 0xffff, /* dst_mask */
335 FALSE), /* pcrel_offset */
337 /* The lower 16 bits of the GOT offset for the address of the
338 canonical descriptor of a function. */
339 HOWTO (R_FRV_FUNCDESC_GOTLO, /* type */
341 2, /* size (0 = byte, 1 = short, 2 = long) */
343 FALSE, /* pc_relative */
345 complain_overflow_dont, /* complain_on_overflow */
346 bfd_elf_generic_reloc, /* special_function */
347 "R_FRV_FUNCDESC_GOTLO", /* name */
348 FALSE, /* partial_inplace */
349 0xffff, /* src_mask */
350 0xffff, /* dst_mask */
351 FALSE), /* pcrel_offset */
353 /* The 32-bit address of the canonical descriptor of a function. */
354 HOWTO (R_FRV_FUNCDESC_VALUE, /* type */
356 2, /* size (0 = byte, 1 = short, 2 = long) */
358 FALSE, /* pc_relative */
360 complain_overflow_bitfield, /* complain_on_overflow */
361 bfd_elf_generic_reloc, /* special_function */
362 "R_FRV_FUNCDESC_VALUE", /* name */
363 FALSE, /* partial_inplace */
364 0xffffffff, /* src_mask */
365 0xffffffff, /* dst_mask */
366 FALSE), /* pcrel_offset */
368 /* A 12-bit signed operand with the GOT offset for the address of
369 canonical descriptor of a function. */
370 HOWTO (R_FRV_FUNCDESC_GOTOFF12, /* type */
372 2, /* size (0 = byte, 1 = short, 2 = long) */
374 FALSE, /* pc_relative */
376 complain_overflow_signed, /* complain_on_overflow */
377 bfd_elf_generic_reloc, /* special_function */
378 "R_FRV_FUNCDESC_GOTOFF12", /* name */
379 FALSE, /* partial_inplace */
380 0xfff, /* src_mask */
381 0xfff, /* dst_mask */
382 FALSE), /* pcrel_offset */
384 /* The upper 16 bits of the GOT offset for the address of the
385 canonical descriptor of a function. */
386 HOWTO (R_FRV_FUNCDESC_GOTOFFHI, /* type */
388 2, /* size (0 = byte, 1 = short, 2 = long) */
390 FALSE, /* pc_relative */
392 complain_overflow_dont, /* complain_on_overflow */
393 bfd_elf_generic_reloc, /* special_function */
394 "R_FRV_FUNCDESC_GOTOFFHI", /* name */
395 FALSE, /* partial_inplace */
396 0xffff, /* src_mask */
397 0xffff, /* dst_mask */
398 FALSE), /* pcrel_offset */
400 /* The lower 16 bits of the GOT offset for the address of the
401 canonical descriptor of a function. */
402 HOWTO (R_FRV_FUNCDESC_GOTOFFLO, /* type */
404 2, /* size (0 = byte, 1 = short, 2 = long) */
406 FALSE, /* pc_relative */
408 complain_overflow_dont, /* complain_on_overflow */
409 bfd_elf_generic_reloc, /* special_function */
410 "R_FRV_FUNCDESC_GOTOFFLO", /* name */
411 FALSE, /* partial_inplace */
412 0xffff, /* src_mask */
413 0xffff, /* dst_mask */
414 FALSE), /* pcrel_offset */
416 /* A 12-bit signed operand with the GOT offset for the address of
418 HOWTO (R_FRV_GOTOFF12, /* type */
420 2, /* size (0 = byte, 1 = short, 2 = long) */
422 FALSE, /* pc_relative */
424 complain_overflow_signed, /* complain_on_overflow */
425 bfd_elf_generic_reloc, /* special_function */
426 "R_FRV_GOTOFF12", /* name */
427 FALSE, /* partial_inplace */
428 0xfff, /* src_mask */
429 0xfff, /* dst_mask */
430 FALSE), /* pcrel_offset */
432 /* The upper 16 bits of the GOT offset for the address of the
434 HOWTO (R_FRV_GOTOFFHI, /* type */
436 2, /* size (0 = byte, 1 = short, 2 = long) */
438 FALSE, /* pc_relative */
440 complain_overflow_dont, /* complain_on_overflow */
441 bfd_elf_generic_reloc, /* special_function */
442 "R_FRV_GOTOFFHI", /* name */
443 FALSE, /* partial_inplace */
444 0xffff, /* src_mask */
445 0xffff, /* dst_mask */
446 FALSE), /* pcrel_offset */
448 /* The lower 16 bits of the GOT offset for the address of the
450 HOWTO (R_FRV_GOTOFFLO, /* type */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
454 FALSE, /* pc_relative */
456 complain_overflow_dont, /* complain_on_overflow */
457 bfd_elf_generic_reloc, /* special_function */
458 "R_FRV_GOTOFFLO", /* name */
459 FALSE, /* partial_inplace */
460 0xffff, /* src_mask */
461 0xffff, /* dst_mask */
462 FALSE), /* pcrel_offset */
466 /* GNU extension to record C++ vtable hierarchy. */
467 static reloc_howto_type elf32_frv_vtinherit_howto =
468 HOWTO (R_FRV_GNU_VTINHERIT, /* type */
470 2, /* size (0 = byte, 1 = short, 2 = long) */
472 FALSE, /* pc_relative */
474 complain_overflow_dont, /* complain_on_overflow */
475 NULL, /* special_function */
476 "R_FRV_GNU_VTINHERIT", /* name */
477 FALSE, /* partial_inplace */
480 FALSE); /* pcrel_offset */
482 /* GNU extension to record C++ vtable member usage. */
483 static reloc_howto_type elf32_frv_vtentry_howto =
484 HOWTO (R_FRV_GNU_VTENTRY, /* type */
486 2, /* size (0 = byte, 1 = short, 2 = long) */
488 FALSE, /* pc_relative */
490 complain_overflow_dont, /* complain_on_overflow */
491 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
492 "R_FRV_GNU_VTENTRY", /* name */
493 FALSE, /* partial_inplace */
496 FALSE); /* pcrel_offset */
498 /* The following 3 relocations are REL. The only difference to the
499 entries in the table above are that partial_inplace is TRUE. */
500 static reloc_howto_type elf32_frv_rel_32_howto =
501 HOWTO (R_FRV_32, /* type */
503 2, /* size (0 = byte, 1 = short, 2 = long) */
505 FALSE, /* pc_relative */
507 complain_overflow_bitfield, /* complain_on_overflow */
508 bfd_elf_generic_reloc, /* special_function */
509 "R_FRV_32", /* name */
510 TRUE, /* partial_inplace */
511 0xffffffff, /* src_mask */
512 0xffffffff, /* dst_mask */
513 FALSE); /* pcrel_offset */
515 static reloc_howto_type elf32_frv_rel_funcdesc_howto =
516 HOWTO (R_FRV_FUNCDESC, /* type */
518 2, /* size (0 = byte, 1 = short, 2 = long) */
520 FALSE, /* pc_relative */
522 complain_overflow_bitfield, /* complain_on_overflow */
523 bfd_elf_generic_reloc, /* special_function */
524 "R_FRV_FUNCDESC", /* name */
525 TRUE, /* partial_inplace */
526 0xffffffff, /* src_mask */
527 0xffffffff, /* dst_mask */
528 FALSE); /* pcrel_offset */
530 static reloc_howto_type elf32_frv_rel_funcdesc_value_howto =
531 HOWTO (R_FRV_FUNCDESC_VALUE, /* type */
533 2, /* size (0 = byte, 1 = short, 2 = long) */
535 FALSE, /* pc_relative */
537 complain_overflow_bitfield, /* complain_on_overflow */
538 bfd_elf_generic_reloc, /* special_function */
539 "R_FRV_FUNCDESC_VALUE", /* name */
540 TRUE, /* partial_inplace */
541 0xffffffff, /* src_mask */
542 0xffffffff, /* dst_mask */
543 FALSE); /* pcrel_offset */
546 /* Map BFD reloc types to FRV ELF reloc types. */
550 unsigned int bfd_reloc_val;
551 unsigned int frv_reloc_val;
554 static const struct frv_reloc_map frv_reloc_map [] =
556 { BFD_RELOC_NONE, R_FRV_NONE },
557 { BFD_RELOC_32, R_FRV_32 },
558 { BFD_RELOC_FRV_LABEL16, R_FRV_LABEL16 },
559 { BFD_RELOC_FRV_LABEL24, R_FRV_LABEL24 },
560 { BFD_RELOC_FRV_LO16, R_FRV_LO16 },
561 { BFD_RELOC_FRV_HI16, R_FRV_HI16 },
562 { BFD_RELOC_FRV_GPREL12, R_FRV_GPREL12 },
563 { BFD_RELOC_FRV_GPRELU12, R_FRV_GPRELU12 },
564 { BFD_RELOC_FRV_GPREL32, R_FRV_GPREL32 },
565 { BFD_RELOC_FRV_GPRELHI, R_FRV_GPRELHI },
566 { BFD_RELOC_FRV_GPRELLO, R_FRV_GPRELLO },
567 { BFD_RELOC_FRV_GOT12, R_FRV_GOT12 },
568 { BFD_RELOC_FRV_GOTHI, R_FRV_GOTHI },
569 { BFD_RELOC_FRV_GOTLO, R_FRV_GOTLO },
570 { BFD_RELOC_FRV_FUNCDESC, R_FRV_FUNCDESC },
571 { BFD_RELOC_FRV_FUNCDESC_GOT12, R_FRV_FUNCDESC_GOT12 },
572 { BFD_RELOC_FRV_FUNCDESC_GOTHI, R_FRV_FUNCDESC_GOTHI },
573 { BFD_RELOC_FRV_FUNCDESC_GOTLO, R_FRV_FUNCDESC_GOTLO },
574 { BFD_RELOC_FRV_FUNCDESC_VALUE, R_FRV_FUNCDESC_VALUE },
575 { BFD_RELOC_FRV_FUNCDESC_GOTOFF12, R_FRV_FUNCDESC_GOTOFF12 },
576 { BFD_RELOC_FRV_FUNCDESC_GOTOFFHI, R_FRV_FUNCDESC_GOTOFFHI },
577 { BFD_RELOC_FRV_FUNCDESC_GOTOFFLO, R_FRV_FUNCDESC_GOTOFFLO },
578 { BFD_RELOC_FRV_GOTOFF12, R_FRV_GOTOFF12 },
579 { BFD_RELOC_FRV_GOTOFFHI, R_FRV_GOTOFFHI },
580 { BFD_RELOC_FRV_GOTOFFLO, R_FRV_GOTOFFLO },
581 { BFD_RELOC_VTABLE_INHERIT, R_FRV_GNU_VTINHERIT },
582 { BFD_RELOC_VTABLE_ENTRY, R_FRV_GNU_VTENTRY },
587 /* An extension of the elf hash table data structure, containing some
588 additional FRV-specific data. */
589 struct frv_elf_link_hash_table
591 struct elf_link_hash_table elf;
593 /* A pointer to the .got section. */
595 /* A pointer to the .rel.got section. */
597 /* A pointer to the .rofixup section. */
599 /* A pointer to the .plt section. */
601 /* A pointer to the .rel.plt section. */
603 /* GOT base offset. */
605 /* Location of the first non-lazy PLT entry, i.e., the number of
606 bytes taken by lazy PLT entries. */
608 /* A hash table holding information about which symbols were
609 referenced with which PIC-related relocations. */
610 struct htab *relocs_info;
613 /* Get the FRV ELF linker hash table from a link_info structure. */
615 #define frv_hash_table(info) \
616 ((struct frv_elf_link_hash_table *) ((info)->hash))
618 #define frv_got_section(info) \
619 (frv_hash_table (info)->sgot)
620 #define frv_gotrel_section(info) \
621 (frv_hash_table (info)->sgotrel)
622 #define frv_gotfixup_section(info) \
623 (frv_hash_table (info)->sgotfixup)
624 #define frv_plt_section(info) \
625 (frv_hash_table (info)->splt)
626 #define frv_pltrel_section(info) \
627 (frv_hash_table (info)->spltrel)
628 #define frv_relocs_info(info) \
629 (frv_hash_table (info)->relocs_info)
630 #define frv_got_initial_offset(info) \
631 (frv_hash_table (info)->got0)
632 #define frv_plt_initial_offset(info) \
633 (frv_hash_table (info)->plt0)
635 /* Create an FRV ELF linker hash table. */
637 static struct bfd_link_hash_table *
638 frv_elf_link_hash_table_create (bfd *abfd)
640 struct frv_elf_link_hash_table *ret;
641 bfd_size_type amt = sizeof (struct frv_elf_link_hash_table);
643 ret = bfd_zalloc (abfd, amt);
647 if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd,
648 _bfd_elf_link_hash_newfunc))
654 return &ret->elf.root;
657 /* Decide whether a reference to a symbol can be resolved locally or
658 not. If the symbol is protected, we want the local address, but
659 its function descriptor must be assigned by the dynamic linker. */
660 #define FRV_SYM_LOCAL(INFO, H) \
661 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
662 || ! elf_hash_table (INFO)->dynamic_sections_created \
663 || (/* The condition below is an ugly hack to get .scommon data to
664 be regarded as local. For some reason the
665 ELF_LINK_HASH_DEF_REGULAR bit is not set on such common
666 symbols, and the SEC_IS_COMMON bit is not set any longer
667 when we need to perform this test. Hopefully this
668 approximation is good enough. */ \
669 ((H)->root.type == bfd_link_hash_defined \
670 || (H)->root.type == bfd_link_hash_defweak) \
671 && (H)->root.u.def.section->output_section \
672 && ((H)->root.u.def.section->flags & SEC_LINKER_CREATED)))
673 #define FRV_FUNCDESC_LOCAL(INFO, H) \
674 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
676 /* This structure collects information on what kind of GOT, PLT or
677 function descriptors are required by relocations that reference a
679 struct frv_pic_relocs_info
681 /* The index of the symbol, as stored in the relocation r_info, if
682 we have a local symbol; -1 otherwise. */
686 /* The input bfd in which the symbol is defined, if it's a local
689 /* If symndx == -1, the hash table entry corresponding to a global
690 symbol (even if it turns out to bind locally, in which case it
691 should ideally be replaced with section's symndx + addend). */
692 struct elf_link_hash_entry *h;
694 /* The addend of the relocation that references the symbol. */
697 /* The fields above are used to identify an entry. The fields below
698 contain information on how an entry is used and, later on, which
699 locations it was assigned. */
700 /* The following 3 fields record whether the symbol+addend above was
701 ever referenced with a GOT relocation. The 12 suffix indicates a
702 GOT12 relocation; los is used for GOTLO relocations that are not
703 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
708 /* Whether a FUNCDESC relocation references symbol+addend. */
710 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
713 unsigned fdgothilo:1;
714 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
716 unsigned fdgofflos:1;
717 unsigned fdgoffhilo:1;
718 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
719 GOTOFFHI relocations. The addend doesn't really matter, since we
720 envision that this will only be used to check whether the symbol
721 is mapped to the same segment as the got. */
723 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
725 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
728 /* Whether we need a PLT entry for a symbol. Should be implied by
730 (call && symndx == -1 && ! FRV_SYM_LOCAL (info, d.h)) */
732 /* Whether a function descriptor should be created in this link unit
733 for symbol+addend. Should be implied by something like:
734 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
735 || ((fd || fdgot12 || fdgotlos || fdgothilo)
736 && (symndx != -1 || FRV_FUNCDESC_LOCAL (info, d.h)))) */
738 /* Whether a lazy PLT entry is needed for this symbol+addend.
739 Should be implied by something like:
740 (privfd && symndx == -1 && ! FRV_SYM_LOCAL (info, d.h)
741 && ! (info->flags & DF_BIND_NOW)) */
743 /* Whether we've already emitted GOT relocations and PLT entries as
744 needed for this symbol. */
747 /* The number of R_FRV_32, R_FRV_FUNCDESC and R_FRV_FUNCDESC_VALUE
748 relocations referencing the symbol. */
749 unsigned relocs32, relocsfd, relocsfdv;
751 /* The offsets of the GOT entries assigned to symbol+addend, to the
752 function descriptor's address, and to a function descriptor,
753 respectively. Should be zero if unassigned. The offsets are
754 counted from the value that will be assigned to the PIC register,
755 not from the beginning of the .got section. */
756 bfd_signed_vma got_entry, fdgot_entry, fd_entry;
757 /* The offsets of the PLT entries assigned to symbol+addend,
758 non-lazy and lazy, respectively. If unassigned, should be
760 bfd_vma plt_entry, lzplt_entry;
763 /* Compute a hash with the key fields of an frv_pic_relocs_info entry. */
765 frv_pic_relocs_info_hash (const void *entry_)
767 const struct frv_pic_relocs_info *entry = entry_;
769 return (entry->symndx == -1
770 ? entry->d.h->root.root.hash
771 : entry->symndx + entry->d.abfd->id * 257) + entry->addend;
774 /* Test whether the key fields of two frv_pic_relocs_info entries are
777 frv_pic_relocs_info_eq (const void *entry1, const void *entry2)
779 const struct frv_pic_relocs_info *e1 = entry1;
780 const struct frv_pic_relocs_info *e2 = entry2;
782 return e1->symndx == e2->symndx && e1->addend == e2->addend
783 && (e1->symndx == -1 ? e1->d.h == e2->d.h : e1->d.abfd == e2->d.abfd);
786 /* Find or create an entry in a hash table HT that matches the key
787 fields of the given ENTRY. If it's not found, memory for a new
788 entry is allocated in ABFD's obstack. */
789 static struct frv_pic_relocs_info *
790 frv_pic_relocs_info_find (struct htab *ht,
792 const struct frv_pic_relocs_info *entry)
794 struct frv_pic_relocs_info **loc =
795 (struct frv_pic_relocs_info **) htab_find_slot (ht, entry, INSERT);
800 *loc = bfd_zalloc (abfd, sizeof (**loc));
805 (*loc)->symndx = entry->symndx;
806 (*loc)->d = entry->d;
807 (*loc)->addend = entry->addend;
808 (*loc)->plt_entry = (bfd_vma)-1;
809 (*loc)->lzplt_entry = (bfd_vma)-1;
814 /* Obtain the address of the entry in HT associated with H's symbol +
815 addend, creating a new entry if none existed. ABFD is only used
816 for memory allocation purposes. */
817 inline static struct frv_pic_relocs_info *
818 frv_pic_relocs_info_for_global (struct htab *ht,
820 struct elf_link_hash_entry *h,
823 struct frv_pic_relocs_info entry;
827 entry.addend = addend;
829 return frv_pic_relocs_info_find (ht, abfd, &entry);
832 /* Obtain the address of the entry in HT associated with the SYMNDXth
833 local symbol of the input bfd ABFD, plus the addend, creating a new
834 entry if none existed. */
835 inline static struct frv_pic_relocs_info *
836 frv_pic_relocs_info_for_local (struct htab *ht,
841 struct frv_pic_relocs_info entry;
843 entry.symndx = symndx;
845 entry.addend = addend;
847 return frv_pic_relocs_info_find (ht, abfd, &entry);
850 /* Every block of 65535 lazy PLT entries shares a single call to the
851 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
852 32767, counting from 0). All other lazy PLT entries branch to it
853 in a single instruction. */
855 #define FRV_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
856 #define FRV_LZPLT_RESOLV_LOC (8 * 32767)
858 /* Add a dynamic relocation to the SRELOC section. */
860 inline static bfd_vma
861 _frv_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset,
862 int reloc_type, long dynindx, bfd_vma addend)
864 Elf_Internal_Rela outrel;
865 bfd_vma reloc_offset;
867 outrel.r_offset = offset;
868 outrel.r_info = ELF32_R_INFO (dynindx, reloc_type);
869 outrel.r_addend = addend;
871 reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rel);
872 BFD_ASSERT (reloc_offset < sreloc->_raw_size);
873 bfd_elf32_swap_reloc_out (output_bfd, &outrel,
874 sreloc->contents + reloc_offset);
875 sreloc->reloc_count++;
880 /* Add a fixup to the ROFIXUP section. */
883 _frv_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset)
885 bfd_vma fixup_offset;
887 if (rofixup->flags & SEC_EXCLUDE)
890 fixup_offset = rofixup->reloc_count * 4;
891 if (rofixup->contents)
893 BFD_ASSERT (fixup_offset < rofixup->_raw_size);
894 bfd_put_32 (output_bfd, offset, rofixup->contents + fixup_offset);
896 rofixup->reloc_count++;
901 /* Find the segment number in which OSEC, and output section, is
905 _frv_osec_to_segment (bfd *output_bfd, asection *osec)
907 struct elf_segment_map *m;
908 Elf_Internal_Phdr *p;
910 /* Find the segment that contains the output_section. */
911 for (m = elf_tdata (output_bfd)->segment_map,
912 p = elf_tdata (output_bfd)->phdr;
918 for (i = m->count - 1; i >= 0; i--)
919 if (m->sections[i] == osec)
926 return p - elf_tdata (output_bfd)->phdr;
929 inline static bfd_boolean
930 _frv_osec_readonly_p (bfd *output_bfd, asection *osec)
932 unsigned seg = _frv_osec_to_segment (output_bfd, osec);
934 return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W);
937 /* Generate relocations for GOT entries, function descriptors, and
938 code for PLT and lazy PLT entries. */
940 inline static bfd_boolean
941 _frv_emit_got_relocs_plt_entries (struct frv_pic_relocs_info *entry,
943 struct bfd_link_info *info,
945 Elf_Internal_Sym *sym,
949 bfd_vma fd_lazy_rel_offset = (bfd_vma)-1;
956 if (entry->got_entry || entry->fdgot_entry || entry->fd_entry)
958 /* If the symbol is dynamic, consider it for dynamic
959 relocations, otherwise decay to section + offset. */
960 if (entry->symndx == -1 && entry->d.h->dynindx != -1)
961 dynindx = entry->d.h->dynindx;
964 if (sec->output_section
965 && ! bfd_is_abs_section (sec->output_section)
966 && ! bfd_is_und_section (sec->output_section))
967 dynindx = elf_section_data (sec->output_section)->dynindx;
973 /* Generate relocation for GOT entry pointing to the symbol. */
974 if (entry->got_entry)
979 /* If the symbol is dynamic but binds locally, use
981 if (sec && (entry->symndx != -1 || FRV_SYM_LOCAL (info, entry->d.h)))
983 if (entry->symndx == -1)
984 ad += entry->d.h->root.u.def.value;
987 ad += sec->output_offset;
988 if (sec->output_section && elf_section_data (sec->output_section))
989 idx = elf_section_data (sec->output_section)->dynindx;
994 /* If we're linking an executable at a fixed address, we can
995 omit the dynamic relocation as long as the symbol is local to
997 if (info->executable && !info->pie
998 && (entry->symndx != -1 || FRV_SYM_LOCAL (info, entry->d.h)))
1001 ad += sec->output_section->vma;
1002 if (entry->symndx != -1 ||
1003 entry->d.h->root.type != bfd_link_hash_undefweak)
1004 _frv_add_rofixup (output_bfd, frv_gotfixup_section (info),
1005 frv_got_section (info)->output_section->vma
1006 + frv_got_section (info)->output_offset
1007 + frv_got_initial_offset (info)
1008 + entry->got_entry);
1011 _frv_add_dyn_reloc (output_bfd, frv_gotrel_section (info),
1012 _bfd_elf_section_offset
1014 frv_got_section (info),
1015 frv_got_initial_offset (info)
1017 + frv_got_section (info)->output_section->vma
1018 + frv_got_section (info)->output_offset,
1021 bfd_put_32 (output_bfd, ad,
1022 frv_got_section (info)->contents
1023 + frv_got_initial_offset (info)
1024 + entry->got_entry);
1027 /* Generate relocation for GOT entry pointing to a canonical
1028 function descriptor. */
1029 if (entry->fdgot_entry)
1034 if (! (entry->symndx == -1
1035 && entry->d.h->root.type == bfd_link_hash_undefweak
1036 && FRV_SYM_LOCAL (info, entry->d.h)))
1038 /* If the symbol is dynamic and there may be dynamic symbol
1039 resolution because we are, or are linked with, a shared
1040 library, emit a FUNCDESC relocation such that the dynamic
1041 linker will allocate the function descriptor. If the
1042 symbol needs a non-local function descriptor but binds
1043 locally (e.g., its visibility is protected, emit a
1044 dynamic relocation decayed to section+offset. */
1045 if (entry->symndx == -1 && ! FRV_FUNCDESC_LOCAL (info, entry->d.h)
1046 && FRV_SYM_LOCAL (info, entry->d.h)
1047 && !(info->executable && !info->pie))
1049 reloc = R_FRV_FUNCDESC;
1050 idx = elf_section_data (entry->d.h->root.u.def.section
1051 ->output_section)->dynindx;
1052 ad = entry->d.h->root.u.def.section->output_offset
1053 + entry->d.h->root.u.def.value;
1055 else if (entry->symndx == -1
1056 && ! FRV_FUNCDESC_LOCAL (info, entry->d.h))
1058 reloc = R_FRV_FUNCDESC;
1066 /* Otherwise, we know we have a private function descriptor,
1067 so reference it directly. */
1068 if (elf_hash_table (info)->dynamic_sections_created)
1069 BFD_ASSERT (entry->privfd);
1071 idx = elf_section_data (frv_got_section (info)
1072 ->output_section)->dynindx;
1073 ad = frv_got_section (info)->output_offset
1074 + frv_got_initial_offset (info) + entry->fd_entry;
1077 /* If there is room for dynamic symbol resolution, emit the
1078 dynamic relocation. However, if we're linking an
1079 executable at a fixed location, we won't have emitted a
1080 dynamic symbol entry for the got section, so idx will be
1081 zero, which means we can and should compute the address
1082 of the private descriptor ourselves. */
1083 if (info->executable && !info->pie
1084 && (entry->symndx != -1
1085 || FRV_FUNCDESC_LOCAL (info, entry->d.h)))
1087 ad += frv_got_section (info)->output_section->vma;
1088 _frv_add_rofixup (output_bfd, frv_gotfixup_section (info),
1089 frv_got_section (info)->output_section->vma
1090 + frv_got_section (info)->output_offset
1091 + frv_got_initial_offset (info)
1092 + entry->fdgot_entry);
1095 _frv_add_dyn_reloc (output_bfd, frv_gotrel_section (info),
1096 _bfd_elf_section_offset
1098 frv_got_section (info),
1099 frv_got_initial_offset (info)
1100 + entry->fdgot_entry)
1101 + frv_got_section (info)->output_section->vma
1102 + frv_got_section (info)->output_offset,
1106 bfd_put_32 (output_bfd, ad,
1107 frv_got_section (info)->contents
1108 + frv_got_initial_offset (info)
1109 + entry->fdgot_entry);
1112 /* Generate relocation to fill in a private function descriptor in
1114 if (entry->fd_entry)
1117 bfd_vma ad = addend;
1119 long lowword, highword;
1121 /* If the symbol is dynamic but binds locally, use
1123 if (sec && (entry->symndx != -1 || FRV_SYM_LOCAL (info, entry->d.h)))
1125 if (entry->symndx == -1)
1126 ad += entry->d.h->root.u.def.value;
1128 ad += sym->st_value;
1129 ad += sec->output_offset;
1130 if (sec->output_section && elf_section_data (sec->output_section))
1131 idx = elf_section_data (sec->output_section)->dynindx;
1136 /* If we're linking an executable at a fixed address, we can
1137 omit the dynamic relocation as long as the symbol is local to
1139 if (info->executable && !info->pie
1140 && (entry->symndx != -1 || FRV_SYM_LOCAL (info, entry->d.h)))
1143 ad += sec->output_section->vma;
1145 if (entry->symndx != -1 ||
1146 entry->d.h->root.type != bfd_link_hash_undefweak)
1148 _frv_add_rofixup (output_bfd, frv_gotfixup_section (info),
1149 frv_got_section (info)->output_section->vma
1150 + frv_got_section (info)->output_offset
1151 + frv_got_initial_offset (info)
1153 _frv_add_rofixup (output_bfd, frv_gotfixup_section (info),
1154 frv_got_section (info)->output_section->vma
1155 + frv_got_section (info)->output_offset
1156 + frv_got_initial_offset (info)
1157 + entry->fd_entry + 4);
1163 _frv_add_dyn_reloc (output_bfd,
1164 entry->lazyplt ? frv_pltrel_section (info)
1165 : frv_gotrel_section (info),
1166 _bfd_elf_section_offset
1168 frv_got_section (info),
1169 frv_got_initial_offset (info)
1171 + frv_got_section (info)->output_section->vma
1172 + frv_got_section (info)->output_offset,
1173 R_FRV_FUNCDESC_VALUE, idx, ad);
1176 /* If we've omitted the dynamic relocation, just emit the fixed
1177 addresses of the symbol and of the local GOT base offset. */
1178 if (info->executable && !info->pie && sec && sec->output_section)
1181 highword = frv_got_section (info)->output_section->vma
1182 + frv_got_section (info)->output_offset
1183 + frv_got_initial_offset (info);
1185 else if (entry->lazyplt)
1190 fd_lazy_rel_offset = ofst;
1192 /* A function descriptor used for lazy or local resolving is
1193 initialized such that its high word contains the output
1194 section index in which the PLT entries are located, and
1195 the low word contains the address of the lazy PLT entry
1196 entry point, that must be within the memory region
1197 assigned to that section. */
1198 lowword = entry->lzplt_entry + 4
1199 + frv_plt_section (info)->output_offset
1200 + frv_plt_section (info)->output_section->vma;
1201 highword = _frv_osec_to_segment
1202 (output_bfd, frv_plt_section (info)->output_section);
1206 /* A function descriptor for a local function gets the index
1207 of the section. For a non-local function, it's
1210 if (entry->symndx == -1 && entry->d.h->dynindx != -1
1211 && entry->d.h->dynindx == idx)
1214 highword = _frv_osec_to_segment (output_bfd, sec->output_section);
1217 bfd_put_32 (output_bfd, lowword,
1218 frv_got_section (info)->contents
1219 + frv_got_initial_offset (info)
1221 bfd_put_32 (output_bfd, highword,
1222 frv_got_section (info)->contents
1223 + frv_got_initial_offset (info)
1224 + entry->fd_entry + 4);
1227 /* Generate code for the PLT entry. */
1228 if (entry->plt_entry != (bfd_vma) -1)
1230 bfd_byte *plt_code = frv_plt_section (info)->contents + entry->plt_entry;
1232 BFD_ASSERT (entry->fd_entry);
1234 /* Figure out what kind of PLT entry we need, depending on the
1235 location of the function descriptor within the GOT. */
1236 if (entry->fd_entry >= -(1 << (12 - 1))
1237 && entry->fd_entry < (1 << (12 - 1)))
1239 /* lddi @(gr15, fd_entry), gr14 */
1240 bfd_put_32 (output_bfd,
1241 0x9cccf000 | (entry->fd_entry & ((1 << 12) - 1)),
1247 if (entry->fd_entry >= -(1 << (16 - 1))
1248 && entry->fd_entry < (1 << (16 - 1)))
1250 /* setlos lo(fd_entry), gr14 */
1251 bfd_put_32 (output_bfd,
1253 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
1259 /* sethi.p hi(fd_entry), gr14
1260 setlo lo(fd_entry), gr14 */
1261 bfd_put_32 (output_bfd,
1263 | ((entry->fd_entry >> 16)
1264 & (((bfd_vma)1 << 16) - 1)),
1266 bfd_put_32 (output_bfd,
1268 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
1272 /* ldd @(gr14,gr15),gr14 */
1273 bfd_put_32 (output_bfd, 0x9c08e14f, plt_code);
1276 /* jmpl @(gr14,gr0) */
1277 bfd_put_32 (output_bfd, 0x8030e000, plt_code);
1280 /* Generate code for the lazy PLT entry. */
1281 if (entry->lzplt_entry != (bfd_vma) -1)
1283 bfd_byte *lzplt_code = frv_plt_section (info)->contents
1284 + entry->lzplt_entry;
1285 bfd_vma resolverStub_addr;
1287 bfd_put_32 (output_bfd, fd_lazy_rel_offset, lzplt_code);
1290 resolverStub_addr = entry->lzplt_entry / FRV_LZPLT_BLOCK_SIZE
1291 * FRV_LZPLT_BLOCK_SIZE + FRV_LZPLT_RESOLV_LOC;
1292 if (resolverStub_addr >= frv_plt_initial_offset (info))
1293 resolverStub_addr = frv_plt_initial_offset (info) - 12;
1295 if (entry->lzplt_entry == resolverStub_addr)
1297 /* This is a lazy PLT entry that includes a resolver call. */
1298 /* ldd @(gr15,gr0), gr4
1300 bfd_put_32 (output_bfd, 0x8808f140, lzplt_code);
1301 bfd_put_32 (output_bfd, 0x80304000, lzplt_code + 4);
1305 /* bra resolverStub */
1306 bfd_put_32 (output_bfd,
1308 | (((resolverStub_addr - entry->lzplt_entry)
1309 / 4) & (((bfd_vma)1 << 16) - 1)),
1317 /* Handle an FRV small data reloc. */
1319 static bfd_reloc_status_type
1320 elf32_frv_relocate_gprel12 (info, input_bfd, input_section, relocation,
1322 struct bfd_link_info *info;
1324 asection *input_section;
1325 Elf_Internal_Rela *relocation;
1331 struct bfd_link_hash_entry *h;
1333 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
1335 gp = (h->u.def.value
1336 + h->u.def.section->output_section->vma
1337 + h->u.def.section->output_offset);
1339 value -= input_section->output_section->vma;
1340 value -= (gp - input_section->output_section->vma);
1342 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
1344 value += relocation->r_addend;
1346 if ((long) value > 0x7ff || (long) value < -0x800)
1347 return bfd_reloc_overflow;
1349 bfd_put_32 (input_bfd,
1350 (insn & 0xfffff000) | (value & 0xfff),
1351 contents + relocation->r_offset);
1353 return bfd_reloc_ok;
1356 /* Handle an FRV small data reloc. for the u12 field. */
1358 static bfd_reloc_status_type
1359 elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, relocation,
1361 struct bfd_link_info *info;
1363 asection *input_section;
1364 Elf_Internal_Rela *relocation;
1370 struct bfd_link_hash_entry *h;
1373 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
1375 gp = (h->u.def.value
1376 + h->u.def.section->output_section->vma
1377 + h->u.def.section->output_offset);
1379 value -= input_section->output_section->vma;
1380 value -= (gp - input_section->output_section->vma);
1382 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
1384 value += relocation->r_addend;
1386 if ((long) value > 0x7ff || (long) value < -0x800)
1387 return bfd_reloc_overflow;
1389 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
1391 insn = (insn & ~mask) | ((value & 0xfc0) << 12) | (value & 0x3f);
1393 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
1395 return bfd_reloc_ok;
1398 /* Handle an FRV ELF HI16 reloc. */
1400 static bfd_reloc_status_type
1401 elf32_frv_relocate_hi16 (input_bfd, relhi, contents, value)
1403 Elf_Internal_Rela *relhi;
1409 insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
1411 value += relhi->r_addend;
1412 value = ((value >> 16) & 0xffff);
1414 insn = (insn & 0xffff0000) | value;
1416 if ((long) value > 0xffff || (long) value < -0x10000)
1417 return bfd_reloc_overflow;
1419 bfd_put_32 (input_bfd, insn, contents + relhi->r_offset);
1420 return bfd_reloc_ok;
1423 static bfd_reloc_status_type
1424 elf32_frv_relocate_lo16 (input_bfd, rello, contents, value)
1426 Elf_Internal_Rela *rello;
1432 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
1434 value += rello->r_addend;
1435 value = value & 0xffff;
1437 insn = (insn & 0xffff0000) | value;
1439 if ((long) value > 0xffff || (long) value < -0x10000)
1440 return bfd_reloc_overflow;
1442 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
1443 return bfd_reloc_ok;
1446 /* Perform the relocation for the CALL label24 instruction. */
1448 static bfd_reloc_status_type
1449 elf32_frv_relocate_label24 (input_bfd, input_section, rello, contents, value)
1451 asection *input_section;
1452 Elf_Internal_Rela *rello;
1460 /* The format for the call instruction is:
1462 0 000000 0001111 000000000000000000
1463 label6 opcode label18
1465 The branch calculation is: pc + (4*label24)
1466 where label24 is the concatenation of label6 and label18. */
1468 /* Grab the instruction. */
1469 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
1471 value -= input_section->output_section->vma + input_section->output_offset;
1472 value -= rello->r_offset;
1473 value += rello->r_addend;
1477 label6 = value & 0xfc0000;
1478 label6 = label6 << 7;
1480 label18 = value & 0x3ffff;
1482 insn = insn & 0x803c0000;
1483 insn = insn | label6;
1484 insn = insn | label18;
1486 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
1488 return bfd_reloc_ok;
1491 static bfd_reloc_status_type
1492 elf32_frv_relocate_gprelhi (info, input_bfd, input_section, relocation,
1494 struct bfd_link_info *info;
1496 asection *input_section;
1497 Elf_Internal_Rela *relocation;
1503 struct bfd_link_hash_entry *h;
1505 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
1507 gp = (h->u.def.value
1508 + h->u.def.section->output_section->vma
1509 + h->u.def.section->output_offset);
1511 value -= input_section->output_section->vma;
1512 value -= (gp - input_section->output_section->vma);
1513 value += relocation->r_addend;
1514 value = ((value >> 16) & 0xffff);
1516 if ((long) value > 0xffff || (long) value < -0x10000)
1517 return bfd_reloc_overflow;
1519 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
1520 insn = (insn & 0xffff0000) | value;
1522 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
1523 return bfd_reloc_ok;
1526 static bfd_reloc_status_type
1527 elf32_frv_relocate_gprello (info, input_bfd, input_section, relocation,
1529 struct bfd_link_info *info;
1531 asection *input_section;
1532 Elf_Internal_Rela *relocation;
1538 struct bfd_link_hash_entry *h;
1540 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
1542 gp = (h->u.def.value
1543 + h->u.def.section->output_section->vma
1544 + h->u.def.section->output_offset);
1546 value -= input_section->output_section->vma;
1547 value -= (gp - input_section->output_section->vma);
1548 value += relocation->r_addend;
1549 value = value & 0xffff;
1551 if ((long) value > 0xffff || (long) value < -0x10000)
1552 return bfd_reloc_overflow;
1554 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
1555 insn = (insn & 0xffff0000) | value;
1557 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
1559 return bfd_reloc_ok;
1562 static reloc_howto_type *
1563 frv_reloc_type_lookup (abfd, code)
1564 bfd *abfd ATTRIBUTE_UNUSED;
1565 bfd_reloc_code_real_type code;
1572 case BFD_RELOC_NONE:
1573 return &elf32_frv_howto_table[ (int) R_FRV_NONE];
1576 if (elf_elfheader (abfd)->e_type == ET_EXEC
1577 || elf_elfheader (abfd)->e_type == ET_DYN)
1578 return &elf32_frv_rel_32_howto;
1580 case BFD_RELOC_CTOR:
1581 return &elf32_frv_howto_table[ (int) R_FRV_32];
1583 case BFD_RELOC_FRV_LABEL16:
1584 return &elf32_frv_howto_table[ (int) R_FRV_LABEL16];
1586 case BFD_RELOC_FRV_LABEL24:
1587 return &elf32_frv_howto_table[ (int) R_FRV_LABEL24];
1589 case BFD_RELOC_FRV_LO16:
1590 return &elf32_frv_howto_table[ (int) R_FRV_LO16];
1592 case BFD_RELOC_FRV_HI16:
1593 return &elf32_frv_howto_table[ (int) R_FRV_HI16];
1595 case BFD_RELOC_FRV_GPREL12:
1596 return &elf32_frv_howto_table[ (int) R_FRV_GPREL12];
1598 case BFD_RELOC_FRV_GPRELU12:
1599 return &elf32_frv_howto_table[ (int) R_FRV_GPRELU12];
1601 case BFD_RELOC_FRV_GPREL32:
1602 return &elf32_frv_howto_table[ (int) R_FRV_GPREL32];
1604 case BFD_RELOC_FRV_GPRELHI:
1605 return &elf32_frv_howto_table[ (int) R_FRV_GPRELHI];
1607 case BFD_RELOC_FRV_GPRELLO:
1608 return &elf32_frv_howto_table[ (int) R_FRV_GPRELLO];
1610 case BFD_RELOC_FRV_GOT12:
1611 return &elf32_frv_howto_table[ (int) R_FRV_GOT12];
1613 case BFD_RELOC_FRV_GOTHI:
1614 return &elf32_frv_howto_table[ (int) R_FRV_GOTHI];
1616 case BFD_RELOC_FRV_GOTLO:
1617 return &elf32_frv_howto_table[ (int) R_FRV_GOTLO];
1619 case BFD_RELOC_FRV_FUNCDESC:
1620 if (elf_elfheader (abfd)->e_type == ET_EXEC
1621 || elf_elfheader (abfd)->e_type == ET_DYN)
1622 return &elf32_frv_rel_funcdesc_howto;
1623 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC];
1625 case BFD_RELOC_FRV_FUNCDESC_GOT12:
1626 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOT12];
1628 case BFD_RELOC_FRV_FUNCDESC_GOTHI:
1629 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTHI];
1631 case BFD_RELOC_FRV_FUNCDESC_GOTLO:
1632 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTLO];
1634 case BFD_RELOC_FRV_FUNCDESC_VALUE:
1635 if (elf_elfheader (abfd)->e_type == ET_EXEC
1636 || elf_elfheader (abfd)->e_type == ET_DYN)
1637 return &elf32_frv_rel_funcdesc_value_howto;
1638 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_VALUE];
1640 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12:
1641 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFF12];
1643 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI:
1644 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFHI];
1646 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO:
1647 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFLO];
1649 case BFD_RELOC_FRV_GOTOFF12:
1650 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFF12];
1652 case BFD_RELOC_FRV_GOTOFFHI:
1653 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFHI];
1655 case BFD_RELOC_FRV_GOTOFFLO:
1656 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFLO];
1658 case BFD_RELOC_VTABLE_INHERIT:
1659 return &elf32_frv_vtinherit_howto;
1661 case BFD_RELOC_VTABLE_ENTRY:
1662 return &elf32_frv_vtentry_howto;
1668 /* Set the howto pointer for an FRV ELF reloc. */
1671 frv_info_to_howto_rela (abfd, cache_ptr, dst)
1672 bfd *abfd ATTRIBUTE_UNUSED;
1674 Elf_Internal_Rela *dst;
1676 unsigned int r_type;
1678 r_type = ELF32_R_TYPE (dst->r_info);
1681 case R_FRV_GNU_VTINHERIT:
1682 cache_ptr->howto = &elf32_frv_vtinherit_howto;
1685 case R_FRV_GNU_VTENTRY:
1686 cache_ptr->howto = &elf32_frv_vtentry_howto;
1690 cache_ptr->howto = & elf32_frv_howto_table [r_type];
1695 /* Set the howto pointer for an FRV ELF REL reloc. */
1697 frv_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
1698 arelent *cache_ptr, Elf_Internal_Rela *dst)
1700 unsigned int r_type;
1702 r_type = ELF32_R_TYPE (dst->r_info);
1706 cache_ptr->howto = &elf32_frv_rel_32_howto;
1709 case R_FRV_FUNCDESC:
1710 cache_ptr->howto = &elf32_frv_rel_funcdesc_howto;
1713 case R_FRV_FUNCDESC_VALUE:
1714 cache_ptr->howto = &elf32_frv_rel_funcdesc_value_howto;
1718 cache_ptr->howto = NULL;
1723 /* Perform a single relocation. By default we use the standard BFD
1724 routines, but a few relocs, we have to do them ourselves. */
1726 static bfd_reloc_status_type
1727 frv_final_link_relocate (howto, input_bfd, input_section, contents, rel,
1729 reloc_howto_type *howto;
1731 asection *input_section;
1733 Elf_Internal_Rela *rel;
1736 return _bfd_final_link_relocate (howto, input_bfd, input_section,
1737 contents, rel->r_offset, relocation,
1742 /* Relocate an FRV ELF section.
1744 The RELOCATE_SECTION function is called by the new ELF backend linker
1745 to handle the relocations for a section.
1747 The relocs are always passed as Rela structures; if the section
1748 actually uses Rel structures, the r_addend field will always be
1751 This function is responsible for adjusting the section contents as
1752 necessary, and (if using Rela relocs and generating a relocatable
1753 output file) adjusting the reloc addend as necessary.
1755 This function does not have to worry about setting the reloc
1756 address or the reloc symbol index.
1758 LOCAL_SYMS is a pointer to the swapped in local symbols.
1760 LOCAL_SECTIONS is an array giving the section in the input file
1761 corresponding to the st_shndx field of each local symbol.
1763 The global hash table entry for the global symbols can be found
1764 via elf_sym_hashes (input_bfd).
1766 When generating relocatable output, this function must handle
1767 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1768 going to be the section symbol corresponding to the output
1769 section, which means that the addend must be adjusted
1773 elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
1774 contents, relocs, local_syms, local_sections)
1775 bfd *output_bfd ATTRIBUTE_UNUSED;
1776 struct bfd_link_info *info;
1778 asection *input_section;
1780 Elf_Internal_Rela *relocs;
1781 Elf_Internal_Sym *local_syms;
1782 asection **local_sections;
1784 Elf_Internal_Shdr *symtab_hdr;
1785 struct elf_link_hash_entry **sym_hashes;
1786 Elf_Internal_Rela *rel;
1787 Elf_Internal_Rela *relend;
1788 unsigned isec_segment, got_segment, plt_segment, gprel_segment,
1790 int silence_segment_error = !(info->shared || info->pie);
1792 if (info->relocatable)
1795 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
1796 sym_hashes = elf_sym_hashes (input_bfd);
1797 relend = relocs + input_section->reloc_count;
1799 isec_segment = _frv_osec_to_segment (output_bfd,
1800 input_section->output_section);
1801 if (frv_got_section (info))
1802 got_segment = _frv_osec_to_segment (output_bfd,
1803 frv_got_section (info)
1807 if (frv_gotfixup_section (info))
1808 gprel_segment = _frv_osec_to_segment (output_bfd,
1809 frv_gotfixup_section (info)
1813 if (elf_hash_table (info)->dynamic_sections_created)
1814 plt_segment = _frv_osec_to_segment (output_bfd,
1815 frv_plt_section (info)
1820 for (rel = relocs; rel < relend; rel ++)
1822 reloc_howto_type *howto;
1823 unsigned long r_symndx;
1824 Elf_Internal_Sym *sym;
1826 struct elf_link_hash_entry *h;
1828 bfd_reloc_status_type r;
1829 const char * name = NULL;
1832 struct frv_pic_relocs_info *picrel;
1833 bfd_vma orig_addend = rel->r_addend;
1835 r_type = ELF32_R_TYPE (rel->r_info);
1837 if ( r_type == R_FRV_GNU_VTINHERIT
1838 || r_type == R_FRV_GNU_VTENTRY)
1841 /* This is a final link. */
1842 r_symndx = ELF32_R_SYM (rel->r_info);
1843 howto = elf32_frv_howto_table + ELF32_R_TYPE (rel->r_info);
1848 if (r_symndx < symtab_hdr->sh_info)
1850 sym = local_syms + r_symndx;
1851 osec = sec = local_sections [r_symndx];
1852 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1854 name = bfd_elf_string_from_elf_section
1855 (input_bfd, symtab_hdr->sh_link, sym->st_name);
1856 name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
1860 h = sym_hashes [r_symndx - symtab_hdr->sh_info];
1862 while (h->root.type == bfd_link_hash_indirect
1863 || h->root.type == bfd_link_hash_warning)
1864 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1866 name = h->root.root.string;
1868 if ((h->root.type == bfd_link_hash_defined
1869 || h->root.type == bfd_link_hash_defweak)
1870 && ! FRV_SYM_LOCAL (info, h))
1876 if (h->root.type == bfd_link_hash_defined
1877 || h->root.type == bfd_link_hash_defweak)
1879 sec = h->root.u.def.section;
1880 relocation = (h->root.u.def.value
1881 + sec->output_section->vma
1882 + sec->output_offset);
1884 else if (h->root.type == bfd_link_hash_undefweak)
1888 else if ( ! info->executable
1890 && info->unresolved_syms_in_objects == RM_IGNORE
1891 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
1895 if (! ((*info->callbacks->undefined_symbol)
1896 (info, h->root.root.string, input_bfd,
1897 input_section, rel->r_offset, TRUE)))
1911 case R_FRV_FUNCDESC_GOT12:
1912 case R_FRV_FUNCDESC_GOTHI:
1913 case R_FRV_FUNCDESC_GOTLO:
1914 case R_FRV_GOTOFF12:
1915 case R_FRV_GOTOFFHI:
1916 case R_FRV_GOTOFFLO:
1917 case R_FRV_FUNCDESC_GOTOFF12:
1918 case R_FRV_FUNCDESC_GOTOFFHI:
1919 case R_FRV_FUNCDESC_GOTOFFLO:
1920 case R_FRV_FUNCDESC:
1921 case R_FRV_FUNCDESC_VALUE:
1923 picrel = frv_pic_relocs_info_for_global (frv_relocs_info (info),
1927 /* In order to find the entry we created before, we must
1928 use the original addend, not the one that may have been
1929 modified by _bfd_elf_rela_local_sym(). */
1930 picrel = frv_pic_relocs_info_for_local (frv_relocs_info (info),
1931 input_bfd, r_symndx,
1936 if (!_frv_emit_got_relocs_plt_entries (picrel, output_bfd, info,
1937 osec, sym, rel->r_addend))
1939 info->callbacks->warning
1940 (info, _("Dynamic relocation references symbol with nonzero addend"),
1941 name, input_bfd, input_section, rel->r_offset);
1950 if (h && ! FRV_SYM_LOCAL (info, h))
1952 info->callbacks->warning
1953 (info, _("relocation references symbol not defined in the module"),
1954 name, input_bfd, input_section, rel->r_offset);
1963 check_segment[0] = isec_segment;
1966 relocation = frv_plt_section (info)->output_section->vma
1967 + frv_plt_section (info)->output_offset
1968 + picrel->plt_entry;
1969 check_segment[1] = plt_segment;
1971 /* We don't want to warn on calls to undefined weak symbols,
1972 as calls to them must be protected by non-NULL tests
1973 anyway, and unprotected calls would invoke undefined
1975 else if (picrel->symndx == -1
1976 && picrel->d.h->root.type == bfd_link_hash_undefweak)
1977 check_segment[1] = check_segment[0];
1979 check_segment[1] = sec
1980 ? _frv_osec_to_segment (output_bfd, sec->output_section)
1987 relocation = picrel->got_entry;
1988 check_segment[0] = check_segment[1] = got_segment;
1991 case R_FRV_FUNCDESC_GOT12:
1992 case R_FRV_FUNCDESC_GOTHI:
1993 case R_FRV_FUNCDESC_GOTLO:
1994 relocation = picrel->fdgot_entry;
1995 check_segment[0] = check_segment[1] = got_segment;
1998 case R_FRV_GOTOFFHI:
1999 case R_FRV_GOTOFF12:
2000 case R_FRV_GOTOFFLO:
2001 relocation -= frv_got_section (info)->output_section->vma
2002 + frv_got_section (info)->output_offset
2003 + frv_got_initial_offset (info);
2004 check_segment[0] = got_segment;
2005 check_segment[1] = sec
2006 ? _frv_osec_to_segment (output_bfd, sec->output_section)
2010 case R_FRV_FUNCDESC_GOTOFF12:
2011 case R_FRV_FUNCDESC_GOTOFFHI:
2012 case R_FRV_FUNCDESC_GOTOFFLO:
2013 relocation = picrel->fd_entry;
2014 check_segment[0] = check_segment[1] = got_segment;
2017 case R_FRV_FUNCDESC:
2020 bfd_vma addend = rel->r_addend;
2022 if (! (h && h->root.type == bfd_link_hash_undefweak
2023 && FRV_SYM_LOCAL (info, h)))
2025 /* If the symbol is dynamic and there may be dynamic
2026 symbol resolution because we are or are linked with a
2027 shared library, emit a FUNCDESC relocation such that
2028 the dynamic linker will allocate the function
2029 descriptor. If the symbol needs a non-local function
2030 descriptor but binds locally (e.g., its visibility is
2031 protected, emit a dynamic relocation decayed to
2033 if (h && ! FRV_FUNCDESC_LOCAL (info, h)
2034 && FRV_SYM_LOCAL (info, h)
2035 && !(info->executable && !info->pie))
2037 dynindx = elf_section_data (h->root.u.def.section
2038 ->output_section)->dynindx;
2039 addend += h->root.u.def.section->output_offset
2040 + h->root.u.def.value;
2042 else if (h && ! FRV_FUNCDESC_LOCAL (info, h))
2046 info->callbacks->warning
2047 (info, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"),
2048 name, input_bfd, input_section, rel->r_offset);
2051 dynindx = h->dynindx;
2055 /* Otherwise, we know we have a private function
2056 descriptor, so reference it directly. */
2057 BFD_ASSERT (picrel->privfd);
2059 dynindx = elf_section_data (frv_got_section (info)
2060 ->output_section)->dynindx;
2061 addend = frv_got_section (info)->output_offset
2062 + frv_got_initial_offset (info)
2066 /* If there is room for dynamic symbol resolution, emit
2067 the dynamic relocation. However, if we're linking an
2068 executable at a fixed location, we won't have emitted a
2069 dynamic symbol entry for the got section, so idx will
2070 be zero, which means we can and should compute the
2071 address of the private descriptor ourselves. */
2072 if (info->executable && !info->pie
2073 && (!h || FRV_FUNCDESC_LOCAL (info, h)))
2075 addend += frv_got_section (info)->output_section->vma;
2076 if ((bfd_get_section_flags (output_bfd,
2077 input_section->output_section)
2078 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2080 if (_frv_osec_readonly_p (output_bfd,
2081 input_section->output_section))
2083 info->callbacks->warning
2085 _("cannot emit fixups in read-only section"),
2086 name, input_bfd, input_section, rel->r_offset);
2089 _frv_add_rofixup (output_bfd,
2090 frv_gotfixup_section (info),
2091 _bfd_elf_section_offset
2093 input_section, rel->r_offset)
2094 + input_section->output_section->vma
2095 + input_section->output_offset);
2098 else if ((bfd_get_section_flags (output_bfd,
2099 input_section->output_section)
2100 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2102 if (_frv_osec_readonly_p (output_bfd,
2103 input_section->output_section))
2105 info->callbacks->warning
2107 _("cannot emit dynamic relocations in read-only section"),
2108 name, input_bfd, input_section, rel->r_offset);
2111 _frv_add_dyn_reloc (output_bfd, frv_gotrel_section (info),
2112 _bfd_elf_section_offset
2114 input_section, rel->r_offset)
2115 + input_section->output_section->vma
2116 + input_section->output_offset,
2117 r_type, dynindx, addend);
2121 /* We want the addend in-place because dynamic
2122 relocations are REL. Setting relocation to it should
2123 arrange for it to be installed. */
2124 relocation = addend - rel->r_addend;
2126 check_segment[0] = check_segment[1] = got_segment;
2130 case R_FRV_FUNCDESC_VALUE:
2133 bfd_vma addend = rel->r_addend;
2135 /* If the symbol is dynamic but binds locally, use
2137 if (h && ! FRV_SYM_LOCAL (info, h))
2139 if (addend && r_type == R_FRV_FUNCDESC_VALUE)
2141 info->callbacks->warning
2142 (info, _("R_FRV_FUNCDESC_VALUE references dynamic symbol with nonzero addend"),
2143 name, input_bfd, input_section, rel->r_offset);
2146 dynindx = h->dynindx;
2151 addend += h->root.u.def.value;
2153 addend += sym->st_value;
2155 addend += osec->output_offset;
2156 if (osec && osec->output_section
2157 && ! bfd_is_abs_section (osec->output_section)
2158 && ! bfd_is_und_section (osec->output_section))
2159 dynindx = elf_section_data (osec->output_section)->dynindx;
2164 /* If we're linking an executable at a fixed address, we
2165 can omit the dynamic relocation as long as the symbol
2166 is defined in the current link unit (which is implied
2167 by its output section not being NULL). */
2168 if (info->executable && !info->pie
2169 && (!h || FRV_SYM_LOCAL (info, h)))
2172 addend += osec->output_section->vma;
2173 if ((elf_elfheader (input_bfd)->e_flags & EF_FRV_FDPIC)
2174 && (bfd_get_section_flags (output_bfd,
2175 input_section->output_section)
2176 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2178 if (_frv_osec_readonly_p (output_bfd,
2179 input_section->output_section))
2181 info->callbacks->warning
2183 _("cannot emit fixups in read-only section"),
2184 name, input_bfd, input_section, rel->r_offset);
2187 if (!h || h->root.type != bfd_link_hash_undefweak)
2189 _frv_add_rofixup (output_bfd,
2190 frv_gotfixup_section (info),
2191 _bfd_elf_section_offset
2193 input_section, rel->r_offset)
2194 + input_section->output_section->vma
2195 + input_section->output_offset);
2196 if (r_type == R_FRV_FUNCDESC_VALUE)
2199 frv_gotfixup_section (info),
2200 _bfd_elf_section_offset
2202 input_section, rel->r_offset)
2203 + input_section->output_section->vma
2204 + input_section->output_offset + 4);
2210 if ((bfd_get_section_flags (output_bfd,
2211 input_section->output_section)
2212 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2214 if (_frv_osec_readonly_p (output_bfd,
2215 input_section->output_section))
2217 info->callbacks->warning
2219 _("cannot emit dynamic relocations in read-only section"),
2220 name, input_bfd, input_section, rel->r_offset);
2223 _frv_add_dyn_reloc (output_bfd, frv_gotrel_section (info),
2224 _bfd_elf_section_offset
2226 input_section, rel->r_offset)
2227 + input_section->output_section->vma
2228 + input_section->output_offset,
2229 r_type, dynindx, addend);
2231 /* We want the addend in-place because dynamic
2232 relocations are REL. Setting relocation to it
2233 should arrange for it to be installed. */
2234 relocation = addend - rel->r_addend;
2237 if (r_type == R_FRV_FUNCDESC_VALUE)
2239 /* If we've omitted the dynamic relocation, just emit
2240 the fixed addresses of the symbol and of the local
2242 if (info->executable && !info->pie
2243 && (!h || FRV_SYM_LOCAL (info, h)))
2244 bfd_put_32 (output_bfd,
2245 frv_got_section (info)->output_section->vma
2246 + frv_got_section (info)->output_offset
2247 + frv_got_initial_offset (info),
2248 contents + rel->r_offset + 4);
2250 /* A function descriptor used for lazy or local
2251 resolving is initialized such that its high word
2252 contains the output section index in which the
2253 PLT entries are located, and the low word
2254 contains the offset of the lazy PLT entry entry
2255 point into that section. */
2256 bfd_put_32 (output_bfd,
2257 h && ! FRV_SYM_LOCAL (info, h)
2259 : _frv_osec_to_segment (output_bfd,
2260 sec->output_section),
2261 contents + rel->r_offset + 4);
2264 check_segment[0] = check_segment[1] = got_segment;
2268 case R_FRV_GPRELU12:
2272 check_segment[0] = gprel_segment;
2273 check_segment[1] = sec
2274 ? _frv_osec_to_segment (output_bfd, sec->output_section)
2279 check_segment[0] = isec_segment;
2280 check_segment[1] = sec
2281 ? _frv_osec_to_segment (output_bfd, sec->output_section)
2286 if (check_segment[0] != check_segment[1]
2287 && (elf_elfheader (output_bfd)->e_flags & EF_FRV_FDPIC))
2290 /* This helps catch problems in GCC while we can't do more
2291 than static linking. The idea is to test whether the
2292 input file basename is crt0.o only once. */
2293 if (silence_segment_error == 1)
2294 silence_segment_error =
2295 (strlen (input_bfd->filename) == 6
2296 && strcmp (input_bfd->filename, "crt0.o") == 0)
2297 || (strlen (input_bfd->filename) > 6
2298 && strcmp (input_bfd->filename
2299 + strlen (input_bfd->filename) - 7,
2303 if (!silence_segment_error
2304 /* We don't want duplicate errors for undefined
2306 && !(picrel && picrel->symndx == -1
2307 && picrel->d.h->root.type == bfd_link_hash_undefined))
2308 info->callbacks->warning
2310 (info->shared || info->pie)
2311 ? _("relocations between different segments are not supported")
2312 : _("warning: relocation references a different segment"),
2313 name, input_bfd, input_section, rel->r_offset);
2314 if (!silence_segment_error && (info->shared || info->pie))
2316 elf_elfheader (output_bfd)->e_flags |= EF_FRV_PIC;
2321 case R_FRV_GOTOFFHI:
2322 /* We need the addend to be applied before we shift the
2324 relocation += rel->r_addend;
2327 case R_FRV_FUNCDESC_GOTHI:
2328 case R_FRV_FUNCDESC_GOTOFFHI:
2333 case R_FRV_FUNCDESC_GOTLO:
2334 case R_FRV_GOTOFFLO:
2335 case R_FRV_FUNCDESC_GOTOFFLO:
2336 relocation &= 0xffff;
2350 /* When referencing a GOT entry, a function descriptor or a
2351 PLT, we don't want the addend to apply to the reference,
2352 but rather to the referenced symbol. The actual entry
2353 will have already been created taking the addend into
2354 account, so cancel it out here. */
2358 case R_FRV_FUNCDESC_GOT12:
2359 case R_FRV_FUNCDESC_GOTHI:
2360 case R_FRV_FUNCDESC_GOTLO:
2361 case R_FRV_FUNCDESC_GOTOFF12:
2362 case R_FRV_FUNCDESC_GOTOFFHI:
2363 case R_FRV_FUNCDESC_GOTOFFLO:
2364 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
2365 here, since we do want to apply the addend to the others.
2366 Note that we've applied the addend to GOTOFFHI before we
2367 shifted it right. */
2368 case R_FRV_GOTOFFHI:
2369 relocation -= rel->r_addend;
2376 if (r_type == R_FRV_HI16)
2377 r = elf32_frv_relocate_hi16 (input_bfd, rel, contents, relocation);
2379 else if (r_type == R_FRV_LO16)
2380 r = elf32_frv_relocate_lo16 (input_bfd, rel, contents, relocation);
2382 else if (r_type == R_FRV_LABEL24)
2383 r = elf32_frv_relocate_label24 (input_bfd, input_section, rel,
2384 contents, relocation);
2386 else if (r_type == R_FRV_GPREL12)
2387 r = elf32_frv_relocate_gprel12 (info, input_bfd, input_section, rel,
2388 contents, relocation);
2390 else if (r_type == R_FRV_GPRELU12)
2391 r = elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, rel,
2392 contents, relocation);
2394 else if (r_type == R_FRV_GPRELLO)
2395 r = elf32_frv_relocate_gprello (info, input_bfd, input_section, rel,
2396 contents, relocation);
2398 else if (r_type == R_FRV_GPRELHI)
2399 r = elf32_frv_relocate_gprelhi (info, input_bfd, input_section, rel,
2400 contents, relocation);
2403 r = frv_final_link_relocate (howto, input_bfd, input_section, contents,
2406 if (r != bfd_reloc_ok)
2408 const char * msg = (const char *) NULL;
2412 case bfd_reloc_overflow:
2413 r = info->callbacks->reloc_overflow
2414 (info, name, howto->name, (bfd_vma) 0,
2415 input_bfd, input_section, rel->r_offset);
2418 case bfd_reloc_undefined:
2419 r = info->callbacks->undefined_symbol
2420 (info, name, input_bfd, input_section, rel->r_offset, TRUE);
2423 case bfd_reloc_outofrange:
2424 msg = _("internal error: out of range error");
2427 case bfd_reloc_notsupported:
2428 msg = _("internal error: unsupported relocation error");
2431 case bfd_reloc_dangerous:
2432 msg = _("internal error: dangerous relocation");
2436 msg = _("internal error: unknown error");
2441 r = info->callbacks->warning
2442 (info, msg, name, input_bfd, input_section, rel->r_offset);
2452 /* Return the section that should be marked against GC for a given
2456 elf32_frv_gc_mark_hook (sec, info, rel, h, sym)
2458 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2459 Elf_Internal_Rela *rel;
2460 struct elf_link_hash_entry *h;
2461 Elf_Internal_Sym *sym;
2465 switch (ELF32_R_TYPE (rel->r_info))
2467 case R_FRV_GNU_VTINHERIT:
2468 case R_FRV_GNU_VTENTRY:
2472 switch (h->root.type)
2477 case bfd_link_hash_defined:
2478 case bfd_link_hash_defweak:
2479 return h->root.u.def.section;
2481 case bfd_link_hash_common:
2482 return h->root.u.c.p->section;
2487 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
2492 /* Update the got entry reference counts for the section being removed. */
2495 elf32_frv_gc_sweep_hook (abfd, info, sec, relocs)
2496 bfd *abfd ATTRIBUTE_UNUSED;
2497 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2498 asection *sec ATTRIBUTE_UNUSED;
2499 const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
2505 /* Hook called by the linker routine which adds symbols from an object
2506 file. We use it to put .comm items in .scomm, and not .comm. */
2509 elf32_frv_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
2511 struct bfd_link_info *info;
2512 const Elf_Internal_Sym *sym;
2513 const char **namep ATTRIBUTE_UNUSED;
2514 flagword *flagsp ATTRIBUTE_UNUSED;
2518 if (sym->st_shndx == SHN_COMMON
2519 && !info->relocatable
2520 && (int)sym->st_size <= (int)bfd_get_gp_size (abfd))
2522 /* Common symbols less than or equal to -G nn bytes are
2523 automatically put into .sbss. */
2525 asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
2529 scomm = bfd_make_section (abfd, ".scommon");
2531 || !bfd_set_section_flags (abfd, scomm, (SEC_ALLOC
2533 | SEC_LINKER_CREATED)))
2538 *valp = sym->st_size;
2543 /* Create a .got section, as well as its additional info field. This
2544 is almost entirely copied from
2545 elflink.c:_bfd_elf_create_got_section(). */
2548 _frv_create_got_section (bfd *abfd, struct bfd_link_info *info)
2552 struct elf_link_hash_entry *h;
2553 struct bfd_link_hash_entry *bh;
2554 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2557 /* This function may be called more than once. */
2558 s = bfd_get_section_by_name (abfd, ".got");
2559 if (s != NULL && (s->flags & SEC_LINKER_CREATED) != 0)
2562 /* Machine specific: although pointers are 32-bits wide, we want the
2563 GOT to be aligned to a 64-bit boundary, such that function
2564 descriptors in it can be accessed with 64-bit loads and
2568 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2569 | SEC_LINKER_CREATED);
2571 s = bfd_make_section (abfd, ".got");
2573 || !bfd_set_section_flags (abfd, s, flags)
2574 || !bfd_set_section_alignment (abfd, s, ptralign))
2577 if (bed->want_got_plt)
2579 s = bfd_make_section (abfd, ".got.plt");
2581 || !bfd_set_section_flags (abfd, s, flags)
2582 || !bfd_set_section_alignment (abfd, s, ptralign))
2586 if (bed->want_got_sym)
2588 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
2589 (or .got.plt) section. We don't do this in the linker script
2590 because we don't want to define the symbol if we are not creating
2591 a global offset table. */
2593 if (!(_bfd_generic_link_add_one_symbol
2594 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
2595 bed->got_symbol_offset, (const char *) NULL, FALSE,
2596 bed->collect, &bh)))
2598 h = (struct elf_link_hash_entry *) bh;
2599 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2600 h->type = STT_OBJECT;
2602 /* Machine-specific: we want the symbol for executables as
2604 if (! _bfd_elf_link_record_dynamic_symbol (info, h))
2607 elf_hash_table (info)->hgot = h;
2610 /* The first bit of the global offset table is the header. */
2611 s->_raw_size += bed->got_header_size + bed->got_symbol_offset;
2613 /* This is the machine-specific part. Create and initialize section
2614 data for the got. */
2615 frv_got_section (info) = s;
2616 frv_relocs_info (info) = htab_try_create (1, frv_pic_relocs_info_hash,
2617 frv_pic_relocs_info_eq,
2619 if (! frv_relocs_info (info))
2622 s = bfd_make_section (abfd, ".rel.got");
2624 || ! bfd_set_section_flags (abfd, s, (flags | SEC_READONLY))
2625 || ! bfd_set_section_alignment (abfd, s, 2))
2628 frv_gotrel_section (info) = s;
2630 /* Machine-specific. */
2631 s = bfd_make_section (abfd, ".rofixup");
2633 || ! bfd_set_section_flags (abfd, s, (flags | SEC_READONLY))
2634 || ! bfd_set_section_alignment (abfd, s, 2))
2637 frv_gotfixup_section (info) = s;
2639 /* Define _gp in .rofixup, for FDPIC. If it turns out that
2640 we're linking with a different linker script, the linker script
2641 will override it. */
2643 if (!(_bfd_generic_link_add_one_symbol
2644 (info, abfd, "_gp", BSF_GLOBAL, s, -2048, (const char *) NULL, FALSE,
2645 bed->collect, &bh)))
2647 h = (struct elf_link_hash_entry *) bh;
2648 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2649 h->type = STT_OBJECT;
2651 /* Machine-specific: we want the symbol for executables as well. */
2652 if (! _bfd_elf_link_record_dynamic_symbol (info, h))
2658 /* Make sure the got and plt sections exist, and that our pointers in
2659 the link hash table point to them. */
2662 elf32_frv_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
2664 /* This is mostly copied from
2665 elflink.c:_bfd_elf_create_dynamic_sections(). */
2666 flagword flags, pltflags;
2668 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2670 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
2671 .rel[a].bss sections. */
2673 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2674 | SEC_LINKER_CREATED);
2677 pltflags |= SEC_CODE;
2678 if (bed->plt_not_loaded)
2679 pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS);
2680 if (bed->plt_readonly)
2681 pltflags |= SEC_READONLY;
2683 s = bfd_make_section (abfd, ".plt");
2685 || ! bfd_set_section_flags (abfd, s, pltflags)
2686 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
2688 /* FRV-specific: remember it. */
2689 frv_plt_section (info) = s;
2691 if (bed->want_plt_sym)
2693 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
2695 struct elf_link_hash_entry *h;
2696 struct bfd_link_hash_entry *bh = NULL;
2698 if (! (_bfd_generic_link_add_one_symbol
2699 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s, 0, NULL,
2700 FALSE, get_elf_backend_data (abfd)->collect, &bh)))
2702 h = (struct elf_link_hash_entry *) bh;
2703 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2704 h->type = STT_OBJECT;
2706 if (! info->executable
2707 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
2711 /* FRV-specific: we want rel relocations for the plt. */
2712 s = bfd_make_section (abfd, ".rel.plt");
2714 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
2715 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
2717 /* FRV-specific: remember it. */
2718 frv_pltrel_section (info) = s;
2720 /* FRV-specific: we want to create the GOT in the FRV way. */
2721 if (! _frv_create_got_section (abfd, info))
2724 /* FRV-specific: make sure we created everything we wanted. */
2725 BFD_ASSERT (frv_got_section (info) && frv_gotrel_section (info)
2726 && frv_gotfixup_section (info)
2727 && frv_plt_section (info) && frv_pltrel_section (info));
2729 if (bed->want_dynbss)
2731 /* The .dynbss section is a place to put symbols which are defined
2732 by dynamic objects, are referenced by regular objects, and are
2733 not functions. We must allocate space for them in the process
2734 image and use a R_*_COPY reloc to tell the dynamic linker to
2735 initialize them at run time. The linker script puts the .dynbss
2736 section into the .bss section of the final image. */
2737 s = bfd_make_section (abfd, ".dynbss");
2739 || ! bfd_set_section_flags (abfd, s, SEC_ALLOC | SEC_LINKER_CREATED))
2742 /* The .rel[a].bss section holds copy relocs. This section is not
2743 normally needed. We need to create it here, though, so that the
2744 linker will map it to an output section. We can't just create it
2745 only if we need it, because we will not know whether we need it
2746 until we have seen all the input files, and the first time the
2747 main linker code calls BFD after examining all the input files
2748 (size_dynamic_sections) the input sections have already been
2749 mapped to the output sections. If the section turns out not to
2750 be needed, we can discard it later. We will never need this
2751 section when generating a shared object, since they do not use
2755 s = bfd_make_section (abfd,
2756 (bed->default_use_rela_p
2757 ? ".rela.bss" : ".rel.bss"));
2759 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
2760 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
2768 /* The name of the dynamic interpreter. This is put in the .interp
2771 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
2773 #define DEFAULT_STACK_SIZE 0x20000
2775 /* This structure is used to collect the number of entries present in
2776 each addressable range of the got. */
2777 struct _frv_dynamic_got_info
2779 /* Several bits of information about the current link. */
2780 struct bfd_link_info *info;
2781 /* Total size needed for GOT entries within the 12-, 16- or 32-bit
2783 bfd_vma got12, gotlos, gothilo;
2784 /* Total size needed for function descriptor entries within the 12-,
2785 16- or 32-bit ranges. */
2786 bfd_vma fd12, fdlos, fdhilo;
2787 /* Total size needed function descriptor entries referenced in PLT
2788 entries, that would be profitable to place in offsets close to
2789 the PIC register. */
2791 /* Total size needed by lazy PLT entries. */
2793 /* Number of relocations carried over from input object files. */
2794 unsigned long relocs;
2795 /* Number of fixups introduced by relocations in input object files. */
2796 unsigned long fixups;
2799 /* Compute the total GOT size required by each symbol in each range.
2800 Symbols may require up to 4 words in the GOT: an entry pointing to
2801 the symbol, an entry pointing to its function descriptor, and a
2802 private function descriptors taking two words. */
2805 _frv_count_got_plt_entries (void **entryp, void *dinfo_)
2807 struct frv_pic_relocs_info *entry = *entryp;
2808 struct _frv_dynamic_got_info *dinfo = dinfo_;
2810 /* Allocate space for a GOT entry pointing to the symbol. */
2813 else if (entry->gotlos)
2815 else if (entry->gothilo)
2816 dinfo->gothilo += 4;
2821 /* Allocate space for a GOT entry pointing to the function
2825 else if (entry->fdgotlos)
2827 else if (entry->fdgothilo)
2828 dinfo->gothilo += 4;
2833 /* Decide whether we need a PLT entry, a function descriptor in the
2834 GOT, and a lazy PLT entry for this symbol. */
2835 entry->plt = entry->call
2836 && entry->symndx == -1 && ! FRV_SYM_LOCAL (dinfo->info, entry->d.h)
2837 && elf_hash_table (dinfo->info)->dynamic_sections_created;
2838 entry->privfd = entry->plt
2839 || entry->fdgoff12 || entry->fdgofflos || entry->fdgoffhilo
2840 || ((entry->fd || entry->fdgot12 || entry->fdgotlos || entry->fdgothilo)
2841 && (entry->symndx != -1
2842 || FRV_FUNCDESC_LOCAL (dinfo->info, entry->d.h)));
2843 entry->lazyplt = entry->privfd
2844 && entry->symndx == -1 && ! FRV_SYM_LOCAL (dinfo->info, entry->d.h)
2845 && ! (dinfo->info->flags & DF_BIND_NOW)
2846 && elf_hash_table (dinfo->info)->dynamic_sections_created;
2848 /* Allocate space for a function descriptor. */
2849 if (entry->fdgoff12)
2851 else if (entry->fdgofflos)
2853 else if (entry->privfd && entry->plt)
2855 else if (entry->privfd)
2864 if (!dinfo->info->executable || dinfo->info->pie)
2865 dinfo->relocs += entry->relocs32 + entry->relocsfd + entry->relocsfdv;
2868 if (entry->symndx != -1 || FRV_SYM_LOCAL (dinfo->info, entry->d.h))
2870 if (entry->symndx != -1
2871 || entry->d.h->root.type != bfd_link_hash_undefweak)
2872 dinfo->fixups += entry->relocs32 + 2 * entry->relocsfdv;
2875 dinfo->relocs += entry->relocs32 + entry->relocsfdv;
2876 if (entry->symndx != -1 || FRV_FUNCDESC_LOCAL (dinfo->info, entry->d.h))
2878 if (entry->symndx != -1
2879 || entry->d.h->root.type != bfd_link_hash_undefweak)
2880 dinfo->fixups += entry->relocsfd;
2883 dinfo->relocs += entry->relocsfd;
2889 /* This structure is used to assign offsets to got entries, function
2890 descriptors, plt entries and lazy plt entries. */
2892 struct _frv_dynamic_got_plt_info
2894 /* Summary information collected with _frv_count_got_plt_entries. */
2895 struct _frv_dynamic_got_info g;
2897 /* For each addressable range, we record a MAX (positive) and MIN
2898 (negative) value. CUR is used to assign got entries, and it's
2899 incremented from an initial positive value to MAX, then from MIN
2900 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
2901 assign function descriptors, and it's decreased from an initial
2902 non-positive value to MIN, then from MAX down to CUR (unless CUR
2903 wraps around first). All of MIN, MAX, CUR and FDCUR always point
2904 to even words. ODD, if non-zero, indicates an odd word to be
2905 used for the next got entry, otherwise CUR is used and
2906 incremented by a pair of words, wrapping around when it reaches
2907 MAX. FDCUR is decremented (and wrapped) before the next function
2908 descriptor is chosen. FDPLT indicates the number of remaining
2909 slots that can be used for function descriptors used only by PLT
2911 struct _frv_dynamic_got_alloc_data
2913 bfd_signed_vma max, cur, odd, fdcur, min;
2915 } got12, gotlos, gothilo;
2918 /* Determine the positive and negative ranges to be used by each
2919 offset range in the GOT. FDCUR and CUR, that must be aligned to a
2920 double-word boundary, are the minimum (negative) and maximum
2921 (positive) GOT offsets already used by previous ranges, except for
2922 an ODD entry that may have been left behind. GOT and FD indicate
2923 the size of GOT entries and function descriptors that must be
2924 placed within the range from -WRAP to WRAP. If there's room left,
2925 up to FDPLT bytes should be reserved for additional function
2928 inline static bfd_signed_vma
2929 _frv_compute_got_alloc_data (struct _frv_dynamic_got_alloc_data *gad,
2930 bfd_signed_vma fdcur,
2938 bfd_signed_vma wrapmin = -wrap;
2940 /* Start at the given initial points. */
2944 /* If we had an incoming odd word and we have any got entries that
2945 are going to use it, consume it, otherwise leave gad->odd at
2946 zero. We might force gad->odd to zero and return the incoming
2947 odd such that it is used by the next range, but then GOT entries
2948 might appear to be out of order and we wouldn't be able to
2949 shorten the GOT by one word if it turns out to end with an
2950 unpaired GOT entry. */
2960 /* If we're left with an unpaired GOT entry, compute its location
2961 such that we can return it. Otherwise, if got doesn't require an
2962 odd number of words here, either odd was already zero in the
2963 block above, or it was set to zero because got was non-zero, or
2964 got was already zero. In the latter case, we want the value of
2965 odd to carry over to the return statement, so we don't want to
2966 reset odd unless the condition below is true. */
2973 /* Compute the tentative boundaries of this range. */
2974 gad->max = cur + got;
2975 gad->min = fdcur - fd;
2978 /* If function descriptors took too much space, wrap some of them
2980 if (gad->min < wrapmin)
2982 gad->max += wrapmin - gad->min;
2985 /* If there is space left and we have function descriptors
2986 referenced in PLT entries that could take advantage of shorter
2987 offsets, place them here. */
2988 else if (fdplt && gad->min > wrapmin)
2991 if ((bfd_vma) (gad->min - wrapmin) < fdplt)
2992 fds = gad->min - wrapmin;
3001 /* If GOT entries took too much space, wrap some of them around.
3002 This may well cause gad->min to become lower than wrapmin. This
3003 will cause a relocation overflow later on, so we don't have to
3005 if ((bfd_vma) gad->max > wrap)
3007 gad->min -= gad->max - wrap;
3010 /* If there is more space left, try to place some more function
3011 descriptors for PLT entries. */
3012 else if (fdplt && (bfd_vma) gad->max < wrap)
3015 if ((bfd_vma) (wrap - gad->max) < fdplt)
3016 fds = wrap - gad->max;
3025 /* If odd was initially computed as an offset past the wrap point,
3028 odd = gad->min + odd - gad->max;
3030 /* _frv_get_got_entry() below will always wrap gad->cur if needed
3031 before returning, so do it here too. This guarantees that,
3032 should cur and fdcur meet at the wrap point, they'll both be
3034 if (gad->cur == gad->max)
3035 gad->cur = gad->min;
3040 /* Compute the location of the next GOT entry, given the allocation
3041 data for a range. */
3043 inline static bfd_signed_vma
3044 _frv_get_got_entry (struct _frv_dynamic_got_alloc_data *gad)
3050 /* If there was an odd word left behind, use it. */
3056 /* Otherwise, use the word pointed to by cur, reserve the next
3057 as an odd word, and skip to the next pair of words, possibly
3060 gad->odd = gad->cur + 4;
3062 if (gad->cur == gad->max)
3063 gad->cur = gad->min;
3069 /* Compute the location of the next function descriptor entry in the
3070 GOT, given the allocation data for a range. */
3072 inline static bfd_signed_vma
3073 _frv_get_fd_entry (struct _frv_dynamic_got_alloc_data *gad)
3075 /* If we're at the bottom, wrap around, and only then allocate the
3076 next pair of words. */
3077 if (gad->fdcur == gad->min)
3078 gad->fdcur = gad->max;
3079 return gad->fdcur -= 8;
3082 /* Assign GOT offsets for every GOT entry and function descriptor.
3083 Doing everything in a single pass is tricky. */
3086 _frv_assign_got_entries (void **entryp, void *info_)
3088 struct frv_pic_relocs_info *entry = *entryp;
3089 struct _frv_dynamic_got_plt_info *dinfo = info_;
3092 entry->got_entry = _frv_get_got_entry (&dinfo->got12);
3093 else if (entry->gotlos)
3094 entry->got_entry = _frv_get_got_entry (&dinfo->gotlos);
3095 else if (entry->gothilo)
3096 entry->got_entry = _frv_get_got_entry (&dinfo->gothilo);
3099 entry->fdgot_entry = _frv_get_got_entry (&dinfo->got12);
3100 else if (entry->fdgotlos)
3101 entry->fdgot_entry = _frv_get_got_entry (&dinfo->gotlos);
3102 else if (entry->fdgothilo)
3103 entry->fdgot_entry = _frv_get_got_entry (&dinfo->gothilo);
3105 if (entry->fdgoff12)
3106 entry->fd_entry = _frv_get_fd_entry (&dinfo->got12);
3107 else if (entry->plt && dinfo->got12.fdplt)
3109 dinfo->got12.fdplt -= 8;
3110 entry->fd_entry = _frv_get_fd_entry (&dinfo->got12);
3112 else if (entry->fdgofflos)
3113 entry->fd_entry = _frv_get_fd_entry (&dinfo->gotlos);
3114 else if (entry->plt && dinfo->gotlos.fdplt)
3116 dinfo->gotlos.fdplt -= 8;
3117 entry->fd_entry = _frv_get_fd_entry (&dinfo->gotlos);
3119 else if (entry->plt)
3121 dinfo->gothilo.fdplt -= 8;
3122 entry->fd_entry = _frv_get_fd_entry (&dinfo->gothilo);
3124 else if (entry->privfd)
3125 entry->fd_entry = _frv_get_fd_entry (&dinfo->gothilo);
3130 /* Assign GOT offsets to private function descriptors used by PLT
3131 entries (or referenced by 32-bit offsets), as well as PLT entries
3132 and lazy PLT entries. */
3135 _frv_assign_plt_entries (void **entryp, void *info_)
3137 struct frv_pic_relocs_info *entry = *entryp;
3138 struct _frv_dynamic_got_plt_info *dinfo = info_;
3140 /* If this symbol requires a local function descriptor, allocate
3142 if (entry->privfd && entry->fd_entry == 0)
3144 if (dinfo->got12.fdplt)
3146 entry->fd_entry = _frv_get_fd_entry (&dinfo->got12);
3147 dinfo->got12.fdplt -= 8;
3149 else if (dinfo->gotlos.fdplt)
3151 entry->fd_entry = _frv_get_fd_entry (&dinfo->gotlos);
3152 dinfo->gotlos.fdplt -= 8;
3156 BFD_ASSERT (dinfo->gothilo.fdplt)
3157 entry->fd_entry = _frv_get_fd_entry (&dinfo->gothilo);
3158 dinfo->gothilo.fdplt -= 8;
3166 /* We use the section's raw size to mark the location of the
3168 entry->plt_entry = frv_plt_section (dinfo->g.info)->_raw_size;
3170 /* Figure out the length of this PLT entry based on the
3171 addressing mode we need to reach the function descriptor. */
3172 BFD_ASSERT (entry->fd_entry);
3173 if (entry->fd_entry >= -(1 << (12 - 1))
3174 && entry->fd_entry < (1 << (12 - 1)))
3176 else if (entry->fd_entry >= -(1 << (16 - 1))
3177 && entry->fd_entry < (1 << (16 - 1)))
3182 frv_plt_section (dinfo->g.info)->_raw_size += size;
3187 entry->lzplt_entry = dinfo->g.lzplt;
3188 dinfo->g.lzplt += 8;
3189 /* If this entry is the one that gets the resolver stub, account
3190 for the additional instruction. */
3191 if (entry->lzplt_entry % FRV_LZPLT_BLOCK_SIZE == FRV_LZPLT_RESOLV_LOC)
3192 dinfo->g.lzplt += 4;
3198 /* Follow indirect and warning hash entries so that each got entry
3199 points to the final symbol definition. P must point to a pointer
3200 to the hash table we're traversing. Since this traversal may
3201 modify the hash table, we set this pointer to NULL to indicate
3202 we've made a potentially-destructive change to the hash table, so
3203 the traversal must be restarted. */
3205 _frv_resolve_final_relocs_info (void **entryp, void *p)
3207 struct frv_pic_relocs_info *entry = *entryp;
3210 if (entry->symndx == -1)
3212 struct elf_link_hash_entry *h = entry->d.h;
3214 while (h->root.type == bfd_link_hash_indirect
3215 || h->root.type == bfd_link_hash_warning)
3216 h = (struct elf_link_hash_entry *)h->root.u.i.link;
3218 if (entry->d.h == h)
3223 /* If we can't find this entry with the new bfd hash, re-insert
3224 it, and get the traversal restarted. */
3225 if (! htab_find (*htab, entry))
3227 htab_clear_slot (*htab, entryp);
3228 entryp = htab_find_slot (*htab, entry, INSERT);
3231 /* Abort the traversal, since the whole table may have
3232 moved, and leave it up to the parent to restart the
3234 *(htab_t *)p = NULL;
3242 /* Set the sizes of the dynamic sections. */
3245 elf32_frv_size_dynamic_sections (bfd *output_bfd,
3246 struct bfd_link_info *info)
3250 struct _frv_dynamic_got_plt_info gpinfo;
3254 dynobj = elf_hash_table (info)->dynobj;
3255 BFD_ASSERT (dynobj != NULL);
3257 if (elf_hash_table (info)->dynamic_sections_created)
3259 /* Set the contents of the .interp section to the interpreter. */
3260 if (info->executable)
3262 s = bfd_get_section_by_name (dynobj, ".interp");
3263 BFD_ASSERT (s != NULL);
3264 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
3265 s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
3269 memset (&gpinfo, 0, sizeof (gpinfo));
3270 gpinfo.g.info = info;
3274 htab_t relocs = frv_relocs_info (info);
3276 htab_traverse (relocs, _frv_resolve_final_relocs_info, &relocs);
3278 if (relocs == frv_relocs_info (info))
3282 htab_traverse (frv_relocs_info (info), _frv_count_got_plt_entries,
3286 /* Compute the total size taken by entries in the 12-bit and 16-bit
3287 ranges, to tell how many PLT function descriptors we can bring
3288 into the 12-bit range without causing the 16-bit range to
3290 limit = odd + gpinfo.g.got12 + gpinfo.g.gotlos
3291 + gpinfo.g.fd12 + gpinfo.g.fdlos;
3292 if (limit < (bfd_vma)1 << 16)
3293 limit = ((bfd_vma)1 << 16) - limit;
3296 if (gpinfo.g.fdplt < limit)
3297 limit = gpinfo.g.fdplt;
3299 /* Determine the ranges of GOT offsets that we can use for each
3300 range of addressing modes. */
3301 odd = _frv_compute_got_alloc_data (&gpinfo.got12,
3308 (bfd_vma)1 << (12-1));
3309 odd = _frv_compute_got_alloc_data (&gpinfo.gotlos,
3315 gpinfo.g.fdplt - gpinfo.got12.fdplt,
3316 (bfd_vma)1 << (16-1));
3317 odd = _frv_compute_got_alloc_data (&gpinfo.gothilo,
3323 gpinfo.g.fdplt - gpinfo.got12.fdplt
3324 - gpinfo.gotlos.fdplt,
3325 (bfd_vma)1 << (32-1));
3327 /* Now assign (most) GOT offsets. */
3328 htab_traverse (frv_relocs_info (info), _frv_assign_got_entries, &gpinfo);
3330 frv_got_section (info)->_raw_size = gpinfo.gothilo.max - gpinfo.gothilo.min
3331 /* If an odd word is the last word of the GOT, we don't need this
3332 word to be part of the GOT. */
3333 - (odd + 4 == gpinfo.gothilo.max ? 4 : 0);
3334 if (frv_got_section (info)->_raw_size == 0)
3335 frv_got_section (info)->flags |= SEC_EXCLUDE;
3336 else if (frv_got_section (info)->_raw_size == 12
3337 && ! elf_hash_table (info)->dynamic_sections_created)
3339 frv_got_section (info)->flags |= SEC_EXCLUDE;
3340 frv_got_section (info)->_raw_size = 0;
3344 frv_got_section (info)->contents =
3345 (bfd_byte *) bfd_zalloc (dynobj, frv_got_section (info)->_raw_size);
3346 if (frv_got_section (info)->contents == NULL)
3350 if (elf_hash_table (info)->dynamic_sections_created)
3351 /* Subtract the number of lzplt entries, since those will generate
3352 relocations in the pltrel section. */
3353 frv_gotrel_section (info)->_raw_size =
3354 (gpinfo.g.relocs - gpinfo.g.lzplt / 8)
3355 * get_elf_backend_data (output_bfd)->s->sizeof_rel;
3357 BFD_ASSERT (gpinfo.g.relocs == 0);
3358 if (frv_gotrel_section (info)->_raw_size == 0)
3359 frv_gotrel_section (info)->flags |= SEC_EXCLUDE;
3362 frv_gotrel_section (info)->contents =
3363 (bfd_byte *) bfd_zalloc (dynobj, frv_gotrel_section (info)->_raw_size);
3364 if (frv_gotrel_section (info)->contents == NULL)
3368 if (elf_elfheader (output_bfd)->e_flags & EF_FRV_FDPIC)
3369 frv_gotfixup_section (info)->_raw_size = (gpinfo.g.fixups + 1) * 4;
3370 if (frv_gotfixup_section (info)->_raw_size == 0)
3371 frv_gotfixup_section (info)->flags |= SEC_EXCLUDE;
3374 frv_gotfixup_section (info)->contents =
3375 (bfd_byte *) bfd_zalloc (dynobj,
3376 frv_gotfixup_section (info)->_raw_size);
3377 if (frv_gotfixup_section (info)->contents == NULL)
3381 if (elf_hash_table (info)->dynamic_sections_created)
3383 frv_pltrel_section (info)->_raw_size =
3384 gpinfo.g.lzplt / 8 * get_elf_backend_data (output_bfd)->s->sizeof_rel;
3385 if (frv_pltrel_section (info)->_raw_size == 0)
3386 frv_pltrel_section (info)->flags |= SEC_EXCLUDE;
3389 frv_pltrel_section (info)->contents =
3390 (bfd_byte *) bfd_zalloc (dynobj,
3391 frv_pltrel_section (info)->_raw_size);
3392 if (frv_pltrel_section (info)->contents == NULL)
3397 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
3398 such that there's room for the additional instruction needed to
3399 call the resolver. Since _frv_assign_got_entries didn't account
3400 for them, our block size is 4 bytes smaller than the real block
3402 if (elf_hash_table (info)->dynamic_sections_created)
3404 frv_plt_section (info)->_raw_size = gpinfo.g.lzplt
3405 + ((gpinfo.g.lzplt + (FRV_LZPLT_BLOCK_SIZE - 4) - 8)
3406 / (FRV_LZPLT_BLOCK_SIZE - 4) * 4);
3409 /* Reset it, such that _frv_assign_plt_entries() can use it to
3410 actually assign lazy PLT entries addresses. */
3413 /* Save information that we're going to need to generate GOT and PLT
3415 frv_got_initial_offset (info) = -gpinfo.gothilo.min;
3417 if (get_elf_backend_data (output_bfd)->want_got_sym)
3418 elf_hash_table (info)->hgot->root.u.def.value
3419 += frv_got_initial_offset (info);
3421 if (elf_hash_table (info)->dynamic_sections_created)
3422 frv_plt_initial_offset (info) = frv_plt_section (info)->_raw_size;
3424 htab_traverse (frv_relocs_info (info), _frv_assign_plt_entries, &gpinfo);
3426 /* Allocate the PLT section contents only after
3427 _frv_assign_plt_entries has a chance to add the size of the
3428 non-lazy PLT entries. */
3429 if (elf_hash_table (info)->dynamic_sections_created)
3431 if (frv_plt_section (info)->_raw_size == 0)
3432 frv_plt_section (info)->flags |= SEC_EXCLUDE;
3435 frv_plt_section (info)->contents =
3436 (bfd_byte *) bfd_zalloc (dynobj, frv_plt_section (info)->_raw_size);
3437 if (frv_plt_section (info)->contents == NULL)
3442 if (elf_hash_table (info)->dynamic_sections_created)
3444 if (frv_got_section (info)->_raw_size)
3445 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0))
3448 if (frv_pltrel_section (info)->_raw_size)
3449 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
3450 || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_REL)
3451 || ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0))
3454 if (frv_gotrel_section (info)->_raw_size)
3455 if (! bfd_elf32_add_dynamic_entry (info, DT_REL, 0)
3456 || ! bfd_elf32_add_dynamic_entry (info, DT_RELSZ, 0)
3457 || ! bfd_elf32_add_dynamic_entry (info, DT_RELENT,
3458 sizeof (Elf32_External_Rel)))
3466 elf32_frv_always_size_sections (bfd *output_bfd,
3467 struct bfd_link_info *info)
3469 if (!info->relocatable
3470 && elf_elfheader (output_bfd)->e_flags & EF_FRV_FDPIC)
3472 struct elf_link_hash_entry *h;
3475 /* Force a PT_GNU_STACK segment to be created. */
3476 if (! elf_tdata (output_bfd)->stack_flags)
3477 elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
3479 /* Define __stacksize if it's not defined yet. */
3480 h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize",
3481 FALSE, FALSE, FALSE);
3482 if (! h || h->root.type != bfd_link_hash_defined
3483 || h->type != STT_OBJECT
3484 || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
3486 struct bfd_link_hash_entry *bh = NULL;
3488 if (!(_bfd_generic_link_add_one_symbol
3489 (info, output_bfd, "__stacksize",
3490 BSF_GLOBAL, bfd_abs_section_ptr, DEFAULT_STACK_SIZE,
3491 (const char *) NULL, FALSE,
3492 get_elf_backend_data (output_bfd)->collect, &bh)))
3495 h = (struct elf_link_hash_entry *) bh;
3496 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3497 h->type = STT_OBJECT;
3500 /* Create a stack section, and set its alignment. */
3501 sec = bfd_make_section (output_bfd, ".stack");
3504 || ! bfd_set_section_alignment (output_bfd, sec, 3))
3512 elf32_frv_modify_segment_map (bfd *output_bfd,
3513 struct bfd_link_info *info)
3515 if (elf_elfheader (output_bfd)->e_flags & EF_FRV_FDPIC)
3517 struct elf_segment_map *m;
3519 for (m = elf_tdata (output_bfd)->segment_map; m != NULL; m = m->next)
3520 if (m->p_type == PT_GNU_STACK)
3525 asection *sec = bfd_get_section_by_name (output_bfd, ".stack");
3526 struct elf_link_hash_entry *h;
3530 /* Obtain the pointer to the __stacksize symbol. */
3531 h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize",
3532 FALSE, FALSE, FALSE);
3533 while (h->root.type == bfd_link_hash_indirect
3534 || h->root.type == bfd_link_hash_warning)
3535 h = (struct elf_link_hash_entry *)h->root.u.i.link;
3536 BFD_ASSERT (h->root.type == bfd_link_hash_defined);
3538 /* Set the section size from the symbol value. We
3539 intentionally ignore the symbol section. */
3540 if (h->root.type == bfd_link_hash_defined)
3541 sec->_raw_size = h->root.u.def.value;
3543 sec->_raw_size = DEFAULT_STACK_SIZE;
3545 /* Add the stack section to the PT_GNU_STACK segment,
3546 such that its size and alignment requirements make it
3548 m->sections[m->count] = sec;
3557 /* Fill in code and data in dynamic sections. */
3560 elf32_frv_finish_dynamic_sections (bfd *output_bfd,
3561 struct bfd_link_info *info)
3566 dynobj = elf_hash_table (info)->dynobj;
3568 if (frv_got_section (info))
3570 BFD_ASSERT (frv_gotrel_section (info)->_raw_size
3571 == (frv_gotrel_section (info)->reloc_count
3572 * sizeof (Elf32_External_Rel)));
3574 if (frv_gotfixup_section (info))
3576 if (elf_elfheader (output_bfd)->e_flags & EF_FRV_FDPIC)
3578 struct elf_link_hash_entry *hgot = elf_hash_table (info)->hgot;
3579 bfd_vma got_value = hgot->root.u.def.value
3580 + hgot->root.u.def.section->output_section->vma
3581 + hgot->root.u.def.section->output_offset;
3583 _frv_add_rofixup (output_bfd, frv_gotfixup_section (info),
3587 if (frv_gotfixup_section (info)->_raw_size
3588 != (frv_gotfixup_section (info)->reloc_count * 4))
3590 if (!elf_hash_table (info)->dynamic_sections_created)
3592 info->callbacks->warning
3593 (info, "no dynamic sections, missing -melf32frvfd?",
3594 ".rofixup", NULL, NULL, 0);
3601 if (elf_hash_table (info)->dynamic_sections_created)
3603 BFD_ASSERT (frv_pltrel_section (info)->_raw_size
3604 == (frv_pltrel_section (info)->reloc_count
3605 * sizeof (Elf32_External_Rel)));
3608 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3610 if (elf_hash_table (info)->dynamic_sections_created)
3612 Elf32_External_Dyn * dyncon;
3613 Elf32_External_Dyn * dynconend;
3615 BFD_ASSERT (sdyn != NULL);
3617 dyncon = (Elf32_External_Dyn *) sdyn->contents;
3618 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
3620 for (; dyncon < dynconend; dyncon++)
3622 Elf_Internal_Dyn dyn;
3624 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
3632 dyn.d_un.d_ptr = frv_got_section (info)->output_section->vma
3633 + frv_got_section (info)->output_offset
3634 + frv_got_initial_offset (info);
3635 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3639 dyn.d_un.d_ptr = frv_pltrel_section (info)->output_section->vma
3640 + frv_pltrel_section (info)->output_offset;
3641 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3645 if (frv_pltrel_section (info)->_cooked_size != 0)
3646 dyn.d_un.d_val = frv_pltrel_section (info)->_cooked_size;
3648 dyn.d_un.d_val = frv_pltrel_section (info)->_raw_size;
3649 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3658 /* Adjust a symbol defined by a dynamic object and referenced by a
3662 elf32_frv_adjust_dynamic_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED,
3663 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
3667 dynobj = elf_hash_table (info)->dynobj;
3669 /* Make sure we know what is going on here. */
3670 BFD_ASSERT (dynobj != NULL
3671 && (h->weakdef != NULL
3672 || ((h->elf_link_hash_flags
3673 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3674 && (h->elf_link_hash_flags
3675 & ELF_LINK_HASH_REF_REGULAR) != 0
3676 && (h->elf_link_hash_flags
3677 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
3679 /* If this is a weak symbol, and there is a real definition, the
3680 processor independent code will have arranged for us to see the
3681 real definition first, and we can just use the same value. */
3682 if (h->weakdef != NULL)
3684 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
3685 || h->weakdef->root.type == bfd_link_hash_defweak);
3686 h->root.u.def.section = h->weakdef->root.u.def.section;
3687 h->root.u.def.value = h->weakdef->root.u.def.value;
3693 /* Perform any actions needed for dynamic symbols. */
3696 elf32_frv_finish_dynamic_symbol (bfd *output_bfd ATTRIBUTE_UNUSED,
3697 struct bfd_link_info *info ATTRIBUTE_UNUSED,
3698 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED,
3699 Elf_Internal_Sym *sym ATTRIBUTE_UNUSED)
3704 /* Decide whether to attempt to turn absptr or lsda encodings in
3705 shared libraries into pcrel within the given input section. */
3708 frv_elf_use_relative_eh_frame (bfd *input_bfd,
3709 struct bfd_link_info *info ATTRIBUTE_UNUSED,
3710 asection *eh_frame_section ATTRIBUTE_UNUSED)
3712 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
3713 if (elf_elfheader (input_bfd)->e_flags & EF_FRV_FDPIC)
3719 /* Adjust the contents of an eh_frame_hdr section before they're output. */
3722 frv_elf_encode_eh_address (bfd *abfd,
3723 struct bfd_link_info *info,
3724 asection *osec, bfd_vma offset,
3725 asection *loc_sec, bfd_vma loc_offset,
3728 struct elf_link_hash_entry *h;
3730 /* Non-FDPIC binaries can use PC-relative encodings. */
3731 if (! (elf_elfheader (abfd)->e_flags & EF_FRV_FDPIC))
3732 return _bfd_elf_encode_eh_address (abfd, info, osec, offset,
3733 loc_sec, loc_offset, encoded);
3735 h = elf_hash_table (info)->hgot;
3736 BFD_ASSERT (h && h->root.type == bfd_link_hash_defined);
3738 if (! h || (_frv_osec_to_segment (abfd, osec)
3739 == _frv_osec_to_segment (abfd, loc_sec->output_section)))
3740 return _bfd_elf_encode_eh_address (abfd, info, osec, offset,
3741 loc_sec, loc_offset, encoded);
3743 BFD_ASSERT (_frv_osec_to_segment (abfd, osec)
3744 == _frv_osec_to_segment (abfd,
3745 h->root.u.def.section->output_section));
3747 *encoded = osec->vma + offset
3748 - (h->root.u.def.value
3749 + h->root.u.def.section->output_section->vma
3750 + h->root.u.def.section->output_offset);
3752 return DW_EH_PE_datarel | DW_EH_PE_sdata4;
3755 /* Look through the relocs for a section during the first phase.
3757 Besides handling virtual table relocs for gc, we have to deal with
3758 all sorts of PIC-related relocations. We describe below the
3759 general plan on how to handle such relocations, even though we only
3760 collect information at this point, storing them in hash tables for
3761 perusal of later passes.
3763 32 relocations are propagated to the linker output when creating
3764 position-independent output. LO16 and HI16 relocations are not
3765 supposed to be encountered in this case.
3767 LABEL16 should always be resolvable by the linker, since it's only
3770 LABEL24, on the other hand, is used by calls. If it turns out that
3771 the target of a call is a dynamic symbol, a PLT entry must be
3772 created for it, which triggers the creation of a private function
3773 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
3775 GPREL relocations require the referenced symbol to be in the same
3776 segment as _gp, but this can only be checked later.
3778 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
3779 exist. LABEL24 might as well, since it may require a PLT entry,
3780 that will require a got.
3782 Non-FUNCDESC GOT relocations require a GOT entry to be created
3783 regardless of whether the symbol is dynamic. However, since a
3784 global symbol that turns out to not be exported may have the same
3785 address of a non-dynamic symbol, we don't assign GOT entries at
3786 this point, such that we can share them in this case. A relocation
3787 for the GOT entry always has to be created, be it to offset a
3788 private symbol by the section load address, be it to get the symbol
3789 resolved dynamically.
3791 FUNCDESC GOT relocations require a GOT entry to be created, and
3792 handled as if a FUNCDESC relocation was applied to the GOT entry in
3795 FUNCDESC relocations referencing a symbol that turns out to NOT be
3796 dynamic cause a private function descriptor to be created. The
3797 FUNCDESC relocation then decays to a 32 relocation that points at
3798 the private descriptor. If the symbol is dynamic, the FUNCDESC
3799 relocation is propagated to the linker output, such that the
3800 dynamic linker creates the canonical descriptor, pointing to the
3801 dynamically-resolved definition of the function.
3803 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
3804 symbols that are assigned to the same segment as the GOT, but we
3805 can only check this later, after we know the complete set of
3806 symbols defined and/or exported.
3808 FUNCDESC GOTOFF relocations require a function descriptor to be
3809 created and, unless lazy binding is disabled or the symbol is not
3810 dynamic, a lazy PLT entry. Since we can't tell at this point
3811 whether a symbol is going to be dynamic, we have to decide later
3812 whether to create a lazy PLT entry or bind the descriptor directly
3813 to the private function.
3815 FUNCDESC_VALUE relocations are not supposed to be present in object
3816 files, but they may very well be simply propagated to the linker
3817 output, since they have no side effect.
3820 A function descriptor always requires a FUNCDESC_VALUE relocation.
3821 Whether it's in .plt.rel or not depends on whether lazy binding is
3822 enabled and on whether the referenced symbol is dynamic.
3824 The existence of a lazy PLT requires the resolverStub lazy PLT
3825 entry to be present.
3828 As for assignment of GOT, PLT and lazy PLT entries, and private
3829 descriptors, we might do them all sequentially, but we can do
3830 better than that. For example, we can place GOT entries and
3831 private function descriptors referenced using 12-bit operands
3832 closer to the PIC register value, such that these relocations don't
3833 overflow. Those that are only referenced with LO16 relocations
3834 could come next, but we may as well place PLT-required function
3835 descriptors in the 12-bit range to make them shorter. Symbols
3836 referenced with LO16/HI16 may come next, but we may place
3837 additional function descriptors in the 16-bit range if we can
3838 reliably tell that we've already placed entries that are ever
3839 referenced with only LO16. PLT entries are therefore generated as
3840 small as possible, while not introducing relocation overflows in
3841 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
3842 generated before or after PLT entries, but not intermingled with
3843 them, such that we can have more lazy PLT entries in range for a
3844 branch to the resolverStub. The resolverStub should be emitted at
3845 the most distant location from the first lazy PLT entry such that
3846 it's still in range for a branch, or closer, if there isn't a need
3847 for so many lazy PLT entries. Additional lazy PLT entries may be
3848 emitted after the resolverStub, as long as branches are still in
3849 range. If the branch goes out of range, longer lazy PLT entries
3852 We could further optimize PLT and lazy PLT entries by giving them
3853 priority in assignment to closer-to-gr17 locations depending on the
3854 number of occurrences of references to them (assuming a function
3855 that's called more often is more important for performance, so its
3856 PLT entry should be faster), or taking hints from the compiler.
3857 Given infinite time and money... :-) */
3860 elf32_frv_check_relocs (abfd, info, sec, relocs)
3862 struct bfd_link_info *info;
3864 const Elf_Internal_Rela *relocs;
3866 Elf_Internal_Shdr *symtab_hdr;
3867 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
3868 const Elf_Internal_Rela *rel;
3869 const Elf_Internal_Rela *rel_end;
3871 struct frv_pic_relocs_info *picrel;
3873 if (info->relocatable)
3876 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3877 sym_hashes = elf_sym_hashes (abfd);
3878 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf32_External_Sym);
3879 if (!elf_bad_symtab (abfd))
3880 sym_hashes_end -= symtab_hdr->sh_info;
3882 dynobj = elf_hash_table (info)->dynobj;
3883 rel_end = relocs + sec->reloc_count;
3884 for (rel = relocs; rel < rel_end; rel++)
3886 struct elf_link_hash_entry *h;
3887 unsigned long r_symndx;
3889 r_symndx = ELF32_R_SYM (rel->r_info);
3890 if (r_symndx < symtab_hdr->sh_info)
3893 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3895 switch (ELF32_R_TYPE (rel->r_info))
3902 case R_FRV_FUNCDESC_GOT12:
3903 case R_FRV_FUNCDESC_GOTHI:
3904 case R_FRV_FUNCDESC_GOTLO:
3905 case R_FRV_GOTOFF12:
3906 case R_FRV_GOTOFFHI:
3907 case R_FRV_GOTOFFLO:
3908 case R_FRV_FUNCDESC_GOTOFF12:
3909 case R_FRV_FUNCDESC_GOTOFFHI:
3910 case R_FRV_FUNCDESC_GOTOFFLO:
3911 case R_FRV_FUNCDESC:
3912 case R_FRV_FUNCDESC_VALUE:
3915 elf_hash_table (info)->dynobj = dynobj = abfd;
3916 if (! _frv_create_got_section (abfd, info))
3921 if (h->dynindx == -1)
3922 switch (ELF_ST_VISIBILITY (h->other))
3928 bfd_elf32_link_record_dynamic_symbol (info, h);
3932 = frv_pic_relocs_info_for_global (frv_relocs_info (info),
3937 picrel = frv_pic_relocs_info_for_local (frv_relocs_info (info),
3949 switch (ELF32_R_TYPE (rel->r_info))
3955 case R_FRV_FUNCDESC_VALUE:
3956 picrel->relocsfdv++;
3957 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
3962 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
3972 picrel->gothilo = 1;
3975 case R_FRV_FUNCDESC_GOT12:
3976 picrel->fdgot12 = 1;
3979 case R_FRV_FUNCDESC_GOTHI:
3980 case R_FRV_FUNCDESC_GOTLO:
3981 picrel->fdgothilo = 1;
3984 case R_FRV_GOTOFF12:
3985 case R_FRV_GOTOFFHI:
3986 case R_FRV_GOTOFFLO:
3990 case R_FRV_FUNCDESC_GOTOFF12:
3991 picrel->fdgoff12 = 1;
3994 case R_FRV_FUNCDESC_GOTOFFHI:
3995 case R_FRV_FUNCDESC_GOTOFFLO:
3996 picrel->fdgoffhilo = 1;
3999 case R_FRV_FUNCDESC:
4004 /* This relocation describes the C++ object vtable hierarchy.
4005 Reconstruct it for later use during GC. */
4006 case R_FRV_GNU_VTINHERIT:
4007 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
4011 /* This relocation describes which C++ vtable entries are actually
4012 used. Record for later use during GC. */
4013 case R_FRV_GNU_VTENTRY:
4014 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
4024 /* Return the machine subcode from the ELF e_flags header. */
4027 elf32_frv_machine (abfd)
4030 switch (elf_elfheader (abfd)->e_flags & EF_FRV_CPU_MASK)
4033 case EF_FRV_CPU_FR550: return bfd_mach_fr550;
4034 case EF_FRV_CPU_FR500: return bfd_mach_fr500;
4035 case EF_FRV_CPU_FR400: return bfd_mach_fr400;
4036 case EF_FRV_CPU_FR300: return bfd_mach_fr300;
4037 case EF_FRV_CPU_SIMPLE: return bfd_mach_frvsimple;
4038 case EF_FRV_CPU_TOMCAT: return bfd_mach_frvtomcat;
4041 return bfd_mach_frv;
4044 /* Set the right machine number for a FRV ELF file. */
4047 elf32_frv_object_p (abfd)
4050 bfd_default_set_arch_mach (abfd, bfd_arch_frv, elf32_frv_machine (abfd));
4054 /* Function to set the ELF flag bits. */
4057 frv_elf_set_private_flags (abfd, flags)
4061 elf_elfheader (abfd)->e_flags = flags;
4062 elf_flags_init (abfd) = TRUE;
4066 /* Copy backend specific data from one object module to another. */
4069 frv_elf_copy_private_bfd_data (ibfd, obfd)
4073 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
4074 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
4077 BFD_ASSERT (!elf_flags_init (obfd)
4078 || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
4080 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
4081 elf_flags_init (obfd) = TRUE;
4085 /* Merge backend specific data from an object file to the output
4086 object file when linking. */
4089 frv_elf_merge_private_bfd_data (ibfd, obfd)
4093 flagword old_flags, old_partial;
4094 flagword new_flags, new_partial;
4095 bfd_boolean error = FALSE;
4099 new_opt[0] = old_opt[0] = '\0';
4100 new_flags = elf_elfheader (ibfd)->e_flags;
4101 old_flags = elf_elfheader (obfd)->e_flags;
4103 if (new_flags & EF_FRV_FDPIC)
4104 new_flags &= ~EF_FRV_PIC;
4107 (*_bfd_error_handler) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s",
4108 old_flags, new_flags, elf_flags_init (obfd) ? "yes" : "no",
4109 bfd_get_filename (ibfd));
4112 if (!elf_flags_init (obfd)) /* First call, no flags set. */
4114 elf_flags_init (obfd) = TRUE;
4115 old_flags = new_flags;
4118 else if (new_flags == old_flags) /* Compatible flags are ok. */
4121 else /* Possibly incompatible flags. */
4123 /* Warn if different # of gprs are used. Note, 0 means nothing is
4124 said about the size of gprs. */
4125 new_partial = (new_flags & EF_FRV_GPR_MASK);
4126 old_partial = (old_flags & EF_FRV_GPR_MASK);
4127 if (new_partial == old_partial)
4130 else if (new_partial == 0)
4133 else if (old_partial == 0)
4134 old_flags |= new_partial;
4138 switch (new_partial)
4140 default: strcat (new_opt, " -mgpr-??"); break;
4141 case EF_FRV_GPR_32: strcat (new_opt, " -mgpr-32"); break;
4142 case EF_FRV_GPR_64: strcat (new_opt, " -mgpr-64"); break;
4145 switch (old_partial)
4147 default: strcat (old_opt, " -mgpr-??"); break;
4148 case EF_FRV_GPR_32: strcat (old_opt, " -mgpr-32"); break;
4149 case EF_FRV_GPR_64: strcat (old_opt, " -mgpr-64"); break;
4153 /* Warn if different # of fprs are used. Note, 0 means nothing is
4154 said about the size of fprs. */
4155 new_partial = (new_flags & EF_FRV_FPR_MASK);
4156 old_partial = (old_flags & EF_FRV_FPR_MASK);
4157 if (new_partial == old_partial)
4160 else if (new_partial == 0)
4163 else if (old_partial == 0)
4164 old_flags |= new_partial;
4168 switch (new_partial)
4170 default: strcat (new_opt, " -mfpr-?"); break;
4171 case EF_FRV_FPR_32: strcat (new_opt, " -mfpr-32"); break;
4172 case EF_FRV_FPR_64: strcat (new_opt, " -mfpr-64"); break;
4173 case EF_FRV_FPR_NONE: strcat (new_opt, " -msoft-float"); break;
4176 switch (old_partial)
4178 default: strcat (old_opt, " -mfpr-?"); break;
4179 case EF_FRV_FPR_32: strcat (old_opt, " -mfpr-32"); break;
4180 case EF_FRV_FPR_64: strcat (old_opt, " -mfpr-64"); break;
4181 case EF_FRV_FPR_NONE: strcat (old_opt, " -msoft-float"); break;
4185 /* Warn if different dword support was used. Note, 0 means nothing is
4186 said about the dword support. */
4187 new_partial = (new_flags & EF_FRV_DWORD_MASK);
4188 old_partial = (old_flags & EF_FRV_DWORD_MASK);
4189 if (new_partial == old_partial)
4192 else if (new_partial == 0)
4195 else if (old_partial == 0)
4196 old_flags |= new_partial;
4200 switch (new_partial)
4202 default: strcat (new_opt, " -mdword-?"); break;
4203 case EF_FRV_DWORD_YES: strcat (new_opt, " -mdword"); break;
4204 case EF_FRV_DWORD_NO: strcat (new_opt, " -mno-dword"); break;
4207 switch (old_partial)
4209 default: strcat (old_opt, " -mdword-?"); break;
4210 case EF_FRV_DWORD_YES: strcat (old_opt, " -mdword"); break;
4211 case EF_FRV_DWORD_NO: strcat (old_opt, " -mno-dword"); break;
4215 /* Or in flags that accumulate (ie, if one module uses it, mark that the
4217 old_flags |= new_flags & (EF_FRV_DOUBLE
4220 | EF_FRV_NON_PIC_RELOCS);
4222 /* If any module was compiled without -G0, clear the G0 bit. */
4223 old_flags = ((old_flags & ~ EF_FRV_G0)
4224 | (old_flags & new_flags & EF_FRV_G0));
4226 /* If any module was compiled without -mnopack, clear the mnopack bit. */
4227 old_flags = ((old_flags & ~ EF_FRV_NOPACK)
4228 | (old_flags & new_flags & EF_FRV_NOPACK));
4230 /* We don't have to do anything if the pic flags are the same, or the new
4231 module(s) were compiled with -mlibrary-pic. */
4232 new_partial = (new_flags & EF_FRV_PIC_FLAGS);
4233 old_partial = (old_flags & EF_FRV_PIC_FLAGS);
4234 if ((new_partial == old_partial) || ((new_partial & EF_FRV_LIBPIC) != 0))
4237 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
4238 flags if any from the new module. */
4239 else if ((old_partial & EF_FRV_LIBPIC) != 0)
4240 old_flags = (old_flags & ~ EF_FRV_PIC_FLAGS) | new_partial;
4242 /* If we have mixtures of -fpic and -fPIC, or in both bits. */
4243 else if (new_partial != 0 && old_partial != 0)
4244 old_flags |= new_partial;
4246 /* One module was compiled for pic and the other was not, see if we have
4247 had any relocations that are not pic-safe. */
4250 if ((old_flags & EF_FRV_NON_PIC_RELOCS) == 0)
4251 old_flags |= new_partial;
4254 old_flags &= ~ EF_FRV_PIC_FLAGS;
4255 #ifndef FRV_NO_PIC_ERROR
4257 (*_bfd_error_handler)
4258 (_("%s: compiled with %s and linked with modules that use non-pic relocations"),
4259 bfd_get_filename (ibfd),
4260 (new_flags & EF_FRV_BIGPIC) ? "-fPIC" : "-fpic");
4265 /* Warn if different cpu is used (allow a specific cpu to override
4266 the generic cpu). */
4267 new_partial = (new_flags & EF_FRV_CPU_MASK);
4268 old_partial = (old_flags & EF_FRV_CPU_MASK);
4269 if (new_partial == old_partial)
4272 else if (new_partial == EF_FRV_CPU_GENERIC)
4275 else if (old_partial == EF_FRV_CPU_GENERIC)
4276 old_flags = (old_flags & ~EF_FRV_CPU_MASK) | new_partial;
4280 switch (new_partial)
4282 default: strcat (new_opt, " -mcpu=?"); break;
4283 case EF_FRV_CPU_GENERIC: strcat (new_opt, " -mcpu=frv"); break;
4284 case EF_FRV_CPU_SIMPLE: strcat (new_opt, " -mcpu=simple"); break;
4285 case EF_FRV_CPU_FR550: strcat (new_opt, " -mcpu=fr550"); break;
4286 case EF_FRV_CPU_FR500: strcat (new_opt, " -mcpu=fr500"); break;
4287 case EF_FRV_CPU_FR400: strcat (new_opt, " -mcpu=fr400"); break;
4288 case EF_FRV_CPU_FR300: strcat (new_opt, " -mcpu=fr300"); break;
4289 case EF_FRV_CPU_TOMCAT: strcat (new_opt, " -mcpu=tomcat"); break;
4292 switch (old_partial)
4294 default: strcat (old_opt, " -mcpu=?"); break;
4295 case EF_FRV_CPU_GENERIC: strcat (old_opt, " -mcpu=frv"); break;
4296 case EF_FRV_CPU_SIMPLE: strcat (old_opt, " -mcpu=simple"); break;
4297 case EF_FRV_CPU_FR550: strcat (old_opt, " -mcpu=fr550"); break;
4298 case EF_FRV_CPU_FR500: strcat (old_opt, " -mcpu=fr500"); break;
4299 case EF_FRV_CPU_FR400: strcat (old_opt, " -mcpu=fr400"); break;
4300 case EF_FRV_CPU_FR300: strcat (old_opt, " -mcpu=fr300"); break;
4301 case EF_FRV_CPU_TOMCAT: strcat (old_opt, " -mcpu=tomcat"); break;
4305 /* Print out any mismatches from above. */
4309 (*_bfd_error_handler)
4310 (_("%s: compiled with %s and linked with modules compiled with %s"),
4311 bfd_get_filename (ibfd), new_opt, old_opt);
4314 /* Warn about any other mismatches */
4315 new_partial = (new_flags & ~ EF_FRV_ALL_FLAGS);
4316 old_partial = (old_flags & ~ EF_FRV_ALL_FLAGS);
4317 if (new_partial != old_partial)
4319 old_flags |= new_partial;
4321 (*_bfd_error_handler)
4322 (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"),
4323 bfd_get_filename (ibfd), (long)new_partial, (long)old_partial);
4327 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
4328 if ((old_flags & EF_FRV_CPU_MASK) == EF_FRV_CPU_SIMPLE)
4329 old_flags |= EF_FRV_NOPACK;
4331 /* Update the old flags now with changes made above. */
4332 old_partial = elf_elfheader (obfd)->e_flags & EF_FRV_CPU_MASK;
4333 elf_elfheader (obfd)->e_flags = old_flags;
4334 if (old_partial != (old_flags & EF_FRV_CPU_MASK))
4335 bfd_default_set_arch_mach (obfd, bfd_arch_frv, elf32_frv_machine (obfd));
4338 bfd_set_error (bfd_error_bad_value);
4345 frv_elf_print_private_bfd_data (abfd, ptr)
4349 FILE *file = (FILE *) ptr;
4352 BFD_ASSERT (abfd != NULL && ptr != NULL);
4354 /* Print normal ELF private data. */
4355 _bfd_elf_print_private_bfd_data (abfd, ptr);
4357 flags = elf_elfheader (abfd)->e_flags;
4358 fprintf (file, _("private flags = 0x%lx:"), (long)flags);
4360 switch (flags & EF_FRV_CPU_MASK)
4363 case EF_FRV_CPU_SIMPLE: fprintf (file, " -mcpu=simple"); break;
4364 case EF_FRV_CPU_FR550: fprintf (file, " -mcpu=fr550"); break;
4365 case EF_FRV_CPU_FR500: fprintf (file, " -mcpu=fr500"); break;
4366 case EF_FRV_CPU_FR400: fprintf (file, " -mcpu=fr400"); break;
4367 case EF_FRV_CPU_FR300: fprintf (file, " -mcpu=fr300"); break;
4368 case EF_FRV_CPU_TOMCAT: fprintf (file, " -mcpu=tomcat"); break;
4371 switch (flags & EF_FRV_GPR_MASK)
4374 case EF_FRV_GPR_32: fprintf (file, " -mgpr-32"); break;
4375 case EF_FRV_GPR_64: fprintf (file, " -mgpr-64"); break;
4378 switch (flags & EF_FRV_FPR_MASK)
4381 case EF_FRV_FPR_32: fprintf (file, " -mfpr-32"); break;
4382 case EF_FRV_FPR_64: fprintf (file, " -mfpr-64"); break;
4383 case EF_FRV_FPR_NONE: fprintf (file, " -msoft-float"); break;
4386 switch (flags & EF_FRV_DWORD_MASK)
4389 case EF_FRV_DWORD_YES: fprintf (file, " -mdword"); break;
4390 case EF_FRV_DWORD_NO: fprintf (file, " -mno-dword"); break;
4393 if (flags & EF_FRV_DOUBLE)
4394 fprintf (file, " -mdouble");
4396 if (flags & EF_FRV_MEDIA)
4397 fprintf (file, " -mmedia");
4399 if (flags & EF_FRV_MULADD)
4400 fprintf (file, " -mmuladd");
4402 if (flags & EF_FRV_PIC)
4403 fprintf (file, " -fpic");
4405 if (flags & EF_FRV_BIGPIC)
4406 fprintf (file, " -fPIC");
4408 if (flags & EF_FRV_LIBPIC)
4409 fprintf (file, " -mlibrary-pic");
4411 if (flags & EF_FRV_FDPIC)
4412 fprintf (file, " -mfdpic");
4414 if (flags & EF_FRV_NON_PIC_RELOCS)
4415 fprintf (file, " non-pic relocations");
4417 if (flags & EF_FRV_G0)
4418 fprintf (file, " -G0");
4425 #define ELF_ARCH bfd_arch_frv
4426 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
4427 #define ELF_MAXPAGESIZE 0x1000
4429 #define TARGET_BIG_SYM bfd_elf32_frv_vec
4430 #define TARGET_BIG_NAME "elf32-frv"
4432 #define elf_info_to_howto_rel frv_info_to_howto_rel
4433 #define elf_info_to_howto frv_info_to_howto_rela
4434 #define elf_backend_relocate_section elf32_frv_relocate_section
4435 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
4436 #define elf_backend_gc_sweep_hook elf32_frv_gc_sweep_hook
4437 #define elf_backend_check_relocs elf32_frv_check_relocs
4438 #define elf_backend_object_p elf32_frv_object_p
4439 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
4441 #define elf_backend_can_gc_sections 1
4442 #define elf_backend_rela_normal 1
4444 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
4445 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
4446 #define bfd_elf32_bfd_copy_private_bfd_data frv_elf_copy_private_bfd_data
4447 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
4448 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
4450 #define bfd_elf32_bfd_link_hash_table_create frv_elf_link_hash_table_create
4451 #define elf_backend_always_size_sections \
4452 elf32_frv_always_size_sections
4453 #define elf_backend_modify_segment_map \
4454 elf32_frv_modify_segment_map
4456 #define elf_backend_create_dynamic_sections \
4457 elf32_frv_create_dynamic_sections
4458 #define elf_backend_adjust_dynamic_symbol \
4459 elf32_frv_adjust_dynamic_symbol
4460 #define elf_backend_size_dynamic_sections \
4461 elf32_frv_size_dynamic_sections
4462 #define elf_backend_finish_dynamic_symbol \
4463 elf32_frv_finish_dynamic_symbol
4464 #define elf_backend_finish_dynamic_sections \
4465 elf32_frv_finish_dynamic_sections
4467 #define elf_backend_want_got_sym 1
4468 #define elf_backend_got_header_size 0
4469 #define elf_backend_want_got_plt 0
4470 #define elf_backend_plt_readonly 1
4471 #define elf_backend_want_plt_sym 0
4472 #define elf_backend_plt_header_size 0
4474 #define elf_backend_can_make_relative_eh_frame \
4475 frv_elf_use_relative_eh_frame
4476 #define elf_backend_can_make_lsda_relative_eh_frame \
4477 frv_elf_use_relative_eh_frame
4478 #define elf_backend_encode_eh_address frv_elf_encode_eh_address
4480 #define elf_backend_may_use_rel_p 1
4481 #define elf_backend_may_use_rela_p 1
4482 /* We use REL for dynamic relocations only. */
4483 #define elf_backend_default_use_rela_p 1
4485 #include "elf32-target.h"