1 /* FRV-specific support for 32-bit ELF.
2 Copyright 2002, 2003, 2004 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 *, 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 },
586 extern const bfd_target bfd_elf32_frvfdpic_vec;
587 #define IS_FDPIC(bfd) ((bfd)->xvec == &bfd_elf32_frvfdpic_vec)
589 /* An extension of the elf hash table data structure, containing some
590 additional FRV-specific data. */
591 struct frvfdpic_elf_link_hash_table
593 struct elf_link_hash_table elf;
595 /* A pointer to the .got section. */
597 /* A pointer to the .rel.got section. */
599 /* A pointer to the .rofixup section. */
601 /* A pointer to the .plt section. */
603 /* A pointer to the .rel.plt section. */
605 /* GOT base offset. */
607 /* Location of the first non-lazy PLT entry, i.e., the number of
608 bytes taken by lazy PLT entries. */
610 /* A hash table holding information about which symbols were
611 referenced with which PIC-related relocations. */
612 struct htab *relocs_info;
615 /* Get the FRV ELF linker hash table from a link_info structure. */
617 #define frvfdpic_hash_table(info) \
618 ((struct frvfdpic_elf_link_hash_table *) ((info)->hash))
620 #define frvfdpic_got_section(info) \
621 (frvfdpic_hash_table (info)->sgot)
622 #define frvfdpic_gotrel_section(info) \
623 (frvfdpic_hash_table (info)->sgotrel)
624 #define frvfdpic_gotfixup_section(info) \
625 (frvfdpic_hash_table (info)->sgotfixup)
626 #define frvfdpic_plt_section(info) \
627 (frvfdpic_hash_table (info)->splt)
628 #define frvfdpic_pltrel_section(info) \
629 (frvfdpic_hash_table (info)->spltrel)
630 #define frvfdpic_relocs_info(info) \
631 (frvfdpic_hash_table (info)->relocs_info)
632 #define frvfdpic_got_initial_offset(info) \
633 (frvfdpic_hash_table (info)->got0)
634 #define frvfdpic_plt_initial_offset(info) \
635 (frvfdpic_hash_table (info)->plt0)
637 /* Create an FRV ELF linker hash table. */
639 static struct bfd_link_hash_table *
640 frvfdpic_elf_link_hash_table_create (bfd *abfd)
642 struct frvfdpic_elf_link_hash_table *ret;
643 bfd_size_type amt = sizeof (struct frvfdpic_elf_link_hash_table);
645 ret = bfd_zalloc (abfd, amt);
649 if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd,
650 _bfd_elf_link_hash_newfunc))
656 return &ret->elf.root;
659 /* Decide whether a reference to a symbol can be resolved locally or
660 not. If the symbol is protected, we want the local address, but
661 its function descriptor must be assigned by the dynamic linker. */
662 #define FRVFDPIC_SYM_LOCAL(INFO, H) \
663 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
664 || ! elf_hash_table (INFO)->dynamic_sections_created)
665 #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \
666 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
668 /* This structure collects information on what kind of GOT, PLT or
669 function descriptors are required by relocations that reference a
671 struct frvfdpic_relocs_info
673 /* The index of the symbol, as stored in the relocation r_info, if
674 we have a local symbol; -1 otherwise. */
678 /* The input bfd in which the symbol is defined, if it's a local
681 /* If symndx == -1, the hash table entry corresponding to a global
682 symbol (even if it turns out to bind locally, in which case it
683 should ideally be replaced with section's symndx + addend). */
684 struct elf_link_hash_entry *h;
686 /* The addend of the relocation that references the symbol. */
689 /* The fields above are used to identify an entry. The fields below
690 contain information on how an entry is used and, later on, which
691 locations it was assigned. */
692 /* The following 3 fields record whether the symbol+addend above was
693 ever referenced with a GOT relocation. The 12 suffix indicates a
694 GOT12 relocation; los is used for GOTLO relocations that are not
695 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
700 /* Whether a FUNCDESC relocation references symbol+addend. */
702 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
705 unsigned fdgothilo:1;
706 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
708 unsigned fdgofflos:1;
709 unsigned fdgoffhilo:1;
710 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
711 GOTOFFHI relocations. The addend doesn't really matter, since we
712 envision that this will only be used to check whether the symbol
713 is mapped to the same segment as the got. */
715 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
717 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
720 /* Whether we need a PLT entry for a symbol. Should be implied by
722 (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */
724 /* Whether a function descriptor should be created in this link unit
725 for symbol+addend. Should be implied by something like:
726 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
727 || ((fd || fdgot12 || fdgotlos || fdgothilo)
728 && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */
730 /* Whether a lazy PLT entry is needed for this symbol+addend.
731 Should be implied by something like:
732 (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)
733 && ! (info->flags & DF_BIND_NOW)) */
735 /* Whether we've already emitted GOT relocations and PLT entries as
736 needed for this symbol. */
739 /* The number of R_FRV_32, R_FRV_FUNCDESC and R_FRV_FUNCDESC_VALUE
740 relocations referencing the symbol. */
741 unsigned relocs32, relocsfd, relocsfdv;
743 /* The number of .rofixups entries and dynamic relocations allocated
744 for this symbol, minus any that might have already been used. */
745 unsigned fixups, dynrelocs;
747 /* The offsets of the GOT entries assigned to symbol+addend, to the
748 function descriptor's address, and to a function descriptor,
749 respectively. Should be zero if unassigned. The offsets are
750 counted from the value that will be assigned to the PIC register,
751 not from the beginning of the .got section. */
752 bfd_signed_vma got_entry, fdgot_entry, fd_entry;
753 /* The offsets of the PLT entries assigned to symbol+addend,
754 non-lazy and lazy, respectively. If unassigned, should be
756 bfd_vma plt_entry, lzplt_entry;
759 /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */
761 frvfdpic_relocs_info_hash (const void *entry_)
763 const struct frvfdpic_relocs_info *entry = entry_;
765 return (entry->symndx == -1
766 ? entry->d.h->root.root.hash
767 : entry->symndx + entry->d.abfd->id * 257) + entry->addend;
770 /* Test whether the key fields of two frvfdpic_relocs_info entries are
773 frvfdpic_relocs_info_eq (const void *entry1, const void *entry2)
775 const struct frvfdpic_relocs_info *e1 = entry1;
776 const struct frvfdpic_relocs_info *e2 = entry2;
778 return e1->symndx == e2->symndx && e1->addend == e2->addend
779 && (e1->symndx == -1 ? e1->d.h == e2->d.h : e1->d.abfd == e2->d.abfd);
782 /* Find or create an entry in a hash table HT that matches the key
783 fields of the given ENTRY. If it's not found, memory for a new
784 entry is allocated in ABFD's obstack. */
785 static struct frvfdpic_relocs_info *
786 frvfdpic_relocs_info_find (struct htab *ht,
788 const struct frvfdpic_relocs_info *entry,
789 enum insert_option insert)
791 struct frvfdpic_relocs_info **loc =
792 (struct frvfdpic_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 frvfdpic_relocs_info *
818 frvfdpic_relocs_info_for_global (struct htab *ht,
820 struct elf_link_hash_entry *h,
822 enum insert_option insert)
824 struct frvfdpic_relocs_info entry;
828 entry.addend = addend;
830 return frvfdpic_relocs_info_find (ht, abfd, &entry, insert);
833 /* Obtain the address of the entry in HT associated with the SYMNDXth
834 local symbol of the input bfd ABFD, plus the addend, creating a new
835 entry if none existed. */
836 inline static struct frvfdpic_relocs_info *
837 frvfdpic_relocs_info_for_local (struct htab *ht,
841 enum insert_option insert)
843 struct frvfdpic_relocs_info entry;
845 entry.symndx = symndx;
847 entry.addend = addend;
849 return frvfdpic_relocs_info_find (ht, abfd, &entry, insert);
852 /* Merge fields set by check_relocs() of two entries that end up being
853 mapped to the same (presumably global) symbol. */
856 frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info *e2,
857 struct frvfdpic_relocs_info const *e1)
859 e2->got12 |= e1->got12;
860 e2->gotlos |= e1->gotlos;
861 e2->gothilo |= e1->gothilo;
863 e2->fdgot12 |= e1->fdgot12;
864 e2->fdgotlos |= e1->fdgotlos;
865 e2->fdgothilo |= e1->fdgothilo;
866 e2->fdgoff12 |= e1->fdgoff12;
867 e2->fdgofflos |= e1->fdgofflos;
868 e2->fdgoffhilo |= e1->fdgoffhilo;
869 e2->gotoff |= e1->gotoff;
870 e2->call |= e1->call;
874 /* These are set in _frvfdpic_count_got_plt_entries() or later, and this
875 function is only called in _frvfdpic_resolve_final_relocs_info(), that
876 runs just before it, so we don't have to worry about the fields
880 e2->privfd |= e1->privfd;
881 e2->lazyplt |= e1->lazyplt;
882 e2->done |= e1->done;
884 e2->relocs32 += e1->relocs32;
885 e2->relocsfd += e1->relocsfd;
886 e2->relocsfdv += e1->relocsfdv;
887 e2->fixups += e1->fixups;
888 e2->dynrelocs += e1->dynrelocs;
890 if (abs (e1->got_entry) < abs (e2->got_entry))
891 e2->got_entry = e1->got_entry;
892 if (abs (e1->fdgot_entry) < abs (e2->fdgot_entry))
893 e2->fdgot_entry = e1->fdgot_entry;
894 if (abs (e1->fd_entry) < abs (e2->fd_entry))
895 e2->fd_entry = e1->fd_entry;
897 if (e1->plt_entry < e2->plt_entry)
898 e2->plt_entry = e1->plt_entry;
899 if (e1->lzplt_entry < e2->lzplt_entry)
900 e2->lzplt_entry = e1->lzplt_entry;
904 /* Every block of 65535 lazy PLT entries shares a single call to the
905 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
906 32767, counting from 0). All other lazy PLT entries branch to it
907 in a single instruction. */
909 #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
910 #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767)
912 /* Add a dynamic relocation to the SRELOC section. */
914 inline static bfd_vma
915 _frvfdpic_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset,
916 int reloc_type, long dynindx, bfd_vma addend,
917 struct frvfdpic_relocs_info *entry)
919 Elf_Internal_Rela outrel;
920 bfd_vma reloc_offset;
922 outrel.r_offset = offset;
923 outrel.r_info = ELF32_R_INFO (dynindx, reloc_type);
924 outrel.r_addend = addend;
926 reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rel);
927 BFD_ASSERT (reloc_offset < sreloc->size);
928 bfd_elf32_swap_reloc_out (output_bfd, &outrel,
929 sreloc->contents + reloc_offset);
930 sreloc->reloc_count++;
932 /* If the entry's index is zero, this relocation was probably to a
933 linkonce section that got discarded. We reserved a dynamic
934 relocation, but it was for another entry than the one we got at
935 the time of emitting the relocation. Unfortunately there's no
936 simple way for us to catch this situation, since the relocation
937 is cleared right before calling relocate_section, at which point
938 we no longer know what the relocation used to point to. */
941 BFD_ASSERT (entry->dynrelocs > 0);
948 /* Add a fixup to the ROFIXUP section. */
951 _frvfdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset,
952 struct frvfdpic_relocs_info *entry)
954 bfd_vma fixup_offset;
956 if (rofixup->flags & SEC_EXCLUDE)
959 fixup_offset = rofixup->reloc_count * 4;
960 if (rofixup->contents)
962 BFD_ASSERT (fixup_offset < rofixup->size);
963 bfd_put_32 (output_bfd, offset, rofixup->contents + fixup_offset);
965 rofixup->reloc_count++;
967 if (entry && entry->symndx)
969 /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc
971 BFD_ASSERT (entry->fixups > 0);
978 /* Find the segment number in which OSEC, and output section, is
982 _frvfdpic_osec_to_segment (bfd *output_bfd, asection *osec)
984 struct elf_segment_map *m;
985 Elf_Internal_Phdr *p;
987 /* Find the segment that contains the output_section. */
988 for (m = elf_tdata (output_bfd)->segment_map,
989 p = elf_tdata (output_bfd)->phdr;
995 for (i = m->count - 1; i >= 0; i--)
996 if (m->sections[i] == osec)
1003 return p - elf_tdata (output_bfd)->phdr;
1006 inline static bfd_boolean
1007 _frvfdpic_osec_readonly_p (bfd *output_bfd, asection *osec)
1009 unsigned seg = _frvfdpic_osec_to_segment (output_bfd, osec);
1011 return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W);
1014 /* Generate relocations for GOT entries, function descriptors, and
1015 code for PLT and lazy PLT entries. */
1017 inline static bfd_boolean
1018 _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info *entry,
1020 struct bfd_link_info *info,
1022 Elf_Internal_Sym *sym,
1026 bfd_vma fd_lazy_rel_offset = (bfd_vma)-1;
1033 if (entry->got_entry || entry->fdgot_entry || entry->fd_entry)
1035 /* If the symbol is dynamic, consider it for dynamic
1036 relocations, otherwise decay to section + offset. */
1037 if (entry->symndx == -1 && entry->d.h->dynindx != -1)
1038 dynindx = entry->d.h->dynindx;
1041 if (sec->output_section
1042 && ! bfd_is_abs_section (sec->output_section)
1043 && ! bfd_is_und_section (sec->output_section))
1044 dynindx = elf_section_data (sec->output_section)->dynindx;
1050 /* Generate relocation for GOT entry pointing to the symbol. */
1051 if (entry->got_entry)
1054 bfd_vma ad = addend;
1056 /* If the symbol is dynamic but binds locally, use
1058 if (sec && (entry->symndx != -1
1059 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1061 if (entry->symndx == -1)
1062 ad += entry->d.h->root.u.def.value;
1064 ad += sym->st_value;
1065 ad += sec->output_offset;
1066 if (sec->output_section && elf_section_data (sec->output_section))
1067 idx = elf_section_data (sec->output_section)->dynindx;
1072 /* If we're linking an executable at a fixed address, we can
1073 omit the dynamic relocation as long as the symbol is local to
1075 if (info->executable && !info->pie
1076 && (entry->symndx != -1
1077 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1080 ad += sec->output_section->vma;
1081 if (entry->symndx != -1
1082 || entry->d.h->root.type != bfd_link_hash_undefweak)
1083 _frvfdpic_add_rofixup (output_bfd,
1084 frvfdpic_gotfixup_section (info),
1085 frvfdpic_got_section (info)->output_section
1087 + frvfdpic_got_section (info)->output_offset
1088 + frvfdpic_got_initial_offset (info)
1089 + entry->got_entry, entry);
1092 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
1093 _bfd_elf_section_offset
1095 frvfdpic_got_section (info),
1096 frvfdpic_got_initial_offset (info)
1098 + frvfdpic_got_section (info)
1099 ->output_section->vma
1100 + frvfdpic_got_section (info)->output_offset,
1101 R_FRV_32, idx, ad, entry);
1103 bfd_put_32 (output_bfd, ad,
1104 frvfdpic_got_section (info)->contents
1105 + frvfdpic_got_initial_offset (info)
1106 + entry->got_entry);
1109 /* Generate relocation for GOT entry pointing to a canonical
1110 function descriptor. */
1111 if (entry->fdgot_entry)
1116 if (! (entry->symndx == -1
1117 && entry->d.h->root.type == bfd_link_hash_undefweak
1118 && FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1120 /* If the symbol is dynamic and there may be dynamic symbol
1121 resolution because we are, or are linked with, a shared
1122 library, emit a FUNCDESC relocation such that the dynamic
1123 linker will allocate the function descriptor. If the
1124 symbol needs a non-local function descriptor but binds
1125 locally (e.g., its visibility is protected, emit a
1126 dynamic relocation decayed to section+offset. */
1127 if (entry->symndx == -1
1128 && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)
1129 && FRVFDPIC_SYM_LOCAL (info, entry->d.h)
1130 && !(info->executable && !info->pie))
1132 reloc = R_FRV_FUNCDESC;
1133 idx = elf_section_data (entry->d.h->root.u.def.section
1134 ->output_section)->dynindx;
1135 ad = entry->d.h->root.u.def.section->output_offset
1136 + entry->d.h->root.u.def.value;
1138 else if (entry->symndx == -1
1139 && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h))
1141 reloc = R_FRV_FUNCDESC;
1149 /* Otherwise, we know we have a private function descriptor,
1150 so reference it directly. */
1151 if (elf_hash_table (info)->dynamic_sections_created)
1152 BFD_ASSERT (entry->privfd);
1154 idx = elf_section_data (frvfdpic_got_section (info)
1155 ->output_section)->dynindx;
1156 ad = frvfdpic_got_section (info)->output_offset
1157 + frvfdpic_got_initial_offset (info) + entry->fd_entry;
1160 /* If there is room for dynamic symbol resolution, emit the
1161 dynamic relocation. However, if we're linking an
1162 executable at a fixed location, we won't have emitted a
1163 dynamic symbol entry for the got section, so idx will be
1164 zero, which means we can and should compute the address
1165 of the private descriptor ourselves. */
1166 if (info->executable && !info->pie
1167 && (entry->symndx != -1
1168 || FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)))
1170 ad += frvfdpic_got_section (info)->output_section->vma;
1171 _frvfdpic_add_rofixup (output_bfd,
1172 frvfdpic_gotfixup_section (info),
1173 frvfdpic_got_section (info)
1174 ->output_section->vma
1175 + frvfdpic_got_section (info)
1177 + frvfdpic_got_initial_offset (info)
1178 + entry->fdgot_entry, entry);
1181 _frvfdpic_add_dyn_reloc (output_bfd,
1182 frvfdpic_gotrel_section (info),
1183 _bfd_elf_section_offset
1185 frvfdpic_got_section (info),
1186 frvfdpic_got_initial_offset (info)
1187 + entry->fdgot_entry)
1188 + frvfdpic_got_section (info)
1189 ->output_section->vma
1190 + frvfdpic_got_section (info)
1192 reloc, idx, ad, entry);
1195 bfd_put_32 (output_bfd, ad,
1196 frvfdpic_got_section (info)->contents
1197 + frvfdpic_got_initial_offset (info)
1198 + entry->fdgot_entry);
1201 /* Generate relocation to fill in a private function descriptor in
1203 if (entry->fd_entry)
1206 bfd_vma ad = addend;
1208 long lowword, highword;
1210 /* If the symbol is dynamic but binds locally, use
1212 if (sec && (entry->symndx != -1
1213 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1215 if (entry->symndx == -1)
1216 ad += entry->d.h->root.u.def.value;
1218 ad += sym->st_value;
1219 ad += sec->output_offset;
1220 if (sec->output_section && elf_section_data (sec->output_section))
1221 idx = elf_section_data (sec->output_section)->dynindx;
1226 /* If we're linking an executable at a fixed address, we can
1227 omit the dynamic relocation as long as the symbol is local to
1229 if (info->executable && !info->pie
1230 && (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1233 ad += sec->output_section->vma;
1235 if (entry->symndx != -1
1236 || entry->d.h->root.type != bfd_link_hash_undefweak)
1238 _frvfdpic_add_rofixup (output_bfd,
1239 frvfdpic_gotfixup_section (info),
1240 frvfdpic_got_section (info)
1241 ->output_section->vma
1242 + frvfdpic_got_section (info)
1244 + frvfdpic_got_initial_offset (info)
1245 + entry->fd_entry, entry);
1246 _frvfdpic_add_rofixup (output_bfd,
1247 frvfdpic_gotfixup_section (info),
1248 frvfdpic_got_section (info)
1249 ->output_section->vma
1250 + frvfdpic_got_section (info)
1252 + frvfdpic_got_initial_offset (info)
1253 + entry->fd_entry + 4, entry);
1259 _frvfdpic_add_dyn_reloc (output_bfd,
1261 ? frvfdpic_pltrel_section (info)
1262 : frvfdpic_gotrel_section (info),
1263 _bfd_elf_section_offset
1265 frvfdpic_got_section (info),
1266 frvfdpic_got_initial_offset (info)
1268 + frvfdpic_got_section (info)
1269 ->output_section->vma
1270 + frvfdpic_got_section (info)
1272 R_FRV_FUNCDESC_VALUE, idx, ad, entry);
1275 /* If we've omitted the dynamic relocation, just emit the fixed
1276 addresses of the symbol and of the local GOT base offset. */
1277 if (info->executable && !info->pie && sec && sec->output_section)
1280 highword = frvfdpic_got_section (info)->output_section->vma
1281 + frvfdpic_got_section (info)->output_offset
1282 + frvfdpic_got_initial_offset (info);
1284 else if (entry->lazyplt)
1289 fd_lazy_rel_offset = ofst;
1291 /* A function descriptor used for lazy or local resolving is
1292 initialized such that its high word contains the output
1293 section index in which the PLT entries are located, and
1294 the low word contains the address of the lazy PLT entry
1295 entry point, that must be within the memory region
1296 assigned to that section. */
1297 lowword = entry->lzplt_entry + 4
1298 + frvfdpic_plt_section (info)->output_offset
1299 + frvfdpic_plt_section (info)->output_section->vma;
1300 highword = _frvfdpic_osec_to_segment
1301 (output_bfd, frvfdpic_plt_section (info)->output_section);
1305 /* A function descriptor for a local function gets the index
1306 of the section. For a non-local function, it's
1309 if (entry->symndx == -1 && entry->d.h->dynindx != -1
1310 && entry->d.h->dynindx == idx)
1313 highword = _frvfdpic_osec_to_segment
1314 (output_bfd, sec->output_section);
1317 bfd_put_32 (output_bfd, lowword,
1318 frvfdpic_got_section (info)->contents
1319 + frvfdpic_got_initial_offset (info)
1321 bfd_put_32 (output_bfd, highword,
1322 frvfdpic_got_section (info)->contents
1323 + frvfdpic_got_initial_offset (info)
1324 + entry->fd_entry + 4);
1327 /* Generate code for the PLT entry. */
1328 if (entry->plt_entry != (bfd_vma) -1)
1330 bfd_byte *plt_code = frvfdpic_plt_section (info)->contents
1333 BFD_ASSERT (entry->fd_entry);
1335 /* Figure out what kind of PLT entry we need, depending on the
1336 location of the function descriptor within the GOT. */
1337 if (entry->fd_entry >= -(1 << (12 - 1))
1338 && entry->fd_entry < (1 << (12 - 1)))
1340 /* lddi @(gr15, fd_entry), gr14 */
1341 bfd_put_32 (output_bfd,
1342 0x9cccf000 | (entry->fd_entry & ((1 << 12) - 1)),
1348 if (entry->fd_entry >= -(1 << (16 - 1))
1349 && entry->fd_entry < (1 << (16 - 1)))
1351 /* setlos lo(fd_entry), gr14 */
1352 bfd_put_32 (output_bfd,
1354 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
1360 /* sethi.p hi(fd_entry), gr14
1361 setlo lo(fd_entry), gr14 */
1362 bfd_put_32 (output_bfd,
1364 | ((entry->fd_entry >> 16)
1365 & (((bfd_vma)1 << 16) - 1)),
1367 bfd_put_32 (output_bfd,
1369 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
1373 /* ldd @(gr14,gr15),gr14 */
1374 bfd_put_32 (output_bfd, 0x9c08e14f, plt_code);
1377 /* jmpl @(gr14,gr0) */
1378 bfd_put_32 (output_bfd, 0x8030e000, plt_code);
1381 /* Generate code for the lazy PLT entry. */
1382 if (entry->lzplt_entry != (bfd_vma) -1)
1384 bfd_byte *lzplt_code = frvfdpic_plt_section (info)->contents
1385 + entry->lzplt_entry;
1386 bfd_vma resolverStub_addr;
1388 bfd_put_32 (output_bfd, fd_lazy_rel_offset, lzplt_code);
1391 resolverStub_addr = entry->lzplt_entry / FRVFDPIC_LZPLT_BLOCK_SIZE
1392 * FRVFDPIC_LZPLT_BLOCK_SIZE + FRVFDPIC_LZPLT_RESOLV_LOC;
1393 if (resolverStub_addr >= frvfdpic_plt_initial_offset (info))
1394 resolverStub_addr = frvfdpic_plt_initial_offset (info) - 12;
1396 if (entry->lzplt_entry == resolverStub_addr)
1398 /* This is a lazy PLT entry that includes a resolver call. */
1399 /* ldd @(gr15,gr0), gr4
1401 bfd_put_32 (output_bfd, 0x8808f140, lzplt_code);
1402 bfd_put_32 (output_bfd, 0x80304000, lzplt_code + 4);
1406 /* bra resolverStub */
1407 bfd_put_32 (output_bfd,
1409 | (((resolverStub_addr - entry->lzplt_entry)
1410 / 4) & (((bfd_vma)1 << 16) - 1)),
1418 /* Handle an FRV small data reloc. */
1420 static bfd_reloc_status_type
1421 elf32_frv_relocate_gprel12 (info, input_bfd, input_section, relocation,
1423 struct bfd_link_info *info;
1425 asection *input_section;
1426 Elf_Internal_Rela *relocation;
1432 struct bfd_link_hash_entry *h;
1434 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
1436 gp = (h->u.def.value
1437 + h->u.def.section->output_section->vma
1438 + h->u.def.section->output_offset);
1440 value -= input_section->output_section->vma;
1441 value -= (gp - input_section->output_section->vma);
1443 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
1445 value += relocation->r_addend;
1447 if ((long) value > 0x7ff || (long) value < -0x800)
1448 return bfd_reloc_overflow;
1450 bfd_put_32 (input_bfd,
1451 (insn & 0xfffff000) | (value & 0xfff),
1452 contents + relocation->r_offset);
1454 return bfd_reloc_ok;
1457 /* Handle an FRV small data reloc. for the u12 field. */
1459 static bfd_reloc_status_type
1460 elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, relocation,
1462 struct bfd_link_info *info;
1464 asection *input_section;
1465 Elf_Internal_Rela *relocation;
1471 struct bfd_link_hash_entry *h;
1474 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
1476 gp = (h->u.def.value
1477 + h->u.def.section->output_section->vma
1478 + h->u.def.section->output_offset);
1480 value -= input_section->output_section->vma;
1481 value -= (gp - input_section->output_section->vma);
1483 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
1485 value += relocation->r_addend;
1487 if ((long) value > 0x7ff || (long) value < -0x800)
1488 return bfd_reloc_overflow;
1490 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
1492 insn = (insn & ~mask) | ((value & 0xfc0) << 12) | (value & 0x3f);
1494 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
1496 return bfd_reloc_ok;
1499 /* Handle an FRV ELF HI16 reloc. */
1501 static bfd_reloc_status_type
1502 elf32_frv_relocate_hi16 (input_bfd, relhi, contents, value)
1504 Elf_Internal_Rela *relhi;
1510 insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
1512 value += relhi->r_addend;
1513 value = ((value >> 16) & 0xffff);
1515 insn = (insn & 0xffff0000) | value;
1517 if ((long) value > 0xffff || (long) value < -0x10000)
1518 return bfd_reloc_overflow;
1520 bfd_put_32 (input_bfd, insn, contents + relhi->r_offset);
1521 return bfd_reloc_ok;
1524 static bfd_reloc_status_type
1525 elf32_frv_relocate_lo16 (input_bfd, rello, contents, value)
1527 Elf_Internal_Rela *rello;
1533 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
1535 value += rello->r_addend;
1536 value = value & 0xffff;
1538 insn = (insn & 0xffff0000) | value;
1540 if ((long) value > 0xffff || (long) value < -0x10000)
1541 return bfd_reloc_overflow;
1543 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
1544 return bfd_reloc_ok;
1547 /* Perform the relocation for the CALL label24 instruction. */
1549 static bfd_reloc_status_type
1550 elf32_frv_relocate_label24 (input_bfd, input_section, rello, contents, value)
1552 asection *input_section;
1553 Elf_Internal_Rela *rello;
1561 /* The format for the call instruction is:
1563 0 000000 0001111 000000000000000000
1564 label6 opcode label18
1566 The branch calculation is: pc + (4*label24)
1567 where label24 is the concatenation of label6 and label18. */
1569 /* Grab the instruction. */
1570 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
1572 value -= input_section->output_section->vma + input_section->output_offset;
1573 value -= rello->r_offset;
1574 value += rello->r_addend;
1578 label6 = value & 0xfc0000;
1579 label6 = label6 << 7;
1581 label18 = value & 0x3ffff;
1583 insn = insn & 0x803c0000;
1584 insn = insn | label6;
1585 insn = insn | label18;
1587 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
1589 return bfd_reloc_ok;
1592 static bfd_reloc_status_type
1593 elf32_frv_relocate_gprelhi (info, input_bfd, input_section, relocation,
1595 struct bfd_link_info *info;
1597 asection *input_section;
1598 Elf_Internal_Rela *relocation;
1604 struct bfd_link_hash_entry *h;
1606 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
1608 gp = (h->u.def.value
1609 + h->u.def.section->output_section->vma
1610 + h->u.def.section->output_offset);
1612 value -= input_section->output_section->vma;
1613 value -= (gp - input_section->output_section->vma);
1614 value += relocation->r_addend;
1615 value = ((value >> 16) & 0xffff);
1617 if ((long) value > 0xffff || (long) value < -0x10000)
1618 return bfd_reloc_overflow;
1620 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
1621 insn = (insn & 0xffff0000) | value;
1623 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
1624 return bfd_reloc_ok;
1627 static bfd_reloc_status_type
1628 elf32_frv_relocate_gprello (info, input_bfd, input_section, relocation,
1630 struct bfd_link_info *info;
1632 asection *input_section;
1633 Elf_Internal_Rela *relocation;
1639 struct bfd_link_hash_entry *h;
1641 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
1643 gp = (h->u.def.value
1644 + h->u.def.section->output_section->vma
1645 + h->u.def.section->output_offset);
1647 value -= input_section->output_section->vma;
1648 value -= (gp - input_section->output_section->vma);
1649 value += relocation->r_addend;
1650 value = value & 0xffff;
1652 if ((long) value > 0xffff || (long) value < -0x10000)
1653 return bfd_reloc_overflow;
1655 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
1656 insn = (insn & 0xffff0000) | value;
1658 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
1660 return bfd_reloc_ok;
1663 static reloc_howto_type *
1664 frv_reloc_type_lookup (abfd, code)
1665 bfd *abfd ATTRIBUTE_UNUSED;
1666 bfd_reloc_code_real_type code;
1673 case BFD_RELOC_NONE:
1674 return &elf32_frv_howto_table[ (int) R_FRV_NONE];
1677 if (elf_elfheader (abfd)->e_type == ET_EXEC
1678 || elf_elfheader (abfd)->e_type == ET_DYN)
1679 return &elf32_frv_rel_32_howto;
1681 case BFD_RELOC_CTOR:
1682 return &elf32_frv_howto_table[ (int) R_FRV_32];
1684 case BFD_RELOC_FRV_LABEL16:
1685 return &elf32_frv_howto_table[ (int) R_FRV_LABEL16];
1687 case BFD_RELOC_FRV_LABEL24:
1688 return &elf32_frv_howto_table[ (int) R_FRV_LABEL24];
1690 case BFD_RELOC_FRV_LO16:
1691 return &elf32_frv_howto_table[ (int) R_FRV_LO16];
1693 case BFD_RELOC_FRV_HI16:
1694 return &elf32_frv_howto_table[ (int) R_FRV_HI16];
1696 case BFD_RELOC_FRV_GPREL12:
1697 return &elf32_frv_howto_table[ (int) R_FRV_GPREL12];
1699 case BFD_RELOC_FRV_GPRELU12:
1700 return &elf32_frv_howto_table[ (int) R_FRV_GPRELU12];
1702 case BFD_RELOC_FRV_GPREL32:
1703 return &elf32_frv_howto_table[ (int) R_FRV_GPREL32];
1705 case BFD_RELOC_FRV_GPRELHI:
1706 return &elf32_frv_howto_table[ (int) R_FRV_GPRELHI];
1708 case BFD_RELOC_FRV_GPRELLO:
1709 return &elf32_frv_howto_table[ (int) R_FRV_GPRELLO];
1711 case BFD_RELOC_FRV_GOT12:
1712 return &elf32_frv_howto_table[ (int) R_FRV_GOT12];
1714 case BFD_RELOC_FRV_GOTHI:
1715 return &elf32_frv_howto_table[ (int) R_FRV_GOTHI];
1717 case BFD_RELOC_FRV_GOTLO:
1718 return &elf32_frv_howto_table[ (int) R_FRV_GOTLO];
1720 case BFD_RELOC_FRV_FUNCDESC:
1721 if (elf_elfheader (abfd)->e_type == ET_EXEC
1722 || elf_elfheader (abfd)->e_type == ET_DYN)
1723 return &elf32_frv_rel_funcdesc_howto;
1724 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC];
1726 case BFD_RELOC_FRV_FUNCDESC_GOT12:
1727 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOT12];
1729 case BFD_RELOC_FRV_FUNCDESC_GOTHI:
1730 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTHI];
1732 case BFD_RELOC_FRV_FUNCDESC_GOTLO:
1733 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTLO];
1735 case BFD_RELOC_FRV_FUNCDESC_VALUE:
1736 if (elf_elfheader (abfd)->e_type == ET_EXEC
1737 || elf_elfheader (abfd)->e_type == ET_DYN)
1738 return &elf32_frv_rel_funcdesc_value_howto;
1739 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_VALUE];
1741 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12:
1742 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFF12];
1744 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI:
1745 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFHI];
1747 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO:
1748 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFLO];
1750 case BFD_RELOC_FRV_GOTOFF12:
1751 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFF12];
1753 case BFD_RELOC_FRV_GOTOFFHI:
1754 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFHI];
1756 case BFD_RELOC_FRV_GOTOFFLO:
1757 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFLO];
1759 case BFD_RELOC_VTABLE_INHERIT:
1760 return &elf32_frv_vtinherit_howto;
1762 case BFD_RELOC_VTABLE_ENTRY:
1763 return &elf32_frv_vtentry_howto;
1769 /* Set the howto pointer for an FRV ELF reloc. */
1772 frv_info_to_howto_rela (abfd, cache_ptr, dst)
1773 bfd *abfd ATTRIBUTE_UNUSED;
1775 Elf_Internal_Rela *dst;
1777 unsigned int r_type;
1779 r_type = ELF32_R_TYPE (dst->r_info);
1782 case R_FRV_GNU_VTINHERIT:
1783 cache_ptr->howto = &elf32_frv_vtinherit_howto;
1786 case R_FRV_GNU_VTENTRY:
1787 cache_ptr->howto = &elf32_frv_vtentry_howto;
1791 cache_ptr->howto = & elf32_frv_howto_table [r_type];
1796 /* Set the howto pointer for an FRV ELF REL reloc. */
1798 frvfdpic_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
1799 arelent *cache_ptr, Elf_Internal_Rela *dst)
1801 unsigned int r_type;
1803 r_type = ELF32_R_TYPE (dst->r_info);
1807 cache_ptr->howto = &elf32_frv_rel_32_howto;
1810 case R_FRV_FUNCDESC:
1811 cache_ptr->howto = &elf32_frv_rel_funcdesc_howto;
1814 case R_FRV_FUNCDESC_VALUE:
1815 cache_ptr->howto = &elf32_frv_rel_funcdesc_value_howto;
1819 cache_ptr->howto = NULL;
1824 /* Perform a single relocation. By default we use the standard BFD
1825 routines, but a few relocs, we have to do them ourselves. */
1827 static bfd_reloc_status_type
1828 frv_final_link_relocate (howto, input_bfd, input_section, contents, rel,
1830 reloc_howto_type *howto;
1832 asection *input_section;
1834 Elf_Internal_Rela *rel;
1837 return _bfd_final_link_relocate (howto, input_bfd, input_section,
1838 contents, rel->r_offset, relocation,
1843 /* Relocate an FRV ELF section.
1845 The RELOCATE_SECTION function is called by the new ELF backend linker
1846 to handle the relocations for a section.
1848 The relocs are always passed as Rela structures; if the section
1849 actually uses Rel structures, the r_addend field will always be
1852 This function is responsible for adjusting the section contents as
1853 necessary, and (if using Rela relocs and generating a relocatable
1854 output file) adjusting the reloc addend as necessary.
1856 This function does not have to worry about setting the reloc
1857 address or the reloc symbol index.
1859 LOCAL_SYMS is a pointer to the swapped in local symbols.
1861 LOCAL_SECTIONS is an array giving the section in the input file
1862 corresponding to the st_shndx field of each local symbol.
1864 The global hash table entry for the global symbols can be found
1865 via elf_sym_hashes (input_bfd).
1867 When generating relocatable output, this function must handle
1868 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1869 going to be the section symbol corresponding to the output
1870 section, which means that the addend must be adjusted
1874 elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
1875 contents, relocs, local_syms, local_sections)
1876 bfd *output_bfd ATTRIBUTE_UNUSED;
1877 struct bfd_link_info *info;
1879 asection *input_section;
1881 Elf_Internal_Rela *relocs;
1882 Elf_Internal_Sym *local_syms;
1883 asection **local_sections;
1885 Elf_Internal_Shdr *symtab_hdr;
1886 struct elf_link_hash_entry **sym_hashes;
1887 Elf_Internal_Rela *rel;
1888 Elf_Internal_Rela *relend;
1889 unsigned isec_segment, got_segment, plt_segment, gprel_segment,
1891 int silence_segment_error = !(info->shared || info->pie);
1893 if (info->relocatable)
1896 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
1897 sym_hashes = elf_sym_hashes (input_bfd);
1898 relend = relocs + input_section->reloc_count;
1900 isec_segment = _frvfdpic_osec_to_segment (output_bfd,
1901 input_section->output_section);
1902 if (IS_FDPIC (output_bfd) && frvfdpic_got_section (info))
1903 got_segment = _frvfdpic_osec_to_segment (output_bfd,
1904 frvfdpic_got_section (info)
1908 if (IS_FDPIC (output_bfd) && frvfdpic_gotfixup_section (info))
1909 gprel_segment = _frvfdpic_osec_to_segment (output_bfd,
1910 frvfdpic_gotfixup_section (info)
1914 if (IS_FDPIC (output_bfd) && elf_hash_table (info)->dynamic_sections_created)
1915 plt_segment = _frvfdpic_osec_to_segment (output_bfd,
1916 frvfdpic_plt_section (info)
1921 for (rel = relocs; rel < relend; rel ++)
1923 reloc_howto_type *howto;
1924 unsigned long r_symndx;
1925 Elf_Internal_Sym *sym;
1927 struct elf_link_hash_entry *h;
1929 bfd_reloc_status_type r;
1930 const char * name = NULL;
1933 struct frvfdpic_relocs_info *picrel;
1934 bfd_vma orig_addend = rel->r_addend;
1936 r_type = ELF32_R_TYPE (rel->r_info);
1938 if ( r_type == R_FRV_GNU_VTINHERIT
1939 || r_type == R_FRV_GNU_VTENTRY)
1942 /* This is a final link. */
1943 r_symndx = ELF32_R_SYM (rel->r_info);
1944 howto = elf32_frv_howto_table + ELF32_R_TYPE (rel->r_info);
1949 if (r_symndx < symtab_hdr->sh_info)
1951 sym = local_syms + r_symndx;
1952 osec = sec = local_sections [r_symndx];
1953 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1955 name = bfd_elf_string_from_elf_section
1956 (input_bfd, symtab_hdr->sh_link, sym->st_name);
1957 name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
1961 h = sym_hashes [r_symndx - symtab_hdr->sh_info];
1963 while (h->root.type == bfd_link_hash_indirect
1964 || h->root.type == bfd_link_hash_warning)
1965 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1967 name = h->root.root.string;
1969 if ((h->root.type == bfd_link_hash_defined
1970 || h->root.type == bfd_link_hash_defweak)
1971 && ! FRVFDPIC_SYM_LOCAL (info, h))
1977 if (h->root.type == bfd_link_hash_defined
1978 || h->root.type == bfd_link_hash_defweak)
1980 sec = h->root.u.def.section;
1981 relocation = (h->root.u.def.value
1982 + sec->output_section->vma
1983 + sec->output_offset);
1985 else if (h->root.type == bfd_link_hash_undefweak)
1989 else if (info->unresolved_syms_in_objects == RM_IGNORE
1990 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
1994 if (! ((*info->callbacks->undefined_symbol)
1995 (info, h->root.root.string, input_bfd,
1996 input_section, rel->r_offset,
1997 (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
1998 || ELF_ST_VISIBILITY (h->other)))))
2009 if (! IS_FDPIC (output_bfd))
2015 case R_FRV_FUNCDESC_GOT12:
2016 case R_FRV_FUNCDESC_GOTHI:
2017 case R_FRV_FUNCDESC_GOTLO:
2018 case R_FRV_GOTOFF12:
2019 case R_FRV_GOTOFFHI:
2020 case R_FRV_GOTOFFLO:
2021 case R_FRV_FUNCDESC_GOTOFF12:
2022 case R_FRV_FUNCDESC_GOTOFFHI:
2023 case R_FRV_FUNCDESC_GOTOFFLO:
2024 case R_FRV_FUNCDESC:
2025 case R_FRV_FUNCDESC_VALUE:
2027 picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info
2028 (info), input_bfd, h,
2029 orig_addend, INSERT);
2031 /* In order to find the entry we created before, we must
2032 use the original addend, not the one that may have been
2033 modified by _bfd_elf_rela_local_sym(). */
2034 picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
2035 (info), input_bfd, r_symndx,
2036 orig_addend, INSERT);
2040 if (!_frvfdpic_emit_got_relocs_plt_entries (picrel, output_bfd, info,
2044 (*_bfd_error_handler)
2045 (_("%s: relocation at `%s+0x%x' references symbol `%s' with nonzero addend"),
2046 bfd_archive_filename (input_bfd), input_section->name,
2047 rel->r_offset, name);
2057 if (h && ! FRVFDPIC_SYM_LOCAL (info, h))
2059 info->callbacks->warning
2060 (info, _("relocation references symbol not defined in the module"),
2061 name, input_bfd, input_section, rel->r_offset);
2070 check_segment[0] = isec_segment;
2071 if (! IS_FDPIC (output_bfd))
2072 check_segment[1] = isec_segment;
2073 else if (picrel->plt)
2075 relocation = frvfdpic_plt_section (info)->output_section->vma
2076 + frvfdpic_plt_section (info)->output_offset
2077 + picrel->plt_entry;
2078 check_segment[1] = plt_segment;
2080 /* We don't want to warn on calls to undefined weak symbols,
2081 as calls to them must be protected by non-NULL tests
2082 anyway, and unprotected calls would invoke undefined
2084 else if (picrel->symndx == -1
2085 && picrel->d.h->root.type == bfd_link_hash_undefweak)
2086 check_segment[1] = check_segment[0];
2088 check_segment[1] = sec
2089 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
2096 relocation = picrel->got_entry;
2097 check_segment[0] = check_segment[1] = got_segment;
2100 case R_FRV_FUNCDESC_GOT12:
2101 case R_FRV_FUNCDESC_GOTHI:
2102 case R_FRV_FUNCDESC_GOTLO:
2103 relocation = picrel->fdgot_entry;
2104 check_segment[0] = check_segment[1] = got_segment;
2107 case R_FRV_GOTOFFHI:
2108 case R_FRV_GOTOFF12:
2109 case R_FRV_GOTOFFLO:
2110 relocation -= frvfdpic_got_section (info)->output_section->vma
2111 + frvfdpic_got_section (info)->output_offset
2112 + frvfdpic_got_initial_offset (info);
2113 check_segment[0] = got_segment;
2114 check_segment[1] = sec
2115 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
2119 case R_FRV_FUNCDESC_GOTOFF12:
2120 case R_FRV_FUNCDESC_GOTOFFHI:
2121 case R_FRV_FUNCDESC_GOTOFFLO:
2122 relocation = picrel->fd_entry;
2123 check_segment[0] = check_segment[1] = got_segment;
2126 case R_FRV_FUNCDESC:
2129 bfd_vma addend = rel->r_addend;
2131 if (! (h && h->root.type == bfd_link_hash_undefweak
2132 && FRVFDPIC_SYM_LOCAL (info, h)))
2134 /* If the symbol is dynamic and there may be dynamic
2135 symbol resolution because we are or are linked with a
2136 shared library, emit a FUNCDESC relocation such that
2137 the dynamic linker will allocate the function
2138 descriptor. If the symbol needs a non-local function
2139 descriptor but binds locally (e.g., its visibility is
2140 protected, emit a dynamic relocation decayed to
2142 if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h)
2143 && FRVFDPIC_SYM_LOCAL (info, h)
2144 && !(info->executable && !info->pie))
2146 dynindx = elf_section_data (h->root.u.def.section
2147 ->output_section)->dynindx;
2148 addend += h->root.u.def.section->output_offset
2149 + h->root.u.def.value;
2151 else if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h))
2155 info->callbacks->warning
2156 (info, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"),
2157 name, input_bfd, input_section, rel->r_offset);
2160 dynindx = h->dynindx;
2164 /* Otherwise, we know we have a private function
2165 descriptor, so reference it directly. */
2166 BFD_ASSERT (picrel->privfd);
2168 dynindx = elf_section_data (frvfdpic_got_section (info)
2169 ->output_section)->dynindx;
2170 addend = frvfdpic_got_section (info)->output_offset
2171 + frvfdpic_got_initial_offset (info)
2175 /* If there is room for dynamic symbol resolution, emit
2176 the dynamic relocation. However, if we're linking an
2177 executable at a fixed location, we won't have emitted a
2178 dynamic symbol entry for the got section, so idx will
2179 be zero, which means we can and should compute the
2180 address of the private descriptor ourselves. */
2181 if (info->executable && !info->pie
2182 && (!h || FRVFDPIC_FUNCDESC_LOCAL (info, h)))
2184 addend += frvfdpic_got_section (info)->output_section->vma;
2185 if ((bfd_get_section_flags (output_bfd,
2186 input_section->output_section)
2187 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2189 if (_frvfdpic_osec_readonly_p (output_bfd,
2193 info->callbacks->warning
2195 _("cannot emit fixups in read-only section"),
2196 name, input_bfd, input_section, rel->r_offset);
2199 _frvfdpic_add_rofixup (output_bfd,
2200 frvfdpic_gotfixup_section
2202 _bfd_elf_section_offset
2204 input_section, rel->r_offset)
2206 ->output_section->vma
2207 + input_section->output_offset,
2211 else if ((bfd_get_section_flags (output_bfd,
2212 input_section->output_section)
2213 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2215 if (_frvfdpic_osec_readonly_p (output_bfd,
2219 info->callbacks->warning
2221 _("cannot emit dynamic relocations in read-only section"),
2222 name, input_bfd, input_section, rel->r_offset);
2225 _frvfdpic_add_dyn_reloc (output_bfd,
2226 frvfdpic_gotrel_section (info),
2227 _bfd_elf_section_offset
2229 input_section, rel->r_offset)
2231 ->output_section->vma
2232 + input_section->output_offset,
2233 r_type, dynindx, addend, picrel);
2236 addend += frvfdpic_got_section (info)->output_section->vma;
2239 /* We want the addend in-place because dynamic
2240 relocations are REL. Setting relocation to it should
2241 arrange for it to be installed. */
2242 relocation = addend - rel->r_addend;
2244 check_segment[0] = check_segment[1] = got_segment;
2248 if (! IS_FDPIC (output_bfd))
2250 check_segment[0] = check_segment[1] = -1;
2254 case R_FRV_FUNCDESC_VALUE:
2257 bfd_vma addend = rel->r_addend;
2259 /* If the symbol is dynamic but binds locally, use
2261 if (h && ! FRVFDPIC_SYM_LOCAL (info, h))
2263 if (addend && r_type == R_FRV_FUNCDESC_VALUE)
2265 info->callbacks->warning
2266 (info, _("R_FRV_FUNCDESC_VALUE references dynamic symbol with nonzero addend"),
2267 name, input_bfd, input_section, rel->r_offset);
2270 dynindx = h->dynindx;
2275 addend += h->root.u.def.value;
2277 addend += sym->st_value;
2279 addend += osec->output_offset;
2280 if (osec && osec->output_section
2281 && ! bfd_is_abs_section (osec->output_section)
2282 && ! bfd_is_und_section (osec->output_section))
2283 dynindx = elf_section_data (osec->output_section)->dynindx;
2288 /* If we're linking an executable at a fixed address, we
2289 can omit the dynamic relocation as long as the symbol
2290 is defined in the current link unit (which is implied
2291 by its output section not being NULL). */
2292 if (info->executable && !info->pie
2293 && (!h || FRVFDPIC_SYM_LOCAL (info, h)))
2296 addend += osec->output_section->vma;
2297 if (IS_FDPIC (input_bfd)
2298 && (bfd_get_section_flags (output_bfd,
2299 input_section->output_section)
2300 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2302 if (_frvfdpic_osec_readonly_p (output_bfd,
2306 info->callbacks->warning
2308 _("cannot emit fixups in read-only section"),
2309 name, input_bfd, input_section, rel->r_offset);
2312 if (!h || h->root.type != bfd_link_hash_undefweak)
2314 _frvfdpic_add_rofixup (output_bfd,
2315 frvfdpic_gotfixup_section
2317 _bfd_elf_section_offset
2319 input_section, rel->r_offset)
2321 ->output_section->vma
2322 + input_section->output_offset,
2324 if (r_type == R_FRV_FUNCDESC_VALUE)
2325 _frvfdpic_add_rofixup
2327 frvfdpic_gotfixup_section (info),
2328 _bfd_elf_section_offset
2330 input_section, rel->r_offset)
2331 + input_section->output_section->vma
2332 + input_section->output_offset + 4, picrel);
2338 if ((bfd_get_section_flags (output_bfd,
2339 input_section->output_section)
2340 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2342 if (_frvfdpic_osec_readonly_p (output_bfd,
2346 info->callbacks->warning
2348 _("cannot emit dynamic relocations in read-only section"),
2349 name, input_bfd, input_section, rel->r_offset);
2352 _frvfdpic_add_dyn_reloc (output_bfd,
2353 frvfdpic_gotrel_section (info),
2354 _bfd_elf_section_offset
2356 input_section, rel->r_offset)
2358 ->output_section->vma
2359 + input_section->output_offset,
2360 r_type, dynindx, addend, picrel);
2363 addend += osec->output_section->vma;
2364 /* We want the addend in-place because dynamic
2365 relocations are REL. Setting relocation to it
2366 should arrange for it to be installed. */
2367 relocation = addend - rel->r_addend;
2370 if (r_type == R_FRV_FUNCDESC_VALUE)
2372 /* If we've omitted the dynamic relocation, just emit
2373 the fixed addresses of the symbol and of the local
2375 if (info->executable && !info->pie
2376 && (!h || FRVFDPIC_SYM_LOCAL (info, h)))
2377 bfd_put_32 (output_bfd,
2378 frvfdpic_got_section (info)->output_section->vma
2379 + frvfdpic_got_section (info)->output_offset
2380 + frvfdpic_got_initial_offset (info),
2381 contents + rel->r_offset + 4);
2383 /* A function descriptor used for lazy or local
2384 resolving is initialized such that its high word
2385 contains the output section index in which the
2386 PLT entries are located, and the low word
2387 contains the offset of the lazy PLT entry entry
2388 point into that section. */
2389 bfd_put_32 (output_bfd,
2390 h && ! FRVFDPIC_SYM_LOCAL (info, h)
2392 : _frvfdpic_osec_to_segment (output_bfd,
2395 contents + rel->r_offset + 4);
2398 check_segment[0] = check_segment[1] = got_segment;
2402 case R_FRV_GPRELU12:
2406 check_segment[0] = gprel_segment;
2407 check_segment[1] = sec
2408 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
2413 check_segment[0] = isec_segment;
2414 check_segment[1] = sec
2415 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
2420 if (check_segment[0] != check_segment[1] && IS_FDPIC (output_bfd))
2422 #if 1 /* If you take this out, remove the #error from fdpic-static-6.d
2423 in the ld testsuite. */
2424 /* This helps catch problems in GCC while we can't do more
2425 than static linking. The idea is to test whether the
2426 input file basename is crt0.o only once. */
2427 if (silence_segment_error == 1)
2428 silence_segment_error =
2429 (strlen (input_bfd->filename) == 6
2430 && strcmp (input_bfd->filename, "crt0.o") == 0)
2431 || (strlen (input_bfd->filename) > 6
2432 && strcmp (input_bfd->filename
2433 + strlen (input_bfd->filename) - 7,
2437 if (!silence_segment_error
2438 /* We don't want duplicate errors for undefined
2440 && !(picrel && picrel->symndx == -1
2441 && picrel->d.h->root.type == bfd_link_hash_undefined))
2442 info->callbacks->warning
2444 (info->shared || info->pie)
2445 ? _("relocations between different segments are not supported")
2446 : _("warning: relocation references a different segment"),
2447 name, input_bfd, input_section, rel->r_offset);
2448 if (!silence_segment_error && (info->shared || info->pie))
2450 elf_elfheader (output_bfd)->e_flags |= EF_FRV_PIC;
2455 case R_FRV_GOTOFFHI:
2456 /* We need the addend to be applied before we shift the
2458 relocation += rel->r_addend;
2461 case R_FRV_FUNCDESC_GOTHI:
2462 case R_FRV_FUNCDESC_GOTOFFHI:
2467 case R_FRV_FUNCDESC_GOTLO:
2468 case R_FRV_GOTOFFLO:
2469 case R_FRV_FUNCDESC_GOTOFFLO:
2470 relocation &= 0xffff;
2480 if (! IS_FDPIC (output_bfd) || ! picrel->plt)
2484 /* When referencing a GOT entry, a function descriptor or a
2485 PLT, we don't want the addend to apply to the reference,
2486 but rather to the referenced symbol. The actual entry
2487 will have already been created taking the addend into
2488 account, so cancel it out here. */
2492 case R_FRV_FUNCDESC_GOT12:
2493 case R_FRV_FUNCDESC_GOTHI:
2494 case R_FRV_FUNCDESC_GOTLO:
2495 case R_FRV_FUNCDESC_GOTOFF12:
2496 case R_FRV_FUNCDESC_GOTOFFHI:
2497 case R_FRV_FUNCDESC_GOTOFFLO:
2498 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
2499 here, since we do want to apply the addend to the others.
2500 Note that we've applied the addend to GOTOFFHI before we
2501 shifted it right. */
2502 case R_FRV_GOTOFFHI:
2503 relocation -= rel->r_addend;
2510 if (r_type == R_FRV_HI16)
2511 r = elf32_frv_relocate_hi16 (input_bfd, rel, contents, relocation);
2513 else if (r_type == R_FRV_LO16)
2514 r = elf32_frv_relocate_lo16 (input_bfd, rel, contents, relocation);
2516 else if (r_type == R_FRV_LABEL24)
2517 r = elf32_frv_relocate_label24 (input_bfd, input_section, rel,
2518 contents, relocation);
2520 else if (r_type == R_FRV_GPREL12)
2521 r = elf32_frv_relocate_gprel12 (info, input_bfd, input_section, rel,
2522 contents, relocation);
2524 else if (r_type == R_FRV_GPRELU12)
2525 r = elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, rel,
2526 contents, relocation);
2528 else if (r_type == R_FRV_GPRELLO)
2529 r = elf32_frv_relocate_gprello (info, input_bfd, input_section, rel,
2530 contents, relocation);
2532 else if (r_type == R_FRV_GPRELHI)
2533 r = elf32_frv_relocate_gprelhi (info, input_bfd, input_section, rel,
2534 contents, relocation);
2537 r = frv_final_link_relocate (howto, input_bfd, input_section, contents,
2540 if (r != bfd_reloc_ok)
2542 const char * msg = (const char *) NULL;
2546 case bfd_reloc_overflow:
2547 r = info->callbacks->reloc_overflow
2548 (info, name, howto->name, (bfd_vma) 0,
2549 input_bfd, input_section, rel->r_offset);
2552 case bfd_reloc_undefined:
2553 r = info->callbacks->undefined_symbol
2554 (info, name, input_bfd, input_section, rel->r_offset, TRUE);
2557 case bfd_reloc_outofrange:
2558 msg = _("internal error: out of range error");
2561 case bfd_reloc_notsupported:
2562 msg = _("internal error: unsupported relocation error");
2565 case bfd_reloc_dangerous:
2566 msg = _("internal error: dangerous relocation");
2570 msg = _("internal error: unknown error");
2575 r = info->callbacks->warning
2576 (info, msg, name, input_bfd, input_section, rel->r_offset);
2586 /* Return the section that should be marked against GC for a given
2590 elf32_frv_gc_mark_hook (sec, info, rel, h, sym)
2592 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2593 Elf_Internal_Rela *rel;
2594 struct elf_link_hash_entry *h;
2595 Elf_Internal_Sym *sym;
2599 switch (ELF32_R_TYPE (rel->r_info))
2601 case R_FRV_GNU_VTINHERIT:
2602 case R_FRV_GNU_VTENTRY:
2606 switch (h->root.type)
2611 case bfd_link_hash_defined:
2612 case bfd_link_hash_defweak:
2613 return h->root.u.def.section;
2615 case bfd_link_hash_common:
2616 return h->root.u.c.p->section;
2621 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
2626 /* Update the got entry reference counts for the section being removed. */
2629 elf32_frv_gc_sweep_hook (abfd, info, sec, relocs)
2630 bfd *abfd ATTRIBUTE_UNUSED;
2631 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2632 asection *sec ATTRIBUTE_UNUSED;
2633 const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
2639 /* Hook called by the linker routine which adds symbols from an object
2640 file. We use it to put .comm items in .scomm, and not .comm. */
2643 elf32_frv_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
2645 struct bfd_link_info *info;
2646 Elf_Internal_Sym *sym;
2647 const char **namep ATTRIBUTE_UNUSED;
2648 flagword *flagsp ATTRIBUTE_UNUSED;
2652 if (sym->st_shndx == SHN_COMMON
2653 && !info->relocatable
2654 && (int)sym->st_size <= (int)bfd_get_gp_size (abfd))
2656 /* Common symbols less than or equal to -G nn bytes are
2657 automatically put into .sbss. */
2659 asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
2663 scomm = bfd_make_section (abfd, ".scommon");
2665 || !bfd_set_section_flags (abfd, scomm, (SEC_ALLOC
2667 | SEC_LINKER_CREATED)))
2672 *valp = sym->st_size;
2678 /* We need dynamic symbols for every section, since segments can
2679 relocate independently. */
2681 _frvfdpic_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED,
2682 struct bfd_link_info *info
2684 asection *p ATTRIBUTE_UNUSED)
2686 switch (elf_section_data (p)->this_hdr.sh_type)
2690 /* If sh_type is yet undecided, assume it could be
2691 SHT_PROGBITS/SHT_NOBITS. */
2695 /* There shouldn't be section relative relocations
2696 against any other section. */
2702 /* Create a .got section, as well as its additional info field. This
2703 is almost entirely copied from
2704 elflink.c:_bfd_elf_create_got_section(). */
2707 _frv_create_got_section (bfd *abfd, struct bfd_link_info *info)
2711 struct elf_link_hash_entry *h;
2712 struct bfd_link_hash_entry *bh;
2713 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2717 /* This function may be called more than once. */
2718 s = bfd_get_section_by_name (abfd, ".got");
2719 if (s != NULL && (s->flags & SEC_LINKER_CREATED) != 0)
2722 /* Machine specific: although pointers are 32-bits wide, we want the
2723 GOT to be aligned to a 64-bit boundary, such that function
2724 descriptors in it can be accessed with 64-bit loads and
2728 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2729 | SEC_LINKER_CREATED);
2731 s = bfd_make_section (abfd, ".got");
2733 || !bfd_set_section_flags (abfd, s, flags)
2734 || !bfd_set_section_alignment (abfd, s, ptralign))
2737 if (bed->want_got_plt)
2739 s = bfd_make_section (abfd, ".got.plt");
2741 || !bfd_set_section_flags (abfd, s, flags)
2742 || !bfd_set_section_alignment (abfd, s, ptralign))
2746 if (bed->want_got_sym)
2748 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
2749 (or .got.plt) section. We don't do this in the linker script
2750 because we don't want to define the symbol if we are not creating
2751 a global offset table. */
2753 if (!(_bfd_generic_link_add_one_symbol
2754 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
2755 bed->got_symbol_offset, (const char *) NULL, FALSE,
2756 bed->collect, &bh)))
2758 h = (struct elf_link_hash_entry *) bh;
2759 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2760 h->type = STT_OBJECT;
2762 /* Machine-specific: we want the symbol for executables as
2764 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2767 elf_hash_table (info)->hgot = h;
2770 /* The first bit of the global offset table is the header. */
2771 s->size += bed->got_header_size + bed->got_symbol_offset;
2773 /* This is the machine-specific part. Create and initialize section
2774 data for the got. */
2775 if (IS_FDPIC (abfd))
2777 frvfdpic_got_section (info) = s;
2778 frvfdpic_relocs_info (info) = htab_try_create (1, frvfdpic_relocs_info_hash,
2779 frvfdpic_relocs_info_eq,
2781 if (! frvfdpic_relocs_info (info))
2784 s = bfd_make_section (abfd, ".rel.got");
2786 || ! bfd_set_section_flags (abfd, s, (flags | SEC_READONLY))
2787 || ! bfd_set_section_alignment (abfd, s, 2))
2790 frvfdpic_gotrel_section (info) = s;
2792 /* Machine-specific. */
2793 s = bfd_make_section (abfd, ".rofixup");
2795 || ! bfd_set_section_flags (abfd, s, (flags | SEC_READONLY))
2796 || ! bfd_set_section_alignment (abfd, s, 2))
2799 frvfdpic_gotfixup_section (info) = s;
2806 flags = BSF_GLOBAL | BSF_WEAK;
2809 /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it
2810 turns out that we're linking with a different linker script, the
2811 linker script will override it. */
2813 if (!(_bfd_generic_link_add_one_symbol
2814 (info, abfd, "_gp", flags, s, offset, (const char *) NULL, FALSE,
2815 bed->collect, &bh)))
2817 h = (struct elf_link_hash_entry *) bh;
2818 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2819 h->type = STT_OBJECT;
2821 /* Machine-specific: we want the symbol for executables as well. */
2822 if (IS_FDPIC (abfd) && ! bfd_elf_link_record_dynamic_symbol (info, h))
2828 /* Make sure the got and plt sections exist, and that our pointers in
2829 the link hash table point to them. */
2832 elf32_frvfdpic_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
2834 /* This is mostly copied from
2835 elflink.c:_bfd_elf_create_dynamic_sections(). */
2836 flagword flags, pltflags;
2838 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2840 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
2841 .rel[a].bss sections. */
2843 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2844 | SEC_LINKER_CREATED);
2847 pltflags |= SEC_CODE;
2848 if (bed->plt_not_loaded)
2849 pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS);
2850 if (bed->plt_readonly)
2851 pltflags |= SEC_READONLY;
2853 s = bfd_make_section (abfd, ".plt");
2855 || ! bfd_set_section_flags (abfd, s, pltflags)
2856 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
2858 /* FRV-specific: remember it. */
2859 frvfdpic_plt_section (info) = s;
2861 if (bed->want_plt_sym)
2863 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
2865 struct elf_link_hash_entry *h;
2866 struct bfd_link_hash_entry *bh = NULL;
2868 if (! (_bfd_generic_link_add_one_symbol
2869 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s, 0, NULL,
2870 FALSE, get_elf_backend_data (abfd)->collect, &bh)))
2872 h = (struct elf_link_hash_entry *) bh;
2873 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2874 h->type = STT_OBJECT;
2876 if (! info->executable
2877 && ! bfd_elf_link_record_dynamic_symbol (info, h))
2881 /* FRV-specific: we want rel relocations for the plt. */
2882 s = bfd_make_section (abfd, ".rel.plt");
2884 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
2885 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
2887 /* FRV-specific: remember it. */
2888 frvfdpic_pltrel_section (info) = s;
2890 /* FRV-specific: we want to create the GOT in the FRV way. */
2891 if (! _frv_create_got_section (abfd, info))
2894 /* FRV-specific: make sure we created everything we wanted. */
2895 BFD_ASSERT (frvfdpic_got_section (info) && frvfdpic_gotrel_section (info)
2896 && frvfdpic_gotfixup_section (info)
2897 && frvfdpic_plt_section (info)
2898 && frvfdpic_pltrel_section (info));
2900 if (bed->want_dynbss)
2902 /* The .dynbss section is a place to put symbols which are defined
2903 by dynamic objects, are referenced by regular objects, and are
2904 not functions. We must allocate space for them in the process
2905 image and use a R_*_COPY reloc to tell the dynamic linker to
2906 initialize them at run time. The linker script puts the .dynbss
2907 section into the .bss section of the final image. */
2908 s = bfd_make_section (abfd, ".dynbss");
2910 || ! bfd_set_section_flags (abfd, s, SEC_ALLOC | SEC_LINKER_CREATED))
2913 /* The .rel[a].bss section holds copy relocs. This section is not
2914 normally needed. We need to create it here, though, so that the
2915 linker will map it to an output section. We can't just create it
2916 only if we need it, because we will not know whether we need it
2917 until we have seen all the input files, and the first time the
2918 main linker code calls BFD after examining all the input files
2919 (size_dynamic_sections) the input sections have already been
2920 mapped to the output sections. If the section turns out not to
2921 be needed, we can discard it later. We will never need this
2922 section when generating a shared object, since they do not use
2926 s = bfd_make_section (abfd,
2927 (bed->default_use_rela_p
2928 ? ".rela.bss" : ".rel.bss"));
2930 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
2931 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
2939 /* The name of the dynamic interpreter. This is put in the .interp
2942 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
2944 #define DEFAULT_STACK_SIZE 0x20000
2946 /* This structure is used to collect the number of entries present in
2947 each addressable range of the got. */
2948 struct _frvfdpic_dynamic_got_info
2950 /* Several bits of information about the current link. */
2951 struct bfd_link_info *info;
2952 /* Total size needed for GOT entries within the 12-, 16- or 32-bit
2954 bfd_vma got12, gotlos, gothilo;
2955 /* Total size needed for function descriptor entries within the 12-,
2956 16- or 32-bit ranges. */
2957 bfd_vma fd12, fdlos, fdhilo;
2958 /* Total size needed function descriptor entries referenced in PLT
2959 entries, that would be profitable to place in offsets close to
2960 the PIC register. */
2962 /* Total size needed by lazy PLT entries. */
2964 /* Number of relocations carried over from input object files. */
2965 unsigned long relocs;
2966 /* Number of fixups introduced by relocations in input object files. */
2967 unsigned long fixups;
2970 /* Compute the total GOT size required by each symbol in each range.
2971 Symbols may require up to 4 words in the GOT: an entry pointing to
2972 the symbol, an entry pointing to its function descriptor, and a
2973 private function descriptors taking two words. */
2976 _frvfdpic_count_got_plt_entries (void **entryp, void *dinfo_)
2978 struct frvfdpic_relocs_info *entry = *entryp;
2979 struct _frvfdpic_dynamic_got_info *dinfo = dinfo_;
2980 unsigned relocs = 0, fixups = 0;
2982 /* Allocate space for a GOT entry pointing to the symbol. */
2985 else if (entry->gotlos)
2987 else if (entry->gothilo)
2988 dinfo->gothilo += 4;
2993 /* Allocate space for a GOT entry pointing to the function
2997 else if (entry->fdgotlos)
2999 else if (entry->fdgothilo)
3000 dinfo->gothilo += 4;
3005 /* Decide whether we need a PLT entry, a function descriptor in the
3006 GOT, and a lazy PLT entry for this symbol. */
3007 entry->plt = entry->call
3008 && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
3009 && elf_hash_table (dinfo->info)->dynamic_sections_created;
3010 entry->privfd = entry->plt
3011 || entry->fdgoff12 || entry->fdgofflos || entry->fdgoffhilo
3012 || ((entry->fd || entry->fdgot12 || entry->fdgotlos || entry->fdgothilo)
3013 && (entry->symndx != -1
3014 || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h)));
3015 entry->lazyplt = entry->privfd
3016 && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
3017 && ! (dinfo->info->flags & DF_BIND_NOW)
3018 && elf_hash_table (dinfo->info)->dynamic_sections_created;
3020 /* Allocate space for a function descriptor. */
3021 if (entry->fdgoff12)
3023 else if (entry->fdgofflos)
3025 else if (entry->privfd && entry->plt)
3027 else if (entry->privfd)
3036 if (!dinfo->info->executable || dinfo->info->pie)
3037 relocs = entry->relocs32 + entry->relocsfd + entry->relocsfdv;
3040 if (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h))
3042 if (entry->symndx != -1
3043 || entry->d.h->root.type != bfd_link_hash_undefweak)
3044 fixups += entry->relocs32 + 2 * entry->relocsfdv;
3047 relocs += entry->relocs32 + entry->relocsfdv;
3049 if (entry->symndx != -1
3050 || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h))
3052 if (entry->symndx != -1
3053 || entry->d.h->root.type != bfd_link_hash_undefweak)
3054 fixups += entry->relocsfd;
3057 relocs += entry->relocsfd;
3060 entry->dynrelocs += relocs;
3061 entry->fixups += fixups;
3062 dinfo->relocs += relocs;
3063 dinfo->fixups += fixups;
3068 /* This structure is used to assign offsets to got entries, function
3069 descriptors, plt entries and lazy plt entries. */
3071 struct _frvfdpic_dynamic_got_plt_info
3073 /* Summary information collected with _frvfdpic_count_got_plt_entries. */
3074 struct _frvfdpic_dynamic_got_info g;
3076 /* For each addressable range, we record a MAX (positive) and MIN
3077 (negative) value. CUR is used to assign got entries, and it's
3078 incremented from an initial positive value to MAX, then from MIN
3079 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
3080 assign function descriptors, and it's decreased from an initial
3081 non-positive value to MIN, then from MAX down to CUR (unless CUR
3082 wraps around first). All of MIN, MAX, CUR and FDCUR always point
3083 to even words. ODD, if non-zero, indicates an odd word to be
3084 used for the next got entry, otherwise CUR is used and
3085 incremented by a pair of words, wrapping around when it reaches
3086 MAX. FDCUR is decremented (and wrapped) before the next function
3087 descriptor is chosen. FDPLT indicates the number of remaining
3088 slots that can be used for function descriptors used only by PLT
3090 struct _frvfdpic_dynamic_got_alloc_data
3092 bfd_signed_vma max, cur, odd, fdcur, min;
3094 } got12, gotlos, gothilo;
3097 /* Determine the positive and negative ranges to be used by each
3098 offset range in the GOT. FDCUR and CUR, that must be aligned to a
3099 double-word boundary, are the minimum (negative) and maximum
3100 (positive) GOT offsets already used by previous ranges, except for
3101 an ODD entry that may have been left behind. GOT and FD indicate
3102 the size of GOT entries and function descriptors that must be
3103 placed within the range from -WRAP to WRAP. If there's room left,
3104 up to FDPLT bytes should be reserved for additional function
3107 inline static bfd_signed_vma
3108 _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data *gad,
3109 bfd_signed_vma fdcur,
3117 bfd_signed_vma wrapmin = -wrap;
3119 /* Start at the given initial points. */
3123 /* If we had an incoming odd word and we have any got entries that
3124 are going to use it, consume it, otherwise leave gad->odd at
3125 zero. We might force gad->odd to zero and return the incoming
3126 odd such that it is used by the next range, but then GOT entries
3127 might appear to be out of order and we wouldn't be able to
3128 shorten the GOT by one word if it turns out to end with an
3129 unpaired GOT entry. */
3139 /* If we're left with an unpaired GOT entry, compute its location
3140 such that we can return it. Otherwise, if got doesn't require an
3141 odd number of words here, either odd was already zero in the
3142 block above, or it was set to zero because got was non-zero, or
3143 got was already zero. In the latter case, we want the value of
3144 odd to carry over to the return statement, so we don't want to
3145 reset odd unless the condition below is true. */
3152 /* Compute the tentative boundaries of this range. */
3153 gad->max = cur + got;
3154 gad->min = fdcur - fd;
3157 /* If function descriptors took too much space, wrap some of them
3159 if (gad->min < wrapmin)
3161 gad->max += wrapmin - gad->min;
3164 /* If there is space left and we have function descriptors
3165 referenced in PLT entries that could take advantage of shorter
3166 offsets, place them here. */
3167 else if (fdplt && gad->min > wrapmin)
3170 if ((bfd_vma) (gad->min - wrapmin) < fdplt)
3171 fds = gad->min - wrapmin;
3180 /* If GOT entries took too much space, wrap some of them around.
3181 This may well cause gad->min to become lower than wrapmin. This
3182 will cause a relocation overflow later on, so we don't have to
3184 if ((bfd_vma) gad->max > wrap)
3186 gad->min -= gad->max - wrap;
3189 /* If there is more space left, try to place some more function
3190 descriptors for PLT entries. */
3191 else if (fdplt && (bfd_vma) gad->max < wrap)
3194 if ((bfd_vma) (wrap - gad->max) < fdplt)
3195 fds = wrap - gad->max;
3204 /* If odd was initially computed as an offset past the wrap point,
3207 odd = gad->min + odd - gad->max;
3209 /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed
3210 before returning, so do it here too. This guarantees that,
3211 should cur and fdcur meet at the wrap point, they'll both be
3213 if (gad->cur == gad->max)
3214 gad->cur = gad->min;
3219 /* Compute the location of the next GOT entry, given the allocation
3220 data for a range. */
3222 inline static bfd_signed_vma
3223 _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
3229 /* If there was an odd word left behind, use it. */
3235 /* Otherwise, use the word pointed to by cur, reserve the next
3236 as an odd word, and skip to the next pair of words, possibly
3239 gad->odd = gad->cur + 4;
3241 if (gad->cur == gad->max)
3242 gad->cur = gad->min;
3248 /* Compute the location of the next function descriptor entry in the
3249 GOT, given the allocation data for a range. */
3251 inline static bfd_signed_vma
3252 _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
3254 /* If we're at the bottom, wrap around, and only then allocate the
3255 next pair of words. */
3256 if (gad->fdcur == gad->min)
3257 gad->fdcur = gad->max;
3258 return gad->fdcur -= 8;
3261 /* Assign GOT offsets for every GOT entry and function descriptor.
3262 Doing everything in a single pass is tricky. */
3265 _frvfdpic_assign_got_entries (void **entryp, void *info_)
3267 struct frvfdpic_relocs_info *entry = *entryp;
3268 struct _frvfdpic_dynamic_got_plt_info *dinfo = info_;
3271 entry->got_entry = _frvfdpic_get_got_entry (&dinfo->got12);
3272 else if (entry->gotlos)
3273 entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
3274 else if (entry->gothilo)
3275 entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
3278 entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->got12);
3279 else if (entry->fdgotlos)
3280 entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
3281 else if (entry->fdgothilo)
3282 entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
3284 if (entry->fdgoff12)
3285 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12);
3286 else if (entry->plt && dinfo->got12.fdplt)
3288 dinfo->got12.fdplt -= 8;
3289 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12);
3291 else if (entry->fdgofflos)
3292 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos);
3293 else if (entry->plt && dinfo->gotlos.fdplt)
3295 dinfo->gotlos.fdplt -= 8;
3296 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos);
3298 else if (entry->plt)
3300 dinfo->gothilo.fdplt -= 8;
3301 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo);
3303 else if (entry->privfd)
3304 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo);
3309 /* Assign GOT offsets to private function descriptors used by PLT
3310 entries (or referenced by 32-bit offsets), as well as PLT entries
3311 and lazy PLT entries. */
3314 _frvfdpic_assign_plt_entries (void **entryp, void *info_)
3316 struct frvfdpic_relocs_info *entry = *entryp;
3317 struct _frvfdpic_dynamic_got_plt_info *dinfo = info_;
3319 /* If this symbol requires a local function descriptor, allocate
3321 if (entry->privfd && entry->fd_entry == 0)
3323 if (dinfo->got12.fdplt)
3325 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12);
3326 dinfo->got12.fdplt -= 8;
3328 else if (dinfo->gotlos.fdplt)
3330 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos);
3331 dinfo->gotlos.fdplt -= 8;
3335 BFD_ASSERT (dinfo->gothilo.fdplt)
3336 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo);
3337 dinfo->gothilo.fdplt -= 8;
3345 /* We use the section's raw size to mark the location of the
3347 entry->plt_entry = frvfdpic_plt_section (dinfo->g.info)->size;
3349 /* Figure out the length of this PLT entry based on the
3350 addressing mode we need to reach the function descriptor. */
3351 BFD_ASSERT (entry->fd_entry);
3352 if (entry->fd_entry >= -(1 << (12 - 1))
3353 && entry->fd_entry < (1 << (12 - 1)))
3355 else if (entry->fd_entry >= -(1 << (16 - 1))
3356 && entry->fd_entry < (1 << (16 - 1)))
3361 frvfdpic_plt_section (dinfo->g.info)->size += size;
3366 entry->lzplt_entry = dinfo->g.lzplt;
3367 dinfo->g.lzplt += 8;
3368 /* If this entry is the one that gets the resolver stub, account
3369 for the additional instruction. */
3370 if (entry->lzplt_entry % FRVFDPIC_LZPLT_BLOCK_SIZE
3371 == FRVFDPIC_LZPLT_RESOLV_LOC)
3372 dinfo->g.lzplt += 4;
3378 /* Follow indirect and warning hash entries so that each got entry
3379 points to the final symbol definition. P must point to a pointer
3380 to the hash table we're traversing. Since this traversal may
3381 modify the hash table, we set this pointer to NULL to indicate
3382 we've made a potentially-destructive change to the hash table, so
3383 the traversal must be restarted. */
3385 _frvfdpic_resolve_final_relocs_info (void **entryp, void *p)
3387 struct frvfdpic_relocs_info *entry = *entryp;
3390 if (entry->symndx == -1)
3392 struct elf_link_hash_entry *h = entry->d.h;
3393 struct frvfdpic_relocs_info *oentry;
3395 while (h->root.type == bfd_link_hash_indirect
3396 || h->root.type == bfd_link_hash_warning)
3397 h = (struct elf_link_hash_entry *)h->root.u.i.link;
3399 if (entry->d.h == h)
3402 oentry = frvfdpic_relocs_info_for_global (*htab, 0, h, entry->addend,
3407 /* Merge the two entries. */
3408 frvfdpic_pic_merge_early_relocs_info (oentry, entry);
3409 htab_clear_slot (*htab, entryp);
3415 /* If we can't find this entry with the new bfd hash, re-insert
3416 it, and get the traversal restarted. */
3417 if (! htab_find (*htab, entry))
3419 htab_clear_slot (*htab, entryp);
3420 entryp = htab_find_slot (*htab, entry, INSERT);
3423 /* Abort the traversal, since the whole table may have
3424 moved, and leave it up to the parent to restart the
3426 *(htab_t *)p = NULL;
3434 /* Set the sizes of the dynamic sections. */
3437 elf32_frvfdpic_size_dynamic_sections (bfd *output_bfd,
3438 struct bfd_link_info *info)
3442 struct _frvfdpic_dynamic_got_plt_info gpinfo;
3446 dynobj = elf_hash_table (info)->dynobj;
3447 BFD_ASSERT (dynobj != NULL);
3449 if (elf_hash_table (info)->dynamic_sections_created)
3451 /* Set the contents of the .interp section to the interpreter. */
3452 if (info->executable)
3454 s = bfd_get_section_by_name (dynobj, ".interp");
3455 BFD_ASSERT (s != NULL);
3456 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
3457 s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
3461 memset (&gpinfo, 0, sizeof (gpinfo));
3462 gpinfo.g.info = info;
3466 htab_t relocs = frvfdpic_relocs_info (info);
3468 htab_traverse (relocs, _frvfdpic_resolve_final_relocs_info, &relocs);
3470 if (relocs == frvfdpic_relocs_info (info))
3474 htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_count_got_plt_entries,
3478 /* Compute the total size taken by entries in the 12-bit and 16-bit
3479 ranges, to tell how many PLT function descriptors we can bring
3480 into the 12-bit range without causing the 16-bit range to
3482 limit = odd + gpinfo.g.got12 + gpinfo.g.gotlos
3483 + gpinfo.g.fd12 + gpinfo.g.fdlos;
3484 if (limit < (bfd_vma)1 << 16)
3485 limit = ((bfd_vma)1 << 16) - limit;
3488 if (gpinfo.g.fdplt < limit)
3489 limit = gpinfo.g.fdplt;
3491 /* Determine the ranges of GOT offsets that we can use for each
3492 range of addressing modes. */
3493 odd = _frvfdpic_compute_got_alloc_data (&gpinfo.got12,
3500 (bfd_vma)1 << (12-1));
3501 odd = _frvfdpic_compute_got_alloc_data (&gpinfo.gotlos,
3507 gpinfo.g.fdplt - gpinfo.got12.fdplt,
3508 (bfd_vma)1 << (16-1));
3509 odd = _frvfdpic_compute_got_alloc_data (&gpinfo.gothilo,
3515 gpinfo.g.fdplt - gpinfo.got12.fdplt
3516 - gpinfo.gotlos.fdplt,
3517 (bfd_vma)1 << (32-1));
3519 /* Now assign (most) GOT offsets. */
3520 htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_got_entries,
3523 frvfdpic_got_section (info)->size = gpinfo.gothilo.max
3524 - gpinfo.gothilo.min
3525 /* If an odd word is the last word of the GOT, we don't need this
3526 word to be part of the GOT. */
3527 - (odd + 4 == gpinfo.gothilo.max ? 4 : 0);
3528 if (frvfdpic_got_section (info)->size == 0)
3529 frvfdpic_got_section (info)->flags |= SEC_EXCLUDE;
3530 else if (frvfdpic_got_section (info)->size == 12
3531 && ! elf_hash_table (info)->dynamic_sections_created)
3533 frvfdpic_got_section (info)->flags |= SEC_EXCLUDE;
3534 frvfdpic_got_section (info)->size = 0;
3538 frvfdpic_got_section (info)->contents =
3539 (bfd_byte *) bfd_zalloc (dynobj,
3540 frvfdpic_got_section (info)->size);
3541 if (frvfdpic_got_section (info)->contents == NULL)
3545 if (elf_hash_table (info)->dynamic_sections_created)
3546 /* Subtract the number of lzplt entries, since those will generate
3547 relocations in the pltrel section. */
3548 frvfdpic_gotrel_section (info)->size =
3549 (gpinfo.g.relocs - gpinfo.g.lzplt / 8)
3550 * get_elf_backend_data (output_bfd)->s->sizeof_rel;
3552 BFD_ASSERT (gpinfo.g.relocs == 0);
3553 if (frvfdpic_gotrel_section (info)->size == 0)
3554 frvfdpic_gotrel_section (info)->flags |= SEC_EXCLUDE;
3557 frvfdpic_gotrel_section (info)->contents =
3558 (bfd_byte *) bfd_zalloc (dynobj,
3559 frvfdpic_gotrel_section (info)->size);
3560 if (frvfdpic_gotrel_section (info)->contents == NULL)
3564 frvfdpic_gotfixup_section (info)->size = (gpinfo.g.fixups + 1) * 4;
3565 if (frvfdpic_gotfixup_section (info)->size == 0)
3566 frvfdpic_gotfixup_section (info)->flags |= SEC_EXCLUDE;
3569 frvfdpic_gotfixup_section (info)->contents =
3570 (bfd_byte *) bfd_zalloc (dynobj,
3571 frvfdpic_gotfixup_section (info)->size);
3572 if (frvfdpic_gotfixup_section (info)->contents == NULL)
3576 if (elf_hash_table (info)->dynamic_sections_created)
3578 frvfdpic_pltrel_section (info)->size =
3579 gpinfo.g.lzplt / 8 * get_elf_backend_data (output_bfd)->s->sizeof_rel;
3580 if (frvfdpic_pltrel_section (info)->size == 0)
3581 frvfdpic_pltrel_section (info)->flags |= SEC_EXCLUDE;
3584 frvfdpic_pltrel_section (info)->contents =
3585 (bfd_byte *) bfd_zalloc (dynobj,
3586 frvfdpic_pltrel_section (info)->size);
3587 if (frvfdpic_pltrel_section (info)->contents == NULL)
3592 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
3593 such that there's room for the additional instruction needed to
3594 call the resolver. Since _frvfdpic_assign_got_entries didn't
3595 account for them, our block size is 4 bytes smaller than the real
3597 if (elf_hash_table (info)->dynamic_sections_created)
3599 frvfdpic_plt_section (info)->size = gpinfo.g.lzplt
3600 + ((gpinfo.g.lzplt + (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) - 8)
3601 / (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) * 4);
3604 /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to
3605 actually assign lazy PLT entries addresses. */
3608 /* Save information that we're going to need to generate GOT and PLT
3610 frvfdpic_got_initial_offset (info) = -gpinfo.gothilo.min;
3612 if (get_elf_backend_data (output_bfd)->want_got_sym)
3613 elf_hash_table (info)->hgot->root.u.def.value
3614 += frvfdpic_got_initial_offset (info);
3616 if (elf_hash_table (info)->dynamic_sections_created)
3617 frvfdpic_plt_initial_offset (info) =
3618 frvfdpic_plt_section (info)->size;
3620 htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_plt_entries,
3623 /* Allocate the PLT section contents only after
3624 _frvfdpic_assign_plt_entries has a chance to add the size of the
3625 non-lazy PLT entries. */
3626 if (elf_hash_table (info)->dynamic_sections_created)
3628 if (frvfdpic_plt_section (info)->size == 0)
3629 frvfdpic_plt_section (info)->flags |= SEC_EXCLUDE;
3632 frvfdpic_plt_section (info)->contents =
3633 (bfd_byte *) bfd_zalloc (dynobj,
3634 frvfdpic_plt_section (info)->size);
3635 if (frvfdpic_plt_section (info)->contents == NULL)
3640 if (elf_hash_table (info)->dynamic_sections_created)
3642 if (frvfdpic_got_section (info)->size)
3643 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0))
3646 if (frvfdpic_pltrel_section (info)->size)
3647 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
3648 || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_REL)
3649 || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
3652 if (frvfdpic_gotrel_section (info)->size)
3653 if (!_bfd_elf_add_dynamic_entry (info, DT_REL, 0)
3654 || !_bfd_elf_add_dynamic_entry (info, DT_RELSZ, 0)
3655 || !_bfd_elf_add_dynamic_entry (info, DT_RELENT,
3656 sizeof (Elf32_External_Rel)))
3664 elf32_frvfdpic_always_size_sections (bfd *output_bfd,
3665 struct bfd_link_info *info)
3667 if (!info->relocatable)
3669 struct elf_link_hash_entry *h;
3672 /* Force a PT_GNU_STACK segment to be created. */
3673 if (! elf_tdata (output_bfd)->stack_flags)
3674 elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
3676 /* Define __stacksize if it's not defined yet. */
3677 h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize",
3678 FALSE, FALSE, FALSE);
3679 if (! h || h->root.type != bfd_link_hash_defined
3680 || h->type != STT_OBJECT
3681 || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
3683 struct bfd_link_hash_entry *bh = NULL;
3685 if (!(_bfd_generic_link_add_one_symbol
3686 (info, output_bfd, "__stacksize",
3687 BSF_GLOBAL, bfd_abs_section_ptr, DEFAULT_STACK_SIZE,
3688 (const char *) NULL, FALSE,
3689 get_elf_backend_data (output_bfd)->collect, &bh)))
3692 h = (struct elf_link_hash_entry *) bh;
3693 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3694 h->type = STT_OBJECT;
3697 /* Create a stack section, and set its alignment. */
3698 sec = bfd_make_section (output_bfd, ".stack");
3701 || ! bfd_set_section_alignment (output_bfd, sec, 3))
3709 elf32_frvfdpic_modify_segment_map (bfd *output_bfd,
3710 struct bfd_link_info *info)
3712 struct elf_segment_map *m;
3714 /* objcopy and strip preserve what's already there using
3715 elf32_frvfdpic_copy_private_bfd_data (). */
3719 for (m = elf_tdata (output_bfd)->segment_map; m != NULL; m = m->next)
3720 if (m->p_type == PT_GNU_STACK)
3725 asection *sec = bfd_get_section_by_name (output_bfd, ".stack");
3726 struct elf_link_hash_entry *h;
3730 /* Obtain the pointer to the __stacksize symbol. */
3731 h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize",
3732 FALSE, FALSE, FALSE);
3733 while (h->root.type == bfd_link_hash_indirect
3734 || h->root.type == bfd_link_hash_warning)
3735 h = (struct elf_link_hash_entry *)h->root.u.i.link;
3736 BFD_ASSERT (h->root.type == bfd_link_hash_defined);
3738 /* Set the section size from the symbol value. We
3739 intentionally ignore the symbol section. */
3740 if (h->root.type == bfd_link_hash_defined)
3741 sec->size = h->root.u.def.value;
3743 sec->size = DEFAULT_STACK_SIZE;
3745 /* Add the stack section to the PT_GNU_STACK segment,
3746 such that its size and alignment requirements make it
3748 m->sections[m->count] = sec;
3756 /* Fill in code and data in dynamic sections. */
3759 elf32_frv_finish_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
3760 struct bfd_link_info *info ATTRIBUTE_UNUSED)
3762 /* Nothing to be done for non-FDPIC. */
3767 elf32_frvfdpic_finish_dynamic_sections (bfd *output_bfd,
3768 struct bfd_link_info *info)
3773 dynobj = elf_hash_table (info)->dynobj;
3775 if (frvfdpic_got_section (info))
3777 BFD_ASSERT (frvfdpic_gotrel_section (info)->size
3778 == (frvfdpic_gotrel_section (info)->reloc_count
3779 * sizeof (Elf32_External_Rel)));
3781 if (frvfdpic_gotfixup_section (info))
3783 struct elf_link_hash_entry *hgot = elf_hash_table (info)->hgot;
3784 bfd_vma got_value = hgot->root.u.def.value
3785 + hgot->root.u.def.section->output_section->vma
3786 + hgot->root.u.def.section->output_offset;
3788 _frvfdpic_add_rofixup (output_bfd, frvfdpic_gotfixup_section (info),
3791 if (frvfdpic_gotfixup_section (info)->size
3792 != (frvfdpic_gotfixup_section (info)->reloc_count * 4))
3794 (*_bfd_error_handler)
3795 ("LINKER BUG: .rofixup section size mismatch");
3800 if (elf_hash_table (info)->dynamic_sections_created)
3802 BFD_ASSERT (frvfdpic_pltrel_section (info)->size
3803 == (frvfdpic_pltrel_section (info)->reloc_count
3804 * sizeof (Elf32_External_Rel)));
3807 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3809 if (elf_hash_table (info)->dynamic_sections_created)
3811 Elf32_External_Dyn * dyncon;
3812 Elf32_External_Dyn * dynconend;
3814 BFD_ASSERT (sdyn != NULL);
3816 dyncon = (Elf32_External_Dyn *) sdyn->contents;
3817 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
3819 for (; dyncon < dynconend; dyncon++)
3821 Elf_Internal_Dyn dyn;
3823 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
3831 dyn.d_un.d_ptr = frvfdpic_got_section (info)->output_section->vma
3832 + frvfdpic_got_section (info)->output_offset
3833 + frvfdpic_got_initial_offset (info);
3834 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3838 dyn.d_un.d_ptr = frvfdpic_pltrel_section (info)
3839 ->output_section->vma
3840 + frvfdpic_pltrel_section (info)->output_offset;
3841 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3845 dyn.d_un.d_val = frvfdpic_pltrel_section (info)->size;
3846 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3855 /* Adjust a symbol defined by a dynamic object and referenced by a
3859 elf32_frvfdpic_adjust_dynamic_symbol
3860 (struct bfd_link_info *info ATTRIBUTE_UNUSED,
3861 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
3865 dynobj = elf_hash_table (info)->dynobj;
3867 /* Make sure we know what is going on here. */
3868 BFD_ASSERT (dynobj != NULL
3869 && (h->weakdef != NULL
3870 || ((h->elf_link_hash_flags
3871 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3872 && (h->elf_link_hash_flags
3873 & ELF_LINK_HASH_REF_REGULAR) != 0
3874 && (h->elf_link_hash_flags
3875 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
3877 /* If this is a weak symbol, and there is a real definition, the
3878 processor independent code will have arranged for us to see the
3879 real definition first, and we can just use the same value. */
3880 if (h->weakdef != NULL)
3882 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
3883 || h->weakdef->root.type == bfd_link_hash_defweak);
3884 h->root.u.def.section = h->weakdef->root.u.def.section;
3885 h->root.u.def.value = h->weakdef->root.u.def.value;
3891 /* Perform any actions needed for dynamic symbols. */
3894 elf32_frvfdpic_finish_dynamic_symbol
3895 (bfd *output_bfd ATTRIBUTE_UNUSED,
3896 struct bfd_link_info *info ATTRIBUTE_UNUSED,
3897 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED,
3898 Elf_Internal_Sym *sym ATTRIBUTE_UNUSED)
3903 /* Decide whether to attempt to turn absptr or lsda encodings in
3904 shared libraries into pcrel within the given input section. */
3907 frvfdpic_elf_use_relative_eh_frame
3908 (bfd *input_bfd ATTRIBUTE_UNUSED,
3909 struct bfd_link_info *info ATTRIBUTE_UNUSED,
3910 asection *eh_frame_section ATTRIBUTE_UNUSED)
3912 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
3916 /* Adjust the contents of an eh_frame_hdr section before they're output. */
3919 frvfdpic_elf_encode_eh_address (bfd *abfd,
3920 struct bfd_link_info *info,
3921 asection *osec, bfd_vma offset,
3922 asection *loc_sec, bfd_vma loc_offset,
3925 struct elf_link_hash_entry *h;
3927 h = elf_hash_table (info)->hgot;
3928 BFD_ASSERT (h && h->root.type == bfd_link_hash_defined);
3930 if (! h || (_frvfdpic_osec_to_segment (abfd, osec)
3931 == _frvfdpic_osec_to_segment (abfd, loc_sec->output_section)))
3932 return _bfd_elf_encode_eh_address (abfd, info, osec, offset,
3933 loc_sec, loc_offset, encoded);
3935 BFD_ASSERT (_frvfdpic_osec_to_segment (abfd, osec)
3936 == (_frvfdpic_osec_to_segment
3937 (abfd, h->root.u.def.section->output_section)));
3939 *encoded = osec->vma + offset
3940 - (h->root.u.def.value
3941 + h->root.u.def.section->output_section->vma
3942 + h->root.u.def.section->output_offset);
3944 return DW_EH_PE_datarel | DW_EH_PE_sdata4;
3947 /* Look through the relocs for a section during the first phase.
3949 Besides handling virtual table relocs for gc, we have to deal with
3950 all sorts of PIC-related relocations. We describe below the
3951 general plan on how to handle such relocations, even though we only
3952 collect information at this point, storing them in hash tables for
3953 perusal of later passes.
3955 32 relocations are propagated to the linker output when creating
3956 position-independent output. LO16 and HI16 relocations are not
3957 supposed to be encountered in this case.
3959 LABEL16 should always be resolvable by the linker, since it's only
3962 LABEL24, on the other hand, is used by calls. If it turns out that
3963 the target of a call is a dynamic symbol, a PLT entry must be
3964 created for it, which triggers the creation of a private function
3965 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
3967 GPREL relocations require the referenced symbol to be in the same
3968 segment as _gp, but this can only be checked later.
3970 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
3971 exist. LABEL24 might as well, since it may require a PLT entry,
3972 that will require a got.
3974 Non-FUNCDESC GOT relocations require a GOT entry to be created
3975 regardless of whether the symbol is dynamic. However, since a
3976 global symbol that turns out to not be exported may have the same
3977 address of a non-dynamic symbol, we don't assign GOT entries at
3978 this point, such that we can share them in this case. A relocation
3979 for the GOT entry always has to be created, be it to offset a
3980 private symbol by the section load address, be it to get the symbol
3981 resolved dynamically.
3983 FUNCDESC GOT relocations require a GOT entry to be created, and
3984 handled as if a FUNCDESC relocation was applied to the GOT entry in
3987 FUNCDESC relocations referencing a symbol that turns out to NOT be
3988 dynamic cause a private function descriptor to be created. The
3989 FUNCDESC relocation then decays to a 32 relocation that points at
3990 the private descriptor. If the symbol is dynamic, the FUNCDESC
3991 relocation is propagated to the linker output, such that the
3992 dynamic linker creates the canonical descriptor, pointing to the
3993 dynamically-resolved definition of the function.
3995 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
3996 symbols that are assigned to the same segment as the GOT, but we
3997 can only check this later, after we know the complete set of
3998 symbols defined and/or exported.
4000 FUNCDESC GOTOFF relocations require a function descriptor to be
4001 created and, unless lazy binding is disabled or the symbol is not
4002 dynamic, a lazy PLT entry. Since we can't tell at this point
4003 whether a symbol is going to be dynamic, we have to decide later
4004 whether to create a lazy PLT entry or bind the descriptor directly
4005 to the private function.
4007 FUNCDESC_VALUE relocations are not supposed to be present in object
4008 files, but they may very well be simply propagated to the linker
4009 output, since they have no side effect.
4012 A function descriptor always requires a FUNCDESC_VALUE relocation.
4013 Whether it's in .plt.rel or not depends on whether lazy binding is
4014 enabled and on whether the referenced symbol is dynamic.
4016 The existence of a lazy PLT requires the resolverStub lazy PLT
4017 entry to be present.
4020 As for assignment of GOT, PLT and lazy PLT entries, and private
4021 descriptors, we might do them all sequentially, but we can do
4022 better than that. For example, we can place GOT entries and
4023 private function descriptors referenced using 12-bit operands
4024 closer to the PIC register value, such that these relocations don't
4025 overflow. Those that are only referenced with LO16 relocations
4026 could come next, but we may as well place PLT-required function
4027 descriptors in the 12-bit range to make them shorter. Symbols
4028 referenced with LO16/HI16 may come next, but we may place
4029 additional function descriptors in the 16-bit range if we can
4030 reliably tell that we've already placed entries that are ever
4031 referenced with only LO16. PLT entries are therefore generated as
4032 small as possible, while not introducing relocation overflows in
4033 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
4034 generated before or after PLT entries, but not intermingled with
4035 them, such that we can have more lazy PLT entries in range for a
4036 branch to the resolverStub. The resolverStub should be emitted at
4037 the most distant location from the first lazy PLT entry such that
4038 it's still in range for a branch, or closer, if there isn't a need
4039 for so many lazy PLT entries. Additional lazy PLT entries may be
4040 emitted after the resolverStub, as long as branches are still in
4041 range. If the branch goes out of range, longer lazy PLT entries
4044 We could further optimize PLT and lazy PLT entries by giving them
4045 priority in assignment to closer-to-gr17 locations depending on the
4046 number of occurrences of references to them (assuming a function
4047 that's called more often is more important for performance, so its
4048 PLT entry should be faster), or taking hints from the compiler.
4049 Given infinite time and money... :-) */
4052 elf32_frv_check_relocs (abfd, info, sec, relocs)
4054 struct bfd_link_info *info;
4056 const Elf_Internal_Rela *relocs;
4058 Elf_Internal_Shdr *symtab_hdr;
4059 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
4060 const Elf_Internal_Rela *rel;
4061 const Elf_Internal_Rela *rel_end;
4063 struct frvfdpic_relocs_info *picrel;
4065 if (info->relocatable)
4068 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4069 sym_hashes = elf_sym_hashes (abfd);
4070 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf32_External_Sym);
4071 if (!elf_bad_symtab (abfd))
4072 sym_hashes_end -= symtab_hdr->sh_info;
4074 dynobj = elf_hash_table (info)->dynobj;
4075 rel_end = relocs + sec->reloc_count;
4076 for (rel = relocs; rel < rel_end; rel++)
4078 struct elf_link_hash_entry *h;
4079 unsigned long r_symndx;
4081 r_symndx = ELF32_R_SYM (rel->r_info);
4082 if (r_symndx < symtab_hdr->sh_info)
4085 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4087 switch (ELF32_R_TYPE (rel->r_info))
4092 case R_FRV_FUNCDESC_GOT12:
4093 case R_FRV_FUNCDESC_GOTHI:
4094 case R_FRV_FUNCDESC_GOTLO:
4095 case R_FRV_GOTOFF12:
4096 case R_FRV_GOTOFFHI:
4097 case R_FRV_GOTOFFLO:
4098 case R_FRV_FUNCDESC_GOTOFF12:
4099 case R_FRV_FUNCDESC_GOTOFFHI:
4100 case R_FRV_FUNCDESC_GOTOFFLO:
4101 case R_FRV_FUNCDESC:
4102 case R_FRV_FUNCDESC_VALUE:
4103 if (! IS_FDPIC (abfd))
4107 case R_FRV_GPRELU12:
4114 elf_hash_table (info)->dynobj = dynobj = abfd;
4115 if (! _frv_create_got_section (abfd, info))
4118 if (! IS_FDPIC (abfd))
4125 if (h->dynindx == -1)
4126 switch (ELF_ST_VISIBILITY (h->other))
4132 bfd_elf_link_record_dynamic_symbol (info, h);
4136 = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info),
4138 rel->r_addend, INSERT);
4141 picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
4142 (info), abfd, r_symndx,
4143 rel->r_addend, INSERT);
4153 switch (ELF32_R_TYPE (rel->r_info))
4156 if (IS_FDPIC (abfd))
4160 case R_FRV_FUNCDESC_VALUE:
4161 picrel->relocsfdv++;
4162 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
4167 if (! IS_FDPIC (abfd))
4171 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
4181 picrel->gothilo = 1;
4184 case R_FRV_FUNCDESC_GOT12:
4185 picrel->fdgot12 = 1;
4188 case R_FRV_FUNCDESC_GOTHI:
4189 case R_FRV_FUNCDESC_GOTLO:
4190 picrel->fdgothilo = 1;
4193 case R_FRV_GOTOFF12:
4194 case R_FRV_GOTOFFHI:
4195 case R_FRV_GOTOFFLO:
4199 case R_FRV_FUNCDESC_GOTOFF12:
4200 picrel->fdgoff12 = 1;
4203 case R_FRV_FUNCDESC_GOTOFFHI:
4204 case R_FRV_FUNCDESC_GOTOFFLO:
4205 picrel->fdgoffhilo = 1;
4208 case R_FRV_FUNCDESC:
4213 /* This relocation describes the C++ object vtable hierarchy.
4214 Reconstruct it for later use during GC. */
4215 case R_FRV_GNU_VTINHERIT:
4216 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
4220 /* This relocation describes which C++ vtable entries are actually
4221 used. Record for later use during GC. */
4222 case R_FRV_GNU_VTENTRY:
4223 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
4231 case R_FRV_GPRELU12:
4239 (*_bfd_error_handler)
4240 (_("%s: unsupported relocation type %i"),
4241 bfd_archive_filename (abfd), ELF32_R_TYPE (rel->r_info));
4250 /* Return the machine subcode from the ELF e_flags header. */
4253 elf32_frv_machine (abfd)
4256 switch (elf_elfheader (abfd)->e_flags & EF_FRV_CPU_MASK)
4259 case EF_FRV_CPU_FR550: return bfd_mach_fr550;
4260 case EF_FRV_CPU_FR500: return bfd_mach_fr500;
4261 case EF_FRV_CPU_FR450: return bfd_mach_fr450;
4262 case EF_FRV_CPU_FR405: return bfd_mach_fr400;
4263 case EF_FRV_CPU_FR400: return bfd_mach_fr400;
4264 case EF_FRV_CPU_FR300: return bfd_mach_fr300;
4265 case EF_FRV_CPU_SIMPLE: return bfd_mach_frvsimple;
4266 case EF_FRV_CPU_TOMCAT: return bfd_mach_frvtomcat;
4269 return bfd_mach_frv;
4272 /* Set the right machine number for a FRV ELF file. */
4275 elf32_frv_object_p (abfd)
4278 bfd_default_set_arch_mach (abfd, bfd_arch_frv, elf32_frv_machine (abfd));
4279 return (((elf_elfheader (abfd)->e_flags & EF_FRV_FDPIC) != 0)
4280 == (IS_FDPIC (abfd)));
4283 /* Function to set the ELF flag bits. */
4286 frv_elf_set_private_flags (abfd, flags)
4290 elf_elfheader (abfd)->e_flags = flags;
4291 elf_flags_init (abfd) = TRUE;
4295 /* Copy backend specific data from one object module to another. */
4298 frv_elf_copy_private_bfd_data (ibfd, obfd)
4302 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
4303 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
4306 BFD_ASSERT (!elf_flags_init (obfd)
4307 || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
4309 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
4310 elf_flags_init (obfd) = TRUE;
4314 /* Return true if the architecture described by elf header flag
4315 EXTENSION is an extension of the architecture described by BASE. */
4318 frv_elf_arch_extension_p (flagword base, flagword extension)
4320 if (base == extension)
4323 /* CPU_GENERIC code can be merged with code for a specific
4324 architecture, in which case the result is marked as being
4325 for the specific architecture. Everything is therefore
4326 an extension of CPU_GENERIC. */
4327 if (base == EF_FRV_CPU_GENERIC)
4330 if (extension == EF_FRV_CPU_FR450)
4331 if (base == EF_FRV_CPU_FR400 || base == EF_FRV_CPU_FR405)
4334 if (extension == EF_FRV_CPU_FR405)
4335 if (base == EF_FRV_CPU_FR400)
4342 elf32_frvfdpic_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
4346 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
4347 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
4350 if (! frv_elf_copy_private_bfd_data (ibfd, obfd))
4353 if (! elf_tdata (ibfd) || ! elf_tdata (ibfd)->phdr
4354 || ! elf_tdata (obfd) || ! elf_tdata (obfd)->phdr)
4357 /* Copy the stack size. */
4358 for (i = 0; i < elf_elfheader (ibfd)->e_phnum; i++)
4359 if (elf_tdata (ibfd)->phdr[i].p_type == PT_GNU_STACK)
4361 Elf_Internal_Phdr *iphdr = &elf_tdata (ibfd)->phdr[i];
4363 for (i = 0; i < elf_elfheader (obfd)->e_phnum; i++)
4364 if (elf_tdata (obfd)->phdr[i].p_type == PT_GNU_STACK)
4366 memcpy (&elf_tdata (obfd)->phdr[i], iphdr, sizeof (*iphdr));
4368 /* Rewrite the phdrs, since we're only called after they
4369 were first written. */
4370 if (bfd_seek (obfd, (bfd_signed_vma) get_elf_backend_data (obfd)
4371 ->s->sizeof_ehdr, SEEK_SET) != 0
4372 || get_elf_backend_data (obfd)->s
4373 ->write_out_phdrs (obfd, elf_tdata (obfd)->phdr,
4374 elf_elfheader (obfd)->e_phnum) != 0)
4385 /* Merge backend specific data from an object file to the output
4386 object file when linking. */
4389 frv_elf_merge_private_bfd_data (ibfd, obfd)
4393 flagword old_flags, old_partial;
4394 flagword new_flags, new_partial;
4395 bfd_boolean error = FALSE;
4399 new_opt[0] = old_opt[0] = '\0';
4400 new_flags = elf_elfheader (ibfd)->e_flags;
4401 old_flags = elf_elfheader (obfd)->e_flags;
4403 if (new_flags & EF_FRV_FDPIC)
4404 new_flags &= ~EF_FRV_PIC;
4407 (*_bfd_error_handler) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s",
4408 old_flags, new_flags, elf_flags_init (obfd) ? "yes" : "no",
4409 bfd_get_filename (ibfd));
4412 if (!elf_flags_init (obfd)) /* First call, no flags set. */
4414 elf_flags_init (obfd) = TRUE;
4415 old_flags = new_flags;
4418 else if (new_flags == old_flags) /* Compatible flags are ok. */
4421 else /* Possibly incompatible flags. */
4423 /* Warn if different # of gprs are used. Note, 0 means nothing is
4424 said about the size of gprs. */
4425 new_partial = (new_flags & EF_FRV_GPR_MASK);
4426 old_partial = (old_flags & EF_FRV_GPR_MASK);
4427 if (new_partial == old_partial)
4430 else if (new_partial == 0)
4433 else if (old_partial == 0)
4434 old_flags |= new_partial;
4438 switch (new_partial)
4440 default: strcat (new_opt, " -mgpr-??"); break;
4441 case EF_FRV_GPR_32: strcat (new_opt, " -mgpr-32"); break;
4442 case EF_FRV_GPR_64: strcat (new_opt, " -mgpr-64"); break;
4445 switch (old_partial)
4447 default: strcat (old_opt, " -mgpr-??"); break;
4448 case EF_FRV_GPR_32: strcat (old_opt, " -mgpr-32"); break;
4449 case EF_FRV_GPR_64: strcat (old_opt, " -mgpr-64"); break;
4453 /* Warn if different # of fprs are used. Note, 0 means nothing is
4454 said about the size of fprs. */
4455 new_partial = (new_flags & EF_FRV_FPR_MASK);
4456 old_partial = (old_flags & EF_FRV_FPR_MASK);
4457 if (new_partial == old_partial)
4460 else if (new_partial == 0)
4463 else if (old_partial == 0)
4464 old_flags |= new_partial;
4468 switch (new_partial)
4470 default: strcat (new_opt, " -mfpr-?"); break;
4471 case EF_FRV_FPR_32: strcat (new_opt, " -mfpr-32"); break;
4472 case EF_FRV_FPR_64: strcat (new_opt, " -mfpr-64"); break;
4473 case EF_FRV_FPR_NONE: strcat (new_opt, " -msoft-float"); break;
4476 switch (old_partial)
4478 default: strcat (old_opt, " -mfpr-?"); break;
4479 case EF_FRV_FPR_32: strcat (old_opt, " -mfpr-32"); break;
4480 case EF_FRV_FPR_64: strcat (old_opt, " -mfpr-64"); break;
4481 case EF_FRV_FPR_NONE: strcat (old_opt, " -msoft-float"); break;
4485 /* Warn if different dword support was used. Note, 0 means nothing is
4486 said about the dword support. */
4487 new_partial = (new_flags & EF_FRV_DWORD_MASK);
4488 old_partial = (old_flags & EF_FRV_DWORD_MASK);
4489 if (new_partial == old_partial)
4492 else if (new_partial == 0)
4495 else if (old_partial == 0)
4496 old_flags |= new_partial;
4500 switch (new_partial)
4502 default: strcat (new_opt, " -mdword-?"); break;
4503 case EF_FRV_DWORD_YES: strcat (new_opt, " -mdword"); break;
4504 case EF_FRV_DWORD_NO: strcat (new_opt, " -mno-dword"); break;
4507 switch (old_partial)
4509 default: strcat (old_opt, " -mdword-?"); break;
4510 case EF_FRV_DWORD_YES: strcat (old_opt, " -mdword"); break;
4511 case EF_FRV_DWORD_NO: strcat (old_opt, " -mno-dword"); break;
4515 /* Or in flags that accumulate (ie, if one module uses it, mark that the
4517 old_flags |= new_flags & (EF_FRV_DOUBLE
4520 | EF_FRV_NON_PIC_RELOCS);
4522 /* If any module was compiled without -G0, clear the G0 bit. */
4523 old_flags = ((old_flags & ~ EF_FRV_G0)
4524 | (old_flags & new_flags & EF_FRV_G0));
4526 /* If any module was compiled without -mnopack, clear the mnopack bit. */
4527 old_flags = ((old_flags & ~ EF_FRV_NOPACK)
4528 | (old_flags & new_flags & EF_FRV_NOPACK));
4530 /* We don't have to do anything if the pic flags are the same, or the new
4531 module(s) were compiled with -mlibrary-pic. */
4532 new_partial = (new_flags & EF_FRV_PIC_FLAGS);
4533 old_partial = (old_flags & EF_FRV_PIC_FLAGS);
4534 if ((new_partial == old_partial) || ((new_partial & EF_FRV_LIBPIC) != 0))
4537 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
4538 flags if any from the new module. */
4539 else if ((old_partial & EF_FRV_LIBPIC) != 0)
4540 old_flags = (old_flags & ~ EF_FRV_PIC_FLAGS) | new_partial;
4542 /* If we have mixtures of -fpic and -fPIC, or in both bits. */
4543 else if (new_partial != 0 && old_partial != 0)
4544 old_flags |= new_partial;
4546 /* One module was compiled for pic and the other was not, see if we have
4547 had any relocations that are not pic-safe. */
4550 if ((old_flags & EF_FRV_NON_PIC_RELOCS) == 0)
4551 old_flags |= new_partial;
4554 old_flags &= ~ EF_FRV_PIC_FLAGS;
4555 #ifndef FRV_NO_PIC_ERROR
4557 (*_bfd_error_handler)
4558 (_("%s: compiled with %s and linked with modules that use non-pic relocations"),
4559 bfd_get_filename (ibfd),
4560 (new_flags & EF_FRV_BIGPIC) ? "-fPIC" : "-fpic");
4565 /* Warn if different cpu is used (allow a specific cpu to override
4566 the generic cpu). */
4567 new_partial = (new_flags & EF_FRV_CPU_MASK);
4568 old_partial = (old_flags & EF_FRV_CPU_MASK);
4569 if (frv_elf_arch_extension_p (new_partial, old_partial))
4572 else if (frv_elf_arch_extension_p (old_partial, new_partial))
4573 old_flags = (old_flags & ~EF_FRV_CPU_MASK) | new_partial;
4577 switch (new_partial)
4579 default: strcat (new_opt, " -mcpu=?"); break;
4580 case EF_FRV_CPU_GENERIC: strcat (new_opt, " -mcpu=frv"); break;
4581 case EF_FRV_CPU_SIMPLE: strcat (new_opt, " -mcpu=simple"); break;
4582 case EF_FRV_CPU_FR550: strcat (new_opt, " -mcpu=fr550"); break;
4583 case EF_FRV_CPU_FR500: strcat (new_opt, " -mcpu=fr500"); break;
4584 case EF_FRV_CPU_FR450: strcat (new_opt, " -mcpu=fr450"); break;
4585 case EF_FRV_CPU_FR405: strcat (new_opt, " -mcpu=fr405"); break;
4586 case EF_FRV_CPU_FR400: strcat (new_opt, " -mcpu=fr400"); break;
4587 case EF_FRV_CPU_FR300: strcat (new_opt, " -mcpu=fr300"); break;
4588 case EF_FRV_CPU_TOMCAT: strcat (new_opt, " -mcpu=tomcat"); break;
4591 switch (old_partial)
4593 default: strcat (old_opt, " -mcpu=?"); break;
4594 case EF_FRV_CPU_GENERIC: strcat (old_opt, " -mcpu=frv"); break;
4595 case EF_FRV_CPU_SIMPLE: strcat (old_opt, " -mcpu=simple"); break;
4596 case EF_FRV_CPU_FR550: strcat (old_opt, " -mcpu=fr550"); break;
4597 case EF_FRV_CPU_FR500: strcat (old_opt, " -mcpu=fr500"); break;
4598 case EF_FRV_CPU_FR450: strcat (old_opt, " -mcpu=fr450"); break;
4599 case EF_FRV_CPU_FR405: strcat (old_opt, " -mcpu=fr405"); break;
4600 case EF_FRV_CPU_FR400: strcat (old_opt, " -mcpu=fr400"); break;
4601 case EF_FRV_CPU_FR300: strcat (old_opt, " -mcpu=fr300"); break;
4602 case EF_FRV_CPU_TOMCAT: strcat (old_opt, " -mcpu=tomcat"); break;
4606 /* Print out any mismatches from above. */
4610 (*_bfd_error_handler)
4611 (_("%s: compiled with %s and linked with modules compiled with %s"),
4612 bfd_get_filename (ibfd), new_opt, old_opt);
4615 /* Warn about any other mismatches */
4616 new_partial = (new_flags & ~ EF_FRV_ALL_FLAGS);
4617 old_partial = (old_flags & ~ EF_FRV_ALL_FLAGS);
4618 if (new_partial != old_partial)
4620 old_flags |= new_partial;
4622 (*_bfd_error_handler)
4623 (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"),
4624 bfd_get_filename (ibfd), (long)new_partial, (long)old_partial);
4628 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
4629 if ((old_flags & EF_FRV_CPU_MASK) == EF_FRV_CPU_SIMPLE)
4630 old_flags |= EF_FRV_NOPACK;
4632 /* Update the old flags now with changes made above. */
4633 old_partial = elf_elfheader (obfd)->e_flags & EF_FRV_CPU_MASK;
4634 elf_elfheader (obfd)->e_flags = old_flags;
4635 if (old_partial != (old_flags & EF_FRV_CPU_MASK))
4636 bfd_default_set_arch_mach (obfd, bfd_arch_frv, elf32_frv_machine (obfd));
4638 if (((new_flags & EF_FRV_FDPIC) == 0)
4639 != (! IS_FDPIC (ibfd)))
4642 if (IS_FDPIC (obfd))
4643 (*_bfd_error_handler)
4644 (_("%s: cannot link non-fdpic object file into fdpic executable"),
4645 bfd_get_filename (ibfd));
4647 (*_bfd_error_handler)
4648 (_("%s: cannot link fdpic object file into non-fdpic executable"),
4649 bfd_get_filename (ibfd));
4653 bfd_set_error (bfd_error_bad_value);
4660 frv_elf_print_private_bfd_data (abfd, ptr)
4664 FILE *file = (FILE *) ptr;
4667 BFD_ASSERT (abfd != NULL && ptr != NULL);
4669 /* Print normal ELF private data. */
4670 _bfd_elf_print_private_bfd_data (abfd, ptr);
4672 flags = elf_elfheader (abfd)->e_flags;
4673 fprintf (file, _("private flags = 0x%lx:"), (long)flags);
4675 switch (flags & EF_FRV_CPU_MASK)
4678 case EF_FRV_CPU_SIMPLE: fprintf (file, " -mcpu=simple"); break;
4679 case EF_FRV_CPU_FR550: fprintf (file, " -mcpu=fr550"); break;
4680 case EF_FRV_CPU_FR500: fprintf (file, " -mcpu=fr500"); break;
4681 case EF_FRV_CPU_FR450: fprintf (file, " -mcpu=fr450"); break;
4682 case EF_FRV_CPU_FR405: fprintf (file, " -mcpu=fr405"); break;
4683 case EF_FRV_CPU_FR400: fprintf (file, " -mcpu=fr400"); break;
4684 case EF_FRV_CPU_FR300: fprintf (file, " -mcpu=fr300"); break;
4685 case EF_FRV_CPU_TOMCAT: fprintf (file, " -mcpu=tomcat"); break;
4688 switch (flags & EF_FRV_GPR_MASK)
4691 case EF_FRV_GPR_32: fprintf (file, " -mgpr-32"); break;
4692 case EF_FRV_GPR_64: fprintf (file, " -mgpr-64"); break;
4695 switch (flags & EF_FRV_FPR_MASK)
4698 case EF_FRV_FPR_32: fprintf (file, " -mfpr-32"); break;
4699 case EF_FRV_FPR_64: fprintf (file, " -mfpr-64"); break;
4700 case EF_FRV_FPR_NONE: fprintf (file, " -msoft-float"); break;
4703 switch (flags & EF_FRV_DWORD_MASK)
4706 case EF_FRV_DWORD_YES: fprintf (file, " -mdword"); break;
4707 case EF_FRV_DWORD_NO: fprintf (file, " -mno-dword"); break;
4710 if (flags & EF_FRV_DOUBLE)
4711 fprintf (file, " -mdouble");
4713 if (flags & EF_FRV_MEDIA)
4714 fprintf (file, " -mmedia");
4716 if (flags & EF_FRV_MULADD)
4717 fprintf (file, " -mmuladd");
4719 if (flags & EF_FRV_PIC)
4720 fprintf (file, " -fpic");
4722 if (flags & EF_FRV_BIGPIC)
4723 fprintf (file, " -fPIC");
4725 if (flags & EF_FRV_LIBPIC)
4726 fprintf (file, " -mlibrary-pic");
4728 if (flags & EF_FRV_FDPIC)
4729 fprintf (file, " -mfdpic");
4731 if (flags & EF_FRV_NON_PIC_RELOCS)
4732 fprintf (file, " non-pic relocations");
4734 if (flags & EF_FRV_G0)
4735 fprintf (file, " -G0");
4742 #define ELF_ARCH bfd_arch_frv
4743 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
4744 #define ELF_MAXPAGESIZE 0x1000
4746 #define TARGET_BIG_SYM bfd_elf32_frv_vec
4747 #define TARGET_BIG_NAME "elf32-frv"
4749 #define elf_info_to_howto frv_info_to_howto_rela
4750 #define elf_backend_relocate_section elf32_frv_relocate_section
4751 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
4752 #define elf_backend_gc_sweep_hook elf32_frv_gc_sweep_hook
4753 #define elf_backend_check_relocs elf32_frv_check_relocs
4754 #define elf_backend_object_p elf32_frv_object_p
4755 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
4757 #define elf_backend_can_gc_sections 1
4758 #define elf_backend_rela_normal 1
4760 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
4761 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
4762 #define bfd_elf32_bfd_copy_private_bfd_data frv_elf_copy_private_bfd_data
4763 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
4764 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
4766 #define elf_backend_want_got_sym 1
4767 #define elf_backend_got_header_size 0
4768 #define elf_backend_want_got_plt 0
4769 #define elf_backend_plt_readonly 1
4770 #define elf_backend_want_plt_sym 0
4771 #define elf_backend_plt_header_size 0
4773 #define elf_backend_finish_dynamic_sections \
4774 elf32_frv_finish_dynamic_sections
4776 #include "elf32-target.h"
4778 #undef ELF_MAXPAGESIZE
4779 #define ELF_MAXPAGESIZE 0x4000
4781 #undef TARGET_BIG_SYM
4782 #define TARGET_BIG_SYM bfd_elf32_frvfdpic_vec
4783 #undef TARGET_BIG_NAME
4784 #define TARGET_BIG_NAME "elf32-frvfdpic"
4786 #define elf32_bed elf32_frvfdpic_bed
4788 #undef elf_info_to_howto_rel
4789 #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel
4791 #undef bfd_elf32_bfd_link_hash_table_create
4792 #define bfd_elf32_bfd_link_hash_table_create \
4793 frvfdpic_elf_link_hash_table_create
4794 #undef elf_backend_always_size_sections
4795 #define elf_backend_always_size_sections \
4796 elf32_frvfdpic_always_size_sections
4797 #undef elf_backend_modify_segment_map
4798 #define elf_backend_modify_segment_map \
4799 elf32_frvfdpic_modify_segment_map
4800 #undef bfd_elf32_bfd_copy_private_bfd_data
4801 #define bfd_elf32_bfd_copy_private_bfd_data \
4802 elf32_frvfdpic_copy_private_bfd_data
4804 #undef elf_backend_create_dynamic_sections
4805 #define elf_backend_create_dynamic_sections \
4806 elf32_frvfdpic_create_dynamic_sections
4807 #undef elf_backend_adjust_dynamic_symbol
4808 #define elf_backend_adjust_dynamic_symbol \
4809 elf32_frvfdpic_adjust_dynamic_symbol
4810 #undef elf_backend_size_dynamic_sections
4811 #define elf_backend_size_dynamic_sections \
4812 elf32_frvfdpic_size_dynamic_sections
4813 #undef elf_backend_finish_dynamic_symbol
4814 #define elf_backend_finish_dynamic_symbol \
4815 elf32_frvfdpic_finish_dynamic_symbol
4816 #undef elf_backend_finish_dynamic_sections
4817 #define elf_backend_finish_dynamic_sections \
4818 elf32_frvfdpic_finish_dynamic_sections
4820 #undef elf_backend_can_make_relative_eh_frame
4821 #define elf_backend_can_make_relative_eh_frame \
4822 frvfdpic_elf_use_relative_eh_frame
4823 #undef elf_backend_can_make_lsda_relative_eh_frame
4824 #define elf_backend_can_make_lsda_relative_eh_frame \
4825 frvfdpic_elf_use_relative_eh_frame
4826 #undef elf_backend_encode_eh_address
4827 #define elf_backend_encode_eh_address \
4828 frvfdpic_elf_encode_eh_address
4830 #undef elf_backend_may_use_rel_p
4831 #define elf_backend_may_use_rel_p 1
4832 #undef elf_backend_may_use_rela_p
4833 #define elf_backend_may_use_rela_p 1
4834 /* We use REL for dynamic relocations only. */
4835 #undef elf_backend_default_use_rela_p
4836 #define elf_backend_default_use_rela_p 1
4838 #undef elf_backend_omit_section_dynsym
4839 #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym
4841 #include "elf32-target.h"